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