@rolloutctrl/js-sdk 0.0.5 → 0.0.6

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 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]) => ({ 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) {
@@ -444,9 +451,12 @@ var RolloutCtrlClient = class {
444
451
  } else {
445
452
  type = "FLAG_DISABLED";
446
453
  }
454
+ const fingerprint = `${type}:${result.strategy?.id ?? ""}:${result.variant?.id ?? ""}`;
455
+ if (this.trackedEvaluations.get(flagKey) === fingerprint) return;
456
+ this.trackedEvaluations.set(flagKey, fingerprint);
447
457
  this.metricsQueue.push({
448
458
  featureFlagId: flag.id,
449
- featureFlagEnvironmentId: config.environmentId,
459
+ featureFlagEnvironmentId: flag.featureFlagEnvironmentId,
450
460
  type,
451
461
  strategyId: result.strategy?.id,
452
462
  variantId: result.variant?.id
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]) => ({ 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) {
@@ -415,9 +422,12 @@ var RolloutCtrlClient = class {
415
422
  } else {
416
423
  type = "FLAG_DISABLED";
417
424
  }
425
+ const fingerprint = `${type}:${result.strategy?.id ?? ""}:${result.variant?.id ?? ""}`;
426
+ if (this.trackedEvaluations.get(flagKey) === fingerprint) return;
427
+ this.trackedEvaluations.set(flagKey, fingerprint);
418
428
  this.metricsQueue.push({
419
429
  featureFlagId: flag.id,
420
- featureFlagEnvironmentId: config.environmentId,
430
+ featureFlagEnvironmentId: flag.featureFlagEnvironmentId,
421
431
  type,
422
432
  strategyId: result.strategy?.id,
423
433
  variantId: result.variant?.id
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolloutctrl/js-sdk",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "RolloutCtrl JavaScript SDK for browser applications",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",