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.
Files changed (153) hide show
  1. package/CHANGELOG.md +34 -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-Cv5_y8Tf.mjs +656 -0
  12. package/dist/derive-Cv5_y8Tf.mjs.map +1 -0
  13. package/dist/{derive-DBCCXTmL.d.cts → derive-J2NQLqZm.d.cts} +1 -1
  14. package/dist/derive-t_E3ftJN.cjs +733 -0
  15. package/dist/derive-t_E3ftJN.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 +2344 -845
  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/package.json +15 -2
  111. package/dist/derive-2CDqwrvS.cjs +0 -303
  112. package/dist/derive-2CDqwrvS.cjs.map +0 -1
  113. package/dist/derive-CTzR56T_.mjs +0 -233
  114. package/dist/derive-CTzR56T_.mjs.map +0 -1
  115. package/dist/id-X2zyx5Jk.mjs.map +0 -1
  116. package/dist/id-pdr3R1xs.cjs.map +0 -1
  117. package/dist/isVariable-8-Wy5FnX.mjs +0 -20
  118. package/dist/isVariable-8-Wy5FnX.mjs.map +0 -1
  119. package/dist/isVariable-I3nllgeI.cjs +0 -25
  120. package/dist/isVariable-I3nllgeI.cjs.map +0 -1
  121. package/dist/projects/getProjectData.js +0 -87
  122. package/dist/runtime-Bcp4F2ME.mjs +0 -974
  123. package/dist/runtime-Bcp4F2ME.mjs.map +0 -1
  124. package/dist/runtime-C25lwh9m.cjs +0 -1027
  125. package/dist/runtime-C25lwh9m.cjs.map +0 -1
  126. package/dist/translate/api.d.ts +0 -4
  127. package/dist/translate/api.js +0 -4
  128. package/dist/translate/createTag.d.ts +0 -19
  129. package/dist/translate/createTag.js +0 -67
  130. package/dist/translate/downloadFileBatch.d.ts +0 -1
  131. package/dist/translate/downloadFileBatch.js +0 -80
  132. package/dist/translate/getOrphanedFiles.d.ts +0 -8
  133. package/dist/translate/getOrphanedFiles.js +0 -97
  134. package/dist/translate/querySourceFile.d.ts +0 -1
  135. package/dist/translate/querySourceFile.js +0 -67
  136. package/dist/translate/translateMany.d.ts +0 -1
  137. package/dist/translate/translateMany.js +0 -124
  138. package/dist/translate/uploadFonts.d.ts +0 -1
  139. package/dist/translate/uploadFonts.js +0 -74
  140. package/dist/translate/uploadSourceFiles.d.ts +0 -1
  141. package/dist/translate/uploadSourceFiles.js +0 -90
  142. package/dist/translate/uploadTranslations.d.ts +0 -1
  143. package/dist/translate/uploadTranslations.js +0 -106
  144. package/dist/translate/utils/apiRequest.d.ts +0 -1
  145. package/dist/translate/utils/apiRequest.js +0 -167
  146. package/dist/translate/utils/generateRequestHeaders.d.ts +0 -2
  147. package/dist/translate/utils/generateRequestHeaders.js +0 -21
  148. package/dist/translate/utils/handleFetchError.d.ts +0 -1
  149. package/dist/translate/utils/handleFetchError.js +0 -12
  150. package/dist/unwrapApiResult-BzGfPw75.mjs.map +0 -1
  151. package/dist/unwrapApiResult-Dv6Mfw_K.cjs +0 -134
  152. package/dist/unwrapApiResult-Dv6Mfw_K.cjs.map +0 -1
  153. /package/dist/{projects/getProjectData.d.ts → types-dir/__tests__/runtimeTranslate.type-test.d.ts} +0 -0
@@ -1,90 +1 @@
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
- /**
40
- * @internal
41
- * Processes file moves by cloning source files and translations with new fileIds.
42
- * Called when the CLI detects that files have been moved/renamed.
43
- * @param moves - Array of move mappings (old fileId to new fileId)
44
- * @param options - Options including branchId and timeout
45
- * @param config - The configuration for the API call.
46
- * @returns Promise resolving to the move results
47
- */
48
- export function _processFileMoves(moves, options, config) {
49
- return __awaiter(this, void 0, void 0, function () {
50
- var batchResult, succeeded, failed;
51
- var _this = this;
52
- return __generator(this, function (_a) {
53
- switch (_a.label) {
54
- case 0:
55
- if (moves.length === 0) {
56
- return [2 /*return*/, {
57
- results: [],
58
- summary: { total: 0, succeeded: 0, failed: 0 },
59
- }];
60
- }
61
- return [4 /*yield*/, processBatches(moves, function (batch) { return __awaiter(_this, void 0, void 0, function () {
62
- var result;
63
- return __generator(this, function (_a) {
64
- switch (_a.label) {
65
- case 0: return [4 /*yield*/, apiRequest(config, '/v2/project/files/moves', {
66
- body: { branchId: options.branchId, moves: batch },
67
- timeout: options.timeout,
68
- })];
69
- case 1:
70
- result = _a.sent();
71
- return [2 /*return*/, result.results];
72
- }
73
- });
74
- }); }, { batchSize: 100 })];
75
- case 1:
76
- batchResult = _a.sent();
77
- succeeded = batchResult.data.filter(function (r) { return r.success; }).length;
78
- failed = batchResult.data.filter(function (r) { return !r.success; }).length;
79
- return [2 /*return*/, {
80
- results: batchResult.data,
81
- summary: {
82
- total: moves.length,
83
- succeeded: succeeded,
84
- failed: failed,
85
- },
86
- }];
87
- }
88
- });
89
- });
90
- }
1
+ export {};
@@ -1,17 +1,5 @@
1
- export type PublishFileEntry = {
2
- fileId: string;
3
- versionId: string;
4
- branchId?: string;
5
- publish: boolean;
1
+ import type { PublishFilesData, PublishFilesResponse } from '@generaltranslation/api';
2
+ export type PublishFileEntry = PublishFilesData['body']['files'][number] & {
6
3
  fileName?: string;
7
4
  };
8
- export type PublishFilesResult = {
9
- results: {
10
- fileId: string;
11
- versionId: string;
12
- locale?: string;
13
- branchId: string;
14
- success: boolean;
15
- error?: string;
16
- }[];
17
- };
5
+ export type PublishFilesResult = PublishFilesResponse;
@@ -1,56 +1 @@
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
- /**
39
- * @internal
40
- * Publishes or unpublishes files on the CDN.
41
- * @param files - Array of file entries with publish flags
42
- * @param config - The configuration for the API call.
43
- * @returns The result of the API call.
44
- */
45
- export function _publishFiles(files, config) {
46
- return __awaiter(this, void 0, void 0, function () {
47
- return __generator(this, function (_a) {
48
- switch (_a.label) {
49
- case 0: return [4 /*yield*/, apiRequest(config, '/v2/project/files/publish', {
50
- body: { files: files },
51
- })];
52
- case 1: return [2 /*return*/, _a.sent()];
53
- }
54
- });
55
- });
56
- }
1
+ export {};
@@ -1,53 +1 @@
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
- /**
39
- * @internal
40
- * Queries branch information from the API.
41
- * @param query - Object mapping the current branch and incoming branches
42
- * @param config - The configuration for the API call.
43
- * @returns The branch information.
44
- */
45
- export function _queryBranchData(query, config) {
46
- return __awaiter(this, void 0, void 0, function () {
47
- return __generator(this, function (_a) {
48
- return [2 /*return*/, apiRequest(config, '/v2/project/branches/info', {
49
- body: query,
50
- })];
51
- });
52
- });
53
- }
1
+ export {};
@@ -1,41 +1,3 @@
1
- export type FileDataQuery = {
2
- sourceFiles?: {
3
- fileId: string;
4
- versionId: string;
5
- branchId: string;
6
- }[];
7
- translatedFiles?: {
8
- fileId: string;
9
- versionId: string;
10
- branchId: string;
11
- locale: string;
12
- }[];
13
- };
14
- export type FileDataResult = {
15
- sourceFiles?: {
16
- branchId: string;
17
- fileId: string;
18
- versionId: string;
19
- fileName: string;
20
- fileFormat: string;
21
- dataFormat: string | null;
22
- createdAt: string;
23
- updatedAt: string;
24
- publishedAt: string | null;
25
- locales: string[];
26
- sourceLocale: string;
27
- }[];
28
- translatedFiles?: {
29
- branchId: string;
30
- fileId: string;
31
- versionId: string;
32
- fileFormat: string;
33
- dataFormat: string | null;
34
- createdAt: string;
35
- updatedAt: string;
36
- approvedAt: string | null;
37
- publishedAt: string | null;
38
- completedAt: string | null;
39
- locale: string;
40
- }[];
41
- };
1
+ import type { GetFileInfoData, GetFileInfoResponse } from '@generaltranslation/api';
2
+ export type FileDataQuery = GetFileInfoData['body'];
3
+ export type FileDataResult = Partial<GetFileInfoResponse>;
@@ -1,71 +1 @@
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
- /**
39
- * @internal
40
- * Queries data about one or more source or translation files.
41
- * @param data - Object mapping source or translation file information
42
- * @param options - The options for the API call.
43
- * @param config - The configuration for the API call.
44
- * @returns The file data.
45
- */
46
- export function _queryFileData(data_1) {
47
- return __awaiter(this, arguments, void 0, function (data, options, config) {
48
- var body;
49
- var _a, _b;
50
- if (options === void 0) { options = {}; }
51
- return __generator(this, function (_c) {
52
- body = {
53
- sourceFiles: (_a = data.sourceFiles) === null || _a === void 0 ? void 0 : _a.map(function (item) { return ({
54
- fileId: item.fileId,
55
- versionId: item.versionId,
56
- branchId: item.branchId,
57
- }); }),
58
- translatedFiles: (_b = data.translatedFiles) === null || _b === void 0 ? void 0 : _b.map(function (item) { return ({
59
- fileId: item.fileId,
60
- versionId: item.versionId,
61
- branchId: item.branchId,
62
- locale: item.locale,
63
- }); }),
64
- };
65
- return [2 /*return*/, apiRequest(config, '/v2/project/files/info', {
66
- body: body,
67
- timeout: options.timeout,
68
- })];
69
- });
70
- });
71
- }
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { TranslateConfig, TranslateManyResult, TranslationResult } from '../types';
2
+ import type { TranslateManyEntry, TranslateOptions } from '../types-dir/api/entry';
3
+ type TranslateDefaults = Partial<Pick<TranslateOptions, 'sourceLocale' | 'targetLocale'>>;
4
+ export declare function translateMany(sources: Record<string, TranslateManyEntry>, options: string | TranslateOptions, config: TranslateConfig, defaults?: TranslateDefaults): Promise<Record<string, TranslationResult>>;
5
+ export declare function translateMany(sources: TranslateManyEntry[] | Record<string, TranslateManyEntry>, options: string | TranslateOptions, config: TranslateConfig, defaults?: TranslateDefaults): Promise<TranslateManyResult | Record<string, TranslationResult>>;
6
+ export {};
@@ -0,0 +1,297 @@
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
+ 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]];
56
+ }
57
+ return t;
58
+ };
59
+ import { createApiClient, translate as translateEndpoint, } from '@generaltranslation/api';
60
+ import { resolveCanonicalLocale, standardizeLocale, } from '@generaltranslation/format';
61
+ import { libraryDefaultLocale } from '../settings/settings';
62
+ import { defaultRuntimeApiUrl } from '../settings/settingsUrls';
63
+ import { noApiKeyProvidedError, noProjectIdProvidedError, noTargetLocaleProvidedError, } from '../logging/errors';
64
+ import { gtInstanceLogger } from '../logging/logger';
65
+ import { createDiagnosticMessage } from '../logging/diagnostics';
66
+ import { hashSource } from '../id';
67
+ import { isModelProvider, supportedModelProviders, } from '../adapter/modelProvider';
68
+ import { fetchWithTimeout } from './utils/fetchWithTimeout';
69
+ import { hasDecodedError, unwrapApiResult } from './utils/unwrapApiResult';
70
+ import { validateResponse } from './utils/validateResponse';
71
+ /**
72
+ * @internal
73
+ * Credential/provider errors are reported before the project error, and both
74
+ * before any locale validation. GT/GTRuntime share this ordering.
75
+ */
76
+ export function validateAuth(functionName, config) {
77
+ var errors = [];
78
+ if (!config.apiKey && !config.userTokenProvider) {
79
+ errors.push(noApiKeyProvidedError(functionName));
80
+ }
81
+ if (!config.projectId) {
82
+ errors.push(noProjectIdProvidedError(functionName));
83
+ }
84
+ if (errors.length) {
85
+ throw new Error(errors.join('\n'));
86
+ }
87
+ }
88
+ /**
89
+ * @internal
90
+ *
91
+ * Shared preparation for every translation surface (classes and the tooling
92
+ * facade): normalize the string shorthand, validate auth, require a target
93
+ * locale, default the source locale and canonicalize both for the wire.
94
+ *
95
+ * @param defaults - Instance defaults supplied by GT/GTRuntime. Facade calls pass none.
96
+ */
97
+ function prepareTranslation(functionName, options, config, defaults) {
98
+ if (defaults === void 0) { defaults = {}; }
99
+ if (typeof options === 'string') {
100
+ options = { targetLocale: options };
101
+ }
102
+ validateAuth(functionName, config);
103
+ var targetLocale = (options === null || options === void 0 ? void 0 : options.targetLocale) || defaults.targetLocale;
104
+ if (!targetLocale) {
105
+ var error = noTargetLocaleProvidedError(functionName);
106
+ gtInstanceLogger.error(error);
107
+ throw new Error(error);
108
+ }
109
+ var customMapping = config.customMapping, requestConfig = __rest(config, ["customMapping"]);
110
+ // Mapping resolves aliases; standardization also canonicalizes configured
111
+ // spellings such as en-us before they cross the service boundary.
112
+ var resolveServiceLocale = function (locale) {
113
+ return standardizeLocale(resolveCanonicalLocale(locale, customMapping));
114
+ };
115
+ return {
116
+ options: __assign(__assign({}, options), { targetLocale: resolveServiceLocale(targetLocale), sourceLocale: resolveServiceLocale((options === null || options === void 0 ? void 0 : options.sourceLocale) || defaults.sourceLocale || libraryDefaultLocale) }),
117
+ config: requestConfig,
118
+ };
119
+ }
120
+ /**
121
+ * @internal
122
+ * Translates a single entry with explicit configuration and optional locale defaults.
123
+ */
124
+ export function translate(source, options, config, defaults) {
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ var prepared, results;
127
+ return __generator(this, function (_a) {
128
+ switch (_a.label) {
129
+ case 0:
130
+ prepared = prepareTranslation('translate', options, config, defaults);
131
+ return [4 /*yield*/, executeTranslationBatch([source], prepared.options, prepared.config)];
132
+ case 1:
133
+ results = _a.sent();
134
+ return [2 /*return*/, results[0]];
135
+ }
136
+ });
137
+ });
138
+ }
139
+ export function translateMany(sources, options, config, defaults) {
140
+ return __awaiter(this, void 0, void 0, function () {
141
+ var prepared;
142
+ return __generator(this, function (_a) {
143
+ switch (_a.label) {
144
+ case 0:
145
+ prepared = prepareTranslation('translateMany', options, config, defaults);
146
+ return [4 /*yield*/, executeTranslationBatch(sources, prepared.options, prepared.config)];
147
+ case 1: return [2 /*return*/, _a.sent()];
148
+ }
149
+ });
150
+ });
151
+ }
152
+ function isJsonObject(value) {
153
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
154
+ }
155
+ function isGtProp(value) {
156
+ if (!isJsonObject(value))
157
+ return false;
158
+ if (value.t !== undefined && value.t !== 'p' && value.t !== 'b')
159
+ return false;
160
+ if (['pl', 'ti', 'alt', 'arl', 'arb', 'ard'].some(function (key) { return value[key] !== undefined && typeof value[key] !== 'string'; })) {
161
+ return false;
162
+ }
163
+ return (value.b === undefined ||
164
+ (isJsonObject(value.b) && Object.values(value.b).every(isJsxChildren)));
165
+ }
166
+ function isJsxElement(value) {
167
+ if (!isJsonObject(value))
168
+ return false;
169
+ return ((value.t === undefined || typeof value.t === 'string') &&
170
+ (value.i === undefined || typeof value.i === 'number') &&
171
+ (value.d === undefined || isGtProp(value.d)) &&
172
+ (value.c === undefined || isJsxChildren(value.c)));
173
+ }
174
+ function isJsxChild(value) {
175
+ return typeof value === 'string' || isJsxElement(value);
176
+ }
177
+ function isJsxChildren(value) {
178
+ return (value === null ||
179
+ typeof value === 'boolean' ||
180
+ isJsxChild(value) ||
181
+ (Array.isArray(value) && value.every(isJsxChild)));
182
+ }
183
+ // JsonValue is wider than core's format-specific Content union, so narrow each
184
+ // successful translation by dataFormat at the API boundary.
185
+ function toTranslationResult(result) {
186
+ if (!result.success)
187
+ return result;
188
+ if (result.dataFormat === 'JSX' && isJsxChildren(result.translation)) {
189
+ return {
190
+ success: true,
191
+ translation: result.translation,
192
+ dataFormat: result.dataFormat,
193
+ locale: result.locale,
194
+ };
195
+ }
196
+ if (result.dataFormat !== 'JSX' && typeof result.translation === 'string') {
197
+ return {
198
+ success: true,
199
+ translation: result.translation,
200
+ dataFormat: result.dataFormat,
201
+ locale: result.locale,
202
+ };
203
+ }
204
+ return {
205
+ success: false,
206
+ error: 'Invalid translation returned',
207
+ code: 500,
208
+ };
209
+ }
210
+ function executeTranslationBatch(requests, globalMetadata, config) {
211
+ return __awaiter(this, void 0, void 0, function () {
212
+ var isArray, hashOrder, requestsObject, entries, _i, entries_1, _a, key, request, normalized, source, metadata, hash, client, body, result, runtimeResponse, response;
213
+ var _b, _c;
214
+ return __generator(this, function (_d) {
215
+ switch (_d.label) {
216
+ case 0:
217
+ isArray = Array.isArray(requests);
218
+ hashOrder = isArray ? [] : undefined;
219
+ requestsObject = {};
220
+ entries = isArray
221
+ ? requests.map(function (r) { return [undefined, r]; })
222
+ : Object.entries(requests);
223
+ for (_i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
224
+ _a = entries_1[_i], key = _a[0], request = _a[1];
225
+ normalized = typeof request === 'string' ? { source: request } : request;
226
+ source = normalized.source, metadata = normalized.metadata;
227
+ 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' }));
228
+ hashOrder === null || hashOrder === void 0 ? void 0 : hashOrder.push(hash);
229
+ requestsObject[hash] = {
230
+ source: source,
231
+ metadata: metadata,
232
+ };
233
+ }
234
+ if (globalMetadata.modelProvider !== undefined &&
235
+ !isModelProvider(globalMetadata.modelProvider)) {
236
+ throw new Error(createDiagnosticMessage({
237
+ source: 'generaltranslation',
238
+ severity: 'Error',
239
+ whatHappened: 'The configured model provider is not supported',
240
+ details: String(globalMetadata.modelProvider),
241
+ fix: "Use one of: ".concat(supportedModelProviders.join(', ')),
242
+ }));
243
+ }
244
+ client = createApiClient({
245
+ apiKey: config.apiKey,
246
+ apiVersion: config.apiVersion,
247
+ userTokenProvider: config.userTokenProvider,
248
+ baseUrl: config.baseUrl || defaultRuntimeApiUrl,
249
+ fetch: function (input, init) {
250
+ return fetchWithTimeout(input, init !== null && init !== void 0 ? init : {}, config.timeoutMs, config.fetch);
251
+ },
252
+ projectId: config.projectId,
253
+ retryPolicy: 'none',
254
+ timeoutMs: false,
255
+ });
256
+ body = {
257
+ requests: requestsObject,
258
+ targetLocale: globalMetadata.targetLocale,
259
+ sourceLocale: globalMetadata.sourceLocale,
260
+ metadata: __assign(__assign({}, globalMetadata), { modelProvider: globalMetadata.modelProvider }),
261
+ };
262
+ return [4 /*yield*/, translateEndpoint({ body: body, client: client })];
263
+ case 1:
264
+ result = _d.sent();
265
+ if (!(result.data === undefined &&
266
+ result.response &&
267
+ !hasDecodedError(result))) return [3 /*break*/, 3];
268
+ return [4 /*yield*/, validateResponse(result.response)];
269
+ case 2:
270
+ _d.sent();
271
+ throw result.error;
272
+ case 3:
273
+ runtimeResponse = unwrapApiResult(result);
274
+ response = Object.fromEntries(Object.entries(runtimeResponse).map(function (_a) {
275
+ var hash = _a[0], translationResult = _a[1];
276
+ return [
277
+ hash,
278
+ toTranslationResult(translationResult),
279
+ ];
280
+ }));
281
+ // If input was an array, map the record response back to an array in input order
282
+ if (hashOrder) {
283
+ return [2 /*return*/, hashOrder.map(function (hash) {
284
+ var _a;
285
+ return (_a = response[hash]) !== null && _a !== void 0 ? _a : {
286
+ success: false,
287
+ error: 'No translation returned',
288
+ code: 500,
289
+ };
290
+ })];
291
+ }
292
+ // If input was a record, return the record response directly
293
+ return [2 /*return*/, response];
294
+ }
295
+ });
296
+ });
297
+ }
@@ -1,11 +1,7 @@
1
+ import type { GenerateProjectContextResponse } from '@generaltranslation/api';
1
2
  import type { FileReference } from '../types-dir/api/file';
2
3
  export type SetupProjectFileReference = Pick<FileReference, 'branchId' | 'fileId' | 'versionId'>;
3
- export type SetupProjectResult = {
4
- setupJobId: string;
5
- status: 'queued';
6
- } | {
7
- status: 'completed';
8
- };
4
+ export type SetupProjectResult = GenerateProjectContextResponse;
9
5
  export type SetupProjectOptions = {
10
6
  force?: boolean;
11
7
  locales?: string[];