@remotion/serverless 4.0.244 → 4.0.246

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/.turbo/turbo-make.log +1 -1
  2. package/LICENSE.md +1 -1
  3. package/dist/best-frames-per-function-param.d.ts +1 -0
  4. package/dist/best-frames-per-function-param.js +17 -0
  5. package/dist/calculate-chunk-times.d.ts +5 -0
  6. package/dist/calculate-chunk-times.js +29 -0
  7. package/dist/can-concat-seamlessly.d.ts +3 -0
  8. package/dist/can-concat-seamlessly.js +17 -0
  9. package/dist/cleanup-props.d.ts +9 -0
  10. package/dist/cleanup-props.js +23 -0
  11. package/dist/cleanup-serialized-input-props.d.ts +15 -0
  12. package/dist/cleanup-serialized-input-props.js +34 -0
  13. package/dist/client.d.ts +9 -0
  14. package/dist/client.js +30 -12
  15. package/dist/compress-props.d.ts +6 -2
  16. package/dist/compress-props.js +5 -3
  17. package/dist/concat-videos.d.ts +25 -0
  18. package/dist/concat-videos.js +53 -0
  19. package/dist/constants.d.ts +39 -3
  20. package/dist/constants.js +8 -1
  21. package/dist/create-post-render-data.d.ts +20 -0
  22. package/dist/create-post-render-data.js +68 -0
  23. package/dist/docs-url.d.ts +1 -0
  24. package/dist/docs-url.js +4 -0
  25. package/dist/estimate-price-from-bucket.d.ts +15 -0
  26. package/dist/estimate-price-from-bucket.js +31 -0
  27. package/dist/expected-out-name.d.ts +1 -1
  28. package/dist/find-output-file-in-bucket.d.ts +16 -0
  29. package/dist/find-output-file-in-bucket.js +41 -0
  30. package/dist/format-costs-info.d.ts +2 -0
  31. package/dist/format-costs-info.js +23 -0
  32. package/dist/get-browser-instance.d.ts +5 -12
  33. package/dist/get-browser-instance.js +8 -7
  34. package/dist/get-custom-out-name.d.ts +1 -1
  35. package/dist/get-or-create-bucket.d.ts +1 -1
  36. package/dist/get-overall-progress-from-storage.d.ts +11 -0
  37. package/dist/get-overall-progress-from-storage.js +25 -0
  38. package/dist/get-overall-progress.d.ts +9 -0
  39. package/dist/get-overall-progress.js +23 -0
  40. package/dist/handlers/check-version-mismatch.d.ts +8 -0
  41. package/dist/handlers/check-version-mismatch.js +23 -0
  42. package/dist/handlers/compositions.d.ts +16 -0
  43. package/dist/handlers/compositions.js +81 -0
  44. package/dist/handlers/launch.d.ts +18 -0
  45. package/dist/handlers/launch.js +600 -0
  46. package/dist/handlers/progress.d.ts +16 -0
  47. package/dist/handlers/progress.js +54 -0
  48. package/dist/handlers/renderer.d.ts +24 -0
  49. package/dist/handlers/renderer.js +344 -0
  50. package/dist/handlers/start.d.ts +19 -0
  51. package/dist/handlers/start.js +104 -0
  52. package/dist/handlers/still.d.ts +21 -0
  53. package/dist/handlers/still.js +335 -0
  54. package/dist/index.d.ts +21 -5
  55. package/dist/index.js +54 -7
  56. package/dist/info.d.ts +1 -1
  57. package/dist/inner-routine.d.ts +22 -0
  58. package/dist/inner-routine.js +267 -0
  59. package/dist/inspect-error.d.ts +4 -0
  60. package/dist/inspect-error.js +39 -0
  61. package/dist/invoke-webhook.d.ts +42 -0
  62. package/dist/invoke-webhook.js +116 -0
  63. package/dist/is-warm.d.ts +2 -0
  64. package/dist/is-warm.js +10 -0
  65. package/dist/leak-detection.d.ts +4 -0
  66. package/dist/leak-detection.js +40 -0
  67. package/dist/make-bucket-name.d.ts +1 -1
  68. package/dist/make-timeout-error.d.ts +13 -0
  69. package/dist/make-timeout-error.js +32 -0
  70. package/dist/make-timeout-message.d.ts +12 -0
  71. package/dist/make-timeout-message.js +76 -0
  72. package/dist/merge-chunks.d.ts +38 -0
  73. package/dist/merge-chunks.js +92 -0
  74. package/dist/min-max.d.ts +2 -0
  75. package/dist/min-max.js +33 -0
  76. package/dist/most-expensive-chunks.d.ts +13 -0
  77. package/dist/most-expensive-chunks.js +28 -0
  78. package/dist/on-downloads-helpers.d.ts +2 -0
  79. package/dist/on-downloads-helpers.js +29 -0
  80. package/dist/overall-render-progress.d.ts +59 -0
  81. package/dist/overall-render-progress.js +180 -0
  82. package/dist/plan-frame-ranges.d.ts +7 -0
  83. package/dist/plan-frame-ranges.js +17 -0
  84. package/dist/print-logging-grep-helper.d.ts +4 -0
  85. package/dist/print-logging-grep-helper.js +12 -0
  86. package/dist/progress.d.ts +16 -0
  87. package/dist/progress.js +254 -0
  88. package/dist/provider-implementation.d.ts +152 -3
  89. package/dist/render-has-audio-video.d.ts +6 -0
  90. package/dist/render-has-audio-video.js +21 -0
  91. package/dist/render-metadata.d.ts +1 -1
  92. package/dist/render-progress.d.ts +51 -0
  93. package/dist/return-values.d.ts +38 -0
  94. package/dist/return-values.js +2 -0
  95. package/dist/stackback.d.ts +6 -0
  96. package/dist/stackback.js +59 -0
  97. package/dist/stream-renderer.d.ts +17 -0
  98. package/dist/stream-renderer.js +148 -0
  99. package/dist/streaming/streaming.d.ts +6 -6
  100. package/dist/streaming/streaming.js +3 -3
  101. package/dist/types.d.ts +55 -0
  102. package/dist/types.js +2 -0
  103. package/dist/validate-composition.d.ts +1 -1
  104. package/dist/validate-composition.js +11 -1
  105. package/dist/validate-download-behavior.d.ts +1 -0
  106. package/dist/validate-download-behavior.js +21 -0
  107. package/dist/validate-frames-per-function.d.ts +4 -0
  108. package/dist/validate-frames-per-function.js +29 -0
  109. package/dist/validate-privacy.d.ts +2 -0
  110. package/dist/validate-privacy.js +14 -0
  111. package/dist/validate.d.ts +4 -0
  112. package/dist/validate.js +8 -0
  113. package/dist/why-is-node-running.d.ts +15 -0
  114. package/dist/why-is-node-running.js +89 -0
  115. package/dist/{write-lambda-error.d.ts → write-error-to-storage.d.ts} +4 -4
  116. package/package.json +6 -5
  117. package/tsconfig.tsbuildinfo +1 -1
  118. package/dist/compositions.d.ts +0 -11
  119. package/dist/compositions.js +0 -82
  120. package/dist/still.d.ts +0 -28
  121. /package/dist/{still.js → render-progress.js} +0 -0
  122. /package/dist/{write-lambda-error.js → write-error-to-storage.js} +0 -0
@@ -0,0 +1,267 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.innerRoutine = exports.innerHandler = void 0;
4
+ const renderer_1 = require("@remotion/renderer");
5
+ const client_1 = require("./client");
6
+ const constants_1 = require("./constants");
7
+ const compositions_1 = require("./handlers/compositions");
8
+ const launch_1 = require("./handlers/launch");
9
+ const progress_1 = require("./handlers/progress");
10
+ const renderer_2 = require("./handlers/renderer");
11
+ const start_1 = require("./handlers/start");
12
+ const still_1 = require("./handlers/still");
13
+ const info_1 = require("./info");
14
+ const is_warm_1 = require("./is-warm");
15
+ const leak_detection_1 = require("./leak-detection");
16
+ const print_logging_grep_helper_1 = require("./print-logging-grep-helper");
17
+ const innerHandler = async ({ params, responseWriter, context, providerSpecifics, insideFunctionSpecifics, webhookClient, }) => {
18
+ (0, leak_detection_1.setCurrentRequestId)(context.awsRequestId);
19
+ process.env.__RESERVED_IS_INSIDE_REMOTION_LAMBDA = 'true';
20
+ const timeoutInMilliseconds = context.getRemainingTimeInMillis();
21
+ renderer_1.RenderInternals.Log.verbose({ indent: false, logLevel: params.logLevel }, 'AWS Request ID:', context.awsRequestId);
22
+ (0, leak_detection_1.stopLeakDetection)();
23
+ if (!(context === null || context === void 0 ? void 0 : context.invokedFunctionArn)) {
24
+ throw new Error('Lambda function unexpectedly does not have context.invokedFunctionArn');
25
+ }
26
+ await insideFunctionSpecifics.deleteTmpDir();
27
+ const isWarm = (0, is_warm_1.getWarm)();
28
+ (0, is_warm_1.setWarm)();
29
+ const currentUserId = context.invokedFunctionArn.split(':')[4];
30
+ if (params.type === constants_1.ServerlessRoutines.still) {
31
+ providerSpecifics.validateDeleteAfter(params.deleteAfter);
32
+ const renderId = insideFunctionSpecifics.generateRandomId({
33
+ deleteAfter: params.deleteAfter,
34
+ randomHashFn: providerSpecifics.randomHash,
35
+ });
36
+ if (providerSpecifics.printLoggingHelper) {
37
+ (0, print_logging_grep_helper_1.printLoggingGrepHelper)(constants_1.ServerlessRoutines.still, {
38
+ renderId,
39
+ inputProps: JSON.stringify(params.inputProps),
40
+ isWarm,
41
+ }, params.logLevel);
42
+ }
43
+ try {
44
+ await new Promise((resolve, reject) => {
45
+ const onStream = async (payload) => {
46
+ if (!params.streamed) {
47
+ if (payload.type !== 'still-rendered') {
48
+ throw new Error('Expected still-rendered');
49
+ }
50
+ await responseWriter.write(Buffer.from(JSON.stringify(payload.payload)));
51
+ return;
52
+ }
53
+ const message = (0, client_1.makeStreamPayload)({
54
+ message: payload,
55
+ });
56
+ return new Promise((innerResolve, innerReject) => {
57
+ responseWriter
58
+ .write(message)
59
+ .then(() => {
60
+ innerResolve();
61
+ })
62
+ .catch((err) => {
63
+ reject(err);
64
+ innerReject(err);
65
+ });
66
+ });
67
+ };
68
+ if (params.streamed) {
69
+ onStream({
70
+ type: 'render-id-determined',
71
+ payload: { renderId },
72
+ });
73
+ }
74
+ (0, still_1.stillHandler)({
75
+ expectedBucketOwner: currentUserId,
76
+ params,
77
+ renderId,
78
+ onStream,
79
+ timeoutInMilliseconds,
80
+ providerSpecifics,
81
+ insideFunctionSpecifics,
82
+ })
83
+ .then((r) => {
84
+ resolve(r);
85
+ })
86
+ .catch((err) => {
87
+ reject(err);
88
+ });
89
+ });
90
+ await responseWriter.end();
91
+ }
92
+ catch (err) {
93
+ // eslint-disable-next-line no-console
94
+ console.log({ err });
95
+ }
96
+ return;
97
+ }
98
+ if (params.type === constants_1.ServerlessRoutines.start) {
99
+ const renderId = insideFunctionSpecifics.generateRandomId({
100
+ deleteAfter: params.deleteAfter,
101
+ randomHashFn: providerSpecifics.randomHash,
102
+ });
103
+ if (providerSpecifics.printLoggingHelper) {
104
+ (0, print_logging_grep_helper_1.printLoggingGrepHelper)(constants_1.ServerlessRoutines.start, {
105
+ renderId,
106
+ inputProps: JSON.stringify(params.inputProps),
107
+ isWarm,
108
+ }, params.logLevel);
109
+ }
110
+ const response = await (0, start_1.startHandler)({
111
+ params,
112
+ options: {
113
+ expectedBucketOwner: currentUserId,
114
+ timeoutInMilliseconds,
115
+ renderId,
116
+ },
117
+ providerSpecifics,
118
+ insideFunctionSpecifics,
119
+ });
120
+ await responseWriter.write(Buffer.from(JSON.stringify(response)));
121
+ await responseWriter.end();
122
+ return;
123
+ }
124
+ if (params.type === constants_1.ServerlessRoutines.launch) {
125
+ if (providerSpecifics.printLoggingHelper) {
126
+ (0, print_logging_grep_helper_1.printLoggingGrepHelper)(constants_1.ServerlessRoutines.launch, {
127
+ renderId: params.renderId,
128
+ inputProps: JSON.stringify(params.inputProps),
129
+ isWarm,
130
+ }, params.logLevel);
131
+ }
132
+ const response = await (0, launch_1.launchHandler)({
133
+ params,
134
+ options: {
135
+ expectedBucketOwner: currentUserId,
136
+ getRemainingTimeInMillis: context.getRemainingTimeInMillis,
137
+ },
138
+ providerSpecifics,
139
+ client: webhookClient,
140
+ insideFunctionSpecifics,
141
+ });
142
+ await responseWriter.write(Buffer.from(JSON.stringify(response)));
143
+ await responseWriter.end();
144
+ return;
145
+ }
146
+ if (params.type === constants_1.ServerlessRoutines.status) {
147
+ if (providerSpecifics.printLoggingHelper) {
148
+ (0, print_logging_grep_helper_1.printLoggingGrepHelper)(constants_1.ServerlessRoutines.status, {
149
+ renderId: params.renderId,
150
+ isWarm,
151
+ }, params.logLevel);
152
+ }
153
+ const response = await (0, progress_1.progressHandler)({
154
+ params,
155
+ options: {
156
+ expectedBucketOwner: currentUserId,
157
+ timeoutInMilliseconds,
158
+ retriesRemaining: 2,
159
+ providerSpecifics,
160
+ insideFunctionSpecifics,
161
+ },
162
+ });
163
+ await responseWriter.write(Buffer.from(JSON.stringify(response)));
164
+ await responseWriter.end();
165
+ return;
166
+ }
167
+ if (params.type === constants_1.ServerlessRoutines.renderer) {
168
+ if (providerSpecifics.printLoggingHelper) {
169
+ (0, print_logging_grep_helper_1.printLoggingGrepHelper)(constants_1.ServerlessRoutines.renderer, {
170
+ renderId: params.renderId,
171
+ chunk: String(params.chunk),
172
+ dumpLogs: String(renderer_1.RenderInternals.isEqualOrBelowLogLevel(params.logLevel, 'verbose')),
173
+ resolvedProps: JSON.stringify(params.resolvedProps),
174
+ isWarm,
175
+ }, params.logLevel);
176
+ }
177
+ await new Promise((resolve, reject) => {
178
+ (0, renderer_2.rendererHandler)({
179
+ params,
180
+ options: {
181
+ expectedBucketOwner: currentUserId,
182
+ isWarm,
183
+ },
184
+ onStream: (payload) => {
185
+ const message = (0, client_1.makeStreamPayload)({
186
+ message: payload,
187
+ });
188
+ const writeProm = responseWriter.write(message);
189
+ return new Promise((innerResolve, innerReject) => {
190
+ writeProm
191
+ .then(() => {
192
+ innerResolve();
193
+ })
194
+ .catch((err) => {
195
+ reject(err);
196
+ innerReject(err);
197
+ });
198
+ });
199
+ },
200
+ requestContext: context,
201
+ providerSpecifics,
202
+ insideFunctionSpecifics,
203
+ })
204
+ .then((res) => {
205
+ resolve(res);
206
+ })
207
+ .catch((err) => {
208
+ reject(err);
209
+ });
210
+ });
211
+ await responseWriter.end();
212
+ return;
213
+ }
214
+ if (params.type === constants_1.ServerlessRoutines.info) {
215
+ if (providerSpecifics.printLoggingHelper) {
216
+ (0, print_logging_grep_helper_1.printLoggingGrepHelper)(constants_1.ServerlessRoutines.info, {
217
+ isWarm,
218
+ }, params.logLevel);
219
+ }
220
+ const response = await (0, info_1.infoHandler)(params);
221
+ await responseWriter.write(Buffer.from(JSON.stringify(response)));
222
+ await responseWriter.end();
223
+ return;
224
+ }
225
+ if (params.type === constants_1.ServerlessRoutines.compositions) {
226
+ if (providerSpecifics.printLoggingHelper) {
227
+ (0, print_logging_grep_helper_1.printLoggingGrepHelper)(constants_1.ServerlessRoutines.compositions, {
228
+ isWarm,
229
+ }, params.logLevel);
230
+ }
231
+ const response = await (0, compositions_1.compositionsHandler)({
232
+ params,
233
+ options: {
234
+ expectedBucketOwner: currentUserId,
235
+ },
236
+ providerSpecifics,
237
+ insideFunctionSpecifics,
238
+ });
239
+ await responseWriter.write(Buffer.from(JSON.stringify(response)));
240
+ await responseWriter.end();
241
+ return;
242
+ }
243
+ throw new Error(constants_1.COMMAND_NOT_FOUND);
244
+ };
245
+ exports.innerHandler = innerHandler;
246
+ const innerRoutine = async ({ params, responseWriter, context, providerSpecifics, insideFunctionSpecifics, webhookClient, }) => {
247
+ try {
248
+ await (0, exports.innerHandler)({
249
+ params,
250
+ responseWriter,
251
+ context,
252
+ providerSpecifics,
253
+ insideFunctionSpecifics,
254
+ webhookClient,
255
+ });
256
+ }
257
+ catch (err) {
258
+ const res = {
259
+ type: 'error',
260
+ message: err.message,
261
+ stack: err.stack,
262
+ };
263
+ await responseWriter.write(Buffer.from(JSON.stringify(res)));
264
+ await responseWriter.end();
265
+ }
266
+ };
267
+ exports.innerRoutine = innerRoutine;
@@ -0,0 +1,4 @@
1
+ import type { EnhancedErrorInfo, FunctionErrorInfo } from './write-error-to-storage';
2
+ export declare const inspectErrors: ({ errors, }: {
3
+ errors: FunctionErrorInfo[];
4
+ }) => EnhancedErrorInfo[];
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.inspectErrors = void 0;
4
+ const docs_url_1 = require("./docs-url");
5
+ const error_category_1 = require("./error-category");
6
+ const FAILED_TO_LAUNCH_TOKEN = 'Failed to launch browser.';
7
+ const getExplanation = (stack) => {
8
+ if (stack.includes('FATAL:zygote_communication_linux.cc')) {
9
+ return (FAILED_TO_LAUNCH_TOKEN +
10
+ ' Will be retried - you can probably ignore this error.');
11
+ }
12
+ if (stack.includes('error while loading shared libraries: libnss3.so')) {
13
+ return (FAILED_TO_LAUNCH_TOKEN +
14
+ ' Will be retried - you can probably ignore this error.');
15
+ }
16
+ if (stack.includes('TooManyRequestsException')) {
17
+ return `AWS returned an "TooManyRequestsException" error message which could mean you reached the concurrency limit of AWS Lambda. You can increase the limit - read this troubleshooting page: ${docs_url_1.DOCS_URL}/docs/lambda/troubleshooting/rate-limit`;
18
+ }
19
+ if ((0, error_category_1.errorIsOutOfSpaceError)(stack)) {
20
+ return `Your lambda function reached the storage limit. Reduce the amount of space needed per lambda function or increase the storage limit: ${docs_url_1.DOCS_URL}/docs/lambda/disk-size.`;
21
+ }
22
+ if ((0, error_category_1.isErrInsufficientResourcesErr)(stack)) {
23
+ return 'The lambda ran out of memory. Deploy a new function with more memory.';
24
+ }
25
+ if ((0, error_category_1.isBrowserCrashedError)(stack)) {
26
+ return 'The browser crashed while rendering the video. Deploy a new function with memory to give the browser more resources.';
27
+ }
28
+ return null;
29
+ };
30
+ const inspectErrors = ({ errors, }) => {
31
+ return errors.map((e) => {
32
+ return {
33
+ ...e,
34
+ explanation: getExplanation(e.stack),
35
+ s3Location: '',
36
+ };
37
+ });
38
+ };
39
+ exports.inspectErrors = inspectErrors;
@@ -0,0 +1,42 @@
1
+ import type { LogLevel } from '@remotion/renderer';
2
+ import type https from 'https';
3
+ import type http from 'node:http';
4
+ import type { AfterRenderCost } from './constants';
5
+ import type { EnhancedErrorInfo } from './write-error-to-storage';
6
+ export declare function calculateSignature(payload: string, secret: string | null): string;
7
+ type StaticWebhookPayload = {
8
+ renderId: string;
9
+ expectedBucketOwner: string;
10
+ bucketName: string;
11
+ customData: Record<string, unknown> | null;
12
+ };
13
+ export type WebhookErrorPayload = StaticWebhookPayload & {
14
+ type: 'error';
15
+ errors: {
16
+ message: string;
17
+ name: string;
18
+ stack: string;
19
+ }[];
20
+ };
21
+ export type WebhookSuccessPayload = StaticWebhookPayload & {
22
+ type: 'success';
23
+ lambdaErrors: EnhancedErrorInfo[];
24
+ outputUrl: string | undefined;
25
+ outputFile: string | undefined;
26
+ timeToFinish: number | undefined;
27
+ costs: AfterRenderCost;
28
+ };
29
+ export type WebhookTimeoutPayload = StaticWebhookPayload & {
30
+ type: 'timeout';
31
+ };
32
+ export type WebhookPayload = WebhookErrorPayload | WebhookSuccessPayload | WebhookTimeoutPayload;
33
+ export type WebhookClient = (url: string) => (url: string | URL, options: https.RequestOptions, callback?: (res: http.IncomingMessage) => void) => http.ClientRequest;
34
+ type InvokeWebhookOptions = {
35
+ payload: WebhookPayload;
36
+ url: string;
37
+ secret: string | null;
38
+ redirectsSoFar: number;
39
+ client: WebhookClient;
40
+ };
41
+ export declare const invokeWebhook: (options: InvokeWebhookOptions, logLevel: LogLevel, retries?: number, errors?: number) => Promise<void>;
42
+ export {};
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.invokeWebhook = void 0;
27
+ exports.calculateSignature = calculateSignature;
28
+ const renderer_1 = require("@remotion/renderer");
29
+ const Crypto = __importStar(require("node:crypto"));
30
+ function calculateSignature(payload, secret) {
31
+ if (!secret) {
32
+ return 'NO_SECRET_PROVIDED';
33
+ }
34
+ const hmac = Crypto.createHmac('sha512', secret);
35
+ const signature = 'sha512=' + hmac.update(payload).digest('hex');
36
+ return signature;
37
+ }
38
+ // Don't handle 304 status code (Not Modified) as a redirect,
39
+ // since the browser will display the right page.
40
+ const redirectStatusCodes = [301, 302, 303, 307, 308];
41
+ function invokeWebhookRaw({ payload, secret, url, redirectsSoFar, client, }) {
42
+ const jsonPayload = JSON.stringify(payload);
43
+ return new Promise((resolve, reject) => {
44
+ const req = client(url)(url, {
45
+ method: 'POST',
46
+ headers: {
47
+ 'Content-Type': 'application/json',
48
+ 'Content-Length': jsonPayload.length,
49
+ 'X-Remotion-Mode': 'production',
50
+ 'X-Remotion-Signature': calculateSignature(jsonPayload, secret),
51
+ 'X-Remotion-Status': payload.type,
52
+ },
53
+ timeout: 5000,
54
+ }, (res) => {
55
+ if (res.statusCode && res.statusCode > 299) {
56
+ if (redirectStatusCodes.includes(res.statusCode)) {
57
+ if (!res.headers.location) {
58
+ reject(new Error(`Received a status code ${res.statusCode} but no "Location" header while calling ${res.headers.location}`));
59
+ return;
60
+ }
61
+ if (redirectsSoFar > 10) {
62
+ reject(new Error(`Too many redirects while downloading ${url}`));
63
+ return;
64
+ }
65
+ invokeWebhookRaw({
66
+ payload,
67
+ secret,
68
+ url: res.headers.location,
69
+ redirectsSoFar: redirectsSoFar + 1,
70
+ client,
71
+ })
72
+ .then(resolve)
73
+ .catch(reject);
74
+ return;
75
+ }
76
+ reject(new Error(`Sent a webhook to ${url} but got a status code of ${res.statusCode} with message '${res.statusMessage}'`));
77
+ return;
78
+ }
79
+ resolve();
80
+ });
81
+ req.write(jsonPayload, (err) => {
82
+ if (err) {
83
+ reject(err);
84
+ }
85
+ else {
86
+ req.end();
87
+ }
88
+ });
89
+ req.on('error', (err) => {
90
+ reject(err);
91
+ });
92
+ });
93
+ }
94
+ function exponentialBackoff(errorCount) {
95
+ return 1000 * 2 ** (errorCount - 1);
96
+ }
97
+ const invokeWebhook = async (options, logLevel, retries = 2, errors = 0) => {
98
+ try {
99
+ await invokeWebhookRaw(options);
100
+ }
101
+ catch (err) {
102
+ if (retries === 0) {
103
+ throw err;
104
+ }
105
+ renderer_1.RenderInternals.Log.error({ indent: false, logLevel }, 'Could not send webhook due to error:');
106
+ renderer_1.RenderInternals.Log.error({ indent: false, logLevel }, err.stack);
107
+ renderer_1.RenderInternals.Log.error({ indent: false, logLevel }, `Retrying in ${exponentialBackoff(errors)}ms.`);
108
+ await new Promise((resolve) => {
109
+ setTimeout(() => {
110
+ resolve();
111
+ }, exponentialBackoff(errors));
112
+ });
113
+ return (0, exports.invokeWebhook)(options, logLevel, retries - 1, errors + 1);
114
+ }
115
+ };
116
+ exports.invokeWebhook = invokeWebhook;
@@ -0,0 +1,2 @@
1
+ export declare const setWarm: () => void;
2
+ export declare const getWarm: () => boolean;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWarm = exports.setWarm = void 0;
4
+ let warm = false;
5
+ const setWarm = () => {
6
+ warm = true;
7
+ };
8
+ exports.setWarm = setWarm;
9
+ const getWarm = () => warm;
10
+ exports.getWarm = getWarm;
@@ -0,0 +1,4 @@
1
+ import type { NodeIntrospection } from './why-is-node-running';
2
+ export declare const stopLeakDetection: () => void;
3
+ export declare const setCurrentRequestId: (awsRequestId: string) => void;
4
+ export declare const startLeakDetection: (leakDetection: NodeIntrospection, awsRequestId: string) => void;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startLeakDetection = exports.setCurrentRequestId = exports.stopLeakDetection = void 0;
4
+ const why_is_node_running_1 = require("./why-is-node-running");
5
+ let currentRequestId = null;
6
+ let leakDetectionTimeout = null;
7
+ const stopLeakDetection = () => {
8
+ if (leakDetectionTimeout !== null) {
9
+ clearTimeout(leakDetectionTimeout.timeout);
10
+ leakDetectionTimeout = null;
11
+ }
12
+ };
13
+ exports.stopLeakDetection = stopLeakDetection;
14
+ const setCurrentRequestId = (awsRequestId) => {
15
+ currentRequestId = awsRequestId;
16
+ };
17
+ exports.setCurrentRequestId = setCurrentRequestId;
18
+ const startLeakDetection = (leakDetection, awsRequestId) => {
19
+ currentRequestId = awsRequestId;
20
+ leakDetectionTimeout = {
21
+ awsRequestId,
22
+ timeout: setTimeout(() => {
23
+ // First allow request ID to be set
24
+ setTimeout(() => {
25
+ if (currentRequestId !== awsRequestId) {
26
+ // New function, all good
27
+ return;
28
+ }
29
+ console.log('Leak detected: Lambda function is still running 10s after the render has finished.');
30
+ console.log('You may report this to the Remotion team.');
31
+ console.log('Include the logs below:');
32
+ (0, why_is_node_running_1.whyIsNodeRunning)(leakDetection);
33
+ console.log('Force-quitting the Lambda function now.');
34
+ process.exit(0);
35
+ }, 100);
36
+ }, 10000),
37
+ };
38
+ leakDetectionTimeout.timeout.unref();
39
+ };
40
+ exports.startLeakDetection = startLeakDetection;
@@ -1,3 +1,3 @@
1
1
  import type { ProviderSpecifics } from './provider-implementation';
2
- import type { CloudProvider } from './still';
2
+ import type { CloudProvider } from './types';
3
3
  export declare const makeBucketName: <Provider extends CloudProvider>(region: Provider["region"], providerSpecifics: ProviderSpecifics<Provider>) => string;
@@ -0,0 +1,13 @@
1
+ import type { ProviderSpecifics } from './provider-implementation';
2
+ import type { RenderMetadata } from './render-metadata';
3
+ import type { CloudProvider } from './types';
4
+ import type { EnhancedErrorInfo } from './write-error-to-storage';
5
+ export declare const makeTimeoutError: <Provider extends CloudProvider>({ timeoutInMilliseconds, missingChunks, renderMetadata, renderId, functionName, region, providerSpecifics, }: {
6
+ timeoutInMilliseconds: number;
7
+ renderMetadata: RenderMetadata<Provider>;
8
+ renderId: string;
9
+ missingChunks: number[];
10
+ functionName: string;
11
+ region: Provider["region"];
12
+ providerSpecifics: ProviderSpecifics<Provider>;
13
+ }) => EnhancedErrorInfo;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeTimeoutError = void 0;
4
+ const make_timeout_message_1 = require("./make-timeout-message");
5
+ const makeTimeoutError = ({ timeoutInMilliseconds, missingChunks, renderMetadata, renderId, functionName, region, providerSpecifics, }) => {
6
+ const message = (0, make_timeout_message_1.makeTimeoutMessage)({
7
+ missingChunks,
8
+ renderMetadata,
9
+ timeoutInMilliseconds,
10
+ renderId,
11
+ functionName,
12
+ region,
13
+ providerSpecifics,
14
+ });
15
+ const error = new Error(message);
16
+ return {
17
+ attempt: 1,
18
+ chunk: null,
19
+ explanation: null,
20
+ frame: null,
21
+ isFatal: true,
22
+ s3Location: '',
23
+ stack: error.stack,
24
+ tmpDir: null,
25
+ totalAttempts: 1,
26
+ type: 'stitcher',
27
+ willRetry: false,
28
+ message,
29
+ name: 'TimeoutError',
30
+ };
31
+ };
32
+ exports.makeTimeoutError = makeTimeoutError;
@@ -0,0 +1,12 @@
1
+ import type { ProviderSpecifics } from './provider-implementation';
2
+ import type { RenderMetadata } from './render-metadata';
3
+ import type { CloudProvider } from './types';
4
+ export declare const makeTimeoutMessage: <Provider extends CloudProvider>({ timeoutInMilliseconds, missingChunks, renderMetadata, renderId, functionName, region, providerSpecifics, }: {
5
+ timeoutInMilliseconds: number;
6
+ missingChunks: number[];
7
+ renderMetadata: RenderMetadata<Provider>;
8
+ renderId: string;
9
+ region: Provider["region"];
10
+ functionName: string;
11
+ providerSpecifics: ProviderSpecifics<Provider>;
12
+ }) => string;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeTimeoutMessage = void 0;
4
+ const constants_1 = require("./constants");
5
+ const docs_url_1 = require("./docs-url");
6
+ const MAX_MISSING_CHUNKS = 5;
7
+ const makeChunkMissingMessage = ({ missingChunks, renderMetadata, region, providerSpecifics, functionName, }) => {
8
+ if (missingChunks.length === 0) {
9
+ return 'All chunks have been successfully rendered, but the main function has timed out.';
10
+ }
11
+ return [
12
+ `The following chunks are missing (showing ${Math.min(MAX_MISSING_CHUNKS, missingChunks.length)} out of ${missingChunks.length}):`,
13
+ ...missingChunks
14
+ .map((ch) => {
15
+ const isLastChunk = ch === renderMetadata.totalChunks - 1;
16
+ const start = ch * renderMetadata.framesPerLambda;
17
+ const end = renderMetadata.type === 'still'
18
+ ? 0
19
+ : isLastChunk
20
+ ? renderMetadata.frameRange[1]
21
+ : (ch + 1) * renderMetadata.framesPerLambda - 1;
22
+ const msg = `Chunk ${ch} (Frames ${start} - ${end})`;
23
+ return [
24
+ msg,
25
+ `▸ Logs for chunk ${ch}: ${providerSpecifics.getLoggingUrlForRendererFunction({
26
+ functionName,
27
+ region,
28
+ rendererFunctionName: null,
29
+ renderId: renderMetadata.renderId,
30
+ chunk: ch,
31
+ })}`,
32
+ ].join('\n');
33
+ })
34
+ .slice(0, 5),
35
+ ].join('\n');
36
+ };
37
+ const makeTimeoutMessage = ({ timeoutInMilliseconds, missingChunks, renderMetadata, renderId, functionName, region, providerSpecifics, }) => {
38
+ const cloudWatchRendererUrl = providerSpecifics.getLoggingUrlForRendererFunction({
39
+ renderId,
40
+ functionName,
41
+ region,
42
+ rendererFunctionName: functionName,
43
+ chunk: null,
44
+ });
45
+ const cloudWatchLaunchUrl = providerSpecifics.getLoggingUrlForMethod({
46
+ renderId,
47
+ functionName,
48
+ method: constants_1.ServerlessRoutines.launch,
49
+ region,
50
+ rendererFunctionName: functionName,
51
+ });
52
+ const message = [
53
+ `The main function timed out after ${timeoutInMilliseconds}ms.`,
54
+ makeChunkMissingMessage({
55
+ missingChunks,
56
+ renderMetadata,
57
+ region,
58
+ providerSpecifics,
59
+ functionName,
60
+ }),
61
+ '',
62
+ `Consider increasing the timeout of your function.`,
63
+ `▸ You can use the "--timeout" parameter when deploying a function via CLI, or the "timeoutInSeconds" parameter when using the deployFunction() API.`,
64
+ `${docs_url_1.DOCS_URL}/docs/lambda/cli/functions#deploy`,
65
+ '',
66
+ '▸ Visit the logs for the main function:',
67
+ cloudWatchLaunchUrl,
68
+ '▸ Visit the logs for the renderer functions:',
69
+ cloudWatchRendererUrl,
70
+ '',
71
+ '▸ Get help on debugging this error:',
72
+ `${docs_url_1.DOCS_URL}/docs/lambda/troubleshooting/debug`,
73
+ ].join('\n');
74
+ return message;
75
+ };
76
+ exports.makeTimeoutMessage = makeTimeoutMessage;