@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.
Files changed (227) hide show
  1. package/.turbo/turbo-make.log +6 -0
  2. package/LICENSE.md +49 -0
  3. package/README.md +5 -0
  4. package/bundle.ts +20 -0
  5. package/dist/app-router-webhook.d.ts +10 -0
  6. package/dist/app-router-webhook.js +43 -0
  7. package/dist/apply-lifecycle.d.ts +8 -0
  8. package/dist/apply-lifecycle.js +18 -0
  9. package/dist/aws-clients.d.ts +11 -0
  10. package/dist/aws-clients.js +51 -0
  11. package/dist/aws-provider.d.ts +23 -0
  12. package/dist/aws-provider.js +94 -0
  13. package/dist/bucket-exists.d.ts +3 -0
  14. package/dist/bucket-exists.js +26 -0
  15. package/dist/call-lambda-async.d.ts +2 -0
  16. package/dist/call-lambda-async.js +20 -0
  17. package/dist/call-lambda-streaming.d.ts +6 -0
  18. package/dist/call-lambda-streaming.js +125 -0
  19. package/dist/call-lambda-sync.d.ts +2 -0
  20. package/dist/call-lambda-sync.js +30 -0
  21. package/dist/check-credentials.d.ts +1 -0
  22. package/dist/check-credentials.js +39 -0
  23. package/dist/clean-items.d.ts +16 -0
  24. package/dist/clean-items.js +25 -0
  25. package/dist/constants.d.ts +25 -0
  26. package/dist/constants.js +26 -0
  27. package/dist/content-disposition-header.d.ts +2 -0
  28. package/dist/content-disposition-header.js +50 -0
  29. package/dist/convert-to-serve-url.d.ts +6 -0
  30. package/dist/convert-to-serve-url.js +14 -0
  31. package/dist/create-bucket.d.ts +3 -0
  32. package/dist/create-bucket.js +45 -0
  33. package/dist/delete-file.d.ts +3 -0
  34. package/dist/delete-file.js +12 -0
  35. package/dist/delete-function.d.ts +4 -0
  36. package/dist/delete-function.js +15 -0
  37. package/dist/delete-render.d.ts +20 -0
  38. package/dist/delete-render.js +84 -0
  39. package/dist/encode-aws-url-params.d.ts +1 -0
  40. package/dist/encode-aws-url-params.js +7 -0
  41. package/dist/esm/constants.mjs +45 -0
  42. package/dist/esm/index.mjs +6516 -0
  43. package/dist/esm/regions.mjs +50 -0
  44. package/dist/estimate-price.d.ts +17 -0
  45. package/dist/estimate-price.js +45 -0
  46. package/dist/express-webhook.d.ts +3 -0
  47. package/dist/express-webhook.js +46 -0
  48. package/dist/get-account-id.d.ts +3 -0
  49. package/dist/get-account-id.js +15 -0
  50. package/dist/get-aws-client.d.ts +30 -0
  51. package/dist/get-aws-client.js +56 -0
  52. package/dist/get-aws-urls.d.ts +25 -0
  53. package/dist/get-aws-urls.js +31 -0
  54. package/dist/get-buckets.d.ts +9 -0
  55. package/dist/get-buckets.js +62 -0
  56. package/dist/get-compositions-on-lambda.d.ts +18 -0
  57. package/dist/get-compositions-on-lambda.js +59 -0
  58. package/dist/get-credentials.d.ts +9 -0
  59. package/dist/get-credentials.js +55 -0
  60. package/dist/get-env-variable.d.ts +1 -0
  61. package/dist/get-env-variable.js +15 -0
  62. package/dist/get-function-name.d.ts +8 -0
  63. package/dist/get-function-name.js +17 -0
  64. package/dist/get-function-version.d.ts +7 -0
  65. package/dist/get-function-version.js +32 -0
  66. package/dist/get-functions.d.ts +8 -0
  67. package/dist/get-functions.js +77 -0
  68. package/dist/get-output-url-from-metadata.d.ts +3 -0
  69. package/dist/get-output-url-from-metadata.js +18 -0
  70. package/dist/get-render-progress.d.ts +15 -0
  71. package/dist/get-render-progress.js +45 -0
  72. package/dist/get-s3-client.d.ts +9 -0
  73. package/dist/get-s3-client.js +14 -0
  74. package/dist/get-service-client.d.ts +23 -0
  75. package/dist/get-service-client.js +120 -0
  76. package/dist/get-sites.d.ts +29 -0
  77. package/dist/get-sites.js +79 -0
  78. package/dist/head-file.d.ts +3 -0
  79. package/dist/head-file.js +17 -0
  80. package/dist/index.d.ts +123 -0
  81. package/dist/index.js +104 -0
  82. package/dist/is-cli.d.ts +2 -0
  83. package/dist/is-cli.js +10 -0
  84. package/dist/is-flaky-error.d.ts +1 -0
  85. package/dist/is-flaky-error.js +77 -0
  86. package/dist/is-in-lambda.d.ts +1 -0
  87. package/dist/is-in-lambda.js +9 -0
  88. package/dist/is-likely-to-have-aws-profile.d.ts +1 -0
  89. package/dist/is-likely-to-have-aws-profile.js +50 -0
  90. package/dist/lambda-version-string.d.ts +1 -0
  91. package/dist/lambda-version-string.js +7 -0
  92. package/dist/lifecycle-rules.d.ts +10 -0
  93. package/dist/lifecycle-rules.js +61 -0
  94. package/dist/lifecycle.d.ts +7 -0
  95. package/dist/lifecycle.js +24 -0
  96. package/dist/list-objects.d.ts +3 -0
  97. package/dist/list-objects.js +67 -0
  98. package/dist/make-lambda-payload.d.ts +54 -0
  99. package/dist/make-lambda-payload.js +148 -0
  100. package/dist/make-s3-url.d.ts +6 -0
  101. package/dist/make-s3-url.js +7 -0
  102. package/dist/p-limit.d.ts +1 -0
  103. package/dist/p-limit.js +57 -0
  104. package/dist/pages-router-webhook.d.ts +5 -0
  105. package/dist/pages-router-webhook.js +48 -0
  106. package/dist/parse-function-name.d.ts +8 -0
  107. package/dist/parse-function-name.js +17 -0
  108. package/dist/presign-url.d.ts +14 -0
  109. package/dist/presign-url.js +64 -0
  110. package/dist/price-per-1s.d.ts +37 -0
  111. package/dist/price-per-1s.js +822 -0
  112. package/dist/random-hash.d.ts +1 -0
  113. package/dist/random-hash.js +13 -0
  114. package/dist/read-file.d.ts +9 -0
  115. package/dist/read-file.js +18 -0
  116. package/dist/regions.d.ts +3 -0
  117. package/dist/regions.js +48 -0
  118. package/dist/render-media-on-lambda.d.ts +61 -0
  119. package/dist/render-media-on-lambda.js +127 -0
  120. package/dist/render-still-on-lambda.d.ts +53 -0
  121. package/dist/render-still-on-lambda.js +118 -0
  122. package/dist/runtime-preference.d.ts +2 -0
  123. package/dist/runtime-preference.js +8 -0
  124. package/dist/speculate-function-name.d.ts +6 -0
  125. package/dist/speculate-function-name.js +20 -0
  126. package/dist/test/encode-aws-url.test.d.ts +1 -0
  127. package/dist/test/encode-aws-url.test.js +8 -0
  128. package/dist/test/price-calculation.test.d.ts +1 -0
  129. package/dist/test/price-calculation.test.js +61 -0
  130. package/dist/test/pricing.test.d.ts +1 -0
  131. package/dist/test/pricing.test.js +27 -0
  132. package/dist/test/validate-disk-size-in-mb.test.d.ts +1 -0
  133. package/dist/test/validate-disk-size-in-mb.test.js +14 -0
  134. package/dist/validate-aws-region.d.ts +2 -0
  135. package/dist/validate-aws-region.js +9 -0
  136. package/dist/validate-bucketname.d.ts +4 -0
  137. package/dist/validate-bucketname.js +15 -0
  138. package/dist/validate-disk-size-in-mb.d.ts +1 -0
  139. package/dist/validate-disk-size-in-mb.js +23 -0
  140. package/dist/validate-lambda-codec.d.ts +2 -0
  141. package/dist/validate-lambda-codec.js +21 -0
  142. package/dist/validate-memory-size.d.ts +1 -0
  143. package/dist/validate-memory-size.js +22 -0
  144. package/dist/validate-presign-expiration.d.ts +1 -0
  145. package/dist/validate-presign-expiration.js +29 -0
  146. package/dist/validate-serveurl.d.ts +1 -0
  147. package/dist/validate-serveurl.js +9 -0
  148. package/dist/validate-webhook-signature.d.ts +5 -0
  149. package/dist/validate-webhook-signature.js +28 -0
  150. package/dist/write-file.d.ts +5 -0
  151. package/dist/write-file.js +56 -0
  152. package/eslint.config.mjs +5 -0
  153. package/package.json +71 -0
  154. package/src/app-router-webhook.ts +64 -0
  155. package/src/apply-lifecycle.ts +30 -0
  156. package/src/aws-clients.ts +60 -0
  157. package/src/aws-provider.ts +135 -0
  158. package/src/bucket-exists.ts +28 -0
  159. package/src/call-lambda-async.ts +39 -0
  160. package/src/call-lambda-streaming.ts +219 -0
  161. package/src/call-lambda-sync.ts +55 -0
  162. package/src/check-credentials.ts +51 -0
  163. package/src/clean-items.ts +47 -0
  164. package/src/constants.ts +38 -0
  165. package/src/content-disposition-header.ts +64 -0
  166. package/src/convert-to-serve-url.ts +24 -0
  167. package/src/create-bucket.ts +67 -0
  168. package/src/delete-file.ts +30 -0
  169. package/src/delete-function.ts +24 -0
  170. package/src/delete-render.ts +107 -0
  171. package/src/encode-aws-url-params.ts +3 -0
  172. package/src/estimate-price.ts +95 -0
  173. package/src/express-webhook.ts +50 -0
  174. package/src/get-account-id.ts +22 -0
  175. package/src/get-aws-client.ts +59 -0
  176. package/src/get-aws-urls.ts +85 -0
  177. package/src/get-buckets.ts +81 -0
  178. package/src/get-compositions-on-lambda.ts +104 -0
  179. package/src/get-credentials.ts +81 -0
  180. package/src/get-env-variable.ts +15 -0
  181. package/src/get-function-name.ts +24 -0
  182. package/src/get-function-version.ts +43 -0
  183. package/src/get-functions.ts +103 -0
  184. package/src/get-output-url-from-metadata.ts +23 -0
  185. package/src/get-render-progress.ts +62 -0
  186. package/src/get-s3-client.ts +22 -0
  187. package/src/get-service-client.ts +178 -0
  188. package/src/get-sites.ts +128 -0
  189. package/src/head-file.ts +28 -0
  190. package/src/index.ts +147 -0
  191. package/src/is-cli.ts +7 -0
  192. package/src/is-flaky-error.ts +101 -0
  193. package/src/is-in-lambda.ts +5 -0
  194. package/src/is-likely-to-have-aws-profile.ts +55 -0
  195. package/src/lambda-version-string.ts +5 -0
  196. package/src/lifecycle-rules.ts +104 -0
  197. package/src/lifecycle.ts +44 -0
  198. package/src/list-objects.ts +83 -0
  199. package/src/make-lambda-payload.ts +317 -0
  200. package/src/make-s3-url.ts +13 -0
  201. package/src/p-limit.ts +75 -0
  202. package/src/pages-router-webhook.ts +58 -0
  203. package/src/parse-function-name.ts +24 -0
  204. package/src/presign-url.ts +110 -0
  205. package/src/price-per-1s.ts +863 -0
  206. package/src/random-hash.ts +10 -0
  207. package/src/read-file.ts +31 -0
  208. package/src/regions.ts +48 -0
  209. package/src/render-media-on-lambda.ts +216 -0
  210. package/src/render-still-on-lambda.ts +195 -0
  211. package/src/runtime-preference.ts +7 -0
  212. package/src/speculate-function-name.ts +27 -0
  213. package/src/test/encode-aws-url.test.ts +7 -0
  214. package/src/test/price-calculation.test.ts +61 -0
  215. package/src/test/pricing.test.ts +32 -0
  216. package/src/test/validate-disk-size-in-mb.test.ts +15 -0
  217. package/src/validate-aws-region.ts +14 -0
  218. package/src/validate-bucketname.ts +24 -0
  219. package/src/validate-disk-size-in-mb.ts +37 -0
  220. package/src/validate-lambda-codec.ts +28 -0
  221. package/src/validate-memory-size.ts +31 -0
  222. package/src/validate-presign-expiration.ts +46 -0
  223. package/src/validate-serveurl.ts +9 -0
  224. package/src/validate-webhook-signature.ts +42 -0
  225. package/src/write-file.ts +74 -0
  226. package/tsconfig.json +9 -0
  227. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,37 @@
1
+ import {
2
+ MAX_EPHEMERAL_STORAGE_IN_MB,
3
+ MIN_EPHEMERAL_STORAGE_IN_MB,
4
+ } from './constants';
5
+
6
+ export const validateDiskSizeInMb = (diskSizeInMb: unknown) => {
7
+ if (typeof diskSizeInMb !== 'number') {
8
+ throw new TypeError(
9
+ `parameter 'diskSizeInMb' must be a number, got a ${typeof diskSizeInMb}`,
10
+ );
11
+ }
12
+
13
+ if (Number.isNaN(diskSizeInMb)) {
14
+ throw new TypeError(`parameter 'diskSizeInMb' must not be NaN, but is`);
15
+ }
16
+
17
+ if (!Number.isFinite(diskSizeInMb)) {
18
+ throw new TypeError(
19
+ `parameter 'diskSizeInMb' must be finite, but is ${diskSizeInMb}`,
20
+ );
21
+ }
22
+
23
+ if (
24
+ diskSizeInMb < MIN_EPHEMERAL_STORAGE_IN_MB ||
25
+ diskSizeInMb > MAX_EPHEMERAL_STORAGE_IN_MB
26
+ ) {
27
+ throw new TypeError(
28
+ `parameter 'diskSizeInMb' must be between ${MIN_EPHEMERAL_STORAGE_IN_MB} and ${MAX_EPHEMERAL_STORAGE_IN_MB}, but got ${diskSizeInMb}`,
29
+ );
30
+ }
31
+
32
+ if (diskSizeInMb % 1 !== 0) {
33
+ throw new TypeError(
34
+ `parameter 'diskSizeInMb' must be an integer but got ${diskSizeInMb}`,
35
+ );
36
+ }
37
+ };
@@ -0,0 +1,28 @@
1
+ /* eslint-disable no-console */
2
+ import type {ServerlessCodec} from '@remotion/serverless-client';
3
+ import {serverlessCodecs} from '@remotion/serverless-client';
4
+
5
+ export const validateLambdaCodec = (codec: unknown): ServerlessCodec => {
6
+ if (typeof codec !== 'string') {
7
+ throw new TypeError('"codec" must be a string ');
8
+ }
9
+
10
+ if (!(serverlessCodecs as readonly string[]).includes(codec)) {
11
+ throw new TypeError(
12
+ "'" +
13
+ codec +
14
+ "' is not a valid codec for Lambda. The following values are supported: " +
15
+ serverlessCodecs.join(', '),
16
+ );
17
+ }
18
+
19
+ if ((codec as string) === 'h264-mkv') {
20
+ console.warn(
21
+ 'The "h264-mkv" codec for renderMediaOnLambda() is deprecated - it\'s now just "h264".',
22
+ );
23
+
24
+ return 'h264';
25
+ }
26
+
27
+ return codec as ServerlessCodec;
28
+ };
@@ -0,0 +1,31 @@
1
+ import {MAX_MEMORY, MIN_MEMORY} from './constants';
2
+
3
+ export const validateMemorySize = (memorySizeInMb: unknown) => {
4
+ if (typeof memorySizeInMb !== 'number') {
5
+ throw new TypeError(
6
+ `parameter 'memorySizeInMb' must be a number, got a ${typeof memorySizeInMb}`,
7
+ );
8
+ }
9
+
10
+ if (Number.isNaN(memorySizeInMb)) {
11
+ throw new TypeError(`parameter 'memorySizeInMb' must not be NaN, but is`);
12
+ }
13
+
14
+ if (!Number.isFinite(memorySizeInMb)) {
15
+ throw new TypeError(
16
+ `parameter 'memorySizeInMb' must be finite, but is ${memorySizeInMb}`,
17
+ );
18
+ }
19
+
20
+ if (memorySizeInMb < MIN_MEMORY || memorySizeInMb > MAX_MEMORY) {
21
+ throw new TypeError(
22
+ `parameter 'memorySizeInMb' must be between ${MIN_MEMORY} and ${MAX_MEMORY}, but got ${memorySizeInMb}`,
23
+ );
24
+ }
25
+
26
+ if (memorySizeInMb % 1 !== 0) {
27
+ throw new TypeError(
28
+ `parameter 'memorySizeInMb' must be an integer but got ${memorySizeInMb}`,
29
+ );
30
+ }
31
+ };
@@ -0,0 +1,46 @@
1
+ const MAX_PRESIGN_EXPIRATION = 604800;
2
+ const MIN_PRESIGN_EXPIRATION = 1;
3
+
4
+ export const validatePresignExpiration = (presignExpiration: unknown) => {
5
+ if (typeof presignExpiration === 'undefined' || presignExpiration === null) {
6
+ return;
7
+ }
8
+
9
+ if (typeof presignExpiration !== 'number') {
10
+ throw new TypeError(
11
+ `'expiresIn' should be a number, but is ${JSON.stringify(
12
+ presignExpiration,
13
+ )}`,
14
+ );
15
+ }
16
+
17
+ if (Number.isNaN(presignExpiration)) {
18
+ throw new TypeError(`'expiresIn' should not be NaN, but is NaN`);
19
+ }
20
+
21
+ if (!Number.isFinite(presignExpiration)) {
22
+ throw new TypeError(
23
+ `'expiresIn' should be finite but is ${presignExpiration}`,
24
+ );
25
+ }
26
+
27
+ if (presignExpiration % 1 !== 0) {
28
+ throw new TypeError(
29
+ `'expiresIn' should be an integer but is ${JSON.stringify(
30
+ presignExpiration,
31
+ )}`,
32
+ );
33
+ }
34
+
35
+ if (presignExpiration > MAX_PRESIGN_EXPIRATION) {
36
+ throw new TypeError(
37
+ `The 'expiresIn' parameter must be less or equal than ${MAX_PRESIGN_EXPIRATION} (7 days) as enforced by AWS`,
38
+ );
39
+ }
40
+
41
+ if (presignExpiration < MIN_PRESIGN_EXPIRATION) {
42
+ throw new TypeError(
43
+ `The 'expiresIn' parameter must be greater or equal than ${MIN_PRESIGN_EXPIRATION}`,
44
+ );
45
+ }
46
+ };
@@ -0,0 +1,9 @@
1
+ export const validateServeUrl = (serveUrl: unknown) => {
2
+ if (typeof serveUrl !== 'string') {
3
+ throw new TypeError(
4
+ `"serveURL" parameter must be a string, but is ${JSON.stringify(
5
+ serveUrl,
6
+ )}`,
7
+ );
8
+ }
9
+ };
@@ -0,0 +1,42 @@
1
+ /*
2
+ * @description Validates that the signature received by a webhook endpoint is authentic. If validation fails, an error is thrown.
3
+ * @see [Documentation](https://remotion.dev/docs/lambda/validatewebhooksignature)
4
+ */
5
+ export const validateWebhookSignature = ({
6
+ secret,
7
+ body,
8
+ signatureHeader,
9
+ }: {
10
+ secret: string;
11
+ body: unknown;
12
+ signatureHeader: string;
13
+ }) => {
14
+ if (!secret) {
15
+ throw new TypeError(
16
+ "No 'secret' was provided to validateWebhookSignature().",
17
+ );
18
+ }
19
+
20
+ if (!body) {
21
+ throw new TypeError(
22
+ "No 'body' was provided to validateWebhookSignature().",
23
+ );
24
+ }
25
+
26
+ if (typeof require === 'undefined') {
27
+ throw new Error('validateWebhookSignature can only be called from Node.JS');
28
+ }
29
+
30
+ const Crypto = require('crypto');
31
+
32
+ const hmac = Crypto.createHmac('sha512', secret);
33
+ const signature = `sha512=${hmac.update(JSON.stringify(body)).digest('hex')}`;
34
+
35
+ if (!signatureHeader || signatureHeader === 'NO_SECRET_PROVIDED') {
36
+ throw new Error('No webhook signature was provided');
37
+ }
38
+
39
+ if (signatureHeader !== signature) {
40
+ throw new Error('Signatures do not match');
41
+ }
42
+ };
@@ -0,0 +1,74 @@
1
+ /* eslint-disable no-console */
2
+ import {PutObjectCommand} from '@aws-sdk/client-s3';
3
+ import type {
4
+ CustomCredentials,
5
+ WriteFileInput,
6
+ } from '@remotion/serverless-client';
7
+ import mimeTypes from 'mime-types';
8
+ import type {AwsProvider} from './aws-provider';
9
+ import {getContentDispositionHeader} from './content-disposition-header';
10
+ import {getS3Client} from './get-s3-client';
11
+
12
+ const tryLambdaWriteFile = async ({
13
+ bucketName,
14
+ key,
15
+ body,
16
+ region,
17
+ privacy,
18
+ expectedBucketOwner,
19
+ downloadBehavior,
20
+ customCredentials,
21
+ forcePathStyle,
22
+ }: WriteFileInput<AwsProvider>): Promise<void> => {
23
+ await getS3Client({
24
+ region,
25
+ customCredentials: customCredentials as CustomCredentials<AwsProvider>,
26
+ forcePathStyle,
27
+ }).send(
28
+ new PutObjectCommand({
29
+ Bucket: bucketName,
30
+ Key: key,
31
+ Body: body,
32
+ ACL:
33
+ privacy === 'no-acl'
34
+ ? undefined
35
+ : privacy === 'private'
36
+ ? 'private'
37
+ : 'public-read',
38
+ ExpectedBucketOwner: customCredentials
39
+ ? undefined
40
+ : (expectedBucketOwner ?? undefined),
41
+ ContentType: mimeTypes.lookup(key) || 'application/octet-stream',
42
+ ContentDisposition: getContentDispositionHeader(downloadBehavior),
43
+ }),
44
+ );
45
+ };
46
+
47
+ export const lambdaWriteFileImplementation = async (
48
+ params: WriteFileInput<AwsProvider> & {
49
+ retries?: number;
50
+ },
51
+ ): Promise<void> => {
52
+ const remainingRetries = params.retries ?? 2;
53
+ try {
54
+ await tryLambdaWriteFile(params);
55
+ } catch (err) {
56
+ if (remainingRetries === 0) {
57
+ throw err;
58
+ }
59
+
60
+ const backoff = 2 ** (2 - remainingRetries) * 2000;
61
+ await new Promise((resolve) => {
62
+ setTimeout(resolve, backoff);
63
+ });
64
+
65
+ console.warn('Failed to write file to storage:');
66
+ console.warn(err);
67
+ console.warn(`Retrying (${remainingRetries} retries remaining)...`);
68
+
69
+ return lambdaWriteFileImplementation({
70
+ ...params,
71
+ retries: remainingRetries - 1,
72
+ });
73
+ }
74
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../tsconfig.settings.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src"],
8
+ "references": [{"path": "../serverless-client"}]
9
+ }