@remotion/lambda-client 4.0.364 → 4.0.366

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 (103) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/esm/index.mjs +1 -1
  3. package/package.json +4 -4
  4. package/.turbo/turbo-formatting.log +0 -4
  5. package/.turbo/turbo-lint.log +0 -25
  6. package/.turbo/turbo-make.log +0 -3
  7. package/bundle.ts +0 -20
  8. package/dist/cjs/test/concurrency-payload.test.d.ts +0 -1
  9. package/dist/cjs/test/encode-aws-url.test.d.ts +0 -1
  10. package/dist/cjs/test/price-calculation.test.d.ts +0 -1
  11. package/dist/cjs/test/pricing.test.d.ts +0 -1
  12. package/dist/cjs/test/request-handler.test.d.ts +0 -1
  13. package/dist/cjs/test/validate-disk-size-in-mb.test.d.ts +0 -1
  14. package/dist/test/concurrency-payload.test.d.ts +0 -1
  15. package/dist/test/concurrency-payload.test.js +0 -119
  16. package/dist/test/encode-aws-url.test.d.ts +0 -1
  17. package/dist/test/encode-aws-url.test.js +0 -8
  18. package/dist/test/price-calculation.test.d.ts +0 -1
  19. package/dist/test/price-calculation.test.js +0 -62
  20. package/dist/test/pricing.test.d.ts +0 -1
  21. package/dist/test/pricing.test.js +0 -27
  22. package/dist/test/request-handler.test.d.ts +0 -1
  23. package/dist/test/request-handler.test.js +0 -36
  24. package/dist/test/validate-disk-size-in-mb.test.d.ts +0 -1
  25. package/dist/test/validate-disk-size-in-mb.test.js +0 -14
  26. package/dist/tsconfig.tsbuildinfo +0 -1
  27. package/eslint.config.mjs +0 -5
  28. package/src/app-router-webhook.ts +0 -73
  29. package/src/apply-lifecycle.ts +0 -30
  30. package/src/aws-clients.ts +0 -75
  31. package/src/aws-provider.ts +0 -139
  32. package/src/bucket-exists.ts +0 -35
  33. package/src/call-lambda-async.ts +0 -43
  34. package/src/call-lambda-streaming.ts +0 -226
  35. package/src/call-lambda-sync.ts +0 -59
  36. package/src/check-credentials.ts +0 -51
  37. package/src/clean-items.ts +0 -50
  38. package/src/constants.ts +0 -38
  39. package/src/content-disposition-header.ts +0 -64
  40. package/src/convert-to-serve-url.ts +0 -24
  41. package/src/create-bucket.ts +0 -87
  42. package/src/delete-file.ts +0 -38
  43. package/src/delete-function.ts +0 -28
  44. package/src/delete-render.ts +0 -114
  45. package/src/encode-aws-url-params.ts +0 -3
  46. package/src/estimate-price.ts +0 -95
  47. package/src/express-webhook.ts +0 -57
  48. package/src/get-account-id.ts +0 -22
  49. package/src/get-aws-client.ts +0 -63
  50. package/src/get-aws-urls.ts +0 -85
  51. package/src/get-buckets.ts +0 -84
  52. package/src/get-compositions-on-lambda.ts +0 -111
  53. package/src/get-credentials.ts +0 -81
  54. package/src/get-env-variable.ts +0 -15
  55. package/src/get-function-name.ts +0 -24
  56. package/src/get-function-version.ts +0 -49
  57. package/src/get-functions.ts +0 -114
  58. package/src/get-output-url-from-metadata.ts +0 -23
  59. package/src/get-render-progress.ts +0 -66
  60. package/src/get-s3-client.ts +0 -26
  61. package/src/get-service-client.ts +0 -195
  62. package/src/get-sites.ts +0 -136
  63. package/src/head-file.ts +0 -30
  64. package/src/index.ts +0 -152
  65. package/src/is-cli.ts +0 -7
  66. package/src/is-flaky-error.ts +0 -104
  67. package/src/is-in-lambda.ts +0 -5
  68. package/src/is-likely-to-have-aws-profile.ts +0 -55
  69. package/src/lambda-version-string.ts +0 -5
  70. package/src/lifecycle-rules.ts +0 -119
  71. package/src/lifecycle.ts +0 -44
  72. package/src/list-objects.ts +0 -87
  73. package/src/make-lambda-payload.ts +0 -328
  74. package/src/make-s3-url.ts +0 -13
  75. package/src/p-limit.ts +0 -75
  76. package/src/pages-router-webhook.ts +0 -68
  77. package/src/parse-function-name.ts +0 -24
  78. package/src/presign-url.ts +0 -121
  79. package/src/price-per-1s.ts +0 -863
  80. package/src/random-hash.ts +0 -10
  81. package/src/read-file.ts +0 -35
  82. package/src/regions.ts +0 -48
  83. package/src/render-media-on-lambda.ts +0 -227
  84. package/src/render-still-on-lambda.ts +0 -209
  85. package/src/runtime-preference.ts +0 -7
  86. package/src/speculate-function-name.ts +0 -60
  87. package/src/test/concurrency-payload.test.ts +0 -121
  88. package/src/test/encode-aws-url.test.ts +0 -7
  89. package/src/test/price-calculation.test.ts +0 -62
  90. package/src/test/pricing.test.ts +0 -32
  91. package/src/test/request-handler.test.ts +0 -42
  92. package/src/test/validate-disk-size-in-mb.test.ts +0 -15
  93. package/src/types.ts +0 -7
  94. package/src/validate-aws-region.ts +0 -14
  95. package/src/validate-bucketname.ts +0 -24
  96. package/src/validate-disk-size-in-mb.ts +0 -37
  97. package/src/validate-lambda-codec.ts +0 -28
  98. package/src/validate-memory-size.ts +0 -31
  99. package/src/validate-presign-expiration.ts +0 -46
  100. package/src/validate-serveurl.ts +0 -9
  101. package/src/validate-webhook-signature.ts +0 -42
  102. package/src/write-file.ts +0 -108
  103. package/tsconfig.json +0 -10
@@ -1,328 +0,0 @@
1
- import type {
2
- AudioCodec,
3
- BrowserSafeApis,
4
- ChromiumOptions,
5
- ColorSpace,
6
- DeleteAfter,
7
- DownloadBehavior,
8
- FrameRange,
9
- LogLevel,
10
- OutNameInput,
11
- PixelFormat,
12
- Privacy,
13
- ProResProfile,
14
- ServerlessCodec,
15
- ServerlessPayloads,
16
- ServerlessStartPayload,
17
- ServerlessStatusPayload,
18
- ToOptions,
19
- VideoImageFormat,
20
- WebhookOption,
21
- X264Preset,
22
- } from '@remotion/serverless-client';
23
- import {
24
- ENABLE_V5_BREAKING_CHANGES,
25
- ServerlessRoutines,
26
- VERSION,
27
- compressInputProps,
28
- getNeedsToUpload,
29
- serializeOrThrow,
30
- validateDownloadBehavior,
31
- } from '@remotion/serverless-client';
32
- import type {AwsProvider} from './aws-provider';
33
- import {awsImplementation} from './aws-provider';
34
-
35
- import type {StorageClass} from '@aws-sdk/client-s3';
36
- import {validateWebhook} from '@remotion/serverless-client';
37
- import type {GetRenderProgressInput} from './get-render-progress';
38
- import type {AwsRegion} from './regions';
39
- import type {RenderStillOnLambdaNonNullInput} from './render-still-on-lambda';
40
- import type {RequestHandler} from './types';
41
- import {validateLambdaCodec} from './validate-lambda-codec';
42
- import {validateServeUrl} from './validate-serveurl';
43
-
44
- export type InnerRenderMediaOnLambdaInput = {
45
- region: AwsRegion;
46
- functionName: string;
47
- serveUrl: string;
48
- composition: string;
49
- inputProps: Record<string, unknown>;
50
- codec: ServerlessCodec;
51
- imageFormat: VideoImageFormat;
52
- crf: number | undefined;
53
- envVariables: Record<string, string>;
54
- pixelFormat: PixelFormat | undefined;
55
- proResProfile: ProResProfile | undefined;
56
- x264Preset: X264Preset | null;
57
- privacy: Privacy;
58
- jpegQuality: number;
59
- maxRetries: number;
60
- framesPerLambda: number | null;
61
- concurrency: number | null;
62
- logLevel: LogLevel;
63
- frameRange: FrameRange | null;
64
- outName: OutNameInput<AwsProvider> | null;
65
- timeoutInMilliseconds: number;
66
- chromiumOptions: ChromiumOptions;
67
- scale: number;
68
- everyNthFrame: number;
69
- numberOfGifLoops: number | null;
70
- concurrencyPerLambda: number;
71
- downloadBehavior: DownloadBehavior;
72
- muted: boolean;
73
- overwrite: boolean;
74
- audioBitrate: string | null;
75
- videoBitrate: string | null;
76
- encodingMaxRate: string | null;
77
- encodingBufferSize: string | null;
78
- webhook: WebhookOption | null;
79
- forceWidth: number | null;
80
- forceHeight: number | null;
81
- rendererFunctionName: string | null;
82
- forceBucketName: string | null;
83
- audioCodec: AudioCodec | null;
84
- colorSpace: ColorSpace | null;
85
- deleteAfter: DeleteAfter | null;
86
- indent: boolean;
87
- forcePathStyle: boolean;
88
- metadata: Record<string, string> | null;
89
- storageClass: StorageClass | null;
90
- requestHandler: RequestHandler | null;
91
- } & ToOptions<typeof BrowserSafeApis.optionsMap.renderMediaOnLambda>;
92
-
93
- export const makeLambdaRenderMediaPayload = async ({
94
- rendererFunctionName,
95
- frameRange,
96
- framesPerLambda,
97
- concurrency,
98
- forceBucketName: bucketName,
99
- codec,
100
- composition,
101
- serveUrl,
102
- imageFormat,
103
- inputProps,
104
- region,
105
- crf,
106
- envVariables,
107
- pixelFormat,
108
- proResProfile,
109
- x264Preset,
110
- maxRetries,
111
- privacy,
112
- logLevel,
113
- outName,
114
- timeoutInMilliseconds,
115
- chromiumOptions,
116
- scale,
117
- everyNthFrame,
118
- numberOfGifLoops,
119
- audioBitrate,
120
- concurrencyPerLambda,
121
- audioCodec,
122
- forceHeight,
123
- forceWidth,
124
- webhook,
125
- videoBitrate,
126
- encodingMaxRate,
127
- encodingBufferSize,
128
- downloadBehavior,
129
- muted,
130
- overwrite,
131
- jpegQuality,
132
- offthreadVideoCacheSizeInBytes,
133
- mediaCacheSizeInBytes,
134
- deleteAfter,
135
- colorSpace,
136
- preferLossless,
137
- forcePathStyle,
138
- metadata,
139
- apiKey,
140
- offthreadVideoThreads,
141
- storageClass,
142
- requestHandler,
143
- }: InnerRenderMediaOnLambdaInput): Promise<
144
- ServerlessStartPayload<AwsProvider>
145
- > => {
146
- const actualCodec = validateLambdaCodec(codec);
147
- validateServeUrl(serveUrl);
148
- validateDownloadBehavior(downloadBehavior);
149
- validateWebhook(webhook);
150
-
151
- const stringifiedInputProps = serializeOrThrow(
152
- inputProps ?? {},
153
- 'input-props',
154
- );
155
-
156
- const serialized = await compressInputProps({
157
- stringifiedInputProps,
158
- region,
159
- needsToUpload: getNeedsToUpload({
160
- type: 'video-or-audio',
161
- sizes: [
162
- stringifiedInputProps.length,
163
- JSON.stringify(envVariables).length,
164
- ],
165
- providerSpecifics: awsImplementation,
166
- }),
167
- userSpecifiedBucketName: bucketName ?? null,
168
- propsType: 'input-props',
169
- providerSpecifics: awsImplementation,
170
- forcePathStyle: forcePathStyle ?? false,
171
- skipPutAcl: privacy === 'no-acl',
172
- requestHandler: requestHandler ?? null,
173
- });
174
- return {
175
- rendererFunctionName,
176
- framesPerLambda,
177
- concurrency,
178
- composition,
179
- serveUrl,
180
- inputProps: serialized,
181
- codec: actualCodec,
182
- imageFormat,
183
- crf: crf ?? null,
184
- envVariables,
185
- pixelFormat: pixelFormat ?? null,
186
- proResProfile: proResProfile ?? null,
187
- x264Preset,
188
- jpegQuality,
189
- maxRetries,
190
- privacy,
191
- logLevel,
192
- frameRange,
193
- outName,
194
- timeoutInMilliseconds,
195
- chromiumOptions,
196
- scale,
197
- everyNthFrame,
198
- numberOfGifLoops,
199
- concurrencyPerLambda,
200
- downloadBehavior,
201
- muted,
202
- version: VERSION,
203
- overwrite: overwrite ?? ENABLE_V5_BREAKING_CHANGES,
204
- audioBitrate: audioBitrate ?? null,
205
- videoBitrate: videoBitrate ?? null,
206
- encodingBufferSize: encodingBufferSize ?? null,
207
- encodingMaxRate: encodingMaxRate ?? null,
208
- webhook: webhook ?? null,
209
- forceHeight: forceHeight ?? null,
210
- forceWidth: forceWidth ?? null,
211
- bucketName: bucketName ?? null,
212
- audioCodec: audioCodec ?? null,
213
- type: ServerlessRoutines.start,
214
- offthreadVideoCacheSizeInBytes: offthreadVideoCacheSizeInBytes ?? null,
215
- deleteAfter: deleteAfter ?? null,
216
- colorSpace: colorSpace ?? null,
217
- preferLossless: preferLossless ?? false,
218
- forcePathStyle: forcePathStyle ?? false,
219
- metadata: metadata ?? null,
220
- apiKey: apiKey ?? null,
221
- offthreadVideoThreads: offthreadVideoThreads ?? null,
222
- mediaCacheSizeInBytes: mediaCacheSizeInBytes ?? null,
223
- storageClass: storageClass ?? null,
224
- };
225
- };
226
-
227
- export const getRenderProgressPayload = ({
228
- bucketName,
229
- renderId,
230
- s3OutputProvider,
231
- logLevel,
232
- forcePathStyle,
233
- }: GetRenderProgressInput): ServerlessStatusPayload<AwsProvider> => {
234
- return {
235
- type: ServerlessRoutines.status,
236
- bucketName,
237
- renderId,
238
- version: VERSION,
239
- s3OutputProvider: s3OutputProvider ?? null,
240
- logLevel: logLevel ?? 'info',
241
- forcePathStyle: forcePathStyle ?? false,
242
- };
243
- };
244
-
245
- export const makeLambdaRenderStillPayload = async ({
246
- serveUrl,
247
- inputProps,
248
- imageFormat,
249
- envVariables,
250
- jpegQuality,
251
- region,
252
- maxRetries,
253
- composition,
254
- privacy,
255
- frame,
256
- logLevel,
257
- outName,
258
- timeoutInMilliseconds,
259
- chromiumOptions,
260
- scale,
261
- downloadBehavior,
262
- forceHeight,
263
- forceWidth,
264
- forceBucketName,
265
- offthreadVideoCacheSizeInBytes,
266
- deleteAfter,
267
- forcePathStyle,
268
- apiKey,
269
- storageClass,
270
- requestHandler,
271
- offthreadVideoThreads,
272
- mediaCacheSizeInBytes,
273
- }: RenderStillOnLambdaNonNullInput): Promise<
274
- ServerlessPayloads<AwsProvider>[ServerlessRoutines.still]
275
- > => {
276
- const stringifiedInputProps = serializeOrThrow(inputProps, 'input-props');
277
-
278
- const serializedInputProps = await compressInputProps({
279
- stringifiedInputProps,
280
- region,
281
- needsToUpload: getNeedsToUpload({
282
- type: 'still',
283
- sizes: [
284
- stringifiedInputProps.length,
285
- JSON.stringify(envVariables).length,
286
- ],
287
- providerSpecifics: awsImplementation,
288
- }),
289
- userSpecifiedBucketName: forceBucketName ?? null,
290
- propsType: 'input-props',
291
- providerSpecifics: awsImplementation,
292
- forcePathStyle,
293
- skipPutAcl: privacy === 'no-acl',
294
- requestHandler,
295
- });
296
-
297
- return {
298
- composition,
299
- serveUrl,
300
- inputProps: serializedInputProps,
301
- imageFormat,
302
- envVariables,
303
- jpegQuality,
304
- maxRetries,
305
- frame,
306
- privacy,
307
- attempt: 1,
308
- logLevel,
309
- outName,
310
- timeoutInMilliseconds,
311
- chromiumOptions,
312
- scale,
313
- downloadBehavior,
314
- version: VERSION,
315
- forceHeight,
316
- forceWidth,
317
- bucketName: forceBucketName,
318
- offthreadVideoCacheSizeInBytes,
319
- deleteAfter,
320
- type: ServerlessRoutines.still,
321
- streamed: true,
322
- forcePathStyle,
323
- apiKey: apiKey ?? null,
324
- offthreadVideoThreads: offthreadVideoThreads ?? null,
325
- mediaCacheSizeInBytes: mediaCacheSizeInBytes ?? null,
326
- storageClass: storageClass ?? null,
327
- };
328
- };
@@ -1,13 +0,0 @@
1
- import type {AwsRegion} from './regions';
2
-
3
- export const makeS3ServeUrl = ({
4
- bucketName,
5
- subFolder,
6
- region,
7
- }: {
8
- bucketName: string;
9
- subFolder: string;
10
- region: AwsRegion;
11
- }): string => {
12
- return `https://${bucketName}.s3.${region}.amazonaws.com/${subFolder}/index.html`;
13
- };
package/src/p-limit.ts DELETED
@@ -1,75 +0,0 @@
1
- export const pLimit = (concurrency: number) => {
2
- const queue: Function[] = [];
3
- let activeCount = 0;
4
-
5
- const next = () => {
6
- activeCount--;
7
-
8
- if (queue.length > 0) {
9
- queue.shift()?.();
10
- }
11
- };
12
-
13
- const run = async <Arguments extends unknown[], ReturnType>(
14
- fn: (..._arguments: Arguments) => PromiseLike<ReturnType> | ReturnType,
15
- resolve: (res: Promise<ReturnType>) => void,
16
- ...args: Arguments
17
- ) => {
18
- activeCount++;
19
-
20
- // eslint-disable-next-line require-await
21
- const result = (async () => fn(...args))();
22
-
23
- resolve(result);
24
-
25
- try {
26
- await result;
27
- } catch {}
28
-
29
- next();
30
- };
31
-
32
- const enqueue = <Arguments extends unknown[], ReturnType>(
33
- fn: (..._arguments: Arguments) => PromiseLike<ReturnType> | ReturnType,
34
- resolve: (res: Promise<ReturnType>) => void,
35
- ...args: Arguments
36
- ) => {
37
- queue.push(() => run(fn, resolve, ...args));
38
-
39
- (async () => {
40
- // This function needs to wait until the next microtask before comparing
41
- // `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
42
- // when the run function is dequeued and called. The comparison in the if-statement
43
- // needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
44
- await Promise.resolve();
45
-
46
- if (activeCount < concurrency && queue.length > 0) {
47
- queue.shift()?.();
48
- }
49
- })();
50
- };
51
-
52
- const generator = <Arguments extends unknown[], ReturnType>(
53
- fn: (..._arguments: Arguments) => PromiseLike<ReturnType> | ReturnType,
54
- ...args: Arguments
55
- ) =>
56
- new Promise<ReturnType>((resolve) => {
57
- enqueue(fn, resolve, ...args);
58
- });
59
-
60
- Object.defineProperties(generator, {
61
- activeCount: {
62
- get: () => activeCount,
63
- },
64
- pendingCount: {
65
- get: () => queue.length,
66
- },
67
- clearQueue: {
68
- value: () => {
69
- queue.length = 0;
70
- },
71
- },
72
- });
73
-
74
- return generator;
75
- };
@@ -1,68 +0,0 @@
1
- import type {WebhookPayload} from '@remotion/serverless-client';
2
- import type {Response} from 'express';
3
- import type {NextApiRequest, NextApiResponse} from 'next';
4
- import type {NextWebhookArgs} from './app-router-webhook';
5
- import {validateWebhookSignature} from './validate-webhook-signature';
6
-
7
- export const addHeaders = (
8
- res: NextApiResponse | Response,
9
- headers: Record<string, string>,
10
- ) => {
11
- Object.entries(headers).forEach(([key, value]) => {
12
- res.setHeader(key, value);
13
- });
14
- };
15
-
16
- export const pagesRouterWebhook = (options: NextWebhookArgs) => {
17
- const {testing, extraHeaders, secret, onSuccess, onTimeout, onError} =
18
- options;
19
- return async function (
20
- req: NextApiRequest,
21
- res: NextApiResponse,
22
- ): Promise<void> {
23
- addHeaders(res, extraHeaders || {});
24
-
25
- if (testing) {
26
- const testingheaders = {
27
- 'Access-Control-Allow-Origin': 'https://www.remotion.dev',
28
- 'Access-Control-Allow-Headers':
29
- 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, X-Remotion-Status, X-Remotion-Signature, X-Remotion-Mode',
30
- 'Access-Control-Allow-Methods': 'OPTIONS,POST',
31
- };
32
-
33
- addHeaders(res, testingheaders);
34
- }
35
-
36
- if (req.method === 'OPTIONS') {
37
- res.status(200).end();
38
- return;
39
- }
40
-
41
- try {
42
- validateWebhookSignature({
43
- secret,
44
- body: req.body,
45
- signatureHeader: req.headers['x-remotion-signature'] as string,
46
- });
47
-
48
- // If code reaches this path, the webhook is authentic.
49
- const payload = req.body as WebhookPayload;
50
- if (payload.type === 'success' && onSuccess) {
51
- await onSuccess(payload);
52
- } else if (payload.type === 'timeout' && onTimeout) {
53
- await onTimeout(payload);
54
- } else if (payload.type === 'error' && onError) {
55
- await onError(payload);
56
- }
57
-
58
- res.status(200).json({
59
- success: true,
60
- });
61
- } catch (err) {
62
- res.status(500).json({
63
- success: false,
64
- error: err instanceof Error ? err.message : String(err),
65
- });
66
- }
67
- };
68
- };
@@ -1,24 +0,0 @@
1
- import {RENDER_FN_PREFIX} from './constants';
2
-
3
- type ReturnType = {
4
- version: string;
5
- memorySizeInMb: number;
6
- diskSizeInMb: number;
7
- timeoutInSeconds: number;
8
- };
9
-
10
- export const parseFunctionName = (functionName: string): ReturnType | null => {
11
- const match = functionName.match(
12
- new RegExp(RENDER_FN_PREFIX + '(.*)-mem(\\d+)mb-disk(\\d+)mb-(\\d+)sec$'),
13
- );
14
- if (!match) {
15
- return null;
16
- }
17
-
18
- return {
19
- version: match[1],
20
- memorySizeInMb: parseInt(match[2], 10),
21
- diskSizeInMb: parseInt(match[3], 10),
22
- timeoutInSeconds: parseInt(match[4], 10),
23
- };
24
- };
@@ -1,121 +0,0 @@
1
- import {GetObjectCommand, HeadObjectCommand} from '@aws-sdk/client-s3';
2
- import {getSignedUrl} from '@aws-sdk/s3-request-presigner';
3
- import {validateBucketName} from '@remotion/serverless-client';
4
- import {REMOTION_BUCKET_PREFIX} from './constants';
5
- import {getS3Client} from './get-s3-client';
6
- import type {AwsRegion} from './regions';
7
- import type {RequestHandler} from './types';
8
- import {validatePresignExpiration} from './validate-presign-expiration';
9
-
10
- type MandatoryParameters = {
11
- region: AwsRegion;
12
- bucketName: string;
13
- objectKey: string;
14
- expiresInSeconds: number;
15
- };
16
-
17
- type OptionalParameters<CheckIfObjectExists extends boolean> = {
18
- checkIfObjectExists: CheckIfObjectExists;
19
- forcePathStyle: boolean;
20
- };
21
-
22
- export type PresignUrlInput<CheckIfObjectExists extends boolean = boolean> =
23
- MandatoryParameters &
24
- Partial<OptionalParameters<CheckIfObjectExists>> & {
25
- requestHandler?: RequestHandler;
26
- };
27
- type PresignUrlInputInternal<CheckIfObjectExists extends boolean> =
28
- MandatoryParameters &
29
- OptionalParameters<CheckIfObjectExists> & {
30
- requestHandler?: RequestHandler;
31
- };
32
-
33
- const internalPresignUrl = async <CheckIfObjectExists extends boolean = false>({
34
- region,
35
- bucketName,
36
- objectKey,
37
- checkIfObjectExists,
38
- expiresInSeconds,
39
- forcePathStyle,
40
- requestHandler,
41
- }: PresignUrlInputInternal<CheckIfObjectExists>): Promise<
42
- CheckIfObjectExists extends true ? string | null : string
43
- > => {
44
- validateBucketName({
45
- bucketName,
46
- bucketNamePrefix: REMOTION_BUCKET_PREFIX,
47
- options: {mustStartWithRemotion: false},
48
- });
49
- validatePresignExpiration(expiresInSeconds);
50
-
51
- const s3Client = getS3Client({
52
- region,
53
- customCredentials: null,
54
- forcePathStyle,
55
- requestHandler: requestHandler ?? null,
56
- });
57
-
58
- if (checkIfObjectExists === true) {
59
- try {
60
- await s3Client.send(
61
- new HeadObjectCommand({
62
- Bucket: bucketName,
63
- Key: objectKey,
64
- }),
65
- );
66
- } catch (err) {
67
- if ((err as {name: string}).name === 'NotFound') {
68
- return null as unknown as string;
69
- }
70
-
71
- if (
72
- (err as Error).message === 'UnknownError' ||
73
- (err as {$metadata: {httpStatusCode: number}}).$metadata
74
- .httpStatusCode === 403
75
- ) {
76
- throw new Error(
77
- `Unable to access item "${objectKey}" from bucket "${bucketName}". You must have permission for both "s3:GetObject" and "s3:ListBucket" actions.`,
78
- );
79
- }
80
-
81
- throw err;
82
- }
83
- }
84
-
85
- const objCommand = new GetObjectCommand({
86
- Bucket: bucketName,
87
- Key: objectKey,
88
- });
89
-
90
- const publicUrl = await getSignedUrl(s3Client, objCommand, {
91
- expiresIn: expiresInSeconds,
92
- });
93
-
94
- return publicUrl;
95
- };
96
-
97
- /*
98
- * @description Takes a private S3 object and turns it into a public URL by signing it with your AWS credentials.
99
- * @see [Documentation](https://remotion.dev/docs/lambda/presignurl)
100
- */
101
- export const presignUrl = <CheckIfObjectExists extends boolean = false>({
102
- region,
103
- bucketName,
104
- objectKey,
105
- checkIfObjectExists,
106
- expiresInSeconds,
107
- forcePathStyle,
108
- requestHandler,
109
- }: PresignUrlInput<CheckIfObjectExists>): Promise<
110
- CheckIfObjectExists extends true ? string | null : string
111
- > => {
112
- return internalPresignUrl({
113
- region,
114
- bucketName,
115
- objectKey,
116
- checkIfObjectExists: checkIfObjectExists ?? false,
117
- expiresInSeconds,
118
- forcePathStyle: forcePathStyle ?? false,
119
- requestHandler,
120
- });
121
- };