@localess/cli 0.0.1-dev.20260218083711 → 0.0.1-dev.20260220080241
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 +35 -8
- package/dist/index.mjs +35 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
}
|