vwo-fme-node-sdk 1.0.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 (385) hide show
  1. package/CONTRIBUTING.md +46 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +18 -0
  4. package/README.md +52 -0
  5. package/dist/VWO.d.ts +9 -0
  6. package/dist/VWO.js +100 -0
  7. package/dist/VWO.js.map +1 -0
  8. package/dist/VWOBuilder.d.ts +48 -0
  9. package/dist/VWOBuilder.js +173 -0
  10. package/dist/VWOBuilder.js.map +1 -0
  11. package/dist/VWOClient.d.ts +20 -0
  12. package/dist/VWOClient.js +249 -0
  13. package/dist/VWOClient.js.map +1 -0
  14. package/dist/api/GetFlag.d.ts +19 -0
  15. package/dist/api/GetFlag.js +394 -0
  16. package/dist/api/GetFlag.js.map +1 -0
  17. package/dist/api/GetVariable.d.ts +0 -0
  18. package/dist/api/GetVariable.js +1 -0
  19. package/dist/api/GetVariable.js.map +1 -0
  20. package/dist/api/GetVariables.d.ts +0 -0
  21. package/dist/api/GetVariables.js +1 -0
  22. package/dist/api/GetVariables.js.map +1 -0
  23. package/dist/api/SetAttribute.d.ts +7 -0
  24. package/dist/api/SetAttribute.js +62 -0
  25. package/dist/api/SetAttribute.js.map +1 -0
  26. package/dist/api/Track.js +76 -0
  27. package/dist/api/Track.js.map +1 -0
  28. package/dist/api/TrackEvent.d.ts +8 -0
  29. package/dist/api/TrackEvent.js +78 -0
  30. package/dist/api/TrackEvent.js.map +1 -0
  31. package/dist/constants/index.d.ts +24 -0
  32. package/dist/constants/index.js +31 -0
  33. package/dist/constants/index.js.map +1 -0
  34. package/dist/constants/url.d.ts +6 -0
  35. package/dist/constants/url.js +10 -0
  36. package/dist/constants/url.js.map +1 -0
  37. package/dist/decision-maker/index.js +75 -0
  38. package/dist/decision-maker/index.js.map +1 -0
  39. package/dist/decorators/StorageDecorator.d.ts +12 -0
  40. package/dist/decorators/StorageDecorator.js +119 -0
  41. package/dist/decorators/StorageDecorator.js.map +1 -0
  42. package/dist/enums/ApiEnum.d.ts +4 -0
  43. package/dist/enums/ApiEnum.js +9 -0
  44. package/dist/enums/ApiEnum.js.map +1 -0
  45. package/dist/enums/EventEnum.d.ts +4 -0
  46. package/dist/enums/EventEnum.js +9 -0
  47. package/dist/enums/EventEnum.js.map +1 -0
  48. package/dist/enums/HeadersEnum.d.ts +4 -0
  49. package/dist/enums/HeadersEnum.js +9 -0
  50. package/dist/enums/HeadersEnum.js.map +1 -0
  51. package/dist/enums/HooksEnum.d.ts +7 -0
  52. package/dist/enums/HooksEnum.js +8 -0
  53. package/dist/enums/HooksEnum.js.map +1 -0
  54. package/dist/enums/LogLevelEnum.d.ts +7 -0
  55. package/dist/enums/LogLevelEnum.js +12 -0
  56. package/dist/enums/LogLevelEnum.js.map +1 -0
  57. package/dist/enums/StatusEnum.d.ts +4 -0
  58. package/dist/enums/StorageEnum.d.ts +8 -0
  59. package/dist/enums/StorageEnum.js +13 -0
  60. package/dist/enums/StorageEnum.js.map +1 -0
  61. package/dist/enums/UrlEnum.d.ts +13 -0
  62. package/dist/enums/UrlEnum.js +18 -0
  63. package/dist/enums/UrlEnum.js.map +1 -0
  64. package/dist/enums/campaignTypeEnum.d.ts +5 -0
  65. package/dist/enums/campaignTypeEnum.js +10 -0
  66. package/dist/enums/campaignTypeEnum.js.map +1 -0
  67. package/dist/enums/logMessages/DbugLogMessageEnum.js +1 -0
  68. package/dist/enums/logMessages/DbugLogMessageEnum.js.map +1 -0
  69. package/dist/enums/logMessages/DebugLogMessageEnum.d.ts +3 -0
  70. package/dist/enums/logMessages/ErorLogMessageEnum.js +1 -0
  71. package/dist/enums/logMessages/ErorLogMessageEnum.js.map +1 -0
  72. package/dist/enums/logMessages/ErrorLogMessageEnum.d.ts +3 -0
  73. package/dist/enums/logMessages/debugLogMessageEnum.js +8 -0
  74. package/dist/enums/logMessages/debugLogMessageEnum.js.map +1 -0
  75. package/dist/enums/logMessages/errorLogMessageEnum.js +8 -0
  76. package/dist/enums/logMessages/errorLogMessageEnum.js.map +1 -0
  77. package/dist/enums/statusEnum.js +9 -0
  78. package/dist/enums/statusEnum.js.map +1 -0
  79. package/dist/index.d.ts +1 -0
  80. package/dist/index.js +7 -0
  81. package/dist/index.js.map +1 -0
  82. package/dist/logger/core/logManager.js +97 -0
  83. package/dist/logger/core/logManager.js.map +1 -0
  84. package/dist/logger/core/transportManager.js +60 -0
  85. package/dist/logger/core/transportManager.js.map +1 -0
  86. package/dist/logger/enums/logLevelEnum.js +12 -0
  87. package/dist/logger/enums/logLevelEnum.js.map +1 -0
  88. package/dist/logger/index.js +8 -0
  89. package/dist/logger/index.js.map +1 -0
  90. package/dist/logger/logMessageBuilder.js +43 -0
  91. package/dist/logger/logMessageBuilder.js.map +1 -0
  92. package/dist/logger/logger.js +10 -0
  93. package/dist/logger/logger.js.map +1 -0
  94. package/dist/logger/transports/consoleTransport.js +32 -0
  95. package/dist/logger/transports/consoleTransport.js.map +1 -0
  96. package/dist/models/CampaignModel.d.ts +32 -0
  97. package/dist/models/CampaignModel.js +149 -0
  98. package/dist/models/CampaignModel.js.map +1 -0
  99. package/dist/models/FeatureModel.d.ts +20 -0
  100. package/dist/models/FeatureModel.js +72 -0
  101. package/dist/models/FeatureModel.js.map +1 -0
  102. package/dist/models/ImpactCampaignModel.d.ts +7 -0
  103. package/dist/models/ImpactCampaignModel.js +21 -0
  104. package/dist/models/ImpactCampaignModel.js.map +1 -0
  105. package/dist/models/MetricModel.d.ts +12 -0
  106. package/dist/models/MetricModel.js +25 -0
  107. package/dist/models/MetricModel.js.map +1 -0
  108. package/dist/models/RuleModel.d.ts +11 -0
  109. package/dist/models/RuleModel.js +29 -0
  110. package/dist/models/RuleModel.js.map +1 -0
  111. package/dist/models/SettingsModel.d.ts +28 -0
  112. package/dist/models/SettingsModel.js +70 -0
  113. package/dist/models/SettingsModel.js.map +1 -0
  114. package/dist/models/VariableModel.d.ts +18 -0
  115. package/dist/models/VariableModel.js +38 -0
  116. package/dist/models/VariableModel.js.map +1 -0
  117. package/dist/models/VariationModel.d.ts +29 -0
  118. package/dist/models/VariationModel.js +80 -0
  119. package/dist/models/VariationModel.js.map +1 -0
  120. package/dist/models/schemas/SettingsSchemaValidation.d.ts +13 -0
  121. package/dist/models/schemas/SettingsSchemaValidation.js +70 -0
  122. package/dist/models/schemas/SettingsSchemaValidation.js.map +1 -0
  123. package/dist/modules/decision-maker/index.d.ts +38 -0
  124. package/dist/modules/decision-maker/index.js +67 -0
  125. package/dist/modules/decision-maker/index.js.map +1 -0
  126. package/dist/modules/logger/core/logManager.d.ts +40 -0
  127. package/dist/modules/logger/core/logManager.js +97 -0
  128. package/dist/modules/logger/core/logManager.js.map +1 -0
  129. package/dist/modules/logger/core/transportManager.d.ts +22 -0
  130. package/dist/modules/logger/core/transportManager.js +60 -0
  131. package/dist/modules/logger/core/transportManager.js.map +1 -0
  132. package/dist/modules/logger/enums/logLevelEnum.d.ts +7 -0
  133. package/dist/modules/logger/enums/logLevelEnum.js +12 -0
  134. package/dist/modules/logger/enums/logLevelEnum.js.map +1 -0
  135. package/dist/modules/logger/index.d.ts +2 -0
  136. package/dist/modules/logger/index.js +8 -0
  137. package/dist/modules/logger/index.js.map +1 -0
  138. package/dist/modules/logger/logMessageBuilder.d.ts +21 -0
  139. package/dist/modules/logger/logMessageBuilder.js +43 -0
  140. package/dist/modules/logger/logMessageBuilder.js.map +1 -0
  141. package/dist/modules/logger/logger.d.ts +7 -0
  142. package/dist/modules/logger/logger.js +10 -0
  143. package/dist/modules/logger/logger.js.map +1 -0
  144. package/dist/modules/logger/transports/consoleTransport.d.ts +12 -0
  145. package/dist/modules/logger/transports/consoleTransport.js +32 -0
  146. package/dist/modules/logger/transports/consoleTransport.js.map +1 -0
  147. package/dist/modules/networking/client/networkClient.d.ts +7 -0
  148. package/dist/modules/networking/client/networkClient.js +117 -0
  149. package/dist/modules/networking/client/networkClient.js.map +1 -0
  150. package/dist/modules/networking/client/networkClientInterface.d.ts +6 -0
  151. package/dist/modules/networking/client/networkClientInterface.js +3 -0
  152. package/dist/modules/networking/client/networkClientInterface.js.map +1 -0
  153. package/dist/modules/networking/handlers/requestHandler.d.ts +5 -0
  154. package/dist/modules/networking/handlers/requestHandler.js +29 -0
  155. package/dist/modules/networking/handlers/requestHandler.js.map +1 -0
  156. package/dist/modules/networking/index.d.ts +6 -0
  157. package/dist/modules/networking/index.js +14 -0
  158. package/dist/modules/networking/index.js.map +1 -0
  159. package/dist/modules/networking/manager/networkManager.d.ts +16 -0
  160. package/dist/modules/networking/manager/networkManager.js +72 -0
  161. package/dist/modules/networking/manager/networkManager.js.map +1 -0
  162. package/dist/modules/networking/models/globalRequestModel.d.ts +22 -0
  163. package/dist/modules/networking/models/globalRequestModel.js +51 -0
  164. package/dist/modules/networking/models/globalRequestModel.js.map +1 -0
  165. package/dist/modules/networking/models/requestModel.d.ts +32 -0
  166. package/dist/modules/networking/models/requestModel.js +128 -0
  167. package/dist/modules/networking/models/requestModel.js.map +1 -0
  168. package/dist/modules/networking/models/responseModel.d.ts +15 -0
  169. package/dist/modules/networking/models/responseModel.js +34 -0
  170. package/dist/modules/networking/models/responseModel.js.map +1 -0
  171. package/dist/modules/segmentor/core/segmentationManger.d.ts +10 -0
  172. package/dist/modules/segmentor/core/segmentationManger.js +68 -0
  173. package/dist/modules/segmentor/core/segmentationManger.js.map +1 -0
  174. package/dist/modules/segmentor/enums/segmentOperandRegexEnum.d.ts +10 -0
  175. package/dist/modules/segmentor/enums/segmentOperandRegexEnum.js +15 -0
  176. package/dist/modules/segmentor/enums/segmentOperandRegexEnum.js.map +1 -0
  177. package/dist/modules/segmentor/enums/segmentOperandValueEnum.d.ts +8 -0
  178. package/dist/modules/segmentor/enums/segmentOperandValueEnum.js +13 -0
  179. package/dist/modules/segmentor/enums/segmentOperandValueEnum.js.map +1 -0
  180. package/dist/modules/segmentor/enums/segmentOperatorValueEnum.d.ts +15 -0
  181. package/dist/modules/segmentor/enums/segmentOperatorValueEnum.js +20 -0
  182. package/dist/modules/segmentor/enums/segmentOperatorValueEnum.js.map +1 -0
  183. package/dist/modules/segmentor/evaluators/segmentEvaluator.d.ts +15 -0
  184. package/dist/modules/segmentor/evaluators/segmentEvaluator.js +379 -0
  185. package/dist/modules/segmentor/evaluators/segmentEvaluator.js.map +1 -0
  186. package/dist/modules/segmentor/evaluators/segmentOperandEvaluator.d.ts +12 -0
  187. package/dist/modules/segmentor/evaluators/segmentOperandEvaluator.js +248 -0
  188. package/dist/modules/segmentor/evaluators/segmentOperandEvaluator.js.map +1 -0
  189. package/dist/modules/segmentor/index.d.ts +3 -0
  190. package/dist/modules/segmentor/index.js +8 -0
  191. package/dist/modules/segmentor/index.js.map +1 -0
  192. package/dist/modules/segmentor/segmentation.d.ts +5 -0
  193. package/dist/modules/segmentor/segmentation.js +3 -0
  194. package/dist/modules/segmentor/segmentation.js.map +1 -0
  195. package/dist/modules/segmentor/utils/SegmentUtil.d.ts +2 -0
  196. package/dist/modules/segmentor/utils/SegmentUtil.js +26 -0
  197. package/dist/modules/segmentor/utils/SegmentUtil.js.map +1 -0
  198. package/dist/modules/storage/connector.d.ts +14 -0
  199. package/dist/modules/storage/connector.js +10 -0
  200. package/dist/modules/storage/connector.js.map +1 -0
  201. package/dist/modules/storage/connectors/index.d.ts +0 -0
  202. package/dist/modules/storage/connectors/index.js +3 -0
  203. package/dist/modules/storage/connectors/index.js.map +1 -0
  204. package/dist/modules/storage/connectors/memoryConnector.d.ts +26 -0
  205. package/dist/modules/storage/connectors/memoryConnector.js +103 -0
  206. package/dist/modules/storage/connectors/memoryConnector.js.map +1 -0
  207. package/dist/modules/storage/connectors/redisConnector.d.ts +0 -0
  208. package/dist/modules/storage/connectors/redisConnector.js +181 -0
  209. package/dist/modules/storage/connectors/redisConnector.js.map +1 -0
  210. package/dist/modules/storage/index.d.ts +1 -0
  211. package/dist/modules/storage/index.js +6 -0
  212. package/dist/modules/storage/index.js.map +1 -0
  213. package/dist/modules/storage/storage.d.ts +10 -0
  214. package/dist/modules/storage/storage.js +50 -0
  215. package/dist/modules/storage/storage.js.map +1 -0
  216. package/dist/networking/client/networkClient.js +117 -0
  217. package/dist/networking/client/networkClient.js.map +1 -0
  218. package/dist/networking/client/networkClientInterface.js +3 -0
  219. package/dist/networking/client/networkClientInterface.js.map +1 -0
  220. package/dist/networking/handlers/requestHandler.js +29 -0
  221. package/dist/networking/handlers/requestHandler.js.map +1 -0
  222. package/dist/networking/index.js +14 -0
  223. package/dist/networking/index.js.map +1 -0
  224. package/dist/networking/manager/networkManager.js +72 -0
  225. package/dist/networking/manager/networkManager.js.map +1 -0
  226. package/dist/networking/models/globalRequestModel.js +51 -0
  227. package/dist/networking/models/globalRequestModel.js.map +1 -0
  228. package/dist/networking/models/requestModel.js +107 -0
  229. package/dist/networking/models/requestModel.js.map +1 -0
  230. package/dist/networking/models/responseModel.js +34 -0
  231. package/dist/networking/models/responseModel.js.map +1 -0
  232. package/dist/segmentor/core/segmentationManger.js +25 -0
  233. package/dist/segmentor/core/segmentationManger.js.map +1 -0
  234. package/dist/segmentor/enums/segmentOperandRegexEnum.js +15 -0
  235. package/dist/segmentor/enums/segmentOperandRegexEnum.js.map +1 -0
  236. package/dist/segmentor/enums/segmentOperandValueEnum.js +13 -0
  237. package/dist/segmentor/enums/segmentOperandValueEnum.js.map +1 -0
  238. package/dist/segmentor/enums/segmentOperatorValueEnum.js +12 -0
  239. package/dist/segmentor/enums/segmentOperatorValueEnum.js.map +1 -0
  240. package/dist/segmentor/evaluators/segmentEvaluator.js +52 -0
  241. package/dist/segmentor/evaluators/segmentEvaluator.js.map +1 -0
  242. package/dist/segmentor/evaluators/segmentOperandEvaluator.js +158 -0
  243. package/dist/segmentor/evaluators/segmentOperandEvaluator.js.map +1 -0
  244. package/dist/segmentor/index.js +8 -0
  245. package/dist/segmentor/index.js.map +1 -0
  246. package/dist/segmentor/segmentation.js +3 -0
  247. package/dist/segmentor/segmentation.js.map +1 -0
  248. package/dist/segmentor/utils/SegmentUtil.js +27 -0
  249. package/dist/segmentor/utils/SegmentUtil.js.map +1 -0
  250. package/dist/services/CampaignDecisionService.d.ts +44 -0
  251. package/dist/services/CampaignDecisionService.js +175 -0
  252. package/dist/services/CampaignDecisionService.js.map +1 -0
  253. package/dist/services/HooksManager.d.ts +27 -0
  254. package/dist/services/HooksManager.js +40 -0
  255. package/dist/services/HooksManager.js.map +1 -0
  256. package/dist/services/SettingsManager.d.ts +21 -0
  257. package/dist/services/SettingsManager.js +168 -0
  258. package/dist/services/SettingsManager.js.map +1 -0
  259. package/dist/services/StorageService.d.ts +5 -0
  260. package/dist/services/StorageService.js +94 -0
  261. package/dist/services/StorageService.js.map +1 -0
  262. package/dist/services/UrlService.d.ts +13 -0
  263. package/dist/services/UrlService.js +37 -0
  264. package/dist/services/UrlService.js.map +1 -0
  265. package/dist/types/common.d.ts +2 -0
  266. package/dist/types/common.js +3 -0
  267. package/dist/types/common.js.map +1 -0
  268. package/dist/utils/CampaignUtil.d.ts +23 -0
  269. package/dist/utils/CampaignUtil.js +228 -0
  270. package/dist/utils/CampaignUtil.js.map +1 -0
  271. package/dist/utils/DataTypeUtil.d.ts +17 -0
  272. package/dist/utils/DataTypeUtil.js +86 -0
  273. package/dist/utils/DataTypeUtil.js.map +1 -0
  274. package/dist/utils/DecisionUtil.d.ts +4 -0
  275. package/dist/utils/DecisionUtil.js +197 -0
  276. package/dist/utils/DecisionUtil.js.map +1 -0
  277. package/dist/utils/FunctionUtil.d.ts +13 -0
  278. package/dist/utils/FunctionUtil.js +121 -0
  279. package/dist/utils/FunctionUtil.js.map +1 -0
  280. package/dist/utils/LogMessageUtil.d.ts +16 -0
  281. package/dist/utils/LogMessageUtil.js +53 -0
  282. package/dist/utils/LogMessageUtil.js.map +1 -0
  283. package/dist/utils/MegUtil.d.ts +7 -0
  284. package/dist/utils/MegUtil.js +413 -0
  285. package/dist/utils/MegUtil.js.map +1 -0
  286. package/dist/utils/NetworkUtil.d.ts +140 -0
  287. package/dist/utils/NetworkUtil.js +238 -0
  288. package/dist/utils/NetworkUtil.js.map +1 -0
  289. package/dist/utils/PromiseUtil.d.ts +1 -0
  290. package/dist/utils/PromiseUtil.js +13 -0
  291. package/dist/utils/PromiseUtil.js.map +1 -0
  292. package/dist/utils/SettingsUtil.d.ts +2 -0
  293. package/dist/utils/SettingsUtil.js +17 -0
  294. package/dist/utils/SettingsUtil.js.map +1 -0
  295. package/dist/utils/UuidUtil.d.ts +2 -0
  296. package/dist/utils/UuidUtil.js +30 -0
  297. package/dist/utils/UuidUtil.js.map +1 -0
  298. package/dist/utils/WebServiceUtil.d.ts +4 -0
  299. package/dist/utils/WebServiceUtil.js +93 -0
  300. package/dist/utils/WebServiceUtil.js.map +1 -0
  301. package/dist/utils/logMessageBuilder.d.ts +21 -0
  302. package/dist/utils/logMessageBuilder.js +43 -0
  303. package/dist/utils/logMessageBuilder.js.map +1 -0
  304. package/lib/VWO.ts +55 -0
  305. package/lib/VWOBuilder.ts +237 -0
  306. package/lib/VWOClient.ts +321 -0
  307. package/lib/api/GetFlag.ts +458 -0
  308. package/lib/api/GetVariable.ts +0 -0
  309. package/lib/api/GetVariables.ts +0 -0
  310. package/lib/api/SetAttribute.ts +33 -0
  311. package/lib/api/TrackEvent.ts +52 -0
  312. package/lib/constants/index.ts +35 -0
  313. package/lib/constants/url.ts +7 -0
  314. package/lib/decorators/StorageDecorator.ts +98 -0
  315. package/lib/enums/ApiEnum.ts +4 -0
  316. package/lib/enums/EventEnum.ts +4 -0
  317. package/lib/enums/HeadersEnum.ts +4 -0
  318. package/lib/enums/HooksEnum.ts +11 -0
  319. package/lib/enums/LogLevelEnum.ts +7 -0
  320. package/lib/enums/StatusEnum.ts +4 -0
  321. package/lib/enums/StorageEnum.ts +8 -0
  322. package/lib/enums/UrlEnum.ts +13 -0
  323. package/lib/enums/campaignTypeEnum.ts +5 -0
  324. package/lib/enums/logMessages/DebugLogMessageEnum.ts +3 -0
  325. package/lib/enums/logMessages/ErrorLogMessageEnum.ts +3 -0
  326. package/lib/index.ts +1 -0
  327. package/lib/models/CampaignModel.ts +176 -0
  328. package/lib/models/FeatureModel.ts +81 -0
  329. package/lib/models/ImpactCampaignModel.ts +20 -0
  330. package/lib/models/MetricModel.ts +31 -0
  331. package/lib/models/RuleModel.ts +35 -0
  332. package/lib/models/SettingsModel.ts +95 -0
  333. package/lib/models/VariableModel.ts +51 -0
  334. package/lib/models/VariationModel.ts +101 -0
  335. package/lib/models/schemas/SettingsSchemaValidation.ts +83 -0
  336. package/lib/modules/decision-maker/index.ts +65 -0
  337. package/lib/modules/logger/core/logManager.ts +113 -0
  338. package/lib/modules/logger/core/transportManager.ts +76 -0
  339. package/lib/modules/logger/enums/logLevelEnum.ts +7 -0
  340. package/lib/modules/logger/index.ts +2 -0
  341. package/lib/modules/logger/logMessageBuilder.ts +60 -0
  342. package/lib/modules/logger/logger.ts +7 -0
  343. package/lib/modules/logger/transports/consoleTransport.ts +37 -0
  344. package/lib/modules/networking/client/networkClient.ts +128 -0
  345. package/lib/modules/networking/client/networkClientInterface.ts +8 -0
  346. package/lib/modules/networking/handlers/requestHandler.ts +28 -0
  347. package/lib/modules/networking/index.ts +6 -0
  348. package/lib/modules/networking/manager/networkManager.ts +77 -0
  349. package/lib/modules/networking/models/globalRequestModel.ts +69 -0
  350. package/lib/modules/networking/models/requestModel.ts +164 -0
  351. package/lib/modules/networking/models/responseModel.ts +40 -0
  352. package/lib/modules/segmentor/core/segmentationManger.ts +22 -0
  353. package/lib/modules/segmentor/enums/segmentOperandRegexEnum.ts +10 -0
  354. package/lib/modules/segmentor/enums/segmentOperandValueEnum.ts +8 -0
  355. package/lib/modules/segmentor/enums/segmentOperatorValueEnum.ts +15 -0
  356. package/lib/modules/segmentor/evaluators/segmentEvaluator.ts +239 -0
  357. package/lib/modules/segmentor/evaluators/segmentOperandEvaluator.ts +199 -0
  358. package/lib/modules/segmentor/index.ts +3 -0
  359. package/lib/modules/segmentor/segmentation.ts +6 -0
  360. package/lib/modules/segmentor/utils/SegmentUtil.ts +23 -0
  361. package/lib/modules/storage/connector.ts +25 -0
  362. package/lib/modules/storage/connectors/index.ts +2 -0
  363. package/lib/modules/storage/connectors/memoryConnector.ts +115 -0
  364. package/lib/modules/storage/connectors/redisConnector.ts +180 -0
  365. package/lib/modules/storage/index.ts +1 -0
  366. package/lib/modules/storage/storage.ts +48 -0
  367. package/lib/services/CampaignDecisionService.ts +160 -0
  368. package/lib/services/HooksManager.ts +50 -0
  369. package/lib/services/SettingsManager.ts +167 -0
  370. package/lib/services/StorageService.ts +53 -0
  371. package/lib/services/UrlService.ts +50 -0
  372. package/lib/types/common.ts +13 -0
  373. package/lib/utils/CampaignUtil.ts +236 -0
  374. package/lib/utils/DataTypeUtil.ts +87 -0
  375. package/lib/utils/DecisionUtil.ts +180 -0
  376. package/lib/utils/FunctionUtil.ts +105 -0
  377. package/lib/utils/LogMessageUtil.ts +52 -0
  378. package/lib/utils/MegUtil.ts +408 -0
  379. package/lib/utils/NetworkUtil.ts +262 -0
  380. package/lib/utils/PromiseUtil.ts +10 -0
  381. package/lib/utils/SettingsUtil.ts +18 -0
  382. package/lib/utils/UuidUtil.ts +33 -0
  383. package/lib/utils/WebServiceUtil.ts +60 -0
  384. package/lib/utils/logMessageBuilder.ts +60 -0
  385. package/package.json +70 -0
@@ -0,0 +1,236 @@
1
+ import { VariationModel } from '../models/VariationModel';
2
+ import { VariableModel } from '../models/VariableModel';
3
+ import { Constants } from '../constants';
4
+ import { CampaignModel } from '../models/CampaignModel';
5
+ import { LogManager } from '../modules/logger';
6
+ import { CampaignTypeEnum } from '../enums/campaignTypeEnum';
7
+ import { SettingsModel } from '../models/SettingsModel';
8
+
9
+ export function setVariationAllocation(campaign: CampaignModel): void {
10
+ if (campaign.getType() === CampaignTypeEnum.ROLLOUT || campaign.getType() === CampaignTypeEnum.PERSONALIZE) {
11
+ // Handle special logic for rollout or personalize campaigns
12
+ handleRolloutCampaign(campaign);
13
+ } else {
14
+ let stepFactor = 0;
15
+ const numberOfVariations = campaign.getVariations().length;
16
+ for (let i = 0, currentAllocation = 0; i < numberOfVariations; i++) {
17
+ let variation = campaign.getVariations()[i];
18
+
19
+ stepFactor = assignRangeValues(variation, currentAllocation);
20
+ currentAllocation += stepFactor;
21
+ LogManager.Instance.debug(
22
+ `VARIATION_RANGE_ALLOCATION: Variation:${variation.getKey()} of Campaign:${campaign.getKey()} having weight:${variation.getWeight()} got bucketing range: ( ${variation.getStartRangeVariation()} - ${variation.getEndRangeVariation()} )`,
23
+ );
24
+ }
25
+ }
26
+ }
27
+
28
+ function handleRolloutCampaign(campaign: CampaignModel): void {
29
+ // Set start and end ranges for all variations in the campaign
30
+ for (let i = 0; i < campaign.getVariations().length; i++) {
31
+ let variation = campaign.getVariations()[i];
32
+ let endRange = campaign.getVariations()[i].getWeight() * 100;
33
+ variation.setStartRange(1);
34
+ variation.setEndRange(endRange);
35
+ LogManager.Instance.debug(
36
+ `VARIATION_RANGE_ALLOCATION: Variation:${variation.getKey()} of Campaign:${campaign.getKey()} got bucketing range: ( ${1} - ${endRange} )`,
37
+ );
38
+ }
39
+ }
40
+
41
+ function copyVariableData(variationVariable: Array<VariableModel>, featureVariable: Array<VariableModel>): void {
42
+ // create a featureVariableMap
43
+ const featureVariableMap: Record<number, VariableModel> = {};
44
+ featureVariable.forEach((variable: VariableModel) => {
45
+ featureVariableMap[variable.getId()] = variable;
46
+ });
47
+ variationVariable.forEach((variable: VariableModel) => {
48
+ const featureVariable: VariableModel = featureVariableMap[variable.getId()];
49
+ if (featureVariable) {
50
+ variable.setKey(featureVariable.getKey());
51
+ variable.setType(featureVariable.getType());
52
+ }
53
+ });
54
+ }
55
+
56
+ export function assignRangeValues(data: VariationModel, currentAllocation: number) {
57
+ const stepFactor: number = getVariationBucketRange(data.getWeight());
58
+
59
+ if (stepFactor) {
60
+ data.setStartRange(currentAllocation + 1);
61
+ data.setEndRange(currentAllocation + stepFactor);
62
+ } else {
63
+ data.setStartRange(-1);
64
+ data.setEndRange(-1);
65
+ }
66
+ return stepFactor;
67
+ }
68
+
69
+ function getVariationBucketRange(variationWeight: number) {
70
+ if (!variationWeight || variationWeight === 0) {
71
+ return 0;
72
+ }
73
+
74
+ const startRange = Math.ceil(variationWeight * 100);
75
+
76
+ return Math.min(startRange, Constants.MAX_TRAFFIC_VALUE);
77
+ }
78
+
79
+ export function scaleVariationWeights(variations: any) {
80
+ const totalWeight = variations.reduce((acc, variation) => {
81
+ return acc + variation.weight;
82
+ }, 0);
83
+ if (!totalWeight) {
84
+ const weight = 100 / variations.length;
85
+ variations.forEach((variation) => (variation.weight = weight));
86
+ } else {
87
+ variations.forEach((variation) => (variation.weight = (variation.weight / totalWeight) * 100));
88
+ }
89
+ }
90
+
91
+ export function getBucketingSeed(userId, campaign, groupId) {
92
+ if (groupId) {
93
+ return `${groupId}_${userId}`;
94
+ }
95
+ return `${campaign.id}_${userId}`;
96
+ }
97
+
98
+ export function getCampaignVariation(settings, campaignKey, variationId) {
99
+ const campaign: CampaignModel = settings.getCampaigns().find((campaign: CampaignModel) => {
100
+ return campaign.getKey() === campaignKey;
101
+ });
102
+
103
+ if (campaign) {
104
+ const variation: VariationModel = campaign.getVariations().find((variation: VariationModel) => {
105
+ return variation.getId() === variationId;
106
+ });
107
+
108
+ if (variation) {
109
+ return new VariationModel().modelFromDictionary(variation);
110
+ }
111
+ }
112
+ return null;
113
+ }
114
+
115
+ export function getRolloutVariation(settings, rolloutKey, variationId) {
116
+ const rolloutCampaign: CampaignModel = settings.getCampaigns().find((campaign: CampaignModel) => {
117
+ return campaign.getKey() === rolloutKey;
118
+ });
119
+
120
+ if (rolloutCampaign) {
121
+ const variation: VariationModel = rolloutCampaign.getVariations().find((variation: VariationModel) => {
122
+ return variation.getId() === variationId;
123
+ });
124
+
125
+ if (variation) {
126
+ return new VariationModel().modelFromDictionary(variation);
127
+ }
128
+ }
129
+ return null;
130
+ }
131
+
132
+ export function setCampaignAllocation(campaigns: any[]) {
133
+ let stepFactor = 0;
134
+ for (let i = 0, currentAllocation = 0; i < campaigns.length; i++) {
135
+ let campaign = campaigns[i];
136
+
137
+ stepFactor = assignRangeValuesMEG(campaign, currentAllocation);
138
+ currentAllocation += stepFactor;
139
+ }
140
+ }
141
+
142
+ export function isPartOfGroup(settings: any, campaignId: any) {
143
+ if (settings.campaignGroups && settings.campaignGroups.hasOwnProperty(campaignId)) {
144
+ return {
145
+ groupId: settings.campaignGroups[campaignId],
146
+ groupName: settings.groups[settings.campaignGroups[campaignId]].name,
147
+ };
148
+ }
149
+ return {};
150
+ }
151
+
152
+ export function findGroupsFeaturePartOf(settings: any, featureKey: string) {
153
+ const campaignIds: Array<number> = [];
154
+ // loop over all rules inside feature where feature key is given featureKey and get all campaignIds
155
+ settings.features.forEach((feature) => {
156
+ if (feature.key === featureKey) {
157
+ feature.rules.forEach((rule) => {
158
+ if (campaignIds.indexOf(rule.campaignId) === -1) {
159
+ campaignIds.push(rule.campaignId);
160
+ }
161
+ });
162
+ }
163
+ });
164
+
165
+ // loop over all campaigns and find the group for the campaign
166
+ const groups: Array<any> = [];
167
+ campaignIds.forEach((campaignId) => {
168
+ const group = isPartOfGroup(settings, campaignId);
169
+ if (group.groupId) {
170
+ // check if group is already added to groups array
171
+ const groupIndex = groups.findIndex((grp) => grp.groupId === group.groupId);
172
+ if (groupIndex === -1) {
173
+ groups.push(group);
174
+ }
175
+ }
176
+ });
177
+ return groups;
178
+ }
179
+
180
+ export function getCampaignsByGroupId(settings: SettingsModel, groupId: any) {
181
+ const group = settings.getGroups()[groupId];
182
+ if (group) {
183
+ return group.campaigns;
184
+ } else {
185
+ return []; // Return an empty array if the group ID is not found
186
+ }
187
+ }
188
+
189
+ export function getFeatureKeysFromCampaignIds(settings: SettingsModel, campaignIds: any) {
190
+ const featureKeys = [];
191
+ for (const campaignId of campaignIds) {
192
+ settings.getFeatures().forEach((feature) => {
193
+ feature.getRules().forEach((rule) => {
194
+ if (rule.getCampaignId() === campaignId) {
195
+ featureKeys.push(feature.getKey());
196
+ }
197
+ });
198
+ });
199
+ }
200
+ return featureKeys;
201
+ }
202
+
203
+ export function getCampaignIdsFromFeatureKey(settings: SettingsModel, featureKey: string) {
204
+ const campaignIds = [];
205
+ settings.getFeatures().forEach((feature) => {
206
+ if (feature.getKey() === featureKey) {
207
+ feature.getRules().forEach((rule) => {
208
+ campaignIds.push(rule.getCampaignId());
209
+ });
210
+ }
211
+ });
212
+ return campaignIds;
213
+ }
214
+
215
+ export function assignRangeValuesMEG(data: any, currentAllocation: number) {
216
+ const stepFactor: number = getVariationBucketRange(data.weight);
217
+
218
+ if (stepFactor) {
219
+ data.startRangeVariation = currentAllocation + 1;
220
+ data.endRangeVariation = currentAllocation + stepFactor;
221
+ } else {
222
+ data.startRangeVariation = -1;
223
+ data.endRangeVariation = -1;
224
+ }
225
+ return stepFactor;
226
+ }
227
+
228
+ export function getRuleTypeUsingCampaignIdFromFeature(feature: any, campaignId: number) {
229
+ let ruleType = '';
230
+ feature.rules.forEach((rule) => {
231
+ if (rule.campaignId === campaignId) {
232
+ ruleType = rule.type;
233
+ }
234
+ });
235
+ return ruleType;
236
+ }
@@ -0,0 +1,87 @@
1
+ import { dynamic } from '../types/common';
2
+
3
+ type FunctionType = (val: dynamic) => void;
4
+
5
+ export function isObject<T>(
6
+ val: T,
7
+ ): val is Record<any, dynamic> & Exclude<T, Array<dynamic> | FunctionType | RegExp | Promise<dynamic> | Date> {
8
+ return Object.prototype.toString.call(val) === '[object Object]';
9
+ }
10
+
11
+ export function isArray(val: dynamic): val is Array<dynamic> {
12
+ return Object.prototype.toString.call(val) === '[object Array]';
13
+ }
14
+
15
+ export function isNull(val: dynamic): val is null {
16
+ return Object.prototype.toString.call(val) === '[object Null]';
17
+ }
18
+
19
+ export function isUndefined(val: dynamic): val is undefined {
20
+ return Object.prototype.toString.call(val) === '[object Undefined]';
21
+ }
22
+
23
+ export function isDefined<T>(val: T): val is NonNullable<T> {
24
+ return !isUndefined(val) && !isNull(val);
25
+ }
26
+
27
+ export function isNumber(val: dynamic): val is number {
28
+ // Note: NaN is also a number
29
+ return Object.prototype.toString.call(val) === '[object Number]';
30
+ }
31
+
32
+ export function isString(val: dynamic): val is string {
33
+ return Object.prototype.toString.call(val) === '[object String]';
34
+ }
35
+
36
+ export function isBoolean(val: dynamic): val is boolean {
37
+ return Object.prototype.toString.call(val) === '[object Boolean]';
38
+ }
39
+
40
+ export function isNaN(val: dynamic): val is number {
41
+ // eslint-disable-next-line no-self-compare
42
+ return val !== val;
43
+ }
44
+
45
+ export function isDate(val: dynamic): val is Date {
46
+ return Object.prototype.toString.call(val) === '[object Date]';
47
+ }
48
+
49
+ export function isFunction(val: dynamic): val is FunctionType {
50
+ return Object.prototype.toString.call(val) === '[object Function]';
51
+ }
52
+
53
+ export function isRegex(val: dynamic): val is RegExp {
54
+ return Object.prototype.toString.call(val) === '[object RegExp]';
55
+ }
56
+
57
+ export function isPromise(val: dynamic): val is Promise<dynamic> {
58
+ return Object.prototype.toString.call(val) === '[object Promise]';
59
+ }
60
+
61
+ export function getType(val: dynamic): string {
62
+ return isObject(val)
63
+ ? 'Object'
64
+ : isArray(val)
65
+ ? 'Array'
66
+ : isNull(val)
67
+ ? 'Null'
68
+ : isUndefined(val)
69
+ ? 'Undefined'
70
+ : isNaN(val)
71
+ ? 'NaN'
72
+ : isNumber(val)
73
+ ? 'Number'
74
+ : isString(val)
75
+ ? 'String'
76
+ : isBoolean(val)
77
+ ? 'Boolean'
78
+ : isDate(val)
79
+ ? 'Date'
80
+ : isRegex(val)
81
+ ? 'Regex'
82
+ : isFunction(val)
83
+ ? 'Function'
84
+ : isPromise(val)
85
+ ? 'Promise'
86
+ : 'Unknown Type';
87
+ }
@@ -0,0 +1,180 @@
1
+ import { SettingsModel } from './../models/SettingsModel';
2
+ import { LogManager } from '../modules/logger';
3
+ import { isObject } from '../utils/DataTypeUtil';
4
+ import { SegmentationManager } from '../modules/segmentor';
5
+ import { getUUID } from './UuidUtil';
6
+ import { isPromise } from 'util/types';
7
+ import { cloneObject } from './FunctionUtil';
8
+ import { scaleVariationWeights, assignRangeValues, getBucketingSeed } from './CampaignUtil';
9
+ import { DecisionMaker } from '../modules/decision-maker';
10
+ import { CampaignDecisionService } from '../services/CampaignDecisionService';
11
+ import { CampaignModel } from '../models/CampaignModel';
12
+ import { VariationModel } from '../models/VariationModel'; // Import the missing VariationModel type
13
+ import { CampaignTypeEnum } from '../enums/campaignTypeEnum';
14
+ import HooksManager from '../services/HooksManager';
15
+ import { StatusEnum } from '../enums/StatusEnum';
16
+ // import { CampaignTypeEnum } from '../enums/campaignTypeEnum';
17
+
18
+ export const checkWhitelistingAndPreSeg = async (
19
+ settings: any,
20
+ campaign: CampaignModel,
21
+ context: any,
22
+ isMegWinnerRule: Boolean,
23
+ decision: any,
24
+ ): Promise<[Boolean, any]> => {
25
+ let vwoUserId = getUUID(context.user.id, settings.accountId);
26
+
27
+ // only check whitelisting for ab campaigns
28
+ if (campaign.getType() === CampaignTypeEnum.AB) {
29
+ // set _vwoUserId for variation targeting variables
30
+ context.user.variationTargetingVariables = Object.assign({}, context.user.variationTargetingVariables, {
31
+ _vwoUserId: campaign.getIsUserListEnabled() ? vwoUserId : context.user.id,
32
+ });
33
+ Object.assign(decision, { variationTargetingVariables: context.user.variationTargetingVariables }); // for integration
34
+ // check if the campaign satisfies the whitelisting
35
+ if (campaign.getIsForcedVariationEnabled()) {
36
+ const whitelistedVariation = await checkForWhitelisting(campaign, campaign.getKey(), settings, context);
37
+ if (whitelistedVariation && Object.keys(whitelistedVariation).length > 0) {
38
+ return [true, whitelistedVariation];
39
+ }
40
+ } else {
41
+ LogManager.Instance.info(
42
+ `WHITELISTING_SKIPPED: Whitelisting is not used for Campaign:${campaign.getKey()}, hence skipping evaluating whitelisting for User ID:${context.user.id}`,
43
+ );
44
+ }
45
+ }
46
+
47
+ if (isMegWinnerRule) {
48
+ return [true, null]; // for MEG winner rule, no need to check for pre segmentation as it's already evaluated
49
+ }
50
+ // userlist segment is also available for campaign pre segmentation
51
+ context.user.customVariables = Object.assign({}, context.user.customVariables, {
52
+ _vwoUserId: campaign.getIsUserListEnabled() ? vwoUserId : context.user.id,
53
+ });
54
+ Object.assign(decision, { customVariables: context.user.customVariables }); // for integeration
55
+
56
+ // check for campaign pre segmentation
57
+ const preSegmentationResult = await new CampaignDecisionService().getDecision(campaign, settings, context);
58
+ return [preSegmentationResult, null];
59
+ };
60
+
61
+ /**
62
+ * Check for whitelisting
63
+ * @param campaign Campaign object
64
+ * @param campaignKey Campaign key
65
+ * @param userId User ID
66
+ * @param variationTargetingVariables Variation targeting variables
67
+ * @returns
68
+ */
69
+ const checkForWhitelisting = async (
70
+ campaign: any,
71
+ campaignKey: string,
72
+ settings: SettingsModel,
73
+ context: any,
74
+ ): Promise<any> => {
75
+ let status;
76
+ // check if the campaign satisfies the whitelisting
77
+ const whitelistingResult = await _evaluateWhitelisting(campaign, campaignKey, settings, context);
78
+ let variationString;
79
+ if (whitelistingResult) {
80
+ status = StatusEnum.PASSED;
81
+ variationString = whitelistingResult.variation.key;
82
+ } else {
83
+ status = StatusEnum.FAILED;
84
+ variationString = '';
85
+ }
86
+ LogManager.Instance.info(
87
+ `SEGMENTATION_STATUS: User ID:${context.user.id} for Campaign:${campaignKey} with variables:${JSON.stringify(context.user.variationTargetingVariables)} ${status} whitelisting ${variationString}`,
88
+ );
89
+ return whitelistingResult;
90
+ };
91
+
92
+ const _evaluateWhitelisting = async (
93
+ campaign: CampaignModel,
94
+ campaignKey: string,
95
+ settings: SettingsModel,
96
+ context: any,
97
+ ): Promise<any> => {
98
+ let whitelistedVariation;
99
+ let status;
100
+ const targetedVariations = [];
101
+ const promises: Promise<any>[] = [];
102
+ campaign.getVariations().forEach((variation) => {
103
+ if (isObject(variation.getSegments()) && !Object.keys(variation.getSegments()).length) {
104
+ LogManager.Instance.debug(
105
+ `SEGMENTATION_SKIPPED: Segmentation is not used for Campaign:${campaignKey}, hence skipping evaluating segmentation ${variation} for User ID:${context.user.id}`,
106
+ );
107
+ return;
108
+ }
109
+ // check for segmentation and evaluate
110
+ if (isObject(variation.getSegments())) {
111
+ const SegmentEvaluatorResult = SegmentationManager.Instance.validateSegmentation(
112
+ variation.getSegments(),
113
+ context.user.variationTargetingVariables,
114
+ settings,
115
+ );
116
+ const promise = isPromise(SegmentEvaluatorResult)
117
+ ? SegmentEvaluatorResult.then((evaluationResult) => {
118
+ if (evaluationResult) {
119
+ status = StatusEnum.PASSED;
120
+ targetedVariations.push(cloneObject(variation));
121
+ } else {
122
+ status = StatusEnum.FAILED;
123
+ }
124
+ })
125
+ : Promise.resolve(SegmentEvaluatorResult).then((evaluationResult) => {
126
+ if (evaluationResult) {
127
+ status = StatusEnum.PASSED;
128
+ targetedVariations.push(cloneObject(variation));
129
+ } else {
130
+ status = StatusEnum.FAILED;
131
+ }
132
+ });
133
+ promises.push(promise);
134
+ } else {
135
+ status = StatusEnum.FAILED;
136
+ }
137
+ });
138
+
139
+ // Wait for all promises to resolve
140
+ await Promise.all(promises);
141
+ if (targetedVariations.length > 1) {
142
+ scaleVariationWeights(targetedVariations);
143
+ for (let i = 0, currentAllocation = 0, stepFactor = 0; i < targetedVariations.length; i++) {
144
+ stepFactor = assignRangeValues(targetedVariations[i], currentAllocation);
145
+ currentAllocation += stepFactor;
146
+ }
147
+ whitelistedVariation = new CampaignDecisionService().getVariation(
148
+ targetedVariations,
149
+ new DecisionMaker().calculateBucketValue(getBucketingSeed(context.user.id, campaign, null)),
150
+ );
151
+ } else {
152
+ whitelistedVariation = targetedVariations[0];
153
+ }
154
+
155
+ if (whitelistedVariation) {
156
+ return {
157
+ variation: whitelistedVariation,
158
+ variationName: whitelistedVariation.name,
159
+ variationId: whitelistedVariation.id,
160
+ };
161
+ }
162
+ };
163
+
164
+ export const evaluateTrafficAndGetVariation = (
165
+ settingsFile: any,
166
+ campaign: CampaignModel,
167
+ userId: any,
168
+ ): VariationModel => {
169
+ const variation = new CampaignDecisionService().getVariationAlloted(userId, settingsFile.accountId, campaign);
170
+ if (!variation) {
171
+ LogManager.Instance.debug(
172
+ `USER_NOT_BUCKETED: User ID:${userId} for Campaign:${campaign.getKey()} did not get any variation`,
173
+ );
174
+ return null;
175
+ }
176
+ LogManager.Instance.debug(
177
+ `USER_BUCKETED: User ID:${userId} for Campaign:${campaign.getKey()} ${variation.getKey() ? `got variation:${variation.getKey()}` : 'did not get any variation'}`,
178
+ );
179
+ return variation;
180
+ };
@@ -0,0 +1,105 @@
1
+ import { CampaignTypeEnum } from '../enums/campaignTypeEnum';
2
+ import { SettingsModel } from '../models/SettingsModel';
3
+ import { dynamic } from '../types/common';
4
+ import { isString } from './DataTypeUtil';
5
+
6
+ export function cloneObject(obj: dynamic): any {
7
+ if (!obj) {
8
+ return obj;
9
+ }
10
+ const clonedObj = JSON.parse(JSON.stringify(obj));
11
+ return clonedObj;
12
+ }
13
+
14
+ export function getCurrentUnixTimestamp(): number {
15
+ return Math.ceil(+new Date() / 1000);
16
+ }
17
+
18
+ export function getCurrentUnixTimestampInMillis(): number {
19
+ return +new Date();
20
+ }
21
+
22
+ export function getRandomNumber(): number {
23
+ return Math.random();
24
+ }
25
+
26
+ export function getSpecificRulesBasedOnType(settings, featureKey, type = null) {
27
+ let feature = getFeatureFromKey(settings, featureKey);
28
+ if (feature && !feature.rulesLinkedCampaign) {
29
+ return [];
30
+ }
31
+
32
+ if (feature && feature.rulesLinkedCampaign && type && isString(type)) {
33
+ return feature.rulesLinkedCampaign.filter((rule) => rule.type === type);
34
+ }
35
+
36
+ return feature.rulesLinkedCampaign;
37
+ }
38
+
39
+ export function getAllAbAndPersonaliseRules(settings, featureKey) {
40
+ let feature = getFeatureFromKey(settings, featureKey);
41
+ return feature.rulesLinkedCampaign.filter(
42
+ (rule) => rule.type === CampaignTypeEnum.AB || rule.type === CampaignTypeEnum.PERSONALIZE,
43
+ );
44
+ }
45
+
46
+ export function getFeatureFromKey(settings, featureKey) {
47
+ return settings?.features?.find((feature) => feature.key === featureKey);
48
+ }
49
+
50
+ export function eventExists(eventName: string, settings: any): boolean {
51
+ for (const feature of settings.features) {
52
+ for (const metric of feature.metrics) {
53
+ if (metric.identifier === eventName) {
54
+ return true;
55
+ }
56
+ }
57
+ }
58
+ return false;
59
+ }
60
+
61
+ export function addLInkedCampaignsToSettings(settingsFile: any): void {
62
+ // loop over all features
63
+ for (const feature of settingsFile.features) {
64
+ const { rules } = feature;
65
+ const campaigns = settingsFile.campaigns;
66
+ const rulesLinkedCampaign = [];
67
+
68
+ // loop over all rules of a feature
69
+ for (const rule of rules) {
70
+ const { campaignId, variationId } = rule;
71
+ if (campaignId) {
72
+ // find the campaign with the given campaignId
73
+ const campaign = campaigns.find((c) => c.id === campaignId);
74
+ if (campaign) {
75
+ // create a linked campaign object with the rule and campaign
76
+ const linkedCampaign = { key: campaign.key, ...rule, ...campaign };
77
+
78
+ if (variationId) {
79
+ // find the variation with the given variationId
80
+ const variation = campaign.variations.find((v) => v.id === variationId);
81
+ if (variation) {
82
+ // add the variation to the linked campaign
83
+ linkedCampaign.variations = [variation];
84
+ }
85
+ }
86
+ // add the linked campaign to the rulesLinkedCampaign array
87
+ rulesLinkedCampaign.push(linkedCampaign);
88
+ }
89
+ }
90
+ }
91
+ feature.rulesLinkedCampaign = rulesLinkedCampaign;
92
+ }
93
+ }
94
+
95
+ // get feature name from feature key using settings
96
+ export function getFeatureNameFromKey(settings: SettingsModel, featureKey: string): string {
97
+ const feature = settings.getFeatures().find((f) => f.getKey() === featureKey);
98
+ return feature ? feature.getName() : '';
99
+ }
100
+
101
+ // get feature id from feature key using settings
102
+ export function getFeatureIdFromKey(settings: SettingsModel, featureKey: string): number {
103
+ const feature = settings.getFeatures().find((f) => f.getKey() === featureKey);
104
+ return feature ? feature.getId() : null;
105
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Copyright 2019-2020 Wingify Software Pvt. Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { isNull, isUndefined, isFunction } from '../utils/DataTypeUtil';
18
+
19
+ const nargs = /\{([0-9a-zA-Z_]+)\}/g;
20
+
21
+ export function buildMessage(template: string, data: Record<string, any>): string {
22
+ try {
23
+ return template.replace(nargs, (match, key, index) => {
24
+ let result;
25
+ let isKey;
26
+
27
+ if (template[index - 1] === '{' && template[index + match.length] === '}') {
28
+ return key;
29
+ } else {
30
+ isKey = Object.prototype.hasOwnProperty.call(data, key);
31
+
32
+ if (isKey) {
33
+ let value = data[key];
34
+
35
+ if (isFunction(value)) {
36
+ value = data[key]();
37
+ }
38
+ result = value;
39
+ } else {
40
+ result = null;
41
+ }
42
+ if (isNull(result) || isUndefined(result)) {
43
+ return '';
44
+ }
45
+
46
+ return result;
47
+ }
48
+ });
49
+ } catch (err) {
50
+ return template;
51
+ }
52
+ }