@rolloutctrl/js-sdk 0.0.5 → 0.0.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.
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +24 -16
- package/dist/index.mjs +24 -16
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,7 @@ import { FeatureFlagEnvironment, Action, EvaluationContext, EvaluationResult } f
|
|
|
3
3
|
interface FlagConfig extends FeatureFlagEnvironment {
|
|
4
4
|
id: string;
|
|
5
5
|
key: string;
|
|
6
|
+
featureFlagEnvironmentId: string;
|
|
6
7
|
}
|
|
7
8
|
interface Configuration {
|
|
8
9
|
projectId: string;
|
|
@@ -56,6 +57,7 @@ declare class RolloutCtrlClient {
|
|
|
56
57
|
private readonly metricsQueue;
|
|
57
58
|
private readonly subscribers;
|
|
58
59
|
private isInitialized;
|
|
60
|
+
private readonly trackedEvaluations;
|
|
59
61
|
private readonly readyPromise;
|
|
60
62
|
private resolveReady;
|
|
61
63
|
private rejectReady;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { FeatureFlagEnvironment, Action, EvaluationContext, EvaluationResult } f
|
|
|
3
3
|
interface FlagConfig extends FeatureFlagEnvironment {
|
|
4
4
|
id: string;
|
|
5
5
|
key: string;
|
|
6
|
+
featureFlagEnvironmentId: string;
|
|
6
7
|
}
|
|
7
8
|
interface Configuration {
|
|
8
9
|
projectId: string;
|
|
@@ -56,6 +57,7 @@ declare class RolloutCtrlClient {
|
|
|
56
57
|
private readonly metricsQueue;
|
|
57
58
|
private readonly subscribers;
|
|
58
59
|
private isInitialized;
|
|
60
|
+
private readonly trackedEvaluations;
|
|
59
61
|
private readonly readyPromise;
|
|
60
62
|
private resolveReady;
|
|
61
63
|
private rejectReady;
|
package/dist/index.js
CHANGED
|
@@ -172,7 +172,12 @@ var HttpConfigurationRepository = class {
|
|
|
172
172
|
return this.normalizeConfiguration(raw);
|
|
173
173
|
}
|
|
174
174
|
normalizeConfiguration(raw) {
|
|
175
|
-
const flags = Array.isArray(raw.flags) ? raw.flags : Object.entries(raw.flags ?? {}).map(([key, value]) => ({
|
|
175
|
+
const flags = Array.isArray(raw.flags) ? raw.flags : Object.entries(raw.flags ?? {}).map(([key, value]) => ({
|
|
176
|
+
key,
|
|
177
|
+
...value,
|
|
178
|
+
id: value._featureFlagId ?? value.id ?? "",
|
|
179
|
+
featureFlagEnvironmentId: value._featureFlagEnvironmentId ?? ""
|
|
180
|
+
}));
|
|
176
181
|
const actions = Array.isArray(raw.actions) ? raw.actions : Object.values(raw.actions ?? {});
|
|
177
182
|
return {
|
|
178
183
|
projectId: raw.project?.id ?? raw.projectId ?? "",
|
|
@@ -329,6 +334,7 @@ var RolloutCtrlClient = class {
|
|
|
329
334
|
this.emitter = new TinyEmitter();
|
|
330
335
|
this.subscribers = /* @__PURE__ */ new Set();
|
|
331
336
|
this.isInitialized = false;
|
|
337
|
+
this.trackedEvaluations = /* @__PURE__ */ new Map();
|
|
332
338
|
const apiUrl = options.apiUrl ?? DEFAULT_API_URL;
|
|
333
339
|
const refreshInterval = options.refreshInterval ?? DEFAULT_REFRESH_INTERVAL;
|
|
334
340
|
const requestTimeout = options.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT;
|
|
@@ -338,6 +344,7 @@ var RolloutCtrlClient = class {
|
|
|
338
344
|
this.metricsQueue = options.enableMetrics ?? true ? new MetricsQueue(apiUrl, options.sdkKey, requestTimeout) : null;
|
|
339
345
|
this.repository.subscribe((configuration) => {
|
|
340
346
|
this.evaluatorManager.update(configuration);
|
|
347
|
+
this.trackedEvaluations.clear();
|
|
341
348
|
options.storage?.set(configuration).catch(() => {
|
|
342
349
|
});
|
|
343
350
|
if (this.isInitialized) {
|
|
@@ -434,23 +441,24 @@ var RolloutCtrlClient = class {
|
|
|
434
441
|
const config = this.repository.getConfiguration();
|
|
435
442
|
const flag = config.flags.find((f) => f.key === flagKey);
|
|
436
443
|
if (!flag) return;
|
|
437
|
-
|
|
438
|
-
if (
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
+
const fingerprint = `${result.enabled ? 1 : 0}:${result.strategy?.id ?? ""}:${result.variant?.id ?? ""}`;
|
|
445
|
+
if (this.trackedEvaluations.get(flagKey) === fingerprint) return;
|
|
446
|
+
this.trackedEvaluations.set(flagKey, fingerprint);
|
|
447
|
+
const base = {
|
|
448
|
+
featureFlagId: flag.id,
|
|
449
|
+
featureFlagEnvironmentId: flag.featureFlagEnvironmentId
|
|
450
|
+
};
|
|
451
|
+
if (result.enabled) {
|
|
452
|
+
this.metricsQueue.push({ ...base, type: "FLAG_ENABLED" });
|
|
453
|
+
if (result.strategy?.id) {
|
|
454
|
+
this.metricsQueue.push({ ...base, type: "STRATEGY_MATCH", strategyId: result.strategy.id });
|
|
455
|
+
}
|
|
456
|
+
if (result.variant?.id) {
|
|
457
|
+
this.metricsQueue.push({ ...base, type: "VARIANT_EXPOSURE", variantId: result.variant.id });
|
|
458
|
+
}
|
|
444
459
|
} else {
|
|
445
|
-
type
|
|
460
|
+
this.metricsQueue.push({ ...base, type: "FLAG_DISABLED" });
|
|
446
461
|
}
|
|
447
|
-
this.metricsQueue.push({
|
|
448
|
-
featureFlagId: flag.id,
|
|
449
|
-
featureFlagEnvironmentId: config.environmentId,
|
|
450
|
-
type,
|
|
451
|
-
strategyId: result.strategy?.id,
|
|
452
|
-
variantId: result.variant?.id
|
|
453
|
-
});
|
|
454
462
|
} catch {
|
|
455
463
|
}
|
|
456
464
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -143,7 +143,12 @@ var HttpConfigurationRepository = class {
|
|
|
143
143
|
return this.normalizeConfiguration(raw);
|
|
144
144
|
}
|
|
145
145
|
normalizeConfiguration(raw) {
|
|
146
|
-
const flags = Array.isArray(raw.flags) ? raw.flags : Object.entries(raw.flags ?? {}).map(([key, value]) => ({
|
|
146
|
+
const flags = Array.isArray(raw.flags) ? raw.flags : Object.entries(raw.flags ?? {}).map(([key, value]) => ({
|
|
147
|
+
key,
|
|
148
|
+
...value,
|
|
149
|
+
id: value._featureFlagId ?? value.id ?? "",
|
|
150
|
+
featureFlagEnvironmentId: value._featureFlagEnvironmentId ?? ""
|
|
151
|
+
}));
|
|
147
152
|
const actions = Array.isArray(raw.actions) ? raw.actions : Object.values(raw.actions ?? {});
|
|
148
153
|
return {
|
|
149
154
|
projectId: raw.project?.id ?? raw.projectId ?? "",
|
|
@@ -300,6 +305,7 @@ var RolloutCtrlClient = class {
|
|
|
300
305
|
this.emitter = new TinyEmitter();
|
|
301
306
|
this.subscribers = /* @__PURE__ */ new Set();
|
|
302
307
|
this.isInitialized = false;
|
|
308
|
+
this.trackedEvaluations = /* @__PURE__ */ new Map();
|
|
303
309
|
const apiUrl = options.apiUrl ?? DEFAULT_API_URL;
|
|
304
310
|
const refreshInterval = options.refreshInterval ?? DEFAULT_REFRESH_INTERVAL;
|
|
305
311
|
const requestTimeout = options.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT;
|
|
@@ -309,6 +315,7 @@ var RolloutCtrlClient = class {
|
|
|
309
315
|
this.metricsQueue = options.enableMetrics ?? true ? new MetricsQueue(apiUrl, options.sdkKey, requestTimeout) : null;
|
|
310
316
|
this.repository.subscribe((configuration) => {
|
|
311
317
|
this.evaluatorManager.update(configuration);
|
|
318
|
+
this.trackedEvaluations.clear();
|
|
312
319
|
options.storage?.set(configuration).catch(() => {
|
|
313
320
|
});
|
|
314
321
|
if (this.isInitialized) {
|
|
@@ -405,23 +412,24 @@ var RolloutCtrlClient = class {
|
|
|
405
412
|
const config = this.repository.getConfiguration();
|
|
406
413
|
const flag = config.flags.find((f) => f.key === flagKey);
|
|
407
414
|
if (!flag) return;
|
|
408
|
-
|
|
409
|
-
if (
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
+
const fingerprint = `${result.enabled ? 1 : 0}:${result.strategy?.id ?? ""}:${result.variant?.id ?? ""}`;
|
|
416
|
+
if (this.trackedEvaluations.get(flagKey) === fingerprint) return;
|
|
417
|
+
this.trackedEvaluations.set(flagKey, fingerprint);
|
|
418
|
+
const base = {
|
|
419
|
+
featureFlagId: flag.id,
|
|
420
|
+
featureFlagEnvironmentId: flag.featureFlagEnvironmentId
|
|
421
|
+
};
|
|
422
|
+
if (result.enabled) {
|
|
423
|
+
this.metricsQueue.push({ ...base, type: "FLAG_ENABLED" });
|
|
424
|
+
if (result.strategy?.id) {
|
|
425
|
+
this.metricsQueue.push({ ...base, type: "STRATEGY_MATCH", strategyId: result.strategy.id });
|
|
426
|
+
}
|
|
427
|
+
if (result.variant?.id) {
|
|
428
|
+
this.metricsQueue.push({ ...base, type: "VARIANT_EXPOSURE", variantId: result.variant.id });
|
|
429
|
+
}
|
|
415
430
|
} else {
|
|
416
|
-
type
|
|
431
|
+
this.metricsQueue.push({ ...base, type: "FLAG_DISABLED" });
|
|
417
432
|
}
|
|
418
|
-
this.metricsQueue.push({
|
|
419
|
-
featureFlagId: flag.id,
|
|
420
|
-
featureFlagEnvironmentId: config.environmentId,
|
|
421
|
-
type,
|
|
422
|
-
strategyId: result.strategy?.id,
|
|
423
|
-
variantId: result.variant?.id
|
|
424
|
-
});
|
|
425
433
|
} catch {
|
|
426
434
|
}
|
|
427
435
|
}
|