@flipswitch-io/sdk 0.1.4 → 0.1.5

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
@@ -21,13 +21,6 @@ interface FlipswitchOptions {
21
21
  * @default true
22
22
  */
23
23
  enableRealtime?: boolean;
24
- /**
25
- * Enable telemetry collection.
26
- * When enabled, the SDK sends usage statistics (SDK version, runtime version,
27
- * OS, architecture) to help improve the service. No personal data is collected.
28
- * @default true
29
- */
30
- enableTelemetry?: boolean;
31
24
  /**
32
25
  * Custom fetch function for making HTTP requests.
33
26
  * Useful for testing or custom networking needs.
@@ -35,13 +28,48 @@ interface FlipswitchOptions {
35
28
  fetchImplementation?: typeof fetch;
36
29
  }
37
30
  /**
38
- * Event emitted when a flag changes.
31
+ * Event emitted when a single flag is updated.
39
32
  */
40
- interface FlagChangeEvent {
33
+ interface FlagUpdatedEvent {
34
+ /**
35
+ * The key of the flag that changed.
36
+ */
37
+ flagKey: string;
41
38
  /**
42
- * The ID of the environment where the change occurred.
39
+ * ISO timestamp of when the change occurred.
43
40
  */
44
- environmentId: number;
41
+ timestamp: string;
42
+ }
43
+ /**
44
+ * Event emitted when configuration changes that may affect multiple flags.
45
+ */
46
+ interface ConfigUpdatedEvent {
47
+ /**
48
+ * The reason for the configuration update.
49
+ * Possible values: 'segment-modified', 'api-key-rotated'
50
+ */
51
+ reason: string;
52
+ /**
53
+ * ISO timestamp of when the change occurred.
54
+ */
55
+ timestamp: string;
56
+ }
57
+ /**
58
+ * Union type for all flag events.
59
+ * Used internally to handle both event types.
60
+ */
61
+ type FlagEvent = {
62
+ type: 'flag-updated';
63
+ data: FlagUpdatedEvent;
64
+ } | {
65
+ type: 'config-updated';
66
+ data: ConfigUpdatedEvent;
67
+ };
68
+ /**
69
+ * @deprecated Use FlagUpdatedEvent or ConfigUpdatedEvent instead.
70
+ * Event emitted when a flag changes (legacy format).
71
+ */
72
+ interface FlagChangeEvent {
45
73
  /**
46
74
  * The key of the flag that changed, or null for bulk invalidation.
47
75
  */
@@ -122,7 +150,6 @@ declare class FlipswitchProvider {
122
150
  private readonly baseUrl;
123
151
  private readonly apiKey;
124
152
  private readonly enableRealtime;
125
- private readonly enableTelemetry;
126
153
  private readonly fetchImpl;
127
154
  private readonly ofrepProvider;
128
155
  private sseClient;
@@ -300,4 +327,4 @@ declare class FlagCache {
300
327
  handleFlagChange(event: FlagChangeEvent): void;
301
328
  }
302
329
 
303
- export { FlagCache, type FlagChangeEvent, type FlagEvaluation, type FlipswitchEventHandlers, type FlipswitchOptions, FlipswitchProvider, SseClient, type SseConnectionStatus };
330
+ export { type ConfigUpdatedEvent, FlagCache, type FlagChangeEvent, type FlagEvaluation, type FlagEvent, type FlagUpdatedEvent, type FlipswitchEventHandlers, type FlipswitchOptions, FlipswitchProvider, SseClient, type SseConnectionStatus };
package/dist/index.d.ts CHANGED
@@ -21,13 +21,6 @@ interface FlipswitchOptions {
21
21
  * @default true
22
22
  */
23
23
  enableRealtime?: boolean;
24
- /**
25
- * Enable telemetry collection.
26
- * When enabled, the SDK sends usage statistics (SDK version, runtime version,
27
- * OS, architecture) to help improve the service. No personal data is collected.
28
- * @default true
29
- */
30
- enableTelemetry?: boolean;
31
24
  /**
32
25
  * Custom fetch function for making HTTP requests.
33
26
  * Useful for testing or custom networking needs.
@@ -35,13 +28,48 @@ interface FlipswitchOptions {
35
28
  fetchImplementation?: typeof fetch;
36
29
  }
37
30
  /**
38
- * Event emitted when a flag changes.
31
+ * Event emitted when a single flag is updated.
39
32
  */
40
- interface FlagChangeEvent {
33
+ interface FlagUpdatedEvent {
34
+ /**
35
+ * The key of the flag that changed.
36
+ */
37
+ flagKey: string;
41
38
  /**
42
- * The ID of the environment where the change occurred.
39
+ * ISO timestamp of when the change occurred.
43
40
  */
44
- environmentId: number;
41
+ timestamp: string;
42
+ }
43
+ /**
44
+ * Event emitted when configuration changes that may affect multiple flags.
45
+ */
46
+ interface ConfigUpdatedEvent {
47
+ /**
48
+ * The reason for the configuration update.
49
+ * Possible values: 'segment-modified', 'api-key-rotated'
50
+ */
51
+ reason: string;
52
+ /**
53
+ * ISO timestamp of when the change occurred.
54
+ */
55
+ timestamp: string;
56
+ }
57
+ /**
58
+ * Union type for all flag events.
59
+ * Used internally to handle both event types.
60
+ */
61
+ type FlagEvent = {
62
+ type: 'flag-updated';
63
+ data: FlagUpdatedEvent;
64
+ } | {
65
+ type: 'config-updated';
66
+ data: ConfigUpdatedEvent;
67
+ };
68
+ /**
69
+ * @deprecated Use FlagUpdatedEvent or ConfigUpdatedEvent instead.
70
+ * Event emitted when a flag changes (legacy format).
71
+ */
72
+ interface FlagChangeEvent {
45
73
  /**
46
74
  * The key of the flag that changed, or null for bulk invalidation.
47
75
  */
@@ -122,7 +150,6 @@ declare class FlipswitchProvider {
122
150
  private readonly baseUrl;
123
151
  private readonly apiKey;
124
152
  private readonly enableRealtime;
125
- private readonly enableTelemetry;
126
153
  private readonly fetchImpl;
127
154
  private readonly ofrepProvider;
128
155
  private sseClient;
@@ -300,4 +327,4 @@ declare class FlagCache {
300
327
  handleFlagChange(event: FlagChangeEvent): void;
301
328
  }
302
329
 
303
- export { FlagCache, type FlagChangeEvent, type FlagEvaluation, type FlipswitchEventHandlers, type FlipswitchOptions, FlipswitchProvider, SseClient, type SseConnectionStatus };
330
+ export { type ConfigUpdatedEvent, FlagCache, type FlagChangeEvent, type FlagEvaluation, type FlagEvent, type FlagUpdatedEvent, type FlipswitchEventHandlers, type FlipswitchOptions, FlipswitchProvider, SseClient, type SseConnectionStatus };
package/dist/index.js CHANGED
@@ -149,13 +149,33 @@ var SseClient = class {
149
149
  if (eventType === "heartbeat") {
150
150
  return;
151
151
  }
152
- if (eventType === "flag-change") {
153
- try {
152
+ try {
153
+ if (eventType === "flag-updated") {
154
+ const parsed = JSON.parse(data);
155
+ const event = {
156
+ flagKey: parsed.flagKey,
157
+ timestamp: parsed.timestamp
158
+ };
159
+ this.onFlagChange(event);
160
+ } else if (eventType === "config-updated") {
161
+ const parsed = JSON.parse(data);
162
+ if (parsed.reason === "api-key-rotated") {
163
+ console.warn(
164
+ "[Flipswitch] API key has been rotated. You may need to update your API key configuration."
165
+ );
166
+ }
167
+ const event = {
168
+ flagKey: null,
169
+ // null indicates all flags should be refreshed
170
+ timestamp: parsed.timestamp
171
+ };
172
+ this.onFlagChange(event);
173
+ } else if (eventType === "flag-change") {
154
174
  const event = JSON.parse(data);
155
175
  this.onFlagChange(event);
156
- } catch (error) {
157
- console.error("[Flipswitch] Failed to parse flag-change event:", error);
158
176
  }
177
+ } catch (error) {
178
+ console.error(`[Flipswitch] Failed to parse ${eventType} event:`, error);
159
179
  }
160
180
  }
161
181
  /**
@@ -219,16 +239,15 @@ var FlipswitchProvider = class {
219
239
  this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
220
240
  this.apiKey = options.apiKey;
221
241
  this.enableRealtime = options.enableRealtime ?? true;
222
- this.enableTelemetry = options.enableTelemetry ?? true;
223
242
  this.fetchImpl = options.fetchImplementation ?? (typeof window !== "undefined" ? fetch.bind(window) : fetch);
224
243
  this.userEventHandlers = eventHandlers ?? {};
225
- const headers = [["X-API-Key", this.apiKey]];
226
- if (this.enableTelemetry) {
227
- headers.push(["X-Flipswitch-SDK", this.getTelemetrySdkHeader()]);
228
- headers.push(["X-Flipswitch-Runtime", this.getTelemetryRuntimeHeader()]);
229
- headers.push(["X-Flipswitch-OS", this.getTelemetryOsHeader()]);
230
- headers.push(["X-Flipswitch-Features", this.getTelemetryFeaturesHeader()]);
231
- }
244
+ const headers = [
245
+ ["X-API-Key", this.apiKey],
246
+ ["X-Flipswitch-SDK", this.getTelemetrySdkHeader()],
247
+ ["X-Flipswitch-Runtime", this.getTelemetryRuntimeHeader()],
248
+ ["X-Flipswitch-OS", this.getTelemetryOsHeader()],
249
+ ["X-Flipswitch-Features", this.getTelemetryFeaturesHeader()]
250
+ ];
232
251
  this.ofrepProvider = new import_ofrep_web_provider.OFREPWebProvider({
233
252
  baseUrl: this.baseUrl,
234
253
  fetchImplementation: this.fetchImpl,
@@ -286,7 +305,6 @@ var FlipswitchProvider = class {
286
305
  return `sse=${this.enableRealtime}`;
287
306
  }
288
307
  getTelemetryHeaders() {
289
- if (!this.enableTelemetry) return {};
290
308
  return {
291
309
  "X-Flipswitch-SDK": this.getTelemetrySdkHeader(),
292
310
  "X-Flipswitch-Runtime": this.getTelemetryRuntimeHeader(),
@@ -375,9 +393,6 @@ var FlipswitchProvider = class {
375
393
  * Get telemetry headers as a map.
376
394
  */
377
395
  getTelemetryHeadersMap() {
378
- if (!this.enableTelemetry) {
379
- return void 0;
380
- }
381
396
  return {
382
397
  "X-Flipswitch-SDK": this.getTelemetrySdkHeader(),
383
398
  "X-Flipswitch-Runtime": this.getTelemetryRuntimeHeader(),
package/dist/index.mjs CHANGED
@@ -124,13 +124,33 @@ var SseClient = class {
124
124
  if (eventType === "heartbeat") {
125
125
  return;
126
126
  }
127
- if (eventType === "flag-change") {
128
- try {
127
+ try {
128
+ if (eventType === "flag-updated") {
129
+ const parsed = JSON.parse(data);
130
+ const event = {
131
+ flagKey: parsed.flagKey,
132
+ timestamp: parsed.timestamp
133
+ };
134
+ this.onFlagChange(event);
135
+ } else if (eventType === "config-updated") {
136
+ const parsed = JSON.parse(data);
137
+ if (parsed.reason === "api-key-rotated") {
138
+ console.warn(
139
+ "[Flipswitch] API key has been rotated. You may need to update your API key configuration."
140
+ );
141
+ }
142
+ const event = {
143
+ flagKey: null,
144
+ // null indicates all flags should be refreshed
145
+ timestamp: parsed.timestamp
146
+ };
147
+ this.onFlagChange(event);
148
+ } else if (eventType === "flag-change") {
129
149
  const event = JSON.parse(data);
130
150
  this.onFlagChange(event);
131
- } catch (error) {
132
- console.error("[Flipswitch] Failed to parse flag-change event:", error);
133
151
  }
152
+ } catch (error) {
153
+ console.error(`[Flipswitch] Failed to parse ${eventType} event:`, error);
134
154
  }
135
155
  }
136
156
  /**
@@ -194,16 +214,15 @@ var FlipswitchProvider = class {
194
214
  this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
195
215
  this.apiKey = options.apiKey;
196
216
  this.enableRealtime = options.enableRealtime ?? true;
197
- this.enableTelemetry = options.enableTelemetry ?? true;
198
217
  this.fetchImpl = options.fetchImplementation ?? (typeof window !== "undefined" ? fetch.bind(window) : fetch);
199
218
  this.userEventHandlers = eventHandlers ?? {};
200
- const headers = [["X-API-Key", this.apiKey]];
201
- if (this.enableTelemetry) {
202
- headers.push(["X-Flipswitch-SDK", this.getTelemetrySdkHeader()]);
203
- headers.push(["X-Flipswitch-Runtime", this.getTelemetryRuntimeHeader()]);
204
- headers.push(["X-Flipswitch-OS", this.getTelemetryOsHeader()]);
205
- headers.push(["X-Flipswitch-Features", this.getTelemetryFeaturesHeader()]);
206
- }
219
+ const headers = [
220
+ ["X-API-Key", this.apiKey],
221
+ ["X-Flipswitch-SDK", this.getTelemetrySdkHeader()],
222
+ ["X-Flipswitch-Runtime", this.getTelemetryRuntimeHeader()],
223
+ ["X-Flipswitch-OS", this.getTelemetryOsHeader()],
224
+ ["X-Flipswitch-Features", this.getTelemetryFeaturesHeader()]
225
+ ];
207
226
  this.ofrepProvider = new OFREPWebProvider({
208
227
  baseUrl: this.baseUrl,
209
228
  fetchImplementation: this.fetchImpl,
@@ -261,7 +280,6 @@ var FlipswitchProvider = class {
261
280
  return `sse=${this.enableRealtime}`;
262
281
  }
263
282
  getTelemetryHeaders() {
264
- if (!this.enableTelemetry) return {};
265
283
  return {
266
284
  "X-Flipswitch-SDK": this.getTelemetrySdkHeader(),
267
285
  "X-Flipswitch-Runtime": this.getTelemetryRuntimeHeader(),
@@ -350,9 +368,6 @@ var FlipswitchProvider = class {
350
368
  * Get telemetry headers as a map.
351
369
  */
352
370
  getTelemetryHeadersMap() {
353
- if (!this.enableTelemetry) {
354
- return void 0;
355
- }
356
371
  return {
357
372
  "X-Flipswitch-SDK": this.getTelemetrySdkHeader(),
358
373
  "X-Flipswitch-Runtime": this.getTelemetryRuntimeHeader(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flipswitch-io/sdk",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Flipswitch SDK with real-time SSE support for OpenFeature",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -56,7 +56,7 @@
56
56
  "@openfeature/ofrep-provider": "^0.2.2",
57
57
  "@openfeature/server-sdk": "^1.17.0",
58
58
  "@openfeature/web-sdk": "^1.7.2",
59
- "@types/node": "^20.11.0",
59
+ "@types/node": "^24.0.0",
60
60
  "eslint": "^9.0.0",
61
61
  "tsup": "^8.0.1",
62
62
  "tsx": "^4.7.0",