@splitsoftware/splitio-commons 0.1.1-canary.9 → 0.1.1-rc.18
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/cjs/evaluator/matchers/matcherTypes.js +4 -4
- package/cjs/evaluator/matchersTransform/index.js +11 -11
- package/cjs/evaluator/value/sanitize.js +6 -6
- package/cjs/listeners/browser.js +1 -2
- package/cjs/listeners/node.js +0 -3
- package/cjs/logger/constants.js +3 -1
- package/cjs/logger/messages/error.js +3 -2
- package/cjs/logger/messages/info.js +2 -2
- package/cjs/logger/messages/warn.js +2 -1
- package/cjs/readiness/readinessManager.js +10 -7
- package/cjs/sdkFactory/index.js +1 -4
- package/cjs/services/splitApi.js +1 -1
- package/cjs/services/splitHttpClient.js +5 -4
- package/cjs/storages/AbstractSplitsCacheSync.js +1 -1
- package/cjs/storages/inLocalStorage/index.js +5 -2
- package/cjs/storages/inMemory/InMemoryStorage.js +2 -0
- package/cjs/storages/inMemory/InMemoryStorageCS.js +2 -0
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +6 -2
- package/cjs/storages/inRedis/index.js +5 -2
- package/cjs/storages/pluggable/SplitsCachePluggable.js +6 -2
- package/cjs/storages/pluggable/inMemoryWrapper.js +6 -7
- package/cjs/storages/pluggable/index.js +5 -2
- package/cjs/storages/pluggable/wrapperAdapter.js +0 -1
- package/cjs/sync/offline/splitsParser/splitsParserFromFile.js +92 -89
- package/cjs/sync/offline/splitsParser/splitsParserFromSettings.js +45 -42
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +14 -4
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +30 -10
- package/cjs/sync/streaming/SSEClient/index.js +0 -11
- package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +7 -0
- package/cjs/sync/streaming/SSEHandler/NotificationParser.js +4 -1
- package/cjs/sync/streaming/SSEHandler/index.js +8 -9
- package/cjs/sync/streaming/SSEHandler/types.js +14 -0
- package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +5 -5
- package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -1
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +5 -3
- package/cjs/sync/streaming/constants.js +3 -1
- package/cjs/sync/streaming/mySegmentsV2utils.js +75 -0
- package/cjs/sync/streaming/pushManager.js +141 -40
- package/cjs/sync/submitters/metricsSyncTask.js +1 -1
- package/cjs/sync/submitters/submitterSyncTask.js +2 -2
- package/cjs/sync/syncManagerFromFile.js +15 -0
- package/cjs/sync/syncManagerFromObject.js +14 -0
- package/cjs/sync/syncManagerOffline.js +3 -3
- package/cjs/sync/syncManagerOnline.js +5 -3
- package/cjs/trackers/impressionObserver/ImpressionObserver.js +0 -2
- package/cjs/trackers/impressionObserver/buildKey.js +3 -9
- package/cjs/trackers/impressionObserver/impressionObserverCS.js +2 -2
- package/cjs/trackers/impressionObserver/impressionObserverSS.js +3 -3
- package/cjs/utils/constants/index.js +4 -1
- package/cjs/utils/decompress/index.js +427 -0
- package/cjs/utils/murmur3/{commons.js → common.js} +2 -6
- package/cjs/utils/murmur3/murmur3.js +11 -12
- package/cjs/utils/murmur3/murmur3_128.js +7 -142
- package/cjs/utils/murmur3/murmur3_128_x86.js +154 -0
- package/cjs/utils/murmur3/murmur3_64.js +36 -0
- package/cjs/utils/murmur3/utfx.js +100 -106
- package/cjs/utils/promise/wrapper.js +14 -11
- package/cjs/utils/settingsValidation/index.js +5 -2
- package/cjs/utils/settingsValidation/localhost/index.js +20 -0
- package/cjs/utils/settingsValidation/splitFilters.js +0 -1
- package/cjs/utils/settingsValidation/storage/storageCS.js +18 -8
- package/cjs/utils/settingsValidation/url.js +1 -1
- package/esm/evaluator/matchers/matcherTypes.js +2 -2
- package/esm/evaluator/matchersTransform/index.js +12 -12
- package/esm/evaluator/value/sanitize.js +7 -7
- package/esm/listeners/browser.js +1 -2
- package/esm/listeners/node.js +0 -3
- package/esm/logger/constants.js +2 -0
- package/esm/logger/messages/error.js +3 -2
- package/esm/logger/messages/info.js +2 -2
- package/esm/logger/messages/warn.js +2 -1
- package/esm/readiness/readinessManager.js +10 -7
- package/esm/sdkFactory/index.js +1 -4
- package/esm/services/splitApi.js +1 -1
- package/esm/services/splitHttpClient.js +5 -4
- package/esm/storages/AbstractSplitsCacheSync.js +1 -1
- package/esm/storages/inLocalStorage/index.js +5 -2
- package/esm/storages/inMemory/InMemoryStorage.js +2 -0
- package/esm/storages/inMemory/InMemoryStorageCS.js +2 -0
- package/esm/storages/inRedis/SplitsCacheInRedis.js +6 -2
- package/esm/storages/inRedis/index.js +5 -2
- package/esm/storages/pluggable/SplitsCachePluggable.js +6 -2
- package/esm/storages/pluggable/inMemoryWrapper.js +6 -7
- package/esm/storages/pluggable/index.js +5 -2
- package/esm/storages/pluggable/wrapperAdapter.js +0 -1
- package/esm/sync/offline/splitsParser/splitsParserFromFile.js +90 -88
- package/esm/sync/offline/splitsParser/splitsParserFromSettings.js +43 -41
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +15 -5
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +30 -10
- package/esm/sync/streaming/SSEClient/index.js +0 -11
- package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +7 -0
- package/esm/sync/streaming/SSEHandler/NotificationParser.js +4 -1
- package/esm/sync/streaming/SSEHandler/index.js +9 -10
- package/esm/sync/streaming/SSEHandler/types.js +13 -1
- package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +5 -5
- package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -1
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +5 -3
- package/esm/sync/streaming/constants.js +2 -0
- package/esm/sync/streaming/mySegmentsV2utils.js +69 -0
- package/esm/sync/streaming/pushManager.js +143 -42
- package/esm/sync/submitters/metricsSyncTask.js +1 -1
- package/esm/sync/submitters/submitterSyncTask.js +2 -2
- package/esm/sync/syncManagerFromFile.js +11 -0
- package/esm/sync/syncManagerFromObject.js +10 -0
- package/esm/sync/syncManagerOffline.js +3 -3
- package/esm/sync/syncManagerOnline.js +5 -3
- package/esm/trackers/impressionObserver/ImpressionObserver.js +0 -2
- package/esm/trackers/impressionObserver/buildKey.js +2 -9
- package/esm/trackers/impressionObserver/impressionObserverCS.js +2 -2
- package/esm/trackers/impressionObserver/impressionObserverSS.js +3 -3
- package/esm/utils/constants/index.js +3 -0
- package/esm/utils/decompress/index.js +424 -0
- package/esm/utils/murmur3/{commons.js → common.js} +1 -4
- package/esm/utils/murmur3/murmur3.js +1 -2
- package/esm/utils/murmur3/murmur3_128.js +7 -142
- package/esm/utils/murmur3/murmur3_128_x86.js +150 -0
- package/esm/utils/murmur3/murmur3_64.js +32 -0
- package/esm/utils/murmur3/utfx.js +96 -106
- package/esm/utils/promise/wrapper.js +14 -11
- package/esm/utils/settingsValidation/index.js +5 -2
- package/esm/utils/settingsValidation/localhost/index.js +16 -0
- package/esm/utils/settingsValidation/splitFilters.js +0 -1
- package/esm/utils/settingsValidation/storage/storageCS.js +16 -7
- package/esm/utils/settingsValidation/url.js +1 -1
- package/package.json +5 -5
- package/src/evaluator/matchers/matcherTypes.ts +2 -2
- package/src/evaluator/matchersTransform/index.ts +12 -12
- package/src/evaluator/value/sanitize.ts +7 -7
- package/src/listeners/browser.ts +1 -1
- package/src/listeners/node.ts +1 -2
- package/src/logger/constants.ts +2 -0
- package/src/logger/messages/error.ts +3 -2
- package/src/logger/messages/info.ts +2 -2
- package/src/logger/messages/warn.ts +3 -1
- package/src/readiness/readinessManager.ts +9 -7
- package/src/sdkFactory/index.ts +1 -3
- package/src/sdkFactory/types.ts +3 -3
- package/src/services/splitApi.ts +2 -3
- package/src/services/splitHttpClient.ts +6 -5
- package/src/services/types.ts +5 -5
- package/src/storages/AbstractSplitsCacheSync.ts +1 -1
- package/src/storages/inLocalStorage/index.ts +8 -4
- package/src/storages/inMemory/InMemoryStorage.ts +3 -0
- package/src/storages/inMemory/InMemoryStorageCS.ts +3 -0
- package/src/storages/inRedis/SplitsCacheInRedis.ts +3 -1
- package/src/storages/inRedis/index.ts +8 -4
- package/src/storages/pluggable/SplitsCachePluggable.ts +3 -1
- package/src/storages/pluggable/inMemoryWrapper.ts +6 -7
- package/src/storages/pluggable/index.ts +8 -4
- package/src/storages/pluggable/wrapperAdapter.ts +0 -1
- package/src/storages/types.ts +18 -15
- package/src/sync/offline/splitsParser/splitsParserFromFile.ts +110 -105
- package/src/sync/offline/splitsParser/splitsParserFromSettings.ts +45 -41
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +15 -5
- package/src/sync/polling/types.ts +2 -1
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +28 -10
- package/src/sync/streaming/AuthClient/types.ts +3 -0
- package/src/sync/streaming/SSEClient/index.ts +1 -15
- package/src/sync/streaming/SSEClient/types.ts +0 -1
- package/src/sync/streaming/SSEHandler/NotificationKeeper.ts +8 -0
- package/src/sync/streaming/SSEHandler/NotificationParser.ts +4 -2
- package/src/sync/streaming/SSEHandler/index.ts +11 -20
- package/src/sync/streaming/SSEHandler/types.ts +37 -3
- package/src/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.ts +7 -6
- package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +2 -1
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +4 -3
- package/src/sync/streaming/UpdateWorkers/types.ts +1 -1
- package/src/sync/streaming/constants.ts +2 -0
- package/src/sync/streaming/mySegmentsV2utils.ts +77 -0
- package/src/sync/streaming/pushManager.ts +139 -42
- package/src/sync/streaming/types.ts +14 -22
- package/src/sync/submitters/metricsSyncTask.ts +1 -1
- package/src/sync/submitters/submitterSyncTask.ts +2 -1
- package/src/sync/syncManagerFromFile.ts +13 -0
- package/src/sync/syncManagerFromObject.ts +12 -0
- package/src/sync/syncManagerOffline.ts +3 -3
- package/src/sync/syncManagerOnline.ts +6 -3
- package/src/trackers/impressionObserver/ImpressionObserver.ts +4 -6
- package/src/trackers/impressionObserver/buildKey.ts +2 -16
- package/src/trackers/impressionObserver/impressionObserverCS.ts +2 -2
- package/src/trackers/impressionObserver/impressionObserverSS.ts +3 -3
- package/src/types.ts +16 -2
- package/src/utils/constants/index.ts +6 -1
- package/src/utils/decompress/index.ts +429 -0
- package/src/utils/murmur3/{commons.ts → common.ts} +1 -5
- package/src/utils/murmur3/murmur3.ts +5 -5
- package/src/utils/murmur3/murmur3_128.ts +7 -180
- package/src/utils/murmur3/murmur3_128_x86.ts +188 -0
- package/src/utils/murmur3/murmur3_64.ts +36 -0
- package/src/utils/murmur3/utfx.ts +92 -110
- package/src/utils/promise/wrapper.ts +12 -9
- package/src/utils/settingsValidation/index.ts +8 -4
- package/src/utils/settingsValidation/localhost/index.ts +19 -0
- package/src/utils/settingsValidation/splitFilters.ts +0 -1
- package/src/utils/settingsValidation/storage/storageCS.ts +21 -8
- package/src/utils/settingsValidation/types.ts +2 -11
- package/src/utils/settingsValidation/url.ts +1 -1
- package/types/evaluator/matchers/matcherTypes.d.ts +2 -2
- package/types/listeners/browser.d.ts +1 -0
- package/types/listeners/node.d.ts +0 -1
- package/types/logger/constants.d.ts +2 -0
- package/types/sdkFactory/types.d.ts +3 -3
- package/types/services/types.d.ts +1 -0
- package/types/storages/inLocalStorage/index.d.ts +2 -2
- package/types/storages/inMemory/InMemoryStorage.d.ts +3 -0
- package/types/storages/inMemory/InMemoryStorageCS.d.ts +3 -0
- package/types/storages/inRedis/index.d.ts +2 -2
- package/types/storages/pluggable/index.d.ts +2 -2
- package/types/storages/types.d.ts +15 -15
- package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +2 -7
- package/types/sync/offline/splitsParser/splitsParserFromSettings.d.ts +1 -5
- package/types/sync/polling/types.d.ts +2 -1
- package/types/sync/streaming/AuthClient/indexV1.d.ts +12 -0
- package/types/sync/streaming/AuthClient/indexV2.d.ts +8 -0
- package/types/sync/streaming/AuthClient/types.d.ts +2 -0
- package/types/sync/streaming/SSEClient/index.d.ts +1 -9
- package/types/sync/streaming/SSEClient/types.d.ts +0 -1
- package/types/sync/streaming/SSEHandler/NotificationParser.d.ts +3 -2
- package/types/sync/streaming/SSEHandler/types.d.ts +30 -2
- package/types/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.d.ts +4 -3
- package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +2 -1
- package/types/sync/streaming/UpdateWorkers/SplitsUpdateWorker.d.ts +3 -2
- package/types/sync/streaming/UpdateWorkers/types.d.ts +1 -1
- package/types/sync/streaming/constants.d.ts +3 -1
- package/types/sync/streaming/mySegmentsV2utils.d.ts +27 -0
- package/types/sync/streaming/pushManagerNoUsers.d.ts +13 -0
- package/types/sync/streaming/types.d.ts +9 -5
- package/types/sync/submitters/submitterSyncTask.d.ts +1 -1
- package/types/sync/syncManagerFromFile.d.ts +2 -0
- package/types/sync/syncManagerFromObject.d.ts +2 -0
- package/types/sync/syncManagerOffline.d.ts +1 -1
- package/types/trackers/impressionObserver/ImpressionObserver.d.ts +2 -2
- package/types/trackers/impressionObserver/buildKey.d.ts +1 -1
- package/types/trackers/impressionObserver/impressionObserverCS.d.ts +2 -2
- package/types/trackers/impressionObserver/impressionObserverSS.d.ts +2 -2
- package/types/types.d.ts +16 -2
- package/types/utils/constants/index.d.ts +5 -1
- package/types/utils/decompress/index.d.ts +16 -0
- package/types/utils/murmur3/common.d.ts +12 -0
- package/types/utils/murmur3/murmur3.d.ts +2 -2
- package/types/utils/murmur3/murmur3_128.d.ts +5 -0
- package/types/utils/murmur3/murmur3_128_x86.d.ts +7 -0
- package/types/utils/murmur3/murmur3_64.d.ts +10 -0
- package/types/utils/murmur3/utfx.d.ts +24 -6
- package/types/utils/settingsValidation/index.d.ts +3 -2
- package/types/utils/settingsValidation/localhost/index.d.ts +9 -0
- package/types/utils/settingsValidation/storage/storageCS.d.ts +7 -1
- package/types/utils/settingsValidation/types.d.ts +2 -10
- package/cjs/sync/streaming/pushManagerCS.js +0 -179
- package/cjs/sync/streaming/pushManagerSS.js +0 -128
- package/esm/sync/streaming/pushManagerCS.js +0 -175
- package/esm/sync/streaming/pushManagerSS.js +0 -124
- package/src/sync/streaming/pushManagerCS.ts +0 -238
- package/src/sync/streaming/pushManagerSS.ts +0 -177
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IMySegmentsUpdateData } from './SSEHandler/types';
|
|
1
|
+
import { IMySegmentsUpdateData, IMySegmentsUpdateV2Data, ISegmentUpdateData, ISplitUpdateData, ISplitKillData } from './SSEHandler/types';
|
|
2
2
|
import { ITask } from '../types';
|
|
3
3
|
import { IPollingManager, ISegmentsSyncTask } from '../polling/types';
|
|
4
4
|
import { IReadinessManager } from '../../readiness/types';
|
|
@@ -6,6 +6,7 @@ import { IFetchAuth } from '../../services/types';
|
|
|
6
6
|
import { IStorageSync } from '../../storages/types';
|
|
7
7
|
import { IEventEmitter, ISettings } from '../../types';
|
|
8
8
|
import { IPlatform } from '../../sdkFactory/types';
|
|
9
|
+
import { ControlType } from './constants';
|
|
9
10
|
|
|
10
11
|
// Internal SDK events, subscribed by SyncManager and PushManager
|
|
11
12
|
export type PUSH_SUBSYSTEM_UP = 'PUSH_SUBSYSTEM_UP'
|
|
@@ -15,6 +16,7 @@ export type PUSH_RETRYABLE_ERROR = 'PUSH_RETRYABLE_ERROR'
|
|
|
15
16
|
|
|
16
17
|
// Update-type push notifications, handled by NotificationProcessor
|
|
17
18
|
export type MY_SEGMENTS_UPDATE = 'MY_SEGMENTS_UPDATE';
|
|
19
|
+
export type MY_SEGMENTS_UPDATE_V2 = 'MY_SEGMENTS_UPDATE_V2';
|
|
18
20
|
export type SEGMENT_UPDATE = 'SEGMENT_UPDATE';
|
|
19
21
|
export type SPLIT_KILL = 'SPLIT_KILL';
|
|
20
22
|
export type SPLIT_UPDATE = 'SPLIT_UPDATE';
|
|
@@ -23,33 +25,23 @@ export type SPLIT_UPDATE = 'SPLIT_UPDATE';
|
|
|
23
25
|
export type CONTROL = 'CONTROL';
|
|
24
26
|
export type OCCUPANCY = 'OCCUPANCY';
|
|
25
27
|
|
|
26
|
-
export type IPushEvent = PUSH_SUBSYSTEM_UP | PUSH_SUBSYSTEM_DOWN | PUSH_NONRETRYABLE_ERROR | PUSH_RETRYABLE_ERROR | MY_SEGMENTS_UPDATE | SEGMENT_UPDATE | SPLIT_UPDATE | SPLIT_KILL
|
|
28
|
+
export type IPushEvent = PUSH_SUBSYSTEM_UP | PUSH_SUBSYSTEM_DOWN | PUSH_NONRETRYABLE_ERROR | PUSH_RETRYABLE_ERROR | MY_SEGMENTS_UPDATE | MY_SEGMENTS_UPDATE_V2 | SEGMENT_UPDATE | SPLIT_UPDATE | SPLIT_KILL | ControlType.STREAMING_RESET
|
|
29
|
+
|
|
30
|
+
type IParsedData<T extends IPushEvent> =
|
|
31
|
+
T extends MY_SEGMENTS_UPDATE ? IMySegmentsUpdateData :
|
|
32
|
+
T extends MY_SEGMENTS_UPDATE_V2 ? IMySegmentsUpdateV2Data :
|
|
33
|
+
T extends SEGMENT_UPDATE ? ISegmentUpdateData :
|
|
34
|
+
T extends SPLIT_UPDATE ? ISplitUpdateData :
|
|
35
|
+
T extends SPLIT_KILL ? ISplitKillData : undefined;
|
|
27
36
|
|
|
28
37
|
/**
|
|
29
38
|
* EventEmitter used as Feedback Loop between the SyncManager and PushManager,
|
|
30
39
|
* where the latter pushes messages and the former consumes it
|
|
31
40
|
*/
|
|
32
41
|
export interface IPushEventEmitter extends IEventEmitter {
|
|
33
|
-
once<T extends IPushEvent>(event: T, listener: (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
T extends SPLIT_UPDATE ? [changeNumber: number] :
|
|
37
|
-
T extends SPLIT_KILL ? [changeNumber: number, splitName: string, defaultTreatment: string] :
|
|
38
|
-
any[]) => void): this;
|
|
39
|
-
|
|
40
|
-
on<T extends IPushEvent>(event: T, listener: (...args:
|
|
41
|
-
T extends MY_SEGMENTS_UPDATE ? [parsedData: IMySegmentsUpdateData, channel: string] :
|
|
42
|
-
T extends SEGMENT_UPDATE ? [changeNumber: number, segmentName: string] :
|
|
43
|
-
T extends SPLIT_UPDATE ? [changeNumber: number] :
|
|
44
|
-
T extends SPLIT_KILL ? [changeNumber: number, splitName: string, defaultTreatment: string] :
|
|
45
|
-
any[]) => void): this;
|
|
46
|
-
|
|
47
|
-
emit<T extends IPushEvent>(event: T, ...args:
|
|
48
|
-
T extends MY_SEGMENTS_UPDATE ? [parsedData: IMySegmentsUpdateData, channel: string] :
|
|
49
|
-
T extends SEGMENT_UPDATE ? [changeNumber: number, segmentName: string] :
|
|
50
|
-
T extends SPLIT_UPDATE ? [changeNumber: number] :
|
|
51
|
-
T extends SPLIT_KILL ? [changeNumber: number, splitName: string, defaultTreatment: string] :
|
|
52
|
-
any[]): boolean;
|
|
42
|
+
once<T extends IPushEvent>(event: T, listener: (parsedData: IParsedData<T>, channel: T extends MY_SEGMENTS_UPDATE ? string : undefined) => void): this;
|
|
43
|
+
on<T extends IPushEvent>(event: T, listener: (parsedData: IParsedData<T>, channel: T extends MY_SEGMENTS_UPDATE ? string : undefined) => void): this;
|
|
44
|
+
emit<T extends IPushEvent>(event: T, parsedData?: IParsedData<T>, channel?: T extends MY_SEGMENTS_UPDATE ? string : undefined): boolean;
|
|
53
45
|
}
|
|
54
46
|
|
|
55
47
|
/**
|
|
@@ -45,5 +45,5 @@ export function latenciesSyncTaskFactory(
|
|
|
45
45
|
): ISyncTask {
|
|
46
46
|
|
|
47
47
|
// don't retry metrics.
|
|
48
|
-
return submitterSyncTaskFactory(log, postMetricsLatencies, latenciesCache, metricsRefreshRate, 'latency metrics', latencyTracker, fromCache<number[]>('latencies'));
|
|
48
|
+
return submitterSyncTaskFactory(log, postMetricsLatencies, latenciesCache, metricsRefreshRate, 'latency metrics', latencyTracker, fromCache<number[]>('latencies'), 0, true);
|
|
49
49
|
}
|
|
@@ -17,6 +17,7 @@ export function submitterSyncTaskFactory<TState extends { length?: number }>(
|
|
|
17
17
|
latencyTracker?: ITimeTracker,
|
|
18
18
|
fromCacheToPayload?: (cacheData: TState) => any,
|
|
19
19
|
maxRetries: number = 0,
|
|
20
|
+
debugLogs?: boolean
|
|
20
21
|
): ISyncTask<[], void> {
|
|
21
22
|
|
|
22
23
|
let retries = 0;
|
|
@@ -27,7 +28,7 @@ export function submitterSyncTaskFactory<TState extends { length?: number }>(
|
|
|
27
28
|
const data = sourceCache.state();
|
|
28
29
|
|
|
29
30
|
const dataCount: number | '' = typeof data.length === 'number' ? data.length : '';
|
|
30
|
-
log
|
|
31
|
+
log[debugLogs ? 'debug' : 'info'](SUBMITTERS_PUSH, [dataCount, dataName]);
|
|
31
32
|
const latencyTrackerStop = latencyTracker && latencyTracker.start();
|
|
32
33
|
|
|
33
34
|
const jsonPayload = JSON.stringify(fromCacheToPayload ? fromCacheToPayload(data) : data);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { splitsParserFromFileFactory } from './offline/splitsParser/splitsParserFromFile';
|
|
2
|
+
import { syncManagerOfflineFactory } from './syncManagerOffline';
|
|
3
|
+
import { SplitIO } from '../types';
|
|
4
|
+
import { LOCALHOST_MODE } from '../utils/constants';
|
|
5
|
+
|
|
6
|
+
// Factory of Localhost SyncManager based on yaml file.
|
|
7
|
+
// Requires Node 'fs' and 'path' APIs.
|
|
8
|
+
export function LocalhostFromFile(): SplitIO.LocalhostFactory {
|
|
9
|
+
const localhost = syncManagerOfflineFactory(splitsParserFromFileFactory);
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
localhost.type = LOCALHOST_MODE;
|
|
12
|
+
return localhost;
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { splitsParserFromSettingsFactory } from './offline/splitsParser/splitsParserFromSettings';
|
|
2
|
+
import { syncManagerOfflineFactory } from './syncManagerOffline';
|
|
3
|
+
import { SplitIO } from '../types';
|
|
4
|
+
import { LOCALHOST_MODE } from '../utils/constants';
|
|
5
|
+
|
|
6
|
+
// Factory of Localhost SyncManager based on JS object.
|
|
7
|
+
export function LocalhostFromObject(): SplitIO.LocalhostFactory {
|
|
8
|
+
const localhost = syncManagerOfflineFactory(splitsParserFromSettingsFactory);
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
localhost.type = LOCALHOST_MODE;
|
|
11
|
+
return localhost;
|
|
12
|
+
}
|
|
@@ -16,7 +16,7 @@ function flush() {
|
|
|
16
16
|
* @param splitsParser e.g., `splitsParserFromFile`, `splitsParserFromSettings`.
|
|
17
17
|
*/
|
|
18
18
|
export function syncManagerOfflineFactory(
|
|
19
|
-
|
|
19
|
+
splitsParserFactory: () => ISplitsParser
|
|
20
20
|
): (params: ISyncManagerFactoryParams) => ISyncManagerCS {
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -29,7 +29,7 @@ export function syncManagerOfflineFactory(
|
|
|
29
29
|
}: ISyncManagerFactoryParams): ISyncManagerCS {
|
|
30
30
|
|
|
31
31
|
return objectAssign(
|
|
32
|
-
fromObjectSyncTaskFactory(
|
|
32
|
+
fromObjectSyncTaskFactory(splitsParserFactory(), storage, readiness, settings),
|
|
33
33
|
{
|
|
34
34
|
// fake flush, that resolves immediately
|
|
35
35
|
flush,
|
|
@@ -38,7 +38,7 @@ export function syncManagerOfflineFactory(
|
|
|
38
38
|
shared(matchingKey: string, readinessManager: IReadinessManager): ISyncManager {
|
|
39
39
|
return {
|
|
40
40
|
start() {
|
|
41
|
-
// In LOCALHOST mode, shared clients are ready in the next event cycle than created
|
|
41
|
+
// In LOCALHOST mode, shared clients are ready in the next event-loop cycle than created
|
|
42
42
|
// SDK_READY cannot be emitted directly because this will not update the readiness status
|
|
43
43
|
setTimeout(() => {
|
|
44
44
|
readinessManager.segments.emit(SDK_SEGMENTS_ARRIVED); // SDK_SPLITS_ARRIVED emitted by main SyncManager
|
|
@@ -75,6 +75,11 @@ export function syncManagerOnlineFactory(
|
|
|
75
75
|
pollingManager.syncAll();
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
if (pushManager) {
|
|
79
|
+
pushManager.on(PUSH_SUBSYSTEM_UP, stopPollingAndSyncAll);
|
|
80
|
+
pushManager.on(PUSH_SUBSYSTEM_DOWN, startPolling);
|
|
81
|
+
}
|
|
82
|
+
|
|
78
83
|
let running = false; // flag that indicates whether the syncManager has been started (true) or stopped (false)
|
|
79
84
|
let startFirstTime = true; // flag to distinguish calling the `start` method for the first time, to support pausing and resuming the synchronization
|
|
80
85
|
|
|
@@ -87,11 +92,9 @@ export function syncManagerOnlineFactory(
|
|
|
87
92
|
start() {
|
|
88
93
|
// start syncing splits and segments
|
|
89
94
|
if (pushManager) {
|
|
90
|
-
//
|
|
95
|
+
// Doesn't call `syncAll` when the syncManager is resuming
|
|
91
96
|
if (startFirstTime) {
|
|
92
97
|
pollingManager.syncAll();
|
|
93
|
-
pushManager.on(PUSH_SUBSYSTEM_UP, stopPollingAndSyncAll);
|
|
94
|
-
pushManager.on(PUSH_SUBSYSTEM_DOWN, startPolling);
|
|
95
98
|
startFirstTime = false;
|
|
96
99
|
}
|
|
97
100
|
pushManager.start();
|
|
@@ -2,18 +2,16 @@ import { ImpressionDTO } from '../../types';
|
|
|
2
2
|
import LRUCache from '../../utils/LRUCache';
|
|
3
3
|
import { IImpressionObserver } from './types';
|
|
4
4
|
|
|
5
|
-
export default class ImpressionObserver implements IImpressionObserver {
|
|
6
|
-
private cache: LRUCache<
|
|
7
|
-
private hasher: (impression: ImpressionDTO) =>
|
|
5
|
+
export default class ImpressionObserver<K extends string | number> implements IImpressionObserver {
|
|
6
|
+
private cache: LRUCache<K, number>;
|
|
7
|
+
private hasher: (impression: ImpressionDTO) => K;
|
|
8
8
|
|
|
9
|
-
constructor(size: number, hasher: (impression: ImpressionDTO) =>
|
|
9
|
+
constructor(size: number, hasher: (impression: ImpressionDTO) => K) {
|
|
10
10
|
this.cache = new LRUCache(size);
|
|
11
11
|
this.hasher = hasher;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
testAndSet(impression: ImpressionDTO) {
|
|
15
|
-
if (!impression) return;
|
|
16
|
-
|
|
17
15
|
const hash = this.hasher(impression);
|
|
18
16
|
const previous = this.cache.get(hash);
|
|
19
17
|
this.cache.set(hash, impression.time);
|
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
import { ImpressionDTO } from '../../types';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function _unknownIfNull(s: any) {
|
|
6
|
-
return s ? s : UNKNOWN;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function _zeroIfNull(l: any) {
|
|
10
|
-
return l ? l : 0;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default function buildKey(impression: ImpressionDTO) {
|
|
14
|
-
return `${_unknownIfNull(impression.keyName)}
|
|
15
|
-
:${_unknownIfNull(impression.feature)}
|
|
16
|
-
:${_unknownIfNull(impression.treatment)}
|
|
17
|
-
:${_unknownIfNull(impression.label)}
|
|
18
|
-
:${_zeroIfNull(impression.changeNumber)}`;
|
|
3
|
+
export function buildKey(impression: ImpressionDTO) {
|
|
4
|
+
return `${impression.keyName}:${impression.feature}:${impression.treatment}:${impression.label}:${impression.changeNumber}`;
|
|
19
5
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import ImpressionObserver from './ImpressionObserver';
|
|
2
2
|
import { hash } from '../../utils/murmur3/murmur3';
|
|
3
|
-
import buildKey from './buildKey';
|
|
3
|
+
import { buildKey } from './buildKey';
|
|
4
4
|
import { ImpressionDTO } from '../../types';
|
|
5
5
|
|
|
6
6
|
export function hashImpression32(impression: ImpressionDTO) {
|
|
7
|
-
return
|
|
7
|
+
return hash(buildKey(impression));
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
const LAST_SEEN_CACHE_SIZE = 500; // cache up to 500 impression hashes
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import ImpressionObserver from './ImpressionObserver';
|
|
2
|
-
import { hash128 } from '../../utils/murmur3/
|
|
3
|
-
import buildKey from './buildKey';
|
|
2
|
+
import { hash128 } from '../../utils/murmur3/murmur3_128_x86';
|
|
3
|
+
import { buildKey } from './buildKey';
|
|
4
4
|
import { ImpressionDTO } from '../../types';
|
|
5
5
|
|
|
6
6
|
export function hashImpression128(impression: ImpressionDTO) {
|
|
7
|
-
return
|
|
7
|
+
return hash128(buildKey(impression));
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
const LAST_SEEN_CACHE_SIZE = 500000; // cache up to 500k impression hashes
|
package/src/types.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { ISplitFiltersValidation } from './dtos/types';
|
|
1
2
|
import { IIntegration, IIntegrationFactoryParams } from './integrations/types';
|
|
2
3
|
import { ILogger } from './logger/types';
|
|
3
4
|
/* eslint-disable no-use-before-define */
|
|
4
5
|
|
|
5
|
-
import { IStorageFactoryParams, IStorageSyncCS, IStorageSync, IStorageAsync } from './storages/types';
|
|
6
|
+
import { IStorageFactoryParams, IStorageSyncCS, IStorageSync, IStorageAsync, IStorageSyncFactory } from './storages/types';
|
|
7
|
+
import { ISyncManagerFactoryParams, ISyncManagerCS } from './sync/types';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* EventEmitter interface with the minimal methods used by the SDK
|
|
@@ -55,6 +57,8 @@ export type SDKMode = 'standalone' | 'consumer' | 'localhost';
|
|
|
55
57
|
* Settings interface. This is a representation of the settings the SDK expose, that's why
|
|
56
58
|
* most of it's props are readonly. Only features should be rewritten when localhost mode is active.
|
|
57
59
|
* @interface ISettings
|
|
60
|
+
*
|
|
61
|
+
* NOTE: same ISettings interface from public type declarations extended with private properties.
|
|
58
62
|
*/
|
|
59
63
|
export interface ISettings {
|
|
60
64
|
readonly core: {
|
|
@@ -81,7 +85,7 @@ export interface ISettings {
|
|
|
81
85
|
retriesOnFailureBeforeReady: number,
|
|
82
86
|
eventsFirstPushWindow: number
|
|
83
87
|
},
|
|
84
|
-
readonly storage:
|
|
88
|
+
readonly storage: IStorageSyncFactory,
|
|
85
89
|
readonly integrations?: Array<(params: IIntegrationFactoryParams) => IIntegration | void>,
|
|
86
90
|
readonly urls: {
|
|
87
91
|
events: string,
|
|
@@ -96,12 +100,15 @@ export interface ISettings {
|
|
|
96
100
|
readonly sync: {
|
|
97
101
|
splitFilters: SplitIO.SplitFilter[],
|
|
98
102
|
impressionsMode: SplitIO.ImpressionsMode,
|
|
103
|
+
__splitFiltersValidation: ISplitFiltersValidation,
|
|
104
|
+
localhostMode: SplitIO.LocalhostFactory
|
|
99
105
|
},
|
|
100
106
|
readonly runtime: {
|
|
101
107
|
ip: string | false
|
|
102
108
|
hostname: string | false
|
|
103
109
|
},
|
|
104
110
|
readonly log: ILogger
|
|
111
|
+
readonly impressionListener?: unknown
|
|
105
112
|
}
|
|
106
113
|
/**
|
|
107
114
|
* Log levels.
|
|
@@ -576,6 +583,13 @@ export namespace SplitIO {
|
|
|
576
583
|
* @typedef {Promise<SplitNames>} SplitNamesAsync
|
|
577
584
|
*/
|
|
578
585
|
export type SplitNamesAsync = Promise<SplitNames>;
|
|
586
|
+
/**
|
|
587
|
+
* Localhost mode factory.
|
|
588
|
+
*/
|
|
589
|
+
export type LocalhostFactory = {
|
|
590
|
+
type?: 'localhost'
|
|
591
|
+
(params: ISyncManagerFactoryParams): ISyncManagerCS
|
|
592
|
+
}
|
|
579
593
|
/**
|
|
580
594
|
* Impression listener interface. This is the interface that needs to be implemented
|
|
581
595
|
* by the element you provide to the SDK as impression listener.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { StorageType } from '../../storages/types';
|
|
2
|
+
|
|
1
3
|
// Special treatments
|
|
2
4
|
export const CONTROL = 'control';
|
|
3
5
|
export const CONTROL_WITH_CONFIG = {
|
|
@@ -24,4 +26,7 @@ export const PRODUCER_MODE = 'producer';
|
|
|
24
26
|
export const CONSUMER_MODE = 'consumer';
|
|
25
27
|
|
|
26
28
|
// Storage types
|
|
27
|
-
export const STORAGE_MEMORY = 'MEMORY';
|
|
29
|
+
export const STORAGE_MEMORY: StorageType = 'MEMORY';
|
|
30
|
+
export const STORAGE_LOCALSTORAGE: StorageType = 'LOCALSTORAGE';
|
|
31
|
+
export const STORAGE_REDIS: StorageType = 'REDIS';
|
|
32
|
+
export const STORAGE_CUSTOM: StorageType = 'CUSTOM';
|