@lingo.dev/_sdk 0.16.5 → 0.17.1
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 +27 -0
- package/build/index.d.cts +35 -1
- package/build/index.d.ts +35 -1
- package/build/index.mjs +27 -0
- package/package.json +4 -4
package/build/index.cjs
CHANGED
|
@@ -135,6 +135,12 @@ var localizationParamsSchema = _zod2.default.object({
|
|
|
135
135
|
filePath: _zod2.default.string().optional(),
|
|
136
136
|
triggerType: _zod2.default.enum(["cli", "ci"]).optional()
|
|
137
137
|
});
|
|
138
|
+
var estimateItemsSchema = _zod2.default.array(
|
|
139
|
+
_zod2.default.object({
|
|
140
|
+
targetLocale: normalizedLocaleCodeSchema,
|
|
141
|
+
sourceChars: _zod2.default.number().int().nonnegative()
|
|
142
|
+
})
|
|
143
|
+
).min(1);
|
|
138
144
|
var LingoDotDevEngine = (_class = class _LingoDotDevEngine {
|
|
139
145
|
|
|
140
146
|
__init() {this.sessionId = _cuid2.createId.call(void 0, )}
|
|
@@ -799,6 +805,27 @@ var LingoDotDevEngine = (_class = class _LingoDotDevEngine {
|
|
|
799
805
|
throw error;
|
|
800
806
|
}
|
|
801
807
|
}
|
|
808
|
+
/**
|
|
809
|
+
* Estimate the cost of localizing content BEFORE submitting it.
|
|
810
|
+
* Pure computation server-side — nothing is translated, stored, or billed.
|
|
811
|
+
* @param items - Per-target-locale character counts of translatable source
|
|
812
|
+
* text (sum of source string lengths, excluding keys and markup). Duplicate
|
|
813
|
+
* locales are summed by the server.
|
|
814
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
|
815
|
+
* @returns Promise resolving to an approximate cost with per-locale breakdown
|
|
816
|
+
*/
|
|
817
|
+
async estimate(items, signal) {
|
|
818
|
+
const parsedItems = estimateItemsSchema.parse(items);
|
|
819
|
+
const url = `${this.config.apiUrl}/process/estimate`;
|
|
820
|
+
const res = await fetch(url, {
|
|
821
|
+
method: "POST",
|
|
822
|
+
headers: this.headers,
|
|
823
|
+
body: JSON.stringify({ items: parsedItems }),
|
|
824
|
+
signal
|
|
825
|
+
});
|
|
826
|
+
await _LingoDotDevEngine.throwOnHttpError(res, "Error estimating cost");
|
|
827
|
+
return res.json();
|
|
828
|
+
}
|
|
802
829
|
async whoami(signal) {
|
|
803
830
|
const url = `${this.config.apiUrl}/users/me`;
|
|
804
831
|
const res = await fetch(url, {
|
package/build/index.d.cts
CHANGED
|
@@ -23,6 +23,27 @@ declare const localizationParamsSchema: Z.ZodObject<{
|
|
|
23
23
|
ci: "ci";
|
|
24
24
|
}>>;
|
|
25
25
|
}, Z.core.$strip>;
|
|
26
|
+
/**
|
|
27
|
+
* Approximate localization cost returned by `/process/estimate`.
|
|
28
|
+
* `approximate` is always true — the estimate is a chars→tokens heuristic,
|
|
29
|
+
* not a quote. Actual cost may differ.
|
|
30
|
+
*/
|
|
31
|
+
type CostEstimate = {
|
|
32
|
+
approximate: boolean;
|
|
33
|
+
totals: {
|
|
34
|
+
sourceChars: number;
|
|
35
|
+
estimatedOutputTokens: number;
|
|
36
|
+
estimatedLlmCostUsd: number;
|
|
37
|
+
estimatedLocalizationCostUsd: number;
|
|
38
|
+
estimatedTotalCostUsd: number;
|
|
39
|
+
};
|
|
40
|
+
byLocale: {
|
|
41
|
+
targetLocale: string;
|
|
42
|
+
sourceChars: number;
|
|
43
|
+
estimatedOutputTokens: number;
|
|
44
|
+
estimatedCostUsd: number;
|
|
45
|
+
}[];
|
|
46
|
+
};
|
|
26
47
|
/**
|
|
27
48
|
* LingoDotDevEngine class for interacting with the LingoDotDev API
|
|
28
49
|
* A powerful localization engine that supports various content types including
|
|
@@ -182,6 +203,19 @@ declare class LingoDotDevEngine {
|
|
|
182
203
|
* @returns Promise resolving to a locale code (e.g., 'en', 'es', 'fr')
|
|
183
204
|
*/
|
|
184
205
|
recognizeLocale(text: string, signal?: AbortSignal): Promise<LocaleCode>;
|
|
206
|
+
/**
|
|
207
|
+
* Estimate the cost of localizing content BEFORE submitting it.
|
|
208
|
+
* Pure computation server-side — nothing is translated, stored, or billed.
|
|
209
|
+
* @param items - Per-target-locale character counts of translatable source
|
|
210
|
+
* text (sum of source string lengths, excluding keys and markup). Duplicate
|
|
211
|
+
* locales are summed by the server.
|
|
212
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
|
213
|
+
* @returns Promise resolving to an approximate cost with per-locale breakdown
|
|
214
|
+
*/
|
|
215
|
+
estimate(items: {
|
|
216
|
+
targetLocale: string;
|
|
217
|
+
sourceChars: number;
|
|
218
|
+
}[], signal?: AbortSignal): Promise<CostEstimate>;
|
|
185
219
|
whoami(signal?: AbortSignal): Promise<{
|
|
186
220
|
email: string;
|
|
187
221
|
id: string;
|
|
@@ -202,4 +236,4 @@ declare class LingoEngine extends LingoDotDevEngine {
|
|
|
202
236
|
constructor(config: Partial<Z.infer<typeof engineParamsSchema>>);
|
|
203
237
|
}
|
|
204
238
|
|
|
205
|
-
export { LingoDotDevEngine, LingoEngine, ReplexicaEngine };
|
|
239
|
+
export { type CostEstimate, LingoDotDevEngine, LingoEngine, ReplexicaEngine };
|
package/build/index.d.ts
CHANGED
|
@@ -23,6 +23,27 @@ declare const localizationParamsSchema: Z.ZodObject<{
|
|
|
23
23
|
ci: "ci";
|
|
24
24
|
}>>;
|
|
25
25
|
}, Z.core.$strip>;
|
|
26
|
+
/**
|
|
27
|
+
* Approximate localization cost returned by `/process/estimate`.
|
|
28
|
+
* `approximate` is always true — the estimate is a chars→tokens heuristic,
|
|
29
|
+
* not a quote. Actual cost may differ.
|
|
30
|
+
*/
|
|
31
|
+
type CostEstimate = {
|
|
32
|
+
approximate: boolean;
|
|
33
|
+
totals: {
|
|
34
|
+
sourceChars: number;
|
|
35
|
+
estimatedOutputTokens: number;
|
|
36
|
+
estimatedLlmCostUsd: number;
|
|
37
|
+
estimatedLocalizationCostUsd: number;
|
|
38
|
+
estimatedTotalCostUsd: number;
|
|
39
|
+
};
|
|
40
|
+
byLocale: {
|
|
41
|
+
targetLocale: string;
|
|
42
|
+
sourceChars: number;
|
|
43
|
+
estimatedOutputTokens: number;
|
|
44
|
+
estimatedCostUsd: number;
|
|
45
|
+
}[];
|
|
46
|
+
};
|
|
26
47
|
/**
|
|
27
48
|
* LingoDotDevEngine class for interacting with the LingoDotDev API
|
|
28
49
|
* A powerful localization engine that supports various content types including
|
|
@@ -182,6 +203,19 @@ declare class LingoDotDevEngine {
|
|
|
182
203
|
* @returns Promise resolving to a locale code (e.g., 'en', 'es', 'fr')
|
|
183
204
|
*/
|
|
184
205
|
recognizeLocale(text: string, signal?: AbortSignal): Promise<LocaleCode>;
|
|
206
|
+
/**
|
|
207
|
+
* Estimate the cost of localizing content BEFORE submitting it.
|
|
208
|
+
* Pure computation server-side — nothing is translated, stored, or billed.
|
|
209
|
+
* @param items - Per-target-locale character counts of translatable source
|
|
210
|
+
* text (sum of source string lengths, excluding keys and markup). Duplicate
|
|
211
|
+
* locales are summed by the server.
|
|
212
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
|
213
|
+
* @returns Promise resolving to an approximate cost with per-locale breakdown
|
|
214
|
+
*/
|
|
215
|
+
estimate(items: {
|
|
216
|
+
targetLocale: string;
|
|
217
|
+
sourceChars: number;
|
|
218
|
+
}[], signal?: AbortSignal): Promise<CostEstimate>;
|
|
185
219
|
whoami(signal?: AbortSignal): Promise<{
|
|
186
220
|
email: string;
|
|
187
221
|
id: string;
|
|
@@ -202,4 +236,4 @@ declare class LingoEngine extends LingoDotDevEngine {
|
|
|
202
236
|
constructor(config: Partial<Z.infer<typeof engineParamsSchema>>);
|
|
203
237
|
}
|
|
204
238
|
|
|
205
|
-
export { LingoDotDevEngine, LingoEngine, ReplexicaEngine };
|
|
239
|
+
export { type CostEstimate, LingoDotDevEngine, LingoEngine, ReplexicaEngine };
|
package/build/index.mjs
CHANGED
|
@@ -135,6 +135,12 @@ var localizationParamsSchema = Z.object({
|
|
|
135
135
|
filePath: Z.string().optional(),
|
|
136
136
|
triggerType: Z.enum(["cli", "ci"]).optional()
|
|
137
137
|
});
|
|
138
|
+
var estimateItemsSchema = Z.array(
|
|
139
|
+
Z.object({
|
|
140
|
+
targetLocale: normalizedLocaleCodeSchema,
|
|
141
|
+
sourceChars: Z.number().int().nonnegative()
|
|
142
|
+
})
|
|
143
|
+
).min(1);
|
|
138
144
|
var LingoDotDevEngine = class _LingoDotDevEngine {
|
|
139
145
|
config;
|
|
140
146
|
sessionId = createId();
|
|
@@ -799,6 +805,27 @@ var LingoDotDevEngine = class _LingoDotDevEngine {
|
|
|
799
805
|
throw error;
|
|
800
806
|
}
|
|
801
807
|
}
|
|
808
|
+
/**
|
|
809
|
+
* Estimate the cost of localizing content BEFORE submitting it.
|
|
810
|
+
* Pure computation server-side — nothing is translated, stored, or billed.
|
|
811
|
+
* @param items - Per-target-locale character counts of translatable source
|
|
812
|
+
* text (sum of source string lengths, excluding keys and markup). Duplicate
|
|
813
|
+
* locales are summed by the server.
|
|
814
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
|
815
|
+
* @returns Promise resolving to an approximate cost with per-locale breakdown
|
|
816
|
+
*/
|
|
817
|
+
async estimate(items, signal) {
|
|
818
|
+
const parsedItems = estimateItemsSchema.parse(items);
|
|
819
|
+
const url = `${this.config.apiUrl}/process/estimate`;
|
|
820
|
+
const res = await fetch(url, {
|
|
821
|
+
method: "POST",
|
|
822
|
+
headers: this.headers,
|
|
823
|
+
body: JSON.stringify({ items: parsedItems }),
|
|
824
|
+
signal
|
|
825
|
+
});
|
|
826
|
+
await _LingoDotDevEngine.throwOnHttpError(res, "Error estimating cost");
|
|
827
|
+
return res.json();
|
|
828
|
+
}
|
|
802
829
|
async whoami(signal) {
|
|
803
830
|
const url = `${this.config.apiUrl}/users/me`;
|
|
804
831
|
const res = await fetch(url, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingo.dev/_sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.1",
|
|
4
4
|
"description": "Lingo.dev JS SDK",
|
|
5
5
|
"private": false,
|
|
6
6
|
"repository": {
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"@paralleldrive/cuid2": "2.2.2",
|
|
28
28
|
"jsdom": "25.0.1",
|
|
29
29
|
"posthog-node": "5.14.0",
|
|
30
|
-
"zod": "4.
|
|
31
|
-
"@lingo.dev/_spec": "0.49.
|
|
30
|
+
"zod": "4.4.3",
|
|
31
|
+
"@lingo.dev/_spec": "0.49.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/jsdom": "21.1.7",
|
|
35
35
|
"tsup": "8.5.1",
|
|
36
36
|
"typescript": "5.9.3",
|
|
37
|
-
"vitest": "3.
|
|
37
|
+
"vitest": "3.2.6"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"dev": "tsup --watch",
|