transloadit 6.1.2 → 6.2.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 +14 -0
- package/dist/alphalib/stepParsing.d.ts +1 -0
- package/dist/alphalib/stepParsing.d.ts.map +1 -1
- package/dist/alphalib/stepParsing.js +15 -4
- package/dist/alphalib/stepParsing.js.map +1 -1
- package/dist/alphalib/types/builtinTemplates.d.ts +40 -0
- package/dist/alphalib/types/builtinTemplates.d.ts.map +1 -1
- package/dist/alphalib/types/builtinTemplates.js +29 -0
- package/dist/alphalib/types/builtinTemplates.js.map +1 -1
- package/dist/alphalib/types/responseErrors/DocumentConvertRobot.d.ts +17 -0
- package/dist/alphalib/types/responseErrors/DocumentConvertRobot.d.ts.map +1 -0
- package/dist/alphalib/types/responseErrors/DocumentConvertRobot.js +17 -0
- package/dist/alphalib/types/responseErrors/DocumentConvertRobot.js.map +1 -0
- package/dist/alphalib/types/robots/document-convert.d.ts.map +1 -1
- package/dist/alphalib/types/robots/document-convert.js +19 -0
- package/dist/alphalib/types/robots/document-convert.js.map +1 -1
- package/dist/alphalib/types/robots/document-extract.d.ts +32 -20
- package/dist/alphalib/types/robots/document-extract.d.ts.map +1 -1
- package/dist/alphalib/types/robots/document-extract.js +51 -1
- package/dist/alphalib/types/robots/document-extract.js.map +1 -1
- package/dist/alphalib/types/robots/html-convert.d.ts.map +1 -1
- package/dist/alphalib/types/robots/html-convert.js +1 -0
- package/dist/alphalib/types/robots/html-convert.js.map +1 -1
- package/dist/alphalib/types/robots/speech-transcribe.d.ts +14 -0
- package/dist/alphalib/types/robots/speech-transcribe.d.ts.map +1 -1
- package/dist/alphalib/types/robots/speech-transcribe.js +42 -2
- package/dist/alphalib/types/robots/speech-transcribe.js.map +1 -1
- package/dist/alphalib/types/robots/video-split.d.ts +11 -0
- package/dist/alphalib/types/robots/video-split.d.ts.map +1 -1
- package/dist/alphalib/types/robots/video-split.js +2 -1
- package/dist/alphalib/types/robots/video-split.js.map +1 -1
- package/dist/alphalib/types/robots/video-subtitle.d.ts +24 -24
- package/dist/alphalib/types/robots/video-subtitle.d.ts.map +1 -1
- package/dist/alphalib/types/robots/video-subtitle.js +12 -11
- package/dist/alphalib/types/robots/video-subtitle.js.map +1 -1
- package/dist/alphalib/types/robots/video-thumbs.d.ts +36 -36
- package/dist/alphalib/types/robots/video-thumbs.d.ts.map +1 -1
- package/dist/alphalib/types/robots/video-thumbs.js +8 -3
- package/dist/alphalib/types/robots/video-thumbs.js.map +1 -1
- package/dist/alphalib/types/template.d.ts.map +1 -1
- package/dist/alphalib/types/template.js +5 -2
- package/dist/alphalib/types/template.js.map +1 -1
- package/dist/cli/commands/assemblies.js +3 -3
- 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 +4 -3
- package/dist/cli/commands/auth.js.map +1 -1
- package/dist/cli/commands/templates.d.ts.map +1 -1
- package/dist/cli/commands/templates.js +11 -5
- package/dist/cli/commands/templates.js.map +1 -1
- package/dist/cli/stepsInput.d.ts +6 -2
- package/dist/cli/stepsInput.d.ts.map +1 -1
- package/dist/cli/stepsInput.js +24 -5
- package/dist/cli/stepsInput.js.map +1 -1
- package/dist/cli/types.d.ts +0 -1
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/cli/types.js +0 -7
- package/dist/cli/types.js.map +1 -1
- package/package.json +1 -1
- package/src/alphalib/stepParsing.ts +16 -4
- package/src/alphalib/types/builtinTemplates.ts +37 -0
- package/src/alphalib/types/responseErrors/DocumentConvertRobot.ts +21 -0
- package/src/alphalib/types/robots/document-convert.ts +25 -0
- package/src/alphalib/types/robots/document-extract.ts +76 -0
- package/src/alphalib/types/robots/html-convert.ts +1 -0
- package/src/alphalib/types/robots/speech-transcribe.ts +47 -2
- package/src/alphalib/types/robots/video-split.ts +2 -1
- package/src/alphalib/types/robots/video-subtitle.ts +12 -11
- package/src/alphalib/types/robots/video-thumbs.ts +8 -3
- package/src/alphalib/types/template.ts +3 -0
- package/src/cli/commands/assemblies.ts +3 -3
- package/src/cli/commands/auth.ts +7 -2
- package/src/cli/commands/templates.ts +13 -6
- package/src/cli/stepsInput.ts +34 -5
- package/src/cli/types.ts +0 -9
package/src/cli/commands/auth.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
requireCliCredentials,
|
|
23
23
|
resolveCliConfig,
|
|
24
24
|
} from '../helpers.ts'
|
|
25
|
+
import { createCliStepsSchema } from '../stepsInput.ts'
|
|
25
26
|
import { UnauthenticatedCommand } from './BaseCommand.ts'
|
|
26
27
|
|
|
27
28
|
type UrlParamPrimitive = string | number | boolean
|
|
@@ -113,6 +114,7 @@ function generateSignature(
|
|
|
113
114
|
input: string,
|
|
114
115
|
credentials: CliKeySecretCredentials,
|
|
115
116
|
algorithm?: string,
|
|
117
|
+
output: Pick<IOutputCtl, 'warn'> = console,
|
|
116
118
|
): OutputResult {
|
|
117
119
|
const { authKey } = credentials
|
|
118
120
|
let params: CliSignatureParams
|
|
@@ -120,7 +122,10 @@ function generateSignature(
|
|
|
120
122
|
if (input === '') {
|
|
121
123
|
params = { auth: { key: authKey } }
|
|
122
124
|
} else {
|
|
123
|
-
const parsedResult = parseJsonObject(
|
|
125
|
+
const parsedResult = parseJsonObject(
|
|
126
|
+
input,
|
|
127
|
+
cliSignatureParamsSchema.extend({ steps: createCliStepsSchema(output).optional() }),
|
|
128
|
+
)
|
|
124
129
|
if (!parsedResult.ok) {
|
|
125
130
|
return { ok: false, error: parsedResult.error }
|
|
126
131
|
}
|
|
@@ -347,7 +352,7 @@ export class SignatureCommand extends UnauthenticatedCommand {
|
|
|
347
352
|
|
|
348
353
|
const { content } = await readCliInput({ allowStdinWhenNoPath: true })
|
|
349
354
|
const rawInput = (content ?? '').trim()
|
|
350
|
-
const result = generateSignature(rawInput, credentials, this.algorithm)
|
|
355
|
+
const result = generateSignature(rawInput, credentials, this.algorithm, this.output)
|
|
351
356
|
|
|
352
357
|
if (result.ok) {
|
|
353
358
|
process.stdout.write(`${result.output}\n`)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TemplateContent } from '../../apiTypes.ts'
|
|
2
2
|
import type { Transloadit } from '../../Transloadit.ts'
|
|
3
3
|
import type { IOutputCtl } from '../OutputCtl.ts'
|
|
4
|
-
import type { TemplateFile } from '../types.ts'
|
|
4
|
+
import type { TemplateFile, TemplateFileData } from '../types.ts'
|
|
5
5
|
|
|
6
6
|
import fsp from 'node:fs/promises'
|
|
7
7
|
import path from 'node:path'
|
|
@@ -13,9 +13,9 @@ import { z } from 'zod'
|
|
|
13
13
|
|
|
14
14
|
import { tryCatch } from '../../alphalib/tryCatch.ts'
|
|
15
15
|
import { createReadStream, formatAPIError, streamToBuffer } from '../helpers.ts'
|
|
16
|
-
import { parseStepsInputJson } from '../stepsInput.ts'
|
|
16
|
+
import { createCliStepsSchema, parseStepsInputJson } from '../stepsInput.ts'
|
|
17
17
|
import ModifiedLookup from '../template-last-modified.ts'
|
|
18
|
-
import { ensureError, isTransloaditAPIError
|
|
18
|
+
import { ensureError, isTransloaditAPIError } from '../types.ts'
|
|
19
19
|
import { AuthenticatedCommand } from './BaseCommand.ts'
|
|
20
20
|
|
|
21
21
|
const rreaddirAsync = promisify(rreaddir)
|
|
@@ -62,7 +62,7 @@ export async function create(
|
|
|
62
62
|
try {
|
|
63
63
|
const buf = await streamToBuffer(createReadStream(file))
|
|
64
64
|
|
|
65
|
-
const steps = parseStepsInputJson(buf.toString())
|
|
65
|
+
const steps = parseStepsInputJson(buf.toString(), output)
|
|
66
66
|
|
|
67
67
|
const result = await client.createTemplate({
|
|
68
68
|
name,
|
|
@@ -107,7 +107,7 @@ export async function modify(
|
|
|
107
107
|
let newName = name
|
|
108
108
|
|
|
109
109
|
if (buf.length > 0) {
|
|
110
|
-
steps = parseStepsInputJson(buf.toString()) as TemplateContent['steps']
|
|
110
|
+
steps = parseStepsInputJson(buf.toString(), output) as TemplateContent['steps']
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
if (!name || buf.length === 0) {
|
|
@@ -225,6 +225,13 @@ export async function sync(
|
|
|
225
225
|
client: Transloadit,
|
|
226
226
|
{ files, recursive }: TemplateSyncOptions,
|
|
227
227
|
): Promise<void> {
|
|
228
|
+
const templateFileDataSchema: z.ZodType<TemplateFileData> = z
|
|
229
|
+
.object({
|
|
230
|
+
transloadit_template_id: z.string().optional(),
|
|
231
|
+
steps: createCliStepsSchema(output).optional(),
|
|
232
|
+
})
|
|
233
|
+
.passthrough()
|
|
234
|
+
|
|
228
235
|
// Promise [String] -- all files in the directory tree
|
|
229
236
|
const relevantFilesNested = await Promise.all(
|
|
230
237
|
files.map(async (file) => {
|
|
@@ -263,7 +270,7 @@ export async function sync(
|
|
|
263
270
|
try {
|
|
264
271
|
const data = await fsp.readFile(file, 'utf8')
|
|
265
272
|
const parsed: unknown = JSON.parse(data)
|
|
266
|
-
const validated =
|
|
273
|
+
const validated = templateFileDataSchema.safeParse(parsed)
|
|
267
274
|
if (!validated.success) return null
|
|
268
275
|
return 'transloadit_template_id' in validated.data ? { file, data: validated.data } : null
|
|
269
276
|
} catch (e) {
|
package/src/cli/stepsInput.ts
CHANGED
|
@@ -1,14 +1,40 @@
|
|
|
1
1
|
import type { StepsInput } from '../alphalib/types/template.ts'
|
|
2
|
+
import type { IOutputCtl } from './OutputCtl.ts'
|
|
2
3
|
|
|
3
4
|
import fsp from 'node:fs/promises'
|
|
4
5
|
|
|
5
6
|
import { z } from 'zod'
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
+
import { robotsSchema } from '../alphalib/types/robots/_index.ts'
|
|
9
|
+
import { refineDocumentExtractOcr } from '../alphalib/types/robots/document-extract.ts'
|
|
10
|
+
import { refineTransloaditImportSelector } from '../alphalib/types/robots/transloadit-import.ts'
|
|
8
11
|
|
|
9
12
|
const stepsWrapperSchema = z.object({ steps: z.record(z.unknown()) })
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
/** CLI inputs can be partial overrides; API2 validates OCR after merging their runtime context. */
|
|
15
|
+
export function createCliStepsSchema(
|
|
16
|
+
output: Pick<IOutputCtl, 'warn'> = console,
|
|
17
|
+
): z.ZodType<StepsInput> {
|
|
18
|
+
const cliStepSchema = robotsSchema
|
|
19
|
+
.superRefine(refineTransloaditImportSelector)
|
|
20
|
+
.superRefine((step, context) => {
|
|
21
|
+
// API2 merges Template defaults before Robot validation. New OCR checks must not reject
|
|
22
|
+
// partial --steps overrides in a minor release; explicit Zod schemas remain strict.
|
|
23
|
+
refineDocumentExtractOcr(step, {
|
|
24
|
+
...context,
|
|
25
|
+
addIssue(issue) {
|
|
26
|
+
const field = [...context.path, ...(issue.path ?? [])].join('.')
|
|
27
|
+
output.warn(`${field}: ${issue.message ?? 'Invalid OCR dependency.'}`)
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
return z.record(cliStepSchema)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function parseStepsInputJson(
|
|
35
|
+
content: string,
|
|
36
|
+
output: Pick<IOutputCtl, 'warn'> = console,
|
|
37
|
+
): StepsInput {
|
|
12
38
|
const parsed: unknown = JSON.parse(content)
|
|
13
39
|
const wrapped = stepsWrapperSchema.safeParse(parsed)
|
|
14
40
|
let stepsInput = parsed
|
|
@@ -21,7 +47,7 @@ export function parseStepsInputJson(content: string): StepsInput {
|
|
|
21
47
|
}
|
|
22
48
|
stepsInput = validatedWrapper.data.steps
|
|
23
49
|
}
|
|
24
|
-
const validated =
|
|
50
|
+
const validated = createCliStepsSchema(output).safeParse(stepsInput)
|
|
25
51
|
if (!validated.success) {
|
|
26
52
|
throw new Error(`Invalid steps format: ${validated.error.message}`)
|
|
27
53
|
}
|
|
@@ -42,7 +68,10 @@ export function parseStepsInputJson(content: string): StepsInput {
|
|
|
42
68
|
) as StepsInput
|
|
43
69
|
}
|
|
44
70
|
|
|
45
|
-
export async function readStepsInputFile(
|
|
71
|
+
export async function readStepsInputFile(
|
|
72
|
+
filePath: string,
|
|
73
|
+
output: Pick<IOutputCtl, 'warn'> = console,
|
|
74
|
+
): Promise<StepsInput> {
|
|
46
75
|
const content = await fsp.readFile(filePath, 'utf8')
|
|
47
|
-
return parseStepsInputJson(content)
|
|
76
|
+
return parseStepsInputJson(content, output)
|
|
48
77
|
}
|
package/src/cli/types.ts
CHANGED
|
@@ -2,8 +2,6 @@ import type { Steps } from '../alphalib/types/template.ts'
|
|
|
2
2
|
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
|
|
5
|
-
import { optionalStepsSchema } from '../alphalib/types/template.ts'
|
|
6
|
-
|
|
7
5
|
// Zod schemas for runtime validation
|
|
8
6
|
const APIErrorSchema = z.object({
|
|
9
7
|
error: z.string(),
|
|
@@ -36,13 +34,6 @@ export interface TemplateFileData {
|
|
|
36
34
|
[key: string]: unknown // passthrough
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
export const TemplateFileDataSchema: z.ZodType<TemplateFileData> = z
|
|
40
|
-
.object({
|
|
41
|
-
transloadit_template_id: z.string().optional(),
|
|
42
|
-
steps: optionalStepsSchema,
|
|
43
|
-
})
|
|
44
|
-
.passthrough() as z.ZodType<TemplateFileData>
|
|
45
|
-
|
|
46
37
|
export interface TemplateFile {
|
|
47
38
|
file: string
|
|
48
39
|
data: TemplateFileData
|