@flipswitch-io/sdk 0.1.6 → 0.1.8

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
@@ -210,6 +210,7 @@ declare class FlipswitchProvider {
210
210
  private readonly offlineMode;
211
211
  private sseClient;
212
212
  private _status;
213
+ private _currentContext;
213
214
  private eventHandlers;
214
215
  private userEventHandlers;
215
216
  private pollingTimer;
@@ -230,6 +231,11 @@ declare class FlipswitchProvider {
230
231
  * Validates the API key and starts SSE connection if real-time is enabled.
231
232
  */
232
233
  initialize(context?: EvaluationContext): Promise<void>;
234
+ /**
235
+ * Called by OpenFeature when the global evaluation context changes.
236
+ * This happens when the user logs in/out and the targeting key changes.
237
+ */
238
+ onContextChange(oldContext: EvaluationContext, newContext: EvaluationContext): Promise<void>;
233
239
  /**
234
240
  * Setup online/offline event handling.
235
241
  */
package/dist/index.d.ts CHANGED
@@ -210,6 +210,7 @@ declare class FlipswitchProvider {
210
210
  private readonly offlineMode;
211
211
  private sseClient;
212
212
  private _status;
213
+ private _currentContext;
213
214
  private eventHandlers;
214
215
  private userEventHandlers;
215
216
  private pollingTimer;
@@ -230,6 +231,11 @@ declare class FlipswitchProvider {
230
231
  * Validates the API key and starts SSE connection if real-time is enabled.
231
232
  */
232
233
  initialize(context?: EvaluationContext): Promise<void>;
234
+ /**
235
+ * Called by OpenFeature when the global evaluation context changes.
236
+ * This happens when the user logs in/out and the targeting key changes.
237
+ */
238
+ onContextChange(oldContext: EvaluationContext, newContext: EvaluationContext): Promise<void>;
233
239
  /**
234
240
  * Setup online/offline event handling.
235
241
  */
package/dist/index.js CHANGED
@@ -487,9 +487,11 @@ var BrowserCache = class {
487
487
  }
488
488
  };
489
489
 
490
+ // package.json
491
+ var version = "0.1.8";
492
+
490
493
  // src/provider.ts
491
494
  var DEFAULT_BASE_URL = "https://api.flipswitch.io";
492
- var SDK_VERSION = "0.1.2";
493
495
  var DEFAULT_POLLING_INTERVAL = 3e4;
494
496
  var DEFAULT_MAX_SSE_RETRIES = 5;
495
497
  var FlipswitchProvider = class {
@@ -500,6 +502,7 @@ var FlipswitchProvider = class {
500
502
  this.rulesFromFlagValue = false;
501
503
  this.sseClient = null;
502
504
  this._status = import_core.ClientProviderStatus.NOT_READY;
505
+ this._currentContext = {};
503
506
  this.eventHandlers = /* @__PURE__ */ new Map();
504
507
  this.userEventHandlers = {};
505
508
  this.pollingTimer = null;
@@ -540,7 +543,7 @@ var FlipswitchProvider = class {
540
543
  });
541
544
  }
542
545
  getTelemetrySdkHeader() {
543
- return `javascript/${SDK_VERSION}`;
546
+ return `javascript/${version}`;
544
547
  }
545
548
  getTelemetryRuntimeHeader() {
546
549
  if (typeof process !== "undefined" && process.versions?.node) {
@@ -606,6 +609,7 @@ var FlipswitchProvider = class {
606
609
  */
607
610
  async initialize(context) {
608
611
  this._status = import_core.ClientProviderStatus.NOT_READY;
612
+ this._currentContext = context ?? {};
609
613
  this.setupOfflineHandling();
610
614
  if (!this._isOnline && this.offlineMode) {
611
615
  console.warn("[Flipswitch] Starting in offline mode - using cached flag values");
@@ -647,6 +651,16 @@ var FlipswitchProvider = class {
647
651
  this._status = import_core.ClientProviderStatus.READY;
648
652
  this.emit(import_core.ClientProviderEvents.Ready);
649
653
  }
654
+ /**
655
+ * Called by OpenFeature when the global evaluation context changes.
656
+ * This happens when the user logs in/out and the targeting key changes.
657
+ */
658
+ async onContextChange(oldContext, newContext) {
659
+ this._currentContext = newContext;
660
+ this.browserCache?.invalidate();
661
+ await this.ofrepProvider.onContextChange?.(oldContext, newContext);
662
+ this.emit(import_core.ClientProviderEvents.ConfigurationChanged);
663
+ }
650
664
  /**
651
665
  * Setup online/offline event handling.
652
666
  */
@@ -680,7 +694,7 @@ var FlipswitchProvider = class {
680
694
  */
681
695
  async refreshFlags() {
682
696
  try {
683
- await this.ofrepProvider.onContextChange?.({}, {});
697
+ await this.ofrepProvider.onContextChange?.(this._currentContext, this._currentContext);
684
698
  if (this._status === import_core.ClientProviderStatus.STALE) {
685
699
  this._status = import_core.ClientProviderStatus.READY;
686
700
  this.emit(import_core.ClientProviderEvents.Ready);
@@ -811,7 +825,7 @@ var FlipswitchProvider = class {
811
825
  }
812
826
  }
813
827
  try {
814
- await this.ofrepProvider.onContextChange?.({}, {});
828
+ await this.ofrepProvider.onContextChange?.(this._currentContext, this._currentContext);
815
829
  } catch (error) {
816
830
  console.warn("[Flipswitch] Failed to refresh flags after SSE event:", error);
817
831
  }
package/dist/index.mjs CHANGED
@@ -461,9 +461,11 @@ var BrowserCache = class {
461
461
  }
462
462
  };
463
463
 
464
+ // package.json
465
+ var version = "0.1.8";
466
+
464
467
  // src/provider.ts
465
468
  var DEFAULT_BASE_URL = "https://api.flipswitch.io";
466
- var SDK_VERSION = "0.1.2";
467
469
  var DEFAULT_POLLING_INTERVAL = 3e4;
468
470
  var DEFAULT_MAX_SSE_RETRIES = 5;
469
471
  var FlipswitchProvider = class {
@@ -474,6 +476,7 @@ var FlipswitchProvider = class {
474
476
  this.rulesFromFlagValue = false;
475
477
  this.sseClient = null;
476
478
  this._status = ClientProviderStatus.NOT_READY;
479
+ this._currentContext = {};
477
480
  this.eventHandlers = /* @__PURE__ */ new Map();
478
481
  this.userEventHandlers = {};
479
482
  this.pollingTimer = null;
@@ -514,7 +517,7 @@ var FlipswitchProvider = class {
514
517
  });
515
518
  }
516
519
  getTelemetrySdkHeader() {
517
- return `javascript/${SDK_VERSION}`;
520
+ return `javascript/${version}`;
518
521
  }
519
522
  getTelemetryRuntimeHeader() {
520
523
  if (typeof process !== "undefined" && process.versions?.node) {
@@ -580,6 +583,7 @@ var FlipswitchProvider = class {
580
583
  */
581
584
  async initialize(context) {
582
585
  this._status = ClientProviderStatus.NOT_READY;
586
+ this._currentContext = context ?? {};
583
587
  this.setupOfflineHandling();
584
588
  if (!this._isOnline && this.offlineMode) {
585
589
  console.warn("[Flipswitch] Starting in offline mode - using cached flag values");
@@ -621,6 +625,16 @@ var FlipswitchProvider = class {
621
625
  this._status = ClientProviderStatus.READY;
622
626
  this.emit(ClientProviderEvents.Ready);
623
627
  }
628
+ /**
629
+ * Called by OpenFeature when the global evaluation context changes.
630
+ * This happens when the user logs in/out and the targeting key changes.
631
+ */
632
+ async onContextChange(oldContext, newContext) {
633
+ this._currentContext = newContext;
634
+ this.browserCache?.invalidate();
635
+ await this.ofrepProvider.onContextChange?.(oldContext, newContext);
636
+ this.emit(ClientProviderEvents.ConfigurationChanged);
637
+ }
624
638
  /**
625
639
  * Setup online/offline event handling.
626
640
  */
@@ -654,7 +668,7 @@ var FlipswitchProvider = class {
654
668
  */
655
669
  async refreshFlags() {
656
670
  try {
657
- await this.ofrepProvider.onContextChange?.({}, {});
671
+ await this.ofrepProvider.onContextChange?.(this._currentContext, this._currentContext);
658
672
  if (this._status === ClientProviderStatus.STALE) {
659
673
  this._status = ClientProviderStatus.READY;
660
674
  this.emit(ClientProviderEvents.Ready);
@@ -785,7 +799,7 @@ var FlipswitchProvider = class {
785
799
  }
786
800
  }
787
801
  try {
788
- await this.ofrepProvider.onContextChange?.({}, {});
802
+ await this.ofrepProvider.onContextChange?.(this._currentContext, this._currentContext);
789
803
  } catch (error) {
790
804
  console.warn("[Flipswitch] Failed to refresh flags after SSE event:", error);
791
805
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flipswitch-io/sdk",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Flipswitch SDK with real-time SSE support for OpenFeature",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -57,7 +57,7 @@
57
57
  "@openfeature/server-sdk": "^1.17.0",
58
58
  "@openfeature/web-sdk": "^1.7.2",
59
59
  "@types/node": "^24.0.0",
60
- "eslint": "^9.0.0",
60
+ "eslint": "^10.0.0",
61
61
  "tsup": "^8.0.1",
62
62
  "tsx": "^4.7.0",
63
63
  "typescript": "^5.3.0",