@splitsoftware/splitio-commons 2.8.1-rc.1 → 2.9.1-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.txt +3 -2
- package/cjs/evaluator/index.js +13 -13
- package/cjs/sdkClient/client.js +3 -3
- package/cjs/storages/AbstractMySegmentsCacheSync.js +31 -23
- package/cjs/storages/AbstractSplitsCacheSync.js +3 -2
- package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +10 -28
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +22 -33
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +19 -29
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +3 -2
- package/cjs/storages/inRedis/SegmentsCacheInRedis.js +1 -1
- package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +1 -1
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +16 -5
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +3 -3
- package/cjs/utils/inputValidation/eventProperties.js +1 -6
- package/esm/evaluator/index.js +13 -13
- package/esm/sdkClient/client.js +3 -3
- package/esm/storages/AbstractMySegmentsCacheSync.js +31 -23
- package/esm/storages/AbstractSplitsCacheSync.js +3 -2
- package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +11 -29
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +22 -33
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +19 -29
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +3 -2
- package/esm/storages/inRedis/SegmentsCacheInRedis.js +1 -1
- package/esm/sync/polling/syncTasks/segmentsSyncTask.js +1 -1
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +16 -5
- package/esm/sync/polling/updaters/splitChangesUpdater.js +3 -3
- package/esm/utils/inputValidation/eventProperties.js +1 -6
- package/package.json +1 -1
- package/src/evaluator/index.ts +6 -14
- package/src/presets/serverSide.js +23 -0
- package/src/sdkClient/client.ts +3 -3
- package/src/storages/AbstractMySegmentsCacheSync.ts +26 -20
- package/src/storages/AbstractSplitsCacheSync.ts +3 -2
- package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +9 -24
- package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +18 -27
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +22 -29
- package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +3 -2
- package/src/storages/inRedis/SegmentsCacheInRedis.ts +1 -1
- package/src/sync/polling/syncTasks/segmentsSyncTask.ts +2 -0
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +3 -3
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +17 -4
- package/src/sync/polling/updaters/splitChangesUpdater.ts +6 -7
- package/src/utils/inputValidation/eventProperties.ts +1 -6
- package/types/splitio.d.ts +0 -10
package/esm/evaluator/index.js
CHANGED
|
@@ -16,7 +16,7 @@ function treatmentsException(splitNames) {
|
|
|
16
16
|
});
|
|
17
17
|
return evaluations;
|
|
18
18
|
}
|
|
19
|
-
export function evaluateFeature(log, key, splitName, attributes, storage
|
|
19
|
+
export function evaluateFeature(log, key, splitName, attributes, storage) {
|
|
20
20
|
var parsedSplit;
|
|
21
21
|
try {
|
|
22
22
|
parsedSplit = storage.splits.getSplit(splitName);
|
|
@@ -26,14 +26,14 @@ export function evaluateFeature(log, key, splitName, attributes, storage, option
|
|
|
26
26
|
return treatmentException;
|
|
27
27
|
}
|
|
28
28
|
if (thenable(parsedSplit)) {
|
|
29
|
-
return parsedSplit.then(function (split) { return getEvaluation(log, key, split, attributes, storage
|
|
29
|
+
return parsedSplit.then(function (split) { return getEvaluation(log, key, split, attributes, storage); }).catch(
|
|
30
30
|
// Exception on async `getSplit` storage. For example, when the storage is redis or
|
|
31
31
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
32
32
|
function () { return treatmentException; });
|
|
33
33
|
}
|
|
34
|
-
return getEvaluation(log, key, parsedSplit, attributes, storage
|
|
34
|
+
return getEvaluation(log, key, parsedSplit, attributes, storage);
|
|
35
35
|
}
|
|
36
|
-
export function evaluateFeatures(log, key, splitNames, attributes, storage
|
|
36
|
+
export function evaluateFeatures(log, key, splitNames, attributes, storage) {
|
|
37
37
|
var parsedSplits;
|
|
38
38
|
try {
|
|
39
39
|
parsedSplits = storage.splits.getSplits(splitNames);
|
|
@@ -43,15 +43,15 @@ export function evaluateFeatures(log, key, splitNames, attributes, storage, opti
|
|
|
43
43
|
return treatmentsException(splitNames);
|
|
44
44
|
}
|
|
45
45
|
return thenable(parsedSplits) ?
|
|
46
|
-
parsedSplits.then(function (splits) { return getEvaluations(log, key, splitNames, splits, attributes, storage
|
|
46
|
+
parsedSplits.then(function (splits) { return getEvaluations(log, key, splitNames, splits, attributes, storage); })
|
|
47
47
|
.catch(function () {
|
|
48
48
|
// Exception on async `getSplits` storage. For example, when the storage is redis or
|
|
49
49
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
50
50
|
return treatmentsException(splitNames);
|
|
51
51
|
}) :
|
|
52
|
-
getEvaluations(log, key, splitNames, parsedSplits, attributes, storage
|
|
52
|
+
getEvaluations(log, key, splitNames, parsedSplits, attributes, storage);
|
|
53
53
|
}
|
|
54
|
-
export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, method
|
|
54
|
+
export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, method) {
|
|
55
55
|
var storedFlagNames;
|
|
56
56
|
function evaluate(featureFlagsByFlagSets) {
|
|
57
57
|
var featureFlags = new Set();
|
|
@@ -65,7 +65,7 @@ export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, stora
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
return featureFlags.size ?
|
|
68
|
-
evaluateFeatures(log, key, setToArray(featureFlags), attributes, storage
|
|
68
|
+
evaluateFeatures(log, key, setToArray(featureFlags), attributes, storage) :
|
|
69
69
|
{};
|
|
70
70
|
}
|
|
71
71
|
// get features by flag sets
|
|
@@ -84,7 +84,7 @@ export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, stora
|
|
|
84
84
|
}) :
|
|
85
85
|
evaluate(storedFlagNames);
|
|
86
86
|
}
|
|
87
|
-
function getEvaluation(log, key, splitJSON, attributes, storage
|
|
87
|
+
function getEvaluation(log, key, splitJSON, attributes, storage) {
|
|
88
88
|
var evaluation = {
|
|
89
89
|
treatment: CONTROL,
|
|
90
90
|
label: SPLIT_NOT_FOUND,
|
|
@@ -98,23 +98,23 @@ function getEvaluation(log, key, splitJSON, attributes, storage, options) {
|
|
|
98
98
|
return evaluation.then(function (result) {
|
|
99
99
|
result.changeNumber = splitJSON.changeNumber;
|
|
100
100
|
result.config = splitJSON.configurations && splitJSON.configurations[result.treatment] || null;
|
|
101
|
-
result.impressionsDisabled =
|
|
101
|
+
result.impressionsDisabled = splitJSON.impressionsDisabled;
|
|
102
102
|
return result;
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
else {
|
|
106
106
|
evaluation.changeNumber = splitJSON.changeNumber;
|
|
107
107
|
evaluation.config = splitJSON.configurations && splitJSON.configurations[evaluation.treatment] || null;
|
|
108
|
-
evaluation.impressionsDisabled =
|
|
108
|
+
evaluation.impressionsDisabled = splitJSON.impressionsDisabled;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
return evaluation;
|
|
112
112
|
}
|
|
113
|
-
function getEvaluations(log, key, splitNames, splits, attributes, storage
|
|
113
|
+
function getEvaluations(log, key, splitNames, splits, attributes, storage) {
|
|
114
114
|
var result = {};
|
|
115
115
|
var thenables = [];
|
|
116
116
|
splitNames.forEach(function (splitName) {
|
|
117
|
-
var evaluation = getEvaluation(log, key, splits[splitName], attributes, storage
|
|
117
|
+
var evaluation = getEvaluation(log, key, splits[splitName], attributes, storage);
|
|
118
118
|
if (thenable(evaluation)) {
|
|
119
119
|
thenables.push(evaluation.then(function (res) {
|
|
120
120
|
result[splitName] = res;
|
package/esm/sdkClient/client.js
CHANGED
|
@@ -42,7 +42,7 @@ export function clientFactory(params) {
|
|
|
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;
|
|
@@ -67,7 +67,7 @@ export function clientFactory(params) {
|
|
|
67
67
|
return treatments;
|
|
68
68
|
};
|
|
69
69
|
var evaluations = readinessManager.isReadyFromCache() ?
|
|
70
|
-
evaluateFeatures(log, key, featureFlagNames, attributes, storage
|
|
70
|
+
evaluateFeatures(log, key, featureFlagNames, attributes, storage) :
|
|
71
71
|
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
72
|
Promise.resolve(treatmentsNotReady(featureFlagNames)) :
|
|
73
73
|
treatmentsNotReady(featureFlagNames);
|
|
@@ -93,7 +93,7 @@ export function clientFactory(params) {
|
|
|
93
93
|
return treatments;
|
|
94
94
|
};
|
|
95
95
|
var evaluations = readinessManager.isReadyFromCache() ?
|
|
96
|
-
evaluateFeaturesByFlagSets(log, key, flagSetNames, attributes, storage, methodName
|
|
96
|
+
evaluateFeaturesByFlagSets(log, key, flagSetNames, attributes, storage, methodName) :
|
|
97
97
|
isAsync ?
|
|
98
98
|
Promise.resolve({}) :
|
|
99
99
|
{};
|
|
@@ -20,37 +20,45 @@ var AbstractMySegmentsCacheSync = /** @class */ (function () {
|
|
|
20
20
|
*/
|
|
21
21
|
AbstractMySegmentsCacheSync.prototype.resetSegments = function (segmentsData) {
|
|
22
22
|
var _this = this;
|
|
23
|
-
|
|
23
|
+
var isDiff = false;
|
|
24
24
|
var _a = segmentsData, added = _a.added, removed = _a.removed;
|
|
25
25
|
if (added && removed) {
|
|
26
|
-
var isDiff_1 = false;
|
|
27
26
|
added.forEach(function (segment) {
|
|
28
|
-
|
|
27
|
+
isDiff = _this.addSegment(segment) || isDiff;
|
|
29
28
|
});
|
|
30
29
|
removed.forEach(function (segment) {
|
|
31
|
-
|
|
30
|
+
isDiff = _this.removeSegment(segment) || isDiff;
|
|
32
31
|
});
|
|
33
|
-
return isDiff_1;
|
|
34
|
-
}
|
|
35
|
-
var names = (segmentsData.k || []).map(function (s) { return s.n; }).sort();
|
|
36
|
-
var storedSegmentKeys = this.getRegisteredSegments().sort();
|
|
37
|
-
// Extreme fast => everything is empty
|
|
38
|
-
if (!names.length && !storedSegmentKeys.length)
|
|
39
|
-
return false;
|
|
40
|
-
var index = 0;
|
|
41
|
-
while (index < names.length && index < storedSegmentKeys.length && names[index] === storedSegmentKeys[index])
|
|
42
|
-
index++;
|
|
43
|
-
// Quick path => no changes
|
|
44
|
-
if (index === names.length && index === storedSegmentKeys.length)
|
|
45
|
-
return false;
|
|
46
|
-
// Slowest path => add and/or remove segments
|
|
47
|
-
for (var removeIndex = index; removeIndex < storedSegmentKeys.length; removeIndex++) {
|
|
48
|
-
this.removeSegment(storedSegmentKeys[removeIndex]);
|
|
49
32
|
}
|
|
50
|
-
|
|
51
|
-
|
|
33
|
+
else {
|
|
34
|
+
var names = (segmentsData.k || []).map(function (s) { return s.n; }).sort();
|
|
35
|
+
var storedSegmentKeys = this.getRegisteredSegments().sort();
|
|
36
|
+
// Extreme fast => everything is empty
|
|
37
|
+
if (!names.length && !storedSegmentKeys.length) {
|
|
38
|
+
isDiff = false;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
var index = 0;
|
|
42
|
+
while (index < names.length && index < storedSegmentKeys.length && names[index] === storedSegmentKeys[index])
|
|
43
|
+
index++;
|
|
44
|
+
// Quick path => no changes
|
|
45
|
+
if (index === names.length && index === storedSegmentKeys.length) {
|
|
46
|
+
isDiff = false;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
// Slowest path => add and/or remove segments
|
|
50
|
+
for (var removeIndex = index; removeIndex < storedSegmentKeys.length; removeIndex++) {
|
|
51
|
+
this.removeSegment(storedSegmentKeys[removeIndex]);
|
|
52
|
+
}
|
|
53
|
+
for (var addIndex = index; addIndex < names.length; addIndex++) {
|
|
54
|
+
this.addSegment(names[addIndex]);
|
|
55
|
+
}
|
|
56
|
+
isDiff = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
52
59
|
}
|
|
53
|
-
|
|
60
|
+
this.setChangeNumber(segmentsData.cn);
|
|
61
|
+
return isDiff;
|
|
54
62
|
};
|
|
55
63
|
return AbstractMySegmentsCacheSync;
|
|
56
64
|
}());
|
|
@@ -9,9 +9,10 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
|
|
|
9
9
|
}
|
|
10
10
|
AbstractSplitsCacheSync.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
11
11
|
var _this = this;
|
|
12
|
-
this.setChangeNumber(changeNumber);
|
|
13
12
|
var updated = toAdd.map(function (addedFF) { return _this.addSplit(addedFF); }).some(function (result) { return result; });
|
|
14
|
-
|
|
13
|
+
updated = toRemove.map(function (removedFF) { return _this.removeSplit(removedFF.name); }).some(function (result) { return result; }) || updated;
|
|
14
|
+
this.setChangeNumber(changeNumber);
|
|
15
|
+
return updated;
|
|
15
16
|
};
|
|
16
17
|
AbstractSplitsCacheSync.prototype.getSplits = function (names) {
|
|
17
18
|
var _this = this;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __extends } from "tslib";
|
|
2
2
|
import { isNaNNumber } from '../../utils/lang';
|
|
3
3
|
import { AbstractMySegmentsCacheSync } from '../AbstractMySegmentsCacheSync';
|
|
4
|
-
import {
|
|
4
|
+
import { DEFINED } from './constants';
|
|
5
5
|
var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
6
6
|
__extends(MySegmentsCacheInLocal, _super);
|
|
7
7
|
function MySegmentsCacheInLocal(log, keys, storage) {
|
|
@@ -10,33 +10,20 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
|
10
10
|
_this.keys = keys;
|
|
11
11
|
_this.storage = storage;
|
|
12
12
|
return _this;
|
|
13
|
-
// There is not need to flush segments cache like splits cache, since resetSegments receives the up-to-date list of active segments
|
|
14
13
|
}
|
|
15
14
|
MySegmentsCacheInLocal.prototype.addSegment = function (name) {
|
|
16
15
|
var segmentKey = this.keys.buildSegmentNameKey(name);
|
|
17
|
-
|
|
18
|
-
if (this.storage.getItem(segmentKey) === DEFINED)
|
|
19
|
-
return false;
|
|
20
|
-
this.storage.setItem(segmentKey, DEFINED);
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
this.log.error(LOG_PREFIX + e);
|
|
16
|
+
if (this.storage.getItem(segmentKey) === DEFINED)
|
|
25
17
|
return false;
|
|
26
|
-
|
|
18
|
+
this.storage.setItem(segmentKey, DEFINED);
|
|
19
|
+
return true;
|
|
27
20
|
};
|
|
28
21
|
MySegmentsCacheInLocal.prototype.removeSegment = function (name) {
|
|
29
22
|
var segmentKey = this.keys.buildSegmentNameKey(name);
|
|
30
|
-
|
|
31
|
-
if (this.storage.getItem(segmentKey) !== DEFINED)
|
|
32
|
-
return false;
|
|
33
|
-
this.storage.removeItem(segmentKey);
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
this.log.error(LOG_PREFIX + e);
|
|
23
|
+
if (this.storage.getItem(segmentKey) !== DEFINED)
|
|
38
24
|
return false;
|
|
39
|
-
|
|
25
|
+
this.storage.removeItem(segmentKey);
|
|
26
|
+
return true;
|
|
40
27
|
};
|
|
41
28
|
MySegmentsCacheInLocal.prototype.isInSegment = function (name) {
|
|
42
29
|
return this.storage.getItem(this.keys.buildSegmentNameKey(name)) === DEFINED;
|
|
@@ -54,15 +41,10 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
|
|
|
54
41
|
return 1;
|
|
55
42
|
};
|
|
56
43
|
MySegmentsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
this.storage.removeItem(this.keys.buildTillKey());
|
|
62
|
-
}
|
|
63
|
-
catch (e) {
|
|
64
|
-
this.log.error(e);
|
|
65
|
-
}
|
|
44
|
+
if (changeNumber)
|
|
45
|
+
this.storage.setItem(this.keys.buildTillKey(), changeNumber + '');
|
|
46
|
+
else
|
|
47
|
+
this.storage.removeItem(this.keys.buildTillKey());
|
|
66
48
|
};
|
|
67
49
|
MySegmentsCacheInLocal.prototype.getChangeNumber = function () {
|
|
68
50
|
var n = -1;
|
|
@@ -15,9 +15,10 @@ var RBSegmentsCacheInLocal = /** @class */ (function () {
|
|
|
15
15
|
};
|
|
16
16
|
RBSegmentsCacheInLocal.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
17
17
|
var _this = this;
|
|
18
|
-
this.setChangeNumber(changeNumber);
|
|
19
18
|
var updated = toAdd.map(function (toAdd) { return _this.add(toAdd); }).some(function (result) { return result; });
|
|
20
|
-
|
|
19
|
+
updated = toRemove.map(function (toRemove) { return _this.remove(toRemove.name); }).some(function (result) { return result; }) || updated;
|
|
20
|
+
this.setChangeNumber(changeNumber);
|
|
21
|
+
return updated;
|
|
21
22
|
};
|
|
22
23
|
RBSegmentsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
|
|
23
24
|
try {
|
|
@@ -37,40 +38,28 @@ var RBSegmentsCacheInLocal = /** @class */ (function () {
|
|
|
37
38
|
this.storage.removeItem(segmentsCountKey);
|
|
38
39
|
};
|
|
39
40
|
RBSegmentsCacheInLocal.prototype.add = function (rbSegment) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
catch (e) {
|
|
56
|
-
this.log.error(LOG_PREFIX + e);
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
41
|
+
var name = rbSegment.name;
|
|
42
|
+
var rbSegmentKey = this.keys.buildRBSegmentKey(name);
|
|
43
|
+
var rbSegmentFromStorage = this.storage.getItem(rbSegmentKey);
|
|
44
|
+
var previous = rbSegmentFromStorage ? JSON.parse(rbSegmentFromStorage) : null;
|
|
45
|
+
this.storage.setItem(rbSegmentKey, JSON.stringify(rbSegment));
|
|
46
|
+
var usesSegmentsDiff = 0;
|
|
47
|
+
if (previous && usesSegments(previous))
|
|
48
|
+
usesSegmentsDiff--;
|
|
49
|
+
if (usesSegments(rbSegment))
|
|
50
|
+
usesSegmentsDiff++;
|
|
51
|
+
if (usesSegmentsDiff !== 0)
|
|
52
|
+
this.updateSegmentCount(usesSegmentsDiff);
|
|
53
|
+
return true;
|
|
59
54
|
};
|
|
60
55
|
RBSegmentsCacheInLocal.prototype.remove = function (name) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (!rbSegment)
|
|
64
|
-
return false;
|
|
65
|
-
this.storage.removeItem(this.keys.buildRBSegmentKey(name));
|
|
66
|
-
if (usesSegments(rbSegment))
|
|
67
|
-
this.updateSegmentCount(-1);
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
this.log.error(LOG_PREFIX + e);
|
|
56
|
+
var rbSegment = this.get(name);
|
|
57
|
+
if (!rbSegment)
|
|
72
58
|
return false;
|
|
73
|
-
|
|
59
|
+
this.storage.removeItem(this.keys.buildRBSegmentKey(name));
|
|
60
|
+
if (usesSegments(rbSegment))
|
|
61
|
+
this.updateSegmentCount(-1);
|
|
62
|
+
return true;
|
|
74
63
|
};
|
|
75
64
|
RBSegmentsCacheInLocal.prototype.getNames = function () {
|
|
76
65
|
var len = this.storage.length;
|
|
@@ -67,39 +67,27 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
67
67
|
this.hasSync = false;
|
|
68
68
|
};
|
|
69
69
|
SplitsCacheInLocal.prototype.addSplit = function (split) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
this.removeFromFlagSets(previousSplit.name, previousSplit.sets);
|
|
78
|
-
}
|
|
79
|
-
this.storage.setItem(splitKey, JSON.stringify(split));
|
|
80
|
-
this._incrementCounts(split);
|
|
81
|
-
this.addToFlagSets(split);
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
catch (e) {
|
|
85
|
-
this.log.error(LOG_PREFIX + e);
|
|
86
|
-
return false;
|
|
70
|
+
var name = split.name;
|
|
71
|
+
var splitKey = this.keys.buildSplitKey(name);
|
|
72
|
+
var splitFromStorage = this.storage.getItem(splitKey);
|
|
73
|
+
var previousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : null;
|
|
74
|
+
if (previousSplit) {
|
|
75
|
+
this._decrementCounts(previousSplit);
|
|
76
|
+
this.removeFromFlagSets(previousSplit.name, previousSplit.sets);
|
|
87
77
|
}
|
|
78
|
+
this.storage.setItem(splitKey, JSON.stringify(split));
|
|
79
|
+
this._incrementCounts(split);
|
|
80
|
+
this.addToFlagSets(split);
|
|
81
|
+
return true;
|
|
88
82
|
};
|
|
89
83
|
SplitsCacheInLocal.prototype.removeSplit = function (name) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (!split)
|
|
93
|
-
return false;
|
|
94
|
-
this.storage.removeItem(this.keys.buildSplitKey(name));
|
|
95
|
-
this._decrementCounts(split);
|
|
96
|
-
this.removeFromFlagSets(split.name, split.sets);
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
catch (e) {
|
|
100
|
-
this.log.error(LOG_PREFIX + e);
|
|
84
|
+
var split = this.getSplit(name);
|
|
85
|
+
if (!split)
|
|
101
86
|
return false;
|
|
102
|
-
|
|
87
|
+
this.storage.removeItem(this.keys.buildSplitKey(name));
|
|
88
|
+
this._decrementCounts(split);
|
|
89
|
+
this.removeFromFlagSets(split.name, split.sets);
|
|
90
|
+
return true;
|
|
103
91
|
};
|
|
104
92
|
SplitsCacheInLocal.prototype.getSplit = function (name) {
|
|
105
93
|
var item = this.storage.getItem(this.keys.buildSplitKey(name));
|
|
@@ -171,6 +159,8 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
|
|
|
171
159
|
var flagSetKey = _this.keys.buildFlagSetKey(featureFlagSet);
|
|
172
160
|
var flagSetFromStorage = _this.storage.getItem(flagSetKey);
|
|
173
161
|
var flagSetCache = new Set(flagSetFromStorage ? JSON.parse(flagSetFromStorage) : []);
|
|
162
|
+
if (flagSetCache.has(featureFlag.name))
|
|
163
|
+
return;
|
|
174
164
|
flagSetCache.add(featureFlag.name);
|
|
175
165
|
_this.storage.setItem(flagSetKey, JSON.stringify(setToArray(flagSetCache)));
|
|
176
166
|
});
|
|
@@ -13,9 +13,10 @@ var RBSegmentsCacheInMemory = /** @class */ (function () {
|
|
|
13
13
|
};
|
|
14
14
|
RBSegmentsCacheInMemory.prototype.update = function (toAdd, toRemove, changeNumber) {
|
|
15
15
|
var _this = this;
|
|
16
|
-
this.changeNumber = changeNumber;
|
|
17
16
|
var updated = toAdd.map(function (toAdd) { return _this.add(toAdd); }).some(function (result) { return result; });
|
|
18
|
-
|
|
17
|
+
updated = toRemove.map(function (toRemove) { return _this.remove(toRemove.name); }).some(function (result) { return result; }) || updated;
|
|
18
|
+
this.changeNumber = changeNumber;
|
|
19
|
+
return updated;
|
|
19
20
|
};
|
|
20
21
|
RBSegmentsCacheInMemory.prototype.add = function (rbSegment) {
|
|
21
22
|
var name = rbSegment.name;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isNaNNumber } from '../../utils/lang';
|
|
2
|
-
import { LOG_PREFIX } from '
|
|
2
|
+
import { LOG_PREFIX } from './constants';
|
|
3
3
|
var SegmentsCacheInRedis = /** @class */ (function () {
|
|
4
4
|
function SegmentsCacheInRedis(log, keys, redis) {
|
|
5
5
|
this.log = log;
|
|
@@ -5,5 +5,5 @@ import { segmentChangesUpdaterFactory } from '../updaters/segmentChangesUpdater'
|
|
|
5
5
|
* Creates a sync task that periodically executes a `segmentChangesUpdater` task
|
|
6
6
|
*/
|
|
7
7
|
export function segmentsSyncTaskFactory(fetchSegmentChanges, storage, readiness, settings) {
|
|
8
|
-
return syncTaskFactory(settings.log, segmentChangesUpdaterFactory(settings.log, segmentChangesFetcherFactory(fetchSegmentChanges), storage.segments, readiness), settings.scheduler.segmentsRefreshRate, 'segmentChangesUpdater');
|
|
8
|
+
return syncTaskFactory(settings.log, segmentChangesUpdaterFactory(settings.log, segmentChangesFetcherFactory(fetchSegmentChanges), storage.segments, readiness, settings.startup.requestTimeoutBeforeReady, settings.startup.retriesOnFailureBeforeReady), settings.scheduler.segmentsRefreshRate, 'segmentChangesUpdater');
|
|
9
9
|
}
|
|
@@ -45,9 +45,9 @@ export function mySegmentsUpdaterFactory(log, mySegmentsFetcher, storage, segmen
|
|
|
45
45
|
new Promise(function (res) { updateSegments(segmentsData); res(true); }) :
|
|
46
46
|
// If not provided, fetch mySegments
|
|
47
47
|
mySegmentsFetcher(matchingKey, noCache, till, _promiseDecorator).then(function (segments) {
|
|
48
|
-
// Only when we have downloaded segments completely, we should not keep retrying anymore
|
|
49
|
-
startingUp = false;
|
|
50
48
|
updateSegments(segments);
|
|
49
|
+
// Only when we have downloaded and stored segments completely, we should not keep retrying anymore
|
|
50
|
+
startingUp = false;
|
|
51
51
|
return true;
|
|
52
52
|
});
|
|
53
53
|
return updaterPromise.catch(function (error) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SDK_SEGMENTS_ARRIVED } from '../../../readiness/constants';
|
|
2
2
|
import { LOG_PREFIX_INSTANTIATION, LOG_PREFIX_SYNC_SEGMENTS } from '../../../logger/constants';
|
|
3
|
+
import { timeout } from '../../../utils/promise/timeout';
|
|
3
4
|
/**
|
|
4
5
|
* Factory of SegmentChanges updater, a task that:
|
|
5
6
|
* - fetches segment changes using `segmentChangesFetcher`
|
|
@@ -11,22 +12,33 @@ import { LOG_PREFIX_INSTANTIATION, LOG_PREFIX_SYNC_SEGMENTS } from '../../../log
|
|
|
11
12
|
* @param segments - segments storage, with sync or async methods
|
|
12
13
|
* @param readiness - optional readiness manager. Not required for synchronizer or producer mode.
|
|
13
14
|
*/
|
|
14
|
-
export function segmentChangesUpdaterFactory(log, segmentChangesFetcher, segments, readiness) {
|
|
15
|
+
export function segmentChangesUpdaterFactory(log, segmentChangesFetcher, segments, readiness, requestTimeoutBeforeReady, retriesOnFailureBeforeReady) {
|
|
15
16
|
var readyOnAlreadyExistentState = true;
|
|
16
|
-
function
|
|
17
|
+
function _promiseDecorator(promise) {
|
|
18
|
+
if (readyOnAlreadyExistentState && requestTimeoutBeforeReady)
|
|
19
|
+
promise = timeout(requestTimeoutBeforeReady, promise);
|
|
20
|
+
return promise;
|
|
21
|
+
}
|
|
22
|
+
function updateSegment(segmentName, noCache, till, fetchOnlyNew, retries) {
|
|
17
23
|
log.debug(LOG_PREFIX_SYNC_SEGMENTS + "Processing segment " + segmentName);
|
|
18
24
|
var sincePromise = Promise.resolve(segments.getChangeNumber(segmentName));
|
|
19
25
|
return sincePromise.then(function (since) {
|
|
20
26
|
// if fetchOnlyNew flag, avoid processing already fetched segments
|
|
21
27
|
return fetchOnlyNew && since !== undefined ?
|
|
22
28
|
false :
|
|
23
|
-
segmentChangesFetcher(since || -1, segmentName, noCache, till).then(function (changes) {
|
|
29
|
+
segmentChangesFetcher(since || -1, segmentName, noCache, till, _promiseDecorator).then(function (changes) {
|
|
24
30
|
return Promise.all(changes.map(function (x) {
|
|
25
31
|
log.debug(LOG_PREFIX_SYNC_SEGMENTS + "Processing " + segmentName + " with till = " + x.till + ". Added: " + x.added.length + ". Removed: " + x.removed.length);
|
|
26
32
|
return segments.update(segmentName, x.added, x.removed, x.till);
|
|
27
33
|
})).then(function (updates) {
|
|
28
34
|
return updates.some(function (update) { return update; });
|
|
29
35
|
});
|
|
36
|
+
}).catch(function (error) {
|
|
37
|
+
if (retries) {
|
|
38
|
+
log.warn(LOG_PREFIX_SYNC_SEGMENTS + "Retrying fetch of segment " + segmentName + " (attempt #" + retries + "). Reason: " + error);
|
|
39
|
+
return updateSegment(segmentName, noCache, till, fetchOnlyNew, retries - 1);
|
|
40
|
+
}
|
|
41
|
+
throw error;
|
|
30
42
|
});
|
|
31
43
|
});
|
|
32
44
|
}
|
|
@@ -46,8 +58,7 @@ export function segmentChangesUpdaterFactory(log, segmentChangesFetcher, segment
|
|
|
46
58
|
// If not a segment name provided, read list of available segments names to be updated.
|
|
47
59
|
var segmentsPromise = Promise.resolve(segmentName ? [segmentName] : segments.getRegisteredSegments());
|
|
48
60
|
return segmentsPromise.then(function (segmentNames) {
|
|
49
|
-
|
|
50
|
-
var updaters = segmentNames.map(function (segmentName) { return updateSegment(segmentName, noCache, till, fetchOnlyNew); });
|
|
61
|
+
var updaters = segmentNames.map(function (segmentName) { return updateSegment(segmentName, noCache, till, fetchOnlyNew, readyOnAlreadyExistentState ? retriesOnFailureBeforeReady : 0); });
|
|
51
62
|
return Promise.all(updaters).then(function (shouldUpdateFlags) {
|
|
52
63
|
// if at least one segment fetch succeeded, mark segments ready
|
|
53
64
|
if (shouldUpdateFlags.some(function (update) { return update; }) || readyOnAlreadyExistentState) {
|
|
@@ -130,7 +130,6 @@ export function splitChangesUpdaterFactory(log, splitChangesFetcher, storage, sp
|
|
|
130
130
|
{ rbs: { d: [instantUpdate.payload], t: instantUpdate.changeNumber } } :
|
|
131
131
|
splitChangesFetcher(since, noCache, till, rbSince, _promiseDecorator))
|
|
132
132
|
.then(function (splitChanges) {
|
|
133
|
-
startingUp = false;
|
|
134
133
|
var usedSegments = new Set();
|
|
135
134
|
var ffUpdate = false;
|
|
136
135
|
if (splitChanges.ff) {
|
|
@@ -151,6 +150,7 @@ export function splitChangesUpdaterFactory(log, splitChangesFetcher, storage, sp
|
|
|
151
150
|
var ffChanged = _a[0], rbsChanged = _a[1];
|
|
152
151
|
if (storage.save)
|
|
153
152
|
storage.save();
|
|
153
|
+
startingUp = false;
|
|
154
154
|
if (splitsEventEmitter) {
|
|
155
155
|
// To emit SDK_SPLITS_ARRIVED for server-side SDK, we must check that all registered segments have been fetched
|
|
156
156
|
return Promise.resolve(!splitsEventEmitter.splitsArrived || ((ffChanged || rbsChanged) && (isClientSide || checkAllSegmentsExist(segments))))
|
|
@@ -166,14 +166,14 @@ export function splitChangesUpdaterFactory(log, splitChangesFetcher, storage, sp
|
|
|
166
166
|
});
|
|
167
167
|
})
|
|
168
168
|
.catch(function (error) {
|
|
169
|
-
log.warn(SYNC_SPLITS_FETCH_FAILS, [error]);
|
|
170
169
|
if (startingUp && retriesOnFailureBeforeReady > retry) {
|
|
171
170
|
retry += 1;
|
|
172
|
-
log.
|
|
171
|
+
log.warn(SYNC_SPLITS_FETCH_RETRY, [retry, error]);
|
|
173
172
|
return _splitChangesUpdater(sinces, retry);
|
|
174
173
|
}
|
|
175
174
|
else {
|
|
176
175
|
startingUp = false;
|
|
176
|
+
log.warn(SYNC_SPLITS_FETCH_FAILS, [error]);
|
|
177
177
|
}
|
|
178
178
|
return false;
|
|
179
179
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
1
|
import { isObject, isString, isFiniteNumber, isBoolean } from '../lang';
|
|
3
2
|
import { objectAssign } from '../lang/objectAssign';
|
|
4
3
|
import { ERROR_NOT_PLAIN_OBJECT, ERROR_SIZE_EXCEEDED, WARN_SETTING_NULL, WARN_TRIMMING_PROPERTIES } from '../../logger/constants';
|
|
@@ -61,11 +60,7 @@ export function validateEventProperties(log, maybeProperties, method) {
|
|
|
61
60
|
export function validateEvaluationOptions(log, maybeOptions, method) {
|
|
62
61
|
if (isObject(maybeOptions)) {
|
|
63
62
|
var properties = validateEventProperties(log, maybeOptions.properties, method).properties;
|
|
64
|
-
|
|
65
|
-
var impressionsDisabled = maybeOptions.impressionsDisabled;
|
|
66
|
-
if (!impressionsDisabled)
|
|
67
|
-
return options;
|
|
68
|
-
return options ? __assign(__assign({}, options), { impressionsDisabled: impressionsDisabled }) : { impressionsDisabled: impressionsDisabled };
|
|
63
|
+
return properties && Object.keys(properties).length > 0 ? { properties: properties } : undefined;
|
|
69
64
|
}
|
|
70
65
|
else if (maybeOptions) {
|
|
71
66
|
log.error(ERROR_NOT_PLAIN_OBJECT, [method, 'evaluation options']);
|