@transloadit/node 4.2.0 → 4.3.1
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/README.md +116 -4
- package/dist/Transloadit.d.ts +45 -4
- package/dist/Transloadit.d.ts.map +1 -1
- package/dist/Transloadit.js +104 -21
- package/dist/Transloadit.js.map +1 -1
- package/dist/alphalib/assembly-linter.d.ts +123 -0
- package/dist/alphalib/assembly-linter.d.ts.map +1 -0
- package/dist/alphalib/assembly-linter.js +1142 -0
- package/dist/alphalib/assembly-linter.js.map +1 -0
- package/dist/alphalib/assembly-linter.lang.en.d.ts +87 -0
- package/dist/alphalib/assembly-linter.lang.en.d.ts.map +1 -0
- package/dist/alphalib/assembly-linter.lang.en.js +326 -0
- package/dist/alphalib/assembly-linter.lang.en.js.map +1 -0
- package/dist/alphalib/goldenTemplates.d.ts +52 -0
- package/dist/alphalib/goldenTemplates.d.ts.map +1 -0
- package/dist/alphalib/goldenTemplates.js +46 -0
- package/dist/alphalib/goldenTemplates.js.map +1 -0
- package/dist/alphalib/object.d.ts +20 -0
- package/dist/alphalib/object.d.ts.map +1 -0
- package/dist/alphalib/object.js +23 -0
- package/dist/alphalib/object.js.map +1 -0
- package/dist/alphalib/stepParsing.d.ts +93 -0
- package/dist/alphalib/stepParsing.d.ts.map +1 -0
- package/dist/alphalib/stepParsing.js +1154 -0
- package/dist/alphalib/stepParsing.js.map +1 -0
- package/dist/alphalib/templateMerge.d.ts +4 -0
- package/dist/alphalib/templateMerge.d.ts.map +1 -0
- package/dist/alphalib/templateMerge.js +22 -0
- package/dist/alphalib/templateMerge.js.map +1 -0
- package/dist/cli/commands/assemblies.d.ts +20 -1
- package/dist/cli/commands/assemblies.d.ts.map +1 -1
- package/dist/cli/commands/assemblies.js +137 -2
- package/dist/cli/commands/assemblies.js.map +1 -1
- package/dist/cli/commands/auth.d.ts.map +1 -1
- package/dist/cli/commands/auth.js +19 -19
- package/dist/cli/commands/auth.js.map +1 -1
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +2 -1
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/docs/assemblyLintingExamples.d.ts +2 -0
- package/dist/cli/docs/assemblyLintingExamples.d.ts.map +1 -0
- package/dist/cli/docs/assemblyLintingExamples.js +10 -0
- package/dist/cli/docs/assemblyLintingExamples.js.map +1 -0
- package/dist/cli/helpers.d.ts +11 -0
- package/dist/cli/helpers.d.ts.map +1 -1
- package/dist/cli/helpers.js +29 -0
- package/dist/cli/helpers.js.map +1 -1
- package/dist/inputFiles.d.ts +41 -0
- package/dist/inputFiles.d.ts.map +1 -0
- package/dist/inputFiles.js +214 -0
- package/dist/inputFiles.js.map +1 -0
- package/dist/lintAssemblyInput.d.ts +10 -0
- package/dist/lintAssemblyInput.d.ts.map +1 -0
- package/dist/lintAssemblyInput.js +73 -0
- package/dist/lintAssemblyInput.js.map +1 -0
- package/dist/lintAssemblyInstructions.d.ts +29 -0
- package/dist/lintAssemblyInstructions.d.ts.map +1 -0
- package/dist/lintAssemblyInstructions.js +33 -0
- package/dist/lintAssemblyInstructions.js.map +1 -0
- package/dist/robots.d.ts +38 -0
- package/dist/robots.d.ts.map +1 -0
- package/dist/robots.js +230 -0
- package/dist/robots.js.map +1 -0
- package/dist/tus.d.ts +5 -1
- package/dist/tus.d.ts.map +1 -1
- package/dist/tus.js +80 -6
- package/dist/tus.js.map +1 -1
- package/package.json +5 -2
- package/src/Transloadit.ts +170 -26
- package/src/alphalib/assembly-linter.lang.en.ts +393 -0
- package/src/alphalib/assembly-linter.ts +1475 -0
- package/src/alphalib/goldenTemplates.ts +53 -0
- package/src/alphalib/object.ts +27 -0
- package/src/alphalib/stepParsing.ts +1465 -0
- package/src/alphalib/templateMerge.ts +32 -0
- package/src/alphalib/typings/json-to-ast.d.ts +34 -0
- package/src/cli/commands/assemblies.ts +161 -2
- package/src/cli/commands/auth.ts +19 -22
- package/src/cli/commands/index.ts +2 -0
- package/src/cli/docs/assemblyLintingExamples.ts +9 -0
- package/src/cli/helpers.ts +50 -0
- package/src/inputFiles.ts +278 -0
- package/src/lintAssemblyInput.ts +89 -0
- package/src/lintAssemblyInstructions.ts +72 -0
- package/src/robots.ts +317 -0
- package/src/tus.ts +91 -5
package/README.md
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
[](https://github.com/transloadit/node-sdk/actions/workflows/ci.yml)
|
|
2
2
|
[](https://codecov.io/gh/transloadit/node-sdk)
|
|
3
3
|
|
|
4
|
-
> **Stability: Experimental.** This scoped package is new and may change without notice.
|
|
5
|
-
> For the stable SDK, use the unscoped `transloadit` package.
|
|
6
|
-
|
|
7
4
|
<a href="https://transloadit.com/?utm_source=github&utm_medium=referral&utm_campaign=sdks&utm_content=node_sdk">
|
|
8
5
|
<picture>
|
|
9
6
|
<source media="(prefers-color-scheme: dark)" srcset="https://assets.transloadit.com/assets/images/sponsorships/logo-dark.svg">
|
|
@@ -112,6 +109,76 @@ npx transloadit assemblies replay --steps new-steps.json ASSEMBLY_ID
|
|
|
112
109
|
npx transloadit assemblies replay --reparse-template ASSEMBLY_ID
|
|
113
110
|
```
|
|
114
111
|
|
|
112
|
+
### Linting Assembly Instructions
|
|
113
|
+
|
|
114
|
+
Lint Assembly Instructions locally using the same linter as the API.
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# From a JSON file (full instructions or steps-only)
|
|
118
|
+
npx transloadit assemblies lint --steps steps.json
|
|
119
|
+
|
|
120
|
+
# From stdin
|
|
121
|
+
cat steps.json | npx transloadit assemblies lint
|
|
122
|
+
|
|
123
|
+
# Merge template content before linting
|
|
124
|
+
npx transloadit assemblies lint --template TEMPLATE_ID --steps steps.json
|
|
125
|
+
|
|
126
|
+
# Treat warnings as fatal; apply fixes (overwrites files / stdout for stdin)
|
|
127
|
+
npx transloadit assemblies lint --fatal warning --fix --steps steps.json
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
When both `--template` and steps input are provided, Transloadit merges the template content with
|
|
131
|
+
the provided steps before linting, matching the API's runtime behavior. If the template sets
|
|
132
|
+
`allow_steps_override=false`, providing steps will fail with `TEMPLATE_DENIES_STEPS_OVERRIDE`.
|
|
133
|
+
|
|
134
|
+
## SDK Helpers
|
|
135
|
+
|
|
136
|
+
### prepareInputFiles
|
|
137
|
+
|
|
138
|
+
`prepareInputFiles()` converts mixed file inputs into `files`, `uploads`, and optional
|
|
139
|
+
`/http/import` steps so you can pass them directly into `createAssembly()` or
|
|
140
|
+
`resumeAssemblyUploads()`.
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
import { prepareInputFiles } from '@transloadit/node'
|
|
144
|
+
|
|
145
|
+
const prepared = await prepareInputFiles({
|
|
146
|
+
inputFiles: [
|
|
147
|
+
{ kind: 'path', field: 'video', path: '/tmp/video.mp4' },
|
|
148
|
+
{ kind: 'base64', field: 'logo', filename: 'logo.png', base64: '...' },
|
|
149
|
+
{ kind: 'url', field: 'remote', url: 'https://example.com/file.jpg' },
|
|
150
|
+
],
|
|
151
|
+
params: {
|
|
152
|
+
steps: {
|
|
153
|
+
':original': { robot: '/upload/handle' },
|
|
154
|
+
encode: { robot: '/video/encode', use: ':original' },
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
base64Strategy: 'tempfile',
|
|
158
|
+
urlStrategy: 'import-if-present',
|
|
159
|
+
maxBase64Bytes: 512_000,
|
|
160
|
+
allowPrivateUrls: true,
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
await client.createAssembly({
|
|
164
|
+
params: prepared.params,
|
|
165
|
+
files: prepared.files,
|
|
166
|
+
uploads: prepared.uploads,
|
|
167
|
+
})
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Options:
|
|
171
|
+
|
|
172
|
+
- `inputFiles` – Array of `{ kind, field, ... }` entries for `path`, `base64`, or `url` inputs.
|
|
173
|
+
- `params` – Assembly instructions; steps will be extended when URL imports are injected.
|
|
174
|
+
- `fields` – Extra form fields to merge into `params.fields`.
|
|
175
|
+
- `base64Strategy` – `'buffer'` (default) or `'tempfile'` for base64 inputs.
|
|
176
|
+
- `urlStrategy` – `'import'`, `'download'`, or `'import-if-present'` (default `'import'`).
|
|
177
|
+
- `maxBase64Bytes` – Optional size cap (decoded bytes). Overages throw before decoding.
|
|
178
|
+
- `allowPrivateUrls` – Allow downloading private/loopback URLs when using `urlStrategy: 'download'`
|
|
179
|
+
(default `true`). Hosted deployments should disable this.
|
|
180
|
+
- `tempDir` – Optional temp directory base when `base64Strategy: 'tempfile'`.
|
|
181
|
+
|
|
115
182
|
### Managing Templates
|
|
116
183
|
|
|
117
184
|
```bash
|
|
@@ -268,7 +335,8 @@ names stable and pass the same files. Only path-based inputs resume; Buffer/stri
|
|
|
268
335
|
start a new tus upload automatically.
|
|
269
336
|
|
|
270
337
|
You can pass the same upload and progress options as `createAssembly` (such as `chunkSize`,
|
|
271
|
-
`uploadConcurrency`, `waitForCompletion`, `timeout`, `onUploadProgress`, and
|
|
338
|
+
`uploadConcurrency`, `uploadBehavior`, `waitForCompletion`, `timeout`, `onUploadProgress`, and
|
|
339
|
+
`onAssemblyProgress`).
|
|
272
340
|
When `waitForCompletion` is `true`, the SDK will poll and resolve once the Assembly is finished.
|
|
273
341
|
|
|
274
342
|
```javascript
|
|
@@ -354,9 +422,17 @@ You can provide the following keys inside the `options` object:
|
|
|
354
422
|
- `onAssemblyProgress` - Once the Assembly has started processing this will be periodically called with the _Assembly Execution Status_ (result of `getAssembly`) **only if `waitForCompletion` is `true`**.
|
|
355
423
|
- `chunkSize` - (for uploads) a number indicating the maximum size of a tus `PATCH` request body in bytes. Default to `Infinity` for file uploads and 50MB for streams of unknown length. See [tus-js-client](https://github.com/tus/tus-js-client/blob/master/docs/api.md#chunksize).
|
|
356
424
|
- `uploadConcurrency` - Maximum number of concurrent tus file uploads to occur at any given time (default 10.)
|
|
425
|
+
- `uploadBehavior` - Controls how uploads are handled:
|
|
426
|
+
- `await` (default) waits for all uploads to finish.
|
|
427
|
+
- `background` starts uploads and returns once upload URLs are created.
|
|
428
|
+
- `none` returns upload URLs without uploading any bytes.
|
|
429
|
+
- When `uploadBehavior` is not `await`, `waitForCompletion` is ignored.
|
|
357
430
|
|
|
358
431
|
**NOTE**: Make sure the key in `files` and `uploads` is not one of `signature`, `params` or `max_size`.
|
|
359
432
|
|
|
433
|
+
When `uploadBehavior` is `background` or `none`, the resolved Assembly object includes
|
|
434
|
+
`upload_urls` with a map of field names to tus upload URLs.
|
|
435
|
+
|
|
360
436
|
Example code showing all options:
|
|
361
437
|
|
|
362
438
|
```js
|
|
@@ -416,6 +492,42 @@ See also:
|
|
|
416
492
|
- [API documentation](https://transloadit.com/docs/api/assemblies-post/)
|
|
417
493
|
- Error codes and retry logic below
|
|
418
494
|
|
|
495
|
+
#### async lintAssemblyInstructions(options)
|
|
496
|
+
|
|
497
|
+
Lint Assembly Instructions locally using the same linter as the API.
|
|
498
|
+
If you provide a `templateId`, the template content is fetched and merged with your instructions
|
|
499
|
+
before linting (matching the API's runtime merge behavior). If the template sets
|
|
500
|
+
`allow_steps_override=false`, providing steps will throw `TEMPLATE_DENIES_STEPS_OVERRIDE`.
|
|
501
|
+
|
|
502
|
+
The `options` object accepts:
|
|
503
|
+
|
|
504
|
+
- `assemblyInstructions` - Assembly Instructions as a JSON string, a full instructions object, or a steps-only object.
|
|
505
|
+
If no `steps` property is present, the object is treated as steps.
|
|
506
|
+
- `templateId` - Optional template ID to merge before linting.
|
|
507
|
+
- `fatal` - `'error' | 'warning'` (default: `'error'`). When set to `'warning'`, warnings are treated as fatal.
|
|
508
|
+
- `fix` - Apply auto-fixes where possible. If `true`, the result includes `fixedInstructions`.
|
|
509
|
+
|
|
510
|
+
The method returns:
|
|
511
|
+
|
|
512
|
+
- `success` - `true` when no fatal issues are found.
|
|
513
|
+
- `issues` - Array of lint issues (each includes `code`, `type`, `row`, `column`, and `desc`).
|
|
514
|
+
- `fixedInstructions` - The fixed JSON string when `fix` is `true` (steps-only inputs return steps-only JSON).
|
|
515
|
+
|
|
516
|
+
Example:
|
|
517
|
+
|
|
518
|
+
```js
|
|
519
|
+
const result = await transloadit.lintAssemblyInstructions({
|
|
520
|
+
assemblyInstructions: {
|
|
521
|
+
resize: { robot: '/image/resize', use: ':original', width: 100, height: 100 },
|
|
522
|
+
},
|
|
523
|
+
fatal: 'warning',
|
|
524
|
+
})
|
|
525
|
+
|
|
526
|
+
if (!result.success) {
|
|
527
|
+
console.log(result.issues)
|
|
528
|
+
}
|
|
529
|
+
```
|
|
530
|
+
|
|
419
531
|
#### async listAssemblies(params)
|
|
420
532
|
|
|
421
533
|
Retrieve Assemblies according to the given `params`.
|
package/dist/Transloadit.d.ts
CHANGED
|
@@ -5,15 +5,28 @@ import { ApiError } from './ApiError.ts';
|
|
|
5
5
|
import type { AssemblyIndexItem, AssemblyStatus } from './alphalib/types/assemblyStatus.ts';
|
|
6
6
|
import type { BaseResponse, BillResponse, CreateAssemblyParams, CreateTemplateCredentialParams, CreateTemplateParams, EditTemplateParams, ListAssembliesParams, ListedTemplate, ListTemplateCredentialsParams, ListTemplatesParams, OptionalAuthParams, PaginationListWithCount, ReplayAssemblyNotificationParams, ReplayAssemblyNotificationResponse, ReplayAssemblyParams, ReplayAssemblyResponse, TemplateCredentialResponse, TemplateCredentialsResponse, TemplateResponse } from './apiTypes.ts';
|
|
7
7
|
import InconsistentResponseError from './InconsistentResponseError.ts';
|
|
8
|
+
import type { LintAssemblyInstructionsInput, LintAssemblyInstructionsResult } from './lintAssemblyInstructions.ts';
|
|
8
9
|
import PaginationStream from './PaginationStream.ts';
|
|
10
|
+
import type { UploadBehavior } from './tus.ts';
|
|
9
11
|
export { HTTPError, MaxRedirectsError, ParseError, ReadError, RequestError, TimeoutError, UploadError, } from 'got';
|
|
12
|
+
export { goldenTemplates } from './alphalib/goldenTemplates.ts';
|
|
10
13
|
export type { AssemblyStatus } from './alphalib/types/assemblyStatus.ts';
|
|
11
14
|
export * from './apiTypes.ts';
|
|
12
15
|
export { InconsistentResponseError, ApiError };
|
|
16
|
+
export { mergeTemplateContent } from './alphalib/templateMerge.ts';
|
|
17
|
+
export type { Base64Strategy, InputFile, PrepareInputFilesOptions, PrepareInputFilesResult, UploadInput, UrlStrategy, } from './inputFiles.ts';
|
|
18
|
+
export { prepareInputFiles } from './inputFiles.ts';
|
|
19
|
+
export type { LintAssemblyInstructionsResult, LintFatalLevel } from './lintAssemblyInstructions.ts';
|
|
20
|
+
export type { RobotHelp, RobotHelpOptions, RobotListItem, RobotListOptions, RobotListResult, RobotParamHelp, } from './robots.ts';
|
|
21
|
+
export { getRobotHelp, listRobots } from './robots.ts';
|
|
13
22
|
export interface UploadProgress {
|
|
14
23
|
uploadedBytes?: number | undefined;
|
|
15
24
|
totalBytes?: number | undefined;
|
|
16
25
|
}
|
|
26
|
+
export type { UploadBehavior };
|
|
27
|
+
export type AssemblyStatusWithUploadUrls = AssemblyStatus & {
|
|
28
|
+
upload_urls?: Record<string, string>;
|
|
29
|
+
};
|
|
17
30
|
export type AssemblyProgress = (assembly: AssemblyStatus) => void;
|
|
18
31
|
interface AssemblyUploadOptions {
|
|
19
32
|
files?: {
|
|
@@ -22,6 +35,7 @@ interface AssemblyUploadOptions {
|
|
|
22
35
|
uploads?: {
|
|
23
36
|
[name: string]: Readable | IntoStreamInput;
|
|
24
37
|
};
|
|
38
|
+
uploadBehavior?: UploadBehavior;
|
|
25
39
|
waitForCompletion?: boolean;
|
|
26
40
|
chunkSize?: number;
|
|
27
41
|
uploadConcurrency?: number;
|
|
@@ -63,6 +77,12 @@ export interface AwaitAssemblyCompletionOptions {
|
|
|
63
77
|
*/
|
|
64
78
|
onPoll?: () => boolean | undefined;
|
|
65
79
|
}
|
|
80
|
+
export interface LintAssemblyInstructionsOptions extends Omit<LintAssemblyInstructionsInput, 'template'> {
|
|
81
|
+
/**
|
|
82
|
+
* Template ID to merge with the provided instructions before linting.
|
|
83
|
+
*/
|
|
84
|
+
templateId?: string;
|
|
85
|
+
}
|
|
66
86
|
export interface SmartCDNUrlOptions {
|
|
67
87
|
/**
|
|
68
88
|
* Workspace slug
|
|
@@ -87,21 +107,31 @@ export interface SmartCDNUrlOptions {
|
|
|
87
107
|
expiresAt?: number;
|
|
88
108
|
}
|
|
89
109
|
export type Fields = Record<string, string | number>;
|
|
90
|
-
interface CreateAssemblyPromise extends Promise<
|
|
110
|
+
interface CreateAssemblyPromise extends Promise<AssemblyStatusWithUploadUrls> {
|
|
91
111
|
assemblyId: string;
|
|
92
112
|
}
|
|
93
|
-
|
|
113
|
+
type AuthKeySecret = {
|
|
94
114
|
authKey: string;
|
|
95
115
|
authSecret: string;
|
|
116
|
+
authToken?: undefined;
|
|
117
|
+
};
|
|
118
|
+
type AuthToken = {
|
|
119
|
+
authToken: string;
|
|
120
|
+
authKey?: string;
|
|
121
|
+
authSecret?: string;
|
|
122
|
+
};
|
|
123
|
+
type BaseOptions = {
|
|
96
124
|
endpoint?: string;
|
|
97
125
|
maxRetries?: number;
|
|
98
126
|
timeout?: number;
|
|
99
127
|
gotRetry?: Partial<RetryOptions>;
|
|
100
128
|
validateResponses?: boolean;
|
|
101
|
-
}
|
|
129
|
+
};
|
|
130
|
+
export type Options = BaseOptions & (AuthKeySecret | AuthToken);
|
|
102
131
|
export declare class Transloadit {
|
|
103
132
|
private _authKey;
|
|
104
133
|
private _authSecret;
|
|
134
|
+
private _authToken;
|
|
105
135
|
private _endpoint;
|
|
106
136
|
private _maxRetries;
|
|
107
137
|
private _defaultTimeout;
|
|
@@ -117,7 +147,18 @@ export declare class Transloadit {
|
|
|
117
147
|
* @param opts assembly options
|
|
118
148
|
*/
|
|
119
149
|
createAssembly(opts?: CreateAssemblyOptions): CreateAssemblyPromise;
|
|
120
|
-
|
|
150
|
+
/**
|
|
151
|
+
* Lint Assembly Instructions locally.
|
|
152
|
+
*
|
|
153
|
+
* If a templateId is provided, the template content is merged with the instructions,
|
|
154
|
+
* just like the API. When a template sets `allow_steps_override=false`, providing
|
|
155
|
+
* `steps` will throw a TEMPLATE_DENIES_STEPS_OVERRIDE error.
|
|
156
|
+
*
|
|
157
|
+
* The `assemblyInstructions` input may be a JSON string, a full instructions object,
|
|
158
|
+
* or a steps-only object (missing the `steps` property).
|
|
159
|
+
*/
|
|
160
|
+
lintAssemblyInstructions(options: LintAssemblyInstructionsOptions): Promise<LintAssemblyInstructionsResult>;
|
|
161
|
+
resumeAssemblyUploads(opts: ResumeAssemblyUploadsOptions): Promise<AssemblyStatusWithUploadUrls>;
|
|
121
162
|
awaitAssemblyCompletion(assemblyId: string, { onAssemblyProgress, timeout, startTimeMs, interval, assemblyUrl, signal, onPoll, }?: AwaitAssemblyCompletionOptions): Promise<AssemblyStatus>;
|
|
122
163
|
maybeThrowInconsistentResponseError(message: string): void;
|
|
123
164
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transloadit.d.ts","sourceRoot":"","sources":["../src/Transloadit.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAK3C,OAAO,KAAK,EAA8C,YAAY,EAAE,MAAM,KAAK,CAAA;AAEnF,OAAmB,EAAE,KAAK,KAAK,IAAI,eAAe,EAAE,MAAM,aAAa,CAAA;AAKvE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,EAEV,iBAAiB,EACjB,cAAc,EACf,MAAM,oCAAoC,CAAA;AAG3C,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,oBAAoB,EACpB,8BAA8B,EAC9B,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,EACd,6BAA6B,EAC7B,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACvB,gCAAgC,EAChC,kCAAkC,EAClC,oBAAoB,EACpB,sBAAsB,EACtB,0BAA0B,EAC1B,2BAA2B,EAC3B,gBAAgB,EACjB,MAAM,eAAe,CAAA;AACtB,OAAO,yBAAyB,MAAM,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0BnB,OAAO,CAAC,kBAAkB;IAe1B,OAAO,CAAC,cAAc;IAmBtB,OAAO,CAAC,eAAe;YAST,WAAW;CA8H1B"}
|
package/dist/Transloadit.js
CHANGED
|
@@ -16,14 +16,19 @@ import { ApiError } from "./ApiError.js";
|
|
|
16
16
|
import { assemblyIndexSchema, assemblyStatusSchema } from "./alphalib/types/assemblyStatus.js";
|
|
17
17
|
import { zodParseWithContext } from "./alphalib/zodParseWithContext.js";
|
|
18
18
|
import InconsistentResponseError from "./InconsistentResponseError.js";
|
|
19
|
+
import { lintAssemblyInstructions as lintAssemblyInstructionsInternal } from "./lintAssemblyInstructions.js";
|
|
19
20
|
import PaginationStream from "./PaginationStream.js";
|
|
20
21
|
import PollingTimeoutError from "./PollingTimeoutError.js";
|
|
21
22
|
import { sendTusRequest } from "./tus.js";
|
|
22
23
|
// See https://github.com/sindresorhus/got/tree/v11.8.6?tab=readme-ov-file#errors
|
|
23
24
|
// Expose relevant errors
|
|
24
25
|
export { HTTPError, MaxRedirectsError, ParseError, ReadError, RequestError, TimeoutError, UploadError, } from 'got';
|
|
26
|
+
export { goldenTemplates } from "./alphalib/goldenTemplates.js";
|
|
25
27
|
export * from "./apiTypes.js";
|
|
26
28
|
export { InconsistentResponseError, ApiError };
|
|
29
|
+
export { mergeTemplateContent } from "./alphalib/templateMerge.js";
|
|
30
|
+
export { prepareInputFiles } from "./inputFiles.js";
|
|
31
|
+
export { getRobotHelp, listRobots } from "./robots.js";
|
|
27
32
|
const log = debug('transloadit');
|
|
28
33
|
const logWarn = debug('transloadit:warn');
|
|
29
34
|
const { version } = packageJson;
|
|
@@ -105,6 +110,7 @@ function checkResult(result) {
|
|
|
105
110
|
export class Transloadit {
|
|
106
111
|
_authKey;
|
|
107
112
|
_authSecret;
|
|
113
|
+
_authToken;
|
|
108
114
|
_endpoint;
|
|
109
115
|
_maxRetries;
|
|
110
116
|
_defaultTimeout;
|
|
@@ -112,17 +118,22 @@ export class Transloadit {
|
|
|
112
118
|
_lastUsedAssemblyUrl = '';
|
|
113
119
|
_validateResponses = false;
|
|
114
120
|
constructor(opts) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
if (opts.authSecret == null) {
|
|
119
|
-
throw new Error('Please provide an authSecret');
|
|
120
|
-
}
|
|
121
|
+
const rawToken = typeof opts?.authToken === 'string' ? opts.authToken.trim() : '';
|
|
122
|
+
const hasToken = rawToken.length > 0;
|
|
121
123
|
if (opts.endpoint?.endsWith('/')) {
|
|
122
124
|
throw new Error('Trailing slash in endpoint is not allowed');
|
|
123
125
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
+
if (!hasToken) {
|
|
127
|
+
if (opts?.authKey == null) {
|
|
128
|
+
throw new Error('Please provide an authKey');
|
|
129
|
+
}
|
|
130
|
+
if (opts.authSecret == null) {
|
|
131
|
+
throw new Error('Please provide an authSecret');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
this._authKey = opts.authKey ?? '';
|
|
135
|
+
this._authSecret = opts.authSecret ?? '';
|
|
136
|
+
this._authToken = hasToken ? rawToken : null;
|
|
126
137
|
this._endpoint = opts.endpoint || 'https://api2.transloadit.com';
|
|
127
138
|
this._maxRetries = opts.maxRetries != null ? opts.maxRetries : 5;
|
|
128
139
|
this._defaultTimeout = opts.timeout != null ? opts.timeout : 60000;
|
|
@@ -144,7 +155,7 @@ export class Transloadit {
|
|
|
144
155
|
*/
|
|
145
156
|
createAssembly(opts = {}) {
|
|
146
157
|
const { params = {}, waitForCompletion = false, chunkSize: requestedChunkSize = Number.POSITIVE_INFINITY, uploadConcurrency = 10, timeout = 24 * 60 * 60 * 1000, // 1 day
|
|
147
|
-
onUploadProgress = () => { }, onAssemblyProgress = () => { }, files = {}, uploads = {}, assemblyId, signal, } = opts;
|
|
158
|
+
onUploadProgress = () => { }, onAssemblyProgress = () => { }, files = {}, uploads = {}, assemblyId, signal, uploadBehavior = 'await', } = opts;
|
|
148
159
|
// Keep track of how long the request took
|
|
149
160
|
const startTimeMs = getHrTimeMs();
|
|
150
161
|
// Undocumented feature to allow specifying a custom assembly id from the client
|
|
@@ -198,16 +209,21 @@ export class Transloadit {
|
|
|
198
209
|
});
|
|
199
210
|
checkResult(result);
|
|
200
211
|
if (Object.keys(allStreamsMap).length > 0) {
|
|
201
|
-
await sendTusRequest({
|
|
212
|
+
const { uploadUrls } = await sendTusRequest({
|
|
202
213
|
streamsMap: allStreamsMap,
|
|
203
214
|
assembly: result,
|
|
204
215
|
onProgress: onUploadProgress,
|
|
205
216
|
requestedChunkSize,
|
|
206
217
|
uploadConcurrency,
|
|
207
218
|
signal,
|
|
219
|
+
uploadBehavior,
|
|
208
220
|
});
|
|
221
|
+
if (uploadBehavior !== 'await' && Object.keys(uploadUrls).length > 0) {
|
|
222
|
+
result.upload_urls = uploadUrls;
|
|
223
|
+
}
|
|
209
224
|
}
|
|
210
|
-
|
|
225
|
+
const shouldWaitForCompletion = waitForCompletion && uploadBehavior === 'await';
|
|
226
|
+
if (!shouldWaitForCompletion)
|
|
211
227
|
return result;
|
|
212
228
|
if (result.assembly_id == null) {
|
|
213
229
|
throw new InconsistentResponseError('Server returned an assembly response without an assembly_id after creation');
|
|
@@ -226,12 +242,36 @@ export class Transloadit {
|
|
|
226
242
|
// This allows the user to use or log the assemblyId even before it has been created for easier debugging
|
|
227
243
|
return Object.assign(promise, { assemblyId: effectiveAssemblyId });
|
|
228
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Lint Assembly Instructions locally.
|
|
247
|
+
*
|
|
248
|
+
* If a templateId is provided, the template content is merged with the instructions,
|
|
249
|
+
* just like the API. When a template sets `allow_steps_override=false`, providing
|
|
250
|
+
* `steps` will throw a TEMPLATE_DENIES_STEPS_OVERRIDE error.
|
|
251
|
+
*
|
|
252
|
+
* The `assemblyInstructions` input may be a JSON string, a full instructions object,
|
|
253
|
+
* or a steps-only object (missing the `steps` property).
|
|
254
|
+
*/
|
|
255
|
+
async lintAssemblyInstructions(options) {
|
|
256
|
+
const { templateId, ...rest } = options;
|
|
257
|
+
if (!templateId) {
|
|
258
|
+
return await lintAssemblyInstructionsInternal(rest);
|
|
259
|
+
}
|
|
260
|
+
const template = await this.getTemplate(templateId);
|
|
261
|
+
return await lintAssemblyInstructionsInternal({
|
|
262
|
+
...rest,
|
|
263
|
+
template: template.content,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
229
266
|
async resumeAssemblyUploads(opts) {
|
|
230
267
|
const { assemblyUrl, files = {}, uploads = {}, chunkSize: requestedChunkSize = Number.POSITIVE_INFINITY, uploadConcurrency = 10, timeout = 24 * 60 * 60 * 1000, // 1 day
|
|
231
|
-
waitForCompletion = false, onUploadProgress = () => { }, onAssemblyProgress = () => { }, signal, } = opts;
|
|
268
|
+
waitForCompletion = false, onUploadProgress = () => { }, onAssemblyProgress = () => { }, signal, uploadBehavior = 'await', } = opts;
|
|
232
269
|
const startTimeMs = getHrTimeMs();
|
|
233
270
|
getAssemblyIdFromUrl(assemblyUrl);
|
|
234
|
-
const assembly = await this._fetchAssemblyStatus({
|
|
271
|
+
const assembly = await this._fetchAssemblyStatus({
|
|
272
|
+
url: assemblyUrl,
|
|
273
|
+
signal,
|
|
274
|
+
});
|
|
235
275
|
const statusUrl = assembly.assembly_ssl_url ?? assembly.assembly_url ?? assemblyUrl;
|
|
236
276
|
const finishedKeys = new Set();
|
|
237
277
|
for (const upload of assembly.uploads ?? []) {
|
|
@@ -302,11 +342,23 @@ export class Transloadit {
|
|
|
302
342
|
onProgress: onUploadProgress,
|
|
303
343
|
signal,
|
|
304
344
|
uploadUrls: uploadUrlsByLabel,
|
|
345
|
+
uploadBehavior,
|
|
305
346
|
});
|
|
306
347
|
await Promise.race([uploadPromise, streamErrorPromise]);
|
|
348
|
+
const { uploadUrls } = await uploadPromise;
|
|
349
|
+
if (uploadBehavior !== 'await' && Object.keys(uploadUrls).length > 0) {
|
|
350
|
+
assembly.upload_urls = uploadUrls;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
const latestAssembly = await this._fetchAssemblyStatus({
|
|
354
|
+
url: statusUrl,
|
|
355
|
+
signal,
|
|
356
|
+
});
|
|
357
|
+
if (uploadBehavior !== 'await' && assembly.upload_urls) {
|
|
358
|
+
latestAssembly.upload_urls = assembly.upload_urls;
|
|
307
359
|
}
|
|
308
|
-
const
|
|
309
|
-
if (!
|
|
360
|
+
const shouldWaitForCompletion = waitForCompletion && uploadBehavior === 'await';
|
|
361
|
+
if (!shouldWaitForCompletion)
|
|
310
362
|
return latestAssembly;
|
|
311
363
|
if (latestAssembly.assembly_id == null) {
|
|
312
364
|
throw new InconsistentResponseError('Server returned an assembly response without an assembly_id after resuming uploads');
|
|
@@ -398,6 +450,7 @@ export class Transloadit {
|
|
|
398
450
|
const { assembly_ssl_url: url } = await this.getAssembly(assemblyId);
|
|
399
451
|
const rawResult = await this._remoteJson({
|
|
400
452
|
url,
|
|
453
|
+
isTrustedUrl: true,
|
|
401
454
|
method: 'delete',
|
|
402
455
|
});
|
|
403
456
|
const parsedResult = zodParseWithContext(assemblyStatusSchema, rawResult);
|
|
@@ -483,6 +536,7 @@ export class Transloadit {
|
|
|
483
536
|
const rawResult = await this._remoteJson({
|
|
484
537
|
url,
|
|
485
538
|
urlSuffix: url ? undefined : `/assemblies/${assemblyId}`,
|
|
539
|
+
isTrustedUrl: Boolean(url),
|
|
486
540
|
signal,
|
|
487
541
|
});
|
|
488
542
|
const parsedResult = zodParseWithContext(assemblyStatusSchema, rawResult);
|
|
@@ -644,6 +698,9 @@ export class Transloadit {
|
|
|
644
698
|
});
|
|
645
699
|
}
|
|
646
700
|
calcSignature(params, algorithm) {
|
|
701
|
+
if (!this._authKey || !this._authSecret) {
|
|
702
|
+
throw new Error('Cannot sign params without authKey and authSecret.');
|
|
703
|
+
}
|
|
647
704
|
const jsonParams = this._prepareParams(params);
|
|
648
705
|
const signature = this._calcSignature(jsonParams, algorithm);
|
|
649
706
|
return { signature, params: jsonParams };
|
|
@@ -652,6 +709,9 @@ export class Transloadit {
|
|
|
652
709
|
* Construct a signed Smart CDN URL. See https://transloadit.com/docs/topics/signature-authentication/#smart-cdn.
|
|
653
710
|
*/
|
|
654
711
|
getSignedSmartCDNUrl(opts) {
|
|
712
|
+
if (!this._authKey || !this._authSecret) {
|
|
713
|
+
throw new Error('authKey and authSecret are required to sign Smart CDN URLs.');
|
|
714
|
+
}
|
|
655
715
|
return getSignedSmartCdnUrl({
|
|
656
716
|
...opts,
|
|
657
717
|
authKey: this._authKey,
|
|
@@ -659,27 +719,42 @@ export class Transloadit {
|
|
|
659
719
|
});
|
|
660
720
|
}
|
|
661
721
|
_calcSignature(toSign, algorithm = 'sha384') {
|
|
722
|
+
if (!this._authSecret) {
|
|
723
|
+
throw new Error('Cannot sign params without authSecret.');
|
|
724
|
+
}
|
|
662
725
|
return signParamsSync(toSign, this._authSecret, algorithm);
|
|
663
726
|
}
|
|
664
727
|
// Sets the multipart/form-data for POST, PUT and DELETE requests, including
|
|
665
728
|
// the streams, the signed params, and any additional fields.
|
|
666
729
|
_appendForm(form, params, fields) {
|
|
667
|
-
const
|
|
668
|
-
|
|
669
|
-
|
|
730
|
+
const shouldSign = Boolean(this._authKey && this._authSecret);
|
|
731
|
+
let jsonParams = JSON.stringify(params ?? {});
|
|
732
|
+
let signature;
|
|
733
|
+
if (shouldSign) {
|
|
734
|
+
const sigData = this.calcSignature(params);
|
|
735
|
+
jsonParams = sigData.params;
|
|
736
|
+
signature = sigData.signature;
|
|
737
|
+
}
|
|
670
738
|
form.append('params', jsonParams);
|
|
671
739
|
if (fields != null) {
|
|
672
740
|
for (const [key, val] of Object.entries(fields)) {
|
|
673
741
|
form.append(key, val);
|
|
674
742
|
}
|
|
675
743
|
}
|
|
676
|
-
|
|
744
|
+
if (signature) {
|
|
745
|
+
form.append('signature', signature);
|
|
746
|
+
}
|
|
677
747
|
}
|
|
678
748
|
// Implements HTTP GET query params, handling the case where the url already
|
|
679
749
|
// has params.
|
|
680
750
|
_appendParamsToUrl(url, params) {
|
|
681
|
-
const { signature, params: jsonParams } = this.calcSignature(params);
|
|
682
751
|
const prefix = url.indexOf('?') === -1 ? '?' : '&';
|
|
752
|
+
const shouldSign = Boolean(this._authKey && this._authSecret);
|
|
753
|
+
if (!shouldSign) {
|
|
754
|
+
const jsonParams = JSON.stringify(params ?? {});
|
|
755
|
+
return `${url}${prefix}params=${encodeURIComponent(jsonParams)}`;
|
|
756
|
+
}
|
|
757
|
+
const { signature, params: jsonParams } = this.calcSignature(params);
|
|
683
758
|
return `${url}${prefix}signature=${signature}¶ms=${encodeURIComponent(jsonParams)}`;
|
|
684
759
|
}
|
|
685
760
|
// Responsible for including auth parameters in all requests
|
|
@@ -709,11 +784,18 @@ export class Transloadit {
|
|
|
709
784
|
// PUT or DELETE requests. Automatically adds signature parameters to all
|
|
710
785
|
// requests. Also automatically parses the JSON response.
|
|
711
786
|
async _remoteJson(opts) {
|
|
712
|
-
const { urlSuffix, url: urlInput, timeout = { request: this._defaultTimeout }, method = 'get', params = {}, fields, headers, signal, } = opts;
|
|
787
|
+
const { urlSuffix, url: urlInput, isTrustedUrl = false, timeout = { request: this._defaultTimeout }, method = 'get', params = {}, fields, headers, signal, } = opts;
|
|
713
788
|
// Allow providing either a `urlSuffix` or a full `url`
|
|
714
789
|
if (!urlSuffix && !urlInput)
|
|
715
790
|
throw new Error('No URL provided');
|
|
716
791
|
let url = urlInput || `${this._endpoint}${urlSuffix}`;
|
|
792
|
+
if (urlInput && !isTrustedUrl) {
|
|
793
|
+
const allowed = new URL(this._endpoint);
|
|
794
|
+
const candidate = new URL(urlInput);
|
|
795
|
+
if (allowed.origin !== candidate.origin) {
|
|
796
|
+
throw new Error(`Untrusted URL: ${candidate.origin}`);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
717
799
|
if (method === 'get') {
|
|
718
800
|
url = this._appendParamsToUrl(url, params);
|
|
719
801
|
}
|
|
@@ -733,6 +815,7 @@ export class Transloadit {
|
|
|
733
815
|
headers: {
|
|
734
816
|
'Transloadit-Client': `node-sdk:${version}`,
|
|
735
817
|
'User-Agent': undefined, // Remove got's user-agent
|
|
818
|
+
...(this._authToken ? { Authorization: `Bearer ${this._authToken}` } : {}),
|
|
736
819
|
...headers,
|
|
737
820
|
},
|
|
738
821
|
responseType: 'json',
|