Skip to content

Commit 79df832

Browse files
Merge branch 'fallback-treatment' into prepare-release
2 parents ad8d66a + d58f162 commit 79df832

File tree

6 files changed

+69
-30
lines changed

6 files changed

+69
-30
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2.8.0 (October 28, 2025)
22
- Added new configuration for Fallback Treatments, which allows setting a treatment value and optional config to be returned in place of "control", either globally or by flag. Read more in our docs.
3+
- Added `client.getStatus()` method to retrieve the client readiness status properties (`isReady`, `isReadyFromCache`, etc).
34
- 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.
45
- Updated the SDK_READY_FROM_CACHE event to be emitted alongside the SDK_READY event if it hasn’t already been emitted.
56

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
@@ -695,6 +695,52 @@ declare namespace SplitIO {
695695
[status in ConsentStatus]: ConsentStatus;
696696
};
697697
}
698+
/**
699+
* Readiness Status interface. It represents the readiness state of an SDK client.
700+
*/
701+
interface ReadinessStatus {
702+
703+
/**
704+
* `isReady` indicates if the client has triggered an `SDK_READY` event and
705+
* thus is ready to evaluate with cached data synchronized with the backend.
706+
*/
707+
isReady: boolean;
708+
709+
/**
710+
* `isReadyFromCache` indicates if the client has triggered an `SDK_READY_FROM_CACHE` event and
711+
* thus is ready to evaluate with cached data, although the data in cache might be stale, not synchronized with the backend.
712+
*/
713+
isReadyFromCache: boolean;
714+
715+
/**
716+
* `isTimedout` indicates if the client has triggered an `SDK_READY_TIMED_OUT` event and is not ready to evaluate.
717+
* In other words, `isTimedout` is equivalent to `hasTimedout && !isReady`.
718+
*/
719+
isTimedout: boolean;
720+
721+
/**
722+
* `hasTimedout` indicates if the client has ever triggered an `SDK_READY_TIMED_OUT` event.
723+
* It's meant to keep a reference that the SDK emitted a timeout at some point, not the current state.
724+
*/
725+
hasTimedout: boolean;
726+
727+
/**
728+
* `isDestroyed` indicates if the client has been destroyed, i.e., `destroy` method has been called.
729+
*/
730+
isDestroyed: boolean;
731+
732+
/**
733+
* `isOperational` indicates if the client can evaluate feature flags.
734+
* In this state, `getTreatment` calls will not return `CONTROL` due to the SDK being unready or destroyed.
735+
* It's equivalent to `isReadyFromCache && !isDestroyed`.
736+
*/
737+
isOperational: boolean;
738+
739+
/**
740+
* `lastUpdate` indicates the timestamp of the most recent status event.
741+
*/
742+
lastUpdate: number;
743+
}
698744
/**
699745
* Common API for entities that expose status handlers.
700746
*/
@@ -703,6 +749,12 @@ declare namespace SplitIO {
703749
* Constant object containing the SDK events for you to use.
704750
*/
705751
Event: EventConsts;
752+
/**
753+
* Gets the readiness status.
754+
*
755+
* @returns The current readiness status.
756+
*/
757+
getStatus(): ReadinessStatus;
706758
/**
707759
* 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).
708760
* 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)