@splitsoftware/splitio-commons 3.1.1-rc.10 → 3.1.1-rc.12

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 (237) hide show
  1. package/CHANGES.txt +3 -0
  2. package/cjs/evaluator/condition/index.js +2 -2
  3. package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
  4. package/cjs/evaluator/index.js +81 -71
  5. package/cjs/listeners/browser.js +2 -1
  6. package/cjs/listeners/node.js +4 -4
  7. package/cjs/logger/constants.js +15 -20
  8. package/cjs/logger/messages/debug.js +5 -6
  9. package/cjs/logger/messages/error.js +3 -3
  10. package/cjs/logger/messages/info.js +3 -4
  11. package/cjs/logger/messages/warn.js +6 -7
  12. package/cjs/platform/browser.js +15 -0
  13. package/cjs/platform/getEventSource/browser.js +8 -0
  14. package/cjs/platform/getEventSource/eventsource.js +480 -0
  15. package/cjs/platform/getEventSource/node.js +26 -0
  16. package/cjs/platform/getFetch/browser.js +9 -0
  17. package/cjs/platform/getFetch/node.js +27 -0
  18. package/cjs/platform/getOptions/node.js +25 -0
  19. package/cjs/platform/node.js +17 -0
  20. package/cjs/presets/serverSide.js +2 -2
  21. package/cjs/readiness/constants.js +5 -4
  22. package/cjs/readiness/readinessManager.js +23 -23
  23. package/cjs/readiness/sdkReadinessManager.js +1 -17
  24. package/cjs/sdkClient/client.js +24 -50
  25. package/cjs/sdkClient/clientInputValidation.js +6 -17
  26. package/cjs/sdkClient/sdkClient.js +3 -60
  27. package/cjs/sdkClient/sdkLifecycle.js +74 -0
  28. package/cjs/sdkClient/trackMethod.js +56 -0
  29. package/cjs/sdkFactory/index.js +11 -15
  30. package/cjs/sdkManager/index.js +5 -5
  31. package/cjs/services/authProvider.js +80 -0
  32. package/cjs/services/decorateHeaders.js +2 -1
  33. package/cjs/{sync/streaming/AuthClient/index.js → services/fetchAuth.js} +15 -16
  34. package/cjs/services/secureSplitHttpClient.js +36 -0
  35. package/cjs/services/serviceApi.js +147 -0
  36. package/cjs/services/splitApi.js +24 -10
  37. package/cjs/services/splitHttpClient.js +3 -5
  38. package/cjs/storages/AbstractDefinitionsCacheAsync.js +51 -0
  39. package/cjs/storages/AbstractDefinitionsCacheSync.js +76 -0
  40. package/cjs/storages/KeyBuilder.js +6 -6
  41. package/cjs/storages/KeyBuilderCS.js +5 -5
  42. package/cjs/storages/KeyBuilderSS.js +2 -2
  43. package/cjs/storages/getRolloutPlan.js +3 -3
  44. package/cjs/storages/inLocalStorage/DefinitionsCacheInLocal.js +195 -0
  45. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -2
  46. package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +12 -11
  47. package/cjs/storages/inLocalStorage/index.js +6 -6
  48. package/cjs/storages/inLocalStorage/validateCache.js +3 -3
  49. package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +122 -0
  50. package/cjs/storages/inMemory/InMemoryStorage.js +4 -4
  51. package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -5
  52. package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +7 -6
  53. package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  54. package/cjs/storages/inMemory/TelemetryCacheInMemory.js +5 -5
  55. package/cjs/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +79 -77
  56. package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +4 -2
  57. package/cjs/storages/inRedis/index.js +2 -2
  58. package/cjs/storages/pluggable/DefinitionsCachePluggable.js +214 -0
  59. package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +4 -2
  60. package/cjs/storages/pluggable/index.js +2 -2
  61. package/cjs/storages/setRolloutPlan.js +4 -4
  62. package/cjs/storages/utils.js +1 -0
  63. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +5 -5
  64. package/cjs/sync/polling/fetchers/splitChangesFetcher.js +24 -15
  65. package/cjs/sync/polling/pollingManagerCS.js +86 -81
  66. package/cjs/sync/polling/pollingManagerSS.js +44 -36
  67. package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +13 -0
  68. package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +2 -3
  69. package/cjs/sync/polling/updaters/definitionChangesUpdater.js +207 -0
  70. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  71. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
  72. package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +1 -1
  73. package/cjs/sync/streaming/SSEHandler/index.js +2 -1
  74. package/cjs/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +19 -20
  75. package/cjs/sync/streaming/constants.js +4 -3
  76. package/cjs/sync/streaming/parseUtils.js +14 -14
  77. package/cjs/sync/streaming/pushManager.js +22 -26
  78. package/cjs/sync/submitters/eventsSubmitter.js +1 -1
  79. package/cjs/sync/submitters/impressionCountsSubmitter.js +1 -1
  80. package/cjs/sync/submitters/impressionsSubmitter.js +5 -4
  81. package/cjs/sync/submitters/telemetrySubmitter.js +3 -4
  82. package/cjs/sync/submitters/uniqueKeysSubmitter.js +1 -1
  83. package/cjs/sync/syncManagerOnline.js +5 -5
  84. package/cjs/utils/Backoff.js +35 -3
  85. package/cjs/utils/EventEmitter.js +391 -0
  86. package/cjs/utils/filter/bloomFilter.js +37 -0
  87. package/cjs/utils/inputValidation/{split.js → definition.js} +10 -10
  88. package/cjs/utils/inputValidation/{splitExistence.js → definitionExistence.js} +6 -6
  89. package/cjs/utils/inputValidation/definitions.js +25 -0
  90. package/cjs/utils/inputValidation/index.js +7 -7
  91. package/cjs/utils/inputValidation/isOperational.js +4 -4
  92. package/cjs/utils/inputValidation/target.js +22 -0
  93. package/cjs/utils/labels/index.js +3 -3
  94. package/cjs/utils/settingsValidation/index.js +2 -0
  95. package/cjs/utils/settingsValidation/splitFilters.js +3 -3
  96. package/cjs/utils/settingsValidation/url.js +6 -2
  97. package/esm/evaluator/condition/index.js +2 -2
  98. package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
  99. package/esm/evaluator/index.js +80 -71
  100. package/esm/listeners/browser.js +2 -1
  101. package/esm/listeners/node.js +4 -4
  102. package/esm/logger/constants.js +12 -17
  103. package/esm/logger/messages/debug.js +5 -6
  104. package/esm/logger/messages/error.js +3 -3
  105. package/esm/logger/messages/info.js +3 -4
  106. package/esm/logger/messages/warn.js +6 -7
  107. package/esm/platform/browser.js +12 -0
  108. package/esm/platform/getEventSource/browser.js +4 -0
  109. package/esm/platform/getEventSource/eventsource.js +480 -0
  110. package/esm/platform/getEventSource/node.js +20 -0
  111. package/esm/platform/getFetch/browser.js +5 -0
  112. package/esm/platform/getFetch/node.js +22 -0
  113. package/esm/platform/getOptions/node.js +20 -0
  114. package/esm/platform/node.js +14 -0
  115. package/esm/presets/serverSide.js +2 -2
  116. package/esm/readiness/constants.js +4 -3
  117. package/esm/readiness/readinessManager.js +24 -24
  118. package/esm/readiness/sdkReadinessManager.js +2 -18
  119. package/esm/sdkClient/client.js +23 -50
  120. package/esm/sdkClient/clientInputValidation.js +8 -19
  121. package/esm/sdkClient/sdkClient.js +3 -60
  122. package/esm/sdkClient/sdkLifecycle.js +70 -0
  123. package/esm/sdkClient/trackMethod.js +52 -0
  124. package/esm/sdkFactory/index.js +12 -16
  125. package/esm/sdkManager/index.js +6 -6
  126. package/esm/services/authProvider.js +76 -0
  127. package/esm/services/decorateHeaders.js +2 -1
  128. package/esm/{sync/streaming/AuthClient/index.js → services/fetchAuth.js} +13 -13
  129. package/esm/services/secureSplitHttpClient.js +32 -0
  130. package/esm/services/serviceApi.js +143 -0
  131. package/esm/services/splitApi.js +24 -10
  132. package/esm/services/splitHttpClient.js +3 -5
  133. package/esm/storages/AbstractDefinitionsCacheAsync.js +48 -0
  134. package/esm/storages/AbstractDefinitionsCacheSync.js +71 -0
  135. package/esm/storages/KeyBuilder.js +6 -6
  136. package/esm/storages/KeyBuilderCS.js +5 -5
  137. package/esm/storages/KeyBuilderSS.js +2 -2
  138. package/esm/storages/getRolloutPlan.js +3 -3
  139. package/esm/storages/inLocalStorage/DefinitionsCacheInLocal.js +192 -0
  140. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -2
  141. package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +9 -8
  142. package/esm/storages/inLocalStorage/index.js +6 -6
  143. package/esm/storages/inLocalStorage/validateCache.js +3 -3
  144. package/esm/storages/inMemory/DefinitionsCacheInMemory.js +119 -0
  145. package/esm/storages/inMemory/InMemoryStorage.js +4 -4
  146. package/esm/storages/inMemory/InMemoryStorageCS.js +5 -5
  147. package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +4 -3
  148. package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  149. package/esm/storages/inMemory/TelemetryCacheInMemory.js +5 -5
  150. package/esm/storages/inRedis/{SplitsCacheInRedis.js → DefinitionsCacheInRedis.js} +78 -76
  151. package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +4 -2
  152. package/esm/storages/inRedis/index.js +2 -2
  153. package/esm/storages/pluggable/DefinitionsCachePluggable.js +211 -0
  154. package/esm/storages/pluggable/RBSegmentsCachePluggable.js +4 -2
  155. package/esm/storages/pluggable/index.js +2 -2
  156. package/esm/storages/setRolloutPlan.js +4 -4
  157. package/esm/storages/utils.js +1 -0
  158. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +6 -6
  159. package/esm/sync/polling/fetchers/splitChangesFetcher.js +25 -16
  160. package/esm/sync/polling/pollingManagerCS.js +87 -82
  161. package/esm/sync/polling/pollingManagerSS.js +44 -36
  162. package/esm/sync/polling/syncTasks/definitionsSyncTask.js +9 -0
  163. package/esm/sync/polling/syncTasks/segmentsSyncTask.js +2 -3
  164. package/esm/sync/polling/updaters/definitionChangesUpdater.js +201 -0
  165. package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  166. package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
  167. package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +2 -2
  168. package/esm/sync/streaming/SSEHandler/index.js +3 -2
  169. package/esm/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +19 -20
  170. package/esm/sync/streaming/constants.js +3 -2
  171. package/esm/sync/streaming/parseUtils.js +11 -11
  172. package/esm/sync/streaming/pushManager.js +24 -28
  173. package/esm/sync/submitters/eventsSubmitter.js +1 -1
  174. package/esm/sync/submitters/impressionCountsSubmitter.js +1 -1
  175. package/esm/sync/submitters/impressionsSubmitter.js +5 -4
  176. package/esm/sync/submitters/telemetrySubmitter.js +3 -4
  177. package/esm/sync/submitters/uniqueKeysSubmitter.js +1 -1
  178. package/esm/sync/syncManagerOnline.js +4 -4
  179. package/esm/utils/Backoff.js +35 -3
  180. package/esm/utils/EventEmitter.js +387 -0
  181. package/esm/utils/filter/bloomFilter.js +33 -0
  182. package/esm/utils/inputValidation/{split.js → definition.js} +8 -8
  183. package/esm/utils/inputValidation/definitionExistence.js +15 -0
  184. package/esm/utils/inputValidation/definitions.js +21 -0
  185. package/esm/utils/inputValidation/index.js +3 -3
  186. package/esm/utils/inputValidation/isOperational.js +4 -4
  187. package/esm/utils/inputValidation/target.js +18 -0
  188. package/esm/utils/labels/index.js +2 -2
  189. package/esm/utils/settingsValidation/index.js +2 -0
  190. package/esm/utils/settingsValidation/splitFilters.js +3 -3
  191. package/esm/utils/settingsValidation/url.js +6 -2
  192. package/package.json +1 -1
  193. package/src/dtos/types.ts +4 -4
  194. package/src/services/authProvider.ts +2 -2
  195. package/src/{sync/streaming/AuthClient/index.ts → services/fetchAuth.ts} +3 -4
  196. package/src/services/splitApi.ts +1 -1
  197. package/src/services/types.ts +21 -4
  198. package/src/storages/AbstractDefinitionsCacheAsync.ts +3 -3
  199. package/src/storages/AbstractDefinitionsCacheSync.ts +2 -2
  200. package/src/storages/inLocalStorage/DefinitionsCacheInLocal.ts +2 -2
  201. package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +3 -3
  202. package/src/storages/inMemory/DefinitionsCacheInMemory.ts +2 -2
  203. package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +2 -2
  204. package/src/storages/inRedis/DefinitionsCacheInRedis.ts +6 -4
  205. package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +7 -5
  206. package/src/storages/pluggable/DefinitionsCachePluggable.ts +4 -2
  207. package/src/storages/pluggable/RBSegmentsCachePluggable.ts +5 -3
  208. package/src/storages/types.ts +6 -6
  209. package/src/sync/polling/fetchers/splitChangesFetcher.ts +5 -5
  210. package/src/sync/polling/types.ts +22 -1
  211. package/src/sync/polling/updaters/definitionChangesUpdater.ts +26 -20
  212. package/src/sync/streaming/SSEClient/index.ts +1 -1
  213. package/src/sync/streaming/SSEClient/types.ts +1 -1
  214. package/src/sync/streaming/UpdateWorkers/DefinitionsUpdateWorker.ts +15 -11
  215. package/src/sync/streaming/UpdateWorkers/types.ts +6 -0
  216. package/src/sync/streaming/parseUtils.ts +3 -4
  217. package/src/sync/streaming/pushManager.ts +4 -3
  218. package/cjs/storages/AbstractSplitsCacheAsync.js +0 -51
  219. package/cjs/storages/AbstractSplitsCacheSync.js +0 -76
  220. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +0 -194
  221. package/cjs/storages/inMemory/SplitsCacheInMemory.js +0 -121
  222. package/cjs/storages/pluggable/SplitsCachePluggable.js +0 -212
  223. package/cjs/sync/polling/syncTasks/splitsSyncTask.js +0 -13
  224. package/cjs/sync/polling/updaters/splitChangesUpdater.js +0 -200
  225. package/cjs/sync/streaming/AuthClient/types.js +0 -2
  226. package/cjs/utils/inputValidation/splits.js +0 -25
  227. package/esm/storages/AbstractSplitsCacheAsync.js +0 -48
  228. package/esm/storages/AbstractSplitsCacheSync.js +0 -71
  229. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +0 -191
  230. package/esm/storages/inMemory/SplitsCacheInMemory.js +0 -118
  231. package/esm/storages/pluggable/SplitsCachePluggable.js +0 -209
  232. package/esm/sync/polling/syncTasks/splitsSyncTask.js +0 -9
  233. package/esm/sync/polling/updaters/splitChangesUpdater.js +0 -194
  234. package/esm/sync/streaming/AuthClient/types.js +0 -1
  235. package/esm/utils/inputValidation/splitExistence.js +0 -15
  236. package/esm/utils/inputValidation/splits.js +0 -21
  237. package/src/sync/streaming/AuthClient/types.ts +0 -19
@@ -1,7 +1,7 @@
1
1
  import { __extends, __spreadArray } from "tslib";
2
2
  import { isFiniteNumber, isNaNNumber } from '../../utils/lang';
3
3
  import { LOG_PREFIX } from './constants';
4
- import { AbstractSplitsCacheAsync } from '../AbstractSplitsCacheAsync';
4
+ import { AbstractDefinitionsCacheAsync } from '../AbstractDefinitionsCacheAsync';
5
5
  import { returnDifference } from '../../utils/lang/sets';
6
6
  /**
7
7
  * Discard errors for an answer of multiple operations.
@@ -14,17 +14,17 @@ function processPipelineAnswer(results) {
14
14
  }, []) : [];
15
15
  }
16
16
  /**
17
- * ISplitsCacheAsync implementation that stores split definitions in Redis.
17
+ * IDefinitionsCacheAsync implementation that stores definitions in Redis.
18
18
  * Supported by Node.js
19
19
  */
20
- var SplitsCacheInRedis = /** @class */ (function (_super) {
21
- __extends(SplitsCacheInRedis, _super);
22
- function SplitsCacheInRedis(log, keys, redis, splitFiltersValidation) {
20
+ var DefinitionsCacheInRedis = /** @class */ (function (_super) {
21
+ __extends(DefinitionsCacheInRedis, _super);
22
+ function DefinitionsCacheInRedis(log, keys, redis, splitFiltersValidation) {
23
23
  var _this = _super.call(this) || this;
24
24
  _this.log = log;
25
25
  _this.redis = redis;
26
26
  _this.keys = keys;
27
- _this.flagSetsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
27
+ _this.setsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
28
28
  // There is no need to listen for redis 'error' event, because in that case ioredis calls will be rejected and handled by redis storage adapters.
29
29
  // But it is done just to avoid getting the ioredis message `Unhandled error event`.
30
30
  _this.redis.on('error', function (e) {
@@ -35,104 +35,106 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
35
35
  });
36
36
  return _this;
37
37
  }
38
- SplitsCacheInRedis.prototype._decrementCounts = function (split) {
38
+ DefinitionsCacheInRedis.prototype._decrementCounts = function (definition) {
39
39
  var _this = this;
40
- var ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
40
+ var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
41
41
  return this.redis.decr(ttKey).then(function (count) {
42
42
  if (count === 0)
43
43
  return _this.redis.del(ttKey);
44
44
  });
45
45
  };
46
- SplitsCacheInRedis.prototype._incrementCounts = function (split) {
47
- var ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
46
+ DefinitionsCacheInRedis.prototype._incrementCounts = function (definition) {
47
+ var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
48
48
  return this.redis.incr(ttKey);
49
49
  };
50
- SplitsCacheInRedis.prototype._updateFlagSets = function (featureFlagName, flagSetsOfRemovedFlag, flagSetsOfAddedFlag) {
50
+ DefinitionsCacheInRedis.prototype._updateSets = function (definitionName, setsOfRemovedDefinition, setsOfAddedDefinition) {
51
51
  var _this = this;
52
- var removeFromFlagSets = returnDifference(flagSetsOfRemovedFlag, flagSetsOfAddedFlag);
53
- var addToFlagSets = returnDifference(flagSetsOfAddedFlag, flagSetsOfRemovedFlag);
54
- if (this.flagSetsFilter.length > 0) {
55
- addToFlagSets = addToFlagSets.filter(function (flagSet) {
56
- return _this.flagSetsFilter.some(function (filterFlagSet) { return filterFlagSet === flagSet; });
52
+ var removeFromSets = returnDifference(setsOfRemovedDefinition, setsOfAddedDefinition);
53
+ var addToSets = returnDifference(setsOfAddedDefinition, setsOfRemovedDefinition);
54
+ if (this.setsFilter.length > 0) {
55
+ addToSets = addToSets.filter(function (set) {
56
+ return _this.setsFilter.some(function (filterSet) { return filterSet === set; });
57
57
  });
58
58
  }
59
- var items = [featureFlagName];
60
- return Promise.all(__spreadArray(__spreadArray([], removeFromFlagSets.map(function (flagSetName) { return _this.redis.srem(_this.keys.buildFlagSetKey(flagSetName), items); }), true), addToFlagSets.map(function (flagSetName) { return _this.redis.sadd(_this.keys.buildFlagSetKey(flagSetName), items); }), true));
59
+ var items = [definitionName];
60
+ return Promise.all(__spreadArray(__spreadArray([], removeFromSets.map(function (setName) { return _this.redis.srem(_this.keys.buildSetKey(setName), items); }), true), addToSets.map(function (setName) { return _this.redis.sadd(_this.keys.buildSetKey(setName), items); }), true));
61
61
  };
62
62
  /**
63
- * Add a given split.
63
+ * Add a given definition.
64
64
  * The returned promise is resolved when the operation success
65
65
  * or rejected if it fails (e.g., redis operation fails)
66
66
  */
67
- SplitsCacheInRedis.prototype.addSplit = function (split) {
67
+ DefinitionsCacheInRedis.prototype.add = function (definition) {
68
68
  var _this = this;
69
- var name = split.name;
70
- var splitKey = this.keys.buildSplitKey(name);
71
- return this.redis.get(splitKey).then(function (splitFromStorage) {
69
+ var name = definition.name;
70
+ var definitionKey = this.keys.buildDefinitionKey(name);
71
+ return this.redis.get(definitionKey).then(function (definitionFromStorage) {
72
72
  // handling parsing error
73
- var parsedPreviousSplit, stringifiedNewSplit;
73
+ var parsedPreviousDefinition, stringifiedNewDefinition;
74
74
  try {
75
- parsedPreviousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : undefined;
76
- stringifiedNewSplit = JSON.stringify(split);
75
+ parsedPreviousDefinition = definitionFromStorage ? JSON.parse(definitionFromStorage) : undefined;
76
+ stringifiedNewDefinition = JSON.stringify(definition);
77
77
  }
78
78
  catch (e) {
79
79
  throw new Error('Error parsing feature flag definition: ' + e);
80
80
  }
81
- return _this.redis.set(splitKey, stringifiedNewSplit).then(function () {
81
+ return _this.redis.set(definitionKey, stringifiedNewDefinition).then(function () {
82
82
  // avoid unnecessary increment/decrement operations
83
- if (parsedPreviousSplit && parsedPreviousSplit.trafficTypeName === split.trafficTypeName)
83
+ if (parsedPreviousDefinition && parsedPreviousDefinition.trafficTypeName === definition.trafficTypeName)
84
84
  return;
85
85
  // update traffic type counts
86
- return _this._incrementCounts(split).then(function () {
87
- if (parsedPreviousSplit)
88
- return _this._decrementCounts(parsedPreviousSplit);
86
+ return _this._incrementCounts(definition).then(function () {
87
+ if (parsedPreviousDefinition)
88
+ return _this._decrementCounts(parsedPreviousDefinition);
89
89
  });
90
- }).then(function () { return _this._updateFlagSets(name, parsedPreviousSplit && parsedPreviousSplit.sets, split.sets); });
90
+ }).then(function () { return _this._updateSets(name, parsedPreviousDefinition && parsedPreviousDefinition.sets, definition.sets); });
91
91
  }).then(function () { return true; });
92
92
  };
93
93
  /**
94
- * Remove a given split.
95
- * The returned promise is resolved when the operation success, with true or false indicating if the split existed (and was removed) or not.
94
+ * Remove a given definition.
95
+ * The returned promise is resolved when the operation success, with true or false indicating if the definition existed (and was removed) or not.
96
96
  * or rejected if it fails (e.g., redis operation fails).
97
97
  */
98
- SplitsCacheInRedis.prototype.removeSplit = function (name) {
98
+ DefinitionsCacheInRedis.prototype.remove = function (name) {
99
99
  var _this = this;
100
- return this.getSplit(name).then(function (split) {
101
- if (split) {
102
- return _this._decrementCounts(split).then(function () { return _this._updateFlagSets(name, split.sets); });
100
+ return this.get(name).then(function (definition) {
101
+ if (definition) {
102
+ return _this._decrementCounts(definition).then(function () { return _this._updateSets(name, definition.sets); });
103
103
  }
104
104
  }).then(function () {
105
- return _this.redis.del(_this.keys.buildSplitKey(name)).then(function (status) { return status === 1; });
105
+ return _this.redis.del(_this.keys.buildDefinitionKey(name)).then(function (status) { return status === 1; });
106
106
  });
107
107
  };
108
108
  /**
109
- * Get split definition or null if it's not defined.
109
+ * Get definition or null if it's not defined.
110
110
  * Returned promise is rejected if redis operation fails.
111
111
  */
112
- SplitsCacheInRedis.prototype.getSplit = function (name) {
112
+ DefinitionsCacheInRedis.prototype.get = function (name) {
113
113
  if (this.redisError) {
114
114
  this.log.error(LOG_PREFIX + this.redisError);
115
115
  return Promise.reject(this.redisError);
116
116
  }
117
- return this.redis.get(this.keys.buildSplitKey(name))
118
- .then(function (maybeSplit) { return maybeSplit && JSON.parse(maybeSplit); });
117
+ return this.redis.get(this.keys.buildDefinitionKey(name))
118
+ .then(function (maybeDefinition) { return maybeDefinition && JSON.parse(maybeDefinition); });
119
119
  };
120
120
  /**
121
121
  * Set till number.
122
122
  * The returned promise is resolved when the operation success,
123
123
  * or rejected if it fails.
124
124
  */
125
- SplitsCacheInRedis.prototype.setChangeNumber = function (changeNumber) {
126
- return this.redis.set(this.keys.buildSplitsTillKey(), changeNumber + '').then(function (status) { return status === 'OK'; });
125
+ DefinitionsCacheInRedis.prototype.setChangeNumber = function (changeNumber) {
126
+ if (changeNumber !== undefined) {
127
+ return this.redis.set(this.keys.buildDefinitionsTillKey(), changeNumber + '').then(function (status) { return status === 'OK'; });
128
+ }
127
129
  };
128
130
  /**
129
131
  * Get till number or -1 if it's not defined.
130
132
  * The returned promise is resolved with the changeNumber or -1 if it doesn't exist or a redis operation fails.
131
133
  * The promise will never be rejected.
132
134
  */
133
- SplitsCacheInRedis.prototype.getChangeNumber = function () {
135
+ DefinitionsCacheInRedis.prototype.getChangeNumber = function () {
134
136
  var _this = this;
135
- return this.redis.get(this.keys.buildSplitsTillKey()).then(function (value) {
137
+ return this.redis.get(this.keys.buildDefinitionsTillKey()).then(function (value) {
136
138
  var i = parseInt(value, 10);
137
139
  return isNaNNumber(i) ? -1 : i;
138
140
  }).catch(function (e) {
@@ -141,44 +143,44 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
141
143
  });
142
144
  };
143
145
  /**
144
- * Get list of all split definitions.
145
- * The returned promise is resolved with the list of split definitions,
146
+ * Get list of all definitions.
147
+ * The returned promise is resolved with the list of definitions,
146
148
  * or rejected if redis operation fails.
147
149
  */
148
150
  // @TODO we need to benchmark which is the maximun number of commands we could pipeline without kill redis performance.
149
- SplitsCacheInRedis.prototype.getAll = function () {
151
+ DefinitionsCacheInRedis.prototype.getAll = function () {
150
152
  var _this = this;
151
- return this.redis.keys(this.keys.searchPatternForSplitKeys())
153
+ return this.redis.keys(this.keys.searchPatternForDefinitionKeys())
152
154
  .then(function (listOfKeys) { return _this.redis.pipeline(listOfKeys.map(function (k) { return ['get', k]; })).exec(); })
153
155
  .then(processPipelineAnswer)
154
- .then(function (splitDefinitions) { return splitDefinitions.map(function (splitDefinition) {
155
- return JSON.parse(splitDefinition);
156
+ .then(function (definitions) { return definitions.map(function (definition) {
157
+ return JSON.parse(definition);
156
158
  }); });
157
159
  };
158
160
  /**
159
- * Get list of split names.
160
- * The returned promise is resolved with the list of split names,
161
+ * Get list of definition names.
162
+ * The returned promise is resolved with the list of names,
161
163
  * or rejected if redis operation fails.
162
164
  */
163
- SplitsCacheInRedis.prototype.getSplitNames = function () {
165
+ DefinitionsCacheInRedis.prototype.getNames = function () {
164
166
  var _this = this;
165
- return this.redis.keys(this.keys.searchPatternForSplitKeys()).then(function (listOfKeys) { return listOfKeys.map(_this.keys.extractKey); });
167
+ return this.redis.keys(this.keys.searchPatternForDefinitionKeys()).then(function (listOfKeys) { return listOfKeys.map(_this.keys.extractKey); });
166
168
  };
167
169
  /**
168
- * Get list of feature flag names related to a given list of flag set names.
169
- * The returned promise is resolved with the list of feature flag names per flag set,
170
+ * Get list of definition names related to a given list of set names.
171
+ * The returned promise is resolved with the list of names per set,
170
172
  * or rejected if the pipelined redis operation fails (e.g., timeout).
171
173
  */
172
- SplitsCacheInRedis.prototype.getNamesByFlagSets = function (flagSets) {
174
+ DefinitionsCacheInRedis.prototype.getNamesBySets = function (sets) {
173
175
  var _this = this;
174
- return this.redis.pipeline(flagSets.map(function (flagSet) { return ['smembers', _this.keys.buildFlagSetKey(flagSet)]; })).exec()
176
+ return this.redis.pipeline(sets.map(function (set) { return ['smembers', _this.keys.buildSetKey(set)]; })).exec()
175
177
  .then(function (results) { return results ? results.map(function (_a, index) {
176
178
  var e = _a[0], value = _a[1];
177
179
  if (e === null)
178
180
  return value;
179
- _this.log.error(LOG_PREFIX + "Could not read result from get members of flag set ".concat(flagSets[index], " due to an error: ").concat(e));
181
+ _this.log.error(LOG_PREFIX + "Could not read result from get members of set ".concat(sets[index], " due to an error: ").concat(e));
180
182
  }) : []; })
181
- .then(function (namesByFlagSets) { return namesByFlagSets.map(function (namesByFlagSet) { return new Set(namesByFlagSet); }); });
183
+ .then(function (namesBySets) { return namesBySets.map(function (namesBySet) { return new Set(namesBySet); }); });
182
184
  };
183
185
  /**
184
186
  * Check traffic type existence.
@@ -186,7 +188,7 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
186
188
  * In case of redis operation failure, the promise resolves with a true value, assuming that the TT might exist.
187
189
  * It will never be rejected.
188
190
  */
189
- SplitsCacheInRedis.prototype.trafficTypeExists = function (trafficType) {
191
+ DefinitionsCacheInRedis.prototype.trafficTypeExists = function (trafficType) {
190
192
  var _this = this;
191
193
  // If there is a number there should be > 0, otherwise the TT is considered as not existent.
192
194
  return this.redis.get(this.keys.buildTrafficTypeKey(trafficType))
@@ -207,34 +209,34 @@ var SplitsCacheInRedis = /** @class */ (function (_super) {
207
209
  });
208
210
  };
209
211
  // @TODO remove or implement. It is not being used.
210
- SplitsCacheInRedis.prototype.clear = function () {
212
+ DefinitionsCacheInRedis.prototype.clear = function () {
211
213
  return Promise.resolve();
212
214
  };
213
215
  /**
214
- * Fetches multiple splits definitions.
216
+ * Fetches multiple definitions.
215
217
  * Returned promise is rejected if redis operation fails.
216
218
  */
217
- SplitsCacheInRedis.prototype.getSplits = function (names) {
219
+ DefinitionsCacheInRedis.prototype.getMany = function (names) {
218
220
  var _a;
219
221
  var _this = this;
220
222
  if (this.redisError) {
221
223
  this.log.error(LOG_PREFIX + this.redisError);
222
224
  return Promise.reject(this.redisError);
223
225
  }
224
- var keys = names.map(function (name) { return _this.keys.buildSplitKey(name); });
225
- return (_a = this.redis).mget.apply(_a, keys).then(function (splitDefinitions) {
226
- var splits = {};
226
+ var keys = names.map(function (name) { return _this.keys.buildDefinitionKey(name); });
227
+ return (_a = this.redis).mget.apply(_a, keys).then(function (stringifiedDefinitions) {
228
+ var definitions = {};
227
229
  names.forEach(function (name, idx) {
228
- var split = splitDefinitions[idx];
229
- splits[name] = split && JSON.parse(split);
230
+ var definition = stringifiedDefinitions[idx];
231
+ definitions[name] = definition && JSON.parse(definition);
230
232
  });
231
- return Promise.resolve(splits);
233
+ return Promise.resolve(definitions);
232
234
  })
233
235
  .catch(function (e) {
234
236
  _this.log.error(LOG_PREFIX + "Could not grab feature flags due to an error: ".concat(e, "."));
235
237
  return Promise.reject(e);
236
238
  });
237
239
  };
238
- return SplitsCacheInRedis;
239
- }(AbstractSplitsCacheAsync));
240
- export { SplitsCacheInRedis };
240
+ return DefinitionsCacheInRedis;
241
+ }(AbstractDefinitionsCacheAsync));
242
+ export { DefinitionsCacheInRedis };
@@ -31,7 +31,7 @@ var RBSegmentsCacheInRedis = /** @class */ (function () {
31
31
  return _this.redis.set(key, stringifiedNewRBSegment).then(function () { return true; });
32
32
  })),
33
33
  Promise.all(toRemove.map(function (toRemove) {
34
- var key = _this.keys.buildRBSegmentKey(toRemove.name);
34
+ var key = _this.keys.buildRBSegmentKey(toRemove);
35
35
  return _this.redis.del(key).then(function (status) { return status === 1; });
36
36
  }))
37
37
  ]).then(function (_a) {
@@ -40,7 +40,9 @@ var RBSegmentsCacheInRedis = /** @class */ (function () {
40
40
  });
41
41
  };
42
42
  RBSegmentsCacheInRedis.prototype.setChangeNumber = function (changeNumber) {
43
- return this.redis.set(this.keys.buildRBSegmentsTillKey(), changeNumber + '').then(function (status) { return status === 'OK'; });
43
+ if (changeNumber !== undefined) {
44
+ return this.redis.set(this.keys.buildRBSegmentsTillKey(), changeNumber + '').then(function (status) { return status === 'OK'; });
45
+ }
44
46
  };
45
47
  RBSegmentsCacheInRedis.prototype.getChangeNumber = function () {
46
48
  var _this = this;
@@ -1,6 +1,6 @@
1
1
  import { validatePrefix } from '../KeyBuilder';
2
2
  import { KeyBuilderSS } from '../KeyBuilderSS';
3
- import { SplitsCacheInRedis } from './SplitsCacheInRedis';
3
+ import { DefinitionsCacheInRedis } from './DefinitionsCacheInRedis';
4
4
  import { SegmentsCacheInRedis } from './SegmentsCacheInRedis';
5
5
  import { ImpressionsCacheInRedis } from './ImpressionsCacheInRedis';
6
6
  import { EventsCacheInRedis } from './EventsCacheInRedis';
@@ -45,7 +45,7 @@ export function InRedisStorage(options) {
45
45
  telemetry.recordConfig();
46
46
  });
47
47
  return {
48
- splits: new SplitsCacheInRedis(log, keys, redisClient, settings.sync.__splitFiltersValidation),
48
+ definitions: new DefinitionsCacheInRedis(log, keys, redisClient, settings.sync.__splitFiltersValidation),
49
49
  rbSegments: new RBSegmentsCacheInRedis(log, keys, redisClient),
50
50
  segments: new SegmentsCacheInRedis(log, keys, redisClient),
51
51
  impressions: new ImpressionsCacheInRedis(log, keys.buildImpressionsKey(), redisClient, metadata),
@@ -0,0 +1,211 @@
1
+ import { __extends, __spreadArray } from "tslib";
2
+ import { isFiniteNumber, isNaNNumber } from '../../utils/lang';
3
+ import { LOG_PREFIX } from './constants';
4
+ import { AbstractDefinitionsCacheAsync } from '../AbstractDefinitionsCacheAsync';
5
+ import { returnDifference } from '../../utils/lang/sets';
6
+ /**
7
+ * IDefinitionsCacheAsync implementation for pluggable storages.
8
+ */
9
+ var DefinitionsCachePluggable = /** @class */ (function (_super) {
10
+ __extends(DefinitionsCachePluggable, _super);
11
+ /**
12
+ * Create a DefinitionsCache that uses a storage wrapper.
13
+ * @param log - Logger instance.
14
+ * @param keys - Key builder.
15
+ * @param wrapper - Adapted wrapper storage.
16
+ */
17
+ function DefinitionsCachePluggable(log, keys, wrapper, splitFiltersValidation) {
18
+ var _this = _super.call(this) || this;
19
+ _this.log = log;
20
+ _this.keys = keys;
21
+ _this.wrapper = wrapper;
22
+ _this.setsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
23
+ return _this;
24
+ }
25
+ DefinitionsCachePluggable.prototype._decrementCounts = function (definition) {
26
+ var _this = this;
27
+ var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
28
+ return this.wrapper.decr(ttKey).then(function (count) {
29
+ if (count === 0)
30
+ return _this.wrapper.del(ttKey);
31
+ });
32
+ };
33
+ DefinitionsCachePluggable.prototype._incrementCounts = function (definition) {
34
+ var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
35
+ return this.wrapper.incr(ttKey);
36
+ };
37
+ DefinitionsCachePluggable.prototype._updateSets = function (definitionName, setsOfRemovedDefinition, setsOfAddedDefinition) {
38
+ var _this = this;
39
+ var removeFromSets = returnDifference(setsOfRemovedDefinition, setsOfAddedDefinition);
40
+ var addToSets = returnDifference(setsOfAddedDefinition, setsOfRemovedDefinition);
41
+ if (this.setsFilter.length > 0) {
42
+ addToSets = addToSets.filter(function (set) {
43
+ return _this.setsFilter.some(function (filterSet) { return filterSet === set; });
44
+ });
45
+ }
46
+ var items = [definitionName];
47
+ return Promise.all(__spreadArray(__spreadArray([], removeFromSets.map(function (setName) { return _this.wrapper.removeItems(_this.keys.buildSetKey(setName), items); }), true), addToSets.map(function (setName) { return _this.wrapper.addItems(_this.keys.buildSetKey(setName), items); }), true));
48
+ };
49
+ /**
50
+ * Add a given definition.
51
+ * The returned promise is resolved when the operation success
52
+ * or rejected if it fails (e.g., wrapper operation fails)
53
+ */
54
+ DefinitionsCachePluggable.prototype.add = function (definition) {
55
+ var _this = this;
56
+ var name = definition.name;
57
+ var definitionKey = this.keys.buildDefinitionKey(name);
58
+ return this.wrapper.get(definitionKey).then(function (definitionFromStorage) {
59
+ // handling parsing error
60
+ var parsedPreviousDefinition, stringifiedNewDefinition;
61
+ try {
62
+ parsedPreviousDefinition = definitionFromStorage ? JSON.parse(definitionFromStorage) : undefined;
63
+ stringifiedNewDefinition = JSON.stringify(definition);
64
+ }
65
+ catch (e) {
66
+ throw new Error('Error parsing feature flag definition: ' + e);
67
+ }
68
+ return _this.wrapper.set(definitionKey, stringifiedNewDefinition).then(function () {
69
+ // avoid unnecessary increment/decrement operations
70
+ if (parsedPreviousDefinition && parsedPreviousDefinition.trafficTypeName === definition.trafficTypeName)
71
+ return;
72
+ // update traffic type counts
73
+ return _this._incrementCounts(definition).then(function () {
74
+ if (parsedPreviousDefinition)
75
+ return _this._decrementCounts(parsedPreviousDefinition);
76
+ });
77
+ }).then(function () { return _this._updateSets(name, parsedPreviousDefinition && parsedPreviousDefinition.sets, definition.sets); });
78
+ }).then(function () { return true; });
79
+ };
80
+ /**
81
+ * Remove a given definition.
82
+ * The returned promise is resolved when the operation success, with a boolean indicating if the definition existed or not.
83
+ * or rejected if it fails (e.g., wrapper operation fails).
84
+ */
85
+ DefinitionsCachePluggable.prototype.remove = function (name) {
86
+ var _this = this;
87
+ return this.get(name).then(function (definition) {
88
+ if (definition) {
89
+ return _this._decrementCounts(definition).then(function () { return _this._updateSets(name, definition.sets); });
90
+ }
91
+ }).then(function () {
92
+ return _this.wrapper.del(_this.keys.buildDefinitionKey(name));
93
+ });
94
+ };
95
+ /**
96
+ * Get definition.
97
+ * The returned promise is resolved with the definition or null if it's not defined,
98
+ * or rejected if wrapper operation fails.
99
+ */
100
+ DefinitionsCachePluggable.prototype.get = function (name) {
101
+ return this.wrapper.get(this.keys.buildDefinitionKey(name))
102
+ .then(function (maybeDefinition) { return maybeDefinition && JSON.parse(maybeDefinition); });
103
+ };
104
+ /**
105
+ * Get list of definitions.
106
+ * The returned promise is resolved with a map of names to their definition or null if it's not defined,
107
+ * or rejected if wrapper operation fails.
108
+ */
109
+ DefinitionsCachePluggable.prototype.getMany = function (names) {
110
+ var _this = this;
111
+ var keys = names.map(function (name) { return _this.keys.buildDefinitionKey(name); });
112
+ return this.wrapper.getMany(keys).then(function (stringifiedDefinitions) {
113
+ var definitions = {};
114
+ names.forEach(function (name, idx) {
115
+ var definition = stringifiedDefinitions[idx];
116
+ definitions[name] = definition && JSON.parse(definition);
117
+ });
118
+ return Promise.resolve(definitions);
119
+ });
120
+ };
121
+ /**
122
+ * Get list of all definitions.
123
+ * The returned promise is resolved with the list of definitions,
124
+ * or rejected if wrapper operation fails.
125
+ */
126
+ DefinitionsCachePluggable.prototype.getAll = function () {
127
+ var _this = this;
128
+ return this.wrapper.getKeysByPrefix(this.keys.buildDefinitionKeyPrefix())
129
+ .then(function (listOfKeys) { return _this.wrapper.getMany(listOfKeys); })
130
+ .then(function (definitions) { return definitions.map(function (definition) {
131
+ return JSON.parse(definition);
132
+ }); });
133
+ };
134
+ /**
135
+ * Get list of definition names.
136
+ * The returned promise is resolved with the list of names,
137
+ * or rejected if wrapper operation fails.
138
+ */
139
+ DefinitionsCachePluggable.prototype.getNames = function () {
140
+ var _this = this;
141
+ return this.wrapper.getKeysByPrefix(this.keys.buildDefinitionKeyPrefix()).then(function (listOfKeys) { return listOfKeys.map(_this.keys.extractKey); });
142
+ };
143
+ /**
144
+ * Get list of definition names related to a given list of set names.
145
+ * The returned promise is resolved with the list of names per set.
146
+ * It never rejects (If there is a wrapper error for some set, an empty set is returned for it).
147
+ */
148
+ DefinitionsCachePluggable.prototype.getNamesBySets = function (sets) {
149
+ var _this = this;
150
+ return Promise.all(sets.map(function (set) {
151
+ var setKey = _this.keys.buildSetKey(set);
152
+ return _this.wrapper.getItems(setKey).catch(function () { return []; });
153
+ })).then(function (namesBySets) { return namesBySets.map(function (namesBySet) { return new Set(namesBySet); }); });
154
+ };
155
+ /**
156
+ * Check traffic type existence.
157
+ * The returned promise is resolved with a boolean indicating whether the TT exist or not.
158
+ * In case of wrapper operation failures, the promise resolves with a true value, assuming that the TT might exist.
159
+ * It will never be rejected.
160
+ */
161
+ DefinitionsCachePluggable.prototype.trafficTypeExists = function (trafficType) {
162
+ var _this = this;
163
+ // If there is a number there should be > 0, otherwise the TT is considered as not existent.
164
+ return this.wrapper.get(this.keys.buildTrafficTypeKey(trafficType))
165
+ .then(function (ttCount) {
166
+ if (ttCount === null)
167
+ return false; // if entry doesn't exist, means that TT doesn't exist
168
+ ttCount = parseInt(ttCount, 10);
169
+ if (!isFiniteNumber(ttCount) || ttCount < 0) {
170
+ _this.log.info(LOG_PREFIX + "Could not validate traffic type existence of ".concat(trafficType, " due to data corruption of some sorts."));
171
+ return false;
172
+ }
173
+ return ttCount > 0;
174
+ }).catch(function (e) {
175
+ _this.log.error(LOG_PREFIX + "Could not validate traffic type existence of ".concat(trafficType, " due to an error: ").concat(e, "."));
176
+ // If there is an error, bypass the validation so the event can get tracked.
177
+ return true;
178
+ });
179
+ };
180
+ /**
181
+ * Set till number.
182
+ * The returned promise is resolved when the operation success,
183
+ * or rejected if it fails (e.g., wrapper operation fails).
184
+ */
185
+ DefinitionsCachePluggable.prototype.setChangeNumber = function (changeNumber) {
186
+ if (changeNumber !== undefined) {
187
+ return this.wrapper.set(this.keys.buildDefinitionsTillKey(), changeNumber + '');
188
+ }
189
+ };
190
+ /**
191
+ * Get till number or -1 if it's not defined.
192
+ * The returned promise is resolved with the changeNumber or -1 if it doesn't exist or a wrapper operation fails.
193
+ * The promise will never be rejected.
194
+ */
195
+ DefinitionsCachePluggable.prototype.getChangeNumber = function () {
196
+ var _this = this;
197
+ return this.wrapper.get(this.keys.buildDefinitionsTillKey()).then(function (value) {
198
+ var i = parseInt(value, 10);
199
+ return isNaNNumber(i) ? -1 : i;
200
+ }).catch(function (e) {
201
+ _this.log.error(LOG_PREFIX + 'Could not retrieve changeNumber from storage. Error: ' + e);
202
+ return -1;
203
+ });
204
+ };
205
+ // @TODO implement if required by DataLoader or producer mode
206
+ DefinitionsCachePluggable.prototype.clear = function () {
207
+ return Promise.resolve(true);
208
+ };
209
+ return DefinitionsCachePluggable;
210
+ }(AbstractDefinitionsCacheAsync));
211
+ export { DefinitionsCachePluggable };
@@ -31,7 +31,7 @@ var RBSegmentsCachePluggable = /** @class */ (function () {
31
31
  return _this.wrapper.set(key, stringifiedNewRBSegment).then(function () { return true; });
32
32
  })),
33
33
  Promise.all(toRemove.map(function (toRemove) {
34
- var key = _this.keys.buildRBSegmentKey(toRemove.name);
34
+ var key = _this.keys.buildRBSegmentKey(toRemove);
35
35
  return _this.wrapper.del(key);
36
36
  }))
37
37
  ]).then(function (_a) {
@@ -40,7 +40,9 @@ var RBSegmentsCachePluggable = /** @class */ (function () {
40
40
  });
41
41
  };
42
42
  RBSegmentsCachePluggable.prototype.setChangeNumber = function (changeNumber) {
43
- return this.wrapper.set(this.keys.buildRBSegmentsTillKey(), changeNumber + '');
43
+ if (changeNumber !== undefined) {
44
+ return this.wrapper.set(this.keys.buildRBSegmentsTillKey(), changeNumber + '');
45
+ }
44
46
  };
45
47
  RBSegmentsCachePluggable.prototype.getChangeNumber = function () {
46
48
  var _this = this;
@@ -1,6 +1,6 @@
1
1
  import { __assign } from "tslib";
2
2
  import { KeyBuilderSS } from '../KeyBuilderSS';
3
- import { SplitsCachePluggable } from './SplitsCachePluggable';
3
+ import { DefinitionsCachePluggable } from './DefinitionsCachePluggable';
4
4
  import { SegmentsCachePluggable } from './SegmentsCachePluggable';
5
5
  import { ImpressionsCachePluggable } from './ImpressionsCachePluggable';
6
6
  import { EventsCachePluggable } from './EventsCachePluggable';
@@ -103,7 +103,7 @@ export function PluggableStorage(options) {
103
103
  return e; // Propagate error for shared clients
104
104
  });
105
105
  return {
106
- splits: new SplitsCachePluggable(log, keys, wrapper, settings.sync.__splitFiltersValidation),
106
+ definitions: new DefinitionsCachePluggable(log, keys, wrapper, settings.sync.__splitFiltersValidation),
107
107
  rbSegments: new RBSegmentsCachePluggable(log, keys, wrapper),
108
108
  segments: new SegmentsCachePluggable(log, keys, wrapper),
109
109
  impressions: isPartialConsumer ? new ImpressionsCacheInMemory(impressionsQueueSize) : new ImpressionsCachePluggable(log, keys.buildImpressionsKey(), wrapper, metadata),
@@ -20,12 +20,12 @@ export function validateRolloutPlan(log, settings) {
20
20
  * Otherwise, the storage is handled as a server-side storage (segments is an instance of SegmentsCache).
21
21
  */
22
22
  export function setRolloutPlan(log, rolloutPlan, storage, matchingKey) {
23
- var splits = storage.splits, rbSegments = storage.rbSegments, segments = storage.segments, largeSegments = storage.largeSegments;
23
+ var definitions = storage.definitions, rbSegments = storage.rbSegments, segments = storage.segments, largeSegments = storage.largeSegments;
24
24
  var _a = rolloutPlan.splitChanges, ff = _a.ff, rbs = _a.rbs;
25
25
  log.debug("storage: set feature flags and segments".concat(matchingKey ? " for key ".concat(matchingKey) : ''));
26
- if (splits && ff) {
27
- splits.clear();
28
- splits.update(ff.d || [], [], ff.t);
26
+ if (definitions && ff) {
27
+ definitions.clear();
28
+ definitions.update(ff.d || [], [], ff.t);
29
29
  }
30
30
  if (rbSegments && rbs) {
31
31
  rbSegments.clear();
@@ -24,6 +24,7 @@ export function impressionsToJSON(impressions, metadata) {
24
24
  m: impression.time,
25
25
  pt: impression.pt,
26
26
  properties: impression.properties
27
+ // @TODO set entityType
27
28
  }
28
29
  };
29
30
  return JSON.stringify(impressionWithMetadata);