langsys-js-typescript 0.2.0 → 0.2.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
@@ -1,3 +1,13 @@
1
+ ## 0.2.1 - 2026-06-11
2
+
3
+ ### Changed
4
+
5
+ - **Migrated off the deprecated API routes onto the current endpoints.** No public API change — the same `t()`, `<Phrase>`, and `<Translate>` usage now talks to:
6
+ - Reads: `GET /translations?project_id=…&locale=…` (was the deprecated `GET /projects/{id}/translations`).
7
+ - Writes: `POST /translatable-items` with a unified `{ project_id, translatable_items: [{ type: 'phrase' | 'content_block', … }] }` body (was the deprecated `POST /projects/{id}/tokens` and `POST /projects/{id}/content-blocks`).
8
+ - Missing-phrase registration now chunks into batches of 200 to respect the `/translatable-items` per-request cap.
9
+ - Added `LangsysAppAPI.createTranslatableItems()` as the single write entry point for both phrases and content blocks.
10
+
1
11
  ## 0.1.0 - 2026-05-19
2
12
 
3
13
  Initial public release. Framework-agnostic TypeScript SDK for the Langsys Translation Manager — the foundation that `langsys-js-svelte` (and future framework-specific bindings) build on.
package/dist/index.d.mts CHANGED
@@ -511,6 +511,12 @@ declare class LangsysAppAPIClass {
511
511
  setBaseUrl(url: string): void;
512
512
  validate(config: iLangsysConfig): Promise<ResponseObject>;
513
513
  getTranslations(locale: string): Promise<ResponseObject>;
514
+ /**
515
+ * Register phrases and/or content blocks via the current unified endpoint.
516
+ * Each item carries `type: 'phrase' | 'content_block'`. Replaces the
517
+ * deprecated `projects/{id}/tokens` and `projects/{id}/content-blocks` routes.
518
+ */
519
+ createTranslatableItems(items: Array<Record<string, unknown>>): Promise<ResponseObject>;
514
520
  post(path: string, data?: Record<string, unknown>): Promise<ResponseObject>;
515
521
  get(path: string, data?: Record<string, unknown>): Promise<ResponseObject>;
516
522
  delete(path: string, data?: Record<string, unknown>): Promise<ResponseObject>;
package/dist/index.d.ts CHANGED
@@ -511,6 +511,12 @@ declare class LangsysAppAPIClass {
511
511
  setBaseUrl(url: string): void;
512
512
  validate(config: iLangsysConfig): Promise<ResponseObject>;
513
513
  getTranslations(locale: string): Promise<ResponseObject>;
514
+ /**
515
+ * Register phrases and/or content blocks via the current unified endpoint.
516
+ * Each item carries `type: 'phrase' | 'content_block'`. Replaces the
517
+ * deprecated `projects/{id}/tokens` and `projects/{id}/content-blocks` routes.
518
+ */
519
+ createTranslatableItems(items: Array<Record<string, unknown>>): Promise<ResponseObject>;
514
520
  post(path: string, data?: Record<string, unknown>): Promise<ResponseObject>;
515
521
  get(path: string, data?: Record<string, unknown>): Promise<ResponseObject>;
516
522
  delete(path: string, data?: Record<string, unknown>): Promise<ResponseObject>;
package/dist/index.js CHANGED
@@ -93,7 +93,18 @@ var LangsysAppAPIClass = class {
93
93
  return await this.get("authorize-project/[projectid]");
94
94
  }
95
95
  async getTranslations(locale) {
96
- return await this.get("projects/[projectid]/translations", { locale });
96
+ return await this.get("translations", { project_id: this.config.projectid, locale });
97
+ }
98
+ /**
99
+ * Register phrases and/or content blocks via the current unified endpoint.
100
+ * Each item carries `type: 'phrase' | 'content_block'`. Replaces the
101
+ * deprecated `projects/{id}/tokens` and `projects/{id}/content-blocks` routes.
102
+ */
103
+ async createTranslatableItems(items) {
104
+ return await this.post("translatable-items", {
105
+ project_id: this.config.projectid,
106
+ translatable_items: items
107
+ });
97
108
  }
98
109
  async post(path, data = {}) {
99
110
  return await this.send("POST", path, data);
@@ -480,20 +491,23 @@ var Translations = class {
480
491
  if (!this.missingTokens.length) return false;
481
492
  this.debug.log("CREATE MISSING TOKENS", this.missingTokens);
482
493
  try {
483
- const tokensForApi = this.missingTokens.map((tokenObj) => ({
484
- projectid: tokenObj.projectid,
485
- token: tokenObj.token,
494
+ const phraseItems = this.missingTokens.map((tokenObj) => ({
495
+ type: "phrase",
496
+ phrase: tokenObj.token,
486
497
  category: tokenObj.category || null
487
498
  }));
488
- const response = await LangsysAppAPI.post("projects/[projectid]/tokens", {
489
- tokens: tokensForApi
490
- });
491
- if (!response.status) {
492
- if (response.errors) {
493
- this.debug.log("TOKEN UPDATE FAIL", this.missingTokens);
494
- this.debug.error("Error updating project tokens", response.errors);
499
+ const BATCH_SIZE = 200;
500
+ for (let offset = 0; offset < phraseItems.length; offset += BATCH_SIZE) {
501
+ const response = await LangsysAppAPI.createTranslatableItems(
502
+ phraseItems.slice(offset, offset + BATCH_SIZE)
503
+ );
504
+ if (!response.status) {
505
+ if (response.errors) {
506
+ this.debug.log("TOKEN UPDATE FAIL", this.missingTokens);
507
+ this.debug.error("Error updating project tokens", response.errors);
508
+ }
509
+ return false;
495
510
  }
496
- return false;
497
511
  }
498
512
  this.missingTokens.forEach((tokenObj) => {
499
513
  const lookupCat = tokenObj.category || "__uncategorized__";
@@ -1048,10 +1062,16 @@ async function registerContentBlock(contentBlock) {
1048
1062
  return { status: true };
1049
1063
  }
1050
1064
  try {
1051
- const response = await LangsysAppAPI.post(
1052
- "projects/[projectid]/content-blocks",
1053
- contentBlock
1054
- );
1065
+ const response = await LangsysAppAPI.createTranslatableItems([
1066
+ {
1067
+ type: "content_block",
1068
+ custom_id: contentBlock.custom_id,
1069
+ category: contentBlock.category,
1070
+ content: contentBlock.content,
1071
+ label: contentBlock.label,
1072
+ phrases: contentBlock.tokens.map((phrase) => ({ phrase }))
1073
+ }
1074
+ ]);
1055
1075
  if (!response.status) {
1056
1076
  logger.error("Could not save content block", response.errors);
1057
1077
  return { status: false, errors: response.errors };