@generaltranslation/api 0.0.0 → 0.0.2
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/CHANGELOG.md +13 -0
- package/LICENSE.md +21 -0
- package/dist/index.cjs +1227 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2370 -0
- package/dist/index.d.mts +2370 -0
- package/dist/index.mjs +1192 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +48 -5
- package/spec/openapi.json +6116 -0
- package/README.md +0 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1227 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/generated/sdk.gen.ts
|
|
3
|
+
/**
|
|
4
|
+
* Create a Project
|
|
5
|
+
*
|
|
6
|
+
* Create a Project in the Organization associated with an Organization API key. The key must have the `org:projects:create` permission. Project keys cannot use this endpoint. Enabling CDN delivery also requires `project:write`.
|
|
7
|
+
*/
|
|
8
|
+
const createProject = (options) => options.client.post({
|
|
9
|
+
security: [{
|
|
10
|
+
scheme: "bearer",
|
|
11
|
+
type: "http"
|
|
12
|
+
}],
|
|
13
|
+
url: "/v2/projects",
|
|
14
|
+
...options,
|
|
15
|
+
headers: {
|
|
16
|
+
"Content-Type": "application/json",
|
|
17
|
+
...options.headers
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Upload source files
|
|
22
|
+
*
|
|
23
|
+
* Upload one or more source files to the project. Max 100 files per request.
|
|
24
|
+
*/
|
|
25
|
+
const uploadSourceFiles = (options) => options.client.post({
|
|
26
|
+
security: [{
|
|
27
|
+
scheme: "bearer",
|
|
28
|
+
type: "http"
|
|
29
|
+
}],
|
|
30
|
+
url: "/v2/project/files/upload-files",
|
|
31
|
+
...options,
|
|
32
|
+
headers: {
|
|
33
|
+
"Content-Type": "application/json",
|
|
34
|
+
...options.headers
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Upload translated files
|
|
39
|
+
*
|
|
40
|
+
* Upload translated files linked to their source files. Max 100 files per request.
|
|
41
|
+
*/
|
|
42
|
+
const uploadTranslations = (options) => options.client.post({
|
|
43
|
+
security: [{
|
|
44
|
+
scheme: "bearer",
|
|
45
|
+
type: "http"
|
|
46
|
+
}],
|
|
47
|
+
url: "/v2/project/files/upload-translations",
|
|
48
|
+
...options,
|
|
49
|
+
headers: {
|
|
50
|
+
"Content-Type": "application/json",
|
|
51
|
+
...options.headers
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Upload Project assets
|
|
56
|
+
*
|
|
57
|
+
* Upload OpenType or TrueType fonts through a Project and make them available to Lottie translation workflows across its Organization. Each font is keyed by a normalized identity derived from its family, weight, and italic style (from the supplied `family` and `style`, or from the font metadata and file name). Re-uploading the same identity overwrites the existing asset, so complete retries after a `500` response are safe.
|
|
58
|
+
*/
|
|
59
|
+
const uploadAssets = (options) => options.client.post({
|
|
60
|
+
security: [{
|
|
61
|
+
scheme: "bearer",
|
|
62
|
+
type: "http"
|
|
63
|
+
}],
|
|
64
|
+
url: "/v2/project/assets",
|
|
65
|
+
...options,
|
|
66
|
+
headers: {
|
|
67
|
+
"Content-Type": "application/json",
|
|
68
|
+
...options.headers
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
/**
|
|
72
|
+
* Submit translation diffs
|
|
73
|
+
*
|
|
74
|
+
* Overwrite translations with user-provided localized content.
|
|
75
|
+
*/
|
|
76
|
+
const submitUserEditDiffs = (options) => options.client.post({
|
|
77
|
+
security: [{
|
|
78
|
+
scheme: "bearer",
|
|
79
|
+
type: "http"
|
|
80
|
+
}],
|
|
81
|
+
url: "/v2/project/files/diffs",
|
|
82
|
+
...options,
|
|
83
|
+
headers: {
|
|
84
|
+
"Content-Type": "application/json",
|
|
85
|
+
...options.headers
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
/**
|
|
89
|
+
* Check if context generation is needed
|
|
90
|
+
*
|
|
91
|
+
* Check whether the Project needs translation context generated. This deprecated endpoint is retained for backward compatibility and is no longer called by current clients.
|
|
92
|
+
*
|
|
93
|
+
* @deprecated
|
|
94
|
+
*/
|
|
95
|
+
const shouldGenerateProjectContext = (options) => options.client.get({
|
|
96
|
+
security: [{
|
|
97
|
+
scheme: "bearer",
|
|
98
|
+
type: "http"
|
|
99
|
+
}],
|
|
100
|
+
url: "/v2/project/setup/should-generate",
|
|
101
|
+
...options
|
|
102
|
+
});
|
|
103
|
+
/**
|
|
104
|
+
* Generate translation context
|
|
105
|
+
*
|
|
106
|
+
* Generate glossaries and translation instructions for the project.
|
|
107
|
+
*/
|
|
108
|
+
const generateProjectContext = (options) => options.client.post({
|
|
109
|
+
security: [{
|
|
110
|
+
scheme: "bearer",
|
|
111
|
+
type: "http"
|
|
112
|
+
}],
|
|
113
|
+
url: "/v2/project/setup/generate",
|
|
114
|
+
...options,
|
|
115
|
+
headers: {
|
|
116
|
+
"Content-Type": "application/json",
|
|
117
|
+
...options.headers
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
/**
|
|
121
|
+
* Get context generation job status
|
|
122
|
+
*
|
|
123
|
+
* Track a context generation job. This deprecated endpoint is retained for backward compatibility; new integrations should use `POST /v2/project/jobs/info`.
|
|
124
|
+
*
|
|
125
|
+
* @deprecated
|
|
126
|
+
*/
|
|
127
|
+
const getProjectContextGenerationStatus = (options) => options.client.get({
|
|
128
|
+
security: [{
|
|
129
|
+
scheme: "bearer",
|
|
130
|
+
type: "http"
|
|
131
|
+
}],
|
|
132
|
+
url: "/v2/project/setup/status/{jobId}",
|
|
133
|
+
...options
|
|
134
|
+
});
|
|
135
|
+
/**
|
|
136
|
+
* Queue files for translation
|
|
137
|
+
*
|
|
138
|
+
* Enqueue uploaded source files for background translation. Max 100 files per request. The response shape depends on the requested `gt-api-version`.
|
|
139
|
+
*/
|
|
140
|
+
const enqueueFileTranslations = (options) => options.client.post({
|
|
141
|
+
security: [{
|
|
142
|
+
scheme: "bearer",
|
|
143
|
+
type: "http"
|
|
144
|
+
}],
|
|
145
|
+
url: "/v2/project/translations/enqueue",
|
|
146
|
+
...options,
|
|
147
|
+
headers: {
|
|
148
|
+
"Content-Type": "application/json",
|
|
149
|
+
...options.headers
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
/**
|
|
153
|
+
* Publish or unpublish files
|
|
154
|
+
*
|
|
155
|
+
* Publish or unpublish translated files to the CDN. Requires CDN to be enabled.
|
|
156
|
+
*/
|
|
157
|
+
const publishFiles = (options) => options.client.post({
|
|
158
|
+
security: [{
|
|
159
|
+
scheme: "bearer",
|
|
160
|
+
type: "http"
|
|
161
|
+
}],
|
|
162
|
+
url: "/v2/project/files/publish",
|
|
163
|
+
...options,
|
|
164
|
+
headers: {
|
|
165
|
+
"Content-Type": "application/json",
|
|
166
|
+
...options.headers
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
/**
|
|
170
|
+
* Download a single file
|
|
171
|
+
*
|
|
172
|
+
* Download a single source or translated file. This deprecated endpoint is retained for backward compatibility; new integrations should use `POST /v2/project/files/download`.
|
|
173
|
+
*
|
|
174
|
+
* @deprecated
|
|
175
|
+
*/
|
|
176
|
+
const downloadFile = (options) => options.client.get({
|
|
177
|
+
security: [{
|
|
178
|
+
scheme: "bearer",
|
|
179
|
+
type: "http"
|
|
180
|
+
}],
|
|
181
|
+
url: "/v2/project/files/download/{fileId}",
|
|
182
|
+
...options
|
|
183
|
+
});
|
|
184
|
+
/**
|
|
185
|
+
* Download multiple files
|
|
186
|
+
*
|
|
187
|
+
* Download up to 100 source or translated files in one request.
|
|
188
|
+
*/
|
|
189
|
+
const downloadFiles = (options) => options.client.post({
|
|
190
|
+
security: [{
|
|
191
|
+
scheme: "bearer",
|
|
192
|
+
type: "http"
|
|
193
|
+
}],
|
|
194
|
+
url: "/v2/project/files/download",
|
|
195
|
+
...options,
|
|
196
|
+
headers: {
|
|
197
|
+
"Content-Type": "application/json",
|
|
198
|
+
...options.headers
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
/**
|
|
202
|
+
* Get branch information
|
|
203
|
+
*
|
|
204
|
+
* Return the Project's default branch and any branches requested by name.
|
|
205
|
+
*/
|
|
206
|
+
const getBranchInfo = (options) => options.client.post({
|
|
207
|
+
security: [{
|
|
208
|
+
scheme: "bearer",
|
|
209
|
+
type: "http"
|
|
210
|
+
}],
|
|
211
|
+
url: "/v2/project/branches/info",
|
|
212
|
+
...options,
|
|
213
|
+
headers: {
|
|
214
|
+
"Content-Type": "application/json",
|
|
215
|
+
...options.headers
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
/**
|
|
219
|
+
* Create a branch
|
|
220
|
+
*
|
|
221
|
+
* Create a new branch, or rename and confirm the default branch.
|
|
222
|
+
*/
|
|
223
|
+
const createBranch = (options) => options.client.post({
|
|
224
|
+
security: [{
|
|
225
|
+
scheme: "bearer",
|
|
226
|
+
type: "http"
|
|
227
|
+
}],
|
|
228
|
+
url: "/v2/project/branches/create",
|
|
229
|
+
...options,
|
|
230
|
+
headers: {
|
|
231
|
+
"Content-Type": "application/json",
|
|
232
|
+
...options.headers
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
/**
|
|
236
|
+
* Create or update a tag
|
|
237
|
+
*
|
|
238
|
+
* Create or upsert a tag that points at a set of file versions.
|
|
239
|
+
*/
|
|
240
|
+
const createTag = (options) => options.client.post({
|
|
241
|
+
security: [{
|
|
242
|
+
scheme: "bearer",
|
|
243
|
+
type: "http"
|
|
244
|
+
}],
|
|
245
|
+
url: "/v2/project/tags/create",
|
|
246
|
+
...options,
|
|
247
|
+
headers: {
|
|
248
|
+
"Content-Type": "application/json",
|
|
249
|
+
...options.headers
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
/**
|
|
253
|
+
* Get Project information
|
|
254
|
+
*
|
|
255
|
+
* Read the authenticated Project's name, Organization ID, locale settings, and auto-approval setting.
|
|
256
|
+
*/
|
|
257
|
+
const getProjectInfo = (options) => options.client.get({
|
|
258
|
+
security: [{
|
|
259
|
+
scheme: "bearer",
|
|
260
|
+
type: "http"
|
|
261
|
+
}],
|
|
262
|
+
url: "/v2/project/info/{projectId}",
|
|
263
|
+
...options
|
|
264
|
+
});
|
|
265
|
+
/**
|
|
266
|
+
* Update Project information
|
|
267
|
+
*
|
|
268
|
+
* Update the Project's default locale or CDN delivery setting.
|
|
269
|
+
*/
|
|
270
|
+
const updateProjectInfo = (options) => options.client.post({
|
|
271
|
+
security: [{
|
|
272
|
+
scheme: "bearer",
|
|
273
|
+
type: "http"
|
|
274
|
+
}],
|
|
275
|
+
url: "/v2/project/info/{projectId}",
|
|
276
|
+
...options,
|
|
277
|
+
headers: {
|
|
278
|
+
"Content-Type": "application/json",
|
|
279
|
+
...options.headers
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
/**
|
|
283
|
+
* Get translation job status
|
|
284
|
+
*
|
|
285
|
+
* Return normalized status information for one or more queued translation or context generation jobs.
|
|
286
|
+
*/
|
|
287
|
+
const getTranslationJobInfo = (options) => options.client.post({
|
|
288
|
+
security: [{
|
|
289
|
+
scheme: "bearer",
|
|
290
|
+
type: "http"
|
|
291
|
+
}],
|
|
292
|
+
url: "/v2/project/jobs/info",
|
|
293
|
+
...options,
|
|
294
|
+
headers: {
|
|
295
|
+
"Content-Type": "application/json",
|
|
296
|
+
...options.headers
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
/**
|
|
300
|
+
* Translate content at runtime
|
|
301
|
+
*
|
|
302
|
+
* Translate one or more strings or structured content entries with caching and memoization. Development API keys are accepted for this endpoint.
|
|
303
|
+
*/
|
|
304
|
+
const translate = (options) => options.client.post({
|
|
305
|
+
security: [{
|
|
306
|
+
scheme: "bearer",
|
|
307
|
+
type: "http"
|
|
308
|
+
}],
|
|
309
|
+
url: "/v2/translate",
|
|
310
|
+
...options,
|
|
311
|
+
headers: {
|
|
312
|
+
"Content-Type": "application/json",
|
|
313
|
+
...options.headers
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
/**
|
|
317
|
+
* Get file metadata
|
|
318
|
+
*
|
|
319
|
+
* Get detailed metadata for specific source and translated files.
|
|
320
|
+
*/
|
|
321
|
+
const getFileInfo = (options) => options.client.post({
|
|
322
|
+
security: [{
|
|
323
|
+
scheme: "bearer",
|
|
324
|
+
type: "http"
|
|
325
|
+
}],
|
|
326
|
+
url: "/v2/project/files/info",
|
|
327
|
+
...options,
|
|
328
|
+
headers: {
|
|
329
|
+
"Content-Type": "application/json",
|
|
330
|
+
...options.headers
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
/**
|
|
334
|
+
* Get translation status for a file
|
|
335
|
+
*
|
|
336
|
+
* Return translation progress and availability by locale for one source file, along with its source metadata.
|
|
337
|
+
*/
|
|
338
|
+
const getTranslationStatus = (options) => options.client.get({
|
|
339
|
+
security: [{
|
|
340
|
+
scheme: "bearer",
|
|
341
|
+
type: "http"
|
|
342
|
+
}],
|
|
343
|
+
url: "/v2/project/translations/files/status/{fileId}",
|
|
344
|
+
...options
|
|
345
|
+
});
|
|
346
|
+
/**
|
|
347
|
+
* Move or rename files
|
|
348
|
+
*
|
|
349
|
+
* Clone source files and their translations under new file IDs.
|
|
350
|
+
*/
|
|
351
|
+
const processFileMoves = (options) => options.client.post({
|
|
352
|
+
security: [{
|
|
353
|
+
scheme: "bearer",
|
|
354
|
+
type: "http"
|
|
355
|
+
}],
|
|
356
|
+
url: "/v2/project/files/moves",
|
|
357
|
+
...options,
|
|
358
|
+
headers: {
|
|
359
|
+
"Content-Type": "application/json",
|
|
360
|
+
...options.headers
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
/**
|
|
364
|
+
* Find orphaned files
|
|
365
|
+
*
|
|
366
|
+
* Return files on a branch that are not present in the provided file ID list.
|
|
367
|
+
*/
|
|
368
|
+
const getOrphanedFiles = (options) => options.client.post({
|
|
369
|
+
security: [{
|
|
370
|
+
scheme: "bearer",
|
|
371
|
+
type: "http"
|
|
372
|
+
}],
|
|
373
|
+
url: "/v2/project/files/orphaned",
|
|
374
|
+
...options,
|
|
375
|
+
headers: {
|
|
376
|
+
"Content-Type": "application/json",
|
|
377
|
+
...options.headers
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
/**
|
|
381
|
+
* Create a CLI wizard session
|
|
382
|
+
*
|
|
383
|
+
* Create a temporary session for CLI browser authentication.
|
|
384
|
+
*/
|
|
385
|
+
const createCliWizardSession = (options) => options.client.post({
|
|
386
|
+
url: "/cli/wizard/session",
|
|
387
|
+
...options,
|
|
388
|
+
headers: {
|
|
389
|
+
"Content-Type": "application/json",
|
|
390
|
+
...options.headers
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
/**
|
|
394
|
+
* Delete a CLI wizard session
|
|
395
|
+
*
|
|
396
|
+
* Delete a completed or abandoned CLI wizard session.
|
|
397
|
+
*/
|
|
398
|
+
const deleteCliWizardSession = (options) => options.client.delete({
|
|
399
|
+
url: "/cli/wizard/{sessionId}",
|
|
400
|
+
...options
|
|
401
|
+
});
|
|
402
|
+
/**
|
|
403
|
+
* Get a CLI wizard session
|
|
404
|
+
*
|
|
405
|
+
* Get credentials for a completed CLI wizard session or its current waiting status.
|
|
406
|
+
*/
|
|
407
|
+
const getCliWizardSession = (options) => options.client.get({
|
|
408
|
+
url: "/cli/wizard/{sessionId}",
|
|
409
|
+
...options
|
|
410
|
+
});
|
|
411
|
+
//#endregion
|
|
412
|
+
//#region src/wrappers/transport.ts
|
|
413
|
+
const MAX_RETRIES = 3;
|
|
414
|
+
const INITIAL_DELAY_MS = 500;
|
|
415
|
+
const RATE_LIMIT_RETRY_DELAY_MS = 6e4;
|
|
416
|
+
const IDEMPOTENT_METHODS = new Set([
|
|
417
|
+
"GET",
|
|
418
|
+
"HEAD",
|
|
419
|
+
"OPTIONS",
|
|
420
|
+
"PUT",
|
|
421
|
+
"DELETE"
|
|
422
|
+
]);
|
|
423
|
+
const DEFAULT_TIMEOUT_MS = 6e4;
|
|
424
|
+
function createTimeoutFetch({ fetch: fetchImplementation = globalThis.fetch, timeoutMs = DEFAULT_TIMEOUT_MS } = {}) {
|
|
425
|
+
return async (input, init) => {
|
|
426
|
+
const request = new Request(input, init);
|
|
427
|
+
const controller = new AbortController();
|
|
428
|
+
const forwardAbort = () => controller.abort(request.signal.reason);
|
|
429
|
+
if (request.signal.aborted) forwardAbort();
|
|
430
|
+
else request.signal.addEventListener("abort", forwardAbort, { once: true });
|
|
431
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
432
|
+
try {
|
|
433
|
+
return await fetchImplementation(new Request(request, { signal: controller.signal }));
|
|
434
|
+
} catch (error) {
|
|
435
|
+
if (controller.signal.aborted && !request.signal.aborted) throw new Error(`Request timed out after ${timeoutMs}ms`);
|
|
436
|
+
throw error;
|
|
437
|
+
} finally {
|
|
438
|
+
clearTimeout(timeoutId);
|
|
439
|
+
request.signal.removeEventListener("abort", forwardAbort);
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
444
|
+
function parseDelayMs(value) {
|
|
445
|
+
if (!value) return void 0;
|
|
446
|
+
const seconds = Number(value.split(",")[0].split(";")[0].trim());
|
|
447
|
+
return Number.isFinite(seconds) && seconds >= 0 ? seconds * 1e3 : void 0;
|
|
448
|
+
}
|
|
449
|
+
function parseRetryAfter(value) {
|
|
450
|
+
const delayMs = parseDelayMs(value);
|
|
451
|
+
if (delayMs !== void 0) return delayMs;
|
|
452
|
+
if (!value) return void 0;
|
|
453
|
+
const retryDate = Date.parse(value);
|
|
454
|
+
return Number.isNaN(retryDate) ? void 0 : Math.max(retryDate - Date.now(), 0);
|
|
455
|
+
}
|
|
456
|
+
function retryDelay(response, attempt, retryPolicy) {
|
|
457
|
+
if (response?.status === 429) return parseRetryAfter(response.headers.get("Retry-After")) ?? parseDelayMs(response.headers.get("RateLimit-Reset")) ?? RATE_LIMIT_RETRY_DELAY_MS;
|
|
458
|
+
return INITIAL_DELAY_MS * (retryPolicy === "linear" ? attempt + 1 : 2 ** attempt);
|
|
459
|
+
}
|
|
460
|
+
function createRetryingFetch({ fetch: fetchImplementation = globalThis.fetch, retryPolicy = "exponential" } = {}) {
|
|
461
|
+
return async (input, init) => {
|
|
462
|
+
const request = new Request(input, init);
|
|
463
|
+
const maxRetries = retryPolicy === "none" ? 0 : MAX_RETRIES;
|
|
464
|
+
const isIdempotent = IDEMPOTENT_METHODS.has(request.method);
|
|
465
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
466
|
+
let response;
|
|
467
|
+
try {
|
|
468
|
+
response = await fetchImplementation(request.clone());
|
|
469
|
+
} catch (error) {
|
|
470
|
+
if (request.signal.aborted || attempt === maxRetries || !isIdempotent) throw error;
|
|
471
|
+
}
|
|
472
|
+
if (response && response.status !== 429 && (response.status < 500 || !isIdempotent)) return response;
|
|
473
|
+
if (response && attempt === maxRetries) return response;
|
|
474
|
+
if (request.signal.aborted) {
|
|
475
|
+
if (response) return response;
|
|
476
|
+
throw request.signal.reason;
|
|
477
|
+
}
|
|
478
|
+
response?.body?.cancel();
|
|
479
|
+
await sleep(retryDelay(response, attempt, retryPolicy));
|
|
480
|
+
}
|
|
481
|
+
throw new Error("Max retries exceeded");
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
//#endregion
|
|
485
|
+
//#region src/wrappers/awaitJobs.ts
|
|
486
|
+
const DEFAULT_POLLING_INTERVAL_SECONDS = 5;
|
|
487
|
+
const DEFAULT_TIMEOUT_SECONDS = 600;
|
|
488
|
+
async function awaitJobs(client, jobIds, options = {}) {
|
|
489
|
+
return pollJobs(jobIds, async (pendingJobIds, signal) => {
|
|
490
|
+
return (await getTranslationJobInfo({
|
|
491
|
+
body: { jobIds: pendingJobIds },
|
|
492
|
+
client,
|
|
493
|
+
signal,
|
|
494
|
+
throwOnError: true
|
|
495
|
+
})).data;
|
|
496
|
+
}, options);
|
|
497
|
+
}
|
|
498
|
+
async function pollJobs(jobIds, getJobStatuses, options = {}) {
|
|
499
|
+
if (jobIds.length === 0) return {
|
|
500
|
+
complete: true,
|
|
501
|
+
jobs: []
|
|
502
|
+
};
|
|
503
|
+
const pollingInterval = (options.pollingIntervalSeconds ?? DEFAULT_POLLING_INTERVAL_SECONDS) * 1e3;
|
|
504
|
+
const timeout = (options.timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS) * 1e3;
|
|
505
|
+
const deadline = Date.now() + timeout;
|
|
506
|
+
const finalStatuses = new Map(jobIds.map((jobId) => [jobId, {
|
|
507
|
+
jobId,
|
|
508
|
+
status: "unknown"
|
|
509
|
+
}]));
|
|
510
|
+
const pendingJobIds = new Set(jobIds);
|
|
511
|
+
while (pendingJobIds.size > 0 && Date.now() < deadline) {
|
|
512
|
+
let statuses;
|
|
513
|
+
try {
|
|
514
|
+
statuses = await getJobStatuses([...pendingJobIds], AbortSignal.timeout(Math.min(deadline - Date.now(), DEFAULT_TIMEOUT_MS)));
|
|
515
|
+
} catch (error) {
|
|
516
|
+
if (Date.now() >= deadline) break;
|
|
517
|
+
throw error;
|
|
518
|
+
}
|
|
519
|
+
if (Date.now() >= deadline) break;
|
|
520
|
+
const returnedJobIds = new Set(statuses.map(({ jobId }) => jobId));
|
|
521
|
+
for (const job of statuses) {
|
|
522
|
+
finalStatuses.set(job.jobId, job);
|
|
523
|
+
if (job.status === "completed" || job.status === "failed" || job.status === "unknown") pendingJobIds.delete(job.jobId);
|
|
524
|
+
}
|
|
525
|
+
for (const jobId of pendingJobIds) if (!returnedJobIds.has(jobId)) {
|
|
526
|
+
finalStatuses.set(jobId, {
|
|
527
|
+
jobId,
|
|
528
|
+
status: "unknown"
|
|
529
|
+
});
|
|
530
|
+
pendingJobIds.delete(jobId);
|
|
531
|
+
}
|
|
532
|
+
if (pendingJobIds.size > 0) await new Promise((resolve) => setTimeout(resolve, Math.min(pollingInterval, deadline - Date.now())));
|
|
533
|
+
}
|
|
534
|
+
return {
|
|
535
|
+
complete: pendingJobIds.size === 0,
|
|
536
|
+
jobs: [...finalStatuses.values()]
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
//#endregion
|
|
540
|
+
//#region src/wrappers/base64.ts
|
|
541
|
+
function encodeBase64(data) {
|
|
542
|
+
if (typeof Buffer !== "undefined") return Buffer.from(data, "utf-8").toString("base64");
|
|
543
|
+
const bytes = new TextEncoder().encode(data);
|
|
544
|
+
let binary = "";
|
|
545
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
546
|
+
return btoa(binary);
|
|
547
|
+
}
|
|
548
|
+
function decodeBase64(base64) {
|
|
549
|
+
if (typeof Buffer !== "undefined") return Buffer.from(base64, "base64").toString("utf-8");
|
|
550
|
+
const bytes = Uint8Array.from(atob(base64), (character) => character.charCodeAt(0));
|
|
551
|
+
return new TextDecoder().decode(bytes);
|
|
552
|
+
}
|
|
553
|
+
function encodeFileContent(content, fileFormat) {
|
|
554
|
+
return fileFormat === "LOTTIE" ? content : encodeBase64(content);
|
|
555
|
+
}
|
|
556
|
+
function decodeFileContent(content, fileFormat) {
|
|
557
|
+
return fileFormat === "LOTTIE" ? content : decodeBase64(content);
|
|
558
|
+
}
|
|
559
|
+
//#endregion
|
|
560
|
+
//#region src/wrappers/batch.ts
|
|
561
|
+
const DEFAULT_BATCH_SIZE = 100;
|
|
562
|
+
function createBatches(items, batchSize = 100) {
|
|
563
|
+
const batches = [];
|
|
564
|
+
for (let index = 0; index < items.length; index += batchSize) batches.push(items.slice(index, index + batchSize));
|
|
565
|
+
return batches;
|
|
566
|
+
}
|
|
567
|
+
async function processBatches(items, processBatch, { batchSize = 100, parallel = true } = {}) {
|
|
568
|
+
const batches = createBatches(items, batchSize);
|
|
569
|
+
if (parallel) return (await Promise.all(batches.map(processBatch))).flat();
|
|
570
|
+
const results = [];
|
|
571
|
+
for (const batch of batches) results.push(await processBatch(batch));
|
|
572
|
+
return results.flat();
|
|
573
|
+
}
|
|
574
|
+
//#endregion
|
|
575
|
+
//#region src/generated/core/bodySerializer.gen.ts
|
|
576
|
+
const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
|
|
577
|
+
//#endregion
|
|
578
|
+
//#region src/generated/core/serverSentEvents.gen.ts
|
|
579
|
+
const createSseClient = ({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) => {
|
|
580
|
+
let lastEventId;
|
|
581
|
+
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
582
|
+
const createStream = async function* () {
|
|
583
|
+
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
584
|
+
let attempt = 0;
|
|
585
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
586
|
+
while (true) {
|
|
587
|
+
if (signal.aborted) break;
|
|
588
|
+
attempt++;
|
|
589
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
590
|
+
if (lastEventId !== void 0) headers.set("Last-Event-ID", lastEventId);
|
|
591
|
+
try {
|
|
592
|
+
const requestInit = {
|
|
593
|
+
redirect: "follow",
|
|
594
|
+
...options,
|
|
595
|
+
body: options.serializedBody,
|
|
596
|
+
headers,
|
|
597
|
+
signal
|
|
598
|
+
};
|
|
599
|
+
let request = new Request(url, requestInit);
|
|
600
|
+
if (onRequest) request = await onRequest(url, requestInit);
|
|
601
|
+
const response = await (options.fetch ?? globalThis.fetch)(request);
|
|
602
|
+
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
603
|
+
if (!response.body) throw new Error("No body in SSE response");
|
|
604
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
605
|
+
let buffer = "";
|
|
606
|
+
const abortHandler = () => {
|
|
607
|
+
try {
|
|
608
|
+
reader.cancel();
|
|
609
|
+
} catch {}
|
|
610
|
+
};
|
|
611
|
+
signal.addEventListener("abort", abortHandler);
|
|
612
|
+
try {
|
|
613
|
+
while (true) {
|
|
614
|
+
const { done, value } = await reader.read();
|
|
615
|
+
if (done) break;
|
|
616
|
+
buffer += value;
|
|
617
|
+
const chunks = buffer.split("\n\n");
|
|
618
|
+
buffer = chunks.pop() ?? "";
|
|
619
|
+
for (const chunk of chunks) {
|
|
620
|
+
const lines = chunk.split("\n");
|
|
621
|
+
const dataLines = [];
|
|
622
|
+
let eventName;
|
|
623
|
+
for (const line of lines) if (line.startsWith("data:")) dataLines.push(line.replace(/^data:\s*/, ""));
|
|
624
|
+
else if (line.startsWith("event:")) eventName = line.replace(/^event:\s*/, "");
|
|
625
|
+
else if (line.startsWith("id:")) lastEventId = line.replace(/^id:\s*/, "");
|
|
626
|
+
else if (line.startsWith("retry:")) {
|
|
627
|
+
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
628
|
+
if (!Number.isNaN(parsed)) retryDelay = parsed;
|
|
629
|
+
}
|
|
630
|
+
let data;
|
|
631
|
+
let parsedJson = false;
|
|
632
|
+
if (dataLines.length) {
|
|
633
|
+
const rawData = dataLines.join("\n");
|
|
634
|
+
try {
|
|
635
|
+
data = JSON.parse(rawData);
|
|
636
|
+
parsedJson = true;
|
|
637
|
+
} catch {
|
|
638
|
+
data = rawData;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
if (parsedJson) {
|
|
642
|
+
if (responseValidator) await responseValidator(data);
|
|
643
|
+
if (responseTransformer) data = await responseTransformer(data);
|
|
644
|
+
}
|
|
645
|
+
onSseEvent?.({
|
|
646
|
+
data,
|
|
647
|
+
event: eventName,
|
|
648
|
+
id: lastEventId,
|
|
649
|
+
retry: retryDelay
|
|
650
|
+
});
|
|
651
|
+
if (dataLines.length) yield data;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
} finally {
|
|
655
|
+
signal.removeEventListener("abort", abortHandler);
|
|
656
|
+
reader.releaseLock();
|
|
657
|
+
}
|
|
658
|
+
break;
|
|
659
|
+
} catch (error) {
|
|
660
|
+
onSseError?.(error);
|
|
661
|
+
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) break;
|
|
662
|
+
await sleep(Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4));
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
return { stream: createStream() };
|
|
667
|
+
};
|
|
668
|
+
//#endregion
|
|
669
|
+
//#region src/generated/core/pathSerializer.gen.ts
|
|
670
|
+
const separatorArrayExplode = (style) => {
|
|
671
|
+
switch (style) {
|
|
672
|
+
case "label": return ".";
|
|
673
|
+
case "matrix": return ";";
|
|
674
|
+
case "simple": return ",";
|
|
675
|
+
default: return "&";
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
const separatorArrayNoExplode = (style) => {
|
|
679
|
+
switch (style) {
|
|
680
|
+
case "form": return ",";
|
|
681
|
+
case "pipeDelimited": return "|";
|
|
682
|
+
case "spaceDelimited": return "%20";
|
|
683
|
+
default: return ",";
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
const separatorObjectExplode = (style) => {
|
|
687
|
+
switch (style) {
|
|
688
|
+
case "label": return ".";
|
|
689
|
+
case "matrix": return ";";
|
|
690
|
+
case "simple": return ",";
|
|
691
|
+
default: return "&";
|
|
692
|
+
}
|
|
693
|
+
};
|
|
694
|
+
const serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
|
|
695
|
+
if (!explode) {
|
|
696
|
+
const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
697
|
+
switch (style) {
|
|
698
|
+
case "label": return `.${joinedValues}`;
|
|
699
|
+
case "matrix": return `;${name}=${joinedValues}`;
|
|
700
|
+
case "simple": return joinedValues;
|
|
701
|
+
default: return `${name}=${joinedValues}`;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
const separator = separatorArrayExplode(style);
|
|
705
|
+
const joinedValues = value.map((v) => {
|
|
706
|
+
if (style === "label" || style === "simple") return allowReserved ? v : encodeURIComponent(v);
|
|
707
|
+
return serializePrimitiveParam({
|
|
708
|
+
allowReserved,
|
|
709
|
+
name,
|
|
710
|
+
value: v
|
|
711
|
+
});
|
|
712
|
+
}).join(separator);
|
|
713
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
714
|
+
};
|
|
715
|
+
const serializePrimitiveParam = ({ allowReserved, name, value }) => {
|
|
716
|
+
if (value === void 0 || value === null) return "";
|
|
717
|
+
if (typeof value === "object") throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
|
|
718
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
719
|
+
};
|
|
720
|
+
const serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly }) => {
|
|
721
|
+
if (value instanceof Date) return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
722
|
+
if (style !== "deepObject" && !explode) {
|
|
723
|
+
let values = [];
|
|
724
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
725
|
+
values = [
|
|
726
|
+
...values,
|
|
727
|
+
key,
|
|
728
|
+
allowReserved ? v : encodeURIComponent(v)
|
|
729
|
+
];
|
|
730
|
+
});
|
|
731
|
+
const joinedValues = values.join(",");
|
|
732
|
+
switch (style) {
|
|
733
|
+
case "form": return `${name}=${joinedValues}`;
|
|
734
|
+
case "label": return `.${joinedValues}`;
|
|
735
|
+
case "matrix": return `;${name}=${joinedValues}`;
|
|
736
|
+
default: return joinedValues;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
const separator = separatorObjectExplode(style);
|
|
740
|
+
const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
|
|
741
|
+
allowReserved,
|
|
742
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
743
|
+
value: v
|
|
744
|
+
})).join(separator);
|
|
745
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
746
|
+
};
|
|
747
|
+
//#endregion
|
|
748
|
+
//#region src/generated/core/utils.gen.ts
|
|
749
|
+
const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
750
|
+
const defaultPathSerializer = ({ path, url: _url }) => {
|
|
751
|
+
let url = _url;
|
|
752
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
753
|
+
if (matches) for (const match of matches) {
|
|
754
|
+
let explode = false;
|
|
755
|
+
let name = match.substring(1, match.length - 1);
|
|
756
|
+
let style = "simple";
|
|
757
|
+
if (name.endsWith("*")) {
|
|
758
|
+
explode = true;
|
|
759
|
+
name = name.substring(0, name.length - 1);
|
|
760
|
+
}
|
|
761
|
+
if (name.startsWith(".")) {
|
|
762
|
+
name = name.substring(1);
|
|
763
|
+
style = "label";
|
|
764
|
+
} else if (name.startsWith(";")) {
|
|
765
|
+
name = name.substring(1);
|
|
766
|
+
style = "matrix";
|
|
767
|
+
}
|
|
768
|
+
const value = path[name];
|
|
769
|
+
if (value === void 0 || value === null) continue;
|
|
770
|
+
if (Array.isArray(value)) {
|
|
771
|
+
url = url.replace(match, serializeArrayParam({
|
|
772
|
+
explode,
|
|
773
|
+
name,
|
|
774
|
+
style,
|
|
775
|
+
value
|
|
776
|
+
}));
|
|
777
|
+
continue;
|
|
778
|
+
}
|
|
779
|
+
if (typeof value === "object") {
|
|
780
|
+
url = url.replace(match, serializeObjectParam({
|
|
781
|
+
explode,
|
|
782
|
+
name,
|
|
783
|
+
style,
|
|
784
|
+
value,
|
|
785
|
+
valueOnly: true
|
|
786
|
+
}));
|
|
787
|
+
continue;
|
|
788
|
+
}
|
|
789
|
+
if (style === "matrix") {
|
|
790
|
+
url = url.replace(match, `;${serializePrimitiveParam({
|
|
791
|
+
name,
|
|
792
|
+
value
|
|
793
|
+
})}`);
|
|
794
|
+
continue;
|
|
795
|
+
}
|
|
796
|
+
const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
|
|
797
|
+
url = url.replace(match, replaceValue);
|
|
798
|
+
}
|
|
799
|
+
return url;
|
|
800
|
+
};
|
|
801
|
+
const getUrl = ({ baseUrl, path, query, querySerializer, url: _url }) => {
|
|
802
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
803
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
804
|
+
if (path) url = defaultPathSerializer({
|
|
805
|
+
path,
|
|
806
|
+
url
|
|
807
|
+
});
|
|
808
|
+
let search = query ? querySerializer(query) : "";
|
|
809
|
+
if (search.startsWith("?")) search = search.substring(1);
|
|
810
|
+
if (search) url += `?${search}`;
|
|
811
|
+
return url;
|
|
812
|
+
};
|
|
813
|
+
function getValidRequestBody(options) {
|
|
814
|
+
const hasBody = options.body !== void 0;
|
|
815
|
+
if (hasBody && options.bodySerializer) {
|
|
816
|
+
if ("serializedBody" in options) return options.serializedBody !== void 0 && options.serializedBody !== "" ? options.serializedBody : null;
|
|
817
|
+
return options.body !== "" ? options.body : null;
|
|
818
|
+
}
|
|
819
|
+
if (hasBody) return options.body;
|
|
820
|
+
}
|
|
821
|
+
//#endregion
|
|
822
|
+
//#region src/generated/core/auth.gen.ts
|
|
823
|
+
const getAuthToken = async (auth, callback) => {
|
|
824
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
825
|
+
if (!token) return;
|
|
826
|
+
if (auth.scheme === "bearer") return `Bearer ${token}`;
|
|
827
|
+
if (auth.scheme === "basic") return `Basic ${btoa(token)}`;
|
|
828
|
+
return token;
|
|
829
|
+
};
|
|
830
|
+
//#endregion
|
|
831
|
+
//#region src/generated/client/utils.gen.ts
|
|
832
|
+
const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
|
|
833
|
+
const querySerializer = (queryParams) => {
|
|
834
|
+
const search = [];
|
|
835
|
+
if (queryParams && typeof queryParams === "object") for (const name in queryParams) {
|
|
836
|
+
const value = queryParams[name];
|
|
837
|
+
if (value === void 0 || value === null) continue;
|
|
838
|
+
const options = parameters[name] || args;
|
|
839
|
+
if (Array.isArray(value)) {
|
|
840
|
+
const serializedArray = serializeArrayParam({
|
|
841
|
+
allowReserved: options.allowReserved,
|
|
842
|
+
explode: true,
|
|
843
|
+
name,
|
|
844
|
+
style: "form",
|
|
845
|
+
value,
|
|
846
|
+
...options.array
|
|
847
|
+
});
|
|
848
|
+
if (serializedArray) search.push(serializedArray);
|
|
849
|
+
} else if (typeof value === "object") {
|
|
850
|
+
const serializedObject = serializeObjectParam({
|
|
851
|
+
allowReserved: options.allowReserved,
|
|
852
|
+
explode: true,
|
|
853
|
+
name,
|
|
854
|
+
style: "deepObject",
|
|
855
|
+
value,
|
|
856
|
+
...options.object
|
|
857
|
+
});
|
|
858
|
+
if (serializedObject) search.push(serializedObject);
|
|
859
|
+
} else {
|
|
860
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
861
|
+
allowReserved: options.allowReserved,
|
|
862
|
+
name,
|
|
863
|
+
value
|
|
864
|
+
});
|
|
865
|
+
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
return search.join("&");
|
|
869
|
+
};
|
|
870
|
+
return querySerializer;
|
|
871
|
+
};
|
|
872
|
+
/**
|
|
873
|
+
* Infers parseAs value from provided Content-Type header.
|
|
874
|
+
*/
|
|
875
|
+
const getParseAs = (contentType) => {
|
|
876
|
+
if (!contentType) return "stream";
|
|
877
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
878
|
+
if (!cleanContent) return;
|
|
879
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) return "json";
|
|
880
|
+
if (cleanContent === "multipart/form-data") return "formData";
|
|
881
|
+
if ([
|
|
882
|
+
"application/",
|
|
883
|
+
"audio/",
|
|
884
|
+
"image/",
|
|
885
|
+
"video/"
|
|
886
|
+
].some((type) => cleanContent.startsWith(type))) return "blob";
|
|
887
|
+
if (cleanContent.startsWith("text/")) return "text";
|
|
888
|
+
};
|
|
889
|
+
const checkForExistence = (options, name) => {
|
|
890
|
+
if (!name) return false;
|
|
891
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) return true;
|
|
892
|
+
return false;
|
|
893
|
+
};
|
|
894
|
+
const setAuthParams = async ({ security, ...options }) => {
|
|
895
|
+
for (const auth of security) {
|
|
896
|
+
if (checkForExistence(options, auth.name)) continue;
|
|
897
|
+
const token = await getAuthToken(auth, options.auth);
|
|
898
|
+
if (!token) continue;
|
|
899
|
+
const name = auth.name ?? "Authorization";
|
|
900
|
+
switch (auth.in) {
|
|
901
|
+
case "query":
|
|
902
|
+
if (!options.query) options.query = {};
|
|
903
|
+
options.query[name] = token;
|
|
904
|
+
break;
|
|
905
|
+
case "cookie":
|
|
906
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
907
|
+
break;
|
|
908
|
+
default:
|
|
909
|
+
options.headers.set(name, token);
|
|
910
|
+
break;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
const buildUrl = (options) => getUrl({
|
|
915
|
+
baseUrl: options.baseUrl,
|
|
916
|
+
path: options.path,
|
|
917
|
+
query: options.query,
|
|
918
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
919
|
+
url: options.url
|
|
920
|
+
});
|
|
921
|
+
const mergeConfigs = (a, b) => {
|
|
922
|
+
const config = {
|
|
923
|
+
...a,
|
|
924
|
+
...b
|
|
925
|
+
};
|
|
926
|
+
if (config.baseUrl?.endsWith("/")) config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
927
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
928
|
+
return config;
|
|
929
|
+
};
|
|
930
|
+
const headersEntries = (headers) => {
|
|
931
|
+
const entries = [];
|
|
932
|
+
headers.forEach((value, key) => {
|
|
933
|
+
entries.push([key, value]);
|
|
934
|
+
});
|
|
935
|
+
return entries;
|
|
936
|
+
};
|
|
937
|
+
const mergeHeaders = (...headers) => {
|
|
938
|
+
const mergedHeaders = new Headers();
|
|
939
|
+
for (const header of headers) {
|
|
940
|
+
if (!header) continue;
|
|
941
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
942
|
+
for (const [key, value] of iterator) if (value === null) mergedHeaders.delete(key);
|
|
943
|
+
else if (Array.isArray(value)) for (const v of value) mergedHeaders.append(key, v);
|
|
944
|
+
else if (value !== void 0) mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
|
|
945
|
+
}
|
|
946
|
+
return mergedHeaders;
|
|
947
|
+
};
|
|
948
|
+
var Interceptors = class {
|
|
949
|
+
fns = [];
|
|
950
|
+
clear() {
|
|
951
|
+
this.fns = [];
|
|
952
|
+
}
|
|
953
|
+
eject(id) {
|
|
954
|
+
const index = this.getInterceptorIndex(id);
|
|
955
|
+
if (this.fns[index]) this.fns[index] = null;
|
|
956
|
+
}
|
|
957
|
+
exists(id) {
|
|
958
|
+
const index = this.getInterceptorIndex(id);
|
|
959
|
+
return Boolean(this.fns[index]);
|
|
960
|
+
}
|
|
961
|
+
getInterceptorIndex(id) {
|
|
962
|
+
if (typeof id === "number") return this.fns[id] ? id : -1;
|
|
963
|
+
return this.fns.indexOf(id);
|
|
964
|
+
}
|
|
965
|
+
update(id, fn) {
|
|
966
|
+
const index = this.getInterceptorIndex(id);
|
|
967
|
+
if (this.fns[index]) {
|
|
968
|
+
this.fns[index] = fn;
|
|
969
|
+
return id;
|
|
970
|
+
}
|
|
971
|
+
return false;
|
|
972
|
+
}
|
|
973
|
+
use(fn) {
|
|
974
|
+
this.fns.push(fn);
|
|
975
|
+
return this.fns.length - 1;
|
|
976
|
+
}
|
|
977
|
+
};
|
|
978
|
+
const createInterceptors = () => ({
|
|
979
|
+
error: new Interceptors(),
|
|
980
|
+
request: new Interceptors(),
|
|
981
|
+
response: new Interceptors()
|
|
982
|
+
});
|
|
983
|
+
const defaultQuerySerializer = createQuerySerializer({
|
|
984
|
+
allowReserved: false,
|
|
985
|
+
array: {
|
|
986
|
+
explode: true,
|
|
987
|
+
style: "form"
|
|
988
|
+
},
|
|
989
|
+
object: {
|
|
990
|
+
explode: true,
|
|
991
|
+
style: "deepObject"
|
|
992
|
+
}
|
|
993
|
+
});
|
|
994
|
+
const defaultHeaders = { "Content-Type": "application/json" };
|
|
995
|
+
const createConfig = (override = {}) => ({
|
|
996
|
+
...jsonBodySerializer,
|
|
997
|
+
headers: defaultHeaders,
|
|
998
|
+
parseAs: "auto",
|
|
999
|
+
querySerializer: defaultQuerySerializer,
|
|
1000
|
+
...override
|
|
1001
|
+
});
|
|
1002
|
+
//#endregion
|
|
1003
|
+
//#region src/generated/client/client.gen.ts
|
|
1004
|
+
const createClient = (config = {}) => {
|
|
1005
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
1006
|
+
const getConfig = () => ({ ..._config });
|
|
1007
|
+
const setConfig = (config) => {
|
|
1008
|
+
_config = mergeConfigs(_config, config);
|
|
1009
|
+
return getConfig();
|
|
1010
|
+
};
|
|
1011
|
+
const interceptors = createInterceptors();
|
|
1012
|
+
const beforeRequest = async (options) => {
|
|
1013
|
+
const opts = {
|
|
1014
|
+
..._config,
|
|
1015
|
+
...options,
|
|
1016
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
1017
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
1018
|
+
serializedBody: void 0
|
|
1019
|
+
};
|
|
1020
|
+
if (opts.security) await setAuthParams({
|
|
1021
|
+
...opts,
|
|
1022
|
+
security: opts.security
|
|
1023
|
+
});
|
|
1024
|
+
if (opts.requestValidator) await opts.requestValidator(opts);
|
|
1025
|
+
if (opts.body !== void 0 && opts.bodySerializer) opts.serializedBody = opts.bodySerializer(opts.body);
|
|
1026
|
+
if (opts.body === void 0 || opts.serializedBody === "") opts.headers.delete("Content-Type");
|
|
1027
|
+
return {
|
|
1028
|
+
opts,
|
|
1029
|
+
url: buildUrl(opts)
|
|
1030
|
+
};
|
|
1031
|
+
};
|
|
1032
|
+
const request = async (options) => {
|
|
1033
|
+
const { opts, url } = await beforeRequest(options);
|
|
1034
|
+
const requestInit = {
|
|
1035
|
+
redirect: "follow",
|
|
1036
|
+
...opts,
|
|
1037
|
+
body: getValidRequestBody(opts)
|
|
1038
|
+
};
|
|
1039
|
+
let request = new Request(url, requestInit);
|
|
1040
|
+
for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
|
|
1041
|
+
const _fetch = opts.fetch;
|
|
1042
|
+
let response;
|
|
1043
|
+
try {
|
|
1044
|
+
response = await _fetch(request);
|
|
1045
|
+
} catch (error) {
|
|
1046
|
+
let finalError = error;
|
|
1047
|
+
for (const fn of interceptors.error.fns) if (fn) finalError = await fn(error, void 0, request, opts);
|
|
1048
|
+
finalError = finalError || {};
|
|
1049
|
+
if (opts.throwOnError) throw finalError;
|
|
1050
|
+
return opts.responseStyle === "data" ? void 0 : {
|
|
1051
|
+
error: finalError,
|
|
1052
|
+
request,
|
|
1053
|
+
response: void 0
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
for (const fn of interceptors.response.fns) if (fn) response = await fn(response, request, opts);
|
|
1057
|
+
const result = {
|
|
1058
|
+
request,
|
|
1059
|
+
response
|
|
1060
|
+
};
|
|
1061
|
+
if (response.ok) {
|
|
1062
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
1063
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
1064
|
+
let emptyData;
|
|
1065
|
+
switch (parseAs) {
|
|
1066
|
+
case "arrayBuffer":
|
|
1067
|
+
case "blob":
|
|
1068
|
+
case "text":
|
|
1069
|
+
emptyData = await response[parseAs]();
|
|
1070
|
+
break;
|
|
1071
|
+
case "formData":
|
|
1072
|
+
emptyData = new FormData();
|
|
1073
|
+
break;
|
|
1074
|
+
case "stream":
|
|
1075
|
+
emptyData = response.body;
|
|
1076
|
+
break;
|
|
1077
|
+
default:
|
|
1078
|
+
emptyData = {};
|
|
1079
|
+
break;
|
|
1080
|
+
}
|
|
1081
|
+
return opts.responseStyle === "data" ? emptyData : {
|
|
1082
|
+
data: emptyData,
|
|
1083
|
+
...result
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
let data;
|
|
1087
|
+
switch (parseAs) {
|
|
1088
|
+
case "arrayBuffer":
|
|
1089
|
+
case "blob":
|
|
1090
|
+
case "formData":
|
|
1091
|
+
case "json":
|
|
1092
|
+
case "text":
|
|
1093
|
+
data = await response[parseAs]();
|
|
1094
|
+
break;
|
|
1095
|
+
case "stream": return opts.responseStyle === "data" ? response.body : {
|
|
1096
|
+
data: response.body,
|
|
1097
|
+
...result
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
if (parseAs === "json") {
|
|
1101
|
+
if (opts.responseValidator) await opts.responseValidator(data);
|
|
1102
|
+
if (opts.responseTransformer) data = await opts.responseTransformer(data);
|
|
1103
|
+
}
|
|
1104
|
+
return opts.responseStyle === "data" ? data : {
|
|
1105
|
+
data,
|
|
1106
|
+
...result
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
const textError = await response.text();
|
|
1110
|
+
let jsonError;
|
|
1111
|
+
try {
|
|
1112
|
+
jsonError = JSON.parse(textError);
|
|
1113
|
+
} catch {}
|
|
1114
|
+
const error = jsonError ?? textError;
|
|
1115
|
+
let finalError = error;
|
|
1116
|
+
for (const fn of interceptors.error.fns) if (fn) finalError = await fn(error, response, request, opts);
|
|
1117
|
+
finalError = finalError || {};
|
|
1118
|
+
if (opts.throwOnError) throw finalError;
|
|
1119
|
+
return opts.responseStyle === "data" ? void 0 : {
|
|
1120
|
+
error: finalError,
|
|
1121
|
+
...result
|
|
1122
|
+
};
|
|
1123
|
+
};
|
|
1124
|
+
const makeMethodFn = (method) => (options) => request({
|
|
1125
|
+
...options,
|
|
1126
|
+
method
|
|
1127
|
+
});
|
|
1128
|
+
const makeSseFn = (method) => async (options) => {
|
|
1129
|
+
const { opts, url } = await beforeRequest(options);
|
|
1130
|
+
return createSseClient({
|
|
1131
|
+
...opts,
|
|
1132
|
+
body: opts.body,
|
|
1133
|
+
headers: opts.headers,
|
|
1134
|
+
method,
|
|
1135
|
+
onRequest: async (url, init) => {
|
|
1136
|
+
let request = new Request(url, init);
|
|
1137
|
+
for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
|
|
1138
|
+
return request;
|
|
1139
|
+
},
|
|
1140
|
+
url
|
|
1141
|
+
});
|
|
1142
|
+
};
|
|
1143
|
+
return {
|
|
1144
|
+
buildUrl,
|
|
1145
|
+
connect: makeMethodFn("CONNECT"),
|
|
1146
|
+
delete: makeMethodFn("DELETE"),
|
|
1147
|
+
get: makeMethodFn("GET"),
|
|
1148
|
+
getConfig,
|
|
1149
|
+
head: makeMethodFn("HEAD"),
|
|
1150
|
+
interceptors,
|
|
1151
|
+
options: makeMethodFn("OPTIONS"),
|
|
1152
|
+
patch: makeMethodFn("PATCH"),
|
|
1153
|
+
post: makeMethodFn("POST"),
|
|
1154
|
+
put: makeMethodFn("PUT"),
|
|
1155
|
+
request,
|
|
1156
|
+
setConfig,
|
|
1157
|
+
sse: {
|
|
1158
|
+
connect: makeSseFn("CONNECT"),
|
|
1159
|
+
delete: makeSseFn("DELETE"),
|
|
1160
|
+
get: makeSseFn("GET"),
|
|
1161
|
+
head: makeSseFn("HEAD"),
|
|
1162
|
+
options: makeSseFn("OPTIONS"),
|
|
1163
|
+
patch: makeSseFn("PATCH"),
|
|
1164
|
+
post: makeSseFn("POST"),
|
|
1165
|
+
put: makeSseFn("PUT"),
|
|
1166
|
+
trace: makeSseFn("TRACE")
|
|
1167
|
+
},
|
|
1168
|
+
trace: makeMethodFn("TRACE")
|
|
1169
|
+
};
|
|
1170
|
+
};
|
|
1171
|
+
//#endregion
|
|
1172
|
+
//#region src/wrappers/client.ts
|
|
1173
|
+
const API_VERSION = "2026-03-06.v1";
|
|
1174
|
+
function createApiClient(config) {
|
|
1175
|
+
const headers = new Headers({ "gt-api-version": config.apiVersion ?? "2026-03-06.v1" });
|
|
1176
|
+
if (config.apiKey) headers.set("Authorization", `Bearer ${config.apiKey}`);
|
|
1177
|
+
if (config.projectId) headers.set("gt-project-id", config.projectId);
|
|
1178
|
+
return createClient({
|
|
1179
|
+
baseUrl: config.baseUrl,
|
|
1180
|
+
fetch: createRetryingFetch({
|
|
1181
|
+
fetch: createTimeoutFetch({
|
|
1182
|
+
fetch: config.fetch,
|
|
1183
|
+
timeoutMs: config.timeoutMs
|
|
1184
|
+
}),
|
|
1185
|
+
retryPolicy: config.retryPolicy
|
|
1186
|
+
}),
|
|
1187
|
+
headers
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
//#endregion
|
|
1191
|
+
exports.API_VERSION = API_VERSION;
|
|
1192
|
+
exports.DEFAULT_BATCH_SIZE = DEFAULT_BATCH_SIZE;
|
|
1193
|
+
exports.awaitJobs = awaitJobs;
|
|
1194
|
+
exports.createApiClient = createApiClient;
|
|
1195
|
+
exports.createBranch = createBranch;
|
|
1196
|
+
exports.createCliWizardSession = createCliWizardSession;
|
|
1197
|
+
exports.createProject = createProject;
|
|
1198
|
+
exports.createTag = createTag;
|
|
1199
|
+
exports.decodeBase64 = decodeBase64;
|
|
1200
|
+
exports.decodeFileContent = decodeFileContent;
|
|
1201
|
+
exports.deleteCliWizardSession = deleteCliWizardSession;
|
|
1202
|
+
exports.downloadFile = downloadFile;
|
|
1203
|
+
exports.downloadFiles = downloadFiles;
|
|
1204
|
+
exports.encodeBase64 = encodeBase64;
|
|
1205
|
+
exports.encodeFileContent = encodeFileContent;
|
|
1206
|
+
exports.enqueueFileTranslations = enqueueFileTranslations;
|
|
1207
|
+
exports.generateProjectContext = generateProjectContext;
|
|
1208
|
+
exports.getBranchInfo = getBranchInfo;
|
|
1209
|
+
exports.getCliWizardSession = getCliWizardSession;
|
|
1210
|
+
exports.getFileInfo = getFileInfo;
|
|
1211
|
+
exports.getOrphanedFiles = getOrphanedFiles;
|
|
1212
|
+
exports.getProjectContextGenerationStatus = getProjectContextGenerationStatus;
|
|
1213
|
+
exports.getProjectInfo = getProjectInfo;
|
|
1214
|
+
exports.getTranslationJobInfo = getTranslationJobInfo;
|
|
1215
|
+
exports.getTranslationStatus = getTranslationStatus;
|
|
1216
|
+
exports.processBatches = processBatches;
|
|
1217
|
+
exports.processFileMoves = processFileMoves;
|
|
1218
|
+
exports.publishFiles = publishFiles;
|
|
1219
|
+
exports.shouldGenerateProjectContext = shouldGenerateProjectContext;
|
|
1220
|
+
exports.submitUserEditDiffs = submitUserEditDiffs;
|
|
1221
|
+
exports.translate = translate;
|
|
1222
|
+
exports.updateProjectInfo = updateProjectInfo;
|
|
1223
|
+
exports.uploadAssets = uploadAssets;
|
|
1224
|
+
exports.uploadSourceFiles = uploadSourceFiles;
|
|
1225
|
+
exports.uploadTranslations = uploadTranslations;
|
|
1226
|
+
|
|
1227
|
+
//# sourceMappingURL=index.cjs.map
|