@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,6 +1,6 @@
|
|
|
1
1
|
import { isObject, uniq, toString, toNumber } from '../../utils/lang';
|
|
2
2
|
import { zeroSinceHH, zeroSinceSS } from '../convertions';
|
|
3
|
-
import { matcherTypes,
|
|
3
|
+
import { matcherTypes, matcherDataTypes } from '../matchers/matcherTypes';
|
|
4
4
|
import { ENGINE_SANITIZE } from '../../logger/constants';
|
|
5
5
|
function sanitizeNumber(val) {
|
|
6
6
|
var num = toNumber(val);
|
|
@@ -61,20 +61,20 @@ export default function sanitize(log, matcherTypeID, value, dataType, attributes
|
|
|
61
61
|
var processor = getProcessingFunction(matcherTypeID, dataType);
|
|
62
62
|
var sanitizedValue;
|
|
63
63
|
switch (dataType) {
|
|
64
|
-
case
|
|
65
|
-
case
|
|
64
|
+
case matcherDataTypes.NUMBER:
|
|
65
|
+
case matcherDataTypes.DATETIME:
|
|
66
66
|
sanitizedValue = sanitizeNumber(value);
|
|
67
67
|
break;
|
|
68
|
-
case
|
|
68
|
+
case matcherDataTypes.STRING:
|
|
69
69
|
sanitizedValue = sanitizeString(value);
|
|
70
70
|
break;
|
|
71
|
-
case
|
|
71
|
+
case matcherDataTypes.SET:
|
|
72
72
|
sanitizedValue = sanitizeArray(value);
|
|
73
73
|
break;
|
|
74
|
-
case
|
|
74
|
+
case matcherDataTypes.BOOLEAN:
|
|
75
75
|
sanitizedValue = sanitizeBoolean(value);
|
|
76
76
|
break;
|
|
77
|
-
case
|
|
77
|
+
case matcherDataTypes.NOT_SPECIFIED:
|
|
78
78
|
sanitizedValue = value;
|
|
79
79
|
break;
|
|
80
80
|
default:
|
package/esm/listeners/browser.js
CHANGED
|
@@ -24,8 +24,6 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
24
24
|
* We add a handler on unload events. The handler flushes remaining impressions and events to the backend.
|
|
25
25
|
*/
|
|
26
26
|
BrowserSignalListener.prototype.start = function () {
|
|
27
|
-
var _a;
|
|
28
|
-
(_a = this.syncManager) === null || _a === void 0 ? void 0 : _a.start();
|
|
29
27
|
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
30
28
|
this.settings.log.debug(CLEANUP_REGISTERING, [EVENT_NAME]);
|
|
31
29
|
window.addEventListener(UNLOAD_DOM_EVENT, this.flushData);
|
|
@@ -34,6 +32,7 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
34
32
|
/**
|
|
35
33
|
* stop method.
|
|
36
34
|
* Called when client is destroyed.
|
|
35
|
+
* We need to remove the handler for unload events, since it can break if called when Split context was destroyed.
|
|
37
36
|
*/
|
|
38
37
|
BrowserSignalListener.prototype.stop = function () {
|
|
39
38
|
if (typeof window !== 'undefined' && window.removeEventListener) {
|
package/esm/listeners/node.js
CHANGED
|
@@ -12,7 +12,6 @@ var EVENT_NAME = 'for SIGTERM signal.';
|
|
|
12
12
|
var NodeSignalListener = /** @class */ (function () {
|
|
13
13
|
function NodeSignalListener(syncManager, // private handler: () => MaybeThenable<void>,
|
|
14
14
|
settings) {
|
|
15
|
-
this.syncManager = syncManager;
|
|
16
15
|
// @TODO review handler logic when implementing Node SDK
|
|
17
16
|
this.handler = function () {
|
|
18
17
|
if (syncManager) {
|
|
@@ -24,8 +23,6 @@ var NodeSignalListener = /** @class */ (function () {
|
|
|
24
23
|
this._sigtermHandler = this._sigtermHandler.bind(this);
|
|
25
24
|
}
|
|
26
25
|
NodeSignalListener.prototype.start = function () {
|
|
27
|
-
var _a;
|
|
28
|
-
(_a = this.syncManager) === null || _a === void 0 ? void 0 : _a.start();
|
|
29
26
|
this.settings.log.debug(CLEANUP_REGISTERING, [EVENT_NAME]);
|
|
30
27
|
// eslint-disable-next-line no-undef
|
|
31
28
|
process.on(SIGTERM, this._sigtermHandler);
|
package/esm/logger/constants.js
CHANGED
|
@@ -91,6 +91,7 @@ export var WARN_SPLITS_FILTER_INVALID = 220;
|
|
|
91
91
|
export var WARN_SPLITS_FILTER_EMPTY = 221;
|
|
92
92
|
export var WARN_STORAGE_INVALID = 222;
|
|
93
93
|
export var WARN_API_KEY = 223;
|
|
94
|
+
export var STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 224;
|
|
94
95
|
export var ERROR_ENGINE_COMBINER_IFELSEIF = 300;
|
|
95
96
|
export var ERROR_LOGLEVEL_INVALID = 301;
|
|
96
97
|
export var ERROR_CLIENT_LISTENER = 302;
|
|
@@ -114,6 +115,7 @@ export var ERROR_EMPTY = 319;
|
|
|
114
115
|
export var ERROR_EMPTY_ARRAY = 320;
|
|
115
116
|
export var ERROR_INVALID_IMPRESSIONS_MODE = 321;
|
|
116
117
|
export var ERROR_HTTP = 322;
|
|
118
|
+
export var ERROR_LOCALHOST_MODULE_REQUIRED = 323;
|
|
117
119
|
// Log prefixes (a.k.a. tags or categories)
|
|
118
120
|
export var LOG_PREFIX_SETTINGS = 'settings';
|
|
119
121
|
export var LOG_PREFIX_INSTANTIATION = 'Factory instantiation';
|
|
@@ -10,8 +10,8 @@ export var codesError = [
|
|
|
10
10
|
[c.ERROR_EVENTS_TRACKER, c.LOG_PREFIX_EVENTS_TRACKER + 'Failed to queue %s'],
|
|
11
11
|
// synchronizer
|
|
12
12
|
[c.ERROR_SYNC_OFFLINE_LOADING, c.LOG_PREFIX_SYNC_OFFLINE + 'There was an issue loading the mock Splits data, no changes will be applied to the current cache. %s'],
|
|
13
|
-
[c.ERROR_STREAMING_SSE, c.LOG_PREFIX_SYNC_STREAMING + '
|
|
14
|
-
[c.ERROR_STREAMING_AUTH, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to authenticate for streaming. Error:
|
|
13
|
+
[c.ERROR_STREAMING_SSE, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to connect or error on streaming connection, with error message: %s'],
|
|
14
|
+
[c.ERROR_STREAMING_AUTH, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to authenticate for streaming. Error: %s.'],
|
|
15
15
|
[c.ERROR_HTTP, ' Response status is not OK. Status: %s. URL: %s. Message: %s'],
|
|
16
16
|
// client status
|
|
17
17
|
[c.ERROR_CLIENT_LISTENER, 'A listener was added for %s on the SDK, which has already fired and won\'t be emitted again. The callback won\'t be executed.'],
|
|
@@ -29,4 +29,5 @@ export var codesError = [
|
|
|
29
29
|
[c.ERROR_EMPTY_ARRAY, '%s: %s must be a non-empty array.'],
|
|
30
30
|
// initialization / settings validation
|
|
31
31
|
[c.ERROR_INVALID_IMPRESSIONS_MODE, c.LOG_PREFIX_SETTINGS + ': you passed an invalid "impressionsMode". It should be one of the following values: %s. Defaulting to "%s" mode.'],
|
|
32
|
+
[c.ERROR_LOCALHOST_MODULE_REQUIRED, c.LOG_PREFIX_SETTINGS + ': you didn\'t pass a valid "sync.localhostMode". It should be defined for using the SDK in localhost mode']
|
|
32
33
|
];
|
|
@@ -19,9 +19,9 @@ export var codesInfo = codesWarn.concat([
|
|
|
19
19
|
[c.SYNC_SPLITS_FETCH_RETRY, c.LOG_PREFIX_SYNC_SPLITS + 'Retrying download of splits #%s. Reason: %s'],
|
|
20
20
|
[c.SUBMITTERS_PUSH_FULL_EVENTS_QUEUE, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Flushing full events queue and reseting timer.'],
|
|
21
21
|
[c.SUBMITTERS_PUSH, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Pushing %s %s.'],
|
|
22
|
-
[c.STREAMING_REFRESH_TOKEN, c.LOG_PREFIX_SYNC_STREAMING + 'Refreshing streaming token in %s seconds.'],
|
|
22
|
+
[c.STREAMING_REFRESH_TOKEN, c.LOG_PREFIX_SYNC_STREAMING + 'Refreshing streaming token in %s seconds, and connecting streaming in %s seconds.'],
|
|
23
23
|
[c.STREAMING_RECONNECT, c.LOG_PREFIX_SYNC_STREAMING + 'Attempting to reconnect in %s seconds.'],
|
|
24
|
-
[c.STREAMING_CONNECTING, c.LOG_PREFIX_SYNC_STREAMING + '
|
|
24
|
+
[c.STREAMING_CONNECTING, c.LOG_PREFIX_SYNC_STREAMING + '%sConnecting to streaming.'],
|
|
25
25
|
[c.STREAMING_DISABLED, c.LOG_PREFIX_SYNC_STREAMING + 'Streaming is disabled for given Api key. Switching to polling mode.'],
|
|
26
26
|
[c.STREAMING_DISCONNECTING, c.LOG_PREFIX_SYNC_STREAMING + 'Disconnecting from streaming.'],
|
|
27
27
|
[c.SYNC_START_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming not available. Starting polling.'],
|
|
@@ -29,5 +29,6 @@ export var codesWarn = codesError.concat([
|
|
|
29
29
|
[c.WARN_SPLITS_FILTER_INVALID, c.LOG_PREFIX_SETTINGS + ': split filter at position %s is invalid. It must be an object with a valid filter type ("byName" or "byPrefix") and a list of "values".'],
|
|
30
30
|
[c.WARN_SPLITS_FILTER_EMPTY, c.LOG_PREFIX_SETTINGS + ': splitFilters configuration must be a non-empty array of filter objects.'],
|
|
31
31
|
[c.WARN_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS + ': The provided storage is invalid. Fallbacking into default MEMORY storage'],
|
|
32
|
-
[c.WARN_API_KEY, c.LOG_PREFIX_SETTINGS + ': You already have %s. We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing it throughout your application']
|
|
32
|
+
[c.WARN_API_KEY, c.LOG_PREFIX_SETTINGS + ': You already have %s. We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing it throughout your application'],
|
|
33
|
+
[c.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching MySegments due to an error processing %s notification: %s'],
|
|
33
34
|
]);
|
|
@@ -31,7 +31,7 @@ export function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
|
|
|
31
31
|
// emit SDK_READY_FROM_CACHE
|
|
32
32
|
var isReadyFromCache = false;
|
|
33
33
|
if (splits.splitsCacheLoaded)
|
|
34
|
-
|
|
34
|
+
isReadyFromCache = true; // ready from cache, but doesn't emit SDK_READY_FROM_CACHE
|
|
35
35
|
else
|
|
36
36
|
splits.once(SDK_SPLITS_CACHE_LOADED, checkIsReadyFromCache);
|
|
37
37
|
// emit SDK_READY_TIMED_OUT
|
|
@@ -49,13 +49,16 @@ export function readinessManagerFactory(EventEmitter, readyTimeout, splits) {
|
|
|
49
49
|
segments.on(SDK_SEGMENTS_ARRIVED, checkIsReadyOrUpdate);
|
|
50
50
|
var isDestroyed = false;
|
|
51
51
|
function checkIsReadyFromCache() {
|
|
52
|
-
|
|
53
|
-
if
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
isReadyFromCache = true;
|
|
52
|
+
isReadyFromCache = true;
|
|
53
|
+
// Don't emit SDK_READY_FROM_CACHE if SDK_READY has been emitted
|
|
54
|
+
if (!isReady) {
|
|
55
|
+
try {
|
|
57
56
|
gate.emit(SDK_READY_FROM_CACHE);
|
|
58
|
-
}
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
// throws user callback exceptions in next tick
|
|
60
|
+
setTimeout(function () { throw e; }, 0);
|
|
61
|
+
}
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
function checkIsReadyOrUpdate(diff) {
|
package/esm/sdkFactory/index.js
CHANGED
|
@@ -58,10 +58,7 @@ export function sdkFactory(params) {
|
|
|
58
58
|
// Sdk client and manager
|
|
59
59
|
var clientMethod = sdkClientMethodFactory({ eventTracker: eventTracker, impressionsTracker: impressionsTracker, sdkReadinessManager: sdkReadinessManager, settings: settings, storage: storage, syncManager: syncManager, signalListener: signalListener });
|
|
60
60
|
var managerInstance = sdkManagerFactory(log, storage.splits, sdkReadinessManager);
|
|
61
|
-
|
|
62
|
-
// It is required for RN to consider the app state when the SDK is instantiated (foreground/background).
|
|
63
|
-
if (syncManager && !signalListener)
|
|
64
|
-
syncManager.start();
|
|
61
|
+
syncManager && syncManager.start();
|
|
65
62
|
signalListener && signalListener.start();
|
|
66
63
|
log.info(NEW_FACTORY);
|
|
67
64
|
return {
|
package/esm/services/splitApi.js
CHANGED
|
@@ -25,7 +25,7 @@ export function splitApiFactory(settings, platform) {
|
|
|
25
25
|
return splitHttpClient(url).then(function () { return true; }).catch(function () { return false; });
|
|
26
26
|
},
|
|
27
27
|
fetchAuth: function (userMatchingKeys) {
|
|
28
|
-
var url = urls.auth + "/auth";
|
|
28
|
+
var url = urls.auth + "/v2/auth";
|
|
29
29
|
if (userMatchingKeys) { // accounting the possibility that `userMatchingKeys` is undefined (server-side API)
|
|
30
30
|
var queryParams = userMatchingKeys.map(userKeyToQueryParam).join('&');
|
|
31
31
|
if (queryParams) // accounting the possibility that `userKeys` and thus `queryParams` are empty
|
|
@@ -37,8 +37,8 @@ export function splitHttpClientFactory(settings, getFetch, getOptions) {
|
|
|
37
37
|
return fetch ? fetch(url, request)
|
|
38
38
|
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful
|
|
39
39
|
.then(function (response) {
|
|
40
|
-
if (!response.ok) {
|
|
41
|
-
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
return response.text().then(function (message) { return Promise.reject({ response: response, message: message }); });
|
|
42
42
|
}
|
|
43
43
|
return response;
|
|
44
44
|
})
|
|
@@ -50,13 +50,14 @@ export function splitHttpClientFactory(settings, getFetch, getOptions) {
|
|
|
50
50
|
case 404:
|
|
51
51
|
msg = 'Invalid API key or resource not found.';
|
|
52
52
|
break;
|
|
53
|
+
// Don't use resp.statusText since reason phrase is removed in HTTP/2
|
|
53
54
|
default:
|
|
54
|
-
msg =
|
|
55
|
+
msg = error.message;
|
|
55
56
|
break;
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
else { // Something else, either an error making the request or a Network error.
|
|
59
|
-
msg = error.message;
|
|
60
|
+
msg = error.message || 'Network Error';
|
|
60
61
|
}
|
|
61
62
|
if (!resp || resp.status !== 403) { // 403's log we'll be handled somewhere else.
|
|
62
63
|
log[logErrorsAsInfo ? 'info' : 'error'](ERROR_HTTP, [resp ? resp.status : 'NO_STATUS', url, msg]);
|
|
@@ -30,7 +30,7 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
|
|
|
30
30
|
* It is used as condition to emit SDK_SPLITS_CACHE_LOADED, and then SDK_READY_FROM_CACHE.
|
|
31
31
|
*/
|
|
32
32
|
AbstractSplitsCacheSync.prototype.checkCache = function () {
|
|
33
|
-
return
|
|
33
|
+
return false;
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
36
|
* Kill `name` split and set `defaultTreatment` and `changeNumber`.
|
|
@@ -11,13 +11,14 @@ import SplitsCacheInMemory from '../inMemory/SplitsCacheInMemory';
|
|
|
11
11
|
import { DEFAULT_CACHE_EXPIRATION_IN_MILLIS } from '../../utils/constants/browser';
|
|
12
12
|
import { InMemoryStorageCSFactory } from '../inMemory/InMemoryStorageCS';
|
|
13
13
|
import { LOG_PREFIX } from './constants';
|
|
14
|
+
import { STORAGE_LOCALSTORAGE } from '../../utils/constants';
|
|
14
15
|
/**
|
|
15
16
|
* InLocal storage factory for standalone client-side SplitFactory
|
|
16
17
|
*/
|
|
17
18
|
export function InLocalStorage(options) {
|
|
18
19
|
if (options === void 0) { options = {}; }
|
|
19
20
|
var prefix = validatePrefix(options.prefix);
|
|
20
|
-
|
|
21
|
+
function InLocalStorageCSFactory(params) {
|
|
21
22
|
// Fallback to InMemoryStorage if LocalStorage API is not available
|
|
22
23
|
if (!isLocalStorageAvailable()) {
|
|
23
24
|
params.log.warn(LOG_PREFIX + 'LocalStorage API is unavailable. Fallbacking into default MEMORY storage');
|
|
@@ -55,5 +56,7 @@ export function InLocalStorage(options) {
|
|
|
55
56
|
};
|
|
56
57
|
},
|
|
57
58
|
};
|
|
58
|
-
}
|
|
59
|
+
}
|
|
60
|
+
InLocalStorageCSFactory.type = STORAGE_LOCALSTORAGE;
|
|
61
|
+
return InLocalStorageCSFactory;
|
|
59
62
|
}
|
|
@@ -3,6 +3,7 @@ import SegmentsCacheInMemory from './SegmentsCacheInMemory';
|
|
|
3
3
|
import ImpressionsCacheInMemory from './ImpressionsCacheInMemory';
|
|
4
4
|
import EventsCacheInMemory from './EventsCacheInMemory';
|
|
5
5
|
import ImpressionCountsCacheInMemory from './ImpressionCountsCacheInMemory';
|
|
6
|
+
import { STORAGE_MEMORY } from '../../utils/constants';
|
|
6
7
|
/**
|
|
7
8
|
* InMemory storage factory for standalone server-side SplitFactory
|
|
8
9
|
*
|
|
@@ -28,3 +29,4 @@ export function InMemoryStorageFactory(params) {
|
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
31
|
}
|
|
32
|
+
InMemoryStorageFactory.type = STORAGE_MEMORY;
|
|
@@ -3,6 +3,7 @@ import MySegmentsCacheInMemory from './MySegmentsCacheInMemory';
|
|
|
3
3
|
import ImpressionsCacheInMemory from './ImpressionsCacheInMemory';
|
|
4
4
|
import EventsCacheInMemory from './EventsCacheInMemory';
|
|
5
5
|
import ImpressionCountsCacheInMemory from './ImpressionCountsCacheInMemory';
|
|
6
|
+
import { STORAGE_MEMORY } from '../../utils/constants';
|
|
6
7
|
/**
|
|
7
8
|
* InMemory storage factory for standalone client-side SplitFactory
|
|
8
9
|
*
|
|
@@ -40,3 +41,4 @@ export function InMemoryStorageCSFactory(params) {
|
|
|
40
41
|
},
|
|
41
42
|
};
|
|
42
43
|
}
|
|
44
|
+
InMemoryStorageCSFactory.type = STORAGE_MEMORY;
|
|
@@ -34,9 +34,13 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
34
34
|
return _this;
|
|
35
35
|
}
|
|
36
36
|
SplitsCacheInRedis.prototype._decrementCounts = function (split) {
|
|
37
|
+
var _this = this;
|
|
37
38
|
if (split.trafficTypeName) {
|
|
38
|
-
var
|
|
39
|
-
return this.redis.decr(
|
|
39
|
+
var ttKey_1 = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
40
|
+
return this.redis.decr(ttKey_1).then(function (count) {
|
|
41
|
+
if (count === 0)
|
|
42
|
+
return _this.redis.del(ttKey_1);
|
|
43
|
+
});
|
|
40
44
|
}
|
|
41
45
|
};
|
|
42
46
|
SplitsCacheInRedis.prototype._incrementCounts = function (split) {
|
|
@@ -7,6 +7,7 @@ import ImpressionsCacheInRedis from './ImpressionsCacheInRedis';
|
|
|
7
7
|
import EventsCacheInRedis from './EventsCacheInRedis';
|
|
8
8
|
import LatenciesCacheInRedis from './LatenciesCacheInRedis';
|
|
9
9
|
import CountsCacheInRedis from './CountsCacheInRedis';
|
|
10
|
+
import { STORAGE_REDIS } from '../../utils/constants';
|
|
10
11
|
/**
|
|
11
12
|
* InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.
|
|
12
13
|
* @see {@link https://www.npmjs.com/package/ioredis}
|
|
@@ -14,7 +15,7 @@ import CountsCacheInRedis from './CountsCacheInRedis';
|
|
|
14
15
|
export function InRedisStorage(options) {
|
|
15
16
|
if (options === void 0) { options = {}; }
|
|
16
17
|
var prefix = validatePrefix(options.prefix);
|
|
17
|
-
|
|
18
|
+
function InRedisStorageFactory(_a) {
|
|
18
19
|
var log = _a.log, metadata = _a.metadata, onReadyCb = _a.onReadyCb;
|
|
19
20
|
var keys = new KeyBuilderSS(prefix, metadata);
|
|
20
21
|
var redisClient = new RedisAdapter(log, options.options || {});
|
|
@@ -37,5 +38,7 @@ export function InRedisStorage(options) {
|
|
|
37
38
|
// @TODO check that caches works as expected when redisClient is disconnected
|
|
38
39
|
}
|
|
39
40
|
};
|
|
40
|
-
}
|
|
41
|
+
}
|
|
42
|
+
InRedisStorageFactory.type = STORAGE_REDIS;
|
|
43
|
+
return InRedisStorageFactory;
|
|
41
44
|
}
|
|
@@ -21,9 +21,13 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
21
21
|
return _this;
|
|
22
22
|
}
|
|
23
23
|
SplitsCachePluggable.prototype._decrementCounts = function (split) {
|
|
24
|
+
var _this = this;
|
|
24
25
|
if (split.trafficTypeName) {
|
|
25
|
-
var
|
|
26
|
-
return this.wrapper.decr(
|
|
26
|
+
var ttKey_1 = this.keys.buildTrafficTypeKey(split.trafficTypeName);
|
|
27
|
+
return this.wrapper.decr(ttKey_1).then(function (count) {
|
|
28
|
+
if (count === 0)
|
|
29
|
+
return _this.wrapper.del(ttKey_1);
|
|
30
|
+
});
|
|
27
31
|
}
|
|
28
32
|
};
|
|
29
33
|
SplitsCachePluggable.prototype._incrementCounts = function (split) {
|
|
@@ -31,32 +31,31 @@ export function inMemoryWrapperFactory() {
|
|
|
31
31
|
getKeysByPrefix: function (prefix) {
|
|
32
32
|
return Promise.resolve(Object.keys(_cache).filter(function (key) { return startsWith(key, prefix); }));
|
|
33
33
|
},
|
|
34
|
-
getByPrefix: function (prefix) {
|
|
35
|
-
return Promise.resolve(Object.keys(_cache).filter(function (key) { return startsWith(key, prefix); }).map(function (key) { return _cache[key]; }));
|
|
36
|
-
},
|
|
37
34
|
incr: function (key) {
|
|
38
35
|
if (key in _cache) {
|
|
39
36
|
var count = toNumber(_cache[key]) + 1;
|
|
40
37
|
if (isNaN(count))
|
|
41
|
-
return Promise.
|
|
38
|
+
return Promise.reject('Given key is not a number');
|
|
42
39
|
_cache[key] = count + '';
|
|
40
|
+
return Promise.resolve(count);
|
|
43
41
|
}
|
|
44
42
|
else {
|
|
45
43
|
_cache[key] = '1';
|
|
44
|
+
return Promise.resolve(1);
|
|
46
45
|
}
|
|
47
|
-
return Promise.resolve(true);
|
|
48
46
|
},
|
|
49
47
|
decr: function (key) {
|
|
50
48
|
if (key in _cache) {
|
|
51
49
|
var count = toNumber(_cache[key]) - 1;
|
|
52
50
|
if (isNaN(count))
|
|
53
|
-
return Promise.
|
|
51
|
+
return Promise.reject('Given key is not a number');
|
|
54
52
|
_cache[key] = count + '';
|
|
53
|
+
return Promise.resolve(count);
|
|
55
54
|
}
|
|
56
55
|
else {
|
|
57
56
|
_cache[key] = '-1';
|
|
57
|
+
return Promise.resolve(-1);
|
|
58
58
|
}
|
|
59
|
-
return Promise.resolve(true);
|
|
60
59
|
},
|
|
61
60
|
getMany: function (keys) {
|
|
62
61
|
return Promise.resolve(keys.map(function (key) { return _cache[key] ? _cache[key] : null; }));
|
|
@@ -6,6 +6,7 @@ import { EventsCachePluggable } from './EventsCachePluggable';
|
|
|
6
6
|
import { wrapperAdapter, METHODS_TO_PROMISE_WRAP } from './wrapperAdapter';
|
|
7
7
|
import { isObject } from '../../utils/lang';
|
|
8
8
|
import { validatePrefix } from '../KeyBuilder';
|
|
9
|
+
import { STORAGE_CUSTOM } from '../../utils/constants';
|
|
9
10
|
var NO_VALID_WRAPPER = 'Expecting custom storage `wrapper` in options, but no valid wrapper instance was provided.';
|
|
10
11
|
var NO_VALID_WRAPPER_INTERFACE = 'The provided wrapper instance doesn’t follow the expected interface. Check our docs.';
|
|
11
12
|
/**
|
|
@@ -28,7 +29,7 @@ function validatePluggableStorageOptions(options) {
|
|
|
28
29
|
export function PluggableStorage(options) {
|
|
29
30
|
validatePluggableStorageOptions(options);
|
|
30
31
|
var prefix = validatePrefix(options.prefix);
|
|
31
|
-
|
|
32
|
+
function PluggableStorageFactory(_a) {
|
|
32
33
|
var log = _a.log, metadata = _a.metadata, onReadyCb = _a.onReadyCb;
|
|
33
34
|
var keys = new KeyBuilderSS(prefix, metadata);
|
|
34
35
|
var wrapper = wrapperAdapter(log, options.wrapper);
|
|
@@ -51,5 +52,7 @@ export function PluggableStorage(options) {
|
|
|
51
52
|
return wrapper.close();
|
|
52
53
|
}
|
|
53
54
|
};
|
|
54
|
-
}
|
|
55
|
+
}
|
|
56
|
+
PluggableStorageFactory.type = STORAGE_CUSTOM;
|
|
57
|
+
return PluggableStorageFactory;
|
|
55
58
|
}
|
|
@@ -8,7 +8,6 @@ import { isString, endsWith, find, forOwn, uniq, } from '../../../utils/lang';
|
|
|
8
8
|
import parseCondition from './parseCondition';
|
|
9
9
|
var logPrefix = 'sync:offline:splits-fetcher: ';
|
|
10
10
|
var DEFAULT_FILENAME = '.split';
|
|
11
|
-
var previousMock = 'NO_MOCK_LOADED';
|
|
12
11
|
function configFilesPath(configFilePath) {
|
|
13
12
|
if (configFilePath === DEFAULT_FILENAME || !isString(configFilePath)) {
|
|
14
13
|
var root = process.env.HOME;
|
|
@@ -25,81 +24,6 @@ function configFilesPath(configFilePath) {
|
|
|
25
24
|
throw new Error("Split configuration not found in " + configFilePath + " - Please review your Split file location.");
|
|
26
25
|
return configFilePath;
|
|
27
26
|
}
|
|
28
|
-
// Parse `.split` configuration file and return a map of "Split Objects"
|
|
29
|
-
function readSplitConfigFile(log, filePath) {
|
|
30
|
-
var SPLIT_POSITION = 0;
|
|
31
|
-
var TREATMENT_POSITION = 1;
|
|
32
|
-
var data;
|
|
33
|
-
try {
|
|
34
|
-
data = fs.readFileSync(filePath, 'utf-8');
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
log.error(e.message);
|
|
38
|
-
return {};
|
|
39
|
-
}
|
|
40
|
-
if (data === previousMock)
|
|
41
|
-
return false;
|
|
42
|
-
previousMock = data;
|
|
43
|
-
var splitObjects = data.split(/\r?\n/).reduce(function (accum, line, index) {
|
|
44
|
-
var tuple = line.trim();
|
|
45
|
-
if (tuple === '' || tuple.charAt(0) === '#') {
|
|
46
|
-
log.debug(logPrefix + ("Ignoring empty line or comment at #" + index));
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
tuple = tuple.split(/\s+/);
|
|
50
|
-
if (tuple.length !== 2) {
|
|
51
|
-
log.debug(logPrefix + ("Ignoring line since it does not have exactly two columns #" + index));
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
var splitName = tuple[SPLIT_POSITION];
|
|
55
|
-
var condition = parseCondition({ treatment: tuple[TREATMENT_POSITION] });
|
|
56
|
-
accum[splitName] = { conditions: [condition], configurations: {}, trafficTypeName: 'localhost' };
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return accum;
|
|
60
|
-
}, {});
|
|
61
|
-
return splitObjects;
|
|
62
|
-
}
|
|
63
|
-
// Parse `.yml` or `.yaml` configuration files and return a map of "Split Objects"
|
|
64
|
-
function readYAMLConfigFile(log, filePath) {
|
|
65
|
-
var data = '';
|
|
66
|
-
var yamldoc = null;
|
|
67
|
-
try {
|
|
68
|
-
data = fs.readFileSync(filePath, 'utf8');
|
|
69
|
-
if (data === previousMock)
|
|
70
|
-
return false;
|
|
71
|
-
previousMock = data;
|
|
72
|
-
yamldoc = yaml.safeLoad(data);
|
|
73
|
-
}
|
|
74
|
-
catch (e) {
|
|
75
|
-
log.error(e);
|
|
76
|
-
return {};
|
|
77
|
-
}
|
|
78
|
-
// Each entry will be mapped to a condition, but we'll also keep the configurations map.
|
|
79
|
-
var mocksData = yamldoc.reduce(function (accum, splitEntry) {
|
|
80
|
-
var splitName = Object.keys(splitEntry)[0];
|
|
81
|
-
if (!splitName || !isString(splitEntry[splitName].treatment))
|
|
82
|
-
log.error(logPrefix + 'Ignoring entry on YAML since the format is incorrect.');
|
|
83
|
-
var mockData = splitEntry[splitName];
|
|
84
|
-
// "Template" for each split accumulated data
|
|
85
|
-
if (!accum[splitName]) {
|
|
86
|
-
accum[splitName] = {
|
|
87
|
-
configurations: {}, conditions: [], treatments: [], trafficTypeName: 'localhost'
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
// Assign the config if there is one on the mock
|
|
91
|
-
if (mockData.config)
|
|
92
|
-
accum[splitName].configurations[mockData.treatment] = mockData.config;
|
|
93
|
-
// Parse the condition from the entry.
|
|
94
|
-
var condition = parseCondition(mockData);
|
|
95
|
-
accum[splitName].conditions[condition.conditionType === 'ROLLOUT' ? 'push' : 'unshift'](condition);
|
|
96
|
-
// Also keep track of the treatments, will be useful for manager functionality.
|
|
97
|
-
accum[splitName].treatments.push(mockData.treatment);
|
|
98
|
-
return accum;
|
|
99
|
-
}, {});
|
|
100
|
-
arrangeConditions(mocksData);
|
|
101
|
-
return mocksData;
|
|
102
|
-
}
|
|
103
27
|
// This function is not pure nor meant to be. Here we apply modifications to cover
|
|
104
28
|
// for behaviour that's ensured by the BE.
|
|
105
29
|
function arrangeConditions(mocksData) {
|
|
@@ -127,18 +51,96 @@ function arrangeConditions(mocksData) {
|
|
|
127
51
|
delete data.treatments;
|
|
128
52
|
});
|
|
129
53
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
54
|
+
export function splitsParserFromFileFactory() {
|
|
55
|
+
var previousMock = 'NO_MOCK_LOADED';
|
|
56
|
+
// Parse `.split` configuration file and return a map of "Split Objects"
|
|
57
|
+
function readSplitConfigFile(log, filePath) {
|
|
58
|
+
var SPLIT_POSITION = 0;
|
|
59
|
+
var TREATMENT_POSITION = 1;
|
|
60
|
+
var data;
|
|
61
|
+
try {
|
|
62
|
+
data = fs.readFileSync(filePath, 'utf-8');
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
log.error(e.message);
|
|
66
|
+
return {};
|
|
67
|
+
}
|
|
68
|
+
if (data === previousMock)
|
|
69
|
+
return false;
|
|
70
|
+
previousMock = data;
|
|
71
|
+
var splitObjects = data.split(/\r?\n/).reduce(function (accum, line, index) {
|
|
72
|
+
var tuple = line.trim();
|
|
73
|
+
if (tuple === '' || tuple.charAt(0) === '#') {
|
|
74
|
+
log.debug(logPrefix + ("Ignoring empty line or comment at #" + index));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
tuple = tuple.split(/\s+/);
|
|
78
|
+
if (tuple.length !== 2) {
|
|
79
|
+
log.debug(logPrefix + ("Ignoring line since it does not have exactly two columns #" + index));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
var splitName = tuple[SPLIT_POSITION];
|
|
83
|
+
var condition = parseCondition({ treatment: tuple[TREATMENT_POSITION] });
|
|
84
|
+
accum[splitName] = { conditions: [condition], configurations: {}, trafficTypeName: 'localhost' };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return accum;
|
|
88
|
+
}, {});
|
|
89
|
+
return splitObjects;
|
|
139
90
|
}
|
|
140
|
-
|
|
141
|
-
|
|
91
|
+
// Parse `.yml` or `.yaml` configuration files and return a map of "Split Objects"
|
|
92
|
+
function readYAMLConfigFile(log, filePath) {
|
|
93
|
+
var data = '';
|
|
94
|
+
var yamldoc = null;
|
|
95
|
+
try {
|
|
96
|
+
data = fs.readFileSync(filePath, 'utf8');
|
|
97
|
+
if (data === previousMock)
|
|
98
|
+
return false;
|
|
99
|
+
previousMock = data;
|
|
100
|
+
yamldoc = yaml.safeLoad(data);
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
log.error(e);
|
|
104
|
+
return {};
|
|
105
|
+
}
|
|
106
|
+
// Each entry will be mapped to a condition, but we'll also keep the configurations map.
|
|
107
|
+
var mocksData = yamldoc.reduce(function (accum, splitEntry) {
|
|
108
|
+
var splitName = Object.keys(splitEntry)[0];
|
|
109
|
+
if (!splitName || !isString(splitEntry[splitName].treatment))
|
|
110
|
+
log.error(logPrefix + 'Ignoring entry on YAML since the format is incorrect.');
|
|
111
|
+
var mockData = splitEntry[splitName];
|
|
112
|
+
// "Template" for each split accumulated data
|
|
113
|
+
if (!accum[splitName]) {
|
|
114
|
+
accum[splitName] = {
|
|
115
|
+
configurations: {}, conditions: [], treatments: [], trafficTypeName: 'localhost'
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
// Assign the config if there is one on the mock
|
|
119
|
+
if (mockData.config)
|
|
120
|
+
accum[splitName].configurations[mockData.treatment] = mockData.config;
|
|
121
|
+
// Parse the condition from the entry.
|
|
122
|
+
var condition = parseCondition(mockData);
|
|
123
|
+
accum[splitName].conditions[condition.conditionType === 'ROLLOUT' ? 'push' : 'unshift'](condition);
|
|
124
|
+
// Also keep track of the treatments, will be useful for manager functionality.
|
|
125
|
+
accum[splitName].treatments.push(mockData.treatment);
|
|
126
|
+
return accum;
|
|
127
|
+
}, {});
|
|
128
|
+
arrangeConditions(mocksData);
|
|
129
|
+
return mocksData;
|
|
142
130
|
}
|
|
143
|
-
|
|
131
|
+
// Load the content of a configuration file into an Object
|
|
132
|
+
return function splitsParserFromFile(_a) {
|
|
133
|
+
var features = _a.features, log = _a.log;
|
|
134
|
+
var filePath = configFilesPath(features);
|
|
135
|
+
var mockData;
|
|
136
|
+
// If we have a filePath, it means the extension is correct, choose the parser.
|
|
137
|
+
if (endsWith(filePath, '.split')) {
|
|
138
|
+
log.warn(logPrefix + '.split mocks will be deprecated soon in favor of YAML files, which provide more targeting power. Take a look in our documentation.');
|
|
139
|
+
mockData = readSplitConfigFile(log, filePath);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
mockData = readYAMLConfigFile(log, filePath);
|
|
143
|
+
}
|
|
144
|
+
return mockData;
|
|
145
|
+
};
|
|
144
146
|
}
|