Skip to content

Commit adc9fe7

Browse files
Merge pull request #134 from splitio/upgrade_js_sdk
Upgrade JS SDK and add Impression Properties support
2 parents f0da593 + 49b7a1c commit adc9fe7

11 files changed

+198
-187
lines changed

CHANGES.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2.1.0 (April 1, 2025)
2+
- Added a new optional `properties` argument to the options object of the `getTreatments` action creator, allowing to pass a map of properties to append to the generated impressions sent to Split backend. Read more in our docs.
3+
- Updated @splitsoftware/splitio package to version 11.2.0 that includes some minor updates:
4+
- Added support for the new impressions tracking toggle available on feature flags, both respecting the setting and including the new field being returned on `SplitView` type objects. Read more in our docs.
5+
- Added two new configuration options for the SDK's `LOCALSTORAGE` storage type to control the behavior of the persisted rollout plan cache in the browser:
6+
- `storage.expirationDays` to specify the validity period of the rollout plan cache in days.
7+
- `storage.clearOnInit` to clear the rollout plan cache on SDK initialization.
8+
- Updated SDK_READY_FROM_CACHE event when using the `LOCALSTORAGE` storage type to be emitted alongside the SDK_READY event if it has not already been emitted.
9+
110
2.0.1 (December 5, 2024)
211
- Updated @splitsoftware/splitio package to version 11.0.3 that includes some improvements and bugfixes.
312
- Bugfixing - Fixed issue where the `SplitIO` namespace from `@splitsoftware/splitio` was not accessible through the library, enabling users to use the namespace without additional imports (Related to https://github.com/splitio/redux-client/issues/130).

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright © 2024 Split Software, Inc.
1+
Copyright © 2025 Split Software, Inc.
22

33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Split has built and maintains SDKs for:
9393
* .NET [Github](https://github.com/splitio/dotnet-client) [Docs](https://help.split.io/hc/en-us/articles/360020240172--NET-SDK)
9494
* Android [Github](https://github.com/splitio/android-client) [Docs](https://help.split.io/hc/en-us/articles/360020343291-Android-SDK)
9595
* Angular [Github](https://github.com/splitio/angular-sdk-plugin) [Docs](https://help.split.io/hc/en-us/articles/6495326064397-Angular-utilities)
96+
* Elixir thin-client [Github](https://github.com/splitio/elixir-thin-client) [Docs](https://help.split.io/hc/en-us/articles/26988707417869-Elixir-Thin-Client-SDK)
9697
* Flutter [Github](https://github.com/splitio/flutter-sdk-plugin) [Docs](https://help.split.io/hc/en-us/articles/8096158017165-Flutter-plugin)
9798
* GO [Github](https://github.com/splitio/go-client) [Docs](https://help.split.io/hc/en-us/articles/360020093652-Go-SDK)
9899
* iOS [Github](https://github.com/splitio/ios-client) [Docs](https://help.split.io/hc/en-us/articles/360020401491-iOS-SDK)
@@ -112,4 +113,4 @@ For a comprehensive list of open source projects visit our [Github page](https:/
112113

113114
**Learn more about Split:**
114115

115-
Visit [split.io/product](https://www.split.io/product) for an overview of Split, or visit our documentation at [help.split.io](http://help.split.io) for more detailed information.
116+
Visit [split.io/product](https://www.split.io/product) for an overview of Split, or visit our documentation at [help.split.io](https://help.split.io) for more detailed information.

package-lock.json

Lines changed: 143 additions & 156 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splitsoftware/splitio-redux",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"description": "A library to easily use Split JS SDK with Redux and React Redux",
55
"main": "cjs/index.js",
66
"module": "esm/index.js",
@@ -59,7 +59,7 @@
5959
},
6060
"homepage": "https://github.com/splitio/redux-client#readme",
6161
"dependencies": {
62-
"@splitsoftware/splitio": "11.0.3",
62+
"@splitsoftware/splitio": "11.2.0",
6363
"tslib": "^2.3.1"
6464
},
6565
"devDependencies": {

src/__tests__/asyncActions.browser.test.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ describe('getTreatments', () => {
222222
});
223223

224224
// getting the evaluation result and validating it matches the results from SDK
225-
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveBeenCalledWith(['split1'], undefined);
225+
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveBeenCalledWith(['split1'], undefined, undefined);
226226
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveReturnedWith(actions[0].payload.treatments);
227-
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveBeenLastCalledWith(['split2'], undefined);
227+
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveBeenLastCalledWith(['split2'], undefined, undefined);
228228
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveLastReturnedWith(actions[1].payload.treatments);
229-
expect(splitSdk.factory.client().getTreatmentsWithConfigByFlagSets).toHaveBeenLastCalledWith(['set1'], undefined);
229+
expect(splitSdk.factory.client().getTreatmentsWithConfigByFlagSets).toHaveBeenLastCalledWith(['set1'], undefined, undefined);
230230
expect(splitSdk.factory.client().getTreatmentsWithConfigByFlagSets).toHaveLastReturnedWith(actions[2].payload.treatments);
231231

232232
expect(getClient(splitSdk).evalOnUpdate).toEqual({});
@@ -258,7 +258,7 @@ describe('getTreatments', () => {
258258
treatments: expect.any(Object)
259259
}
260260
});
261-
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveBeenNthCalledWith(1, ['split1'], undefined);
261+
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveBeenNthCalledWith(1, ['split1'], undefined, undefined);
262262
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveNthReturnedWith(1, action.payload.treatments);
263263

264264
// getting the 2nd evaluation result and validating it matches the results from SDK
@@ -270,7 +270,7 @@ describe('getTreatments', () => {
270270
treatments: expect.any(Object)
271271
}
272272
});
273-
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveBeenNthCalledWith(2, ['split2', 'split3'], attributes);
273+
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveBeenNthCalledWith(2, ['split2', 'split3'], attributes, undefined);
274274
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveNthReturnedWith(2, action.payload.treatments);
275275
expect(getClient(splitSdk).evalOnUpdate).toEqual({}); // control assertion - cbs scheduled for update
276276
expect(getClient(splitSdk).evalOnReady.length).toEqual(2); // control assertion - cbs scheduled for ready
@@ -294,8 +294,8 @@ describe('getTreatments', () => {
294294
expect(store.getActions().length).toBe(4);
295295

296296
// getting the evaluation result and validating it matches the results from SDK calls
297-
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveBeenNthCalledWith(3, ['split1'], undefined);
298-
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveBeenNthCalledWith(4, ['split2', 'split3'], attributes);
297+
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveBeenNthCalledWith(3, ['split1'], undefined, undefined);
298+
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveBeenNthCalledWith(4, ['split2', 'split3'], attributes, undefined);
299299
const expectedTreatments = {
300300
...(splitSdk.factory.client().getTreatmentsWithConfig as jest.Mock).mock.results[2].value,
301301
...(splitSdk.factory.client().getTreatmentsWithConfig as jest.Mock).mock.results[3].value,
@@ -369,8 +369,8 @@ describe('getTreatments', () => {
369369

370370
// getting the evaluation result and validating it matches the results from SDK
371371
const treatments = action.payload.treatments;
372-
expect(splitSdk.factory.client().getTreatmentsWithConfig).toBeCalledWith(['split2'], undefined);
373-
expect(splitSdk.factory.client().getTreatmentsWithConfigByFlagSets).toBeCalledWith(['set2'], undefined);
372+
expect(splitSdk.factory.client().getTreatmentsWithConfig).toBeCalledWith(['split2'], undefined, undefined);
373+
expect(splitSdk.factory.client().getTreatmentsWithConfigByFlagSets).toBeCalledWith(['set2'], undefined, undefined);
374374
expect(treatments).toEqual({
375375
...(splitSdk.factory.client().getTreatmentsWithConfig as jest.Mock).mock.results[0].value,
376376
...(splitSdk.factory.client().getTreatmentsWithConfigByFlagSets as jest.Mock).mock.results[0].value,
@@ -395,7 +395,8 @@ describe('getTreatments', () => {
395395
store.dispatch<any>(initSplitSdk({ config: sdkBrowserConfig, onTimedout: onTimedoutCb, onReadyFromCache: onReadyFromCacheCb, onReady: onReadyCb }));
396396

397397
const attributes = { att1: 'att1' };
398-
store.dispatch<any>(getTreatments({ splitNames: 'split3', attributes, evalOnUpdate: true, evalOnReadyFromCache: true }));
398+
const properties = { prop1: 'prop1' };
399+
store.dispatch<any>(getTreatments({ splitNames: 'split3', attributes, properties, evalOnUpdate: true, evalOnReadyFromCache: true }));
399400

400401
// If SDK is not ready, an ADD_TREATMENTS action is dispatched with control treatments without calling SDK client
401402
expect(store.getActions().length).toBe(0);
@@ -436,7 +437,7 @@ describe('getTreatments', () => {
436437

437438
// getting the evaluation result and validating it matches the results from SDK
438439
const treatments = action.payload.treatments;
439-
expect(splitSdk.factory.client().getTreatmentsWithConfig).lastCalledWith(['split3'], attributes);
440+
expect(splitSdk.factory.client().getTreatmentsWithConfig).lastCalledWith(['split3'], attributes, { properties });
440441
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveLastReturnedWith(treatments);
441442
}
442443

@@ -458,7 +459,7 @@ describe('getTreatments', () => {
458459

459460
// getting the evaluation result and validating it matches the results from SDK
460461
let treatments = action.payload.treatments;
461-
expect(splitSdk.factory.client().getTreatmentsWithConfig).lastCalledWith(['split3'], attributes);
462+
expect(splitSdk.factory.client().getTreatmentsWithConfig).lastCalledWith(['split3'], attributes, { properties });
462463
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveLastReturnedWith(treatments);
463464

464465
expect(Object.values(getClient(splitSdk).evalOnUpdate).length).toBe(1); // control assertion - We should have an item to evaluate on update
@@ -478,7 +479,7 @@ describe('getTreatments', () => {
478479

479480
// getting the evaluation result and validating it matches the results from SDK
480481
treatments = action.payload.treatments;
481-
expect(splitSdk.factory.client().getTreatmentsWithConfig).lastCalledWith(['split3'], attributes);
482+
expect(splitSdk.factory.client().getTreatmentsWithConfig).lastCalledWith(['split3'], attributes, { properties });
482483
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveLastReturnedWith(treatments);
483484

484485
expect(Object.values(getClient(splitSdk).evalOnUpdate).length).toBe(1); // control assertion - still have one evalOnUpdate subscription
@@ -546,7 +547,7 @@ describe('getTreatments', () => {
546547
}
547548
});
548549

549-
expect(splitSdk.factory.client('other-user-key').getTreatmentsWithConfig).lastCalledWith(['split2'], undefined);
550+
expect(splitSdk.factory.client('other-user-key').getTreatmentsWithConfig).lastCalledWith(['split2'], undefined, undefined);
550551
expect(splitSdk.factory.client('other-user-key').getTreatmentsWithConfig).toHaveLastReturnedWith(action.payload.treatments);
551552

552553
(splitSdk.factory as any).client('other-user-key').__emitter__.emit(Event.SDK_READY, 'other-user-key');
@@ -564,14 +565,15 @@ describe('getTreatments', () => {
564565
});
565566

566567
// getting the evaluation result and validating it matches the results from SDK
567-
expect(splitSdk.factory.client('other-user-key').getTreatmentsWithConfig).lastCalledWith(['split2'], undefined);
568+
expect(splitSdk.factory.client('other-user-key').getTreatmentsWithConfig).lastCalledWith(['split2'], undefined, undefined);
568569
expect(splitSdk.factory.client('other-user-key').getTreatmentsWithConfig).toHaveLastReturnedWith(action.payload.treatments);
569570

570571
expect(getClient(splitSdk).evalOnUpdate).toEqual({}); // control assertion
571572

572573
// The getTreatments is dispatched again, but this time is evaluated with attributes and registered for 'evalOnUpdate'
573574
const attributes = { att1: 'att1' };
574-
store.dispatch<any>(getTreatments({ splitNames: 'split2', attributes, key: 'other-user-key', evalOnUpdate: true }));
575+
const properties = { prop1: 'prop1' };
576+
store.dispatch<any>(getTreatments({ splitNames: 'split2', attributes, properties, key: 'other-user-key', evalOnUpdate: true }));
575577
action = store.getActions()[4];
576578
expect(action).toEqual({
577579
type: ADD_TREATMENTS,
@@ -580,7 +582,7 @@ describe('getTreatments', () => {
580582
treatments: expect.any(Object)
581583
}
582584
});
583-
expect(splitSdk.factory.client('other-user-key').getTreatmentsWithConfig).lastCalledWith(['split2'], attributes);
585+
expect(splitSdk.factory.client('other-user-key').getTreatmentsWithConfig).lastCalledWith(['split2'], attributes, { properties });
584586
expect(Object.values(getClient(splitSdk, 'other-user-key').evalOnUpdate).length).toBe(1); // control assertion - added evalOnUpdate subscription
585587

586588
// The SPLIT_UPDATE_WITH_EVALUATIONS action is dispatched when the SDK is updated for the new user key
@@ -595,7 +597,7 @@ describe('getTreatments', () => {
595597
nonDefaultKey: true
596598
}
597599
});
598-
expect(splitSdk.factory.client('other-user-key').getTreatmentsWithConfig).lastCalledWith(['split2'], attributes);
600+
expect(splitSdk.factory.client('other-user-key').getTreatmentsWithConfig).lastCalledWith(['split2'], attributes, { properties });
599601
expect(splitSdk.factory.client('other-user-key').getTreatmentsWithConfig).toHaveLastReturnedWith(action.payload.treatments);
600602
expect(Object.values(getClient(splitSdk, 'other-user-key').evalOnUpdate).length).toBe(1); // control assertion - keeping evalOnUpdate subscription
601603

@@ -609,7 +611,7 @@ describe('getTreatments', () => {
609611
treatments: expect.any(Object)
610612
}
611613
});
612-
expect(splitSdk.factory.client('other-user-key').getTreatmentsWithConfig).lastCalledWith(['split2'], undefined);
614+
expect(splitSdk.factory.client('other-user-key').getTreatmentsWithConfig).lastCalledWith(['split2'], undefined, undefined);
613615
expect(splitSdk.factory.client('other-user-key').getTreatmentsWithConfig).toHaveLastReturnedWith(action.payload.treatments);
614616
expect(Object.values(getClient(splitSdk).evalOnUpdate).length).toBe(0); // control assertion - removed evalOnUpdate subscription
615617

src/__tests__/asyncActions.node.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,16 @@ describe('getTreatments', () => {
191191
}
192192
});
193193
});
194-
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveBeenLastCalledWith(splitKey, ['split1'], undefined);
194+
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveBeenLastCalledWith(splitKey, ['split1'], undefined, undefined);
195195
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveLastReturnedWith(actions[0].payload.treatments);
196-
expect(splitSdk.factory.client().getTreatmentsWithConfigByFlagSets).toHaveBeenLastCalledWith(splitKey, ['set1'], undefined);
196+
expect(splitSdk.factory.client().getTreatmentsWithConfigByFlagSets).toHaveBeenLastCalledWith(splitKey, ['set1'], undefined, undefined);
197197
expect(splitSdk.factory.client().getTreatmentsWithConfigByFlagSets).toHaveLastReturnedWith(actions[1].payload.treatments);
198198

199199
// Invoke with a list of feature flag names and a attributes object
200200
const featureFlagNames = ['split1', 'split2'];
201201
const attributes = { att1: 'att1' };
202-
store.dispatch<any>(getTreatments({ key: 'other_user', splitNames: featureFlagNames, attributes }));
202+
const properties = { prop1: 'prop1' };
203+
store.dispatch<any>(getTreatments({ key: 'other_user', splitNames: featureFlagNames, attributes, properties }));
203204

204205
const action = store.getActions()[3];
205206
expect(action).toEqual({
@@ -209,7 +210,7 @@ describe('getTreatments', () => {
209210
treatments: expect.any(Object)
210211
}
211212
});
212-
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveBeenLastCalledWith('other_user', featureFlagNames, attributes);
213+
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveBeenLastCalledWith('other_user', featureFlagNames, attributes, { properties });
213214
expect(splitSdk.factory.client().getTreatmentsWithConfig).toHaveLastReturnedWith(action.payload.treatments);
214215
}
215216

src/__tests__/helpers.browser.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const featureFlagViews: SplitIO.SplitViews = [
3434
configs: { on: null, off: null },
3535
sets: [],
3636
defaultTreatment: 'off',
37+
impressionsDisabled: false,
3738
}, {
3839
name: 'split_2',
3940
trafficType: 'user',
@@ -43,6 +44,7 @@ const featureFlagViews: SplitIO.SplitViews = [
4344
configs: { on: null, off: null },
4445
sets: [],
4546
defaultTreatment: 'off',
47+
impressionsDisabled: false,
4648
},
4749
];
4850

src/__tests__/helpers.node.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const featureFlagViews: SplitIO.SplitViews = [
3333
configs: { on: null, off: null },
3434
sets: [],
3535
defaultTreatment: 'off',
36+
impressionsDisabled: false,
3637
}, {
3738
name: 'split_2',
3839
trafficType: 'user',
@@ -42,6 +43,7 @@ const featureFlagViews: SplitIO.SplitViews = [
4243
configs: { on: null, off: null },
4344
sets: [],
4445
defaultTreatment: 'off',
46+
impressionsDisabled: false,
4547
},
4648
];
4749

src/asyncActions.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@ export function initSplitSdk(params: IInitSplitSdkParams): (dispatch: Dispatch<A
9191
*/
9292
function __getTreatments(client: IClientNotDetached, evalParams: IGetTreatmentsParams[]): SplitIO.TreatmentsWithConfig {
9393
return evalParams.reduce((acc, params) => {
94+
const evaluationOptions = params.properties ? { properties: params.properties } : undefined;
9495
return {
9596
...acc,
9697
...(params.splitNames ?
97-
client.getTreatmentsWithConfig(params.splitNames as string[], params.attributes) :
98-
client.getTreatmentsWithConfigByFlagSets(params.flagSets as string[], params.attributes)
98+
client.getTreatmentsWithConfig(params.splitNames as string[], params.attributes, evaluationOptions) :
99+
client.getTreatmentsWithConfigByFlagSets(params.flagSets as string[], params.attributes, evaluationOptions)
99100
)
100101
};
101102
}, {});
@@ -171,9 +172,10 @@ export function getTreatments(params: IGetTreatmentsParams): Action | (() => voi
171172

172173
// Evaluate Split and return redux action.
173174
const client = splitSdk.factory.client() as SplitIO.IClient;
175+
const evaluationOptions = params.properties ? { properties: params.properties } : undefined;
174176
const treatments = splitNames ?
175-
client.getTreatmentsWithConfig(params.key, splitNames, params.attributes) :
176-
client.getTreatmentsWithConfigByFlagSets(params.key, flagSets, params.attributes);
177+
client.getTreatmentsWithConfig(params.key, splitNames, params.attributes, evaluationOptions) :
178+
client.getTreatmentsWithConfigByFlagSets(params.key, flagSets, params.attributes, evaluationOptions);
177179
return addTreatments(params.key, treatments);
178180

179181
}

0 commit comments

Comments
 (0)