@flipt-io/flipt-client-js 0.5.0 → 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.
- package/README.md +29 -1
- package/dist/browser/index.cjs +143 -56
- package/dist/browser/index.mjs +144 -57
- package/dist/flipt_engine_wasm_js_bg.wasm +0 -0
- package/dist/node/index.cjs +157 -60
- package/dist/node/index.mjs +158 -61
- package/dist/slim/index.cjs +123 -52
- package/dist/slim/index.mjs +124 -53
- package/dist/types/browser/index.d.ts +1 -0
- package/dist/types/core/base.d.ts +23 -1
- package/dist/types/core/types.d.ts +28 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/node/index.d.ts +1 -0
- package/package.json +4 -3
package/dist/slim/index.mjs
CHANGED
|
@@ -111,7 +111,7 @@ if (Symbol.dispose) Engine.prototype[Symbol.dispose] = Engine.prototype.free;
|
|
|
111
111
|
function __wbg_get_imports() {
|
|
112
112
|
const import0 = {
|
|
113
113
|
__proto__: null,
|
|
114
|
-
|
|
114
|
+
__wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
|
|
115
115
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
116
116
|
return ret;
|
|
117
117
|
},
|
|
@@ -122,50 +122,50 @@ function __wbg_get_imports() {
|
|
|
122
122
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
123
123
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
124
124
|
},
|
|
125
|
-
|
|
125
|
+
__wbg___wbindgen_boolean_get_5b446f51afd21013: function(arg0) {
|
|
126
126
|
const v = arg0;
|
|
127
127
|
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
128
128
|
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
129
129
|
},
|
|
130
|
-
|
|
130
|
+
__wbg___wbindgen_debug_string_4687d8d8c2017d52: function(arg0, arg1) {
|
|
131
131
|
const ret = debugString(arg1);
|
|
132
132
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
133
133
|
const len1 = WASM_VECTOR_LEN;
|
|
134
134
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
135
135
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
136
136
|
},
|
|
137
|
-
|
|
137
|
+
__wbg___wbindgen_in_92f62ee1427d9e49: function(arg0, arg1) {
|
|
138
138
|
const ret = arg0 in arg1;
|
|
139
139
|
return ret;
|
|
140
140
|
},
|
|
141
|
-
|
|
141
|
+
__wbg___wbindgen_is_function_1f9d30630b8b1d3d: function(arg0) {
|
|
142
142
|
const ret = typeof(arg0) === 'function';
|
|
143
143
|
return ret;
|
|
144
144
|
},
|
|
145
|
-
|
|
145
|
+
__wbg___wbindgen_is_object_3c45d4f2dde4e749: function(arg0) {
|
|
146
146
|
const val = arg0;
|
|
147
147
|
const ret = typeof(val) === 'object' && val !== null;
|
|
148
148
|
return ret;
|
|
149
149
|
},
|
|
150
|
-
|
|
150
|
+
__wbg___wbindgen_is_string_90b56bc79aad6f6c: function(arg0) {
|
|
151
151
|
const ret = typeof(arg0) === 'string';
|
|
152
152
|
return ret;
|
|
153
153
|
},
|
|
154
|
-
|
|
154
|
+
__wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
|
|
155
155
|
const ret = arg0 === undefined;
|
|
156
156
|
return ret;
|
|
157
157
|
},
|
|
158
|
-
|
|
158
|
+
__wbg___wbindgen_jsval_loose_eq_677f21e468d6b461: function(arg0, arg1) {
|
|
159
159
|
const ret = arg0 == arg1;
|
|
160
160
|
return ret;
|
|
161
161
|
},
|
|
162
|
-
|
|
162
|
+
__wbg___wbindgen_number_get_2e0e7dee9f701a71: function(arg0, arg1) {
|
|
163
163
|
const obj = arg1;
|
|
164
164
|
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
165
165
|
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
166
166
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
167
167
|
},
|
|
168
|
-
|
|
168
|
+
__wbg___wbindgen_string_get_0380ccaa2f57f0d9: function(arg0, arg1) {
|
|
169
169
|
const obj = arg1;
|
|
170
170
|
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
171
171
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -173,22 +173,22 @@ function __wbg_get_imports() {
|
|
|
173
173
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
174
174
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
175
175
|
},
|
|
176
|
-
|
|
176
|
+
__wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
|
|
177
177
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
178
178
|
},
|
|
179
|
-
|
|
179
|
+
__wbg_call_6137034ef55c9d0f: function() { return handleError(function (arg0, arg1) {
|
|
180
180
|
const ret = arg0.call(arg1);
|
|
181
181
|
return ret;
|
|
182
182
|
}, arguments); },
|
|
183
|
-
|
|
183
|
+
__wbg_done_b41a1d26cdb37fb6: function(arg0) {
|
|
184
184
|
const ret = arg0.done;
|
|
185
185
|
return ret;
|
|
186
186
|
},
|
|
187
|
-
|
|
187
|
+
__wbg_entries_fb6397112b1de25f: function(arg0) {
|
|
188
188
|
const ret = Object.entries(arg0);
|
|
189
189
|
return ret;
|
|
190
190
|
},
|
|
191
|
-
|
|
191
|
+
__wbg_error_757e9472f8410341: function(arg0, arg1) {
|
|
192
192
|
let deferred0_0;
|
|
193
193
|
let deferred0_1;
|
|
194
194
|
try {
|
|
@@ -199,19 +199,19 @@ function __wbg_get_imports() {
|
|
|
199
199
|
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
200
200
|
}
|
|
201
201
|
},
|
|
202
|
-
|
|
202
|
+
__wbg_getTime_f5a55efff2585d5d: function(arg0) {
|
|
203
203
|
const ret = arg0.getTime();
|
|
204
204
|
return ret;
|
|
205
205
|
},
|
|
206
|
-
|
|
207
|
-
const ret = arg0[arg1 >>> 0];
|
|
208
|
-
return ret;
|
|
209
|
-
},
|
|
210
|
-
__wbg_get_9a29be2cb383ed9a: function() { return handleError(function (arg0, arg1) {
|
|
206
|
+
__wbg_get_658f6698067d9515: function() { return handleError(function (arg0, arg1) {
|
|
211
207
|
const ret = Reflect.get(arg0, arg1);
|
|
212
208
|
return ret;
|
|
213
209
|
}, arguments); },
|
|
214
|
-
|
|
210
|
+
__wbg_get_6c896e0571ddae51: function(arg0, arg1) {
|
|
211
|
+
const ret = arg0[arg1 >>> 0];
|
|
212
|
+
return ret;
|
|
213
|
+
},
|
|
214
|
+
__wbg_get_unchecked_288889d017702237: function(arg0, arg1) {
|
|
215
215
|
const ret = arg0[arg1 >>> 0];
|
|
216
216
|
return ret;
|
|
217
217
|
},
|
|
@@ -219,7 +219,7 @@ function __wbg_get_imports() {
|
|
|
219
219
|
const ret = arg0[arg1];
|
|
220
220
|
return ret;
|
|
221
221
|
},
|
|
222
|
-
|
|
222
|
+
__wbg_instanceof_ArrayBuffer_a99f175873e5d9b8: function(arg0) {
|
|
223
223
|
let result;
|
|
224
224
|
try {
|
|
225
225
|
result = arg0 instanceof ArrayBuffer;
|
|
@@ -229,7 +229,7 @@ function __wbg_get_imports() {
|
|
|
229
229
|
const ret = result;
|
|
230
230
|
return ret;
|
|
231
231
|
},
|
|
232
|
-
|
|
232
|
+
__wbg_instanceof_Uint8Array_828cef2aaacafc31: function(arg0) {
|
|
233
233
|
let result;
|
|
234
234
|
try {
|
|
235
235
|
result = arg0 instanceof Uint8Array;
|
|
@@ -239,50 +239,50 @@ function __wbg_get_imports() {
|
|
|
239
239
|
const ret = result;
|
|
240
240
|
return ret;
|
|
241
241
|
},
|
|
242
|
-
|
|
242
|
+
__wbg_isArray_e15a2ff68ffdbef2: function(arg0) {
|
|
243
243
|
const ret = Array.isArray(arg0);
|
|
244
244
|
return ret;
|
|
245
245
|
},
|
|
246
|
-
|
|
246
|
+
__wbg_iterator_e3c31c892080e444: function() {
|
|
247
247
|
const ret = Symbol.iterator;
|
|
248
248
|
return ret;
|
|
249
249
|
},
|
|
250
|
-
|
|
250
|
+
__wbg_length_7f3c00c40364105e: function(arg0) {
|
|
251
251
|
const ret = arg0.length;
|
|
252
252
|
return ret;
|
|
253
253
|
},
|
|
254
|
-
|
|
254
|
+
__wbg_length_d4bdea10311bd9cf: function(arg0) {
|
|
255
255
|
const ret = arg0.length;
|
|
256
256
|
return ret;
|
|
257
257
|
},
|
|
258
|
-
|
|
258
|
+
__wbg_new_0_72d020f0c63443d4: function() {
|
|
259
259
|
const ret = new Date();
|
|
260
260
|
return ret;
|
|
261
261
|
},
|
|
262
|
+
__wbg_new_1dbf7428bba60a42: function(arg0) {
|
|
263
|
+
const ret = new Uint8Array(arg0);
|
|
264
|
+
return ret;
|
|
265
|
+
},
|
|
262
266
|
__wbg_new_227d7c05414eb861: function() {
|
|
263
267
|
const ret = new Error();
|
|
264
268
|
return ret;
|
|
265
269
|
},
|
|
266
|
-
|
|
270
|
+
__wbg_new_617a8cdb8bb1130e: function() {
|
|
267
271
|
const ret = new Object();
|
|
268
272
|
return ret;
|
|
269
273
|
},
|
|
270
|
-
|
|
274
|
+
__wbg_new_ee2291f50781bf1d: function() {
|
|
271
275
|
const ret = new Array();
|
|
272
276
|
return ret;
|
|
273
277
|
},
|
|
274
|
-
|
|
275
|
-
const ret =
|
|
278
|
+
__wbg_next_33784799010f1bbe: function(arg0) {
|
|
279
|
+
const ret = arg0.next;
|
|
276
280
|
return ret;
|
|
277
281
|
},
|
|
278
|
-
|
|
282
|
+
__wbg_next_f4aac29c42af995c: function() { return handleError(function (arg0) {
|
|
279
283
|
const ret = arg0.next();
|
|
280
284
|
return ret;
|
|
281
285
|
}, arguments); },
|
|
282
|
-
__wbg_next_402fa10b59ab20c3: function(arg0) {
|
|
283
|
-
const ret = arg0.next;
|
|
284
|
-
return ret;
|
|
285
|
-
},
|
|
286
286
|
__wbg_now_e7c6795a7f81e10f: function(arg0) {
|
|
287
287
|
const ret = arg0.now();
|
|
288
288
|
return ret;
|
|
@@ -291,13 +291,13 @@ function __wbg_get_imports() {
|
|
|
291
291
|
const ret = arg0.performance;
|
|
292
292
|
return ret;
|
|
293
293
|
},
|
|
294
|
-
|
|
294
|
+
__wbg_prototypesetcall_bc27214492979395: function(arg0, arg1, arg2) {
|
|
295
295
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
296
296
|
},
|
|
297
297
|
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
|
|
298
298
|
arg0[arg1] = arg2;
|
|
299
299
|
},
|
|
300
|
-
|
|
300
|
+
__wbg_set_bea140a88be9b277: function(arg0, arg1, arg2) {
|
|
301
301
|
arg0[arg1 >>> 0] = arg2;
|
|
302
302
|
},
|
|
303
303
|
__wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
|
|
@@ -307,32 +307,32 @@ function __wbg_get_imports() {
|
|
|
307
307
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
308
308
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
309
309
|
},
|
|
310
|
-
|
|
311
|
-
const ret = typeof
|
|
310
|
+
__wbg_static_accessor_GLOBAL_266715b9d96ba635: function() {
|
|
311
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
312
312
|
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
313
313
|
},
|
|
314
|
-
|
|
315
|
-
const ret = typeof
|
|
314
|
+
__wbg_static_accessor_GLOBAL_THIS_10fb7dc1ae063179: function() {
|
|
315
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
316
316
|
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
317
317
|
},
|
|
318
|
-
|
|
318
|
+
__wbg_static_accessor_SELF_0b583911f537483a: function() {
|
|
319
319
|
const ret = typeof self === 'undefined' ? null : self;
|
|
320
320
|
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
321
321
|
},
|
|
322
|
-
|
|
322
|
+
__wbg_static_accessor_WINDOW_d7f903d1508cbdc4: function() {
|
|
323
323
|
const ret = typeof window === 'undefined' ? null : window;
|
|
324
324
|
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
325
325
|
},
|
|
326
|
-
|
|
326
|
+
__wbg_value_f3c585ee8f5ba40c: function(arg0) {
|
|
327
327
|
const ret = arg0.value;
|
|
328
328
|
return ret;
|
|
329
329
|
},
|
|
330
|
-
|
|
330
|
+
__wbindgen_generic_0000000000000001: function(arg0) {
|
|
331
331
|
// Cast intrinsic for `F64 -> Externref`.
|
|
332
332
|
const ret = arg0;
|
|
333
333
|
return ret;
|
|
334
334
|
},
|
|
335
|
-
|
|
335
|
+
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
|
|
336
336
|
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
337
337
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
338
338
|
return ret;
|
|
@@ -549,11 +549,15 @@ function __wbg_finalize_init(instance, module) {
|
|
|
549
549
|
|
|
550
550
|
async function __wbg_load(module, imports) {
|
|
551
551
|
if (typeof Response === 'function' && module instanceof Response) {
|
|
552
|
+
if (!module.ok) {
|
|
553
|
+
throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
554
|
+
}
|
|
555
|
+
|
|
552
556
|
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
553
557
|
try {
|
|
554
558
|
return await WebAssembly.instantiateStreaming(module, imports);
|
|
555
559
|
} catch (e) {
|
|
556
|
-
const validResponse =
|
|
560
|
+
const validResponse = expectedResponseType(module.type);
|
|
557
561
|
|
|
558
562
|
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
559
563
|
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
@@ -608,6 +612,16 @@ async function __wbg_init(module_or_path) {
|
|
|
608
612
|
return __wbg_finalize_init(instance);
|
|
609
613
|
}
|
|
610
614
|
|
|
615
|
+
/**
|
|
616
|
+
* Defines how the client fetches flag state updates from the Flipt server.
|
|
617
|
+
*/
|
|
618
|
+
var FetchMode;
|
|
619
|
+
(function (FetchMode) {
|
|
620
|
+
/** Periodically poll the server for new flag state at the configured updateInterval. */
|
|
621
|
+
FetchMode["Polling"] = "polling";
|
|
622
|
+
/** Use Server-Sent Events to receive real-time flag state updates. */
|
|
623
|
+
FetchMode["Streaming"] = "streaming";
|
|
624
|
+
})(FetchMode || (FetchMode = {}));
|
|
611
625
|
/**
|
|
612
626
|
* Defines the strategy to handle errors during the flags snapshot update calls.
|
|
613
627
|
*/
|
|
@@ -633,7 +647,8 @@ class ClientOptionsFactory {
|
|
|
633
647
|
url: 'http://localhost:8080',
|
|
634
648
|
reference: '',
|
|
635
649
|
updateInterval: 120,
|
|
636
|
-
errorStrategy: ErrorStrategy.Fail
|
|
650
|
+
errorStrategy: ErrorStrategy.Fail,
|
|
651
|
+
fetchMode: FetchMode.Polling
|
|
637
652
|
};
|
|
638
653
|
}
|
|
639
654
|
}
|
|
@@ -665,11 +680,67 @@ function serialize(data) {
|
|
|
665
680
|
return result;
|
|
666
681
|
}
|
|
667
682
|
|
|
683
|
+
const noopLogger = {
|
|
684
|
+
debug: () => { },
|
|
685
|
+
info: () => { },
|
|
686
|
+
warn: () => { },
|
|
687
|
+
error: () => { }
|
|
688
|
+
};
|
|
668
689
|
class BaseFliptClient {
|
|
669
690
|
constructor(engine, fetcher) {
|
|
691
|
+
this.logger = noopLogger;
|
|
670
692
|
this.engine = engine;
|
|
671
693
|
this.fetcher = fetcher;
|
|
672
694
|
}
|
|
695
|
+
/**
|
|
696
|
+
* Close the client and clean up resources.
|
|
697
|
+
*/
|
|
698
|
+
close() {
|
|
699
|
+
this.closeEventSource();
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Wire up SSE handlers shared by the browser and Node clients.
|
|
703
|
+
* EventSource reconnects on its own after transient errors; on every
|
|
704
|
+
* (re)open we refresh so updates missed while disconnected are picked up.
|
|
705
|
+
*/
|
|
706
|
+
attachStream(eventSource) {
|
|
707
|
+
eventSource.onopen = () => {
|
|
708
|
+
this.logger.debug('sse connected');
|
|
709
|
+
this.refreshFromStream();
|
|
710
|
+
};
|
|
711
|
+
eventSource.onmessage = (event) => {
|
|
712
|
+
try {
|
|
713
|
+
const data = JSON.parse(event.data);
|
|
714
|
+
this.logger.debug('sse message:', data);
|
|
715
|
+
if (data.type === 'refetchEvaluation') {
|
|
716
|
+
this.refreshFromStream();
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
catch {
|
|
720
|
+
this.logger.warn('sse parse error:', event.data);
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
eventSource.onerror = (err) => {
|
|
724
|
+
if (eventSource.readyState === 2 /* CLOSED */) {
|
|
725
|
+
this.logger.error('sse connection closed, no further updates:', err);
|
|
726
|
+
}
|
|
727
|
+
else {
|
|
728
|
+
this.logger.warn('sse error, reconnecting:', err);
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
this.eventSource = eventSource;
|
|
732
|
+
}
|
|
733
|
+
refreshFromStream() {
|
|
734
|
+
this.refresh().catch((err) => {
|
|
735
|
+
this.logger.warn('sse refresh failed:', err);
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
closeEventSource() {
|
|
739
|
+
if (this.eventSource) {
|
|
740
|
+
this.eventSource.close();
|
|
741
|
+
this.eventSource = undefined;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
673
744
|
/**
|
|
674
745
|
* Store etag from response for next requests
|
|
675
746
|
*/
|
|
@@ -955,4 +1026,4 @@ class FliptClient extends BaseFliptClient {
|
|
|
955
1026
|
}
|
|
956
1027
|
}
|
|
957
1028
|
|
|
958
|
-
export { BaseFliptClient, ClientOptionsFactory, ErrorStrategy, FliptClient };
|
|
1029
|
+
export { BaseFliptClient, ClientOptionsFactory, ErrorStrategy, FetchMode, FliptClient };
|
|
@@ -1,12 +1,34 @@
|
|
|
1
|
-
import { BatchEvaluationResponse, BooleanEvaluationResponse, EvaluationRequest, Flag, IFetcher, VariantEvaluationResponse, ErrorStrategy, Response, Hook } from './types';
|
|
1
|
+
import { BatchEvaluationResponse, BooleanEvaluationResponse, EvaluationRequest, Flag, IFetcher, VariantEvaluationResponse, ErrorStrategy, Response, Hook, Logger } from './types';
|
|
2
2
|
export type FliptClient = BaseFliptClient;
|
|
3
|
+
/** The subset of the EventSource API used by the client (browser and `eventsource` package). */
|
|
4
|
+
export interface StreamSource {
|
|
5
|
+
readyState: number;
|
|
6
|
+
onopen: ((event: any) => void) | null;
|
|
7
|
+
onmessage: ((event: any) => void) | null;
|
|
8
|
+
onerror: ((event: any) => void) | null;
|
|
9
|
+
close(): void;
|
|
10
|
+
}
|
|
3
11
|
export declare abstract class BaseFliptClient {
|
|
4
12
|
protected engine: any;
|
|
5
13
|
protected fetcher: IFetcher;
|
|
6
14
|
protected etag?: string;
|
|
7
15
|
protected errorStrategy?: ErrorStrategy;
|
|
8
16
|
protected hook?: Hook;
|
|
17
|
+
protected eventSource?: StreamSource;
|
|
18
|
+
protected logger: Logger;
|
|
9
19
|
constructor(engine: any, fetcher: IFetcher);
|
|
20
|
+
/**
|
|
21
|
+
* Close the client and clean up resources.
|
|
22
|
+
*/
|
|
23
|
+
close(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Wire up SSE handlers shared by the browser and Node clients.
|
|
26
|
+
* EventSource reconnects on its own after transient errors; on every
|
|
27
|
+
* (re)open we refresh so updates missed while disconnected are picked up.
|
|
28
|
+
*/
|
|
29
|
+
protected attachStream(eventSource: StreamSource): void;
|
|
30
|
+
private refreshFromStream;
|
|
31
|
+
protected closeEventSource(): void;
|
|
10
32
|
/**
|
|
11
33
|
* Store etag from response for next requests
|
|
12
34
|
*/
|
|
@@ -132,6 +132,16 @@ export interface ClientOptions {
|
|
|
132
132
|
* The strategy to use for errors during refresh snapshot calls. {@link ErrorStrategy}
|
|
133
133
|
*/
|
|
134
134
|
errorStrategy?: ErrorStrategy;
|
|
135
|
+
/**
|
|
136
|
+
* The fetch mode to use for receiving flag state updates. {@link FetchMode}
|
|
137
|
+
*
|
|
138
|
+
* @defaultValue `FetchMode.Polling`
|
|
139
|
+
*/
|
|
140
|
+
fetchMode?: FetchMode;
|
|
141
|
+
/**
|
|
142
|
+
* Optional logger for debugging and diagnostics.
|
|
143
|
+
*/
|
|
144
|
+
logger?: Logger;
|
|
135
145
|
/**
|
|
136
146
|
* The hook to use for before and after evaluation calls.
|
|
137
147
|
*/
|
|
@@ -259,6 +269,15 @@ export interface BatchEvaluationResponse {
|
|
|
259
269
|
/** Duration of the request in milliseconds. */
|
|
260
270
|
requestDurationMillis: number;
|
|
261
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Defines how the client fetches flag state updates from the Flipt server.
|
|
274
|
+
*/
|
|
275
|
+
export declare enum FetchMode {
|
|
276
|
+
/** Periodically poll the server for new flag state at the configured updateInterval. */
|
|
277
|
+
Polling = "polling",
|
|
278
|
+
/** Use Server-Sent Events to receive real-time flag state updates. */
|
|
279
|
+
Streaming = "streaming"
|
|
280
|
+
}
|
|
262
281
|
/**
|
|
263
282
|
* Defines the strategy to handle errors during the flags snapshot update calls.
|
|
264
283
|
*/
|
|
@@ -299,3 +318,12 @@ export interface Hook {
|
|
|
299
318
|
segmentKeys: string[];
|
|
300
319
|
}): void;
|
|
301
320
|
}
|
|
321
|
+
/**
|
|
322
|
+
* Logger interface for client diagnostics.
|
|
323
|
+
*/
|
|
324
|
+
export interface Logger {
|
|
325
|
+
debug(...args: any[]): void;
|
|
326
|
+
info(...args: any[]): void;
|
|
327
|
+
warn(...args: any[]): void;
|
|
328
|
+
error(...args: any[]): void;
|
|
329
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ import { FliptClient as NodeImpl } from './node';
|
|
|
6
6
|
import { FliptClient as BrowserImpl } from './browser';
|
|
7
7
|
export { NodeImpl as NodeFliptClient };
|
|
8
8
|
export { BrowserImpl as BrowserFliptClient };
|
|
9
|
-
export declare const FliptClient: typeof BrowserImpl;
|
|
9
|
+
export declare const FliptClient: typeof NodeImpl | typeof BrowserImpl;
|
|
10
10
|
export type FliptClient = InstanceType<typeof FliptClient>;
|
|
@@ -11,6 +11,7 @@ export declare class FliptClient extends BaseFliptClient {
|
|
|
11
11
|
* @returns {Promise<FliptClient>}
|
|
12
12
|
*/
|
|
13
13
|
static init(options?: ClientOptions): Promise<FliptClient>;
|
|
14
|
+
private setupStream;
|
|
14
15
|
private setupAutoRefresh;
|
|
15
16
|
private cleanupAutoRefresh;
|
|
16
17
|
close(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flipt-io/flipt-client-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Flipt Client Evaluation SDK for Web and Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/node/index.cjs",
|
|
@@ -83,6 +83,7 @@
|
|
|
83
83
|
"clean": "rimraf dist"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
+
"eventsource": "^4.1.0",
|
|
86
87
|
"node-fetch": "^3.3.0"
|
|
87
88
|
},
|
|
88
89
|
"devDependencies": {
|
|
@@ -91,7 +92,7 @@
|
|
|
91
92
|
"@rollup/plugin-typescript": "^12.1.0",
|
|
92
93
|
"@rollup/plugin-wasm": "^6.2.2",
|
|
93
94
|
"@types/jest": "^30.0.0",
|
|
94
|
-
"@types/node": "^
|
|
95
|
+
"@types/node": "^26.0.0",
|
|
95
96
|
"@types/node-fetch": "^2.6.11",
|
|
96
97
|
"@typescript-eslint/eslint-plugin": "^8.33.1",
|
|
97
98
|
"@typescript-eslint/parser": "^8.33.1",
|
|
@@ -108,7 +109,7 @@
|
|
|
108
109
|
"undici": "^8.0.2"
|
|
109
110
|
},
|
|
110
111
|
"engines": {
|
|
111
|
-
"node": ">=
|
|
112
|
+
"node": ">=20"
|
|
112
113
|
},
|
|
113
114
|
"publishConfig": {
|
|
114
115
|
"access": "public"
|