Skip to content
Draft
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
4 changes: 2 additions & 2 deletions src/readiness/__tests__/sdkReadinessManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ describe('SDK Readiness Manager - Event emitter', () => {
});

expect(typeof sdkStatus.ready).toBe('function'); // The sdkStatus exposes a .ready() function.
expect(typeof sdkStatus.__getStatus).toBe('function'); // The sdkStatus exposes a .__getStatus() function.
expect(sdkStatus.__getStatus()).toEqual({
expect(typeof sdkStatus.getStatus).toBe('function'); // The sdkStatus exposes a .getStatus() function.
expect(sdkStatus.getStatus()).toEqual({
isReady: false, isReadyFromCache: false, isTimedout: false, hasTimedout: false, isDestroyed: false, isOperational: false, lastUpdate: 0
});

Expand Down
2 changes: 1 addition & 1 deletion src/readiness/sdkReadinessManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function sdkReadinessManagerFactory(
return readyPromise;
},

__getStatus() {
getStatus() {
return {
isReady: readinessManager.isReady(),
isReadyFromCache: readinessManager.isReadyFromCache(),
Expand Down
3 changes: 1 addition & 2 deletions src/readiness/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { IStatusInterface } from '../types';
import SplitIO from '../../types/splitio';

/** Splits data emitter */
Expand Down Expand Up @@ -72,7 +71,7 @@ export interface IReadinessManager {

export interface ISdkReadinessManager {
readinessManager: IReadinessManager
sdkStatus: IStatusInterface
sdkStatus: SplitIO.IStatusInterface

/**
* Increment internalReadyCbCount, an offset value of SDK_READY listeners that are added/removed internally
Expand Down
15 changes: 0 additions & 15 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ export interface ISettings extends SplitIO.ISettings {
readonly initialRolloutPlan?: RolloutPlan;
}

/**
* SplitIO.IStatusInterface interface extended with private properties for internal use
*/
export interface IStatusInterface extends SplitIO.IStatusInterface {
// Expose status for internal purposes only. Not considered part of the public API, and might be updated eventually.
__getStatus(): {
isReady: boolean;
isReadyFromCache: boolean;
isTimedout: boolean;
hasTimedout: boolean;
isDestroyed: boolean;
isOperational: boolean;
lastUpdate: number;
};
}
/**
* SplitIO.IBasicClient interface extended with private properties for internal use
*/
Expand Down
52 changes: 52 additions & 0 deletions types/splitio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,52 @@ declare namespace SplitIO {
[status in ConsentStatus]: ConsentStatus;
};
}
/**
* Readiness Status interface. It represents the readiness state of an SDK client.
*/
interface ReadinessStatus {

/**
* `isReady` indicates if the client has triggered an `SDK_READY` event and
* thus is ready to evaluate with cached data synchronized with the backend.
*/
isReady: boolean;

/**
* `isReadyFromCache` indicates if the client has triggered an `SDK_READY_FROM_CACHE` event and
* thus is ready to evaluate with cached data, although the data in cache might be stale.
*/
isReadyFromCache: boolean;

/**
* `isTimedout` indicates if the client has triggered an `SDK_READY_TIMED_OUT` event and is not ready to evaluate.
* In other words, `isTimedout` is equivalent to `hasTimedout && !isReady`.
*/
isTimedout: boolean;

/**
* `hasTimedout` indicates if the client has ever triggered an `SDK_READY_TIMED_OUT` event.
* It's meant to keep a reference that the SDK emitted a timeout at some point, not the current state.
*/
hasTimedout: boolean;

/**
* `isDestroyed` indicates if the client has been destroyed, i.e., `destroy` method has been called.
*/
isDestroyed: boolean;

/**
* `isOperational` indicates if the client can evaluate feature flags.
* In this state, `getTreatment` calls will not return `CONTROL` due to the SDK being unready or destroyed.
* It's equivalent to `(isReady || isReadyFromCache) && !isDestroyed`.
*/
isOperational: boolean;

/**
* `lastUpdate` indicates the timestamp of the most recent status event.
*/
lastUpdate: number;
}
/**
* Common API for entities that expose status handlers.
*/
Expand All @@ -676,6 +722,12 @@ declare namespace SplitIO {
* Constant object containing the SDK events for you to use.
*/
Event: EventConsts;
/**
* Gets the readiness status.
*
* @returns The current readiness status.
*/
getStatus(): ReadinessStatus;
/**
* Returns a promise that resolves once the SDK has finished loading (`SDK_READY` event emitted) or rejected if the SDK has timedout (`SDK_READY_TIMED_OUT` event emitted).
* 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.
Expand Down