@shipeasy/sdk 2.1.3 → 2.1.7

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.
@@ -143,6 +143,8 @@ interface BootstrapPayload {
143
143
  /** Set by getBootstrapHtml() for auto-init. Not part of evaluate() output. */
144
144
  apiKey?: string;
145
145
  apiUrl?: string;
146
+ /** When true, tEl() returns marker-wrapped strings for devtools label editing. */
147
+ editLabels?: boolean;
146
148
  }
147
149
  /**
148
150
  * Universal flags facade. Methods return safe defaults when the singleton
@@ -143,6 +143,8 @@ interface BootstrapPayload {
143
143
  /** Set by getBootstrapHtml() for auto-init. Not part of evaluate() output. */
144
144
  apiKey?: string;
145
145
  apiUrl?: string;
146
+ /** When true, tEl() returns marker-wrapped strings for devtools label editing. */
147
+ editLabels?: boolean;
146
148
  }
147
149
  /**
148
150
  * Universal flags facade. Methods return safe defaults when the singleton
@@ -784,9 +784,17 @@ function labelAttrs(key, variables, desc) {
784
784
  }
785
785
  var _createElement = null;
786
786
  var _I18N_SSR_SYM = /* @__PURE__ */ Symbol.for("@shipeasy/sdk:ssr-i18n");
787
+ var _EDIT_MODE_SSR_SYM = /* @__PURE__ */ Symbol.for("@shipeasy/sdk:ssr-edit-mode");
787
788
  function getSSRI18nStore() {
788
789
  return globalThis[_I18N_SSR_SYM]?.() ?? null;
789
790
  }
791
+ function isEditLabelsMode() {
792
+ if (typeof window !== "undefined") {
793
+ return !!window.__SE_BOOTSTRAP?.editLabels || new URLSearchParams(location.search).has("se_edit_labels");
794
+ }
795
+ const val = globalThis[_EDIT_MODE_SSR_SYM];
796
+ return typeof val === "boolean" ? val : typeof val === "function" ? val() : false;
797
+ }
790
798
  function interpolate(raw, variables) {
791
799
  if (!variables) return raw;
792
800
  return raw.replace(/\{\{(\w+)\}\}/g, (_, k) => String(variables[k] ?? `{{${k}}}`));
@@ -814,8 +822,9 @@ var i18n = {
814
822
  const hasTranslation = typeof window !== "undefined" && Boolean(window.i18n) || Boolean(getSSRI18nStore()?.strings[key]);
815
823
  const translated = hasTranslation ? this.t(key, variables) : void 0;
816
824
  const text = translated && translated !== key ? translated : fallback;
817
- if (!_createElement) return text;
818
- return _createElement("span", labelAttrs(key, variables, desc), text);
825
+ if (isEditLabelsMode()) return encodeLabelMarker(key, text);
826
+ if (_createElement) return _createElement("span", labelAttrs(key, variables, desc), text);
827
+ return text;
819
828
  },
820
829
  /** Wire up the element creator once at app startup (call before any tEl use). */
821
830
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -741,9 +741,17 @@ function labelAttrs(key, variables, desc) {
741
741
  }
742
742
  var _createElement = null;
743
743
  var _I18N_SSR_SYM = /* @__PURE__ */ Symbol.for("@shipeasy/sdk:ssr-i18n");
744
+ var _EDIT_MODE_SSR_SYM = /* @__PURE__ */ Symbol.for("@shipeasy/sdk:ssr-edit-mode");
744
745
  function getSSRI18nStore() {
745
746
  return globalThis[_I18N_SSR_SYM]?.() ?? null;
746
747
  }
748
+ function isEditLabelsMode() {
749
+ if (typeof window !== "undefined") {
750
+ return !!window.__SE_BOOTSTRAP?.editLabels || new URLSearchParams(location.search).has("se_edit_labels");
751
+ }
752
+ const val = globalThis[_EDIT_MODE_SSR_SYM];
753
+ return typeof val === "boolean" ? val : typeof val === "function" ? val() : false;
754
+ }
747
755
  function interpolate(raw, variables) {
748
756
  if (!variables) return raw;
749
757
  return raw.replace(/\{\{(\w+)\}\}/g, (_, k) => String(variables[k] ?? `{{${k}}}`));
@@ -771,8 +779,9 @@ var i18n = {
771
779
  const hasTranslation = typeof window !== "undefined" && Boolean(window.i18n) || Boolean(getSSRI18nStore()?.strings[key]);
772
780
  const translated = hasTranslation ? this.t(key, variables) : void 0;
773
781
  const text = translated && translated !== key ? translated : fallback;
774
- if (!_createElement) return text;
775
- return _createElement("span", labelAttrs(key, variables, desc), text);
782
+ if (isEditLabelsMode()) return encodeLabelMarker(key, text);
783
+ if (_createElement) return _createElement("span", labelAttrs(key, variables, desc), text);
784
+ return text;
776
785
  },
777
786
  /** Wire up the element creator once at app startup (call before any tEl use). */
778
787
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -136,6 +136,8 @@ interface BootstrapHtmlOptions {
136
136
  apiKey: string;
137
137
  /** i18n profile fed to the loader script. Defaults to "en:prod". */
138
138
  i18nProfile?: string;
139
+ /** When true, tEl() embeds label markers so the devtools can highlight them. */
140
+ editLabels?: boolean;
139
141
  }
140
142
  /**
141
143
  * Returns a vanilla-JS script string for a single <script> tag.
@@ -136,6 +136,8 @@ interface BootstrapHtmlOptions {
136
136
  apiKey: string;
137
137
  /** i18n profile fed to the loader script. Defaults to "en:prod". */
138
138
  i18nProfile?: string;
139
+ /** When true, tEl() embeds label markers so the devtools can highlight them. */
140
+ editLabels?: boolean;
139
141
  }
140
142
  /**
141
143
  * Returns a vanilla-JS script string for a single <script> tag.
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/server/index.ts
@@ -191,7 +201,7 @@ var FlagsClient = class {
191
201
  initialized = false;
192
202
  constructor(opts) {
193
203
  this.apiKey = opts.apiKey;
194
- this.baseUrl = (opts.baseUrl ?? "https://edge.shipeasy.dev").replace(/\/$/, "");
204
+ this.baseUrl = (opts.baseUrl ?? "https://cdn.shipeasy.ai").replace(/\/$/, "");
195
205
  this.env = opts.env ?? "prod";
196
206
  }
197
207
  async init() {
@@ -354,8 +364,12 @@ var FlagsClient = class {
354
364
  }
355
365
  };
356
366
  var _I18N_SSR_SYM = /* @__PURE__ */ Symbol.for("@shipeasy/sdk:ssr-i18n");
367
+ var _EDIT_MODE_SSR_SYM = /* @__PURE__ */ Symbol.for("@shipeasy/sdk:ssr-edit-mode");
357
368
  var _i18nALS = new import_node_async_hooks.AsyncLocalStorage();
358
369
  globalThis[_I18N_SSR_SYM] = () => _i18nALS.getStore() ?? null;
370
+ if (globalThis[_EDIT_MODE_SSR_SYM] === void 0) {
371
+ globalThis[_EDIT_MODE_SSR_SYM] = false;
372
+ }
359
373
  var i18n = {
360
374
  /**
361
375
  * Fetch translation labels for the current request and store them in an
@@ -438,15 +452,27 @@ async function shipeasy(opts) {
438
452
  const clientKey = opts.clientKey ?? opts.apiKey ?? "";
439
453
  const profile = opts.i18nDefaultProfile ?? "en:prod";
440
454
  flags.configure({ apiKey });
455
+ let resolvedUrlOverrides = opts.urlOverrides;
456
+ if (!resolvedUrlOverrides) {
457
+ try {
458
+ const { headers } = await import("next/headers");
459
+ const h = await Promise.resolve(headers());
460
+ const search = h.get("x-se-search") ?? "";
461
+ if (search) resolvedUrlOverrides = search;
462
+ } catch {
463
+ }
464
+ }
465
+ const editLabels = resolvedUrlOverrides ? new URLSearchParams(resolvedUrlOverrides).has("se_edit_labels") : false;
466
+ globalThis[_EDIT_MODE_SSR_SYM] = editLabels;
441
467
  await Promise.allSettled([flags.initOnce(), i18n.init(clientKey, profile)]);
442
- const bootstrap = flags.evaluate(opts.user ?? {}, opts.urlOverrides);
468
+ const bootstrap = flags.evaluate(opts.user ?? {}, resolvedUrlOverrides);
443
469
  const i18nData = i18n.getForRequest();
444
470
  return {
445
471
  flags: bootstrap.flags,
446
472
  configs: bootstrap.configs,
447
473
  experiments: bootstrap.experiments,
448
474
  getBootstrapHtml() {
449
- return getBootstrapHtml(bootstrap, i18nData, { apiKey: clientKey });
475
+ return getBootstrapHtml(bootstrap, i18nData, { apiKey: clientKey, editLabels });
450
476
  }
451
477
  };
452
478
  }
@@ -462,6 +488,7 @@ function getBootstrapHtml(bootstrap, i18nData, opts) {
462
488
  apiUrl
463
489
  };
464
490
  if (i18nData) payload.i18n = i18nData;
491
+ if (opts.editLabels) payload.editLabels = true;
465
492
  parts.push(`window.__SE_BOOTSTRAP=${JSON.stringify(payload)};`);
466
493
  if (i18nData?.strings && Object.keys(i18nData.strings).length > 0) {
467
494
  parts.push(
@@ -471,6 +498,9 @@ function getBootstrapHtml(bootstrap, i18nData, opts) {
471
498
  parts.push(
472
499
  `(function(){var s=document.createElement('script');s.src=${JSON.stringify(`${apiUrl}/sdk/i18n/loader.js`)};s.setAttribute('data-key',${JSON.stringify(opts.apiKey)});s.setAttribute('data-profile',${JSON.stringify(profile)});document.head.appendChild(s);})();`
473
500
  );
501
+ parts.push(
502
+ `(function(){var p=new URLSearchParams(location.search);if(p.has('se')||p.has('se_devtools')){var d=document.createElement('script');d.src='https://shipeasy.ai/se-devtools.js';document.head.appendChild(d);}})();`
503
+ );
474
504
  return parts.join("");
475
505
  }
476
506
  var flags = {
@@ -158,7 +158,7 @@ var FlagsClient = class {
158
158
  initialized = false;
159
159
  constructor(opts) {
160
160
  this.apiKey = opts.apiKey;
161
- this.baseUrl = (opts.baseUrl ?? "https://edge.shipeasy.dev").replace(/\/$/, "");
161
+ this.baseUrl = (opts.baseUrl ?? "https://cdn.shipeasy.ai").replace(/\/$/, "");
162
162
  this.env = opts.env ?? "prod";
163
163
  }
164
164
  async init() {
@@ -321,8 +321,12 @@ var FlagsClient = class {
321
321
  }
322
322
  };
323
323
  var _I18N_SSR_SYM = /* @__PURE__ */ Symbol.for("@shipeasy/sdk:ssr-i18n");
324
+ var _EDIT_MODE_SSR_SYM = /* @__PURE__ */ Symbol.for("@shipeasy/sdk:ssr-edit-mode");
324
325
  var _i18nALS = new AsyncLocalStorage();
325
326
  globalThis[_I18N_SSR_SYM] = () => _i18nALS.getStore() ?? null;
327
+ if (globalThis[_EDIT_MODE_SSR_SYM] === void 0) {
328
+ globalThis[_EDIT_MODE_SSR_SYM] = false;
329
+ }
326
330
  var i18n = {
327
331
  /**
328
332
  * Fetch translation labels for the current request and store them in an
@@ -405,15 +409,27 @@ async function shipeasy(opts) {
405
409
  const clientKey = opts.clientKey ?? opts.apiKey ?? "";
406
410
  const profile = opts.i18nDefaultProfile ?? "en:prod";
407
411
  flags.configure({ apiKey });
412
+ let resolvedUrlOverrides = opts.urlOverrides;
413
+ if (!resolvedUrlOverrides) {
414
+ try {
415
+ const { headers } = await import("next/headers");
416
+ const h = await Promise.resolve(headers());
417
+ const search = h.get("x-se-search") ?? "";
418
+ if (search) resolvedUrlOverrides = search;
419
+ } catch {
420
+ }
421
+ }
422
+ const editLabels = resolvedUrlOverrides ? new URLSearchParams(resolvedUrlOverrides).has("se_edit_labels") : false;
423
+ globalThis[_EDIT_MODE_SSR_SYM] = editLabels;
408
424
  await Promise.allSettled([flags.initOnce(), i18n.init(clientKey, profile)]);
409
- const bootstrap = flags.evaluate(opts.user ?? {}, opts.urlOverrides);
425
+ const bootstrap = flags.evaluate(opts.user ?? {}, resolvedUrlOverrides);
410
426
  const i18nData = i18n.getForRequest();
411
427
  return {
412
428
  flags: bootstrap.flags,
413
429
  configs: bootstrap.configs,
414
430
  experiments: bootstrap.experiments,
415
431
  getBootstrapHtml() {
416
- return getBootstrapHtml(bootstrap, i18nData, { apiKey: clientKey });
432
+ return getBootstrapHtml(bootstrap, i18nData, { apiKey: clientKey, editLabels });
417
433
  }
418
434
  };
419
435
  }
@@ -429,6 +445,7 @@ function getBootstrapHtml(bootstrap, i18nData, opts) {
429
445
  apiUrl
430
446
  };
431
447
  if (i18nData) payload.i18n = i18nData;
448
+ if (opts.editLabels) payload.editLabels = true;
432
449
  parts.push(`window.__SE_BOOTSTRAP=${JSON.stringify(payload)};`);
433
450
  if (i18nData?.strings && Object.keys(i18nData.strings).length > 0) {
434
451
  parts.push(
@@ -438,6 +455,9 @@ function getBootstrapHtml(bootstrap, i18nData, opts) {
438
455
  parts.push(
439
456
  `(function(){var s=document.createElement('script');s.src=${JSON.stringify(`${apiUrl}/sdk/i18n/loader.js`)};s.setAttribute('data-key',${JSON.stringify(opts.apiKey)});s.setAttribute('data-profile',${JSON.stringify(profile)});document.head.appendChild(s);})();`
440
457
  );
458
+ parts.push(
459
+ `(function(){var p=new URLSearchParams(location.search);if(p.has('se')||p.has('se_devtools')){var d=document.createElement('script');d.src='https://shipeasy.ai/se-devtools.js';document.head.appendChild(d);}})();`
460
+ );
441
461
  return parts.join("");
442
462
  }
443
463
  var flags = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipeasy/sdk",
3
- "version": "2.1.3",
3
+ "version": "2.1.7",
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",