generaltranslation 9.4.2 → 9.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +2 -1
- package/dist/{ApiError-BcjcnTAr.cjs → ApiError-BCjEo_CM.cjs} +1 -1
- package/dist/{ApiError-BcjcnTAr.cjs.map → ApiError-BCjEo_CM.cjs.map} +1 -1
- package/dist/{ApiError-CUKcz3YS.mjs → ApiError-DxWKM0Xt.mjs} +1 -1
- package/dist/{ApiError-CUKcz3YS.mjs.map → ApiError-DxWKM0Xt.mjs.map} +1 -1
- package/dist/adapter/createGtApi.d.ts +196 -27
- package/dist/adapter/createGtApi.js +561 -117
- package/dist/adapter/modelProvider.d.ts +4 -0
- package/dist/adapter/modelProvider.js +6 -0
- package/dist/derive-Cv5_y8Tf.mjs +656 -0
- package/dist/derive-Cv5_y8Tf.mjs.map +1 -0
- package/dist/{derive-DBCCXTmL.d.cts → derive-J2NQLqZm.d.cts} +1 -1
- package/dist/derive-t_E3ftJN.cjs +733 -0
- package/dist/derive-t_E3ftJN.cjs.map +1 -0
- package/dist/diagnostics-CqAHg_Vc.d.cts +34 -0
- package/dist/diagnostics-DKA2SkZB.mjs +45 -0
- package/dist/diagnostics-DKA2SkZB.mjs.map +1 -0
- package/dist/{unwrapApiResult-BzGfPw75.mjs → diagnostics-DKtiPUvo.cjs} +12 -31
- package/dist/diagnostics-DKtiPUvo.cjs.map +1 -0
- package/dist/diagnostics-DYtVjOm5.d.mts +34 -0
- package/dist/diagnostics.cjs +4 -0
- package/dist/diagnostics.d.cts +2 -0
- package/dist/diagnostics.d.mts +2 -0
- package/dist/diagnostics.d.ts +1 -0
- package/dist/diagnostics.js +1 -0
- package/dist/diagnostics.mjs +2 -0
- package/dist/errors.cjs +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/file-B37WkCqM.cjs.map +1 -1
- package/dist/file-Dga6cyM8.mjs.map +1 -1
- package/dist/{id-X2zyx5Jk.mjs → id-B2wA7-S-.mjs} +19 -3
- package/dist/id-B2wA7-S-.mjs.map +1 -0
- package/dist/{id-pdr3R1xs.cjs → id-DJ_59q21.cjs} +25 -3
- package/dist/id-DJ_59q21.cjs.map +1 -0
- package/dist/id.cjs +1 -1
- package/dist/id.d.cts +1 -1
- package/dist/id.d.mts +1 -1
- package/dist/id.mjs +1 -1
- package/dist/index.cjs +94 -753
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -33
- package/dist/index.d.mts +13 -32
- package/dist/index.d.ts +20 -16
- package/dist/index.js +110 -98
- package/dist/index.mjs +88 -746
- package/dist/index.mjs.map +1 -1
- package/dist/internal.cjs +16 -186
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +200 -62
- package/dist/internal.d.mts +199 -61
- package/dist/internal.d.ts +3 -1
- package/dist/internal.js +2 -1
- package/dist/internal.mjs +6 -178
- package/dist/internal.mjs.map +1 -1
- package/dist/logging/errors.d.ts +0 -1
- package/dist/logging/errors.js +0 -6
- package/dist/logging/logger.js +6 -4
- package/dist/openapi.json +2344 -845
- package/dist/runtime.cjs +580 -2
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +12 -6
- package/dist/runtime.d.mts +12 -6
- package/dist/runtime.d.ts +10 -4
- package/dist/runtime.js +10 -65
- package/dist/runtime.mjs +579 -1
- package/dist/runtime.mjs.map +1 -0
- package/dist/runtimeTranslate-CVw143pQ.mjs +506 -0
- package/dist/runtimeTranslate-CVw143pQ.mjs.map +1 -0
- package/dist/runtimeTranslate-DJioRjb6.cjs +601 -0
- package/dist/runtimeTranslate-DJioRjb6.cjs.map +1 -0
- package/dist/translate/awaitJobs.d.ts +2 -2
- package/dist/translate/awaitJobs.js +1 -156
- package/dist/translate/checkJobStatus.d.ts +2 -1
- package/dist/translate/checkJobStatus.js +1 -55
- package/dist/translate/createBranch.d.ts +2 -6
- package/dist/translate/createBranch.js +1 -53
- package/dist/translate/enqueueFiles.js +1 -95
- package/dist/translate/getProjectInfo.d.ts +2 -6
- package/dist/translate/getProjectInfo.js +1 -54
- package/dist/translate/processFileMoves.d.ts +3 -13
- package/dist/translate/processFileMoves.js +1 -90
- package/dist/translate/publishFiles.d.ts +3 -15
- package/dist/translate/publishFiles.js +1 -56
- package/dist/translate/queryBranchData.js +1 -53
- package/dist/translate/queryFileData.d.ts +3 -41
- package/dist/translate/queryFileData.js +1 -71
- package/dist/translate/runtimeTranslate.d.ts +6 -0
- package/dist/translate/runtimeTranslate.js +297 -0
- package/dist/translate/setupProject.d.ts +2 -6
- package/dist/translate/setupProject.js +1 -63
- package/dist/translate/submitUserEditDiffs.js +1 -68
- package/dist/translate/utils/fetchWithTimeout.js +19 -12
- package/dist/{types-bCr8pV1Z.d.cts → types-Si4UstLL.d.mts} +41 -165
- package/dist/types-dir/__tests__/runtimeTranslate.type-test.js +18 -0
- package/dist/types-dir/api/branch.d.ts +3 -9
- package/dist/types-dir/api/checkFileTranslations.d.ts +2 -22
- package/dist/types-dir/api/downloadFileBatch.d.ts +2 -7
- package/dist/types-dir/api/entry.d.ts +3 -8
- package/dist/types-dir/api/file.d.ts +2 -1
- package/dist/types-dir/api/json.d.ts +1 -4
- package/dist/types-dir/api/project.d.ts +2 -7
- package/dist/types-dir/api/uploadAssets.d.ts +3 -10
- package/dist/types-dir/api/uploadAssets.js +0 -4
- package/dist/types-dir/config.d.ts +1 -0
- package/dist/{types-Dp1drjxq.d.mts → types-yByDbKnV.d.cts} +41 -165
- package/dist/types.d.cts +2 -2
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +26 -7
- package/package.json +15 -2
- package/dist/derive-2CDqwrvS.cjs +0 -303
- package/dist/derive-2CDqwrvS.cjs.map +0 -1
- package/dist/derive-CTzR56T_.mjs +0 -233
- package/dist/derive-CTzR56T_.mjs.map +0 -1
- package/dist/id-X2zyx5Jk.mjs.map +0 -1
- package/dist/id-pdr3R1xs.cjs.map +0 -1
- package/dist/isVariable-8-Wy5FnX.mjs +0 -20
- package/dist/isVariable-8-Wy5FnX.mjs.map +0 -1
- package/dist/isVariable-I3nllgeI.cjs +0 -25
- package/dist/isVariable-I3nllgeI.cjs.map +0 -1
- package/dist/projects/getProjectData.js +0 -87
- package/dist/runtime-Bcp4F2ME.mjs +0 -974
- package/dist/runtime-Bcp4F2ME.mjs.map +0 -1
- package/dist/runtime-C25lwh9m.cjs +0 -1027
- package/dist/runtime-C25lwh9m.cjs.map +0 -1
- package/dist/translate/api.d.ts +0 -4
- package/dist/translate/api.js +0 -4
- package/dist/translate/createTag.d.ts +0 -19
- package/dist/translate/createTag.js +0 -67
- package/dist/translate/downloadFileBatch.d.ts +0 -1
- package/dist/translate/downloadFileBatch.js +0 -80
- package/dist/translate/getOrphanedFiles.d.ts +0 -8
- package/dist/translate/getOrphanedFiles.js +0 -97
- package/dist/translate/querySourceFile.d.ts +0 -1
- package/dist/translate/querySourceFile.js +0 -67
- package/dist/translate/translateMany.d.ts +0 -1
- package/dist/translate/translateMany.js +0 -124
- package/dist/translate/uploadFonts.d.ts +0 -1
- package/dist/translate/uploadFonts.js +0 -74
- package/dist/translate/uploadSourceFiles.d.ts +0 -1
- package/dist/translate/uploadSourceFiles.js +0 -90
- package/dist/translate/uploadTranslations.d.ts +0 -1
- package/dist/translate/uploadTranslations.js +0 -106
- package/dist/translate/utils/apiRequest.d.ts +0 -1
- package/dist/translate/utils/apiRequest.js +0 -167
- package/dist/translate/utils/generateRequestHeaders.d.ts +0 -2
- package/dist/translate/utils/generateRequestHeaders.js +0 -21
- package/dist/translate/utils/handleFetchError.d.ts +0 -1
- package/dist/translate/utils/handleFetchError.js +0 -12
- package/dist/unwrapApiResult-BzGfPw75.mjs.map +0 -1
- package/dist/unwrapApiResult-Dv6Mfw_K.cjs +0 -134
- package/dist/unwrapApiResult-Dv6Mfw_K.cjs.map +0 -1
- /package/dist/{projects/getProjectData.d.ts → types-dir/__tests__/runtimeTranslate.type-test.d.ts} +0 -0
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
import { createApiClient, translate, } from '@generaltranslation/api';
|
|
49
|
-
import { defaultRuntimeApiUrl } from '../settings/settingsUrls';
|
|
50
|
-
import { hashSource } from '../id';
|
|
51
|
-
import { fetchWithTimeout } from './utils/fetchWithTimeout';
|
|
52
|
-
import { hasDecodedError, unwrapApiResult } from './utils/unwrapApiResult';
|
|
53
|
-
import { validateResponse } from './utils/validateResponse';
|
|
54
|
-
export function _translateMany(requests, globalMetadata, config, timeout) {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
-
var isArray, hashOrder, requestsObject, entries, _i, entries_1, _a, key, request, normalized, source, metadata, hash, client, body, result, runtimeResponse, response;
|
|
57
|
-
var _b, _c;
|
|
58
|
-
return __generator(this, function (_d) {
|
|
59
|
-
switch (_d.label) {
|
|
60
|
-
case 0:
|
|
61
|
-
isArray = Array.isArray(requests);
|
|
62
|
-
hashOrder = isArray ? [] : undefined;
|
|
63
|
-
requestsObject = {};
|
|
64
|
-
entries = isArray
|
|
65
|
-
? requests.map(function (r) { return [undefined, r]; })
|
|
66
|
-
: Object.entries(requests);
|
|
67
|
-
for (_i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
|
|
68
|
-
_a = entries_1[_i], key = _a[0], request = _a[1];
|
|
69
|
-
normalized = typeof request === 'string' ? { source: request } : request;
|
|
70
|
-
source = normalized.source, metadata = normalized.metadata;
|
|
71
|
-
hash = (_b = key !== null && key !== void 0 ? key : metadata === null || metadata === void 0 ? void 0 : metadata.hash) !== null && _b !== void 0 ? _b : hashSource(__assign(__assign(__assign(__assign({ source: source }, ((metadata === null || metadata === void 0 ? void 0 : metadata.context) && { context: metadata.context })), ((metadata === null || metadata === void 0 ? void 0 : metadata.maxChars) != null && { maxChars: metadata.maxChars })), ((metadata === null || metadata === void 0 ? void 0 : metadata.fileFormat) && { fileFormat: metadata.fileFormat })), { dataFormat: (_c = metadata === null || metadata === void 0 ? void 0 : metadata.dataFormat) !== null && _c !== void 0 ? _c : 'STRING' }));
|
|
72
|
-
hashOrder === null || hashOrder === void 0 ? void 0 : hashOrder.push(hash);
|
|
73
|
-
requestsObject[hash] = {
|
|
74
|
-
source: source,
|
|
75
|
-
metadata: metadata,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
client = createApiClient({
|
|
79
|
-
apiKey: config.apiKey,
|
|
80
|
-
baseUrl: config.baseUrl || defaultRuntimeApiUrl,
|
|
81
|
-
fetch: function (input, init) { return fetchWithTimeout(input, init !== null && init !== void 0 ? init : {}, timeout); },
|
|
82
|
-
projectId: config.projectId,
|
|
83
|
-
retryPolicy: 'none',
|
|
84
|
-
timeoutMs: false,
|
|
85
|
-
});
|
|
86
|
-
body = {
|
|
87
|
-
requests: requestsObject,
|
|
88
|
-
targetLocale: globalMetadata.targetLocale,
|
|
89
|
-
sourceLocale: globalMetadata.sourceLocale,
|
|
90
|
-
// Core intentionally accepts custom model-provider strings beyond the
|
|
91
|
-
// OpenAPI ANTHROPIC|OPENAI|XAI|GOOGLE enum; preserve the pre-migration
|
|
92
|
-
// wire behavior at this boundary.
|
|
93
|
-
metadata: globalMetadata,
|
|
94
|
-
};
|
|
95
|
-
return [4 /*yield*/, translate({ body: body, client: client })];
|
|
96
|
-
case 1:
|
|
97
|
-
result = _d.sent();
|
|
98
|
-
if (!(result.data === undefined &&
|
|
99
|
-
result.response &&
|
|
100
|
-
!hasDecodedError(result))) return [3 /*break*/, 3];
|
|
101
|
-
return [4 /*yield*/, validateResponse(result.response)];
|
|
102
|
-
case 2:
|
|
103
|
-
_d.sent();
|
|
104
|
-
throw result.error;
|
|
105
|
-
case 3:
|
|
106
|
-
runtimeResponse = unwrapApiResult(result);
|
|
107
|
-
response = runtimeResponse;
|
|
108
|
-
// If input was an array, map the record response back to an array in input order
|
|
109
|
-
if (hashOrder) {
|
|
110
|
-
return [2 /*return*/, hashOrder.map(function (hash) {
|
|
111
|
-
var _a;
|
|
112
|
-
return (_a = response[hash]) !== null && _a !== void 0 ? _a : {
|
|
113
|
-
success: false,
|
|
114
|
-
error: 'No translation returned',
|
|
115
|
-
code: 500,
|
|
116
|
-
};
|
|
117
|
-
})];
|
|
118
|
-
}
|
|
119
|
-
// If input was a record, return the record response directly
|
|
120
|
-
return [2 /*return*/, response];
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
import { apiRequest } from './utils/apiRequest';
|
|
38
|
-
import { processBatches } from './utils/batch';
|
|
39
|
-
// Fonts are large binary payloads (often hundreds of KB each once
|
|
40
|
-
// base64-encoded), so batches are kept smaller than the default of 100 used
|
|
41
|
-
// for text-file uploads to bound the request body size.
|
|
42
|
-
var FONT_UPLOAD_BATCH_SIZE = 50;
|
|
43
|
-
/**
|
|
44
|
-
* @internal
|
|
45
|
-
* Uploads project fonts to the General Translation API in batches. Idempotent
|
|
46
|
-
* on the server (re-running only stores genuinely new fonts). `content` is
|
|
47
|
-
* already base64-encoded by the caller (fonts are binary).
|
|
48
|
-
*/
|
|
49
|
-
export function _uploadFonts(fonts, options, config) {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
-
var _this = this;
|
|
52
|
-
return __generator(this, function (_a) {
|
|
53
|
-
return [2 /*return*/, processBatches(fonts, function (batch) { return __awaiter(_this, void 0, void 0, function () {
|
|
54
|
-
var body, result;
|
|
55
|
-
return __generator(this, function (_a) {
|
|
56
|
-
switch (_a.label) {
|
|
57
|
-
case 0:
|
|
58
|
-
body = {
|
|
59
|
-
assets: batch.map(function (font) { return ({
|
|
60
|
-
assetType: font.assetType,
|
|
61
|
-
content: font.content,
|
|
62
|
-
fileName: font.fileName,
|
|
63
|
-
}); }),
|
|
64
|
-
};
|
|
65
|
-
return [4 /*yield*/, apiRequest(config, '/v2/project/assets', { body: body, timeout: options.timeout })];
|
|
66
|
-
case 1:
|
|
67
|
-
result = _a.sent();
|
|
68
|
-
return [2 /*return*/, result.assets || []];
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}); }, { batchSize: FONT_UPLOAD_BATCH_SIZE })];
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
import { apiRequest } from './utils/apiRequest';
|
|
38
|
-
import { encode } from '../utils/base64';
|
|
39
|
-
import { processBatches } from './utils/batch';
|
|
40
|
-
import { isBinaryFileFormat } from '../types-dir/api/file';
|
|
41
|
-
/**
|
|
42
|
-
* @internal
|
|
43
|
-
* Uploads source files to the General Translation API in batches.
|
|
44
|
-
* @param files - The files to upload.
|
|
45
|
-
* @param options - The options for the API call.
|
|
46
|
-
* @param config - The configuration for the API call.
|
|
47
|
-
* @returns Promise resolving to a BatchList with all uploaded files
|
|
48
|
-
*/
|
|
49
|
-
export function _uploadSourceFiles(files, options, config) {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
-
var _this = this;
|
|
52
|
-
return __generator(this, function (_a) {
|
|
53
|
-
return [2 /*return*/, processBatches(files, function (batch) { return __awaiter(_this, void 0, void 0, function () {
|
|
54
|
-
var body, result;
|
|
55
|
-
return __generator(this, function (_a) {
|
|
56
|
-
switch (_a.label) {
|
|
57
|
-
case 0:
|
|
58
|
-
body = {
|
|
59
|
-
data: batch.map(function (_a) {
|
|
60
|
-
var source = _a.source;
|
|
61
|
-
return ({
|
|
62
|
-
source: {
|
|
63
|
-
content: isBinaryFileFormat(source.fileFormat)
|
|
64
|
-
? source.content
|
|
65
|
-
: encode(source.content),
|
|
66
|
-
fileName: source.fileName,
|
|
67
|
-
fileFormat: source.fileFormat,
|
|
68
|
-
locale: source.locale,
|
|
69
|
-
dataFormat: source.dataFormat,
|
|
70
|
-
formatMetadata: source.formatMetadata,
|
|
71
|
-
fileId: source.fileId,
|
|
72
|
-
versionId: source.versionId,
|
|
73
|
-
branchId: source.branchId,
|
|
74
|
-
incomingBranchId: source.incomingBranchId,
|
|
75
|
-
checkedOutBranchId: source.checkedOutBranchId,
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
}),
|
|
79
|
-
sourceLocale: options.sourceLocale,
|
|
80
|
-
};
|
|
81
|
-
return [4 /*yield*/, apiRequest(config, '/v2/project/files/upload-files', { body: body, timeout: options.timeout })];
|
|
82
|
-
case 1:
|
|
83
|
-
result = _a.sent();
|
|
84
|
-
return [2 /*return*/, result.uploadedFiles || []];
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}); }, { batchSize: 100 })];
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
import { apiRequest } from './utils/apiRequest';
|
|
38
|
-
import { processBatches } from './utils/batch';
|
|
39
|
-
import { encode } from '../utils/base64';
|
|
40
|
-
import { isBinaryFileFormat } from '../types-dir/api/file';
|
|
41
|
-
import { validateFileFormatTransforms } from './utils/validateFileFormatTransform';
|
|
42
|
-
/**
|
|
43
|
-
* @internal
|
|
44
|
-
* Uploads multiple translations to the General Translation API in batches.
|
|
45
|
-
* @param files - Translations to upload with their source
|
|
46
|
-
* @param options - The options for the API call.
|
|
47
|
-
* @param config - The configuration for the API call.
|
|
48
|
-
* @returns Promise resolving to a BatchList with all uploaded files
|
|
49
|
-
*/
|
|
50
|
-
export function _uploadTranslations(files, options, config) {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
-
var _this = this;
|
|
53
|
-
return __generator(this, function (_a) {
|
|
54
|
-
validateFileFormatTransforms(files.map(function (_a) {
|
|
55
|
-
var source = _a.source;
|
|
56
|
-
return source;
|
|
57
|
-
}));
|
|
58
|
-
return [2 /*return*/, processBatches(files, function (batch) { return __awaiter(_this, void 0, void 0, function () {
|
|
59
|
-
var body, result;
|
|
60
|
-
return __generator(this, function (_a) {
|
|
61
|
-
switch (_a.label) {
|
|
62
|
-
case 0:
|
|
63
|
-
body = {
|
|
64
|
-
data: batch.map(function (_a) {
|
|
65
|
-
var source = _a.source, translations = _a.translations;
|
|
66
|
-
return ({
|
|
67
|
-
source: {
|
|
68
|
-
content: isBinaryFileFormat(source.fileFormat)
|
|
69
|
-
? source.content
|
|
70
|
-
: encode(source.content),
|
|
71
|
-
fileName: source.fileName,
|
|
72
|
-
fileFormat: source.fileFormat,
|
|
73
|
-
transformFormat: source.transformFormat,
|
|
74
|
-
locale: source.locale,
|
|
75
|
-
dataFormat: source.dataFormat,
|
|
76
|
-
formatMetadata: source.formatMetadata,
|
|
77
|
-
fileId: source.fileId,
|
|
78
|
-
versionId: source.versionId,
|
|
79
|
-
branchId: source.branchId,
|
|
80
|
-
},
|
|
81
|
-
translations: translations.map(function (t) { return ({
|
|
82
|
-
content: isBinaryFileFormat(t.fileFormat)
|
|
83
|
-
? t.content
|
|
84
|
-
: encode(t.content),
|
|
85
|
-
fileName: t.fileName,
|
|
86
|
-
fileFormat: t.fileFormat,
|
|
87
|
-
locale: t.locale,
|
|
88
|
-
dataFormat: t.dataFormat,
|
|
89
|
-
fileId: t.fileId,
|
|
90
|
-
versionId: t.versionId,
|
|
91
|
-
branchId: t.branchId,
|
|
92
|
-
}); }),
|
|
93
|
-
});
|
|
94
|
-
}),
|
|
95
|
-
sourceLocale: options.sourceLocale,
|
|
96
|
-
};
|
|
97
|
-
return [4 /*yield*/, apiRequest(config, '/v2/project/files/upload-translations', { body: body, timeout: options.timeout })];
|
|
98
|
-
case 1:
|
|
99
|
-
result = _a.sent();
|
|
100
|
-
return [2 /*return*/, result.uploadedFiles || []];
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}); }, { batchSize: 100 })];
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
import { defaultBaseUrl } from '../../settings/settingsUrls';
|
|
38
|
-
import { defaultTimeout } from '../../settings/settings';
|
|
39
|
-
import { fetchWithTimeout } from './fetchWithTimeout';
|
|
40
|
-
import { validateResponse } from './validateResponse';
|
|
41
|
-
import { handleFetchError } from './handleFetchError';
|
|
42
|
-
import { generateRequestHeaders } from './generateRequestHeaders';
|
|
43
|
-
var MAX_RETRIES = 3;
|
|
44
|
-
var INITIAL_DELAY_MS = 500;
|
|
45
|
-
var RATE_LIMIT_RETRY_DELAY_MS = 60000;
|
|
46
|
-
var MS_PER_SECOND = 1000;
|
|
47
|
-
function sleep(ms) {
|
|
48
|
-
return new Promise(function (resolve) { return setTimeout(resolve, ms); });
|
|
49
|
-
}
|
|
50
|
-
function getRetryDelay(policy, attempt) {
|
|
51
|
-
switch (policy) {
|
|
52
|
-
case 'linear':
|
|
53
|
-
return INITIAL_DELAY_MS * (attempt + 1);
|
|
54
|
-
case 'exponential':
|
|
55
|
-
return INITIAL_DELAY_MS * Math.pow(2, attempt);
|
|
56
|
-
default:
|
|
57
|
-
return 0;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function parseDelayMs(value) {
|
|
61
|
-
if (!value) {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
var seconds = Number(value.split(',')[0].split(';')[0].trim());
|
|
65
|
-
if (!Number.isFinite(seconds) || seconds < 0) {
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
return seconds * MS_PER_SECOND;
|
|
69
|
-
}
|
|
70
|
-
function parseRetryAfter(value) {
|
|
71
|
-
var delayMs = parseDelayMs(value);
|
|
72
|
-
if (delayMs !== undefined) {
|
|
73
|
-
return delayMs;
|
|
74
|
-
}
|
|
75
|
-
if (!value) {
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
78
|
-
var retryDate = Date.parse(value);
|
|
79
|
-
if (Number.isNaN(retryDate)) {
|
|
80
|
-
return undefined;
|
|
81
|
-
}
|
|
82
|
-
return Math.max(retryDate - Date.now(), 0);
|
|
83
|
-
}
|
|
84
|
-
function getRateLimitRetryDelay(response) {
|
|
85
|
-
var _a, _b;
|
|
86
|
-
return ((_b = (_a = parseRetryAfter(response.headers.get('Retry-After'))) !== null && _a !== void 0 ? _a : parseDelayMs(response.headers.get('RateLimit-Reset'))) !== null && _b !== void 0 ? _b : RATE_LIMIT_RETRY_DELAY_MS);
|
|
87
|
-
}
|
|
88
|
-
function getResponseRetryDelay(response, policy, attempt) {
|
|
89
|
-
if (response.status === 429) {
|
|
90
|
-
return getRateLimitRetryDelay(response);
|
|
91
|
-
}
|
|
92
|
-
return getRetryDelay(policy, attempt);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* @internal
|
|
96
|
-
*
|
|
97
|
-
* Makes an API request with automatic retry for 429 and 5XX errors.
|
|
98
|
-
*
|
|
99
|
-
* Encapsulates URL construction, fetch with timeout, error handling,
|
|
100
|
-
* response validation, and JSON parsing.
|
|
101
|
-
*
|
|
102
|
-
* @param config - The configuration for the API call.
|
|
103
|
-
* @param endpoint - The API endpoint path (e.g. '/v2/project/jobs/info')
|
|
104
|
-
* @param options - Optional request options.
|
|
105
|
-
* @returns The parsed JSON response.
|
|
106
|
-
*/
|
|
107
|
-
export function apiRequest(config, endpoint, options) {
|
|
108
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
109
|
-
var timeout, retryPolicy, url, method, maxRetries, requestInit, attempt, response, error_1;
|
|
110
|
-
var _a, _b, _c;
|
|
111
|
-
return __generator(this, function (_d) {
|
|
112
|
-
switch (_d.label) {
|
|
113
|
-
case 0:
|
|
114
|
-
timeout = (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : defaultTimeout;
|
|
115
|
-
retryPolicy = (_b = options === null || options === void 0 ? void 0 : options.retryPolicy) !== null && _b !== void 0 ? _b : 'exponential';
|
|
116
|
-
url = "".concat(config.baseUrl || defaultBaseUrl).concat(endpoint);
|
|
117
|
-
method = (_c = options === null || options === void 0 ? void 0 : options.method) !== null && _c !== void 0 ? _c : 'POST';
|
|
118
|
-
maxRetries = retryPolicy === 'none' ? 0 : MAX_RETRIES;
|
|
119
|
-
requestInit = {
|
|
120
|
-
method: method,
|
|
121
|
-
headers: generateRequestHeaders(config),
|
|
122
|
-
};
|
|
123
|
-
if ((options === null || options === void 0 ? void 0 : options.body) !== undefined) {
|
|
124
|
-
requestInit.body = JSON.stringify(options.body);
|
|
125
|
-
}
|
|
126
|
-
attempt = 0;
|
|
127
|
-
_d.label = 1;
|
|
128
|
-
case 1:
|
|
129
|
-
if (!(attempt <= maxRetries)) return [3 /*break*/, 13];
|
|
130
|
-
response = void 0;
|
|
131
|
-
_d.label = 2;
|
|
132
|
-
case 2:
|
|
133
|
-
_d.trys.push([2, 4, , 7]);
|
|
134
|
-
return [4 /*yield*/, fetchWithTimeout(url, requestInit, timeout)];
|
|
135
|
-
case 3:
|
|
136
|
-
response = _d.sent();
|
|
137
|
-
return [3 /*break*/, 7];
|
|
138
|
-
case 4:
|
|
139
|
-
error_1 = _d.sent();
|
|
140
|
-
if (!(attempt < maxRetries)) return [3 /*break*/, 6];
|
|
141
|
-
return [4 /*yield*/, sleep(getRetryDelay(retryPolicy, attempt))];
|
|
142
|
-
case 5:
|
|
143
|
-
_d.sent();
|
|
144
|
-
return [3 /*break*/, 12];
|
|
145
|
-
case 6:
|
|
146
|
-
handleFetchError(error_1, timeout);
|
|
147
|
-
return [3 /*break*/, 7];
|
|
148
|
-
case 7:
|
|
149
|
-
if (!((response.status === 429 || response.status >= 500) &&
|
|
150
|
-
attempt < maxRetries)) return [3 /*break*/, 9];
|
|
151
|
-
return [4 /*yield*/, sleep(getResponseRetryDelay(response, retryPolicy, attempt))];
|
|
152
|
-
case 8:
|
|
153
|
-
_d.sent();
|
|
154
|
-
return [3 /*break*/, 12];
|
|
155
|
-
case 9: return [4 /*yield*/, validateResponse(response)];
|
|
156
|
-
case 10:
|
|
157
|
-
_d.sent();
|
|
158
|
-
return [4 /*yield*/, response.json()];
|
|
159
|
-
case 11: return [2 /*return*/, (_d.sent())];
|
|
160
|
-
case 12:
|
|
161
|
-
attempt++;
|
|
162
|
-
return [3 /*break*/, 1];
|
|
163
|
-
case 13: throw new Error('Max retries exceeded');
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
import { API_VERSION } from '../api';
|
|
13
|
-
export function generateRequestHeaders(config, excludeContentType) {
|
|
14
|
-
if (excludeContentType === void 0) { excludeContentType = false; }
|
|
15
|
-
var authHeaders = __assign(__assign({}, (!excludeContentType && { 'Content-Type': 'application/json' })), { 'gt-project-id': config.projectId });
|
|
16
|
-
if (config.apiKey) {
|
|
17
|
-
authHeaders['Authorization'] = "Bearer ".concat(config.apiKey);
|
|
18
|
-
}
|
|
19
|
-
authHeaders['gt-api-version'] = API_VERSION;
|
|
20
|
-
return authHeaders;
|
|
21
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function handleFetchError(error: unknown, timeout: number): never;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { fetchLogger } from '../../logging/logger';
|
|
2
|
-
import { translationRequestFailedError, translationTimeoutError, } from '../../logging/errors';
|
|
3
|
-
export function handleFetchError(error, timeout) {
|
|
4
|
-
if (error instanceof Error && error.name === 'AbortError') {
|
|
5
|
-
var errorMessage_1 = translationTimeoutError(timeout);
|
|
6
|
-
fetchLogger.error(errorMessage_1);
|
|
7
|
-
throw new Error(errorMessage_1);
|
|
8
|
-
}
|
|
9
|
-
var errorMessage = translationRequestFailedError(error instanceof Error ? error.message : String(error));
|
|
10
|
-
fetchLogger.error(errorMessage);
|
|
11
|
-
throw error;
|
|
12
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unwrapApiResult-BzGfPw75.mjs","names":[],"sources":["../src/settings/settings.ts","../src/logging/diagnostics.ts","../src/settings/settingsUrls.ts","../src/translate/utils/unwrapApiResult.ts"],"sourcesContent":["export const libraryDefaultLocale = 'en' as const;\nexport const defaultTimeout = 60000;\n","export type DiagnosticSeverity = 'Error' | 'Warning';\n\n/**\n * Text slots follow the five-part error message model:\n * what happened, reassurance, why it happened, how to fix it, and a way out.\n * Clauses that are combined into another sentence should use their intended\n * in-sentence casing.\n */\nexport type DiagnosticMessageInput = {\n source?: string;\n severity?: DiagnosticSeverity;\n whatHappened: string;\n reassurance?: string;\n why?: string;\n fix?: string;\n wayOut?: string;\n details?: string | string[];\n docsUrl?: string;\n};\n\nfunction ensureSentence(text: string): string {\n const trimmed = text.trim();\n if (!trimmed) return '';\n return /[.!?)]$/.test(trimmed) ? trimmed : `${trimmed}.`;\n}\n\nfunction stripSentence(text: string): string {\n const trimmed = text.trim();\n let end = trimmed.length;\n while (end > 0) {\n const char = trimmed[end - 1];\n if (char !== '.' && char !== '!' && char !== '?') break;\n end -= 1;\n }\n return trimmed.slice(0, end);\n}\n\nfunction formatDetails(details: string | string[] | undefined): string {\n if (!details) return '';\n const detailText = Array.isArray(details) ? details.join(', ') : details;\n if (!detailText.trim()) return '';\n return ensureSentence(`Details: ${detailText}`);\n}\n\nexport function formatDiagnosticErrorDetails(\n error: unknown\n): string | undefined {\n if (error == null) return undefined;\n return String(error);\n}\n\nexport function createDiagnosticMessage({\n source,\n severity,\n whatHappened,\n reassurance,\n why,\n fix,\n wayOut,\n details,\n docsUrl,\n}: DiagnosticMessageInput): string {\n const prefix = source\n ? severity\n ? `${source} ${severity}:`\n : `${source}:`\n : severity\n ? `${severity}:`\n : '';\n const whatAndWhy = why\n ? `${stripSentence(whatHappened)} because ${stripSentence(why)}`\n : whatHappened;\n const shouldCombineWayOut =\n !!fix && !!wayOut && /^[a-z]/.test(stripSentence(wayOut));\n const fixAndWayOut = shouldCombineWayOut\n ? `${stripSentence(fix)}, or ${stripSentence(wayOut)}`\n : fix;\n const messageParts = [\n whatAndWhy,\n reassurance,\n fixAndWayOut,\n shouldCombineWayOut ? undefined : wayOut,\n formatDetails(details),\n ]\n .filter((part): part is string => !!part)\n .map(ensureSentence);\n\n if (docsUrl) {\n messageParts.push(`Learn more: ${docsUrl}`);\n }\n\n const message = messageParts.join(' ');\n return prefix ? `${prefix} ${message}` : message;\n}\n","export const defaultCacheUrl = 'https://cdn.gtx.dev' as const;\nexport const defaultBaseUrl = 'https://api.gtx.dev' as const;\nexport const defaultRuntimeApiUrl = 'https://api.gtx.dev' as const;\n","import { ApiError } from '../../errors/ApiError';\n\nexport function isErrorResult(error: unknown): error is { error: string } {\n return (\n typeof error === 'object' &&\n error !== null &&\n 'error' in error &&\n typeof error.error === 'string'\n );\n}\n\nexport function hasDecodedError(result: { error: unknown }): boolean {\n return isErrorResult(result.error) || typeof result.error === 'string';\n}\n\n/**\n * Unwraps a `@generaltranslation/api` SDK result, returning its data or\n * throwing an `ApiError` built from the failed response.\n */\nexport function unwrapApiResult<T>(result: {\n data: T | undefined;\n error: unknown;\n response?: Response;\n}): Exclude<T, undefined> {\n if (result.data !== undefined) {\n // TypeScript cannot narrow a generic T after excluding undefined; the\n // runtime guard above establishes the exact Exclude<T, undefined> result.\n return result.data as Exclude<T, undefined>;\n }\n if (result.response) {\n const details = isErrorResult(result.error)\n ? result.error.error\n : typeof result.error === 'string'\n ? result.error\n : result.response.statusText;\n throw new ApiError(details, result.response.status, details);\n }\n throw result.error;\n}\n"],"mappings":";;AAAA,MAAa,uBAAuB;AACpC,MAAa,iBAAiB;;;ACmB9B,SAAS,eAAe,MAAsB;CAC5C,MAAM,UAAU,KAAK,MAAM;AAC3B,KAAI,CAAC,QAAS,QAAO;AACrB,QAAO,UAAU,KAAK,QAAQ,GAAG,UAAU,GAAG,QAAQ;;AAGxD,SAAS,cAAc,MAAsB;CAC3C,MAAM,UAAU,KAAK,MAAM;CAC3B,IAAI,MAAM,QAAQ;AAClB,QAAO,MAAM,GAAG;EACd,MAAM,OAAO,QAAQ,MAAM;AAC3B,MAAI,SAAS,OAAO,SAAS,OAAO,SAAS,IAAK;AAClD,SAAO;;AAET,QAAO,QAAQ,MAAM,GAAG,IAAI;;AAG9B,SAAS,cAAc,SAAgD;AACrE,KAAI,CAAC,QAAS,QAAO;CACrB,MAAM,aAAa,MAAM,QAAQ,QAAQ,GAAG,QAAQ,KAAK,KAAK,GAAG;AACjE,KAAI,CAAC,WAAW,MAAM,CAAE,QAAO;AAC/B,QAAO,eAAe,YAAY,aAAa;;AAGjD,SAAgB,6BACd,OACoB;AACpB,KAAI,SAAS,KAAM,QAAO,KAAA;AAC1B,QAAO,OAAO,MAAM;;AAGtB,SAAgB,wBAAwB,EACtC,QACA,UACA,cACA,aACA,KACA,KACA,QACA,SACA,WACiC;CACjC,MAAM,SAAS,SACX,WACE,GAAG,OAAO,GAAG,SAAS,KACtB,GAAG,OAAO,KACZ,WACE,GAAG,SAAS,KACZ;CACN,MAAM,aAAa,MACf,GAAG,cAAc,aAAa,CAAC,WAAW,cAAc,IAAI,KAC5D;CACJ,MAAM,sBACJ,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,SAAS,KAAK,cAAc,OAAO,CAAC;CAI3D,MAAM,eAAe;EACnB;EACA;EALmB,sBACjB,GAAG,cAAc,IAAI,CAAC,OAAO,cAAc,OAAO,KAClD;EAKF,sBAAsB,KAAA,IAAY;EAClC,cAAc,QAAQ;EACvB,CACE,QAAQ,SAAyB,CAAC,CAAC,KAAK,CACxC,IAAI,eAAe;AAEtB,KAAI,QACF,cAAa,KAAK,eAAe,UAAU;CAG7C,MAAM,UAAU,aAAa,KAAK,IAAI;AACtC,QAAO,SAAS,GAAG,OAAO,GAAG,YAAY;;;;AC5F3C,MAAa,kBAAkB;AAC/B,MAAa,iBAAiB;AAC9B,MAAa,uBAAuB;;;ACApC,SAAgB,cAAc,OAA4C;AACxE,QACE,OAAO,UAAU,YACjB,UAAU,QACV,WAAW,SACX,OAAO,MAAM,UAAU;;AAI3B,SAAgB,gBAAgB,QAAqC;AACnE,QAAO,cAAc,OAAO,MAAM,IAAI,OAAO,OAAO,UAAU;;;;;;AAOhE,SAAgB,gBAAmB,QAIT;AACxB,KAAI,OAAO,SAAS,KAAA,EAGlB,QAAO,OAAO;AAEhB,KAAI,OAAO,UAAU;EACnB,MAAM,UAAU,cAAc,OAAO,MAAM,GACvC,OAAO,MAAM,QACb,OAAO,OAAO,UAAU,WACtB,OAAO,QACP,OAAO,SAAS;AACtB,QAAM,IAAI,SAAS,SAAS,OAAO,SAAS,QAAQ,QAAQ;;AAE9D,OAAM,OAAO"}
|