@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
@@ -6,40 +6,40 @@ var KeyBuilderCS = /** @class */ (function (_super) {
6
6
  function KeyBuilderCS(prefix, matchingKey) {
7
7
  var _this = _super.call(this, prefix) || this;
8
8
  _this.matchingKey = matchingKey;
9
- _this.regexSplitsCacheKey = new RegExp("^" + prefix + "\\.(splits?|trafficType|flagSet)\\.");
9
+ _this.regexDefinitionsCacheKey = new RegExp("^".concat(prefix, "\\.(splits?|trafficType|flagSet)\\."));
10
10
  return _this;
11
11
  }
12
12
  /**
13
13
  * @override
14
14
  */
15
15
  KeyBuilderCS.prototype.buildSegmentNameKey = function (segmentName) {
16
- return this.prefix + "." + this.matchingKey + ".segment." + segmentName;
16
+ return "".concat(this.prefix, ".").concat(this.matchingKey, ".segment.").concat(segmentName);
17
17
  };
18
18
  KeyBuilderCS.prototype.extractSegmentName = function (builtSegmentKeyName) {
19
- var prefix = this.prefix + "." + this.matchingKey + ".segment.";
19
+ var prefix = "".concat(this.prefix, ".").concat(this.matchingKey, ".segment.");
20
20
  if (startsWith(builtSegmentKeyName, prefix))
21
21
  return builtSegmentKeyName.slice(prefix.length);
22
22
  };
23
23
  KeyBuilderCS.prototype.buildLastUpdatedKey = function () {
24
- return this.prefix + ".splits.lastUpdated";
24
+ return "".concat(this.prefix, ".splits.lastUpdated");
25
25
  };
26
- KeyBuilderCS.prototype.isSplitsCacheKey = function (key) {
27
- return this.regexSplitsCacheKey.test(key);
26
+ KeyBuilderCS.prototype.isDefinitionsCacheKey = function (key) {
27
+ return this.regexDefinitionsCacheKey.test(key);
28
28
  };
29
29
  KeyBuilderCS.prototype.buildTillKey = function () {
30
- return this.prefix + "." + this.matchingKey + ".segments.till";
30
+ return "".concat(this.prefix, ".").concat(this.matchingKey, ".segments.till");
31
31
  };
32
- KeyBuilderCS.prototype.isSplitKey = function (key) {
33
- return startsWith(key, this.prefix + ".split.");
32
+ KeyBuilderCS.prototype.isDefinitionKey = function (key) {
33
+ return startsWith(key, "".concat(this.prefix, ".split."));
34
34
  };
35
35
  KeyBuilderCS.prototype.isRBSegmentKey = function (key) {
36
- return startsWith(key, this.prefix + ".rbsegment.");
36
+ return startsWith(key, "".concat(this.prefix, ".rbsegment."));
37
37
  };
38
- KeyBuilderCS.prototype.buildSplitsWithSegmentCountKey = function () {
39
- return this.prefix + ".splits.usingSegments";
38
+ KeyBuilderCS.prototype.buildDefinitionsWithSegmentCountKey = function () {
39
+ return "".concat(this.prefix, ".splits.usingSegments");
40
40
  };
41
41
  KeyBuilderCS.prototype.buildLastClear = function () {
42
- return this.prefix + ".lastClear";
42
+ return "".concat(this.prefix, ".lastClear");
43
43
  };
44
44
  return KeyBuilderCS;
45
45
  }(KeyBuilder));
@@ -47,15 +47,15 @@ export { KeyBuilderCS };
47
47
  export function myLargeSegmentsKeyBuilder(prefix, matchingKey) {
48
48
  return {
49
49
  buildSegmentNameKey: function (segmentName) {
50
- return prefix + "." + matchingKey + ".largeSegment." + segmentName;
50
+ return "".concat(prefix, ".").concat(matchingKey, ".largeSegment.").concat(segmentName);
51
51
  },
52
52
  extractSegmentName: function (builtSegmentKeyName) {
53
- var p = prefix + "." + matchingKey + ".largeSegment.";
53
+ var p = "".concat(prefix, ".").concat(matchingKey, ".largeSegment.");
54
54
  if (startsWith(builtSegmentKeyName, p))
55
55
  return builtSegmentKeyName.slice(p.length);
56
56
  },
57
57
  buildTillKey: function () {
58
- return prefix + "." + matchingKey + ".largeSegments.till";
58
+ return "".concat(prefix, ".").concat(matchingKey, ".largeSegments.till");
59
59
  }
60
60
  };
61
61
  }
@@ -15,42 +15,42 @@ var KeyBuilderSS = /** @class */ (function (_super) {
15
15
  __extends(KeyBuilderSS, _super);
16
16
  function KeyBuilderSS(prefix, metadata) {
17
17
  var _this = _super.call(this, prefix) || this;
18
- _this.latencyPrefix = _this.prefix + ".telemetry.latencies";
19
- _this.exceptionPrefix = _this.prefix + ".telemetry.exceptions";
20
- _this.initPrefix = _this.prefix + ".telemetry.init";
21
- _this.versionablePrefix = metadata.s + "/" + metadata.n + "/" + metadata.i;
18
+ _this.latencyPrefix = "".concat(_this.prefix, ".telemetry.latencies");
19
+ _this.exceptionPrefix = "".concat(_this.prefix, ".telemetry.exceptions");
20
+ _this.initPrefix = "".concat(_this.prefix, ".telemetry.init");
21
+ _this.versionablePrefix = "".concat(metadata.s, "/").concat(metadata.n, "/").concat(metadata.i);
22
22
  return _this;
23
23
  }
24
24
  KeyBuilderSS.prototype.buildRegisteredSegmentsKey = function () {
25
- return this.prefix + ".segments.registered";
25
+ return "".concat(this.prefix, ".segments.registered");
26
26
  };
27
27
  KeyBuilderSS.prototype.buildImpressionsKey = function () {
28
- return this.prefix + ".impressions";
28
+ return "".concat(this.prefix, ".impressions");
29
29
  };
30
30
  KeyBuilderSS.prototype.buildImpressionsCountKey = function () {
31
- return this.prefix + ".impressions.count";
31
+ return "".concat(this.prefix, ".impressions.count");
32
32
  };
33
33
  KeyBuilderSS.prototype.buildUniqueKeysKey = function () {
34
- return this.prefix + ".uniquekeys";
34
+ return "".concat(this.prefix, ".uniquekeys");
35
35
  };
36
36
  KeyBuilderSS.prototype.buildEventsKey = function () {
37
- return this.prefix + ".events";
37
+ return "".concat(this.prefix, ".events");
38
38
  };
39
- KeyBuilderSS.prototype.searchPatternForSplitKeys = function () {
40
- return this.buildSplitKeyPrefix() + "*";
39
+ KeyBuilderSS.prototype.searchPatternForDefinitionKeys = function () {
40
+ return "".concat(this.buildDefinitionKeyPrefix(), "*");
41
41
  };
42
42
  KeyBuilderSS.prototype.searchPatternForRBSegmentKeys = function () {
43
- return this.buildRBSegmentKeyPrefix() + "*";
43
+ return "".concat(this.buildRBSegmentKeyPrefix(), "*");
44
44
  };
45
45
  /* Telemetry keys */
46
46
  KeyBuilderSS.prototype.buildLatencyKey = function (method, bucket) {
47
- return this.latencyPrefix + "::" + this.versionablePrefix + "/" + METHOD_NAMES[method] + "/" + bucket;
47
+ return "".concat(this.latencyPrefix, "::").concat(this.versionablePrefix, "/").concat(METHOD_NAMES[method], "/").concat(bucket);
48
48
  };
49
49
  KeyBuilderSS.prototype.buildExceptionKey = function (method) {
50
- return this.exceptionPrefix + "::" + this.versionablePrefix + "/" + METHOD_NAMES[method];
50
+ return "".concat(this.exceptionPrefix, "::").concat(this.versionablePrefix, "/").concat(METHOD_NAMES[method]);
51
51
  };
52
52
  KeyBuilderSS.prototype.buildInitKey = function () {
53
- return this.initPrefix + "::" + this.versionablePrefix;
53
+ return "".concat(this.initPrefix, "::").concat(this.versionablePrefix);
54
54
  };
55
55
  return KeyBuilderSS;
56
56
  }(KeyBuilder));
@@ -6,14 +6,14 @@ import { getMatching } from '../utils/key';
6
6
  export function getRolloutPlan(log, storage, options) {
7
7
  if (options === void 0) { options = {}; }
8
8
  var keys = options.keys, exposeSegments = options.exposeSegments;
9
- var splits = storage.splits, segments = storage.segments, rbSegments = storage.rbSegments;
10
- log.debug("storage: get feature flags" + (keys ? ", and memberships for keys: " + keys : '') + (exposeSegments ? ', and segments' : ''));
9
+ var definitions = storage.definitions, segments = storage.segments, rbSegments = storage.rbSegments;
10
+ log.debug("storage: get feature flags".concat(keys ? ", and memberships for keys: ".concat(keys) : '').concat(exposeSegments ? ', and segments' : ''));
11
11
  return {
12
12
  splitChanges: {
13
13
  ff: {
14
- t: splits.getChangeNumber(),
14
+ t: definitions.getChangeNumber(),
15
15
  s: -1,
16
- d: splits.getAll(),
16
+ d: definitions.getAll(),
17
17
  },
18
18
  rbs: {
19
19
  t: rbSegments.getChangeNumber(),
@@ -0,0 +1,191 @@
1
+ import { __extends } from "tslib";
2
+ import { AbstractDefinitionsCacheSync, usesSegments } from '../AbstractDefinitionsCacheSync';
3
+ import { isFiniteNumber, toNumber, isNaNNumber } from '../../utils/lang';
4
+ import { LOG_PREFIX } from './constants';
5
+ import { setToArray } from '../../utils/lang/sets';
6
+ var DefinitionsCacheInLocal = /** @class */ (function (_super) {
7
+ __extends(DefinitionsCacheInLocal, _super);
8
+ function DefinitionsCacheInLocal(settings, keys, storage) {
9
+ var _this = _super.call(this) || this;
10
+ _this.keys = keys;
11
+ _this.log = settings.log;
12
+ _this.setsFilter = settings.sync.__splitFiltersValidation.groupedFilters.bySet;
13
+ _this.storage = storage;
14
+ return _this;
15
+ }
16
+ DefinitionsCacheInLocal.prototype._decrementCount = function (key) {
17
+ var count = toNumber(this.storage.getItem(key)) - 1;
18
+ if (count > 0)
19
+ this.storage.setItem(key, count + '');
20
+ else
21
+ this.storage.removeItem(key);
22
+ };
23
+ DefinitionsCacheInLocal.prototype._decrementCounts = function (definition) {
24
+ try {
25
+ var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
26
+ this._decrementCount(ttKey);
27
+ if (usesSegments(definition)) {
28
+ var segmentsCountKey = this.keys.buildDefinitionsWithSegmentCountKey();
29
+ this._decrementCount(segmentsCountKey);
30
+ }
31
+ }
32
+ catch (e) {
33
+ this.log.error(LOG_PREFIX + e);
34
+ }
35
+ };
36
+ DefinitionsCacheInLocal.prototype._incrementCounts = function (definition) {
37
+ try {
38
+ var ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
39
+ this.storage.setItem(ttKey, (toNumber(this.storage.getItem(ttKey)) + 1) + '');
40
+ if (usesSegments(definition)) {
41
+ var segmentsCountKey = this.keys.buildDefinitionsWithSegmentCountKey();
42
+ this.storage.setItem(segmentsCountKey, (toNumber(this.storage.getItem(segmentsCountKey)) + 1) + '');
43
+ }
44
+ }
45
+ catch (e) {
46
+ this.log.error(LOG_PREFIX + e);
47
+ }
48
+ };
49
+ /**
50
+ * Removes all definitions related data from localStorage (splits, counters, changeNumber and lastUpdated).
51
+ * We cannot simply call `localStorage.clear()` since that implies removing user items from the storage.
52
+ */
53
+ DefinitionsCacheInLocal.prototype.clear = function () {
54
+ var _this = this;
55
+ // collect item keys
56
+ var len = this.storage.length;
57
+ var accum = [];
58
+ for (var cur = 0; cur < len; cur++) {
59
+ var key = this.storage.key(cur);
60
+ if (key != null && this.keys.isDefinitionsCacheKey(key))
61
+ accum.push(key);
62
+ }
63
+ // remove items
64
+ accum.forEach(function (key) {
65
+ _this.storage.removeItem(key);
66
+ });
67
+ this.hasSync = false;
68
+ };
69
+ DefinitionsCacheInLocal.prototype.add = function (definition) {
70
+ var name = definition.name;
71
+ var definitionKey = this.keys.buildDefinitionKey(name);
72
+ var definitionFromStorage = this.storage.getItem(definitionKey);
73
+ var previousDefinition = definitionFromStorage ? JSON.parse(definitionFromStorage) : null;
74
+ if (previousDefinition) {
75
+ this._decrementCounts(previousDefinition);
76
+ this.removeFromSets(previousDefinition.name, previousDefinition.sets);
77
+ }
78
+ this.storage.setItem(definitionKey, JSON.stringify(definition));
79
+ this._incrementCounts(definition);
80
+ this.addToSets(definition);
81
+ return true;
82
+ };
83
+ DefinitionsCacheInLocal.prototype.remove = function (name) {
84
+ var definition = this.get(name);
85
+ if (!definition)
86
+ return false;
87
+ this.storage.removeItem(this.keys.buildDefinitionKey(name));
88
+ this._decrementCounts(definition);
89
+ this.removeFromSets(definition.name, definition.sets);
90
+ return true;
91
+ };
92
+ DefinitionsCacheInLocal.prototype.get = function (name) {
93
+ var item = this.storage.getItem(this.keys.buildDefinitionKey(name));
94
+ return item && JSON.parse(item);
95
+ };
96
+ DefinitionsCacheInLocal.prototype.setChangeNumber = function (changeNumber) {
97
+ try {
98
+ this.storage.setItem(this.keys.buildDefinitionsTillKey(), changeNumber + '');
99
+ // update "last updated" timestamp with current time
100
+ this.storage.setItem(this.keys.buildLastUpdatedKey(), Date.now() + '');
101
+ this.hasSync = true;
102
+ return true;
103
+ }
104
+ catch (e) {
105
+ this.log.error(LOG_PREFIX + e);
106
+ return false;
107
+ }
108
+ };
109
+ DefinitionsCacheInLocal.prototype.getChangeNumber = function () {
110
+ var n = -1;
111
+ var value = this.storage.getItem(this.keys.buildDefinitionsTillKey());
112
+ if (value !== null) {
113
+ value = parseInt(value, 10);
114
+ return isNaNNumber(value) ? n : value;
115
+ }
116
+ return n;
117
+ };
118
+ DefinitionsCacheInLocal.prototype.getNames = function () {
119
+ var len = this.storage.length;
120
+ var accum = [];
121
+ var cur = 0;
122
+ while (cur < len) {
123
+ var key = this.storage.key(cur);
124
+ if (key != null && this.keys.isDefinitionKey(key))
125
+ accum.push(this.keys.extractKey(key));
126
+ cur++;
127
+ }
128
+ return accum;
129
+ };
130
+ DefinitionsCacheInLocal.prototype.trafficTypeExists = function (trafficType) {
131
+ var ttCount = toNumber(this.storage.getItem(this.keys.buildTrafficTypeKey(trafficType)));
132
+ return isFiniteNumber(ttCount) && ttCount > 0;
133
+ };
134
+ DefinitionsCacheInLocal.prototype.usesSegments = function () {
135
+ // If cache hasn't been synchronized with the cloud, assume we need them.
136
+ if (!this.hasSync)
137
+ return true;
138
+ var storedCount = this.storage.getItem(this.keys.buildDefinitionsWithSegmentCountKey());
139
+ var definitionsWithSegmentsCount = storedCount === null ? 0 : toNumber(storedCount);
140
+ return isFiniteNumber(definitionsWithSegmentsCount) ?
141
+ definitionsWithSegmentsCount > 0 :
142
+ true;
143
+ };
144
+ DefinitionsCacheInLocal.prototype.getNamesBySets = function (sets) {
145
+ var _this = this;
146
+ return sets.map(function (set) {
147
+ var setKey = _this.keys.buildSetKey(set);
148
+ var setFromStorage = _this.storage.getItem(setKey);
149
+ return new Set(setFromStorage ? JSON.parse(setFromStorage) : []);
150
+ });
151
+ };
152
+ DefinitionsCacheInLocal.prototype.addToSets = function (definition) {
153
+ var _this = this;
154
+ if (!definition.sets)
155
+ return;
156
+ definition.sets.forEach(function (set) {
157
+ if (_this.setsFilter.length > 0 && !_this.setsFilter.some(function (filterSet) { return filterSet === set; }))
158
+ return;
159
+ var setKey = _this.keys.buildSetKey(set);
160
+ var setFromStorage = _this.storage.getItem(setKey);
161
+ var setCache = new Set(setFromStorage ? JSON.parse(setFromStorage) : []);
162
+ if (setCache.has(definition.name))
163
+ return;
164
+ setCache.add(definition.name);
165
+ _this.storage.setItem(setKey, JSON.stringify(setToArray(setCache)));
166
+ });
167
+ };
168
+ DefinitionsCacheInLocal.prototype.removeFromSets = function (definitionName, sets) {
169
+ var _this = this;
170
+ if (!sets)
171
+ return;
172
+ sets.forEach(function (set) {
173
+ _this.removeNames(set, definitionName);
174
+ });
175
+ };
176
+ DefinitionsCacheInLocal.prototype.removeNames = function (setName, definitionName) {
177
+ var setKey = this.keys.buildSetKey(setName);
178
+ var setFromStorage = this.storage.getItem(setKey);
179
+ if (!setFromStorage)
180
+ return;
181
+ var setCache = new Set(JSON.parse(setFromStorage));
182
+ setCache.delete(definitionName);
183
+ if (setCache.size === 0) {
184
+ this.storage.removeItem(setKey);
185
+ return;
186
+ }
187
+ this.storage.setItem(setKey, JSON.stringify(setToArray(setCache)));
188
+ };
189
+ return DefinitionsCacheInLocal;
190
+ }(AbstractDefinitionsCacheSync));
191
+ export { DefinitionsCacheInLocal };
@@ -1,6 +1,6 @@
1
1
  import { isFiniteNumber, isNaNNumber, toNumber } from '../../utils/lang';
2
2
  import { setToArray } from '../../utils/lang/sets';
3
- import { usesSegments } from '../AbstractSplitsCacheSync';
3
+ import { usesSegments } from '../AbstractDefinitionsCacheSync';
4
4
  import { LOG_PREFIX } from './constants';
5
5
  var RBSegmentsCacheInLocal = /** @class */ (function () {
6
6
  function RBSegmentsCacheInLocal(settings, keys, storage) {
@@ -16,7 +16,7 @@ var RBSegmentsCacheInLocal = /** @class */ (function () {
16
16
  RBSegmentsCacheInLocal.prototype.update = function (toAdd, toRemove, changeNumber) {
17
17
  var _this = this;
18
18
  var updated = toAdd.map(function (toAdd) { return _this.add(toAdd); }).some(function (result) { return result; });
19
- updated = toRemove.map(function (toRemove) { return _this.remove(toRemove.name); }).some(function (result) { return result; }) || updated;
19
+ updated = toRemove.map(function (toRemove) { return _this.remove(toRemove); }).some(function (result) { return result; }) || updated;
20
20
  this.setChangeNumber(changeNumber);
21
21
  return updated;
22
22
  };
@@ -30,7 +30,7 @@ var RBSegmentsCacheInLocal = /** @class */ (function () {
30
30
  }
31
31
  };
32
32
  RBSegmentsCacheInLocal.prototype.updateSegmentCount = function (diff) {
33
- var segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
33
+ var segmentsCountKey = this.keys.buildDefinitionsWithSegmentCountKey();
34
34
  var count = toNumber(this.storage.getItem(segmentsCountKey)) + diff;
35
35
  if (count > 0)
36
36
  this.storage.setItem(segmentsCountKey, count + '');
@@ -96,10 +96,10 @@ var RBSegmentsCacheInLocal = /** @class */ (function () {
96
96
  return n;
97
97
  };
98
98
  RBSegmentsCacheInLocal.prototype.usesSegments = function () {
99
- var storedCount = this.storage.getItem(this.keys.buildSplitsWithSegmentCountKey());
100
- var splitsWithSegmentsCount = storedCount === null ? 0 : toNumber(storedCount);
101
- return isFiniteNumber(splitsWithSegmentsCount) ?
102
- splitsWithSegmentsCount > 0 :
99
+ var storedCount = this.storage.getItem(this.keys.buildDefinitionsWithSegmentCountKey());
100
+ var definitionsWithSegmentsCount = storedCount === null ? 0 : toNumber(storedCount);
101
+ return isFiniteNumber(definitionsWithSegmentsCount) ?
102
+ definitionsWithSegmentsCount > 0 :
103
103
  true;
104
104
  };
105
105
  return RBSegmentsCacheInLocal;
@@ -4,7 +4,7 @@ import { EventsCacheInMemory } from '../inMemory/EventsCacheInMemory';
4
4
  import { validatePrefix } from '../KeyBuilder';
5
5
  import { KeyBuilderCS, myLargeSegmentsKeyBuilder } from '../KeyBuilderCS';
6
6
  import { isLocalStorageAvailable, isValidStorageWrapper, isWebStorage } from '../../utils/env/isLocalStorageAvailable';
7
- import { SplitsCacheInLocal } from './SplitsCacheInLocal';
7
+ import { DefinitionsCacheInLocal } from './DefinitionsCacheInLocal';
8
8
  import { RBSegmentsCacheInLocal } from './RBSegmentsCacheInLocal';
9
9
  import { MySegmentsCacheInLocal } from './MySegmentsCacheInLocal';
10
10
  import { InMemoryStorageCSFactory } from '../inMemory/InMemoryStorageCS';
@@ -41,24 +41,24 @@ export function InLocalStorage(options) {
41
41
  return InMemoryStorageCSFactory(params);
42
42
  var matchingKey = getMatching(settings.core.key);
43
43
  var keys = new KeyBuilderCS(prefix, matchingKey);
44
- var splits = new SplitsCacheInLocal(settings, keys, storage);
44
+ var definitions = new DefinitionsCacheInLocal(settings, keys, storage);
45
45
  var rbSegments = new RBSegmentsCacheInLocal(settings, keys, storage);
46
46
  var segments = new MySegmentsCacheInLocal(log, keys, storage);
47
47
  var largeSegments = new MySegmentsCacheInLocal(log, myLargeSegmentsKeyBuilder(prefix, matchingKey), storage);
48
48
  var validateCachePromise;
49
49
  return {
50
- splits: splits,
50
+ definitions: definitions,
51
51
  rbSegments: rbSegments,
52
52
  segments: segments,
53
53
  largeSegments: largeSegments,
54
54
  impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
55
55
  impressionCounts: new ImpressionCountsCacheInMemory(),
56
56
  events: new EventsCacheInMemory(eventsQueueSize),
57
- telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory(splits, segments) : undefined,
57
+ telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory(definitions, segments) : undefined,
58
58
  uniqueKeys: new UniqueKeysCacheInMemoryCS(),
59
59
  validateCache: function () {
60
60
  if (!validateCachePromise) {
61
- validateCachePromise = validateCache(options, storage, settings, keys, splits, rbSegments, segments, largeSegments);
61
+ validateCachePromise = validateCache(options, storage, settings, keys, definitions, rbSegments, segments, largeSegments);
62
62
  }
63
63
  return validateCachePromise;
64
64
  },
@@ -71,7 +71,7 @@ export function InLocalStorage(options) {
71
71
  // When using shared instantiation with MEMORY we reuse everything but segments (they are customer per key).
72
72
  shared: function (matchingKey) {
73
73
  return {
74
- splits: this.splits,
74
+ definitions: this.definitions,
75
75
  rbSegments: this.rbSegments,
76
76
  segments: new MySegmentsCacheInLocal(log, new KeyBuilderCS(prefix, matchingKey), storage),
77
77
  largeSegments: new MySegmentsCacheInLocal(log, myLargeSegmentsKeyBuilder(prefix, matchingKey), storage),
@@ -54,16 +54,16 @@ function validateExpiration(options, storage, settings, keys, currentTimestamp,
54
54
  *
55
55
  * @returns Metadata object with `initialCacheLoad` (true if is fresh install, false if is ready from cache) and `lastUpdateTimestamp` (timestamp of last cache update or undefined)
56
56
  */
57
- export function validateCache(options, storage, settings, keys, splits, rbSegments, segments, largeSegments) {
57
+ export function validateCache(options, storage, settings, keys, definitions, rbSegments, segments, largeSegments) {
58
58
  return Promise.resolve(storage.load && storage.load()).then(function () {
59
59
  var currentTimestamp = Date.now();
60
- var isThereCache = splits.getChangeNumber() > -1;
60
+ var isThereCache = definitions.getChangeNumber() > -1;
61
61
  // Get lastUpdateTimestamp from storage
62
62
  var lastUpdatedTimestampStr = storage.getItem(keys.buildLastUpdatedKey());
63
63
  var lastUpdatedTimestamp = lastUpdatedTimestampStr ? parseInt(lastUpdatedTimestampStr, 10) : undefined;
64
64
  var lastUpdateTimestamp = (!isNaNNumber(lastUpdatedTimestamp) && lastUpdatedTimestamp !== undefined) ? lastUpdatedTimestamp : undefined;
65
65
  if (validateExpiration(options, storage, settings, keys, currentTimestamp, isThereCache)) {
66
- splits.clear();
66
+ definitions.clear();
67
67
  rbSegments.clear();
68
68
  segments.clear();
69
69
  largeSegments.clear();
@@ -0,0 +1,118 @@
1
+ import { __extends } from "tslib";
2
+ import { AbstractDefinitionsCacheSync, usesSegments } from '../AbstractDefinitionsCacheSync';
3
+ import { isFiniteNumber } from '../../utils/lang';
4
+ /**
5
+ * Default IDefinitionsCacheSync implementation that stores split definitions in memory.
6
+ */
7
+ var DefinitionsCacheInMemory = /** @class */ (function (_super) {
8
+ __extends(DefinitionsCacheInMemory, _super);
9
+ function DefinitionsCacheInMemory(splitFiltersValidation) {
10
+ var _this = _super.call(this) || this;
11
+ _this.definitionsCache = {};
12
+ _this.ttCache = {};
13
+ _this.changeNumber = -1;
14
+ _this.segmentsCount = 0;
15
+ _this.setsCache = {};
16
+ _this.setsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
17
+ return _this;
18
+ }
19
+ DefinitionsCacheInMemory.prototype.clear = function () {
20
+ this.definitionsCache = {};
21
+ this.ttCache = {};
22
+ this.changeNumber = -1;
23
+ this.segmentsCount = 0;
24
+ this.setsCache = {};
25
+ };
26
+ DefinitionsCacheInMemory.prototype.add = function (definition) {
27
+ var name = definition.name;
28
+ var previousDefinition = this.get(name);
29
+ if (previousDefinition) { // We had this Split already
30
+ var previousTtName = previousDefinition.trafficTypeName;
31
+ this.ttCache[previousTtName]--;
32
+ if (!this.ttCache[previousTtName])
33
+ delete this.ttCache[previousTtName];
34
+ this.removeFromFlagSets(previousDefinition.name, previousDefinition.sets);
35
+ // Subtract from segments count for the previous version of this Split
36
+ if (usesSegments(previousDefinition))
37
+ this.segmentsCount--;
38
+ }
39
+ // Store the Split.
40
+ this.definitionsCache[name] = definition;
41
+ // Update TT cache
42
+ var ttName = definition.trafficTypeName;
43
+ this.ttCache[ttName] = (this.ttCache[ttName] || 0) + 1;
44
+ this.addToFlagSets(definition);
45
+ // Add to segments count for the new version of the Split
46
+ if (usesSegments(definition))
47
+ this.segmentsCount++;
48
+ return true;
49
+ };
50
+ DefinitionsCacheInMemory.prototype.remove = function (name) {
51
+ var definition = this.get(name);
52
+ if (!definition)
53
+ return false;
54
+ // Delete the Split
55
+ delete this.definitionsCache[name];
56
+ var ttName = definition.trafficTypeName;
57
+ this.ttCache[ttName]--; // Update tt cache
58
+ if (!this.ttCache[ttName])
59
+ delete this.ttCache[ttName];
60
+ this.removeFromFlagSets(definition.name, definition.sets);
61
+ // Update the segments count.
62
+ if (usesSegments(definition))
63
+ this.segmentsCount--;
64
+ return true;
65
+ };
66
+ DefinitionsCacheInMemory.prototype.get = function (name) {
67
+ return this.definitionsCache[name] || null;
68
+ };
69
+ DefinitionsCacheInMemory.prototype.setChangeNumber = function (changeNumber) {
70
+ this.changeNumber = changeNumber;
71
+ return true;
72
+ };
73
+ DefinitionsCacheInMemory.prototype.getChangeNumber = function () {
74
+ return this.changeNumber;
75
+ };
76
+ DefinitionsCacheInMemory.prototype.getNames = function () {
77
+ return Object.keys(this.definitionsCache);
78
+ };
79
+ DefinitionsCacheInMemory.prototype.trafficTypeExists = function (trafficType) {
80
+ return isFiniteNumber(this.ttCache[trafficType]) && this.ttCache[trafficType] > 0;
81
+ };
82
+ DefinitionsCacheInMemory.prototype.usesSegments = function () {
83
+ return this.getChangeNumber() === -1 || this.segmentsCount > 0;
84
+ };
85
+ DefinitionsCacheInMemory.prototype.getNamesBySets = function (sets) {
86
+ var _this = this;
87
+ return sets.map(function (set) { return _this.setsCache[set] || new Set(); });
88
+ };
89
+ DefinitionsCacheInMemory.prototype.addToFlagSets = function (featureFlag) {
90
+ var _this = this;
91
+ if (!featureFlag.sets)
92
+ return;
93
+ featureFlag.sets.forEach(function (featureFlagSet) {
94
+ if (_this.setsFilter.length > 0 && !_this.setsFilter.some(function (filterFlagSet) { return filterFlagSet === featureFlagSet; }))
95
+ return;
96
+ if (!_this.setsCache[featureFlagSet])
97
+ _this.setsCache[featureFlagSet] = new Set([]);
98
+ _this.setsCache[featureFlagSet].add(featureFlag.name);
99
+ });
100
+ };
101
+ DefinitionsCacheInMemory.prototype.removeFromFlagSets = function (featureFlagName, sets) {
102
+ var _this = this;
103
+ if (!sets)
104
+ return;
105
+ sets.forEach(function (set) {
106
+ _this.removeNames(set, featureFlagName);
107
+ });
108
+ };
109
+ DefinitionsCacheInMemory.prototype.removeNames = function (setName, featureFlagName) {
110
+ if (!this.setsCache[setName])
111
+ return;
112
+ this.setsCache[setName].delete(featureFlagName);
113
+ if (this.setsCache[setName].size === 0)
114
+ delete this.setsCache[setName];
115
+ };
116
+ return DefinitionsCacheInMemory;
117
+ }(AbstractDefinitionsCacheSync));
118
+ export { DefinitionsCacheInMemory };
@@ -12,7 +12,7 @@ var ImpressionCountsCacheInMemory = /** @class */ (function () {
12
12
  * Builds key to be stored in the cache with the featureName and the timeFrame truncated.
13
13
  */
14
14
  ImpressionCountsCacheInMemory.prototype._makeKey = function (featureName, timeFrame) {
15
- return featureName + "::" + truncateTimeFrame(timeFrame);
15
+ return "".concat(featureName, "::").concat(truncateTimeFrame(timeFrame));
16
16
  };
17
17
  /**
18
18
  * Increments the quantity of impressions with the passed featureName and timeFrame.
@@ -1,4 +1,4 @@
1
- import { SplitsCacheInMemory } from './SplitsCacheInMemory';
1
+ import { DefinitionsCacheInMemory } from './DefinitionsCacheInMemory';
2
2
  import { SegmentsCacheInMemory } from './SegmentsCacheInMemory';
3
3
  import { ImpressionsCacheInMemory } from './ImpressionsCacheInMemory';
4
4
  import { EventsCacheInMemory } from './EventsCacheInMemory';
@@ -14,17 +14,17 @@ import { RBSegmentsCacheInMemory } from './RBSegmentsCacheInMemory';
14
14
  */
15
15
  export function InMemoryStorageFactory(params) {
16
16
  var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
17
- var splits = new SplitsCacheInMemory(__splitFiltersValidation);
17
+ var definitions = new DefinitionsCacheInMemory(__splitFiltersValidation);
18
18
  var rbSegments = new RBSegmentsCacheInMemory();
19
19
  var segments = new SegmentsCacheInMemory();
20
20
  var storage = {
21
- splits: splits,
21
+ definitions: definitions,
22
22
  rbSegments: rbSegments,
23
23
  segments: segments,
24
24
  impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
25
25
  impressionCounts: new ImpressionCountsCacheInMemory(),
26
26
  events: new EventsCacheInMemory(eventsQueueSize),
27
- telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory(splits, segments) : undefined,
27
+ telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory(definitions, segments) : undefined,
28
28
  uniqueKeys: new UniqueKeysCacheInMemory(),
29
29
  destroy: function () { }
30
30
  };
@@ -1,4 +1,4 @@
1
- import { SplitsCacheInMemory } from './SplitsCacheInMemory';
1
+ import { DefinitionsCacheInMemory } from './DefinitionsCacheInMemory';
2
2
  import { MySegmentsCacheInMemory } from './MySegmentsCacheInMemory';
3
3
  import { ImpressionsCacheInMemory } from './ImpressionsCacheInMemory';
4
4
  import { EventsCacheInMemory } from './EventsCacheInMemory';
@@ -14,25 +14,25 @@ import { RBSegmentsCacheInMemory } from './RBSegmentsCacheInMemory';
14
14
  */
15
15
  export function InMemoryStorageCSFactory(params) {
16
16
  var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, __splitFiltersValidation = _a.sync.__splitFiltersValidation;
17
- var splits = new SplitsCacheInMemory(__splitFiltersValidation);
17
+ var definitions = new DefinitionsCacheInMemory(__splitFiltersValidation);
18
18
  var rbSegments = new RBSegmentsCacheInMemory();
19
19
  var segments = new MySegmentsCacheInMemory();
20
20
  var largeSegments = new MySegmentsCacheInMemory();
21
21
  var storage = {
22
- splits: splits,
22
+ definitions: definitions,
23
23
  rbSegments: rbSegments,
24
24
  segments: segments,
25
25
  largeSegments: largeSegments,
26
26
  impressions: new ImpressionsCacheInMemory(impressionsQueueSize),
27
27
  impressionCounts: new ImpressionCountsCacheInMemory(),
28
28
  events: new EventsCacheInMemory(eventsQueueSize),
29
- telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory(splits, segments) : undefined,
29
+ telemetry: shouldRecordTelemetry(params) ? new TelemetryCacheInMemory(definitions, segments) : undefined,
30
30
  uniqueKeys: new UniqueKeysCacheInMemoryCS(),
31
31
  destroy: function () { },
32
32
  // When using shared instantiation with MEMORY we reuse everything but segments (they are unique per key)
33
33
  shared: function () {
34
34
  return {
35
- splits: this.splits,
35
+ definitions: this.definitions,
36
36
  rbSegments: this.rbSegments,
37
37
  segments: new MySegmentsCacheInMemory(),
38
38
  largeSegments: new MySegmentsCacheInMemory(),