@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,19 @@
1
+ import { FALLBACK_DEFINITION_NOT_FOUND, DEFINITION_NOT_FOUND } from '../labels';
2
+ import { IReadinessManager } from '../../readiness/types';
3
+ import { ILogger } from '../../logger/types';
4
+ import { WARN_NOT_EXISTENT_DEFINITION } from '../../logger/constants';
5
+
6
+ /**
7
+ * This is defined here and in this format mostly because of the logger and the fact that it's considered a validation at product level.
8
+ * But it's not going to run on the input validation layer. In any case, the most compelling reason to use it as we do is to avoid going to Redis and get a definition twice.
9
+ */
10
+ export function validateDefinitionExistence(log: ILogger, readinessManager: IReadinessManager, definitionName: string, labelOrDefinitionObj: any, method: string): boolean {
11
+ if (readinessManager.isReady()) { // Only if it's ready (synced with BE) we validate this, otherwise it may just be that the SDK is still syncing
12
+ if (labelOrDefinitionObj === DEFINITION_NOT_FOUND || labelOrDefinitionObj === FALLBACK_DEFINITION_NOT_FOUND || labelOrDefinitionObj == null) {
13
+ log.warn(WARN_NOT_EXISTENT_DEFINITION, [method, definitionName]);
14
+ return false;
15
+ }
16
+ }
17
+
18
+ return true;
19
+ }
@@ -0,0 +1,21 @@
1
+ import { ERROR_EMPTY_ARRAY } from '../../logger/constants';
2
+ import { ILogger } from '../../logger/types';
3
+ import { uniq } from '../lang';
4
+ import { validateDefinition } from './definition';
5
+
6
+ export function validateDefinitions(log: ILogger, maybeDefinitions: any, method: string, listName = 'feature flag names', item = 'feature flag name'): string[] | false {
7
+ if (Array.isArray(maybeDefinitions) && maybeDefinitions.length > 0) {
8
+ let validatedArray: string[] = [];
9
+ // Remove invalid values
10
+ maybeDefinitions.forEach(maybeDefinition => {
11
+ const definitionName = validateDefinition(log, maybeDefinition, method, item);
12
+ if (definitionName) validatedArray.push(definitionName);
13
+ });
14
+
15
+ // Strip off duplicated values if we have valid definition names then return
16
+ if (validatedArray.length) return uniq(validatedArray);
17
+ }
18
+
19
+ log.error(ERROR_EMPTY_ARRAY, [method, listName]);
20
+ return false;
21
+ }
@@ -4,10 +4,10 @@ export { validateEvent } from './event';
4
4
  export { validateEventValue } from './eventValue';
5
5
  export { validateEventProperties } from './eventProperties';
6
6
  export { validateKey } from './key';
7
- export { validateSplit } from './split';
8
- export { validateSplits } from './splits';
7
+ export { validateDefinition } from './definition';
8
+ export { validateDefinitions } from './definitions';
9
9
  export { validateTrafficType } from './trafficType';
10
10
  export { validateIfNotDestroyed, validateIfReadyFromCache, validateIfOperational } from './isOperational';
11
- export { validateSplitExistence } from './splitExistence';
11
+ export { validateDefinitionExistence } from './definitionExistence';
12
12
  export { validateTrafficTypeExistence } from './trafficTypeExistence';
13
13
  export { validateEvaluationOptions } from './eventProperties';
@@ -9,14 +9,14 @@ export function validateIfNotDestroyed(log: ILogger, readinessManager: IReadines
9
9
  return false;
10
10
  }
11
11
 
12
- export function validateIfReadyFromCache(log: ILogger, readinessManager: IReadinessManager, method: string, featureFlagNameOrNames?: string | string[] | false) {
12
+ export function validateIfReadyFromCache(log: ILogger, readinessManager: IReadinessManager, method: string) {
13
13
  if (readinessManager.isReadyFromCache()) return true;
14
14
 
15
- log.warn(CLIENT_NOT_READY_FROM_CACHE, [method, featureFlagNameOrNames ? ` for feature flag ${featureFlagNameOrNames.toString()}` : '']);
15
+ log.warn(CLIENT_NOT_READY_FROM_CACHE, [method]);
16
16
  return false;
17
17
  }
18
18
 
19
19
  // Operational means that the SDK is ready to evaluate (not destroyed and ready from cache)
20
- export function validateIfOperational(log: ILogger, readinessManager: IReadinessManager, method: string, featureFlagNameOrNames?: string | string[] | false) {
21
- return validateIfNotDestroyed(log, readinessManager, method) && validateIfReadyFromCache(log, readinessManager, method, featureFlagNameOrNames);
20
+ export function validateIfOperational(log: ILogger, readinessManager: IReadinessManager, method: string) {
21
+ return validateIfNotDestroyed(log, readinessManager, method) && validateIfReadyFromCache(log, readinessManager, method);
22
22
  }
@@ -0,0 +1,21 @@
1
+ import { isObject } from '../lang';
2
+ import SplitIO from '../../../types/splitio';
3
+ import { ILogger } from '../../logger/types';
4
+ import { validateKey } from './key';
5
+ import { validateAttributes } from './attributes';
6
+ import { ERROR_NOT_PLAIN_OBJECT } from '../../logger/constants';
7
+
8
+ export function validateTarget(log: ILogger, maybeTarget: any, method: string): SplitIO.Target | false {
9
+ if (!isObject(maybeTarget)) {
10
+ log.error(ERROR_NOT_PLAIN_OBJECT, [method, 'target']);
11
+ return false;
12
+ }
13
+
14
+ const key = validateKey(log, maybeTarget.key, method);
15
+ if (key === false) return false;
16
+
17
+ const attributes = validateAttributes(log, maybeTarget.attributes, method);
18
+ if (attributes === false) return false;
19
+
20
+ return { ...maybeTarget, key, attributes };
21
+ }
@@ -1,6 +1,6 @@
1
1
  import { thenable } from '../promise/thenable';
2
2
  import { LOCALHOST_MODE } from '../constants';
3
- import { ISplitsCacheBase } from '../../storages/types';
3
+ import { IDefinitionsCacheBase } from '../../storages/types';
4
4
  import { IReadinessManager } from '../../readiness/types';
5
5
  import SplitIO from '../../../types/splitio';
6
6
  import { MaybeThenable } from '../../dtos/types';
@@ -14,7 +14,7 @@ function logTTExistenceWarning(log: ILogger, maybeTT: string, method: string) {
14
14
  /**
15
15
  * Separated from the previous method since on some cases it'll be async.
16
16
  */
17
- export function validateTrafficTypeExistence(log: ILogger, readinessManager: IReadinessManager, splitsCache: ISplitsCacheBase, mode: SplitIO.SDKMode, maybeTT: string, method: string): MaybeThenable<boolean> {
17
+ export function validateTrafficTypeExistence(log: ILogger, readinessManager: IReadinessManager, splitsCache: IDefinitionsCacheBase, mode: SplitIO.SDKMode, maybeTT: string, method: string): MaybeThenable<boolean> {
18
18
 
19
19
  // If not ready or in localhost mode, we won't run the validation
20
20
  if (!readinessManager.isReady() || mode === LOCALHOST_MODE) return true;
@@ -1,6 +1,6 @@
1
1
  export interface IDecodedJWTToken {
2
2
  ['x-ably-capability']: string
3
- exp: number
3
+ exp: number // epoch seconds
4
4
  iat: number
5
5
 
6
6
  /** Unused fields: */
@@ -2,11 +2,11 @@ import { FALLBACK_PREFIX } from '../../evaluator/fallbackTreatmentsCalculator';
2
2
 
3
3
  export const SPLIT_KILLED = 'killed';
4
4
  export const NO_CONDITION_MATCH = 'default rule';
5
- export const SPLIT_NOT_FOUND = 'definition not found';
5
+ export const DEFINITION_NOT_FOUND = 'definition not found';
6
6
  export const SDK_NOT_READY = 'not ready';
7
7
  export const EXCEPTION = 'exception';
8
8
  export const SPLIT_ARCHIVED = 'archived';
9
9
  export const NOT_IN_SPLIT = 'not in split';
10
10
  export const UNSUPPORTED_MATCHER_TYPE = 'targeting rule type unsupported by sdk';
11
11
  export const PREREQUISITES_NOT_MET = 'prerequisites not met';
12
- export const FALLBACK_SPLIT_NOT_FOUND = FALLBACK_PREFIX + SPLIT_NOT_FOUND;
12
+ export const FALLBACK_DEFINITION_NOT_FOUND = FALLBACK_PREFIX + DEFINITION_NOT_FOUND;
@@ -12,6 +12,8 @@ export function returnSetsUnion<T>(set: Set<T>, set2: Set<T>): Set<T> {
12
12
  return new Set(setToArray(set).concat(setToArray(set2)));
13
13
  }
14
14
 
15
- export function returnDifference<T>(list: T[] = [], list2: T[] = []): T[] {
16
- return list.filter(item => list2.indexOf(item) === -1);
15
+ export function returnDifference<T>(list1?: T[] | null, list2?: T[] | null): T[] {
16
+ list1 = list1 || [];
17
+ list2 = list2 || [];
18
+ return list1.filter(item => list2!.indexOf(item) === -1);
17
19
  }
@@ -1,4 +1,4 @@
1
- import { validateSplits } from '../inputValidation/splits';
1
+ import { validateDefinitions } from '../inputValidation/definitions';
2
2
  import { ISplitFiltersValidation } from '../../dtos/types';
3
3
  import SplitIO from '../../../types/splitio';
4
4
  import { ILogger } from '../../logger/types';
@@ -49,7 +49,7 @@ function validateFilterType(maybeFilterType: any): maybeFilterType is SplitIO.Sp
49
49
  */
50
50
  function validateSplitFilter(log: ILogger, type: SplitIO.SplitFilterType, values: string[], maxLength: number) {
51
51
  // validate and remove invalid and duplicated values
52
- let result = validateSplits(log, values, LOG_PREFIX_SETTINGS, `${type} filter`, `${type} filter value`);
52
+ let result = validateDefinitions(log, values, LOG_PREFIX_SETTINGS, `${type} filter`, `${type} filter value`);
53
53
 
54
54
  if (result) {
55
55
 
@@ -181,7 +181,7 @@ export function validateSplitFilters(log: ILogger, maybeSplitFilters: any, mode:
181
181
  }
182
182
 
183
183
  export function validateFlagSets(log: ILogger, method: string, flagSets: string[], flagSetsInConfig: string[]): string[] | false {
184
- const sets = validateSplits(log, flagSets, method, 'flag sets', 'flag set');
184
+ const sets = validateDefinitions(log, flagSets, method, 'flag sets', 'flag set');
185
185
  let toReturn = sets ? sanitizeFlagSets(log, sets, method) : [];
186
186
  if (flagSetsInConfig.length > 0) {
187
187
  toReturn = toReturn.filter(flagSet => {
@@ -2,7 +2,7 @@ import { ISettings } from '../../types';
2
2
 
3
3
  const telemetryEndpointMatcher = /^\/v1\/metrics\/(config|usage)/;
4
4
  const eventsEndpointMatcher = /^\/(testImpressions|metrics|events)/;
5
- const authEndpointMatcher = /^\/v2\/auth/;
5
+ const authEndpointMatcher = /^\/(v2|v3)\/auth/;
6
6
  const streamingEndpointMatcher = /^\/(sse|event-stream)/;
7
7
 
8
8
  /**
@@ -73,10 +73,12 @@ interface ISharedSettings {
73
73
  * const factory = SplitFactory({
74
74
  * ...
75
75
  * sync: {
76
- * getHeaderOverrides: (context) => {
77
- * return {
78
- * 'Authorization': context.headers['Authorization'] + ', other-value',
79
- * 'custom-header': 'custom-value'
76
+ * requestOptions: {
77
+ * getHeaderOverrides: (context) => {
78
+ * return {
79
+ * 'Authorization': context.headers['Authorization'] + ', other-value',
80
+ * 'custom-header': 'custom-value'
81
+ * };
80
82
  * };
81
83
  * }
82
84
  * }
@@ -493,7 +495,7 @@ declare namespace SplitIO {
493
495
  }
494
496
 
495
497
  /**
496
- * Metadata for the update event emitted when the SDK cache is updated with new data for flags or segments.
498
+ * Metadata for the update event emitted when the SDK cache is updated with new data for flags, configs, or segments.
497
499
  */
498
500
  type SdkUpdateMetadata = {
499
501
  /**
@@ -501,7 +503,7 @@ declare namespace SplitIO {
501
503
  */
502
504
  type: SdkUpdateMetadataType;
503
505
  /**
504
- * The names of the flags or segments that were updated.
506
+ * The names of the flags or configs that were updated. Empty array if the update is of type 'SEGMENTS_UPDATE'.
505
507
  */
506
508
  names: string[];
507
509
  }
@@ -509,7 +511,7 @@ declare namespace SplitIO {
509
511
  /**
510
512
  * Metadata type for SDK update events.
511
513
  */
512
- type SdkUpdateMetadataType = 'FLAGS_UPDATE' | 'SEGMENTS_UPDATE';
514
+ type SdkUpdateMetadataType = 'CONFIGS_UPDATE' | 'FLAGS_UPDATE' | 'SEGMENTS_UPDATE';
513
515
 
514
516
  /**
515
517
  * Metadata for the ready events emitted when the SDK is ready to evaluate feature flags.
@@ -1590,10 +1592,12 @@ declare namespace SplitIO {
1590
1592
  * const factory = SplitFactory({
1591
1593
  * ...
1592
1594
  * sync: {
1593
- * getHeaderOverrides: (context) => {
1594
- * return {
1595
- * 'Authorization': context.headers['Authorization'] + ', other-value',
1596
- * 'custom-header': 'custom-value'
1595
+ * requestOptions: {
1596
+ * getHeaderOverrides: (context) => {
1597
+ * return {
1598
+ * 'Authorization': context.headers['Authorization'] + ', other-value',
1599
+ * 'custom-header': 'custom-value'
1600
+ * };
1597
1601
  * };
1598
1602
  * }
1599
1603
  * }
@@ -2284,4 +2288,211 @@ declare namespace SplitIO {
2284
2288
  */
2285
2289
  split(featureFlagName: string): SplitViewAsync;
2286
2290
  }
2291
+
2292
+ /**
2293
+ * Fallback configuration objects returned by the `client.getConfig` method when the SDK is not ready or the provided config name is not found.
2294
+ */
2295
+ type FallbackConfigs = {
2296
+ /**
2297
+ * Fallback config for all config names.
2298
+ */
2299
+ global?: Config;
2300
+ /**
2301
+ * Fallback configs for specific config names. It takes precedence over the global fallback config.
2302
+ */
2303
+ byName?: {
2304
+ [configName: string]: Config;
2305
+ };
2306
+ }
2307
+
2308
+ /**
2309
+ * Configs SDK settings.
2310
+ */
2311
+ interface ConfigsClientSettings {
2312
+ /**
2313
+ * Your SDK key.
2314
+ *
2315
+ * @see {@link https://developer.harness.io/docs/feature-management-experimentation/management-and-administration/account-settings/api-keys/}
2316
+ */
2317
+ authorizationKey: string;
2318
+ /**
2319
+ * Polling rate for configs and segments refresh, in seconds. Minimum value: 5.
2320
+ *
2321
+ * @defaultValue `60`
2322
+ */
2323
+ pollingRate?: number;
2324
+ /**
2325
+ * Push rate for events and impressions, in seconds. Minimum value: 60.
2326
+ *
2327
+ * @defaultValue `60`
2328
+ */
2329
+ pushRate?: number;
2330
+ /**
2331
+ * Maximum queue size for events and impressions. When the queue reaches this size, a flush is triggered. Minimum value: 1000.
2332
+ *
2333
+ * @defaultValue `10000`
2334
+ */
2335
+ queueSize?: number;
2336
+ /**
2337
+ * Logging level.
2338
+ *
2339
+ * @defaultValue `'NONE'`
2340
+ */
2341
+ logLevel?: LogLevel;
2342
+ /**
2343
+ * Time in seconds until SDK ready timeout is emitted.
2344
+ *
2345
+ * @defaultValue `10`
2346
+ */
2347
+ timeout?: number;
2348
+ /**
2349
+ * Custom endpoints to replace the default ones used by the SDK.
2350
+ */
2351
+ urls?: {
2352
+ /**
2353
+ * String property to override the base URL where the SDK will get JWT authentication credentials.
2354
+ *
2355
+ * @defaultValue `'https://auth.split.io/api'`
2356
+ */
2357
+ auth?: string;
2358
+ /**
2359
+ * String property to override the base URL where the SDK will get rollout plan related data, like feature flags and segments definitions.
2360
+ *
2361
+ * @defaultValue `'https://appconfig.split.io/api'`
2362
+ */
2363
+ sdk?: string;
2364
+ /**
2365
+ * String property to override the base URL where the SDK will post event-related information like impressions.
2366
+ *
2367
+ * @defaultValue `'https://events.split.io/api'`
2368
+ */
2369
+ events?: string;
2370
+ };
2371
+ /**
2372
+ * Fallback configuration objects returned by the `client.getConfig` method when the SDK is not ready or the provided config name is not found.
2373
+ */
2374
+ fallbackConfigs?: FallbackConfigs;
2375
+ /**
2376
+ * Custom options object for HTTP(S) requests.
2377
+ * If provided, this object is merged with the options object passed by the SDK for EventSource and Fetch calls.
2378
+ */
2379
+ requestOptions?: {
2380
+ /**
2381
+ * Custom function called before each request, allowing you to add or update headers in SDK HTTP requests.
2382
+ * Some headers, such as `SplitSDKVersion`, are required by the SDK and cannot be overridden.
2383
+ * To pass multiple headers with the same name, combine their values into a single line, separated by commas. Example: `{ 'Authorization': 'value1, value2' }`
2384
+ * Or provide keys with different cases since headers are case-insensitive. Example: `{ 'authorization': 'value1', 'Authorization': 'value2' }`
2385
+ *
2386
+ * @defaultValue `undefined`
2387
+ *
2388
+ * @param context - The context for the request, which contains the `headers` property object representing the current headers in the request.
2389
+ * @returns An object representing a set of headers to be merged with the current headers.
2390
+ *
2391
+ * @example
2392
+ * ```
2393
+ * const client = ConfigsClient({
2394
+ * ...
2395
+ * requestOptions: {
2396
+ * getHeaderOverrides: (context) => {
2397
+ * return {
2398
+ * 'Authorization': context.headers['Authorization'] + ', other-value',
2399
+ * 'custom-header': 'custom-value'
2400
+ * };
2401
+ * }
2402
+ * }
2403
+ * });
2404
+ * ```
2405
+ */
2406
+ getHeaderOverrides?: (context: { headers: Record<string, string>; }) => Record<string, string>;
2407
+ /**
2408
+ * Custom Node.js HTTP(S) Agent used by the SDK for HTTP(S) requests.
2409
+ *
2410
+ * You can use it, for example, for certificate pinning or setting a network proxy:
2411
+ *
2412
+ * ```
2413
+ * const { HttpsProxyAgent } = require('https-proxy-agent');
2414
+ *
2415
+ * const proxyAgent = new HttpsProxyAgent(process.env.HTTPS_PROXY || 'http://10.10.1.10:1080');
2416
+ *
2417
+ * const client = ConfigsClient({
2418
+ * ...
2419
+ * requestOptions: {
2420
+ * agent: proxyAgent
2421
+ * }
2422
+ * })
2423
+ * ```
2424
+ *
2425
+ * @see {@link https://nodejs.org/api/https.html#class-httpsagent}
2426
+ *
2427
+ * @defaultValue `undefined`
2428
+ */
2429
+ agent?: RequestOptions['agent'];
2430
+ };
2431
+ }
2432
+
2433
+ /**
2434
+ * Target for a config evaluation.
2435
+ */
2436
+ interface Target {
2437
+ /**
2438
+ * The key of the target.
2439
+ */
2440
+ key: SplitKey;
2441
+ /**
2442
+ * The attributes of the target.
2443
+ *
2444
+ * @defaultValue `undefined`
2445
+ */
2446
+ attributes?: Attributes;
2447
+ }
2448
+
2449
+ type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
2450
+ type JsonArray = JsonValue[];
2451
+ type JsonObject = { [key: string]: JsonValue; };
2452
+
2453
+ /**
2454
+ * Config object returned by getConfig.
2455
+ */
2456
+ type Config = {
2457
+ /**
2458
+ * The name of the variant.
2459
+ */
2460
+ variant: string;
2461
+ /**
2462
+ * The config value, a raw JSON object.
2463
+ */
2464
+ value: JsonObject;
2465
+ }
2466
+
2467
+ /**
2468
+ * Configs SDK client interface.
2469
+ */
2470
+ interface ConfigsClient extends Omit<IStatusInterface, 'ready'> {
2471
+ /**
2472
+ * Destroys the client.
2473
+ *
2474
+ * @returns A promise that resolves once all clients are destroyed.
2475
+ */
2476
+ destroy(): Promise<void>;
2477
+ /**
2478
+ * Gets the config object for a given config name and optional target. If no target is provided, the default variant of the config is returned.
2479
+ *
2480
+ * @param configName - The name of the config we want to get.
2481
+ * @param target - The target of the config evaluation.
2482
+ * @param options - An object of type EvaluationOptions for advanced evaluation options.
2483
+ * @returns The config object.
2484
+ */
2485
+ getConfig(configName: string, target?: Target, options?: EvaluationOptions): Config;
2486
+ /**
2487
+ * Tracks an event to be fed to the results product on Harness FME user interface.
2488
+ *
2489
+ * @param trafficKey - The key that identifies the entity related to this event.
2490
+ * @param trafficType - The traffic type of the entity related to this event. See {@link https://developer.harness.io/docs/feature-management-experimentation/management-and-administration/fme-settings/traffic-types/}
2491
+ * @param eventType - The event type corresponding to this event.
2492
+ * @param value - The value of this event.
2493
+ * @param properties - The properties of this event. Values can be string, number, boolean or null.
2494
+ * @returns Whether the event was added to the queue successfully or not.
2495
+ */
2496
+ track(trafficKey: SplitKey, trafficType: string, eventType: string, value?: number, properties?: Properties): boolean;
2497
+ }
2287
2498
  }
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbstractSplitsCacheAsync = void 0;
4
- var objectAssign_1 = require("../utils/lang/objectAssign");
5
- /**
6
- * This class provides a skeletal implementation of the ISplitsCacheAsync interface
7
- * to minimize the effort required to implement this interface.
8
- */
9
- var AbstractSplitsCacheAsync = /** @class */ (function () {
10
- function AbstractSplitsCacheAsync() {
11
- }
12
- AbstractSplitsCacheAsync.prototype.update = function (toAdd, toRemove, changeNumber) {
13
- var _this = this;
14
- return Promise.all([
15
- this.setChangeNumber(changeNumber),
16
- Promise.all(toAdd.map(function (addedFF) { return _this.addSplit(addedFF); })),
17
- Promise.all(toRemove.map(function (removedFF) { return _this.removeSplit(removedFF.name); }))
18
- ]).then(function (_a) {
19
- var added = _a[1], removed = _a[2];
20
- return added.some(function (result) { return result; }) || removed.some(function (result) { return result; });
21
- });
22
- };
23
- // @TODO revisit segment-related methods ('usesSegments', 'getRegisteredSegments', 'registerSegments')
24
- // noop, just keeping the interface. This is used by standalone client-side API only, and so only implemented by InMemory and InLocalStorage.
25
- AbstractSplitsCacheAsync.prototype.usesSegments = function () {
26
- return Promise.resolve(true);
27
- };
28
- /**
29
- * Kill `name` split and set `defaultTreatment` and `changeNumber`.
30
- * Used for SPLIT_KILL push notifications.
31
- *
32
- * @returns a promise that is resolved once the split kill operation is performed. The fulfillment value is a boolean: `true` if the operation successed updating the split or `false` if no split is updated,
33
- * for instance, if the `changeNumber` is old, or if the split is not found (e.g., `/splitchanges` hasn't been fetched yet), or if the storage fails to apply the update.
34
- * The promise will never be rejected.
35
- */
36
- AbstractSplitsCacheAsync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
37
- var _this = this;
38
- return this.getSplit(name).then(function (split) {
39
- if (split && (!split.changeNumber || split.changeNumber < changeNumber)) {
40
- var newSplit = (0, objectAssign_1.objectAssign)({}, split);
41
- newSplit.killed = true;
42
- newSplit.defaultTreatment = defaultTreatment;
43
- newSplit.changeNumber = changeNumber;
44
- return _this.addSplit(newSplit);
45
- }
46
- return false;
47
- }).catch(function () { return false; });
48
- };
49
- return AbstractSplitsCacheAsync;
50
- }());
51
- exports.AbstractSplitsCacheAsync = AbstractSplitsCacheAsync;
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usesSegmentsSync = exports.usesSegments = exports.AbstractSplitsCacheSync = void 0;
4
- var objectAssign_1 = require("../utils/lang/objectAssign");
5
- var constants_1 = require("../utils/constants");
6
- /**
7
- * This class provides a skeletal implementation of the ISplitsCacheSync interface
8
- * to minimize the effort required to implement this interface.
9
- */
10
- var AbstractSplitsCacheSync = /** @class */ (function () {
11
- function AbstractSplitsCacheSync() {
12
- }
13
- AbstractSplitsCacheSync.prototype.update = function (toAdd, toRemove, changeNumber) {
14
- var _this = this;
15
- var updated = toAdd.map(function (addedFF) { return _this.addSplit(addedFF); }).some(function (result) { return result; });
16
- updated = toRemove.map(function (removedFF) { return _this.removeSplit(removedFF.name); }).some(function (result) { return result; }) || updated;
17
- this.setChangeNumber(changeNumber);
18
- return updated;
19
- };
20
- AbstractSplitsCacheSync.prototype.getSplits = function (names) {
21
- var _this = this;
22
- var splits = {};
23
- names.forEach(function (name) {
24
- splits[name] = _this.getSplit(name);
25
- });
26
- return splits;
27
- };
28
- AbstractSplitsCacheSync.prototype.getAll = function () {
29
- var _this = this;
30
- return this.getSplitNames().map(function (key) { return _this.getSplit(key); });
31
- };
32
- /**
33
- * Kill `name` split and set `defaultTreatment` and `changeNumber`.
34
- * Used for SPLIT_KILL push notifications.
35
- *
36
- * @returns `true` if the operation successed updating the split, or `false` if no split is updated,
37
- * for instance, if the `changeNumber` is old, or if the split is not found (e.g., `/splitchanges` hasn't been fetched yet), or if the storage fails to apply the update.
38
- */
39
- AbstractSplitsCacheSync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
40
- var split = this.getSplit(name);
41
- if (split && (!split.changeNumber || split.changeNumber < changeNumber)) {
42
- var newSplit = (0, objectAssign_1.objectAssign)({}, split);
43
- newSplit.killed = true;
44
- newSplit.defaultTreatment = defaultTreatment;
45
- newSplit.changeNumber = changeNumber;
46
- return this.addSplit(newSplit);
47
- }
48
- return false;
49
- };
50
- return AbstractSplitsCacheSync;
51
- }());
52
- exports.AbstractSplitsCacheSync = AbstractSplitsCacheSync;
53
- /**
54
- * Given a parsed split, it returns a boolean flagging if its conditions use segments matchers (rules & whitelists).
55
- * This util is intended to simplify the implementation of `splitsCache::usesSegments` method
56
- */
57
- function usesSegments(ruleEntity) {
58
- var conditions = ruleEntity.conditions || [];
59
- for (var i = 0; i < conditions.length; i++) {
60
- var matchers = conditions[i].matcherGroup.matchers;
61
- for (var j = 0; j < matchers.length; j++) {
62
- var matcher = matchers[j].matcherType;
63
- if (matcher === constants_1.IN_SEGMENT || matcher === constants_1.IN_LARGE_SEGMENT)
64
- return true;
65
- }
66
- }
67
- var excluded = ruleEntity.excluded;
68
- if (excluded && excluded.segments && excluded.segments.length > 0)
69
- return true;
70
- return false;
71
- }
72
- exports.usesSegments = usesSegments;
73
- function usesSegmentsSync(storage) {
74
- return storage.splits.usesSegments() || storage.rbSegments.usesSegments();
75
- }
76
- exports.usesSegmentsSync = usesSegmentsSync;