@lingo.dev/_sdk 0.7.40 → 0.7.42
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/build/index.cjs +59 -9
- package/build/index.d.cts +4 -0
- package/build/index.d.ts +4 -0
- package/build/index.mjs +59 -9
- package/package.json +2 -2
package/build/index.cjs
CHANGED
@@ -41,7 +41,9 @@ var LingoDotDevEngine = class {
|
|
41
41
|
const workflowId = _cuid2.createId.call(void 0, );
|
42
42
|
for (let i = 0; i < chunkedPayload.length; i++) {
|
43
43
|
const chunk = chunkedPayload[i];
|
44
|
-
const percentageCompleted = Math.round(
|
44
|
+
const percentageCompleted = Math.round(
|
45
|
+
(i + 1) / chunkedPayload.length * 100
|
46
|
+
);
|
45
47
|
const processedPayloadChunk = await this.localizeChunk(
|
46
48
|
finalParams.sourceLocale,
|
47
49
|
finalParams.targetLocale,
|
@@ -128,9 +130,15 @@ var LingoDotDevEngine = class {
|
|
128
130
|
*/
|
129
131
|
countWordsInRecord(payload) {
|
130
132
|
if (Array.isArray(payload)) {
|
131
|
-
return payload.reduce(
|
133
|
+
return payload.reduce(
|
134
|
+
(acc, item) => acc + this.countWordsInRecord(item),
|
135
|
+
0
|
136
|
+
);
|
132
137
|
} else if (typeof payload === "object" && payload !== null) {
|
133
|
-
return Object.values(payload).reduce(
|
138
|
+
return Object.values(payload).reduce(
|
139
|
+
(acc, item) => acc + this.countWordsInRecord(item),
|
140
|
+
0
|
141
|
+
);
|
134
142
|
} else if (typeof payload === "string") {
|
135
143
|
return payload.trim().split(/\s+/).filter(Boolean).length;
|
136
144
|
} else {
|
@@ -161,7 +169,11 @@ var LingoDotDevEngine = class {
|
|
161
169
|
* @returns The localized text string
|
162
170
|
*/
|
163
171
|
async localizeText(text, params, progressCallback) {
|
164
|
-
const response = await this._localizeRaw(
|
172
|
+
const response = await this._localizeRaw(
|
173
|
+
{ text },
|
174
|
+
params,
|
175
|
+
progressCallback
|
176
|
+
);
|
165
177
|
return response.text || "";
|
166
178
|
}
|
167
179
|
/**
|
@@ -196,7 +208,11 @@ var LingoDotDevEngine = class {
|
|
196
208
|
* @returns Array of localized chat messages with preserved structure
|
197
209
|
*/
|
198
210
|
async localizeChat(chat, params, progressCallback) {
|
199
|
-
const localized = await this._localizeRaw(
|
211
|
+
const localized = await this._localizeRaw(
|
212
|
+
{ chat },
|
213
|
+
params,
|
214
|
+
progressCallback
|
215
|
+
);
|
200
216
|
return Object.entries(localized).map(([key, value]) => ({
|
201
217
|
name: chat[parseInt(key.split("_")[1])].name,
|
202
218
|
text: value
|
@@ -272,12 +288,22 @@ var LingoDotDevEngine = class {
|
|
272
288
|
extractedContent[getPath(element, attr)] = value;
|
273
289
|
}
|
274
290
|
});
|
275
|
-
Array.from(element.childNodes).filter(
|
291
|
+
Array.from(element.childNodes).filter(
|
292
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _7 => _7.textContent, 'optionalAccess', _8 => _8.trim, 'call', _9 => _9()])
|
293
|
+
).forEach(processNode);
|
276
294
|
}
|
277
295
|
};
|
278
|
-
Array.from(document.head.childNodes).filter(
|
279
|
-
|
280
|
-
|
296
|
+
Array.from(document.head.childNodes).filter(
|
297
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _10 => _10.textContent, 'optionalAccess', _11 => _11.trim, 'call', _12 => _12()])
|
298
|
+
).forEach(processNode);
|
299
|
+
Array.from(document.body.childNodes).filter(
|
300
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _13 => _13.textContent, 'optionalAccess', _14 => _14.trim, 'call', _15 => _15()])
|
301
|
+
).forEach(processNode);
|
302
|
+
const localizedContent = await this._localizeRaw(
|
303
|
+
extractedContent,
|
304
|
+
params,
|
305
|
+
progressCallback
|
306
|
+
);
|
281
307
|
document.documentElement.setAttribute("lang", params.targetLocale);
|
282
308
|
Object.entries(localizedContent).forEach(([path, value]) => {
|
283
309
|
const [nodePath, attribute] = path.split("#");
|
@@ -323,6 +349,30 @@ var LingoDotDevEngine = class {
|
|
323
349
|
const jsonResponse = await response.json();
|
324
350
|
return jsonResponse.locale;
|
325
351
|
}
|
352
|
+
async whoami() {
|
353
|
+
try {
|
354
|
+
const res = await fetch(`${this.config.apiUrl}/whoami`, {
|
355
|
+
method: "POST",
|
356
|
+
headers: {
|
357
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
358
|
+
ContentType: "application/json"
|
359
|
+
}
|
360
|
+
});
|
361
|
+
if (res.ok) {
|
362
|
+
const payload = await res.json();
|
363
|
+
if (!_optionalChain([payload, 'optionalAccess', _20 => _20.email])) {
|
364
|
+
return null;
|
365
|
+
}
|
366
|
+
return {
|
367
|
+
email: payload.email,
|
368
|
+
id: payload.id
|
369
|
+
};
|
370
|
+
}
|
371
|
+
return null;
|
372
|
+
} catch (error) {
|
373
|
+
return null;
|
374
|
+
}
|
375
|
+
}
|
326
376
|
};
|
327
377
|
var ReplexicaEngine = (_class = class _ReplexicaEngine extends LingoDotDevEngine {
|
328
378
|
static __initStatic() {this.hasWarnedDeprecation = false}
|
package/build/index.d.cts
CHANGED
@@ -146,6 +146,10 @@ declare class LingoDotDevEngine {
|
|
146
146
|
* @returns Promise resolving to a locale code (e.g., 'en', 'es', 'fr')
|
147
147
|
*/
|
148
148
|
recognizeLocale(text: string): Promise<LocaleCode>;
|
149
|
+
whoami(): Promise<{
|
150
|
+
email: string;
|
151
|
+
id: string;
|
152
|
+
} | null>;
|
149
153
|
}
|
150
154
|
/**
|
151
155
|
* @deprecated Use LingoDotDevEngine instead. This class is maintained for backwards compatibility.
|
package/build/index.d.ts
CHANGED
@@ -146,6 +146,10 @@ declare class LingoDotDevEngine {
|
|
146
146
|
* @returns Promise resolving to a locale code (e.g., 'en', 'es', 'fr')
|
147
147
|
*/
|
148
148
|
recognizeLocale(text: string): Promise<LocaleCode>;
|
149
|
+
whoami(): Promise<{
|
150
|
+
email: string;
|
151
|
+
id: string;
|
152
|
+
} | null>;
|
149
153
|
}
|
150
154
|
/**
|
151
155
|
* @deprecated Use LingoDotDevEngine instead. This class is maintained for backwards compatibility.
|
package/build/index.mjs
CHANGED
@@ -41,7 +41,9 @@ var LingoDotDevEngine = class {
|
|
41
41
|
const workflowId = createId();
|
42
42
|
for (let i = 0; i < chunkedPayload.length; i++) {
|
43
43
|
const chunk = chunkedPayload[i];
|
44
|
-
const percentageCompleted = Math.round(
|
44
|
+
const percentageCompleted = Math.round(
|
45
|
+
(i + 1) / chunkedPayload.length * 100
|
46
|
+
);
|
45
47
|
const processedPayloadChunk = await this.localizeChunk(
|
46
48
|
finalParams.sourceLocale,
|
47
49
|
finalParams.targetLocale,
|
@@ -128,9 +130,15 @@ var LingoDotDevEngine = class {
|
|
128
130
|
*/
|
129
131
|
countWordsInRecord(payload) {
|
130
132
|
if (Array.isArray(payload)) {
|
131
|
-
return payload.reduce(
|
133
|
+
return payload.reduce(
|
134
|
+
(acc, item) => acc + this.countWordsInRecord(item),
|
135
|
+
0
|
136
|
+
);
|
132
137
|
} else if (typeof payload === "object" && payload !== null) {
|
133
|
-
return Object.values(payload).reduce(
|
138
|
+
return Object.values(payload).reduce(
|
139
|
+
(acc, item) => acc + this.countWordsInRecord(item),
|
140
|
+
0
|
141
|
+
);
|
134
142
|
} else if (typeof payload === "string") {
|
135
143
|
return payload.trim().split(/\s+/).filter(Boolean).length;
|
136
144
|
} else {
|
@@ -161,7 +169,11 @@ var LingoDotDevEngine = class {
|
|
161
169
|
* @returns The localized text string
|
162
170
|
*/
|
163
171
|
async localizeText(text, params, progressCallback) {
|
164
|
-
const response = await this._localizeRaw(
|
172
|
+
const response = await this._localizeRaw(
|
173
|
+
{ text },
|
174
|
+
params,
|
175
|
+
progressCallback
|
176
|
+
);
|
165
177
|
return response.text || "";
|
166
178
|
}
|
167
179
|
/**
|
@@ -196,7 +208,11 @@ var LingoDotDevEngine = class {
|
|
196
208
|
* @returns Array of localized chat messages with preserved structure
|
197
209
|
*/
|
198
210
|
async localizeChat(chat, params, progressCallback) {
|
199
|
-
const localized = await this._localizeRaw(
|
211
|
+
const localized = await this._localizeRaw(
|
212
|
+
{ chat },
|
213
|
+
params,
|
214
|
+
progressCallback
|
215
|
+
);
|
200
216
|
return Object.entries(localized).map(([key, value]) => ({
|
201
217
|
name: chat[parseInt(key.split("_")[1])].name,
|
202
218
|
text: value
|
@@ -272,12 +288,22 @@ var LingoDotDevEngine = class {
|
|
272
288
|
extractedContent[getPath(element, attr)] = value;
|
273
289
|
}
|
274
290
|
});
|
275
|
-
Array.from(element.childNodes).filter(
|
291
|
+
Array.from(element.childNodes).filter(
|
292
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()
|
293
|
+
).forEach(processNode);
|
276
294
|
}
|
277
295
|
};
|
278
|
-
Array.from(document.head.childNodes).filter(
|
279
|
-
|
280
|
-
|
296
|
+
Array.from(document.head.childNodes).filter(
|
297
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()
|
298
|
+
).forEach(processNode);
|
299
|
+
Array.from(document.body.childNodes).filter(
|
300
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()
|
301
|
+
).forEach(processNode);
|
302
|
+
const localizedContent = await this._localizeRaw(
|
303
|
+
extractedContent,
|
304
|
+
params,
|
305
|
+
progressCallback
|
306
|
+
);
|
281
307
|
document.documentElement.setAttribute("lang", params.targetLocale);
|
282
308
|
Object.entries(localizedContent).forEach(([path, value]) => {
|
283
309
|
const [nodePath, attribute] = path.split("#");
|
@@ -323,6 +349,30 @@ var LingoDotDevEngine = class {
|
|
323
349
|
const jsonResponse = await response.json();
|
324
350
|
return jsonResponse.locale;
|
325
351
|
}
|
352
|
+
async whoami() {
|
353
|
+
try {
|
354
|
+
const res = await fetch(`${this.config.apiUrl}/whoami`, {
|
355
|
+
method: "POST",
|
356
|
+
headers: {
|
357
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
358
|
+
ContentType: "application/json"
|
359
|
+
}
|
360
|
+
});
|
361
|
+
if (res.ok) {
|
362
|
+
const payload = await res.json();
|
363
|
+
if (!payload?.email) {
|
364
|
+
return null;
|
365
|
+
}
|
366
|
+
return {
|
367
|
+
email: payload.email,
|
368
|
+
id: payload.id
|
369
|
+
};
|
370
|
+
}
|
371
|
+
return null;
|
372
|
+
} catch (error) {
|
373
|
+
return null;
|
374
|
+
}
|
375
|
+
}
|
326
376
|
};
|
327
377
|
var ReplexicaEngine = class _ReplexicaEngine extends LingoDotDevEngine {
|
328
378
|
static hasWarnedDeprecation = false;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lingo.dev/_sdk",
|
3
|
-
"version": "0.7.
|
3
|
+
"version": "0.7.42",
|
4
4
|
"description": "Lingo.dev JS SDK",
|
5
5
|
"private": false,
|
6
6
|
"publishConfig": {
|
@@ -21,7 +21,7 @@
|
|
21
21
|
"@paralleldrive/cuid2": "^2.2.2",
|
22
22
|
"jsdom": "^25.0.1",
|
23
23
|
"zod": "^3.24.1",
|
24
|
-
"@lingo.dev/_spec": "0.33.
|
24
|
+
"@lingo.dev/_spec": "0.33.2"
|
25
25
|
},
|
26
26
|
"devDependencies": {
|
27
27
|
"@types/jsdom": "^21.1.7",
|