@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
@@ -22,13 +22,13 @@ const inputs_utils_create_1 = require("../../inputs/utils/inputs.utils.create");
22
22
  const enums_1 = require("../../types/enums");
23
23
  const productsBuilder_types_1 = require("../../types/productsBuilder.types");
24
24
  const validators_1 = require("../validators");
25
- const objects_utils_1 = require("../utils/objects.utils");
25
+ const objects_utils_1 = require("./utils/objects.utils");
26
26
  const processor_utils_1 = require("../../processor/utils/processor.utils");
27
- const create_productDatabaseAction_validator_1 = require("../validators/joi-validators/create.productDatabaseAction.validator");
28
- const update_productDatabaseAction_validator_1 = require("../validators/joi-validators/update.productDatabaseAction.validator");
27
+ const create_productDatabaseAction_validator_1 = __importDefault(require("../validators/joi-validators/create.productDatabaseAction.validator"));
28
+ const update_productDatabaseAction_validator_1 = __importDefault(require("../validators/joi-validators/update.productDatabaseAction.validator"));
29
29
  const create_productStorage_validator_1 = require("../validators/joi-validators/create.productStorage.validator");
30
30
  const inputs_types_1 = require("../../types/inputs.types");
31
- const string_utils_1 = require("../utils/string.utils");
31
+ const string_utils_1 = require("./utils/string.utils");
32
32
  const workspaceApi_service_1 = require("../../api/services/workspaceApi.service");
33
33
  const string_utils_2 = require("../../apps/utils/string.utils");
34
34
  const create_productDatabaseMigration_validator_1 = __importDefault(require("../validators/joi-validators/create.productDatabaseMigration.validator"));
@@ -36,13 +36,15 @@ const update_productDatabaseMigration_validator_1 = __importDefault(require("../
36
36
  const create_productNotificationMessage_validator_1 = __importDefault(require("../validators/joi-validators/create.productNotificationMessage.validator"));
37
37
  const create_productMessageBrokerTopic_validator_1 = __importDefault(require("../validators/joi-validators/create.productMessageBrokerTopic.validator"));
38
38
  const update_productMessageBrokerTopic_validator_1 = __importDefault(require("../validators/joi-validators/update.productMessageBrokerTopic.validator"));
39
+ const create_productGraphAction_validator_1 = __importDefault(require("../validators/joi-validators/create.productGraphAction.validator"));
40
+ const update_productGraphAction_validator_1 = __importDefault(require("../validators/joi-validators/update.productGraphAction.validator"));
39
41
  const update_productNotificationMessage_validator_1 = __importDefault(require("../validators/joi-validators/update.productNotificationMessage.validator"));
40
42
  const create_productNotification_validator_1 = require("../validators/joi-validators/create.productNotification.validator");
41
- const functions_utils_1 = require("../utils/functions.utils");
43
+ const functions_utils_1 = require("./utils/functions.utils");
42
44
  const objects_utils_2 = require("../../apps/utils/objects.utils");
43
45
  const webhooksApi_service_1 = require("../../api/services/webhooksApi.service");
44
46
  class ProductsBuilderService {
45
- constructor({ workspace_id, public_key, user_id, token, env_type, redis_client }) {
47
+ constructor({ workspace_id, public_key, user_id, token, env_type, redis_client, queues }) {
46
48
  this.workspace_id = workspace_id;
47
49
  this.public_key = public_key;
48
50
  this.user_id = user_id;
@@ -54,6 +56,150 @@ class ProductsBuilderService {
54
56
  this.appApi = new appApi_service_1.AppApiService(env_type, redis_client);
55
57
  this.inputsService = new inputs_service_1.default();
56
58
  this.thirdPartyApps = [];
59
+ if (redis_client) {
60
+ this.redisClient = redis_client;
61
+ // Start healthcheck workers automatically
62
+ //this.startHealthcheckWorkers();
63
+ }
64
+ if (queues) {
65
+ this.queues = queues;
66
+ }
67
+ }
68
+ fetchPrivateKey() {
69
+ return this.product.private_key;
70
+ }
71
+ fetchWorkspaceId() {
72
+ return this.product.workspace_id;
73
+ }
74
+ fetchProductId() {
75
+ return this.product._id;
76
+ }
77
+ async createHealthcheck(data) {
78
+ try {
79
+ await validators_1.CreateProductHealthcheckSchema.validateAsync(data);
80
+ if (!data.tag) {
81
+ throw new Error('tag field is required');
82
+ }
83
+ const exists = await this.fetchHealthcheck(data.app, data.tag);
84
+ if (!exists) {
85
+ const { app: access_tag, event: action } = data;
86
+ const app = await this.fetchThirdPartyAppByAccessTag(access_tag);
87
+ const version = app.versions.find((data) => data.tag === app.version);
88
+ if (!version) {
89
+ throw new Error(`Version ${app.version} not found`);
90
+ }
91
+ const event = version.actions.find((act) => act.tag === action);
92
+ data.envs = await Promise.all(data.envs.map(async (env) => {
93
+ const exists = await this.fetchEnv(env.slug);
94
+ if (!exists) {
95
+ throw new Error(`Env ${env.slug} does not exist`);
96
+ }
97
+ await this.validateActionDataInput({ input: env.input }, event, env.input, 0, 0);
98
+ env.input = (0, processor_utils_1.encrypt)(JSON.stringify(env.input), this.product.private_key);
99
+ console.log("INPUT", env);
100
+ return env;
101
+ }));
102
+ const envs = await this.fetchEnvs();
103
+ console.log("ENVS ===>>>>", envs);
104
+ console.log("DBENVS ====>>>>", data.envs);
105
+ envs.map((env) => {
106
+ const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
107
+ if (exists === -1) {
108
+ throw new Error(`Product env ${env.slug} is not defined, please provide details`);
109
+ }
110
+ });
111
+ console.log("UPDATING VALUE", data);
112
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { action: enums_1.RequestAction.CREATE, component: enums_1.ProductComponents.HEALTHCHECK }), this.getUserAccess());
113
+ data.envs.map(async (env) => {
114
+ const payload = {
115
+ app: data.app,
116
+ event: data.event,
117
+ input: env.input,
118
+ env: env.slug,
119
+ product: this.product.tag,
120
+ retries: data.retries,
121
+ };
122
+ const jobId = `healthcheck-${data.tag}`;
123
+ const job = await this.queues.health.getJob(jobId);
124
+ if (job) {
125
+ await job.remove();
126
+ }
127
+ await this.queues.health.add(jobId, payload, { jobId, repeat: { every: data.interval } });
128
+ });
129
+ }
130
+ }
131
+ catch (e) {
132
+ console.log(e);
133
+ throw e;
134
+ }
135
+ }
136
+ async updateHealthcheck(tag, data) {
137
+ try {
138
+ // 1. Fetch the existing healthcheck
139
+ const healthcheck = await this.fetchHealthcheck(data.app, tag);
140
+ if (!healthcheck) {
141
+ throw new Error(`Healthcheck with tag: ${tag} not found`);
142
+ }
143
+ // 2. Validate the incoming data
144
+ await validators_1.CreateProductHealthcheckSchema.validateAsync(data); // No Update schema, use Create
145
+ // 3. Check for tag conflicts
146
+ if (data.tag && data.tag !== tag && await this.fetchHealthcheck(data.app, data.tag)) {
147
+ throw new Error(`Healthcheck with tag ${data.tag} already exists`);
148
+ }
149
+ // 4. Validate and process envs
150
+ if (data.envs) {
151
+ data.envs = await Promise.all(data.envs.map(async (env) => {
152
+ const exists = await this.fetchEnv(env.slug);
153
+ if (!exists) {
154
+ throw new Error(`Env ${env.slug} does not exist`);
155
+ }
156
+ // Validate input if present
157
+ if (env.input) {
158
+ const app = await this.fetchThirdPartyAppByAccessTag(data.app);
159
+ const version = app.versions.find((v) => v.tag === app.version);
160
+ if (!version) {
161
+ throw new Error(`Version ${app.version} not found`);
162
+ }
163
+ const event = version.actions.find((act) => act.tag === data.event);
164
+ await this.validateActionDataInput({ input: env.input }, event, env.input, 0, 0);
165
+ env.input = (0, processor_utils_1.encrypt)(JSON.stringify(env.input), this.product.private_key);
166
+ }
167
+ return env;
168
+ }));
169
+ }
170
+ // 5. Ensure all product envs are covered
171
+ const envs = await this.fetchEnvs();
172
+ envs.map((env) => {
173
+ var _a;
174
+ const exists = (_a = data.envs) === null || _a === void 0 ? void 0 : _a.findIndex((dbEnv) => dbEnv.slug === env.slug);
175
+ if (exists === -1) {
176
+ throw new Error(`Product env ${env.slug} is not defined, please provide details`);
177
+ }
178
+ });
179
+ // 6. Update the healthcheck
180
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({}, healthcheck), data), { tag, component: enums_1.ProductComponents.HEALTHCHECK, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
181
+ }
182
+ catch (e) {
183
+ throw e;
184
+ }
185
+ }
186
+ async fetchHealthcheck(access_tag, tag, throwError = false) {
187
+ const healthchecks = await this.productApi.fetchProductComponents(this.product_id, 'healthcheck', this.getUserAccess());
188
+ const health = healthchecks.find((data) => data.tag === tag && data.app === access_tag);
189
+ if (!health && throwError)
190
+ throw new Error(`Healthcheck ${tag} not found`);
191
+ return health || null;
192
+ }
193
+ async fetchHealthchecks(access_tag, throwError = false) {
194
+ const healthchecks = await this.productApi.fetchProductComponents(this.product_id, 'healthcheck', this.getUserAccess());
195
+ const health = healthchecks.filter((data) => data.app === access_tag);
196
+ if (!health && throwError)
197
+ throw new Error(`Access tag ${access_tag} not found`);
198
+ return health;
199
+ }
200
+ async fetchProductHealthchecks() {
201
+ const healthchecks = await this.productApi.fetchProductComponents(this.product_id, 'healthcheck', this.getUserAccess());
202
+ return healthchecks;
57
203
  }
58
204
  async updateDataValidation(selector, update) {
59
205
  if (!selector.startsWith('$Data{') && !selector.startsWith('$Filter')) {
@@ -68,26 +214,27 @@ class ProductsBuilderService {
68
214
  if (stages.length < 3) {
69
215
  throw new Error(`Invalid selector ${selector}`);
70
216
  }
71
- const tag = stages[0];
72
- const type = stages[1];
217
+ const tag = String(stages[0]);
218
+ const type = String(stages[1]);
73
219
  let size = 2;
74
220
  let data;
75
221
  switch (type) {
76
222
  case productsBuilder_types_1.FeatureEventTypes.DB_ACTION:
77
- const action = this.fetchDatabaseAction(tag);
223
+ const action = await this.fetchDatabaseAction(tag);
78
224
  if (!action)
79
225
  throw new Error(`DB Action ${tag} not found`);
80
226
  data = useData ? action.data : action.filterData;
81
227
  break;
82
228
  case productsBuilder_types_1.FeatureEventTypes.NOTIFICATION:
83
229
  size = 3;
84
- if (!stages[3] || (stages[3] !== 'push' && stages[3] !== 'callback' && stages[3] !== 'email')) {
85
- throw new Error(`Invalid value ${stages[3]} in ${selector}, expected to be "push", "callback" or "email" in notification`);
230
+ const stage3Str = String(stages[3]);
231
+ if (!stages[3] || (stage3Str !== 'push' && stage3Str !== 'callback' && stage3Str !== 'email')) {
232
+ throw new Error(`Invalid value ${stage3Str} in ${selector}, expected to be "push", "callback" or "email" in notification`);
86
233
  }
87
- const notification = this.fetchNotificationMessage(tag);
234
+ const notification = await this.fetchNotificationMessage(tag);
88
235
  if (!notification)
89
236
  throw new Error(`Notification ${tag} not found`);
90
- if (stages[3] === 'push') {
237
+ if (stage3Str === 'push') {
91
238
  data = notification.push_notification_data;
92
239
  }
93
240
  if (stages[3] === 'callback') {
@@ -129,11 +276,11 @@ class ProductsBuilderService {
129
276
  await validators_1.CreateProductBuilderSchema.validateAsync(data);
130
277
  const exists = await this.checkIfProductExists(data.name);
131
278
  if (exists && (exists === null || exists === void 0 ? void 0 : exists._id)) {
132
- await this.initializeProduct(exists === null || exists === void 0 ? void 0 : exists._id);
279
+ // await this.initializeProduct(exists?._id);
133
280
  }
134
281
  else {
135
282
  const product = await this.createNewProduct(data);
136
- await this.initializeProduct(product._id);
283
+ // await this.initializeProduct(product._id);
137
284
  }
138
285
  }
139
286
  catch (e) {
@@ -147,7 +294,7 @@ class ProductsBuilderService {
147
294
  }
148
295
  async initializeProduct(product_id) {
149
296
  try {
150
- this.product = await this.productApi.fetchProduct(product_id, this.getUserAccess());
297
+ this.product = await this.productApi.initProduct(product_id, this.getUserAccess());
151
298
  this.product_id = product_id;
152
299
  }
153
300
  catch (e) {
@@ -156,7 +303,10 @@ class ProductsBuilderService {
156
303
  }
157
304
  async initializeProductByTag(tag) {
158
305
  try {
159
- this.product = await this.productApi.fetchProductByTag(tag, this.getUserAccess());
306
+ this.product = await this.productApi.initProduct(tag, this.getUserAccess());
307
+ if (!this.product) {
308
+ throw new Error(`Product with tag "${tag}" not found or failed to fetch`);
309
+ }
160
310
  this.product_id = this.product._id;
161
311
  }
162
312
  catch (e) {
@@ -169,7 +319,6 @@ class ProductsBuilderService {
169
319
  throw new Error('Product not initialized');
170
320
  await validators_1.CreateProductBuilderSchema.validateAsync(data);
171
321
  await this.productApi.updateProduct(this.product_id, Object.assign({}, data), this.getUserAccess());
172
- await this.initializeProduct(this.product_id);
173
322
  }
174
323
  catch (e) {
175
324
  throw e;
@@ -186,24 +335,49 @@ class ProductsBuilderService {
186
335
  return false;
187
336
  }
188
337
  }
189
- fetchProduct() {
338
+ async fetchProduct() {
190
339
  if (!this.product) {
191
340
  throw new Error('Product not yet initiated');
192
341
  }
193
- return this.product;
342
+ return await this.productApi.fetchProductByTag(this.product.tag, this.getUserAccess());
194
343
  }
195
- async createSession(data) {
344
+ async createSession(data, throwErrorIfExists = false) {
196
345
  try {
197
- // TODO: figure out a way to check if this has run before, halt if it has
198
- if (!this.fetchSession(data.tag)) {
199
- await validators_1.CreateProductSessionSchema.validateAsync(data);
200
- data.schema_data = (await this.inputsService.parseJson({
346
+ await validators_1.CreateProductSessionSchema.validateAsync(data);
347
+ if (!data.tag) {
348
+ throw new Error('tag field is required');
349
+ }
350
+ const exists = await this.fetchSession(data.tag);
351
+ if (!exists) {
352
+ if (!data.selector.startsWith('$Session{')) {
353
+ throw new Error('Selector should be in the format $Session{...}{key}');
354
+ }
355
+ const stages = (0, string_utils_1.extractStages)(data.selector);
356
+ let current = data.schema;
357
+ for (const stage of stages) {
358
+ if (current && typeof current === 'object' && stage in current) {
359
+ current = current[stage];
360
+ }
361
+ else {
362
+ throw new Error(`${data.selector} not found in event sample`);
363
+ }
364
+ }
365
+ if (current === null ||
366
+ typeof current === "undefined" ||
367
+ typeof current === "object") {
368
+ throw new Error("Selector value is not allowed to be an object|array|null|undefined");
369
+ }
370
+ data.schema_data = await this.inputsService.parseJson({
201
371
  data: data.schema,
202
- expected: inputs_types_1.ExpectedValues.PARSESAMPLE,
203
- category: enums_1.Categories.DATA,
204
- }));
205
- await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.SESSION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
206
- await this.initializeProduct(this.product_id);
372
+ expected: inputs_types_1.ExpectedValues.PARSESAMPLE
373
+ });
374
+ data.selectorValue = current;
375
+ const payload = Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.SESSION, action: enums_1.RequestAction.CREATE });
376
+ await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
377
+ }
378
+ else {
379
+ if (throwErrorIfExists)
380
+ throw new Error(`Session ${data.tag} already exists`);
207
381
  }
208
382
  }
209
383
  catch (e) {
@@ -212,13 +386,13 @@ class ProductsBuilderService {
212
386
  }
213
387
  async updateSession(tag, data) {
214
388
  try {
215
- const auth = this.fetchSession(tag);
216
- if (!auth) {
217
- throw new Error(`Session ${tag} not found`);
389
+ const session = await this.fetchSession(tag);
390
+ if (!session) {
391
+ throw new Error(`Session with tag: ${tag} not found`);
218
392
  }
219
393
  //const { _id } = auth;
220
394
  await validators_1.UpdateProductSessionSchema.validateAsync(data); // Change to update;
221
- if (data.tag && this.fetchEnv(data.tag) && data.tag !== tag) {
395
+ if (data.tag && this.fetchSession(data.tag) && data.tag !== tag) {
222
396
  throw new Error(`tag ${data.tag} is in use`); // TODO: also check on the backend
223
397
  }
224
398
  if (!data.tag) {
@@ -230,20 +404,40 @@ class ProductsBuilderService {
230
404
  expected: inputs_types_1.ExpectedValues.PARSESAMPLE,
231
405
  category: enums_1.Categories.DATA,
232
406
  }));
407
+ if (!data.selector) {
408
+ throw new Error('Selector is expected when updating schema');
409
+ }
233
410
  }
234
- await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, Object.assign(Object.assign({}, auth), data)), { component: enums_1.ProductComponents.SESSION, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
235
- await this.initializeProduct(this.product_id);
411
+ if (data.selector) {
412
+ const stages = (0, string_utils_1.extractStages)(data.selector);
413
+ let current = data.schema;
414
+ for (const stage of stages) {
415
+ if (current && typeof current === 'object' && stage in current) {
416
+ current = current[stage];
417
+ }
418
+ else {
419
+ throw new Error(`${data.selector} not found in event sample`);
420
+ }
421
+ }
422
+ if (current === null ||
423
+ typeof current === "undefined" ||
424
+ typeof current === "object") {
425
+ throw new Error("Selector value is not allowed to be an object|array|null|undefined");
426
+ }
427
+ }
428
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, Object.assign(Object.assign({}, session), data)), { component: enums_1.ProductComponents.SESSION, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
236
429
  }
237
430
  catch (e) {
238
431
  throw e;
239
432
  }
240
433
  }
241
- fetchSession(tag) {
242
- var _a;
243
- return (_a = this.product.sessions) === null || _a === void 0 ? void 0 : _a.find((auth) => auth.tag === tag);
434
+ async fetchSessions() {
435
+ const components = await this.productApi.fetchProductComponents(this.product_id, 'session', this.getUserAccess());
436
+ return components;
244
437
  }
245
- fetchSessions() {
246
- return this.product.sessions;
438
+ async fetchSession(tag) {
439
+ const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'session', tag, this.getUserAccess());
440
+ return component;
247
441
  }
248
442
  async createMessageBrokerTopic(data, throwErrorIfExists = false) {
249
443
  try {
@@ -257,16 +451,17 @@ class ProductsBuilderService {
257
451
  if (data.sample)
258
452
  data.sample = JSON.stringify(data.sample);
259
453
  await create_productMessageBrokerTopic_validator_1.default.validateAsync(data);
260
- const exists = this.fetchMessageBrokerTopic(data.tag);
261
- const broker = this.fetchMessageBroker(messageBrokerTag);
262
- (0, functions_utils_1.validateAWSSQSQueueUrl)(broker.envs, data.queueUrls);
454
+ const exists = await this.fetchMessageBrokerTopic(data.tag);
455
+ const broker = await this.fetchMessageBroker(messageBrokerTag);
456
+ if (broker) {
457
+ (0, functions_utils_1.validateAWSSQSQueueUrl)(broker.envs, data.queueUrls);
458
+ }
263
459
  data.tag = tag;
264
460
  if (!exists) {
265
461
  if (data.sample) {
266
462
  data.data = (await (0, string_utils_1.extractPlaceholders)(data.sample));
267
463
  }
268
464
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { messageBrokerTag, component: enums_1.ProductComponents.MESSAGEBROKER_TOPIC, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
269
- await this.initializeProduct(this.product_id);
270
465
  }
271
466
  else {
272
467
  if (throwErrorIfExists)
@@ -289,12 +484,12 @@ class ProductsBuilderService {
289
484
  if (!messageBrokerTag || !tag) {
290
485
  throw new Error(`tag is expected to be defined as "messageBrokr_tag:topic_tag"`);
291
486
  }
292
- const exists = this.fetchMessageBrokerTopic(data.tag);
487
+ const exists = await this.fetchMessageBrokerTopic(data.tag);
293
488
  if (!exists) {
294
489
  throw new Error(`Topic ${data.tag} not found`);
295
490
  }
296
- const broker = this.fetchMessageBroker(messageBrokerTag);
297
- if (data.queueUrls) {
491
+ const broker = await this.fetchMessageBroker(messageBrokerTag);
492
+ if (data.queueUrls && broker) {
298
493
  (0, functions_utils_1.validateAWSSQSQueueUrl)(broker.envs, data.queueUrls);
299
494
  }
300
495
  data.tag = tag;
@@ -303,7 +498,6 @@ class ProductsBuilderService {
303
498
  data.data = (await (0, string_utils_1.extractPlaceholders)(data.sample));
304
499
  }
305
500
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { messageBrokerTag, component: enums_1.ProductComponents.MESSAGEBROKER_TOPIC, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
306
- await this.initializeProduct(this.product_id);
307
501
  }
308
502
  else {
309
503
  throw new Error(`Message Broker Topic ${data.tag} not found`);
@@ -313,12 +507,12 @@ class ProductsBuilderService {
313
507
  throw e;
314
508
  }
315
509
  }
316
- fetchMessageBrokerTopic(tag, throwErrorIfExists = false) {
510
+ async fetchMessageBrokerTopic(tag, throwErrorIfExists = false) {
317
511
  const [messageBrokerTag, topicTag] = tag.split(':');
318
512
  if (!messageBrokerTag || !topicTag) {
319
513
  throw new Error(`tag is expected to be defined as "messageBroker_tag:topic_tag"`);
320
514
  }
321
- const messageBroker = this.product.messageBrokers.find((data) => data.tag === messageBrokerTag);
515
+ const messageBroker = await this.fetchMessageBroker(messageBrokerTag);
322
516
  if (!messageBroker)
323
517
  throw new Error(`MessageBroker ${messageBrokerTag} not found`);
324
518
  const topic = messageBroker.topics.find((data) => data.tag === topicTag);
@@ -326,8 +520,8 @@ class ProductsBuilderService {
326
520
  throw new Error(`MessageBroker topic ${tag} not found`);
327
521
  return topic;
328
522
  }
329
- fetchMessageBrokerTopics(messageBrokerTag) {
330
- const messageBroker = this.product.messageBrokers.find((data) => data.tag === messageBrokerTag);
523
+ async fetchMessageBrokerTopics(messageBrokerTag) {
524
+ const messageBroker = await this.fetchMessageBroker(messageBrokerTag);
331
525
  if (!messageBroker)
332
526
  throw new Error(`Message Broker ${messageBrokerTag} not found`);
333
527
  return messageBroker.topics;
@@ -364,7 +558,7 @@ class ProductsBuilderService {
364
558
  this.checkActionQuotaFallbackInput(action.body, option.input.body, input, 'body');
365
559
  }
366
560
  else {
367
- const feature = this.fetchFeature(option.event);
561
+ const feature = await this.fetchFeature(option.event);
368
562
  if (!feature) {
369
563
  throw new Error(`Feature ${option.event} not found`);
370
564
  }
@@ -454,7 +648,7 @@ class ProductsBuilderService {
454
648
  }
455
649
  else {
456
650
  // fetch feature
457
- const feature = this.fetchFeature(option.event);
651
+ const feature = await this.fetchFeature(option.event);
458
652
  if (!feature) {
459
653
  throw new Error(`Feature ${option.event} not found`);
460
654
  }
@@ -522,7 +716,7 @@ class ProductsBuilderService {
522
716
  if (!data.tag) {
523
717
  throw new Error('tag field is required');
524
718
  }
525
- if (!this.fetchQuota(data.tag)) {
719
+ if (!(await this.fetchQuota(data.tag))) {
526
720
  await validators_1.CreateProductQuotaSchema.validateAsync(data);
527
721
  await this.validateQuotaFallbackInputAndOutput(data, 'quota');
528
722
  data.total_quota = 0;
@@ -565,7 +759,7 @@ class ProductsBuilderService {
565
759
  }
566
760
  async updateQuota(tag, data) {
567
761
  try {
568
- const quota = this.fetchQuota(tag);
762
+ const quota = await this.fetchQuota(tag);
569
763
  if (quota) {
570
764
  await validators_1.UpdateProductQuotaSchema.validateAsync(data);
571
765
  if (data.options) {
@@ -613,18 +807,20 @@ class ProductsBuilderService {
613
807
  throw e;
614
808
  }
615
809
  }
616
- fetchQuota(tag) {
617
- return this.fetchQuotas().find((data) => data.tag === tag);
810
+ async fetchQuotas() {
811
+ const components = await this.productApi.fetchProductComponents(this.product_id, 'quota', this.getUserAccess());
812
+ return components;
618
813
  }
619
- fetchQuotas() {
620
- return this.product.quota;
814
+ async fetchQuota(tag) {
815
+ const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'quota', tag, this.getUserAccess());
816
+ return component;
621
817
  }
622
818
  async createFallback(data) {
623
819
  try {
624
820
  if (!data.tag) {
625
821
  throw new Error('tag field is required');
626
822
  }
627
- if (!this.fetchFallback(data.tag)) {
823
+ if (!(await this.fetchFallback(data.tag))) {
628
824
  await validators_1.CreateProductFallbackSchema.validateAsync(data);
629
825
  await this.validateQuotaFallbackInputAndOutput(data, 'fallback');
630
826
  await Promise.all(data.options.map(async (d) => {
@@ -664,7 +860,7 @@ class ProductsBuilderService {
664
860
  }
665
861
  async updateFallback(tag, data) {
666
862
  try {
667
- const fallback = this.fetchFallback(tag);
863
+ const fallback = await this.fetchFallback(tag);
668
864
  if (fallback) {
669
865
  await validators_1.UpdateProductFallbackSchema.validateAsync(data);
670
866
  if (data.options) {
@@ -709,19 +905,20 @@ class ProductsBuilderService {
709
905
  throw e;
710
906
  }
711
907
  }
712
- fetchFallback(tag) {
713
- return this.fetchFallbacks().find((data) => data.tag === tag);
908
+ async fetchFallbacks() {
909
+ const components = await this.productApi.fetchProductComponents(this.product_id, 'fallback', this.getUserAccess());
910
+ return components;
714
911
  }
715
- fetchFallbacks() {
716
- return this.product.fallback;
912
+ async fetchFallback(tag) {
913
+ const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'fallback', tag, this.getUserAccess());
914
+ return component;
717
915
  }
718
916
  async createEnv(data, throwErrorIfExists = false) {
719
917
  try {
720
918
  // TODO: figure out a way to check if this has run before, halt if it has
721
- if (!this.fetchEnv(data.slug)) {
919
+ if (!(await this.fetchEnv(data.slug))) {
722
920
  await validators_1.CreateProductEnvSchema.validateAsync(data);
723
921
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.ENV, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
724
- await this.initializeProduct(this.product_id);
725
922
  }
726
923
  else {
727
924
  if (throwErrorIfExists)
@@ -734,54 +931,53 @@ class ProductsBuilderService {
734
931
  }
735
932
  async updateEnv(slug, data) {
736
933
  try {
737
- const env = this.fetchEnv(slug, true);
934
+ const env = await this.fetchEnv(slug);
738
935
  if (!env) {
739
936
  throw new Error(`Env ${slug} not found`);
740
937
  }
741
938
  const { _id } = env;
742
939
  await validators_1.UpdateProductEnvSchema.validateAsync(data); // Change to update;
743
- if (data.slug && this.fetchEnv(data.slug)) {
940
+ if (data.slug && (await this.fetchEnv(data.slug))) {
744
941
  throw new Error(`slug ${slug} is in use`); // TODO: also check on the backend
745
942
  }
746
943
  if (!data.slug) {
747
944
  data.slug = slug;
748
945
  }
749
946
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, Object.assign(Object.assign({}, env), data)), { component: enums_1.ProductComponents.ENV, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
750
- await this.initializeProduct(this.product_id);
751
947
  }
752
948
  catch (e) {
753
949
  throw e;
754
950
  }
755
951
  }
756
- fetchEnvs() {
757
- return this.product.envs;
952
+ async fetchEnvs() {
953
+ const components = await this.productApi.fetchProductComponents(this.product_id, 'env', this.getUserAccess());
954
+ return components;
758
955
  }
759
- fetchEnv(slug, throwErrorIfExists = false) {
760
- const env = this.product.envs.find((data) => data.slug === slug);
761
- if (!env && throwErrorIfExists)
762
- throw new Error(`Env ${slug} not found`);
763
- return env;
956
+ async fetchEnv(slug) {
957
+ const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'env', slug, this.getUserAccess());
958
+ return component;
764
959
  }
765
960
  async createMessageBroker(data, throwErrorIfExists = false) {
766
- if (!this.fetchMessageBroker(data.tag, false)) {
961
+ if (!(await this.fetchMessageBroker(data.tag))) {
767
962
  await validators_1.CreateMessageBrokerSchema.validateAsync(data);
768
- data.envs = data.envs.map((env) => {
769
- const exists = this.fetchEnv(env.slug);
963
+ const processedEnvs = [];
964
+ for (const env of data.envs) {
965
+ const exists = await this.fetchEnv(env.slug);
770
966
  if (!exists) {
771
967
  throw new Error(`Env ${env.slug} does not exist`);
772
968
  }
773
- env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.fetchProduct().private_key);
774
- return env;
775
- });
776
- const envs = this.fetchEnvs();
777
- envs.map((env) => {
969
+ env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
970
+ processedEnvs.push(env);
971
+ }
972
+ data.envs = processedEnvs;
973
+ const envs = await this.fetchEnvs();
974
+ for (const env of envs) {
778
975
  const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
779
976
  if (exists === -1) {
780
977
  throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
781
978
  }
782
- });
979
+ }
783
980
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.MESSAGEBROKER, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
784
- await this.initializeProduct(this.product_id);
785
981
  }
786
982
  else {
787
983
  if (throwErrorIfExists)
@@ -790,30 +986,32 @@ class ProductsBuilderService {
790
986
  }
791
987
  async updateMessageBroker(tag, data) {
792
988
  try {
793
- const messageBroker = this.fetchMessageBroker(tag);
989
+ const messageBroker = await this.fetchMessageBroker(tag);
794
990
  if (!messageBroker) {
795
991
  throw new Error(`Broker ${tag} not found`);
796
992
  }
797
993
  const { _id, envs } = messageBroker;
798
994
  await validators_1.UpdateMessageBrokerSchema.validateAsync(data); // Change to update;
799
- if (data.tag && this.fetchMessageBroker(data.tag)) {
995
+ if (data.tag && (await this.fetchMessageBroker(data.tag))) {
800
996
  throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
801
997
  }
802
998
  console.log('2', data.envs);
803
- data.envs = data.envs.map((env) => {
804
- const exists = this.fetchEnv(env.slug);
999
+ const processedEnvs = [];
1000
+ for (const env of data.envs) {
1001
+ const exists = await this.fetchEnv(env.slug);
805
1002
  if (!exists) {
806
1003
  throw new Error(`Env ${env.slug} does not exist`);
807
1004
  }
808
1005
  if (env.config)
809
- env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.fetchProduct().private_key);
810
- return env;
811
- });
1006
+ env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
1007
+ processedEnvs.push(env);
1008
+ }
1009
+ data.envs = processedEnvs;
812
1010
  const overwrite = [];
813
1011
  const newEnvs = [];
814
- data.envs.map((dataEnv) => {
1012
+ for (const dataEnv of data.envs) {
815
1013
  const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
816
- if (!this.fetchEnv(dataEnv.slug)) {
1014
+ if (!(await this.fetchEnv(dataEnv.slug))) {
817
1015
  throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
818
1016
  }
819
1017
  if (exists === -1) {
@@ -824,48 +1022,51 @@ class ProductsBuilderService {
824
1022
  }
825
1023
  else {
826
1024
  if (envs[exists].config) {
827
- envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.fetchProduct().private_key);
1025
+ envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.product.private_key);
828
1026
  }
829
1027
  overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
830
1028
  }
831
- });
1029
+ }
832
1030
  const unchanged = [];
833
- envs.map((env) => {
1031
+ for (const env of envs) {
834
1032
  const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
835
1033
  const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
836
1034
  if (!newEnv && !overwriteEnv) {
837
1035
  if (env.config) {
838
- env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.fetchProduct().private_key);
1036
+ env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
839
1037
  }
840
1038
  unchanged.push(env);
841
1039
  }
842
- });
1040
+ }
843
1041
  data.envs = [...unchanged, ...overwrite, ...newEnvs];
844
1042
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({ _id }, messageBroker), data), { component: enums_1.ProductComponents.MESSAGEBROKER, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
845
- await this.initializeProduct(this.product_id);
846
1043
  }
847
1044
  catch (e) {
848
1045
  throw e;
849
1046
  }
850
1047
  }
851
- fetchMessageBroker(tag, throwErrorIfExists = false) {
852
- const messageBroker = this.product.messageBrokers.find((data) => data.tag === tag);
853
- if (!messageBroker && throwErrorIfExists)
854
- throw new Error(`Message Broker ${tag} not found`);
1048
+ async fetchMessageBrokers() {
1049
+ const components = await this.productApi.fetchProductComponents(this.product_id, 'message_broker', this.getUserAccess());
1050
+ components.map((broker) => {
1051
+ return broker.envs.map((env) => {
1052
+ if (typeof env.config === 'string') {
1053
+ env.config = JSON.parse((0, processor_utils_1.decrypt)(String(env.config), this.product.private_key));
1054
+ }
1055
+ });
1056
+ });
1057
+ return components;
1058
+ }
1059
+ async fetchMessageBroker(tag) {
1060
+ const messageBroker = await this.productApi.fetchProductComponentByTag(this.product_id, 'message_broker', tag, this.getUserAccess());
855
1061
  if (messageBroker) {
856
- messageBroker.envs.map((broker) => {
857
- if (typeof broker.config === 'string') {
858
- broker.config = JSON.parse((0, processor_utils_1.decrypt)(String(broker.config), this.fetchProduct().private_key));
1062
+ messageBroker.envs.map((env) => {
1063
+ if (typeof env.config === 'string') {
1064
+ env.config = JSON.parse((0, processor_utils_1.decrypt)(String(env.config), this.product.private_key));
859
1065
  }
860
1066
  });
861
1067
  }
862
1068
  return messageBroker;
863
1069
  }
864
- fetchMessageBrokers() {
865
- return this.product.messageBrokers.map((broker) => {
866
- return this.fetchMessageBroker(broker.tag);
867
- });
868
- }
869
1070
  async fetchStorageFiles(filter) {
870
1071
  try {
871
1072
  const result = await this.productApi.fetchProductStorageFiles(Object.assign(Object.assign({}, filter), { product: this.product.tag }), this.getUserAccess());
@@ -883,11 +1084,28 @@ class ProductsBuilderService {
883
1084
  throw (e);
884
1085
  }
885
1086
  }
1087
+ async fetchSessionUsers(filter) {
1088
+ try {
1089
+ const result = await this.productApi.fetchProductSessionUsers(Object.assign(Object.assign({}, filter), { product: this.product.tag }), this.getUserAccess());
1090
+ if (!result)
1091
+ return [];
1092
+ return result.map((res) => {
1093
+ delete res._id;
1094
+ delete res.workspace_id;
1095
+ delete res.__v;
1096
+ return res;
1097
+ });
1098
+ }
1099
+ catch (e) {
1100
+ throw (e);
1101
+ }
1102
+ }
886
1103
  async createStorage(data, throwErrorIfExists = false) {
887
- if (!this.fetchStorage(data.tag, false)) {
1104
+ if (!(await this.fetchStorage(data.tag))) {
888
1105
  await create_productStorage_validator_1.CreateProductStorageSchema.validateAsync(data);
889
- data.envs = data.envs.map((env) => {
890
- const exists = this.fetchEnv(env.slug);
1106
+ const processedEnvs = [];
1107
+ for (const env of data.envs) {
1108
+ const exists = await this.fetchEnv(env.slug);
891
1109
  if (!exists) {
892
1110
  throw new Error(`Env ${env.slug} does not exist`);
893
1111
  }
@@ -895,18 +1113,18 @@ class ProductsBuilderService {
895
1113
  // @ts-ignore
896
1114
  //env.config.config.private_key = gcpPKCSConvert(env.config.config.private_key)
897
1115
  }
898
- env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.fetchProduct().private_key);
899
- return env;
900
- });
901
- const envs = this.fetchEnvs();
902
- envs.map((env) => {
1116
+ env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
1117
+ processedEnvs.push(env);
1118
+ }
1119
+ data.envs = processedEnvs;
1120
+ const envs = await this.fetchEnvs();
1121
+ for (const env of envs) {
903
1122
  const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
904
1123
  if (exists === -1) {
905
1124
  throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
906
1125
  }
907
- });
1126
+ }
908
1127
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.STORAGE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
909
- await this.initializeProduct(this.product_id);
910
1128
  }
911
1129
  else {
912
1130
  if (throwErrorIfExists)
@@ -915,7 +1133,7 @@ class ProductsBuilderService {
915
1133
  }
916
1134
  async updateStorage(tag, data) {
917
1135
  try {
918
- const storage = this.fetchStorage(tag);
1136
+ const storage = await this.fetchStorage(tag);
919
1137
  if (!storage) {
920
1138
  throw new Error(`Storage ${tag} not found`);
921
1139
  }
@@ -924,8 +1142,8 @@ class ProductsBuilderService {
924
1142
  if (data.tag && this.fetchStorage(data.tag)) {
925
1143
  throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
926
1144
  }
927
- data.envs = data.envs.map((env) => {
928
- const exists = this.fetchEnv(env.slug);
1145
+ data.envs = await Promise.all(data.envs.map(async (env) => {
1146
+ const exists = await this.fetchEnv(env.slug);
929
1147
  if (!exists) {
930
1148
  throw new Error(`Env ${env.slug} does not exist`);
931
1149
  }
@@ -934,9 +1152,9 @@ class ProductsBuilderService {
934
1152
  //env.config.config.private_key = gcpPKCSConvert(env.config.config.private_key)
935
1153
  }
936
1154
  if (env.config)
937
- env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.fetchProduct().private_key);
1155
+ env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
938
1156
  return env;
939
- });
1157
+ }));
940
1158
  const overwrite = [];
941
1159
  const newEnvs = [];
942
1160
  data.envs.map((dataEnv) => {
@@ -952,7 +1170,7 @@ class ProductsBuilderService {
952
1170
  }
953
1171
  else {
954
1172
  if (envs[exists].config) {
955
- envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.fetchProduct().private_key);
1173
+ envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.product.private_key);
956
1174
  }
957
1175
  overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
958
1176
  }
@@ -963,37 +1181,40 @@ class ProductsBuilderService {
963
1181
  const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
964
1182
  if (!newEnv && !overwriteEnv) {
965
1183
  if (env.config) {
966
- env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.fetchProduct().private_key);
1184
+ env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.product.private_key);
967
1185
  }
968
1186
  unchanged.push(env);
969
1187
  }
970
1188
  });
971
1189
  data.envs = [...unchanged, ...overwrite, ...newEnvs];
972
1190
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({ _id }, storage), data), { component: enums_1.ProductComponents.STORAGE, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
973
- await this.initializeProduct(this.product_id);
974
1191
  }
975
1192
  catch (e) {
976
1193
  throw e;
977
1194
  }
978
1195
  }
979
- fetchStorage(tag, throwErrorIfExists = false) {
980
- const storage = this.product.storage.find((data) => data.tag === tag);
981
- if (!storage && throwErrorIfExists)
982
- throw new Error(`Storage ${tag} not found`);
1196
+ async fetchStorages() {
1197
+ const components = await this.productApi.fetchProductComponents(this.product_id, 'storage', this.getUserAccess());
1198
+ components.map((storage) => {
1199
+ storage.envs.map((env) => {
1200
+ if (typeof env.config === 'string') {
1201
+ env.config = JSON.parse((0, processor_utils_1.decrypt)(String(env.config), this.product.private_key));
1202
+ }
1203
+ });
1204
+ });
1205
+ return components;
1206
+ }
1207
+ async fetchStorage(tag) {
1208
+ const storage = await this.productApi.fetchProductComponentByTag(this.product_id, 'storage', tag, this.getUserAccess());
983
1209
  if (storage) {
984
1210
  storage.envs.map((store) => {
985
1211
  if (typeof store.config === 'string') {
986
- store.config = JSON.parse((0, processor_utils_1.decrypt)(String(store.config), this.fetchProduct().private_key));
1212
+ store.config = JSON.parse((0, processor_utils_1.decrypt)(String(store.config), this.product.private_key));
987
1213
  }
988
1214
  });
989
1215
  }
990
1216
  return storage;
991
1217
  }
992
- fetchStorages() {
993
- return this.product.storage.map((storage) => {
994
- return this.fetchStorage(storage.tag);
995
- });
996
- }
997
1218
  async validateAppData(appData, app) {
998
1219
  // TODO:
999
1220
  const { envs } = app;
@@ -1015,6 +1236,9 @@ class ProductsBuilderService {
1015
1236
  }
1016
1237
  }
1017
1238
  validateVariablesValues(variables, appVariables) {
1239
+ if (!variables) {
1240
+ variables = [];
1241
+ }
1018
1242
  if (appVariables && appVariables.length) {
1019
1243
  appVariables.map((data) => {
1020
1244
  const find = variables.find((value) => value.key === data.key);
@@ -1031,7 +1255,7 @@ class ProductsBuilderService {
1031
1255
  const { envs: appEnvs } = version;
1032
1256
  return envs.map((env) => {
1033
1257
  const { auth } = env;
1034
- this.fetchEnv(env.product_env_slug, true);
1258
+ this.fetchEnv(env.product_env_slug);
1035
1259
  const appEnv = appEnvs.find((appEnv) => appEnv.slug === env.app_env_slug);
1036
1260
  if (!appEnv) {
1037
1261
  throw new Error(`app_slug ${env.app_env_slug} not found`);
@@ -1121,10 +1345,10 @@ class ProductsBuilderService {
1121
1345
  });
1122
1346
  (0, inputs_utils_create_1.validateInputSchema)(queryValues, querySchema);
1123
1347
  }
1124
- const updateData = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.fetchProduct().private_key);
1348
+ const updateData = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.product.private_key);
1125
1349
  let updateValues = null;
1126
1350
  if (exists.setup_type === enums_1.AuthTypes.TOKEN) {
1127
- updateValues = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.fetchProduct().private_key);
1351
+ updateValues = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.product.private_key);
1128
1352
  }
1129
1353
  return { data: updateData, values: updateValues };
1130
1354
  }
@@ -1157,8 +1381,10 @@ class ProductsBuilderService {
1157
1381
  throw new Error(`App ${app.access_tag} not found`);
1158
1382
  }
1159
1383
  const cleanedAppData = await this.validateAppData(appData, app);
1160
- await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, cleanedAppData), { component: enums_1.ProductComponents.APP, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
1161
- await this.initializeProduct(this.product_id);
1384
+ if (!cleanedAppData.pricing_tag) {
1385
+ cleanedAppData.pricing_tag = `${appData.tag}:${productsBuilder_types_1.PricingTag.FREE}`;
1386
+ }
1387
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, cleanedAppData), { app_tag: appData.tag, component: enums_1.ProductComponents.APP, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
1162
1388
  }
1163
1389
  else {
1164
1390
  if (throwErrorIfExists)
@@ -1189,7 +1415,7 @@ class ProductsBuilderService {
1189
1415
  }
1190
1416
  async updateApp(access_tag, data) {
1191
1417
  try {
1192
- const app = this.fetchApp(access_tag);
1418
+ const app = await this.fetchApp(access_tag);
1193
1419
  if (!app) {
1194
1420
  throw new Error(`App ${access_tag} not found`);
1195
1421
  }
@@ -1205,17 +1431,18 @@ class ProductsBuilderService {
1205
1431
  throw new Error(`access_tag ${access_tag} is in use`); // TODO: also check on the backend
1206
1432
  }*/
1207
1433
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id }, data), { access_tag, component: enums_1.ProductComponents.APP, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
1208
- await this.initializeProduct(this.product_id);
1209
1434
  }
1210
1435
  catch (e) {
1211
1436
  throw e;
1212
1437
  }
1213
1438
  }
1214
- fetchApps() {
1215
- return this.product.apps;
1439
+ async fetchApps() {
1440
+ const app = await this.productApi.fetchProductComponents(this.product_id, 'app', this.getUserAccess());
1441
+ return app;
1216
1442
  }
1217
- fetchApp(tag, throwErrorIfExists = false) {
1218
- const app = this.product.apps.find((data) => data.access_tag === tag);
1443
+ async fetchApp(tag, throwErrorIfExists = false) {
1444
+ const apps = await this.fetchApps();
1445
+ const app = apps.find((data) => data.app_tag === tag || data.access_tag === tag);
1219
1446
  if (!app && throwErrorIfExists)
1220
1447
  throw new Error(`App ${tag} not found`);
1221
1448
  return app;
@@ -1223,10 +1450,10 @@ class ProductsBuilderService {
1223
1450
  async createFunction(data, throwErrorIfExists = false) {
1224
1451
  try {
1225
1452
  // TODO: figure out a way to check if this has run before, halt if it has
1226
- if (!this.fetchFunction(data.tag)) {
1453
+ if (!(await this.fetchFunction(data.tag))) {
1227
1454
  await validators_1.CreateProductFunctionSchema.validateAsync(data);
1228
1455
  data.envs.map((env) => {
1229
- env.auth = (0, processor_utils_1.encrypt)(JSON.stringify(env.auth), this.fetchProduct().private_key);
1456
+ env.auth = (0, processor_utils_1.encrypt)(JSON.stringify(env.auth), this.product.private_key);
1230
1457
  });
1231
1458
  data.sample_data = (await this.inputsService.parseJson({
1232
1459
  data: data.sample,
@@ -1239,7 +1466,6 @@ class ProductsBuilderService {
1239
1466
  category: enums_1.Categories.DATA,
1240
1467
  }));
1241
1468
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.FUNCTION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
1242
- await this.initializeProduct(this.product_id);
1243
1469
  }
1244
1470
  else {
1245
1471
  if (throwErrorIfExists)
@@ -1252,37 +1478,35 @@ class ProductsBuilderService {
1252
1478
  }
1253
1479
  async updateFunction(tag, data) {
1254
1480
  try {
1255
- const func = this.fetchFunction(tag);
1481
+ const func = await this.fetchFunction(tag);
1256
1482
  if (!func) {
1257
1483
  throw new Error(`Function ${tag} not found`);
1258
1484
  }
1259
1485
  const { _id } = func;
1260
1486
  await validators_1.UpdateProductFunctionSchema.validateAsync(data); // Change to update;
1261
- if (data.tag && this.fetchFunction(data.tag)) {
1487
+ if (data.tag && await this.fetchFunction(data.tag)) {
1262
1488
  throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
1263
1489
  }
1264
1490
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({ _id }, func), data), { component: enums_1.ProductComponents.FUNCTION, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
1265
- await this.initializeProduct(this.product_id);
1266
1491
  }
1267
1492
  catch (e) {
1268
1493
  throw e;
1269
1494
  }
1270
1495
  }
1271
- fetchFunctions() {
1272
- return this.product.functions;
1496
+ async fetchFunctions() {
1497
+ const components = await this.productApi.fetchProductComponents(this.product_id, 'function', this.getUserAccess());
1498
+ return components;
1273
1499
  }
1274
- fetchFunction(tag) {
1275
- const func = this.product.functions.find((data) => data.tag === tag);
1276
- // if (!func) throw new Error(`Function ${tag} not found`);
1277
- return func;
1500
+ async fetchFunction(tag) {
1501
+ const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'function', tag, this.getUserAccess());
1502
+ return component;
1278
1503
  }
1279
1504
  async createCache(data, throwErrorIfExists = false) {
1280
1505
  try {
1281
1506
  // TODO: figure out a way to check if this has run before, halt if it has
1282
- if (!this.fetchCache(data.tag)) {
1507
+ if (!(await this.fetchCache(data.tag))) {
1283
1508
  await validators_1.CreateProductCacheSchema.validateAsync(data);
1284
1509
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.CACHE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
1285
- await this.initializeProduct(this.product_id);
1286
1510
  }
1287
1511
  else {
1288
1512
  if (throwErrorIfExists)
@@ -1295,62 +1519,59 @@ class ProductsBuilderService {
1295
1519
  }
1296
1520
  async updateCache(tag, data) {
1297
1521
  try {
1298
- const cache = this.fetchCache(tag);
1522
+ const cache = await this.fetchCache(tag);
1299
1523
  if (!cache) {
1300
1524
  throw new Error(`Cache ${tag} not found`);
1301
1525
  }
1302
1526
  const { _id } = cache;
1303
1527
  await validators_1.UpdateProductCacheSchema.validateAsync(data); // Change to update;
1304
- if (data.tag && this.fetchCache(data.tag)) {
1528
+ if (data.tag && await this.fetchCache(data.tag)) {
1305
1529
  throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
1306
1530
  }
1307
1531
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id }, data), { component: enums_1.ProductComponents.CACHE, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
1308
- await this.initializeProduct(this.product_id);
1309
1532
  }
1310
1533
  catch (e) {
1311
1534
  throw e;
1312
1535
  }
1313
1536
  }
1314
- fetchCache(tag, throwErrorIfExists = false) {
1315
- const cache = this.product.caches.find((data) => data.tag === tag);
1316
- if (!cache && throwErrorIfExists)
1317
- throw new Error(`Cache ${tag} not found`);
1318
- return cache;
1537
+ async fetchCaches() {
1538
+ const components = await this.productApi.fetchProductComponents(this.product_id, 'cache', this.getUserAccess());
1539
+ return components;
1319
1540
  }
1320
- fetchCaches() {
1321
- return this.product.caches;
1541
+ async fetchCache(tag) {
1542
+ const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'cache', tag, this.getUserAccess());
1543
+ return component;
1322
1544
  }
1323
1545
  async createNotification(data, throwErrorIfExists = false) {
1324
1546
  try {
1325
1547
  // TODO: figure out a way to check if this has run before, halt if it has
1326
- if (!this.fetchNotification(data.tag)) {
1548
+ if (!(await this.fetchNotification(data.tag))) {
1327
1549
  await validators_1.CreateProductNotificationSchema.validateAsync(data);
1328
- const envs = this.fetchEnvs();
1329
- envs.map((env) => {
1550
+ const envs = await this.fetchEnvs();
1551
+ for (const env of envs) {
1330
1552
  const exists = data.envs.findIndex((nEnv) => nEnv.slug === env.slug);
1331
1553
  if (exists === -1) {
1332
1554
  throw new Error(`Notification for environment ${env.slug} is not defined, please provide the environment details`);
1333
1555
  }
1334
- });
1556
+ }
1335
1557
  for (let i = 0; i < data.envs.length; i++) {
1336
1558
  const updates = {
1337
1559
  push_notifications: data.envs[i].push_notifications
1338
- ? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].push_notifications), this.fetchProduct().private_key)
1560
+ ? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].push_notifications), this.product.private_key)
1339
1561
  : undefined,
1340
1562
  emails: data.envs[i].emails
1341
- ? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].emails), this.fetchProduct().private_key)
1563
+ ? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].emails), this.product.private_key)
1342
1564
  : undefined,
1343
1565
  callbacks: data.envs[i].callbacks
1344
- ? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].callbacks), this.fetchProduct().private_key)
1566
+ ? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].callbacks), this.product.private_key)
1345
1567
  : undefined,
1346
1568
  sms: data.envs[i].sms
1347
- ? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].sms), this.fetchProduct().private_key)
1569
+ ? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].sms), this.product.private_key)
1348
1570
  : undefined,
1349
1571
  };
1350
1572
  data.envs[i] = Object.assign(Object.assign({}, data.envs[i]), updates);
1351
1573
  }
1352
1574
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.NOTIFICATION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
1353
- await this.initializeProduct(this.product_id);
1354
1575
  }
1355
1576
  else {
1356
1577
  if (throwErrorIfExists)
@@ -1371,7 +1592,7 @@ class ProductsBuilderService {
1371
1592
  if (!notificationTag || !tag) {
1372
1593
  throw new Error(`tag is expected to be defined as "notification_tag:message_tag"`);
1373
1594
  }
1374
- const exists = this.fetchNotificationMessage(data.tag);
1595
+ const exists = await this.fetchNotificationMessage(data.tag);
1375
1596
  data.tag = tag;
1376
1597
  if (!exists) {
1377
1598
  if (!data.email && !data.push_notification && !data.callback) {
@@ -1408,7 +1629,6 @@ class ProductsBuilderService {
1408
1629
  data.sms_data = (0, string_utils_1.extractPlaceholders)(data.sms, '');
1409
1630
  }
1410
1631
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { notificationTag, component: enums_1.ProductComponents.NOTIFICATION_MESSAGE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
1411
- await this.initializeProduct(this.product_id);
1412
1632
  }
1413
1633
  else {
1414
1634
  if (throwErrorIfExists)
@@ -1419,12 +1639,12 @@ class ProductsBuilderService {
1419
1639
  throw e;
1420
1640
  }
1421
1641
  }
1422
- fetchNotificationMessage(tag, throwErrorIfExists = false) {
1642
+ async fetchNotificationMessage(tag, throwErrorIfExists = false) {
1423
1643
  const [notificationTag, messageTag] = tag.split(':');
1424
1644
  if (!notificationTag || !messageTag) {
1425
1645
  throw new Error(`tag is expected to be defined as "notification_tag:message_tag"`);
1426
1646
  }
1427
- const notification = this.fetchNotification(notificationTag);
1647
+ const notification = await this.fetchNotification(notificationTag);
1428
1648
  if (!notification)
1429
1649
  throw new Error(`Notification ${notificationTag} not found`);
1430
1650
  const message = notification.messages.find((data) => data.tag === messageTag);
@@ -1432,8 +1652,8 @@ class ProductsBuilderService {
1432
1652
  throw new Error(`Notification message ${tag} not found`);
1433
1653
  return message;
1434
1654
  }
1435
- fetchNotificationMessages(notificationTag, throwErrorIfExists = false) {
1436
- const notification = this.product.notifications.find((data) => data.tag === notificationTag);
1655
+ async fetchNotificationMessages(notificationTag, throwErrorIfExists = false) {
1656
+ const notification = await this.fetchNotification(notificationTag); //this.product.notifications.find((data: IProductNotification) => data.tag === notificationTag);
1437
1657
  if (!notification)
1438
1658
  throw new Error(`Notification ${notificationTag} not found`);
1439
1659
  return notification.messages;
@@ -1486,7 +1706,6 @@ class ProductsBuilderService {
1486
1706
  const payload = Object.assign(Object.assign(Object.assign({}, message), data), { notificationTag, component: enums_1.ProductComponents.NOTIFICATION_MESSAGE, action: enums_1.RequestAction.UPDATE });
1487
1707
  // Update product and reinitialize
1488
1708
  await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
1489
- await this.initializeProduct(this.product_id);
1490
1709
  }
1491
1710
  catch (error) {
1492
1711
  throw error;
@@ -1494,21 +1713,25 @@ class ProductsBuilderService {
1494
1713
  }
1495
1714
  async updateNotification(tag, data) {
1496
1715
  try {
1497
- const { _id, envs } = this.fetchNotification(tag);
1498
- if (data.tag && tag !== data.tag && this.fetchNotification(data.tag)) {
1716
+ const notificationResult = await this.fetchNotification(tag);
1717
+ if (!notificationResult) {
1718
+ throw new Error(`Notification with tag ${tag} not found`);
1719
+ }
1720
+ const { _id, envs } = notificationResult;
1721
+ if (data.tag && tag !== data.tag && (await this.fetchNotification(data.tag))) {
1499
1722
  throw new Error(`Notification of tag ${data.tag} already exists`);
1500
1723
  }
1501
1724
  await validators_1.UpdateProductNotificationSchema.validateAsync(data); // Change to update;
1502
- let notification = this.fetchNotification(tag);
1725
+ let notification = await this.fetchNotification(tag);
1503
1726
  if (!notification) {
1504
1727
  throw new Error(`Notification with tag ${tag} not found`);
1505
1728
  }
1506
1729
  if (data.envs) {
1507
1730
  const overwrite = [];
1508
1731
  const newEnvs = [];
1509
- data.envs.map(async (dataEnv) => {
1732
+ for (const dataEnv of data.envs) {
1510
1733
  const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
1511
- if (!this.fetchEnv(dataEnv.slug)) {
1734
+ if (!(await this.fetchEnv(dataEnv.slug))) {
1512
1735
  throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
1513
1736
  }
1514
1737
  if (exists === -1) {
@@ -1518,70 +1741,74 @@ class ProductsBuilderService {
1518
1741
  else {
1519
1742
  overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
1520
1743
  }
1521
- });
1744
+ }
1522
1745
  const unchanged = [];
1523
- envs.map((env) => {
1746
+ for (const env of envs) {
1524
1747
  const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
1525
1748
  const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
1526
1749
  if (!newEnv && !overwriteEnv) {
1527
1750
  unchanged.push(env);
1528
1751
  }
1529
- });
1752
+ }
1530
1753
  data.envs = [...unchanged, ...overwrite, ...newEnvs];
1531
1754
  }
1532
1755
  const update = Object.assign(Object.assign({}, notification), data);
1533
- update.envs.map((env) => {
1756
+ for (const env of update.envs) {
1534
1757
  if (env.emails)
1535
- env.emails = (0, processor_utils_1.encrypt)(JSON.stringify(env.emails), this.fetchProduct().private_key);
1758
+ env.emails = (0, processor_utils_1.encrypt)(JSON.stringify(env.emails), this.product.private_key);
1536
1759
  if (env.push_notifications)
1537
- env.push_notifications = (0, processor_utils_1.encrypt)(JSON.stringify(env.push_notifications), this.fetchProduct().private_key);
1760
+ env.push_notifications = (0, processor_utils_1.encrypt)(JSON.stringify(env.push_notifications), this.product.private_key);
1538
1761
  if (env.callbacks)
1539
- env.callbacks = (0, processor_utils_1.encrypt)(JSON.stringify(env.callbacks), this.fetchProduct().private_key);
1762
+ env.callbacks = (0, processor_utils_1.encrypt)(JSON.stringify(env.callbacks), this.product.private_key);
1540
1763
  if (env.sms)
1541
- env.sms = (0, processor_utils_1.encrypt)(JSON.stringify(env.sms), this.fetchProduct().private_key);
1542
- return env;
1543
- });
1764
+ env.sms = (0, processor_utils_1.encrypt)(JSON.stringify(env.sms), this.product.private_key);
1765
+ }
1544
1766
  const payload = Object.assign(Object.assign({ _id }, update), { component: enums_1.ProductComponents.NOTIFICATION, action: enums_1.RequestAction.UPDATE });
1545
1767
  await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
1546
- await this.initializeProduct(this.product_id);
1547
1768
  }
1548
1769
  catch (e) {
1549
1770
  throw e;
1550
1771
  }
1551
1772
  }
1552
- fetchNotification(tag, notification_slug = '', throwErrorIfExists = false) {
1553
- const notification = this.product.notifications.find((data) => data.tag === tag);
1554
- if (notification && throwErrorIfExists)
1555
- throw new Error(`Notification ${tag} is in use`);
1556
- /*if (notification_slug) {
1557
- const { notifications, emails, callbacks } = notification.envs.find(
1558
- (data: INotificationEnv) => (data.slug = notification_slug),
1559
- );
1560
- return { notifications, emails, callbacks };
1561
- }*/
1562
- if (notification) {
1563
- notification.envs.map((data) => {
1773
+ async fetchNotifications() {
1774
+ let components = await this.productApi.fetchProductComponents(this.product_id, 'notification', this.getUserAccess());
1775
+ const notifications = components.map((notification) => {
1776
+ return notification.envs.map((data) => {
1564
1777
  if (data.callbacks && typeof data.callbacks == 'string') {
1565
- data.callbacks = JSON.parse((0, processor_utils_1.decrypt)(String(data.callbacks), this.fetchProduct().private_key));
1778
+ data.callbacks = JSON.parse((0, processor_utils_1.decrypt)(String(data.callbacks), this.product.private_key));
1566
1779
  }
1567
1780
  if (data.push_notifications && typeof data.push_notifications == 'string') {
1568
- data.push_notifications = JSON.parse((0, processor_utils_1.decrypt)(String(data.push_notifications), this.fetchProduct().private_key));
1781
+ data.push_notifications = JSON.parse((0, processor_utils_1.decrypt)(String(data.push_notifications), this.product.private_key));
1569
1782
  }
1570
1783
  if (data.emails && typeof data.emails == 'string') {
1571
- data.emails = JSON.parse((0, processor_utils_1.decrypt)(String(data.emails), this.fetchProduct().private_key));
1784
+ data.emails = JSON.parse((0, processor_utils_1.decrypt)(String(data.emails), this.product.private_key));
1572
1785
  }
1573
1786
  if (data.sms && typeof data.sms == 'string') {
1574
- data.sms = JSON.parse((0, processor_utils_1.decrypt)(String(data.sms), this.fetchProduct().private_key));
1787
+ data.sms = JSON.parse((0, processor_utils_1.decrypt)(String(data.sms), this.product.private_key));
1575
1788
  }
1576
1789
  return data;
1577
1790
  });
1578
- }
1579
- return notification;
1791
+ });
1792
+ return notifications;
1580
1793
  }
1581
- fetchNotifications() {
1582
- return this.product.notifications.map((notification) => {
1583
- return this.fetchNotification(notification.tag);
1794
+ async fetchNotification(tag) {
1795
+ const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'notification', tag, this.getUserAccess());
1796
+ component.envs.map((data) => {
1797
+ if (data.callbacks && typeof data.callbacks == 'string') {
1798
+ data.callbacks = JSON.parse((0, processor_utils_1.decrypt)(String(data.callbacks), this.product.private_key));
1799
+ }
1800
+ if (data.push_notifications && typeof data.push_notifications == 'string') {
1801
+ data.push_notifications = JSON.parse((0, processor_utils_1.decrypt)(String(data.push_notifications), this.product.private_key));
1802
+ }
1803
+ if (data.emails && typeof data.emails == 'string') {
1804
+ data.emails = JSON.parse((0, processor_utils_1.decrypt)(String(data.emails), this.product.private_key));
1805
+ }
1806
+ if (data.sms && typeof data.sms == 'string') {
1807
+ data.sms = JSON.parse((0, processor_utils_1.decrypt)(String(data.sms), this.product.private_key));
1808
+ }
1809
+ return data;
1584
1810
  });
1811
+ return component;
1585
1812
  }
1586
1813
  validateFeatureSequence(array) {
1587
1814
  // Validate uniqueness of sequence_tag
@@ -1681,24 +1908,27 @@ class ProductsBuilderService {
1681
1908
  await this.validateActionDataInput(data, action, event.input, event_index, sequence_index);
1682
1909
  }
1683
1910
  async checkAndValidateFunctionDataInput(data, sequence_index, event, event_index) {
1684
- const func = this.fetchFunction(event.event);
1911
+ const func = await this.fetchFunction(event.event);
1685
1912
  await this.validateActionDataInput(data, func, event.input, event_index, sequence_index);
1686
1913
  }
1687
1914
  async checkAndValidateDBActionDataInput(data, sequence_index, event, event_index) {
1688
1915
  console.log('EVENTY', event.event);
1689
- const { filterData, data: dbData, filterTemplate, template } = this.fetchDatabaseAction(event.event);
1916
+ const { filterData, data: dbData, filterTemplate, template } = await this.fetchDatabaseAction(event.event);
1690
1917
  await this.validateDBActionDataInput(data, { filterData, data: dbData, template, filter: filterTemplate }, event.input, event_index, sequence_index);
1691
1918
  }
1692
1919
  async checkAndValidateFeatureDataInput(data, sequence_index, event, event_index) {
1693
- const { input } = this.fetchFeature(event.event);
1920
+ const feature = await this.fetchFeature(event.event);
1921
+ if (!feature)
1922
+ throw new Error(`Feature ${event.event} not found`);
1923
+ const { input } = feature;
1694
1924
  await this.validateFeatureDataInput(data, input, event.input, event_index, sequence_index);
1695
1925
  }
1696
1926
  async checkAndValidateNotificationDataInput(data, sequence_index, event, event_index) {
1697
- const { callback_data: callback, push_notification_data: notification, email_data: email, sms_data: sms, } = this.fetchNotificationMessage(event.event);
1927
+ const { callback_data: callback, push_notification_data: notification, email_data: email, sms_data: sms, } = await this.fetchNotificationMessage(event.event);
1698
1928
  await this.validateNotificationDataInput(data, { callback, notification, email, sms }, event.input, event_index, sequence_index);
1699
1929
  }
1700
1930
  async checkAndValidatePublishDataInput(data, sequence_index, event, event_index) {
1701
- const topic = this.fetchMessageBrokerTopic(event.event);
1931
+ const topic = await this.fetchMessageBrokerTopic(event.event);
1702
1932
  if (!topic) {
1703
1933
  throw new Error(`Topic ${event.event} not registered`);
1704
1934
  }
@@ -1706,14 +1936,14 @@ class ProductsBuilderService {
1706
1936
  //await this.validatePublishTopicDataInput(data, { data: topicData }, event.input, event_index, sequence_index)
1707
1937
  }
1708
1938
  async checkAndValidateStorageDataInput(data, sequence_index, event, event_index) {
1709
- const storage = this.fetchStorage(event.event);
1939
+ const storage = await this.fetchStorage(event.event);
1710
1940
  if (!storage) {
1711
1941
  throw new Error(`Storage ${event.event} does not exist`);
1712
1942
  }
1713
1943
  //await this.validateStorageDataInput(data, {}, event.input, event_index, sequence_index);
1714
1944
  }
1715
1945
  async checkAndValidateJobDataInput(data, sequence_index, event, event_index) {
1716
- const job = this.fetchJob(event.event);
1946
+ const job = await this.fetchJob(event.event);
1717
1947
  if (job.type === productsBuilder_types_1.JobEventTypes.ACTION) {
1718
1948
  await this.checkAndValidateActionDataInput(data, sequence_index, event, event_index);
1719
1949
  }
@@ -1753,7 +1983,7 @@ class ProductsBuilderService {
1753
1983
  await this.checkAndValidatePublishDataInput(data, sequence_index, event, event_index);
1754
1984
  }
1755
1985
  /*if (event.type === FeatureEventTypes.SUBSCRIBE) {
1756
- const topic = this.fetchMessageBrokerTopic(event.event);
1986
+ const topic = await this.fetchMessageBrokerTopic(event.event);
1757
1987
 
1758
1988
  if(!topic) {
1759
1989
  throw new Error(`Topic ${event.event} not registered`);
@@ -1956,7 +2186,7 @@ class ProductsBuilderService {
1956
2186
  });
1957
2187
  }
1958
2188
  async validateActionInputData(data, skipSample = false, option = false, optionIndex = 0) {
1959
- var _a;
2189
+ var _a, _b;
1960
2190
  const { obj } = data, base_data = __rest(data, ["obj"]);
1961
2191
  if (!data.sample && Object.keys(obj).length === 0) {
1962
2192
  return;
@@ -1964,8 +2194,8 @@ class ProductsBuilderService {
1964
2194
  if (!data.sample) {
1965
2195
  throw new Error('Something unexpected happened in validating action input');
1966
2196
  }
1967
- const sequence = data.feature.sequence[data.sequence_index];
1968
- if (obj === undefined || obj === null) {
2197
+ const sequence = data.feature.sequence ? (_a = data.feature) === null || _a === void 0 ? void 0 : _a.sequence[data.sequence_index] : null;
2198
+ if ((obj === undefined || obj === null) && sequence) {
1969
2199
  if (!option) {
1970
2200
  throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should not be ${obj}`);
1971
2201
  }
@@ -1973,7 +2203,7 @@ class ProductsBuilderService {
1973
2203
  throw new Error(`option event index ${optionIndex}, ${data.type} should not be ${obj}`);
1974
2204
  }
1975
2205
  }
1976
- if (Object.values(obj).length > 0 && ((_a = data.sample.data) === null || _a === void 0 ? void 0 : _a.length) === 0) {
2206
+ if (sequence && (Object.values(obj).length > 0 && ((_b = data.sample.data) === null || _b === void 0 ? void 0 : _b.length) === 0)) {
1977
2207
  if (!option) {
1978
2208
  throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should be an empty object`);
1979
2209
  }
@@ -1984,7 +2214,7 @@ class ProductsBuilderService {
1984
2214
  if (Object.values(obj).length === 0 && data.sample.data.length === 0 /*data.sample?.data?.length === 0*/) {
1985
2215
  return;
1986
2216
  }
1987
- if (Object.values(obj).length === 0 && data.sample.data.length > 0 && !skipSample) {
2217
+ if (sequence && Object.values(obj).length === 0 && data.sample.data.length > 0 && !skipSample) {
1988
2218
  //console.log("validity err: ",obj, data.sample)
1989
2219
  if (!option) {
1990
2220
  throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should not be an empty object`);
@@ -2160,7 +2390,9 @@ class ProductsBuilderService {
2160
2390
  let current_input = input;
2161
2391
  for (let i = 0; i < stages.length; i++) {
2162
2392
  let stage = stages[i];
2163
- const matches = stage.match(/^\[(\d+)\]$/);
2393
+ // Convert to string for .match() call
2394
+ const stageStr = String(stage);
2395
+ const matches = stageStr.match(/^\[(\d+)\]$/);
2164
2396
  if (matches && matches.length === 2) {
2165
2397
  const number = parseInt(matches[1], 10);
2166
2398
  if (!isNaN(number)) {
@@ -2216,14 +2448,16 @@ class ProductsBuilderService {
2216
2448
  }
2217
2449
  else {
2218
2450
  //const envs =
2219
- const app = this.fetchApp(access_tag);
2451
+ const app = await this.fetchApp(access_tag);
2220
2452
  const { envs } = app;
2221
2453
  await Promise.all(envs.map((env) => {
2222
2454
  if (stages[0] !== env.auth.auth_tag) {
2223
2455
  throw new Error(`Auth ${stages[0]} does not exist on env ${env.product_env_slug} on app ${access_tag}`);
2224
2456
  }
2225
- const decrypted = JSON.parse((0, processor_utils_1.decrypt)(env.auth.values, this.fetchProduct().private_key));
2226
- const check = (0, objects_utils_1.findFaultyKeys)(stages.slice(1), decrypted);
2457
+ const decrypted = JSON.parse((0, processor_utils_1.decrypt)(env.auth.values, this.product.private_key));
2458
+ // Convert stages to string[] for findFaultyKeys
2459
+ const stringStages = stages.slice(1).map(stage => String(stage));
2460
+ const check = (0, objects_utils_1.findFaultyKeys)(stringStages, decrypted);
2227
2461
  if (check.faultyKeys) {
2228
2462
  throw new Error(`Auth Key(s) ${check.faultyKeys.join(', ')} is/are invalid, they do not exist in authorization for ${env.product_env_slug} on app ${access_tag}`);
2229
2463
  }
@@ -2239,7 +2473,9 @@ class ProductsBuilderService {
2239
2473
  let i = 1;
2240
2474
  while (i < stages.length) {
2241
2475
  let stage = stages[i];
2242
- const matches = stage.match(/^\[(\d+)\]$/);
2476
+ // Convert to string for .match() call
2477
+ const stageStr = String(stage);
2478
+ const matches = stageStr.match(/^\[(\d+)\]$/);
2243
2479
  if (matches && matches.length === 2) {
2244
2480
  const number = parseInt(matches[1], 10);
2245
2481
  if (!isNaN(number)) {
@@ -2313,11 +2549,15 @@ class ProductsBuilderService {
2313
2549
  // let current_data;
2314
2550
  if (i === 0) {
2315
2551
  // find sequence by tag, see if it exists and its before current sequence
2316
- this.validateSequenceInputParents(stage, meta.sequence_index, meta.feature.sequence);
2317
- sequence = this.fetchPriorSequence(meta, stage);
2552
+ // Convert stage to string for function calls
2553
+ const stageStr = String(stage);
2554
+ this.validateSequenceInputParents(stageStr, meta.sequence_index, meta.feature.sequence);
2555
+ sequence = this.fetchPriorSequence(meta, stageStr);
2318
2556
  }
2319
2557
  if (i === 1 && sequence) {
2320
- event = this.fetchSequenceEvent(sequence, stage);
2558
+ // Convert stage to string for function calls
2559
+ const stageStr = String(stage);
2560
+ event = this.fetchSequenceEvent(sequence, stageStr);
2321
2561
  if (!event) {
2322
2562
  throw new Error(`event ${stage} not found in sequence ${sequence.tag}`);
2323
2563
  }
@@ -2346,7 +2586,9 @@ class ProductsBuilderService {
2346
2586
  if (i > 1 && response) {
2347
2587
  let parent_index = 0;
2348
2588
  let increment = false;
2349
- const matches = stage.match(/^\[(\d+)\]$/);
2589
+ // Convert to string for .match() call
2590
+ const stageStr = String(stage);
2591
+ const matches = stageStr.match(/^\[(\d+)\]$/);
2350
2592
  if (matches && matches.length === 2) {
2351
2593
  const number = parseInt(matches[1], 10);
2352
2594
  if (!isNaN(number)) {
@@ -2404,7 +2646,7 @@ class ProductsBuilderService {
2404
2646
  if (stages.length > 2) {
2405
2647
  throw new Error(`sequence ${sequence.tag} event ${sequence.events[meta.event_index].event} ${meta.type}, has invalid varibale definition ${value}, only two keys is required`);
2406
2648
  }
2407
- const app = this.fetchApp(stages[0]);
2649
+ const app = await this.fetchApp(String(stages[0]));
2408
2650
  if (!app) {
2409
2651
  throw new Error(`App ${stages[0]} not found in sequence ${sequence.tag} event ${sequence.events[meta.event_index].event} ${meta.type}, has invalid varibale definition ${value}. `);
2410
2652
  }
@@ -2421,8 +2663,8 @@ class ProductsBuilderService {
2421
2663
  if (stages.length !== 2) {
2422
2664
  throw new Error(`When using constants you need to specify the constant in the format $Constant{app_tag}{key} instead of ${value}`);
2423
2665
  }
2424
- const app_tag = stages[0];
2425
- const key = stages[1];
2666
+ const app_tag = String(stages[0]);
2667
+ const key = String(stages[1]);
2426
2668
  const _c = await this.fetchThirdPartyAppByAccessTag(app_tag), { version } = _c, app = __rest(_c, ["version"]);
2427
2669
  if (!app) {
2428
2670
  throw new Error(`App ${app_tag} not found in constant ${value}`);
@@ -2512,9 +2754,10 @@ class ProductsBuilderService {
2512
2754
  return found;
2513
2755
  }
2514
2756
  validateActionKeyPlacement(data) {
2757
+ var _a;
2515
2758
  const actionData = data.sample.data;
2516
2759
  const { indexes } = data;
2517
- const sequence = data.feature.sequence[data.sequence_index];
2760
+ const sequence = data.feature.sequence ? (_a = data.feature) === null || _a === void 0 ? void 0 : _a.sequence[data.sequence_index] : null;
2518
2761
  const datapoint = actionData.find((item) => {
2519
2762
  return (item.parent_key === indexes.parent_key && item.key === data.key && item.level === indexes.level //&&
2520
2763
  //indexes.index === item.index
@@ -2522,7 +2765,12 @@ class ProductsBuilderService {
2522
2765
  });
2523
2766
  if (!datapoint) {
2524
2767
  console.log('VALIDATE', data.key, data.value, actionData, indexes);
2525
- throw new Error(`Key ${data.key} not found for ${data.type} for sequence ${sequence.tag} event ${sequence.events[data.event_index].event}`);
2768
+ if (sequence) {
2769
+ throw new Error(`Key ${data.key} not found for ${data.type} for sequence ${sequence.tag} event ${sequence.events[data.event_index].event}`);
2770
+ }
2771
+ else {
2772
+ throw new Error(`Key ${data.key} not found`);
2773
+ }
2526
2774
  }
2527
2775
  return datapoint;
2528
2776
  }
@@ -2553,12 +2801,11 @@ class ProductsBuilderService {
2553
2801
  }
2554
2802
  async createFeature(data, throwErrorIfExists = false) {
2555
2803
  try {
2556
- if (!this.fetchFeature(data.tag, false)) {
2804
+ if (!(await this.fetchFeature(data.tag))) {
2557
2805
  await validators_1.CreateProductFeatureSchema.validateAsync(data);
2558
2806
  try {
2559
2807
  await this.validateFeatureData(data);
2560
2808
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.FEATURE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
2561
- await this.initializeProduct(this.product_id);
2562
2809
  }
2563
2810
  catch (e) {
2564
2811
  throw e;
@@ -2575,7 +2822,7 @@ class ProductsBuilderService {
2575
2822
  }
2576
2823
  async updateFeature(tag, data) {
2577
2824
  try {
2578
- const feature = this.fetchFeature(tag);
2825
+ const feature = await this.fetchFeature(tag);
2579
2826
  if (!feature) {
2580
2827
  throw new Error(`Feature ${tag} not found`);
2581
2828
  }
@@ -2587,43 +2834,42 @@ class ProductsBuilderService {
2587
2834
  }
2588
2835
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id,
2589
2836
  tag }, data), { component: enums_1.ProductComponents.FEATURE, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
2590
- await this.initializeProduct(this.product_id);
2591
2837
  }
2592
2838
  catch (e) {
2593
2839
  throw e;
2594
2840
  }
2595
2841
  }
2596
- fetchFeature(tag, throwErrorIfExists = true) {
2597
- const feature = this.product.features.find((data) => data.tag === tag);
2598
- if (!feature && throwErrorIfExists)
2599
- throw new Error(`Feature ${tag} not found`);
2600
- return feature;
2842
+ async fetchFeatures() {
2843
+ const components = await this.productApi.fetchProductComponents(this.product_id, 'feature', this.getUserAccess());
2844
+ return components;
2601
2845
  }
2602
- fetchFeatures() {
2603
- return this.product.features;
2846
+ async fetchFeature(tag) {
2847
+ const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'feature', tag, this.getUserAccess());
2848
+ return component;
2604
2849
  }
2605
2850
  async createDatabase(data, throwErrorIfExists = false) {
2606
2851
  try {
2607
2852
  // TODO: figure out a way to check if this has run before, halt if it has
2608
- if (!this.fetchDatabase(data.tag, false)) {
2853
+ if (!(await this.fetchDatabase(data.tag))) {
2609
2854
  await validators_1.CreateProductDatabaseSchema.validateAsync(data);
2610
- data.envs = data.envs.map((env) => {
2611
- const exists = this.fetchEnv(env.slug);
2855
+ const processedEnvs = [];
2856
+ for (const env of data.envs) {
2857
+ const exists = await this.fetchEnv(env.slug);
2612
2858
  if (!exists) {
2613
2859
  throw new Error(`Env ${env.slug} does not exist`);
2614
2860
  }
2615
- env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.fetchProduct().private_key);
2616
- return env;
2617
- });
2618
- const envs = this.fetchEnvs();
2619
- envs.map((env) => {
2861
+ env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
2862
+ processedEnvs.push(env);
2863
+ }
2864
+ data.envs = processedEnvs;
2865
+ const envs = await this.fetchEnvs();
2866
+ for (const env of envs) {
2620
2867
  const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
2621
2868
  if (exists === -1) {
2622
2869
  throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
2623
2870
  }
2624
- });
2871
+ }
2625
2872
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.DATABASE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
2626
- await this.initializeProduct(this.product_id);
2627
2873
  }
2628
2874
  else {
2629
2875
  if (throwErrorIfExists)
@@ -2636,7 +2882,7 @@ class ProductsBuilderService {
2636
2882
  }
2637
2883
  async updateDatabase(tag, data) {
2638
2884
  try {
2639
- const db = this.fetchDatabase(tag);
2885
+ const db = await this.fetchDatabase(tag);
2640
2886
  if (!db) {
2641
2887
  throw new Error(`Database ${tag} not found`);
2642
2888
  }
@@ -2645,15 +2891,16 @@ class ProductsBuilderService {
2645
2891
  if (data.tag && this.fetchDatabase(data.tag)) {
2646
2892
  throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
2647
2893
  }
2648
- data.envs = data.envs.map((env) => {
2649
- const exists = this.fetchEnv(env.slug);
2894
+ data.envs = await Promise.all(data.envs.map(async (env) => {
2895
+ const exists = await this.fetchEnv(env.slug);
2650
2896
  if (!exists) {
2651
2897
  throw new Error(`Env ${env.slug} does not exist`);
2652
2898
  }
2653
- if (env.connection_url)
2654
- env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.fetchProduct().private_key);
2899
+ if (env.connection_url) {
2900
+ env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
2901
+ }
2655
2902
  return env;
2656
- });
2903
+ }));
2657
2904
  const overwrite = [];
2658
2905
  const newEnvs = [];
2659
2906
  data.envs.map((dataEnv) => {
@@ -2682,23 +2929,237 @@ class ProductsBuilderService {
2682
2929
  data.envs = [...unchanged, ...overwrite, ...newEnvs];
2683
2930
  //console.log("UPDATED!!!", JSON.stringify(data.envs))
2684
2931
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id }, data), { tag, component: enums_1.ProductComponents.DATABASE, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
2685
- await this.initializeProduct(this.product_id);
2686
2932
  }
2687
2933
  catch (e) {
2688
2934
  throw e;
2689
2935
  }
2690
2936
  }
2691
- fetchDatabase(tag, throwErrorIfExists = false) {
2692
- const database = this.product.databases.find((data) => data.tag === tag);
2937
+ async fetchDatabases() {
2938
+ const components = await this.productApi.fetchProductComponents(this.product_id, 'database', this.getUserAccess());
2939
+ components.map((database) => {
2940
+ database.envs.map((env) => {
2941
+ env.connection_url = (0, processor_utils_1.decrypt)(env.connection_url, this.product.private_key);
2942
+ });
2943
+ });
2944
+ return components;
2945
+ }
2946
+ async fetchDatabase(tag) {
2947
+ const database = await this.productApi.fetchProductComponentByTag(this.product_id, 'database', tag, this.getUserAccess());
2693
2948
  database.envs.map((env) => {
2694
- env.connection_url = (0, processor_utils_1.decrypt)(env.connection_url, this.fetchProduct().private_key);
2949
+ env.connection_url = (0, processor_utils_1.decrypt)(env.connection_url, this.product.private_key);
2695
2950
  });
2696
- if (!database && throwErrorIfExists)
2697
- throw new Error(`Database ${tag} not found`);
2698
2951
  return database;
2699
2952
  }
2700
- fetchDatabases() {
2701
- return this.product.databases;
2953
+ // ==================== GRAPH DATABASE METHODS ====================
2954
+ async createGraph(data, throwErrorIfExists = false) {
2955
+ try {
2956
+ if (!(await this.fetchGraph(data.tag))) {
2957
+ await validators_1.CreateProductGraphSchema.validateAsync(data);
2958
+ const processedEnvs = [];
2959
+ for (const env of data.envs) {
2960
+ const exists = await this.fetchEnv(env.slug);
2961
+ if (!exists) {
2962
+ throw new Error(`Env ${env.slug} does not exist`);
2963
+ }
2964
+ env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
2965
+ processedEnvs.push(env);
2966
+ }
2967
+ data.envs = processedEnvs;
2968
+ const envs = await this.fetchEnvs();
2969
+ for (const env of envs) {
2970
+ const exists = data.envs.findIndex((graphEnv) => graphEnv.slug === env.slug);
2971
+ if (exists === -1) {
2972
+ throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
2973
+ }
2974
+ }
2975
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.GRAPH, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
2976
+ }
2977
+ else {
2978
+ if (throwErrorIfExists)
2979
+ throw new Error(`Graph ${data.tag} already exists`);
2980
+ }
2981
+ }
2982
+ catch (e) {
2983
+ throw e;
2984
+ }
2985
+ }
2986
+ async updateGraph(tag, data) {
2987
+ try {
2988
+ const graph = await this.fetchGraph(tag);
2989
+ if (!graph) {
2990
+ throw new Error(`Graph ${tag} not found`);
2991
+ }
2992
+ const { _id, envs } = graph;
2993
+ await validators_1.UpdateProductGraphSchema.validateAsync(data);
2994
+ if (data.tag && (await this.fetchGraph(data.tag))) {
2995
+ throw new Error(`tag ${data.tag} is in use`);
2996
+ }
2997
+ if (data.envs) {
2998
+ data.envs = await Promise.all(data.envs.map(async (env) => {
2999
+ const exists = await this.fetchEnv(env.slug);
3000
+ if (!exists) {
3001
+ throw new Error(`Env ${env.slug} does not exist`);
3002
+ }
3003
+ if (env.connection_url) {
3004
+ env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.product.private_key);
3005
+ }
3006
+ return env;
3007
+ }));
3008
+ const overwrite = [];
3009
+ const newEnvs = [];
3010
+ data.envs.map((dataEnv) => {
3011
+ const existsIndex = envs.findIndex((env) => env.slug === dataEnv.slug);
3012
+ if (!(this.fetchEnv(dataEnv.slug))) {
3013
+ throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
3014
+ }
3015
+ if (existsIndex === -1) {
3016
+ if (!dataEnv.connection_url) {
3017
+ throw new Error(`connection_url is required for new env ${dataEnv.slug}`);
3018
+ }
3019
+ newEnvs.push(dataEnv);
3020
+ }
3021
+ else {
3022
+ overwrite.push(Object.assign(Object.assign({}, envs[existsIndex]), dataEnv));
3023
+ }
3024
+ });
3025
+ const unchanged = [];
3026
+ envs.map((env) => {
3027
+ const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
3028
+ const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
3029
+ if (!newEnv && !overwriteEnv) {
3030
+ unchanged.push(env);
3031
+ }
3032
+ });
3033
+ data.envs = [...unchanged, ...overwrite, ...newEnvs];
3034
+ }
3035
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id }, data), { tag, component: enums_1.ProductComponents.GRAPH, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
3036
+ }
3037
+ catch (e) {
3038
+ throw e;
3039
+ }
3040
+ }
3041
+ async fetchGraphs() {
3042
+ const components = await this.productApi.fetchProductComponents(this.product_id, 'graph', this.getUserAccess());
3043
+ components.map((graph) => {
3044
+ graph.envs.map((env) => {
3045
+ env.connection_url = (0, processor_utils_1.decrypt)(env.connection_url, this.product.private_key);
3046
+ });
3047
+ });
3048
+ return components;
3049
+ }
3050
+ async fetchGraph(tag) {
3051
+ const graph = await this.productApi.fetchProductComponentByTag(this.product_id, 'graph', tag, this.getUserAccess());
3052
+ if (graph && graph.envs) {
3053
+ graph.envs.map((env) => {
3054
+ env.connection_url = (0, processor_utils_1.decrypt)(env.connection_url, this.product.private_key);
3055
+ });
3056
+ }
3057
+ return graph;
3058
+ }
3059
+ // ==================== GRAPH ACTION METHODS ====================
3060
+ async createGraphAction(data, throwErrorIfExists = false) {
3061
+ var _a;
3062
+ try {
3063
+ if (!data.tag) {
3064
+ throw new Error('tag field is required');
3065
+ }
3066
+ const [graphTag, tag] = data.tag.split(':');
3067
+ if (!graphTag || !tag) {
3068
+ throw new Error('tag should be formatted as graph_tag:action_tag');
3069
+ }
3070
+ const graph = await this.fetchGraph(graphTag);
3071
+ if (!graph) {
3072
+ throw new Error(`Graph ${graphTag} not found`);
3073
+ }
3074
+ const existingAction = (_a = graph.actions) === null || _a === void 0 ? void 0 : _a.find((action) => action.tag === tag);
3075
+ if (existingAction) {
3076
+ if (throwErrorIfExists) {
3077
+ throw new Error(`Graph action ${data.tag} already exists`);
3078
+ }
3079
+ return;
3080
+ }
3081
+ // Validate the action data
3082
+ const validationData = Object.assign(Object.assign({}, data), { tag });
3083
+ await create_productGraphAction_validator_1.default.validateAsync(validationData);
3084
+ // Extract placeholders from template
3085
+ const values = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.template));
3086
+ const template = JSON.stringify(data.template);
3087
+ // Process filter template if provided
3088
+ let filterData, filterTemplate;
3089
+ if (data.filterTemplate) {
3090
+ filterData = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.filterTemplate));
3091
+ filterTemplate = JSON.stringify(data.filterTemplate);
3092
+ }
3093
+ const actionData = Object.assign(Object.assign({}, data), { tag, data: values, template,
3094
+ filterData,
3095
+ filterTemplate });
3096
+ graph.actions = graph.actions || [];
3097
+ graph.actions.push(actionData);
3098
+ await this.updateGraph(graphTag, { actions: graph.actions });
3099
+ }
3100
+ catch (error) {
3101
+ throw new Error(`Failed to create graph action: ${error.message}`);
3102
+ }
3103
+ }
3104
+ async updateGraphAction(data) {
3105
+ var _a;
3106
+ try {
3107
+ if (!data.tag) {
3108
+ throw new Error('tag field is required');
3109
+ }
3110
+ const [graphTag, tag] = data.tag.split(':');
3111
+ if (!graphTag || !tag) {
3112
+ throw new Error('tag should be formatted as graph_tag:action_tag');
3113
+ }
3114
+ const graph = await this.fetchGraph(graphTag);
3115
+ if (!graph) {
3116
+ throw new Error(`Graph ${graphTag} not found`);
3117
+ }
3118
+ const actionIndex = (_a = graph.actions) === null || _a === void 0 ? void 0 : _a.findIndex((action) => action.tag === tag);
3119
+ if (actionIndex === undefined || actionIndex === -1) {
3120
+ throw new Error(`Graph action ${data.tag} not found`);
3121
+ }
3122
+ // Validate the update data
3123
+ const validationData = Object.assign(Object.assign({}, data), { tag });
3124
+ await update_productGraphAction_validator_1.default.validateAsync(validationData);
3125
+ // Process template if provided
3126
+ const updateData = Object.assign(Object.assign({}, data), { tag });
3127
+ if (data.template) {
3128
+ updateData.data = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.template));
3129
+ updateData.template = JSON.stringify(data.template);
3130
+ }
3131
+ // Process filter template if provided
3132
+ if (data.filterTemplate) {
3133
+ updateData.filterData = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.filterTemplate));
3134
+ updateData.filterTemplate = JSON.stringify(data.filterTemplate);
3135
+ }
3136
+ graph.actions[actionIndex] = Object.assign(Object.assign({}, graph.actions[actionIndex]), updateData);
3137
+ await this.updateGraph(graphTag, { actions: graph.actions });
3138
+ }
3139
+ catch (error) {
3140
+ throw new Error(`Failed to update graph action: ${error.message}`);
3141
+ }
3142
+ }
3143
+ async fetchGraphAction(tag, throwErrorIfNotExists = false) {
3144
+ var _a, _b;
3145
+ const [graphTag, actionTag] = tag.split(':');
3146
+ if (!graphTag || !actionTag) {
3147
+ throw new Error('tag is expected to be defined as "graph_tag:action_tag"');
3148
+ }
3149
+ const graph = (_a = this.product.graphs) === null || _a === void 0 ? void 0 : _a.find((data) => data.tag === graphTag);
3150
+ if (!graph)
3151
+ throw new Error(`Graph ${graphTag} not found`);
3152
+ const action = (_b = graph.actions) === null || _b === void 0 ? void 0 : _b.find((data) => data.tag === actionTag);
3153
+ if (!action && throwErrorIfNotExists)
3154
+ throw new Error(`Graph action ${tag} not found`);
3155
+ return action || null;
3156
+ }
3157
+ async fetchGraphActions(graphTag) {
3158
+ const graph = await this.fetchGraph(graphTag);
3159
+ if (!graph) {
3160
+ throw new Error(`Graph ${graphTag} not found`);
3161
+ }
3162
+ return graph.actions || [];
2702
3163
  }
2703
3164
  async createDatabaseAction(data, throwErrorIfExists = false) {
2704
3165
  try {
@@ -2709,34 +3170,24 @@ class ProductsBuilderService {
2709
3170
  if (!databaseTag || !tag) {
2710
3171
  throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
2711
3172
  }
2712
- const exists = this.fetchDatabaseAction(data.tag);
3173
+ const exists = await this.fetchDatabaseAction(data.tag);
2713
3174
  data.tag = tag;
2714
3175
  if (!exists) {
2715
- const database = this.fetchDatabase(databaseTag);
2716
- let values, template;
2717
- if (database.type === productsBuilder_types_1.DatabaseTypes.MONGODB) {
2718
- await create_productDatabaseAction_validator_1.NOSQLDatabaseActionsSchema.validateAsync(data);
2719
- values = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.template));
2720
- template = JSON.stringify(data.template);
2721
- if (data.type === productsBuilder_types_1.DatabaseActionTypes.UPDATE && !data.filterTemplate) {
2722
- throw new Error(`filterTemplate is required for ${productsBuilder_types_1.DatabaseActionTypes.UPDATE} actions in ${productsBuilder_types_1.DatabaseTypes.MONGODB}`);
2723
- }
2724
- if (data.filterTemplate) {
2725
- data.filterData = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.filterTemplate));
2726
- data.filterTemplate = JSON.stringify(data.filterTemplate);
2727
- }
2728
- }
2729
- else {
2730
- create_productDatabaseAction_validator_1.SQLDatabaseActionSchema.validateAsync(data);
2731
- values = (0, string_utils_1.extractPlaceholders)(String(data.template));
2732
- template = data.template;
2733
- if (data.filterTemplate) {
2734
- data.filterData = (0, string_utils_1.extractPlaceholders)(String(data.filterTemplate));
2735
- }
3176
+ // Verify database exists
3177
+ await this.fetchDatabase(databaseTag);
3178
+ // Validate the action data using the unified schema
3179
+ const validationData = Object.assign(Object.assign({}, data), { tag });
3180
+ await create_productDatabaseAction_validator_1.default.validateAsync(validationData);
3181
+ // Extract placeholders from the structured template
3182
+ const values = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.template));
3183
+ const template = JSON.stringify(data.template);
3184
+ // Process filter template if provided (for UPDATE/DELETE actions)
3185
+ if (data.filterTemplate) {
3186
+ data.filterData = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.filterTemplate));
3187
+ data.filterTemplate = JSON.stringify(data.filterTemplate);
2736
3188
  }
2737
3189
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { data: values, template,
2738
3190
  databaseTag, component: enums_1.ProductComponents.DATABASE_ACTION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
2739
- await this.initializeProduct(this.product_id);
2740
3191
  }
2741
3192
  else {
2742
3193
  if (throwErrorIfExists)
@@ -2747,7 +3198,7 @@ class ProductsBuilderService {
2747
3198
  throw e;
2748
3199
  }
2749
3200
  }
2750
- fetchDatabaseAction(tag, throwErrorIfExists = false) {
3201
+ async fetchDatabaseAction(tag, throwErrorIfExists = false) {
2751
3202
  const [databaseTag, actionTag] = tag.split(':');
2752
3203
  if (!databaseTag || !actionTag) {
2753
3204
  throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
@@ -2773,43 +3224,37 @@ class ProductsBuilderService {
2773
3224
  if (!databaseTag || !tag) {
2774
3225
  throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
2775
3226
  }
2776
- // Fetch required data
2777
- const database = await this.fetchDatabase(databaseTag, true);
3227
+ // Fetch required data (also verifies database exists)
3228
+ await this.fetchDatabase(databaseTag);
2778
3229
  const action = await this.fetchDatabaseAction(data.tag, true);
2779
3230
  // Construct payload
2780
3231
  const payload = Object.assign(Object.assign(Object.assign({}, action), data), { databaseTag, component: enums_1.ProductComponents.DATABASE_ACTION, action: enums_1.RequestAction.UPDATE });
2781
3232
  // Validate and process the template
2782
3233
  data.tag = tag;
3234
+ // Validate using the unified schema
3235
+ const validationData = Object.assign(Object.assign({}, data), { tag });
3236
+ await update_productDatabaseAction_validator_1.default.validateAsync(validationData);
2783
3237
  if (data.template) {
2784
- let values, template;
2785
- if (database.type === productsBuilder_types_1.DatabaseTypes.MONGODB) {
2786
- await update_productDatabaseAction_validator_1.UpdateNOSQLDatabaseActionsSchema.validateAsync(data);
2787
- values = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.template));
2788
- template = JSON.stringify(data.template);
2789
- }
2790
- else {
2791
- await update_productDatabaseAction_validator_1.UpdateSQLDatabaseActionSchema.validateAsync(data);
2792
- values = (0, string_utils_1.extractPlaceholders)(String(data.template));
2793
- template = data.template;
2794
- }
3238
+ // Extract placeholders from the structured template
3239
+ const values = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.template));
3240
+ const template = JSON.stringify(data.template);
2795
3241
  Object.assign(payload, { data: values, template });
2796
3242
  }
2797
- else if (database.type === productsBuilder_types_1.DatabaseTypes.MONGODB) {
2798
- await update_productDatabaseAction_validator_1.UpdateNOSQLDatabaseActionsSchema.validateAsync(data);
2799
- }
2800
- else {
2801
- await update_productDatabaseAction_validator_1.UpdateSQLDatabaseActionSchema.validateAsync(data);
3243
+ // Process filter template if provided
3244
+ if (data.filterTemplate) {
3245
+ const filterData = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.filterTemplate));
3246
+ const filterTemplate = JSON.stringify(data.filterTemplate);
3247
+ Object.assign(payload, { filterData, filterTemplate });
2802
3248
  }
2803
3249
  // Update product and reinitialize
2804
3250
  await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
2805
- await this.initializeProduct(this.product_id);
2806
3251
  }
2807
3252
  catch (error) {
2808
3253
  throw error;
2809
3254
  }
2810
3255
  }
2811
- fetchDatabaseActions(databaseTag) {
2812
- const database = this.product.databases.find((data) => data.tag === databaseTag);
3256
+ async fetchDatabaseActions(databaseTag) {
3257
+ const database = await this.fetchDatabase(databaseTag);
2813
3258
  if (!database)
2814
3259
  throw new Error(`Database ${databaseTag} not found`);
2815
3260
  const actions = database.actions;
@@ -2832,12 +3277,11 @@ class ProductsBuilderService {
2832
3277
  data.tag = tag;
2833
3278
  await create_productDatabaseMigration_validator_1.default.validateAsync(Object.assign(Object.assign({}, data), { databaseTag })); // Change to update;
2834
3279
  if (!exists) {
2835
- const database = this.fetchDatabase(databaseTag, true);
3280
+ const database = await this.fetchDatabase(databaseTag);
2836
3281
  if (database.type === productsBuilder_types_1.DatabaseTypes.MONGODB) {
2837
3282
  throw new Error(`${database.type} does not support migrations`);
2838
3283
  }
2839
3284
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { databaseTag, component: enums_1.ProductComponents.DATABASE_MIGRATION }), this.getUserAccess());
2840
- await this.initializeProduct(this.product_id);
2841
3285
  }
2842
3286
  else {
2843
3287
  if (throwErrorIfExists)
@@ -2859,14 +3303,13 @@ class ProductsBuilderService {
2859
3303
  }
2860
3304
  data.tag = tag;
2861
3305
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({}, action), Object.assign(Object.assign({}, data), { databaseTag })), { component: enums_1.ProductComponents.DATABASE_MIGRATION }), this.getUserAccess());
2862
- await this.initializeProduct(this.product_id);
2863
3306
  }
2864
- fetchDatabaseMigration(tag, throwError = false) {
3307
+ async fetchDatabaseMigration(tag, throwError = false) {
2865
3308
  const [databaseTag, migrationTag] = tag.split(':');
2866
3309
  if (!databaseTag || !migrationTag) {
2867
3310
  throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
2868
3311
  }
2869
- const database = this.product.databases.find((data) => data.tag === databaseTag);
3312
+ const database = await this.fetchDatabase(databaseTag); //this.product.databases.find((data: IProductDatabase) => data.tag === databaseTag);
2870
3313
  if (!database)
2871
3314
  throw new Error(`Database ${databaseTag} not found`);
2872
3315
  const migration = database.migrations.find((data) => data.tag === migrationTag);
@@ -2874,8 +3317,8 @@ class ProductsBuilderService {
2874
3317
  throw new Error(`Database migration ${tag} not found`);
2875
3318
  return migration;
2876
3319
  }
2877
- fetchDatabaseMigrations(databaseTag) {
2878
- const database = this.product.databases.find((data) => data.tag === databaseTag);
3320
+ async fetchDatabaseMigrations(databaseTag) {
3321
+ const database = await this.fetchDatabase(databaseTag); //this.product.databases.find((data: IProductDatabase) => data.tag === databaseTag);
2879
3322
  if (!database)
2880
3323
  throw new Error(`Database ${databaseTag} not found`);
2881
3324
  const migrations = database.migrations;
@@ -2895,31 +3338,31 @@ class ProductsBuilderService {
2895
3338
  }
2896
3339
  }
2897
3340
  if (type === productsBuilder_types_1.JobEventTypes.DATABASE_ACTION) {
2898
- const found = this.fetchDatabaseAction(event);
3341
+ const found = await this.fetchDatabaseAction(event);
2899
3342
  if (!found) {
2900
3343
  throw new Error(`Database action ${event} not found`);
2901
3344
  }
2902
3345
  }
2903
3346
  if (type === productsBuilder_types_1.JobEventTypes.FUNCTION) {
2904
- const found = this.fetchFunction(event);
3347
+ const found = await this.fetchFunction(event);
2905
3348
  if (!found) {
2906
3349
  throw new Error(`Cloud function ${event} not found`);
2907
3350
  }
2908
3351
  }
2909
3352
  if (type === productsBuilder_types_1.JobEventTypes.STORAGE) {
2910
- const found = this.fetchStorage(event);
3353
+ const found = await this.fetchStorage(event);
2911
3354
  if (!found) {
2912
3355
  throw new Error(`Storage ${event} not found`);
2913
3356
  }
2914
3357
  }
2915
3358
  if (type === productsBuilder_types_1.JobEventTypes.NOTIFICATION) {
2916
- const found = this.fetchNotification(event);
3359
+ const found = await this.fetchNotification(event);
2917
3360
  if (!found) {
2918
3361
  throw new Error(`Notification ${event} not found`);
2919
3362
  }
2920
3363
  }
2921
3364
  if (type === productsBuilder_types_1.JobEventTypes.PUBLISH) {
2922
- const found = this.fetchMessageBroker(event);
3365
+ const found = await this.fetchMessageBroker(event);
2923
3366
  if (!found) {
2924
3367
  throw new Error(`Message Broker ${event} not found`);
2925
3368
  }
@@ -2928,7 +3371,7 @@ class ProductsBuilderService {
2928
3371
  async createJob(data, throwErrorIfExists = false) {
2929
3372
  try {
2930
3373
  // TODO: figure out a way to check if this has run before, halt if it has
2931
- if (!this.fetchJob(data.tag)) {
3374
+ if (!(await this.fetchJob(data.tag))) {
2932
3375
  await validators_1.CreateProductJobSchema.validateAsync(data);
2933
3376
  await this.validateJobEvent(data);
2934
3377
  if (data.type === productsBuilder_types_1.JobEventTypes.ACTION) {
@@ -2950,7 +3393,6 @@ class ProductsBuilderService {
2950
3393
  const dbAction = await this.fetchDatabaseAction(data.event);
2951
3394
  }
2952
3395
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.JOB, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
2953
- await this.initializeProduct(this.product_id);
2954
3396
  }
2955
3397
  else {
2956
3398
  if (throwErrorIfExists)
@@ -2963,7 +3405,7 @@ class ProductsBuilderService {
2963
3405
  }
2964
3406
  async updateJob(tag, data) {
2965
3407
  try {
2966
- const job = this.fetchJob(tag);
3408
+ const job = await this.fetchJob(tag);
2967
3409
  if (!job) {
2968
3410
  throw new Error(`Job ${tag} not found`);
2969
3411
  }
@@ -2973,20 +3415,18 @@ class ProductsBuilderService {
2973
3415
  throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
2974
3416
  }
2975
3417
  await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign(Object.assign({}, job), data), { component: enums_1.ProductComponents.JOB, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
2976
- await this.initializeProduct(this.product_id);
2977
3418
  }
2978
3419
  catch (e) {
2979
3420
  throw e;
2980
3421
  }
2981
3422
  }
2982
- fetchJob(tag, throwError = false) {
2983
- const job = this.product.jobs.find((data) => data.tag === tag);
2984
- if (!job && throwError)
2985
- throw new Error(`Job ${tag} not found`);
2986
- return job;
3423
+ async fetchJobs() {
3424
+ const components = await this.productApi.fetchProductComponents(this.product_id, 'job', this.getUserAccess());
3425
+ return components;
2987
3426
  }
2988
- fetchJobs() {
2989
- return this.product.jobs;
3427
+ async fetchJob(tag) {
3428
+ const component = await this.productApi.fetchProductComponentByTag(this.product_id, 'job', tag, this.getUserAccess());
3429
+ return component;
2990
3430
  }
2991
3431
  getUserAccess() {
2992
3432
  return {
@@ -2996,6 +3436,9 @@ class ProductsBuilderService {
2996
3436
  public_key: this.public_key,
2997
3437
  };
2998
3438
  }
3439
+ async fetchSessionUser(ductape_user_id) {
3440
+ return await this.productApi.fetchProductSessionUser(ductape_user_id, this.getUserAccess());
3441
+ }
2999
3442
  }
3000
3443
  exports.default = ProductsBuilderService;
3001
3444
  //# sourceMappingURL=products.service.js.map