@shipeasy/sdk 3.0.0 → 3.0.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/dist/server/index.js +8 -2
- package/dist/server/index.mjs +8 -2
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -387,6 +387,7 @@ var _I18N_SSR_SYM = /* @__PURE__ */ Symbol.for("@shipeasy/sdk:ssr-i18n");
|
|
|
387
387
|
var _EDIT_MODE_SSR_SYM = /* @__PURE__ */ Symbol.for("@shipeasy/sdk:ssr-edit-mode");
|
|
388
388
|
var _i18nALS = new import_node_async_hooks.AsyncLocalStorage();
|
|
389
389
|
var _I18N_CACHE_SYM = /* @__PURE__ */ Symbol.for("@shipeasy/sdk:ssr-i18n-cache");
|
|
390
|
+
var I18N_CACHE_TTL_MS = 6e4;
|
|
390
391
|
var _i18nCache = globalThis[_I18N_CACHE_SYM] ?? (globalThis[_I18N_CACHE_SYM] = /* @__PURE__ */ new Map());
|
|
391
392
|
globalThis[_I18N_SSR_SYM] = () => {
|
|
392
393
|
const fromALS = _i18nALS.getStore();
|
|
@@ -432,14 +433,19 @@ var i18n = {
|
|
|
432
433
|
const existingALS = _i18nALS.getStore();
|
|
433
434
|
if (existingALS && Object.keys(existingALS.strings).length > 0) return;
|
|
434
435
|
const cached = _i18nCache.get(profile);
|
|
435
|
-
if (cached && Object.keys(cached.strings).length > 0) {
|
|
436
|
+
if (cached && Object.keys(cached.strings).length > 0 && Date.now() - cached.fetchedAt < I18N_CACHE_TTL_MS) {
|
|
436
437
|
_i18nALS.enterWith(cached);
|
|
437
438
|
return;
|
|
438
439
|
}
|
|
439
440
|
const labels = await fetchLabelsForSSR({ key, profile, cdnBaseUrl }).catch(() => null);
|
|
440
441
|
const locale = profile.split(":")[0] || "en";
|
|
441
442
|
const store = { strings: labels?.strings ?? {}, locale };
|
|
442
|
-
if (Object.keys(store.strings).length > 0)
|
|
443
|
+
if (Object.keys(store.strings).length > 0) {
|
|
444
|
+
_i18nCache.set(profile, { ...store, fetchedAt: Date.now() });
|
|
445
|
+
} else if (cached && Object.keys(cached.strings).length > 0) {
|
|
446
|
+
_i18nALS.enterWith(cached);
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
443
449
|
_i18nALS.enterWith(store);
|
|
444
450
|
},
|
|
445
451
|
/**
|
package/dist/server/index.mjs
CHANGED
|
@@ -344,6 +344,7 @@ var _I18N_SSR_SYM = /* @__PURE__ */ Symbol.for("@shipeasy/sdk:ssr-i18n");
|
|
|
344
344
|
var _EDIT_MODE_SSR_SYM = /* @__PURE__ */ Symbol.for("@shipeasy/sdk:ssr-edit-mode");
|
|
345
345
|
var _i18nALS = new AsyncLocalStorage();
|
|
346
346
|
var _I18N_CACHE_SYM = /* @__PURE__ */ Symbol.for("@shipeasy/sdk:ssr-i18n-cache");
|
|
347
|
+
var I18N_CACHE_TTL_MS = 6e4;
|
|
347
348
|
var _i18nCache = globalThis[_I18N_CACHE_SYM] ?? (globalThis[_I18N_CACHE_SYM] = /* @__PURE__ */ new Map());
|
|
348
349
|
globalThis[_I18N_SSR_SYM] = () => {
|
|
349
350
|
const fromALS = _i18nALS.getStore();
|
|
@@ -389,14 +390,19 @@ var i18n = {
|
|
|
389
390
|
const existingALS = _i18nALS.getStore();
|
|
390
391
|
if (existingALS && Object.keys(existingALS.strings).length > 0) return;
|
|
391
392
|
const cached = _i18nCache.get(profile);
|
|
392
|
-
if (cached && Object.keys(cached.strings).length > 0) {
|
|
393
|
+
if (cached && Object.keys(cached.strings).length > 0 && Date.now() - cached.fetchedAt < I18N_CACHE_TTL_MS) {
|
|
393
394
|
_i18nALS.enterWith(cached);
|
|
394
395
|
return;
|
|
395
396
|
}
|
|
396
397
|
const labels = await fetchLabelsForSSR({ key, profile, cdnBaseUrl }).catch(() => null);
|
|
397
398
|
const locale = profile.split(":")[0] || "en";
|
|
398
399
|
const store = { strings: labels?.strings ?? {}, locale };
|
|
399
|
-
if (Object.keys(store.strings).length > 0)
|
|
400
|
+
if (Object.keys(store.strings).length > 0) {
|
|
401
|
+
_i18nCache.set(profile, { ...store, fetchedAt: Date.now() });
|
|
402
|
+
} else if (cached && Object.keys(cached.strings).length > 0) {
|
|
403
|
+
_i18nALS.enterWith(cached);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
400
406
|
_i18nALS.enterWith(store);
|
|
401
407
|
},
|
|
402
408
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shipeasy/sdk",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Shipeasy SDK — feature gates, runtime configs, experiments, and metrics for the Shipeasy hosted service.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"homepage": "https://shipeasy.ai",
|