Skip to content

Commit 818235b

Browse files
Revert "Revert "Add method to retrieve client readiness status synchronously""
This reverts commit e49de68.
1 parent e49de68 commit 818235b

File tree

5 files changed

+56
-20
lines changed

5 files changed

+56
-20
lines changed

src/readiness/__tests__/sdkReadinessManager.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ describe('SDK Readiness Manager - Event emitter', () => {
5151
});
5252

5353
expect(typeof sdkStatus.ready).toBe('function'); // The sdkStatus exposes a .ready() function.
54-
expect(typeof sdkStatus.__getStatus).toBe('function'); // The sdkStatus exposes a .__getStatus() function.
55-
expect(sdkStatus.__getStatus()).toEqual({
54+
expect(typeof sdkStatus.getStatus).toBe('function'); // The sdkStatus exposes a .getStatus() function.
55+
expect(sdkStatus.getStatus()).toEqual({
5656
isReady: false, isReadyFromCache: false, isTimedout: false, hasTimedout: false, isDestroyed: false, isOperational: false, lastUpdate: 0
5757
});
5858

src/readiness/sdkReadinessManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export function sdkReadinessManagerFactory(
132132
});
133133
},
134134

135-
__getStatus() {
135+
getStatus() {
136136
return {
137137
isReady: readinessManager.isReady(),
138138
isReadyFromCache: readinessManager.isReadyFromCache(),

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 once the SDK has finished synchronizing 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)