@splitsoftware/splitio-commons 1.11.0 → 1.12.0
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 +15 -9
- package/cjs/evaluator/index.js +19 -3
- package/cjs/logger/constants.js +6 -4
- package/cjs/logger/messages/warn.js +5 -3
- package/cjs/sdkClient/client.js +19 -16
- package/cjs/sdkClient/clientInputValidation.js +16 -16
- package/cjs/sdkFactory/index.js +1 -1
- package/cjs/sdkManager/index.js +14 -13
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +3 -10
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +2 -10
- package/cjs/storages/inRedis/RedisAdapter.js +32 -13
- package/cjs/storages/inRedis/SegmentsCacheInRedis.js +2 -2
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +39 -22
- package/cjs/storages/inRedis/index.js +1 -1
- package/cjs/storages/pluggable/SplitsCachePluggable.js +28 -11
- package/cjs/storages/pluggable/index.js +1 -1
- package/cjs/utils/constants/index.js +16 -2
- package/cjs/utils/inputValidation/index.js +5 -5
- package/cjs/utils/inputValidation/{splitExistance.js → splitExistence.js} +3 -3
- package/cjs/utils/inputValidation/{trafficTypeExistance.js → trafficTypeExistence.js} +6 -6
- package/cjs/utils/lang/sets.js +11 -1
- package/cjs/utils/settingsValidation/index.js +1 -1
- package/cjs/utils/settingsValidation/splitFilters.js +25 -17
- package/esm/evaluator/index.js +20 -4
- package/esm/logger/constants.js +4 -2
- package/esm/logger/messages/warn.js +5 -3
- package/esm/sdkClient/client.js +20 -17
- package/esm/sdkClient/clientInputValidation.js +18 -18
- package/esm/sdkFactory/index.js +1 -1
- package/esm/sdkManager/index.js +11 -10
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +4 -11
- package/esm/storages/inMemory/SplitsCacheInMemory.js +3 -11
- package/esm/storages/inRedis/RedisAdapter.js +32 -13
- package/esm/storages/inRedis/SegmentsCacheInRedis.js +2 -2
- package/esm/storages/inRedis/SplitsCacheInRedis.js +40 -23
- package/esm/storages/inRedis/index.js +1 -1
- package/esm/storages/pluggable/SplitsCachePluggable.js +29 -12
- package/esm/storages/pluggable/index.js +1 -1
- package/esm/utils/constants/index.js +14 -0
- package/esm/utils/inputValidation/index.js +2 -2
- package/esm/utils/inputValidation/{splitExistance.js → splitExistence.js} +1 -1
- package/esm/utils/inputValidation/{trafficTypeExistance.js → trafficTypeExistence.js} +4 -4
- package/esm/utils/lang/sets.js +9 -0
- package/esm/utils/settingsValidation/index.js +1 -1
- package/esm/utils/settingsValidation/splitFilters.js +17 -9
- package/package.json +1 -1
- package/src/evaluator/index.ts +24 -4
- package/src/logger/constants.ts +4 -2
- package/src/logger/messages/warn.ts +9 -7
- package/src/sdkClient/client.ts +18 -18
- package/src/sdkClient/clientInputValidation.ts +18 -18
- package/src/sdkFactory/index.ts +1 -1
- package/src/sdkFactory/types.ts +3 -7
- package/src/sdkManager/index.ts +14 -14
- package/src/storages/AbstractSplitsCacheAsync.ts +1 -1
- package/src/storages/AbstractSplitsCacheSync.ts +1 -1
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +8 -15
- package/src/storages/inMemory/SplitsCacheInMemory.ts +6 -14
- package/src/storages/inRedis/EventsCacheInRedis.ts +3 -3
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +3 -3
- package/src/storages/inRedis/ImpressionsCacheInRedis.ts +3 -3
- package/src/storages/inRedis/RedisAdapter.ts +38 -16
- package/src/storages/inRedis/SegmentsCacheInRedis.ts +5 -5
- package/src/storages/inRedis/SplitsCacheInRedis.ts +49 -28
- package/src/storages/inRedis/TelemetryCacheInRedis.ts +2 -2
- package/src/storages/inRedis/UniqueKeysCacheInRedis.ts +3 -3
- package/src/storages/inRedis/index.ts +1 -1
- package/src/storages/pluggable/SplitsCachePluggable.ts +35 -13
- package/src/storages/pluggable/index.ts +1 -1
- package/src/storages/types.ts +5 -5
- package/src/trackers/impressionObserver/utils.ts +1 -1
- package/src/types.ts +0 -2
- package/src/utils/constants/index.ts +16 -0
- package/src/utils/inputValidation/index.ts +2 -2
- package/src/utils/inputValidation/{splitExistance.ts → splitExistence.ts} +1 -1
- package/src/utils/inputValidation/{trafficTypeExistance.ts → trafficTypeExistence.ts} +4 -4
- package/src/utils/lang/sets.ts +9 -1
- package/src/utils/redis/RedisMock.ts +1 -3
- package/src/utils/settingsValidation/index.ts +1 -1
- package/src/utils/settingsValidation/splitFilters.ts +19 -11
- package/types/evaluator/index.d.ts +1 -1
- package/types/logger/constants.d.ts +4 -2
- package/types/sdkClient/identity.d.ts +6 -0
- package/types/sdkFactory/types.d.ts +3 -3
- package/types/sdkManager/index.d.ts +2 -3
- package/types/storages/AbstractSplitsCacheAsync.d.ts +1 -1
- package/types/storages/AbstractSplitsCacheSync.d.ts +1 -1
- package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +1 -1
- package/types/storages/inMemory/SplitsCacheInMemory.d.ts +1 -1
- package/types/storages/inRedis/EventsCacheInRedis.d.ts +2 -2
- package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +3 -2
- package/types/storages/inRedis/ImpressionsCacheInRedis.d.ts +2 -2
- package/types/storages/inRedis/RedisAdapter.d.ts +1 -1
- package/types/storages/inRedis/SegmentsCacheInRedis.d.ts +3 -3
- package/types/storages/inRedis/SplitsCacheInRedis.d.ts +10 -14
- package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +2 -2
- package/types/storages/inRedis/{uniqueKeysCacheInRedis.d.ts → UniqueKeysCacheInRedis.d.ts} +3 -2
- package/types/storages/pluggable/SplitsCachePluggable.d.ts +10 -9
- package/types/storages/types.d.ts +5 -5
- package/types/trackers/impressionObserver/utils.d.ts +1 -1
- package/types/types.d.ts +0 -2
- package/types/utils/constants/index.d.ts +12 -0
- package/types/utils/inputValidation/index.d.ts +2 -2
- package/types/utils/inputValidation/sdkKey.d.ts +7 -0
- package/types/utils/inputValidation/splitExistence.d.ts +7 -0
- package/types/utils/inputValidation/trafficTypeExistence.d.ts +9 -0
- package/types/utils/lang/sets.d.ts +1 -0
- package/types/utils/settingsValidation/splitFilters.d.ts +3 -2
- package/types/myLogger.d.ts +0 -5
- package/types/sdkClient/types.d.ts +0 -18
- package/types/storages/inMemory/CountsCacheInMemory.d.ts +0 -20
- package/types/storages/inMemory/LatenciesCacheInMemory.d.ts +0 -20
- package/types/storages/inRedis/CountsCacheInRedis.d.ts +0 -9
- package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +0 -9
- package/types/storages/metadataBuilder.d.ts +0 -3
- package/types/sync/offline/LocalhostFromFile.d.ts +0 -2
- package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +0 -2
- package/types/sync/offline/updaters/splitChangesUpdater.d.ts +0 -0
- package/types/sync/submitters/eventsSyncTask.d.ts +0 -8
- package/types/sync/submitters/impressionCountsSubmitterInRedis.d.ts +0 -5
- package/types/sync/submitters/impressionCountsSyncTask.d.ts +0 -13
- package/types/sync/submitters/impressionsSyncTask.d.ts +0 -14
- package/types/sync/submitters/metricsSyncTask.d.ts +0 -12
- package/types/sync/submitters/submitterSyncTask.d.ts +0 -10
- package/types/sync/submitters/uniqueKeysSubmitterInRedis.d.ts +0 -5
- package/types/sync/syncTaskComposite.d.ts +0 -5
- package/types/trackers/filter/bloomFilter.d.ts +0 -10
- package/types/trackers/filter/dictionaryFilter.d.ts +0 -8
- package/types/trackers/filter/types.d.ts +0 -5
- package/types/utils/timeTracker/index.d.ts +0 -70
- /package/types/storages/inMemory/{uniqueKeysCacheInMemory.d.ts → UniqueKeysCacheInMemory.d.ts} +0 -0
- /package/types/storages/inMemory/{uniqueKeysCacheInMemoryCS.d.ts → UniqueKeysCacheInMemoryCS.d.ts} +0 -0
package/CHANGES.txt
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
+
1.12.0 (December 4, 2023)
|
|
2
|
+
- Added support for Flag Sets in "consumer" and "partial consumer" modes for Pluggable and Redis storages.
|
|
3
|
+
- Updated evaluation flow to log a warning when using flag sets that don't contain cached feature flags.
|
|
4
|
+
- Updated Redis adapter to handle timeouts and queueing of some missing commands: 'hincrby', 'popNRaw', and 'pipeline.exec'.
|
|
5
|
+
- Bugfixing - Fixed manager methods in consumer modes to return results in a promise when the SDK is not operational (not ready or destroyed).
|
|
6
|
+
|
|
1
7
|
1.11.0 (November 3, 2023)
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
- Added support for Flag Sets on the SDK, which enables grouping feature flags and interacting with the group rather than individually (more details in our documentation):
|
|
9
|
+
- Added new variations of the get treatment methods to support evaluating flags in given flag set/s.
|
|
10
|
+
- getTreatmentsByFlagSet and getTreatmentsByFlagSets
|
|
11
|
+
- getTreatmentsWithConfigByFlagSets and getTreatmentsWithConfigByFlagSets
|
|
12
|
+
- Added a new optional Split Filter configuration option. This allows the SDK and Split services to only synchronize the flags in the specified flag sets, avoiding unused or unwanted flags from being synced on the SDK instance, bringing all the benefits from a reduced payload.
|
|
13
|
+
- Note: Only applicable when the SDK is in charge of the rollout data synchronization. When not applicable, the SDK will log a warning on init.
|
|
14
|
+
- Added `sets` property to the `SplitView` object returned by the `split` and `splits` methods of the SDK manager to expose flag sets on flag views.
|
|
15
|
+
- Bugfixing - Fixed SDK key validation in NodeJS to ensure the SDK_READY_TIMED_OUT event is emitted when a client-side type SDK key is provided instead of a server-side one (Related to issue https://github.com/splitio/javascript-client/issues/768).
|
|
10
16
|
|
|
11
17
|
1.10.0 (October 20, 2023)
|
|
12
18
|
- Added `defaultTreatment` property to the `SplitView` object returned by the `split` and `splits` methods of the SDK manager (Related to issue https://github.com/splitio/javascript-commons/issues/225).
|
|
@@ -53,7 +59,7 @@
|
|
|
53
59
|
- Added a new impressions mode for the SDK called NONE, to be used in factory when there is no desire to capture impressions on an SDK factory to feed Split's analytics engine. Running NONE mode, the SDK will only capture unique keys evaluated for a particular feature flag instead of full blown impressions.
|
|
54
60
|
- Updated SDK telemetry to support pluggable storage, partial consumer mode, and synchronizer.
|
|
55
61
|
- Updated storage implementations to improve the performance of feature flag evaluations (i.e., `getTreatment(s)` method calls) when using the default storage in memory.
|
|
56
|
-
- Updated evaluation flow to avoid
|
|
62
|
+
- Updated evaluation flow (i.e., `getTreatment(s)` method calls) to avoid calling the storage for cached feature flags when the SDK is not ready or ready from cache. It applies to all SDK modes.
|
|
57
63
|
|
|
58
64
|
1.6.1 (July 22, 2022)
|
|
59
65
|
- Updated GoogleAnalyticsToSplit integration to validate `autoRequire` config parameter and avoid some wrong warning logs when mapping GA hit fields to Split event properties.
|
package/cjs/evaluator/index.js
CHANGED
|
@@ -7,6 +7,7 @@ var thenable_1 = require("../utils/promise/thenable");
|
|
|
7
7
|
var LabelsConstants = (0, tslib_1.__importStar)(require("../utils/labels"));
|
|
8
8
|
var constants_1 = require("../utils/constants");
|
|
9
9
|
var sets_1 = require("../utils/lang/sets");
|
|
10
|
+
var constants_2 = require("../logger/constants");
|
|
10
11
|
var treatmentException = {
|
|
11
12
|
treatment: constants_1.CONTROL,
|
|
12
13
|
label: LabelsConstants.EXCEPTION,
|
|
@@ -56,8 +57,23 @@ function evaluateFeatures(log, key, splitNames, attributes, storage) {
|
|
|
56
57
|
getEvaluations(log, splitNames, parsedSplits, key, attributes, storage);
|
|
57
58
|
}
|
|
58
59
|
exports.evaluateFeatures = evaluateFeatures;
|
|
59
|
-
function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage) {
|
|
60
|
+
function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, method) {
|
|
60
61
|
var storedFlagNames;
|
|
62
|
+
function evaluate(featureFlagsByFlagSets) {
|
|
63
|
+
var featureFlags = new sets_1._Set();
|
|
64
|
+
for (var i = 0; i < flagSets.length; i++) {
|
|
65
|
+
var featureFlagByFlagSet = featureFlagsByFlagSets[i];
|
|
66
|
+
if (featureFlagByFlagSet.size) {
|
|
67
|
+
featureFlags = (0, sets_1.returnSetsUnion)(featureFlags, featureFlagByFlagSet);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
log.warn(constants_2.WARN_FLAGSET_WITHOUT_FLAGS, [method, flagSets[i]]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return featureFlags.size ?
|
|
74
|
+
evaluateFeatures(log, key, (0, sets_1.setToArray)(featureFlags), attributes, storage) :
|
|
75
|
+
{};
|
|
76
|
+
}
|
|
61
77
|
// get features by flag sets
|
|
62
78
|
try {
|
|
63
79
|
storedFlagNames = storage.splits.getNamesByFlagSets(flagSets);
|
|
@@ -68,11 +84,11 @@ function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage) {
|
|
|
68
84
|
}
|
|
69
85
|
// evaluate related features
|
|
70
86
|
return (0, thenable_1.thenable)(storedFlagNames) ?
|
|
71
|
-
storedFlagNames.then(function (
|
|
87
|
+
storedFlagNames.then(function (storedFlagNames) { return evaluate(storedFlagNames); })
|
|
72
88
|
.catch(function () {
|
|
73
89
|
return {};
|
|
74
90
|
}) :
|
|
75
|
-
|
|
91
|
+
evaluate(storedFlagNames);
|
|
76
92
|
}
|
|
77
93
|
exports.evaluateFeaturesByFlagSets = evaluateFeaturesByFlagSets;
|
|
78
94
|
function getEvaluation(log, splitJSON, key, attributes, storage) {
|
package/cjs/logger/constants.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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.
|
|
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 = 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.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
|
+
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,
|
|
8
8
|
* in order to reduce the minimal SDK size for Browser and eventually other client-side environments.
|
|
@@ -94,14 +94,16 @@ exports.WARN_NOT_EXISTENT_SPLIT = 215;
|
|
|
94
94
|
exports.WARN_LOWERCASE_TRAFFIC_TYPE = 216;
|
|
95
95
|
exports.WARN_NOT_EXISTENT_TT = 217;
|
|
96
96
|
exports.WARN_INTEGRATION_INVALID = 218;
|
|
97
|
+
exports.WARN_SPLITS_FILTER_IGNORED = 219;
|
|
97
98
|
exports.WARN_SPLITS_FILTER_INVALID = 220;
|
|
98
99
|
exports.WARN_SPLITS_FILTER_EMPTY = 221;
|
|
99
100
|
exports.WARN_SDK_KEY = 222;
|
|
100
101
|
exports.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 223;
|
|
101
102
|
exports.STREAMING_PARSING_SPLIT_UPDATE = 224;
|
|
102
|
-
exports.
|
|
103
|
-
exports.
|
|
103
|
+
exports.WARN_INVALID_FLAGSET = 225;
|
|
104
|
+
exports.WARN_LOWERCASE_FLAGSET = 226;
|
|
104
105
|
exports.WARN_FLAGSET_NOT_CONFIGURED = 227;
|
|
106
|
+
exports.WARN_FLAGSET_WITHOUT_FLAGS = 228;
|
|
105
107
|
exports.ERROR_ENGINE_COMBINER_IFELSEIF = 300;
|
|
106
108
|
exports.ERROR_LOGLEVEL_INVALID = 301;
|
|
107
109
|
exports.ERROR_CLIENT_LISTENER = 302;
|
|
@@ -27,14 +27,16 @@ exports.codesWarn = error_1.codesError.concat([
|
|
|
27
27
|
[c.WARN_NOT_EXISTENT_SPLIT, '%s: feature flag "%s" does not exist in this environment. Please double check what feature flags exist in the Split user interface.'],
|
|
28
28
|
[c.WARN_LOWERCASE_TRAFFIC_TYPE, '%s: traffic_type_name should be all lowercase - converting string to lowercase.'],
|
|
29
29
|
[c.WARN_NOT_EXISTENT_TT, '%s: traffic type "%s" does not have any corresponding feature flag in this environment, make sure you\'re tracking your events to a valid traffic type defined in the Split user interface.'],
|
|
30
|
-
[c.WARN_FLAGSET_NOT_CONFIGURED, '%s:
|
|
30
|
+
[c.WARN_FLAGSET_NOT_CONFIGURED, '%s: you passed %s which is not part of the configured FlagSetsFilter, ignoring Flag Set.'],
|
|
31
31
|
// initialization / settings validation
|
|
32
32
|
[c.WARN_INTEGRATION_INVALID, c.LOG_PREFIX_SETTINGS + ': %s integration item(s) at settings is invalid. %s'],
|
|
33
|
+
[c.WARN_SPLITS_FILTER_IGNORED, c.LOG_PREFIX_SETTINGS + ': feature flag filters are not applicable for Consumer modes where the SDK does not keep rollout data in sync. Filters were discarded'],
|
|
33
34
|
[c.WARN_SPLITS_FILTER_INVALID, c.LOG_PREFIX_SETTINGS + ': feature flag filter at position %s is invalid. It must be an object with a valid filter type ("bySet", "byName" or "byPrefix") and a list of "values".'],
|
|
34
35
|
[c.WARN_SPLITS_FILTER_EMPTY, c.LOG_PREFIX_SETTINGS + ': feature flag filter configuration must be a non-empty array of filter objects.'],
|
|
35
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'],
|
|
36
37
|
[c.STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching MySegments due to an error processing %s notification: %s'],
|
|
37
38
|
[c.STREAMING_PARSING_SPLIT_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching SplitChanges due to an error processing SPLIT_UPDATE notification: %s'],
|
|
38
|
-
[c.
|
|
39
|
-
[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
|
+
[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.'],
|
|
40
42
|
]);
|
package/cjs/sdkClient/client.js
CHANGED
|
@@ -4,8 +4,8 @@ exports.clientFactory = void 0;
|
|
|
4
4
|
var evaluator_1 = require("../evaluator");
|
|
5
5
|
var thenable_1 = require("../utils/promise/thenable");
|
|
6
6
|
var key_1 = require("../utils/key");
|
|
7
|
-
var
|
|
8
|
-
var
|
|
7
|
+
var splitExistence_1 = require("../utils/inputValidation/splitExistence");
|
|
8
|
+
var trafficTypeExistence_1 = require("../utils/inputValidation/trafficTypeExistence");
|
|
9
9
|
var labels_1 = require("../utils/labels");
|
|
10
10
|
var constants_1 = require("../utils/constants");
|
|
11
11
|
var constants_2 = require("../logger/constants");
|
|
@@ -24,12 +24,13 @@ 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
|
-
function getTreatment(key, featureFlagName, attributes, withConfig) {
|
|
27
|
+
function getTreatment(key, featureFlagName, attributes, withConfig, methodName) {
|
|
28
28
|
if (withConfig === void 0) { withConfig = false; }
|
|
29
|
+
if (methodName === void 0) { methodName = constants_1.GET_TREATMENT; }
|
|
29
30
|
var stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? constants_1.TREATMENT_WITH_CONFIG : constants_1.TREATMENT);
|
|
30
31
|
var wrapUp = function (evaluationResult) {
|
|
31
32
|
var queue = [];
|
|
32
|
-
var treatment = processEvaluation(evaluationResult, featureFlagName, key, attributes, withConfig,
|
|
33
|
+
var treatment = processEvaluation(evaluationResult, featureFlagName, key, attributes, withConfig, methodName, queue);
|
|
33
34
|
impressionsTracker.track(queue, attributes);
|
|
34
35
|
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
35
36
|
return treatment;
|
|
@@ -42,16 +43,17 @@ function clientFactory(params) {
|
|
|
42
43
|
return (0, thenable_1.thenable)(evaluation) ? evaluation.then(function (res) { return wrapUp(res); }) : wrapUp(evaluation);
|
|
43
44
|
}
|
|
44
45
|
function getTreatmentWithConfig(key, featureFlagName, attributes) {
|
|
45
|
-
return getTreatment(key, featureFlagName, attributes, true);
|
|
46
|
+
return getTreatment(key, featureFlagName, attributes, true, constants_1.GET_TREATMENT_WITH_CONFIG);
|
|
46
47
|
}
|
|
47
|
-
function getTreatments(key, featureFlagNames, attributes, withConfig) {
|
|
48
|
+
function getTreatments(key, featureFlagNames, attributes, withConfig, methodName) {
|
|
48
49
|
if (withConfig === void 0) { withConfig = false; }
|
|
50
|
+
if (methodName === void 0) { methodName = constants_1.GET_TREATMENTS; }
|
|
49
51
|
var stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? constants_1.TREATMENTS_WITH_CONFIG : constants_1.TREATMENTS);
|
|
50
52
|
var wrapUp = function (evaluationResults) {
|
|
51
53
|
var queue = [];
|
|
52
54
|
var treatments = {};
|
|
53
55
|
Object.keys(evaluationResults).forEach(function (featureFlagName) {
|
|
54
|
-
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, attributes, withConfig,
|
|
56
|
+
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, attributes, withConfig, methodName, queue);
|
|
55
57
|
});
|
|
56
58
|
impressionsTracker.track(queue, attributes);
|
|
57
59
|
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
@@ -65,36 +67,37 @@ function clientFactory(params) {
|
|
|
65
67
|
return (0, thenable_1.thenable)(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
|
|
66
68
|
}
|
|
67
69
|
function getTreatmentsWithConfig(key, featureFlagNames, attributes) {
|
|
68
|
-
return getTreatments(key, featureFlagNames, attributes, true);
|
|
70
|
+
return getTreatments(key, featureFlagNames, attributes, true, constants_1.GET_TREATMENTS_WITH_CONFIG);
|
|
69
71
|
}
|
|
70
|
-
function getTreatmentsByFlagSets(key, flagSetNames, attributes, withConfig, method) {
|
|
72
|
+
function getTreatmentsByFlagSets(key, flagSetNames, attributes, withConfig, method, methodName) {
|
|
71
73
|
if (withConfig === void 0) { withConfig = false; }
|
|
72
74
|
if (method === void 0) { method = constants_1.TREATMENTS_BY_FLAGSETS; }
|
|
75
|
+
if (methodName === void 0) { methodName = constants_1.GET_TREATMENTS_BY_FLAG_SETS; }
|
|
73
76
|
var stopTelemetryTracker = telemetryTracker.trackEval(method);
|
|
74
77
|
var wrapUp = function (evaluationResults) {
|
|
75
78
|
var queue = [];
|
|
76
79
|
var treatments = {};
|
|
77
80
|
var evaluations = evaluationResults;
|
|
78
81
|
Object.keys(evaluations).forEach(function (featureFlagName) {
|
|
79
|
-
treatments[featureFlagName] = processEvaluation(evaluations[featureFlagName], featureFlagName, key, attributes, withConfig,
|
|
82
|
+
treatments[featureFlagName] = processEvaluation(evaluations[featureFlagName], featureFlagName, key, attributes, withConfig, methodName, queue);
|
|
80
83
|
});
|
|
81
84
|
impressionsTracker.track(queue, attributes);
|
|
82
85
|
stopTelemetryTracker(queue[0] && queue[0].label);
|
|
83
86
|
return treatments;
|
|
84
87
|
};
|
|
85
88
|
var evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
|
|
86
|
-
(0, evaluator_1.evaluateFeaturesByFlagSets)(log, key, flagSetNames, attributes, storage) :
|
|
89
|
+
(0, evaluator_1.evaluateFeaturesByFlagSets)(log, key, flagSetNames, attributes, storage, methodName) :
|
|
87
90
|
(0, utils_1.isStorageSync)(settings) ? {} : Promise.resolve({}); // Promisify if async
|
|
88
91
|
return (0, thenable_1.thenable)(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
|
|
89
92
|
}
|
|
90
93
|
function getTreatmentsWithConfigByFlagSets(key, flagSetNames, attributes) {
|
|
91
|
-
return getTreatmentsByFlagSets(key, flagSetNames, attributes, true, constants_1.TREATMENTS_WITH_CONFIG_BY_FLAGSETS);
|
|
94
|
+
return getTreatmentsByFlagSets(key, flagSetNames, attributes, true, constants_1.TREATMENTS_WITH_CONFIG_BY_FLAGSETS, constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS);
|
|
92
95
|
}
|
|
93
96
|
function getTreatmentsByFlagSet(key, flagSetName, attributes) {
|
|
94
|
-
return getTreatmentsByFlagSets(key, [flagSetName], attributes, false, constants_1.TREATMENTS_BY_FLAGSET);
|
|
97
|
+
return getTreatmentsByFlagSets(key, [flagSetName], attributes, false, constants_1.TREATMENTS_BY_FLAGSET, constants_1.GET_TREATMENTS_BY_FLAG_SET);
|
|
95
98
|
}
|
|
96
99
|
function getTreatmentsWithConfigByFlagSet(key, flagSetName, attributes) {
|
|
97
|
-
return getTreatmentsByFlagSets(key, [flagSetName], attributes, true, constants_1.TREATMENTS_WITH_CONFIG_BY_FLAGSET);
|
|
100
|
+
return getTreatmentsByFlagSets(key, [flagSetName], attributes, true, constants_1.TREATMENTS_WITH_CONFIG_BY_FLAGSET, constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET);
|
|
98
101
|
}
|
|
99
102
|
// Internal function
|
|
100
103
|
function processEvaluation(evaluation, featureFlagName, key, attributes, withConfig, invokingMethodName, queue) {
|
|
@@ -102,7 +105,7 @@ function clientFactory(params) {
|
|
|
102
105
|
var bucketingKey = (0, key_1.getBucketing)(key);
|
|
103
106
|
var treatment = evaluation.treatment, label = evaluation.label, changeNumber = evaluation.changeNumber, _a = evaluation.config, config = _a === void 0 ? null : _a;
|
|
104
107
|
log.info(constants_2.IMPRESSION, [featureFlagName, matchingKey, treatment, label]);
|
|
105
|
-
if ((0,
|
|
108
|
+
if ((0, splitExistence_1.validateSplitExistence)(log, readinessManager, featureFlagName, label, invokingMethodName)) {
|
|
106
109
|
log.info(constants_2.IMPRESSION_QUEUEING);
|
|
107
110
|
queue.push({
|
|
108
111
|
feature: featureFlagName,
|
|
@@ -136,7 +139,7 @@ function clientFactory(params) {
|
|
|
136
139
|
properties: properties
|
|
137
140
|
};
|
|
138
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.
|
|
139
|
-
(0,
|
|
142
|
+
(0, trafficTypeExistence_1.validateTrafficTypeExistence)(log, readinessManager, storage.splits, mode, trafficTypeName, constants_1.TRACK_FN_LABEL);
|
|
140
143
|
var result = eventTracker.track(eventData, size);
|
|
141
144
|
if ((0, thenable_1.thenable)(result)) {
|
|
142
145
|
return result.then(function (result) {
|
|
@@ -18,7 +18,7 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
|
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;
|
|
@@ -44,7 +44,7 @@ function clientInputValidationDecorator(settings, client, readinessManager) {
|
|
|
44
44
|
return isSync ? value : Promise.resolve(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,12 +122,12 @@ 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
|
}
|
package/cjs/sdkFactory/index.js
CHANGED
|
@@ -66,7 +66,7 @@ function sdkFactory(params) {
|
|
|
66
66
|
ctx.signalListener = signalListener;
|
|
67
67
|
// SDK client and manager
|
|
68
68
|
var clientMethod = sdkClientMethodFactory(ctx);
|
|
69
|
-
var managerInstance = sdkManagerFactory(
|
|
69
|
+
var managerInstance = sdkManagerFactory(settings, storage.splits, sdkReadinessManager);
|
|
70
70
|
syncManager && syncManager.start();
|
|
71
71
|
signalListener && signalListener.start();
|
|
72
72
|
log.info(constants_1.NEW_FACTORY);
|
package/cjs/sdkManager/index.js
CHANGED
|
@@ -5,9 +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 NAMES_FN_LABEL = 'names';
|
|
8
|
+
var utils_1 = require("../trackers/impressionObserver/utils");
|
|
9
|
+
var constants_1 = require("../utils/constants");
|
|
11
10
|
function collectTreatments(splitObject) {
|
|
12
11
|
var conditions = splitObject.conditions;
|
|
13
12
|
// Rollout conditions are supposed to have the entire partitions list, so we find the first one.
|
|
@@ -41,8 +40,10 @@ function objectsToViews(splitObjects) {
|
|
|
41
40
|
});
|
|
42
41
|
return views;
|
|
43
42
|
}
|
|
44
|
-
function sdkManagerFactory(
|
|
43
|
+
function sdkManagerFactory(settings, splits, _a) {
|
|
45
44
|
var readinessManager = _a.readinessManager, sdkStatus = _a.sdkStatus;
|
|
45
|
+
var log = settings.log;
|
|
46
|
+
var isSync = (0, utils_1.isStorageSync)(settings);
|
|
46
47
|
return (0, objectAssign_1.objectAssign)(
|
|
47
48
|
// Proto-linkage of the readiness Event Emitter
|
|
48
49
|
Object.create(sdkStatus), {
|
|
@@ -50,26 +51,26 @@ function sdkManagerFactory(log, splits, _a) {
|
|
|
50
51
|
* Get the feature flag object corresponding to the given feature flag name if valid
|
|
51
52
|
*/
|
|
52
53
|
split: function (featureFlagName) {
|
|
53
|
-
var splitName = (0, inputValidation_1.validateSplit)(log, featureFlagName, SPLIT_FN_LABEL);
|
|
54
|
-
if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, SPLIT_FN_LABEL) || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, SPLIT_FN_LABEL) || !splitName) {
|
|
55
|
-
return null;
|
|
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 isSync ? null : Promise.resolve(null);
|
|
56
57
|
}
|
|
57
58
|
var split = splits.getSplit(splitName);
|
|
58
59
|
if ((0, thenable_1.thenable)(split)) {
|
|
59
60
|
return split.catch(function () { return null; }).then(function (result) {
|
|
60
|
-
(0, inputValidation_1.
|
|
61
|
+
(0, inputValidation_1.validateSplitExistence)(log, readinessManager, splitName, result, constants_1.SPLIT_FN_LABEL);
|
|
61
62
|
return objectToView(result);
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
|
-
(0, inputValidation_1.
|
|
65
|
+
(0, inputValidation_1.validateSplitExistence)(log, readinessManager, splitName, split, constants_1.SPLIT_FN_LABEL);
|
|
65
66
|
return objectToView(split);
|
|
66
67
|
},
|
|
67
68
|
/**
|
|
68
69
|
* Get the feature flag objects present on the factory storage
|
|
69
70
|
*/
|
|
70
71
|
splits: function () {
|
|
71
|
-
if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, SPLITS_FN_LABEL) || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, SPLITS_FN_LABEL)) {
|
|
72
|
-
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 isSync ? [] : Promise.resolve([]);
|
|
73
74
|
}
|
|
74
75
|
var currentSplits = splits.getAll();
|
|
75
76
|
return (0, thenable_1.thenable)(currentSplits) ?
|
|
@@ -80,8 +81,8 @@ function sdkManagerFactory(log, splits, _a) {
|
|
|
80
81
|
* Get the feature flag names present on the factory storage
|
|
81
82
|
*/
|
|
82
83
|
names: function () {
|
|
83
|
-
if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, NAMES_FN_LABEL) || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, NAMES_FN_LABEL)) {
|
|
84
|
-
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 isSync ? [] : Promise.resolve([]);
|
|
85
86
|
}
|
|
86
87
|
var splitNames = splits.getSplitNames();
|
|
87
88
|
return (0, thenable_1.thenable)(splitNames) ?
|
|
@@ -231,16 +231,11 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
231
231
|
};
|
|
232
232
|
SplitsCacheInLocal.prototype.getNamesByFlagSets = function (flagSets) {
|
|
233
233
|
var _this = this;
|
|
234
|
-
|
|
235
|
-
flagSets.forEach(function (flagSet) {
|
|
234
|
+
return flagSets.map(function (flagSet) {
|
|
236
235
|
var flagSetKey = _this.keys.buildFlagSetKey(flagSet);
|
|
237
236
|
var flagSetFromLocalStorage = localStorage.getItem(flagSetKey);
|
|
238
|
-
|
|
239
|
-
var flagSetCache = new sets_1._Set(JSON.parse(flagSetFromLocalStorage));
|
|
240
|
-
toReturn = (0, sets_1.returnSetsUnion)(toReturn, flagSetCache);
|
|
241
|
-
}
|
|
237
|
+
return new sets_1._Set(flagSetFromLocalStorage ? JSON.parse(flagSetFromLocalStorage) : []);
|
|
242
238
|
});
|
|
243
|
-
return toReturn;
|
|
244
239
|
};
|
|
245
240
|
SplitsCacheInLocal.prototype.addToFlagSets = function (featureFlag) {
|
|
246
241
|
var _this = this;
|
|
@@ -251,9 +246,7 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
251
246
|
return;
|
|
252
247
|
var flagSetKey = _this.keys.buildFlagSetKey(featureFlagSet);
|
|
253
248
|
var flagSetFromLocalStorage = localStorage.getItem(flagSetKey);
|
|
254
|
-
|
|
255
|
-
flagSetFromLocalStorage = '[]';
|
|
256
|
-
var flagSetCache = new sets_1._Set(JSON.parse(flagSetFromLocalStorage));
|
|
249
|
+
var flagSetCache = new sets_1._Set(flagSetFromLocalStorage ? JSON.parse(flagSetFromLocalStorage) : []);
|
|
257
250
|
flagSetCache.add(featureFlag.name);
|
|
258
251
|
localStorage.setItem(flagSetKey, JSON.stringify((0, sets_1.setToArray)(flagSetCache)));
|
|
259
252
|
});
|
|
@@ -12,14 +12,13 @@ var sets_1 = require("../../utils/lang/sets");
|
|
|
12
12
|
var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
13
13
|
(0, tslib_1.__extends)(SplitsCacheInMemory, _super);
|
|
14
14
|
function SplitsCacheInMemory(splitFiltersValidation) {
|
|
15
|
-
if (splitFiltersValidation === void 0) { splitFiltersValidation = { queryString: null, groupedFilters: { bySet: [], byName: [], byPrefix: [] }, validFilters: [] }; }
|
|
16
15
|
var _this = _super.call(this) || this;
|
|
17
16
|
_this.splitsCache = {};
|
|
18
17
|
_this.ttCache = {};
|
|
19
18
|
_this.changeNumber = -1;
|
|
20
19
|
_this.splitsWithSegmentsCount = 0;
|
|
21
20
|
_this.flagSetsCache = {};
|
|
22
|
-
_this.flagSetsFilter = splitFiltersValidation.groupedFilters.bySet;
|
|
21
|
+
_this.flagSetsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
|
|
23
22
|
return _this;
|
|
24
23
|
}
|
|
25
24
|
SplitsCacheInMemory.prototype.clear = function () {
|
|
@@ -96,14 +95,7 @@ var SplitsCacheInMemory = /** @class */ (function (_super) {
|
|
|
96
95
|
};
|
|
97
96
|
SplitsCacheInMemory.prototype.getNamesByFlagSets = function (flagSets) {
|
|
98
97
|
var _this = this;
|
|
99
|
-
|
|
100
|
-
flagSets.forEach(function (flagSet) {
|
|
101
|
-
var featureFlagNames = _this.flagSetsCache[flagSet];
|
|
102
|
-
if (featureFlagNames) {
|
|
103
|
-
toReturn = (0, sets_1.returnSetsUnion)(toReturn, featureFlagNames);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
return toReturn;
|
|
98
|
+
return flagSets.map(function (flagSet) { return _this.flagSetsCache[flagSet] || new sets_1._Set(); });
|
|
107
99
|
};
|
|
108
100
|
SplitsCacheInMemory.prototype.addToFlagSets = function (featureFlag) {
|
|
109
101
|
var _this = this;
|
|
@@ -9,7 +9,8 @@ var thenable_1 = require("../../utils/promise/thenable");
|
|
|
9
9
|
var timeout_1 = require("../../utils/promise/timeout");
|
|
10
10
|
var LOG_PREFIX = 'storage:redis-adapter: ';
|
|
11
11
|
// If we ever decide to fully wrap every method, there's a Commander.getBuiltinCommands from ioredis.
|
|
12
|
-
var METHODS_TO_PROMISE_WRAP = ['set', 'exec', 'del', 'get', 'keys', 'sadd', 'srem', 'sismember', 'smembers', 'incr', 'rpush', '
|
|
12
|
+
var METHODS_TO_PROMISE_WRAP = ['set', 'exec', 'del', 'get', 'keys', 'sadd', 'srem', 'sismember', 'smembers', 'incr', 'rpush', 'expire', 'mget', 'lrange', 'ltrim', 'hset', 'hincrby', 'popNRaw'];
|
|
13
|
+
var METHODS_TO_PROMISE_WRAP_EXEC = ['pipeline'];
|
|
13
14
|
// Not part of the settings since it'll vary on each storage. We should be removing storage specific logic from elsewhere.
|
|
14
15
|
var DEFAULT_OPTIONS = {
|
|
15
16
|
connectionTimeout: 10000,
|
|
@@ -27,6 +28,7 @@ var DEFAULT_LIBRARY_OPTIONS = {
|
|
|
27
28
|
var RedisAdapter = /** @class */ (function (_super) {
|
|
28
29
|
(0, tslib_1.__extends)(RedisAdapter, _super);
|
|
29
30
|
function RedisAdapter(log, storageSettings) {
|
|
31
|
+
if (storageSettings === void 0) { storageSettings = {}; }
|
|
30
32
|
var _this = this;
|
|
31
33
|
var options = RedisAdapter._defineOptions(storageSettings);
|
|
32
34
|
// Call the ioredis constructor
|
|
@@ -58,14 +60,15 @@ var RedisAdapter = /** @class */ (function (_super) {
|
|
|
58
60
|
};
|
|
59
61
|
RedisAdapter.prototype._setTimeoutWrappers = function () {
|
|
60
62
|
var instance = this;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
instance
|
|
63
|
+
var wrapCommand = function (originalMethod, methodName) {
|
|
64
|
+
// The value of "this" in this function should be the instance actually executing the method. It might be the instance referred (the base one)
|
|
65
|
+
// or it can be the instance of a Pipeline object.
|
|
66
|
+
return function () {
|
|
64
67
|
var params = arguments;
|
|
68
|
+
var caller = this;
|
|
65
69
|
function commandWrapper() {
|
|
66
|
-
instance.log.debug(LOG_PREFIX +
|
|
67
|
-
|
|
68
|
-
var result = originalMethod.apply(instance, params);
|
|
70
|
+
instance.log.debug(LOG_PREFIX + "Executing " + methodName + ".");
|
|
71
|
+
var result = originalMethod.apply(caller, params);
|
|
69
72
|
if ((0, thenable_1.thenable)(result)) {
|
|
70
73
|
// For handling pending commands on disconnect, add to the set and remove once finished.
|
|
71
74
|
// On sync commands there's no need, only thenables.
|
|
@@ -76,7 +79,7 @@ var RedisAdapter = /** @class */ (function (_super) {
|
|
|
76
79
|
// Both success and error remove from queue.
|
|
77
80
|
result.then(cleanUpRunningCommandsCb, cleanUpRunningCommandsCb);
|
|
78
81
|
return (0, timeout_1.timeout)(instance._options.operationTimeout, result).catch(function (err) {
|
|
79
|
-
instance.log.error(LOG_PREFIX +
|
|
82
|
+
instance.log.error("" + LOG_PREFIX + methodName + " operation threw an error or exceeded configured timeout of " + instance._options.operationTimeout + "ms. Message: " + err);
|
|
80
83
|
// Handling is not the adapter responsibility.
|
|
81
84
|
throw err;
|
|
82
85
|
});
|
|
@@ -84,12 +87,12 @@ var RedisAdapter = /** @class */ (function (_super) {
|
|
|
84
87
|
return result;
|
|
85
88
|
}
|
|
86
89
|
if (instance._notReadyCommandsQueue) {
|
|
87
|
-
return new Promise(function (
|
|
90
|
+
return new Promise(function (resolve, reject) {
|
|
88
91
|
instance._notReadyCommandsQueue.unshift({
|
|
89
|
-
resolve:
|
|
90
|
-
reject:
|
|
92
|
+
resolve: resolve,
|
|
93
|
+
reject: reject,
|
|
91
94
|
command: commandWrapper,
|
|
92
|
-
name:
|
|
95
|
+
name: methodName.toUpperCase()
|
|
93
96
|
});
|
|
94
97
|
});
|
|
95
98
|
}
|
|
@@ -97,6 +100,22 @@ var RedisAdapter = /** @class */ (function (_super) {
|
|
|
97
100
|
return commandWrapper();
|
|
98
101
|
}
|
|
99
102
|
};
|
|
103
|
+
};
|
|
104
|
+
// Wrap regular async methods to track timeouts and queue when Redis is not yet executing commands.
|
|
105
|
+
METHODS_TO_PROMISE_WRAP.forEach(function (methodName) {
|
|
106
|
+
var originalFn = instance[methodName];
|
|
107
|
+
instance[methodName] = wrapCommand(originalFn, methodName);
|
|
108
|
+
});
|
|
109
|
+
// Special handling for pipeline~like methods. We need to wrap the async trigger, which is exec, but return the Pipeline right away.
|
|
110
|
+
METHODS_TO_PROMISE_WRAP_EXEC.forEach(function (methodName) {
|
|
111
|
+
var originalFn = instance[methodName];
|
|
112
|
+
// "First level wrapper" to handle the sync execution and wrap async, queueing later if applicable.
|
|
113
|
+
instance[methodName] = function () {
|
|
114
|
+
var res = originalFn.apply(instance, arguments);
|
|
115
|
+
var originalExec = res.exec;
|
|
116
|
+
res.exec = wrapCommand(originalExec, methodName + '.exec').bind(res);
|
|
117
|
+
return res;
|
|
118
|
+
};
|
|
100
119
|
});
|
|
101
120
|
};
|
|
102
121
|
RedisAdapter.prototype._setDisconnectWrapper = function () {
|
|
@@ -107,7 +126,7 @@ var RedisAdapter = /** @class */ (function (_super) {
|
|
|
107
126
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
108
127
|
params[_i] = arguments[_i];
|
|
109
128
|
}
|
|
110
|
-
setTimeout(function
|
|
129
|
+
setTimeout(function deferredDisconnect() {
|
|
111
130
|
if (instance._runningCommands.size > 0) {
|
|
112
131
|
instance.log.info(LOG_PREFIX + ("Attempting to disconnect but there are " + instance._runningCommands.size + " commands still waiting for resolution. Defering disconnection until those finish."));
|
|
113
132
|
Promise.all((0, sets_1.setToArray)(instance._runningCommands))
|