Skip to content

Commit 06cbb9b

Browse files
Merge pull request #807 from splitio/add_getOptions
Fix localhost mode and add `getOptions` method
2 parents d56a65d + 6776916 commit 06cbb9b

File tree

15 files changed

+628
-117
lines changed

15 files changed

+628
-117
lines changed

CHANGES.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
10.26.1 (June XX, 2024)
2-
- Updated the internal imports of 'os' and 'ioredis' modules for NodeJS to use EcmaScript 'import' rather than CommonJS 'require' for the ES modules build, avoiding runtime errors when bundling or importing the SDK in a .mjs file.
3-
- Updated @splitsoftware/splitio-commons package to version 1.15.1 that includes updates on input validation logs.
1+
10.26.1 (June 14, 2024)
2+
- Updated the internal imports of 'os' and 'ioredis' modules for NodeJS, to use EcmaScript 'import' rather than CommonJS 'require' for the ES modules build. This avoids runtime errors on some scenarios when bundling the SDK into a .mjs file or importing it from a .mjs file.
3+
- Updated @splitsoftware/splitio-commons package to version 1.16.0 that includes some vulnerability and bug fixes.
4+
- Bugfixing - Restored some input validation error logs that were removed in version 10.24.0. The logs inform the user when the `getTreatment(s)` methods are called with an invalid value as feature flag name or flag set name.
5+
- Bugfixing - Fixed localhost mode to emit SDK_UPDATE when mocked feature flags are updated in the `features` object map of the config object (Related to issue https://github.com/splitio/javascript-browser-client/issues/119).
46

57
10.26.0 (May 6, 2024)
68
- Updated @splitsoftware/splitio-commons package to version 1.14.0 that includes minor updates:

package-lock.json

Lines changed: 23 additions & 41 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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splitsoftware/splitio",
3-
"version": "10.26.1-rc.1",
3+
"version": "10.26.1",
44
"description": "Split SDK",
55
"files": [
66
"README.md",
@@ -40,7 +40,7 @@
4040
"node": ">=6"
4141
},
4242
"dependencies": {
43-
"@splitsoftware/splitio-commons": "1.15.1-rc.1",
43+
"@splitsoftware/splitio-commons": "1.16.0",
4444
"@types/google.analytics": "0.0.40",
4545
"@types/ioredis": "^4.28.0",
4646
"bloom-filters": "^3.0.0",
@@ -50,9 +50,6 @@
5050
"tslib": "^2.3.1",
5151
"unfetch": "^4.2.0"
5252
},
53-
"optionalDependencies": {
54-
"eventsource": "^1.1.2"
55-
},
5653
"devDependencies": {
5754
"@types/node-fetch": "^2.6.10",
5855
"@types/seedrandom": "^3.0.2",

src/__tests__/nodeSuites/push-initialization-nopush.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ function testInitializationFail(fetchMock, assert, fallbackToPolling) {
5353
fetchMock.getOnce(url(settings, '/splitChanges?s=1.1&since=1457552620999'), function () {
5454
assert.true(ready, 'client ready');
5555
const lapse = Date.now() - start;
56-
assert.true(nearlyEqual(lapse, 0), 'polling (first fetch)');
56+
assert.true(nearlyEqual(lapse, 0, 100), 'polling (first fetch)');
5757
return { status: 200, body: splitChangesMock2 };
5858
});
5959
}
6060

6161
fetchMock.getOnce(url(settings, '/splitChanges?s=1.1&since=1457552620999'), function () {
6262
assert.true(ready, 'client ready');
6363
const lapse = Date.now() - start;
64-
assert.true(nearlyEqual(lapse, settings.scheduler.featuresRefreshRate), 'polling (second fetch)');
64+
assert.true(nearlyEqual(lapse, settings.scheduler.featuresRefreshRate, 100), 'polling (second fetch)');
6565
client.destroy().then(() => {
6666
assert.end();
6767
});

src/__tests__/nodeSuites/push-synchronization.spec.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const MILLIS_IFFU_UPDATE_EVENT_WITH_NEW_SEGMENTS = 700;
5858
const MILLIS_IFFU_UPDATE_EVENT_WITH_WRONG_COMPRESS = 800;
5959
const MILLIS_IFFU_UPDATE_EVENT_WITH_OLD_CHANGENUMBER = 900;
6060
const MILLIS_IFFU_UPDATE_EVENT_WITH_ZERO_PCN = 1000;
61-
const MILLIS_IFFU_UPDATE_EVENT_WITH_MISSING_PCN= 1100;
61+
const MILLIS_IFFU_UPDATE_EVENT_WITH_MISSING_PCN = 1100;
6262
const MILLIS_IFFU_UPDATE_EVENT_WITH_ARCHIVED = 1200;
6363
const MILLIS_DESTROY = 1300;
6464

@@ -89,13 +89,11 @@ export function testSynchronization(fetchMock, assert) {
8989
setMockListener(function (eventSourceInstance) {
9090
const expectedSSEurl = `${url(settings, '/sse')}?channels=NzM2MDI5Mzc0_NDEzMjQ1MzA0Nw%3D%3D_segments,NzM2MDI5Mzc0_NDEzMjQ1MzA0Nw%3D%3D_splits,%5B%3Foccupancy%3Dmetrics.publishers%5Dcontrol_pri,%5B%3Foccupancy%3Dmetrics.publishers%5Dcontrol_sec&accessToken=${authPushEnabled.token}&v=1.1&heartbeats=true`;
9191
assert.equals(eventSourceInstance.url, expectedSSEurl, 'EventSource URL is the expected');
92-
assert.deepEqual(eventSourceInstance.__eventSourceInitDict, {
93-
headers: {
94-
SplitSDKClientKey: 'h-1>',
95-
SplitSDKVersion: settings.version,
96-
SplitSDKMachineIP: settings.runtime.ip,
97-
SplitSDKMachineName: settings.runtime.hostname
98-
}
92+
assert.deepEqual(eventSourceInstance.__eventSourceInitDict.headers, {
93+
SplitSDKClientKey: 'h-1>',
94+
SplitSDKVersion: settings.version,
95+
SplitSDKMachineIP: settings.runtime.ip,
96+
SplitSDKMachineName: settings.runtime.hostname
9997
}, 'EventSource headers are the expected');
10098

10199
setTimeout(() => {
@@ -285,7 +283,7 @@ export function testSynchronization(fetchMock, assert) {
285283

286284
// fetch segments due to IFFU SPLIT_UPDATE event with new segments
287285
fetchMock.getOnce(url(settings, '/segmentChanges/maur-2?since=-1'), function () {
288-
return { status: 200, body: { since: 1457552650000, till: 1457552650000, name: 'maur-2', added: ['admin','mauro','nico'], removed: [] } };
286+
return { status: 200, body: { since: 1457552650000, till: 1457552650000, name: 'maur-2', added: ['admin', 'mauro', 'nico'], removed: [] } };
289287
});
290288

291289
// fetch feature flags due to IFFU SPLIT_UPDATE event with wrong compress code

src/__tests__/offline/browser.spec.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ tape('Browser offline mode', function (assert) {
8888
});
8989

9090
// Multiple factories must handle their own `features` mock, even if instantiated with the same config.
91-
const factories = [
92-
SplitFactory(config),
93-
SplitFactory({ ...config }),
94-
SplitFactory({ ...config, features: { ...config.features }, storage: { type: 'INVALID TYPE' } }),
95-
SplitFactory({ ...config, storage: { type: 'LOCALSTORAGE' } })
91+
const configs = [
92+
{ ...config, features: { ...config.features }, storage: { type: 'INVALID TYPE' } },
93+
{ ...config, storage: { type: 'LOCALSTORAGE' } },
94+
{ ...config },
95+
config,
9696
];
97+
const factories = configs.map(config => SplitFactory(config));
98+
9799
let readyCount = 0, updateCount = 0, readyFromCacheCount = 0;
98100

99101
for (let i = 0; i < factories.length; i++) {
@@ -105,7 +107,7 @@ tape('Browser offline mode', function (assert) {
105107
readyCount++;
106108
});
107109
client.on(client.Event.SDK_UPDATE, () => {
108-
assert.deepEqual(manager.names(), ['testing_split', 'testing_split_2', 'testing_split_3', 'testing_split_with_config']);
110+
assert.deepEqual(manager.names().sort(), ['testing_split', 'testing_split_2', 'testing_split_3', 'testing_split_with_config']);
109111
assert.equal(client.getTreatment('testing_split_with_config'), 'nope');
110112
updateCount++;
111113
});
@@ -211,7 +213,7 @@ tape('Browser offline mode', function (assert) {
211213
});
212214

213215
setTimeout(() => {
214-
// Update the features
216+
// Update features reference in settings
215217
factory.settings.features = {
216218
testing_split: 'on',
217219
testing_split_2: 'off',
@@ -221,10 +223,23 @@ tape('Browser offline mode', function (assert) {
221223
config: null
222224
}
223225
};
224-
// Update the features in all factories except the last one
225-
for (let i = 0; i < factories.length - 1; i++) {
226+
227+
// Update features properties in config
228+
configs[0].features['testing_split'] = 'on';
229+
configs[0].features['testing_split_2'] = 'off';
230+
configs[0].features['testing_split_3'] = 'custom_treatment';
231+
configs[0].features['testing_split_with_config'] = {
232+
treatment: 'nope',
233+
config: null
234+
};
235+
236+
// Update the features in all remaining factories except the last one
237+
for (let i = 1; i < factories.length - 1; i++) {
226238
factories[i].settings.features = factory.settings.features;
227239
}
240+
241+
// Assigning a new object to the features property in the config doesn't trigger an update
242+
configs[configs.length - 1].features = { ...factory.settings.features };
228243
}, 1000);
229244

230245
setTimeout(() => { factory.settings.features = originalFeaturesMap; }, 200);

src/platform/getEventSource/__tests__/node.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import tape from 'tape-catch';
22
import { getEventSource } from '../node';
33

44
tape('getEventSource returns eventsource module in Node', assert => {
5-
assert.equal(getEventSource(), require('eventsource'));
5+
assert.equal(getEventSource(), require('../eventsource'));
66

77
assert.end();
88
});

0 commit comments

Comments
 (0)