@@ -15,7 +15,9 @@ import { LRUInMemoryAssignmentCache } from '../cache/lru-in-memory-assignment-ca
15
15
import { NonExpiringInMemoryAssignmentCache } from '../cache/non-expiring-in-memory-cache-assignment' ;
16
16
import { TLRUInMemoryAssignmentCache } from '../cache/tlru-in-memory-assignment-cache' ;
17
17
import ConfigurationRequestor from '../configuration-requestor' ;
18
+ import { ConfigurationManager } from '../configuration-store/configuration-manager' ;
18
19
import { IConfigurationStore , ISyncStore } from '../configuration-store/configuration-store' ;
20
+ import { IConfigurationManager } from '../configuration-store/i-configuration-manager' ;
19
21
import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.store' ;
20
22
import {
21
23
ConfigurationWireV1 ,
@@ -41,7 +43,7 @@ import {
41
43
} from '../flag-evaluation-details-builder' ;
42
44
import { FlagEvaluationError } from '../flag-evaluation-error' ;
43
45
import FetchHttpClient from '../http-client' ;
44
- import { IConfiguration , StoreBackedConfiguration } from '../i-configuration' ;
46
+ import { IConfiguration } from '../i-configuration' ;
45
47
import {
46
48
BanditModelData ,
47
49
BanditParameters ,
@@ -138,6 +140,7 @@ export default class EppoClient {
138
140
private readonly evaluator = new Evaluator ( ) ;
139
141
private configurationRequestor ?: ConfigurationRequestor ;
140
142
private readonly overrideValidator = new OverrideValidator ( ) ;
143
+ private configurationManager : IConfigurationManager ;
141
144
142
145
constructor ( {
143
146
eventDispatcher = new NoOpEventDispatcher ( ) ,
@@ -165,16 +168,18 @@ export default class EppoClient {
165
168
this . overrideStore = overrideStore ;
166
169
this . configurationRequestParameters = configurationRequestParameters ;
167
170
this . expectObfuscated = isObfuscated ;
171
+
172
+ // Initialize the configuration manager
173
+ this . configurationManager = new ConfigurationManager (
174
+ this . flagConfigurationStore ,
175
+ this . banditVariationConfigurationStore ||
176
+ new MemoryOnlyConfigurationStore < BanditVariation [ ] > ( ) ,
177
+ this . banditModelConfigurationStore || new MemoryOnlyConfigurationStore < BanditParameters > ( ) ,
178
+ ) ;
168
179
}
169
180
170
181
private getConfiguration ( ) : IConfiguration {
171
- return this . configurationRequestor
172
- ? this . configurationRequestor . getConfiguration ( )
173
- : new StoreBackedConfiguration (
174
- this . flagConfigurationStore ,
175
- this . banditVariationConfigurationStore ,
176
- this . banditModelConfigurationStore ,
177
- ) ;
182
+ return this . configurationManager . getConfiguration ( ) ;
178
183
}
179
184
180
185
private maybeWarnAboutObfuscationMismatch ( configObfuscated : boolean ) {
@@ -238,21 +243,51 @@ export default class EppoClient {
238
243
this . configurationRequestParameters = configurationRequestParameters ;
239
244
}
240
245
241
- // noinspection JSUnusedGlobalSymbols
242
246
setFlagConfigurationStore ( flagConfigurationStore : IConfigurationStore < Flag | ObfuscatedFlag > ) {
243
247
this . flagConfigurationStore = flagConfigurationStore ;
244
248
this . configObfuscatedCache = undefined ;
249
+
250
+ // Update the configuration manager
251
+ this . configurationManager . setConfigurationStores ( {
252
+ flagConfigurationStore : this . flagConfigurationStore ,
253
+ banditReferenceConfigurationStore :
254
+ this . banditVariationConfigurationStore ||
255
+ new MemoryOnlyConfigurationStore < BanditVariation [ ] > ( ) ,
256
+ banditConfigurationStore :
257
+ this . banditModelConfigurationStore || new MemoryOnlyConfigurationStore < BanditParameters > ( ) ,
258
+ } ) ;
245
259
}
246
260
247
- // noinspection JSUnusedGlobalSymbols
248
261
setBanditVariationConfigurationStore (
249
262
banditVariationConfigurationStore : IConfigurationStore < BanditVariation [ ] > ,
250
263
) {
251
264
this . banditVariationConfigurationStore = banditVariationConfigurationStore ;
265
+
266
+ // Update the configuration manager
267
+ this . configurationManager . setConfigurationStores ( {
268
+ flagConfigurationStore : this . flagConfigurationStore ,
269
+ banditReferenceConfigurationStore : this . banditVariationConfigurationStore ,
270
+ banditConfigurationStore :
271
+ this . banditModelConfigurationStore || new MemoryOnlyConfigurationStore < BanditParameters > ( ) ,
272
+ } ) ;
273
+ }
274
+
275
+ setBanditModelConfigurationStore (
276
+ banditModelConfigurationStore : IConfigurationStore < BanditParameters > ,
277
+ ) {
278
+ this . banditModelConfigurationStore = banditModelConfigurationStore ;
279
+
280
+ // Update the configuration manager
281
+ this . configurationManager . setConfigurationStores ( {
282
+ flagConfigurationStore : this . flagConfigurationStore ,
283
+ banditReferenceConfigurationStore :
284
+ this . banditVariationConfigurationStore ||
285
+ new MemoryOnlyConfigurationStore < BanditVariation [ ] > ( ) ,
286
+ banditConfigurationStore : this . banditModelConfigurationStore ,
287
+ } ) ;
252
288
}
253
289
254
290
/** Sets the EventDispatcher instance to use when tracking events with {@link track}. */
255
- // noinspection JSUnusedGlobalSymbols
256
291
setEventDispatcher ( eventDispatcher : EventDispatcher ) {
257
292
this . eventDispatcher = eventDispatcher ;
258
293
}
@@ -272,25 +307,6 @@ export default class EppoClient {
272
307
this . eventDispatcher ?. attachContext ( key , value ) ;
273
308
}
274
309
275
- // noinspection JSUnusedGlobalSymbols
276
- setBanditModelConfigurationStore (
277
- banditModelConfigurationStore : IConfigurationStore < BanditParameters > ,
278
- ) {
279
- this . banditModelConfigurationStore = banditModelConfigurationStore ;
280
- }
281
-
282
- // noinspection JSUnusedGlobalSymbols
283
- /**
284
- * Setting this value will have no side effects other than triggering a warning when the actual
285
- * configuration's obfuscated does not match the value set here.
286
- *
287
- * @deprecated The client determines whether the configuration is obfuscated by inspection
288
- * @param isObfuscated
289
- */
290
- setIsObfuscated ( isObfuscated : boolean ) {
291
- this . expectObfuscated = isObfuscated ;
292
- }
293
-
294
310
setOverrideStore ( store : ISyncStore < Variation > ) : void {
295
311
this . overrideStore = store ;
296
312
}
@@ -322,7 +338,7 @@ export default class EppoClient {
322
338
apiKey,
323
339
sdkName,
324
340
sdkVersion,
325
- baseUrl, // Default is set in ApiEndpoints constructor if undefined
341
+ baseUrl,
326
342
requestTimeoutMs = DEFAULT_REQUEST_TIMEOUT_MS ,
327
343
numInitialRequestRetries = DEFAULT_INITIAL_CONFIG_REQUEST_RETRIES ,
328
344
numPollRequestRetries = DEFAULT_POLL_CONFIG_REQUEST_RETRIES ,
@@ -338,22 +354,22 @@ export default class EppoClient {
338
354
pollingIntervalMs = DEFAULT_POLL_INTERVAL_MS ;
339
355
}
340
356
341
- // todo: Inject the chain of dependencies below
342
357
const apiEndpoints = new ApiEndpoints ( {
343
358
baseUrl,
344
359
queryParams : { apiKey, sdkName, sdkVersion } ,
345
360
} ) ;
346
361
const httpClient = new FetchHttpClient ( apiEndpoints , requestTimeoutMs ) ;
362
+
363
+ // Use the configuration manager when creating the requestor
347
364
const configurationRequestor = new ConfigurationRequestor (
348
365
httpClient ,
349
- this . flagConfigurationStore ,
350
- this . banditVariationConfigurationStore ?? null ,
351
- this . banditModelConfigurationStore ?? null ,
366
+ this . configurationManager ,
367
+ ! ! this . banditModelConfigurationStore && ! ! this . banditVariationConfigurationStore ,
352
368
) ;
353
369
this . configurationRequestor = configurationRequestor ;
354
370
355
371
const pollingCallback = async ( ) => {
356
- if ( await configurationRequestor . isFlagConfigExpired ( ) ) {
372
+ if ( await this . flagConfigurationStore . isExpired ( ) ) {
357
373
this . configObfuscatedCache = undefined ;
358
374
return configurationRequestor . fetchAndStoreConfigurations ( ) ;
359
375
}
0 commit comments