Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag sets #100

Merged
merged 12 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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 .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: BUILD_BRANCH=$(echo "${GITHUB_REF#refs/heads/}") npm run build

- name: Store assets
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/development' || github.ref == 'refs/heads/main') }}
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/sdks-7668' || github.ref == 'refs/heads/main') }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sdks-7668 -> development

uses: actions/upload-artifact@v3
with:
name: assets
Expand All @@ -58,7 +58,7 @@ jobs:
name: Upload assets
runs-on: ubuntu-20.04
needs: build
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/development' }}
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/sdks-7668' }}
strategy:
matrix:
environment:
Expand Down
19,587 changes: 8,228 additions & 11,359 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splitsoftware/splitio-browserjs",
"version": "0.10.2-rc.1",
"version": "0.10.2-rc.2",
"description": "Split SDK for JavaScript on Browser",
"main": "cjs/index.js",
"module": "esm/index.js",
Expand Down Expand Up @@ -64,7 +64,7 @@
"bugs": "https://github.com/splitio/javascript-browser-client/issues",
"homepage": "https://github.com/splitio/javascript-browser-client#readme",
"dependencies": {
"@splitsoftware/splitio-commons": "1.10.0",
"@splitsoftware/splitio-commons": "1.10.1-rc.0",
"@types/google.analytics": "0.0.40",
"unfetch": "^4.2.0"
},
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/browserSuites/manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default async function (settings, fetchMock, assert) {
'changeNumber': mockSplits.splits[index].changeNumber,
'treatments': map(mockSplits.splits[index].conditions[0].partitions, partition => partition.treatment),
'configs': mockSplits.splits[index].configurations || {},
'sets': mockSplits.splits[index].sets,
'defaultTreatment': mockSplits.splits[index].defaultTreatment
});

Expand Down
10 changes: 6 additions & 4 deletions src/__tests__/browserSuites/ready-from-cache.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ export default function (fetchMock, assert) {
events: 'https://events.baseurl/readyFromCache_5'
};
localStorage.clear();
t.plan(7);
t.plan(6);

fetchMock.getOnce(testUrls.sdk + '/splitChanges?since=-1&names=p1__split,p2__split', { status: 200, body: { splits: [splitDeclarations.p1__split, splitDeclarations.p2__split], since: -1, till: 1457552620999 } }, { delay: 10 }); // short delay to let emit SDK_READY_FROM_CACHE
// fetchMock.getOnce(testUrls.sdk + '/splitChanges?since=1457552620999&names=p1__split', { status: 200, body: { splits: [], since: 1457552620999, till: 1457552620999 } });
Expand All @@ -499,7 +499,8 @@ export default function (fetchMock, assert) {
const manager = splitio.manager();

client.once(client.Event.SDK_READY_FROM_CACHE, () => {
t.deepEqual(manager.names(), ['p2__split'], 'stored p3__split must be removed because doesn\'t match the filter');
t.fail('It should not emit SDK_READY_FROM_CACHE if cache is empty.');
t.end();
});

client.once(client.Event.SDK_READY, () => {
Expand Down Expand Up @@ -731,7 +732,7 @@ export default function (fetchMock, assert) {
events: 'https://events.baseurl/readyFromCache_9'
};
localStorage.clear();
t.plan(7);
t.plan(6);

fetchMock.getOnce(testUrls.sdk + '/splitChanges?since=-1&names=no%20exist%20trim,no_exist,p3__split&prefixes=no%20exist%20trim,p2', { status: 200, body: { splits: [splitDeclarations.p2__split, splitDeclarations.p3__split], since: -1, till: 1457552620999 } }, { delay: 10 }); // short delay to let emit SDK_READY_FROM_CACHE
fetchMock.getOnce(testUrls.sdk + '/mySegments/nicolas%40split.io', { status: 200, body: { mySegments: [] } });
Expand All @@ -757,7 +758,8 @@ export default function (fetchMock, assert) {
const manager = splitio.manager();

client.once(client.Event.SDK_READY_FROM_CACHE, () => {
t.deepEqual(manager.names(), ['p2__split'], 'stored p1__split must be removed because doesn\'t match the filter');
t.fail('It should not emit SDK_READY_FROM_CACHE because all splits were removed from cache since the filter query changed.');
t.end();
});

client.once(client.Event.SDK_READY, () => {
Expand Down
5 changes: 3 additions & 2 deletions src/__tests__/browserSuites/telemetry.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default async function telemetryBrowserSuite(fetchMock, assert) {
const data = JSON.parse(opts.body);

// Validate last successful sync
assert.deepEqual(Object.keys(data.lS), ['sp', 'ms', 'te'], 'Successful splitChanges, mySegments and metrics/config requests');
assert.deepEqual(Object.keys(data.lS), ['ms', 'sp', 'te'], 'Successful splitChanges, mySegments and metrics/config requests');
lastSync = data.lS; delete data.lS;

// Validate http and method latencies
Expand Down Expand Up @@ -106,7 +106,8 @@ export default async function telemetryBrowserSuite(fetchMock, assert) {
oM: 0, st: 'memory', aF: 1, rF: 0, sE: false,
rR: { sp: 99999, ms: 60, im: 300, ev: 60, te: 1 } /* override featuresRefreshRate */,
uO: { s: true, e: true, a: false, st: false, t: true } /* override sdk, events and telemetry URLs */,
iQ: 30000, eQ: 500, iM: 0, iL: false, hP: false, nR: 1 /* 1 non ready usage */, t: [], i: [], uC: 2 /* Default GRANTED */
iQ: 30000, eQ: 500, iM: 0, iL: false, hP: false, nR: 1 /* 1 non ready usage */, t: [], i: [], uC: 2 /* Default GRANTED */,
fsT: 0, fsI: 0 /* Flag sets */
}, 'metrics/config JSON payload should be the expected');

finish.next();
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/consumer/browser_consumer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { version } from '../../../package.json';
import { SplitFactory, PluggableStorage } from '../../';

const expectedSplitName = 'hierarchical_splits_testing_on';
const expectedSplitView = { name: 'hierarchical_splits_testing_on', trafficType: 'user', killed: false, changeNumber: 1487277320548, treatments: ['on', 'off'], configs: {}, defaultTreatment: 'off' };
const expectedSplitView = { name: 'hierarchical_splits_testing_on', trafficType: 'user', killed: false, changeNumber: 1487277320548, treatments: ['on', 'off'], configs: {}, sets: [], defaultTreatment: 'off' };

const wrapperPrefix = 'PLUGGABLE_STORAGE_UT';
const wrapperInstance = inMemoryWrapperFactory();
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/consumer/browser_consumer_partial.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { applyOperations } from './wrapper-commands';
import { SplitFactory, PluggableStorage } from '../../';

const expectedSplitName = 'hierarchical_splits_testing_on';
const expectedSplitView = { name: 'hierarchical_splits_testing_on', trafficType: 'user', killed: false, changeNumber: 1487277320548, treatments: ['on', 'off'], configs: {}, defaultTreatment: 'off' };
const expectedSplitView = { name: 'hierarchical_splits_testing_on', trafficType: 'user', killed: false, changeNumber: 1487277320548, treatments: ['on', 'off'], configs: {}, sets: [], defaultTreatment: 'off' };

const wrapperPrefix = 'PLUGGABLE_STORAGE_UT';
const wrapperInstance = inMemoryWrapperFactory();
Expand Down
6 changes: 4 additions & 2 deletions src/__tests__/mocks/splitchanges.real.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"label": "default rule"
}
],
"configurations": {}
"configurations": {},
"sets": []
},
{
"trafficTypeName": "user",
Expand Down Expand Up @@ -98,7 +99,8 @@
],
"configurations": {
"on": "{\"color\":\"brown\",\"dimensions\":{\"height\":12,\"width\":14},\"text\":{\"inner\":\"click me\"}}"
}
},
"sets": []
}
],
"since": -1,
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/offline/browser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ tape('Browser offline mode', function (assert) {

// Manager tests
const expectedSplitView1 = {
name: 'testing_split', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['on'], configs: {}, defaultTreatment: 'control'
name: 'testing_split', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['on'], configs: {}, sets: [], defaultTreatment: 'control'
};
const expectedSplitView2 = {
name: 'testing_split_with_config', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['off'], configs: { off: '{ "color": "blue" }' }, defaultTreatment: 'control'
name: 'testing_split_with_config', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['off'], configs: { off: '{ "color": "blue" }' }, sets: [], defaultTreatment: 'control'
};
assert.deepEqual(manager.names(), ['testing_split', 'testing_split_with_config']);
assert.deepEqual(manager.split('testing_split'), expectedSplitView1);
Expand Down Expand Up @@ -282,7 +282,7 @@ tape('Browser offline mode', function (assert) {

// Manager tests
const expectedSplitView3 = {
name: 'testing_split_with_config', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['nope'], configs: {}, defaultTreatment: 'control'
name: 'testing_split_with_config', trafficType: 'localhost', killed: false, changeNumber: 0, treatments: ['nope'], configs: {}, sets: [], defaultTreatment: 'control'
};
assert.deepEqual(manager.names(), ['testing_split', 'testing_split_2', 'testing_split_3', 'testing_split_with_config']);
assert.deepEqual(manager.split('testing_split'), expectedSplitView1);
Expand Down
2 changes: 1 addition & 1 deletion src/settings/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LogLevels, isLogLevelString } from '@splitsoftware/splitio-commons/src/
import { ConsentStatus, LogLevel } from '@splitsoftware/splitio-commons/src/types';
import { CONSENT_GRANTED } from '@splitsoftware/splitio-commons/src/utils/constants';

const packageVersion = '0.10.2-rc.1';
const packageVersion = '0.10.2-rc.2';

/**
* In browser, the default debug level, can be set via the `localStorage.splitio_debug` item.
Expand Down
58 changes: 57 additions & 1 deletion ts-tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,34 @@ treatmentsWithConfig = client.getTreatmentsWithConfig(['mySplit']);
// treatmentsWithConfig = client.getTreatmentsWithConfig(splitKey, ['mySplit'], attributes);
treatmentsWithConfig = client.getTreatmentsWithConfig(['mySplit'], attributes);

// We can call getTreatmentsByFlagSet without a key.
// treatments = client.getTreatmentsByFlagSet(splitKey, 'set_a');
treatments = client.getTreatmentsByFlagSet('set_a');
// Attributes parameter is optional.
// treatments = client.getTreatmentsByFlagSet(splitKey, 'set_a', attributes);
treatments = client.getTreatmentsByFlagSet('set_a', attributes);

// We can call getTreatmentsByFlagSets without a key.
// treatments = client.getTreatmentsByFlagSets(splitKey, ['set_a']);
treatments = client.getTreatmentsByFlagSets(['set_a']);
// Attributes parameter is optional.
// treatments = client.getTreatmentsByFlagSets(splitKey, ['set_a'], attributes);
treatments = client.getTreatmentsByFlagSets(['set_a'], attributes);

// We can call getTreatmentsWithConfigByFlagSet without a key.
// treatmentsWithConfig = client.getTreatmentsWithConfigByFlagSet(splitKey, 'set_a');
treatmentsWithConfig = client.getTreatmentsWithConfigByFlagSet('set_a');
// Attributes parameter is optional.
// treatmentsWithConfig = client.getTreatmentsWithConfigByFlagSet(splitKey, 'set_a', attributes);
treatmentsWithConfig = client.getTreatmentsWithConfigByFlagSet('set_a', attributes);

// We can call getTreatmentsWithConfigByFlagSets without a key.
// treatmentsWithConfig = client.getTreatmentsWithConfigByFlagSets(splitKey, ['set_a']);
treatmentsWithConfig = client.getTreatmentsWithConfigByFlagSets(['set_a']);
// Attributes parameter is optional.
// treatmentsWithConfig = client.getTreatmentsWithConfigByFlagSets(splitKey, ['set_a'], attributes);
treatmentsWithConfig = client.getTreatmentsWithConfigByFlagSets(['set_a'], attributes);

// We can call track without a key. Traffic type can also be binded to the client.
// tracked = client.track(splitKey, 'myTrafficType', 'myEventType'); // all params
tracked = client.track('myTrafficType', 'myEventType'); // key binded, tt provided.
Expand Down Expand Up @@ -343,6 +371,34 @@ asyncTreatmentsWithConfig = asyncClient.getTreatmentsWithConfig(['mySplit']);
asyncTreatmentsWithConfig = asyncClient.getTreatmentsWithConfig(['mySplit'], attributes);
// asyncTreatmentsWithConfig = asyncClient.getTreatmentsWithConfig(splitKey, ['mySplit'], attributes);

// We can call getTreatmentsByFlagSet
asyncTreatments = asyncClient.getTreatmentsByFlagSet('set_a');
// asyncTreatments = asyncClient.getTreatmentsByFlagSet(splitKey, 'set_a');
// Attributes parameter is optional
asyncTreatments = asyncClient.getTreatmentsByFlagSet('set_a', attributes);
// asyncTreatments = asyncClient.getTreatmentsByFlagSet(splitKey, 'set_a', attributes);

// We can call getTreatmentsByFlagSets
asyncTreatments = asyncClient.getTreatmentsByFlagSets(['set_a']);
// asyncTreatments = asyncClient.getTreatmentsByFlagSets(splitKey, ['set_a']);
// Attributes parameter is optional
asyncTreatments = asyncClient.getTreatmentsByFlagSets(['set_a'], attributes);
// asyncTreatments = asyncClient.getTreatmentsByFlagSets(splitKey, ['set_a'], attributes);

// We can call getTreatmentsWithConfigByFlagSet
asyncTreatmentsWithConfig = asyncClient.getTreatmentsWithConfigByFlagSet('set_a');
// asyncTreatmentsWithConfig = asyncClient.getTreatmentsWithConfigByFlagSet(splitKey, 'set_a');
// Attributes parameter is optional
asyncTreatmentsWithConfig = asyncClient.getTreatmentsWithConfigByFlagSet('set_a', attributes);
// asyncTreatmentsWithConfig = asyncClient.getTreatmentsWithConfigByFlagSet(splitKey, 'set_a', attributes);

// We can call getTreatmentsByFlagSets but always with a key.
asyncTreatmentsWithConfig = asyncClient.getTreatmentsWithConfigByFlagSets(['set_a']);
// asyncTreatmentsWithConfig = asyncClient.getTreatmentsWithConfigByFlagSets(splitKey, ['set_a']);
// Attributes parameter is optional
asyncTreatmentsWithConfig = asyncClient.getTreatmentsWithConfigByFlagSets(['set_a'], attributes);
// asyncTreatmentsWithConfig = asyncClient.getTreatmentsWithConfigByFlagSets(splitKey, ['set_a'], attributes);

// We can call track.
trackPromise = asyncClient.track('myTrafficType', 'myEventType'); // all required params
// trackPromise = asyncClient.track(splitKey, 'myTrafficType', 'myEventType'); // all required params
Expand Down Expand Up @@ -462,7 +518,7 @@ userConsent = AsyncSDK.UserConsent.Status.UNKNOWN;
/**** Tests for fully crowded settings interfaces ****/

// Split filters
let splitFilters: SplitIO.SplitFilter[] = [{ type: 'byName', values: ['my_split_1', 'my_split_1'] }, { type: 'byPrefix', values: ['my_split', 'test_split_'] }]
let splitFilters: SplitIO.SplitFilter[] = [{ type: 'bySet', values: ['set_a', 'set_b'] }, { type: 'byName', values: ['my_split_1', 'my_split_1'] }, { type: 'byPrefix', values: ['my_split', 'test_split_'] }]

// Browser integrations
let fieldsObjectSample: UniversalAnalytics.FieldsObject = { hitType: 'event', eventAction: 'action' };
Expand Down
Loading
Loading