Skip to content

Commit 2e5d502

Browse files
Merge branch 'SDKS-8407_baseline' into rename_dist_folders
2 parents 38469cf + 6325b9e commit 2e5d502

File tree

9 files changed

+324
-103
lines changed

9 files changed

+324
-103
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- Added support for targeting rules based on large segments for browsers.
33
- Added `factory.destroy()` method, which invokes the `destroy` method of all clients created by the factory.
44
- Updated @splitsoftware/splitio-commons package to version 2.0.0 that includes major updates and updated some transitive dependencies for vulnerability fixes.
5+
- Bugfixing - Removed an overloaded `client` method in the `SplitIO.ISDK` interface that accepted a key and trafficType parameters. This interface corresponds to the SDK factory instance in NodeJS, which, unlike `SplitIO.IBrowserSDK` for the Browser, does not handle multiple client instances based on keys or traffic types.
56
- BREAKING CHANGES:
67
- Renamed distribution folders from `/lib` to `/cjs` for CommonJS build, and `/es` to `/esm` for EcmaScript Modules build.
78

package-lock.json

Lines changed: 213 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splitsoftware/splitio",
3-
"version": "10.28.1-rc.2",
3+
"version": "10.28.1-rc.4",
44
"description": "Split SDK",
55
"files": [
66
"README.md",
@@ -40,7 +40,7 @@
4040
"node": ">=6"
4141
},
4242
"dependencies": {
43-
"@splitsoftware/splitio-commons": "1.17.1-rc.1",
43+
"@splitsoftware/splitio-commons": "1.17.1-rc.4",
4444
"@types/google.analytics": "0.0.40",
4545
"@types/ioredis": "^4.28.0",
4646
"bloom-filters": "^3.0.0",

src/__tests__/browserSuites/ready-promise.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ export default function readyPromiseAssertions(fetchMock, assert) {
561561
});
562562
}, 0);
563563
});
564-
}, fromSecondsToMillis(0.2));
564+
}, fromSecondsToMillis(0.25));
565565

566566
}, 'Validate that warning messages are properly sent');
567567

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { SplitFactory as SplitFactorySS } from '../../factory/node';
2+
import { SplitFactory as SplitFactoryCS } from '../../factory/browser';
3+
4+
// Tests should finish without dangling timers or requests
5+
export default function (settings, fetchMock, t) {
6+
7+
t.test('Server-side', async (assert) => {
8+
let splitio;
9+
10+
for (let i = 0; i < 100; i++) {
11+
splitio = SplitFactorySS({
12+
core: {
13+
authorizationKey: 'fake-token-' + i,
14+
},
15+
urls: {
16+
sdk: 'https://not-called/api',
17+
events: 'https://not-called/api',
18+
auth: 'https://not-called/api',
19+
}
20+
}, (modules) => {
21+
modules.lazyInit = true;
22+
});
23+
24+
const manager = splitio.manager();
25+
assert.deepEqual(manager.names(), [], 'We should not have done any request yet');
26+
27+
const client = splitio.client();
28+
assert.equal(client.getTreatment('user-1', 'split_test'), 'control', 'We should get control');
29+
assert.equal(client.track('user-1', 'user', 'my_event'), true, 'We should track the event');
30+
}
31+
32+
fetchMock.getOnce('https://not-called/api/splitChanges?s=1.1&since=-1', { status: 200, body: { splits: [], since: -1, till: 1457552620999 } });
33+
fetchMock.getOnce('https://not-called/api/splitChanges?s=1.1&since=1457552620999', { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } });
34+
fetchMock.postOnce('https://not-called/api/testImpressions/bulk', 200);
35+
fetchMock.postOnce('https://not-called/api/events/bulk', 200);
36+
37+
splitio.init();
38+
await splitio.client().ready();
39+
assert.true(splitio.client().__getStatus().isReady, 'Split SDK is ready');
40+
await splitio.destroy();
41+
42+
assert.end();
43+
});
44+
45+
t.test('Client-side', async (assert) => {
46+
let splitio;
47+
48+
for (let i = 0; i < 100; i++) {
49+
splitio = SplitFactoryCS({
50+
core: {
51+
authorizationKey: 'fake-token-' + i,
52+
key: 'user-' + i,
53+
},
54+
urls: {
55+
sdk: 'https://not-called/api',
56+
events: 'https://not-called/api',
57+
auth: 'https://not-called/api',
58+
}
59+
}, (modules) => {
60+
modules.lazyInit = true;
61+
});
62+
63+
const manager = splitio.manager();
64+
assert.deepEqual(manager.names(), [], 'We should not have done any request yet');
65+
66+
const client = splitio.client();
67+
assert.equal(client.getTreatment('split_test'), 'control', 'We should get control');
68+
assert.equal(client.track('user', 'my_event'), true, 'We should track the event');
69+
70+
const otherClient = splitio.client('other-user');
71+
assert.equal(otherClient.getTreatment('split_test'), 'control', 'We should get control');
72+
assert.equal(otherClient.track('user', 'my_event'), true, 'We should track the event');
73+
}
74+
75+
fetchMock.getOnce('https://not-called/api/splitChanges?s=1.2&since=-1', { status: 200, body: { splits: [], since: -1, till: 1457552620999 } });
76+
fetchMock.getOnce('https://not-called/api/splitChanges?s=1.2&since=1457552620999', { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } });
77+
fetchMock.getOnce('https://not-called/api/memberships/user-99', { status: 200, body: {} });
78+
fetchMock.getOnce('https://not-called/api/memberships/other-user', { status: 200, body: {} });
79+
fetchMock.postOnce('https://not-called/api/testImpressions/bulk', 200);
80+
fetchMock.postOnce('https://not-called/api/events/bulk', 200);
81+
82+
splitio.init();
83+
await splitio.client().ready();
84+
assert.true(splitio.client().__getStatus().isReady, 'Split SDK is ready');
85+
await splitio.destroy();
86+
87+
assert.end();
88+
});
89+
}

src/__tests__/online/node.spec.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import fetchMock from '../testUtils/nodeFetchMock';
33
import { url } from '../testUtils';
44
import { settingsFactory } from '../../settings/node';
55

6+
import splitChangesMock1 from '../mocks/splitchanges.since.-1.json';
7+
import splitChangesMock2 from '../mocks/splitchanges.since.1457552620999.json';
8+
69
import evaluationsSuite from '../nodeSuites/evaluations.spec';
710
import evaluationsSemverSuite from '../nodeSuites/evaluations-semver.spec';
811
import eventsSuite from '../nodeSuites/events.spec';
@@ -18,10 +21,8 @@ import ipAddressesSettingDebug from '../nodeSuites/ip-addresses-setting.debug.sp
1821
import readinessSuite from '../nodeSuites/readiness.spec';
1922
import readyPromiseSuite from '../nodeSuites/ready-promise.spec';
2023
import { fetchSpecificSplits, fetchSpecificSplitsForFlagSets } from '../nodeSuites/fetch-specific-splits.spec';
21-
22-
import splitChangesMock1 from '../mocks/splitchanges.since.-1.json';
23-
import splitChangesMock2 from '../mocks/splitchanges.since.1457552620999.json';
2424
import flagSets from '../nodeSuites/flag-sets.spec';
25+
import lazyInitSuite from '../nodeSuites/lazy-init.spec';
2526

2627
const config = {
2728
core: {
@@ -94,5 +95,7 @@ tape('## Node JS - E2E CI Tests ##', async function (assert) {
9495
/* Validate flag sets */
9596
assert.test('E2E / Flag sets', flagSets.bind(null, fetchMock));
9697

98+
assert.test('E2E / SplitFactory with lazy init', lazyInitSuite.bind(null, settings, fetchMock));
99+
97100
assert.end();
98101
});

src/settings/defaults/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const packageVersion = '10.28.1-rc.2';
1+
export const packageVersion = '10.28.1-rc.4';

ts-tests/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ browserSettings = {
163163
}
164164
};
165165
// With sync settings should return ISDK, if settings have async storage it should return IAsyncSDK
166-
SDK = SplitFactory(browserSettings);
167166
SDK = SplitFactory(nodeSettings);
168167
AsyncSDK = SplitFactory(asyncSettings);
169168
BrowserSDK = SplitFactory(browserSettings);
@@ -195,15 +194,15 @@ SDK.settings.features = { 'split_x': 'on' }; // Browser
195194

196195
// Client and Manager
197196
client = SDK.client();
198-
client = SDK.client('a customer key');
199-
client = SDK.client('a customer key', 'a traffic type');
200197
manager = SDK.manager();
198+
manager = BrowserSDK.manager();
201199
// Today async clients are only possible on Node. Shared client creation not available here.
202200
asyncClient = AsyncSDK.client();
203201
asyncManager = AsyncSDK.manager();
204202
// Browser client for attributes binding
205203
browserClient = BrowserSDK.client();
206204
browserClient = BrowserSDK.client('a customer key');
205+
browserClient = BrowserSDK.client('a customer key', 'a traffic type');
207206

208207
// Logger
209208
SDK.Logger.enable();

types/splitio.d.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,14 +1380,6 @@ declare namespace SplitIO {
13801380
* @returns {IClient} The client instance.
13811381
*/
13821382
client(): IClient,
1383-
/**
1384-
* Returns a shared client of the SDK. For usage on the browser.
1385-
* @function client
1386-
* @param {SplitKey} key The key for the new client instance.
1387-
* @param {string=} trafficType The traffic type of the provided key.
1388-
* @returns {IClient} The client instance.
1389-
*/
1390-
client(key: SplitKey, trafficType?: string): IClient,
13911383
/**
13921384
* Returns a manager instance of the SDK to explore available information.
13931385
* @function manager
@@ -1398,23 +1390,29 @@ declare namespace SplitIO {
13981390
/**
13991391
* This represents the interface for the SDK instance with synchronous storage.
14001392
* @interface IBrowserSDK
1401-
* @extends ISDK
1393+
* @extends IBasicSDK
14021394
*/
1403-
interface IBrowserSDK extends ISDK {
1395+
interface IBrowserSDK extends IBasicSDK {
14041396
/**
14051397
* Returns the default client instance of the SDK.
14061398
* @function client
14071399
* @returns {IBrowserClient} The client instance.
14081400
*/
14091401
client(): IBrowserClient,
14101402
/**
1411-
* Returns a shared client of the SDK. For usage on the browser.
1403+
* Returns a shared client of the SDK.
14121404
* @function client
14131405
* @param {SplitKey} key The key for the new client instance.
14141406
* @param {string=} trafficType The traffic type of the provided key.
14151407
* @returns {IBrowserClient} The client instance.
14161408
*/
14171409
client(key: SplitKey, trafficType?: string): IBrowserClient
1410+
/**
1411+
* Returns a manager instance of the SDK to explore available information.
1412+
* @function manager
1413+
* @returns {IManager} The manager instance.
1414+
*/
1415+
manager(): IManager,
14181416
/**
14191417
* User consent API.
14201418
* @property UserConsent

0 commit comments

Comments
 (0)