Skip to content

Commit 0648040

Browse files
committed
fix: Update configuration stores in ConfigurationRequestor when they are changed on the client (#257)
* reset config stores in the config requestor when set on the client * tests * v4.14.4
1 parent 6561a4f commit 0648040

File tree

3 files changed

+69
-9
lines changed

3 files changed

+69
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk-common",
3-
"version": "4.14.3",
3+
"version": "4.14.4",
44
"description": "Common library for Eppo JavaScript SDKs (web, react native, and node)",
55
"main": "dist/index.js",
66
"files": [

src/client/eppo-client.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,6 @@ export default class EppoClient {
270270
this.eventDispatcher?.attachContext(key, value);
271271
}
272272

273-
// noinspection JSUnusedGlobalSymbols
274-
setBanditModelConfigurationStore(
275-
banditModelConfigurationStore: IConfigurationStore<BanditParameters>,
276-
) {
277-
this.banditModelConfigurationStore = banditModelConfigurationStore;
278-
}
279-
280273
// noinspection JSUnusedGlobalSymbols
281274
/**
282275
* Setting this value will have no side effects other than triggering a warning when the actual

src/configuration-requestor.spec.ts

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import FetchHttpClient, {
1616
IUniversalFlagConfigResponse,
1717
} from './http-client';
1818
import { StoreBackedConfiguration } from './i-configuration';
19-
import { BanditParameters, BanditVariation, Flag } from './interfaces';
19+
import { BanditParameters, BanditVariation, Flag, VariationType } from './interfaces';
2020

2121
describe('ConfigurationRequestor', () => {
2222
let flagStore: IConfigurationStore<Flag>;
@@ -588,5 +588,72 @@ describe('ConfigurationRequestor', () => {
588588
expect(fetchSpy.mock.calls.length).toBe(1);
589589
});
590590
});
591+
592+
describe('IConfigurationStore updates', () => {
593+
it('should update configuration when stores are changed', async () => {
594+
// Create new stores
595+
const newFlagStore = new MemoryOnlyConfigurationStore<Flag>();
596+
const newBanditVariationStore = new MemoryOnlyConfigurationStore<BanditVariation[]>();
597+
const newBanditModelStore = new MemoryOnlyConfigurationStore<BanditParameters>();
598+
599+
// Add a test flag to the new flag store
600+
await newFlagStore.setEntries({
601+
'test-flag': {
602+
key: 'test-flag',
603+
enabled: true,
604+
variationType: VariationType.STRING,
605+
variations: {
606+
control: { key: 'control', value: 'control-value' },
607+
treatment: { key: 'treatment', value: 'treatment-value' },
608+
},
609+
allocations: [
610+
{
611+
key: 'allocation-1',
612+
rules: [],
613+
splits: [
614+
{
615+
shards: [{ salt: '', ranges: [{ start: 0, end: 10000 }] }],
616+
variationKey: 'treatment',
617+
},
618+
],
619+
doLog: true,
620+
},
621+
],
622+
totalShards: 10000,
623+
},
624+
});
625+
626+
await newBanditModelStore.setEntries({
627+
'test-bandit': {
628+
banditKey: 'test-bandt',
629+
modelVersion: 'v123',
630+
modelName: 'falcon',
631+
modelData: {
632+
coefficients: {},
633+
gamma: 0,
634+
defaultActionScore: 0,
635+
actionProbabilityFloor: 0,
636+
},
637+
},
638+
});
639+
640+
// Get the configuration and verify it has the test flag
641+
const initialConfig = configurationRequestor.getConfiguration();
642+
expect(initialConfig.getFlagKeys()).toEqual([]);
643+
expect(Object.keys(initialConfig.getBandits())).toEqual([]);
644+
645+
// Update the stores
646+
configurationRequestor.setConfigurationStores(
647+
newFlagStore,
648+
newBanditVariationStore,
649+
newBanditModelStore,
650+
);
651+
652+
// Get the configuration and verify it has the test flag
653+
const config = configurationRequestor.getConfiguration();
654+
expect(config.getFlagKeys()).toEqual(['test-flag']);
655+
expect(Object.keys(config.getBandits())).toEqual(['test-bandit']);
656+
});
657+
});
591658
});
592659
});

0 commit comments

Comments
 (0)