@flipswitch-io/sdk 0.1.7 → 0.1.9
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 +10 -8
- package/dist/index.d.ts +10 -8
- package/dist/index.js +19 -18
- package/dist/index.mjs +19 -18
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ProviderMetadata, ClientProviderStatus, EvaluationContext,
|
|
1
|
+
import { ProviderMetadata, ClientProviderStatus, EvaluationContext, ResolutionDetails, JsonValue } from '@openfeature/core';
|
|
2
|
+
import { OpenFeatureEventEmitter } from '@openfeature/web-sdk';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Configuration options for the Flipswitch provider.
|
|
@@ -172,7 +173,6 @@ interface FlagEvaluation {
|
|
|
172
173
|
variant: string | null;
|
|
173
174
|
}
|
|
174
175
|
|
|
175
|
-
type EventHandler = () => void;
|
|
176
176
|
/**
|
|
177
177
|
* Flipswitch OpenFeature provider with real-time SSE support.
|
|
178
178
|
*
|
|
@@ -197,6 +197,7 @@ type EventHandler = () => void;
|
|
|
197
197
|
declare class FlipswitchProvider {
|
|
198
198
|
readonly metadata: ProviderMetadata;
|
|
199
199
|
readonly rulesFromFlagValue = false;
|
|
200
|
+
readonly events: OpenFeatureEventEmitter;
|
|
200
201
|
private readonly baseUrl;
|
|
201
202
|
private readonly apiKey;
|
|
202
203
|
private readonly enableRealtime;
|
|
@@ -210,7 +211,7 @@ declare class FlipswitchProvider {
|
|
|
210
211
|
private readonly offlineMode;
|
|
211
212
|
private sseClient;
|
|
212
213
|
private _status;
|
|
213
|
-
private
|
|
214
|
+
private _currentContext;
|
|
214
215
|
private userEventHandlers;
|
|
215
216
|
private pollingTimer;
|
|
216
217
|
private sseRetryCount;
|
|
@@ -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
|
*/
|
|
@@ -272,13 +278,9 @@ declare class FlipswitchProvider {
|
|
|
272
278
|
*/
|
|
273
279
|
private handleFlagChange;
|
|
274
280
|
/**
|
|
275
|
-
* Emit an event
|
|
281
|
+
* Emit an event through the OpenFeature event emitter.
|
|
276
282
|
*/
|
|
277
283
|
private emit;
|
|
278
|
-
/**
|
|
279
|
-
* Register an event handler.
|
|
280
|
-
*/
|
|
281
|
-
onProviderEvent?(event: ClientProviderEvents, handler: EventHandler): void;
|
|
282
284
|
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext): ResolutionDetails<boolean>;
|
|
283
285
|
resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext): ResolutionDetails<string>;
|
|
284
286
|
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext): ResolutionDetails<number>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ProviderMetadata, ClientProviderStatus, EvaluationContext,
|
|
1
|
+
import { ProviderMetadata, ClientProviderStatus, EvaluationContext, ResolutionDetails, JsonValue } from '@openfeature/core';
|
|
2
|
+
import { OpenFeatureEventEmitter } from '@openfeature/web-sdk';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Configuration options for the Flipswitch provider.
|
|
@@ -172,7 +173,6 @@ interface FlagEvaluation {
|
|
|
172
173
|
variant: string | null;
|
|
173
174
|
}
|
|
174
175
|
|
|
175
|
-
type EventHandler = () => void;
|
|
176
176
|
/**
|
|
177
177
|
* Flipswitch OpenFeature provider with real-time SSE support.
|
|
178
178
|
*
|
|
@@ -197,6 +197,7 @@ type EventHandler = () => void;
|
|
|
197
197
|
declare class FlipswitchProvider {
|
|
198
198
|
readonly metadata: ProviderMetadata;
|
|
199
199
|
readonly rulesFromFlagValue = false;
|
|
200
|
+
readonly events: OpenFeatureEventEmitter;
|
|
200
201
|
private readonly baseUrl;
|
|
201
202
|
private readonly apiKey;
|
|
202
203
|
private readonly enableRealtime;
|
|
@@ -210,7 +211,7 @@ declare class FlipswitchProvider {
|
|
|
210
211
|
private readonly offlineMode;
|
|
211
212
|
private sseClient;
|
|
212
213
|
private _status;
|
|
213
|
-
private
|
|
214
|
+
private _currentContext;
|
|
214
215
|
private userEventHandlers;
|
|
215
216
|
private pollingTimer;
|
|
216
217
|
private sseRetryCount;
|
|
@@ -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
|
*/
|
|
@@ -272,13 +278,9 @@ declare class FlipswitchProvider {
|
|
|
272
278
|
*/
|
|
273
279
|
private handleFlagChange;
|
|
274
280
|
/**
|
|
275
|
-
* Emit an event
|
|
281
|
+
* Emit an event through the OpenFeature event emitter.
|
|
276
282
|
*/
|
|
277
283
|
private emit;
|
|
278
|
-
/**
|
|
279
|
-
* Register an event handler.
|
|
280
|
-
*/
|
|
281
|
-
onProviderEvent?(event: ClientProviderEvents, handler: EventHandler): void;
|
|
282
284
|
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext): ResolutionDetails<boolean>;
|
|
283
285
|
resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext): ResolutionDetails<string>;
|
|
284
286
|
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext): ResolutionDetails<number>;
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
29
29
|
|
|
30
30
|
// src/provider.ts
|
|
31
31
|
var import_core = require("@openfeature/core");
|
|
32
|
+
var import_web_sdk = require("@openfeature/web-sdk");
|
|
32
33
|
var import_ofrep_web_provider = require("@openfeature/ofrep-web-provider");
|
|
33
34
|
|
|
34
35
|
// src/sse-client.ts
|
|
@@ -488,7 +489,7 @@ var BrowserCache = class {
|
|
|
488
489
|
};
|
|
489
490
|
|
|
490
491
|
// package.json
|
|
491
|
-
var version = "0.1.
|
|
492
|
+
var version = "0.1.9";
|
|
492
493
|
|
|
493
494
|
// src/provider.ts
|
|
494
495
|
var DEFAULT_BASE_URL = "https://api.flipswitch.io";
|
|
@@ -500,9 +501,10 @@ var FlipswitchProvider = class {
|
|
|
500
501
|
name: "flipswitch"
|
|
501
502
|
};
|
|
502
503
|
this.rulesFromFlagValue = false;
|
|
504
|
+
this.events = new import_web_sdk.OpenFeatureEventEmitter();
|
|
503
505
|
this.sseClient = null;
|
|
504
506
|
this._status = import_core.ClientProviderStatus.NOT_READY;
|
|
505
|
-
this.
|
|
507
|
+
this._currentContext = {};
|
|
506
508
|
this.userEventHandlers = {};
|
|
507
509
|
this.pollingTimer = null;
|
|
508
510
|
this.sseRetryCount = 0;
|
|
@@ -608,6 +610,7 @@ var FlipswitchProvider = class {
|
|
|
608
610
|
*/
|
|
609
611
|
async initialize(context) {
|
|
610
612
|
this._status = import_core.ClientProviderStatus.NOT_READY;
|
|
613
|
+
this._currentContext = context ?? {};
|
|
611
614
|
this.setupOfflineHandling();
|
|
612
615
|
if (!this._isOnline && this.offlineMode) {
|
|
613
616
|
console.warn("[Flipswitch] Starting in offline mode - using cached flag values");
|
|
@@ -649,6 +652,16 @@ var FlipswitchProvider = class {
|
|
|
649
652
|
this._status = import_core.ClientProviderStatus.READY;
|
|
650
653
|
this.emit(import_core.ClientProviderEvents.Ready);
|
|
651
654
|
}
|
|
655
|
+
/**
|
|
656
|
+
* Called by OpenFeature when the global evaluation context changes.
|
|
657
|
+
* This happens when the user logs in/out and the targeting key changes.
|
|
658
|
+
*/
|
|
659
|
+
async onContextChange(oldContext, newContext) {
|
|
660
|
+
this._currentContext = newContext;
|
|
661
|
+
this.browserCache?.invalidate();
|
|
662
|
+
await this.ofrepProvider.onContextChange?.(oldContext, newContext);
|
|
663
|
+
this.emit(import_core.ClientProviderEvents.ConfigurationChanged);
|
|
664
|
+
}
|
|
652
665
|
/**
|
|
653
666
|
* Setup online/offline event handling.
|
|
654
667
|
*/
|
|
@@ -682,7 +695,7 @@ var FlipswitchProvider = class {
|
|
|
682
695
|
*/
|
|
683
696
|
async refreshFlags() {
|
|
684
697
|
try {
|
|
685
|
-
await this.ofrepProvider.onContextChange?.(
|
|
698
|
+
await this.ofrepProvider.onContextChange?.(this._currentContext, this._currentContext);
|
|
686
699
|
if (this._status === import_core.ClientProviderStatus.STALE) {
|
|
687
700
|
this._status = import_core.ClientProviderStatus.READY;
|
|
688
701
|
this.emit(import_core.ClientProviderEvents.Ready);
|
|
@@ -813,29 +826,17 @@ var FlipswitchProvider = class {
|
|
|
813
826
|
}
|
|
814
827
|
}
|
|
815
828
|
try {
|
|
816
|
-
await this.ofrepProvider.onContextChange?.(
|
|
829
|
+
await this.ofrepProvider.onContextChange?.(this._currentContext, this._currentContext);
|
|
817
830
|
} catch (error) {
|
|
818
831
|
console.warn("[Flipswitch] Failed to refresh flags after SSE event:", error);
|
|
819
832
|
}
|
|
820
833
|
this.emit(import_core.ClientProviderEvents.ConfigurationChanged);
|
|
821
834
|
}
|
|
822
835
|
/**
|
|
823
|
-
* Emit an event
|
|
836
|
+
* Emit an event through the OpenFeature event emitter.
|
|
824
837
|
*/
|
|
825
838
|
emit(event) {
|
|
826
|
-
|
|
827
|
-
if (handlers) {
|
|
828
|
-
Array.from(handlers).forEach((handler) => handler());
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
/**
|
|
832
|
-
* Register an event handler.
|
|
833
|
-
*/
|
|
834
|
-
onProviderEvent(event, handler) {
|
|
835
|
-
if (!this.eventHandlers.has(event)) {
|
|
836
|
-
this.eventHandlers.set(event, /* @__PURE__ */ new Set());
|
|
837
|
-
}
|
|
838
|
-
this.eventHandlers.get(event).add(handler);
|
|
839
|
+
this.events.emit(event);
|
|
839
840
|
}
|
|
840
841
|
// ===============================
|
|
841
842
|
// Flag Resolution Methods - Delegated to OFREP Provider
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
ClientProviderStatus,
|
|
4
4
|
ClientProviderEvents
|
|
5
5
|
} from "@openfeature/core";
|
|
6
|
+
import { OpenFeatureEventEmitter } from "@openfeature/web-sdk";
|
|
6
7
|
import { OFREPWebProvider } from "@openfeature/ofrep-web-provider";
|
|
7
8
|
|
|
8
9
|
// src/sse-client.ts
|
|
@@ -462,7 +463,7 @@ var BrowserCache = class {
|
|
|
462
463
|
};
|
|
463
464
|
|
|
464
465
|
// package.json
|
|
465
|
-
var version = "0.1.
|
|
466
|
+
var version = "0.1.9";
|
|
466
467
|
|
|
467
468
|
// src/provider.ts
|
|
468
469
|
var DEFAULT_BASE_URL = "https://api.flipswitch.io";
|
|
@@ -474,9 +475,10 @@ var FlipswitchProvider = class {
|
|
|
474
475
|
name: "flipswitch"
|
|
475
476
|
};
|
|
476
477
|
this.rulesFromFlagValue = false;
|
|
478
|
+
this.events = new OpenFeatureEventEmitter();
|
|
477
479
|
this.sseClient = null;
|
|
478
480
|
this._status = ClientProviderStatus.NOT_READY;
|
|
479
|
-
this.
|
|
481
|
+
this._currentContext = {};
|
|
480
482
|
this.userEventHandlers = {};
|
|
481
483
|
this.pollingTimer = null;
|
|
482
484
|
this.sseRetryCount = 0;
|
|
@@ -582,6 +584,7 @@ var FlipswitchProvider = class {
|
|
|
582
584
|
*/
|
|
583
585
|
async initialize(context) {
|
|
584
586
|
this._status = ClientProviderStatus.NOT_READY;
|
|
587
|
+
this._currentContext = context ?? {};
|
|
585
588
|
this.setupOfflineHandling();
|
|
586
589
|
if (!this._isOnline && this.offlineMode) {
|
|
587
590
|
console.warn("[Flipswitch] Starting in offline mode - using cached flag values");
|
|
@@ -623,6 +626,16 @@ var FlipswitchProvider = class {
|
|
|
623
626
|
this._status = ClientProviderStatus.READY;
|
|
624
627
|
this.emit(ClientProviderEvents.Ready);
|
|
625
628
|
}
|
|
629
|
+
/**
|
|
630
|
+
* Called by OpenFeature when the global evaluation context changes.
|
|
631
|
+
* This happens when the user logs in/out and the targeting key changes.
|
|
632
|
+
*/
|
|
633
|
+
async onContextChange(oldContext, newContext) {
|
|
634
|
+
this._currentContext = newContext;
|
|
635
|
+
this.browserCache?.invalidate();
|
|
636
|
+
await this.ofrepProvider.onContextChange?.(oldContext, newContext);
|
|
637
|
+
this.emit(ClientProviderEvents.ConfigurationChanged);
|
|
638
|
+
}
|
|
626
639
|
/**
|
|
627
640
|
* Setup online/offline event handling.
|
|
628
641
|
*/
|
|
@@ -656,7 +669,7 @@ var FlipswitchProvider = class {
|
|
|
656
669
|
*/
|
|
657
670
|
async refreshFlags() {
|
|
658
671
|
try {
|
|
659
|
-
await this.ofrepProvider.onContextChange?.(
|
|
672
|
+
await this.ofrepProvider.onContextChange?.(this._currentContext, this._currentContext);
|
|
660
673
|
if (this._status === ClientProviderStatus.STALE) {
|
|
661
674
|
this._status = ClientProviderStatus.READY;
|
|
662
675
|
this.emit(ClientProviderEvents.Ready);
|
|
@@ -787,29 +800,17 @@ var FlipswitchProvider = class {
|
|
|
787
800
|
}
|
|
788
801
|
}
|
|
789
802
|
try {
|
|
790
|
-
await this.ofrepProvider.onContextChange?.(
|
|
803
|
+
await this.ofrepProvider.onContextChange?.(this._currentContext, this._currentContext);
|
|
791
804
|
} catch (error) {
|
|
792
805
|
console.warn("[Flipswitch] Failed to refresh flags after SSE event:", error);
|
|
793
806
|
}
|
|
794
807
|
this.emit(ClientProviderEvents.ConfigurationChanged);
|
|
795
808
|
}
|
|
796
809
|
/**
|
|
797
|
-
* Emit an event
|
|
810
|
+
* Emit an event through the OpenFeature event emitter.
|
|
798
811
|
*/
|
|
799
812
|
emit(event) {
|
|
800
|
-
|
|
801
|
-
if (handlers) {
|
|
802
|
-
Array.from(handlers).forEach((handler) => handler());
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* Register an event handler.
|
|
807
|
-
*/
|
|
808
|
-
onProviderEvent(event, handler) {
|
|
809
|
-
if (!this.eventHandlers.has(event)) {
|
|
810
|
-
this.eventHandlers.set(event, /* @__PURE__ */ new Set());
|
|
811
|
-
}
|
|
812
|
-
this.eventHandlers.get(event).add(handler);
|
|
813
|
+
this.events.emit(event);
|
|
813
814
|
}
|
|
814
815
|
// ===============================
|
|
815
816
|
// Flag Resolution Methods - Delegated to OFREP Provider
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flipswitch-io/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
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",
|