@shipeasy/sdk 1.1.0 → 1.2.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 +12 -1
- package/dist/client/index.d.ts +12 -1
- package/dist/client/index.js +26 -4
- package/dist/client/index.mjs +20 -4
- 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,6 +137,17 @@ declare const flags: {
|
|
|
137
137
|
/** True once identify() has completed and flags are available. */
|
|
138
138
|
readonly ready: boolean;
|
|
139
139
|
};
|
|
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;
|
|
140
151
|
/**
|
|
141
152
|
* Universal i18n facade. Backed by the `window.i18n` global the loader
|
|
142
153
|
* script installs. Returns the key itself when the loader hasn't run
|
|
@@ -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,6 +137,17 @@ declare const flags: {
|
|
|
137
137
|
/** True once identify() has completed and flags are available. */
|
|
138
138
|
readonly ready: boolean;
|
|
139
139
|
};
|
|
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;
|
|
140
151
|
/**
|
|
141
152
|
* Universal i18n facade. Backed by the `window.i18n` global the loader
|
|
142
153
|
* script installs. Returns the key itself when the loader hasn't run
|
|
@@ -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,
|
|
@@ -695,6 +701,19 @@ var flags = {
|
|
|
695
701
|
return _client?.ready ?? false;
|
|
696
702
|
}
|
|
697
703
|
};
|
|
704
|
+
var LABEL_MARKER_START = "\uFFF9";
|
|
705
|
+
var LABEL_MARKER_SEP = "\uFFFA";
|
|
706
|
+
var LABEL_MARKER_END = "\uFFFB";
|
|
707
|
+
var LABEL_MARKER_RE = /([^]+)([^]*)/g;
|
|
708
|
+
function encodeLabelMarker(key, value) {
|
|
709
|
+
return `${LABEL_MARKER_START}${key}${LABEL_MARKER_SEP}${value}${LABEL_MARKER_END}`;
|
|
710
|
+
}
|
|
711
|
+
function labelAttrs(key, variables, desc) {
|
|
712
|
+
const attrs = { "data-label": key };
|
|
713
|
+
if (variables) attrs["data-variables"] = JSON.stringify(variables);
|
|
714
|
+
if (desc) attrs["data-label-desc"] = desc;
|
|
715
|
+
return attrs;
|
|
716
|
+
}
|
|
698
717
|
var _createElement = null;
|
|
699
718
|
var i18n = {
|
|
700
719
|
t(key, variables) {
|
|
@@ -717,10 +736,7 @@ var i18n = {
|
|
|
717
736
|
tEl(key, variables, desc) {
|
|
718
737
|
const text = this.t(key, variables);
|
|
719
738
|
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);
|
|
739
|
+
return _createElement("span", labelAttrs(key, variables, desc), text);
|
|
724
740
|
},
|
|
725
741
|
/** Wire up the element creator once at app startup (call before any tEl use). */
|
|
726
742
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -764,13 +780,19 @@ var i18n = {
|
|
|
764
780
|
// Annotate the CommonJS export names for ESM import in node:
|
|
765
781
|
0 && (module.exports = {
|
|
766
782
|
FlagsClientBrowser,
|
|
783
|
+
LABEL_MARKER_END,
|
|
784
|
+
LABEL_MARKER_RE,
|
|
785
|
+
LABEL_MARKER_SEP,
|
|
786
|
+
LABEL_MARKER_START,
|
|
767
787
|
_resetShipeasyForTests,
|
|
768
788
|
attachDevtools,
|
|
769
789
|
configureShipeasy,
|
|
790
|
+
encodeLabelMarker,
|
|
770
791
|
flags,
|
|
771
792
|
getShipeasyClient,
|
|
772
793
|
i18n,
|
|
773
794
|
isDevtoolsRequested,
|
|
795
|
+
labelAttrs,
|
|
774
796
|
loadDevtools,
|
|
775
797
|
readConfigOverride,
|
|
776
798
|
readExpOverride,
|
package/dist/client/index.mjs
CHANGED
|
@@ -659,6 +659,19 @@ var flags = {
|
|
|
659
659
|
return _client?.ready ?? false;
|
|
660
660
|
}
|
|
661
661
|
};
|
|
662
|
+
var LABEL_MARKER_START = "\uFFF9";
|
|
663
|
+
var LABEL_MARKER_SEP = "\uFFFA";
|
|
664
|
+
var LABEL_MARKER_END = "\uFFFB";
|
|
665
|
+
var LABEL_MARKER_RE = /([^]+)([^]*)/g;
|
|
666
|
+
function encodeLabelMarker(key, value) {
|
|
667
|
+
return `${LABEL_MARKER_START}${key}${LABEL_MARKER_SEP}${value}${LABEL_MARKER_END}`;
|
|
668
|
+
}
|
|
669
|
+
function labelAttrs(key, variables, desc) {
|
|
670
|
+
const attrs = { "data-label": key };
|
|
671
|
+
if (variables) attrs["data-variables"] = JSON.stringify(variables);
|
|
672
|
+
if (desc) attrs["data-label-desc"] = desc;
|
|
673
|
+
return attrs;
|
|
674
|
+
}
|
|
662
675
|
var _createElement = null;
|
|
663
676
|
var i18n = {
|
|
664
677
|
t(key, variables) {
|
|
@@ -681,10 +694,7 @@ var i18n = {
|
|
|
681
694
|
tEl(key, variables, desc) {
|
|
682
695
|
const text = this.t(key, variables);
|
|
683
696
|
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);
|
|
697
|
+
return _createElement("span", labelAttrs(key, variables, desc), text);
|
|
688
698
|
},
|
|
689
699
|
/** Wire up the element creator once at app startup (call before any tEl use). */
|
|
690
700
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -727,13 +737,19 @@ var i18n = {
|
|
|
727
737
|
};
|
|
728
738
|
export {
|
|
729
739
|
FlagsClientBrowser,
|
|
740
|
+
LABEL_MARKER_END,
|
|
741
|
+
LABEL_MARKER_RE,
|
|
742
|
+
LABEL_MARKER_SEP,
|
|
743
|
+
LABEL_MARKER_START,
|
|
730
744
|
_resetShipeasyForTests,
|
|
731
745
|
attachDevtools,
|
|
732
746
|
configureShipeasy,
|
|
747
|
+
encodeLabelMarker,
|
|
733
748
|
flags,
|
|
734
749
|
getShipeasyClient,
|
|
735
750
|
i18n,
|
|
736
751
|
isDevtoolsRequested,
|
|
752
|
+
labelAttrs,
|
|
737
753
|
loadDevtools,
|
|
738
754
|
readConfigOverride,
|
|
739
755
|
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": "1.
|
|
3
|
+
"version": "1.2.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": {
|