Skip to content

Commit 22d56cf

Browse files
Merge branch 'rb_segments_baseline' into rb_segments_test_updates
2 parents aecbd2c + 7219d06 commit 22d56cf

18 files changed

+276
-160
lines changed

CHANGES.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
11.2.0 (March 28, 2025)
2+
- Added a new optional argument to the client `getTreatment` methods to allow passing additional evaluation options, such as a map of properties to append to the generated impressions sent to Split backend. Read more in our docs.
3+
- 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:
4+
- `storage.expirationDays` to specify the validity period of the rollout plan cache in days.
5+
- `storage.clearOnInit` to clear the rollout plan cache on SDK initialization.
6+
- 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.
7+
18
11.1.0 (January 17, 2025)
29
- 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.
310
- Updated @splitsoftware/splitio-commons package to version 2.1.0.

package-lock.json

Lines changed: 16 additions & 15 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",
3-
"version": "11.1.0",
3+
"version": "11.2.0",
44
"description": "Split SDK",
55
"files": [
66
"README.md",
@@ -38,7 +38,7 @@
3838
"node": ">=14.0.0"
3939
},
4040
"dependencies": {
41-
"@splitsoftware/splitio-commons": "2.1.1-rc.0",
41+
"@splitsoftware/splitio-commons": "2.2.0",
4242
"bloom-filters": "^3.0.4",
4343
"ioredis": "^4.28.0",
4444
"js-yaml": "^3.13.1",

src/__tests__/browserSuites/impressions-listener.spec.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function (assert) {
4646
const testAttrs = { is_test: true };
4747

4848
// Impression listener is shared across all client instances and does not get affected by configurations.
49-
client.getTreatment('hierarchical_splits_test');
49+
client.getTreatment('hierarchical_splits_test', undefined, { properties: { prop1: 'prop-value' } });
5050
client2.getTreatment('qc_team');
5151
client2.getTreatmentWithConfig('qc_team'); // Validate that the impression is the same.
5252
client3.getTreatment('qc_team', testAttrs);
@@ -58,7 +58,8 @@ export default function (assert) {
5858
treatment: 'no',
5959
bucketingKey: 'impr_bucketing_2',
6060
label: 'default rule',
61-
pt: undefined
61+
pt: undefined,
62+
properties: undefined
6263
};
6364

6465
assert.equal(listener.logImpression.callCount, 4, 'Impression listener logImpression method should be called after we call client.getTreatment, once per each impression generated.');
@@ -71,7 +72,7 @@ export default function (assert) {
7172
bucketingKey: undefined,
7273
label: 'expected label',
7374
changeNumber: 2828282828,
74-
pt: undefined
75+
properties: '{"prop1":"prop-value"}'
7576
},
7677
attributes: undefined,
7778
...metaData

src/__tests__/browserSuites/impressions.debug.spec.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ export default function (fetchMock, assert) {
6363
k: 'facundo@split.io', t: 'o.n', m: data[0].i[1].m, c: 828282828282, r: 'another expected label', pt: data[0].i[0].m,
6464
}, {
6565
k: 'facundo@split.io', t: 'o.n', m: data[0].i[2].m, c: 828282828282, r: 'another expected label', pt: data[0].i[1].m
66+
}, {
67+
k: 'facundo@split.io', t: 'o.n', m: data[0].i[3].m, c: 828282828282, r: 'another expected label', properties: '{"prop1":"value1"}'
68+
}, {
69+
k: 'facundo@split.io', t: 'o.n', m: data[0].i[4].m, c: 828282828282, r: 'another expected label', properties: '{"prop1":"value2"}'
70+
}, {
71+
k: 'facundo@split.io', t: 'o.n', m: data[0].i[5].m, c: 828282828282, r: 'another expected label', properties: '{"prop1":"value3"}'
72+
}, {
73+
k: 'facundo@split.io', t: 'o.n', m: data[0].i[6].m, c: 828282828282, r: 'another expected label', properties: '{"prop1":"value4"}'
6674
}]
6775
}]);
6876

@@ -75,15 +83,15 @@ export default function (fetchMock, assert) {
7583

7684
fetchMock.postOnce(url(settings, '/testImpressions/count'), (url, opts) => {
7785
assert.deepEqual(JSON.parse(opts.body), {
78-
pf: [{ f: 'always_on_track_impressions_false', m: truncatedTimeFrame, rc: 1 }]
86+
pf: [{ f: 'always_on_impressions_disabled_true', m: truncatedTimeFrame, rc: 1 }]
7987
}, 'We should generate impression count for the feature with track impressions disabled.');
8088

8189
return 200;
8290
});
8391

8492
fetchMock.postOnce(url(settings, '/v1/keys/cs'), (url, opts) => {
8593
assert.deepEqual(JSON.parse(opts.body), {
86-
keys: [{ fs: ['always_on_track_impressions_false'], k: 'facundo@split.io' }]
94+
keys: [{ fs: ['always_on_impressions_disabled_true'], k: 'facundo@split.io' }]
8795
}, 'We should track unique keys for the feature with track impressions disabled.');
8896

8997
return 200;
@@ -95,6 +103,12 @@ export default function (fetchMock, assert) {
95103
client.getTreatment('split_with_config');
96104
client.getTreatment('split_with_config');
97105
client.getTreatment('split_with_config');
98-
assert.equal(client.getTreatment('always_on_track_impressions_false'), 'on');
106+
assert.equal(client.getTreatment('always_on_impressions_disabled_true'), 'on');
107+
108+
// with properties
109+
assert.equal(client.getTreatment('split_with_config', undefined, { properties: { prop1: 'value1' } }), 'o.n');
110+
assert.equal(client.getTreatments(['split_with_config'], undefined, { properties: { prop1: 'value2' } }).split_with_config, 'o.n');
111+
assert.equal(client.getTreatmentWithConfig('split_with_config', undefined, { properties: { prop1: 'value3' } }).treatment, 'o.n');
112+
assert.equal(client.getTreatmentsWithConfig(['split_with_config'], undefined, { properties: { prop1: 'value4' } }).split_with_config.treatment, 'o.n');
99113
});
100114
}

src/__tests__/browserSuites/impressions.none.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export default async function (fetchMock, assert) {
5959
{ f: 'split_with_config', m: truncatedTimeFrame, rc: 2 },
6060
{ f: 'always_off', m: truncatedTimeFrame, rc: 4 },
6161
{ f: 'always_on', m: truncatedTimeFrame, rc: 2 },
62-
{ f: 'always_on_track_impressions_false', m: truncatedTimeFrame, rc: 1 }
62+
{ f: 'always_on_impressions_disabled_true', m: truncatedTimeFrame, rc: 1 }
6363
]
6464
});
6565
return 200;
@@ -76,7 +76,7 @@ export default async function (fetchMock, assert) {
7676
},
7777
{
7878
k: 'emma@split.io',
79-
fs: ['always_off', 'always_on', 'always_on_track_impressions_false']
79+
fs: ['always_off', 'always_on', 'always_on_impressions_disabled_true']
8080
}
8181
]
8282
}, 'We performed evaluations for two keys, so we should have 2 item total.');
@@ -94,7 +94,7 @@ export default async function (fetchMock, assert) {
9494
client.getTreatment('always_on');
9595
client.getTreatment('always_off');
9696
client.getTreatment('split_with_config');
97-
sharedClient.getTreatment('always_on_track_impressions_false');
97+
sharedClient.getTreatment('always_on_impressions_disabled_true');
9898

9999
client.destroy().then(() => {
100100
assert.end();

src/__tests__/browserSuites/impressions.spec.js

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,21 @@ export default function (fetchMock, assert) {
4747

4848
const client = splitio.client();
4949
const assertPayload = req => {
50-
const resp = JSON.parse(req.body);
51-
52-
assert.equal(resp.length, 2, 'We performed evaluations for 3 features, but one with `impressionsDisabled` true, so we should have 2 items total');
53-
54-
const dependencyChildImpr = resp.filter(e => e.f === 'hierarchical_splits_test')[0];
55-
const splitWithConfigImpr = resp.filter(e => e.f === 'split_with_config')[0];
56-
const alwaysOnWithTrackImpressionsFalse = resp.filter(e => e.f === 'always_on_track_impressions_false');
57-
58-
assert.true(dependencyChildImpr, 'Split we wanted to evaluate should be present on the impressions.');
59-
assert.false(resp.some(e => e.f === 'hierarchical_dep_always_on'), 'Parent split evaluations should not result in impressions.');
60-
assert.false(resp.some(e => e.f === 'hierarchical_dep_hierarchical'), 'No matter how deep is the chain.');
61-
assert.true(splitWithConfigImpr, 'Split evaluated with config should have generated an impression too.');
62-
assert.false(Object.prototype.hasOwnProperty.call(splitWithConfigImpr.i[0], 'configuration'), 'Impressions do not change with configuration evaluations.');
63-
assert.false(Object.prototype.hasOwnProperty.call(splitWithConfigImpr.i[0], 'config'), 'Impressions do not change with configuration evaluations.');
64-
assert.equal(alwaysOnWithTrackImpressionsFalse.length, 0);
65-
66-
const {
67-
k,
68-
r,
69-
t
70-
} = dependencyChildImpr.i[0];
71-
72-
assert.equal(k, 'facundo@split.io', 'Present impression should have the correct key.');
73-
// The label present on the mock.
74-
assert.equal(r, 'expected label', 'Present impression should have the correct label.');
75-
assert.equal(t, 'on', 'Present impression should have the correct treatment.');
50+
const reqBody = JSON.parse(req.body);
51+
52+
assert.deepEqual(reqBody, [{
53+
f: 'hierarchical_splits_test',
54+
i: [{
55+
k: 'facundo@split.io', t: 'on', m: reqBody[0].i[0].m, c: 2828282828, r: 'expected label'
56+
}]
57+
}, {
58+
f: 'split_with_config',
59+
i: [{
60+
k: 'facundo@split.io', t: 'o.n', m: reqBody[1].i[0].m, c: 828282828282, r: 'another expected label'
61+
}, {
62+
k: 'facundo@split.io', t: 'o.n', m: reqBody[1].i[1].m, c: 828282828282, r: 'another expected label', properties: '{"some":"value2"}'
63+
}]
64+
}], 'We performed evaluations for 3 features, but one with `impressionsDisabled` true, so we should have 2 items total');
7665
};
7766

7867
fetchMock.postOnce(url(settings, '/testImpressions/bulk'), (url, req) => {
@@ -93,28 +82,23 @@ export default function (fetchMock, assert) {
9382
return 200;
9483
});
9584

96-
fetchMock.postOnce(url(settings, '/testImpressions/count'), (url, opts) => {
97-
const data = JSON.parse(opts.body);
85+
fetchMock.postOnce(url(settings, '/testImpressions/count'), (url, req) => {
86+
const reqBody = JSON.parse(req.body);
9887

99-
assert.equal(data.pf.length, 2, 'We should generate impressions count for 2 features.');
100-
101-
// finding these validate the feature names collection too
102-
const splitWithConfigImpr = data.pf.filter(e => e.f === 'split_with_config')[0];
103-
const alwaysOnWithTrackImpressionsFalse = data.pf.filter(e => e.f === 'always_on_track_impressions_false')[0];
104-
105-
assert.equal(splitWithConfigImpr.rc, 2);
106-
assert.equal(typeof splitWithConfigImpr.m, 'number');
107-
assert.equal(splitWithConfigImpr.m, truncatedTimeFrame);
108-
assert.equal(alwaysOnWithTrackImpressionsFalse.rc, 1);
109-
assert.equal(typeof alwaysOnWithTrackImpressionsFalse.m, 'number');
110-
assert.equal(alwaysOnWithTrackImpressionsFalse.m, truncatedTimeFrame);
88+
assert.deepEqual(reqBody, {
89+
pf: [{
90+
f: 'split_with_config', m: truncatedTimeFrame, rc: 2
91+
}, {
92+
f: 'always_on_impressions_disabled_true', m: truncatedTimeFrame, rc: 1
93+
}]
94+
}, 'We should generate impressions count for 2 features.');
11195

11296
return 200;
11397
});
11498

11599
fetchMock.postOnce(url(settings, '/v1/keys/cs'), (url, opts) => {
116100
assert.deepEqual(JSON.parse(opts.body), {
117-
keys: [{ fs: [ 'always_on_track_impressions_false' ], k: 'facundo@split.io' }]
101+
keys: [{ fs: ['always_on_impressions_disabled_true'], k: 'facundo@split.io' }]
118102
}, 'We should only track unique keys for features flags with track impressions disabled.');
119103

120104
return 200;
@@ -129,9 +113,12 @@ export default function (fetchMock, assert) {
129113
config: '{"color":"brown","dimensions":{"height":12,"width":14},"text":{"inner":"click me"}}'
130114
}, 'We should get an evaluation as always.');
131115
client.getTreatmentWithConfig('split_with_config');
132-
client.getTreatmentWithConfig('split_with_config');
116+
client.getTreatmentWithConfig('split_with_config', undefined, { properties: { /* empty properties are ignored */ } });
117+
118+
// Impression should not be tracked (passed properties will not be submitted)
119+
assert.equal(client.getTreatment('always_on_impressions_disabled_true'), 'on', undefined, { properties: { some: 'value1' } });
133120

134-
// Impression should not be tracked
135-
assert.equal(client.getTreatment('always_on_track_impressions_false'), 'on');
121+
// Tracked impression with properties should be handled in DEBUG mode (doesn't increase `rc` count but adds an impression)
122+
assert.equal(client.getTreatment('split_with_config', undefined, { properties: { some: 'value2' } }), 'o.n');
136123
});
137124
}

0 commit comments

Comments
 (0)