@transloadit/node 4.1.9 → 4.3.0
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 +81 -1
- package/dist/Transloadit.d.ts +36 -5
- package/dist/Transloadit.d.ts.map +1 -1
- package/dist/Transloadit.js +228 -39
- 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/mcache.d.ts.map +1 -1
- package/dist/alphalib/mcache.js +22 -7
- package/dist/alphalib/mcache.js.map +1 -1
- 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/alphalib/types/assemblyReplay.d.ts +56 -0
- package/dist/alphalib/types/assemblyReplay.d.ts.map +1 -1
- package/dist/alphalib/types/assemblyReplayNotification.d.ts +56 -0
- package/dist/alphalib/types/assemblyReplayNotification.d.ts.map +1 -1
- package/dist/alphalib/types/assemblyStatus.d.ts +63 -57
- package/dist/alphalib/types/assemblyStatus.d.ts.map +1 -1
- package/dist/alphalib/types/assemblyStatus.js +9 -1
- package/dist/alphalib/types/assemblyStatus.js.map +1 -1
- package/dist/alphalib/types/assemblyUrls.d.ts +1 -1
- package/dist/alphalib/types/assemblyUrls.d.ts.map +1 -1
- package/dist/alphalib/types/assemblyUrls.js.map +1 -1
- package/dist/alphalib/types/robots/_index.d.ts +608 -81
- package/dist/alphalib/types/robots/_index.d.ts.map +1 -1
- package/dist/alphalib/types/robots/_index.js +4 -0
- package/dist/alphalib/types/robots/_index.js.map +1 -1
- package/dist/alphalib/types/robots/_instructions-primitives.d.ts +4 -4
- package/dist/alphalib/types/robots/_instructions-primitives.d.ts.map +1 -1
- package/dist/alphalib/types/robots/_instructions-primitives.js +1 -0
- package/dist/alphalib/types/robots/_instructions-primitives.js.map +1 -1
- package/dist/alphalib/types/robots/document-optimize.d.ts +489 -0
- package/dist/alphalib/types/robots/document-optimize.d.ts.map +1 -0
- package/dist/alphalib/types/robots/document-optimize.js +151 -0
- package/dist/alphalib/types/robots/document-optimize.js.map +1 -0
- package/dist/alphalib/types/template.d.ts +1050 -174
- package/dist/alphalib/types/template.d.ts.map +1 -1
- 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/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/tus.d.ts +2 -1
- package/dist/tus.d.ts.map +1 -1
- package/dist/tus.js +2 -1
- package/dist/tus.js.map +1 -1
- package/package.json +5 -2
- package/src/Transloadit.ts +318 -49
- package/src/alphalib/assembly-linter.lang.en.ts +393 -0
- package/src/alphalib/assembly-linter.ts +1475 -0
- package/src/alphalib/mcache.ts +26 -7
- package/src/alphalib/object.ts +27 -0
- package/src/alphalib/stepParsing.ts +1465 -0
- package/src/alphalib/templateMerge.ts +32 -0
- package/src/alphalib/types/assemblyStatus.ts +9 -1
- package/src/alphalib/types/assemblyUrls.ts +2 -5
- package/src/alphalib/types/robots/_index.ts +14 -0
- package/src/alphalib/types/robots/_instructions-primitives.ts +1 -0
- package/src/alphalib/types/robots/document-optimize.ts +180 -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/lintAssemblyInput.ts +89 -0
- package/src/lintAssemblyInstructions.ts +72 -0
- package/src/tus.ts +3 -0
package/src/cli/helpers.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
|
+
import fsp from 'node:fs/promises'
|
|
2
3
|
import type { Readable } from 'node:stream'
|
|
3
4
|
import { isAPIError } from './types.ts'
|
|
4
5
|
|
|
@@ -24,6 +25,55 @@ export async function streamToBuffer(stream: Readable): Promise<Buffer> {
|
|
|
24
25
|
return Buffer.concat(chunks)
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
async function readStdin(): Promise<string> {
|
|
29
|
+
if (process.stdin.isTTY) return ''
|
|
30
|
+
|
|
31
|
+
process.stdin.setEncoding('utf8')
|
|
32
|
+
let data = ''
|
|
33
|
+
|
|
34
|
+
for await (const chunk of process.stdin) {
|
|
35
|
+
data += chunk
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return data
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface CliInputResult {
|
|
42
|
+
content: string | null
|
|
43
|
+
isStdin: boolean
|
|
44
|
+
path?: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ReadCliInputOptions {
|
|
48
|
+
inputPath?: string
|
|
49
|
+
providedInput?: string
|
|
50
|
+
allowStdinWhenNoPath?: boolean
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function readCliInput(options: ReadCliInputOptions): Promise<CliInputResult> {
|
|
54
|
+
const { inputPath, providedInput, allowStdinWhenNoPath = false } = options
|
|
55
|
+
const canUseProvided = providedInput != null && (inputPath == null || inputPath === '-')
|
|
56
|
+
|
|
57
|
+
if (canUseProvided) {
|
|
58
|
+
return { content: providedInput, isStdin: inputPath === '-' || inputPath == null }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (inputPath === '-') {
|
|
62
|
+
return { content: await readStdin(), isStdin: true }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (inputPath != null) {
|
|
66
|
+
const content = await fsp.readFile(inputPath, 'utf8')
|
|
67
|
+
return { content, isStdin: false, path: inputPath }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (allowStdinWhenNoPath && !process.stdin.isTTY) {
|
|
71
|
+
return { content: await readStdin(), isStdin: true }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return { content: null, isStdin: false }
|
|
75
|
+
}
|
|
76
|
+
|
|
27
77
|
export function formatAPIError(err: unknown): string {
|
|
28
78
|
if (isAPIError(err)) {
|
|
29
79
|
return `${err.error}: ${err.message}`
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { getIndentation } from './alphalib/stepParsing.ts'
|
|
2
|
+
import { mergeTemplateContent } from './alphalib/templateMerge.ts'
|
|
3
|
+
import type { AssemblyInstructionsInput, StepsInput } from './alphalib/types/template.ts'
|
|
4
|
+
import type { ResponseTemplateContent, TemplateContent } from './apiTypes.ts'
|
|
5
|
+
|
|
6
|
+
const DEFAULT_INDENT = ' '
|
|
7
|
+
|
|
8
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
9
|
+
typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
10
|
+
|
|
11
|
+
export interface BuildLintInputResult {
|
|
12
|
+
lintContent: string
|
|
13
|
+
wasStepsOnly: boolean
|
|
14
|
+
indent: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const unwrapStepsOnly = (content: string, indent: string): string => {
|
|
18
|
+
try {
|
|
19
|
+
const parsed = JSON.parse(content)
|
|
20
|
+
if (isRecord(parsed) && 'steps' in parsed) {
|
|
21
|
+
return JSON.stringify((parsed as { steps?: unknown }).steps ?? {}, null, indent)
|
|
22
|
+
}
|
|
23
|
+
} catch (_err) {
|
|
24
|
+
return content
|
|
25
|
+
}
|
|
26
|
+
return content
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const buildLintInput = (
|
|
30
|
+
assemblyInstructions?: AssemblyInstructionsInput | StepsInput | string,
|
|
31
|
+
template?: TemplateContent | ResponseTemplateContent,
|
|
32
|
+
): BuildLintInputResult => {
|
|
33
|
+
let inputString: string | undefined
|
|
34
|
+
let parsedInput: unknown | undefined
|
|
35
|
+
let parseFailed = false
|
|
36
|
+
let indent = DEFAULT_INDENT
|
|
37
|
+
|
|
38
|
+
if (typeof assemblyInstructions === 'string') {
|
|
39
|
+
inputString = assemblyInstructions
|
|
40
|
+
indent = getIndentation(assemblyInstructions)
|
|
41
|
+
try {
|
|
42
|
+
parsedInput = JSON.parse(assemblyInstructions)
|
|
43
|
+
} catch (_err) {
|
|
44
|
+
parseFailed = true
|
|
45
|
+
}
|
|
46
|
+
} else if (assemblyInstructions != null) {
|
|
47
|
+
parsedInput = assemblyInstructions
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let wasStepsOnly = false
|
|
51
|
+
let instructions: AssemblyInstructionsInput | undefined
|
|
52
|
+
|
|
53
|
+
if (parsedInput !== undefined) {
|
|
54
|
+
if (isRecord(parsedInput)) {
|
|
55
|
+
if ('steps' in parsedInput) {
|
|
56
|
+
instructions = parsedInput as AssemblyInstructionsInput
|
|
57
|
+
} else {
|
|
58
|
+
instructions = { steps: parsedInput as StepsInput }
|
|
59
|
+
wasStepsOnly = true
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
instructions = { steps: parsedInput as StepsInput }
|
|
63
|
+
wasStepsOnly = true
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const shouldMergeTemplate = template != null && !parseFailed
|
|
68
|
+
if (shouldMergeTemplate) {
|
|
69
|
+
instructions = mergeTemplateContent(template, instructions)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let lintContent = ''
|
|
73
|
+
if (instructions != null) {
|
|
74
|
+
if (
|
|
75
|
+
typeof assemblyInstructions === 'string' &&
|
|
76
|
+
!wasStepsOnly &&
|
|
77
|
+
!parseFailed &&
|
|
78
|
+
!shouldMergeTemplate
|
|
79
|
+
) {
|
|
80
|
+
lintContent = assemblyInstructions
|
|
81
|
+
} else {
|
|
82
|
+
lintContent = JSON.stringify(instructions, null, indent)
|
|
83
|
+
}
|
|
84
|
+
} else if (inputString != null) {
|
|
85
|
+
lintContent = inputString
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return { lintContent, wasStepsOnly, indent }
|
|
89
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { HydratedLintIssue } from './alphalib/assembly-linter.lang.en.ts'
|
|
2
|
+
import { hydrateLintIssues } from './alphalib/assembly-linter.lang.en.ts'
|
|
3
|
+
import { applyFix, parseAndLint } from './alphalib/assembly-linter.ts'
|
|
4
|
+
import type { AssemblyInstructionsInput, StepsInput } from './alphalib/types/template.ts'
|
|
5
|
+
import type { ResponseTemplateContent, TemplateContent } from './apiTypes.ts'
|
|
6
|
+
import { buildLintInput, unwrapStepsOnly } from './lintAssemblyInput.ts'
|
|
7
|
+
|
|
8
|
+
export type LintFatalLevel = 'error' | 'warning'
|
|
9
|
+
|
|
10
|
+
export interface LintAssemblyInstructionsInput {
|
|
11
|
+
/**
|
|
12
|
+
* Assembly Instructions as a JSON string, a full instructions object, or a steps-only object.
|
|
13
|
+
*/
|
|
14
|
+
assemblyInstructions?: AssemblyInstructionsInput | StepsInput | string
|
|
15
|
+
/**
|
|
16
|
+
* Optional template content to merge with the provided instructions.
|
|
17
|
+
*/
|
|
18
|
+
template?: TemplateContent | ResponseTemplateContent
|
|
19
|
+
/**
|
|
20
|
+
* Treat issues at this level or above as fatal. Defaults to "error".
|
|
21
|
+
*/
|
|
22
|
+
fatal?: LintFatalLevel
|
|
23
|
+
/**
|
|
24
|
+
* Apply auto-fixes where possible and return the fixed JSON.
|
|
25
|
+
*/
|
|
26
|
+
fix?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface LintAssemblyInstructionsResult {
|
|
30
|
+
success: boolean
|
|
31
|
+
issues: HydratedLintIssue[]
|
|
32
|
+
fixedInstructions?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function lintAssemblyInstructions(
|
|
36
|
+
options: LintAssemblyInstructionsInput,
|
|
37
|
+
): Promise<LintAssemblyInstructionsResult> {
|
|
38
|
+
const { assemblyInstructions, template, fix = false, fatal = 'error' } = options
|
|
39
|
+
|
|
40
|
+
if (assemblyInstructions == null && template == null) {
|
|
41
|
+
throw new Error('Provide assemblyInstructions or template content to lint.')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const { lintContent, wasStepsOnly, indent } = buildLintInput(assemblyInstructions, template)
|
|
45
|
+
|
|
46
|
+
let issues = await parseAndLint(lintContent)
|
|
47
|
+
let fixedContent = lintContent
|
|
48
|
+
|
|
49
|
+
if (fix) {
|
|
50
|
+
for (const issue of issues) {
|
|
51
|
+
if (!issue.fixId) continue
|
|
52
|
+
// applyFix validates fixData against the fix schema for the fixId.
|
|
53
|
+
fixedContent = applyFix(fixedContent, issue.fixId, issue.fixData as never)
|
|
54
|
+
}
|
|
55
|
+
issues = await parseAndLint(fixedContent)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const describedIssues = hydrateLintIssues(issues)
|
|
59
|
+
const fatalTypes = fatal === 'warning' ? new Set(['warning', 'error']) : new Set(['error'])
|
|
60
|
+
const success = !describedIssues.some((issue) => fatalTypes.has(issue.type))
|
|
61
|
+
|
|
62
|
+
const result: LintAssemblyInstructionsResult = {
|
|
63
|
+
success,
|
|
64
|
+
issues: describedIssues,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (fix) {
|
|
68
|
+
result.fixedInstructions = wasStepsOnly ? unwrapStepsOnly(fixedContent, indent) : fixedContent
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return result
|
|
72
|
+
}
|
package/src/tus.ts
CHANGED
|
@@ -22,6 +22,7 @@ interface SendTusRequestOptions {
|
|
|
22
22
|
uploadConcurrency: number
|
|
23
23
|
onProgress: (options: UploadProgress) => void
|
|
24
24
|
signal?: AbortSignal
|
|
25
|
+
uploadUrls?: Record<string, string>
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export async function sendTusRequest({
|
|
@@ -31,6 +32,7 @@ export async function sendTusRequest({
|
|
|
31
32
|
uploadConcurrency,
|
|
32
33
|
onProgress,
|
|
33
34
|
signal,
|
|
35
|
+
uploadUrls,
|
|
34
36
|
}: SendTusRequestOptions) {
|
|
35
37
|
const streamLabels = Object.keys(streamsMap)
|
|
36
38
|
|
|
@@ -133,6 +135,7 @@ export async function sendTusRequest({
|
|
|
133
135
|
|
|
134
136
|
const tusOptions: UploadOptions = {
|
|
135
137
|
endpoint: assembly.tus_url,
|
|
138
|
+
uploadUrl: uploadUrls?.[label],
|
|
136
139
|
metadata: {
|
|
137
140
|
assembly_url: assembly.assembly_ssl_url,
|
|
138
141
|
fieldname: label,
|