Skip to content

Commit cb22821

Browse files
Add getStatus method
1 parent 79622bd commit cb22821

File tree

10 files changed

+42
-41
lines changed

10 files changed

+42
-41
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
1.6.0 (October XX, 2025)
2+
- Added `client.getStatus()` method to retrieve the client readiness status properties (`isReady`, `isReadyFromCache`, etc).
23
- Added `client.whenReady()` and `client.whenReadyFromCache()` methods to replace the deprecated `client.ready()` method, which has an issue causing the returned promise to hang when using async/await syntax if it was rejected.
34
- Updated the SDK_READY_FROM_CACHE event to be emitted alongside the SDK_READY event if it hasn’t already been emitted.
45
- Updated @splitsoftware/splitio-commons package to version 2.8.0.

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"bugs": "https://github.com/splitio/javascript-browser-client/issues",
6060
"homepage": "https://github.com/splitio/javascript-browser-client#readme",
6161
"dependencies": {
62-
"@splitsoftware/splitio-commons": "2.7.9-rc.1",
62+
"@splitsoftware/splitio-commons": "2.7.9-rc.2",
6363
"tslib": "^2.3.1",
6464
"unfetch": "^4.2.0"
6565
},

src/__tests__/browserSuites/ready-from-cache-async-wrapper.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ export default function (fetchMock, assert) {
6969
t.end();
7070
});
7171
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
72-
t.true(client.__getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY');
72+
t.true(client.getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY');
7373
});
7474

7575
client.on(client.Event.SDK_READY, () => {
76-
t.true(client.__getStatus().isReadyFromCache, 'Client should emit SDK_READY and it should be ready from cache');
76+
t.true(client.getStatus().isReadyFromCache, 'Client should emit SDK_READY and it should be ready from cache');
7777
});
7878
client2.on(client.Event.SDK_READY, () => {
79-
t.true(client2.__getStatus().isReadyFromCache, 'Non-default client should emit SDK_READY and it should be ready from cache');
79+
t.true(client2.getStatus().isReadyFromCache, 'Non-default client should emit SDK_READY and it should be ready from cache');
8080
});
8181
client3.on(client.Event.SDK_READY, () => {
82-
t.true(client2.__getStatus().isReadyFromCache, 'Non-default client should emit SDK_READY and it should be ready from cache');
82+
t.true(client2.getStatus().isReadyFromCache, 'Non-default client should emit SDK_READY and it should be ready from cache');
8383
});
8484

8585
});
@@ -351,7 +351,7 @@ export default function (fetchMock, assert) {
351351
let manager = splitio.manager();
352352

353353
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
354-
t.true(client.__getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY, because clearOnInit is true');
354+
t.true(client.getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY, because clearOnInit is true');
355355
});
356356

357357
await client.ready();
@@ -395,7 +395,7 @@ export default function (fetchMock, assert) {
395395
manager = splitio.manager();
396396

397397
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
398-
t.true(client.__getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY, because clearOnInit is true');
398+
t.true(client.getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY, because clearOnInit is true');
399399
});
400400

401401
await new Promise(res => client.once(client.Event.SDK_READY, res));

src/__tests__/browserSuites/ready-from-cache.spec.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,17 @@ export default function (fetchMock, assert) {
140140
t.end();
141141
});
142142
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
143-
t.true(client.__getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY');
143+
t.true(client.getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY');
144144
});
145145

146146
client.on(client.Event.SDK_READY, () => {
147-
t.true(client.__getStatus().isReadyFromCache, 'Client should emit SDK_READY and it should be ready from cache');
147+
t.true(client.getStatus().isReadyFromCache, 'Client should emit SDK_READY and it should be ready from cache');
148148
});
149149
client2.on(client.Event.SDK_READY, () => {
150-
t.true(client.__getStatus().isReadyFromCache, 'Client should emit SDK_READY and it should be ready from cache');
150+
t.true(client.getStatus().isReadyFromCache, 'Client should emit SDK_READY and it should be ready from cache');
151151
});
152152
client3.on(client.Event.SDK_READY, () => {
153-
t.true(client.__getStatus().isReadyFromCache, 'Client should emit SDK_READY and it should be ready from cache');
153+
t.true(client.getStatus().isReadyFromCache, 'Client should emit SDK_READY and it should be ready from cache');
154154
});
155155

156156
});
@@ -521,7 +521,7 @@ export default function (fetchMock, assert) {
521521
const client = splitio.client();
522522
const client2 = splitio.client('emi@split.io');
523523

524-
t.equal(client.__getStatus().isReadyFromCache, true, 'Client is ready from cache');
524+
t.equal(client.getStatus().isReadyFromCache, true, 'Client is ready from cache');
525525

526526
t.equal(client.getTreatment('always_on'), 'off', 'It should evaluate treatments with data from cache. Key without memberships');
527527
t.equal(client2.getTreatment('always_on'), 'on', 'It should evaluate treatments with data from cache. Key with memberships');
@@ -581,7 +581,7 @@ export default function (fetchMock, assert) {
581581
const manager = splitio.manager();
582582

583583
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
584-
t.true(client.__getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY');
584+
t.true(client.getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY');
585585
});
586586

587587
client.once(client.Event.SDK_READY, () => {
@@ -624,7 +624,7 @@ export default function (fetchMock, assert) {
624624
const manager = splitio.manager();
625625

626626
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
627-
t.true(client.__getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY');
627+
t.true(client.getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY');
628628
});
629629

630630
client.once(client.Event.SDK_READY, () => {
@@ -723,7 +723,7 @@ export default function (fetchMock, assert) {
723723
const manager = splitio.manager();
724724

725725
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
726-
t.true(client.__getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY');
726+
t.true(client.getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY');
727727
});
728728

729729
client.once(client.Event.SDK_READY, () => {
@@ -783,7 +783,7 @@ export default function (fetchMock, assert) {
783783
const manager = splitio.manager();
784784

785785
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
786-
t.true(client.__getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY');
786+
t.true(client.getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY');
787787
});
788788

789789
client.once(client.Event.SDK_READY, () => {
@@ -835,7 +835,7 @@ export default function (fetchMock, assert) {
835835
const manager = splitio.manager();
836836

837837
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
838-
t.true(client.__getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY');
838+
t.true(client.getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY');
839839
});
840840

841841
client.once(client.Event.SDK_READY, () => {
@@ -886,7 +886,7 @@ export default function (fetchMock, assert) {
886886
let manager = splitio.manager();
887887

888888
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
889-
t.true(client.__getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY, because clearOnInit is true');
889+
t.true(client.getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY, because clearOnInit is true');
890890
});
891891

892892
await client.ready();
@@ -926,7 +926,7 @@ export default function (fetchMock, assert) {
926926
manager = splitio.manager();
927927

928928
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
929-
t.true(client.__getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY, because clearOnInit is true');
929+
t.true(client.getStatus().isReady, 'Client should emit SDK_READY_FROM_CACHE alongside SDK_READY, because clearOnInit is true');
930930
});
931931

932932
await new Promise(res => client.once(client.Event.SDK_READY, res));

src/__tests__/consumer/browser_consumer.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ tape('Browser Consumer mode with pluggable storage', function (t) {
6262

6363
/** Evaluation, track and manager methods before SDK_READY */
6464

65-
assert.equal(client.__getStatus().isReadyFromCache, false, 'SDK in consumer mode is not operational immediately');
66-
assert.equal(client.__getStatus().isReady, false, 'SDK in consumer mode is not operational immediately');
65+
assert.equal(client.getStatus().isReadyFromCache, false, 'SDK in consumer mode is not operational immediately');
66+
assert.equal(client.getStatus().isReady, false, 'SDK in consumer mode is not operational immediately');
6767

6868
client.getTreatment('UT_IN_SEGMENT').then(treatment => assert.equal(treatment, 'control', 'Evaluations using pluggable storage returns a promise that resolves to control if initiated before SDK_READY'));
6969
otherClient.track('user', 'test.event', 18).then(result => assert.true(result, 'Track calls returns a promise on consumer mode, that resolves to true if the wrapper push operation success to queue the event'));
@@ -218,8 +218,8 @@ tape('Browser Consumer mode with pluggable storage', function (t) {
218218

219219
assert.equal(typeof getTreatmentResult.then, 'function', 'GetTreatment calls should always return a promise on Consumer mode.');
220220
assert.equal(await getTreatmentResult, 'control', 'Evaluations using pluggable storage should be control if initiated before SDK_READY.');
221-
assert.equal(client.__getStatus().isReadyFromCache, false, 'SDK in consumer mode is not operational immediately');
222-
assert.equal(client.__getStatus().isReady, false, 'SDK in consumer mode is not operational immediately');
221+
assert.equal(client.getStatus().isReadyFromCache, false, 'SDK in consumer mode is not operational immediately');
222+
assert.equal(client.getStatus().isReady, false, 'SDK in consumer mode is not operational immediately');
223223

224224
const trackResult = otherClient.track('user', 'test.event', 18);
225225
assert.equal(typeof trackResult.then, 'function', 'Track calls should always return a promise on Consumer mode.');
@@ -350,8 +350,8 @@ tape('Browser Consumer mode with pluggable storage', function (t) {
350350

351351
assert.equal(typeof getTreatmentResult.then, 'function', 'GetTreatment calls should always return a promise on Consumer mode.');
352352
assert.equal(await getTreatmentResult, 'control', 'Evaluations using pluggable storage should be control if initiated before SDK_READY.');
353-
assert.equal(client.__getStatus().isReadyFromCache, false, 'SDK in consumer mode is not operational immediately');
354-
assert.equal(client.__getStatus().isReady, false, 'SDK in consumer mode is not operational immediately');
353+
assert.equal(client.getStatus().isReadyFromCache, false, 'SDK in consumer mode is not operational immediately');
354+
assert.equal(client.getStatus().isReady, false, 'SDK in consumer mode is not operational immediately');
355355

356356
const trackResult = otherClient.track('user', 'test.event', 18);
357357
assert.equal(typeof trackResult.then, 'function', 'Track calls should always return a promise on Consumer mode.');

src/__tests__/consumer/browser_consumer_partial.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ tape('Browser Consumer Partial mode with pluggable storage', function (t) {
9898

9999
/** Evaluation, track and manager methods before SDK_READY */
100100

101-
assert.equal(client.__getStatus().isReadyFromCache, false, 'SDK in consumer mode is not operational immediately');
102-
assert.equal(client.__getStatus().isReady, false, 'SDK in consumer mode is not operational immediately');
101+
assert.equal(client.getStatus().isReadyFromCache, false, 'SDK in consumer mode is not operational immediately');
102+
assert.equal(client.getStatus().isReady, false, 'SDK in consumer mode is not operational immediately');
103103

104104
client.getTreatment('UT_IN_SEGMENT').then(treatment => assert.equal(treatment, 'control', 'Evaluations using pluggable storage returns a promise that resolves to control if initiated before SDK_READY'));
105105
otherClient.track('user', 'test.event', 18).then(result => assert.true(result, 'Track calls returns a promise on consumer mode, that resolves to true if the wrapper push operation success to queue the event'));
@@ -261,8 +261,8 @@ tape('Browser Consumer Partial mode with pluggable storage', function (t) {
261261

262262
assert.equal(typeof getTreatmentResult.then, 'function', 'GetTreatment calls should always return a promise on Consumer mode.');
263263
assert.equal(await getTreatmentResult, 'control', 'Evaluations using pluggable storage should be control if initiated before SDK_READY.');
264-
assert.equal(client.__getStatus().isReadyFromCache, false, 'SDK in consumer mode is not operational immediately');
265-
assert.equal(client.__getStatus().isReady, false, 'SDK in consumer mode is not operational immediately');
264+
assert.equal(client.getStatus().isReadyFromCache, false, 'SDK in consumer mode is not operational immediately');
265+
assert.equal(client.getStatus().isReady, false, 'SDK in consumer mode is not operational immediately');
266266

267267
const trackResult = otherClient.track('user', 'test.event', 18);
268268
assert.equal(typeof trackResult.then, 'function', 'Track calls should always return a promise on Consumer mode.');

src/__tests__/errorCatching/browser.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ tape('Error catching on callbacks - Browsers', assert => {
9090
}
9191

9292
client.on(client.Event.SDK_READY_TIMED_OUT, () => {
93-
assert.true(client.__getStatus().hasTimedout); // SDK status should be already updated
93+
assert.true(client.getStatus().hasTimedout); // SDK status should be already updated
9494
attachErrorHandlerIfApplicable();
9595
null.willThrowForTimedOut();
9696
});
9797

9898
client.once(client.Event.SDK_READY, () => {
99-
assert.true(client.__getStatus().isReady); // SDK status should be already updated
99+
assert.true(client.getStatus().isReady); // SDK status should be already updated
100100
attachErrorHandlerIfApplicable();
101101
null.willThrowForReady();
102102
});
@@ -107,7 +107,7 @@ tape('Error catching on callbacks - Browsers', assert => {
107107
});
108108

109109
client.once(client.Event.SDK_READY_FROM_CACHE, () => {
110-
assert.true(client.__getStatus().isReadyFromCache); // SDK status should be already updated
110+
assert.true(client.getStatus().isReadyFromCache); // SDK status should be already updated
111111
attachErrorHandlerIfApplicable();
112112
null.willThrowForReadyFromCache();
113113
});

src/__tests__/offline/browser.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ tape('Browser offline mode', function (assert) {
117117
const sdkReadyFromCache = (client) => () => {
118118
assert.equal(factory.settings.storage.type, 'MEMORY', 'In localhost mode, storage must fallback to memory storage');
119119

120-
const clientStatus = client.__getStatus();
120+
const clientStatus = client.getStatus();
121121
assert.equal(clientStatus.isReadyFromCache, true, 'If ready from cache, READY_FROM_CACHE status must be true');
122122
assert.equal(clientStatus.isReady, configs[i].storage && configs[i].storage.type === 'LOCALSTORAGE' ? false : true, 'When not using LOCALSTORAGE, READY status is set together with READY_FROM_CACHE');
123123
if (!clientStatus.isReady) readyFromCacheCount++;

types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ declare module JsSdk {
1919
/**
2020
* Persistent storage. By default, it uses the browser's LocalStorage API if available.
2121
*
22-
* @see {@link https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/browser-sdk/#configuring-cache}
22+
* @see {@link https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/browser-sdk/#configure-cache-behavior}
2323
*/
2424
export function InLocalStorage(options?: SplitIO.InLocalStorageOptions): SplitIO.StorageSyncFactory;
2525

0 commit comments

Comments
 (0)