@scalemule/sdk 0.0.13 → 0.0.15

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.
@@ -0,0 +1,121 @@
1
+ /** Wire format types matching the Rust FlagConfigWire from /v1/flags/config */
2
+ interface FlagConfigWire {
3
+ version: number;
4
+ rollout_salt: string;
5
+ environment: string;
6
+ segments: SegmentWire[];
7
+ flags: FlagWire[];
8
+ }
9
+ interface SegmentWire {
10
+ id: string;
11
+ segment_key: string;
12
+ conditions: Condition[];
13
+ included_users: string[];
14
+ excluded_users: string[];
15
+ }
16
+ interface FlagWire {
17
+ flag_key: string;
18
+ flag_id: string;
19
+ flag_type: string;
20
+ status: string;
21
+ default_value: unknown;
22
+ environment_enabled: boolean;
23
+ environment_default_value: unknown | null;
24
+ rules: RuleWire[];
25
+ variants: VariantWire[];
26
+ }
27
+ interface RuleWire {
28
+ id: string;
29
+ priority: number;
30
+ conditions: Condition[];
31
+ segment_ids: string[];
32
+ serve_value: unknown;
33
+ rollout_percentage: number | null;
34
+ enabled: boolean;
35
+ }
36
+ interface VariantWire {
37
+ variant_key: string;
38
+ value: unknown;
39
+ weight: number;
40
+ }
41
+ interface Condition {
42
+ attribute: string;
43
+ operator: string;
44
+ value?: unknown;
45
+ values?: unknown[];
46
+ }
47
+ interface EvaluationContext {
48
+ user_id?: string;
49
+ email?: string;
50
+ session_id?: string;
51
+ ip_address?: string;
52
+ user_agent?: string;
53
+ timestamp?: string;
54
+ [key: string]: unknown;
55
+ }
56
+ interface FlagEvaluation {
57
+ flag_id: string;
58
+ flag_key: string;
59
+ environment: string;
60
+ value: unknown;
61
+ reason: string;
62
+ matched_rule_id: string | null;
63
+ variant_key: string | null;
64
+ bucket: number | null;
65
+ }
66
+
67
+ /**
68
+ * FlagClient — server-side flag evaluation with local caching + SSE push updates.
69
+ * Long-lived Node.js processes only (not browser, not edge).
70
+ */
71
+
72
+ interface FlagClientOptions {
73
+ apiKey: string;
74
+ environment: string;
75
+ gatewayUrl: string;
76
+ }
77
+ declare class FlagClient {
78
+ private apiKey;
79
+ private environment;
80
+ private gatewayUrl;
81
+ private config;
82
+ private lastETag;
83
+ private streamState;
84
+ private pollTimer;
85
+ private reconnectTimer;
86
+ private telemetryTimer;
87
+ private abortController;
88
+ private initPromise;
89
+ private telemetryCounters;
90
+ constructor(options: FlagClientOptions);
91
+ init(): Promise<void>;
92
+ private doInit;
93
+ evaluate(flagKey: string, context: EvaluationContext): FlagEvaluation;
94
+ evaluateBatch(flagKeys: string[], context: EvaluationContext): Record<string, FlagEvaluation>;
95
+ shutdown(): Promise<void>;
96
+ private connectStream;
97
+ private handleSseFrame;
98
+ private startPolling;
99
+ private stopPolling;
100
+ private pollConfig;
101
+ private recordTelemetry;
102
+ private startTelemetryFlush;
103
+ private flushTelemetry;
104
+ }
105
+
106
+ /**
107
+ * Local flag evaluation engine — 1:1 port of Rust evaluator.rs
108
+ * Produces identical results to the server-side evaluation.
109
+ */
110
+
111
+ declare function evaluateFlag(flag: FlagWire, config: FlagConfigWire, context: EvaluationContext): FlagEvaluation;
112
+
113
+ /**
114
+ * Hash-to-bucket matching Rust: SHA256(salt.flag_key.identifier) → first 4 bytes → u32 BE → mod 10_000
115
+ * Synchronous node:crypto — matches Rust evaluation exactly.
116
+ */
117
+ declare function hashToBucket(flagKey: string, identifier: string, salt: string): number;
118
+
119
+ declare function allConditionsMatch(conditions: Condition[], context: EvaluationContext): boolean;
120
+
121
+ export { type Condition, type EvaluationContext, FlagClient, type FlagClientOptions, type FlagConfigWire, type FlagEvaluation, type FlagWire, type RuleWire, type SegmentWire, type VariantWire, allConditionsMatch, evaluateFlag, hashToBucket };
@@ -0,0 +1,121 @@
1
+ /** Wire format types matching the Rust FlagConfigWire from /v1/flags/config */
2
+ interface FlagConfigWire {
3
+ version: number;
4
+ rollout_salt: string;
5
+ environment: string;
6
+ segments: SegmentWire[];
7
+ flags: FlagWire[];
8
+ }
9
+ interface SegmentWire {
10
+ id: string;
11
+ segment_key: string;
12
+ conditions: Condition[];
13
+ included_users: string[];
14
+ excluded_users: string[];
15
+ }
16
+ interface FlagWire {
17
+ flag_key: string;
18
+ flag_id: string;
19
+ flag_type: string;
20
+ status: string;
21
+ default_value: unknown;
22
+ environment_enabled: boolean;
23
+ environment_default_value: unknown | null;
24
+ rules: RuleWire[];
25
+ variants: VariantWire[];
26
+ }
27
+ interface RuleWire {
28
+ id: string;
29
+ priority: number;
30
+ conditions: Condition[];
31
+ segment_ids: string[];
32
+ serve_value: unknown;
33
+ rollout_percentage: number | null;
34
+ enabled: boolean;
35
+ }
36
+ interface VariantWire {
37
+ variant_key: string;
38
+ value: unknown;
39
+ weight: number;
40
+ }
41
+ interface Condition {
42
+ attribute: string;
43
+ operator: string;
44
+ value?: unknown;
45
+ values?: unknown[];
46
+ }
47
+ interface EvaluationContext {
48
+ user_id?: string;
49
+ email?: string;
50
+ session_id?: string;
51
+ ip_address?: string;
52
+ user_agent?: string;
53
+ timestamp?: string;
54
+ [key: string]: unknown;
55
+ }
56
+ interface FlagEvaluation {
57
+ flag_id: string;
58
+ flag_key: string;
59
+ environment: string;
60
+ value: unknown;
61
+ reason: string;
62
+ matched_rule_id: string | null;
63
+ variant_key: string | null;
64
+ bucket: number | null;
65
+ }
66
+
67
+ /**
68
+ * FlagClient — server-side flag evaluation with local caching + SSE push updates.
69
+ * Long-lived Node.js processes only (not browser, not edge).
70
+ */
71
+
72
+ interface FlagClientOptions {
73
+ apiKey: string;
74
+ environment: string;
75
+ gatewayUrl: string;
76
+ }
77
+ declare class FlagClient {
78
+ private apiKey;
79
+ private environment;
80
+ private gatewayUrl;
81
+ private config;
82
+ private lastETag;
83
+ private streamState;
84
+ private pollTimer;
85
+ private reconnectTimer;
86
+ private telemetryTimer;
87
+ private abortController;
88
+ private initPromise;
89
+ private telemetryCounters;
90
+ constructor(options: FlagClientOptions);
91
+ init(): Promise<void>;
92
+ private doInit;
93
+ evaluate(flagKey: string, context: EvaluationContext): FlagEvaluation;
94
+ evaluateBatch(flagKeys: string[], context: EvaluationContext): Record<string, FlagEvaluation>;
95
+ shutdown(): Promise<void>;
96
+ private connectStream;
97
+ private handleSseFrame;
98
+ private startPolling;
99
+ private stopPolling;
100
+ private pollConfig;
101
+ private recordTelemetry;
102
+ private startTelemetryFlush;
103
+ private flushTelemetry;
104
+ }
105
+
106
+ /**
107
+ * Local flag evaluation engine — 1:1 port of Rust evaluator.rs
108
+ * Produces identical results to the server-side evaluation.
109
+ */
110
+
111
+ declare function evaluateFlag(flag: FlagWire, config: FlagConfigWire, context: EvaluationContext): FlagEvaluation;
112
+
113
+ /**
114
+ * Hash-to-bucket matching Rust: SHA256(salt.flag_key.identifier) → first 4 bytes → u32 BE → mod 10_000
115
+ * Synchronous node:crypto — matches Rust evaluation exactly.
116
+ */
117
+ declare function hashToBucket(flagKey: string, identifier: string, salt: string): number;
118
+
119
+ declare function allConditionsMatch(conditions: Condition[], context: EvaluationContext): boolean;
120
+
121
+ export { type Condition, type EvaluationContext, FlagClient, type FlagClientOptions, type FlagConfigWire, type FlagEvaluation, type FlagWire, type RuleWire, type SegmentWire, type VariantWire, allConditionsMatch, evaluateFlag, hashToBucket };
@@ -0,0 +1,523 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/flags/server.ts
21
+ var server_exports = {};
22
+ __export(server_exports, {
23
+ FlagClient: () => FlagClient,
24
+ allConditionsMatch: () => allConditionsMatch,
25
+ evaluateFlag: () => evaluateFlag,
26
+ hashToBucket: () => hashToBucket
27
+ });
28
+ module.exports = __toCommonJS(server_exports);
29
+
30
+ // src/flags/hasher.ts
31
+ var import_node_crypto = require("crypto");
32
+ function hashToBucket(flagKey, identifier, salt) {
33
+ const hash = (0, import_node_crypto.createHash)("sha256").update(`${salt}.${flagKey}.${identifier}`).digest();
34
+ return hash.readUInt32BE(0) % 1e4;
35
+ }
36
+
37
+ // src/flags/conditions.ts
38
+ var import_semver = require("semver");
39
+ function allConditionsMatch(conditions, context) {
40
+ return conditions.every((c) => conditionMatches(c, context));
41
+ }
42
+ function conditionMatches(condition, context) {
43
+ const attributeValue = getAttribute(context, condition.attribute);
44
+ const op = condition.operator;
45
+ if (op === "exists") return attributeValue !== void 0 && attributeValue !== null;
46
+ if (op === "not_exists") return attributeValue === void 0 || attributeValue === null;
47
+ if (attributeValue === void 0 || attributeValue === null) return false;
48
+ switch (op) {
49
+ case "eq":
50
+ return compareValues(attributeValue, condition.value) === 0;
51
+ case "neq":
52
+ return compareValues(attributeValue, condition.value) !== 0;
53
+ case "in":
54
+ return candidateValues(condition).some((v) => compareValues(attributeValue, v) === 0);
55
+ case "not_in":
56
+ return !candidateValues(condition).some((v) => compareValues(attributeValue, v) === 0);
57
+ case "contains":
58
+ return containsValue(attributeValue, condition.value);
59
+ case "starts_with":
60
+ return typeof attributeValue === "string" && typeof condition.value === "string" ? attributeValue.startsWith(condition.value) : false;
61
+ case "ends_with":
62
+ return typeof attributeValue === "string" && typeof condition.value === "string" ? attributeValue.endsWith(condition.value) : false;
63
+ case "gt":
64
+ return compareValues(attributeValue, condition.value) === 1;
65
+ case "gte": {
66
+ const cmp = compareValues(attributeValue, condition.value);
67
+ return cmp === 1 || cmp === 0;
68
+ }
69
+ case "lt":
70
+ return compareValues(attributeValue, condition.value) === -1;
71
+ case "lte": {
72
+ const cmp = compareValues(attributeValue, condition.value);
73
+ return cmp === -1 || cmp === 0;
74
+ }
75
+ case "regex": {
76
+ if (typeof attributeValue !== "string" || typeof condition.value !== "string") return false;
77
+ try {
78
+ return new RegExp(condition.value).test(attributeValue);
79
+ } catch {
80
+ return false;
81
+ }
82
+ }
83
+ case "semver_eq":
84
+ return semverCmp(attributeValue, condition.value) === 0;
85
+ case "semver_neq":
86
+ return semverCmp(attributeValue, condition.value) !== 0;
87
+ case "semver_gt":
88
+ return semverCmp(attributeValue, condition.value) === 1;
89
+ case "semver_gte": {
90
+ const cmp = semverCmp(attributeValue, condition.value);
91
+ return cmp === 1 || cmp === 0;
92
+ }
93
+ case "semver_lt":
94
+ return semverCmp(attributeValue, condition.value) === -1;
95
+ case "semver_lte": {
96
+ const cmp = semverCmp(attributeValue, condition.value);
97
+ return cmp === -1 || cmp === 0;
98
+ }
99
+ default:
100
+ return false;
101
+ }
102
+ }
103
+ function getAttribute(context, key) {
104
+ switch (key) {
105
+ case "user_id":
106
+ return context.user_id;
107
+ case "email":
108
+ return context.email;
109
+ case "session_id":
110
+ return context.session_id;
111
+ case "ip_address":
112
+ return context.ip_address;
113
+ case "user_agent":
114
+ return context.user_agent;
115
+ case "timestamp":
116
+ return context.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
117
+ default:
118
+ return context[key];
119
+ }
120
+ }
121
+ function candidateValues(condition) {
122
+ if (condition.values && condition.values.length > 0) return condition.values;
123
+ if (condition.value === void 0 || condition.value === null) return [];
124
+ if (Array.isArray(condition.value)) return condition.value;
125
+ return [condition.value];
126
+ }
127
+ function compareValues(actual, expected) {
128
+ if (expected === void 0 || expected === null) return null;
129
+ const numA = toNumber(actual);
130
+ const numB = toNumber(expected);
131
+ if (numA !== null && numB !== null) {
132
+ if (numA < numB) return -1;
133
+ if (numA > numB) return 1;
134
+ return 0;
135
+ }
136
+ if (typeof actual === "boolean" && typeof expected === "boolean") {
137
+ if (actual === expected) return 0;
138
+ return actual ? 1 : -1;
139
+ }
140
+ const strA = toString(actual);
141
+ const strB = toString(expected);
142
+ if (strA !== null && strB !== null) {
143
+ if (strA < strB) return -1;
144
+ if (strA > strB) return 1;
145
+ return 0;
146
+ }
147
+ return null;
148
+ }
149
+ function containsValue(actual, expected) {
150
+ if (expected === void 0 || expected === null) return false;
151
+ if (Array.isArray(actual)) {
152
+ return actual.some((item) => compareValues(item, expected) === 0);
153
+ }
154
+ if (typeof actual === "string" && typeof expected === "string") {
155
+ return actual.includes(expected);
156
+ }
157
+ return false;
158
+ }
159
+ function toNumber(value) {
160
+ if (typeof value === "number") return value;
161
+ if (typeof value === "string") {
162
+ const n = Number(value);
163
+ return isNaN(n) ? null : n;
164
+ }
165
+ return null;
166
+ }
167
+ function toString(value) {
168
+ if (typeof value === "string") return value;
169
+ return null;
170
+ }
171
+ function semverCmp(actual, expected) {
172
+ if (typeof actual !== "string" || typeof expected !== "string") return null;
173
+ try {
174
+ const a = (0, import_semver.parse)(actual);
175
+ const b = (0, import_semver.parse)(expected);
176
+ if (!a || !b) return null;
177
+ return (0, import_semver.compare)(a, b);
178
+ } catch {
179
+ return null;
180
+ }
181
+ }
182
+
183
+ // src/flags/evaluator.ts
184
+ function evaluateFlag(flag, config, context) {
185
+ const effectiveDefault = flag.environment_default_value ?? flag.default_value;
186
+ if (flag.status !== "active") {
187
+ return result(flag, config.environment, effectiveDefault, "disabled");
188
+ }
189
+ if (!flag.environment_enabled) {
190
+ return result(flag, config.environment, effectiveDefault, "disabled");
191
+ }
192
+ const bucketIdentifier = getBucketIdentifier(context);
193
+ for (const rule of flag.rules) {
194
+ if (!rule.enabled) continue;
195
+ if (rule.segment_ids.length > 0) {
196
+ const segmentMatched = rule.segment_ids.some((segId) => {
197
+ const segment = config.segments.find((s) => s.id === segId);
198
+ if (!segment) return false;
199
+ return userMatchesSegment(segment, context);
200
+ });
201
+ if (!segmentMatched) continue;
202
+ }
203
+ if (!allConditionsMatch(rule.conditions, context)) continue;
204
+ if (rule.rollout_percentage !== null && rule.rollout_percentage !== void 0) {
205
+ const bucket = hashToBucket(flag.flag_key, bucketIdentifier, config.rollout_salt);
206
+ if (bucket >= rule.rollout_percentage) continue;
207
+ return {
208
+ flag_id: flag.flag_id,
209
+ flag_key: flag.flag_key,
210
+ environment: config.environment,
211
+ value: rule.serve_value,
212
+ reason: "rule_match",
213
+ matched_rule_id: rule.id,
214
+ variant_key: null,
215
+ bucket
216
+ };
217
+ }
218
+ return {
219
+ flag_id: flag.flag_id,
220
+ flag_key: flag.flag_key,
221
+ environment: config.environment,
222
+ value: rule.serve_value,
223
+ reason: "rule_match",
224
+ matched_rule_id: rule.id,
225
+ variant_key: null,
226
+ bucket: null
227
+ };
228
+ }
229
+ if (flag.variants.length > 0) {
230
+ const totalWeight = flag.variants.reduce((sum, v) => sum + v.weight, 0);
231
+ if (totalWeight > 0) {
232
+ const bucket = hashToBucket(flag.flag_key, bucketIdentifier, config.rollout_salt);
233
+ const scaled = Math.floor(bucket * totalWeight / 1e4);
234
+ let cursor = 0;
235
+ for (const variant of flag.variants) {
236
+ cursor += variant.weight;
237
+ if (scaled < cursor) {
238
+ return {
239
+ flag_id: flag.flag_id,
240
+ flag_key: flag.flag_key,
241
+ environment: config.environment,
242
+ value: variant.value,
243
+ reason: "variant",
244
+ matched_rule_id: null,
245
+ variant_key: variant.variant_key,
246
+ bucket
247
+ };
248
+ }
249
+ }
250
+ }
251
+ }
252
+ return result(flag, config.environment, effectiveDefault, "default");
253
+ }
254
+ function getBucketIdentifier(context) {
255
+ return context.user_id ?? context.session_id ?? context.email ?? context.ip_address ?? "anonymous";
256
+ }
257
+ function userMatchesSegment(segment, context) {
258
+ const identifiers = [context.user_id, context.email, context.session_id].filter(
259
+ (v) => v !== void 0 && v !== null
260
+ );
261
+ if (identifiers.some((id) => segment.excluded_users.includes(id))) {
262
+ return false;
263
+ }
264
+ if (identifiers.some((id) => segment.included_users.includes(id))) {
265
+ return true;
266
+ }
267
+ return allConditionsMatch(segment.conditions, context);
268
+ }
269
+ function result(flag, environment, value, reason) {
270
+ return {
271
+ flag_id: flag.flag_id,
272
+ flag_key: flag.flag_key,
273
+ environment,
274
+ value,
275
+ reason,
276
+ matched_rule_id: null,
277
+ variant_key: null,
278
+ bucket: null
279
+ };
280
+ }
281
+
282
+ // src/flags/client.ts
283
+ var FlagClient = class {
284
+ constructor(options) {
285
+ this.config = null;
286
+ this.lastETag = "";
287
+ this.streamState = "idle";
288
+ this.pollTimer = null;
289
+ this.reconnectTimer = null;
290
+ this.telemetryTimer = null;
291
+ this.abortController = null;
292
+ this.initPromise = null;
293
+ this.telemetryCounters = /* @__PURE__ */ new Map();
294
+ this.apiKey = options.apiKey;
295
+ this.environment = options.environment;
296
+ this.gatewayUrl = options.gatewayUrl;
297
+ }
298
+ async init() {
299
+ if (this.config) return;
300
+ if (this.initPromise) return this.initPromise;
301
+ this.initPromise = this.doInit();
302
+ try {
303
+ await this.initPromise;
304
+ } finally {
305
+ this.initPromise = null;
306
+ }
307
+ }
308
+ async doInit() {
309
+ const resp = await fetch(`${this.gatewayUrl}/v1/flags/config?environment=${encodeURIComponent(this.environment)}`, {
310
+ headers: { "x-api-key": this.apiKey }
311
+ });
312
+ if (resp.status === 403) throw new Error("Secret API key required for /config");
313
+ if (!resp.ok) throw new Error(`Config fetch failed: ${resp.status}`);
314
+ const json = await resp.json();
315
+ this.config = json.data;
316
+ this.lastETag = resp.headers.get("etag") || "";
317
+ this.connectStream();
318
+ this.startTelemetryFlush();
319
+ }
320
+ evaluate(flagKey, context) {
321
+ if (!this.config) throw new Error("FlagClient not initialized \u2014 call init() first");
322
+ const flagConfig = this.config.flags.find((f) => f.flag_key === flagKey);
323
+ if (!flagConfig) {
324
+ return {
325
+ flag_id: "",
326
+ flag_key: flagKey,
327
+ environment: this.environment,
328
+ value: null,
329
+ reason: "not_found",
330
+ matched_rule_id: null,
331
+ variant_key: null,
332
+ bucket: null
333
+ };
334
+ }
335
+ const result2 = evaluateFlag(flagConfig, this.config, context);
336
+ this.recordTelemetry(result2);
337
+ return result2;
338
+ }
339
+ evaluateBatch(flagKeys, context) {
340
+ if (!this.config) throw new Error("FlagClient not initialized \u2014 call init() first");
341
+ const results = {};
342
+ for (const key of flagKeys) {
343
+ const flagConfig = this.config.flags.find((f) => f.flag_key === key);
344
+ if (flagConfig) {
345
+ const result2 = evaluateFlag(flagConfig, this.config, context);
346
+ this.recordTelemetry(result2);
347
+ results[key] = result2;
348
+ }
349
+ }
350
+ return results;
351
+ }
352
+ async shutdown() {
353
+ this.streamState = "idle";
354
+ this.abortController?.abort();
355
+ this.abortController = null;
356
+ if (this.pollTimer) {
357
+ clearInterval(this.pollTimer);
358
+ this.pollTimer = null;
359
+ }
360
+ if (this.reconnectTimer) {
361
+ clearInterval(this.reconnectTimer);
362
+ this.reconnectTimer = null;
363
+ }
364
+ if (this.telemetryTimer) {
365
+ clearInterval(this.telemetryTimer);
366
+ this.telemetryTimer = null;
367
+ }
368
+ await this.flushTelemetry();
369
+ }
370
+ // ======== SSE Streaming ========
371
+ async connectStream() {
372
+ if (this.streamState === "streaming") return;
373
+ this.abortController?.abort();
374
+ this.abortController = new AbortController();
375
+ try {
376
+ const resp = await fetch(
377
+ `${this.gatewayUrl}/v1/flags/stream?environment=${encodeURIComponent(this.environment)}`,
378
+ {
379
+ headers: {
380
+ "x-api-key": this.apiKey,
381
+ "Last-Event-ID": String(this.config?.version ?? 0)
382
+ },
383
+ signal: this.abortController.signal
384
+ }
385
+ );
386
+ if (!resp.ok || !resp.body) {
387
+ this.startPolling();
388
+ return;
389
+ }
390
+ this.streamState = "streaming";
391
+ this.stopPolling();
392
+ const reader = resp.body.getReader();
393
+ const decoder = new TextDecoder();
394
+ let buffer = "";
395
+ while (true) {
396
+ const { done, value } = await reader.read();
397
+ if (done) break;
398
+ buffer += decoder.decode(value, { stream: true });
399
+ let idx;
400
+ while ((idx = buffer.indexOf("\n\n")) !== -1) {
401
+ const frame = buffer.slice(0, idx);
402
+ buffer = buffer.slice(idx + 2);
403
+ this.handleSseFrame(frame);
404
+ }
405
+ }
406
+ } catch {
407
+ }
408
+ if (this.streamState === "streaming") {
409
+ this.streamState = "idle";
410
+ this.startPolling();
411
+ }
412
+ }
413
+ handleSseFrame(frame) {
414
+ let eventType = "";
415
+ let data = "";
416
+ for (const line of frame.split("\n")) {
417
+ if (line.startsWith("event:")) eventType = line.slice(6).trim();
418
+ else if (line.startsWith("data:")) data += line.slice(5).trim();
419
+ }
420
+ if (eventType === "config" && data) {
421
+ try {
422
+ const parsed = JSON.parse(data);
423
+ const newConfig = parsed.data;
424
+ if (newConfig && newConfig.version !== void 0) {
425
+ this.config = newConfig;
426
+ }
427
+ } catch {
428
+ }
429
+ }
430
+ }
431
+ // ======== Polling Fallback ========
432
+ startPolling() {
433
+ if (this.streamState === "polling") return;
434
+ this.streamState = "polling";
435
+ this.pollTimer = setInterval(() => void this.pollConfig(), 6e4);
436
+ this.reconnectTimer = setInterval(() => void this.connectStream(), 3e5);
437
+ }
438
+ stopPolling() {
439
+ if (this.pollTimer) {
440
+ clearInterval(this.pollTimer);
441
+ this.pollTimer = null;
442
+ }
443
+ if (this.reconnectTimer) {
444
+ clearInterval(this.reconnectTimer);
445
+ this.reconnectTimer = null;
446
+ }
447
+ }
448
+ async pollConfig() {
449
+ try {
450
+ const headers = { "x-api-key": this.apiKey };
451
+ if (this.lastETag) headers["if-none-match"] = this.lastETag;
452
+ const resp = await fetch(
453
+ `${this.gatewayUrl}/v1/flags/config?environment=${encodeURIComponent(this.environment)}`,
454
+ { headers }
455
+ );
456
+ if (resp.status === 304) return;
457
+ if (!resp.ok) return;
458
+ const json = await resp.json();
459
+ this.config = json.data;
460
+ this.lastETag = resp.headers.get("etag") || "";
461
+ } catch {
462
+ }
463
+ }
464
+ // ======== Telemetry ========
465
+ recordTelemetry(evaluation) {
466
+ const key = `${evaluation.flag_key}:${evaluation.reason}:${String(evaluation.value)}`;
467
+ const existing = this.telemetryCounters.get(key);
468
+ if (existing) {
469
+ existing.count++;
470
+ if (evaluation.value === true) existing.true_count++;
471
+ else if (evaluation.value === false) existing.false_count++;
472
+ } else {
473
+ this.telemetryCounters.set(key, {
474
+ flag_key: evaluation.flag_key,
475
+ flag_id: evaluation.flag_id,
476
+ reason: evaluation.reason,
477
+ count: 1,
478
+ true_count: evaluation.value === true ? 1 : 0,
479
+ false_count: evaluation.value === false ? 1 : 0
480
+ });
481
+ }
482
+ }
483
+ startTelemetryFlush() {
484
+ this.telemetryTimer = setInterval(() => void this.flushTelemetry(), 6e4);
485
+ }
486
+ async flushTelemetry() {
487
+ if (this.telemetryCounters.size === 0) return;
488
+ const evaluations = Array.from(this.telemetryCounters.values());
489
+ this.telemetryCounters.clear();
490
+ try {
491
+ await fetch(`${this.gatewayUrl}/v1/flags/telemetry`, {
492
+ method: "POST",
493
+ headers: {
494
+ "Content-Type": "application/json",
495
+ "x-api-key": this.apiKey
496
+ },
497
+ body: JSON.stringify({
498
+ environment: this.environment,
499
+ evaluations
500
+ })
501
+ });
502
+ } catch {
503
+ for (const counter of evaluations) {
504
+ const key = `${counter.flag_key}:${counter.reason}:${counter.count}`;
505
+ const existing = this.telemetryCounters.get(key);
506
+ if (existing) {
507
+ existing.count += counter.count;
508
+ existing.true_count += counter.true_count;
509
+ existing.false_count += counter.false_count;
510
+ } else {
511
+ this.telemetryCounters.set(key, counter);
512
+ }
513
+ }
514
+ }
515
+ }
516
+ };
517
+ // Annotate the CommonJS export names for ESM import in node:
518
+ 0 && (module.exports = {
519
+ FlagClient,
520
+ allConditionsMatch,
521
+ evaluateFlag,
522
+ hashToBucket
523
+ });
@@ -0,0 +1,493 @@
1
+ // src/flags/hasher.ts
2
+ import { createHash } from "crypto";
3
+ function hashToBucket(flagKey, identifier, salt) {
4
+ const hash = createHash("sha256").update(`${salt}.${flagKey}.${identifier}`).digest();
5
+ return hash.readUInt32BE(0) % 1e4;
6
+ }
7
+
8
+ // src/flags/conditions.ts
9
+ import { parse as semverParse, compare as semverCompare } from "semver";
10
+ function allConditionsMatch(conditions, context) {
11
+ return conditions.every((c) => conditionMatches(c, context));
12
+ }
13
+ function conditionMatches(condition, context) {
14
+ const attributeValue = getAttribute(context, condition.attribute);
15
+ const op = condition.operator;
16
+ if (op === "exists") return attributeValue !== void 0 && attributeValue !== null;
17
+ if (op === "not_exists") return attributeValue === void 0 || attributeValue === null;
18
+ if (attributeValue === void 0 || attributeValue === null) return false;
19
+ switch (op) {
20
+ case "eq":
21
+ return compareValues(attributeValue, condition.value) === 0;
22
+ case "neq":
23
+ return compareValues(attributeValue, condition.value) !== 0;
24
+ case "in":
25
+ return candidateValues(condition).some((v) => compareValues(attributeValue, v) === 0);
26
+ case "not_in":
27
+ return !candidateValues(condition).some((v) => compareValues(attributeValue, v) === 0);
28
+ case "contains":
29
+ return containsValue(attributeValue, condition.value);
30
+ case "starts_with":
31
+ return typeof attributeValue === "string" && typeof condition.value === "string" ? attributeValue.startsWith(condition.value) : false;
32
+ case "ends_with":
33
+ return typeof attributeValue === "string" && typeof condition.value === "string" ? attributeValue.endsWith(condition.value) : false;
34
+ case "gt":
35
+ return compareValues(attributeValue, condition.value) === 1;
36
+ case "gte": {
37
+ const cmp = compareValues(attributeValue, condition.value);
38
+ return cmp === 1 || cmp === 0;
39
+ }
40
+ case "lt":
41
+ return compareValues(attributeValue, condition.value) === -1;
42
+ case "lte": {
43
+ const cmp = compareValues(attributeValue, condition.value);
44
+ return cmp === -1 || cmp === 0;
45
+ }
46
+ case "regex": {
47
+ if (typeof attributeValue !== "string" || typeof condition.value !== "string") return false;
48
+ try {
49
+ return new RegExp(condition.value).test(attributeValue);
50
+ } catch {
51
+ return false;
52
+ }
53
+ }
54
+ case "semver_eq":
55
+ return semverCmp(attributeValue, condition.value) === 0;
56
+ case "semver_neq":
57
+ return semverCmp(attributeValue, condition.value) !== 0;
58
+ case "semver_gt":
59
+ return semverCmp(attributeValue, condition.value) === 1;
60
+ case "semver_gte": {
61
+ const cmp = semverCmp(attributeValue, condition.value);
62
+ return cmp === 1 || cmp === 0;
63
+ }
64
+ case "semver_lt":
65
+ return semverCmp(attributeValue, condition.value) === -1;
66
+ case "semver_lte": {
67
+ const cmp = semverCmp(attributeValue, condition.value);
68
+ return cmp === -1 || cmp === 0;
69
+ }
70
+ default:
71
+ return false;
72
+ }
73
+ }
74
+ function getAttribute(context, key) {
75
+ switch (key) {
76
+ case "user_id":
77
+ return context.user_id;
78
+ case "email":
79
+ return context.email;
80
+ case "session_id":
81
+ return context.session_id;
82
+ case "ip_address":
83
+ return context.ip_address;
84
+ case "user_agent":
85
+ return context.user_agent;
86
+ case "timestamp":
87
+ return context.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
88
+ default:
89
+ return context[key];
90
+ }
91
+ }
92
+ function candidateValues(condition) {
93
+ if (condition.values && condition.values.length > 0) return condition.values;
94
+ if (condition.value === void 0 || condition.value === null) return [];
95
+ if (Array.isArray(condition.value)) return condition.value;
96
+ return [condition.value];
97
+ }
98
+ function compareValues(actual, expected) {
99
+ if (expected === void 0 || expected === null) return null;
100
+ const numA = toNumber(actual);
101
+ const numB = toNumber(expected);
102
+ if (numA !== null && numB !== null) {
103
+ if (numA < numB) return -1;
104
+ if (numA > numB) return 1;
105
+ return 0;
106
+ }
107
+ if (typeof actual === "boolean" && typeof expected === "boolean") {
108
+ if (actual === expected) return 0;
109
+ return actual ? 1 : -1;
110
+ }
111
+ const strA = toString(actual);
112
+ const strB = toString(expected);
113
+ if (strA !== null && strB !== null) {
114
+ if (strA < strB) return -1;
115
+ if (strA > strB) return 1;
116
+ return 0;
117
+ }
118
+ return null;
119
+ }
120
+ function containsValue(actual, expected) {
121
+ if (expected === void 0 || expected === null) return false;
122
+ if (Array.isArray(actual)) {
123
+ return actual.some((item) => compareValues(item, expected) === 0);
124
+ }
125
+ if (typeof actual === "string" && typeof expected === "string") {
126
+ return actual.includes(expected);
127
+ }
128
+ return false;
129
+ }
130
+ function toNumber(value) {
131
+ if (typeof value === "number") return value;
132
+ if (typeof value === "string") {
133
+ const n = Number(value);
134
+ return isNaN(n) ? null : n;
135
+ }
136
+ return null;
137
+ }
138
+ function toString(value) {
139
+ if (typeof value === "string") return value;
140
+ return null;
141
+ }
142
+ function semverCmp(actual, expected) {
143
+ if (typeof actual !== "string" || typeof expected !== "string") return null;
144
+ try {
145
+ const a = semverParse(actual);
146
+ const b = semverParse(expected);
147
+ if (!a || !b) return null;
148
+ return semverCompare(a, b);
149
+ } catch {
150
+ return null;
151
+ }
152
+ }
153
+
154
+ // src/flags/evaluator.ts
155
+ function evaluateFlag(flag, config, context) {
156
+ const effectiveDefault = flag.environment_default_value ?? flag.default_value;
157
+ if (flag.status !== "active") {
158
+ return result(flag, config.environment, effectiveDefault, "disabled");
159
+ }
160
+ if (!flag.environment_enabled) {
161
+ return result(flag, config.environment, effectiveDefault, "disabled");
162
+ }
163
+ const bucketIdentifier = getBucketIdentifier(context);
164
+ for (const rule of flag.rules) {
165
+ if (!rule.enabled) continue;
166
+ if (rule.segment_ids.length > 0) {
167
+ const segmentMatched = rule.segment_ids.some((segId) => {
168
+ const segment = config.segments.find((s) => s.id === segId);
169
+ if (!segment) return false;
170
+ return userMatchesSegment(segment, context);
171
+ });
172
+ if (!segmentMatched) continue;
173
+ }
174
+ if (!allConditionsMatch(rule.conditions, context)) continue;
175
+ if (rule.rollout_percentage !== null && rule.rollout_percentage !== void 0) {
176
+ const bucket = hashToBucket(flag.flag_key, bucketIdentifier, config.rollout_salt);
177
+ if (bucket >= rule.rollout_percentage) continue;
178
+ return {
179
+ flag_id: flag.flag_id,
180
+ flag_key: flag.flag_key,
181
+ environment: config.environment,
182
+ value: rule.serve_value,
183
+ reason: "rule_match",
184
+ matched_rule_id: rule.id,
185
+ variant_key: null,
186
+ bucket
187
+ };
188
+ }
189
+ return {
190
+ flag_id: flag.flag_id,
191
+ flag_key: flag.flag_key,
192
+ environment: config.environment,
193
+ value: rule.serve_value,
194
+ reason: "rule_match",
195
+ matched_rule_id: rule.id,
196
+ variant_key: null,
197
+ bucket: null
198
+ };
199
+ }
200
+ if (flag.variants.length > 0) {
201
+ const totalWeight = flag.variants.reduce((sum, v) => sum + v.weight, 0);
202
+ if (totalWeight > 0) {
203
+ const bucket = hashToBucket(flag.flag_key, bucketIdentifier, config.rollout_salt);
204
+ const scaled = Math.floor(bucket * totalWeight / 1e4);
205
+ let cursor = 0;
206
+ for (const variant of flag.variants) {
207
+ cursor += variant.weight;
208
+ if (scaled < cursor) {
209
+ return {
210
+ flag_id: flag.flag_id,
211
+ flag_key: flag.flag_key,
212
+ environment: config.environment,
213
+ value: variant.value,
214
+ reason: "variant",
215
+ matched_rule_id: null,
216
+ variant_key: variant.variant_key,
217
+ bucket
218
+ };
219
+ }
220
+ }
221
+ }
222
+ }
223
+ return result(flag, config.environment, effectiveDefault, "default");
224
+ }
225
+ function getBucketIdentifier(context) {
226
+ return context.user_id ?? context.session_id ?? context.email ?? context.ip_address ?? "anonymous";
227
+ }
228
+ function userMatchesSegment(segment, context) {
229
+ const identifiers = [context.user_id, context.email, context.session_id].filter(
230
+ (v) => v !== void 0 && v !== null
231
+ );
232
+ if (identifiers.some((id) => segment.excluded_users.includes(id))) {
233
+ return false;
234
+ }
235
+ if (identifiers.some((id) => segment.included_users.includes(id))) {
236
+ return true;
237
+ }
238
+ return allConditionsMatch(segment.conditions, context);
239
+ }
240
+ function result(flag, environment, value, reason) {
241
+ return {
242
+ flag_id: flag.flag_id,
243
+ flag_key: flag.flag_key,
244
+ environment,
245
+ value,
246
+ reason,
247
+ matched_rule_id: null,
248
+ variant_key: null,
249
+ bucket: null
250
+ };
251
+ }
252
+
253
+ // src/flags/client.ts
254
+ var FlagClient = class {
255
+ constructor(options) {
256
+ this.config = null;
257
+ this.lastETag = "";
258
+ this.streamState = "idle";
259
+ this.pollTimer = null;
260
+ this.reconnectTimer = null;
261
+ this.telemetryTimer = null;
262
+ this.abortController = null;
263
+ this.initPromise = null;
264
+ this.telemetryCounters = /* @__PURE__ */ new Map();
265
+ this.apiKey = options.apiKey;
266
+ this.environment = options.environment;
267
+ this.gatewayUrl = options.gatewayUrl;
268
+ }
269
+ async init() {
270
+ if (this.config) return;
271
+ if (this.initPromise) return this.initPromise;
272
+ this.initPromise = this.doInit();
273
+ try {
274
+ await this.initPromise;
275
+ } finally {
276
+ this.initPromise = null;
277
+ }
278
+ }
279
+ async doInit() {
280
+ const resp = await fetch(`${this.gatewayUrl}/v1/flags/config?environment=${encodeURIComponent(this.environment)}`, {
281
+ headers: { "x-api-key": this.apiKey }
282
+ });
283
+ if (resp.status === 403) throw new Error("Secret API key required for /config");
284
+ if (!resp.ok) throw new Error(`Config fetch failed: ${resp.status}`);
285
+ const json = await resp.json();
286
+ this.config = json.data;
287
+ this.lastETag = resp.headers.get("etag") || "";
288
+ this.connectStream();
289
+ this.startTelemetryFlush();
290
+ }
291
+ evaluate(flagKey, context) {
292
+ if (!this.config) throw new Error("FlagClient not initialized \u2014 call init() first");
293
+ const flagConfig = this.config.flags.find((f) => f.flag_key === flagKey);
294
+ if (!flagConfig) {
295
+ return {
296
+ flag_id: "",
297
+ flag_key: flagKey,
298
+ environment: this.environment,
299
+ value: null,
300
+ reason: "not_found",
301
+ matched_rule_id: null,
302
+ variant_key: null,
303
+ bucket: null
304
+ };
305
+ }
306
+ const result2 = evaluateFlag(flagConfig, this.config, context);
307
+ this.recordTelemetry(result2);
308
+ return result2;
309
+ }
310
+ evaluateBatch(flagKeys, context) {
311
+ if (!this.config) throw new Error("FlagClient not initialized \u2014 call init() first");
312
+ const results = {};
313
+ for (const key of flagKeys) {
314
+ const flagConfig = this.config.flags.find((f) => f.flag_key === key);
315
+ if (flagConfig) {
316
+ const result2 = evaluateFlag(flagConfig, this.config, context);
317
+ this.recordTelemetry(result2);
318
+ results[key] = result2;
319
+ }
320
+ }
321
+ return results;
322
+ }
323
+ async shutdown() {
324
+ this.streamState = "idle";
325
+ this.abortController?.abort();
326
+ this.abortController = null;
327
+ if (this.pollTimer) {
328
+ clearInterval(this.pollTimer);
329
+ this.pollTimer = null;
330
+ }
331
+ if (this.reconnectTimer) {
332
+ clearInterval(this.reconnectTimer);
333
+ this.reconnectTimer = null;
334
+ }
335
+ if (this.telemetryTimer) {
336
+ clearInterval(this.telemetryTimer);
337
+ this.telemetryTimer = null;
338
+ }
339
+ await this.flushTelemetry();
340
+ }
341
+ // ======== SSE Streaming ========
342
+ async connectStream() {
343
+ if (this.streamState === "streaming") return;
344
+ this.abortController?.abort();
345
+ this.abortController = new AbortController();
346
+ try {
347
+ const resp = await fetch(
348
+ `${this.gatewayUrl}/v1/flags/stream?environment=${encodeURIComponent(this.environment)}`,
349
+ {
350
+ headers: {
351
+ "x-api-key": this.apiKey,
352
+ "Last-Event-ID": String(this.config?.version ?? 0)
353
+ },
354
+ signal: this.abortController.signal
355
+ }
356
+ );
357
+ if (!resp.ok || !resp.body) {
358
+ this.startPolling();
359
+ return;
360
+ }
361
+ this.streamState = "streaming";
362
+ this.stopPolling();
363
+ const reader = resp.body.getReader();
364
+ const decoder = new TextDecoder();
365
+ let buffer = "";
366
+ while (true) {
367
+ const { done, value } = await reader.read();
368
+ if (done) break;
369
+ buffer += decoder.decode(value, { stream: true });
370
+ let idx;
371
+ while ((idx = buffer.indexOf("\n\n")) !== -1) {
372
+ const frame = buffer.slice(0, idx);
373
+ buffer = buffer.slice(idx + 2);
374
+ this.handleSseFrame(frame);
375
+ }
376
+ }
377
+ } catch {
378
+ }
379
+ if (this.streamState === "streaming") {
380
+ this.streamState = "idle";
381
+ this.startPolling();
382
+ }
383
+ }
384
+ handleSseFrame(frame) {
385
+ let eventType = "";
386
+ let data = "";
387
+ for (const line of frame.split("\n")) {
388
+ if (line.startsWith("event:")) eventType = line.slice(6).trim();
389
+ else if (line.startsWith("data:")) data += line.slice(5).trim();
390
+ }
391
+ if (eventType === "config" && data) {
392
+ try {
393
+ const parsed = JSON.parse(data);
394
+ const newConfig = parsed.data;
395
+ if (newConfig && newConfig.version !== void 0) {
396
+ this.config = newConfig;
397
+ }
398
+ } catch {
399
+ }
400
+ }
401
+ }
402
+ // ======== Polling Fallback ========
403
+ startPolling() {
404
+ if (this.streamState === "polling") return;
405
+ this.streamState = "polling";
406
+ this.pollTimer = setInterval(() => void this.pollConfig(), 6e4);
407
+ this.reconnectTimer = setInterval(() => void this.connectStream(), 3e5);
408
+ }
409
+ stopPolling() {
410
+ if (this.pollTimer) {
411
+ clearInterval(this.pollTimer);
412
+ this.pollTimer = null;
413
+ }
414
+ if (this.reconnectTimer) {
415
+ clearInterval(this.reconnectTimer);
416
+ this.reconnectTimer = null;
417
+ }
418
+ }
419
+ async pollConfig() {
420
+ try {
421
+ const headers = { "x-api-key": this.apiKey };
422
+ if (this.lastETag) headers["if-none-match"] = this.lastETag;
423
+ const resp = await fetch(
424
+ `${this.gatewayUrl}/v1/flags/config?environment=${encodeURIComponent(this.environment)}`,
425
+ { headers }
426
+ );
427
+ if (resp.status === 304) return;
428
+ if (!resp.ok) return;
429
+ const json = await resp.json();
430
+ this.config = json.data;
431
+ this.lastETag = resp.headers.get("etag") || "";
432
+ } catch {
433
+ }
434
+ }
435
+ // ======== Telemetry ========
436
+ recordTelemetry(evaluation) {
437
+ const key = `${evaluation.flag_key}:${evaluation.reason}:${String(evaluation.value)}`;
438
+ const existing = this.telemetryCounters.get(key);
439
+ if (existing) {
440
+ existing.count++;
441
+ if (evaluation.value === true) existing.true_count++;
442
+ else if (evaluation.value === false) existing.false_count++;
443
+ } else {
444
+ this.telemetryCounters.set(key, {
445
+ flag_key: evaluation.flag_key,
446
+ flag_id: evaluation.flag_id,
447
+ reason: evaluation.reason,
448
+ count: 1,
449
+ true_count: evaluation.value === true ? 1 : 0,
450
+ false_count: evaluation.value === false ? 1 : 0
451
+ });
452
+ }
453
+ }
454
+ startTelemetryFlush() {
455
+ this.telemetryTimer = setInterval(() => void this.flushTelemetry(), 6e4);
456
+ }
457
+ async flushTelemetry() {
458
+ if (this.telemetryCounters.size === 0) return;
459
+ const evaluations = Array.from(this.telemetryCounters.values());
460
+ this.telemetryCounters.clear();
461
+ try {
462
+ await fetch(`${this.gatewayUrl}/v1/flags/telemetry`, {
463
+ method: "POST",
464
+ headers: {
465
+ "Content-Type": "application/json",
466
+ "x-api-key": this.apiKey
467
+ },
468
+ body: JSON.stringify({
469
+ environment: this.environment,
470
+ evaluations
471
+ })
472
+ });
473
+ } catch {
474
+ for (const counter of evaluations) {
475
+ const key = `${counter.flag_key}:${counter.reason}:${counter.count}`;
476
+ const existing = this.telemetryCounters.get(key);
477
+ if (existing) {
478
+ existing.count += counter.count;
479
+ existing.true_count += counter.true_count;
480
+ existing.false_count += counter.false_count;
481
+ } else {
482
+ this.telemetryCounters.set(key, counter);
483
+ }
484
+ }
485
+ }
486
+ }
487
+ };
488
+ export {
489
+ FlagClient,
490
+ allConditionsMatch,
491
+ evaluateFlag,
492
+ hashToBucket
493
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalemule/sdk",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "Official TypeScript/JavaScript SDK for ScaleMule Backend-as-a-Service",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -10,6 +10,11 @@
10
10
  "types": "./dist/index.d.ts",
11
11
  "import": "./dist/index.mjs",
12
12
  "require": "./dist/index.js"
13
+ },
14
+ "./flags/server": {
15
+ "types": "./dist/flags/server.d.ts",
16
+ "import": "./dist/flags/server.mjs",
17
+ "require": "./dist/flags/server.js"
13
18
  }
14
19
  },
15
20
  "files": [
@@ -18,7 +23,7 @@
18
23
  "LICENSE"
19
24
  ],
20
25
  "scripts": {
21
- "build": "tsup src/index.ts --format cjs,esm --dts --clean --external @scalemule/ui --external browser-image-compression",
26
+ "build": "tsup src/index.ts src/flags/server.ts --format cjs,esm --dts --clean --external @scalemule/ui --external browser-image-compression",
22
27
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
23
28
  "test": "vitest run",
24
29
  "test:watch": "vitest",
@@ -56,7 +61,9 @@
56
61
  "engines": {
57
62
  "node": ">=18.0.0"
58
63
  },
59
- "dependencies": {},
64
+ "dependencies": {
65
+ "semver": "^7.7.4"
66
+ },
60
67
  "peerDependencies": {
61
68
  "@scalemule/ui": "^0.0.1",
62
69
  "browser-image-compression": ">=2.0.0"