@splitsoftware/splitio-commons 1.2.0 → 1.2.1-rc.10

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 (376) hide show
  1. package/cjs/evaluator/Engine.js +6 -6
  2. package/cjs/evaluator/combiners/and.js +1 -1
  3. package/cjs/evaluator/combiners/ifelseif.js +2 -2
  4. package/cjs/evaluator/condition/engineUtils.js +2 -2
  5. package/cjs/evaluator/condition/index.js +4 -4
  6. package/cjs/evaluator/index.js +5 -5
  7. package/cjs/evaluator/matchers/cont_all.js +1 -1
  8. package/cjs/evaluator/matchers/cont_any.js +1 -1
  9. package/cjs/evaluator/matchers/cont_str.js +1 -1
  10. package/cjs/evaluator/matchers/dependency.js +1 -1
  11. package/cjs/evaluator/matchers/eq_set.js +1 -1
  12. package/cjs/evaluator/matchers/ew.js +3 -3
  13. package/cjs/evaluator/matchers/part_of.js +1 -1
  14. package/cjs/evaluator/matchers/segment.js +1 -1
  15. package/cjs/evaluator/matchers/sw.js +1 -1
  16. package/cjs/evaluator/matchers/whitelist.js +1 -1
  17. package/cjs/evaluator/matchersTransform/index.js +12 -12
  18. package/cjs/evaluator/parser/index.js +6 -6
  19. package/cjs/evaluator/treatments/index.js +1 -1
  20. package/cjs/evaluator/value/index.js +1 -1
  21. package/cjs/evaluator/value/sanitize.js +4 -4
  22. package/cjs/integrations/browser.js +3 -3
  23. package/cjs/integrations/ga/GaToSplit.js +14 -14
  24. package/cjs/integrations/ga/GoogleAnalyticsToSplit.js +5 -3
  25. package/cjs/integrations/ga/SplitToGa.js +1 -1
  26. package/cjs/integrations/ga/SplitToGoogleAnalytics.js +4 -2
  27. package/cjs/listeners/browser.js +15 -11
  28. package/cjs/listeners/node.js +1 -1
  29. package/cjs/logger/constants.js +8 -3
  30. package/cjs/logger/index.js +2 -2
  31. package/cjs/logger/messages/debug.js +4 -4
  32. package/cjs/logger/messages/error.js +5 -4
  33. package/cjs/logger/messages/info.js +10 -8
  34. package/cjs/logger/messages/warn.js +1 -1
  35. package/cjs/logger/sdkLogger.js +1 -1
  36. package/cjs/readiness/readinessManager.js +2 -2
  37. package/cjs/readiness/sdkReadinessManager.js +4 -4
  38. package/cjs/sdkClient/client.js +13 -11
  39. package/cjs/sdkClient/clientAttributesDecoration.js +4 -4
  40. package/cjs/sdkClient/clientCS.js +4 -3
  41. package/cjs/sdkClient/clientInputValidation.js +20 -22
  42. package/cjs/sdkClient/sdkClient.js +3 -6
  43. package/cjs/sdkClient/sdkClientMethod.js +1 -1
  44. package/cjs/sdkClient/sdkClientMethodCS.js +6 -10
  45. package/cjs/sdkClient/sdkClientMethodCSWithTT.js +7 -15
  46. package/cjs/sdkFactory/index.js +14 -12
  47. package/cjs/sdkFactory/userConsentProps.js +37 -0
  48. package/cjs/sdkManager/index.js +11 -11
  49. package/cjs/services/splitApi.js +3 -2
  50. package/cjs/services/splitHttpClient.js +3 -3
  51. package/cjs/storages/KeyBuilder.js +2 -6
  52. package/cjs/storages/KeyBuilderCS.js +13 -3
  53. package/cjs/storages/KeyBuilderSS.js +1 -1
  54. package/cjs/storages/findLatencyIndex.js +1 -1
  55. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +24 -4
  56. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +12 -12
  57. package/cjs/storages/inLocalStorage/index.js +4 -4
  58. package/cjs/storages/inMemory/AttributesCacheInMemory.js +1 -1
  59. package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
  60. package/cjs/storages/inMemory/ImpressionsCacheInMemory.js +15 -1
  61. package/cjs/storages/inMemory/InMemoryStorage.js +1 -1
  62. package/cjs/storages/inMemory/InMemoryStorageCS.js +1 -1
  63. package/cjs/storages/inMemory/LatenciesCacheInMemory.js +1 -1
  64. package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +1 -1
  65. package/cjs/storages/inMemory/SegmentsCacheInMemory.js +2 -2
  66. package/cjs/storages/inMemory/SplitsCacheInMemory.js +5 -5
  67. package/cjs/storages/inRedis/LatenciesCacheInRedis.js +1 -1
  68. package/cjs/storages/inRedis/RedisAdapter.js +24 -11
  69. package/cjs/storages/inRedis/SegmentsCacheInRedis.js +1 -1
  70. package/cjs/storages/inRedis/SplitsCacheInRedis.js +3 -3
  71. package/cjs/storages/inRedis/index.js +1 -1
  72. package/cjs/storages/pluggable/SegmentsCachePluggable.js +1 -1
  73. package/cjs/storages/pluggable/SplitsCachePluggable.js +3 -3
  74. package/cjs/storages/pluggable/inMemoryWrapper.js +4 -4
  75. package/cjs/storages/pluggable/index.js +6 -6
  76. package/cjs/sync/offline/LocalhostFromFile.js +1 -1
  77. package/cjs/sync/offline/LocalhostFromObject.js +1 -1
  78. package/cjs/sync/offline/splitsParser/parseCondition.js +1 -1
  79. package/cjs/sync/offline/splitsParser/splitsParserFromFile.js +13 -13
  80. package/cjs/sync/offline/splitsParser/splitsParserFromSettings.js +3 -3
  81. package/cjs/sync/offline/syncManagerOffline.js +1 -1
  82. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +2 -2
  83. package/cjs/sync/polling/fetchers/mySegmentsFetcher.js +2 -2
  84. package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
  85. package/cjs/sync/polling/pollingManagerCS.js +8 -7
  86. package/cjs/sync/polling/pollingManagerSS.js +5 -4
  87. package/cjs/sync/polling/syncTasks/mySegmentsSyncTask.js +1 -1
  88. package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +1 -1
  89. package/cjs/sync/polling/syncTasks/splitsSyncTask.js +1 -1
  90. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +3 -3
  91. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +2 -2
  92. package/cjs/sync/polling/updaters/splitChangesUpdater.js +2 -2
  93. package/cjs/sync/streaming/AuthClient/index.js +4 -5
  94. package/cjs/sync/streaming/SSEClient/index.js +2 -1
  95. package/cjs/sync/streaming/SSEHandler/NotificationParser.js +1 -1
  96. package/cjs/sync/streaming/SSEHandler/index.js +3 -3
  97. package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +1 -1
  98. package/cjs/sync/streaming/mySegmentsV2utils.js +1 -1
  99. package/cjs/sync/streaming/pushManager.js +46 -35
  100. package/cjs/sync/submitters/eventsSyncTask.js +17 -5
  101. package/cjs/sync/submitters/impressionCountsSyncTask.js +1 -1
  102. package/cjs/sync/submitters/impressionsSyncTask.js +15 -3
  103. package/cjs/sync/submitters/metricsSyncTask.js +3 -3
  104. package/cjs/sync/submitters/submitterManager.js +6 -5
  105. package/cjs/sync/submitters/submitterSyncTask.js +1 -1
  106. package/cjs/sync/syncManagerOnline.js +21 -17
  107. package/cjs/trackers/eventTracker.js +11 -4
  108. package/cjs/trackers/impressionObserver/impressionObserverCS.js +1 -1
  109. package/cjs/trackers/impressionObserver/impressionObserverSS.js +1 -1
  110. package/cjs/trackers/impressionObserver/utils.js +8 -1
  111. package/cjs/trackers/impressionsTracker.js +9 -8
  112. package/cjs/utils/MinEvents.js +2 -1
  113. package/cjs/utils/consent.js +10 -0
  114. package/cjs/utils/constants/index.js +5 -1
  115. package/cjs/utils/inputValidation/apiKey.js +1 -1
  116. package/cjs/utils/inputValidation/attribute.js +4 -4
  117. package/cjs/utils/inputValidation/attributes.js +2 -2
  118. package/cjs/utils/inputValidation/event.js +1 -1
  119. package/cjs/utils/inputValidation/eventProperties.js +7 -5
  120. package/cjs/utils/inputValidation/eventValue.js +1 -1
  121. package/cjs/utils/inputValidation/key.js +6 -5
  122. package/cjs/utils/inputValidation/preloadedData.js +8 -8
  123. package/cjs/utils/inputValidation/split.js +1 -1
  124. package/cjs/utils/inputValidation/splits.js +2 -2
  125. package/cjs/utils/inputValidation/trafficType.js +1 -1
  126. package/cjs/utils/inputValidation/trafficTypeExistance.js +1 -1
  127. package/cjs/utils/jwt/index.js +1 -1
  128. package/cjs/utils/key/index.js +3 -3
  129. package/cjs/utils/lang/index.js +13 -16
  130. package/cjs/utils/lang/maps.js +16 -2
  131. package/cjs/utils/murmur3/common.js +1 -1
  132. package/cjs/utils/murmur3/legacy.js +44 -0
  133. package/cjs/utils/murmur3/murmur3.js +10 -10
  134. package/cjs/utils/murmur3/murmur3_128.js +1 -1
  135. package/cjs/utils/murmur3/murmur3_128_x86.js +37 -37
  136. package/cjs/utils/murmur3/murmur3_64.js +1 -1
  137. package/cjs/utils/promise/timeout.js +1 -1
  138. package/cjs/utils/settingsValidation/consent.js +16 -0
  139. package/cjs/utils/settingsValidation/impressionsMode.js +6 -6
  140. package/cjs/utils/settingsValidation/index.js +32 -14
  141. package/cjs/utils/settingsValidation/integrations/configurable.js +1 -1
  142. package/cjs/utils/settingsValidation/integrations/pluggable.js +1 -1
  143. package/cjs/utils/settingsValidation/localhost/builtin.js +2 -2
  144. package/cjs/utils/settingsValidation/logger/builtinLogger.js +3 -3
  145. package/cjs/utils/settingsValidation/logger/commons.js +1 -1
  146. package/cjs/utils/settingsValidation/logger/pluggableLogger.js +1 -1
  147. package/cjs/utils/settingsValidation/runtime.js +11 -0
  148. package/cjs/utils/settingsValidation/splitFilters.js +1 -1
  149. package/cjs/utils/settingsValidation/storage/storageCS.js +1 -1
  150. package/cjs/utils/timeTracker/index.js +3 -3
  151. package/esm/evaluator/matchers/ew.js +4 -4
  152. package/esm/integrations/ga/GoogleAnalyticsToSplit.js +4 -2
  153. package/esm/integrations/ga/SplitToGoogleAnalytics.js +4 -2
  154. package/esm/listeners/browser.js +14 -10
  155. package/esm/logger/constants.js +5 -2
  156. package/esm/logger/messages/debug.js +3 -3
  157. package/esm/logger/messages/error.js +4 -3
  158. package/esm/logger/messages/info.js +9 -7
  159. package/esm/sdkClient/client.js +4 -2
  160. package/esm/sdkClient/clientCS.js +2 -1
  161. package/esm/sdkClient/clientInputValidation.js +6 -8
  162. package/esm/sdkClient/sdkClient.js +1 -4
  163. package/esm/sdkClient/sdkClientMethodCS.js +1 -5
  164. package/esm/sdkClient/sdkClientMethodCSWithTT.js +1 -9
  165. package/esm/sdkFactory/index.js +8 -6
  166. package/esm/sdkFactory/userConsentProps.js +33 -0
  167. package/esm/services/splitApi.js +2 -1
  168. package/esm/services/splitHttpClient.js +1 -1
  169. package/esm/storages/KeyBuilder.js +2 -6
  170. package/esm/storages/KeyBuilderCS.js +11 -1
  171. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +23 -3
  172. package/esm/storages/inLocalStorage/index.js +1 -1
  173. package/esm/storages/inMemory/ImpressionsCacheInMemory.js +15 -1
  174. package/esm/storages/inMemory/InMemoryStorage.js +1 -1
  175. package/esm/storages/inMemory/InMemoryStorageCS.js +1 -1
  176. package/esm/storages/inRedis/RedisAdapter.js +15 -2
  177. package/esm/storages/pluggable/index.js +2 -2
  178. package/esm/sync/offline/splitsParser/splitsParserFromFile.js +1 -1
  179. package/esm/sync/polling/fetchers/mySegmentsFetcher.js +2 -2
  180. package/esm/sync/polling/fetchers/segmentChangesFetcher.js +2 -2
  181. package/esm/sync/polling/pollingManagerCS.js +2 -1
  182. package/esm/sync/polling/pollingManagerSS.js +2 -1
  183. package/esm/sync/polling/syncTasks/mySegmentsSyncTask.js +1 -1
  184. package/esm/sync/polling/updaters/mySegmentsUpdater.js +2 -2
  185. package/esm/sync/streaming/AuthClient/index.js +1 -2
  186. package/esm/sync/streaming/SSEClient/index.js +2 -1
  187. package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +1 -1
  188. package/esm/sync/streaming/pushManager.js +34 -23
  189. package/esm/sync/submitters/eventsSyncTask.js +18 -6
  190. package/esm/sync/submitters/impressionsSyncTask.js +13 -1
  191. package/esm/sync/submitters/submitterManager.js +2 -1
  192. package/esm/sync/syncManagerOnline.js +21 -17
  193. package/esm/trackers/eventTracker.js +8 -1
  194. package/esm/trackers/impressionObserver/utils.js +7 -1
  195. package/esm/trackers/impressionsTracker.js +6 -5
  196. package/esm/utils/consent.js +6 -0
  197. package/esm/utils/constants/index.js +4 -0
  198. package/esm/utils/inputValidation/attributes.js +1 -1
  199. package/esm/utils/inputValidation/eventProperties.js +4 -2
  200. package/esm/utils/inputValidation/key.js +2 -1
  201. package/esm/utils/lang/index.js +12 -15
  202. package/esm/utils/lang/maps.js +14 -1
  203. package/esm/utils/murmur3/legacy.js +39 -0
  204. package/esm/utils/promise/timeout.js +1 -1
  205. package/esm/utils/settingsValidation/consent.js +12 -0
  206. package/esm/utils/settingsValidation/impressionsMode.js +7 -7
  207. package/esm/utils/settingsValidation/index.js +28 -10
  208. package/esm/utils/settingsValidation/runtime.js +7 -0
  209. package/package.json +7 -7
  210. package/src/evaluator/matchers/ew.ts +4 -4
  211. package/src/evaluator/parser/index.ts +1 -1
  212. package/src/evaluator/types.ts +2 -2
  213. package/src/evaluator/value/index.ts +2 -2
  214. package/src/evaluator/value/sanitize.ts +2 -2
  215. package/src/integrations/ga/GoogleAnalyticsToSplit.ts +7 -4
  216. package/src/integrations/ga/SplitToGoogleAnalytics.ts +7 -4
  217. package/src/integrations/pluggable.ts +2 -2
  218. package/src/integrations/types.ts +5 -0
  219. package/src/listeners/browser.ts +13 -9
  220. package/src/logger/.DS_Store +0 -0
  221. package/src/logger/constants.ts +5 -2
  222. package/src/logger/messages/debug.ts +3 -3
  223. package/src/logger/messages/error.ts +4 -3
  224. package/src/logger/messages/info.ts +9 -7
  225. package/src/logger/types.ts +4 -0
  226. package/src/sdkClient/client.ts +4 -2
  227. package/src/sdkClient/clientCS.ts +3 -1
  228. package/src/sdkClient/clientInputValidation.ts +8 -7
  229. package/src/sdkClient/sdkClient.ts +2 -5
  230. package/src/sdkClient/sdkClientMethodCS.ts +1 -6
  231. package/src/sdkClient/sdkClientMethodCSWithTT.ts +2 -11
  232. package/src/sdkFactory/index.ts +9 -7
  233. package/src/sdkFactory/types.ts +2 -1
  234. package/src/sdkFactory/userConsentProps.ts +40 -0
  235. package/src/services/splitHttpClient.ts +1 -1
  236. package/src/storages/KeyBuilder.ts +2 -6
  237. package/src/storages/KeyBuilderCS.ts +13 -1
  238. package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +23 -3
  239. package/src/storages/inLocalStorage/index.ts +1 -1
  240. package/src/storages/inMemory/ImpressionsCacheInMemory.ts +22 -1
  241. package/src/storages/inMemory/InMemoryStorage.ts +1 -1
  242. package/src/storages/inMemory/InMemoryStorageCS.ts +1 -1
  243. package/src/storages/inRedis/RedisAdapter.ts +8 -2
  244. package/src/storages/pluggable/index.ts +2 -2
  245. package/src/storages/types.ts +6 -2
  246. package/src/sync/offline/splitsParser/splitsParserFromFile.ts +1 -1
  247. package/src/sync/polling/fetchers/mySegmentsFetcher.ts +2 -1
  248. package/src/sync/polling/fetchers/types.ts +1 -0
  249. package/src/sync/polling/pollingManagerCS.ts +3 -6
  250. package/src/sync/polling/pollingManagerSS.ts +3 -8
  251. package/src/sync/polling/syncTasks/mySegmentsSyncTask.ts +2 -1
  252. package/src/sync/polling/types.ts +0 -12
  253. package/src/sync/polling/updaters/mySegmentsUpdater.ts +2 -1
  254. package/src/sync/streaming/AuthClient/index.ts +1 -2
  255. package/src/sync/streaming/SSEClient/index.ts +2 -1
  256. package/src/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.ts +1 -1
  257. package/src/sync/streaming/pushManager.ts +39 -37
  258. package/src/sync/streaming/types.ts +5 -25
  259. package/src/sync/submitters/eventsSyncTask.ts +19 -6
  260. package/src/sync/submitters/impressionsSyncTask.ts +16 -1
  261. package/src/sync/submitters/submitterManager.ts +4 -8
  262. package/src/sync/syncManagerOnline.ts +27 -27
  263. package/src/sync/types.ts +4 -1
  264. package/src/trackers/eventTracker.ts +11 -3
  265. package/src/trackers/impressionObserver/utils.ts +8 -1
  266. package/src/trackers/impressionsTracker.ts +7 -8
  267. package/src/types.ts +26 -1
  268. package/src/utils/consent.ts +8 -0
  269. package/src/utils/constants/index.ts +5 -0
  270. package/src/utils/inputValidation/attributes.ts +1 -2
  271. package/src/utils/inputValidation/eventProperties.ts +4 -2
  272. package/src/utils/lang/index.ts +15 -18
  273. package/src/utils/lang/maps.ts +15 -1
  274. package/src/utils/murmur3/legacy.ts +48 -0
  275. package/src/utils/promise/timeout.ts +1 -1
  276. package/src/utils/settingsValidation/consent.ts +16 -0
  277. package/src/utils/settingsValidation/impressionsMode.ts +8 -8
  278. package/src/utils/settingsValidation/index.ts +29 -10
  279. package/src/utils/settingsValidation/runtime.ts +9 -0
  280. package/src/utils/settingsValidation/types.ts +12 -6
  281. package/types/evaluator/types.d.ts +2 -2
  282. package/types/evaluator/value/index.d.ts +1 -1
  283. package/types/evaluator/value/sanitize.d.ts +1 -1
  284. package/types/integrations/ga/GaToSplitPlugin.d.ts +3 -0
  285. package/types/integrations/ga/GoogleAnalyticsToSplit.d.ts +2 -2
  286. package/types/integrations/ga/SplitToGaPlugin.d.ts +4 -0
  287. package/types/integrations/ga/SplitToGoogleAnalytics.d.ts +2 -3
  288. package/types/integrations/types.d.ts +4 -0
  289. package/types/logger/browser/{DebugLogger.d.ts → debugLogger.d.ts} +0 -0
  290. package/types/logger/browser/{ErrorLogger.d.ts → errorLogger.d.ts} +0 -0
  291. package/types/logger/browser/{InfoLogger.d.ts → infoLogger.d.ts} +0 -0
  292. package/types/logger/browser/{WarnLogger.d.ts → warnLogger.d.ts} +0 -0
  293. package/types/logger/codes.d.ts +2 -0
  294. package/types/logger/codesConstants.d.ts +117 -0
  295. package/types/logger/codesConstantsBrowser.d.ts +2 -0
  296. package/types/logger/codesConstantsNode.d.ts +14 -0
  297. package/types/logger/codesDebug.d.ts +1 -0
  298. package/types/logger/codesDebugBrowser.d.ts +1 -0
  299. package/types/logger/codesDebugNode.d.ts +1 -0
  300. package/types/logger/codesError.d.ts +1 -0
  301. package/types/logger/codesErrorNode.d.ts +1 -0
  302. package/types/logger/codesInfo.d.ts +1 -0
  303. package/types/logger/codesWarn.d.ts +1 -0
  304. package/types/logger/codesWarnNode.d.ts +1 -0
  305. package/types/logger/constants.d.ts +5 -2
  306. package/types/logger/debugLogger.d.ts +2 -0
  307. package/types/logger/errorLogger.d.ts +2 -0
  308. package/types/logger/infoLogger.d.ts +2 -0
  309. package/types/logger/messages/debugBrowser.d.ts +1 -0
  310. package/types/logger/messages/debugNode.d.ts +1 -0
  311. package/types/logger/messages/errorNode.d.ts +1 -0
  312. package/types/logger/messages/warnNode.d.ts +1 -0
  313. package/types/logger/noopLogger.d.ts +2 -0
  314. package/types/logger/types.d.ts +4 -0
  315. package/types/logger/warnLogger.d.ts +2 -0
  316. package/types/sdkClient/clientAttributesDecoration.d.ts +1 -1
  317. package/types/sdkClient/clientInputValidation.d.ts +2 -3
  318. package/types/sdkFactory/types.d.ts +1 -1
  319. package/types/sdkFactory/userConsentProps.d.ts +6 -0
  320. package/types/sdkManager/sdkManagerMethod.d.ts +6 -0
  321. package/types/storages/KeyBuilderCS.d.ts +2 -0
  322. package/types/storages/getRegisteredSegments.d.ts +10 -0
  323. package/types/storages/inMemory/ImpressionsCacheInMemory.d.ts +9 -0
  324. package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +51 -0
  325. package/types/storages/inMemory/index.d.ts +10 -0
  326. package/types/storages/inRedis/RedisAdapter.d.ts +1 -1
  327. package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +0 -0
  328. package/types/storages/parseSegments.d.ts +6 -0
  329. package/types/storages/pluggable/TelemetryCachePluggable.d.ts +2 -0
  330. package/types/storages/types.d.ts +3 -1
  331. package/types/sync/polling/fetchers/mySegmentsFetcher.d.ts +1 -1
  332. package/types/sync/polling/fetchers/types.d.ts +1 -1
  333. package/types/sync/polling/pollingManagerCS.d.ts +2 -5
  334. package/types/sync/polling/pollingManagerSS.d.ts +2 -5
  335. package/types/sync/polling/syncTasks/splitsSyncTask.copy.d.ts +35 -0
  336. package/types/sync/polling/syncTasks/splitsSyncTask.morelikeoriginal.d.ts +35 -0
  337. package/types/sync/polling/types.d.ts +0 -11
  338. package/types/sync/polling/updaters/mySegmentsUpdater.d.ts +1 -1
  339. package/types/sync/streaming/AuthClient/indexV1.d.ts +12 -0
  340. package/types/sync/streaming/AuthClient/indexV2.d.ts +8 -0
  341. package/types/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.d.ts +1 -1
  342. package/types/sync/streaming/pushManager.d.ts +3 -7
  343. package/types/sync/streaming/pushManagerCS.d.ts +1 -0
  344. package/types/sync/streaming/pushManagerNoUsers.d.ts +13 -0
  345. package/types/sync/streaming/pushManagerSS.d.ts +1 -0
  346. package/types/sync/streaming/types.d.ts +3 -23
  347. package/types/sync/submitters/submitterManager.d.ts +2 -4
  348. package/types/sync/submitters/telemetrySyncTask.d.ts +17 -0
  349. package/types/sync/syncManagerFromFile.d.ts +2 -0
  350. package/types/sync/syncManagerFromObject.d.ts +2 -0
  351. package/types/sync/syncManagerOffline.d.ts +9 -0
  352. package/types/sync/syncManagerOnline.d.ts +3 -3
  353. package/types/sync/types.d.ts +3 -0
  354. package/types/trackers/eventTracker.d.ts +2 -2
  355. package/types/trackers/impressionObserver/utils.d.ts +4 -0
  356. package/types/trackers/impressionsTracker.d.ts +2 -3
  357. package/types/trackers/telemetryRecorder.d.ts +0 -0
  358. package/types/types.d.ts +22 -0
  359. package/types/utils/EventEmitter.d.ts +4 -0
  360. package/types/utils/consent.d.ts +2 -0
  361. package/types/utils/constants/index.d.ts +3 -0
  362. package/types/utils/lang/errors.d.ts +10 -0
  363. package/types/utils/lang/index.d.ts +6 -5
  364. package/types/utils/lang/maps.d.ts +7 -0
  365. package/types/utils/murmur3/commons.d.ts +12 -0
  366. package/types/utils/murmur3/legacy.d.ts +2 -0
  367. package/types/utils/settingsValidation/buildMetadata.d.ts +3 -0
  368. package/types/utils/settingsValidation/consent.d.ts +6 -0
  369. package/types/utils/settingsValidation/impressionsMode.d.ts +1 -1
  370. package/types/utils/settingsValidation/localhost/index.d.ts +9 -0
  371. package/types/utils/settingsValidation/logger.d.ts +11 -0
  372. package/types/utils/settingsValidation/runtime/browser.d.ts +2 -0
  373. package/types/utils/settingsValidation/runtime/node.d.ts +2 -0
  374. package/types/utils/settingsValidation/runtime.d.ts +2 -0
  375. package/types/utils/settingsValidation/types.d.ts +12 -6
  376. package/types/utils/settingsValidation/userConsent.d.ts +5 -0
@@ -1,7 +1,5 @@
1
- import { IPushEventEmitter, IPushManagerCS } from './types';
1
+ import { IPushEventEmitter, IPushManager } from './types';
2
2
  import { ISSEClient } from './SSEClient/types';
3
- import { IStorageSync } from '../../storages/types';
4
- import { IReadinessManager } from '../../readiness/types';
5
3
  import { ISegmentsSyncTask, IPollingManager } from '../polling/types';
6
4
  import { objectAssign } from '../../utils/lang/objectAssign';
7
5
  import { Backoff } from '../../utils/Backoff';
@@ -12,17 +10,15 @@ import { SplitsUpdateWorker } from './UpdateWorkers/SplitsUpdateWorker';
12
10
  import { authenticateFactory, hashUserKey } from './AuthClient';
13
11
  import { forOwn } from '../../utils/lang';
14
12
  import { SSEClient } from './SSEClient';
15
- import { IFetchAuth } from '../../services/types';
16
- import { ISettings } from '../../types';
17
13
  import { getMatching } from '../../utils/key';
18
14
  import { MY_SEGMENTS_UPDATE, MY_SEGMENTS_UPDATE_V2, PUSH_NONRETRYABLE_ERROR, PUSH_SUBSYSTEM_DOWN, SECONDS_BEFORE_EXPIRATION, SEGMENT_UPDATE, SPLIT_KILL, SPLIT_UPDATE, PUSH_RETRYABLE_ERROR, PUSH_SUBSYSTEM_UP, ControlType } from './constants';
19
- import { IPlatform } from '../../sdkFactory/types';
20
15
  import { STREAMING_FALLBACK, STREAMING_REFRESH_TOKEN, STREAMING_CONNECTING, STREAMING_DISABLED, ERROR_STREAMING_AUTH, STREAMING_DISCONNECTING, STREAMING_RECONNECT, STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 } from '../../logger/constants';
21
16
  import { KeyList, UpdateStrategy } from './SSEHandler/types';
22
17
  import { isInBitmap, parseBitmap, parseKeyList } from './mySegmentsV2utils';
23
18
  import { ISet, _Set } from '../../utils/lang/sets';
24
19
  import { Hash64, hash64 } from '../../utils/murmur3/murmur3_64';
25
20
  import { IAuthTokenPushEnabled } from './AuthClient/types';
21
+ import { ISyncManagerFactoryParams } from '../types';
26
22
 
27
23
  /**
28
24
  * PushManager factory:
@@ -30,17 +26,15 @@ import { IAuthTokenPushEnabled } from './AuthClient/types';
30
26
  * - for client-side, with support for multiple clients, if key is provided in settings
31
27
  */
32
28
  export function pushManagerFactory(
29
+ params: ISyncManagerFactoryParams,
33
30
  pollingManager: IPollingManager,
34
- storage: IStorageSync,
35
- readiness: IReadinessManager,
36
- fetchAuth: IFetchAuth,
37
- platform: IPlatform,
38
- settings: ISettings,
39
- ): IPushManagerCS | undefined {
31
+ ): IPushManager | undefined {
32
+
33
+ const { settings, storage, splitApi, readiness, platform } = params;
40
34
 
41
35
  // `userKey` is the matching key of main client in client-side SDK.
42
36
  // It can be used to check if running on client-side or server-side SDK.
43
- const userKey = settings.core.key ? getMatching(settings.core.key) : undefined; //
37
+ const userKey = settings.core.key ? getMatching(settings.core.key) : undefined;
44
38
  const log = settings.log;
45
39
 
46
40
  let sseClient: ISSEClient;
@@ -51,7 +45,7 @@ export function pushManagerFactory(
51
45
  log.warn(STREAMING_FALLBACK, [e]);
52
46
  return;
53
47
  }
54
- const authenticate = authenticateFactory(fetchAuth);
48
+ const authenticate = authenticateFactory(splitApi.fetchAuth);
55
49
 
56
50
  // init feedback loop
57
51
  const pushEmitter = new platform.EventEmitter() as IPushEventEmitter;
@@ -59,7 +53,8 @@ export function pushManagerFactory(
59
53
  sseClient.setEventHandler(sseHandler);
60
54
 
61
55
  // init workers
62
- const segmentsUpdateWorker = userKey ? new MySegmentsUpdateWorker(pollingManager.segmentsSyncTask) : new SegmentsUpdateWorker(storage.segments, pollingManager.segmentsSyncTask);
56
+ // MySegmentsUpdateWorker (client-side) are initiated in `add` method
57
+ const segmentsUpdateWorker = userKey ? undefined : new SegmentsUpdateWorker(pollingManager.segmentsSyncTask, storage.segments);
63
58
  // For server-side we pass the segmentsSyncTask, used by SplitsUpdateWorker to fetch new segments
64
59
  const splitsUpdateWorker = new SplitsUpdateWorker(storage.splits, pollingManager.splitsSyncTask, readiness.splits, userKey ? undefined : pollingManager.segmentsSyncTask);
65
60
 
@@ -68,11 +63,6 @@ export function pushManagerFactory(
68
63
  // [Only for client-side] map of user keys to their corresponding hash64 and MySegmentsUpdateWorkers.
69
64
  // Hash64 is used to process MY_SEGMENTS_UPDATE_V2 events and dispatch actions to the corresponding MySegmentsUpdateWorker.
70
65
  const clients: Record<string, { hash64: Hash64, worker: MySegmentsUpdateWorker }> = {};
71
- if (userKey) {
72
- const hash = hashUserKey(userKey);
73
- userKeyHashes[hash] = userKey;
74
- clients[userKey] = { hash64: hash64(userKey), worker: segmentsUpdateWorker as MySegmentsUpdateWorker };
75
- }
76
66
 
77
67
  // [Only for client-side] variable to flag that a new client was added. It is needed to reconnect streaming.
78
68
  let connectForNewClient = false;
@@ -81,6 +71,7 @@ export function pushManagerFactory(
81
71
  // It is used to halt the `connectPush` process if it was in progress.
82
72
  let disconnected: boolean | undefined;
83
73
  // flag that indicates a PUSH_NONRETRYABLE_ERROR, condition with which starting pushManager again is ignored.
74
+ // true if STREAMING_DISABLED control event, or 'pushEnabled: false', or non-recoverable SSE or Auth errors.
84
75
  let disabled: boolean | undefined; // `disabled` implies `disconnected === true`
85
76
 
86
77
  /** PushManager functions related to initialization */
@@ -176,7 +167,7 @@ export function pushManagerFactory(
176
167
  function stopWorkers() {
177
168
  splitsUpdateWorker.backoff.reset();
178
169
  if (userKey) forOwn(clients, ({ worker }) => worker.backoff.reset());
179
- else segmentsUpdateWorker.backoff.reset();
170
+ else (segmentsUpdateWorker as SegmentsUpdateWorker).backoff.reset();
180
171
  }
181
172
 
182
173
  pushEmitter.on(PUSH_SUBSYSTEM_DOWN, stopWorkers);
@@ -306,37 +297,48 @@ export function pushManagerFactory(
306
297
  // Expose Event Emitter functionality and Event constants
307
298
  Object.create(pushEmitter),
308
299
  {
309
- // Expose functionality for starting and stoping push mode:
310
- stop: disconnectPush, // `handleNonRetryableError` cannot be used as `stop`, because it emits PUSH_SUBSYSTEM_DOWN event, which starts polling.
300
+ // Stop/pause push mode.
301
+ // It doesn't emit events. Neither PUSH_SUBSYSTEM_DOWN to start polling.
302
+ stop() {
303
+ disconnectPush(); // `handleNonRetryableError` cannot be used as `stop`, because it emits PUSH_SUBSYSTEM_DOWN event, which starts polling.
304
+ if (userKey) this.remove(userKey); // Necessary to properly resume streaming in client-side (e.g., RN SDK transition to foreground).
305
+ },
311
306
 
307
+ // Start/resume push mode.
308
+ // It eventually emits PUSH_SUBSYSTEM_DOWN, that starts polling, or PUSH_SUBSYSTEM_UP, that executes a syncAll
312
309
  start() {
313
310
  // Guard condition to avoid calling `connectPush` again if the `start` method is called multiple times or if push has been disabled.
314
311
  if (disabled || disconnected === false) return;
315
312
  disconnected = false;
316
- // Run in next event-loop cycle for optimization on client-side: if multiple clients are created in the same cycle than the factory, only one authentication is performed.
317
- setTimeout(connectPush);
313
+
314
+ if (userKey) this.add(userKey, pollingManager.segmentsSyncTask); // client-side
315
+ else setTimeout(connectPush); // server-side runs in next cycle as in client-side, for consistency with client-side
316
+ },
317
+
318
+ // true/false if start or stop was called last respectively
319
+ isRunning(){
320
+ return disconnected === false;
318
321
  },
319
322
 
320
323
  // [Only for client-side]
321
324
  add(userKey: string, mySegmentsSyncTask: ISegmentsSyncTask) {
322
- clients[userKey] = { hash64: hash64(userKey), worker: new MySegmentsUpdateWorker(mySegmentsSyncTask) };
323
-
324
325
  const hash = hashUserKey(userKey);
325
326
 
326
327
  if (!userKeyHashes[hash]) {
327
328
  userKeyHashes[hash] = userKey;
329
+ clients[userKey] = { hash64: hash64(userKey), worker: new MySegmentsUpdateWorker(mySegmentsSyncTask) };
328
330
  connectForNewClient = true; // we must reconnect on start, to listen the channel for the new user key
329
- }
330
331
 
331
- // Reconnects in case of a new client.
332
- // Run in next event-loop cycle to save authentication calls
333
- // in case the user is creating several clients in the current cycle.
334
- setTimeout(function checkForReconnect() {
335
- if (connectForNewClient) {
336
- connectForNewClient = false;
337
- connectPush();
338
- }
339
- }, 0);
332
+ // Reconnects in case of a new client.
333
+ // Run in next event-loop cycle to save authentication calls
334
+ // in case multiple clients are created in the current cycle.
335
+ setTimeout(function checkForReconnect() {
336
+ if (connectForNewClient) {
337
+ connectForNewClient = false;
338
+ connectPush();
339
+ }
340
+ }, 0);
341
+ }
340
342
  },
341
343
  // [Only for client-side]
342
344
  remove(userKey: string) {
@@ -1,11 +1,7 @@
1
1
  import { IMySegmentsUpdateData, IMySegmentsUpdateV2Data, ISegmentUpdateData, ISplitUpdateData, ISplitKillData } from './SSEHandler/types';
2
2
  import { ITask } from '../types';
3
- import { IPollingManager, ISegmentsSyncTask } from '../polling/types';
4
- import { IReadinessManager } from '../../readiness/types';
5
- import { IFetchAuth } from '../../services/types';
6
- import { IStorageSync } from '../../storages/types';
7
- import { IEventEmitter, ISettings } from '../../types';
8
- import { IPlatform } from '../../sdkFactory/types';
3
+ import { ISegmentsSyncTask } from '../polling/types';
4
+ import { IEventEmitter } from '../../types';
9
5
  import { ControlType } from './constants';
10
6
 
11
7
  // Internal SDK events, subscribed by SyncManager and PushManager
@@ -45,26 +41,10 @@ export interface IPushEventEmitter extends IEventEmitter {
45
41
  }
46
42
 
47
43
  /**
48
- * PushManager for server-side
44
+ * PushManager
49
45
  */
50
- export interface IPushManager extends ITask, IPushEventEmitter { }
51
-
52
- /**
53
- * PushManager for client-side with support for multiple clients
54
- */
55
- export interface IPushManagerCS extends IPushManager {
46
+ export interface IPushManager extends ITask, IPushEventEmitter {
47
+ // Methods used in client-side, to support multiple clients
56
48
  add(userKey: string, mySegmentsSyncTask: ISegmentsSyncTask): void,
57
49
  remove(userKey: string): void
58
50
  }
59
-
60
- /**
61
- * Signature of push manager factory/constructor
62
- */
63
- export type IPushManagerFactoryParams = [
64
- pollingManager: IPollingManager,
65
- storage: IStorageSync,
66
- readiness: IReadinessManager,
67
- fetchAuth: IFetchAuth,
68
- platform: IPlatform,
69
- settings: ISettings
70
- ]
@@ -3,7 +3,9 @@ import { IPostEventsBulk } from '../../services/types';
3
3
  import { ISyncTask, ITimeTracker } from '../types';
4
4
  import { submitterSyncTaskFactory } from './submitterSyncTask';
5
5
  import { ILogger } from '../../logger/types';
6
- import { SUBMITTERS_PUSH_FULL_EVENTS_QUEUE } from '../../logger/constants';
6
+ import { SUBMITTERS_PUSH_FULL_QUEUE } from '../../logger/constants';
7
+
8
+ const DATA_NAME = 'events';
7
9
 
8
10
  /**
9
11
  * Sync task that periodically posts tracked events
@@ -18,26 +20,37 @@ export function eventsSyncTaskFactory(
18
20
  ): ISyncTask {
19
21
 
20
22
  // don't retry events.
21
- const syncTask = submitterSyncTaskFactory(log, postEventsBulk, eventsCache, eventsPushRate, 'queued events', latencyTracker);
23
+ const syncTask = submitterSyncTaskFactory(log, postEventsBulk, eventsCache, eventsPushRate, DATA_NAME, latencyTracker);
22
24
 
23
- // Set a timer for the first push of events,
25
+ // Set a timer for the first push window of events.
26
+ // Not implemented in the base submitter or sync task, since this feature is only used by the events submitter.
24
27
  if (eventsFirstPushWindow > 0) {
28
+ let running = false;
25
29
  let stopEventPublisherTimeout: ReturnType<typeof setTimeout>;
26
30
  const originalStart = syncTask.start;
27
31
  syncTask.start = () => {
32
+ running = true;
28
33
  stopEventPublisherTimeout = setTimeout(originalStart, eventsFirstPushWindow);
29
34
  };
30
35
  const originalStop = syncTask.stop;
31
36
  syncTask.stop = () => {
37
+ running = false;
32
38
  clearTimeout(stopEventPublisherTimeout);
33
39
  originalStop();
34
40
  };
41
+ syncTask.isRunning = () => {
42
+ return running;
43
+ };
35
44
  }
36
45
 
37
- // register eventsSubmitter to be executed when events cache is full
46
+ // register events submitter to be executed when events cache is full
38
47
  eventsCache.setOnFullQueueCb(() => {
39
- log.info(SUBMITTERS_PUSH_FULL_EVENTS_QUEUE);
40
- syncTask.execute();
48
+ if (syncTask.isRunning()) {
49
+ log.info(SUBMITTERS_PUSH_FULL_QUEUE, [DATA_NAME]);
50
+ syncTask.execute();
51
+ }
52
+ // If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.
53
+ // Data will be sent when submitter is resumed.
41
54
  });
42
55
 
43
56
  return syncTask;
@@ -6,6 +6,9 @@ import { ImpressionDTO } from '../../types';
6
6
  import { submitterSyncTaskFactory } from './submitterSyncTask';
7
7
  import { ImpressionsPayload } from './types';
8
8
  import { ILogger } from '../../logger/types';
9
+ import { SUBMITTERS_PUSH_FULL_QUEUE } from '../../logger/constants';
10
+
11
+ const DATA_NAME = 'impressions';
9
12
 
10
13
  /**
11
14
  * Converts `impressions` data from cache into request payload.
@@ -50,5 +53,17 @@ export function impressionsSyncTaskFactory(
50
53
  ): ISyncTask {
51
54
 
52
55
  // retry impressions only once.
53
- return submitterSyncTaskFactory(log, postTestImpressionsBulk, impressionsCache, impressionsRefreshRate, 'impressions', latencyTracker, fromImpressionsCollector.bind(undefined, sendLabels), 1);
56
+ const syncTask = submitterSyncTaskFactory(log, postTestImpressionsBulk, impressionsCache, impressionsRefreshRate, DATA_NAME, latencyTracker, fromImpressionsCollector.bind(undefined, sendLabels), 1);
57
+
58
+ // register impressions submitter to be executed when impressions cache is full
59
+ impressionsCache.setOnFullQueueCb(() => {
60
+ if (syncTask.isRunning()) {
61
+ log.info(SUBMITTERS_PUSH_FULL_QUEUE, [DATA_NAME]);
62
+ syncTask.execute();
63
+ }
64
+ // If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.
65
+ // Data will be sent when submitter is resumed.
66
+ });
67
+
68
+ return syncTask;
54
69
  }
@@ -2,15 +2,11 @@ import { syncTaskComposite } from '../syncTaskComposite';
2
2
  import { eventsSyncTaskFactory } from './eventsSyncTask';
3
3
  import { impressionsSyncTaskFactory } from './impressionsSyncTask';
4
4
  import { impressionCountsSyncTaskFactory } from './impressionCountsSyncTask';
5
- import { ISplitApi } from '../../services/types';
6
- import { IStorageSync } from '../../storages/types';
7
- import { ISettings } from '../../types';
5
+ import { ISyncManagerFactoryParams } from '../types';
8
6
 
9
- export function submitterManagerFactory(
10
- settings: ISettings,
11
- storage: IStorageSync,
12
- splitApi: ISplitApi,
13
- ) {
7
+ export function submitterManagerFactory(params: ISyncManagerFactoryParams) {
8
+
9
+ const { settings, storage, splitApi } = params;
14
10
  const log = settings.log;
15
11
  const submitters = [
16
12
  impressionsSyncTaskFactory(log, splitApi.postTestImpressionsBulk, storage.impressions, settings.scheduler.impressionsRefreshRate, settings.core.labelsEnabled),
@@ -2,10 +2,11 @@ import { ISyncManagerCS, ISyncManagerFactoryParams } from './types';
2
2
  import { submitterManagerFactory } from './submitters/submitterManager';
3
3
  import { IReadinessManager } from '../readiness/types';
4
4
  import { IStorageSync } from '../storages/types';
5
- import { IPushManagerFactoryParams, IPushManager, IPushManagerCS } from './streaming/types';
6
- import { IPollingManager, IPollingManagerCS, IPollingManagerFactoryParams } from './polling/types';
5
+ import { IPushManager } from './streaming/types';
6
+ import { IPollingManager, IPollingManagerCS } from './polling/types';
7
7
  import { PUSH_SUBSYSTEM_UP, PUSH_SUBSYSTEM_DOWN } from './streaming/constants';
8
8
  import { SYNC_START_POLLING, SYNC_CONTINUE_POLLING, SYNC_STOP_POLLING } from '../logger/constants';
9
+ import { isConsentGranted } from '../utils/consent';
9
10
 
10
11
  /**
11
12
  * Online SyncManager factory.
@@ -16,44 +17,37 @@ import { SYNC_START_POLLING, SYNC_CONTINUE_POLLING, SYNC_STOP_POLLING } from '..
16
17
  * @param pushManagerFactory optional to build a SyncManager with or without streaming support
17
18
  */
18
19
  export function syncManagerOnlineFactory(
19
- pollingManagerFactory?: (...args: IPollingManagerFactoryParams) => IPollingManager,
20
- pushManagerFactory?: (...args: IPushManagerFactoryParams) => IPushManager | undefined
20
+ pollingManagerFactory?: (params: ISyncManagerFactoryParams) => IPollingManager,
21
+ pushManagerFactory?: (params: ISyncManagerFactoryParams, pollingManager: IPollingManager) => IPushManager | undefined,
21
22
  ): (params: ISyncManagerFactoryParams) => ISyncManagerCS {
22
23
 
23
24
  /**
24
25
  * SyncManager factory for modular SDK
25
26
  */
26
- return function ({
27
- settings,
28
- platform,
29
- splitApi,
30
- storage,
31
- readiness
32
- }: ISyncManagerFactoryParams): ISyncManagerCS {
27
+ return function (params: ISyncManagerFactoryParams): ISyncManagerCS {
33
28
 
34
- const log = settings.log;
29
+ const { settings, settings: { log, streamingEnabled } } = params;
35
30
 
36
31
  /** Polling Manager */
37
- const pollingManager = pollingManagerFactory && pollingManagerFactory(splitApi, storage, readiness, settings);
32
+ const pollingManager = pollingManagerFactory && pollingManagerFactory(params);
38
33
 
39
34
  /** Push Manager */
40
- const pushManager = settings.streamingEnabled && pollingManager && pushManagerFactory ?
41
- pushManagerFactory(pollingManager, storage, readiness, splitApi.fetchAuth, platform, settings) :
35
+ const pushManager = streamingEnabled && pollingManager && pushManagerFactory ?
36
+ pushManagerFactory(params, pollingManager) :
42
37
  undefined;
43
38
 
44
39
  /** Submitter Manager */
45
40
  // It is not inyected as push and polling managers, because at the moment it is required
46
- const submitter = submitterManagerFactory(settings, storage, splitApi);
47
-
41
+ const submitter = submitterManagerFactory(params);
48
42
 
49
43
  /** Sync Manager logic */
50
44
 
51
45
  function startPolling() {
52
- if (!pollingManager!.isRunning()) {
46
+ if (pollingManager!.isRunning()) {
47
+ log.info(SYNC_CONTINUE_POLLING);
48
+ } else {
53
49
  log.info(SYNC_START_POLLING);
54
50
  pollingManager!.start();
55
- } else {
56
- log.info(SYNC_CONTINUE_POLLING);
57
51
  }
58
52
  }
59
53
 
@@ -75,12 +69,18 @@ export function syncManagerOnlineFactory(
75
69
  let startFirstTime = true; // flag to distinguish calling the `start` method for the first time, to support pausing and resuming the synchronization
76
70
 
77
71
  return {
72
+ // Exposed for fine-grained control of synchronization.
73
+ // E.g.: user consent, app state changes (Page hide, Foreground/Background, Online/Offline).
74
+ pollingManager,
78
75
  pushManager,
76
+ submitter,
79
77
 
80
78
  /**
81
79
  * Method used to start the syncManager for the first time, or resume it after being stopped.
82
80
  */
83
81
  start() {
82
+ running = true;
83
+
84
84
  // start syncing splits and segments
85
85
  if (pollingManager) {
86
86
  if (pushManager) {
@@ -96,21 +96,21 @@ export function syncManagerOnlineFactory(
96
96
  }
97
97
 
98
98
  // start periodic data recording (events, impressions, telemetry).
99
- submitter && submitter.start();
100
- running = true;
99
+ if (isConsentGranted(settings)) submitter.start();
101
100
  },
102
101
 
103
102
  /**
104
103
  * Method used to stop/pause the syncManager.
105
104
  */
106
105
  stop() {
106
+ running = false;
107
+
107
108
  // stop syncing
108
109
  if (pushManager) pushManager.stop();
109
110
  if (pollingManager && pollingManager.isRunning()) pollingManager.stop();
110
111
 
111
112
  // stop periodic data recording (events, impressions, telemetry).
112
- if (submitter) submitter.stop();
113
- running = false;
113
+ submitter.stop();
114
114
  },
115
115
 
116
116
  isRunning() {
@@ -118,7 +118,7 @@ export function syncManagerOnlineFactory(
118
118
  },
119
119
 
120
120
  flush() {
121
- if (submitter) return submitter.execute();
121
+ if (isConsentGranted(settings)) return submitter.execute();
122
122
  else return Promise.resolve();
123
123
  },
124
124
 
@@ -141,7 +141,7 @@ export function syncManagerOnlineFactory(
141
141
  // of segments since `syncAll` was already executed when starting the main client
142
142
  mySegmentsSyncTask.execute();
143
143
  }
144
- (pushManager as IPushManagerCS).add(matchingKey, mySegmentsSyncTask);
144
+ pushManager.add(matchingKey, mySegmentsSyncTask);
145
145
  } else {
146
146
  if (storage.splits.usesSegments()) mySegmentsSyncTask.start();
147
147
  }
@@ -151,7 +151,7 @@ export function syncManagerOnlineFactory(
151
151
  const mySegmentsSyncTask = (pollingManager as IPollingManagerCS).get(matchingKey);
152
152
  if (mySegmentsSyncTask) {
153
153
  // stop syncing
154
- if (pushManager) (pushManager as IPushManagerCS).remove(matchingKey);
154
+ if (pushManager) pushManager.remove(matchingKey);
155
155
  if (mySegmentsSyncTask.isRunning()) mySegmentsSyncTask.stop();
156
156
 
157
157
  (pollingManager as IPollingManagerCS).remove(matchingKey);
package/src/sync/types.ts CHANGED
@@ -3,6 +3,7 @@ import { IPlatform } from '../sdkFactory/types';
3
3
  import { ISplitApi } from '../services/types';
4
4
  import { IStorageSync } from '../storages/types';
5
5
  import { ISettings } from '../types';
6
+ import { IPollingManager } from './polling/types';
6
7
  import { IPushManager } from './streaming/types';
7
8
 
8
9
  export interface ITask<Input extends any[] = []> {
@@ -43,7 +44,9 @@ export interface ITimeTracker {
43
44
 
44
45
  export interface ISyncManager extends ITask {
45
46
  flush(): Promise<any>,
46
- pushManager?: IPushManager
47
+ pushManager?: IPushManager,
48
+ pollingManager?: IPollingManager,
49
+ submitter?: ISyncTask
47
50
  }
48
51
 
49
52
  export interface ISyncManagerCS extends ISyncManager {
@@ -2,9 +2,10 @@ import { objectAssign } from '../utils/lang/objectAssign';
2
2
  import { thenable } from '../utils/promise/thenable';
3
3
  import { IEventsCacheBase } from '../storages/types';
4
4
  import { IEventsHandler, IEventTracker } from './types';
5
- import { SplitIO } from '../types';
6
- import { ILogger } from '../logger/types';
5
+ import { ISettings, SplitIO } from '../types';
7
6
  import { EVENTS_TRACKER_SUCCESS, ERROR_EVENTS_TRACKER } from '../logger/constants';
7
+ import { CONSENT_DECLINED } from '../utils/constants';
8
+ import { isStorageSync } from './impressionObserver/utils';
8
9
 
9
10
  /**
10
11
  * Event tracker stores events in cache and pass them to the integrations manager if provided.
@@ -13,11 +14,14 @@ import { EVENTS_TRACKER_SUCCESS, ERROR_EVENTS_TRACKER } from '../logger/constant
13
14
  * @param integrationsManager optional event handler used for integrations
14
15
  */
15
16
  export function eventTrackerFactory(
16
- log: ILogger,
17
+ settings: ISettings,
17
18
  eventsCache: IEventsCacheBase,
18
19
  integrationsManager?: IEventsHandler
19
20
  ): IEventTracker {
20
21
 
22
+ const log = settings.log;
23
+ const isSync = isStorageSync(settings);
24
+
21
25
  function queueEventsCallback(eventData: SplitIO.EventData, tracked: boolean) {
22
26
  const { eventTypeId, trafficTypeName, key, value, timestamp, properties } = eventData;
23
27
  // Logging every prop would be too much.
@@ -44,6 +48,10 @@ export function eventTrackerFactory(
44
48
 
45
49
  return {
46
50
  track(eventData: SplitIO.EventData, size?: number) {
51
+ if (settings.userConsent === CONSENT_DECLINED) {
52
+ return isSync ? false : Promise.resolve(false);
53
+ }
54
+
47
55
  const tracked = eventsCache.track(eventData, size);
48
56
 
49
57
  if (thenable(tracked)) {
@@ -1,4 +1,4 @@
1
- import { CONSUMER_PARTIAL_MODE, OPTIMIZED, PRODUCER_MODE, STANDALONE_MODE } from '../../utils/constants';
1
+ import { CONSUMER_MODE, CONSUMER_PARTIAL_MODE, OPTIMIZED, PRODUCER_MODE, STANDALONE_MODE } from '../../utils/constants';
2
2
  import { ISettings } from '../../types';
3
3
 
4
4
  /**
@@ -15,3 +15,10 @@ export function shouldBeOptimized(settings: ISettings) {
15
15
  if (!shouldAddPt(settings)) return false;
16
16
  return settings.sync.impressionsMode === OPTIMIZED ? true : false;
17
17
  }
18
+
19
+ /**
20
+ * Storage is async if mode is consumer or partial consumer
21
+ */
22
+ export function isStorageSync(settings: ISettings) {
23
+ return [CONSUMER_MODE, CONSUMER_PARTIAL_MODE].indexOf(settings.mode) === -1 ? true : false;
24
+ }
@@ -5,8 +5,8 @@ import { IImpressionCountsCacheSync, IImpressionsCacheBase } from '../storages/t
5
5
  import { IImpressionsHandler, IImpressionsTracker } from './types';
6
6
  import { SplitIO, ImpressionDTO, ISettings } from '../types';
7
7
  import { IImpressionObserver } from './impressionObserver/types';
8
- import { ILogger } from '../logger/types';
9
8
  import { IMPRESSIONS_TRACKER_SUCCESS, ERROR_IMPRESSIONS_TRACKER, ERROR_IMPRESSIONS_LISTENER } from '../logger/constants';
9
+ import { CONSENT_DECLINED } from '../utils/constants';
10
10
 
11
11
  /**
12
12
  * Impressions tracker stores impressions in cache and pass them to the listener and integrations manager if provided.
@@ -19,22 +19,21 @@ import { IMPRESSIONS_TRACKER_SUCCESS, ERROR_IMPRESSIONS_TRACKER, ERROR_IMPRESSIO
19
19
  * @param countsCache optional cache to save impressions count. If provided, impressions will be deduped (OPTIMIZED mode)
20
20
  */
21
21
  export function impressionsTrackerFactory(
22
- log: ILogger,
22
+ settings: ISettings,
23
23
  impressionsCache: IImpressionsCacheBase,
24
-
25
- // @TODO consider passing only an optional integrationsManager to handle impressions
26
- { runtime: { ip, hostname }, version }: Pick<ISettings, 'version' | 'runtime'>,
27
- impressionListener?: SplitIO.IImpressionListener,
28
24
  integrationsManager?: IImpressionsHandler,
29
-
30
25
  // if observer is provided, it implies `shouldAddPreviousTime` flag (i.e., if impressions previous time should be added or not)
31
26
  observer?: IImpressionObserver,
32
27
  // if countsCache is provided, it implies `isOptimized` flag (i.e., if impressions should be deduped or not)
33
28
  countsCache?: IImpressionCountsCacheSync
34
29
  ): IImpressionsTracker {
35
30
 
31
+ const { log, impressionListener, runtime: { ip, hostname }, version } = settings;
32
+
36
33
  return {
37
34
  track(impressions: ImpressionDTO[], attributes?: SplitIO.Attributes) {
35
+ if (settings.userConsent === CONSENT_DECLINED) return;
36
+
38
37
  const impressionsCount = impressions.length;
39
38
 
40
39
  const impressionsToStore: ImpressionDTO[] = []; // Track only the impressions that are going to be stored
@@ -85,7 +84,7 @@ export function impressionsTrackerFactory(
85
84
  // integrationsManager.handleImpression does not throw errors
86
85
  if (integrationsManager) integrationsManager.handleImpression(impressionData);
87
86
 
88
- try { // An exception on the listeners should not break the SDK.
87
+ try { // @ts-ignore. An exception on the listeners should not break the SDK.
89
88
  if (impressionListener) impressionListener.logImpression(impressionData);
90
89
  } catch (err) {
91
90
  log.error(ERROR_IMPRESSIONS_LISTENER, [err]);
package/src/types.ts CHANGED
@@ -54,6 +54,11 @@ type EventConsts = {
54
54
  * @typedef {string} SDKMode
55
55
  */
56
56
  export type SDKMode = 'standalone' | 'consumer' | 'localhost' | 'consumer_partial';
57
+ /**
58
+ * User consent status.
59
+ * @typedef {string} ConsentStatus
60
+ */
61
+ export type ConsentStatus = 'GRANTED' | 'DECLINED' | 'UNKNOWN';
57
62
  /**
58
63
  * Settings interface. This is a representation of the settings the SDK expose, that's why
59
64
  * most of it's props are readonly. Only features should be rewritten when localhost mode is active.
@@ -73,6 +78,7 @@ export interface ISettings {
73
78
  readonly scheduler: {
74
79
  featuresRefreshRate: number,
75
80
  impressionsRefreshRate: number,
81
+ impressionsQueueSize: number,
76
82
  metricsRefreshRate: number,
77
83
  segmentsRefreshRate: number,
78
84
  offlineRefreshRate: number,
@@ -110,6 +116,7 @@ export interface ISettings {
110
116
  },
111
117
  readonly log: ILogger
112
118
  readonly impressionListener?: unknown
119
+ readonly userConsent?: ConsentStatus
113
120
  }
114
121
  /**
115
122
  * Log levels.
@@ -255,6 +262,13 @@ interface INodeBasicSettings extends ISharedSettings {
255
262
  * @default 300
256
263
  */
257
264
  impressionsRefreshRate?: number,
265
+ /**
266
+ * The maximum number of impression items we want to queue. If we queue more values, it will trigger a flush and reset the timer.
267
+ * If you use a 0 here, the queue will have no maximum size.
268
+ * @property {number} impressionsQueueSize
269
+ * @default 30000
270
+ */
271
+ impressionsQueueSize?: number,
258
272
  /**
259
273
  * The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
260
274
  * @property {number} metricsRefreshRate
@@ -381,6 +395,10 @@ interface IBasicClient extends IStatusInterface {
381
395
  * @returns {Promise<void>}
382
396
  */
383
397
  destroy(): Promise<void>
398
+
399
+ // Whether the client implements the client-side API, i.e, with bound key, (true), or the server-side API (false).
400
+ // Exposed for internal purposes only. Not considered part of the public API, and might be renamed eventually.
401
+ isClientSide: boolean
384
402
  }
385
403
  /**
386
404
  * Common definitions between SDK instances for different environments interface.
@@ -765,6 +783,13 @@ export namespace SplitIO {
765
783
  * @default 60
766
784
  */
767
785
  impressionsRefreshRate?: number,
786
+ /**
787
+ * The maximum number of impression items we want to queue. If we queue more values, it will trigger a flush and reset the timer.
788
+ * If you use a 0 here, the queue will have no maximum size.
789
+ * @property {number} impressionsQueueSize
790
+ * @default 30000
791
+ */
792
+ impressionsQueueSize?: number,
768
793
  /**
769
794
  * The SDK sends diagnostic metrics to Split servers. This parameters controls this metric flush period in seconds.
770
795
  * @property {number} metricsRefreshRate
@@ -1139,7 +1164,7 @@ export namespace SplitIO {
1139
1164
  /**
1140
1165
  * Removes from client's in memory attributes storage the attribute with the given key
1141
1166
  * @function removeAttribute
1142
- * @param {string} attributeName
1167
+ * @param {string} attributeName
1143
1168
  * @returns {boolean} true if attribute was removed and false otherways
1144
1169
  */
1145
1170
  removeAttribute(attributeName: string): boolean,
@@ -0,0 +1,8 @@
1
+ import { ISettings } from '../types';
2
+ import { CONSENT_GRANTED } from './constants';
3
+
4
+ export function isConsentGranted(settings: ISettings) {
5
+ const userConsent = settings.userConsent;
6
+ // undefined userConsent is handled as granted (default)
7
+ return !userConsent || userConsent === CONSENT_GRANTED;
8
+ }