Skip to content

Commit 7fd5a4a

Browse files
authored
FF-1749: JS SDK Common UFC update (#45)
1 parent 248478e commit 7fd5a4a

36 files changed

+2820
-2217
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ yarn-error.log
1010

1111
test/data
1212
.vscode/settings.json
13+
14+
.DS_Store

Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ test-data:
3535
rm -rf $(testDataDir)
3636
mkdir -p $(tempDir)
3737
git clone -b ${branchName} --depth 1 --single-branch ${githubRepoLink} ${gitDataDir}
38-
cp ${gitDataDir}rac-experiments-v3.json ${testDataDir}
39-
cp ${gitDataDir}rac-experiments-v3-obfuscated.json ${testDataDir}
40-
cp -r ${gitDataDir}assignment-v2 ${testDataDir}
41-
cp -r ${gitDataDir}assignment-v2-holdouts/. ${testDataDir}assignment-v2
38+
cp -r ${gitDataDir}ufc ${testDataDir}
4239
rm -rf ${tempDir}
4340

4441
## prepare

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk-common",
3-
"version": "2.3.0",
3+
"version": "3.0.0",
44
"description": "Eppo SDK for client-side JavaScript applications (base for both web and react native)",
55
"main": "dist/index.js",
66
"files": [
@@ -25,7 +25,7 @@
2525
"typecheck": "tsc",
2626
"test": "yarn test:unit",
2727
"test:unit": "NODE_ENV=test jest '.*\\.spec\\.ts'",
28-
"obfuscate-mock-rac": "ts-node test/writeObfuscatedMockRac"
28+
"obfuscate-mock-ufc": "ts-node test/writeObfuscatedMockUFC"
2929
},
3030
"jsdelivr": "dist/eppo-sdk.js",
3131
"repository": {

src/assignment-cache.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { EppoValue } from './eppo_value';
21
import { LRUCache } from './lru-cache';
2+
import { getMD5Hash } from './obfuscation';
33

44
export interface AssignmentCacheKey {
55
subjectKey: string;
66
flagKey: string;
77
allocationKey: string;
8-
variationValue: EppoValue;
8+
variationKey: string;
99
}
1010

1111
export interface Cacheable {
@@ -31,15 +31,15 @@ export abstract class AssignmentCache<T extends Cacheable> {
3131
// the subject has been assigned to a different variation
3232
// than was previously logged.
3333
// in this case we need to log the assignment again.
34-
if (this.cache.get(this.getCacheKey(key)) !== key.variationValue.toHashedString()) {
34+
if (this.cache.get(this.getCacheKey(key)) !== getMD5Hash(key.variationKey)) {
3535
return false;
3636
}
3737

3838
return true;
3939
}
4040

4141
setLastLoggedAssignment(key: AssignmentCacheKey): void {
42-
this.cache.set(this.getCacheKey(key), key.variationValue.toHashedString());
42+
this.cache.set(this.getCacheKey(key), getMD5Hash(key.variationKey));
4343
}
4444

4545
protected getCacheKey({ subjectKey, flagKey, allocationKey }: AssignmentCacheKey): string {

src/assignment-logger.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { IAssignmentEvent } from './assignment-logger';
2+
3+
describe('IAssignmentEvent', () => {
4+
it('should allow adding arbitrary fields', () => {
5+
const event: IAssignmentEvent = {
6+
allocation: 'allocation_123',
7+
experiment: 'experiment_123',
8+
featureFlag: 'feature_flag_123',
9+
variation: 'variation_123',
10+
subject: 'subject_123',
11+
timestamp: new Date().toISOString(),
12+
subjectAttributes: { age: 25, country: 'USA' },
13+
holdoutKey: 'holdout_key_123',
14+
};
15+
16+
expect(event.holdoutKey).toBe('holdout_key_123');
17+
});
18+
});

src/assignment-logger.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ export type NullableHoldoutVariationType = HoldoutVariationEnum | null;
99
* Holds data about the variation a subject was assigned to.
1010
* @public
1111
*/
12+
1213
export interface IAssignmentEvent {
1314
/**
1415
* An Eppo allocation key
1516
*/
16-
allocation: string;
17+
allocation: string | null;
1718

1819
/**
1920
* An Eppo experiment key
2021
*/
21-
experiment: string;
22+
experiment: string | null;
2223

2324
/**
2425
* An Eppo feature flag key
@@ -28,7 +29,7 @@ export interface IAssignmentEvent {
2829
/**
2930
* The assigned variation
3031
*/
31-
variation: string;
32+
variation: string | null;
3233

3334
/**
3435
* The entity or user that was assigned to a variation
@@ -40,18 +41,11 @@ export interface IAssignmentEvent {
4041
*/
4142
timestamp: string;
4243

43-
/**
44-
* An Eppo holdout key
45-
*/
46-
holdout: string | null;
47-
48-
/**
49-
* The Eppo holdout variation for the assigned variation
50-
*/
51-
holdoutVariation: NullableHoldoutVariationType;
52-
5344
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5445
subjectAttributes: Record<string, any>;
46+
[propName: string]: unknown;
47+
48+
metaData?: Record<string, unknown>;
5549
}
5650

5751
/**

0 commit comments

Comments
 (0)