Skip to content

Commit 2251bf5

Browse files
authored
feat: create EppoPrecomputedClient (#129)
* New interfaces for precomputed response * Fetch and store precomputed flags * Make hydrateConfigurationStore more reusable * Add a precomputed requestor test * Test format in response * Tests for the precomputed client * Comment for why eval details can be null * Comment clean up * tsc fixes * Fix more tests * Add to exports * Include logging for format * Fix tsc * Fix test * feat: precomputed assignment methods for supported types (#135) * Add methods for boolean, integer, numeric, and json types * Add tests for typed assignments * Remove eslint warnings * v4.3.1-alpha.0 * Adjust api endpoing for precomputed * Add PrecomputedFlag interface to export * Log format * Fix test * v4.3.1-alpha.1 * fix: post with http client (#137) * Add method for post * Change request to a post * Fix payload format * v4.3.1-alpha.2 * Fix tsc issue * v4.5.0
1 parent 0fae041 commit 2251bf5

21 files changed

+1471
-44
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.4.0",
3+
"version": "4.5.0",
44
"description": "Eppo SDK for client-side JavaScript applications (base for both web and react native)",
55
"main": "dist/index.js",
66
"files": [

src/api-endpoints.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import { BASE_URL as DEFAULT_BASE_URL, UFC_ENDPOINT, BANDIT_ENDPOINT } from './constants';
2-
import { IQueryParams } from './http-client';
1+
import {
2+
BASE_URL as DEFAULT_BASE_URL,
3+
UFC_ENDPOINT,
4+
BANDIT_ENDPOINT,
5+
PRECOMPUTED_FLAGS_ENDPOINT,
6+
} from './constants';
7+
import { IQueryParams, IQueryParamsWithSubject } from './http-client';
38

49
interface IApiEndpointsParams {
5-
queryParams?: IQueryParams;
10+
queryParams?: IQueryParams | IQueryParamsWithSubject;
611
baseUrl?: string;
712
}
813

@@ -27,4 +32,8 @@ export default class ApiEndpoints {
2732
banditParametersEndpoint(): URL {
2833
return this.endpoint(BANDIT_ENDPOINT);
2934
}
35+
36+
precomputedFlagsEndpoint(): URL {
37+
return this.endpoint(PRECOMPUTED_FLAGS_ENDPOINT);
38+
}
3039
}

src/assignment-logger.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IAssignmentEvent } from './assignment-logger';
22
import { AllocationEvaluationCode } from './flag-evaluation-details-builder';
3+
import { FormatEnum } from './interfaces';
34

45
describe('IAssignmentEvent', () => {
56
it('should allow adding arbitrary fields', () => {
@@ -11,6 +12,7 @@ describe('IAssignmentEvent', () => {
1112
subject: 'subject_123',
1213
timestamp: new Date().toISOString(),
1314
subjectAttributes: { age: 25, country: 'USA' },
15+
format: FormatEnum.SERVER,
1416
holdoutKey: 'holdout_key_123',
1517
evaluationDetails: {
1618
environmentName: 'Test',

src/assignment-logger.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,14 @@ export interface IAssignmentEvent {
5050
metaData?: Record<string, unknown>;
5151

5252
/**
53-
* The flag evaluation details
53+
* The format of the flag.
5454
*/
55-
evaluationDetails: IFlagEvaluationDetails;
55+
format: string;
56+
57+
/**
58+
* The flag evaluation details. Null if the flag was precomputed.
59+
*/
60+
evaluationDetails: IFlagEvaluationDetails | null;
5661
}
5762

5863
/**

src/client/eppo-client.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,13 @@ export default class EppoClient {
867867
'FLAG_UNRECOGNIZED_OR_DISABLED',
868868
`Unrecognized or disabled flag: ${flagKey}`,
869869
);
870-
return noneResult(flagKey, subjectKey, subjectAttributes, flagEvaluationDetails);
870+
return noneResult(
871+
flagKey,
872+
subjectKey,
873+
subjectAttributes,
874+
flagEvaluationDetails,
875+
configDetails.configFormat,
876+
);
871877
}
872878

873879
if (!checkTypeMatch(expectedVariationType, flag.variationType)) {
@@ -877,7 +883,13 @@ export default class EppoClient {
877883
'TYPE_MISMATCH',
878884
errorMessage,
879885
);
880-
return noneResult(flagKey, subjectKey, subjectAttributes, flagEvaluationDetails);
886+
return noneResult(
887+
flagKey,
888+
subjectKey,
889+
subjectAttributes,
890+
flagEvaluationDetails,
891+
configDetails.configFormat,
892+
);
881893
}
882894
throw new TypeError(errorMessage);
883895
}
@@ -889,7 +901,13 @@ export default class EppoClient {
889901
'FLAG_UNRECOGNIZED_OR_DISABLED',
890902
`Unrecognized or disabled flag: ${flagKey}`,
891903
);
892-
return noneResult(flagKey, subjectKey, subjectAttributes, flagEvaluationDetails);
904+
return noneResult(
905+
flagKey,
906+
subjectKey,
907+
subjectAttributes,
908+
flagEvaluationDetails,
909+
configDetails.configFormat,
910+
);
893911
}
894912

895913
const result = this.evaluator.evaluateFlag(
@@ -937,9 +955,8 @@ export default class EppoClient {
937955
return {
938956
configFetchedAt: this.flagConfigurationStore.getConfigFetchedAt() ?? '',
939957
configPublishedAt: this.flagConfigurationStore.getConfigPublishedAt() ?? '',
940-
configEnvironment: this.flagConfigurationStore.getEnvironment() ?? {
941-
name: '',
942-
},
958+
configEnvironment: this.flagConfigurationStore.getEnvironment() ?? { name: '' },
959+
configFormat: this.flagConfigurationStore.getFormat() ?? '',
943960
};
944961
}
945962

@@ -1058,12 +1075,13 @@ export default class EppoClient {
10581075
}
10591076

10601077
private maybeLogAssignment(result: FlagEvaluation) {
1061-
const { flagKey, subjectKey, allocationKey, subjectAttributes, variation } = result;
1078+
const { flagKey, format, subjectKey, allocationKey, subjectAttributes, variation } = result;
10621079
const event: IAssignmentEvent = {
10631080
...(result.extraLogging ?? {}),
10641081
allocation: allocationKey ?? null,
10651082
experiment: allocationKey ? `${flagKey}-${allocationKey}` : null,
10661083
featureFlag: flagKey,
1084+
format,
10671085
variation: variation?.key ?? null,
10681086
subject: subjectKey,
10691087
timestamp: new Date().toISOString(),

0 commit comments

Comments
 (0)