@splitsoftware/splitio-commons 0.1.1-canary.6 → 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 +5 -2
- package/cjs/listeners/node.js +9 -2
- 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 -1
- package/cjs/services/splitApi.js +9 -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/fetchers/segmentChangesFetcher.js +0 -8
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +30 -10
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +2 -4
- package/cjs/sync/streaming/SSEClient/index.js +38 -20
- 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 +148 -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 +18 -5
- package/cjs/sync/syncTask.js +1 -1
- 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 +5 -2
- package/esm/listeners/node.js +9 -2
- 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 -1
- package/esm/services/splitApi.js +9 -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/fetchers/segmentChangesFetcher.js +0 -8
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +30 -10
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +2 -4
- package/esm/sync/streaming/SSEClient/index.js +38 -20
- 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 +150 -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 +18 -5
- package/esm/sync/syncTask.js +1 -1
- 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 +5 -2
- package/src/listeners/node.ts +14 -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 -1
- package/src/sdkFactory/types.ts +4 -5
- package/src/services/splitApi.ts +12 -3
- package/src/services/splitHttpClient.ts +6 -5
- package/src/services/types.ts +7 -3
- 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/SegmentsCachePluggable.ts +1 -1
- 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/fetchers/segmentChangesFetcher.ts +0 -7
- package/src/sync/polling/types.ts +2 -1
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +28 -10
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +2 -3
- package/src/sync/streaming/AuthClient/types.ts +3 -0
- package/src/sync/streaming/SSEClient/index.ts +43 -23
- 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 +145 -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 +19 -5
- package/src/sync/syncTask.ts +1 -1
- package/src/sync/types.ts +3 -1
- 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/lang/index.ts +1 -1
- 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 +3 -3
- package/types/listeners/node.d.ts +3 -2
- package/types/logger/constants.d.ts +2 -0
- package/types/sdkFactory/types.d.ts +4 -5
- package/types/services/types.d.ts +4 -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 +9 -12
- 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/sync/syncTask.d.ts +1 -1
- package/types/sync/types.d.ts +2 -0
- 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/lang/index.d.ts +1 -1
- 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 -178
- package/cjs/sync/streaming/pushManagerSS.js +0 -128
- package/esm/sync/streaming/pushManagerCS.js +0 -174
- package/esm/sync/streaming/pushManagerSS.js +0 -124
- package/src/sync/streaming/pushManagerCS.ts +0 -237
- package/src/sync/streaming/pushManagerSS.ts +0 -177
|
@@ -3,7 +3,8 @@ import mode from './mode';
|
|
|
3
3
|
import { validateSplitFilters } from './splitFilters';
|
|
4
4
|
import { STANDALONE_MODE, OPTIMIZED, LOCALHOST_MODE } from '../constants';
|
|
5
5
|
import validImpressionsMode from './impressionsMode';
|
|
6
|
-
import {
|
|
6
|
+
import { ISettingsValidationParams } from './types';
|
|
7
|
+
import { ISettings } from '../../types';
|
|
7
8
|
|
|
8
9
|
const base = {
|
|
9
10
|
// Define which kind of object you want to retrieve from SplitFactory
|
|
@@ -73,7 +74,8 @@ const base = {
|
|
|
73
74
|
sync: {
|
|
74
75
|
splitFilters: undefined,
|
|
75
76
|
// impressions collection mode
|
|
76
|
-
impressionsMode: OPTIMIZED
|
|
77
|
+
impressionsMode: OPTIMIZED,
|
|
78
|
+
localhostMode: undefined
|
|
77
79
|
},
|
|
78
80
|
|
|
79
81
|
runtime: {
|
|
@@ -98,10 +100,10 @@ function fromSecondsToMillis(n: number) {
|
|
|
98
100
|
*/
|
|
99
101
|
export function settingsValidation(config: unknown, validationParams: ISettingsValidationParams) {
|
|
100
102
|
|
|
101
|
-
const { defaults, runtime, storage, integrations, logger } = validationParams;
|
|
103
|
+
const { defaults, runtime, storage, integrations, logger, localhost } = validationParams;
|
|
102
104
|
|
|
103
105
|
// creates a settings object merging base, defaults and config objects.
|
|
104
|
-
const withDefaults = merge({}, base, defaults, config) as
|
|
106
|
+
const withDefaults = merge({}, base, defaults, config) as ISettings;
|
|
105
107
|
|
|
106
108
|
// ensure a valid logger.
|
|
107
109
|
// First thing to validate, since other validators might use the logger.
|
|
@@ -143,6 +145,8 @@ export function settingsValidation(config: unknown, validationParams: ISettingsV
|
|
|
143
145
|
// @ts-ignore, modify readonly prop
|
|
144
146
|
if (integrations) withDefaults.integrations = integrations(withDefaults);
|
|
145
147
|
|
|
148
|
+
if (localhost) withDefaults.sync.localhostMode = localhost(withDefaults);
|
|
149
|
+
|
|
146
150
|
// validate push options
|
|
147
151
|
if (withDefaults.streamingEnabled !== false) { // @ts-ignore, modify readonly prop
|
|
148
152
|
withDefaults.streamingEnabled = true;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ERROR_LOCALHOST_MODULE_REQUIRED } from '../../../logger/constants';
|
|
2
|
+
import { ISettings, } from '../../../types';
|
|
3
|
+
import { LOCALHOST_MODE } from '../../constants';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This function validates `settings.storage` object
|
|
7
|
+
*
|
|
8
|
+
* @param {any} settings config object provided by the user to initialize the sdk
|
|
9
|
+
*
|
|
10
|
+
* @returns {Object} valid storage factory. It might be the default `InMemoryStorageCSFactory` if the provided storage is invalid.
|
|
11
|
+
*/
|
|
12
|
+
export function validateLocalhost(settings: ISettings) {
|
|
13
|
+
const localhostMode = settings.sync.localhostMode;
|
|
14
|
+
|
|
15
|
+
if (settings.mode === LOCALHOST_MODE && (typeof localhostMode !== 'function' || localhostMode.type !== LOCALHOST_MODE)) {
|
|
16
|
+
settings.log.error(ERROR_LOCALHOST_MODULE_REQUIRED);
|
|
17
|
+
}
|
|
18
|
+
return localhostMode;
|
|
19
|
+
}
|
|
@@ -107,7 +107,6 @@ export function validateSplitFilters(log: ILogger, maybeSplitFilters: any, mode:
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
// Validate filters and group their values by filter type inside `groupedFilters` object
|
|
110
|
-
// Assign the valid filters to the output of the validator by using filter function
|
|
111
110
|
res.validFilters = maybeSplitFilters.filter((filter, index) => {
|
|
112
111
|
if (filter && validateFilterType(filter.type) && Array.isArray(filter.values)) {
|
|
113
112
|
res.groupedFilters[filter.type as SplitIO.SplitFilterType] = res.groupedFilters[filter.type as SplitIO.SplitFilterType].concat(filter.values);
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { InMemoryStorageCSFactory } from '../../../storages/inMemory/InMemoryStorageCS';
|
|
2
|
-
import { ISettings } from '../../../types';
|
|
2
|
+
import { ISettings, SDKMode } from '../../../types';
|
|
3
3
|
import { ILogger } from '../../../logger/types';
|
|
4
4
|
import { WARN_STORAGE_INVALID } from '../../../logger/constants';
|
|
5
|
+
import { LOCALHOST_MODE, STORAGE_LOCALSTORAGE, STORAGE_MEMORY } from '../../../utils/constants';
|
|
6
|
+
import { IStorageFactoryParams, IStorageSyncCS } from '../../../storages/types';
|
|
7
|
+
|
|
8
|
+
export function __InLocalStorageMockFactory(params: IStorageFactoryParams): IStorageSyncCS {
|
|
9
|
+
const result = InMemoryStorageCSFactory(params);
|
|
10
|
+
result.splits.checkCache = () => true; // to emit SDK_READY_FROM_CACHE
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
__InLocalStorageMockFactory.type = STORAGE_MEMORY;
|
|
5
14
|
|
|
6
15
|
/**
|
|
7
16
|
* This function validates `settings.storage` object
|
|
@@ -10,16 +19,20 @@ import { WARN_STORAGE_INVALID } from '../../../logger/constants';
|
|
|
10
19
|
*
|
|
11
20
|
* @returns {Object} valid storage factory. It might be the default `InMemoryStorageCSFactory` if the provided storage is invalid.
|
|
12
21
|
*/
|
|
13
|
-
export function validateStorageCS(settings: { log: ILogger, storage?: any }): ISettings['storage'] {
|
|
14
|
-
|
|
22
|
+
export function validateStorageCS(settings: { log: ILogger, storage?: any, mode?: SDKMode }): ISettings['storage'] {
|
|
23
|
+
let { storage = InMemoryStorageCSFactory, log, mode } = settings;
|
|
15
24
|
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (typeof storage === 'function') return storage;
|
|
25
|
+
// If an invalid storage is provided, fallback into MEMORY
|
|
26
|
+
if (typeof storage !== 'function' || storage.type !== STORAGE_MEMORY && storage.type !== STORAGE_LOCALSTORAGE) {
|
|
27
|
+
storage = InMemoryStorageCSFactory;
|
|
20
28
|
log.warn(WARN_STORAGE_INVALID);
|
|
21
29
|
}
|
|
22
30
|
|
|
31
|
+
// In localhost mode with InLocalStorage, fallback to a mock InLocalStorage to emit SDK_READY_FROM_CACHE
|
|
32
|
+
if (mode === LOCALHOST_MODE && storage.type === STORAGE_LOCALSTORAGE) {
|
|
33
|
+
return __InLocalStorageMockFactory;
|
|
34
|
+
}
|
|
35
|
+
|
|
23
36
|
// return default InMemory storage if provided one is not valid
|
|
24
|
-
return
|
|
37
|
+
return storage;
|
|
25
38
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ISplitFiltersValidation } from '../../dtos/types';
|
|
2
1
|
import { ISettings } from '../../types';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -19,14 +18,6 @@ export interface ISettingsValidationParams {
|
|
|
19
18
|
integrations?: (settings: ISettings) => ISettings['integrations'],
|
|
20
19
|
/** Logger validator */
|
|
21
20
|
logger: (settings: ISettings) => ISettings['log'],
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Settings interface extended with private properties used for internal purposes.
|
|
26
|
-
*/
|
|
27
|
-
export interface ISettingsInternal extends ISettings {
|
|
28
|
-
readonly sync: ISettings['sync'] & {
|
|
29
|
-
__splitFiltersValidation: ISplitFiltersValidation
|
|
30
|
-
}
|
|
31
|
-
readonly impressionListener?: unknown
|
|
21
|
+
/** Localhost mode validator */
|
|
22
|
+
localhost?: (settings: ISettings) => ISettings['sync']['localhostMode'],
|
|
32
23
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ISettings } from '../../types';
|
|
2
2
|
|
|
3
3
|
const eventsEndpointMatcher = /^\/(testImpressions|metrics|events)/;
|
|
4
|
-
const authEndpointMatcher = /^\/auth/;
|
|
4
|
+
const authEndpointMatcher = /^\/v2\/auth/;
|
|
5
5
|
const streamingEndpointMatcher = /^\/(sse|event-stream)/;
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const matcherTypes: Record<string, number>;
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const matcherDataTypes: {
|
|
3
3
|
BOOLEAN: string;
|
|
4
4
|
STRING: string;
|
|
5
5
|
NUMBER: string;
|
|
@@ -7,4 +7,4 @@ export declare const dataTypes: {
|
|
|
7
7
|
DATETIME: string;
|
|
8
8
|
NOT_SPECIFIED: string;
|
|
9
9
|
};
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function matcherTypesMapper(matcherType: string): number;
|
|
@@ -2,17 +2,17 @@ import { ISignalListener } from './types';
|
|
|
2
2
|
import { IStorageSync } from '../storages/types';
|
|
3
3
|
import { ISplitApi } from '../services/types';
|
|
4
4
|
import { ISettings } from '../types';
|
|
5
|
-
import {
|
|
5
|
+
import { ISyncManager } from '../sync/types';
|
|
6
6
|
/**
|
|
7
7
|
* We'll listen for 'unload' event over the window object, since it's the standard way to listen page reload and close.
|
|
8
8
|
*/
|
|
9
9
|
export default class BrowserSignalListener implements ISignalListener {
|
|
10
|
+
private syncManager;
|
|
10
11
|
private settings;
|
|
11
12
|
private storage;
|
|
12
13
|
private serviceApi;
|
|
13
14
|
private fromImpressionsCollector;
|
|
14
|
-
constructor(
|
|
15
|
-
settings: ISettings, storage: IStorageSync, serviceApi: ISplitApi);
|
|
15
|
+
constructor(syncManager: ISyncManager | undefined, settings: ISettings, storage: IStorageSync, serviceApi: ISplitApi);
|
|
16
16
|
/**
|
|
17
17
|
* start method.
|
|
18
18
|
* Called when SplitFactory is initialized.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ISignalListener } from './types';
|
|
2
|
-
import { MaybeThenable } from '../dtos/types';
|
|
3
2
|
import { ISettings } from '../types';
|
|
3
|
+
import { ISyncManager } from '../sync/types';
|
|
4
4
|
/**
|
|
5
5
|
* We'll listen for SIGTERM since it's the standard signal for server shutdown.
|
|
6
6
|
*
|
|
@@ -11,7 +11,8 @@ import { ISettings } from '../types';
|
|
|
11
11
|
export default class NodeSignalListener implements ISignalListener {
|
|
12
12
|
private handler;
|
|
13
13
|
private settings;
|
|
14
|
-
constructor(handler: () => MaybeThenable<void>,
|
|
14
|
+
constructor(syncManager: ISyncManager | undefined, // private handler: () => MaybeThenable<void>,
|
|
15
|
+
settings: ISettings);
|
|
15
16
|
start(): void;
|
|
16
17
|
stop(): void;
|
|
17
18
|
/**
|
|
@@ -91,6 +91,7 @@ export declare const WARN_SPLITS_FILTER_INVALID = 220;
|
|
|
91
91
|
export declare const WARN_SPLITS_FILTER_EMPTY = 221;
|
|
92
92
|
export declare const WARN_STORAGE_INVALID = 222;
|
|
93
93
|
export declare const WARN_API_KEY = 223;
|
|
94
|
+
export declare const STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 224;
|
|
94
95
|
export declare const ERROR_ENGINE_COMBINER_IFELSEIF = 300;
|
|
95
96
|
export declare const ERROR_LOGLEVEL_INVALID = 301;
|
|
96
97
|
export declare const ERROR_CLIENT_LISTENER = 302;
|
|
@@ -114,6 +115,7 @@ export declare const ERROR_EMPTY = 319;
|
|
|
114
115
|
export declare const ERROR_EMPTY_ARRAY = 320;
|
|
115
116
|
export declare const ERROR_INVALID_IMPRESSIONS_MODE = 321;
|
|
116
117
|
export declare const ERROR_HTTP = 322;
|
|
118
|
+
export declare const ERROR_LOCALHOST_MODULE_REQUIRED = 323;
|
|
117
119
|
export declare const LOG_PREFIX_SETTINGS = "settings";
|
|
118
120
|
export declare const LOG_PREFIX_INSTANTIATION = "Factory instantiation";
|
|
119
121
|
export declare const LOG_PREFIX_ENGINE = "engine";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { MaybeThenable } from '../dtos/types';
|
|
2
1
|
import { IIntegrationManager, IIntegrationFactoryParams } from '../integrations/types';
|
|
3
2
|
import { ISignalListener } from '../listeners/types';
|
|
4
3
|
import { ILogger } from '../logger/types';
|
|
@@ -9,9 +8,9 @@ import { IStorageAsync, IStorageSync, ISplitsCacheSync, ISplitsCacheAsync, IStor
|
|
|
9
8
|
import { ISyncManager, ISyncManagerFactoryParams } from '../sync/types';
|
|
10
9
|
import { IImpressionObserver } from '../trackers/impressionObserver/types';
|
|
11
10
|
import { SplitIO, ISettings, IEventEmitter } from '../types';
|
|
12
|
-
import { ISettingsInternal } from '../utils/settingsValidation/types';
|
|
13
11
|
/**
|
|
14
|
-
* Environment related dependencies
|
|
12
|
+
* Environment related dependencies.
|
|
13
|
+
* These getters are called a fixed number of times per factory instantiation.
|
|
15
14
|
*/
|
|
16
15
|
export interface IPlatform {
|
|
17
16
|
getOptions?: () => object;
|
|
@@ -23,7 +22,7 @@ export interface IPlatform {
|
|
|
23
22
|
* Object parameter with the modules required to create an SDK factory instance
|
|
24
23
|
*/
|
|
25
24
|
export interface ISdkFactoryParams {
|
|
26
|
-
settings:
|
|
25
|
+
settings: ISettings;
|
|
27
26
|
platform: IPlatform;
|
|
28
27
|
storageFactory: (params: IStorageFactoryParams) => IStorageSync | IStorageAsync;
|
|
29
28
|
splitApiFactory?: (settings: ISettings, platform: IPlatform) => ISplitApi;
|
|
@@ -33,7 +32,7 @@ export interface ISdkFactoryParams {
|
|
|
33
32
|
(): SplitIO.ICsClient;
|
|
34
33
|
(key: SplitIO.SplitKey, trafficType?: string | undefined): SplitIO.ICsClient;
|
|
35
34
|
} | (() => SplitIO.IClient) | (() => SplitIO.IAsyncClient));
|
|
36
|
-
SignalListener?: new (
|
|
35
|
+
SignalListener?: new (syncManager: ISyncManager | undefined, // Used by NodeSignalListener to flush data, and by BrowserSignalListener to close streaming connection.
|
|
37
36
|
settings: ISettings, // Used by BrowserSignalListener
|
|
38
37
|
storage: IStorageSync | IStorageAsync, // Used by BrowserSignalListener
|
|
39
38
|
serviceApi: ISplitApi | undefined) => ISignalListener;
|
|
@@ -7,8 +7,10 @@ export declare type IResponse = {
|
|
|
7
7
|
ok: boolean;
|
|
8
8
|
status: number;
|
|
9
9
|
json: () => Promise<any>;
|
|
10
|
+
text: () => Promise<string>;
|
|
10
11
|
};
|
|
11
12
|
export declare type IFetch = (url: string, options?: IRequestOptions) => Promise<IResponse>;
|
|
13
|
+
export declare type IHealthCheckAPI = () => Promise<boolean>;
|
|
12
14
|
export declare type ISplitHttpClient = (url: string, options?: IRequestOptions, logErrorsAsInfo?: boolean) => Promise<IResponse>;
|
|
13
15
|
export declare type IFetchAuth = (userKeys?: string[]) => Promise<IResponse>;
|
|
14
16
|
export declare type IFetchSplitChanges = (since: number, noCache?: boolean) => Promise<IResponse>;
|
|
@@ -20,6 +22,8 @@ export declare type IPostTestImpressionsCount = (body: string, headers?: Record<
|
|
|
20
22
|
export declare type IPostMetricsCounters = (body: string) => Promise<IResponse>;
|
|
21
23
|
export declare type IPostMetricsTimes = (body: string) => Promise<IResponse>;
|
|
22
24
|
export interface ISplitApi {
|
|
25
|
+
getSdkAPIHealthCheck: IHealthCheckAPI;
|
|
26
|
+
getEventsAPIHealthCheck: IHealthCheckAPI;
|
|
23
27
|
fetchAuth: IFetchAuth;
|
|
24
28
|
fetchSplitChanges: IFetchSplitChanges;
|
|
25
29
|
fetchSegmentChanges: IFetchSegmentChanges;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IStorageSyncFactory } from '../types';
|
|
2
2
|
export interface InLocalStorageOptions {
|
|
3
3
|
prefix?: string;
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
6
6
|
* InLocal storage factory for standalone client-side SplitFactory
|
|
7
7
|
*/
|
|
8
|
-
export declare function InLocalStorage(options?: InLocalStorageOptions):
|
|
8
|
+
export declare function InLocalStorage(options?: InLocalStorageOptions): IStorageSyncFactory;
|
|
@@ -5,3 +5,6 @@ import { IStorageFactoryParams, IStorageSync } from '../types';
|
|
|
5
5
|
* @param params parameters required by EventsCacheSync
|
|
6
6
|
*/
|
|
7
7
|
export declare function InMemoryStorageFactory(params: IStorageFactoryParams): IStorageSync;
|
|
8
|
+
export declare namespace InMemoryStorageFactory {
|
|
9
|
+
var type: import("../types").StorageType;
|
|
10
|
+
}
|
|
@@ -5,3 +5,6 @@ import { IStorageSyncCS, IStorageFactoryParams } from '../types';
|
|
|
5
5
|
* @param params parameters required by EventsCacheSync
|
|
6
6
|
*/
|
|
7
7
|
export declare function InMemoryStorageCSFactory(params: IStorageFactoryParams): IStorageSyncCS;
|
|
8
|
+
export declare namespace InMemoryStorageCSFactory {
|
|
9
|
+
var type: import("../types").StorageType;
|
|
10
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IStorageAsyncFactory } from '../types';
|
|
2
2
|
export interface InRedisStorageOptions {
|
|
3
3
|
prefix?: string;
|
|
4
4
|
options?: Record<string, any>;
|
|
@@ -7,4 +7,4 @@ export interface InRedisStorageOptions {
|
|
|
7
7
|
* InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.
|
|
8
8
|
* @see {@link https://www.npmjs.com/package/ioredis}
|
|
9
9
|
*/
|
|
10
|
-
export declare function InRedisStorage(options?: InRedisStorageOptions):
|
|
10
|
+
export declare function InRedisStorage(options?: InRedisStorageOptions): IStorageAsyncFactory;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ICustomStorageWrapper,
|
|
1
|
+
import { ICustomStorageWrapper, IStorageAsyncFactory } from '../types';
|
|
2
2
|
export interface PluggableStorageOptions {
|
|
3
3
|
prefix?: string;
|
|
4
4
|
wrapper: ICustomStorageWrapper;
|
|
@@ -6,4 +6,4 @@ export interface PluggableStorageOptions {
|
|
|
6
6
|
/**
|
|
7
7
|
* Pluggable storage factory for consumer server-side & client-side SplitFactory.
|
|
8
8
|
*/
|
|
9
|
-
export declare function PluggableStorage(options: PluggableStorageOptions):
|
|
9
|
+
export declare function PluggableStorage(options: PluggableStorageOptions): IStorageAsyncFactory;
|
|
@@ -54,15 +54,6 @@ export interface ICustomStorageWrapper {
|
|
|
54
54
|
* The promise rejects if the operation fails.
|
|
55
55
|
*/
|
|
56
56
|
getKeysByPrefix: (prefix: string) => Promise<string[]>;
|
|
57
|
-
/**
|
|
58
|
-
* Returns all values which keys match the given prefix.
|
|
59
|
-
*
|
|
60
|
-
* @function getByPrefix
|
|
61
|
-
* @param {string} prefix String prefix to match
|
|
62
|
-
* @returns {Promise<string[]>} A promise that resolves with the list of values which keys match the given `prefix`.
|
|
63
|
-
* The promise rejects if the operation fails.
|
|
64
|
-
*/
|
|
65
|
-
getByPrefix: (prefix: string) => Promise<string[]>;
|
|
66
57
|
/**
|
|
67
58
|
* Returns the values of all given `keys`.
|
|
68
59
|
*
|
|
@@ -78,19 +69,19 @@ export interface ICustomStorageWrapper {
|
|
|
78
69
|
*
|
|
79
70
|
* @function incr
|
|
80
71
|
* @param {string} key Key to increment
|
|
81
|
-
* @returns {Promise<
|
|
72
|
+
* @returns {Promise<number>} A promise that resolves with the value of key after the increment. The promise rejects if the operation fails,
|
|
82
73
|
* for example, if there is a connection error or the key contains a string that can not be represented as integer.
|
|
83
74
|
*/
|
|
84
|
-
incr: (key: string) => Promise<
|
|
75
|
+
incr: (key: string) => Promise<number>;
|
|
85
76
|
/**
|
|
86
77
|
* Decrements in 1 the given `key` value or set it in -1 if the value doesn't exist.
|
|
87
78
|
*
|
|
88
79
|
* @function decr
|
|
89
80
|
* @param {string} key Key to decrement
|
|
90
|
-
* @returns {Promise<
|
|
81
|
+
* @returns {Promise<number>} A promise that resolves with the value of key after the decrement. The promise rejects if the operation fails,
|
|
91
82
|
* for example, if there is a connection error or the key contains a string that can not be represented as integer.
|
|
92
83
|
*/
|
|
93
|
-
decr: (key: string) => Promise<
|
|
84
|
+
decr: (key: string) => Promise<number>;
|
|
94
85
|
/** Queue operations */
|
|
95
86
|
/**
|
|
96
87
|
* Inserts given items at the tail of `key` list. If `key` does not exist, an empty list is created before pushing the items.
|
|
@@ -243,8 +234,8 @@ export interface ISegmentsCacheBase {
|
|
|
243
234
|
clear(): MaybeThenable<boolean | void>;
|
|
244
235
|
}
|
|
245
236
|
export interface ISegmentsCacheSync extends ISegmentsCacheBase {
|
|
246
|
-
addToSegment(name: string, segmentKeys
|
|
247
|
-
removeFromSegment(name: string, segmentKeys
|
|
237
|
+
addToSegment(name: string, segmentKeys?: string[]): boolean;
|
|
238
|
+
removeFromSegment(name: string, segmentKeys?: string[]): boolean;
|
|
248
239
|
isInSegment(name: string, key?: string): boolean;
|
|
249
240
|
registerSegments(names: string[]): boolean;
|
|
250
241
|
getRegisteredSegments(): string[];
|
|
@@ -353,3 +344,12 @@ export interface IStorageFactoryParams {
|
|
|
353
344
|
onReadyCb?: (error?: any) => void;
|
|
354
345
|
metadata: IMetadata;
|
|
355
346
|
}
|
|
347
|
+
export declare type StorageType = 'MEMORY' | 'LOCALSTORAGE' | 'REDIS' | 'CUSTOM';
|
|
348
|
+
export declare type IStorageSyncFactory = {
|
|
349
|
+
type: StorageType;
|
|
350
|
+
(params: IStorageFactoryParams): IStorageSync;
|
|
351
|
+
};
|
|
352
|
+
export declare type IStorageAsyncFactory = {
|
|
353
|
+
type: StorageType;
|
|
354
|
+
(params: IStorageFactoryParams): IStorageAsync;
|
|
355
|
+
};
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { ILogger } from '../../../logger/types';
|
|
4
|
-
export default function splitsParserFromFile({ features, log }: {
|
|
5
|
-
features?: SplitIO.MockedFeaturesFilePath;
|
|
6
|
-
log: ILogger;
|
|
7
|
-
}): false | Record<string, ISplitPartial>;
|
|
1
|
+
import { ISplitsParser } from './types';
|
|
2
|
+
export declare function splitsParserFromFileFactory(): ISplitsParser;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
import { ISplitPartial } from '../../../dtos/types';
|
|
2
2
|
import { ISettings } from '../../../types';
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* @param features validated object with mocked features mapping.
|
|
6
|
-
*/
|
|
7
|
-
export default function splitsParserFromSettings(settings: ISettings): false | Record<string, ISplitPartial>;
|
|
3
|
+
export declare function splitsParserFromSettingsFactory(): (settings: ISettings) => false | Record<string, ISplitPartial>;
|
|
@@ -2,10 +2,11 @@ import { IReadinessManager } from '../../readiness/types';
|
|
|
2
2
|
import { ISplitApi } from '../../services/types';
|
|
3
3
|
import { IStorageSync } from '../../storages/types';
|
|
4
4
|
import { ISettings } from '../../types';
|
|
5
|
+
import { SegmentsData } from '../streaming/SSEHandler/types';
|
|
5
6
|
import { ITask, ISyncTask } from '../types';
|
|
6
7
|
export interface ISplitsSyncTask extends ISyncTask<[noCache?: boolean], boolean> {
|
|
7
8
|
}
|
|
8
|
-
export interface ISegmentsSyncTask extends ISyncTask<[segmentNames?:
|
|
9
|
+
export interface ISegmentsSyncTask extends ISyncTask<[segmentNames?: SegmentsData, noCache?: boolean, fetchOnlyNew?: boolean], boolean> {
|
|
9
10
|
}
|
|
10
11
|
export interface IPollingManager extends ITask {
|
|
11
12
|
syncAll(): Promise<any>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IFetchAuth } from '../../../services/types';
|
|
2
|
+
import { IAuthenticate } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Factory of authentication function.
|
|
5
|
+
*
|
|
6
|
+
* @param fetchAuth `SplitAPI.fetchAuth` endpoint
|
|
7
|
+
*/
|
|
8
|
+
export declare function authenticateFactory(fetchAuth: IFetchAuth): IAuthenticate;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the hash of a given user key
|
|
11
|
+
*/
|
|
12
|
+
export declare function hashUserKey(userKey: string): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IFetchAuthV2 } from '../../../services/types';
|
|
2
|
+
import { IAuthenticateV2 } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Factory of authentication function.
|
|
5
|
+
*
|
|
6
|
+
* @param fetchAuth `SplitAPI.fetchAuth` endpoint
|
|
7
|
+
*/
|
|
8
|
+
export declare function authenticateFactory(fetchAuthV2: IFetchAuthV2): IAuthenticateV2;
|
|
@@ -6,6 +6,7 @@ export interface IAuthTokenPushEnabled {
|
|
|
6
6
|
channels: {
|
|
7
7
|
[channel: string]: string[];
|
|
8
8
|
};
|
|
9
|
+
connDelay?: number;
|
|
9
10
|
}
|
|
10
11
|
export interface IAuthTokenPushDisabled {
|
|
11
12
|
pushEnabled: false;
|
|
@@ -13,3 +14,4 @@ export interface IAuthTokenPushDisabled {
|
|
|
13
14
|
}
|
|
14
15
|
export declare type IAuthToken = IAuthTokenPushDisabled | IAuthTokenPushEnabled;
|
|
15
16
|
export declare type IAuthenticate = (userKeys?: string[]) => Promise<IAuthToken>;
|
|
17
|
+
export declare type IAuthenticateV2 = (isClientSide?: boolean) => Promise<IAuthToken>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ISettings } from '../../../types';
|
|
1
2
|
import { IAuthTokenPushEnabled } from '../AuthClient/types';
|
|
2
3
|
import { ISSEClient, ISseEventHandler } from './types';
|
|
3
4
|
/**
|
|
@@ -8,29 +9,25 @@ export default class SSEClient implements ISSEClient {
|
|
|
8
9
|
streamingUrl: string;
|
|
9
10
|
connection?: InstanceType<typeof EventSource>;
|
|
10
11
|
handler?: ISseEventHandler;
|
|
11
|
-
|
|
12
|
+
useHeaders?: boolean;
|
|
13
|
+
headers: Record<string, string>;
|
|
12
14
|
/**
|
|
13
15
|
* SSEClient constructor.
|
|
14
16
|
*
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @
|
|
17
|
+
* @param settings Validated settings.
|
|
18
|
+
* @param useHeaders True to send metadata as headers or false to send as query params. If `true`, the provided EventSource must support headers.
|
|
19
|
+
* @param getEventSource Function to get the EventSource constructor.
|
|
20
|
+
* @throws 'EventSource API is not available. ' if EventSource is not available.
|
|
18
21
|
*/
|
|
19
|
-
constructor(
|
|
22
|
+
constructor(settings: ISettings, useHeaders?: boolean, getEventSource?: () => (typeof EventSource | undefined));
|
|
20
23
|
setEventHandler(handler: ISseEventHandler): void;
|
|
21
24
|
/**
|
|
22
25
|
* Open the connection with a given authToken
|
|
23
26
|
*
|
|
24
27
|
* @param {IAuthTokenPushEnabled} authToken
|
|
25
|
-
* @throws {TypeError} if `authToken` is undefined
|
|
28
|
+
* @throws {TypeError} Will throw an error if `authToken` is undefined
|
|
26
29
|
*/
|
|
27
30
|
open(authToken: IAuthTokenPushEnabled): void;
|
|
28
31
|
/** Close connection */
|
|
29
32
|
close(): void;
|
|
30
|
-
/**
|
|
31
|
-
* Re-open the connection with the last given authToken.
|
|
32
|
-
*
|
|
33
|
-
* @throws {TypeError} if `open` has not been previously called with an authToken
|
|
34
|
-
*/
|
|
35
|
-
reopen(): void;
|
|
36
33
|
}
|
|
@@ -13,7 +13,8 @@ export declare function errorParser(error: Event): INotificationError;
|
|
|
13
13
|
* Also assigns the type OCCUPANCY, if it corresponds, so that all supported messages (e.g., SPLIT_UPDATE, CONTROL) have a type.
|
|
14
14
|
*
|
|
15
15
|
* @param message
|
|
16
|
-
* @returns parsed notification message
|
|
16
|
+
* @returns parsed notification message or undefined if the given event data is falsy (e.g, '' or undefined).
|
|
17
|
+
* For example, the EventSource implementation of React-Native for iOS emits a message event with empty data for Ably keepalive comments.
|
|
17
18
|
* @throws {SyntaxError} if `message.data` or `JSON.parse(message.data).data` are invalid JSON strings
|
|
18
19
|
*/
|
|
19
|
-
export declare function messageParser(message: MessageEvent): INotificationMessage;
|
|
20
|
+
export declare function messageParser(message: MessageEvent): INotificationMessage | undefined;
|
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
import { ControlType } from '../constants';
|
|
2
|
-
import { MY_SEGMENTS_UPDATE, SEGMENT_UPDATE, SPLIT_UPDATE, SPLIT_KILL, CONTROL, OCCUPANCY } from '../types';
|
|
2
|
+
import { MY_SEGMENTS_UPDATE, MY_SEGMENTS_UPDATE_V2, SEGMENT_UPDATE, SPLIT_UPDATE, SPLIT_KILL, CONTROL, OCCUPANCY } from '../types';
|
|
3
3
|
export interface IMySegmentsUpdateData {
|
|
4
4
|
type: MY_SEGMENTS_UPDATE;
|
|
5
5
|
changeNumber: number;
|
|
6
6
|
includesPayload: boolean;
|
|
7
7
|
segmentList?: string[];
|
|
8
8
|
}
|
|
9
|
+
export declare enum Compression {
|
|
10
|
+
None = 0,
|
|
11
|
+
Gzip = 1,
|
|
12
|
+
Zlib = 2
|
|
13
|
+
}
|
|
14
|
+
export declare enum UpdateStrategy {
|
|
15
|
+
UnboundedFetchRequest = 0,
|
|
16
|
+
BoundedFetchRequest = 1,
|
|
17
|
+
KeyList = 2,
|
|
18
|
+
SegmentRemoval = 3
|
|
19
|
+
}
|
|
20
|
+
export interface KeyList {
|
|
21
|
+
a?: string[];
|
|
22
|
+
r?: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface IMySegmentsUpdateV2Data {
|
|
25
|
+
type: MY_SEGMENTS_UPDATE_V2;
|
|
26
|
+
changeNumber: number;
|
|
27
|
+
segmentName: string;
|
|
28
|
+
c: Compression;
|
|
29
|
+
d: string;
|
|
30
|
+
u: UpdateStrategy;
|
|
31
|
+
}
|
|
9
32
|
export interface ISegmentUpdateData {
|
|
10
33
|
type: SEGMENT_UPDATE;
|
|
11
34
|
changeNumber: number;
|
|
@@ -31,7 +54,7 @@ export interface IOccupancyData {
|
|
|
31
54
|
publishers: number;
|
|
32
55
|
};
|
|
33
56
|
}
|
|
34
|
-
export declare type INotificationData = IMySegmentsUpdateData | ISegmentUpdateData | ISplitUpdateData | ISplitKillData | IControlData | IOccupancyData;
|
|
57
|
+
export declare type INotificationData = IMySegmentsUpdateData | IMySegmentsUpdateV2Data | ISegmentUpdateData | ISplitUpdateData | ISplitKillData | IControlData | IOccupancyData;
|
|
35
58
|
export declare type INotificationMessage = {
|
|
36
59
|
parsedData: INotificationData;
|
|
37
60
|
channel: string;
|
|
@@ -40,4 +63,9 @@ export declare type INotificationMessage = {
|
|
|
40
63
|
};
|
|
41
64
|
export declare type INotificationError = Event & {
|
|
42
65
|
parsedData?: any;
|
|
66
|
+
message?: string;
|
|
67
|
+
};
|
|
68
|
+
export declare type SegmentsData = string[] | {
|
|
69
|
+
name: string;
|
|
70
|
+
add: boolean;
|
|
43
71
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ISegmentsSyncTask } from '../../polling/types';
|
|
2
2
|
import Backoff from '../../../utils/Backoff';
|
|
3
3
|
import { IUpdateWorker } from './types';
|
|
4
|
+
import { SegmentsData } from '../SSEHandler/types';
|
|
4
5
|
/**
|
|
5
6
|
* MySegmentsUpdateWorker class
|
|
6
7
|
*/
|
|
@@ -8,7 +9,7 @@ export default class MySegmentsUpdateWorker implements IUpdateWorker {
|
|
|
8
9
|
private readonly mySegmentsSyncTask;
|
|
9
10
|
private maxChangeNumber;
|
|
10
11
|
private handleNewEvent;
|
|
11
|
-
private
|
|
12
|
+
private segmentsData?;
|
|
12
13
|
private currentChangeNumber;
|
|
13
14
|
readonly backoff: Backoff;
|
|
14
15
|
/**
|
|
@@ -20,7 +21,7 @@ export default class MySegmentsUpdateWorker implements IUpdateWorker {
|
|
|
20
21
|
* Invoked by NotificationProcessor on MY_SEGMENTS_UPDATE event
|
|
21
22
|
*
|
|
22
23
|
* @param {number} changeNumber change number of the MY_SEGMENTS_UPDATE notification
|
|
23
|
-
* @param {
|
|
24
|
+
* @param {SegmentsData | undefined} segmentsData might be undefined
|
|
24
25
|
*/
|
|
25
|
-
put(changeNumber: number,
|
|
26
|
+
put(changeNumber: number, segmentsData?: SegmentsData): void;
|
|
26
27
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ISegmentsCacheSync } from '../../../storages/types';
|
|
2
2
|
import Backoff from '../../../utils/Backoff';
|
|
3
3
|
import { ISegmentsSyncTask } from '../../polling/types';
|
|
4
|
+
import { ISegmentUpdateData } from '../SSEHandler/types';
|
|
4
5
|
import { IUpdateWorker } from './types';
|
|
5
6
|
/**
|
|
6
7
|
* SegmentUpdateWorker class
|
|
@@ -23,5 +24,5 @@ export default class SegmentsUpdateWorker implements IUpdateWorker {
|
|
|
23
24
|
* @param {number} changeNumber change number of the SEGMENT_UPDATE notification
|
|
24
25
|
* @param {string} segmentName segment name of the SEGMENT_UPDATE notification
|
|
25
26
|
*/
|
|
26
|
-
put(changeNumber
|
|
27
|
+
put({ changeNumber, segmentName }: ISegmentUpdateData): void;
|
|
27
28
|
}
|