Skip to content

Commit f0b1c5d

Browse files
Merge pull request #439 from splitio/readiness-status
[Readiness] Add getter for readiness status
2 parents 4beb824 + 02447ea commit f0b1c5d

File tree

6 files changed

+70
-31
lines changed

6 files changed

+70
-31
lines changed

CHANGES.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
2.8.0 (October XX, 2025)
1+
2.8.0 (October 28, 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

src/readiness/__tests__/sdkReadinessManager.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ describe('SDK Readiness Manager - Event emitter', () => {
6666

6767
expect(typeof sdkStatus.whenReady).toBe('function'); // The sdkStatus exposes a .whenReady() function.
6868
expect(typeof sdkStatus.whenReadyFromCache).toBe('function'); // The sdkStatus exposes a .whenReadyFromCache() function.
69-
expect(typeof sdkStatus.__getStatus).toBe('function'); // The sdkStatus exposes a .__getStatus() function.
70-
expect(sdkStatus.__getStatus()).toEqual({
69+
expect(sdkStatus.getStatus()).toEqual({ // The sdkStatus exposes a .getStatus() function.
7170
isReady: false, isReadyFromCache: false, isTimedout: false, hasTimedout: false, isDestroyed: false, isOperational: false, lastUpdate: 0
7271
});
7372

src/readiness/sdkReadinessManager.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ export function sdkReadinessManagerFactory(
7272
return promise;
7373
}
7474

75+
function getStatus() {
76+
return {
77+
isReady: readinessManager.isReady(),
78+
isReadyFromCache: readinessManager.isReadyFromCache(),
79+
isTimedout: readinessManager.isTimedout(),
80+
hasTimedout: readinessManager.hasTimedout(),
81+
isDestroyed: readinessManager.isDestroyed(),
82+
isOperational: readinessManager.isOperational(),
83+
lastUpdate: readinessManager.lastUpdate(),
84+
};
85+
}
7586

7687
return {
7788
readinessManager,
@@ -134,17 +145,9 @@ export function sdkReadinessManagerFactory(
134145
});
135146
},
136147

137-
__getStatus() {
138-
return {
139-
isReady: readinessManager.isReady(),
140-
isReadyFromCache: readinessManager.isReadyFromCache(),
141-
isTimedout: readinessManager.isTimedout(),
142-
hasTimedout: readinessManager.hasTimedout(),
143-
isDestroyed: readinessManager.isDestroyed(),
144-
isOperational: readinessManager.isOperational(),
145-
lastUpdate: readinessManager.lastUpdate(),
146-
};
147-
},
148+
getStatus,
149+
// @TODO: remove in next major
150+
__getStatus: getStatus
148151
}
149152
)
150153
};

src/readiness/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { IStatusInterface } from '../types';
21
import SplitIO from '../../types/splitio';
32

43
/** Splits data emitter */
@@ -72,7 +71,7 @@ export interface IReadinessManager {
7271

7372
export interface ISdkReadinessManager {
7473
readinessManager: IReadinessManager
75-
sdkStatus: IStatusInterface
74+
sdkStatus: SplitIO.IStatusInterface
7675

7776
/**
7877
* Increment internalReadyCbCount, an offset value of SDK_READY listeners that are added/removed internally

src/types.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,6 @@ export interface ISettings extends SplitIO.ISettings {
1414
readonly initialRolloutPlan?: RolloutPlan;
1515
}
1616

17-
/**
18-
* SplitIO.IStatusInterface interface extended with private properties for internal use
19-
*/
20-
export interface IStatusInterface extends SplitIO.IStatusInterface {
21-
// Expose status for internal purposes only. Not considered part of the public API, and might be updated eventually.
22-
__getStatus(): {
23-
isReady: boolean;
24-
isReadyFromCache: boolean;
25-
isTimedout: boolean;
26-
hasTimedout: boolean;
27-
isDestroyed: boolean;
28-
isOperational: boolean;
29-
lastUpdate: number;
30-
};
31-
}
3217
/**
3318
* SplitIO.IBasicClient interface extended with private properties for internal use
3419
*/

types/splitio.d.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,52 @@ declare namespace SplitIO {
691691
[status in ConsentStatus]: ConsentStatus;
692692
};
693693
}
694+
/**
695+
* Readiness Status interface. It represents the readiness state of an SDK client.
696+
*/
697+
interface ReadinessStatus {
698+
699+
/**
700+
* `isReady` indicates if the client has triggered an `SDK_READY` event and
701+
* thus is ready to evaluate with cached data synchronized with the backend.
702+
*/
703+
isReady: boolean;
704+
705+
/**
706+
* `isReadyFromCache` indicates if the client has triggered an `SDK_READY_FROM_CACHE` event and
707+
* thus is ready to evaluate with cached data, although the data in cache might be stale, not synchronized with the backend.
708+
*/
709+
isReadyFromCache: boolean;
710+
711+
/**
712+
* `isTimedout` indicates if the client has triggered an `SDK_READY_TIMED_OUT` event and is not ready to evaluate.
713+
* In other words, `isTimedout` is equivalent to `hasTimedout && !isReady`.
714+
*/
715+
isTimedout: boolean;
716+
717+
/**
718+
* `hasTimedout` indicates if the client has ever triggered an `SDK_READY_TIMED_OUT` event.
719+
* It's meant to keep a reference that the SDK emitted a timeout at some point, not the current state.
720+
*/
721+
hasTimedout: boolean;
722+
723+
/**
724+
* `isDestroyed` indicates if the client has been destroyed, i.e., `destroy` method has been called.
725+
*/
726+
isDestroyed: boolean;
727+
728+
/**
729+
* `isOperational` indicates if the client can evaluate feature flags.
730+
* In this state, `getTreatment` calls will not return `CONTROL` due to the SDK being unready or destroyed.
731+
* It's equivalent to `isReadyFromCache && !isDestroyed`.
732+
*/
733+
isOperational: boolean;
734+
735+
/**
736+
* `lastUpdate` indicates the timestamp of the most recent status event.
737+
*/
738+
lastUpdate: number;
739+
}
694740
/**
695741
* Common API for entities that expose status handlers.
696742
*/
@@ -699,6 +745,12 @@ declare namespace SplitIO {
699745
* Constant object containing the SDK events for you to use.
700746
*/
701747
Event: EventConsts;
748+
/**
749+
* Gets the readiness status.
750+
*
751+
* @returns The current readiness status.
752+
*/
753+
getStatus(): ReadinessStatus;
702754
/**
703755
* Returns a promise that resolves when the SDK has finished initial synchronization with the backend (`SDK_READY` event emitted), or rejected if the SDK has timedout (`SDK_READY_TIMED_OUT` event emitted).
704756
* As it's meant to provide similar flexibility to the event approach, given that the SDK might be eventually ready after a timeout event, the `ready` method will return a resolved promise once the SDK is ready.

0 commit comments

Comments
 (0)