Skip to content

Commit c1f3807

Browse files
Merge branch 'development' into enhanced_sdk_headers
2 parents a8d80cc + c08d5a8 commit c1f3807

File tree

7 files changed

+28
-6
lines changed

7 files changed

+28
-6
lines changed

CHANGES.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
1.17.0 (September 6, 2024)
1+
1.17.0 (September XX, 2024)
22
- Added `sync.requestOptions.getHeaderOverrides` configuration option to enhance SDK HTTP request Headers for Authorization Frameworks.
3-
- Added lastUpdate property to ReadinessManager to keep track of the timestamp of the last SDK event, used on React and Redux SDKs.
3+
- Added `isTimedout` and `lastUpdate` properties to IStatusInterface to keep track of the timestamp of the last SDK event, used on React and Redux SDKs.
44
- Updated some transitive dependencies for vulnerability fixes.
55

66
1.16.0 (June 13, 2024)

src/readiness/__tests__/readinessManager.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import { IReadinessManager } from '../types';
44
import { SDK_READY, SDK_UPDATE, SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED, SDK_READY_FROM_CACHE, SDK_SPLITS_CACHE_LOADED, SDK_READY_TIMED_OUT } from '../constants';
55

66
const timeoutMs = 100;
7-
const statusFlagsCount = 5;
7+
const statusFlagsCount = 7;
88

99
function assertInitialStatus(readinessManager: IReadinessManager) {
1010
expect(readinessManager.isReady()).toBe(false);
1111
expect(readinessManager.isReadyFromCache()).toBe(false);
12+
expect(readinessManager.isTimedout()).toBe(false);
1213
expect(readinessManager.hasTimedout()).toBe(false);
1314
expect(readinessManager.isDestroyed()).toBe(false);
1415
expect(readinessManager.isOperational()).toBe(false);
16+
expect(readinessManager.lastUpdate()).toBe(0);
1517
}
1618

1719
test('READINESS MANAGER / Share splits but segments (without timeout enabled)', (done) => {
@@ -153,6 +155,7 @@ describe('READINESS MANAGER / Timeout ready event', () => {
153155
timeoutCounter = 0;
154156

155157
readinessManager.gate.on(SDK_READY_TIMED_OUT, () => {
158+
expect(readinessManager.isTimedout()).toBe(true);
156159
expect(readinessManager.hasTimedout()).toBe(true);
157160
if (!readinessManager.isReady()) timeoutCounter++;
158161
});
@@ -166,6 +169,8 @@ describe('READINESS MANAGER / Timeout ready event', () => {
166169
test('should be fired once', (done) => {
167170
readinessManager.gate.on(SDK_READY, () => {
168171
expect(readinessManager.isReady()).toBe(true);
172+
expect(readinessManager.isTimedout()).toBe(false);
173+
expect(readinessManager.hasTimedout()).toBe(true);
169174
expect(timeoutCounter).toBe(1);
170175
done();
171176
});

src/readiness/__tests__/sdkReadinessManager.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ describe('SDK Readiness Manager - Event emitter', () => {
5050
});
5151

5252
expect(typeof sdkStatus.ready).toBe('function'); // The sdkStatus exposes a .ready() function.
53+
expect(typeof sdkStatus.__getStatus).toBe('function'); // The sdkStatus exposes a .__getStatus() function.
54+
expect(sdkStatus.__getStatus()).toEqual({
55+
isReady: false, isReadyFromCache: false, isTimedout: false, hasTimedout: false, isDestroyed: false, isOperational: false, lastUpdate: 0
56+
});
5357

5458
expect(typeof sdkStatus.Event).toBe('object'); // It also exposes the Event map,
5559
expect(sdkStatus.Event.SDK_READY).toBe(SDK_READY); // which contains the constants for the events, for backwards compatibility.

src/readiness/readinessManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ export function readinessManagerFactory(
143143
},
144144

145145
isReady() { return isReady; },
146-
hasTimedout() { return hasTimedout; },
147146
isReadyFromCache() { return isReadyFromCache; },
147+
isTimedout() { return hasTimedout && !isReady; },
148+
hasTimedout() { return hasTimedout; },
148149
isDestroyed() { return isDestroyed; },
149150
isOperational() { return (isReady || isReadyFromCache) && !isDestroyed; },
150151
lastUpdate() { return lastUpdate; }

src/readiness/sdkReadinessManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ export function sdkReadinessManagerFactory(
121121
return readyPromise;
122122
},
123123

124-
// Expose status for internal purposes only. Not considered part of the public API, and might be updated eventually.
125124
__getStatus() {
126125
return {
127126
isReady: readinessManager.isReady(),
128127
isReadyFromCache: readinessManager.isReadyFromCache(),
129-
isOperational: readinessManager.isOperational(),
128+
isTimedout: readinessManager.isTimedout(),
130129
hasTimedout: readinessManager.hasTimedout(),
131130
isDestroyed: readinessManager.isDestroyed(),
131+
isOperational: readinessManager.isOperational(),
132132
lastUpdate: readinessManager.lastUpdate(),
133133
};
134134
},

src/readiness/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export interface IReadinessManager {
5050
/** Readiness status */
5151
isReady(): boolean,
5252
isReadyFromCache(): boolean,
53+
isTimedout(): boolean,
5354
hasTimedout(): boolean,
5455
isDestroyed(): boolean,
5556
isOperational(): boolean,

src/types.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,17 @@ export interface IStatusInterface extends IEventEmitter {
409409
* @returns {Promise<void>}
410410
*/
411411
ready(): Promise<void>
412+
413+
// Expose status for internal purposes only. Not considered part of the public API, and might be updated eventually.
414+
__getStatus(): {
415+
isReady: boolean;
416+
isReadyFromCache: boolean;
417+
isTimedout: boolean;
418+
hasTimedout: boolean;
419+
isDestroyed: boolean;
420+
isOperational: boolean;
421+
lastUpdate: number;
422+
}
412423
}
413424
/**
414425
* Common definitions between clients for different environments interface.

0 commit comments

Comments
 (0)