@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.
- package/CHANGES.txt +10 -9
- package/cjs/sdkClient/client.js +16 -13
- package/cjs/sdkClient/clientInputValidation.js +15 -15
- package/cjs/sdkFactory/index.js +1 -1
- package/cjs/sdkManager/index.js +14 -13
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +5 -1
- package/cjs/storages/inRedis/RedisAdapter.js +29 -12
- package/cjs/storages/inRedis/SegmentsCacheInRedis.js +2 -2
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +5 -9
- package/cjs/utils/constants/index.js +16 -2
- package/cjs/utils/redis/RedisMock.js +7 -1
- package/esm/sdkClient/client.js +17 -14
- package/esm/sdkClient/clientInputValidation.js +16 -16
- package/esm/sdkFactory/index.js +1 -1
- package/esm/sdkManager/index.js +8 -7
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +5 -1
- package/esm/storages/inRedis/RedisAdapter.js +29 -12
- package/esm/storages/inRedis/SegmentsCacheInRedis.js +2 -2
- package/esm/storages/inRedis/SplitsCacheInRedis.js +5 -9
- package/esm/utils/constants/index.js +14 -0
- package/esm/utils/redis/RedisMock.js +7 -1
- package/package.json +1 -1
- package/src/sdkClient/client.ts +15 -15
- package/src/sdkClient/clientInputValidation.ts +16 -16
- package/src/sdkFactory/index.ts +1 -1
- package/src/sdkFactory/types.ts +3 -7
- package/src/sdkManager/index.ts +11 -11
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +5 -1
- package/src/storages/inRedis/RedisAdapter.ts +35 -17
- package/src/storages/inRedis/SegmentsCacheInRedis.ts +2 -2
- package/src/storages/inRedis/SplitsCacheInRedis.ts +5 -9
- package/src/trackers/impressionObserver/utils.ts +1 -1
- package/src/utils/constants/index.ts +16 -0
- package/src/utils/redis/RedisMock.ts +9 -1
- package/types/sdkFactory/types.d.ts +3 -3
- package/types/sdkManager/index.d.ts +2 -3
- package/types/storages/inRedis/RedisAdapter.d.ts +1 -2
- package/types/storages/inRedis/SegmentsCacheInRedis.d.ts +1 -1
- package/types/storages/inRedis/SplitsCacheInRedis.d.ts +2 -7
- package/types/trackers/impressionObserver/utils.d.ts +1 -1
- package/types/utils/constants/index.d.ts +12 -0
- package/types/utils/redis/RedisMock.d.ts +1 -0
|
@@ -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,
|
|
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,
|
|
44
|
+
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, GET_TREATMENT);
|
|
45
45
|
if (params.valid) {
|
|
46
46
|
return client.getTreatment(params.key, params.splitOrSplits, params.attributes);
|
|
47
47
|
}
|
|
@@ -50,7 +50,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
function getTreatmentWithConfig(maybeKey, maybeFeatureFlagName, maybeAttributes) {
|
|
53
|
-
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes,
|
|
53
|
+
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagName, maybeAttributes, GET_TREATMENT_WITH_CONFIG);
|
|
54
54
|
if (params.valid) {
|
|
55
55
|
return client.getTreatmentWithConfig(params.key, params.splitOrSplits, params.attributes);
|
|
56
56
|
}
|
|
@@ -59,7 +59,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
function getTreatments(maybeKey, maybeFeatureFlagNames, maybeAttributes) {
|
|
62
|
-
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes,
|
|
62
|
+
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes, GET_TREATMENTS);
|
|
63
63
|
if (params.valid) {
|
|
64
64
|
return client.getTreatments(params.key, params.splitOrSplits, params.attributes);
|
|
65
65
|
}
|
|
@@ -71,7 +71,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
function getTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, maybeAttributes) {
|
|
74
|
-
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes,
|
|
74
|
+
var params = validateEvaluationParams(maybeKey, maybeFeatureFlagNames, maybeAttributes, GET_TREATMENTS_WITH_CONFIG);
|
|
75
75
|
if (params.valid) {
|
|
76
76
|
return client.getTreatmentsWithConfig(params.key, params.splitOrSplits, params.attributes);
|
|
77
77
|
}
|
|
@@ -83,7 +83,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
function getTreatmentsByFlagSets(maybeKey, maybeFlagSets, maybeAttributes) {
|
|
86
|
-
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes,
|
|
86
|
+
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, GET_TREATMENTS_BY_FLAG_SETS, maybeFlagSets);
|
|
87
87
|
if (params.valid) {
|
|
88
88
|
return client.getTreatmentsByFlagSets(params.key, params.flagSetOrFlagSets, params.attributes);
|
|
89
89
|
}
|
|
@@ -92,7 +92,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
function getTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, maybeAttributes) {
|
|
95
|
-
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes,
|
|
95
|
+
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, maybeFlagSets);
|
|
96
96
|
if (params.valid) {
|
|
97
97
|
return client.getTreatmentsWithConfigByFlagSets(params.key, params.flagSetOrFlagSets, params.attributes);
|
|
98
98
|
}
|
|
@@ -101,7 +101,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
function getTreatmentsByFlagSet(maybeKey, maybeFlagSet, maybeAttributes) {
|
|
104
|
-
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes,
|
|
104
|
+
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, GET_TREATMENTS_BY_FLAG_SET, [maybeFlagSet]);
|
|
105
105
|
if (params.valid) {
|
|
106
106
|
return client.getTreatmentsByFlagSet(params.key, params.flagSetOrFlagSets[0], params.attributes);
|
|
107
107
|
}
|
|
@@ -110,7 +110,7 @@ export function clientInputValidationDecorator(settings, client, readinessManage
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
function getTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, maybeAttributes) {
|
|
113
|
-
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes,
|
|
113
|
+
var params = validateEvaluationParams(maybeKey, undefined, maybeAttributes, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, [maybeFlagSet]);
|
|
114
114
|
if (params.valid) {
|
|
115
115
|
return client.getTreatmentsWithConfigByFlagSet(params.key, params.flagSetOrFlagSets[0], params.attributes);
|
|
116
116
|
}
|
|
@@ -119,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,
|
|
123
|
-
var tt = validateTrafficType(log, maybeTT,
|
|
124
|
-
var event = validateEvent(log, maybeEvent,
|
|
125
|
-
var eventValue = validateEventValue(log, maybeEventValue,
|
|
126
|
-
var _a = validateEventProperties(log, maybeProperties,
|
|
127
|
-
var isNotDestroyed = validateIfNotDestroyed(log, readinessManager,
|
|
122
|
+
var key = validateKey(log, maybeKey, TRACK_FN_LABEL);
|
|
123
|
+
var tt = validateTrafficType(log, maybeTT, TRACK_FN_LABEL);
|
|
124
|
+
var event = validateEvent(log, maybeEvent, TRACK_FN_LABEL);
|
|
125
|
+
var eventValue = validateEventValue(log, maybeEventValue, TRACK_FN_LABEL);
|
|
126
|
+
var _a = validateEventProperties(log, maybeProperties, TRACK_FN_LABEL), properties = _a.properties, size = _a.size;
|
|
127
|
+
var isNotDestroyed = validateIfNotDestroyed(log, readinessManager, TRACK_FN_LABEL);
|
|
128
128
|
if (isNotDestroyed && key && tt && event && eventValue !== false && properties !== false) { // @ts-expect-error
|
|
129
129
|
return client.track(key, tt, event, eventValue, properties, size);
|
|
130
130
|
}
|
package/esm/sdkFactory/index.js
CHANGED
|
@@ -63,7 +63,7 @@ export function sdkFactory(params) {
|
|
|
63
63
|
ctx.signalListener = signalListener;
|
|
64
64
|
// SDK client and manager
|
|
65
65
|
var clientMethod = sdkClientMethodFactory(ctx);
|
|
66
|
-
var managerInstance = sdkManagerFactory(
|
|
66
|
+
var managerInstance = sdkManagerFactory(settings, storage.splits, sdkReadinessManager);
|
|
67
67
|
syncManager && syncManager.start();
|
|
68
68
|
signalListener && signalListener.start();
|
|
69
69
|
log.info(NEW_FACTORY);
|
package/esm/sdkManager/index.js
CHANGED
|
@@ -2,9 +2,8 @@ import { objectAssign } from '../utils/lang/objectAssign';
|
|
|
2
2
|
import { thenable } from '../utils/promise/thenable';
|
|
3
3
|
import { find } from '../utils/lang';
|
|
4
4
|
import { validateSplit, validateSplitExistence, validateIfNotDestroyed, validateIfOperational } from '../utils/inputValidation';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var NAMES_FN_LABEL = 'names';
|
|
5
|
+
import { isStorageSync } from '../trackers/impressionObserver/utils';
|
|
6
|
+
import { SPLIT_FN_LABEL, SPLITS_FN_LABEL, NAMES_FN_LABEL } from '../utils/constants';
|
|
8
7
|
function collectTreatments(splitObject) {
|
|
9
8
|
var conditions = splitObject.conditions;
|
|
10
9
|
// Rollout conditions are supposed to have the entire partitions list, so we find the first one.
|
|
@@ -38,8 +37,10 @@ function objectsToViews(splitObjects) {
|
|
|
38
37
|
});
|
|
39
38
|
return views;
|
|
40
39
|
}
|
|
41
|
-
export function sdkManagerFactory(
|
|
40
|
+
export function sdkManagerFactory(settings, splits, _a) {
|
|
42
41
|
var readinessManager = _a.readinessManager, sdkStatus = _a.sdkStatus;
|
|
42
|
+
var log = settings.log;
|
|
43
|
+
var isSync = isStorageSync(settings);
|
|
43
44
|
return objectAssign(
|
|
44
45
|
// Proto-linkage of the readiness Event Emitter
|
|
45
46
|
Object.create(sdkStatus), {
|
|
@@ -49,7 +50,7 @@ export function sdkManagerFactory(log, splits, _a) {
|
|
|
49
50
|
split: function (featureFlagName) {
|
|
50
51
|
var splitName = validateSplit(log, featureFlagName, SPLIT_FN_LABEL);
|
|
51
52
|
if (!validateIfNotDestroyed(log, readinessManager, SPLIT_FN_LABEL) || !validateIfOperational(log, readinessManager, SPLIT_FN_LABEL) || !splitName) {
|
|
52
|
-
return null;
|
|
53
|
+
return isSync ? null : Promise.resolve(null);
|
|
53
54
|
}
|
|
54
55
|
var split = splits.getSplit(splitName);
|
|
55
56
|
if (thenable(split)) {
|
|
@@ -66,7 +67,7 @@ export function sdkManagerFactory(log, splits, _a) {
|
|
|
66
67
|
*/
|
|
67
68
|
splits: function () {
|
|
68
69
|
if (!validateIfNotDestroyed(log, readinessManager, SPLITS_FN_LABEL) || !validateIfOperational(log, readinessManager, SPLITS_FN_LABEL)) {
|
|
69
|
-
return [];
|
|
70
|
+
return isSync ? [] : Promise.resolve([]);
|
|
70
71
|
}
|
|
71
72
|
var currentSplits = splits.getAll();
|
|
72
73
|
return thenable(currentSplits) ?
|
|
@@ -78,7 +79,7 @@ export function sdkManagerFactory(log, splits, _a) {
|
|
|
78
79
|
*/
|
|
79
80
|
names: function () {
|
|
80
81
|
if (!validateIfNotDestroyed(log, readinessManager, NAMES_FN_LABEL) || !validateIfOperational(log, readinessManager, NAMES_FN_LABEL)) {
|
|
81
|
-
return [];
|
|
82
|
+
return isSync ? [] : Promise.resolve([]);
|
|
82
83
|
}
|
|
83
84
|
var splitNames = splits.getSplitNames();
|
|
84
85
|
return thenable(splitNames) ?
|
|
@@ -20,7 +20,11 @@ var ImpressionCountsCacheInRedis = /** @class */ (function (_super) {
|
|
|
20
20
|
var keys = Object.keys(counts);
|
|
21
21
|
if (!keys.length)
|
|
22
22
|
return Promise.resolve(false);
|
|
23
|
-
|
|
23
|
+
var pipeline = this.redis.pipeline();
|
|
24
|
+
keys.forEach(function (key) {
|
|
25
|
+
pipeline.hincrby(_this.key, key, counts[key]);
|
|
26
|
+
});
|
|
27
|
+
return pipeline.exec()
|
|
24
28
|
.then(function (data) {
|
|
25
29
|
// If this is the creation of the key on Redis, set the expiration for it in 3600 seconds.
|
|
26
30
|
if (data.length && data.length === keys.length) {
|
|
@@ -6,7 +6,8 @@ import { thenable } from '../../utils/promise/thenable';
|
|
|
6
6
|
import { timeout } from '../../utils/promise/timeout';
|
|
7
7
|
var LOG_PREFIX = 'storage:redis-adapter: ';
|
|
8
8
|
// If we ever decide to fully wrap every method, there's a Commander.getBuiltinCommands from ioredis.
|
|
9
|
-
var METHODS_TO_PROMISE_WRAP = ['set', 'exec', 'del', 'get', 'keys', 'sadd', 'srem', 'sismember', 'smembers', 'incr', 'rpush', 'expire', 'mget', 'lrange', 'ltrim', 'hset', 'hincrby', 'popNRaw'
|
|
9
|
+
var METHODS_TO_PROMISE_WRAP = ['set', 'exec', 'del', 'get', 'keys', 'sadd', 'srem', 'sismember', 'smembers', 'incr', 'rpush', 'expire', 'mget', 'lrange', 'ltrim', 'hset', 'hincrby', 'popNRaw'];
|
|
10
|
+
var METHODS_TO_PROMISE_WRAP_EXEC = ['pipeline'];
|
|
10
11
|
// Not part of the settings since it'll vary on each storage. We should be removing storage specific logic from elsewhere.
|
|
11
12
|
var DEFAULT_OPTIONS = {
|
|
12
13
|
connectionTimeout: 10000,
|
|
@@ -24,6 +25,7 @@ var DEFAULT_LIBRARY_OPTIONS = {
|
|
|
24
25
|
var RedisAdapter = /** @class */ (function (_super) {
|
|
25
26
|
__extends(RedisAdapter, _super);
|
|
26
27
|
function RedisAdapter(log, storageSettings) {
|
|
28
|
+
if (storageSettings === void 0) { storageSettings = {}; }
|
|
27
29
|
var _this = this;
|
|
28
30
|
var options = RedisAdapter._defineOptions(storageSettings);
|
|
29
31
|
// Call the ioredis constructor
|
|
@@ -37,9 +39,6 @@ var RedisAdapter = /** @class */ (function (_super) {
|
|
|
37
39
|
_this._setDisconnectWrapper();
|
|
38
40
|
return _this;
|
|
39
41
|
}
|
|
40
|
-
RedisAdapter.prototype.pipelineExec = function (commands) {
|
|
41
|
-
return this.pipeline(commands).exec();
|
|
42
|
-
};
|
|
43
42
|
RedisAdapter.prototype._listenToEvents = function () {
|
|
44
43
|
var _this = this;
|
|
45
44
|
this.once('ready', function () {
|
|
@@ -58,13 +57,15 @@ var RedisAdapter = /** @class */ (function (_super) {
|
|
|
58
57
|
};
|
|
59
58
|
RedisAdapter.prototype._setTimeoutWrappers = function () {
|
|
60
59
|
var instance = this;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
instance
|
|
60
|
+
var wrapCommand = function (originalMethod, methodName) {
|
|
61
|
+
// The value of "this" in this function should be the instance actually executing the method. It might be the instance referred (the base one)
|
|
62
|
+
// or it can be the instance of a Pipeline object.
|
|
63
|
+
return function () {
|
|
64
64
|
var params = arguments;
|
|
65
|
+
var caller = this;
|
|
65
66
|
function commandWrapper() {
|
|
66
67
|
instance.log.debug(LOG_PREFIX + "Executing " + methodName + ".");
|
|
67
|
-
var result = originalMethod.apply(
|
|
68
|
+
var result = originalMethod.apply(caller, params);
|
|
68
69
|
if (thenable(result)) {
|
|
69
70
|
// For handling pending commands on disconnect, add to the set and remove once finished.
|
|
70
71
|
// On sync commands there's no need, only thenables.
|
|
@@ -83,10 +84,10 @@ var RedisAdapter = /** @class */ (function (_super) {
|
|
|
83
84
|
return result;
|
|
84
85
|
}
|
|
85
86
|
if (instance._notReadyCommandsQueue) {
|
|
86
|
-
return new Promise(function (
|
|
87
|
+
return new Promise(function (resolve, reject) {
|
|
87
88
|
instance._notReadyCommandsQueue.unshift({
|
|
88
|
-
resolve:
|
|
89
|
-
reject:
|
|
89
|
+
resolve: resolve,
|
|
90
|
+
reject: reject,
|
|
90
91
|
command: commandWrapper,
|
|
91
92
|
name: methodName.toUpperCase()
|
|
92
93
|
});
|
|
@@ -96,6 +97,22 @@ var RedisAdapter = /** @class */ (function (_super) {
|
|
|
96
97
|
return commandWrapper();
|
|
97
98
|
}
|
|
98
99
|
};
|
|
100
|
+
};
|
|
101
|
+
// Wrap regular async methods to track timeouts and queue when Redis is not yet executing commands.
|
|
102
|
+
METHODS_TO_PROMISE_WRAP.forEach(function (methodName) {
|
|
103
|
+
var originalFn = instance[methodName];
|
|
104
|
+
instance[methodName] = wrapCommand(originalFn, methodName);
|
|
105
|
+
});
|
|
106
|
+
// Special handling for pipeline~like methods. We need to wrap the async trigger, which is exec, but return the Pipeline right away.
|
|
107
|
+
METHODS_TO_PROMISE_WRAP_EXEC.forEach(function (methodName) {
|
|
108
|
+
var originalFn = instance[methodName];
|
|
109
|
+
// "First level wrapper" to handle the sync execution and wrap async, queueing later if applicable.
|
|
110
|
+
instance[methodName] = function () {
|
|
111
|
+
var res = originalFn.apply(instance, arguments);
|
|
112
|
+
var originalExec = res.exec;
|
|
113
|
+
res.exec = wrapCommand(originalExec, methodName + '.exec').bind(res);
|
|
114
|
+
return res;
|
|
115
|
+
};
|
|
99
116
|
});
|
|
100
117
|
};
|
|
101
118
|
RedisAdapter.prototype._setDisconnectWrapper = function () {
|
|
@@ -157,7 +174,7 @@ var RedisAdapter = /** @class */ (function (_super) {
|
|
|
157
174
|
* Parses the options into what we care about.
|
|
158
175
|
*/
|
|
159
176
|
RedisAdapter._defineOptions = function (_a) {
|
|
160
|
-
var
|
|
177
|
+
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;
|
|
161
178
|
var parsedOptions = {
|
|
162
179
|
connectionTimeout: connectionTimeout,
|
|
163
180
|
operationTimeout: operationTimeout,
|
|
@@ -51,9 +51,9 @@ var SegmentsCacheInRedis = /** @class */ (function () {
|
|
|
51
51
|
SegmentsCacheInRedis.prototype.getRegisteredSegments = function () {
|
|
52
52
|
return this.redis.smembers(this.keys.buildRegisteredSegmentsKey());
|
|
53
53
|
};
|
|
54
|
-
// @TODO remove
|
|
54
|
+
// @TODO remove or implement. It is not being used.
|
|
55
55
|
SegmentsCacheInRedis.prototype.clear = function () {
|
|
56
|
-
return
|
|
56
|
+
return Promise.resolve();
|
|
57
57
|
};
|
|
58
58
|
return SegmentsCacheInRedis;
|
|
59
59
|
}());
|
|
@@ -168,7 +168,7 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
168
168
|
SplitsCacheInRedis.prototype.getAll = function () {
|
|
169
169
|
var _this = this;
|
|
170
170
|
return this.redis.keys(this.keys.searchPatternForSplitKeys())
|
|
171
|
-
.then(function (listOfKeys) { return _this.redis.
|
|
171
|
+
.then(function (listOfKeys) { return _this.redis.pipeline(listOfKeys.map(function (k) { return ['get', k]; })).exec(); })
|
|
172
172
|
.then(processPipelineAnswer)
|
|
173
173
|
.then(function (splitDefinitions) { return splitDefinitions.map(function (splitDefinition) {
|
|
174
174
|
return JSON.parse(splitDefinition);
|
|
@@ -186,11 +186,11 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
186
186
|
/**
|
|
187
187
|
* Get list of feature flag names related to a given list of flag set names.
|
|
188
188
|
* The returned promise is resolved with the list of feature flag names per flag set,
|
|
189
|
-
* or rejected if the pipelined redis operation fails.
|
|
189
|
+
* or rejected if the pipelined redis operation fails (e.g., timeout).
|
|
190
190
|
*/
|
|
191
191
|
SplitsCacheInRedis.prototype.getNamesByFlagSets = function (flagSets) {
|
|
192
192
|
var _this = this;
|
|
193
|
-
return this.redis.
|
|
193
|
+
return this.redis.pipeline(flagSets.map(function (flagSet) { return ['smembers', _this.keys.buildFlagSetKey(flagSet)]; })).exec()
|
|
194
194
|
.then(function (results) { return results.map(function (_a, index) {
|
|
195
195
|
var e = _a[0], value = _a[1];
|
|
196
196
|
if (e === null)
|
|
@@ -225,13 +225,9 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
|
|
|
225
225
|
return true;
|
|
226
226
|
});
|
|
227
227
|
};
|
|
228
|
-
|
|
229
|
-
* Delete everything in the current database.
|
|
230
|
-
*
|
|
231
|
-
* @NOTE documentation says it never fails.
|
|
232
|
-
*/
|
|
228
|
+
// @TODO remove or implement. It is not being used.
|
|
233
229
|
SplitsCacheInRedis.prototype.clear = function () {
|
|
234
|
-
return
|
|
230
|
+
return Promise.resolve();
|
|
235
231
|
};
|
|
236
232
|
/**
|
|
237
233
|
* Fetches multiple splits definitions.
|
|
@@ -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;
|
|
@@ -6,16 +6,22 @@ function asyncFunction(data) {
|
|
|
6
6
|
return Promise.resolve(data);
|
|
7
7
|
}
|
|
8
8
|
var IDENTITY_METHODS = [];
|
|
9
|
-
var ASYNC_METHODS = ['rpush', 'hincrby'
|
|
9
|
+
var ASYNC_METHODS = ['rpush', 'hincrby'];
|
|
10
|
+
var PIPELINE_METHODS = ['rpush', 'hincrby'];
|
|
10
11
|
var RedisMock = /** @class */ (function () {
|
|
11
12
|
function RedisMock() {
|
|
12
13
|
var _this = this;
|
|
14
|
+
this.pipelineMethods = { exec: jest.fn(asyncFunction) };
|
|
13
15
|
IDENTITY_METHODS.forEach(function (method) {
|
|
14
16
|
_this[method] = jest.fn(identityFunction);
|
|
15
17
|
});
|
|
16
18
|
ASYNC_METHODS.forEach(function (method) {
|
|
17
19
|
_this[method] = jest.fn(asyncFunction);
|
|
18
20
|
});
|
|
21
|
+
PIPELINE_METHODS.forEach(function (method) {
|
|
22
|
+
_this.pipelineMethods[method] = _this[method];
|
|
23
|
+
});
|
|
24
|
+
this.pipeline = jest.fn(function () { return _this.pipelineMethods; });
|
|
19
25
|
}
|
|
20
26
|
return RedisMock;
|
|
21
27
|
}());
|
package/package.json
CHANGED
package/src/sdkClient/client.ts
CHANGED
|
@@ -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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
153
|
-
const tt = validateTrafficType(log, maybeTT,
|
|
154
|
-
const event = validateEvent(log, maybeEvent,
|
|
155
|
-
const eventValue = validateEventValue(log, maybeEventValue,
|
|
156
|
-
const { properties, size } = validateEventProperties(log, maybeProperties,
|
|
157
|
-
const isNotDestroyed = validateIfNotDestroyed(log, readinessManager,
|
|
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);
|
package/src/sdkFactory/index.ts
CHANGED
|
@@ -83,7 +83,7 @@ export function sdkFactory(params: ISdkFactoryParams): SplitIO.ICsSDK | SplitIO.
|
|
|
83
83
|
|
|
84
84
|
// SDK client and manager
|
|
85
85
|
const clientMethod = sdkClientMethodFactory(ctx);
|
|
86
|
-
const managerInstance = sdkManagerFactory(
|
|
86
|
+
const managerInstance = sdkManagerFactory(settings, storage.splits, sdkReadinessManager);
|
|
87
87
|
|
|
88
88
|
syncManager && syncManager.start();
|
|
89
89
|
signalListener && signalListener.start();
|
package/src/sdkFactory/types.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { IIntegrationManager, IIntegrationFactoryParams } from '../integrations/types';
|
|
2
2
|
import { ISignalListener } from '../listeners/types';
|
|
3
|
-
import { ILogger } from '../logger/types';
|
|
4
3
|
import { IReadinessManager, ISdkReadinessManager } from '../readiness/types';
|
|
4
|
+
import type { sdkManagerFactory } from '../sdkManager';
|
|
5
5
|
import { IFetch, ISplitApi, IEventSourceConstructor } from '../services/types';
|
|
6
|
-
import { IStorageAsync, IStorageSync,
|
|
6
|
+
import { IStorageAsync, IStorageSync, IStorageFactoryParams } from '../storages/types';
|
|
7
7
|
import { ISyncManager } from '../sync/types';
|
|
8
8
|
import { IImpressionObserver } from '../trackers/impressionObserver/types';
|
|
9
9
|
import { IImpressionsTracker, IEventTracker, ITelemetryTracker, IFilterAdapter, IUniqueKeysTracker } from '../trackers/types';
|
|
@@ -87,11 +87,7 @@ export interface ISdkFactoryParams {
|
|
|
87
87
|
syncManagerFactory?: (params: ISdkFactoryContextSync) => ISyncManager,
|
|
88
88
|
|
|
89
89
|
// Sdk manager factory
|
|
90
|
-
sdkManagerFactory:
|
|
91
|
-
log: ILogger,
|
|
92
|
-
splits: ISplitsCacheSync | ISplitsCacheAsync,
|
|
93
|
-
sdkReadinessManager: ISdkReadinessManager
|
|
94
|
-
) => SplitIO.IManager | SplitIO.IAsyncManager,
|
|
90
|
+
sdkManagerFactory: typeof sdkManagerFactory,
|
|
95
91
|
|
|
96
92
|
// Sdk client method factory (ISDK::client method).
|
|
97
93
|
// It Allows to distinguish SDK clients with the client-side API (`ICsSDK`) or server-side API (`ISDK` or `IAsyncSDK`).
|