@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,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateTarget = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var lang_1 = require("../lang");
6
+ var key_1 = require("./key");
7
+ var attributes_1 = require("./attributes");
8
+ var constants_1 = require("../../logger/constants");
9
+ function validateTarget(log, maybeTarget, method) {
10
+ if (!(0, lang_1.isObject)(maybeTarget)) {
11
+ log.error(constants_1.ERROR_NOT_PLAIN_OBJECT, [method, 'target']);
12
+ return false;
13
+ }
14
+ var key = (0, key_1.validateKey)(log, maybeTarget.key, method);
15
+ if (key === false)
16
+ return false;
17
+ var attributes = (0, attributes_1.validateAttributes)(log, maybeTarget.attributes, method);
18
+ if (attributes === false)
19
+ return false;
20
+ return tslib_1.__assign(tslib_1.__assign({}, maybeTarget), { key: key, attributes: attributes });
21
+ }
22
+ exports.validateTarget = validateTarget;
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FALLBACK_SPLIT_NOT_FOUND = exports.PREREQUISITES_NOT_MET = exports.UNSUPPORTED_MATCHER_TYPE = exports.NOT_IN_SPLIT = exports.SPLIT_ARCHIVED = exports.EXCEPTION = exports.SDK_NOT_READY = exports.SPLIT_NOT_FOUND = exports.NO_CONDITION_MATCH = exports.SPLIT_KILLED = void 0;
3
+ exports.FALLBACK_DEFINITION_NOT_FOUND = exports.PREREQUISITES_NOT_MET = exports.UNSUPPORTED_MATCHER_TYPE = exports.NOT_IN_SPLIT = exports.SPLIT_ARCHIVED = exports.EXCEPTION = exports.SDK_NOT_READY = exports.DEFINITION_NOT_FOUND = exports.NO_CONDITION_MATCH = exports.SPLIT_KILLED = void 0;
4
4
  var fallbackTreatmentsCalculator_1 = require("../../evaluator/fallbackTreatmentsCalculator");
5
5
  exports.SPLIT_KILLED = 'killed';
6
6
  exports.NO_CONDITION_MATCH = 'default rule';
7
- exports.SPLIT_NOT_FOUND = 'definition not found';
7
+ exports.DEFINITION_NOT_FOUND = 'definition not found';
8
8
  exports.SDK_NOT_READY = 'not ready';
9
9
  exports.EXCEPTION = 'exception';
10
10
  exports.SPLIT_ARCHIVED = 'archived';
11
11
  exports.NOT_IN_SPLIT = 'not in split';
12
12
  exports.UNSUPPORTED_MATCHER_TYPE = 'targeting rule type unsupported by sdk';
13
13
  exports.PREREQUISITES_NOT_MET = 'prerequisites not met';
14
- exports.FALLBACK_SPLIT_NOT_FOUND = fallbackTreatmentsCalculator_1.FALLBACK_PREFIX + exports.SPLIT_NOT_FOUND;
14
+ exports.FALLBACK_DEFINITION_NOT_FOUND = fallbackTreatmentsCalculator_1.FALLBACK_PREFIX + exports.DEFINITION_NOT_FOUND;
@@ -200,7 +200,7 @@ function merge(target, source) {
200
200
  });
201
201
  if (rest && rest.length) {
202
202
  var nextSource = rest.splice(0, 1)[0];
203
- res = merge.apply(void 0, (0, tslib_1.__spreadArray)([res, nextSource], rest, false));
203
+ res = merge.apply(void 0, tslib_1.__spreadArray([res, nextSource], rest, false));
204
204
  }
205
205
  return res;
206
206
  }
@@ -15,9 +15,9 @@ function returnSetsUnion(set, set2) {
15
15
  return new Set(setToArray(set).concat(setToArray(set2)));
16
16
  }
17
17
  exports.returnSetsUnion = returnSetsUnion;
18
- function returnDifference(list, list2) {
19
- if (list === void 0) { list = []; }
20
- if (list2 === void 0) { list2 = []; }
21
- return list.filter(function (item) { return list2.indexOf(item) === -1; });
18
+ function returnDifference(list1, list2) {
19
+ list1 = list1 || [];
20
+ list2 = list2 || [];
21
+ return list1.filter(function (item) { return list2.indexOf(item) === -1; });
22
22
  }
23
23
  exports.returnDifference = returnDifference;
@@ -6,7 +6,7 @@ function timeout(ms, promise) {
6
6
  return promise;
7
7
  return new Promise(function (resolve, reject) {
8
8
  var tid = setTimeout(function () {
9
- reject(new Error("Operation timed out because it exceeded the configured time limit of " + ms + " ms."));
9
+ reject(new Error("Operation timed out because it exceeded the configured time limit of ".concat(ms, " ms.")));
10
10
  }, ms);
11
11
  promise.then(function (res) {
12
12
  clearTimeout(tid);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateFlagSets = exports.validateSplitFilters = void 0;
4
- var splits_1 = require("../inputValidation/splits");
4
+ var definitions_1 = require("../inputValidation/definitions");
5
5
  var constants_1 = require("../../logger/constants");
6
6
  var objectAssign_1 = require("../lang/objectAssign");
7
7
  var lang_1 = require("../lang");
@@ -45,14 +45,14 @@ function validateFilterType(maybeFilterType) {
45
45
  */
46
46
  function validateSplitFilter(log, type, values, maxLength) {
47
47
  // validate and remove invalid and duplicated values
48
- var result = (0, splits_1.validateSplits)(log, values, constants_1.LOG_PREFIX_SETTINGS, type + " filter", type + " filter value");
48
+ var result = (0, definitions_1.validateDefinitions)(log, values, constants_1.LOG_PREFIX_SETTINGS, "".concat(type, " filter"), "".concat(type, " filter value"));
49
49
  if (result) {
50
50
  if (type === 'bySet') {
51
51
  result = sanitizeFlagSets(log, result, constants_1.LOG_PREFIX_SETTINGS);
52
52
  }
53
53
  // check max length
54
54
  if (result.length > maxLength)
55
- throw new Error(maxLength + " unique values can be specified at most for '" + type + "' filter. You passed " + result.length + ". Please consider reducing the amount or using other filter.");
55
+ throw new Error("".concat(maxLength, " unique values can be specified at most for '").concat(type, "' filter. You passed ").concat(result.length, ". Please consider reducing the amount or using other filter."));
56
56
  // sort values
57
57
  result.sort();
58
58
  }
@@ -172,7 +172,7 @@ function validateSplitFilters(log, maybeSplitFilters, mode) {
172
172
  }
173
173
  exports.validateSplitFilters = validateSplitFilters;
174
174
  function validateFlagSets(log, method, flagSets, flagSetsInConfig) {
175
- var sets = (0, splits_1.validateSplits)(log, flagSets, method, 'flag sets', 'flag set');
175
+ var sets = (0, definitions_1.validateDefinitions)(log, flagSets, method, 'flag sets', 'flag set');
176
176
  var toReturn = sets ? sanitizeFlagSets(log, sets, method) : [];
177
177
  if (flagSetsInConfig.length > 0) {
178
178
  toReturn = toReturn.filter(function (flagSet) {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.url = void 0;
4
4
  var telemetryEndpointMatcher = /^\/v1\/metrics\/(config|usage)/;
5
5
  var eventsEndpointMatcher = /^\/(testImpressions|metrics|events)/;
6
- var authEndpointMatcher = /^\/v2\/auth/;
6
+ var authEndpointMatcher = /^\/(v2|v3)\/auth/;
7
7
  var streamingEndpointMatcher = /^\/(sse|event-stream)/;
8
8
  /**
9
9
  * Get URL based on a given target (path).
@@ -15,17 +15,17 @@ var streamingEndpointMatcher = /^\/(sse|event-stream)/;
15
15
  */
16
16
  function url(settings, target) {
17
17
  if (telemetryEndpointMatcher.test(target)) {
18
- return "" + settings.urls.telemetry + target;
18
+ return "".concat(settings.urls.telemetry).concat(target);
19
19
  }
20
20
  if (eventsEndpointMatcher.test(target)) {
21
- return "" + settings.urls.events + target;
21
+ return "".concat(settings.urls.events).concat(target);
22
22
  }
23
23
  if (authEndpointMatcher.test(target)) {
24
- return "" + settings.urls.auth + target;
24
+ return "".concat(settings.urls.auth).concat(target);
25
25
  }
26
26
  if (streamingEndpointMatcher.test(target)) {
27
- return "" + settings.urls.streaming + target;
27
+ return "".concat(settings.urls.streaming).concat(target);
28
28
  }
29
- return "" + settings.urls.sdk + target;
29
+ return "".concat(settings.urls.sdk).concat(target);
30
30
  }
31
31
  exports.url = url;
@@ -12,10 +12,10 @@ export function getTreatment(log, key, seed, treatments) {
12
12
  /**
13
13
  * Evaluates the traffic allocation to see if we should apply rollout conditions or not.
14
14
  */
15
- export function shouldApplyRollout(trafficAllocation, key, trafficAllocationSeed) {
15
+ export function shouldApplyRollout(trafficAllocation, bucketingKey, trafficAllocationSeed) {
16
16
  // For rollout, if traffic allocation for splits is 100%, we don't need to filter it because everything should evaluate the rollout.
17
17
  if (trafficAllocation < 100) {
18
- var _bucket = bucket(key, trafficAllocationSeed);
18
+ var _bucket = bucket(bucketingKey, trafficAllocationSeed);
19
19
  if (_bucket > trafficAllocation) {
20
20
  return false;
21
21
  }
@@ -0,0 +1,64 @@
1
+ import { isObject, isString } from '../../../utils/lang';
2
+ var CONFIG_NAME_DISCARD_REASON = 'Invalid config name (max 100 chars, no spaces)';
3
+ var VARIANT_DISCARD_REASON = 'Invalid variant (max 100 chars and must match pattern)';
4
+ var VALUE_DISCARD_REASON = 'Invalid value (must be an object)';
5
+ var VARIANT_PATTERN = /^[0-9]+[.a-zA-Z0-9_-]*$|^[a-zA-Z]+[a-zA-Z0-9_-]*$/;
6
+ export function isValidConfigName(name) {
7
+ return name.length <= 100 && !name.includes(' ');
8
+ }
9
+ export function isValidConfig(config) {
10
+ if (!isObject(config))
11
+ return false;
12
+ if (!isString(config.variant) || config.variant.length > 100 || !VARIANT_PATTERN.test(config.variant))
13
+ return false;
14
+ if (!isObject(config.value))
15
+ return false;
16
+ return true;
17
+ }
18
+ function sanitizeGlobal(logger, config) {
19
+ if (config === undefined)
20
+ return undefined;
21
+ if (!isValidConfig(config)) {
22
+ if (!isObject(config) || !isString(config.variant) || config.variant.length > 100 || !VARIANT_PATTERN.test(config.variant)) {
23
+ logger.error("Fallback configs - Discarded fallback: ".concat(VARIANT_DISCARD_REASON));
24
+ }
25
+ else {
26
+ logger.error("Fallback configs - Discarded fallback: ".concat(VALUE_DISCARD_REASON));
27
+ }
28
+ return undefined;
29
+ }
30
+ return config;
31
+ }
32
+ function sanitizeByName(logger, byNameFallbacks) {
33
+ var sanitizedByName = {};
34
+ if (!isObject(byNameFallbacks))
35
+ return sanitizedByName;
36
+ Object.keys(byNameFallbacks).forEach(function (configName) {
37
+ var config = byNameFallbacks[configName];
38
+ if (!isValidConfigName(configName)) {
39
+ logger.error("Fallback configs - Discarded config '".concat(configName, "': ").concat(CONFIG_NAME_DISCARD_REASON));
40
+ return;
41
+ }
42
+ if (!isValidConfig(config)) {
43
+ if (!isObject(config) || !isString(config.variant) || config.variant.length > 100 || !VARIANT_PATTERN.test(config.variant)) {
44
+ logger.error("Fallback configs - Discarded config '".concat(configName, "': ").concat(VARIANT_DISCARD_REASON));
45
+ }
46
+ else {
47
+ logger.error("Fallback configs - Discarded config '".concat(configName, "': ").concat(VALUE_DISCARD_REASON));
48
+ }
49
+ return;
50
+ }
51
+ sanitizedByName[configName] = config;
52
+ });
53
+ return sanitizedByName;
54
+ }
55
+ export function sanitizeFallbacks(logger, fallbacks) {
56
+ if (!isObject(fallbacks)) {
57
+ logger.error('Fallback configs - Discarded configuration: it must be an object with optional `global` and `byName` properties');
58
+ return;
59
+ }
60
+ return {
61
+ global: sanitizeGlobal(logger, fallbacks.global),
62
+ byName: sanitizeByName(logger, fallbacks.byName)
63
+ };
64
+ }
@@ -0,0 +1,21 @@
1
+ import { CONTROL } from '../../utils/constants';
2
+ export var FALLBACK_PREFIX = 'fallback - ';
3
+ export function FallbackConfigsCalculator(fallbacks) {
4
+ if (fallbacks === void 0) { fallbacks = {}; }
5
+ return function (configName, label) {
6
+ var _a;
7
+ if (label === void 0) { label = ''; }
8
+ var fallback = ((_a = fallbacks.byName) === null || _a === void 0 ? void 0 : _a[configName]) || fallbacks.global;
9
+ return fallback ?
10
+ {
11
+ treatment: fallback.variant,
12
+ config: fallback.value,
13
+ label: "".concat(FALLBACK_PREFIX).concat(label),
14
+ } :
15
+ {
16
+ treatment: CONTROL,
17
+ config: null,
18
+ label: label,
19
+ };
20
+ };
21
+ }
@@ -1,9 +1,6 @@
1
1
  import { isObject, isString } from '../../../utils/lang';
2
- var FallbackDiscardReason;
3
- (function (FallbackDiscardReason) {
4
- FallbackDiscardReason["FlagName"] = "Invalid flag name (max 100 chars, no spaces)";
5
- FallbackDiscardReason["Treatment"] = "Invalid treatment (max 100 chars and must match pattern)";
6
- })(FallbackDiscardReason || (FallbackDiscardReason = {}));
2
+ var FLAG_NAME_DISCARD_REASON = 'Invalid flag name (max 100 chars, no spaces)';
3
+ var TREATMENT_DISCARD_REASON = 'Invalid treatment (max 100 chars and must match pattern)';
7
4
  var TREATMENT_PATTERN = /^[0-9]+[.a-zA-Z0-9_-]*$|^[a-zA-Z]+[a-zA-Z0-9_-]*$/;
8
5
  export function isValidFlagName(name) {
9
6
  return name.length <= 100 && !name.includes(' ');
@@ -19,7 +16,7 @@ function sanitizeGlobal(logger, treatment) {
19
16
  if (treatment === undefined)
20
17
  return undefined;
21
18
  if (!isValidTreatment(treatment)) {
22
- logger.error("Fallback treatments - Discarded fallback: " + FallbackDiscardReason.Treatment);
19
+ logger.error("Fallback treatments - Discarded fallback: ".concat(TREATMENT_DISCARD_REASON));
23
20
  return undefined;
24
21
  }
25
22
  return treatment;
@@ -31,11 +28,11 @@ function sanitizeByFlag(logger, byFlagFallbacks) {
31
28
  Object.keys(byFlagFallbacks).forEach(function (flag) {
32
29
  var t = byFlagFallbacks[flag];
33
30
  if (!isValidFlagName(flag)) {
34
- logger.error("Fallback treatments - Discarded flag '" + flag + "': " + FallbackDiscardReason.FlagName);
31
+ logger.error("Fallback treatments - Discarded flag '".concat(flag, "': ").concat(FLAG_NAME_DISCARD_REASON));
35
32
  return;
36
33
  }
37
34
  if (!isValidTreatment(t)) {
38
- logger.error("Fallback treatments - Discarded treatment for flag '" + flag + "': " + FallbackDiscardReason.Treatment);
35
+ logger.error("Fallback treatments - Discarded treatment for flag '".concat(flag, "': ").concat(TREATMENT_DISCARD_REASON));
39
36
  return;
40
37
  }
41
38
  sanitizedByFlag[flag] = t;
@@ -1,40 +1,28 @@
1
1
  import { CONTROL } from '../../utils/constants';
2
2
  import { isString } from '../../utils/lang';
3
3
  export var FALLBACK_PREFIX = 'fallback - ';
4
- var FallbackTreatmentsCalculator = /** @class */ (function () {
5
- function FallbackTreatmentsCalculator(fallbacks) {
6
- if (fallbacks === void 0) { fallbacks = {}; }
7
- this.fallbacks = fallbacks;
8
- }
9
- FallbackTreatmentsCalculator.prototype.resolve = function (flagName, label) {
4
+ export function FallbackTreatmentsCalculator(fallbacks) {
5
+ if (fallbacks === void 0) { fallbacks = {}; }
6
+ return function (flagName, label) {
10
7
  var _a;
11
- var treatment = (_a = this.fallbacks.byFlag) === null || _a === void 0 ? void 0 : _a[flagName];
12
- if (treatment) {
13
- return this.copyWithLabel(treatment, label);
14
- }
15
- if (this.fallbacks.global) {
16
- return this.copyWithLabel(this.fallbacks.global, label);
17
- }
18
- return {
19
- treatment: CONTROL,
20
- config: null,
21
- label: label,
22
- };
23
- };
24
- FallbackTreatmentsCalculator.prototype.copyWithLabel = function (fallback, label) {
25
- if (isString(fallback)) {
26
- return {
27
- treatment: fallback,
8
+ if (label === void 0) { label = ''; }
9
+ var fallback = ((_a = fallbacks.byFlag) === null || _a === void 0 ? void 0 : _a[flagName]) || fallbacks.global;
10
+ return fallback ?
11
+ isString(fallback) ?
12
+ {
13
+ treatment: fallback,
14
+ config: null,
15
+ label: "".concat(FALLBACK_PREFIX).concat(label),
16
+ } :
17
+ {
18
+ treatment: fallback.treatment,
19
+ config: fallback.config,
20
+ label: "".concat(FALLBACK_PREFIX).concat(label),
21
+ } :
22
+ {
23
+ treatment: CONTROL,
28
24
  config: null,
29
- label: "" + FALLBACK_PREFIX + label,
25
+ label: label,
30
26
  };
31
- }
32
- return {
33
- treatment: fallback.treatment,
34
- config: fallback.config,
35
- label: "" + FALLBACK_PREFIX + label,
36
- };
37
27
  };
38
- return FallbackTreatmentsCalculator;
39
- }());
40
- export { FallbackTreatmentsCalculator };
28
+ }
@@ -1,55 +1,60 @@
1
1
  import { engineParser } from './Engine';
2
2
  import { thenable } from '../utils/promise/thenable';
3
- import { EXCEPTION, SPLIT_NOT_FOUND } from '../utils/labels';
3
+ import { EXCEPTION, NO_CONDITION_MATCH, DEFINITION_NOT_FOUND } from '../utils/labels';
4
4
  import { CONTROL } from '../utils/constants';
5
5
  import { returnSetsUnion, setToArray } from '../utils/lang/sets';
6
6
  import { WARN_FLAGSET_WITHOUT_FLAGS } from '../logger/constants';
7
- var treatmentException = {
7
+ var EVALUATION_EXCEPTION = {
8
8
  treatment: CONTROL,
9
9
  label: EXCEPTION,
10
10
  config: null
11
11
  };
12
- function treatmentsException(splitNames) {
12
+ var EVALUATION_DEFINITION_NOT_FOUND = {
13
+ treatment: CONTROL,
14
+ label: DEFINITION_NOT_FOUND,
15
+ config: null
16
+ };
17
+ function treatmentsException(definitionNames) {
13
18
  var evaluations = {};
14
- splitNames.forEach(function (splitName) {
15
- evaluations[splitName] = treatmentException;
19
+ definitionNames.forEach(function (definitionName) {
20
+ evaluations[definitionName] = EVALUATION_EXCEPTION;
16
21
  });
17
22
  return evaluations;
18
23
  }
19
- export function evaluateFeature(log, key, splitName, attributes, storage, options) {
20
- var parsedSplit;
24
+ export function evaluateFeature(log, key, definitionName, attributes, storage, options) {
25
+ var definition;
21
26
  try {
22
- parsedSplit = storage.splits.getSplit(splitName);
27
+ definition = storage.definitions.get(definitionName);
23
28
  }
24
29
  catch (e) {
25
- // Exception on sync `getSplit` storage. Not possible ATM with InMemory and InLocal storages.
26
- return treatmentException;
30
+ // Exception on sync storage. Not possible ATM with InMemory and InLocal storages.
31
+ return EVALUATION_EXCEPTION;
27
32
  }
28
- if (thenable(parsedSplit)) {
29
- return parsedSplit.then(function (split) { return getEvaluation(log, key, split, attributes, storage, options); }).catch(
30
- // Exception on async `getSplit` storage. For example, when the storage is redis or
33
+ if (thenable(definition)) {
34
+ return definition.then(function (definition) { return getEvaluation(log, key, definition, attributes, storage, options); }).catch(
35
+ // Exception on async storage. For example, when the storage is redis or
31
36
  // pluggable and there is a connection issue and we can't retrieve the split to be evaluated
32
- function () { return treatmentException; });
37
+ function () { return EVALUATION_EXCEPTION; });
33
38
  }
34
- return getEvaluation(log, key, parsedSplit, attributes, storage, options);
39
+ return getEvaluation(log, key, definition, attributes, storage, options);
35
40
  }
36
- export function evaluateFeatures(log, key, splitNames, attributes, storage, options) {
37
- var parsedSplits;
41
+ export function evaluateFeatures(log, key, definitionNames, attributes, storage, options) {
42
+ var definitions;
38
43
  try {
39
- parsedSplits = storage.splits.getSplits(splitNames);
44
+ definitions = storage.definitions.getMany(definitionNames);
40
45
  }
41
46
  catch (e) {
42
- // Exception on sync `getSplits` storage. Not possible ATM with InMemory and InLocal storages.
43
- return treatmentsException(splitNames);
47
+ // Exception on sync storage. Not possible ATM with InMemory and InLocal storages.
48
+ return treatmentsException(definitionNames);
44
49
  }
45
- return thenable(parsedSplits) ?
46
- parsedSplits.then(function (splits) { return getEvaluations(log, key, splitNames, splits, attributes, storage, options); })
50
+ return thenable(definitions) ?
51
+ definitions.then(function (definitions) { return getEvaluations(log, key, definitionNames, definitions, attributes, storage, options); })
47
52
  .catch(function () {
48
- // Exception on async `getSplits` storage. For example, when the storage is redis or
53
+ // Exception on async storage. For example, when the storage is redis or
49
54
  // pluggable and there is a connection issue and we can't retrieve the split to be evaluated
50
- return treatmentsException(splitNames);
55
+ return treatmentsException(definitionNames);
51
56
  }) :
52
- getEvaluations(log, key, splitNames, parsedSplits, attributes, storage, options);
57
+ getEvaluations(log, key, definitionNames, definitions, attributes, storage, options);
53
58
  }
54
59
  export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, storage, method, options) {
55
60
  var storedFlagNames;
@@ -70,7 +75,7 @@ export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, stora
70
75
  }
71
76
  // get features by flag sets
72
77
  try {
73
- storedFlagNames = storage.splits.getNamesByFlagSets(flagSets);
78
+ storedFlagNames = storage.definitions.getNamesBySets(flagSets);
74
79
  }
75
80
  catch (e) {
76
81
  // return empty evaluations
@@ -84,47 +89,66 @@ export function evaluateFeaturesByFlagSets(log, key, flagSets, attributes, stora
84
89
  }) :
85
90
  evaluate(storedFlagNames);
86
91
  }
87
- function getEvaluation(log, key, splitJSON, attributes, storage, options) {
88
- var evaluation = {
89
- treatment: CONTROL,
90
- label: SPLIT_NOT_FOUND,
91
- config: null
92
- };
93
- if (splitJSON) {
94
- var split = engineParser(log, splitJSON, storage);
95
- evaluation = split.getTreatment(key, attributes, evaluateFeature);
96
- // If the storage is async and the evaluated flag uses segments or dependencies, evaluation is thenable
92
+ function getEvaluation(log, key, definition, attributes, storage, options) {
93
+ if (definition) {
94
+ var split = engineParser(log, definition, storage);
95
+ var evaluation = split.getTreatment(key, attributes, evaluateFeature);
96
+ // If the storage is async and the evaluated definition uses segments or dependencies, evaluation is thenable
97
97
  if (thenable(evaluation)) {
98
98
  return evaluation.then(function (result) {
99
- result.changeNumber = splitJSON.changeNumber;
100
- result.config = splitJSON.configurations && splitJSON.configurations[result.treatment] || null;
99
+ result.changeNumber = definition.changeNumber;
100
+ result.config = definition.configurations && definition.configurations[result.treatment] || null;
101
101
  // @ts-expect-error impressionsDisabled is not exposed in the public typings yet.
102
- result.impressionsDisabled = (options === null || options === void 0 ? void 0 : options.impressionsDisabled) || splitJSON.impressionsDisabled;
102
+ result.impressionsDisabled = (options === null || options === void 0 ? void 0 : options.impressionsDisabled) || definition.impressionsDisabled;
103
103
  return result;
104
104
  });
105
105
  }
106
106
  else {
107
- evaluation.changeNumber = splitJSON.changeNumber;
108
- evaluation.config = splitJSON.configurations && splitJSON.configurations[evaluation.treatment] || null;
107
+ evaluation.changeNumber = definition.changeNumber;
108
+ evaluation.config = definition.configurations && definition.configurations[evaluation.treatment] || null;
109
109
  // @ts-expect-error impressionsDisabled is not exposed in the public typings yet.
110
- evaluation.impressionsDisabled = (options === null || options === void 0 ? void 0 : options.impressionsDisabled) || splitJSON.impressionsDisabled;
110
+ evaluation.impressionsDisabled = (options === null || options === void 0 ? void 0 : options.impressionsDisabled) || definition.impressionsDisabled;
111
111
  }
112
+ return evaluation;
112
113
  }
113
- return evaluation;
114
+ return EVALUATION_DEFINITION_NOT_FOUND;
114
115
  }
115
- function getEvaluations(log, key, splitNames, splits, attributes, storage, options) {
116
+ function getEvaluations(log, key, definitionNames, definitions, attributes, storage, options) {
116
117
  var result = {};
117
118
  var thenables = [];
118
- splitNames.forEach(function (splitName) {
119
- var evaluation = getEvaluation(log, key, splits[splitName], attributes, storage, options);
119
+ definitionNames.forEach(function (definitionName) {
120
+ var evaluation = getEvaluation(log, key, definitions[definitionName], attributes, storage, options);
120
121
  if (thenable(evaluation)) {
121
122
  thenables.push(evaluation.then(function (res) {
122
- result[splitName] = res;
123
+ result[definitionName] = res;
123
124
  }));
124
125
  }
125
126
  else {
126
- result[splitName] = evaluation;
127
+ result[definitionName] = evaluation;
127
128
  }
128
129
  });
129
130
  return thenables.length > 0 ? Promise.all(thenables).then(function () { return result; }) : result;
130
131
  }
132
+ export function evaluateDefaultTreatment(definitionName, storage) {
133
+ var definition;
134
+ try {
135
+ definition = storage.definitions.get(definitionName);
136
+ }
137
+ catch (e) {
138
+ return EVALUATION_EXCEPTION;
139
+ }
140
+ return thenable(definition) ?
141
+ definition.then(getDefaultTreatment).catch(function () { return EVALUATION_EXCEPTION; }) :
142
+ getDefaultTreatment(definition);
143
+ }
144
+ function getDefaultTreatment(definition) {
145
+ if (definition) {
146
+ return {
147
+ treatment: definition.defaultTreatment,
148
+ label: NO_CONDITION_MATCH,
149
+ config: definition.configurations && definition.configurations[definition.defaultTreatment] || null,
150
+ changeNumber: definition.changeNumber
151
+ };
152
+ }
153
+ return EVALUATION_DEFINITION_NOT_FOUND;
154
+ }
@@ -1,5 +1,5 @@
1
1
  export function whitelistMatcherContext(ruleAttr) {
2
- var whitelistSet = new Set(ruleAttr);
2
+ var whitelistSet = new Set(ruleAttr || []);
3
3
  return function whitelistMatcher(runtimeAttr) {
4
4
  var isInWhitelist = whitelistSet.has(runtimeAttr);
5
5
  return isInWhitelist;
@@ -13,7 +13,7 @@ export function pluggableIntegrationsManagerFactory(integrations, params) {
13
13
  // No need to check if `settings.integrations` is an array of functions. It was already validated
14
14
  integrations.forEach(function (integrationFactory) {
15
15
  var integration = integrationFactory(params);
16
- if (integration && integration.queue)
16
+ if (integration)
17
17
  listeners.push(integration);
18
18
  });
19
19
  // If `listeners` is empty, not return a integration manager
@@ -10,14 +10,15 @@ var EVENT_NAME = 'for visibilitychange and pagehide events.';
10
10
  * We'll listen for events over the window object.
11
11
  */
12
12
  var BrowserSignalListener = /** @class */ (function () {
13
- function BrowserSignalListener(syncManager, settings, storage, serviceApi) {
13
+ function BrowserSignalListener(_a) {
14
+ var syncManager = _a.syncManager, settings = _a.settings, storage = _a.storage, splitApi = _a.splitApi, entityType = _a.entityType;
14
15
  this.syncManager = syncManager;
15
16
  this.settings = settings;
16
17
  this.storage = storage;
17
- this.serviceApi = serviceApi;
18
+ this.serviceApi = splitApi;
18
19
  this.flushData = this.flushData.bind(this);
19
20
  this.flushDataIfHidden = this.flushDataIfHidden.bind(this);
20
- this.fromImpressionsCollector = fromImpressionsCollector.bind(undefined, settings.core.labelsEnabled);
21
+ this.fromImpressionsCollector = fromImpressionsCollector.bind(undefined, settings.core.labelsEnabled, entityType);
21
22
  }
22
23
  /**
23
24
  * start method.
@@ -10,8 +10,8 @@ var EVENT_NAME = 'for SIGTERM signal.';
10
10
  * the process is already exiting.
11
11
  */
12
12
  var NodeSignalListener = /** @class */ (function () {
13
- function NodeSignalListener(syncManager, // private handler: () => MaybeThenable<void>,
14
- settings) {
13
+ function NodeSignalListener(_a) {
14
+ var syncManager = _a.syncManager, settings = _a.settings;
15
15
  // @TODO review handler logic when implementing Node.js SDK
16
16
  this.handler = function () {
17
17
  if (syncManager) {
@@ -44,13 +44,13 @@ var NodeSignalListener = /** @class */ (function () {
44
44
  // eslint-disable-next-line no-undef
45
45
  process.kill(process.pid, SIGTERM);
46
46
  };
47
- this.settings.log.debug(LOG_PREFIX_CLEANUP + "Split SDK graceful shutdown after SIGTERM.");
47
+ this.settings.log.debug("".concat(LOG_PREFIX_CLEANUP, "Split SDK graceful shutdown after SIGTERM."));
48
48
  var handlerResult = null;
49
49
  try {
50
50
  handlerResult = this.handler();
51
51
  }
52
52
  catch (err) {
53
- this.settings.log.error(LOG_PREFIX_CLEANUP + "Error with Split SDK graceful shutdown: " + err);
53
+ this.settings.log.error("".concat(LOG_PREFIX_CLEANUP, "Error with Split SDK graceful shutdown: ").concat(err));
54
54
  }
55
55
  if (thenable(handlerResult)) {
56
56
  // Always exit, even with errors. The promise is returned for UT purposes.