@splitsoftware/splitio-commons 2.11.1-rc.2 → 3.0.0-rc.0

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 (309) hide show
  1. package/CHANGES.txt +15 -2
  2. package/cjs/evaluator/condition/engineUtils.js +2 -2
  3. package/cjs/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +70 -0
  4. package/cjs/evaluator/fallbackConfigsCalculator/index.js +25 -0
  5. package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
  6. package/cjs/evaluator/fallbackTreatmentsCalculator/index.js +21 -32
  7. package/cjs/evaluator/index.js +67 -42
  8. package/cjs/evaluator/matchers/whitelist.js +1 -1
  9. package/cjs/integrations/pluggable.js +1 -1
  10. package/cjs/listeners/browser.js +4 -3
  11. package/cjs/listeners/node.js +4 -4
  12. package/cjs/logger/constants.js +14 -20
  13. package/cjs/logger/index.js +1 -1
  14. package/cjs/logger/messages/debug.js +6 -7
  15. package/cjs/logger/messages/error.js +4 -4
  16. package/cjs/logger/messages/info.js +2 -4
  17. package/cjs/logger/messages/warn.js +9 -9
  18. package/cjs/platform/browser.js +15 -0
  19. package/cjs/platform/getEventSource/browser.js +8 -0
  20. package/cjs/platform/getEventSource/eventsource.js +480 -0
  21. package/cjs/platform/getEventSource/node.js +26 -0
  22. package/cjs/platform/getFetch/browser.js +9 -0
  23. package/cjs/platform/getFetch/node.js +27 -0
  24. package/cjs/platform/getOptions/node.js +25 -0
  25. package/cjs/platform/node.js +17 -0
  26. package/cjs/readiness/constants.js +2 -1
  27. package/cjs/sdkClient/client.js +9 -35
  28. package/cjs/sdkClient/clientAttributesDecoration.js +3 -3
  29. package/cjs/sdkClient/clientInputValidation.js +38 -81
  30. package/cjs/sdkClient/identity.js +1 -1
  31. package/cjs/sdkClient/sdkClient.js +4 -49
  32. package/cjs/sdkClient/sdkLifecycle.js +70 -0
  33. package/cjs/sdkClient/trackMethod.js +56 -0
  34. package/cjs/sdkFactory/index.js +8 -45
  35. package/cjs/sdkManager/index.js +3 -3
  36. package/cjs/services/splitApi.js +18 -13
  37. package/cjs/services/splitHttpClient.js +1 -1
  38. package/cjs/storages/AbstractSplitsCacheAsync.js +1 -1
  39. package/cjs/storages/AbstractSplitsCacheSync.js +1 -1
  40. package/cjs/storages/KeyBuilder.js +12 -12
  41. package/cjs/storages/KeyBuilderCS.js +13 -13
  42. package/cjs/storages/KeyBuilderSS.js +15 -15
  43. package/cjs/storages/getRolloutPlan.js +1 -1
  44. package/cjs/storages/inLocalStorage/MySegmentsCacheInLocal.js +1 -1
  45. package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +1 -1
  46. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +1 -1
  47. package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
  48. package/cjs/storages/inMemory/MySegmentsCacheInMemory.js +1 -1
  49. package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +1 -1
  50. package/cjs/storages/inMemory/SplitsCacheInMemory.js +1 -1
  51. package/cjs/storages/inMemory/TelemetryCacheInMemory.js +2 -2
  52. package/cjs/storages/inRedis/EventsCacheInRedis.js +1 -1
  53. package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +5 -5
  54. package/cjs/storages/inRedis/ImpressionsCacheInRedis.js +1 -1
  55. package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
  56. package/cjs/storages/inRedis/RedisAdapter.js +8 -8
  57. package/cjs/storages/inRedis/SplitsCacheInRedis.js +6 -6
  58. package/cjs/storages/inRedis/TelemetryCacheInRedis.js +7 -7
  59. package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +3 -3
  60. package/cjs/storages/pluggable/EventsCachePluggable.js +1 -1
  61. package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +6 -6
  62. package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
  63. package/cjs/storages/pluggable/SplitsCachePluggable.js +4 -4
  64. package/cjs/storages/pluggable/TelemetryCachePluggable.js +7 -7
  65. package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +2 -2
  66. package/cjs/storages/pluggable/index.js +3 -3
  67. package/cjs/storages/pluggable/wrapperAdapter.js +1 -1
  68. package/cjs/storages/setRolloutPlan.js +1 -1
  69. package/cjs/storages/utils.js +6 -6
  70. package/cjs/sync/offline/splitsParser/parseCondition.js +1 -1
  71. package/cjs/sync/polling/fetchers/segmentChangesFetcher.js +1 -1
  72. package/cjs/sync/polling/fetchers/splitChangesFetcher.js +23 -14
  73. package/cjs/sync/polling/pollingManagerCS.js +11 -11
  74. package/cjs/sync/polling/pollingManagerSS.js +13 -13
  75. package/cjs/sync/polling/syncTasks/definitionsSyncTask.js +12 -0
  76. package/cjs/sync/polling/updaters/{splitChangesUpdater.js → definitionChangesUpdater.js} +67 -59
  77. package/cjs/sync/polling/updaters/mySegmentsUpdater.js +1 -1
  78. package/cjs/sync/polling/updaters/segmentChangesUpdater.js +6 -6
  79. package/cjs/sync/streaming/SSEClient/index.js +2 -2
  80. package/cjs/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +2 -2
  81. package/cjs/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -2
  82. package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +4 -4
  83. package/cjs/sync/streaming/parseUtils.js +12 -12
  84. package/cjs/sync/streaming/pushManager.js +2 -2
  85. package/cjs/sync/submitters/impressionsSubmitter.js +6 -6
  86. package/cjs/sync/submitters/submitter.js +1 -1
  87. package/cjs/sync/syncManagerOnline.js +5 -2
  88. package/cjs/trackers/eventTracker.js +10 -12
  89. package/cjs/trackers/impressionObserver/buildKey.js +1 -1
  90. package/cjs/trackers/impressionsTracker.js +37 -20
  91. package/cjs/trackers/uniqueKeysTracker.js +1 -1
  92. package/cjs/utils/EventEmitter.js +391 -0
  93. package/cjs/utils/filter/bloomFilter.js +37 -0
  94. package/cjs/utils/inputValidation/apiKey.js +1 -1
  95. package/cjs/utils/inputValidation/attribute.js +2 -2
  96. package/cjs/utils/inputValidation/{split.js → definition.js} +10 -10
  97. package/cjs/utils/inputValidation/{splitExistence.js → definitionExistence.js} +6 -6
  98. package/cjs/utils/inputValidation/definitions.js +25 -0
  99. package/cjs/utils/inputValidation/eventProperties.js +1 -1
  100. package/cjs/utils/inputValidation/index.js +7 -7
  101. package/cjs/utils/inputValidation/isOperational.js +4 -4
  102. package/cjs/utils/inputValidation/target.js +22 -0
  103. package/cjs/utils/labels/index.js +3 -3
  104. package/cjs/utils/lang/index.js +1 -1
  105. package/cjs/utils/promise/timeout.js +1 -1
  106. package/cjs/utils/settingsValidation/splitFilters.js +4 -4
  107. package/cjs/utils/settingsValidation/url.js +5 -5
  108. package/esm/evaluator/condition/engineUtils.js +2 -2
  109. package/esm/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +64 -0
  110. package/esm/evaluator/fallbackConfigsCalculator/index.js +21 -0
  111. package/esm/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
  112. package/esm/evaluator/fallbackTreatmentsCalculator/index.js +21 -33
  113. package/esm/evaluator/index.js +66 -42
  114. package/esm/evaluator/matchers/whitelist.js +1 -1
  115. package/esm/integrations/pluggable.js +1 -1
  116. package/esm/listeners/browser.js +4 -3
  117. package/esm/listeners/node.js +4 -4
  118. package/esm/logger/constants.js +11 -17
  119. package/esm/logger/index.js +1 -1
  120. package/esm/logger/messages/debug.js +5 -6
  121. package/esm/logger/messages/error.js +3 -3
  122. package/esm/logger/messages/info.js +1 -3
  123. package/esm/logger/messages/warn.js +8 -8
  124. package/esm/platform/browser.js +12 -0
  125. package/esm/platform/getEventSource/browser.js +4 -0
  126. package/esm/platform/getEventSource/eventsource.js +480 -0
  127. package/esm/platform/getEventSource/node.js +20 -0
  128. package/esm/platform/getFetch/browser.js +5 -0
  129. package/esm/platform/getFetch/node.js +22 -0
  130. package/esm/platform/getOptions/node.js +20 -0
  131. package/esm/platform/node.js +14 -0
  132. package/esm/readiness/constants.js +1 -0
  133. package/esm/sdkClient/client.js +10 -37
  134. package/esm/sdkClient/clientAttributesDecoration.js +3 -3
  135. package/esm/sdkClient/clientInputValidation.js +40 -83
  136. package/esm/sdkClient/identity.js +1 -1
  137. package/esm/sdkClient/sdkClient.js +4 -49
  138. package/esm/sdkClient/sdkLifecycle.js +66 -0
  139. package/esm/sdkClient/trackMethod.js +52 -0
  140. package/esm/sdkFactory/index.js +8 -45
  141. package/esm/sdkManager/index.js +4 -4
  142. package/esm/services/splitApi.js +18 -13
  143. package/esm/services/splitHttpClient.js +1 -1
  144. package/esm/storages/AbstractSplitsCacheAsync.js +1 -1
  145. package/esm/storages/AbstractSplitsCacheSync.js +1 -1
  146. package/esm/storages/KeyBuilder.js +12 -12
  147. package/esm/storages/KeyBuilderCS.js +12 -12
  148. package/esm/storages/KeyBuilderSS.js +14 -14
  149. package/esm/storages/getRolloutPlan.js +1 -1
  150. package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +1 -1
  151. package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -1
  152. package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +1 -1
  153. package/esm/storages/inMemory/TelemetryCacheInMemory.js +2 -2
  154. package/esm/storages/inRedis/EventsCacheInRedis.js +1 -1
  155. package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +4 -4
  156. package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +1 -1
  157. package/esm/storages/inRedis/RedisAdapter.js +7 -7
  158. package/esm/storages/inRedis/SplitsCacheInRedis.js +4 -4
  159. package/esm/storages/inRedis/TelemetryCacheInRedis.js +7 -7
  160. package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +1 -1
  161. package/esm/storages/pluggable/EventsCachePluggable.js +1 -1
  162. package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +5 -5
  163. package/esm/storages/pluggable/RBSegmentsCachePluggable.js +1 -1
  164. package/esm/storages/pluggable/SplitsCachePluggable.js +2 -2
  165. package/esm/storages/pluggable/TelemetryCachePluggable.js +7 -7
  166. package/esm/storages/pluggable/UniqueKeysCachePluggable.js +1 -1
  167. package/esm/storages/pluggable/index.js +2 -2
  168. package/esm/storages/pluggable/wrapperAdapter.js +1 -1
  169. package/esm/storages/setRolloutPlan.js +1 -1
  170. package/esm/storages/utils.js +6 -6
  171. package/esm/sync/offline/splitsParser/parseCondition.js +1 -1
  172. package/esm/sync/polling/fetchers/splitChangesFetcher.js +24 -15
  173. package/esm/sync/polling/pollingManagerCS.js +11 -11
  174. package/esm/sync/polling/pollingManagerSS.js +13 -13
  175. package/esm/sync/polling/syncTasks/definitionsSyncTask.js +8 -0
  176. package/esm/sync/polling/updaters/{splitChangesUpdater.js → definitionChangesUpdater.js} +67 -59
  177. package/esm/sync/polling/updaters/mySegmentsUpdater.js +2 -2
  178. package/esm/sync/polling/updaters/segmentChangesUpdater.js +7 -7
  179. package/esm/sync/streaming/SSEClient/index.js +2 -2
  180. package/esm/sync/streaming/UpdateWorkers/MySegmentsUpdateWorker.js +2 -2
  181. package/esm/sync/streaming/UpdateWorkers/SegmentsUpdateWorker.js +2 -2
  182. package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +4 -4
  183. package/esm/sync/streaming/parseUtils.js +10 -10
  184. package/esm/sync/streaming/pushManager.js +3 -3
  185. package/esm/sync/submitters/impressionsSubmitter.js +6 -6
  186. package/esm/sync/submitters/submitter.js +1 -1
  187. package/esm/sync/syncManagerOnline.js +5 -2
  188. package/esm/trackers/eventTracker.js +10 -12
  189. package/esm/trackers/impressionObserver/buildKey.js +1 -1
  190. package/esm/trackers/impressionsTracker.js +38 -21
  191. package/esm/trackers/uniqueKeysTracker.js +1 -1
  192. package/esm/utils/EventEmitter.js +387 -0
  193. package/esm/utils/filter/bloomFilter.js +33 -0
  194. package/esm/utils/inputValidation/apiKey.js +1 -1
  195. package/esm/utils/inputValidation/attribute.js +2 -2
  196. package/esm/utils/inputValidation/{split.js → definition.js} +8 -8
  197. package/esm/utils/inputValidation/definitionExistence.js +15 -0
  198. package/esm/utils/inputValidation/definitions.js +21 -0
  199. package/esm/utils/inputValidation/index.js +3 -3
  200. package/esm/utils/inputValidation/isOperational.js +4 -4
  201. package/esm/utils/inputValidation/target.js +18 -0
  202. package/esm/utils/labels/index.js +2 -2
  203. package/esm/utils/promise/timeout.js +1 -1
  204. package/esm/utils/settingsValidation/splitFilters.js +4 -4
  205. package/esm/utils/settingsValidation/url.js +5 -5
  206. package/package.json +15 -6
  207. package/src/dtos/types.ts +65 -70
  208. package/src/evaluator/Engine.ts +4 -4
  209. package/src/evaluator/combiners/and.ts +3 -3
  210. package/src/evaluator/combiners/ifelseif.ts +2 -2
  211. package/src/evaluator/condition/engineUtils.ts +2 -2
  212. package/src/evaluator/condition/index.ts +3 -3
  213. package/src/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.ts +76 -0
  214. package/src/evaluator/fallbackConfigsCalculator/index.ts +24 -0
  215. package/src/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.ts +5 -7
  216. package/src/evaluator/fallbackTreatmentsCalculator/index.ts +27 -41
  217. package/src/evaluator/index.ts +80 -45
  218. package/src/evaluator/matchers/dependency.ts +2 -2
  219. package/src/evaluator/matchers/matcherTypes.ts +2 -2
  220. package/src/evaluator/matchers/prerequisites.ts +4 -4
  221. package/src/evaluator/matchers/rbsegment.ts +2 -2
  222. package/src/evaluator/matchers/whitelist.ts +2 -2
  223. package/src/evaluator/matchersTransform/index.ts +2 -2
  224. package/src/evaluator/matchersTransform/whitelist.ts +2 -2
  225. package/src/evaluator/parser/index.ts +4 -4
  226. package/src/evaluator/treatments/index.ts +2 -2
  227. package/src/evaluator/types.ts +6 -6
  228. package/src/evaluator/value/index.ts +1 -1
  229. package/src/integrations/pluggable.ts +1 -1
  230. package/src/listeners/browser.ts +11 -8
  231. package/src/listeners/node.ts +2 -5
  232. package/src/logger/constants.ts +11 -17
  233. package/src/logger/messages/debug.ts +5 -6
  234. package/src/logger/messages/error.ts +3 -3
  235. package/src/logger/messages/info.ts +1 -3
  236. package/src/logger/messages/warn.ts +8 -8
  237. package/src/platform/browser.ts +14 -0
  238. package/src/platform/getEventSource/browser.ts +4 -0
  239. package/src/platform/getEventSource/eventsource.js +519 -0
  240. package/src/platform/getEventSource/node.ts +23 -0
  241. package/src/platform/getFetch/browser.ts +5 -0
  242. package/src/platform/getFetch/node.ts +27 -0
  243. package/src/platform/getOptions/node.ts +24 -0
  244. package/src/platform/node.ts +16 -0
  245. package/src/readiness/constants.ts +1 -0
  246. package/src/sdkClient/client.ts +11 -41
  247. package/src/sdkClient/clientInputValidation.ts +44 -84
  248. package/src/sdkClient/sdkClient.ts +5 -54
  249. package/src/sdkClient/sdkLifecycle.ts +78 -0
  250. package/src/sdkClient/trackMethod.ts +59 -0
  251. package/src/sdkFactory/index.ts +10 -54
  252. package/src/sdkFactory/types.ts +19 -16
  253. package/src/sdkManager/index.ts +9 -9
  254. package/src/services/splitApi.ts +6 -0
  255. package/src/services/types.ts +3 -2
  256. package/src/storages/AbstractSplitsCacheAsync.ts +7 -7
  257. package/src/storages/AbstractSplitsCacheSync.ts +10 -10
  258. package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +2 -2
  259. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +6 -6
  260. package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +2 -2
  261. package/src/storages/inMemory/SplitsCacheInMemory.ts +5 -5
  262. package/src/storages/inMemory/TelemetryCacheInMemory.ts +2 -2
  263. package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +2 -2
  264. package/src/storages/inRedis/SplitsCacheInRedis.ts +9 -9
  265. package/src/storages/pluggable/RBSegmentsCachePluggable.ts +2 -2
  266. package/src/storages/pluggable/SplitsCachePluggable.ts +9 -9
  267. package/src/storages/types.ts +21 -16
  268. package/src/sync/offline/splitsParser/parseCondition.ts +2 -2
  269. package/src/sync/offline/splitsParser/splitsParserFromSettings.ts +3 -3
  270. package/src/sync/offline/splitsParser/types.ts +6 -3
  271. package/src/sync/offline/syncManagerOffline.ts +2 -2
  272. package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +6 -6
  273. package/src/sync/polling/fetchers/splitChangesFetcher.ts +57 -22
  274. package/src/sync/polling/fetchers/types.ts +5 -3
  275. package/src/sync/polling/pollingManagerCS.ts +12 -10
  276. package/src/sync/polling/pollingManagerSS.ts +15 -13
  277. package/src/sync/polling/syncTasks/{splitsSyncTask.ts → definitionsSyncTask.ts} +10 -11
  278. package/src/sync/polling/types.ts +3 -3
  279. package/src/sync/polling/updaters/{splitChangesUpdater.ts → definitionChangesUpdater.ts} +77 -68
  280. package/src/sync/polling/updaters/mySegmentsUpdater.ts +2 -2
  281. package/src/sync/polling/updaters/segmentChangesUpdater.ts +7 -7
  282. package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +6 -6
  283. package/src/sync/streaming/parseUtils.ts +12 -12
  284. package/src/sync/streaming/pushManager.ts +3 -3
  285. package/src/sync/submitters/impressionsSubmitter.ts +9 -9
  286. package/src/sync/submitters/types.ts +3 -0
  287. package/src/sync/syncManagerOnline.ts +6 -2
  288. package/src/trackers/eventTracker.ts +7 -10
  289. package/src/trackers/impressionsTracker.ts +42 -26
  290. package/src/trackers/types.ts +3 -1
  291. package/src/utils/EventEmitter.js +444 -0
  292. package/src/utils/filter/bloomFilter.ts +38 -0
  293. package/src/utils/inputValidation/definition.ts +27 -0
  294. package/src/utils/inputValidation/definitionExistence.ts +19 -0
  295. package/src/utils/inputValidation/definitions.ts +21 -0
  296. package/src/utils/inputValidation/index.ts +3 -3
  297. package/src/utils/inputValidation/isOperational.ts +4 -4
  298. package/src/utils/inputValidation/target.ts +21 -0
  299. package/src/utils/labels/index.ts +2 -2
  300. package/src/utils/settingsValidation/splitFilters.ts +3 -3
  301. package/types/splitio.d.ts +202 -9
  302. package/cjs/sync/polling/syncTasks/splitsSyncTask.js +0 -13
  303. package/cjs/utils/inputValidation/splits.js +0 -25
  304. package/esm/sync/polling/syncTasks/splitsSyncTask.js +0 -9
  305. package/esm/utils/inputValidation/splitExistence.js +0 -15
  306. package/esm/utils/inputValidation/splits.js +0 -21
  307. package/src/utils/inputValidation/split.ts +0 -27
  308. package/src/utils/inputValidation/splitExistence.ts +0 -19
  309. package/src/utils/inputValidation/splits.ts +0 -21
@@ -1,13 +1,32 @@
1
1
  import { objectAssign } from '../utils/lang/objectAssign';
2
2
  import { thenable } from '../utils/promise/thenable';
3
3
  import { IMPRESSIONS_TRACKER_SUCCESS, ERROR_IMPRESSIONS_TRACKER, ERROR_IMPRESSIONS_LISTENER } from '../logger/constants';
4
- import { CONSENT_DECLINED, DEDUPED, QUEUED } from '../utils/constants';
4
+ import { CONSENT_DECLINED, DEBUG, DEDUPED, OPTIMIZED, QUEUED } from '../utils/constants';
5
+ import { strategyDebugFactory } from './strategy/strategyDebug';
6
+ import { strategyNoneFactory } from './strategy/strategyNone';
7
+ import { strategyOptimizedFactory } from './strategy/strategyOptimized';
8
+ import { uniqueKeysTrackerFactory } from './uniqueKeysTracker';
5
9
  /**
6
10
  * Impressions tracker stores impressions in cache and pass them to the listener and integrations manager if provided.
7
11
  */
8
- export function impressionsTrackerFactory(settings, impressionsCache, noneStrategy, strategy, whenInit, integrationsManager, telemetryCache) {
9
- var log = settings.log, impressionListener = settings.impressionListener, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname, version = settings.version;
12
+ export function impressionsTrackerFactory(params, storage, integrationsManager) {
13
+ var settings = params.settings, impressionsObserverFactory = params.impressionsObserverFactory, filterAdapterFactory = params.filterAdapterFactory;
14
+ var log = settings.log, impressionListener = settings.impressionListener, _a = settings.runtime, ip = _a.ip, hostname = _a.hostname, version = settings.version, impressionsMode = settings.sync.impressionsMode;
15
+ var observer = impressionsObserverFactory();
16
+ var uniqueKeysTracker = uniqueKeysTrackerFactory(log, storage.uniqueKeys, filterAdapterFactory && filterAdapterFactory());
17
+ var noneStrategy = strategyNoneFactory(storage.impressionCounts, uniqueKeysTracker);
18
+ var strategy = impressionsMode === OPTIMIZED ?
19
+ strategyOptimizedFactory(observer, storage.impressionCounts) :
20
+ impressionsMode === DEBUG ?
21
+ strategyDebugFactory(observer) :
22
+ noneStrategy;
10
23
  return {
24
+ start: function () {
25
+ uniqueKeysTracker.start();
26
+ },
27
+ stop: function () {
28
+ uniqueKeysTracker.stop();
29
+ },
11
30
  track: function (impressions, attributes) {
12
31
  if (settings.userConsent === CONSENT_DECLINED)
13
32
  return;
@@ -20,7 +39,7 @@ export function impressionsTrackerFactory(settings, impressionsCache, noneStrate
20
39
  var impressionsLength = impressions.length;
21
40
  var impressionsToStoreLength = impressionsToStore.length;
22
41
  if (impressionsToStoreLength) {
23
- var res = impressionsCache.track(impressionsToStore.map(function (item) { return item.imp; }));
42
+ var res = storage.impressions.track(impressionsToStore.map(function (item) { return item.imp; }));
24
43
  // If we're on an async storage, handle error and log it.
25
44
  if (thenable(res)) {
26
45
  res.then(function () {
@@ -32,9 +51,9 @@ export function impressionsTrackerFactory(settings, impressionsCache, noneStrate
32
51
  else {
33
52
  // Record when impressionsCache is sync only (standalone mode)
34
53
  // @TODO we are not dropping impressions on full queue yet, so DROPPED stats are not recorded
35
- if (telemetryCache) {
36
- telemetryCache.recordImpressionStats(QUEUED, impressionsToStoreLength);
37
- telemetryCache.recordImpressionStats(DEDUPED, impressionsLength - impressionsToStoreLength);
54
+ if (storage.telemetry) {
55
+ storage.telemetry.recordImpressionStats(QUEUED, impressionsToStoreLength);
56
+ storage.telemetry.recordImpressionStats(DEDUPED, impressionsLength - impressionsToStoreLength);
38
57
  }
39
58
  }
40
59
  }
@@ -49,20 +68,18 @@ export function impressionsTrackerFactory(settings, impressionsCache, noneStrate
49
68
  hostname: hostname,
50
69
  sdkLanguageVersion: version
51
70
  };
52
- whenInit(function () {
53
- // Wrap in a timeout because we don't want it to be blocking.
54
- setTimeout(function () {
55
- // integrationsManager.handleImpression does not throw errors
56
- if (integrationsManager)
57
- integrationsManager.handleImpression(impressionData);
58
- try { // @ts-ignore. An exception on the listeners should not break the SDK.
59
- if (impressionListener)
60
- impressionListener.logImpression(impressionData);
61
- }
62
- catch (err) {
63
- log.error(ERROR_IMPRESSIONS_LISTENER, [err]);
64
- }
65
- });
71
+ // Wrap in a timeout because we don't want it to be blocking.
72
+ setTimeout(function () {
73
+ // integrationsManager.handleImpression does not throw errors
74
+ if (integrationsManager)
75
+ integrationsManager.handleImpression(impressionData);
76
+ try { // @ts-ignore. An exception on the listeners should not break the SDK.
77
+ if (impressionListener)
78
+ impressionListener.logImpression(impressionData);
79
+ }
80
+ catch (err) {
81
+ log.error(ERROR_IMPRESSIONS_LISTENER, [err]);
82
+ }
66
83
  });
67
84
  };
68
85
  for (var i = 0; i < impressionsLength; i++) {
@@ -19,7 +19,7 @@ export function uniqueKeysTrackerFactory(log, uniqueKeysCache, filterAdapter) {
19
19
  return {
20
20
  track: function (key, featureName) {
21
21
  if (!filterAdapter.add(key, featureName)) {
22
- log.debug(LOG_PREFIX_UNIQUE_KEYS_TRACKER + "The feature " + featureName + " and key " + key + " exist in the filter");
22
+ log.debug("".concat(LOG_PREFIX_UNIQUE_KEYS_TRACKER, "The feature ").concat(featureName, " and key ").concat(key, " exist in the filter"));
23
23
  return;
24
24
  }
25
25
  uniqueKeysCache.track(key, featureName);
@@ -0,0 +1,387 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+ // Adaptation of "events" library (https://www.npmjs.com/package/events)
22
+ // exported as an ES module instead of CommonJS, to avoid extra configuration steps when using
23
+ // the ESM build of the SDK with tools that doesn't support CommonJS by default (e.g. Rollup).
24
+ var R = typeof Reflect === 'object' ? Reflect : null;
25
+ var ReflectApply = R && typeof R.apply === 'function'
26
+ ? R.apply
27
+ : function ReflectApply(target, receiver, args) {
28
+ return Function.prototype.apply.call(target, receiver, args);
29
+ };
30
+ var ReflectOwnKeys;
31
+ if (R && typeof R.ownKeys === 'function') {
32
+ ReflectOwnKeys = R.ownKeys;
33
+ }
34
+ else if (Object.getOwnPropertySymbols) {
35
+ ReflectOwnKeys = function ReflectOwnKeys(target) {
36
+ return Object.getOwnPropertyNames(target)
37
+ .concat(Object.getOwnPropertySymbols(target));
38
+ };
39
+ }
40
+ else {
41
+ ReflectOwnKeys = function ReflectOwnKeys(target) {
42
+ return Object.getOwnPropertyNames(target);
43
+ };
44
+ }
45
+ function ProcessEmitWarning(warning) {
46
+ if (console && console.warn)
47
+ console.warn(warning);
48
+ }
49
+ // eslint-disable-next-line compat/compat
50
+ var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
51
+ return value !== value;
52
+ };
53
+ export function EventEmitter() {
54
+ EventEmitter.init.call(this);
55
+ }
56
+ EventEmitter.prototype._events = undefined;
57
+ EventEmitter.prototype._eventsCount = 0;
58
+ EventEmitter.prototype._maxListeners = undefined;
59
+ // By default EventEmitters will print a warning if more than 10 listeners are
60
+ // added to it. This is a useful default which helps finding memory leaks.
61
+ var defaultMaxListeners = 10;
62
+ function checkListener(listener) {
63
+ if (typeof listener !== 'function') {
64
+ throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
65
+ }
66
+ }
67
+ Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
68
+ enumerable: true,
69
+ get: function () {
70
+ return defaultMaxListeners;
71
+ },
72
+ set: function (arg) {
73
+ if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
74
+ throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
75
+ }
76
+ defaultMaxListeners = arg;
77
+ }
78
+ });
79
+ EventEmitter.init = function () {
80
+ if (this._events === undefined ||
81
+ this._events === Object.getPrototypeOf(this)._events) {
82
+ this._events = Object.create(null);
83
+ this._eventsCount = 0;
84
+ }
85
+ this._maxListeners = this._maxListeners || undefined;
86
+ };
87
+ // Obviously not all Emitters should be limited to 10. This function allows
88
+ // that to be increased. Set to zero for unlimited.
89
+ EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
90
+ if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
91
+ throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
92
+ }
93
+ this._maxListeners = n;
94
+ return this;
95
+ };
96
+ function _getMaxListeners(that) {
97
+ if (that._maxListeners === undefined)
98
+ return EventEmitter.defaultMaxListeners;
99
+ return that._maxListeners;
100
+ }
101
+ EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
102
+ return _getMaxListeners(this);
103
+ };
104
+ EventEmitter.prototype.emit = function emit(type) {
105
+ var args = [];
106
+ for (var i = 1; i < arguments.length; i++)
107
+ args.push(arguments[i]);
108
+ var doError = (type === 'error');
109
+ var events = this._events;
110
+ if (events !== undefined)
111
+ doError = (doError && events.error === undefined);
112
+ else if (!doError)
113
+ return false;
114
+ // If there is no 'error' event listener then throw.
115
+ if (doError) {
116
+ var er;
117
+ if (args.length > 0)
118
+ er = args[0];
119
+ if (er instanceof Error) {
120
+ // Note: The comments on the `throw` lines are intentional, they show
121
+ // up in Node.js output if this results in an unhandled exception.
122
+ throw er; // Unhandled 'error' event
123
+ }
124
+ // At least give some kind of context to the user
125
+ var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
126
+ err.context = er;
127
+ throw err; // Unhandled 'error' event
128
+ }
129
+ var handler = events[type];
130
+ if (handler === undefined)
131
+ return false;
132
+ if (typeof handler === 'function') {
133
+ ReflectApply(handler, this, args);
134
+ }
135
+ else {
136
+ var len = handler.length;
137
+ var listeners = arrayClone(handler, len); // eslint-disable-next-line no-redeclare
138
+ for (var i = 0; i < len; ++i)
139
+ ReflectApply(listeners[i], this, args);
140
+ }
141
+ return true;
142
+ };
143
+ function _addListener(target, type, listener, prepend) {
144
+ var m;
145
+ var events;
146
+ var existing;
147
+ checkListener(listener);
148
+ events = target._events;
149
+ if (events === undefined) {
150
+ events = target._events = Object.create(null);
151
+ target._eventsCount = 0;
152
+ }
153
+ else {
154
+ // To avoid recursion in the case that type === "newListener"! Before
155
+ // adding it to the listeners, first emit "newListener".
156
+ if (events.newListener !== undefined) {
157
+ target.emit('newListener', type, listener.listener ? listener.listener : listener);
158
+ // Re-assign `events` because a newListener handler could have caused the
159
+ // this._events to be assigned to a new object
160
+ events = target._events;
161
+ }
162
+ existing = events[type];
163
+ }
164
+ if (existing === undefined) {
165
+ // Optimize the case of one listener. Don't need the extra array object.
166
+ existing = events[type] = listener;
167
+ ++target._eventsCount;
168
+ }
169
+ else {
170
+ if (typeof existing === 'function') {
171
+ // Adding the second element, need to change to array.
172
+ existing = events[type] =
173
+ prepend ? [listener, existing] : [existing, listener];
174
+ // If we've already got an array, just append.
175
+ }
176
+ else if (prepend) {
177
+ existing.unshift(listener);
178
+ }
179
+ else {
180
+ existing.push(listener);
181
+ }
182
+ // Check for listener leak
183
+ m = _getMaxListeners(target);
184
+ if (m > 0 && existing.length > m && !existing.warned) {
185
+ existing.warned = true;
186
+ // No error code for this since it is a Warning
187
+ // eslint-disable-next-line no-restricted-syntax
188
+ var w = new Error('Possible EventEmitter memory leak detected. ' +
189
+ existing.length + ' ' + String(type) + ' listeners ' +
190
+ 'added. Use emitter.setMaxListeners() to ' +
191
+ 'increase limit');
192
+ w.name = 'MaxListenersExceededWarning';
193
+ w.emitter = target;
194
+ w.type = type;
195
+ w.count = existing.length;
196
+ ProcessEmitWarning(w);
197
+ }
198
+ }
199
+ return target;
200
+ }
201
+ EventEmitter.prototype.addListener = function addListener(type, listener) {
202
+ return _addListener(this, type, listener, false);
203
+ };
204
+ EventEmitter.prototype.on = EventEmitter.prototype.addListener;
205
+ EventEmitter.prototype.prependListener =
206
+ function prependListener(type, listener) {
207
+ return _addListener(this, type, listener, true);
208
+ };
209
+ function onceWrapper() {
210
+ if (!this.fired) {
211
+ this.target.removeListener(this.type, this.wrapFn);
212
+ this.fired = true;
213
+ if (arguments.length === 0)
214
+ return this.listener.call(this.target);
215
+ return this.listener.apply(this.target, arguments);
216
+ }
217
+ }
218
+ function _onceWrap(target, type, listener) {
219
+ var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
220
+ var wrapped = onceWrapper.bind(state);
221
+ wrapped.listener = listener;
222
+ state.wrapFn = wrapped;
223
+ return wrapped;
224
+ }
225
+ EventEmitter.prototype.once = function once(type, listener) {
226
+ checkListener(listener);
227
+ this.on(type, _onceWrap(this, type, listener));
228
+ return this;
229
+ };
230
+ EventEmitter.prototype.prependOnceListener =
231
+ function prependOnceListener(type, listener) {
232
+ checkListener(listener);
233
+ this.prependListener(type, _onceWrap(this, type, listener));
234
+ return this;
235
+ };
236
+ // Emits a 'removeListener' event if and only if the listener was removed.
237
+ EventEmitter.prototype.removeListener =
238
+ function removeListener(type, listener) {
239
+ var list, events, position, i, originalListener;
240
+ checkListener(listener);
241
+ events = this._events;
242
+ if (events === undefined)
243
+ return this;
244
+ list = events[type];
245
+ if (list === undefined)
246
+ return this;
247
+ if (list === listener || list.listener === listener) {
248
+ if (--this._eventsCount === 0)
249
+ this._events = Object.create(null);
250
+ else {
251
+ delete events[type];
252
+ if (events.removeListener)
253
+ this.emit('removeListener', type, list.listener || listener);
254
+ }
255
+ }
256
+ else if (typeof list !== 'function') {
257
+ position = -1;
258
+ for (i = list.length - 1; i >= 0; i--) {
259
+ if (list[i] === listener || list[i].listener === listener) {
260
+ originalListener = list[i].listener;
261
+ position = i;
262
+ break;
263
+ }
264
+ }
265
+ if (position < 0)
266
+ return this;
267
+ if (position === 0)
268
+ list.shift();
269
+ else {
270
+ spliceOne(list, position);
271
+ }
272
+ if (list.length === 1)
273
+ events[type] = list[0];
274
+ if (events.removeListener !== undefined)
275
+ this.emit('removeListener', type, originalListener || listener);
276
+ }
277
+ return this;
278
+ };
279
+ EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
280
+ EventEmitter.prototype.removeAllListeners =
281
+ function removeAllListeners(type) {
282
+ var listeners, events, i;
283
+ events = this._events;
284
+ if (events === undefined)
285
+ return this;
286
+ // not listening for removeListener, no need to emit
287
+ if (events.removeListener === undefined) {
288
+ if (arguments.length === 0) {
289
+ this._events = Object.create(null);
290
+ this._eventsCount = 0;
291
+ }
292
+ else if (events[type] !== undefined) {
293
+ if (--this._eventsCount === 0)
294
+ this._events = Object.create(null);
295
+ else
296
+ delete events[type];
297
+ }
298
+ return this;
299
+ }
300
+ // emit removeListener for all listeners on all events
301
+ if (arguments.length === 0) {
302
+ var keys = Object.keys(events);
303
+ var key;
304
+ for (i = 0; i < keys.length; ++i) {
305
+ key = keys[i];
306
+ if (key === 'removeListener')
307
+ continue;
308
+ this.removeAllListeners(key);
309
+ }
310
+ this.removeAllListeners('removeListener');
311
+ this._events = Object.create(null);
312
+ this._eventsCount = 0;
313
+ return this;
314
+ }
315
+ listeners = events[type];
316
+ if (typeof listeners === 'function') {
317
+ this.removeListener(type, listeners);
318
+ }
319
+ else if (listeners !== undefined) {
320
+ // LIFO order
321
+ for (i = listeners.length - 1; i >= 0; i--) {
322
+ this.removeListener(type, listeners[i]);
323
+ }
324
+ }
325
+ return this;
326
+ };
327
+ function _listeners(target, type, unwrap) {
328
+ var events = target._events;
329
+ if (events === undefined)
330
+ return [];
331
+ var evlistener = events[type];
332
+ if (evlistener === undefined)
333
+ return [];
334
+ if (typeof evlistener === 'function')
335
+ return unwrap ? [evlistener.listener || evlistener] : [evlistener];
336
+ return unwrap ?
337
+ unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
338
+ }
339
+ EventEmitter.prototype.listeners = function listeners(type) {
340
+ return _listeners(this, type, true);
341
+ };
342
+ EventEmitter.prototype.rawListeners = function rawListeners(type) {
343
+ return _listeners(this, type, false);
344
+ };
345
+ EventEmitter.listenerCount = function (emitter, type) {
346
+ if (typeof emitter.listenerCount === 'function') {
347
+ return emitter.listenerCount(type);
348
+ }
349
+ else {
350
+ return listenerCount.call(emitter, type);
351
+ }
352
+ };
353
+ EventEmitter.prototype.listenerCount = listenerCount;
354
+ function listenerCount(type) {
355
+ var events = this._events;
356
+ if (events !== undefined) {
357
+ var evlistener = events[type];
358
+ if (typeof evlistener === 'function') {
359
+ return 1;
360
+ }
361
+ else if (evlistener !== undefined) {
362
+ return evlistener.length;
363
+ }
364
+ }
365
+ return 0;
366
+ }
367
+ EventEmitter.prototype.eventNames = function eventNames() {
368
+ return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
369
+ };
370
+ function arrayClone(arr, n) {
371
+ var copy = new Array(n);
372
+ for (var i = 0; i < n; ++i)
373
+ copy[i] = arr[i];
374
+ return copy;
375
+ }
376
+ function spliceOne(list, index) {
377
+ for (; index + 1 < list.length; index++)
378
+ list[index] = list[index + 1];
379
+ list.pop();
380
+ }
381
+ function unwrapListeners(arr) {
382
+ var ret = new Array(arr.length);
383
+ for (var i = 0; i < ret.length; ++i) {
384
+ ret[i] = arr[i].listener || arr[i];
385
+ }
386
+ return ret;
387
+ }
@@ -0,0 +1,33 @@
1
+ // bloom-filters is supported on the following platforms:
2
+ // - Node.js: v4.0.0 or higher
3
+ // - Google Chrome: v41 or higher
4
+ // - Mozilla Firefox: v34 or higher
5
+ // - Microsoft Edge: v12 or higher
6
+ import { BloomFilter } from 'bloom-filters';
7
+ var EXPECTED_INSERTIONS = 10000000;
8
+ var ERROR_RATE = 0.01;
9
+ var REFRESH_RATE = 24 * 60 * 60000; // 24HS
10
+ export function bloomFilterFactory(expectedInsertions, errorRate, refreshRate) {
11
+ if (expectedInsertions === void 0) { expectedInsertions = EXPECTED_INSERTIONS; }
12
+ if (errorRate === void 0) { errorRate = ERROR_RATE; }
13
+ if (refreshRate === void 0) { refreshRate = REFRESH_RATE; }
14
+ var filter = BloomFilter.create(expectedInsertions, errorRate);
15
+ return {
16
+ refreshRate: refreshRate,
17
+ add: function (key, value) {
18
+ var data = "".concat(key, ":").concat(value);
19
+ if (filter.has(data)) {
20
+ return false;
21
+ }
22
+ filter.add(data);
23
+ return true;
24
+ },
25
+ contains: function (key, value) {
26
+ var data = "".concat(key, ":").concat(value);
27
+ return filter.has(data);
28
+ },
29
+ clear: function () {
30
+ filter = BloomFilter.create(expectedInsertions, errorRate);
31
+ }
32
+ };
33
+ }
@@ -34,7 +34,7 @@ export function validateAndTrackApiKey(log, maybeSdkKey) {
34
34
  }
35
35
  }
36
36
  else {
37
- log.warn(WARN_SDK_KEY, [usedKeysMap[sdkKey] + " factory/ies with this SDK Key"]);
37
+ log.warn(WARN_SDK_KEY, ["".concat(usedKeysMap[sdkKey], " factory/ies with this SDK Key")]);
38
38
  usedKeysMap[sdkKey]++;
39
39
  }
40
40
  }
@@ -1,7 +1,7 @@
1
1
  import { isString, isFiniteNumber, isBoolean } from '../../utils/lang';
2
2
  export function validateAttribute(log, attributeKey, attributeValue, method) {
3
3
  if (!isString(attributeKey) || attributeKey.length === 0) {
4
- log.warn(method + ": you passed an invalid attribute name, attribute name must be a non-empty string.");
4
+ log.warn("".concat(method, ": you passed an invalid attribute name, attribute name must be a non-empty string."));
5
5
  return false;
6
6
  }
7
7
  var isStringVal = isString(attributeValue);
@@ -9,7 +9,7 @@ export function validateAttribute(log, attributeKey, attributeValue, method) {
9
9
  var isBoolVal = isBoolean(attributeValue);
10
10
  var isArrayVal = Array.isArray(attributeValue);
11
11
  if (!(isStringVal || isFiniteVal || isBoolVal || isArrayVal)) { // If it's not of valid type.
12
- log.warn(method + ": you passed an invalid attribute value for " + attributeKey + ". Acceptable types are: string, number, boolean and array of strings.");
12
+ log.warn("".concat(method, ": you passed an invalid attribute value for ").concat(attributeKey, ". Acceptable types are: string, number, boolean and array of strings."));
13
13
  return false;
14
14
  }
15
15
  return true;
@@ -2,21 +2,21 @@ import { ERROR_NULL, ERROR_INVALID, WARN_TRIMMING, ERROR_EMPTY } from '../../log
2
2
  import { isString } from '../lang';
3
3
  // include BOM and nbsp
4
4
  var TRIMMABLE_SPACES_REGEX = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/;
5
- export function validateSplit(log, maybeSplit, method, item) {
5
+ export function validateDefinition(log, maybeDefinition, method, item) {
6
6
  if (item === void 0) { item = 'feature flag name'; }
7
- if (maybeSplit == undefined) { // eslint-disable-line eqeqeq
7
+ if (maybeDefinition == undefined) { // eslint-disable-line eqeqeq
8
8
  log.error(ERROR_NULL, [method, item]);
9
9
  }
10
- else if (!isString(maybeSplit)) {
10
+ else if (!isString(maybeDefinition)) {
11
11
  log.error(ERROR_INVALID, [method, item]);
12
12
  }
13
13
  else {
14
- if (TRIMMABLE_SPACES_REGEX.test(maybeSplit)) {
15
- log.warn(WARN_TRIMMING, [method, item, maybeSplit]);
16
- maybeSplit = maybeSplit.trim();
14
+ if (TRIMMABLE_SPACES_REGEX.test(maybeDefinition)) {
15
+ log.warn(WARN_TRIMMING, [method, item, maybeDefinition]);
16
+ maybeDefinition = maybeDefinition.trim();
17
17
  }
18
- if (maybeSplit.length > 0) {
19
- return maybeSplit;
18
+ if (maybeDefinition.length > 0) {
19
+ return maybeDefinition;
20
20
  }
21
21
  else {
22
22
  log.error(ERROR_EMPTY, [method, item]);
@@ -0,0 +1,15 @@
1
+ import { FALLBACK_DEFINITION_NOT_FOUND, DEFINITION_NOT_FOUND } from '../labels';
2
+ import { WARN_NOT_EXISTENT_DEFINITION } from '../../logger/constants';
3
+ /**
4
+ * This is defined here and in this format mostly because of the logger and the fact that it's considered a validation at product level.
5
+ * But it's not going to run on the input validation layer. In any case, the most compelling reason to use it as we do is to avoid going to Redis and get a definition twice.
6
+ */
7
+ export function validateDefinitionExistence(log, readinessManager, definitionName, labelOrDefinitionObj, method) {
8
+ if (readinessManager.isReady()) { // Only if it's ready (synced with BE) we validate this, otherwise it may just be that the SDK is still syncing
9
+ if (labelOrDefinitionObj === DEFINITION_NOT_FOUND || labelOrDefinitionObj === FALLBACK_DEFINITION_NOT_FOUND || labelOrDefinitionObj == null) {
10
+ log.warn(WARN_NOT_EXISTENT_DEFINITION, [method, definitionName]);
11
+ return false;
12
+ }
13
+ }
14
+ return true;
15
+ }
@@ -0,0 +1,21 @@
1
+ import { ERROR_EMPTY_ARRAY } from '../../logger/constants';
2
+ import { uniq } from '../lang';
3
+ import { validateDefinition } from './definition';
4
+ export function validateDefinitions(log, maybeDefinitions, method, listName, item) {
5
+ if (listName === void 0) { listName = 'feature flag names'; }
6
+ if (item === void 0) { item = 'feature flag name'; }
7
+ if (Array.isArray(maybeDefinitions) && maybeDefinitions.length > 0) {
8
+ var validatedArray_1 = [];
9
+ // Remove invalid values
10
+ maybeDefinitions.forEach(function (maybeDefinition) {
11
+ var definitionName = validateDefinition(log, maybeDefinition, method, item);
12
+ if (definitionName)
13
+ validatedArray_1.push(definitionName);
14
+ });
15
+ // Strip off duplicated values if we have valid definition names then return
16
+ if (validatedArray_1.length)
17
+ return uniq(validatedArray_1);
18
+ }
19
+ log.error(ERROR_EMPTY_ARRAY, [method, listName]);
20
+ return false;
21
+ }
@@ -4,10 +4,10 @@ export { validateEvent } from './event';
4
4
  export { validateEventValue } from './eventValue';
5
5
  export { validateEventProperties } from './eventProperties';
6
6
  export { validateKey } from './key';
7
- export { validateSplit } from './split';
8
- export { validateSplits } from './splits';
7
+ export { validateDefinition } from './definition';
8
+ export { validateDefinitions } from './definitions';
9
9
  export { validateTrafficType } from './trafficType';
10
10
  export { validateIfNotDestroyed, validateIfReadyFromCache, validateIfOperational } from './isOperational';
11
- export { validateSplitExistence } from './splitExistence';
11
+ export { validateDefinitionExistence } from './definitionExistence';
12
12
  export { validateTrafficTypeExistence } from './trafficTypeExistence';
13
13
  export { validateEvaluationOptions } from './eventProperties';
@@ -5,13 +5,13 @@ export function validateIfNotDestroyed(log, readinessManager, method) {
5
5
  log.error(ERROR_CLIENT_DESTROYED, [method]);
6
6
  return false;
7
7
  }
8
- export function validateIfReadyFromCache(log, readinessManager, method, featureFlagNameOrNames) {
8
+ export function validateIfReadyFromCache(log, readinessManager, method) {
9
9
  if (readinessManager.isReadyFromCache())
10
10
  return true;
11
- log.warn(CLIENT_NOT_READY_FROM_CACHE, [method, featureFlagNameOrNames ? " for feature flag " + featureFlagNameOrNames.toString() : '']);
11
+ log.warn(CLIENT_NOT_READY_FROM_CACHE, [method]);
12
12
  return false;
13
13
  }
14
14
  // Operational means that the SDK is ready to evaluate (not destroyed and ready from cache)
15
- export function validateIfOperational(log, readinessManager, method, featureFlagNameOrNames) {
16
- return validateIfNotDestroyed(log, readinessManager, method) && validateIfReadyFromCache(log, readinessManager, method, featureFlagNameOrNames);
15
+ export function validateIfOperational(log, readinessManager, method) {
16
+ return validateIfNotDestroyed(log, readinessManager, method) && validateIfReadyFromCache(log, readinessManager, method);
17
17
  }