@shipeasy/sdk 1.1.0 → 2.0.0
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/client/index.d.mts +20 -9
- package/dist/client/index.d.ts +20 -9
- package/dist/client/index.js +52 -12
- package/dist/client/index.mjs +46 -12
- package/dist/server/index.d.mts +15 -1
- package/dist/server/index.d.ts +15 -1
- package/dist/server/index.js +32 -0
- package/dist/server/index.mjs +31 -0
- package/package.json +7 -3
package/dist/client/index.d.mts
CHANGED
|
@@ -137,14 +137,25 @@ declare const flags: {
|
|
|
137
137
|
/** True once identify() has completed and flags are available. */
|
|
138
138
|
readonly ready: boolean;
|
|
139
139
|
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
140
|
+
declare const LABEL_MARKER_START = "\uFFF9";
|
|
141
|
+
declare const LABEL_MARKER_SEP = "\uFFFA";
|
|
142
|
+
declare const LABEL_MARKER_END = "\uFFFB";
|
|
143
|
+
declare const LABEL_MARKER_RE: RegExp;
|
|
144
|
+
declare function encodeLabelMarker(key: string, value: string): string;
|
|
145
|
+
interface LabelAttrs {
|
|
146
|
+
"data-label": string;
|
|
147
|
+
"data-variables"?: string;
|
|
148
|
+
"data-label-desc"?: string;
|
|
149
|
+
}
|
|
150
|
+
declare function labelAttrs(key: string, variables?: Record<string, string | number>, desc?: string): LabelAttrs;
|
|
146
151
|
declare const i18n: {
|
|
147
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Look up `key` in the active translation profile. When the profile
|
|
154
|
+
* hasn't been fetched yet (SSR, CDN downtime, missing key), interpolate
|
|
155
|
+
* `fallback` instead — `fallback` is the source-of-truth English copy
|
|
156
|
+
* and is mandatory so the page never renders a raw key.
|
|
157
|
+
*/
|
|
158
|
+
t(key: string, fallback: string, variables?: Record<string, string | number>): string;
|
|
148
159
|
/**
|
|
149
160
|
* Translate a key and return a framework element (e.g. React <span>)
|
|
150
161
|
* carrying `data-label` / `data-variables` attributes so the ShipEasy
|
|
@@ -157,7 +168,7 @@ declare const i18n: {
|
|
|
157
168
|
* Falls back to a plain translated string if `createElement` was not
|
|
158
169
|
* configured (e.g. server-side or in non-JSX contexts).
|
|
159
170
|
*/
|
|
160
|
-
tEl(key: string, variables?: Record<string, string | number>, desc?: string): any;
|
|
171
|
+
tEl(key: string, fallback: string, variables?: Record<string, string | number>, desc?: string): any;
|
|
161
172
|
/** Wire up the element creator once at app startup (call before any tEl use). */
|
|
162
173
|
configure(opts: {
|
|
163
174
|
createElement: (tag: string, props: object, children: string) => any;
|
|
@@ -170,4 +181,4 @@ declare const i18n: {
|
|
|
170
181
|
onUpdate(cb: () => void): () => void;
|
|
171
182
|
};
|
|
172
183
|
|
|
173
|
-
export { type ExperimentResult, FlagsClientBrowser, type FlagsClientBrowserEnv, type FlagsClientBrowserOptions, type ShipeasySdkBridge, type User, _resetShipeasyForTests, attachDevtools, configureShipeasy, flags, getShipeasyClient, i18n, isDevtoolsRequested, loadDevtools, readConfigOverride, readExpOverride, readGateOverride, version };
|
|
184
|
+
export { type ExperimentResult, FlagsClientBrowser, type FlagsClientBrowserEnv, type FlagsClientBrowserOptions, LABEL_MARKER_END, LABEL_MARKER_RE, LABEL_MARKER_SEP, LABEL_MARKER_START, type LabelAttrs, type ShipeasySdkBridge, type User, _resetShipeasyForTests, attachDevtools, configureShipeasy, encodeLabelMarker, flags, getShipeasyClient, i18n, isDevtoolsRequested, labelAttrs, loadDevtools, readConfigOverride, readExpOverride, readGateOverride, version };
|
package/dist/client/index.d.ts
CHANGED
|
@@ -137,14 +137,25 @@ declare const flags: {
|
|
|
137
137
|
/** True once identify() has completed and flags are available. */
|
|
138
138
|
readonly ready: boolean;
|
|
139
139
|
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
140
|
+
declare const LABEL_MARKER_START = "\uFFF9";
|
|
141
|
+
declare const LABEL_MARKER_SEP = "\uFFFA";
|
|
142
|
+
declare const LABEL_MARKER_END = "\uFFFB";
|
|
143
|
+
declare const LABEL_MARKER_RE: RegExp;
|
|
144
|
+
declare function encodeLabelMarker(key: string, value: string): string;
|
|
145
|
+
interface LabelAttrs {
|
|
146
|
+
"data-label": string;
|
|
147
|
+
"data-variables"?: string;
|
|
148
|
+
"data-label-desc"?: string;
|
|
149
|
+
}
|
|
150
|
+
declare function labelAttrs(key: string, variables?: Record<string, string | number>, desc?: string): LabelAttrs;
|
|
146
151
|
declare const i18n: {
|
|
147
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Look up `key` in the active translation profile. When the profile
|
|
154
|
+
* hasn't been fetched yet (SSR, CDN downtime, missing key), interpolate
|
|
155
|
+
* `fallback` instead — `fallback` is the source-of-truth English copy
|
|
156
|
+
* and is mandatory so the page never renders a raw key.
|
|
157
|
+
*/
|
|
158
|
+
t(key: string, fallback: string, variables?: Record<string, string | number>): string;
|
|
148
159
|
/**
|
|
149
160
|
* Translate a key and return a framework element (e.g. React <span>)
|
|
150
161
|
* carrying `data-label` / `data-variables` attributes so the ShipEasy
|
|
@@ -157,7 +168,7 @@ declare const i18n: {
|
|
|
157
168
|
* Falls back to a plain translated string if `createElement` was not
|
|
158
169
|
* configured (e.g. server-side or in non-JSX contexts).
|
|
159
170
|
*/
|
|
160
|
-
tEl(key: string, variables?: Record<string, string | number>, desc?: string): any;
|
|
171
|
+
tEl(key: string, fallback: string, variables?: Record<string, string | number>, desc?: string): any;
|
|
161
172
|
/** Wire up the element creator once at app startup (call before any tEl use). */
|
|
162
173
|
configure(opts: {
|
|
163
174
|
createElement: (tag: string, props: object, children: string) => any;
|
|
@@ -170,4 +181,4 @@ declare const i18n: {
|
|
|
170
181
|
onUpdate(cb: () => void): () => void;
|
|
171
182
|
};
|
|
172
183
|
|
|
173
|
-
export { type ExperimentResult, FlagsClientBrowser, type FlagsClientBrowserEnv, type FlagsClientBrowserOptions, type ShipeasySdkBridge, type User, _resetShipeasyForTests, attachDevtools, configureShipeasy, flags, getShipeasyClient, i18n, isDevtoolsRequested, loadDevtools, readConfigOverride, readExpOverride, readGateOverride, version };
|
|
184
|
+
export { type ExperimentResult, FlagsClientBrowser, type FlagsClientBrowserEnv, type FlagsClientBrowserOptions, LABEL_MARKER_END, LABEL_MARKER_RE, LABEL_MARKER_SEP, LABEL_MARKER_START, type LabelAttrs, type ShipeasySdkBridge, type User, _resetShipeasyForTests, attachDevtools, configureShipeasy, encodeLabelMarker, flags, getShipeasyClient, i18n, isDevtoolsRequested, labelAttrs, loadDevtools, readConfigOverride, readExpOverride, readGateOverride, version };
|
package/dist/client/index.js
CHANGED
|
@@ -21,13 +21,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var client_exports = {};
|
|
22
22
|
__export(client_exports, {
|
|
23
23
|
FlagsClientBrowser: () => FlagsClientBrowser,
|
|
24
|
+
LABEL_MARKER_END: () => LABEL_MARKER_END,
|
|
25
|
+
LABEL_MARKER_RE: () => LABEL_MARKER_RE,
|
|
26
|
+
LABEL_MARKER_SEP: () => LABEL_MARKER_SEP,
|
|
27
|
+
LABEL_MARKER_START: () => LABEL_MARKER_START,
|
|
24
28
|
_resetShipeasyForTests: () => _resetShipeasyForTests,
|
|
25
29
|
attachDevtools: () => attachDevtools,
|
|
26
30
|
configureShipeasy: () => configureShipeasy,
|
|
31
|
+
encodeLabelMarker: () => encodeLabelMarker,
|
|
27
32
|
flags: () => flags,
|
|
28
33
|
getShipeasyClient: () => getShipeasyClient,
|
|
29
34
|
i18n: () => i18n,
|
|
30
35
|
isDevtoolsRequested: () => isDevtoolsRequested,
|
|
36
|
+
labelAttrs: () => labelAttrs,
|
|
31
37
|
loadDevtools: () => loadDevtools,
|
|
32
38
|
readConfigOverride: () => readConfigOverride,
|
|
33
39
|
readExpOverride: () => readExpOverride,
|
|
@@ -448,13 +454,15 @@ var FlagsClientBrowser = class {
|
|
|
448
454
|
this.evalResult = data;
|
|
449
455
|
}
|
|
450
456
|
getFlag(name) {
|
|
457
|
+
if (this.evalResult === null) return false;
|
|
451
458
|
const ov = readGateOverride(name);
|
|
452
459
|
if (ov !== null) return ov;
|
|
453
|
-
return this.evalResult
|
|
460
|
+
return this.evalResult.flags[name] ?? false;
|
|
454
461
|
}
|
|
455
462
|
getConfig(name, decode) {
|
|
463
|
+
if (this.evalResult === null) return void 0;
|
|
456
464
|
const ov = readConfigOverride(name);
|
|
457
|
-
const raw = ov !== void 0 ? ov : this.evalResult
|
|
465
|
+
const raw = ov !== void 0 ? ov : this.evalResult.configs?.[name];
|
|
458
466
|
if (raw === void 0) return void 0;
|
|
459
467
|
if (!decode) return raw;
|
|
460
468
|
try {
|
|
@@ -695,11 +703,41 @@ var flags = {
|
|
|
695
703
|
return _client?.ready ?? false;
|
|
696
704
|
}
|
|
697
705
|
};
|
|
706
|
+
var LABEL_MARKER_START = "\uFFF9";
|
|
707
|
+
var LABEL_MARKER_SEP = "\uFFFA";
|
|
708
|
+
var LABEL_MARKER_END = "\uFFFB";
|
|
709
|
+
var LABEL_MARKER_RE = /([^]+)([^]*)/g;
|
|
710
|
+
function encodeLabelMarker(key, value) {
|
|
711
|
+
return `${LABEL_MARKER_START}${key}${LABEL_MARKER_SEP}${value}${LABEL_MARKER_END}`;
|
|
712
|
+
}
|
|
713
|
+
function labelAttrs(key, variables, desc) {
|
|
714
|
+
const attrs = { "data-label": key };
|
|
715
|
+
if (variables) attrs["data-variables"] = JSON.stringify(variables);
|
|
716
|
+
if (desc) attrs["data-label-desc"] = desc;
|
|
717
|
+
return attrs;
|
|
718
|
+
}
|
|
698
719
|
var _createElement = null;
|
|
720
|
+
function interpolate(template, variables) {
|
|
721
|
+
if (!variables) return template;
|
|
722
|
+
let out = template;
|
|
723
|
+
for (const name of Object.keys(variables)) {
|
|
724
|
+
out = out.replace(new RegExp(`\\{\\{${name}\\}\\}`, "g"), String(variables[name]));
|
|
725
|
+
}
|
|
726
|
+
return out;
|
|
727
|
+
}
|
|
699
728
|
var i18n = {
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
729
|
+
/**
|
|
730
|
+
* Look up `key` in the active translation profile. When the profile
|
|
731
|
+
* hasn't been fetched yet (SSR, CDN downtime, missing key), interpolate
|
|
732
|
+
* `fallback` instead — `fallback` is the source-of-truth English copy
|
|
733
|
+
* and is mandatory so the page never renders a raw key.
|
|
734
|
+
*/
|
|
735
|
+
t(key, fallback, variables) {
|
|
736
|
+
if (typeof window !== "undefined" && window.i18n) {
|
|
737
|
+
const v = window.i18n.t(key, variables);
|
|
738
|
+
if (v !== key) return v;
|
|
739
|
+
}
|
|
740
|
+
return interpolate(fallback, variables);
|
|
703
741
|
},
|
|
704
742
|
/**
|
|
705
743
|
* Translate a key and return a framework element (e.g. React <span>)
|
|
@@ -713,14 +751,10 @@ var i18n = {
|
|
|
713
751
|
* Falls back to a plain translated string if `createElement` was not
|
|
714
752
|
* configured (e.g. server-side or in non-JSX contexts).
|
|
715
753
|
*/
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
const text = this.t(key, variables);
|
|
754
|
+
tEl(key, fallback, variables, desc) {
|
|
755
|
+
const text = this.t(key, fallback, variables);
|
|
719
756
|
if (!_createElement) return text;
|
|
720
|
-
|
|
721
|
-
if (variables) props["data-variables"] = JSON.stringify(variables);
|
|
722
|
-
if (desc) props["data-label-desc"] = desc;
|
|
723
|
-
return _createElement("span", props, text);
|
|
757
|
+
return _createElement("span", labelAttrs(key, variables, desc), text);
|
|
724
758
|
},
|
|
725
759
|
/** Wire up the element creator once at app startup (call before any tEl use). */
|
|
726
760
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -764,13 +798,19 @@ var i18n = {
|
|
|
764
798
|
// Annotate the CommonJS export names for ESM import in node:
|
|
765
799
|
0 && (module.exports = {
|
|
766
800
|
FlagsClientBrowser,
|
|
801
|
+
LABEL_MARKER_END,
|
|
802
|
+
LABEL_MARKER_RE,
|
|
803
|
+
LABEL_MARKER_SEP,
|
|
804
|
+
LABEL_MARKER_START,
|
|
767
805
|
_resetShipeasyForTests,
|
|
768
806
|
attachDevtools,
|
|
769
807
|
configureShipeasy,
|
|
808
|
+
encodeLabelMarker,
|
|
770
809
|
flags,
|
|
771
810
|
getShipeasyClient,
|
|
772
811
|
i18n,
|
|
773
812
|
isDevtoolsRequested,
|
|
813
|
+
labelAttrs,
|
|
774
814
|
loadDevtools,
|
|
775
815
|
readConfigOverride,
|
|
776
816
|
readExpOverride,
|
package/dist/client/index.mjs
CHANGED
|
@@ -412,13 +412,15 @@ var FlagsClientBrowser = class {
|
|
|
412
412
|
this.evalResult = data;
|
|
413
413
|
}
|
|
414
414
|
getFlag(name) {
|
|
415
|
+
if (this.evalResult === null) return false;
|
|
415
416
|
const ov = readGateOverride(name);
|
|
416
417
|
if (ov !== null) return ov;
|
|
417
|
-
return this.evalResult
|
|
418
|
+
return this.evalResult.flags[name] ?? false;
|
|
418
419
|
}
|
|
419
420
|
getConfig(name, decode) {
|
|
421
|
+
if (this.evalResult === null) return void 0;
|
|
420
422
|
const ov = readConfigOverride(name);
|
|
421
|
-
const raw = ov !== void 0 ? ov : this.evalResult
|
|
423
|
+
const raw = ov !== void 0 ? ov : this.evalResult.configs?.[name];
|
|
422
424
|
if (raw === void 0) return void 0;
|
|
423
425
|
if (!decode) return raw;
|
|
424
426
|
try {
|
|
@@ -659,11 +661,41 @@ var flags = {
|
|
|
659
661
|
return _client?.ready ?? false;
|
|
660
662
|
}
|
|
661
663
|
};
|
|
664
|
+
var LABEL_MARKER_START = "\uFFF9";
|
|
665
|
+
var LABEL_MARKER_SEP = "\uFFFA";
|
|
666
|
+
var LABEL_MARKER_END = "\uFFFB";
|
|
667
|
+
var LABEL_MARKER_RE = /([^]+)([^]*)/g;
|
|
668
|
+
function encodeLabelMarker(key, value) {
|
|
669
|
+
return `${LABEL_MARKER_START}${key}${LABEL_MARKER_SEP}${value}${LABEL_MARKER_END}`;
|
|
670
|
+
}
|
|
671
|
+
function labelAttrs(key, variables, desc) {
|
|
672
|
+
const attrs = { "data-label": key };
|
|
673
|
+
if (variables) attrs["data-variables"] = JSON.stringify(variables);
|
|
674
|
+
if (desc) attrs["data-label-desc"] = desc;
|
|
675
|
+
return attrs;
|
|
676
|
+
}
|
|
662
677
|
var _createElement = null;
|
|
678
|
+
function interpolate(template, variables) {
|
|
679
|
+
if (!variables) return template;
|
|
680
|
+
let out = template;
|
|
681
|
+
for (const name of Object.keys(variables)) {
|
|
682
|
+
out = out.replace(new RegExp(`\\{\\{${name}\\}\\}`, "g"), String(variables[name]));
|
|
683
|
+
}
|
|
684
|
+
return out;
|
|
685
|
+
}
|
|
663
686
|
var i18n = {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
687
|
+
/**
|
|
688
|
+
* Look up `key` in the active translation profile. When the profile
|
|
689
|
+
* hasn't been fetched yet (SSR, CDN downtime, missing key), interpolate
|
|
690
|
+
* `fallback` instead — `fallback` is the source-of-truth English copy
|
|
691
|
+
* and is mandatory so the page never renders a raw key.
|
|
692
|
+
*/
|
|
693
|
+
t(key, fallback, variables) {
|
|
694
|
+
if (typeof window !== "undefined" && window.i18n) {
|
|
695
|
+
const v = window.i18n.t(key, variables);
|
|
696
|
+
if (v !== key) return v;
|
|
697
|
+
}
|
|
698
|
+
return interpolate(fallback, variables);
|
|
667
699
|
},
|
|
668
700
|
/**
|
|
669
701
|
* Translate a key and return a framework element (e.g. React <span>)
|
|
@@ -677,14 +709,10 @@ var i18n = {
|
|
|
677
709
|
* Falls back to a plain translated string if `createElement` was not
|
|
678
710
|
* configured (e.g. server-side or in non-JSX contexts).
|
|
679
711
|
*/
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
const text = this.t(key, variables);
|
|
712
|
+
tEl(key, fallback, variables, desc) {
|
|
713
|
+
const text = this.t(key, fallback, variables);
|
|
683
714
|
if (!_createElement) return text;
|
|
684
|
-
|
|
685
|
-
if (variables) props["data-variables"] = JSON.stringify(variables);
|
|
686
|
-
if (desc) props["data-label-desc"] = desc;
|
|
687
|
-
return _createElement("span", props, text);
|
|
715
|
+
return _createElement("span", labelAttrs(key, variables, desc), text);
|
|
688
716
|
},
|
|
689
717
|
/** Wire up the element creator once at app startup (call before any tEl use). */
|
|
690
718
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -727,13 +755,19 @@ var i18n = {
|
|
|
727
755
|
};
|
|
728
756
|
export {
|
|
729
757
|
FlagsClientBrowser,
|
|
758
|
+
LABEL_MARKER_END,
|
|
759
|
+
LABEL_MARKER_RE,
|
|
760
|
+
LABEL_MARKER_SEP,
|
|
761
|
+
LABEL_MARKER_START,
|
|
730
762
|
_resetShipeasyForTests,
|
|
731
763
|
attachDevtools,
|
|
732
764
|
configureShipeasy,
|
|
765
|
+
encodeLabelMarker,
|
|
733
766
|
flags,
|
|
734
767
|
getShipeasyClient,
|
|
735
768
|
i18n,
|
|
736
769
|
isDevtoolsRequested,
|
|
770
|
+
labelAttrs,
|
|
737
771
|
loadDevtools,
|
|
738
772
|
readConfigOverride,
|
|
739
773
|
readExpOverride,
|
package/dist/server/index.d.mts
CHANGED
|
@@ -40,6 +40,20 @@ declare class FlagsClient {
|
|
|
40
40
|
getExperiment<P extends Record<string, unknown>>(name: string, user: User, defaultParams: P, decode?: (raw: unknown) => P): ExperimentResult<P>;
|
|
41
41
|
track(userId: string, eventName: string, props?: Record<string, unknown>): void;
|
|
42
42
|
}
|
|
43
|
+
interface LabelFile {
|
|
44
|
+
v: number;
|
|
45
|
+
profile: string;
|
|
46
|
+
chunk: string;
|
|
47
|
+
strings: Record<string, string>;
|
|
48
|
+
}
|
|
49
|
+
interface FetchLabelsOptions {
|
|
50
|
+
key: string;
|
|
51
|
+
profile: string;
|
|
52
|
+
chunk?: string;
|
|
53
|
+
cdnBaseUrl?: string;
|
|
54
|
+
timeoutMs?: number;
|
|
55
|
+
}
|
|
56
|
+
declare function fetchLabelsForSSR(opts: FetchLabelsOptions): Promise<LabelFile | null>;
|
|
43
57
|
declare function configureShipeasyServer(opts: FlagsClientOptions): FlagsClient;
|
|
44
58
|
declare function getShipeasyServerClient(): FlagsClient | null;
|
|
45
59
|
declare function _resetShipeasyServerForTests(): void;
|
|
@@ -60,4 +74,4 @@ declare const flags: {
|
|
|
60
74
|
track(userId: string, eventName: string, props?: Record<string, unknown>): void;
|
|
61
75
|
};
|
|
62
76
|
|
|
63
|
-
export { type ExperimentResult, FlagsClient, type FlagsClientEnv, type FlagsClientOptions, type User, _resetShipeasyServerForTests, configureShipeasyServer, flags, getShipeasyServerClient, version };
|
|
77
|
+
export { type ExperimentResult, type FetchLabelsOptions, FlagsClient, type FlagsClientEnv, type FlagsClientOptions, type LabelFile, type User, _resetShipeasyServerForTests, configureShipeasyServer, fetchLabelsForSSR, flags, getShipeasyServerClient, version };
|
package/dist/server/index.d.ts
CHANGED
|
@@ -40,6 +40,20 @@ declare class FlagsClient {
|
|
|
40
40
|
getExperiment<P extends Record<string, unknown>>(name: string, user: User, defaultParams: P, decode?: (raw: unknown) => P): ExperimentResult<P>;
|
|
41
41
|
track(userId: string, eventName: string, props?: Record<string, unknown>): void;
|
|
42
42
|
}
|
|
43
|
+
interface LabelFile {
|
|
44
|
+
v: number;
|
|
45
|
+
profile: string;
|
|
46
|
+
chunk: string;
|
|
47
|
+
strings: Record<string, string>;
|
|
48
|
+
}
|
|
49
|
+
interface FetchLabelsOptions {
|
|
50
|
+
key: string;
|
|
51
|
+
profile: string;
|
|
52
|
+
chunk?: string;
|
|
53
|
+
cdnBaseUrl?: string;
|
|
54
|
+
timeoutMs?: number;
|
|
55
|
+
}
|
|
56
|
+
declare function fetchLabelsForSSR(opts: FetchLabelsOptions): Promise<LabelFile | null>;
|
|
43
57
|
declare function configureShipeasyServer(opts: FlagsClientOptions): FlagsClient;
|
|
44
58
|
declare function getShipeasyServerClient(): FlagsClient | null;
|
|
45
59
|
declare function _resetShipeasyServerForTests(): void;
|
|
@@ -60,4 +74,4 @@ declare const flags: {
|
|
|
60
74
|
track(userId: string, eventName: string, props?: Record<string, unknown>): void;
|
|
61
75
|
};
|
|
62
76
|
|
|
63
|
-
export { type ExperimentResult, FlagsClient, type FlagsClientEnv, type FlagsClientOptions, type User, _resetShipeasyServerForTests, configureShipeasyServer, flags, getShipeasyServerClient, version };
|
|
77
|
+
export { type ExperimentResult, type FetchLabelsOptions, FlagsClient, type FlagsClientEnv, type FlagsClientOptions, type LabelFile, type User, _resetShipeasyServerForTests, configureShipeasyServer, fetchLabelsForSSR, flags, getShipeasyServerClient, version };
|
package/dist/server/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __export(server_exports, {
|
|
|
23
23
|
FlagsClient: () => FlagsClient,
|
|
24
24
|
_resetShipeasyServerForTests: () => _resetShipeasyServerForTests,
|
|
25
25
|
configureShipeasyServer: () => configureShipeasyServer,
|
|
26
|
+
fetchLabelsForSSR: () => fetchLabelsForSSR,
|
|
26
27
|
flags: () => flags,
|
|
27
28
|
getShipeasyServerClient: () => getShipeasyServerClient,
|
|
28
29
|
version: () => version
|
|
@@ -271,6 +272,36 @@ var FlagsClient = class {
|
|
|
271
272
|
}).catch((err) => console.warn("[shipeasy] track failed:", String(err)));
|
|
272
273
|
}
|
|
273
274
|
};
|
|
275
|
+
var DEFAULT_I18N_CDN = "https://cdn.i18n.shipeasy.ai";
|
|
276
|
+
async function fetchJson(url, timeoutMs = 2e3) {
|
|
277
|
+
const controller = new AbortController();
|
|
278
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
279
|
+
try {
|
|
280
|
+
const res = await fetch(url, {
|
|
281
|
+
signal: controller.signal,
|
|
282
|
+
next: { revalidate: 60 }
|
|
283
|
+
});
|
|
284
|
+
if (!res.ok) throw new Error(`HTTP ${res.status} fetching ${url}`);
|
|
285
|
+
return res.json();
|
|
286
|
+
} finally {
|
|
287
|
+
clearTimeout(timer);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
async function fetchLabelsForSSR(opts) {
|
|
291
|
+
const cdn = opts.cdnBaseUrl ?? DEFAULT_I18N_CDN;
|
|
292
|
+
const chunk = opts.chunk ?? "index";
|
|
293
|
+
try {
|
|
294
|
+
const manifest = await fetchJson(
|
|
295
|
+
`${cdn}/labels/${opts.key}/${opts.profile}/manifest.json`,
|
|
296
|
+
opts.timeoutMs
|
|
297
|
+
);
|
|
298
|
+
const fileUrl = manifest[chunk];
|
|
299
|
+
if (!fileUrl) return null;
|
|
300
|
+
return await fetchJson(fileUrl, opts.timeoutMs);
|
|
301
|
+
} catch {
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
274
305
|
var _server = null;
|
|
275
306
|
function configureShipeasyServer(opts) {
|
|
276
307
|
if (_server) return _server;
|
|
@@ -327,6 +358,7 @@ var flags = {
|
|
|
327
358
|
FlagsClient,
|
|
328
359
|
_resetShipeasyServerForTests,
|
|
329
360
|
configureShipeasyServer,
|
|
361
|
+
fetchLabelsForSSR,
|
|
330
362
|
flags,
|
|
331
363
|
getShipeasyServerClient,
|
|
332
364
|
version
|
package/dist/server/index.mjs
CHANGED
|
@@ -242,6 +242,36 @@ var FlagsClient = class {
|
|
|
242
242
|
}).catch((err) => console.warn("[shipeasy] track failed:", String(err)));
|
|
243
243
|
}
|
|
244
244
|
};
|
|
245
|
+
var DEFAULT_I18N_CDN = "https://cdn.i18n.shipeasy.ai";
|
|
246
|
+
async function fetchJson(url, timeoutMs = 2e3) {
|
|
247
|
+
const controller = new AbortController();
|
|
248
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
249
|
+
try {
|
|
250
|
+
const res = await fetch(url, {
|
|
251
|
+
signal: controller.signal,
|
|
252
|
+
next: { revalidate: 60 }
|
|
253
|
+
});
|
|
254
|
+
if (!res.ok) throw new Error(`HTTP ${res.status} fetching ${url}`);
|
|
255
|
+
return res.json();
|
|
256
|
+
} finally {
|
|
257
|
+
clearTimeout(timer);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
async function fetchLabelsForSSR(opts) {
|
|
261
|
+
const cdn = opts.cdnBaseUrl ?? DEFAULT_I18N_CDN;
|
|
262
|
+
const chunk = opts.chunk ?? "index";
|
|
263
|
+
try {
|
|
264
|
+
const manifest = await fetchJson(
|
|
265
|
+
`${cdn}/labels/${opts.key}/${opts.profile}/manifest.json`,
|
|
266
|
+
opts.timeoutMs
|
|
267
|
+
);
|
|
268
|
+
const fileUrl = manifest[chunk];
|
|
269
|
+
if (!fileUrl) return null;
|
|
270
|
+
return await fetchJson(fileUrl, opts.timeoutMs);
|
|
271
|
+
} catch {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
245
275
|
var _server = null;
|
|
246
276
|
function configureShipeasyServer(opts) {
|
|
247
277
|
if (_server) return _server;
|
|
@@ -297,6 +327,7 @@ export {
|
|
|
297
327
|
FlagsClient,
|
|
298
328
|
_resetShipeasyServerForTests,
|
|
299
329
|
configureShipeasyServer,
|
|
330
|
+
fetchLabelsForSSR,
|
|
300
331
|
flags,
|
|
301
332
|
getShipeasyServerClient,
|
|
302
333
|
version
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shipeasy/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
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",
|
|
@@ -16,8 +16,12 @@
|
|
|
16
16
|
"browser": "./dist/client/index.js",
|
|
17
17
|
"typesVersions": {
|
|
18
18
|
"*": {
|
|
19
|
-
"client": [
|
|
20
|
-
|
|
19
|
+
"client": [
|
|
20
|
+
"./dist/client/index.d.ts"
|
|
21
|
+
],
|
|
22
|
+
"server": [
|
|
23
|
+
"./dist/server/index.d.ts"
|
|
24
|
+
]
|
|
21
25
|
}
|
|
22
26
|
},
|
|
23
27
|
"exports": {
|