@flipswitch-io/sdk 0.1.2 → 0.1.3
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 +3 -5
- package/dist/index.d.ts +3 -5
- package/dist/index.js +16 -15
- package/dist/index.mjs +19 -15
- package/package.json +3 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProviderMetadata, EvaluationContext, ResolutionDetails, JsonValue } from '@openfeature/core';
|
|
1
|
+
import { ProviderMetadata, ClientProviderStatus, EvaluationContext, ClientProviderEvents, ResolutionDetails, JsonValue } from '@openfeature/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Configuration options for the Flipswitch provider.
|
|
@@ -94,8 +94,6 @@ interface FlagEvaluation {
|
|
|
94
94
|
variant: string | null;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
type ProviderStatus = 'NOT_READY' | 'READY' | 'ERROR' | 'STALE';
|
|
98
|
-
type ProviderEvent = 'PROVIDER_READY' | 'PROVIDER_ERROR' | 'PROVIDER_STALE' | 'PROVIDER_CONFIGURATION_CHANGED';
|
|
99
97
|
type EventHandler = () => void;
|
|
100
98
|
/**
|
|
101
99
|
* Flipswitch OpenFeature provider with real-time SSE support.
|
|
@@ -137,7 +135,7 @@ declare class FlipswitchProvider {
|
|
|
137
135
|
private getTelemetryOsHeader;
|
|
138
136
|
private getTelemetryFeaturesHeader;
|
|
139
137
|
private getTelemetryHeaders;
|
|
140
|
-
get status():
|
|
138
|
+
get status(): ClientProviderStatus;
|
|
141
139
|
/**
|
|
142
140
|
* Initialize the provider.
|
|
143
141
|
* Validates the API key and starts SSE connection if real-time is enabled.
|
|
@@ -167,7 +165,7 @@ declare class FlipswitchProvider {
|
|
|
167
165
|
/**
|
|
168
166
|
* Register an event handler.
|
|
169
167
|
*/
|
|
170
|
-
onProviderEvent?(event:
|
|
168
|
+
onProviderEvent?(event: ClientProviderEvents, handler: EventHandler): void;
|
|
171
169
|
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext): ResolutionDetails<boolean>;
|
|
172
170
|
resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext): ResolutionDetails<string>;
|
|
173
171
|
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext): ResolutionDetails<number>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProviderMetadata, EvaluationContext, ResolutionDetails, JsonValue } from '@openfeature/core';
|
|
1
|
+
import { ProviderMetadata, ClientProviderStatus, EvaluationContext, ClientProviderEvents, ResolutionDetails, JsonValue } from '@openfeature/core';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Configuration options for the Flipswitch provider.
|
|
@@ -94,8 +94,6 @@ interface FlagEvaluation {
|
|
|
94
94
|
variant: string | null;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
type ProviderStatus = 'NOT_READY' | 'READY' | 'ERROR' | 'STALE';
|
|
98
|
-
type ProviderEvent = 'PROVIDER_READY' | 'PROVIDER_ERROR' | 'PROVIDER_STALE' | 'PROVIDER_CONFIGURATION_CHANGED';
|
|
99
97
|
type EventHandler = () => void;
|
|
100
98
|
/**
|
|
101
99
|
* Flipswitch OpenFeature provider with real-time SSE support.
|
|
@@ -137,7 +135,7 @@ declare class FlipswitchProvider {
|
|
|
137
135
|
private getTelemetryOsHeader;
|
|
138
136
|
private getTelemetryFeaturesHeader;
|
|
139
137
|
private getTelemetryHeaders;
|
|
140
|
-
get status():
|
|
138
|
+
get status(): ClientProviderStatus;
|
|
141
139
|
/**
|
|
142
140
|
* Initialize the provider.
|
|
143
141
|
* Validates the API key and starts SSE connection if real-time is enabled.
|
|
@@ -167,7 +165,7 @@ declare class FlipswitchProvider {
|
|
|
167
165
|
/**
|
|
168
166
|
* Register an event handler.
|
|
169
167
|
*/
|
|
170
|
-
onProviderEvent?(event:
|
|
168
|
+
onProviderEvent?(event: ClientProviderEvents, handler: EventHandler): void;
|
|
171
169
|
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext): ResolutionDetails<boolean>;
|
|
172
170
|
resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext): ResolutionDetails<string>;
|
|
173
171
|
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext): ResolutionDetails<number>;
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __export(index_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
|
|
29
29
|
// src/provider.ts
|
|
30
|
+
var import_core = require("@openfeature/core");
|
|
30
31
|
var import_ofrep_web_provider = require("@openfeature/ofrep-web-provider");
|
|
31
32
|
|
|
32
33
|
// src/sse-client.ts
|
|
@@ -204,7 +205,7 @@ var SseClient = class {
|
|
|
204
205
|
|
|
205
206
|
// src/provider.ts
|
|
206
207
|
var DEFAULT_BASE_URL = "https://api.flipswitch.io";
|
|
207
|
-
var SDK_VERSION = "0.1.
|
|
208
|
+
var SDK_VERSION = "0.1.1";
|
|
208
209
|
var FlipswitchProvider = class {
|
|
209
210
|
constructor(options, eventHandlers) {
|
|
210
211
|
this.metadata = {
|
|
@@ -212,7 +213,7 @@ var FlipswitchProvider = class {
|
|
|
212
213
|
};
|
|
213
214
|
this.rulesFromFlagValue = false;
|
|
214
215
|
this.sseClient = null;
|
|
215
|
-
this._status =
|
|
216
|
+
this._status = import_core.ClientProviderStatus.NOT_READY;
|
|
216
217
|
this.eventHandlers = /* @__PURE__ */ new Map();
|
|
217
218
|
this.userEventHandlers = {};
|
|
218
219
|
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
@@ -301,7 +302,7 @@ var FlipswitchProvider = class {
|
|
|
301
302
|
* Validates the API key and starts SSE connection if real-time is enabled.
|
|
302
303
|
*/
|
|
303
304
|
async initialize(context) {
|
|
304
|
-
this._status =
|
|
305
|
+
this._status = import_core.ClientProviderStatus.NOT_READY;
|
|
305
306
|
try {
|
|
306
307
|
await this.ofrepProvider.initialize(context);
|
|
307
308
|
} catch (error) {
|
|
@@ -318,23 +319,23 @@ var FlipswitchProvider = class {
|
|
|
318
319
|
})
|
|
319
320
|
});
|
|
320
321
|
if (response.status === 401 || response.status === 403) {
|
|
321
|
-
this._status =
|
|
322
|
+
this._status = import_core.ClientProviderStatus.ERROR;
|
|
322
323
|
throw new Error("Invalid API key");
|
|
323
324
|
}
|
|
324
325
|
if (!response.ok && response.status !== 404) {
|
|
325
|
-
this._status =
|
|
326
|
+
this._status = import_core.ClientProviderStatus.ERROR;
|
|
326
327
|
throw new Error(`Failed to connect to Flipswitch: ${response.status}`);
|
|
327
328
|
}
|
|
328
329
|
} catch (validationError) {
|
|
329
|
-
this._status =
|
|
330
|
+
this._status = import_core.ClientProviderStatus.ERROR;
|
|
330
331
|
throw validationError;
|
|
331
332
|
}
|
|
332
333
|
}
|
|
333
334
|
if (this.enableRealtime) {
|
|
334
335
|
this.startSseConnection();
|
|
335
336
|
}
|
|
336
|
-
this._status =
|
|
337
|
-
this.emit(
|
|
337
|
+
this._status = import_core.ClientProviderStatus.READY;
|
|
338
|
+
this.emit(import_core.ClientProviderEvents.Ready);
|
|
338
339
|
}
|
|
339
340
|
/**
|
|
340
341
|
* Called when the provider is shut down.
|
|
@@ -343,7 +344,7 @@ var FlipswitchProvider = class {
|
|
|
343
344
|
this.sseClient?.close();
|
|
344
345
|
this.sseClient = null;
|
|
345
346
|
await this.ofrepProvider.onClose?.();
|
|
346
|
-
this._status =
|
|
347
|
+
this._status = import_core.ClientProviderStatus.NOT_READY;
|
|
347
348
|
}
|
|
348
349
|
/**
|
|
349
350
|
* Start the SSE connection for real-time updates.
|
|
@@ -359,11 +360,11 @@ var FlipswitchProvider = class {
|
|
|
359
360
|
(status) => {
|
|
360
361
|
this.userEventHandlers.onConnectionStatusChange?.(status);
|
|
361
362
|
if (status === "error") {
|
|
362
|
-
this._status =
|
|
363
|
-
this.emit(
|
|
364
|
-
} else if (status === "connected" && this._status ===
|
|
365
|
-
this._status =
|
|
366
|
-
this.emit(
|
|
363
|
+
this._status = import_core.ClientProviderStatus.STALE;
|
|
364
|
+
this.emit(import_core.ClientProviderEvents.Stale);
|
|
365
|
+
} else if (status === "connected" && this._status === import_core.ClientProviderStatus.STALE) {
|
|
366
|
+
this._status = import_core.ClientProviderStatus.READY;
|
|
367
|
+
this.emit(import_core.ClientProviderEvents.Ready);
|
|
367
368
|
}
|
|
368
369
|
},
|
|
369
370
|
telemetryHeaders
|
|
@@ -390,7 +391,7 @@ var FlipswitchProvider = class {
|
|
|
390
391
|
*/
|
|
391
392
|
handleFlagChange(event) {
|
|
392
393
|
this.userEventHandlers.onFlagChange?.(event);
|
|
393
|
-
this.emit(
|
|
394
|
+
this.emit(import_core.ClientProviderEvents.ConfigurationChanged);
|
|
394
395
|
}
|
|
395
396
|
/**
|
|
396
397
|
* Emit an event to registered handlers.
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
// src/provider.ts
|
|
2
|
+
import {
|
|
3
|
+
ClientProviderStatus,
|
|
4
|
+
ClientProviderEvents
|
|
5
|
+
} from "@openfeature/core";
|
|
2
6
|
import { OFREPWebProvider } from "@openfeature/ofrep-web-provider";
|
|
3
7
|
|
|
4
8
|
// src/sse-client.ts
|
|
@@ -176,7 +180,7 @@ var SseClient = class {
|
|
|
176
180
|
|
|
177
181
|
// src/provider.ts
|
|
178
182
|
var DEFAULT_BASE_URL = "https://api.flipswitch.io";
|
|
179
|
-
var SDK_VERSION = "0.1.
|
|
183
|
+
var SDK_VERSION = "0.1.1";
|
|
180
184
|
var FlipswitchProvider = class {
|
|
181
185
|
constructor(options, eventHandlers) {
|
|
182
186
|
this.metadata = {
|
|
@@ -184,7 +188,7 @@ var FlipswitchProvider = class {
|
|
|
184
188
|
};
|
|
185
189
|
this.rulesFromFlagValue = false;
|
|
186
190
|
this.sseClient = null;
|
|
187
|
-
this._status =
|
|
191
|
+
this._status = ClientProviderStatus.NOT_READY;
|
|
188
192
|
this.eventHandlers = /* @__PURE__ */ new Map();
|
|
189
193
|
this.userEventHandlers = {};
|
|
190
194
|
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
@@ -273,7 +277,7 @@ var FlipswitchProvider = class {
|
|
|
273
277
|
* Validates the API key and starts SSE connection if real-time is enabled.
|
|
274
278
|
*/
|
|
275
279
|
async initialize(context) {
|
|
276
|
-
this._status =
|
|
280
|
+
this._status = ClientProviderStatus.NOT_READY;
|
|
277
281
|
try {
|
|
278
282
|
await this.ofrepProvider.initialize(context);
|
|
279
283
|
} catch (error) {
|
|
@@ -290,23 +294,23 @@ var FlipswitchProvider = class {
|
|
|
290
294
|
})
|
|
291
295
|
});
|
|
292
296
|
if (response.status === 401 || response.status === 403) {
|
|
293
|
-
this._status =
|
|
297
|
+
this._status = ClientProviderStatus.ERROR;
|
|
294
298
|
throw new Error("Invalid API key");
|
|
295
299
|
}
|
|
296
300
|
if (!response.ok && response.status !== 404) {
|
|
297
|
-
this._status =
|
|
301
|
+
this._status = ClientProviderStatus.ERROR;
|
|
298
302
|
throw new Error(`Failed to connect to Flipswitch: ${response.status}`);
|
|
299
303
|
}
|
|
300
304
|
} catch (validationError) {
|
|
301
|
-
this._status =
|
|
305
|
+
this._status = ClientProviderStatus.ERROR;
|
|
302
306
|
throw validationError;
|
|
303
307
|
}
|
|
304
308
|
}
|
|
305
309
|
if (this.enableRealtime) {
|
|
306
310
|
this.startSseConnection();
|
|
307
311
|
}
|
|
308
|
-
this._status =
|
|
309
|
-
this.emit(
|
|
312
|
+
this._status = ClientProviderStatus.READY;
|
|
313
|
+
this.emit(ClientProviderEvents.Ready);
|
|
310
314
|
}
|
|
311
315
|
/**
|
|
312
316
|
* Called when the provider is shut down.
|
|
@@ -315,7 +319,7 @@ var FlipswitchProvider = class {
|
|
|
315
319
|
this.sseClient?.close();
|
|
316
320
|
this.sseClient = null;
|
|
317
321
|
await this.ofrepProvider.onClose?.();
|
|
318
|
-
this._status =
|
|
322
|
+
this._status = ClientProviderStatus.NOT_READY;
|
|
319
323
|
}
|
|
320
324
|
/**
|
|
321
325
|
* Start the SSE connection for real-time updates.
|
|
@@ -331,11 +335,11 @@ var FlipswitchProvider = class {
|
|
|
331
335
|
(status) => {
|
|
332
336
|
this.userEventHandlers.onConnectionStatusChange?.(status);
|
|
333
337
|
if (status === "error") {
|
|
334
|
-
this._status =
|
|
335
|
-
this.emit(
|
|
336
|
-
} else if (status === "connected" && this._status ===
|
|
337
|
-
this._status =
|
|
338
|
-
this.emit(
|
|
338
|
+
this._status = ClientProviderStatus.STALE;
|
|
339
|
+
this.emit(ClientProviderEvents.Stale);
|
|
340
|
+
} else if (status === "connected" && this._status === ClientProviderStatus.STALE) {
|
|
341
|
+
this._status = ClientProviderStatus.READY;
|
|
342
|
+
this.emit(ClientProviderEvents.Ready);
|
|
339
343
|
}
|
|
340
344
|
},
|
|
341
345
|
telemetryHeaders
|
|
@@ -362,7 +366,7 @@ var FlipswitchProvider = class {
|
|
|
362
366
|
*/
|
|
363
367
|
handleFlagChange(event) {
|
|
364
368
|
this.userEventHandlers.onFlagChange?.(event);
|
|
365
|
-
this.emit(
|
|
369
|
+
this.emit(ClientProviderEvents.ConfigurationChanged);
|
|
366
370
|
}
|
|
367
371
|
/**
|
|
368
372
|
* Emit an event to registered handlers.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flipswitch-io/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Flipswitch SDK with real-time SSE support for OpenFeature",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"author": "",
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@openfeature/core": "^1.6.0",
|
|
39
38
|
"@openfeature/ofrep-core": "^2.0.0",
|
|
40
39
|
"@openfeature/ofrep-web-provider": "^0.3.5"
|
|
41
40
|
},
|
|
42
41
|
"peerDependencies": {
|
|
42
|
+
"@openfeature/core": "^1.6.0",
|
|
43
43
|
"@openfeature/server-sdk": "^1.0.0 || ^2.0.0",
|
|
44
44
|
"@openfeature/web-sdk": "^1.0.0 || ^2.0.0"
|
|
45
45
|
},
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
+
"@openfeature/core": "^1.6.0",
|
|
55
56
|
"@openfeature/ofrep-provider": "^0.2.2",
|
|
56
57
|
"@openfeature/server-sdk": "^1.17.0",
|
|
57
58
|
"@openfeature/web-sdk": "^1.7.2",
|