@splitsoftware/splitio-commons 1.0.1-rc.1 → 1.0.1-rc.2
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/logger/constants.js +4 -4
- package/cjs/logger/messages/error.js +2 -1
- package/cjs/logger/messages/warn.js +0 -1
- package/cjs/sdkFactory/index.js +1 -1
- package/cjs/storages/inRedis/index.js +1 -2
- package/cjs/storages/pluggable/SplitsCachePluggable.js +1 -1
- package/cjs/storages/pluggable/inMemoryWrapper.js +3 -3
- package/cjs/storages/pluggable/index.js +6 -6
- package/cjs/storages/pluggable/wrapperAdapter.js +3 -3
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +1 -1
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +0 -1
- package/cjs/utils/constants/index.js +2 -2
- package/cjs/utils/settingsValidation/storage/storageCS.js +11 -8
- package/esm/logger/constants.js +3 -3
- package/esm/logger/messages/error.js +2 -1
- package/esm/logger/messages/warn.js +0 -1
- package/esm/sdkFactory/index.js +1 -1
- package/esm/storages/inRedis/index.js +1 -2
- package/esm/storages/pluggable/SplitsCachePluggable.js +1 -1
- package/esm/storages/pluggable/inMemoryWrapper.js +3 -3
- package/esm/storages/pluggable/index.js +7 -7
- package/esm/storages/pluggable/wrapperAdapter.js +3 -3
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +1 -1
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +0 -1
- package/esm/utils/constants/index.js +1 -1
- package/esm/utils/settingsValidation/storage/storageCS.js +13 -10
- package/package.json +1 -1
- package/src/logger/constants.ts +3 -3
- package/src/logger/messages/error.ts +2 -1
- package/src/logger/messages/warn.ts +0 -1
- package/src/sdkFactory/index.ts +1 -1
- package/src/services/splitApi.ts +4 -1
- package/src/storages/inRedis/index.ts +1 -1
- package/src/storages/pluggable/EventsCachePluggable.ts +3 -3
- package/src/storages/pluggable/ImpressionsCachePluggable.ts +3 -3
- package/src/storages/pluggable/SegmentsCachePluggable.ts +3 -3
- package/src/storages/pluggable/SplitsCachePluggable.ts +4 -4
- package/src/storages/pluggable/inMemoryWrapper.ts +5 -5
- package/src/storages/pluggable/index.ts +10 -10
- package/src/storages/pluggable/wrapperAdapter.ts +5 -5
- package/src/storages/types.ts +7 -7
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +1 -1
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +0 -1
- package/src/trackers/impressionObserver/ImpressionObserver.ts +1 -1
- package/src/types.ts +1 -1
- package/src/utils/constants/index.ts +1 -1
- package/src/utils/settingsValidation/storage/storageCS.ts +12 -8
- package/types/logger/constants.d.ts +3 -3
- package/types/services/splitApi.d.ts +1 -1
- package/types/storages/pluggable/EventsCachePluggable.d.ts +2 -2
- package/types/storages/pluggable/ImpressionsCachePluggable.d.ts +2 -2
- package/types/storages/pluggable/SegmentsCachePluggable.d.ts +2 -2
- package/types/storages/pluggable/SplitsCachePluggable.d.ts +3 -3
- package/types/storages/pluggable/inMemoryWrapper.d.ts +3 -3
- package/types/storages/pluggable/index.d.ts +2 -2
- package/types/storages/pluggable/wrapperAdapter.d.ts +4 -4
- package/types/storages/types.d.ts +6 -6
- package/types/trackers/impressionObserver/ImpressionObserver.d.ts +1 -1
- package/types/types.d.ts +1 -1
- package/types/utils/constants/index.d.ts +1 -1
- package/types/utils/settingsValidation/storage/storageCS.d.ts +3 -1
package/cjs/logger/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LOG_PREFIX_CLEANUP = exports.LOG_PREFIX_EVENTS_TRACKER = exports.LOG_PREFIX_IMPRESSIONS_TRACKER = exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC_MYSEGMENTS = exports.LOG_PREFIX_SYNC_SEGMENTS = exports.LOG_PREFIX_SYNC_SPLITS = exports.LOG_PREFIX_SYNC_STREAMING = exports.LOG_PREFIX_SYNC_OFFLINE = exports.LOG_PREFIX_SYNC_MANAGER = exports.LOG_PREFIX_SYNC = exports.LOG_PREFIX_ENGINE_VALUE = exports.LOG_PREFIX_ENGINE_MATCHER = exports.LOG_PREFIX_ENGINE_COMBINER = exports.LOG_PREFIX_ENGINE = exports.LOG_PREFIX_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ERROR_LOCALHOST_MODULE_REQUIRED = exports.ERROR_HTTP = exports.ERROR_INVALID_IMPRESSIONS_MODE = exports.ERROR_EMPTY_ARRAY = exports.ERROR_EMPTY = exports.ERROR_INVALID = exports.ERROR_INVALID_KEY_OBJECT = exports.ERROR_TOO_LONG = exports.ERROR_NULL = exports.ERROR_CLIENT_DESTROYED = exports.ERROR_NOT_FINITE = exports.ERROR_SIZE_EXCEEDED = exports.ERROR_NOT_PLAIN_OBJECT = exports.ERROR_EVENT_TYPE_FORMAT = exports.ERROR_EVENTS_TRACKER = exports.ERROR_IMPRESSIONS_LISTENER = exports.ERROR_IMPRESSIONS_TRACKER = exports.ERROR_STREAMING_AUTH = exports.ERROR_STREAMING_SSE = exports.ERROR_SYNC_OFFLINE_LOADING = exports.ERROR_CLIENT_CANNOT_GET_READY = exports.ERROR_CLIENT_LISTENER = exports.ERROR_LOGLEVEL_INVALID = exports.ERROR_ENGINE_COMBINER_IFELSEIF = exports.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = exports.WARN_API_KEY = exports.
|
|
3
|
+
exports.LOG_PREFIX_CLEANUP = exports.LOG_PREFIX_EVENTS_TRACKER = exports.LOG_PREFIX_IMPRESSIONS_TRACKER = exports.LOG_PREFIX_SYNC_SUBMITTERS = exports.LOG_PREFIX_SYNC_POLLING = exports.LOG_PREFIX_SYNC_MYSEGMENTS = exports.LOG_PREFIX_SYNC_SEGMENTS = exports.LOG_PREFIX_SYNC_SPLITS = exports.LOG_PREFIX_SYNC_STREAMING = exports.LOG_PREFIX_SYNC_OFFLINE = exports.LOG_PREFIX_SYNC_MANAGER = exports.LOG_PREFIX_SYNC = exports.LOG_PREFIX_ENGINE_VALUE = exports.LOG_PREFIX_ENGINE_MATCHER = exports.LOG_PREFIX_ENGINE_COMBINER = exports.LOG_PREFIX_ENGINE = exports.LOG_PREFIX_INSTANTIATION = exports.LOG_PREFIX_SETTINGS = exports.ERROR_STORAGE_INVALID = exports.ERROR_LOCALHOST_MODULE_REQUIRED = exports.ERROR_HTTP = exports.ERROR_INVALID_IMPRESSIONS_MODE = exports.ERROR_EMPTY_ARRAY = exports.ERROR_EMPTY = exports.ERROR_INVALID = exports.ERROR_INVALID_KEY_OBJECT = exports.ERROR_TOO_LONG = exports.ERROR_NULL = exports.ERROR_CLIENT_DESTROYED = exports.ERROR_NOT_FINITE = exports.ERROR_SIZE_EXCEEDED = exports.ERROR_NOT_PLAIN_OBJECT = exports.ERROR_EVENT_TYPE_FORMAT = exports.ERROR_EVENTS_TRACKER = exports.ERROR_IMPRESSIONS_LISTENER = exports.ERROR_IMPRESSIONS_TRACKER = exports.ERROR_STREAMING_AUTH = exports.ERROR_STREAMING_SSE = exports.ERROR_SYNC_OFFLINE_LOADING = exports.ERROR_CLIENT_CANNOT_GET_READY = exports.ERROR_CLIENT_LISTENER = exports.ERROR_LOGLEVEL_INVALID = exports.ERROR_ENGINE_COMBINER_IFELSEIF = exports.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = exports.WARN_API_KEY = exports.WARN_SPLITS_FILTER_EMPTY = exports.WARN_SPLITS_FILTER_INVALID = exports.WARN_SPLITS_FILTER_IGNORED = exports.WARN_INTEGRATION_INVALID = exports.WARN_NOT_EXISTENT_TT = exports.WARN_LOWERCASE_TRAFFIC_TYPE = exports.WARN_NOT_EXISTENT_SPLIT = exports.WARN_TRIMMING = exports.WARN_CONVERTING = exports.WARN_TRIMMING_PROPERTIES = exports.WARN_SETTING_NULL = exports.SUBMITTERS_PUSH_RETRY = exports.SUBMITTERS_PUSH_FAILS = exports.STREAMING_FALLBACK = exports.STREAMING_PARSING_MESSAGE_FAILS = exports.STREAMING_PARSING_ERROR_FAILS = exports.SYNC_SPLITS_FETCH_FAILS = exports.SYNC_MYSEGMENTS_FETCH_RETRY = exports.CLIENT_NOT_READY = exports.CLIENT_NO_LISTENER = exports.ENGINE_VALUE_NO_ATTRIBUTES = exports.ENGINE_VALUE_INVALID = exports.IMPRESSIONS_TRACKER_SUCCESS = exports.EVENTS_TRACKER_SUCCESS = exports.SYNC_STOP_POLLING = exports.SYNC_CONTINUE_POLLING = exports.SYNC_START_POLLING = exports.SUBMITTERS_PUSH = exports.SUBMITTERS_PUSH_FULL_EVENTS_QUEUE = exports.STREAMING_DISCONNECTING = exports.STREAMING_DISABLED = exports.STREAMING_CONNECTING = exports.STREAMING_RECONNECT = exports.STREAMING_REFRESH_TOKEN = exports.SYNC_SPLITS_FETCH_RETRY = exports.POLLING_STOP = exports.POLLING_START = exports.POLLING_SMART_PAUSING = exports.NEW_FACTORY = exports.NEW_SHARED_CLIENT = exports.IMPRESSION_QUEUEING = exports.IMPRESSION = exports.CLIENT_READY = exports.CLIENT_READY_FROM_CACHE = exports.SETTINGS_SPLITS_FILTER = exports.SYNC_TASK_STOP = exports.SYNC_TASK_EXECUTE = exports.SYNC_TASK_START = exports.STREAMING_NEW_MESSAGE = exports.SYNC_SPLITS_SEGMENTS = exports.SYNC_SPLITS_REMOVED = exports.SYNC_SPLITS_NEW = exports.SYNC_SPLITS_FETCH = exports.SYNC_OFFLINE_DATA = exports.RETRIEVE_MANAGER = exports.RETRIEVE_CLIENT_EXISTING = exports.RETRIEVE_CLIENT_DEFAULT = exports.CLEANUP_DEREGISTERING = exports.CLEANUP_REGISTERING = exports.ENGINE_SANITIZE = exports.ENGINE_VALUE = exports.ENGINE_MATCHER_WHITELIST = exports.ENGINE_MATCHER_STARTS_WITH = exports.ENGINE_MATCHER_STRING_INVALID = exports.ENGINE_MATCHER_STRING = exports.ENGINE_MATCHER_SEGMENT = exports.ENGINE_MATCHER_PART_OF = exports.ENGINE_MATCHER_LESS = exports.ENGINE_MATCHER_GREATER = exports.ENGINE_MATCHER_ENDS_WITH = exports.ENGINE_MATCHER_EQUAL_TO_SET = exports.ENGINE_MATCHER_EQUAL = exports.ENGINE_MATCHER_DEPENDENCY_PRE = exports.ENGINE_MATCHER_DEPENDENCY = exports.ENGINE_MATCHER_CONTAINS_STRING = exports.ENGINE_MATCHER_CONTAINS_ANY = exports.ENGINE_MATCHER_CONTAINS_ALL = exports.ENGINE_MATCHER_BOOLEAN = exports.ENGINE_MATCHER_BETWEEN = exports.ENGINE_MATCHER_ALL = exports.ENGINE_BUCKET = exports.ENGINE_COMBINER_IFELSEIF_NO_TREATMENT = exports.ENGINE_COMBINER_IFELSEIF = exports.ENGINE_COMBINER_AND = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Message codes used to trim string log messages from commons and client-side API modules,
|
|
6
6
|
* in order to reduce the minimal SDK size for Browser and eventually other client-side environments.
|
|
@@ -92,9 +92,8 @@ exports.WARN_INTEGRATION_INVALID = 218;
|
|
|
92
92
|
exports.WARN_SPLITS_FILTER_IGNORED = 219;
|
|
93
93
|
exports.WARN_SPLITS_FILTER_INVALID = 220;
|
|
94
94
|
exports.WARN_SPLITS_FILTER_EMPTY = 221;
|
|
95
|
-
exports.
|
|
96
|
-
exports.
|
|
97
|
-
exports.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 224;
|
|
95
|
+
exports.WARN_API_KEY = 222;
|
|
96
|
+
exports.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 223;
|
|
98
97
|
exports.ERROR_ENGINE_COMBINER_IFELSEIF = 300;
|
|
99
98
|
exports.ERROR_LOGLEVEL_INVALID = 301;
|
|
100
99
|
exports.ERROR_CLIENT_LISTENER = 302;
|
|
@@ -119,6 +118,7 @@ exports.ERROR_EMPTY_ARRAY = 320;
|
|
|
119
118
|
exports.ERROR_INVALID_IMPRESSIONS_MODE = 321;
|
|
120
119
|
exports.ERROR_HTTP = 322;
|
|
121
120
|
exports.ERROR_LOCALHOST_MODULE_REQUIRED = 323;
|
|
121
|
+
exports.ERROR_STORAGE_INVALID = 324;
|
|
122
122
|
// Log prefixes (a.k.a. tags or categories)
|
|
123
123
|
exports.LOG_PREFIX_SETTINGS = 'settings';
|
|
124
124
|
exports.LOG_PREFIX_INSTANTIATION = 'Factory instantiation';
|
|
@@ -33,5 +33,6 @@ exports.codesError = [
|
|
|
33
33
|
[c.ERROR_EMPTY_ARRAY, '%s: %s must be a non-empty array.'],
|
|
34
34
|
// initialization / settings validation
|
|
35
35
|
[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.'],
|
|
36
|
-
[c.ERROR_LOCALHOST_MODULE_REQUIRED, c.LOG_PREFIX_SETTINGS + ': an invalid value was received for "sync.localhostMode" config. A valid entity should be provided for localhost mode.']
|
|
36
|
+
[c.ERROR_LOCALHOST_MODULE_REQUIRED, c.LOG_PREFIX_SETTINGS + ': an invalid value was received for "sync.localhostMode" config. A valid entity should be provided for localhost mode.'],
|
|
37
|
+
[c.ERROR_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS + ': The provided storage is invalid.%s Fallbacking into default MEMORY storage'],
|
|
37
38
|
];
|
|
@@ -32,7 +32,6 @@ exports.codesWarn = error_1.codesError.concat([
|
|
|
32
32
|
[c.WARN_SPLITS_FILTER_IGNORED, c.LOG_PREFIX_SETTINGS + ': split filters have been configured but will have no effect if mode is not "%s", since synchronization is being deferred to an external tool.'],
|
|
33
33
|
[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".'],
|
|
34
34
|
[c.WARN_SPLITS_FILTER_EMPTY, c.LOG_PREFIX_SETTINGS + ': splitFilters configuration must be a non-empty array of filter objects.'],
|
|
35
|
-
[c.WARN_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS + ': The provided storage is invalid. Fallbacking into default MEMORY storage'],
|
|
36
35
|
[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'],
|
|
37
36
|
[c.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching MySegments due to an error processing %s notification: %s'],
|
|
38
37
|
]);
|
package/cjs/sdkFactory/index.js
CHANGED
|
@@ -31,7 +31,7 @@ function sdkFactory(params) {
|
|
|
31
31
|
// ATM, only used by InLocalStorage
|
|
32
32
|
matchingKey: key_1.getMatching(settings.core.key),
|
|
33
33
|
splitFiltersValidation: settings.sync.__splitFiltersValidation,
|
|
34
|
-
// ATM, only used by
|
|
34
|
+
// ATM, only used by PluggableStorage
|
|
35
35
|
mode: settings.mode,
|
|
36
36
|
// Callback used to emit SDK_READY in consumer mode, where `syncManagerFactory` is undefined
|
|
37
37
|
// or only instantiates submitters, and therefore it is not able to emit readiness events.
|
|
@@ -25,8 +25,7 @@ function InRedisStorage(options) {
|
|
|
25
25
|
var redisClient = new RedisAdapter_1.default(log, options.options || {});
|
|
26
26
|
// subscription to Redis connect event in order to emit SDK_READY event on consumer mode
|
|
27
27
|
redisClient.on('connect', function () {
|
|
28
|
-
|
|
29
|
-
onReadyCb();
|
|
28
|
+
onReadyCb();
|
|
30
29
|
});
|
|
31
30
|
return {
|
|
32
31
|
splits: new SplitsCacheInRedis_1.default(log, keys, redisClient),
|
|
@@ -11,7 +11,7 @@ var AbstractSplitsCacheAsync_1 = tslib_1.__importDefault(require("../AbstractSpl
|
|
|
11
11
|
var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
12
12
|
tslib_1.__extends(SplitsCachePluggable, _super);
|
|
13
13
|
/**
|
|
14
|
-
* Create a SplitsCache that uses a
|
|
14
|
+
* Create a SplitsCache that uses a storage wrapper.
|
|
15
15
|
* @param log Logger instance.
|
|
16
16
|
* @param keys Key builder.
|
|
17
17
|
* @param wrapper Adapted wrapper storage.
|
|
@@ -4,7 +4,7 @@ exports.inMemoryWrapperFactory = void 0;
|
|
|
4
4
|
var lang_1 = require("../../utils/lang");
|
|
5
5
|
var sets_1 = require("../../utils/lang/sets");
|
|
6
6
|
/**
|
|
7
|
-
* Creates a
|
|
7
|
+
* Creates a IPluggableStorageWrapper implementation that stores items in memory.
|
|
8
8
|
* The `_cache` property is the object were items are stored.
|
|
9
9
|
* Intended for testing purposes.
|
|
10
10
|
*
|
|
@@ -120,7 +120,7 @@ function inMemoryWrapperFactory(connDelay) {
|
|
|
120
120
|
return Promise.resolve(sets_1.setToArray(set));
|
|
121
121
|
return Promise.reject('key is not a set');
|
|
122
122
|
},
|
|
123
|
-
// always connects and
|
|
123
|
+
// always connects and disconnects
|
|
124
124
|
connect: function () {
|
|
125
125
|
if (typeof _connDelay === 'number') {
|
|
126
126
|
return new Promise(function (res) { return setTimeout(res, _connDelay); });
|
|
@@ -129,7 +129,7 @@ function inMemoryWrapperFactory(connDelay) {
|
|
|
129
129
|
return Promise.resolve();
|
|
130
130
|
}
|
|
131
131
|
},
|
|
132
|
-
|
|
132
|
+
disconnect: function () { return Promise.resolve(); },
|
|
133
133
|
// for testing
|
|
134
134
|
_setConnDelay: function (connDelay) {
|
|
135
135
|
_connDelay = connDelay;
|
|
@@ -14,7 +14,7 @@ var constants_1 = require("../../utils/constants");
|
|
|
14
14
|
var ImpressionsCacheInMemory_1 = tslib_1.__importDefault(require("../inMemory/ImpressionsCacheInMemory"));
|
|
15
15
|
var EventsCacheInMemory_1 = tslib_1.__importDefault(require("../inMemory/EventsCacheInMemory"));
|
|
16
16
|
var ImpressionCountsCacheInMemory_1 = tslib_1.__importDefault(require("../inMemory/ImpressionCountsCacheInMemory"));
|
|
17
|
-
var NO_VALID_WRAPPER = 'Expecting
|
|
17
|
+
var NO_VALID_WRAPPER = 'Expecting pluggable storage `wrapper` in options, but no valid wrapper instance was provided.';
|
|
18
18
|
var NO_VALID_WRAPPER_INTERFACE = 'The provided wrapper instance doesn’t follow the expected interface. Check our docs.';
|
|
19
19
|
/**
|
|
20
20
|
* Validate pluggable storage factory options.
|
|
@@ -58,7 +58,7 @@ function PluggableStorage(options) {
|
|
|
58
58
|
var keys = new KeyBuilderSS_1.default(prefix, metadata);
|
|
59
59
|
var wrapper = wrapperAdapter_1.wrapperAdapter(log, options.wrapper);
|
|
60
60
|
var isPartialConsumer = mode === constants_1.CONSUMER_PARTIAL_MODE;
|
|
61
|
-
//
|
|
61
|
+
// Connects to wrapper and emits SDK_READY event on main client
|
|
62
62
|
wrapperConnect(wrapper, onReadyCb);
|
|
63
63
|
return {
|
|
64
64
|
splits: new SplitsCachePluggable_1.SplitsCachePluggable(log, keys, wrapper),
|
|
@@ -67,20 +67,20 @@ function PluggableStorage(options) {
|
|
|
67
67
|
impressionCounts: optimize ? new ImpressionCountsCacheInMemory_1.default() : undefined,
|
|
68
68
|
events: isPartialConsumer ? promisifyEventsTrack(new EventsCacheInMemory_1.default(eventsQueueSize)) : new EventsCachePluggable_1.EventsCachePluggable(log, keys.buildEventsKey(), wrapper, metadata),
|
|
69
69
|
// @TODO add telemetry cache when required
|
|
70
|
-
// Disconnect the underlying storage
|
|
70
|
+
// Disconnect the underlying storage
|
|
71
71
|
destroy: function () {
|
|
72
|
-
return wrapper.
|
|
72
|
+
return wrapper.disconnect();
|
|
73
73
|
},
|
|
74
74
|
// emits SDK_READY event on shared clients and returns a reference to the storage
|
|
75
75
|
shared: function (_, onReadyCb) {
|
|
76
76
|
wrapperConnect(wrapper, onReadyCb);
|
|
77
77
|
return tslib_1.__assign(tslib_1.__assign({}, this), {
|
|
78
|
-
// no-op destroy, to
|
|
78
|
+
// no-op destroy, to disconnect the wrapper only when the main client is destroyed
|
|
79
79
|
destroy: function () { } });
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
PluggableStorageFactory.type = constants_1.
|
|
83
|
+
PluggableStorageFactory.type = constants_1.STORAGE_PLUGGABLE;
|
|
84
84
|
return PluggableStorageFactory;
|
|
85
85
|
}
|
|
86
86
|
exports.PluggableStorage = PluggableStorage;
|
|
@@ -19,14 +19,14 @@ exports.METHODS_TO_PROMISE_WRAP = [
|
|
|
19
19
|
'removeItems',
|
|
20
20
|
'getItems',
|
|
21
21
|
'connect',
|
|
22
|
-
'
|
|
22
|
+
'disconnect'
|
|
23
23
|
];
|
|
24
24
|
/**
|
|
25
|
-
* Adapter of the
|
|
25
|
+
* Adapter of the Pluggable Storage Wrapper.
|
|
26
26
|
* Used to handle exceptions as rejected promises, in order to simplify the error handling on storages.
|
|
27
27
|
*
|
|
28
28
|
* @param log logger instance
|
|
29
|
-
* @param wrapper
|
|
29
|
+
* @param wrapper storage wrapper to adapt
|
|
30
30
|
* @returns an adapted version of the given storage wrapper
|
|
31
31
|
*/
|
|
32
32
|
function wrapperAdapter(log, wrapper) {
|
|
@@ -23,7 +23,7 @@ function mySegmentsUpdaterFactory(log, mySegmentsFetcher, splitsCache, mySegment
|
|
|
23
23
|
// NOTE: We only collect metrics on startup.
|
|
24
24
|
// mySegmentsPromise = tracker.start(tracker.TaskNames.MY_SEGMENTS_FETCH, startingUp ? metricCollectors : false, mySegmentsPromise);
|
|
25
25
|
}
|
|
26
|
-
// @TODO if allowing
|
|
26
|
+
// @TODO if allowing pluggable storages, handle async execution
|
|
27
27
|
function updateSegments(segmentsData) {
|
|
28
28
|
var shouldNotifyUpdate;
|
|
29
29
|
if (Array.isArray(segmentsData)) {
|
|
@@ -70,7 +70,6 @@ var SplitsUpdateWorker = /** @class */ (function () {
|
|
|
70
70
|
*/
|
|
71
71
|
SplitsUpdateWorker.prototype.killSplit = function (_a) {
|
|
72
72
|
var changeNumber = _a.changeNumber, splitName = _a.splitName, defaultTreatment = _a.defaultTreatment;
|
|
73
|
-
// @TODO handle retry due to errors in storage, once we allow the definition of custom async storages
|
|
74
73
|
if (this.splitsCache.killLocally(splitName, defaultTreatment, changeNumber)) {
|
|
75
74
|
// trigger an SDK_UPDATE if Split was killed locally
|
|
76
75
|
this.splitsEventEmitter.emit(constants_1.SDK_SPLITS_ARRIVED, true);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.STORAGE_PLUGGABLE = exports.STORAGE_REDIS = exports.STORAGE_LOCALSTORAGE = exports.STORAGE_MEMORY = exports.CONSUMER_PARTIAL_MODE = exports.CONSUMER_MODE = exports.PRODUCER_MODE = exports.STANDALONE_MODE = exports.LOCALHOST_MODE = exports.OPTIMIZED = exports.DEBUG = exports.SPLIT_EVENT = exports.SPLIT_IMPRESSION = exports.NA = exports.UNKNOWN = exports.CONTROL_WITH_CONFIG = exports.CONTROL = void 0;
|
|
4
4
|
// Special treatments
|
|
5
5
|
exports.CONTROL = 'control';
|
|
6
6
|
exports.CONTROL_WITH_CONFIG = {
|
|
@@ -26,4 +26,4 @@ exports.CONSUMER_PARTIAL_MODE = 'consumer_partial';
|
|
|
26
26
|
exports.STORAGE_MEMORY = 'MEMORY';
|
|
27
27
|
exports.STORAGE_LOCALSTORAGE = 'LOCALSTORAGE';
|
|
28
28
|
exports.STORAGE_REDIS = 'REDIS';
|
|
29
|
-
exports.
|
|
29
|
+
exports.STORAGE_PLUGGABLE = 'PLUGGABLE';
|
|
@@ -16,29 +16,32 @@ __InLocalStorageMockFactory.type = constants_2.STORAGE_MEMORY;
|
|
|
16
16
|
*
|
|
17
17
|
* @param {any} settings config object provided by the user to initialize the sdk
|
|
18
18
|
*
|
|
19
|
-
* @returns {Object} valid storage factory.
|
|
19
|
+
* @returns {Object} valid storage factory. Default to `InMemoryStorageCSFactory` if the provided storage is invalid or not compatible with the sdk mode if mode is standalone or localhost
|
|
20
|
+
*
|
|
21
|
+
* @throws error if mode is consumer and the provided storage is not compatible
|
|
20
22
|
*/
|
|
21
23
|
function validateStorageCS(settings) {
|
|
22
24
|
var _a = settings.storage, storage = _a === void 0 ? InMemoryStorageCS_1.InMemoryStorageCSFactory : _a, log = settings.log, mode = settings.mode;
|
|
23
25
|
// If an invalid storage is provided, fallback into MEMORY
|
|
24
|
-
if (typeof storage !== 'function' || [constants_2.STORAGE_MEMORY, constants_2.STORAGE_LOCALSTORAGE, constants_2.
|
|
26
|
+
if (typeof storage !== 'function' || [constants_2.STORAGE_MEMORY, constants_2.STORAGE_LOCALSTORAGE, constants_2.STORAGE_PLUGGABLE].indexOf(storage.type) === -1) {
|
|
25
27
|
storage = InMemoryStorageCS_1.InMemoryStorageCSFactory;
|
|
26
|
-
log.
|
|
28
|
+
log.error(constants_1.ERROR_STORAGE_INVALID);
|
|
27
29
|
}
|
|
28
30
|
// In localhost mode with InLocalStorage, fallback to a mock InLocalStorage to emit SDK_READY_FROM_CACHE
|
|
29
31
|
if (mode === constants_2.LOCALHOST_MODE && storage.type === constants_2.STORAGE_LOCALSTORAGE) {
|
|
30
32
|
return __InLocalStorageMockFactory;
|
|
31
33
|
}
|
|
32
|
-
// @TODO check behaviour
|
|
33
34
|
if ([constants_2.LOCALHOST_MODE, constants_2.STANDALONE_MODE].indexOf(mode) === -1) {
|
|
34
35
|
// Consumer modes require an async storage
|
|
35
|
-
if (storage.type !== constants_2.
|
|
36
|
-
throw new Error('A
|
|
36
|
+
if (storage.type !== constants_2.STORAGE_PLUGGABLE)
|
|
37
|
+
throw new Error('A PluggableStorage instance is required on consumer mode');
|
|
37
38
|
}
|
|
38
39
|
else {
|
|
39
40
|
// Standalone and localhost modes require a sync storage
|
|
40
|
-
if (storage.type === constants_2.
|
|
41
|
-
|
|
41
|
+
if (storage.type === constants_2.STORAGE_PLUGGABLE) {
|
|
42
|
+
storage = InMemoryStorageCS_1.InMemoryStorageCSFactory;
|
|
43
|
+
log.error(constants_1.ERROR_STORAGE_INVALID, [' It requires consumer mode.']);
|
|
44
|
+
}
|
|
42
45
|
}
|
|
43
46
|
// return default InMemory storage if provided one is not valid
|
|
44
47
|
return storage;
|
package/esm/logger/constants.js
CHANGED
|
@@ -89,9 +89,8 @@ export var WARN_INTEGRATION_INVALID = 218;
|
|
|
89
89
|
export var WARN_SPLITS_FILTER_IGNORED = 219;
|
|
90
90
|
export var WARN_SPLITS_FILTER_INVALID = 220;
|
|
91
91
|
export var WARN_SPLITS_FILTER_EMPTY = 221;
|
|
92
|
-
export var
|
|
93
|
-
export var
|
|
94
|
-
export var STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 224;
|
|
92
|
+
export var WARN_API_KEY = 222;
|
|
93
|
+
export var STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 223;
|
|
95
94
|
export var ERROR_ENGINE_COMBINER_IFELSEIF = 300;
|
|
96
95
|
export var ERROR_LOGLEVEL_INVALID = 301;
|
|
97
96
|
export var ERROR_CLIENT_LISTENER = 302;
|
|
@@ -116,6 +115,7 @@ export var ERROR_EMPTY_ARRAY = 320;
|
|
|
116
115
|
export var ERROR_INVALID_IMPRESSIONS_MODE = 321;
|
|
117
116
|
export var ERROR_HTTP = 322;
|
|
118
117
|
export var ERROR_LOCALHOST_MODULE_REQUIRED = 323;
|
|
118
|
+
export var ERROR_STORAGE_INVALID = 324;
|
|
119
119
|
// Log prefixes (a.k.a. tags or categories)
|
|
120
120
|
export var LOG_PREFIX_SETTINGS = 'settings';
|
|
121
121
|
export var LOG_PREFIX_INSTANTIATION = 'Factory instantiation';
|
|
@@ -29,5 +29,6 @@ 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 + ': an invalid value was received for "sync.localhostMode" config. A valid entity should be provided for localhost mode.']
|
|
32
|
+
[c.ERROR_LOCALHOST_MODULE_REQUIRED, c.LOG_PREFIX_SETTINGS + ': an invalid value was received for "sync.localhostMode" config. A valid entity should be provided for localhost mode.'],
|
|
33
|
+
[c.ERROR_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS + ': The provided storage is invalid.%s Fallbacking into default MEMORY storage'],
|
|
33
34
|
];
|
|
@@ -28,7 +28,6 @@ export var codesWarn = codesError.concat([
|
|
|
28
28
|
[c.WARN_SPLITS_FILTER_IGNORED, c.LOG_PREFIX_SETTINGS + ': split filters have been configured but will have no effect if mode is not "%s", since synchronization is being deferred to an external tool.'],
|
|
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
|
-
[c.WARN_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS + ': The provided storage is invalid. Fallbacking into default MEMORY storage'],
|
|
32
31
|
[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
32
|
[c.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching MySegments due to an error processing %s notification: %s'],
|
|
34
33
|
]);
|
package/esm/sdkFactory/index.js
CHANGED
|
@@ -27,7 +27,7 @@ export function sdkFactory(params) {
|
|
|
27
27
|
// ATM, only used by InLocalStorage
|
|
28
28
|
matchingKey: getMatching(settings.core.key),
|
|
29
29
|
splitFiltersValidation: settings.sync.__splitFiltersValidation,
|
|
30
|
-
// ATM, only used by
|
|
30
|
+
// ATM, only used by PluggableStorage
|
|
31
31
|
mode: settings.mode,
|
|
32
32
|
// Callback used to emit SDK_READY in consumer mode, where `syncManagerFactory` is undefined
|
|
33
33
|
// or only instantiates submitters, and therefore it is not able to emit readiness events.
|
|
@@ -21,8 +21,7 @@ export function InRedisStorage(options) {
|
|
|
21
21
|
var redisClient = new RedisAdapter(log, options.options || {});
|
|
22
22
|
// subscription to Redis connect event in order to emit SDK_READY event on consumer mode
|
|
23
23
|
redisClient.on('connect', function () {
|
|
24
|
-
|
|
25
|
-
onReadyCb();
|
|
24
|
+
onReadyCb();
|
|
26
25
|
});
|
|
27
26
|
return {
|
|
28
27
|
splits: new SplitsCacheInRedis(log, keys, redisClient),
|
|
@@ -8,7 +8,7 @@ import AbstractSplitsCacheAsync from '../AbstractSplitsCacheAsync';
|
|
|
8
8
|
var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
9
9
|
__extends(SplitsCachePluggable, _super);
|
|
10
10
|
/**
|
|
11
|
-
* Create a SplitsCache that uses a
|
|
11
|
+
* Create a SplitsCache that uses a storage wrapper.
|
|
12
12
|
* @param log Logger instance.
|
|
13
13
|
* @param keys Key builder.
|
|
14
14
|
* @param wrapper Adapted wrapper storage.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { startsWith, toNumber } from '../../utils/lang';
|
|
2
2
|
import { setToArray, _Set } from '../../utils/lang/sets';
|
|
3
3
|
/**
|
|
4
|
-
* Creates a
|
|
4
|
+
* Creates a IPluggableStorageWrapper implementation that stores items in memory.
|
|
5
5
|
* The `_cache` property is the object were items are stored.
|
|
6
6
|
* Intended for testing purposes.
|
|
7
7
|
*
|
|
@@ -117,7 +117,7 @@ export function inMemoryWrapperFactory(connDelay) {
|
|
|
117
117
|
return Promise.resolve(setToArray(set));
|
|
118
118
|
return Promise.reject('key is not a set');
|
|
119
119
|
},
|
|
120
|
-
// always connects and
|
|
120
|
+
// always connects and disconnects
|
|
121
121
|
connect: function () {
|
|
122
122
|
if (typeof _connDelay === 'number') {
|
|
123
123
|
return new Promise(function (res) { return setTimeout(res, _connDelay); });
|
|
@@ -126,7 +126,7 @@ export function inMemoryWrapperFactory(connDelay) {
|
|
|
126
126
|
return Promise.resolve();
|
|
127
127
|
}
|
|
128
128
|
},
|
|
129
|
-
|
|
129
|
+
disconnect: function () { return Promise.resolve(); },
|
|
130
130
|
// for testing
|
|
131
131
|
_setConnDelay: function (connDelay) {
|
|
132
132
|
_connDelay = connDelay;
|
|
@@ -7,11 +7,11 @@ import { EventsCachePluggable } from './EventsCachePluggable';
|
|
|
7
7
|
import { wrapperAdapter, METHODS_TO_PROMISE_WRAP } from './wrapperAdapter';
|
|
8
8
|
import { isObject } from '../../utils/lang';
|
|
9
9
|
import { validatePrefix } from '../KeyBuilder';
|
|
10
|
-
import { CONSUMER_PARTIAL_MODE,
|
|
10
|
+
import { CONSUMER_PARTIAL_MODE, STORAGE_PLUGGABLE } from '../../utils/constants';
|
|
11
11
|
import ImpressionsCacheInMemory from '../inMemory/ImpressionsCacheInMemory';
|
|
12
12
|
import EventsCacheInMemory from '../inMemory/EventsCacheInMemory';
|
|
13
13
|
import ImpressionCountsCacheInMemory from '../inMemory/ImpressionCountsCacheInMemory';
|
|
14
|
-
var NO_VALID_WRAPPER = 'Expecting
|
|
14
|
+
var NO_VALID_WRAPPER = 'Expecting pluggable storage `wrapper` in options, but no valid wrapper instance was provided.';
|
|
15
15
|
var NO_VALID_WRAPPER_INTERFACE = 'The provided wrapper instance doesn’t follow the expected interface. Check our docs.';
|
|
16
16
|
/**
|
|
17
17
|
* Validate pluggable storage factory options.
|
|
@@ -55,7 +55,7 @@ export function PluggableStorage(options) {
|
|
|
55
55
|
var keys = new KeyBuilderSS(prefix, metadata);
|
|
56
56
|
var wrapper = wrapperAdapter(log, options.wrapper);
|
|
57
57
|
var isPartialConsumer = mode === CONSUMER_PARTIAL_MODE;
|
|
58
|
-
//
|
|
58
|
+
// Connects to wrapper and emits SDK_READY event on main client
|
|
59
59
|
wrapperConnect(wrapper, onReadyCb);
|
|
60
60
|
return {
|
|
61
61
|
splits: new SplitsCachePluggable(log, keys, wrapper),
|
|
@@ -64,19 +64,19 @@ export function PluggableStorage(options) {
|
|
|
64
64
|
impressionCounts: optimize ? new ImpressionCountsCacheInMemory() : undefined,
|
|
65
65
|
events: isPartialConsumer ? promisifyEventsTrack(new EventsCacheInMemory(eventsQueueSize)) : new EventsCachePluggable(log, keys.buildEventsKey(), wrapper, metadata),
|
|
66
66
|
// @TODO add telemetry cache when required
|
|
67
|
-
// Disconnect the underlying storage
|
|
67
|
+
// Disconnect the underlying storage
|
|
68
68
|
destroy: function () {
|
|
69
|
-
return wrapper.
|
|
69
|
+
return wrapper.disconnect();
|
|
70
70
|
},
|
|
71
71
|
// emits SDK_READY event on shared clients and returns a reference to the storage
|
|
72
72
|
shared: function (_, onReadyCb) {
|
|
73
73
|
wrapperConnect(wrapper, onReadyCb);
|
|
74
74
|
return __assign(__assign({}, this), {
|
|
75
|
-
// no-op destroy, to
|
|
75
|
+
// no-op destroy, to disconnect the wrapper only when the main client is destroyed
|
|
76
76
|
destroy: function () { } });
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
-
PluggableStorageFactory.type =
|
|
80
|
+
PluggableStorageFactory.type = STORAGE_PLUGGABLE;
|
|
81
81
|
return PluggableStorageFactory;
|
|
82
82
|
}
|
|
@@ -16,14 +16,14 @@ export var METHODS_TO_PROMISE_WRAP = [
|
|
|
16
16
|
'removeItems',
|
|
17
17
|
'getItems',
|
|
18
18
|
'connect',
|
|
19
|
-
'
|
|
19
|
+
'disconnect'
|
|
20
20
|
];
|
|
21
21
|
/**
|
|
22
|
-
* Adapter of the
|
|
22
|
+
* Adapter of the Pluggable Storage Wrapper.
|
|
23
23
|
* Used to handle exceptions as rejected promises, in order to simplify the error handling on storages.
|
|
24
24
|
*
|
|
25
25
|
* @param log logger instance
|
|
26
|
-
* @param wrapper
|
|
26
|
+
* @param wrapper storage wrapper to adapt
|
|
27
27
|
* @returns an adapted version of the given storage wrapper
|
|
28
28
|
*/
|
|
29
29
|
export function wrapperAdapter(log, wrapper) {
|
|
@@ -19,7 +19,7 @@ export function mySegmentsUpdaterFactory(log, mySegmentsFetcher, splitsCache, my
|
|
|
19
19
|
// NOTE: We only collect metrics on startup.
|
|
20
20
|
// mySegmentsPromise = tracker.start(tracker.TaskNames.MY_SEGMENTS_FETCH, startingUp ? metricCollectors : false, mySegmentsPromise);
|
|
21
21
|
}
|
|
22
|
-
// @TODO if allowing
|
|
22
|
+
// @TODO if allowing pluggable storages, handle async execution
|
|
23
23
|
function updateSegments(segmentsData) {
|
|
24
24
|
var shouldNotifyUpdate;
|
|
25
25
|
if (Array.isArray(segmentsData)) {
|
|
@@ -67,7 +67,6 @@ var SplitsUpdateWorker = /** @class */ (function () {
|
|
|
67
67
|
*/
|
|
68
68
|
SplitsUpdateWorker.prototype.killSplit = function (_a) {
|
|
69
69
|
var changeNumber = _a.changeNumber, splitName = _a.splitName, defaultTreatment = _a.defaultTreatment;
|
|
70
|
-
// @TODO handle retry due to errors in storage, once we allow the definition of custom async storages
|
|
71
70
|
if (this.splitsCache.killLocally(splitName, defaultTreatment, changeNumber)) {
|
|
72
71
|
// trigger an SDK_UPDATE if Split was killed locally
|
|
73
72
|
this.splitsEventEmitter.emit(SDK_SPLITS_ARRIVED, true);
|
|
@@ -23,4 +23,4 @@ export var CONSUMER_PARTIAL_MODE = 'consumer_partial';
|
|
|
23
23
|
export var STORAGE_MEMORY = 'MEMORY';
|
|
24
24
|
export var STORAGE_LOCALSTORAGE = 'LOCALSTORAGE';
|
|
25
25
|
export var STORAGE_REDIS = 'REDIS';
|
|
26
|
-
export var
|
|
26
|
+
export var STORAGE_PLUGGABLE = 'PLUGGABLE';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { InMemoryStorageCSFactory } from '../../../storages/inMemory/InMemoryStorageCS';
|
|
2
|
-
import {
|
|
3
|
-
import { LOCALHOST_MODE, STANDALONE_MODE,
|
|
2
|
+
import { ERROR_STORAGE_INVALID } from '../../../logger/constants';
|
|
3
|
+
import { LOCALHOST_MODE, STANDALONE_MODE, STORAGE_PLUGGABLE, STORAGE_LOCALSTORAGE, STORAGE_MEMORY } from '../../../utils/constants';
|
|
4
4
|
export function __InLocalStorageMockFactory(params) {
|
|
5
5
|
var result = InMemoryStorageCSFactory(params);
|
|
6
6
|
result.splits.checkCache = function () { return true; }; // to emit SDK_READY_FROM_CACHE
|
|
@@ -12,29 +12,32 @@ __InLocalStorageMockFactory.type = STORAGE_MEMORY;
|
|
|
12
12
|
*
|
|
13
13
|
* @param {any} settings config object provided by the user to initialize the sdk
|
|
14
14
|
*
|
|
15
|
-
* @returns {Object} valid storage factory.
|
|
15
|
+
* @returns {Object} valid storage factory. Default to `InMemoryStorageCSFactory` if the provided storage is invalid or not compatible with the sdk mode if mode is standalone or localhost
|
|
16
|
+
*
|
|
17
|
+
* @throws error if mode is consumer and the provided storage is not compatible
|
|
16
18
|
*/
|
|
17
19
|
export function validateStorageCS(settings) {
|
|
18
20
|
var _a = settings.storage, storage = _a === void 0 ? InMemoryStorageCSFactory : _a, log = settings.log, mode = settings.mode;
|
|
19
21
|
// If an invalid storage is provided, fallback into MEMORY
|
|
20
|
-
if (typeof storage !== 'function' || [STORAGE_MEMORY, STORAGE_LOCALSTORAGE,
|
|
22
|
+
if (typeof storage !== 'function' || [STORAGE_MEMORY, STORAGE_LOCALSTORAGE, STORAGE_PLUGGABLE].indexOf(storage.type) === -1) {
|
|
21
23
|
storage = InMemoryStorageCSFactory;
|
|
22
|
-
log.
|
|
24
|
+
log.error(ERROR_STORAGE_INVALID);
|
|
23
25
|
}
|
|
24
26
|
// In localhost mode with InLocalStorage, fallback to a mock InLocalStorage to emit SDK_READY_FROM_CACHE
|
|
25
27
|
if (mode === LOCALHOST_MODE && storage.type === STORAGE_LOCALSTORAGE) {
|
|
26
28
|
return __InLocalStorageMockFactory;
|
|
27
29
|
}
|
|
28
|
-
// @TODO check behaviour
|
|
29
30
|
if ([LOCALHOST_MODE, STANDALONE_MODE].indexOf(mode) === -1) {
|
|
30
31
|
// Consumer modes require an async storage
|
|
31
|
-
if (storage.type !==
|
|
32
|
-
throw new Error('A
|
|
32
|
+
if (storage.type !== STORAGE_PLUGGABLE)
|
|
33
|
+
throw new Error('A PluggableStorage instance is required on consumer mode');
|
|
33
34
|
}
|
|
34
35
|
else {
|
|
35
36
|
// Standalone and localhost modes require a sync storage
|
|
36
|
-
if (storage.type ===
|
|
37
|
-
|
|
37
|
+
if (storage.type === STORAGE_PLUGGABLE) {
|
|
38
|
+
storage = InMemoryStorageCSFactory;
|
|
39
|
+
log.error(ERROR_STORAGE_INVALID, [' It requires consumer mode.']);
|
|
40
|
+
}
|
|
38
41
|
}
|
|
39
42
|
// return default InMemory storage if provided one is not valid
|
|
40
43
|
return storage;
|
package/package.json
CHANGED
package/src/logger/constants.ts
CHANGED
|
@@ -91,9 +91,8 @@ export const WARN_INTEGRATION_INVALID = 218;
|
|
|
91
91
|
export const WARN_SPLITS_FILTER_IGNORED = 219;
|
|
92
92
|
export const WARN_SPLITS_FILTER_INVALID = 220;
|
|
93
93
|
export const WARN_SPLITS_FILTER_EMPTY = 221;
|
|
94
|
-
export const
|
|
95
|
-
export const
|
|
96
|
-
export const STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 224;
|
|
94
|
+
export const WARN_API_KEY = 222;
|
|
95
|
+
export const STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 223;
|
|
97
96
|
|
|
98
97
|
export const ERROR_ENGINE_COMBINER_IFELSEIF = 300;
|
|
99
98
|
export const ERROR_LOGLEVEL_INVALID = 301;
|
|
@@ -119,6 +118,7 @@ export const ERROR_EMPTY_ARRAY = 320;
|
|
|
119
118
|
export const ERROR_INVALID_IMPRESSIONS_MODE = 321;
|
|
120
119
|
export const ERROR_HTTP = 322;
|
|
121
120
|
export const ERROR_LOCALHOST_MODULE_REQUIRED = 323;
|
|
121
|
+
export const ERROR_STORAGE_INVALID = 324;
|
|
122
122
|
|
|
123
123
|
// Log prefixes (a.k.a. tags or categories)
|
|
124
124
|
export const LOG_PREFIX_SETTINGS = 'settings';
|
|
@@ -30,5 +30,6 @@ export const codesError: [number, string][] = [
|
|
|
30
30
|
[c.ERROR_EMPTY_ARRAY, '%s: %s must be a non-empty array.'],
|
|
31
31
|
// initialization / settings validation
|
|
32
32
|
[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.'],
|
|
33
|
-
[c.ERROR_LOCALHOST_MODULE_REQUIRED, c.LOG_PREFIX_SETTINGS + ': an invalid value was received for "sync.localhostMode" config. A valid entity should be provided for localhost mode.']
|
|
33
|
+
[c.ERROR_LOCALHOST_MODULE_REQUIRED, c.LOG_PREFIX_SETTINGS + ': an invalid value was received for "sync.localhostMode" config. A valid entity should be provided for localhost mode.'],
|
|
34
|
+
[c.ERROR_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS+': The provided storage is invalid.%s Fallbacking into default MEMORY storage'],
|
|
34
35
|
];
|
|
@@ -29,7 +29,6 @@ export const codesWarn: [number, string][] = codesError.concat([
|
|
|
29
29
|
[c.WARN_SPLITS_FILTER_IGNORED, c.LOG_PREFIX_SETTINGS+': split filters have been configured but will have no effect if mode is not "%s", since synchronization is being deferred to an external tool.'],
|
|
30
30
|
[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".'],
|
|
31
31
|
[c.WARN_SPLITS_FILTER_EMPTY, c.LOG_PREFIX_SETTINGS+': splitFilters configuration must be a non-empty array of filter objects.'],
|
|
32
|
-
[c.WARN_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS+': The provided storage is invalid. Fallbacking into default MEMORY storage'],
|
|
33
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'],
|
|
34
33
|
|
|
35
34
|
[c.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching MySegments due to an error processing %s notification: %s'],
|
package/src/sdkFactory/index.ts
CHANGED
|
@@ -40,7 +40,7 @@ export function sdkFactory(params: ISdkFactoryParams): SplitIO.ICsSDK | SplitIO.
|
|
|
40
40
|
matchingKey: getMatching(settings.core.key),
|
|
41
41
|
splitFiltersValidation: settings.sync.__splitFiltersValidation,
|
|
42
42
|
|
|
43
|
-
// ATM, only used by
|
|
43
|
+
// ATM, only used by PluggableStorage
|
|
44
44
|
mode: settings.mode,
|
|
45
45
|
|
|
46
46
|
// Callback used to emit SDK_READY in consumer mode, where `syncManagerFactory` is undefined
|
package/src/services/splitApi.ts
CHANGED
|
@@ -16,7 +16,10 @@ function userKeyToQueryParam(userKey: string) {
|
|
|
16
16
|
* @param settings validated settings object
|
|
17
17
|
* @param platform object containing environment-specific `getFetch` and `getOptions` dependencies
|
|
18
18
|
*/
|
|
19
|
-
export function splitApiFactory(
|
|
19
|
+
export function splitApiFactory(
|
|
20
|
+
settings: Pick<ISettings, 'urls' | 'sync' | 'log' | 'version' | 'runtime' | 'core'>,
|
|
21
|
+
platform: Pick<IPlatform, 'getFetch' | 'getOptions'>
|
|
22
|
+
): ISplitApi {
|
|
20
23
|
|
|
21
24
|
const urls = settings.urls;
|
|
22
25
|
const filterQueryString = settings.sync.__splitFiltersValidation && settings.sync.__splitFiltersValidation.queryString;
|
|
@@ -30,7 +30,7 @@ export function InRedisStorage(options: InRedisStorageOptions = {}): IStorageAsy
|
|
|
30
30
|
|
|
31
31
|
// subscription to Redis connect event in order to emit SDK_READY event on consumer mode
|
|
32
32
|
redisClient.on('connect', () => {
|
|
33
|
-
|
|
33
|
+
onReadyCb();
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IPluggableStorageWrapper, IEventsCacheAsync } from '../types';
|
|
2
2
|
import { IMetadata } from '../../dtos/types';
|
|
3
3
|
import { SplitIO } from '../../types';
|
|
4
4
|
import { ILogger } from '../../logger/types';
|
|
@@ -8,11 +8,11 @@ import { StoredEventWithMetadata } from '../../sync/submitters/types';
|
|
|
8
8
|
export class EventsCachePluggable implements IEventsCacheAsync {
|
|
9
9
|
|
|
10
10
|
private readonly log: ILogger;
|
|
11
|
-
private readonly wrapper:
|
|
11
|
+
private readonly wrapper: IPluggableStorageWrapper;
|
|
12
12
|
private readonly key: string;
|
|
13
13
|
private readonly metadata: IMetadata;
|
|
14
14
|
|
|
15
|
-
constructor(log: ILogger, key: string, wrapper:
|
|
15
|
+
constructor(log: ILogger, key: string, wrapper: IPluggableStorageWrapper, metadata: IMetadata) {
|
|
16
16
|
this.log = log;
|
|
17
17
|
this.key = key;
|
|
18
18
|
this.wrapper = wrapper;
|