Skip to content

Commit 9657396

Browse files
committed
latest with precomputed
1 parent 3db2205 commit 9657396

File tree

5 files changed

+49
-33
lines changed

5 files changed

+49
-33
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"webpack-cli": "^4.10.0"
6060
},
6161
"dependencies": {
62-
"@eppo/js-client-sdk-common": "^4.6.3"
62+
"@eppo/js-client-sdk-common": "^4.7.0-alpha.1"
6363
},
6464
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
6565
}

src/i-client-config.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { AttributeType, Flag, IAssignmentLogger, IAsyncStore } from '@eppo/js-client-sdk-common';
1+
import {
2+
AttributeType,
3+
ContextAttributes,
4+
Flag,
5+
IAssignmentLogger,
6+
IAsyncStore,
7+
} from '@eppo/js-client-sdk-common';
28
import { EventDispatcherConfig } from '@eppo/js-client-sdk-common/src/events/default-event-dispatcher';
39

410
import { ServingStoreUpdateStrategy } from './isolatable-hybrid.store';
@@ -76,7 +82,7 @@ export interface IPrecomputedClientConfig extends IBaseRequestConfig {
7682
/**
7783
* Subject attributes to use for precomputed flag assignments.
7884
*/
79-
subjectAttributes?: Record<string, AttributeType>;
85+
subjectAttributes?: ContextAttributes;
8086
}
8187

8288
/**

src/index.spec.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,11 @@ describe('getConfigUrl function', () => {
10631063
describe('EppoPrecomputedJSClient E2E test', () => {
10641064
let globalClient: EppoPrecomputedJSClient;
10651065
let mockLogger: IAssignmentLogger;
1066+
const stringFlagMD5 = '7724c9cf3eeb7e9478d4c5d45d523db0';
1067+
const booleanFlagMD5 = 'da342f2d2df9aa65fd422191c581d4dc';
1068+
const numericFlagMD5 = 'ea3957393f8c54d09bb0800186480bae';
1069+
const jsonFlagMD5 = '801c055015c6cf6710d486f099000fea';
1070+
const integerFlagMD5 = 'eb4caea3db4e58836bda9830ee098291';
10661071

10671072
beforeAll(async () => {
10681073
global.fetch = jest.fn(() => {
@@ -1077,43 +1082,44 @@ describe('EppoPrecomputedJSClient E2E test', () => {
10771082
name: 'Test',
10781083
},
10791084
flags: {
1080-
'string-flag': {
1081-
allocationKey: 'allocation-123',
1082-
variationKey: 'variation-123',
1085+
[stringFlagMD5]: {
1086+
flagKey: stringFlagMD5,
1087+
allocationKey: base64Encode('allocation-123'),
1088+
variationKey: base64Encode('variation-123'),
10831089
variationType: 'STRING',
1084-
variationValue: 'red',
1090+
variationValue: base64Encode('red'),
10851091
extraLogging: {},
10861092
doLog: true,
10871093
},
1088-
'boolean-flag': {
1089-
allocationKey: 'allocation-124',
1090-
variationKey: 'variation-124',
1094+
[booleanFlagMD5]: {
1095+
allocationKey: base64Encode('allocation-124'),
1096+
variationKey: base64Encode('variation-124'),
10911097
variationType: 'BOOLEAN',
1092-
variationValue: true,
1098+
variationValue: base64Encode('true'),
10931099
extraLogging: {},
10941100
doLog: true,
10951101
},
1096-
'numeric-flag': {
1097-
allocationKey: 'allocation-126',
1098-
variationKey: 'variation-126',
1102+
[numericFlagMD5]: {
1103+
allocationKey: base64Encode('allocation-126'),
1104+
variationKey: base64Encode('variation-126'),
10991105
variationType: 'NUMERIC',
1100-
variationValue: 3.14,
1106+
variationValue: base64Encode('3.14'),
11011107
extraLogging: {},
11021108
doLog: true,
11031109
},
1104-
'integer-flag': {
1105-
allocationKey: 'allocation-125',
1106-
variationKey: 'variation-125',
1110+
[integerFlagMD5]: {
1111+
allocationKey: base64Encode('allocation-125'),
1112+
variationKey: base64Encode('variation-125'),
11071113
variationType: 'INTEGER',
1108-
variationValue: 42,
1114+
variationValue: base64Encode('42'),
11091115
extraLogging: {},
11101116
doLog: true,
11111117
},
1112-
'json-flag': {
1113-
allocationKey: 'allocation-127',
1114-
variationKey: 'variation-127',
1118+
[jsonFlagMD5]: {
1119+
allocationKey: base64Encode('allocation-127'),
1120+
variationKey: base64Encode('variation-127'),
11151121
variationType: 'JSON',
1116-
variationValue: '{"key": "value", "number": 123}',
1122+
variationValue: base64Encode('{"key": "value", "number": 123}'),
11171123
extraLogging: {},
11181124
doLog: true,
11191125
},
@@ -1129,7 +1135,7 @@ describe('EppoPrecomputedJSClient E2E test', () => {
11291135
baseUrl: 'http://127.0.0.1:4000',
11301136
assignmentLogger: mockLogger,
11311137
subjectKey: 'test-subject',
1132-
subjectAttributes: { attr1: 'value1' },
1138+
subjectAttributes: { categoricalAttributes: { attr1: 'value1' }, numericAttributes: {} },
11331139
});
11341140
});
11351141

@@ -1205,7 +1211,7 @@ describe('EppoClient config', () => {
12051211
const retryManager = eventDispatcher['retryManager'];
12061212
const batchProcessor = eventDispatcher['batchProcessor'];
12071213
expect(eventDispatcher['deliveryIntervalMs']).toEqual(1);
1208-
expect(batchProcessor['batchSize']).toEqual(5);
1214+
expect(batchProcessor['batchSize']).toEqual(100);
12091215
expect(retryManager['config']['retryIntervalMs']).toEqual(2);
12101216
expect(retryManager['config']['maxRetryDelayMs']).toEqual(3);
12111217
expect(retryManager['config']['maxRetries']).toEqual(4);

src/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,9 +511,9 @@ export function getConfigUrl(apiKey: string, baseUrl?: string): URL {
511511
*/
512512
export class EppoPrecomputedJSClient extends EppoPrecomputedClient {
513513
// Use an empty memory-only configuration store
514-
public static instance: EppoPrecomputedJSClient = new EppoPrecomputedJSClient(
515-
memoryOnlyPrecomputedFlagsStore,
516-
);
514+
public static instance: EppoPrecomputedJSClient = new EppoPrecomputedJSClient({
515+
precomputedFlagStore: memoryOnlyPrecomputedFlagsStore,
516+
});
517517
public static initialized = false;
518518

519519
public getStringAssignment(flagKey: string, defaultValue: string): string {
@@ -564,7 +564,6 @@ export async function precomputedInit(
564564
const {
565565
apiKey,
566566
subjectKey,
567-
subjectAttributes = {},
568567
baseUrl,
569568
requestTimeoutMs,
570569
numInitialRequestRetries,
@@ -575,6 +574,11 @@ export async function precomputedInit(
575574
skipInitialRequest = false,
576575
} = config;
577576

577+
const subjectAttributes = config.subjectAttributes ?? {
578+
categoricalAttributes: {},
579+
numericAttributes: {},
580+
};
581+
578582
// Set up assignment logger and cache
579583
instance.setAssignmentLogger(config.assignmentLogger);
580584

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,10 @@
380380
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70"
381381
integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==
382382

383-
"@eppo/js-client-sdk-common@^4.6.3":
384-
version "4.6.3"
385-
resolved "https://registry.yarnpkg.com/@eppo/js-client-sdk-common/-/js-client-sdk-common-4.6.3.tgz#89267a1c247bc04725b7701cdfb573613c133ddc"
386-
integrity sha512-e2nSvzONjqUiAYUjBMIIk1jWuKPOmBl5AlbiNjsoJAd6dZKN1RWpTmy83hNk6ff/syjAEWTcplls2cU37VbyiQ==
383+
"@eppo/js-client-sdk-common@^4.7.0-alpha.1":
384+
version "4.7.0-alpha.1"
385+
resolved "https://registry.yarnpkg.com/@eppo/js-client-sdk-common/-/js-client-sdk-common-4.7.0-alpha.1.tgz#ff40526fb9f76ddbcff1264bbb26d8be38b3e25c"
386+
integrity sha512-36DF7TVtPkn7JcLrV5YBChp/9Wv0+0bKC32SWrs1ag5/TTyF4cgZYzf1TIsX9ykHvIQGHNPW4Kd3S+TRRVOZ0w==
387387
dependencies:
388388
buffer "npm:@eppo/[email protected]"
389389
js-base64 "^3.7.7"

0 commit comments

Comments
 (0)