@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.PAUSED = exports.ENABLED = exports.DISABLED = exports.NON_REQUESTED = exports.REQUESTED = exports.POLLING = exports.STREAMING = exports.AUTH_REJECTION = exports.SYNC_MODE_UPDATE = exports.ABLY_ERROR = exports.TOKEN_REFRESH = exports.SSE_CONNECTION_ERROR = exports.STREAMING_STATUS = void 0;
|
|
3
|
+
exports.MY_SEGMENT = exports.SEGMENT = exports.TOKEN = exports.TELEMETRY = exports.EVENTS = exports.IMPRESSIONS_COUNT = exports.IMPRESSIONS = exports.SPLITS = exports.NONE_ENUM = exports.DEBUG_ENUM = exports.OPTIMIZED_ENUM = exports.CONSUMER_PARTIAL_ENUM = exports.CONSUMER_ENUM = exports.STANDALONE_ENUM = exports.DEDUPED = exports.DROPPED = exports.QUEUED = exports.NAMES_FN_LABEL = exports.SPLITS_FN_LABEL = exports.SPLIT_FN_LABEL = exports.TRACK_FN_LABEL = exports.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS = exports.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET = exports.GET_TREATMENTS_BY_FLAG_SETS = exports.GET_TREATMENTS_BY_FLAG_SET = exports.GET_TREATMENTS_WITH_CONFIG = exports.GET_TREATMENT_WITH_CONFIG = exports.GET_TREATMENTS = exports.GET_TREATMENT = exports.CONSENT_UNKNOWN = exports.CONSENT_DECLINED = exports.CONSENT_GRANTED = 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.NONE = exports.OPTIMIZED = exports.DEBUG = exports.SPLIT_EVENT = exports.SPLIT_IMPRESSION = exports.NA = exports.UNKNOWN = exports.CONTROL_WITH_CONFIG = exports.CONTROL = void 0;
|
|
4
|
+
exports.PAUSED = exports.ENABLED = exports.DISABLED = exports.NON_REQUESTED = exports.REQUESTED = exports.POLLING = exports.STREAMING = exports.AUTH_REJECTION = exports.SYNC_MODE_UPDATE = exports.ABLY_ERROR = exports.TOKEN_REFRESH = exports.SSE_CONNECTION_ERROR = exports.STREAMING_STATUS = exports.OCCUPANCY_SEC = exports.OCCUPANCY_PRI = exports.CONNECTION_ESTABLISHED = exports.TRACK = exports.TREATMENTS_WITH_CONFIG_BY_FLAGSETS = exports.TREATMENTS_WITH_CONFIG_BY_FLAGSET = exports.TREATMENTS_BY_FLAGSETS = exports.TREATMENTS_BY_FLAGSET = exports.TREATMENTS_WITH_CONFIG = exports.TREATMENT_WITH_CONFIG = exports.TREATMENTS = exports.TREATMENT = void 0;
|
|
5
5
|
// Special treatments
|
|
6
6
|
exports.CONTROL = 'control';
|
|
7
7
|
exports.CONTROL_WITH_CONFIG = {
|
|
@@ -33,6 +33,20 @@ exports.STORAGE_PLUGGABLE = 'PLUGGABLE';
|
|
|
33
33
|
exports.CONSENT_GRANTED = 'GRANTED'; // The user has granted consent for tracking events and impressions
|
|
34
34
|
exports.CONSENT_DECLINED = 'DECLINED'; // The user has declined consent for tracking events and impressions
|
|
35
35
|
exports.CONSENT_UNKNOWN = 'UNKNOWN'; // The user has neither granted nor declined consent for tracking events and impressions
|
|
36
|
+
// Client method names
|
|
37
|
+
exports.GET_TREATMENT = 'getTreatment';
|
|
38
|
+
exports.GET_TREATMENTS = 'getTreatments';
|
|
39
|
+
exports.GET_TREATMENT_WITH_CONFIG = 'getTreatmentWithConfig';
|
|
40
|
+
exports.GET_TREATMENTS_WITH_CONFIG = 'getTreatmentsWithConfig';
|
|
41
|
+
exports.GET_TREATMENTS_BY_FLAG_SET = 'getTreatmentsByFlagSet';
|
|
42
|
+
exports.GET_TREATMENTS_BY_FLAG_SETS = 'getTreatmentsByFlagSets';
|
|
43
|
+
exports.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET = 'getTreatmentsWithConfigByFlagSet';
|
|
44
|
+
exports.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS = 'getTreatmentsWithConfigByFlagSets';
|
|
45
|
+
exports.TRACK_FN_LABEL = 'track';
|
|
46
|
+
// Manager method names
|
|
47
|
+
exports.SPLIT_FN_LABEL = 'split';
|
|
48
|
+
exports.SPLITS_FN_LABEL = 'splits';
|
|
49
|
+
exports.NAMES_FN_LABEL = 'names';
|
|
36
50
|
// Telemetry
|
|
37
51
|
exports.QUEUED = 0;
|
|
38
52
|
exports.DROPPED = 1;
|
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
|
]);
|
package/esm/sdkClient/client.js
CHANGED
|
@@ -4,9 +4,9 @@ import { getMatching, getBucketing } from '../utils/key';
|
|
|
4
4
|
import { validateSplitExistence } from '../utils/inputValidation/splitExistence';
|
|
5
5
|
import { validateTrafficTypeExistence } from '../utils/inputValidation/trafficTypeExistence';
|
|
6
6
|
import { SDK_NOT_READY } from '../utils/labels';
|
|
7
|
-
import { CONTROL, TREATMENT, TREATMENTS, TREATMENT_WITH_CONFIG, TREATMENTS_WITH_CONFIG, TRACK, TREATMENTS_WITH_CONFIG_BY_FLAGSETS, TREATMENTS_BY_FLAGSETS, TREATMENTS_BY_FLAGSET, TREATMENTS_WITH_CONFIG_BY_FLAGSET } from '../utils/constants';
|
|
7
|
+
import { CONTROL, TREATMENT, TREATMENTS, TREATMENT_WITH_CONFIG, TREATMENTS_WITH_CONFIG, TRACK, TREATMENTS_WITH_CONFIG_BY_FLAGSETS, TREATMENTS_BY_FLAGSETS, TREATMENTS_BY_FLAGSET, TREATMENTS_WITH_CONFIG_BY_FLAGSET, GET_TREATMENTS_WITH_CONFIG, GET_TREATMENTS_BY_FLAG_SETS, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, GET_TREATMENTS_BY_FLAG_SET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, GET_TREATMENT_WITH_CONFIG, GET_TREATMENT, GET_TREATMENTS, TRACK_FN_LABEL } from '../utils/constants';
|
|
8
8
|
import { IMPRESSION, IMPRESSION_QUEUEING } from '../logger/constants';
|
|
9
|
-
import {
|
|
9
|
+
import { isConsumerMode } from '../utils/settingsValidation/mode';
|
|
10
10
|
var treatmentNotReady = { treatment: CONTROL, label: SDK_NOT_READY };
|
|
11
11
|
function treatmentsNotReady(featureFlagNames) {
|
|
12
12
|
var evaluations = {};
|
|
@@ -21,34 +21,37 @@ function treatmentsNotReady(featureFlagNames) {
|
|
|
21
21
|
export function clientFactory(params) {
|
|
22
22
|
var readinessManager = params.sdkReadinessManager.readinessManager, storage = params.storage, settings = params.settings, impressionsTracker = params.impressionsTracker, eventTracker = params.eventTracker, telemetryTracker = params.telemetryTracker;
|
|
23
23
|
var log = settings.log, mode = settings.mode;
|
|
24
|
-
|
|
24
|
+
var isAsync = isConsumerMode(mode);
|
|
25
|
+
function getTreatment(key, featureFlagName, attributes, withConfig, methodName) {
|
|
25
26
|
if (withConfig === void 0) { withConfig = false; }
|
|
27
|
+
if (methodName === void 0) { methodName = GET_TREATMENT; }
|
|
26
28
|
var stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? TREATMENT_WITH_CONFIG : TREATMENT);
|
|
27
29
|
var wrapUp = function (evaluationResult) {
|
|
28
30
|
var queue = [];
|
|
29
|
-
var treatment = processEvaluation(evaluationResult, featureFlagName, key, attributes, withConfig,
|
|
31
|
+
var treatment = processEvaluation(evaluationResult, featureFlagName, key, attributes, withConfig, methodName, queue);
|
|
30
32
|
impressionsTracker.track(queue, attributes);
|
|
31
33
|
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
32
34
|
return treatment;
|
|
33
35
|
};
|
|
34
36
|
var evaluation = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
35
37
|
evaluateFeature(log, key, featureFlagName, attributes, storage) :
|
|
36
|
-
|
|
37
|
-
treatmentNotReady :
|
|
38
|
-
|
|
38
|
+
isAsync ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
|
|
39
|
+
Promise.resolve(treatmentNotReady) :
|
|
40
|
+
treatmentNotReady;
|
|
39
41
|
return thenable(evaluation) ? evaluation.then(function (res) { return wrapUp(res); }) : wrapUp(evaluation);
|
|
40
42
|
}
|
|
41
43
|
function getTreatmentWithConfig(key, featureFlagName, attributes) {
|
|
42
|
-
return getTreatment(key, featureFlagName, attributes, true);
|
|
44
|
+
return getTreatment(key, featureFlagName, attributes, true, GET_TREATMENT_WITH_CONFIG);
|
|
43
45
|
}
|
|
44
|
-
function getTreatments(key, featureFlagNames, attributes, withConfig) {
|
|
46
|
+
function getTreatments(key, featureFlagNames, attributes, withConfig, methodName) {
|
|
45
47
|
if (withConfig === void 0) { withConfig = false; }
|
|
48
|
+
if (methodName === void 0) { methodName = GET_TREATMENTS; }
|
|
46
49
|
var stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? TREATMENTS_WITH_CONFIG : TREATMENTS);
|
|
47
50
|
var wrapUp = function (evaluationResults) {
|
|
48
51
|
var queue = [];
|
|
49
52
|
var treatments = {};
|
|
50
53
|
Object.keys(evaluationResults).forEach(function (featureFlagName) {
|
|
51
|
-
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, attributes, withConfig,
|
|
54
|
+
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, attributes, withConfig, methodName, queue);
|
|
52
55
|
});
|
|
53
56
|
impressionsTracker.track(queue, attributes);
|
|
54
57
|
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
@@ -56,42 +59,45 @@ export function clientFactory(params) {
|
|
|
56
59
|
};
|
|
57
60
|
var evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
58
61
|
evaluateFeatures(log, key, featureFlagNames, attributes, storage) :
|
|
59
|
-
|
|
60
|
-
treatmentsNotReady(featureFlagNames) :
|
|
61
|
-
|
|
62
|
+
isAsync ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
|
|
63
|
+
Promise.resolve(treatmentsNotReady(featureFlagNames)) :
|
|
64
|
+
treatmentsNotReady(featureFlagNames);
|
|
62
65
|
return thenable(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
|
|
63
66
|
}
|
|
64
67
|
function getTreatmentsWithConfig(key, featureFlagNames, attributes) {
|
|
65
|
-
return getTreatments(key, featureFlagNames, attributes, true);
|
|
68
|
+
return getTreatments(key, featureFlagNames, attributes, true, GET_TREATMENTS_WITH_CONFIG);
|
|
66
69
|
}
|
|
67
|
-
function getTreatmentsByFlagSets(key, flagSetNames, attributes, withConfig, method) {
|
|
70
|
+
function getTreatmentsByFlagSets(key, flagSetNames, attributes, withConfig, method, methodName) {
|
|
68
71
|
if (withConfig === void 0) { withConfig = false; }
|
|
69
72
|
if (method === void 0) { method = TREATMENTS_BY_FLAGSETS; }
|
|
73
|
+
if (methodName === void 0) { methodName = GET_TREATMENTS_BY_FLAG_SETS; }
|
|
70
74
|
var stopTelemetryTracker = telemetryTracker.trackEval(method);
|
|
71
75
|
var wrapUp = function (evaluationResults) {
|
|
72
76
|
var queue = [];
|
|
73
77
|
var treatments = {};
|
|
74
78
|
var evaluations = evaluationResults;
|
|
75
79
|
Object.keys(evaluations).forEach(function (featureFlagName) {
|
|
76
|
-
treatments[featureFlagName] = processEvaluation(evaluations[featureFlagName], featureFlagName, key, attributes, withConfig,
|
|
80
|
+
treatments[featureFlagName] = processEvaluation(evaluations[featureFlagName], featureFlagName, key, attributes, withConfig, methodName, queue);
|
|
77
81
|
});
|
|
78
82
|
impressionsTracker.track(queue, attributes);
|
|
79
83
|
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
80
84
|
return treatments;
|
|
81
85
|
};
|
|
82
86
|
var evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
83
|
-
evaluateFeaturesByFlagSets(log, key, flagSetNames, attributes, storage,
|
|
84
|
-
|
|
87
|
+
evaluateFeaturesByFlagSets(log, key, flagSetNames, attributes, storage, methodName) :
|
|
88
|
+
isAsync ?
|
|
89
|
+
Promise.resolve({}) :
|
|
90
|
+
{};
|
|
85
91
|
return thenable(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
|
|
86
92
|
}
|
|
87
93
|
function getTreatmentsWithConfigByFlagSets(key, flagSetNames, attributes) {
|
|
88
|
-
return getTreatmentsByFlagSets(key, flagSetNames, attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSETS);
|
|
94
|
+
return getTreatmentsByFlagSets(key, flagSetNames, attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSETS, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS);
|
|
89
95
|
}
|
|
90
96
|
function getTreatmentsByFlagSet(key, flagSetName, attributes) {
|
|
91
|
-
return getTreatmentsByFlagSets(key, [flagSetName], attributes, false, TREATMENTS_BY_FLAGSET);
|
|
97
|
+
return getTreatmentsByFlagSets(key, [flagSetName], attributes, false, TREATMENTS_BY_FLAGSET, GET_TREATMENTS_BY_FLAG_SET);
|
|
92
98
|
}
|
|
93
99
|
function getTreatmentsWithConfigByFlagSet(key, flagSetName, attributes) {
|
|
94
|
-
return getTreatmentsByFlagSets(key, [flagSetName], attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSET);
|
|
100
|
+
return getTreatmentsByFlagSets(key, [flagSetName], attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET);
|
|
95
101
|
}
|
|
96
102
|
// Internal function
|
|
97
103
|
function processEvaluation(evaluation, featureFlagName, key, attributes, withConfig, invokingMethodName, queue) {
|
|
@@ -133,7 +139,7 @@ export function clientFactory(params) {
|
|
|
133
139
|
properties: properties
|
|
134
140
|
};
|
|
135
141
|
// 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.
|
|
136
|
-
validateTrafficTypeExistence(log, readinessManager, storage.splits, mode, trafficTypeName,
|
|
142
|
+
validateTrafficTypeExistence(log, readinessManager, storage.splits, mode, trafficTypeName, TRACK_FN_LABEL);
|
|
137
143
|
var result = eventTracker.track(eventData, size);
|
|
138
144
|
if (thenable(result)) {
|
|
139
145
|
return result.then(function (result) {
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { objectAssign } from '../utils/lang/objectAssign';
|
|
2
2
|
import { validateAttributes, validateEvent, validateEventValue, validateEventProperties, validateKey, validateSplit, validateSplits, validateTrafficType, validateIfNotDestroyed, validateIfOperational } from '../utils/inputValidation';
|
|
3
3
|
import { startsWith } from '../utils/lang';
|
|
4
|
-
import { CONTROL, CONTROL_WITH_CONFIG } from '../utils/constants';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { CONTROL, CONTROL_WITH_CONFIG, GET_TREATMENT, GET_TREATMENTS, GET_TREATMENTS_BY_FLAG_SET, GET_TREATMENTS_BY_FLAG_SETS, GET_TREATMENTS_WITH_CONFIG, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, GET_TREATMENT_WITH_CONFIG, TRACK_FN_LABEL } from '../utils/constants';
|
|
5
|
+
import { isConsumerMode } from '../utils/settingsValidation/mode';
|
|
6
|
+
import { validateFlagSets } from '../utils/settingsValidation/splitFilters';
|
|
7
7
|
/**
|
|
8
8
|
* Decorator that validates the input before actually executing the client methods.
|
|
9
9
|
* We should "guard" the client here, while not polluting the "real" implementation of those methods.
|
|
10
10
|
*/
|
|
11
11
|
export function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
12
|
-
var log = settings.log;
|
|
13
|
-
var
|
|
12
|
+
var log = settings.log, mode = settings.mode;
|
|
13
|
+
var isAsync = isConsumerMode(mode);
|
|
14
14
|
/**
|
|
15
15
|
* Avoid repeating this validations code
|
|
16
16
|
*/
|
|
17
17
|
function validateEvaluationParams(maybeKey, maybeFeatureFlagNameOrNames, maybeAttributes, methodName, maybeFlagSetNameOrNames) {
|
|
18
|
-
var multi = startsWith(methodName,
|
|
18
|
+
var multi = startsWith(methodName, GET_TREATMENTS);
|
|
19
19
|
var key = validateKey(log, maybeKey, methodName);
|
|
20
20
|
var splitOrSplits = false;
|
|
21
21
|
var flagSetOrFlagSets = [];
|
|
@@ -25,7 +25,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
25
25
|
var attributes = validateAttributes(log, maybeAttributes, methodName);
|
|
26
26
|
var isNotDestroyed = validateIfNotDestroyed(log, readinessManager, methodName);
|
|
27
27
|
if (maybeFlagSetNameOrNames) {
|
|
28
|
-
flagSetOrFlagSets =
|
|
28
|
+
flagSetOrFlagSets = validateFlagSets(log, methodName, maybeFlagSetNameOrNames, settings.sync.__splitFiltersValidation.groupedFilters.bySet);
|
|
29
29
|
}
|
|
30
30
|
validateIfOperational(log, readinessManager, methodName, splitOrSplits);
|
|
31
31
|
var valid = isNotDestroyed && key && (splitOrSplits || flagSetOrFlagSets.length > 0) && attributes !== false;
|
|
@@ -38,10 +38,10 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
function wrapResult(value) {
|
|
41
|
-
return
|
|
41
|
+
return isAsync ? Promise.resolve(value) : value;
|
|
42
42
|
}
|
|
43
43
|
function getTreatment(maybeKey, maybeFeatureFlagName, maybeAttributes) {
|
|
44
|
-
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes,
|
|
44
|
+
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, GET_TREATMENT);
|
|
45
45
|
if (params.valid) {
|
|
46
46
|
return client.getTreatment(params.key, params.splitOrSplits, params.attributes);
|
|
47
47
|
}
|
|
@@ -50,7 +50,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
function getTreatmentWithConfig(maybeKey, maybeFeatureFlagName, maybeAttributes) {
|
|
53
|
-
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes,
|
|
53
|
+
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, GET_TREATMENT_WITH_CONFIG);
|
|
54
54
|
if (params.valid) {
|
|
55
55
|
return client.getTreatmentWithConfig(params.key, params.splitOrSplits, params.attributes);
|
|
56
56
|
}
|
|
@@ -59,7 +59,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
function getTreatments(maybeKey, maybeFeatureFlagNames, maybeAttributes) {
|
|
62
|
-
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes,
|
|
62
|
+
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes, GET_TREATMENTS);
|
|
63
63
|
if (params.valid) {
|
|
64
64
|
return client.getTreatments(params.key, params.splitOrSplits, params.attributes);
|
|
65
65
|
}
|
|
@@ -71,7 +71,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
function getTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, maybeAttributes) {
|
|
74
|
-
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes,
|
|
74
|
+
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes, GET_TREATMENTS_WITH_CONFIG);
|
|
75
75
|
if (params.valid) {
|
|
76
76
|
return client.getTreatmentsWithConfig(params.key, params.splitOrSplits, params.attributes);
|
|
77
77
|
}
|
|
@@ -83,7 +83,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
function getTreatmentsByFlagSets(maybeKey, maybeFlagSets, maybeAttributes) {
|
|
86
|
-
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes,
|
|
86
|
+
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, GET_TREATMENTS_BY_FLAG_SETS, maybeFlagSets);
|
|
87
87
|
if (params.valid) {
|
|
88
88
|
return client.getTreatmentsByFlagSets(params.key, params.flagSetOrFlagSets, params.attributes);
|
|
89
89
|
}
|
|
@@ -92,7 +92,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
function getTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, maybeAttributes) {
|
|
95
|
-
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes,
|
|
95
|
+
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, maybeFlagSets);
|
|
96
96
|
if (params.valid) {
|
|
97
97
|
return client.getTreatmentsWithConfigByFlagSets(params.key, params.flagSetOrFlagSets, params.attributes);
|
|
98
98
|
}
|
|
@@ -101,7 +101,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
function getTreatmentsByFlagSet(maybeKey, maybeFlagSet, maybeAttributes) {
|
|
104
|
-
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes,
|
|
104
|
+
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, GET_TREATMENTS_BY_FLAG_SET, [maybeFlagSet]);
|
|
105
105
|
if (params.valid) {
|
|
106
106
|
return client.getTreatmentsByFlagSet(params.key, params.flagSetOrFlagSets[0], params.attributes);
|
|
107
107
|
}
|
|
@@ -110,7 +110,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
function getTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, maybeAttributes) {
|
|
113
|
-
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes,
|
|
113
|
+
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, [maybeFlagSet]);
|
|
114
114
|
if (params.valid) {
|
|
115
115
|
return client.getTreatmentsWithConfigByFlagSet(params.key, params.flagSetOrFlagSets[0], params.attributes);
|
|
116
116
|
}
|
|
@@ -119,17 +119,17 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
function track(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties) {
|
|
122
|
-
var key = validateKey(log, maybeKey,
|
|
123
|
-
var tt = validateTrafficType(log, maybeTT,
|
|
124
|
-
var event = validateEvent(log, maybeEvent,
|
|
125
|
-
var eventValue = validateEventValue(log, maybeEventValue,
|
|
126
|
-
var _a = validateEventProperties(log, maybeProperties,
|
|
127
|
-
var isNotDestroyed = validateIfNotDestroyed(log, readinessManager,
|
|
122
|
+
var key = validateKey(log, maybeKey, TRACK_FN_LABEL);
|
|
123
|
+
var tt = validateTrafficType(log, maybeTT, TRACK_FN_LABEL);
|
|
124
|
+
var event = validateEvent(log, maybeEvent, TRACK_FN_LABEL);
|
|
125
|
+
var eventValue = validateEventValue(log, maybeEventValue, TRACK_FN_LABEL);
|
|
126
|
+
var _a = validateEventProperties(log, maybeProperties, TRACK_FN_LABEL), properties = _a.properties, size = _a.size;
|
|
127
|
+
var isNotDestroyed = validateIfNotDestroyed(log, readinessManager, TRACK_FN_LABEL);
|
|
128
128
|
if (isNotDestroyed && key && tt && event && eventValue !== false && properties !== false) { // @ts-expect-error
|
|
129
129
|
return client.track(key, tt, event, eventValue, properties, size);
|
|
130
130
|
}
|
|
131
131
|
else {
|
|
132
|
-
return
|
|
132
|
+
return isAsync ? Promise.resolve(false) : false;
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
return {
|
package/esm/sdkManager/index.js
CHANGED
|
@@ -2,10 +2,8 @@ import { objectAssign } from '../utils/lang/objectAssign';
|
|
|
2
2
|
import { thenable } from '../utils/promise/thenable';
|
|
3
3
|
import { find } from '../utils/lang';
|
|
4
4
|
import { validateSplit, validateSplitExistence, validateIfNotDestroyed, validateIfOperational } from '../utils/inputValidation';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
var SPLITS_FN_LABEL = 'splits';
|
|
8
|
-
var NAMES_FN_LABEL = 'names';
|
|
5
|
+
import { isConsumerMode } from '../utils/settingsValidation/mode';
|
|
6
|
+
import { SPLIT_FN_LABEL, SPLITS_FN_LABEL, NAMES_FN_LABEL } from '../utils/constants';
|
|
9
7
|
function collectTreatments(splitObject) {
|
|
10
8
|
var conditions = splitObject.conditions;
|
|
11
9
|
// Rollout conditions are supposed to have the entire partitions list, so we find the first one.
|
|
@@ -41,8 +39,8 @@ function objectsToViews(splitObjects) {
|
|
|
41
39
|
}
|
|
42
40
|
export function sdkManagerFactory(settings, splits, _a) {
|
|
43
41
|
var readinessManager = _a.readinessManager, sdkStatus = _a.sdkStatus;
|
|
44
|
-
var log = settings.log;
|
|
45
|
-
var
|
|
42
|
+
var log = settings.log, mode = settings.mode;
|
|
43
|
+
var isAsync = isConsumerMode(mode);
|
|
46
44
|
return objectAssign(
|
|
47
45
|
// Proto-linkage of the readiness Event Emitter
|
|
48
46
|
Object.create(sdkStatus), {
|
|
@@ -52,7 +50,7 @@ export function sdkManagerFactory(settings, splits, _a) {
|
|
|
52
50
|
split: function (featureFlagName) {
|
|
53
51
|
var splitName = validateSplit(log, featureFlagName, SPLIT_FN_LABEL);
|
|
54
52
|
if (!validateIfNotDestroyed(log, readinessManager, SPLIT_FN_LABEL) || !validateIfOperational(log, readinessManager, SPLIT_FN_LABEL) || !splitName) {
|
|
55
|
-
return
|
|
53
|
+
return isAsync ? Promise.resolve(null) : null;
|
|
56
54
|
}
|
|
57
55
|
var split = splits.getSplit(splitName);
|
|
58
56
|
if (thenable(split)) {
|
|
@@ -69,7 +67,7 @@ export function sdkManagerFactory(settings, splits, _a) {
|
|
|
69
67
|
*/
|
|
70
68
|
splits: function () {
|
|
71
69
|
if (!validateIfNotDestroyed(log, readinessManager, SPLITS_FN_LABEL) || !validateIfOperational(log, readinessManager, SPLITS_FN_LABEL)) {
|
|
72
|
-
return
|
|
70
|
+
return isAsync ? Promise.resolve([]) : [];
|
|
73
71
|
}
|
|
74
72
|
var currentSplits = splits.getAll();
|
|
75
73
|
return thenable(currentSplits) ?
|
|
@@ -81,7 +79,7 @@ export function sdkManagerFactory(settings, splits, _a) {
|
|
|
81
79
|
*/
|
|
82
80
|
names: function () {
|
|
83
81
|
if (!validateIfNotDestroyed(log, readinessManager, NAMES_FN_LABEL) || !validateIfOperational(log, readinessManager, NAMES_FN_LABEL)) {
|
|
84
|
-
return
|
|
82
|
+
return isAsync ? Promise.resolve([]) : [];
|
|
85
83
|
}
|
|
86
84
|
var splitNames = splits.getSplitNames();
|
|
87
85
|
return thenable(splitNames) ?
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { startsWith } from '../utils/lang';
|
|
2
|
+
import { hash } from '../utils/murmur3/murmur3';
|
|
2
3
|
var everythingAtTheEnd = /[^.]+$/;
|
|
3
4
|
var DEFAULT_PREFIX = 'SPLITIO';
|
|
4
5
|
export function validatePrefix(prefix) {
|
|
@@ -54,6 +55,16 @@ var KeyBuilder = /** @class */ (function () {
|
|
|
54
55
|
throw new Error('Invalid latency key provided');
|
|
55
56
|
}
|
|
56
57
|
};
|
|
58
|
+
KeyBuilder.prototype.buildHashKey = function () {
|
|
59
|
+
return this.prefix + ".hash";
|
|
60
|
+
};
|
|
57
61
|
return KeyBuilder;
|
|
58
62
|
}());
|
|
59
63
|
export { KeyBuilder };
|
|
64
|
+
/**
|
|
65
|
+
* Generates a murmur32 hash based on the authorization key and the feature flags filter query.
|
|
66
|
+
* The hash is in hexadecimal format (8 characters max, 32 bits).
|
|
67
|
+
*/
|
|
68
|
+
export function getStorageHash(settings) {
|
|
69
|
+
return hash(settings.core.authorizationKey + "::" + settings.sync.__splitFiltersValidation.queryString).toString(16);
|
|
70
|
+
}
|
|
@@ -6,7 +6,7 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
6
6
|
function KeyBuilderCS(prefix, matchingKey) {
|
|
7
7
|
var _this = _super.call(this, prefix) || this;
|
|
8
8
|
_this.matchingKey = matchingKey;
|
|
9
|
-
_this.regexSplitsCacheKey = new RegExp("^" + prefix + "\\.
|
|
9
|
+
_this.regexSplitsCacheKey = new RegExp("^" + prefix + "\\.");
|
|
10
10
|
return _this;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
@@ -36,9 +36,6 @@ var KeyBuilderCS = /** @class */ (function (_super) {
|
|
|
36
36
|
KeyBuilderCS.prototype.isSplitsCacheKey = function (key) {
|
|
37
37
|
return this.regexSplitsCacheKey.test(key);
|
|
38
38
|
};
|
|
39
|
-
KeyBuilderCS.prototype.buildSplitsFilterQueryKey = function () {
|
|
40
|
-
return this.prefix + ".splits.filterQuery";
|
|
41
|
-
};
|
|
42
39
|
return KeyBuilderCS;
|
|
43
40
|
}(KeyBuilder));
|
|
44
41
|
export { KeyBuilderCS };
|