transloadit 4.7.3 → 4.7.6
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 +897 -5
- package/dist/Transloadit.d.ts +13 -3
- package/dist/Transloadit.d.ts.map +1 -1
- package/dist/Transloadit.js +22 -2
- package/dist/Transloadit.js.map +1 -1
- package/dist/alphalib/types/assembliesGet.d.ts +5 -0
- package/dist/alphalib/types/assembliesGet.d.ts.map +1 -1
- package/dist/alphalib/types/assemblyReplay.d.ts +5 -0
- package/dist/alphalib/types/assemblyReplay.d.ts.map +1 -1
- package/dist/alphalib/types/assemblyReplayNotification.d.ts +5 -0
- package/dist/alphalib/types/assemblyReplayNotification.d.ts.map +1 -1
- package/dist/alphalib/types/assemblyStatus.d.ts +25 -25
- package/dist/alphalib/types/assemblyStatus.d.ts.map +1 -1
- package/dist/alphalib/types/assemblyStatus.js +4 -1
- package/dist/alphalib/types/assemblyStatus.js.map +1 -1
- package/dist/alphalib/types/bill.d.ts +5 -0
- package/dist/alphalib/types/bill.d.ts.map +1 -1
- package/dist/alphalib/types/builtinTemplates.d.ts +83 -0
- package/dist/alphalib/types/builtinTemplates.d.ts.map +1 -0
- package/dist/alphalib/types/builtinTemplates.js +19 -0
- package/dist/alphalib/types/builtinTemplates.js.map +1 -0
- package/dist/alphalib/types/robots/ai-chat.d.ts.map +1 -1
- package/dist/alphalib/types/robots/ai-chat.js +1 -0
- package/dist/alphalib/types/robots/ai-chat.js.map +1 -1
- package/dist/alphalib/types/skillFrontmatter.d.ts +29 -0
- package/dist/alphalib/types/skillFrontmatter.d.ts.map +1 -0
- package/dist/alphalib/types/skillFrontmatter.js +19 -0
- package/dist/alphalib/types/skillFrontmatter.js.map +1 -0
- package/dist/alphalib/types/template.d.ts +36 -0
- package/dist/alphalib/types/template.d.ts.map +1 -1
- package/dist/alphalib/types/template.js +10 -0
- package/dist/alphalib/types/template.js.map +1 -1
- package/dist/alphalib/types/templateCredential.d.ts +10 -0
- package/dist/alphalib/types/templateCredential.d.ts.map +1 -1
- package/dist/bearerToken.d.ts +31 -0
- package/dist/bearerToken.d.ts.map +1 -0
- package/dist/bearerToken.js +158 -0
- package/dist/bearerToken.js.map +1 -0
- package/dist/cli/commands/assemblies.d.ts +8 -2
- package/dist/cli/commands/assemblies.d.ts.map +1 -1
- package/dist/cli/commands/assemblies.js +566 -411
- package/dist/cli/commands/assemblies.js.map +1 -1
- package/dist/cli/commands/auth.d.ts +1 -4
- package/dist/cli/commands/auth.d.ts.map +1 -1
- package/dist/cli/commands/auth.js +7 -123
- 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 +5 -0
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/templates.d.ts.map +1 -1
- package/dist/cli/commands/templates.js +4 -14
- package/dist/cli/commands/templates.js.map +1 -1
- package/dist/cli/fileProcessingOptions.d.ts +35 -0
- package/dist/cli/fileProcessingOptions.d.ts.map +1 -0
- package/dist/cli/fileProcessingOptions.js +182 -0
- package/dist/cli/fileProcessingOptions.js.map +1 -0
- package/dist/cli/generateIntentDocs.d.ts +2 -0
- package/dist/cli/generateIntentDocs.d.ts.map +1 -0
- package/dist/cli/generateIntentDocs.js +321 -0
- package/dist/cli/generateIntentDocs.js.map +1 -0
- package/dist/cli/intentCommandSpecs.d.ts +36 -0
- package/dist/cli/intentCommandSpecs.d.ts.map +1 -0
- package/dist/cli/intentCommandSpecs.js +181 -0
- package/dist/cli/intentCommandSpecs.js.map +1 -0
- package/dist/cli/intentCommands.d.ts +13 -0
- package/dist/cli/intentCommands.d.ts.map +1 -0
- package/dist/cli/intentCommands.js +368 -0
- package/dist/cli/intentCommands.js.map +1 -0
- package/dist/cli/intentFields.d.ts +25 -0
- package/dist/cli/intentFields.d.ts.map +1 -0
- package/dist/cli/intentFields.js +298 -0
- package/dist/cli/intentFields.js.map +1 -0
- package/dist/cli/intentInputPolicy.d.ts +10 -0
- package/dist/cli/intentInputPolicy.d.ts.map +1 -0
- package/dist/cli/intentInputPolicy.js +2 -0
- package/dist/cli/intentInputPolicy.js.map +1 -0
- package/dist/cli/intentRuntime.d.ts +114 -0
- package/dist/cli/intentRuntime.d.ts.map +1 -0
- package/dist/cli/intentRuntime.js +464 -0
- package/dist/cli/intentRuntime.js.map +1 -0
- package/dist/cli/resultFiles.d.ts +19 -0
- package/dist/cli/resultFiles.d.ts.map +1 -0
- package/dist/cli/resultFiles.js +66 -0
- package/dist/cli/resultFiles.js.map +1 -0
- package/dist/cli/resultUrls.d.ts +19 -0
- package/dist/cli/resultUrls.d.ts.map +1 -0
- package/dist/cli/resultUrls.js +36 -0
- package/dist/cli/resultUrls.js.map +1 -0
- package/dist/cli/semanticIntents/imageDescribe.d.ts +43 -0
- package/dist/cli/semanticIntents/imageDescribe.d.ts.map +1 -0
- package/dist/cli/semanticIntents/imageDescribe.js +188 -0
- package/dist/cli/semanticIntents/imageDescribe.js.map +1 -0
- package/dist/cli/semanticIntents/index.d.ts +18 -0
- package/dist/cli/semanticIntents/index.d.ts.map +1 -0
- package/dist/cli/semanticIntents/index.js +18 -0
- package/dist/cli/semanticIntents/index.js.map +1 -0
- package/dist/cli/semanticIntents/markdownPdf.d.ts +4 -0
- package/dist/cli/semanticIntents/markdownPdf.d.ts.map +1 -0
- package/dist/cli/semanticIntents/markdownPdf.js +93 -0
- package/dist/cli/semanticIntents/markdownPdf.js.map +1 -0
- package/dist/cli/semanticIntents/parsing.d.ts +11 -0
- package/dist/cli/semanticIntents/parsing.d.ts.map +1 -0
- package/dist/cli/semanticIntents/parsing.js +29 -0
- package/dist/cli/semanticIntents/parsing.js.map +1 -0
- package/dist/cli/stepsInput.d.ts +4 -0
- package/dist/cli/stepsInput.d.ts.map +1 -0
- package/dist/cli/stepsInput.js +23 -0
- package/dist/cli/stepsInput.js.map +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +5 -4
- package/dist/cli.js.map +1 -1
- package/dist/ensureUniqueCounter.d.ts +8 -0
- package/dist/ensureUniqueCounter.d.ts.map +1 -0
- package/dist/ensureUniqueCounter.js +48 -0
- package/dist/ensureUniqueCounter.js.map +1 -0
- package/dist/inputFiles.d.ts +9 -0
- package/dist/inputFiles.d.ts.map +1 -1
- package/dist/inputFiles.js +177 -26
- package/dist/inputFiles.js.map +1 -1
- package/dist/robots.js +1 -1
- package/dist/robots.js.map +1 -1
- package/package.json +9 -7
- package/src/Transloadit.ts +35 -3
- package/src/alphalib/types/assemblyStatus.ts +4 -1
- package/src/alphalib/types/builtinTemplates.ts +24 -0
- package/src/alphalib/types/robots/ai-chat.ts +1 -0
- package/src/alphalib/types/skillFrontmatter.ts +24 -0
- package/src/alphalib/types/template.ts +14 -0
- package/src/bearerToken.ts +208 -0
- package/src/cli/commands/assemblies.ts +825 -505
- package/src/cli/commands/auth.ts +9 -151
- package/src/cli/commands/index.ts +6 -3
- package/src/cli/commands/templates.ts +6 -17
- package/src/cli/fileProcessingOptions.ts +294 -0
- package/src/cli/generateIntentDocs.ts +419 -0
- package/src/cli/intentCommandSpecs.ts +282 -0
- package/src/cli/intentCommands.ts +525 -0
- package/src/cli/intentFields.ts +403 -0
- package/src/cli/intentInputPolicy.ts +11 -0
- package/src/cli/intentRuntime.ts +734 -0
- package/src/cli/resultFiles.ts +105 -0
- package/src/cli/resultUrls.ts +72 -0
- package/src/cli/semanticIntents/imageDescribe.ts +254 -0
- package/src/cli/semanticIntents/index.ts +48 -0
- package/src/cli/semanticIntents/markdownPdf.ts +120 -0
- package/src/cli/semanticIntents/parsing.ts +56 -0
- package/src/cli/stepsInput.ts +32 -0
- package/src/cli.ts +5 -4
- package/src/ensureUniqueCounter.ts +75 -0
- package/src/inputFiles.ts +277 -26
- package/src/robots.ts +1 -1
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
export type BearerTokenAudience = 'mcp' | 'api2' | (string & {})
|
|
4
|
+
|
|
5
|
+
export type BearerTokenResponse = {
|
|
6
|
+
access_token: string
|
|
7
|
+
token_type: 'Bearer'
|
|
8
|
+
expires_in: number
|
|
9
|
+
scope?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type MintBearerTokenOptions = {
|
|
13
|
+
endpoint?: string
|
|
14
|
+
aud?: BearerTokenAudience | string
|
|
15
|
+
/**
|
|
16
|
+
* Requested scopes. Must be a subset of the auth key's scope.
|
|
17
|
+
*
|
|
18
|
+
* If omitted, the token inherits the auth key's scope.
|
|
19
|
+
*/
|
|
20
|
+
scope?: string[] | string
|
|
21
|
+
timeoutMs?: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type MintBearerTokenResult =
|
|
25
|
+
| { ok: true; raw: string; data: BearerTokenResponse }
|
|
26
|
+
| { ok: false; error: string }
|
|
27
|
+
|
|
28
|
+
const tokenErrorSchema = z
|
|
29
|
+
.object({
|
|
30
|
+
error: z.string(),
|
|
31
|
+
message: z.string().optional(),
|
|
32
|
+
})
|
|
33
|
+
.passthrough()
|
|
34
|
+
|
|
35
|
+
const tokenSuccessSchema = z
|
|
36
|
+
.object({
|
|
37
|
+
access_token: z.string().min(1),
|
|
38
|
+
token_type: z.literal('Bearer').optional(),
|
|
39
|
+
expires_in: z.number(),
|
|
40
|
+
scope: z.string().optional(),
|
|
41
|
+
})
|
|
42
|
+
.passthrough()
|
|
43
|
+
|
|
44
|
+
const buildBasicAuthHeaderValue = (credentials: { authKey: string; authSecret: string }): string =>
|
|
45
|
+
`Basic ${Buffer.from(`${credentials.authKey}:${credentials.authSecret}`, 'utf8').toString('base64')}`
|
|
46
|
+
|
|
47
|
+
const isLoopbackHost = (hostname: string): boolean =>
|
|
48
|
+
hostname === 'localhost' || hostname === '::1' || hostname.startsWith('127.')
|
|
49
|
+
|
|
50
|
+
type TokenBaseResult = { ok: true; baseUrl: URL } | { ok: false; error: string }
|
|
51
|
+
|
|
52
|
+
const normalizeTokenBaseEndpoint = (raw?: string): TokenBaseResult => {
|
|
53
|
+
const baseRaw = (raw || process.env.TRANSLOADIT_ENDPOINT || 'https://api2.transloadit.com').trim()
|
|
54
|
+
|
|
55
|
+
let url: URL
|
|
56
|
+
try {
|
|
57
|
+
url = new URL(baseRaw)
|
|
58
|
+
} catch {
|
|
59
|
+
return {
|
|
60
|
+
ok: false,
|
|
61
|
+
error:
|
|
62
|
+
'Invalid endpoint URL. Use --endpoint https://api2.transloadit.com (or set TRANSLOADIT_ENDPOINT).',
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (url.username || url.password) {
|
|
67
|
+
return { ok: false, error: 'Endpoint must not include username/password.' }
|
|
68
|
+
}
|
|
69
|
+
if (url.search || url.hash) {
|
|
70
|
+
return { ok: false, error: 'Endpoint must not include query string or hash.' }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (url.protocol !== 'https:') {
|
|
74
|
+
if (url.protocol === 'http:' && isLoopbackHost(url.hostname)) {
|
|
75
|
+
// Allowed for local development only.
|
|
76
|
+
} else {
|
|
77
|
+
return {
|
|
78
|
+
ok: false,
|
|
79
|
+
error:
|
|
80
|
+
'Refusing to send credentials to a non-HTTPS endpoint. Use https://... (or http://localhost for local development).',
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// If someone pasted the token URL, normalize it back to the API base to avoid /token/token.
|
|
86
|
+
const pathLower = url.pathname.toLowerCase()
|
|
87
|
+
if (pathLower === '/token' || pathLower === '/token/') {
|
|
88
|
+
url.pathname = '/'
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!url.pathname.endsWith('/')) {
|
|
92
|
+
url.pathname = `${url.pathname}/`
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return { ok: true, baseUrl: url }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const normalizeScopeInput = (input?: string[] | string): string | undefined => {
|
|
99
|
+
if (input == null) return undefined
|
|
100
|
+
|
|
101
|
+
const raw = Array.isArray(input) ? input.join(' ') : String(input)
|
|
102
|
+
const trimmed = raw.trim()
|
|
103
|
+
if (!trimmed) return undefined
|
|
104
|
+
|
|
105
|
+
const parts = trimmed.split(/[\s,]+/).map((p) => p.trim())
|
|
106
|
+
const seen = new Set<string>()
|
|
107
|
+
const out: string[] = []
|
|
108
|
+
for (const part of parts) {
|
|
109
|
+
if (!part || seen.has(part)) continue
|
|
110
|
+
seen.add(part)
|
|
111
|
+
out.push(part)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return out.length > 0 ? out.join(' ') : undefined
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export async function mintBearerTokenWithCredentials(
|
|
118
|
+
credentials: { authKey: string; authSecret: string },
|
|
119
|
+
options: MintBearerTokenOptions = {},
|
|
120
|
+
): Promise<MintBearerTokenResult> {
|
|
121
|
+
const endpointResult = normalizeTokenBaseEndpoint(options.endpoint)
|
|
122
|
+
if (!endpointResult.ok) {
|
|
123
|
+
return { ok: false, error: endpointResult.error }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const url = new URL('token', endpointResult.baseUrl).toString()
|
|
127
|
+
const aud = (options.aud ?? 'mcp').trim() || 'mcp'
|
|
128
|
+
const scope = normalizeScopeInput(options.scope)
|
|
129
|
+
const timeoutMs = options.timeoutMs ?? 15_000
|
|
130
|
+
|
|
131
|
+
const params = new URLSearchParams({
|
|
132
|
+
grant_type: 'client_credentials',
|
|
133
|
+
aud,
|
|
134
|
+
})
|
|
135
|
+
if (scope) params.set('scope', scope)
|
|
136
|
+
|
|
137
|
+
let res: Response
|
|
138
|
+
const controller = new AbortController()
|
|
139
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs)
|
|
140
|
+
try {
|
|
141
|
+
res = await fetch(url, {
|
|
142
|
+
method: 'POST',
|
|
143
|
+
// Never follow redirects with Basic Auth credentials.
|
|
144
|
+
redirect: 'error',
|
|
145
|
+
signal: controller.signal,
|
|
146
|
+
headers: {
|
|
147
|
+
Authorization: buildBasicAuthHeaderValue(credentials),
|
|
148
|
+
Accept: 'application/json',
|
|
149
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
150
|
+
},
|
|
151
|
+
body: params.toString(),
|
|
152
|
+
})
|
|
153
|
+
} catch (err) {
|
|
154
|
+
clearTimeout(timeout)
|
|
155
|
+
if (err instanceof Error && err.name === 'AbortError') {
|
|
156
|
+
return {
|
|
157
|
+
ok: false,
|
|
158
|
+
error: `Failed to mint bearer token: request timed out after ${Math.round(timeoutMs / 1000)}s.`,
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const message = err instanceof Error ? err.message : String(err)
|
|
162
|
+
return { ok: false, error: `Failed to mint bearer token: ${message}` }
|
|
163
|
+
} finally {
|
|
164
|
+
clearTimeout(timeout)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const text = await res.text()
|
|
168
|
+
const trimmed = text.trim()
|
|
169
|
+
|
|
170
|
+
let parsedJson: unknown = null
|
|
171
|
+
try {
|
|
172
|
+
parsedJson = trimmed ? JSON.parse(trimmed) : null
|
|
173
|
+
} catch {
|
|
174
|
+
parsedJson = null
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (res.ok) {
|
|
178
|
+
if (parsedJson == null) {
|
|
179
|
+
return { ok: false, error: 'Token response was not valid JSON.' }
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const parsed = tokenSuccessSchema.safeParse(parsedJson)
|
|
183
|
+
if (!parsed.success) {
|
|
184
|
+
return { ok: false, error: 'Token response did not include an access_token.' }
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const data: BearerTokenResponse = {
|
|
188
|
+
...parsed.data,
|
|
189
|
+
token_type: parsed.data.token_type ?? 'Bearer',
|
|
190
|
+
}
|
|
191
|
+
return { ok: true, raw: trimmed, data }
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const parsedError = tokenErrorSchema.safeParse(parsedJson)
|
|
195
|
+
if (parsedError.success) {
|
|
196
|
+
return {
|
|
197
|
+
ok: false,
|
|
198
|
+
error: parsedError.data.message
|
|
199
|
+
? `${parsedError.data.error}: ${parsedError.data.message}`
|
|
200
|
+
: parsedError.data.error,
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
ok: false,
|
|
206
|
+
error: `Token request failed (${res.status}): ${trimmed || res.statusText}`,
|
|
207
|
+
}
|
|
208
|
+
}
|