@splitsoftware/splitio-commons 1.17.1-rc.3 → 1.17.1-rc.5
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/CHANGES.txt +28 -28
- package/LICENSE +1 -1
- package/README.md +4 -3
- package/cjs/consent/sdkUserConsent.js +4 -2
- package/cjs/evaluator/matchers/index.js +1 -3
- package/cjs/evaluator/matchers/matcherTypes.js +0 -1
- package/cjs/evaluator/matchers/segment.js +0 -6
- package/cjs/evaluator/matchersTransform/index.js +1 -4
- package/cjs/evaluator/matchersTransform/segment.js +1 -3
- package/cjs/logger/constants.js +2 -2
- package/cjs/logger/messages/info.js +1 -1
- package/cjs/logger/messages/warn.js +1 -1
- package/cjs/readiness/readinessManager.js +11 -12
- package/cjs/readiness/sdkReadinessManager.js +6 -5
- package/cjs/sdkClient/sdkClient.js +5 -5
- package/cjs/sdkClient/sdkClientMethod.js +1 -3
- package/cjs/sdkClient/sdkClientMethodCS.js +17 -15
- package/cjs/sdkClient/sdkClientMethodCSWithTT.js +17 -15
- package/cjs/sdkFactory/index.js +11 -38
- package/cjs/services/decorateHeaders.js +6 -1
- package/cjs/services/splitApi.js +5 -5
- package/cjs/services/splitHttpClient.js +5 -2
- package/cjs/storages/AbstractSegmentsCacheSync.js +12 -41
- package/cjs/storages/AbstractSplitsCacheAsync.js +7 -0
- package/cjs/storages/AbstractSplitsCacheSync.js +8 -2
- package/cjs/storages/KeyBuilderCS.js +5 -23
- package/cjs/storages/dataLoader.js +33 -65
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +52 -29
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +9 -1
- package/cjs/storages/inLocalStorage/index.js +3 -12
- package/cjs/storages/inMemory/InMemoryStorageCS.js +3 -20
- package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +40 -9
- package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +8 -8
- package/cjs/storages/inMemory/TelemetryCacheInMemory.js +10 -7
- package/cjs/storages/inRedis/RedisAdapter.js +1 -1
- package/cjs/storages/inRedis/SegmentsCacheInRedis.js +2 -2
- package/cjs/storages/inRedis/index.js +11 -5
- package/cjs/storages/pluggable/SegmentsCachePluggable.js +2 -2
- package/cjs/storages/pluggable/inMemoryWrapper.js +1 -1
- package/cjs/storages/pluggable/index.js +32 -37
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +7 -2
- package/cjs/sync/polling/fetchers/mySegmentsFetcher.js +8 -5
- package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
- package/cjs/sync/polling/pollingManagerCS.js +1 -1
- package/cjs/sync/polling/pollingManagerSS.js +3 -3
- package/cjs/sync/polling/syncTasks/mySegmentsSyncTask.js +2 -2
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +21 -15
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +2 -2
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +11 -2
- package/cjs/sync/streaming/AuthClient/index.js +1 -1
- package/cjs/sync/streaming/SSEHandler/index.js +5 -3
- package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +48 -107
- package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +3 -3
- package/cjs/sync/streaming/constants.js +3 -3
- package/cjs/sync/streaming/parseUtils.js +9 -14
- package/cjs/sync/streaming/pushManager.js +67 -69
- package/cjs/sync/syncTask.js +2 -2
- package/cjs/trackers/eventTracker.js +9 -11
- package/cjs/trackers/impressionsTracker.js +13 -15
- package/cjs/trackers/uniqueKeysTracker.js +3 -5
- package/cjs/utils/constants/index.js +4 -5
- package/cjs/utils/settingsValidation/index.js +1 -2
- package/cjs/utils/settingsValidation/storage/storageCS.js +12 -1
- package/esm/consent/sdkUserConsent.js +4 -2
- package/esm/evaluator/matchers/index.js +1 -3
- package/esm/evaluator/matchers/matcherTypes.js +0 -1
- package/esm/evaluator/matchers/segment.js +0 -6
- package/esm/evaluator/matchersTransform/index.js +1 -4
- package/esm/evaluator/matchersTransform/segment.js +1 -3
- package/esm/logger/constants.js +1 -1
- package/esm/logger/messages/info.js +1 -1
- package/esm/logger/messages/warn.js +1 -1
- package/esm/readiness/readinessManager.js +11 -12
- package/esm/readiness/sdkReadinessManager.js +6 -5
- package/esm/sdkClient/sdkClient.js +5 -5
- package/esm/sdkClient/sdkClientMethod.js +1 -3
- package/esm/sdkClient/sdkClientMethodCS.js +15 -13
- package/esm/sdkClient/sdkClientMethodCSWithTT.js +15 -13
- package/esm/sdkFactory/index.js +12 -39
- package/esm/services/decorateHeaders.js +4 -0
- package/esm/services/splitApi.js +6 -6
- package/esm/services/splitHttpClient.js +6 -3
- package/esm/storages/AbstractSegmentsCacheSync.js +12 -41
- package/esm/storages/AbstractSplitsCacheAsync.js +7 -0
- package/esm/storages/AbstractSplitsCacheSync.js +9 -3
- package/esm/storages/KeyBuilderCS.js +4 -21
- package/esm/storages/dataLoader.js +31 -62
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +52 -29
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +9 -1
- package/esm/storages/inLocalStorage/index.js +5 -14
- package/esm/storages/inMemory/InMemoryStorageCS.js +3 -20
- package/esm/storages/inMemory/MySegmentsCacheInMemory.js +40 -9
- package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
- package/esm/storages/inMemory/SplitsCacheInMemory.js +8 -8
- package/esm/storages/inMemory/TelemetryCacheInMemory.js +10 -7
- package/esm/storages/inRedis/RedisAdapter.js +1 -1
- package/esm/storages/inRedis/SegmentsCacheInRedis.js +2 -2
- package/esm/storages/inRedis/index.js +11 -5
- package/esm/storages/pluggable/SegmentsCachePluggable.js +2 -2
- package/esm/storages/pluggable/inMemoryWrapper.js +1 -1
- package/esm/storages/pluggable/index.js +32 -37
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +8 -3
- package/esm/sync/polling/fetchers/mySegmentsFetcher.js +8 -5
- package/esm/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
- package/esm/sync/polling/pollingManagerCS.js +1 -1
- package/esm/sync/polling/pollingManagerSS.js +3 -3
- package/esm/sync/polling/syncTasks/mySegmentsSyncTask.js +2 -2
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +21 -15
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +2 -2
- package/esm/sync/polling/updaters/splitChangesUpdater.js +12 -3
- package/esm/sync/streaming/AuthClient/index.js +1 -1
- package/esm/sync/streaming/SSEHandler/index.js +6 -4
- package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +49 -108
- package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +3 -3
- package/esm/sync/streaming/constants.js +2 -2
- package/esm/sync/streaming/parseUtils.js +8 -12
- package/esm/sync/streaming/pushManager.js +70 -72
- package/esm/sync/syncTask.js +2 -2
- package/esm/trackers/eventTracker.js +9 -11
- package/esm/trackers/impressionsTracker.js +13 -15
- package/esm/trackers/uniqueKeysTracker.js +3 -5
- package/esm/utils/constants/index.js +2 -3
- package/esm/utils/settingsValidation/index.js +1 -2
- package/esm/utils/settingsValidation/storage/storageCS.js +10 -0
- package/package.json +1 -1
- package/src/consent/sdkUserConsent.ts +3 -2
- package/src/dtos/types.ts +7 -21
- package/src/evaluator/matchers/index.ts +0 -2
- package/src/evaluator/matchers/matcherTypes.ts +0 -1
- package/src/evaluator/matchers/segment.ts +0 -7
- package/src/evaluator/matchersTransform/index.ts +1 -4
- package/src/evaluator/matchersTransform/segment.ts +3 -5
- package/src/logger/constants.ts +1 -1
- package/src/logger/messages/info.ts +1 -1
- package/src/logger/messages/warn.ts +1 -1
- package/src/readiness/readinessManager.ts +12 -16
- package/src/readiness/sdkReadinessManager.ts +7 -7
- package/src/readiness/types.ts +2 -3
- package/src/sdkClient/sdkClient.ts +5 -5
- package/src/sdkClient/sdkClientMethod.ts +1 -4
- package/src/sdkClient/sdkClientMethodCS.ts +14 -11
- package/src/sdkClient/sdkClientMethodCSWithTT.ts +14 -11
- package/src/sdkFactory/index.ts +13 -42
- package/src/sdkFactory/types.ts +1 -5
- package/src/services/decorateHeaders.ts +5 -0
- package/src/services/splitApi.ts +7 -7
- package/src/services/splitHttpClient.ts +7 -4
- package/src/services/types.ts +2 -2
- package/src/storages/AbstractSegmentsCacheSync.ts +12 -53
- package/src/storages/AbstractSplitsCacheAsync.ts +8 -0
- package/src/storages/AbstractSplitsCacheSync.ts +11 -4
- package/src/storages/KeyBuilderCS.ts +5 -34
- package/src/storages/dataLoader.ts +33 -63
- package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +59 -29
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +10 -1
- package/src/storages/inLocalStorage/index.ts +6 -16
- package/src/storages/inMemory/InMemoryStorageCS.ts +3 -23
- package/src/storages/inMemory/MySegmentsCacheInMemory.ts +44 -10
- package/src/storages/inMemory/SegmentsCacheInMemory.ts +1 -1
- package/src/storages/inMemory/SplitsCacheInMemory.ts +8 -7
- package/src/storages/inMemory/TelemetryCacheInMemory.ts +11 -7
- package/src/storages/inRedis/RedisAdapter.ts +1 -1
- package/src/storages/inRedis/SegmentsCacheInRedis.ts +2 -2
- package/src/storages/inRedis/index.ts +12 -6
- package/src/storages/pluggable/SegmentsCachePluggable.ts +2 -2
- package/src/storages/pluggable/inMemoryWrapper.ts +1 -1
- package/src/storages/pluggable/index.ts +33 -38
- package/src/storages/types.ts +15 -15
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +7 -3
- package/src/sync/polling/fetchers/mySegmentsFetcher.ts +10 -8
- package/src/sync/polling/fetchers/segmentChangesFetcher.ts +1 -1
- package/src/sync/polling/fetchers/types.ts +2 -3
- package/src/sync/polling/pollingManagerCS.ts +4 -4
- package/src/sync/polling/pollingManagerSS.ts +2 -3
- package/src/sync/polling/syncTasks/mySegmentsSyncTask.ts +5 -4
- package/src/sync/polling/types.ts +6 -7
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +22 -19
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +2 -2
- package/src/sync/polling/updaters/splitChangesUpdater.ts +12 -4
- package/src/sync/streaming/AuthClient/index.ts +1 -1
- package/src/sync/streaming/SSEClient/index.ts +6 -4
- package/src/sync/streaming/SSEHandler/index.ts +8 -5
- package/src/sync/streaming/SSEHandler/types.ts +15 -15
- package/src/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.ts +49 -116
- package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +4 -4
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +1 -1
- package/src/sync/streaming/UpdateWorkers/types.ts +2 -2
- package/src/sync/streaming/constants.ts +2 -2
- package/src/sync/streaming/parseUtils.ts +11 -19
- package/src/sync/streaming/pushManager.ts +72 -73
- package/src/sync/streaming/types.ts +10 -10
- package/src/sync/submitters/types.ts +5 -8
- package/src/sync/syncTask.ts +2 -2
- package/src/trackers/eventTracker.ts +7 -10
- package/src/trackers/impressionsTracker.ts +9 -12
- package/src/trackers/types.ts +0 -1
- package/src/trackers/uniqueKeysTracker.ts +4 -6
- package/src/types.ts +9 -16
- package/src/utils/constants/index.ts +2 -3
- package/src/utils/settingsValidation/index.ts +2 -3
- package/src/utils/settingsValidation/storage/storageCS.ts +13 -0
- package/src/utils/settingsValidation/types.ts +1 -1
- package/types/dtos/types.d.ts +7 -18
- package/types/evaluator/matchersTransform/segment.d.ts +2 -2
- package/types/logger/constants.d.ts +1 -1
- package/types/readiness/readinessManager.d.ts +2 -2
- package/types/readiness/sdkReadinessManager.d.ts +3 -2
- package/types/readiness/types.d.ts +2 -3
- package/types/sdkClient/sdkClientMethod.d.ts +1 -1
- package/types/sdkFactory/types.d.ts +1 -4
- package/types/services/decorateHeaders.d.ts +1 -0
- package/types/services/splitApi.d.ts +1 -1
- package/types/services/splitHttpClient.d.ts +1 -1
- package/types/services/types.d.ts +2 -2
- package/types/storages/AbstractSegmentsCacheSync.d.ts +11 -9
- package/types/storages/AbstractSplitsCacheAsync.d.ts +5 -0
- package/types/storages/AbstractSplitsCacheSync.d.ts +6 -1
- package/types/storages/KeyBuilderCS.d.ts +2 -9
- package/types/storages/dataLoader.d.ts +6 -17
- package/types/storages/inLocalStorage/MySegmentsCacheInLocal.d.ts +14 -4
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +6 -0
- package/types/storages/inMemory/MySegmentsCacheInMemory.d.ts +9 -3
- package/types/storages/inMemory/SegmentsCacheInMemory.d.ts +1 -1
- package/types/storages/inMemory/SplitsCacheInMemory.d.ts +1 -1
- package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +6 -4
- package/types/storages/inRedis/SegmentsCacheInRedis.d.ts +1 -1
- package/types/storages/inRedis/index.d.ts +1 -1
- package/types/storages/pluggable/SegmentsCachePluggable.d.ts +1 -1
- package/types/storages/pluggable/inMemoryWrapper.d.ts +1 -1
- package/types/storages/types.d.ts +11 -11
- package/types/sync/polling/fetchers/mySegmentsFetcher.d.ts +2 -2
- package/types/sync/polling/fetchers/types.d.ts +2 -2
- package/types/sync/polling/syncTasks/mySegmentsSyncTask.d.ts +2 -2
- package/types/sync/polling/types.d.ts +4 -7
- package/types/sync/polling/updaters/mySegmentsUpdater.d.ts +3 -4
- package/types/sync/streaming/SSEHandler/types.d.ts +14 -16
- package/types/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.d.ts +2 -4
- package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +1 -2
- package/types/sync/streaming/UpdateWorkers/SplitsUpdateWorker.d.ts +2 -3
- package/types/sync/streaming/UpdateWorkers/types.d.ts +2 -2
- package/types/sync/streaming/constants.d.ts +2 -2
- package/types/sync/streaming/parseUtils.d.ts +5 -4
- package/types/sync/streaming/types.d.ts +8 -8
- package/types/sync/submitters/types.d.ts +4 -7
- package/types/trackers/eventTracker.d.ts +1 -1
- package/types/trackers/impressionsTracker.d.ts +1 -1
- package/types/trackers/types.d.ts +0 -1
- package/types/types.d.ts +9 -15
- package/types/utils/constants/index.d.ts +2 -3
- package/types/utils/settingsValidation/storage/storageCS.d.ts +5 -0
- package/types/utils/settingsValidation/types.d.ts +1 -1
- package/cjs/evaluator/matchers/large_segment.js +0 -16
- package/cjs/sdkClient/identity.js +0 -7
- package/esm/evaluator/matchers/large_segment.js +0 -12
- package/esm/sdkClient/identity.js +0 -3
- package/src/evaluator/matchers/large_segment.ts +0 -18
- package/src/sdkClient/identity.ts +0 -5
- package/types/evaluator/matchers/large_segment.d.ts +0 -5
- package/types/evaluator/matchers/sember_inlist.d.ts +0 -3
- package/types/evaluator/matchersTransform/set.d.ts +0 -5
- package/types/evaluator/matchersTransform/string.d.ts +0 -7
- package/types/sdkClient/identity.d.ts +0 -2
- package/types/storages/AbstractMySegmentsCacheSync.d.ts +0 -39
- package/types/storages/AbstractSplitsCache.d.ts +0 -46
- package/types/sync/streaming/mySegmentsV2utils.d.ts +0 -27
- package/types/sync/streaming/pushManagerCS_Spec1_3.d.ts +0 -9
- package/types/sync/streaming/pushManager_Spec1_3.d.ts +0 -9
- package/types/trackers/impressionObserver/utils.d.ts +0 -5
- package/types/utils/inputValidation/sdkKey.d.ts +0 -7
- package/types/utils/inputValidation/splitExistance.d.ts +0 -7
- package/types/utils/inputValidation/trafficTypeExistance.d.ts +0 -9
- package/types/utils/redis/RedisMock.d.ts +0 -4
- package/types/utils/settingsValidation/logger/globalLogLevel.d.ts +0 -8
- /package/types/utils/{semVer.d.ts → Semver.d.ts} +0 -0
|
@@ -1,120 +1,61 @@
|
|
|
1
1
|
import { Backoff } from '../../../utils/Backoff';
|
|
2
|
-
import {
|
|
3
|
-
import { FETCH_BACKOFF_MAX_RETRIES } from './constants';
|
|
4
|
-
import { MEMBERSHIPS_LS_UPDATE, MEMBERSHIPS_MS_UPDATE } from '../constants';
|
|
2
|
+
import { MY_SEGMENT } from '../../../utils/constants';
|
|
5
3
|
/**
|
|
6
4
|
* MySegmentsUpdateWorker factory
|
|
7
5
|
*/
|
|
8
|
-
export function MySegmentsUpdateWorker(
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
mySegmentsSyncTask.execute(_segmentsData, true, cdnBypass ? maxChangeNumber : undefined).then(res);
|
|
31
|
-
}, _delay);
|
|
32
|
-
}) :
|
|
33
|
-
mySegmentsSyncTask.execute(_segmentsData, true, cdnBypass ? maxChangeNumber : undefined);
|
|
34
|
-
syncTask.then(function (result) {
|
|
35
|
-
if (!isHandlingEvent)
|
|
36
|
-
return; // halt if `stop` has been called
|
|
37
|
-
if (result !== false) { // Unlike `Splits|SegmentsUpdateWorker`, `mySegmentsCache.getChangeNumber` can be -1, since `/memberships` change number is optional
|
|
38
|
-
var storageChangeNumber = mySegmentsCache.getChangeNumber();
|
|
39
|
-
currentChangeNumber = storageChangeNumber > -1 ?
|
|
40
|
-
storageChangeNumber :
|
|
41
|
-
Math.max(currentChangeNumber, currentMaxChangeNumber_1); // use `currentMaxChangeNumber`, in case that `maxChangeNumber` was updated during fetch.
|
|
42
|
-
}
|
|
43
|
-
if (handleNewEvent) {
|
|
44
|
-
__handleMySegmentsUpdateCall();
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
if (_segmentsData)
|
|
48
|
-
telemetryTracker.trackUpdatesFromSSE(MEMBERSHIPS);
|
|
49
|
-
var attempts = backoff.attempts + 1;
|
|
50
|
-
if (maxChangeNumber <= currentChangeNumber) {
|
|
51
|
-
log.debug("Refresh completed" + (cdnBypass ? ' bypassing the CDN' : '') + " in " + attempts + " attempts.");
|
|
52
|
-
isHandlingEvent = false;
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
if (attempts < FETCH_BACKOFF_MAX_RETRIES) {
|
|
56
|
-
backoff.scheduleCall();
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (cdnBypass) {
|
|
60
|
-
log.debug("No changes fetched after " + attempts + " attempts with CDN bypassed.");
|
|
61
|
-
isHandlingEvent = false;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
backoff.reset();
|
|
65
|
-
cdnBypass = true;
|
|
66
|
-
__handleMySegmentsUpdateCall();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
isHandlingEvent = false;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
/**
|
|
77
|
-
* Invoked by NotificationProcessor on MY_(LARGE)_SEGMENTS_UPDATE notifications
|
|
78
|
-
*
|
|
79
|
-
* @param changeNumber change number of the notification
|
|
80
|
-
* @param segmentsData data for KeyList or SegmentRemoval instant updates
|
|
81
|
-
* @param delay optional time to wait for BoundedFetchRequest or BoundedFetchRequest updates
|
|
82
|
-
*/
|
|
83
|
-
put: function (mySegmentsData, payload, delay) {
|
|
84
|
-
var type = mySegmentsData.type, cn = mySegmentsData.cn;
|
|
85
|
-
// Discard event if it is outdated or there is a pending fetch request (_delay is set), but update target change number
|
|
86
|
-
if (cn <= Math.max(currentChangeNumber, mySegmentsCache.getChangeNumber()) || cn <= maxChangeNumber)
|
|
87
|
-
return;
|
|
88
|
-
maxChangeNumber = cn;
|
|
89
|
-
if (_delay)
|
|
90
|
-
return;
|
|
91
|
-
handleNewEvent = true;
|
|
92
|
-
cdnBypass = false;
|
|
93
|
-
_segmentsData = payload && { type: type, cn: cn, added: payload.added, removed: payload.removed };
|
|
94
|
-
_delay = delay;
|
|
95
|
-
if (backoff.timeoutID || !isHandlingEvent)
|
|
6
|
+
export function MySegmentsUpdateWorker(mySegmentsSyncTask, telemetryTracker) {
|
|
7
|
+
var maxChangeNumber = 0; // keeps the maximum changeNumber among queued events
|
|
8
|
+
var currentChangeNumber = -1;
|
|
9
|
+
var handleNewEvent = false;
|
|
10
|
+
var isHandlingEvent;
|
|
11
|
+
var _segmentsData; // keeps the segmentsData (if included in notification payload) from the queued event with maximum changeNumber
|
|
12
|
+
var backoff = new Backoff(__handleMySegmentsUpdateCall);
|
|
13
|
+
function __handleMySegmentsUpdateCall() {
|
|
14
|
+
isHandlingEvent = true;
|
|
15
|
+
if (maxChangeNumber > currentChangeNumber) {
|
|
16
|
+
handleNewEvent = false;
|
|
17
|
+
var currentMaxChangeNumber_1 = maxChangeNumber;
|
|
18
|
+
// fetch mySegments revalidating data if cached
|
|
19
|
+
mySegmentsSyncTask.execute(_segmentsData, true).then(function (result) {
|
|
20
|
+
if (!isHandlingEvent)
|
|
21
|
+
return; // halt if `stop` has been called
|
|
22
|
+
if (result !== false) { // Unlike `Splits|SegmentsUpdateWorker`, we cannot use `mySegmentsCache.getChangeNumber` since `/mySegments` endpoint doesn't provide this value.
|
|
23
|
+
if (_segmentsData)
|
|
24
|
+
telemetryTracker.trackUpdatesFromSSE(MY_SEGMENT);
|
|
25
|
+
currentChangeNumber = Math.max(currentChangeNumber, currentMaxChangeNumber_1); // use `currentMaxChangeNumber`, in case that `maxChangeNumber` was updated during fetch.
|
|
26
|
+
}
|
|
27
|
+
if (handleNewEvent) {
|
|
96
28
|
__handleMySegmentsUpdateCall();
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
backoff.scheduleCall();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
isHandlingEvent = false;
|
|
37
|
+
}
|
|
106
38
|
}
|
|
107
|
-
var updateWorkers = (_a = {},
|
|
108
|
-
_a[MEMBERSHIPS_MS_UPDATE] = createUpdateWorker(storage.segments),
|
|
109
|
-
_a[MEMBERSHIPS_LS_UPDATE] = createUpdateWorker(storage.largeSegments),
|
|
110
|
-
_a);
|
|
111
39
|
return {
|
|
112
|
-
|
|
113
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Invoked by NotificationProcessor on MY_SEGMENTS_UPDATE event
|
|
42
|
+
*
|
|
43
|
+
* @param {number} changeNumber change number of the MY_SEGMENTS_UPDATE notification
|
|
44
|
+
* @param {SegmentsData | undefined} segmentsData might be undefined
|
|
45
|
+
*/
|
|
46
|
+
put: function (changeNumber, segmentsData) {
|
|
47
|
+
if (changeNumber <= currentChangeNumber || changeNumber <= maxChangeNumber)
|
|
48
|
+
return;
|
|
49
|
+
maxChangeNumber = changeNumber;
|
|
50
|
+
handleNewEvent = true;
|
|
51
|
+
_segmentsData = segmentsData;
|
|
52
|
+
if (backoff.timeoutID || !isHandlingEvent)
|
|
53
|
+
__handleMySegmentsUpdateCall();
|
|
54
|
+
backoff.reset();
|
|
114
55
|
},
|
|
115
56
|
stop: function () {
|
|
116
|
-
|
|
117
|
-
|
|
57
|
+
isHandlingEvent = false;
|
|
58
|
+
backoff.reset();
|
|
118
59
|
}
|
|
119
60
|
};
|
|
120
61
|
}
|
|
@@ -13,7 +13,7 @@ export function SegmentsUpdateWorker(log, segmentsSyncTask, segmentsCache) {
|
|
|
13
13
|
var backoff = new Backoff(__handleSegmentUpdateCall, FETCH_BACKOFF_BASE, FETCH_BACKOFF_MAX_WAIT);
|
|
14
14
|
function __handleSegmentUpdateCall() {
|
|
15
15
|
isHandlingEvent = true;
|
|
16
|
-
if (maxChangeNumber > segmentsCache.getChangeNumber(segment)) {
|
|
16
|
+
if (maxChangeNumber > (segmentsCache.getChangeNumber(segment) || -1)) {
|
|
17
17
|
handleNewEvent = false;
|
|
18
18
|
// fetch segments revalidating data if cached
|
|
19
19
|
segmentsSyncTask.execute(false, segment, true, cdnBypass ? maxChangeNumber : undefined).then(function () {
|
|
@@ -24,7 +24,7 @@ export function SegmentsUpdateWorker(log, segmentsSyncTask, segmentsCache) {
|
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
26
|
var attempts = backoff.attempts + 1;
|
|
27
|
-
if (maxChangeNumber <= segmentsCache.getChangeNumber(segment)) {
|
|
27
|
+
if (maxChangeNumber <= (segmentsCache.getChangeNumber(segment) || -1)) {
|
|
28
28
|
log.debug("Refresh completed" + (cdnBypass ? ' bypassing the CDN' : '') + " in " + attempts + " attempts.");
|
|
29
29
|
isHandlingEvent = false;
|
|
30
30
|
return;
|
|
@@ -51,7 +51,7 @@ export function SegmentsUpdateWorker(log, segmentsSyncTask, segmentsCache) {
|
|
|
51
51
|
}
|
|
52
52
|
return {
|
|
53
53
|
put: function (changeNumber) {
|
|
54
|
-
var currentChangeNumber = segmentsCache.getChangeNumber(segment);
|
|
54
|
+
var currentChangeNumber = segmentsCache.getChangeNumber(segment) || -1;
|
|
55
55
|
if (changeNumber <= currentChangeNumber || changeNumber <= maxChangeNumber)
|
|
56
56
|
return;
|
|
57
57
|
maxChangeNumber = changeNumber;
|
|
@@ -22,8 +22,8 @@ export var PUSH_SUBSYSTEM_UP = 'PUSH_SUBSYSTEM_UP';
|
|
|
22
22
|
*/
|
|
23
23
|
export var PUSH_SUBSYSTEM_DOWN = 'PUSH_SUBSYSTEM_DOWN';
|
|
24
24
|
// Update-type push notifications, handled by NotificationProcessor
|
|
25
|
-
export var
|
|
26
|
-
export var
|
|
25
|
+
export var MY_SEGMENTS_UPDATE = 'MY_SEGMENTS_UPDATE';
|
|
26
|
+
export var MY_SEGMENTS_UPDATE_V2 = 'MY_SEGMENTS_UPDATE_V2';
|
|
27
27
|
export var SEGMENT_UPDATE = 'SEGMENT_UPDATE';
|
|
28
28
|
export var SPLIT_KILL = 'SPLIT_KILL';
|
|
29
29
|
export var SPLIT_UPDATE = 'SPLIT_UPDATE';
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { algorithms } from '../../utils/decompress';
|
|
2
2
|
import { decodeFromBase64 } from '../../utils/base64';
|
|
3
|
-
import { hash } from '../../utils/murmur3/murmur3';
|
|
4
3
|
var GZIP = 1;
|
|
5
4
|
var ZLIB = 2;
|
|
6
5
|
function Uint8ArrayToString(myUint8Arr) {
|
|
@@ -75,17 +74,14 @@ export function isInBitmap(bitmap, hash64hex) {
|
|
|
75
74
|
}
|
|
76
75
|
/**
|
|
77
76
|
* Parse feature flags notifications for instant feature flag updates
|
|
77
|
+
*
|
|
78
|
+
* @param {ISplitUpdateData} data
|
|
79
|
+
* @returns {KeyList}
|
|
78
80
|
*/
|
|
79
81
|
export function parseFFUpdatePayload(compression, data) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
export function getDelay(parsedData, matchingKey) {
|
|
86
|
-
if (parsedData.h === 0)
|
|
87
|
-
return 0;
|
|
88
|
-
var interval = parsedData.i || DEFAULT_MAX_INTERVAL;
|
|
89
|
-
var seed = parsedData.s || 0;
|
|
90
|
-
return hash(matchingKey, seed) % interval;
|
|
82
|
+
var avoidPrecisionLoss = false;
|
|
83
|
+
if (compression > 0)
|
|
84
|
+
return parseKeyList(data, compression, avoidPrecisionLoss);
|
|
85
|
+
else
|
|
86
|
+
return JSON.parse(decodeFromBase64(data));
|
|
91
87
|
}
|
|
@@ -8,10 +8,10 @@ import { authenticateFactory, hashUserKey } from './AuthClient';
|
|
|
8
8
|
import { forOwn } from '../../utils/lang';
|
|
9
9
|
import { SSEClient } from './SSEClient';
|
|
10
10
|
import { getMatching } from '../../utils/key';
|
|
11
|
-
import {
|
|
12
|
-
import { STREAMING_FALLBACK, STREAMING_REFRESH_TOKEN, STREAMING_CONNECTING, STREAMING_DISABLED, ERROR_STREAMING_AUTH, STREAMING_DISCONNECTING, STREAMING_RECONNECT,
|
|
11
|
+
import { MY_SEGMENTS_UPDATE, MY_SEGMENTS_UPDATE_V2, PUSH_NONRETRYABLE_ERROR, PUSH_SUBSYSTEM_DOWN, SECONDS_BEFORE_EXPIRATION, SEGMENT_UPDATE, SPLIT_KILL, SPLIT_UPDATE, PUSH_RETRYABLE_ERROR, PUSH_SUBSYSTEM_UP, ControlType } from './constants';
|
|
12
|
+
import { STREAMING_FALLBACK, STREAMING_REFRESH_TOKEN, STREAMING_CONNECTING, STREAMING_DISABLED, ERROR_STREAMING_AUTH, STREAMING_DISCONNECTING, STREAMING_RECONNECT, STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2, STREAMING_PARSING_SPLIT_UPDATE } from '../../logger/constants';
|
|
13
13
|
import { UpdateStrategy } from './SSEHandler/types';
|
|
14
|
-
import {
|
|
14
|
+
import { isInBitmap, parseBitmap, parseFFUpdatePayload, parseKeyList } from './parseUtils';
|
|
15
15
|
import { _Set } from '../../utils/lang/sets';
|
|
16
16
|
import { hash64 } from '../../utils/murmur3/murmur3_64';
|
|
17
17
|
import { TOKEN_REFRESH, AUTH_REJECTION } from '../../utils/constants';
|
|
@@ -45,10 +45,10 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
45
45
|
var segmentsUpdateWorker = userKey ? undefined : SegmentsUpdateWorker(log, pollingManager.segmentsSyncTask, storage.segments);
|
|
46
46
|
// For server-side we pass the segmentsSyncTask, used by SplitsUpdateWorker to fetch new segments
|
|
47
47
|
var splitsUpdateWorker = SplitsUpdateWorker(log, storage.splits, pollingManager.splitsSyncTask, readiness.splits, telemetryTracker, userKey ? undefined : pollingManager.segmentsSyncTask);
|
|
48
|
-
// [Only for client-side] map of hashes to user keys, to dispatch
|
|
48
|
+
// [Only for client-side] map of hashes to user keys, to dispatch MY_SEGMENTS_UPDATE events to the corresponding MySegmentsUpdateWorker
|
|
49
49
|
var userKeyHashes = {};
|
|
50
50
|
// [Only for client-side] map of user keys to their corresponding hash64 and MySegmentsUpdateWorkers.
|
|
51
|
-
// Hash64 is used to process
|
|
51
|
+
// Hash64 is used to process MY_SEGMENTS_UPDATE_V2 events and dispatch actions to the corresponding MySegmentsUpdateWorker.
|
|
52
52
|
var clients = {};
|
|
53
53
|
// [Only for client-side] variable to flag that a new client was added. It is needed to reconnect streaming.
|
|
54
54
|
var connectForNewClient = false;
|
|
@@ -195,76 +195,77 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
195
195
|
}
|
|
196
196
|
splitsUpdateWorker.put(parsedData);
|
|
197
197
|
});
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
catch (e) {
|
|
206
|
-
log.warn(STREAMING_PARSING_MEMBERSHIPS_UPDATE, ['BoundedFetchRequest', e]);
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
|
-
forOwn(clients, function (_a, matchingKey) {
|
|
210
|
-
var hash64 = _a.hash64, worker = _a.worker;
|
|
211
|
-
if (isInBitmap(bitmap_1, hash64.hex)) {
|
|
212
|
-
worker.put(parsedData, undefined, getDelay(parsedData, matchingKey));
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
return;
|
|
198
|
+
if (userKey) {
|
|
199
|
+
pushEmitter.on(MY_SEGMENTS_UPDATE, function handleMySegmentsUpdate(parsedData, channel) {
|
|
200
|
+
var userKeyHash = channel.split('_')[2];
|
|
201
|
+
var userKey = userKeyHashes[userKeyHash];
|
|
202
|
+
if (userKey && clients[userKey]) { // check existence since it can be undefined if client has been destroyed
|
|
203
|
+
clients[userKey].worker.put(parsedData.changeNumber, parsedData.includesPayload ? parsedData.segmentList ? parsedData.segmentList : [] : undefined);
|
|
216
204
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
205
|
+
});
|
|
206
|
+
pushEmitter.on(MY_SEGMENTS_UPDATE_V2, function handleMySegmentsUpdate(parsedData) {
|
|
207
|
+
switch (parsedData.u) {
|
|
208
|
+
case UpdateStrategy.BoundedFetchRequest: {
|
|
209
|
+
var bitmap_1;
|
|
210
|
+
try {
|
|
211
|
+
bitmap_1 = parseBitmap(parsedData.d, parsedData.c);
|
|
212
|
+
}
|
|
213
|
+
catch (e) {
|
|
214
|
+
log.warn(STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2, ['BoundedFetchRequest', e]);
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
forOwn(clients, function (_a) {
|
|
218
|
+
var hash64 = _a.hash64, worker = _a.worker;
|
|
219
|
+
if (isInBitmap(bitmap_1, hash64.hex)) {
|
|
220
|
+
worker.put(parsedData.changeNumber); // fetch mySegments
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
return;
|
|
231
224
|
}
|
|
232
|
-
|
|
233
|
-
var
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
removed: add ? [] : [parsedData.n[0]]
|
|
239
|
-
});
|
|
225
|
+
case UpdateStrategy.KeyList: {
|
|
226
|
+
var keyList = void 0, added_1, removed_1;
|
|
227
|
+
try {
|
|
228
|
+
keyList = parseKeyList(parsedData.d, parsedData.c);
|
|
229
|
+
added_1 = new _Set(keyList.a);
|
|
230
|
+
removed_1 = new _Set(keyList.r);
|
|
240
231
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
232
|
+
catch (e) {
|
|
233
|
+
log.warn(STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2, ['KeyList', e]);
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
forOwn(clients, function (_a) {
|
|
237
|
+
var hash64 = _a.hash64, worker = _a.worker;
|
|
238
|
+
var add = added_1.has(hash64.dec) ? true : removed_1.has(hash64.dec) ? false : undefined;
|
|
239
|
+
if (add !== undefined) {
|
|
240
|
+
worker.put(parsedData.changeNumber, {
|
|
241
|
+
name: parsedData.segmentName,
|
|
242
|
+
add: add
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
return;
|
|
248
247
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
248
|
+
case UpdateStrategy.SegmentRemoval:
|
|
249
|
+
if (!parsedData.segmentName) {
|
|
250
|
+
log.warn(STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2, ['SegmentRemoval', 'No segment name was provided']);
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
forOwn(clients, function (_a) {
|
|
254
|
+
var worker = _a.worker;
|
|
255
|
+
return worker.put(parsedData.changeNumber, {
|
|
256
|
+
name: parsedData.segmentName,
|
|
257
|
+
add: false
|
|
258
|
+
});
|
|
254
259
|
});
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
// `UpdateStrategy.UnboundedFetchRequest` and fallbacks of other cases
|
|
263
|
+
forOwn(clients, function (_a) {
|
|
264
|
+
var worker = _a.worker;
|
|
265
|
+
worker.put(parsedData.changeNumber);
|
|
266
|
+
});
|
|
262
267
|
});
|
|
263
268
|
}
|
|
264
|
-
if (userKey) {
|
|
265
|
-
pushEmitter.on(MEMBERSHIPS_MS_UPDATE, handleMySegmentsUpdate);
|
|
266
|
-
pushEmitter.on(MEMBERSHIPS_LS_UPDATE, handleMySegmentsUpdate);
|
|
267
|
-
}
|
|
268
269
|
else {
|
|
269
270
|
pushEmitter.on(SEGMENT_UPDATE, segmentsUpdateWorker.put);
|
|
270
271
|
}
|
|
@@ -299,10 +300,7 @@ export function pushManagerFactory(params, pollingManager) {
|
|
|
299
300
|
var hash = hashUserKey(userKey);
|
|
300
301
|
if (!userKeyHashes[hash]) {
|
|
301
302
|
userKeyHashes[hash] = userKey;
|
|
302
|
-
clients[userKey] = {
|
|
303
|
-
hash64: hash64(userKey),
|
|
304
|
-
worker: MySegmentsUpdateWorker(log, storage, mySegmentsSyncTask, telemetryTracker)
|
|
305
|
-
};
|
|
303
|
+
clients[userKey] = { hash64: hash64(userKey), worker: MySegmentsUpdateWorker(mySegmentsSyncTask, telemetryTracker) };
|
|
306
304
|
connectForNewClient = true; // we must reconnect on start, to listen the channel for the new user key
|
|
307
305
|
// Reconnects in case of a new client.
|
|
308
306
|
// Run in next event-loop cycle to save authentication calls
|
package/esm/sync/syncTask.js
CHANGED
|
@@ -66,8 +66,8 @@ export function syncTaskFactory(log, task, period, taskName) {
|
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
68
|
stop: function () {
|
|
69
|
-
running
|
|
70
|
-
|
|
69
|
+
if (running) {
|
|
70
|
+
running = false;
|
|
71
71
|
log.debug(SYNC_TASK_STOP, [taskName]);
|
|
72
72
|
clearTimeout(timeoutID);
|
|
73
73
|
timeoutID = undefined;
|
|
@@ -9,7 +9,7 @@ import { isConsumerMode } from '../utils/settingsValidation/mode';
|
|
|
9
9
|
* @param eventsCache cache to save events
|
|
10
10
|
* @param integrationsManager optional event handler used for integrations
|
|
11
11
|
*/
|
|
12
|
-
export function eventTrackerFactory(settings, eventsCache,
|
|
12
|
+
export function eventTrackerFactory(settings, eventsCache, integrationsManager, telemetryCache) {
|
|
13
13
|
var log = settings.log, mode = settings.mode;
|
|
14
14
|
var isAsync = isConsumerMode(mode);
|
|
15
15
|
function queueEventsCallback(eventData, tracked) {
|
|
@@ -20,16 +20,14 @@ export function eventTrackerFactory(settings, eventsCache, whenInit, integration
|
|
|
20
20
|
log.info(EVENTS_TRACKER_SUCCESS, [msg]);
|
|
21
21
|
if (integrationsManager) {
|
|
22
22
|
// Wrap in a timeout because we don't want it to be blocking.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
32
|
-
});
|
|
23
|
+
setTimeout(function () {
|
|
24
|
+
// copy of event, to avoid unexpected behaviour if modified by integrations
|
|
25
|
+
var eventDataCopy = objectAssign({}, eventData);
|
|
26
|
+
if (properties)
|
|
27
|
+
eventDataCopy.properties = objectAssign({}, properties);
|
|
28
|
+
// integrationsManager does not throw errors (they are internally handled by each integration module)
|
|
29
|
+
integrationsManager.handleEvent(eventDataCopy);
|
|
30
|
+
}, 0);
|
|
33
31
|
}
|
|
34
32
|
}
|
|
35
33
|
else {
|
|
@@ -11,7 +11,7 @@ import { CONSENT_DECLINED, DEDUPED, QUEUED } from '../utils/constants';
|
|
|
11
11
|
* @param integrationsManager optional integrations manager
|
|
12
12
|
* @param strategy strategy for impressions tracking.
|
|
13
13
|
*/
|
|
14
|
-
export function impressionsTrackerFactory(settings, impressionsCache, strategy,
|
|
14
|
+
export function impressionsTrackerFactory(settings, impressionsCache, strategy, integrationsManager, telemetryCache) {
|
|
15
15
|
var log = settings.log, impressionListener = settings.impressionListener, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname, version = settings.version;
|
|
16
16
|
return {
|
|
17
17
|
track: function (impressions, attributes) {
|
|
@@ -51,20 +51,18 @@ export function impressionsTrackerFactory(settings, impressionsCache, strategy,
|
|
|
51
51
|
sdkLanguageVersion: version
|
|
52
52
|
};
|
|
53
53
|
// Wrap in a timeout because we don't want it to be blocking.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
67
|
-
});
|
|
54
|
+
setTimeout(function () {
|
|
55
|
+
// integrationsManager.handleImpression does not throw errors
|
|
56
|
+
if (integrationsManager)
|
|
57
|
+
integrationsManager.handleImpression(impressionData);
|
|
58
|
+
try { // @ts-ignore. An exception on the listeners should not break the SDK.
|
|
59
|
+
if (impressionListener)
|
|
60
|
+
impressionListener.logImpression(impressionData);
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
log.error(ERROR_IMPRESSIONS_LISTENER, [err]);
|
|
64
|
+
}
|
|
65
|
+
}, 0);
|
|
68
66
|
};
|
|
69
67
|
for (var i = 0; i < impressionsToListenerCount; i++) {
|
|
70
68
|
_loop_1(i);
|
|
@@ -16,6 +16,9 @@ var noopFilterAdapter = {
|
|
|
16
16
|
export function uniqueKeysTrackerFactory(log, uniqueKeysCache, filterAdapter) {
|
|
17
17
|
if (filterAdapter === void 0) { filterAdapter = noopFilterAdapter; }
|
|
18
18
|
var intervalId;
|
|
19
|
+
if (filterAdapter.refreshRate) {
|
|
20
|
+
intervalId = setInterval(filterAdapter.clear, filterAdapter.refreshRate);
|
|
21
|
+
}
|
|
19
22
|
return {
|
|
20
23
|
track: function (key, featureName) {
|
|
21
24
|
if (!filterAdapter.add(key, featureName)) {
|
|
@@ -24,11 +27,6 @@ export function uniqueKeysTrackerFactory(log, uniqueKeysCache, filterAdapter) {
|
|
|
24
27
|
}
|
|
25
28
|
uniqueKeysCache.track(key, featureName);
|
|
26
29
|
},
|
|
27
|
-
start: function () {
|
|
28
|
-
if (filterAdapter.refreshRate) {
|
|
29
|
-
intervalId = setInterval(filterAdapter.clear, filterAdapter.refreshRate);
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
30
|
stop: function () {
|
|
33
31
|
clearInterval(intervalId);
|
|
34
32
|
}
|
|
@@ -60,7 +60,7 @@ export var EVENTS = 'ev';
|
|
|
60
60
|
export var TELEMETRY = 'te';
|
|
61
61
|
export var TOKEN = 'to';
|
|
62
62
|
export var SEGMENT = 'se';
|
|
63
|
-
export var
|
|
63
|
+
export var MY_SEGMENT = 'ms';
|
|
64
64
|
export var TREATMENT = 't';
|
|
65
65
|
export var TREATMENTS = 'ts';
|
|
66
66
|
export var TREATMENT_WITH_CONFIG = 'tc';
|
|
@@ -86,7 +86,6 @@ export var NON_REQUESTED = 1;
|
|
|
86
86
|
export var DISABLED = 0;
|
|
87
87
|
export var ENABLED = 1;
|
|
88
88
|
export var PAUSED = 2;
|
|
89
|
-
export var FLAG_SPEC_VERSION = '1.
|
|
89
|
+
export var FLAG_SPEC_VERSION = '1.1';
|
|
90
90
|
// Matcher types
|
|
91
91
|
export var IN_SEGMENT = 'IN_SEGMENT';
|
|
92
|
-
export var IN_LARGE_SEGMENT = 'IN_LARGE_SEGMENT';
|
|
@@ -183,10 +183,9 @@ export function settingsValidation(config, validationParams) {
|
|
|
183
183
|
var splitFiltersValidation = validateSplitFilters(log, sync.splitFilters, withDefaults.mode);
|
|
184
184
|
sync.splitFilters = splitFiltersValidation.validFilters;
|
|
185
185
|
sync.__splitFiltersValidation = splitFiltersValidation;
|
|
186
|
-
// ensure a valid flag spec version
|
|
187
186
|
sync.flagSpecVersion = flagSpec ? flagSpec(withDefaults) : FLAG_SPEC_VERSION;
|
|
188
187
|
// ensure a valid user consent value
|
|
189
188
|
// @ts-ignore, modify readonly prop
|
|
190
|
-
withDefaults.userConsent = consent
|
|
189
|
+
withDefaults.userConsent = consent(withDefaults);
|
|
191
190
|
return withDefaults;
|
|
192
191
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { InMemoryStorageCSFactory } from '../../../storages/inMemory/InMemoryStorageCS';
|
|
2
2
|
import { ERROR_STORAGE_INVALID } from '../../../logger/constants';
|
|
3
3
|
import { LOCALHOST_MODE, STANDALONE_MODE, STORAGE_PLUGGABLE, STORAGE_LOCALSTORAGE, STORAGE_MEMORY } from '../../../utils/constants';
|
|
4
|
+
export function __InLocalStorageMockFactory(params) {
|
|
5
|
+
var result = InMemoryStorageCSFactory(params);
|
|
6
|
+
result.splits.checkCache = function () { return true; }; // to emit SDK_READY_FROM_CACHE
|
|
7
|
+
return result;
|
|
8
|
+
}
|
|
9
|
+
__InLocalStorageMockFactory.type = STORAGE_MEMORY;
|
|
4
10
|
/**
|
|
5
11
|
* This function validates `settings.storage` object
|
|
6
12
|
*
|
|
@@ -17,6 +23,10 @@ export function validateStorageCS(settings) {
|
|
|
17
23
|
storage = InMemoryStorageCSFactory;
|
|
18
24
|
log.error(ERROR_STORAGE_INVALID);
|
|
19
25
|
}
|
|
26
|
+
// In localhost mode with InLocalStorage, fallback to a mock InLocalStorage to emit SDK_READY_FROM_CACHE
|
|
27
|
+
if (mode === LOCALHOST_MODE && storage.type === STORAGE_LOCALSTORAGE) {
|
|
28
|
+
return __InLocalStorageMockFactory;
|
|
29
|
+
}
|
|
20
30
|
if ([LOCALHOST_MODE, STANDALONE_MODE].indexOf(mode) === -1) {
|
|
21
31
|
// Consumer modes require an async storage
|
|
22
32
|
if (storage.type !== STORAGE_PLUGGABLE)
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@ const ConsentStatus = {
|
|
|
15
15
|
* The public user consent API exposed via SplitFactory, used to control if the SDK tracks and sends impressions and events or not.
|
|
16
16
|
*/
|
|
17
17
|
export function createUserConsentAPI(params: ISdkFactoryContext) {
|
|
18
|
-
const { settings, settings: { log }, syncManager, storage: { events, impressions, impressionCounts } } = params;
|
|
18
|
+
const { settings, settings: { log }, syncManager, storage: { events, impressions, impressionCounts, uniqueKeys } } = params;
|
|
19
19
|
|
|
20
20
|
if (!isConsentGranted(settings)) log.info(USER_CONSENT_INITIAL, [settings.userConsent]);
|
|
21
21
|
|
|
@@ -41,7 +41,8 @@ export function createUserConsentAPI(params: ISdkFactoryContext) {
|
|
|
41
41
|
// @ts-ignore, clear method is present in storage for standalone and partial consumer mode
|
|
42
42
|
if (events.clear) events.clear(); // @ts-ignore
|
|
43
43
|
if (impressions.clear) impressions.clear(); // @ts-ignore
|
|
44
|
-
if (impressionCounts && impressionCounts.clear) impressionCounts.clear();
|
|
44
|
+
if (impressionCounts && impressionCounts.clear) impressionCounts.clear(); // @ts-ignore
|
|
45
|
+
if (uniqueKeys && uniqueKeys.clear) uniqueKeys.clear();
|
|
45
46
|
}
|
|
46
47
|
} else {
|
|
47
48
|
log.info(USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
|