@splitsoftware/splitio-commons 2.0.2 → 2.1.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/cjs/listeners/node.js +2 -2
- package/cjs/storages/AbstractSplitsCacheAsync.js +0 -7
- package/cjs/storages/AbstractSplitsCacheSync.js +0 -7
- package/cjs/storages/KeyBuilderCS.js +3 -0
- package/cjs/storages/dataLoader.js +3 -2
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +1 -57
- package/cjs/storages/inLocalStorage/index.js +5 -3
- package/cjs/storages/inLocalStorage/validateCache.js +80 -0
- package/cjs/storages/pluggable/index.js +2 -1
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +3 -2
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +1 -10
- package/cjs/sync/streaming/pushManager.js +8 -6
- package/cjs/sync/syncManagerOnline.js +10 -4
- package/cjs/trackers/eventTracker.js +1 -1
- package/cjs/trackers/impressionsTracker.js +1 -1
- package/cjs/utils/settingsValidation/index.js +1 -1
- package/cjs/utils/settingsValidation/storage/storageCS.js +1 -1
- package/esm/listeners/node.js +2 -2
- package/esm/storages/AbstractSplitsCacheAsync.js +0 -7
- package/esm/storages/AbstractSplitsCacheSync.js +0 -7
- package/esm/storages/KeyBuilderCS.js +3 -0
- package/esm/storages/dataLoader.js +2 -1
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +1 -57
- package/esm/storages/inLocalStorage/index.js +5 -3
- package/esm/storages/inLocalStorage/validateCache.js +76 -0
- package/esm/storages/pluggable/index.js +2 -1
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +3 -2
- package/esm/sync/polling/updaters/splitChangesUpdater.js +2 -11
- package/esm/sync/streaming/pushManager.js +8 -6
- package/esm/sync/syncManagerOnline.js +10 -4
- package/esm/trackers/eventTracker.js +1 -1
- package/esm/trackers/impressionsTracker.js +1 -1
- package/esm/utils/settingsValidation/index.js +1 -1
- package/esm/utils/settingsValidation/storage/storageCS.js +1 -1
- package/package.json +1 -1
- package/src/listeners/node.ts +2 -2
- package/src/storages/AbstractSplitsCacheAsync.ts +0 -8
- package/src/storages/AbstractSplitsCacheSync.ts +0 -8
- package/src/storages/KeyBuilderCS.ts +4 -0
- package/src/storages/dataLoader.ts +3 -1
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +1 -66
- package/src/storages/inLocalStorage/index.ts +8 -8
- package/src/storages/inLocalStorage/validateCache.ts +92 -0
- package/src/storages/pluggable/index.ts +2 -1
- package/src/storages/types.ts +1 -4
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +6 -5
- package/src/sync/polling/updaters/splitChangesUpdater.ts +2 -11
- package/src/sync/streaming/pushManager.ts +8 -6
- package/src/sync/syncManagerOnline.ts +11 -5
- package/src/trackers/eventTracker.ts +1 -1
- package/src/trackers/impressionsTracker.ts +1 -1
- package/src/utils/lang/index.ts +1 -1
- package/src/utils/settingsValidation/index.ts +1 -1
- package/src/utils/settingsValidation/storage/storageCS.ts +1 -1
- package/types/index.d.ts +1 -1
- package/types/splitio.d.ts +26 -2
- package/cjs/utils/constants/browser.js +0 -5
- package/esm/utils/constants/browser.js +0 -2
- package/src/utils/constants/browser.ts +0 -2
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ISettings } from '../../types';
|
|
2
|
+
import { isFiniteNumber, isNaNNumber } from '../../utils/lang';
|
|
3
|
+
import { getStorageHash } from '../KeyBuilder';
|
|
4
|
+
import { LOG_PREFIX } from './constants';
|
|
5
|
+
import type { SplitsCacheInLocal } from './SplitsCacheInLocal';
|
|
6
|
+
import type { MySegmentsCacheInLocal } from './MySegmentsCacheInLocal';
|
|
7
|
+
import { KeyBuilderCS } from '../KeyBuilderCS';
|
|
8
|
+
import SplitIO from '../../../types/splitio';
|
|
9
|
+
|
|
10
|
+
// milliseconds in a day
|
|
11
|
+
const DEFAULT_CACHE_EXPIRATION_IN_DAYS = 10;
|
|
12
|
+
const MILLIS_IN_A_DAY = 86400000;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Validates if cache should be cleared and sets the cache `hash` if needed.
|
|
16
|
+
*
|
|
17
|
+
* @returns `true` if cache should be cleared, `false` otherwise
|
|
18
|
+
*/
|
|
19
|
+
function validateExpiration(options: SplitIO.InLocalStorageOptions, settings: ISettings, keys: KeyBuilderCS, currentTimestamp: number, isThereCache: boolean) {
|
|
20
|
+
const { log } = settings;
|
|
21
|
+
|
|
22
|
+
// Check expiration
|
|
23
|
+
const lastUpdatedTimestamp = parseInt(localStorage.getItem(keys.buildLastUpdatedKey()) as string, 10);
|
|
24
|
+
if (!isNaNNumber(lastUpdatedTimestamp)) {
|
|
25
|
+
const cacheExpirationInDays = isFiniteNumber(options.expirationDays) && options.expirationDays >= 1 ? options.expirationDays : DEFAULT_CACHE_EXPIRATION_IN_DAYS;
|
|
26
|
+
const expirationTimestamp = currentTimestamp - MILLIS_IN_A_DAY * cacheExpirationInDays;
|
|
27
|
+
if (lastUpdatedTimestamp < expirationTimestamp) {
|
|
28
|
+
log.info(LOG_PREFIX + 'Cache expired more than ' + cacheExpirationInDays + ' days ago. Cleaning up cache');
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Check hash
|
|
34
|
+
const storageHashKey = keys.buildHashKey();
|
|
35
|
+
const storageHash = localStorage.getItem(storageHashKey);
|
|
36
|
+
const currentStorageHash = getStorageHash(settings);
|
|
37
|
+
|
|
38
|
+
if (storageHash !== currentStorageHash) {
|
|
39
|
+
try {
|
|
40
|
+
localStorage.setItem(storageHashKey, currentStorageHash);
|
|
41
|
+
} catch (e) {
|
|
42
|
+
log.error(LOG_PREFIX + e);
|
|
43
|
+
}
|
|
44
|
+
if (isThereCache) {
|
|
45
|
+
log.info(LOG_PREFIX + 'SDK key, flags filter criteria or flags spec version has changed. Cleaning up cache');
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false; // No cache to clear
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Clear on init
|
|
52
|
+
if (options.clearOnInit) {
|
|
53
|
+
const lastClearTimestamp = parseInt(localStorage.getItem(keys.buildLastClear()) as string, 10);
|
|
54
|
+
|
|
55
|
+
if (isNaNNumber(lastClearTimestamp) || lastClearTimestamp < currentTimestamp - MILLIS_IN_A_DAY) {
|
|
56
|
+
log.info(LOG_PREFIX + 'clearOnInit was set and cache was not cleared in the last 24 hours. Cleaning up cache');
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Clean cache if:
|
|
64
|
+
* - it has expired, i.e., its `lastUpdated` timestamp is older than the given `expirationTimestamp`
|
|
65
|
+
* - its hash has changed, i.e., the SDK key, flags filter criteria or flags spec version was modified
|
|
66
|
+
* - `clearOnInit` was set and cache was not cleared in the last 24 hours
|
|
67
|
+
*
|
|
68
|
+
* @returns `true` if cache is ready to be used, `false` otherwise (cache was cleared or there is no cache)
|
|
69
|
+
*/
|
|
70
|
+
export function validateCache(options: SplitIO.InLocalStorageOptions, settings: ISettings, keys: KeyBuilderCS, splits: SplitsCacheInLocal, segments: MySegmentsCacheInLocal, largeSegments: MySegmentsCacheInLocal): boolean {
|
|
71
|
+
|
|
72
|
+
const currentTimestamp = Date.now();
|
|
73
|
+
const isThereCache = splits.getChangeNumber() > -1;
|
|
74
|
+
|
|
75
|
+
if (validateExpiration(options, settings, keys, currentTimestamp, isThereCache)) {
|
|
76
|
+
splits.clear();
|
|
77
|
+
segments.clear();
|
|
78
|
+
largeSegments.clear();
|
|
79
|
+
|
|
80
|
+
// Update last clear timestamp
|
|
81
|
+
try {
|
|
82
|
+
localStorage.setItem(keys.buildLastClear(), currentTimestamp + '');
|
|
83
|
+
} catch (e) {
|
|
84
|
+
settings.log.error(LOG_PREFIX + e);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Check if ready from cache
|
|
91
|
+
return isThereCache;
|
|
92
|
+
}
|
|
@@ -92,7 +92,8 @@ export function PluggableStorage(options: PluggableStorageOptions): IStorageAsyn
|
|
|
92
92
|
// Connects to wrapper and emits SDK_READY event on main client
|
|
93
93
|
const connectPromise = wrapper.connect().then(() => {
|
|
94
94
|
if (isSyncronizer) {
|
|
95
|
-
//
|
|
95
|
+
// @TODO reuse InLocalStorage::validateCache logic
|
|
96
|
+
// In standalone or producer mode, clear storage if SDK key, flags filter criteria or flags spec version was modified
|
|
96
97
|
return wrapper.get(keys.buildHashKey()).then((hash) => {
|
|
97
98
|
const currentHash = getStorageHash(settings);
|
|
98
99
|
if (hash !== currentHash) {
|
package/src/storages/types.ts
CHANGED
|
@@ -191,8 +191,6 @@ export interface ISplitsCacheBase {
|
|
|
191
191
|
// only for Client-Side. Returns true if the storage is not synchronized yet (getChangeNumber() === -1) or contains a FF using segments or large segments
|
|
192
192
|
usesSegments(): MaybeThenable<boolean>,
|
|
193
193
|
clear(): MaybeThenable<boolean | void>,
|
|
194
|
-
// should never reject or throw an exception. Instead return false by default, to avoid emitting SDK_READY_FROM_CACHE.
|
|
195
|
-
checkCache(): MaybeThenable<boolean>,
|
|
196
194
|
killLocally(name: string, defaultTreatment: string, changeNumber: number): MaybeThenable<boolean>,
|
|
197
195
|
getNamesByFlagSets(flagSets: string[]): MaybeThenable<Set<string>[]>
|
|
198
196
|
}
|
|
@@ -209,7 +207,6 @@ export interface ISplitsCacheSync extends ISplitsCacheBase {
|
|
|
209
207
|
trafficTypeExists(trafficType: string): boolean,
|
|
210
208
|
usesSegments(): boolean,
|
|
211
209
|
clear(): void,
|
|
212
|
-
checkCache(): boolean,
|
|
213
210
|
killLocally(name: string, defaultTreatment: string, changeNumber: number): boolean,
|
|
214
211
|
getNamesByFlagSets(flagSets: string[]): Set<string>[]
|
|
215
212
|
}
|
|
@@ -226,7 +223,6 @@ export interface ISplitsCacheAsync extends ISplitsCacheBase {
|
|
|
226
223
|
trafficTypeExists(trafficType: string): Promise<boolean>,
|
|
227
224
|
usesSegments(): Promise<boolean>,
|
|
228
225
|
clear(): Promise<boolean | void>,
|
|
229
|
-
checkCache(): Promise<boolean>,
|
|
230
226
|
killLocally(name: string, defaultTreatment: string, changeNumber: number): Promise<boolean>,
|
|
231
227
|
getNamesByFlagSets(flagSets: string[]): Promise<Set<string>[]>
|
|
232
228
|
}
|
|
@@ -457,6 +453,7 @@ export interface IStorageSync extends IStorageBase<
|
|
|
457
453
|
IUniqueKeysCacheSync
|
|
458
454
|
> {
|
|
459
455
|
// Defined in client-side
|
|
456
|
+
validateCache?: () => boolean, // @TODO support async
|
|
460
457
|
largeSegments?: ISegmentsCacheSync,
|
|
461
458
|
}
|
|
462
459
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { forOwn } from '../../../utils/lang';
|
|
2
2
|
import { IReadinessManager } from '../../../readiness/types';
|
|
3
|
-
import {
|
|
3
|
+
import { IStorageSync } from '../../../storages/types';
|
|
4
4
|
import { ISplitsParser } from '../splitsParser/types';
|
|
5
5
|
import { ISplit, ISplitPartial } from '../../../dtos/types';
|
|
6
6
|
import { syncTaskFactory } from '../../syncTask';
|
|
@@ -15,7 +15,7 @@ import { SYNC_OFFLINE_DATA, ERROR_SYNC_OFFLINE_LOADING } from '../../../logger/c
|
|
|
15
15
|
*/
|
|
16
16
|
export function fromObjectUpdaterFactory(
|
|
17
17
|
splitsParser: ISplitsParser,
|
|
18
|
-
storage:
|
|
18
|
+
storage: Pick<IStorageSync, 'splits' | 'validateCache'>,
|
|
19
19
|
readiness: IReadinessManager,
|
|
20
20
|
settings: ISettings,
|
|
21
21
|
): () => Promise<boolean> {
|
|
@@ -60,9 +60,10 @@ export function fromObjectUpdaterFactory(
|
|
|
60
60
|
|
|
61
61
|
if (startingUp) {
|
|
62
62
|
startingUp = false;
|
|
63
|
-
|
|
63
|
+
const isCacheLoaded = storage.validateCache ? storage.validateCache() : false;
|
|
64
|
+
Promise.resolve().then(() => {
|
|
64
65
|
// Emits SDK_READY_FROM_CACHE
|
|
65
|
-
if (
|
|
66
|
+
if (isCacheLoaded) readiness.splits.emit(SDK_SPLITS_CACHE_LOADED);
|
|
66
67
|
// Emits SDK_READY
|
|
67
68
|
readiness.segments.emit(SDK_SEGMENTS_ARRIVED);
|
|
68
69
|
});
|
|
@@ -80,7 +81,7 @@ export function fromObjectUpdaterFactory(
|
|
|
80
81
|
*/
|
|
81
82
|
export function fromObjectSyncTaskFactory(
|
|
82
83
|
splitsParser: ISplitsParser,
|
|
83
|
-
storage:
|
|
84
|
+
storage: Pick<IStorageSync, 'splits' | 'validateCache'>,
|
|
84
85
|
readiness: IReadinessManager,
|
|
85
86
|
settings: ISettings
|
|
86
87
|
): ISyncTask<[], boolean> {
|
|
@@ -3,7 +3,7 @@ import { ISplitChangesFetcher } from '../fetchers/types';
|
|
|
3
3
|
import { ISplit, ISplitChangesResponse, ISplitFiltersValidation } from '../../../dtos/types';
|
|
4
4
|
import { ISplitsEventEmitter } from '../../../readiness/types';
|
|
5
5
|
import { timeout } from '../../../utils/promise/timeout';
|
|
6
|
-
import { SDK_SPLITS_ARRIVED
|
|
6
|
+
import { SDK_SPLITS_ARRIVED } from '../../../readiness/constants';
|
|
7
7
|
import { ILogger } from '../../../logger/types';
|
|
8
8
|
import { SYNC_SPLITS_FETCH, SYNC_SPLITS_NEW, SYNC_SPLITS_REMOVED, SYNC_SPLITS_SEGMENTS, SYNC_SPLITS_FETCH_FAILS, SYNC_SPLITS_FETCH_RETRY } from '../../../logger/constants';
|
|
9
9
|
import { startsWith } from '../../../utils/lang';
|
|
@@ -153,7 +153,7 @@ export function splitChangesUpdaterFactory(
|
|
|
153
153
|
*/
|
|
154
154
|
function _splitChangesUpdater(since: number, retry = 0): Promise<boolean> {
|
|
155
155
|
log.debug(SYNC_SPLITS_FETCH, [since]);
|
|
156
|
-
|
|
156
|
+
return Promise.resolve(splitUpdateNotification ?
|
|
157
157
|
{ splits: [splitUpdateNotification.payload], till: splitUpdateNotification.changeNumber } :
|
|
158
158
|
splitChangesFetcher(since, noCache, till, _promiseDecorator)
|
|
159
159
|
)
|
|
@@ -200,15 +200,6 @@ export function splitChangesUpdaterFactory(
|
|
|
200
200
|
}
|
|
201
201
|
return false;
|
|
202
202
|
});
|
|
203
|
-
|
|
204
|
-
// After triggering the requests, if we have cached splits information let's notify that to emit SDK_READY_FROM_CACHE.
|
|
205
|
-
// Wrapping in a promise since checkCache can be async.
|
|
206
|
-
if (splitsEventEmitter && startingUp) {
|
|
207
|
-
Promise.resolve(splits.checkCache()).then(isCacheReady => {
|
|
208
|
-
if (isCacheReady) splitsEventEmitter.emit(SDK_SPLITS_CACHE_LOADED);
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
return fetcherPromise;
|
|
212
203
|
}
|
|
213
204
|
|
|
214
205
|
let sincePromise = Promise.resolve(splits.getChangeNumber()); // `getChangeNumber` never rejects or throws error
|
|
@@ -349,12 +349,14 @@ export function pushManagerFactory(
|
|
|
349
349
|
// Reconnects in case of a new client.
|
|
350
350
|
// Run in next event-loop cycle to save authentication calls
|
|
351
351
|
// in case multiple clients are created in the current cycle.
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
connectForNewClient
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
352
|
+
if (this.isRunning()) {
|
|
353
|
+
setTimeout(function checkForReconnect() {
|
|
354
|
+
if (connectForNewClient) {
|
|
355
|
+
connectForNewClient = false;
|
|
356
|
+
connectPush();
|
|
357
|
+
}
|
|
358
|
+
}, 0);
|
|
359
|
+
}
|
|
358
360
|
}
|
|
359
361
|
},
|
|
360
362
|
// [Only for client-side]
|
|
@@ -9,6 +9,7 @@ import { SYNC_START_POLLING, SYNC_CONTINUE_POLLING, SYNC_STOP_POLLING } from '..
|
|
|
9
9
|
import { isConsentGranted } from '../consent';
|
|
10
10
|
import { POLLING, STREAMING, SYNC_MODE_UPDATE } from '../utils/constants';
|
|
11
11
|
import { ISdkFactoryContextSync } from '../sdkFactory/types';
|
|
12
|
+
import { SDK_SPLITS_CACHE_LOADED } from '../readiness/constants';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Online SyncManager factory.
|
|
@@ -28,7 +29,7 @@ export function syncManagerOnlineFactory(
|
|
|
28
29
|
*/
|
|
29
30
|
return function (params: ISdkFactoryContextSync): ISyncManagerCS {
|
|
30
31
|
|
|
31
|
-
const { settings, settings: { log, streamingEnabled, sync: { enabled: syncEnabled } },
|
|
32
|
+
const { settings, settings: { log, streamingEnabled, sync: { enabled: syncEnabled } }, telemetryTracker, storage, readiness } = params;
|
|
32
33
|
|
|
33
34
|
/** Polling Manager */
|
|
34
35
|
const pollingManager = pollingManagerFactory && pollingManagerFactory(params);
|
|
@@ -87,6 +88,11 @@ export function syncManagerOnlineFactory(
|
|
|
87
88
|
start() {
|
|
88
89
|
running = true;
|
|
89
90
|
|
|
91
|
+
if (startFirstTime) {
|
|
92
|
+
const isCacheLoaded = storage.validateCache ? storage.validateCache() : false;
|
|
93
|
+
if (isCacheLoaded) Promise.resolve().then(() => { readiness.splits.emit(SDK_SPLITS_CACHE_LOADED); });
|
|
94
|
+
}
|
|
95
|
+
|
|
90
96
|
// start syncing splits and segments
|
|
91
97
|
if (pollingManager) {
|
|
92
98
|
|
|
@@ -96,7 +102,6 @@ export function syncManagerOnlineFactory(
|
|
|
96
102
|
// Doesn't call `syncAll` when the syncManager is resuming
|
|
97
103
|
if (startFirstTime) {
|
|
98
104
|
pollingManager.syncAll();
|
|
99
|
-
startFirstTime = false;
|
|
100
105
|
}
|
|
101
106
|
pushManager.start();
|
|
102
107
|
} else {
|
|
@@ -105,13 +110,14 @@ export function syncManagerOnlineFactory(
|
|
|
105
110
|
} else {
|
|
106
111
|
if (startFirstTime) {
|
|
107
112
|
pollingManager.syncAll();
|
|
108
|
-
startFirstTime = false;
|
|
109
113
|
}
|
|
110
114
|
}
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
// start periodic data recording (events, impressions, telemetry).
|
|
114
118
|
submitterManager.start(!isConsentGranted(settings));
|
|
119
|
+
|
|
120
|
+
startFirstTime = false;
|
|
115
121
|
},
|
|
116
122
|
|
|
117
123
|
/**
|
|
@@ -142,11 +148,12 @@ export function syncManagerOnlineFactory(
|
|
|
142
148
|
if (!pollingManager) return;
|
|
143
149
|
|
|
144
150
|
const mySegmentsSyncTask = (pollingManager as IPollingManagerCS).add(matchingKey, readinessManager, storage);
|
|
151
|
+
if (syncEnabled && pushManager) pushManager.add(matchingKey, mySegmentsSyncTask);
|
|
145
152
|
|
|
146
153
|
if (running) {
|
|
147
154
|
if (syncEnabled) {
|
|
148
155
|
if (pushManager) {
|
|
149
|
-
if (pollingManager
|
|
156
|
+
if (pollingManager.isRunning()) {
|
|
150
157
|
// if doing polling, we must start the periodic fetch of data
|
|
151
158
|
if (storage.splits.usesSegments()) mySegmentsSyncTask.start();
|
|
152
159
|
} else {
|
|
@@ -154,7 +161,6 @@ export function syncManagerOnlineFactory(
|
|
|
154
161
|
// of segments since `syncAll` was already executed when starting the main client
|
|
155
162
|
mySegmentsSyncTask.execute();
|
|
156
163
|
}
|
|
157
|
-
pushManager.add(matchingKey, mySegmentsSyncTask);
|
|
158
164
|
} else {
|
|
159
165
|
if (storage.splits.usesSegments()) mySegmentsSyncTask.start();
|
|
160
166
|
}
|
|
@@ -36,7 +36,7 @@ export function eventTrackerFactory(
|
|
|
36
36
|
whenInit(() => {
|
|
37
37
|
// Wrap in a timeout because we don't want it to be blocking.
|
|
38
38
|
setTimeout(() => {
|
|
39
|
-
// copy of event, to avoid unexpected
|
|
39
|
+
// copy of event, to avoid unexpected behavior if modified by integrations
|
|
40
40
|
const eventDataCopy = objectAssign({}, eventData);
|
|
41
41
|
if (properties) eventDataCopy.properties = objectAssign({}, properties);
|
|
42
42
|
// integrationsManager does not throw errors (they are internally handled by each integration module)
|
|
@@ -60,7 +60,7 @@ export function impressionsTrackerFactory(
|
|
|
60
60
|
if (impressionListener || integrationsManager) {
|
|
61
61
|
for (let i = 0; i < impressionsToListenerCount; i++) {
|
|
62
62
|
const impressionData: SplitIO.ImpressionData = {
|
|
63
|
-
// copy of impression, to avoid unexpected
|
|
63
|
+
// copy of impression, to avoid unexpected behavior if modified by integrations or impressionListener
|
|
64
64
|
impression: objectAssign({}, impressionsToListener[i]),
|
|
65
65
|
attributes,
|
|
66
66
|
ip,
|
package/src/utils/lang/index.ts
CHANGED
|
@@ -120,7 +120,7 @@ export function isBoolean(val: any): boolean {
|
|
|
120
120
|
* Unlike `Number.isFinite`, it also tests Number object instances.
|
|
121
121
|
* Unlike global `isFinite`, it returns false if the value is not a number or Number object instance.
|
|
122
122
|
*/
|
|
123
|
-
export function isFiniteNumber(val: any):
|
|
123
|
+
export function isFiniteNumber(val: any): val is number {
|
|
124
124
|
if (val instanceof Number) val = val.valueOf();
|
|
125
125
|
return typeof val === 'number' ?
|
|
126
126
|
Number.isFinite ? Number.isFinite(val) : isFinite(val) :
|
|
@@ -159,7 +159,7 @@ export function settingsValidation(config: unknown, validationParams: ISettingsV
|
|
|
159
159
|
if (withDefaults.mode === LOCALHOST_MODE && maybeKey === undefined) {
|
|
160
160
|
withDefaults.core.key = 'localhost_key';
|
|
161
161
|
} else {
|
|
162
|
-
// Keeping same
|
|
162
|
+
// Keeping same behavior than JS SDK: if settings key or TT are invalid,
|
|
163
163
|
// `false` value is used as bound key/TT of the default client, which leads to some issues.
|
|
164
164
|
// @ts-ignore, @TODO handle invalid keys as a non-recoverable error?
|
|
165
165
|
withDefaults.core.key = validateKey(log, maybeKey, LOG_PREFIX_CLIENT_INSTANTIATION);
|
|
@@ -8,7 +8,7 @@ import { IStorageFactoryParams, IStorageSync } from '../../../storages/types';
|
|
|
8
8
|
|
|
9
9
|
export function __InLocalStorageMockFactory(params: IStorageFactoryParams): IStorageSync {
|
|
10
10
|
const result = InMemoryStorageCSFactory(params);
|
|
11
|
-
result.
|
|
11
|
+
result.validateCache = () => true; // to emit SDK_READY_FROM_CACHE
|
|
12
12
|
return result;
|
|
13
13
|
}
|
|
14
14
|
__InLocalStorageMockFactory.type = STORAGE_MEMORY;
|
package/types/index.d.ts
CHANGED
package/types/splitio.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Type definitions for Split Software SDKs
|
|
2
|
-
// Project:
|
|
2
|
+
// Project: https://www.split.io/
|
|
3
3
|
|
|
4
4
|
import { RedisOptions } from 'ioredis';
|
|
5
5
|
import { RequestOptions } from 'http';
|
|
@@ -906,6 +906,18 @@ declare namespace SplitIO {
|
|
|
906
906
|
* @defaultValue `'SPLITIO'`
|
|
907
907
|
*/
|
|
908
908
|
prefix?: string;
|
|
909
|
+
/**
|
|
910
|
+
* Number of days before cached data expires if it was not updated. If cache expires, it is cleared on initialization.
|
|
911
|
+
*
|
|
912
|
+
* @defaultValue `10`
|
|
913
|
+
*/
|
|
914
|
+
expirationDays?: number;
|
|
915
|
+
/**
|
|
916
|
+
* Optional settings to clear the cache. If set to `true`, the SDK clears the cached data on initialization, unless the cache was cleared within the last 24 hours.
|
|
917
|
+
*
|
|
918
|
+
* @defaultValue `false`
|
|
919
|
+
*/
|
|
920
|
+
clearOnInit?: boolean;
|
|
909
921
|
}
|
|
910
922
|
/**
|
|
911
923
|
* Storage for asynchronous (consumer) SDK.
|
|
@@ -1229,11 +1241,23 @@ declare namespace SplitIO {
|
|
|
1229
1241
|
*/
|
|
1230
1242
|
type?: BrowserStorage;
|
|
1231
1243
|
/**
|
|
1232
|
-
* Optional prefix to prevent any kind of data collision between SDK versions.
|
|
1244
|
+
* Optional prefix to prevent any kind of data collision between SDK versions when using 'LOCALSTORAGE'.
|
|
1233
1245
|
*
|
|
1234
1246
|
* @defaultValue `'SPLITIO'`
|
|
1235
1247
|
*/
|
|
1236
1248
|
prefix?: string;
|
|
1249
|
+
/**
|
|
1250
|
+
* Optional settings for the 'LOCALSTORAGE' storage type. It specifies the number of days before cached data expires if it was not updated. If cache expires, it is cleared on initialization.
|
|
1251
|
+
*
|
|
1252
|
+
* @defaultValue `10`
|
|
1253
|
+
*/
|
|
1254
|
+
expirationDays?: number;
|
|
1255
|
+
/**
|
|
1256
|
+
* Optional settings for the 'LOCALSTORAGE' storage type. If set to `true`, the SDK clears the cached data on initialization, unless the cache was cleared within the last 24 hours.
|
|
1257
|
+
*
|
|
1258
|
+
* @defaultValue `false`
|
|
1259
|
+
*/
|
|
1260
|
+
clearOnInit?: boolean;
|
|
1237
1261
|
};
|
|
1238
1262
|
}
|
|
1239
1263
|
/**
|