@splitsoftware/splitio-commons 2.12.0 → 3.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (395) hide show
  1. package/CHANGES.txt +19 -1
  2. package/cjs/evaluator/condition/engineUtils.js +2 -2
  3. package/cjs/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +70 -0
  4. package/cjs/evaluator/fallbackConfigsCalculator/index.js +25 -0
  5. package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
  6. package/cjs/evaluator/fallbackTreatmentsCalculator/index.js +21 -32
  7. package/cjs/evaluator/index.js +73 -48
  8. package/cjs/evaluator/matchers/whitelist.js +1 -1
  9. package/cjs/integrations/pluggable.js +1 -1
  10. package/cjs/listeners/browser.js +4 -3
  11. package/cjs/listeners/node.js +4 -4
  12. package/cjs/logger/constants.js +15 -21
  13. package/cjs/logger/index.js +1 -1
  14. package/cjs/logger/messages/debug.js +6 -7
  15. package/cjs/logger/messages/error.js +4 -4
  16. package/cjs/logger/messages/info.js +2 -4
  17. package/cjs/logger/messages/warn.js +9 -10
  18. package/cjs/platform/browser.js +15 -0
  19. package/cjs/platform/getEventSource/browser.js +8 -0
  20. package/cjs/platform/getEventSource/eventsource.js +480 -0
  21. package/cjs/platform/getEventSource/node.js +26 -0
  22. package/cjs/platform/getFetch/browser.js +9 -0
  23. package/cjs/platform/getFetch/node.js +27 -0
  24. package/cjs/platform/getOptions/node.js +25 -0
  25. package/cjs/platform/node.js +17 -0
  26. package/cjs/readiness/constants.js +5 -4
  27. package/cjs/readiness/readinessManager.js +22 -22
  28. package/cjs/readiness/sdkReadinessManager.js +0 -16
  29. package/cjs/sdkClient/client.js +9 -35
  30. package/cjs/sdkClient/clientAttributesDecoration.js +3 -3
  31. package/cjs/sdkClient/clientInputValidation.js +38 -81
  32. package/cjs/sdkClient/identity.js +1 -1
  33. package/cjs/sdkClient/sdkClient.js +4 -49
  34. package/cjs/sdkClient/sdkLifecycle.js +71 -0
  35. package/cjs/sdkClient/trackMethod.js +56 -0
  36. package/cjs/sdkFactory/index.js +13 -50
  37. package/cjs/sdkManager/index.js +5 -5
  38. package/cjs/services/authProvider.js +67 -0
  39. package/cjs/services/secureSplitHttpClient.js +39 -0
  40. package/cjs/services/splitApi.js +24 -14
  41. package/cjs/services/splitHttpClient.js +1 -1
  42. package/cjs/storages/AbstractDefinitionsCacheAsync.js +51 -0
  43. package/cjs/storages/AbstractDefinitionsCacheSync.js +76 -0
  44. package/cjs/storages/KeyBuilder.js +16 -16
  45. package/cjs/storages/KeyBuilderCS.js +17 -17
  46. package/cjs/storages/KeyBuilderSS.js +16 -16
  47. package/cjs/storages/getRolloutPlan.js +4 -4
  48. package/cjs/storages/inLocalStorage/DefinitionsCacheInLocal.js +194 -0
  49. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -1
  50. package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +10 -10
  51. package/cjs/storages/inLocalStorage/index.js +6 -6
  52. package/cjs/storages/inLocalStorage/validateCache.js +3 -3
  53. package/cjs/storages/inMemory/DefinitionsCacheInMemory.js +121 -0
  54. package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
  55. package/cjs/storages/inMemory/InMemoryStorage.js +4 -4
  56. package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -5
  57. package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +1 -1
  58. package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +5 -5
  59. package/cjs/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  60. package/cjs/storages/inMemory/TelemetryCacheInMemory.js +5 -5
  61. package/cjs/storages/inRedis/DefinitionsCacheInRedis.js +243 -0
  62. package/cjs/storages/inRedis/EventsCacheInRedis.js +1 -1
  63. package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +5 -5
  64. package/cjs/storages/inRedis/ImpressionsCacheInRedis.js +1 -1
  65. package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
  66. package/cjs/storages/inRedis/RedisAdapter.js +8 -8
  67. package/cjs/storages/inRedis/TelemetryCacheInRedis.js +7 -7
  68. package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +3 -3
  69. package/cjs/storages/inRedis/index.js +2 -2
  70. package/cjs/storages/pluggable/DefinitionsCachePluggable.js +212 -0
  71. package/cjs/storages/pluggable/EventsCachePluggable.js +1 -1
  72. package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +6 -6
  73. package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
  74. package/cjs/storages/pluggable/TelemetryCachePluggable.js +7 -7
  75. package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +2 -2
  76. package/cjs/storages/pluggable/index.js +5 -5
  77. package/cjs/storages/pluggable/wrapperAdapter.js +1 -1
  78. package/cjs/storages/setRolloutPlan.js +6 -6
  79. package/cjs/storages/utils.js +6 -6
  80. package/cjs/sync/offline/splitsParser/parseCondition.js +1 -1
  81. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +5 -5
  82. package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
  83. package/cjs/sync/polling/fetchers/splitChangesFetcher.js +24 -15
  84. package/cjs/sync/polling/pollingManagerCS.js +18 -18
  85. package/cjs/sync/polling/pollingManagerSS.js +13 -13
  86. package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +12 -0
  87. package/cjs/sync/polling/updaters/{splitChangesUpdater.js → definitionChangesUpdater.js} +72 -64
  88. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  89. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
  90. package/cjs/sync/streaming/SSEClient/index.js +2 -2
  91. package/cjs/sync/streaming/SSEHandler/NotificationKeeper.js +1 -1
  92. package/cjs/sync/streaming/SSEHandler/index.js +1 -1
  93. package/cjs/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +18 -18
  94. package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +2 -2
  95. package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -2
  96. package/cjs/sync/streaming/constants.js +3 -3
  97. package/cjs/sync/streaming/parseUtils.js +12 -12
  98. package/cjs/sync/streaming/pushManager.js +14 -14
  99. package/cjs/sync/submitters/impressionsSubmitter.js +6 -6
  100. package/cjs/sync/submitters/submitter.js +1 -1
  101. package/cjs/sync/submitters/telemetrySubmitter.js +1 -2
  102. package/cjs/sync/syncManagerOnline.js +9 -6
  103. package/cjs/trackers/eventTracker.js +10 -12
  104. package/cjs/trackers/impressionObserver/buildKey.js +1 -1
  105. package/cjs/trackers/impressionsTracker.js +37 -20
  106. package/cjs/trackers/uniqueKeysTracker.js +1 -1
  107. package/cjs/utils/Backoff.js +20 -0
  108. package/cjs/utils/EventEmitter.js +391 -0
  109. package/cjs/utils/filter/bloomFilter.js +37 -0
  110. package/cjs/utils/inputValidation/apiKey.js +1 -1
  111. package/cjs/utils/inputValidation/attribute.js +2 -2
  112. package/cjs/utils/inputValidation/{split.js → definition.js} +10 -10
  113. package/cjs/utils/inputValidation/{splitExistence.js → definitionExistence.js} +6 -6
  114. package/cjs/utils/inputValidation/definitions.js +25 -0
  115. package/cjs/utils/inputValidation/eventProperties.js +1 -1
  116. package/cjs/utils/inputValidation/index.js +7 -7
  117. package/cjs/utils/inputValidation/isOperational.js +4 -4
  118. package/cjs/utils/inputValidation/target.js +22 -0
  119. package/cjs/utils/labels/index.js +3 -3
  120. package/cjs/utils/lang/index.js +1 -1
  121. package/cjs/utils/lang/sets.js +4 -4
  122. package/cjs/utils/promise/timeout.js +1 -1
  123. package/cjs/utils/settingsValidation/splitFilters.js +4 -4
  124. package/cjs/utils/settingsValidation/url.js +6 -6
  125. package/esm/evaluator/condition/engineUtils.js +2 -2
  126. package/esm/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +64 -0
  127. package/esm/evaluator/fallbackConfigsCalculator/index.js +21 -0
  128. package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
  129. package/esm/evaluator/fallbackTreatmentsCalculator/index.js +21 -33
  130. package/esm/evaluator/index.js +72 -48
  131. package/esm/evaluator/matchers/whitelist.js +1 -1
  132. package/esm/integrations/pluggable.js +1 -1
  133. package/esm/listeners/browser.js +4 -3
  134. package/esm/listeners/node.js +4 -4
  135. package/esm/logger/constants.js +12 -18
  136. package/esm/logger/index.js +1 -1
  137. package/esm/logger/messages/debug.js +5 -6
  138. package/esm/logger/messages/error.js +3 -3
  139. package/esm/logger/messages/info.js +1 -3
  140. package/esm/logger/messages/warn.js +8 -9
  141. package/esm/platform/browser.js +12 -0
  142. package/esm/platform/getEventSource/browser.js +4 -0
  143. package/esm/platform/getEventSource/eventsource.js +480 -0
  144. package/esm/platform/getEventSource/node.js +20 -0
  145. package/esm/platform/getFetch/browser.js +5 -0
  146. package/esm/platform/getFetch/node.js +22 -0
  147. package/esm/platform/getOptions/node.js +20 -0
  148. package/esm/platform/node.js +14 -0
  149. package/esm/readiness/constants.js +4 -3
  150. package/esm/readiness/readinessManager.js +23 -23
  151. package/esm/readiness/sdkReadinessManager.js +1 -17
  152. package/esm/sdkClient/client.js +10 -37
  153. package/esm/sdkClient/clientAttributesDecoration.js +3 -3
  154. package/esm/sdkClient/clientInputValidation.js +40 -83
  155. package/esm/sdkClient/identity.js +1 -1
  156. package/esm/sdkClient/sdkClient.js +4 -49
  157. package/esm/sdkClient/sdkLifecycle.js +67 -0
  158. package/esm/sdkClient/trackMethod.js +52 -0
  159. package/esm/sdkFactory/index.js +14 -51
  160. package/esm/sdkManager/index.js +6 -6
  161. package/esm/services/authProvider.js +63 -0
  162. package/esm/services/secureSplitHttpClient.js +35 -0
  163. package/esm/services/splitApi.js +24 -14
  164. package/esm/services/splitHttpClient.js +1 -1
  165. package/esm/storages/AbstractDefinitionsCacheAsync.js +48 -0
  166. package/esm/storages/AbstractDefinitionsCacheSync.js +71 -0
  167. package/esm/storages/KeyBuilder.js +16 -16
  168. package/esm/storages/KeyBuilderCS.js +16 -16
  169. package/esm/storages/KeyBuilderSS.js +15 -15
  170. package/esm/storages/getRolloutPlan.js +4 -4
  171. package/esm/storages/inLocalStorage/DefinitionsCacheInLocal.js +191 -0
  172. package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +7 -7
  173. package/esm/storages/inLocalStorage/index.js +6 -6
  174. package/esm/storages/inLocalStorage/validateCache.js +3 -3
  175. package/esm/storages/inMemory/DefinitionsCacheInMemory.js +118 -0
  176. package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
  177. package/esm/storages/inMemory/InMemoryStorage.js +4 -4
  178. package/esm/storages/inMemory/InMemoryStorageCS.js +5 -5
  179. package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +2 -2
  180. package/esm/storages/inMemory/SegmentsCacheInMemory.js +1 -1
  181. package/esm/storages/inMemory/TelemetryCacheInMemory.js +5 -5
  182. package/esm/storages/inRedis/DefinitionsCacheInRedis.js +240 -0
  183. package/esm/storages/inRedis/EventsCacheInRedis.js +1 -1
  184. package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +4 -4
  185. package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
  186. package/esm/storages/inRedis/RedisAdapter.js +7 -7
  187. package/esm/storages/inRedis/TelemetryCacheInRedis.js +7 -7
  188. package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +1 -1
  189. package/esm/storages/inRedis/index.js +2 -2
  190. package/esm/storages/pluggable/DefinitionsCachePluggable.js +209 -0
  191. package/esm/storages/pluggable/EventsCachePluggable.js +1 -1
  192. package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +5 -5
  193. package/esm/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
  194. package/esm/storages/pluggable/TelemetryCachePluggable.js +7 -7
  195. package/esm/storages/pluggable/UniqueKeysCachePluggable.js +1 -1
  196. package/esm/storages/pluggable/index.js +4 -4
  197. package/esm/storages/pluggable/wrapperAdapter.js +1 -1
  198. package/esm/storages/setRolloutPlan.js +6 -6
  199. package/esm/storages/utils.js +6 -6
  200. package/esm/sync/offline/splitsParser/parseCondition.js +1 -1
  201. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +6 -6
  202. package/esm/sync/polling/fetchers/splitChangesFetcher.js +25 -16
  203. package/esm/sync/polling/pollingManagerCS.js +15 -15
  204. package/esm/sync/polling/pollingManagerSS.js +13 -13
  205. package/esm/sync/polling/syncTasks/definitionsSyncTask.js +8 -0
  206. package/esm/sync/polling/updaters/definitionChangesUpdater.js +200 -0
  207. package/esm/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  208. package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
  209. package/esm/sync/streaming/SSEClient/index.js +2 -2
  210. package/esm/sync/streaming/SSEHandler/NotificationKeeper.js +2 -2
  211. package/esm/sync/streaming/SSEHandler/index.js +2 -2
  212. package/esm/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.js → DefinitionsUpdateWorker.js} +17 -17
  213. package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +2 -2
  214. package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -2
  215. package/esm/sync/streaming/constants.js +2 -2
  216. package/esm/sync/streaming/parseUtils.js +10 -10
  217. package/esm/sync/streaming/pushManager.js +16 -16
  218. package/esm/sync/submitters/impressionsSubmitter.js +6 -6
  219. package/esm/sync/submitters/submitter.js +1 -1
  220. package/esm/sync/submitters/telemetrySubmitter.js +1 -2
  221. package/esm/sync/syncManagerOnline.js +8 -5
  222. package/esm/trackers/eventTracker.js +10 -12
  223. package/esm/trackers/impressionObserver/buildKey.js +1 -1
  224. package/esm/trackers/impressionsTracker.js +38 -21
  225. package/esm/trackers/uniqueKeysTracker.js +1 -1
  226. package/esm/utils/Backoff.js +20 -0
  227. package/esm/utils/EventEmitter.js +387 -0
  228. package/esm/utils/filter/bloomFilter.js +33 -0
  229. package/esm/utils/inputValidation/apiKey.js +1 -1
  230. package/esm/utils/inputValidation/attribute.js +2 -2
  231. package/esm/utils/inputValidation/{split.js → definition.js} +8 -8
  232. package/esm/utils/inputValidation/definitionExistence.js +15 -0
  233. package/esm/utils/inputValidation/definitions.js +21 -0
  234. package/esm/utils/inputValidation/index.js +3 -3
  235. package/esm/utils/inputValidation/isOperational.js +4 -4
  236. package/esm/utils/inputValidation/target.js +18 -0
  237. package/esm/utils/labels/index.js +2 -2
  238. package/esm/utils/lang/sets.js +4 -4
  239. package/esm/utils/promise/timeout.js +1 -1
  240. package/esm/utils/settingsValidation/splitFilters.js +4 -4
  241. package/esm/utils/settingsValidation/url.js +6 -6
  242. package/package.json +15 -6
  243. package/src/dtos/types.ts +65 -70
  244. package/src/evaluator/Engine.ts +4 -4
  245. package/src/evaluator/combiners/and.ts +3 -3
  246. package/src/evaluator/combiners/ifelseif.ts +2 -2
  247. package/src/evaluator/condition/engineUtils.ts +2 -2
  248. package/src/evaluator/condition/index.ts +3 -3
  249. package/src/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.ts +76 -0
  250. package/src/evaluator/fallbackConfigsCalculator/index.ts +24 -0
  251. package/src/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.ts +5 -7
  252. package/src/evaluator/fallbackTreatmentsCalculator/index.ts +27 -41
  253. package/src/evaluator/index.ts +86 -51
  254. package/src/evaluator/matchers/dependency.ts +2 -2
  255. package/src/evaluator/matchers/matcherTypes.ts +2 -2
  256. package/src/evaluator/matchers/prerequisites.ts +4 -4
  257. package/src/evaluator/matchers/rbsegment.ts +2 -2
  258. package/src/evaluator/matchers/whitelist.ts +2 -2
  259. package/src/evaluator/matchersTransform/index.ts +2 -2
  260. package/src/evaluator/matchersTransform/whitelist.ts +2 -2
  261. package/src/evaluator/parser/index.ts +4 -4
  262. package/src/evaluator/treatments/index.ts +2 -2
  263. package/src/evaluator/types.ts +6 -6
  264. package/src/evaluator/value/index.ts +1 -1
  265. package/src/integrations/pluggable.ts +1 -1
  266. package/src/listeners/browser.ts +11 -8
  267. package/src/listeners/node.ts +2 -5
  268. package/src/logger/constants.ts +12 -18
  269. package/src/logger/messages/debug.ts +5 -6
  270. package/src/logger/messages/error.ts +3 -3
  271. package/src/logger/messages/info.ts +1 -3
  272. package/src/logger/messages/warn.ts +8 -9
  273. package/src/platform/browser.ts +14 -0
  274. package/src/platform/getEventSource/browser.ts +4 -0
  275. package/src/platform/getEventSource/eventsource.js +519 -0
  276. package/src/platform/getEventSource/node.ts +23 -0
  277. package/src/platform/getFetch/browser.ts +5 -0
  278. package/src/platform/getFetch/node.ts +27 -0
  279. package/src/platform/getOptions/node.ts +24 -0
  280. package/src/platform/node.ts +16 -0
  281. package/src/readiness/constants.ts +4 -3
  282. package/src/readiness/readinessManager.ts +22 -22
  283. package/src/readiness/sdkReadinessManager.ts +1 -16
  284. package/src/readiness/types.ts +10 -16
  285. package/src/sdkClient/client.ts +11 -41
  286. package/src/sdkClient/clientInputValidation.ts +44 -84
  287. package/src/sdkClient/sdkClient.ts +5 -54
  288. package/src/sdkClient/sdkLifecycle.ts +79 -0
  289. package/src/sdkClient/trackMethod.ts +59 -0
  290. package/src/sdkFactory/index.ts +15 -59
  291. package/src/sdkFactory/types.ts +19 -16
  292. package/src/sdkManager/index.ts +15 -15
  293. package/src/services/authProvider.ts +86 -0
  294. package/src/services/secureSplitHttpClient.ts +44 -0
  295. package/src/services/splitApi.ts +14 -2
  296. package/src/services/types.ts +7 -2
  297. package/src/storages/AbstractDefinitionsCacheAsync.ts +63 -0
  298. package/src/storages/AbstractDefinitionsCacheSync.ts +95 -0
  299. package/src/storages/KeyBuilder.ts +6 -6
  300. package/src/storages/KeyBuilderCS.ts +6 -6
  301. package/src/storages/KeyBuilderSS.ts +2 -2
  302. package/src/storages/getRolloutPlan.ts +3 -3
  303. package/src/storages/inLocalStorage/DefinitionsCacheInLocal.ts +234 -0
  304. package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +8 -8
  305. package/src/storages/inLocalStorage/index.ts +6 -6
  306. package/src/storages/inLocalStorage/validateCache.ts +4 -4
  307. package/src/storages/inMemory/DefinitionsCacheInMemory.ts +130 -0
  308. package/src/storages/inMemory/InMemoryStorage.ts +4 -4
  309. package/src/storages/inMemory/InMemoryStorageCS.ts +5 -5
  310. package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +3 -3
  311. package/src/storages/inMemory/SegmentsCacheInMemory.ts +1 -1
  312. package/src/storages/inMemory/TelemetryCacheInMemory.ts +5 -5
  313. package/src/storages/inRedis/{SplitsCacheInRedis.ts → DefinitionsCacheInRedis.ts} +69 -69
  314. package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +2 -2
  315. package/src/storages/inRedis/index.ts +2 -2
  316. package/src/storages/pluggable/DefinitionsCachePluggable.ts +230 -0
  317. package/src/storages/pluggable/RBSegmentsCachePluggable.ts +2 -2
  318. package/src/storages/pluggable/index.ts +2 -2
  319. package/src/storages/setRolloutPlan.ts +7 -7
  320. package/src/storages/types.ts +34 -29
  321. package/src/sync/offline/splitsParser/parseCondition.ts +2 -2
  322. package/src/sync/offline/splitsParser/splitsParserFromSettings.ts +3 -3
  323. package/src/sync/offline/splitsParser/types.ts +6 -3
  324. package/src/sync/offline/syncManagerOffline.ts +2 -2
  325. package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +14 -14
  326. package/src/sync/polling/fetchers/splitChangesFetcher.ts +58 -23
  327. package/src/sync/polling/fetchers/types.ts +5 -3
  328. package/src/sync/polling/pollingManagerCS.ts +16 -14
  329. package/src/sync/polling/pollingManagerSS.ts +15 -13
  330. package/src/sync/polling/syncTasks/{splitsSyncTask.ts → definitionsSyncTask.ts} +11 -12
  331. package/src/sync/polling/types.ts +3 -3
  332. package/src/sync/polling/updaters/definitionChangesUpdater.ts +239 -0
  333. package/src/sync/polling/updaters/mySegmentsUpdater.ts +3 -3
  334. package/src/sync/polling/updaters/segmentChangesUpdater.ts +7 -7
  335. package/src/sync/streaming/AuthClient/index.ts +2 -2
  336. package/src/sync/streaming/AuthClient/types.ts +14 -11
  337. package/src/sync/streaming/SSEClient/index.ts +2 -2
  338. package/src/sync/streaming/SSEClient/types.ts +2 -2
  339. package/src/sync/streaming/SSEHandler/NotificationKeeper.ts +2 -2
  340. package/src/sync/streaming/SSEHandler/index.ts +2 -2
  341. package/src/sync/streaming/UpdateWorkers/{SplitsUpdateWorker.ts → DefinitionsUpdateWorker.ts} +21 -21
  342. package/src/sync/streaming/constants.ts +2 -2
  343. package/src/sync/streaming/parseUtils.ts +12 -12
  344. package/src/sync/streaming/pushManager.ts +18 -18
  345. package/src/sync/streaming/types.ts +2 -2
  346. package/src/sync/submitters/impressionsSubmitter.ts +9 -9
  347. package/src/sync/submitters/telemetrySubmitter.ts +1 -2
  348. package/src/sync/submitters/types.ts +3 -0
  349. package/src/sync/syncManagerOnline.ts +9 -5
  350. package/src/trackers/eventTracker.ts +7 -10
  351. package/src/trackers/impressionsTracker.ts +42 -26
  352. package/src/trackers/types.ts +3 -1
  353. package/src/utils/Backoff.ts +21 -0
  354. package/src/utils/EventEmitter.js +444 -0
  355. package/src/utils/filter/bloomFilter.ts +38 -0
  356. package/src/utils/inputValidation/definition.ts +27 -0
  357. package/src/utils/inputValidation/definitionExistence.ts +19 -0
  358. package/src/utils/inputValidation/definitions.ts +21 -0
  359. package/src/utils/inputValidation/index.ts +3 -3
  360. package/src/utils/inputValidation/isOperational.ts +4 -4
  361. package/src/utils/inputValidation/target.ts +21 -0
  362. package/src/utils/inputValidation/trafficTypeExistence.ts +2 -2
  363. package/src/utils/jwt/types.ts +1 -1
  364. package/src/utils/labels/index.ts +2 -2
  365. package/src/utils/lang/sets.ts +4 -2
  366. package/src/utils/settingsValidation/splitFilters.ts +3 -3
  367. package/src/utils/settingsValidation/url.ts +1 -1
  368. package/types/splitio.d.ts +222 -11
  369. package/cjs/storages/AbstractSplitsCacheAsync.js +0 -51
  370. package/cjs/storages/AbstractSplitsCacheSync.js +0 -76
  371. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +0 -194
  372. package/cjs/storages/inMemory/SplitsCacheInMemory.js +0 -121
  373. package/cjs/storages/inRedis/SplitsCacheInRedis.js +0 -243
  374. package/cjs/storages/pluggable/SplitsCachePluggable.js +0 -212
  375. package/cjs/sync/polling/syncTasks/splitsSyncTask.js +0 -13
  376. package/cjs/utils/inputValidation/splits.js +0 -25
  377. package/esm/storages/AbstractSplitsCacheAsync.js +0 -48
  378. package/esm/storages/AbstractSplitsCacheSync.js +0 -71
  379. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +0 -191
  380. package/esm/storages/inMemory/SplitsCacheInMemory.js +0 -118
  381. package/esm/storages/inRedis/SplitsCacheInRedis.js +0 -240
  382. package/esm/storages/pluggable/SplitsCachePluggable.js +0 -209
  383. package/esm/sync/polling/syncTasks/splitsSyncTask.js +0 -9
  384. package/esm/sync/polling/updaters/splitChangesUpdater.js +0 -192
  385. package/esm/utils/inputValidation/splitExistence.js +0 -15
  386. package/esm/utils/inputValidation/splits.js +0 -21
  387. package/src/storages/AbstractSplitsCacheAsync.ts +0 -63
  388. package/src/storages/AbstractSplitsCacheSync.ts +0 -95
  389. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +0 -234
  390. package/src/storages/inMemory/SplitsCacheInMemory.ts +0 -130
  391. package/src/storages/pluggable/SplitsCachePluggable.ts +0 -230
  392. package/src/sync/polling/updaters/splitChangesUpdater.ts +0 -230
  393. package/src/utils/inputValidation/split.ts +0 -27
  394. package/src/utils/inputValidation/splitExistence.ts +0 -19
  395. package/src/utils/inputValidation/splits.ts +0 -21
@@ -0,0 +1,230 @@
1
+ import { isFiniteNumber, isNaNNumber } from '../../utils/lang';
2
+ import { KeyBuilder } from '../KeyBuilder';
3
+ import { IPluggableStorageWrapper } from '../types';
4
+ import { ILogger } from '../../logger/types';
5
+ import { IDefinition, ISplitFiltersValidation } from '../../dtos/types';
6
+ import { LOG_PREFIX } from './constants';
7
+ import { AbstractDefinitionsCacheAsync } from '../AbstractDefinitionsCacheAsync';
8
+ import { returnDifference } from '../../utils/lang/sets';
9
+
10
+ /**
11
+ * IDefinitionsCacheAsync implementation for pluggable storages.
12
+ */
13
+ export class DefinitionsCachePluggable extends AbstractDefinitionsCacheAsync {
14
+
15
+ private readonly log: ILogger;
16
+ private readonly keys: KeyBuilder;
17
+ private readonly wrapper: IPluggableStorageWrapper;
18
+ private readonly setsFilter: string[];
19
+
20
+ /**
21
+ * Create a DefinitionsCache that uses a storage wrapper.
22
+ * @param log - Logger instance.
23
+ * @param keys - Key builder.
24
+ * @param wrapper - Adapted wrapper storage.
25
+ */
26
+ constructor(log: ILogger, keys: KeyBuilder, wrapper: IPluggableStorageWrapper, splitFiltersValidation?: ISplitFiltersValidation) {
27
+ super();
28
+ this.log = log;
29
+ this.keys = keys;
30
+ this.wrapper = wrapper;
31
+ this.setsFilter = splitFiltersValidation ? splitFiltersValidation.groupedFilters.bySet : [];
32
+ }
33
+
34
+ private _decrementCounts(definition: IDefinition) {
35
+ const ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
36
+ return this.wrapper.decr(ttKey).then(count => {
37
+ if (count === 0) return this.wrapper.del(ttKey);
38
+ });
39
+ }
40
+
41
+ private _incrementCounts(definition: IDefinition) {
42
+ const ttKey = this.keys.buildTrafficTypeKey(definition.trafficTypeName);
43
+ return this.wrapper.incr(ttKey);
44
+ }
45
+
46
+ private _updateSets(definitionName: string, setsOfRemovedDefinition?: string[] | null, setsOfAddedDefinition?: string[] | null) {
47
+ const removeFromSets = returnDifference(setsOfRemovedDefinition, setsOfAddedDefinition);
48
+
49
+ let addToSets = returnDifference(setsOfAddedDefinition, setsOfRemovedDefinition);
50
+ if (this.setsFilter.length > 0) {
51
+ addToSets = addToSets.filter(set => {
52
+ return this.setsFilter.some(filterSet => filterSet === set);
53
+ });
54
+ }
55
+
56
+ const items = [definitionName];
57
+
58
+ return Promise.all([
59
+ ...removeFromSets.map(setName => this.wrapper.removeItems(this.keys.buildSetKey(setName), items)),
60
+ ...addToSets.map(setName => this.wrapper.addItems(this.keys.buildSetKey(setName), items))
61
+ ]);
62
+ }
63
+
64
+ /**
65
+ * Add a given definition.
66
+ * The returned promise is resolved when the operation success
67
+ * or rejected if it fails (e.g., wrapper operation fails)
68
+ */
69
+ add(definition: IDefinition): Promise<boolean> {
70
+ const name = definition.name;
71
+ const definitionKey = this.keys.buildDefinitionKey(name);
72
+ return this.wrapper.get(definitionKey).then(definitionFromStorage => {
73
+
74
+ // handling parsing error
75
+ let parsedPreviousDefinition: IDefinition, stringifiedNewDefinition;
76
+ try {
77
+ parsedPreviousDefinition = definitionFromStorage ? JSON.parse(definitionFromStorage) : undefined;
78
+ stringifiedNewDefinition = JSON.stringify(definition);
79
+ } catch (e) {
80
+ throw new Error('Error parsing feature flag definition: ' + e);
81
+ }
82
+
83
+ return this.wrapper.set(definitionKey, stringifiedNewDefinition).then(() => {
84
+ // avoid unnecessary increment/decrement operations
85
+ if (parsedPreviousDefinition && parsedPreviousDefinition.trafficTypeName === definition.trafficTypeName) return;
86
+
87
+ // update traffic type counts
88
+ return this._incrementCounts(definition).then(() => {
89
+ if (parsedPreviousDefinition) return this._decrementCounts(parsedPreviousDefinition);
90
+ });
91
+ }).then(() => this._updateSets(name, parsedPreviousDefinition && parsedPreviousDefinition.sets, definition.sets));
92
+ }).then(() => true);
93
+ }
94
+
95
+ /**
96
+ * Remove a given definition.
97
+ * The returned promise is resolved when the operation success, with a boolean indicating if the definition existed or not.
98
+ * or rejected if it fails (e.g., wrapper operation fails).
99
+ */
100
+ remove(name: string) {
101
+ return this.get(name).then((definition) => {
102
+ if (definition) {
103
+ return this._decrementCounts(definition).then(() => this._updateSets(name, definition.sets));
104
+ }
105
+ }).then(() => {
106
+ return this.wrapper.del(this.keys.buildDefinitionKey(name));
107
+ });
108
+ }
109
+
110
+ /**
111
+ * Get definition.
112
+ * The returned promise is resolved with the definition or null if it's not defined,
113
+ * or rejected if wrapper operation fails.
114
+ */
115
+ get(name: string): Promise<IDefinition | null> {
116
+ return this.wrapper.get(this.keys.buildDefinitionKey(name))
117
+ .then(maybeDefinition => maybeDefinition && JSON.parse(maybeDefinition));
118
+ }
119
+
120
+ /**
121
+ * Get list of definitions.
122
+ * The returned promise is resolved with a map of names to their definition or null if it's not defined,
123
+ * or rejected if wrapper operation fails.
124
+ */
125
+ getMany(names: string[]): Promise<Record<string, IDefinition | null>> {
126
+ const keys = names.map(name => this.keys.buildDefinitionKey(name));
127
+
128
+ return this.wrapper.getMany(keys).then(stringifiedDefinitions => {
129
+ const definitions: Record<string, IDefinition | null> = {};
130
+ names.forEach((name, idx) => {
131
+ const definition = stringifiedDefinitions[idx];
132
+ definitions[name] = definition && JSON.parse(definition);
133
+ });
134
+ return Promise.resolve(definitions);
135
+ });
136
+ }
137
+
138
+ /**
139
+ * Get list of all definitions.
140
+ * The returned promise is resolved with the list of definitions,
141
+ * or rejected if wrapper operation fails.
142
+ */
143
+ getAll(): Promise<IDefinition[]> {
144
+ return this.wrapper.getKeysByPrefix(this.keys.buildDefinitionKeyPrefix())
145
+ .then((listOfKeys) => this.wrapper.getMany(listOfKeys))
146
+ .then((definitions) => definitions.map((definition) => {
147
+ return JSON.parse(definition as string);
148
+ }));
149
+ }
150
+
151
+ /**
152
+ * Get list of definition names.
153
+ * The returned promise is resolved with the list of names,
154
+ * or rejected if wrapper operation fails.
155
+ */
156
+ getNames(): Promise<string[]> {
157
+ return this.wrapper.getKeysByPrefix(this.keys.buildDefinitionKeyPrefix()).then(
158
+ (listOfKeys) => listOfKeys.map(this.keys.extractKey)
159
+ );
160
+ }
161
+
162
+ /**
163
+ * Get list of definition names related to a given list of set names.
164
+ * The returned promise is resolved with the list of names per set.
165
+ * It never rejects (If there is a wrapper error for some set, an empty set is returned for it).
166
+ */
167
+ getNamesBySets(sets: string[]): Promise<Set<string>[]> {
168
+ return Promise.all(sets.map(set => {
169
+ const setKey = this.keys.buildSetKey(set);
170
+ return this.wrapper.getItems(setKey).catch(() => []);
171
+ })).then(namesBySets => namesBySets.map(namesBySet => new Set(namesBySet)));
172
+ }
173
+
174
+ /**
175
+ * Check traffic type existence.
176
+ * The returned promise is resolved with a boolean indicating whether the TT exist or not.
177
+ * In case of wrapper operation failures, the promise resolves with a true value, assuming that the TT might exist.
178
+ * It will never be rejected.
179
+ */
180
+ trafficTypeExists(trafficType: string): Promise<boolean> {
181
+ // If there is a number there should be > 0, otherwise the TT is considered as not existent.
182
+ return this.wrapper.get(this.keys.buildTrafficTypeKey(trafficType))
183
+ .then((ttCount: string | null | number) => {
184
+ if (ttCount === null) return false; // if entry doesn't exist, means that TT doesn't exist
185
+
186
+ ttCount = parseInt(ttCount as string, 10);
187
+ if (!isFiniteNumber(ttCount) || ttCount < 0) {
188
+ this.log.info(LOG_PREFIX + `Could not validate traffic type existence of ${trafficType} due to data corruption of some sorts.`);
189
+ return false;
190
+ }
191
+
192
+ return ttCount > 0;
193
+ }).catch(e => {
194
+ this.log.error(LOG_PREFIX + `Could not validate traffic type existence of ${trafficType} due to an error: ${e}.`);
195
+ // If there is an error, bypass the validation so the event can get tracked.
196
+ return true;
197
+ });
198
+ }
199
+
200
+ /**
201
+ * Set till number.
202
+ * The returned promise is resolved when the operation success,
203
+ * or rejected if it fails (e.g., wrapper operation fails).
204
+ */
205
+ setChangeNumber(changeNumber: number) {
206
+ return this.wrapper.set(this.keys.buildDefinitionsTillKey(), changeNumber + '');
207
+ }
208
+
209
+ /**
210
+ * Get till number or -1 if it's not defined.
211
+ * The returned promise is resolved with the changeNumber or -1 if it doesn't exist or a wrapper operation fails.
212
+ * The promise will never be rejected.
213
+ */
214
+ getChangeNumber(): Promise<number> {
215
+ return this.wrapper.get(this.keys.buildDefinitionsTillKey()).then((value) => {
216
+ const i = parseInt(value as string, 10);
217
+
218
+ return isNaNNumber(i) ? -1 : i;
219
+ }).catch((e) => {
220
+ this.log.error(LOG_PREFIX + 'Could not retrieve changeNumber from storage. Error: ' + e);
221
+ return -1;
222
+ });
223
+ }
224
+
225
+ // @TODO implement if required by DataLoader or producer mode
226
+ clear() {
227
+ return Promise.resolve(true);
228
+ }
229
+
230
+ }
@@ -36,7 +36,7 @@ export class RBSegmentsCachePluggable implements IRBSegmentsCacheAsync {
36
36
  });
37
37
  }
38
38
 
39
- update(toAdd: IRBSegment[], toRemove: IRBSegment[], changeNumber: number): Promise<boolean> {
39
+ update(toAdd: IRBSegment[], toRemove: string[], changeNumber: number): Promise<boolean> {
40
40
  return Promise.all([
41
41
  this.setChangeNumber(changeNumber),
42
42
  Promise.all(toAdd.map(toAdd => {
@@ -45,7 +45,7 @@ export class RBSegmentsCachePluggable implements IRBSegmentsCacheAsync {
45
45
  return this.wrapper.set(key, stringifiedNewRBSegment).then(() => true);
46
46
  })),
47
47
  Promise.all(toRemove.map(toRemove => {
48
- const key = this.keys.buildRBSegmentKey(toRemove.name);
48
+ const key = this.keys.buildRBSegmentKey(toRemove);
49
49
  return this.wrapper.del(key);
50
50
  }))
51
51
  ]).then(([, added, removed]) => {
@@ -1,7 +1,7 @@
1
1
  import { IPluggableStorageWrapper, IStorageAsync, IStorageAsyncFactory, IStorageFactoryParams, ITelemetryCacheAsync } from '../types';
2
2
 
3
3
  import { KeyBuilderSS } from '../KeyBuilderSS';
4
- import { SplitsCachePluggable } from './SplitsCachePluggable';
4
+ import { DefinitionsCachePluggable } from './DefinitionsCachePluggable';
5
5
  import { SegmentsCachePluggable } from './SegmentsCachePluggable';
6
6
  import { ImpressionsCachePluggable } from './ImpressionsCachePluggable';
7
7
  import { EventsCachePluggable } from './EventsCachePluggable';
@@ -118,7 +118,7 @@ export function PluggableStorage(options: PluggableStorageOptions): IStorageAsyn
118
118
  });
119
119
 
120
120
  return {
121
- splits: new SplitsCachePluggable(log, keys, wrapper, settings.sync.__splitFiltersValidation),
121
+ definitions: new DefinitionsCachePluggable(log, keys, wrapper, settings.sync.__splitFiltersValidation),
122
122
  rbSegments: new RBSegmentsCachePluggable(log, keys, wrapper),
123
123
  segments: new SegmentsCachePluggable(log, keys, wrapper),
124
124
  impressions: isPartialConsumer ? new ImpressionsCacheInMemory(impressionsQueueSize) : new ImpressionsCachePluggable(log, keys.buildImpressionsKey(), wrapper, metadata),
@@ -1,5 +1,5 @@
1
1
  import SplitIO from '../../types/splitio';
2
- import { IRBSegmentsCacheSync, ISegmentsCacheSync, ISplitsCacheSync } from './types';
2
+ import { IRBSegmentsCacheSync, ISegmentsCacheSync, IDefinitionsCacheSync } from './types';
3
3
  import { ILogger } from '../logger/types';
4
4
  import { isObject } from '../utils/lang';
5
5
  import { isConsumerMode } from '../utils/settingsValidation/mode';
@@ -27,20 +27,20 @@ export function validateRolloutPlan(log: ILogger, settings: SplitIO.ISettings):
27
27
  * If `matchingKey` is provided, the storage is handled as a client-side storage (segments and largeSegments are instances of MySegmentsCache).
28
28
  * Otherwise, the storage is handled as a server-side storage (segments is an instance of SegmentsCache).
29
29
  */
30
- export function setRolloutPlan(log: ILogger, rolloutPlan: RolloutPlan, storage: { splits?: ISplitsCacheSync, rbSegments?: IRBSegmentsCacheSync, segments: ISegmentsCacheSync, largeSegments?: ISegmentsCacheSync }, matchingKey?: string) {
31
- const { splits, rbSegments, segments, largeSegments } = storage;
30
+ export function setRolloutPlan(log: ILogger, rolloutPlan: RolloutPlan, storage: { definitions?: IDefinitionsCacheSync, rbSegments?: IRBSegmentsCacheSync, segments: ISegmentsCacheSync, largeSegments?: ISegmentsCacheSync }, matchingKey?: string) {
31
+ const { definitions, rbSegments, segments, largeSegments } = storage;
32
32
  const { splitChanges: { ff, rbs } } = rolloutPlan;
33
33
 
34
34
  log.debug(`storage: set feature flags and segments${matchingKey ? ` for key ${matchingKey}` : ''}`);
35
35
 
36
- if (splits && ff) {
37
- splits.clear();
38
- splits.update(ff.d, [], ff.t);
36
+ if (definitions && ff) {
37
+ definitions.clear();
38
+ definitions.update(ff.d || [], [], ff.t);
39
39
  }
40
40
 
41
41
  if (rbSegments && rbs) {
42
42
  rbSegments.clear();
43
- rbSegments.update(rbs.d, [], rbs.t);
43
+ rbSegments.update(rbs.d || [], [], rbs.t);
44
44
  }
45
45
 
46
46
  const segmentChanges = rolloutPlan.segmentChanges;
@@ -1,5 +1,6 @@
1
1
  import SplitIO from '../../types/splitio';
2
- import { MaybeThenable, ISplit, IRBSegment, IMySegmentsResponse, IMembershipsResponse, ISegmentChangesResponse, ISplitChangesResponse } from '../dtos/types';
2
+ import { MaybeThenable, IDefinition, IRBSegment, IMySegmentsResponse, IMembershipsResponse, ISegmentChangesResponse } from '../dtos/types';
3
+ import { ISplitChangesResponse } from '../sync/polling/fetchers/splitChangesFetcher';
3
4
  import { MySegmentsData } from '../sync/polling/types';
4
5
  import { EventDataType, HttpErrors, HttpLatencies, ImpressionDataType, LastSync, Method, MethodExceptions, MethodLatencies, MultiMethodExceptions, MultiMethodLatencies, MultiConfigs, OperationType, StoredEventWithMetadata, StoredImpressionWithMetadata, StreamingEvent, UniqueKeysPayloadCs, UniqueKeysPayloadSs, TelemetryUsageStatsPayload, UpdatesFromSSEEnum } from '../sync/submitters/types';
5
6
  import { ISettings } from '../types';
@@ -193,55 +194,55 @@ export interface IPluggableStorageWrapper {
193
194
 
194
195
  /** Splits cache */
195
196
 
196
- export interface ISplitsCacheBase {
197
- update(toAdd: ISplit[], toRemove: ISplit[], changeNumber: number): MaybeThenable<boolean>,
198
- getSplit(name: string): MaybeThenable<ISplit | null>,
199
- getSplits(names: string[]): MaybeThenable<Record<string, ISplit | null>>, // `fetchMany` in spec
197
+ export interface IDefinitionsCacheBase {
198
+ update(toAdd: IDefinition[], toRemove: string[], changeNumber: number): MaybeThenable<boolean>,
199
+ get(name: string): MaybeThenable<IDefinition | null>,
200
+ getMany(names: string[]): MaybeThenable<Record<string, IDefinition | null>>, // `fetchMany` in spec
200
201
  // should never reject or throw an exception. Instead return -1 by default, assuming no splits are present in the storage.
201
202
  getChangeNumber(): MaybeThenable<number>,
202
- getAll(): MaybeThenable<ISplit[]>,
203
- getSplitNames(): MaybeThenable<string[]>,
203
+ getAll(): MaybeThenable<IDefinition[]>,
204
+ getNames(): MaybeThenable<string[]>,
204
205
  // should never reject or throw an exception. Instead return true by default, asssuming the TT might exist.
205
206
  trafficTypeExists(trafficType: string): MaybeThenable<boolean>,
206
207
  // only for Client-Side. Returns true if the storage is not synchronized yet (getChangeNumber() === -1) or contains a FF using segments or large segments
207
208
  usesSegments(): MaybeThenable<boolean>,
208
209
  clear(): MaybeThenable<boolean | void>,
209
210
  killLocally(name: string, defaultTreatment: string, changeNumber: number): MaybeThenable<boolean>,
210
- getNamesByFlagSets(flagSets: string[]): MaybeThenable<Set<string>[]>
211
+ getNamesBySets(sets: string[]): MaybeThenable<Set<string>[]>
211
212
  }
212
213
 
213
- export interface ISplitsCacheSync extends ISplitsCacheBase {
214
- update(toAdd: ISplit[], toRemove: ISplit[], changeNumber: number): boolean,
215
- getSplit(name: string): ISplit | null,
216
- getSplits(names: string[]): Record<string, ISplit | null>,
214
+ export interface IDefinitionsCacheSync extends IDefinitionsCacheBase {
215
+ update(toAdd: IDefinition[], toRemove: string[], changeNumber: number): boolean,
216
+ get(name: string): IDefinition | null,
217
+ getMany(names: string[]): Record<string, IDefinition | null>,
217
218
  getChangeNumber(): number,
218
- getAll(): ISplit[],
219
- getSplitNames(): string[],
219
+ getAll(): IDefinition[],
220
+ getNames(): string[],
220
221
  trafficTypeExists(trafficType: string): boolean,
221
222
  usesSegments(): boolean,
222
223
  clear(): void,
223
224
  killLocally(name: string, defaultTreatment: string, changeNumber: number): boolean,
224
- getNamesByFlagSets(flagSets: string[]): Set<string>[]
225
+ getNamesBySets(sets: string[]): Set<string>[]
225
226
  }
226
227
 
227
- export interface ISplitsCacheAsync extends ISplitsCacheBase {
228
- update(toAdd: ISplit[], toRemove: ISplit[], changeNumber: number): Promise<boolean>,
229
- getSplit(name: string): Promise<ISplit | null>,
230
- getSplits(names: string[]): Promise<Record<string, ISplit | null>>,
228
+ export interface IDefinitionsCacheAsync extends IDefinitionsCacheBase {
229
+ update(toAdd: IDefinition[], toRemove: string[], changeNumber: number): Promise<boolean>,
230
+ get(name: string): Promise<IDefinition | null>,
231
+ getMany(names: string[]): Promise<Record<string, IDefinition | null>>,
231
232
  getChangeNumber(): Promise<number>,
232
- getAll(): Promise<ISplit[]>,
233
- getSplitNames(): Promise<string[]>,
233
+ getAll(): Promise<IDefinition[]>,
234
+ getNames(): Promise<string[]>,
234
235
  trafficTypeExists(trafficType: string): Promise<boolean>,
235
236
  usesSegments(): Promise<boolean>,
236
237
  clear(): Promise<boolean | void>,
237
238
  killLocally(name: string, defaultTreatment: string, changeNumber: number): Promise<boolean>,
238
- getNamesByFlagSets(flagSets: string[]): Promise<Set<string>[]>
239
+ getNamesBySets(sets: string[]): Promise<Set<string>[]>
239
240
  }
240
241
 
241
242
  /** Rule-Based Segments cache */
242
243
 
243
244
  export interface IRBSegmentsCacheBase {
244
- update(toAdd: IRBSegment[], toRemove: IRBSegment[], changeNumber: number): MaybeThenable<boolean>,
245
+ update(toAdd: IRBSegment[], toRemove: string[], changeNumber: number): MaybeThenable<boolean>,
245
246
  get(name: string): MaybeThenable<IRBSegment | null>,
246
247
  getChangeNumber(): MaybeThenable<number>,
247
248
  clear(): MaybeThenable<boolean | void>,
@@ -249,7 +250,7 @@ export interface IRBSegmentsCacheBase {
249
250
  }
250
251
 
251
252
  export interface IRBSegmentsCacheSync extends IRBSegmentsCacheBase {
252
- update(toAdd: IRBSegment[], toRemove: IRBSegment[], changeNumber: number): boolean,
253
+ update(toAdd: IRBSegment[], toRemove: string[], changeNumber: number): boolean,
253
254
  get(name: string): IRBSegment | null,
254
255
  getChangeNumber(): number,
255
256
  getAll(): IRBSegment[],
@@ -260,7 +261,7 @@ export interface IRBSegmentsCacheSync extends IRBSegmentsCacheBase {
260
261
  }
261
262
 
262
263
  export interface IRBSegmentsCacheAsync extends IRBSegmentsCacheBase {
263
- update(toAdd: IRBSegment[], toRemove: IRBSegment[], changeNumber: number): Promise<boolean>,
264
+ update(toAdd: IRBSegment[], toRemove: string[], changeNumber: number): Promise<boolean>,
264
265
  get(name: string): Promise<IRBSegment | null>,
265
266
  getChangeNumber(): Promise<number>,
266
267
  clear(): Promise<boolean | void>,
@@ -465,7 +466,7 @@ export interface ITelemetryCacheAsync extends ITelemetryEvaluationProducerAsync,
465
466
  */
466
467
 
467
468
  export interface IStorageBase<
468
- TSplitsCache extends ISplitsCacheBase = ISplitsCacheBase,
469
+ TDefinitionsCache extends IDefinitionsCacheBase = IDefinitionsCacheBase,
469
470
  TRBSegmentsCache extends IRBSegmentsCacheBase = IRBSegmentsCacheBase,
470
471
  TSegmentsCache extends ISegmentsCacheBase = ISegmentsCacheBase,
471
472
  TImpressionsCache extends IImpressionsCacheBase = IImpressionsCacheBase,
@@ -474,7 +475,7 @@ export interface IStorageBase<
474
475
  TTelemetryCache extends ITelemetryCacheSync | ITelemetryCacheAsync = ITelemetryCacheSync | ITelemetryCacheAsync,
475
476
  TUniqueKeysCache extends IUniqueKeysCacheBase = IUniqueKeysCacheBase
476
477
  > {
477
- splits: TSplitsCache,
478
+ definitions: TDefinitionsCache,
478
479
  rbSegments: TRBSegmentsCache,
479
480
  segments: TSegmentsCache,
480
481
  largeSegments?: TSegmentsCache,
@@ -489,7 +490,7 @@ export interface IStorageBase<
489
490
  }
490
491
 
491
492
  export interface IStorageSync extends IStorageBase<
492
- ISplitsCacheSync,
493
+ IDefinitionsCacheSync,
493
494
  IRBSegmentsCacheSync,
494
495
  ISegmentsCacheSync,
495
496
  IImpressionsCacheSync,
@@ -504,7 +505,7 @@ export interface IStorageSync extends IStorageBase<
504
505
  }
505
506
 
506
507
  export interface IStorageAsync extends IStorageBase<
507
- ISplitsCacheAsync,
508
+ IDefinitionsCacheAsync,
508
509
  IRBSegmentsCacheAsync,
509
510
  ISegmentsCacheAsync,
510
511
  IImpressionsCacheAsync | IImpressionsCacheSync,
@@ -527,6 +528,10 @@ export interface IStorageFactoryParams {
527
528
  * For emitting SDK_READY_FROM_CACHE event in consumer mode with Redis to allow immediate evaluations
528
529
  */
529
530
  onReadyFromCacheCb: () => void,
531
+ /**
532
+ * If true, telemetry will not be recorded.
533
+ */
534
+ disableTelemetry?: boolean,
530
535
  }
531
536
 
532
537
 
@@ -1,4 +1,4 @@
1
- import { ISplitCondition } from '../../../dtos/types';
1
+ import { IDefinitionCondition } from '../../../dtos/types';
2
2
  import { isString } from '../../../utils/lang';
3
3
 
4
4
  export interface IMockSplitEntry {
@@ -7,7 +7,7 @@ export interface IMockSplitEntry {
7
7
  config?: string
8
8
  }
9
9
 
10
- export function parseCondition(data: IMockSplitEntry): ISplitCondition {
10
+ export function parseCondition(data: IMockSplitEntry): IDefinitionCondition {
11
11
  const treatment = data.treatment;
12
12
 
13
13
  if (data.keys) {
@@ -1,4 +1,4 @@
1
- import { ISplitPartial } from '../../../dtos/types';
1
+ import { IDefinitionPartial } from './types';
2
2
  import SplitIO from '../../../../types/splitio';
3
3
  import { isObject, forOwn, merge } from '../../../utils/lang';
4
4
  import { parseCondition } from './parseCondition';
@@ -41,12 +41,12 @@ export function splitsParserFromSettingsFactory() {
41
41
  *
42
42
  * @param settings - validated object with mocked features mapping.
43
43
  */
44
- return function splitsParserFromSettings(settings: Pick<SplitIO.ISettings, 'features'>): false | Record<string, ISplitPartial> {
44
+ return function splitsParserFromSettings(settings: Pick<SplitIO.ISettings, 'features'>): false | Record<string, IDefinitionPartial> {
45
45
  const features = settings.features as SplitIO.MockedFeaturesMap || {};
46
46
 
47
47
  if (!mockUpdated(features)) return false;
48
48
 
49
- const splitObjects: Record<string, ISplitPartial> = {};
49
+ const splitObjects: Record<string, IDefinitionPartial> = {};
50
50
 
51
51
  forOwn(features, (data, splitName) => {
52
52
  let treatment = data;
@@ -1,5 +1,8 @@
1
- import { ISplitPartial } from '../../../dtos/types';
1
+ import { IDefinition } from '../../../dtos/types';
2
2
  import { ISettings } from '../../../types';
3
3
 
4
- // Analog to `ISplitChangesFetcher` used by `splitChangesUpdaterFactory`
5
- export type ISplitsParser = (settings: ISettings) => false | Record<string, ISplitPartial>
4
+ // Split definition used in offline mode
5
+ export type IDefinitionPartial = Pick<IDefinition, 'conditions' | 'configurations' | 'trafficTypeName'>
6
+
7
+ // Analog to `IDefinitionChangesFetcher` used by `definitionChangesUpdaterFactory`
8
+ export type IDefinitionsParser = (settings: ISettings) => false | Record<string, IDefinitionPartial>
@@ -1,7 +1,7 @@
1
1
  import { ISyncManagerCS } from '../types';
2
2
  import { fromObjectSyncTaskFactory } from './syncTasks/fromObjectSyncTask';
3
3
  import { objectAssign } from '../../utils/lang/objectAssign';
4
- import { ISplitsParser } from './splitsParser/types';
4
+ import { IDefinitionsParser } from './splitsParser/types';
5
5
  import { IReadinessManager } from '../../readiness/types';
6
6
  import { SDK_SEGMENTS_ARRIVED } from '../../readiness/constants';
7
7
  import { ISdkFactoryContextSync } from '../../sdkFactory/types';
@@ -17,7 +17,7 @@ function flush() {
17
17
  * @param splitsParser - e.g., `splitsParserFromFile`, `splitsParserFromSettings`.
18
18
  */
19
19
  export function syncManagerOfflineFactory(
20
- splitsParserFactory: () => ISplitsParser
20
+ splitsParserFactory: () => IDefinitionsParser
21
21
  ): (params: ISdkFactoryContextSync) => ISyncManagerCS {
22
22
 
23
23
  /**
@@ -1,32 +1,32 @@
1
1
  import { forOwn } from '../../../utils/lang';
2
2
  import { IReadinessManager } from '../../../readiness/types';
3
3
  import { IStorageSync } from '../../../storages/types';
4
- import { ISplitsParser } from '../splitsParser/types';
5
- import { ISplit, ISplitPartial } from '../../../dtos/types';
4
+ import { IDefinitionsParser, IDefinitionPartial } from '../splitsParser/types';
5
+ import { IDefinition } from '../../../dtos/types';
6
6
  import { syncTaskFactory } from '../../syncTask';
7
7
  import { ISyncTask } from '../../types';
8
8
  import { ISettings } from '../../../types';
9
9
  import { CONTROL } from '../../../utils/constants';
10
- import { SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED, SDK_SPLITS_CACHE_LOADED, FLAGS_UPDATE, SEGMENTS_UPDATE } from '../../../readiness/constants';
10
+ import { SDK_DEFINITIONS_ARRIVED, SDK_SEGMENTS_ARRIVED, SDK_DEFINITIONS_CACHE_LOADED, FLAGS_UPDATE, SEGMENTS_UPDATE } from '../../../readiness/constants';
11
11
  import { SYNC_OFFLINE_DATA, ERROR_SYNC_OFFLINE_LOADING } from '../../../logger/constants';
12
12
 
13
13
  /**
14
14
  * Offline equivalent of `splitChangesUpdaterFactory`
15
15
  */
16
16
  export function fromObjectUpdaterFactory(
17
- splitsParser: ISplitsParser,
18
- storage: Pick<IStorageSync, 'splits' | 'validateCache'>,
17
+ splitsParser: IDefinitionsParser,
18
+ storage: Pick<IStorageSync, 'definitions' | 'validateCache'>,
19
19
  readiness: IReadinessManager,
20
20
  settings: ISettings,
21
21
  ): () => Promise<boolean> {
22
22
 
23
- const log = settings.log, splitsCache = storage.splits;
23
+ const log = settings.log, definitions = storage.definitions;
24
24
  let startingUp = true;
25
25
 
26
26
  return function objectUpdater() {
27
- const splits: ISplit[] = [];
27
+ const splits: IDefinition[] = [];
28
28
  let loadError = null;
29
- let splitsMock: false | Record<string, ISplitPartial> = {};
29
+ let splitsMock: false | Record<string, IDefinitionPartial> = {};
30
30
  try {
31
31
  splitsMock = splitsParser(settings);
32
32
  } catch (err) {
@@ -52,17 +52,17 @@ export function fromObjectUpdaterFactory(
52
52
  });
53
53
 
54
54
  return Promise.all([
55
- splitsCache.clear(), // required to sync removed splits from mock
56
- splitsCache.update(splits, [], Date.now())
55
+ definitions.clear(), // required to sync removed splits from mock
56
+ definitions.update(splits, [], Date.now())
57
57
  ]).then(() => {
58
- readiness.splits.emit(SDK_SPLITS_ARRIVED, { type: FLAGS_UPDATE, names: [] });
58
+ readiness.definitions.emit(SDK_DEFINITIONS_ARRIVED, { type: FLAGS_UPDATE, names: [] });
59
59
 
60
60
  if (startingUp) {
61
61
  startingUp = false;
62
62
  Promise.resolve(storage.validateCache ? storage.validateCache() : { initialCacheLoad: true /* Fallback: assume initial load when validateCache doesn't exist */ }).then((cacheMetadata) => {
63
63
  // Emits SDK_READY_FROM_CACHE
64
64
  if (!cacheMetadata.initialCacheLoad) {
65
- readiness.splits.emit(SDK_SPLITS_CACHE_LOADED, cacheMetadata);
65
+ readiness.definitions.emit(SDK_DEFINITIONS_CACHE_LOADED, cacheMetadata);
66
66
  }
67
67
  // Emits SDK_READY
68
68
  readiness.segments.emit(SDK_SEGMENTS_ARRIVED, { type: SEGMENTS_UPDATE, names: [] });
@@ -80,8 +80,8 @@ export function fromObjectUpdaterFactory(
80
80
  * PollingManager in Offline mode
81
81
  */
82
82
  export function fromObjectSyncTaskFactory(
83
- splitsParser: ISplitsParser,
84
- storage: Pick<IStorageSync, 'splits' | 'validateCache'>,
83
+ splitsParser: IDefinitionsParser,
84
+ storage: Pick<IStorageSync, 'definitions' | 'validateCache'>,
85
85
  readiness: IReadinessManager,
86
86
  settings: ISettings
87
87
  ): ISyncTask<[], boolean> {