@ductape/sdk 0.0.4-v5 → 0.0.4-v51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (338) hide show
  1. package/README.md +1 -1
  2. package/dist/api/services/appApi.service.d.ts +48 -2
  3. package/dist/api/services/appApi.service.js +101 -2
  4. package/dist/api/services/appApi.service.js.map +1 -1
  5. package/dist/api/services/pricingApi.service.d.ts +10 -0
  6. package/dist/api/services/pricingApi.service.js +34 -0
  7. package/dist/api/services/pricingApi.service.js.map +1 -0
  8. package/dist/api/services/processorApi.service.d.ts +12 -2
  9. package/dist/api/services/processorApi.service.js +12 -2
  10. package/dist/api/services/processorApi.service.js.map +1 -1
  11. package/dist/api/services/productsApi.service.d.ts +40 -1
  12. package/dist/api/services/productsApi.service.js +105 -1
  13. package/dist/api/services/productsApi.service.js.map +1 -1
  14. package/dist/api/services/userApi.service.js +1 -0
  15. package/dist/api/services/userApi.service.js.map +1 -1
  16. package/dist/api/services/workspaceApi.service.js +1 -0
  17. package/dist/api/services/workspaceApi.service.js.map +1 -1
  18. package/dist/api/services/workspaceSecretsApi.service.d.ts +75 -0
  19. package/dist/api/services/workspaceSecretsApi.service.js +62 -0
  20. package/dist/api/services/workspaceSecretsApi.service.js.map +1 -0
  21. package/dist/api/urls.d.ts +6 -1
  22. package/dist/api/urls.js +12 -2
  23. package/dist/api/urls.js.map +1 -1
  24. package/dist/api/utils/cache.utils.d.ts +1 -1
  25. package/dist/api/utils/cache.utils.js +10 -4
  26. package/dist/api/utils/cache.utils.js.map +1 -1
  27. package/dist/api/utils/strings.utils.d.ts +2 -0
  28. package/dist/api/utils/strings.utils.js +14 -0
  29. package/dist/api/utils/strings.utils.js.map +1 -1
  30. package/dist/apps/services/app.service.d.ts +51 -33
  31. package/dist/apps/services/app.service.js +488 -244
  32. package/dist/apps/services/app.service.js.map +1 -1
  33. package/dist/apps/validators/joi-validators/create.appAction.validator.d.ts +1 -2
  34. package/dist/apps/validators/joi-validators/create.appAction.validator.js +21 -2
  35. package/dist/apps/validators/joi-validators/create.appAction.validator.js.map +1 -1
  36. package/dist/apps/validators/joi-validators/create.appWebhook.validator.d.ts +1 -2
  37. package/dist/apps/validators/joi-validators/create.appWebhook.validator.js +2 -15
  38. package/dist/apps/validators/joi-validators/create.appWebhook.validator.js.map +1 -1
  39. package/dist/apps/validators/joi-validators/update.appAction.validator.js +11 -1
  40. package/dist/apps/validators/joi-validators/update.appAction.validator.js.map +1 -1
  41. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.d.ts +1 -1
  42. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js +34 -1
  43. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js.map +1 -1
  44. package/dist/apps/validators/joi-validators/update.appWebhook.validator.d.ts +1 -2
  45. package/dist/apps/validators/joi-validators/update.appWebhook.validator.js +2 -14
  46. package/dist/apps/validators/joi-validators/update.appWebhook.validator.js.map +1 -1
  47. package/dist/clients/pricing.client.d.ts +3 -0
  48. package/dist/clients/pricing.client.js +33 -0
  49. package/dist/clients/pricing.client.js.map +1 -0
  50. package/dist/database/adapters/base.adapter.d.ts +176 -0
  51. package/dist/database/adapters/base.adapter.js +31 -0
  52. package/dist/database/adapters/base.adapter.js.map +1 -0
  53. package/dist/database/adapters/dynamodb.adapter.d.ts +91 -0
  54. package/dist/database/adapters/dynamodb.adapter.js +1608 -0
  55. package/dist/database/adapters/dynamodb.adapter.js.map +1 -0
  56. package/dist/database/adapters/mongodb.adapter.d.ts +71 -0
  57. package/dist/database/adapters/mongodb.adapter.js +1072 -0
  58. package/dist/database/adapters/mongodb.adapter.js.map +1 -0
  59. package/dist/database/adapters/mysql.adapter.d.ts +146 -0
  60. package/dist/database/adapters/mysql.adapter.js +1492 -0
  61. package/dist/database/adapters/mysql.adapter.js.map +1 -0
  62. package/dist/database/adapters/postgresql.adapter.d.ts +147 -0
  63. package/dist/database/adapters/postgresql.adapter.js +1603 -0
  64. package/dist/database/adapters/postgresql.adapter.js.map +1 -0
  65. package/dist/database/database.service.d.ts +232 -0
  66. package/dist/database/database.service.js +802 -0
  67. package/dist/database/database.service.js.map +1 -0
  68. package/dist/database/index.d.ts +18 -0
  69. package/dist/database/index.js +98 -0
  70. package/dist/database/index.js.map +1 -0
  71. package/dist/database/types/aggregation.types.d.ts +261 -0
  72. package/dist/database/types/aggregation.types.js +21 -0
  73. package/dist/database/types/aggregation.types.js.map +1 -0
  74. package/dist/database/types/connection.types.d.ts +132 -0
  75. package/dist/database/types/connection.types.js +6 -0
  76. package/dist/database/types/connection.types.js.map +1 -0
  77. package/dist/database/types/database.types.d.ts +175 -0
  78. package/dist/database/types/database.types.js +75 -0
  79. package/dist/database/types/database.types.js.map +1 -0
  80. package/dist/database/types/index.d.ts +12 -0
  81. package/dist/database/types/index.js +37 -0
  82. package/dist/database/types/index.js.map +1 -0
  83. package/dist/database/types/index.types.d.ts +220 -0
  84. package/dist/database/types/index.types.js +27 -0
  85. package/dist/database/types/index.types.js.map +1 -0
  86. package/dist/database/types/migration.types.d.ts +205 -0
  87. package/dist/database/types/migration.types.js +44 -0
  88. package/dist/database/types/migration.types.js.map +1 -0
  89. package/dist/database/types/query.types.d.ts +305 -0
  90. package/dist/database/types/query.types.js +57 -0
  91. package/dist/database/types/query.types.js.map +1 -0
  92. package/dist/database/types/result.types.d.ts +220 -0
  93. package/dist/database/types/result.types.js +6 -0
  94. package/dist/database/types/result.types.js.map +1 -0
  95. package/dist/database/types/schema.types.d.ts +190 -0
  96. package/dist/database/types/schema.types.js +69 -0
  97. package/dist/database/types/schema.types.js.map +1 -0
  98. package/dist/database/utils/helpers.d.ts +66 -0
  99. package/dist/database/utils/helpers.js +501 -0
  100. package/dist/database/utils/helpers.js.map +1 -0
  101. package/dist/database/utils/migration.utils.d.ts +151 -0
  102. package/dist/database/utils/migration.utils.js +476 -0
  103. package/dist/database/utils/migration.utils.js.map +1 -0
  104. package/dist/database/utils/transaction.d.ts +64 -0
  105. package/dist/database/utils/transaction.js +130 -0
  106. package/dist/database/utils/transaction.js.map +1 -0
  107. package/dist/database/validators/connection.validator.d.ts +20 -0
  108. package/dist/database/validators/connection.validator.js +267 -0
  109. package/dist/database/validators/connection.validator.js.map +1 -0
  110. package/dist/database/validators/query.validator.d.ts +31 -0
  111. package/dist/database/validators/query.validator.js +305 -0
  112. package/dist/database/validators/query.validator.js.map +1 -0
  113. package/dist/database/validators/schema.validator.d.ts +31 -0
  114. package/dist/database/validators/schema.validator.js +334 -0
  115. package/dist/database/validators/schema.validator.js.map +1 -0
  116. package/dist/graph/adapters/arangodb.adapter.d.ts +80 -0
  117. package/dist/graph/adapters/arangodb.adapter.js +1393 -0
  118. package/dist/graph/adapters/arangodb.adapter.js.map +1 -0
  119. package/dist/graph/adapters/base.adapter.d.ts +228 -0
  120. package/dist/graph/adapters/base.adapter.js +38 -0
  121. package/dist/graph/adapters/base.adapter.js.map +1 -0
  122. package/dist/graph/adapters/index.d.ts +10 -0
  123. package/dist/graph/adapters/index.js +23 -0
  124. package/dist/graph/adapters/index.js.map +1 -0
  125. package/dist/graph/adapters/memgraph.adapter.d.ts +85 -0
  126. package/dist/graph/adapters/memgraph.adapter.js +1491 -0
  127. package/dist/graph/adapters/memgraph.adapter.js.map +1 -0
  128. package/dist/graph/adapters/neo4j.adapter.d.ts +88 -0
  129. package/dist/graph/adapters/neo4j.adapter.js +1861 -0
  130. package/dist/graph/adapters/neo4j.adapter.js.map +1 -0
  131. package/dist/graph/adapters/neptune.adapter.d.ts +87 -0
  132. package/dist/graph/adapters/neptune.adapter.js +1430 -0
  133. package/dist/graph/adapters/neptune.adapter.js.map +1 -0
  134. package/dist/graph/graph.service.d.ts +278 -0
  135. package/dist/graph/graph.service.js +687 -0
  136. package/dist/graph/graph.service.js.map +1 -0
  137. package/dist/graph/index.d.ts +11 -0
  138. package/dist/graph/index.js +42 -0
  139. package/dist/graph/index.js.map +1 -0
  140. package/dist/graph/types/connection.types.d.ts +158 -0
  141. package/dist/graph/types/connection.types.js +43 -0
  142. package/dist/graph/types/connection.types.js.map +1 -0
  143. package/dist/graph/types/graph.types.d.ts +144 -0
  144. package/dist/graph/types/graph.types.js +84 -0
  145. package/dist/graph/types/graph.types.js.map +1 -0
  146. package/dist/graph/types/index.d.ts +11 -0
  147. package/dist/graph/types/index.js +35 -0
  148. package/dist/graph/types/index.js.map +1 -0
  149. package/dist/graph/types/node.types.d.ts +193 -0
  150. package/dist/graph/types/node.types.js +49 -0
  151. package/dist/graph/types/node.types.js.map +1 -0
  152. package/dist/graph/types/path.types.d.ts +224 -0
  153. package/dist/graph/types/path.types.js +38 -0
  154. package/dist/graph/types/path.types.js.map +1 -0
  155. package/dist/graph/types/query.types.d.ts +247 -0
  156. package/dist/graph/types/query.types.js +23 -0
  157. package/dist/graph/types/query.types.js.map +1 -0
  158. package/dist/graph/types/relationship.types.d.ts +224 -0
  159. package/dist/graph/types/relationship.types.js +35 -0
  160. package/dist/graph/types/relationship.types.js.map +1 -0
  161. package/dist/graph/types/result.types.d.ts +237 -0
  162. package/dist/graph/types/result.types.js +7 -0
  163. package/dist/graph/types/result.types.js.map +1 -0
  164. package/dist/graph/validators/index.d.ts +81 -0
  165. package/dist/graph/validators/index.js +243 -0
  166. package/dist/graph/validators/index.js.map +1 -0
  167. package/dist/imports/imports.service.d.ts +3 -3
  168. package/dist/imports/imports.service.js +7 -7
  169. package/dist/imports/imports.service.js.map +1 -1
  170. package/dist/imports/imports.types.d.ts +8 -0
  171. package/dist/imports/repos/postmanV21.repo.d.ts +1 -1
  172. package/dist/imports/repos/postmanV21.repo.js +29 -2
  173. package/dist/imports/repos/postmanV21.repo.js.map +1 -1
  174. package/dist/index.d.ts +1244 -150
  175. package/dist/index.js +1309 -209
  176. package/dist/index.js.map +1 -1
  177. package/dist/inputs/inputs.service.js +2 -2
  178. package/dist/inputs/inputs.service.js.map +1 -1
  179. package/dist/inputs/utils/inputs.utils.create.js +1 -1
  180. package/dist/inputs/utils/inputs.utils.create.js.map +1 -1
  181. package/dist/logs/logs.types.d.ts +5 -0
  182. package/dist/logs/logs.types.js +1 -0
  183. package/dist/logs/logs.types.js.map +1 -1
  184. package/dist/parsers/index.d.ts +3 -0
  185. package/dist/parsers/index.js +27 -0
  186. package/dist/parsers/index.js.map +1 -0
  187. package/dist/parsers/pipelines/postman.pipelines.d.ts +15 -0
  188. package/dist/parsers/pipelines/postman.pipelines.js +103 -0
  189. package/dist/parsers/pipelines/postman.pipelines.js.map +1 -0
  190. package/dist/parsers/types/postman.types.d.ts +200 -0
  191. package/dist/parsers/types/postman.types.js +3 -0
  192. package/dist/parsers/types/postman.types.js.map +1 -0
  193. package/dist/parsers/utils/postman.utils.d.ts +12 -0
  194. package/dist/parsers/utils/postman.utils.js +116 -0
  195. package/dist/parsers/utils/postman.utils.js.map +1 -0
  196. package/dist/parsers/validators/postman-auth.validators.d.ts +10 -0
  197. package/dist/parsers/validators/postman-auth.validators.js +127 -0
  198. package/dist/parsers/validators/postman-auth.validators.js.map +1 -0
  199. package/dist/parsers/validators/postman-request.validators.d.ts +13 -0
  200. package/dist/parsers/validators/postman-request.validators.js +139 -0
  201. package/dist/parsers/validators/postman-request.validators.js.map +1 -0
  202. package/dist/parsers/validators/postman-response.validators.d.ts +13 -0
  203. package/dist/parsers/validators/postman-response.validators.js +150 -0
  204. package/dist/parsers/validators/postman-response.validators.js.map +1 -0
  205. package/dist/parsers/validators/postman-variable.validators.d.ts +14 -0
  206. package/dist/parsers/validators/postman-variable.validators.js +163 -0
  207. package/dist/parsers/validators/postman-variable.validators.js.map +1 -0
  208. package/dist/pricing/pricing.repo.d.ts +0 -0
  209. package/dist/pricing/pricing.repo.js +1 -0
  210. package/dist/pricing/pricing.repo.js.map +1 -0
  211. package/dist/pricing/pricing.service.d.ts +24 -0
  212. package/dist/pricing/pricing.service.js +51 -0
  213. package/dist/pricing/pricing.service.js.map +1 -0
  214. package/dist/pricing/pricing.types.d.ts +76 -0
  215. package/dist/pricing/pricing.types.js +21 -0
  216. package/dist/pricing/pricing.types.js.map +1 -0
  217. package/dist/pricing/utils/string.utils.d.ts +1 -0
  218. package/dist/pricing/utils/string.utils.js +9 -0
  219. package/dist/pricing/utils/string.utils.js.map +1 -0
  220. package/dist/processor/repos/sms.repo.d.ts +4 -4
  221. package/dist/processor/repos/sms.repo.js +23 -10
  222. package/dist/processor/repos/sms.repo.js.map +1 -1
  223. package/dist/processor/services/messagebrokers/kafka.service.js +0 -2
  224. package/dist/processor/services/messagebrokers/kafka.service.js.map +1 -1
  225. package/dist/processor/services/messagebrokers/rabbitmq.service.d.ts +9 -1
  226. package/dist/processor/services/messagebrokers/rabbitmq.service.js +40 -11
  227. package/dist/processor/services/messagebrokers/rabbitmq.service.js.map +1 -1
  228. package/dist/processor/services/processor.service.d.ts +38 -10
  229. package/dist/processor/services/processor.service.js +533 -248
  230. package/dist/processor/services/processor.service.js.map +1 -1
  231. package/dist/processor/services/request.service.d.ts +36 -0
  232. package/dist/processor/services/request.service.js +304 -0
  233. package/dist/processor/services/request.service.js.map +1 -0
  234. package/dist/processor/types/request.types.d.ts +14 -0
  235. package/dist/processor/types/request.types.js +3 -0
  236. package/dist/processor/types/request.types.js.map +1 -0
  237. package/dist/processor/utils/processor.utils.d.ts +3 -0
  238. package/dist/processor/utils/processor.utils.js +84 -22
  239. package/dist/processor/utils/processor.utils.js.map +1 -1
  240. package/dist/processor/utils/request.utils.d.ts +20 -0
  241. package/dist/processor/utils/request.utils.js +113 -0
  242. package/dist/processor/utils/request.utils.js.map +1 -0
  243. package/dist/products/services/products.service.d.ts +114 -77
  244. package/dist/products/services/products.service.js +805 -362
  245. package/dist/products/services/products.service.js.map +1 -1
  246. package/dist/products/services/utils/crypt.utils.d.ts +1 -0
  247. package/dist/products/services/utils/crypt.utils.js +17 -0
  248. package/dist/products/services/utils/crypt.utils.js.map +1 -0
  249. package/dist/products/services/utils/functions.utils.d.ts +13 -0
  250. package/dist/products/services/utils/functions.utils.js +289 -0
  251. package/dist/products/services/utils/functions.utils.js.map +1 -0
  252. package/dist/products/services/utils/objects.utils.d.ts +13 -0
  253. package/dist/products/services/utils/objects.utils.js +89 -0
  254. package/dist/products/services/utils/objects.utils.js.map +1 -0
  255. package/dist/products/services/utils/string.utils.d.ts +12 -0
  256. package/dist/products/services/utils/string.utils.js +168 -0
  257. package/dist/products/services/utils/string.utils.js.map +1 -0
  258. package/dist/products/utils/string.utils.d.ts +1 -1
  259. package/dist/products/utils/string.utils.js +14 -2
  260. package/dist/products/utils/string.utils.js.map +1 -1
  261. package/dist/products/validators/index.d.ts +4 -1
  262. package/dist/products/validators/index.js +7 -1
  263. package/dist/products/validators/index.js.map +1 -1
  264. package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.d.ts +15 -4
  265. package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js +501 -109
  266. package/dist/products/validators/joi-validators/create.productDatabaseAction.validator.js.map +1 -1
  267. package/dist/products/validators/joi-validators/create.productEnv.validator.js +1 -0
  268. package/dist/products/validators/joi-validators/create.productEnv.validator.js.map +1 -1
  269. package/dist/products/validators/joi-validators/create.productGraph.validator.d.ts +3 -0
  270. package/dist/products/validators/joi-validators/create.productGraph.validator.js +82 -0
  271. package/dist/products/validators/joi-validators/create.productGraph.validator.js.map +1 -0
  272. package/dist/products/validators/joi-validators/create.productGraphAction.validator.d.ts +14 -0
  273. package/dist/products/validators/joi-validators/create.productGraphAction.validator.js +696 -0
  274. package/dist/products/validators/joi-validators/create.productGraphAction.validator.js.map +1 -0
  275. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.d.ts +4 -0
  276. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js +58 -0
  277. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js.map +1 -0
  278. package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js +1 -0
  279. package/dist/products/validators/joi-validators/create.productMessageBrokerTopic.validator.js.map +1 -1
  280. package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js +9 -4
  281. package/dist/products/validators/joi-validators/create.productMessageBrokers.validator.js.map +1 -1
  282. package/dist/products/validators/joi-validators/create.productNotification.validator.js +5 -2
  283. package/dist/products/validators/joi-validators/create.productNotification.validator.js.map +1 -1
  284. package/dist/products/validators/joi-validators/create.userAuth.validator.js +1 -0
  285. package/dist/products/validators/joi-validators/create.userAuth.validator.js.map +1 -1
  286. package/dist/products/validators/joi-validators/update.dataValue.validator.js +1 -0
  287. package/dist/products/validators/joi-validators/update.dataValue.validator.js.map +1 -1
  288. package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.d.ts +6 -0
  289. package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.js +28 -26
  290. package/dist/products/validators/joi-validators/update.productDatabaseAction.validator.js.map +1 -1
  291. package/dist/products/validators/joi-validators/update.productEnv.validator.js +3 -0
  292. package/dist/products/validators/joi-validators/update.productEnv.validator.js.map +1 -1
  293. package/dist/products/validators/joi-validators/update.productGraph.validator.d.ts +3 -0
  294. package/dist/products/validators/joi-validators/update.productGraph.validator.js +87 -0
  295. package/dist/products/validators/joi-validators/update.productGraph.validator.js.map +1 -0
  296. package/dist/products/validators/joi-validators/update.productGraphAction.validator.d.ts +7 -0
  297. package/dist/products/validators/joi-validators/update.productGraphAction.validator.js +72 -0
  298. package/dist/products/validators/joi-validators/update.productGraphAction.validator.js.map +1 -0
  299. package/dist/products/validators/joi-validators/update.productMessageBrokerTopic.validator.js +1 -0
  300. package/dist/products/validators/joi-validators/update.productMessageBrokerTopic.validator.js.map +1 -1
  301. package/dist/products/validators/joi-validators/update.userAuth.validator.js +1 -0
  302. package/dist/products/validators/joi-validators/update.userAuth.validator.js.map +1 -1
  303. package/dist/test/test.health.d.ts +1 -0
  304. package/dist/test/test.health.js +49 -0
  305. package/dist/test/test.health.js.map +1 -0
  306. package/dist/test/test.import.js +51 -4
  307. package/dist/test/test.import.js.map +1 -1
  308. package/dist/test/test.imports.js +22 -7
  309. package/dist/test/test.imports.js.map +1 -1
  310. package/dist/test/test.notifiers.d.ts +1 -0
  311. package/dist/test/test.notifiers.js +85 -0
  312. package/dist/test/test.notifiers.js.map +1 -0
  313. package/dist/test/test.processor.js +30 -115
  314. package/dist/test/test.processor.js.map +1 -1
  315. package/dist/test/test.products.d.ts +1 -0
  316. package/dist/test/test.products.js +49 -0
  317. package/dist/test/test.products.js.map +1 -0
  318. package/dist/tsconfig.tsbuildinfo +1 -0
  319. package/dist/types/appBuilder.types.d.ts +5 -12
  320. package/dist/types/enums.d.ts +4 -1
  321. package/dist/types/enums.js +3 -0
  322. package/dist/types/enums.js.map +1 -1
  323. package/dist/types/index.types.d.ts +4 -0
  324. package/dist/types/pricing.types.d.ts +4 -0
  325. package/dist/types/pricing.types.js +3 -0
  326. package/dist/types/pricing.types.js.map +1 -0
  327. package/dist/types/processor.types.d.ts +67 -11
  328. package/dist/types/processor.types.js.map +1 -1
  329. package/dist/types/productsBuilder.types.d.ts +132 -14
  330. package/dist/types/productsBuilder.types.js +69 -4
  331. package/dist/types/productsBuilder.types.js.map +1 -1
  332. package/dist/types/request-tracker.interface.d.ts +0 -0
  333. package/dist/types/request-tracker.interface.js +1 -0
  334. package/dist/types/request-tracker.interface.js.map +1 -0
  335. package/dist/utils/constants.d.ts +1 -0
  336. package/dist/utils/constants.js +5 -0
  337. package/dist/utils/constants.js.map +1 -0
  338. package/package.json +17 -3
package/dist/index.js CHANGED
@@ -43,39 +43,67 @@ const app_service_1 = __importDefault(require("./apps/services/app.service"));
43
43
  const filePath = __importStar(require("path"));
44
44
  const products_service_1 = __importDefault(require("./products/services/products.service"));
45
45
  const fs_1 = require("fs");
46
+ const database_service_1 = require("./database/database.service");
47
+ const graph_service_1 = require("./graph/graph.service");
46
48
  const index_types_1 = require("./types/index.types");
49
+ const enums_1 = require("./types/enums");
47
50
  const productsApi_service_1 = require("./api/services/productsApi.service");
51
+ const workspaceSecretsApi_service_1 = require("./api/services/workspaceSecretsApi.service");
48
52
  const imports_service_1 = __importDefault(require("./imports/imports.service"));
49
53
  const processor_service_1 = __importDefault(require("./processor/services/processor.service"));
50
54
  const logs_service_1 = __importDefault(require("./logs/logs.service"));
51
55
  const utils_1 = require("./utils");
52
56
  const mime = __importStar(require("mime-types"));
57
+ const processor_utils_1 = require("./processor/utils/processor.utils");
53
58
  class Ductape {
54
59
  async loadRedis() {
55
60
  if (typeof window !== 'undefined') {
56
61
  throw new Error("RedisService can only be used in a server environment.");
57
62
  }
58
- const redis = await Promise.resolve().then(() => __importStar(require('redis')));
59
- return redis;
63
+ return await Promise.resolve().then(() => __importStar(require('ioredis')));
60
64
  }
61
65
  constructor({ workspace_id, private_key, user_id, env_type, redis_url }) {
66
+ /**
67
+ * Product-related operations for managing products, sessions, apps, quotas, and fallbacks.
68
+ */
62
69
  this.product = {
70
+ /**
71
+ * Creates a new product.
72
+ * @param {IProduct} data - The product data.
73
+ * @returns {Promise<void>} Resolves when the product is created. Throws on error.
74
+ */
63
75
  create: async (data) => {
64
76
  await this.initProduct();
65
77
  return this.productBuilder.createProduct(data);
66
78
  },
79
+ /**
80
+ * Fetches a product by tag.
81
+ * @param {string} tag - The product tag.
82
+ * @returns {Promise<IProduct|null>} The fetched product, or null if not found.
83
+ */
67
84
  fetch: async (tag) => {
68
85
  await this.initProduct();
69
86
  await this.productBuilder.initializeProductByTag(tag);
70
87
  this.productInit = false;
71
88
  return this.productBuilder.fetchProduct();
72
89
  },
90
+ /**
91
+ * Updates a product by tag.
92
+ * @param {string} tag - The product tag.
93
+ * @param {Partial<IProduct>} data - The product data to update.
94
+ * @returns {Promise<void>} Resolves when the product is updated. Throws on error.
95
+ */
73
96
  update: async (tag, data) => {
74
97
  await this.initProduct();
75
98
  await this.productBuilder.initializeProductByTag(tag);
76
99
  this.productInit = false;
77
100
  return this.productBuilder.updateProduct(data);
78
101
  },
102
+ /**
103
+ * Initializes a product by tag.
104
+ * @param {string} productTag - The product tag.
105
+ * @returns {Promise<void>} Resolves when initialization is complete. Throws on error.
106
+ */
79
107
  init: async (productTag) => {
80
108
  try {
81
109
  console.log(`Product initialized with tag: ${productTag}`);
@@ -89,185 +117,399 @@ class Ductape {
89
117
  }
90
118
  },
91
119
  sessions: {
92
- create: (payload) => {
120
+ /**
121
+ * Creates a new product session.
122
+ * @param {IProductSession} payload - The session payload.
123
+ * @returns {Promise<void>} Resolves when the session is created. Throws on error.
124
+ */
125
+ create: async (payload) => {
93
126
  this.checkProductInit();
94
127
  return this.productBuilder.createSession(payload);
95
128
  },
96
- update: (tag, payload) => {
129
+ /**
130
+ * Updates a product session by tag.
131
+ * @param {string} tag - The session tag.
132
+ * @param {Partial<IProductSession>} payload - The session data to update.
133
+ * @returns {Promise<void>} Resolves when the session is updated. Throws on error.
134
+ */
135
+ update: async (tag, payload) => {
97
136
  this.checkProductInit();
98
137
  return this.productBuilder.updateSession(tag, payload);
99
138
  },
100
- fetchAll: () => {
139
+ /**
140
+ * Fetches all product sessions.
141
+ * @returns {IProductSession[]} The list of sessions.
142
+ */
143
+ fetchAll: async () => {
101
144
  this.checkProductInit();
102
145
  return this.productBuilder.fetchSessions();
103
146
  },
104
- fetch: (tag) => {
147
+ /**
148
+ * Fetches a product session by tag.
149
+ * @param {string} tag - The session tag.
150
+ * @returns {IProductSession|null} The fetched session, or null if not found.
151
+ */
152
+ fetch: async (tag) => {
105
153
  this.checkProductInit();
106
154
  return this.productBuilder.fetchSession(tag);
155
+ },
156
+ /**
157
+ * Fetches users for a session.
158
+ * @param {IFetchUsersPayload} data - The user fetch payload.
159
+ * @returns {Promise<any[]>} The users for the session.
160
+ */
161
+ users: (data) => {
162
+ this.checkProductInit();
163
+ return this.productBuilder.fetchSessionUsers(data);
107
164
  }
108
165
  },
109
166
  apps: {
167
+ /**
168
+ * Connects an app to a product by app tag.
169
+ * @param {string} appTag - The app tag.
170
+ * @returns {Promise<IAppAccess>} The result of the connection.
171
+ */
110
172
  connect: async (appTag) => {
111
173
  this.checkProductInit();
112
174
  return this.productBuilder.createAppAccessTag(appTag);
113
175
  },
176
+ /**
177
+ * Adds an app to a product.
178
+ * @param {IProductApp} app - The app data.
179
+ * @returns {Promise<void>} Resolves when the app is added. Throws on error.
180
+ */
114
181
  add: async (app) => {
115
182
  this.checkProductInit();
116
183
  return this.productBuilder.addApp(app);
117
184
  },
185
+ /**
186
+ * Fetches all apps for a product.
187
+ * @returns {IProductApp[]} The list of apps.
188
+ */
118
189
  fetchAll: async () => {
119
190
  this.checkProductInit();
120
191
  return this.productBuilder.fetchApps();
121
192
  },
193
+ /**
194
+ * Fetches an app by tag.
195
+ * @param {string} tag - The app tag.
196
+ * @returns {IProductApp|null} The fetched app, or null if not found.
197
+ */
122
198
  fetch: async (tag) => {
123
199
  this.checkProductInit();
124
200
  return this.productBuilder.fetchApp(tag);
125
201
  },
202
+ /**
203
+ * Updates an app by access tag.
204
+ * @param {string} accessTag - The app access tag.
205
+ * @param {Partial<IProductApp>} data - The app data to update.
206
+ * @returns {Promise<void>} Resolves when the app is updated. Throws on error.
207
+ */
126
208
  update: async (accessTag, data) => {
127
209
  this.checkProductInit();
128
210
  return this.productBuilder.updateApp(accessTag, data);
129
211
  },
130
212
  webhooks: {
213
+ /**
214
+ * Fetches all webhooks for an app by access tag.
215
+ * @param {string} accessTag - The app access tag.
216
+ * @returns {Promise<IAppWebhook[]>} The list of webhooks.
217
+ */
131
218
  fetchAll: async (accessTag) => {
132
219
  this.checkProductInit();
133
220
  return this.productBuilder.fetchAppWebhooks(accessTag);
134
221
  },
135
- enable: async (data) => {
136
- const processorService = await this.createNewProcessor();
137
- return processorService.registerWebhook(data);
138
- },
222
+ /**
223
+ * Generates a webhook link for an app.
224
+ * @param {IGenerateWebhookLink} data - The webhook link data.
225
+ * @returns {Promise<string>} The generated webhook link.
226
+ */
139
227
  generateLink: async (data) => {
140
228
  const processorService = await this.createNewProcessor();
141
229
  return processorService.generateWebhookLink(data);
142
230
  },
143
231
  },
232
+ health: {
233
+ /**
234
+ * Creates a health check for an app.
235
+ * @param {Partial<IProductAppHealth>} data - The health check data.
236
+ * @returns {Promise<void>} Resolves when the health check is created. Throws on error.
237
+ */
238
+ create: async (data) => {
239
+ await this.checkProductInit();
240
+ return await this.productBuilder.createHealthcheck(data);
241
+ },
242
+ /**
243
+ * Updates a health check by tag.
244
+ * @param {string} tag - The health check tag.
245
+ * @param {Partial<IProductAppHealth>} data - The health check data to update.
246
+ * @returns {Promise<void>} Resolves when the health check is updated. Throws on error.
247
+ */
248
+ update: async (tag, data) => {
249
+ this.checkProductInit();
250
+ return this.productBuilder.updateHealthcheck(tag, data);
251
+ },
252
+ /**
253
+ * Fetches a health check by access tag and tag.
254
+ * @param {string} access_tag - The app access tag.
255
+ * @param {string} tag - The health check tag.
256
+ * @returns {Promise<IProductAppHealth|null>} The fetched health check, or null if not found.
257
+ */
258
+ fetch: async (access_tag, tag) => {
259
+ this.checkProductInit();
260
+ return this.productBuilder.fetchHealthcheck(access_tag, tag);
261
+ },
262
+ /**
263
+ * Fetches all health checks for an app by access tag.
264
+ * @param {string} access_tag - The app access tag.
265
+ * @returns {Promise<IProductAppHealth[]>} The list of health checks.
266
+ */
267
+ fetchAll: async (access_tag) => {
268
+ this.checkProductInit();
269
+ return this.productBuilder.fetchHealthchecks(access_tag);
270
+ },
271
+ }
144
272
  },
273
+ /**
274
+ * Creates a quota for a product.
275
+ * @param {Partial<IProductQuota>} data - The quota data.
276
+ * @returns {Promise<void>} Resolves when the quota is created. Throws on error.
277
+ */
145
278
  quota: {
146
279
  create: async (data) => {
147
280
  await this.initProduct();
148
281
  return this.productBuilder.createQuota(data);
149
282
  },
150
- fetch: (tag) => {
283
+ /**
284
+ * Fetches a quota by tag.
285
+ * @param {string} tag - The quota tag.
286
+ * @returns {IProductQuota|null} The fetched quota, or null if not found.
287
+ */
288
+ fetch: async (tag) => {
151
289
  return this.productBuilder.fetchQuota(tag);
152
290
  },
153
- fetchAll: () => {
291
+ /**
292
+ * Fetches all quotas for a product.
293
+ * @returns {IProductQuota[]} The list of quotas.
294
+ */
295
+ fetchAll: async () => {
154
296
  return this.productBuilder.fetchQuotas();
155
297
  },
298
+ /**
299
+ * Updates a quota by tag.
300
+ * @param {string} tag - The quota tag.
301
+ * @param {Partial<IProductQuota>} data - The quota data to update.
302
+ * @returns {Promise<void>} Resolves when the quota is updated. Throws on error.
303
+ */
156
304
  update: async (tag, data) => {
157
305
  await this.initProduct();
158
306
  return this.productBuilder.updateQuota(tag, data);
159
307
  },
160
308
  },
309
+ /**
310
+ * Creates a fallback for a product.
311
+ * @param {Partial<IProductFallback>} data - The fallback data.
312
+ * @returns {Promise<void>} Resolves when the fallback is created. Throws on error.
313
+ */
161
314
  fallback: {
162
315
  create: async (data) => {
163
316
  this.checkProductInit();
164
317
  return this.productBuilder.createFallback(data);
165
318
  },
166
- fetch: (tag) => {
319
+ /**
320
+ * Fetches a fallback by tag.
321
+ * @param {string} tag - The fallback tag.
322
+ * @returns {IProductFallback|null} The fetched fallback, or null if not found.
323
+ */
324
+ fetch: async (tag) => {
167
325
  this.checkProductInit();
168
326
  return this.productBuilder.fetchFallback(tag);
169
327
  },
170
- fetchAll: () => {
328
+ /**
329
+ * Fetches all fallbacks for a product.
330
+ * @returns {IProductFallback[]} The list of fallbacks.
331
+ */
332
+ fetchAll: async () => {
171
333
  this.checkProductInit();
172
334
  return this.productBuilder.fetchFallbacks();
173
335
  },
336
+ /**
337
+ * Updates a fallback by tag.
338
+ * @param {string} tag - The fallback tag.
339
+ * @param {Partial<IProductFallback>} data - The fallback data to update.
340
+ * @returns {Promise<void>} Resolves when the fallback is updated. Throws on error.
341
+ */
174
342
  update: async (tag, data) => {
175
343
  this.checkProductInit();
176
344
  return this.productBuilder.updateFallback(tag, data);
177
345
  },
178
346
  },
347
+ /**
348
+ * Updates data validation for a product.
349
+ * @param {string} tag - The product tag.
350
+ * @param {Partial<IParsedSample>} update - The update data.
351
+ * @returns {Promise<void>} Resolves when the validation is updated. Throws on error.
352
+ */
179
353
  updateValidation: async (tag, update) => {
180
354
  this.checkProductInit();
181
355
  return this.productBuilder.updateDataValidation(tag, update);
182
356
  },
183
357
  environments: {
358
+ /**
359
+ * Creates an environment for a product.
360
+ * @param {IProductEnv} data - The environment data.
361
+ * @returns {Promise<void>} Resolves when the environment is created. Throws on error.
362
+ */
184
363
  create: async (data) => {
185
364
  this.checkProductInit();
186
365
  return this.productBuilder.createEnv(data);
187
366
  },
188
- fetchAll: () => {
367
+ /**
368
+ * Fetches all environments for a product.
369
+ * @returns {IAppEnv[]} The list of environments.
370
+ */
371
+ fetchAll: async () => {
189
372
  this.checkProductInit();
190
373
  return this.productBuilder.fetchEnvs();
191
374
  },
192
- fetch: (slug) => {
375
+ /**
376
+ * Fetches an environment by slug.
377
+ * @param {string} slug - The environment slug.
378
+ * @returns {IAppEnv|null} The fetched environment, or null if not found.
379
+ */
380
+ fetch: async (slug) => {
193
381
  this.checkProductInit();
194
382
  return this.productBuilder.fetchEnv(slug);
195
383
  },
384
+ /**
385
+ * Updates an environment by slug.
386
+ * @param {string} slug - The environment slug.
387
+ * @param {Partial<IProductEnv>} data - The environment data to update.
388
+ * @returns {Promise<void>} Resolves when the environment is updated. Throws on error.
389
+ */
196
390
  update: async (slug, data) => {
197
391
  this.checkProductInit();
198
392
  return this.productBuilder.updateEnv(slug, data);
199
393
  },
200
394
  },
201
395
  storage: {
396
+ /**
397
+ * Creates a storage for a product.
398
+ * @param {IProductStorage} data - The storage data.
399
+ * @returns {Promise<void>} Resolves when the storage is created. Throws on error.
400
+ */
202
401
  create: async (data) => {
203
402
  this.checkProductInit();
204
403
  return this.productBuilder.createStorage(data);
205
404
  },
206
- fetchAll: () => {
405
+ /**
406
+ * Fetches all storages for a product.
407
+ * @returns {IProductStorage[]} The list of storages.
408
+ */
409
+ fetchAll: async () => {
207
410
  this.checkProductInit();
208
411
  return this.productBuilder.fetchStorages();
209
412
  },
210
- fetch: (tag) => {
413
+ /**
414
+ * Fetches a storage by tag.
415
+ * @param {string} tag - The storage tag.
416
+ * @returns {IProductStorage|null} The fetched storage, or null if not found.
417
+ */
418
+ fetch: async (tag) => {
211
419
  this.checkProductInit();
212
420
  return this.productBuilder.fetchStorage(tag);
213
421
  },
422
+ /**
423
+ * Updates a storage by tag.
424
+ * @param {string} tag - The storage tag.
425
+ * @param {Partial<IProductStorage>} data - The storage data to update.
426
+ * @returns {Promise<void>} Resolves when the storage is updated. Throws on error.
427
+ */
214
428
  update: async (tag, data) => {
215
429
  this.checkProductInit();
216
430
  return this.productBuilder.updateStorage(tag, data);
217
431
  },
432
+ /**
433
+ * Fetches storage files for a product.
434
+ * @param {IFetchFilesPayload} data - The fetch files payload.
435
+ * @returns {Promise<void>} Resolves when the storage files are fetched. Throws on error.
436
+ */
218
437
  files: async (data) => {
219
438
  this.checkProductInit();
220
439
  return this.productBuilder.fetchStorageFiles(data);
221
440
  }
222
441
  },
223
- /*cloudFunctions: {
224
- create: async (data: IProductFunction) => {
225
- this.checkProductInit();
226
- return this.productBuilder.createFunction(data);
227
- },
228
- fetchAll: () => {
229
- this.checkProductInit();
230
- return this.productBuilder.fetchFunctions();
231
- },
232
- fetch: (tag: string) => {
233
- this.checkProductInit();
234
- return this.productBuilder.fetchFunction(tag);
235
- },
236
- update: async (tag: string, data: Partial<IProductFunction>) => {
237
- this.checkProductInit();
238
- return this.productBuilder.updateFunction(tag, data);
239
- },
240
- },*/
241
442
  messageBrokers: {
443
+ /**
444
+ * Creates a message broker for a product.
445
+ * @param {Partial<IProductMessageBroker>} data - The message broker data.
446
+ * @returns {Promise<void>} Resolves when the message broker is created. Throws on error.
447
+ */
242
448
  create: async (data) => {
243
449
  this.checkProductInit();
244
450
  return this.productBuilder.createMessageBroker(data);
245
451
  },
246
- fetchAll: () => {
452
+ /**
453
+ * Fetches all message brokers for a product.
454
+ * @returns {IProductMessageBroker[]} The list of message brokers.
455
+ */
456
+ fetchAll: async () => {
247
457
  this.checkProductInit();
248
458
  return this.productBuilder.fetchMessageBrokers();
249
459
  },
250
- fetch: (tag) => {
460
+ /**
461
+ * Fetches a message broker by tag.
462
+ * @param {string} tag - The message broker tag.
463
+ * @returns {IProductMessageBroker|null} The fetched message broker, or null if not found.
464
+ */
465
+ fetch: async (tag) => {
251
466
  this.checkProductInit();
252
467
  return this.productBuilder.fetchMessageBroker(tag);
253
468
  },
469
+ /**
470
+ * Updates a message broker by tag.
471
+ * @param {string} tag - The message broker tag.
472
+ * @param {Partial<IProductMessageBroker>} data - The message broker data to update.
473
+ * @returns {Promise<void>} Resolves when the message broker is updated. Throws on error.
474
+ */
254
475
  update: async (tag, data) => {
255
476
  this.checkProductInit();
256
477
  return this.productBuilder.updateMessageBroker(tag, data);
257
478
  },
258
479
  topics: {
480
+ /**
481
+ * Creates a message broker topic for a product.
482
+ * @param {IProductMessageBrokerTopic} data - The message broker topic data.
483
+ * @returns {Promise<void>} Resolves when the message broker topic is created. Throws on error.
484
+ */
259
485
  create: async (data) => {
260
486
  this.checkProductInit();
261
487
  return this.productBuilder.createMessageBrokerTopic(data);
262
488
  },
263
- fetchAll: (messageBrokerTag) => {
489
+ /**
490
+ * Fetches all message broker topics for a message broker by tag.
491
+ * @param {string} messageBrokerTag - The message broker tag.
492
+ * @returns {IProductMessageBrokerTopic[]} The list of message broker topics.
493
+ */
494
+ fetchAll: async (messageBrokerTag) => {
264
495
  this.checkProductInit();
265
496
  return this.productBuilder.fetchMessageBrokerTopics(messageBrokerTag);
266
497
  },
267
- fetch: (tag) => {
498
+ /**
499
+ * Fetches a message broker topic by tag.
500
+ * @param {string} tag - The message broker topic tag.
501
+ * @returns {IProductMessageBrokerTopic|null} The fetched message broker topic, or null if not found.
502
+ */
503
+ fetch: async (tag) => {
268
504
  this.checkProductInit();
269
505
  return this.productBuilder.fetchMessageBrokerTopic(tag);
270
506
  },
507
+ /**
508
+ * Updates a message broker topic by tag.
509
+ * @param {string} tag - The message broker topic tag.
510
+ * @param {Partial<IProductMessageBrokerTopic>} data - The message broker topic data to update.
511
+ * @returns {Promise<void>} Resolves when the message broker topic is updated. Throws on error.
512
+ */
271
513
  update: (tag, data) => {
272
514
  this.checkProductInit();
273
515
  return this.productBuilder.updateMessageBrokerTopic(Object.assign(Object.assign({}, data), { tag }));
@@ -275,35 +517,76 @@ class Ductape {
275
517
  },
276
518
  },
277
519
  notifications: {
520
+ /**
521
+ * Creates a notification for a product.
522
+ * @param {IProductNotification} data - The notification data.
523
+ * @returns {Promise<void>} Resolves when the notification is created. Throws on error.
524
+ */
278
525
  create: async (data) => {
279
526
  this.checkProductInit();
280
527
  return this.productBuilder.createNotification(data);
281
528
  },
282
- fetchAll: () => {
529
+ /**
530
+ * Fetches all notifications for a product.
531
+ * @returns {IProductNotification[]} The list of notifications.
532
+ */
533
+ fetchAll: async () => {
283
534
  this.checkProductInit();
284
535
  return this.productBuilder.fetchNotifications();
285
536
  },
286
- fetch: (tag) => {
537
+ /**
538
+ * Fetches a notification by tag.
539
+ * @param {string} tag - The notification tag.
540
+ * @returns {IProductNotification|null} The fetched notification, or null if not found.
541
+ */
542
+ fetch: async (tag) => {
287
543
  this.checkProductInit();
288
544
  return this.productBuilder.fetchNotification(tag);
289
545
  },
546
+ /**
547
+ * Updates a notification by tag.
548
+ * @param {string} tag - The notification tag.
549
+ * @param {Partial<IProductNotification>} data - The notification data to update.
550
+ * @returns {Promise<void>} Resolves when the notification is updated. Throws on error.
551
+ */
290
552
  update: async (tag, data) => {
291
553
  this.checkProductInit();
292
554
  return this.productBuilder.updateNotification(tag, data);
293
555
  },
294
556
  messages: {
557
+ /**
558
+ * Creates a notification message for a product.
559
+ * @param {IProductNotificationTemplate} data - The notification message data.
560
+ * @returns {Promise<void>} Resolves when the notification message is created. Throws on error.
561
+ */
295
562
  create: async (data) => {
296
563
  this.checkProductInit();
297
564
  return this.productBuilder.createNotificationMessage(data);
298
565
  },
299
- fetchAll: (notificationTag) => {
566
+ /**
567
+ * Fetches all notification messages for a notification by tag.
568
+ * @param {string} notificationTag - The notification tag.
569
+ * @returns {IProductNotificationTemplate[]} The list of notification messages.
570
+ */
571
+ fetchAll: async (notificationTag) => {
300
572
  this.checkProductInit();
301
573
  return this.productBuilder.fetchNotificationMessages(notificationTag);
302
574
  },
303
- fetch: (tag) => {
575
+ /**
576
+ * Fetches a notification message by tag.
577
+ * @param {string} tag - The notification message tag.
578
+ * @returns {IProductNotificationTemplate|null} The fetched notification message, or null if not found.
579
+ */
580
+ fetch: async (tag) => {
304
581
  this.checkProductInit();
305
582
  return this.productBuilder.fetchNotificationMessage(tag);
306
583
  },
584
+ /**
585
+ * Updates a notification message by tag.
586
+ * @param {string} tag - The notification message tag.
587
+ * @param {Partial<IProductNotificationTemplate>} data - The notification message data to update.
588
+ * @returns {Promise<void>} Resolves when the notification message is updated. Throws on error.
589
+ */
307
590
  update: async (tag, data) => {
308
591
  this.checkProductInit();
309
592
  return this.productBuilder.updateNotificationMessage(Object.assign(Object.assign({}, data), { tag }));
@@ -311,90 +594,230 @@ class Ductape {
311
594
  },
312
595
  },
313
596
  databases: {
597
+ /**
598
+ * Creates a database for a product.
599
+ * @param {IProductDatabase} data - The database data.
600
+ * @returns {Promise<void>} Resolves when the database is created. Throws on error.
601
+ */
314
602
  create: async (data) => {
315
603
  this.checkProductInit();
316
604
  return this.productBuilder.createDatabase(data);
317
605
  },
318
- fetchAll: () => {
606
+ /**
607
+ * Fetches all databases for a product.
608
+ * @returns {IProductDatabase[]} The list of databases.
609
+ */
610
+ fetchAll: async () => {
319
611
  this.checkProductInit();
320
612
  return this.productBuilder.fetchDatabases();
321
613
  },
322
- fetch: (tag) => {
614
+ /**
615
+ * Fetches a database by tag.
616
+ * @param {string} tag - The database tag.
617
+ * @returns {IProductDatabase|null} The fetched database, or null if not found.
618
+ */
619
+ fetch: async (tag) => {
323
620
  this.checkProductInit();
324
621
  return this.productBuilder.fetchDatabase(tag);
325
622
  },
623
+ /**
624
+ * Updates a database by tag.
625
+ * @param {string} tag - The database tag.
626
+ * @param {Partial<IProductDatabase>} data - The database data to update.
627
+ * @returns {Promise<void>} Resolves when the database is updated. Throws on error.
628
+ */
326
629
  update: async (tag, data) => {
327
630
  this.checkProductInit();
328
631
  return this.productBuilder.updateDatabase(tag, data);
329
632
  },
330
633
  actions: {
634
+ /**
635
+ * Creates a database action for a product.
636
+ * @param {IProductDatabaseAction} data - The database action data.
637
+ * @returns {Promise<void>} Resolves when the database action is created. Throws on error.
638
+ */
331
639
  create: async (data) => {
332
640
  this.checkProductInit();
333
641
  return this.productBuilder.createDatabaseAction(data);
334
642
  },
335
- fetchAll: (databaseTag) => {
643
+ /**
644
+ * Fetches all database actions for a product.
645
+ * @param {string} databaseTag - The database tag.
646
+ * @returns {IProductDatabaseAction[]} The list of database actions.
647
+ */
648
+ fetchAll: async (databaseTag) => {
336
649
  this.checkProductInit();
337
650
  return this.productBuilder.fetchDatabaseActions(databaseTag);
338
651
  },
339
- fetch: (tag) => {
652
+ /**
653
+ * Fetches a database action by tag.
654
+ * @param {string} tag - The database action tag.
655
+ * @returns {IProductDatabaseAction|null} The fetched database action, or null if not found.
656
+ */
657
+ fetch: async (tag) => {
340
658
  this.checkProductInit();
341
659
  return this.productBuilder.fetchDatabaseAction(tag);
342
660
  },
661
+ /**
662
+ * Updates a database action by tag.
663
+ * @param {string} tag - The database action tag.
664
+ * @param {Partial<IProductDatabaseAction>} data - The database action data to update.
665
+ * @returns {Promise<void>} Resolves when the database action is updated. Throws on error.
666
+ */
343
667
  update: async (tag, data) => {
344
668
  this.checkProductInit();
345
669
  return this.productBuilder.updateDatabaseAction(Object.assign(Object.assign({}, data), { tag }));
346
670
  },
347
671
  },
348
672
  migrations: {
673
+ /**
674
+ * Creates a database migration for a product.
675
+ * @param {IProductDatabaseMigration} data - The database migration data.
676
+ * @returns {void} Resolves when the database migration is created. Throws on error.
677
+ */
349
678
  create: (data) => {
350
679
  this.checkProductInit();
351
680
  return this.productBuilder.createDatabaseMigration(data);
352
681
  },
353
- fetchAll: (databaseTag) => {
682
+ /**
683
+ * Fetches all database migrations for a product.
684
+ * @param {string} databaseTag - The database tag.
685
+ * @returns {IProductDatabaseMigration[]} The list of database migrations.
686
+ */
687
+ fetchAll: async (databaseTag) => {
354
688
  this.checkProductInit();
355
689
  return this.productBuilder.fetchDatabaseMigrations(databaseTag);
356
690
  },
357
- fetch: (tag) => {
691
+ /**
692
+ * Fetches a database migration by tag.
693
+ * @param {string} tag - The database migration tag.
694
+ * @returns {IProductDatabaseMigration|null} The fetched database migration, or null if not found.
695
+ */
696
+ fetch: async (tag) => {
358
697
  this.checkProductInit();
359
698
  return this.productBuilder.fetchDatabaseMigration(tag);
360
699
  },
700
+ /**
701
+ * Updates a database migration by tag.
702
+ * @param {string} tag - The database migration tag.
703
+ * @param {Partial<IProductDatabaseMigration>} data - The database migration data to update.
704
+ * @returns {void} Resolves when the database migration is updated. Throws on error.
705
+ */
361
706
  update: (tag, data) => {
362
707
  this.checkProductInit();
363
708
  return this.productBuilder.updateDatabaseMigration(Object.assign(Object.assign({}, data), { tag }));
364
709
  },
365
710
  },
366
711
  },
712
+ graphs: {
713
+ /**
714
+ * Creates a graph database for a product.
715
+ * @param {IProductGraph} data - The graph database data.
716
+ * @returns {Promise<void>} Resolves when the graph database is created. Throws on error.
717
+ */
718
+ create: async (data) => {
719
+ this.checkProductInit();
720
+ return this.productBuilder.createGraph(data);
721
+ },
722
+ /**
723
+ * Fetches all graph databases for a product.
724
+ * @returns {IProductGraph[]} The list of graph databases.
725
+ */
726
+ fetchAll: async () => {
727
+ this.checkProductInit();
728
+ return this.productBuilder.fetchGraphs();
729
+ },
730
+ /**
731
+ * Fetches a graph database by tag.
732
+ * @param {string} tag - The graph database tag.
733
+ * @returns {IProductGraph|null} The fetched graph database, or null if not found.
734
+ */
735
+ fetch: async (tag) => {
736
+ this.checkProductInit();
737
+ return this.productBuilder.fetchGraph(tag);
738
+ },
739
+ /**
740
+ * Updates a graph database by tag.
741
+ * @param {string} tag - The graph database tag.
742
+ * @param {Partial<IProductGraph>} data - The graph database data to update.
743
+ * @returns {Promise<void>} Resolves when the graph database is updated. Throws on error.
744
+ */
745
+ update: async (tag, data) => {
746
+ this.checkProductInit();
747
+ return this.productBuilder.updateGraph(tag, data);
748
+ },
749
+ },
367
750
  jobs: {
751
+ /**
752
+ * Creates a job for a product.
753
+ * @param {Partial<IProductJobs>} data - The job data.
754
+ * @returns {Promise<void>} Resolves when the job is created. Throws on error.
755
+ */
368
756
  create: async (data) => {
369
757
  this.checkProductInit();
370
758
  return this.productBuilder.createJob(data);
371
759
  },
372
- fetchAll: () => {
760
+ /**
761
+ * Fetches all jobs for a product.
762
+ * @returns {IProductJobs[]} The list of jobs.
763
+ */
764
+ fetchAll: async () => {
373
765
  this.checkProductInit();
374
766
  return this.productBuilder.fetchJobs();
375
767
  },
376
- fetch: (tag) => {
768
+ /**
769
+ * Fetches a job by tag.
770
+ * @param {string} tag - The job tag.
771
+ * @returns {IProductJobs|null} The fetched job, or null if not found.
772
+ */
773
+ fetch: async (tag) => {
377
774
  this.checkProductInit();
378
775
  return this.productBuilder.fetchJob(tag);
379
776
  },
777
+ /**
778
+ * Updates a job by tag.
779
+ * @param {string} tag - The job tag.
780
+ * @param {Partial<IProductJobs>} data - The job data to update.
781
+ * @returns {Promise<void>} Resolves when the job is updated. Throws on error.
782
+ */
380
783
  update: async (tag, data) => {
381
784
  this.checkProductInit();
382
785
  return this.productBuilder.updateJob(tag, data);
383
786
  },
384
787
  },
385
788
  caches: {
789
+ /**
790
+ * Creates a cache for a product.
791
+ * @param {IProductCache} data - The cache data.
792
+ * @returns {Promise<void>} Resolves when the cache is created. Throws on error.
793
+ */
386
794
  create: async (data) => {
387
795
  this.checkProductInit();
388
796
  return this.productBuilder.createCache(data);
389
797
  },
390
- fetchAll: () => {
798
+ /**
799
+ * Fetches all caches for a product.
800
+ * @returns {IProductCache[]} The list of caches.
801
+ */
802
+ fetchAll: async () => {
391
803
  this.checkProductInit();
392
804
  return this.productBuilder.fetchCaches();
393
805
  },
394
- fetch: (tag) => {
806
+ /**
807
+ * Fetches a cache by tag.
808
+ * @param {string} tag - The cache tag.
809
+ * @returns {IProductCache|null} The fetched cache, or null if not found.
810
+ */
811
+ fetch: async (tag) => {
395
812
  this.checkProductInit();
396
813
  return this.productBuilder.fetchCache(tag);
397
814
  },
815
+ /**
816
+ * Updates a cache by tag.
817
+ * @param {string} tag - The cache tag.
818
+ * @param {Partial<IProductCache>} data - The cache data to update.
819
+ * @returns {Promise<void>} Resolves when the cache is updated. Throws on error.
820
+ */
398
821
  update: async (tag, data) => {
399
822
  this.checkProductInit();
400
823
  return this.productBuilder.updateCache(tag, data);
@@ -405,41 +828,85 @@ class Ductape {
405
828
  },
406
829
  },
407
830
  features: {
831
+ /**
832
+ * Creates a feature for a product.
833
+ * @param {Partial<IProductFeature>} data - The feature data.
834
+ * @returns {Promise<void>} Resolves when the feature is created. Throws on error.
835
+ */
408
836
  create: async (data) => {
409
837
  this.checkProductInit();
410
838
  return this.productBuilder.createFeature(data);
411
839
  },
412
- fetchAll: () => {
840
+ /**
841
+ * Fetches all features for a product.
842
+ * @returns {IProductFeature[]} The list of features.
843
+ */
844
+ fetchAll: async () => {
413
845
  this.checkProductInit();
414
846
  return this.productBuilder.fetchFeatures();
415
847
  },
416
- fetch: (tag) => {
848
+ /**
849
+ * Fetches a feature by tag.
850
+ * @param {string} tag - The feature tag.
851
+ * @returns {IProductFeature|null} The fetched feature, or null if not found.
852
+ */
853
+ fetch: async (tag) => {
417
854
  this.checkProductInit();
418
855
  return this.productBuilder.fetchFeature(tag);
419
856
  },
857
+ /**
858
+ * Updates a feature by tag.
859
+ * @param {string} tag - The feature tag.
860
+ * @param {Partial<IProductCache>} data - The feature data to update.
861
+ * @returns {Promise<void>} Resolves when the feature is updated. Throws on error.
862
+ */
420
863
  update: async (tag, data) => {
421
864
  this.checkProductInit();
422
865
  return this.productBuilder.updateFeature(tag, data);
423
866
  },
424
867
  },
425
868
  };
869
+ /**
870
+ * App-related operations for managing apps, variables, constants, actions, auths, webhooks, environments, and validation.
871
+ */
426
872
  this.app = {
873
+ /**
874
+ * Creates a new app.
875
+ * @param {ICreateAppBuilder} data - The app data.
876
+ * @returns {Promise<{ app_id: string }>} The ID of the created app.
877
+ */
427
878
  create: async (data) => {
428
879
  await this.initApp();
429
880
  return this.appBuilder.createApp(data);
430
881
  },
882
+ /**
883
+ * Fetches an app by tag.
884
+ * @param {string} tag - The app tag.
885
+ * @returns {Promise<IApp|null>} The fetched app, or null if not found.
886
+ */
431
887
  fetch: async (tag) => {
432
888
  await this.initApp();
433
889
  await this.appBuilder.initializeAppByTag(tag);
434
890
  this.appInit = false;
435
891
  return this.appBuilder.fetchApp();
436
892
  },
893
+ /**
894
+ * Updates an app by tag.
895
+ * @param {string} tag - The app tag.
896
+ * @param {Partial<IApp>} data - The app data to update.
897
+ * @returns {Promise<void>} Resolves when the app is updated. Throws on error.
898
+ */
437
899
  update: async (tag, data) => {
438
900
  await this.initApp();
439
901
  await this.appBuilder.initializeAppByTag(tag);
440
902
  this.appInit = false;
441
903
  return this.appBuilder.updateApp(data);
442
904
  },
905
+ /**
906
+ * Initializes an app by tag.
907
+ * @param {string} appTag - The app tag.
908
+ * @returns {Promise<void>} Resolves when initialization is complete. Throws on error.
909
+ */
443
910
  init: async (appTag) => {
444
911
  console.log(`App initialized with tag: ${appTag}`);
445
912
  await this.initApp();
@@ -447,43 +914,93 @@ class Ductape {
447
914
  this.appInit = true;
448
915
  },
449
916
  variables: {
917
+ /**
918
+ * Creates a variable for an app.
919
+ * @param {IAppVariables} data - The variable data.
920
+ * @returns {Promise<void>} Resolves when the variable is created. Throws on error.
921
+ */
450
922
  create: async (data) => {
451
923
  this.checkAppInit();
452
924
  return this.appBuilder.createVariable(data);
453
925
  },
454
- fetchAll: () => {
926
+ /**
927
+ * Fetches all variables for an app.
928
+ * @returns {IAppVariables[]} The list of variables.
929
+ */
930
+ fetchAll: async () => {
455
931
  this.checkAppInit();
456
932
  return this.appBuilder.fetchVariables();
457
933
  },
458
- fetch: (tag) => {
934
+ /**
935
+ * Fetches a variable by tag.
936
+ * @param {string} tag - The variable tag.
937
+ * @returns {IAppVariables|null} The fetched variable, or null if not found.
938
+ */
939
+ fetch: async (tag) => {
459
940
  this.checkAppInit();
460
941
  return this.appBuilder.fetchVariable(tag);
461
942
  },
943
+ /**
944
+ * Updates a variable by tag.
945
+ * @param {string} tag - The variable tag.
946
+ * @param {Partial<IAppVariables>} data - The variable data to update.
947
+ * @returns {Promise<void>} Resolves when the variable is updated. Throws on error.
948
+ */
462
949
  update: async (tag, data) => {
463
950
  this.checkAppInit();
464
951
  return this.appBuilder.updateVariable(tag, data);
465
952
  },
466
953
  },
467
954
  constants: {
955
+ /**
956
+ * Creates a constant for an app.
957
+ * @param {IAppConstants} data - The constant data.
958
+ * @returns {Promise<void>} Resolves when the constant is created. Throws on error.
959
+ */
468
960
  create: async (data) => {
469
961
  this.checkAppInit();
470
962
  return this.appBuilder.createConstant(data);
471
963
  },
472
- fetchAll: () => {
964
+ /**
965
+ * Fetches all constants for an app.
966
+ * @returns {IAppConstants[]} The list of constants.
967
+ */
968
+ fetchAll: async () => {
473
969
  this.checkAppInit();
474
970
  return this.appBuilder.fetchConstants();
475
971
  },
476
- fetch: (tag) => {
972
+ /**
973
+ * Fetches a constant by tag.
974
+ * @param {string} tag - The constant tag.
975
+ * @returns {IAppConstants|null} The fetched constant, or null if not found.
976
+ */
977
+ fetch: async (tag) => {
477
978
  this.checkAppInit();
478
979
  return this.appBuilder.fetchConstant(tag);
479
980
  },
981
+ /**
982
+ * Updates a constant by tag.
983
+ * @param {string} tag - The constant tag.
984
+ * @param {Partial<IAppVariables>} data - The constant data to update.
985
+ * @returns {Promise<void>} Resolves when the constant is updated. Throws on error.
986
+ */
480
987
  update: async (tag, data) => {
481
988
  this.checkAppInit();
482
989
  return this.appBuilder.updateConstant(tag, data);
483
990
  },
484
991
  },
485
992
  actions: {
486
- import: async ({ file, type, version, appTag, updateIfExists, }) => {
993
+ /**
994
+ * Imports actions for an app from a file.
995
+ * @param {Object} params - The import parameters.
996
+ * @param {Buffer} params.file - The file buffer.
997
+ * @param {ImportDocsTypes} params.type - The import type.
998
+ * @param {string} params.version - The version.
999
+ * @param {string} [params.appTag] - The app tag (optional).
1000
+ * @param {boolean} [params.updateIfExists] - Whether to update if actions exist (optional).
1001
+ * @returns {Promise<void>} Resolves when the import is complete. Throws on error.
1002
+ */
1003
+ import: async ({ file, type, version, appTag, updateIfExists, isAdminImport, }) => {
487
1004
  var _a;
488
1005
  if (!this.token)
489
1006
  await this.initUserAuth();
@@ -503,69 +1020,167 @@ class Ductape {
503
1020
  }
504
1021
  app_id = app._id;
505
1022
  }
506
- return this.importService.importApp(file, type, version, updateIfExists, app_id);
507
- },
1023
+ return this.importService.importApp(file, type, version, updateIfExists, app_id, isAdminImport);
1024
+ },
1025
+ /**
1026
+ * Updates an action by tag.
1027
+ * @param {string} tag - The action tag.
1028
+ * @param {Partial<IActionUpdate>} data - The action data to update.
1029
+ * @returns {Promise<void>} Resolves when the action is updated. Throws on error.
1030
+ */
508
1031
  update: async (tag, data) => {
509
1032
  this.checkAppInit();
510
1033
  return this.appBuilder.updateAction(tag, data);
511
1034
  },
512
- fetchAll: () => {
1035
+ /**
1036
+ * Updates multiple actions at once with shared variables (query params or headers).
1037
+ * @param {string[]} tags - Array of action tags to update.
1038
+ * @param {Object} data - The shared variable data.
1039
+ * @param {'query' | 'headers'} data.category - The variable type (query params or headers).
1040
+ * @param {string} data.key - The variable key.
1041
+ * @param {string} data.value - The variable value.
1042
+ * @returns {Promise<void>} Resolves when all actions are updated. Throws on error.
1043
+ */
1044
+ updateMany: async (tags, data) => {
1045
+ this.checkAppInit();
1046
+ return this.appBuilder.updateManyActions(tags, data);
1047
+ },
1048
+ /**
1049
+ * Creates an action.
1050
+ * @param {Partial<IActionUpdate> & { tag: string; name: string; resource: string; method: string }} data - The action data to create.
1051
+ * @returns {Promise<void>} Resolves when the action is created. Throws on error.
1052
+ */
1053
+ create: async (data) => {
1054
+ this.checkAppInit();
1055
+ return this.appBuilder.createAction(data);
1056
+ },
1057
+ /**
1058
+ * Fetches all actions for an app.
1059
+ * @returns {IAppAction[]} The list of actions.
1060
+ */
1061
+ fetchAll: async () => {
513
1062
  this.checkAppInit();
514
1063
  return this.appBuilder.fetchActions();
515
1064
  },
516
- fetch: (tag) => {
1065
+ /**
1066
+ * Fetches an action by tag.
1067
+ * @param {string} tag - The action tag.
1068
+ * @returns {IAppAction|null} The fetched action, or null if not found.
1069
+ */
1070
+ fetch: async (tag) => {
517
1071
  this.checkAppInit();
518
1072
  return this.appBuilder.fetchAction(tag);
519
1073
  },
520
1074
  },
521
1075
  auths: {
1076
+ /**
1077
+ * Creates an auth for an app.
1078
+ * @param {IAppAuth} data - The auth data.
1079
+ * @returns {Promise<void>} Resolves when the auth is created. Throws on error.
1080
+ */
522
1081
  create: async (data) => {
523
1082
  this.checkAppInit();
524
1083
  return this.appBuilder.createAuth(data);
525
1084
  },
526
- fetchAll: () => {
1085
+ /**
1086
+ * Fetches all auths for an app.
1087
+ * @returns {IAppAuth[]} The list of auths.
1088
+ */
1089
+ fetchAll: async () => {
527
1090
  this.checkAppInit();
528
1091
  return this.appBuilder.fetchAuths();
529
1092
  },
530
- fetch: (tag) => {
1093
+ /**
1094
+ * Fetches an auth by tag.
1095
+ * @param {string} tag - The auth tag.
1096
+ * @returns {IAppAuth|null} The fetched auth, or null if not found.
1097
+ */
1098
+ fetch: async (tag) => {
531
1099
  this.checkAppInit();
532
1100
  return this.appBuilder.fetchAuth(tag);
533
1101
  },
1102
+ /**
1103
+ * Updates an auth by tag.
1104
+ * @param {string} tag - The auth tag.
1105
+ * @param {Partial<IAppAuth>} data - The auth data to update.
1106
+ * @returns {Promise<void>} Resolves when the auth is updated. Throws on error.
1107
+ */
534
1108
  update: async (tag, data) => {
535
1109
  this.checkAppInit();
536
1110
  return this.appBuilder.updateAuth(tag, data);
537
1111
  },
538
1112
  },
539
1113
  webhooks: {
1114
+ /**
1115
+ * Creates a webhook for an app.
1116
+ * @param {Partial<IAppWebhook>} data - The webhook data.
1117
+ * @returns {Promise<void>} Resolves when the webhook is created. Throws on error.
1118
+ */
540
1119
  create: async (data) => {
541
1120
  this.checkAppInit();
542
1121
  return this.appBuilder.createWebhook(data);
543
1122
  },
544
- fetchAll: () => {
1123
+ /**
1124
+ * Fetches all webhooks for an app.
1125
+ * @returns {IAppWebhook[]} The list of webhooks.
1126
+ */
1127
+ fetchAll: async () => {
545
1128
  this.checkAppInit();
546
1129
  return this.appBuilder.fetchWebhooks();
547
1130
  },
548
- fetch: (tag) => {
1131
+ /**
1132
+ * Fetches a webhook by tag.
1133
+ * @param {string} tag - The webhook tag.
1134
+ * @returns {IAppWebhook|null} The fetched webhook, or null if not found.
1135
+ */
1136
+ fetch: async (tag) => {
549
1137
  this.checkAppInit();
550
1138
  return this.appBuilder.fetchWebhook(tag);
551
1139
  },
1140
+ /**
1141
+ * Updates a webhook by tag.
1142
+ * @param {string} tag - The webhook tag.
1143
+ * @param {Partial<IAppWebhook>} data - The webhook data to update.
1144
+ * @returns {Promise<void>} Resolves when the webhook is updated. Throws on error.
1145
+ */
552
1146
  update: async (tag, data) => {
553
1147
  this.checkAppInit();
554
1148
  return this.appBuilder.updateWebhook(tag, data);
555
1149
  },
556
1150
  events: {
1151
+ /**
1152
+ * Creates a webhook event for an app.
1153
+ * @param {IAppWebhookEvent} data - The webhook event data.
1154
+ * @returns {Promise<void>} Resolves when the webhook event is created. Throws on error.
1155
+ */
557
1156
  create: async (data) => {
558
1157
  this.checkAppInit();
559
1158
  return this.appBuilder.createWebhookEvent(data);
560
1159
  },
561
- fetchAll: (webhookTag) => {
1160
+ /**
1161
+ * Fetches all webhook events for a webhook by tag.
1162
+ * @param {string} webhookTag - The webhook tag.
1163
+ * @returns {IAppWebhookEvent[]} The list of webhook events.
1164
+ */
1165
+ fetchAll: async (webhookTag) => {
562
1166
  this.checkAppInit();
563
1167
  return this.appBuilder.fetchWebhookEvents(webhookTag);
564
1168
  },
565
- fetch: (tag) => {
1169
+ /**
1170
+ * Fetches a webhook event by tag.
1171
+ * @param {string} tag - The webhook event tag.
1172
+ * @returns {IAppWebhookEvent|null} The fetched webhook event, or null if not found.
1173
+ */
1174
+ fetch: async (tag) => {
566
1175
  this.checkAppInit();
567
1176
  return this.appBuilder.fetchWebhookEvent(tag);
568
1177
  },
1178
+ /**
1179
+ * Updates a webhook event by tag.
1180
+ * @param {string} tag - The webhook event tag.
1181
+ * @param {Partial<IAppWebhookEvent>} data - The webhook event data to update.
1182
+ * @returns {Promise<void>} Resolves when the webhook event is updated. Throws on error.
1183
+ */
569
1184
  update: async (tag, data) => {
570
1185
  this.checkAppInit();
571
1186
  return this.appBuilder.updateWebhookEvent(Object.assign(Object.assign({}, data), { tag }));
@@ -573,136 +1188,303 @@ class Ductape {
573
1188
  },
574
1189
  },
575
1190
  environments: {
1191
+ /**
1192
+ * Creates an environment for an app.
1193
+ * @param {IAppEnv} data - The environment data.
1194
+ * @returns {Promise<void>} Resolves when the environment is created. Throws on error.
1195
+ */
576
1196
  create: async (data) => {
577
1197
  this.checkAppInit();
578
1198
  return this.appBuilder.createEnv(data);
579
1199
  },
580
- fetchAll: () => {
1200
+ /**
1201
+ * Fetches all environments for an app.
1202
+ * @returns {IAppEnv[]} The list of environments.
1203
+ */
1204
+ fetchAll: async () => {
581
1205
  this.checkAppInit();
582
1206
  return this.appBuilder.fetchEnvs();
583
1207
  },
584
- fetch: (slug) => {
1208
+ /**
1209
+ * Fetches an environment by slug.
1210
+ * @param {string} slug - The environment slug.
1211
+ * @returns {IAppEnv|null} The fetched environment, or null if not found.
1212
+ */
1213
+ fetch: async (slug) => {
585
1214
  this.checkAppInit();
586
1215
  return this.appBuilder.fetchEnv(slug);
587
1216
  },
1217
+ /**
1218
+ * Updates an environment by slug.
1219
+ * @param {string} slug - The environment slug.
1220
+ * @param {Partial<IAppEnv>} data - The environment data to update.
1221
+ * @returns {Promise<void>} Resolves when the environment is updated. Throws on error.
1222
+ */
588
1223
  update: async (slug, data) => {
589
1224
  this.checkAppInit();
590
1225
  return this.appBuilder.updateEnv(slug, data);
591
1226
  },
592
1227
  },
1228
+ /**
1229
+ * Updates data validation for an app.
1230
+ * @param {string} selector - The selector for the data validation.
1231
+ * @param {Partial<IParsedSample>} update - The update data.
1232
+ * @returns {Promise<void>} Resolves when the validation is updated. Throws on error.
1233
+ */
593
1234
  validation: (selector, update) => {
594
1235
  this.checkAppInit();
595
1236
  return this.appBuilder.updateDataValidation(selector, update);
596
1237
  },
597
1238
  };
598
- this.processor = {
599
- job: {
600
- schedule: async (data) => {
601
- const processorService = await this.createNewProcessor();
602
- //return processorService.processJob()
603
- },
1239
+ /**
1240
+ * Job-related operations for scheduling jobs.
1241
+ */
1242
+ this.job = {
1243
+ /**
1244
+ * Schedules a job for a product.
1245
+ * @param {IProduct} data - The product data.
1246
+ * @returns {Promise<any>} The result of the job scheduling.
1247
+ */
1248
+ schedule: async (data) => {
1249
+ const processorService = await this.createNewProcessor();
1250
+ //return processorService.processJob()
604
1251
  },
605
- action: {
606
- run: async (data) => {
607
- const processorService = await this.createNewProcessor();
608
- return processorService.processAction(data);
609
- },
1252
+ };
1253
+ /**
1254
+ * Action-related operations for running actions.
1255
+ */
1256
+ this.action = {
1257
+ /**
1258
+ * Runs an action processor.
1259
+ * @param {IActionProcessorInput} data - The action processor input.
1260
+ * @returns {Promise<any>} The result of the action processing.
1261
+ */
1262
+ run: async (data) => {
1263
+ const processorService = await this.createNewProcessor();
1264
+ return processorService.processAction(data);
1265
+ },
1266
+ };
1267
+ /**
1268
+ * Session-related operations for creating, validating, and refreshing sessions.
1269
+ */
1270
+ this.sessions = {
1271
+ /**
1272
+ * Starts a new session.
1273
+ * @param {ISessionInput} data - The session input data.
1274
+ * @returns {Promise<any>} The result of the session generation.
1275
+ */
1276
+ create: async (data) => {
1277
+ const processorService = await this.createNewProcessor();
1278
+ return processorService.generateSession(data);
1279
+ },
1280
+ /**
1281
+ * Decrypts a session.
1282
+ * @param {ISessionPayload} data - The session payload.
1283
+ * @returns {Promise<any>} The decrypted session.
1284
+ */
1285
+ validate: async (data) => {
1286
+ const processorService = await this.createNewProcessor();
1287
+ return processorService.decryptSession(data);
1288
+ },
1289
+ /**
1290
+ * Refreshes a session.
1291
+ * @param {ISessionRefreshPayload} data - The session refresh payload.
1292
+ * @returns {Promise<any>} The refreshed session.
1293
+ */
1294
+ refresh: async (data) => {
1295
+ const processorService = await this.createNewProcessor();
1296
+ return processorService.refreshSession(data);
1297
+ }
1298
+ };
1299
+ /**
1300
+ * Feature-related operations for running, replaying, and resuming features.
1301
+ */
1302
+ this.feature = {
1303
+ /**
1304
+ * Runs a feature processor.
1305
+ * @param {IProcessorInput} data - The feature processor input.
1306
+ * @returns {Promise<any>} The result of the feature processing.
1307
+ */
1308
+ run: async (data) => {
1309
+ const processorService = await this.createNewProcessor();
1310
+ return await processorService.processFeature(data);
1311
+ },
1312
+ /**
1313
+ * Generates output for a process by ID.
1314
+ * @param {string} process_id - The process ID.
1315
+ * @returns {Promise<any>} The generated output.
1316
+ */
1317
+ output: async (process_id) => {
1318
+ const processorService = await this.createNewProcessor();
1319
+ return await processorService.generateOutput(process_id);
1320
+ },
1321
+ /**
1322
+ * Replays a process by ID.
1323
+ * @param {string} process_id - The process ID.
1324
+ * @returns {Promise<any>} The result of the replay.
1325
+ */
1326
+ replay: async (process_id) => {
1327
+ const processorService = await this.createNewProcessor();
1328
+ return await processorService.replayProcess(process_id);
1329
+ },
1330
+ /**
1331
+ * Resumes a process by ID.
1332
+ * @param {string} process_id - The process ID.
1333
+ * @returns {Promise<any>} The result of the resume.
1334
+ */
1335
+ resume: async (process_id) => {
1336
+ const processorService = await this.createNewProcessor();
1337
+ return await processorService.resumeProcess(process_id);
1338
+ },
1339
+ };
1340
+ /**
1341
+ * Quota-related operations for running quota processors.
1342
+ */
1343
+ this.quota = {
1344
+ /**
1345
+ * Runs a quota processor.
1346
+ * @param {IProcessorInput} data - The quota processor input.
1347
+ * @returns {Promise<any>} The result of the quota processing.
1348
+ */
1349
+ run: async (data) => {
1350
+ const processorService = await this.createNewProcessor();
1351
+ return processorService.processQuota(data);
1352
+ },
1353
+ };
1354
+ /**
1355
+ * Fallback-related operations for running fallback processors.
1356
+ */
1357
+ this.fallback = {
1358
+ /**
1359
+ * Runs a fallback processor.
1360
+ * @param {IProcessorInput} data - The fallback processor input.
1361
+ * @returns {Promise<any>} The result of the fallback processing.
1362
+ */
1363
+ run: async (data) => {
1364
+ const processorService = await this.createNewProcessor();
1365
+ return processorService.processFallback(data);
610
1366
  },
1367
+ };
1368
+ /**
1369
+ * Notification-related operations for sending notifications.
1370
+ */
1371
+ this.notification = {
1372
+ /**
1373
+ * Sends a notification using the notification processor.
1374
+ * @param {INotificationProcessorInput} data - The notification processor input.
1375
+ * @returns {Promise<any>} The result of the notification processing.
1376
+ */
1377
+ send: async (data) => {
1378
+ const processorService = await this.createNewProcessor();
1379
+ return processorService.processNotification(data);
1380
+ },
1381
+ };
1382
+ /**
1383
+ * Storage-related operations for reading and saving files.
1384
+ */
1385
+ this.storage = {
1386
+ /**
1387
+ * Reads a file from storage.
1388
+ * @param {string} path - The file path.
1389
+ * @returns {Promise<IFileReadResult>} The file read result.
1390
+ */
1391
+ read: async (path) => {
1392
+ try {
1393
+ const buffer = await fs_1.promises.readFile(path);
1394
+ const mimeType = mime.lookup(path) || ''; // Get MIME type or fallback to empty string
1395
+ return { buffer: buffer.toString('base64'), fileName: filePath.basename(path), mimeType };
1396
+ }
1397
+ catch (error) {
1398
+ console.error('Error reading file:', error);
1399
+ throw error;
1400
+ }
1401
+ },
1402
+ /**
1403
+ * Saves data to storage using the storage processor.
1404
+ * @param {IStorageProcessorInput} data - The storage processor input.
1405
+ * @returns {Promise<any>} The result of the storage processing.
1406
+ */
1407
+ save: async (data) => {
1408
+ const processorService = await this.createNewProcessor();
1409
+ return processorService.processStorage(data);
1410
+ },
1411
+ };
1412
+ /**
1413
+ * Message broker-related operations for publishing and subscribing to topics.
1414
+ */
1415
+ this.broker = {
1416
+ /**
1417
+ * Publishes a message using the message broker processor.
1418
+ * @param {IMessageBrokerPublishInput} data - The publish input.
1419
+ * @returns {Promise<any>} The result of the publish operation.
1420
+ */
1421
+ publish: async (data) => {
1422
+ const processorService = await this.createNewProcessor();
1423
+ return processorService.processMessageBrokerPublish(data);
1424
+ },
1425
+ /**
1426
+ * Subscribes to a message broker topic.
1427
+ * @param {IMessageBrokerSubscribeInput} data - The subscribe input.
1428
+ * @returns {Promise<any>} The result of the subscribe operation.
1429
+ */
1430
+ subcribe: async (data) => {
1431
+ const processorService = await this.createNewProcessor();
1432
+ return processorService.processMessageBrokerSubscribe(data);
1433
+ },
1434
+ };
1435
+ /**
1436
+ * Processor-related operations for database actions only.
1437
+ */
1438
+ this.processor = {
611
1439
  db: {
1440
+ /**
1441
+ * Executes a database action processor.
1442
+ * @param {IDBActionProcessorInput} data - The database action processor input.
1443
+ * @returns {Promise<any>} The result of the database action processing.
1444
+ */
612
1445
  execute: async (data) => {
613
1446
  const processorService = await this.createNewProcessor();
614
1447
  return processorService.processDBAction(data);
615
1448
  },
616
1449
  migration: {
1450
+ /**
1451
+ * Runs a database migration.
1452
+ * @param {Object} params - The migration parameters.
1453
+ * @param {string} params.migration - The migration name.
1454
+ * @param {string} params.env - The environment.
1455
+ * @param {string} params.product - The product name.
1456
+ * @returns {Promise<any>} The result of the migration.
1457
+ */
617
1458
  run: async ({ migration, env, product }) => {
618
- //this.checkProductInit();
619
1459
  const processorService = await this.createNewProcessor();
620
1460
  return processorService.runMigration(product, migration, env, 'up');
621
1461
  },
1462
+ /**
1463
+ * Rolls back a database migration.
1464
+ * @param {Object} params - The migration parameters.
1465
+ * @param {string} params.migration - The migration name.
1466
+ * @param {string} params.env - The environment.
1467
+ * @param {string} params.product - The product name.
1468
+ * @returns {Promise<any>} The result of the rollback.
1469
+ */
622
1470
  rollback: async ({ migration, env, product }) => {
623
- //this.checkProductInit();
624
1471
  const processorService = await this.createNewProcessor();
625
1472
  return processorService.runMigration(product, migration, env, 'down');
626
1473
  },
627
1474
  },
628
1475
  },
629
- sessions: {
630
- generate: async (data) => {
631
- const processorService = await this.createNewProcessor();
632
- return processorService.generateSession(data);
633
- }
634
- },
635
- feature: {
636
- run: async (data) => {
637
- const processorService = await this.createNewProcessor();
638
- return await processorService.processFeature(data);
639
- },
640
- output: async (process_id) => {
641
- const processorService = await this.createNewProcessor();
642
- return await processorService.generateOutput(process_id);
643
- },
644
- replay: async (process_id) => {
645
- const processorService = await this.createNewProcessor();
646
- return await processorService.replayProcess(process_id);
647
- },
648
- resume: async (process_id) => {
649
- const processorService = await this.createNewProcessor();
650
- return await processorService.resumeProcess(process_id);
651
- },
652
- },
653
- quota: {
654
- run: async (data) => {
655
- const processorService = await this.createNewProcessor();
656
- return processorService.processQuota(data);
657
- },
658
- },
659
- fallback: {
660
- run: async (data) => {
661
- const processorService = await this.createNewProcessor();
662
- return processorService.processFallback(data);
663
- },
664
- },
665
- notification: {
666
- send: async (data) => {
667
- const processorService = await this.createNewProcessor();
668
- return processorService.processNotification(data);
669
- },
670
- },
671
- storage: {
672
- readFile: async (path) => {
673
- try {
674
- const buffer = await fs_1.promises.readFile(path);
675
- const mimeType = mime.lookup(path) || ''; // Get MIME type or fallback to empty string
676
- return { buffer: buffer.toString('base64'), fileName: filePath.basename(path), mimeType };
677
- }
678
- catch (error) {
679
- console.error('Error reading file:', error);
680
- throw error;
681
- }
682
- },
683
- save: async (data) => {
684
- const processorService = await this.createNewProcessor();
685
- return processorService.processStorage(data);
686
- },
687
- },
688
- /*cloudFunction: {
689
- invoke: async (data: IFunctionProcessorInput) => {
690
- const processorService = this.createNewProcessor();
691
- return processorService.processFunction(data);
692
- },
693
- },*/
694
- messageBroker: {
695
- publish: async (data) => {
696
- const processorService = await this.createNewProcessor();
697
- return processorService.processMessageBrokerPublish(data);
698
- },
699
- subcribe: async (data) => {
700
- const processorService = await this.createNewProcessor();
701
- return processorService.processMessageBrokerSubscribe(data);
702
- },
703
- },
704
1476
  };
1477
+ /**
1478
+ * Logs-related operations for initializing and fetching logs.
1479
+ */
705
1480
  this.logs = {
1481
+ /**
1482
+ * Initializes the logger service for a product or app.
1483
+ * @param {string} [productTag] - The product tag (optional).
1484
+ * @param {string} [appTag] - The app tag (optional).
1485
+ * @throws {Error} If neither productTag nor appTag is provided.
1486
+ * @returns {Promise<void>} Resolves when logger is initialized.
1487
+ */
706
1488
  init: async (productTag, appTag) => {
707
1489
  if (!productTag && !appTag) {
708
1490
  throw new Error('At least one of productTag or appTag must be provided');
@@ -717,52 +1499,13 @@ class Ductape {
717
1499
  await this.appBuilder.initializeAppByTag(appTag);
718
1500
  this.appInit = true;
719
1501
  }
720
- this.loggerService = this.createNewLogger(productTag ? this.productBuilder.fetchProduct()._id : null, appTag ? this.appBuilder.fetchApp()._id : null);
1502
+ this.loggerService = this.createNewLogger(productTag ? this.productBuilder.fetchProductId() : null, appTag ? this.appBuilder.fetchApp()._id : null);
721
1503
  },
722
1504
  add: async () => { },
723
1505
  /**
724
- * Fetches logs based on provded query parameters.
725
- *
726
- * @param params.component - Required. Specifies the component type ('app' or 'product')
727
- * @param params.type - Optional. Type of analysis ('apps', 'process', 'feature', 'integrations', etc.)
728
- * @param params.groupBy - Optional. Time period for grouping ('day', 'week', 'month', 'year')
729
- * @param params.search - Optional. Search term for filtering logs
730
- * @param params.page - Optional. Page number for pagination (≥ 1)
731
- * @param params.limit - Optional. Number of items per page (≥ 1)
732
- * @param params.status - Optional. Filter by status ('success', 'processing', 'fail')
733
- *
734
- * For component='app':
735
- * @param params.tag - Optional. Tag identifier (only valid when type='actions')
736
- * @param params.env - Optional. Environment filter
737
- * @param params.name - Optional. Name filter
738
- * @param params.action - Optional. Specific action filter
739
- *
740
- * For component='product':
741
- * @param params.env - Optional. Environment filter
742
- * @param params.name - Optional. Name filter
743
- * @param params.action - Optional. Specific action filter
744
- *
745
- * @throws {Error} If logger service is not initialized
746
- * @throws {Error} If required parameters are missing or invalid
747
- * @throws {Error} If API request fails
748
- *
749
- * @returns {Promise<any>} The fetched log data
750
- *
751
- * @example
752
- * // Fetch app logs
753
- * const appLogs = await logs.fetch({
754
- * component: 'app',
755
- * type: 'actions',
756
- * groupBy: 'day',
757
- * limit: 20
758
- * });
759
- *
760
- * // Fetch product logs
761
- * const productLogs = await logs.fetch({
762
- * component: 'product',
763
- * type: 'database',
764
- * status: 'success'
765
- * });
1506
+ * Fetches logs based on provided query parameters.
1507
+ * @param {LogQueryParams} params - The log query parameters.
1508
+ * @returns {Promise<any>} The fetched log data.
766
1509
  */
767
1510
  fetch: async (params) => {
768
1511
  if (!this.loggerService) {
@@ -778,6 +1521,153 @@ class Ductape {
778
1521
  },
779
1522
  publish: async () => { },
780
1523
  };
1524
+ /**
1525
+ * Workspace secrets operations for securely storing encrypted key-value pairs.
1526
+ * Values are encrypted client-side using the workspace's private key.
1527
+ */
1528
+ this.secrets = {
1529
+ /**
1530
+ * Cached workspace private key for encryption/decryption.
1531
+ * Fetched once and reused for the session.
1532
+ */
1533
+ _privateKey: null,
1534
+ /**
1535
+ * Fetches and caches the workspace private key.
1536
+ * @returns {Promise<string>} The decrypted workspace private key.
1537
+ */
1538
+ fetchPrivateKey: async () => {
1539
+ if (!this.token)
1540
+ await this.initUserAuth();
1541
+ if (this.secrets._privateKey) {
1542
+ return this.secrets._privateKey;
1543
+ }
1544
+ const privateKey = await this.secretsApi.getPrivateKey({
1545
+ token: this.token,
1546
+ public_key: this.public_key,
1547
+ user_id: this.user_id,
1548
+ workspace_id: this.workspace_id,
1549
+ });
1550
+ this.secrets._privateKey = privateKey;
1551
+ return privateKey;
1552
+ },
1553
+ /**
1554
+ * Creates a new workspace secret.
1555
+ * The value is encrypted client-side before being sent to the server.
1556
+ * @param {Object} data - The secret data.
1557
+ * @param {string} data.key - The unique key for the secret (alphanumeric + underscores).
1558
+ * @param {string} data.value - The plaintext value to encrypt and store.
1559
+ * @param {string} [data.description] - Optional description.
1560
+ * @param {string} [data.token_type] - Optional token type ('api' or 'access').
1561
+ * @param {string[]} [data.scope] - Optional array of scopes.
1562
+ * @param {string[]} [data.envs] - Optional array of environment slugs.
1563
+ * @param {number|null} [data.expires_at] - Optional expiry timestamp in seconds (Unix epoch).
1564
+ * @returns {Promise<IWorkspaceSecret>} The created secret (without encrypted value).
1565
+ */
1566
+ create: async (data) => {
1567
+ if (!this.token)
1568
+ await this.initUserAuth();
1569
+ // Get the workspace private key for encryption
1570
+ const workspacePrivateKey = await this.secrets.fetchPrivateKey();
1571
+ // Encrypt the value client-side
1572
+ const encrypted_value = (0, processor_utils_1.encrypt)(data.value, workspacePrivateKey);
1573
+ const payload = {
1574
+ key: data.key,
1575
+ encrypted_value,
1576
+ description: data.description,
1577
+ token_type: data.token_type,
1578
+ scope: data.scope,
1579
+ envs: data.envs,
1580
+ expires_at: data.expires_at,
1581
+ };
1582
+ return this.secretsApi.createSecret({
1583
+ token: this.token,
1584
+ public_key: this.public_key,
1585
+ user_id: this.user_id,
1586
+ workspace_id: this.workspace_id,
1587
+ }, payload);
1588
+ },
1589
+ /**
1590
+ * Lists all workspace secrets.
1591
+ * Returns metadata only, not the encrypted values.
1592
+ * @returns {Promise<IWorkspaceSecret[]>} List of secrets.
1593
+ */
1594
+ fetchAll: async () => {
1595
+ if (!this.token)
1596
+ await this.initUserAuth();
1597
+ return this.secretsApi.listSecrets({
1598
+ token: this.token,
1599
+ public_key: this.public_key,
1600
+ user_id: this.user_id,
1601
+ workspace_id: this.workspace_id,
1602
+ });
1603
+ },
1604
+ /**
1605
+ * Fetches a single secret by key and decrypts its value.
1606
+ * @param {string} key - The secret key.
1607
+ * @returns {Promise<IWorkspaceSecret & { value: string }>} The secret with decrypted value.
1608
+ */
1609
+ fetch: async (key) => {
1610
+ if (!this.token)
1611
+ await this.initUserAuth();
1612
+ // Get the workspace private key for decryption
1613
+ const workspacePrivateKey = await this.secrets.fetchPrivateKey();
1614
+ const secret = await this.secretsApi.getSecret({
1615
+ token: this.token,
1616
+ public_key: this.public_key,
1617
+ user_id: this.user_id,
1618
+ workspace_id: this.workspace_id,
1619
+ }, key);
1620
+ // Decrypt the value client-side
1621
+ const decryptedValue = secret.encrypted_value
1622
+ ? (0, processor_utils_1.decrypt)(secret.encrypted_value, workspacePrivateKey)
1623
+ : '';
1624
+ return Object.assign(Object.assign({}, secret), { value: decryptedValue });
1625
+ },
1626
+ /**
1627
+ * Updates a workspace secret.
1628
+ * If a new value is provided, it will be encrypted client-side.
1629
+ * @param {string} key - The secret key to update.
1630
+ * @param {Object} data - The update data.
1631
+ * @param {string} [data.value] - New plaintext value to encrypt.
1632
+ * @param {string} [data.description] - New description.
1633
+ * @param {number|null} [data.expires_at] - New expiry timestamp.
1634
+ * @returns {Promise<IWorkspaceSecret>} The updated secret.
1635
+ */
1636
+ update: async (key, data) => {
1637
+ if (!this.token)
1638
+ await this.initUserAuth();
1639
+ const payload = {
1640
+ description: data.description,
1641
+ expires_at: data.expires_at,
1642
+ };
1643
+ // If a new value is provided, encrypt it
1644
+ if (data.value !== undefined) {
1645
+ const workspacePrivateKey = await this.secrets.fetchPrivateKey();
1646
+ payload.encrypted_value = (0, processor_utils_1.encrypt)(data.value, workspacePrivateKey);
1647
+ }
1648
+ return this.secretsApi.updateSecret({
1649
+ token: this.token,
1650
+ public_key: this.public_key,
1651
+ user_id: this.user_id,
1652
+ workspace_id: this.workspace_id,
1653
+ }, key, payload);
1654
+ },
1655
+ /**
1656
+ * Deletes a workspace secret.
1657
+ * @param {string} key - The secret key to delete.
1658
+ * @returns {Promise<boolean>} True if deleted successfully.
1659
+ */
1660
+ delete: async (key) => {
1661
+ if (!this.token)
1662
+ await this.initUserAuth();
1663
+ return this.secretsApi.deleteSecret({
1664
+ token: this.token,
1665
+ public_key: this.public_key,
1666
+ user_id: this.user_id,
1667
+ workspace_id: this.workspace_id,
1668
+ }, key);
1669
+ },
1670
+ };
781
1671
  this.workspace_id = workspace_id;
782
1672
  this.private_key = private_key;
783
1673
  this.user_id = user_id;
@@ -786,10 +1676,27 @@ class Ductape {
786
1676
  this.appApi = new appApi_service_1.AppApiService(this.environment);
787
1677
  this.workspaceApi = new workspaceApi_service_1.WorkspaceApiService(this.environment);
788
1678
  this.productsApi = new productsApi_service_1.ProductsApiService(this.environment);
1679
+ this.secretsApi = new workspaceSecretsApi_service_1.WorkspaceSecretsApiService(this.environment);
789
1680
  this.redis_url = redis_url;
790
1681
  return (0, utils_1.createDeepProxy)(this, this.environment);
791
1682
  }
792
- async connectRedis() {
1683
+ async loadBullMQ() {
1684
+ if (typeof window !== 'undefined') {
1685
+ throw new Error("Bullmq can only be used in a server environment.");
1686
+ }
1687
+ const bull = await Promise.resolve().then(() => __importStar(require('bullmq')));
1688
+ return {
1689
+ Queue: bull.Queue,
1690
+ Worker: bull.Worker,
1691
+ Job: bull.Job,
1692
+ };
1693
+ }
1694
+ /**
1695
+ * Connects to Redis and initializes job and health check queues and workers.
1696
+ * @throws {Error} If called in a browser environment or if Redis URL is missing.
1697
+ * @returns {Promise<void>} Resolves when Redis and queues are initialized.
1698
+ */
1699
+ async monitor() {
793
1700
  if (typeof window !== 'undefined') {
794
1701
  throw new Error("RedisService can only be used in a server environment.");
795
1702
  }
@@ -797,16 +1704,162 @@ class Ductape {
797
1704
  throw new Error("Redis URL is not provided.");
798
1705
  }
799
1706
  if (this.redisClient) {
800
- // Already connected — reuse existing client
1707
+ // Already connected
1708
+ return;
1709
+ }
1710
+ // TODO: remove this requirement
1711
+ if (!this.redisClient) {
801
1712
  return;
802
1713
  }
803
- const { createClient } = await this.loadRedis();
804
- this.redisClient = createClient({ url: this.redis_url });
805
- await this.redisClient.connect();
1714
+ if (!this.public_key) {
1715
+ await this.initUserAuth(false);
1716
+ }
1717
+ const Redis = await this.loadRedis();
1718
+ const { Queue, Worker: BullWorker } = await this.loadBullMQ();
1719
+ // Create Redis client with required options for BullMQ
1720
+ this.redisClient = new Redis.default(this.redis_url, {
1721
+ maxRetriesPerRequest: null, // Required by BullMQ
1722
+ });
1723
+ // Initialize job queues
1724
+ this.jobsQueue = new Queue('ductape_jobs', {
1725
+ connection: this.redisClient,
1726
+ });
1727
+ this.healthCheckQueue = new Queue('ductape_healthchecks', {
1728
+ connection: this.redisClient,
1729
+ });
1730
+ this.healthCheckUpdaterQueue = new Queue('healthchecks-updater', {
1731
+ connection: this.redisClient
1732
+ });
1733
+ // Schedule healthcheck jobs for all products/environments
1734
+ await this.scheduleAllHealthcheckJobs();
1735
+ // Initialize job worker
1736
+ this.jobsWorker = new BullWorker('ductape_jobs', async (job) => {
1737
+ console.log(`Processing job ${job.id} of type ${job.name}`, job.data);
1738
+ const processor = await this.createNewProcessor();
1739
+ await processor.runJobs(job);
1740
+ }, {
1741
+ connection: this.redisClient,
1742
+ });
1743
+ // Initialize health check worker
1744
+ this.healthCheckWorker = new BullWorker('ductape_healthchecks', async (job) => {
1745
+ console.log(`Running health check job ${job.id}`, job.data);
1746
+ const processor = await this.createNewProcessor();
1747
+ console.log("FIND JOB!!!!", job.data);
1748
+ if (job && job.data && Object.keys(job.data).length) {
1749
+ // Call processAction with job.data
1750
+ const result = await processor.processAction(job.data);
1751
+ // Write result to Redis cache
1752
+ await processor.writeHealthcheckResultToCache(job.data, Object.assign({ status: (result === null || result === void 0 ? void 0 : result.status) || 'unknown', lastChecked: Date.now() }, result));
1753
+ // Re-enqueue the job for continuous healthchecks
1754
+ //await this.scheduleHealthcheckJob(job.data);
1755
+ }
1756
+ }, {
1757
+ connection: this.redisClient,
1758
+ });
1759
+ // Add a repeatable job to update DB every 10 minutes
1760
+ await this.healthCheckUpdaterQueue.add('healthchecks-updater', {}, {
1761
+ jobId: 'healthchecks-updater',
1762
+ repeat: { every: 5 * 60 * 1000 }
1763
+ });
1764
+ // Healthcheck updater worker
1765
+ this.healthCheckUpdaterWorker = new BullWorker('healthchecks-updater', async (job) => {
1766
+ console.log('Init Processor for healthcheck Updater');
1767
+ if (job.name !== 'healthchecks-updater')
1768
+ return;
1769
+ // Gather all healthcheck results from Redis
1770
+ const keys = await this.redisClient.keys('healthcheck:*');
1771
+ console.log("Found Keys for healthcheck updater", JSON.stringify(keys));
1772
+ const envResults = {};
1773
+ for (const key of keys) {
1774
+ const [_, productTag, tag, envSlug] = key.split(':');
1775
+ console.log(`${productTag} , ${tag}, ${envSlug}`);
1776
+ const data = JSON.parse(await this.redisClient.get(key));
1777
+ if (!envResults[productTag])
1778
+ envResults[productTag] = {};
1779
+ if (!envResults[productTag][tag])
1780
+ envResults[productTag][tag] = {};
1781
+ envResults[productTag][tag][envSlug] = data;
1782
+ }
1783
+ for (const productTag in envResults) {
1784
+ const tagsData = Object.entries(envResults[productTag]).map(([tag, envs]) => ({
1785
+ tag,
1786
+ environments: Object.entries(envs).map(([slug, data]) => (Object.assign({ slug }, data))),
1787
+ }));
1788
+ console.log();
1789
+ const processor = await this.createNewProcessor();
1790
+ console.log('PROCESSING ENV RESULT', productTag, tagsData);
1791
+ await processor.updateHealthcheckOnProcessor(productTag, tagsData);
1792
+ }
1793
+ }, {
1794
+ connection: this.redisClient,
1795
+ });
1796
+ // Attach error listeners
1797
+ this.jobsWorker.on('failed', (job, err) => {
1798
+ console.error(`Job ${job === null || job === void 0 ? void 0 : job.id} failed:`, err);
1799
+ });
1800
+ this.healthCheckWorker.on('failed', (job, err) => {
1801
+ console.error(`Health check ${job === null || job === void 0 ? void 0 : job.id} failed:`, err);
1802
+ });
1803
+ }
1804
+ /**
1805
+ * Schedules all healthcheck jobs for all products and environments.
1806
+ */
1807
+ async scheduleAllHealthcheckJobs() {
1808
+ // Fetch all products (or use this.products if already loaded)
1809
+ const products = this.products || await this.productsApi.fetchWorkspaceProducts(enums_1.PublicStates.ALL, {
1810
+ token: this.token,
1811
+ public_key: this.public_key,
1812
+ user_id: this.user_id,
1813
+ workspace_id: this.workspace_id,
1814
+ });
1815
+ for (const product of products) {
1816
+ const healthchecks = product.healthchecks || [];
1817
+ const privateKey = product.private_key;
1818
+ for (const healthcheck of healthchecks) {
1819
+ for (const env of healthcheck.envs) {
1820
+ let decryptedInput = env.input;
1821
+ if (typeof decryptedInput === 'string') {
1822
+ decryptedInput = JSON.parse((0, processor_utils_1.decrypt)(decryptedInput, privateKey));
1823
+ }
1824
+ const jobData = {
1825
+ healthcheck: healthcheck.tag,
1826
+ env: env.slug,
1827
+ product: product.tag,
1828
+ app: healthcheck.app,
1829
+ input: decryptedInput,
1830
+ event: healthcheck.event,
1831
+ retries: healthcheck.retries || 0,
1832
+ };
1833
+ const jobId = `healthcheck-exec-${healthcheck.tag}-${env.slug}`;
1834
+ await this.scheduleHealthcheckJob(jobId, jobData, healthcheck.interval);
1835
+ }
1836
+ }
1837
+ }
1838
+ }
1839
+ /**
1840
+ * Schedules a single healthcheck job with the given interval (ms).
1841
+ * If interval is not provided, defaults to 60s.
1842
+ */
1843
+ async scheduleHealthcheckJob(jobId, jobData, interval) {
1844
+ console.log("JOBBERMAN", { jobId, jobData, interval });
1845
+ const job = await this.healthCheckQueue.getJob(jobId);
1846
+ if (job) {
1847
+ await job.remove();
1848
+ }
1849
+ const repeat = interval ? { every: interval } : { every: 60000 };
1850
+ await this.healthCheckQueue.add('healthchecks-updater', jobData, { repeat, jobId });
806
1851
  }
1852
+ /**
1853
+ * Sets the authentication token for API requests.
1854
+ * @param {string} token - The authentication token.
1855
+ */
807
1856
  setToken(token) {
808
1857
  this.token = token;
809
1858
  }
1859
+ /**
1860
+ * Sets the public key for API requests.
1861
+ * @param {string} public_key - The public key.
1862
+ */
810
1863
  setPublicKey(public_key) {
811
1864
  this.public_key = public_key;
812
1865
  }
@@ -832,6 +1885,26 @@ class Ductape {
832
1885
  throw new Error(`app init required`);
833
1886
  }
834
1887
  }
1888
+ /**
1889
+ * Database operations for querying, inserting, updating, and managing databases.
1890
+ * Provides unified interface for SQL and NoSQL databases.
1891
+ */
1892
+ get database() {
1893
+ if (!this.databaseService) {
1894
+ this.databaseService = this.createNewDatabaseService();
1895
+ }
1896
+ return this.databaseService;
1897
+ }
1898
+ /**
1899
+ * Graph database operations for Neo4j, AWS Neptune, ArangoDB, and Memgraph.
1900
+ * Provides unified interface for graph database CRUD, traversals, and path finding.
1901
+ */
1902
+ get graph() {
1903
+ if (!this.graphService) {
1904
+ this.graphService = this.createNewGraphService();
1905
+ }
1906
+ return this.graphService;
1907
+ }
835
1908
  async initUserAuth(subCheck = true) {
836
1909
  this.token = null;
837
1910
  this.public_key = null;
@@ -860,6 +1933,24 @@ class Ductape {
860
1933
  app_id,
861
1934
  });
862
1935
  }
1936
+ createNewDatabaseService() {
1937
+ return new database_service_1.DatabaseService({
1938
+ workspace_id: this.workspace_id,
1939
+ user_id: this.user_id,
1940
+ public_key: this.public_key,
1941
+ token: this.token,
1942
+ env_type: this.environment,
1943
+ });
1944
+ }
1945
+ createNewGraphService() {
1946
+ return new graph_service_1.GraphService({
1947
+ workspace_id: this.workspace_id,
1948
+ user_id: this.user_id,
1949
+ public_key: this.public_key,
1950
+ token: this.token,
1951
+ env_type: this.environment,
1952
+ });
1953
+ }
863
1954
  createNewProductBuilder() {
864
1955
  return new products_service_1.default({
865
1956
  workspace_id: this.workspace_id,
@@ -878,6 +1969,8 @@ class Ductape {
878
1969
  user_id: this.user_id,
879
1970
  token: this.token,
880
1971
  env_type: this.environment,
1972
+ redis_client: this.redisClient,
1973
+ queues: { health: this.healthCheckQueue, jobs: this.jobsQueue }
881
1974
  });
882
1975
  }
883
1976
  createNewImporter() {
@@ -996,6 +2089,13 @@ class Ductape {
996
2089
  throw error;
997
2090
  }
998
2091
  }
2092
+ /**
2093
+ * Fetches the latest healthcheck status for a product/env from Redis cache via processor service.
2094
+ */
2095
+ async getHealthcheckStatus(productTag, envSlug) {
2096
+ const processor = await this.createNewProcessor();
2097
+ return processor.getHealthcheckStatusFromCache(productTag, envSlug);
2098
+ }
999
2099
  }
1000
2100
  exports.default = Ductape;
1001
2101
  //# sourceMappingURL=index.js.map