@@ -15,6 +15,7 @@ import { LRUInMemoryAssignmentCache } from '../cache/lru-in-memory-assignment-ca
1515import { NonExpiringInMemoryAssignmentCache } from '../cache/non-expiring-in-memory-cache-assignment' ;
1616import { TLRUInMemoryAssignmentCache } from '../cache/tlru-in-memory-assignment-cache' ;
1717import ConfigurationRequestor from '../configuration-requestor' ;
18+ import { ConfigurationStore } from '../configuration-store' ;
1819import { IConfigurationStore , ISyncStore } from '../configuration-store/configuration-store' ;
1920import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.store' ;
2021import {
@@ -41,7 +42,7 @@ import {
4142} from '../flag-evaluation-details-builder' ;
4243import { FlagEvaluationError } from '../flag-evaluation-error' ;
4344import FetchHttpClient from '../http-client' ;
44- import { IConfiguration , StoreBackedConfiguration } from '../i-configuration' ;
45+ import { Configuration , IConfiguration , StoreBackedConfiguration } from '../i-configuration' ;
4546import {
4647 BanditModelData ,
4748 BanditParameters ,
@@ -124,10 +125,7 @@ export default class EppoClient {
124125 private banditLogger ?: IBanditLogger ;
125126 private banditAssignmentCache ?: AssignmentCache ;
126127 private configurationRequestParameters ?: FlagConfigurationRequestParameters ;
127- private banditModelConfigurationStore ?: IConfigurationStore < BanditParameters > ;
128- private banditVariationConfigurationStore ?: IConfigurationStore < BanditVariation [ ] > ;
129128 private overrideStore ?: ISyncStore < Variation > ;
130- private flagConfigurationStore : IConfigurationStore < Flag | ObfuscatedFlag > ;
131129 private assignmentLogger ?: IAssignmentLogger ;
132130 private assignmentCache ?: AssignmentCache ;
133131 // whether to suppress any errors and return default values instead
@@ -137,6 +135,14 @@ export default class EppoClient {
137135 private configurationRequestor ?: ConfigurationRequestor ;
138136 private readonly overrideValidator = new OverrideValidator ( ) ;
139137
138+ private readonly configurationStore = new ConfigurationStore ( null ) ;
139+ /** @deprecated use configurationStore instead. */
140+ private flagConfigurationStore : IConfigurationStore < Flag | ObfuscatedFlag > ;
141+ /** @deprecated use configurationStore instead. */
142+ private banditModelConfigurationStore ?: IConfigurationStore < BanditParameters > ;
143+ /** @deprecated use configurationStore instead. */
144+ private banditVariationConfigurationStore ?: IConfigurationStore < BanditVariation [ ] > ;
145+
140146 constructor ( {
141147 eventDispatcher = new NoOpEventDispatcher ( ) ,
142148 isObfuscated,
@@ -161,14 +167,8 @@ export default class EppoClient {
161167 }
162168 }
163169
164- private getConfiguration ( ) : IConfiguration {
165- return this . configurationRequestor
166- ? this . configurationRequestor . getConfiguration ( )
167- : new StoreBackedConfiguration (
168- this . flagConfigurationStore ,
169- this . banditVariationConfigurationStore ,
170- this . banditModelConfigurationStore ,
171- ) ;
170+ private getConfiguration ( ) : Configuration | null {
171+ return this . configurationStore . getConfiguration ( ) ;
172172 }
173173
174174 /**
@@ -206,18 +206,6 @@ export default class EppoClient {
206206 this . configurationRequestParameters = configurationRequestParameters ;
207207 }
208208
209- // noinspection JSUnusedGlobalSymbols
210- setFlagConfigurationStore ( flagConfigurationStore : IConfigurationStore < Flag | ObfuscatedFlag > ) {
211- this . flagConfigurationStore = flagConfigurationStore ;
212- }
213-
214- // noinspection JSUnusedGlobalSymbols
215- setBanditVariationConfigurationStore (
216- banditVariationConfigurationStore : IConfigurationStore < BanditVariation [ ] > ,
217- ) {
218- this . banditVariationConfigurationStore = banditVariationConfigurationStore ;
219- }
220-
221209 /** Sets the EventDispatcher instance to use when tracking events with {@link track}. */
222210 // noinspection JSUnusedGlobalSymbols
223211 setEventDispatcher ( eventDispatcher : EventDispatcher ) {
@@ -239,29 +227,6 @@ export default class EppoClient {
239227 this . eventDispatcher ?. attachContext ( key , value ) ;
240228 }
241229
242- // noinspection JSUnusedGlobalSymbols
243- setBanditModelConfigurationStore (
244- banditModelConfigurationStore : IConfigurationStore < BanditParameters > ,
245- ) {
246- this . banditModelConfigurationStore = banditModelConfigurationStore ;
247- }
248-
249- // noinspection JSUnusedGlobalSymbols
250- /**
251- * Setting this value will have no side effects other than triggering a warning when the actual
252- * configuration's obfuscated does not match the value set here.
253- *
254- * @deprecated The client determines whether the configuration is obfuscated by inspection
255- * @param isObfuscated
256- */
257- // eslint-disable-next-line @typescript-eslint/no-unused-vars
258- setIsObfuscated ( isObfuscated : boolean ) {
259- logger . warn (
260- '[Eppo SDK] setIsObfuscated no longer has an effect and will be removed in the next major release; obfuscation ' +
261- 'is now inferred from the configuration, so you can safely remove the call to this method.' ,
262- ) ;
263- }
264-
265230 setOverrideStore ( store : ISyncStore < Variation > ) : void {
266231 this . overrideStore = store ;
267232 }
@@ -641,6 +606,9 @@ export default class EppoClient {
641606 defaultAction : string ,
642607 ) : string {
643608 const config = this . getConfiguration ( ) ;
609+ if ( ! config ) {
610+ return defaultAction ;
611+ }
644612 let result : string | null = null ;
645613
646614 const flagBanditVariations = config . getFlagBanditVariations ( flagKey ) ;
@@ -697,6 +665,10 @@ export default class EppoClient {
697665 variation = assignedVariation ;
698666 evaluationDetails = assignmentEvaluationDetails ;
699667
668+ if ( ! config ) {
669+ return { variation, action : null , evaluationDetails } ;
670+ }
671+
700672 // Check if the assigned variation is an active bandit
701673 // Note: the reason for non-bandit assignments include the subject being bucketed into a non-bandit variation or
702674 // a rollout having been done.
@@ -929,8 +901,11 @@ export default class EppoClient {
929901 subjectAttributes : Attributes = { } ,
930902 ) : Record < FlagKey , PrecomputedFlag > {
931903 const config = this . getConfiguration ( ) ;
904+ if ( ! config ) {
905+ return { } ;
906+ }
932907 const configDetails = config . getFlagConfigDetails ( ) ;
933- const flagKeys = this . getFlagKeys ( ) ;
908+ const flagKeys = config . getFlagKeys ( ) ;
934909 const flags : Record < FlagKey , PrecomputedFlag > = { } ;
935910
936911 // Evaluate all the enabled flags for the user
@@ -985,11 +960,24 @@ export default class EppoClient {
985960 banditActions : Record < FlagKey , BanditActions > = { } ,
986961 salt ?: string ,
987962 ) : string {
963+ const subjectContextualAttributes = ensureContextualSubjectAttributes ( subjectAttributes ) ;
964+ const subjectFlatAttributes = ensureNonContextualSubjectAttributes ( subjectAttributes ) ;
965+
988966 const config = this . getConfiguration ( ) ;
967+ if ( ! config ) {
968+ const precomputedConfig = PrecomputedConfiguration . obfuscated (
969+ subjectKey ,
970+ { } ,
971+ { } ,
972+ salt ?? '' ,
973+ subjectContextualAttributes ,
974+ undefined ,
975+ ) ;
976+ return JSON . stringify ( ConfigurationWireV1 . precomputed ( precomputedConfig ) ) ;
977+ }
978+
989979 const configDetails = config . getFlagConfigDetails ( ) ;
990980
991- const subjectContextualAttributes = ensureContextualSubjectAttributes ( subjectAttributes ) ;
992- const subjectFlatAttributes = ensureNonContextualSubjectAttributes ( subjectAttributes ) ;
993981 const flags = this . getAllAssignments ( subjectKey , subjectFlatAttributes ) ;
994982
995983 const bandits = this . computeBanditsForFlags (
@@ -1036,6 +1024,14 @@ export default class EppoClient {
10361024 const config = this . getConfiguration ( ) ;
10371025
10381026 const flagEvaluationDetailsBuilder = this . newFlagEvaluationDetailsBuilder ( config , flagKey ) ;
1027+ if ( ! config ) {
1028+ const flagEvaluationDetails = flagEvaluationDetailsBuilder . buildForNoneResult (
1029+ 'FLAG_UNRECOGNIZED_OR_DISABLED' ,
1030+ "Configuration hasn't being fetched yet" ,
1031+ ) ;
1032+ return noneResult ( flagKey , subjectKey , subjectAttributes , flagEvaluationDetails , '' ) ;
1033+ }
1034+
10391035 const overrideVariation = this . overrideStore ?. get ( flagKey ) ;
10401036 if ( overrideVariation ) {
10411037 return overrideResult (
@@ -1138,9 +1134,13 @@ export default class EppoClient {
11381134 }
11391135
11401136 private newFlagEvaluationDetailsBuilder (
1141- config : IConfiguration ,
1137+ config : IConfiguration | null ,
11421138 flagKey : string ,
11431139 ) : FlagEvaluationDetailsBuilder {
1140+ if ( ! config ) {
1141+ return new FlagEvaluationDetailsBuilder ( '' , [ ] , '' , '' ) ;
1142+ }
1143+
11441144 const flag = this . getNormalizedFlag ( config , flagKey ) ;
11451145 const configDetails = config . getFlagConfigDetails ( ) ;
11461146 return new FlagEvaluationDetailsBuilder (
@@ -1162,19 +1162,8 @@ export default class EppoClient {
11621162 return flag ? decodeFlag ( flag ) : null ;
11631163 }
11641164
1165- // noinspection JSUnusedGlobalSymbols
1166- getFlagKeys ( ) {
1167- /**
1168- * Returns a list of all flag keys that have been initialized.
1169- * This can be useful to debug the initialization process.
1170- *
1171- * Note that it is generally not a good idea to preload all flag configurations.
1172- */
1173- return this . getConfiguration ( ) . getFlagKeys ( ) ;
1174- }
1175-
11761165 isInitialized ( ) {
1177- return this . getConfiguration ( ) . isInitialized ( ) ;
1166+ return this . getConfiguration ( ) ? .isInitialized ( ) ?? false ;
11781167 }
11791168
11801169 /** @deprecated Use `setAssignmentLogger` */
@@ -1239,10 +1228,6 @@ export default class EppoClient {
12391228 this . isGracefulFailureMode = gracefulFailureMode ;
12401229 }
12411230
1242- getFlagConfigurations ( ) : Record < string , Flag > {
1243- return this . getConfiguration ( ) . getFlags ( ) ;
1244- }
1245-
12461231 private flushQueuedEvents < T > ( eventQueue : BoundedEventQueue < T > , logFunction ?: ( event : T ) => void ) {
12471232 const eventsToFlush = eventQueue . flush ( ) ;
12481233 if ( ! logFunction ) {
@@ -1319,7 +1304,7 @@ export default class EppoClient {
13191304
13201305 private buildLoggerMetadata ( ) : Record < string , unknown > {
13211306 return {
1322- obfuscated : this . getConfiguration ( ) . isObfuscated ( ) ,
1307+ obfuscated : this . getConfiguration ( ) ? .isObfuscated ( ) ,
13231308 sdkLanguage : 'javascript' ,
13241309 sdkLibVersion : LIB_VERSION ,
13251310 } ;
0 commit comments