@@ -124,6 +124,7 @@ export default class EppoClient {
124
124
private isObfuscated : boolean ;
125
125
private requestPoller ?: IPoller ;
126
126
private readonly evaluator = new Evaluator ( ) ;
127
+ protected overridesStore ?: IConfigurationStore < Variation > ;
127
128
128
129
constructor ( {
129
130
eventDispatcher = new NoOpEventDispatcher ( ) ,
@@ -132,13 +133,25 @@ export default class EppoClient {
132
133
banditVariationConfigurationStore,
133
134
banditModelConfigurationStore,
134
135
configurationRequestParameters,
135
- } : EppoClientParameters ) {
136
+ overridesStore,
137
+ } : {
138
+ // Dispatcher for arbitrary, application-level events (not to be confused with Eppo specific assignment
139
+ // or bandit events). These events are application-specific and captures by EppoClient#track API.
140
+ eventDispatcher ?: EventDispatcher ;
141
+ flagConfigurationStore : IConfigurationStore < Flag | ObfuscatedFlag > ;
142
+ banditVariationConfigurationStore ?: IConfigurationStore < BanditVariation [ ] > ;
143
+ banditModelConfigurationStore ?: IConfigurationStore < BanditParameters > ;
144
+ configurationRequestParameters ?: FlagConfigurationRequestParameters ;
145
+ isObfuscated ?: boolean ;
146
+ overridesStore ?: IConfigurationStore < Variation > ;
147
+ } ) {
136
148
this . eventDispatcher = eventDispatcher ;
137
149
this . flagConfigurationStore = flagConfigurationStore ;
138
150
this . banditVariationConfigurationStore = banditVariationConfigurationStore ;
139
151
this . banditModelConfigurationStore = banditModelConfigurationStore ;
140
152
this . configurationRequestParameters = configurationRequestParameters ;
141
153
this . isObfuscated = isObfuscated ;
154
+ this . overridesStore = overridesStore ;
142
155
}
143
156
144
157
setConfigurationRequestParameters (
@@ -192,6 +205,10 @@ export default class EppoClient {
192
205
this . isObfuscated = isObfuscated ;
193
206
}
194
207
208
+ setOverridesStore ( store : IConfigurationStore < Variation > ) : void {
209
+ this . overridesStore = store ;
210
+ }
211
+
195
212
async fetchFlagConfigurations ( ) {
196
213
if ( ! this . configurationRequestParameters ) {
197
214
throw new Error (
@@ -939,6 +956,34 @@ export default class EppoClient {
939
956
validateNotBlank ( subjectKey , 'Invalid argument: subjectKey cannot be blank' ) ;
940
957
validateNotBlank ( flagKey , 'Invalid argument: flagKey cannot be blank' ) ;
941
958
959
+ // Check for override early
960
+ const overrideVariation = this . overridesStore ?. get ( flagKey ) ;
961
+ if ( overrideVariation ) {
962
+ const configFormat = this . overridesStore ?. getFormat ( ) ?? '' ;
963
+ const flagEvaluationDetailsBuilder = this . newFlagEvaluationDetailsBuilder ( flagKey ) ;
964
+ const flagEvaluationDetails = flagEvaluationDetailsBuilder
965
+ . setMatch (
966
+ 0 ,
967
+ overrideVariation ,
968
+ { key : overrideVariation . key , splits : [ ] , doLog : false } ,
969
+ null ,
970
+ undefined ,
971
+ )
972
+ . build ( 'MATCH' , 'Flag override applied' ) ;
973
+
974
+ return {
975
+ flagKey,
976
+ subjectKey,
977
+ variation : overrideVariation ,
978
+ subjectAttributes,
979
+ flagEvaluationDetails,
980
+ doLog : false ,
981
+ format : configFormat ,
982
+ allocationKey : 'override' ,
983
+ extraLogging : { } ,
984
+ } ;
985
+ }
986
+
942
987
const flagEvaluationDetailsBuilder = this . newFlagEvaluationDetailsBuilder ( flagKey ) ;
943
988
const configDetails = this . getConfigDetails ( ) ;
944
989
const flag = this . getFlag ( flagKey ) ;
0 commit comments