-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
call out to Octopus Imaging API from
database-bridge-lambda
in `cre…
…ateItem` mutation if the `type` is `imaging-request`
- Loading branch information
1 parent
0d7dd60
commit b6d17a8
Showing
12 changed files
with
173 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { getEnvironmentVariableOrThrow } from "shared/environmentVariables"; | ||
import { ItemWithParsedPayload } from "shared/types/ItemWithParsedPayload"; | ||
import { InvokeCommand, LambdaClient, LogType } from "@aws-sdk/client-lambda"; | ||
import { standardAwsConfig } from "shared/awsIntegration"; | ||
|
||
const lambda = new LambdaClient(standardAwsConfig); | ||
const textEncoder = new TextEncoder(); | ||
const textDecoder = new TextDecoder(); | ||
|
||
export const performImagingRequest = async (item: ItemWithParsedPayload) => { | ||
const gridId = (item.payload?.embeddableUrl as string)?.split("/").pop(); | ||
if (!gridId) { | ||
throw new Error(`Couldn't extract grid ID from payload: ${item.payload}`); | ||
} | ||
const imagingRequestBody = { | ||
workflowId: item.pinboardId, | ||
pinboardItemId: item.id, | ||
lastUser: item.userEmail, | ||
notes: item.message, //TODO check for 256 max (probably limit in UI too) | ||
requestType: item.payload?.requestType, // TODO tighten this up | ||
gridId, | ||
// composerId: TODO lookup somehow | ||
// pubDate TODO scheduled launch vs some date field in workflow - what's worse wrong date or no date? | ||
// section TODO lookup somehow | ||
// story group name TODO (synced from InCopy most likely, if available) | ||
}; | ||
console.log("Performing imaging request", imagingRequestBody); | ||
|
||
const octopusLambdaFunctionName = getEnvironmentVariableOrThrow( | ||
"octopusApiLambdaFunctionName" | ||
); | ||
|
||
const octopusResponse = await lambda.send( | ||
new InvokeCommand({ | ||
FunctionName: octopusLambdaFunctionName, | ||
Payload: textEncoder.encode(JSON.stringify(imagingRequestBody)), | ||
LogType: LogType.None, //TODO consider whether we tail the octopus logs as pinboard logs | ||
}) | ||
); | ||
|
||
console.log( | ||
"Imaging request complete", | ||
JSON.parse(textDecoder.decode(octopusResponse.Payload)) | ||
); | ||
|
||
// FIXME return something from octopusResponse.Payload | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Item } from "../graphql/graphql"; | ||
|
||
export type ItemWithParsedPayload = Omit<Item, "payload"> & { | ||
payload: Record<string, unknown> | null | undefined; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters