@lokalise/polyglot-sdk 3.0.0 → 3.2.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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/sdk/PolyglotClient.d.ts +7 -5
- package/dist/sdk/PolyglotClient.js +92 -32
- package/dist/sdk/PolyglotClient.js.map +1 -1
- package/dist/sdk/segmentUtils.d.ts +3 -0
- package/dist/sdk/segmentUtils.js +22 -0
- package/dist/sdk/segmentUtils.js.map +1 -0
- package/dist/sdk/types/callbacks.d.ts +4 -0
- package/dist/sdk/types/callbacks.js +3 -0
- package/dist/sdk/types/callbacks.js.map +1 -0
- package/dist/sdk/types/client.d.ts +7 -0
- package/dist/sdk/types/requests.d.ts +5 -0
- package/dist/sdk/types/responses.d.ts +1 -0
- package/package.json +9 -9
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -9,4 +9,5 @@ Object.defineProperty(exports, "PolyglotError", { enumerable: true, get: functio
|
|
|
9
9
|
tslib_1.__exportStar(require("./sdk/types/client"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./sdk/types/requests"), exports);
|
|
11
11
|
tslib_1.__exportStar(require("./sdk/types/responses"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./sdk/types/callbacks"), exports);
|
|
12
13
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,uDAAqD;AAA5C,gHAAA,cAAc,OAAA;AACvB,4DAA0D;AAAjD,8GAAA,aAAa,OAAA;AACtB,6DAAkC;AAClC,+DAAoC;AACpC,gEAAqC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,uDAAqD;AAA5C,gHAAA,cAAc,OAAA;AACvB,4DAA0D;AAAjD,8GAAA,aAAa,OAAA;AACtB,6DAAkC;AAClC,+DAAoC;AACpC,gEAAqC;AACrC,gEAAqC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Either } from '@lokalise/node-core';
|
|
2
|
+
import type { ClientOptions, ClientOptionsWithRequestContext, PolyglotClientConfig } from './types/client';
|
|
3
|
+
import type { GenerateVariantsRequest, LqaSyncRequest, TranslateAsyncRequestBody, TranslateSyncRequest } from './types/requests';
|
|
3
4
|
import type { ContentUnitLqaResponse, ContentUnitTranslationResponse, PolyglotClientSyncIterativeResponse } from './types/responses';
|
|
4
5
|
export declare class PolyglotClient {
|
|
5
6
|
private readonly client;
|
|
@@ -21,12 +22,13 @@ export declare class PolyglotClient {
|
|
|
21
22
|
* Re-translates a given translation pair and provides several different variants. Can take previously generated
|
|
22
23
|
* variants as an input - in attempt to avoid repetition.
|
|
23
24
|
*/
|
|
24
|
-
generateVariants(request: GenerateVariantsRequest,
|
|
25
|
+
generateVariants(request: GenerateVariantsRequest, options?: ClientOptions): Promise<string[]>;
|
|
25
26
|
private callTranslateSyncApi;
|
|
27
|
+
translateAsync(requestBody: TranslateAsyncRequestBody, options: ClientOptionsWithRequestContext): Promise<Either<Error, 'scheduled' | 'nothingToTranslate'>>;
|
|
26
28
|
private callLqaSyncApi;
|
|
29
|
+
private wrapWithErrorHandling;
|
|
27
30
|
/**
|
|
28
|
-
* Calls the provided request function and
|
|
29
|
-
* and logs the execution time and metadata with the provided logger
|
|
31
|
+
* Calls the provided request function and logs the execution time and metadata with the provided logger
|
|
30
32
|
* @private
|
|
31
33
|
*/
|
|
32
34
|
private wrapWithInstrumentation;
|
|
@@ -2,9 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PolyglotClient = void 0;
|
|
4
4
|
const node_core_1 = require("@lokalise/node-core");
|
|
5
|
+
const typeUtils_1 = require("@lokalise/node-core/dist/src/utils/typeUtils");
|
|
5
6
|
const PolyglotError_1 = require("./errors/PolyglotError");
|
|
6
7
|
const polyglotChunkHandler_1 = require("./polyglotChunkHandler");
|
|
7
|
-
const
|
|
8
|
+
const segmentUtils_1 = require("./segmentUtils");
|
|
9
|
+
const DEFAULT_CLIENT_OPTIONS = {
|
|
10
|
+
timeout: 30000,
|
|
11
|
+
};
|
|
12
|
+
function resolveOptions(options) {
|
|
13
|
+
return {
|
|
14
|
+
...options,
|
|
15
|
+
timeout: Object.hasOwn(options, 'timeout') ? options.timeout : DEFAULT_CLIENT_OPTIONS.timeout,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
8
18
|
class PolyglotClient {
|
|
9
19
|
client;
|
|
10
20
|
clientHeaders;
|
|
@@ -37,16 +47,12 @@ class PolyglotClient {
|
|
|
37
47
|
* the amount of segments exceeds synchronous API limits and will yield the results separately.
|
|
38
48
|
*/
|
|
39
49
|
async *translateSyncIterative(request, options = DEFAULT_CLIENT_OPTIONS) {
|
|
50
|
+
const resolvedOptions = resolveOptions(options);
|
|
40
51
|
const chunks = (0, polyglotChunkHandler_1.getChunkedTranslationRequest)(request);
|
|
41
52
|
for (const requestChunked of chunks) {
|
|
42
53
|
yield {
|
|
43
|
-
response: await this.callTranslateSyncApi(requestChunked,
|
|
44
|
-
segmentIdsProcessedByContentUnitId: requestChunked.contentUnits
|
|
45
|
-
if (!acc[cu.id])
|
|
46
|
-
acc[cu.id] = [];
|
|
47
|
-
acc[cu.id].push(...cu.segments.map((s) => s.id));
|
|
48
|
-
return acc;
|
|
49
|
-
}, {}),
|
|
54
|
+
response: await this.callTranslateSyncApi(requestChunked, resolvedOptions),
|
|
55
|
+
segmentIdsProcessedByContentUnitId: (0, segmentUtils_1.groupTranslationSegmentIdsProcessedByContentUnitId)(requestChunked.contentUnits),
|
|
50
56
|
};
|
|
51
57
|
}
|
|
52
58
|
}
|
|
@@ -59,12 +65,7 @@ class PolyglotClient {
|
|
|
59
65
|
for (const requestChunked of chunks) {
|
|
60
66
|
yield {
|
|
61
67
|
response: await this.callLqaSyncApi(requestChunked, options),
|
|
62
|
-
segmentIdsProcessedByContentUnitId: requestChunked.contentUnits
|
|
63
|
-
if (!acc[cu.id])
|
|
64
|
-
acc[cu.id] = [];
|
|
65
|
-
acc[cu.id].push(...cu.segments.flatMap((s) => s.translations).map((t) => t.id));
|
|
66
|
-
return acc;
|
|
67
|
-
}, {}),
|
|
68
|
+
segmentIdsProcessedByContentUnitId: (0, segmentUtils_1.groupLqaSegmentIdsProcessedByContentUnitId)(requestChunked.contentUnits),
|
|
68
69
|
};
|
|
69
70
|
}
|
|
70
71
|
}
|
|
@@ -72,75 +73,134 @@ class PolyglotClient {
|
|
|
72
73
|
* Re-translates a given translation pair and provides several different variants. Can take previously generated
|
|
73
74
|
* variants as an input - in attempt to avoid repetition.
|
|
74
75
|
*/
|
|
75
|
-
async generateVariants(request,
|
|
76
|
+
async generateVariants(request, options = DEFAULT_CLIENT_OPTIONS) {
|
|
77
|
+
const resolvedOptions = resolveOptions(options);
|
|
76
78
|
if (request.sourceValue.trim() === '' || request.targetValue.trim() === '') {
|
|
77
79
|
return [];
|
|
78
80
|
}
|
|
79
81
|
const requestLabel = 'Generate variants (Polyglot)';
|
|
80
82
|
const response = await this.wrapWithInstrumentation(() => {
|
|
81
83
|
return (0, node_core_1.sendPost)(this.client, '/v1/content/actions/generate-variants', request, {
|
|
82
|
-
reqContext,
|
|
84
|
+
reqContext: resolvedOptions.reqContext,
|
|
83
85
|
retryConfig: this.retryConfig,
|
|
86
|
+
timeout: resolvedOptions.timeout,
|
|
84
87
|
headers: {
|
|
85
88
|
...this.clientHeaders,
|
|
86
|
-
'x-fake-processing': fakeProcessing ? 'true' : undefined,
|
|
89
|
+
'x-fake-processing': resolvedOptions.fakeProcessing ? 'true' : undefined,
|
|
87
90
|
},
|
|
88
91
|
requestLabel,
|
|
89
92
|
});
|
|
90
93
|
}, {
|
|
91
94
|
requestLabel,
|
|
92
95
|
callMetadata: {
|
|
93
|
-
...metadata,
|
|
94
|
-
reqContext: JSON.stringify(
|
|
96
|
+
...resolvedOptions.metadata,
|
|
97
|
+
reqContext: JSON.stringify({
|
|
98
|
+
reqId: resolvedOptions.reqContext?.reqId,
|
|
99
|
+
}),
|
|
95
100
|
},
|
|
96
101
|
});
|
|
97
102
|
return response.body.variants;
|
|
98
103
|
}
|
|
99
|
-
async callTranslateSyncApi(request,
|
|
104
|
+
async callTranslateSyncApi(request, options) {
|
|
105
|
+
const resolvedOptions = resolveOptions(options);
|
|
100
106
|
const requestLabel = 'Translate synchronously (Polyglot)';
|
|
101
107
|
const result = await this.wrapWithInstrumentation(() => {
|
|
102
108
|
return (0, node_core_1.sendPost)(this.client, '/v1/content/actions/translate-sync', request, {
|
|
103
|
-
reqContext,
|
|
109
|
+
reqContext: resolvedOptions.reqContext,
|
|
104
110
|
retryConfig: this.retryConfig,
|
|
111
|
+
timeout: resolvedOptions.timeout,
|
|
105
112
|
headers: {
|
|
106
113
|
...this.clientHeaders,
|
|
107
|
-
'x-fake-processing': fakeProcessing ? 'true' : undefined,
|
|
114
|
+
'x-fake-processing': resolvedOptions.fakeProcessing ? 'true' : undefined,
|
|
108
115
|
},
|
|
109
116
|
requestLabel,
|
|
110
117
|
});
|
|
111
118
|
}, {
|
|
112
119
|
requestLabel,
|
|
113
120
|
callMetadata: {
|
|
114
|
-
...metadata,
|
|
115
|
-
reqContext: JSON.stringify(
|
|
121
|
+
...resolvedOptions.metadata,
|
|
122
|
+
reqContext: JSON.stringify({
|
|
123
|
+
reqId: resolvedOptions.reqContext?.reqId,
|
|
124
|
+
}),
|
|
116
125
|
},
|
|
117
126
|
});
|
|
118
127
|
return result.body.contentUnits;
|
|
119
128
|
}
|
|
120
|
-
async
|
|
129
|
+
async translateAsync(requestBody, options) {
|
|
130
|
+
const contentUnits = requestBody.contentUnits.filter((contentUnit) => contentUnit.segments.length > 0);
|
|
131
|
+
if (contentUnits.length === 0) {
|
|
132
|
+
return (0, node_core_1.success)('nothingToTranslate');
|
|
133
|
+
}
|
|
134
|
+
const resolvedOptions = resolveOptions(options);
|
|
135
|
+
const requestLabel = 'Translate asynchronously (Polyglot)';
|
|
136
|
+
const result = await this.wrapWithErrorHandling(() => {
|
|
137
|
+
return (0, node_core_1.sendPost)(this.client, '/v1/content/actions/translate-async', requestBody, {
|
|
138
|
+
reqContext: resolvedOptions.reqContext,
|
|
139
|
+
retryConfig: this.retryConfig,
|
|
140
|
+
throwOnError: false,
|
|
141
|
+
timeout: resolvedOptions.timeout,
|
|
142
|
+
headers: {
|
|
143
|
+
...this.clientHeaders,
|
|
144
|
+
'x-fake-processing': resolvedOptions.fakeProcessing ? 'true' : undefined,
|
|
145
|
+
},
|
|
146
|
+
requestLabel,
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
if (result.error) {
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
if (result.result.statusCode === 202) {
|
|
153
|
+
return (0, node_core_1.success)('scheduled');
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
return (0, node_core_1.failure)(new node_core_1.InternalError({
|
|
157
|
+
message: 'Failed to schedule asynchronous translation',
|
|
158
|
+
errorCode: 'FAILED_TO_SCHEDULE_ASYNC_TRANSLATION',
|
|
159
|
+
details: {
|
|
160
|
+
originCorrelationId: requestBody.originCorrelationId,
|
|
161
|
+
},
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async callLqaSyncApi(request, options) {
|
|
166
|
+
const resolvedOptions = resolveOptions(options);
|
|
121
167
|
const requestLabel = 'Review with LQA synchronously (Polyglot)';
|
|
122
168
|
const result = await this.wrapWithInstrumentation(() => {
|
|
123
169
|
return (0, node_core_1.sendPost)(this.client, '/v1/content/actions/lqa-sync', request, {
|
|
124
|
-
reqContext,
|
|
170
|
+
reqContext: resolvedOptions.reqContext,
|
|
125
171
|
retryConfig: this.retryConfig,
|
|
172
|
+
timeout: resolvedOptions.timeout,
|
|
126
173
|
headers: {
|
|
127
174
|
...this.clientHeaders,
|
|
128
|
-
'x-fake-processing': fakeProcessing ? 'true' : undefined,
|
|
175
|
+
'x-fake-processing': resolvedOptions.fakeProcessing ? 'true' : undefined,
|
|
129
176
|
},
|
|
130
177
|
requestLabel,
|
|
131
178
|
});
|
|
132
179
|
}, {
|
|
133
180
|
requestLabel,
|
|
134
181
|
callMetadata: {
|
|
135
|
-
...metadata,
|
|
136
|
-
reqContext: JSON.stringify(
|
|
182
|
+
...resolvedOptions.metadata,
|
|
183
|
+
reqContext: JSON.stringify({
|
|
184
|
+
reqId: resolvedOptions.reqContext?.reqId,
|
|
185
|
+
}),
|
|
137
186
|
},
|
|
138
187
|
});
|
|
139
188
|
return result.body.contentUnits;
|
|
140
189
|
}
|
|
190
|
+
async wrapWithErrorHandling(innerFn) {
|
|
191
|
+
try {
|
|
192
|
+
const { result, error } = await innerFn();
|
|
193
|
+
if (error) {
|
|
194
|
+
return (0, node_core_1.failure)(this.wrapError(error));
|
|
195
|
+
}
|
|
196
|
+
return (0, node_core_1.success)(result);
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
return (0, node_core_1.failure)(this.wrapError(error));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
141
202
|
/**
|
|
142
|
-
* Calls the provided request function and
|
|
143
|
-
* and logs the execution time and metadata with the provided logger
|
|
203
|
+
* Calls the provided request function and logs the execution time and metadata with the provided logger
|
|
144
204
|
* @private
|
|
145
205
|
*/
|
|
146
206
|
async wrapWithInstrumentation(innerFn, { callMetadata, requestLabel }) {
|
|
@@ -170,7 +230,7 @@ class PolyglotClient {
|
|
|
170
230
|
}
|
|
171
231
|
wrapError(e) {
|
|
172
232
|
let error;
|
|
173
|
-
if (
|
|
233
|
+
if ((0, typeUtils_1.isError)(e)) {
|
|
174
234
|
error = (0, node_core_1.isResponseStatusError)(e) ? new PolyglotError_1.PolyglotError(e) : e;
|
|
175
235
|
}
|
|
176
236
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PolyglotClient.js","sourceRoot":"","sources":["../../src/sdk/PolyglotClient.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"PolyglotClient.js","sourceRoot":"","sources":["../../src/sdk/PolyglotClient.ts"],"names":[],"mappings":";;;AACA,mDAO4B;AAE5B,4EAAsE;AAKtE,0DAAsD;AACtD,iEAA2F;AAC3F,iDAGuB;AAsBvB,MAAM,sBAAsB,GAAkB;IAC5C,OAAO,EAAE,KAAK;CACf,CAAA;AAED,SAAS,cAAc,CAAC,OAAsB;IAC5C,OAAO;QACL,GAAG,OAAO;QACV,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,sBAAsB,CAAC,OAAO;KAC9F,CAAA;AACH,CAAC;AAED,MAAa,cAAc;IACR,MAAM,CAAQ;IACd,aAAa,CAAyB;IACtC,WAAW,CAAa;IACxB,MAAM,CAAS;IAEhC,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAwB;QAC1E,IAAI,CAAC,MAAM,GAAG,IAAA,uBAAW,EAAC,OAAO,CAAC,CAAA;QAClC,IAAI,CAAC,aAAa,GAAG;YACnB,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,QAAQ,EAAE;SACpC,CAAA;QACD,IAAI,CAAC,WAAW,GAAG;YACjB,cAAc,EAAE,KAAK;YACrB,WAAW,EAAE,CAAC;YACd,2BAA2B,EAAE,GAAG;YAChC,kBAAkB,EAAE;gBAClB,GAAG,EAAE,kBAAkB;gBACvB,GAAG,EAAE,sBAAsB;gBAC3B,GAAG,EAAE,oBAAoB;gBACzB,GAAG,EAAE,wBAAwB;gBAC7B,GAAG,EAAE,sBAAsB;gBAC3B,GAAG,EAAE,mBAAmB;aACzB;YACD,GAAG,WA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,CAAA;QAC5B,IAAI,IAAA,mBAAO,EAAC,CAAC,CAAC,EAAE,CAAC;YACf,KAAK,GAAG,IAAA,iCAAqB,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,6BAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC7D,CAAC;aAAM,CAAC;YACN,KAAK,GAAG,IAAI,yBAAa,CAAC;gBACxB,OAAO,EAAE,eAAe;gBACxB,SAAS,EAAE,eAAe;gBAC1B,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;aACtC,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AAnTD,wCAmTC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { LqaContentUnit, TranslateSyncContentUnits } from './types/requests';
|
|
2
|
+
export declare function groupTranslationSegmentIdsProcessedByContentUnitId(contentUnits: readonly TranslateSyncContentUnits[]): Record<string, string[]>;
|
|
3
|
+
export declare function groupLqaSegmentIdsProcessedByContentUnitId(contentUnits: readonly LqaContentUnit[]): Record<string, string[]>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.groupLqaSegmentIdsProcessedByContentUnitId = exports.groupTranslationSegmentIdsProcessedByContentUnitId = void 0;
|
|
4
|
+
function groupTranslationSegmentIdsProcessedByContentUnitId(contentUnits) {
|
|
5
|
+
return contentUnits.reduce((acc, cu) => {
|
|
6
|
+
if (!acc[cu.id])
|
|
7
|
+
acc[cu.id] = [];
|
|
8
|
+
acc[cu.id].push(...cu.segments.map((s) => s.id));
|
|
9
|
+
return acc;
|
|
10
|
+
}, {});
|
|
11
|
+
}
|
|
12
|
+
exports.groupTranslationSegmentIdsProcessedByContentUnitId = groupTranslationSegmentIdsProcessedByContentUnitId;
|
|
13
|
+
function groupLqaSegmentIdsProcessedByContentUnitId(contentUnits) {
|
|
14
|
+
return contentUnits.reduce((acc, cu) => {
|
|
15
|
+
if (!acc[cu.id])
|
|
16
|
+
acc[cu.id] = [];
|
|
17
|
+
acc[cu.id].push(...cu.segments.flatMap((s) => s.translations).map((t) => t.id));
|
|
18
|
+
return acc;
|
|
19
|
+
}, {});
|
|
20
|
+
}
|
|
21
|
+
exports.groupLqaSegmentIdsProcessedByContentUnitId = groupLqaSegmentIdsProcessedByContentUnitId;
|
|
22
|
+
//# sourceMappingURL=segmentUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segmentUtils.js","sourceRoot":"","sources":["../../src/sdk/segmentUtils.ts"],"names":[],"mappings":";;;AAEA,SAAgB,kDAAkD,CAChE,YAAkD;IAElD,OAAO,YAAY,CAAC,MAAM,CACxB,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE;QACV,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YAAE,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAA;QAChC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QAChD,OAAO,GAAG,CAAA;IACZ,CAAC,EACD,EAA8B,CAC/B,CAAA;AACH,CAAC;AAXD,gHAWC;AAED,SAAgB,0CAA0C,CACxD,YAAuC;IAEvC,OAAO,YAAY,CAAC,MAAM,CACxB,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE;QACV,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YAAE,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAA;QAChC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QAC/E,OAAO,GAAG,CAAA;IACZ,CAAC,EACD,EAA8B,CAC/B,CAAA;AACH,CAAC;AAXD,gGAWC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callbacks.js","sourceRoot":"","sources":["../../../src/sdk/types/callbacks.ts"],"names":[],"mappings":""}
|
|
@@ -5,6 +5,13 @@ export type ClientOptions = {
|
|
|
5
5
|
fakeProcessing?: boolean;
|
|
6
6
|
reqContext?: RequestContext;
|
|
7
7
|
metadata?: Record<string, string>;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
};
|
|
10
|
+
export type ClientOptionsWithRequestContext = {
|
|
11
|
+
fakeProcessing?: boolean;
|
|
12
|
+
reqContext: RequestContext;
|
|
13
|
+
metadata?: Record<string, string>;
|
|
14
|
+
timeout?: number;
|
|
8
15
|
};
|
|
9
16
|
export type InstrumentationOptions = {
|
|
10
17
|
requestLabel: string;
|
|
@@ -5,6 +5,11 @@ export type TranslateSyncRequest = {
|
|
|
5
5
|
context?: PolyglotAssetsRequest;
|
|
6
6
|
integration?: IntegrationKind;
|
|
7
7
|
};
|
|
8
|
+
export type TranslateAsyncRequestBody = TranslateSyncRequest & {
|
|
9
|
+
callbackUrl: string;
|
|
10
|
+
callbackToken: string;
|
|
11
|
+
originCorrelationId: string;
|
|
12
|
+
};
|
|
8
13
|
export type TranslateSyncContentUnits = {
|
|
9
14
|
id: string;
|
|
10
15
|
segments: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lokalise/polyglot-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Lokalise",
|
|
6
6
|
"url": "https://lokalise.com/"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"build": "shx rm -rf ./dist && tsc",
|
|
25
25
|
"build:publish": "shx rm -rf ./dist && tsc -p tsconfig.publish.json",
|
|
26
26
|
"lint": "eslint . --ext .ts",
|
|
27
|
-
"lint:fix": "eslint . --ext .ts --fix",
|
|
27
|
+
"lint:fix": "eslint . --ext .ts --fix && prettier --write . ",
|
|
28
28
|
"test": "vitest",
|
|
29
29
|
"test:coverage": "npm test -- --coverage",
|
|
30
30
|
"test:ci": "npm run test:coverage",
|
|
@@ -33,28 +33,28 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@amplitude/analytics-types": "^2.5.0",
|
|
36
|
-
"@lokalise/fastify-extras": "^17.0.
|
|
36
|
+
"@lokalise/fastify-extras": "^17.0.3",
|
|
37
37
|
"@lokalise/id-utils": "^1.0.0",
|
|
38
|
-
"@lokalise/node-core": "^9.
|
|
38
|
+
"@lokalise/node-core": "^9.12.0",
|
|
39
39
|
"@lokalise/zod-extras": "^2.0.1",
|
|
40
|
-
"undici": "^6.
|
|
40
|
+
"undici": "^6.11.1",
|
|
41
41
|
"undici-retry": "^5.0.2",
|
|
42
42
|
"zod": "^3.22.4"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@types/node": "^20.
|
|
45
|
+
"@types/node": "^20.12.5",
|
|
46
46
|
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
|
47
47
|
"@typescript-eslint/parser": "^7.4.0",
|
|
48
48
|
"@vitest/coverage-v8": "^0.34.6",
|
|
49
49
|
"auto-changelog": "^2.4.0",
|
|
50
50
|
"eslint": "^8.57.0",
|
|
51
51
|
"eslint-plugin-import": "^2.29.1",
|
|
52
|
-
"eslint-plugin-vitest": "^0.4.
|
|
53
|
-
"mockttp": "^3.10.
|
|
52
|
+
"eslint-plugin-vitest": "^0.4.1",
|
|
53
|
+
"mockttp": "^3.10.2",
|
|
54
54
|
"prettier": "^3.2.5",
|
|
55
55
|
"shx": "^0.3.4",
|
|
56
56
|
"ts-deepmerge": "^7.0.0",
|
|
57
|
-
"typescript": "5.4.
|
|
57
|
+
"typescript": "5.4.4",
|
|
58
58
|
"vitest": "^0.34.6"
|
|
59
59
|
}
|
|
60
60
|
}
|