@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
@@ -49,7 +49,7 @@ var RedisAdapter = /** @class */ (function () {
49
49
  this._runningCommands = new Set();
50
50
  // Instantiate the client using the dynamic constructor
51
51
  var librarySettings = RedisAdapter._defineLibrarySettings(options);
52
- this.client = new (RedisConstructor.bind.apply(RedisConstructor, (0, tslib_1.__spreadArray)([void 0], librarySettings, false)))();
52
+ this.client = new (RedisConstructor.bind.apply(RedisConstructor, tslib_1.__spreadArray([void 0], librarySettings, false)))();
53
53
  this._listenToEvents();
54
54
  this._setTimeoutWrappers();
55
55
  this._setDisconnectWrapper();
@@ -61,9 +61,9 @@ var RedisAdapter = /** @class */ (function () {
61
61
  var _this = this;
62
62
  this.client.once('ready', function () {
63
63
  var commandsCount = _this._notReadyCommandsQueue ? _this._notReadyCommandsQueue.length : 0;
64
- _this.log.info(LOG_PREFIX + ("Redis connection established. Queued commands: " + commandsCount + "."));
64
+ _this.log.info(LOG_PREFIX + "Redis connection established. Queued commands: ".concat(commandsCount, "."));
65
65
  _this._notReadyCommandsQueue && _this._notReadyCommandsQueue.forEach(function (queued) {
66
- _this.log.info(LOG_PREFIX + ("Executing queued " + queued.name + " command."));
66
+ _this.log.info(LOG_PREFIX + "Executing queued ".concat(queued.name, " command."));
67
67
  queued.command().then(queued.resolve).catch(queued.reject);
68
68
  });
69
69
  // After the SDK is ready for the first time we'll stop queueing commands. This is just so we can keep handling BUR for them.
@@ -85,7 +85,7 @@ var RedisAdapter = /** @class */ (function () {
85
85
  params[_i] = arguments[_i];
86
86
  }
87
87
  function commandWrapper() {
88
- instance.log.debug(LOG_PREFIX + "Executing " + methodName + ".");
88
+ instance.log.debug("".concat(LOG_PREFIX, "Executing ").concat(methodName, "."));
89
89
  var result = originalMethod.apply(bindTarget, params);
90
90
  if ((0, thenable_1.thenable)(result)) {
91
91
  // For handling pending commands on disconnect, add to the set and remove once finished.
@@ -97,7 +97,7 @@ var RedisAdapter = /** @class */ (function () {
97
97
  // Both success and error remove from queue.
98
98
  result.then(cleanUpRunningCommandsCb, cleanUpRunningCommandsCb);
99
99
  return (0, timeout_1.timeout)(instance._options.operationTimeout, result).catch(function (err) {
100
- instance.log.error("" + LOG_PREFIX + methodName + " operation threw an error or exceeded configured timeout of " + instance._options.operationTimeout + "ms. Message: " + err);
100
+ instance.log.error("".concat(LOG_PREFIX).concat(methodName, " operation threw an error or exceeded configured timeout of ").concat(instance._options.operationTimeout, "ms. Message: ").concat(err));
101
101
  // Handling is not the adapter responsibility.
102
102
  throw err;
103
103
  });
@@ -135,7 +135,7 @@ var RedisAdapter = /** @class */ (function () {
135
135
  }
136
136
  var res = originalFn.apply(instance.client, args);
137
137
  var originalExec = res.exec;
138
- res.exec = wrapCommand(originalExec, methodName + ".exec", res);
138
+ res.exec = wrapCommand(originalExec, "".concat(methodName, ".exec"), res);
139
139
  return res;
140
140
  };
141
141
  });
@@ -150,14 +150,14 @@ var RedisAdapter = /** @class */ (function () {
150
150
  }
151
151
  setTimeout(function deferredDisconnect() {
152
152
  if (instance._runningCommands.size > 0) {
153
- instance.log.info(LOG_PREFIX + ("Attempting to disconnect but there are " + instance._runningCommands.size + " commands still waiting for resolution. Defering disconnection until those finish."));
153
+ instance.log.info(LOG_PREFIX + "Attempting to disconnect but there are ".concat(instance._runningCommands.size, " commands still waiting for resolution. Defering disconnection until those finish."));
154
154
  Promise.all((0, sets_1.setToArray)(instance._runningCommands))
155
155
  .then(function () {
156
156
  instance.log.debug(LOG_PREFIX + 'Pending commands finished successfully, disconnecting.');
157
157
  originalMethod.apply(instance.client, params);
158
158
  })
159
159
  .catch(function (e) {
160
- instance.log.warn(LOG_PREFIX + ("Pending commands finished with error: " + e + ". Proceeding with disconnection."));
160
+ instance.log.warn(LOG_PREFIX + "Pending commands finished with error: ".concat(e, ". Proceeding with disconnection."));
161
161
  originalMethod.apply(instance.client, params);
162
162
  });
163
163
  }
@@ -45,17 +45,17 @@ var TelemetryCacheInRedis = /** @class */ (function () {
45
45
  Object.keys(latencies).forEach(function (field) {
46
46
  var parsedField = (0, utils_1.parseLatencyField)(field);
47
47
  if ((0, lang_1.isString)(parsedField)) {
48
- _this.log.error("Ignoring invalid latency field: " + field + ": " + parsedField);
48
+ _this.log.error("Ignoring invalid latency field: ".concat(field, ": ").concat(parsedField));
49
49
  return;
50
50
  }
51
51
  var count = parseInt(latencies[field]);
52
52
  if ((0, lang_1.isNaNNumber)(count)) {
53
- _this.log.error("Ignoring latency with invalid count: " + latencies[field]);
53
+ _this.log.error("Ignoring latency with invalid count: ".concat(latencies[field]));
54
54
  return;
55
55
  }
56
56
  var metadata = parsedField[0], method = parsedField[1], bucket = parsedField[2];
57
57
  if (bucket >= TelemetryCacheInMemory_1.MAX_LATENCY_BUCKET_COUNT) {
58
- _this.log.error("Ignoring latency with invalid bucket: " + bucket);
58
+ _this.log.error("Ignoring latency with invalid bucket: ".concat(bucket));
59
59
  return;
60
60
  }
61
61
  var methodLatencies = result.get(metadata) || {};
@@ -77,12 +77,12 @@ var TelemetryCacheInRedis = /** @class */ (function () {
77
77
  Object.keys(exceptions).forEach(function (field) {
78
78
  var parsedField = (0, utils_1.parseExceptionField)(field);
79
79
  if ((0, lang_1.isString)(parsedField)) {
80
- _this.log.error("Ignoring invalid exception field: " + field + ": " + parsedField);
80
+ _this.log.error("Ignoring invalid exception field: ".concat(field, ": ").concat(parsedField));
81
81
  return;
82
82
  }
83
83
  var count = parseInt(exceptions[field]);
84
84
  if ((0, lang_1.isNaNNumber)(count)) {
85
- _this.log.error("Ignoring exception with invalid count: " + exceptions[field]);
85
+ _this.log.error("Ignoring exception with invalid count: ".concat(exceptions[field]));
86
86
  return;
87
87
  }
88
88
  var metadata = parsedField[0], method = parsedField[1];
@@ -104,7 +104,7 @@ var TelemetryCacheInRedis = /** @class */ (function () {
104
104
  Object.keys(configs).forEach(function (field) {
105
105
  var parsedField = (0, utils_1.parseMetadata)(field);
106
106
  if ((0, lang_1.isString)(parsedField)) {
107
- _this.log.error("Ignoring invalid config field: " + field + ": " + parsedField);
107
+ _this.log.error("Ignoring invalid config field: ".concat(field, ": ").concat(parsedField));
108
108
  return;
109
109
  }
110
110
  var metadata = parsedField[0];
@@ -113,7 +113,7 @@ var TelemetryCacheInRedis = /** @class */ (function () {
113
113
  result.set(metadata, config);
114
114
  }
115
115
  catch (e) {
116
- _this.log.error("Ignoring invalid config: " + configs[field]);
116
+ _this.log.error("Ignoring invalid config: ".concat(configs[field]));
117
117
  }
118
118
  });
119
119
  return _this.redis.del(_this.keys.initPrefix).then(function () { return result; });
@@ -7,7 +7,7 @@ var constants_1 = require("./constants");
7
7
  var constants_2 = require("./constants");
8
8
  var sets_1 = require("../../utils/lang/sets");
9
9
  var UniqueKeysCacheInRedis = /** @class */ (function (_super) {
10
- (0, tslib_1.__extends)(UniqueKeysCacheInRedis, _super);
10
+ tslib_1.__extends(UniqueKeysCacheInRedis, _super);
11
11
  function UniqueKeysCacheInRedis(log, key, redis, uniqueKeysQueueSize, refreshRate) {
12
12
  if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = constants_1.DEFAULT_CACHE_SIZE; }
13
13
  if (refreshRate === void 0) { refreshRate = constants_1.REFRESH_RATE; }
@@ -34,14 +34,14 @@ var UniqueKeysCacheInRedis = /** @class */ (function (_super) {
34
34
  return JSON.stringify(uniqueKeysPayload);
35
35
  });
36
36
  this.clear();
37
- return (_a = this.redis).rpush.apply(_a, (0, tslib_1.__spreadArray)([this.key], uniqueKeysArray, false)).then(function (data) {
37
+ return (_a = this.redis).rpush.apply(_a, tslib_1.__spreadArray([this.key], uniqueKeysArray, false)).then(function (data) {
38
38
  // If this is the creation of the key on Redis, set the expiration for it in 3600 seconds.
39
39
  if (data === featureNames.length) {
40
40
  return _this.redis.expire(_this.key, constants_1.TTL_REFRESH);
41
41
  }
42
42
  })
43
43
  .catch(function (err) {
44
- _this.log.error(constants_2.LOG_PREFIX + "Error in uniqueKeys pipeline: " + err + ".");
44
+ _this.log.error("".concat(constants_2.LOG_PREFIX, "Error in uniqueKeys pipeline: ").concat(err, "."));
45
45
  return false;
46
46
  });
47
47
  };
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InRedisStorage = void 0;
4
4
  var KeyBuilder_1 = require("../KeyBuilder");
5
5
  var KeyBuilderSS_1 = require("../KeyBuilderSS");
6
- var SplitsCacheInRedis_1 = require("./SplitsCacheInRedis");
6
+ var DefinitionsCacheInRedis_1 = require("./DefinitionsCacheInRedis");
7
7
  var SegmentsCacheInRedis_1 = require("./SegmentsCacheInRedis");
8
8
  var ImpressionsCacheInRedis_1 = require("./ImpressionsCacheInRedis");
9
9
  var EventsCacheInRedis_1 = require("./EventsCacheInRedis");
@@ -48,7 +48,7 @@ function InRedisStorage(options) {
48
48
  telemetry.recordConfig();
49
49
  });
50
50
  return {
51
- splits: new SplitsCacheInRedis_1.SplitsCacheInRedis(log, keys, redisClient, settings.sync.__splitFiltersValidation),
51
+ definitions: new DefinitionsCacheInRedis_1.DefinitionsCacheInRedis(log, keys, redisClient, settings.sync.__splitFiltersValidation),
52
52
  rbSegments: new RBSegmentsCacheInRedis_1.RBSegmentsCacheInRedis(log, keys, redisClient),
53
53
  segments: new SegmentsCacheInRedis_1.SegmentsCacheInRedis(log, keys, redisClient),
54
54
  impressions: new ImpressionsCacheInRedis_1.ImpressionsCacheInRedis(log, keys.buildImpressionsKey(), redisClient, metadata),
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefinitionsCachePluggable = 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
+ * IDefinitionsCacheAsync implementation for pluggable storages.
11
+ */
12
+ var DefinitionsCachePluggable = /** @class */ (function (_super) {
13
+ tslib_1.__extends(DefinitionsCachePluggable, _super);
14
+ /**
15
+ * Create a DefinitionsCache that uses a storage wrapper.
16
+ * @param log - Logger instance.
17
+ * @param keys - Key builder.
18
+ * @param wrapper - Adapted wrapper storage.
19
+ */
20
+ function DefinitionsCachePluggable(log, keys, wrapper, splitFiltersValidation) {
21
+ var _this = _super.call(this) || this;
22
+ _this.log = log;
23
+ _this.keys = keys;
24
+ _this.wrapper = wrapper;
25
+ _this.setsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
26
+ return _this;
27
+ }
28
+ DefinitionsCachePluggable.prototype._decrementCounts = function (definition) {
29
+ var _this = this;
30
+ var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
31
+ return this.wrapper.decr(ttKey).then(function (count) {
32
+ if (count === 0)
33
+ return _this.wrapper.del(ttKey);
34
+ });
35
+ };
36
+ DefinitionsCachePluggable.prototype._incrementCounts = function (definition) {
37
+ var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
38
+ return this.wrapper.incr(ttKey);
39
+ };
40
+ DefinitionsCachePluggable.prototype._updateSets = function (definitionName, setsOfRemovedDefinition, setsOfAddedDefinition) {
41
+ var _this = this;
42
+ var removeFromSets = (0, sets_1.returnDifference)(setsOfRemovedDefinition, setsOfAddedDefinition);
43
+ var addToSets = (0, sets_1.returnDifference)(setsOfAddedDefinition, setsOfRemovedDefinition);
44
+ if (this.setsFilter.length > 0) {
45
+ addToSets = addToSets.filter(function (set) {
46
+ return _this.setsFilter.some(function (filterSet) { return filterSet === set; });
47
+ });
48
+ }
49
+ var items = [definitionName];
50
+ return Promise.all(tslib_1.__spreadArray(tslib_1.__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));
51
+ };
52
+ /**
53
+ * Add a given definition.
54
+ * The returned promise is resolved when the operation success
55
+ * or rejected if it fails (e.g., wrapper operation fails)
56
+ */
57
+ DefinitionsCachePluggable.prototype.add = function (definition) {
58
+ var _this = this;
59
+ var name = definition.name;
60
+ var definitionKey = this.keys.buildDefinitionKey(name);
61
+ return this.wrapper.get(definitionKey).then(function (definitionFromStorage) {
62
+ // handling parsing error
63
+ var parsedPreviousDefinition, stringifiedNewDefinition;
64
+ try {
65
+ parsedPreviousDefinition = definitionFromStorage ? JSON.parse(definitionFromStorage) : undefined;
66
+ stringifiedNewDefinition = JSON.stringify(definition);
67
+ }
68
+ catch (e) {
69
+ throw new Error('Error parsing feature flag definition: ' + e);
70
+ }
71
+ return _this.wrapper.set(definitionKey, stringifiedNewDefinition).then(function () {
72
+ // avoid unnecessary increment/decrement operations
73
+ if (parsedPreviousDefinition && parsedPreviousDefinition.trafficTypeName === definition.trafficTypeName)
74
+ return;
75
+ // update traffic type counts
76
+ return _this._incrementCounts(definition).then(function () {
77
+ if (parsedPreviousDefinition)
78
+ return _this._decrementCounts(parsedPreviousDefinition);
79
+ });
80
+ }).then(function () { return _this._updateSets(name, parsedPreviousDefinition && parsedPreviousDefinition.sets, definition.sets); });
81
+ }).then(function () { return true; });
82
+ };
83
+ /**
84
+ * Remove a given definition.
85
+ * The returned promise is resolved when the operation success, with a boolean indicating if the definition existed or not.
86
+ * or rejected if it fails (e.g., wrapper operation fails).
87
+ */
88
+ DefinitionsCachePluggable.prototype.remove = function (name) {
89
+ var _this = this;
90
+ return this.get(name).then(function (definition) {
91
+ if (definition) {
92
+ return _this._decrementCounts(definition).then(function () { return _this._updateSets(name, definition.sets); });
93
+ }
94
+ }).then(function () {
95
+ return _this.wrapper.del(_this.keys.buildDefinitionKey(name));
96
+ });
97
+ };
98
+ /**
99
+ * Get definition.
100
+ * The returned promise is resolved with the definition or null if it's not defined,
101
+ * or rejected if wrapper operation fails.
102
+ */
103
+ DefinitionsCachePluggable.prototype.get = function (name) {
104
+ return this.wrapper.get(this.keys.buildDefinitionKey(name))
105
+ .then(function (maybeDefinition) { return maybeDefinition && JSON.parse(maybeDefinition); });
106
+ };
107
+ /**
108
+ * Get list of definitions.
109
+ * The returned promise is resolved with a map of names to their definition or null if it's not defined,
110
+ * or rejected if wrapper operation fails.
111
+ */
112
+ DefinitionsCachePluggable.prototype.getMany = function (names) {
113
+ var _this = this;
114
+ var keys = names.map(function (name) { return _this.keys.buildDefinitionKey(name); });
115
+ return this.wrapper.getMany(keys).then(function (stringifiedDefinitions) {
116
+ var definitions = {};
117
+ names.forEach(function (name, idx) {
118
+ var definition = stringifiedDefinitions[idx];
119
+ definitions[name] = definition && JSON.parse(definition);
120
+ });
121
+ return Promise.resolve(definitions);
122
+ });
123
+ };
124
+ /**
125
+ * Get list of all definitions.
126
+ * The returned promise is resolved with the list of definitions,
127
+ * or rejected if wrapper operation fails.
128
+ */
129
+ DefinitionsCachePluggable.prototype.getAll = function () {
130
+ var _this = this;
131
+ return this.wrapper.getKeysByPrefix(this.keys.buildDefinitionKeyPrefix())
132
+ .then(function (listOfKeys) { return _this.wrapper.getMany(listOfKeys); })
133
+ .then(function (definitions) { return definitions.map(function (definition) {
134
+ return JSON.parse(definition);
135
+ }); });
136
+ };
137
+ /**
138
+ * Get list of definition names.
139
+ * The returned promise is resolved with the list of names,
140
+ * or rejected if wrapper operation fails.
141
+ */
142
+ DefinitionsCachePluggable.prototype.getNames = function () {
143
+ var _this = this;
144
+ return this.wrapper.getKeysByPrefix(this.keys.buildDefinitionKeyPrefix()).then(function (listOfKeys) { return listOfKeys.map(_this.keys.extractKey); });
145
+ };
146
+ /**
147
+ * Get list of definition names related to a given list of set names.
148
+ * The returned promise is resolved with the list of names per set.
149
+ * It never rejects (If there is a wrapper error for some set, an empty set is returned for it).
150
+ */
151
+ DefinitionsCachePluggable.prototype.getNamesBySets = function (sets) {
152
+ var _this = this;
153
+ return Promise.all(sets.map(function (set) {
154
+ var setKey = _this.keys.buildSetKey(set);
155
+ return _this.wrapper.getItems(setKey).catch(function () { return []; });
156
+ })).then(function (namesBySets) { return namesBySets.map(function (namesBySet) { return new Set(namesBySet); }); });
157
+ };
158
+ /**
159
+ * Check traffic type existence.
160
+ * The returned promise is resolved with a boolean indicating whether the TT exist or not.
161
+ * In case of wrapper operation failures, the promise resolves with a true value, assuming that the TT might exist.
162
+ * It will never be rejected.
163
+ */
164
+ DefinitionsCachePluggable.prototype.trafficTypeExists = function (trafficType) {
165
+ var _this = this;
166
+ // If there is a number there should be > 0, otherwise the TT is considered as not existent.
167
+ return this.wrapper.get(this.keys.buildTrafficTypeKey(trafficType))
168
+ .then(function (ttCount) {
169
+ if (ttCount === null)
170
+ return false; // if entry doesn't exist, means that TT doesn't exist
171
+ ttCount = parseInt(ttCount, 10);
172
+ if (!(0, lang_1.isFiniteNumber)(ttCount) || ttCount < 0) {
173
+ _this.log.info(constants_1.LOG_PREFIX + "Could not validate traffic type existence of ".concat(trafficType, " due to data corruption of some sorts."));
174
+ return false;
175
+ }
176
+ return ttCount > 0;
177
+ }).catch(function (e) {
178
+ _this.log.error(constants_1.LOG_PREFIX + "Could not validate traffic type existence of ".concat(trafficType, " due to an error: ").concat(e, "."));
179
+ // If there is an error, bypass the validation so the event can get tracked.
180
+ return true;
181
+ });
182
+ };
183
+ /**
184
+ * Set till number.
185
+ * The returned promise is resolved when the operation success,
186
+ * or rejected if it fails (e.g., wrapper operation fails).
187
+ */
188
+ DefinitionsCachePluggable.prototype.setChangeNumber = function (changeNumber) {
189
+ return this.wrapper.set(this.keys.buildDefinitionsTillKey(), changeNumber + '');
190
+ };
191
+ /**
192
+ * Get till number or -1 if it's not defined.
193
+ * The returned promise is resolved with the changeNumber or -1 if it doesn't exist or a wrapper operation fails.
194
+ * The promise will never be rejected.
195
+ */
196
+ DefinitionsCachePluggable.prototype.getChangeNumber = function () {
197
+ var _this = this;
198
+ return this.wrapper.get(this.keys.buildDefinitionsTillKey()).then(function (value) {
199
+ var i = parseInt(value, 10);
200
+ return (0, lang_1.isNaNNumber)(i) ? -1 : i;
201
+ }).catch(function (e) {
202
+ _this.log.error(constants_1.LOG_PREFIX + 'Could not retrieve changeNumber from storage. Error: ' + e);
203
+ return -1;
204
+ });
205
+ };
206
+ // @TODO implement if required by DataLoader or producer mode
207
+ DefinitionsCachePluggable.prototype.clear = function () {
208
+ return Promise.resolve(true);
209
+ };
210
+ return DefinitionsCachePluggable;
211
+ }(AbstractDefinitionsCacheAsync_1.AbstractDefinitionsCacheAsync));
212
+ exports.DefinitionsCachePluggable = DefinitionsCachePluggable;
@@ -21,7 +21,7 @@ var EventsCachePluggable = /** @class */ (function () {
21
21
  // We use boolean values to signal successful queueing
22
22
  .then(function () { return true; })
23
23
  .catch(function (e) {
24
- _this.log.error(constants_1.LOG_PREFIX + "Error adding event to queue: " + e + ".");
24
+ _this.log.error("".concat(constants_1.LOG_PREFIX, "Error adding event to queue: ").concat(e, "."));
25
25
  return false;
26
26
  });
27
27
  };
@@ -6,7 +6,7 @@ var ImpressionCountsCacheInMemory_1 = require("../inMemory/ImpressionCountsCache
6
6
  var constants_1 = require("../inRedis/constants");
7
7
  var constants_2 = require("./constants");
8
8
  var ImpressionCountsCachePluggable = /** @class */ (function (_super) {
9
- (0, tslib_1.__extends)(ImpressionCountsCachePluggable, _super);
9
+ tslib_1.__extends(ImpressionCountsCachePluggable, _super);
10
10
  function ImpressionCountsCachePluggable(log, key, wrapper, impressionCountsCacheSize, refreshRate) {
11
11
  if (refreshRate === void 0) { refreshRate = constants_1.REFRESH_RATE; }
12
12
  var _this = _super.call(this, impressionCountsCacheSize) || this;
@@ -24,10 +24,10 @@ var ImpressionCountsCachePluggable = /** @class */ (function (_super) {
24
24
  if (!keys.length)
25
25
  return Promise.resolve(false);
26
26
  var pipeline = keys.reduce(function (pipeline, key) {
27
- return pipeline.then(function () { return _this.wrapper.incr(_this.key + "::" + key, counts[key]); });
27
+ return pipeline.then(function () { return _this.wrapper.incr("".concat(_this.key, "::").concat(key), counts[key]); });
28
28
  }, Promise.resolve());
29
29
  return pipeline.catch(function (err) {
30
- _this.log.error(constants_2.LOG_PREFIX + "Error in impression counts pipeline: " + err + ".");
30
+ _this.log.error("".concat(constants_2.LOG_PREFIX, "Error in impression counts pipeline: ").concat(err, "."));
31
31
  return false;
32
32
  });
33
33
  };
@@ -52,18 +52,18 @@ var ImpressionCountsCachePluggable = /** @class */ (function (_super) {
52
52
  var count = counts[i];
53
53
  var keyFeatureNameAndTime = key.split('::');
54
54
  if (keyFeatureNameAndTime.length !== 3) {
55
- _this.log.error(constants_2.LOG_PREFIX + "Error spliting key " + key);
55
+ _this.log.error("".concat(constants_2.LOG_PREFIX, "Error spliting key ").concat(key));
56
56
  continue;
57
57
  }
58
58
  var timeFrame = parseInt(keyFeatureNameAndTime[2]);
59
59
  if (isNaN(timeFrame)) {
60
- _this.log.error(constants_2.LOG_PREFIX + "Error parsing time frame " + keyFeatureNameAndTime[2]);
60
+ _this.log.error("".concat(constants_2.LOG_PREFIX, "Error parsing time frame ").concat(keyFeatureNameAndTime[2]));
61
61
  continue;
62
62
  }
63
63
  // @ts-ignore
64
64
  var rawCount = parseInt(count);
65
65
  if (isNaN(rawCount)) {
66
- _this.log.error(constants_2.LOG_PREFIX + "Error parsing raw count " + count);
66
+ _this.log.error("".concat(constants_2.LOG_PREFIX, "Error parsing raw count ").concat(count));
67
67
  continue;
68
68
  }
69
69
  pf.push({
@@ -34,7 +34,7 @@ var RBSegmentsCachePluggable = /** @class */ (function () {
34
34
  return _this.wrapper.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.wrapper.del(key);
39
39
  }))
40
40
  ]).then(function (_a) {
@@ -45,18 +45,18 @@ var TelemetryCachePluggable = /** @class */ (function () {
45
45
  var field = latencyKeys[i].split('::')[1];
46
46
  var parsedField = (0, utils_1.parseLatencyField)(field);
47
47
  if ((0, lang_1.isString)(parsedField)) {
48
- _this.log.error("Ignoring invalid latency field: " + field + ": " + parsedField);
48
+ _this.log.error("Ignoring invalid latency field: ".concat(field, ": ").concat(parsedField));
49
49
  continue;
50
50
  }
51
51
  // @ts-ignore
52
52
  var count = parseInt(latencies[i]);
53
53
  if ((0, lang_1.isNaNNumber)(count)) {
54
- _this.log.error("Ignoring latency with invalid count: " + latencies[i]);
54
+ _this.log.error("Ignoring latency with invalid count: ".concat(latencies[i]));
55
55
  continue;
56
56
  }
57
57
  var metadata = parsedField[0], method = parsedField[1], bucket = parsedField[2];
58
58
  if (bucket >= TelemetryCacheInMemory_1.MAX_LATENCY_BUCKET_COUNT) {
59
- _this.log.error("Ignoring latency with invalid bucket: " + bucket);
59
+ _this.log.error("Ignoring latency with invalid bucket: ".concat(bucket));
60
60
  continue;
61
61
  }
62
62
  var methodLatencies = result.get(metadata) || {};
@@ -84,13 +84,13 @@ var TelemetryCachePluggable = /** @class */ (function () {
84
84
  var field = exceptionKeys[i].split('::')[1];
85
85
  var parsedField = (0, utils_1.parseExceptionField)(field);
86
86
  if ((0, lang_1.isString)(parsedField)) {
87
- _this.log.error("Ignoring invalid exception field: " + field + ": " + parsedField);
87
+ _this.log.error("Ignoring invalid exception field: ".concat(field, ": ").concat(parsedField));
88
88
  continue;
89
89
  }
90
90
  // @ts-ignore
91
91
  var count = parseInt(exceptions[i]);
92
92
  if ((0, lang_1.isNaNNumber)(count)) {
93
- _this.log.error("Ignoring exception with invalid count: " + exceptions[i]);
93
+ _this.log.error("Ignoring exception with invalid count: ".concat(exceptions[i]));
94
94
  continue;
95
95
  }
96
96
  var metadata = parsedField[0], method = parsedField[1];
@@ -118,7 +118,7 @@ var TelemetryCachePluggable = /** @class */ (function () {
118
118
  var field = configKeys[i].split('::')[1];
119
119
  var parsedField = (0, utils_1.parseMetadata)(field);
120
120
  if ((0, lang_1.isString)(parsedField)) {
121
- _this.log.error("Ignoring invalid config field: " + field + ": " + parsedField);
121
+ _this.log.error("Ignoring invalid config field: ".concat(field, ": ").concat(parsedField));
122
122
  continue;
123
123
  }
124
124
  var metadata = parsedField[0];
@@ -127,7 +127,7 @@ var TelemetryCachePluggable = /** @class */ (function () {
127
127
  result.set(metadata, config);
128
128
  }
129
129
  catch (e) {
130
- _this.log.error("Ignoring invalid config: " + configs[i]);
130
+ _this.log.error("Ignoring invalid config: ".concat(configs[i]));
131
131
  }
132
132
  }
133
133
  return Promise.all(configKeys.map(function (configKey) { return _this.wrapper.del(configKey); })).then(function () { return result; });
@@ -7,7 +7,7 @@ var constants_1 = require("../inRedis/constants");
7
7
  var constants_2 = require("./constants");
8
8
  var sets_1 = require("../../utils/lang/sets");
9
9
  var UniqueKeysCachePluggable = /** @class */ (function (_super) {
10
- (0, tslib_1.__extends)(UniqueKeysCachePluggable, _super);
10
+ tslib_1.__extends(UniqueKeysCachePluggable, _super);
11
11
  function UniqueKeysCachePluggable(log, key, wrapper, uniqueKeysQueueSize, refreshRate) {
12
12
  if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = constants_1.DEFAULT_CACHE_SIZE; }
13
13
  if (refreshRate === void 0) { refreshRate = constants_1.REFRESH_RATE; }
@@ -35,7 +35,7 @@ var UniqueKeysCachePluggable = /** @class */ (function (_super) {
35
35
  this.clear();
36
36
  return this.wrapper.pushItems(this.key, uniqueKeysArray)
37
37
  .catch(function (err) {
38
- _this.log.error(constants_2.LOG_PREFIX + "Error in uniqueKeys pipeline: " + err + ".");
38
+ _this.log.error("".concat(constants_2.LOG_PREFIX, "Error in uniqueKeys pipeline: ").concat(err, "."));
39
39
  return false;
40
40
  });
41
41
  };
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PluggableStorage = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var KeyBuilderSS_1 = require("../KeyBuilderSS");
6
- var SplitsCachePluggable_1 = require("./SplitsCachePluggable");
6
+ var DefinitionsCachePluggable_1 = require("./DefinitionsCachePluggable");
7
7
  var SegmentsCachePluggable_1 = require("./SegmentsCachePluggable");
8
8
  var ImpressionsCachePluggable_1 = require("./ImpressionsCachePluggable");
9
9
  var EventsCachePluggable_1 = require("./EventsCachePluggable");
@@ -38,7 +38,7 @@ function validatePluggableStorageOptions(options) {
38
38
  var wrapper = options.wrapper;
39
39
  var missingMethods = wrapperAdapter_1.METHODS_TO_PROMISE_WRAP.filter(function (method) { return typeof wrapper[method] !== 'function'; });
40
40
  if (missingMethods.length)
41
- throw new Error(NO_VALID_WRAPPER_INTERFACE + " The following methods are missing or invalid: " + missingMethods);
41
+ throw new Error("".concat(NO_VALID_WRAPPER_INTERFACE, " The following methods are missing or invalid: ").concat(missingMethods));
42
42
  }
43
43
  // Async return type in `client.track` method on consumer partial mode
44
44
  // No need to promisify impressions cache
@@ -82,7 +82,7 @@ function PluggableStorage(options) {
82
82
  var currentHash = (0, KeyBuilder_1.getStorageHash)(settings);
83
83
  if (hash !== currentHash) {
84
84
  log.info(constants_2.LOG_PREFIX + 'Storage HASH has changed (SDK key, flags filter criteria or flags spec version was modified). Clearing cache');
85
- return wrapper.getKeysByPrefix(keys.prefix + ".").then(function (storageKeys) {
85
+ return wrapper.getKeysByPrefix("".concat(keys.prefix, ".")).then(function (storageKeys) {
86
86
  return Promise.all(storageKeys.map(function (storageKey) { return wrapper.del(storageKey); }));
87
87
  }).then(function () { return wrapper.set(keys.buildHashKey(), currentHash); });
88
88
  }
@@ -106,7 +106,7 @@ function PluggableStorage(options) {
106
106
  return e; // Propagate error for shared clients
107
107
  });
108
108
  return {
109
- splits: new SplitsCachePluggable_1.SplitsCachePluggable(log, keys, wrapper, settings.sync.__splitFiltersValidation),
109
+ definitions: new DefinitionsCachePluggable_1.DefinitionsCachePluggable(log, keys, wrapper, settings.sync.__splitFiltersValidation),
110
110
  rbSegments: new RBSegmentsCachePluggable_1.RBSegmentsCachePluggable(log, keys, wrapper),
111
111
  segments: new SegmentsCachePluggable_1.SegmentsCachePluggable(log, keys, wrapper),
112
112
  impressions: isPartialConsumer ? new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize) : new ImpressionsCachePluggable_1.ImpressionsCachePluggable(log, keys.buildImpressionsKey(), wrapper, metadata),
@@ -124,7 +124,7 @@ function PluggableStorage(options) {
124
124
  // emits SDK_READY event on shared clients and returns a reference to the storage
125
125
  shared: function (_, onReadyCb) {
126
126
  connectPromise.then(onReadyCb);
127
- return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, this), {
127
+ return tslib_1.__assign(tslib_1.__assign({}, this), {
128
128
  // no-op destroy, to disconnect the wrapper only when the main client is destroyed
129
129
  destroy: function () { } });
130
130
  }
@@ -34,7 +34,7 @@ function wrapperAdapter(log, wrapper) {
34
34
  exports.METHODS_TO_PROMISE_WRAP.forEach(function (method) {
35
35
  // Logs error and wraps it into a rejected promise.
36
36
  function handleError(e) {
37
- log.error(constants_1.LOG_PREFIX + " Wrapper '" + method + "' operation threw an error. Message: " + e);
37
+ log.error("".concat(constants_1.LOG_PREFIX, " Wrapper '").concat(method, "' operation threw an error. Message: ").concat(e));
38
38
  return Promise.reject(e);
39
39
  }
40
40
  wrapperAdapter[method] = function () {
@@ -24,16 +24,16 @@ exports.validateRolloutPlan = validateRolloutPlan;
24
24
  * Otherwise, the storage is handled as a server-side storage (segments is an instance of SegmentsCache).
25
25
  */
26
26
  function setRolloutPlan(log, rolloutPlan, storage, matchingKey) {
27
- var splits = storage.splits, rbSegments = storage.rbSegments, segments = storage.segments, largeSegments = storage.largeSegments;
27
+ var definitions = storage.definitions, rbSegments = storage.rbSegments, segments = storage.segments, largeSegments = storage.largeSegments;
28
28
  var _a = rolloutPlan.splitChanges, ff = _a.ff, rbs = _a.rbs;
29
- log.debug("storage: set feature flags and segments" + (matchingKey ? " for key " + matchingKey : ''));
30
- if (splits && ff) {
31
- splits.clear();
32
- splits.update(ff.d, [], ff.t);
29
+ log.debug("storage: set feature flags and segments".concat(matchingKey ? " for key ".concat(matchingKey) : ''));
30
+ if (definitions && ff) {
31
+ definitions.clear();
32
+ definitions.update(ff.d || [], [], ff.t);
33
33
  }
34
34
  if (rbSegments && rbs) {
35
35
  rbSegments.clear();
36
- rbSegments.update(rbs.d, [], rbs.t);
36
+ rbSegments.update(rbs.d || [], [], rbs.t);
37
37
  }
38
38
  var segmentChanges = rolloutPlan.segmentChanges;
39
39
  if (matchingKey) { // add memberships data (client-side)
@@ -42,7 +42,7 @@ var REVERSE_METHOD_NAMES = Object.keys(KeyBuilderSS_1.METHOD_NAMES).reduce(funct
42
42
  function parseMetadata(field) {
43
43
  var parts = field.split('/');
44
44
  if (parts.length !== 3)
45
- return "invalid subsection count. Expected 3, got: " + parts.length;
45
+ return "invalid subsection count. Expected 3, got: ".concat(parts.length);
46
46
  var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */;
47
47
  return [JSON.stringify({ s: s, n: n, i: i })];
48
48
  }
@@ -50,25 +50,25 @@ exports.parseMetadata = parseMetadata;
50
50
  function parseExceptionField(field) {
51
51
  var parts = field.split('/');
52
52
  if (parts.length !== 4)
53
- return "invalid subsection count. Expected 4, got: " + parts.length;
53
+ return "invalid subsection count. Expected 4, got: ".concat(parts.length);
54
54
  var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */, m = parts[3];
55
55
  var method = REVERSE_METHOD_NAMES[m];
56
56
  if (!method)
57
- return "unknown method '" + m + "'";
57
+ return "unknown method '".concat(m, "'");
58
58
  return [JSON.stringify({ s: s, n: n, i: i }), method];
59
59
  }
60
60
  exports.parseExceptionField = parseExceptionField;
61
61
  function parseLatencyField(field) {
62
62
  var parts = field.split('/');
63
63
  if (parts.length !== 5)
64
- return "invalid subsection count. Expected 5, got: " + parts.length;
64
+ return "invalid subsection count. Expected 5, got: ".concat(parts.length);
65
65
  var s = parts[0] /* metadata.s */, n = parts[1] /* metadata.n */, i = parts[2] /* metadata.i */, m = parts[3], b = parts[4];
66
66
  var method = REVERSE_METHOD_NAMES[m];
67
67
  if (!method)
68
- return "unknown method '" + m + "'";
68
+ return "unknown method '".concat(m, "'");
69
69
  var bucket = parseInt(b);
70
70
  if (isNaN(bucket) || bucket >= TelemetryCacheInMemory_1.MAX_LATENCY_BUCKET_COUNT)
71
- return "invalid bucket. Expected a number between 0 and " + (TelemetryCacheInMemory_1.MAX_LATENCY_BUCKET_COUNT - 1) + ", got: " + b;
71
+ return "invalid bucket. Expected a number between 0 and ".concat(TelemetryCacheInMemory_1.MAX_LATENCY_BUCKET_COUNT - 1, ", got: ").concat(b);
72
72
  return [JSON.stringify({ s: s, n: n, i: i }), method, bucket];
73
73
  }
74
74
  exports.parseLatencyField = parseLatencyField;