@@ -17,7 +17,10 @@ import { TLRUInMemoryAssignmentCache } from '../cache/tlru-in-memory-assignment-
17
17
import ConfigurationRequestor from '../configuration-requestor' ;
18
18
import { ConfigurationManager } from '../configuration-store/configuration-manager' ;
19
19
import { IConfigurationStore , ISyncStore } from '../configuration-store/configuration-store' ;
20
- import { IConfigurationManager } from '../configuration-store/i-configuration-manager' ;
20
+ import {
21
+ ConfigurationStoreBundle ,
22
+ IConfigurationManager ,
23
+ } from '../configuration-store/i-configuration-manager' ;
21
24
import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.store' ;
22
25
import {
23
26
ConfigurationWireV1 ,
@@ -43,7 +46,10 @@ import {
43
46
IFlagEvaluationDetails ,
44
47
} from '../flag-evaluation-details-builder' ;
45
48
import { FlagEvaluationError } from '../flag-evaluation-error' ;
46
- import FetchHttpClient from '../http-client' ;
49
+ import FetchHttpClient , {
50
+ IBanditParametersResponse ,
51
+ IUniversalFlagConfigResponse ,
52
+ } from '../http-client' ;
47
53
import { IConfiguration } from '../i-configuration' ;
48
54
import {
49
55
BanditModelData ,
@@ -173,9 +179,8 @@ export default class EppoClient {
173
179
// Initialize the configuration manager
174
180
this . configurationManager = new ConfigurationManager (
175
181
this . flagConfigurationStore ,
176
- this . banditVariationConfigurationStore ||
177
- new MemoryOnlyConfigurationStore < BanditVariation [ ] > ( ) ,
178
- this . banditModelConfigurationStore || new MemoryOnlyConfigurationStore < BanditParameters > ( ) ,
182
+ this . banditVariationConfigurationStore ,
183
+ this . banditModelConfigurationStore ,
179
184
) ;
180
185
}
181
186
@@ -244,46 +249,54 @@ export default class EppoClient {
244
249
this . configurationRequestParameters = configurationRequestParameters ;
245
250
}
246
251
252
+ public setConfigurationStores ( configStores : ConfigurationStoreBundle ) {
253
+ // Update the configuration manager
254
+ this . configurationManager . setConfigurationStores ( configStores ) ;
255
+ }
256
+
257
+ // noinspection JSUnusedGlobalSymbols
258
+ /**
259
+ * @deprecated use `setConfigurationStores` instead
260
+ */
247
261
setFlagConfigurationStore ( flagConfigurationStore : IConfigurationStore < Flag | ObfuscatedFlag > ) {
248
262
this . flagConfigurationStore = flagConfigurationStore ;
249
263
this . configObfuscatedCache = undefined ;
250
264
251
265
// Update the configuration manager
252
- this . configurationManager . setConfigurationStores ( {
253
- flagConfigurationStore : this . flagConfigurationStore ,
254
- banditReferenceConfigurationStore :
255
- this . banditVariationConfigurationStore ||
256
- new MemoryOnlyConfigurationStore < BanditVariation [ ] > ( ) ,
257
- banditConfigurationStore :
258
- this . banditModelConfigurationStore || new MemoryOnlyConfigurationStore < BanditParameters > ( ) ,
259
- } ) ;
266
+ this . innerSetConfigurationStores ( ) ;
260
267
}
261
268
269
+ // noinspection JSUnusedGlobalSymbols
270
+ /**
271
+ * @deprecated use `setConfigurationStores` instead
272
+ */
262
273
setBanditVariationConfigurationStore (
263
274
banditVariationConfigurationStore : IConfigurationStore < BanditVariation [ ] > ,
264
275
) {
265
276
this . banditVariationConfigurationStore = banditVariationConfigurationStore ;
266
277
267
278
// Update the configuration manager
268
- this . configurationManager . setConfigurationStores ( {
269
- flagConfigurationStore : this . flagConfigurationStore ,
270
- banditReferenceConfigurationStore : this . banditVariationConfigurationStore ,
271
- banditConfigurationStore :
272
- this . banditModelConfigurationStore || new MemoryOnlyConfigurationStore < BanditParameters > ( ) ,
273
- } ) ;
279
+ this . innerSetConfigurationStores ( ) ;
274
280
}
275
281
282
+ // noinspection JSUnusedGlobalSymbols
283
+ /**
284
+ * @deprecated use `setConfigurationStores` instead
285
+ */
276
286
setBanditModelConfigurationStore (
277
287
banditModelConfigurationStore : IConfigurationStore < BanditParameters > ,
278
288
) {
279
289
this . banditModelConfigurationStore = banditModelConfigurationStore ;
280
290
281
291
// Update the configuration manager
282
- this . configurationManager . setConfigurationStores ( {
292
+ this . innerSetConfigurationStores ( ) ;
293
+ }
294
+
295
+ private innerSetConfigurationStores ( ) {
296
+ // Set the set of configuration stores to those owned by the `this`.
297
+ this . setConfigurationStores ( {
283
298
flagConfigurationStore : this . flagConfigurationStore ,
284
- banditReferenceConfigurationStore :
285
- this . banditVariationConfigurationStore ||
286
- new MemoryOnlyConfigurationStore < BanditVariation [ ] > ( ) ,
299
+ banditReferenceConfigurationStore : this . banditVariationConfigurationStore ,
287
300
banditConfigurationStore : this . banditModelConfigurationStore ,
288
301
} ) ;
289
302
}
@@ -326,32 +339,49 @@ export default class EppoClient {
326
339
) ;
327
340
}
328
341
329
- bootstrap ( configuration : IConfigurationWire ) {
342
+ /**
343
+ * Initializes the `EppoClient` from the provided configuration. This method is async only to
344
+ * accommodate writing to a persistent store. For fastest initialization, (at the cost of persisting configuration),
345
+ * use `bootstrap` in conjunction with `MemoryOnlyConfigurationStore` instances which won't do an async write.
346
+ */
347
+ async bootstrap ( configuration : IConfigurationWire ) : Promise < void > {
330
348
if ( ! configuration . config ) {
331
349
throw new Error ( 'Flag configuration not provided' ) ;
332
350
}
333
- const flagConfigResponse = inflateResponse ( configuration . config . response ) ;
334
- const banditParamResponse = configuration . bandits
351
+ const flagConfigResponse : IUniversalFlagConfigResponse = inflateResponse (
352
+ configuration . config . response ,
353
+ ) ;
354
+ const banditParamResponse : IBanditParametersResponse | undefined = configuration . bandits
335
355
? inflateResponse ( configuration . bandits . response )
336
356
: undefined ;
337
357
338
- this . configurationManager . hydrateConfigurationStoresFromUfc (
358
+ // We need to run this method sync, but, because the configuration stores potentially have an async write at the end
359
+ // of updating the configuration, the method to do so it also async. Use an IIFE to wrap the async call.
360
+ await this . configurationManager . hydrateConfigurationStoresFromUfc (
339
361
flagConfigResponse ,
340
362
banditParamResponse ,
341
363
) ;
342
364
343
365
// Still initialize the client in case polling is needed.
344
- this . inititalize ( ) ;
366
+ // fire-and-forget so ignore the resolution of this promise.
367
+ this . initialize ( )
368
+ . then ( ( ) => {
369
+ logger . debug ( 'Eppo SDK polling initialization complete' ) ;
370
+ return ;
371
+ } )
372
+ . catch ( ( e ) => {
373
+ logger . error ( 'Eppo SDK Error initializing polling after bootstrap()' , e ) ;
374
+ } ) ;
345
375
}
346
376
347
377
/**
348
378
* @deprecated use `initialize` instead.
349
379
*/
350
380
async fetchFlagConfigurations ( ) {
351
- return this . inititalize ( ) ;
381
+ return this . initialize ( ) ;
352
382
}
353
383
354
- async inititalize ( ) {
384
+ async initialize ( ) {
355
385
if ( ! this . configurationRequestParameters ) {
356
386
throw new Error (
357
387
'Eppo SDK unable to fetch flag configurations without configuration request parameters' ,
0 commit comments