generaltranslation 9.4.3 → 9.5.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.
Files changed (154) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +2 -1
  3. package/dist/{ApiError-BcjcnTAr.cjs → ApiError-BCjEo_CM.cjs} +1 -1
  4. package/dist/{ApiError-BcjcnTAr.cjs.map → ApiError-BCjEo_CM.cjs.map} +1 -1
  5. package/dist/{ApiError-CUKcz3YS.mjs → ApiError-DxWKM0Xt.mjs} +1 -1
  6. package/dist/{ApiError-CUKcz3YS.mjs.map → ApiError-DxWKM0Xt.mjs.map} +1 -1
  7. package/dist/adapter/createGtApi.d.ts +196 -27
  8. package/dist/adapter/createGtApi.js +561 -117
  9. package/dist/adapter/modelProvider.d.ts +4 -0
  10. package/dist/adapter/modelProvider.js +6 -0
  11. package/dist/derive-BVRyqmWc.mjs +657 -0
  12. package/dist/derive-BVRyqmWc.mjs.map +1 -0
  13. package/dist/{derive-DBCCXTmL.d.cts → derive-J2NQLqZm.d.cts} +1 -1
  14. package/dist/derive-sRw1yaMu.cjs +734 -0
  15. package/dist/derive-sRw1yaMu.cjs.map +1 -0
  16. package/dist/diagnostics-CqAHg_Vc.d.cts +34 -0
  17. package/dist/diagnostics-DKA2SkZB.mjs +45 -0
  18. package/dist/diagnostics-DKA2SkZB.mjs.map +1 -0
  19. package/dist/{unwrapApiResult-BzGfPw75.mjs → diagnostics-DKtiPUvo.cjs} +12 -31
  20. package/dist/diagnostics-DKtiPUvo.cjs.map +1 -0
  21. package/dist/diagnostics-DYtVjOm5.d.mts +34 -0
  22. package/dist/diagnostics.cjs +4 -0
  23. package/dist/diagnostics.d.cts +2 -0
  24. package/dist/diagnostics.d.mts +2 -0
  25. package/dist/diagnostics.d.ts +1 -0
  26. package/dist/diagnostics.js +1 -0
  27. package/dist/diagnostics.mjs +2 -0
  28. package/dist/errors.cjs +1 -1
  29. package/dist/errors.mjs +1 -1
  30. package/dist/file-B37WkCqM.cjs.map +1 -1
  31. package/dist/file-Dga6cyM8.mjs.map +1 -1
  32. package/dist/{id-X2zyx5Jk.mjs → id-B2wA7-S-.mjs} +19 -3
  33. package/dist/id-B2wA7-S-.mjs.map +1 -0
  34. package/dist/{id-pdr3R1xs.cjs → id-DJ_59q21.cjs} +25 -3
  35. package/dist/id-DJ_59q21.cjs.map +1 -0
  36. package/dist/id.cjs +1 -1
  37. package/dist/id.d.cts +1 -1
  38. package/dist/id.d.mts +1 -1
  39. package/dist/id.mjs +1 -1
  40. package/dist/index.cjs +94 -753
  41. package/dist/index.cjs.map +1 -1
  42. package/dist/index.d.cts +14 -33
  43. package/dist/index.d.mts +13 -32
  44. package/dist/index.d.ts +20 -16
  45. package/dist/index.js +110 -98
  46. package/dist/index.mjs +88 -746
  47. package/dist/index.mjs.map +1 -1
  48. package/dist/internal.cjs +16 -186
  49. package/dist/internal.cjs.map +1 -1
  50. package/dist/internal.d.cts +200 -62
  51. package/dist/internal.d.mts +199 -61
  52. package/dist/internal.d.ts +3 -1
  53. package/dist/internal.js +2 -1
  54. package/dist/internal.mjs +6 -178
  55. package/dist/internal.mjs.map +1 -1
  56. package/dist/logging/errors.d.ts +0 -1
  57. package/dist/logging/errors.js +0 -6
  58. package/dist/logging/logger.js +6 -4
  59. package/dist/openapi.json +12 -6
  60. package/dist/runtime.cjs +580 -2
  61. package/dist/runtime.cjs.map +1 -0
  62. package/dist/runtime.d.cts +12 -6
  63. package/dist/runtime.d.mts +12 -6
  64. package/dist/runtime.d.ts +10 -4
  65. package/dist/runtime.js +10 -65
  66. package/dist/runtime.mjs +579 -1
  67. package/dist/runtime.mjs.map +1 -0
  68. package/dist/runtimeTranslate-CVw143pQ.mjs +506 -0
  69. package/dist/runtimeTranslate-CVw143pQ.mjs.map +1 -0
  70. package/dist/runtimeTranslate-DJioRjb6.cjs +601 -0
  71. package/dist/runtimeTranslate-DJioRjb6.cjs.map +1 -0
  72. package/dist/translate/awaitJobs.d.ts +2 -2
  73. package/dist/translate/awaitJobs.js +1 -156
  74. package/dist/translate/checkJobStatus.d.ts +2 -1
  75. package/dist/translate/checkJobStatus.js +1 -55
  76. package/dist/translate/createBranch.d.ts +2 -6
  77. package/dist/translate/createBranch.js +1 -53
  78. package/dist/translate/enqueueFiles.js +1 -95
  79. package/dist/translate/getProjectInfo.d.ts +2 -6
  80. package/dist/translate/getProjectInfo.js +1 -54
  81. package/dist/translate/processFileMoves.d.ts +3 -13
  82. package/dist/translate/processFileMoves.js +1 -90
  83. package/dist/translate/publishFiles.d.ts +3 -15
  84. package/dist/translate/publishFiles.js +1 -56
  85. package/dist/translate/queryBranchData.js +1 -53
  86. package/dist/translate/queryFileData.d.ts +3 -41
  87. package/dist/translate/queryFileData.js +1 -71
  88. package/dist/translate/runtimeTranslate.d.ts +6 -0
  89. package/dist/translate/runtimeTranslate.js +297 -0
  90. package/dist/translate/setupProject.d.ts +2 -6
  91. package/dist/translate/setupProject.js +1 -63
  92. package/dist/translate/submitUserEditDiffs.js +1 -68
  93. package/dist/translate/utils/fetchWithTimeout.js +19 -12
  94. package/dist/{types-bCr8pV1Z.d.cts → types-Si4UstLL.d.mts} +41 -165
  95. package/dist/types-dir/__tests__/runtimeTranslate.type-test.js +18 -0
  96. package/dist/types-dir/api/branch.d.ts +3 -9
  97. package/dist/types-dir/api/checkFileTranslations.d.ts +2 -22
  98. package/dist/types-dir/api/downloadFileBatch.d.ts +2 -7
  99. package/dist/types-dir/api/entry.d.ts +3 -8
  100. package/dist/types-dir/api/file.d.ts +2 -1
  101. package/dist/types-dir/api/json.d.ts +1 -4
  102. package/dist/types-dir/api/project.d.ts +2 -7
  103. package/dist/types-dir/api/uploadAssets.d.ts +3 -10
  104. package/dist/types-dir/api/uploadAssets.js +0 -4
  105. package/dist/types-dir/config.d.ts +1 -0
  106. package/dist/{types-Dp1drjxq.d.mts → types-yByDbKnV.d.cts} +41 -165
  107. package/dist/types.d.cts +2 -2
  108. package/dist/types.d.mts +2 -2
  109. package/dist/types.d.ts +26 -7
  110. package/dist/utils/isSupportedFileFormatTransform.js +1 -0
  111. package/package.json +15 -2
  112. package/dist/derive-2CDqwrvS.cjs +0 -303
  113. package/dist/derive-2CDqwrvS.cjs.map +0 -1
  114. package/dist/derive-CTzR56T_.mjs +0 -233
  115. package/dist/derive-CTzR56T_.mjs.map +0 -1
  116. package/dist/id-X2zyx5Jk.mjs.map +0 -1
  117. package/dist/id-pdr3R1xs.cjs.map +0 -1
  118. package/dist/isVariable-8-Wy5FnX.mjs +0 -20
  119. package/dist/isVariable-8-Wy5FnX.mjs.map +0 -1
  120. package/dist/isVariable-I3nllgeI.cjs +0 -25
  121. package/dist/isVariable-I3nllgeI.cjs.map +0 -1
  122. package/dist/projects/getProjectData.js +0 -87
  123. package/dist/runtime-Bcp4F2ME.mjs +0 -974
  124. package/dist/runtime-Bcp4F2ME.mjs.map +0 -1
  125. package/dist/runtime-C25lwh9m.cjs +0 -1027
  126. package/dist/runtime-C25lwh9m.cjs.map +0 -1
  127. package/dist/translate/api.d.ts +0 -4
  128. package/dist/translate/api.js +0 -4
  129. package/dist/translate/createTag.d.ts +0 -19
  130. package/dist/translate/createTag.js +0 -67
  131. package/dist/translate/downloadFileBatch.d.ts +0 -1
  132. package/dist/translate/downloadFileBatch.js +0 -80
  133. package/dist/translate/getOrphanedFiles.d.ts +0 -8
  134. package/dist/translate/getOrphanedFiles.js +0 -97
  135. package/dist/translate/querySourceFile.d.ts +0 -1
  136. package/dist/translate/querySourceFile.js +0 -67
  137. package/dist/translate/translateMany.d.ts +0 -1
  138. package/dist/translate/translateMany.js +0 -124
  139. package/dist/translate/uploadFonts.d.ts +0 -1
  140. package/dist/translate/uploadFonts.js +0 -74
  141. package/dist/translate/uploadSourceFiles.d.ts +0 -1
  142. package/dist/translate/uploadSourceFiles.js +0 -90
  143. package/dist/translate/uploadTranslations.d.ts +0 -1
  144. package/dist/translate/uploadTranslations.js +0 -106
  145. package/dist/translate/utils/apiRequest.d.ts +0 -1
  146. package/dist/translate/utils/apiRequest.js +0 -167
  147. package/dist/translate/utils/generateRequestHeaders.d.ts +0 -2
  148. package/dist/translate/utils/generateRequestHeaders.js +0 -21
  149. package/dist/translate/utils/handleFetchError.d.ts +0 -1
  150. package/dist/translate/utils/handleFetchError.js +0 -12
  151. package/dist/unwrapApiResult-BzGfPw75.mjs.map +0 -1
  152. package/dist/unwrapApiResult-Dv6Mfw_K.cjs +0 -134
  153. package/dist/unwrapApiResult-Dv6Mfw_K.cjs.map +0 -1
  154. /package/dist/{projects/getProjectData.d.ts → types-dir/__tests__/runtimeTranslate.type-test.d.ts} +0 -0
@@ -45,98 +45,223 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
- var __rest = (this && this.__rest) || function (s, e) {
49
- var t = {};
50
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
- t[p] = s[p];
52
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
54
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
55
- t[p[i]] = s[p[i]];
48
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
+ if (ar || !(i in from)) {
51
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
+ ar[i] = from[i];
56
53
  }
57
- return t;
54
+ }
55
+ return to.concat(ar || Array.prototype.slice.call(from));
58
56
  };
59
- import { createApiClient, createBranch, DEFAULT_BATCH_SIZE, downloadFiles, enqueueFileTranslations, generateProjectContext, getFileInfo, getTranslationJobInfo, pollJobs, processBatches, uploadSourceFiles, uploadTranslations, } from '@generaltranslation/api';
57
+ import { createApiClient, createBranch, createProject, createProjectApiKey, createTag, DEFAULT_BATCH_SIZE, downloadFiles, enqueueFileTranslations, generateProjectContext, getBranchInfo, getFileInfo, getOrphanedFiles, getProjectInfo, getTranslationJobInfo, getTranslationStatus, listOrgs, listProjects, pollJobs, processBatches, processFileMoves, publishFiles, submitUserEditDiffs, uploadAssets, uploadSourceFiles, uploadTranslations, } from '@generaltranslation/api';
60
58
  import { resolveAliasLocale, resolveCanonicalLocale, standardizeLocale, } from '@generaltranslation/format';
59
+ import { createDiagnosticMessage } from '../logging/diagnostics';
60
+ import { translate as translateWithConfig, translateMany as translateManyWithConfig, } from '../translate/runtimeTranslate';
61
61
  import { decodeFileContent, encodeFileContent } from '../utils/base64';
62
62
  import { unwrapApiResult } from '../translate/utils/unwrapApiResult';
63
+ import { validateFileFormatTransforms } from '../translate/utils/validateFileFormatTransform';
64
+ import { isModelProvider, supportedModelProviders } from './modelProvider';
65
+ // Follows nextCursor until the service reports the last page.
66
+ function collectPages(loadPage) {
67
+ return __awaiter(this, void 0, void 0, function () {
68
+ var items, cursor, page;
69
+ var _a;
70
+ return __generator(this, function (_b) {
71
+ switch (_b.label) {
72
+ case 0:
73
+ items = [];
74
+ _b.label = 1;
75
+ case 1: return [4 /*yield*/, loadPage(cursor)];
76
+ case 2:
77
+ page = _b.sent();
78
+ items.push.apply(items, page.items);
79
+ cursor = (_a = page.nextCursor) !== null && _a !== void 0 ? _a : undefined;
80
+ _b.label = 3;
81
+ case 3:
82
+ if (cursor) return [3 /*break*/, 1];
83
+ _b.label = 4;
84
+ case 4: return [2 /*return*/, items];
85
+ }
86
+ });
87
+ });
88
+ }
89
+ function normalizeJobStatus(job) {
90
+ var _a;
91
+ return __assign({ jobId: job.jobId, status: job.status }, (job.status === 'failed'
92
+ ? { error: { message: (_a = job.error.message) !== null && _a !== void 0 ? _a : '' } }
93
+ : {}));
94
+ }
63
95
  export function createGtApiAdapter(defaultConfig) {
64
- var client = defaultConfig ? createApiClient(defaultConfig) : undefined;
65
- var configuredClientConfig = defaultConfig;
66
- var customMapping;
96
+ var client;
97
+ var config;
67
98
  // Mapping resolves aliases; standardization also canonicalizes configured
68
99
  // spellings such as en-us before they cross the service boundary.
69
100
  function resolveServiceLocale(locale) {
70
- return standardizeLocale(resolveCanonicalLocale(locale, customMapping));
101
+ return standardizeLocale(resolveCanonicalLocale(locale, config === null || config === void 0 ? void 0 : config.customMapping));
71
102
  }
72
- function getClient() {
73
- if (!client) {
74
- throw new Error('API client not configured — call configureApiClient first');
75
- }
76
- return client;
103
+ // Upload responses echo the canonical locale; callers key lockfile entries
104
+ // by the configured alias, so map it back before it leaves the adapter.
105
+ function aliasUploadedFileLocale(file) {
106
+ return file.locale
107
+ ? __assign(__assign({}, file), { locale: resolveAliasLocale(file.locale, config === null || config === void 0 ? void 0 : config.customMapping) }) : file;
77
108
  }
78
- function getClientConfig() {
79
- if (!configuredClientConfig) {
109
+ function getConfig() {
110
+ if (!config) {
80
111
  throw new Error('API client not configured — call configureApiClient first');
81
112
  }
82
- return configuredClientConfig;
113
+ return config;
114
+ }
115
+ function getClient(timeoutMs) {
116
+ if (timeoutMs === undefined && client)
117
+ return client;
118
+ return createApiClient(__assign(__assign({}, getConfig()), { timeoutMs: timeoutMs }));
83
119
  }
84
- function configure(config) {
85
- var mapping = config.customMapping, clientConfig = __rest(config, ["customMapping"]);
86
- client = createApiClient(clientConfig);
87
- configuredClientConfig = clientConfig;
88
- customMapping = mapping;
120
+ function configure(nextConfig) {
121
+ client = createApiClient(nextConfig);
122
+ config = __assign({}, nextConfig);
123
+ }
124
+ function translate(source, options, timeoutMs) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ return __generator(this, function (_a) {
127
+ return [2 /*return*/, translateWithConfig(source, options, __assign(__assign({}, getConfig()), (timeoutMs !== undefined && { timeoutMs: timeoutMs })))];
128
+ });
129
+ });
130
+ }
131
+ function translateMany(sources, options, timeoutMs) {
132
+ return __awaiter(this, void 0, void 0, function () {
133
+ return __generator(this, function (_a) {
134
+ return [2 /*return*/, translateManyWithConfig(sources, options, __assign(__assign({}, getConfig()), (timeoutMs !== undefined && { timeoutMs: timeoutMs })))];
135
+ });
136
+ });
137
+ }
138
+ if (defaultConfig)
139
+ configure(defaultConfig);
140
+ // Raw service responses; the normalized adapter methods build on these and
141
+ // compatibility facades (CLI) expose them unchanged.
142
+ function loadJobStatuses(jobIds_1) {
143
+ return __awaiter(this, arguments, void 0, function (jobIds, options) {
144
+ var _a;
145
+ if (options === void 0) { options = {}; }
146
+ return __generator(this, function (_b) {
147
+ switch (_b.label) {
148
+ case 0:
149
+ _a = unwrapApiResult;
150
+ return [4 /*yield*/, getTranslationJobInfo({
151
+ body: { jobIds: __spreadArray([], jobIds, true) },
152
+ client: getClient(options.timeoutMs),
153
+ signal: options.signal,
154
+ })];
155
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
156
+ }
157
+ });
158
+ });
159
+ }
160
+ function loadProjectInfo(projectId, timeoutMs) {
161
+ return __awaiter(this, void 0, void 0, function () {
162
+ var resolvedProjectId, _a;
163
+ return __generator(this, function (_b) {
164
+ switch (_b.label) {
165
+ case 0:
166
+ resolvedProjectId = projectId !== null && projectId !== void 0 ? projectId : getConfig().projectId;
167
+ if (!resolvedProjectId) {
168
+ throw new Error('Project ID is required to fetch project information');
169
+ }
170
+ _a = unwrapApiResult;
171
+ return [4 /*yield*/, getProjectInfo({
172
+ client: getClient(timeoutMs),
173
+ path: { projectId: resolvedProjectId },
174
+ })];
175
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
176
+ }
177
+ });
178
+ });
89
179
  }
90
180
  return {
91
181
  configure: configure,
92
182
  getClient: getClient,
93
- getClientConfig: getClientConfig,
94
183
  resolveAliasLocale: function (locale) {
95
- return resolveAliasLocale(locale, customMapping);
184
+ return resolveAliasLocale(locale, config === null || config === void 0 ? void 0 : config.customMapping);
96
185
  },
97
186
  resolveCanonicalLocale: function (locale) {
98
187
  return resolveServiceLocale(locale);
99
188
  },
100
- createBranch: function (body) {
189
+ translate: translate,
190
+ translateMany: translateMany,
191
+ queryBranchData: function (body) {
101
192
  return __awaiter(this, void 0, void 0, function () {
102
193
  var _a;
103
194
  return __generator(this, function (_b) {
104
195
  switch (_b.label) {
105
196
  case 0:
106
197
  _a = unwrapApiResult;
107
- return [4 /*yield*/, createBranch({ body: body, client: getClient() })];
198
+ return [4 /*yield*/, getBranchInfo({ body: body, client: getClient() })];
108
199
  case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
109
200
  }
110
201
  });
111
202
  });
112
203
  },
113
- queryFileData: function (body) {
204
+ createBranch: function (body) {
114
205
  return __awaiter(this, void 0, void 0, function () {
115
- var result, _a;
116
- var _b;
117
- return __generator(this, function (_c) {
118
- switch (_c.label) {
206
+ var _a;
207
+ return __generator(this, function (_b) {
208
+ switch (_b.label) {
119
209
  case 0:
120
210
  _a = unwrapApiResult;
121
- return [4 /*yield*/, getFileInfo({
122
- body: __assign(__assign({}, body), { translatedFiles: (_b = body.translatedFiles) === null || _b === void 0 ? void 0 : _b.map(function (file) { return (__assign(__assign({}, file), { locale: resolveServiceLocale(file.locale) })); }) }),
123
- client: getClient(),
124
- })];
125
- case 1:
126
- result = _a.apply(void 0, [_c.sent()]);
127
- return [2 /*return*/, __assign(__assign({}, result), { translatedFiles: result.translatedFiles.map(function (file) { return (__assign(__assign({}, file), { locale: resolveAliasLocale(file.locale, customMapping) })); }), sourceFiles: result.sourceFiles.map(function (file) { return (__assign(__assign({}, file), { sourceLocale: resolveAliasLocale(file.sourceLocale, customMapping), locales: file.locales.map(function (locale) {
128
- return resolveAliasLocale(locale, customMapping);
129
- }) })); }) })];
211
+ return [4 /*yield*/, createBranch({ body: body, client: getClient() })];
212
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
130
213
  }
131
214
  });
132
215
  });
133
216
  },
134
- downloadFileBatch: function (files) {
135
- return __awaiter(this, void 0, void 0, function () {
136
- var request, responses;
217
+ processFileMoves: function (moves_1) {
218
+ return __awaiter(this, arguments, void 0, function (moves, options) {
219
+ var results, succeeded;
137
220
  var _this = this;
221
+ if (options === void 0) { options = {}; }
138
222
  return __generator(this, function (_a) {
139
223
  switch (_a.label) {
224
+ case 0: return [4 /*yield*/, processBatches(moves, function (batch) { return __awaiter(_this, void 0, void 0, function () {
225
+ var response, _a;
226
+ return __generator(this, function (_b) {
227
+ switch (_b.label) {
228
+ case 0:
229
+ _a = unwrapApiResult;
230
+ return [4 /*yield*/, processFileMoves({
231
+ body: { branchId: options.branchId, moves: batch },
232
+ client: getClient(options.timeout),
233
+ })];
234
+ case 1:
235
+ response = _a.apply(void 0, [_b.sent()]);
236
+ return [2 /*return*/, response.results];
237
+ }
238
+ });
239
+ }); })];
240
+ case 1:
241
+ results = _a.sent();
242
+ succeeded = results.filter(function (_a) {
243
+ var success = _a.success;
244
+ return success;
245
+ }).length;
246
+ return [2 /*return*/, {
247
+ results: results,
248
+ summary: {
249
+ total: moves.length,
250
+ succeeded: succeeded,
251
+ failed: results.length - succeeded,
252
+ },
253
+ }];
254
+ }
255
+ });
256
+ });
257
+ },
258
+ getOrphanedFiles: function (branchId_1, fileIds_1) {
259
+ return __awaiter(this, arguments, void 0, function (branchId, fileIds, options) {
260
+ var request, results, orphanedFiles, _i, _a, result, batchFileIds, _b, _c, fileId;
261
+ var _this = this;
262
+ if (options === void 0) { options = {}; }
263
+ return __generator(this, function (_d) {
264
+ switch (_d.label) {
140
265
  case 0:
141
266
  request = function (batch) { return __awaiter(_this, void 0, void 0, function () {
142
267
  var _a;
@@ -144,17 +269,17 @@ export function createGtApiAdapter(defaultConfig) {
144
269
  switch (_b.label) {
145
270
  case 0:
146
271
  _a = unwrapApiResult;
147
- return [4 /*yield*/, downloadFiles({
148
- body: batch.map(function (file) { return (__assign(__assign({}, file), { locale: file.locale
149
- ? resolveServiceLocale(file.locale)
150
- : undefined })); }),
151
- client: getClient(),
272
+ return [4 /*yield*/, getOrphanedFiles({
273
+ body: { branchId: branchId, fileIds: batch },
274
+ client: getClient(options.timeout),
152
275
  })];
153
276
  case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
154
277
  }
155
278
  });
156
279
  }); };
157
- return [4 /*yield*/, processBatches(files, function (batch) { return __awaiter(_this, void 0, void 0, function () {
280
+ if (fileIds.length === 0)
281
+ return [2 /*return*/, request([])];
282
+ return [4 /*yield*/, processBatches(fileIds, function (batch) { return __awaiter(_this, void 0, void 0, function () {
158
283
  return __generator(this, function (_a) {
159
284
  switch (_a.label) {
160
285
  case 0: return [4 /*yield*/, request(batch)];
@@ -165,19 +290,18 @@ export function createGtApiAdapter(defaultConfig) {
165
290
  });
166
291
  }); })];
167
292
  case 1:
168
- responses = _a.sent();
169
- return [2 /*return*/, {
170
- files: responses.flatMap(function (response) {
171
- return response.files.map(function (file) { return (__assign(__assign(__assign({}, file), (file.locale && {
172
- locale: resolveAliasLocale(file.locale, customMapping),
173
- })), { data: decodeFileContent(file.data, file.fileFormat),
174
- // OpenAPI currently types metadata as an open object; the API emits
175
- // JSON values here, matching DownloadedFile's public contract.
176
- metadata: file.metadata })); });
177
- }),
178
- count: responses.reduce(function (count, response) { return count + response.count; }, 0),
179
- pending: responses.flatMap(function (response) { var _a; return (_a = response.pending) !== null && _a !== void 0 ? _a : []; }),
180
- }];
293
+ results = _d.sent();
294
+ orphanedFiles = new Map(results[0].orphanedFiles.map(function (file) { return [file.fileId, file]; }));
295
+ for (_i = 0, _a = results.slice(1); _i < _a.length; _i++) {
296
+ result = _a[_i];
297
+ batchFileIds = new Set(result.orphanedFiles.map(function (file) { return file.fileId; }));
298
+ for (_b = 0, _c = Array.from(orphanedFiles.keys()); _b < _c.length; _b++) {
299
+ fileId = _c[_b];
300
+ if (!batchFileIds.has(fileId))
301
+ orphanedFiles.delete(fileId);
302
+ }
303
+ }
304
+ return [2 /*return*/, { orphanedFiles: Array.from(orphanedFiles.values()) }];
181
305
  }
182
306
  });
183
307
  });
@@ -206,20 +330,57 @@ export function createGtApiAdapter(defaultConfig) {
206
330
  }),
207
331
  force: options.force,
208
332
  },
209
- client: getClient(),
333
+ client: getClient(options.timeoutMs),
210
334
  })];
211
335
  case 1: return [2 /*return*/, _a.apply(void 0, [_c.sent()])];
212
336
  }
213
337
  });
214
338
  });
215
339
  },
340
+ loadJobStatuses: loadJobStatuses,
341
+ checkJobStatus: function (jobIds, timeoutMs) {
342
+ return __awaiter(this, void 0, void 0, function () {
343
+ var statuses;
344
+ return __generator(this, function (_a) {
345
+ switch (_a.label) {
346
+ case 0: return [4 /*yield*/, loadJobStatuses(jobIds, { timeoutMs: timeoutMs })];
347
+ case 1:
348
+ statuses = _a.sent();
349
+ return [2 /*return*/, statuses.map(normalizeJobStatus)];
350
+ }
351
+ });
352
+ });
353
+ },
354
+ awaitJobs: function (jobIds, options) {
355
+ return __awaiter(this, void 0, void 0, function () {
356
+ var result;
357
+ return __generator(this, function (_a) {
358
+ switch (_a.label) {
359
+ case 0: return [4 /*yield*/, pollJobs(jobIds, function (pendingJobIds, signal) { return loadJobStatuses(pendingJobIds, { signal: signal }); }, options)];
360
+ case 1:
361
+ result = _a.sent();
362
+ return [2 /*return*/, __assign(__assign({}, result), { jobs: result.jobs.map(normalizeJobStatus) })];
363
+ }
364
+ });
365
+ });
366
+ },
216
367
  enqueueFiles: function (files, options) {
217
368
  return __awaiter(this, void 0, void 0, function () {
218
- var targetLocales, result;
369
+ var modelProvider, targetLocales, result;
219
370
  var _this = this;
220
371
  return __generator(this, function (_a) {
221
372
  switch (_a.label) {
222
373
  case 0:
374
+ validateFileFormatTransforms(files);
375
+ modelProvider = options.modelProvider;
376
+ if (modelProvider !== undefined && !isModelProvider(modelProvider)) {
377
+ throw new Error(createDiagnosticMessage({
378
+ source: 'generaltranslation',
379
+ severity: 'Error',
380
+ whatHappened: "Unsupported model provider `".concat(modelProvider, "`"),
381
+ fix: "Use one of: ".concat(supportedModelProviders.join(', ')),
382
+ }));
383
+ }
223
384
  targetLocales = options.targetLocales.map(function (locale) {
224
385
  return resolveServiceLocale(locale);
225
386
  });
@@ -245,12 +406,10 @@ export function createGtApiAdapter(defaultConfig) {
245
406
  sourceLocale: options.sourceLocale
246
407
  ? resolveServiceLocale(options.sourceLocale)
247
408
  : undefined,
248
- // Consumers intentionally accept custom model-provider strings beyond
249
- // the OpenAPI enum; preserve the existing wire behavior at this boundary.
250
- modelProvider: options.modelProvider,
409
+ modelProvider: modelProvider,
251
410
  force: options.force,
252
411
  },
253
- client: getClient(),
412
+ client: getClient(options.timeout),
254
413
  })];
255
414
  case 1:
256
415
  response = _a.apply(void 0, [_b.sent()]);
@@ -270,6 +429,278 @@ export function createGtApiAdapter(defaultConfig) {
270
429
  });
271
430
  });
272
431
  },
432
+ createTag: function (body) {
433
+ return __awaiter(this, void 0, void 0, function () {
434
+ var _a;
435
+ return __generator(this, function (_b) {
436
+ switch (_b.label) {
437
+ case 0:
438
+ _a = unwrapApiResult;
439
+ return [4 /*yield*/, createTag({ body: body, client: getClient() })];
440
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
441
+ }
442
+ });
443
+ });
444
+ },
445
+ publishFiles: function (files) {
446
+ return __awaiter(this, void 0, void 0, function () {
447
+ var _a;
448
+ return __generator(this, function (_b) {
449
+ switch (_b.label) {
450
+ case 0:
451
+ _a = unwrapApiResult;
452
+ return [4 /*yield*/, publishFiles({
453
+ body: {
454
+ files: files.map(function (_a) {
455
+ var fileId = _a.fileId, versionId = _a.versionId, branchId = _a.branchId, publish = _a.publish;
456
+ return ({
457
+ fileId: fileId,
458
+ versionId: versionId,
459
+ branchId: branchId,
460
+ publish: publish,
461
+ });
462
+ }),
463
+ },
464
+ client: getClient(),
465
+ })];
466
+ case 1:
467
+ // Compatibility callers pass entries carrying fileName; map only the
468
+ // contract fields so nothing outside the generated body reaches the wire.
469
+ return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
470
+ }
471
+ });
472
+ });
473
+ },
474
+ submitUserEditDiffs: function (body_1) {
475
+ return __awaiter(this, arguments, void 0, function (body, options) {
476
+ var _this = this;
477
+ if (options === void 0) { options = {}; }
478
+ return __generator(this, function (_a) {
479
+ return [2 /*return*/, processBatches(body.diffs, function (diffs) { return __awaiter(_this, void 0, void 0, function () {
480
+ var _a;
481
+ return __generator(this, function (_b) {
482
+ switch (_b.label) {
483
+ case 0:
484
+ _a = unwrapApiResult;
485
+ return [4 /*yield*/, submitUserEditDiffs({
486
+ body: {
487
+ projectId: body.projectId,
488
+ diffs: diffs.map(function (_a) {
489
+ var diff = _a.diff, branchId = _a.branchId, versionId = _a.versionId, fileId = _a.fileId, localContent = _a.localContent, locale = _a.locale;
490
+ return ({
491
+ diff: diff,
492
+ branchId: branchId,
493
+ versionId: versionId,
494
+ fileId: fileId,
495
+ localContent: localContent,
496
+ locale: resolveServiceLocale(locale),
497
+ });
498
+ }),
499
+ },
500
+ client: getClient(options.timeout),
501
+ })];
502
+ case 1: return [2 /*return*/, [
503
+ _a.apply(void 0, [_b.sent()])
504
+ ]];
505
+ }
506
+ });
507
+ }); })];
508
+ });
509
+ });
510
+ },
511
+ createProject: function (orgId, body) {
512
+ return __awaiter(this, void 0, void 0, function () {
513
+ var _a;
514
+ return __generator(this, function (_b) {
515
+ switch (_b.label) {
516
+ case 0:
517
+ _a = unwrapApiResult;
518
+ return [4 /*yield*/, createProject({
519
+ path: { orgId: orgId },
520
+ body: __assign(__assign({}, body), { defaultLocale: resolveServiceLocale(body.defaultLocale) }),
521
+ client: getClient(),
522
+ })];
523
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
524
+ }
525
+ });
526
+ });
527
+ },
528
+ /** Every project the configured credentials can read. */
529
+ listProjects: function () {
530
+ return __awaiter(this, void 0, void 0, function () {
531
+ var _this = this;
532
+ return __generator(this, function (_a) {
533
+ return [2 /*return*/, collectPages(function (cursor) { return __awaiter(_this, void 0, void 0, function () {
534
+ var _a, projects, nextCursor, _b;
535
+ return __generator(this, function (_c) {
536
+ switch (_c.label) {
537
+ case 0:
538
+ _b = unwrapApiResult;
539
+ return [4 /*yield*/, listProjects({
540
+ query: cursor ? { cursor: cursor } : undefined,
541
+ client: getClient(),
542
+ })];
543
+ case 1:
544
+ _a = _b.apply(void 0, [_c.sent()]), projects = _a.projects, nextCursor = _a.nextCursor;
545
+ return [2 /*return*/, { items: projects, nextCursor: nextCursor }];
546
+ }
547
+ });
548
+ }); })];
549
+ });
550
+ });
551
+ },
552
+ /** Organizations where the signed-in user can create projects; user tokens only. */
553
+ listOrgs: function () {
554
+ return __awaiter(this, void 0, void 0, function () {
555
+ var _this = this;
556
+ return __generator(this, function (_a) {
557
+ return [2 /*return*/, collectPages(function (cursor) { return __awaiter(_this, void 0, void 0, function () {
558
+ var _a, orgs, nextCursor, _b;
559
+ return __generator(this, function (_c) {
560
+ switch (_c.label) {
561
+ case 0:
562
+ _b = unwrapApiResult;
563
+ return [4 /*yield*/, listOrgs({
564
+ query: cursor ? { cursor: cursor } : undefined,
565
+ client: getClient(),
566
+ })];
567
+ case 1:
568
+ _a = _b.apply(void 0, [_c.sent()]), orgs = _a.orgs, nextCursor = _a.nextCursor;
569
+ return [2 /*return*/, { items: orgs, nextCursor: nextCursor }];
570
+ }
571
+ });
572
+ }); })];
573
+ });
574
+ });
575
+ },
576
+ createProjectApiKey: function (projectId, body) {
577
+ return __awaiter(this, void 0, void 0, function () {
578
+ var _a;
579
+ return __generator(this, function (_b) {
580
+ switch (_b.label) {
581
+ case 0:
582
+ _a = unwrapApiResult;
583
+ return [4 /*yield*/, createProjectApiKey({
584
+ path: { projectId: projectId },
585
+ body: body,
586
+ client: getClient(),
587
+ })];
588
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
589
+ }
590
+ });
591
+ });
592
+ },
593
+ loadProjectInfo: loadProjectInfo,
594
+ getProjectInfo: function (projectId, timeoutMs) {
595
+ return __awaiter(this, void 0, void 0, function () {
596
+ var result;
597
+ return __generator(this, function (_a) {
598
+ switch (_a.label) {
599
+ case 0: return [4 /*yield*/, loadProjectInfo(projectId, timeoutMs)];
600
+ case 1:
601
+ result = _a.sent();
602
+ return [2 /*return*/, __assign(__assign({}, result), { defaultLocale: resolveAliasLocale(result.defaultLocale, config === null || config === void 0 ? void 0 : config.customMapping), currentLocales: result.currentLocales.map(function (locale) {
603
+ return resolveAliasLocale(locale, config === null || config === void 0 ? void 0 : config.customMapping);
604
+ }) })];
605
+ }
606
+ });
607
+ });
608
+ },
609
+ queryFileData: function (body, timeoutMs) {
610
+ return __awaiter(this, void 0, void 0, function () {
611
+ var result, _a;
612
+ var _b;
613
+ return __generator(this, function (_c) {
614
+ switch (_c.label) {
615
+ case 0:
616
+ _a = unwrapApiResult;
617
+ return [4 /*yield*/, getFileInfo({
618
+ body: __assign(__assign({}, body), { translatedFiles: (_b = body.translatedFiles) === null || _b === void 0 ? void 0 : _b.map(function (file) { return (__assign(__assign({}, file), { locale: resolveServiceLocale(file.locale) })); }) }),
619
+ client: getClient(timeoutMs),
620
+ })];
621
+ case 1:
622
+ result = _a.apply(void 0, [_c.sent()]);
623
+ return [2 /*return*/, __assign(__assign({}, result), { translatedFiles: result.translatedFiles.map(function (file) { return (__assign(__assign({}, file), { locale: resolveAliasLocale(file.locale, config === null || config === void 0 ? void 0 : config.customMapping) })); }), sourceFiles: result.sourceFiles.map(function (file) { return (__assign(__assign({}, file), { sourceLocale: resolveAliasLocale(file.sourceLocale, config === null || config === void 0 ? void 0 : config.customMapping), locales: file.locales.map(function (locale) {
624
+ return resolveAliasLocale(locale, config === null || config === void 0 ? void 0 : config.customMapping);
625
+ }) })); }) })];
626
+ }
627
+ });
628
+ });
629
+ },
630
+ querySourceFile: function (path_1) {
631
+ return __awaiter(this, arguments, void 0, function (path, query, timeoutMs) {
632
+ var result, _a;
633
+ if (query === void 0) { query = {}; }
634
+ return __generator(this, function (_b) {
635
+ switch (_b.label) {
636
+ case 0:
637
+ _a = unwrapApiResult;
638
+ return [4 /*yield*/, getTranslationStatus({
639
+ path: path,
640
+ query: query,
641
+ client: getClient(timeoutMs),
642
+ })];
643
+ case 1:
644
+ result = _a.apply(void 0, [_b.sent()]);
645
+ return [2 /*return*/, __assign(__assign({}, result), { translations: result.translations.map(function (translation) { return (__assign(__assign({}, translation), { locale: resolveAliasLocale(translation.locale, config === null || config === void 0 ? void 0 : config.customMapping) })); }), sourceFile: __assign(__assign({}, result.sourceFile), { sourceLocale: resolveAliasLocale(result.sourceFile.sourceLocale, config === null || config === void 0 ? void 0 : config.customMapping), locales: result.sourceFile.locales.map(function (locale) {
646
+ return resolveAliasLocale(locale, config === null || config === void 0 ? void 0 : config.customMapping);
647
+ }) }) })];
648
+ }
649
+ });
650
+ });
651
+ },
652
+ downloadFileBatch: function (files_1) {
653
+ return __awaiter(this, arguments, void 0, function (files, options) {
654
+ var request, responses;
655
+ var _this = this;
656
+ if (options === void 0) { options = {}; }
657
+ return __generator(this, function (_a) {
658
+ switch (_a.label) {
659
+ case 0:
660
+ request = function (batch) { return __awaiter(_this, void 0, void 0, function () {
661
+ var _a;
662
+ return __generator(this, function (_b) {
663
+ switch (_b.label) {
664
+ case 0:
665
+ _a = unwrapApiResult;
666
+ return [4 /*yield*/, downloadFiles({
667
+ body: batch.map(function (file) { return (__assign(__assign({}, file), { locale: file.locale
668
+ ? resolveServiceLocale(file.locale)
669
+ : undefined })); }),
670
+ client: getClient(options.timeout),
671
+ })];
672
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
673
+ }
674
+ });
675
+ }); };
676
+ return [4 /*yield*/, processBatches(files, function (batch) { return __awaiter(_this, void 0, void 0, function () {
677
+ return __generator(this, function (_a) {
678
+ switch (_a.label) {
679
+ case 0: return [4 /*yield*/, request(batch)];
680
+ case 1: return [2 /*return*/, [
681
+ _a.sent()
682
+ ]];
683
+ }
684
+ });
685
+ }); })];
686
+ case 1:
687
+ responses = _a.sent();
688
+ return [2 /*return*/, {
689
+ files: responses.flatMap(function (response) {
690
+ return response.files.map(function (file) { return (__assign(__assign(__assign({}, file), (file.locale && {
691
+ locale: resolveAliasLocale(file.locale, config === null || config === void 0 ? void 0 : config.customMapping),
692
+ })), { data: decodeFileContent(file.data, file.fileFormat), metadata: file.metadata })); });
693
+ }),
694
+ count: responses.reduce(function (count, response) { return count + response.count; }, 0),
695
+ pending: responses.flatMap(function (response) {
696
+ var _a;
697
+ return ((_a = response.pending) !== null && _a !== void 0 ? _a : []).map(function (file) { return (__assign(__assign({}, file), { locale: resolveAliasLocale(file.locale, config === null || config === void 0 ? void 0 : config.customMapping) })); });
698
+ }),
699
+ }];
700
+ }
701
+ });
702
+ });
703
+ },
273
704
  uploadSourceFiles: function (files, options) {
274
705
  return __awaiter(this, void 0, void 0, function () {
275
706
  var sourceLocale, result;
@@ -294,11 +725,11 @@ export function createGtApiAdapter(defaultConfig) {
294
725
  }),
295
726
  sourceLocale: sourceLocale,
296
727
  },
297
- client: getClient(),
728
+ client: getClient(options.timeout),
298
729
  })];
299
730
  case 1:
300
731
  response = _a.apply(void 0, [_b.sent()]);
301
- return [2 /*return*/, response.uploadedFiles];
732
+ return [2 /*return*/, response.uploadedFiles.map(aliasUploadedFileLocale)];
302
733
  }
303
734
  });
304
735
  }); })];
@@ -309,59 +740,72 @@ export function createGtApiAdapter(defaultConfig) {
309
740
  });
310
741
  });
311
742
  },
312
- awaitJobs: function (jobIds, options) {
313
- return __awaiter(this, void 0, void 0, function () {
314
- var _this = this;
315
- return __generator(this, function (_a) {
316
- return [2 /*return*/, pollJobs(jobIds, function (pendingJobIds, signal) { return __awaiter(_this, void 0, void 0, function () {
317
- var _a;
318
- return __generator(this, function (_b) {
319
- switch (_b.label) {
320
- case 0:
321
- _a = unwrapApiResult;
322
- return [4 /*yield*/, getTranslationJobInfo({
323
- body: { jobIds: pendingJobIds },
324
- client: getClient(),
325
- signal: signal,
326
- })];
327
- case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
328
- }
329
- });
330
- }); }, options)];
331
- });
332
- });
333
- },
334
- uploadTranslations: function (files, options) {
335
- return __awaiter(this, void 0, void 0, function () {
336
- var result;
743
+ uploadFonts: function (fonts_1) {
744
+ return __awaiter(this, arguments, void 0, function (fonts, options) {
745
+ var assets;
337
746
  var _this = this;
747
+ if (options === void 0) { options = {}; }
338
748
  return __generator(this, function (_a) {
339
749
  switch (_a.label) {
340
- case 0: return [4 /*yield*/, processBatches(files, function (batch) { return __awaiter(_this, void 0, void 0, function () {
341
- var response, _a;
750
+ case 0: return [4 /*yield*/, processBatches(fonts, function (batch) { return __awaiter(_this, void 0, void 0, function () {
751
+ var result, _a;
342
752
  return __generator(this, function (_b) {
343
753
  switch (_b.label) {
344
754
  case 0:
345
755
  _a = unwrapApiResult;
346
- return [4 /*yield*/, uploadTranslations({
347
- body: {
348
- data: batch.map(function (_a) {
349
- var source = _a.source, translations = _a.translations;
350
- return ({
351
- source: __assign(__assign({}, source), { content: encodeFileContent(source.content, source.fileFormat), locale: resolveServiceLocale(source.locale) }),
352
- translations: translations.map(function (translation) { return (__assign(__assign({}, translation), { locale: resolveServiceLocale(translation.locale), content: encodeFileContent(translation.content, translation.fileFormat) })); }),
353
- });
354
- }),
355
- sourceLocale: resolveServiceLocale(options.sourceLocale),
356
- },
357
- client: getClient(),
756
+ return [4 /*yield*/, uploadAssets({
757
+ body: { assets: batch },
758
+ client: getClient(options.timeout),
358
759
  })];
359
760
  case 1:
360
- response = _a.apply(void 0, [_b.sent()]);
361
- return [2 /*return*/, response.uploadedFiles];
761
+ result = _a.apply(void 0, [_b.sent()]);
762
+ return [2 /*return*/, result.assets];
362
763
  }
363
764
  });
364
- }); })];
765
+ }); }, { batchSize: 50 })];
766
+ case 1:
767
+ assets = _a.sent();
768
+ return [2 /*return*/, { assets: assets, count: assets.length }];
769
+ }
770
+ });
771
+ });
772
+ },
773
+ uploadTranslations: function (files, options) {
774
+ return __awaiter(this, void 0, void 0, function () {
775
+ var result;
776
+ var _this = this;
777
+ return __generator(this, function (_a) {
778
+ switch (_a.label) {
779
+ case 0:
780
+ validateFileFormatTransforms(files.map(function (_a) {
781
+ var source = _a.source;
782
+ return source;
783
+ }));
784
+ return [4 /*yield*/, processBatches(files, function (batch) { return __awaiter(_this, void 0, void 0, function () {
785
+ var response, _a;
786
+ return __generator(this, function (_b) {
787
+ switch (_b.label) {
788
+ case 0:
789
+ _a = unwrapApiResult;
790
+ return [4 /*yield*/, uploadTranslations({
791
+ body: {
792
+ data: batch.map(function (_a) {
793
+ var source = _a.source, translations = _a.translations;
794
+ return ({
795
+ source: __assign(__assign({}, source), { content: encodeFileContent(source.content, source.fileFormat), locale: resolveServiceLocale(source.locale) }),
796
+ translations: translations.map(function (translation) { return (__assign(__assign({}, translation), { locale: resolveServiceLocale(translation.locale), content: encodeFileContent(translation.content, translation.fileFormat) })); }),
797
+ });
798
+ }),
799
+ sourceLocale: resolveServiceLocale(options.sourceLocale),
800
+ },
801
+ client: getClient(options.timeout),
802
+ })];
803
+ case 1:
804
+ response = _a.apply(void 0, [_b.sent()]);
805
+ return [2 /*return*/, response.uploadedFiles.map(aliasUploadedFileLocale)];
806
+ }
807
+ });
808
+ }); })];
365
809
  case 1:
366
810
  result = _a.sent();
367
811
  return [2 /*return*/, { uploadedFiles: result }];