@ductape/sdk 0.0.4-v5 → 0.0.4-v51

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 (338) hide show
  1. package/README.md +1 -1
  2. package/dist/api/services/appApi.service.d.ts +48 -2
  3. package/dist/api/services/appApi.service.js +101 -2
  4. package/dist/api/services/appApi.service.js.map +1 -1
  5. package/dist/api/services/pricingApi.service.d.ts +10 -0
  6. package/dist/api/services/pricingApi.service.js +34 -0
  7. package/dist/api/services/pricingApi.service.js.map +1 -0
  8. package/dist/api/services/processorApi.service.d.ts +12 -2
  9. package/dist/api/services/processorApi.service.js +12 -2
  10. package/dist/api/services/processorApi.service.js.map +1 -1
  11. package/dist/api/services/productsApi.service.d.ts +40 -1
  12. package/dist/api/services/productsApi.service.js +105 -1
  13. package/dist/api/services/productsApi.service.js.map +1 -1
  14. package/dist/api/services/userApi.service.js +1 -0
  15. package/dist/api/services/userApi.service.js.map +1 -1
  16. package/dist/api/services/workspaceApi.service.js +1 -0
  17. package/dist/api/services/workspaceApi.service.js.map +1 -1
  18. package/dist/api/services/workspaceSecretsApi.service.d.ts +75 -0
  19. package/dist/api/services/workspaceSecretsApi.service.js +62 -0
  20. package/dist/api/services/workspaceSecretsApi.service.js.map +1 -0
  21. package/dist/api/urls.d.ts +6 -1
  22. package/dist/api/urls.js +12 -2
  23. package/dist/api/urls.js.map +1 -1
  24. package/dist/api/utils/cache.utils.d.ts +1 -1
  25. package/dist/api/utils/cache.utils.js +10 -4
  26. package/dist/api/utils/cache.utils.js.map +1 -1
  27. package/dist/api/utils/strings.utils.d.ts +2 -0
  28. package/dist/api/utils/strings.utils.js +14 -0
  29. package/dist/api/utils/strings.utils.js.map +1 -1
  30. package/dist/apps/services/app.service.d.ts +51 -33
  31. package/dist/apps/services/app.service.js +488 -244
  32. package/dist/apps/services/app.service.js.map +1 -1
  33. package/dist/apps/validators/joi-validators/create.appAction.validator.d.ts +1 -2
  34. package/dist/apps/validators/joi-validators/create.appAction.validator.js +21 -2
  35. package/dist/apps/validators/joi-validators/create.appAction.validator.js.map +1 -1
  36. package/dist/apps/validators/joi-validators/create.appWebhook.validator.d.ts +1 -2
  37. package/dist/apps/validators/joi-validators/create.appWebhook.validator.js +2 -15
  38. package/dist/apps/validators/joi-validators/create.appWebhook.validator.js.map +1 -1
  39. package/dist/apps/validators/joi-validators/update.appAction.validator.js +11 -1
  40. package/dist/apps/validators/joi-validators/update.appAction.validator.js.map +1 -1
  41. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.d.ts +1 -1
  42. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js +34 -1
  43. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js.map +1 -1
  44. package/dist/apps/validators/joi-validators/update.appWebhook.validator.d.ts +1 -2
  45. package/dist/apps/validators/joi-validators/update.appWebhook.validator.js +2 -14
  46. package/dist/apps/validators/joi-validators/update.appWebhook.validator.js.map +1 -1
  47. package/dist/clients/pricing.client.d.ts +3 -0
  48. package/dist/clients/pricing.client.js +33 -0
  49. package/dist/clients/pricing.client.js.map +1 -0
  50. package/dist/database/adapters/base.adapter.d.ts +176 -0
  51. package/dist/database/adapters/base.adapter.js +31 -0
  52. package/dist/database/adapters/base.adapter.js.map +1 -0
  53. package/dist/database/adapters/dynamodb.adapter.d.ts +91 -0
  54. package/dist/database/adapters/dynamodb.adapter.js +1608 -0
  55. package/dist/database/adapters/dynamodb.adapter.js.map +1 -0
  56. package/dist/database/adapters/mongodb.adapter.d.ts +71 -0
  57. package/dist/database/adapters/mongodb.adapter.js +1072 -0
  58. package/dist/database/adapters/mongodb.adapter.js.map +1 -0
  59. package/dist/database/adapters/mysql.adapter.d.ts +146 -0
  60. package/dist/database/adapters/mysql.adapter.js +1492 -0
  61. package/dist/database/adapters/mysql.adapter.js.map +1 -0
  62. package/dist/database/adapters/postgresql.adapter.d.ts +147 -0
  63. package/dist/database/adapters/postgresql.adapter.js +1603 -0
  64. package/dist/database/adapters/postgresql.adapter.js.map +1 -0
  65. package/dist/database/database.service.d.ts +232 -0
  66. package/dist/database/database.service.js +802 -0
  67. package/dist/database/database.service.js.map +1 -0
  68. package/dist/database/index.d.ts +18 -0
  69. package/dist/database/index.js +98 -0
  70. package/dist/database/index.js.map +1 -0
  71. package/dist/database/types/aggregation.types.d.ts +261 -0
  72. package/dist/database/types/aggregation.types.js +21 -0
  73. package/dist/database/types/aggregation.types.js.map +1 -0
  74. package/dist/database/types/connection.types.d.ts +132 -0
  75. package/dist/database/types/connection.types.js +6 -0
  76. package/dist/database/types/connection.types.js.map +1 -0
  77. package/dist/database/types/database.types.d.ts +175 -0
  78. package/dist/database/types/database.types.js +75 -0
  79. package/dist/database/types/database.types.js.map +1 -0
  80. package/dist/database/types/index.d.ts +12 -0
  81. package/dist/database/types/index.js +37 -0
  82. package/dist/database/types/index.js.map +1 -0
  83. package/dist/database/types/index.types.d.ts +220 -0
  84. package/dist/database/types/index.types.js +27 -0
  85. package/dist/database/types/index.types.js.map +1 -0
  86. package/dist/database/types/migration.types.d.ts +205 -0
  87. package/dist/database/types/migration.types.js +44 -0
  88. package/dist/database/types/migration.types.js.map +1 -0
  89. package/dist/database/types/query.types.d.ts +305 -0
  90. package/dist/database/types/query.types.js +57 -0
  91. package/dist/database/types/query.types.js.map +1 -0
  92. package/dist/database/types/result.types.d.ts +220 -0
  93. package/dist/database/types/result.types.js +6 -0
  94. package/dist/database/types/result.types.js.map +1 -0
  95. package/dist/database/types/schema.types.d.ts +190 -0
  96. package/dist/database/types/schema.types.js +69 -0
  97. package/dist/database/types/schema.types.js.map +1 -0
  98. package/dist/database/utils/helpers.d.ts +66 -0
  99. package/dist/database/utils/helpers.js +501 -0
  100. package/dist/database/utils/helpers.js.map +1 -0
  101. package/dist/database/utils/migration.utils.d.ts +151 -0
  102. package/dist/database/utils/migration.utils.js +476 -0
  103. package/dist/database/utils/migration.utils.js.map +1 -0
  104. package/dist/database/utils/transaction.d.ts +64 -0
  105. package/dist/database/utils/transaction.js +130 -0
  106. package/dist/database/utils/transaction.js.map +1 -0
  107. package/dist/database/validators/connection.validator.d.ts +20 -0
  108. package/dist/database/validators/connection.validator.js +267 -0
  109. package/dist/database/validators/connection.validator.js.map +1 -0
  110. package/dist/database/validators/query.validator.d.ts +31 -0
  111. package/dist/database/validators/query.validator.js +305 -0
  112. package/dist/database/validators/query.validator.js.map +1 -0
  113. package/dist/database/validators/schema.validator.d.ts +31 -0
  114. package/dist/database/validators/schema.validator.js +334 -0
  115. package/dist/database/validators/schema.validator.js.map +1 -0
  116. package/dist/graph/adapters/arangodb.adapter.d.ts +80 -0
  117. package/dist/graph/adapters/arangodb.adapter.js +1393 -0
  118. package/dist/graph/adapters/arangodb.adapter.js.map +1 -0
  119. package/dist/graph/adapters/base.adapter.d.ts +228 -0
  120. package/dist/graph/adapters/base.adapter.js +38 -0
  121. package/dist/graph/adapters/base.adapter.js.map +1 -0
  122. package/dist/graph/adapters/index.d.ts +10 -0
  123. package/dist/graph/adapters/index.js +23 -0
  124. package/dist/graph/adapters/index.js.map +1 -0
  125. package/dist/graph/adapters/memgraph.adapter.d.ts +85 -0
  126. package/dist/graph/adapters/memgraph.adapter.js +1491 -0
  127. package/dist/graph/adapters/memgraph.adapter.js.map +1 -0
  128. package/dist/graph/adapters/neo4j.adapter.d.ts +88 -0
  129. package/dist/graph/adapters/neo4j.adapter.js +1861 -0
  130. package/dist/graph/adapters/neo4j.adapter.js.map +1 -0
  131. package/dist/graph/adapters/neptune.adapter.d.ts +87 -0
  132. package/dist/graph/adapters/neptune.adapter.js +1430 -0
  133. package/dist/graph/adapters/neptune.adapter.js.map +1 -0
  134. package/dist/graph/graph.service.d.ts +278 -0
  135. package/dist/graph/graph.service.js +687 -0
  136. package/dist/graph/graph.service.js.map +1 -0
  137. package/dist/graph/index.d.ts +11 -0
  138. package/dist/graph/index.js +42 -0
  139. package/dist/graph/index.js.map +1 -0
  140. package/dist/graph/types/connection.types.d.ts +158 -0
  141. package/dist/graph/types/connection.types.js +43 -0
  142. package/dist/graph/types/connection.types.js.map +1 -0
  143. package/dist/graph/types/graph.types.d.ts +144 -0
  144. package/dist/graph/types/graph.types.js +84 -0
  145. package/dist/graph/types/graph.types.js.map +1 -0
  146. package/dist/graph/types/index.d.ts +11 -0
  147. package/dist/graph/types/index.js +35 -0
  148. package/dist/graph/types/index.js.map +1 -0
  149. package/dist/graph/types/node.types.d.ts +193 -0
  150. package/dist/graph/types/node.types.js +49 -0
  151. package/dist/graph/types/node.types.js.map +1 -0
  152. package/dist/graph/types/path.types.d.ts +224 -0
  153. package/dist/graph/types/path.types.js +38 -0
  154. package/dist/graph/types/path.types.js.map +1 -0
  155. package/dist/graph/types/query.types.d.ts +247 -0
  156. package/dist/graph/types/query.types.js +23 -0
  157. package/dist/graph/types/query.types.js.map +1 -0
  158. package/dist/graph/types/relationship.types.d.ts +224 -0
  159. package/dist/graph/types/relationship.types.js +35 -0
  160. package/dist/graph/types/relationship.types.js.map +1 -0
  161. package/dist/graph/types/result.types.d.ts +237 -0
  162. package/dist/graph/types/result.types.js +7 -0
  163. package/dist/graph/types/result.types.js.map +1 -0
  164. package/dist/graph/validators/index.d.ts +81 -0
  165. package/dist/graph/validators/index.js +243 -0
  166. package/dist/graph/validators/index.js.map +1 -0
  167. package/dist/imports/imports.service.d.ts +3 -3
  168. package/dist/imports/imports.service.js +7 -7
  169. package/dist/imports/imports.service.js.map +1 -1
  170. package/dist/imports/imports.types.d.ts +8 -0
  171. package/dist/imports/repos/postmanV21.repo.d.ts +1 -1
  172. package/dist/imports/repos/postmanV21.repo.js +29 -2
  173. package/dist/imports/repos/postmanV21.repo.js.map +1 -1
  174. package/dist/index.d.ts +1244 -150
  175. package/dist/index.js +1309 -209
  176. package/dist/index.js.map +1 -1
  177. package/dist/inputs/inputs.service.js +2 -2
  178. package/dist/inputs/inputs.service.js.map +1 -1
  179. package/dist/inputs/utils/inputs.utils.create.js +1 -1
  180. package/dist/inputs/utils/inputs.utils.create.js.map +1 -1
  181. package/dist/logs/logs.types.d.ts +5 -0
  182. package/dist/logs/logs.types.js +1 -0
  183. package/dist/logs/logs.types.js.map +1 -1
  184. package/dist/parsers/index.d.ts +3 -0
  185. package/dist/parsers/index.js +27 -0
  186. package/dist/parsers/index.js.map +1 -0
  187. package/dist/parsers/pipelines/postman.pipelines.d.ts +15 -0
  188. package/dist/parsers/pipelines/postman.pipelines.js +103 -0
  189. package/dist/parsers/pipelines/postman.pipelines.js.map +1 -0
  190. package/dist/parsers/types/postman.types.d.ts +200 -0
  191. package/dist/parsers/types/postman.types.js +3 -0
  192. package/dist/parsers/types/postman.types.js.map +1 -0
  193. package/dist/parsers/utils/postman.utils.d.ts +12 -0
  194. package/dist/parsers/utils/postman.utils.js +116 -0
  195. package/dist/parsers/utils/postman.utils.js.map +1 -0
  196. package/dist/parsers/validators/postman-auth.validators.d.ts +10 -0
  197. package/dist/parsers/validators/postman-auth.validators.js +127 -0
  198. package/dist/parsers/validators/postman-auth.validators.js.map +1 -0
  199. package/dist/parsers/validators/postman-request.validators.d.ts +13 -0
  200. package/dist/parsers/validators/postman-request.validators.js +139 -0
  201. package/dist/parsers/validators/postman-request.validators.js.map +1 -0
  202. package/dist/parsers/validators/postman-response.validators.d.ts +13 -0
  203. package/dist/parsers/validators/postman-response.validators.js +150 -0
  204. package/dist/parsers/validators/postman-response.validators.js.map +1 -0
  205. package/dist/parsers/validators/postman-variable.validators.d.ts +14 -0
  206. package/dist/parsers/validators/postman-variable.validators.js +163 -0
  207. package/dist/parsers/validators/postman-variable.validators.js.map +1 -0
  208. package/dist/pricing/pricing.repo.d.ts +0 -0
  209. package/dist/pricing/pricing.repo.js +1 -0
  210. package/dist/pricing/pricing.repo.js.map +1 -0
  211. package/dist/pricing/pricing.service.d.ts +24 -0
  212. package/dist/pricing/pricing.service.js +51 -0
  213. package/dist/pricing/pricing.service.js.map +1 -0
  214. package/dist/pricing/pricing.types.d.ts +76 -0
  215. package/dist/pricing/pricing.types.js +21 -0
  216. package/dist/pricing/pricing.types.js.map +1 -0
  217. package/dist/pricing/utils/string.utils.d.ts +1 -0
  218. package/dist/pricing/utils/string.utils.js +9 -0
  219. package/dist/pricing/utils/string.utils.js.map +1 -0
  220. package/dist/processor/repos/sms.repo.d.ts +4 -4
  221. package/dist/processor/repos/sms.repo.js +23 -10
  222. package/dist/processor/repos/sms.repo.js.map +1 -1
  223. package/dist/processor/services/messagebrokers/kafka.service.js +0 -2
  224. package/dist/processor/services/messagebrokers/kafka.service.js.map +1 -1
  225. package/dist/processor/services/messagebrokers/rabbitmq.service.d.ts +9 -1
  226. package/dist/processor/services/messagebrokers/rabbitmq.service.js +40 -11
  227. package/dist/processor/services/messagebrokers/rabbitmq.service.js.map +1 -1
  228. package/dist/processor/services/processor.service.d.ts +38 -10
  229. package/dist/processor/services/processor.service.js +533 -248
  230. package/dist/processor/services/processor.service.js.map +1 -1
  231. package/dist/processor/services/request.service.d.ts +36 -0
  232. package/dist/processor/services/request.service.js +304 -0
  233. package/dist/processor/services/request.service.js.map +1 -0
  234. package/dist/processor/types/request.types.d.ts +14 -0
  235. package/dist/processor/types/request.types.js +3 -0
  236. package/dist/processor/types/request.types.js.map +1 -0
  237. package/dist/processor/utils/processor.utils.d.ts +3 -0
  238. package/dist/processor/utils/processor.utils.js +84 -22
  239. package/dist/processor/utils/processor.utils.js.map +1 -1
  240. package/dist/processor/utils/request.utils.d.ts +20 -0
  241. package/dist/processor/utils/request.utils.js +113 -0
  242. package/dist/processor/utils/request.utils.js.map +1 -0
  243. package/dist/products/services/products.service.d.ts +114 -77
  244. package/dist/products/services/products.service.js +805 -362
  245. package/dist/products/services/products.service.js.map +1 -1
  246. package/dist/products/services/utils/crypt.utils.d.ts +1 -0
  247. package/dist/products/services/utils/crypt.utils.js +17 -0
  248. package/dist/products/services/utils/crypt.utils.js.map +1 -0
  249. package/dist/products/services/utils/functions.utils.d.ts +13 -0
  250. package/dist/products/services/utils/functions.utils.js +289 -0
  251. package/dist/products/services/utils/functions.utils.js.map +1 -0
  252. package/dist/products/services/utils/objects.utils.d.ts +13 -0
  253. package/dist/products/services/utils/objects.utils.js +89 -0
  254. package/dist/products/services/utils/objects.utils.js.map +1 -0
  255. package/dist/products/services/utils/string.utils.d.ts +12 -0
  256. package/dist/products/services/utils/string.utils.js +168 -0
  257. package/dist/products/services/utils/string.utils.js.map +1 -0
  258. package/dist/products/utils/string.utils.d.ts +1 -1
  259. package/dist/products/utils/string.utils.js +14 -2
  260. package/dist/products/utils/string.utils.js.map +1 -1
  261. package/dist/products/validators/index.d.ts +4 -1
  262. package/dist/products/validators/index.js +7 -1
  263. package/dist/products/validators/index.js.map +1 -1
  264. package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.d.ts +15 -4
  265. package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js +501 -109
  266. package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js.map +1 -1
  267. package/dist/products/validators/joi-validators/create.productEnv.validator.js +1 -0
  268. package/dist/products/validators/joi-validators/create.productEnv.validator.js.map +1 -1
  269. package/dist/products/validators/joi-validators/create.productGraph.validator.d.ts +3 -0
  270. package/dist/products/validators/joi-validators/create.productGraph.validator.js +82 -0
  271. package/dist/products/validators/joi-validators/create.productGraph.validator.js.map +1 -0
  272. package/dist/products/validators/joi-validators/create.productGraphAction.validator.d.ts +14 -0
  273. package/dist/products/validators/joi-validators/create.productGraphAction.validator.js +696 -0
  274. package/dist/products/validators/joi-validators/create.productGraphAction.validator.js.map +1 -0
  275. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.d.ts +4 -0
  276. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js +58 -0
  277. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js.map +1 -0
  278. package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js +1 -0
  279. package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js.map +1 -1
  280. package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js +9 -4
  281. package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js.map +1 -1
  282. package/dist/products/validators/joi-validators/create.productNotification.validator.js +5 -2
  283. package/dist/products/validators/joi-validators/create.productNotification.validator.js.map +1 -1
  284. package/dist/products/validators/joi-validators/create.userAuth.validator.js +1 -0
  285. package/dist/products/validators/joi-validators/create.userAuth.validator.js.map +1 -1
  286. package/dist/products/validators/joi-validators/update.dataValue.validator.js +1 -0
  287. package/dist/products/validators/joi-validators/update.dataValue.validator.js.map +1 -1
  288. package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.d.ts +6 -0
  289. package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.js +28 -26
  290. package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.js.map +1 -1
  291. package/dist/products/validators/joi-validators/update.productEnv.validator.js +3 -0
  292. package/dist/products/validators/joi-validators/update.productEnv.validator.js.map +1 -1
  293. package/dist/products/validators/joi-validators/update.productGraph.validator.d.ts +3 -0
  294. package/dist/products/validators/joi-validators/update.productGraph.validator.js +87 -0
  295. package/dist/products/validators/joi-validators/update.productGraph.validator.js.map +1 -0
  296. package/dist/products/validators/joi-validators/update.productGraphAction.validator.d.ts +7 -0
  297. package/dist/products/validators/joi-validators/update.productGraphAction.validator.js +72 -0
  298. package/dist/products/validators/joi-validators/update.productGraphAction.validator.js.map +1 -0
  299. package/dist/products/validators/joi-validators/update.productMessageBrokerTopic.validator.js +1 -0
  300. package/dist/products/validators/joi-validators/update.productMessageBrokerTopic.validator.js.map +1 -1
  301. package/dist/products/validators/joi-validators/update.userAuth.validator.js +1 -0
  302. package/dist/products/validators/joi-validators/update.userAuth.validator.js.map +1 -1
  303. package/dist/test/test.health.d.ts +1 -0
  304. package/dist/test/test.health.js +49 -0
  305. package/dist/test/test.health.js.map +1 -0
  306. package/dist/test/test.import.js +51 -4
  307. package/dist/test/test.import.js.map +1 -1
  308. package/dist/test/test.imports.js +22 -7
  309. package/dist/test/test.imports.js.map +1 -1
  310. package/dist/test/test.notifiers.d.ts +1 -0
  311. package/dist/test/test.notifiers.js +85 -0
  312. package/dist/test/test.notifiers.js.map +1 -0
  313. package/dist/test/test.processor.js +30 -115
  314. package/dist/test/test.processor.js.map +1 -1
  315. package/dist/test/test.products.d.ts +1 -0
  316. package/dist/test/test.products.js +49 -0
  317. package/dist/test/test.products.js.map +1 -0
  318. package/dist/tsconfig.tsbuildinfo +1 -0
  319. package/dist/types/appBuilder.types.d.ts +5 -12
  320. package/dist/types/enums.d.ts +4 -1
  321. package/dist/types/enums.js +3 -0
  322. package/dist/types/enums.js.map +1 -1
  323. package/dist/types/index.types.d.ts +4 -0
  324. package/dist/types/pricing.types.d.ts +4 -0
  325. package/dist/types/pricing.types.js +3 -0
  326. package/dist/types/pricing.types.js.map +1 -0
  327. package/dist/types/processor.types.d.ts +67 -11
  328. package/dist/types/processor.types.js.map +1 -1
  329. package/dist/types/productsBuilder.types.d.ts +132 -14
  330. package/dist/types/productsBuilder.types.js +69 -4
  331. package/dist/types/productsBuilder.types.js.map +1 -1
  332. package/dist/types/request-tracker.interface.d.ts +0 -0
  333. package/dist/types/request-tracker.interface.js +1 -0
  334. package/dist/types/request-tracker.interface.js.map +1 -0
  335. package/dist/utils/constants.d.ts +1 -0
  336. package/dist/utils/constants.js +5 -0
  337. package/dist/utils/constants.js.map +1 -0
  338. package/package.json +17 -3
@@ -56,12 +56,10 @@ const axios_1 = __importDefault(require("axios"));
56
56
  const processorApi_service_1 = require("../../api/services/processorApi.service");
57
57
  const expo_client_1 = __importDefault(require("../../clients/expo.client"));
58
58
  const handlebars_1 = require("handlebars");
59
- const functions_utils_1 = require("../../products/utils/functions.utils");
60
- const string_utils_1 = require("../../products/utils/string.utils");
59
+ const functions_utils_1 = require("../../products/services/utils/functions.utils");
60
+ const string_utils_1 = require("../../products/services/utils/string.utils");
61
61
  const create_productFeature_validator_1 = require("../../products/validators/joi-validators/create.productFeature.validator");
62
- const validators_1 = require("../../products/validators");
63
62
  const uuid_1 = require("uuid");
64
- const urls_1 = require("../../api/urls");
65
63
  //import { createBrokerService } from './messagebrokers';
66
64
  const date_fns_1 = require("date-fns");
67
65
  const mongo_repo_1 = require("../repos/mongo.repo");
@@ -69,6 +67,9 @@ const postgres_repo_1 = require("../repos/postgres.repo");
69
67
  const storage_util_1 = require("../utils/storage.util");
70
68
  const sms_repo_1 = require("../repos/sms.repo");
71
69
  const quota_service_1 = __importDefault(require("./quota.service"));
70
+ const pricing_service_1 = __importDefault(require("../../pricing/pricing.service"));
71
+ const request_utils_1 = require("../utils/request.utils");
72
+ const request_service_1 = __importDefault(require("./request.service"));
72
73
  async function loadBrokerService() {
73
74
  if (typeof window === 'undefined') {
74
75
  const { createBrokerService } = await Promise.resolve().then(() => __importStar(require('./messagebrokers')));
@@ -77,14 +78,14 @@ async function loadBrokerService() {
77
78
  return null;
78
79
  }
79
80
  async function loadJWT() {
80
- if (typeof window === undefined) {
81
+ if (typeof window === 'undefined') {
81
82
  const JWT = await Promise.resolve().then(() => __importStar(require("jsonwebtoken")));
82
83
  return JWT;
83
84
  }
84
85
  return null;
85
86
  }
86
87
  class ProcessorService {
87
- constructor({ workspace_id, public_key, user_id, token, env_type, redis_client }) {
88
+ constructor({ workspace_id, public_key, user_id, token, env_type, redis_client, queues }) {
88
89
  this.workspace_id = workspace_id;
89
90
  this.public_key = public_key;
90
91
  this.user_id = user_id;
@@ -98,6 +99,14 @@ class ProcessorService {
98
99
  env_type,
99
100
  redis_client
100
101
  });
102
+ this.pricingService = new pricing_service_1.default({
103
+ workspace_id,
104
+ public_key,
105
+ user_id,
106
+ token,
107
+ env_type,
108
+ redis_client,
109
+ });
101
110
  this.inputService = new inputs_service_1.default();
102
111
  this.requestTime = 0;
103
112
  this.totalRequests = 0;
@@ -108,10 +117,89 @@ class ProcessorService {
108
117
  skipped: [],
109
118
  };
110
119
  this.apps = [];
120
+ this.requestTrackerService = request_service_1.default.getInstance(redis_client);
111
121
  this.processorApiService = new processorApi_service_1.ProcessorApiService(env_type);
112
122
  this.environment = env_type;
113
- if (redis_client) {
123
+ if (redis_client && this.productTag) {
114
124
  this.redisClient = redis_client;
125
+ // Start healthcheck workers automatically
126
+ this.startHealthcheckWorkers();
127
+ }
128
+ if (queues) {
129
+ this.queues = queues;
130
+ }
131
+ }
132
+ /**
133
+ * Start healthcheck workers for all products/environments after Redis is connected.
134
+ * This is called automatically in the constructor if redisClient is present.
135
+ */
136
+ async startHealthcheckWorkers() {
137
+ // Fetch all products (or the current product if context is single-tenant)
138
+ // For demo, we use the current product only
139
+ await this.productBuilderService.initializeProductByTag(this.productTag);
140
+ const healthchecks = await this.productBuilderService.fetchProductHealthchecks();
141
+ const privateKey = this.productBuilderService.fetchPrivateKey();
142
+ for (const healthcheck of healthchecks) {
143
+ for (const env of healthcheck.envs) {
144
+ // Each env gets its own worker (setInterval)
145
+ const interval = healthcheck.interval || 60000; // default 60s
146
+ setInterval(async () => {
147
+ try {
148
+ // Decrypt input for this env
149
+ let decryptedInput = env.input;
150
+ if (typeof decryptedInput === 'string') {
151
+ decryptedInput = JSON.parse((0, processor_utils_1.decrypt)(decryptedInput, privateKey));
152
+ }
153
+ // Prepare action input
154
+ const actionInput = {
155
+ env: env.slug,
156
+ product: this.productTag,
157
+ app: healthcheck.app,
158
+ input: decryptedInput,
159
+ event: healthcheck.event,
160
+ retries: healthcheck.retries || 0,
161
+ };
162
+ // Process the action
163
+ const result = await this.processAction(actionInput);
164
+ // Log result (success/failure)
165
+ this.logService.add(Object.assign(Object.assign({}, this.baseLogs), { message: `Healthcheck processed for ${healthcheck.tag} in env ${env.slug}`, data: { result }, status: types_1.LogEventStatus.SUCCESS }));
166
+ }
167
+ catch (e) {
168
+ this.logService.add(Object.assign(Object.assign({}, this.baseLogs), { message: `Healthcheck failed for ${healthcheck.tag} in env ${env.slug}`, data: { error: e.toString() }, status: types_1.LogEventStatus.FAIL }));
169
+ }
170
+ }, interval);
171
+ }
172
+ }
173
+ }
174
+ /**
175
+ * Manually trigger healthcheck processing for all healthchecks (can be called externally if needed)
176
+ */
177
+ async processAllHealthchecksForProduct(productTag) {
178
+ await this.productBuilderService.initializeProductByTag(productTag);
179
+ const healthchecks = await this.productBuilderService.fetchProductHealthchecks();
180
+ const privateKey = this.productBuilderService.fetchPrivateKey();
181
+ for (const healthcheck of healthchecks) {
182
+ for (const env of healthcheck.envs) {
183
+ try {
184
+ let decryptedInput = env.input;
185
+ if (typeof decryptedInput === 'string') {
186
+ decryptedInput = JSON.parse((0, processor_utils_1.decrypt)(decryptedInput, privateKey));
187
+ }
188
+ const actionInput = {
189
+ env: env.slug,
190
+ product: productTag,
191
+ app: healthcheck.app,
192
+ input: decryptedInput,
193
+ event: healthcheck.event,
194
+ retries: healthcheck.retries || 0,
195
+ };
196
+ const result = await this.processAction(actionInput);
197
+ this.logService.add(Object.assign(Object.assign({}, this.baseLogs), { message: `Manual healthcheck processed for ${healthcheck.tag} in env ${env.slug}`, data: { result }, status: types_1.LogEventStatus.SUCCESS }));
198
+ }
199
+ catch (e) {
200
+ this.logService.add(Object.assign(Object.assign({}, this.baseLogs), { message: `Manual healthcheck failed for ${healthcheck.tag} in env ${env.slug}`, data: { error: e.toString() }, status: types_1.LogEventStatus.FAIL }));
201
+ }
202
+ }
115
203
  }
116
204
  }
117
205
  async generateSession(payload) {
@@ -122,23 +210,37 @@ class ProcessorService {
122
210
  expected: types_1.ExpectedValues.PARSEINPUT,
123
211
  });
124
212
  await this.productBuilderService.initializeProductByTag(product_tag);
125
- // const product = this.productBuilderService.fetchProduct();
126
- const session = this.productBuilderService.fetchSession(tag);
213
+ const privateKey = this.productBuilderService.fetchPrivateKey();
214
+ const session = await this.productBuilderService.fetchSession(tag);
127
215
  if (!session) {
128
216
  throw new Error(`Session with tag ${tag} does not exist`);
129
217
  }
130
- const env = this.productBuilderService.fetchEnv(slug);
218
+ const env = await this.productBuilderService.fetchEnv(slug);
131
219
  if (!env) {
132
220
  throw new Error(`Env with slug ${slug} does not exist`);
133
221
  }
134
222
  await this.inputService.validateInput(input, session.schema_data);
135
- const expiry = (0, processor_utils_1.calculateExpiry)(session.expiry, session.period);
223
+ const stages = (0, string_utils_1.extractStages)(session.selector);
224
+ // Convert stages to string[] for functions expecting string[]
225
+ const stringStages = stages.map(stage => String(stage));
226
+ const user = (0, processor_utils_1.extractSelectorValue)(data, stringStages, session.selector);
227
+ const expiry = (0, processor_utils_1.calculateJWTExpiry)(session.expiry, session.period);
228
+ const end_at = (0, processor_utils_1.calculateExpiry)(session.expiry, session.period);
136
229
  const JWT = await loadJWT();
137
230
  if (JWT) {
138
- const token = JWT.sign(JSON.stringify(Object.assign({ type: "token" }, data)), this.productBuilderService.fetchProduct().private_key, { expiresIn: expiry });
139
- const refreshToken = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.productBuilderService.fetchProduct().private_key);
231
+ const session_id = (0, uuid_1.v4)();
232
+ const token = JWT.sign({ session: payload.tag, env: payload.env, session_id, data }, privateKey, { expiresIn: expiry });
233
+ const refreshToken = (0, processor_utils_1.encrypt)(JSON.stringify(data), privateKey);
140
234
  // WRITE REFRESH TOKEN TO DATABASE... TO INVALIDATE DELETE FROM DATABASE
141
- await this.processorApiService.createRefreshToken({ product_tag, env: slug, refreshToken }, this.getUserAccess());
235
+ const details = {
236
+ identifier: user,
237
+ start_at: Date.now(),
238
+ end_at,
239
+ session_tag: tag,
240
+ data: (0, processor_utils_1.encrypt)(JSON.stringify(JSON.stringify(data)), privateKey),
241
+ session_id
242
+ };
243
+ await this.processorApiService.createSessionInfo(Object.assign({ product_tag, env: slug, refreshToken }, details), this.getUserAccess());
142
244
  return {
143
245
  token,
144
246
  refreshToken,
@@ -152,100 +254,46 @@ class ProcessorService {
152
254
  throw e;
153
255
  }
154
256
  }
155
- async registerWebhook(data) {
156
- const { product: product_tag, access_tag, webhook_tag, envs } = data;
157
- await this.productBuilderService.initializeProductByTag(product_tag);
158
- const product = this.productBuilderService.fetchProduct();
159
- const { version, envs: appEnvs } = this.productBuilderService.fetchApp(access_tag);
160
- const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(access_tag);
161
- const { webhooks } = app.versions.find((data) => data.tag === version);
162
- if (!webhooks) {
163
- throw new Error(`Webhooks not found for app ${access_tag}`);
257
+ async refreshSession(payload) {
258
+ await this.productBuilderService.initializeProductByTag(payload.product);
259
+ const privateKey = this.productBuilderService.fetchPrivateKey();
260
+ // validate token validity
261
+ const { refreshToken } = payload, payloadData = __rest(payload, ["refreshToken"]);
262
+ const valid = await this.processorApiService.validateRefreshToken({ refreshToken, product: payload.product, env: payload.env }, this.getUserAccess());
263
+ if (valid) {
264
+ const data = JSON.parse((0, processor_utils_1.decrypt)(refreshToken, privateKey));
265
+ return await this.generateSession(Object.assign(Object.assign({}, payloadData), { data }));
164
266
  }
165
- await validators_1.RegisterWebhookEnvSchema.validateAsync(envs);
166
- const webhook = webhooks.find((data) => data.tag === webhook_tag);
167
- if (!webhook) {
168
- throw new Error(`Webhook tag ${webhook_tag} not found`);
267
+ else {
268
+ throw new Error(`Invalid refresh token`);
269
+ }
270
+ }
271
+ async decryptSession(data) {
272
+ await this.productBuilderService.initializeProductByTag(data.product);
273
+ const privateKey = this.productBuilderService.fetchPrivateKey();
274
+ const JWT = await loadJWT();
275
+ if (!JWT) {
276
+ throw new Error(`Running in browser, token service not loaded.`);
169
277
  }
170
- const productEnvs = this.productBuilderService.fetchEnvs();
171
- productEnvs.map((env) => {
172
- const exists = envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
173
- if (exists === -1) {
174
- throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
278
+ try {
279
+ const res = await JWT.verify(data.token, privateKey);
280
+ if (res.session !== data.tag) {
281
+ throw new Error(`Invalid token for session ${data.tag}`);
175
282
  }
176
- });
177
- const dataArray = await Promise.all(envs.map(async (env) => {
178
- await this.validateActionDataMappingInput(env.auth, types_1.WebhookEventTypes.WEBHOOK_REGISTER);
179
- const productEnvData = productEnvs.find((data) => data.slug === env.slug);
180
- if (!productEnvData) {
181
- throw new Error(`Error finding product env ${env.slug}`);
182
- }
183
- const envData = productEnvData.envs.find((productEnvMap) => productEnvMap.product_env_slug === env.slug);
184
- if (!envData) {
185
- throw new Error(`Error finding env data for ${env.slug}`);
186
- }
187
- const { app_env_slug: appEnv, product_env_slug: productEnv } = envData;
188
- const envWebhookData = webhook.envs.find((webhookEnv) => webhookEnv.slug === appEnv);
189
- if (!envWebhookData) {
190
- throw new Error(`Error finding webhook registration sample ${webhook_tag} for env ${env.slug}`);
191
- }
192
- const uuid = (0, uuid_1.v4)();
193
- const url = `${urls_1.WEBHOOK_BASE_URL}/webhooks/v1/process/${uuid}`;
194
- let active = false;
195
- if (envWebhookData.sample) {
196
- const samples = {
197
- query: envWebhookData.sample_data.filter((data) => data.parent_key === 'query'),
198
- params: envWebhookData.sample_data.filter((data) => data.parent_key === 'params'),
199
- body: envWebhookData.sample_data.filter((data) => data.parent_key === 'body'),
200
- headers: envWebhookData.sample_data.filter((data) => data.parent_key === 'headers'),
201
- };
202
- let payload = (await this.constructJSONDataPayloads(env.auth, {}, samples, {
203
- app: access_tag,
204
- event: '',
205
- input: env.auth,
206
- type: types_1.FeatureEventTypes.ACTION,
207
- retries: 0,
208
- allow_fail: false,
209
- }));
210
- const { updatedObj, replacedUrl } = (0, processor_utils_1.updateUrlsInObject)(payload, url);
211
- if (replacedUrl && replacedUrl !== env.url && replacedUrl) {
212
- throw new Error(`Ductape expects the url ${replacedUrl} in request body to match inputted url ${env.url}`);
213
- }
214
- const exists = this.fetchEnv(env.slug, {});
215
- if (!exists) {
216
- throw new Error(`Env ${env.slug} does not exist`);
217
- }
218
- payload = updatedObj;
219
- if (!replacedUrl) {
220
- payload.body.url = url;
221
- }
222
- const parsedUrl = new URL(envWebhookData.registration_url);
223
- await this.sendActionRequest(parsedUrl.origin, parsedUrl.pathname, payload, envWebhookData.method, env.slug);
224
- active = true;
283
+ if (res.env !== data.env) {
284
+ throw new Error(`Invalid session env`);
225
285
  }
226
- return {
227
- appEnv,
228
- productEnv,
229
- uuid,
230
- url: env.url,
231
- method: env.method,
232
- access_tag,
233
- webhook_tag,
234
- version,
235
- sender_workspace_id: app.workspace_id,
236
- receiver_workspace_id: product.workspace_id,
237
- app_tag: app.tag,
238
- product_tag,
239
- active,
240
- };
241
- }));
242
- await this.webhookApi.registerWebhooks(dataArray, this.getUserAccess());
286
+ return res.data;
287
+ }
288
+ catch (e) {
289
+ console.log(e);
290
+ throw new Error("Invalid/Expired token");
291
+ }
243
292
  }
244
293
  async generateWebhookLink(data) {
245
294
  const { product: product_tag, access_tag, webhook_tag, env: product_env, url, method } = data;
246
295
  await this.productBuilderService.initializeProductByTag(product_tag);
247
- const product = this.productBuilderService.fetchProduct();
248
- const { version, envs: appEnvs } = this.productBuilderService.fetchApp(access_tag);
296
+ const { version, envs: appEnvs } = await this.productBuilderService.fetchApp(access_tag);
249
297
  const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(access_tag);
250
298
  const { webhooks } = app.versions.find((data) => data.tag === version);
251
299
  if (!webhooks) {
@@ -266,7 +314,7 @@ class ProcessorService {
266
314
  webhook_tag,
267
315
  version,
268
316
  sender_workspace_id: app.workspace_id,
269
- receiver_workspace_id: product.workspace_id,
317
+ receiver_workspace_id: this.getUserAccess().workspace_id,
270
318
  app_tag: app.tag,
271
319
  product_tag,
272
320
  active: false,
@@ -296,12 +344,12 @@ class ProcessorService {
296
344
  process_id,
297
345
  data: input,
298
346
  };
299
- this.quota = this.fetchQuota(quota_tag, additional_logs);
347
+ this.quota = await this.fetchQuota(quota_tag, additional_logs);
300
348
  if (!this.quota) {
301
349
  throw new Error(`Quota ${quota_tag} not found`);
302
350
  }
303
351
  this.logService.setFeatureId(this.quota._id);
304
- this.processEnv = this.fetchEnv(env, additional_logs);
352
+ this.processEnv = await this.fetchEnv(env, additional_logs);
305
353
  if (!this.processEnv.active) {
306
354
  throw new Error(`Environment ${data.env} is not active`);
307
355
  }
@@ -358,10 +406,14 @@ class ProcessorService {
358
406
  }
359
407
  async overrideQuotaFallbackInput(value, quotaInput, app) {
360
408
  if (value.startsWith('$Input{')) {
361
- return quotaInput[(0, string_utils_1.extractStages)(value)[0]];
409
+ const stages = (0, string_utils_1.extractStages)(value);
410
+ return quotaInput[String(stages[0])];
362
411
  }
363
412
  else if (value.startsWith('$Auth')) {
364
- return await this.generateAuthValue((0, string_utils_1.extractStages)(value), app, [], {});
413
+ const stages = (0, string_utils_1.extractStages)(value);
414
+ // Convert stages to string[] for functions expecting string[]
415
+ const stringStages = stages.map(stage => String(stage));
416
+ return await this.generateAuthValue(stringStages, app, [], {});
365
417
  }
366
418
  else if (value.startsWith('$')) {
367
419
  this.input = Object.assign(Object.assign({}, this.input), { input: quotaInput });
@@ -423,12 +475,12 @@ class ProcessorService {
423
475
  process_id,
424
476
  data: input,
425
477
  };
426
- this.fallback = this.fetchFallback(fallback_tag, additional_logs);
478
+ this.fallback = await this.fetchFallback(fallback_tag, additional_logs);
427
479
  if (!this.fallback) {
428
480
  throw new Error(`Fallback "${fallback_tag}" not found`);
429
481
  }
430
482
  this.logService.setFeatureId(this.fallback._id);
431
- this.processEnv = this.fetchEnv(env, additional_logs);
483
+ this.processEnv = await this.fetchEnv(env, additional_logs);
432
484
  if (!this.processEnv.active) {
433
485
  throw new Error(`Environment ${data.env} is not active`);
434
486
  }
@@ -461,7 +513,7 @@ class ProcessorService {
461
513
  this.component = types_1.LogEventTypes.FEATURE;
462
514
  const process_id = this.process_id || (0, processor_utils_1.generateObjectId)();
463
515
  this.process_id = process_id;
464
- this.feature = this.fetchFeature(feature_tag, additional_logs);
516
+ this.feature = await this.fetchFeature(feature_tag, additional_logs);
465
517
  if (!this.feature) {
466
518
  throw new Error(`Feature "${feature_tag}" not found`);
467
519
  }
@@ -477,7 +529,7 @@ class ProcessorService {
477
529
  feature_id: this.feature._id,
478
530
  };
479
531
  this.logService.setFeatureId(this.feature._id);
480
- this.processEnv = this.fetchEnv(env, additional_logs);
532
+ this.processEnv = await this.fetchEnv(env, additional_logs);
481
533
  if (!this.processEnv.active) {
482
534
  throw new Error(`Environment ${data.env} is not active`);
483
535
  }
@@ -525,8 +577,8 @@ class ProcessorService {
525
577
  else {
526
578
  await this.productBuilderService.initializeProduct(this.productId);
527
579
  }
528
- const { _id: product_id, workspace_id } = this.productBuilderService.fetchProduct();
529
- this.productId = product_id;
580
+ this.productId = this.productBuilderService.fetchProductId();
581
+ const workspace_id = this.productBuilderService.fetchWorkspaceId();
530
582
  if (workspace_id !== this.workspace_id) {
531
583
  throw new Error('Access Denied');
532
584
  }
@@ -537,9 +589,35 @@ class ProcessorService {
537
589
  throw e;
538
590
  }
539
591
  }
540
- fetchFeature(tag, additional_logs) {
592
+ async initializePricing(additional_logs, access_tag) {
593
+ if (!this.logService) {
594
+ this.logService = new logs_service_1.default({
595
+ product_id: this.productId,
596
+ workspace_id: this.workspace_id,
597
+ public_key: this.public_key,
598
+ user_id: this.user_id,
599
+ token: this.token,
600
+ env_type: this.environment,
601
+ });
602
+ }
603
+ try {
604
+ console.log(`Initializing pricing for access tag: ${access_tag}`);
605
+ const product_app = await this.productBuilderService.fetchApp(access_tag); // validate app exists
606
+ console.log(`Found product app: ${JSON.stringify(product_app)}`);
607
+ const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(product_app.access_tag);
608
+ await this.pricingService.initializePricingByTag(product_app.pricing_tag, app._id);
609
+ const { pricing_tag } = this.pricingService.fetchPricing();
610
+ this.pricingTag = pricing_tag;
611
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Pricing initialize - success', data: { pricing_tag: this.pricingTag }, status: types_1.LogEventStatus.SUCCESS }));
612
+ }
613
+ catch (e) {
614
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Pricing initialize - failed', data: e, status: types_1.LogEventStatus.FAIL }));
615
+ throw e;
616
+ }
617
+ }
618
+ async fetchFeature(tag, additional_logs) {
541
619
  try {
542
- const feature = this.productBuilderService.fetchFeature(tag); // validate feature exists
620
+ const feature = await this.productBuilderService.fetchFeature(tag); // validate feature exists
543
621
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch feature - success', data: { tag, feature }, status: types_1.LogEventStatus.SUCCESS }));
544
622
  return feature;
545
623
  }
@@ -548,9 +626,9 @@ class ProcessorService {
548
626
  throw e;
549
627
  }
550
628
  }
551
- fetchQuota(tag, additional_logs) {
629
+ async fetchQuota(tag, additional_logs) {
552
630
  try {
553
- const quota = this.productBuilderService.fetchQuota(tag); // validate feature exists
631
+ const quota = await this.productBuilderService.fetchQuota(tag); // validate feature exists
554
632
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch quota - success', data: { tag, quota }, status: types_1.LogEventStatus.SUCCESS }));
555
633
  return quota;
556
634
  }
@@ -559,9 +637,9 @@ class ProcessorService {
559
637
  throw e;
560
638
  }
561
639
  }
562
- fetchFallback(tag, additional_logs) {
640
+ async fetchFallback(tag, additional_logs) {
563
641
  try {
564
- const fallback = this.productBuilderService.fetchFallback(tag); // validate feature exists
642
+ const fallback = await this.productBuilderService.fetchFallback(tag); // validate feature exists
565
643
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch fallback - success', data: { tag, fallback }, status: types_1.LogEventStatus.SUCCESS }));
566
644
  return fallback;
567
645
  }
@@ -570,9 +648,9 @@ class ProcessorService {
570
648
  throw e;
571
649
  }
572
650
  }
573
- fetchEnv(env, additional_logs) {
651
+ async fetchEnv(env, additional_logs) {
574
652
  try {
575
- const product_env = this.productBuilderService.fetchEnv(env); // validate env exists
653
+ const product_env = await this.productBuilderService.fetchEnv(env); // validate env exists
576
654
  if (!product_env) {
577
655
  throw new Error(`Env ${env} not found`);
578
656
  }
@@ -787,8 +865,8 @@ class ProcessorService {
787
865
  if (values[i].startsWith('$Sequence')) {
788
866
  const stages = this.productBuilderService.extractStages(values[i]);
789
867
  dependants.push({
790
- sequence_tag: stages[0],
791
- event_tag: stages[1],
868
+ sequence_tag: String(stages[0]),
869
+ event_tag: String(stages[1]),
792
870
  });
793
871
  }
794
872
  else if (values[i].startsWith('$')) {
@@ -798,8 +876,8 @@ class ProcessorService {
798
876
  if (arg.startsWith('$Sequence')) {
799
877
  const stages = this.productBuilderService.extractStages(arg);
800
878
  dependants.push({
801
- sequence_tag: stages[0],
802
- event_tag: stages[1],
879
+ sequence_tag: String(stages[0]),
880
+ event_tag: String(stages[1]),
803
881
  });
804
882
  }
805
883
  });
@@ -825,7 +903,7 @@ class ProcessorService {
825
903
  const dependants = [];
826
904
  if (value.startsWith('$Sequence')) {
827
905
  const stages = this.productBuilderService.extractStages(value);
828
- dependants.push({ sequence_tag: stages[0], event_tag: stages[1] });
906
+ dependants.push({ sequence_tag: String(stages[0]), event_tag: String(stages[1]) });
829
907
  }
830
908
  else if (value.startsWith('$')) {
831
909
  const funcArgs = (0, functions_utils_1.extractFunctionAndArgs)(value);
@@ -834,8 +912,8 @@ class ProcessorService {
834
912
  if (arg.startsWith('$Sequence')) {
835
913
  const stages = this.productBuilderService.extractStages(arg);
836
914
  dependants.push({
837
- sequence_tag: stages[0],
838
- event_tag: stages[1],
915
+ sequence_tag: String(stages[0]),
916
+ event_tag: String(stages[1]),
839
917
  });
840
918
  }
841
919
  else {
@@ -908,6 +986,7 @@ class ProcessorService {
908
986
  async generatePayload(obj, event, additional_logs, sample = [], index = {}, loopIndex = null) {
909
987
  try {
910
988
  const payload = {};
989
+ console.log("Payload Construction", { obj, event, sample, index, loopIndex });
911
990
  const keys = Object.keys(obj);
912
991
  for (let i = 0; i < keys.length; i++) {
913
992
  const key = keys[i];
@@ -953,22 +1032,32 @@ class ProcessorService {
953
1032
  const locatorFor$Index = (0, string_utils_1.validateAndLocateTag)(value);
954
1033
  if (value.startsWith('$Auth{') && value.endsWith('}')) {
955
1034
  // should only be allowed in apps
956
- return await this.generateAuthValue(stages, app, sample, additional_logs);
1035
+ // Convert stages to string[] for functions expecting string[]
1036
+ const stringStages = stages.map(stage => String(stage));
1037
+ return await this.generateAuthValue(stringStages, app, sample, additional_logs);
957
1038
  }
958
1039
  else if (value.startsWith('$Sequence{') && value.endsWith('}')) {
959
- return await this.generateSequenceValue(stages, locatorFor$Index, loopIndex); // pass
1040
+ // Convert stages to string[] for functions expecting string[]
1041
+ const stringStages = stages.map(stage => String(stage));
1042
+ return await this.generateSequenceValue(stringStages, locatorFor$Index, loopIndex); // pass
960
1043
  }
961
1044
  else if (value.startsWith('$Input{') && value.endsWith('}')) {
962
- return await this.generateInputValue(this.input.input, stages);
1045
+ // Convert stages to string[] for functions expecting string[]
1046
+ const stringStages = stages.map(stage => String(stage));
1047
+ return await this.generateInputValue(this.input.input, stringStages);
963
1048
  }
964
1049
  else if (value === '$Default') {
965
1050
  return await this.generateDefaultValue(sample, Object.assign(Object.assign({}, index), { key }));
966
1051
  }
967
1052
  else if (value.startsWith('$Variable{') && value.endsWith('}')) {
968
- return await this.generateVariableValue(stages);
1053
+ // Convert stages to string[] for functions expecting string[]
1054
+ const stringStages = stages.map(stage => String(stage));
1055
+ return await this.generateVariableValue(stringStages);
969
1056
  }
970
1057
  else if (value.startsWith('$Constant{') && value.endsWith('}')) {
971
- return await this.generateConstantValue(stages);
1058
+ // Convert stages to string[] for functions expecting string[]
1059
+ const stringStages = stages.map(stage => String(stage));
1060
+ return await this.generateConstantValue(stringStages);
972
1061
  }
973
1062
  else if (value.startsWith('$Size{') || value.startsWith('$Length{')) {
974
1063
  const { matchLength, matchSize } = (0, string_utils_1.checkLengthAndSizeMatches)(value);
@@ -1093,6 +1182,7 @@ class ProcessorService {
1093
1182
  const placeholdersStr = match[1];
1094
1183
  const separator = match[2];
1095
1184
  const placeHolders = placeholdersStr.split(',').map((data) => data.trim());
1185
+ console.log('placeHolders', { placeHolders, separator });
1096
1186
  const values = await Promise.all(placeHolders.map(async (holder) => {
1097
1187
  return await this.generateStringValues(holder, app, additional_logs, sample, index, key, loopIndex);
1098
1188
  }));
@@ -1365,7 +1455,7 @@ class ProcessorService {
1365
1455
  }
1366
1456
  async generateVariableValue(stages) {
1367
1457
  try {
1368
- const app = this.productBuilderService.fetchApp(stages[0]);
1458
+ const app = await this.productBuilderService.fetchApp(stages[0]);
1369
1459
  const env = app.envs.find((items) => items.product_env_slug === this.processEnv.slug);
1370
1460
  if (!env) {
1371
1461
  throw new Error(`App ${stages[0]} variables needs to have a definition for env: ${this.processEnv.slug}`);
@@ -1411,6 +1501,7 @@ class ProcessorService {
1411
1501
  }
1412
1502
  async generateAuthValue(stages, app, sample, additional_logs) {
1413
1503
  try {
1504
+ console.log("Generate Auth Data", { stages, app, sample });
1414
1505
  let auth_data = await this.fetchAuthData(app, additional_logs); //TODO: should use stages[0]
1415
1506
  // take the app tag in index 0..
1416
1507
  if (!auth_data) {
@@ -1426,7 +1517,7 @@ class ProcessorService {
1426
1517
  }
1427
1518
  async fetchAuthData(app_tag, additional_logs) {
1428
1519
  try {
1429
- const app = this.productBuilderService.fetchApp(app_tag);
1520
+ const app = await this.productBuilderService.fetchApp(app_tag);
1430
1521
  if (!app) {
1431
1522
  throw new Error(`App ${app_tag} not found in $Auth value`);
1432
1523
  }
@@ -1437,6 +1528,7 @@ class ProcessorService {
1437
1528
  if (!env.auth) {
1438
1529
  throw new Error(`App ${app_tag} in auth needs to have a definition for auth in env: ${this.processEnv.slug}`);
1439
1530
  }
1531
+ console.log("Envroment", env.auth);
1440
1532
  let values = env.auth.values;
1441
1533
  if (!values) {
1442
1534
  // no auth values
@@ -1444,9 +1536,10 @@ class ProcessorService {
1444
1536
  }
1445
1537
  if (!env.auth.expiry || (env.auth.expiry && Date.now() > new Date(env.auth.expiry).getTime())) {
1446
1538
  // refresh
1539
+ console.log("REFRESH DATA", env, app_tag);
1447
1540
  values = await this.getAndStoreAuth(env, app_tag);
1448
1541
  }
1449
- const decrypted = (0, processor_utils_1.decrypt)(values, this.productBuilderService.fetchProduct().private_key);
1542
+ const decrypted = (0, processor_utils_1.decrypt)(values, this.productBuilderService.fetchPrivateKey());
1450
1543
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch auth data - success', data: { auth: (0, processor_utils_1.anonymizeValue)(decrypted) }, status: types_1.LogEventStatus.SUCCESS }));
1451
1544
  return JSON.parse(decrypted);
1452
1545
  }
@@ -1556,7 +1649,18 @@ class ProcessorService {
1556
1649
  parent_tag: event.event,
1557
1650
  name: 'Process feature job',
1558
1651
  };
1559
- return this.runJob(event, additional_logs);
1652
+ const input = {
1653
+ env: event.env.slug,
1654
+ product: this.productTag,
1655
+ event: event.event,
1656
+ retries: event.retries,
1657
+ input: event.input,
1658
+ start_at: event.start_at || 0,
1659
+ cache: event.cache,
1660
+ session: this.input.session
1661
+ };
1662
+ // TODO: fix this
1663
+ return this.processJob(input, additional_logs);
1560
1664
  }
1561
1665
  }
1562
1666
  catch (e) {
@@ -1580,8 +1684,10 @@ class ProcessorService {
1580
1684
  }
1581
1685
  return output;
1582
1686
  }
1583
- runJob(event, additional_logs) {
1584
- throw new Error('Method not implemented.');
1687
+ async runJobs(job, additional_logs = {}) {
1688
+ if (job.name === types_1.FeatureEventTypes.ACTION) {
1689
+ await this.processAction(job.data);
1690
+ }
1585
1691
  }
1586
1692
  async processFailedAndWaiting() { }
1587
1693
  async fetchResult(process_id) {
@@ -1590,8 +1696,8 @@ class ProcessorService {
1590
1696
  throw new Error(`Invalid process id ${process_id}`);
1591
1697
  }
1592
1698
  await this.productBuilderService.initializeProduct(result.product_id);
1593
- result.result = JSON.parse((0, processor_utils_1.decrypt)(String(result.result), this.productBuilderService.fetchProduct().private_key));
1594
- result.input = JSON.parse((0, processor_utils_1.decrypt)(String(result.input), this.productBuilderService.fetchProduct().private_key));
1699
+ result.result = JSON.parse((0, processor_utils_1.decrypt)(String(result.result), this.productBuilderService.fetchPrivateKey()));
1700
+ result.input = JSON.parse((0, processor_utils_1.decrypt)(String(result.input), this.productBuilderService.fetchPrivateKey()));
1595
1701
  return result;
1596
1702
  }
1597
1703
  async generateOutput(process_id) {
@@ -1655,7 +1761,7 @@ class ProcessorService {
1655
1761
  if (result.component === types_1.LogEventTypes.FEATURE) {
1656
1762
  this.feature = await this.fetchFeature(result.input.tag, additional_logs);
1657
1763
  const { input: featureInput, sequence, output } = this.feature;
1658
- this.processEnv = this.fetchEnv(result.env, additional_logs);
1764
+ this.processEnv = await this.fetchEnv(result.env, additional_logs);
1659
1765
  if (!this.processEnv.active) {
1660
1766
  throw new Error(`Environment ${result.env} is not active`);
1661
1767
  }
@@ -1697,7 +1803,7 @@ class ProcessorService {
1697
1803
  //await this.processWaitingEvents(additional_logs);
1698
1804
  this.feature = await this.fetchFeature(result.input.tag, additional_logs);
1699
1805
  const { input: featureInput, sequence, output } = this.feature;
1700
- this.processEnv = this.fetchEnv(result.env, additional_logs);
1806
+ this.processEnv = await this.fetchEnv(result.env, additional_logs);
1701
1807
  if (!this.processEnv.active) {
1702
1808
  throw new Error(`Environment ${result.env} is not active`);
1703
1809
  }
@@ -1712,7 +1818,7 @@ class ProcessorService {
1712
1818
  ((_b = result.result.success[0]) === null || _b === void 0 ? void 0 : _b.event) ||
1713
1819
  ((_c = result.result.skipped[0]) === null || _c === void 0 ? void 0 : _c.event) ||
1714
1820
  result.result.waiting[0].event;
1715
- this.processEnv = this.fetchEnv(result.env, additional_logs);
1821
+ this.processEnv = await this.fetchEnv(result.env, additional_logs);
1716
1822
  this.start = Date.now();
1717
1823
  await this.processEvent(event);
1718
1824
  this.end = Date.now();
@@ -1739,10 +1845,11 @@ class ProcessorService {
1739
1845
  }
1740
1846
  async getAndStoreAuth(appEnv, access_tag) {
1741
1847
  try {
1742
- // const payload = JSON.parse(decrypt(env.auth.data, this.productBuilderService.fetchProduct().private_key));
1743
- const payload = appEnv.auth.data;
1848
+ // const payload = JSON.parse(decrypt(env.auth.data, this.productBuilderService.fetchPrivateKey()));
1849
+ const payload = JSON.parse((0, processor_utils_1.decrypt)(String(appEnv.auth.data), this.productBuilderService.fetchPrivateKey()));
1744
1850
  let app = await this.fetchThirdPartyApp(access_tag);
1745
1851
  const auth = app.auths.find((item) => item.tag === appEnv.auth.auth_tag);
1852
+ console.log("JAMESY", auth);
1746
1853
  if (!auth) {
1747
1854
  // throw an error
1748
1855
  throw new Error(`Cannot find auth ${appEnv.auth.auth_tag} on environment ${appEnv.product_env_slug}`);
@@ -1757,9 +1864,16 @@ class ProcessorService {
1757
1864
  if (env.base_url) {
1758
1865
  request_base_url = env.base_url;
1759
1866
  }
1867
+ if (action.envs && action.envs.length) {
1868
+ const env = action.envs.find((item) => item.slug === appEnv.app_env_slug);
1869
+ if (env && env.base_url) {
1870
+ request_base_url = env.base_url;
1871
+ }
1872
+ }
1873
+ console.log("payloadabi!!!!", payload);
1760
1874
  const results = await this.sendActionRequest(request_base_url, url, payload, method, appEnv.app_env_slug);
1761
- const values = (0, processor_utils_1.encrypt)(JSON.stringify(results), this.productBuilderService.fetchProduct().private_key);
1762
- const productApp = this.productBuilderService.fetchApp(access_tag);
1875
+ const values = (0, processor_utils_1.encrypt)(JSON.stringify(results), this.productBuilderService.fetchPrivateKey());
1876
+ const productApp = await this.productBuilderService.fetchApp(access_tag);
1763
1877
  for (let i = 0; i < productApp.envs.length; i++) {
1764
1878
  if (productApp.envs[i].app_env_slug === env.slug) {
1765
1879
  productApp.envs[i].auth.values = values; // write new values
@@ -1870,12 +1984,13 @@ class ProcessorService {
1870
1984
  }
1871
1985
  let app = await this.fetchThirdPartyApp(access_tag);
1872
1986
  const { actions, envs: appEnvs, retries, workspace_id: recipient_workspace_id, active } = app;
1873
- const productApp = this.productBuilderService.fetchApp(access_tag);
1987
+ const productApp = await this.productBuilderService.fetchApp(access_tag);
1874
1988
  const { envs: productEnvs, version } = productApp;
1875
1989
  const { app_env_slug } = productEnvs.find((item) => item.product_env_slug === this.processEnv.slug);
1876
1990
  additional_logs.app_env = app_env_slug;
1991
+ console.log(app, appEnvs);
1877
1992
  const env = appEnvs.find((item) => item.slug === app_env_slug); // fetch the actuall app Environment variable
1878
- if (!active) {
1993
+ if (!active && recipient_workspace_id !== this.baseLogs.workspace_id) {
1879
1994
  throw new Error(`App ${event.app} version ${app.version} is not active`);
1880
1995
  }
1881
1996
  if (!env.active) {
@@ -1890,6 +2005,12 @@ class ProcessorService {
1890
2005
  if (env.base_url) {
1891
2006
  request_base_url = env.base_url;
1892
2007
  }
2008
+ if (action.envs && action.envs.length) {
2009
+ const env = action.envs.find((item) => item.slug === app_env_slug);
2010
+ if (env && env.base_url) {
2011
+ request_base_url = env.base_url;
2012
+ }
2013
+ }
1893
2014
  const samples = {
1894
2015
  query: (query === null || query === void 0 ? void 0 : query.data) || [],
1895
2016
  headers: (headers === null || headers === void 0 ? void 0 : headers.data) || [],
@@ -1898,9 +2019,9 @@ class ProcessorService {
1898
2019
  };
1899
2020
  let payloads;
1900
2021
  let result;
1901
- const product = this.productBuilderService.fetchProduct();
2022
+ //const product = this.productBuilderService.fetchProduct();
1902
2023
  if (cache_tag && this.redisClient) {
1903
- const productCache = this.productBuilderService.fetchCache(cache_tag);
2024
+ const productCache = await this.productBuilderService.fetchCache(cache_tag);
1904
2025
  if (!productCache) {
1905
2026
  throw new Error('Invalid cache tag ');
1906
2027
  }
@@ -1908,7 +2029,7 @@ class ProcessorService {
1908
2029
  const check = await this.fetchFromCache({
1909
2030
  cache_tag,
1910
2031
  input: inputString,
1911
- privateKey: product.private_key,
2032
+ privateKey: this.productBuilderService.fetchPrivateKey(),
1912
2033
  expiry: productCache.expiry,
1913
2034
  }, additional_logs);
1914
2035
  if (check) {
@@ -1938,14 +2059,14 @@ class ProcessorService {
1938
2059
  }
1939
2060
  }
1940
2061
  if (cache_tag && this.redisClient && result) {
1941
- const productCache = this.productBuilderService.fetchCache(cache_tag);
2062
+ const productCache = await this.productBuilderService.fetchCache(cache_tag);
1942
2063
  if (!productCache) {
1943
2064
  throw new Error('Invalid cache tag ');
1944
2065
  }
1945
2066
  const inputString = JSON.stringify(event.input);
1946
2067
  await this.addToCache({
1947
2068
  input: inputString,
1948
- privateKey: product.private_key,
2069
+ privateKey: this.productBuilderService.fetchPrivateKey(),
1949
2070
  data: JSON.stringify(result),
1950
2071
  cache_tag,
1951
2072
  timestamp: Date.now(),
@@ -1962,6 +2083,7 @@ class ProcessorService {
1962
2083
  }
1963
2084
  }
1964
2085
  async processRequest(payload, event, retries, additional_logs, returnValue = false) {
2086
+ var _a;
1965
2087
  const { request_base_url, resource, payloads, method, env, app_id } = payload;
1966
2088
  const start = Date.now();
1967
2089
  try {
@@ -1972,7 +2094,11 @@ class ProcessorService {
1972
2094
  const end = Date.now();
1973
2095
  this.requestTime += end - start;
1974
2096
  this.totalRequests += 1;
1975
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process http request - success', successful_execution: true, data: { response: (0, processor_utils_1.anonymizeObject)(results) }, status: types_1.LogEventStatus.SUCCESS, app_id, action: event.event, start,
2097
+ const { pricing_tag, pricing_cost, is_overage, currency } = await this.processPricingCost(Object.assign(Object.assign({}, additional_logs), { app_id, workspace_id: this.workspace_id }));
2098
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { pricing_tag,
2099
+ pricing_cost,
2100
+ currency,
2101
+ is_overage, message: 'Process http request - success', successful_execution: true, data: { response: (0, processor_utils_1.anonymizeObject)(results) }, status: types_1.LogEventStatus.SUCCESS, app_id, action: event.event, start,
1976
2102
  end }));
1977
2103
  await this.addToSuccessOutput(event, results, additional_logs);
1978
2104
  if (returnValue) {
@@ -1985,7 +2111,7 @@ class ProcessorService {
1985
2111
  catch (e) {
1986
2112
  const end = Date.now();
1987
2113
  let error = e;
1988
- if (e.response.data) {
2114
+ if ((_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.data) {
1989
2115
  error = e.response.data;
1990
2116
  }
1991
2117
  this.requestTime += end - start;
@@ -2018,6 +2144,67 @@ class ProcessorService {
2018
2144
  }
2019
2145
  }
2020
2146
  }
2147
+ async processPricingCost(additional_logs) {
2148
+ try {
2149
+ const { app_id, workspace_id } = additional_logs;
2150
+ if (!app_id || !workspace_id) {
2151
+ throw new Error('app_id and workspace_id are required in additional_logs');
2152
+ }
2153
+ const primaryPricing = this.pricingService.fetchPricing();
2154
+ const overagePricing = this.pricingService.fetchOveragePricing();
2155
+ const requests = await this.requestTrackerService.incrementRequest(app_id, workspace_id);
2156
+ const limitCheck = (0, request_utils_1.checkLimitExceeded)(requests, primaryPricing.limits);
2157
+ let finalCost = 0;
2158
+ let usedPricing = primaryPricing;
2159
+ let isOverage = false;
2160
+ let finalCurrency = primaryPricing.currency;
2161
+ if ((0, request_utils_1.isFreeTag)(primaryPricing.pricing_tag)) {
2162
+ if (limitCheck.exceeded) {
2163
+ const overageRequests = (0, request_utils_1.calculateOverageRequests)(requests, primaryPricing.limits);
2164
+ finalCost = (0, request_utils_1.calculateCost)(overagePricing.pricing_mode, overagePricing.unit_price, overageRequests);
2165
+ usedPricing = overagePricing;
2166
+ isOverage = true;
2167
+ finalCurrency = overagePricing.currency;
2168
+ }
2169
+ else {
2170
+ finalCost = 0;
2171
+ }
2172
+ }
2173
+ else {
2174
+ if (limitCheck.exceeded) {
2175
+ const overageRequests = (0, request_utils_1.calculateOverageRequests)(requests, primaryPricing.limits);
2176
+ const overageCost = (0, request_utils_1.calculateCost)(overagePricing.pricing_mode, overagePricing.unit_price, overageRequests);
2177
+ finalCost = overageCost;
2178
+ isOverage = true;
2179
+ }
2180
+ else {
2181
+ const pricingRequests = (0, request_utils_1.calculateRequests)(requests);
2182
+ finalCost = (0, request_utils_1.calculateCost)(primaryPricing.pricing_mode, primaryPricing.unit_price, pricingRequests);
2183
+ }
2184
+ }
2185
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process Pricing Cost - success', data: {
2186
+ pricing_tag: usedPricing.pricing_tag,
2187
+ cost: finalCost,
2188
+ currency: finalCurrency,
2189
+ is_overage: isOverage,
2190
+ requests: requests,
2191
+ limit_exceeded: limitCheck.exceeded
2192
+ }, status: types_1.LogEventStatus.SUCCESS }));
2193
+ return {
2194
+ pricing_tag: usedPricing.pricing_tag,
2195
+ pricing_cost: Math.round(finalCost * 100) / 100,
2196
+ currency: finalCurrency,
2197
+ is_overage: isOverage,
2198
+ requests_made: requests,
2199
+ limit_exceeded: limitCheck.exceeded,
2200
+ exceeded_limits: limitCheck.exceededLimits
2201
+ };
2202
+ }
2203
+ catch (e) {
2204
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Process Pricing Cost - failed', data: { error: e }, status: types_1.LogEventStatus.FAIL }));
2205
+ throw e;
2206
+ }
2207
+ }
2021
2208
  async addToSuccessOutput(event, output, additional_logs) {
2022
2209
  // Remove event from failed, skipped, and waiting arrays
2023
2210
  this.processingOutput.failure = this.processingOutput.failure.filter((data) => !(data.event.sequence_tag === event.sequence_tag && data.event.event === event.event));
@@ -2143,52 +2330,15 @@ class ProcessorService {
2143
2330
  }
2144
2331
  }
2145
2332
  generateRetryMetrices(error_code, retries) {
2146
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
2147
- let allow_fail = true;
2148
- let retry_at = 5000;
2149
- let max = (retries === null || retries === void 0 ? void 0 : retries.max) || 0;
2150
- switch (error_code) {
2151
- case '500':
2152
- allow_fail = ((_a = retries === null || retries === void 0 ? void 0 : retries.policy[500]) === null || _a === void 0 ? void 0 : _a.available) || false;
2153
- retry_at = ((_b = retries === null || retries === void 0 ? void 0 : retries.policy[500]) === null || _b === void 0 ? void 0 : _b.lag) || 0;
2154
- break;
2155
- case '502':
2156
- allow_fail = ((_c = retries === null || retries === void 0 ? void 0 : retries.policy[502]) === null || _c === void 0 ? void 0 : _c.available) || false;
2157
- retry_at = ((_d = retries === null || retries === void 0 ? void 0 : retries.policy[502]) === null || _d === void 0 ? void 0 : _d.lag) || 0;
2158
- break;
2159
- case '503':
2160
- allow_fail = ((_e = retries === null || retries === void 0 ? void 0 : retries.policy[503]) === null || _e === void 0 ? void 0 : _e.available) || false;
2161
- retry_at = ((_f = retries === null || retries === void 0 ? void 0 : retries.policy[503]) === null || _f === void 0 ? void 0 : _f.lag) || 0;
2162
- break;
2163
- case '504':
2164
- allow_fail = ((_g = retries === null || retries === void 0 ? void 0 : retries.policy[504]) === null || _g === void 0 ? void 0 : _g.available) || false;
2165
- retry_at = ((_h = retries === null || retries === void 0 ? void 0 : retries.policy[504]) === null || _h === void 0 ? void 0 : _h.lag) || 0;
2166
- break;
2167
- case '400':
2168
- allow_fail = ((_j = retries === null || retries === void 0 ? void 0 : retries.policy[400]) === null || _j === void 0 ? void 0 : _j.available) || false;
2169
- retry_at = ((_k = retries === null || retries === void 0 ? void 0 : retries.policy[400]) === null || _k === void 0 ? void 0 : _k.lag) || 0;
2170
- break;
2171
- case '401':
2172
- allow_fail = ((_l = retries === null || retries === void 0 ? void 0 : retries.policy[401]) === null || _l === void 0 ? void 0 : _l.available) || false;
2173
- retry_at = ((_m = retries === null || retries === void 0 ? void 0 : retries.policy[401]) === null || _m === void 0 ? void 0 : _m.lag) || 0;
2174
- break;
2175
- case '403':
2176
- allow_fail = ((_o = retries === null || retries === void 0 ? void 0 : retries.policy[403]) === null || _o === void 0 ? void 0 : _o.available) || false;
2177
- retry_at = ((_p = retries === null || retries === void 0 ? void 0 : retries.policy[403]) === null || _p === void 0 ? void 0 : _p.lag) || 0;
2178
- break;
2179
- case '404':
2180
- allow_fail = ((_q = retries === null || retries === void 0 ? void 0 : retries.policy[404]) === null || _q === void 0 ? void 0 : _q.available) || false;
2181
- retry_at = ((_r = retries === null || retries === void 0 ? void 0 : retries.policy[404]) === null || _r === void 0 ? void 0 : _r.lag) || 0;
2182
- break;
2183
- case '1000': // all non http errors
2184
- allow_fail = true;
2185
- retry_at = 500;
2186
- default:
2187
- allow_fail = true;
2188
- retry_at = 0;
2189
- max = 0;
2190
- break;
2191
- }
2333
+ var _a;
2334
+ const isSpecial = error_code === '1000';
2335
+ if (isSpecial) {
2336
+ return { allow_fail: true, max: (retries === null || retries === void 0 ? void 0 : retries.max) || 0, retry_at: 500 };
2337
+ }
2338
+ const policy = (_a = retries === null || retries === void 0 ? void 0 : retries.policy) === null || _a === void 0 ? void 0 : _a[error_code];
2339
+ const allow_fail = policy ? policy.available : true;
2340
+ const retry_at = policy ? policy.lag : 0;
2341
+ const max = (retries === null || retries === void 0 ? void 0 : retries.max) || 0;
2192
2342
  return { allow_fail, max, retry_at };
2193
2343
  }
2194
2344
  async sendActionRequest(base_url, resource, payload, method, env) {
@@ -2214,6 +2364,7 @@ class ProcessorService {
2214
2364
  timeout: 15000,
2215
2365
  withCredentials: false
2216
2366
  };
2367
+ console.log("REQUEST!!!!", request);
2217
2368
  const response = await axios_1.default.request(request);
2218
2369
  return response.data;
2219
2370
  }
@@ -2231,7 +2382,7 @@ class ProcessorService {
2231
2382
  name: 'Process Storage',
2232
2383
  };
2233
2384
  try {
2234
- this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.STORAGE);
2385
+ await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.STORAGE);
2235
2386
  this.input = input;
2236
2387
  this.start = Date.now();
2237
2388
  this.component = types_1.LogEventTypes.STORAGE;
@@ -2244,7 +2395,7 @@ class ProcessorService {
2244
2395
  process_id, data: this.clone }, additional_logs);
2245
2396
  await this.intializeProduct(additional_logs);
2246
2397
  this.process_id = process_id;
2247
- const productEnv = this.fetchEnv(env, additional_logs);
2398
+ const productEnv = await this.fetchEnv(env, additional_logs);
2248
2399
  this.processEnv = productEnv;
2249
2400
  if (!productEnv.active) {
2250
2401
  throw new Error(`Environment ${env} is not active`);
@@ -2284,16 +2435,17 @@ class ProcessorService {
2284
2435
  name: `Subscribe to broker topic`,
2285
2436
  };
2286
2437
  try {
2287
- this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.STORAGE);
2438
+ //await this.validateActionDataMappingInput(data.input, FeatureEventTypes.STORAGE);
2439
+ const input = { callback: data.callback };
2288
2440
  this.start = Date.now();
2289
2441
  this.productTag = data.product;
2290
2442
  const process_id = (0, processor_utils_1.generateObjectId)();
2291
- this.input = data;
2292
- this.baseLogs = Object.assign({ product_tag: this.productTag, product_id: this.productId, workspace_id: this.workspace_id, env: data.env, process_id, data: data.input }, additional_logs);
2443
+ this.input = Object.assign(Object.assign({}, data), { input });
2444
+ this.baseLogs = Object.assign({ product_tag: this.productTag, product_id: this.productId, workspace_id: this.workspace_id, env: data.env, process_id, data: input }, additional_logs);
2293
2445
  await this.intializeProduct(additional_logs);
2294
2446
  this.baseLogs.product_id = this.productId;
2295
2447
  this.process_id = process_id;
2296
- const productEnv = this.fetchEnv(data.env, additional_logs);
2448
+ const productEnv = await this.fetchEnv(data.env, additional_logs);
2297
2449
  this.processEnv = productEnv;
2298
2450
  if (!productEnv.active) {
2299
2451
  throw new Error(`Environment ${data.env} is not active`);
@@ -2302,7 +2454,7 @@ class ProcessorService {
2302
2454
  const payload = {
2303
2455
  type: types_1.FeatureEventTypes.SUBSCRIBE,
2304
2456
  event: data.event,
2305
- input: data.input,
2457
+ input: input,
2306
2458
  env: productEnv,
2307
2459
  retries: 0,
2308
2460
  allow_fail: false,
@@ -2333,10 +2485,11 @@ class ProcessorService {
2333
2485
  name: 'Publish to broker topic',
2334
2486
  };
2335
2487
  try {
2336
- this.validateActionDataMappingInput(data.input, types_1.FeatureEventTypes.PUBLISH);
2488
+ const input = { message: data.message };
2489
+ await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.PUBLISH);
2337
2490
  this.start = Date.now();
2338
2491
  // clone
2339
- this.clone = (0, processor_utils_1.structuredClone)(data.input);
2492
+ this.clone = (0, processor_utils_1.structuredClone)(input);
2340
2493
  this.input = data;
2341
2494
  this.productTag = data.product;
2342
2495
  const process_id = (0, processor_utils_1.generateObjectId)();
@@ -2345,7 +2498,7 @@ class ProcessorService {
2345
2498
  await this.intializeProduct(additional_logs);
2346
2499
  this.baseLogs.product_id = this.productId;
2347
2500
  this.process_id = process_id;
2348
- const productEnv = this.fetchEnv(data.env, additional_logs);
2501
+ const productEnv = await this.fetchEnv(data.env, additional_logs);
2349
2502
  this.processEnv = productEnv;
2350
2503
  if (!productEnv.active) {
2351
2504
  throw new Error(`Environment ${data.env} is not active`);
@@ -2354,7 +2507,7 @@ class ProcessorService {
2354
2507
  type: types_1.FeatureEventTypes.PUBLISH,
2355
2508
  event: data.event,
2356
2509
  cache: data.cache,
2357
- input: data.input,
2510
+ input: input,
2358
2511
  env: productEnv,
2359
2512
  retries: 0,
2360
2513
  allow_fail: false,
@@ -2373,7 +2526,113 @@ class ProcessorService {
2373
2526
  return { process_id: this.process_id };
2374
2527
  }
2375
2528
  }
2376
- async processJob(job) { }
2529
+ async processJob(job, additional_logs = {}) {
2530
+ var _a;
2531
+ const productJob = await this.productBuilderService.fetchJob(job.event);
2532
+ if (!productJob) {
2533
+ throw new Error(`Job ${job.event} not found`);
2534
+ }
2535
+ await this.validateActionDataMappingInput(job.input, productJob.type);
2536
+ const NOW = Date.now();
2537
+ // Treat anything above Jan 1, 2023 as a timestamp (to be safe and future-proof)
2538
+ const IS_PROBABLY_TIMESTAMP = job.start_at > 1672531200000;
2539
+ const delay = Math.max(0, IS_PROBABLY_TIMESTAMP ? job.start_at - NOW : job.start_at);
2540
+ let jobInput;
2541
+ if (productJob.type === types_1.JobEventTypes.ACTION) {
2542
+ const input = {
2543
+ env: job.env,
2544
+ product: job.product,
2545
+ app: productJob.app,
2546
+ cache: job.cache,
2547
+ input: job.input,
2548
+ event: job.event,
2549
+ session: job.session
2550
+ };
2551
+ jobInput = input;
2552
+ }
2553
+ else if (productJob.type === types_1.JobEventTypes.DATABASE_ACTION) {
2554
+ const input = {
2555
+ env: job.env,
2556
+ product: job.product,
2557
+ cache: job.cache,
2558
+ input: job.input,
2559
+ event: job.event,
2560
+ session: job.session,
2561
+ };
2562
+ jobInput = input;
2563
+ }
2564
+ else if (productJob.type === types_1.JobEventTypes.FALLBACK || productJob.type === types_1.JobEventTypes.QUOTA || productJob.type === types_1.JobEventTypes.FEATURE) {
2565
+ const input = {
2566
+ input: job.input,
2567
+ product: job.product,
2568
+ env: job.env,
2569
+ tag: job.event,
2570
+ session: job.session,
2571
+ cache: job.cache,
2572
+ };
2573
+ jobInput = input;
2574
+ }
2575
+ else if (productJob.type === types_1.JobEventTypes.NOTIFICATION) {
2576
+ const input = {
2577
+ env: job.env,
2578
+ product: job.product,
2579
+ event: job.event,
2580
+ input: job.input,
2581
+ session: job.session,
2582
+ cache: job.cache
2583
+ };
2584
+ jobInput = input;
2585
+ }
2586
+ else if (productJob.type === types_1.JobEventTypes.PUBLISH) {
2587
+ const input = {
2588
+ env: job.env,
2589
+ product: job.product,
2590
+ event: job.event,
2591
+ cache: job.cache,
2592
+ session: job.session,
2593
+ message: job.input
2594
+ };
2595
+ jobInput = input;
2596
+ }
2597
+ else if (productJob.type === types_1.JobEventTypes.STORAGE) {
2598
+ const input = {
2599
+ env: job.env,
2600
+ product: job.product,
2601
+ event: job.event,
2602
+ cache: job.cache,
2603
+ session: job.session,
2604
+ input: job.input
2605
+ };
2606
+ jobInput = input;
2607
+ }
2608
+ else {
2609
+ throw new Error(`Job type ${productJob.type} not supported`);
2610
+ }
2611
+ const options = {};
2612
+ // Handle `delay` only if repeat.every is not defined
2613
+ if (!((_a = job.repeat) === null || _a === void 0 ? void 0 : _a.every)) {
2614
+ options.delay = delay;
2615
+ }
2616
+ // Add repeat config if defined
2617
+ if (job.repeat) {
2618
+ const { every, cron, tz, limit, endDate } = job.repeat;
2619
+ options.repeat = cron
2620
+ ? {
2621
+ cron,
2622
+ tz,
2623
+ limit,
2624
+ endDate,
2625
+ }
2626
+ : every
2627
+ ? {
2628
+ every,
2629
+ limit,
2630
+ endDate,
2631
+ }
2632
+ : undefined;
2633
+ }
2634
+ await this.queues.jobs.add(productJob.type, jobInput, options);
2635
+ }
2377
2636
  async sendExpoNotification(payload, device_tokens) {
2378
2637
  const message = {
2379
2638
  to: device_tokens,
@@ -2433,8 +2692,8 @@ class ProcessorService {
2433
2692
  const input = notification.input;
2434
2693
  try {
2435
2694
  //await this.intializeProduct(additional_logs);
2436
- const notificationEvent = this.productBuilderService.fetchNotification(event.split(":")[0]);
2437
- const message = this.productBuilderService.fetchNotificationMessage(event);
2695
+ const notificationEvent = await this.productBuilderService.fetchNotification(event.split(":")[0]);
2696
+ const message = await this.productBuilderService.fetchNotificationMessage(event);
2438
2697
  if (!message) {
2439
2698
  throw new Error(`Message ${event} not found`);
2440
2699
  }
@@ -2562,14 +2821,14 @@ class ProcessorService {
2562
2821
  name: 'Run Migration',
2563
2822
  };
2564
2823
  await this.intializeProduct(additional_logs);
2565
- const db = this.productBuilderService.fetchDatabase(dbTag);
2824
+ const db = await this.productBuilderService.fetchDatabase(dbTag);
2566
2825
  if (!db) {
2567
2826
  throw new Error('Database not found');
2568
2827
  }
2569
2828
  if (db.type === types_1.DatabaseTypes.MONGODB) {
2570
2829
  throw new Error(`${db.type} does not support migrations`);
2571
2830
  }
2572
- const migration = this.productBuilderService.fetchDatabaseMigration(tag);
2831
+ const migration = await this.productBuilderService.fetchDatabaseMigration(tag);
2573
2832
  if (!migration) {
2574
2833
  throw new Error('Database migration not found');
2575
2834
  }
@@ -2577,12 +2836,11 @@ class ProcessorService {
2577
2836
  if (!dbEnv) {
2578
2837
  throw new Error(`Environment ${env} not found`);
2579
2838
  }
2580
- const productEnv = this.fetchEnv(env, additional_logs);
2839
+ const productEnv = await this.fetchEnv(env, additional_logs);
2581
2840
  if (!productEnv.active) {
2582
2841
  throw new Error(`Environment ${env} is not active`);
2583
2842
  }
2584
- const product = this.productBuilderService.fetchProduct();
2585
- const migrations = this.productBuilderService.fetchDatabaseMigrations(dbTag);
2843
+ const migrations = await this.productBuilderService.fetchDatabaseMigrations(dbTag);
2586
2844
  //this.processEnv = productEnv;
2587
2845
  /* const check = migration.envs.find((migrationEnv) => migrationEnv.slug === env);
2588
2846
  if (!check) {
@@ -2594,7 +2852,7 @@ class ProcessorService {
2594
2852
  const migrationsToRun = (0, processor_utils_1.getMigrationsToRun)((0, processor_utils_1.structuredClone)(migrations), type, migrationTag, env);
2595
2853
  if (db.type === types_1.DatabaseTypes.POSTGRES) {
2596
2854
  const PostgresDBHandler = await (0, postgres_repo_1.loadPostgresHandler)();
2597
- const pgHandler = new PostgresDBHandler((0, processor_utils_1.decrypt)(dbEnv.connection_url, product.private_key));
2855
+ const pgHandler = new PostgresDBHandler((0, processor_utils_1.decrypt)(dbEnv.connection_url, this.productBuilderService.fetchPrivateKey()));
2598
2856
  for (const migrationToRun of migrationsToRun) {
2599
2857
  const envS = migration.envs.find((envT) => envT.slug === env && type === envT.type);
2600
2858
  if (envS && envS.status === types_1.MigrationStatus.PROCESSED) {
@@ -2663,7 +2921,7 @@ class ProcessorService {
2663
2921
  status: LogEventStatus.PROCESSING,
2664
2922
  });
2665
2923
 
2666
- const cloudFunction = this.productBuilderService.fetchFunction(data.event);
2924
+ const cloudFunction = await this.productBuilderService.fetchFunction(data.event);
2667
2925
 
2668
2926
  this.logService.add({
2669
2927
  ...this.baseLogs,
@@ -2730,10 +2988,9 @@ class ProcessorService {
2730
2988
  throw new Error(`Storage env for ${env.slug} not found`);
2731
2989
  }
2732
2990
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Fetch storage details - success', data: { storage }, status: types_1.LogEventStatus.SUCCESS }));
2733
- const product = this.productBuilderService.fetchProduct();
2734
2991
  let result;
2735
2992
  if (cache_tag && this.redisClient) {
2736
- const productCache = this.productBuilderService.fetchCache(cache_tag);
2993
+ const productCache = await this.productBuilderService.fetchCache(cache_tag);
2737
2994
  if (!productCache) {
2738
2995
  throw new Error('Invalid cache tag ');
2739
2996
  }
@@ -2741,7 +2998,7 @@ class ProcessorService {
2741
2998
  const check = await this.fetchFromCache({
2742
2999
  cache_tag,
2743
3000
  input: inputString,
2744
- privateKey: product.private_key,
3001
+ privateKey: this.productBuilderService.fetchPrivateKey(),
2745
3002
  expiry: productCache.expiry,
2746
3003
  }, additional_logs);
2747
3004
  if (check) {
@@ -2755,14 +3012,14 @@ class ProcessorService {
2755
3012
  input.mimeType = input.mimeType ? await this.generateStringValues(input.mimeType, '', additional_logs, []) : undefined;
2756
3013
  result = await this.processStorageRequest(data, input, storageEnv, additional_logs);
2757
3014
  if (cache_tag && this.redisClient) {
2758
- const productCache = this.productBuilderService.fetchCache(cache_tag);
3015
+ const productCache = await this.productBuilderService.fetchCache(cache_tag);
2759
3016
  if (!productCache) {
2760
3017
  throw new Error('Invalid cache tag ');
2761
3018
  }
2762
3019
  const inputString = JSON.stringify(input);
2763
3020
  await this.addToCache({
2764
3021
  input: inputString,
2765
- privateKey: product.private_key,
3022
+ privateKey: this.productBuilderService.fetchPrivateKey(),
2766
3023
  data: JSON.stringify(result),
2767
3024
  cache_tag,
2768
3025
  timestamp: Date.now(),
@@ -2783,7 +3040,6 @@ class ProcessorService {
2783
3040
  try {
2784
3041
  //await this.intializeProduct(additional_logs);
2785
3042
  const [database_tag, action_tag] = event.split(':');
2786
- const product = this.productBuilderService.fetchProduct();
2787
3043
  const database = await this.productBuilderService.fetchDatabase(database_tag);
2788
3044
  const databaseAction = await this.productBuilderService.fetchDatabaseAction(event);
2789
3045
  const databaseEnv = database.envs.find((el) => el.slug === env.slug);
@@ -2823,7 +3079,7 @@ class ProcessorService {
2823
3079
  }
2824
3080
  let result;
2825
3081
  if (cache_tag && this.redisClient) {
2826
- const productCache = this.productBuilderService.fetchCache(cache_tag);
3082
+ const productCache = await this.productBuilderService.fetchCache(cache_tag);
2827
3083
  if (!productCache) {
2828
3084
  throw new Error('Invalid cache tag ');
2829
3085
  }
@@ -2831,7 +3087,7 @@ class ProcessorService {
2831
3087
  const check = await this.fetchFromCache({
2832
3088
  cache_tag,
2833
3089
  input: inputString,
2834
- privateKey: product.private_key,
3090
+ privateKey: this.productBuilderService.fetchPrivateKey(),
2835
3091
  expiry: productCache.expiry,
2836
3092
  }, additional_logs);
2837
3093
  if (check) {
@@ -2862,7 +3118,7 @@ class ProcessorService {
2862
3118
  if (!PostgresDBHandler) {
2863
3119
  throw new Error(`Running in browser, postgres handler not loaded.`);
2864
3120
  }
2865
- const pgHandler = new PostgresDBHandler((0, processor_utils_1.decrypt)(databaseEnv.connection_url, this.productBuilderService.fetchProduct().private_key));
3121
+ const pgHandler = new PostgresDBHandler((0, processor_utils_1.decrypt)(databaseEnv.connection_url, this.productBuilderService.fetchPrivateKey()));
2866
3122
  if (databaseAction.type !== types_1.DatabaseActionTypes.AGGREGATE) {
2867
3123
  result = await pgHandler[databaseAction.type](databaseAction.data, template, input.data);
2868
3124
  }
@@ -2871,14 +3127,14 @@ class ProcessorService {
2871
3127
  // const result = this.processDBRequest(db_action, input, database_tag, databaseEnv, action_tag, additional_logs);
2872
3128
  await this.addToSuccessOutput(db_action, result, additional_logs);
2873
3129
  if (cache_tag && this.redisClient) {
2874
- const productCache = this.productBuilderService.fetchCache(cache_tag);
3130
+ const productCache = await this.productBuilderService.fetchCache(cache_tag);
2875
3131
  if (!productCache) {
2876
3132
  throw new Error('Invalid cache tag ');
2877
3133
  }
2878
3134
  const inputString = JSON.stringify(input);
2879
3135
  await this.addToCache({
2880
3136
  input: inputString,
2881
- privateKey: product.private_key,
3137
+ privateKey: this.productBuilderService.fetchPrivateKey(),
2882
3138
  data: JSON.stringify(result),
2883
3139
  cache_tag,
2884
3140
  timestamp: Date.now(),
@@ -2901,7 +3157,7 @@ class ProcessorService {
2901
3157
  try {
2902
3158
  await this.intializeProduct(additional_logs);
2903
3159
  const [brokerTag, topicTag] = event.split(':');
2904
- const broker = this.productBuilderService.fetchMessageBroker(brokerTag);
3160
+ const broker = await this.productBuilderService.fetchMessageBroker(brokerTag);
2905
3161
  if (!broker) {
2906
3162
  throw new Error(`Message Broker ${brokerTag} not found`);
2907
3163
  }
@@ -2909,7 +3165,7 @@ class ProcessorService {
2909
3165
  if (!brokerEnv) {
2910
3166
  throw new Error(`Broker env for ${env.slug} not found`);
2911
3167
  }
2912
- const topic = this.productBuilderService.fetchMessageBrokerTopic(event);
3168
+ const topic = await this.productBuilderService.fetchMessageBrokerTopic(event);
2913
3169
  if (!topic) {
2914
3170
  throw new Error(`Topic ${topicTag} not found in broker ${brokerTag}`);
2915
3171
  }
@@ -2950,7 +3206,7 @@ class ProcessorService {
2950
3206
  try {
2951
3207
  await this.intializeProduct(additional_logs);
2952
3208
  const [brokerTag, topicTag] = event.split(':');
2953
- const broker = this.productBuilderService.fetchMessageBroker(brokerTag);
3209
+ const broker = await this.productBuilderService.fetchMessageBroker(brokerTag);
2954
3210
  if (!broker) {
2955
3211
  throw new Error(`Message Broker ${brokerTag} not found`);
2956
3212
  }
@@ -2958,7 +3214,7 @@ class ProcessorService {
2958
3214
  if (!brokerEnv) {
2959
3215
  throw new Error(`Broker env for ${env.slug} not found`);
2960
3216
  }
2961
- const topic = this.productBuilderService.fetchMessageBrokerTopic(event);
3217
+ const topic = await this.productBuilderService.fetchMessageBrokerTopic(event);
2962
3218
  if (!topic) {
2963
3219
  throw new Error(`Topic ${topicTag} not found in broker ${brokerTag}`);
2964
3220
  }
@@ -3022,7 +3278,7 @@ class ProcessorService {
3022
3278
  const result = { url: await (0, storage_util_1.uploadBlobToCloud)({ data: input.buffer, destinationPath: input.fileName, config }) };
3023
3279
  try {
3024
3280
  await this.processorApiService.saveFileURL({
3025
- url: (0, processor_utils_1.encrypt)(result.url, this.productBuilderService.fetchProduct().private_key),
3281
+ url: (0, processor_utils_1.encrypt)(result.url, this.productBuilderService.fetchPrivateKey()),
3026
3282
  provider: storageEnv.type,
3027
3283
  product: this.productTag,
3028
3284
  process_id: this.process_id,
@@ -3083,12 +3339,12 @@ class ProcessorService {
3083
3339
  start: this.start,
3084
3340
  end: this.end,
3085
3341
  retryable,
3086
- result: (0, processor_utils_1.encrypt)(JSON.stringify(this.processingOutput), this.productBuilderService.fetchProduct().private_key),
3342
+ result: (0, processor_utils_1.encrypt)(JSON.stringify(this.processingOutput), this.productBuilderService.fetchPrivateKey()),
3087
3343
  process_id: this.process_id,
3088
3344
  feature_id: this.feature ? this.feature._id : null,
3089
3345
  product_id: this.productId,
3090
3346
  env: this.processEnv.slug,
3091
- input: (0, processor_utils_1.encrypt)(JSON.stringify(this.input), this.productBuilderService.fetchProduct().private_key),
3347
+ input: (0, processor_utils_1.encrypt)(JSON.stringify(this.input), this.productBuilderService.fetchPrivateKey()),
3092
3348
  }, this.getUserAccess());
3093
3349
  }
3094
3350
  async validateActionDataMappingInput(input, type) {
@@ -3120,7 +3376,7 @@ class ProcessorService {
3120
3376
  this.component = types_1.LogEventTypes.ACTION;
3121
3377
  try {
3122
3378
  // validate input do not allow $Sequence or $Length and $Size of $Input
3123
- this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.ACTION);
3379
+ await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.ACTION);
3124
3380
  this.input = action;
3125
3381
  this.start = Date.now();
3126
3382
  this.productTag = product_tag;
@@ -3134,9 +3390,10 @@ class ProcessorService {
3134
3390
  data: input,
3135
3391
  };
3136
3392
  await this.intializeProduct(additional_logs);
3393
+ await this.initializePricing(additional_logs, app);
3137
3394
  this.process_id = process_id;
3138
3395
  this.baseLogs.product_id = this.productId;
3139
- const productEnv = this.fetchEnv(env, additional_logs);
3396
+ const productEnv = await this.fetchEnv(env, additional_logs);
3140
3397
  this.processEnv = productEnv;
3141
3398
  if (!productEnv.active) {
3142
3399
  throw new Error(`Environment ${env} is not active`);
@@ -3158,7 +3415,8 @@ class ProcessorService {
3158
3415
  return result;
3159
3416
  }
3160
3417
  catch (e) {
3161
- this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute action - failed', data: { e }, status: types_1.LogEventStatus.FAIL }));
3418
+ console.log("ERRRRROORRRRR!!!!!!", e);
3419
+ this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Execute action - failed', data: { e: e.toString() }, status: types_1.LogEventStatus.FAIL }));
3162
3420
  this.end = Date.now();
3163
3421
  await this.writeResult(types_1.LogEventStatus.FAIL);
3164
3422
  await this.logService.publish();
@@ -3180,7 +3438,7 @@ class ProcessorService {
3180
3438
  name: 'Process database action',
3181
3439
  };
3182
3440
  try {
3183
- this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.DB_ACTION);
3441
+ await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.DB_ACTION);
3184
3442
  this.input = action;
3185
3443
  this.start = Date.now();
3186
3444
  this.productTag = product_tag;
@@ -3190,7 +3448,7 @@ class ProcessorService {
3190
3448
  await this.intializeProduct(additional_logs);
3191
3449
  this.baseLogs.product_id = this.productId;
3192
3450
  this.process_id = process_id;
3193
- const productEnv = this.fetchEnv(env, additional_logs);
3451
+ const productEnv = await this.fetchEnv(env, additional_logs);
3194
3452
  this.processEnv = productEnv;
3195
3453
  if (!productEnv.active) {
3196
3454
  throw new Error(`Environment ${env} is not active`);
@@ -3234,7 +3492,7 @@ class ProcessorService {
3234
3492
  name: 'Process Notification',
3235
3493
  };
3236
3494
  try {
3237
- this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.NOTIFICATION);
3495
+ await this.validateActionDataMappingInput(input, types_1.FeatureEventTypes.NOTIFICATION);
3238
3496
  this.input = action;
3239
3497
  this.start = Date.now();
3240
3498
  this.productTag = product_tag;
@@ -3244,7 +3502,7 @@ class ProcessorService {
3244
3502
  await this.intializeProduct(additional_logs);
3245
3503
  this.process_id = process_id;
3246
3504
  this.baseLogs.product_id = this.productId;
3247
- const productEnv = this.fetchEnv(env, additional_logs);
3505
+ const productEnv = await this.fetchEnv(env, additional_logs);
3248
3506
  this.processEnv = productEnv;
3249
3507
  if (!productEnv.active) {
3250
3508
  throw new Error(`Environment ${env} is not active`);
@@ -3276,7 +3534,7 @@ class ProcessorService {
3276
3534
  try {
3277
3535
  const data = await this.processorApiService.fetchRemoteCaches(payload, this.getUserAccess());
3278
3536
  return data.map((data) => {
3279
- data.value = (0, processor_utils_1.decrypt)(data.value, this.productBuilderService.fetchProduct().private_key);
3537
+ data.value = (0, processor_utils_1.decrypt)(data.value, this.productBuilderService.fetchPrivateKey());
3280
3538
  return data;
3281
3539
  });
3282
3540
  }
@@ -3344,6 +3602,33 @@ class ProcessorService {
3344
3602
  this.logService.add(Object.assign(Object.assign(Object.assign({}, this.baseLogs), additional_logs), { message: 'Cache Found', data: { key }, successful_execution: true, status: types_1.LogEventStatus.SUCCESS, cache_tag }));
3345
3603
  return (0, processor_utils_1.decrypt)(record.data, privateKey);
3346
3604
  }
3605
+ /**
3606
+ * Writes the healthcheck result to Redis cache for fast status retrieval.
3607
+ */
3608
+ async writeHealthcheckResultToCache(data, result) {
3609
+ if (!this.redisClient)
3610
+ return;
3611
+ const key = `healthcheck:${data.product}:${data.healthcheck}:${data.env}`;
3612
+ console.log("LOG TO CACHE", key, JSON.stringify(result));
3613
+ await this.redisClient.set(key, JSON.stringify(result));
3614
+ console.log();
3615
+ }
3616
+ /**
3617
+ * Fetches the latest healthcheck status for a product/env from Redis cache.
3618
+ */
3619
+ async getHealthcheckStatusFromCache(productTag, envSlug) {
3620
+ if (!this.redisClient)
3621
+ return null;
3622
+ const key = `healthcheck:${productTag}:${envSlug}`;
3623
+ const cached = await this.redisClient.get(key);
3624
+ return cached ? JSON.parse(cached) : null;
3625
+ }
3626
+ /**
3627
+ * Updates the healthcheck in the remote DB for a product with all envs' results.
3628
+ */
3629
+ async updateHealthcheckOnProcessor(productTag, envs) {
3630
+ return this.productBuilderService.updateHealthcheck(productTag, { envs });
3631
+ }
3347
3632
  }
3348
3633
  exports.default = ProcessorService;
3349
3634
  //# sourceMappingURL=processor.service.js.map