@splitsoftware/splitio-commons 2.12.0 → 3.0.0-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 (395) hide show
  1. package/CHANGES.txt +19 -1
  2. package/cjs/evaluator/condition/engineUtils.js +2 -2
  3. package/cjs/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +70 -0
  4. package/cjs/evaluator/fallbackConfigsCalculator/index.js +25 -0
  5. package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
  6. package/cjs/evaluator/fallbackTreatmentsCalculator/index.js +21 -32
  7. package/cjs/evaluator/index.js +73 -48
  8. package/cjs/evaluator/matchers/whitelist.js +1 -1
  9. package/cjs/integrations/pluggable.js +1 -1
  10. package/cjs/listeners/browser.js +4 -3
  11. package/cjs/listeners/node.js +4 -4
  12. package/cjs/logger/constants.js +15 -21
  13. package/cjs/logger/index.js +1 -1
  14. package/cjs/logger/messages/debug.js +6 -7
  15. package/cjs/logger/messages/error.js +4 -4
  16. package/cjs/logger/messages/info.js +2 -4
  17. package/cjs/logger/messages/warn.js +9 -10
  18. package/cjs/platform/browser.js +15 -0
  19. package/cjs/platform/getEventSource/browser.js +8 -0
  20. package/cjs/platform/getEventSource/eventsource.js +480 -0
  21. package/cjs/platform/getEventSource/node.js +26 -0
  22. package/cjs/platform/getFetch/browser.js +9 -0
  23. package/cjs/platform/getFetch/node.js +27 -0
  24. package/cjs/platform/getOptions/node.js +25 -0
  25. package/cjs/platform/node.js +17 -0
  26. package/cjs/readiness/constants.js +5 -4
  27. package/cjs/readiness/readinessManager.js +22 -22
  28. package/cjs/readiness/sdkReadinessManager.js +0 -16
  29. package/cjs/sdkClient/client.js +9 -35
  30. package/cjs/sdkClient/clientAttributesDecoration.js +3 -3
  31. package/cjs/sdkClient/clientInputValidation.js +38 -81
  32. package/cjs/sdkClient/identity.js +1 -1
  33. package/cjs/sdkClient/sdkClient.js +4 -49
  34. package/cjs/sdkClient/sdkLifecycle.js +71 -0
  35. package/cjs/sdkClient/trackMethod.js +56 -0
  36. package/cjs/sdkFactory/index.js +13 -50
  37. package/cjs/sdkManager/index.js +5 -5
  38. package/cjs/services/authProvider.js +67 -0
  39. package/cjs/services/secureSplitHttpClient.js +39 -0
  40. package/cjs/services/splitApi.js +24 -14
  41. package/cjs/services/splitHttpClient.js +1 -1
  42. package/cjs/storages/AbstractDefinitionsCacheAsync.js +51 -0
  43. package/cjs/storages/AbstractDefinitionsCacheSync.js +76 -0
  44. package/cjs/storages/KeyBuilder.js +16 -16
  45. package/cjs/storages/KeyBuilderCS.js +17 -17
  46. package/cjs/storages/KeyBuilderSS.js +16 -16
  47. package/cjs/storages/getRolloutPlan.js +4 -4
  48. package/cjs/storages/inLocalStorage/DefinitionsCacheInLocal.js +194 -0
  49. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -1
  50. package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +10 -10
  51. package/cjs/storages/inLocalStorage/index.js +6 -6
  52. package/cjs/storages/inLocalStorage/validateCache.js +3 -3
  53. package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +121 -0
  54. package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
  55. package/cjs/storages/inMemory/InMemoryStorage.js +4 -4
  56. package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -5
  57. package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +1 -1
  58. package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +5 -5
  59. package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  60. package/cjs/storages/inMemory/TelemetryCacheInMemory.js +5 -5
  61. package/cjs/storages/inRedis/DefinitionsCacheInRedis.js +243 -0
  62. package/cjs/storages/inRedis/EventsCacheInRedis.js +1 -1
  63. package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +5 -5
  64. package/cjs/storages/inRedis/ImpressionsCacheInRedis.js +1 -1
  65. package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
  66. package/cjs/storages/inRedis/RedisAdapter.js +8 -8
  67. package/cjs/storages/inRedis/TelemetryCacheInRedis.js +7 -7
  68. package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +3 -3
  69. package/cjs/storages/inRedis/index.js +2 -2
  70. package/cjs/storages/pluggable/DefinitionsCachePluggable.js +212 -0
  71. package/cjs/storages/pluggable/EventsCachePluggable.js +1 -1
  72. package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +6 -6
  73. package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
  74. package/cjs/storages/pluggable/TelemetryCachePluggable.js +7 -7
  75. package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +2 -2
  76. package/cjs/storages/pluggable/index.js +5 -5
  77. package/cjs/storages/pluggable/wrapperAdapter.js +1 -1
  78. package/cjs/storages/setRolloutPlan.js +6 -6
  79. package/cjs/storages/utils.js +6 -6
  80. package/cjs/sync/offline/splitsParser/parseCondition.js +1 -1
  81. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +5 -5
  82. package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
  83. package/cjs/sync/polling/fetchers/splitChangesFetcher.js +24 -15
  84. package/cjs/sync/polling/pollingManagerCS.js +18 -18
  85. package/cjs/sync/polling/pollingManagerSS.js +13 -13
  86. package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +12 -0
  87. package/cjs/sync/polling/updaters/{splitChangesUpdater.js → definitionChangesUpdater.js} +72 -64
  88. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  89. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
  90. package/cjs/sync/streaming/SSEClient/index.js +2 -2
  91. package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +1 -1
  92. package/cjs/sync/streaming/SSEHandler/index.js +1 -1
  93. package/cjs/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +18 -18
  94. package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +2 -2
  95. package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -2
  96. package/cjs/sync/streaming/constants.js +3 -3
  97. package/cjs/sync/streaming/parseUtils.js +12 -12
  98. package/cjs/sync/streaming/pushManager.js +14 -14
  99. package/cjs/sync/submitters/impressionsSubmitter.js +6 -6
  100. package/cjs/sync/submitters/submitter.js +1 -1
  101. package/cjs/sync/submitters/telemetrySubmitter.js +1 -2
  102. package/cjs/sync/syncManagerOnline.js +9 -6
  103. package/cjs/trackers/eventTracker.js +10 -12
  104. package/cjs/trackers/impressionObserver/buildKey.js +1 -1
  105. package/cjs/trackers/impressionsTracker.js +37 -20
  106. package/cjs/trackers/uniqueKeysTracker.js +1 -1
  107. package/cjs/utils/Backoff.js +20 -0
  108. package/cjs/utils/EventEmitter.js +391 -0
  109. package/cjs/utils/filter/bloomFilter.js +37 -0
  110. package/cjs/utils/inputValidation/apiKey.js +1 -1
  111. package/cjs/utils/inputValidation/attribute.js +2 -2
  112. package/cjs/utils/inputValidation/{split.js → definition.js} +10 -10
  113. package/cjs/utils/inputValidation/{splitExistence.js → definitionExistence.js} +6 -6
  114. package/cjs/utils/inputValidation/definitions.js +25 -0
  115. package/cjs/utils/inputValidation/eventProperties.js +1 -1
  116. package/cjs/utils/inputValidation/index.js +7 -7
  117. package/cjs/utils/inputValidation/isOperational.js +4 -4
  118. package/cjs/utils/inputValidation/target.js +22 -0
  119. package/cjs/utils/labels/index.js +3 -3
  120. package/cjs/utils/lang/index.js +1 -1
  121. package/cjs/utils/lang/sets.js +4 -4
  122. package/cjs/utils/promise/timeout.js +1 -1
  123. package/cjs/utils/settingsValidation/splitFilters.js +4 -4
  124. package/cjs/utils/settingsValidation/url.js +6 -6
  125. package/esm/evaluator/condition/engineUtils.js +2 -2
  126. package/esm/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +64 -0
  127. package/esm/evaluator/fallbackConfigsCalculator/index.js +21 -0
  128. package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
  129. package/esm/evaluator/fallbackTreatmentsCalculator/index.js +21 -33
  130. package/esm/evaluator/index.js +72 -48
  131. package/esm/evaluator/matchers/whitelist.js +1 -1
  132. package/esm/integrations/pluggable.js +1 -1
  133. package/esm/listeners/browser.js +4 -3
  134. package/esm/listeners/node.js +4 -4
  135. package/esm/logger/constants.js +12 -18
  136. package/esm/logger/index.js +1 -1
  137. package/esm/logger/messages/debug.js +5 -6
  138. package/esm/logger/messages/error.js +3 -3
  139. package/esm/logger/messages/info.js +1 -3
  140. package/esm/logger/messages/warn.js +8 -9
  141. package/esm/platform/browser.js +12 -0
  142. package/esm/platform/getEventSource/browser.js +4 -0
  143. package/esm/platform/getEventSource/eventsource.js +480 -0
  144. package/esm/platform/getEventSource/node.js +20 -0
  145. package/esm/platform/getFetch/browser.js +5 -0
  146. package/esm/platform/getFetch/node.js +22 -0
  147. package/esm/platform/getOptions/node.js +20 -0
  148. package/esm/platform/node.js +14 -0
  149. package/esm/readiness/constants.js +4 -3
  150. package/esm/readiness/readinessManager.js +23 -23
  151. package/esm/readiness/sdkReadinessManager.js +1 -17
  152. package/esm/sdkClient/client.js +10 -37
  153. package/esm/sdkClient/clientAttributesDecoration.js +3 -3
  154. package/esm/sdkClient/clientInputValidation.js +40 -83
  155. package/esm/sdkClient/identity.js +1 -1
  156. package/esm/sdkClient/sdkClient.js +4 -49
  157. package/esm/sdkClient/sdkLifecycle.js +67 -0
  158. package/esm/sdkClient/trackMethod.js +52 -0
  159. package/esm/sdkFactory/index.js +14 -51
  160. package/esm/sdkManager/index.js +6 -6
  161. package/esm/services/authProvider.js +63 -0
  162. package/esm/services/secureSplitHttpClient.js +35 -0
  163. package/esm/services/splitApi.js +24 -14
  164. package/esm/services/splitHttpClient.js +1 -1
  165. package/esm/storages/AbstractDefinitionsCacheAsync.js +48 -0
  166. package/esm/storages/AbstractDefinitionsCacheSync.js +71 -0
  167. package/esm/storages/KeyBuilder.js +16 -16
  168. package/esm/storages/KeyBuilderCS.js +16 -16
  169. package/esm/storages/KeyBuilderSS.js +15 -15
  170. package/esm/storages/getRolloutPlan.js +4 -4
  171. package/esm/storages/inLocalStorage/DefinitionsCacheInLocal.js +191 -0
  172. package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +7 -7
  173. package/esm/storages/inLocalStorage/index.js +6 -6
  174. package/esm/storages/inLocalStorage/validateCache.js +3 -3
  175. package/esm/storages/inMemory/DefinitionsCacheInMemory.js +118 -0
  176. package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
  177. package/esm/storages/inMemory/InMemoryStorage.js +4 -4
  178. package/esm/storages/inMemory/InMemoryStorageCS.js +5 -5
  179. package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +2 -2
  180. package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  181. package/esm/storages/inMemory/TelemetryCacheInMemory.js +5 -5
  182. package/esm/storages/inRedis/DefinitionsCacheInRedis.js +240 -0
  183. package/esm/storages/inRedis/EventsCacheInRedis.js +1 -1
  184. package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +4 -4
  185. package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
  186. package/esm/storages/inRedis/RedisAdapter.js +7 -7
  187. package/esm/storages/inRedis/TelemetryCacheInRedis.js +7 -7
  188. package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +1 -1
  189. package/esm/storages/inRedis/index.js +2 -2
  190. package/esm/storages/pluggable/DefinitionsCachePluggable.js +209 -0
  191. package/esm/storages/pluggable/EventsCachePluggable.js +1 -1
  192. package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +5 -5
  193. package/esm/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
  194. package/esm/storages/pluggable/TelemetryCachePluggable.js +7 -7
  195. package/esm/storages/pluggable/UniqueKeysCachePluggable.js +1 -1
  196. package/esm/storages/pluggable/index.js +4 -4
  197. package/esm/storages/pluggable/wrapperAdapter.js +1 -1
  198. package/esm/storages/setRolloutPlan.js +6 -6
  199. package/esm/storages/utils.js +6 -6
  200. package/esm/sync/offline/splitsParser/parseCondition.js +1 -1
  201. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +6 -6
  202. package/esm/sync/polling/fetchers/splitChangesFetcher.js +25 -16
  203. package/esm/sync/polling/pollingManagerCS.js +15 -15
  204. package/esm/sync/polling/pollingManagerSS.js +13 -13
  205. package/esm/sync/polling/syncTasks/definitionsSyncTask.js +8 -0
  206. package/esm/sync/polling/updaters/definitionChangesUpdater.js +200 -0
  207. package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  208. package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
  209. package/esm/sync/streaming/SSEClient/index.js +2 -2
  210. package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +2 -2
  211. package/esm/sync/streaming/SSEHandler/index.js +2 -2
  212. package/esm/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +17 -17
  213. package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +2 -2
  214. package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -2
  215. package/esm/sync/streaming/constants.js +2 -2
  216. package/esm/sync/streaming/parseUtils.js +10 -10
  217. package/esm/sync/streaming/pushManager.js +16 -16
  218. package/esm/sync/submitters/impressionsSubmitter.js +6 -6
  219. package/esm/sync/submitters/submitter.js +1 -1
  220. package/esm/sync/submitters/telemetrySubmitter.js +1 -2
  221. package/esm/sync/syncManagerOnline.js +8 -5
  222. package/esm/trackers/eventTracker.js +10 -12
  223. package/esm/trackers/impressionObserver/buildKey.js +1 -1
  224. package/esm/trackers/impressionsTracker.js +38 -21
  225. package/esm/trackers/uniqueKeysTracker.js +1 -1
  226. package/esm/utils/Backoff.js +20 -0
  227. package/esm/utils/EventEmitter.js +387 -0
  228. package/esm/utils/filter/bloomFilter.js +33 -0
  229. package/esm/utils/inputValidation/apiKey.js +1 -1
  230. package/esm/utils/inputValidation/attribute.js +2 -2
  231. package/esm/utils/inputValidation/{split.js → definition.js} +8 -8
  232. package/esm/utils/inputValidation/definitionExistence.js +15 -0
  233. package/esm/utils/inputValidation/definitions.js +21 -0
  234. package/esm/utils/inputValidation/index.js +3 -3
  235. package/esm/utils/inputValidation/isOperational.js +4 -4
  236. package/esm/utils/inputValidation/target.js +18 -0
  237. package/esm/utils/labels/index.js +2 -2
  238. package/esm/utils/lang/sets.js +4 -4
  239. package/esm/utils/promise/timeout.js +1 -1
  240. package/esm/utils/settingsValidation/splitFilters.js +4 -4
  241. package/esm/utils/settingsValidation/url.js +6 -6
  242. package/package.json +15 -6
  243. package/src/dtos/types.ts +65 -70
  244. package/src/evaluator/Engine.ts +4 -4
  245. package/src/evaluator/combiners/and.ts +3 -3
  246. package/src/evaluator/combiners/ifelseif.ts +2 -2
  247. package/src/evaluator/condition/engineUtils.ts +2 -2
  248. package/src/evaluator/condition/index.ts +3 -3
  249. package/src/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.ts +76 -0
  250. package/src/evaluator/fallbackConfigsCalculator/index.ts +24 -0
  251. package/src/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.ts +5 -7
  252. package/src/evaluator/fallbackTreatmentsCalculator/index.ts +27 -41
  253. package/src/evaluator/index.ts +86 -51
  254. package/src/evaluator/matchers/dependency.ts +2 -2
  255. package/src/evaluator/matchers/matcherTypes.ts +2 -2
  256. package/src/evaluator/matchers/prerequisites.ts +4 -4
  257. package/src/evaluator/matchers/rbsegment.ts +2 -2
  258. package/src/evaluator/matchers/whitelist.ts +2 -2
  259. package/src/evaluator/matchersTransform/index.ts +2 -2
  260. package/src/evaluator/matchersTransform/whitelist.ts +2 -2
  261. package/src/evaluator/parser/index.ts +4 -4
  262. package/src/evaluator/treatments/index.ts +2 -2
  263. package/src/evaluator/types.ts +6 -6
  264. package/src/evaluator/value/index.ts +1 -1
  265. package/src/integrations/pluggable.ts +1 -1
  266. package/src/listeners/browser.ts +11 -8
  267. package/src/listeners/node.ts +2 -5
  268. package/src/logger/constants.ts +12 -18
  269. package/src/logger/messages/debug.ts +5 -6
  270. package/src/logger/messages/error.ts +3 -3
  271. package/src/logger/messages/info.ts +1 -3
  272. package/src/logger/messages/warn.ts +8 -9
  273. package/src/platform/browser.ts +14 -0
  274. package/src/platform/getEventSource/browser.ts +4 -0
  275. package/src/platform/getEventSource/eventsource.js +519 -0
  276. package/src/platform/getEventSource/node.ts +23 -0
  277. package/src/platform/getFetch/browser.ts +5 -0
  278. package/src/platform/getFetch/node.ts +27 -0
  279. package/src/platform/getOptions/node.ts +24 -0
  280. package/src/platform/node.ts +16 -0
  281. package/src/readiness/constants.ts +4 -3
  282. package/src/readiness/readinessManager.ts +22 -22
  283. package/src/readiness/sdkReadinessManager.ts +1 -16
  284. package/src/readiness/types.ts +10 -16
  285. package/src/sdkClient/client.ts +11 -41
  286. package/src/sdkClient/clientInputValidation.ts +44 -84
  287. package/src/sdkClient/sdkClient.ts +5 -54
  288. package/src/sdkClient/sdkLifecycle.ts +79 -0
  289. package/src/sdkClient/trackMethod.ts +59 -0
  290. package/src/sdkFactory/index.ts +15 -59
  291. package/src/sdkFactory/types.ts +19 -16
  292. package/src/sdkManager/index.ts +15 -15
  293. package/src/services/authProvider.ts +86 -0
  294. package/src/services/secureSplitHttpClient.ts +44 -0
  295. package/src/services/splitApi.ts +14 -2
  296. package/src/services/types.ts +7 -2
  297. package/src/storages/AbstractDefinitionsCacheAsync.ts +63 -0
  298. package/src/storages/AbstractDefinitionsCacheSync.ts +95 -0
  299. package/src/storages/KeyBuilder.ts +6 -6
  300. package/src/storages/KeyBuilderCS.ts +6 -6
  301. package/src/storages/KeyBuilderSS.ts +2 -2
  302. package/src/storages/getRolloutPlan.ts +3 -3
  303. package/src/storages/inLocalStorage/DefinitionsCacheInLocal.ts +234 -0
  304. package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +8 -8
  305. package/src/storages/inLocalStorage/index.ts +6 -6
  306. package/src/storages/inLocalStorage/validateCache.ts +4 -4
  307. package/src/storages/inMemory/DefinitionsCacheInMemory.ts +130 -0
  308. package/src/storages/inMemory/InMemoryStorage.ts +4 -4
  309. package/src/storages/inMemory/InMemoryStorageCS.ts +5 -5
  310. package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +3 -3
  311. package/src/storages/inMemory/SegmentsCacheInMemory.ts +1 -1
  312. package/src/storages/inMemory/TelemetryCacheInMemory.ts +5 -5
  313. package/src/storages/inRedis/{SplitsCacheInRedis.ts → DefinitionsCacheInRedis.ts} +69 -69
  314. package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +2 -2
  315. package/src/storages/inRedis/index.ts +2 -2
  316. package/src/storages/pluggable/DefinitionsCachePluggable.ts +230 -0
  317. package/src/storages/pluggable/RBSegmentsCachePluggable.ts +2 -2
  318. package/src/storages/pluggable/index.ts +2 -2
  319. package/src/storages/setRolloutPlan.ts +7 -7
  320. package/src/storages/types.ts +34 -29
  321. package/src/sync/offline/splitsParser/parseCondition.ts +2 -2
  322. package/src/sync/offline/splitsParser/splitsParserFromSettings.ts +3 -3
  323. package/src/sync/offline/splitsParser/types.ts +6 -3
  324. package/src/sync/offline/syncManagerOffline.ts +2 -2
  325. package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +14 -14
  326. package/src/sync/polling/fetchers/splitChangesFetcher.ts +58 -23
  327. package/src/sync/polling/fetchers/types.ts +5 -3
  328. package/src/sync/polling/pollingManagerCS.ts +16 -14
  329. package/src/sync/polling/pollingManagerSS.ts +15 -13
  330. package/src/sync/polling/syncTasks/{splitsSyncTask.ts → definitionsSyncTask.ts} +11 -12
  331. package/src/sync/polling/types.ts +3 -3
  332. package/src/sync/polling/updaters/definitionChangesUpdater.ts +239 -0
  333. package/src/sync/polling/updaters/mySegmentsUpdater.ts +3 -3
  334. package/src/sync/polling/updaters/segmentChangesUpdater.ts +7 -7
  335. package/src/sync/streaming/AuthClient/index.ts +2 -2
  336. package/src/sync/streaming/AuthClient/types.ts +14 -11
  337. package/src/sync/streaming/SSEClient/index.ts +2 -2
  338. package/src/sync/streaming/SSEClient/types.ts +2 -2
  339. package/src/sync/streaming/SSEHandler/NotificationKeeper.ts +2 -2
  340. package/src/sync/streaming/SSEHandler/index.ts +2 -2
  341. package/src/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.ts → DefinitionsUpdateWorker.ts} +21 -21
  342. package/src/sync/streaming/constants.ts +2 -2
  343. package/src/sync/streaming/parseUtils.ts +12 -12
  344. package/src/sync/streaming/pushManager.ts +18 -18
  345. package/src/sync/streaming/types.ts +2 -2
  346. package/src/sync/submitters/impressionsSubmitter.ts +9 -9
  347. package/src/sync/submitters/telemetrySubmitter.ts +1 -2
  348. package/src/sync/submitters/types.ts +3 -0
  349. package/src/sync/syncManagerOnline.ts +9 -5
  350. package/src/trackers/eventTracker.ts +7 -10
  351. package/src/trackers/impressionsTracker.ts +42 -26
  352. package/src/trackers/types.ts +3 -1
  353. package/src/utils/Backoff.ts +21 -0
  354. package/src/utils/EventEmitter.js +444 -0
  355. package/src/utils/filter/bloomFilter.ts +38 -0
  356. package/src/utils/inputValidation/definition.ts +27 -0
  357. package/src/utils/inputValidation/definitionExistence.ts +19 -0
  358. package/src/utils/inputValidation/definitions.ts +21 -0
  359. package/src/utils/inputValidation/index.ts +3 -3
  360. package/src/utils/inputValidation/isOperational.ts +4 -4
  361. package/src/utils/inputValidation/target.ts +21 -0
  362. package/src/utils/inputValidation/trafficTypeExistence.ts +2 -2
  363. package/src/utils/jwt/types.ts +1 -1
  364. package/src/utils/labels/index.ts +2 -2
  365. package/src/utils/lang/sets.ts +4 -2
  366. package/src/utils/settingsValidation/splitFilters.ts +3 -3
  367. package/src/utils/settingsValidation/url.ts +1 -1
  368. package/types/splitio.d.ts +222 -11
  369. package/cjs/storages/AbstractSplitsCacheAsync.js +0 -51
  370. package/cjs/storages/AbstractSplitsCacheSync.js +0 -76
  371. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +0 -194
  372. package/cjs/storages/inMemory/SplitsCacheInMemory.js +0 -121
  373. package/cjs/storages/inRedis/SplitsCacheInRedis.js +0 -243
  374. package/cjs/storages/pluggable/SplitsCachePluggable.js +0 -212
  375. package/cjs/sync/polling/syncTasks/splitsSyncTask.js +0 -13
  376. package/cjs/utils/inputValidation/splits.js +0 -25
  377. package/esm/storages/AbstractSplitsCacheAsync.js +0 -48
  378. package/esm/storages/AbstractSplitsCacheSync.js +0 -71
  379. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +0 -191
  380. package/esm/storages/inMemory/SplitsCacheInMemory.js +0 -118
  381. package/esm/storages/inRedis/SplitsCacheInRedis.js +0 -240
  382. package/esm/storages/pluggable/SplitsCachePluggable.js +0 -209
  383. package/esm/sync/polling/syncTasks/splitsSyncTask.js +0 -9
  384. package/esm/sync/polling/updaters/splitChangesUpdater.js +0 -192
  385. package/esm/utils/inputValidation/splitExistence.js +0 -15
  386. package/esm/utils/inputValidation/splits.js +0 -21
  387. package/src/storages/AbstractSplitsCacheAsync.ts +0 -63
  388. package/src/storages/AbstractSplitsCacheSync.ts +0 -95
  389. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +0 -234
  390. package/src/storages/inMemory/SplitsCacheInMemory.ts +0 -130
  391. package/src/storages/pluggable/SplitsCachePluggable.ts +0 -230
  392. package/src/sync/polling/updaters/splitChangesUpdater.ts +0 -230
  393. package/src/utils/inputValidation/split.ts +0 -27
  394. package/src/utils/inputValidation/splitExistence.ts +0 -19
  395. package/src/utils/inputValidation/splits.ts +0 -21
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefinitionsCacheInMemory = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var AbstractDefinitionsCacheSync_1 = require("../AbstractDefinitionsCacheSync");
6
+ var lang_1 = require("../../utils/lang");
7
+ /**
8
+ * Default IDefinitionsCacheSync implementation that stores split definitions in memory.
9
+ */
10
+ var DefinitionsCacheInMemory = /** @class */ (function (_super) {
11
+ tslib_1.__extends(DefinitionsCacheInMemory, _super);
12
+ function DefinitionsCacheInMemory(splitFiltersValidation) {
13
+ var _this = _super.call(this) || this;
14
+ _this.definitionsCache = {};
15
+ _this.ttCache = {};
16
+ _this.changeNumber = -1;
17
+ _this.segmentsCount = 0;
18
+ _this.setsCache = {};
19
+ _this.setsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
20
+ return _this;
21
+ }
22
+ DefinitionsCacheInMemory.prototype.clear = function () {
23
+ this.definitionsCache = {};
24
+ this.ttCache = {};
25
+ this.changeNumber = -1;
26
+ this.segmentsCount = 0;
27
+ this.setsCache = {};
28
+ };
29
+ DefinitionsCacheInMemory.prototype.add = function (definition) {
30
+ var name = definition.name;
31
+ var previousDefinition = this.get(name);
32
+ if (previousDefinition) { // We had this Split already
33
+ var previousTtName = previousDefinition.trafficTypeName;
34
+ this.ttCache[previousTtName]--;
35
+ if (!this.ttCache[previousTtName])
36
+ delete this.ttCache[previousTtName];
37
+ this.removeFromFlagSets(previousDefinition.name, previousDefinition.sets);
38
+ // Subtract from segments count for the previous version of this Split
39
+ if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(previousDefinition))
40
+ this.segmentsCount--;
41
+ }
42
+ // Store the Split.
43
+ this.definitionsCache[name] = definition;
44
+ // Update TT cache
45
+ var ttName = definition.trafficTypeName;
46
+ this.ttCache[ttName] = (this.ttCache[ttName] || 0) + 1;
47
+ this.addToFlagSets(definition);
48
+ // Add to segments count for the new version of the Split
49
+ if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(definition))
50
+ this.segmentsCount++;
51
+ return true;
52
+ };
53
+ DefinitionsCacheInMemory.prototype.remove = function (name) {
54
+ var definition = this.get(name);
55
+ if (!definition)
56
+ return false;
57
+ // Delete the Split
58
+ delete this.definitionsCache[name];
59
+ var ttName = definition.trafficTypeName;
60
+ this.ttCache[ttName]--; // Update tt cache
61
+ if (!this.ttCache[ttName])
62
+ delete this.ttCache[ttName];
63
+ this.removeFromFlagSets(definition.name, definition.sets);
64
+ // Update the segments count.
65
+ if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(definition))
66
+ this.segmentsCount--;
67
+ return true;
68
+ };
69
+ DefinitionsCacheInMemory.prototype.get = function (name) {
70
+ return this.definitionsCache[name] || null;
71
+ };
72
+ DefinitionsCacheInMemory.prototype.setChangeNumber = function (changeNumber) {
73
+ this.changeNumber = changeNumber;
74
+ return true;
75
+ };
76
+ DefinitionsCacheInMemory.prototype.getChangeNumber = function () {
77
+ return this.changeNumber;
78
+ };
79
+ DefinitionsCacheInMemory.prototype.getNames = function () {
80
+ return Object.keys(this.definitionsCache);
81
+ };
82
+ DefinitionsCacheInMemory.prototype.trafficTypeExists = function (trafficType) {
83
+ return (0, lang_1.isFiniteNumber)(this.ttCache[trafficType]) && this.ttCache[trafficType] > 0;
84
+ };
85
+ DefinitionsCacheInMemory.prototype.usesSegments = function () {
86
+ return this.getChangeNumber() === -1 || this.segmentsCount > 0;
87
+ };
88
+ DefinitionsCacheInMemory.prototype.getNamesBySets = function (sets) {
89
+ var _this = this;
90
+ return sets.map(function (set) { return _this.setsCache[set] || new Set(); });
91
+ };
92
+ DefinitionsCacheInMemory.prototype.addToFlagSets = function (featureFlag) {
93
+ var _this = this;
94
+ if (!featureFlag.sets)
95
+ return;
96
+ featureFlag.sets.forEach(function (featureFlagSet) {
97
+ if (_this.setsFilter.length > 0 && !_this.setsFilter.some(function (filterFlagSet) { return filterFlagSet === featureFlagSet; }))
98
+ return;
99
+ if (!_this.setsCache[featureFlagSet])
100
+ _this.setsCache[featureFlagSet] = new Set([]);
101
+ _this.setsCache[featureFlagSet].add(featureFlag.name);
102
+ });
103
+ };
104
+ DefinitionsCacheInMemory.prototype.removeFromFlagSets = function (featureFlagName, sets) {
105
+ var _this = this;
106
+ if (!sets)
107
+ return;
108
+ sets.forEach(function (set) {
109
+ _this.removeNames(set, featureFlagName);
110
+ });
111
+ };
112
+ DefinitionsCacheInMemory.prototype.removeNames = function (setName, featureFlagName) {
113
+ if (!this.setsCache[setName])
114
+ return;
115
+ this.setsCache[setName].delete(featureFlagName);
116
+ if (this.setsCache[setName].size === 0)
117
+ delete this.setsCache[setName];
118
+ };
119
+ return DefinitionsCacheInMemory;
120
+ }(AbstractDefinitionsCacheSync_1.AbstractDefinitionsCacheSync));
121
+ exports.DefinitionsCacheInMemory = DefinitionsCacheInMemory;
@@ -15,7 +15,7 @@ var ImpressionCountsCacheInMemory = /** @class */ (function () {
15
15
  * Builds key to be stored in the cache with the featureName and the timeFrame truncated.
16
16
  */
17
17
  ImpressionCountsCacheInMemory.prototype._makeKey = function (featureName, timeFrame) {
18
- return featureName + "::" + (0, time_1.truncateTimeFrame)(timeFrame);
18
+ return "".concat(featureName, "::").concat((0, time_1.truncateTimeFrame)(timeFrame));
19
19
  };
20
20
  /**
21
21
  * Increments the quantity of impressions with the passed featureName and timeFrame.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InMemoryStorageFactory = void 0;
4
- var SplitsCacheInMemory_1 = require("./SplitsCacheInMemory");
4
+ var DefinitionsCacheInMemory_1 = require("./DefinitionsCacheInMemory");
5
5
  var SegmentsCacheInMemory_1 = require("./SegmentsCacheInMemory");
6
6
  var ImpressionsCacheInMemory_1 = require("./ImpressionsCacheInMemory");
7
7
  var EventsCacheInMemory_1 = require("./EventsCacheInMemory");
@@ -17,17 +17,17 @@ var RBSegmentsCacheInMemory_1 = require("./RBSegmentsCacheInMemory");
17
17
  */
18
18
  function InMemoryStorageFactory(params) {
19
19
  var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
20
- var splits = new SplitsCacheInMemory_1.SplitsCacheInMemory(__splitFiltersValidation);
20
+ var definitions = new DefinitionsCacheInMemory_1.DefinitionsCacheInMemory(__splitFiltersValidation);
21
21
  var rbSegments = new RBSegmentsCacheInMemory_1.RBSegmentsCacheInMemory();
22
22
  var segments = new SegmentsCacheInMemory_1.SegmentsCacheInMemory();
23
23
  var storage = {
24
- splits: splits,
24
+ definitions: definitions,
25
25
  rbSegments: rbSegments,
26
26
  segments: segments,
27
27
  impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
28
28
  impressionCounts: new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory(),
29
29
  events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
30
- telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
30
+ telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(definitions, segments) : undefined,
31
31
  uniqueKeys: new UniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory(),
32
32
  destroy: function () { }
33
33
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InMemoryStorageCSFactory = void 0;
4
- var SplitsCacheInMemory_1 = require("./SplitsCacheInMemory");
4
+ var DefinitionsCacheInMemory_1 = require("./DefinitionsCacheInMemory");
5
5
  var MySegmentsCacheInMemory_1 = require("./MySegmentsCacheInMemory");
6
6
  var ImpressionsCacheInMemory_1 = require("./ImpressionsCacheInMemory");
7
7
  var EventsCacheInMemory_1 = require("./EventsCacheInMemory");
@@ -17,25 +17,25 @@ var RBSegmentsCacheInMemory_1 = require("./RBSegmentsCacheInMemory");
17
17
  */
18
18
  function InMemoryStorageCSFactory(params) {
19
19
  var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
20
- var splits = new SplitsCacheInMemory_1.SplitsCacheInMemory(__splitFiltersValidation);
20
+ var definitions = new DefinitionsCacheInMemory_1.DefinitionsCacheInMemory(__splitFiltersValidation);
21
21
  var rbSegments = new RBSegmentsCacheInMemory_1.RBSegmentsCacheInMemory();
22
22
  var segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
23
23
  var largeSegments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
24
24
  var storage = {
25
- splits: splits,
25
+ definitions: definitions,
26
26
  rbSegments: rbSegments,
27
27
  segments: segments,
28
28
  largeSegments: largeSegments,
29
29
  impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
30
30
  impressionCounts: new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory(),
31
31
  events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
32
- telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
32
+ telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(definitions, segments) : undefined,
33
33
  uniqueKeys: new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS(),
34
34
  destroy: function () { },
35
35
  // When using shared instantiation with MEMORY we reuse everything but segments (they are unique per key)
36
36
  shared: function () {
37
37
  return {
38
- splits: this.splits,
38
+ definitions: this.definitions,
39
39
  rbSegments: this.rbSegments,
40
40
  segments: new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(),
41
41
  largeSegments: new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(),
@@ -8,7 +8,7 @@ var AbstractMySegmentsCacheSync_1 = require("../AbstractMySegmentsCacheSync");
8
8
  * Supported by all JS runtimes.
9
9
  */
10
10
  var MySegmentsCacheInMemory = /** @class */ (function (_super) {
11
- (0, tslib_1.__extends)(MySegmentsCacheInMemory, _super);
11
+ tslib_1.__extends(MySegmentsCacheInMemory, _super);
12
12
  function MySegmentsCacheInMemory() {
13
13
  var _this = _super !== null && _super.apply(this, arguments) || this;
14
14
  _this.segmentCache = {};
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RBSegmentsCacheInMemory = void 0;
4
4
  var sets_1 = require("../../utils/lang/sets");
5
- var AbstractSplitsCacheSync_1 = require("../AbstractSplitsCacheSync");
5
+ var AbstractDefinitionsCacheSync_1 = require("../AbstractDefinitionsCacheSync");
6
6
  var RBSegmentsCacheInMemory = /** @class */ (function () {
7
7
  function RBSegmentsCacheInMemory() {
8
8
  this.cache = {};
@@ -17,17 +17,17 @@ var RBSegmentsCacheInMemory = /** @class */ (function () {
17
17
  RBSegmentsCacheInMemory.prototype.update = function (toAdd, toRemove, changeNumber) {
18
18
  var _this = this;
19
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;
20
+ updated = toRemove.map(function (toRemove) { return _this.remove(toRemove); }).some(function (result) { return result; }) || updated;
21
21
  this.changeNumber = changeNumber;
22
22
  return updated;
23
23
  };
24
24
  RBSegmentsCacheInMemory.prototype.add = function (rbSegment) {
25
25
  var name = rbSegment.name;
26
26
  var previous = this.get(name);
27
- if (previous && (0, AbstractSplitsCacheSync_1.usesSegments)(previous))
27
+ if (previous && (0, AbstractDefinitionsCacheSync_1.usesSegments)(previous))
28
28
  this.segmentsCount--;
29
29
  this.cache[name] = rbSegment;
30
- if ((0, AbstractSplitsCacheSync_1.usesSegments)(rbSegment))
30
+ if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(rbSegment))
31
31
  this.segmentsCount++;
32
32
  return true;
33
33
  };
@@ -36,7 +36,7 @@ var RBSegmentsCacheInMemory = /** @class */ (function () {
36
36
  if (!rbSegment)
37
37
  return false;
38
38
  delete this.cache[name];
39
- if ((0, AbstractSplitsCacheSync_1.usesSegments)(rbSegment))
39
+ if ((0, AbstractDefinitionsCacheSync_1.usesSegments)(rbSegment))
40
40
  this.segmentsCount--;
41
41
  return true;
42
42
  };
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SegmentsCacheInMemory = void 0;
4
4
  var lang_1 = require("../../utils/lang");
5
5
  /**
6
- * Default ISplitsCacheSync implementation for server-side that stores segments definitions in memory.
6
+ * Default IDefinitionsCacheSync implementation for server-side that stores segments definitions in memory.
7
7
  */
8
8
  var SegmentsCacheInMemory = /** @class */ (function () {
9
9
  function SegmentsCacheInMemory() {
@@ -19,13 +19,13 @@ var ACCEPTANCE_RANGE = 0.001;
19
19
  * All factory instances track telemetry on server-side, and 0.1% on client-side.
20
20
  */
21
21
  function shouldRecordTelemetry(_a) {
22
- var settings = _a.settings;
23
- return settings.mode !== constants_1.LOCALHOST_MODE && ((0, key_1.checkIfServerSide)(settings) || Math.random() <= ACCEPTANCE_RANGE);
22
+ var settings = _a.settings, disableTelemetry = _a.disableTelemetry;
23
+ return !disableTelemetry && settings.mode !== constants_1.LOCALHOST_MODE && ((0, key_1.checkIfServerSide)(settings) || Math.random() <= ACCEPTANCE_RANGE);
24
24
  }
25
25
  exports.shouldRecordTelemetry = shouldRecordTelemetry;
26
26
  var TelemetryCacheInMemory = /** @class */ (function () {
27
- function TelemetryCacheInMemory(splits, segments, largeSegments) {
28
- this.splits = splits;
27
+ function TelemetryCacheInMemory(definitions, segments, largeSegments) {
28
+ this.definitions = definitions;
29
29
  this.segments = segments;
30
30
  this.largeSegments = largeSegments;
31
31
  this.name = 'telemetry stats';
@@ -61,7 +61,7 @@ var TelemetryCacheInMemory = /** @class */ (function () {
61
61
  iQ: this.getImpressionStats(constants_1.QUEUED),
62
62
  iDe: this.getImpressionStats(constants_1.DEDUPED),
63
63
  iDr: this.getImpressionStats(constants_1.DROPPED),
64
- spC: this.splits && this.splits.getSplitNames().length,
64
+ spC: this.definitions && this.definitions.getNames().length,
65
65
  seC: this.segments && this.segments.getRegisteredSegments().length,
66
66
  skC: this.segments && this.segments.getKeysCount(),
67
67
  lsC: this.largeSegments && this.largeSegments.getRegisteredSegments().length,
@@ -0,0 +1,243 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefinitionsCacheInRedis = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var lang_1 = require("../../utils/lang");
6
+ var constants_1 = require("./constants");
7
+ var AbstractDefinitionsCacheAsync_1 = require("../AbstractDefinitionsCacheAsync");
8
+ var sets_1 = require("../../utils/lang/sets");
9
+ /**
10
+ * Discard errors for an answer of multiple operations.
11
+ */
12
+ function processPipelineAnswer(results) {
13
+ return results ? results.reduce(function (accum, errValuePair) {
14
+ if (errValuePair[0] === null)
15
+ accum.push(errValuePair[1]);
16
+ return accum;
17
+ }, []) : [];
18
+ }
19
+ /**
20
+ * IDefinitionsCacheAsync implementation that stores definitions in Redis.
21
+ * Supported by Node.js
22
+ */
23
+ var DefinitionsCacheInRedis = /** @class */ (function (_super) {
24
+ tslib_1.__extends(DefinitionsCacheInRedis, _super);
25
+ function DefinitionsCacheInRedis(log, keys, redis, splitFiltersValidation) {
26
+ var _this = _super.call(this) || this;
27
+ _this.log = log;
28
+ _this.redis = redis;
29
+ _this.keys = keys;
30
+ _this.setsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
31
+ // 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.
32
+ // But it is done just to avoid getting the ioredis message `Unhandled error event`.
33
+ _this.redis.on('error', function (e) {
34
+ _this.redisError = e;
35
+ });
36
+ _this.redis.on('connect', function () {
37
+ _this.redisError = undefined;
38
+ });
39
+ return _this;
40
+ }
41
+ DefinitionsCacheInRedis.prototype._decrementCounts = function (definition) {
42
+ var _this = this;
43
+ var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
44
+ return this.redis.decr(ttKey).then(function (count) {
45
+ if (count === 0)
46
+ return _this.redis.del(ttKey);
47
+ });
48
+ };
49
+ DefinitionsCacheInRedis.prototype._incrementCounts = function (definition) {
50
+ var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
51
+ return this.redis.incr(ttKey);
52
+ };
53
+ DefinitionsCacheInRedis.prototype._updateSets = function (definitionName, setsOfRemovedDefinition, setsOfAddedDefinition) {
54
+ var _this = this;
55
+ var removeFromSets = (0, sets_1.returnDifference)(setsOfRemovedDefinition, setsOfAddedDefinition);
56
+ var addToSets = (0, sets_1.returnDifference)(setsOfAddedDefinition, setsOfRemovedDefinition);
57
+ if (this.setsFilter.length > 0) {
58
+ addToSets = addToSets.filter(function (set) {
59
+ return _this.setsFilter.some(function (filterSet) { return filterSet === set; });
60
+ });
61
+ }
62
+ var items = [definitionName];
63
+ return Promise.all(tslib_1.__spreadArray(tslib_1.__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));
64
+ };
65
+ /**
66
+ * Add a given definition.
67
+ * The returned promise is resolved when the operation success
68
+ * or rejected if it fails (e.g., redis operation fails)
69
+ */
70
+ DefinitionsCacheInRedis.prototype.add = function (definition) {
71
+ var _this = this;
72
+ var name = definition.name;
73
+ var definitionKey = this.keys.buildDefinitionKey(name);
74
+ return this.redis.get(definitionKey).then(function (definitionFromStorage) {
75
+ // handling parsing error
76
+ var parsedPreviousDefinition, stringifiedNewDefinition;
77
+ try {
78
+ parsedPreviousDefinition = definitionFromStorage ? JSON.parse(definitionFromStorage) : undefined;
79
+ stringifiedNewDefinition = JSON.stringify(definition);
80
+ }
81
+ catch (e) {
82
+ throw new Error('Error parsing feature flag definition: ' + e);
83
+ }
84
+ return _this.redis.set(definitionKey, stringifiedNewDefinition).then(function () {
85
+ // avoid unnecessary increment/decrement operations
86
+ if (parsedPreviousDefinition && parsedPreviousDefinition.trafficTypeName === definition.trafficTypeName)
87
+ return;
88
+ // update traffic type counts
89
+ return _this._incrementCounts(definition).then(function () {
90
+ if (parsedPreviousDefinition)
91
+ return _this._decrementCounts(parsedPreviousDefinition);
92
+ });
93
+ }).then(function () { return _this._updateSets(name, parsedPreviousDefinition && parsedPreviousDefinition.sets, definition.sets); });
94
+ }).then(function () { return true; });
95
+ };
96
+ /**
97
+ * Remove a given definition.
98
+ * The returned promise is resolved when the operation success, with true or false indicating if the definition existed (and was removed) or not.
99
+ * or rejected if it fails (e.g., redis operation fails).
100
+ */
101
+ DefinitionsCacheInRedis.prototype.remove = function (name) {
102
+ var _this = this;
103
+ return this.get(name).then(function (definition) {
104
+ if (definition) {
105
+ return _this._decrementCounts(definition).then(function () { return _this._updateSets(name, definition.sets); });
106
+ }
107
+ }).then(function () {
108
+ return _this.redis.del(_this.keys.buildDefinitionKey(name)).then(function (status) { return status === 1; });
109
+ });
110
+ };
111
+ /**
112
+ * Get definition or null if it's not defined.
113
+ * Returned promise is rejected if redis operation fails.
114
+ */
115
+ DefinitionsCacheInRedis.prototype.get = function (name) {
116
+ if (this.redisError) {
117
+ this.log.error(constants_1.LOG_PREFIX + this.redisError);
118
+ return Promise.reject(this.redisError);
119
+ }
120
+ return this.redis.get(this.keys.buildDefinitionKey(name))
121
+ .then(function (maybeDefinition) { return maybeDefinition && JSON.parse(maybeDefinition); });
122
+ };
123
+ /**
124
+ * Set till number.
125
+ * The returned promise is resolved when the operation success,
126
+ * or rejected if it fails.
127
+ */
128
+ DefinitionsCacheInRedis.prototype.setChangeNumber = function (changeNumber) {
129
+ return this.redis.set(this.keys.buildDefinitionsTillKey(), changeNumber + '').then(function (status) { return status === 'OK'; });
130
+ };
131
+ /**
132
+ * Get till number or -1 if it's not defined.
133
+ * The returned promise is resolved with the changeNumber or -1 if it doesn't exist or a redis operation fails.
134
+ * The promise will never be rejected.
135
+ */
136
+ DefinitionsCacheInRedis.prototype.getChangeNumber = function () {
137
+ var _this = this;
138
+ return this.redis.get(this.keys.buildDefinitionsTillKey()).then(function (value) {
139
+ var i = parseInt(value, 10);
140
+ return (0, lang_1.isNaNNumber)(i) ? -1 : i;
141
+ }).catch(function (e) {
142
+ _this.log.error(constants_1.LOG_PREFIX + 'Could not retrieve changeNumber from storage. Error: ' + e);
143
+ return -1;
144
+ });
145
+ };
146
+ /**
147
+ * Get list of all definitions.
148
+ * The returned promise is resolved with the list of definitions,
149
+ * or rejected if redis operation fails.
150
+ */
151
+ // @TODO we need to benchmark which is the maximun number of commands we could pipeline without kill redis performance.
152
+ DefinitionsCacheInRedis.prototype.getAll = function () {
153
+ var _this = this;
154
+ return this.redis.keys(this.keys.searchPatternForDefinitionKeys())
155
+ .then(function (listOfKeys) { return _this.redis.pipeline(listOfKeys.map(function (k) { return ['get', k]; })).exec(); })
156
+ .then(processPipelineAnswer)
157
+ .then(function (definitions) { return definitions.map(function (definition) {
158
+ return JSON.parse(definition);
159
+ }); });
160
+ };
161
+ /**
162
+ * Get list of definition names.
163
+ * The returned promise is resolved with the list of names,
164
+ * or rejected if redis operation fails.
165
+ */
166
+ DefinitionsCacheInRedis.prototype.getNames = function () {
167
+ var _this = this;
168
+ return this.redis.keys(this.keys.searchPatternForDefinitionKeys()).then(function (listOfKeys) { return listOfKeys.map(_this.keys.extractKey); });
169
+ };
170
+ /**
171
+ * Get list of definition names related to a given list of set names.
172
+ * The returned promise is resolved with the list of names per set,
173
+ * or rejected if the pipelined redis operation fails (e.g., timeout).
174
+ */
175
+ DefinitionsCacheInRedis.prototype.getNamesBySets = function (sets) {
176
+ var _this = this;
177
+ return this.redis.pipeline(sets.map(function (set) { return ['smembers', _this.keys.buildSetKey(set)]; })).exec()
178
+ .then(function (results) { return results ? results.map(function (_a, index) {
179
+ var e = _a[0], value = _a[1];
180
+ if (e === null)
181
+ return value;
182
+ _this.log.error(constants_1.LOG_PREFIX + "Could not read result from get members of set ".concat(sets[index], " due to an error: ").concat(e));
183
+ }) : []; })
184
+ .then(function (namesBySets) { return namesBySets.map(function (namesBySet) { return new Set(namesBySet); }); });
185
+ };
186
+ /**
187
+ * Check traffic type existence.
188
+ * The returned promise is resolved with a boolean indicating whether the TT exist or not.
189
+ * In case of redis operation failure, the promise resolves with a true value, assuming that the TT might exist.
190
+ * It will never be rejected.
191
+ */
192
+ DefinitionsCacheInRedis.prototype.trafficTypeExists = function (trafficType) {
193
+ var _this = this;
194
+ // If there is a number there should be > 0, otherwise the TT is considered as not existent.
195
+ return this.redis.get(this.keys.buildTrafficTypeKey(trafficType))
196
+ .then(function (ttCount) {
197
+ if (ttCount === null)
198
+ return false; // if entry doesn't exist, means that TT doesn't exist
199
+ ttCount = parseInt(ttCount, 10);
200
+ if (!(0, lang_1.isFiniteNumber)(ttCount) || ttCount < 0) {
201
+ _this.log.info(constants_1.LOG_PREFIX + "Could not validate traffic type existence of ".concat(trafficType, " due to data corruption of some sorts."));
202
+ return false;
203
+ }
204
+ return ttCount > 0;
205
+ })
206
+ .catch(function (e) {
207
+ _this.log.error(constants_1.LOG_PREFIX + "Could not validate traffic type existence of ".concat(trafficType, " due to an error: ").concat(e, "."));
208
+ // If there is an error, bypass the validation so the event can get tracked.
209
+ return true;
210
+ });
211
+ };
212
+ // @TODO remove or implement. It is not being used.
213
+ DefinitionsCacheInRedis.prototype.clear = function () {
214
+ return Promise.resolve();
215
+ };
216
+ /**
217
+ * Fetches multiple definitions.
218
+ * Returned promise is rejected if redis operation fails.
219
+ */
220
+ DefinitionsCacheInRedis.prototype.getMany = function (names) {
221
+ var _a;
222
+ var _this = this;
223
+ if (this.redisError) {
224
+ this.log.error(constants_1.LOG_PREFIX + this.redisError);
225
+ return Promise.reject(this.redisError);
226
+ }
227
+ var keys = names.map(function (name) { return _this.keys.buildDefinitionKey(name); });
228
+ return (_a = this.redis).mget.apply(_a, keys).then(function (stringifiedDefinitions) {
229
+ var definitions = {};
230
+ names.forEach(function (name, idx) {
231
+ var definition = stringifiedDefinitions[idx];
232
+ definitions[name] = definition && JSON.parse(definition);
233
+ });
234
+ return Promise.resolve(definitions);
235
+ })
236
+ .catch(function (e) {
237
+ _this.log.error(constants_1.LOG_PREFIX + "Could not grab feature flags due to an error: ".concat(e, "."));
238
+ return Promise.reject(e);
239
+ });
240
+ };
241
+ return DefinitionsCacheInRedis;
242
+ }(AbstractDefinitionsCacheAsync_1.AbstractDefinitionsCacheAsync));
243
+ exports.DefinitionsCacheInRedis = DefinitionsCacheInRedis;
@@ -19,7 +19,7 @@ var EventsCacheInRedis = /** @class */ (function () {
19
19
  // We use boolean values to signal successful queueing
20
20
  .then(function () { return true; })
21
21
  .catch(function (err) {
22
- _this.log.error(constants_1.LOG_PREFIX + "Error adding event to queue: " + err + ".");
22
+ _this.log.error("".concat(constants_1.LOG_PREFIX, "Error adding event to queue: ").concat(err, "."));
23
23
  return false;
24
24
  });
25
25
  };
@@ -6,7 +6,7 @@ var lang_1 = require("../../utils/lang");
6
6
  var ImpressionCountsCacheInMemory_1 = require("../inMemory/ImpressionCountsCacheInMemory");
7
7
  var constants_1 = require("./constants");
8
8
  var ImpressionCountsCacheInRedis = /** @class */ (function (_super) {
9
- (0, tslib_1.__extends)(ImpressionCountsCacheInRedis, _super);
9
+ tslib_1.__extends(ImpressionCountsCacheInRedis, _super);
10
10
  function ImpressionCountsCacheInRedis(log, key, redis, impressionCountsCacheSize, refreshRate) {
11
11
  if (refreshRate === void 0) { refreshRate = constants_1.REFRESH_RATE; }
12
12
  var _this = _super.call(this, impressionCountsCacheSize) || this;
@@ -35,7 +35,7 @@ var ImpressionCountsCacheInRedis = /** @class */ (function (_super) {
35
35
  }
36
36
  })
37
37
  .catch(function (err) {
38
- _this.log.error(constants_1.LOG_PREFIX + "Error in impression counts pipeline: " + err + ".");
38
+ _this.log.error("".concat(constants_1.LOG_PREFIX, "Error in impression counts pipeline: ").concat(err, "."));
39
39
  return false;
40
40
  });
41
41
  };
@@ -58,17 +58,17 @@ var ImpressionCountsCacheInRedis = /** @class */ (function (_super) {
58
58
  (0, lang_1.forOwn)(counts, function (count, key) {
59
59
  var nameAndTime = key.split('::');
60
60
  if (nameAndTime.length !== 2) {
61
- _this.log.error(constants_1.LOG_PREFIX + "Error spliting key " + key);
61
+ _this.log.error("".concat(constants_1.LOG_PREFIX, "Error spliting key ").concat(key));
62
62
  return;
63
63
  }
64
64
  var timeFrame = parseInt(nameAndTime[1]);
65
65
  if (isNaN(timeFrame)) {
66
- _this.log.error(constants_1.LOG_PREFIX + "Error parsing time frame " + nameAndTime[1]);
66
+ _this.log.error("".concat(constants_1.LOG_PREFIX, "Error parsing time frame ").concat(nameAndTime[1]));
67
67
  return;
68
68
  }
69
69
  var rawCount = parseInt(count);
70
70
  if (isNaN(rawCount)) {
71
- _this.log.error(constants_1.LOG_PREFIX + "Error parsing raw count " + count);
71
+ _this.log.error("".concat(constants_1.LOG_PREFIX, "Error parsing raw count ").concat(count));
72
72
  return;
73
73
  }
74
74
  pf.push({
@@ -14,7 +14,7 @@ var ImpressionsCacheInRedis = /** @class */ (function () {
14
14
  ImpressionsCacheInRedis.prototype.track = function (impressions) {
15
15
  var _a;
16
16
  var _this = this;
17
- return (_a = this.redis).rpush.apply(_a, (0, tslib_1.__spreadArray)([this.key], (0, utils_1.impressionsToJSON)(impressions, this.metadata), false)).then(function (queuedCount) {
17
+ return (_a = this.redis).rpush.apply(_a, tslib_1.__spreadArray([this.key], (0, utils_1.impressionsToJSON)(impressions, this.metadata), false)).then(function (queuedCount) {
18
18
  // If this is the creation of the key on Redis, set the expiration for it in 1hr.
19
19
  if (queuedCount === impressions.length) {
20
20
  return _this.redis.expire(_this.key, IMPRESSIONS_TTL_REFRESH);
@@ -34,7 +34,7 @@ var RBSegmentsCacheInRedis = /** @class */ (function () {
34
34
  return _this.redis.set(key, stringifiedNewRBSegment).then(function () { return true; });
35
35
  })),
36
36
  Promise.all(toRemove.map(function (toRemove) {
37
- var key = _this.keys.buildRBSegmentKey(toRemove.name);
37
+ var key = _this.keys.buildRBSegmentKey(toRemove);
38
38
  return _this.redis.del(key).then(function (status) { return status === 1; });
39
39
  }))
40
40
  ]).then(function (_a) {