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