ai-l10n-core 1.5.0 → 1.5.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/CHANGELOG.md CHANGED
@@ -5,6 +5,15 @@ All notable changes to the core package will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.5.1] - 2026-04-17
9
+
10
+ ### Changed
11
+ - Set default client identifier on `translate()` requests.
12
+ - Standardized the `reason` type used in API error responses to a fixed union of values.
13
+
14
+ ### Fixed
15
+ - API documentation
16
+
8
17
  ## [1.5.0] - 2026-04-16
9
18
 
10
19
  ### Added
@@ -12,7 +21,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
12
21
  ```typescript
13
22
  type ApiResponse<T> =
14
23
  | { success: true; data: T }
15
- | { success: false; reason: string; message: string };
24
+ | {
25
+ success: false;
26
+ reason:
27
+ | "paymentRequired"
28
+ | "translationError"
29
+ | "requestTooLarge"
30
+ | "badRequest"
31
+ | "unauthorized"
32
+ | "forbidden"
33
+ | "rateLimited"
34
+ | "serverError"
35
+ | "networkError"
36
+ | "noApiKey";
37
+ message: string;
38
+ };
16
39
  ```
17
40
  - **Balance API** — New `getBalance(apiKey)` method on `L10nTranslationService` retrieves the current character balance from the `GET /v2/balance` endpoint. Returns `ApiResponse<BalanceResponse>` (always resolves, never throws).
18
41
  - **`BalanceResponse` type** — `{ currentBalance: number }`
@@ -24,7 +47,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
24
47
  - The method always resolves — it never throws
25
48
  - On success: `{ success: true, data: TranslationResult, currentBalance?: number }`
26
49
  - On error: `{ success: false, reason: string, message: string, currentBalance?: number }`
27
- - `reason` values: `"noApiKey"`, `"unauthorized"`, `"paymentRequired"`, `"badRequest"`, `"requestTooLarge"`, `"serverError"`, `"networkError"`, `"translationError"`
50
+ - `reason` values: "paymentRequired", "translationError", "requestTooLarge", "badRequest", "unauthorized", "forbidden", "rateLimited", "serverError", "networkError", "noApiKey"
28
51
  - **`getLanguages()` now requires `apiKey` as its first parameter** (bug fix — previously no API key was sent)
29
52
  - New signature: `getLanguages(apiKey: string, options?: ...): Promise<ApiResponse<SupportedLanguagesResponse>>`
30
53
  - Returns structured `ApiResponse` instead of throwing; error reasons: `noApiKey`, `unauthorized`, `badRequest`, `networkError`
package/README.md CHANGED
@@ -150,7 +150,7 @@ Retrieves the current character balance available for translation.
150
150
 
151
151
  **Returns:** `Promise<ApiResponse<BalanceResponse>>` — Always resolves (never throws). Check `success` to determine success or failure. On success, `data.currentBalance` holds the number of characters available.
152
152
 
153
- **Error reasons:** `noApiKey`, `unauthorized`, `networkError`
153
+ **Error reasons:** `noApiKey`, `unauthorized`, `serverError`, `networkError`
154
154
 
155
155
  **Example:**
156
156
  ```typescript
@@ -172,7 +172,7 @@ Predicts possible language codes from a text input (language name in English or
172
172
 
173
173
  **Returns:** `Promise<ApiResponse<Language[]>>` — Always resolves (never throws). On success, `data` is an array of predicted languages with codes and names.
174
174
 
175
- **Error reasons:** `networkError`
175
+ **Error reasons:** , `serverError`, `networkError`
176
176
 
177
177
  ##### `getLanguages(apiKey: string, options?: { codes?: string[]; proficiencyLevels?: LanguageProficiencyLevel[] }): Promise<ApiResponse<SupportedLanguagesResponse>>`
178
178
 
@@ -186,7 +186,7 @@ Retrieves a list of supported languages, optionally filtered by language codes o
186
186
 
187
187
  **Returns:** `Promise<ApiResponse<SupportedLanguagesResponse>>` — Always resolves (never throws). On success, `data.languages` is an array of `SupportedLanguage` entries.
188
188
 
189
- **Error reasons:** `noApiKey`, `unauthorized`, `badRequest`, `networkError`
189
+ **Error reasons:** `noApiKey`, `unauthorized`, `badRequest`, `serverError`, `networkError`
190
190
 
191
191
  **Example:**
192
192
  ```typescript
@@ -216,7 +216,21 @@ const response = await service.getLanguages(apiKey, {
216
216
  ```typescript
217
217
  type ApiResponse<T> =
218
218
  | { success: true; data: T }
219
- | { success: false; reason: string; message: string };
219
+ | {
220
+ success: false;
221
+ reason:
222
+ | "paymentRequired"
223
+ | "translationError"
224
+ | "requestTooLarge"
225
+ | "badRequest"
226
+ | "unauthorized"
227
+ | "forbidden"
228
+ | "rateLimited"
229
+ | "serverError"
230
+ | "networkError"
231
+ | "noApiKey";
232
+ message: string;
233
+ };
220
234
  ```
221
235
 
222
236
  All methods that contact the API return an `ApiResponse<T>`. Check `success` before accessing `data`.
@@ -389,14 +403,16 @@ All methods always resolve — they never throw. Check `response.success`:
389
403
 
390
404
  | `reason` | Description |
391
405
  |----------|-------------|
392
- | `"noApiKey"` | API key was not provided |
393
- | `"unauthorized"` | API key is invalid (401) |
394
406
  | `"paymentRequired"` | Insufficient balance (402); `currentBalance` is set |
395
- | `"badRequest"` | Validation error (400); `message` contains details |
407
+ | `"translationError"` | Translation failed; API returned `finishReason: "error"` |
396
408
  | `"requestTooLarge"` | Request exceeds 5 MB (413) |
409
+ | `"badRequest"` | Validation error (400); `message` contains details |
410
+ | `"unauthorized"` | API key is invalid (401) |
411
+ | `"forbidden"` | API key lacks required permissions (403) |
412
+ | `"rateLimited"` | Requests are being rate-limited (429) |
397
413
  | `"serverError"` | Internal server error (500) |
398
414
  | `"networkError"` | Connection or other failure |
399
- | `"translationError"` | API returned `finishReason: "error"` |
415
+ | `"noApiKey"` | API key was not provided |
400
416
 
401
417
  ##### `getBalance()` error reasons
402
418
 
@@ -404,6 +420,7 @@ All methods always resolve — they never throw. Check `response.success`:
404
420
  |----------|-------------|
405
421
  | `"noApiKey"` | API key was not provided |
406
422
  | `"unauthorized"` | API key is invalid (401) |
423
+ | `"serverError"` | Internal server error (500) |
407
424
  | `"networkError"` | Connection or other failure |
408
425
 
409
426
  ##### `getLanguages()` error reasons
@@ -413,12 +430,14 @@ All methods always resolve — they never throw. Check `response.success`:
413
430
  | `"noApiKey"` | API key was not provided |
414
431
  | `"unauthorized"` | API key is invalid (401) |
415
432
  | `"badRequest"` | Validation error (400); `message` contains details |
433
+ | `"serverError"` | Internal server error (500) |
416
434
  | `"networkError"` | Connection or other failure |
417
435
 
418
436
  ##### `predictLanguages()` error reasons
419
437
 
420
438
  | `reason` | Description |
421
439
  |----------|-------------|
440
+ | `"serverError"` | Internal server error (500) |
422
441
  | `"networkError"` | Connection or other failure |
423
442
 
424
443
  ---
@@ -93,7 +93,7 @@ export type ApiResponse<T> = {
93
93
  data: T;
94
94
  } | {
95
95
  success: false;
96
- reason: string;
96
+ reason: "paymentRequired" | "translationError" | "requestTooLarge" | "badRequest" | "unauthorized" | "forbidden" | "rateLimited" | "serverError" | "networkError" | "noApiKey";
97
97
  message: string;
98
98
  };
99
99
  /**
@@ -93,6 +93,9 @@ class L10nTranslationService {
93
93
  return apiKeyError;
94
94
  }
95
95
  this.logger.logInfo(`Starting translation to ${request.targetLanguageCode}`);
96
+ if (!request.client) {
97
+ request.client = "ai-l10n-core-npmjs";
98
+ }
96
99
  const response = await fetch(`${constants_1.URLS.API_BASE}/v2/translate`, {
97
100
  method: "POST",
98
101
  headers: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-l10n-core",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Platform-independent core for AI-powered localization — translation API client, language utilities, and shared types",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",