Skip to content

Commit 6584f28

Browse files
Merge pull request #400 from splitio/development
Release v2.2.0
2 parents 2a20458 + d6a0e69 commit 6584f28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1124
-1186
lines changed

CHANGES.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2.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 storage in browsers when using storage type `LOCALSTORAGE`:
4+
- `storage.expirationDays` to specify the validity period of the rollout cache.
5+
- `storage.clearOnInit` to clear the rollout 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
2.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

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splitsoftware/splitio-commons",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"description": "Split JavaScript SDK common components",
55
"main": "cjs/index.js",
66
"module": "esm/index.js",

src/evaluator/parser/__tests__/index.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { parser } from '..';
33
import { keyParser } from '../../../utils/key';
44
import { ISplitCondition } from '../../../dtos/types';
5-
import { bucket } from '../../../utils/murmur3/murmur3';
65
import { loggerMock } from '../../../logger/__tests__/sdkLogger.mock';
76

87
test('PARSER / if user is in segment all 100%:on', async function () {
@@ -662,8 +661,6 @@ test('PARSER / if user is in segment all then split 20%:A,20%:B,60%:A', async fu
662661
let evaluation = await evaluator(keyParser('aa'), 31, 100, 31);
663662
expect(evaluation.treatment).toBe('A'); // 20%:A // bucket 6 with murmur3
664663

665-
console.log(bucket('b297', 31));
666-
667664
evaluation = await evaluator(keyParser('b297'), 31, 100, 31);
668665
expect(evaluation.treatment).toBe('B'); // 20%:B // bucket 34 with murmur3
669666

src/logger/constants.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ export const RETRIEVE_CLIENT_EXISTING = 28;
2020
export const RETRIEVE_MANAGER = 29;
2121
export const SYNC_OFFLINE_DATA = 30;
2222
export const SYNC_SPLITS_FETCH = 31;
23-
export const SYNC_SPLITS_NEW = 32;
24-
export const SYNC_SPLITS_REMOVED = 33;
25-
export const SYNC_SPLITS_SEGMENTS = 34;
23+
export const SYNC_SPLITS_UPDATE = 32;
2624
export const STREAMING_NEW_MESSAGE = 35;
2725
export const SYNC_TASK_START = 36;
2826
export const SYNC_TASK_EXECUTE = 37;

src/logger/messages/debug.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ export const codesDebug: [number, string][] = codesInfo.concat([
2121
// synchronizer
2222
[c.SYNC_OFFLINE_DATA, c.LOG_PREFIX_SYNC_OFFLINE + 'Feature flags data: \n%s'],
2323
[c.SYNC_SPLITS_FETCH, c.LOG_PREFIX_SYNC_SPLITS + 'Spin up feature flags update using since = %s'],
24-
[c.SYNC_SPLITS_NEW, c.LOG_PREFIX_SYNC_SPLITS + 'New feature flags %s'],
25-
[c.SYNC_SPLITS_REMOVED, c.LOG_PREFIX_SYNC_SPLITS + 'Removed feature flags %s'],
26-
[c.SYNC_SPLITS_SEGMENTS, c.LOG_PREFIX_SYNC_SPLITS + 'Segment names collected %s'],
24+
[c.SYNC_SPLITS_UPDATE, c.LOG_PREFIX_SYNC_SPLITS + 'New feature flags %s. Removed feature flags %s. Segment names collected %s'],
2725
[c.STREAMING_NEW_MESSAGE, c.LOG_PREFIX_SYNC_STREAMING + 'New SSE message received, with data: %s.'],
2826
[c.SYNC_TASK_START, c.LOG_PREFIX_SYNC + ': Starting %s. Running each %s millis'],
2927
[c.SYNC_TASK_EXECUTE, c.LOG_PREFIX_SYNC + ': Running %s'],

src/logger/messages/error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const codesError: [number, string][] = [
2121
// input validation
2222
[c.ERROR_EVENT_TYPE_FORMAT, '%s: you passed "%s", event_type must adhere to the regular expression /^[a-zA-Z0-9][-_.:a-zA-Z0-9]{0,79}$/g. This means an event_type must be alphanumeric, cannot be more than 80 characters long, and can only include a dash, underscore, period, or colon as separators of alphanumeric characters.'],
2323
[c.ERROR_NOT_PLAIN_OBJECT, '%s: %s must be a plain object.'],
24-
[c.ERROR_SIZE_EXCEEDED, '%s: the maximum size allowed for the properties is 32768 bytes, which was exceeded. Event not queued.'],
24+
[c.ERROR_SIZE_EXCEEDED, '%s: the maximum size allowed for the properties is 32768 bytes, which was exceeded.'],
2525
[c.ERROR_NOT_FINITE, '%s: value must be a finite number.'],
2626
[c.ERROR_NULL, '%s: you passed a null or undefined %s. It must be a non-empty string.'],
2727
[c.ERROR_TOO_LONG, '%s: %s too long. It must have 250 characters or less.'],

src/logger/messages/warn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const codesWarn: [number, string][] = codesError.concat([
1818
[c.CLIENT_NO_LISTENER, 'No listeners for SDK Readiness detected. Incorrect control treatments could have been logged if you called getTreatment/s while the SDK was not yet ready.'],
1919
// input validation
2020
[c.WARN_SETTING_NULL, '%s: Property "%s" is of invalid type. Setting value to null.'],
21-
[c.WARN_TRIMMING_PROPERTIES, '%s: Event has more than 300 properties. Some of them will be trimmed when processed.'],
21+
[c.WARN_TRIMMING_PROPERTIES, '%s: more than 300 properties were provided. Some of them will be trimmed when processed.'],
2222
[c.WARN_CONVERTING, '%s: %s "%s" is not of type string, converting.'],
2323
[c.WARN_TRIMMING, '%s: %s "%s" has extra whitespace, trimming.'],
2424
[c.WARN_NOT_EXISTENT_SPLIT, '%s: feature flag "%s" does not exist in this environment. Please double check what feature flags exist in the Split user interface.'],

src/readiness/__tests__/readinessManager.spec.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import { EventEmitter } from '../../utils/MinEvents';
33
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
import { ISettings } from '../../types';
6+
import { STORAGE_LOCALSTORAGE } from '../../utils/constants';
67

78
const settings = {
89
startup: {
910
readyTimeout: 0,
11+
},
12+
storage: {
13+
type: STORAGE_LOCALSTORAGE
1014
}
1115
} as unknown as ISettings;
1216

@@ -67,7 +71,14 @@ test('READINESS MANAGER / Ready event should be fired once', () => {
6771
const readinessManager = readinessManagerFactory(EventEmitter, settings);
6872
let counter = 0;
6973

74+
readinessManager.gate.on(SDK_READY_FROM_CACHE, () => {
75+
expect(readinessManager.isReadyFromCache()).toBe(true);
76+
expect(readinessManager.isReady()).toBe(true);
77+
counter++;
78+
});
79+
7080
readinessManager.gate.on(SDK_READY, () => {
81+
expect(readinessManager.isReadyFromCache()).toBe(true);
7182
expect(readinessManager.isReady()).toBe(true);
7283
counter++;
7384
});
@@ -79,7 +90,7 @@ test('READINESS MANAGER / Ready event should be fired once', () => {
7990
readinessManager.splits.emit(SDK_SPLITS_ARRIVED);
8091
readinessManager.segments.emit(SDK_SEGMENTS_ARRIVED);
8192

82-
expect(counter).toBe(1); // should be called once
93+
expect(counter).toBe(2); // should be called once
8394
});
8495

8596
test('READINESS MANAGER / Ready from cache event should be fired once', (done) => {
@@ -88,6 +99,7 @@ test('READINESS MANAGER / Ready from cache event should be fired once', (done) =
8899

89100
readinessManager.gate.on(SDK_READY_FROM_CACHE, () => {
90101
expect(readinessManager.isReadyFromCache()).toBe(true);
102+
expect(readinessManager.isReady()).toBe(false);
91103
counter++;
92104
});
93105

src/readiness/readinessManager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ISettings } from '../types';
33
import SplitIO from '../../types/splitio';
44
import { SDK_SPLITS_ARRIVED, SDK_SPLITS_CACHE_LOADED, SDK_SEGMENTS_ARRIVED, SDK_READY_TIMED_OUT, SDK_READY_FROM_CACHE, SDK_UPDATE, SDK_READY } from './constants';
55
import { IReadinessEventEmitter, IReadinessManager, ISegmentsEventEmitter, ISplitsEventEmitter } from './types';
6+
import { STORAGE_LOCALSTORAGE } from '../utils/constants';
67

78
function splitsEventEmitterFactory(EventEmitter: new () => SplitIO.IEventEmitter): ISplitsEventEmitter {
89
const splitsEventEmitter = objectAssign(new EventEmitter(), {
@@ -114,6 +115,10 @@ export function readinessManagerFactory(
114115
isReady = true;
115116
try {
116117
syncLastUpdate();
118+
if (!isReadyFromCache && settings.storage?.type === STORAGE_LOCALSTORAGE) {
119+
isReadyFromCache = true;
120+
gate.emit(SDK_READY_FROM_CACHE);
121+
}
117122
gate.emit(SDK_READY);
118123
} catch (e) {
119124
// throws user callback exceptions in next tick

0 commit comments

Comments
 (0)