@@ -9,7 +9,7 @@ import { IBanditEvent, IBanditLogger } from '../bandit-logger';
9
9
import { AssignmentCache } from '../cache/abstract-assignment-cache' ;
10
10
import { LRUInMemoryAssignmentCache } from '../cache/lru-in-memory-assignment-cache' ;
11
11
import { NonExpiringInMemoryAssignmentCache } from '../cache/non-expiring-in-memory-cache-assignment' ;
12
- import { IConfigurationStore } from '../configuration-store/configuration-store' ;
12
+ import { IConfigurationStore , ISyncStore } from '../configuration-store/configuration-store' ;
13
13
import {
14
14
DEFAULT_INITIAL_CONFIG_REQUEST_RETRIES ,
15
15
DEFAULT_POLL_CONFIG_REQUEST_RETRIES ,
@@ -27,6 +27,7 @@ import {
27
27
IObfuscatedPrecomputedBandit ,
28
28
PrecomputedFlag ,
29
29
VariationType ,
30
+ Variation ,
30
31
} from '../interfaces' ;
31
32
import { getMD5Hash } from '../obfuscation' ;
32
33
import initPoller , { IPoller } from '../poller' ;
@@ -60,6 +61,7 @@ export type PrecomputedFlagsRequestParameters = {
60
61
interface EppoPrecomputedClientOptions {
61
62
precomputedFlagStore : IConfigurationStore < PrecomputedFlag > ;
62
63
precomputedBanditStore ?: IConfigurationStore < IObfuscatedPrecomputedBandit > ;
64
+ overridesStore ?: ISyncStore < Variation > ;
63
65
subject : Subject ;
64
66
banditActions ?: Record < FlagKey , Record < string , ContextAttributes > > ;
65
67
requestParameters ?: PrecomputedFlagsRequestParameters ;
@@ -81,10 +83,13 @@ export default class EppoPrecomputedClient {
81
83
private banditActions ?: Record < FlagKey , Record < string , ContextAttributes > > ;
82
84
private precomputedFlagStore : IConfigurationStore < PrecomputedFlag > ;
83
85
private precomputedBanditStore ?: IConfigurationStore < IObfuscatedPrecomputedBandit > ;
86
+ private overridesStore ?: ISyncStore < Variation > ;
84
87
85
88
public constructor ( options : EppoPrecomputedClientOptions ) {
86
89
this . precomputedFlagStore = options . precomputedFlagStore ;
87
90
this . precomputedBanditStore = options . precomputedBanditStore ;
91
+ this . overridesStore = options . overridesStore ;
92
+
88
93
const { subjectKey, subjectAttributes } = options . subject ;
89
94
this . subject = {
90
95
subjectKey,
@@ -199,6 +204,11 @@ export default class EppoPrecomputedClient {
199
204
) : T {
200
205
validateNotBlank ( flagKey , 'Invalid argument: flagKey cannot be blank' ) ;
201
206
207
+ const overrideVariation = this . overridesStore ?. get ( flagKey ) ;
208
+ if ( overrideVariation ) {
209
+ return valueTransformer ( overrideVariation . value ) ;
210
+ }
211
+
202
212
const precomputedFlag = this . getPrecomputedFlag ( flagKey ) ;
203
213
204
214
if ( precomputedFlag == null ) {
@@ -515,4 +525,12 @@ export default class EppoPrecomputedClient {
515
525
sdkLibVersion : LIB_VERSION ,
516
526
} ;
517
527
}
528
+
529
+ public setOverridesStore ( store : ISyncStore < Variation > ) : void {
530
+ this . overridesStore = store ;
531
+ }
532
+
533
+ public unsetOverridesStore ( ) : void {
534
+ this . overridesStore = undefined ;
535
+ }
518
536
}
0 commit comments