@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
package/types/types.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { ISplitFiltersValidation } from './dtos/types';
|
|
2
3
|
import { IIntegration, IIntegrationFactoryParams } from './integrations/types';
|
|
3
4
|
import { ILogger } from './logger/types';
|
|
4
|
-
import { IStorageFactoryParams, IStorageSyncCS, IStorageSync, IStorageAsync } from './storages/types';
|
|
5
|
+
import { IStorageFactoryParams, IStorageSyncCS, IStorageSync, IStorageAsync, IStorageSyncFactory } from './storages/types';
|
|
6
|
+
import { ISyncManagerFactoryParams, ISyncManagerCS } from './sync/types';
|
|
5
7
|
/**
|
|
6
8
|
* EventEmitter interface with the minimal methods used by the SDK
|
|
7
9
|
*/
|
|
@@ -50,6 +52,8 @@ export declare type SDKMode = 'standalone' | 'consumer' | 'localhost';
|
|
|
50
52
|
* Settings interface. This is a representation of the settings the SDK expose, that's why
|
|
51
53
|
* most of it's props are readonly. Only features should be rewritten when localhost mode is active.
|
|
52
54
|
* @interface ISettings
|
|
55
|
+
*
|
|
56
|
+
* NOTE: same ISettings interface from public type declarations extended with private properties.
|
|
53
57
|
*/
|
|
54
58
|
export interface ISettings {
|
|
55
59
|
readonly core: {
|
|
@@ -76,7 +80,7 @@ export interface ISettings {
|
|
|
76
80
|
retriesOnFailureBeforeReady: number;
|
|
77
81
|
eventsFirstPushWindow: number;
|
|
78
82
|
};
|
|
79
|
-
readonly storage:
|
|
83
|
+
readonly storage: IStorageSyncFactory;
|
|
80
84
|
readonly integrations?: Array<(params: IIntegrationFactoryParams) => IIntegration | void>;
|
|
81
85
|
readonly urls: {
|
|
82
86
|
events: string;
|
|
@@ -91,12 +95,15 @@ export interface ISettings {
|
|
|
91
95
|
readonly sync: {
|
|
92
96
|
splitFilters: SplitIO.SplitFilter[];
|
|
93
97
|
impressionsMode: SplitIO.ImpressionsMode;
|
|
98
|
+
__splitFiltersValidation: ISplitFiltersValidation;
|
|
99
|
+
localhostMode: SplitIO.LocalhostFactory;
|
|
94
100
|
};
|
|
95
101
|
readonly runtime: {
|
|
96
102
|
ip: string | false;
|
|
97
103
|
hostname: string | false;
|
|
98
104
|
};
|
|
99
105
|
readonly log: ILogger;
|
|
106
|
+
readonly impressionListener?: unknown;
|
|
100
107
|
}
|
|
101
108
|
/**
|
|
102
109
|
* Log levels.
|
|
@@ -571,6 +578,13 @@ export declare namespace SplitIO {
|
|
|
571
578
|
* @typedef {Promise<SplitNames>} SplitNamesAsync
|
|
572
579
|
*/
|
|
573
580
|
type SplitNamesAsync = Promise<SplitNames>;
|
|
581
|
+
/**
|
|
582
|
+
* Localhost mode factory.
|
|
583
|
+
*/
|
|
584
|
+
type LocalhostFactory = {
|
|
585
|
+
type?: 'localhost';
|
|
586
|
+
(params: ISyncManagerFactoryParams): ISyncManagerCS;
|
|
587
|
+
};
|
|
574
588
|
/**
|
|
575
589
|
* Impression listener interface. This is the interface that needs to be implemented
|
|
576
590
|
* by the element you provide to the SDK as impression listener.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { StorageType } from '../../storages/types';
|
|
1
2
|
export declare const CONTROL = "control";
|
|
2
3
|
export declare const CONTROL_WITH_CONFIG: {
|
|
3
4
|
treatment: string;
|
|
@@ -13,4 +14,7 @@ export declare const LOCALHOST_MODE = "localhost";
|
|
|
13
14
|
export declare const STANDALONE_MODE = "standalone";
|
|
14
15
|
export declare const PRODUCER_MODE = "producer";
|
|
15
16
|
export declare const CONSUMER_MODE = "consumer";
|
|
16
|
-
export declare const STORAGE_MEMORY
|
|
17
|
+
export declare const STORAGE_MEMORY: StorageType;
|
|
18
|
+
export declare const STORAGE_LOCALSTORAGE: StorageType;
|
|
19
|
+
export declare const STORAGE_REDIS: StorageType;
|
|
20
|
+
export declare const STORAGE_CUSTOM: StorageType;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const algorithms: string | {
|
|
2
|
+
/**
|
|
3
|
+
* Expands GZIP data
|
|
4
|
+
* @param data The data to decompress
|
|
5
|
+
* @param out Where to write the data. GZIP already encodes the output size, so providing this doesn't save memory.
|
|
6
|
+
* @returns The decompressed version of the data
|
|
7
|
+
*/
|
|
8
|
+
gunzipSync(data: Uint8Array, out?: Uint8Array | undefined): Uint8Array;
|
|
9
|
+
/**
|
|
10
|
+
* Expands Zlib data
|
|
11
|
+
* @param data The data to decompress
|
|
12
|
+
* @param out Where to write the data. Saves memory if you know the decompressed size and provide an output buffer of that length.
|
|
13
|
+
* @returns The decompressed version of the data
|
|
14
|
+
*/
|
|
15
|
+
unzlibSync(data: Uint8Array, out?: Uint8Array | undefined): Uint8Array;
|
|
16
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function UTF16ToUTF8(key: string): string | undefined;
|
|
2
|
+
/*!
|
|
3
|
+
* +----------------------------------------------------------------------------------+
|
|
4
|
+
* | murmurHash3.js v3.0.0 (http://github.com/karanlyons/murmurHash3.js) |
|
|
5
|
+
* | A TypeScript/JavaScript implementation of MurmurHash3's hashing algorithms. |
|
|
6
|
+
* |----------------------------------------------------------------------------------|
|
|
7
|
+
* | Copyright (c) 2012-2020 Karan Lyons. Freely distributable under the MIT license. |
|
|
8
|
+
* +----------------------------------------------------------------------------------+
|
|
9
|
+
*/
|
|
10
|
+
export declare function x86Multiply(m: number, n: number): number;
|
|
11
|
+
export declare function x86Rotl(m: number, n: number): number;
|
|
12
|
+
export declare function x86Fmix(h: number): number;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function hash(str
|
|
2
|
-
export declare function bucket(str
|
|
1
|
+
export declare function hash(str: string, seed?: number): number;
|
|
2
|
+
export declare function bucket(str: string, seed?: number): number;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* x86 version of Murmur3 for 128bits.
|
|
3
|
+
* Used by hashImpression128 because in JS it is more efficient than the x64 version, no matter the underlying OS/CPU arch.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} str
|
|
6
|
+
*/
|
|
7
|
+
export declare function hash128(str: string, seed?: number): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare type Hash64 = {
|
|
2
|
+
hex: string;
|
|
3
|
+
dec: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Gets the higher 64 bits of the x64 version of Murmur3 for 128bits, as decimal and hexadecimal number strings.
|
|
7
|
+
* Used for MySegments channel V2 notifications.
|
|
8
|
+
* @param {string} str
|
|
9
|
+
*/
|
|
10
|
+
export declare function hash64(str: string): Hash64;
|
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
export interface utfx {
|
|
2
|
-
stringSource(key: string): () => number | null;
|
|
3
|
-
stringDestination(): (...args: number[]) => string | undefined;
|
|
4
2
|
encodeUTF16toUTF8(src: () => number | null, dst: (...args: number[]) => string | undefined): void;
|
|
5
|
-
UTF16toUTF8(src: () => number | null, dst: (cp: number) => void): void;
|
|
6
|
-
encodeUTF8(src: (() => number | null) | number, dst: (cp: number) => void): void;
|
|
7
3
|
}
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Converts and encodes UTF16 characters to UTF8 bytes.
|
|
6
|
+
* @param {!function():number|null} src Characters source as a function returning the next char code respectively `null`
|
|
7
|
+
* if there are no more characters left.
|
|
8
|
+
* @param {!function(number)} dst Bytes destination as a function successively called with the next byte.
|
|
9
|
+
* @expose
|
|
10
|
+
*/
|
|
11
|
+
export declare function encodeUTF16toUTF8(src: () => number | null, dst: (...args: number[]) => string | undefined): void;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a source function for a string.
|
|
14
|
+
* @param {string} s String to read from
|
|
15
|
+
* @returns {!function():number|null} Source function returning the next char code respectively `null` if there are
|
|
16
|
+
* no more characters left.
|
|
17
|
+
* @throws {TypeError} If the argument is invalid
|
|
18
|
+
* @expose
|
|
19
|
+
*/
|
|
20
|
+
export declare function stringSource(s: string): () => number | null;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a destination function for a string.
|
|
23
|
+
* @returns {function(number=):undefined|string} Destination function successively called with the next char code.
|
|
24
|
+
* Returns the final string when called without arguments.
|
|
25
|
+
* @expose
|
|
26
|
+
*/
|
|
27
|
+
export declare function stringDestination(): (...args: number[]) => string | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ISettingsValidationParams } from './types';
|
|
2
|
+
import { ISettings } from '../../types';
|
|
2
3
|
/**
|
|
3
4
|
* Validates the given config and use it to build a settings object.
|
|
4
5
|
* NOTE: it doesn't validate the Api Key. Call `validateApikey` or `validateAndTrackApiKey` for that after settings validation.
|
|
@@ -6,4 +7,4 @@ import { ISettingsInternal, ISettingsValidationParams } from './types';
|
|
|
6
7
|
* @param config user defined configuration
|
|
7
8
|
* @param validationParams defaults and fields validators used to validate and creates a settings object from a given config
|
|
8
9
|
*/
|
|
9
|
-
export declare function settingsValidation(config: unknown, validationParams: ISettingsValidationParams):
|
|
10
|
+
export declare function settingsValidation(config: unknown, validationParams: ISettingsValidationParams): ISettings;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ISettings } from '../../../types';
|
|
2
|
+
/**
|
|
3
|
+
* This function validates `settings.storage` object
|
|
4
|
+
*
|
|
5
|
+
* @param {any} settings config object provided by the user to initialize the sdk
|
|
6
|
+
*
|
|
7
|
+
* @returns {Object} valid storage factory. It might be the default `InMemoryStorageCSFactory` if the provided storage is invalid.
|
|
8
|
+
*/
|
|
9
|
+
export declare function validateLocalhost(settings: ISettings): import("../../../types").SplitIO.LocalhostFactory;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import { ISettings } from '../../../types';
|
|
1
|
+
import { ISettings, SDKMode } from '../../../types';
|
|
2
2
|
import { ILogger } from '../../../logger/types';
|
|
3
|
+
import { IStorageFactoryParams, IStorageSyncCS } from '../../../storages/types';
|
|
4
|
+
export declare function __InLocalStorageMockFactory(params: IStorageFactoryParams): IStorageSyncCS;
|
|
5
|
+
export declare namespace __InLocalStorageMockFactory {
|
|
6
|
+
var type: import("../../../storages/types").StorageType;
|
|
7
|
+
}
|
|
3
8
|
/**
|
|
4
9
|
* This function validates `settings.storage` object
|
|
5
10
|
*
|
|
@@ -10,4 +15,5 @@ import { ILogger } from '../../../logger/types';
|
|
|
10
15
|
export declare function validateStorageCS(settings: {
|
|
11
16
|
log: ILogger;
|
|
12
17
|
storage?: any;
|
|
18
|
+
mode?: SDKMode;
|
|
13
19
|
}): ISettings['storage'];
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ISplitFiltersValidation } from '../../dtos/types';
|
|
2
1
|
import { ISettings } from '../../types';
|
|
3
2
|
/**
|
|
4
3
|
* Parameters used to specialize the settings validation for each API variant
|
|
@@ -22,13 +21,6 @@ export interface ISettingsValidationParams {
|
|
|
22
21
|
integrations?: (settings: ISettings) => ISettings['integrations'];
|
|
23
22
|
/** Logger validator */
|
|
24
23
|
logger: (settings: ISettings) => ISettings['log'];
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* Settings interface extended with private properties used for internal purposes.
|
|
28
|
-
*/
|
|
29
|
-
export interface ISettingsInternal extends ISettings {
|
|
30
|
-
readonly sync: ISettings['sync'] & {
|
|
31
|
-
__splitFiltersValidation: ISplitFiltersValidation;
|
|
32
|
-
};
|
|
33
|
-
readonly impressionListener?: unknown;
|
|
24
|
+
/** Localhost mode validator */
|
|
25
|
+
localhost?: (settings: ISettings) => ISettings['sync']['localhostMode'];
|
|
34
26
|
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var tslib_1 = require("tslib");
|
|
4
|
-
var object_assign_1 = tslib_1.__importDefault(require("object-assign"));
|
|
5
|
-
var constants_1 = require("./constants");
|
|
6
|
-
var Backoff_1 = tslib_1.__importDefault(require("../../utils/Backoff"));
|
|
7
|
-
var SSEHandler_1 = tslib_1.__importDefault(require("./SSEHandler"));
|
|
8
|
-
var MySegmentsUpdateWorker_1 = tslib_1.__importDefault(require("./UpdateWorkers/MySegmentsUpdateWorker"));
|
|
9
|
-
var SplitsUpdateWorker_1 = tslib_1.__importDefault(require("./UpdateWorkers/SplitsUpdateWorker"));
|
|
10
|
-
var AuthClient_1 = require("./AuthClient");
|
|
11
|
-
var lang_1 = require("../../utils/lang");
|
|
12
|
-
var SSEClient_1 = tslib_1.__importDefault(require("./SSEClient"));
|
|
13
|
-
var key_1 = require("../../utils/key");
|
|
14
|
-
var constants_2 = require("../../logger/constants");
|
|
15
|
-
/**
|
|
16
|
-
* PushManager factory for client-side, with support for multiple clients.
|
|
17
|
-
* It assumes settings contains a key.
|
|
18
|
-
*/
|
|
19
|
-
function pushManagerCSFactory(pollingManager, storage, readiness, fetchAuth, platform, settings) {
|
|
20
|
-
var log = settings.log;
|
|
21
|
-
var sseClient;
|
|
22
|
-
try {
|
|
23
|
-
// `useHeaders` false for client-side, even if the platform EventSource supports headers (e.g., React Native).
|
|
24
|
-
sseClient = new SSEClient_1.default(settings, false, platform.getEventSource);
|
|
25
|
-
}
|
|
26
|
-
catch (e) {
|
|
27
|
-
log.warn(constants_2.STREAMING_FALLBACK, [e]);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
var authenticate = AuthClient_1.authenticateFactory(fetchAuth);
|
|
31
|
-
// init feedback loop
|
|
32
|
-
var pushEmitter = new platform.EventEmitter();
|
|
33
|
-
var sseHandler = SSEHandler_1.default(log, pushEmitter);
|
|
34
|
-
sseClient.setEventHandler(sseHandler);
|
|
35
|
-
// [Only for client-side] map of hashes to user keys, to dispatch MY_SEGMENTS_UPDATE events to the corresponding MySegmentsUpdateWorker
|
|
36
|
-
var userKeyHashes = {};
|
|
37
|
-
var userKey = key_1.getMatching(settings.core.key); // matching key of main client
|
|
38
|
-
var hash = AuthClient_1.hashUserKey(userKey);
|
|
39
|
-
userKeyHashes[hash] = userKey;
|
|
40
|
-
// [Only for client-side] map of user keys to their corresponding MySegmentsUpdateWorkers. It has a two-fold intention:
|
|
41
|
-
// - stop workers all together when push is disconnected
|
|
42
|
-
// - keep the current list of user keys to authenticate
|
|
43
|
-
var workers = {};
|
|
44
|
-
// init workers
|
|
45
|
-
var mySegmentsUpdateWorker = new MySegmentsUpdateWorker_1.default(pollingManager.segmentsSyncTask);
|
|
46
|
-
workers[userKey] = mySegmentsUpdateWorker;
|
|
47
|
-
var splitsUpdateWorker = new SplitsUpdateWorker_1.default(storage.splits, pollingManager.splitsSyncTask, readiness.splits);
|
|
48
|
-
// [Only for client-side] variable to flag that a new client was added. It is needed to reconnect streaming.
|
|
49
|
-
var connectForNewClient = false;
|
|
50
|
-
// flag that indicates if `disconnectPush` was called, either by the SyncManager (when the client is destroyed) or by a PUSH_NONRETRYABLE_ERROR error.
|
|
51
|
-
// It is used to halt the `connectPush` process if it was in progress.
|
|
52
|
-
var disconnected;
|
|
53
|
-
/** PushManager functions related to initialization */
|
|
54
|
-
var connectPushRetryBackoff = new Backoff_1.default(connectPush, settings.scheduler.pushRetryBackoffBase);
|
|
55
|
-
var timeoutId;
|
|
56
|
-
function scheduleTokenRefresh(issuedAt, expirationTime) {
|
|
57
|
-
// clear scheduled token refresh if exists (needed when resuming PUSH)
|
|
58
|
-
if (timeoutId)
|
|
59
|
-
clearTimeout(timeoutId);
|
|
60
|
-
// Set token refresh 10 minutes before expirationTime
|
|
61
|
-
var delayInSeconds = expirationTime - issuedAt - constants_1.SECONDS_BEFORE_EXPIRATION;
|
|
62
|
-
log.info(constants_2.STREAMING_REFRESH_TOKEN, [delayInSeconds]);
|
|
63
|
-
timeoutId = setTimeout(connectPush, delayInSeconds * 1000);
|
|
64
|
-
}
|
|
65
|
-
function connectPush() {
|
|
66
|
-
disconnected = false;
|
|
67
|
-
log.info(constants_2.STREAMING_CONNECTING);
|
|
68
|
-
var userKeys = Object.keys(workers); // [Only for client-side]
|
|
69
|
-
authenticate(userKeys).then(function (authData) {
|
|
70
|
-
if (disconnected)
|
|
71
|
-
return;
|
|
72
|
-
// 'pushEnabled: false' is handled as a PUSH_NONRETRYABLE_ERROR instead of PUSH_SUBSYSTEM_DOWN, in order to
|
|
73
|
-
// close the sseClient in case the org has been bloqued while the instance was connected to streaming
|
|
74
|
-
if (!authData.pushEnabled) {
|
|
75
|
-
log.info(constants_2.STREAMING_DISABLED);
|
|
76
|
-
pushEmitter.emit(constants_1.PUSH_NONRETRYABLE_ERROR);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
// [Only for client-side] don't open SSE connection if a new shared client was added, since it means that a new authentication is taking place
|
|
80
|
-
if (userKeys && userKeys.length < Object.keys(workers).length)
|
|
81
|
-
return;
|
|
82
|
-
// Connect to SSE and schedule refresh token
|
|
83
|
-
var decodedToken = authData.decodedToken;
|
|
84
|
-
sseClient.open(authData);
|
|
85
|
-
scheduleTokenRefresh(decodedToken.iat, decodedToken.exp);
|
|
86
|
-
}).catch(function (error) {
|
|
87
|
-
if (disconnected)
|
|
88
|
-
return;
|
|
89
|
-
log.error(constants_2.ERROR_STREAMING_AUTH, [error.message]);
|
|
90
|
-
// Handle 4XX HTTP errors: 401 (invalid API Key) or 400 (using incorrect API Key, i.e., client-side API Key on server-side)
|
|
91
|
-
if (error.statusCode >= 400 && error.statusCode < 500) {
|
|
92
|
-
pushEmitter.emit(constants_1.PUSH_NONRETRYABLE_ERROR);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
// Handle other HTTP and network errors as recoverable errors
|
|
96
|
-
pushEmitter.emit(constants_1.PUSH_RETRYABLE_ERROR);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
// close SSE connection and cancel scheduled tasks
|
|
100
|
-
function disconnectPush() {
|
|
101
|
-
sseClient.close();
|
|
102
|
-
disconnected = true;
|
|
103
|
-
log.info(constants_2.STREAMING_DISCONNECTING);
|
|
104
|
-
if (timeoutId)
|
|
105
|
-
clearTimeout(timeoutId);
|
|
106
|
-
connectPushRetryBackoff.reset();
|
|
107
|
-
stopWorkers();
|
|
108
|
-
}
|
|
109
|
-
// cancel scheduled fetch retries of Splits, Segments, and MySegments Update Workers
|
|
110
|
-
function stopWorkers() {
|
|
111
|
-
splitsUpdateWorker.backoff.reset();
|
|
112
|
-
lang_1.forOwn(workers, function (worker) { return worker.backoff.reset(); });
|
|
113
|
-
}
|
|
114
|
-
pushEmitter.on(constants_1.PUSH_SUBSYSTEM_DOWN, stopWorkers);
|
|
115
|
-
// restart backoff retry counter once push is connected
|
|
116
|
-
pushEmitter.on(constants_1.PUSH_SUBSYSTEM_UP, function () { connectPushRetryBackoff.reset(); });
|
|
117
|
-
/** Fallbacking without retry due to: STREAMING_DISABLED control event, or 'pushEnabled: false', or non-recoverable SSE and Authentication errors */
|
|
118
|
-
pushEmitter.on(constants_1.PUSH_NONRETRYABLE_ERROR, function handleNonRetryableError() {
|
|
119
|
-
// Note: `stopWorkers` is been called twice, but it is not harmful
|
|
120
|
-
disconnectPush();
|
|
121
|
-
pushEmitter.emit(constants_1.PUSH_SUBSYSTEM_DOWN); // no harm if polling already
|
|
122
|
-
});
|
|
123
|
-
/** Fallbacking with retry due to recoverable SSE and Authentication errors */
|
|
124
|
-
pushEmitter.on(constants_1.PUSH_RETRYABLE_ERROR, function handleRetryableError() {
|
|
125
|
-
// SSE connection is closed to avoid repeated errors due to retries
|
|
126
|
-
sseClient.close();
|
|
127
|
-
// retry streaming reconnect with backoff algorithm
|
|
128
|
-
var delayInMillis = connectPushRetryBackoff.scheduleCall();
|
|
129
|
-
log.info(constants_2.STREAMING_RECONNECT, [delayInMillis / 1000]);
|
|
130
|
-
pushEmitter.emit(constants_1.PUSH_SUBSYSTEM_DOWN); // no harm if polling already
|
|
131
|
-
});
|
|
132
|
-
/** Functions related to synchronization (Queues and Workers in the spec) */
|
|
133
|
-
pushEmitter.on(constants_1.SPLIT_KILL, splitsUpdateWorker.killSplit);
|
|
134
|
-
pushEmitter.on(constants_1.SPLIT_UPDATE, splitsUpdateWorker.put);
|
|
135
|
-
// [Only for client-side]
|
|
136
|
-
pushEmitter.on(constants_1.MY_SEGMENTS_UPDATE, function handleMySegmentsUpdate(parsedData, channel) {
|
|
137
|
-
var userKeyHash = channel.split('_')[2];
|
|
138
|
-
var userKey = userKeyHashes[userKeyHash];
|
|
139
|
-
if (userKey && workers[userKey]) { // check context since it can be undefined if client has been destroyed
|
|
140
|
-
var mySegmentsUpdateWorker_1 = workers[userKey];
|
|
141
|
-
mySegmentsUpdateWorker_1.put(parsedData.changeNumber, parsedData.includesPayload ? parsedData.segmentList ? parsedData.segmentList : [] : undefined);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
return object_assign_1.default(
|
|
145
|
-
// Expose Event Emitter functionality and Event constants
|
|
146
|
-
Object.create(pushEmitter), {
|
|
147
|
-
// Expose functionality for starting and stoping push mode:
|
|
148
|
-
stop: disconnectPush,
|
|
149
|
-
start: function () {
|
|
150
|
-
// Run in next event-loop cycle for optimization: if multiple clients are created in the same cycle than the factory, only one authentication is performed.
|
|
151
|
-
setTimeout(connectPush);
|
|
152
|
-
},
|
|
153
|
-
// [Only for client-side]
|
|
154
|
-
add: function (userKey, mySegmentsSyncTask) {
|
|
155
|
-
var mySegmentsUpdateWorker = new MySegmentsUpdateWorker_1.default(mySegmentsSyncTask);
|
|
156
|
-
workers[userKey] = mySegmentsUpdateWorker;
|
|
157
|
-
var hash = AuthClient_1.hashUserKey(userKey);
|
|
158
|
-
if (!userKeyHashes[hash]) {
|
|
159
|
-
userKeyHashes[hash] = userKey;
|
|
160
|
-
connectForNewClient = true; // we must reconnect on start, to listen the channel for the new user key
|
|
161
|
-
}
|
|
162
|
-
// Reconnects in case of a new client.
|
|
163
|
-
// Run in next event-loop cycle to save authentication calls
|
|
164
|
-
// in case the user is creating several clients in the current cycle.
|
|
165
|
-
setTimeout(function checkForReconnect() {
|
|
166
|
-
if (connectForNewClient) {
|
|
167
|
-
connectForNewClient = false;
|
|
168
|
-
connectPush();
|
|
169
|
-
}
|
|
170
|
-
}, 0);
|
|
171
|
-
},
|
|
172
|
-
// [Only for client-side]
|
|
173
|
-
remove: function (userKey) {
|
|
174
|
-
var hash = AuthClient_1.hashUserKey(userKey);
|
|
175
|
-
delete userKeyHashes[hash];
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
exports.default = pushManagerCSFactory;
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var tslib_1 = require("tslib");
|
|
4
|
-
var object_assign_1 = tslib_1.__importDefault(require("object-assign"));
|
|
5
|
-
var constants_1 = require("./constants");
|
|
6
|
-
var Backoff_1 = tslib_1.__importDefault(require("../../utils/Backoff"));
|
|
7
|
-
var SSEHandler_1 = tslib_1.__importDefault(require("./SSEHandler"));
|
|
8
|
-
var SegmentsUpdateWorker_1 = tslib_1.__importDefault(require("./UpdateWorkers/SegmentsUpdateWorker"));
|
|
9
|
-
var SplitsUpdateWorker_1 = tslib_1.__importDefault(require("./UpdateWorkers/SplitsUpdateWorker"));
|
|
10
|
-
var AuthClient_1 = require("./AuthClient");
|
|
11
|
-
var SSEClient_1 = tslib_1.__importDefault(require("./SSEClient"));
|
|
12
|
-
var constants_2 = require("../../logger/constants");
|
|
13
|
-
/**
|
|
14
|
-
* PushManager factory for server-side
|
|
15
|
-
*/
|
|
16
|
-
function pushManagerSSFactory(pollingManager, storage, readiness, fetchAuth, platform, settings) {
|
|
17
|
-
var log = settings.log;
|
|
18
|
-
var sseClient;
|
|
19
|
-
try {
|
|
20
|
-
sseClient = new SSEClient_1.default(settings, true, platform.getEventSource);
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
log.warn(constants_2.STREAMING_FALLBACK, [e]);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
var authenticate = AuthClient_1.authenticateFactory(fetchAuth);
|
|
27
|
-
// init feedback loop (pushEmitter)
|
|
28
|
-
var pushEmitter = new platform.EventEmitter();
|
|
29
|
-
var sseHandler = SSEHandler_1.default(log, pushEmitter);
|
|
30
|
-
sseClient.setEventHandler(sseHandler);
|
|
31
|
-
// init workers
|
|
32
|
-
var splitsUpdateWorker = new SplitsUpdateWorker_1.default(storage.splits, pollingManager.splitsSyncTask, readiness.splits, pollingManager.segmentsSyncTask);
|
|
33
|
-
var segmentsUpdateWorker = new SegmentsUpdateWorker_1.default(storage.segments, pollingManager.segmentsSyncTask);
|
|
34
|
-
// flag that indicates if `disconnectPush` was called, either by the SyncManager (when the client is destroyed) or by a PUSH_NONRETRYABLE_ERROR error.
|
|
35
|
-
// It is used to halt the `connectPush` process if it was in progress.
|
|
36
|
-
var disconnected;
|
|
37
|
-
/** PushManager functions related to initialization */
|
|
38
|
-
var connectPushRetryBackoff = new Backoff_1.default(connectPush, settings.scheduler.pushRetryBackoffBase);
|
|
39
|
-
var timeoutId;
|
|
40
|
-
function scheduleTokenRefresh(issuedAt, expirationTime) {
|
|
41
|
-
// clear scheduled token refresh if exists (needed when resuming PUSH)
|
|
42
|
-
if (timeoutId)
|
|
43
|
-
clearTimeout(timeoutId);
|
|
44
|
-
// Set token refresh 10 minutes before expirationTime
|
|
45
|
-
var delayInSeconds = expirationTime - issuedAt - constants_1.SECONDS_BEFORE_EXPIRATION;
|
|
46
|
-
log.info(constants_2.STREAMING_REFRESH_TOKEN, [delayInSeconds]);
|
|
47
|
-
timeoutId = setTimeout(connectPush, delayInSeconds * 1000);
|
|
48
|
-
}
|
|
49
|
-
function connectPush() {
|
|
50
|
-
disconnected = false;
|
|
51
|
-
log.info(constants_2.STREAMING_CONNECTING);
|
|
52
|
-
authenticate().then(function (authData) {
|
|
53
|
-
if (disconnected)
|
|
54
|
-
return;
|
|
55
|
-
// 'pushEnabled: false' is handled as a PUSH_NONRETRYABLE_ERROR instead of PUSH_SUBSYSTEM_DOWN, in order to
|
|
56
|
-
// close the sseClient in case the org has been bloqued while the instance was connected to streaming
|
|
57
|
-
if (!authData.pushEnabled) {
|
|
58
|
-
log.info(constants_2.STREAMING_DISABLED);
|
|
59
|
-
pushEmitter.emit(constants_1.PUSH_NONRETRYABLE_ERROR);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
// Connect to SSE and schedule refresh token
|
|
63
|
-
var decodedToken = authData.decodedToken;
|
|
64
|
-
sseClient.open(authData);
|
|
65
|
-
scheduleTokenRefresh(decodedToken.iat, decodedToken.exp);
|
|
66
|
-
}).catch(function (error) {
|
|
67
|
-
if (disconnected)
|
|
68
|
-
return;
|
|
69
|
-
log.error(constants_2.ERROR_STREAMING_AUTH, [error.message]);
|
|
70
|
-
// Handle 4XX HTTP errors: 401 (invalid API Key) or 400 (using incorrect API Key, i.e., client-side API Key on server-side)
|
|
71
|
-
if (error.statusCode >= 400 && error.statusCode < 500) {
|
|
72
|
-
pushEmitter.emit(constants_1.PUSH_NONRETRYABLE_ERROR);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
// Handle other HTTP and network errors as recoverable errors
|
|
76
|
-
pushEmitter.emit(constants_1.PUSH_RETRYABLE_ERROR);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
// close SSE connection and cancel scheduled tasks
|
|
80
|
-
function disconnectPush() {
|
|
81
|
-
sseClient.close();
|
|
82
|
-
disconnected = true;
|
|
83
|
-
log.info(constants_2.STREAMING_DISCONNECTING);
|
|
84
|
-
if (timeoutId)
|
|
85
|
-
clearTimeout(timeoutId);
|
|
86
|
-
connectPushRetryBackoff.reset();
|
|
87
|
-
stopWorkers();
|
|
88
|
-
}
|
|
89
|
-
// cancel scheduled fetch retries of Splits, Segments, and MySegments Update Workers
|
|
90
|
-
function stopWorkers() {
|
|
91
|
-
splitsUpdateWorker.backoff.reset();
|
|
92
|
-
segmentsUpdateWorker.backoff.reset();
|
|
93
|
-
}
|
|
94
|
-
pushEmitter.on(constants_1.PUSH_SUBSYSTEM_DOWN, stopWorkers);
|
|
95
|
-
// restart backoff retry counter once push is connected
|
|
96
|
-
pushEmitter.on(constants_1.PUSH_SUBSYSTEM_UP, function () { connectPushRetryBackoff.reset(); });
|
|
97
|
-
/** Fallbacking without retry due to: STREAMING_DISABLED control event, or 'pushEnabled: false', or non-recoverable SSE and Authentication errors */
|
|
98
|
-
pushEmitter.on(constants_1.PUSH_NONRETRYABLE_ERROR, function handleNonRetryableError() {
|
|
99
|
-
// Note: `stopWorkers` is been called twice, but it is not harmful
|
|
100
|
-
disconnectPush();
|
|
101
|
-
pushEmitter.emit(constants_1.PUSH_SUBSYSTEM_DOWN); // no harm if polling already
|
|
102
|
-
});
|
|
103
|
-
/** Fallbacking with retry due to recoverable SSE and Authentication errors */
|
|
104
|
-
pushEmitter.on(constants_1.PUSH_RETRYABLE_ERROR, function handleRetryableError() {
|
|
105
|
-
// SSE connection is closed to avoid repeated errors due to retries
|
|
106
|
-
sseClient.close();
|
|
107
|
-
// retry streaming reconnect with backoff algorithm
|
|
108
|
-
var delayInMillis = connectPushRetryBackoff.scheduleCall();
|
|
109
|
-
log.info(constants_2.STREAMING_RECONNECT, [delayInMillis / 1000]);
|
|
110
|
-
pushEmitter.emit(constants_1.PUSH_SUBSYSTEM_DOWN); // no harm if polling already
|
|
111
|
-
});
|
|
112
|
-
/** Functions related to synchronization (Queues and Workers in the spec) */
|
|
113
|
-
pushEmitter.on(constants_1.SPLIT_KILL, splitsUpdateWorker.killSplit);
|
|
114
|
-
pushEmitter.on(constants_1.SPLIT_UPDATE, splitsUpdateWorker.put);
|
|
115
|
-
// [Only for server-side]
|
|
116
|
-
pushEmitter.on(constants_1.SEGMENT_UPDATE, segmentsUpdateWorker.put);
|
|
117
|
-
return object_assign_1.default(
|
|
118
|
-
// Expose Event Emitter functionality and Event constants
|
|
119
|
-
Object.create(pushEmitter), {
|
|
120
|
-
// Expose functionality for starting and stoping push mode:
|
|
121
|
-
stop: disconnectPush,
|
|
122
|
-
start: function () {
|
|
123
|
-
// Run in next event-loop cycle as in browser
|
|
124
|
-
setTimeout(connectPush);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
exports.default = pushManagerSSFactory;
|