@splitsoftware/splitio-commons 1.12.1-rc.3 → 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.
@@ -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
  }
@@ -6,9 +6,7 @@ var thenable_1 = require("../utils/promise/thenable");
6
6
  var lang_1 = require("../utils/lang");
7
7
  var inputValidation_1 = require("../utils/inputValidation");
8
8
  var utils_1 = require("../trackers/impressionObserver/utils");
9
- var SPLIT_FN_LABEL = 'split';
10
- var SPLITS_FN_LABEL = 'splits';
11
- var NAMES_FN_LABEL = 'names';
9
+ var constants_1 = require("../utils/constants");
12
10
  function collectTreatments(splitObject) {
13
11
  var conditions = splitObject.conditions;
14
12
  // Rollout conditions are supposed to have the entire partitions list, so we find the first one.
@@ -53,25 +51,25 @@ function sdkManagerFactory(settings, splits, _a) {
53
51
  * Get the feature flag object corresponding to the given feature flag name if valid
54
52
  */
55
53
  split: function (featureFlagName) {
56
- var splitName = (0, inputValidation_1.validateSplit)(log, featureFlagName, SPLIT_FN_LABEL);
57
- if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, SPLIT_FN_LABEL) || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, SPLIT_FN_LABEL) || !splitName) {
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) {
58
56
  return isSync ? null : Promise.resolve(null);
59
57
  }
60
58
  var split = splits.getSplit(splitName);
61
59
  if ((0, thenable_1.thenable)(split)) {
62
60
  return split.catch(function () { return null; }).then(function (result) {
63
- (0, inputValidation_1.validateSplitExistence)(log, readinessManager, splitName, result, SPLIT_FN_LABEL);
61
+ (0, inputValidation_1.validateSplitExistence)(log, readinessManager, splitName, result, constants_1.SPLIT_FN_LABEL);
64
62
  return objectToView(result);
65
63
  });
66
64
  }
67
- (0, inputValidation_1.validateSplitExistence)(log, readinessManager, splitName, split, SPLIT_FN_LABEL);
65
+ (0, inputValidation_1.validateSplitExistence)(log, readinessManager, splitName, split, constants_1.SPLIT_FN_LABEL);
68
66
  return objectToView(split);
69
67
  },
70
68
  /**
71
69
  * Get the feature flag objects present on the factory storage
72
70
  */
73
71
  splits: function () {
74
- if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, SPLITS_FN_LABEL) || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, SPLITS_FN_LABEL)) {
72
+ if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, constants_1.SPLITS_FN_LABEL) || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, constants_1.SPLITS_FN_LABEL)) {
75
73
  return isSync ? [] : Promise.resolve([]);
76
74
  }
77
75
  var currentSplits = splits.getAll();
@@ -83,7 +81,7 @@ function sdkManagerFactory(settings, splits, _a) {
83
81
  * Get the feature flag names present on the factory storage
84
82
  */
85
83
  names: function () {
86
- if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, NAMES_FN_LABEL) || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, NAMES_FN_LABEL)) {
84
+ if (!(0, inputValidation_1.validateIfNotDestroyed)(log, readinessManager, constants_1.NAMES_FN_LABEL) || !(0, inputValidation_1.validateIfOperational)(log, readinessManager, constants_1.NAMES_FN_LABEL)) {
87
85
  return isSync ? [] : Promise.resolve([]);
88
86
  }
89
87
  var splitNames = splits.getSplitNames();
@@ -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;
@@ -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) {
@@ -1,7 +1,7 @@
1
1
  import { objectAssign } from '../utils/lang/objectAssign';
2
2
  import { validateAttributes, validateEvent, validateEventValue, validateEventProperties, validateKey, validateSplit, validateSplits, validateTrafficType, validateIfNotDestroyed, validateIfOperational } from '../utils/inputValidation';
3
3
  import { startsWith } from '../utils/lang';
4
- import { CONTROL, CONTROL_WITH_CONFIG } from '../utils/constants';
4
+ import { CONTROL, CONTROL_WITH_CONFIG, GET_TREATMENT, GET_TREATMENTS, GET_TREATMENTS_BY_FLAG_SET, GET_TREATMENTS_BY_FLAG_SETS, GET_TREATMENTS_WITH_CONFIG, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, GET_TREATMENT_WITH_CONFIG, TRACK_FN_LABEL } from '../utils/constants';
5
5
  import { isStorageSync } from '../trackers/impressionObserver/utils';
6
6
  import { flagSetsAreValid } from '../utils/settingsValidation/splitFilters';
7
7
  /**
@@ -15,7 +15,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
15
15
  * Avoid repeating this validations code
16
16
  */
17
17
  function validateEvaluationParams(maybeKey, maybeFeatureFlagNameOrNames, maybeAttributes, methodName, maybeFlagSetNameOrNames) {
18
- var multi = startsWith(methodName, 'getTreatments');
18
+ var multi = startsWith(methodName, GET_TREATMENTS);
19
19
  var key = validateKey(log, maybeKey, methodName);
20
20
  var splitOrSplits = false;
21
21
  var flagSetOrFlagSets = [];
@@ -41,7 +41,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
41
41
  return isSync ? value : Promise.resolve(value);
42
42
  }
43
43
  function getTreatment(maybeKey, maybeFeatureFlagName, maybeAttributes) {
44
- var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, 'getTreatment');
44
+ var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, GET_TREATMENT);
45
45
  if (params.valid) {
46
46
  return client.getTreatment(params.key, params.splitOrSplits, params.attributes);
47
47
  }
@@ -50,7 +50,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
50
50
  }
51
51
  }
52
52
  function getTreatmentWithConfig(maybeKey, maybeFeatureFlagName, maybeAttributes) {
53
- var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, 'getTreatmentWithConfig');
53
+ var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, GET_TREATMENT_WITH_CONFIG);
54
54
  if (params.valid) {
55
55
  return client.getTreatmentWithConfig(params.key, params.splitOrSplits, params.attributes);
56
56
  }
@@ -59,7 +59,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
59
59
  }
60
60
  }
61
61
  function getTreatments(maybeKey, maybeFeatureFlagNames, maybeAttributes) {
62
- var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes, 'getTreatments');
62
+ var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes, GET_TREATMENTS);
63
63
  if (params.valid) {
64
64
  return client.getTreatments(params.key, params.splitOrSplits, params.attributes);
65
65
  }
@@ -71,7 +71,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
71
71
  }
72
72
  }
73
73
  function getTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, maybeAttributes) {
74
- var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes, 'getTreatmentsWithConfig');
74
+ var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes, GET_TREATMENTS_WITH_CONFIG);
75
75
  if (params.valid) {
76
76
  return client.getTreatmentsWithConfig(params.key, params.splitOrSplits, params.attributes);
77
77
  }
@@ -83,7 +83,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
83
83
  }
84
84
  }
85
85
  function getTreatmentsByFlagSets(maybeKey, maybeFlagSets, maybeAttributes) {
86
- var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, 'getTreatmentsByFlagSets', maybeFlagSets);
86
+ var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, GET_TREATMENTS_BY_FLAG_SETS, maybeFlagSets);
87
87
  if (params.valid) {
88
88
  return client.getTreatmentsByFlagSets(params.key, params.flagSetOrFlagSets, params.attributes);
89
89
  }
@@ -92,7 +92,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
92
92
  }
93
93
  }
94
94
  function getTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, maybeAttributes) {
95
- var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, 'getTreatmentsWithConfigByFlagSets', maybeFlagSets);
95
+ var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, maybeFlagSets);
96
96
  if (params.valid) {
97
97
  return client.getTreatmentsWithConfigByFlagSets(params.key, params.flagSetOrFlagSets, params.attributes);
98
98
  }
@@ -101,7 +101,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
101
101
  }
102
102
  }
103
103
  function getTreatmentsByFlagSet(maybeKey, maybeFlagSet, maybeAttributes) {
104
- var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, 'getTreatmentsByFlagSet', [maybeFlagSet]);
104
+ var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, GET_TREATMENTS_BY_FLAG_SET, [maybeFlagSet]);
105
105
  if (params.valid) {
106
106
  return client.getTreatmentsByFlagSet(params.key, params.flagSetOrFlagSets[0], params.attributes);
107
107
  }
@@ -110,7 +110,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
110
110
  }
111
111
  }
112
112
  function getTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, maybeAttributes) {
113
- var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, 'getTreatmentsWithConfigByFlagSet', [maybeFlagSet]);
113
+ var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, [maybeFlagSet]);
114
114
  if (params.valid) {
115
115
  return client.getTreatmentsWithConfigByFlagSet(params.key, params.flagSetOrFlagSets[0], params.attributes);
116
116
  }
@@ -119,12 +119,12 @@ export function clientInputValidationDecorator(settings, client, readinessManage
119
119
  }
120
120
  }
121
121
  function track(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties) {
122
- var key = validateKey(log, maybeKey, 'track');
123
- var tt = validateTrafficType(log, maybeTT, 'track');
124
- var event = validateEvent(log, maybeEvent, 'track');
125
- var eventValue = validateEventValue(log, maybeEventValue, 'track');
126
- var _a = validateEventProperties(log, maybeProperties, 'track'), properties = _a.properties, size = _a.size;
127
- var isNotDestroyed = validateIfNotDestroyed(log, readinessManager, 'track');
122
+ var key = validateKey(log, maybeKey, TRACK_FN_LABEL);
123
+ var tt = validateTrafficType(log, maybeTT, TRACK_FN_LABEL);
124
+ var event = validateEvent(log, maybeEvent, TRACK_FN_LABEL);
125
+ var eventValue = validateEventValue(log, maybeEventValue, TRACK_FN_LABEL);
126
+ var _a = validateEventProperties(log, maybeProperties, TRACK_FN_LABEL), properties = _a.properties, size = _a.size;
127
+ var isNotDestroyed = validateIfNotDestroyed(log, readinessManager, TRACK_FN_LABEL);
128
128
  if (isNotDestroyed && key && tt && event && eventValue !== false && properties !== false) { // @ts-expect-error
129
129
  return client.track(key, tt, event, eventValue, properties, size);
130
130
  }
@@ -3,9 +3,7 @@ import { thenable } from '../utils/promise/thenable';
3
3
  import { find } from '../utils/lang';
4
4
  import { validateSplit, validateSplitExistence, validateIfNotDestroyed, validateIfOperational } from '../utils/inputValidation';
5
5
  import { isStorageSync } from '../trackers/impressionObserver/utils';
6
- var SPLIT_FN_LABEL = 'split';
7
- var SPLITS_FN_LABEL = 'splits';
8
- var NAMES_FN_LABEL = 'names';
6
+ import { SPLIT_FN_LABEL, SPLITS_FN_LABEL, NAMES_FN_LABEL } from '../utils/constants';
9
7
  function collectTreatments(splitObject) {
10
8
  var conditions = splitObject.conditions;
11
9
  // Rollout conditions are supposed to have the entire partitions list, so we find the first one.
@@ -29,6 +29,20 @@ export var STORAGE_PLUGGABLE = 'PLUGGABLE';
29
29
  export var CONSENT_GRANTED = 'GRANTED'; // The user has granted consent for tracking events and impressions
30
30
  export var CONSENT_DECLINED = 'DECLINED'; // The user has declined consent for tracking events and impressions
31
31
  export var CONSENT_UNKNOWN = 'UNKNOWN'; // The user has neither granted nor declined consent for tracking events and impressions
32
+ // Client method names
33
+ export var GET_TREATMENT = 'getTreatment';
34
+ export var GET_TREATMENTS = 'getTreatments';
35
+ export var GET_TREATMENT_WITH_CONFIG = 'getTreatmentWithConfig';
36
+ export var GET_TREATMENTS_WITH_CONFIG = 'getTreatmentsWithConfig';
37
+ export var GET_TREATMENTS_BY_FLAG_SET = 'getTreatmentsByFlagSet';
38
+ export var GET_TREATMENTS_BY_FLAG_SETS = 'getTreatmentsByFlagSets';
39
+ export var GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET = 'getTreatmentsWithConfigByFlagSet';
40
+ export var GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS = 'getTreatmentsWithConfigByFlagSets';
41
+ export var TRACK_FN_LABEL = 'track';
42
+ // Manager method names
43
+ export var SPLIT_FN_LABEL = 'split';
44
+ export var SPLITS_FN_LABEL = 'splits';
45
+ export var NAMES_FN_LABEL = 'names';
32
46
  // Telemetry
33
47
  export var QUEUED = 0;
34
48
  export var DROPPED = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/splitio-commons",
3
- "version": "1.12.1-rc.3",
3
+ "version": "1.12.1-rc.4",
4
4
  "description": "Split Javascript SDK common components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -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 { IEvaluationResult } from '../evaluator/types';
9
9
  import { SplitIO, ImpressionDTO } from '../types';
10
10
  import { IMPRESSION, IMPRESSION_QUEUEING } from '../logger/constants';
@@ -29,12 +29,12 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
29
29
  const { sdkReadinessManager: { readinessManager }, storage, settings, impressionsTracker, eventTracker, telemetryTracker } = params;
30
30
  const { log, mode } = settings;
31
31
 
32
- function getTreatment(key: SplitIO.SplitKey, featureFlagName: string, attributes: SplitIO.Attributes | undefined, withConfig = false) {
32
+ function getTreatment(key: SplitIO.SplitKey, featureFlagName: string, attributes: SplitIO.Attributes | undefined, withConfig = false, methodName = GET_TREATMENT) {
33
33
  const stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? TREATMENT_WITH_CONFIG : TREATMENT);
34
34
 
35
35
  const wrapUp = (evaluationResult: IEvaluationResult) => {
36
36
  const queue: ImpressionDTO[] = [];
37
- const treatment = processEvaluation(evaluationResult, featureFlagName, key, attributes, withConfig, `getTreatment${withConfig ? 'withConfig' : ''}`, queue);
37
+ const treatment = processEvaluation(evaluationResult, featureFlagName, key, attributes, withConfig, methodName, queue);
38
38
  impressionsTracker.track(queue, attributes);
39
39
 
40
40
  stopTelemetryTracker(queue[0] && queue[0].label);
@@ -51,17 +51,17 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
51
51
  }
52
52
 
53
53
  function getTreatmentWithConfig(key: SplitIO.SplitKey, featureFlagName: string, attributes: SplitIO.Attributes | undefined) {
54
- return getTreatment(key, featureFlagName, attributes, true);
54
+ return getTreatment(key, featureFlagName, attributes, true, GET_TREATMENT_WITH_CONFIG);
55
55
  }
56
56
 
57
- function getTreatments(key: SplitIO.SplitKey, featureFlagNames: string[], attributes: SplitIO.Attributes | undefined, withConfig = false) {
57
+ function getTreatments(key: SplitIO.SplitKey, featureFlagNames: string[], attributes: SplitIO.Attributes | undefined, withConfig = false, methodName = GET_TREATMENTS) {
58
58
  const stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? TREATMENTS_WITH_CONFIG : TREATMENTS);
59
59
 
60
60
  const wrapUp = (evaluationResults: Record<string, IEvaluationResult>) => {
61
61
  const queue: ImpressionDTO[] = [];
62
62
  const treatments: Record<string, SplitIO.Treatment | SplitIO.TreatmentWithConfig> = {};
63
63
  Object.keys(evaluationResults).forEach(featureFlagName => {
64
- treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, attributes, withConfig, `getTreatments${withConfig ? 'withConfig' : ''}`, queue);
64
+ treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, attributes, withConfig, methodName, queue);
65
65
  });
66
66
  impressionsTracker.track(queue, attributes);
67
67
 
@@ -79,18 +79,18 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
79
79
  }
80
80
 
81
81
  function getTreatmentsWithConfig(key: SplitIO.SplitKey, featureFlagNames: string[], attributes: SplitIO.Attributes | undefined) {
82
- return getTreatments(key, featureFlagNames, attributes, true);
82
+ return getTreatments(key, featureFlagNames, attributes, true, GET_TREATMENTS_WITH_CONFIG);
83
83
  }
84
84
 
85
- function getTreatmentsByFlagSets(key: SplitIO.SplitKey, flagSetNames: string[], attributes: SplitIO.Attributes | undefined, withConfig = false, method: Method = TREATMENTS_BY_FLAGSETS) {
85
+ function getTreatmentsByFlagSets(key: SplitIO.SplitKey, flagSetNames: string[], attributes: SplitIO.Attributes | undefined, withConfig = false, method: Method = TREATMENTS_BY_FLAGSETS, methodName = GET_TREATMENTS_BY_FLAG_SETS) {
86
86
  const stopTelemetryTracker = telemetryTracker.trackEval(method);
87
87
 
88
- const wrapUp = (evaluationResults: Record<string,IEvaluationResult>) => {
88
+ const wrapUp = (evaluationResults: Record<string, IEvaluationResult>) => {
89
89
  const queue: ImpressionDTO[] = [];
90
90
  const treatments: Record<string, SplitIO.Treatment | SplitIO.TreatmentWithConfig> = {};
91
91
  const evaluations = evaluationResults;
92
92
  Object.keys(evaluations).forEach(featureFlagName => {
93
- treatments[featureFlagName] = processEvaluation(evaluations[featureFlagName], featureFlagName, key, attributes, withConfig, `getTreatmentsByFlagSets${withConfig ? 'WithConfig' : ''}`, queue);
93
+ treatments[featureFlagName] = processEvaluation(evaluations[featureFlagName], featureFlagName, key, attributes, withConfig, methodName, queue);
94
94
  });
95
95
  impressionsTracker.track(queue, attributes);
96
96
 
@@ -99,22 +99,22 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
99
99
  };
100
100
 
101
101
  const evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
102
- evaluateFeaturesByFlagSets(log, key, flagSetNames, attributes, storage, method) :
102
+ evaluateFeaturesByFlagSets(log, key, flagSetNames, attributes, storage, methodName) :
103
103
  isStorageSync(settings) ? {} : Promise.resolve({}); // Promisify if async
104
104
 
105
105
  return thenable(evaluations) ? evaluations.then((res) => wrapUp(res)) : wrapUp(evaluations);
106
106
  }
107
107
 
108
108
  function getTreatmentsWithConfigByFlagSets(key: SplitIO.SplitKey, flagSetNames: string[], attributes: SplitIO.Attributes | undefined) {
109
- return getTreatmentsByFlagSets(key, flagSetNames, attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSETS);
109
+ return getTreatmentsByFlagSets(key, flagSetNames, attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSETS, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS);
110
110
  }
111
111
 
112
112
  function getTreatmentsByFlagSet(key: SplitIO.SplitKey, flagSetName: string, attributes: SplitIO.Attributes | undefined) {
113
- return getTreatmentsByFlagSets(key, [flagSetName], attributes, false, TREATMENTS_BY_FLAGSET);
113
+ return getTreatmentsByFlagSets(key, [flagSetName], attributes, false, TREATMENTS_BY_FLAGSET, GET_TREATMENTS_BY_FLAG_SET);
114
114
  }
115
115
 
116
116
  function getTreatmentsWithConfigByFlagSet(key: SplitIO.SplitKey, flagSetName: string, attributes: SplitIO.Attributes | undefined) {
117
- return getTreatmentsByFlagSets(key, [flagSetName], attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSET);
117
+ return getTreatmentsByFlagSets(key, [flagSetName], attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET);
118
118
  }
119
119
 
120
120
  // Internal function
@@ -171,7 +171,7 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
171
171
  };
172
172
 
173
173
  // 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.
174
- validateTrafficTypeExistence(log, readinessManager, storage.splits, mode, trafficTypeName, 'track');
174
+ validateTrafficTypeExistence(log, readinessManager, storage.splits, mode, trafficTypeName, TRACK_FN_LABEL);
175
175
 
176
176
  const result = eventTracker.track(eventData, size);
177
177
 
@@ -12,7 +12,7 @@ import {
12
12
  validateIfOperational
13
13
  } from '../utils/inputValidation';
14
14
  import { startsWith } from '../utils/lang';
15
- import { CONTROL, CONTROL_WITH_CONFIG } from '../utils/constants';
15
+ import { CONTROL, CONTROL_WITH_CONFIG, GET_TREATMENT, GET_TREATMENTS, GET_TREATMENTS_BY_FLAG_SET, GET_TREATMENTS_BY_FLAG_SETS, GET_TREATMENTS_WITH_CONFIG, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, GET_TREATMENT_WITH_CONFIG, TRACK_FN_LABEL } from '../utils/constants';
16
16
  import { IReadinessManager } from '../readiness/types';
17
17
  import { MaybeThenable } from '../dtos/types';
18
18
  import { ISettings, SplitIO } from '../types';
@@ -32,7 +32,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
32
32
  * Avoid repeating this validations code
33
33
  */
34
34
  function validateEvaluationParams(maybeKey: SplitIO.SplitKey, maybeFeatureFlagNameOrNames: string | string[] | undefined, maybeAttributes: SplitIO.Attributes | undefined, methodName: string, maybeFlagSetNameOrNames?: string[]) {
35
- const multi = startsWith(methodName, 'getTreatments');
35
+ const multi = startsWith(methodName, GET_TREATMENTS);
36
36
  const key = validateKey(log, maybeKey, methodName);
37
37
  let splitOrSplits: string | string[] | false = false;
38
38
  let flagSetOrFlagSets: string[] = [];
@@ -63,7 +63,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
63
63
  }
64
64
 
65
65
  function getTreatment(maybeKey: SplitIO.SplitKey, maybeFeatureFlagName: string, maybeAttributes?: SplitIO.Attributes) {
66
- const params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, 'getTreatment');
66
+ const params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, GET_TREATMENT);
67
67
 
68
68
  if (params.valid) {
69
69
  return client.getTreatment(params.key as SplitIO.SplitKey, params.splitOrSplits as string, params.attributes as SplitIO.Attributes | undefined);
@@ -73,7 +73,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
73
73
  }
74
74
 
75
75
  function getTreatmentWithConfig(maybeKey: SplitIO.SplitKey, maybeFeatureFlagName: string, maybeAttributes?: SplitIO.Attributes) {
76
- const params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, 'getTreatmentWithConfig');
76
+ const params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, GET_TREATMENT_WITH_CONFIG);
77
77
 
78
78
  if (params.valid) {
79
79
  return client.getTreatmentWithConfig(params.key as SplitIO.SplitKey, params.splitOrSplits as string, params.attributes as SplitIO.Attributes | undefined);
@@ -83,7 +83,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
83
83
  }
84
84
 
85
85
  function getTreatments(maybeKey: SplitIO.SplitKey, maybeFeatureFlagNames: string[], maybeAttributes?: SplitIO.Attributes) {
86
- const params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes, 'getTreatments');
86
+ const params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes, GET_TREATMENTS);
87
87
 
88
88
  if (params.valid) {
89
89
  return client.getTreatments(params.key as SplitIO.SplitKey, params.splitOrSplits as string[], params.attributes as SplitIO.Attributes | undefined);
@@ -96,7 +96,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
96
96
  }
97
97
 
98
98
  function getTreatmentsWithConfig(maybeKey: SplitIO.SplitKey, maybeFeatureFlagNames: string[], maybeAttributes?: SplitIO.Attributes) {
99
- const params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes, 'getTreatmentsWithConfig');
99
+ const params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes, GET_TREATMENTS_WITH_CONFIG);
100
100
 
101
101
  if (params.valid) {
102
102
  return client.getTreatmentsWithConfig(params.key as SplitIO.SplitKey, params.splitOrSplits as string[], params.attributes as SplitIO.Attributes | undefined);
@@ -109,7 +109,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
109
109
  }
110
110
 
111
111
  function getTreatmentsByFlagSets(maybeKey: SplitIO.SplitKey, maybeFlagSets: string[], maybeAttributes?: SplitIO.Attributes) {
112
- const params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, 'getTreatmentsByFlagSets', maybeFlagSets);
112
+ const params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, GET_TREATMENTS_BY_FLAG_SETS, maybeFlagSets);
113
113
 
114
114
  if (params.valid) {
115
115
  return client.getTreatmentsByFlagSets(params.key as SplitIO.SplitKey, params.flagSetOrFlagSets as string[], params.attributes as SplitIO.Attributes | undefined);
@@ -119,7 +119,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
119
119
  }
120
120
 
121
121
  function getTreatmentsWithConfigByFlagSets(maybeKey: SplitIO.SplitKey, maybeFlagSets: string[], maybeAttributes?: SplitIO.Attributes) {
122
- const params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, 'getTreatmentsWithConfigByFlagSets', maybeFlagSets);
122
+ const params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, maybeFlagSets);
123
123
 
124
124
  if (params.valid) {
125
125
  return client.getTreatmentsWithConfigByFlagSets(params.key as SplitIO.SplitKey, params.flagSetOrFlagSets as string[], params.attributes as SplitIO.Attributes | undefined);
@@ -129,7 +129,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
129
129
  }
130
130
 
131
131
  function getTreatmentsByFlagSet(maybeKey: SplitIO.SplitKey, maybeFlagSet: string, maybeAttributes?: SplitIO.Attributes) {
132
- const params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, 'getTreatmentsByFlagSet', [maybeFlagSet]);
132
+ const params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, GET_TREATMENTS_BY_FLAG_SET, [maybeFlagSet]);
133
133
 
134
134
  if (params.valid) {
135
135
  return client.getTreatmentsByFlagSet(params.key as SplitIO.SplitKey, params.flagSetOrFlagSets[0] as string, params.attributes as SplitIO.Attributes | undefined);
@@ -139,7 +139,7 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
139
139
  }
140
140
 
141
141
  function getTreatmentsWithConfigByFlagSet(maybeKey: SplitIO.SplitKey, maybeFlagSet: string, maybeAttributes?: SplitIO.Attributes) {
142
- const params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, 'getTreatmentsWithConfigByFlagSet', [maybeFlagSet]);
142
+ const params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, [maybeFlagSet]);
143
143
 
144
144
  if (params.valid) {
145
145
  return client.getTreatmentsWithConfigByFlagSet(params.key as SplitIO.SplitKey, params.flagSetOrFlagSets[0] as string, params.attributes as SplitIO.Attributes | undefined);
@@ -149,12 +149,12 @@ export function clientInputValidationDecorator<TClient extends SplitIO.IClient |
149
149
  }
150
150
 
151
151
  function track(maybeKey: SplitIO.SplitKey, maybeTT: string, maybeEvent: string, maybeEventValue?: number, maybeProperties?: SplitIO.Properties) {
152
- const key = validateKey(log, maybeKey, 'track');
153
- const tt = validateTrafficType(log, maybeTT, 'track');
154
- const event = validateEvent(log, maybeEvent, 'track');
155
- const eventValue = validateEventValue(log, maybeEventValue, 'track');
156
- const { properties, size } = validateEventProperties(log, maybeProperties, 'track');
157
- const isNotDestroyed = validateIfNotDestroyed(log, readinessManager, 'track');
152
+ const key = validateKey(log, maybeKey, TRACK_FN_LABEL);
153
+ const tt = validateTrafficType(log, maybeTT, TRACK_FN_LABEL);
154
+ const event = validateEvent(log, maybeEvent, TRACK_FN_LABEL);
155
+ const eventValue = validateEventValue(log, maybeEventValue, TRACK_FN_LABEL);
156
+ const { properties, size } = validateEventProperties(log, maybeProperties, TRACK_FN_LABEL);
157
+ const isNotDestroyed = validateIfNotDestroyed(log, readinessManager, TRACK_FN_LABEL);
158
158
 
159
159
  if (isNotDestroyed && key && tt && event && eventValue !== false && properties !== false) { // @ts-expect-error
160
160
  return client.track(key, tt, event, eventValue, properties, size);
@@ -7,10 +7,7 @@ import { ISdkReadinessManager } from '../readiness/types';
7
7
  import { ISplit } from '../dtos/types';
8
8
  import { ISettings, SplitIO } from '../types';
9
9
  import { isStorageSync } from '../trackers/impressionObserver/utils';
10
-
11
- const SPLIT_FN_LABEL = 'split';
12
- const SPLITS_FN_LABEL = 'splits';
13
- const NAMES_FN_LABEL = 'names';
10
+ import { SPLIT_FN_LABEL, SPLITS_FN_LABEL, NAMES_FN_LABEL } from '../utils/constants';
14
11
 
15
12
  function collectTreatments(splitObject: ISplit) {
16
13
  const conditions = splitObject.conditions;
@@ -39,6 +39,22 @@ export const CONSENT_GRANTED = 'GRANTED'; // The user has granted consent for tr
39
39
  export const CONSENT_DECLINED = 'DECLINED'; // The user has declined consent for tracking events and impressions
40
40
  export const CONSENT_UNKNOWN = 'UNKNOWN'; // The user has neither granted nor declined consent for tracking events and impressions
41
41
 
42
+ // Client method names
43
+ export const GET_TREATMENT = 'getTreatment';
44
+ export const GET_TREATMENTS = 'getTreatments';
45
+ export const GET_TREATMENT_WITH_CONFIG = 'getTreatmentWithConfig';
46
+ export const GET_TREATMENTS_WITH_CONFIG = 'getTreatmentsWithConfig';
47
+ export const GET_TREATMENTS_BY_FLAG_SET = 'getTreatmentsByFlagSet';
48
+ export const GET_TREATMENTS_BY_FLAG_SETS = 'getTreatmentsByFlagSets';
49
+ export const GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET = 'getTreatmentsWithConfigByFlagSet';
50
+ export const GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS = 'getTreatmentsWithConfigByFlagSets';
51
+ export const TRACK_FN_LABEL = 'track';
52
+
53
+ // Manager method names
54
+ export const SPLIT_FN_LABEL = 'split';
55
+ export const SPLITS_FN_LABEL = 'splits';
56
+ export const NAMES_FN_LABEL = 'names';
57
+
42
58
  // Telemetry
43
59
  export const QUEUED = 0;
44
60
  export const DROPPED = 1;
@@ -24,6 +24,18 @@ export declare const STORAGE_PLUGGABLE: StorageType;
24
24
  export declare const CONSENT_GRANTED = "GRANTED";
25
25
  export declare const CONSENT_DECLINED = "DECLINED";
26
26
  export declare const CONSENT_UNKNOWN = "UNKNOWN";
27
+ export declare const GET_TREATMENT = "getTreatment";
28
+ export declare const GET_TREATMENTS = "getTreatments";
29
+ export declare const GET_TREATMENT_WITH_CONFIG = "getTreatmentWithConfig";
30
+ export declare const GET_TREATMENTS_WITH_CONFIG = "getTreatmentsWithConfig";
31
+ export declare const GET_TREATMENTS_BY_FLAG_SET = "getTreatmentsByFlagSet";
32
+ export declare const GET_TREATMENTS_BY_FLAG_SETS = "getTreatmentsByFlagSets";
33
+ export declare const GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET = "getTreatmentsWithConfigByFlagSet";
34
+ export declare const GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS = "getTreatmentsWithConfigByFlagSets";
35
+ export declare const TRACK_FN_LABEL = "track";
36
+ export declare const SPLIT_FN_LABEL = "split";
37
+ export declare const SPLITS_FN_LABEL = "splits";
38
+ export declare const NAMES_FN_LABEL = "names";
27
39
  export declare const QUEUED = 0;
28
40
  export declare const DROPPED = 1;
29
41
  export declare const DEDUPED = 2;