Skip to content

Commit d93679e

Browse files
authored
chore: Upgrade to [email protected] (#201)
* upgrade to common 4.15.1 * test for encoded custom subdomain in regular and precomputed clients * v3.15.0
1 parent 73ef99d commit d93679e

File tree

4 files changed

+180
-7
lines changed

4 files changed

+180
-7
lines changed

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",
3-
"version": "3.14.1",
3+
"version": "3.15.0",
44
"description": "Eppo SDK for client-side JavaScript applications",
55
"main": "dist/index.js",
66
"files": [
@@ -60,7 +60,7 @@
6060
"webpack-cli": "^6.0.1"
6161
},
6262
"dependencies": {
63-
"@eppo/js-client-sdk-common": "4.14.4"
63+
"@eppo/js-client-sdk-common": "4.15.1"
6464
},
6565
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
6666
}

src/index.spec.ts

Lines changed: 171 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232

3333
import { IClientConfig } from './i-client-config';
3434
import { ServingStoreUpdateStrategy } from './isolatable-hybrid.store';
35+
import { sdkVersion } from './sdk-data';
3536

3637
import {
3738
EppoPrecomputedJSClient,
@@ -48,6 +49,8 @@ import {
4849

4950
const { DEFAULT_POLL_INTERVAL_MS, POLL_JITTER_PCT } = constants;
5051

52+
const expectedSdkParams = `&sdkName=js-client-sdk&sdkVersion=${sdkVersion}`;
53+
5154
function md5Hash(input: string): string {
5255
return createHash('md5').update(input).digest('hex');
5356
}
@@ -641,6 +644,78 @@ describe('initialization options', () => {
641644
expect(callCount).toBe(1);
642645
});
643646

647+
describe('enhanced SDK token', () => {
648+
let urlsRequested: string[] = [];
649+
650+
afterEach(() => {
651+
urlsRequested = [];
652+
});
653+
654+
beforeEach(() => {
655+
global.fetch = jest.fn((url) => {
656+
urlsRequested.push(url);
657+
return Promise.resolve({
658+
ok: true,
659+
status: 200,
660+
json: () => Promise.resolve(mockConfigResponse),
661+
});
662+
}) as jest.Mock;
663+
});
664+
665+
it('uses the provided subdomain', async () => {
666+
await init({
667+
apiKey: 'zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA==', // subdomain=experiment
668+
assignmentLogger: mockLogger,
669+
});
670+
expect(urlsRequested).toHaveLength(1);
671+
expect(urlsRequested[0]).toEqual(
672+
'https://experiment.fscdn.eppo.cloud/api/flag-config/v1/config?apiKey=zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA%3D%3D' +
673+
expectedSdkParams,
674+
);
675+
});
676+
677+
it('uses the provided custom relative baseUrl', async () => {
678+
await init({
679+
apiKey: 'zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA==',
680+
baseUrl: '//custom-base-url.com',
681+
assignmentLogger: mockLogger,
682+
});
683+
684+
expect(urlsRequested).toHaveLength(1);
685+
expect(urlsRequested[0]).toEqual(
686+
'//custom-base-url.com/flag-config/v1/config?apiKey=zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA%3D%3D' +
687+
expectedSdkParams,
688+
);
689+
});
690+
691+
it('uses the provided custom baseUrl and prepends https', async () => {
692+
await init({
693+
apiKey: 'zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA==',
694+
baseUrl: 'custom-base-url.com',
695+
assignmentLogger: mockLogger,
696+
});
697+
698+
expect(urlsRequested).toHaveLength(1);
699+
expect(urlsRequested[0]).toEqual(
700+
'https://custom-base-url.com/flag-config/v1/config?apiKey=zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA%3D%3D' +
701+
expectedSdkParams,
702+
);
703+
});
704+
705+
it('falls back to the default url', async () => {
706+
await init({
707+
apiKey: 'old style key',
708+
assignmentLogger: mockLogger,
709+
});
710+
711+
expect(urlsRequested).toHaveLength(1);
712+
expect(urlsRequested[0]).toEqual(
713+
'https://fscdn.eppo.cloud/api/flag-config/v1/config?apiKey=old+style+key' +
714+
expectedSdkParams,
715+
);
716+
});
717+
});
718+
644719
it('force reinitialize', async () => {
645720
let callCount = 0;
646721

@@ -1172,7 +1247,7 @@ describe('initialization options', () => {
11721247
async entries() {
11731248
return entriesPromise.promise;
11741249
},
1175-
async setEntries(entries) {
1250+
async setEntries() {
11761251
// pass
11771252
},
11781253
};
@@ -1337,6 +1412,101 @@ describe('EppoPrecomputedJSClient E2E test', () => {
13371412
subject: 'test-subject',
13381413
});
13391414
});
1415+
1416+
describe('with an enhanced SDK token', () => {
1417+
let urlsRequested: string[] = [];
1418+
1419+
afterEach(() => {
1420+
urlsRequested = [];
1421+
});
1422+
1423+
beforeEach(() => {
1424+
EppoPrecomputedJSClient.initialized = false;
1425+
1426+
global.fetch = jest.fn((url) => {
1427+
urlsRequested.push(url);
1428+
const precomputedConfiguration = readMockPrecomputedResponse(MOCK_PRECOMPUTED_WIRE_FILE);
1429+
const precomputedResponse: IPrecomputedConfigurationResponse = JSON.parse(
1430+
JSON.parse(precomputedConfiguration).precomputed.response,
1431+
);
1432+
return Promise.resolve({
1433+
ok: true,
1434+
status: 200,
1435+
json: () => Promise.resolve(precomputedResponse),
1436+
});
1437+
}) as jest.Mock;
1438+
});
1439+
1440+
it('uses the provided subdomain', async () => {
1441+
await precomputedInit({
1442+
apiKey: 'zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA==', // subdomain=experiment
1443+
assignmentLogger: mockLogger,
1444+
precompute: {
1445+
subjectKey: 'test-subject',
1446+
subjectAttributes: { attr1: 'value1' },
1447+
},
1448+
});
1449+
1450+
expect(urlsRequested).toHaveLength(1);
1451+
expect(urlsRequested[0]).toEqual(
1452+
'https://experiment.fs-edge-assignment.eppo.cloud/assignments?apiKey=zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA%3D%3D' +
1453+
expectedSdkParams,
1454+
);
1455+
});
1456+
1457+
it('uses the provided custom relative baseUrl', async () => {
1458+
await precomputedInit({
1459+
apiKey: 'zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA==', // subdomain=experiment
1460+
baseUrl: '//custom-base-url.com',
1461+
assignmentLogger: mockLogger,
1462+
precompute: {
1463+
subjectKey: 'test-subject',
1464+
subjectAttributes: { attr1: 'value1' },
1465+
},
1466+
});
1467+
1468+
expect(urlsRequested).toHaveLength(1);
1469+
expect(urlsRequested[0]).toEqual(
1470+
'//custom-base-url.com/assignments?apiKey=zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA%3D%3D' +
1471+
expectedSdkParams,
1472+
);
1473+
});
1474+
1475+
it('uses the provided custom baseUrl and prepends https', async () => {
1476+
await precomputedInit({
1477+
apiKey: 'zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA==', // subdomain=experiment
1478+
baseUrl: '//custom-base-url.com',
1479+
assignmentLogger: mockLogger,
1480+
precompute: {
1481+
subjectKey: 'test-subject',
1482+
subjectAttributes: { attr1: 'value1' },
1483+
},
1484+
});
1485+
1486+
expect(urlsRequested).toHaveLength(1);
1487+
expect(urlsRequested[0]).toEqual(
1488+
'//custom-base-url.com/assignments?apiKey=zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA%3D%3D' +
1489+
expectedSdkParams,
1490+
);
1491+
});
1492+
1493+
it('falls back to the default url', async () => {
1494+
await precomputedInit({
1495+
apiKey: 'Y3M9ZXhwZXJpbWVudA==', // no encoded subdomain
1496+
assignmentLogger: mockLogger,
1497+
precompute: {
1498+
subjectKey: 'test-subject',
1499+
subjectAttributes: { attr1: 'value1' },
1500+
},
1501+
});
1502+
1503+
expect(urlsRequested).toHaveLength(1);
1504+
expect(urlsRequested[0]).toEqual(
1505+
'https://fs-edge-assignment.eppo.cloud/assignments?apiKey=Y3M9ZXhwZXJpbWVudA%3D%3D' +
1506+
expectedSdkParams,
1507+
);
1508+
});
1509+
});
13401510
});
13411511

13421512
describe('offlinePrecomputedInit', () => {

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ const flagConfigurationStore = configurationStorageFactory({
100100
const memoryOnlyPrecomputedFlagsStore = precomputedFlagsStorageFactory();
101101
const memoryOnlyPrecomputedBanditsStore = precomputedBanditStoreFactory();
102102

103+
/**
104+
* @internal
105+
*/
103106
export const NO_OP_EVENT_DISPATCHER: EventDispatcher = {
104107
// eslint-disable-next-line @typescript-eslint/no-empty-function
105108
attachContext: () => {},

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.6.3.tgz#f13c7c205915eb91ae54c557f5e92bddd8be0e83"
381381
integrity sha512-4B4OijXeVNOPZlYA2oEwWOTkzyltLao+xbotHQeqN++Rv27Y6s818+n2Qkp8q+Fxhn0t/5lA5X1Mxktud8eayQ==
382382

383-
"@eppo/js-client-sdk-common@4.14.4":
384-
version "4.14.4"
385-
resolved "https://registry.yarnpkg.com/@eppo/js-client-sdk-common/-/js-client-sdk-common-4.14.4.tgz#fd59daa3b9ae385756476bcc1022a53ffcfd8188"
386-
integrity sha512-12JKsYLu+WICH1t9NEgWoxTYc/MyFnZAHhcBJwfcaG0tPIbPfgG9VBT8yTUgBLG8cYZBmDVk7R7SzMGc3vD2eg==
383+
"@eppo/js-client-sdk-common@4.15.1":
384+
version "4.15.1"
385+
resolved "https://registry.yarnpkg.com/@eppo/js-client-sdk-common/-/js-client-sdk-common-4.15.1.tgz#bf2d602b1462eb156224edd73f734a3c99267816"
386+
integrity sha512-ZVyczDCfAMAnuUlfE293b6h2wfDOcZnfxXHS52r0OU9GktdTYD9EuC3Arpzw4JeTgzV1vW6iTzoz5HDJHwZz6A==
387387
dependencies:
388388
buffer "npm:@eppo/[email protected]"
389389
js-base64 "^3.7.7"

0 commit comments

Comments
 (0)