@splitsoftware/splitio-commons 2.12.0 → 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 +14 -1
  2. package/cjs/evaluator/condition/engineUtils.js +2 -2
  3. package/cjs/evaluator/fallbackConfigsCalculator/fallbackSanitizer/index.js +70 -0
  4. package/cjs/evaluator/fallbackConfigsCalculator/index.js +25 -0
  5. package/cjs/evaluator/fallbackTreatmentsCalculator/fallbackSanitizer/index.js +5 -8
  6. package/cjs/evaluator/fallbackTreatmentsCalculator/index.js +21 -32
  7. package/cjs/evaluator/index.js +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
@@ -9,14 +9,14 @@ export function validateIfNotDestroyed(log: ILogger, readinessManager: IReadines
9
9
  return false;
10
10
  }
11
11
 
12
- export function validateIfReadyFromCache(log: ILogger, readinessManager: IReadinessManager, method: string, featureFlagNameOrNames?: string | string[] | false) {
12
+ export function validateIfReadyFromCache(log: ILogger, readinessManager: IReadinessManager, method: string) {
13
13
  if (readinessManager.isReadyFromCache()) return true;
14
14
 
15
- log.warn(CLIENT_NOT_READY_FROM_CACHE, [method, featureFlagNameOrNames ? ` for feature flag ${featureFlagNameOrNames.toString()}` : '']);
15
+ log.warn(CLIENT_NOT_READY_FROM_CACHE, [method]);
16
16
  return false;
17
17
  }
18
18
 
19
19
  // Operational means that the SDK is ready to evaluate (not destroyed and ready from cache)
20
- export function validateIfOperational(log: ILogger, readinessManager: IReadinessManager, method: string, featureFlagNameOrNames?: string | string[] | false) {
21
- return validateIfNotDestroyed(log, readinessManager, method) && validateIfReadyFromCache(log, readinessManager, method, featureFlagNameOrNames);
20
+ export function validateIfOperational(log: ILogger, readinessManager: IReadinessManager, method: string) {
21
+ return validateIfNotDestroyed(log, readinessManager, method) && validateIfReadyFromCache(log, readinessManager, method);
22
22
  }
@@ -0,0 +1,21 @@
1
+ import { isObject } from '../lang';
2
+ import SplitIO from '../../../types/splitio';
3
+ import { ILogger } from '../../logger/types';
4
+ import { validateKey } from './key';
5
+ import { validateAttributes } from './attributes';
6
+ import { ERROR_NOT_PLAIN_OBJECT } from '../../logger/constants';
7
+
8
+ export function validateTarget(log: ILogger, maybeTarget: any, method: string): SplitIO.Target | false {
9
+ if (!isObject(maybeTarget)) {
10
+ log.error(ERROR_NOT_PLAIN_OBJECT, [method, 'target']);
11
+ return false;
12
+ }
13
+
14
+ const key = validateKey(log, maybeTarget.key, method);
15
+ if (key === false) return false;
16
+
17
+ const attributes = validateAttributes(log, maybeTarget.attributes, method);
18
+ if (attributes === false) return false;
19
+
20
+ return { ...maybeTarget, key, attributes };
21
+ }
@@ -2,11 +2,11 @@ import { FALLBACK_PREFIX } from '../../evaluator/fallbackTreatmentsCalculator';
2
2
 
3
3
  export const SPLIT_KILLED = 'killed';
4
4
  export const NO_CONDITION_MATCH = 'default rule';
5
- export const SPLIT_NOT_FOUND = 'definition not found';
5
+ export const DEFINITION_NOT_FOUND = 'definition not found';
6
6
  export const SDK_NOT_READY = 'not ready';
7
7
  export const EXCEPTION = 'exception';
8
8
  export const SPLIT_ARCHIVED = 'archived';
9
9
  export const NOT_IN_SPLIT = 'not in split';
10
10
  export const UNSUPPORTED_MATCHER_TYPE = 'targeting rule type unsupported by sdk';
11
11
  export const PREREQUISITES_NOT_MET = 'prerequisites not met';
12
- export const FALLBACK_SPLIT_NOT_FOUND = FALLBACK_PREFIX + SPLIT_NOT_FOUND;
12
+ export const FALLBACK_DEFINITION_NOT_FOUND = FALLBACK_PREFIX + DEFINITION_NOT_FOUND;
@@ -1,4 +1,4 @@
1
- import { validateSplits } from '../inputValidation/splits';
1
+ import { validateDefinitions } from '../inputValidation/definitions';
2
2
  import { ISplitFiltersValidation } from '../../dtos/types';
3
3
  import SplitIO from '../../../types/splitio';
4
4
  import { ILogger } from '../../logger/types';
@@ -49,7 +49,7 @@ function validateFilterType(maybeFilterType: any): maybeFilterType is SplitIO.Sp
49
49
  */
50
50
  function validateSplitFilter(log: ILogger, type: SplitIO.SplitFilterType, values: string[], maxLength: number) {
51
51
  // validate and remove invalid and duplicated values
52
- let result = validateSplits(log, values, LOG_PREFIX_SETTINGS, `${type} filter`, `${type} filter value`);
52
+ let result = validateDefinitions(log, values, LOG_PREFIX_SETTINGS, `${type} filter`, `${type} filter value`);
53
53
 
54
54
  if (result) {
55
55
 
@@ -181,7 +181,7 @@ export function validateSplitFilters(log: ILogger, maybeSplitFilters: any, mode:
181
181
  }
182
182
 
183
183
  export function validateFlagSets(log: ILogger, method: string, flagSets: string[], flagSetsInConfig: string[]): string[] | false {
184
- const sets = validateSplits(log, flagSets, method, 'flag sets', 'flag set');
184
+ const sets = validateDefinitions(log, flagSets, method, 'flag sets', 'flag set');
185
185
  let toReturn = sets ? sanitizeFlagSets(log, sets, method) : [];
186
186
  if (flagSetsInConfig.length > 0) {
187
187
  toReturn = toReturn.filter(flagSet => {
@@ -73,10 +73,12 @@ interface ISharedSettings {
73
73
  * const factory = SplitFactory({
74
74
  * ...
75
75
  * sync: {
76
- * getHeaderOverrides: (context) => {
77
- * return {
78
- * 'Authorization': context.headers['Authorization'] + ', other-value',
79
- * 'custom-header': 'custom-value'
76
+ * requestOptions: {
77
+ * getHeaderOverrides: (context) => {
78
+ * return {
79
+ * 'Authorization': context.headers['Authorization'] + ', other-value',
80
+ * 'custom-header': 'custom-value'
81
+ * };
80
82
  * };
81
83
  * }
82
84
  * }
@@ -509,7 +511,7 @@ declare namespace SplitIO {
509
511
  /**
510
512
  * Metadata type for SDK update events.
511
513
  */
512
- type SdkUpdateMetadataType = 'FLAGS_UPDATE' | 'SEGMENTS_UPDATE';
514
+ type SdkUpdateMetadataType = 'CONFIGS_UPDATE' | 'FLAGS_UPDATE' | 'SEGMENTS_UPDATE';
513
515
 
514
516
  /**
515
517
  * Metadata for the ready events emitted when the SDK is ready to evaluate feature flags.
@@ -1590,10 +1592,12 @@ declare namespace SplitIO {
1590
1592
  * const factory = SplitFactory({
1591
1593
  * ...
1592
1594
  * sync: {
1593
- * getHeaderOverrides: (context) => {
1594
- * return {
1595
- * 'Authorization': context.headers['Authorization'] + ', other-value',
1596
- * 'custom-header': 'custom-value'
1595
+ * requestOptions: {
1596
+ * getHeaderOverrides: (context) => {
1597
+ * return {
1598
+ * 'Authorization': context.headers['Authorization'] + ', other-value',
1599
+ * 'custom-header': 'custom-value'
1600
+ * };
1597
1601
  * };
1598
1602
  * }
1599
1603
  * }
@@ -2284,4 +2288,193 @@ declare namespace SplitIO {
2284
2288
  */
2285
2289
  split(featureFlagName: string): SplitViewAsync;
2286
2290
  }
2291
+
2292
+ /**
2293
+ * Fallback configuration objects returned by the `client.getConfig` method when the SDK is not ready or the provided config name is not found.
2294
+ */
2295
+ type FallbackConfigs = {
2296
+ /**
2297
+ * Fallback config for all config names.
2298
+ */
2299
+ global?: Config;
2300
+ /**
2301
+ * Fallback configs for specific config names. It takes precedence over the global fallback config.
2302
+ */
2303
+ byName?: {
2304
+ [configName: string]: Config;
2305
+ };
2306
+ }
2307
+
2308
+ /**
2309
+ * Configs SDK settings.
2310
+ */
2311
+ interface ConfigsClientSettings {
2312
+ /**
2313
+ * Your SDK key.
2314
+ *
2315
+ * @see {@link https://developer.harness.io/docs/feature-management-experimentation/management-and-administration/account-settings/api-keys/}
2316
+ */
2317
+ authorizationKey: string;
2318
+ /**
2319
+ * Configs definitions refresh rate for polling, in seconds.
2320
+ *
2321
+ * @defaultValue `60`
2322
+ */
2323
+ configsRefreshRate?: number;
2324
+ /**
2325
+ * Logging level.
2326
+ *
2327
+ * @defaultValue `'NONE'`
2328
+ */
2329
+ logLevel?: LogLevel;
2330
+ /**
2331
+ * Time in seconds until SDK ready timeout is emitted.
2332
+ *
2333
+ * @defaultValue `10`
2334
+ */
2335
+ timeout?: number;
2336
+ /**
2337
+ * Custom endpoints to replace the default ones used by the SDK.
2338
+ */
2339
+ urls?: {
2340
+ /**
2341
+ * String property to override the base URL where the SDK will get rollout plan related data, like feature flags and segments definitions.
2342
+ *
2343
+ * @defaultValue `'https://appconfig.split.io/api'`
2344
+ */
2345
+ sdk?: string;
2346
+ /**
2347
+ * String property to override the base URL where the SDK will post event-related information like impressions.
2348
+ *
2349
+ * @defaultValue `'https://events.split.io/api'`
2350
+ */
2351
+ events?: string;
2352
+ };
2353
+ /**
2354
+ * Fallback configuration objects returned by the `client.getConfig` method when the SDK is not ready or the provided config name is not found.
2355
+ */
2356
+ fallbackConfigs?: FallbackConfigs;
2357
+ /**
2358
+ * Custom options object for HTTP(S) requests.
2359
+ * If provided, this object is merged with the options object passed by the SDK for EventSource and Fetch calls.
2360
+ */
2361
+ requestOptions?: {
2362
+ /**
2363
+ * Custom function called before each request, allowing you to add or update headers in SDK HTTP requests.
2364
+ * Some headers, such as `SplitSDKVersion`, are required by the SDK and cannot be overridden.
2365
+ * To pass multiple headers with the same name, combine their values into a single line, separated by commas. Example: `{ 'Authorization': 'value1, value2' }`
2366
+ * Or provide keys with different cases since headers are case-insensitive. Example: `{ 'authorization': 'value1', 'Authorization': 'value2' }`
2367
+ *
2368
+ * @defaultValue `undefined`
2369
+ *
2370
+ * @param context - The context for the request, which contains the `headers` property object representing the current headers in the request.
2371
+ * @returns An object representing a set of headers to be merged with the current headers.
2372
+ *
2373
+ * @example
2374
+ * ```
2375
+ * const client = ConfigsClient({
2376
+ * ...
2377
+ * requestOptions: {
2378
+ * getHeaderOverrides: (context) => {
2379
+ * return {
2380
+ * 'Authorization': context.headers['Authorization'] + ', other-value',
2381
+ * 'custom-header': 'custom-value'
2382
+ * };
2383
+ * }
2384
+ * }
2385
+ * });
2386
+ * ```
2387
+ */
2388
+ getHeaderOverrides?: (context: { headers: Record<string, string>; }) => Record<string, string>;
2389
+ /**
2390
+ * Custom Node.js HTTP(S) Agent used by the SDK for HTTP(S) requests.
2391
+ *
2392
+ * You can use it, for example, for certificate pinning or setting a network proxy:
2393
+ *
2394
+ * ```
2395
+ * const { HttpsProxyAgent } = require('https-proxy-agent');
2396
+ *
2397
+ * const proxyAgent = new HttpsProxyAgent(process.env.HTTPS_PROXY || 'http://10.10.1.10:1080');
2398
+ *
2399
+ * const client = ConfigsClient({
2400
+ * ...
2401
+ * requestOptions: {
2402
+ * agent: proxyAgent
2403
+ * }
2404
+ * })
2405
+ * ```
2406
+ *
2407
+ * @see {@link https://nodejs.org/api/https.html#class-httpsagent}
2408
+ *
2409
+ * @defaultValue `undefined`
2410
+ */
2411
+ agent?: RequestOptions['agent'];
2412
+ };
2413
+ }
2414
+
2415
+ /**
2416
+ * Target for a config evaluation.
2417
+ */
2418
+ interface Target {
2419
+ /**
2420
+ * The key of the target.
2421
+ */
2422
+ key: SplitKey;
2423
+ /**
2424
+ * The attributes of the target.
2425
+ *
2426
+ * @defaultValue `undefined`
2427
+ */
2428
+ attributes?: Attributes;
2429
+ }
2430
+
2431
+ type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
2432
+ type JsonArray = JsonValue[];
2433
+ type JsonObject = { [key: string]: JsonValue; };
2434
+
2435
+ /**
2436
+ * Config object returned by getConfig.
2437
+ */
2438
+ type Config = {
2439
+ /**
2440
+ * The name of the variant.
2441
+ */
2442
+ variant: string;
2443
+ /**
2444
+ * The config value, a raw JSON object.
2445
+ */
2446
+ value: JsonObject;
2447
+ }
2448
+
2449
+ /**
2450
+ * Configs SDK client interface.
2451
+ */
2452
+ interface ConfigsClient extends IStatusInterface {
2453
+ /**
2454
+ * Destroys the client.
2455
+ *
2456
+ * @returns A promise that resolves once all clients are destroyed.
2457
+ */
2458
+ destroy(): Promise<void>;
2459
+ /**
2460
+ * Gets the config object for a given config name and optional target. If no target is provided, the default variant of the config is returned.
2461
+ *
2462
+ * @param configName - The name of the config we want to get.
2463
+ * @param target - The target of the config evaluation.
2464
+ * @param options - An object of type EvaluationOptions for advanced evaluation options.
2465
+ * @returns The config object.
2466
+ */
2467
+ getConfig(configName: string, target?: Target, options?: EvaluationOptions): Config;
2468
+ /**
2469
+ * Tracks an event to be fed to the results product on Harness FME user interface.
2470
+ *
2471
+ * @param trafficKey - The key that identifies the entity related to this event.
2472
+ * @param trafficType - The traffic type of the entity related to this event. See {@link https://developer.harness.io/docs/feature-management-experimentation/management-and-administration/fme-settings/traffic-types/}
2473
+ * @param eventType - The event type corresponding to this event.
2474
+ * @param value - The value of this event.
2475
+ * @param properties - The properties of this event. Values can be string, number, boolean or null.
2476
+ * @returns Whether the event was added to the queue successfully or not.
2477
+ */
2478
+ track(trafficKey: SplitKey, trafficType: string, eventType: string, value?: number, properties?: Properties): boolean;
2479
+ }
2287
2480
  }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.splitsSyncTaskFactory = void 0;
4
- var syncTask_1 = require("../../syncTask");
5
- var splitChangesFetcher_1 = require("../fetchers/splitChangesFetcher");
6
- var splitChangesUpdater_1 = require("../updaters/splitChangesUpdater");
7
- /**
8
- * Creates a sync task that periodically executes a `splitChangesUpdater` task
9
- */
10
- function splitsSyncTaskFactory(fetchSplitChanges, storage, readiness, settings, isClientSide) {
11
- return (0, syncTask_1.syncTaskFactory)(settings.log, (0, splitChangesUpdater_1.splitChangesUpdaterFactory)(settings.log, (0, splitChangesFetcher_1.splitChangesFetcherFactory)(fetchSplitChanges, settings, storage), storage, settings.sync.__splitFiltersValidation, readiness.splits, settings.startup.requestTimeoutBeforeReady, settings.startup.retriesOnFailureBeforeReady, isClientSide), settings.scheduler.featuresRefreshRate, 'splitChangesUpdater');
12
- }
13
- exports.splitsSyncTaskFactory = splitsSyncTaskFactory;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateSplits = void 0;
4
- var constants_1 = require("../../logger/constants");
5
- var lang_1 = require("../lang");
6
- var split_1 = require("./split");
7
- function validateSplits(log, maybeSplits, method, listName, item) {
8
- if (listName === void 0) { listName = 'feature flag names'; }
9
- if (item === void 0) { item = 'feature flag name'; }
10
- if (Array.isArray(maybeSplits) && maybeSplits.length > 0) {
11
- var validatedArray_1 = [];
12
- // Remove invalid values
13
- maybeSplits.forEach(function (maybeSplit) {
14
- var splitName = (0, split_1.validateSplit)(log, maybeSplit, method, item);
15
- if (splitName)
16
- validatedArray_1.push(splitName);
17
- });
18
- // Strip off duplicated values if we have valid split names then return
19
- if (validatedArray_1.length)
20
- return (0, lang_1.uniq)(validatedArray_1);
21
- }
22
- log.error(constants_1.ERROR_EMPTY_ARRAY, [method, listName]);
23
- return false;
24
- }
25
- exports.validateSplits = validateSplits;
@@ -1,9 +0,0 @@
1
- import { syncTaskFactory } from '../../syncTask';
2
- import { splitChangesFetcherFactory } from '../fetchers/splitChangesFetcher';
3
- import { splitChangesUpdaterFactory } from '../updaters/splitChangesUpdater';
4
- /**
5
- * Creates a sync task that periodically executes a `splitChangesUpdater` task
6
- */
7
- export function splitsSyncTaskFactory(fetchSplitChanges, storage, readiness, settings, isClientSide) {
8
- return syncTaskFactory(settings.log, splitChangesUpdaterFactory(settings.log, splitChangesFetcherFactory(fetchSplitChanges, settings, storage), storage, settings.sync.__splitFiltersValidation, readiness.splits, settings.startup.requestTimeoutBeforeReady, settings.startup.retriesOnFailureBeforeReady, isClientSide), settings.scheduler.featuresRefreshRate, 'splitChangesUpdater');
9
- }
@@ -1,15 +0,0 @@
1
- import { FALLBACK_SPLIT_NOT_FOUND, SPLIT_NOT_FOUND } from '../labels';
2
- import { WARN_NOT_EXISTENT_SPLIT } 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 split twice.
6
- */
7
- export function validateSplitExistence(log, readinessManager, splitName, labelOrSplitObj, 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 (labelOrSplitObj === SPLIT_NOT_FOUND || labelOrSplitObj === FALLBACK_SPLIT_NOT_FOUND || labelOrSplitObj == null) {
10
- log.warn(WARN_NOT_EXISTENT_SPLIT, [method, splitName]);
11
- return false;
12
- }
13
- }
14
- return true;
15
- }
@@ -1,21 +0,0 @@
1
- import { ERROR_EMPTY_ARRAY } from '../../logger/constants';
2
- import { uniq } from '../lang';
3
- import { validateSplit } from './split';
4
- export function validateSplits(log, maybeSplits, 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(maybeSplits) && maybeSplits.length > 0) {
8
- var validatedArray_1 = [];
9
- // Remove invalid values
10
- maybeSplits.forEach(function (maybeSplit) {
11
- var splitName = validateSplit(log, maybeSplit, method, item);
12
- if (splitName)
13
- validatedArray_1.push(splitName);
14
- });
15
- // Strip off duplicated values if we have valid split 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
- }
@@ -1,27 +0,0 @@
1
- import { ERROR_NULL, ERROR_INVALID, WARN_TRIMMING, ERROR_EMPTY } from '../../logger/constants';
2
- import { ILogger } from '../../logger/types';
3
- import { isString } from '../lang';
4
-
5
- // include BOM and nbsp
6
- const TRIMMABLE_SPACES_REGEX = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/;
7
-
8
- export function validateSplit(log: ILogger, maybeSplit: any, method: string, item = 'feature flag name'): string | false {
9
- if (maybeSplit == undefined) { // eslint-disable-line eqeqeq
10
- log.error(ERROR_NULL, [method, item]);
11
- } else if (!isString(maybeSplit)) {
12
- log.error(ERROR_INVALID, [method, item]);
13
- } else {
14
- if (TRIMMABLE_SPACES_REGEX.test(maybeSplit)) {
15
- log.warn(WARN_TRIMMING, [method, item, maybeSplit]);
16
- maybeSplit = maybeSplit.trim();
17
- }
18
-
19
- if (maybeSplit.length > 0) {
20
- return maybeSplit;
21
- } else {
22
- log.error(ERROR_EMPTY, [method, item]);
23
- }
24
- }
25
-
26
- return false;
27
- }
@@ -1,19 +0,0 @@
1
- import { FALLBACK_SPLIT_NOT_FOUND, SPLIT_NOT_FOUND } from '../labels';
2
- import { IReadinessManager } from '../../readiness/types';
3
- import { ILogger } from '../../logger/types';
4
- import { WARN_NOT_EXISTENT_SPLIT } from '../../logger/constants';
5
-
6
- /**
7
- * This is defined here and in this format mostly because of the logger and the fact that it's considered a validation at product level.
8
- * But it's not going to run on the input validation layer. In any case, the most compelling reason to use it as we do is to avoid going to Redis and get a split twice.
9
- */
10
- export function validateSplitExistence(log: ILogger, readinessManager: IReadinessManager, splitName: string, labelOrSplitObj: any, method: string): boolean {
11
- if (readinessManager.isReady()) { // Only if it's ready (synced with BE) we validate this, otherwise it may just be that the SDK is still syncing
12
- if (labelOrSplitObj === SPLIT_NOT_FOUND || labelOrSplitObj === FALLBACK_SPLIT_NOT_FOUND || labelOrSplitObj == null) {
13
- log.warn(WARN_NOT_EXISTENT_SPLIT, [method, splitName]);
14
- return false;
15
- }
16
- }
17
-
18
- return true;
19
- }
@@ -1,21 +0,0 @@
1
- import { ERROR_EMPTY_ARRAY } from '../../logger/constants';
2
- import { ILogger } from '../../logger/types';
3
- import { uniq } from '../lang';
4
- import { validateSplit } from './split';
5
-
6
- export function validateSplits(log: ILogger, maybeSplits: any, method: string, listName = 'feature flag names', item = 'feature flag name'): string[] | false {
7
- if (Array.isArray(maybeSplits) && maybeSplits.length > 0) {
8
- let validatedArray: string[] = [];
9
- // Remove invalid values
10
- maybeSplits.forEach(maybeSplit => {
11
- const splitName = validateSplit(log, maybeSplit, method, item);
12
- if (splitName) validatedArray.push(splitName);
13
- });
14
-
15
- // Strip off duplicated values if we have valid split names then return
16
- if (validatedArray.length) return uniq(validatedArray);
17
- }
18
-
19
- log.error(ERROR_EMPTY_ARRAY, [method, listName]);
20
- return false;
21
- }