@@ -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 (
@@ -177,6 +190,10 @@ export default class EppoClient {
177
190
this . isObfuscated = isObfuscated ;
178
191
}
179
192
193
+ setOverridesStore ( store : IConfigurationStore < Variation > ) : void {
194
+ this . overridesStore = store ;
195
+ }
196
+
180
197
async fetchFlagConfigurations ( ) {
181
198
if ( ! this . configurationRequestParameters ) {
182
199
throw new Error (
@@ -924,6 +941,34 @@ export default class EppoClient {
924
941
validateNotBlank ( subjectKey , 'Invalid argument: subjectKey cannot be blank' ) ;
925
942
validateNotBlank ( flagKey , 'Invalid argument: flagKey cannot be blank' ) ;
926
943
944
+ // Check for override early
945
+ const overrideVariation = this . overridesStore ?. get ( flagKey ) ;
946
+ if ( overrideVariation ) {
947
+ const configFormat = this . overridesStore ?. getFormat ( ) ?? '' ;
948
+ const flagEvaluationDetailsBuilder = this . newFlagEvaluationDetailsBuilder ( flagKey ) ;
949
+ const flagEvaluationDetails = flagEvaluationDetailsBuilder
950
+ . setMatch (
951
+ 0 ,
952
+ overrideVariation ,
953
+ { key : overrideVariation . key , splits : [ ] , doLog : false } ,
954
+ null ,
955
+ undefined ,
956
+ )
957
+ . build ( 'MATCH' , 'Flag override applied' ) ;
958
+
959
+ return {
960
+ flagKey,
961
+ subjectKey,
962
+ variation : overrideVariation ,
963
+ subjectAttributes,
964
+ flagEvaluationDetails,
965
+ doLog : false ,
966
+ format : configFormat ,
967
+ allocationKey : 'override' ,
968
+ extraLogging : { } ,
969
+ } ;
970
+ }
971
+
927
972
const flagEvaluationDetailsBuilder = this . newFlagEvaluationDetailsBuilder ( flagKey ) ;
928
973
const configDetails = this . getConfigDetails ( ) ;
929
974
const flag = this . getFlag ( flagKey ) ;
0 commit comments