@splitsoftware/splitio-commons 1.12.1-rc.4 → 1.12.1-rc.6
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/CHANGES.txt +1 -1
- package/cjs/logger/constants.js +3 -3
- package/cjs/logger/messages/warn.js +2 -2
- package/cjs/sdkClient/client.js +11 -8
- package/cjs/sdkClient/clientInputValidation.js +6 -6
- package/cjs/sdkManager/index.js +6 -6
- package/cjs/storages/KeyBuilder.js +13 -1
- package/cjs/storages/KeyBuilderCS.js +1 -4
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +12 -16
- package/cjs/storages/inLocalStorage/index.js +1 -1
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +2 -2
- package/cjs/storages/inRedis/index.js +1 -1
- package/cjs/storages/pluggable/SplitsCachePluggable.js +2 -2
- package/cjs/storages/pluggable/index.js +16 -3
- package/cjs/trackers/eventTracker.js +4 -4
- package/cjs/utils/lang/sets.js +3 -3
- package/cjs/utils/settingsValidation/index.js +1 -1
- package/cjs/utils/settingsValidation/mode.js +10 -3
- package/cjs/utils/settingsValidation/splitFilters.js +20 -19
- package/esm/logger/constants.js +2 -2
- package/esm/logger/messages/warn.js +2 -2
- package/esm/sdkClient/client.js +11 -8
- package/esm/sdkClient/clientInputValidation.js +7 -7
- package/esm/sdkManager/index.js +6 -6
- package/esm/storages/KeyBuilder.js +11 -0
- package/esm/storages/KeyBuilderCS.js +1 -4
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +12 -16
- package/esm/storages/inLocalStorage/index.js +1 -1
- package/esm/storages/inRedis/SplitsCacheInRedis.js +3 -3
- package/esm/storages/inRedis/index.js +1 -1
- package/esm/storages/pluggable/SplitsCachePluggable.js +3 -3
- package/esm/storages/pluggable/index.js +17 -4
- package/esm/trackers/eventTracker.js +4 -4
- package/esm/utils/lang/sets.js +1 -1
- package/esm/utils/settingsValidation/index.js +2 -2
- package/esm/utils/settingsValidation/mode.js +7 -1
- package/esm/utils/settingsValidation/splitFilters.js +11 -10
- package/package.json +1 -1
- package/src/logger/constants.ts +2 -2
- package/src/logger/messages/warn.ts +2 -2
- package/src/sdkClient/client.ts +11 -8
- package/src/sdkClient/clientInputValidation.ts +7 -7
- package/src/sdkManager/index.ts +6 -6
- package/src/storages/KeyBuilder.ts +14 -1
- package/src/storages/KeyBuilderCS.ts +1 -5
- package/src/storages/KeyBuilderSS.ts +4 -4
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +16 -14
- package/src/storages/inLocalStorage/index.ts +1 -1
- package/src/storages/inRedis/SplitsCacheInRedis.ts +3 -3
- package/src/storages/inRedis/index.ts +1 -1
- package/src/storages/pluggable/SplitsCachePluggable.ts +3 -3
- package/src/storages/pluggable/index.ts +17 -5
- package/src/storages/types.ts +3 -3
- package/src/trackers/eventTracker.ts +4 -4
- package/src/utils/lang/sets.ts +1 -1
- package/src/utils/murmur3/murmur3.ts +0 -1
- package/src/utils/settingsValidation/index.ts +2 -2
- package/src/utils/settingsValidation/mode.ts +8 -1
- package/src/utils/settingsValidation/splitFilters.ts +11 -10
- package/types/logger/constants.d.ts +2 -2
- package/types/storages/AbstractSplitsCache.d.ts +46 -0
- package/types/storages/KeyBuilder.d.ts +8 -1
- package/types/storages/KeyBuilderCS.d.ts +0 -1
- package/types/storages/KeyBuilderSS.d.ts +4 -4
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +5 -5
- package/types/utils/lang/sets.d.ts +1 -1
- package/types/utils/settingsValidation/mode.d.ts +5 -1
- package/types/utils/settingsValidation/splitFilters.d.ts +1 -1
- package/cjs/trackers/impressionObserver/utils.js +0 -11
- package/cjs/utils/redis/RedisMock.js +0 -31
- package/esm/trackers/impressionObserver/utils.js +0 -7
- package/esm/utils/redis/RedisMock.js +0 -28
- package/src/trackers/impressionObserver/utils.ts +0 -9
- package/src/utils/redis/RedisMock.ts +0 -31
package/CHANGES.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
1.12.0 (December
|
|
1
|
+
1.12.0 (December 4, 2023)
|
|
2
2
|
- Added support for Flag Sets in "consumer" and "partial consumer" modes for Pluggable and Redis storages.
|
|
3
3
|
- Updated evaluation flow to log a warning when using flag sets that don't contain cached feature flags.
|
|
4
4
|
- Updated Redis adapter to handle timeouts and queueing of some missing commands: 'hincrby', 'popNRaw', and 'pipeline.exec'.
|
package/cjs/logger/constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
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
|
-
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.WARN_FLAGSET_WITHOUT_FLAGS = exports.WARN_FLAGSET_NOT_CONFIGURED = exports.
|
|
4
|
+
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.WARN_FLAGSET_WITHOUT_FLAGS = exports.WARN_FLAGSET_NOT_CONFIGURED = exports.WARN_LOWERCASE_FLAGSET = exports.WARN_INVALID_FLAGSET = exports.STREAMING_PARSING_SPLIT_UPDATE = exports.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = exports.WARN_SDK_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.USER_CONSENT_INITIAL = exports.USER_CONSENT_NOT_UPDATED = exports.USER_CONSENT_UPDATED = 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_QUEUE = exports.STREAMING_DISCONNECTING = exports.STREAMING_DISABLED = exports.STREAMING_CONNECTING = exports.STREAMING_RECONNECT = exports.STREAMING_REFRESH_TOKEN = void 0;
|
|
5
5
|
exports.LOG_PREFIX_CLEANUP = exports.LOG_PREFIX_UNIQUE_KEYS_TRACKER = 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_SETS_FILTER_EXCLUSIVE = exports.ERROR_TOO_MANY_SETS = exports.ERROR_MIN_CONFIG_PARAM = exports.ERROR_NOT_BOOLEAN = exports.ERROR_STORAGE_INVALID = exports.ERROR_LOCALHOST_MODULE_REQUIRED = exports.ERROR_HTTP = exports.ERROR_INVALID_CONFIG_PARAM = 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 = void 0;
|
|
6
6
|
/**
|
|
7
7
|
* Message codes used to trim string log messages from commons and client-side API modules,
|
|
@@ -100,8 +100,8 @@ exports.WARN_SPLITS_FILTER_EMPTY = 221;
|
|
|
100
100
|
exports.WARN_SDK_KEY = 222;
|
|
101
101
|
exports.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 223;
|
|
102
102
|
exports.STREAMING_PARSING_SPLIT_UPDATE = 224;
|
|
103
|
-
exports.
|
|
104
|
-
exports.
|
|
103
|
+
exports.WARN_INVALID_FLAGSET = 225;
|
|
104
|
+
exports.WARN_LOWERCASE_FLAGSET = 226;
|
|
105
105
|
exports.WARN_FLAGSET_NOT_CONFIGURED = 227;
|
|
106
106
|
exports.WARN_FLAGSET_WITHOUT_FLAGS = 228;
|
|
107
107
|
exports.ERROR_ENGINE_COMBINER_IFELSEIF = 300;
|
|
@@ -36,7 +36,7 @@ exports.codesWarn = error_1.codesError.concat([
|
|
|
36
36
|
[c.WARN_SDK_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
37
|
[c.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching MySegments due to an error processing %s notification: %s'],
|
|
38
38
|
[c.STREAMING_PARSING_SPLIT_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching SplitChanges due to an error processing SPLIT_UPDATE notification: %s'],
|
|
39
|
-
[c.
|
|
40
|
-
[c.
|
|
39
|
+
[c.WARN_INVALID_FLAGSET, '%s: you passed %s, flag set must adhere to the regular expressions %s. This means a flag set must start with a letter or number, be in lowercase, alphanumeric and have a max length of 50 characters. %s was discarded.'],
|
|
40
|
+
[c.WARN_LOWERCASE_FLAGSET, '%s: flag set %s should be all lowercase - converting string to lowercase.'],
|
|
41
41
|
[c.WARN_FLAGSET_WITHOUT_FLAGS, '%s: you passed %s flag set that does not contain cached feature flag names. Please double check what flag sets are in use in the Split user interface.'],
|
|
42
42
|
]);
|
package/cjs/sdkClient/client.js
CHANGED
|
@@ -9,7 +9,7 @@ var trafficTypeExistence_1 = require("../utils/inputValidation/trafficTypeExiste
|
|
|
9
9
|
var labels_1 = require("../utils/labels");
|
|
10
10
|
var constants_1 = require("../utils/constants");
|
|
11
11
|
var constants_2 = require("../logger/constants");
|
|
12
|
-
var
|
|
12
|
+
var mode_1 = require("../utils/settingsValidation/mode");
|
|
13
13
|
var treatmentNotReady = { treatment: constants_1.CONTROL, label: labels_1.SDK_NOT_READY };
|
|
14
14
|
function treatmentsNotReady(featureFlagNames) {
|
|
15
15
|
var evaluations = {};
|
|
@@ -24,6 +24,7 @@ function treatmentsNotReady(featureFlagNames) {
|
|
|
24
24
|
function clientFactory(params) {
|
|
25
25
|
var readinessManager = params.sdkReadinessManager.readinessManager, storage = params.storage, settings = params.settings, impressionsTracker = params.impressionsTracker, eventTracker = params.eventTracker, telemetryTracker = params.telemetryTracker;
|
|
26
26
|
var log = settings.log, mode = settings.mode;
|
|
27
|
+
var isAsync = (0, mode_1.isConsumerMode)(mode);
|
|
27
28
|
function getTreatment(key, featureFlagName, attributes, withConfig, methodName) {
|
|
28
29
|
if (withConfig === void 0) { withConfig = false; }
|
|
29
30
|
if (methodName === void 0) { methodName = constants_1.GET_TREATMENT; }
|
|
@@ -37,9 +38,9 @@ function clientFactory(params) {
|
|
|
37
38
|
};
|
|
38
39
|
var evaluation = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
39
40
|
(0, evaluator_1.evaluateFeature)(log, key, featureFlagName, attributes, storage) :
|
|
40
|
-
|
|
41
|
-
treatmentNotReady :
|
|
42
|
-
|
|
41
|
+
isAsync ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
|
|
42
|
+
Promise.resolve(treatmentNotReady) :
|
|
43
|
+
treatmentNotReady;
|
|
43
44
|
return (0, thenable_1.thenable)(evaluation) ? evaluation.then(function (res) { return wrapUp(res); }) : wrapUp(evaluation);
|
|
44
45
|
}
|
|
45
46
|
function getTreatmentWithConfig(key, featureFlagName, attributes) {
|
|
@@ -61,9 +62,9 @@ function clientFactory(params) {
|
|
|
61
62
|
};
|
|
62
63
|
var evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
63
64
|
(0, evaluator_1.evaluateFeatures)(log, key, featureFlagNames, attributes, storage) :
|
|
64
|
-
|
|
65
|
-
treatmentsNotReady(featureFlagNames) :
|
|
66
|
-
|
|
65
|
+
isAsync ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
|
|
66
|
+
Promise.resolve(treatmentsNotReady(featureFlagNames)) :
|
|
67
|
+
treatmentsNotReady(featureFlagNames);
|
|
67
68
|
return (0, thenable_1.thenable)(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
|
|
68
69
|
}
|
|
69
70
|
function getTreatmentsWithConfig(key, featureFlagNames, attributes) {
|
|
@@ -87,7 +88,9 @@ function clientFactory(params) {
|
|
|
87
88
|
};
|
|
88
89
|
var evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
89
90
|
(0, evaluator_1.evaluateFeaturesByFlagSets)(log, key, flagSetNames, attributes, storage, methodName) :
|
|
90
|
-
|
|
91
|
+
isAsync ?
|
|
92
|
+
Promise.resolve({}) :
|
|
93
|
+
{};
|
|
91
94
|
return (0, thenable_1.thenable)(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
|
|
92
95
|
}
|
|
93
96
|
function getTreatmentsWithConfigByFlagSets(key, flagSetNames, attributes) {
|
|
@@ -5,15 +5,15 @@ var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
|
5
5
|
var inputValidation_1 = require("../utils/inputValidation");
|
|
6
6
|
var lang_1 = require("../utils/lang");
|
|
7
7
|
var constants_1 = require("../utils/constants");
|
|
8
|
-
var
|
|
8
|
+
var mode_1 = require("../utils/settingsValidation/mode");
|
|
9
9
|
var splitFilters_1 = require("../utils/settingsValidation/splitFilters");
|
|
10
10
|
/**
|
|
11
11
|
* Decorator that validates the input before actually executing the client methods.
|
|
12
12
|
* We should "guard" the client here, while not polluting the "real" implementation of those methods.
|
|
13
13
|
*/
|
|
14
14
|
function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
15
|
-
var log = settings.log;
|
|
16
|
-
var
|
|
15
|
+
var log = settings.log, mode = settings.mode;
|
|
16
|
+
var isAsync = (0, mode_1.isConsumerMode)(mode);
|
|
17
17
|
/**
|
|
18
18
|
* Avoid repeating this validations code
|
|
19
19
|
*/
|
|
@@ -28,7 +28,7 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
|
28
28
|
var attributes = (0, inputValidation_1.validateAttributes)(log, maybeAttributes, methodName);
|
|
29
29
|
var isNotDestroyed = (0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, methodName);
|
|
30
30
|
if (maybeFlagSetNameOrNames) {
|
|
31
|
-
flagSetOrFlagSets = (0, splitFilters_1.
|
|
31
|
+
flagSetOrFlagSets = (0, splitFilters_1.validateFlagSets)(log, methodName, maybeFlagSetNameOrNames, settings.sync.__splitFiltersValidation.groupedFilters.bySet);
|
|
32
32
|
}
|
|
33
33
|
(0, inputValidation_1.validateIfOperational)(log, readinessManager, methodName, splitOrSplits);
|
|
34
34
|
var valid = isNotDestroyed && key && (splitOrSplits || flagSetOrFlagSets.length > 0) && attributes !== false;
|
|
@@ -41,7 +41,7 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
function wrapResult(value) {
|
|
44
|
-
return
|
|
44
|
+
return isAsync ? Promise.resolve(value) : value;
|
|
45
45
|
}
|
|
46
46
|
function getTreatment(maybeKey, maybeFeatureFlagName, maybeAttributes) {
|
|
47
47
|
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, constants_1.GET_TREATMENT);
|
|
@@ -132,7 +132,7 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
|
132
132
|
return client.track(key, tt, event, eventValue, properties, size);
|
|
133
133
|
}
|
|
134
134
|
else {
|
|
135
|
-
return
|
|
135
|
+
return isAsync ? Promise.resolve(false) : false;
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
return {
|
package/cjs/sdkManager/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
|
5
5
|
var thenable_1 = require("../utils/promise/thenable");
|
|
6
6
|
var lang_1 = require("../utils/lang");
|
|
7
7
|
var inputValidation_1 = require("../utils/inputValidation");
|
|
8
|
-
var
|
|
8
|
+
var mode_1 = require("../utils/settingsValidation/mode");
|
|
9
9
|
var constants_1 = require("../utils/constants");
|
|
10
10
|
function collectTreatments(splitObject) {
|
|
11
11
|
var conditions = splitObject.conditions;
|
|
@@ -42,8 +42,8 @@ function objectsToViews(splitObjects) {
|
|
|
42
42
|
}
|
|
43
43
|
function sdkManagerFactory(settings, splits, _a) {
|
|
44
44
|
var readinessManager = _a.readinessManager, sdkStatus = _a.sdkStatus;
|
|
45
|
-
var log = settings.log;
|
|
46
|
-
var
|
|
45
|
+
var log = settings.log, mode = settings.mode;
|
|
46
|
+
var isAsync = (0, mode_1.isConsumerMode)(mode);
|
|
47
47
|
return (0, objectAssign_1.objectAssign)(
|
|
48
48
|
// Proto-linkage of the readiness Event Emitter
|
|
49
49
|
Object.create(sdkStatus), {
|
|
@@ -53,7 +53,7 @@ function sdkManagerFactory(settings, splits, _a) {
|
|
|
53
53
|
split: function (featureFlagName) {
|
|
54
54
|
var splitName = (0, inputValidation_1.validateSplit)(log, featureFlagName, constants_1.SPLIT_FN_LABEL);
|
|
55
55
|
if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, constants_1.SPLIT_FN_LABEL) || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, constants_1.SPLIT_FN_LABEL) || !splitName) {
|
|
56
|
-
return
|
|
56
|
+
return isAsync ? Promise.resolve(null) : null;
|
|
57
57
|
}
|
|
58
58
|
var split = splits.getSplit(splitName);
|
|
59
59
|
if ((0, thenable_1.thenable)(split)) {
|
|
@@ -70,7 +70,7 @@ function sdkManagerFactory(settings, splits, _a) {
|
|
|
70
70
|
*/
|
|
71
71
|
splits: function () {
|
|
72
72
|
if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, constants_1.SPLITS_FN_LABEL) || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, constants_1.SPLITS_FN_LABEL)) {
|
|
73
|
-
return
|
|
73
|
+
return isAsync ? Promise.resolve([]) : [];
|
|
74
74
|
}
|
|
75
75
|
var currentSplits = splits.getAll();
|
|
76
76
|
return (0, thenable_1.thenable)(currentSplits) ?
|
|
@@ -82,7 +82,7 @@ function sdkManagerFactory(settings, splits, _a) {
|
|
|
82
82
|
*/
|
|
83
83
|
names: function () {
|
|
84
84
|
if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, constants_1.NAMES_FN_LABEL) || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, constants_1.NAMES_FN_LABEL)) {
|
|
85
|
-
return
|
|
85
|
+
return isAsync ? Promise.resolve([]) : [];
|
|
86
86
|
}
|
|
87
87
|
var splitNames = splits.getSplitNames();
|
|
88
88
|
return (0, thenable_1.thenable)(splitNames) ?
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KeyBuilder = exports.validatePrefix = void 0;
|
|
3
|
+
exports.getStorageHash = exports.KeyBuilder = exports.validatePrefix = void 0;
|
|
4
4
|
var lang_1 = require("../utils/lang");
|
|
5
|
+
var murmur3_1 = require("../utils/murmur3/murmur3");
|
|
5
6
|
var everythingAtTheEnd = /[^.]+$/;
|
|
6
7
|
var DEFAULT_PREFIX = 'SPLITIO';
|
|
7
8
|
function validatePrefix(prefix) {
|
|
@@ -58,6 +59,17 @@ var KeyBuilder = /** @class */ (function () {
|
|
|
58
59
|
throw new Error('Invalid latency key provided');
|
|
59
60
|
}
|
|
60
61
|
};
|
|
62
|
+
KeyBuilder.prototype.buildHashKey = function () {
|
|
63
|
+
return this.prefix + ".hash";
|
|
64
|
+
};
|
|
61
65
|
return KeyBuilder;
|
|
62
66
|
}());
|
|
63
67
|
exports.KeyBuilder = KeyBuilder;
|
|
68
|
+
/**
|
|
69
|
+
* Generates a murmur32 hash based on the authorization key and the feature flags filter query.
|
|
70
|
+
* The hash is in hexadecimal format (8 characters max, 32 bits).
|
|
71
|
+
*/
|
|
72
|
+
function getStorageHash(settings) {
|
|
73
|
+
return (0, murmur3_1.hash)(settings.core.authorizationKey + "::" + settings.sync.__splitFiltersValidation.queryString).toString(16);
|
|
74
|
+
}
|
|
75
|
+
exports.getStorageHash = getStorageHash;
|
|
@@ -9,7 +9,7 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
9
9
|
function KeyBuilderCS(prefix, matchingKey) {
|
|
10
10
|
var _this = _super.call(this, prefix) || this;
|
|
11
11
|
_this.matchingKey = matchingKey;
|
|
12
|
-
_this.regexSplitsCacheKey = new RegExp("^" + prefix + "\\.
|
|
12
|
+
_this.regexSplitsCacheKey = new RegExp("^" + prefix + "\\.");
|
|
13
13
|
return _this;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
@@ -39,9 +39,6 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
39
39
|
KeyBuilderCS.prototype.isSplitsCacheKey = function (key) {
|
|
40
40
|
return this.regexSplitsCacheKey.test(key);
|
|
41
41
|
};
|
|
42
|
-
KeyBuilderCS.prototype.buildSplitsFilterQueryKey = function () {
|
|
43
|
-
return this.prefix + ".splits.filterQuery";
|
|
44
|
-
};
|
|
45
42
|
return KeyBuilderCS;
|
|
46
43
|
}(KeyBuilder_1.KeyBuilder));
|
|
47
44
|
exports.KeyBuilderCS = KeyBuilderCS;
|
|
@@ -6,6 +6,7 @@ var AbstractSplitsCacheSync_1 = require("../AbstractSplitsCacheSync");
|
|
|
6
6
|
var lang_1 = require("../../utils/lang");
|
|
7
7
|
var constants_1 = require("./constants");
|
|
8
8
|
var sets_1 = require("../../utils/lang/sets");
|
|
9
|
+
var KeyBuilder_1 = require("../KeyBuilder");
|
|
9
10
|
/**
|
|
10
11
|
* ISplitsCacheSync implementation that stores split definitions in browser LocalStorage.
|
|
11
12
|
*/
|
|
@@ -16,13 +17,12 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
16
17
|
* @param {number | undefined} expirationTimestamp
|
|
17
18
|
* @param {ISplitFiltersValidation} splitFiltersValidation
|
|
18
19
|
*/
|
|
19
|
-
function SplitsCacheInLocal(
|
|
20
|
-
if (splitFiltersValidation === void 0) { splitFiltersValidation = { queryString: null, groupedFilters: { bySet: [], byName: [], byPrefix: [] }, validFilters: [] }; }
|
|
20
|
+
function SplitsCacheInLocal(settings, keys, expirationTimestamp) {
|
|
21
21
|
var _this = _super.call(this) || this;
|
|
22
|
-
_this.log = log;
|
|
23
22
|
_this.keys = keys;
|
|
24
|
-
_this.
|
|
25
|
-
_this.
|
|
23
|
+
_this.log = settings.log;
|
|
24
|
+
_this.storageHash = (0, KeyBuilder_1.getStorageHash)(settings);
|
|
25
|
+
_this.flagSetsFilter = settings.sync.__splitFiltersValidation.groupedFilters.bySet;
|
|
26
26
|
_this._checkExpiration(expirationTimestamp);
|
|
27
27
|
_this._checkFilterQuery();
|
|
28
28
|
return _this;
|
|
@@ -126,14 +126,10 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
126
126
|
SplitsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
127
127
|
// when using a new split query, we must update it at the store
|
|
128
128
|
if (this.updateNewFilter) {
|
|
129
|
-
this.log.info(constants_1.LOG_PREFIX + '
|
|
130
|
-
var
|
|
131
|
-
var queryString = this.splitFiltersValidation.queryString;
|
|
129
|
+
this.log.info(constants_1.LOG_PREFIX + 'SDK key or feature flag filter criteria was modified. Updating cache.');
|
|
130
|
+
var storageHashKey = this.keys.buildHashKey();
|
|
132
131
|
try {
|
|
133
|
-
|
|
134
|
-
localStorage.setItem(queryKey, queryString);
|
|
135
|
-
else
|
|
136
|
-
localStorage.removeItem(queryKey);
|
|
132
|
+
localStorage.setItem(storageHashKey, this.storageHash);
|
|
137
133
|
}
|
|
138
134
|
catch (e) {
|
|
139
135
|
this.log.error(constants_1.LOG_PREFIX + e);
|
|
@@ -211,11 +207,11 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
211
207
|
this.clear();
|
|
212
208
|
}
|
|
213
209
|
};
|
|
210
|
+
// @TODO eventually remove `_checkFilterQuery`. Cache should be cleared at the storage level, reusing same logic than PluggableStorage
|
|
214
211
|
SplitsCacheInLocal.prototype._checkFilterQuery = function () {
|
|
215
|
-
var
|
|
216
|
-
var
|
|
217
|
-
|
|
218
|
-
if (currentQueryString !== queryString) {
|
|
212
|
+
var storageHashKey = this.keys.buildHashKey();
|
|
213
|
+
var storageHash = localStorage.getItem(storageHashKey);
|
|
214
|
+
if (storageHash !== this.storageHash) {
|
|
219
215
|
try {
|
|
220
216
|
// mark cache to update the new query filter on first successful splits fetch
|
|
221
217
|
this.updateNewFilter = true;
|
|
@@ -34,7 +34,7 @@ function InLocalStorage(options) {
|
|
|
34
34
|
var matchingKey = (0, key_1.getMatching)(settings.core.key);
|
|
35
35
|
var keys = new KeyBuilderCS_1.KeyBuilderCS(prefix, matchingKey);
|
|
36
36
|
var expirationTimestamp = Date.now() - browser_1.DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
|
|
37
|
-
var splits = new SplitsCacheInLocal_1.SplitsCacheInLocal(
|
|
37
|
+
var splits = new SplitsCacheInLocal_1.SplitsCacheInLocal(settings, keys, expirationTimestamp);
|
|
38
38
|
var segments = new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, keys);
|
|
39
39
|
return {
|
|
40
40
|
splits: splits,
|
|
@@ -52,8 +52,8 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
52
52
|
};
|
|
53
53
|
SplitsCacheInRedis.prototype._updateFlagSets = function (featureFlagName, flagSetsOfRemovedFlag, flagSetsOfAddedFlag) {
|
|
54
54
|
var _this = this;
|
|
55
|
-
var removeFromFlagSets = (0, sets_1.
|
|
56
|
-
var addToFlagSets = (0, sets_1.
|
|
55
|
+
var removeFromFlagSets = (0, sets_1.returnDifference)(flagSetsOfRemovedFlag, flagSetsOfAddedFlag);
|
|
56
|
+
var addToFlagSets = (0, sets_1.returnDifference)(flagSetsOfAddedFlag, flagSetsOfRemovedFlag);
|
|
57
57
|
if (this.flagSetsFilter.length > 0) {
|
|
58
58
|
addToFlagSets = addToFlagSets.filter(function (flagSet) {
|
|
59
59
|
return _this.flagSetsFilter.some(function (filterFlagSet) { return filterFlagSet === flagSet; });
|
|
@@ -39,7 +39,7 @@ function InRedisStorage(options) {
|
|
|
39
39
|
telemetry.recordConfig();
|
|
40
40
|
});
|
|
41
41
|
return {
|
|
42
|
-
splits: new SplitsCacheInRedis_1.SplitsCacheInRedis(log, keys, redisClient),
|
|
42
|
+
splits: new SplitsCacheInRedis_1.SplitsCacheInRedis(log, keys, redisClient, settings.sync.__splitFiltersValidation),
|
|
43
43
|
segments: new SegmentsCacheInRedis_1.SegmentsCacheInRedis(log, keys, redisClient),
|
|
44
44
|
impressions: new ImpressionsCacheInRedis_1.ImpressionsCacheInRedis(log, keys.buildImpressionsKey(), redisClient, metadata),
|
|
45
45
|
impressionCounts: impressionCountsCache,
|
|
@@ -39,8 +39,8 @@ var SplitsCachePluggable = /** @class */ (function (_super) {
|
|
|
39
39
|
};
|
|
40
40
|
SplitsCachePluggable.prototype._updateFlagSets = function (featureFlagName, flagSetsOfRemovedFlag, flagSetsOfAddedFlag) {
|
|
41
41
|
var _this = this;
|
|
42
|
-
var removeFromFlagSets = (0, sets_1.
|
|
43
|
-
var addToFlagSets = (0, sets_1.
|
|
42
|
+
var removeFromFlagSets = (0, sets_1.returnDifference)(flagSetsOfRemovedFlag, flagSetsOfAddedFlag);
|
|
43
|
+
var addToFlagSets = (0, sets_1.returnDifference)(flagSetsOfAddedFlag, flagSetsOfRemovedFlag);
|
|
44
44
|
if (this.flagSetsFilter.length > 0) {
|
|
45
45
|
addToFlagSets = addToFlagSets.filter(function (flagSet) {
|
|
46
46
|
return _this.flagSetsFilter.some(function (filterFlagSet) { return filterFlagSet === flagSet; });
|
|
@@ -76,15 +76,28 @@ function PluggableStorage(options) {
|
|
|
76
76
|
undefined;
|
|
77
77
|
// Connects to wrapper and emits SDK_READY event on main client
|
|
78
78
|
var connectPromise = wrapper.connect().then(function () {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
if (isSyncronizer) {
|
|
80
|
+
// In standalone or producer mode, clear storage if SDK key or feature flag filter has changed
|
|
81
|
+
return wrapper.get(keys.buildHashKey()).then(function (hash) {
|
|
82
|
+
var currentHash = (0, KeyBuilder_1.getStorageHash)(settings);
|
|
83
|
+
if (hash !== currentHash) {
|
|
84
|
+
return wrapper.getKeysByPrefix(keys.prefix + ".").then(function (storageKeys) {
|
|
85
|
+
return Promise.all(storageKeys.map(function (storageKey) { return wrapper.del(storageKey); }));
|
|
86
|
+
}).then(function () { return wrapper.set(keys.buildHashKey(), currentHash); });
|
|
87
|
+
}
|
|
88
|
+
}).then(function () {
|
|
89
|
+
onReadyCb();
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// Start periodic flush of async storages if not running synchronizer (producer mode)
|
|
82
94
|
if (impressionCountsCache && impressionCountsCache.start)
|
|
83
95
|
impressionCountsCache.start();
|
|
84
96
|
if (uniqueKeysCache && uniqueKeysCache.start)
|
|
85
97
|
uniqueKeysCache.start();
|
|
86
98
|
if (telemetry && telemetry.recordConfig)
|
|
87
99
|
telemetry.recordConfig();
|
|
100
|
+
onReadyCb();
|
|
88
101
|
}
|
|
89
102
|
}).catch(function (e) {
|
|
90
103
|
e = e || new Error('Error connecting wrapper');
|
|
@@ -5,7 +5,7 @@ var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
|
5
5
|
var thenable_1 = require("../utils/promise/thenable");
|
|
6
6
|
var constants_1 = require("../logger/constants");
|
|
7
7
|
var constants_2 = require("../utils/constants");
|
|
8
|
-
var
|
|
8
|
+
var mode_1 = require("../utils/settingsValidation/mode");
|
|
9
9
|
/**
|
|
10
10
|
* Event tracker stores events in cache and pass them to the integrations manager if provided.
|
|
11
11
|
*
|
|
@@ -13,8 +13,8 @@ var utils_1 = require("./impressionObserver/utils");
|
|
|
13
13
|
* @param integrationsManager optional event handler used for integrations
|
|
14
14
|
*/
|
|
15
15
|
function eventTrackerFactory(settings, eventsCache, integrationsManager, telemetryCache) {
|
|
16
|
-
var log = settings.log;
|
|
17
|
-
var
|
|
16
|
+
var log = settings.log, mode = settings.mode;
|
|
17
|
+
var isAsync = (0, mode_1.isConsumerMode)(mode);
|
|
18
18
|
function queueEventsCallback(eventData, tracked) {
|
|
19
19
|
var eventTypeId = eventData.eventTypeId, trafficTypeName = eventData.trafficTypeName, key = eventData.key, value = eventData.value, timestamp = eventData.timestamp, properties = eventData.properties;
|
|
20
20
|
// Logging every prop would be too much.
|
|
@@ -41,7 +41,7 @@ function eventTrackerFactory(settings, eventsCache, integrationsManager, telemet
|
|
|
41
41
|
return {
|
|
42
42
|
track: function (eventData, size) {
|
|
43
43
|
if (settings.userConsent === constants_2.CONSENT_DECLINED) {
|
|
44
|
-
return
|
|
44
|
+
return isAsync ? Promise.resolve(false) : false;
|
|
45
45
|
}
|
|
46
46
|
var tracked = eventsCache.track(eventData, size);
|
|
47
47
|
if ((0, thenable_1.thenable)(tracked)) {
|
package/cjs/utils/lang/sets.js
CHANGED
|
@@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
24
24
|
THE SOFTWARE.
|
|
25
25
|
**/
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.
|
|
27
|
+
exports.returnDifference = exports.returnSetsUnion = exports._Set = exports.__getSetConstructor = exports.setToArray = exports.SetPoly = void 0;
|
|
28
28
|
var SetPoly = /** @class */ (function () {
|
|
29
29
|
// unlike ES6 `Set`, it only accepts an array as first argument iterable
|
|
30
30
|
function SetPoly(values) {
|
|
@@ -108,7 +108,7 @@ function returnSetsUnion(set, set2) {
|
|
|
108
108
|
return result;
|
|
109
109
|
}
|
|
110
110
|
exports.returnSetsUnion = returnSetsUnion;
|
|
111
|
-
function
|
|
111
|
+
function returnDifference(list, list2) {
|
|
112
112
|
if (list === void 0) { list = []; }
|
|
113
113
|
if (list2 === void 0) { list2 = []; }
|
|
114
114
|
var result = new exports._Set(list);
|
|
@@ -117,4 +117,4 @@ function returnListDifference(list, list2) {
|
|
|
117
117
|
});
|
|
118
118
|
return setToArray(result);
|
|
119
119
|
}
|
|
120
|
-
exports.
|
|
120
|
+
exports.returnDifference = returnDifference;
|
|
@@ -126,7 +126,7 @@ function settingsValidation(config, validationParams) {
|
|
|
126
126
|
startup.eventsFirstPushWindow = fromSecondsToMillis(startup.eventsFirstPushWindow);
|
|
127
127
|
// ensure a valid SDK mode
|
|
128
128
|
// @ts-ignore, modify readonly prop
|
|
129
|
-
withDefaults.mode = (0, mode_1.
|
|
129
|
+
withDefaults.mode = (0, mode_1.validateMode)(withDefaults.core.authorizationKey, withDefaults.mode);
|
|
130
130
|
// ensure a valid Storage based on mode defined.
|
|
131
131
|
// @ts-ignore, modify readonly prop
|
|
132
132
|
if (storage)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isConsumerMode = exports.validateMode = void 0;
|
|
4
4
|
var constants_1 = require("../constants");
|
|
5
|
-
function
|
|
5
|
+
function validateMode(key, mode) {
|
|
6
6
|
// Leaving the comparison as is, in case we change the mode name but not the setting.
|
|
7
7
|
if (key === 'localhost')
|
|
8
8
|
return constants_1.LOCALHOST_MODE;
|
|
@@ -10,4 +10,11 @@ function mode(key, mode) {
|
|
|
10
10
|
throw Error('Invalid mode provided');
|
|
11
11
|
return mode;
|
|
12
12
|
}
|
|
13
|
-
exports.
|
|
13
|
+
exports.validateMode = validateMode;
|
|
14
|
+
/**
|
|
15
|
+
* Storage is async if mode is consumer or partial consumer
|
|
16
|
+
*/
|
|
17
|
+
function isConsumerMode(mode) {
|
|
18
|
+
return constants_1.CONSUMER_MODE === mode || constants_1.CONSUMER_PARTIAL_MODE === mode;
|
|
19
|
+
}
|
|
20
|
+
exports.isConsumerMode = isConsumerMode;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var constants_1 = require("../constants");
|
|
3
|
+
exports.validateFlagSets = exports.validateSplitFilters = void 0;
|
|
5
4
|
var splits_1 = require("../inputValidation/splits");
|
|
6
|
-
var
|
|
5
|
+
var constants_1 = require("../../logger/constants");
|
|
7
6
|
var objectAssign_1 = require("../lang/objectAssign");
|
|
8
7
|
var lang_1 = require("../lang");
|
|
8
|
+
var mode_1 = require("./mode");
|
|
9
9
|
// Split filters metadata.
|
|
10
10
|
// Ordered according to their precedency when forming the filter query string: `&names=<values>&prefixes=<values>`
|
|
11
11
|
var FILTERS_METADATA = [
|
|
@@ -45,10 +45,10 @@ function validateFilterType(maybeFilterType) {
|
|
|
45
45
|
*/
|
|
46
46
|
function validateSplitFilter(log, type, values, maxLength) {
|
|
47
47
|
// validate and remove invalid and duplicated values
|
|
48
|
-
var result = (0, splits_1.validateSplits)(log, values,
|
|
48
|
+
var result = (0, splits_1.validateSplits)(log, values, constants_1.LOG_PREFIX_SETTINGS, type + " filter", type + " filter value");
|
|
49
49
|
if (result) {
|
|
50
50
|
if (type === 'bySet') {
|
|
51
|
-
result = sanitizeFlagSets(log, result);
|
|
51
|
+
result = sanitizeFlagSets(log, result, constants_1.LOG_PREFIX_SETTINGS);
|
|
52
52
|
}
|
|
53
53
|
// check max length
|
|
54
54
|
if (result.length > maxLength)
|
|
@@ -81,7 +81,7 @@ function queryStringBuilder(groupedFilters) {
|
|
|
81
81
|
return queryParams.length > 0 ? '&' + queryParams.join('&') : null;
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
|
-
* Sanitizes set names list taking
|
|
84
|
+
* Sanitizes set names list taking into account:
|
|
85
85
|
* - It should be lowercase
|
|
86
86
|
* - Must adhere the following regular expression /^[a-z0-9][_a-z0-9]{0,49}$/ that means
|
|
87
87
|
* - must start with a letter or number
|
|
@@ -91,20 +91,21 @@ function queryStringBuilder(groupedFilters) {
|
|
|
91
91
|
*
|
|
92
92
|
* @param {ILogger} log
|
|
93
93
|
* @param {string[]} flagSets
|
|
94
|
+
* @param {string} method
|
|
94
95
|
* @returns sanitized list of set names
|
|
95
96
|
*/
|
|
96
|
-
function sanitizeFlagSets(log, flagSets) {
|
|
97
|
+
function sanitizeFlagSets(log, flagSets, method) {
|
|
97
98
|
var sanitizedSets = flagSets
|
|
98
99
|
.map(function (flagSet) {
|
|
99
100
|
if (CAPITAL_LETTERS_REGEX.test(flagSet)) {
|
|
100
|
-
log.warn(
|
|
101
|
+
log.warn(constants_1.WARN_LOWERCASE_FLAGSET, [method, flagSet]);
|
|
101
102
|
flagSet = flagSet.toLowerCase();
|
|
102
103
|
}
|
|
103
104
|
return flagSet;
|
|
104
105
|
})
|
|
105
106
|
.filter(function (flagSet) {
|
|
106
107
|
if (!VALID_FLAGSET_REGEX.test(flagSet)) {
|
|
107
|
-
log.warn(
|
|
108
|
+
log.warn(constants_1.WARN_INVALID_FLAGSET, [method, flagSet, VALID_FLAGSET_REGEX, flagSet]);
|
|
108
109
|
return false;
|
|
109
110
|
}
|
|
110
111
|
if (typeof flagSet !== 'string')
|
|
@@ -140,13 +141,13 @@ function validateSplitFilters(log, maybeSplitFilters, mode) {
|
|
|
140
141
|
if (!maybeSplitFilters)
|
|
141
142
|
return res;
|
|
142
143
|
// Warn depending on the mode
|
|
143
|
-
if (
|
|
144
|
-
log.warn(
|
|
144
|
+
if ((0, mode_1.isConsumerMode)(mode)) {
|
|
145
|
+
log.warn(constants_1.WARN_SPLITS_FILTER_IGNORED);
|
|
145
146
|
return res;
|
|
146
147
|
}
|
|
147
148
|
// Check collection type
|
|
148
149
|
if (!Array.isArray(maybeSplitFilters) || maybeSplitFilters.length === 0) {
|
|
149
|
-
log.warn(
|
|
150
|
+
log.warn(constants_1.WARN_SPLITS_FILTER_EMPTY);
|
|
150
151
|
return res;
|
|
151
152
|
}
|
|
152
153
|
// Validate filters and group their values by filter type inside `groupedFilters` object
|
|
@@ -156,7 +157,7 @@ function validateSplitFilters(log, maybeSplitFilters, mode) {
|
|
|
156
157
|
return true;
|
|
157
158
|
}
|
|
158
159
|
else {
|
|
159
|
-
log.warn(
|
|
160
|
+
log.warn(constants_1.WARN_SPLITS_FILTER_INVALID, [index]);
|
|
160
161
|
}
|
|
161
162
|
return false;
|
|
162
163
|
});
|
|
@@ -170,27 +171,27 @@ function validateSplitFilters(log, maybeSplitFilters, mode) {
|
|
|
170
171
|
// Clean all filters if set filter is present
|
|
171
172
|
if (setFilter) {
|
|
172
173
|
if (configuredFilter(res.validFilters, 'byName') || configuredFilter(res.validFilters, 'byPrefix'))
|
|
173
|
-
log.error(
|
|
174
|
+
log.error(constants_1.ERROR_SETS_FILTER_EXCLUSIVE);
|
|
174
175
|
(0, objectAssign_1.objectAssign)(res.groupedFilters, { byName: [], byPrefix: [] });
|
|
175
176
|
}
|
|
176
177
|
// build query string
|
|
177
178
|
res.queryString = queryStringBuilder(res.groupedFilters);
|
|
178
|
-
log.debug(
|
|
179
|
+
log.debug(constants_1.SETTINGS_SPLITS_FILTER, [res.queryString]);
|
|
179
180
|
return res;
|
|
180
181
|
}
|
|
181
182
|
exports.validateSplitFilters = validateSplitFilters;
|
|
182
|
-
function
|
|
183
|
+
function validateFlagSets(log, method, flagSets, flagSetsInConfig) {
|
|
183
184
|
var sets = (0, splits_1.validateSplits)(log, flagSets, method, 'flag sets', 'flag set');
|
|
184
|
-
var toReturn = sets ? sanitizeFlagSets(log, sets) : [];
|
|
185
|
+
var toReturn = sets ? sanitizeFlagSets(log, sets, method) : [];
|
|
185
186
|
if (flagSetsInConfig.length > 0) {
|
|
186
187
|
toReturn = toReturn.filter(function (flagSet) {
|
|
187
188
|
if (flagSetsInConfig.indexOf(flagSet) > -1) {
|
|
188
189
|
return true;
|
|
189
190
|
}
|
|
190
|
-
log.warn(
|
|
191
|
+
log.warn(constants_1.WARN_FLAGSET_NOT_CONFIGURED, [method, flagSet]);
|
|
191
192
|
return false;
|
|
192
193
|
});
|
|
193
194
|
}
|
|
194
195
|
return toReturn;
|
|
195
196
|
}
|
|
196
|
-
exports.
|
|
197
|
+
exports.validateFlagSets = validateFlagSets;
|
package/esm/logger/constants.js
CHANGED
|
@@ -95,8 +95,8 @@ export var WARN_SPLITS_FILTER_EMPTY = 221;
|
|
|
95
95
|
export var WARN_SDK_KEY = 222;
|
|
96
96
|
export var STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 223;
|
|
97
97
|
export var STREAMING_PARSING_SPLIT_UPDATE = 224;
|
|
98
|
-
export var
|
|
99
|
-
export var
|
|
98
|
+
export var WARN_INVALID_FLAGSET = 225;
|
|
99
|
+
export var WARN_LOWERCASE_FLAGSET = 226;
|
|
100
100
|
export var WARN_FLAGSET_NOT_CONFIGURED = 227;
|
|
101
101
|
export var WARN_FLAGSET_WITHOUT_FLAGS = 228;
|
|
102
102
|
export var ERROR_ENGINE_COMBINER_IFELSEIF = 300;
|
|
@@ -32,7 +32,7 @@ export var codesWarn = codesError.concat([
|
|
|
32
32
|
[c.WARN_SDK_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
33
|
[c.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching MySegments due to an error processing %s notification: %s'],
|
|
34
34
|
[c.STREAMING_PARSING_SPLIT_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching SplitChanges due to an error processing SPLIT_UPDATE notification: %s'],
|
|
35
|
-
[c.
|
|
36
|
-
[c.
|
|
35
|
+
[c.WARN_INVALID_FLAGSET, '%s: you passed %s, flag set must adhere to the regular expressions %s. This means a flag set must start with a letter or number, be in lowercase, alphanumeric and have a max length of 50 characters. %s was discarded.'],
|
|
36
|
+
[c.WARN_LOWERCASE_FLAGSET, '%s: flag set %s should be all lowercase - converting string to lowercase.'],
|
|
37
37
|
[c.WARN_FLAGSET_WITHOUT_FLAGS, '%s: you passed %s flag set that does not contain cached feature flag names. Please double check what flag sets are in use in the Split user interface.'],
|
|
38
38
|
]);
|