@localess/cli 0.0.1-dev.20260218083711 → 0.0.1-dev.20260220221945

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.js CHANGED
@@ -24,7 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  ));
25
25
 
26
26
  // src/program.ts
27
- var import_commander6 = require("commander");
27
+ var import_commander7 = require("commander");
28
28
 
29
29
  // src/commands/login/index.ts
30
30
  var import_commander = require("commander");
@@ -73,6 +73,33 @@ var TTLCache = class {
73
73
 
74
74
  // src/client.ts
75
75
  var LOG_GROUP = `${FG_BLUE}[Localess:Client]${RESET}`;
76
+ async function fetchWithRetry(url, options, retryCount = 3, retryDelay = 500, debug) {
77
+ let attempt = 0;
78
+ let lastError;
79
+ while (attempt <= retryCount) {
80
+ try {
81
+ const response = await fetch(url, options);
82
+ if (!response.ok && response.status >= 500) {
83
+ if (debug) {
84
+ console.log(LOG_GROUP, `fetchWithRetry: HTTP ${response.status} on attempt ${attempt + 1}`);
85
+ }
86
+ lastError = new Error(`HTTP ${response.status}`);
87
+ } else {
88
+ return response;
89
+ }
90
+ } catch (err) {
91
+ if (debug) {
92
+ console.log(LOG_GROUP, `fetchWithRetry: network error on attempt ${attempt + 1}`, err);
93
+ }
94
+ lastError = err;
95
+ }
96
+ attempt++;
97
+ if (attempt <= retryCount) {
98
+ await new Promise((res) => setTimeout(res, retryDelay));
99
+ }
100
+ }
101
+ throw lastError;
102
+ }
76
103
  function localessClient(options) {
77
104
  if (options.debug) {
78
105
  console.log(LOG_GROUP, "Client Options : ", options);
@@ -103,7 +130,7 @@ function localessClient(options) {
103
130
  return cache.get(url);
104
131
  }
105
132
  try {
106
- const response = await fetch(url, fetchOptions);
133
+ const response = await fetchWithRetry(url, fetchOptions, options.retryCount, options.retryDelay, options.debug);
107
134
  if (options.debug) {
108
135
  console.log(LOG_GROUP, "getSpace status : ", response.status);
109
136
  }
@@ -142,7 +169,7 @@ function localessClient(options) {
142
169
  return cache.get(url);
143
170
  }
144
171
  try {
145
- const response = await fetch(url, fetchOptions);
172
+ const response = await fetchWithRetry(url, fetchOptions, options.retryCount, options.retryDelay, options.debug);
146
173
  if (options.debug) {
147
174
  console.log(LOG_GROUP, "getLinks status : ", response.status);
148
175
  }
@@ -180,7 +207,7 @@ function localessClient(options) {
180
207
  return cache.get(url);
181
208
  }
182
209
  try {
183
- const response = await fetch(url, fetchOptions);
210
+ const response = await fetchWithRetry(url, fetchOptions, options.retryCount, options.retryDelay, options.debug);
184
211
  if (options.debug) {
185
212
  console.log(LOG_GROUP, "getContentBySlug status : ", response.status);
186
213
  }
@@ -218,7 +245,7 @@ function localessClient(options) {
218
245
  return cache.get(url);
219
246
  }
220
247
  try {
221
- const response = await fetch(url, fetchOptions);
248
+ const response = await fetchWithRetry(url, fetchOptions, options.retryCount, options.retryDelay, options.debug);
222
249
  if (options.debug) {
223
250
  console.log(LOG_GROUP, "getContentById status : ", response.status);
224
251
  }
@@ -253,7 +280,7 @@ function localessClient(options) {
253
280
  return cache.get(url);
254
281
  }
255
282
  try {
256
- const response = await fetch(url, fetchOptions);
283
+ const response = await fetchWithRetry(url, fetchOptions, options.retryCount, options.retryDelay, options.debug);
257
284
  if (options.debug) {
258
285
  console.log(LOG_GROUP, "getTranslations status : ", response.status);
259
286
  }
@@ -280,14 +307,14 @@ function localessClient(options) {
280
307
  values
281
308
  };
282
309
  try {
283
- const response = await fetch(url, {
310
+ const response = await fetchWithRetry(url, {
284
311
  method: "POST",
285
312
  headers: {
286
313
  "X-API-KEY": options.token,
287
314
  ...fetchOptions.headers
288
315
  },
289
316
  body: JSON.stringify(body)
290
- });
317
+ }, options.retryCount, options.retryDelay, options.debug);
291
318
  if (options.debug) {
292
319
  console.log(LOG_GROUP, "updateTranslations status : ", response.status);
293
320
  }
@@ -311,7 +338,7 @@ function localessClient(options) {
311
338
  return cache.get(url);
312
339
  }
313
340
  try {
314
- const response = await fetch(url, fetchOptions);
341
+ const response = await fetchWithRetry(url, fetchOptions, options.retryCount, options.retryDelay, options.debug);
315
342
  if (options.debug) {
316
343
  console.log(LOG_GROUP, "getOpenApi status : ", response.status);
317
344
  }
@@ -474,12 +501,15 @@ var logoutCommand = new import_commander2.Command("logout").description("Logout
474
501
  });
475
502
 
476
503
  // src/commands/types/index.ts
504
+ var import_commander4 = require("commander");
505
+
506
+ // src/commands/types/generate/index.ts
477
507
  var import_commander3 = require("commander");
478
508
  var import_openapi_typescript = __toESM(require("openapi-typescript"));
479
509
  var import_node_path3 = require("path");
480
510
  var import_node_process = __toESM(require("process"));
481
511
  var TYPES_PATH = (0, import_node_path3.join)(import_node_process.default.cwd(), DEFAULT_CONFIG_DIR, "localess.d.ts");
482
- var typesCommand = new import_commander3.Command("types").description("Generate types for your schemas").action(async (options) => {
512
+ var typesGenerateCommand = new import_commander3.Command("generate").description("Generate types for your schemas").option("-f, --file <path>", "Path to the file where to save the generated types. Default is .localess/localess.d.ts", TYPES_PATH).action(async (options) => {
483
513
  console.log("Types in with options:", options);
484
514
  const session = await getSession();
485
515
  if (!session.isLoggedIn) {
@@ -503,18 +533,21 @@ var typesCommand = new import_commander3.Command("types").description("Generate
503
533
  };
504
534
  const ast = await (0, import_openapi_typescript.default)(minimalSpec, { exportType: true, rootTypes: true, rootTypesNoSchemaPrefix: true });
505
535
  const contents = (0, import_openapi_typescript.astToString)(ast);
506
- await writeFile(TYPES_PATH, contents);
507
- console.log(`Types generated successfully at ${TYPES_PATH}`);
536
+ await writeFile(options.file, contents);
537
+ console.log(`Types generated successfully at ${options.file}`);
508
538
  } catch (e) {
509
539
  console.error(e);
510
540
  }
511
541
  });
512
542
 
543
+ // src/commands/types/index.ts
544
+ var typesCommand = new import_commander4.Command("types").description("Generate types for your schemas").addCommand(typesGenerateCommand);
545
+
513
546
  // src/commands/translations/index.ts
514
- var import_commander5 = require("commander");
547
+ var import_commander6 = require("commander");
515
548
 
516
549
  // src/commands/translations/push/index.ts
517
- var import_commander4 = require("commander");
550
+ var import_commander5 = require("commander");
518
551
 
519
552
  // src/models/translations.ts
520
553
  var TranslationUpdateType = /* @__PURE__ */ ((TranslationUpdateType2) => {
@@ -533,7 +566,7 @@ var zTranslationUpdateSchema = import_zod.z.object({
533
566
  });
534
567
 
535
568
  // src/commands/translations/push/index.ts
536
- var translationsPushCommand = new import_commander4.Command("push").argument("<locale>", "Locale to push").description("Push locale translations to Localess").requiredOption("-f, --file <path>", "Path to the translations file to push").option("-t, --type <type>", `Push type. Possible values are : ${Object.values(TranslationUpdateType)}`, "add-missing" /* ADD_MISSING */).action(async (locale, options) => {
569
+ var translationsPushCommand = new import_commander5.Command("push").argument("<locale>", "Locale to push").description("Push locale translations to Localess").requiredOption("-f, --file <path>", "Path to the translations file to push").option("-t, --type <type>", `Push type. Possible values are : ${Object.values(TranslationUpdateType)}`, "add-missing" /* ADD_MISSING */).action(async (locale, options) => {
537
570
  console.log("Pushing translations with arguments:", locale);
538
571
  console.log("Pushing translations with options:", options);
539
572
  if (!zTranslationUpdateTypeSchema.safeParse(options.type).success) {
@@ -573,10 +606,10 @@ var translationsPushCommand = new import_commander4.Command("push").argument("<l
573
606
  });
574
607
 
575
608
  // src/commands/translations/index.ts
576
- var translationsCommand = new import_commander5.Command("translations").description("Manage translations").addCommand(translationsPushCommand);
609
+ var translationsCommand = new import_commander6.Command("translations").description("Manage translations").addCommand(translationsPushCommand);
577
610
 
578
611
  // src/program.ts
579
- var program = new import_commander6.Command();
612
+ var program = new import_commander7.Command();
580
613
  program.name("Localess CLI").description("CLI tool for Localess platform management").version("0.0.1");
581
614
  program.addCommand(loginCommand);
582
615
  program.addCommand(logoutCommand);
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/program.ts
4
- import { Command as Command6 } from "commander";
4
+ import { Command as Command7 } from "commander";
5
5
 
6
6
  // src/commands/login/index.ts
7
7
  import { Command } from "commander";
@@ -50,6 +50,33 @@ var TTLCache = class {
50
50
 
51
51
  // src/client.ts
52
52
  var LOG_GROUP = `${FG_BLUE}[Localess:Client]${RESET}`;
53
+ async function fetchWithRetry(url, options, retryCount = 3, retryDelay = 500, debug) {
54
+ let attempt = 0;
55
+ let lastError;
56
+ while (attempt <= retryCount) {
57
+ try {
58
+ const response = await fetch(url, options);
59
+ if (!response.ok && response.status >= 500) {
60
+ if (debug) {
61
+ console.log(LOG_GROUP, `fetchWithRetry: HTTP ${response.status} on attempt ${attempt + 1}`);
62
+ }
63
+ lastError = new Error(`HTTP ${response.status}`);
64
+ } else {
65
+ return response;
66
+ }
67
+ } catch (err) {
68
+ if (debug) {
69
+ console.log(LOG_GROUP, `fetchWithRetry: network error on attempt ${attempt + 1}`, err);
70
+ }
71
+ lastError = err;
72
+ }
73
+ attempt++;
74
+ if (attempt <= retryCount) {
75
+ await new Promise((res) => setTimeout(res, retryDelay));
76
+ }
77
+ }
78
+ throw lastError;
79
+ }
53
80
  function localessClient(options) {
54
81
  if (options.debug) {
55
82
  console.log(LOG_GROUP, "Client Options : ", options);
@@ -80,7 +107,7 @@ function localessClient(options) {
80
107
  return cache.get(url);
81
108
  }
82
109
  try {
83
- const response = await fetch(url, fetchOptions);
110
+ const response = await fetchWithRetry(url, fetchOptions, options.retryCount, options.retryDelay, options.debug);
84
111
  if (options.debug) {
85
112
  console.log(LOG_GROUP, "getSpace status : ", response.status);
86
113
  }
@@ -119,7 +146,7 @@ function localessClient(options) {
119
146
  return cache.get(url);
120
147
  }
121
148
  try {
122
- const response = await fetch(url, fetchOptions);
149
+ const response = await fetchWithRetry(url, fetchOptions, options.retryCount, options.retryDelay, options.debug);
123
150
  if (options.debug) {
124
151
  console.log(LOG_GROUP, "getLinks status : ", response.status);
125
152
  }
@@ -157,7 +184,7 @@ function localessClient(options) {
157
184
  return cache.get(url);
158
185
  }
159
186
  try {
160
- const response = await fetch(url, fetchOptions);
187
+ const response = await fetchWithRetry(url, fetchOptions, options.retryCount, options.retryDelay, options.debug);
161
188
  if (options.debug) {
162
189
  console.log(LOG_GROUP, "getContentBySlug status : ", response.status);
163
190
  }
@@ -195,7 +222,7 @@ function localessClient(options) {
195
222
  return cache.get(url);
196
223
  }
197
224
  try {
198
- const response = await fetch(url, fetchOptions);
225
+ const response = await fetchWithRetry(url, fetchOptions, options.retryCount, options.retryDelay, options.debug);
199
226
  if (options.debug) {
200
227
  console.log(LOG_GROUP, "getContentById status : ", response.status);
201
228
  }
@@ -230,7 +257,7 @@ function localessClient(options) {
230
257
  return cache.get(url);
231
258
  }
232
259
  try {
233
- const response = await fetch(url, fetchOptions);
260
+ const response = await fetchWithRetry(url, fetchOptions, options.retryCount, options.retryDelay, options.debug);
234
261
  if (options.debug) {
235
262
  console.log(LOG_GROUP, "getTranslations status : ", response.status);
236
263
  }
@@ -257,14 +284,14 @@ function localessClient(options) {
257
284
  values
258
285
  };
259
286
  try {
260
- const response = await fetch(url, {
287
+ const response = await fetchWithRetry(url, {
261
288
  method: "POST",
262
289
  headers: {
263
290
  "X-API-KEY": options.token,
264
291
  ...fetchOptions.headers
265
292
  },
266
293
  body: JSON.stringify(body)
267
- });
294
+ }, options.retryCount, options.retryDelay, options.debug);
268
295
  if (options.debug) {
269
296
  console.log(LOG_GROUP, "updateTranslations status : ", response.status);
270
297
  }
@@ -288,7 +315,7 @@ function localessClient(options) {
288
315
  return cache.get(url);
289
316
  }
290
317
  try {
291
- const response = await fetch(url, fetchOptions);
318
+ const response = await fetchWithRetry(url, fetchOptions, options.retryCount, options.retryDelay, options.debug);
292
319
  if (options.debug) {
293
320
  console.log(LOG_GROUP, "getOpenApi status : ", response.status);
294
321
  }
@@ -451,12 +478,15 @@ var logoutCommand = new Command2("logout").description("Logout from Localess CLI
451
478
  });
452
479
 
453
480
  // src/commands/types/index.ts
481
+ import { Command as Command4 } from "commander";
482
+
483
+ // src/commands/types/generate/index.ts
454
484
  import { Command as Command3 } from "commander";
455
485
  import openapiTS, { astToString } from "openapi-typescript";
456
486
  import { join as join2 } from "path";
457
487
  import process3 from "process";
458
488
  var TYPES_PATH = join2(process3.cwd(), DEFAULT_CONFIG_DIR, "localess.d.ts");
459
- var typesCommand = new Command3("types").description("Generate types for your schemas").action(async (options) => {
489
+ var typesGenerateCommand = new Command3("generate").description("Generate types for your schemas").option("-f, --file <path>", "Path to the file where to save the generated types. Default is .localess/localess.d.ts", TYPES_PATH).action(async (options) => {
460
490
  console.log("Types in with options:", options);
461
491
  const session = await getSession();
462
492
  if (!session.isLoggedIn) {
@@ -480,18 +510,21 @@ var typesCommand = new Command3("types").description("Generate types for your sc
480
510
  };
481
511
  const ast = await openapiTS(minimalSpec, { exportType: true, rootTypes: true, rootTypesNoSchemaPrefix: true });
482
512
  const contents = astToString(ast);
483
- await writeFile(TYPES_PATH, contents);
484
- console.log(`Types generated successfully at ${TYPES_PATH}`);
513
+ await writeFile(options.file, contents);
514
+ console.log(`Types generated successfully at ${options.file}`);
485
515
  } catch (e) {
486
516
  console.error(e);
487
517
  }
488
518
  });
489
519
 
520
+ // src/commands/types/index.ts
521
+ var typesCommand = new Command4("types").description("Generate types for your schemas").addCommand(typesGenerateCommand);
522
+
490
523
  // src/commands/translations/index.ts
491
- import { Command as Command5 } from "commander";
524
+ import { Command as Command6 } from "commander";
492
525
 
493
526
  // src/commands/translations/push/index.ts
494
- import { Command as Command4 } from "commander";
527
+ import { Command as Command5 } from "commander";
495
528
 
496
529
  // src/models/translations.ts
497
530
  var TranslationUpdateType = /* @__PURE__ */ ((TranslationUpdateType2) => {
@@ -510,7 +543,7 @@ var zTranslationUpdateSchema = z.object({
510
543
  });
511
544
 
512
545
  // src/commands/translations/push/index.ts
513
- var translationsPushCommand = new Command4("push").argument("<locale>", "Locale to push").description("Push locale translations to Localess").requiredOption("-f, --file <path>", "Path to the translations file to push").option("-t, --type <type>", `Push type. Possible values are : ${Object.values(TranslationUpdateType)}`, "add-missing" /* ADD_MISSING */).action(async (locale, options) => {
546
+ var translationsPushCommand = new Command5("push").argument("<locale>", "Locale to push").description("Push locale translations to Localess").requiredOption("-f, --file <path>", "Path to the translations file to push").option("-t, --type <type>", `Push type. Possible values are : ${Object.values(TranslationUpdateType)}`, "add-missing" /* ADD_MISSING */).action(async (locale, options) => {
514
547
  console.log("Pushing translations with arguments:", locale);
515
548
  console.log("Pushing translations with options:", options);
516
549
  if (!zTranslationUpdateTypeSchema.safeParse(options.type).success) {
@@ -550,10 +583,10 @@ var translationsPushCommand = new Command4("push").argument("<locale>", "Locale
550
583
  });
551
584
 
552
585
  // src/commands/translations/index.ts
553
- var translationsCommand = new Command5("translations").description("Manage translations").addCommand(translationsPushCommand);
586
+ var translationsCommand = new Command6("translations").description("Manage translations").addCommand(translationsPushCommand);
554
587
 
555
588
  // src/program.ts
556
- var program = new Command6();
589
+ var program = new Command7();
557
590
  program.name("Localess CLI").description("CLI tool for Localess platform management").version("0.0.1");
558
591
  program.addCommand(loginCommand);
559
592
  program.addCommand(logoutCommand);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localess/cli",
3
- "version": "0.0.1-dev.20260218083711",
3
+ "version": "0.0.1-dev.20260220221945",
4
4
  "description": "Localess Command Line.",
5
5
  "keywords": [
6
6
  "localess",