From b4348834fdc11568ef496c13e3b55ebc68797eef Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Thu, 12 Sep 2024 13:31:46 -0300 Subject: [PATCH 1/5] Add selectStatus selector --- CHANGES.txt | 1 + src/index.ts | 2 +- src/selectors.ts | 9 ++++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 7e5e215..ac95a7e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,7 @@ 1.14.0 (September XX, 2024) - Added `status` property to Split reducer's slice of state to track the SDK events of non-default clients (Related to https://github.com/splitio/redux-client/issues/113). - Added `lastUpdate` and `isTimedout` properties to the object returned by the `getStatus` helper and `selectTreatmentAndStatus` and `selectTreatmentWithConfigAndStatus` selectors, to expose the last event timestamp and the timedout status of the SDK clients (Related to https://github.com/splitio/redux-client/issues/113). + - Added `selectStatus` selector to retrieve the status properties of the SDK manager and clients from the Split state. - Updated `selectTreatmentAndStatus` and `selectTreatmentWithConfigAndStatus` selectors to retrieve status properties from the state rather than the SDK client instances directly. - Updated @splitsoftware/splitio package to version 10.28.0 that includes minor updates: - Added `sync.requestOptions.getHeaderOverrides` configuration option to enhance SDK HTTP request Headers for Authorization Frameworks. diff --git a/src/index.ts b/src/index.ts index c99eda8..6feb589 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ export { splitReducer } from './reducer'; export { initSplitSdk, getTreatments, destroySplitSdk, splitSdk } from './asyncActions'; export { track, getSplitNames, getSplit, getSplits, getStatus } from './helpers'; -export { selectTreatmentValue, selectTreatmentWithConfig, selectTreatmentAndStatus, selectTreatmentWithConfigAndStatus } from './selectors'; +export { selectTreatmentValue, selectTreatmentWithConfig, selectTreatmentAndStatus, selectTreatmentWithConfigAndStatus, selectStatus } from './selectors'; // For React-redux export { connectSplit } from './react-redux/connectSplit'; diff --git a/src/selectors.ts b/src/selectors.ts index 9b43ed0..43ce15d 100644 --- a/src/selectors.ts +++ b/src/selectors.ts @@ -84,7 +84,14 @@ export function selectTreatmentWithConfigAndStatus(splitState: ISplitState, feat }; } -function selectStatus(splitState: ISplitState, key?: SplitIO.SplitKey): IStatus { +/** + * This function extracts the status properties of the client for the given user key from the Split state. + * If no user key is provided, it returns the status properties of the main client, which matches the SDK manager status. + * + * @param {ISplitState} splitState + * @param {SplitIO.SplitKey} key + */ +export function selectStatus(splitState: ISplitState, key?: SplitIO.SplitKey): IStatus { const status = splitState ? isMainClient(key) ? splitState : From bd8c52ffa82bb249beb7140545402abe5d40965f Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Thu, 12 Sep 2024 16:23:59 -0300 Subject: [PATCH 2/5] Update type definition comments --- CHANGES.txt | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/helpers.ts | 8 +++----- src/selectors.ts | 10 +++++++--- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 5dd2d4e..5dca282 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,4 @@ -1.14.0 (September 12, 2024) +1.14.0 (September 13, 2024) - Added `status` property to Split reducer's slice of state to track the SDK events of non-default clients (Related to https://github.com/splitio/redux-client/issues/113). - Added `lastUpdate` and `isTimedout` properties to the object returned by the `getStatus` helper and `selectTreatmentAndStatus` and `selectTreatmentWithConfigAndStatus` selectors, to expose the last event timestamp and the timedout status of the SDK clients (Related to https://github.com/splitio/redux-client/issues/113). - Added `selectStatus` selector to retrieve the status properties of the SDK manager and clients from the Split state. diff --git a/package-lock.json b/package-lock.json index 0df10ce..f1d0bdc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@splitsoftware/splitio-redux", - "version": "1.14.0", + "version": "1.13.1-rc.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@splitsoftware/splitio-redux", - "version": "1.14.0", + "version": "1.13.1-rc.2", "license": "Apache-2.0", "dependencies": { "@splitsoftware/splitio": "10.28.0", diff --git a/package.json b/package.json index a1715c3..22fc534 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@splitsoftware/splitio-redux", - "version": "1.14.0", + "version": "1.13.1-rc.2", "description": "A library to easily use Split JS SDK with Redux and React Redux", "main": "lib/index.js", "module": "es/index.js", diff --git a/src/helpers.ts b/src/helpers.ts index 73a12ee..4b658ac 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -87,12 +87,10 @@ export function getSplits(): SplitIO.SplitViews { } /** - * Gets an object with the status properties of the SDK client or manager: + * Gets an object with the status properties of the SDK client or manager. * - * - `isReady` indicates if the SDK client has emitted the SDK_READY event. - * - `isReadyFromCache` indicates if the SDK client has emitted the SDK_READY_FROM_CACHE event. - * - `hasTimedout` indicates if the SDK client has emitted the SDK_READY_TIMED_OUT event. - * - `isDestroyed` indicates if the SDK client has been destroyed, i.e., if the `destroySplitSdk` action was dispatched. + * This function is similar to the `selectStatus` selector, but it does not require the Split state as a parameter since it uses the global `splitSdk` object. + * Consider using the `selectStatus` selector instead for a more Redux-friendly approach. * * @param {SplitIO.SplitKey} key To use only on client-side. Ignored in server-side. If a key is provided and a client associated to that key has been used, the status of that client is returned. * If no key is provided, the status of the main client and manager is returned (the main client shares the status with the manager). diff --git a/src/selectors.ts b/src/selectors.ts index 43ce15d..c678d35 100644 --- a/src/selectors.ts +++ b/src/selectors.ts @@ -85,11 +85,15 @@ export function selectTreatmentWithConfigAndStatus(splitState: ISplitState, feat } /** - * This function extracts the status properties of the client for the given user key from the Split state. - * If no user key is provided, it returns the status properties of the main client, which matches the SDK manager status. + * Extracts an object with the status properties of the SDK manager or client from the Split state, for the given user key. * * @param {ISplitState} splitState - * @param {SplitIO.SplitKey} key + * @param {SplitIO.SplitKey} key To use only on client-side. Ignored in server-side. If a key is provided and a client associated to that key has been used, the status of that client is returned. + * If no key is provided, the status of the main client and manager is returned (the main client shares the status with the manager). + * + * @returns {IStatus} The status of the SDK client or manager. + * + * @see {@link https://help.split.io/hc/en-us/articles/360038851551-Redux-SDK#subscribe-to-events} */ export function selectStatus(splitState: ISplitState, key?: SplitIO.SplitKey): IStatus { const status = splitState ? From d728b47b0adef50cdc1267fff9c6aa6cccef4aa4 Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Thu, 12 Sep 2024 16:45:17 -0300 Subject: [PATCH 3/5] Export remaining types --- CHANGES.txt | 1 + package-lock.json | 4 ++-- package.json | 2 +- src/index.ts | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 5dca282..441f867 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,6 +2,7 @@ - Added `status` property to Split reducer's slice of state to track the SDK events of non-default clients (Related to https://github.com/splitio/redux-client/issues/113). - Added `lastUpdate` and `isTimedout` properties to the object returned by the `getStatus` helper and `selectTreatmentAndStatus` and `selectTreatmentWithConfigAndStatus` selectors, to expose the last event timestamp and the timedout status of the SDK clients (Related to https://github.com/splitio/redux-client/issues/113). - Added `selectStatus` selector to retrieve the status properties of the SDK manager and clients from the Split state. + - Added remaining TypeScript types and interfaces to the library index exports, allowing them to be imported from the library index in TypeScript, e.g., `import type { IInitSplitSdkParams } from '@splitsoftware/splitio-redux'`. - Updated `selectTreatmentAndStatus` and `selectTreatmentWithConfigAndStatus` selectors to retrieve status properties from the state rather than the SDK client instances directly. - Updated @splitsoftware/splitio package to version 10.28.0 that includes minor updates: - Added `sync.requestOptions.getHeaderOverrides` configuration option to enhance SDK HTTP request Headers for Authorization Frameworks. diff --git a/package-lock.json b/package-lock.json index f1d0bdc..88845ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@splitsoftware/splitio-redux", - "version": "1.13.1-rc.2", + "version": "1.13.1-rc.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@splitsoftware/splitio-redux", - "version": "1.13.1-rc.2", + "version": "1.13.1-rc.3", "license": "Apache-2.0", "dependencies": { "@splitsoftware/splitio": "10.28.0", diff --git a/package.json b/package.json index 22fc534..66b4f97 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@splitsoftware/splitio-redux", - "version": "1.13.1-rc.2", + "version": "1.13.1-rc.3", "description": "A library to easily use Split JS SDK with Redux and React Redux", "main": "lib/index.js", "module": "es/index.js", diff --git a/src/index.ts b/src/index.ts index 6feb589..cf8060e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,4 +8,5 @@ export { selectTreatmentValue, selectTreatmentWithConfig, selectTreatmentAndStat export { connectSplit } from './react-redux/connectSplit'; export { connectToggler, mapTreatmentToProps, mapIsFeatureOnToProps } from './react-redux/connectToggler'; -export { ISplitState } from './types'; +// Types +export type { IStatus, ISplitState, IGetSplitState, IInitSplitSdkParams, IGetTreatmentsParams, IDestroySplitSdkParams, ITrackParams } from './types'; From 0677eebe6afbb39bdd3c68c5f0fd98bdceac7dc2 Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Thu, 12 Sep 2024 16:52:39 -0300 Subject: [PATCH 4/5] Fix some links --- package-lock.json | 4 ++-- package.json | 2 +- src/types.ts | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 88845ce..0df10ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@splitsoftware/splitio-redux", - "version": "1.13.1-rc.3", + "version": "1.14.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@splitsoftware/splitio-redux", - "version": "1.13.1-rc.3", + "version": "1.14.0", "license": "Apache-2.0", "dependencies": { "@splitsoftware/splitio": "10.28.0", diff --git a/package.json b/package.json index 66b4f97..a1715c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@splitsoftware/splitio-redux", - "version": "1.13.1-rc.3", + "version": "1.14.0", "description": "A library to easily use Split JS SDK with Redux and React Redux", "main": "lib/index.js", "module": "es/index.js", diff --git a/src/types.ts b/src/types.ts index 4a0909d..4b2d6ab 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,7 +4,7 @@ export interface IStatus { /** * isReady indicates if Split client is ready, i.e., if it has emitted an SDK_READY event. - * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#advanced-subscribe-to-events-and-changes} + * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#subscribe-to-events} */ isReady: boolean; @@ -12,21 +12,21 @@ export interface IStatus { * isReadyFromCache indicates if Split client has emitted an SDK_READY_FROM_CACHE event, what means that the SDK is ready to * evaluate using LocalStorage cached data (which might be stale). * This flag only applies for the Browser if using LOCALSTORAGE as storage type. - * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#advanced-subscribe-to-events-and-changes} + * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#subscribe-to-events} */ isReadyFromCache: boolean; /** * isTimedout indicates if the Split client has emitted an SDK_READY_TIMED_OUT event and is not ready. * In other words, `isTimedout` is equivalent to `hasTimeout && !isReady`. - * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#advanced-subscribe-to-events-and-changes} + * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#subscribe-to-events} */ isTimedout: boolean; /** * hasTimedout indicates if the Split client has ever emitted 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. - * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#advanced-subscribe-to-events-and-changes} + * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#subscribe-to-events} */ hasTimedout: boolean; @@ -38,7 +38,7 @@ export interface IStatus { /** * lastUpdate is the timestamp of the last Split client event (SDK_READY, SDK_READY_TIMED_OUT or SDK_UPDATE). - * @see {@link https://help.split.io/hc/en-us/articles/360038851551-Redux-SDK#advanced-subscribe-to-events-and-changes} + * @see {@link https://help.split.io/hc/en-us/articles/360038851551-Redux-SDK#subscribe-to-events} */ lastUpdate: number; } From c7433a3e5c722605d09e3b64fdc1a3d2777e1aff Mon Sep 17 00:00:00 2001 From: Emiliano Sanchez Date: Thu, 12 Sep 2024 17:05:51 -0300 Subject: [PATCH 5/5] Fix export --- src/index.ts | 2 +- src/selectors.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index cf8060e..0aefb73 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,4 +9,4 @@ export { connectSplit } from './react-redux/connectSplit'; export { connectToggler, mapTreatmentToProps, mapIsFeatureOnToProps } from './react-redux/connectToggler'; // Types -export type { IStatus, ISplitState, IGetSplitState, IInitSplitSdkParams, IGetTreatmentsParams, IDestroySplitSdkParams, ITrackParams } from './types'; +export { IStatus, ISplitState, IGetSplitState, IInitSplitSdkParams, IGetTreatmentsParams, IDestroySplitSdkParams, ITrackParams } from './types'; diff --git a/src/selectors.ts b/src/selectors.ts index c678d35..ed1411e 100644 --- a/src/selectors.ts +++ b/src/selectors.ts @@ -85,7 +85,7 @@ export function selectTreatmentWithConfigAndStatus(splitState: ISplitState, feat } /** - * Extracts an object with the status properties of the SDK manager or client from the Split state, for the given user key. + * Extracts an object with the status properties of the SDK client or manager from the Split state. * * @param {ISplitState} splitState * @param {SplitIO.SplitKey} key To use only on client-side. Ignored in server-side. If a key is provided and a client associated to that key has been used, the status of that client is returned.