@flipswitch-io/sdk 0.1.7 → 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 +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +15 -3
- package/dist/index.mjs +15 -3
- package/package.json +2 -2
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
|
@@ -488,7 +488,7 @@ var BrowserCache = class {
|
|
|
488
488
|
};
|
|
489
489
|
|
|
490
490
|
// package.json
|
|
491
|
-
var version = "0.1.
|
|
491
|
+
var version = "0.1.8";
|
|
492
492
|
|
|
493
493
|
// src/provider.ts
|
|
494
494
|
var DEFAULT_BASE_URL = "https://api.flipswitch.io";
|
|
@@ -502,6 +502,7 @@ var FlipswitchProvider = class {
|
|
|
502
502
|
this.rulesFromFlagValue = false;
|
|
503
503
|
this.sseClient = null;
|
|
504
504
|
this._status = import_core.ClientProviderStatus.NOT_READY;
|
|
505
|
+
this._currentContext = {};
|
|
505
506
|
this.eventHandlers = /* @__PURE__ */ new Map();
|
|
506
507
|
this.userEventHandlers = {};
|
|
507
508
|
this.pollingTimer = null;
|
|
@@ -608,6 +609,7 @@ var FlipswitchProvider = class {
|
|
|
608
609
|
*/
|
|
609
610
|
async initialize(context) {
|
|
610
611
|
this._status = import_core.ClientProviderStatus.NOT_READY;
|
|
612
|
+
this._currentContext = context ?? {};
|
|
611
613
|
this.setupOfflineHandling();
|
|
612
614
|
if (!this._isOnline && this.offlineMode) {
|
|
613
615
|
console.warn("[Flipswitch] Starting in offline mode - using cached flag values");
|
|
@@ -649,6 +651,16 @@ var FlipswitchProvider = class {
|
|
|
649
651
|
this._status = import_core.ClientProviderStatus.READY;
|
|
650
652
|
this.emit(import_core.ClientProviderEvents.Ready);
|
|
651
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
|
+
}
|
|
652
664
|
/**
|
|
653
665
|
* Setup online/offline event handling.
|
|
654
666
|
*/
|
|
@@ -682,7 +694,7 @@ var FlipswitchProvider = class {
|
|
|
682
694
|
*/
|
|
683
695
|
async refreshFlags() {
|
|
684
696
|
try {
|
|
685
|
-
await this.ofrepProvider.onContextChange?.(
|
|
697
|
+
await this.ofrepProvider.onContextChange?.(this._currentContext, this._currentContext);
|
|
686
698
|
if (this._status === import_core.ClientProviderStatus.STALE) {
|
|
687
699
|
this._status = import_core.ClientProviderStatus.READY;
|
|
688
700
|
this.emit(import_core.ClientProviderEvents.Ready);
|
|
@@ -813,7 +825,7 @@ var FlipswitchProvider = class {
|
|
|
813
825
|
}
|
|
814
826
|
}
|
|
815
827
|
try {
|
|
816
|
-
await this.ofrepProvider.onContextChange?.(
|
|
828
|
+
await this.ofrepProvider.onContextChange?.(this._currentContext, this._currentContext);
|
|
817
829
|
} catch (error) {
|
|
818
830
|
console.warn("[Flipswitch] Failed to refresh flags after SSE event:", error);
|
|
819
831
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -462,7 +462,7 @@ var BrowserCache = class {
|
|
|
462
462
|
};
|
|
463
463
|
|
|
464
464
|
// package.json
|
|
465
|
-
var version = "0.1.
|
|
465
|
+
var version = "0.1.8";
|
|
466
466
|
|
|
467
467
|
// src/provider.ts
|
|
468
468
|
var DEFAULT_BASE_URL = "https://api.flipswitch.io";
|
|
@@ -476,6 +476,7 @@ var FlipswitchProvider = class {
|
|
|
476
476
|
this.rulesFromFlagValue = false;
|
|
477
477
|
this.sseClient = null;
|
|
478
478
|
this._status = ClientProviderStatus.NOT_READY;
|
|
479
|
+
this._currentContext = {};
|
|
479
480
|
this.eventHandlers = /* @__PURE__ */ new Map();
|
|
480
481
|
this.userEventHandlers = {};
|
|
481
482
|
this.pollingTimer = null;
|
|
@@ -582,6 +583,7 @@ var FlipswitchProvider = class {
|
|
|
582
583
|
*/
|
|
583
584
|
async initialize(context) {
|
|
584
585
|
this._status = ClientProviderStatus.NOT_READY;
|
|
586
|
+
this._currentContext = context ?? {};
|
|
585
587
|
this.setupOfflineHandling();
|
|
586
588
|
if (!this._isOnline && this.offlineMode) {
|
|
587
589
|
console.warn("[Flipswitch] Starting in offline mode - using cached flag values");
|
|
@@ -623,6 +625,16 @@ var FlipswitchProvider = class {
|
|
|
623
625
|
this._status = ClientProviderStatus.READY;
|
|
624
626
|
this.emit(ClientProviderEvents.Ready);
|
|
625
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
|
+
}
|
|
626
638
|
/**
|
|
627
639
|
* Setup online/offline event handling.
|
|
628
640
|
*/
|
|
@@ -656,7 +668,7 @@ var FlipswitchProvider = class {
|
|
|
656
668
|
*/
|
|
657
669
|
async refreshFlags() {
|
|
658
670
|
try {
|
|
659
|
-
await this.ofrepProvider.onContextChange?.(
|
|
671
|
+
await this.ofrepProvider.onContextChange?.(this._currentContext, this._currentContext);
|
|
660
672
|
if (this._status === ClientProviderStatus.STALE) {
|
|
661
673
|
this._status = ClientProviderStatus.READY;
|
|
662
674
|
this.emit(ClientProviderEvents.Ready);
|
|
@@ -787,7 +799,7 @@ var FlipswitchProvider = class {
|
|
|
787
799
|
}
|
|
788
800
|
}
|
|
789
801
|
try {
|
|
790
|
-
await this.ofrepProvider.onContextChange?.(
|
|
802
|
+
await this.ofrepProvider.onContextChange?.(this._currentContext, this._currentContext);
|
|
791
803
|
} catch (error) {
|
|
792
804
|
console.warn("[Flipswitch] Failed to refresh flags after SSE event:", error);
|
|
793
805
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flipswitch-io/sdk",
|
|
3
|
-
"version": "0.1.
|
|
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": "^
|
|
60
|
+
"eslint": "^10.0.0",
|
|
61
61
|
"tsup": "^8.0.1",
|
|
62
62
|
"tsx": "^4.7.0",
|
|
63
63
|
"typescript": "^5.3.0",
|