@splitsoftware/splitio-commons 1.2.1-rc.1 → 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 (278) 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 +1 -1
  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 +7 -5
  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 +12 -11
  39. package/cjs/sdkClient/clientAttributesDecoration.js +4 -4
  40. package/cjs/sdkClient/clientCS.js +3 -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 +2 -2
  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/segmentChangesFetcher.js +1 -1
  84. package/cjs/sync/polling/pollingManagerCS.js +6 -6
  85. package/cjs/sync/polling/pollingManagerSS.js +3 -3
  86. package/cjs/sync/polling/syncTasks/mySegmentsSyncTask.js +1 -1
  87. package/cjs/sync/polling/syncTasks/segmentsSyncTask.js +1 -1
  88. package/cjs/sync/polling/syncTasks/splitsSyncTask.js +1 -1
  89. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +1 -1
  90. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +2 -2
  91. package/cjs/sync/polling/updaters/splitChangesUpdater.js +2 -2
  92. package/cjs/sync/streaming/AuthClient/index.js +3 -3
  93. package/cjs/sync/streaming/SSEClient/index.js +2 -1
  94. package/cjs/sync/streaming/SSEHandler/NotificationParser.js +1 -1
  95. package/cjs/sync/streaming/SSEHandler/index.js +3 -3
  96. package/cjs/sync/streaming/mySegmentsV2utils.js +1 -1
  97. package/cjs/sync/streaming/pushManager.js +24 -17
  98. package/cjs/sync/submitters/eventsSyncTask.js +17 -5
  99. package/cjs/sync/submitters/impressionCountsSyncTask.js +1 -1
  100. package/cjs/sync/submitters/impressionsSyncTask.js +15 -3
  101. package/cjs/sync/submitters/metricsSyncTask.js +3 -3
  102. package/cjs/sync/submitters/submitterManager.js +4 -4
  103. package/cjs/sync/submitters/submitterSyncTask.js +1 -1
  104. package/cjs/sync/syncManagerOnline.js +12 -8
  105. package/cjs/trackers/eventTracker.js +11 -4
  106. package/cjs/trackers/impressionObserver/impressionObserverCS.js +1 -1
  107. package/cjs/trackers/impressionObserver/impressionObserverSS.js +1 -1
  108. package/cjs/trackers/impressionObserver/utils.js +8 -1
  109. package/cjs/trackers/impressionsTracker.js +9 -8
  110. package/cjs/utils/MinEvents.js +2 -1
  111. package/cjs/utils/consent.js +10 -0
  112. package/cjs/utils/constants/index.js +5 -1
  113. package/cjs/utils/inputValidation/apiKey.js +1 -1
  114. package/cjs/utils/inputValidation/attribute.js +4 -4
  115. package/cjs/utils/inputValidation/attributes.js +2 -2
  116. package/cjs/utils/inputValidation/event.js +1 -1
  117. package/cjs/utils/inputValidation/eventProperties.js +5 -5
  118. package/cjs/utils/inputValidation/eventValue.js +1 -1
  119. package/cjs/utils/inputValidation/key.js +6 -5
  120. package/cjs/utils/inputValidation/preloadedData.js +8 -8
  121. package/cjs/utils/inputValidation/split.js +1 -1
  122. package/cjs/utils/inputValidation/splits.js +2 -2
  123. package/cjs/utils/inputValidation/trafficType.js +1 -1
  124. package/cjs/utils/inputValidation/trafficTypeExistance.js +1 -1
  125. package/cjs/utils/jwt/index.js +1 -1
  126. package/cjs/utils/key/index.js +3 -3
  127. package/cjs/utils/lang/index.js +13 -4
  128. package/cjs/utils/lang/maps.js +16 -2
  129. package/cjs/utils/murmur3/common.js +1 -1
  130. package/cjs/utils/murmur3/murmur3.js +10 -10
  131. package/cjs/utils/murmur3/murmur3_128.js +1 -1
  132. package/cjs/utils/murmur3/murmur3_128_x86.js +37 -37
  133. package/cjs/utils/murmur3/murmur3_64.js +1 -1
  134. package/cjs/utils/settingsValidation/consent.js +16 -0
  135. package/cjs/utils/settingsValidation/impressionsMode.js +6 -6
  136. package/cjs/utils/settingsValidation/index.js +32 -14
  137. package/cjs/utils/settingsValidation/integrations/configurable.js +1 -1
  138. package/cjs/utils/settingsValidation/integrations/pluggable.js +1 -1
  139. package/cjs/utils/settingsValidation/localhost/builtin.js +2 -2
  140. package/cjs/utils/settingsValidation/logger/builtinLogger.js +3 -3
  141. package/cjs/utils/settingsValidation/logger/commons.js +1 -1
  142. package/cjs/utils/settingsValidation/logger/pluggableLogger.js +1 -1
  143. package/cjs/utils/settingsValidation/runtime.js +11 -0
  144. package/cjs/utils/settingsValidation/splitFilters.js +1 -1
  145. package/cjs/utils/settingsValidation/storage/storageCS.js +1 -1
  146. package/cjs/utils/timeTracker/index.js +3 -3
  147. package/esm/integrations/ga/GoogleAnalyticsToSplit.js +4 -2
  148. package/esm/integrations/ga/SplitToGoogleAnalytics.js +4 -2
  149. package/esm/listeners/browser.js +14 -10
  150. package/esm/logger/constants.js +5 -2
  151. package/esm/logger/messages/debug.js +3 -3
  152. package/esm/logger/messages/error.js +4 -3
  153. package/esm/logger/messages/info.js +6 -4
  154. package/esm/sdkClient/client.js +3 -2
  155. package/esm/sdkClient/clientCS.js +1 -1
  156. package/esm/sdkClient/clientInputValidation.js +6 -8
  157. package/esm/sdkClient/sdkClient.js +1 -4
  158. package/esm/sdkClient/sdkClientMethodCS.js +1 -5
  159. package/esm/sdkClient/sdkClientMethodCSWithTT.js +1 -9
  160. package/esm/sdkFactory/index.js +8 -6
  161. package/esm/sdkFactory/userConsentProps.js +33 -0
  162. package/esm/services/splitApi.js +2 -1
  163. package/esm/storages/KeyBuilder.js +2 -6
  164. package/esm/storages/KeyBuilderCS.js +11 -1
  165. package/esm/storages/inLocalStorage/MySegmentsCacheInLocal.js +23 -3
  166. package/esm/storages/inLocalStorage/index.js +1 -1
  167. package/esm/storages/inMemory/ImpressionsCacheInMemory.js +15 -1
  168. package/esm/storages/inMemory/InMemoryStorage.js +1 -1
  169. package/esm/storages/inMemory/InMemoryStorageCS.js +1 -1
  170. package/esm/storages/inRedis/RedisAdapter.js +15 -2
  171. package/esm/storages/pluggable/index.js +2 -2
  172. package/esm/sync/offline/splitsParser/splitsParserFromFile.js +1 -1
  173. package/esm/sync/polling/fetchers/segmentChangesFetcher.js +2 -2
  174. package/esm/sync/streaming/SSEClient/index.js +2 -1
  175. package/esm/sync/streaming/pushManager.js +9 -2
  176. package/esm/sync/submitters/eventsSyncTask.js +18 -6
  177. package/esm/sync/submitters/impressionsSyncTask.js +13 -1
  178. package/esm/sync/syncManagerOnline.js +11 -7
  179. package/esm/trackers/eventTracker.js +8 -1
  180. package/esm/trackers/impressionObserver/utils.js +7 -1
  181. package/esm/trackers/impressionsTracker.js +6 -5
  182. package/esm/utils/consent.js +6 -0
  183. package/esm/utils/constants/index.js +4 -0
  184. package/esm/utils/inputValidation/attributes.js +1 -1
  185. package/esm/utils/inputValidation/key.js +2 -1
  186. package/esm/utils/lang/index.js +12 -4
  187. package/esm/utils/lang/maps.js +14 -1
  188. package/esm/utils/settingsValidation/consent.js +12 -0
  189. package/esm/utils/settingsValidation/impressionsMode.js +7 -7
  190. package/esm/utils/settingsValidation/index.js +28 -10
  191. package/esm/utils/settingsValidation/runtime.js +7 -0
  192. package/package.json +8 -8
  193. package/src/evaluator/parser/index.ts +1 -1
  194. package/src/evaluator/types.ts +2 -2
  195. package/src/evaluator/value/index.ts +2 -2
  196. package/src/evaluator/value/sanitize.ts +2 -2
  197. package/src/integrations/ga/GoogleAnalyticsToSplit.ts +7 -4
  198. package/src/integrations/ga/SplitToGoogleAnalytics.ts +7 -4
  199. package/src/integrations/pluggable.ts +2 -2
  200. package/src/integrations/types.ts +5 -0
  201. package/src/listeners/browser.ts +13 -9
  202. package/src/logger/constants.ts +5 -2
  203. package/src/logger/messages/debug.ts +3 -3
  204. package/src/logger/messages/error.ts +4 -3
  205. package/src/logger/messages/info.ts +6 -4
  206. package/src/logger/types.ts +4 -0
  207. package/src/sdkClient/client.ts +3 -2
  208. package/src/sdkClient/clientCS.ts +1 -1
  209. package/src/sdkClient/clientInputValidation.ts +8 -7
  210. package/src/sdkClient/sdkClient.ts +2 -5
  211. package/src/sdkClient/sdkClientMethodCS.ts +1 -6
  212. package/src/sdkClient/sdkClientMethodCSWithTT.ts +2 -11
  213. package/src/sdkFactory/index.ts +9 -7
  214. package/src/sdkFactory/types.ts +2 -1
  215. package/src/sdkFactory/userConsentProps.ts +40 -0
  216. package/src/storages/KeyBuilder.ts +2 -6
  217. package/src/storages/KeyBuilderCS.ts +13 -1
  218. package/src/storages/inLocalStorage/MySegmentsCacheInLocal.ts +23 -3
  219. package/src/storages/inLocalStorage/index.ts +1 -1
  220. package/src/storages/inMemory/ImpressionsCacheInMemory.ts +22 -1
  221. package/src/storages/inMemory/InMemoryStorage.ts +1 -1
  222. package/src/storages/inMemory/InMemoryStorageCS.ts +1 -1
  223. package/src/storages/inRedis/RedisAdapter.ts +8 -2
  224. package/src/storages/pluggable/index.ts +2 -2
  225. package/src/storages/types.ts +6 -2
  226. package/src/sync/offline/splitsParser/splitsParserFromFile.ts +1 -1
  227. package/src/sync/streaming/SSEClient/index.ts +2 -1
  228. package/src/sync/streaming/pushManager.ts +11 -2
  229. package/src/sync/submitters/eventsSyncTask.ts +19 -6
  230. package/src/sync/submitters/impressionsSyncTask.ts +16 -1
  231. package/src/sync/syncManagerOnline.ts +13 -7
  232. package/src/sync/types.ts +4 -1
  233. package/src/trackers/eventTracker.ts +11 -3
  234. package/src/trackers/impressionObserver/utils.ts +8 -1
  235. package/src/trackers/impressionsTracker.ts +7 -8
  236. package/src/types.ts +22 -1
  237. package/src/utils/consent.ts +8 -0
  238. package/src/utils/constants/index.ts +5 -0
  239. package/src/utils/inputValidation/attributes.ts +1 -2
  240. package/src/utils/lang/index.ts +15 -4
  241. package/src/utils/lang/maps.ts +15 -1
  242. package/src/utils/settingsValidation/consent.ts +16 -0
  243. package/src/utils/settingsValidation/impressionsMode.ts +8 -8
  244. package/src/utils/settingsValidation/index.ts +29 -10
  245. package/src/utils/settingsValidation/runtime.ts +9 -0
  246. package/src/utils/settingsValidation/types.ts +12 -6
  247. package/types/evaluator/types.d.ts +2 -2
  248. package/types/evaluator/value/index.d.ts +1 -1
  249. package/types/evaluator/value/sanitize.d.ts +1 -1
  250. package/types/integrations/ga/GoogleAnalyticsToSplit.d.ts +2 -2
  251. package/types/integrations/ga/SplitToGoogleAnalytics.d.ts +2 -3
  252. package/types/integrations/types.d.ts +4 -0
  253. package/types/logger/constants.d.ts +5 -2
  254. package/types/logger/types.d.ts +4 -0
  255. package/types/sdkClient/clientAttributesDecoration.d.ts +1 -1
  256. package/types/sdkClient/clientInputValidation.d.ts +2 -3
  257. package/types/sdkFactory/types.d.ts +1 -1
  258. package/types/sdkFactory/userConsentProps.d.ts +6 -0
  259. package/types/storages/KeyBuilderCS.d.ts +2 -0
  260. package/types/storages/inMemory/ImpressionsCacheInMemory.d.ts +9 -0
  261. package/types/storages/inRedis/RedisAdapter.d.ts +1 -1
  262. package/types/storages/types.d.ts +3 -1
  263. package/types/sync/types.d.ts +3 -0
  264. package/types/trackers/eventTracker.d.ts +2 -2
  265. package/types/trackers/impressionObserver/utils.d.ts +4 -0
  266. package/types/trackers/impressionsTracker.d.ts +2 -3
  267. package/types/types.d.ts +22 -1
  268. package/types/utils/consent.d.ts +2 -0
  269. package/types/utils/constants/index.d.ts +3 -0
  270. package/types/utils/lang/index.d.ts +6 -1
  271. package/types/utils/lang/maps.d.ts +7 -0
  272. package/types/utils/settingsValidation/consent.d.ts +6 -0
  273. package/types/utils/settingsValidation/impressionsMode.d.ts +1 -1
  274. package/types/utils/settingsValidation/runtime/browser.d.ts +2 -0
  275. package/types/utils/settingsValidation/runtime/node.d.ts +2 -0
  276. package/types/utils/settingsValidation/runtime.d.ts +2 -0
  277. package/types/utils/settingsValidation/types.d.ts +12 -6
  278. package/types/utils/settingsValidation/userConsent.d.ts +5 -0
@@ -6,6 +6,8 @@ var mode_1 = require("./mode");
6
6
  var splitFilters_1 = require("./splitFilters");
7
7
  var constants_1 = require("../constants");
8
8
  var impressionsMode_1 = require("./impressionsMode");
9
+ var key_1 = require("../inputValidation/key");
10
+ var trafficType_1 = require("../inputValidation/trafficType");
9
11
  var base = {
10
12
  // Define which kind of object you want to retrieve from SplitFactory
11
13
  mode: constants_1.STANDALONE_MODE,
@@ -36,6 +38,8 @@ var base = {
36
38
  eventsPushRate: 60,
37
39
  // how many events will be queued before flushing
38
40
  eventsQueueSize: 500,
41
+ // how many impressions will be queued before flushing
42
+ impressionsQueueSize: 30000,
39
43
  // backoff base seconds to wait before re attempting to connect to push notifications
40
44
  pushRetryBackoffBase: 1,
41
45
  },
@@ -67,10 +71,6 @@ var base = {
67
71
  impressionsMode: constants_1.OPTIMIZED,
68
72
  localhostMode: undefined
69
73
  },
70
- runtime: {
71
- ip: false,
72
- hostname: false
73
- },
74
74
  // Logger
75
75
  log: undefined
76
76
  };
@@ -85,9 +85,9 @@ function fromSecondsToMillis(n) {
85
85
  * @param validationParams defaults and fields validators used to validate and creates a settings object from a given config
86
86
  */
87
87
  function settingsValidation(config, validationParams) {
88
- var defaults = validationParams.defaults, runtime = validationParams.runtime, storage = validationParams.storage, integrations = validationParams.integrations, logger = validationParams.logger, localhost = validationParams.localhost;
88
+ var defaults = validationParams.defaults, runtime = validationParams.runtime, storage = validationParams.storage, integrations = validationParams.integrations, logger = validationParams.logger, localhost = validationParams.localhost, consent = validationParams.consent;
89
89
  // creates a settings object merging base, defaults and config objects.
90
- var withDefaults = lang_1.merge({}, base, defaults, config);
90
+ var withDefaults = (0, lang_1.merge)({}, base, defaults, config);
91
91
  // ensure a valid logger.
92
92
  // First thing to validate, since other validators might use the logger.
93
93
  var log = logger(withDefaults); // @ts-ignore, modify readonly prop
@@ -106,19 +106,34 @@ function settingsValidation(config, validationParams) {
106
106
  startup.eventsFirstPushWindow = fromSecondsToMillis(startup.eventsFirstPushWindow);
107
107
  // ensure a valid SDK mode
108
108
  // @ts-ignore, modify readonly prop
109
- withDefaults.mode = mode_1.mode(withDefaults.core.authorizationKey, withDefaults.mode);
109
+ withDefaults.mode = (0, mode_1.mode)(withDefaults.core.authorizationKey, withDefaults.mode);
110
110
  // ensure a valid Storage based on mode defined.
111
111
  // @ts-ignore, modify readonly prop
112
112
  if (storage)
113
113
  withDefaults.storage = storage(withDefaults);
114
- // Although `key` is mandatory according to TS declaration files, it can be omitted in LOCALHOST mode. In that case, the value `localhost_key` is used.
115
- if (withDefaults.mode === constants_1.LOCALHOST_MODE && withDefaults.core.key === undefined) {
116
- withDefaults.core.key = 'localhost_key';
114
+ // Validate key and TT (for client-side)
115
+ if (validationParams.acceptKey) {
116
+ var maybeKey = withDefaults.core.key;
117
+ // Although `key` is required in client-side, it can be omitted in LOCALHOST mode. In that case, the value `localhost_key` is used.
118
+ if (withDefaults.mode === constants_1.LOCALHOST_MODE && maybeKey === undefined) {
119
+ withDefaults.core.key = 'localhost_key';
120
+ }
121
+ else {
122
+ // Keeping same behaviour than JS SDK: if settings key or TT are invalid,
123
+ // `false` value is used as binded key/TT of the default client, which leads to some issues.
124
+ // @ts-ignore, @TODO handle invalid keys as a non-recoverable error?
125
+ withDefaults.core.key = (0, key_1.validateKey)(log, maybeKey, 'Client instantiation');
126
+ }
127
+ if (validationParams.acceptTT) {
128
+ var maybeTT = withDefaults.core.trafficType;
129
+ if (maybeTT !== undefined) { // @ts-ignore
130
+ withDefaults.core.trafficType = (0, trafficType_1.validateTrafficType)(log, maybeTT, 'Client instantiation');
131
+ }
132
+ }
117
133
  }
118
134
  // Current ip/hostname information
119
135
  // @ts-ignore, modify readonly prop
120
- if (runtime)
121
- withDefaults.runtime = runtime(withDefaults);
136
+ withDefaults.runtime = runtime(withDefaults);
122
137
  // ensure a valid list of integrations.
123
138
  // `integrations` returns an array of valid integration items.
124
139
  // @ts-ignore, modify readonly prop
@@ -134,11 +149,14 @@ function settingsValidation(config, validationParams) {
134
149
  scheduler.pushRetryBackoffBase = fromSecondsToMillis(scheduler.pushRetryBackoffBase);
135
150
  }
136
151
  // validate the `splitFilters` settings and parse splits query
137
- var splitFiltersValidation = splitFilters_1.validateSplitFilters(log, withDefaults.sync.splitFilters, withDefaults.mode);
152
+ var splitFiltersValidation = (0, splitFilters_1.validateSplitFilters)(log, withDefaults.sync.splitFilters, withDefaults.mode);
138
153
  withDefaults.sync.splitFilters = splitFiltersValidation.validFilters;
139
154
  withDefaults.sync.__splitFiltersValidation = splitFiltersValidation;
140
155
  // ensure a valid impressionsMode
141
- withDefaults.sync.impressionsMode = impressionsMode_1.validImpressionsMode(log, withDefaults.sync.impressionsMode);
156
+ withDefaults.sync.impressionsMode = (0, impressionsMode_1.validImpressionsMode)(log, withDefaults.sync.impressionsMode);
157
+ // ensure a valid user consent value
158
+ // @ts-ignore, modify readonly prop
159
+ withDefaults.userConsent = consent(withDefaults);
142
160
  return withDefaults;
143
161
  }
144
162
  exports.settingsValidation = settingsValidation;
@@ -13,6 +13,6 @@ var lang_1 = require("../../lang");
13
13
  */
14
14
  function validateConfigurableIntegrations(settings, validIntegrationTypes) {
15
15
  if (validIntegrationTypes === void 0) { validIntegrationTypes = []; }
16
- return common_1.validateIntegrations(settings, function (integration) { return integration && lang_1.isString(integration.type) && validIntegrationTypes.indexOf(integration.type) > -1; }, 'Integration items must have a valid "type" value');
16
+ return (0, common_1.validateIntegrations)(settings, function (integration) { return integration && (0, lang_1.isString)(integration.type) && validIntegrationTypes.indexOf(integration.type) > -1; }, 'Integration items must have a valid "type" value');
17
17
  }
18
18
  exports.validateConfigurableIntegrations = validateConfigurableIntegrations;
@@ -10,6 +10,6 @@ var common_1 = require("./common");
10
10
  * @returns {Array} array of valid integration factories. The array might be empty if `settings` object does not have valid integrations.
11
11
  */
12
12
  function validatePluggableIntegrations(settings) {
13
- return common_1.validateIntegrations(settings, function (integration) { return typeof integration === 'function'; }, 'Integration items must be functions that initialize the integrations');
13
+ return (0, common_1.validateIntegrations)(settings, function (integration) { return typeof integration === 'function'; }, 'Integration items must be functions that initialize the integrations');
14
14
  }
15
15
  exports.validatePluggableIntegrations = validatePluggableIntegrations;
@@ -12,7 +12,7 @@ var pluggable_1 = require("./pluggable");
12
12
  */
13
13
  function validateLocalhostWithDefault(settings) {
14
14
  if (!settings.sync.localhostMode)
15
- return LocalhostFromObject_1.LocalhostFromObject();
16
- return pluggable_1.validateLocalhost(settings) || LocalhostFromObject_1.LocalhostFromObject();
15
+ return (0, LocalhostFromObject_1.LocalhostFromObject)();
16
+ return (0, pluggable_1.validateLocalhost)(settings) || (0, LocalhostFromObject_1.LocalhostFromObject)();
17
17
  }
18
18
  exports.validateLocalhostWithDefault = validateLocalhostWithDefault;
@@ -19,14 +19,14 @@ var ENV_VAR_KEY = 'SPLITIO_DEBUG';
19
19
  */
20
20
  var initialState = String(
21
21
  // eslint-disable-next-line no-undef
22
- isNode_1.isNode ? process.env[ENV_VAR_KEY] : isLocalStorageAvailable_1.isLocalStorageAvailable() ? localStorage.getItem(LS_KEY) : '');
22
+ isNode_1.isNode ? process.env[ENV_VAR_KEY] : (0, isLocalStorageAvailable_1.isLocalStorageAvailable)() ? localStorage.getItem(LS_KEY) : '');
23
23
  // By default it starts disabled.
24
24
  var initialLogLevel = logger_1.LogLevels.NONE;
25
25
  // Kept to avoid a breaking change ('on', 'enable' and 'enabled' are equivalent)
26
26
  if (/^(enabled?|on)/i.test(initialState)) {
27
27
  initialLogLevel = logger_1.LogLevels.DEBUG;
28
28
  }
29
- else if (logger_1.isLogLevelString(initialState)) {
29
+ else if ((0, logger_1.isLogLevelString)(initialState)) {
30
30
  initialLogLevel = initialState;
31
31
  }
32
32
  /**
@@ -37,7 +37,7 @@ else if (logger_1.isLogLevelString(initialState)) {
37
37
  */
38
38
  function validateLogger(settings) {
39
39
  var debug = settings.debug;
40
- var logLevel = debug !== undefined ? commons_1.getLogLevel(debug) : initialLogLevel;
40
+ var logLevel = debug !== undefined ? (0, commons_1.getLogLevel)(debug) : initialLogLevel;
41
41
  var log = new logger_1.Logger({ logLevel: logLevel || initialLogLevel }, allCodes);
42
42
  // @ts-ignore // if logLevel is undefined at this point, it means that settings `debug` value is invalid
43
43
  if (!logLevel)
@@ -18,7 +18,7 @@ function getLogLevel(debugValue) {
18
18
  return logger_1.LogLevels.NONE;
19
19
  }
20
20
  }
21
- else if (typeof debugValue === 'string' && logger_1.isLogLevelString(debugValue)) {
21
+ else if (typeof debugValue === 'string' && (0, logger_1.isLogLevelString)(debugValue)) {
22
22
  return debugValue;
23
23
  }
24
24
  else {
@@ -21,7 +21,7 @@ function validateLogger(settings) {
21
21
  if (debug !== undefined) {
22
22
  if (isLogger(debug))
23
23
  return debug;
24
- logLevel = commons_1.getLogLevel(settings.debug);
24
+ logLevel = (0, commons_1.getLogLevel)(settings.debug);
25
25
  }
26
26
  var log = new logger_1.Logger({ logLevel: logLevel || initialLogLevel });
27
27
  // @ts-ignore // `debug` value is invalid if logLevel is undefined at this point
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateRuntime = void 0;
4
+ // For client-side SDKs, machine IP and Hostname are not captured and sent to Split backend.
5
+ function validateRuntime() {
6
+ return {
7
+ ip: false,
8
+ hostname: false
9
+ };
10
+ }
11
+ exports.validateRuntime = validateRuntime;
@@ -36,7 +36,7 @@ function validateFilterType(maybeFilterType) {
36
36
  */
37
37
  function validateSplitFilter(log, type, values, maxLength) {
38
38
  // validate and remove invalid and duplicated values
39
- var result = splits_1.validateSplits(log, values, constants_2.LOG_PREFIX_SETTINGS, type + " filter", type + " filter value");
39
+ var result = (0, splits_1.validateSplits)(log, values, constants_2.LOG_PREFIX_SETTINGS, type + " filter", type + " filter value");
40
40
  if (result) {
41
41
  // check max length
42
42
  if (result.length > maxLength)
@@ -5,7 +5,7 @@ var InMemoryStorageCS_1 = require("../../../storages/inMemory/InMemoryStorageCS"
5
5
  var constants_1 = require("../../../logger/constants");
6
6
  var constants_2 = require("../../../utils/constants");
7
7
  function __InLocalStorageMockFactory(params) {
8
- var result = InMemoryStorageCS_1.InMemoryStorageCSFactory(params);
8
+ var result = (0, InMemoryStorageCS_1.InMemoryStorageCSFactory)(params);
9
9
  result.splits.checkCache = function () { return true; }; // to emit SDK_READY_FROM_CACHE
10
10
  return result;
11
11
  }
@@ -125,12 +125,12 @@ exports.TrackerAPI = {
125
125
  * @return {Function | Promise} The stop function for this specific task or the promise received with the callbacks registered.
126
126
  */
127
127
  start: function (log, task, collectors, promise, now) {
128
- var taskUniqueId = lang_1.uniqueId();
128
+ var taskUniqueId = (0, lang_1.uniqueId)();
129
129
  var taskCollector = getCollectorForTask(task, collectors);
130
130
  var result;
131
131
  // If we are registering a promise with this task, we should count the status and the exceptions as well
132
132
  // as stopping the task when the promise resolves. Then return the promise
133
- if (thenable_1.thenable(promise)) {
133
+ if ((0, thenable_1.thenable)(promise)) {
134
134
  result = this.__attachToPromise(log, promise, task, taskCollector, taskUniqueId);
135
135
  }
136
136
  else {
@@ -147,7 +147,7 @@ exports.TrackerAPI = {
147
147
  var cb = getCallbackForTask(task, taskCollector);
148
148
  timers[trackingKey] = {
149
149
  cb: cb,
150
- timer: timer_1.timer(now)
150
+ timer: (0, timer_1.timer)(now)
151
151
  };
152
152
  return result;
153
153
  },
@@ -1,7 +1,9 @@
1
1
  import { GaToSplit } from './GaToSplit';
2
2
  export function GoogleAnalyticsToSplit(options) {
3
3
  // GaToSplit integration factory
4
- return function (params) {
4
+ function GoogleAnalyticsToSplitFactory(params) {
5
5
  return GaToSplit(options, params);
6
- };
6
+ }
7
+ GoogleAnalyticsToSplitFactory.type = 'GOOGLE_ANALYTICS_TO_SPLIT';
8
+ return GoogleAnalyticsToSplitFactory;
7
9
  }
@@ -2,7 +2,9 @@ import { SplitToGa } from './SplitToGa';
2
2
  export function SplitToGoogleAnalytics(options) {
3
3
  if (options === void 0) { options = {}; }
4
4
  // SplitToGa integration factory
5
- return function (params) {
5
+ function SplitToGoogleAnalyticsFactory(params) {
6
6
  return new SplitToGa(params.settings.log, options);
7
- };
7
+ }
8
+ SplitToGoogleAnalyticsFactory.type = 'SPLIT_TO_GOOGLE_ANALYTICS';
9
+ return SplitToGoogleAnalyticsFactory;
8
10
  }
@@ -3,6 +3,7 @@ import { fromImpressionCountsCollector } from '../sync/submitters/impressionCoun
3
3
  import { OPTIMIZED, DEBUG } from '../utils/constants';
4
4
  import { objectAssign } from '../utils/lang/objectAssign';
5
5
  import { CLEANUP_REGISTERING, CLEANUP_DEREGISTERING } from '../logger/constants';
6
+ import { isConsentGranted } from '../utils/consent';
6
7
  // 'unload' event is used instead of 'beforeunload', since 'unload' is not a cancelable event, so no other listeners can stop the event from occurring.
7
8
  var UNLOAD_DOM_EVENT = 'unload';
8
9
  var EVENT_NAME = 'for unload page event.';
@@ -48,15 +49,18 @@ var BrowserSignalListener = /** @class */ (function () {
48
49
  BrowserSignalListener.prototype.flushData = function () {
49
50
  if (!this.syncManager)
50
51
  return; // In consumer mode there is not sync manager and data to flush
51
- var eventsUrl = this.settings.urls.events;
52
- var extraMetadata = {
53
- // sim stands for Sync/Split Impressions Mode
54
- sim: this.settings.sync.impressionsMode === OPTIMIZED ? OPTIMIZED : DEBUG
55
- };
56
- this._flushData(eventsUrl + '/testImpressions/beacon', this.storage.impressions, this.serviceApi.postTestImpressionsBulk, this.fromImpressionsCollector, extraMetadata);
57
- this._flushData(eventsUrl + '/events/beacon', this.storage.events, this.serviceApi.postEventsBulk);
58
- if (this.storage.impressionCounts)
59
- this._flushData(eventsUrl + '/testImpressions/count/beacon', this.storage.impressionCounts, this.serviceApi.postTestImpressionsCount, fromImpressionCountsCollector);
52
+ // Flush data if there is user consent
53
+ if (isConsentGranted(this.settings)) {
54
+ var eventsUrl = this.settings.urls.events;
55
+ var extraMetadata = {
56
+ // sim stands for Sync/Split Impressions Mode
57
+ sim: this.settings.sync.impressionsMode === OPTIMIZED ? OPTIMIZED : DEBUG
58
+ };
59
+ this._flushData(eventsUrl + '/testImpressions/beacon', this.storage.impressions, this.serviceApi.postTestImpressionsBulk, this.fromImpressionsCollector, extraMetadata);
60
+ this._flushData(eventsUrl + '/events/beacon', this.storage.events, this.serviceApi.postEventsBulk);
61
+ if (this.storage.impressionCounts)
62
+ this._flushData(eventsUrl + '/testImpressions/count/beacon', this.storage.impressionCounts, this.serviceApi.postTestImpressionsCount, fromImpressionCountsCollector);
63
+ }
60
64
  // Close streaming connection
61
65
  if (this.syncManager.pushManager)
62
66
  this.syncManager.pushManager.stop();
@@ -66,7 +70,7 @@ var BrowserSignalListener = /** @class */ (function () {
66
70
  if (!cache.isEmpty()) {
67
71
  var dataPayload = fromCacheToPayload ? fromCacheToPayload(cache.state()) : cache.state();
68
72
  if (!this._sendBeacon(url, dataPayload, extraMetadata)) {
69
- postService(JSON.stringify(dataPayload)).catch(function () { }); // no-op just to catch a possible exceptions
73
+ postService(JSON.stringify(dataPayload)).catch(function () { }); // no-op just to catch a possible exception
70
74
  }
71
75
  cache.clear();
72
76
  }
@@ -60,13 +60,15 @@ export var STREAMING_RECONNECT = 111;
60
60
  export var STREAMING_CONNECTING = 112;
61
61
  export var STREAMING_DISABLED = 113;
62
62
  export var STREAMING_DISCONNECTING = 114;
63
- export var SUBMITTERS_PUSH_FULL_EVENTS_QUEUE = 115;
63
+ export var SUBMITTERS_PUSH_FULL_QUEUE = 115;
64
64
  export var SUBMITTERS_PUSH = 116;
65
65
  export var SYNC_START_POLLING = 117;
66
66
  export var SYNC_CONTINUE_POLLING = 118;
67
67
  export var SYNC_STOP_POLLING = 119;
68
68
  export var EVENTS_TRACKER_SUCCESS = 120;
69
69
  export var IMPRESSIONS_TRACKER_SUCCESS = 121;
70
+ export var USER_CONSENT_UPDATED = 122;
71
+ export var USER_CONSENT_NOT_UPDATED = 123;
70
72
  export var ENGINE_VALUE_INVALID = 200;
71
73
  export var ENGINE_VALUE_NO_ATTRIBUTES = 201;
72
74
  export var CLIENT_NO_LISTENER = 202;
@@ -112,10 +114,11 @@ export var ERROR_INVALID_KEY_OBJECT = 317;
112
114
  export var ERROR_INVALID = 318;
113
115
  export var ERROR_EMPTY = 319;
114
116
  export var ERROR_EMPTY_ARRAY = 320;
115
- export var ERROR_INVALID_IMPRESSIONS_MODE = 321;
117
+ export var ERROR_INVALID_CONFIG_PARAM = 321;
116
118
  export var ERROR_HTTP = 322;
117
119
  export var ERROR_LOCALHOST_MODULE_REQUIRED = 323;
118
120
  export var ERROR_STORAGE_INVALID = 324;
121
+ export var ERROR_NOT_BOOLEAN = 325;
119
122
  // Log prefixes (a.k.a. tags or categories)
120
123
  export var LOG_PREFIX_SETTINGS = 'settings';
121
124
  export var LOG_PREFIX_INSTANTIATION = 'Factory instantiation';
@@ -30,9 +30,9 @@ export var codesDebug = codesInfo.concat([
30
30
  // SDK
31
31
  [c.CLEANUP_REGISTERING, c.LOG_PREFIX_CLEANUP + 'Registering cleanup handler %s'],
32
32
  [c.CLEANUP_DEREGISTERING, c.LOG_PREFIX_CLEANUP + 'Deregistering cleanup handler %s'],
33
- [c.RETRIEVE_CLIENT_DEFAULT, ' Retrieving default SDK client.'],
34
- [c.RETRIEVE_CLIENT_EXISTING, ' Retrieving existing SDK client.'],
35
- [c.RETRIEVE_MANAGER, ' Retrieving manager instance.'],
33
+ [c.RETRIEVE_CLIENT_DEFAULT, 'Retrieving default SDK client.'],
34
+ [c.RETRIEVE_CLIENT_EXISTING, 'Retrieving existing SDK client.'],
35
+ [c.RETRIEVE_MANAGER, 'Retrieving manager instance.'],
36
36
  // synchronizer
37
37
  [c.SYNC_OFFLINE_DATA, c.LOG_PREFIX_SYNC_OFFLINE + 'Splits data: \n%s'],
38
38
  [c.SYNC_SPLITS_FETCH, c.LOG_PREFIX_SYNC_SPLITS + 'Spin up split update using since = %s'],
@@ -4,7 +4,7 @@ export var codesError = [
4
4
  [c.ERROR_ENGINE_COMBINER_IFELSEIF, c.LOG_PREFIX_ENGINE_COMBINER + 'Invalid Split, no valid rules found'],
5
5
  // SDK
6
6
  [c.ERROR_LOGLEVEL_INVALID, 'logger: Invalid Log Level - No changes to the logs will be applied.'],
7
- [c.ERROR_CLIENT_CANNOT_GET_READY, ' The SDK will not get ready. Reason: %s'],
7
+ [c.ERROR_CLIENT_CANNOT_GET_READY, 'The SDK will not get ready. Reason: %s'],
8
8
  [c.ERROR_IMPRESSIONS_TRACKER, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Could not store impressions bulk with %s impression(s). Error: %s'],
9
9
  [c.ERROR_IMPRESSIONS_LISTENER, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Impression listener logImpression method threw: %s.'],
10
10
  [c.ERROR_EVENTS_TRACKER, c.LOG_PREFIX_EVENTS_TRACKER + 'Failed to queue %s'],
@@ -12,7 +12,7 @@ export var codesError = [
12
12
  [c.ERROR_SYNC_OFFLINE_LOADING, c.LOG_PREFIX_SYNC_OFFLINE + 'There was an issue loading the mock Splits data, no changes will be applied to the current cache. %s'],
13
13
  [c.ERROR_STREAMING_SSE, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to connect or error on streaming connection, with error message: %s'],
14
14
  [c.ERROR_STREAMING_AUTH, c.LOG_PREFIX_SYNC_STREAMING + 'Failed to authenticate for streaming. Error: %s.'],
15
- [c.ERROR_HTTP, ' Response status is not OK. Status: %s. URL: %s. Message: %s'],
15
+ [c.ERROR_HTTP, 'Response status is not OK. Status: %s. URL: %s. Message: %s'],
16
16
  // client status
17
17
  [c.ERROR_CLIENT_LISTENER, 'A listener was added for %s on the SDK, which has already fired and won\'t be emitted again. The callback won\'t be executed.'],
18
18
  [c.ERROR_CLIENT_DESTROYED, '%s: Client has already been destroyed - no calls possible.'],
@@ -27,8 +27,9 @@ export var codesError = [
27
27
  [c.ERROR_INVALID, '%s: you passed an invalid %s. It must be a non-empty string.'],
28
28
  [c.ERROR_EMPTY, '%s: you passed an empty %s. It must be a non-empty string.'],
29
29
  [c.ERROR_EMPTY_ARRAY, '%s: %s must be a non-empty array.'],
30
+ [c.ERROR_NOT_BOOLEAN, '%s: provided param must be a boolean value.'],
30
31
  // initialization / settings validation
31
- [c.ERROR_INVALID_IMPRESSIONS_MODE, c.LOG_PREFIX_SETTINGS + ': you passed an invalid "impressionsMode". It should be one of the following values: %s. Defaulting to "%s" mode.'],
32
+ [c.ERROR_INVALID_CONFIG_PARAM, c.LOG_PREFIX_SETTINGS + ': you passed an invalid "%s" config param. It should be one of the following values: %s. Defaulting to "%s".'],
32
33
  [c.ERROR_LOCALHOST_MODULE_REQUIRED, c.LOG_PREFIX_SETTINGS + ': an invalid value was received for "sync.localhostMode" config. A valid entity should be provided for localhost mode.'],
33
34
  [c.ERROR_STORAGE_INVALID, c.LOG_PREFIX_SETTINGS + ': The provided storage is invalid.%s Fallbacking into default MEMORY storage'],
34
35
  ];
@@ -8,16 +8,18 @@ export var codesInfo = codesWarn.concat([
8
8
  // SDK
9
9
  [c.IMPRESSION, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Split: %s. Key: %s. Evaluation: %s. Label: %s'],
10
10
  [c.IMPRESSION_QUEUEING, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Queueing corresponding impression.'],
11
- [c.NEW_SHARED_CLIENT, ' New shared client instance created.'],
12
- [c.NEW_FACTORY, ' New Split SDK instance created.'],
11
+ [c.NEW_SHARED_CLIENT, 'New shared client instance created.'],
12
+ [c.NEW_FACTORY, 'New Split SDK instance created.'],
13
13
  [c.EVENTS_TRACKER_SUCCESS, c.LOG_PREFIX_EVENTS_TRACKER + 'Successfully queued %s'],
14
14
  [c.IMPRESSIONS_TRACKER_SUCCESS, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Successfully stored %s impression(s).'],
15
+ [c.USER_CONSENT_UPDATED, 'setUserConsent: consent status changed from %s to %s.'],
16
+ [c.USER_CONSENT_NOT_UPDATED, 'setUserConsent: call had no effect because it was the current consent status (%s).'],
15
17
  // synchronizer
16
18
  [c.POLLING_SMART_PAUSING, c.LOG_PREFIX_SYNC_POLLING + 'Turning segments data polling %s.'],
17
19
  [c.POLLING_START, c.LOG_PREFIX_SYNC_POLLING + 'Starting polling'],
18
20
  [c.POLLING_STOP, c.LOG_PREFIX_SYNC_POLLING + 'Stopping polling'],
19
21
  [c.SYNC_SPLITS_FETCH_RETRY, c.LOG_PREFIX_SYNC_SPLITS + 'Retrying download of splits #%s. Reason: %s'],
20
- [c.SUBMITTERS_PUSH_FULL_EVENTS_QUEUE, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Flushing full events queue and reseting timer.'],
22
+ [c.SUBMITTERS_PUSH_FULL_QUEUE, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Flushing full %s queue and reseting timer.'],
21
23
  [c.SUBMITTERS_PUSH, c.LOG_PREFIX_SYNC_SUBMITTERS + 'Pushing %s %s.'],
22
24
  [c.STREAMING_REFRESH_TOKEN, c.LOG_PREFIX_SYNC_STREAMING + 'Refreshing streaming token in %s seconds, and connecting streaming in %s seconds.'],
23
25
  [c.STREAMING_RECONNECT, c.LOG_PREFIX_SYNC_STREAMING + 'Attempting to reconnect streaming in %s seconds.'],
@@ -26,5 +28,5 @@ export var codesInfo = codesWarn.concat([
26
28
  [c.STREAMING_DISCONNECTING, c.LOG_PREFIX_SYNC_STREAMING + 'Disconnecting streaming.'],
27
29
  [c.SYNC_START_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming not available. Starting polling.'],
28
30
  [c.SYNC_CONTINUE_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming couldn\'t connect. Continue polling.'],
29
- [c.SYNC_STOP_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming (re)connected. Syncing and stopping polling.'],
31
+ [c.SYNC_STOP_POLLING, c.LOG_PREFIX_SYNC_MANAGER + 'Streaming connected. Syncing and stopping polling.'],
30
32
  ]);
@@ -11,7 +11,8 @@ import { IMPRESSION, IMPRESSION_QUEUEING } from '../logger/constants';
11
11
  */
12
12
  // @TODO missing time tracking to collect telemetry
13
13
  export function clientFactory(params) {
14
- var readinessManager = params.sdkReadinessManager.readinessManager, storage = params.storage, _a = params.settings, log = _a.log, mode = _a.mode, impressionsTracker = params.impressionsTracker, eventTracker = params.eventTracker;
14
+ var readinessManager = params.sdkReadinessManager.readinessManager, storage = params.storage, settings = params.settings, impressionsTracker = params.impressionsTracker, eventTracker = params.eventTracker;
15
+ var log = settings.log, mode = settings.mode;
15
16
  function getTreatment(key, splitName, attributes, withConfig) {
16
17
  if (withConfig === void 0) { withConfig = false; }
17
18
  var wrapUp = function (evaluationResult) {
@@ -96,6 +97,6 @@ export function clientFactory(params) {
96
97
  getTreatments: getTreatments,
97
98
  getTreatmentsWithConfig: getTreatmentsWithConfig,
98
99
  track: track,
99
- isBrowserClient: false
100
+ isClientSide: false
100
101
  };
101
102
  }
@@ -17,6 +17,6 @@ export function clientCSDecorator(log, client, key, trafficType) {
17
17
  getTreatmentsWithConfig: clientCS.getTreatmentsWithConfig.bind(clientCS, key),
18
18
  // Key is bound to the `track` method. Same thing happens with trafficType but only if provided
19
19
  track: trafficType ? clientCS.track.bind(clientCS, key, trafficType) : clientCS.track.bind(clientCS, key),
20
- isBrowserClient: true
20
+ isClientSide: true
21
21
  });
22
22
  }
@@ -2,12 +2,14 @@ import { objectAssign } from '../utils/lang/objectAssign';
2
2
  import { validateAttributes, validateEvent, validateEventValue, validateEventProperties, validateKey, validateSplit, validateSplits, validateTrafficType, validateIfNotDestroyed, validateIfOperational } from '../utils/inputValidation';
3
3
  import { startsWith } from '../utils/lang';
4
4
  import { CONTROL, CONTROL_WITH_CONFIG } from '../utils/constants';
5
+ import { isStorageSync } from '../trackers/impressionObserver/utils';
5
6
  /**
6
7
  * Decorator that validates the input before actually executing the client methods.
7
8
  * We should "guard" the client here, while not polluting the "real" implementation of those methods.
8
9
  */
9
- export function clientInputValidationDecorator(log, client, readinessManager, isStorageSync) {
10
- if (isStorageSync === void 0) { isStorageSync = false; }
10
+ export function clientInputValidationDecorator(settings, client, readinessManager) {
11
+ var log = settings.log;
12
+ var isSync = isStorageSync(settings);
11
13
  /**
12
14
  * Avoid repeating this validations code
13
15
  */
@@ -27,9 +29,7 @@ export function clientInputValidationDecorator(log, client, readinessManager, is
27
29
  };
28
30
  }
29
31
  function wrapResult(value) {
30
- if (isStorageSync)
31
- return value;
32
- return Promise.resolve(value);
32
+ return isSync ? value : Promise.resolve(value);
33
33
  }
34
34
  function getTreatment(maybeKey, maybeSplit, maybeAttributes) {
35
35
  var params = validateEvaluationParams(maybeKey, maybeSplit, maybeAttributes, 'getTreatment');
@@ -84,9 +84,7 @@ export function clientInputValidationDecorator(log, client, readinessManager, is
84
84
  return client.track(key, tt, event, eventValue, properties, size);
85
85
  }
86
86
  else {
87
- if (isStorageSync)
88
- return false;
89
- return Promise.resolve(false);
87
+ return isSync ? false : Promise.resolve(false);
90
88
  }
91
89
  }
92
90
  return {
@@ -1,5 +1,4 @@
1
1
  import { objectAssign } from '../utils/lang/objectAssign';
2
- import { CONSUMER_MODE, CONSUMER_PARTIAL_MODE } from '../utils/constants';
3
2
  import { releaseApiKey } from '../utils/inputValidation/apiKey';
4
3
  import { clientFactory } from './client';
5
4
  import { clientInputValidationDecorator } from './clientInputValidation';
@@ -12,9 +11,7 @@ export function sdkClientFactory(params) {
12
11
  // Proto-linkage of the readiness Event Emitter
13
12
  Object.create(sdkReadinessManager.sdkStatus),
14
13
  // Client API (getTreatment* & track methods)
15
- clientInputValidationDecorator(settings.log, clientFactory(params), sdkReadinessManager.readinessManager,
16
- // storage is async if and only if mode is consumer or partial consumer
17
- [CONSUMER_MODE, CONSUMER_PARTIAL_MODE].indexOf(settings.mode) === -1 ? true : false),
14
+ clientInputValidationDecorator(settings, clientFactory(params), sdkReadinessManager.readinessManager),
18
15
  // Sdk destroy
19
16
  {
20
17
  destroy: function () {
@@ -16,12 +16,8 @@ var method = 'Client instantiation';
16
16
  */
17
17
  export function sdkClientMethodCSFactory(params) {
18
18
  var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, key = _a.core.key, readyTimeout = _a.startup.readyTimeout, log = _a.log;
19
- // Keeping similar behaviour as in the isomorphic JS SDK: if settings key is invalid,
20
- // `false` value is used as binded key of the default client, but trafficType is ignored
21
- // @TODO handle as a non-recoverable error
22
- var validKey = validateKey(log, key, method);
23
19
  var mainClientInstance = clientCSDecorator(log, sdkClientFactory(params), // @ts-ignore
24
- validKey);
20
+ key);
25
21
  var parsedDefaultKey = keyParser(key);
26
22
  var defaultInstanceId = buildInstanceId(parsedDefaultKey);
27
23
  // Cache instances created per factory.
@@ -18,16 +18,8 @@ var method = 'Client instantiation';
18
18
  */
19
19
  export function sdkClientMethodCSFactory(params) {
20
20
  var storage = params.storage, syncManager = params.syncManager, sdkReadinessManager = params.sdkReadinessManager, _a = params.settings, _b = _a.core, key = _b.key, trafficType = _b.trafficType, readyTimeout = _a.startup.readyTimeout, log = _a.log;
21
- // Keeping the behaviour as in the isomorphic JS SDK: if settings key or TT are invalid,
22
- // `false` value is used as binded key/TT of the default client, which leads to several issues.
23
- // @TODO update when supporting non-recoverable errors
24
- var validKey = validateKey(log, key, method);
25
- var validTrafficType;
26
- if (trafficType !== undefined) {
27
- validTrafficType = validateTrafficType(log, trafficType, method);
28
- }
29
21
  var mainClientInstance = clientCSDecorator(log, sdkClientFactory(params), // @ts-ignore
30
- validKey, validTrafficType);
22
+ key, trafficType);
31
23
  var parsedDefaultKey = keyParser(key);
32
24
  var defaultInstanceId = buildInstanceId(parsedDefaultKey, trafficType);
33
25
  // Cache instances created per factory.
@@ -8,11 +8,12 @@ import { createLoggerAPI } from '../logger/sdkLogger';
8
8
  import { NEW_FACTORY, RETRIEVE_MANAGER } from '../logger/constants';
9
9
  import { metadataBuilder } from '../storages/metadataBuilder';
10
10
  import { SDK_SPLITS_ARRIVED, SDK_SEGMENTS_ARRIVED } from '../readiness/constants';
11
+ import { objectAssign } from '../utils/lang/objectAssign';
11
12
  /**
12
13
  * Modular SDK factory
13
14
  */
14
15
  export function sdkFactory(params) {
15
- var settings = params.settings, platform = params.platform, storageFactory = params.storageFactory, splitApiFactory = params.splitApiFactory, syncManagerFactory = params.syncManagerFactory, SignalListener = params.SignalListener, impressionsObserverFactory = params.impressionsObserverFactory, impressionListener = params.impressionListener, integrationsManagerFactory = params.integrationsManagerFactory, sdkManagerFactory = params.sdkManagerFactory, sdkClientMethodFactory = params.sdkClientMethodFactory;
16
+ var settings = params.settings, platform = params.platform, storageFactory = params.storageFactory, splitApiFactory = params.splitApiFactory, extraProps = params.extraProps, syncManagerFactory = params.syncManagerFactory, SignalListener = params.SignalListener, impressionsObserverFactory = params.impressionsObserverFactory, integrationsManagerFactory = params.integrationsManagerFactory, sdkManagerFactory = params.sdkManagerFactory, sdkClientMethodFactory = params.sdkClientMethodFactory;
16
17
  var log = settings.log;
17
18
  // @TODO handle non-recoverable errors: not start sync, mark the SDK as destroyed, etc.
18
19
  // We will just log and allow for the SDK to end up throwing an SDK_TIMEOUT event for devs to handle.
@@ -22,6 +23,7 @@ export function sdkFactory(params) {
22
23
  var readinessManager = sdkReadinessManager.readinessManager;
23
24
  // @TODO consider passing the settings object, so that each storage access only what it needs
24
25
  var storageFactoryParams = {
26
+ impressionsQueueSize: settings.scheduler.impressionsQueueSize,
25
27
  eventsQueueSize: settings.scheduler.eventsQueueSize,
26
28
  optimize: shouldBeOptimized(settings),
27
29
  // ATM, only used by InLocalStorage
@@ -54,8 +56,8 @@ export function sdkFactory(params) {
54
56
  var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage });
55
57
  // trackers
56
58
  var observer = impressionsObserverFactory && impressionsObserverFactory();
57
- var impressionsTracker = impressionsTrackerFactory(log, storage.impressions, settings, impressionListener, integrationsManager, observer, storage.impressionCounts);
58
- var eventTracker = eventTrackerFactory(log, storage.events, integrationsManager);
59
+ var impressionsTracker = impressionsTrackerFactory(settings, storage.impressions, integrationsManager, observer, storage.impressionCounts);
60
+ var eventTracker = eventTrackerFactory(settings, storage.events, integrationsManager);
59
61
  // signal listener
60
62
  var signalListener = SignalListener && new SignalListener(syncManager, settings, storage, splitApi);
61
63
  // Sdk client and manager
@@ -64,11 +66,11 @@ export function sdkFactory(params) {
64
66
  syncManager && syncManager.start();
65
67
  signalListener && signalListener.start();
66
68
  log.info(NEW_FACTORY);
67
- return {
69
+ // @ts-ignore
70
+ return objectAssign({
68
71
  // Split evaluation and event tracking engine
69
72
  client: clientMethod,
70
73
  // Manager API to explore available information
71
- // @ts-ignore
72
74
  manager: function () {
73
75
  log.debug(RETRIEVE_MANAGER);
74
76
  return managerInstance;
@@ -76,5 +78,5 @@ export function sdkFactory(params) {
76
78
  // Logger wrapper API
77
79
  Logger: createLoggerAPI(settings.log),
78
80
  settings: settings,
79
- };
81
+ }, extraProps && extraProps(settings, syncManager));
80
82
  }
@@ -0,0 +1,33 @@
1
+ import { ERROR_NOT_BOOLEAN, USER_CONSENT_UPDATED, USER_CONSENT_NOT_UPDATED } from '../logger/constants';
2
+ import { CONSENT_GRANTED, CONSENT_DECLINED } from '../utils/constants';
3
+ import { isBoolean } from '../utils/lang';
4
+ // Extend client-side factory instances with user consent getter/setter
5
+ export function userConsentProps(settings, syncManager) {
6
+ var log = settings.log;
7
+ return {
8
+ setUserConsent: function (consent) {
9
+ var _a, _b;
10
+ // validate input param
11
+ if (!isBoolean(consent)) {
12
+ log.warn(ERROR_NOT_BOOLEAN, ['setUserConsent']);
13
+ return false;
14
+ }
15
+ var newConsentStatus = consent ? CONSENT_GRANTED : CONSENT_DECLINED;
16
+ if (settings.userConsent !== newConsentStatus) { // @ts-ignore, modify readonly prop
17
+ settings.userConsent = newConsentStatus;
18
+ if (consent)
19
+ (_a = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _a === void 0 ? void 0 : _a.start(); // resumes submitters if transitioning to GRANTED
20
+ else
21
+ (_b = syncManager === null || syncManager === void 0 ? void 0 : syncManager.submitter) === null || _b === void 0 ? void 0 : _b.stop(); // pauses submitters if transitioning to DECLINED
22
+ log.info(USER_CONSENT_UPDATED, [settings.userConsent, newConsentStatus]);
23
+ }
24
+ else {
25
+ log.info(USER_CONSENT_NOT_UPDATED, [newConsentStatus]);
26
+ }
27
+ return true;
28
+ },
29
+ getUserConsent: function () {
30
+ return settings.userConsent;
31
+ }
32
+ };
33
+ }