generaltranslation 9.4.2 → 9.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +2 -1
- package/dist/{ApiError-BcjcnTAr.cjs → ApiError-BCjEo_CM.cjs} +1 -1
- package/dist/{ApiError-BcjcnTAr.cjs.map → ApiError-BCjEo_CM.cjs.map} +1 -1
- package/dist/{ApiError-CUKcz3YS.mjs → ApiError-DxWKM0Xt.mjs} +1 -1
- package/dist/{ApiError-CUKcz3YS.mjs.map → ApiError-DxWKM0Xt.mjs.map} +1 -1
- package/dist/adapter/createGtApi.d.ts +196 -27
- package/dist/adapter/createGtApi.js +561 -117
- package/dist/adapter/modelProvider.d.ts +4 -0
- package/dist/adapter/modelProvider.js +6 -0
- package/dist/derive-Cv5_y8Tf.mjs +656 -0
- package/dist/derive-Cv5_y8Tf.mjs.map +1 -0
- package/dist/{derive-DBCCXTmL.d.cts → derive-J2NQLqZm.d.cts} +1 -1
- package/dist/derive-t_E3ftJN.cjs +733 -0
- package/dist/derive-t_E3ftJN.cjs.map +1 -0
- package/dist/diagnostics-CqAHg_Vc.d.cts +34 -0
- package/dist/diagnostics-DKA2SkZB.mjs +45 -0
- package/dist/diagnostics-DKA2SkZB.mjs.map +1 -0
- package/dist/{unwrapApiResult-BzGfPw75.mjs → diagnostics-DKtiPUvo.cjs} +12 -31
- package/dist/diagnostics-DKtiPUvo.cjs.map +1 -0
- package/dist/diagnostics-DYtVjOm5.d.mts +34 -0
- package/dist/diagnostics.cjs +4 -0
- package/dist/diagnostics.d.cts +2 -0
- package/dist/diagnostics.d.mts +2 -0
- package/dist/diagnostics.d.ts +1 -0
- package/dist/diagnostics.js +1 -0
- package/dist/diagnostics.mjs +2 -0
- package/dist/errors.cjs +1 -1
- package/dist/errors.mjs +1 -1
- package/dist/file-B37WkCqM.cjs.map +1 -1
- package/dist/file-Dga6cyM8.mjs.map +1 -1
- package/dist/{id-X2zyx5Jk.mjs → id-B2wA7-S-.mjs} +19 -3
- package/dist/id-B2wA7-S-.mjs.map +1 -0
- package/dist/{id-pdr3R1xs.cjs → id-DJ_59q21.cjs} +25 -3
- package/dist/id-DJ_59q21.cjs.map +1 -0
- package/dist/id.cjs +1 -1
- package/dist/id.d.cts +1 -1
- package/dist/id.d.mts +1 -1
- package/dist/id.mjs +1 -1
- package/dist/index.cjs +94 -753
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -33
- package/dist/index.d.mts +13 -32
- package/dist/index.d.ts +20 -16
- package/dist/index.js +110 -98
- package/dist/index.mjs +88 -746
- package/dist/index.mjs.map +1 -1
- package/dist/internal.cjs +16 -186
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +200 -62
- package/dist/internal.d.mts +199 -61
- package/dist/internal.d.ts +3 -1
- package/dist/internal.js +2 -1
- package/dist/internal.mjs +6 -178
- package/dist/internal.mjs.map +1 -1
- package/dist/logging/errors.d.ts +0 -1
- package/dist/logging/errors.js +0 -6
- package/dist/logging/logger.js +6 -4
- package/dist/openapi.json +2344 -845
- package/dist/runtime.cjs +580 -2
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +12 -6
- package/dist/runtime.d.mts +12 -6
- package/dist/runtime.d.ts +10 -4
- package/dist/runtime.js +10 -65
- package/dist/runtime.mjs +579 -1
- package/dist/runtime.mjs.map +1 -0
- package/dist/runtimeTranslate-CVw143pQ.mjs +506 -0
- package/dist/runtimeTranslate-CVw143pQ.mjs.map +1 -0
- package/dist/runtimeTranslate-DJioRjb6.cjs +601 -0
- package/dist/runtimeTranslate-DJioRjb6.cjs.map +1 -0
- package/dist/translate/awaitJobs.d.ts +2 -2
- package/dist/translate/awaitJobs.js +1 -156
- package/dist/translate/checkJobStatus.d.ts +2 -1
- package/dist/translate/checkJobStatus.js +1 -55
- package/dist/translate/createBranch.d.ts +2 -6
- package/dist/translate/createBranch.js +1 -53
- package/dist/translate/enqueueFiles.js +1 -95
- package/dist/translate/getProjectInfo.d.ts +2 -6
- package/dist/translate/getProjectInfo.js +1 -54
- package/dist/translate/processFileMoves.d.ts +3 -13
- package/dist/translate/processFileMoves.js +1 -90
- package/dist/translate/publishFiles.d.ts +3 -15
- package/dist/translate/publishFiles.js +1 -56
- package/dist/translate/queryBranchData.js +1 -53
- package/dist/translate/queryFileData.d.ts +3 -41
- package/dist/translate/queryFileData.js +1 -71
- package/dist/translate/runtimeTranslate.d.ts +6 -0
- package/dist/translate/runtimeTranslate.js +297 -0
- package/dist/translate/setupProject.d.ts +2 -6
- package/dist/translate/setupProject.js +1 -63
- package/dist/translate/submitUserEditDiffs.js +1 -68
- package/dist/translate/utils/fetchWithTimeout.js +19 -12
- package/dist/{types-bCr8pV1Z.d.cts → types-Si4UstLL.d.mts} +41 -165
- package/dist/types-dir/__tests__/runtimeTranslate.type-test.js +18 -0
- package/dist/types-dir/api/branch.d.ts +3 -9
- package/dist/types-dir/api/checkFileTranslations.d.ts +2 -22
- package/dist/types-dir/api/downloadFileBatch.d.ts +2 -7
- package/dist/types-dir/api/entry.d.ts +3 -8
- package/dist/types-dir/api/file.d.ts +2 -1
- package/dist/types-dir/api/json.d.ts +1 -4
- package/dist/types-dir/api/project.d.ts +2 -7
- package/dist/types-dir/api/uploadAssets.d.ts +3 -10
- package/dist/types-dir/api/uploadAssets.js +0 -4
- package/dist/types-dir/config.d.ts +1 -0
- package/dist/{types-Dp1drjxq.d.mts → types-yByDbKnV.d.cts} +41 -165
- package/dist/types.d.cts +2 -2
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +26 -7
- package/package.json +15 -2
- package/dist/derive-2CDqwrvS.cjs +0 -303
- package/dist/derive-2CDqwrvS.cjs.map +0 -1
- package/dist/derive-CTzR56T_.mjs +0 -233
- package/dist/derive-CTzR56T_.mjs.map +0 -1
- package/dist/id-X2zyx5Jk.mjs.map +0 -1
- package/dist/id-pdr3R1xs.cjs.map +0 -1
- package/dist/isVariable-8-Wy5FnX.mjs +0 -20
- package/dist/isVariable-8-Wy5FnX.mjs.map +0 -1
- package/dist/isVariable-I3nllgeI.cjs +0 -25
- package/dist/isVariable-I3nllgeI.cjs.map +0 -1
- package/dist/projects/getProjectData.js +0 -87
- package/dist/runtime-Bcp4F2ME.mjs +0 -974
- package/dist/runtime-Bcp4F2ME.mjs.map +0 -1
- package/dist/runtime-C25lwh9m.cjs +0 -1027
- package/dist/runtime-C25lwh9m.cjs.map +0 -1
- package/dist/translate/api.d.ts +0 -4
- package/dist/translate/api.js +0 -4
- package/dist/translate/createTag.d.ts +0 -19
- package/dist/translate/createTag.js +0 -67
- package/dist/translate/downloadFileBatch.d.ts +0 -1
- package/dist/translate/downloadFileBatch.js +0 -80
- package/dist/translate/getOrphanedFiles.d.ts +0 -8
- package/dist/translate/getOrphanedFiles.js +0 -97
- package/dist/translate/querySourceFile.d.ts +0 -1
- package/dist/translate/querySourceFile.js +0 -67
- package/dist/translate/translateMany.d.ts +0 -1
- package/dist/translate/translateMany.js +0 -124
- package/dist/translate/uploadFonts.d.ts +0 -1
- package/dist/translate/uploadFonts.js +0 -74
- package/dist/translate/uploadSourceFiles.d.ts +0 -1
- package/dist/translate/uploadSourceFiles.js +0 -90
- package/dist/translate/uploadTranslations.d.ts +0 -1
- package/dist/translate/uploadTranslations.js +0 -106
- package/dist/translate/utils/apiRequest.d.ts +0 -1
- package/dist/translate/utils/apiRequest.js +0 -167
- package/dist/translate/utils/generateRequestHeaders.d.ts +0 -2
- package/dist/translate/utils/generateRequestHeaders.js +0 -21
- package/dist/translate/utils/handleFetchError.d.ts +0 -1
- package/dist/translate/utils/handleFetchError.js +0 -12
- package/dist/unwrapApiResult-BzGfPw75.mjs.map +0 -1
- package/dist/unwrapApiResult-Dv6Mfw_K.cjs +0 -134
- package/dist/unwrapApiResult-Dv6Mfw_K.cjs.map +0 -1
- /package/dist/{projects/getProjectData.d.ts → types-dir/__tests__/runtimeTranslate.type-test.d.ts} +0 -0
package/dist/internal.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as formatDiagnosticErrorDetails, n as DiagnosticSeverity, r as createDiagnosticMessage, t as DiagnosticMessageInput } from "./diagnostics-DYtVjOm5.mjs";
|
|
2
|
+
import { Ft as TranslateManyEntry, It as TranslateOptions, N as VariableTransformationSuffix, O as Variable, Pt as RuntimeTranslateManyOptions, Y as TranslateManyResult, Z as TranslationResult, _ as JsxChildren, ft as DownloadedFile, g as JsxChild, k as VariableType, mt as FileFormat, v as JsxElement, y as LocaleProperties } from "./types-Si4UstLL.mjs";
|
|
2
3
|
import { n as declareVar, r as decodeVars, t as derive } from "./derive-texIAHzc.mjs";
|
|
3
4
|
import * as _$_generaltranslation_api0 from "@generaltranslation/api";
|
|
4
|
-
import { API_VERSION, ApiClientConfig, AwaitJobsOptions, CreateBranchData, DownloadFilesData, EnqueueFileTranslationsData, GenerateProjectContextData, GetFileInfoData, UploadSourceFilesData, UploadTranslationsData, createApiClient } from "@generaltranslation/api";
|
|
5
|
+
import { API_VERSION, ApiClientConfig, AwaitJobsOptions, CreateBranchData, CreateProjectApiKeyData, CreateProjectData, CreateTagData, DownloadFilesData, EnqueueFileTranslationsData, GenerateProjectContextData, GetBranchInfoData, GetFileInfoData, GetTranslationJobInfoResponse, GetTranslationStatusData, ModelProvider, ProcessFileMovesData, PublishFilesData, SubmitUserEditDiffsData, UploadAssetsData, UploadSourceFilesData, UploadTranslationsData, createApiClient } from "@generaltranslation/api";
|
|
5
6
|
import { CustomMapping, IcuMessage } from "@generaltranslation/format/types";
|
|
6
7
|
|
|
7
8
|
//#region src/settings/settingsUrls.d.ts
|
|
@@ -9,38 +10,6 @@ declare const defaultCacheUrl: "https://cdn.gtx.dev";
|
|
|
9
10
|
declare const defaultBaseUrl: "https://api.gtx.dev";
|
|
10
11
|
declare const defaultRuntimeApiUrl: "https://api.gtx.dev";
|
|
11
12
|
//#endregion
|
|
12
|
-
//#region src/logging/diagnostics.d.ts
|
|
13
|
-
type DiagnosticSeverity = 'Error' | 'Warning';
|
|
14
|
-
/**
|
|
15
|
-
* Text slots follow the five-part error message model:
|
|
16
|
-
* what happened, reassurance, why it happened, how to fix it, and a way out.
|
|
17
|
-
* Clauses that are combined into another sentence should use their intended
|
|
18
|
-
* in-sentence casing.
|
|
19
|
-
*/
|
|
20
|
-
type DiagnosticMessageInput = {
|
|
21
|
-
source?: string;
|
|
22
|
-
severity?: DiagnosticSeverity;
|
|
23
|
-
whatHappened: string;
|
|
24
|
-
reassurance?: string;
|
|
25
|
-
why?: string;
|
|
26
|
-
fix?: string;
|
|
27
|
-
wayOut?: string;
|
|
28
|
-
details?: string | string[];
|
|
29
|
-
docsUrl?: string;
|
|
30
|
-
};
|
|
31
|
-
declare function formatDiagnosticErrorDetails(error: unknown): string | undefined;
|
|
32
|
-
declare function createDiagnosticMessage({
|
|
33
|
-
source,
|
|
34
|
-
severity,
|
|
35
|
-
whatHappened,
|
|
36
|
-
reassurance,
|
|
37
|
-
why,
|
|
38
|
-
fix,
|
|
39
|
-
wayOut,
|
|
40
|
-
details,
|
|
41
|
-
docsUrl
|
|
42
|
-
}: DiagnosticMessageInput): string;
|
|
43
|
-
//#endregion
|
|
44
13
|
//#region src/settings/settings.d.ts
|
|
45
14
|
declare const libraryDefaultLocale: "en";
|
|
46
15
|
//#endregion
|
|
@@ -98,16 +67,163 @@ declare function unwrapApiResult<T>(result: {
|
|
|
98
67
|
type GtApiAdapterConfig = ApiClientConfig & {
|
|
99
68
|
customMapping?: CustomMapping;
|
|
100
69
|
};
|
|
101
|
-
declare function createGtApiAdapter(defaultConfig?:
|
|
102
|
-
configure: (
|
|
103
|
-
getClient: () => ReturnType<typeof createApiClient>;
|
|
104
|
-
getClientConfig: () => ApiClientConfig;
|
|
70
|
+
declare function createGtApiAdapter(defaultConfig?: GtApiAdapterConfig): {
|
|
71
|
+
configure: (nextConfig: GtApiAdapterConfig) => void;
|
|
72
|
+
getClient: (timeoutMs?: number) => ReturnType<typeof createApiClient>;
|
|
105
73
|
resolveAliasLocale(locale: string): string;
|
|
106
74
|
resolveCanonicalLocale(locale: string): string;
|
|
75
|
+
translate: (source: TranslateManyEntry, options: string | TranslateOptions, timeoutMs?: number | false) => Promise<TranslationResult>;
|
|
76
|
+
translateMany: {
|
|
77
|
+
(sources: TranslateManyEntry[], options: string | TranslateOptions, timeoutMs?: number | false): Promise<TranslateManyResult>;
|
|
78
|
+
(sources: Record<string, TranslateManyEntry>, options: string | TranslateOptions, timeoutMs?: number | false): Promise<Record<string, TranslationResult>>;
|
|
79
|
+
};
|
|
80
|
+
queryBranchData(body: GetBranchInfoData["body"]): Promise<{
|
|
81
|
+
branches: Array<_$_generaltranslation_api0.Branch>;
|
|
82
|
+
defaultBranch: _$_generaltranslation_api0.Branch & ({
|
|
83
|
+
[key: string]: unknown;
|
|
84
|
+
} | null);
|
|
85
|
+
}>;
|
|
107
86
|
createBranch(body: CreateBranchData["body"]): Promise<{
|
|
108
87
|
branch: _$_generaltranslation_api0.Branch;
|
|
109
88
|
}>;
|
|
110
|
-
|
|
89
|
+
processFileMoves(moves: ProcessFileMovesData["body"]["moves"], options?: Pick<ProcessFileMovesData["body"], "branchId"> & {
|
|
90
|
+
timeout?: number;
|
|
91
|
+
}): Promise<{
|
|
92
|
+
results: {
|
|
93
|
+
oldFileId: string;
|
|
94
|
+
newFileId: string;
|
|
95
|
+
success: boolean;
|
|
96
|
+
newSourceFileId?: string;
|
|
97
|
+
clonedTranslationsCount?: number;
|
|
98
|
+
error?: string;
|
|
99
|
+
}[];
|
|
100
|
+
summary: {
|
|
101
|
+
total: number;
|
|
102
|
+
succeeded: number;
|
|
103
|
+
failed: number;
|
|
104
|
+
};
|
|
105
|
+
}>;
|
|
106
|
+
getOrphanedFiles(branchId: string, fileIds: string[], options?: {
|
|
107
|
+
timeout?: number;
|
|
108
|
+
}): Promise<{
|
|
109
|
+
orphanedFiles: Array<{
|
|
110
|
+
fileId: string;
|
|
111
|
+
versionId: string;
|
|
112
|
+
fileName: string;
|
|
113
|
+
}>;
|
|
114
|
+
}>;
|
|
115
|
+
setupProject(files: GenerateProjectContextData["body"]["files"], options?: Omit<GenerateProjectContextData["body"], "files"> & {
|
|
116
|
+
timeoutMs?: number;
|
|
117
|
+
}): Promise<{
|
|
118
|
+
status: "completed";
|
|
119
|
+
} | {
|
|
120
|
+
setupJobId: string;
|
|
121
|
+
status: "queued";
|
|
122
|
+
}>;
|
|
123
|
+
loadJobStatuses: (jobIds: readonly string[], options?: {
|
|
124
|
+
signal?: AbortSignal;
|
|
125
|
+
timeoutMs?: number;
|
|
126
|
+
}) => Promise<GetTranslationJobInfoResponse>;
|
|
127
|
+
checkJobStatus(jobIds: string[], timeoutMs?: number): Promise<{
|
|
128
|
+
jobId: string;
|
|
129
|
+
status: GetTranslationJobInfoResponse[number]["status"];
|
|
130
|
+
error?: {
|
|
131
|
+
message: string;
|
|
132
|
+
};
|
|
133
|
+
}[]>;
|
|
134
|
+
awaitJobs(jobIds: readonly string[], options?: AwaitJobsOptions): Promise<{
|
|
135
|
+
jobs: {
|
|
136
|
+
jobId: string;
|
|
137
|
+
status: GetTranslationJobInfoResponse[number]["status"];
|
|
138
|
+
error?: {
|
|
139
|
+
message: string;
|
|
140
|
+
};
|
|
141
|
+
}[];
|
|
142
|
+
complete: boolean;
|
|
143
|
+
}>;
|
|
144
|
+
enqueueFiles(files: EnqueueFileTranslationsData["body"]["files"], options: {
|
|
145
|
+
sourceLocale?: string;
|
|
146
|
+
targetLocales: string[];
|
|
147
|
+
modelProvider?: string;
|
|
148
|
+
force?: boolean;
|
|
149
|
+
timeout?: number;
|
|
150
|
+
}): Promise<{
|
|
151
|
+
jobData: {
|
|
152
|
+
[k: string]: any;
|
|
153
|
+
};
|
|
154
|
+
locales: string[];
|
|
155
|
+
message: string;
|
|
156
|
+
}>;
|
|
157
|
+
createTag(body: CreateTagData["body"]): Promise<{
|
|
158
|
+
tag: {
|
|
159
|
+
id: string;
|
|
160
|
+
tagId: string;
|
|
161
|
+
message: string | null;
|
|
162
|
+
createdAt: string;
|
|
163
|
+
updatedAt: string;
|
|
164
|
+
};
|
|
165
|
+
}>;
|
|
166
|
+
publishFiles(files: PublishFilesData["body"]["files"]): Promise<{
|
|
167
|
+
results: Array<{
|
|
168
|
+
fileId: string;
|
|
169
|
+
versionId: string;
|
|
170
|
+
locale?: string;
|
|
171
|
+
branchId: string;
|
|
172
|
+
success: boolean;
|
|
173
|
+
error?: string;
|
|
174
|
+
}>;
|
|
175
|
+
}>;
|
|
176
|
+
submitUserEditDiffs(body: SubmitUserEditDiffsData["body"], options?: {
|
|
177
|
+
timeout?: number;
|
|
178
|
+
}): Promise<{
|
|
179
|
+
filesProcessed: number;
|
|
180
|
+
entriesReceived: number;
|
|
181
|
+
message: string;
|
|
182
|
+
}[]>;
|
|
183
|
+
createProject(orgId: CreateProjectData["path"]["orgId"], body: CreateProjectData["body"]): Promise<{
|
|
184
|
+
project: {
|
|
185
|
+
id: string;
|
|
186
|
+
name: string;
|
|
187
|
+
orgId: string;
|
|
188
|
+
defaultLocale: string;
|
|
189
|
+
};
|
|
190
|
+
}>; /** Every project the configured credentials can read. */
|
|
191
|
+
listProjects(): Promise<{
|
|
192
|
+
id: string;
|
|
193
|
+
name: string;
|
|
194
|
+
orgId: string;
|
|
195
|
+
orgName: string;
|
|
196
|
+
}[]>; /** Organizations where the signed-in user can create projects; user tokens only. */
|
|
197
|
+
listOrgs(): Promise<{
|
|
198
|
+
id: string;
|
|
199
|
+
name: string;
|
|
200
|
+
}[]>;
|
|
201
|
+
createProjectApiKey(projectId: CreateProjectApiKeyData["path"]["projectId"], body: CreateProjectApiKeyData["body"]): Promise<{
|
|
202
|
+
apiKey: {
|
|
203
|
+
id: string;
|
|
204
|
+
name: string;
|
|
205
|
+
key: string;
|
|
206
|
+
projectId: string;
|
|
207
|
+
type: "production";
|
|
208
|
+
};
|
|
209
|
+
}>;
|
|
210
|
+
loadProjectInfo: (projectId?: string, timeoutMs?: number) => Promise<{
|
|
211
|
+
id: string;
|
|
212
|
+
name: string;
|
|
213
|
+
orgId: string;
|
|
214
|
+
defaultLocale: string;
|
|
215
|
+
currentLocales: Array<string>;
|
|
216
|
+
autoApprove: boolean;
|
|
217
|
+
}>;
|
|
218
|
+
getProjectInfo(projectId?: string, timeoutMs?: number): Promise<{
|
|
219
|
+
defaultLocale: string;
|
|
220
|
+
currentLocales: string[];
|
|
221
|
+
id: string;
|
|
222
|
+
name: string;
|
|
223
|
+
orgId: string;
|
|
224
|
+
autoApprove: boolean;
|
|
225
|
+
}>;
|
|
226
|
+
queryFileData(body: GetFileInfoData["body"], timeoutMs?: number): Promise<{
|
|
111
227
|
translatedFiles: {
|
|
112
228
|
locale: string;
|
|
113
229
|
branchId: string;
|
|
@@ -135,38 +251,46 @@ declare function createGtApiAdapter(defaultConfig?: ApiClientConfig): {
|
|
|
135
251
|
publishedAt: string | null;
|
|
136
252
|
}[];
|
|
137
253
|
}>;
|
|
138
|
-
|
|
254
|
+
querySourceFile(path: GetTranslationStatusData["path"], query?: GetTranslationStatusData["query"], timeoutMs?: number): Promise<{
|
|
255
|
+
translations: {
|
|
256
|
+
locale: string;
|
|
257
|
+
completedAt: string | null;
|
|
258
|
+
approvedAt: string | null;
|
|
259
|
+
publishedAt: string | null;
|
|
260
|
+
createdAt: string | null;
|
|
261
|
+
updatedAt: string | null;
|
|
262
|
+
}[];
|
|
263
|
+
sourceFile: {
|
|
264
|
+
sourceLocale: string;
|
|
265
|
+
locales: string[];
|
|
266
|
+
id: string;
|
|
267
|
+
branchId: string;
|
|
268
|
+
fileId: string;
|
|
269
|
+
versionId: string;
|
|
270
|
+
fileName: string;
|
|
271
|
+
fileFormat: _$_generaltranslation_api0.FileFormat;
|
|
272
|
+
dataFormat: string | null;
|
|
273
|
+
createdAt: string;
|
|
274
|
+
updatedAt: string;
|
|
275
|
+
};
|
|
276
|
+
}>;
|
|
277
|
+
downloadFileBatch(files: DownloadFilesData["body"], options?: {
|
|
278
|
+
timeout?: number;
|
|
279
|
+
}): Promise<{
|
|
139
280
|
files: DownloadedFile[];
|
|
140
281
|
count: number;
|
|
141
282
|
pending: {
|
|
283
|
+
locale: string;
|
|
142
284
|
branchId: string;
|
|
143
285
|
fileId: string;
|
|
144
|
-
locale: string;
|
|
145
286
|
versionId: string;
|
|
146
287
|
}[];
|
|
147
288
|
}>;
|
|
148
|
-
setupProject(files: GenerateProjectContextData["body"]["files"], options?: Omit<GenerateProjectContextData["body"], "files">): Promise<{
|
|
149
|
-
status: "completed";
|
|
150
|
-
} | {
|
|
151
|
-
setupJobId: string;
|
|
152
|
-
status: "queued";
|
|
153
|
-
}>;
|
|
154
|
-
enqueueFiles(files: EnqueueFileTranslationsData["body"]["files"], options: {
|
|
155
|
-
sourceLocale?: string;
|
|
156
|
-
targetLocales: string[];
|
|
157
|
-
modelProvider?: string;
|
|
158
|
-
force?: boolean;
|
|
159
|
-
}): Promise<{
|
|
160
|
-
jobData: {
|
|
161
|
-
[k: string]: any;
|
|
162
|
-
};
|
|
163
|
-
locales: string[];
|
|
164
|
-
message: string;
|
|
165
|
-
}>;
|
|
166
289
|
uploadSourceFiles(files: Array<{
|
|
167
290
|
source: UploadSourceFilesData["body"]["data"][number]["source"];
|
|
168
291
|
}>, options: {
|
|
169
292
|
sourceLocale: string;
|
|
293
|
+
timeout?: number;
|
|
170
294
|
}): Promise<{
|
|
171
295
|
uploadedFiles: {
|
|
172
296
|
branchId: string;
|
|
@@ -178,9 +302,19 @@ declare function createGtApiAdapter(defaultConfig?: ApiClientConfig): {
|
|
|
178
302
|
locale?: string;
|
|
179
303
|
}[];
|
|
180
304
|
}>;
|
|
181
|
-
|
|
305
|
+
uploadFonts(fonts: UploadAssetsData["body"]["assets"], options?: {
|
|
306
|
+
timeout?: number;
|
|
307
|
+
}): Promise<{
|
|
308
|
+
assets: {
|
|
309
|
+
id: string;
|
|
310
|
+
assetKey: string;
|
|
311
|
+
fileName: string;
|
|
312
|
+
}[];
|
|
313
|
+
count: number;
|
|
314
|
+
}>;
|
|
182
315
|
uploadTranslations(files: UploadTranslationsData["body"]["data"], options: {
|
|
183
316
|
sourceLocale: string;
|
|
317
|
+
timeout?: number;
|
|
184
318
|
}): Promise<{
|
|
185
319
|
uploadedFiles: {
|
|
186
320
|
branchId: string;
|
|
@@ -195,6 +329,10 @@ declare function createGtApiAdapter(defaultConfig?: ApiClientConfig): {
|
|
|
195
329
|
};
|
|
196
330
|
type GtApiAdapter = ReturnType<typeof createGtApiAdapter>;
|
|
197
331
|
//#endregion
|
|
332
|
+
//#region src/adapter/modelProvider.d.ts
|
|
333
|
+
declare const supportedModelProviders: ("ANTHROPIC" | "OPENAI" | "XAI" | "GOOGLE")[];
|
|
334
|
+
declare function isModelProvider(value: unknown): value is ModelProvider;
|
|
335
|
+
//#endregion
|
|
198
336
|
//#region src/derive/indexVars.d.ts
|
|
199
337
|
/**
|
|
200
338
|
* Given an ICU string adds identifiers to each _gt_ placeholder
|
|
@@ -227,5 +365,5 @@ declare function condenseVars(icuString: string): string;
|
|
|
227
365
|
//#region src/derive/utils/constants.d.ts
|
|
228
366
|
declare const VAR_IDENTIFIER = "_gt_";
|
|
229
367
|
//#endregion
|
|
230
|
-
export { API_VERSION, type DiagnosticMessageInput, type DiagnosticSeverity, type GtApiAdapter, type GtApiAdapterConfig, type JsxChild, type JsxChildren, type JsxElement, type LocaleProperties, type RuntimeTranslateManyOptions, VAR_IDENTIFIER, condenseVars, createDiagnosticMessage, createGtApiAdapter, declareVar, decode, decodeFileContent, decodeVars, defaultBaseUrl, defaultCacheUrl, defaultRuntimeApiUrl, derive, encode, encodeFileContent, extractVars, formatDiagnosticErrorDetails, _getPluralForm as getPluralForm, indexVars, isAcceptedPluralForm, isErrorResult, isSupportedFileFormatTransform, isVariable, libraryDefaultLocale, minifyVariableType, pluralForms, unwrapApiResult };
|
|
368
|
+
export { API_VERSION, type DiagnosticMessageInput, type DiagnosticSeverity, type GtApiAdapter, type GtApiAdapterConfig, type JsxChild, type JsxChildren, type JsxElement, type LocaleProperties, type ModelProvider, type RuntimeTranslateManyOptions, VAR_IDENTIFIER, condenseVars, createDiagnosticMessage, createGtApiAdapter, declareVar, decode, decodeFileContent, decodeVars, defaultBaseUrl, defaultCacheUrl, defaultRuntimeApiUrl, derive, encode, encodeFileContent, extractVars, formatDiagnosticErrorDetails, _getPluralForm as getPluralForm, indexVars, isAcceptedPluralForm, isErrorResult, isModelProvider, isSupportedFileFormatTransform, isVariable, libraryDefaultLocale, minifyVariableType, pluralForms, supportedModelProviders, unwrapApiResult };
|
|
231
369
|
//# sourceMappingURL=internal.d.mts.map
|
package/dist/internal.d.ts
CHANGED
|
@@ -10,10 +10,12 @@ export { isVariable } from './utils/isVariable';
|
|
|
10
10
|
export { minifyVariableType } from './utils/minify';
|
|
11
11
|
export { decode, decodeFileContent, encode, encodeFileContent, } from './utils/base64';
|
|
12
12
|
export { isSupportedFileFormatTransform } from './utils/isSupportedFileFormatTransform';
|
|
13
|
-
export { API_VERSION } from '
|
|
13
|
+
export { API_VERSION } from '@generaltranslation/api';
|
|
14
14
|
export { isErrorResult, unwrapApiResult, } from './translate/utils/unwrapApiResult';
|
|
15
15
|
export { createGtApiAdapter } from './adapter/createGtApi';
|
|
16
16
|
export type { GtApiAdapter, GtApiAdapterConfig } from './adapter/createGtApi';
|
|
17
|
+
export { isModelProvider, supportedModelProviders, } from './adapter/modelProvider';
|
|
18
|
+
export type { ModelProvider } from './adapter/modelProvider';
|
|
17
19
|
export { decodeVars } from './derive/decodeVars';
|
|
18
20
|
export { declareVar } from './derive/declareVar';
|
|
19
21
|
export { derive } from './derive/derive';
|
package/dist/internal.js
CHANGED
|
@@ -7,9 +7,10 @@ export { isVariable } from './utils/isVariable';
|
|
|
7
7
|
export { minifyVariableType } from './utils/minify';
|
|
8
8
|
export { decode, decodeFileContent, encode, encodeFileContent, } from './utils/base64';
|
|
9
9
|
export { isSupportedFileFormatTransform } from './utils/isSupportedFileFormatTransform';
|
|
10
|
-
export { API_VERSION } from '
|
|
10
|
+
export { API_VERSION } from '@generaltranslation/api';
|
|
11
11
|
export { isErrorResult, unwrapApiResult, } from './translate/utils/unwrapApiResult';
|
|
12
12
|
export { createGtApiAdapter } from './adapter/createGtApi';
|
|
13
|
+
export { isModelProvider, supportedModelProviders, } from './adapter/modelProvider';
|
|
13
14
|
// derive
|
|
14
15
|
export { decodeVars } from './derive/decodeVars';
|
|
15
16
|
export { declareVar } from './derive/declareVar';
|
package/dist/internal.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { a as unwrapApiResult, g as libraryDefaultLocale, h as defaultRuntimeApiUrl, i as isErrorResult, m as defaultCacheUrl, o as isModelProvider, p as defaultBaseUrl, s as supportedModelProviders } from "./runtimeTranslate-CVw143pQ.mjs";
|
|
2
|
+
import { n as formatDiagnosticErrorDetails, t as createDiagnosticMessage } from "./diagnostics-DKA2SkZB.mjs";
|
|
3
|
+
import { r as isVariable } from "./id-B2wA7-S-.mjs";
|
|
4
|
+
import { a as isGTUnindexedSelectElement, c as createGtApiAdapter, d as decodeFileContent, f as encode, i as isGTIndexedSelectElement, l as isSupportedFileFormatTransform, n as declareVar, o as VAR_IDENTIFIER, p as encodeFileContent, r as decodeVars, s as traverseIcu, t as derive, u as decode } from "./derive-Cv5_y8Tf.mjs";
|
|
5
|
+
import { API_VERSION } from "@generaltranslation/api";
|
|
6
6
|
import { TYPE, printAST } from "@generaltranslation/icu";
|
|
7
7
|
import { getCachedPluralRules } from "@generaltranslation/format/internal";
|
|
8
8
|
//#region src/settings/plurals.ts
|
|
@@ -61,178 +61,6 @@ function minifyVariableType(variableType) {
|
|
|
61
61
|
return VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES[variableType];
|
|
62
62
|
}
|
|
63
63
|
//#endregion
|
|
64
|
-
//#region src/adapter/createGtApi.ts
|
|
65
|
-
function createGtApiAdapter(defaultConfig) {
|
|
66
|
-
let client = defaultConfig ? createApiClient(defaultConfig) : void 0;
|
|
67
|
-
let configuredClientConfig = defaultConfig;
|
|
68
|
-
let customMapping;
|
|
69
|
-
function resolveServiceLocale(locale) {
|
|
70
|
-
return standardizeLocale(resolveCanonicalLocale(locale, customMapping));
|
|
71
|
-
}
|
|
72
|
-
function getClient() {
|
|
73
|
-
if (!client) throw new Error("API client not configured — call configureApiClient first");
|
|
74
|
-
return client;
|
|
75
|
-
}
|
|
76
|
-
function getClientConfig() {
|
|
77
|
-
if (!configuredClientConfig) throw new Error("API client not configured — call configureApiClient first");
|
|
78
|
-
return configuredClientConfig;
|
|
79
|
-
}
|
|
80
|
-
function configure(config) {
|
|
81
|
-
const { customMapping: mapping, ...clientConfig } = config;
|
|
82
|
-
client = createApiClient(clientConfig);
|
|
83
|
-
configuredClientConfig = clientConfig;
|
|
84
|
-
customMapping = mapping;
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
configure,
|
|
88
|
-
getClient,
|
|
89
|
-
getClientConfig,
|
|
90
|
-
resolveAliasLocale(locale) {
|
|
91
|
-
return resolveAliasLocale(locale, customMapping);
|
|
92
|
-
},
|
|
93
|
-
resolveCanonicalLocale(locale) {
|
|
94
|
-
return resolveServiceLocale(locale);
|
|
95
|
-
},
|
|
96
|
-
async createBranch(body) {
|
|
97
|
-
return unwrapApiResult(await createBranch({
|
|
98
|
-
body,
|
|
99
|
-
client: getClient()
|
|
100
|
-
}));
|
|
101
|
-
},
|
|
102
|
-
async queryFileData(body) {
|
|
103
|
-
const result = unwrapApiResult(await getFileInfo({
|
|
104
|
-
body: {
|
|
105
|
-
...body,
|
|
106
|
-
translatedFiles: body.translatedFiles?.map((file) => ({
|
|
107
|
-
...file,
|
|
108
|
-
locale: resolveServiceLocale(file.locale)
|
|
109
|
-
}))
|
|
110
|
-
},
|
|
111
|
-
client: getClient()
|
|
112
|
-
}));
|
|
113
|
-
return {
|
|
114
|
-
...result,
|
|
115
|
-
translatedFiles: result.translatedFiles.map((file) => ({
|
|
116
|
-
...file,
|
|
117
|
-
locale: resolveAliasLocale(file.locale, customMapping)
|
|
118
|
-
})),
|
|
119
|
-
sourceFiles: result.sourceFiles.map((file) => ({
|
|
120
|
-
...file,
|
|
121
|
-
sourceLocale: resolveAliasLocale(file.sourceLocale, customMapping),
|
|
122
|
-
locales: file.locales.map((locale) => resolveAliasLocale(locale, customMapping))
|
|
123
|
-
}))
|
|
124
|
-
};
|
|
125
|
-
},
|
|
126
|
-
async downloadFileBatch(files) {
|
|
127
|
-
const request = async (batch) => unwrapApiResult(await downloadFiles({
|
|
128
|
-
body: batch.map((file) => ({
|
|
129
|
-
...file,
|
|
130
|
-
locale: file.locale ? resolveServiceLocale(file.locale) : void 0
|
|
131
|
-
})),
|
|
132
|
-
client: getClient()
|
|
133
|
-
}));
|
|
134
|
-
const responses = await processBatches(files, async (batch) => [await request(batch)]);
|
|
135
|
-
return {
|
|
136
|
-
files: responses.flatMap((response) => response.files.map((file) => ({
|
|
137
|
-
...file,
|
|
138
|
-
...file.locale && { locale: resolveAliasLocale(file.locale, customMapping) },
|
|
139
|
-
data: decodeFileContent(file.data, file.fileFormat),
|
|
140
|
-
metadata: file.metadata
|
|
141
|
-
}))),
|
|
142
|
-
count: responses.reduce((count, response) => count + response.count, 0),
|
|
143
|
-
pending: responses.flatMap((response) => response.pending ?? [])
|
|
144
|
-
};
|
|
145
|
-
},
|
|
146
|
-
async setupProject(files, options = {}) {
|
|
147
|
-
return unwrapApiResult(await generateProjectContext({
|
|
148
|
-
body: {
|
|
149
|
-
files: files.map(({ branchId, fileId, versionId }) => ({
|
|
150
|
-
branchId,
|
|
151
|
-
fileId,
|
|
152
|
-
versionId
|
|
153
|
-
})),
|
|
154
|
-
locales: options.locales?.map((locale) => resolveServiceLocale(locale)),
|
|
155
|
-
force: options.force
|
|
156
|
-
},
|
|
157
|
-
client: getClient()
|
|
158
|
-
}));
|
|
159
|
-
},
|
|
160
|
-
async enqueueFiles(files, options) {
|
|
161
|
-
const targetLocales = options.targetLocales.map((locale) => resolveServiceLocale(locale));
|
|
162
|
-
const result = await processBatches(files, async (batch) => {
|
|
163
|
-
const response = unwrapApiResult(await enqueueFileTranslations({
|
|
164
|
-
body: {
|
|
165
|
-
files: batch.map(({ branchId, fileId, versionId, fileName, transformFormat }) => ({
|
|
166
|
-
branchId,
|
|
167
|
-
fileId,
|
|
168
|
-
versionId,
|
|
169
|
-
fileName,
|
|
170
|
-
transformFormat
|
|
171
|
-
})),
|
|
172
|
-
targetLocales,
|
|
173
|
-
sourceLocale: options.sourceLocale ? resolveServiceLocale(options.sourceLocale) : void 0,
|
|
174
|
-
modelProvider: options.modelProvider,
|
|
175
|
-
force: options.force
|
|
176
|
-
},
|
|
177
|
-
client: getClient()
|
|
178
|
-
}));
|
|
179
|
-
const jobData = "jobData" in response ? response.jobData : response.data;
|
|
180
|
-
return Object.entries(jobData);
|
|
181
|
-
});
|
|
182
|
-
return {
|
|
183
|
-
jobData: Object.fromEntries(result),
|
|
184
|
-
locales: targetLocales,
|
|
185
|
-
message: `Successfully enqueued ${result.length} file translation jobs in ${Math.ceil(files.length / DEFAULT_BATCH_SIZE)} batch(es)`
|
|
186
|
-
};
|
|
187
|
-
},
|
|
188
|
-
async uploadSourceFiles(files, options) {
|
|
189
|
-
const sourceLocale = resolveServiceLocale(options.sourceLocale);
|
|
190
|
-
return { uploadedFiles: await processBatches(files, async (batch) => {
|
|
191
|
-
return unwrapApiResult(await uploadSourceFiles({
|
|
192
|
-
body: {
|
|
193
|
-
data: batch.map(({ source }) => ({ source: {
|
|
194
|
-
...source,
|
|
195
|
-
content: encodeFileContent(source.content, source.fileFormat),
|
|
196
|
-
locale: resolveServiceLocale(source.locale)
|
|
197
|
-
} })),
|
|
198
|
-
sourceLocale
|
|
199
|
-
},
|
|
200
|
-
client: getClient()
|
|
201
|
-
})).uploadedFiles;
|
|
202
|
-
}) };
|
|
203
|
-
},
|
|
204
|
-
async awaitJobs(jobIds, options) {
|
|
205
|
-
return pollJobs(jobIds, async (pendingJobIds, signal) => unwrapApiResult(await getTranslationJobInfo({
|
|
206
|
-
body: { jobIds: pendingJobIds },
|
|
207
|
-
client: getClient(),
|
|
208
|
-
signal
|
|
209
|
-
})), options);
|
|
210
|
-
},
|
|
211
|
-
async uploadTranslations(files, options) {
|
|
212
|
-
return { uploadedFiles: await processBatches(files, async (batch) => {
|
|
213
|
-
return unwrapApiResult(await uploadTranslations({
|
|
214
|
-
body: {
|
|
215
|
-
data: batch.map(({ source, translations }) => ({
|
|
216
|
-
source: {
|
|
217
|
-
...source,
|
|
218
|
-
content: encodeFileContent(source.content, source.fileFormat),
|
|
219
|
-
locale: resolveServiceLocale(source.locale)
|
|
220
|
-
},
|
|
221
|
-
translations: translations.map((translation) => ({
|
|
222
|
-
...translation,
|
|
223
|
-
locale: resolveServiceLocale(translation.locale),
|
|
224
|
-
content: encodeFileContent(translation.content, translation.fileFormat)
|
|
225
|
-
}))
|
|
226
|
-
})),
|
|
227
|
-
sourceLocale: resolveServiceLocale(options.sourceLocale)
|
|
228
|
-
},
|
|
229
|
-
client: getClient()
|
|
230
|
-
})).uploadedFiles;
|
|
231
|
-
}) };
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
//#endregion
|
|
236
64
|
//#region src/derive/indexVars.ts
|
|
237
65
|
/**
|
|
238
66
|
* Given an ICU string adds identifiers to each _gt_ placeholder
|
|
@@ -324,6 +152,6 @@ function condenseVars(icuString) {
|
|
|
324
152
|
}));
|
|
325
153
|
}
|
|
326
154
|
//#endregion
|
|
327
|
-
export { API_VERSION, VAR_IDENTIFIER, condenseVars, createDiagnosticMessage, createGtApiAdapter, declareVar, decode, decodeFileContent, decodeVars, defaultBaseUrl, defaultCacheUrl, defaultRuntimeApiUrl, derive, encode, encodeFileContent, extractVars, formatDiagnosticErrorDetails, _getPluralForm as getPluralForm, indexVars, isAcceptedPluralForm, isErrorResult, isSupportedFileFormatTransform, isVariable, libraryDefaultLocale, minifyVariableType, pluralForms, unwrapApiResult };
|
|
155
|
+
export { API_VERSION, VAR_IDENTIFIER, condenseVars, createDiagnosticMessage, createGtApiAdapter, declareVar, decode, decodeFileContent, decodeVars, defaultBaseUrl, defaultCacheUrl, defaultRuntimeApiUrl, derive, encode, encodeFileContent, extractVars, formatDiagnosticErrorDetails, _getPluralForm as getPluralForm, indexVars, isAcceptedPluralForm, isErrorResult, isModelProvider, isSupportedFileFormatTransform, isVariable, libraryDefaultLocale, minifyVariableType, pluralForms, supportedModelProviders, unwrapApiResult };
|
|
328
156
|
|
|
329
157
|
//# sourceMappingURL=internal.mjs.map
|
package/dist/internal.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.mjs","names":[],"sources":["../src/settings/plurals.ts","../src/locales/getPluralForm.ts","../src/utils/minify.ts","../src/adapter/createGtApi.ts","../src/derive/indexVars.ts","../src/derive/extractVars.ts","../src/derive/condenseVars.ts"],"sourcesContent":["export const pluralForms = [\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n] as const;\nexport type PluralType = (typeof pluralForms)[number];\nexport function isAcceptedPluralForm(form: string): form is PluralType {\n return pluralForms.includes(form as (typeof pluralForms)[number]);\n}\n","import { getCachedPluralRules } from '@generaltranslation/format/internal';\n\nimport { pluralForms, PluralType } from '../settings/plurals';\nimport { libraryDefaultLocale } from '../settings/settings';\n\n/**\n * Given a number and a list of allowed plural forms, return the plural form that best fits the number.\n *\n * @param {number} n - The number to determine the plural form for.\n * @param {PluralType[]} forms - The allowed plural forms.\n * @returns {PluralType} The determined plural form, or an empty string if none fit.\n */\nexport function _getPluralForm(\n n: number,\n forms: readonly PluralType[] = pluralForms,\n locales: string[] = [libraryDefaultLocale]\n): PluralType | '' {\n const pluralRules = getCachedPluralRules(locales);\n const provisionalBranchName = pluralRules.select(n);\n // aliases\n const absN = Math.abs(n);\n // 0\n if (absN === 0 && forms.includes('zero')) return 'zero'; // override\n // 1\n if (absN === 1) {\n if (forms.includes('singular')) return 'singular'; // override\n if (forms.includes('one')) return 'one'; // override\n }\n if (provisionalBranchName === 'one' && forms.includes('singular'))\n return 'singular';\n // 2\n if (absN === 2) {\n if (forms.includes('dual')) return 'dual'; // override\n if (forms.includes('two')) return 'two'; // override\n }\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n // fallbacks\n if (forms.includes(provisionalBranchName)) return provisionalBranchName;\n if (forms.includes('plural')) return 'plural';\n if (forms.includes('other')) return 'other';\n return '';\n}\n","import { VariableTransformationSuffix, VariableType } from '../types';\n\nconst VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES = {\n variable: 'v',\n number: 'n',\n datetime: 'd',\n currency: 'c',\n 'relative-time': 'rt',\n} as const;\n\nexport function minifyVariableType(\n variableType: VariableTransformationSuffix\n): VariableType {\n return VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES[variableType];\n}\n","import {\n createApiClient,\n createBranch,\n DEFAULT_BATCH_SIZE,\n downloadFiles,\n enqueueFileTranslations,\n generateProjectContext,\n getFileInfo,\n getTranslationJobInfo,\n pollJobs,\n processBatches,\n uploadSourceFiles,\n uploadTranslations,\n type ApiClientConfig,\n type AwaitJobsOptions,\n type CreateBranchData,\n type DownloadFilesData,\n type EnqueueFileTranslationsData,\n type GenerateProjectContextData,\n type GetFileInfoData,\n type UploadSourceFilesData,\n type UploadTranslationsData,\n} from '@generaltranslation/api';\nimport {\n resolveAliasLocale,\n resolveCanonicalLocale,\n standardizeLocale,\n} from '@generaltranslation/format';\nimport type { CustomMapping } from '@generaltranslation/format/types';\nimport type { DownloadedFile } from '../types-dir/api/downloadFileBatch';\nimport { decodeFileContent, encodeFileContent } from '../utils/base64';\nimport { unwrapApiResult } from '../translate/utils/unwrapApiResult';\n\nexport type GtApiAdapterConfig = ApiClientConfig & {\n customMapping?: CustomMapping;\n};\n\nexport function createGtApiAdapter(defaultConfig?: ApiClientConfig) {\n let client = defaultConfig ? createApiClient(defaultConfig) : undefined;\n let configuredClientConfig = defaultConfig;\n let customMapping: CustomMapping | undefined;\n\n // Mapping resolves aliases; standardization also canonicalizes configured\n // spellings such as en-us before they cross the service boundary.\n function resolveServiceLocale(locale: string): string {\n return standardizeLocale(resolveCanonicalLocale(locale, customMapping));\n }\n\n function getClient(): ReturnType<typeof createApiClient> {\n if (!client) {\n throw new Error(\n 'API client not configured — call configureApiClient first'\n );\n }\n return client;\n }\n\n function getClientConfig(): ApiClientConfig {\n if (!configuredClientConfig) {\n throw new Error(\n 'API client not configured — call configureApiClient first'\n );\n }\n return configuredClientConfig;\n }\n\n function configure(config: GtApiAdapterConfig): void {\n const { customMapping: mapping, ...clientConfig } = config;\n client = createApiClient(clientConfig);\n configuredClientConfig = clientConfig;\n customMapping = mapping;\n }\n\n return {\n configure,\n getClient,\n getClientConfig,\n\n resolveAliasLocale(locale: string) {\n return resolveAliasLocale(locale, customMapping);\n },\n\n resolveCanonicalLocale(locale: string) {\n return resolveServiceLocale(locale);\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: resolveServiceLocale(file.locale),\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 downloadFileBatch(files: DownloadFilesData['body']) {\n const request = async (batch: DownloadFilesData['body']) =>\n unwrapApiResult(\n await downloadFiles({\n body: batch.map((file) => ({\n ...file,\n locale: file.locale\n ? resolveServiceLocale(file.locale)\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(\n (file): DownloadedFile => ({\n ...file,\n ...(file.locale && {\n locale: resolveAliasLocale(file.locale, customMapping),\n }),\n data: decodeFileContent(file.data, file.fileFormat),\n // OpenAPI currently types metadata as an open object; the API emits\n // JSON values here, matching DownloadedFile's public contract.\n metadata: file.metadata as DownloadedFile['metadata'],\n })\n )\n ),\n count: responses.reduce((count, response) => count + response.count, 0),\n pending: responses.flatMap((response) => response.pending ?? []),\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 resolveServiceLocale(locale)\n ),\n force: options.force,\n },\n client: getClient(),\n })\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 resolveServiceLocale(locale)\n );\n const result = await processBatches(files, async (batch) => {\n const response = unwrapApiResult(\n await enqueueFileTranslations({\n body: {\n files: batch.map(\n ({\n branchId,\n fileId,\n versionId,\n fileName,\n transformFormat,\n }) => ({\n branchId,\n fileId,\n versionId,\n fileName,\n transformFormat,\n })\n ),\n targetLocales,\n sourceLocale: options.sourceLocale\n ? resolveServiceLocale(options.sourceLocale)\n : undefined,\n // Consumers intentionally accept custom model-provider strings beyond\n // the OpenAPI enum; preserve the existing wire behavior at this boundary.\n modelProvider:\n options.modelProvider as EnqueueFileTranslationsData['body']['modelProvider'],\n force: options.force,\n },\n client: getClient(),\n })\n );\n const jobData =\n '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 = resolveServiceLocale(options.sourceLocale);\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: resolveServiceLocale(source.locale),\n },\n })),\n sourceLocale,\n },\n client: getClient(),\n })\n );\n return response.uploadedFiles;\n });\n\n return { uploadedFiles: result };\n },\n\n async awaitJobs(jobIds: readonly string[], options?: AwaitJobsOptions) {\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 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 locale: resolveServiceLocale(source.locale),\n },\n translations: translations.map((translation) => ({\n ...translation,\n locale: resolveServiceLocale(translation.locale),\n content: encodeFileContent(\n translation.content,\n translation.fileFormat\n ),\n })),\n })),\n sourceLocale: resolveServiceLocale(options.sourceLocale),\n },\n client: getClient(),\n })\n );\n return response.uploadedFiles;\n });\n\n return { uploadedFiles: result };\n },\n };\n}\n\nexport type GtApiAdapter = ReturnType<typeof createGtApiAdapter>;\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport type { IcuMessage } from '@generaltranslation/format/types';\n\ntype Location = {\n start: number;\n end: number;\n otherStart: number;\n otherEnd: number;\n};\n\n/**\n * Given an ICU string adds identifiers to each _gt_ placeholder\n * indexVars('Hello {_gt_} {_gt_} World') => 'Hello {_gt_1_} {_gt_2_} World'\n */\nexport function indexVars(icuString: IcuMessage): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n otherStart: child.options.other.location?.start.offset ?? 0,\n otherEnd: child.options.other.location?.end.offset ?? 0,\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false, captureLocation: true },\n });\n\n // Index each variable and collapse the other option.\n const result = [];\n let current = 0;\n for (let i = 0; i < variableLocations.length; i++) {\n const { start, end, otherStart, otherEnd } = variableLocations[i];\n // Before the variable\n result.push(icuString.slice(current, start));\n // Replace the variable with the new identifier (+1 is for the curly brace)\n result.push(icuString.slice(start, start + VAR_IDENTIFIER.length + 1));\n\n // Add the new identifier.\n result.push(String(i + 1));\n // After the variable\n result.push(icuString.slice(start + VAR_IDENTIFIER.length + 1, otherStart));\n // Before the other option\n result.push('{}');\n // The other option\n result.push(icuString.slice(otherEnd, end));\n current = end;\n }\n result.push(icuString.slice(current, icuString.length));\n\n return result.join('');\n}\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\n/**\n * Given an unindexed ICU string, extracts all the _gt_ variables and an indexed mapping of the variable to the values\n *\n * extractVars('Hello {_gt_, select, other {World}}') => { _gt_1: 'World' }\n *\n * @param {string} icuString - The ICU string to extract variables from.\n * @returns {Record<string, string>} A mapping of the variable to the value.\n */\nexport function extractVars(icuString: string): Record<string, string> {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return {};\n }\n\n // Extract all the _gt_# variables\n let index = 1;\n const variables: Record<string, string> = {};\n function visitor(child: GTUnindexedSelectElement): void {\n variables[child.value + index] = child.options.other.value.length\n ? child.options.other.value[0]?.value\n : '';\n index += 1;\n }\n\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n return variables;\n}\n","import { printAST, TYPE, type ArgumentElement } from '@generaltranslation/icu';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTIndexedSelectElement } from './utils/types';\nimport { isGTIndexedSelectElement } from './utils/traverseHelpers';\ninterface GTIndexedArgumentElement extends ArgumentElement {\n value: `${typeof VAR_IDENTIFIER}${number}`;\n}\n\nconst CONTAINS_INDEXED_GT_REGEX = new RegExp(`${VAR_IDENTIFIER}\\\\d+`);\n\n/**\n * Given an indexed ICU string, condenses any select to an argument\n * Unindexed _gt_ source strings and indexed _gt_# translation strings\n * are mutually exclusive.\n * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'\n * @param {string} icuString - The ICU string to condense.\n * @returns {string} The condensed ICU string.\n */\nexport function condenseVars(icuString: string): string {\n // Check if the string contains an indexed _gt_ identifier.\n if (!CONTAINS_INDEXED_GT_REGEX.test(icuString)) {\n return icuString;\n }\n\n // Replace with argument\n function visitor(child: GTIndexedSelectElement): void {\n (child as unknown as GTIndexedArgumentElement).type = TYPE.argument;\n Reflect.deleteProperty(child, 'options');\n }\n\n const ast = traverseIcu({\n icuString,\n shouldVisit: isGTIndexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n // Serialize\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MAAM,QAAQ,MAAM,MAAM,IAAI,QAC9B;AACJ,WAAS;;AAGX,aAAY;EACV;EACA,aAAa;EACb;EACA,SAAS,EAAE,oBAAoB,OAAO;EACvC,CAAC;AAEF,QAAO;;;;AC1BT,MAAM,4BAA4B,IAAI,OAAO,GAAG,eAAe,MAAM;;;;;;;;;AAUrE,SAAgB,aAAa,WAA2B;AAEtD,KAAI,CAAC,0BAA0B,KAAK,UAAU,CAC5C,QAAO;CAIT,SAAS,QAAQ,OAAqC;AACnD,QAA8C,OAAO,KAAK;AAC3D,UAAQ,eAAe,OAAO,UAAU;;AAW1C,QAAO,SARK,YAAY;EACtB;EACA,aAAa;EACb;EACA,SAAS,EAAE,oBAAoB,OAAO;EACvC,CAGkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"internal.mjs","names":[],"sources":["../src/settings/plurals.ts","../src/locales/getPluralForm.ts","../src/utils/minify.ts","../src/derive/indexVars.ts","../src/derive/extractVars.ts","../src/derive/condenseVars.ts"],"sourcesContent":["export const pluralForms = [\n 'singular',\n 'plural',\n 'dual',\n 'zero',\n 'one',\n 'two',\n 'few',\n 'many',\n 'other',\n] as const;\nexport type PluralType = (typeof pluralForms)[number];\nexport function isAcceptedPluralForm(form: string): form is PluralType {\n return pluralForms.includes(form as (typeof pluralForms)[number]);\n}\n","import { getCachedPluralRules } from '@generaltranslation/format/internal';\n\nimport { pluralForms, PluralType } from '../settings/plurals';\nimport { libraryDefaultLocale } from '../settings/settings';\n\n/**\n * Given a number and a list of allowed plural forms, return the plural form that best fits the number.\n *\n * @param {number} n - The number to determine the plural form for.\n * @param {PluralType[]} forms - The allowed plural forms.\n * @returns {PluralType} The determined plural form, or an empty string if none fit.\n */\nexport function _getPluralForm(\n n: number,\n forms: readonly PluralType[] = pluralForms,\n locales: string[] = [libraryDefaultLocale]\n): PluralType | '' {\n const pluralRules = getCachedPluralRules(locales);\n const provisionalBranchName = pluralRules.select(n);\n // aliases\n const absN = Math.abs(n);\n // 0\n if (absN === 0 && forms.includes('zero')) return 'zero'; // override\n // 1\n if (absN === 1) {\n if (forms.includes('singular')) return 'singular'; // override\n if (forms.includes('one')) return 'one'; // override\n }\n if (provisionalBranchName === 'one' && forms.includes('singular'))\n return 'singular';\n // 2\n if (absN === 2) {\n if (forms.includes('dual')) return 'dual'; // override\n if (forms.includes('two')) return 'two'; // override\n }\n if (provisionalBranchName === 'two' && forms.includes('dual')) return 'dual';\n // fallbacks\n if (forms.includes(provisionalBranchName)) return provisionalBranchName;\n if (forms.includes('plural')) return 'plural';\n if (forms.includes('other')) return 'other';\n return '';\n}\n","import { VariableTransformationSuffix, VariableType } from '../types';\n\nconst VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES = {\n variable: 'v',\n number: 'n',\n datetime: 'd',\n currency: 'c',\n 'relative-time': 'rt',\n} as const;\n\nexport function minifyVariableType(\n variableType: VariableTransformationSuffix\n): VariableType {\n return VARIABLE_TRANSFORMATION_SUFFIXES_TO_MINIFIED_NAMES[variableType];\n}\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport type { IcuMessage } from '@generaltranslation/format/types';\n\ntype Location = {\n start: number;\n end: number;\n otherStart: number;\n otherEnd: number;\n};\n\n/**\n * Given an ICU string adds identifiers to each _gt_ placeholder\n * indexVars('Hello {_gt_} {_gt_} World') => 'Hello {_gt_1_} {_gt_2_} World'\n */\nexport function indexVars(icuString: IcuMessage): string {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return icuString;\n }\n\n // Record the location of the variable\n const variableLocations: Location[] = [];\n function visitor(child: GTUnindexedSelectElement): void {\n variableLocations.push({\n start: child.location?.start.offset ?? 0,\n end: child.location?.end.offset ?? 0,\n otherStart: child.options.other.location?.start.offset ?? 0,\n otherEnd: child.options.other.location?.end.offset ?? 0,\n });\n }\n\n // Find all variable identifiers.\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false, captureLocation: true },\n });\n\n // Index each variable and collapse the other option.\n const result = [];\n let current = 0;\n for (let i = 0; i < variableLocations.length; i++) {\n const { start, end, otherStart, otherEnd } = variableLocations[i];\n // Before the variable\n result.push(icuString.slice(current, start));\n // Replace the variable with the new identifier (+1 is for the curly brace)\n result.push(icuString.slice(start, start + VAR_IDENTIFIER.length + 1));\n\n // Add the new identifier.\n result.push(String(i + 1));\n // After the variable\n result.push(icuString.slice(start + VAR_IDENTIFIER.length + 1, otherStart));\n // Before the other option\n result.push('{}');\n // The other option\n result.push(icuString.slice(otherEnd, end));\n current = end;\n }\n result.push(icuString.slice(current, icuString.length));\n\n return result.join('');\n}\n","import { VAR_IDENTIFIER } from './utils/constants';\nimport { isGTUnindexedSelectElement } from './utils/traverseHelpers';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { GTUnindexedSelectElement } from './utils/types';\n/**\n * Given an unindexed ICU string, extracts all the _gt_ variables and an indexed mapping of the variable to the values\n *\n * extractVars('Hello {_gt_, select, other {World}}') => { _gt_1: 'World' }\n *\n * @param {string} icuString - The ICU string to extract variables from.\n * @returns {Record<string, string>} A mapping of the variable to the value.\n */\nexport function extractVars(icuString: string): Record<string, string> {\n // Check if the string contains _gt_\n if (!icuString.includes(VAR_IDENTIFIER)) {\n return {};\n }\n\n // Extract all the _gt_# variables\n let index = 1;\n const variables: Record<string, string> = {};\n function visitor(child: GTUnindexedSelectElement): void {\n variables[child.value + index] = child.options.other.value.length\n ? child.options.other.value[0]?.value\n : '';\n index += 1;\n }\n\n traverseIcu({\n icuString,\n shouldVisit: isGTUnindexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n return variables;\n}\n","import { printAST, TYPE, type ArgumentElement } from '@generaltranslation/icu';\nimport { traverseIcu } from './utils/traverseIcu';\nimport { VAR_IDENTIFIER } from './utils/constants';\nimport { GTIndexedSelectElement } from './utils/types';\nimport { isGTIndexedSelectElement } from './utils/traverseHelpers';\ninterface GTIndexedArgumentElement extends ArgumentElement {\n value: `${typeof VAR_IDENTIFIER}${number}`;\n}\n\nconst CONTAINS_INDEXED_GT_REGEX = new RegExp(`${VAR_IDENTIFIER}\\\\d+`);\n\n/**\n * Given an indexed ICU string, condenses any select to an argument\n * Unindexed _gt_ source strings and indexed _gt_# translation strings\n * are mutually exclusive.\n * indexVars('Hello {_gt_1, select, other {World}}') => 'Hello {_gt_1}'\n * @param {string} icuString - The ICU string to condense.\n * @returns {string} The condensed ICU string.\n */\nexport function condenseVars(icuString: string): string {\n // Check if the string contains an indexed _gt_ identifier.\n if (!CONTAINS_INDEXED_GT_REGEX.test(icuString)) {\n return icuString;\n }\n\n // Replace with argument\n function visitor(child: GTIndexedSelectElement): void {\n (child as unknown as GTIndexedArgumentElement).type = TYPE.argument;\n Reflect.deleteProperty(child, 'options');\n }\n\n const ast = traverseIcu({\n icuString,\n shouldVisit: isGTIndexedSelectElement,\n visitor,\n options: { recurseIntoVisited: false },\n });\n\n // Serialize\n return printAST(ast);\n}\n"],"mappings":";;;;;;;;AAAA,MAAa,cAAc;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,SAAgB,qBAAqB,MAAkC;AACrE,QAAO,YAAY,SAAS,KAAqC;;;;;;;;;;;ACDnE,SAAgB,eACd,GACA,QAA+B,aAC/B,UAAoB,CAAA,KAAsB,EACzB;CAEjB,MAAM,wBADc,qBAAqB,QACA,CAAC,OAAO,EAAE;CAEnD,MAAM,OAAO,KAAK,IAAI,EAAE;AAExB,KAAI,SAAS,KAAK,MAAM,SAAS,OAAO,CAAE,QAAO;AAEjD,KAAI,SAAS,GAAG;AACd,MAAI,MAAM,SAAS,WAAW,CAAE,QAAO;AACvC,MAAI,MAAM,SAAS,MAAM,CAAE,QAAO;;AAEpC,KAAI,0BAA0B,SAAS,MAAM,SAAS,WAAW,CAC/D,QAAO;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,SAAS,GAAG,WAAW,CAAC;AAE3E,SAAO,KAAK,KAAK;AAEjB,SAAO,KAAK,UAAU,MAAM,UAAU,IAAI,CAAC;AAC3C,YAAU;;AAEZ,QAAO,KAAK,UAAU,MAAM,SAAS,UAAU,OAAO,CAAC;AAEvD,QAAO,OAAO,KAAK,GAAG;;;;;;;;;;;;ACpDxB,SAAgB,YAAY,WAA2C;AAErE,KAAI,CAAC,UAAU,SAAA,OAAwB,CACrC,QAAO,EAAE;CAIX,IAAI,QAAQ;CACZ,MAAM,YAAoC,EAAE;CAC5C,SAAS,QAAQ,OAAuC;AACtD,YAAU,MAAM,QAAQ,SAAS,MAAM,QAAQ,MAAM,MAAM,SACvD,MAAM,QAAQ,MAAM,MAAM,IAAI,QAC9B;AACJ,WAAS;;AAGX,aAAY;EACV;EACA,aAAa;EACb;EACA,SAAS,EAAE,oBAAoB,OAAO;EACvC,CAAC;AAEF,QAAO;;;;AC1BT,MAAM,4BAA4B,IAAI,OAAO,GAAG,eAAe,MAAM;;;;;;;;;AAUrE,SAAgB,aAAa,WAA2B;AAEtD,KAAI,CAAC,0BAA0B,KAAK,UAAU,CAC5C,QAAO;CAIT,SAAS,QAAQ,OAAqC;AACnD,QAA8C,OAAO,KAAK;AAC3D,UAAQ,eAAe,OAAO,UAAU;;AAW1C,QAAO,SARK,YAAY;EACtB;EACA,aAAa;EACb;EACA,SAAS,EAAE,oBAAoB,OAAO;EACvC,CAGkB,CAAC"}
|
package/dist/logging/errors.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export declare const translationTimeoutError: (timeout: number) => string;
|
|
2
2
|
export declare const translationRequestFailedError: (error: string) => string;
|
|
3
3
|
export declare const apiError: (status: number, statusText: string, error: string) => string;
|
|
4
|
-
export declare const invalidAuthError: string;
|
|
5
4
|
export declare const noTargetLocaleProvidedError: (functionName: string) => string;
|
|
6
5
|
export declare const noSourceLocaleProvidedError: (functionName: string) => string;
|
|
7
6
|
export declare const noProjectIdProvidedError: (functionName: string) => string;
|
package/dist/logging/errors.js
CHANGED
|
@@ -26,12 +26,6 @@ export var apiError = function (status, statusText, error) {
|
|
|
26
26
|
details: error,
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
|
-
export var invalidAuthError = createDiagnosticMessage({
|
|
30
|
-
source: GT_SOURCE,
|
|
31
|
-
severity: 'Error',
|
|
32
|
-
whatHappened: 'Authentication failed',
|
|
33
|
-
fix: 'Check that your API key and project ID are correct',
|
|
34
|
-
});
|
|
35
29
|
export var noTargetLocaleProvidedError = function (functionName) {
|
|
36
30
|
return createDiagnosticMessage({
|
|
37
31
|
source: GT_SOURCE,
|