gt 2.21.1 → 2.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +1 -1
- package/dist/generated/version.js.map +1 -1
- package/dist/utils/api.d.ts +49 -58
- package/dist/utils/api.js +7 -168
- package/dist/utils/api.js.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# gtx-cli
|
|
2
2
|
|
|
3
|
+
## 2.21.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2215](https://github.com/generaltranslation/gt/pull/2215) [`5f5843b`](https://github.com/generaltranslation/gt/commit/5f5843b94066d9ee9c0703722105a189d2a4e3d5) Thanks [@chenxin-yan](https://github.com/chenxin-yan)! - Consolidate base64, file-content, locale-mapping, and job-polling seams in `generaltranslation/internal`, remove the generated API package's workspace dependency surface, and reuse the core helpers in the CLI and Sanity integration. `encodeBase64`, `decodeBase64`, `encodeFileContent`, and `decodeFileContent` are removed from `@generaltranslation/api` (and therefore `generaltranslation/api`); import the `generaltranslation/internal` equivalents instead.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`50098c6`](https://github.com/generaltranslation/gt/commit/50098c68e33b13585dde418e227cfca1cef3bf7e), [`5f5843b`](https://github.com/generaltranslation/gt/commit/5f5843b94066d9ee9c0703722105a189d2a4e3d5)]:
|
|
10
|
+
- generaltranslation@9.4.0
|
|
11
|
+
- @generaltranslation/python-extractor@0.2.50
|
|
12
|
+
- @generaltranslation/supported-locales@2.1.30
|
|
13
|
+
- @generaltranslation/vue-extractor@0.1.10
|
|
14
|
+
|
|
3
15
|
## 2.21.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "2.21.
|
|
1
|
+
export declare const PACKAGE_VERSION = "2.21.2";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/generated/version.ts"],"sourcesContent":["// This file is auto-generated. Do not edit manually.\nexport const PACKAGE_VERSION = '2.21.
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/generated/version.ts"],"sourcesContent":["// This file is auto-generated. Do not edit manually.\nexport const PACKAGE_VERSION = '2.21.2';\n"],"mappings":";AACA,MAAa,kBAAkB"}
|
package/dist/utils/api.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CustomMapping } from '@generaltranslation/format/types';
|
|
2
|
-
import { type ApiClientConfig, type
|
|
2
|
+
import { type ApiClientConfig, type CreateProjectData, type CreateTagData, type GetBranchInfoData, type ProcessFileMovesData, type PublishFilesData, type SubmitUserEditDiffsData } from 'generaltranslation/api';
|
|
3
3
|
export declare function configureApiClient(config: ApiClientConfig & {
|
|
4
4
|
customMapping?: CustomMapping;
|
|
5
5
|
}): void;
|
|
@@ -10,37 +10,6 @@ export declare const api: {
|
|
|
10
10
|
[key: string]: unknown;
|
|
11
11
|
} | null);
|
|
12
12
|
}>;
|
|
13
|
-
createBranch(body: CreateBranchData["body"]): Promise<{
|
|
14
|
-
branch: import("@generaltranslation/api").Branch;
|
|
15
|
-
}>;
|
|
16
|
-
queryFileData(body: GetFileInfoData["body"]): Promise<{
|
|
17
|
-
translatedFiles: {
|
|
18
|
-
locale: string;
|
|
19
|
-
branchId: string;
|
|
20
|
-
fileId: string;
|
|
21
|
-
versionId: string;
|
|
22
|
-
fileFormat: import("@generaltranslation/api").FileFormat;
|
|
23
|
-
dataFormat: string | null;
|
|
24
|
-
createdAt: string;
|
|
25
|
-
updatedAt: string;
|
|
26
|
-
approvedAt: string | null;
|
|
27
|
-
publishedAt: string | null;
|
|
28
|
-
completedAt: string | null;
|
|
29
|
-
}[];
|
|
30
|
-
sourceFiles: {
|
|
31
|
-
sourceLocale: string;
|
|
32
|
-
locales: string[];
|
|
33
|
-
branchId: string;
|
|
34
|
-
fileId: string;
|
|
35
|
-
versionId: string;
|
|
36
|
-
fileName: string;
|
|
37
|
-
fileFormat: import("@generaltranslation/api").FileFormat;
|
|
38
|
-
dataFormat: string | null;
|
|
39
|
-
createdAt: string;
|
|
40
|
-
updatedAt: string;
|
|
41
|
-
publishedAt: string | null;
|
|
42
|
-
}[];
|
|
43
|
-
}>;
|
|
44
13
|
checkJobStatus(jobIds: string[]): Promise<({
|
|
45
14
|
status: "queued";
|
|
46
15
|
jobId: string;
|
|
@@ -68,27 +37,6 @@ export declare const api: {
|
|
|
68
37
|
currentLocales: Array<string>;
|
|
69
38
|
autoApprove: boolean;
|
|
70
39
|
}>;
|
|
71
|
-
resolveAliasLocale(locale: string): string;
|
|
72
|
-
downloadFileBatch(files: DownloadFilesData["body"]): Promise<{
|
|
73
|
-
files: {
|
|
74
|
-
data: string;
|
|
75
|
-
locale?: string;
|
|
76
|
-
id: string;
|
|
77
|
-
branchId: string;
|
|
78
|
-
fileId: string;
|
|
79
|
-
versionId: string;
|
|
80
|
-
fileName?: string;
|
|
81
|
-
metadata: import("@generaltranslation/api").JsonObject;
|
|
82
|
-
fileFormat: import("@generaltranslation/api").FileFormat;
|
|
83
|
-
}[];
|
|
84
|
-
count: number;
|
|
85
|
-
pending: {
|
|
86
|
-
branchId: string;
|
|
87
|
-
fileId: string;
|
|
88
|
-
locale: string;
|
|
89
|
-
versionId: string;
|
|
90
|
-
}[];
|
|
91
|
-
}>;
|
|
92
40
|
publishFiles(files: PublishFilesData["body"]["files"]): Promise<{
|
|
93
41
|
results: Array<{
|
|
94
42
|
fileId: string;
|
|
@@ -143,14 +91,56 @@ export declare const api: {
|
|
|
143
91
|
failed: number;
|
|
144
92
|
};
|
|
145
93
|
}>;
|
|
146
|
-
|
|
94
|
+
resolveAliasLocale(locale: string): string;
|
|
95
|
+
resolveCanonicalLocale(locale: string): string;
|
|
96
|
+
createBranch(body: import("@generaltranslation/api").CreateBranchData["body"]): Promise<{
|
|
97
|
+
branch: import("@generaltranslation/api").Branch;
|
|
98
|
+
}>;
|
|
99
|
+
queryFileData(body: import("@generaltranslation/api").GetFileInfoData["body"]): Promise<{
|
|
100
|
+
translatedFiles: {
|
|
101
|
+
locale: string;
|
|
102
|
+
branchId: string;
|
|
103
|
+
fileId: string;
|
|
104
|
+
versionId: string;
|
|
105
|
+
fileFormat: import("@generaltranslation/api").FileFormat;
|
|
106
|
+
dataFormat: string | null;
|
|
107
|
+
createdAt: string;
|
|
108
|
+
updatedAt: string;
|
|
109
|
+
approvedAt: string | null;
|
|
110
|
+
publishedAt: string | null;
|
|
111
|
+
completedAt: string | null;
|
|
112
|
+
}[];
|
|
113
|
+
sourceFiles: {
|
|
114
|
+
sourceLocale: string;
|
|
115
|
+
locales: string[];
|
|
116
|
+
branchId: string;
|
|
117
|
+
fileId: string;
|
|
118
|
+
versionId: string;
|
|
119
|
+
fileName: string;
|
|
120
|
+
fileFormat: import("@generaltranslation/api").FileFormat;
|
|
121
|
+
dataFormat: string | null;
|
|
122
|
+
createdAt: string;
|
|
123
|
+
updatedAt: string;
|
|
124
|
+
publishedAt: string | null;
|
|
125
|
+
}[];
|
|
126
|
+
}>;
|
|
127
|
+
downloadFileBatch(files: import("@generaltranslation/api").DownloadFilesData["body"]): Promise<{
|
|
128
|
+
files: import("generaltranslation/types").DownloadedFile[];
|
|
129
|
+
count: number;
|
|
130
|
+
pending: {
|
|
131
|
+
branchId: string;
|
|
132
|
+
fileId: string;
|
|
133
|
+
locale: string;
|
|
134
|
+
versionId: string;
|
|
135
|
+
}[];
|
|
136
|
+
}>;
|
|
137
|
+
setupProject(files: import("@generaltranslation/api").GenerateProjectContextData["body"]["files"], options?: Omit<import("@generaltranslation/api").GenerateProjectContextData["body"], "files">): Promise<{
|
|
147
138
|
status: "completed";
|
|
148
139
|
} | {
|
|
149
140
|
setupJobId: string;
|
|
150
141
|
status: "queued";
|
|
151
142
|
}>;
|
|
152
|
-
|
|
153
|
-
enqueueFiles(files: EnqueueFileTranslationsData["body"]["files"], options: {
|
|
143
|
+
enqueueFiles(files: import("@generaltranslation/api").EnqueueFileTranslationsData["body"]["files"], options: {
|
|
154
144
|
sourceLocale?: string;
|
|
155
145
|
targetLocales: string[];
|
|
156
146
|
modelProvider?: string;
|
|
@@ -163,7 +153,7 @@ export declare const api: {
|
|
|
163
153
|
message: string;
|
|
164
154
|
}>;
|
|
165
155
|
uploadSourceFiles(files: Array<{
|
|
166
|
-
source: UploadSourceFilesData["body"]["data"][number]["source"];
|
|
156
|
+
source: import("@generaltranslation/api").UploadSourceFilesData["body"]["data"][number]["source"];
|
|
167
157
|
}>, options: {
|
|
168
158
|
sourceLocale: string;
|
|
169
159
|
}): Promise<{
|
|
@@ -177,7 +167,8 @@ export declare const api: {
|
|
|
177
167
|
locale?: string;
|
|
178
168
|
}[];
|
|
179
169
|
}>;
|
|
180
|
-
|
|
170
|
+
awaitJobs(jobIds: readonly string[], options?: import("@generaltranslation/api").AwaitJobsOptions): Promise<import("@generaltranslation/api").AwaitJobsResult>;
|
|
171
|
+
uploadTranslations(files: import("@generaltranslation/api").UploadTranslationsData["body"]["data"], options: {
|
|
181
172
|
sourceLocale: string;
|
|
182
173
|
}): Promise<{
|
|
183
174
|
uploadedFiles: {
|
package/dist/utils/api.js
CHANGED
|
@@ -1,66 +1,18 @@
|
|
|
1
|
-
import { unwrapApiResult } from "generaltranslation/internal";
|
|
2
|
-
import {
|
|
3
|
-
import { DEFAULT_BATCH_SIZE, createApiClient, createBranch, createProject, createTag, decodeFileContent, downloadFiles, encodeFileContent, enqueueFileTranslations, generateProjectContext, getBranchInfo, getFileInfo, getOrphanedFiles, getProjectInfo, getTranslationJobInfo, pollJobs, processBatches, processFileMoves, publishFiles, submitUserEditDiffs, uploadSourceFiles, uploadTranslations } from "generaltranslation/api";
|
|
1
|
+
import { createGtApiAdapter, unwrapApiResult } from "generaltranslation/internal";
|
|
2
|
+
import { createApiClient, createProject, createTag, getBranchInfo, getOrphanedFiles, getProjectInfo, getTranslationJobInfo, processBatches, processFileMoves, publishFiles, submitUserEditDiffs } from "generaltranslation/api";
|
|
4
3
|
//#region src/utils/api.ts
|
|
5
|
-
|
|
6
|
-
let configuredClientConfig;
|
|
7
|
-
let customMapping;
|
|
8
|
-
function getConfiguredClient() {
|
|
9
|
-
if (!client || !configuredClientConfig) throw new Error("API client not configured — call configureApiClient first");
|
|
10
|
-
return {
|
|
11
|
-
client,
|
|
12
|
-
config: configuredClientConfig
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
function getClient() {
|
|
16
|
-
return getConfiguredClient().client;
|
|
17
|
-
}
|
|
18
|
-
function getClientConfig() {
|
|
19
|
-
return getConfiguredClient().config;
|
|
20
|
-
}
|
|
4
|
+
const { configure: configureSharedApi, getClient, getClientConfig, ...sharedApi } = createGtApiAdapter();
|
|
21
5
|
function configureApiClient(config) {
|
|
22
|
-
|
|
23
|
-
client = createApiClient(clientConfig);
|
|
24
|
-
configuredClientConfig = clientConfig;
|
|
25
|
-
customMapping = mapping;
|
|
6
|
+
configureSharedApi(config);
|
|
26
7
|
}
|
|
27
8
|
const api = {
|
|
9
|
+
...sharedApi,
|
|
28
10
|
async queryBranchData(body) {
|
|
29
11
|
return unwrapApiResult(await getBranchInfo({
|
|
30
12
|
body,
|
|
31
13
|
client: getClient()
|
|
32
14
|
}));
|
|
33
15
|
},
|
|
34
|
-
async createBranch(body) {
|
|
35
|
-
return unwrapApiResult(await createBranch({
|
|
36
|
-
body,
|
|
37
|
-
client: getClient()
|
|
38
|
-
}));
|
|
39
|
-
},
|
|
40
|
-
async queryFileData(body) {
|
|
41
|
-
const result = unwrapApiResult(await getFileInfo({
|
|
42
|
-
body: {
|
|
43
|
-
...body,
|
|
44
|
-
translatedFiles: body.translatedFiles?.map((file) => ({
|
|
45
|
-
...file,
|
|
46
|
-
locale: resolveCanonicalLocale(file.locale, customMapping)
|
|
47
|
-
}))
|
|
48
|
-
},
|
|
49
|
-
client: getClient()
|
|
50
|
-
}));
|
|
51
|
-
return {
|
|
52
|
-
...result,
|
|
53
|
-
translatedFiles: result.translatedFiles.map((file) => ({
|
|
54
|
-
...file,
|
|
55
|
-
locale: resolveAliasLocale(file.locale, customMapping)
|
|
56
|
-
})),
|
|
57
|
-
sourceFiles: result.sourceFiles.map((file) => ({
|
|
58
|
-
...file,
|
|
59
|
-
sourceLocale: resolveAliasLocale(file.sourceLocale, customMapping),
|
|
60
|
-
locales: file.locales.map((locale) => resolveAliasLocale(locale, customMapping))
|
|
61
|
-
}))
|
|
62
|
-
};
|
|
63
|
-
},
|
|
64
16
|
async checkJobStatus(jobIds) {
|
|
65
17
|
return unwrapApiResult(await getTranslationJobInfo({
|
|
66
18
|
body: { jobIds },
|
|
@@ -78,33 +30,6 @@ const api = {
|
|
|
78
30
|
path: { projectId: config.projectId }
|
|
79
31
|
}));
|
|
80
32
|
},
|
|
81
|
-
resolveAliasLocale(locale) {
|
|
82
|
-
return resolveAliasLocale(locale, customMapping);
|
|
83
|
-
},
|
|
84
|
-
async downloadFileBatch(files) {
|
|
85
|
-
if (files.length === 0) return {
|
|
86
|
-
files: [],
|
|
87
|
-
count: 0,
|
|
88
|
-
pending: []
|
|
89
|
-
};
|
|
90
|
-
const request = async (batch) => unwrapApiResult(await downloadFiles({
|
|
91
|
-
body: batch.map((file) => ({
|
|
92
|
-
...file,
|
|
93
|
-
locale: file.locale ? resolveCanonicalLocale(file.locale, customMapping) : void 0
|
|
94
|
-
})),
|
|
95
|
-
client: getClient()
|
|
96
|
-
}));
|
|
97
|
-
const responses = await processBatches(files, async (batch) => [await request(batch)]);
|
|
98
|
-
return {
|
|
99
|
-
files: responses.flatMap((response) => response.files.map((file) => ({
|
|
100
|
-
...file,
|
|
101
|
-
...file.locale && { locale: resolveAliasLocale(file.locale, customMapping) },
|
|
102
|
-
data: decodeFileContent(file.data, file.fileFormat)
|
|
103
|
-
}))),
|
|
104
|
-
count: responses.reduce((count, response) => count + response.count, 0),
|
|
105
|
-
pending: responses.flatMap((response) => response.pending ?? [])
|
|
106
|
-
};
|
|
107
|
-
},
|
|
108
33
|
async publishFiles(files) {
|
|
109
34
|
return unwrapApiResult(await publishFiles({
|
|
110
35
|
body: { files },
|
|
@@ -117,7 +42,7 @@ const api = {
|
|
|
117
42
|
projectId: body.projectId,
|
|
118
43
|
diffs: diffs.map((diff) => ({
|
|
119
44
|
...diff,
|
|
120
|
-
locale: resolveCanonicalLocale(diff.locale
|
|
45
|
+
locale: sharedApi.resolveCanonicalLocale(diff.locale)
|
|
121
46
|
}))
|
|
122
47
|
},
|
|
123
48
|
client: getClient()
|
|
@@ -134,7 +59,7 @@ const api = {
|
|
|
134
59
|
path: { orgId },
|
|
135
60
|
body: {
|
|
136
61
|
...body,
|
|
137
|
-
defaultLocale: resolveCanonicalLocale(body.defaultLocale
|
|
62
|
+
defaultLocale: sharedApi.resolveCanonicalLocale(body.defaultLocale)
|
|
138
63
|
},
|
|
139
64
|
client: getClient()
|
|
140
65
|
}));
|
|
@@ -175,92 +100,6 @@ const api = {
|
|
|
175
100
|
failed: result.length - succeeded
|
|
176
101
|
}
|
|
177
102
|
};
|
|
178
|
-
},
|
|
179
|
-
async setupProject(files, options = {}) {
|
|
180
|
-
return unwrapApiResult(await generateProjectContext({
|
|
181
|
-
body: {
|
|
182
|
-
files: files.map(({ branchId, fileId, versionId }) => ({
|
|
183
|
-
branchId,
|
|
184
|
-
fileId,
|
|
185
|
-
versionId
|
|
186
|
-
})),
|
|
187
|
-
locales: options.locales?.map((locale) => resolveCanonicalLocale(locale, customMapping)),
|
|
188
|
-
force: options.force
|
|
189
|
-
},
|
|
190
|
-
client: getClient()
|
|
191
|
-
}));
|
|
192
|
-
},
|
|
193
|
-
async awaitJobs(jobIds, options) {
|
|
194
|
-
return pollJobs(jobIds, async (pendingJobIds, signal) => unwrapApiResult(await getTranslationJobInfo({
|
|
195
|
-
body: { jobIds: pendingJobIds },
|
|
196
|
-
client: getClient(),
|
|
197
|
-
signal
|
|
198
|
-
})), options);
|
|
199
|
-
},
|
|
200
|
-
async enqueueFiles(files, options) {
|
|
201
|
-
const targetLocales = options.targetLocales.map((locale) => resolveCanonicalLocale(locale, customMapping));
|
|
202
|
-
const result = await processBatches(files, async (batch) => {
|
|
203
|
-
const response = unwrapApiResult(await enqueueFileTranslations({
|
|
204
|
-
body: {
|
|
205
|
-
files: batch.map(({ branchId, fileId, versionId, fileName, transformFormat }) => ({
|
|
206
|
-
branchId,
|
|
207
|
-
fileId,
|
|
208
|
-
versionId,
|
|
209
|
-
fileName,
|
|
210
|
-
transformFormat
|
|
211
|
-
})),
|
|
212
|
-
targetLocales,
|
|
213
|
-
sourceLocale: options.sourceLocale ? resolveCanonicalLocale(options.sourceLocale, customMapping) : void 0,
|
|
214
|
-
modelProvider: options.modelProvider,
|
|
215
|
-
force: options.force
|
|
216
|
-
},
|
|
217
|
-
client: getClient()
|
|
218
|
-
}));
|
|
219
|
-
const jobData = "jobData" in response ? response.jobData : response.data;
|
|
220
|
-
return Object.entries(jobData);
|
|
221
|
-
});
|
|
222
|
-
return {
|
|
223
|
-
jobData: Object.fromEntries(result),
|
|
224
|
-
locales: targetLocales,
|
|
225
|
-
message: `Successfully enqueued ${result.length} file translation jobs in ${Math.ceil(files.length / DEFAULT_BATCH_SIZE)} batch(es)`
|
|
226
|
-
};
|
|
227
|
-
},
|
|
228
|
-
async uploadSourceFiles(files, options) {
|
|
229
|
-
const sourceLocale = resolveCanonicalLocale(options.sourceLocale, customMapping);
|
|
230
|
-
return { uploadedFiles: await processBatches(files, async (batch) => {
|
|
231
|
-
return unwrapApiResult(await uploadSourceFiles({
|
|
232
|
-
body: {
|
|
233
|
-
data: batch.map(({ source }) => ({ source: {
|
|
234
|
-
...source,
|
|
235
|
-
content: encodeFileContent(source.content, source.fileFormat),
|
|
236
|
-
locale: resolveCanonicalLocale(source.locale, customMapping)
|
|
237
|
-
} })),
|
|
238
|
-
sourceLocale
|
|
239
|
-
},
|
|
240
|
-
client: getClient()
|
|
241
|
-
})).uploadedFiles;
|
|
242
|
-
}) };
|
|
243
|
-
},
|
|
244
|
-
async uploadTranslations(files, options) {
|
|
245
|
-
return { uploadedFiles: await processBatches(files, async (batch) => {
|
|
246
|
-
return unwrapApiResult(await uploadTranslations({
|
|
247
|
-
body: {
|
|
248
|
-
data: batch.map(({ source, translations }) => ({
|
|
249
|
-
source: {
|
|
250
|
-
...source,
|
|
251
|
-
content: encodeFileContent(source.content, source.fileFormat)
|
|
252
|
-
},
|
|
253
|
-
translations: translations.map((translation) => ({
|
|
254
|
-
...translation,
|
|
255
|
-
locale: resolveCanonicalLocale(translation.locale, customMapping),
|
|
256
|
-
content: encodeFileContent(translation.content, translation.fileFormat)
|
|
257
|
-
}))
|
|
258
|
-
})),
|
|
259
|
-
sourceLocale: resolveCanonicalLocale(options.sourceLocale, customMapping)
|
|
260
|
-
},
|
|
261
|
-
client: getClient()
|
|
262
|
-
})).uploadedFiles;
|
|
263
|
-
}) };
|
|
264
103
|
}
|
|
265
104
|
};
|
|
266
105
|
//#endregion
|
package/dist/utils/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","names":[],"sources":["../../src/utils/api.ts"],"sourcesContent":["import {\n resolveAliasLocale,\n resolveCanonicalLocale,\n} from '@generaltranslation/format';\nimport type { CustomMapping } from '@generaltranslation/format/types';\nimport {\n createApiClient,\n createBranch,\n createProject,\n createTag,\n decodeFileContent,\n DEFAULT_BATCH_SIZE,\n downloadFiles,\n encodeFileContent,\n enqueueFileTranslations,\n generateProjectContext,\n getBranchInfo,\n getFileInfo,\n getOrphanedFiles,\n getProjectInfo,\n getTranslationJobInfo,\n pollJobs,\n processBatches,\n processFileMoves,\n publishFiles,\n submitUserEditDiffs,\n uploadSourceFiles,\n uploadTranslations,\n type ApiClientConfig,\n type AwaitJobsOptions,\n type CreateBranchData,\n type CreateProjectData,\n type CreateTagData,\n type DownloadFilesData,\n type EnqueueFileTranslationsData,\n type GenerateProjectContextData,\n type GetBranchInfoData,\n type GetFileInfoData,\n type ProcessFileMovesData,\n type PublishFilesData,\n type SubmitUserEditDiffsData,\n type UploadSourceFilesData,\n type UploadTranslationsData,\n} from 'generaltranslation/api';\nimport { unwrapApiResult } from 'generaltranslation/internal';\n\nlet client: ReturnType<typeof createApiClient> | undefined;\nlet configuredClientConfig: ApiClientConfig | undefined;\nlet customMapping: CustomMapping | undefined;\n\nfunction getConfiguredClient(): {\n client: ReturnType<typeof createApiClient>;\n config: ApiClientConfig;\n} {\n if (!client || !configuredClientConfig) {\n throw new Error(\n 'API client not configured — call configureApiClient first'\n );\n }\n return { client, config: configuredClientConfig };\n}\n\nfunction getClient(): ReturnType<typeof createApiClient> {\n return getConfiguredClient().client;\n}\n\nfunction getClientConfig(): ApiClientConfig {\n return getConfiguredClient().config;\n}\n\nexport function configureApiClient(\n config: ApiClientConfig & { customMapping?: CustomMapping }\n): void {\n const { customMapping: mapping, ...clientConfig } = config;\n client = createApiClient(clientConfig);\n // Retain the resolved config for the one project-info call that deliberately\n // uses a shorter timeout than normal translation requests.\n configuredClientConfig = clientConfig;\n customMapping = mapping;\n}\n\nexport const api = {\n async queryBranchData(body: GetBranchInfoData['body']) {\n return unwrapApiResult(await getBranchInfo({ body, client: getClient() }));\n },\n\n async createBranch(body: CreateBranchData['body']) {\n return unwrapApiResult(await createBranch({ body, client: getClient() }));\n },\n\n async queryFileData(body: GetFileInfoData['body']) {\n const result = unwrapApiResult(\n await getFileInfo({\n body: {\n ...body,\n translatedFiles: body.translatedFiles?.map((file) => ({\n ...file,\n locale: resolveCanonicalLocale(file.locale, customMapping),\n })),\n },\n client: getClient(),\n })\n );\n return {\n ...result,\n translatedFiles: result.translatedFiles.map((file) => ({\n ...file,\n locale: resolveAliasLocale(file.locale, customMapping),\n })),\n sourceFiles: result.sourceFiles.map((file) => ({\n ...file,\n sourceLocale: resolveAliasLocale(file.sourceLocale, customMapping),\n locales: file.locales.map((locale) =>\n resolveAliasLocale(locale, customMapping)\n ),\n })),\n };\n },\n\n async checkJobStatus(jobIds: string[]) {\n return unwrapApiResult(\n await getTranslationJobInfo({\n body: { jobIds },\n client: getClient(),\n })\n );\n },\n\n async getProjectInfo(timeoutMs: number) {\n const config = getClientConfig();\n if (!config.projectId) {\n throw new Error('Project ID is required to fetch project information');\n }\n const projectInfoClient = createApiClient({ ...config, timeoutMs });\n return unwrapApiResult(\n await getProjectInfo({\n client: projectInfoClient,\n path: { projectId: config.projectId },\n })\n );\n },\n\n resolveAliasLocale(locale: string) {\n return resolveAliasLocale(locale, customMapping);\n },\n\n async downloadFileBatch(files: DownloadFilesData['body']) {\n if (files.length === 0) return { files: [], count: 0, pending: [] };\n\n const request = async (batch: DownloadFilesData['body']) =>\n unwrapApiResult(\n await downloadFiles({\n body: batch.map((file) => ({\n ...file,\n locale: file.locale\n ? resolveCanonicalLocale(file.locale, customMapping)\n : undefined,\n })),\n client: getClient(),\n })\n );\n const responses = await processBatches(files, async (batch) => [\n await request(batch),\n ]);\n return {\n files: responses.flatMap((response) =>\n response.files.map((file) => ({\n ...file,\n ...(file.locale && {\n locale: resolveAliasLocale(file.locale, customMapping),\n }),\n data: decodeFileContent(file.data, file.fileFormat),\n }))\n ),\n count: responses.reduce((count, response) => count + response.count, 0),\n pending: responses.flatMap((response) => response.pending ?? []),\n };\n },\n\n async publishFiles(files: PublishFilesData['body']['files']) {\n return unwrapApiResult(\n await publishFiles({ body: { files }, client: getClient() })\n );\n },\n\n async submitUserEditDiffs(body: SubmitUserEditDiffsData['body']) {\n return processBatches(body.diffs, async (diffs) => [\n unwrapApiResult(\n await submitUserEditDiffs({\n body: {\n projectId: body.projectId,\n diffs: diffs.map((diff) => ({\n ...diff,\n locale: resolveCanonicalLocale(diff.locale, customMapping),\n })),\n },\n client: getClient(),\n })\n ),\n ]);\n },\n\n async createTag(body: CreateTagData['body']) {\n return unwrapApiResult(await createTag({ body, client: getClient() }));\n },\n\n async createProject(\n orgId: CreateProjectData['path']['orgId'],\n body: CreateProjectData['body']\n ) {\n return unwrapApiResult(\n await createProject({\n path: { orgId },\n body: {\n ...body,\n defaultLocale: resolveCanonicalLocale(\n body.defaultLocale,\n customMapping\n ),\n },\n client: getClient(),\n })\n );\n },\n\n // ponytail: duplicates core/src/translate/getOrphanedFiles.ts batching +\n // intersection; delete one copy when utils/gt.ts is removed.\n async getOrphanedFiles(branchId: string, fileIds: string[]) {\n const request = async (batch: string[]) =>\n unwrapApiResult(\n await getOrphanedFiles({\n body: { branchId, fileIds: batch },\n client: getClient(),\n })\n );\n\n if (fileIds.length === 0) return request([]);\n\n const results = await processBatches(fileIds, async (batch) => [\n await request(batch),\n ]);\n const orphanedFiles = new Map(\n results[0].orphanedFiles.map((file) => [file.fileId, file])\n );\n for (const result of results.slice(1)) {\n const batchFileIds = new Set(\n result.orphanedFiles.map((file) => file.fileId)\n );\n for (const fileId of orphanedFiles.keys()) {\n if (!batchFileIds.has(fileId)) orphanedFiles.delete(fileId);\n }\n }\n return { orphanedFiles: [...orphanedFiles.values()] };\n },\n\n async processFileMoves(\n moves: ProcessFileMovesData['body']['moves'],\n options: Pick<ProcessFileMovesData['body'], 'branchId'>\n ) {\n const result = await processBatches(moves, async (batch) => {\n const response = unwrapApiResult(\n await processFileMoves({\n body: { branchId: options.branchId, moves: batch },\n client: getClient(),\n })\n );\n return response.results;\n });\n const succeeded = result.filter(({ success }) => success).length;\n\n return {\n results: result,\n summary: {\n total: moves.length,\n succeeded,\n failed: result.length - succeeded,\n },\n };\n },\n\n async setupProject(\n files: GenerateProjectContextData['body']['files'],\n options: Omit<GenerateProjectContextData['body'], 'files'> = {}\n ) {\n return unwrapApiResult(\n await generateProjectContext({\n body: {\n files: files.map(({ branchId, fileId, versionId }) => ({\n branchId,\n fileId,\n versionId,\n })),\n locales: options.locales?.map((locale) =>\n resolveCanonicalLocale(locale, customMapping)\n ),\n force: options.force,\n },\n client: getClient(),\n })\n );\n },\n\n async awaitJobs(jobIds: readonly string[], options?: AwaitJobsOptions) {\n // Poll through unwrapApiResult so HTTP failures throw ApiError with the\n // status code instead of the decoded response body.\n return pollJobs(\n jobIds,\n async (pendingJobIds, signal) =>\n unwrapApiResult(\n await getTranslationJobInfo({\n body: { jobIds: pendingJobIds },\n client: getClient(),\n signal,\n })\n ),\n options\n );\n },\n\n async enqueueFiles(\n files: EnqueueFileTranslationsData['body']['files'],\n options: {\n sourceLocale?: string;\n targetLocales: string[];\n modelProvider?: string;\n force?: boolean;\n }\n ) {\n const targetLocales = options.targetLocales.map((locale) =>\n resolveCanonicalLocale(locale, customMapping)\n );\n const result = await processBatches(files, async (batch) => {\n const response = unwrapApiResult(\n await enqueueFileTranslations({\n body: {\n files: batch.map(\n ({ branchId, fileId, versionId, fileName, transformFormat }) => ({\n branchId,\n fileId,\n versionId,\n fileName,\n transformFormat,\n })\n ),\n targetLocales,\n sourceLocale: options.sourceLocale\n ? resolveCanonicalLocale(options.sourceLocale, customMapping)\n : undefined,\n // The CLI intentionally accepts custom model-provider strings beyond\n // the OpenAPI ANTHROPIC|OPENAI|XAI|GOOGLE enum; preserve wire behavior.\n modelProvider:\n options.modelProvider as EnqueueFileTranslationsData['body']['modelProvider'],\n force: options.force,\n },\n client: getClient(),\n })\n );\n const jobData = 'jobData' in response ? response.jobData : response.data;\n return Object.entries(jobData);\n });\n\n return {\n jobData: Object.fromEntries(result),\n locales: targetLocales,\n message: `Successfully enqueued ${result.length} file translation jobs in ${Math.ceil(files.length / DEFAULT_BATCH_SIZE)} batch(es)`,\n };\n },\n\n async uploadSourceFiles(\n files: Array<{\n source: UploadSourceFilesData['body']['data'][number]['source'];\n }>,\n options: { sourceLocale: string }\n ) {\n const sourceLocale = resolveCanonicalLocale(\n options.sourceLocale,\n customMapping\n );\n const result = await processBatches(files, async (batch) => {\n const response = unwrapApiResult(\n await uploadSourceFiles({\n body: {\n data: batch.map(({ source }) => ({\n source: {\n ...source,\n content: encodeFileContent(source.content, source.fileFormat),\n locale: resolveCanonicalLocale(source.locale, customMapping),\n },\n })),\n sourceLocale,\n },\n client: getClient(),\n })\n );\n return response.uploadedFiles;\n });\n\n return { uploadedFiles: result };\n },\n\n async uploadTranslations(\n files: UploadTranslationsData['body']['data'],\n options: { sourceLocale: string }\n ) {\n const result = await processBatches(files, async (batch) => {\n const response = unwrapApiResult(\n await uploadTranslations({\n body: {\n data: batch.map(({ source, translations }) => ({\n source: {\n ...source,\n content: encodeFileContent(source.content, source.fileFormat),\n },\n translations: translations.map((translation) => ({\n ...translation,\n locale: resolveCanonicalLocale(\n translation.locale,\n customMapping\n ),\n content: encodeFileContent(\n translation.content,\n translation.fileFormat\n ),\n })),\n })),\n sourceLocale: resolveCanonicalLocale(\n options.sourceLocale,\n customMapping\n ),\n },\n client: getClient(),\n })\n );\n return response.uploadedFiles;\n });\n\n return { uploadedFiles: result };\n },\n};\n\nexport type ApiClient = typeof api;\n"],"mappings":";;;;AA8CA,IAAI;AACJ,IAAI;AACJ,IAAI;AAEJ,SAAS,sBAGP;AACA,KAAI,CAAC,UAAU,CAAC,uBACd,OAAM,IAAI,MACR,4DACD;AAEH,QAAO;EAAE;EAAQ,QAAQ;EAAwB;;AAGnD,SAAS,YAAgD;AACvD,QAAO,qBAAqB,CAAC;;AAG/B,SAAS,kBAAmC;AAC1C,QAAO,qBAAqB,CAAC;;AAG/B,SAAgB,mBACd,QACM;CACN,MAAM,EAAE,eAAe,SAAS,GAAG,iBAAiB;AACpD,UAAS,gBAAgB,aAAa;AAGtC,0BAAyB;AACzB,iBAAgB;;AAGlB,MAAa,MAAM;CACjB,MAAM,gBAAgB,MAAiC;AACrD,SAAO,gBAAgB,MAAM,cAAc;GAAE;GAAM,QAAQ,WAAW;GAAE,CAAC,CAAC;;CAG5E,MAAM,aAAa,MAAgC;AACjD,SAAO,gBAAgB,MAAM,aAAa;GAAE;GAAM,QAAQ,WAAW;GAAE,CAAC,CAAC;;CAG3E,MAAM,cAAc,MAA+B;EACjD,MAAM,SAAS,gBACb,MAAM,Y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A,SACA;AAiCA,SAAO,EAAE,eAAe,MAhCH,eAAe,OAAO,OAAO,UAAU;AA6B1D,UA5BiB,gBACf,MAAM,mBAAmB;IACvB,MAAM;KACJ,MAAM,MAAM,KAAK,EAAE,QAAQ,oBAAoB;MAC7C,QAAQ;OACN,GAAG;OACH,SAAS,kBAAkB,OAAO,SAAS,OAAO,WAAW;OAC9D;MACD,cAAc,aAAa,KAAK,iBAAiB;OAC/C,GAAG;OACH,QAAQ,uBACN,YAAY,QACZ,cACD;OACD,SAAS,kBACP,YAAY,SACZ,YAAY,WACb;OACF,EAAE;MACJ,EAAE;KACH,cAAc,uBACZ,QAAQ,cACR,cACD;KACF;IACD,QAAQ,WAAW;IACpB,CAAC,CAEW,CAAC;IAChB,EAE8B;;CAEnC"}
|
|
1
|
+
{"version":3,"file":"api.js","names":[],"sources":["../../src/utils/api.ts"],"sourcesContent":["import type { CustomMapping } from '@generaltranslation/format/types';\nimport {\n createApiClient,\n createProject,\n createTag,\n getBranchInfo,\n getOrphanedFiles,\n getProjectInfo,\n getTranslationJobInfo,\n processBatches,\n processFileMoves,\n publishFiles,\n submitUserEditDiffs,\n type ApiClientConfig,\n type CreateProjectData,\n type CreateTagData,\n type GetBranchInfoData,\n type ProcessFileMovesData,\n type PublishFilesData,\n type SubmitUserEditDiffsData,\n} from 'generaltranslation/api';\nimport {\n createGtApiAdapter,\n unwrapApiResult,\n} from 'generaltranslation/internal';\n\nconst {\n configure: configureSharedApi,\n getClient,\n getClientConfig,\n ...sharedApi\n} = createGtApiAdapter();\n\nexport function configureApiClient(\n config: ApiClientConfig & { customMapping?: CustomMapping }\n): void {\n configureSharedApi(config);\n}\n\nexport const api = {\n ...sharedApi,\n async queryBranchData(body: GetBranchInfoData['body']) {\n return unwrapApiResult(await getBranchInfo({ body, client: getClient() }));\n },\n\n async checkJobStatus(jobIds: string[]) {\n return unwrapApiResult(\n await getTranslationJobInfo({\n body: { jobIds },\n client: getClient(),\n })\n );\n },\n\n async getProjectInfo(timeoutMs: number) {\n const config = getClientConfig();\n if (!config.projectId) {\n throw new Error('Project ID is required to fetch project information');\n }\n const projectInfoClient = createApiClient({ ...config, timeoutMs });\n return unwrapApiResult(\n await getProjectInfo({\n client: projectInfoClient,\n path: { projectId: config.projectId },\n })\n );\n },\n\n async publishFiles(files: PublishFilesData['body']['files']) {\n return unwrapApiResult(\n await publishFiles({ body: { files }, client: getClient() })\n );\n },\n\n async submitUserEditDiffs(body: SubmitUserEditDiffsData['body']) {\n return processBatches(body.diffs, async (diffs) => [\n unwrapApiResult(\n await submitUserEditDiffs({\n body: {\n projectId: body.projectId,\n diffs: diffs.map((diff) => ({\n ...diff,\n locale: sharedApi.resolveCanonicalLocale(diff.locale),\n })),\n },\n client: getClient(),\n })\n ),\n ]);\n },\n\n async createTag(body: CreateTagData['body']) {\n return unwrapApiResult(await createTag({ body, client: getClient() }));\n },\n\n async createProject(\n orgId: CreateProjectData['path']['orgId'],\n body: CreateProjectData['body']\n ) {\n return unwrapApiResult(\n await createProject({\n path: { orgId },\n body: {\n ...body,\n defaultLocale: sharedApi.resolveCanonicalLocale(body.defaultLocale),\n },\n client: getClient(),\n })\n );\n },\n\n // ponytail: duplicates core/src/translate/getOrphanedFiles.ts batching +\n // intersection; delete one copy when utils/gt.ts is removed.\n async getOrphanedFiles(branchId: string, fileIds: string[]) {\n const request = async (batch: string[]) =>\n unwrapApiResult(\n await getOrphanedFiles({\n body: { branchId, fileIds: batch },\n client: getClient(),\n })\n );\n\n if (fileIds.length === 0) return request([]);\n\n const results = await processBatches(fileIds, async (batch) => [\n await request(batch),\n ]);\n const orphanedFiles = new Map(\n results[0].orphanedFiles.map((file) => [file.fileId, file])\n );\n for (const result of results.slice(1)) {\n const batchFileIds = new Set(\n result.orphanedFiles.map((file) => file.fileId)\n );\n for (const fileId of orphanedFiles.keys()) {\n if (!batchFileIds.has(fileId)) orphanedFiles.delete(fileId);\n }\n }\n return { orphanedFiles: [...orphanedFiles.values()] };\n },\n\n async processFileMoves(\n moves: ProcessFileMovesData['body']['moves'],\n options: Pick<ProcessFileMovesData['body'], 'branchId'>\n ) {\n const result = await processBatches(moves, async (batch) => {\n const response = unwrapApiResult(\n await processFileMoves({\n body: { branchId: options.branchId, moves: batch },\n client: getClient(),\n })\n );\n return response.results;\n });\n const succeeded = result.filter(({ success }) => success).length;\n\n return {\n results: result,\n summary: {\n total: moves.length,\n succeeded,\n failed: result.length - succeeded,\n },\n };\n },\n};\n\nexport type ApiClient = typeof api;\n"],"mappings":";;;AA0BA,MAAM,EACJ,WAAW,oBACX,WACA,iBACA,GAAG,cACD,oBAAoB;AAExB,SAAgB,mBACd,QACM;AACN,oBAAmB,OAAO;;AAG5B,MAAa,MAAM;CACjB,GAAG;CACH,MAAM,gBAAgB,MAAiC;AACrD,SAAO,gBAAgB,MAAM,cAAc;GAAE;GAAM,QAAQ,WAAW;GAAE,CAAC,CAAC;;CAG5E,MAAM,eAAe,QAAkB;AACrC,SAAO,gBACL,MAAM,sBAAsB;GAC1B,MAAM,EAAE,QAAQ;GAChB,QAAQ,WAAW;GACpB,CAAC,CACH;;CAGH,MAAM,eAAe,WAAmB;EACtC,MAAM,SAAS,iBAAiB;AAChC,MAAI,CAAC,OAAO,UACV,OAAM,IAAI,MAAM,sDAAsD;AAGxE,SAAO,gBACL,MAAM,eAAe;GACnB,QAHsB,gBAAgB;IAAE,GAAG;IAAQ;IAAW,CAGrC;GACzB,MAAM,EAAE,WAAW,OAAO,WAAW;GACtC,CAAC,CACH;;CAGH,MAAM,aAAa,OAA0C;AAC3D,SAAO,gBACL,MAAM,aAAa;GAAE,MAAM,EAAE,OAAO;GAAE,QAAQ,WAAW;GAAE,CAAC,CAC7D;;CAGH,MAAM,oBAAoB,MAAuC;AAC/D,SAAO,eAAe,KAAK,OAAO,OAAO,UAAU,CACjD,gBACE,MAAM,oBAAoB;GACxB,MAAM;IACJ,WAAW,KAAK;IAChB,OAAO,MAAM,KAAK,UAAU;KAC1B,GAAG;KACH,QAAQ,UAA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,WAAW;IACpB,CAAC,CAEW,CAAC;IAChB;EACF,MAAM,YAAY,OAAO,QAAQ,EAAE,cAAc,QAAQ,CAAC;AAE1D,SAAO;GACL,SAAS;GACT,SAAS;IACP,OAAO,MAAM;IACb;IACA,QAAQ,OAAO,SAAS;IACzB;GACF;;CAEJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt",
|
|
3
|
-
"version": "2.21.
|
|
3
|
+
"version": "2.21.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"bin": "bin/main.js",
|
|
6
6
|
"files": [
|
|
@@ -117,10 +117,10 @@
|
|
|
117
117
|
"yaml": "^2.8.0",
|
|
118
118
|
"@generaltranslation/icu": "0.1.2",
|
|
119
119
|
"@generaltranslation/format": "0.1.8",
|
|
120
|
-
"@generaltranslation/python-extractor": "0.2.
|
|
121
|
-
"@generaltranslation/supported-locales": "2.1.
|
|
122
|
-
"@generaltranslation/vue-extractor": "0.1.
|
|
123
|
-
"generaltranslation": "9.
|
|
120
|
+
"@generaltranslation/python-extractor": "0.2.50",
|
|
121
|
+
"@generaltranslation/supported-locales": "2.1.30",
|
|
122
|
+
"@generaltranslation/vue-extractor": "0.1.10",
|
|
123
|
+
"generaltranslation": "9.4.0",
|
|
124
124
|
"gt-remark": "1.0.12"
|
|
125
125
|
},
|
|
126
126
|
"devDependencies": {
|