@splitsoftware/splitio-commons 2.8.1-rc.0 → 2.8.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.
Files changed (45) hide show
  1. package/CHANGES.txt +2 -3
  2. package/cjs/evaluator/index.js +13 -13
  3. package/cjs/sdkClient/client.js +3 -3
  4. package/cjs/storages/AbstractMySegmentsCacheSync.js +23 -31
  5. package/cjs/storages/AbstractSplitsCacheSync.js +2 -3
  6. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +28 -10
  7. package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +33 -22
  8. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +29 -19
  9. package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +2 -3
  10. package/cjs/storages/inRedis/SegmentsCacheInRedis.js +1 -1
  11. package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +1 -1
  12. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +2 -2
  13. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +5 -16
  14. package/cjs/sync/polling/updaters/splitChangesUpdater.js +3 -3
  15. package/cjs/utils/inputValidation/eventProperties.js +6 -1
  16. package/esm/evaluator/index.js +13 -13
  17. package/esm/sdkClient/client.js +3 -3
  18. package/esm/storages/AbstractMySegmentsCacheSync.js +23 -31
  19. package/esm/storages/AbstractSplitsCacheSync.js +2 -3
  20. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +29 -11
  21. package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +33 -22
  22. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +29 -19
  23. package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +2 -3
  24. package/esm/storages/inRedis/SegmentsCacheInRedis.js +1 -1
  25. package/esm/sync/polling/syncTasks/segmentsSyncTask.js +1 -1
  26. package/esm/sync/polling/updaters/mySegmentsUpdater.js +2 -2
  27. package/esm/sync/polling/updaters/segmentChangesUpdater.js +5 -16
  28. package/esm/sync/polling/updaters/splitChangesUpdater.js +3 -3
  29. package/esm/utils/inputValidation/eventProperties.js +6 -1
  30. package/package.json +1 -1
  31. package/src/evaluator/index.ts +14 -6
  32. package/src/sdkClient/client.ts +3 -3
  33. package/src/storages/AbstractMySegmentsCacheSync.ts +20 -26
  34. package/src/storages/AbstractSplitsCacheSync.ts +2 -3
  35. package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +24 -9
  36. package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +27 -18
  37. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +29 -22
  38. package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +2 -3
  39. package/src/storages/inRedis/SegmentsCacheInRedis.ts +1 -1
  40. package/src/sync/polling/syncTasks/segmentsSyncTask.ts +0 -2
  41. package/src/sync/polling/updaters/mySegmentsUpdater.ts +3 -3
  42. package/src/sync/polling/updaters/segmentChangesUpdater.ts +4 -17
  43. package/src/sync/polling/updaters/splitChangesUpdater.ts +7 -6
  44. package/src/utils/inputValidation/eventProperties.ts +6 -1
  45. package/types/splitio.d.ts +10 -0
package/CHANGES.txt CHANGED
@@ -1,6 +1,5 @@
1
- 2.9.0 (November 26, 2025)
2
- - Updated the SDK’s initial synchronization in Node.js (server-side) to use the `startup.requestTimeoutBeforeReady` and `startup.retriesOnFailureBeforeReady` options to control the timeout and retry behavior of segment requests.
3
- - Updated the order of storage operations to prevent inconsistent states when using the `LOCALSTORAGE` storage type and the browser’s `localStorage` fails due to quota limits.
1
+ 2.9.0
2
+ - Added property `impressionsDisabled` in getTreatment(s) `evaluationOptions` parameter, to disable impressions per evaluations.
4
3
 
5
4
  2.8.0 (October 30, 2025)
6
5
  - Added new configuration for Fallback Treatments, which allows setting a treatment value and optional config to be returned in place of "control", either globally or by flag. Read more in our docs.
@@ -19,7 +19,7 @@ function treatmentsException(splitNames) {
19
19
  });
20
20
  return evaluations;
21
21
  }
22
- function evaluateFeature(log, key, splitName, attributes, storage) {
22
+ function evaluateFeature(log, key, splitName, attributes, storage, options) {
23
23
  var parsedSplit;
24
24
  try {
25
25
  parsedSplit = storage.splits.getSplit(splitName);
@@ -29,15 +29,15 @@ function evaluateFeature(log, key, splitName, attributes, storage) {
29
29
  return treatmentException;
30
30
  }
31
31
  if ((0, thenable_1.thenable)(parsedSplit)) {
32
- return parsedSplit.then(function (split) { return getEvaluation(log, key, split, attributes, storage); }).catch(
32
+ return parsedSplit.then(function (split) { return getEvaluation(log, key, split, attributes, storage, options); }).catch(
33
33
  // Exception on async `getSplit` storage. For example, when the storage is redis or
34
34
  // pluggable and there is a connection issue and we can't retrieve the split to be evaluated
35
35
  function () { return treatmentException; });
36
36
  }
37
- return getEvaluation(log, key, parsedSplit, attributes, storage);
37
+ return getEvaluation(log, key, parsedSplit, attributes, storage, options);
38
38
  }
39
39
  exports.evaluateFeature = evaluateFeature;
40
- function evaluateFeatures(log, key, splitNames, attributes, storage) {
40
+ function evaluateFeatures(log, key, splitNames, attributes, storage, options) {
41
41
  var parsedSplits;
42
42
  try {
43
43
  parsedSplits = storage.splits.getSplits(splitNames);
@@ -47,16 +47,16 @@ function evaluateFeatures(log, key, splitNames, attributes, storage) {
47
47
  return treatmentsException(splitNames);
48
48
  }
49
49
  return (0, thenable_1.thenable)(parsedSplits) ?
50
- parsedSplits.then(function (splits) { return getEvaluations(log, key, splitNames, splits, attributes, storage); })
50
+ parsedSplits.then(function (splits) { return getEvaluations(log, key, splitNames, splits, attributes, storage, options); })
51
51
  .catch(function () {
52
52
  // Exception on async `getSplits` storage. For example, when the storage is redis or
53
53
  // pluggable and there is a connection issue and we can't retrieve the split to be evaluated
54
54
  return treatmentsException(splitNames);
55
55
  }) :
56
- getEvaluations(log, key, splitNames, parsedSplits, attributes, storage);
56
+ getEvaluations(log, key, splitNames, parsedSplits, attributes, storage, options);
57
57
  }
58
58
  exports.evaluateFeatures = evaluateFeatures;
59
- function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, method) {
59
+ function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, method, options) {
60
60
  var storedFlagNames;
61
61
  function evaluate(featureFlagsByFlagSets) {
62
62
  var featureFlags = new Set();
@@ -70,7 +70,7 @@ function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, met
70
70
  }
71
71
  }
72
72
  return featureFlags.size ?
73
- evaluateFeatures(log, key, (0, sets_1.setToArray)(featureFlags), attributes, storage) :
73
+ evaluateFeatures(log, key, (0, sets_1.setToArray)(featureFlags), attributes, storage, options) :
74
74
  {};
75
75
  }
76
76
  // get features by flag sets
@@ -90,7 +90,7 @@ function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, met
90
90
  evaluate(storedFlagNames);
91
91
  }
92
92
  exports.evaluateFeaturesByFlagSets = evaluateFeaturesByFlagSets;
93
- function getEvaluation(log, key, splitJSON, attributes, storage) {
93
+ function getEvaluation(log, key, splitJSON, attributes, storage, options) {
94
94
  var evaluation = {
95
95
  treatment: constants_1.CONTROL,
96
96
  label: labels_1.SPLIT_NOT_FOUND,
@@ -104,23 +104,23 @@ function getEvaluation(log, key, splitJSON, attributes, storage) {
104
104
  return evaluation.then(function (result) {
105
105
  result.changeNumber = splitJSON.changeNumber;
106
106
  result.config = splitJSON.configurations && splitJSON.configurations[result.treatment] || null;
107
- result.impressionsDisabled = splitJSON.impressionsDisabled;
107
+ result.impressionsDisabled = (options === null || options === void 0 ? void 0 : options.impressionsDisabled) || splitJSON.impressionsDisabled;
108
108
  return result;
109
109
  });
110
110
  }
111
111
  else {
112
112
  evaluation.changeNumber = splitJSON.changeNumber;
113
113
  evaluation.config = splitJSON.configurations && splitJSON.configurations[evaluation.treatment] || null;
114
- evaluation.impressionsDisabled = splitJSON.impressionsDisabled;
114
+ evaluation.impressionsDisabled = (options === null || options === void 0 ? void 0 : options.impressionsDisabled) || splitJSON.impressionsDisabled;
115
115
  }
116
116
  }
117
117
  return evaluation;
118
118
  }
119
- function getEvaluations(log, key, splitNames, splits, attributes, storage) {
119
+ function getEvaluations(log, key, splitNames, splits, attributes, storage, options) {
120
120
  var result = {};
121
121
  var thenables = [];
122
122
  splitNames.forEach(function (splitName) {
123
- var evaluation = getEvaluation(log, key, splits[splitName], attributes, storage);
123
+ var evaluation = getEvaluation(log, key, splits[splitName], attributes, storage, options);
124
124
  if ((0, thenable_1.thenable)(evaluation)) {
125
125
  thenables.push(evaluation.then(function (res) {
126
126
  result[splitName] = res;
@@ -45,7 +45,7 @@ function clientFactory(params) {
45
45
  return treatment;
46
46
  };
47
47
  var evaluation = readinessManager.isReadyFromCache() ?
48
- (0, evaluator_1.evaluateFeature)(log, key, featureFlagName, attributes, storage) :
48
+ (0, evaluator_1.evaluateFeature)(log, key, featureFlagName, attributes, storage, options) :
49
49
  isAsync ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
50
50
  Promise.resolve(treatmentNotReady) :
51
51
  treatmentNotReady;
@@ -70,7 +70,7 @@ function clientFactory(params) {
70
70
  return treatments;
71
71
  };
72
72
  var evaluations = readinessManager.isReadyFromCache() ?
73
- (0, evaluator_1.evaluateFeatures)(log, key, featureFlagNames, attributes, storage) :
73
+ (0, evaluator_1.evaluateFeatures)(log, key, featureFlagNames, attributes, storage, options) :
74
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
75
75
  Promise.resolve(treatmentsNotReady(featureFlagNames)) :
76
76
  treatmentsNotReady(featureFlagNames);
@@ -96,7 +96,7 @@ function clientFactory(params) {
96
96
  return treatments;
97
97
  };
98
98
  var evaluations = readinessManager.isReadyFromCache() ?
99
- (0, evaluator_1.evaluateFeaturesByFlagSets)(log, key, flagSetNames, attributes, storage, methodName) :
99
+ (0, evaluator_1.evaluateFeaturesByFlagSets)(log, key, flagSetNames, attributes, storage, methodName, options) :
100
100
  isAsync ?
101
101
  Promise.resolve({}) :
102
102
  {};
@@ -23,45 +23,37 @@ var AbstractMySegmentsCacheSync = /** @class */ (function () {
23
23
  */
24
24
  AbstractMySegmentsCacheSync.prototype.resetSegments = function (segmentsData) {
25
25
  var _this = this;
26
- var isDiff = false;
26
+ this.setChangeNumber(segmentsData.cn);
27
27
  var _a = segmentsData, added = _a.added, removed = _a.removed;
28
28
  if (added && removed) {
29
+ var isDiff_1 = false;
29
30
  added.forEach(function (segment) {
30
- isDiff = _this.addSegment(segment) || isDiff;
31
+ isDiff_1 = _this.addSegment(segment) || isDiff_1;
31
32
  });
32
33
  removed.forEach(function (segment) {
33
- isDiff = _this.removeSegment(segment) || isDiff;
34
+ isDiff_1 = _this.removeSegment(segment) || isDiff_1;
34
35
  });
36
+ return isDiff_1;
35
37
  }
36
- else {
37
- var names = (segmentsData.k || []).map(function (s) { return s.n; }).sort();
38
- var storedSegmentKeys = this.getRegisteredSegments().sort();
39
- // Extreme fast => everything is empty
40
- if (!names.length && !storedSegmentKeys.length) {
41
- isDiff = false;
42
- }
43
- else {
44
- var index = 0;
45
- while (index < names.length && index < storedSegmentKeys.length && names[index] === storedSegmentKeys[index])
46
- index++;
47
- // Quick path => no changes
48
- if (index === names.length && index === storedSegmentKeys.length) {
49
- isDiff = false;
50
- }
51
- else {
52
- // Slowest path => add and/or remove segments
53
- for (var removeIndex = index; removeIndex < storedSegmentKeys.length; removeIndex++) {
54
- this.removeSegment(storedSegmentKeys[removeIndex]);
55
- }
56
- for (var addIndex = index; addIndex < names.length; addIndex++) {
57
- this.addSegment(names[addIndex]);
58
- }
59
- isDiff = true;
60
- }
61
- }
38
+ var names = (segmentsData.k || []).map(function (s) { return s.n; }).sort();
39
+ var storedSegmentKeys = this.getRegisteredSegments().sort();
40
+ // Extreme fast => everything is empty
41
+ if (!names.length && !storedSegmentKeys.length)
42
+ return false;
43
+ var index = 0;
44
+ while (index < names.length && index < storedSegmentKeys.length && names[index] === storedSegmentKeys[index])
45
+ index++;
46
+ // Quick path => no changes
47
+ if (index === names.length && index === storedSegmentKeys.length)
48
+ return false;
49
+ // Slowest path => add and/or remove segments
50
+ for (var removeIndex = index; removeIndex < storedSegmentKeys.length; removeIndex++) {
51
+ this.removeSegment(storedSegmentKeys[removeIndex]);
62
52
  }
63
- this.setChangeNumber(segmentsData.cn);
64
- return isDiff;
53
+ for (var addIndex = index; addIndex < names.length; addIndex++) {
54
+ this.addSegment(names[addIndex]);
55
+ }
56
+ return true;
65
57
  };
66
58
  return AbstractMySegmentsCacheSync;
67
59
  }());
@@ -12,10 +12,9 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
12
12
  }
13
13
  AbstractSplitsCacheSync.prototype.update = function (toAdd, toRemove, changeNumber) {
14
14
  var _this = this;
15
- var updated = toAdd.map(function (addedFF) { return _this.addSplit(addedFF); }).some(function (result) { return result; });
16
- updated = toRemove.map(function (removedFF) { return _this.removeSplit(removedFF.name); }).some(function (result) { return result; }) || updated;
17
15
  this.setChangeNumber(changeNumber);
18
- return updated;
16
+ var updated = toAdd.map(function (addedFF) { return _this.addSplit(addedFF); }).some(function (result) { return result; });
17
+ return toRemove.map(function (removedFF) { return _this.removeSplit(removedFF.name); }).some(function (result) { return result; }) || updated;
19
18
  };
20
19
  AbstractSplitsCacheSync.prototype.getSplits = function (names) {
21
20
  var _this = this;
@@ -13,20 +13,33 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
13
13
  _this.keys = keys;
14
14
  _this.storage = storage;
15
15
  return _this;
16
+ // There is not need to flush segments cache like splits cache, since resetSegments receives the up-to-date list of active segments
16
17
  }
17
18
  MySegmentsCacheInLocal.prototype.addSegment = function (name) {
18
19
  var segmentKey = this.keys.buildSegmentNameKey(name);
19
- if (this.storage.getItem(segmentKey) === constants_1.DEFINED)
20
+ try {
21
+ if (this.storage.getItem(segmentKey) === constants_1.DEFINED)
22
+ return false;
23
+ this.storage.setItem(segmentKey, constants_1.DEFINED);
24
+ return true;
25
+ }
26
+ catch (e) {
27
+ this.log.error(constants_1.LOG_PREFIX + e);
20
28
  return false;
21
- this.storage.setItem(segmentKey, constants_1.DEFINED);
22
- return true;
29
+ }
23
30
  };
24
31
  MySegmentsCacheInLocal.prototype.removeSegment = function (name) {
25
32
  var segmentKey = this.keys.buildSegmentNameKey(name);
26
- if (this.storage.getItem(segmentKey) !== constants_1.DEFINED)
33
+ try {
34
+ if (this.storage.getItem(segmentKey) !== constants_1.DEFINED)
35
+ return false;
36
+ this.storage.removeItem(segmentKey);
37
+ return true;
38
+ }
39
+ catch (e) {
40
+ this.log.error(constants_1.LOG_PREFIX + e);
27
41
  return false;
28
- this.storage.removeItem(segmentKey);
29
- return true;
42
+ }
30
43
  };
31
44
  MySegmentsCacheInLocal.prototype.isInSegment = function (name) {
32
45
  return this.storage.getItem(this.keys.buildSegmentNameKey(name)) === constants_1.DEFINED;
@@ -44,10 +57,15 @@ var MySegmentsCacheInLocal = /** @class */ (function (_super) {
44
57
  return 1;
45
58
  };
46
59
  MySegmentsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
47
- if (changeNumber)
48
- this.storage.setItem(this.keys.buildTillKey(), changeNumber + '');
49
- else
50
- this.storage.removeItem(this.keys.buildTillKey());
60
+ try {
61
+ if (changeNumber)
62
+ this.storage.setItem(this.keys.buildTillKey(), changeNumber + '');
63
+ else
64
+ this.storage.removeItem(this.keys.buildTillKey());
65
+ }
66
+ catch (e) {
67
+ this.log.error(e);
68
+ }
51
69
  };
52
70
  MySegmentsCacheInLocal.prototype.getChangeNumber = function () {
53
71
  var n = -1;
@@ -18,10 +18,9 @@ var RBSegmentsCacheInLocal = /** @class */ (function () {
18
18
  };
19
19
  RBSegmentsCacheInLocal.prototype.update = function (toAdd, toRemove, changeNumber) {
20
20
  var _this = this;
21
- var updated = toAdd.map(function (toAdd) { return _this.add(toAdd); }).some(function (result) { return result; });
22
- updated = toRemove.map(function (toRemove) { return _this.remove(toRemove.name); }).some(function (result) { return result; }) || updated;
23
21
  this.setChangeNumber(changeNumber);
24
- return updated;
22
+ var updated = toAdd.map(function (toAdd) { return _this.add(toAdd); }).some(function (result) { return result; });
23
+ return toRemove.map(function (toRemove) { return _this.remove(toRemove.name); }).some(function (result) { return result; }) || updated;
25
24
  };
26
25
  RBSegmentsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
27
26
  try {
@@ -41,28 +40,40 @@ var RBSegmentsCacheInLocal = /** @class */ (function () {
41
40
  this.storage.removeItem(segmentsCountKey);
42
41
  };
43
42
  RBSegmentsCacheInLocal.prototype.add = function (rbSegment) {
44
- var name = rbSegment.name;
45
- var rbSegmentKey = this.keys.buildRBSegmentKey(name);
46
- var rbSegmentFromStorage = this.storage.getItem(rbSegmentKey);
47
- var previous = rbSegmentFromStorage ? JSON.parse(rbSegmentFromStorage) : null;
48
- this.storage.setItem(rbSegmentKey, JSON.stringify(rbSegment));
49
- var usesSegmentsDiff = 0;
50
- if (previous && (0, AbstractSplitsCacheSync_1.usesSegments)(previous))
51
- usesSegmentsDiff--;
52
- if ((0, AbstractSplitsCacheSync_1.usesSegments)(rbSegment))
53
- usesSegmentsDiff++;
54
- if (usesSegmentsDiff !== 0)
55
- this.updateSegmentCount(usesSegmentsDiff);
56
- return true;
43
+ try {
44
+ var name_1 = rbSegment.name;
45
+ var rbSegmentKey = this.keys.buildRBSegmentKey(name_1);
46
+ var rbSegmentFromStorage = this.storage.getItem(rbSegmentKey);
47
+ var previous = rbSegmentFromStorage ? JSON.parse(rbSegmentFromStorage) : null;
48
+ this.storage.setItem(rbSegmentKey, JSON.stringify(rbSegment));
49
+ var usesSegmentsDiff = 0;
50
+ if (previous && (0, AbstractSplitsCacheSync_1.usesSegments)(previous))
51
+ usesSegmentsDiff--;
52
+ if ((0, AbstractSplitsCacheSync_1.usesSegments)(rbSegment))
53
+ usesSegmentsDiff++;
54
+ if (usesSegmentsDiff !== 0)
55
+ this.updateSegmentCount(usesSegmentsDiff);
56
+ return true;
57
+ }
58
+ catch (e) {
59
+ this.log.error(constants_1.LOG_PREFIX + e);
60
+ return false;
61
+ }
57
62
  };
58
63
  RBSegmentsCacheInLocal.prototype.remove = function (name) {
59
- var rbSegment = this.get(name);
60
- if (!rbSegment)
64
+ try {
65
+ var rbSegment = this.get(name);
66
+ if (!rbSegment)
67
+ return false;
68
+ this.storage.removeItem(this.keys.buildRBSegmentKey(name));
69
+ if ((0, AbstractSplitsCacheSync_1.usesSegments)(rbSegment))
70
+ this.updateSegmentCount(-1);
71
+ return true;
72
+ }
73
+ catch (e) {
74
+ this.log.error(constants_1.LOG_PREFIX + e);
61
75
  return false;
62
- this.storage.removeItem(this.keys.buildRBSegmentKey(name));
63
- if ((0, AbstractSplitsCacheSync_1.usesSegments)(rbSegment))
64
- this.updateSegmentCount(-1);
65
- return true;
76
+ }
66
77
  };
67
78
  RBSegmentsCacheInLocal.prototype.getNames = function () {
68
79
  var len = this.storage.length;
@@ -70,27 +70,39 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
70
70
  this.hasSync = false;
71
71
  };
72
72
  SplitsCacheInLocal.prototype.addSplit = function (split) {
73
- var name = split.name;
74
- var splitKey = this.keys.buildSplitKey(name);
75
- var splitFromStorage = this.storage.getItem(splitKey);
76
- var previousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : null;
77
- if (previousSplit) {
78
- this._decrementCounts(previousSplit);
79
- this.removeFromFlagSets(previousSplit.name, previousSplit.sets);
73
+ try {
74
+ var name_1 = split.name;
75
+ var splitKey = this.keys.buildSplitKey(name_1);
76
+ var splitFromStorage = this.storage.getItem(splitKey);
77
+ var previousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : null;
78
+ if (previousSplit) {
79
+ this._decrementCounts(previousSplit);
80
+ this.removeFromFlagSets(previousSplit.name, previousSplit.sets);
81
+ }
82
+ this.storage.setItem(splitKey, JSON.stringify(split));
83
+ this._incrementCounts(split);
84
+ this.addToFlagSets(split);
85
+ return true;
86
+ }
87
+ catch (e) {
88
+ this.log.error(constants_1.LOG_PREFIX + e);
89
+ return false;
80
90
  }
81
- this.storage.setItem(splitKey, JSON.stringify(split));
82
- this._incrementCounts(split);
83
- this.addToFlagSets(split);
84
- return true;
85
91
  };
86
92
  SplitsCacheInLocal.prototype.removeSplit = function (name) {
87
- var split = this.getSplit(name);
88
- if (!split)
93
+ try {
94
+ var split = this.getSplit(name);
95
+ if (!split)
96
+ return false;
97
+ this.storage.removeItem(this.keys.buildSplitKey(name));
98
+ this._decrementCounts(split);
99
+ this.removeFromFlagSets(split.name, split.sets);
100
+ return true;
101
+ }
102
+ catch (e) {
103
+ this.log.error(constants_1.LOG_PREFIX + e);
89
104
  return false;
90
- this.storage.removeItem(this.keys.buildSplitKey(name));
91
- this._decrementCounts(split);
92
- this.removeFromFlagSets(split.name, split.sets);
93
- return true;
105
+ }
94
106
  };
95
107
  SplitsCacheInLocal.prototype.getSplit = function (name) {
96
108
  var item = this.storage.getItem(this.keys.buildSplitKey(name));
@@ -162,8 +174,6 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
162
174
  var flagSetKey = _this.keys.buildFlagSetKey(featureFlagSet);
163
175
  var flagSetFromStorage = _this.storage.getItem(flagSetKey);
164
176
  var flagSetCache = new Set(flagSetFromStorage ? JSON.parse(flagSetFromStorage) : []);
165
- if (flagSetCache.has(featureFlag.name))
166
- return;
167
177
  flagSetCache.add(featureFlag.name);
168
178
  _this.storage.setItem(flagSetKey, JSON.stringify((0, sets_1.setToArray)(flagSetCache)));
169
179
  });
@@ -16,10 +16,9 @@ var RBSegmentsCacheInMemory = /** @class */ (function () {
16
16
  };
17
17
  RBSegmentsCacheInMemory.prototype.update = function (toAdd, toRemove, changeNumber) {
18
18
  var _this = this;
19
- var updated = toAdd.map(function (toAdd) { return _this.add(toAdd); }).some(function (result) { return result; });
20
- updated = toRemove.map(function (toRemove) { return _this.remove(toRemove.name); }).some(function (result) { return result; }) || updated;
21
19
  this.changeNumber = changeNumber;
22
- return updated;
20
+ var updated = toAdd.map(function (toAdd) { return _this.add(toAdd); }).some(function (result) { return result; });
21
+ return toRemove.map(function (toRemove) { return _this.remove(toRemove.name); }).some(function (result) { return result; }) || updated;
23
22
  };
24
23
  RBSegmentsCacheInMemory.prototype.add = function (rbSegment) {
25
24
  var name = rbSegment.name;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SegmentsCacheInRedis = void 0;
4
4
  var lang_1 = require("../../utils/lang");
5
- var constants_1 = require("./constants");
5
+ var constants_1 = require("../inLocalStorage/constants");
6
6
  var SegmentsCacheInRedis = /** @class */ (function () {
7
7
  function SegmentsCacheInRedis(log, keys, redis) {
8
8
  this.log = log;
@@ -8,6 +8,6 @@ var segmentChangesUpdater_1 = require("../updaters/segmentChangesUpdater");
8
8
  * Creates a sync task that periodically executes a `segmentChangesUpdater` task
9
9
  */
10
10
  function segmentsSyncTaskFactory(fetchSegmentChanges, storage, readiness, settings) {
11
- return (0, syncTask_1.syncTaskFactory)(settings.log, (0, segmentChangesUpdater_1.segmentChangesUpdaterFactory)(settings.log, (0, segmentChangesFetcher_1.segmentChangesFetcherFactory)(fetchSegmentChanges), storage.segments, readiness, settings.startup.requestTimeoutBeforeReady, settings.startup.retriesOnFailureBeforeReady), settings.scheduler.segmentsRefreshRate, 'segmentChangesUpdater');
11
+ return (0, syncTask_1.syncTaskFactory)(settings.log, (0, segmentChangesUpdater_1.segmentChangesUpdaterFactory)(settings.log, (0, segmentChangesFetcher_1.segmentChangesFetcherFactory)(fetchSegmentChanges), storage.segments, readiness), settings.scheduler.segmentsRefreshRate, 'segmentChangesUpdater');
12
12
  }
13
13
  exports.segmentsSyncTaskFactory = segmentsSyncTaskFactory;
@@ -48,9 +48,9 @@ function mySegmentsUpdaterFactory(log, mySegmentsFetcher, storage, segmentsEvent
48
48
  new Promise(function (res) { updateSegments(segmentsData); res(true); }) :
49
49
  // If not provided, fetch mySegments
50
50
  mySegmentsFetcher(matchingKey, noCache, till, _promiseDecorator).then(function (segments) {
51
- updateSegments(segments);
52
- // Only when we have downloaded and stored segments completely, we should not keep retrying anymore
51
+ // Only when we have downloaded segments completely, we should not keep retrying anymore
53
52
  startingUp = false;
53
+ updateSegments(segments);
54
54
  return true;
55
55
  });
56
56
  return updaterPromise.catch(function (error) {
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.segmentChangesUpdaterFactory = void 0;
4
4
  var constants_1 = require("../../../readiness/constants");
5
5
  var constants_2 = require("../../../logger/constants");
6
- var timeout_1 = require("../../../utils/promise/timeout");
7
6
  /**
8
7
  * Factory of SegmentChanges updater, a task that:
9
8
  * - fetches segment changes using `segmentChangesFetcher`
@@ -15,33 +14,22 @@ var timeout_1 = require("../../../utils/promise/timeout");
15
14
  * @param segments - segments storage, with sync or async methods
16
15
  * @param readiness - optional readiness manager. Not required for synchronizer or producer mode.
17
16
  */
18
- function segmentChangesUpdaterFactory(log, segmentChangesFetcher, segments, readiness, requestTimeoutBeforeReady, retriesOnFailureBeforeReady) {
17
+ function segmentChangesUpdaterFactory(log, segmentChangesFetcher, segments, readiness) {
19
18
  var readyOnAlreadyExistentState = true;
20
- function _promiseDecorator(promise) {
21
- if (readyOnAlreadyExistentState && requestTimeoutBeforeReady)
22
- promise = (0, timeout_1.timeout)(requestTimeoutBeforeReady, promise);
23
- return promise;
24
- }
25
- function updateSegment(segmentName, noCache, till, fetchOnlyNew, retries) {
19
+ function updateSegment(segmentName, noCache, till, fetchOnlyNew) {
26
20
  log.debug(constants_2.LOG_PREFIX_SYNC_SEGMENTS + "Processing segment " + segmentName);
27
21
  var sincePromise = Promise.resolve(segments.getChangeNumber(segmentName));
28
22
  return sincePromise.then(function (since) {
29
23
  // if fetchOnlyNew flag, avoid processing already fetched segments
30
24
  return fetchOnlyNew && since !== undefined ?
31
25
  false :
32
- segmentChangesFetcher(since || -1, segmentName, noCache, till, _promiseDecorator).then(function (changes) {
26
+ segmentChangesFetcher(since || -1, segmentName, noCache, till).then(function (changes) {
33
27
  return Promise.all(changes.map(function (x) {
34
28
  log.debug(constants_2.LOG_PREFIX_SYNC_SEGMENTS + "Processing " + segmentName + " with till = " + x.till + ". Added: " + x.added.length + ". Removed: " + x.removed.length);
35
29
  return segments.update(segmentName, x.added, x.removed, x.till);
36
30
  })).then(function (updates) {
37
31
  return updates.some(function (update) { return update; });
38
32
  });
39
- }).catch(function (error) {
40
- if (retries) {
41
- log.warn(constants_2.LOG_PREFIX_SYNC_SEGMENTS + "Retrying fetch of segment " + segmentName + " (attempt #" + retries + "). Reason: " + error);
42
- return updateSegment(segmentName, noCache, till, fetchOnlyNew, retries - 1);
43
- }
44
- throw error;
45
33
  });
46
34
  });
47
35
  }
@@ -61,7 +49,8 @@ function segmentChangesUpdaterFactory(log, segmentChangesFetcher, segments, read
61
49
  // If not a segment name provided, read list of available segments names to be updated.
62
50
  var segmentsPromise = Promise.resolve(segmentName ? [segmentName] : segments.getRegisteredSegments());
63
51
  return segmentsPromise.then(function (segmentNames) {
64
- var updaters = segmentNames.map(function (segmentName) { return updateSegment(segmentName, noCache, till, fetchOnlyNew, readyOnAlreadyExistentState ? retriesOnFailureBeforeReady : 0); });
52
+ // Async fetchers
53
+ var updaters = segmentNames.map(function (segmentName) { return updateSegment(segmentName, noCache, till, fetchOnlyNew); });
65
54
  return Promise.all(updaters).then(function (shouldUpdateFlags) {
66
55
  // if at least one segment fetch succeeded, mark segments ready
67
56
  if (shouldUpdateFlags.some(function (update) { return update; }) || readyOnAlreadyExistentState) {
@@ -135,6 +135,7 @@ function splitChangesUpdaterFactory(log, splitChangesFetcher, storage, splitFilt
135
135
  { rbs: { d: [instantUpdate.payload], t: instantUpdate.changeNumber } } :
136
136
  splitChangesFetcher(since, noCache, till, rbSince, _promiseDecorator))
137
137
  .then(function (splitChanges) {
138
+ startingUp = false;
138
139
  var usedSegments = new Set();
139
140
  var ffUpdate = false;
140
141
  if (splitChanges.ff) {
@@ -155,7 +156,6 @@ function splitChangesUpdaterFactory(log, splitChangesFetcher, storage, splitFilt
155
156
  var ffChanged = _a[0], rbsChanged = _a[1];
156
157
  if (storage.save)
157
158
  storage.save();
158
- startingUp = false;
159
159
  if (splitsEventEmitter) {
160
160
  // To emit SDK_SPLITS_ARRIVED for server-side SDK, we must check that all registered segments have been fetched
161
161
  return Promise.resolve(!splitsEventEmitter.splitsArrived || ((ffChanged || rbsChanged) && (isClientSide || checkAllSegmentsExist(segments))))
@@ -171,14 +171,14 @@ function splitChangesUpdaterFactory(log, splitChangesFetcher, storage, splitFilt
171
171
  });
172
172
  })
173
173
  .catch(function (error) {
174
+ log.warn(constants_2.SYNC_SPLITS_FETCH_FAILS, [error]);
174
175
  if (startingUp && retriesOnFailureBeforeReady > retry) {
175
176
  retry += 1;
176
- log.warn(constants_2.SYNC_SPLITS_FETCH_RETRY, [retry, error]);
177
+ log.info(constants_2.SYNC_SPLITS_FETCH_RETRY, [retry, error]);
177
178
  return _splitChangesUpdater(sinces, retry);
178
179
  }
179
180
  else {
180
181
  startingUp = false;
181
- log.warn(constants_2.SYNC_SPLITS_FETCH_FAILS, [error]);
182
182
  }
183
183
  return false;
184
184
  });
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateEvaluationOptions = exports.validateEventProperties = void 0;
4
+ var tslib_1 = require("tslib");
4
5
  var lang_1 = require("../lang");
5
6
  var objectAssign_1 = require("../lang/objectAssign");
6
7
  var constants_1 = require("../../logger/constants");
@@ -64,7 +65,11 @@ exports.validateEventProperties = validateEventProperties;
64
65
  function validateEvaluationOptions(log, maybeOptions, method) {
65
66
  if ((0, lang_1.isObject)(maybeOptions)) {
66
67
  var properties = validateEventProperties(log, maybeOptions.properties, method).properties;
67
- return properties && Object.keys(properties).length > 0 ? { properties: properties } : undefined;
68
+ var options = properties && Object.keys(properties).length > 0 ? { properties: properties } : undefined;
69
+ var impressionsDisabled = maybeOptions.impressionsDisabled;
70
+ if (!impressionsDisabled)
71
+ return options;
72
+ return options ? (0, tslib_1.__assign)((0, tslib_1.__assign)({}, options), { impressionsDisabled: impressionsDisabled }) : { impressionsDisabled: impressionsDisabled };
68
73
  }
69
74
  else if (maybeOptions) {
70
75
  log.error(constants_1.ERROR_NOT_PLAIN_OBJECT, [method, 'evaluation options']);