Skip to content

🎥 Make videos programmatically with React

webhook shape

Jonny Burger9a8767531015
diff --git a/packages/lambda/src/api/render-media-on-lambda.ts b/packages/lambda/src/api/render-media-on-lambda.ts
index 1dfcc6d9dc..25085524b6 100644
--- a/packages/lambda/src/api/render-media-on-lambda.ts
+++ b/packages/lambda/src/api/render-media-on-lambda.ts
@@ -48,8 +48,10 @@ export type RenderMediaOnLambdaInput = {
downloadBehavior?: DownloadBehavior | null;
muted?: boolean;
overwrite?: boolean;
- webhook?: string
- webhookSecret?: string
+ webhook?: {
+ url: string;
+ secret: string | null;
+ };
};
export type RenderMediaOnLambdaOutput = {
@@ -107,7 +109,6 @@ export const renderMediaOnLambda = async ({
muted,
overwrite,
webhook,
- webhookSecret
}: RenderMediaOnLambdaInput): Promise<RenderMediaOnLambdaOutput> => {
const actualCodec = validateLambdaCodec(codec);
validateServeUrl(serveUrl);
@@ -149,8 +150,7 @@ export const renderMediaOnLambda = async ({
muted: muted ?? false,
version: VERSION,
overwrite: overwrite ?? false,
- webhook,
- webhookSecret,
+ webhook: webhook ?? null,
},
region,
});
diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.ts
index 9f7f6e1ed1..dabb374a92 100644
--- a/packages/lambda/src/cli/commands/render/render.ts
+++ b/packages/lambda/src/cli/commands/render/render.ts
@@ -117,8 +117,12 @@ export const renderCommand = async (args: string[]) => {
concurrencyPerLambda: parsedLambdaCli['concurrency-per-lambda'],
muted,
overwrite,
- webhook: parsedLambdaCli.webhook ?? undefined,
- webhookSecret: parsedLambdaCli.webhookSecret ?? undefined
+ webhook: parsedLambdaCli.webhook
+ ? {
+ url: parsedLambdaCli.webhook,
+ secret: parsedLambdaCli.webhookSecret ?? null,
+ }
+ : undefined,
});
const totalSteps = downloadName ? 5 : 4;
diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.ts
index 605b54471a..1174f434bf 100644
--- a/packages/lambda/src/functions/launch.ts
+++ b/packages/lambda/src/functions/launch.ts
@@ -99,8 +99,8 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {
if (params.webhook && !webhookInvoked) {
try {
await invokeWebhook({
- url: params.webhook,
- secret: params.webhookSecret,
+ url: params.webhook.url,
+ secret: params.webhook.secret,
payload: {
type: 'timeout',
renderId: params.renderId,
@@ -566,8 +566,8 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {
if (params.webhook && !webhookInvoked) {
try {
await invokeWebhook({
- url: params.webhook,
- secret: params.webhookSecret,
+ url: params.webhook.url,
+ secret: params.webhook.secret,
payload: {
type: 'success',
renderId: params.renderId,
@@ -643,11 +643,11 @@ export const launchHandler = async (
expectedBucketOwner: options.expectedBucketOwner,
renderId: params.renderId,
});
- if (params.webhook) {
+ if (params.webhook?.url) {
try {
await invokeWebhook({
- url: params.webhook,
- secret: params.webhookSecret,
+ url: params.webhook.url,
+ secret: params.webhook.secret ?? null,
payload: {
type: 'error',
renderId: params.renderId,
diff --git a/packages/lambda/src/functions/start.ts b/packages/lambda/src/functions/start.ts
index 2b05ba1b8b..ebb2192e4a 100644
--- a/packages/lambda/src/functions/start.ts
+++ b/packages/lambda/src/functions/start.ts
@@ -76,7 +76,6 @@ export const startHandler = async (params: LambdaPayload, options: Options) => {
muted: params.muted,
overwrite: params.overwrite,
webhook: params.webhook,
- webhookSecret: params.webhookSecret,
};
await getLambdaClient(getCurrentRegionInFunction()).send(
new InvokeCommand({
diff --git a/packages/lambda/src/shared/constants.ts b/packages/lambda/src/shared/constants.ts
index 6c92cdaa99..5b3397e291 100644
--- a/packages/lambda/src/shared/constants.ts
+++ b/packages/lambda/src/shared/constants.ts
@@ -226,8 +226,10 @@ export type LambdaPayloads = {
muted: boolean;
version: string;
overwrite: boolean;
- webhook: string | undefined;
- webhookSecret: string | undefined;
+ webhook: null | {
+ url: string;
+ secret: string | null;
+ };
};
launch: {
type: LambdaRoutines.launch;
@@ -258,8 +260,10 @@ export type LambdaPayloads = {
downloadBehavior: DownloadBehavior;
muted: boolean;
overwrite: boolean;
- webhook: string | undefined;
- webhookSecret: string | undefined;
+ webhook: null | {
+ url: string;
+ secret: string | null;
+ };
};
status: {
type: LambdaRoutines.status;
diff --git a/packages/lambda/src/shared/invoke-webhook.ts b/packages/lambda/src/shared/invoke-webhook.ts
index 985e8cc8d8..df60785a1f 100644
--- a/packages/lambda/src/shared/invoke-webhook.ts
+++ b/packages/lambda/src/shared/invoke-webhook.ts
@@ -10,7 +10,7 @@ import type {EnhancedErrorInfo} from '../functions/helpers/write-lambda-error';
* @param secret User-provided webhook secret used to sign the request.
* @returns {string} Calculated signature
*/
-export function calculateSignature(payload: string, secret?: string) {
+export function calculateSignature(payload: string, secret: string | null) {
if (!secret) {
return 'NO_SECRET_PROVIDED';
}
@@ -85,7 +85,7 @@ export function invokeWebhook({
}: {
payload: WebhookPayload;
url: string;
- secret: string | undefined;
+ secret: string | null;
}) {
return new Promise<void>((resolve, reject) => {
const req = getWebhookClient(url)(
diff --git a/packages/lambda/src/test/integration/renders/gif.test.ts b/packages/lambda/src/test/integration/renders/gif.test.ts
index f46c4e6e4c..fd9c67d40f 100644
--- a/packages/lambda/src/test/integration/renders/gif.test.ts
+++ b/packages/lambda/src/test/integration/renders/gif.test.ts
@@ -59,8 +59,7 @@ test('Should make a distributed GIF', async () => {
muted: false,
version: VERSION,
overwrite: true,
- webhook: undefined,
- webhookSecret: undefined,
+ webhook: null,
},
extraContext
);
diff --git a/packages/lambda/src/test/integration/renders/old-version.test.ts b/packages/lambda/src/test/integration/renders/old-version.test.ts
index c989ac93f8..2cdf4abbcc 100644
--- a/packages/lambda/src/test/integration/renders/old-version.test.ts
+++ b/packages/lambda/src/test/integration/renders/old-version.test.ts
@@ -56,8 +56,7 @@ test('Should fail when using an incompatible version', async () => {
muted: false,
version: VERSION,
overwrite: true,
- webhook: undefined,
- webhookSecret: undefined,
+ webhook: null,
},
extraContext
)
diff --git a/packages/lambda/src/test/integration/renders/other-bucket.test.ts b/packages/lambda/src/test/integration/renders/other-bucket.test.ts
index 8ebf8c0af0..5ad570aad5 100644
--- a/packages/lambda/src/test/integration/renders/other-bucket.test.ts
+++ b/packages/lambda/src/test/integration/renders/other-bucket.test.ts
@@ -62,8 +62,7 @@ test('Should be able to render to another bucket', async () => {
muted: false,
version: VERSION,
overwrite: true,
- webhook: undefined,
- webhookSecret: undefined,
+ webhook: null,
},
extraContext
);
diff --git a/packages/lambda/src/test/integration/renders/silent-audio.test.ts b/packages/lambda/src/test/integration/renders/silent-audio.test.ts
index 637fa0f48c..c62c5a83ad 100644
--- a/packages/lambda/src/test/integration/renders/silent-audio.test.ts
+++ b/packages/lambda/src/test/integration/renders/silent-audio.test.ts
@@ -59,8 +59,7 @@ test('Should add silent audio if there is no audio', async () => {
muted: false,
version: VERSION,
overwrite: true,
- webhook: undefined,
- webhookSecret: undefined,
+ webhook: null,
},
extraContext
);
diff --git a/packages/lambda/src/test/integration/renders/transparent-webm.test.ts b/packages/lambda/src/test/integration/renders/transparent-webm.test.ts
index 25e0a4b7f1..24574ac8fc 100644
--- a/packages/lambda/src/test/integration/renders/transparent-webm.test.ts
+++ b/packages/lambda/src/test/integration/renders/transparent-webm.test.ts
@@ -62,8 +62,7 @@ test('Should make a transparent video', async () => {
muted: false,
version: VERSION,
overwrite: true,
- webhook: undefined,
- webhookSecret: undefined,
+ webhook: null,
},
extraContext
);
diff --git a/packages/lambda/src/test/integration/webhooks.test.ts b/packages/lambda/src/test/integration/webhooks.test.ts
index 9cc9026104..604180d7c6 100644
--- a/packages/lambda/src/test/integration/webhooks.test.ts
+++ b/packages/lambda/src/test/integration/webhooks.test.ts
@@ -86,8 +86,10 @@ describe('Webhooks', () => {
muted: false,
version: VERSION,
overwrite: true,
- webhook: TEST_URL,
- webhookSecret: 'TEST_SECRET'
+ webhook: {
+ url: TEST_URL,
+ secret: 'TEST_SECRET',
+ },
},
extraContext
);
@@ -154,8 +156,7 @@ describe('Webhooks', () => {
muted: false,
version: VERSION,
overwrite: true,
- webhook: TEST_URL,
- webhookSecret: 'TEST_SECRET'
+ webhook: {url: TEST_URL, secret: 'TEST_SECRET'},
},
extraContext
);