Skip to content

Commit d366925

Browse files
committed
Include salt in convenience method for setting precomputed flag store
1 parent a169e29 commit d366925

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

src/client/eppo-precomputed-client.spec.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,12 @@ describe('EppoPrecomputedClient E2E test', () => {
651651
});
652652

653653
const client = new EppoPrecomputedClient(storage, true);
654-
client.setDecodedFlagKeySalt(salt);
654+
client.setSubjectSaltAndPrecomputedFlagStore(
655+
'test-subject',
656+
{ attr1: 'value1' },
657+
encodeBase64(salt),
658+
storage,
659+
);
655660

656661
expect(client.getStringAssignment(precomputedFlagKey, 'default')).toBe(
657662
mockPrecomputedFlag.variationValue,
@@ -688,7 +693,12 @@ describe('EppoPrecomputedClient E2E test', () => {
688693
});
689694

690695
it('returns default value and does not log when store is not initialized', () => {
691-
client.setSubjectAndPrecomputedFlagStore('test-subject', {}, store);
696+
client.setSubjectSaltAndPrecomputedFlagStore(
697+
'test-subject',
698+
{},
699+
encodeBase64('sodium-chloride'),
700+
store,
701+
);
692702
expect(client.getStringAssignment('test-flag', 'default')).toBe('default');
693703
expect(td.explain(mockLogger.logAssignment).callCount).toEqual(0);
694704
});
@@ -708,7 +718,12 @@ describe('EppoPrecomputedClient E2E test', () => {
708718
extraLogging: {},
709719
},
710720
});
711-
client.setSubjectAndPrecomputedFlagStore(subjectKey, subjectAttributes, store);
721+
client.setSubjectSaltAndPrecomputedFlagStore(
722+
subjectKey,
723+
subjectAttributes,
724+
encodeBase64('sodium-chloride'),
725+
store,
726+
);
712727
expect(client.getStringAssignment('test-flag', 'default')).toBe('test-value');
713728

714729
expect(td.explain(mockLogger.logAssignment).callCount).toEqual(1);

src/client/eppo-precomputed-client.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { decodePrecomputedFlag } from '../decoding';
1717
import { FlagEvaluationWithoutDetails } from '../evaluator';
1818
import FetchHttpClient from '../http-client';
1919
import { DecodedPrecomputedFlag, PrecomputedFlag, VariationType } from '../interfaces';
20-
import { getMD5Hash } from '../obfuscation';
20+
import { decodeBase64, getMD5Hash } from '../obfuscation';
2121
import initPoller, { IPoller } from '../poller';
2222
import PrecomputedRequestor from '../precomputed-requestor';
2323
import { Attributes } from '../types';
@@ -64,20 +64,20 @@ export default class EppoPrecomputedClient {
6464
this.isObfuscated = isObfuscated;
6565
}
6666

67-
public setDecodedFlagKeySalt(salt: string) {
67+
private setDecodedFlagKeySalt(salt: string) {
6868
this.decodedFlagKeySalt = salt;
6969
}
7070

71-
public setPrecomputedFlagsRequestParameters(parameters: PrecomputedFlagsRequestParameters) {
71+
private setPrecomputedFlagsRequestParameters(parameters: PrecomputedFlagsRequestParameters) {
7272
this.precomputedFlagsRequestParameters = parameters;
7373
}
7474

75-
public setSubjectData(subjectKey: string, subjectAttributes: Attributes) {
75+
private setSubjectData(subjectKey: string, subjectAttributes: Attributes) {
7676
this.subjectKey = subjectKey;
7777
this.subjectAttributes = subjectAttributes;
7878
}
7979

80-
// Convenience method that combines both since they are expected to be set together
80+
// Convenience method that combines setters we need to make assignments work
8181
public setSubjectAndPrecomputedFlagsRequestParameters(
8282
parameters: PrecomputedFlagsRequestParameters,
8383
) {
@@ -128,8 +128,8 @@ export default class EppoPrecomputedClient {
128128

129129
// A callback to capture the salt and subject information
130130
precomputedRequestor.onPrecomputedResponse = (responseData) => {
131-
if (responseData.decodedSalt) {
132-
this.setDecodedFlagKeySalt(responseData.decodedSalt);
131+
if (responseData.salt) {
132+
this.setDecodedFlagKeySalt(decodeBase64(responseData.salt));
133133
}
134134
if (responseData.subjectKey && responseData.subjectAttributes) {
135135
this.setSubjectData(responseData.subjectKey, responseData.subjectAttributes);
@@ -160,19 +160,21 @@ export default class EppoPrecomputedClient {
160160
}
161161
}
162162

163-
public setPrecomputedFlagStore(store: IConfigurationStore<PrecomputedFlag>) {
163+
private setPrecomputedFlagStore(store: IConfigurationStore<PrecomputedFlag>) {
164164
this.requestPoller?.stop();
165165
this.precomputedFlagStore = store;
166166
}
167167

168-
// Convenience method that combines both since they are expected to be set together
169-
public setSubjectAndPrecomputedFlagStore(
168+
// Convenience method that combines setters we need to make assignments work
169+
public setSubjectSaltAndPrecomputedFlagStore(
170170
subjectKey: string,
171171
subjectAttributes: Attributes,
172+
salt: string,
172173
precomputedFlagStore: IConfigurationStore<PrecomputedFlag>,
173174
) {
174175
this.setPrecomputedFlagStore(precomputedFlagStore);
175176
this.setSubjectData(subjectKey, subjectAttributes);
177+
this.setDecodedFlagKeySalt(decodeBase64(salt));
176178
}
177179

178180
private getPrecomputedAssignment<T>(

src/precomputed-requestor.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import { IConfigurationStore } from './configuration-store/configuration-store';
22
import { hydrateConfigurationStore } from './configuration-store/configuration-store-utils';
33
import { IHttpClient } from './http-client';
44
import { PrecomputedFlag, UNKNOWN_ENVIRONMENT_NAME } from './interfaces';
5-
import { decodeBase64 } from './obfuscation';
65
import { Attributes } from './types';
76

87
export interface PrecomputedResponseData {
9-
decodedSalt?: string;
8+
salt?: string;
109
subjectKey?: string;
1110
subjectAttributes?: Attributes;
1211
}
@@ -30,7 +29,7 @@ export default class PrecomputedFlagRequestor {
3029

3130
if (this.onPrecomputedResponse) {
3231
this.onPrecomputedResponse({
33-
decodedSalt: precomputedResponse?.salt ? decodeBase64(precomputedResponse.salt) : undefined,
32+
salt: precomputedResponse?.salt,
3433
subjectKey: this.subjectKey,
3534
subjectAttributes: this.subjectAttributes,
3635
});

0 commit comments

Comments
 (0)