|
| 1 | +import { getEnvironmentVariableOrThrow } from "shared/environmentVariables"; |
| 2 | +import { ItemWithParsedPayload } from "shared/types/ItemWithParsedPayload"; |
| 3 | +import { InvokeCommand, LambdaClient, LogType } from "@aws-sdk/client-lambda"; |
| 4 | +import { standardAwsConfig } from "shared/awsIntegration"; |
| 5 | + |
| 6 | +const lambda = new LambdaClient(standardAwsConfig); |
| 7 | +const textEncoder = new TextEncoder(); |
| 8 | + |
| 9 | +export const performImagingRequest = async (item: ItemWithParsedPayload) => { |
| 10 | + const gridId = (item.payload?.embeddableUrl as string)?.split("/").pop(); |
| 11 | + if (!gridId) { |
| 12 | + throw new Error(`Couldn't extract grid ID from payload: ${item.payload}`); |
| 13 | + } |
| 14 | + const imagingRequestBody = { |
| 15 | + workflowId: item.pinboardId, |
| 16 | + pinboardItemId: item.id, |
| 17 | + lastUser: item.userEmail, |
| 18 | + notes: item.message, //TODO check for 256 max (probably limit in UI too) |
| 19 | + requestType: item.payload?.requestType, // TODO tighten this up |
| 20 | + gridId, |
| 21 | + // composerId: TODO lookup somehow |
| 22 | + // pubDate TODO scheduled launch vs some date field in workflow - what's worse wrong date or no date? |
| 23 | + // section TODO lookup somehow |
| 24 | + // story group name TODO (synced from InCopy most likely, if available) |
| 25 | + }; |
| 26 | + console.log("Performing imaging request", imagingRequestBody); |
| 27 | + |
| 28 | + const octopusLambdaFunctionName = getEnvironmentVariableOrThrow( |
| 29 | + "octopusApiLambdaFunctionName" |
| 30 | + ); |
| 31 | + |
| 32 | + const octopusResponse = await lambda.send( |
| 33 | + new InvokeCommand({ |
| 34 | + FunctionName: octopusLambdaFunctionName, |
| 35 | + Payload: textEncoder.encode(JSON.stringify(imagingRequestBody)), |
| 36 | + LogType: LogType.None, //TODO consider whether we tail the octopus logs as pinboard logs |
| 37 | + }) |
| 38 | + ); |
| 39 | + |
| 40 | + // FIXME return something from octopusResponse.Payload |
| 41 | +}; |
0 commit comments