@splitsoftware/splitio-commons 3.1.0 → 3.1.1-rc.1
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 +4 -0
- package/cjs/evaluator/condition/index.js +1 -1
- package/cjs/evaluator/index.js +26 -46
- package/cjs/listeners/browser.js +2 -2
- package/cjs/sdkClient/client.js +18 -17
- package/cjs/services/authProvider.js +1 -1
- package/cjs/storages/utils.js +1 -0
- package/cjs/sync/submitters/impressionsSubmitter.js +5 -4
- package/esm/evaluator/condition/index.js +1 -1
- package/esm/evaluator/index.js +26 -46
- package/esm/listeners/browser.js +2 -2
- package/esm/sdkClient/client.js +18 -17
- package/esm/services/authProvider.js +1 -1
- package/esm/storages/utils.js +1 -0
- package/esm/sync/submitters/impressionsSubmitter.js +5 -4
- package/package.json +1 -1
- package/src/dtos/types.ts +7 -0
- package/src/evaluator/Engine.ts +3 -3
- package/src/evaluator/condition/index.ts +2 -2
- package/src/evaluator/index.ts +33 -79
- package/src/evaluator/types.ts +3 -6
- package/src/listeners/browser.ts +2 -2
- package/src/sdkClient/client.ts +24 -25
- package/src/sdkFactory/types.ts +0 -4
- package/src/services/authProvider.ts +1 -1
- package/src/storages/utils.ts +1 -0
- package/src/sync/submitters/impressionsSubmitter.ts +6 -6
- package/src/sync/submitters/types.ts +2 -1
- package/types/splitio.d.ts +1 -171
- package/cjs/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +0 -70
- package/cjs/evaluator/fallbackConfigsCalculator/index.js +0 -25
- package/esm/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +0 -64
- package/esm/evaluator/fallbackConfigsCalculator/index.js +0 -21
- package/src/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.ts +0 -76
- package/src/evaluator/fallbackConfigsCalculator/index.ts +0 -24
package/CHANGES.txt
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
3.2.0 (August 10, 2026)
|
|
2
|
+
- Added support for AI configs.
|
|
3
|
+
- Removed Configs SDK-related types and modules and moved them to the Configs SDK repository.
|
|
4
|
+
|
|
1
5
|
3.1.0 (July 23, 2026)
|
|
2
6
|
- Added support for rule-based segments in /api/v1/configs endpoint.
|
|
3
7
|
- Updated polling flow to fetch new referenced segments immediately.
|
|
@@ -23,7 +23,7 @@ function conditionContext(log, matcherEvaluator, treatments, label, conditionTyp
|
|
|
23
23
|
// Whitelisting has more priority than traffic allocation, so we don't apply this filtering to those conditions.
|
|
24
24
|
if (conditionType === 'ROLLOUT' && !(0, engineUtils_1.shouldApplyRollout)(trafficAllocation, key.bucketingKey, trafficAllocationSeed)) {
|
|
25
25
|
return {
|
|
26
|
-
treatment
|
|
26
|
+
// treatment value is assigned later, at Engine's evaluationResult
|
|
27
27
|
label: labels_1.NOT_IN_SPLIT
|
|
28
28
|
};
|
|
29
29
|
}
|
package/cjs/evaluator/index.js
CHANGED
|
@@ -7,6 +7,7 @@ var labels_1 = require("../utils/labels");
|
|
|
7
7
|
var constants_1 = require("../utils/constants");
|
|
8
8
|
var sets_1 = require("../utils/lang/sets");
|
|
9
9
|
var constants_2 = require("../logger/constants");
|
|
10
|
+
var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
10
11
|
var EVALUATION_EXCEPTION = {
|
|
11
12
|
treatment: constants_1.CONTROL,
|
|
12
13
|
label: labels_1.EXCEPTION,
|
|
@@ -24,7 +25,7 @@ function treatmentsException(definitionNames) {
|
|
|
24
25
|
});
|
|
25
26
|
return evaluations;
|
|
26
27
|
}
|
|
27
|
-
function evaluateFeature(log, key, definitionName, attributes, storage
|
|
28
|
+
function evaluateFeature(log, key, definitionName, attributes, storage) {
|
|
28
29
|
var definition;
|
|
29
30
|
try {
|
|
30
31
|
definition = storage.definitions.get(definitionName);
|
|
@@ -33,16 +34,16 @@ function evaluateFeature(log, key, definitionName, attributes, storage, options)
|
|
|
33
34
|
// Exception on sync storage. Not possible ATM with InMemory and InLocal storages.
|
|
34
35
|
return EVALUATION_EXCEPTION;
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
return (0, thenable_1.thenable)(definition) ?
|
|
38
|
+
definition.then(function (definition) { return getEvaluation(log, key, definition, attributes, storage); })
|
|
39
|
+
.catch(
|
|
38
40
|
// Exception on async storage. For example, when the storage is redis or
|
|
39
41
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
40
|
-
function () { return EVALUATION_EXCEPTION; })
|
|
41
|
-
|
|
42
|
-
return getEvaluation(log, key, definition, attributes, storage, options);
|
|
42
|
+
function () { return EVALUATION_EXCEPTION; }) :
|
|
43
|
+
getEvaluation(log, key, definition, attributes, storage);
|
|
43
44
|
}
|
|
44
45
|
exports.evaluateFeature = evaluateFeature;
|
|
45
|
-
function evaluateFeatures(log, key, definitionNames, attributes, storage
|
|
46
|
+
function evaluateFeatures(log, key, definitionNames, attributes, storage) {
|
|
46
47
|
var definitions;
|
|
47
48
|
try {
|
|
48
49
|
definitions = storage.definitions.getMany(definitionNames);
|
|
@@ -52,16 +53,15 @@ function evaluateFeatures(log, key, definitionNames, attributes, storage, option
|
|
|
52
53
|
return treatmentsException(definitionNames);
|
|
53
54
|
}
|
|
54
55
|
return (0, thenable_1.thenable)(definitions) ?
|
|
55
|
-
definitions.then(function (definitions) { return getEvaluations(log, key, definitionNames, definitions, attributes, storage
|
|
56
|
-
.catch(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
getEvaluations(log, key, definitionNames, definitions, attributes, storage, options);
|
|
56
|
+
definitions.then(function (definitions) { return getEvaluations(log, key, definitionNames, definitions, attributes, storage); })
|
|
57
|
+
.catch(
|
|
58
|
+
// Exception on async storage. For example, when the storage is redis or
|
|
59
|
+
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
60
|
+
function () { return treatmentsException(definitionNames); }) :
|
|
61
|
+
getEvaluations(log, key, definitionNames, definitions, attributes, storage);
|
|
62
62
|
}
|
|
63
63
|
exports.evaluateFeatures = evaluateFeatures;
|
|
64
|
-
function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, method
|
|
64
|
+
function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, method) {
|
|
65
65
|
var storedFlagNames;
|
|
66
66
|
function evaluate(featureFlagsByFlagSets) {
|
|
67
67
|
var featureFlags = new Set();
|
|
@@ -75,7 +75,7 @@ function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, met
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
return featureFlags.size ?
|
|
78
|
-
evaluateFeatures(log, key, (0, sets_1.setToArray)(featureFlags), attributes, storage
|
|
78
|
+
evaluateFeatures(log, key, (0, sets_1.setToArray)(featureFlags), attributes, storage) :
|
|
79
79
|
{};
|
|
80
80
|
}
|
|
81
81
|
// get features by flag sets
|
|
@@ -89,49 +89,30 @@ function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, met
|
|
|
89
89
|
// evaluate related features
|
|
90
90
|
return (0, thenable_1.thenable)(storedFlagNames) ?
|
|
91
91
|
storedFlagNames.then(function (storedFlagNames) { return evaluate(storedFlagNames); })
|
|
92
|
-
.catch(function () {
|
|
93
|
-
return {};
|
|
94
|
-
}) :
|
|
92
|
+
.catch(function () { return ({}); }) :
|
|
95
93
|
evaluate(storedFlagNames);
|
|
96
94
|
}
|
|
97
95
|
exports.evaluateFeaturesByFlagSets = evaluateFeaturesByFlagSets;
|
|
98
|
-
function getEvaluation(log, key, definition, attributes, storage
|
|
96
|
+
function getEvaluation(log, key, definition, attributes, storage) {
|
|
99
97
|
if (definition) {
|
|
100
98
|
var split = (0, Engine_1.engineParser)(log, definition, storage);
|
|
101
99
|
var evaluation = split.getTreatment(key, attributes, evaluateFeature);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
result.changeNumber = definition.changeNumber;
|
|
106
|
-
result.config = definition.configurations && definition.configurations[result.treatment] || null;
|
|
107
|
-
// @ts-expect-error impressionsDisabled is not exposed in the public typings yet.
|
|
108
|
-
result.impressionsDisabled = (options === null || options === void 0 ? void 0 : options.impressionsDisabled) || definition.impressionsDisabled;
|
|
109
|
-
return result;
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
evaluation.changeNumber = definition.changeNumber;
|
|
114
|
-
evaluation.config = definition.configurations && definition.configurations[evaluation.treatment] || null;
|
|
115
|
-
// @ts-expect-error impressionsDisabled is not exposed in the public typings yet.
|
|
116
|
-
evaluation.impressionsDisabled = (options === null || options === void 0 ? void 0 : options.impressionsDisabled) || definition.impressionsDisabled;
|
|
117
|
-
}
|
|
118
|
-
return evaluation;
|
|
100
|
+
return (0, thenable_1.thenable)(evaluation) ?
|
|
101
|
+
evaluation.then(function (result) { return (0, objectAssign_1.objectAssign)(result, { definition: definition }); }) :
|
|
102
|
+
(0, objectAssign_1.objectAssign)(evaluation, { definition: definition });
|
|
119
103
|
}
|
|
120
104
|
return EVALUATION_DEFINITION_NOT_FOUND;
|
|
121
105
|
}
|
|
122
|
-
function getEvaluations(log, key, definitionNames, definitions, attributes, storage
|
|
106
|
+
function getEvaluations(log, key, definitionNames, definitions, attributes, storage) {
|
|
123
107
|
var result = {};
|
|
124
108
|
var thenables = [];
|
|
125
109
|
definitionNames.forEach(function (definitionName) {
|
|
126
|
-
var evaluation = getEvaluation(log, key, definitions[definitionName], attributes, storage
|
|
127
|
-
|
|
110
|
+
var evaluation = getEvaluation(log, key, definitions[definitionName], attributes, storage);
|
|
111
|
+
(0, thenable_1.thenable)(evaluation) ?
|
|
128
112
|
thenables.push(evaluation.then(function (res) {
|
|
129
113
|
result[definitionName] = res;
|
|
130
|
-
}))
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
114
|
+
})) :
|
|
133
115
|
result[definitionName] = evaluation;
|
|
134
|
-
}
|
|
135
116
|
});
|
|
136
117
|
return thenables.length > 0 ? Promise.all(thenables).then(function () { return result; }) : result;
|
|
137
118
|
}
|
|
@@ -153,8 +134,7 @@ function getDefaultTreatment(definition) {
|
|
|
153
134
|
return {
|
|
154
135
|
treatment: definition.defaultTreatment,
|
|
155
136
|
label: labels_1.NO_CONDITION_MATCH,
|
|
156
|
-
|
|
157
|
-
changeNumber: definition.changeNumber
|
|
137
|
+
definition: definition,
|
|
158
138
|
};
|
|
159
139
|
}
|
|
160
140
|
return EVALUATION_DEFINITION_NOT_FOUND;
|
package/cjs/listeners/browser.js
CHANGED
|
@@ -14,14 +14,14 @@ var EVENT_NAME = 'for visibilitychange and pagehide events.';
|
|
|
14
14
|
*/
|
|
15
15
|
var BrowserSignalListener = /** @class */ (function () {
|
|
16
16
|
function BrowserSignalListener(_a) {
|
|
17
|
-
var syncManager = _a.syncManager, settings = _a.settings, storage = _a.storage, serviceApi = _a.serviceApi
|
|
17
|
+
var syncManager = _a.syncManager, settings = _a.settings, storage = _a.storage, serviceApi = _a.serviceApi;
|
|
18
18
|
this.syncManager = syncManager;
|
|
19
19
|
this.settings = settings;
|
|
20
20
|
this.storage = storage;
|
|
21
21
|
this.serviceApi = serviceApi;
|
|
22
22
|
this.flushData = this.flushData.bind(this);
|
|
23
23
|
this.flushDataIfHidden = this.flushDataIfHidden.bind(this);
|
|
24
|
-
this.fromImpressionsCollector = impressionsSubmitter_1.fromImpressionsCollector.bind(undefined, settings.core.labelsEnabled
|
|
24
|
+
this.fromImpressionsCollector = impressionsSubmitter_1.fromImpressionsCollector.bind(undefined, settings.core.labelsEnabled);
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* start method.
|
package/cjs/sdkClient/client.js
CHANGED
|
@@ -18,10 +18,10 @@ function treatmentsNotReady(featureFlagNames) {
|
|
|
18
18
|
});
|
|
19
19
|
return evaluations;
|
|
20
20
|
}
|
|
21
|
-
function stringify(
|
|
22
|
-
if (
|
|
21
|
+
function stringify(properties) {
|
|
22
|
+
if (properties) {
|
|
23
23
|
try {
|
|
24
|
-
return JSON.stringify(
|
|
24
|
+
return JSON.stringify(properties);
|
|
25
25
|
}
|
|
26
26
|
catch ( /* JSON.stringify should never throw with validated options, but handling just in case */_a) { /* JSON.stringify should never throw with validated options, but handling just in case */ }
|
|
27
27
|
}
|
|
@@ -40,13 +40,13 @@ function clientFactory(params) {
|
|
|
40
40
|
var stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? constants_1.TREATMENT_WITH_CONFIG : constants_1.TREATMENT);
|
|
41
41
|
var wrapUp = function (evaluationResult) {
|
|
42
42
|
var queue = [];
|
|
43
|
-
var treatment = processEvaluation(evaluationResult, featureFlagName, key,
|
|
43
|
+
var treatment = processEvaluation(evaluationResult, featureFlagName, key, withConfig, methodName, queue, options);
|
|
44
44
|
impressionsTracker.track(queue, attributes);
|
|
45
45
|
stopTelemetryTracker(queue[0] && queue[0].imp.label);
|
|
46
46
|
return treatment;
|
|
47
47
|
};
|
|
48
48
|
var evaluation = readinessManager.isReadyFromCache() ?
|
|
49
|
-
(0, evaluator_1.evaluateFeature)(log, key, featureFlagName, attributes, storage
|
|
49
|
+
(0, evaluator_1.evaluateFeature)(log, key, featureFlagName, attributes, storage) :
|
|
50
50
|
isAsync ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
|
|
51
51
|
Promise.resolve(treatmentNotReady) :
|
|
52
52
|
treatmentNotReady;
|
|
@@ -62,16 +62,15 @@ function clientFactory(params) {
|
|
|
62
62
|
var wrapUp = function (evaluationResults) {
|
|
63
63
|
var queue = [];
|
|
64
64
|
var treatments = {};
|
|
65
|
-
var properties = stringify(options);
|
|
66
65
|
Object.keys(evaluationResults).forEach(function (featureFlagName) {
|
|
67
|
-
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key,
|
|
66
|
+
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, withConfig, methodName, queue, options);
|
|
68
67
|
});
|
|
69
68
|
impressionsTracker.track(queue, attributes);
|
|
70
69
|
stopTelemetryTracker(queue[0] && queue[0].imp.label);
|
|
71
70
|
return treatments;
|
|
72
71
|
};
|
|
73
72
|
var evaluations = readinessManager.isReadyFromCache() ?
|
|
74
|
-
(0, evaluator_1.evaluateFeatures)(log, key, featureFlagNames, attributes, storage
|
|
73
|
+
(0, evaluator_1.evaluateFeatures)(log, key, featureFlagNames, attributes, storage) :
|
|
75
74
|
isAsync ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
|
|
76
75
|
Promise.resolve(treatmentsNotReady(featureFlagNames)) :
|
|
77
76
|
treatmentsNotReady(featureFlagNames);
|
|
@@ -88,16 +87,15 @@ function clientFactory(params) {
|
|
|
88
87
|
var wrapUp = function (evaluationResults) {
|
|
89
88
|
var queue = [];
|
|
90
89
|
var treatments = {};
|
|
91
|
-
var properties = stringify(options);
|
|
92
90
|
Object.keys(evaluationResults).forEach(function (featureFlagName) {
|
|
93
|
-
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key,
|
|
91
|
+
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, withConfig, methodName, queue, options);
|
|
94
92
|
});
|
|
95
93
|
impressionsTracker.track(queue, attributes);
|
|
96
94
|
stopTelemetryTracker(queue[0] && queue[0].imp.label);
|
|
97
95
|
return treatments;
|
|
98
96
|
};
|
|
99
97
|
var evaluations = readinessManager.isReadyFromCache() ?
|
|
100
|
-
(0, evaluator_1.evaluateFeaturesByFlagSets)(log, key, flagSetNames, attributes, storage, methodName
|
|
98
|
+
(0, evaluator_1.evaluateFeaturesByFlagSets)(log, key, flagSetNames, attributes, storage, methodName) :
|
|
101
99
|
isAsync ?
|
|
102
100
|
Promise.resolve({}) :
|
|
103
101
|
{};
|
|
@@ -113,11 +111,14 @@ function clientFactory(params) {
|
|
|
113
111
|
return getTreatmentsByFlagSets(key, [flagSetName], attributes, options, true, constants_1.TREATMENTS_WITH_CONFIG_BY_FLAGSET, constants_1.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET);
|
|
114
112
|
}
|
|
115
113
|
// Internal function
|
|
116
|
-
function processEvaluation(evaluation, featureFlagName, key,
|
|
114
|
+
function processEvaluation(evaluation, featureFlagName, key, withConfig, invokingMethodName, queue, options) {
|
|
115
|
+
var _a;
|
|
116
|
+
if (options === void 0) { options = {}; }
|
|
117
117
|
var matchingKey = (0, key_1.getMatching)(key);
|
|
118
118
|
var bucketingKey = (0, key_1.getBucketing)(key);
|
|
119
|
-
var
|
|
120
|
-
var treatment = evaluation.treatment, label = evaluation.label
|
|
119
|
+
var definition = evaluation.definition;
|
|
120
|
+
var treatment = evaluation.treatment, label = evaluation.label;
|
|
121
|
+
var config = ((_a = definition === null || definition === void 0 ? void 0 : definition.configurations) === null || _a === void 0 ? void 0 : _a[treatment]) || null;
|
|
121
122
|
if (treatment === constants_1.CONTROL) {
|
|
122
123
|
var fallbackTreatment = fallbackCalculator(featureFlagName, label);
|
|
123
124
|
treatment = fallbackTreatment.treatment;
|
|
@@ -134,10 +135,10 @@ function clientFactory(params) {
|
|
|
134
135
|
time: Date.now(),
|
|
135
136
|
bucketingKey: bucketingKey,
|
|
136
137
|
label: label,
|
|
137
|
-
changeNumber: changeNumber,
|
|
138
|
-
properties: properties
|
|
138
|
+
changeNumber: definition.changeNumber,
|
|
139
|
+
properties: stringify(options.properties)
|
|
139
140
|
},
|
|
140
|
-
disabled: impressionsDisabled
|
|
141
|
+
disabled: options.impressionsDisabled || definition.impressionsDisabled
|
|
141
142
|
});
|
|
142
143
|
}
|
|
143
144
|
if (withConfig) {
|
|
@@ -16,7 +16,7 @@ function isExpired(credential) {
|
|
|
16
16
|
function authProviderFactory(settings, splitHttpClient, telemetryTracker) {
|
|
17
17
|
var urls = settings.urls, log = settings.log;
|
|
18
18
|
function fetchAuth() {
|
|
19
|
-
var url = "".concat(urls.auth, "/api/v3/auth?capabilities=config");
|
|
19
|
+
var url = "".concat(urls.auth, "/api/v3/auth?capabilities=config,aiconfig");
|
|
20
20
|
return splitHttpClient(url, undefined, telemetryTracker.trackHttp(constants_2.TOKEN), false, true);
|
|
21
21
|
}
|
|
22
22
|
var authenticate = (0, AuthClient_1.authenticateFactory)(fetchAuth);
|
package/cjs/storages/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ var constants_1 = require("../../logger/constants");
|
|
|
7
7
|
/**
|
|
8
8
|
* Converts `impressions` data from cache into request payload.
|
|
9
9
|
*/
|
|
10
|
-
function fromImpressionsCollector(sendLabels,
|
|
10
|
+
function fromImpressionsCollector(sendLabels, data) {
|
|
11
11
|
var groupedByFeature = (0, lang_1.groupBy)(data, 'feature');
|
|
12
12
|
var dto = [];
|
|
13
13
|
(0, lang_1.forOwn)(groupedByFeature, function (value, name) {
|
|
@@ -23,7 +23,8 @@ function fromImpressionsCollector(sendLabels, entityType, data) {
|
|
|
23
23
|
b: entry.bucketingKey,
|
|
24
24
|
pt: entry.pt,
|
|
25
25
|
properties: entry.properties,
|
|
26
|
-
|
|
26
|
+
// @ts-expect-error - entityType is not yet public. @TODO: add to SplitIO.ImpressionDTO type
|
|
27
|
+
et: entry.entityType, // Definition type
|
|
27
28
|
};
|
|
28
29
|
})
|
|
29
30
|
});
|
|
@@ -35,9 +36,9 @@ exports.fromImpressionsCollector = fromImpressionsCollector;
|
|
|
35
36
|
* Submitter that periodically posts impressions data
|
|
36
37
|
*/
|
|
37
38
|
function impressionsSubmitterFactory(params) {
|
|
38
|
-
var _a = params.settings, log = _a.log, impressionsRefreshRate = _a.scheduler.impressionsRefreshRate, labelsEnabled = _a.core.labelsEnabled, postTestImpressionsBulk = params.serviceApi.postTestImpressionsBulk, impressions = params.storage.impressions
|
|
39
|
+
var _a = params.settings, log = _a.log, impressionsRefreshRate = _a.scheduler.impressionsRefreshRate, labelsEnabled = _a.core.labelsEnabled, postTestImpressionsBulk = params.serviceApi.postTestImpressionsBulk, impressions = params.storage.impressions;
|
|
39
40
|
// retry impressions only once.
|
|
40
|
-
var syncTask = (0, submitter_1.submitterFactory)(log, postTestImpressionsBulk, impressions, impressionsRefreshRate, fromImpressionsCollector.bind(undefined, labelsEnabled
|
|
41
|
+
var syncTask = (0, submitter_1.submitterFactory)(log, postTestImpressionsBulk, impressions, impressionsRefreshRate, fromImpressionsCollector.bind(undefined, labelsEnabled), 1);
|
|
41
42
|
// register impressions submitter to be executed when impressions cache is full
|
|
42
43
|
impressions.setOnFullQueueCb(function () {
|
|
43
44
|
if (syncTask.isRunning()) {
|
|
@@ -20,7 +20,7 @@ export function conditionContext(log, matcherEvaluator, treatments, label, condi
|
|
|
20
20
|
// Whitelisting has more priority than traffic allocation, so we don't apply this filtering to those conditions.
|
|
21
21
|
if (conditionType === 'ROLLOUT' && !shouldApplyRollout(trafficAllocation, key.bucketingKey, trafficAllocationSeed)) {
|
|
22
22
|
return {
|
|
23
|
-
treatment
|
|
23
|
+
// treatment value is assigned later, at Engine's evaluationResult
|
|
24
24
|
label: NOT_IN_SPLIT
|
|
25
25
|
};
|
|
26
26
|
}
|
package/esm/evaluator/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { EXCEPTION, NO_CONDITION_MATCH, DEFINITION_NOT_FOUND } from '../utils/la
|
|
|
4
4
|
import { CONTROL } from '../utils/constants';
|
|
5
5
|
import { returnSetsUnion, setToArray } from '../utils/lang/sets';
|
|
6
6
|
import { WARN_FLAGSET_WITHOUT_FLAGS } from '../logger/constants';
|
|
7
|
+
import { objectAssign } from '../utils/lang/objectAssign';
|
|
7
8
|
var EVALUATION_EXCEPTION = {
|
|
8
9
|
treatment: CONTROL,
|
|
9
10
|
label: EXCEPTION,
|
|
@@ -21,7 +22,7 @@ function treatmentsException(definitionNames) {
|
|
|
21
22
|
});
|
|
22
23
|
return evaluations;
|
|
23
24
|
}
|
|
24
|
-
export function evaluateFeature(log, key, definitionName, attributes, storage
|
|
25
|
+
export function evaluateFeature(log, key, definitionName, attributes, storage) {
|
|
25
26
|
var definition;
|
|
26
27
|
try {
|
|
27
28
|
definition = storage.definitions.get(definitionName);
|
|
@@ -30,15 +31,15 @@ export function evaluateFeature(log, key, definitionName, attributes, storage, o
|
|
|
30
31
|
// Exception on sync storage. Not possible ATM with InMemory and InLocal storages.
|
|
31
32
|
return EVALUATION_EXCEPTION;
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
return thenable(definition) ?
|
|
35
|
+
definition.then(function (definition) { return getEvaluation(log, key, definition, attributes, storage); })
|
|
36
|
+
.catch(
|
|
35
37
|
// Exception on async storage. For example, when the storage is redis or
|
|
36
38
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
37
|
-
function () { return EVALUATION_EXCEPTION; })
|
|
38
|
-
|
|
39
|
-
return getEvaluation(log, key, definition, attributes, storage, options);
|
|
39
|
+
function () { return EVALUATION_EXCEPTION; }) :
|
|
40
|
+
getEvaluation(log, key, definition, attributes, storage);
|
|
40
41
|
}
|
|
41
|
-
export function evaluateFeatures(log, key, definitionNames, attributes, storage
|
|
42
|
+
export function evaluateFeatures(log, key, definitionNames, attributes, storage) {
|
|
42
43
|
var definitions;
|
|
43
44
|
try {
|
|
44
45
|
definitions = storage.definitions.getMany(definitionNames);
|
|
@@ -48,15 +49,14 @@ export function evaluateFeatures(log, key, definitionNames, attributes, storage,
|
|
|
48
49
|
return treatmentsException(definitionNames);
|
|
49
50
|
}
|
|
50
51
|
return thenable(definitions) ?
|
|
51
|
-
definitions.then(function (definitions) { return getEvaluations(log, key, definitionNames, definitions, attributes, storage
|
|
52
|
-
.catch(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
getEvaluations(log, key, definitionNames, definitions, attributes, storage, options);
|
|
52
|
+
definitions.then(function (definitions) { return getEvaluations(log, key, definitionNames, definitions, attributes, storage); })
|
|
53
|
+
.catch(
|
|
54
|
+
// Exception on async storage. For example, when the storage is redis or
|
|
55
|
+
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
56
|
+
function () { return treatmentsException(definitionNames); }) :
|
|
57
|
+
getEvaluations(log, key, definitionNames, definitions, attributes, storage);
|
|
58
58
|
}
|
|
59
|
-
export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, method
|
|
59
|
+
export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, method) {
|
|
60
60
|
var storedFlagNames;
|
|
61
61
|
function evaluate(featureFlagsByFlagSets) {
|
|
62
62
|
var featureFlags = new Set();
|
|
@@ -70,7 +70,7 @@ export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, stora
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
return featureFlags.size ?
|
|
73
|
-
evaluateFeatures(log, key, setToArray(featureFlags), attributes, storage
|
|
73
|
+
evaluateFeatures(log, key, setToArray(featureFlags), attributes, storage) :
|
|
74
74
|
{};
|
|
75
75
|
}
|
|
76
76
|
// get features by flag sets
|
|
@@ -84,48 +84,29 @@ export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, stora
|
|
|
84
84
|
// evaluate related features
|
|
85
85
|
return thenable(storedFlagNames) ?
|
|
86
86
|
storedFlagNames.then(function (storedFlagNames) { return evaluate(storedFlagNames); })
|
|
87
|
-
.catch(function () {
|
|
88
|
-
return {};
|
|
89
|
-
}) :
|
|
87
|
+
.catch(function () { return ({}); }) :
|
|
90
88
|
evaluate(storedFlagNames);
|
|
91
89
|
}
|
|
92
|
-
function getEvaluation(log, key, definition, attributes, storage
|
|
90
|
+
function getEvaluation(log, key, definition, attributes, storage) {
|
|
93
91
|
if (definition) {
|
|
94
92
|
var split = engineParser(log, definition, storage);
|
|
95
93
|
var evaluation = split.getTreatment(key, attributes, evaluateFeature);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
result.changeNumber = definition.changeNumber;
|
|
100
|
-
result.config = definition.configurations && definition.configurations[result.treatment] || null;
|
|
101
|
-
// @ts-expect-error impressionsDisabled is not exposed in the public typings yet.
|
|
102
|
-
result.impressionsDisabled = (options === null || options === void 0 ? void 0 : options.impressionsDisabled) || definition.impressionsDisabled;
|
|
103
|
-
return result;
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
evaluation.changeNumber = definition.changeNumber;
|
|
108
|
-
evaluation.config = definition.configurations && definition.configurations[evaluation.treatment] || null;
|
|
109
|
-
// @ts-expect-error impressionsDisabled is not exposed in the public typings yet.
|
|
110
|
-
evaluation.impressionsDisabled = (options === null || options === void 0 ? void 0 : options.impressionsDisabled) || definition.impressionsDisabled;
|
|
111
|
-
}
|
|
112
|
-
return evaluation;
|
|
94
|
+
return thenable(evaluation) ?
|
|
95
|
+
evaluation.then(function (result) { return objectAssign(result, { definition: definition }); }) :
|
|
96
|
+
objectAssign(evaluation, { definition: definition });
|
|
113
97
|
}
|
|
114
98
|
return EVALUATION_DEFINITION_NOT_FOUND;
|
|
115
99
|
}
|
|
116
|
-
function getEvaluations(log, key, definitionNames, definitions, attributes, storage
|
|
100
|
+
function getEvaluations(log, key, definitionNames, definitions, attributes, storage) {
|
|
117
101
|
var result = {};
|
|
118
102
|
var thenables = [];
|
|
119
103
|
definitionNames.forEach(function (definitionName) {
|
|
120
|
-
var evaluation = getEvaluation(log, key, definitions[definitionName], attributes, storage
|
|
121
|
-
|
|
104
|
+
var evaluation = getEvaluation(log, key, definitions[definitionName], attributes, storage);
|
|
105
|
+
thenable(evaluation) ?
|
|
122
106
|
thenables.push(evaluation.then(function (res) {
|
|
123
107
|
result[definitionName] = res;
|
|
124
|
-
}))
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
108
|
+
})) :
|
|
127
109
|
result[definitionName] = evaluation;
|
|
128
|
-
}
|
|
129
110
|
});
|
|
130
111
|
return thenables.length > 0 ? Promise.all(thenables).then(function () { return result; }) : result;
|
|
131
112
|
}
|
|
@@ -146,8 +127,7 @@ function getDefaultTreatment(definition) {
|
|
|
146
127
|
return {
|
|
147
128
|
treatment: definition.defaultTreatment,
|
|
148
129
|
label: NO_CONDITION_MATCH,
|
|
149
|
-
|
|
150
|
-
changeNumber: definition.changeNumber
|
|
130
|
+
definition: definition,
|
|
151
131
|
};
|
|
152
132
|
}
|
|
153
133
|
return EVALUATION_DEFINITION_NOT_FOUND;
|
package/esm/listeners/browser.js
CHANGED
|
@@ -11,14 +11,14 @@ var EVENT_NAME = 'for visibilitychange and pagehide events.';
|
|
|
11
11
|
*/
|
|
12
12
|
var BrowserSignalListener = /** @class */ (function () {
|
|
13
13
|
function BrowserSignalListener(_a) {
|
|
14
|
-
var syncManager = _a.syncManager, settings = _a.settings, storage = _a.storage, serviceApi = _a.serviceApi
|
|
14
|
+
var syncManager = _a.syncManager, settings = _a.settings, storage = _a.storage, serviceApi = _a.serviceApi;
|
|
15
15
|
this.syncManager = syncManager;
|
|
16
16
|
this.settings = settings;
|
|
17
17
|
this.storage = storage;
|
|
18
18
|
this.serviceApi = serviceApi;
|
|
19
19
|
this.flushData = this.flushData.bind(this);
|
|
20
20
|
this.flushDataIfHidden = this.flushDataIfHidden.bind(this);
|
|
21
|
-
this.fromImpressionsCollector = fromImpressionsCollector.bind(undefined, settings.core.labelsEnabled
|
|
21
|
+
this.fromImpressionsCollector = fromImpressionsCollector.bind(undefined, settings.core.labelsEnabled);
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* start method.
|
package/esm/sdkClient/client.js
CHANGED
|
@@ -15,10 +15,10 @@ function treatmentsNotReady(featureFlagNames) {
|
|
|
15
15
|
});
|
|
16
16
|
return evaluations;
|
|
17
17
|
}
|
|
18
|
-
export function stringify(
|
|
19
|
-
if (
|
|
18
|
+
export function stringify(properties) {
|
|
19
|
+
if (properties) {
|
|
20
20
|
try {
|
|
21
|
-
return JSON.stringify(
|
|
21
|
+
return JSON.stringify(properties);
|
|
22
22
|
}
|
|
23
23
|
catch ( /* JSON.stringify should never throw with validated options, but handling just in case */_a) { /* JSON.stringify should never throw with validated options, but handling just in case */ }
|
|
24
24
|
}
|
|
@@ -36,13 +36,13 @@ export function clientFactory(params) {
|
|
|
36
36
|
var stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? TREATMENT_WITH_CONFIG : TREATMENT);
|
|
37
37
|
var wrapUp = function (evaluationResult) {
|
|
38
38
|
var queue = [];
|
|
39
|
-
var treatment = processEvaluation(evaluationResult, featureFlagName, key,
|
|
39
|
+
var treatment = processEvaluation(evaluationResult, featureFlagName, key, withConfig, methodName, queue, options);
|
|
40
40
|
impressionsTracker.track(queue, attributes);
|
|
41
41
|
stopTelemetryTracker(queue[0] && queue[0].imp.label);
|
|
42
42
|
return treatment;
|
|
43
43
|
};
|
|
44
44
|
var evaluation = readinessManager.isReadyFromCache() ?
|
|
45
|
-
evaluateFeature(log, key, featureFlagName, attributes, storage
|
|
45
|
+
evaluateFeature(log, key, featureFlagName, attributes, storage) :
|
|
46
46
|
isAsync ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
|
|
47
47
|
Promise.resolve(treatmentNotReady) :
|
|
48
48
|
treatmentNotReady;
|
|
@@ -58,16 +58,15 @@ export function clientFactory(params) {
|
|
|
58
58
|
var wrapUp = function (evaluationResults) {
|
|
59
59
|
var queue = [];
|
|
60
60
|
var treatments = {};
|
|
61
|
-
var properties = stringify(options);
|
|
62
61
|
Object.keys(evaluationResults).forEach(function (featureFlagName) {
|
|
63
|
-
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key,
|
|
62
|
+
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, withConfig, methodName, queue, options);
|
|
64
63
|
});
|
|
65
64
|
impressionsTracker.track(queue, attributes);
|
|
66
65
|
stopTelemetryTracker(queue[0] && queue[0].imp.label);
|
|
67
66
|
return treatments;
|
|
68
67
|
};
|
|
69
68
|
var evaluations = readinessManager.isReadyFromCache() ?
|
|
70
|
-
evaluateFeatures(log, key, featureFlagNames, attributes, storage
|
|
69
|
+
evaluateFeatures(log, key, featureFlagNames, attributes, storage) :
|
|
71
70
|
isAsync ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
|
|
72
71
|
Promise.resolve(treatmentsNotReady(featureFlagNames)) :
|
|
73
72
|
treatmentsNotReady(featureFlagNames);
|
|
@@ -84,16 +83,15 @@ export function clientFactory(params) {
|
|
|
84
83
|
var wrapUp = function (evaluationResults) {
|
|
85
84
|
var queue = [];
|
|
86
85
|
var treatments = {};
|
|
87
|
-
var properties = stringify(options);
|
|
88
86
|
Object.keys(evaluationResults).forEach(function (featureFlagName) {
|
|
89
|
-
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key,
|
|
87
|
+
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, withConfig, methodName, queue, options);
|
|
90
88
|
});
|
|
91
89
|
impressionsTracker.track(queue, attributes);
|
|
92
90
|
stopTelemetryTracker(queue[0] && queue[0].imp.label);
|
|
93
91
|
return treatments;
|
|
94
92
|
};
|
|
95
93
|
var evaluations = readinessManager.isReadyFromCache() ?
|
|
96
|
-
evaluateFeaturesByFlagSets(log, key, flagSetNames, attributes, storage, methodName
|
|
94
|
+
evaluateFeaturesByFlagSets(log, key, flagSetNames, attributes, storage, methodName) :
|
|
97
95
|
isAsync ?
|
|
98
96
|
Promise.resolve({}) :
|
|
99
97
|
{};
|
|
@@ -109,11 +107,14 @@ export function clientFactory(params) {
|
|
|
109
107
|
return getTreatmentsByFlagSets(key, [flagSetName], attributes, options, true, TREATMENTS_WITH_CONFIG_BY_FLAGSET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET);
|
|
110
108
|
}
|
|
111
109
|
// Internal function
|
|
112
|
-
function processEvaluation(evaluation, featureFlagName, key,
|
|
110
|
+
function processEvaluation(evaluation, featureFlagName, key, withConfig, invokingMethodName, queue, options) {
|
|
111
|
+
var _a;
|
|
112
|
+
if (options === void 0) { options = {}; }
|
|
113
113
|
var matchingKey = getMatching(key);
|
|
114
114
|
var bucketingKey = getBucketing(key);
|
|
115
|
-
var
|
|
116
|
-
var treatment = evaluation.treatment, label = evaluation.label
|
|
115
|
+
var definition = evaluation.definition;
|
|
116
|
+
var treatment = evaluation.treatment, label = evaluation.label;
|
|
117
|
+
var config = ((_a = definition === null || definition === void 0 ? void 0 : definition.configurations) === null || _a === void 0 ? void 0 : _a[treatment]) || null;
|
|
117
118
|
if (treatment === CONTROL) {
|
|
118
119
|
var fallbackTreatment = fallbackCalculator(featureFlagName, label);
|
|
119
120
|
treatment = fallbackTreatment.treatment;
|
|
@@ -130,10 +131,10 @@ export function clientFactory(params) {
|
|
|
130
131
|
time: Date.now(),
|
|
131
132
|
bucketingKey: bucketingKey,
|
|
132
133
|
label: label,
|
|
133
|
-
changeNumber: changeNumber,
|
|
134
|
-
properties: properties
|
|
134
|
+
changeNumber: definition.changeNumber,
|
|
135
|
+
properties: stringify(options.properties)
|
|
135
136
|
},
|
|
136
|
-
disabled: impressionsDisabled
|
|
137
|
+
disabled: options.impressionsDisabled || definition.impressionsDisabled
|
|
137
138
|
});
|
|
138
139
|
}
|
|
139
140
|
if (withConfig) {
|
|
@@ -13,7 +13,7 @@ function isExpired(credential) {
|
|
|
13
13
|
export function authProviderFactory(settings, splitHttpClient, telemetryTracker) {
|
|
14
14
|
var urls = settings.urls, log = settings.log;
|
|
15
15
|
function fetchAuth() {
|
|
16
|
-
var url = "".concat(urls.auth, "/api/v3/auth?capabilities=config");
|
|
16
|
+
var url = "".concat(urls.auth, "/api/v3/auth?capabilities=config,aiconfig");
|
|
17
17
|
return splitHttpClient(url, undefined, telemetryTracker.trackHttp(TOKEN), false, true);
|
|
18
18
|
}
|
|
19
19
|
var authenticate = authenticateFactory(fetchAuth);
|
package/esm/storages/utils.js
CHANGED