@splitsoftware/splitio-commons 1.12.1-rc.2 → 1.12.1-rc.4

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.
Files changed (42) hide show
  1. package/CHANGES.txt +10 -9
  2. package/cjs/sdkClient/client.js +16 -13
  3. package/cjs/sdkClient/clientInputValidation.js +15 -15
  4. package/cjs/sdkFactory/index.js +1 -1
  5. package/cjs/sdkManager/index.js +14 -13
  6. package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +5 -1
  7. package/cjs/storages/inRedis/RedisAdapter.js +29 -12
  8. package/cjs/storages/inRedis/SegmentsCacheInRedis.js +2 -2
  9. package/cjs/storages/inRedis/SplitsCacheInRedis.js +5 -9
  10. package/cjs/utils/constants/index.js +16 -2
  11. package/cjs/utils/redis/RedisMock.js +7 -1
  12. package/esm/sdkClient/client.js +17 -14
  13. package/esm/sdkClient/clientInputValidation.js +16 -16
  14. package/esm/sdkFactory/index.js +1 -1
  15. package/esm/sdkManager/index.js +8 -7
  16. package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +5 -1
  17. package/esm/storages/inRedis/RedisAdapter.js +29 -12
  18. package/esm/storages/inRedis/SegmentsCacheInRedis.js +2 -2
  19. package/esm/storages/inRedis/SplitsCacheInRedis.js +5 -9
  20. package/esm/utils/constants/index.js +14 -0
  21. package/esm/utils/redis/RedisMock.js +7 -1
  22. package/package.json +1 -1
  23. package/src/sdkClient/client.ts +15 -15
  24. package/src/sdkClient/clientInputValidation.ts +16 -16
  25. package/src/sdkFactory/index.ts +1 -1
  26. package/src/sdkFactory/types.ts +3 -7
  27. package/src/sdkManager/index.ts +11 -11
  28. package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +5 -1
  29. package/src/storages/inRedis/RedisAdapter.ts +35 -17
  30. package/src/storages/inRedis/SegmentsCacheInRedis.ts +2 -2
  31. package/src/storages/inRedis/SplitsCacheInRedis.ts +5 -9
  32. package/src/trackers/impressionObserver/utils.ts +1 -1
  33. package/src/utils/constants/index.ts +16 -0
  34. package/src/utils/redis/RedisMock.ts +9 -1
  35. package/types/sdkFactory/types.d.ts +3 -3
  36. package/types/sdkManager/index.d.ts +2 -3
  37. package/types/storages/inRedis/RedisAdapter.d.ts +1 -2
  38. package/types/storages/inRedis/SegmentsCacheInRedis.d.ts +1 -1
  39. package/types/storages/inRedis/SplitsCacheInRedis.d.ts +2 -7
  40. package/types/trackers/impressionObserver/utils.d.ts +1 -1
  41. package/types/utils/constants/index.d.ts +12 -0
  42. package/types/utils/redis/RedisMock.d.ts +1 -0
package/CHANGES.txt CHANGED
@@ -1,17 +1,18 @@
1
1
  1.12.0 (December XX, 2023)
2
2
  - Added support for Flag Sets in "consumer" and "partial consumer" modes for Pluggable and Redis storages.
3
3
  - Updated evaluation flow to log a warning when using flag sets that don't contain cached feature flags.
4
- - Updated Redis adapter to wrap missing commands: 'hincrby', 'popNRaw', 'flushdb' and 'pipeline.exec'.
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).
5
6
 
6
7
  1.11.0 (November 3, 2023)
7
- - 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):
8
- - Added new variations of the get treatment methods to support evaluating flags in given flag set/s.
9
- - getTreatmentsByFlagSet and getTreatmentsByFlagSets
10
- - getTreatmentsWithConfigByFlagSets and getTreatmentsWithConfigByFlagSets
11
- - 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.
12
- - 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.
13
- - 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.
14
- - 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).
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).
15
16
 
16
17
  1.10.0 (October 20, 2023)
17
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).
@@ -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, "getTreatment" + (withConfig ? 'withConfig' : ''), queue);
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, "getTreatments" + (withConfig ? 'withConfig' : ''), queue);
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, "getTreatmentsByFlagSets" + (withConfig ? 'WithConfig' : ''), queue);
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, method) :
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) {
@@ -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, trafficTypeExistence_1.validateTrafficTypeExistence)(log, readinessManager, storage.splits, mode, trafficTypeName, 'track');
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, 'getTreatments');
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 = [];
@@ -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, 'getTreatment');
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, 'getTreatmentWithConfig');
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, 'getTreatments');
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, 'getTreatmentsWithConfig');
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, 'getTreatmentsByFlagSets', maybeFlagSets);
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, 'getTreatmentsWithConfigByFlagSets', maybeFlagSets);
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, 'getTreatmentsByFlagSet', [maybeFlagSet]);
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, 'getTreatmentsWithConfigByFlagSet', [maybeFlagSet]);
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, 'track');
126
- var tt = (0, inputValidation_1.validateTrafficType)(log, maybeTT, 'track');
127
- var event = (0, inputValidation_1.validateEvent)(log, maybeEvent, 'track');
128
- var eventValue = (0, inputValidation_1.validateEventValue)(log, maybeEventValue, 'track');
129
- var _a = (0, inputValidation_1.validateEventProperties)(log, maybeProperties, 'track'), properties = _a.properties, size = _a.size;
130
- var isNotDestroyed = (0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, 'track');
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
  }
@@ -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(log, storage.splits, sdkReadinessManager);
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);
@@ -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 SPLIT_FN_LABEL = 'split';
9
- var SPLITS_FN_LABEL = 'splits';
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(log, splits, _a) {
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.validateSplitExistence)(log, readinessManager, splitName, result, SPLIT_FN_LABEL);
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.validateSplitExistence)(log, readinessManager, splitName, split, SPLIT_FN_LABEL);
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) ?
@@ -23,7 +23,11 @@ var ImpressionCountsCacheInRedis = /** @class */ (function (_super) {
23
23
  var keys = Object.keys(counts);
24
24
  if (!keys.length)
25
25
  return Promise.resolve(false);
26
- return this.redis.pipelineExec(keys.map(function (key) { return ['hincrby', _this.key, key, counts[key]]; }))
26
+ var pipeline = this.redis.pipeline();
27
+ keys.forEach(function (key) {
28
+ pipeline.hincrby(_this.key, key, counts[key]);
29
+ });
30
+ return pipeline.exec()
27
31
  .then(function (data) {
28
32
  // If this is the creation of the key on Redis, set the expiration for it in 3600 seconds.
29
33
  if (data.length && data.length === keys.length) {
@@ -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', 'expire', 'mget', 'lrange', 'ltrim', 'hset', 'hincrby', 'popNRaw', 'flushdb', 'pipelineExec'];
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
@@ -40,9 +42,6 @@ var RedisAdapter = /** @class */ (function (_super) {
40
42
  _this._setDisconnectWrapper();
41
43
  return _this;
42
44
  }
43
- RedisAdapter.prototype.pipelineExec = function (commands) {
44
- return this.pipeline(commands).exec();
45
- };
46
45
  RedisAdapter.prototype._listenToEvents = function () {
47
46
  var _this = this;
48
47
  this.once('ready', function () {
@@ -61,13 +60,15 @@ var RedisAdapter = /** @class */ (function (_super) {
61
60
  };
62
61
  RedisAdapter.prototype._setTimeoutWrappers = function () {
63
62
  var instance = this;
64
- METHODS_TO_PROMISE_WRAP.forEach(function (methodName) {
65
- var originalMethod = instance[methodName];
66
- instance[methodName] = function () {
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 () {
67
67
  var params = arguments;
68
+ var caller = this;
68
69
  function commandWrapper() {
69
70
  instance.log.debug(LOG_PREFIX + "Executing " + methodName + ".");
70
- var result = originalMethod.apply(instance, params);
71
+ var result = originalMethod.apply(caller, params);
71
72
  if ((0, thenable_1.thenable)(result)) {
72
73
  // For handling pending commands on disconnect, add to the set and remove once finished.
73
74
  // On sync commands there's no need, only thenables.
@@ -86,10 +87,10 @@ var RedisAdapter = /** @class */ (function (_super) {
86
87
  return result;
87
88
  }
88
89
  if (instance._notReadyCommandsQueue) {
89
- return new Promise(function (res, rej) {
90
+ return new Promise(function (resolve, reject) {
90
91
  instance._notReadyCommandsQueue.unshift({
91
- resolve: res,
92
- reject: rej,
92
+ resolve: resolve,
93
+ reject: reject,
93
94
  command: commandWrapper,
94
95
  name: methodName.toUpperCase()
95
96
  });
@@ -99,6 +100,22 @@ var RedisAdapter = /** @class */ (function (_super) {
99
100
  return commandWrapper();
100
101
  }
101
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
+ };
102
119
  });
103
120
  };
104
121
  RedisAdapter.prototype._setDisconnectWrapper = function () {
@@ -160,7 +177,7 @@ var RedisAdapter = /** @class */ (function (_super) {
160
177
  * Parses the options into what we care about.
161
178
  */
162
179
  RedisAdapter._defineOptions = function (_a) {
163
- var _b = _a === void 0 ? {} : _a, connectionTimeout = _b.connectionTimeout, operationTimeout = _b.operationTimeout, url = _b.url, host = _b.host, port = _b.port, db = _b.db, pass = _b.pass, tls = _b.tls;
180
+ var connectionTimeout = _a.connectionTimeout, operationTimeout = _a.operationTimeout, url = _a.url, host = _a.host, port = _a.port, db = _a.db, pass = _a.pass, tls = _a.tls;
164
181
  var parsedOptions = {
165
182
  connectionTimeout: connectionTimeout,
166
183
  operationTimeout: operationTimeout,
@@ -54,9 +54,9 @@ var SegmentsCacheInRedis = /** @class */ (function () {
54
54
  SegmentsCacheInRedis.prototype.getRegisteredSegments = function () {
55
55
  return this.redis.smembers(this.keys.buildRegisteredSegmentsKey());
56
56
  };
57
- // @TODO remove/review. It is not being used.
57
+ // @TODO remove or implement. It is not being used.
58
58
  SegmentsCacheInRedis.prototype.clear = function () {
59
- return this.redis.flushdb().then(function (status) { return status === 'OK'; });
59
+ return Promise.resolve();
60
60
  };
61
61
  return SegmentsCacheInRedis;
62
62
  }());
@@ -171,7 +171,7 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
171
171
  SplitsCacheInRedis.prototype.getAll = function () {
172
172
  var _this = this;
173
173
  return this.redis.keys(this.keys.searchPatternForSplitKeys())
174
- .then(function (listOfKeys) { return _this.redis.pipelineExec(listOfKeys.map(function (k) { return ['get', k]; })); })
174
+ .then(function (listOfKeys) { return _this.redis.pipeline(listOfKeys.map(function (k) { return ['get', k]; })).exec(); })
175
175
  .then(processPipelineAnswer)
176
176
  .then(function (splitDefinitions) { return splitDefinitions.map(function (splitDefinition) {
177
177
  return JSON.parse(splitDefinition);
@@ -189,11 +189,11 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
189
189
  /**
190
190
  * Get list of feature flag names related to a given list of flag set names.
191
191
  * The returned promise is resolved with the list of feature flag names per flag set,
192
- * or rejected if the pipelined redis operation fails.
192
+ * or rejected if the pipelined redis operation fails (e.g., timeout).
193
193
  */
194
194
  SplitsCacheInRedis.prototype.getNamesByFlagSets = function (flagSets) {
195
195
  var _this = this;
196
- return this.redis.pipelineExec(flagSets.map(function (flagSet) { return ['smembers', _this.keys.buildFlagSetKey(flagSet)]; }))
196
+ return this.redis.pipeline(flagSets.map(function (flagSet) { return ['smembers', _this.keys.buildFlagSetKey(flagSet)]; })).exec()
197
197
  .then(function (results) { return results.map(function (_a, index) {
198
198
  var e = _a[0], value = _a[1];
199
199
  if (e === null)
@@ -228,13 +228,9 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
228
228
  return true;
229
229
  });
230
230
  };
231
- /**
232
- * Delete everything in the current database.
233
- *
234
- * @NOTE documentation says it never fails.
235
- */
231
+ // @TODO remove or implement. It is not being used.
236
232
  SplitsCacheInRedis.prototype.clear = function () {
237
- return this.redis.flushdb().then(function (status) { return status === 'OK'; });
233
+ return Promise.resolve();
238
234
  };
239
235
  /**
240
236
  * Fetches multiple splits definitions.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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 = 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.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 = 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;
@@ -9,16 +9,22 @@ function asyncFunction(data) {
9
9
  return Promise.resolve(data);
10
10
  }
11
11
  var IDENTITY_METHODS = [];
12
- var ASYNC_METHODS = ['rpush', 'hincrby', 'pipelineExec'];
12
+ var ASYNC_METHODS = ['rpush', 'hincrby'];
13
+ var PIPELINE_METHODS = ['rpush', 'hincrby'];
13
14
  var RedisMock = /** @class */ (function () {
14
15
  function RedisMock() {
15
16
  var _this = this;
17
+ this.pipelineMethods = { exec: jest.fn(asyncFunction) };
16
18
  IDENTITY_METHODS.forEach(function (method) {
17
19
  _this[method] = jest.fn(identityFunction);
18
20
  });
19
21
  ASYNC_METHODS.forEach(function (method) {
20
22
  _this[method] = jest.fn(asyncFunction);
21
23
  });
24
+ PIPELINE_METHODS.forEach(function (method) {
25
+ _this.pipelineMethods[method] = _this[method];
26
+ });
27
+ this.pipeline = jest.fn(function () { return _this.pipelineMethods; });
22
28
  }
23
29
  return RedisMock;
24
30
  }());
@@ -4,7 +4,7 @@ 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
9
  import { isStorageSync } from '../trackers/impressionObserver/utils';
10
10
  var treatmentNotReady = { treatment: CONTROL, label: SDK_NOT_READY };
@@ -21,12 +21,13 @@ 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
- function getTreatment(key, featureFlagName, attributes, withConfig) {
24
+ function getTreatment(key, featureFlagName, attributes, withConfig, methodName) {
25
25
  if (withConfig === void 0) { withConfig = false; }
26
+ if (methodName === void 0) { methodName = GET_TREATMENT; }
26
27
  var stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? TREATMENT_WITH_CONFIG : TREATMENT);
27
28
  var wrapUp = function (evaluationResult) {
28
29
  var queue = [];
29
- var treatment = processEvaluation(evaluationResult, featureFlagName, key, attributes, withConfig, "getTreatment" + (withConfig ? 'withConfig' : ''), queue);
30
+ var treatment = processEvaluation(evaluationResult, featureFlagName, key, attributes, withConfig, methodName, queue);
30
31
  impressionsTracker.track(queue, attributes);
31
32
  stopTelemetryTracker(queue[0] && queue[0].label);
32
33
  return treatment;
@@ -39,16 +40,17 @@ export function clientFactory(params) {
39
40
  return thenable(evaluation) ? evaluation.then(function (res) { return wrapUp(res); }) : wrapUp(evaluation);
40
41
  }
41
42
  function getTreatmentWithConfig(key, featureFlagName, attributes) {
42
- return getTreatment(key, featureFlagName, attributes, true);
43
+ return getTreatment(key, featureFlagName, attributes, true, GET_TREATMENT_WITH_CONFIG);
43
44
  }
44
- function getTreatments(key, featureFlagNames, attributes, withConfig) {
45
+ function getTreatments(key, featureFlagNames, attributes, withConfig, methodName) {
45
46
  if (withConfig === void 0) { withConfig = false; }
47
+ if (methodName === void 0) { methodName = GET_TREATMENTS; }
46
48
  var stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? TREATMENTS_WITH_CONFIG : TREATMENTS);
47
49
  var wrapUp = function (evaluationResults) {
48
50
  var queue = [];
49
51
  var treatments = {};
50
52
  Object.keys(evaluationResults).forEach(function (featureFlagName) {
51
- treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, attributes, withConfig, "getTreatments" + (withConfig ? 'withConfig' : ''), queue);
53
+ treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, attributes, withConfig, methodName, queue);
52
54
  });
53
55
  impressionsTracker.track(queue, attributes);
54
56
  stopTelemetryTracker(queue[0] && queue[0].label);
@@ -62,36 +64,37 @@ export function clientFactory(params) {
62
64
  return thenable(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
63
65
  }
64
66
  function getTreatmentsWithConfig(key, featureFlagNames, attributes) {
65
- return getTreatments(key, featureFlagNames, attributes, true);
67
+ return getTreatments(key, featureFlagNames, attributes, true, GET_TREATMENTS_WITH_CONFIG);
66
68
  }
67
- function getTreatmentsByFlagSets(key, flagSetNames, attributes, withConfig, method) {
69
+ function getTreatmentsByFlagSets(key, flagSetNames, attributes, withConfig, method, methodName) {
68
70
  if (withConfig === void 0) { withConfig = false; }
69
71
  if (method === void 0) { method = TREATMENTS_BY_FLAGSETS; }
72
+ if (methodName === void 0) { methodName = GET_TREATMENTS_BY_FLAG_SETS; }
70
73
  var stopTelemetryTracker = telemetryTracker.trackEval(method);
71
74
  var wrapUp = function (evaluationResults) {
72
75
  var queue = [];
73
76
  var treatments = {};
74
77
  var evaluations = evaluationResults;
75
78
  Object.keys(evaluations).forEach(function (featureFlagName) {
76
- treatments[featureFlagName] = processEvaluation(evaluations[featureFlagName], featureFlagName, key, attributes, withConfig, "getTreatmentsByFlagSets" + (withConfig ? 'WithConfig' : ''), queue);
79
+ treatments[featureFlagName] = processEvaluation(evaluations[featureFlagName], featureFlagName, key, attributes, withConfig, methodName, queue);
77
80
  });
78
81
  impressionsTracker.track(queue, attributes);
79
82
  stopTelemetryTracker(queue[0] && queue[0].label);
80
83
  return treatments;
81
84
  };
82
85
  var evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
83
- evaluateFeaturesByFlagSets(log, key, flagSetNames, attributes, storage, method) :
86
+ evaluateFeaturesByFlagSets(log, key, flagSetNames, attributes, storage, methodName) :
84
87
  isStorageSync(settings) ? {} : Promise.resolve({}); // Promisify if async
85
88
  return thenable(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
86
89
  }
87
90
  function getTreatmentsWithConfigByFlagSets(key, flagSetNames, attributes) {
88
- return getTreatmentsByFlagSets(key, flagSetNames, attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSETS);
91
+ return getTreatmentsByFlagSets(key, flagSetNames, attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSETS, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS);
89
92
  }
90
93
  function getTreatmentsByFlagSet(key, flagSetName, attributes) {
91
- return getTreatmentsByFlagSets(key, [flagSetName], attributes, false, TREATMENTS_BY_FLAGSET);
94
+ return getTreatmentsByFlagSets(key, [flagSetName], attributes, false, TREATMENTS_BY_FLAGSET, GET_TREATMENTS_BY_FLAG_SET);
92
95
  }
93
96
  function getTreatmentsWithConfigByFlagSet(key, flagSetName, attributes) {
94
- return getTreatmentsByFlagSets(key, [flagSetName], attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSET);
97
+ return getTreatmentsByFlagSets(key, [flagSetName], attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET);
95
98
  }
96
99
  // Internal function
97
100
  function processEvaluation(evaluation, featureFlagName, key, attributes, withConfig, invokingMethodName, queue) {
@@ -133,7 +136,7 @@ export function clientFactory(params) {
133
136
  properties: properties
134
137
  };
135
138
  // 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, 'track');
139
+ validateTrafficTypeExistence(log, readinessManager, storage.splits, mode, trafficTypeName, TRACK_FN_LABEL);
137
140
  var result = eventTracker.track(eventData, size);
138
141
  if (thenable(result)) {
139
142
  return result.then(function (result) {