@ductape/sdk 0.0.1

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 (614) hide show
  1. package/README.md +58 -0
  2. package/dist/actions/actions.repo.d.ts +0 -0
  3. package/dist/actions/actions.repo.js +13 -0
  4. package/dist/actions/actions.repo.js.map +1 -0
  5. package/dist/actions/actions.service.d.ts +0 -0
  6. package/dist/actions/actions.service.js +24 -0
  7. package/dist/actions/actions.service.js.map +1 -0
  8. package/dist/actions/utils/actions.util.read.d.ts +0 -0
  9. package/dist/actions/utils/actions.util.read.js +427 -0
  10. package/dist/actions/utils/actions.util.read.js.map +1 -0
  11. package/dist/api/services/appApi.service.d.ts +30 -0
  12. package/dist/api/services/appApi.service.js +157 -0
  13. package/dist/api/services/appApi.service.js.map +1 -0
  14. package/dist/api/services/integrationsApi.service.d.ts +18 -0
  15. package/dist/api/services/integrationsApi.service.js +80 -0
  16. package/dist/api/services/integrationsApi.service.js.map +1 -0
  17. package/dist/api/services/logsApi.service.d.ts +11 -0
  18. package/dist/api/services/logsApi.service.js +50 -0
  19. package/dist/api/services/logsApi.service.js.map +1 -0
  20. package/dist/api/services/processorApi.service.d.ts +20 -0
  21. package/dist/api/services/processorApi.service.js +108 -0
  22. package/dist/api/services/processorApi.service.js.map +1 -0
  23. package/dist/api/services/productsApi.service.d.ts +19 -0
  24. package/dist/api/services/productsApi.service.js +92 -0
  25. package/dist/api/services/productsApi.service.js.map +1 -0
  26. package/dist/api/services/userApi.service.d.ts +9 -0
  27. package/dist/api/services/userApi.service.js +20 -0
  28. package/dist/api/services/userApi.service.js.map +1 -0
  29. package/dist/api/services/webhooksApi.service.d.ts +11 -0
  30. package/dist/api/services/webhooksApi.service.js +51 -0
  31. package/dist/api/services/webhooksApi.service.js.map +1 -0
  32. package/dist/api/services/workspaceApi.service.d.ts +9 -0
  33. package/dist/api/services/workspaceApi.service.js +24 -0
  34. package/dist/api/services/workspaceApi.service.js.map +1 -0
  35. package/dist/api/urls.d.ts +43 -0
  36. package/dist/api/urls.js +83 -0
  37. package/dist/api/urls.js.map +1 -0
  38. package/dist/api/utils/auth.utils.d.ts +12 -0
  39. package/dist/api/utils/auth.utils.js +24 -0
  40. package/dist/api/utils/auth.utils.js.map +1 -0
  41. package/dist/api/utils/strings.utils.d.ts +5 -0
  42. package/dist/api/utils/strings.utils.js +50 -0
  43. package/dist/api/utils/strings.utils.js.map +1 -0
  44. package/dist/appBuilder/services/app.service.d.ts +111 -0
  45. package/dist/appBuilder/services/app.service.js +737 -0
  46. package/dist/appBuilder/services/app.service.js.map +1 -0
  47. package/dist/appBuilder/services/appBuilder.service.d.ts +111 -0
  48. package/dist/appBuilder/services/appBuilder.service.js +662 -0
  49. package/dist/appBuilder/services/appBuilder.service.js.map +1 -0
  50. package/dist/appBuilder/utils/objects.utils.d.ts +3 -0
  51. package/dist/appBuilder/utils/objects.utils.js +9 -0
  52. package/dist/appBuilder/utils/objects.utils.js.map +1 -0
  53. package/dist/appBuilder/utils/string.utils.d.ts +2 -0
  54. package/dist/appBuilder/utils/string.utils.js +57 -0
  55. package/dist/appBuilder/utils/string.utils.js.map +1 -0
  56. package/dist/appBuilder/validators/index.d.ts +19 -0
  57. package/dist/appBuilder/validators/index.js +40 -0
  58. package/dist/appBuilder/validators/index.js.map +1 -0
  59. package/dist/appBuilder/validators/joi-validators/create.app.validator.d.ts +3 -0
  60. package/dist/appBuilder/validators/joi-validators/create.app.validator.js +10 -0
  61. package/dist/appBuilder/validators/joi-validators/create.app.validator.js.map +1 -0
  62. package/dist/appBuilder/validators/joi-validators/create.appAction.validator.d.ts +4 -0
  63. package/dist/appBuilder/validators/joi-validators/create.appAction.validator.js +20 -0
  64. package/dist/appBuilder/validators/joi-validators/create.appAction.validator.js.map +1 -0
  65. package/dist/appBuilder/validators/joi-validators/create.appActionResponse.validator.d.ts +7 -0
  66. package/dist/appBuilder/validators/joi-validators/create.appActionResponse.validator.js +44 -0
  67. package/dist/appBuilder/validators/joi-validators/create.appActionResponse.validator.js.map +1 -0
  68. package/dist/appBuilder/validators/joi-validators/create.appAuth.validator.d.ts +3 -0
  69. package/dist/appBuilder/validators/joi-validators/create.appAuth.validator.js +31 -0
  70. package/dist/appBuilder/validators/joi-validators/create.appAuth.validator.js.map +1 -0
  71. package/dist/appBuilder/validators/joi-validators/create.appBody.validators.d.ts +4 -0
  72. package/dist/appBuilder/validators/joi-validators/create.appBody.validators.js +11 -0
  73. package/dist/appBuilder/validators/joi-validators/create.appBody.validators.js.map +1 -0
  74. package/dist/appBuilder/validators/joi-validators/create.appConstants.validator.d.ts +4 -0
  75. package/dist/appBuilder/validators/joi-validators/create.appConstants.validator.js +12 -0
  76. package/dist/appBuilder/validators/joi-validators/create.appConstants.validator.js.map +1 -0
  77. package/dist/appBuilder/validators/joi-validators/create.appEnv.validator.d.ts +4 -0
  78. package/dist/appBuilder/validators/joi-validators/create.appEnv.validator.js +17 -0
  79. package/dist/appBuilder/validators/joi-validators/create.appEnv.validator.js.map +1 -0
  80. package/dist/appBuilder/validators/joi-validators/create.appEvent.validator.d.ts +5 -0
  81. package/dist/appBuilder/validators/joi-validators/create.appEvent.validator.js +30 -0
  82. package/dist/appBuilder/validators/joi-validators/create.appEvent.validator.js.map +1 -0
  83. package/dist/appBuilder/validators/joi-validators/create.appVariable.validator.d.ts +4 -0
  84. package/dist/appBuilder/validators/joi-validators/create.appVariable.validator.js +14 -0
  85. package/dist/appBuilder/validators/joi-validators/create.appVariable.validator.js.map +1 -0
  86. package/dist/appBuilder/validators/joi-validators/sample.validator.d.ts +5 -0
  87. package/dist/appBuilder/validators/joi-validators/sample.validator.js +26 -0
  88. package/dist/appBuilder/validators/joi-validators/sample.validator.js.map +1 -0
  89. package/dist/appBuilder/validators/joi-validators/update.app.validator.d.ts +4 -0
  90. package/dist/appBuilder/validators/joi-validators/update.app.validator.js +34 -0
  91. package/dist/appBuilder/validators/joi-validators/update.app.validator.js.map +1 -0
  92. package/dist/appBuilder/validators/joi-validators/update.appAction.validator.d.ts +4 -0
  93. package/dist/appBuilder/validators/joi-validators/update.appAction.validator.js +23 -0
  94. package/dist/appBuilder/validators/joi-validators/update.appAction.validator.js.map +1 -0
  95. package/dist/appBuilder/validators/joi-validators/update.appActionResponse.validator.d.ts +3 -0
  96. package/dist/appBuilder/validators/joi-validators/update.appActionResponse.validator.js +21 -0
  97. package/dist/appBuilder/validators/joi-validators/update.appActionResponse.validator.js.map +1 -0
  98. package/dist/appBuilder/validators/joi-validators/update.appAuth.validator.d.ts +4 -0
  99. package/dist/appBuilder/validators/joi-validators/update.appAuth.validator.js +19 -0
  100. package/dist/appBuilder/validators/joi-validators/update.appAuth.validator.js.map +1 -0
  101. package/dist/appBuilder/validators/joi-validators/update.appConstants.validator.d.ts +4 -0
  102. package/dist/appBuilder/validators/joi-validators/update.appConstants.validator.js +12 -0
  103. package/dist/appBuilder/validators/joi-validators/update.appConstants.validator.js.map +1 -0
  104. package/dist/appBuilder/validators/joi-validators/update.appEnv.validator.d.ts +4 -0
  105. package/dist/appBuilder/validators/joi-validators/update.appEnv.validator.js +17 -0
  106. package/dist/appBuilder/validators/joi-validators/update.appEnv.validator.js.map +1 -0
  107. package/dist/appBuilder/validators/joi-validators/update.appEvent.validator.d.ts +4 -0
  108. package/dist/appBuilder/validators/joi-validators/update.appEvent.validator.js +16 -0
  109. package/dist/appBuilder/validators/joi-validators/update.appEvent.validator.js.map +1 -0
  110. package/dist/appBuilder/validators/joi-validators/update.appVariables.validator.d.ts +4 -0
  111. package/dist/appBuilder/validators/joi-validators/update.appVariables.validator.js +14 -0
  112. package/dist/appBuilder/validators/joi-validators/update.appVariables.validator.js.map +1 -0
  113. package/dist/appBuilder/validators/joi-validators/update.validation.entityData.validator.d.ts +3 -0
  114. package/dist/appBuilder/validators/joi-validators/update.validation.entityData.validator.js +27 -0
  115. package/dist/appBuilder/validators/joi-validators/update.validation.entityData.validator.js.map +1 -0
  116. package/dist/apps/services/app.service.d.ts +116 -0
  117. package/dist/apps/services/app.service.js +995 -0
  118. package/dist/apps/services/app.service.js.map +1 -0
  119. package/dist/apps/utils/objects.utils.d.ts +4 -0
  120. package/dist/apps/utils/objects.utils.js +57 -0
  121. package/dist/apps/utils/objects.utils.js.map +1 -0
  122. package/dist/apps/utils/string.utils.d.ts +2 -0
  123. package/dist/apps/utils/string.utils.js +57 -0
  124. package/dist/apps/utils/string.utils.js.map +1 -0
  125. package/dist/apps/validators/index.d.ts +17 -0
  126. package/dist/apps/validators/index.js +39 -0
  127. package/dist/apps/validators/index.js.map +1 -0
  128. package/dist/apps/validators/joi-validators/create.app.validator.d.ts +3 -0
  129. package/dist/apps/validators/joi-validators/create.app.validator.js +43 -0
  130. package/dist/apps/validators/joi-validators/create.app.validator.js.map +1 -0
  131. package/dist/apps/validators/joi-validators/create.appAction.validator.d.ts +4 -0
  132. package/dist/apps/validators/joi-validators/create.appAction.validator.js +52 -0
  133. package/dist/apps/validators/joi-validators/create.appAction.validator.js.map +1 -0
  134. package/dist/apps/validators/joi-validators/create.appActionResponse.validator.d.ts +7 -0
  135. package/dist/apps/validators/joi-validators/create.appActionResponse.validator.js +79 -0
  136. package/dist/apps/validators/joi-validators/create.appActionResponse.validator.js.map +1 -0
  137. package/dist/apps/validators/joi-validators/create.appAuth.validator.d.ts +3 -0
  138. package/dist/apps/validators/joi-validators/create.appAuth.validator.js +64 -0
  139. package/dist/apps/validators/joi-validators/create.appAuth.validator.js.map +1 -0
  140. package/dist/apps/validators/joi-validators/create.appBody.validators.d.ts +4 -0
  141. package/dist/apps/validators/joi-validators/create.appBody.validators.js +44 -0
  142. package/dist/apps/validators/joi-validators/create.appBody.validators.js.map +1 -0
  143. package/dist/apps/validators/joi-validators/create.appConstants.validator.d.ts +4 -0
  144. package/dist/apps/validators/joi-validators/create.appConstants.validator.js +45 -0
  145. package/dist/apps/validators/joi-validators/create.appConstants.validator.js.map +1 -0
  146. package/dist/apps/validators/joi-validators/create.appEnv.validator.d.ts +4 -0
  147. package/dist/apps/validators/joi-validators/create.appEnv.validator.js +49 -0
  148. package/dist/apps/validators/joi-validators/create.appEnv.validator.js.map +1 -0
  149. package/dist/apps/validators/joi-validators/create.appEvent.validator.d.ts +5 -0
  150. package/dist/apps/validators/joi-validators/create.appEvent.validator.js +30 -0
  151. package/dist/apps/validators/joi-validators/create.appEvent.validator.js.map +1 -0
  152. package/dist/apps/validators/joi-validators/create.appVariable.validator.d.ts +4 -0
  153. package/dist/apps/validators/joi-validators/create.appVariable.validator.js +47 -0
  154. package/dist/apps/validators/joi-validators/create.appVariable.validator.js.map +1 -0
  155. package/dist/apps/validators/joi-validators/create.appWebhook.validator.d.ts +4 -0
  156. package/dist/apps/validators/joi-validators/create.appWebhook.validator.js +60 -0
  157. package/dist/apps/validators/joi-validators/create.appWebhook.validator.js.map +1 -0
  158. package/dist/apps/validators/joi-validators/create.appWebhookEvent.validator.d.ts +3 -0
  159. package/dist/apps/validators/joi-validators/create.appWebhookEvent.validator.js +47 -0
  160. package/dist/apps/validators/joi-validators/create.appWebhookEvent.validator.js.map +1 -0
  161. package/dist/apps/validators/joi-validators/sample.validator.d.ts +6 -0
  162. package/dist/apps/validators/joi-validators/sample.validator.js +65 -0
  163. package/dist/apps/validators/joi-validators/sample.validator.js.map +1 -0
  164. package/dist/apps/validators/joi-validators/update.app.validator.d.ts +4 -0
  165. package/dist/apps/validators/joi-validators/update.app.validator.js +64 -0
  166. package/dist/apps/validators/joi-validators/update.app.validator.js.map +1 -0
  167. package/dist/apps/validators/joi-validators/update.appAction.validator.d.ts +4 -0
  168. package/dist/apps/validators/joi-validators/update.appAction.validator.js +55 -0
  169. package/dist/apps/validators/joi-validators/update.appAction.validator.js.map +1 -0
  170. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.d.ts +3 -0
  171. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js +24 -0
  172. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js.map +1 -0
  173. package/dist/apps/validators/joi-validators/update.appAuth.validator.d.ts +4 -0
  174. package/dist/apps/validators/joi-validators/update.appAuth.validator.js +52 -0
  175. package/dist/apps/validators/joi-validators/update.appAuth.validator.js.map +1 -0
  176. package/dist/apps/validators/joi-validators/update.appConstants.validator.d.ts +4 -0
  177. package/dist/apps/validators/joi-validators/update.appConstants.validator.js +45 -0
  178. package/dist/apps/validators/joi-validators/update.appConstants.validator.js.map +1 -0
  179. package/dist/apps/validators/joi-validators/update.appEnv.validator.d.ts +4 -0
  180. package/dist/apps/validators/joi-validators/update.appEnv.validator.js +49 -0
  181. package/dist/apps/validators/joi-validators/update.appEnv.validator.js.map +1 -0
  182. package/dist/apps/validators/joi-validators/update.appEvent.validator.d.ts +4 -0
  183. package/dist/apps/validators/joi-validators/update.appEvent.validator.js +16 -0
  184. package/dist/apps/validators/joi-validators/update.appEvent.validator.js.map +1 -0
  185. package/dist/apps/validators/joi-validators/update.appVariables.validator.d.ts +4 -0
  186. package/dist/apps/validators/joi-validators/update.appVariables.validator.js +47 -0
  187. package/dist/apps/validators/joi-validators/update.appVariables.validator.js.map +1 -0
  188. package/dist/apps/validators/joi-validators/update.appWebhook.validator.d.ts +4 -0
  189. package/dist/apps/validators/joi-validators/update.appWebhook.validator.js +59 -0
  190. package/dist/apps/validators/joi-validators/update.appWebhook.validator.js.map +1 -0
  191. package/dist/apps/validators/joi-validators/update.appWebhookEvent.validator.d.ts +3 -0
  192. package/dist/apps/validators/joi-validators/update.appWebhookEvent.validator.js +46 -0
  193. package/dist/apps/validators/joi-validators/update.appWebhookEvent.validator.js.map +1 -0
  194. package/dist/apps/validators/joi-validators/update.validation.entityData.validator.d.ts +3 -0
  195. package/dist/apps/validators/joi-validators/update.validation.entityData.validator.js +60 -0
  196. package/dist/apps/validators/joi-validators/update.validation.entityData.validator.js.map +1 -0
  197. package/dist/clients/apps.client.d.ts +4 -0
  198. package/dist/clients/apps.client.js +28 -0
  199. package/dist/clients/apps.client.js.map +1 -0
  200. package/dist/clients/email.client.d.ts +3 -0
  201. package/dist/clients/email.client.js +32 -0
  202. package/dist/clients/email.client.js.map +1 -0
  203. package/dist/clients/expo.client.d.ts +3 -0
  204. package/dist/clients/expo.client.js +28 -0
  205. package/dist/clients/expo.client.js.map +1 -0
  206. package/dist/clients/function.client.d.ts +3 -0
  207. package/dist/clients/function.client.js +27 -0
  208. package/dist/clients/function.client.js.map +1 -0
  209. package/dist/clients/http.client.d.ts +3 -0
  210. package/dist/clients/http.client.js +27 -0
  211. package/dist/clients/http.client.js.map +1 -0
  212. package/dist/clients/integrations.client.d.ts +2 -0
  213. package/dist/clients/integrations.client.js +26 -0
  214. package/dist/clients/integrations.client.js.map +1 -0
  215. package/dist/clients/logs.client.d.ts +3 -0
  216. package/dist/clients/logs.client.js +33 -0
  217. package/dist/clients/logs.client.js.map +1 -0
  218. package/dist/clients/products.client.d.ts +3 -0
  219. package/dist/clients/products.client.js +29 -0
  220. package/dist/clients/products.client.js.map +1 -0
  221. package/dist/clients/users.client.d.ts +3 -0
  222. package/dist/clients/users.client.js +33 -0
  223. package/dist/clients/users.client.js.map +1 -0
  224. package/dist/clients/webhooks.client.d.ts +2 -0
  225. package/dist/clients/webhooks.client.js +33 -0
  226. package/dist/clients/webhooks.client.js.map +1 -0
  227. package/dist/clients/workspace.client.d.ts +3 -0
  228. package/dist/clients/workspace.client.js +33 -0
  229. package/dist/clients/workspace.client.js.map +1 -0
  230. package/dist/imports/imports.repo.d.ts +0 -0
  231. package/dist/imports/imports.repo.js +1 -0
  232. package/dist/imports/imports.repo.js.map +1 -0
  233. package/dist/imports/imports.service.d.ts +24 -0
  234. package/dist/imports/imports.service.js +111 -0
  235. package/dist/imports/imports.service.js.map +1 -0
  236. package/dist/imports/imports.types.d.ts +104 -0
  237. package/dist/imports/imports.types.js +33 -0
  238. package/dist/imports/imports.types.js.map +1 -0
  239. package/dist/imports/openAPI3.0.types.d.ts +52 -0
  240. package/dist/imports/openAPI3.0.types.js +3 -0
  241. package/dist/imports/openAPI3.0.types.js.map +1 -0
  242. package/dist/imports/repos/openApi.repo.d.ts +13 -0
  243. package/dist/imports/repos/openApi.repo.js +33 -0
  244. package/dist/imports/repos/openApi.repo.js.map +1 -0
  245. package/dist/imports/repos/postmanV21.repo.d.ts +14 -0
  246. package/dist/imports/repos/postmanV21.repo.js +214 -0
  247. package/dist/imports/repos/postmanV21.repo.js.map +1 -0
  248. package/dist/imports/utils/imports.utils.d.ts +80 -0
  249. package/dist/imports/utils/imports.utils.js +114 -0
  250. package/dist/imports/utils/imports.utils.js.map +1 -0
  251. package/dist/imports/validators/index.d.ts +0 -0
  252. package/dist/imports/validators/index.js +1 -0
  253. package/dist/imports/validators/index.js.map +1 -0
  254. package/dist/imports/validators/joi-validators/postmanV21.validator.d.ts +5 -0
  255. package/dist/imports/validators/joi-validators/postmanV21.validator.js +96 -0
  256. package/dist/imports/validators/joi-validators/postmanV21.validator.js.map +1 -0
  257. package/dist/index.d.ts +325 -0
  258. package/dist/index.js +923 -0
  259. package/dist/index.js.map +1 -0
  260. package/dist/inputs/inputs.repo.d.ts +7 -0
  261. package/dist/inputs/inputs.repo.js +16 -0
  262. package/dist/inputs/inputs.repo.js.map +1 -0
  263. package/dist/inputs/inputs.service.d.ts +61 -0
  264. package/dist/inputs/inputs.service.js +468 -0
  265. package/dist/inputs/inputs.service.js.map +1 -0
  266. package/dist/inputs/utils/inputs.utils.create.d.ts +11 -0
  267. package/dist/inputs/utils/inputs.utils.create.js +273 -0
  268. package/dist/inputs/utils/inputs.utils.create.js.map +1 -0
  269. package/dist/inputs/validators/inputs.validator.parse.d.ts +4 -0
  270. package/dist/inputs/validators/inputs.validator.parse.js +52 -0
  271. package/dist/inputs/validators/inputs.validator.parse.js.map +1 -0
  272. package/dist/integrationsBuilder/services/integration.service.d.ts +138 -0
  273. package/dist/integrationsBuilder/services/integration.service.js +1148 -0
  274. package/dist/integrationsBuilder/services/integration.service.js.map +1 -0
  275. package/dist/integrationsBuilder/services/integrationBuilder.service.d.ts +130 -0
  276. package/dist/integrationsBuilder/services/integrationBuilder.service.js +1017 -0
  277. package/dist/integrationsBuilder/services/integrationBuilder.service.js.map +1 -0
  278. package/dist/integrationsBuilder/utils/objects.utils.d.ts +2 -0
  279. package/dist/integrationsBuilder/utils/objects.utils.js +48 -0
  280. package/dist/integrationsBuilder/utils/objects.utils.js.map +1 -0
  281. package/dist/integrationsBuilder/utils/string.utils.d.ts +1 -0
  282. package/dist/integrationsBuilder/utils/string.utils.js +9 -0
  283. package/dist/integrationsBuilder/utils/string.utils.js.map +1 -0
  284. package/dist/integrationsBuilder/validators/index.d.ts +18 -0
  285. package/dist/integrationsBuilder/validators/index.js +38 -0
  286. package/dist/integrationsBuilder/validators/index.js.map +1 -0
  287. package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.d.ts +3 -0
  288. package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.js +10 -0
  289. package/dist/integrationsBuilder/validators/joi-validators/create.integration.validator.js.map +1 -0
  290. package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.d.ts +4 -0
  291. package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.js +26 -0
  292. package/dist/integrationsBuilder/validators/joi-validators/create.integrationApp.validator.js.map +1 -0
  293. package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.d.ts +3 -0
  294. package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.js +8 -0
  295. package/dist/integrationsBuilder/validators/joi-validators/create.integrationCache.validator.js.map +1 -0
  296. package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.d.ts +3 -0
  297. package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.js +8 -0
  298. package/dist/integrationsBuilder/validators/joi-validators/create.integrationDatabase.validator.js.map +1 -0
  299. package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.d.ts +3 -0
  300. package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.js +10 -0
  301. package/dist/integrationsBuilder/validators/joi-validators/create.integrationEnv.validator.js.map +1 -0
  302. package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.d.ts +3 -0
  303. package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.js +60 -0
  304. package/dist/integrationsBuilder/validators/joi-validators/create.integrationFeature.validator.js.map +1 -0
  305. package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.d.ts +3 -0
  306. package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.js +8 -0
  307. package/dist/integrationsBuilder/validators/joi-validators/create.integrationFunction.validator.js.map +1 -0
  308. package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.d.ts +3 -0
  309. package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.js +8 -0
  310. package/dist/integrationsBuilder/validators/joi-validators/create.integrationJob.validator.js.map +1 -0
  311. package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.d.ts +3 -0
  312. package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.js +8 -0
  313. package/dist/integrationsBuilder/validators/joi-validators/create.integrationNotification.validator.js.map +1 -0
  314. package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.d.ts +3 -0
  315. package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.js +9 -0
  316. package/dist/integrationsBuilder/validators/joi-validators/update.integrationApp.validator.js.map +1 -0
  317. package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.d.ts +3 -0
  318. package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.js +8 -0
  319. package/dist/integrationsBuilder/validators/joi-validators/update.integrationCache.validator.js.map +1 -0
  320. package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.d.ts +3 -0
  321. package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.js +8 -0
  322. package/dist/integrationsBuilder/validators/joi-validators/update.integrationDatabase.validator.js.map +1 -0
  323. package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.d.ts +3 -0
  324. package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.js +8 -0
  325. package/dist/integrationsBuilder/validators/joi-validators/update.integrationEnv.validator.js.map +1 -0
  326. package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.d.ts +3 -0
  327. package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.js +8 -0
  328. package/dist/integrationsBuilder/validators/joi-validators/update.integrationFeature.validator.js.map +1 -0
  329. package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.d.ts +3 -0
  330. package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.js +8 -0
  331. package/dist/integrationsBuilder/validators/joi-validators/update.integrationFunction.validator copy.js.map +1 -0
  332. package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.d.ts +3 -0
  333. package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.js +8 -0
  334. package/dist/integrationsBuilder/validators/joi-validators/update.integrationJob.validator.js.map +1 -0
  335. package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.d.ts +3 -0
  336. package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.js +8 -0
  337. package/dist/integrationsBuilder/validators/joi-validators/update.integrationNotification.validator.js.map +1 -0
  338. package/dist/logs/logs.repo.d.ts +6 -0
  339. package/dist/logs/logs.repo.js +12 -0
  340. package/dist/logs/logs.repo.js.map +1 -0
  341. package/dist/logs/logs.service.d.ts +29 -0
  342. package/dist/logs/logs.service.js +70 -0
  343. package/dist/logs/logs.service.js.map +1 -0
  344. package/dist/logs/logs.types.d.ts +44 -0
  345. package/dist/logs/logs.types.js +31 -0
  346. package/dist/logs/logs.types.js.map +1 -0
  347. package/dist/logs/utils/logs.utils.create.d.ts +0 -0
  348. package/dist/logs/utils/logs.utils.create.js +1 -0
  349. package/dist/logs/utils/logs.utils.create.js.map +1 -0
  350. package/dist/logs/utils/logs.utils.errors.d.ts +2 -0
  351. package/dist/logs/utils/logs.utils.errors.js +8 -0
  352. package/dist/logs/utils/logs.utils.errors.js.map +1 -0
  353. package/dist/postman.d.ts +1 -0
  354. package/dist/postman.js +21674 -0
  355. package/dist/postman.js.map +1 -0
  356. package/dist/processor/repos/mongo.repo.d.ts +39 -0
  357. package/dist/processor/repos/mongo.repo.js +260 -0
  358. package/dist/processor/repos/mongo.repo.js.map +1 -0
  359. package/dist/processor/repos/postgres.repo.d.ts +31 -0
  360. package/dist/processor/repos/postgres.repo.js +185 -0
  361. package/dist/processor/repos/postgres.repo.js.map +1 -0
  362. package/dist/processor/repos/sms.repo.d.ts +39 -0
  363. package/dist/processor/repos/sms.repo.js +111 -0
  364. package/dist/processor/repos/sms.repo.js.map +1 -0
  365. package/dist/processor/services/fallback.service.d.ts +6 -0
  366. package/dist/processor/services/fallback.service.js +59 -0
  367. package/dist/processor/services/fallback.service.js.map +1 -0
  368. package/dist/processor/services/messagebrokers/aws-sqs.service.d.ts +15 -0
  369. package/dist/processor/services/messagebrokers/aws-sqs.service.js +77 -0
  370. package/dist/processor/services/messagebrokers/aws-sqs.service.js.map +1 -0
  371. package/dist/processor/services/messagebrokers/google-pubsub.service.d.ts +16 -0
  372. package/dist/processor/services/messagebrokers/google-pubsub.service.js +34 -0
  373. package/dist/processor/services/messagebrokers/google-pubsub.service.js.map +1 -0
  374. package/dist/processor/services/messagebrokers/index.d.ts +3 -0
  375. package/dist/processor/services/messagebrokers/index.js +26 -0
  376. package/dist/processor/services/messagebrokers/index.js.map +1 -0
  377. package/dist/processor/services/messagebrokers/kafka.service.d.ts +14 -0
  378. package/dist/processor/services/messagebrokers/kafka.service.js +45 -0
  379. package/dist/processor/services/messagebrokers/kafka.service.js.map +1 -0
  380. package/dist/processor/services/messagebrokers/messagebrokers.type.d.ts +6 -0
  381. package/dist/processor/services/messagebrokers/messagebrokers.type.js +3 -0
  382. package/dist/processor/services/messagebrokers/messagebrokers.type.js.map +1 -0
  383. package/dist/processor/services/messagebrokers/rabbitmq.service.d.ts +14 -0
  384. package/dist/processor/services/messagebrokers/rabbitmq.service.js +67 -0
  385. package/dist/processor/services/messagebrokers/rabbitmq.service.js.map +1 -0
  386. package/dist/processor/services/messagebrokers/redis.service.d.ts +16 -0
  387. package/dist/processor/services/messagebrokers/redis.service.js +34 -0
  388. package/dist/processor/services/messagebrokers/redis.service.js.map +1 -0
  389. package/dist/processor/services/processor.service.d.ts +189 -0
  390. package/dist/processor/services/processor.service.js +3078 -0
  391. package/dist/processor/services/processor.service.js.map +1 -0
  392. package/dist/processor/services/quota.service.d.ts +22 -0
  393. package/dist/processor/services/quota.service.js +54 -0
  394. package/dist/processor/services/quota.service.js.map +1 -0
  395. package/dist/processor/utils/mongo.util.d.ts +0 -0
  396. package/dist/processor/utils/mongo.util.js +152 -0
  397. package/dist/processor/utils/mongo.util.js.map +1 -0
  398. package/dist/processor/utils/postgres.util.d.ts +14 -0
  399. package/dist/processor/utils/postgres.util.js +83 -0
  400. package/dist/processor/utils/postgres.util.js.map +1 -0
  401. package/dist/processor/utils/processor.utils.d.ts +323 -0
  402. package/dist/processor/utils/processor.utils.js +906 -0
  403. package/dist/processor/utils/processor.utils.js.map +1 -0
  404. package/dist/processor/utils/storage.util.d.ts +8 -0
  405. package/dist/processor/utils/storage.util.js +83 -0
  406. package/dist/processor/utils/storage.util.js.map +1 -0
  407. package/dist/products/services/products.service.d.ts +225 -0
  408. package/dist/products/services/products.service.js +2762 -0
  409. package/dist/products/services/products.service.js.map +1 -0
  410. package/dist/products/utils/crypt.utils.d.ts +1 -0
  411. package/dist/products/utils/crypt.utils.js +17 -0
  412. package/dist/products/utils/crypt.utils.js.map +1 -0
  413. package/dist/products/utils/functions.utils.d.ts +12 -0
  414. package/dist/products/utils/functions.utils.js +283 -0
  415. package/dist/products/utils/functions.utils.js.map +1 -0
  416. package/dist/products/utils/objects.utils.d.ts +13 -0
  417. package/dist/products/utils/objects.utils.js +89 -0
  418. package/dist/products/utils/objects.utils.js.map +1 -0
  419. package/dist/products/utils/string.utils.d.ts +12 -0
  420. package/dist/products/utils/string.utils.js +155 -0
  421. package/dist/products/utils/string.utils.js.map +1 -0
  422. package/dist/products/validators/index.d.ts +25 -0
  423. package/dist/products/validators/index.js +56 -0
  424. package/dist/products/validators/index.js.map +1 -0
  425. package/dist/products/validators/joi-validators/create.html.validator.d.ts +2 -0
  426. package/dist/products/validators/joi-validators/create.html.validator.js +55 -0
  427. package/dist/products/validators/joi-validators/create.html.validator.js.map +1 -0
  428. package/dist/products/validators/joi-validators/create.product.validator.d.ts +3 -0
  429. package/dist/products/validators/joi-validators/create.product.validator.js +10 -0
  430. package/dist/products/validators/joi-validators/create.product.validator.js.map +1 -0
  431. package/dist/products/validators/joi-validators/create.productApp.validator.d.ts +4 -0
  432. package/dist/products/validators/joi-validators/create.productApp.validator.js +61 -0
  433. package/dist/products/validators/joi-validators/create.productApp.validator.js.map +1 -0
  434. package/dist/products/validators/joi-validators/create.productCache.validator.d.ts +3 -0
  435. package/dist/products/validators/joi-validators/create.productCache.validator.js +46 -0
  436. package/dist/products/validators/joi-validators/create.productCache.validator.js.map +1 -0
  437. package/dist/products/validators/joi-validators/create.productDatabase.validator.d.ts +3 -0
  438. package/dist/products/validators/joi-validators/create.productDatabase.validator.js +72 -0
  439. package/dist/products/validators/joi-validators/create.productDatabase.validator.js.map +1 -0
  440. package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.d.ts +7 -0
  441. package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js +187 -0
  442. package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js.map +1 -0
  443. package/dist/products/validators/joi-validators/create.productDatabaseMigration.validator.d.ts +4 -0
  444. package/dist/products/validators/joi-validators/create.productDatabaseMigration.validator.js +63 -0
  445. package/dist/products/validators/joi-validators/create.productDatabaseMigration.validator.js.map +1 -0
  446. package/dist/products/validators/joi-validators/create.productEnv.validator.d.ts +3 -0
  447. package/dist/products/validators/joi-validators/create.productEnv.validator.js +44 -0
  448. package/dist/products/validators/joi-validators/create.productEnv.validator.js.map +1 -0
  449. package/dist/products/validators/joi-validators/create.productFallback.validator.d.ts +3 -0
  450. package/dist/products/validators/joi-validators/create.productFallback.validator.js +58 -0
  451. package/dist/products/validators/joi-validators/create.productFallback.validator.js.map +1 -0
  452. package/dist/products/validators/joi-validators/create.productFeature.validator.d.ts +12 -0
  453. package/dist/products/validators/joi-validators/create.productFeature.validator.js +124 -0
  454. package/dist/products/validators/joi-validators/create.productFeature.validator.js.map +1 -0
  455. package/dist/products/validators/joi-validators/create.productFunction.validator.d.ts +3 -0
  456. package/dist/products/validators/joi-validators/create.productFunction.validator.js +57 -0
  457. package/dist/products/validators/joi-validators/create.productFunction.validator.js.map +1 -0
  458. package/dist/products/validators/joi-validators/create.productJob.validator.d.ts +12 -0
  459. package/dist/products/validators/joi-validators/create.productJob.validator.js +60 -0
  460. package/dist/products/validators/joi-validators/create.productJob.validator.js.map +1 -0
  461. package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.d.ts +3 -0
  462. package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js +51 -0
  463. package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js.map +1 -0
  464. package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.d.ts +3 -0
  465. package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js +137 -0
  466. package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js.map +1 -0
  467. package/dist/products/validators/joi-validators/create.productNotification.validator.d.ts +4 -0
  468. package/dist/products/validators/joi-validators/create.productNotification.validator.js +142 -0
  469. package/dist/products/validators/joi-validators/create.productNotification.validator.js.map +1 -0
  470. package/dist/products/validators/joi-validators/create.productNotificationMessage.validator.d.ts +3 -0
  471. package/dist/products/validators/joi-validators/create.productNotificationMessage.validator.js +57 -0
  472. package/dist/products/validators/joi-validators/create.productNotificationMessage.validator.js.map +1 -0
  473. package/dist/products/validators/joi-validators/create.productNotifications.validator.d.ts +0 -0
  474. package/dist/products/validators/joi-validators/create.productNotifications.validator.js +1 -0
  475. package/dist/products/validators/joi-validators/create.productNotifications.validator.js.map +1 -0
  476. package/dist/products/validators/joi-validators/create.productQuota.validator.d.ts +3 -0
  477. package/dist/products/validators/joi-validators/create.productQuota.validator.js +59 -0
  478. package/dist/products/validators/joi-validators/create.productQuota.validator.js.map +1 -0
  479. package/dist/products/validators/joi-validators/create.productStorage.validator.d.ts +3 -0
  480. package/dist/products/validators/joi-validators/create.productStorage.validator.js +99 -0
  481. package/dist/products/validators/joi-validators/create.productStorage.validator.js.map +1 -0
  482. package/dist/products/validators/joi-validators/create.products.validator.d.ts +3 -0
  483. package/dist/products/validators/joi-validators/create.products.validator.js +43 -0
  484. package/dist/products/validators/joi-validators/create.products.validator.js.map +1 -0
  485. package/dist/products/validators/joi-validators/create.requestAction.validator.d.ts +2 -0
  486. package/dist/products/validators/joi-validators/create.requestAction.validator.js +45 -0
  487. package/dist/products/validators/joi-validators/create.requestAction.validator.js.map +1 -0
  488. package/dist/products/validators/joi-validators/register.productWebhooks.validator.d.ts +3 -0
  489. package/dist/products/validators/joi-validators/register.productWebhooks.validator.js +48 -0
  490. package/dist/products/validators/joi-validators/register.productWebhooks.validator.js.map +1 -0
  491. package/dist/products/validators/joi-validators/update.dataValue.validator.d.ts +3 -0
  492. package/dist/products/validators/joi-validators/update.dataValue.validator.js +101 -0
  493. package/dist/products/validators/joi-validators/update.dataValue.validator.js.map +1 -0
  494. package/dist/products/validators/joi-validators/update.productApp.validator.d.ts +3 -0
  495. package/dist/products/validators/joi-validators/update.productApp.validator.js +42 -0
  496. package/dist/products/validators/joi-validators/update.productApp.validator.js.map +1 -0
  497. package/dist/products/validators/joi-validators/update.productCache.validator.d.ts +3 -0
  498. package/dist/products/validators/joi-validators/update.productCache.validator.js +45 -0
  499. package/dist/products/validators/joi-validators/update.productCache.validator.js.map +1 -0
  500. package/dist/products/validators/joi-validators/update.productDatabase.validator.d.ts +3 -0
  501. package/dist/products/validators/joi-validators/update.productDatabase.validator.js +71 -0
  502. package/dist/products/validators/joi-validators/update.productDatabase.validator.js.map +1 -0
  503. package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.d.ts +3 -0
  504. package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.js +79 -0
  505. package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.js.map +1 -0
  506. package/dist/products/validators/joi-validators/update.productDatabaseMigration.validator.d.ts +4 -0
  507. package/dist/products/validators/joi-validators/update.productDatabaseMigration.validator.js +64 -0
  508. package/dist/products/validators/joi-validators/update.productDatabaseMigration.validator.js.map +1 -0
  509. package/dist/products/validators/joi-validators/update.productEnv.validator.d.ts +3 -0
  510. package/dist/products/validators/joi-validators/update.productEnv.validator.js +43 -0
  511. package/dist/products/validators/joi-validators/update.productEnv.validator.js.map +1 -0
  512. package/dist/products/validators/joi-validators/update.productFallback.validator.d.ts +3 -0
  513. package/dist/products/validators/joi-validators/update.productFallback.validator.js +55 -0
  514. package/dist/products/validators/joi-validators/update.productFallback.validator.js.map +1 -0
  515. package/dist/products/validators/joi-validators/update.productFeature.validator.d.ts +3 -0
  516. package/dist/products/validators/joi-validators/update.productFeature.validator.js +51 -0
  517. package/dist/products/validators/joi-validators/update.productFeature.validator.js.map +1 -0
  518. package/dist/products/validators/joi-validators/update.productFunction.validator.d.ts +3 -0
  519. package/dist/products/validators/joi-validators/update.productFunction.validator.js +41 -0
  520. package/dist/products/validators/joi-validators/update.productFunction.validator.js.map +1 -0
  521. package/dist/products/validators/joi-validators/update.productJob.validator.d.ts +3 -0
  522. package/dist/products/validators/joi-validators/update.productJob.validator.js +50 -0
  523. package/dist/products/validators/joi-validators/update.productJob.validator.js.map +1 -0
  524. package/dist/products/validators/joi-validators/update.productMessageBrokerTopic.validator.d.ts +3 -0
  525. package/dist/products/validators/joi-validators/update.productMessageBrokerTopic.validator.js +52 -0
  526. package/dist/products/validators/joi-validators/update.productMessageBrokerTopic.validator.js.map +1 -0
  527. package/dist/products/validators/joi-validators/update.productNotification.validator.d.ts +3 -0
  528. package/dist/products/validators/joi-validators/update.productNotification.validator.js +47 -0
  529. package/dist/products/validators/joi-validators/update.productNotification.validator.js.map +1 -0
  530. package/dist/products/validators/joi-validators/update.productNotificationMessage.validator.d.ts +3 -0
  531. package/dist/products/validators/joi-validators/update.productNotificationMessage.validator.js +57 -0
  532. package/dist/products/validators/joi-validators/update.productNotificationMessage.validator.js.map +1 -0
  533. package/dist/products/validators/joi-validators/update.productQuota.validator.d.ts +3 -0
  534. package/dist/products/validators/joi-validators/update.productQuota.validator.js +59 -0
  535. package/dist/products/validators/joi-validators/update.productQuota.validator.js.map +1 -0
  536. package/dist/test/test.appBuilder.d.ts +1 -0
  537. package/dist/test/test.appBuilder.js +16 -0
  538. package/dist/test/test.appBuilder.js.map +1 -0
  539. package/dist/test/test.import.d.ts +1 -0
  540. package/dist/test/test.import.js +1460 -0
  541. package/dist/test/test.import.js.map +1 -0
  542. package/dist/test/test.imports.d.ts +1 -0
  543. package/dist/test/test.imports.js +62 -0
  544. package/dist/test/test.imports.js.map +1 -0
  545. package/dist/test/test.logs.d.ts +1 -0
  546. package/dist/test/test.logs.js +19 -0
  547. package/dist/test/test.logs.js.map +1 -0
  548. package/dist/test/test.processor.d.ts +1 -0
  549. package/dist/test/test.processor.js +123 -0
  550. package/dist/test/test.processor.js.map +1 -0
  551. package/dist/test/test.productBuilder.d.ts +1 -0
  552. package/dist/test/test.productBuilder.js +661 -0
  553. package/dist/test/test.productBuilder.js.map +1 -0
  554. package/dist/test.appBuilder.d.ts +1 -0
  555. package/dist/test.appBuilder.js +14 -0
  556. package/dist/test.appBuilder.js.map +1 -0
  557. package/dist/test.import.d.ts +0 -0
  558. package/dist/test.import.js +24 -0
  559. package/dist/test.import.js.map +1 -0
  560. package/dist/test.imports.d.ts +1 -0
  561. package/dist/test.imports.js +28 -0
  562. package/dist/test.imports.js.map +1 -0
  563. package/dist/test.integrationBuilder.d.ts +1 -0
  564. package/dist/test.integrationBuilder.js +276 -0
  565. package/dist/test.integrationBuilder.js.map +1 -0
  566. package/dist/test.processor.d.ts +1 -0
  567. package/dist/test.processor.js +23 -0
  568. package/dist/test.processor.js.map +1 -0
  569. package/dist/test.utils.d.ts +1 -0
  570. package/dist/test.utils.js +25 -0
  571. package/dist/test.utils.js.map +1 -0
  572. package/dist/types/actions.types.d.ts +0 -0
  573. package/dist/types/actions.types.js +1 -0
  574. package/dist/types/actions.types.js.map +1 -0
  575. package/dist/types/appBuilder.types.d.ts +293 -0
  576. package/dist/types/appBuilder.types.js +3 -0
  577. package/dist/types/appBuilder.types.js.map +1 -0
  578. package/dist/types/database.types.d.ts +9 -0
  579. package/dist/types/database.types.js +3 -0
  580. package/dist/types/database.types.js.map +1 -0
  581. package/dist/types/enums.d.ts +215 -0
  582. package/dist/types/enums.js +244 -0
  583. package/dist/types/enums.js.map +1 -0
  584. package/dist/types/index.d.ts +12 -0
  585. package/dist/types/index.js +29 -0
  586. package/dist/types/index.js.map +1 -0
  587. package/dist/types/index.types.d.ts +26 -0
  588. package/dist/types/index.types.js +10 -0
  589. package/dist/types/index.types.js.map +1 -0
  590. package/dist/types/inputs.types.d.ts +111 -0
  591. package/dist/types/inputs.types.js +43 -0
  592. package/dist/types/inputs.types.js.map +1 -0
  593. package/dist/types/integrationsBuilder.types.d.ts +276 -0
  594. package/dist/types/integrationsBuilder.types.js +51 -0
  595. package/dist/types/integrationsBuilder.types.js.map +1 -0
  596. package/dist/types/logs.types.d.ts +19 -0
  597. package/dist/types/logs.types.js +8 -0
  598. package/dist/types/logs.types.js.map +1 -0
  599. package/dist/types/processor.types.d.ts +270 -0
  600. package/dist/types/processor.types.js +11 -0
  601. package/dist/types/processor.types.js.map +1 -0
  602. package/dist/types/productsBuilder.types.d.ts +560 -0
  603. package/dist/types/productsBuilder.types.js +89 -0
  604. package/dist/types/productsBuilder.types.js.map +1 -0
  605. package/dist/types/requests.types.d.ts +6 -0
  606. package/dist/types/requests.types.js +3 -0
  607. package/dist/types/requests.types.js.map +1 -0
  608. package/dist/types/workspaces.types.d.ts +28 -0
  609. package/dist/types/workspaces.types.js +4 -0
  610. package/dist/types/workspaces.types.js.map +1 -0
  611. package/dist/utils/index.d.ts +4 -0
  612. package/dist/utils/index.js +79 -0
  613. package/dist/utils/index.js.map +1 -0
  614. package/package.json +63 -0
@@ -0,0 +1,2762 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ const appApi_service_1 = require("../../api/services/appApi.service");
18
+ const productsApi_service_1 = require("../../api/services/productsApi.service");
19
+ const userApi_service_1 = require("../../api/services/userApi.service");
20
+ const inputs_service_1 = __importDefault(require("../../inputs/inputs.service"));
21
+ const inputs_utils_create_1 = require("../../inputs/utils/inputs.utils.create");
22
+ const enums_1 = require("../../types/enums");
23
+ const productsBuilder_types_1 = require("../../types/productsBuilder.types");
24
+ const validators_1 = require("../validators");
25
+ const objects_utils_1 = require("../utils/objects.utils");
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");
29
+ const create_productStorage_validator_1 = require("../validators/joi-validators/create.productStorage.validator");
30
+ const inputs_types_1 = require("../../types/inputs.types");
31
+ const string_utils_1 = require("../utils/string.utils");
32
+ const workspaceApi_service_1 = require("../../api/services/workspaceApi.service");
33
+ const string_utils_2 = require("../../apps/utils/string.utils");
34
+ const create_productDatabaseMigration_validator_1 = __importDefault(require("../validators/joi-validators/create.productDatabaseMigration.validator"));
35
+ const update_productDatabaseMigration_validator_1 = __importDefault(require("../validators/joi-validators/update.productDatabaseMigration.validator"));
36
+ const create_productNotificationMessage_validator_1 = __importDefault(require("../validators/joi-validators/create.productNotificationMessage.validator"));
37
+ const create_productMessageBrokerTopic_validator_1 = __importDefault(require("../validators/joi-validators/create.productMessageBrokerTopic.validator"));
38
+ const update_productMessageBrokerTopic_validator_1 = __importDefault(require("../validators/joi-validators/update.productMessageBrokerTopic.validator"));
39
+ const update_productNotificationMessage_validator_1 = __importDefault(require("../validators/joi-validators/update.productNotificationMessage.validator"));
40
+ const create_productNotification_validator_1 = require("../validators/joi-validators/create.productNotification.validator");
41
+ const functions_utils_1 = require("../utils/functions.utils");
42
+ const objects_utils_2 = require("../../apps/utils/objects.utils");
43
+ class ProductsBuilderService {
44
+ constructor({ workspace_id, public_key, user_id, token, env_type }) {
45
+ this.workspace_id = workspace_id;
46
+ this.public_key = public_key;
47
+ this.user_id = user_id;
48
+ this.token = token;
49
+ this.userApi = new userApi_service_1.UserApiService(env_type);
50
+ this.productApi = new productsApi_service_1.ProductsApiService(env_type);
51
+ this.workspaceApi = new workspaceApi_service_1.WorkspaceApiService(env_type);
52
+ this.appApi = new appApi_service_1.AppApiService(env_type);
53
+ this.inputsService = new inputs_service_1.default();
54
+ this.thirdPartyApps = [];
55
+ }
56
+ async updateDataValidation(selector, update) {
57
+ if (!selector.startsWith('$Data{') && !selector.startsWith('$Filter')) {
58
+ throw new Error(`selector ${selector} is expected to start with $Data or $Filter`);
59
+ }
60
+ let useData = true;
61
+ if (selector.startsWith('$Filter')) {
62
+ useData = false;
63
+ }
64
+ await validators_1.UpdateParsedSampleSchema.validateAsync(update);
65
+ const stages = this.extractStages(selector);
66
+ if (stages.length < 3) {
67
+ throw new Error(`Invalid selector ${selector}`);
68
+ }
69
+ const tag = stages[0];
70
+ const type = stages[1];
71
+ let size = 2;
72
+ let data;
73
+ switch (type) {
74
+ case productsBuilder_types_1.FeatureEventTypes.DB_ACTION:
75
+ const action = this.fetchDatabaseAction(tag);
76
+ if (!action)
77
+ throw new Error(`DB Action ${tag} not found`);
78
+ data = useData ? action.data : action.filterData;
79
+ break;
80
+ case productsBuilder_types_1.FeatureEventTypes.NOTIFICATION:
81
+ size = 3;
82
+ if (!stages[3] || (stages[3] !== 'push' && stages[3] !== 'callback' && stages[3] !== 'email')) {
83
+ throw new Error(`Invalid value ${stages[3]} in ${selector}, expected to be "push", "callback" or "email" in notification`);
84
+ }
85
+ const notification = this.fetchNotificationMessage(tag);
86
+ if (!notification)
87
+ throw new Error(`Notification ${tag} not found`);
88
+ if (stages[3] === 'push') {
89
+ data = notification.push_notification_data;
90
+ }
91
+ if (stages[3] === 'callback') {
92
+ data = notification.callback_data;
93
+ }
94
+ if (stages[3] === 'email') {
95
+ data = notification.email_data;
96
+ }
97
+ break;
98
+ default:
99
+ throw new Error(`Type ${type} not handled`);
100
+ }
101
+ if (selector.startsWith('$Filter') && type !== productsBuilder_types_1.FeatureEventTypes.DB_ACTION) {
102
+ throw new Error(`Filter cannot be used for ${type} in ${selector} only usable in ${productsBuilder_types_1.FeatureEventTypes.DB_ACTION}`);
103
+ }
104
+ const selectorArray = stages.slice(size);
105
+ let parent_key = '';
106
+ let exists;
107
+ for (let i = 0; i < selectorArray.length; i++) {
108
+ if (i > 0) {
109
+ exists = data.findIndex((d) => {
110
+ return d.key === selectorArray[i] && d.parent_key === parent_key;
111
+ });
112
+ }
113
+ if (i === 0) {
114
+ exists = data.findIndex((d) => {
115
+ return d.key === selectorArray[i] && (d.parent_key === parent_key || !d.parent_key);
116
+ });
117
+ }
118
+ if (exists === -1) {
119
+ throw new Error(`Invalid value ${selectorArray[i]} in selector ${selector}`);
120
+ }
121
+ }
122
+ const newValue = Object.assign(Object.assign({}, data[exists]), update);
123
+ return false;
124
+ }
125
+ async createProduct(data) {
126
+ try {
127
+ await validators_1.CreateProductBuilderSchema.validateAsync(data);
128
+ const exists = await this.checkIfProductExists(data.name);
129
+ if (exists && (exists === null || exists === void 0 ? void 0 : exists._id)) {
130
+ await this.initializeProduct(exists === null || exists === void 0 ? void 0 : exists._id);
131
+ }
132
+ else {
133
+ const product = await this.createNewProduct(data);
134
+ await this.initializeProduct(product._id);
135
+ }
136
+ }
137
+ catch (e) {
138
+ throw e;
139
+ }
140
+ }
141
+ async initializeWorkspace(subCheck = true) {
142
+ if (!this.workspace) {
143
+ this.workspace = await this.workspaceApi.fetchWorkspaceById(this.getUserAccess(), subCheck);
144
+ }
145
+ }
146
+ async initializeProduct(product_id) {
147
+ try {
148
+ this.product = await this.productApi.fetchProduct(product_id, this.getUserAccess());
149
+ this.product_id = product_id;
150
+ }
151
+ catch (e) {
152
+ throw e;
153
+ }
154
+ }
155
+ async initializeProductByTag(tag) {
156
+ try {
157
+ this.product = await this.productApi.fetchProductByTag(tag, this.getUserAccess());
158
+ this.product_id = this.product._id;
159
+ }
160
+ catch (e) {
161
+ throw e;
162
+ }
163
+ }
164
+ async updateProduct(data) {
165
+ try {
166
+ if (!this.app_id)
167
+ throw new Error('Product not initialized');
168
+ await validators_1.CreateProductBuilderSchema.validateAsync(data);
169
+ await this.productApi.updateProduct(this.product_id, Object.assign({}, data), this.getUserAccess());
170
+ await this.initializeProduct(this.product_id);
171
+ }
172
+ catch (e) {
173
+ throw e;
174
+ }
175
+ }
176
+ async createNewProduct(data) {
177
+ return this.productApi.createProduct(Object.assign({}, data), this.getUserAccess());
178
+ }
179
+ async checkIfProductExists(name) {
180
+ try {
181
+ return await this.productApi.checkProductNameExists(name, this.getUserAccess());
182
+ }
183
+ catch (e) {
184
+ return false;
185
+ }
186
+ }
187
+ fetchProduct() {
188
+ if (!this.product) {
189
+ throw new Error('Product not yet initiated');
190
+ }
191
+ return this.product;
192
+ }
193
+ async createMessageBrokerTopic(data, throwErrorIfExists = false) {
194
+ try {
195
+ if (!data.tag) {
196
+ throw new Error('tag field is required');
197
+ }
198
+ const [messageBrokerTag, tag] = data.tag.split(':');
199
+ if (!messageBrokerTag || !tag) {
200
+ throw new Error(`tag is expected to be defined as "messageBroker_tag:topic_tag"`);
201
+ }
202
+ if (data.sample)
203
+ data.sample = JSON.stringify(data.sample);
204
+ await create_productMessageBrokerTopic_validator_1.default.validateAsync(data);
205
+ const exists = this.fetchMessageBrokerTopic(data.tag);
206
+ const broker = this.fetchMessageBroker(messageBrokerTag);
207
+ (0, functions_utils_1.validateAWSSQSQueueUrl)(broker.envs, data.queueUrls);
208
+ data.tag = tag;
209
+ if (!exists) {
210
+ if (data.sample) {
211
+ data.data = (await (0, string_utils_1.extractPlaceholders)(data.sample));
212
+ }
213
+ 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());
214
+ await this.initializeProduct(this.product_id);
215
+ }
216
+ else {
217
+ if (throwErrorIfExists)
218
+ throw new Error(`Message Broker Topic ${data.tag} already exists`);
219
+ }
220
+ }
221
+ catch (e) {
222
+ throw e;
223
+ }
224
+ }
225
+ async updateMessageBrokerTopic(data) {
226
+ try {
227
+ if (data.sample)
228
+ data.sample = JSON.stringify(data.sample);
229
+ await update_productMessageBrokerTopic_validator_1.default.validateAsync(data);
230
+ if (!data.tag) {
231
+ throw new Error('tag field is required');
232
+ }
233
+ const [messageBrokerTag, tag] = data.tag.split(':');
234
+ if (!messageBrokerTag || !tag) {
235
+ throw new Error(`tag is expected to be defined as "messageBrokr_tag:topic_tag"`);
236
+ }
237
+ const exists = this.fetchMessageBrokerTopic(data.tag);
238
+ if (!exists) {
239
+ throw new Error(`Topic ${data.tag} not found`);
240
+ }
241
+ const broker = this.fetchMessageBroker(messageBrokerTag);
242
+ if (data.queueUrls) {
243
+ (0, functions_utils_1.validateAWSSQSQueueUrl)(broker.envs, data.queueUrls);
244
+ }
245
+ data.tag = tag;
246
+ if (exists) {
247
+ if (data.sample) {
248
+ data.data = (await (0, string_utils_1.extractPlaceholders)(data.sample));
249
+ }
250
+ 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());
251
+ await this.initializeProduct(this.product_id);
252
+ }
253
+ else {
254
+ throw new Error(`Message Broker Topic ${data.tag} not found`);
255
+ }
256
+ }
257
+ catch (e) {
258
+ throw e;
259
+ }
260
+ }
261
+ fetchMessageBrokerTopic(tag, throwErrorIfExists = false) {
262
+ const [messageBrokerTag, topicTag] = tag.split(':');
263
+ if (!messageBrokerTag || !topicTag) {
264
+ throw new Error(`tag is expected to be defined as "messageBroker_tag:topic_tag"`);
265
+ }
266
+ const messageBroker = this.product.messageBrokers.find((data) => data.tag === messageBrokerTag);
267
+ if (!messageBroker)
268
+ throw new Error(`MessageBroker ${messageBrokerTag} not found`);
269
+ const topic = messageBroker.topics.find((data) => data.tag === topicTag);
270
+ if (!topic && throwErrorIfExists)
271
+ throw new Error(`MessageBroker topic ${tag} not found`);
272
+ return topic;
273
+ }
274
+ fetchMessageBrokerTopics(messageBrokerTag) {
275
+ const messageBroker = this.product.messageBrokers.find((data) => data.tag === messageBrokerTag);
276
+ if (!messageBroker)
277
+ throw new Error(`Message Broker ${messageBrokerTag} not found`);
278
+ return messageBroker.topics;
279
+ }
280
+ async validateQuotaFallbackInputAndOutput(data) {
281
+ const input = data.input;
282
+ await Promise.all(data.options.map(async (d, index) => {
283
+ await this.validateQuotaFallbackInput(d, input);
284
+ const pastOutput = index > 0 ? data.options[index - 1].output : null;
285
+ await this.validateQuotaFallbackOutput(d, pastOutput, input);
286
+ }));
287
+ }
288
+ async validateQuotaFallbackInput(option, input) {
289
+ if (option.type === productsBuilder_types_1.FeatureEventTypes.ACTION) {
290
+ const _a = await this.fetchThirdPartyAppByAccessTag(option.app), { version } = _a, appData = __rest(_a, ["version"]);
291
+ if (!appData) {
292
+ throw new Error(`App ${option.app} not found`);
293
+ }
294
+ this.isQuotaFallbackInput = true;
295
+ const { actions } = appData.versions.find((data) => data.tag === version);
296
+ const action = actions.find((data) => data.tag === option.event);
297
+ if (!appData) {
298
+ throw new Error(`Action ${option.event} not found in ${option.app} version ${version}`);
299
+ }
300
+ await this.validateActionDataInput({ input }, action, option.input, 0, 0);
301
+ }
302
+ else {
303
+ const feature = this.fetchFeature(option.event);
304
+ if (!feature) {
305
+ throw new Error(`Feature ${option.event} not found`);
306
+ }
307
+ (0, objects_utils_2.validateObjectKeys)(feature.input, option.input);
308
+ const keyValues = (0, objects_utils_1.traverseObject)(option.input);
309
+ for (let keyValue of keyValues) {
310
+ const { key, value } = keyValue;
311
+ if (!value.startsWith('$Input{')) {
312
+ //throw new Error(`Feature input ${value} is invalid, all feature Inputs are expected to start with $Input{}`);
313
+ }
314
+ }
315
+ }
316
+ this.isQuotaFallbackInput = false;
317
+ }
318
+ async validateQuotaFallbackOutput(
319
+ /*app: string,
320
+ event: string,
321
+ response: Record<string, unknown>,
322
+ input: Record<string, IFeatureInput>,*/
323
+ option, pastResponse, input) {
324
+ /*const { version, ...appData } = await this.fetchThirdPartyAppByAccessTag(option.app);
325
+
326
+ if (!appData) {
327
+ throw new Error(`App ${option.app} not found`);
328
+ }
329
+
330
+ const { actions } = appData.versions.find((data) => data.tag === version);
331
+
332
+ const action = actions.find((data) => data.tag === option.event);
333
+
334
+ if (!appData) {
335
+ throw new Error(`Action ${event} not found in ${option.app} version ${version}`);
336
+ }
337
+ if (pastResponse) {
338
+ validateObjectKeys(response, pastResponse);
339
+ }
340
+
341
+ const res = action.responses.find((item) => item.success === true);
342
+ // fetch success result
343
+
344
+ if (!res) {
345
+ throw new Error(`event ${event} does not have a success response`);
346
+ }
347
+
348
+ await this.validateActionResponse(response, res)*/
349
+ }
350
+ async createQuota(data) {
351
+ try {
352
+ if (!data.tag) {
353
+ throw new Error('tag field is required');
354
+ }
355
+ if (!this.fetchQuota(data.tag)) {
356
+ await validators_1.CreateProductQuotaSchema.validateAsync(data);
357
+ await this.validateQuotaFallbackInputAndOutput(data);
358
+ data.total_quota = 0;
359
+ data.total_init = 0;
360
+ await Promise.all(data.options.map(async (d) => {
361
+ data.total_quota += d.quota;
362
+ const app = await this.fetchThirdPartyAppByAccessTag(d.app);
363
+ if (!app) {
364
+ throw new Error(`App with access tag ${d.app} not found`);
365
+ }
366
+ const version = app.versions.find((version) => version.tag === app.version);
367
+ const action = version.actions.find((action) => action.tag === d.event);
368
+ if (!action) {
369
+ throw new Error(`Cannot find action ${d.event} on app ${app.tag} version ${app.version}`);
370
+ }
371
+ if (d.healthcheck) {
372
+ const action = version.actions.find((action) => action.tag === d.healthcheck);
373
+ if (!d.check_interval) {
374
+ d.check_interval = 10000;
375
+ }
376
+ if (!action) {
377
+ throw new Error(`Cannot find healthcheck action ${d.healthcheck} on app ${app.tag} version ${app.version}`);
378
+ }
379
+ }
380
+ d.last_checked = new Date();
381
+ d.provider_status = productsBuilder_types_1.ProviderStatus.AVAILABLE;
382
+ d.last_available = true;
383
+ }));
384
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.QUOTA, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
385
+ }
386
+ else {
387
+ throw new Error(`Quota with tag ${data.tag} already exists`);
388
+ }
389
+ }
390
+ catch (e) {
391
+ throw e;
392
+ }
393
+ }
394
+ async updateQuota(tag, data) { }
395
+ fetchQuota(tag) {
396
+ return this.fetchQuotas().find((data) => data.tag === tag);
397
+ }
398
+ fetchQuotas() {
399
+ return this.product.quota;
400
+ }
401
+ async createFallback(data) {
402
+ try {
403
+ if (!data.tag) {
404
+ throw new Error('tag field is required');
405
+ }
406
+ if (!this.fetchQuota(data.tag)) {
407
+ await validators_1.CreateProductFallbackSchema.validateAsync(data);
408
+ await this.validateQuotaFallbackInputAndOutput(data);
409
+ await Promise.all(data.options.map(async (d) => {
410
+ const app = await this.fetchThirdPartyAppByAccessTag(d.app);
411
+ if (!app) {
412
+ throw new Error(`App with access tag ${d.app} not found`);
413
+ }
414
+ const version = app.versions.find((version) => version.tag === app.version);
415
+ const action = version.actions.find((action) => action.tag === d.event);
416
+ if (!action) {
417
+ throw new Error(`Cannot find action ${d.event} on app ${app.tag} version ${app.version}`);
418
+ }
419
+ if (d.healthcheck) {
420
+ const action = version.actions.find((action) => action.tag === d.healthcheck);
421
+ if (!d.check_interval) {
422
+ d.check_interval = 10000;
423
+ }
424
+ if (!action) {
425
+ throw new Error(`Cannot find healthcheck action ${d.healthcheck} on app ${app.tag} version ${app.version}`);
426
+ }
427
+ }
428
+ d.last_checked = new Date();
429
+ d.provider_status = productsBuilder_types_1.ProviderStatus.AVAILABLE;
430
+ d.last_available = true;
431
+ }));
432
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.FALLBACK, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
433
+ }
434
+ else {
435
+ throw new Error(`Quota with tag ${data.tag} already exists`);
436
+ }
437
+ }
438
+ catch (e) {
439
+ throw e;
440
+ }
441
+ }
442
+ async updateFallback(tag, data) {
443
+ /*try {
444
+
445
+ if (!data.tag) {
446
+ throw new Error('tag field is required');
447
+ }
448
+
449
+ if (this.fetchQuota(tag)) {
450
+
451
+ if(data.tag && tag !== data.tag && this.fetchFallback(data.tag)) {
452
+ throw new Error(`Fallback with new tag ${data.tag} already exists`)
453
+ }
454
+
455
+ if(!data.tag) {
456
+ data.tag = tag;
457
+ }
458
+
459
+ await UpdateProductFallbackSchema.validateAsync(data);
460
+
461
+ await this.validateQuotaFallbackInputAndOutput(data);
462
+
463
+ await Promise.all(data.options.map(async (d) => {
464
+
465
+ const app = await this.fetchThirdPartyAppByAccessTag(d.app);
466
+
467
+ if (!app) {
468
+ throw new Error(`App with access tag ${d.app} not found`)
469
+ }
470
+
471
+ const version = app.versions.find((version) => version.tag === app.version);
472
+ const action = version.actions.find((action) => action.tag === d.event)
473
+
474
+ if (!action) {
475
+ throw new Error(`Cannot find action ${d.event} on app ${app.tag} version ${app.version}`)
476
+ }
477
+
478
+ if (d.healthcheck) {
479
+ const action = version.actions.find((action) => action.tag === d.healthcheck)
480
+
481
+ if (!d.check_interval) {
482
+ d.check_interval = 10000;
483
+ }
484
+
485
+ if (!action) {
486
+ throw new Error(`Cannot find healthcheck action ${d.healthcheck} on app ${app.tag} version ${app.version}`)
487
+ }
488
+ }
489
+
490
+ d.last_checked = new Date();
491
+ d.provider_status = ProviderStatus.AVAILABLE;
492
+ d.last_available = true;
493
+ }))
494
+
495
+ await this.productApi.updateProduct(
496
+ this.product_id,
497
+ {
498
+ ...data,
499
+ component: ProductComponents.FALLBACK,
500
+ },
501
+ this.getUserAccess(),
502
+ );
503
+
504
+ } else {
505
+ throw new Error(`Quota with tag ${data.tag} already exists`)
506
+ }
507
+
508
+ } catch (e) {
509
+ throw e;
510
+ }*/
511
+ }
512
+ fetchFallback(tag) {
513
+ return this.fetchFallbacks().find((data) => data.tag === tag);
514
+ }
515
+ fetchFallbacks() {
516
+ return this.product.fallback;
517
+ }
518
+ async createEnv(data, throwErrorIfExists = false) {
519
+ try {
520
+ // TODO: figure out a way to check if this has run before, halt if it has
521
+ if (!this.fetchEnv(data.slug)) {
522
+ await validators_1.CreateProductEnvSchema.validateAsync(data);
523
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.ENV, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
524
+ await this.initializeProduct(this.product_id);
525
+ }
526
+ else {
527
+ if (throwErrorIfExists)
528
+ throw new Error(`Environment ${data.slug} already exists`);
529
+ }
530
+ }
531
+ catch (e) {
532
+ throw e;
533
+ }
534
+ }
535
+ async updateEnv(slug, data) {
536
+ try {
537
+ const env = this.fetchEnv(slug, true);
538
+ if (!env) {
539
+ throw new Error(`Env ${slug} not found`);
540
+ }
541
+ const { _id } = env;
542
+ await validators_1.UpdateProductEnvSchema.validateAsync(data); // Change to update;
543
+ if (data.slug && this.fetchEnv(data.slug)) {
544
+ throw new Error(`slug ${slug} is in use`); // TODO: also check on the backend
545
+ }
546
+ if (!data.slug) {
547
+ data.slug = slug;
548
+ }
549
+ 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());
550
+ await this.initializeProduct(this.product_id);
551
+ }
552
+ catch (e) {
553
+ throw e;
554
+ }
555
+ }
556
+ fetchEnvs() {
557
+ return this.product.envs;
558
+ }
559
+ fetchEnv(slug, throwErrorIfExists = false) {
560
+ const env = this.product.envs.find((data) => data.slug === slug);
561
+ if (!env && throwErrorIfExists)
562
+ throw new Error(`Env ${slug} not found`);
563
+ return env;
564
+ }
565
+ async createMessageBroker(data, throwErrorIfExists = false) {
566
+ if (!this.fetchMessageBroker(data.tag, false)) {
567
+ await validators_1.CreateMessageBrokerSchema.validateAsync(data);
568
+ data.envs = data.envs.map((env) => {
569
+ const exists = this.fetchEnv(env.slug);
570
+ if (!exists) {
571
+ throw new Error(`Env ${env.slug} does not exist`);
572
+ }
573
+ env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.fetchProduct().private_key);
574
+ return env;
575
+ });
576
+ const envs = this.fetchEnvs();
577
+ envs.map((env) => {
578
+ const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
579
+ if (exists === -1) {
580
+ throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
581
+ }
582
+ });
583
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.MESSAGEBROKER, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
584
+ await this.initializeProduct(this.product_id);
585
+ }
586
+ else {
587
+ if (throwErrorIfExists)
588
+ throw new Error(`Message Broker ${data.tag} already exists`);
589
+ }
590
+ }
591
+ async updateMessageBroker(tag, data) {
592
+ try {
593
+ const messageBroker = this.fetchMessageBroker(tag);
594
+ if (!messageBroker) {
595
+ throw new Error(`Broker ${tag} not found`);
596
+ }
597
+ const { _id, envs } = messageBroker;
598
+ await validators_1.UpdateMessageBrokerSchema.validateAsync(data); // Change to update;
599
+ if (data.tag && this.fetchMessageBroker(data.tag)) {
600
+ throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
601
+ }
602
+ console.log("2", data.envs);
603
+ data.envs = data.envs.map((env) => {
604
+ const exists = this.fetchEnv(env.slug);
605
+ if (!exists) {
606
+ throw new Error(`Env ${env.slug} does not exist`);
607
+ }
608
+ if (env.config)
609
+ env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.fetchProduct().private_key);
610
+ return env;
611
+ });
612
+ const overwrite = [];
613
+ const newEnvs = [];
614
+ data.envs.map((dataEnv) => {
615
+ const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
616
+ if (!this.fetchEnv(dataEnv.slug)) {
617
+ throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
618
+ }
619
+ if (exists === -1) {
620
+ if (!dataEnv.config) {
621
+ throw new Error(`config is required for new env ${data.envs[exists].slug}`);
622
+ }
623
+ newEnvs.push(dataEnv);
624
+ }
625
+ else {
626
+ if (envs[exists].config) {
627
+ envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.fetchProduct().private_key);
628
+ }
629
+ overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
630
+ }
631
+ });
632
+ const unchanged = [];
633
+ envs.map((env) => {
634
+ const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
635
+ const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
636
+ if (!newEnv && !overwriteEnv) {
637
+ if (env.config) {
638
+ env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.fetchProduct().private_key);
639
+ }
640
+ unchanged.push(env);
641
+ }
642
+ });
643
+ data.envs = [...unchanged, ...overwrite, ...newEnvs];
644
+ 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());
645
+ await this.initializeProduct(this.product_id);
646
+ }
647
+ catch (e) {
648
+ throw e;
649
+ }
650
+ }
651
+ fetchMessageBroker(tag, throwErrorIfExists = false) {
652
+ const messageBroker = this.product.messageBrokers.find((data) => data.tag === tag);
653
+ if (!messageBroker && throwErrorIfExists)
654
+ throw new Error(`Message Broker ${tag} not found`);
655
+ if (messageBroker) {
656
+ messageBroker.envs.map((broker) => {
657
+ if (typeof broker.config === 'string') {
658
+ broker.config = JSON.parse((0, processor_utils_1.decrypt)(String(broker.config), this.fetchProduct().private_key));
659
+ }
660
+ });
661
+ }
662
+ return messageBroker;
663
+ }
664
+ fetchMessageBrokers() {
665
+ return this.product.messageBrokers.map((broker) => {
666
+ return this.fetchMessageBroker(broker.tag);
667
+ });
668
+ }
669
+ async createStorage(data, throwErrorIfExists = false) {
670
+ if (!this.fetchStorage(data.tag, false)) {
671
+ await create_productStorage_validator_1.CreateProductStorageSchema.validateAsync(data);
672
+ data.envs = data.envs.map((env) => {
673
+ const exists = this.fetchEnv(env.slug);
674
+ if (!exists) {
675
+ throw new Error(`Env ${env.slug} does not exist`);
676
+ }
677
+ if (env.type === productsBuilder_types_1.StorageProviders.GCP) {
678
+ // @ts-ignore
679
+ //env.config.config.private_key = gcpPKCSConvert(env.config.config.private_key)
680
+ }
681
+ env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.fetchProduct().private_key);
682
+ return env;
683
+ });
684
+ const envs = this.fetchEnvs();
685
+ envs.map((env) => {
686
+ const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
687
+ if (exists === -1) {
688
+ throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
689
+ }
690
+ });
691
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.STORAGE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
692
+ await this.initializeProduct(this.product_id);
693
+ }
694
+ else {
695
+ if (throwErrorIfExists)
696
+ throw new Error(`Database ${data.tag} already exists`);
697
+ }
698
+ }
699
+ async updateStorage(tag, data) {
700
+ try {
701
+ const storage = this.fetchStorage(tag);
702
+ if (!storage) {
703
+ throw new Error(`Storage ${tag} not found`);
704
+ }
705
+ const { _id, envs } = storage;
706
+ await create_productStorage_validator_1.UpdateProductStorageSchema.validateAsync(data); // Change to update;
707
+ if (data.tag && this.fetchStorage(data.tag)) {
708
+ throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
709
+ }
710
+ data.envs = data.envs.map((env) => {
711
+ const exists = this.fetchEnv(env.slug);
712
+ if (!exists) {
713
+ throw new Error(`Env ${env.slug} does not exist`);
714
+ }
715
+ if (env.type === productsBuilder_types_1.StorageProviders.GCP) {
716
+ // @ts-ignore
717
+ //env.config.config.private_key = gcpPKCSConvert(env.config.config.private_key)
718
+ }
719
+ if (env.config)
720
+ env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.fetchProduct().private_key);
721
+ return env;
722
+ });
723
+ const overwrite = [];
724
+ const newEnvs = [];
725
+ data.envs.map((dataEnv) => {
726
+ const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
727
+ if (!this.fetchEnv(dataEnv.slug)) {
728
+ throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
729
+ }
730
+ if (exists === -1) {
731
+ if (!dataEnv.config) {
732
+ throw new Error(`config is required for new env ${data.envs[exists].slug}`);
733
+ }
734
+ newEnvs.push(dataEnv);
735
+ }
736
+ else {
737
+ if (envs[exists].config) {
738
+ envs[exists].config = (0, processor_utils_1.encrypt)(JSON.stringify(envs[exists].config), this.fetchProduct().private_key);
739
+ }
740
+ overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
741
+ }
742
+ });
743
+ const unchanged = [];
744
+ envs.map((env) => {
745
+ const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
746
+ const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
747
+ if (!newEnv && !overwriteEnv) {
748
+ if (env.config) {
749
+ env.config = (0, processor_utils_1.encrypt)(JSON.stringify(env.config), this.fetchProduct().private_key);
750
+ }
751
+ unchanged.push(env);
752
+ }
753
+ });
754
+ data.envs = [...unchanged, ...overwrite, ...newEnvs];
755
+ 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());
756
+ await this.initializeProduct(this.product_id);
757
+ }
758
+ catch (e) {
759
+ throw e;
760
+ }
761
+ }
762
+ fetchStorage(tag, throwErrorIfExists = false) {
763
+ const storage = this.product.storage.find((data) => data.tag === tag);
764
+ if (!storage && throwErrorIfExists)
765
+ throw new Error(`Storage ${tag} not found`);
766
+ if (storage) {
767
+ storage.envs.map((store) => {
768
+ if (typeof store.config === 'string') {
769
+ store.config = JSON.parse((0, processor_utils_1.decrypt)(String(store.config), this.fetchProduct().private_key));
770
+ }
771
+ });
772
+ }
773
+ return storage;
774
+ }
775
+ fetchStorages() {
776
+ return this.product.storage.map((storage) => {
777
+ return this.fetchStorage(storage.tag);
778
+ });
779
+ }
780
+ async validateAppData(appData, app) {
781
+ // TODO:
782
+ const { envs } = app;
783
+ // const { envs: appEnvs, auths: appAuths } = appData
784
+ const version = appData.versions.find((data) => (data.latest = true));
785
+ app.envs = this.validateAppEnvs(envs, version);
786
+ // await this.validateAppAuth(auth, appData);
787
+ return app;
788
+ }
789
+ validateVariablesSchema(variables, appVariables) {
790
+ if (variables && variables.length) {
791
+ variables.map((data) => {
792
+ const appVar = appVariables.find((value) => value.key === data.key);
793
+ if (!appVar) {
794
+ throw new Error(`variable key: ${data.key} not found`);
795
+ }
796
+ // if()
797
+ });
798
+ }
799
+ }
800
+ validateVariablesValues(variables, appVariables) {
801
+ if (appVariables && appVariables.length) {
802
+ appVariables.map((data) => {
803
+ const find = variables.find((value) => value.key === data.key);
804
+ if (data.required) {
805
+ if (!find) {
806
+ throw new Error(`variable key: ${data.key} is required`);
807
+ }
808
+ }
809
+ this.inputsService.validateFeatureInputData(find, data);
810
+ });
811
+ }
812
+ }
813
+ validateAppEnvs(envs, version) {
814
+ const { envs: appEnvs } = version;
815
+ return envs.map((env) => {
816
+ const { auth } = env;
817
+ this.fetchEnv(env.product_env_slug, true);
818
+ const appEnv = appEnvs.find((appEnv) => appEnv.slug === env.app_env_slug);
819
+ if (!appEnv) {
820
+ throw new Error(`app_slug ${env.app_env_slug} not found`);
821
+ }
822
+ const updates = this.validateAppAuth(auth, version);
823
+ this.validateVariablesSchema(env.variables, version.variables);
824
+ this.validateVariablesValues(env.variables, version.variables);
825
+ if (updates && updates.data) {
826
+ env.auth.data = updates.data;
827
+ }
828
+ if (updates && updates.values) {
829
+ env.auth.values = updates.values;
830
+ }
831
+ return env;
832
+ });
833
+ }
834
+ validateAppAuth(auth, version) {
835
+ const { auths: appAuth, actions } = version;
836
+ const exists = appAuth.find((appAuth) => appAuth.tag === auth.auth_tag);
837
+ if (!exists) {
838
+ throw new Error(`app_auth ${auth.auth_tag} not found`);
839
+ }
840
+ const { data } = auth;
841
+ let bodySchema;
842
+ let headerSchema;
843
+ let paramsSchema;
844
+ let querySchema;
845
+ let schema;
846
+ if (exists.action_tag) {
847
+ const action = actions.find((action) => action.tag === exists.action_tag);
848
+ if (!action)
849
+ throw new Error(`Auth action tag ${exists.action_tag} not found`);
850
+ schema = action;
851
+ }
852
+ else if (exists.tokens) {
853
+ schema = exists.tokens;
854
+ }
855
+ else {
856
+ throw new Error('Invalid auth, create and use another');
857
+ }
858
+ bodySchema = schema.body;
859
+ headerSchema = schema.headers;
860
+ paramsSchema = schema.params;
861
+ querySchema = schema.query;
862
+ const { body, headers, params, query } = data;
863
+ if (!body)
864
+ throw new Error(`Auth body not allowed to be undefined. If empty set as {}`);
865
+ if (!headers)
866
+ throw new Error(`Auth headers not allowed to be undefined. If empty set as {}`);
867
+ if (!params)
868
+ throw new Error(`Auth params not allowed to be undefined. If empty set as {}`);
869
+ if (!query)
870
+ throw new Error(`Auth query not allowed to be undefined. If empty set as {}`);
871
+ if (bodySchema && bodySchema.data) {
872
+ const bodyValues = this.inputsService.parseData({
873
+ data: body,
874
+ category: enums_1.Categories.SETUP,
875
+ expected: inputs_types_1.ExpectedValues.PARSEINPUT,
876
+ type: enums_1.InputsTypes.JSON,
877
+ });
878
+ (0, inputs_utils_create_1.validateInputSchema)(bodyValues, bodySchema);
879
+ }
880
+ if (headerSchema && headerSchema.data) {
881
+ const headerValues = this.inputsService.parseData({
882
+ data: headers,
883
+ category: enums_1.Categories.SETUP,
884
+ expected: inputs_types_1.ExpectedValues.PARSEINPUT,
885
+ type: enums_1.InputsTypes.JSON,
886
+ });
887
+ (0, inputs_utils_create_1.validateInputSchema)(headerValues, headerSchema);
888
+ }
889
+ if (paramsSchema && paramsSchema.data) {
890
+ const paramsValues = this.inputsService.parseData({
891
+ data: params,
892
+ category: enums_1.Categories.SETUP,
893
+ expected: inputs_types_1.ExpectedValues.PARSEINPUT,
894
+ type: enums_1.InputsTypes.JSON,
895
+ });
896
+ (0, inputs_utils_create_1.validateInputSchema)(paramsValues, paramsSchema);
897
+ }
898
+ if (querySchema && querySchema.data) {
899
+ const queryValues = this.inputsService.parseData({
900
+ data: query,
901
+ category: enums_1.Categories.SETUP,
902
+ expected: inputs_types_1.ExpectedValues.PARSEINPUT,
903
+ type: enums_1.InputsTypes.JSON,
904
+ });
905
+ (0, inputs_utils_create_1.validateInputSchema)(queryValues, querySchema);
906
+ }
907
+ const updateData = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.fetchProduct().private_key);
908
+ let updateValues = null;
909
+ if (exists.setup_type === enums_1.AuthTypes.TOKEN) {
910
+ updateValues = (0, processor_utils_1.encrypt)(JSON.stringify(data), this.fetchProduct().private_key);
911
+ }
912
+ return { data: updateData, values: updateValues };
913
+ }
914
+ async createAppAccessTag(app_tag) {
915
+ await this.initializeWorkspace();
916
+ const { name: workspace_name } = this.workspace;
917
+ const app = await this.appApi.fetchAppByTag(app_tag, this.getUserAccess());
918
+ if (!app) {
919
+ throw new Error(`App ${app_tag} not found`);
920
+ }
921
+ const { _id: app_id } = app;
922
+ const accessTag = `${app_tag}:${(0, string_utils_2.tagify)(workspace_name)}`;
923
+ const { access, access_tag } = await this.appApi.createAppAccess(app_id, this.product_id, accessTag, this.getUserAccess());
924
+ return {
925
+ access_tag,
926
+ access,
927
+ };
928
+ }
929
+ async addApp(app, throwErrorIfExists = false) {
930
+ try {
931
+ await validators_1.CreateProductAppSchema.validateAsync(app);
932
+ // TODO: figure out a way to check if this has run before, halt if it has
933
+ if (!this.fetchApp(app.access_tag, throwErrorIfExists)) {
934
+ const _a = await this.appApi.fetchAccessByTag(app.access_tag, this.getUserAccess()), { version } = _a, access = __rest(_a, ["version"]);
935
+ if (!access) {
936
+ throw new Error(`Access to app ${app.access_tag} not found`);
937
+ }
938
+ const appData = await this.appApi.fetchApp(access.app_id, this.getUserAccess());
939
+ if (!appData) {
940
+ throw new Error(`App ${app.access_tag} not found`);
941
+ }
942
+ const cleanedAppData = await this.validateAppData(appData, app);
943
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, cleanedAppData), { component: enums_1.ProductComponents.APP, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
944
+ await this.initializeProduct(this.product_id);
945
+ }
946
+ else {
947
+ if (throwErrorIfExists)
948
+ throw new Error(`App ${app.access_tag} already exists`);
949
+ }
950
+ }
951
+ catch (e) {
952
+ throw e;
953
+ }
954
+ }
955
+ async fetchAppWebhooks(access_tag) {
956
+ try {
957
+ const app = await this.fetchThirdPartyAppByAccessTag(access_tag);
958
+ if (!app) {
959
+ throw new Error(`App with access tag ${access_tag} not found`);
960
+ }
961
+ const version = app.versions.find((version) => version.tag === app.version);
962
+ if (!version) {
963
+ throw new Error(`Required app version not found`);
964
+ }
965
+ return version.webhooks;
966
+ }
967
+ catch (e) {
968
+ throw e;
969
+ }
970
+ }
971
+ async updateApp(access_tag, data) {
972
+ try {
973
+ const app = this.fetchApp(access_tag);
974
+ if (!app) {
975
+ throw new Error(`App ${access_tag} not found`);
976
+ }
977
+ const { _id } = app;
978
+ //await UpdateProductAppSchema.validateAsync(data); // Change to update;
979
+ if (data.access_tag && data.access_tag !== access_tag) {
980
+ throw new Error(`access_tag mismatch between ${access_tag} and ${data.access_tag}`);
981
+ }
982
+ if (!this.fetchApp(access_tag)) {
983
+ throw new Error(`access_tag ${access_tag} not found`); // TODO: also check on the backend
984
+ }
985
+ /*if (data.access_tag && this.fetchApp(data.access_tag)) {
986
+ throw new Error(`access_tag ${access_tag} is in use`); // TODO: also check on the backend
987
+ }*/
988
+ 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());
989
+ await this.initializeProduct(this.product_id);
990
+ }
991
+ catch (e) {
992
+ throw e;
993
+ }
994
+ }
995
+ fetchApps() {
996
+ return this.product.apps;
997
+ }
998
+ fetchApp(tag, throwErrorIfExists = false) {
999
+ const app = this.product.apps.find((data) => data.access_tag === tag);
1000
+ if (!app && throwErrorIfExists)
1001
+ throw new Error(`App ${tag} not found`);
1002
+ return app;
1003
+ }
1004
+ async createFunction(data, throwErrorIfExists = false) {
1005
+ try {
1006
+ // TODO: figure out a way to check if this has run before, halt if it has
1007
+ if (!this.fetchFunction(data.tag)) {
1008
+ await validators_1.CreateProductFunctionSchema.validateAsync(data);
1009
+ data.envs.map((env) => {
1010
+ env.auth = (0, processor_utils_1.encrypt)(JSON.stringify(env.auth), this.fetchProduct().private_key);
1011
+ });
1012
+ data.sample_data = (await this.inputsService.parseJson({
1013
+ data: data.sample,
1014
+ expected: inputs_types_1.ExpectedValues.PARSESAMPLE,
1015
+ category: enums_1.Categories.DATA,
1016
+ }));
1017
+ data.response_data = (await this.inputsService.parseJson({
1018
+ data: data.sample,
1019
+ expected: inputs_types_1.ExpectedValues.PARSESAMPLE,
1020
+ category: enums_1.Categories.DATA,
1021
+ }));
1022
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.FUNCTION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
1023
+ await this.initializeProduct(this.product_id);
1024
+ }
1025
+ else {
1026
+ if (throwErrorIfExists)
1027
+ throw new Error(`Function ${data.tag} already exists`);
1028
+ }
1029
+ }
1030
+ catch (e) {
1031
+ throw e;
1032
+ }
1033
+ }
1034
+ async updateFunction(tag, data) {
1035
+ try {
1036
+ const func = this.fetchFunction(tag);
1037
+ if (!func) {
1038
+ throw new Error(`Function ${tag} not found`);
1039
+ }
1040
+ const { _id } = func;
1041
+ await validators_1.UpdateProductFunctionSchema.validateAsync(data); // Change to update;
1042
+ if (data.tag && this.fetchFunction(data.tag)) {
1043
+ throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
1044
+ }
1045
+ 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());
1046
+ await this.initializeProduct(this.product_id);
1047
+ }
1048
+ catch (e) {
1049
+ throw e;
1050
+ }
1051
+ }
1052
+ fetchFunctions() {
1053
+ return this.product.functions;
1054
+ }
1055
+ fetchFunction(tag) {
1056
+ const func = this.product.functions.find((data) => data.tag === tag);
1057
+ if (!func)
1058
+ throw new Error(`Function ${tag} not found`);
1059
+ return func;
1060
+ }
1061
+ async createCache(data, throwErrorIfExists = false) {
1062
+ try {
1063
+ // TODO: figure out a way to check if this has run before, halt if it has
1064
+ if (!this.fetchCache(data.tag)) {
1065
+ await validators_1.CreateProductCacheSchema.validateAsync(data);
1066
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.CACHE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
1067
+ await this.initializeProduct(this.product_id);
1068
+ }
1069
+ else {
1070
+ if (throwErrorIfExists)
1071
+ throw new Error(`Cache ${data.tag} already exists`);
1072
+ }
1073
+ }
1074
+ catch (e) {
1075
+ throw e;
1076
+ }
1077
+ }
1078
+ async updateCache(tag, data) {
1079
+ try {
1080
+ const cache = this.fetchCache(tag);
1081
+ if (!cache) {
1082
+ throw new Error(`Cache ${tag} not found`);
1083
+ }
1084
+ const { _id } = cache;
1085
+ await validators_1.UpdateProductCacheSchema.validateAsync(data); // Change to update;
1086
+ if (data.tag && this.fetchCache(data.tag)) {
1087
+ throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
1088
+ }
1089
+ 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());
1090
+ await this.initializeProduct(this.product_id);
1091
+ }
1092
+ catch (e) {
1093
+ throw e;
1094
+ }
1095
+ }
1096
+ fetchCache(tag, throwErrorIfExists = false) {
1097
+ const cache = this.product.caches.find((data) => data.tag === tag);
1098
+ if (!cache && throwErrorIfExists)
1099
+ throw new Error(`Cache ${tag} not found`);
1100
+ return cache;
1101
+ }
1102
+ fetchCaches() {
1103
+ return this.product.caches;
1104
+ }
1105
+ async createNotification(data, throwErrorIfExists = false) {
1106
+ try {
1107
+ // TODO: figure out a way to check if this has run before, halt if it has
1108
+ if (!this.fetchNotification(data.tag)) {
1109
+ await validators_1.CreateProductNotificationSchema.validateAsync(data);
1110
+ const envs = this.fetchEnvs();
1111
+ envs.map((env) => {
1112
+ const exists = data.envs.findIndex((nEnv) => nEnv.slug === env.slug);
1113
+ if (exists === -1) {
1114
+ throw new Error(`Notification for environment ${env.slug} is not defined, please provide the environment details`);
1115
+ }
1116
+ });
1117
+ for (let i = 0; i < data.envs.length; i++) {
1118
+ const updates = {
1119
+ push_notifications: data.envs[i].push_notifications
1120
+ ? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].push_notifications), this.fetchProduct().private_key)
1121
+ : undefined,
1122
+ emails: data.envs[i].emails
1123
+ ? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].emails), this.fetchProduct().private_key)
1124
+ : undefined,
1125
+ callbacks: data.envs[i].callbacks
1126
+ ? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].callbacks), this.fetchProduct().private_key)
1127
+ : undefined,
1128
+ sms: data.envs[i].sms
1129
+ ? (0, processor_utils_1.encrypt)(JSON.stringify(data.envs[i].sms), this.fetchProduct().private_key)
1130
+ : undefined,
1131
+ };
1132
+ data.envs[i] = Object.assign(Object.assign({}, data.envs[i]), updates);
1133
+ }
1134
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.NOTIFICATION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
1135
+ await this.initializeProduct(this.product_id);
1136
+ }
1137
+ else {
1138
+ if (throwErrorIfExists)
1139
+ throw new Error(`Notification ${data.tag} already exists`);
1140
+ }
1141
+ }
1142
+ catch (e) {
1143
+ throw e;
1144
+ }
1145
+ }
1146
+ async createNotificationMessage(data, throwErrorIfExists = false) {
1147
+ try {
1148
+ await create_productNotificationMessage_validator_1.default.validateAsync(data);
1149
+ if (!data.tag) {
1150
+ throw new Error('tag field is required');
1151
+ }
1152
+ const [notificationTag, tag] = data.tag.split(':');
1153
+ if (!notificationTag || !tag) {
1154
+ throw new Error(`tag is expected to be defined as "notification_tag:message_tag"`);
1155
+ }
1156
+ const exists = this.fetchNotificationMessage(data.tag);
1157
+ data.tag = tag;
1158
+ if (!exists) {
1159
+ if (!data.email && !data.push_notification && !data.callback) {
1160
+ throw new Error(`atleast one of "email","push_notification" or "callback" is expected to be set`);
1161
+ }
1162
+ if (data.email) {
1163
+ const emailTemaplate = (0, string_utils_1.extractPlaceholders)(data.email.template, 'template');
1164
+ const subjectTemplate = (0, string_utils_1.extractPlaceholders)(data.email.subject, 'subject');
1165
+ data.email_data = [...emailTemaplate, ...subjectTemplate];
1166
+ }
1167
+ if (data.push_notification) {
1168
+ data.push_notification_data = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.push_notification));
1169
+ const titleTemplate = (0, string_utils_1.extractPlaceholders)(data.push_notification.title, 'title');
1170
+ const bodyTemplate = (0, string_utils_1.extractPlaceholders)(data.push_notification.body, 'body');
1171
+ const dataTemplate = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.push_notification.data || {}), 'data');
1172
+ data.push_notification_data = [...titleTemplate, ...bodyTemplate, ...dataTemplate];
1173
+ }
1174
+ if (data.callback) {
1175
+ const bodyTemplate = data.callback.body
1176
+ ? (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.callback.body), 'body')
1177
+ : [];
1178
+ const queryTemplate = data.callback.query
1179
+ ? (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.callback.query), 'query')
1180
+ : [];
1181
+ const paramsTemplate = data.callback.params
1182
+ ? (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.callback.params), 'params')
1183
+ : [];
1184
+ const headerTemplate = data.callback.headers
1185
+ ? (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.callback.headers), 'headers')
1186
+ : [];
1187
+ data.callback_data = [...bodyTemplate, ...queryTemplate, ...paramsTemplate, ...headerTemplate];
1188
+ }
1189
+ if (data.sms) {
1190
+ data.sms_data = (0, string_utils_1.extractPlaceholders)(data.sms, '');
1191
+ }
1192
+ 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());
1193
+ await this.initializeProduct(this.product_id);
1194
+ }
1195
+ else {
1196
+ if (throwErrorIfExists)
1197
+ throw new Error(`Database Action ${data.tag} already exists`);
1198
+ }
1199
+ }
1200
+ catch (e) {
1201
+ throw e;
1202
+ }
1203
+ }
1204
+ fetchNotificationMessage(tag, throwErrorIfExists = false) {
1205
+ const [notificationTag, messageTag] = tag.split(':');
1206
+ if (!notificationTag || !messageTag) {
1207
+ throw new Error(`tag is expected to be defined as "notification_tag:message_tag"`);
1208
+ }
1209
+ const notification = this.product.notifications.find((data) => data.tag === notificationTag);
1210
+ if (!notification)
1211
+ throw new Error(`Notification ${notificationTag} not found`);
1212
+ const message = notification.messages.find((data) => data.tag === messageTag);
1213
+ if (!message && throwErrorIfExists)
1214
+ throw new Error(`Notification message ${tag} not found`);
1215
+ return message;
1216
+ }
1217
+ fetchNotificationMessages(notificationTag, throwErrorIfExists = false) {
1218
+ const notification = this.product.notifications.find((data) => data.tag === notificationTag);
1219
+ if (!notification)
1220
+ throw new Error(`Notification ${notificationTag} not found`);
1221
+ return notification.messages;
1222
+ }
1223
+ async updateNotificationMessage(data) {
1224
+ try {
1225
+ await update_productNotificationMessage_validator_1.default.validateAsync(data);
1226
+ if (!data.tag) {
1227
+ throw new Error('tag field is required');
1228
+ }
1229
+ const [notificationTag, tag] = data.tag.split(':');
1230
+ if (!notificationTag || !tag) {
1231
+ throw new Error(`tag is expected to be defined as "notification_tag:message_tag"`);
1232
+ }
1233
+ // Fetch required data
1234
+ //const notification = await this.fetchNotification(notificationTag);
1235
+ const message = await this.fetchNotificationMessage(data.tag, true);
1236
+ // Validate and process the template
1237
+ data.tag = tag;
1238
+ if (data.email) {
1239
+ const emailTemaplate = (0, string_utils_1.extractPlaceholders)(data.email.template, 'template');
1240
+ const subjectTemplate = (0, string_utils_1.extractPlaceholders)(data.email.subject, 'subject');
1241
+ data.email_data = [...emailTemaplate, ...subjectTemplate];
1242
+ }
1243
+ if (data.push_notification) {
1244
+ data.push_notification_data = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.push_notification));
1245
+ const titleTemplate = (0, string_utils_1.extractPlaceholders)(data.push_notification.title, 'title');
1246
+ const bodyTemplate = (0, string_utils_1.extractPlaceholders)(data.push_notification.body, 'body');
1247
+ const dataTemplate = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.push_notification.data || {}), 'data');
1248
+ data.push_notification_data = [...titleTemplate, ...bodyTemplate, ...dataTemplate];
1249
+ }
1250
+ if (data.callback) {
1251
+ const bodyTemplate = data.callback.body ? (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.callback.body), 'body') : [];
1252
+ const queryTemplate = data.callback.query
1253
+ ? (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.callback.query), 'query')
1254
+ : [];
1255
+ const paramsTemplate = data.callback.params
1256
+ ? (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.callback.params), 'params')
1257
+ : [];
1258
+ const headerTemplate = data.callback.headers
1259
+ ? (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.callback.headers), 'headers')
1260
+ : [];
1261
+ data.callback_data = [...bodyTemplate, ...queryTemplate, ...paramsTemplate, ...headerTemplate];
1262
+ }
1263
+ if (data.sms) {
1264
+ data.sms_data = (0, string_utils_1.extractPlaceholders)(data.sms, '');
1265
+ }
1266
+ // Construct payload
1267
+ const payload = Object.assign(Object.assign(Object.assign({}, message), data), { notificationTag, component: enums_1.ProductComponents.NOTIFICATION_MESSAGE, action: enums_1.RequestAction.UPDATE });
1268
+ // Update product and reinitialize
1269
+ await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
1270
+ await this.initializeProduct(this.product_id);
1271
+ }
1272
+ catch (error) {
1273
+ throw error;
1274
+ }
1275
+ }
1276
+ async updateNotification(tag, data) {
1277
+ try {
1278
+ const { _id, envs } = this.fetchNotification(tag);
1279
+ if (data.tag && tag !== data.tag && this.fetchNotification(data.tag)) {
1280
+ throw new Error(`Notification of tag ${data.tag} already exists`);
1281
+ }
1282
+ await validators_1.UpdateProductNotificationSchema.validateAsync(data); // Change to update;
1283
+ let notification = this.fetchNotification(tag);
1284
+ if (!notification) {
1285
+ throw new Error(`Notification with tag ${tag} not found`);
1286
+ }
1287
+ if (data.envs) {
1288
+ const overwrite = [];
1289
+ const newEnvs = [];
1290
+ data.envs.map(async (dataEnv) => {
1291
+ const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
1292
+ if (!this.fetchEnv(dataEnv.slug)) {
1293
+ throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
1294
+ }
1295
+ if (exists === -1) {
1296
+ await create_productNotification_validator_1.ProductNotificationEnvsSchema.validateAsync(dataEnv);
1297
+ newEnvs.push(dataEnv);
1298
+ }
1299
+ else {
1300
+ overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
1301
+ }
1302
+ });
1303
+ const unchanged = [];
1304
+ envs.map((env) => {
1305
+ const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
1306
+ const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
1307
+ if (!newEnv && !overwriteEnv) {
1308
+ unchanged.push(env);
1309
+ }
1310
+ });
1311
+ data.envs = [...unchanged, ...overwrite, ...newEnvs];
1312
+ }
1313
+ const update = Object.assign(Object.assign({}, notification), data);
1314
+ update.envs.map((env) => {
1315
+ if (env.emails)
1316
+ env.emails = (0, processor_utils_1.encrypt)(JSON.stringify(env.emails), this.fetchProduct().private_key);
1317
+ if (env.push_notifications)
1318
+ env.push_notifications = (0, processor_utils_1.encrypt)(JSON.stringify(env.push_notifications), this.fetchProduct().private_key);
1319
+ if (env.callbacks)
1320
+ env.callbacks = (0, processor_utils_1.encrypt)(JSON.stringify(env.callbacks), this.fetchProduct().private_key);
1321
+ if (env.sms)
1322
+ env.sms = (0, processor_utils_1.encrypt)(JSON.stringify(env.sms), this.fetchProduct().private_key);
1323
+ return env;
1324
+ });
1325
+ const payload = Object.assign(Object.assign({ _id }, update), { component: enums_1.ProductComponents.NOTIFICATION, action: enums_1.RequestAction.UPDATE });
1326
+ await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
1327
+ await this.initializeProduct(this.product_id);
1328
+ }
1329
+ catch (e) {
1330
+ throw e;
1331
+ }
1332
+ }
1333
+ fetchNotification(tag, notification_slug = '', throwErrorIfExists = false) {
1334
+ const notification = this.product.notifications.find((data) => data.tag === tag);
1335
+ if (notification && throwErrorIfExists)
1336
+ throw new Error(`Notification ${tag} is in use`);
1337
+ /*if (notification_slug) {
1338
+ const { notifications, emails, callbacks } = notification.envs.find(
1339
+ (data: INotificationEnv) => (data.slug = notification_slug),
1340
+ );
1341
+ return { notifications, emails, callbacks };
1342
+ }*/
1343
+ if (notification) {
1344
+ notification.envs.map((data) => {
1345
+ if (data.callbacks && typeof data.callbacks == 'string') {
1346
+ data.callbacks = JSON.parse((0, processor_utils_1.decrypt)(String(data.callbacks), this.fetchProduct().private_key));
1347
+ }
1348
+ if (data.push_notifications && typeof data.push_notifications == 'string') {
1349
+ data.push_notifications = JSON.parse((0, processor_utils_1.decrypt)(String(data.push_notifications), this.fetchProduct().private_key));
1350
+ }
1351
+ if (data.emails && typeof data.emails == 'string') {
1352
+ data.emails = JSON.parse((0, processor_utils_1.decrypt)(String(data.emails), this.fetchProduct().private_key));
1353
+ }
1354
+ if (data.sms && typeof data.sms == 'string') {
1355
+ data.sms = JSON.parse((0, processor_utils_1.decrypt)(String(data.sms), this.fetchProduct().private_key));
1356
+ }
1357
+ return data;
1358
+ });
1359
+ }
1360
+ return notification;
1361
+ }
1362
+ fetchNotifications() {
1363
+ return this.product.notifications.map((notification) => {
1364
+ return this.fetchNotification(notification.tag);
1365
+ });
1366
+ }
1367
+ validateFeatureSequence(array) {
1368
+ // Validate uniqueness of sequence_tag
1369
+ const uniqueTags = new Set();
1370
+ for (const item of array) {
1371
+ if (uniqueTags.has(item.tag)) {
1372
+ throw new Error(`Duplicate sequence_tag found: ${item.tag}`);
1373
+ }
1374
+ uniqueTags.add(item.tag);
1375
+ }
1376
+ // Validate levels are in order starting from 0
1377
+ /*let expectedLevel = 0;
1378
+ for (const item of array) {
1379
+ if (item.level !== expectedLevel) {
1380
+ throw new Error(`Invalid level found: expected ${expectedLevel}, found ${item.level}`);
1381
+ }
1382
+ expectedLevel++;
1383
+ }*/
1384
+ }
1385
+ validateUniqueEventTags(data) {
1386
+ // TODO: this might not be necessary o
1387
+ const eventTagsSet = new Set(); // TODO: this might have to be moved to line 658
1388
+ data.sequence.forEach((sequence) => {
1389
+ sequence.events.forEach((data) => {
1390
+ const { event } = data;
1391
+ if (eventTagsSet.has(event)) {
1392
+ throw new Error(`Duplicate event_tag found: ${event}`);
1393
+ }
1394
+ eventTagsSet.add(event);
1395
+ });
1396
+ });
1397
+ }
1398
+ async validateFeatureData(data) {
1399
+ const { sequence } = data;
1400
+ this.validateUniqueEventTags(data); // TODO: this might be unnecessary
1401
+ this.validateFeatureSequence(sequence);
1402
+ const promises = sequence.map((obj, sequence_index) => {
1403
+ const { events, parents } = obj;
1404
+ if (parents && parents.length) {
1405
+ this.validateSequenceParents(parents, sequence_index, sequence);
1406
+ }
1407
+ return Promise.all(events.map((event, event_index) => this.validateEvent(data, sequence_index, event, event_index)));
1408
+ });
1409
+ const results = await Promise.allSettled(promises.flat());
1410
+ const errors = results
1411
+ .filter((result) => result.status === 'rejected')
1412
+ .map((result) => result.reason);
1413
+ if (errors.length > 0) {
1414
+ //throw new Error(`Validation errors: ${errors.join(', ')}`);
1415
+ errors.map((error) => {
1416
+ //console.log(error);
1417
+ throw error;
1418
+ });
1419
+ }
1420
+ }
1421
+ validateSequenceParents(parents, sequence_index, sequence) {
1422
+ const map = new Map();
1423
+ for (let i = 0; i < sequence_index; i++) {
1424
+ map.set(sequence[i].tag, i);
1425
+ }
1426
+ for (let i = 0; i < parents.length; i++) {
1427
+ if (map.get(parents[i]) === undefined) {
1428
+ throw new Error(`Invalid parent ${parents[i]} in sequence ${sequence[sequence_index].tag}, parents have to be declared before their children`);
1429
+ }
1430
+ }
1431
+ }
1432
+ validateSequenceInputParents(parent, sequence_index, sequence) {
1433
+ let found = false;
1434
+ const parents = sequence[sequence_index].parents;
1435
+ if (!parents || parents.length === 0)
1436
+ throw new Error(`Parents array cannot be empty or null when there is a $Sequence value in sequence ${sequence[sequence_index].tag}`);
1437
+ for (let i = 0; i < sequence_index; i++) {
1438
+ if (sequence[i].tag === parent)
1439
+ found = true;
1440
+ }
1441
+ if (!found)
1442
+ throw new Error(`Parents array needs to contain parent sequence ${parent} in ${sequence[sequence_index].tag}`);
1443
+ }
1444
+ async checkAndValidateActionDataInput(data, sequence_index, event, event_index) {
1445
+ /*const application = this.fetchThirdPartyAppByAccessTag(event.a)
1446
+
1447
+ if (!application) {
1448
+ throw new Error(`App ${event.app} does not exist`);
1449
+ }
1450
+
1451
+ const { version, ...app } = application;
1452
+ const { access_tag } = app;*/
1453
+ // validate action_tag
1454
+ const app = await this.fetchThirdPartyAppByAccessTag(event.app);
1455
+ const { versions, version } = app;
1456
+ const versionExists = versions.find((data) => data.tag === version);
1457
+ if (!versionExists) {
1458
+ throw new Error(`Version ${version} does not exist on app ${event.app}`);
1459
+ }
1460
+ const { actions } = versionExists;
1461
+ const action = this.fetchThirdPartyAppActionByTag(actions, event.event);
1462
+ await this.validateActionDataInput(data, action, event.input, event_index, sequence_index);
1463
+ }
1464
+ async checkAndValidateFunctionDataInput(data, sequence_index, event, event_index) {
1465
+ const func = this.fetchFunction(event.event);
1466
+ await this.validateActionDataInput(data, func, event.input, event_index, sequence_index);
1467
+ }
1468
+ async checkAndValidateDBActionDataInput(data, sequence_index, event, event_index) {
1469
+ console.log("EVENTY", event.event);
1470
+ const { filterData, data: dbData, filterTemplate, template } = this.fetchDatabaseAction(event.event);
1471
+ await this.validateDBActionDataInput(data, { filterData, data: dbData, template, filter: filterTemplate }, event.input, event_index, sequence_index);
1472
+ }
1473
+ async checkAndValidateFeatureDataInput(data, sequence_index, event, event_index) {
1474
+ const { input } = this.fetchFeature(event.event);
1475
+ await this.validateFeatureDataInput(data, input, event.input, event_index, sequence_index);
1476
+ }
1477
+ async checkAndValidateNotificationDataInput(data, sequence_index, event, event_index) {
1478
+ const { callback_data: callback, push_notification_data: notification, email_data: email, sms_data: sms, } = this.fetchNotificationMessage(event.event);
1479
+ await this.validateNotificationDataInput(data, { callback, notification, email, sms }, event.input, event_index, sequence_index);
1480
+ }
1481
+ async checkAndValidatePublishDataInput(data, sequence_index, event, event_index) {
1482
+ const topic = this.fetchMessageBrokerTopic(event.event);
1483
+ if (!topic) {
1484
+ throw new Error(`Topic ${event.event} not registered`);
1485
+ }
1486
+ const { data: topicData } = topic;
1487
+ //await this.validatePublishTopicDataInput(data, { data: topicData }, event.input, event_index, sequence_index)
1488
+ }
1489
+ async checkAndValidateStorageDataInput(data, sequence_index, event, event_index) {
1490
+ const storage = this.fetchStorage(event.event);
1491
+ if (!storage) {
1492
+ throw new Error(`Storage ${event.event} does not exist`);
1493
+ }
1494
+ //await this.validateStorageDataInput(data, {}, event.input, event_index, sequence_index);
1495
+ }
1496
+ async checkAndValidateJobDataInput(data, sequence_index, event, event_index) {
1497
+ const job = this.fetchJob(event.event);
1498
+ if (job.type === productsBuilder_types_1.JobEventTypes.ACTION) {
1499
+ await this.checkAndValidateActionDataInput(data, sequence_index, event, event_index);
1500
+ }
1501
+ if (job.type === productsBuilder_types_1.JobEventTypes.DATABASE_ACTION) {
1502
+ await this.checkAndValidateDBActionDataInput(data, sequence_index, event, event_index);
1503
+ }
1504
+ if (job.type === productsBuilder_types_1.JobEventTypes.NOTIFICATION) {
1505
+ await this.checkAndValidateNotificationDataInput(data, sequence_index, event, event_index);
1506
+ }
1507
+ if (job.type === productsBuilder_types_1.JobEventTypes.STORAGE) {
1508
+ await this.checkAndValidateStorageDataInput(data, sequence_index, event, event_index);
1509
+ }
1510
+ if (job.type === productsBuilder_types_1.JobEventTypes.PUBLISH) {
1511
+ await this.checkAndValidatePublishDataInput(data, sequence_index, event, event_index);
1512
+ }
1513
+ if (job.type === productsBuilder_types_1.JobEventTypes.FUNCTION) {
1514
+ await this.checkAndValidateFunctionDataInput(data, sequence_index, event, event_index);
1515
+ }
1516
+ }
1517
+ async checkAndValidateFallbackDataInput(data, sequence_index, event, event_index) { }
1518
+ async validateEvent(data, sequence_index, event, event_index) {
1519
+ this.validateConditional(event, data, sequence_index, event_index);
1520
+ if (event.type === productsBuilder_types_1.FeatureEventTypes.ACTION) {
1521
+ await this.checkAndValidateActionDataInput(data, sequence_index, event, event_index);
1522
+ // validate input
1523
+ }
1524
+ if (event.type === productsBuilder_types_1.FeatureEventTypes.DB_ACTION) {
1525
+ await this.checkAndValidateDBActionDataInput(data, sequence_index, event, event_index);
1526
+ }
1527
+ if (event.type === productsBuilder_types_1.FeatureEventTypes.FEATURE) {
1528
+ await this.checkAndValidateFeatureDataInput(data, sequence_index, event, event_index);
1529
+ }
1530
+ if (event.type === productsBuilder_types_1.FeatureEventTypes.NOTIFICATION) {
1531
+ await this.checkAndValidateNotificationDataInput(data, sequence_index, event, event_index);
1532
+ }
1533
+ if (event.type === productsBuilder_types_1.FeatureEventTypes.PUBLISH) {
1534
+ await this.checkAndValidatePublishDataInput(data, sequence_index, event, event_index);
1535
+ }
1536
+ /*if (event.type === FeatureEventTypes.SUBSCRIBE) {
1537
+ const topic = this.fetchMessageBrokerTopic(event.event);
1538
+
1539
+ if(!topic) {
1540
+ throw new Error(`Topic ${event.event} not registered`);
1541
+ }
1542
+ }*/
1543
+ if (event.type === productsBuilder_types_1.FeatureEventTypes.STORAGE) {
1544
+ await this.checkAndValidateStorageDataInput(data, sequence_index, event, event_index);
1545
+ }
1546
+ if (event.type === productsBuilder_types_1.FeatureEventTypes.JOB) {
1547
+ await this.checkAndValidateJobDataInput(data, sequence_index, event, event_index);
1548
+ }
1549
+ }
1550
+ async validateDBActionDataInput(data, action, event_input, event_index, sequence_index) {
1551
+ // const {data: dataInput, filter: filter} = event_input;
1552
+ const indexes = {
1553
+ parent_key: '',
1554
+ level: 0,
1555
+ key: '',
1556
+ index: 0,
1557
+ };
1558
+ await this.validateActionInputData({
1559
+ obj: event_input.data,
1560
+ sample: { type: enums_1.InputsTypes.JSON, sample: action.template, data: action.data },
1561
+ event_index,
1562
+ sequence_index,
1563
+ feature: data,
1564
+ type: enums_1.Categories.DATA,
1565
+ indexes: indexes,
1566
+ }, true);
1567
+ await this.validateActionInputData({
1568
+ obj: event_input.filter,
1569
+ sample: { type: enums_1.InputsTypes.JSON, sample: action.filter, data: action.filterData },
1570
+ event_index,
1571
+ sequence_index,
1572
+ feature: data,
1573
+ type: enums_1.Categories.FILTER,
1574
+ indexes: indexes,
1575
+ }, true);
1576
+ }
1577
+ async validateFeatureDataInput(data, featureInput, input, event_index, sequence_index) {
1578
+ (0, processor_utils_1.validateFeatureJSONInput)(input, featureInput);
1579
+ }
1580
+ async validateNotificationDataInput(data, action, event_input, event_index, sequence_index) {
1581
+ // const {data: dataInput, filter: filter} = event_input;
1582
+ const indexes = {
1583
+ parent_key: '',
1584
+ level: 0,
1585
+ key: '',
1586
+ index: 0,
1587
+ };
1588
+ if (event_input.callback) {
1589
+ await this.validateActionInputData({
1590
+ obj: event_input.callback,
1591
+ sample: { type: enums_1.InputsTypes.JSON, sample: '', data: action.callback },
1592
+ event_index,
1593
+ sequence_index,
1594
+ feature: data,
1595
+ type: enums_1.Categories.DATA,
1596
+ indexes: indexes,
1597
+ }, true);
1598
+ }
1599
+ if (event_input.email) {
1600
+ const indexes = {
1601
+ parent_key: '',
1602
+ level: 0,
1603
+ key: '',
1604
+ index: 0,
1605
+ };
1606
+ const _a = event_input.email, { recipients } = _a, email = __rest(_a, ["recipients"]);
1607
+ await this.validateActionInputData({
1608
+ obj: email.subject,
1609
+ sample: { type: enums_1.InputsTypes.JSON, sample: '', data: action.email.filter((value) => value.parent_key === 'subject') },
1610
+ event_index,
1611
+ sequence_index,
1612
+ feature: data,
1613
+ type: enums_1.Categories.DATA,
1614
+ indexes: Object.assign(Object.assign({}, indexes), { parent_key: 'subject', level: 1 }),
1615
+ }, true);
1616
+ await this.validateActionInputData({
1617
+ obj: email.template,
1618
+ sample: { type: enums_1.InputsTypes.JSON, sample: '', data: action.email.filter((value) => value.parent_key === 'template') },
1619
+ event_index,
1620
+ sequence_index,
1621
+ feature: data,
1622
+ type: enums_1.Categories.DATA,
1623
+ indexes: Object.assign(Object.assign({}, indexes), { parent_key: 'template', level: 1 }),
1624
+ }, true);
1625
+ }
1626
+ if (event_input.push_notification) {
1627
+ const _b = event_input.push_notification, { device_tokens } = _b, push_notification = __rest(_b, ["device_tokens"]);
1628
+ await this.validateActionInputData({
1629
+ obj: push_notification.body,
1630
+ sample: { type: enums_1.InputsTypes.JSON, sample: '', data: action.notification.filter((value) => value.parent_key === 'body') },
1631
+ event_index,
1632
+ sequence_index,
1633
+ feature: data,
1634
+ type: enums_1.Categories.DATA,
1635
+ indexes: Object.assign(Object.assign({}, indexes), { parent_key: 'body', level: 1 }),
1636
+ }, true);
1637
+ if (push_notification.data) {
1638
+ console.log("JUMANJI", push_notification.data);
1639
+ await this.validateActionInputData({
1640
+ obj: push_notification.data,
1641
+ sample: { type: enums_1.InputsTypes.JSON, sample: '', data: action.notification.filter((value) => value.parent_key === 'data') },
1642
+ event_index,
1643
+ sequence_index,
1644
+ feature: data,
1645
+ type: enums_1.Categories.DATA,
1646
+ indexes: Object.assign(Object.assign({}, indexes), { parent_key: 'data', level: 1 }),
1647
+ }, true);
1648
+ }
1649
+ if (push_notification.title)
1650
+ await this.validateActionInputData({
1651
+ obj: push_notification.title,
1652
+ sample: { type: enums_1.InputsTypes.JSON, sample: '', data: action.notification.filter((value) => value.parent_key === 'title') },
1653
+ event_index,
1654
+ sequence_index,
1655
+ feature: data,
1656
+ type: enums_1.Categories.DATA,
1657
+ indexes: Object.assign(Object.assign({}, indexes), { parent_key: 'title', level: 1 }),
1658
+ }, true);
1659
+ }
1660
+ if (event_input.sms) {
1661
+ const _c = event_input.sms, { recipients } = _c, sms = __rest(_c, ["recipients"]);
1662
+ await this.validateActionInputData({
1663
+ obj: sms.body,
1664
+ sample: { type: enums_1.InputsTypes.JSON, sample: '', data: action.sms },
1665
+ event_index,
1666
+ sequence_index,
1667
+ feature: data,
1668
+ type: enums_1.Categories.DATA,
1669
+ indexes: Object.assign({}, indexes),
1670
+ }, true);
1671
+ }
1672
+ }
1673
+ async validateActionDataInput(data, action, event_input, event_index, sequence_index) {
1674
+ const { params, query, headers, body } = event_input;
1675
+ const { params: actionParams, query: actionQuery, headers: actionHeaders, body: actionBody } = action;
1676
+ const indexes = {
1677
+ parent_key: '',
1678
+ level: 0,
1679
+ key: '',
1680
+ index: 0,
1681
+ };
1682
+ await this.validateActionInputData({
1683
+ obj: params,
1684
+ sample: actionParams,
1685
+ event_index,
1686
+ sequence_index,
1687
+ feature: data,
1688
+ type: enums_1.Categories.PARAMS,
1689
+ indexes,
1690
+ });
1691
+ await this.validateActionInputData({
1692
+ obj: query,
1693
+ sample: actionQuery,
1694
+ event_index,
1695
+ sequence_index,
1696
+ feature: data,
1697
+ type: enums_1.Categories.QUERY,
1698
+ indexes,
1699
+ });
1700
+ await this.validateActionInputData({
1701
+ obj: headers,
1702
+ sample: actionHeaders,
1703
+ event_index,
1704
+ sequence_index,
1705
+ feature: data,
1706
+ type: enums_1.Categories.HEADER,
1707
+ indexes,
1708
+ });
1709
+ await this.validateActionInputData({
1710
+ obj: body,
1711
+ sample: actionBody,
1712
+ event_index,
1713
+ sequence_index,
1714
+ feature: data,
1715
+ type: enums_1.Categories.BODY,
1716
+ indexes,
1717
+ });
1718
+ }
1719
+ async validateActionInputData(data, skipSample = false, option = false, optionIndex = 0) {
1720
+ var _a;
1721
+ const { obj } = data, base_data = __rest(data, ["obj"]);
1722
+ if (!data.sample && Object.keys(obj).length === 0) {
1723
+ return;
1724
+ }
1725
+ if (!data.sample) {
1726
+ throw new Error('Something unexpected happened in validating action input');
1727
+ }
1728
+ const sequence = data.feature.sequence[data.sequence_index];
1729
+ if (obj === undefined || obj === null) {
1730
+ if (!option) {
1731
+ throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should not be ${obj}`);
1732
+ }
1733
+ else {
1734
+ throw new Error(`option event index ${optionIndex}, ${data.type} should not be ${obj}`);
1735
+ }
1736
+ }
1737
+ if (Object.values(obj).length > 0 && ((_a = data.sample.data) === null || _a === void 0 ? void 0 : _a.length) === 0) {
1738
+ if (!option) {
1739
+ throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should be an empty object`);
1740
+ }
1741
+ else {
1742
+ throw new Error(`option event index ${optionIndex}, ${data.type} should not be an empty object`);
1743
+ }
1744
+ }
1745
+ if (Object.values(obj).length === 0 && data.sample.data.length === 0 /*data.sample?.data?.length === 0*/) {
1746
+ return;
1747
+ }
1748
+ if (Object.values(obj).length === 0 && data.sample.data.length > 0 && !skipSample) {
1749
+ //console.log("validity err: ",obj, data.sample)
1750
+ if (!option) {
1751
+ throw new Error(`sequence ${sequence.tag} event ${sequence.events[data.event_index].event} ${data.type} should not be an empty object`);
1752
+ }
1753
+ else {
1754
+ throw new Error(`option event index ${optionIndex}, ${data.type} should not be an empty object`);
1755
+ }
1756
+ }
1757
+ let index = 0;
1758
+ for (const key in obj) {
1759
+ if (typeof obj[key] === 'object') {
1760
+ // Check if the object has keys "function" and "values"
1761
+ if ('function' in obj[key] && 'values' in obj[key]) {
1762
+ // Special handling for objects with keys "function" and "values"
1763
+ await this.parseActionEventInput(Object.assign({ key, value: obj[key] }, base_data));
1764
+ }
1765
+ else {
1766
+ // Normal recursive call for nested objects
1767
+ await this.validateActionInputData(Object.assign(Object.assign({}, base_data), { obj: obj[key], indexes: {
1768
+ key,
1769
+ index,
1770
+ parent_key: data.indexes.key,
1771
+ level: data.indexes.level++,
1772
+ } }), skipSample, option, optionIndex);
1773
+ }
1774
+ }
1775
+ else if (Array.isArray(obj[key])) {
1776
+ // If it's an array, iterate through each element
1777
+ Object.keys(obj[key]).forEach(async (elementKey) => {
1778
+ const element = obj[key][elementKey];
1779
+ if (typeof element === 'object') {
1780
+ // Check if the object within array has keys "function" and "values"
1781
+ if ('function' in element && 'values' in element) {
1782
+ // Special handling for objects within array with keys "function" and "values"
1783
+ await this.parseActionEventInput(Object.assign({ key: elementKey, value: element }, base_data));
1784
+ }
1785
+ else {
1786
+ // Normal recursive call for nested objects within arrays
1787
+ await this.validateActionInputData(Object.assign(Object.assign({}, base_data), { obj: element, indexes: {
1788
+ key: elementKey,
1789
+ index,
1790
+ parent_key: data.indexes.key,
1791
+ level: data.indexes.level++,
1792
+ } }), skipSample, option, optionIndex);
1793
+ }
1794
+ }
1795
+ else {
1796
+ await this.parseActionEventInput(Object.assign({ key: elementKey, value: element }, base_data));
1797
+ }
1798
+ });
1799
+ }
1800
+ else {
1801
+ await this.parseActionEventInput(Object.assign({ key, value: obj[key] }, base_data));
1802
+ }
1803
+ index++;
1804
+ }
1805
+ }
1806
+ validateConditional(event, feature, sequence_index, event_index) {
1807
+ const sequence = feature.sequence[sequence_index];
1808
+ const input = feature.input;
1809
+ const { condition } = event;
1810
+ // Define valid operators
1811
+ // Check if condition exists
1812
+ if (condition && condition.check) {
1813
+ // Split the check into parts: initiator, operator, and value
1814
+ const parts = (0, string_utils_1.extractConditionalParts)(condition.check);
1815
+ if (!parts) {
1816
+ throw new Error(`event ${event.event} in ${sequence.tag} has an invalid check format.
1817
+ Ensure it follows the pattern: initiator operator value (e.g., $Index < 10)
1818
+ Valid operators are: ${productsBuilder_types_1.ValidOperators.join(', ')}`);
1819
+ }
1820
+ const [, initiator, operator, value] = parts;
1821
+ if (condition.type === productsBuilder_types_1.Conditions.LOOP && initiator !== '$Index') {
1822
+ throw new Error(`invalid index ${initiator} in event ${event.event} in ${sequence.tag}, loop indexes are expected to be defined as $Index`);
1823
+ }
1824
+ // Validate operator
1825
+ if (!productsBuilder_types_1.ValidOperators.includes(operator)) {
1826
+ throw new Error(`event ${event.event} in ${sequence.tag} has an invalid operator "${operator}" for "${condition.type}" condition
1827
+ Valid operators are: ${productsBuilder_types_1.ValidOperators.join(', ')}`);
1828
+ }
1829
+ if (condition.type === productsBuilder_types_1.Conditions.LOOP && condition.iter) {
1830
+ // check if value is an integer
1831
+ throw new Error(`event ${event.event} in ${sequence.tag} has an invalid loop iter "${condition.iter}" is expected to be an integer .`);
1832
+ }
1833
+ // check if value is an integer
1834
+ if (condition.type === productsBuilder_types_1.Conditions.LOOP && condition.init && !Number.isInteger(condition.init)) {
1835
+ throw new Error(`event ${event.event} in ${sequence.tag} has an invalid loop init "${condition.init}" is expected to be an integer .`);
1836
+ }
1837
+ // check if value is not numeric but points towards a value
1838
+ if (condition.type === productsBuilder_types_1.Conditions.LOOP && !(0, string_utils_1.isNumeric)(value)) {
1839
+ //console.log(1, value);
1840
+ if (!value.startsWith('$')) {
1841
+ throw new Error(`event ${event.event} in ${sequence.tag} has an invalid operator "${operator}".`);
1842
+ }
1843
+ const payload = {
1844
+ datapoint: {
1845
+ key: 'condition-value',
1846
+ required: true,
1847
+ maxLength: 0,
1848
+ minLength: 0,
1849
+ type: enums_1.DataTypes.INTEGER, // value is expected to be a number
1850
+ },
1851
+ value,
1852
+ input: input,
1853
+ stages: this.extractStages(value),
1854
+ };
1855
+ const meta = { compare: true, feature, sequence_index, event_index, type: enums_1.Categories.CONDITIONAL };
1856
+ this.parseInputString(payload, meta);
1857
+ }
1858
+ if (condition.type === productsBuilder_types_1.Conditions.CHECK) {
1859
+ this.parseInputString({
1860
+ datapoint: {
1861
+ key: 'condition-initiator',
1862
+ required: true,
1863
+ maxLength: 0,
1864
+ minLength: 0,
1865
+ type: enums_1.DataTypes.STRING,
1866
+ },
1867
+ value: initiator,
1868
+ input: input,
1869
+ stages: this.extractStages(initiator),
1870
+ }, { compare: false, feature, sequence_index, event_index, type: enums_1.Categories.CONDITIONAL });
1871
+ //console.log(2, value);
1872
+ if (value.startsWith('$')) {
1873
+ this.parseInputString({
1874
+ datapoint: {
1875
+ key: 'condition-value',
1876
+ required: true,
1877
+ maxLength: 0,
1878
+ minLength: 0,
1879
+ type: enums_1.DataTypes.STRING,
1880
+ },
1881
+ value,
1882
+ input: input,
1883
+ stages: this.extractStages(value),
1884
+ }, { compare: false, feature, sequence_index, event_index, type: enums_1.Categories.CONDITIONAL });
1885
+ }
1886
+ }
1887
+ }
1888
+ // Check if the condition is a CHECK and allow_fail is true
1889
+ if (condition && condition.type === productsBuilder_types_1.Conditions.CHECK && event.allow_fail) {
1890
+ throw new Error(`event ${event.event} cannot set allow_fail: true as it is a check conditional`);
1891
+ }
1892
+ }
1893
+ async parseActionEventInput(data) {
1894
+ const datapoint = this.validateActionKeyPlacement(data);
1895
+ let stages, input;
1896
+ const opFunc = (0, functions_utils_1.extractFunctionAndArgs)(data.value); // TODO: check if this works
1897
+ if (typeof data.value === 'string' && !opFunc) {
1898
+ stages = this.extractStages(data.value);
1899
+ input = data.feature.input;
1900
+ this.parseInputString({ datapoint, value: data.value, input, stages }, {
1901
+ feature: data.feature,
1902
+ sequence_index: data.sequence_index,
1903
+ event_index: data.event_index,
1904
+ type: data.type,
1905
+ compare: true,
1906
+ });
1907
+ }
1908
+ }
1909
+ async parseInputString(payload, meta) {
1910
+ const { datapoint, value, input, stages } = payload;
1911
+ const sequence = meta.feature.sequence[meta.sequence_index];
1912
+ //console.log(3, value)
1913
+ if (!value) {
1914
+ //console.log(payload)
1915
+ return;
1916
+ }
1917
+ if ((this.isQuotaFallbackInput) && (0, string_utils_1.startsWithAny)(value, ['$Sequence{', '$Response{'])) {
1918
+ throw new Error(`Value ${value} cannot be a $Sequence or $Response value when defining Quota & Fallback input`);
1919
+ }
1920
+ if (value.startsWith('$Input{')) {
1921
+ let current_input = input;
1922
+ for (let i = 0; i < stages.length; i++) {
1923
+ let stage = stages[i];
1924
+ const matches = stage.match(/^\[(\d+)\]$/);
1925
+ if (matches && matches.length === 2) {
1926
+ const number = parseInt(matches[1], 10);
1927
+ if (!isNaN(number)) {
1928
+ stage = number;
1929
+ }
1930
+ else {
1931
+ throw new Error(`Invalid array value ${matches[1]}, should be an integer value`);
1932
+ }
1933
+ }
1934
+ if (!current_input[stage])
1935
+ throw new Error(`Input key ${stage} in ${value} does not exist`);
1936
+ current_input = current_input[stage];
1937
+ }
1938
+ if ((0, objects_utils_1.deepEqual)(current_input, input)) {
1939
+ throw new Error(`Error 490101: something unexpected happened`);
1940
+ }
1941
+ if (meta.compare)
1942
+ this.compareInputWithExpectedInput(datapoint, current_input, value);
1943
+ }
1944
+ else if (value.startsWith('$Auth{')) {
1945
+ // TODO: make sure that all auths have the same responses
1946
+ // TODO: make sure apps have only one auth, for now
1947
+ const { app: access_tag } = meta.feature.sequence[meta.sequence_index].events[meta.event_index];
1948
+ const _a = await this.fetchThirdPartyAppByAccessTag(access_tag), { version } = _a, app = __rest(_a, ["version"]);
1949
+ const { auths, actions } = app.versions.find((data) => data.tag === version);
1950
+ const auth_tag = stages[0];
1951
+ let auth;
1952
+ for (let i = 0; i < auths.length; i++) {
1953
+ if (auths[i].tag === auth_tag) {
1954
+ auth = auths[i];
1955
+ }
1956
+ }
1957
+ if (!auth) {
1958
+ throw new Error(`Auth in ${value} not found in app ${access_tag}`);
1959
+ }
1960
+ /*const { envs } = this.fetchApp(access_tag, false);
1961
+
1962
+ for(let i=0; i< envs.length; i++) {
1963
+ if (envs[i].auth.auth_tag ) {
1964
+ throw new Error(`Auth ${auth_tag} not in use in product environment ${envs[i].product_slug}, please be uniform in environment auth definition`)
1965
+ }
1966
+ }*/
1967
+ let response;
1968
+ let validated = false;
1969
+ if (auth.setup_type === enums_1.AuthTypes.CREDENTIALS) {
1970
+ const action = actions.find((item) => {
1971
+ return item.tag === auth.action_tag;
1972
+ });
1973
+ if (!action) {
1974
+ throw new Error(`Could not find auth action ${auth.action_tag}`);
1975
+ }
1976
+ response = action.responses.find((item) => item.success === true);
1977
+ }
1978
+ else {
1979
+ //const envs =
1980
+ const app = this.fetchApp(access_tag);
1981
+ const { envs } = app;
1982
+ await Promise.all(envs.map((env) => {
1983
+ if (stages[0] !== env.auth.auth_tag) {
1984
+ throw new Error(`Auth ${stages[0]} does not exist on env ${env.product_env_slug} on app ${access_tag}`);
1985
+ }
1986
+ const decrypted = JSON.parse((0, processor_utils_1.decrypt)(env.auth.values, this.fetchProduct().private_key));
1987
+ const check = (0, objects_utils_1.findFaultyKeys)(stages.slice(1), decrypted);
1988
+ if (check.faultyKeys) {
1989
+ 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}`);
1990
+ }
1991
+ // TODO: check for valid value
1992
+ validated = true;
1993
+ }));
1994
+ }
1995
+ if (response) {
1996
+ let parent_index = 0;
1997
+ let increment = false;
1998
+ let level = 0;
1999
+ let parent_key = '';
2000
+ let i = 1;
2001
+ while (i < stages.length) {
2002
+ let stage = stages[i];
2003
+ const matches = stage.match(/^\[(\d+)\]$/);
2004
+ if (matches && matches.length === 2) {
2005
+ const number = parseInt(matches[1], 10);
2006
+ if (!isNaN(number)) {
2007
+ stage = number;
2008
+ parent_index = number; // TODO: check whether this handles the array issue
2009
+ i++; // move to next stage instantly
2010
+ increment = true;
2011
+ }
2012
+ else {
2013
+ throw new Error(`Invalid array value ${matches[1]}, should be an integer value`);
2014
+ }
2015
+ }
2016
+ const found = response.body.data.find((item) => {
2017
+ if (!increment) {
2018
+ return item.parent_key === parent_key && item.key === stage && level === item.level;
2019
+ }
2020
+ else {
2021
+ return (item.parent_key === parent_key &&
2022
+ parent_index === stage &&
2023
+ stages[i] === item.key &&
2024
+ level === item.level);
2025
+ }
2026
+ });
2027
+ if (!found) {
2028
+ throw new Error(`Cannot find key: ${stage} in ${value}`);
2029
+ }
2030
+ level++;
2031
+ parent_key = String(stages[i]);
2032
+ if (i === stages.length - 1 && meta.compare) {
2033
+ this.compareInputWithExpectedInput(datapoint, found, value);
2034
+ }
2035
+ i++;
2036
+ }
2037
+ }
2038
+ else if (!validated) {
2039
+ throw new Error(`There is no successful response sample for Action ${auth.action_tag} in app ${access_tag}`);
2040
+ }
2041
+ }
2042
+ else if (value.startsWith('$Sequence{') || value.startsWith('$Response{')) {
2043
+ let isResponse = false;
2044
+ if (value.startsWith('$Response{')) {
2045
+ isResponse = true;
2046
+ }
2047
+ //let current_input = input as unknown as Record<string, unknown>;
2048
+ //const { feature, sequence_index, event_index} = meta;
2049
+ let parent_key = '';
2050
+ let level = 0;
2051
+ let i = 0;
2052
+ let sequence;
2053
+ let response;
2054
+ // handle array checks
2055
+ const indexer = (0, string_utils_1.validateAndLocateTag)(value);
2056
+ /*const bracketPattern = /\[(.*?)\]$/;
2057
+
2058
+ // Test the string for the pattern
2059
+ const matchBracket = value.match(bracketPattern);
2060
+
2061
+ // check if matchbracket value isnt index
2062
+ if (matchBracket) {
2063
+
2064
+ if(matchBracket[1] !== "$Index") {
2065
+ throw new Error(`Invalid sequence loop ending value: "${matchBracket[1]}". Only "$Index" is allowed.`);
2066
+ }
2067
+
2068
+ datapoint.type = DataTypes.ARRAY;
2069
+ }*/
2070
+ // console.log(value, stages)
2071
+ while (i < stages.length) {
2072
+ let stage = stages[i];
2073
+ let event;
2074
+ // let current_data;
2075
+ if (i === 0) {
2076
+ // find sequence by tag, see if it exists and its before current sequence
2077
+ this.validateSequenceInputParents(stage, meta.sequence_index, meta.feature.sequence);
2078
+ sequence = this.fetchPriorSequence(meta, stage);
2079
+ }
2080
+ if (i === 1 && sequence) {
2081
+ event = this.fetchSequenceEvent(sequence, stage);
2082
+ if (!event) {
2083
+ throw new Error(`event ${stage} not found in sequence ${sequence.tag}`);
2084
+ }
2085
+ let { type, app: access_tag, event: event_tag } = event;
2086
+ if (type === productsBuilder_types_1.FeatureEventTypes.ACTION) {
2087
+ const _b = await this.fetchThirdPartyAppByAccessTag(access_tag), { version } = _b, app = __rest(_b, ["version"]);
2088
+ const { actions } = app.versions.find((data) => data.tag === version);
2089
+ const { responses } = this.fetchThirdPartyAppActionByTag(actions, event_tag);
2090
+ response = responses.find((item) => item.success === true);
2091
+ // fetch success result
2092
+ if (!response) {
2093
+ throw new Error(`event ${stage} does not have a success response`);
2094
+ }
2095
+ }
2096
+ if (type === productsBuilder_types_1.FeatureEventTypes.DB_ACTION) {
2097
+ // TODO:
2098
+ }
2099
+ if (type === productsBuilder_types_1.FeatureEventTypes.JOB) {
2100
+ // TODO:
2101
+ }
2102
+ if (type === productsBuilder_types_1.FeatureEventTypes.NOTIFICATION) {
2103
+ // TODO:
2104
+ }
2105
+ //TODO: handle other types
2106
+ }
2107
+ if (i > 1 && response) {
2108
+ let parent_index = 0;
2109
+ let increment = false;
2110
+ const matches = stage.match(/^\[(\d+)\]$/);
2111
+ if (matches && matches.length === 2) {
2112
+ const number = parseInt(matches[1], 10);
2113
+ if (!isNaN(number)) {
2114
+ stage = number;
2115
+ parent_index = number; // TODO: check whether this handles the array issue
2116
+ i++; // move to next stage instantly
2117
+ increment = true;
2118
+ }
2119
+ else {
2120
+ throw new Error(`Invalid array value ${matches[1]}, should be an integer value`);
2121
+ }
2122
+ }
2123
+ const found = response.body.data.find((item) => {
2124
+ if (!increment) {
2125
+ return item.parent_key === parent_key && item.key === stage && level === item.level;
2126
+ }
2127
+ else {
2128
+ return (item.parent_key === parent_key &&
2129
+ parent_index === stage &&
2130
+ stages[i] === item.key &&
2131
+ level === item.level);
2132
+ }
2133
+ });
2134
+ if (!found) {
2135
+ throw new Error(`Cannot find key: ${stage} in ${value}`);
2136
+ }
2137
+ level++;
2138
+ parent_key = String(stages[i]);
2139
+ if (indexer && indexer === i) {
2140
+ // datapoint.type = DataTypes.ARRAY;
2141
+ // console.log({datapoint}, {found}, {value});
2142
+ // this.compareInputWithExpectedInput(datapoint, found as unknown as IParsedSample, value);
2143
+ if (found.type !== enums_1.DataTypes.ARRAY) {
2144
+ throw new Error(`{${stage}} in ${value} is required to be ${datapoint.type} not ${found.type}`);
2145
+ }
2146
+ }
2147
+ if (i === stages.length - 1 && meta.compare) {
2148
+ this.compareInputWithExpectedInput(datapoint, found, value);
2149
+ }
2150
+ }
2151
+ i++;
2152
+ }
2153
+ }
2154
+ else if (value === '$Default') {
2155
+ if (!datapoint.defaultValue) {
2156
+ throw new Error(`sequence ${sequence.tag} event ${sequence.events[meta.event_index].event} ${meta.type}, the key {${datapoint.key}: ${value}} does not have a default`);
2157
+ }
2158
+ }
2159
+ else if (value.startsWith('$Variable{')) {
2160
+ // $Variable{APP_NAME}$
2161
+ const stages = this.extractStages(value);
2162
+ if (stages.length < 2) {
2163
+ throw new Error(`sequence ${sequence.tag} event ${sequence.events[meta.event_index].event} ${meta.type}, has invalid varibale definition ${value}, you have to define what variable is to be used`);
2164
+ }
2165
+ if (stages.length > 2) {
2166
+ 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`);
2167
+ }
2168
+ const app = this.fetchApp(stages[0]);
2169
+ if (!app) {
2170
+ 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}. `);
2171
+ }
2172
+ if (!app.envs[0]) {
2173
+ throw new Error(`App ${stages[0]} has not environments defined`);
2174
+ }
2175
+ const { variables } = app.envs[0];
2176
+ if (!variables.find((item) => item.key === stages[1])) {
2177
+ throw new Error(`Variable ${stages[1]} does not exist in app ${stages[0]} in value ${value} in sequence ${sequence.tag} event ${sequence.events[meta.event_index].event} ${meta.type}`);
2178
+ }
2179
+ }
2180
+ else if (value.startsWith('$Constant{')) {
2181
+ const stages = this.extractStages(value);
2182
+ if (stages.length !== 2) {
2183
+ throw new Error(`When using constants you need to specify the constant in the format $Constant{app_tag}{key} instead of ${value}`);
2184
+ }
2185
+ const app_tag = stages[0];
2186
+ const key = stages[1];
2187
+ const _c = await this.fetchThirdPartyAppByAccessTag(app_tag), { version } = _c, app = __rest(_c, ["version"]);
2188
+ if (!app) {
2189
+ throw new Error(`App ${app_tag} not found in constant ${value}`);
2190
+ }
2191
+ const { constants } = app.versions.find((data) => data.tag === version);
2192
+ const exists = constants.find((item) => item.key === key);
2193
+ if (!exists) {
2194
+ throw new Error(`Constant with key ${key} in ${value}, does not exist on app ${app}`);
2195
+ }
2196
+ }
2197
+ else if (value.startsWith('$Length{') || value.startsWith('$Size{')) {
2198
+ const { matchLength, matchSize } = (0, string_utils_1.checkLengthAndSizeMatches)(value);
2199
+ let content;
2200
+ let type;
2201
+ if (matchLength) {
2202
+ content = matchLength[1];
2203
+ type = enums_1.DataTypes.ARRAY;
2204
+ }
2205
+ else if (matchSize) {
2206
+ // Added safeguard for $Size match
2207
+ content = matchSize[1];
2208
+ type = enums_1.DataTypes.OBJECT;
2209
+ }
2210
+ await this.parseInputString({
2211
+ datapoint: {
2212
+ key: 'value-evaluator',
2213
+ required: true,
2214
+ maxLength: 0,
2215
+ minLength: 0,
2216
+ type, // value is expected to be object or array
2217
+ },
2218
+ value: content,
2219
+ input: input,
2220
+ stages: this.extractStages(content),
2221
+ }, Object.assign(Object.assign({}, meta), { type: enums_1.Categories.CONDITIONAL }));
2222
+ }
2223
+ else if (value.startsWith('$')) {
2224
+ /*throw new Error(
2225
+ `sequence ${sequence.tag} event ${sequence.events[meta.event_index].event} ${meta.type} has invalid : {${
2226
+ datapoint.key
2227
+ }: ${value}}`,
2228
+ );*/
2229
+ (0, functions_utils_1.extractFunctionAndArgs)(value);
2230
+ }
2231
+ }
2232
+ compareInputWithExpectedInput(datapoint, found_input, value) {
2233
+ if (datapoint.maxLength !== 0 && found_input.maxLength && found_input.maxLength > datapoint.maxLength) {
2234
+ throw new Error(`maxlength of ${value} -> ${found_input.maxLength} cannot be greater than ${datapoint.maxLength}`);
2235
+ }
2236
+ if (datapoint.minLength !== 0 && found_input.minLength && found_input.minLength < datapoint.minLength) {
2237
+ throw new Error(`minlength of ${value} cannot be less than ${datapoint.minLength}`);
2238
+ }
2239
+ const strTypes = [
2240
+ enums_1.DataTypes.EMAIL_STRING,
2241
+ enums_1.DataTypes.NOSPACES_STRING,
2242
+ enums_1.DataTypes.UUID,
2243
+ enums_1.DataTypes.NUMBER_STRING,
2244
+ enums_1.DataTypes.INTEGER,
2245
+ ];
2246
+ const dateTypes = [
2247
+ enums_1.DataTypes.DATE,
2248
+ enums_1.DataTypes.DATE_STRING
2249
+ ];
2250
+ const strException = ((datapoint.type === enums_1.DataTypes.STRING || found_input.type === enums_1.DataTypes.STRING) &&
2251
+ (strTypes.includes(found_input.type) || strTypes.includes(datapoint.type)));
2252
+ const dateException = ((datapoint.type === enums_1.DataTypes.INTEGER || found_input.type === enums_1.DataTypes.INTEGER) &&
2253
+ (dateTypes.includes(found_input.type) || dateTypes.includes(datapoint.type)));
2254
+ if (datapoint.type !== found_input.type && !strException && !dateException) {
2255
+ //console.log("STR EXCEPTION", strException, found_input.type, datapoint.type)
2256
+ throw new Error(`${value} is required to be ${datapoint.type} not ${found_input.type}`);
2257
+ }
2258
+ }
2259
+ extractStages(input) {
2260
+ return (0, string_utils_1.extractStages)(input);
2261
+ }
2262
+ fetchSequenceEvent(sequence, event) {
2263
+ return sequence.events.find((item) => item.event === event);
2264
+ }
2265
+ fetchPriorSequence(meta, stage) {
2266
+ let found;
2267
+ for (let i = 0; i < meta.sequence_index; i++) {
2268
+ if (meta.feature.sequence[i].tag === stage) {
2269
+ found = meta.feature.sequence[i];
2270
+ }
2271
+ }
2272
+ if (!found) {
2273
+ const sequence = meta.feature.sequence[meta.sequence_index].tag;
2274
+ throw `sequence ${stage} not found before ${sequence}, values can only inherit from sequences before them in the feature chain`;
2275
+ }
2276
+ return found;
2277
+ }
2278
+ validateActionKeyPlacement(data) {
2279
+ const actionData = data.sample.data;
2280
+ const { indexes } = data;
2281
+ const sequence = data.feature.sequence[data.sequence_index];
2282
+ const datapoint = actionData.find((item) => {
2283
+ return (item.parent_key === indexes.parent_key && item.key === data.key && item.level === indexes.level //&&
2284
+ //indexes.index === item.index
2285
+ );
2286
+ });
2287
+ if (!datapoint) {
2288
+ console.log("VALIDATE", data.key, data.value, actionData, indexes);
2289
+ throw new Error(`Key ${data.key} not found for ${data.type} for sequence ${sequence.tag} event ${sequence.events[data.event_index].event}`);
2290
+ }
2291
+ return datapoint;
2292
+ }
2293
+ async fetchThirdPartyAppByAccessTag(access_tag) {
2294
+ try {
2295
+ const app = this.thirdPartyApps.find((item) => access_tag === item.access_tag);
2296
+ if (app) {
2297
+ return Object.assign(Object.assign({}, app.app), { version: app.version });
2298
+ }
2299
+ const access = await this.appApi.fetchAccessByTag(access_tag, this.getUserAccess());
2300
+ if (!access) {
2301
+ throw new Error(`Access to app ${access_tag} not found`);
2302
+ }
2303
+ const appData = await this.appApi.fetchApp(access.app_id, this.getUserAccess());
2304
+ this.thirdPartyApps.push({ access_tag, app: appData, version: access.version });
2305
+ return Object.assign(Object.assign({}, appData), { version: access.version });
2306
+ }
2307
+ catch (e) {
2308
+ throw e;
2309
+ }
2310
+ }
2311
+ fetchThirdPartyAppActionByTag(actions, action_tag) {
2312
+ const action = actions.find((action) => action.tag === action_tag);
2313
+ if (!action) {
2314
+ throw new Error(`Action ${action_tag} not found`);
2315
+ }
2316
+ return action;
2317
+ }
2318
+ async createFeature(data, throwErrorIfExists = false) {
2319
+ try {
2320
+ if (!this.fetchFeature(data.tag, false)) {
2321
+ await validators_1.CreateProductFeatureSchema.validateAsync(data);
2322
+ try {
2323
+ await this.validateFeatureData(data);
2324
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.FEATURE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
2325
+ await this.initializeProduct(this.product_id);
2326
+ }
2327
+ catch (e) {
2328
+ throw e;
2329
+ }
2330
+ }
2331
+ else {
2332
+ if (throwErrorIfExists)
2333
+ throw new Error(`Feature ${data.tag} already exists`);
2334
+ }
2335
+ }
2336
+ catch (e) {
2337
+ throw e;
2338
+ }
2339
+ }
2340
+ async updateFeature(tag, data) {
2341
+ try {
2342
+ const feature = this.fetchFeature(tag);
2343
+ if (!feature) {
2344
+ throw new Error(`Feature ${tag} not found`);
2345
+ }
2346
+ const { _id } = feature;
2347
+ await validators_1.UpdateProductFeatureSchema.validateAsync(data); // Change to update;
2348
+ await this.validateFeatureData(Object.assign({ tag }, data));
2349
+ if (data.tag && this.fetchFeature(data.tag)) {
2350
+ throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
2351
+ }
2352
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({ _id,
2353
+ tag }, data), { component: enums_1.ProductComponents.FEATURE, action: enums_1.RequestAction.UPDATE }), this.getUserAccess());
2354
+ await this.initializeProduct(this.product_id);
2355
+ }
2356
+ catch (e) {
2357
+ throw e;
2358
+ }
2359
+ }
2360
+ fetchFeature(tag, throwErrorIfExists = true) {
2361
+ const feature = this.product.features.find((data) => data.tag === tag);
2362
+ if (!feature && throwErrorIfExists)
2363
+ throw new Error(`Feature ${tag} not found`);
2364
+ return feature;
2365
+ }
2366
+ fetchFeatures() {
2367
+ return this.product.features;
2368
+ }
2369
+ async createDatabase(data, throwErrorIfExists = false) {
2370
+ try {
2371
+ // TODO: figure out a way to check if this has run before, halt if it has
2372
+ if (!this.fetchDatabase(data.tag, false)) {
2373
+ await validators_1.CreateProductDatabaseSchema.validateAsync(data);
2374
+ data.envs = data.envs.map((env) => {
2375
+ const exists = this.fetchEnv(env.slug);
2376
+ if (!exists) {
2377
+ throw new Error(`Env ${env.slug} does not exist`);
2378
+ }
2379
+ env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.fetchProduct().private_key);
2380
+ return env;
2381
+ });
2382
+ const envs = this.fetchEnvs();
2383
+ envs.map((env) => {
2384
+ const exists = data.envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
2385
+ if (exists === -1) {
2386
+ throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
2387
+ }
2388
+ });
2389
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.DATABASE, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
2390
+ await this.initializeProduct(this.product_id);
2391
+ }
2392
+ else {
2393
+ if (throwErrorIfExists)
2394
+ throw new Error(`Database ${data.tag} already exists`);
2395
+ }
2396
+ }
2397
+ catch (e) {
2398
+ throw e;
2399
+ }
2400
+ }
2401
+ async updateDatabase(tag, data) {
2402
+ try {
2403
+ const db = this.fetchDatabase(tag);
2404
+ if (!db) {
2405
+ throw new Error(`Database ${tag} not found`);
2406
+ }
2407
+ const { _id, envs } = db;
2408
+ await validators_1.UpdateProductDatabaseSchema.validateAsync(data); // Change to update;
2409
+ if (data.tag && this.fetchDatabase(data.tag)) {
2410
+ throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
2411
+ }
2412
+ data.envs = data.envs.map((env) => {
2413
+ const exists = this.fetchEnv(env.slug);
2414
+ if (!exists) {
2415
+ throw new Error(`Env ${env.slug} does not exist`);
2416
+ }
2417
+ if (env.connection_url)
2418
+ env.connection_url = (0, processor_utils_1.encrypt)(env.connection_url, this.fetchProduct().private_key);
2419
+ return env;
2420
+ });
2421
+ const overwrite = [];
2422
+ const newEnvs = [];
2423
+ data.envs.map((dataEnv) => {
2424
+ const exists = envs.findIndex((env) => env.slug === dataEnv.slug);
2425
+ if (!this.fetchEnv(dataEnv.slug)) {
2426
+ throw new Error(`Product Environment ${dataEnv.slug} doesn't exist`);
2427
+ }
2428
+ if (exists === -1) {
2429
+ if (!dataEnv.connection_url) {
2430
+ throw new Error(`connection_url is required for new env ${data.envs[exists].slug}`);
2431
+ }
2432
+ newEnvs.push(dataEnv);
2433
+ }
2434
+ else {
2435
+ overwrite.push(Object.assign(Object.assign({}, envs[exists]), dataEnv));
2436
+ }
2437
+ });
2438
+ const unchanged = [];
2439
+ envs.map((env) => {
2440
+ const newEnv = newEnvs.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
2441
+ const overwriteEnv = overwrite.findIndex((dataEnv) => env.slug === dataEnv.slug) > -1;
2442
+ if (!newEnv && !overwriteEnv) {
2443
+ unchanged.push(env);
2444
+ }
2445
+ });
2446
+ data.envs = [...unchanged, ...overwrite, ...newEnvs];
2447
+ //console.log("UPDATED!!!", JSON.stringify(data.envs))
2448
+ 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());
2449
+ await this.initializeProduct(this.product_id);
2450
+ }
2451
+ catch (e) {
2452
+ throw e;
2453
+ }
2454
+ }
2455
+ fetchDatabase(tag, throwErrorIfExists = false) {
2456
+ const database = this.product.databases.find((data) => data.tag === tag);
2457
+ if (!database && throwErrorIfExists)
2458
+ throw new Error(`Database ${tag} not found`);
2459
+ return database;
2460
+ }
2461
+ fetchDatabases() {
2462
+ return this.product.databases;
2463
+ }
2464
+ async createDatabaseAction(data, throwErrorIfExists = false) {
2465
+ try {
2466
+ if (!data.tag) {
2467
+ throw new Error('tag field is required');
2468
+ }
2469
+ const [databaseTag, tag] = data.tag.split(':');
2470
+ if (!databaseTag || !tag) {
2471
+ throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
2472
+ }
2473
+ const exists = this.fetchDatabaseAction(data.tag);
2474
+ data.tag = tag;
2475
+ if (!exists) {
2476
+ const database = this.fetchDatabase(databaseTag);
2477
+ let values, template;
2478
+ if (database.type === productsBuilder_types_1.DatabaseTypes.MONGODB) {
2479
+ await create_productDatabaseAction_validator_1.NOSQLDatabaseActionsSchema.validateAsync(data);
2480
+ values = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.template));
2481
+ template = JSON.stringify(data.template);
2482
+ if (data.type === productsBuilder_types_1.DatabaseActionTypes.UPDATE && !data.filterTemplate) {
2483
+ throw new Error(`filterTemplate is required for ${productsBuilder_types_1.DatabaseActionTypes.UPDATE} actions in ${productsBuilder_types_1.DatabaseTypes.MONGODB}`);
2484
+ }
2485
+ if (data.filterTemplate) {
2486
+ data.filterData = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.filterTemplate));
2487
+ data.filterTemplate = JSON.stringify(data.filterTemplate);
2488
+ }
2489
+ }
2490
+ else {
2491
+ create_productDatabaseAction_validator_1.SQLDatabaseActionSchema.validateAsync(data);
2492
+ values = (0, string_utils_1.extractPlaceholders)(String(data.template));
2493
+ template = data.template;
2494
+ if (data.filterTemplate) {
2495
+ data.filterData = (0, string_utils_1.extractPlaceholders)(String(data.filterTemplate));
2496
+ }
2497
+ }
2498
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { data: values, template,
2499
+ databaseTag, component: enums_1.ProductComponents.DATABASE_ACTION, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
2500
+ await this.initializeProduct(this.product_id);
2501
+ }
2502
+ else {
2503
+ if (throwErrorIfExists)
2504
+ throw new Error(`Database Action ${data.tag} already exists`);
2505
+ }
2506
+ }
2507
+ catch (e) {
2508
+ throw e;
2509
+ }
2510
+ }
2511
+ fetchDatabaseAction(tag, throwErrorIfExists = false) {
2512
+ const [databaseTag, actionTag] = tag.split(':');
2513
+ if (!databaseTag || !actionTag) {
2514
+ throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
2515
+ }
2516
+ const database = this.product.databases.find((data) => data.tag === databaseTag);
2517
+ if (!database)
2518
+ throw new Error(`Database ${databaseTag} not found`);
2519
+ const action = database.actions.find((data) => data.tag === actionTag);
2520
+ if (!action && throwErrorIfExists)
2521
+ throw new Error(`Database action ${tag} not found`);
2522
+ if (database.type === productsBuilder_types_1.DatabaseTypes.MONGODB && action) {
2523
+ //console.log(action.template)
2524
+ // action.template = JSON.parse(action.template);
2525
+ }
2526
+ return action;
2527
+ }
2528
+ async updateDatabaseAction(data) {
2529
+ try {
2530
+ if (!data.tag) {
2531
+ throw new Error('tag field is required');
2532
+ }
2533
+ const [databaseTag, tag] = data.tag.split(':');
2534
+ if (!databaseTag || !tag) {
2535
+ throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
2536
+ }
2537
+ // Fetch required data
2538
+ const database = await this.fetchDatabase(databaseTag, true);
2539
+ const action = await this.fetchDatabaseAction(data.tag, true);
2540
+ // Construct payload
2541
+ const payload = Object.assign(Object.assign(Object.assign({}, action), data), { databaseTag, component: enums_1.ProductComponents.DATABASE_ACTION, action: enums_1.RequestAction.UPDATE });
2542
+ // Validate and process the template
2543
+ data.tag = tag;
2544
+ if (data.template) {
2545
+ let values, template;
2546
+ if (database.type === productsBuilder_types_1.DatabaseTypes.MONGODB) {
2547
+ await update_productDatabaseAction_validator_1.UpdateNOSQLDatabaseActionsSchema.validateAsync(data);
2548
+ values = (0, string_utils_1.extractPlaceholders)(JSON.stringify(data.template));
2549
+ template = JSON.stringify(data.template);
2550
+ }
2551
+ else {
2552
+ await update_productDatabaseAction_validator_1.UpdateSQLDatabaseActionSchema.validateAsync(data);
2553
+ values = (0, string_utils_1.extractPlaceholders)(String(data.template));
2554
+ template = data.template;
2555
+ }
2556
+ Object.assign(payload, { data: values, template });
2557
+ }
2558
+ else if (database.type === productsBuilder_types_1.DatabaseTypes.MONGODB) {
2559
+ await update_productDatabaseAction_validator_1.UpdateNOSQLDatabaseActionsSchema.validateAsync(data);
2560
+ }
2561
+ else {
2562
+ await update_productDatabaseAction_validator_1.UpdateSQLDatabaseActionSchema.validateAsync(data);
2563
+ }
2564
+ // Update product and reinitialize
2565
+ await this.productApi.updateProduct(this.product_id, payload, this.getUserAccess());
2566
+ await this.initializeProduct(this.product_id);
2567
+ }
2568
+ catch (error) {
2569
+ throw error;
2570
+ }
2571
+ }
2572
+ fetchDatabaseActions(databaseTag) {
2573
+ const database = this.product.databases.find((data) => data.tag === databaseTag);
2574
+ if (!database)
2575
+ throw new Error(`Database ${databaseTag} not found`);
2576
+ const actions = database.actions;
2577
+ if (database.type === productsBuilder_types_1.DatabaseTypes.MONGODB && actions.length) {
2578
+ /*return actions.map((data)=>{
2579
+ return{ ...data,template: JSON.parse(String(data.template))}
2580
+ })*/
2581
+ }
2582
+ return actions;
2583
+ }
2584
+ async createDatabaseMigration(data, throwErrorIfExists) {
2585
+ if (!data.tag) {
2586
+ throw new Error('tag field is required');
2587
+ }
2588
+ const [databaseTag, tag] = data.tag.split(':');
2589
+ if (!databaseTag || !tag) {
2590
+ throw new Error(`tag is expected to be defined as "database_tag:migration_tag"`);
2591
+ }
2592
+ const exists = this.fetchDatabaseMigration(data.tag);
2593
+ data.tag = tag;
2594
+ await create_productDatabaseMigration_validator_1.default.validateAsync(Object.assign(Object.assign({}, data), { databaseTag })); // Change to update;
2595
+ if (!exists) {
2596
+ const database = this.fetchDatabase(databaseTag, true);
2597
+ if (database.type === productsBuilder_types_1.DatabaseTypes.MONGODB) {
2598
+ throw new Error(`${database.type} does not support migrations`);
2599
+ }
2600
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { databaseTag, component: enums_1.ProductComponents.DATABASE_MIGRATION }), this.getUserAccess());
2601
+ await this.initializeProduct(this.product_id);
2602
+ }
2603
+ else {
2604
+ if (throwErrorIfExists)
2605
+ throw new Error(`Database Action ${data.tag} already exists`);
2606
+ }
2607
+ }
2608
+ async updateDatabaseMigration(data) {
2609
+ if (!data.tag) {
2610
+ throw new Error('tag field is required');
2611
+ }
2612
+ const [databaseTag, tag] = data.tag.split(':');
2613
+ if (!databaseTag || !tag) {
2614
+ throw new Error(`tag is expected to be defined as "database_tag:migration_tag"`);
2615
+ }
2616
+ await update_productDatabaseMigration_validator_1.default.validateAsync(Object.assign(Object.assign({}, data), { databaseTag })); // Change to update;
2617
+ const action = this.fetchDatabaseMigration(data.tag);
2618
+ if (!action) {
2619
+ throw new Error(`Migration ${data.tag} not found`);
2620
+ }
2621
+ data.tag = tag;
2622
+ 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());
2623
+ await this.initializeProduct(this.product_id);
2624
+ }
2625
+ fetchDatabaseMigration(tag, throwError = false) {
2626
+ const [databaseTag, migrationTag] = tag.split(':');
2627
+ if (!databaseTag || !migrationTag) {
2628
+ throw new Error(`tag is expected to be defined as "database_tag:action_tag"`);
2629
+ }
2630
+ const database = this.product.databases.find((data) => data.tag === databaseTag);
2631
+ if (!database)
2632
+ throw new Error(`Database ${databaseTag} not found`);
2633
+ const migration = database.migrations.find((data) => data.tag === migrationTag);
2634
+ if (!migration && throwError)
2635
+ throw new Error(`Database migration ${tag} not found`);
2636
+ return migration;
2637
+ }
2638
+ fetchDatabaseMigrations(databaseTag) {
2639
+ const database = this.product.databases.find((data) => data.tag === databaseTag);
2640
+ if (!database)
2641
+ throw new Error(`Database ${databaseTag} not found`);
2642
+ const migrations = database.migrations;
2643
+ return migrations;
2644
+ }
2645
+ async validateJobEvent(data) {
2646
+ const { type, app, event } = data;
2647
+ if (type === productsBuilder_types_1.JobEventTypes.ACTION) {
2648
+ const appl = await this.fetchThirdPartyAppByAccessTag(app);
2649
+ if (!appl) {
2650
+ throw new Error(`App with access tag ${app} not found`);
2651
+ }
2652
+ const version = appl.versions.find((version) => version.tag === appl.version);
2653
+ const action = version.actions.find((action) => action.tag === event);
2654
+ if (!action) {
2655
+ throw new Error(`Cannot find action ${event} on app ${appl.tag} version ${appl.version}`);
2656
+ }
2657
+ }
2658
+ if (type === productsBuilder_types_1.JobEventTypes.DATABASE_ACTION) {
2659
+ const found = this.fetchDatabaseAction(event);
2660
+ if (!found) {
2661
+ throw new Error(`Database action ${event} not found`);
2662
+ }
2663
+ }
2664
+ if (type === productsBuilder_types_1.JobEventTypes.FUNCTION) {
2665
+ const found = this.fetchFunction(event);
2666
+ if (!found) {
2667
+ throw new Error(`Cloud function ${event} not found`);
2668
+ }
2669
+ }
2670
+ if (type === productsBuilder_types_1.JobEventTypes.STORAGE) {
2671
+ const found = this.fetchStorage(event);
2672
+ if (!found) {
2673
+ throw new Error(`Storage ${event} not found`);
2674
+ }
2675
+ }
2676
+ if (type === productsBuilder_types_1.JobEventTypes.NOTIFICATION) {
2677
+ const found = this.fetchNotification(event);
2678
+ if (!found) {
2679
+ throw new Error(`Notification ${event} not found`);
2680
+ }
2681
+ }
2682
+ if (type === productsBuilder_types_1.JobEventTypes.PUBLISH) {
2683
+ const found = this.fetchMessageBroker(event);
2684
+ if (!found) {
2685
+ throw new Error(`Message Broker ${event} not found`);
2686
+ }
2687
+ }
2688
+ }
2689
+ async createJob(data, throwErrorIfExists = false) {
2690
+ try {
2691
+ // TODO: figure out a way to check if this has run before, halt if it has
2692
+ if (!this.fetchJob(data.tag)) {
2693
+ await validators_1.CreateProductJobSchema.validateAsync(data);
2694
+ await this.validateJobEvent(data);
2695
+ if (data.type === productsBuilder_types_1.JobEventTypes.ACTION) {
2696
+ const app = await this.fetchThirdPartyAppByAccessTag(data.app);
2697
+ if (!app) {
2698
+ throw new Error(`Invalid app ${data.app}`);
2699
+ }
2700
+ const { version, versions } = app;
2701
+ const myVersion = versions.find((data) => data.tag === version);
2702
+ if (!myVersion) {
2703
+ throw new Error(`Invlaid version ${version} for app ${data.app}`);
2704
+ }
2705
+ const action = myVersion.actions.findIndex((action) => data.event === action.tag);
2706
+ if (!action) {
2707
+ throw new Error(`Invlaid event ${data.event} on version ${version} for app ${data.app}`);
2708
+ }
2709
+ }
2710
+ if (data.type === productsBuilder_types_1.JobEventTypes.DATABASE_ACTION) {
2711
+ const dbAction = await this.fetchDatabaseAction(data.event);
2712
+ }
2713
+ await this.productApi.updateProduct(this.product_id, Object.assign(Object.assign({}, data), { component: enums_1.ProductComponents.JOB, action: enums_1.RequestAction.CREATE }), this.getUserAccess());
2714
+ await this.initializeProduct(this.product_id);
2715
+ }
2716
+ else {
2717
+ if (throwErrorIfExists)
2718
+ throw new Error(`Job ${data.tag} already exists`);
2719
+ }
2720
+ }
2721
+ catch (e) {
2722
+ throw e;
2723
+ }
2724
+ }
2725
+ async updateJob(tag, data) {
2726
+ try {
2727
+ const job = this.fetchJob(tag);
2728
+ if (!job) {
2729
+ throw new Error(`Job ${tag} not found`);
2730
+ }
2731
+ await validators_1.UpdateProductJobSchema.validateAsync(data); // Change to update;
2732
+ await this.validateJobEvent(data);
2733
+ if (data.tag && this.fetchJob(data.tag)) {
2734
+ throw new Error(`tag ${tag} is in use`); // TODO: also check on the backend
2735
+ }
2736
+ 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());
2737
+ await this.initializeProduct(this.product_id);
2738
+ }
2739
+ catch (e) {
2740
+ throw e;
2741
+ }
2742
+ }
2743
+ fetchJob(tag, throwError = false) {
2744
+ const job = this.product.jobs.find((data) => data.tag === tag);
2745
+ if (!job && throwError)
2746
+ throw new Error(`Job ${tag} not found`);
2747
+ return job;
2748
+ }
2749
+ fetchJobs() {
2750
+ return this.product.jobs;
2751
+ }
2752
+ getUserAccess() {
2753
+ return {
2754
+ user_id: this.user_id,
2755
+ workspace_id: this.workspace_id,
2756
+ token: this.token,
2757
+ public_key: this.public_key,
2758
+ };
2759
+ }
2760
+ }
2761
+ exports.default = ProductsBuilderService;
2762
+ //# sourceMappingURL=products.service.js.map