@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
@@ -1,19 +1,19 @@
1
1
  import { objectAssign } from '../utils/lang/objectAssign';
2
- import { SDK_SPLITS_ARRIVED, SDK_SPLITS_CACHE_LOADED, SDK_SEGMENTS_ARRIVED, SDK_READY_TIMED_OUT, SDK_READY_FROM_CACHE, SDK_UPDATE, SDK_READY } from './constants';
3
- function splitsEventEmitterFactory(EventEmitter) {
4
- var splitsEventEmitter = objectAssign(new EventEmitter(), {
5
- splitsArrived: false,
6
- splitsCacheLoaded: false,
2
+ import { SDK_DEFINITIONS_ARRIVED, SDK_DEFINITIONS_CACHE_LOADED, SDK_SEGMENTS_ARRIVED, SDK_READY_TIMED_OUT, SDK_READY_FROM_CACHE, SDK_UPDATE, SDK_READY } from './constants';
3
+ function definitionsEventEmitterFactory(EventEmitter) {
4
+ var definitionsEventEmitter = objectAssign(new EventEmitter(), {
5
+ definitionsArrived: false,
6
+ definitionsCacheLoaded: false,
7
7
  hasInit: false,
8
8
  initCallbacks: []
9
9
  });
10
10
  // `isSplitKill` condition avoids an edge-case of wrongly emitting SDK_READY if:
11
11
  // - `/memberships` fetch and SPLIT_KILL occurs before `/splitChanges` fetch, and
12
12
  // - storage has cached splits (for which case `splitsStorage.killLocally` can return true)
13
- splitsEventEmitter.on(SDK_SPLITS_ARRIVED, function (metadata, isSplitKill) { if (!isSplitKill)
14
- splitsEventEmitter.splitsArrived = true; });
15
- splitsEventEmitter.once(SDK_SPLITS_CACHE_LOADED, function () { splitsEventEmitter.splitsCacheLoaded = true; });
16
- return splitsEventEmitter;
13
+ definitionsEventEmitter.on(SDK_DEFINITIONS_ARRIVED, function (metadata, isSplitKill) { if (!isSplitKill)
14
+ definitionsEventEmitter.definitionsArrived = true; });
15
+ definitionsEventEmitter.once(SDK_DEFINITIONS_CACHE_LOADED, function () { definitionsEventEmitter.definitionsCacheLoaded = true; });
16
+ return definitionsEventEmitter;
17
17
  }
18
18
  function segmentsEventEmitterFactory(EventEmitter) {
19
19
  var segmentsEventEmitter = objectAssign(new EventEmitter(), {
@@ -25,8 +25,8 @@ function segmentsEventEmitterFactory(EventEmitter) {
25
25
  /**
26
26
  * Factory of readiness manager, which handles the ready / update event propagation.
27
27
  */
28
- export function readinessManagerFactory(EventEmitter, settings, splits, isShared) {
29
- if (splits === void 0) { splits = splitsEventEmitterFactory(EventEmitter); }
28
+ export function readinessManagerFactory(EventEmitter, settings, definitions, isShared) {
29
+ if (definitions === void 0) { definitions = definitionsEventEmitterFactory(EventEmitter); }
30
30
  var readyTimeout = settings.startup.readyTimeout;
31
31
  var segments = segmentsEventEmitterFactory(EventEmitter);
32
32
  var gate = new EventEmitter();
@@ -41,10 +41,10 @@ export function readinessManagerFactory(EventEmitter, settings, splits, isShared
41
41
  };
42
42
  // emit SDK_READY_FROM_CACHE
43
43
  var isReadyFromCache = false;
44
- if (splits.splitsCacheLoaded)
44
+ if (definitions.definitionsCacheLoaded)
45
45
  isReadyFromCache = true; // ready from cache, but doesn't emit SDK_READY_FROM_CACHE
46
46
  else
47
- splits.once(SDK_SPLITS_CACHE_LOADED, checkIsReadyFromCache);
47
+ definitions.once(SDK_DEFINITIONS_CACHE_LOADED, checkIsReadyFromCache);
48
48
  // emit SDK_READY_TIMED_OUT
49
49
  var hasTimedout = false;
50
50
  function timeout() {
@@ -56,7 +56,7 @@ export function readinessManagerFactory(EventEmitter, settings, splits, isShared
56
56
  }
57
57
  // emit SDK_READY and SDK_UPDATE
58
58
  var isReady = false;
59
- splits.on(SDK_SPLITS_ARRIVED, checkIsReadyOrUpdate);
59
+ definitions.on(SDK_DEFINITIONS_ARRIVED, checkIsReadyOrUpdate);
60
60
  segments.on(SDK_SEGMENTS_ARRIVED, checkIsReadyOrUpdate);
61
61
  var isDestroyed = false;
62
62
  var readyTimeoutId;
@@ -65,8 +65,8 @@ export function readinessManagerFactory(EventEmitter, settings, splits, isShared
65
65
  if (readyTimeout > 0 && !isReady)
66
66
  readyTimeoutId = setTimeout(timeout, readyTimeout);
67
67
  }
68
- splits.initCallbacks.push(__init);
69
- if (splits.hasInit)
68
+ definitions.initCallbacks.push(__init);
69
+ if (definitions.hasInit)
70
70
  __init();
71
71
  function checkIsReadyFromCache(cacheMetadata) {
72
72
  metadataReady = cacheMetadata;
@@ -97,7 +97,7 @@ export function readinessManagerFactory(EventEmitter, settings, splits, isShared
97
97
  }
98
98
  }
99
99
  else {
100
- if (splits.splitsArrived && segments.segmentsArrived) {
100
+ if (definitions.definitionsArrived && segments.segmentsArrived) {
101
101
  clearTimeout(readyTimeoutId);
102
102
  isReady = true;
103
103
  try {
@@ -120,11 +120,11 @@ export function readinessManagerFactory(EventEmitter, settings, splits, isShared
120
120
  }
121
121
  }
122
122
  return {
123
- splits: splits,
123
+ definitions: definitions,
124
124
  segments: segments,
125
125
  gate: gate,
126
126
  shared: function () {
127
- return readinessManagerFactory(EventEmitter, settings, splits, true);
127
+ return readinessManagerFactory(EventEmitter, settings, definitions, true);
128
128
  },
129
129
  // @TODO review/remove next methods when non-recoverable errors are reworked
130
130
  // Called on consumer mode, when storage fails to connect
@@ -133,17 +133,17 @@ export function readinessManagerFactory(EventEmitter, settings, splits, isShared
133
133
  // tracking and evaluations, while keeping event listeners to emit SDK_READY_TIMED_OUT event
134
134
  setDestroyed: function () { isDestroyed = true; },
135
135
  init: function () {
136
- if (splits.hasInit)
136
+ if (definitions.hasInit)
137
137
  return;
138
- splits.hasInit = true;
139
- splits.initCallbacks.forEach(function (cb) { return cb(); });
138
+ definitions.hasInit = true;
139
+ definitions.initCallbacks.forEach(function (cb) { return cb(); });
140
140
  },
141
141
  destroy: function () {
142
142
  isDestroyed = true;
143
143
  syncLastUpdate();
144
144
  clearTimeout(readyTimeoutId);
145
145
  if (!isShared)
146
- splits.hasInit = false;
146
+ definitions.hasInit = false;
147
147
  },
148
148
  isReady: function () { return isReady; },
149
149
  isReadyFromCache: function () { return isReadyFromCache; },
@@ -2,9 +2,8 @@ import { objectAssign } from '../utils/lang/objectAssign';
2
2
  import { promiseWrapper } from '../utils/promise/wrapper';
3
3
  import { readinessManagerFactory } from './readinessManager';
4
4
  import { SDK_READY, SDK_READY_TIMED_OUT, SDK_READY_FROM_CACHE, SDK_UPDATE } from './constants';
5
- import { ERROR_CLIENT_LISTENER, CLIENT_READY_FROM_CACHE, CLIENT_READY, CLIENT_NO_LISTENER } from '../logger/constants';
5
+ import { ERROR_CLIENT_LISTENER, CLIENT_READY_FROM_CACHE, CLIENT_READY } from '../logger/constants';
6
6
  var NEW_LISTENER_EVENT = 'newListener';
7
- var REMOVE_LISTENER_EVENT = 'removeListener';
8
7
  var TIMEOUT_ERROR = new Error(SDK_READY_TIMED_OUT);
9
8
  /**
10
9
  * SdkReadinessManager factory, which provides the public status API of SDK clients and manager: ready promise, readiness event emitter and constants (SDK_READY, etc).
@@ -16,21 +15,11 @@ var TIMEOUT_ERROR = new Error(SDK_READY_TIMED_OUT);
16
15
  export function sdkReadinessManagerFactory(EventEmitter, settings, readinessManager) {
17
16
  if (readinessManager === void 0) { readinessManager = readinessManagerFactory(EventEmitter, settings); }
18
17
  var log = settings.log;
19
- /** Ready callback warning */
20
- var internalReadyCbCount = 0;
21
- var readyCbCount = 0;
22
- readinessManager.gate.on(REMOVE_LISTENER_EVENT, function (event) {
23
- if (event === SDK_READY)
24
- readyCbCount--;
25
- });
26
18
  readinessManager.gate.on(NEW_LISTENER_EVENT, function (event) {
27
19
  if (event === SDK_READY || event === SDK_READY_TIMED_OUT) {
28
20
  if (readinessManager.isReady()) {
29
21
  log.error(ERROR_CLIENT_LISTENER, [event === SDK_READY ? 'SDK_READY' : 'SDK_READY_TIMED_OUT']);
30
22
  }
31
- else if (event === SDK_READY) {
32
- readyCbCount++;
33
- }
34
23
  }
35
24
  else if (event === SDK_READY_FROM_CACHE && readinessManager.isReadyFromCache()) {
36
25
  log.error(ERROR_CLIENT_LISTENER, ['SDK_READY_FROM_CACHE']);
@@ -49,8 +38,6 @@ export function sdkReadinessManagerFactory(EventEmitter, settings, readinessMana
49
38
  var promise = promiseWrapper(new Promise(function (resolve, reject) {
50
39
  readinessManager.gate.once(SDK_READY, function () {
51
40
  log.info(CLIENT_READY);
52
- if (readyCbCount === internalReadyCbCount && !promise.hasOnFulfilled())
53
- log.warn(CLIENT_NO_LISTENER);
54
41
  resolve();
55
42
  });
56
43
  readinessManager.gate.once(SDK_READY_TIMED_OUT, function (message) {
@@ -75,9 +62,6 @@ export function sdkReadinessManagerFactory(EventEmitter, settings, readinessMana
75
62
  shared: function () {
76
63
  return sdkReadinessManagerFactory(EventEmitter, settings, readinessManager.shared());
77
64
  },
78
- incInternalReadyCbCount: function () {
79
- internalReadyCbCount++;
80
- },
81
65
  sdkStatus: objectAssign(
82
66
  // Expose Event Emitter functionality
83
67
  Object.create(readinessManager.gate), {
@@ -1,12 +1,12 @@
1
1
  import { evaluateFeature, evaluateFeatures, evaluateFeaturesByFlagSets } from '../evaluator';
2
2
  import { thenable } from '../utils/promise/thenable';
3
3
  import { getMatching, getBucketing } from '../utils/key';
4
- import { validateSplitExistence } from '../utils/inputValidation/splitExistence';
5
- import { validateTrafficTypeExistence } from '../utils/inputValidation/trafficTypeExistence';
4
+ import { validateDefinitionExistence } from '../utils/inputValidation/definitionExistence';
6
5
  import { SDK_NOT_READY } from '../utils/labels';
7
- import { CONTROL, TREATMENT, TREATMENTS, TREATMENT_WITH_CONFIG, TREATMENTS_WITH_CONFIG, TRACK, TREATMENTS_WITH_CONFIG_BY_FLAGSETS, TREATMENTS_BY_FLAGSETS, TREATMENTS_BY_FLAGSET, TREATMENTS_WITH_CONFIG_BY_FLAGSET, GET_TREATMENTS_WITH_CONFIG, GET_TREATMENTS_BY_FLAG_SETS, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, GET_TREATMENTS_BY_FLAG_SET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, GET_TREATMENT_WITH_CONFIG, GET_TREATMENT, GET_TREATMENTS, TRACK_FN_LABEL } from '../utils/constants';
8
- import { IMPRESSION, IMPRESSION_QUEUEING } from '../logger/constants';
6
+ import { CONTROL, TREATMENT, TREATMENTS, TREATMENT_WITH_CONFIG, TREATMENTS_WITH_CONFIG, TREATMENTS_WITH_CONFIG_BY_FLAGSETS, TREATMENTS_BY_FLAGSETS, TREATMENTS_BY_FLAGSET, TREATMENTS_WITH_CONFIG_BY_FLAGSET, GET_TREATMENTS_WITH_CONFIG, GET_TREATMENTS_BY_FLAG_SETS, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, GET_TREATMENTS_BY_FLAG_SET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, GET_TREATMENT_WITH_CONFIG, GET_TREATMENT, GET_TREATMENTS } from '../utils/constants';
7
+ import { IMPRESSION_QUEUEING } from '../logger/constants';
9
8
  import { isConsumerMode } from '../utils/settingsValidation/mode';
9
+ import { trackMethodFactory } from './trackMethod';
10
10
  var treatmentNotReady = { treatment: CONTROL, label: SDK_NOT_READY };
11
11
  function treatmentsNotReady(featureFlagNames) {
12
12
  var evaluations = {};
@@ -15,7 +15,7 @@ function treatmentsNotReady(featureFlagNames) {
15
15
  });
16
16
  return evaluations;
17
17
  }
18
- function stringify(options) {
18
+ export function stringify(options) {
19
19
  if (options && options.properties) {
20
20
  try {
21
21
  return JSON.stringify(options.properties);
@@ -27,7 +27,7 @@ function stringify(options) {
27
27
  * Creator of base client with getTreatments and track methods.
28
28
  */
29
29
  export function clientFactory(params) {
30
- var readinessManager = params.sdkReadinessManager.readinessManager, storage = params.storage, settings = params.settings, impressionsTracker = params.impressionsTracker, eventTracker = params.eventTracker, telemetryTracker = params.telemetryTracker, fallbackTreatmentsCalculator = params.fallbackTreatmentsCalculator;
30
+ var readinessManager = params.sdkReadinessManager.readinessManager, storage = params.storage, settings = params.settings, impressionsTracker = params.impressionsTracker, telemetryTracker = params.telemetryTracker, fallbackCalculator = params.fallbackCalculator;
31
31
  var log = settings.log, mode = settings.mode;
32
32
  var isAsync = isConsumerMode(mode);
33
33
  function getTreatment(key, featureFlagName, attributes, options, withConfig, methodName) {
@@ -115,14 +115,13 @@ export function clientFactory(params) {
115
115
  var changeNumber = evaluation.changeNumber, impressionsDisabled = evaluation.impressionsDisabled;
116
116
  var treatment = evaluation.treatment, label = evaluation.label, _a = evaluation.config, config = _a === void 0 ? null : _a;
117
117
  if (treatment === CONTROL) {
118
- var fallbackTreatment = fallbackTreatmentsCalculator.resolve(featureFlagName, label);
118
+ var fallbackTreatment = fallbackCalculator(featureFlagName, label);
119
119
  treatment = fallbackTreatment.treatment;
120
120
  label = fallbackTreatment.label;
121
121
  config = fallbackTreatment.config;
122
122
  }
123
- log.info(IMPRESSION, [featureFlagName, matchingKey, treatment, label]);
124
- if (validateSplitExistence(log, readinessManager, featureFlagName, label, invokingMethodName)) {
125
- log.info(IMPRESSION_QUEUEING);
123
+ if (validateDefinitionExistence(log, readinessManager, featureFlagName, label, invokingMethodName)) {
124
+ log.info(IMPRESSION_QUEUEING, ['Feature flag', featureFlagName, matchingKey, treatment, label]);
126
125
  queue.push({
127
126
  imp: {
128
127
  feature: featureFlagName,
@@ -145,33 +144,7 @@ export function clientFactory(params) {
145
144
  }
146
145
  return treatment;
147
146
  }
148
- function track(key, trafficTypeName, eventTypeId, value, properties, size) {
149
- if (size === void 0) { size = 1024; }
150
- var stopTelemetryTracker = telemetryTracker.trackEval(TRACK);
151
- var matchingKey = getMatching(key);
152
- var timestamp = Date.now();
153
- var eventData = {
154
- eventTypeId: eventTypeId,
155
- trafficTypeName: trafficTypeName,
156
- value: value,
157
- timestamp: timestamp,
158
- key: matchingKey,
159
- properties: properties
160
- };
161
- // This may be async but we only warn, we don't actually care if it is valid or not in terms of queueing the event.
162
- validateTrafficTypeExistence(log, readinessManager, storage.splits, mode, trafficTypeName, TRACK_FN_LABEL);
163
- var result = eventTracker.track(eventData, size);
164
- if (thenable(result)) {
165
- return result.then(function (result) {
166
- stopTelemetryTracker();
167
- return result;
168
- });
169
- }
170
- else {
171
- stopTelemetryTracker();
172
- return result;
173
- }
174
- }
147
+ var track = trackMethodFactory(params);
175
148
  return {
176
149
  getTreatment: getTreatment,
177
150
  getTreatmentWithConfig: getTreatmentWithConfig,
@@ -66,7 +66,7 @@ export function clientAttributesDecoration(log, client) {
66
66
  attribute[attributeName] = attributeValue;
67
67
  if (!validateAttributesDeep(log, attribute, 'setAttribute'))
68
68
  return false;
69
- log.debug("stored " + attributeValue + " for attribute " + attributeName);
69
+ log.debug("stored ".concat(attributeValue, " for attribute ").concat(attributeName));
70
70
  return attributeStorage.setAttribute(attributeName, attributeValue);
71
71
  },
72
72
  /**
@@ -76,7 +76,7 @@ export function clientAttributesDecoration(log, client) {
76
76
  * @returns Attribute with the given name
77
77
  */
78
78
  getAttribute: function (attributeName) {
79
- log.debug("retrieved attribute " + attributeName);
79
+ log.debug("retrieved attribute ".concat(attributeName));
80
80
  return attributeStorage.getAttribute(attributeName + '');
81
81
  },
82
82
  /**
@@ -105,7 +105,7 @@ export function clientAttributesDecoration(log, client) {
105
105
  * @returns true if attribute was removed and false otherways
106
106
  */
107
107
  removeAttribute: function (attributeName) {
108
- log.debug("removed attribute " + attributeName);
108
+ log.debug("removed attribute ".concat(attributeName));
109
109
  return attributeStorage.removeAttribute(attributeName + '');
110
110
  },
111
111
  /**
@@ -1,13 +1,13 @@
1
- import { validateAttributes, validateEvent, validateEventValue, validateEventProperties, validateKey, validateSplit, validateSplits, validateTrafficType, validateIfNotDestroyed, validateIfReadyFromCache, validateEvaluationOptions } from '../utils/inputValidation';
1
+ import { validateAttributes, validateKey, validateDefinition, validateDefinitions, validateIfNotDestroyed, validateIfReadyFromCache, validateEvaluationOptions } from '../utils/inputValidation';
2
2
  import { startsWith } from '../utils/lang';
3
- import { GET_TREATMENT, GET_TREATMENTS, GET_TREATMENTS_BY_FLAG_SET, GET_TREATMENTS_BY_FLAG_SETS, GET_TREATMENTS_WITH_CONFIG, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, GET_TREATMENT_WITH_CONFIG, TRACK_FN_LABEL } from '../utils/constants';
3
+ import { GET_TREATMENT, GET_TREATMENTS, GET_TREATMENTS_BY_FLAG_SET, GET_TREATMENTS_BY_FLAG_SETS, GET_TREATMENTS_WITH_CONFIG, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, GET_TREATMENT_WITH_CONFIG } from '../utils/constants';
4
4
  import { isConsumerMode } from '../utils/settingsValidation/mode';
5
5
  import { validateFlagSets } from '../utils/settingsValidation/splitFilters';
6
6
  /**
7
7
  * Decorator that validates the input before actually executing the client methods.
8
8
  * We should "guard" the client here, while not polluting the "real" implementation of those methods.
9
9
  */
10
- export function clientInputValidationDecorator(settings, client, readinessManager, fallbackTreatmentsCalculator) {
10
+ export function clientInputValidationDecorator(settings, client, readinessManager, fallbackCalculator) {
11
11
  var log = settings.log, mode = settings.mode;
12
12
  var isAsync = isConsumerMode(mode);
13
13
  /**
@@ -18,12 +18,12 @@ export function clientInputValidationDecorator(settings, client, readinessManage
18
18
  var nameOrNames = methodName.indexOf('ByFlagSet') > -1 ?
19
19
  validateFlagSets(log, methodName, maybeNameOrNames, settings.sync.__splitFiltersValidation.groupedFilters.bySet) :
20
20
  startsWith(methodName, GET_TREATMENTS) ?
21
- validateSplits(log, maybeNameOrNames, methodName) :
22
- validateSplit(log, maybeNameOrNames, methodName);
21
+ validateDefinitions(log, maybeNameOrNames, methodName) :
22
+ validateDefinition(log, maybeNameOrNames, methodName);
23
23
  var attributes = validateAttributes(log, maybeAttributes, methodName);
24
24
  var isNotDestroyed = validateIfNotDestroyed(log, readinessManager, methodName);
25
25
  var options = validateEvaluationOptions(log, maybeOptions, methodName);
26
- validateIfReadyFromCache(log, readinessManager, methodName, nameOrNames);
26
+ validateIfReadyFromCache(log, readinessManager, methodName);
27
27
  var valid = isNotDestroyed && key && nameOrNames && attributes !== false;
28
28
  return {
29
29
  valid: valid,
@@ -34,111 +34,68 @@ export function clientInputValidationDecorator(settings, client, readinessManage
34
34
  };
35
35
  }
36
36
  function evaluateFallBackTreatment(featureFlagName, withConfig) {
37
- var _a = fallbackTreatmentsCalculator.resolve(featureFlagName, ''), treatment = _a.treatment, config = _a.config;
38
- if (withConfig) {
39
- return {
37
+ if (Array.isArray(featureFlagName)) {
38
+ var res_1 = {};
39
+ featureFlagName.forEach(function (split) { return res_1[split] = evaluateFallBackTreatment(split, withConfig); });
40
+ return res_1;
41
+ }
42
+ var _a = fallbackCalculator(featureFlagName), treatment = _a.treatment, config = _a.config;
43
+ return withConfig ?
44
+ {
40
45
  treatment: treatment,
41
46
  config: config
42
- };
43
- }
44
- return treatment;
47
+ } : treatment;
45
48
  }
46
49
  function wrapResult(value) {
47
50
  return isAsync ? Promise.resolve(value) : value;
48
51
  }
49
52
  function getTreatment(maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions) {
50
53
  var params = validateEvaluationParams(GET_TREATMENT, maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions);
51
- if (params.valid) {
52
- return client.getTreatment(params.key, params.nameOrNames, params.attributes, params.options);
53
- }
54
- else {
55
- var result = evaluateFallBackTreatment(params.nameOrNames, false);
56
- return wrapResult(result);
57
- }
54
+ return params.valid ?
55
+ client.getTreatment(params.key, params.nameOrNames, params.attributes, params.options) :
56
+ wrapResult(evaluateFallBackTreatment(params.nameOrNames, false));
58
57
  }
59
58
  function getTreatmentWithConfig(maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions) {
60
59
  var params = validateEvaluationParams(GET_TREATMENT_WITH_CONFIG, maybeKey, maybeFeatureFlagName, maybeAttributes, maybeOptions);
61
- if (params.valid) {
62
- return client.getTreatmentWithConfig(params.key, params.nameOrNames, params.attributes, params.options);
63
- }
64
- else {
65
- var result = evaluateFallBackTreatment(params.nameOrNames, true);
66
- return wrapResult(result);
67
- }
60
+ return params.valid ?
61
+ client.getTreatmentWithConfig(params.key, params.nameOrNames, params.attributes, params.options) :
62
+ wrapResult(evaluateFallBackTreatment(params.nameOrNames, true));
68
63
  }
69
64
  function getTreatments(maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions) {
70
65
  var params = validateEvaluationParams(GET_TREATMENTS, maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions);
71
- if (params.valid) {
72
- return client.getTreatments(params.key, params.nameOrNames, params.attributes, params.options);
73
- }
74
- else {
75
- var res_1 = {};
76
- if (params.nameOrNames)
77
- params.nameOrNames.forEach(function (split) { return res_1[split] = evaluateFallBackTreatment(split, false); });
78
- return wrapResult(res_1);
79
- }
66
+ return params.valid ?
67
+ client.getTreatments(params.key, params.nameOrNames, params.attributes, params.options) :
68
+ wrapResult(evaluateFallBackTreatment(params.nameOrNames || [], false));
80
69
  }
81
70
  function getTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions) {
82
71
  var params = validateEvaluationParams(GET_TREATMENTS_WITH_CONFIG, maybeKey, maybeFeatureFlagNames, maybeAttributes, maybeOptions);
83
- if (params.valid) {
84
- return client.getTreatmentsWithConfig(params.key, params.nameOrNames, params.attributes, params.options);
85
- }
86
- else {
87
- var res_2 = {};
88
- if (params.nameOrNames)
89
- params.nameOrNames.forEach(function (split) { return res_2[split] = evaluateFallBackTreatment(split, true); });
90
- return wrapResult(res_2);
91
- }
72
+ return params.valid ?
73
+ client.getTreatmentsWithConfig(params.key, params.nameOrNames, params.attributes, params.options) :
74
+ wrapResult(evaluateFallBackTreatment(params.nameOrNames || [], true));
92
75
  }
93
76
  function getTreatmentsByFlagSets(maybeKey, maybeFlagSets, maybeAttributes, maybeOptions) {
94
77
  var params = validateEvaluationParams(GET_TREATMENTS_BY_FLAG_SETS, maybeKey, maybeFlagSets, maybeAttributes, maybeOptions);
95
- if (params.valid) {
96
- return client.getTreatmentsByFlagSets(params.key, params.nameOrNames, params.attributes, params.options);
97
- }
98
- else {
99
- return wrapResult({});
100
- }
78
+ return params.valid ?
79
+ client.getTreatmentsByFlagSets(params.key, params.nameOrNames, params.attributes, params.options) :
80
+ wrapResult({});
101
81
  }
102
82
  function getTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, maybeAttributes, maybeOptions) {
103
83
  var params = validateEvaluationParams(GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, maybeKey, maybeFlagSets, maybeAttributes, maybeOptions);
104
- if (params.valid) {
105
- return client.getTreatmentsWithConfigByFlagSets(params.key, params.nameOrNames, params.attributes, params.options);
106
- }
107
- else {
108
- return wrapResult({});
109
- }
84
+ return params.valid ?
85
+ client.getTreatmentsWithConfigByFlagSets(params.key, params.nameOrNames, params.attributes, params.options) :
86
+ wrapResult({});
110
87
  }
111
88
  function getTreatmentsByFlagSet(maybeKey, maybeFlagSet, maybeAttributes, maybeOptions) {
112
89
  var params = validateEvaluationParams(GET_TREATMENTS_BY_FLAG_SET, maybeKey, [maybeFlagSet], maybeAttributes, maybeOptions);
113
- if (params.valid) {
114
- return client.getTreatmentsByFlagSet(params.key, params.nameOrNames[0], params.attributes, params.options);
115
- }
116
- else {
117
- return wrapResult({});
118
- }
90
+ return params.valid ?
91
+ client.getTreatmentsByFlagSet(params.key, params.nameOrNames[0], params.attributes, params.options) :
92
+ wrapResult({});
119
93
  }
120
94
  function getTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, maybeAttributes, maybeOptions) {
121
95
  var params = validateEvaluationParams(GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, maybeKey, [maybeFlagSet], maybeAttributes, maybeOptions);
122
- if (params.valid) {
123
- return client.getTreatmentsWithConfigByFlagSet(params.key, params.nameOrNames[0], params.attributes, params.options);
124
- }
125
- else {
126
- return wrapResult({});
127
- }
128
- }
129
- function track(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties) {
130
- var key = validateKey(log, maybeKey, TRACK_FN_LABEL);
131
- var tt = validateTrafficType(log, maybeTT, TRACK_FN_LABEL);
132
- var event = validateEvent(log, maybeEvent, TRACK_FN_LABEL);
133
- var eventValue = validateEventValue(log, maybeEventValue, TRACK_FN_LABEL);
134
- var _a = validateEventProperties(log, maybeProperties, TRACK_FN_LABEL), properties = _a.properties, size = _a.size;
135
- var isNotDestroyed = validateIfNotDestroyed(log, readinessManager, TRACK_FN_LABEL);
136
- if (isNotDestroyed && key && tt && event && eventValue !== false && properties !== false) { // @ts-expect-error
137
- return client.track(key, tt, event, eventValue, properties, size);
138
- }
139
- else {
140
- return isAsync ? Promise.resolve(false) : false;
141
- }
96
+ return params.valid ?
97
+ client.getTreatmentsWithConfigByFlagSet(params.key, params.nameOrNames[0], params.attributes, params.options) :
98
+ wrapResult({});
142
99
  }
143
100
  return {
144
101
  getTreatment: getTreatment,
@@ -149,6 +106,6 @@ export function clientInputValidationDecorator(settings, client, readinessManage
149
106
  getTreatmentsWithConfigByFlagSets: getTreatmentsWithConfigByFlagSets,
150
107
  getTreatmentsByFlagSet: getTreatmentsByFlagSet,
151
108
  getTreatmentsWithConfigByFlagSet: getTreatmentsWithConfigByFlagSet,
152
- track: track
109
+ track: client.track,
153
110
  };
154
111
  }
@@ -1,3 +1,3 @@
1
1
  export function buildInstanceId(key, trafficType) {
2
- return (key.matchingKey ? key.matchingKey : key) + "-" + (key.bucketingKey ? key.bucketingKey : key) + "-" + (trafficType ? trafficType : '');
2
+ return "".concat(key.matchingKey ? key.matchingKey : key, "-").concat(key.bucketingKey ? key.bucketingKey : key, "-").concat(trafficType ? trafficType : '');
3
3
  }
@@ -1,60 +1,15 @@
1
1
  import { objectAssign } from '../utils/lang/objectAssign';
2
- import { releaseApiKey } from '../utils/inputValidation/apiKey';
3
2
  import { clientFactory } from './client';
4
3
  import { clientInputValidationDecorator } from './clientInputValidation';
5
- var COOLDOWN_TIME_IN_MILLIS = 1000;
4
+ import { sdkLifecycleFactory } from './sdkLifecycle';
6
5
  /**
7
- * Creates an Sdk client, i.e., a base client with status and destroy interface
6
+ * Creates an Sdk client, i.e., a base client with status, init, flush and destroy interface
8
7
  */
9
8
  export function sdkClientFactory(params, isSharedClient) {
10
- var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, signalListener = params.signalListener, settings = params.settings, telemetryTracker = params.telemetryTracker, uniqueKeysTracker = params.uniqueKeysTracker;
11
- var lastActionTime = 0;
12
- function __cooldown(func, time) {
13
- var now = Date.now();
14
- //get the actual time elapsed in ms
15
- var timeElapsed = now - lastActionTime;
16
- //check if the time elapsed is less than desired cooldown
17
- if (timeElapsed < time) {
18
- //if yes, return message with remaining time in seconds
19
- settings.log.warn("Flush cooldown, remaining time " + (time - timeElapsed) / 1000 + " seconds");
20
- return Promise.resolve();
21
- }
22
- else {
23
- //Do the requested action and re-assign the lastActionTime
24
- lastActionTime = now;
25
- return func();
26
- }
27
- }
28
- function __flush() {
29
- return syncManager ? syncManager.flush() : Promise.resolve();
30
- }
9
+ var sdkReadinessManager = params.sdkReadinessManager, settings = params.settings;
31
10
  return objectAssign(
32
11
  // Proto-linkage of the readiness Event Emitter
33
12
  Object.create(sdkReadinessManager.sdkStatus),
34
13
  // Client API (getTreatment* & track methods)
35
- clientInputValidationDecorator(settings, clientFactory(params), sdkReadinessManager.readinessManager, params.fallbackTreatmentsCalculator),
36
- // Sdk destroy
37
- {
38
- flush: function () {
39
- // @TODO define cooldown time
40
- return __cooldown(__flush, COOLDOWN_TIME_IN_MILLIS);
41
- },
42
- destroy: function () {
43
- // Mark the SDK as destroyed immediately
44
- sdkReadinessManager.readinessManager.destroy();
45
- // For main client, cleanup the SDK Key, listeners and scheduled jobs, and record stat before flushing data
46
- if (!isSharedClient) {
47
- releaseApiKey(settings.core.authorizationKey);
48
- telemetryTracker.sessionLength();
49
- signalListener && signalListener.stop();
50
- uniqueKeysTracker.stop();
51
- }
52
- // Stop background jobs
53
- syncManager && syncManager.stop();
54
- return __flush().then(function () {
55
- // Cleanup storage
56
- return storage.destroy();
57
- });
58
- }
59
- });
14
+ clientInputValidationDecorator(settings, clientFactory(params), sdkReadinessManager.readinessManager, params.fallbackCalculator), sdkLifecycleFactory(params, isSharedClient));
60
15
  }
@@ -0,0 +1,67 @@
1
+ import { releaseApiKey, validateAndTrackApiKey } from '../utils/inputValidation/apiKey';
2
+ var COOLDOWN_TIME_IN_MILLIS = 1000;
3
+ /**
4
+ * Creates an Sdk client, i.e., a base client with status, init, flush and destroy interface
5
+ */
6
+ export function sdkLifecycleFactory(params, isSharedClient) {
7
+ var sdkReadinessManager = params.sdkReadinessManager, syncManager = params.syncManager, storage = params.storage, settings = params.settings, telemetryTracker = params.telemetryTracker, impressionsTracker = params.impressionsTracker, platform = params.platform, splitApi = params.splitApi;
8
+ var hasInit = false;
9
+ var lastActionTime = 0;
10
+ var signalListener = platform.SignalListener && new platform.SignalListener(params);
11
+ function __cooldown(func, time) {
12
+ var now = Date.now();
13
+ //get the actual time elapsed in ms
14
+ var timeElapsed = now - lastActionTime;
15
+ //check if the time elapsed is less than desired cooldown
16
+ if (timeElapsed < time) {
17
+ //if yes, return message with remaining time in seconds
18
+ settings.log.warn("Flush cooldown, remaining time ".concat((time - timeElapsed) / 1000, " seconds"));
19
+ return Promise.resolve();
20
+ }
21
+ else {
22
+ //Do the requested action and re-assign the lastActionTime
23
+ lastActionTime = now;
24
+ return func();
25
+ }
26
+ }
27
+ function __flush() {
28
+ return syncManager ? syncManager.flush() : Promise.resolve();
29
+ }
30
+ return {
31
+ init: function () {
32
+ if (hasInit)
33
+ return;
34
+ hasInit = true;
35
+ if (!isSharedClient) {
36
+ validateAndTrackApiKey(settings.log, settings.core.authorizationKey);
37
+ sdkReadinessManager.readinessManager.init();
38
+ impressionsTracker.start();
39
+ syncManager && syncManager.start();
40
+ signalListener && signalListener.start();
41
+ }
42
+ },
43
+ flush: function () {
44
+ // @TODO define cooldown time
45
+ return __cooldown(__flush, COOLDOWN_TIME_IN_MILLIS);
46
+ },
47
+ destroy: function () {
48
+ hasInit = false;
49
+ // Mark the SDK as destroyed immediately
50
+ sdkReadinessManager.readinessManager.destroy();
51
+ // For main client, cleanup the SDK Key, listeners and scheduled jobs, and record stat before flushing data
52
+ if (!isSharedClient) {
53
+ releaseApiKey(settings.core.authorizationKey);
54
+ telemetryTracker.sessionLength();
55
+ signalListener && signalListener.stop();
56
+ impressionsTracker.stop();
57
+ }
58
+ // Stop background jobs
59
+ syncManager && syncManager.stop();
60
+ splitApi && splitApi.stop();
61
+ return __flush().then(function () {
62
+ // Cleanup storage
63
+ return storage.destroy();
64
+ });
65
+ }
66
+ };
67
+ }