Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.8.0 (TBD)
- Added `exports` field to package.json to support native ESM `import` of the `@splitsoftware/splitio-browserjs/full` entry point in Node.js.

1.7.1 (June 26, 2026)
- Updated TypeScript declaration to use `namespace` instead of `module` for compatibility with TypeScript 7 (Related to issue https://github.com/splitio/javascript-client/issues/920, and contributed by Matt Lewis (@mattlewis92) in https://github.com/splitio/javascript-browser-client/pull/173).
- Updated @splitsoftware/splitio-commons package to version 2.12.1, which:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Split JavaScript SDK for Browsers

[![npm version](https://badge.fury.io/js/%40splitsoftware%2Fsplitio-browserjs.svg)](https://badge.fury.io/js/%40splitsoftware%2Fsplitio-browserjs) [![Build Status](https://github.com/splitio/javascript-browser-client/actions/workflows/ci-cd.yml/badge.svg)](https://github.com/splitio/javascript-browser-client/actions/workflows/ci-cd.yml)
[![npm version](https://badge.fury.io/js/%40splitsoftware%2Fsplitio-browserjs.svg)](https://badge.fury.io/js/%40splitsoftware%2Fsplitio-browserjs)

## Overview
This SDK is designed to work with Split, the platform for controlled rollouts, which serves features to your users via feature flags to manage your complete customer experience.
Expand Down
48 changes: 20 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 21 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
{
"name": "@splitsoftware/splitio-browserjs",
"version": "1.7.1-rc.1",
"version": "1.7.2-rc.1",
"description": "Split SDK for JavaScript on Browser",
"main": "cjs/index.js",
"module": "esm/index.js",
"types": "types",
"exports": {
".": {
"types": "./types/index.d.ts",
"module": "./esm/index.js",
"import": "./cjs/index.js",
"default": "./cjs/index.js"
},
"./full": {
"types": "./types/full/index.d.ts",
"module": "./esm/full/index.js",
"import": "./cjs/full/index.js",
"default": "./cjs/full/index.js"
},
"./package.json": "./package.json",
"./types/*.d.ts": "./types/*.d.ts",
"./types/*": "./types/*.d.ts",
"./*": "./*"
},
"files": [
"README.md",
"CONTRIBUTORS-GUIDE.md",
Expand All @@ -23,7 +41,7 @@
"check:version": "./scripts/check_version.sh",
"build": "npm run build:cjs && npm run build:esm && npm run build:umd",
"build:esm": "rimraf esm && tsc -outDir esm && ./scripts/build_esm_replace_imports.sh",
"build:cjs": "rimraf cjs && tsc -outDir cjs -m CommonJS && ./scripts/build_cjs_replace_imports.sh",
"build:cjs": "rimraf cjs && tsc -outDir cjs -m CommonJS && ./scripts/build_cjs_replace_imports.sh && node scripts/check_module_imports.js",
"build:umd-visualizer": "rimraf umd && rollup --config rollup.visualizer.config.js",
"build:umd": "rimraf umd && rollup --config rollup.ci.config.js --branch=$BUILD_BRANCH",
"test": "npm run test:unit && npm run test:e2e",
Expand Down Expand Up @@ -59,7 +77,7 @@
"bugs": "https://github.com/splitio/javascript-browser-client/issues",
"homepage": "https://github.com/splitio/javascript-browser-client#readme",
"dependencies": {
"@splitsoftware/splitio-commons": "2.12.1",
"@splitsoftware/splitio-commons": "3.2.1-rc.0",
"tslib": "^2.3.1",
"unfetch": "^4.2.0"
},
Expand Down
34 changes: 34 additions & 0 deletions scripts/check_module_imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

// Smoke test of the package entry points (`exports` field of package.json): verifies that the root and `full`
// entries can be loaded with both native ESM `import` and CommonJS `require` in Node.js. It imports the package by
// name (package self-reference), not by file path, so the `exports` map is exercised. Run after building `cjs`.
const { execFileSync } = require('child_process');
const path = require('path');

const root = path.resolve(__dirname, '..');
const entries = ['@splitsoftware/splitio-browserjs', '@splitsoftware/splitio-browserjs/full'];

const assertExports = 'if (typeof SplitFactory !== \'function\' || typeof InLocalStorage !== \'function\') throw new Error(\'Missing named exports\');';
const checks = [];
entries.forEach((entry) => {
checks.push([`ESM import of ${entry}`, ['--input-type=module', '-e',
`import { SplitFactory, InLocalStorage } from '${entry}'; import pkg from '${entry}'; ${assertExports} if (pkg.SplitFactory !== SplitFactory) throw new Error('Default export is not the CommonJS module');`
]]);
checks.push([`CJS require of ${entry}`, ['-e',
`const { SplitFactory, InLocalStorage } = require('${entry}'); ${assertExports}`
]]);
});

let failed = false;
checks.forEach(([name, args]) => {
try {
execFileSync(process.execPath, args, { cwd: root, stdio: 'pipe' });
console.log(`OK ${name}`);
} catch (error) {
failed = true;
console.error(`FAILED ${name}\n${error.stderr ? error.stderr.toString() : error.message}`);
}
});

process.exit(failed ? 1 : 0);
2 changes: 1 addition & 1 deletion src/__tests__/browserSuites/evaluations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export default function (config, fetchMock, assert) {
attr: 9
}), 'off');

// This split depends on Split hierarchical_dep_hierarchical which depends on a split that always retuns 'on'
// This split depends on Split hierarchical_dep_hierarchical which depends on a split that always returns 'on'
assert.equal(client.getTreatment('hierarchical_splits_test'), 'on');

// This split has a traffic allocation of 1 (lowest) and the key we're using also returns the lowest bucket for TA (1)
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/browserSuites/push-synchronization.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const EXPECTED_DELAY_AND_BACKOFF = 241 + 100;
export function testSynchronization(fetchMock, assert) {
// Force the backoff base of UpdateWorkers to reduce test time
Backoff.__TEST__BASE_MILLIS = 100;
assert.plan(34);
assert.plan(33);
fetchMock.reset();

let start, splitio, client, otherClient, keylistAddClient, keylistRemoveClient, bitmapTrueClient, sharedClients = [];
Expand Down Expand Up @@ -122,13 +122,13 @@ export function testSynchronization(fetchMock, assert) {

setTimeout(() => {
assert.equal(client.getTreatment('whitelist'), 'allowed', 'evaluation with not killed Split');
const onUpdateCb = () => {
const onUpdateCb = (metadata) => {
assert.deepEqual(metadata, { type: 'FLAGS_UPDATE', names: ['whitelist'] }, 'SDK_UPDATE due to SPLIT_KILL event carries the killed flag name');
const lapse = Date.now() - start;
assert.true(nearlyEqual(lapse, MILLIS_SPLIT_KILL_EVENT), 'SDK_UPDATE due to SPLIT_KILL event');
assert.equal(client.getTreatment('whitelist'), 'not_allowed', 'evaluation with killed Split');
};
// SPLIT_KILL triggers two SDK_UPDATE events. The 1st due to `killLocally` and the 2nd due to `/splitChanges` fetch
client.once(client.Event.SDK_UPDATE, onUpdateCb);
// SPLIT_KILL triggers one SDK_UPDATE event due to `killLocally`. The `/splitChanges` fetch doesn't emit another one, since the flag was already updated with the same changeNumber
client.once(client.Event.SDK_UPDATE, onUpdateCb);
eventSourceInstance.emitMessage(splitKillMessage);
}, MILLIS_SPLIT_KILL_EVENT); // send a SPLIT_KILL event with a new changeNumber after 0.5 seconds
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/browserSuites/readiness.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ export default function (fetchMock, assert) {
if (startWithSegments) {
// Adjust since and till so the order is inverted.
fetchMock.get(testUrls.sdk + '/splitChanges?s=1.3&since=-1&rbSince=-1', { status: 200, body: splitChangesStartWithSegmentsMock });
fetchMock.get(testUrls.sdk + '/splitChanges?s=1.3&since=1457552620999&rbSince=-1', { status: 200, body: { ff: { ...splitChangesUpdateWithoutSegmentsMock.ff, s: 1457552620999, t: 1457552649999 } } });
fetchMock.get(testUrls.sdk + '/splitChanges?s=1.3&since=1457552649999&rbSince=-1', { status: 200, body: { ff: { ...splitChangesUpdateWithSegmentsMock.ff, s: 1457552649999, t: 1457552669999 } } });
fetchMock.get(testUrls.sdk + '/splitChanges?s=1.3&since=1457552620999&rbSince=-1', { status: 200, body: { ff: { ...splitChangesUpdateWithoutSegmentsMock.ff, d: splitChangesUpdateWithoutSegmentsMock.ff.d.map(f => ({ ...f, changeNumber: 1457552649999 })), s: 1457552620999, t: 1457552649999 } } });
fetchMock.get(testUrls.sdk + '/splitChanges?s=1.3&since=1457552649999&rbSince=-1', { status: 200, body: { ff: { ...splitChangesUpdateWithSegmentsMock.ff, d: splitChangesUpdateWithSegmentsMock.ff.d.map(f => ({ ...f, changeNumber: 1457552669999 })), s: 1457552649999, t: 1457552669999 } } });
fetchMock.get(testUrls.sdk + '/splitChanges?s=1.3&since=1457552669999&rbSince=-1', { status: 200, body: { ff: { d: [], s: 1457552669999, t: 1457552669999 } } });
} else {
fetchMock.get(testUrls.sdk + '/splitChanges?s=1.3&since=-1&rbSince=-1', { status: 200, body: splitChangesStartWithoutSegmentsMock });
Expand Down
6 changes: 1 addition & 5 deletions src/__tests__/browserSuites/ready-promise.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function assertGetTreatmentWhenReady(assert, client) {
function assertGetTreatmentControlNotReady(assert, client) {
consoleSpy.log.resetHistory();
assert.equal(client.getTreatment('hierarchical_splits_test'), 'control', 'We should get control if client is not ready.');
assert.true(consoleSpy.log.calledWithExactly('[WARN] splitio => getTreatment: the SDK is not ready to evaluate. Results may be incorrect for feature flag hierarchical_splits_test. Make sure to wait for SDK readiness before using this method.'), 'Telling us that calling getTreatment would return CONTROL since SDK is not ready at this point.');
assert.true(consoleSpy.log.calledWithExactly('[WARN] splitio => getTreatment: the SDK is not ready to evaluate. Results may be incorrect. Make sure to wait for SDK readiness before using this method.'), 'Telling us that calling getTreatment would return CONTROL since SDK is not ready at this point.');
}

function assertGetTreatmentControlNotReadyOnDestroy(assert, client) {
Expand Down Expand Up @@ -543,13 +543,9 @@ export default function readyPromiseAssertions(fetchMock, assert) {
consoleSpy.log.resetHistory();
const sharedClientWithCb = splitio.client('nicolas@split.io');
sharedClientWithCb.on(client.Event.SDK_READY, () => {
t.false(consoleSpy.log.calledWithExactly('[WARN] splitio => No listeners for SDK_READY event detected. Incorrect control treatments could have been logged if you called getTreatment/s while the SDK was not yet synchronized with the backend.'),
'No warning logged');

const sharedClientWithoutCb = splitio.client('emiliano@split.io');
setTimeout(() => {
t.true(consoleSpy.log.calledWithExactly('[WARN] splitio => No listeners for SDK_READY event detected. Incorrect control treatments could have been logged if you called getTreatment/s while the SDK was not yet synchronized with the backend.'),
'Warning logged');
Promise.all([sharedClientWithoutCb.destroy(), client.destroy()]).then(() => {
client.whenReady()
.then(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"id\":\"itKIDa6b4b:0:0\",\"clientId\": \"EORI49J_FSJKA2\",\"timestamp\":1586987434950,\"encoding\":\"json\",\"channel\":\"control_pri\",\"data\":\"{\\\"type\\\":\\\"CONTROL\\\",\\\"controlType\\\":\\\"STREAMING_DISABLED\\\"}\"}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"id\":\"itKIDa6b4b:0:0\",\"clientId\": \"EORI49J_FSJKA2\",\"timestamp\":1586987434750,\"encoding\":\"json\",\"channel\":\"control_pri\",\"data\":\"{\\\"type\\\":\\\"CONTROL\\\",\\\"controlType\\\":\\\"STREAMING_PAUSED\\\"}\"}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"id\":\"itKIDa6b4b:0:0\",\"clientId\": \"EORI49J_FSJKA2\",\"timestamp\":1586987434900,\"encoding\":\"json\",\"channel\":\"control_pri\",\"data\":\"{\\\"type\\\":\\\"CONTROL\\\",\\\"controlType\\\":\\\"STREAMING_PAUSED\\\"}\"}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"id\":\"itKIDa6b4b:0:0\",\"clientId\": \"EORI49J_FSJKA2\",\"timestamp\":1586987434850,\"encoding\":\"json\",\"channel\":\"control_pri\",\"data\":\"{\\\"type\\\":\\\"CONTROL\\\",\\\"controlType\\\":\\\"STREAMING_RESUMED\\\"}\"}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"data\":\"{\\\"type\\\":\\\"MEMBERSHIPS_LS_UPDATE\\\",\\\"cn\\\":1457552653000,\\\"n\\\":[\\\"splitters\\\"],\\\"c\\\": 0,\\\"u\\\": 3,\\\"d\\\":\\\"\\\"}\"}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"data\":\"{\\\"type\\\":\\\"MEMBERSHIPS_LS_UPDATE\\\",\\\"cn\\\":1457552650000,\\\"n\\\":[],\\\"c\\\": 0,\\\"u\\\": 0,\\\"d\\\":\\\"\\\",\\\"i\\\":300,\\\"h\\\":1,\\\"s\\\":0}\"}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"data\":\"{\\\"type\\\":\\\"MEMBERSHIPS_MS_UPDATE\\\",\\\"cn\\\":1457552651000,\\\"n\\\":[],\\\"c\\\": 1,\\\"u\\\": 1,\\\"d\\\":\\\"H4sIAAAAAAAA/2JABxzYeIxQLguYFIBLN8Bl4EABjc+EzOnAsA4QAAD//8YBvWeAAAAA\\\",\\\"h\\\":0}\"}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"data\":\"{\\\"type\\\":\\\"MEMBERSHIPS_MS_UPDATE\\\",\\\"cn\\\":1457552651000,\\\"n\\\":[],\\\"c\\\": 2,\\\"u\\\": 1,\\\"d\\\":\\\"eJxiGAX4AMdAO2AU4AeMA+2AAQACA+0AuoORGMvDBDANtAPoDBQG2gGDGQz16pRloB0wCkbBKBgFo4As0EBYyZCqoojwDwEACAAA//+W/QFR\\\",\\\"h\\\":0}\"}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"data\":\"{\\\"type\\\":\\\"MEMBERSHIPS_MS_UPDATE\\\",\\\"cn\\\":1457552652000,\\\"n\\\":[\\\"splitters\\\"],\\\"c\\\": 1,\\\"u\\\": 2,\\\"d\\\":\\\"H4sIAAAAAAAA/wTAsRHDUAgD0F2ofwEIkPAqPhdZIW0uu/v97GPXHU004ULuMGrYR6XUbIjlXULPPse+dt1yhJibBODjrTmj3GJ4emduuDDP/w0AAP//18WLsl0AAAA=\\\",\\\"h\\\":0}\"}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"data\":\"{\\\"type\\\":\\\"MEMBERSHIPS_MS_UPDATE\\\",\\\"cn\\\":1457552653000,\\\"n\\\":[\\\"splitters\\\"],\\\"c\\\": 0,\\\"u\\\": 3,\\\"d\\\":\\\"\\\",\\\"h\\\":0}\"}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"data\":\"{\\\"type\\\":\\\"MEMBERSHIPS_MS_UPDATE\\\",\\\"cn\\\":1457552640000,\\\"u\\\": 0,\\\"h\\\":0}\"}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"data\":\"{\\\"type\\\":\\\"MEMBERSHIPS_MS_UPDATE\\\",\\\"cn\\\":1457552650000,\\\"n\\\":[],\\\"c\\\": 0,\\\"u\\\": 0,\\\"d\\\":\\\"\\\",\\\"h\\\":0}\"}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"id\":\"itKIDa6b4b:0:0\",\"timestamp\":1586987434550,\"encoding\":\"json\",\"channel\":\"[?occupancy=metrics.publishers]control_pri\",\"data\":\"{\\\"metrics\\\":{\\\"publishers\\\":0}}\",\"name\":\"[meta]occupancy\"}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"id\":\"JdPcOgIxuH:0:0\",\"timestamp\":1586987434451,\"encoding\":\"json\",\"channel\":\"[?occupancy=metrics.publishers]control_sec\",\"data\":\"{\\\"metrics\\\":{\\\"publishers\\\":0}}\",\"name\":\"[meta]occupancy\"}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"id\":\"itKIDa6b4b:0:0\",\"timestamp\":1586987434450,\"encoding\":\"json\",\"channel\":\"[?occupancy=metrics.publishers]control_pri\",\"data\":\"{\\\"metrics\\\":{\\\"publishers\\\":1}}\",\"name\":\"[meta]occupancy\"}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"id\":\"itKIDa6b4b:0:0\",\"timestamp\":1586987434650,\"encoding\":\"json\",\"channel\":\"[?occupancy=metrics.publishers]control_pri\",\"data\":\"{\\\"metrics\\\":{\\\"publishers\\\":2}}\",\"name\":\"[meta]occupancy\"}"
}
2 changes: 1 addition & 1 deletion src/__tests__/mocks/message.SPLIT_KILL.1457552650000.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"id\":\"mc4i3NENoA:0:0\",\"clientId\":\"NDEzMTY5Mzg0MA==:MTM2ODE2NDMxNA==\",\"timestamp\":1457552650900,\"encoding\":\"json\",\"channel\":\"NzM2MDI5Mzc0_NDEzMjQ1MzA0Nw==_splits\",\"data\":\"{\\\"type\\\":\\\"SPLIT_KILL\\\",\\\"changeNumber\\\":1457552650000,\\\"defaultTreatment\\\":\\\"not_allowed\\\",\\\"splitName\\\":\\\"whitelist\\\"}\"}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "message",
"event": "message",
"data": "{\"id\":\"mc4i3NENoA:0:0\",\"clientId\":\"NDEzMTY5Mzg0MA==:MTM2ODE2NDMxNA==\",\"timestamp\":1457552621899,\"encoding\":\"json\",\"channel\":\"NzM2MDI5Mzc0_NDEzMjQ1MzA0Nw==_splits\",\"data\":\"{\\\"type\\\":\\\"SPLIT_UPDATE\\\",\\\"changeNumber\\\":1457552620999}\"}"
}
Loading