@@ -18,7 +18,7 @@ import {
18
18
MAX_EVENT_QUEUE_SIZE ,
19
19
PRECOMPUTED_BASE_URL ,
20
20
} from '../constants' ;
21
- import { decodePrecomputedFlag } from '../decoding' ;
21
+ import { decodePrecomputedBandit , decodePrecomputedFlag } from '../decoding' ;
22
22
import { FlagEvaluationWithoutDetails } from '../evaluator' ;
23
23
import FetchHttpClient from '../http-client' ;
24
24
import {
@@ -307,7 +307,7 @@ export default class EppoPrecomputedClient {
307
307
) ;
308
308
}
309
309
310
- getBanditAction (
310
+ public getBanditAction (
311
311
flagKey : string ,
312
312
defaultValue : string ,
313
313
) : Omit < IAssignmentDetails < string > , 'evaluationDetails' > {
@@ -318,6 +318,8 @@ export default class EppoPrecomputedClient {
318
318
return { variation : defaultValue , action : null } ;
319
319
}
320
320
321
+ const assignedVariation = this . getStringAssignment ( flagKey , defaultValue ) ;
322
+
321
323
const banditEvent : IBanditEvent = {
322
324
timestamp : new Date ( ) . toISOString ( ) ,
323
325
featureFlag : flagKey ,
@@ -341,7 +343,7 @@ export default class EppoPrecomputedClient {
341
343
logger . error ( `${ loggerPrefix } Error logging bandit action: ${ error } ` ) ;
342
344
}
343
345
344
- return { variation : defaultValue , action : banditEvent . action } ;
346
+ return { variation : assignedVariation , action : banditEvent . action } ;
345
347
}
346
348
347
349
private getPrecomputedFlag ( flagKey : string ) : DecodedPrecomputedFlag | null {
@@ -358,13 +360,17 @@ export default class EppoPrecomputedClient {
358
360
}
359
361
360
362
private getPrecomputedBandit ( banditKey : string ) : IPrecomputedBandit | null {
361
- return this . getObfuscatedPrecomputedBandit ( banditKey ) ;
363
+ const obfuscatedBandit = this . getObfuscatedPrecomputedBandit ( banditKey ) ;
364
+ return obfuscatedBandit ? decodePrecomputedBandit ( obfuscatedBandit ) : null ;
362
365
}
363
366
364
367
private getObfuscatedPrecomputedBandit ( banditKey : string ) : IObfuscatedPrecomputedBandit | null {
365
368
const salt = this . precomputedBanditStore ?. salt ;
366
369
const saltedAndHashedBanditKey = getMD5Hash ( banditKey , salt ) ;
367
- return this . precomputedBanditStore ?. get ( saltedAndHashedBanditKey ) ?? null ;
370
+ const precomputedBandit : IObfuscatedPrecomputedBandit | null = this . precomputedBanditStore ?. get (
371
+ saltedAndHashedBanditKey ,
372
+ ) as IObfuscatedPrecomputedBandit ;
373
+ return precomputedBandit ?? null ;
368
374
}
369
375
370
376
public isInitialized ( ) {
0 commit comments