@@ -15,6 +15,7 @@ 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 { ConfigurationStore } from '../configuration-store' ;
18
19
import { IConfigurationStore , ISyncStore } from '../configuration-store/configuration-store' ;
19
20
import { MemoryOnlyConfigurationStore } from '../configuration-store/memory.store' ;
20
21
import {
@@ -41,7 +42,7 @@ import {
41
42
} from '../flag-evaluation-details-builder' ;
42
43
import { FlagEvaluationError } from '../flag-evaluation-error' ;
43
44
import FetchHttpClient from '../http-client' ;
44
- import { IConfiguration , StoreBackedConfiguration } from '../i-configuration' ;
45
+ import { Configuration , IConfiguration , StoreBackedConfiguration } from '../i-configuration' ;
45
46
import {
46
47
BanditModelData ,
47
48
BanditParameters ,
@@ -124,10 +125,7 @@ export default class EppoClient {
124
125
private banditLogger ?: IBanditLogger ;
125
126
private banditAssignmentCache ?: AssignmentCache ;
126
127
private configurationRequestParameters ?: FlagConfigurationRequestParameters ;
127
- private banditModelConfigurationStore ?: IConfigurationStore < BanditParameters > ;
128
- private banditVariationConfigurationStore ?: IConfigurationStore < BanditVariation [ ] > ;
129
128
private overrideStore ?: ISyncStore < Variation > ;
130
- private flagConfigurationStore : IConfigurationStore < Flag | ObfuscatedFlag > ;
131
129
private assignmentLogger ?: IAssignmentLogger ;
132
130
private assignmentCache ?: AssignmentCache ;
133
131
// whether to suppress any errors and return default values instead
@@ -137,6 +135,14 @@ export default class EppoClient {
137
135
private configurationRequestor ?: ConfigurationRequestor ;
138
136
private readonly overrideValidator = new OverrideValidator ( ) ;
139
137
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
+
140
146
constructor ( {
141
147
eventDispatcher = new NoOpEventDispatcher ( ) ,
142
148
isObfuscated,
@@ -161,14 +167,8 @@ export default class EppoClient {
161
167
}
162
168
}
163
169
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 ( ) ;
172
172
}
173
173
174
174
/**
@@ -206,18 +206,6 @@ export default class EppoClient {
206
206
this . configurationRequestParameters = configurationRequestParameters ;
207
207
}
208
208
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
-
221
209
/** Sets the EventDispatcher instance to use when tracking events with {@link track}. */
222
210
// noinspection JSUnusedGlobalSymbols
223
211
setEventDispatcher ( eventDispatcher : EventDispatcher ) {
@@ -239,29 +227,6 @@ export default class EppoClient {
239
227
this . eventDispatcher ?. attachContext ( key , value ) ;
240
228
}
241
229
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
-
265
230
setOverrideStore ( store : ISyncStore < Variation > ) : void {
266
231
this . overrideStore = store ;
267
232
}
@@ -641,6 +606,9 @@ export default class EppoClient {
641
606
defaultAction : string ,
642
607
) : string {
643
608
const config = this . getConfiguration ( ) ;
609
+ if ( ! config ) {
610
+ return defaultAction ;
611
+ }
644
612
let result : string | null = null ;
645
613
646
614
const flagBanditVariations = config . getFlagBanditVariations ( flagKey ) ;
@@ -697,6 +665,10 @@ export default class EppoClient {
697
665
variation = assignedVariation ;
698
666
evaluationDetails = assignmentEvaluationDetails ;
699
667
668
+ if ( ! config ) {
669
+ return { variation, action : null , evaluationDetails } ;
670
+ }
671
+
700
672
// Check if the assigned variation is an active bandit
701
673
// Note: the reason for non-bandit assignments include the subject being bucketed into a non-bandit variation or
702
674
// a rollout having been done.
@@ -929,8 +901,11 @@ export default class EppoClient {
929
901
subjectAttributes : Attributes = { } ,
930
902
) : Record < FlagKey , PrecomputedFlag > {
931
903
const config = this . getConfiguration ( ) ;
904
+ if ( ! config ) {
905
+ return { } ;
906
+ }
932
907
const configDetails = config . getFlagConfigDetails ( ) ;
933
- const flagKeys = this . getFlagKeys ( ) ;
908
+ const flagKeys = config . getFlagKeys ( ) ;
934
909
const flags : Record < FlagKey , PrecomputedFlag > = { } ;
935
910
936
911
// Evaluate all the enabled flags for the user
@@ -985,11 +960,24 @@ export default class EppoClient {
985
960
banditActions : Record < FlagKey , BanditActions > = { } ,
986
961
salt ?: string ,
987
962
) : string {
963
+ const subjectContextualAttributes = ensureContextualSubjectAttributes ( subjectAttributes ) ;
964
+ const subjectFlatAttributes = ensureNonContextualSubjectAttributes ( subjectAttributes ) ;
965
+
988
966
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
+
989
979
const configDetails = config . getFlagConfigDetails ( ) ;
990
980
991
- const subjectContextualAttributes = ensureContextualSubjectAttributes ( subjectAttributes ) ;
992
- const subjectFlatAttributes = ensureNonContextualSubjectAttributes ( subjectAttributes ) ;
993
981
const flags = this . getAllAssignments ( subjectKey , subjectFlatAttributes ) ;
994
982
995
983
const bandits = this . computeBanditsForFlags (
@@ -1036,6 +1024,14 @@ export default class EppoClient {
1036
1024
const config = this . getConfiguration ( ) ;
1037
1025
1038
1026
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
+
1039
1035
const overrideVariation = this . overrideStore ?. get ( flagKey ) ;
1040
1036
if ( overrideVariation ) {
1041
1037
return overrideResult (
@@ -1138,9 +1134,13 @@ export default class EppoClient {
1138
1134
}
1139
1135
1140
1136
private newFlagEvaluationDetailsBuilder (
1141
- config : IConfiguration ,
1137
+ config : IConfiguration | null ,
1142
1138
flagKey : string ,
1143
1139
) : FlagEvaluationDetailsBuilder {
1140
+ if ( ! config ) {
1141
+ return new FlagEvaluationDetailsBuilder ( '' , [ ] , '' , '' ) ;
1142
+ }
1143
+
1144
1144
const flag = this . getNormalizedFlag ( config , flagKey ) ;
1145
1145
const configDetails = config . getFlagConfigDetails ( ) ;
1146
1146
return new FlagEvaluationDetailsBuilder (
@@ -1162,19 +1162,8 @@ export default class EppoClient {
1162
1162
return flag ? decodeFlag ( flag ) : null ;
1163
1163
}
1164
1164
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
-
1176
1165
isInitialized ( ) {
1177
- return this . getConfiguration ( ) . isInitialized ( ) ;
1166
+ return this . getConfiguration ( ) ? .isInitialized ( ) ?? false ;
1178
1167
}
1179
1168
1180
1169
/** @deprecated Use `setAssignmentLogger` */
@@ -1239,10 +1228,6 @@ export default class EppoClient {
1239
1228
this . isGracefulFailureMode = gracefulFailureMode ;
1240
1229
}
1241
1230
1242
- getFlagConfigurations ( ) : Record < string , Flag > {
1243
- return this . getConfiguration ( ) . getFlags ( ) ;
1244
- }
1245
-
1246
1231
private flushQueuedEvents < T > ( eventQueue : BoundedEventQueue < T > , logFunction ?: ( event : T ) => void ) {
1247
1232
const eventsToFlush = eventQueue . flush ( ) ;
1248
1233
if ( ! logFunction ) {
@@ -1319,7 +1304,7 @@ export default class EppoClient {
1319
1304
1320
1305
private buildLoggerMetadata ( ) : Record < string , unknown > {
1321
1306
return {
1322
- obfuscated : this . getConfiguration ( ) . isObfuscated ( ) ,
1307
+ obfuscated : this . getConfiguration ( ) ? .isObfuscated ( ) ,
1323
1308
sdkLanguage : 'javascript' ,
1324
1309
sdkLibVersion : LIB_VERSION ,
1325
1310
} ;
0 commit comments