@flipt-io/flipt-client-js 0.5.1 → 0.6.0

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.
@@ -114,7 +114,7 @@ if (Symbol.dispose) Engine.prototype[Symbol.dispose] = Engine.prototype.free;
114
114
  function __wbg_get_imports() {
115
115
  const import0 = {
116
116
  __proto__: null,
117
- __wbg_Error_408e67f47ca7b58b: function(arg0, arg1) {
117
+ __wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
118
118
  const ret = Error(getStringFromWasm0(arg0, arg1));
119
119
  return ret;
120
120
  },
@@ -125,50 +125,50 @@ function __wbg_get_imports() {
125
125
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
126
126
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
127
127
  },
128
- __wbg___wbindgen_boolean_get_c9c83ebd41b34df3: function(arg0) {
128
+ __wbg___wbindgen_boolean_get_5b446f51afd21013: function(arg0) {
129
129
  const v = arg0;
130
130
  const ret = typeof(v) === 'boolean' ? v : undefined;
131
131
  return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
132
132
  },
133
- __wbg___wbindgen_debug_string_a57024b9c6e4a48b: function(arg0, arg1) {
133
+ __wbg___wbindgen_debug_string_4687d8d8c2017d52: function(arg0, arg1) {
134
134
  const ret = debugString(arg1);
135
135
  const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
136
136
  const len1 = WASM_VECTOR_LEN;
137
137
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
138
138
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
139
139
  },
140
- __wbg___wbindgen_in_ac983077f137f2e6: function(arg0, arg1) {
140
+ __wbg___wbindgen_in_92f62ee1427d9e49: function(arg0, arg1) {
141
141
  const ret = arg0 in arg1;
142
142
  return ret;
143
143
  },
144
- __wbg___wbindgen_is_function_5e4570eb24ffa122: function(arg0) {
144
+ __wbg___wbindgen_is_function_1f9d30630b8b1d3d: function(arg0) {
145
145
  const ret = typeof(arg0) === 'function';
146
146
  return ret;
147
147
  },
148
- __wbg___wbindgen_is_object_a2790eb24c211ea0: function(arg0) {
148
+ __wbg___wbindgen_is_object_3c45d4f2dde4e749: function(arg0) {
149
149
  const val = arg0;
150
150
  const ret = typeof(val) === 'object' && val !== null;
151
151
  return ret;
152
152
  },
153
- __wbg___wbindgen_is_string_e6f02f0ea5f20a32: function(arg0) {
153
+ __wbg___wbindgen_is_string_90b56bc79aad6f6c: function(arg0) {
154
154
  const ret = typeof(arg0) === 'string';
155
155
  return ret;
156
156
  },
157
- __wbg___wbindgen_is_undefined_6cff064c44e0d823: function(arg0) {
157
+ __wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
158
158
  const ret = arg0 === undefined;
159
159
  return ret;
160
160
  },
161
- __wbg___wbindgen_jsval_loose_eq_acf2776254a8d832: function(arg0, arg1) {
161
+ __wbg___wbindgen_jsval_loose_eq_677f21e468d6b461: function(arg0, arg1) {
162
162
  const ret = arg0 == arg1;
163
163
  return ret;
164
164
  },
165
- __wbg___wbindgen_number_get_136b9679cab35cfb: function(arg0, arg1) {
165
+ __wbg___wbindgen_number_get_2e0e7dee9f701a71: function(arg0, arg1) {
166
166
  const obj = arg1;
167
167
  const ret = typeof(obj) === 'number' ? obj : undefined;
168
168
  getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
169
169
  getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
170
170
  },
171
- __wbg___wbindgen_string_get_d154f1e671052120: function(arg0, arg1) {
171
+ __wbg___wbindgen_string_get_0380ccaa2f57f0d9: function(arg0, arg1) {
172
172
  const obj = arg1;
173
173
  const ret = typeof(obj) === 'string' ? obj : undefined;
174
174
  var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
@@ -176,18 +176,18 @@ function __wbg_get_imports() {
176
176
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
177
177
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
178
178
  },
179
- __wbg___wbindgen_throw_bb96b2010945f0bc: function(arg0, arg1) {
179
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
180
180
  throw new Error(getStringFromWasm0(arg0, arg1));
181
181
  },
182
- __wbg_call_1c5886ab9c57d1c7: function() { return handleError(function (arg0, arg1) {
182
+ __wbg_call_6137034ef55c9d0f: function() { return handleError(function (arg0, arg1) {
183
183
  const ret = arg0.call(arg1);
184
184
  return ret;
185
185
  }, arguments); },
186
- __wbg_done_669171204c3dcae2: function(arg0) {
186
+ __wbg_done_b41a1d26cdb37fb6: function(arg0) {
187
187
  const ret = arg0.done;
188
188
  return ret;
189
189
  },
190
- __wbg_entries_7774d489e1da5f4f: function(arg0) {
190
+ __wbg_entries_fb6397112b1de25f: function(arg0) {
191
191
  const ret = Object.entries(arg0);
192
192
  return ret;
193
193
  },
@@ -202,19 +202,19 @@ function __wbg_get_imports() {
202
202
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
203
203
  }
204
204
  },
205
- __wbg_getTime_63fb0332e6c4ec17: function(arg0) {
205
+ __wbg_getTime_f5a55efff2585d5d: function(arg0) {
206
206
  const ret = arg0.getTime();
207
207
  return ret;
208
208
  },
209
- __wbg_get_c0c8f8d7da0c03dd: function(arg0, arg1) {
210
- const ret = arg0[arg1 >>> 0];
211
- return ret;
212
- },
213
- __wbg_get_d173c0308df22d37: function() { return handleError(function (arg0, arg1) {
209
+ __wbg_get_658f6698067d9515: function() { return handleError(function (arg0, arg1) {
214
210
  const ret = Reflect.get(arg0, arg1);
215
211
  return ret;
216
212
  }, arguments); },
217
- __wbg_get_unchecked_e20b893aeafc3fca: function(arg0, arg1) {
213
+ __wbg_get_6c896e0571ddae51: function(arg0, arg1) {
214
+ const ret = arg0[arg1 >>> 0];
215
+ return ret;
216
+ },
217
+ __wbg_get_unchecked_288889d017702237: function(arg0, arg1) {
218
218
  const ret = arg0[arg1 >>> 0];
219
219
  return ret;
220
220
  },
@@ -222,7 +222,7 @@ function __wbg_get_imports() {
222
222
  const ret = arg0[arg1];
223
223
  return ret;
224
224
  },
225
- __wbg_instanceof_ArrayBuffer_993d02d2d254cad1: function(arg0) {
225
+ __wbg_instanceof_ArrayBuffer_a99f175873e5d9b8: function(arg0) {
226
226
  let result;
227
227
  try {
228
228
  result = arg0 instanceof ArrayBuffer;
@@ -232,7 +232,7 @@ function __wbg_get_imports() {
232
232
  const ret = result;
233
233
  return ret;
234
234
  },
235
- __wbg_instanceof_Uint8Array_f935dbb0aa7cdeed: function(arg0) {
235
+ __wbg_instanceof_Uint8Array_828cef2aaacafc31: function(arg0) {
236
236
  let result;
237
237
  try {
238
238
  result = arg0 instanceof Uint8Array;
@@ -242,50 +242,50 @@ function __wbg_get_imports() {
242
242
  const ret = result;
243
243
  return ret;
244
244
  },
245
- __wbg_isArray_6339f732981044bf: function(arg0) {
245
+ __wbg_isArray_e15a2ff68ffdbef2: function(arg0) {
246
246
  const ret = Array.isArray(arg0);
247
247
  return ret;
248
248
  },
249
- __wbg_iterator_5cebbb86e33c6dd6: function() {
249
+ __wbg_iterator_e3c31c892080e444: function() {
250
250
  const ret = Symbol.iterator;
251
251
  return ret;
252
252
  },
253
- __wbg_length_36bd29c6848c2144: function(arg0) {
253
+ __wbg_length_7f3c00c40364105e: function(arg0) {
254
254
  const ret = arg0.length;
255
255
  return ret;
256
256
  },
257
- __wbg_length_ecfa2c63d3d0d82c: function(arg0) {
257
+ __wbg_length_d4bdea10311bd9cf: function(arg0) {
258
258
  const ret = arg0.length;
259
259
  return ret;
260
260
  },
261
- __wbg_new_0_f117d868b403dc07: function() {
261
+ __wbg_new_0_72d020f0c63443d4: function() {
262
262
  const ret = new Date();
263
263
  return ret;
264
264
  },
265
- __wbg_new_116be93542d39019: function() {
266
- const ret = new Array();
265
+ __wbg_new_1dbf7428bba60a42: function(arg0) {
266
+ const ret = new Uint8Array(arg0);
267
267
  return ret;
268
268
  },
269
269
  __wbg_new_227d7c05414eb861: function() {
270
270
  const ret = new Error();
271
271
  return ret;
272
272
  },
273
- __wbg_new_77cc4f4f472aeb81: function(arg0) {
274
- const ret = new Uint8Array(arg0);
275
- return ret;
276
- },
277
- __wbg_new_ebe3e0f6837f0879: function() {
273
+ __wbg_new_617a8cdb8bb1130e: function() {
278
274
  const ret = new Object();
279
275
  return ret;
280
276
  },
281
- __wbg_next_42cf16ee0dafc9e2: function() { return handleError(function (arg0) {
282
- const ret = arg0.next();
277
+ __wbg_new_ee2291f50781bf1d: function() {
278
+ const ret = new Array();
283
279
  return ret;
284
- }, arguments); },
285
- __wbg_next_8f26b64fa5e9f64b: function(arg0) {
280
+ },
281
+ __wbg_next_33784799010f1bbe: function(arg0) {
286
282
  const ret = arg0.next;
287
283
  return ret;
288
284
  },
285
+ __wbg_next_f4aac29c42af995c: function() { return handleError(function (arg0) {
286
+ const ret = arg0.next();
287
+ return ret;
288
+ }, arguments); },
289
289
  __wbg_now_e7c6795a7f81e10f: function(arg0) {
290
290
  const ret = arg0.now();
291
291
  return ret;
@@ -294,13 +294,13 @@ function __wbg_get_imports() {
294
294
  const ret = arg0.performance;
295
295
  return ret;
296
296
  },
297
- __wbg_prototypesetcall_de8e0d9553586985: function(arg0, arg1, arg2) {
297
+ __wbg_prototypesetcall_bc27214492979395: function(arg0, arg1, arg2) {
298
298
  Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
299
299
  },
300
300
  __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
301
301
  arg0[arg1] = arg2;
302
302
  },
303
- __wbg_set_a80955eb93b145c6: function(arg0, arg1, arg2) {
303
+ __wbg_set_bea140a88be9b277: function(arg0, arg1, arg2) {
304
304
  arg0[arg1 >>> 0] = arg2;
305
305
  },
306
306
  __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
@@ -310,32 +310,32 @@ function __wbg_get_imports() {
310
310
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
311
311
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
312
312
  },
313
- __wbg_static_accessor_GLOBAL_THIS_466428f93b4eaa76: function() {
314
- const ret = typeof globalThis === 'undefined' ? null : globalThis;
313
+ __wbg_static_accessor_GLOBAL_266715b9d96ba635: function() {
314
+ const ret = typeof global === 'undefined' ? null : global;
315
315
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
316
316
  },
317
- __wbg_static_accessor_GLOBAL_c7aea38d4de089bc: function() {
318
- const ret = typeof global === 'undefined' ? null : global;
317
+ __wbg_static_accessor_GLOBAL_THIS_10fb7dc1ae063179: function() {
318
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
319
319
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
320
320
  },
321
- __wbg_static_accessor_SELF_42d4fae05e59267a: function() {
321
+ __wbg_static_accessor_SELF_0b583911f537483a: function() {
322
322
  const ret = typeof self === 'undefined' ? null : self;
323
323
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
324
324
  },
325
- __wbg_static_accessor_WINDOW_e0db14a0eba6a812: function() {
325
+ __wbg_static_accessor_WINDOW_d7f903d1508cbdc4: function() {
326
326
  const ret = typeof window === 'undefined' ? null : window;
327
327
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
328
328
  },
329
- __wbg_value_1e2369fab29b420e: function(arg0) {
329
+ __wbg_value_f3c585ee8f5ba40c: function(arg0) {
330
330
  const ret = arg0.value;
331
331
  return ret;
332
332
  },
333
- __wbindgen_cast_0000000000000001: function(arg0) {
333
+ __wbindgen_generic_0000000000000001: function(arg0) {
334
334
  // Cast intrinsic for `F64 -> Externref`.
335
335
  const ret = arg0;
336
336
  return ret;
337
337
  },
338
- __wbindgen_cast_0000000000000002: function(arg0, arg1) {
338
+ __wbindgen_generic_0000000000000002: function(arg0, arg1) {
339
339
  // Cast intrinsic for `Ref(String) -> Externref`.
340
340
  const ret = getStringFromWasm0(arg0, arg1);
341
341
  return ret;
@@ -615,6 +615,16 @@ async function __wbg_init(module_or_path) {
615
615
  return __wbg_finalize_init(instance);
616
616
  }
617
617
 
618
+ /**
619
+ * Defines how the client fetches flag state updates from the Flipt server.
620
+ */
621
+ exports.FetchMode = void 0;
622
+ (function (FetchMode) {
623
+ /** Periodically poll the server for new flag state at the configured updateInterval. */
624
+ FetchMode["Polling"] = "polling";
625
+ /** Use Server-Sent Events to receive real-time flag state updates. */
626
+ FetchMode["Streaming"] = "streaming";
627
+ })(exports.FetchMode || (exports.FetchMode = {}));
618
628
  /**
619
629
  * Defines the strategy to handle errors during the flags snapshot update calls.
620
630
  */
@@ -640,7 +650,8 @@ class ClientOptionsFactory {
640
650
  url: 'http://localhost:8080',
641
651
  reference: '',
642
652
  updateInterval: 120,
643
- errorStrategy: exports.ErrorStrategy.Fail
653
+ errorStrategy: exports.ErrorStrategy.Fail,
654
+ fetchMode: exports.FetchMode.Polling
644
655
  };
645
656
  }
646
657
  }
@@ -672,11 +683,67 @@ function serialize(data) {
672
683
  return result;
673
684
  }
674
685
 
686
+ const noopLogger = {
687
+ debug: () => { },
688
+ info: () => { },
689
+ warn: () => { },
690
+ error: () => { }
691
+ };
675
692
  class BaseFliptClient {
676
693
  constructor(engine, fetcher) {
694
+ this.logger = noopLogger;
677
695
  this.engine = engine;
678
696
  this.fetcher = fetcher;
679
697
  }
698
+ /**
699
+ * Close the client and clean up resources.
700
+ */
701
+ close() {
702
+ this.closeEventSource();
703
+ }
704
+ /**
705
+ * Wire up SSE handlers shared by the browser and Node clients.
706
+ * EventSource reconnects on its own after transient errors; on every
707
+ * (re)open we refresh so updates missed while disconnected are picked up.
708
+ */
709
+ attachStream(eventSource) {
710
+ eventSource.onopen = () => {
711
+ this.logger.debug('sse connected');
712
+ this.refreshFromStream();
713
+ };
714
+ eventSource.onmessage = (event) => {
715
+ try {
716
+ const data = JSON.parse(event.data);
717
+ this.logger.debug('sse message:', data);
718
+ if (data.type === 'refetchEvaluation') {
719
+ this.refreshFromStream();
720
+ }
721
+ }
722
+ catch {
723
+ this.logger.warn('sse parse error:', event.data);
724
+ }
725
+ };
726
+ eventSource.onerror = (err) => {
727
+ if (eventSource.readyState === 2 /* CLOSED */) {
728
+ this.logger.error('sse connection closed, no further updates:', err);
729
+ }
730
+ else {
731
+ this.logger.warn('sse error, reconnecting:', err);
732
+ }
733
+ };
734
+ this.eventSource = eventSource;
735
+ }
736
+ refreshFromStream() {
737
+ this.refresh().catch((err) => {
738
+ this.logger.warn('sse refresh failed:', err);
739
+ });
740
+ }
741
+ closeEventSource() {
742
+ if (this.eventSource) {
743
+ this.eventSource.close();
744
+ this.eventSource = undefined;
745
+ }
746
+ }
680
747
  /**
681
748
  * Store etag from response for next requests
682
749
  */