@splitsoftware/splitio-commons 1.12.1-rc.3 → 1.12.1-rc.5
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 +27 -21
- package/cjs/sdkClient/clientInputValidation.js +21 -21
- package/cjs/sdkManager/index.js +13 -15
- 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 +14 -3
- package/cjs/trackers/eventTracker.js +4 -4
- package/cjs/utils/constants/index.js +16 -2
- 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 +28 -22
- package/esm/sdkClient/clientInputValidation.js +23 -23
- package/esm/sdkManager/index.js +7 -9
- 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 +15 -4
- package/esm/trackers/eventTracker.js +4 -4
- package/esm/utils/constants/index.js +14 -0
- 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 +26 -23
- package/src/sdkClient/clientInputValidation.ts +23 -23
- package/src/sdkManager/index.ts +7 -10
- 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 +15 -5
- package/src/storages/types.ts +3 -3
- package/src/trackers/eventTracker.ts +4 -4
- package/src/utils/constants/index.ts +16 -0
- 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/constants/index.d.ts +12 -0
- 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,34 +24,37 @@ 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
|
-
|
|
27
|
+
var isAsync = (0, mode_1.isConsumerMode)(mode);
|
|
28
|
+
function getTreatment(key, featureFlagName, attributes, withConfig, methodName) {
|
|
28
29
|
if (withConfig === void 0) { withConfig = false; }
|
|
30
|
+
if (methodName === void 0) { methodName = constants_1.GET_TREATMENT; }
|
|
29
31
|
var stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? constants_1.TREATMENT_WITH_CONFIG : constants_1.TREATMENT);
|
|
30
32
|
var wrapUp = function (evaluationResult) {
|
|
31
33
|
var queue = [];
|
|
32
|
-
var treatment = processEvaluation(evaluationResult, featureFlagName, key, attributes, withConfig,
|
|
34
|
+
var treatment = processEvaluation(evaluationResult, featureFlagName, key, attributes, withConfig, methodName, queue);
|
|
33
35
|
impressionsTracker.track(queue, attributes);
|
|
34
36
|
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
35
37
|
return treatment;
|
|
36
38
|
};
|
|
37
39
|
var evaluation = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
38
40
|
(0, evaluator_1.evaluateFeature)(log, key, featureFlagName, attributes, storage) :
|
|
39
|
-
|
|
40
|
-
treatmentNotReady :
|
|
41
|
-
|
|
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;
|
|
42
44
|
return (0, thenable_1.thenable)(evaluation) ? evaluation.then(function (res) { return wrapUp(res); }) : wrapUp(evaluation);
|
|
43
45
|
}
|
|
44
46
|
function getTreatmentWithConfig(key, featureFlagName, attributes) {
|
|
45
|
-
return getTreatment(key, featureFlagName, attributes, true);
|
|
47
|
+
return getTreatment(key, featureFlagName, attributes, true, constants_1.GET_TREATMENT_WITH_CONFIG);
|
|
46
48
|
}
|
|
47
|
-
function getTreatments(key, featureFlagNames, attributes, withConfig) {
|
|
49
|
+
function getTreatments(key, featureFlagNames, attributes, withConfig, methodName) {
|
|
48
50
|
if (withConfig === void 0) { withConfig = false; }
|
|
51
|
+
if (methodName === void 0) { methodName = constants_1.GET_TREATMENTS; }
|
|
49
52
|
var stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? constants_1.TREATMENTS_WITH_CONFIG : constants_1.TREATMENTS);
|
|
50
53
|
var wrapUp = function (evaluationResults) {
|
|
51
54
|
var queue = [];
|
|
52
55
|
var treatments = {};
|
|
53
56
|
Object.keys(evaluationResults).forEach(function (featureFlagName) {
|
|
54
|
-
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, attributes, withConfig,
|
|
57
|
+
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, attributes, withConfig, methodName, queue);
|
|
55
58
|
});
|
|
56
59
|
impressionsTracker.track(queue, attributes);
|
|
57
60
|
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
@@ -59,42 +62,45 @@ function clientFactory(params) {
|
|
|
59
62
|
};
|
|
60
63
|
var evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
61
64
|
(0, evaluator_1.evaluateFeatures)(log, key, featureFlagNames, attributes, storage) :
|
|
62
|
-
|
|
63
|
-
treatmentsNotReady(featureFlagNames) :
|
|
64
|
-
|
|
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);
|
|
65
68
|
return (0, thenable_1.thenable)(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
|
|
66
69
|
}
|
|
67
70
|
function getTreatmentsWithConfig(key, featureFlagNames, attributes) {
|
|
68
|
-
return getTreatments(key, featureFlagNames, attributes, true);
|
|
71
|
+
return getTreatments(key, featureFlagNames, attributes, true, constants_1.GET_TREATMENTS_WITH_CONFIG);
|
|
69
72
|
}
|
|
70
|
-
function getTreatmentsByFlagSets(key, flagSetNames, attributes, withConfig, method) {
|
|
73
|
+
function getTreatmentsByFlagSets(key, flagSetNames, attributes, withConfig, method, methodName) {
|
|
71
74
|
if (withConfig === void 0) { withConfig = false; }
|
|
72
75
|
if (method === void 0) { method = constants_1.TREATMENTS_BY_FLAGSETS; }
|
|
76
|
+
if (methodName === void 0) { methodName = constants_1.GET_TREATMENTS_BY_FLAG_SETS; }
|
|
73
77
|
var stopTelemetryTracker = telemetryTracker.trackEval(method);
|
|
74
78
|
var wrapUp = function (evaluationResults) {
|
|
75
79
|
var queue = [];
|
|
76
80
|
var treatments = {};
|
|
77
81
|
var evaluations = evaluationResults;
|
|
78
82
|
Object.keys(evaluations).forEach(function (featureFlagName) {
|
|
79
|
-
treatments[featureFlagName] = processEvaluation(evaluations[featureFlagName], featureFlagName, key, attributes, withConfig,
|
|
83
|
+
treatments[featureFlagName] = processEvaluation(evaluations[featureFlagName], featureFlagName, key, attributes, withConfig, methodName, queue);
|
|
80
84
|
});
|
|
81
85
|
impressionsTracker.track(queue, attributes);
|
|
82
86
|
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
83
87
|
return treatments;
|
|
84
88
|
};
|
|
85
89
|
var evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
86
|
-
(0, evaluator_1.evaluateFeaturesByFlagSets)(log, key, flagSetNames, attributes, storage,
|
|
87
|
-
|
|
90
|
+
(0, evaluator_1.evaluateFeaturesByFlagSets)(log, key, flagSetNames, attributes, storage, methodName) :
|
|
91
|
+
isAsync ?
|
|
92
|
+
Promise.resolve({}) :
|
|
93
|
+
{};
|
|
88
94
|
return (0, thenable_1.thenable)(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
|
|
89
95
|
}
|
|
90
96
|
function getTreatmentsWithConfigByFlagSets(key, flagSetNames, attributes) {
|
|
91
|
-
return getTreatmentsByFlagSets(key, flagSetNames, attributes, true, constants_1.TREATMENTS_WITH_CONFIG_BY_FLAGSETS);
|
|
97
|
+
return getTreatmentsByFlagSets(key, flagSetNames, attributes, true, constants_1.TREATMENTS_WITH_CONFIG_BY_FLAGSETS, constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS);
|
|
92
98
|
}
|
|
93
99
|
function getTreatmentsByFlagSet(key, flagSetName, attributes) {
|
|
94
|
-
return getTreatmentsByFlagSets(key, [flagSetName], attributes, false, constants_1.TREATMENTS_BY_FLAGSET);
|
|
100
|
+
return getTreatmentsByFlagSets(key, [flagSetName], attributes, false, constants_1.TREATMENTS_BY_FLAGSET, constants_1.GET_TREATMENTS_BY_FLAG_SET);
|
|
95
101
|
}
|
|
96
102
|
function getTreatmentsWithConfigByFlagSet(key, flagSetName, attributes) {
|
|
97
|
-
return getTreatmentsByFlagSets(key, [flagSetName], attributes, true, constants_1.TREATMENTS_WITH_CONFIG_BY_FLAGSET);
|
|
103
|
+
return getTreatmentsByFlagSets(key, [flagSetName], attributes, true, constants_1.TREATMENTS_WITH_CONFIG_BY_FLAGSET, constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET);
|
|
98
104
|
}
|
|
99
105
|
// Internal function
|
|
100
106
|
function processEvaluation(evaluation, featureFlagName, key, attributes, withConfig, invokingMethodName, queue) {
|
|
@@ -136,7 +142,7 @@ function clientFactory(params) {
|
|
|
136
142
|
properties: properties
|
|
137
143
|
};
|
|
138
144
|
// This may be async but we only warn, we don't actually care if it is valid or not in terms of queueing the event.
|
|
139
|
-
(0, trafficTypeExistence_1.validateTrafficTypeExistence)(log, readinessManager, storage.splits, mode, trafficTypeName,
|
|
145
|
+
(0, trafficTypeExistence_1.validateTrafficTypeExistence)(log, readinessManager, storage.splits, mode, trafficTypeName, constants_1.TRACK_FN_LABEL);
|
|
140
146
|
var result = eventTracker.track(eventData, size);
|
|
141
147
|
if ((0, thenable_1.thenable)(result)) {
|
|
142
148
|
return result.then(function (result) {
|
|
@@ -5,20 +5,20 @@ 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
|
*/
|
|
20
20
|
function validateEvaluationParams(maybeKey, maybeFeatureFlagNameOrNames, maybeAttributes, methodName, maybeFlagSetNameOrNames) {
|
|
21
|
-
var multi = (0, lang_1.startsWith)(methodName,
|
|
21
|
+
var multi = (0, lang_1.startsWith)(methodName, constants_1.GET_TREATMENTS);
|
|
22
22
|
var key = (0, inputValidation_1.validateKey)(log, maybeKey, methodName);
|
|
23
23
|
var splitOrSplits = false;
|
|
24
24
|
var flagSetOrFlagSets = [];
|
|
@@ -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,10 +41,10 @@ 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
|
-
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes,
|
|
47
|
+
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, constants_1.GET_TREATMENT);
|
|
48
48
|
if (params.valid) {
|
|
49
49
|
return client.getTreatment(params.key, params.splitOrSplits, params.attributes);
|
|
50
50
|
}
|
|
@@ -53,7 +53,7 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
function getTreatmentWithConfig(maybeKey, maybeFeatureFlagName, maybeAttributes) {
|
|
56
|
-
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes,
|
|
56
|
+
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, constants_1.GET_TREATMENT_WITH_CONFIG);
|
|
57
57
|
if (params.valid) {
|
|
58
58
|
return client.getTreatmentWithConfig(params.key, params.splitOrSplits, params.attributes);
|
|
59
59
|
}
|
|
@@ -62,7 +62,7 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
function getTreatments(maybeKey, maybeFeatureFlagNames, maybeAttributes) {
|
|
65
|
-
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes,
|
|
65
|
+
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes, constants_1.GET_TREATMENTS);
|
|
66
66
|
if (params.valid) {
|
|
67
67
|
return client.getTreatments(params.key, params.splitOrSplits, params.attributes);
|
|
68
68
|
}
|
|
@@ -74,7 +74,7 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
function getTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, maybeAttributes) {
|
|
77
|
-
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes,
|
|
77
|
+
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes, constants_1.GET_TREATMENTS_WITH_CONFIG);
|
|
78
78
|
if (params.valid) {
|
|
79
79
|
return client.getTreatmentsWithConfig(params.key, params.splitOrSplits, params.attributes);
|
|
80
80
|
}
|
|
@@ -86,7 +86,7 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
function getTreatmentsByFlagSets(maybeKey, maybeFlagSets, maybeAttributes) {
|
|
89
|
-
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes,
|
|
89
|
+
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, constants_1.GET_TREATMENTS_BY_FLAG_SETS, maybeFlagSets);
|
|
90
90
|
if (params.valid) {
|
|
91
91
|
return client.getTreatmentsByFlagSets(params.key, params.flagSetOrFlagSets, params.attributes);
|
|
92
92
|
}
|
|
@@ -95,7 +95,7 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
function getTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, maybeAttributes) {
|
|
98
|
-
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes,
|
|
98
|
+
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, maybeFlagSets);
|
|
99
99
|
if (params.valid) {
|
|
100
100
|
return client.getTreatmentsWithConfigByFlagSets(params.key, params.flagSetOrFlagSets, params.attributes);
|
|
101
101
|
}
|
|
@@ -104,7 +104,7 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
function getTreatmentsByFlagSet(maybeKey, maybeFlagSet, maybeAttributes) {
|
|
107
|
-
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes,
|
|
107
|
+
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, constants_1.GET_TREATMENTS_BY_FLAG_SET, [maybeFlagSet]);
|
|
108
108
|
if (params.valid) {
|
|
109
109
|
return client.getTreatmentsByFlagSet(params.key, params.flagSetOrFlagSets[0], params.attributes);
|
|
110
110
|
}
|
|
@@ -113,7 +113,7 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
function getTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, maybeAttributes) {
|
|
116
|
-
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes,
|
|
116
|
+
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, [maybeFlagSet]);
|
|
117
117
|
if (params.valid) {
|
|
118
118
|
return client.getTreatmentsWithConfigByFlagSet(params.key, params.flagSetOrFlagSets[0], params.attributes);
|
|
119
119
|
}
|
|
@@ -122,17 +122,17 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
function track(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties) {
|
|
125
|
-
var key = (0, inputValidation_1.validateKey)(log, maybeKey,
|
|
126
|
-
var tt = (0, inputValidation_1.validateTrafficType)(log, maybeTT,
|
|
127
|
-
var event = (0, inputValidation_1.validateEvent)(log, maybeEvent,
|
|
128
|
-
var eventValue = (0, inputValidation_1.validateEventValue)(log, maybeEventValue,
|
|
129
|
-
var _a = (0, inputValidation_1.validateEventProperties)(log, maybeProperties,
|
|
130
|
-
var isNotDestroyed = (0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager,
|
|
125
|
+
var key = (0, inputValidation_1.validateKey)(log, maybeKey, constants_1.TRACK_FN_LABEL);
|
|
126
|
+
var tt = (0, inputValidation_1.validateTrafficType)(log, maybeTT, constants_1.TRACK_FN_LABEL);
|
|
127
|
+
var event = (0, inputValidation_1.validateEvent)(log, maybeEvent, constants_1.TRACK_FN_LABEL);
|
|
128
|
+
var eventValue = (0, inputValidation_1.validateEventValue)(log, maybeEventValue, constants_1.TRACK_FN_LABEL);
|
|
129
|
+
var _a = (0, inputValidation_1.validateEventProperties)(log, maybeProperties, constants_1.TRACK_FN_LABEL), properties = _a.properties, size = _a.size;
|
|
130
|
+
var isNotDestroyed = (0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, constants_1.TRACK_FN_LABEL);
|
|
131
131
|
if (isNotDestroyed && key && tt && event && eventValue !== false && properties !== false) { // @ts-expect-error
|
|
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,10 +5,8 @@ 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
|
|
9
|
-
var
|
|
10
|
-
var SPLITS_FN_LABEL = 'splits';
|
|
11
|
-
var NAMES_FN_LABEL = 'names';
|
|
8
|
+
var mode_1 = require("../utils/settingsValidation/mode");
|
|
9
|
+
var constants_1 = require("../utils/constants");
|
|
12
10
|
function collectTreatments(splitObject) {
|
|
13
11
|
var conditions = splitObject.conditions;
|
|
14
12
|
// Rollout conditions are supposed to have the entire partitions list, so we find the first one.
|
|
@@ -44,8 +42,8 @@ function objectsToViews(splitObjects) {
|
|
|
44
42
|
}
|
|
45
43
|
function sdkManagerFactory(settings, splits, _a) {
|
|
46
44
|
var readinessManager = _a.readinessManager, sdkStatus = _a.sdkStatus;
|
|
47
|
-
var log = settings.log;
|
|
48
|
-
var
|
|
45
|
+
var log = settings.log, mode = settings.mode;
|
|
46
|
+
var isAsync = (0, mode_1.isConsumerMode)(mode);
|
|
49
47
|
return (0, objectAssign_1.objectAssign)(
|
|
50
48
|
// Proto-linkage of the readiness Event Emitter
|
|
51
49
|
Object.create(sdkStatus), {
|
|
@@ -53,26 +51,26 @@ function sdkManagerFactory(settings, splits, _a) {
|
|
|
53
51
|
* Get the feature flag object corresponding to the given feature flag name if valid
|
|
54
52
|
*/
|
|
55
53
|
split: function (featureFlagName) {
|
|
56
|
-
var splitName = (0, inputValidation_1.validateSplit)(log, featureFlagName, SPLIT_FN_LABEL);
|
|
57
|
-
if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, SPLIT_FN_LABEL) || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, SPLIT_FN_LABEL) || !splitName) {
|
|
58
|
-
return
|
|
54
|
+
var splitName = (0, inputValidation_1.validateSplit)(log, featureFlagName, constants_1.SPLIT_FN_LABEL);
|
|
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 isAsync ? Promise.resolve(null) : null;
|
|
59
57
|
}
|
|
60
58
|
var split = splits.getSplit(splitName);
|
|
61
59
|
if ((0, thenable_1.thenable)(split)) {
|
|
62
60
|
return split.catch(function () { return null; }).then(function (result) {
|
|
63
|
-
(0, inputValidation_1.validateSplitExistence)(log, readinessManager, splitName, result, SPLIT_FN_LABEL);
|
|
61
|
+
(0, inputValidation_1.validateSplitExistence)(log, readinessManager, splitName, result, constants_1.SPLIT_FN_LABEL);
|
|
64
62
|
return objectToView(result);
|
|
65
63
|
});
|
|
66
64
|
}
|
|
67
|
-
(0, inputValidation_1.validateSplitExistence)(log, readinessManager, splitName, split, SPLIT_FN_LABEL);
|
|
65
|
+
(0, inputValidation_1.validateSplitExistence)(log, readinessManager, splitName, split, constants_1.SPLIT_FN_LABEL);
|
|
68
66
|
return objectToView(split);
|
|
69
67
|
},
|
|
70
68
|
/**
|
|
71
69
|
* Get the feature flag objects present on the factory storage
|
|
72
70
|
*/
|
|
73
71
|
splits: function () {
|
|
74
|
-
if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, SPLITS_FN_LABEL) || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, SPLITS_FN_LABEL)) {
|
|
75
|
-
return
|
|
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 isAsync ? Promise.resolve([]) : [];
|
|
76
74
|
}
|
|
77
75
|
var currentSplits = splits.getAll();
|
|
78
76
|
return (0, thenable_1.thenable)(currentSplits) ?
|
|
@@ -83,8 +81,8 @@ function sdkManagerFactory(settings, splits, _a) {
|
|
|
83
81
|
* Get the feature flag names present on the factory storage
|
|
84
82
|
*/
|
|
85
83
|
names: function () {
|
|
86
|
-
if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, NAMES_FN_LABEL) || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, NAMES_FN_LABEL)) {
|
|
87
|
-
return
|
|
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 isAsync ? Promise.resolve([]) : [];
|
|
88
86
|
}
|
|
89
87
|
var splitNames = splits.getSplitNames();
|
|
90
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,26 @@ 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(onReadyCb);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Start periodic flush of async storages if not running synchronizer (producer mode)
|
|
82
92
|
if (impressionCountsCache && impressionCountsCache.start)
|
|
83
93
|
impressionCountsCache.start();
|
|
84
94
|
if (uniqueKeysCache && uniqueKeysCache.start)
|
|
85
95
|
uniqueKeysCache.start();
|
|
86
96
|
if (telemetry && telemetry.recordConfig)
|
|
87
97
|
telemetry.recordConfig();
|
|
98
|
+
onReadyCb();
|
|
88
99
|
}
|
|
89
100
|
}).catch(function (e) {
|
|
90
101
|
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)) {
|