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

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 (241) hide show
  1. package/CHANGES.txt +10 -1
  2. package/cjs/evaluator/condition/index.js +1 -1
  3. package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +8 -5
  4. package/cjs/evaluator/index.js +69 -81
  5. package/cjs/listeners/browser.js +1 -2
  6. package/cjs/listeners/node.js +4 -4
  7. package/cjs/logger/constants.js +20 -15
  8. package/cjs/logger/messages/debug.js +6 -5
  9. package/cjs/logger/messages/error.js +3 -3
  10. package/cjs/logger/messages/info.js +4 -3
  11. package/cjs/logger/messages/warn.js +7 -6
  12. package/cjs/presets/serverSide.js +2 -2
  13. package/cjs/readiness/constants.js +4 -5
  14. package/cjs/readiness/readinessManager.js +23 -23
  15. package/cjs/readiness/sdkReadinessManager.js +17 -1
  16. package/cjs/sdkClient/client.js +34 -9
  17. package/cjs/sdkClient/clientInputValidation.js +17 -6
  18. package/cjs/sdkClient/sdkClient.js +60 -3
  19. package/cjs/sdkFactory/index.js +15 -11
  20. package/cjs/sdkManager/index.js +5 -5
  21. package/cjs/services/decorateHeaders.js +1 -2
  22. package/cjs/services/splitApi.js +1 -14
  23. package/cjs/services/splitHttpClient.js +5 -3
  24. package/cjs/storages/AbstractSplitsCacheAsync.js +51 -0
  25. package/cjs/storages/AbstractSplitsCacheSync.js +76 -0
  26. package/cjs/storages/KeyBuilder.js +6 -6
  27. package/cjs/storages/KeyBuilderCS.js +5 -5
  28. package/cjs/storages/KeyBuilderSS.js +2 -2
  29. package/cjs/storages/getRolloutPlan.js +3 -3
  30. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +2 -1
  31. package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +10 -10
  32. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +194 -0
  33. package/cjs/storages/inLocalStorage/index.js +6 -6
  34. package/cjs/storages/inLocalStorage/validateCache.js +3 -3
  35. package/cjs/storages/inMemory/InMemoryStorage.js +4 -4
  36. package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -5
  37. package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +5 -5
  38. package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  39. package/cjs/storages/inMemory/SplitsCacheInMemory.js +121 -0
  40. package/cjs/storages/inMemory/TelemetryCacheInMemory.js +5 -5
  41. package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
  42. package/cjs/storages/inRedis/RedisAdapter.js +8 -5
  43. package/cjs/storages/inRedis/{DefinitionsCacheInRedis.js → SplitsCacheInRedis.js} +77 -77
  44. package/cjs/storages/inRedis/index.js +2 -2
  45. package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
  46. package/cjs/storages/pluggable/SplitsCachePluggable.js +212 -0
  47. package/cjs/storages/pluggable/index.js +2 -2
  48. package/cjs/storages/setRolloutPlan.js +4 -4
  49. package/cjs/storages/utils.js +0 -1
  50. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +5 -5
  51. package/cjs/sync/polling/fetchers/splitChangesFetcher.js +15 -24
  52. package/cjs/sync/polling/pollingManagerCS.js +20 -20
  53. package/cjs/sync/polling/pollingManagerSS.js +15 -15
  54. package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +3 -2
  55. package/cjs/sync/polling/syncTasks/splitsSyncTask.js +13 -0
  56. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  57. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
  58. package/cjs/sync/polling/updaters/{definitionChangesUpdater.js → splitChangesUpdater.js} +68 -65
  59. package/cjs/sync/streaming/AuthClient/index.js +1 -1
  60. package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +1 -1
  61. package/cjs/sync/streaming/SSEHandler/index.js +1 -1
  62. package/cjs/sync/streaming/UpdateWorkers/{DefinitionsUpdateWorker.js → SplitsUpdateWorker.js} +19 -16
  63. package/cjs/sync/streaming/constants.js +3 -3
  64. package/cjs/sync/streaming/parseUtils.js +11 -11
  65. package/cjs/sync/streaming/pushManager.js +16 -16
  66. package/cjs/sync/submitters/eventsSubmitter.js +1 -1
  67. package/cjs/sync/submitters/impressionCountsSubmitter.js +1 -1
  68. package/cjs/sync/submitters/impressionsSubmitter.js +4 -5
  69. package/cjs/sync/submitters/telemetrySubmitter.js +4 -3
  70. package/cjs/sync/submitters/uniqueKeysSubmitter.js +1 -1
  71. package/cjs/sync/syncManagerOnline.js +7 -12
  72. package/cjs/utils/Backoff.js +0 -20
  73. package/cjs/utils/inputValidation/index.js +7 -7
  74. package/cjs/utils/inputValidation/isOperational.js +4 -4
  75. package/cjs/utils/inputValidation/{definition.js → split.js} +10 -10
  76. package/cjs/utils/inputValidation/{definitionExistence.js → splitExistence.js} +6 -6
  77. package/cjs/utils/inputValidation/splits.js +25 -0
  78. package/cjs/utils/labels/index.js +3 -3
  79. package/cjs/utils/settingsValidation/index.js +0 -2
  80. package/cjs/utils/settingsValidation/splitFilters.js +3 -3
  81. package/cjs/utils/settingsValidation/url.js +2 -6
  82. package/esm/evaluator/condition/index.js +1 -1
  83. package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +8 -5
  84. package/esm/evaluator/index.js +69 -80
  85. package/esm/listeners/browser.js +1 -2
  86. package/esm/listeners/node.js +4 -4
  87. package/esm/logger/constants.js +17 -12
  88. package/esm/logger/messages/debug.js +6 -5
  89. package/esm/logger/messages/error.js +3 -3
  90. package/esm/logger/messages/info.js +4 -3
  91. package/esm/logger/messages/warn.js +7 -6
  92. package/esm/presets/serverSide.js +2 -2
  93. package/esm/readiness/constants.js +3 -4
  94. package/esm/readiness/readinessManager.js +24 -24
  95. package/esm/readiness/sdkReadinessManager.js +18 -2
  96. package/esm/sdkClient/client.js +35 -9
  97. package/esm/sdkClient/clientInputValidation.js +19 -8
  98. package/esm/sdkClient/sdkClient.js +60 -3
  99. package/esm/sdkFactory/index.js +16 -12
  100. package/esm/sdkManager/index.js +6 -6
  101. package/esm/services/decorateHeaders.js +1 -2
  102. package/esm/services/splitApi.js +1 -14
  103. package/esm/services/splitHttpClient.js +5 -3
  104. package/esm/storages/AbstractSplitsCacheAsync.js +48 -0
  105. package/esm/storages/AbstractSplitsCacheSync.js +71 -0
  106. package/esm/storages/KeyBuilder.js +6 -6
  107. package/esm/storages/KeyBuilderCS.js +5 -5
  108. package/esm/storages/KeyBuilderSS.js +2 -2
  109. package/esm/storages/getRolloutPlan.js +3 -3
  110. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +2 -1
  111. package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +7 -7
  112. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +191 -0
  113. package/esm/storages/inLocalStorage/index.js +6 -6
  114. package/esm/storages/inLocalStorage/validateCache.js +3 -3
  115. package/esm/storages/inMemory/InMemoryStorage.js +4 -4
  116. package/esm/storages/inMemory/InMemoryStorageCS.js +5 -5
  117. package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +2 -2
  118. package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  119. package/esm/storages/inMemory/SplitsCacheInMemory.js +118 -0
  120. package/esm/storages/inMemory/TelemetryCacheInMemory.js +5 -5
  121. package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
  122. package/esm/storages/inRedis/RedisAdapter.js +8 -5
  123. package/esm/storages/inRedis/{DefinitionsCacheInRedis.js → SplitsCacheInRedis.js} +76 -76
  124. package/esm/storages/inRedis/index.js +2 -2
  125. package/esm/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
  126. package/esm/storages/pluggable/SplitsCachePluggable.js +209 -0
  127. package/esm/storages/pluggable/index.js +2 -2
  128. package/esm/storages/setRolloutPlan.js +4 -4
  129. package/esm/storages/utils.js +0 -1
  130. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +6 -6
  131. package/esm/sync/polling/fetchers/splitChangesFetcher.js +16 -25
  132. package/esm/sync/polling/pollingManagerCS.js +17 -17
  133. package/esm/sync/polling/pollingManagerSS.js +15 -15
  134. package/esm/sync/polling/syncTasks/segmentsSyncTask.js +3 -2
  135. package/esm/sync/polling/syncTasks/splitsSyncTask.js +9 -0
  136. package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  137. package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
  138. package/esm/sync/polling/updaters/{definitionChangesUpdater.js → splitChangesUpdater.js} +68 -65
  139. package/esm/sync/streaming/AuthClient/index.js +1 -1
  140. package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +2 -2
  141. package/esm/sync/streaming/SSEHandler/index.js +2 -2
  142. package/esm/sync/streaming/UpdateWorkers/{DefinitionsUpdateWorker.js → SplitsUpdateWorker.js} +18 -15
  143. package/esm/sync/streaming/constants.js +2 -2
  144. package/esm/sync/streaming/parseUtils.js +9 -9
  145. package/esm/sync/streaming/pushManager.js +18 -18
  146. package/esm/sync/submitters/eventsSubmitter.js +1 -1
  147. package/esm/sync/submitters/impressionCountsSubmitter.js +1 -1
  148. package/esm/sync/submitters/impressionsSubmitter.js +4 -5
  149. package/esm/sync/submitters/telemetrySubmitter.js +4 -3
  150. package/esm/sync/submitters/uniqueKeysSubmitter.js +1 -1
  151. package/esm/sync/syncManagerOnline.js +6 -11
  152. package/esm/utils/Backoff.js +0 -20
  153. package/esm/utils/inputValidation/index.js +3 -3
  154. package/esm/utils/inputValidation/isOperational.js +4 -4
  155. package/esm/utils/inputValidation/{definition.js → split.js} +8 -8
  156. package/esm/utils/inputValidation/splitExistence.js +15 -0
  157. package/esm/utils/inputValidation/splits.js +21 -0
  158. package/esm/utils/labels/index.js +2 -2
  159. package/esm/utils/settingsValidation/index.js +0 -2
  160. package/esm/utils/settingsValidation/splitFilters.js +3 -3
  161. package/esm/utils/settingsValidation/url.js +2 -6
  162. package/package.json +6 -7
  163. package/src/dtos/types.ts +1 -1
  164. package/src/evaluator/Engine.ts +3 -3
  165. package/src/evaluator/condition/index.ts +2 -2
  166. package/src/evaluator/index.ts +27 -35
  167. package/src/evaluator/types.ts +2 -6
  168. package/src/presets/serverSide.ts +3 -3
  169. package/src/sdkClient/client.ts +22 -24
  170. package/src/sdkClient/sdkLifecycle.ts +3 -0
  171. package/src/services/authProvider.ts +41 -19
  172. package/src/services/secureSplitHttpClient.ts +10 -18
  173. package/src/services/serviceApi.ts +27 -24
  174. package/src/services/splitApi.ts +10 -9
  175. package/src/services/types.ts +5 -4
  176. package/src/storages/inRedis/RedisAdapter.ts +8 -5
  177. package/src/sync/polling/pollingManagerCS.ts +80 -78
  178. package/src/sync/polling/pollingManagerSS.ts +49 -45
  179. package/src/sync/polling/updaters/definitionChangesUpdater.ts +3 -3
  180. package/src/sync/polling/updaters/segmentChangesUpdater.ts +1 -1
  181. package/src/sync/streaming/AuthClient/index.ts +14 -15
  182. package/src/sync/streaming/AuthClient/types.ts +9 -13
  183. package/src/sync/streaming/SSEClient/index.ts +2 -2
  184. package/src/sync/streaming/SSEClient/types.ts +2 -2
  185. package/src/sync/streaming/SSEHandler/index.ts +2 -1
  186. package/src/sync/streaming/SSEHandler/types.ts +2 -2
  187. package/src/sync/streaming/constants.ts +1 -0
  188. package/src/sync/streaming/pushManager.ts +32 -42
  189. package/src/sync/streaming/types.ts +3 -2
  190. package/src/sync/submitters/impressionsSubmitter.ts +3 -3
  191. package/src/sync/submitters/types.ts +2 -2
  192. package/src/sync/syncManagerOnline.ts +2 -8
  193. package/src/utils/Backoff.ts +16 -4
  194. package/types/splitio.d.ts +5 -4
  195. package/cjs/platform/browser.js +0 -15
  196. package/cjs/platform/getEventSource/browser.js +0 -8
  197. package/cjs/platform/getEventSource/eventsource.js +0 -480
  198. package/cjs/platform/getEventSource/node.js +0 -26
  199. package/cjs/platform/getFetch/browser.js +0 -9
  200. package/cjs/platform/getFetch/node.js +0 -27
  201. package/cjs/platform/getOptions/node.js +0 -25
  202. package/cjs/platform/node.js +0 -17
  203. package/cjs/sdkClient/sdkLifecycle.js +0 -72
  204. package/cjs/sdkClient/trackMethod.js +0 -56
  205. package/cjs/services/authProvider.js +0 -67
  206. package/cjs/services/secureSplitHttpClient.js +0 -39
  207. package/cjs/services/serviceApi.js +0 -145
  208. package/cjs/storages/AbstractDefinitionsCacheAsync.js +0 -51
  209. package/cjs/storages/AbstractDefinitionsCacheSync.js +0 -76
  210. package/cjs/storages/inLocalStorage/DefinitionsCacheInLocal.js +0 -194
  211. package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +0 -121
  212. package/cjs/storages/pluggable/DefinitionsCachePluggable.js +0 -212
  213. package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +0 -13
  214. package/cjs/utils/EventEmitter.js +0 -391
  215. package/cjs/utils/filter/bloomFilter.js +0 -37
  216. package/cjs/utils/inputValidation/definitions.js +0 -25
  217. package/cjs/utils/inputValidation/target.js +0 -22
  218. package/esm/platform/browser.js +0 -12
  219. package/esm/platform/getEventSource/browser.js +0 -4
  220. package/esm/platform/getEventSource/eventsource.js +0 -480
  221. package/esm/platform/getEventSource/node.js +0 -20
  222. package/esm/platform/getFetch/browser.js +0 -5
  223. package/esm/platform/getFetch/node.js +0 -22
  224. package/esm/platform/getOptions/node.js +0 -20
  225. package/esm/platform/node.js +0 -14
  226. package/esm/sdkClient/sdkLifecycle.js +0 -68
  227. package/esm/sdkClient/trackMethod.js +0 -52
  228. package/esm/services/authProvider.js +0 -63
  229. package/esm/services/secureSplitHttpClient.js +0 -35
  230. package/esm/services/serviceApi.js +0 -141
  231. package/esm/storages/AbstractDefinitionsCacheAsync.js +0 -48
  232. package/esm/storages/AbstractDefinitionsCacheSync.js +0 -71
  233. package/esm/storages/inLocalStorage/DefinitionsCacheInLocal.js +0 -191
  234. package/esm/storages/inMemory/DefinitionsCacheInMemory.js +0 -118
  235. package/esm/storages/pluggable/DefinitionsCachePluggable.js +0 -209
  236. package/esm/sync/polling/syncTasks/definitionsSyncTask.js +0 -9
  237. package/esm/utils/EventEmitter.js +0 -387
  238. package/esm/utils/filter/bloomFilter.js +0 -33
  239. package/esm/utils/inputValidation/definitionExistence.js +0 -15
  240. package/esm/utils/inputValidation/definitions.js +0 -21
  241. package/esm/utils/inputValidation/target.js +0 -18
@@ -1,209 +0,0 @@
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
- return this.wrapper.set(this.keys.buildDefinitionsTillKey(), changeNumber + '');
187
- };
188
- /**
189
- * Get till number or -1 if it's not defined.
190
- * The returned promise is resolved with the changeNumber or -1 if it doesn't exist or a wrapper operation fails.
191
- * The promise will never be rejected.
192
- */
193
- DefinitionsCachePluggable.prototype.getChangeNumber = function () {
194
- var _this = this;
195
- return this.wrapper.get(this.keys.buildDefinitionsTillKey()).then(function (value) {
196
- var i = parseInt(value, 10);
197
- return isNaNNumber(i) ? -1 : i;
198
- }).catch(function (e) {
199
- _this.log.error(LOG_PREFIX + 'Could not retrieve changeNumber from storage. Error: ' + e);
200
- return -1;
201
- });
202
- };
203
- // @TODO implement if required by DataLoader or producer mode
204
- DefinitionsCachePluggable.prototype.clear = function () {
205
- return Promise.resolve(true);
206
- };
207
- return DefinitionsCachePluggable;
208
- }(AbstractDefinitionsCacheAsync));
209
- export { DefinitionsCachePluggable };
@@ -1,9 +0,0 @@
1
- import { syncTaskFactory } from '../../syncTask';
2
- import { definitionChangesUpdaterFactory } from '../updaters/definitionChangesUpdater';
3
- /**
4
- * Creates a sync task that periodically executes a `definitionChangesUpdater` task
5
- */
6
- export function definitionsSyncTaskFactory(definitionChangesFetcher, storage, readiness, settings, segmentsSyncTask // undefined for client-side
7
- ) {
8
- return syncTaskFactory(settings.log, definitionChangesUpdaterFactory(settings.log, definitionChangesFetcher, storage, settings.sync.__splitFiltersValidation, readiness.definitions, settings.startup.requestTimeoutBeforeReady, settings.startup.retriesOnFailureBeforeReady, segmentsSyncTask), settings.scheduler.featuresRefreshRate, 'definitionChangesUpdater');
9
- }
@@ -1,387 +0,0 @@
1
- // Copyright Joyent, Inc. and other Node contributors.
2
- //
3
- // Permission is hereby granted, free of charge, to any person obtaining a
4
- // copy of this software and associated documentation files (the
5
- // "Software"), to deal in the Software without restriction, including
6
- // without limitation the rights to use, copy, modify, merge, publish,
7
- // distribute, sublicense, and/or sell copies of the Software, and to permit
8
- // persons to whom the Software is furnished to do so, subject to the
9
- // following conditions:
10
- //
11
- // The above copyright notice and this permission notice shall be included
12
- // in all copies or substantial portions of the Software.
13
- //
14
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
- // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
- // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
- // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
- // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
- // Adaptation of "events" library (https://www.npmjs.com/package/events)
22
- // exported as an ES module instead of CommonJS, to avoid extra configuration steps when using
23
- // the ESM build of the SDK with tools that doesn't support CommonJS by default (e.g. Rollup).
24
- var R = typeof Reflect === 'object' ? Reflect : null;
25
- var ReflectApply = R && typeof R.apply === 'function'
26
- ? R.apply
27
- : function ReflectApply(target, receiver, args) {
28
- return Function.prototype.apply.call(target, receiver, args);
29
- };
30
- var ReflectOwnKeys;
31
- if (R && typeof R.ownKeys === 'function') {
32
- ReflectOwnKeys = R.ownKeys;
33
- }
34
- else if (Object.getOwnPropertySymbols) {
35
- ReflectOwnKeys = function ReflectOwnKeys(target) {
36
- return Object.getOwnPropertyNames(target)
37
- .concat(Object.getOwnPropertySymbols(target));
38
- };
39
- }
40
- else {
41
- ReflectOwnKeys = function ReflectOwnKeys(target) {
42
- return Object.getOwnPropertyNames(target);
43
- };
44
- }
45
- function ProcessEmitWarning(warning) {
46
- if (console && console.warn)
47
- console.warn(warning);
48
- }
49
- // eslint-disable-next-line compat/compat
50
- var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
51
- return value !== value;
52
- };
53
- export function EventEmitter() {
54
- EventEmitter.init.call(this);
55
- }
56
- EventEmitter.prototype._events = undefined;
57
- EventEmitter.prototype._eventsCount = 0;
58
- EventEmitter.prototype._maxListeners = undefined;
59
- // By default EventEmitters will print a warning if more than 10 listeners are
60
- // added to it. This is a useful default which helps finding memory leaks.
61
- var defaultMaxListeners = 10;
62
- function checkListener(listener) {
63
- if (typeof listener !== 'function') {
64
- throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
65
- }
66
- }
67
- Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
68
- enumerable: true,
69
- get: function () {
70
- return defaultMaxListeners;
71
- },
72
- set: function (arg) {
73
- if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
74
- throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
75
- }
76
- defaultMaxListeners = arg;
77
- }
78
- });
79
- EventEmitter.init = function () {
80
- if (this._events === undefined ||
81
- this._events === Object.getPrototypeOf(this)._events) {
82
- this._events = Object.create(null);
83
- this._eventsCount = 0;
84
- }
85
- this._maxListeners = this._maxListeners || undefined;
86
- };
87
- // Obviously not all Emitters should be limited to 10. This function allows
88
- // that to be increased. Set to zero for unlimited.
89
- EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
90
- if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
91
- throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
92
- }
93
- this._maxListeners = n;
94
- return this;
95
- };
96
- function _getMaxListeners(that) {
97
- if (that._maxListeners === undefined)
98
- return EventEmitter.defaultMaxListeners;
99
- return that._maxListeners;
100
- }
101
- EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
102
- return _getMaxListeners(this);
103
- };
104
- EventEmitter.prototype.emit = function emit(type) {
105
- var args = [];
106
- for (var i = 1; i < arguments.length; i++)
107
- args.push(arguments[i]);
108
- var doError = (type === 'error');
109
- var events = this._events;
110
- if (events !== undefined)
111
- doError = (doError && events.error === undefined);
112
- else if (!doError)
113
- return false;
114
- // If there is no 'error' event listener then throw.
115
- if (doError) {
116
- var er;
117
- if (args.length > 0)
118
- er = args[0];
119
- if (er instanceof Error) {
120
- // Note: The comments on the `throw` lines are intentional, they show
121
- // up in Node.js output if this results in an unhandled exception.
122
- throw er; // Unhandled 'error' event
123
- }
124
- // At least give some kind of context to the user
125
- var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
126
- err.context = er;
127
- throw err; // Unhandled 'error' event
128
- }
129
- var handler = events[type];
130
- if (handler === undefined)
131
- return false;
132
- if (typeof handler === 'function') {
133
- ReflectApply(handler, this, args);
134
- }
135
- else {
136
- var len = handler.length;
137
- var listeners = arrayClone(handler, len); // eslint-disable-next-line no-redeclare
138
- for (var i = 0; i < len; ++i)
139
- ReflectApply(listeners[i], this, args);
140
- }
141
- return true;
142
- };
143
- function _addListener(target, type, listener, prepend) {
144
- var m;
145
- var events;
146
- var existing;
147
- checkListener(listener);
148
- events = target._events;
149
- if (events === undefined) {
150
- events = target._events = Object.create(null);
151
- target._eventsCount = 0;
152
- }
153
- else {
154
- // To avoid recursion in the case that type === "newListener"! Before
155
- // adding it to the listeners, first emit "newListener".
156
- if (events.newListener !== undefined) {
157
- target.emit('newListener', type, listener.listener ? listener.listener : listener);
158
- // Re-assign `events` because a newListener handler could have caused the
159
- // this._events to be assigned to a new object
160
- events = target._events;
161
- }
162
- existing = events[type];
163
- }
164
- if (existing === undefined) {
165
- // Optimize the case of one listener. Don't need the extra array object.
166
- existing = events[type] = listener;
167
- ++target._eventsCount;
168
- }
169
- else {
170
- if (typeof existing === 'function') {
171
- // Adding the second element, need to change to array.
172
- existing = events[type] =
173
- prepend ? [listener, existing] : [existing, listener];
174
- // If we've already got an array, just append.
175
- }
176
- else if (prepend) {
177
- existing.unshift(listener);
178
- }
179
- else {
180
- existing.push(listener);
181
- }
182
- // Check for listener leak
183
- m = _getMaxListeners(target);
184
- if (m > 0 && existing.length > m && !existing.warned) {
185
- existing.warned = true;
186
- // No error code for this since it is a Warning
187
- // eslint-disable-next-line no-restricted-syntax
188
- var w = new Error('Possible EventEmitter memory leak detected. ' +
189
- existing.length + ' ' + String(type) + ' listeners ' +
190
- 'added. Use emitter.setMaxListeners() to ' +
191
- 'increase limit');
192
- w.name = 'MaxListenersExceededWarning';
193
- w.emitter = target;
194
- w.type = type;
195
- w.count = existing.length;
196
- ProcessEmitWarning(w);
197
- }
198
- }
199
- return target;
200
- }
201
- EventEmitter.prototype.addListener = function addListener(type, listener) {
202
- return _addListener(this, type, listener, false);
203
- };
204
- EventEmitter.prototype.on = EventEmitter.prototype.addListener;
205
- EventEmitter.prototype.prependListener =
206
- function prependListener(type, listener) {
207
- return _addListener(this, type, listener, true);
208
- };
209
- function onceWrapper() {
210
- if (!this.fired) {
211
- this.target.removeListener(this.type, this.wrapFn);
212
- this.fired = true;
213
- if (arguments.length === 0)
214
- return this.listener.call(this.target);
215
- return this.listener.apply(this.target, arguments);
216
- }
217
- }
218
- function _onceWrap(target, type, listener) {
219
- var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
220
- var wrapped = onceWrapper.bind(state);
221
- wrapped.listener = listener;
222
- state.wrapFn = wrapped;
223
- return wrapped;
224
- }
225
- EventEmitter.prototype.once = function once(type, listener) {
226
- checkListener(listener);
227
- this.on(type, _onceWrap(this, type, listener));
228
- return this;
229
- };
230
- EventEmitter.prototype.prependOnceListener =
231
- function prependOnceListener(type, listener) {
232
- checkListener(listener);
233
- this.prependListener(type, _onceWrap(this, type, listener));
234
- return this;
235
- };
236
- // Emits a 'removeListener' event if and only if the listener was removed.
237
- EventEmitter.prototype.removeListener =
238
- function removeListener(type, listener) {
239
- var list, events, position, i, originalListener;
240
- checkListener(listener);
241
- events = this._events;
242
- if (events === undefined)
243
- return this;
244
- list = events[type];
245
- if (list === undefined)
246
- return this;
247
- if (list === listener || list.listener === listener) {
248
- if (--this._eventsCount === 0)
249
- this._events = Object.create(null);
250
- else {
251
- delete events[type];
252
- if (events.removeListener)
253
- this.emit('removeListener', type, list.listener || listener);
254
- }
255
- }
256
- else if (typeof list !== 'function') {
257
- position = -1;
258
- for (i = list.length - 1; i >= 0; i--) {
259
- if (list[i] === listener || list[i].listener === listener) {
260
- originalListener = list[i].listener;
261
- position = i;
262
- break;
263
- }
264
- }
265
- if (position < 0)
266
- return this;
267
- if (position === 0)
268
- list.shift();
269
- else {
270
- spliceOne(list, position);
271
- }
272
- if (list.length === 1)
273
- events[type] = list[0];
274
- if (events.removeListener !== undefined)
275
- this.emit('removeListener', type, originalListener || listener);
276
- }
277
- return this;
278
- };
279
- EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
280
- EventEmitter.prototype.removeAllListeners =
281
- function removeAllListeners(type) {
282
- var listeners, events, i;
283
- events = this._events;
284
- if (events === undefined)
285
- return this;
286
- // not listening for removeListener, no need to emit
287
- if (events.removeListener === undefined) {
288
- if (arguments.length === 0) {
289
- this._events = Object.create(null);
290
- this._eventsCount = 0;
291
- }
292
- else if (events[type] !== undefined) {
293
- if (--this._eventsCount === 0)
294
- this._events = Object.create(null);
295
- else
296
- delete events[type];
297
- }
298
- return this;
299
- }
300
- // emit removeListener for all listeners on all events
301
- if (arguments.length === 0) {
302
- var keys = Object.keys(events);
303
- var key;
304
- for (i = 0; i < keys.length; ++i) {
305
- key = keys[i];
306
- if (key === 'removeListener')
307
- continue;
308
- this.removeAllListeners(key);
309
- }
310
- this.removeAllListeners('removeListener');
311
- this._events = Object.create(null);
312
- this._eventsCount = 0;
313
- return this;
314
- }
315
- listeners = events[type];
316
- if (typeof listeners === 'function') {
317
- this.removeListener(type, listeners);
318
- }
319
- else if (listeners !== undefined) {
320
- // LIFO order
321
- for (i = listeners.length - 1; i >= 0; i--) {
322
- this.removeListener(type, listeners[i]);
323
- }
324
- }
325
- return this;
326
- };
327
- function _listeners(target, type, unwrap) {
328
- var events = target._events;
329
- if (events === undefined)
330
- return [];
331
- var evlistener = events[type];
332
- if (evlistener === undefined)
333
- return [];
334
- if (typeof evlistener === 'function')
335
- return unwrap ? [evlistener.listener || evlistener] : [evlistener];
336
- return unwrap ?
337
- unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
338
- }
339
- EventEmitter.prototype.listeners = function listeners(type) {
340
- return _listeners(this, type, true);
341
- };
342
- EventEmitter.prototype.rawListeners = function rawListeners(type) {
343
- return _listeners(this, type, false);
344
- };
345
- EventEmitter.listenerCount = function (emitter, type) {
346
- if (typeof emitter.listenerCount === 'function') {
347
- return emitter.listenerCount(type);
348
- }
349
- else {
350
- return listenerCount.call(emitter, type);
351
- }
352
- };
353
- EventEmitter.prototype.listenerCount = listenerCount;
354
- function listenerCount(type) {
355
- var events = this._events;
356
- if (events !== undefined) {
357
- var evlistener = events[type];
358
- if (typeof evlistener === 'function') {
359
- return 1;
360
- }
361
- else if (evlistener !== undefined) {
362
- return evlistener.length;
363
- }
364
- }
365
- return 0;
366
- }
367
- EventEmitter.prototype.eventNames = function eventNames() {
368
- return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
369
- };
370
- function arrayClone(arr, n) {
371
- var copy = new Array(n);
372
- for (var i = 0; i < n; ++i)
373
- copy[i] = arr[i];
374
- return copy;
375
- }
376
- function spliceOne(list, index) {
377
- for (; index + 1 < list.length; index++)
378
- list[index] = list[index + 1];
379
- list.pop();
380
- }
381
- function unwrapListeners(arr) {
382
- var ret = new Array(arr.length);
383
- for (var i = 0; i < ret.length; ++i) {
384
- ret[i] = arr[i].listener || arr[i];
385
- }
386
- return ret;
387
- }
@@ -1,33 +0,0 @@
1
- // bloom-filters is supported on the following platforms:
2
- // - Node.js: v4.0.0 or higher
3
- // - Google Chrome: v41 or higher
4
- // - Mozilla Firefox: v34 or higher
5
- // - Microsoft Edge: v12 or higher
6
- import { BloomFilter } from 'bloom-filters';
7
- var EXPECTED_INSERTIONS = 10000000;
8
- var ERROR_RATE = 0.01;
9
- var REFRESH_RATE = 24 * 60 * 60000; // 24HS
10
- export function bloomFilterFactory(expectedInsertions, errorRate, refreshRate) {
11
- if (expectedInsertions === void 0) { expectedInsertions = EXPECTED_INSERTIONS; }
12
- if (errorRate === void 0) { errorRate = ERROR_RATE; }
13
- if (refreshRate === void 0) { refreshRate = REFRESH_RATE; }
14
- var filter = BloomFilter.create(expectedInsertions, errorRate);
15
- return {
16
- refreshRate: refreshRate,
17
- add: function (key, value) {
18
- var data = "".concat(key, ":").concat(value);
19
- if (filter.has(data)) {
20
- return false;
21
- }
22
- filter.add(data);
23
- return true;
24
- },
25
- contains: function (key, value) {
26
- var data = "".concat(key, ":").concat(value);
27
- return filter.has(data);
28
- },
29
- clear: function () {
30
- filter = BloomFilter.create(expectedInsertions, errorRate);
31
- }
32
- };
33
- }
@@ -1,15 +0,0 @@
1
- import { FALLBACK_DEFINITION_NOT_FOUND, DEFINITION_NOT_FOUND } from '../labels';
2
- import { WARN_NOT_EXISTENT_DEFINITION } from '../../logger/constants';
3
- /**
4
- * This is defined here and in this format mostly because of the logger and the fact that it's considered a validation at product level.
5
- * But it's not going to run on the input validation layer. In any case, the most compelling reason to use it as we do is to avoid going to Redis and get a definition twice.
6
- */
7
- export function validateDefinitionExistence(log, readinessManager, definitionName, labelOrDefinitionObj, method) {
8
- if (readinessManager.isReady()) { // Only if it's ready (synced with BE) we validate this, otherwise it may just be that the SDK is still syncing
9
- if (labelOrDefinitionObj === DEFINITION_NOT_FOUND || labelOrDefinitionObj === FALLBACK_DEFINITION_NOT_FOUND || labelOrDefinitionObj == null) {
10
- log.warn(WARN_NOT_EXISTENT_DEFINITION, [method, definitionName]);
11
- return false;
12
- }
13
- }
14
- return true;
15
- }
@@ -1,21 +0,0 @@
1
- import { ERROR_EMPTY_ARRAY } from '../../logger/constants';
2
- import { uniq } from '../lang';
3
- import { validateDefinition } from './definition';
4
- export function validateDefinitions(log, maybeDefinitions, method, listName, item) {
5
- if (listName === void 0) { listName = 'feature flag names'; }
6
- if (item === void 0) { item = 'feature flag name'; }
7
- if (Array.isArray(maybeDefinitions) && maybeDefinitions.length > 0) {
8
- var validatedArray_1 = [];
9
- // Remove invalid values
10
- maybeDefinitions.forEach(function (maybeDefinition) {
11
- var definitionName = validateDefinition(log, maybeDefinition, method, item);
12
- if (definitionName)
13
- validatedArray_1.push(definitionName);
14
- });
15
- // Strip off duplicated values if we have valid definition names then return
16
- if (validatedArray_1.length)
17
- return uniq(validatedArray_1);
18
- }
19
- log.error(ERROR_EMPTY_ARRAY, [method, listName]);
20
- return false;
21
- }