@splitsoftware/splitio-commons 1.6.2-rc.4 → 1.6.2-rc.7

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 (509) hide show
  1. package/CHANGES.txt +3 -0
  2. package/cjs/consent/sdkUserConsent.js +2 -2
  3. package/cjs/evaluator/index.js +10 -11
  4. package/cjs/integrations/ga/GaToSplit.js +8 -5
  5. package/cjs/listeners/browser.js +2 -1
  6. package/cjs/logger/constants.js +2 -1
  7. package/cjs/sdkClient/clientAttributesDecoration.js +1 -1
  8. package/cjs/sdkClient/sdkClient.js +3 -1
  9. package/cjs/sdkFactory/index.js +28 -8
  10. package/cjs/sdkManager/index.js +3 -11
  11. package/cjs/services/splitApi.js +20 -1
  12. package/cjs/storages/AbstractSplitsCacheAsync.js +7 -9
  13. package/cjs/storages/AbstractSplitsCacheSync.js +7 -9
  14. package/cjs/storages/KeyBuilderSS.js +6 -0
  15. package/cjs/storages/dataLoader.js +1 -1
  16. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +5 -6
  17. package/cjs/storages/inLocalStorage/index.js +4 -0
  18. package/cjs/storages/inMemory/AttributesCacheInMemory.js +1 -1
  19. package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
  20. package/cjs/storages/inMemory/InMemoryStorage.js +5 -1
  21. package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -1
  22. package/cjs/storages/inMemory/SplitsCacheInMemory.js +7 -10
  23. package/cjs/storages/inMemory/uniqueKeysCacheInMemory.js +73 -0
  24. package/cjs/storages/inMemory/uniqueKeysCacheInMemoryCS.js +78 -0
  25. package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +49 -0
  26. package/cjs/storages/inRedis/SplitsCacheInRedis.js +15 -9
  27. package/cjs/storages/inRedis/constants.js +4 -1
  28. package/cjs/storages/inRedis/index.js +15 -1
  29. package/cjs/storages/inRedis/uniqueKeysCacheInRedis.js +56 -0
  30. package/cjs/storages/pluggable/SplitsCachePluggable.js +14 -9
  31. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
  32. package/cjs/sync/polling/updaters/splitChangesUpdater.js +1 -1
  33. package/cjs/sync/submitters/submitterManager.js +3 -0
  34. package/cjs/sync/submitters/telemetrySubmitter.js +1 -0
  35. package/cjs/sync/submitters/uniqueKeysSubmitter.js +26 -0
  36. package/cjs/trackers/impressionsTracker.js +22 -41
  37. package/cjs/trackers/strategy/strategyDebug.js +25 -0
  38. package/cjs/trackers/strategy/strategyNone.js +29 -0
  39. package/cjs/trackers/strategy/strategyOptimized.js +35 -0
  40. package/cjs/trackers/telemetryTracker.js +6 -0
  41. package/cjs/trackers/uniqueKeysTracker.js +38 -0
  42. package/cjs/types.js +2 -0
  43. package/cjs/utils/constants/index.js +4 -2
  44. package/cjs/utils/key/index.js +1 -1
  45. package/cjs/utils/settingsValidation/impressionsMode.js +2 -2
  46. package/cjs/utils/settingsValidation/index.js +4 -1
  47. package/esm/consent/sdkUserConsent.js +2 -2
  48. package/esm/evaluator/index.js +10 -11
  49. package/esm/integrations/ga/GaToSplit.js +8 -5
  50. package/esm/listeners/browser.js +3 -2
  51. package/esm/logger/constants.js +1 -0
  52. package/esm/sdkClient/clientAttributesDecoration.js +1 -1
  53. package/esm/sdkClient/sdkClient.js +3 -1
  54. package/esm/sdkFactory/index.js +28 -8
  55. package/esm/sdkManager/index.js +3 -11
  56. package/esm/services/splitApi.js +20 -1
  57. package/esm/storages/AbstractSplitsCacheAsync.js +7 -9
  58. package/esm/storages/AbstractSplitsCacheSync.js +7 -9
  59. package/esm/storages/KeyBuilderSS.js +6 -0
  60. package/esm/storages/dataLoader.js +1 -1
  61. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +5 -6
  62. package/esm/storages/inLocalStorage/index.js +5 -1
  63. package/esm/storages/inMemory/AttributesCacheInMemory.js +1 -1
  64. package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
  65. package/esm/storages/inMemory/InMemoryStorage.js +6 -2
  66. package/esm/storages/inMemory/InMemoryStorageCS.js +6 -2
  67. package/esm/storages/inMemory/SplitsCacheInMemory.js +7 -10
  68. package/esm/storages/inMemory/uniqueKeysCacheInMemory.js +70 -0
  69. package/esm/storages/inMemory/uniqueKeysCacheInMemoryCS.js +75 -0
  70. package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +46 -0
  71. package/esm/storages/inRedis/SplitsCacheInRedis.js +15 -9
  72. package/esm/storages/inRedis/constants.js +3 -0
  73. package/esm/storages/inRedis/index.js +16 -2
  74. package/esm/storages/inRedis/uniqueKeysCacheInRedis.js +53 -0
  75. package/esm/storages/pluggable/SplitsCachePluggable.js +14 -9
  76. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
  77. package/esm/sync/polling/updaters/splitChangesUpdater.js +1 -1
  78. package/esm/sync/submitters/submitterManager.js +3 -0
  79. package/esm/sync/submitters/telemetrySubmitter.js +2 -1
  80. package/esm/sync/submitters/uniqueKeysSubmitter.js +22 -0
  81. package/esm/trackers/impressionsTracker.js +22 -41
  82. package/esm/trackers/strategy/strategyDebug.js +21 -0
  83. package/esm/trackers/strategy/strategyNone.js +25 -0
  84. package/esm/trackers/strategy/strategyOptimized.js +31 -0
  85. package/esm/trackers/telemetryTracker.js +6 -0
  86. package/esm/trackers/uniqueKeysTracker.js +34 -0
  87. package/esm/types.js +1 -0
  88. package/esm/utils/constants/index.js +2 -0
  89. package/esm/utils/key/index.js +1 -1
  90. package/esm/utils/settingsValidation/impressionsMode.js +3 -3
  91. package/esm/utils/settingsValidation/index.js +4 -1
  92. package/package.json +5 -4
  93. package/src/consent/sdkUserConsent.ts +5 -6
  94. package/src/dtos/types.ts +8 -0
  95. package/src/evaluator/Engine.ts +3 -3
  96. package/src/evaluator/combiners/and.ts +1 -1
  97. package/src/evaluator/combiners/ifelseif.ts +3 -3
  98. package/src/evaluator/condition/engineUtils.ts +1 -1
  99. package/src/evaluator/condition/index.ts +6 -6
  100. package/src/evaluator/index.ts +18 -19
  101. package/src/evaluator/matchers/all.ts +1 -1
  102. package/src/evaluator/matchers/between.ts +1 -1
  103. package/src/evaluator/matchers/boolean.ts +1 -1
  104. package/src/evaluator/matchers/cont_all.ts +1 -1
  105. package/src/evaluator/matchers/cont_any.ts +1 -1
  106. package/src/evaluator/matchers/cont_str.ts +1 -1
  107. package/src/evaluator/matchers/dependency.ts +1 -1
  108. package/src/evaluator/matchers/eq.ts +1 -1
  109. package/src/evaluator/matchers/eq_set.ts +1 -1
  110. package/src/evaluator/matchers/ew.ts +1 -1
  111. package/src/evaluator/matchers/gte.ts +1 -1
  112. package/src/evaluator/matchers/index.ts +1 -1
  113. package/src/evaluator/matchers/lte.ts +1 -1
  114. package/src/evaluator/matchers/part_of.ts +1 -1
  115. package/src/evaluator/matchers/segment.ts +1 -1
  116. package/src/evaluator/matchers/string.ts +1 -1
  117. package/src/evaluator/matchers/sw.ts +1 -1
  118. package/src/evaluator/matchers/whitelist.ts +1 -1
  119. package/src/evaluator/parser/index.ts +3 -3
  120. package/src/evaluator/types.ts +6 -6
  121. package/src/evaluator/value/index.ts +4 -4
  122. package/src/evaluator/value/sanitize.ts +4 -4
  123. package/src/integrations/ga/GaToSplit.ts +15 -11
  124. package/src/integrations/ga/SplitToGa.ts +10 -10
  125. package/src/integrations/ga/types.ts +4 -4
  126. package/src/integrations/pluggable.ts +3 -3
  127. package/src/integrations/types.ts +4 -3
  128. package/src/listeners/browser.ts +3 -2
  129. package/src/logger/constants.ts +1 -0
  130. package/src/logger/index.ts +3 -3
  131. package/src/logger/sdkLogger.ts +2 -1
  132. package/src/logger/types.ts +16 -0
  133. package/src/readiness/sdkReadinessManager.ts +1 -1
  134. package/src/readiness/types.ts +9 -2
  135. package/src/sdkClient/client.ts +13 -13
  136. package/src/sdkClient/clientAttributesDecoration.ts +13 -13
  137. package/src/sdkClient/clientCS.ts +4 -3
  138. package/src/sdkClient/clientInputValidation.ts +15 -15
  139. package/src/sdkClient/sdkClient.ts +5 -3
  140. package/src/sdkClient/sdkClientMethod.ts +2 -2
  141. package/src/sdkClient/sdkClientMethodCS.ts +9 -9
  142. package/src/sdkClient/sdkClientMethodCSWithTT.ts +9 -9
  143. package/src/sdkFactory/index.ts +34 -11
  144. package/src/sdkFactory/types.ts +11 -8
  145. package/src/sdkManager/index.ts +7 -16
  146. package/src/services/splitApi.ts +22 -1
  147. package/src/services/types.ts +6 -0
  148. package/src/storages/AbstractSplitsCacheAsync.ts +12 -14
  149. package/src/storages/AbstractSplitsCacheSync.ts +14 -16
  150. package/src/storages/KeyBuilderSS.ts +8 -0
  151. package/src/storages/dataLoader.ts +3 -3
  152. package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +1 -1
  153. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +10 -12
  154. package/src/storages/inLocalStorage/index.ts +6 -4
  155. package/src/storages/inMemory/AttributesCacheInMemory.ts +12 -13
  156. package/src/storages/inMemory/EventsCacheInMemory.ts +4 -4
  157. package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +16 -1
  158. package/src/storages/inMemory/InMemoryStorage.ts +5 -2
  159. package/src/storages/inMemory/InMemoryStorageCS.ts +6 -2
  160. package/src/storages/inMemory/SplitsCacheInMemory.ts +10 -14
  161. package/src/storages/inMemory/uniqueKeysCacheInMemory.ts +82 -0
  162. package/src/storages/inMemory/uniqueKeysCacheInMemoryCS.ts +88 -0
  163. package/src/storages/inRedis/EventsCacheInRedis.ts +4 -4
  164. package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +51 -0
  165. package/src/storages/inRedis/ImpressionsCacheInRedis.ts +1 -1
  166. package/src/storages/inRedis/RedisAdapter.ts +1 -1
  167. package/src/storages/inRedis/SegmentsCacheInRedis.ts +1 -1
  168. package/src/storages/inRedis/SplitsCacheInRedis.ts +22 -18
  169. package/src/storages/inRedis/TelemetryCacheInRedis.ts +1 -1
  170. package/src/storages/inRedis/constants.ts +3 -0
  171. package/src/storages/inRedis/index.ts +14 -6
  172. package/src/storages/inRedis/uniqueKeysCacheInRedis.ts +63 -0
  173. package/src/storages/pluggable/EventsCachePluggable.ts +4 -4
  174. package/src/storages/pluggable/ImpressionsCachePluggable.ts +1 -1
  175. package/src/storages/pluggable/SegmentsCachePluggable.ts +1 -1
  176. package/src/storages/pluggable/SplitsCachePluggable.ts +21 -18
  177. package/src/storages/pluggable/TelemetryCachePluggable.ts +1 -1
  178. package/src/storages/pluggable/index.ts +3 -3
  179. package/src/storages/pluggable/wrapperAdapter.ts +1 -1
  180. package/src/storages/types.ts +60 -62
  181. package/src/sync/offline/LocalhostFromObject.ts +4 -4
  182. package/src/sync/offline/splitsParser/splitsParserFromSettings.ts +8 -8
  183. package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +5 -6
  184. package/src/sync/polling/updaters/mySegmentsUpdater.ts +1 -1
  185. package/src/sync/polling/updaters/segmentChangesUpdater.ts +1 -1
  186. package/src/sync/polling/updaters/splitChangesUpdater.ts +3 -3
  187. package/src/sync/streaming/SSEHandler/index.ts +1 -1
  188. package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +1 -1
  189. package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +1 -1
  190. package/src/sync/submitters/submitter.ts +1 -1
  191. package/src/sync/submitters/submitterManager.ts +2 -0
  192. package/src/sync/submitters/telemetrySubmitter.ts +4 -3
  193. package/src/sync/submitters/types.ts +22 -3
  194. package/src/sync/submitters/uniqueKeysSubmitter.ts +35 -0
  195. package/src/sync/syncTask.ts +1 -1
  196. package/src/trackers/eventTracker.ts +3 -3
  197. package/src/trackers/impressionsTracker.ts +30 -51
  198. package/src/trackers/strategy/strategyDebug.ts +28 -0
  199. package/src/trackers/strategy/strategyNone.ts +34 -0
  200. package/src/trackers/strategy/strategyOptimized.ts +42 -0
  201. package/src/trackers/telemetryTracker.ts +7 -2
  202. package/src/trackers/types.ts +36 -4
  203. package/src/trackers/uniqueKeysTracker.ts +48 -0
  204. package/src/types.ts +1267 -0
  205. package/src/utils/constants/index.ts +3 -1
  206. package/src/utils/inputValidation/apiKey.ts +1 -1
  207. package/src/utils/inputValidation/attribute.ts +1 -1
  208. package/src/utils/inputValidation/attributes.ts +3 -3
  209. package/src/utils/inputValidation/event.ts +1 -1
  210. package/src/utils/inputValidation/eventProperties.ts +3 -3
  211. package/src/utils/inputValidation/eventValue.ts +1 -1
  212. package/src/utils/inputValidation/isOperational.ts +1 -1
  213. package/src/utils/inputValidation/key.ts +3 -3
  214. package/src/utils/inputValidation/preloadedData.ts +3 -3
  215. package/src/utils/inputValidation/split.ts +1 -1
  216. package/src/utils/inputValidation/splitExistance.ts +1 -1
  217. package/src/utils/inputValidation/splits.ts +1 -1
  218. package/src/utils/inputValidation/trafficType.ts +1 -1
  219. package/src/utils/inputValidation/trafficTypeExistance.ts +1 -1
  220. package/src/utils/key/index.ts +9 -9
  221. package/src/utils/settingsValidation/consent.ts +2 -1
  222. package/src/utils/settingsValidation/impressionsMode.ts +6 -6
  223. package/src/utils/settingsValidation/index.ts +5 -1
  224. package/src/utils/settingsValidation/integrations/common.ts +1 -1
  225. package/src/utils/settingsValidation/integrations/configurable.ts +1 -1
  226. package/src/utils/settingsValidation/integrations/pluggable.ts +2 -1
  227. package/src/utils/settingsValidation/localhost/builtin.ts +2 -1
  228. package/src/utils/settingsValidation/localhost/pluggable.ts +2 -1
  229. package/src/utils/settingsValidation/logger/builtinLogger.ts +2 -1
  230. package/src/utils/settingsValidation/logger/pluggableLogger.ts +2 -1
  231. package/src/utils/settingsValidation/splitFilters.ts +9 -7
  232. package/src/utils/settingsValidation/storage/storageCS.ts +2 -1
  233. package/types/consent/index.d.ts +2 -0
  234. package/types/consent/sdkUserConsent.d.ts +13 -0
  235. package/types/dtos/types.d.ts +172 -0
  236. package/types/evaluator/Engine.d.ts +15 -0
  237. package/types/evaluator/combiners/and.d.ts +4 -0
  238. package/types/evaluator/combiners/ifelseif.d.ts +3 -0
  239. package/types/evaluator/condition/engineUtils.d.ts +11 -0
  240. package/types/evaluator/condition/index.d.ts +6 -0
  241. package/types/evaluator/convertions/index.d.ts +2 -0
  242. package/types/evaluator/index.d.ts +7 -0
  243. package/types/evaluator/matchers/all.d.ts +2 -0
  244. package/types/evaluator/matchers/between.d.ts +3 -0
  245. package/types/evaluator/matchers/boolean.d.ts +2 -0
  246. package/types/evaluator/matchers/cont_all.d.ts +2 -0
  247. package/types/evaluator/matchers/cont_any.d.ts +2 -0
  248. package/types/evaluator/matchers/cont_str.d.ts +2 -0
  249. package/types/evaluator/matchers/dependency.d.ts +5 -0
  250. package/types/evaluator/matchers/eq.d.ts +2 -0
  251. package/types/evaluator/matchers/eq_set.d.ts +2 -0
  252. package/types/evaluator/matchers/ew.d.ts +2 -0
  253. package/types/evaluator/matchers/gte.d.ts +2 -0
  254. package/types/evaluator/matchers/index.d.ts +7 -0
  255. package/types/evaluator/matchers/lte.d.ts +2 -0
  256. package/types/evaluator/matchers/matcherTypes.d.ts +10 -0
  257. package/types/evaluator/matchers/part_of.d.ts +2 -0
  258. package/types/evaluator/matchers/segment.d.ts +6 -0
  259. package/types/evaluator/matchers/string.d.ts +2 -0
  260. package/types/evaluator/matchers/sw.d.ts +2 -0
  261. package/types/evaluator/matchers/whitelist.d.ts +3 -0
  262. package/types/evaluator/matchersTransform/index.d.ts +6 -0
  263. package/types/evaluator/matchersTransform/segment.d.ts +5 -0
  264. package/types/evaluator/matchersTransform/set.d.ts +5 -0
  265. package/types/evaluator/matchersTransform/unaryNumeric.d.ts +5 -0
  266. package/types/evaluator/matchersTransform/whitelist.d.ts +5 -0
  267. package/types/evaluator/parser/index.d.ts +5 -0
  268. package/types/evaluator/treatments/index.d.ts +8 -0
  269. package/types/evaluator/types.d.ts +28 -0
  270. package/types/evaluator/value/index.d.ts +7 -0
  271. package/types/evaluator/value/sanitize.d.ts +7 -0
  272. package/types/index.d.ts +5 -0
  273. package/types/integrations/browser.d.ts +12 -0
  274. package/types/integrations/ga/GaToSplit.d.ts +40 -0
  275. package/types/integrations/ga/GoogleAnalyticsToSplit.d.ts +3 -0
  276. package/types/integrations/ga/SplitToGa.d.ts +34 -0
  277. package/types/integrations/ga/SplitToGoogleAnalytics.d.ts +3 -0
  278. package/types/integrations/ga/types.d.ts +148 -0
  279. package/types/integrations/pluggable.d.ts +11 -0
  280. package/types/integrations/types.d.ts +18 -0
  281. package/types/listeners/browser.d.ts +40 -0
  282. package/types/listeners/node.d.ts +22 -0
  283. package/types/listeners/types.d.ts +4 -0
  284. package/types/logger/browser/DebugLogger.d.ts +2 -0
  285. package/types/logger/browser/ErrorLogger.d.ts +2 -0
  286. package/types/logger/browser/InfoLogger.d.ts +2 -0
  287. package/types/logger/browser/WarnLogger.d.ts +2 -0
  288. package/types/logger/constants.d.ts +142 -0
  289. package/types/logger/index.d.ts +22 -0
  290. package/types/logger/messages/debug.d.ts +1 -0
  291. package/types/logger/messages/error.d.ts +1 -0
  292. package/types/logger/messages/info.d.ts +1 -0
  293. package/types/logger/messages/warn.d.ts +1 -0
  294. package/types/logger/sdkLogger.d.ts +8 -0
  295. package/types/logger/types.d.ts +17 -0
  296. package/types/readiness/constants.d.ts +7 -0
  297. package/types/readiness/readinessManager.d.ts +6 -0
  298. package/types/readiness/sdkReadinessManager.d.ts +11 -0
  299. package/types/readiness/types.d.ts +60 -0
  300. package/types/sdkClient/client.d.ts +6 -0
  301. package/types/sdkClient/clientAttributesDecoration.d.ts +51 -0
  302. package/types/sdkClient/clientCS.d.ts +10 -0
  303. package/types/sdkClient/clientInputValidation.d.ts +7 -0
  304. package/types/sdkClient/sdkClient.d.ts +6 -0
  305. package/types/sdkClient/sdkClientMethod.d.ts +6 -0
  306. package/types/sdkClient/sdkClientMethodCS.d.ts +7 -0
  307. package/types/sdkClient/sdkClientMethodCSWithTT.d.ts +8 -0
  308. package/types/sdkClient/types.d.ts +18 -0
  309. package/types/sdkFactory/index.d.ts +6 -0
  310. package/types/sdkFactory/types.d.ts +82 -0
  311. package/types/sdkManager/index.d.ts +5 -0
  312. package/types/services/splitApi.d.ts +11 -0
  313. package/types/services/splitHttpClient.d.ts +10 -0
  314. package/types/services/types.d.ts +54 -0
  315. package/types/storages/AbstractSegmentsCacheSync.d.ts +55 -0
  316. package/types/storages/AbstractSplitsCacheAsync.d.ts +37 -0
  317. package/types/storages/AbstractSplitsCacheSync.d.ts +42 -0
  318. package/types/storages/KeyBuilder.d.ts +14 -0
  319. package/types/storages/KeyBuilderCS.d.ts +16 -0
  320. package/types/storages/KeyBuilderSS.d.ts +17 -0
  321. package/types/storages/dataLoader.d.ts +10 -0
  322. package/types/storages/findLatencyIndex.d.ts +7 -0
  323. package/types/storages/inLocalStorage/MySegmentsCacheInLocal.d.ts +25 -0
  324. package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +51 -0
  325. package/types/storages/inLocalStorage/constants.d.ts +2 -0
  326. package/types/storages/inLocalStorage/index.d.ts +8 -0
  327. package/types/storages/inMemory/AttributesCacheInMemory.d.ts +43 -0
  328. package/types/storages/inMemory/CountsCacheInMemory.d.ts +20 -0
  329. package/types/storages/inMemory/EventsCacheInMemory.d.ts +35 -0
  330. package/types/storages/inMemory/ImpressionCountsCacheInMemory.d.ts +28 -0
  331. package/types/storages/inMemory/ImpressionsCacheInMemory.d.ts +30 -0
  332. package/types/storages/inMemory/InMemoryStorage.d.ts +10 -0
  333. package/types/storages/inMemory/InMemoryStorageCS.d.ts +10 -0
  334. package/types/storages/inMemory/LatenciesCacheInMemory.d.ts +20 -0
  335. package/types/storages/inMemory/MySegmentsCacheInMemory.d.ts +22 -0
  336. package/types/storages/inMemory/SegmentsCacheInMemory.d.ts +19 -0
  337. package/types/storages/inMemory/SplitsCacheInMemory.d.ts +21 -0
  338. package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +53 -0
  339. package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +35 -0
  340. package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +37 -0
  341. package/types/storages/inRedis/CountsCacheInRedis.d.ts +9 -0
  342. package/types/storages/inRedis/EventsCacheInRedis.d.ts +32 -0
  343. package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +14 -0
  344. package/types/storages/inRedis/ImpressionsCacheInRedis.d.ts +18 -0
  345. package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +9 -0
  346. package/types/storages/inRedis/RedisAdapter.d.ts +24 -0
  347. package/types/storages/inRedis/SegmentsCacheInRedis.d.ts +18 -0
  348. package/types/storages/inRedis/SplitsCacheInRedis.d.ts +92 -0
  349. package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +20 -0
  350. package/types/storages/inRedis/constants.d.ts +4 -0
  351. package/types/storages/inRedis/index.d.ts +10 -0
  352. package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +15 -0
  353. package/types/storages/metadataBuilder.d.ts +3 -0
  354. package/types/storages/pluggable/EventsCachePluggable.d.ts +38 -0
  355. package/types/storages/pluggable/ImpressionsCachePluggable.d.ts +35 -0
  356. package/types/storages/pluggable/SegmentsCachePluggable.d.ts +54 -0
  357. package/types/storages/pluggable/SplitsCachePluggable.d.ts +90 -0
  358. package/types/storages/pluggable/TelemetryCachePluggable.d.ts +18 -0
  359. package/types/storages/pluggable/constants.d.ts +1 -0
  360. package/types/storages/pluggable/inMemoryWrapper.d.ts +13 -0
  361. package/types/storages/pluggable/index.d.ts +9 -0
  362. package/types/storages/pluggable/wrapperAdapter.d.ts +12 -0
  363. package/types/storages/types.d.ts +417 -0
  364. package/types/sync/offline/LocalhostFromFile.d.ts +2 -0
  365. package/types/sync/offline/LocalhostFromObject.d.ts +2 -0
  366. package/types/sync/offline/splitsParser/parseCondition.d.ts +7 -0
  367. package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +2 -0
  368. package/types/sync/offline/splitsParser/splitsParserFromSettings.d.ts +3 -0
  369. package/types/sync/offline/splitsParser/types.d.ts +3 -0
  370. package/types/sync/offline/syncManagerOffline.d.ts +10 -0
  371. package/types/sync/offline/syncTasks/fromObjectSyncTask.d.ts +17 -0
  372. package/types/sync/polling/fetchers/mySegmentsFetcher.d.ts +7 -0
  373. package/types/sync/polling/fetchers/segmentChangesFetcher.d.ts +7 -0
  374. package/types/sync/polling/fetchers/splitChangesFetcher.d.ts +7 -0
  375. package/types/sync/polling/fetchers/types.d.ts +5 -0
  376. package/types/sync/polling/pollingManagerCS.d.ts +7 -0
  377. package/types/sync/polling/pollingManagerSS.d.ts +6 -0
  378. package/types/sync/polling/syncTasks/mySegmentsSyncTask.d.ts +9 -0
  379. package/types/sync/polling/syncTasks/segmentsSyncTask.d.ts +9 -0
  380. package/types/sync/polling/syncTasks/splitsSyncTask.d.ts +9 -0
  381. package/types/sync/polling/types.d.ts +26 -0
  382. package/types/sync/polling/updaters/mySegmentsUpdater.d.ts +13 -0
  383. package/types/sync/polling/updaters/segmentChangesUpdater.d.ts +18 -0
  384. package/types/sync/polling/updaters/splitChangesUpdater.d.ts +39 -0
  385. package/types/sync/streaming/AuthClient/index.d.ts +12 -0
  386. package/types/sync/streaming/AuthClient/types.d.ts +17 -0
  387. package/types/sync/streaming/SSEClient/index.d.ts +34 -0
  388. package/types/sync/streaming/SSEClient/types.d.ts +11 -0
  389. package/types/sync/streaming/SSEHandler/NotificationKeeper.d.ts +14 -0
  390. package/types/sync/streaming/SSEHandler/NotificationParser.d.ts +20 -0
  391. package/types/sync/streaming/SSEHandler/index.d.ts +11 -0
  392. package/types/sync/streaming/SSEHandler/types.d.ts +67 -0
  393. package/types/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.d.ts +6 -0
  394. package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +8 -0
  395. package/types/sync/streaming/UpdateWorkers/SplitsUpdateWorker.d.ts +12 -0
  396. package/types/sync/streaming/UpdateWorkers/constants.d.ts +3 -0
  397. package/types/sync/streaming/UpdateWorkers/types.d.ts +4 -0
  398. package/types/sync/streaming/constants.d.ts +34 -0
  399. package/types/sync/streaming/mySegmentsV2utils.d.ts +27 -0
  400. package/types/sync/streaming/pushManager.d.ts +9 -0
  401. package/types/sync/streaming/types.d.ts +35 -0
  402. package/types/sync/submitters/eventsSubmitter.d.ts +5 -0
  403. package/types/sync/submitters/eventsSyncTask.d.ts +8 -0
  404. package/types/sync/submitters/impressionCountsSubmitter.d.ts +10 -0
  405. package/types/sync/submitters/impressionCountsSubmitterInRedis.d.ts +5 -0
  406. package/types/sync/submitters/impressionCountsSyncTask.d.ts +13 -0
  407. package/types/sync/submitters/impressionsSubmitter.d.ts +11 -0
  408. package/types/sync/submitters/impressionsSyncTask.d.ts +14 -0
  409. package/types/sync/submitters/metricsSyncTask.d.ts +12 -0
  410. package/types/sync/submitters/submitter.d.ts +12 -0
  411. package/types/sync/submitters/submitterManager.d.ts +3 -0
  412. package/types/sync/submitters/submitterSyncTask.d.ts +10 -0
  413. package/types/sync/submitters/telemetrySubmitter.d.ts +25 -0
  414. package/types/sync/submitters/types.d.ts +194 -0
  415. package/types/sync/submitters/uniqueKeysSubmitter.d.ts +5 -0
  416. package/types/sync/submitters/uniqueKeysSubmitterInRedis.d.ts +5 -0
  417. package/types/sync/syncManagerOnline.d.ts +13 -0
  418. package/types/sync/syncTask.d.ts +13 -0
  419. package/types/sync/syncTaskComposite.d.ts +5 -0
  420. package/types/sync/types.d.ts +43 -0
  421. package/types/trackers/eventTracker.d.ts +10 -0
  422. package/types/trackers/filter/bloomFilter.d.ts +10 -0
  423. package/types/trackers/filter/dictionaryFilter.d.ts +8 -0
  424. package/types/trackers/filter/types.d.ts +5 -0
  425. package/types/trackers/impressionObserver/ImpressionObserver.d.ts +8 -0
  426. package/types/trackers/impressionObserver/buildKey.d.ts +2 -0
  427. package/types/trackers/impressionObserver/impressionObserverCS.d.ts +4 -0
  428. package/types/trackers/impressionObserver/impressionObserverSS.d.ts +4 -0
  429. package/types/trackers/impressionObserver/types.d.ts +4 -0
  430. package/types/trackers/impressionObserver/utils.d.ts +13 -0
  431. package/types/trackers/impressionsTracker.d.ts +13 -0
  432. package/types/trackers/strategy/strategyDebug.d.ts +9 -0
  433. package/types/trackers/strategy/strategyNone.d.ts +10 -0
  434. package/types/trackers/strategy/strategyOptimized.d.ts +11 -0
  435. package/types/trackers/telemetryTracker.d.ts +3 -0
  436. package/types/trackers/types.d.ts +63 -0
  437. package/types/trackers/uniqueKeysTracker.d.ts +13 -0
  438. package/types/types.d.ts +1265 -0
  439. package/types/utils/Backoff.d.ts +25 -0
  440. package/types/utils/LRUCache/LinkedList.d.ts +34 -0
  441. package/types/utils/LRUCache/index.d.ts +16 -0
  442. package/types/utils/MinEventEmitter.d.ts +12 -0
  443. package/types/utils/MinEvents.d.ts +4 -0
  444. package/types/utils/base64/index.d.ts +30 -0
  445. package/types/utils/constants/browser.d.ts +3 -0
  446. package/types/utils/constants/index.d.ts +64 -0
  447. package/types/utils/decompress/index.d.ts +16 -0
  448. package/types/utils/env/isLocalStorageAvailable.d.ts +1 -0
  449. package/types/utils/env/isNode.d.ts +5 -0
  450. package/types/utils/inputValidation/apiKey.d.ts +7 -0
  451. package/types/utils/inputValidation/attribute.d.ts +2 -0
  452. package/types/utils/inputValidation/attributes.d.ts +4 -0
  453. package/types/utils/inputValidation/event.d.ts +2 -0
  454. package/types/utils/inputValidation/eventProperties.d.ts +6 -0
  455. package/types/utils/inputValidation/eventValue.d.ts +2 -0
  456. package/types/utils/inputValidation/index.d.ts +13 -0
  457. package/types/utils/inputValidation/isOperational.d.ts +4 -0
  458. package/types/utils/inputValidation/key.d.ts +3 -0
  459. package/types/utils/inputValidation/preloadedData.d.ts +3 -0
  460. package/types/utils/inputValidation/split.d.ts +2 -0
  461. package/types/utils/inputValidation/splitExistance.d.ts +7 -0
  462. package/types/utils/inputValidation/splits.d.ts +2 -0
  463. package/types/utils/inputValidation/trafficType.d.ts +2 -0
  464. package/types/utils/inputValidation/trafficTypeExistance.d.ts +9 -0
  465. package/types/utils/jwt/index.d.ts +5 -0
  466. package/types/utils/jwt/types.d.ts +5 -0
  467. package/types/utils/key/index.d.ts +8 -0
  468. package/types/utils/labels/index.d.ts +7 -0
  469. package/types/utils/lang/binarySearch.d.ts +9 -0
  470. package/types/utils/lang/getFnName.d.ts +4 -0
  471. package/types/utils/lang/getGlobal.d.ts +4 -0
  472. package/types/utils/lang/index.d.ts +105 -0
  473. package/types/utils/lang/maps.d.ts +55 -0
  474. package/types/utils/lang/objectAssign.d.ts +3 -0
  475. package/types/utils/lang/sets.d.ts +60 -0
  476. package/types/utils/murmur3/common.d.ts +12 -0
  477. package/types/utils/murmur3/legacy.d.ts +2 -0
  478. package/types/utils/murmur3/murmur3.d.ts +2 -0
  479. package/types/utils/murmur3/murmur3_128.d.ts +6 -0
  480. package/types/utils/murmur3/murmur3_128_x86.d.ts +7 -0
  481. package/types/utils/murmur3/murmur3_64.d.ts +10 -0
  482. package/types/utils/murmur3/utfx.d.ts +27 -0
  483. package/types/utils/promise/thenable.d.ts +1 -0
  484. package/types/utils/promise/timeout.d.ts +1 -0
  485. package/types/utils/promise/wrapper.d.ts +21 -0
  486. package/types/utils/settingsValidation/consent.d.ts +6 -0
  487. package/types/utils/settingsValidation/impressionsMode.d.ts +3 -0
  488. package/types/utils/settingsValidation/index.d.ts +52 -0
  489. package/types/utils/settingsValidation/integrations/common.d.ts +14 -0
  490. package/types/utils/settingsValidation/integrations/configurable.d.ts +13 -0
  491. package/types/utils/settingsValidation/integrations/pluggable.d.ts +13 -0
  492. package/types/utils/settingsValidation/localhost/builtin.d.ts +16 -0
  493. package/types/utils/settingsValidation/localhost/pluggable.d.ts +16 -0
  494. package/types/utils/settingsValidation/logger/builtinLogger.d.ts +10 -0
  495. package/types/utils/settingsValidation/logger/commons.d.ts +9 -0
  496. package/types/utils/settingsValidation/logger/pluggableLogger.d.ts +11 -0
  497. package/types/utils/settingsValidation/mode.d.ts +1 -0
  498. package/types/utils/settingsValidation/runtime.d.ts +2 -0
  499. package/types/utils/settingsValidation/splitFilters.d.ts +16 -0
  500. package/types/utils/settingsValidation/storage/storageCS.d.ts +21 -0
  501. package/types/utils/settingsValidation/types.d.ts +32 -0
  502. package/types/utils/settingsValidation/url.d.ts +10 -0
  503. package/types/utils/time/index.d.ts +4 -0
  504. package/types/utils/timeTracker/index.d.ts +70 -0
  505. package/types/utils/timeTracker/now/browser.d.ts +1 -0
  506. package/types/utils/timeTracker/now/node.d.ts +1 -0
  507. package/types/utils/timeTracker/timer.d.ts +1 -0
  508. package/src/logger/.DS_Store +0 -0
  509. package/src/types.d.ts +0 -1581
@@ -0,0 +1,82 @@
1
+ import { IUniqueKeysCacheBase } from '../types';
2
+ import { ISet, setToArray, _Set } from '../../utils/lang/sets';
3
+ import { UniqueKeysPayloadSs } from '../../sync/submitters/types';
4
+ import { DEFAULT_CACHE_SIZE } from '../inRedis/constants';
5
+
6
+ export class UniqueKeysCacheInMemory implements IUniqueKeysCacheBase {
7
+
8
+ protected onFullQueue?: () => void;
9
+ private readonly maxStorage: number;
10
+ private uniqueTrackerSize = 0;
11
+ protected uniqueKeysTracker: { [keys: string]: ISet<string> };
12
+
13
+ constructor(uniqueKeysQueueSize: number = DEFAULT_CACHE_SIZE) {
14
+ this.maxStorage = uniqueKeysQueueSize;
15
+ this.uniqueKeysTracker = {};
16
+ }
17
+
18
+ setOnFullQueueCb(cb: () => void) {
19
+ this.onFullQueue = cb;
20
+ }
21
+
22
+ /**
23
+ * Store unique keys in sequential order
24
+ * key: string = feature name.
25
+ * value: Set<string> = set of unique keys.
26
+ */
27
+ track(key: string, featureName: string) {
28
+ if (!this.uniqueKeysTracker[featureName]) this.uniqueKeysTracker[featureName] = new _Set();
29
+ const tracker = this.uniqueKeysTracker[featureName];
30
+ if (!tracker.has(key)) {
31
+ tracker.add(key);
32
+ this.uniqueTrackerSize++;
33
+ }
34
+ if (this.uniqueTrackerSize >= this.maxStorage && this.onFullQueue) {
35
+ this.uniqueTrackerSize = 0;
36
+ this.onFullQueue();
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Clear the data stored on the cache.
42
+ */
43
+ clear() {
44
+ this.uniqueKeysTracker = {};
45
+ }
46
+
47
+ /**
48
+ * Pop the collected data, used as payload for posting.
49
+ */
50
+ pop() {
51
+ const data = this.uniqueKeysTracker;
52
+ this.uniqueKeysTracker = {};
53
+ return this.fromUniqueKeysCollector(data);
54
+ }
55
+
56
+ /**
57
+ * Check if the cache is empty.
58
+ */
59
+ isEmpty() {
60
+ return Object.keys(this.uniqueKeysTracker).length === 0;
61
+ }
62
+
63
+ /**
64
+ * Converts `uniqueKeys` data from cache into request payload for SS.
65
+ */
66
+ private fromUniqueKeysCollector(uniqueKeys: { [featureName: string]: ISet<string> }): UniqueKeysPayloadSs {
67
+ const payload = [];
68
+ const featureNames = Object.keys(uniqueKeys);
69
+ for (let i = 0; i < featureNames.length; i++) {
70
+ const featureName = featureNames[i];
71
+ const featureKeys = setToArray(uniqueKeys[featureName]);
72
+ const uniqueKeysPayload = {
73
+ f: featureName,
74
+ ks: featureKeys
75
+ };
76
+
77
+ payload.push(uniqueKeysPayload);
78
+ }
79
+ return { keys: payload };
80
+ }
81
+
82
+ }
@@ -0,0 +1,88 @@
1
+ import { IUniqueKeysCacheBase } from '../types';
2
+ import { ISet, setToArray, _Set } from '../../utils/lang/sets';
3
+ import { UniqueKeysPayloadCs } from '../../sync/submitters/types';
4
+ import { DEFAULT_CACHE_SIZE } from '../inRedis/constants';
5
+
6
+ export class UniqueKeysCacheInMemoryCS implements IUniqueKeysCacheBase {
7
+
8
+ private onFullQueue?: () => void;
9
+ private readonly maxStorage: number;
10
+ private uniqueTrackerSize = 0;
11
+ private uniqueKeysTracker: { [keys: string]: ISet<string> };
12
+
13
+ /**
14
+ *
15
+ * @param impressionsQueueSize number of queued impressions to call onFullQueueCb.
16
+ * Default value is 0, that means no maximum value, in case we want to avoid this being triggered.
17
+ */
18
+ constructor(uniqueKeysQueueSize: number = DEFAULT_CACHE_SIZE) {
19
+ this.maxStorage = uniqueKeysQueueSize;
20
+ this.uniqueKeysTracker = {};
21
+ }
22
+
23
+ setOnFullQueueCb(cb: () => void) {
24
+ this.onFullQueue = cb;
25
+ }
26
+
27
+ /**
28
+ * Store unique keys in sequential order
29
+ * key: string = key.
30
+ * value: HashSet<string> = set of split names.
31
+ */
32
+ track(key: string, featureName: string) {
33
+
34
+ if (!this.uniqueKeysTracker[key]) this.uniqueKeysTracker[key] = new _Set();
35
+ const tracker = this.uniqueKeysTracker[key];
36
+ if (!tracker.has(featureName)) {
37
+ tracker.add(featureName);
38
+ this.uniqueTrackerSize++;
39
+ }
40
+ if (this.uniqueTrackerSize >= this.maxStorage && this.onFullQueue) {
41
+ this.uniqueTrackerSize = 0;
42
+ this.onFullQueue();
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Clear the data stored on the cache.
48
+ */
49
+ clear() {
50
+ this.uniqueKeysTracker = {};
51
+ }
52
+
53
+ /**
54
+ * Pop the collected data, used as payload for posting.
55
+ */
56
+ pop() {
57
+ const data = this.uniqueKeysTracker;
58
+ this.uniqueKeysTracker = {};
59
+ return this.fromUniqueKeysCollector(data);
60
+ }
61
+
62
+ /**
63
+ * Check if the cache is empty.
64
+ */
65
+ isEmpty() {
66
+ return Object.keys(this.uniqueKeysTracker).length === 0;
67
+ }
68
+
69
+ /**
70
+ * Converts `uniqueKeys` data from cache into request payload.
71
+ */
72
+ private fromUniqueKeysCollector(uniqueKeys: { [featureName: string]: ISet<string> }): UniqueKeysPayloadCs {
73
+ const payload = [];
74
+ const featureKeys = Object.keys(uniqueKeys);
75
+ for (let k = 0; k < featureKeys.length; k++) {
76
+ const featureKey = featureKeys[k];
77
+ const featureNames = setToArray(uniqueKeys[featureKey]);
78
+ const uniqueKeysPayload = {
79
+ k: featureKey,
80
+ fs: featureNames
81
+ };
82
+
83
+ payload.push(uniqueKeysPayload);
84
+ }
85
+ return { keys: payload };
86
+ }
87
+
88
+ }
@@ -1,8 +1,8 @@
1
1
  import { IEventsCacheAsync } from '../types';
2
2
  import { IMetadata } from '../../dtos/types';
3
3
  import { Redis } from 'ioredis';
4
- import { EventData } from '../../types';
5
- import { ILogger } from '../../types';
4
+ import { SplitIO } from '../../types';
5
+ import { ILogger } from '../../logger/types';
6
6
  import { LOG_PREFIX } from './constants';
7
7
  import { StoredEventWithMetadata } from '../../sync/submitters/types';
8
8
 
@@ -24,7 +24,7 @@ export class EventsCacheInRedis implements IEventsCacheAsync {
24
24
  * Add a new event object into the queue.
25
25
  * Unlike `impressions::track`, result promise is never rejected.
26
26
  */
27
- track(eventData: EventData): Promise<boolean> {
27
+ track(eventData: SplitIO.EventData): Promise<boolean> {
28
28
  return this.redis.rpush(
29
29
  this.key,
30
30
  this._toJSON(eventData)
@@ -40,7 +40,7 @@ export class EventsCacheInRedis implements IEventsCacheAsync {
40
40
  /**
41
41
  * Generates the JSON as we'll store it on Redis.
42
42
  */
43
- private _toJSON(eventData: EventData): string {
43
+ private _toJSON(eventData: SplitIO.EventData): string {
44
44
  return JSON.stringify({
45
45
  m: this.metadata,
46
46
  e: eventData
@@ -0,0 +1,51 @@
1
+ import { Redis } from 'ioredis';
2
+ import { ILogger } from '../../logger/types';
3
+ import { ImpressionCountsCacheInMemory } from '../inMemory/ImpressionCountsCacheInMemory';
4
+ import { LOG_PREFIX, REFRESH_RATE, TTL_REFRESH } from './constants';
5
+
6
+ export class ImpressionCountsCacheInRedis extends ImpressionCountsCacheInMemory {
7
+
8
+ private readonly log: ILogger;
9
+ private readonly key: string;
10
+ private readonly redis: Redis;
11
+ private readonly refreshRate: number;
12
+ private intervalId: any;
13
+
14
+ constructor(log: ILogger, key: string, redis: Redis, impressionCountsCacheSize?: number, refreshRate: number = REFRESH_RATE) {
15
+ super(impressionCountsCacheSize);
16
+ this.log = log;
17
+ this.key = key;
18
+ this.redis = redis;
19
+ this.refreshRate = refreshRate;
20
+ this.onFullQueue = () => { this.postImpressionCountsInRedis(); };
21
+ }
22
+
23
+ postImpressionCountsInRedis(){
24
+ const counts = this.pop();
25
+ if (!counts) return false;
26
+ const keys = Object.keys(counts);
27
+ const pipeline = this.redis.pipeline();
28
+ keys.forEach(key => {
29
+ pipeline.hincrby(this.key, key, counts[key]);
30
+ });
31
+ return pipeline.exec()
32
+ .then(data => {
33
+ // If this is the creation of the key on Redis, set the expiration for it in 3600 seconds.
34
+ if (data.length && data.length === keys.length) {
35
+ return this.redis.expire(this.key, TTL_REFRESH);
36
+ }
37
+ })
38
+ .catch(err => {
39
+ this.log.error(`${LOG_PREFIX}Error in impression counts pipeline: ${err}.`);
40
+ return false;
41
+ });
42
+ }
43
+
44
+ start() {
45
+ this.intervalId = setInterval(this.postImpressionCountsInRedis.bind(this), this.refreshRate);
46
+ }
47
+
48
+ stop() {
49
+ clearInterval(this.intervalId);
50
+ }
51
+ }
@@ -3,7 +3,7 @@ import { IMetadata } from '../../dtos/types';
3
3
  import { ImpressionDTO } from '../../types';
4
4
  import { Redis } from 'ioredis';
5
5
  import { StoredImpressionWithMetadata } from '../../sync/submitters/types';
6
- import { ILogger } from '../../types';
6
+ import { ILogger } from '../../logger/types';
7
7
 
8
8
  const IMPRESSIONS_TTL_REFRESH = 3600; // 1 hr
9
9
 
@@ -1,5 +1,5 @@
1
1
  import ioredis from 'ioredis';
2
- import { ILogger } from '../../types';
2
+ import { ILogger } from '../../logger/types';
3
3
  import { merge, isString } from '../../utils/lang';
4
4
  import { _Set, setToArray, ISet } from '../../utils/lang/sets';
5
5
  import { thenable } from '../../utils/promise/thenable';
@@ -1,5 +1,5 @@
1
1
  import { Redis } from 'ioredis';
2
- import { ILogger } from '../../types';
2
+ import { ILogger } from '../../logger/types';
3
3
  import { isNaNNumber } from '../../utils/lang';
4
4
  import { LOG_PREFIX } from '../inLocalStorage/constants';
5
5
  import { KeyBuilderSS } from '../KeyBuilderSS';
@@ -1,7 +1,7 @@
1
1
  import { isFiniteNumber, isNaNNumber } from '../../utils/lang';
2
2
  import { KeyBuilderSS } from '../KeyBuilderSS';
3
3
  import { Redis } from 'ioredis';
4
- import { ILogger } from '../../types';
4
+ import { ILogger } from '../../logger/types';
5
5
  import { LOG_PREFIX } from './constants';
6
6
  import { ISplit } from '../../dtos/types';
7
7
  import { AbstractSplitsCacheAsync } from '../AbstractSplitsCacheAsync';
@@ -65,22 +65,22 @@ export class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
65
65
  * The returned promise is resolved when the operation success
66
66
  * or rejected if it fails (e.g., redis operation fails)
67
67
  */
68
- addSplit(name: string, split: string): Promise<boolean> {
68
+ addSplit(name: string, split: ISplit): Promise<boolean> {
69
69
  const splitKey = this.keys.buildSplitKey(name);
70
70
  return this.redis.get(splitKey).then(splitFromStorage => {
71
71
 
72
72
  // handling parsing errors
73
- let parsedPreviousSplit, parsedSplit;
73
+ let parsedPreviousSplit, newStringifiedSplit;
74
74
  try {
75
75
  parsedPreviousSplit = splitFromStorage ? JSON.parse(splitFromStorage) : undefined;
76
- parsedSplit = JSON.parse(split);
76
+ newStringifiedSplit = JSON.stringify(split);
77
77
  } catch (e) {
78
78
  throw new Error('Error parsing split definition: ' + e);
79
79
  }
80
80
 
81
81
  return Promise.all([
82
- this.redis.set(splitKey, split),
83
- this._incrementCounts(parsedSplit),
82
+ this.redis.set(splitKey, newStringifiedSplit),
83
+ this._incrementCounts(split),
84
84
  // If it's an update, we decrement the traffic type of the existing split,
85
85
  parsedPreviousSplit && this._decrementCounts(parsedPreviousSplit)
86
86
  ]);
@@ -92,7 +92,7 @@ export class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
92
92
  * The returned promise is resolved when the operation success
93
93
  * or rejected if it fails (e.g., redis operation fails)
94
94
  */
95
- addSplits(entries: [string, string][]): Promise<boolean[]> {
95
+ addSplits(entries: [string, ISplit][]): Promise<boolean[]> {
96
96
  return Promise.all(entries.map(keyValuePair => this.addSplit(keyValuePair[0], keyValuePair[1])));
97
97
  }
98
98
 
@@ -104,8 +104,7 @@ export class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
104
104
  removeSplit(name: string): Promise<number> {
105
105
  return this.getSplit(name).then((split) => {
106
106
  if (split) {
107
- const parsedSplit = JSON.parse(split);
108
- this._decrementCounts(parsedSplit);
107
+ this._decrementCounts(split);
109
108
  }
110
109
  return this.redis.del(this.keys.buildSplitKey(name));
111
110
  });
@@ -124,14 +123,15 @@ export class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
124
123
  * Get split definition or null if it's not defined.
125
124
  * Returned promise is rejected if redis operation fails.
126
125
  */
127
- getSplit(name: string): Promise<string | null> {
126
+ getSplit(name: string): Promise<ISplit | null> {
128
127
  if (this.redisError) {
129
128
  this.log.error(LOG_PREFIX + this.redisError);
130
129
 
131
130
  return Promise.reject(this.redisError);
132
131
  }
133
132
 
134
- return this.redis.get(this.keys.buildSplitKey(name));
133
+ return this.redis.get(this.keys.buildSplitKey(name))
134
+ .then(maybeSplit => maybeSplit && JSON.parse(maybeSplit));
135
135
  }
136
136
 
137
137
  /**
@@ -169,10 +169,13 @@ export class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
169
169
  * @TODO we need to benchmark which is the maximun number of commands we could
170
170
  * pipeline without kill redis performance.
171
171
  */
172
- getAll(): Promise<string[]> {
173
- return this.redis.keys(this.keys.searchPatternForSplitKeys()).then(
174
- (listOfKeys) => this.redis.pipeline(listOfKeys.map(k => ['get', k])).exec()
175
- ).then(processPipelineAnswer);
172
+ getAll(): Promise<ISplit[]> {
173
+ return this.redis.keys(this.keys.searchPatternForSplitKeys())
174
+ .then((listOfKeys) => this.redis.pipeline(listOfKeys.map(k => ['get', k])).exec())
175
+ .then(processPipelineAnswer)
176
+ .then((splitDefinitions) => splitDefinitions.map((splitDefinition) => {
177
+ return JSON.parse(splitDefinition as string);
178
+ }));
176
179
  }
177
180
 
178
181
  /**
@@ -226,19 +229,20 @@ export class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
226
229
  * Fetches multiple splits definitions.
227
230
  * Returned promise is rejected if redis operation fails.
228
231
  */
229
- getSplits(names: string[]): Promise<Record<string, string | null>> {
232
+ getSplits(names: string[]): Promise<Record<string, ISplit | null>> {
230
233
  if (this.redisError) {
231
234
  this.log.error(LOG_PREFIX + this.redisError);
232
235
 
233
236
  return Promise.reject(this.redisError);
234
237
  }
235
238
 
236
- const splits: Record<string, string | null> = {};
239
+ const splits: Record<string, ISplit | null> = {};
237
240
  const keys = names.map(name => this.keys.buildSplitKey(name));
238
241
  return this.redis.mget(...keys)
239
242
  .then(splitDefinitions => {
240
243
  names.forEach((name, idx) => {
241
- splits[name] = splitDefinitions[idx];
244
+ const split = splitDefinitions[idx];
245
+ splits[name] = split && JSON.parse(split);
242
246
  });
243
247
  return Promise.resolve(splits);
244
248
  })
@@ -1,4 +1,4 @@
1
- import { ILogger } from '../../types';
1
+ import { ILogger } from '../../logger/types';
2
2
  import { Method } from '../../sync/submitters/types';
3
3
  import { KeyBuilderSS } from '../KeyBuilderSS';
4
4
  import { ITelemetryCacheAsync } from '../types';
@@ -1 +1,4 @@
1
1
  export const LOG_PREFIX = 'storage:redis: ';
2
+ export const DEFAULT_CACHE_SIZE = 30000;
3
+ export const REFRESH_RATE = 300000; // 300.000 ms = start after 5 mins
4
+ export const TTL_REFRESH = 3600; // 1hr
@@ -1,14 +1,15 @@
1
1
  import { RedisAdapter } from './RedisAdapter';
2
- import { IStorageAsync, IStorageFactoryParams } from '../types';
3
- import { StorageAsyncFactory } from '../../types';
2
+ import { IStorageAsync, IStorageAsyncFactory, IStorageFactoryParams } from '../types';
4
3
  import { validatePrefix } from '../KeyBuilder';
5
4
  import { KeyBuilderSS } from '../KeyBuilderSS';
6
5
  import { SplitsCacheInRedis } from './SplitsCacheInRedis';
7
6
  import { SegmentsCacheInRedis } from './SegmentsCacheInRedis';
8
7
  import { ImpressionsCacheInRedis } from './ImpressionsCacheInRedis';
9
8
  import { EventsCacheInRedis } from './EventsCacheInRedis';
10
- import { STORAGE_REDIS } from '../../utils/constants';
9
+ import { DEBUG, NONE, STORAGE_REDIS } from '../../utils/constants';
11
10
  import { TelemetryCacheInRedis } from './TelemetryCacheInRedis';
11
+ import { UniqueKeysCacheInRedis } from './uniqueKeysCacheInRedis';
12
+ import { ImpressionCountsCacheInRedis } from './ImpressionCountsCacheInRedis';
12
13
 
13
14
  export interface InRedisStorageOptions {
14
15
  prefix?: string
@@ -19,19 +20,22 @@ export interface InRedisStorageOptions {
19
20
  * InRedis storage factory for consumer server-side SplitFactory, that uses `Ioredis` Redis client for Node.
20
21
  * @see {@link https://www.npmjs.com/package/ioredis}
21
22
  */
22
- export function InRedisStorage(options: InRedisStorageOptions = {}): StorageAsyncFactory {
23
+ export function InRedisStorage(options: InRedisStorageOptions = {}): IStorageAsyncFactory {
23
24
 
24
25
  const prefix = validatePrefix(options.prefix);
25
26
 
26
- function InRedisStorageFactory({ log, metadata, onReadyCb }: IStorageFactoryParams): IStorageAsync {
27
-
27
+ function InRedisStorageFactory({ log, metadata, onReadyCb, impressionsMode, impressionCountsQueueSize, impressionCountsRefreshRate, uniqueKeysCacheSize, uniqueKeysRefreshRate }: IStorageFactoryParams): IStorageAsync {
28
28
  const keys = new KeyBuilderSS(prefix, metadata);
29
29
  const redisClient = new RedisAdapter(log, options.options || {});
30
30
  const telemetry = new TelemetryCacheInRedis(log, keys, redisClient);
31
+ const impressionCountsCache = impressionsMode !== DEBUG ? new ImpressionCountsCacheInRedis(log, keys.buildImpressionsCountKey(), redisClient, impressionCountsQueueSize, impressionCountsRefreshRate) : undefined;
32
+ const uniqueKeysCache = impressionsMode === NONE ? new UniqueKeysCacheInRedis(log, keys.buildUniqueKeysKey(), redisClient, uniqueKeysCacheSize, uniqueKeysRefreshRate) : undefined;
31
33
 
32
34
  // subscription to Redis connect event in order to emit SDK_READY event on consumer mode
33
35
  redisClient.on('connect', () => {
34
36
  onReadyCb();
37
+ if (impressionCountsCache) impressionCountsCache.start();
38
+ if (uniqueKeysCache) uniqueKeysCache.start();
35
39
 
36
40
  // Synchronize config
37
41
  telemetry.recordConfig();
@@ -41,13 +45,17 @@ export function InRedisStorage(options: InRedisStorageOptions = {}): StorageAsyn
41
45
  splits: new SplitsCacheInRedis(log, keys, redisClient),
42
46
  segments: new SegmentsCacheInRedis(log, keys, redisClient),
43
47
  impressions: new ImpressionsCacheInRedis(log, keys.buildImpressionsKey(), redisClient, metadata),
48
+ impressionCounts: impressionCountsCache,
44
49
  events: new EventsCacheInRedis(log, keys.buildEventsKey(), redisClient, metadata),
45
50
  telemetry,
51
+ uniqueKeys: uniqueKeysCache,
46
52
 
47
53
  // When using REDIS we should:
48
54
  // 1- Disconnect from the storage
49
55
  destroy() {
50
56
  redisClient.disconnect();
57
+ if (impressionCountsCache) impressionCountsCache.stop();
58
+ if (uniqueKeysCache) uniqueKeysCache.stop();
51
59
  // @TODO check that caches works as expected when redisClient is disconnected
52
60
  }
53
61
  };
@@ -0,0 +1,63 @@
1
+ import { IUniqueKeysCacheBase } from '../types';
2
+ import { Redis } from 'ioredis';
3
+ import { UniqueKeysCacheInMemory } from '../inMemory/uniqueKeysCacheInMemory';
4
+ import { setToArray } from '../../utils/lang/sets';
5
+ import { DEFAULT_CACHE_SIZE, REFRESH_RATE, TTL_REFRESH } from './constants';
6
+ import { LOG_PREFIX } from './constants';
7
+ import { ILogger } from '../../logger/types';
8
+
9
+ export class UniqueKeysCacheInRedis extends UniqueKeysCacheInMemory implements IUniqueKeysCacheBase {
10
+
11
+ private readonly log: ILogger;
12
+ private readonly key: string;
13
+ private readonly redis: Redis;
14
+ private readonly refreshRate: number;
15
+ private intervalId: any;
16
+
17
+ constructor(log: ILogger, key: string, redis: Redis, uniqueKeysQueueSize: number = DEFAULT_CACHE_SIZE, refreshRate: number = REFRESH_RATE) {
18
+ super(uniqueKeysQueueSize);
19
+ this.log = log;
20
+ this.key = key;
21
+ this.redis = redis;
22
+ this.refreshRate = refreshRate;
23
+ this.onFullQueue = () => {this.postUniqueKeysInRedis();};
24
+ }
25
+
26
+ postUniqueKeysInRedis() {
27
+ const pipeline = this.redis.pipeline();
28
+
29
+ const featureNames = Object.keys(this.uniqueKeysTracker);
30
+ for (let i = 0; i < featureNames.length; i++) {
31
+ const featureName = featureNames[i];
32
+ const featureKeys = setToArray(this.uniqueKeysTracker[featureName]);
33
+ const uniqueKeysPayload = {
34
+ f: featureName,
35
+ ks: featureKeys
36
+ };
37
+
38
+ pipeline.rpush(this.key, JSON.stringify(uniqueKeysPayload));
39
+ }
40
+ this.clear();
41
+ return pipeline.exec()
42
+ .then(data => {
43
+ // If this is the creation of the key on Redis, set the expiration for it in 3600 seconds.
44
+ if (data.length && data.length === featureNames.length) {
45
+ return this.redis.expire(this.key, TTL_REFRESH);
46
+ }
47
+ })
48
+ .catch(err => {
49
+ this.log.error(`${LOG_PREFIX}Error in uniqueKeys pipeline: ${err}.`);
50
+ return false;
51
+ });
52
+ }
53
+
54
+
55
+ start() {
56
+ this.intervalId = setInterval(this.postUniqueKeysInRedis.bind(this), this.refreshRate);
57
+ }
58
+
59
+ stop() {
60
+ clearInterval(this.intervalId);
61
+ }
62
+
63
+ }
@@ -1,7 +1,7 @@
1
1
  import { IPluggableStorageWrapper, IEventsCacheAsync } from '../types';
2
2
  import { IMetadata } from '../../dtos/types';
3
- import { EventData } from '../../types';
4
- import { ILogger } from '../../types';
3
+ import { SplitIO } from '../../types';
4
+ import { ILogger } from '../../logger/types';
5
5
  import { LOG_PREFIX } from './constants';
6
6
  import { StoredEventWithMetadata } from '../../sync/submitters/types';
7
7
 
@@ -25,7 +25,7 @@ export class EventsCachePluggable implements IEventsCacheAsync {
25
25
  * @returns A promise that is resolved with a boolean value indicating if the push operation succeeded or failed.
26
26
  * Unlike `impressions::track`, The promise will never be rejected.
27
27
  */
28
- track(eventData: EventData): Promise<boolean> {
28
+ track(eventData: SplitIO.EventData): Promise<boolean> {
29
29
  return this.wrapper.pushItems(
30
30
  this.key,
31
31
  [this._toJSON(eventData)]
@@ -38,7 +38,7 @@ export class EventsCachePluggable implements IEventsCacheAsync {
38
38
  });
39
39
  }
40
40
 
41
- private _toJSON(eventData: EventData): string {
41
+ private _toJSON(eventData: SplitIO.EventData): string {
42
42
  return JSON.stringify({
43
43
  m: this.metadata,
44
44
  e: eventData
@@ -1,7 +1,7 @@
1
1
  import { IPluggableStorageWrapper, IImpressionsCacheAsync } from '../types';
2
2
  import { IMetadata } from '../../dtos/types';
3
3
  import { ImpressionDTO } from '../../types';
4
- import { ILogger } from '../../types';
4
+ import { ILogger } from '../../logger/types';
5
5
  import { StoredImpressionWithMetadata } from '../../sync/submitters/types';
6
6
 
7
7
  export class ImpressionsCachePluggable implements IImpressionsCacheAsync {
@@ -3,7 +3,7 @@
3
3
  import { isNaNNumber } from '../../utils/lang';
4
4
  import { KeyBuilderSS } from '../KeyBuilderSS';
5
5
  import { IPluggableStorageWrapper, ISegmentsCacheAsync } from '../types';
6
- import { ILogger } from '../../types';
6
+ import { ILogger } from '../../logger/types';
7
7
  import { LOG_PREFIX } from './constants';
8
8
  import { _Set } from '../../utils/lang/sets';
9
9