@ductape/sdk 0.0.4-v2 → 0.0.4-v21

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 (163) hide show
  1. package/dist/api/services/appApi.service.d.ts +2 -2
  2. package/dist/api/services/appApi.service.js +1 -2
  3. package/dist/api/services/appApi.service.js.map +1 -1
  4. package/dist/api/services/pricingApi.service.d.ts +10 -0
  5. package/dist/api/services/pricingApi.service.js +34 -0
  6. package/dist/api/services/pricingApi.service.js.map +1 -0
  7. package/dist/api/services/processorApi.service.d.ts +12 -2
  8. package/dist/api/services/processorApi.service.js +12 -2
  9. package/dist/api/services/processorApi.service.js.map +1 -1
  10. package/dist/api/services/productsApi.service.d.ts +7 -1
  11. package/dist/api/services/productsApi.service.js +33 -0
  12. package/dist/api/services/productsApi.service.js.map +1 -1
  13. package/dist/api/services/userApi.service.js +1 -0
  14. package/dist/api/services/userApi.service.js.map +1 -1
  15. package/dist/api/services/workspaceApi.service.js +1 -0
  16. package/dist/api/services/workspaceApi.service.js.map +1 -1
  17. package/dist/api/urls.d.ts +7 -1
  18. package/dist/api/urls.js +13 -2
  19. package/dist/api/urls.js.map +1 -1
  20. package/dist/api/utils/strings.utils.d.ts +2 -0
  21. package/dist/api/utils/strings.utils.js +14 -0
  22. package/dist/api/utils/strings.utils.js.map +1 -1
  23. package/dist/apps/services/app.service.js +7 -5
  24. package/dist/apps/services/app.service.js.map +1 -1
  25. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.d.ts +1 -1
  26. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js +34 -1
  27. package/dist/apps/validators/joi-validators/update.appActionResponse.validator.js.map +1 -1
  28. package/dist/clients/apps.client.js +1 -1
  29. package/dist/clients/apps.client.js.map +1 -1
  30. package/dist/clients/pricing.client.d.ts +3 -0
  31. package/dist/clients/pricing.client.js +33 -0
  32. package/dist/clients/pricing.client.js.map +1 -0
  33. package/dist/imports/imports.service.d.ts +3 -3
  34. package/dist/imports/imports.service.js +7 -7
  35. package/dist/imports/imports.service.js.map +1 -1
  36. package/dist/imports/imports.types.d.ts +8 -0
  37. package/dist/imports/repos/openApi.repo.d.ts +1 -2
  38. package/dist/imports/repos/openApi.repo.js +43 -71
  39. package/dist/imports/repos/openApi.repo.js.map +1 -1
  40. package/dist/imports/repos/postmanV21.repo.d.ts +1 -1
  41. package/dist/imports/repos/postmanV21.repo.js +29 -2
  42. package/dist/imports/repos/postmanV21.repo.js.map +1 -1
  43. package/dist/index.d.ts +953 -46
  44. package/dist/index.js +918 -81
  45. package/dist/index.js.map +1 -1
  46. package/dist/inputs/inputs.service.js +2 -2
  47. package/dist/inputs/inputs.service.js.map +1 -1
  48. package/dist/inputs/utils/inputs.utils.create.js +1 -1
  49. package/dist/inputs/utils/inputs.utils.create.js.map +1 -1
  50. package/dist/logs/logs.service.js +1 -0
  51. package/dist/logs/logs.service.js.map +1 -1
  52. package/dist/logs/logs.types.d.ts +5 -0
  53. package/dist/logs/logs.types.js.map +1 -1
  54. package/dist/parsers/index.d.ts +3 -0
  55. package/dist/parsers/index.js +27 -0
  56. package/dist/parsers/index.js.map +1 -0
  57. package/dist/parsers/pipelines/postman.pipelines.d.ts +15 -0
  58. package/dist/parsers/pipelines/postman.pipelines.js +103 -0
  59. package/dist/parsers/pipelines/postman.pipelines.js.map +1 -0
  60. package/dist/parsers/types/postman.types.d.ts +200 -0
  61. package/dist/parsers/types/postman.types.js +3 -0
  62. package/dist/parsers/types/postman.types.js.map +1 -0
  63. package/dist/parsers/utils/postman.utils.d.ts +12 -0
  64. package/dist/parsers/utils/postman.utils.js +116 -0
  65. package/dist/parsers/utils/postman.utils.js.map +1 -0
  66. package/dist/parsers/validators/postman-auth.validators.d.ts +10 -0
  67. package/dist/parsers/validators/postman-auth.validators.js +127 -0
  68. package/dist/parsers/validators/postman-auth.validators.js.map +1 -0
  69. package/dist/parsers/validators/postman-request.validators.d.ts +13 -0
  70. package/dist/parsers/validators/postman-request.validators.js +139 -0
  71. package/dist/parsers/validators/postman-request.validators.js.map +1 -0
  72. package/dist/parsers/validators/postman-response.validators.d.ts +13 -0
  73. package/dist/parsers/validators/postman-response.validators.js +150 -0
  74. package/dist/parsers/validators/postman-response.validators.js.map +1 -0
  75. package/dist/parsers/validators/postman-variable.validators.d.ts +14 -0
  76. package/dist/parsers/validators/postman-variable.validators.js +163 -0
  77. package/dist/parsers/validators/postman-variable.validators.js.map +1 -0
  78. package/dist/pricing/pricing.repo.d.ts +0 -0
  79. package/dist/pricing/pricing.repo.js +1 -0
  80. package/dist/pricing/pricing.repo.js.map +1 -0
  81. package/dist/pricing/pricing.service.d.ts +24 -0
  82. package/dist/pricing/pricing.service.js +51 -0
  83. package/dist/pricing/pricing.service.js.map +1 -0
  84. package/dist/pricing/pricing.types.d.ts +76 -0
  85. package/dist/pricing/pricing.types.js +21 -0
  86. package/dist/pricing/pricing.types.js.map +1 -0
  87. package/dist/pricing/utils/string.utils.d.ts +1 -0
  88. package/dist/pricing/utils/string.utils.js +9 -0
  89. package/dist/pricing/utils/string.utils.js.map +1 -0
  90. package/dist/processor/repos/sms.repo.d.ts +4 -4
  91. package/dist/processor/repos/sms.repo.js +23 -10
  92. package/dist/processor/repos/sms.repo.js.map +1 -1
  93. package/dist/processor/services/processor.service.d.ts +36 -5
  94. package/dist/processor/services/processor.service.js +556 -201
  95. package/dist/processor/services/processor.service.js.map +1 -1
  96. package/dist/processor/services/request.service.d.ts +36 -0
  97. package/dist/processor/services/request.service.js +304 -0
  98. package/dist/processor/services/request.service.js.map +1 -0
  99. package/dist/processor/types/request.types.d.ts +14 -0
  100. package/dist/processor/types/request.types.js +3 -0
  101. package/dist/processor/types/request.types.js.map +1 -0
  102. package/dist/processor/utils/processor.utils.d.ts +3 -0
  103. package/dist/processor/utils/processor.utils.js +88 -5
  104. package/dist/processor/utils/processor.utils.js.map +1 -1
  105. package/dist/processor/utils/request.utils.d.ts +20 -0
  106. package/dist/processor/utils/request.utils.js +113 -0
  107. package/dist/processor/utils/request.utils.js.map +1 -0
  108. package/dist/processor/utils/storage.util.js +54 -40
  109. package/dist/processor/utils/storage.util.js.map +1 -1
  110. package/dist/products/services/products.service.d.ts +21 -6
  111. package/dist/products/services/products.service.js +286 -44
  112. package/dist/products/services/products.service.js.map +1 -1
  113. package/dist/products/utils/string.utils.d.ts +1 -1
  114. package/dist/products/utils/string.utils.js +14 -2
  115. package/dist/products/utils/string.utils.js.map +1 -1
  116. package/dist/products/validators/index.d.ts +2 -1
  117. package/dist/products/validators/index.js +3 -1
  118. package/dist/products/validators/index.js.map +1 -1
  119. package/dist/products/validators/joi-validators/create.productEnv.validator.js +1 -0
  120. package/dist/products/validators/joi-validators/create.productEnv.validator.js.map +1 -1
  121. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.d.ts +4 -0
  122. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js +58 -0
  123. package/dist/products/validators/joi-validators/create.productHealthcheck.validator.js.map +1 -0
  124. package/dist/products/validators/joi-validators/create.userAuth.validator.js +1 -0
  125. package/dist/products/validators/joi-validators/create.userAuth.validator.js.map +1 -1
  126. package/dist/products/validators/joi-validators/update.dataValue.validator.js +1 -0
  127. package/dist/products/validators/joi-validators/update.dataValue.validator.js.map +1 -1
  128. package/dist/products/validators/joi-validators/update.productEnv.validator.js +3 -0
  129. package/dist/products/validators/joi-validators/update.productEnv.validator.js.map +1 -1
  130. package/dist/products/validators/joi-validators/update.userAuth.validator.js +1 -0
  131. package/dist/products/validators/joi-validators/update.userAuth.validator.js.map +1 -1
  132. package/dist/test/test.health.d.ts +1 -0
  133. package/dist/test/test.health.js +49 -0
  134. package/dist/test/test.health.js.map +1 -0
  135. package/dist/test/test.import.js +51 -4
  136. package/dist/test/test.import.js.map +1 -1
  137. package/dist/test/test.imports.js +22 -7
  138. package/dist/test/test.imports.js.map +1 -1
  139. package/dist/test/test.processor.js +32 -115
  140. package/dist/test/test.processor.js.map +1 -1
  141. package/dist/test/test.products.d.ts +1 -0
  142. package/dist/test/test.products.js +49 -0
  143. package/dist/test/test.products.js.map +1 -0
  144. package/dist/types/appBuilder.types.d.ts +1 -11
  145. package/dist/types/enums.d.ts +3 -1
  146. package/dist/types/enums.js +2 -0
  147. package/dist/types/enums.js.map +1 -1
  148. package/dist/types/index.types.d.ts +4 -0
  149. package/dist/types/pricing.types.d.ts +4 -0
  150. package/dist/types/pricing.types.js +3 -0
  151. package/dist/types/pricing.types.js.map +1 -0
  152. package/dist/types/processor.types.d.ts +68 -9
  153. package/dist/types/processor.types.js.map +1 -1
  154. package/dist/types/productsBuilder.types.d.ts +59 -3
  155. package/dist/types/productsBuilder.types.js +9 -1
  156. package/dist/types/productsBuilder.types.js.map +1 -1
  157. package/dist/types/request-tracker.interface.d.ts +0 -0
  158. package/dist/types/request-tracker.interface.js +1 -0
  159. package/dist/types/request-tracker.interface.js.map +1 -0
  160. package/dist/utils/constants.d.ts +1 -0
  161. package/dist/utils/constants.js +5 -0
  162. package/dist/utils/constants.js.map +1 -0
  163. package/package.json +13 -1
package/dist/index.js CHANGED
@@ -44,38 +44,63 @@ 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
46
  const index_types_1 = require("./types/index.types");
47
+ const enums_1 = require("./types/enums");
47
48
  const productsApi_service_1 = require("./api/services/productsApi.service");
48
49
  const imports_service_1 = __importDefault(require("./imports/imports.service"));
49
50
  const processor_service_1 = __importDefault(require("./processor/services/processor.service"));
50
51
  const logs_service_1 = __importDefault(require("./logs/logs.service"));
51
52
  const utils_1 = require("./utils");
52
53
  const mime = __importStar(require("mime-types"));
54
+ const processor_utils_1 = require("./processor/utils/processor.utils");
53
55
  class Ductape {
54
56
  async loadRedis() {
55
57
  if (typeof window !== 'undefined') {
56
58
  throw new Error("RedisService can only be used in a server environment.");
57
59
  }
58
- const redis = await Promise.resolve().then(() => __importStar(require('redis')));
59
- return redis;
60
+ return await Promise.resolve().then(() => __importStar(require('ioredis')));
60
61
  }
61
62
  constructor({ workspace_id, private_key, user_id, env_type, redis_url }) {
63
+ /**
64
+ * Product-related operations for managing products, sessions, apps, quotas, and fallbacks.
65
+ */
62
66
  this.product = {
67
+ /**
68
+ * Creates a new product.
69
+ * @param {IProduct} data - The product data.
70
+ * @returns {Promise<void>} Resolves when the product is created. Throws on error.
71
+ */
63
72
  create: async (data) => {
64
73
  await this.initProduct();
65
74
  return this.productBuilder.createProduct(data);
66
75
  },
76
+ /**
77
+ * Fetches a product by tag.
78
+ * @param {string} tag - The product tag.
79
+ * @returns {Promise<IProduct|null>} The fetched product, or null if not found.
80
+ */
67
81
  fetch: async (tag) => {
68
82
  await this.initProduct();
69
83
  await this.productBuilder.initializeProductByTag(tag);
70
84
  this.productInit = false;
71
85
  return this.productBuilder.fetchProduct();
72
86
  },
87
+ /**
88
+ * Updates a product by tag.
89
+ * @param {string} tag - The product tag.
90
+ * @param {Partial<IProduct>} data - The product data to update.
91
+ * @returns {Promise<void>} Resolves when the product is updated. Throws on error.
92
+ */
73
93
  update: async (tag, data) => {
74
94
  await this.initProduct();
75
95
  await this.productBuilder.initializeProductByTag(tag);
76
96
  this.productInit = false;
77
97
  return this.productBuilder.updateProduct(data);
78
98
  },
99
+ /**
100
+ * Initializes a product by tag.
101
+ * @param {string} productTag - The product tag.
102
+ * @returns {Promise<void>} Resolves when initialization is complete. Throws on error.
103
+ */
79
104
  init: async (productTag) => {
80
105
  try {
81
106
  console.log(`Product initialized with tag: ${productTag}`);
@@ -89,181 +114,408 @@ class Ductape {
89
114
  }
90
115
  },
91
116
  sessions: {
92
- create: (payload) => {
117
+ /**
118
+ * Creates a new product session.
119
+ * @param {IProductSession} payload - The session payload.
120
+ * @returns {Promise<void>} Resolves when the session is created. Throws on error.
121
+ */
122
+ create: async (payload) => {
93
123
  this.checkProductInit();
94
124
  return this.productBuilder.createSession(payload);
95
125
  },
96
- update: (tag, payload) => {
126
+ /**
127
+ * Updates a product session by tag.
128
+ * @param {string} tag - The session tag.
129
+ * @param {Partial<IProductSession>} payload - The session data to update.
130
+ * @returns {Promise<void>} Resolves when the session is updated. Throws on error.
131
+ */
132
+ update: async (tag, payload) => {
97
133
  this.checkProductInit();
98
134
  return this.productBuilder.updateSession(tag, payload);
99
135
  },
136
+ /**
137
+ * Fetches all product sessions.
138
+ * @returns {IProductSession[]} The list of sessions.
139
+ */
100
140
  fetchAll: () => {
101
141
  this.checkProductInit();
102
142
  return this.productBuilder.fetchSessions();
103
143
  },
144
+ /**
145
+ * Fetches a product session by tag.
146
+ * @param {string} tag - The session tag.
147
+ * @returns {IProductSession|null} The fetched session, or null if not found.
148
+ */
104
149
  fetch: (tag) => {
105
150
  this.checkProductInit();
106
151
  return this.productBuilder.fetchSession(tag);
152
+ },
153
+ /**
154
+ * Fetches users for a session.
155
+ * @param {IFetchUsersPayload} data - The user fetch payload.
156
+ * @returns {Promise<any[]>} The users for the session.
157
+ */
158
+ users: (data) => {
159
+ this.checkProductInit();
160
+ return this.productBuilder.fetchSessionUsers(data);
107
161
  }
108
162
  },
109
163
  apps: {
164
+ /**
165
+ * Connects an app to a product by app tag.
166
+ * @param {string} appTag - The app tag.
167
+ * @returns {Promise<IAppAccess>} The result of the connection.
168
+ */
110
169
  connect: async (appTag) => {
111
170
  this.checkProductInit();
112
171
  return this.productBuilder.createAppAccessTag(appTag);
113
172
  },
173
+ /**
174
+ * Adds an app to a product.
175
+ * @param {IProductApp} app - The app data.
176
+ * @returns {Promise<void>} Resolves when the app is added. Throws on error.
177
+ */
114
178
  add: async (app) => {
115
179
  this.checkProductInit();
116
180
  return this.productBuilder.addApp(app);
117
181
  },
182
+ /**
183
+ * Fetches all apps for a product.
184
+ * @returns {IProductApp[]} The list of apps.
185
+ */
118
186
  fetchAll: async () => {
119
187
  this.checkProductInit();
120
188
  return this.productBuilder.fetchApps();
121
189
  },
190
+ /**
191
+ * Fetches an app by tag.
192
+ * @param {string} tag - The app tag.
193
+ * @returns {IProductApp|null} The fetched app, or null if not found.
194
+ */
122
195
  fetch: async (tag) => {
123
196
  this.checkProductInit();
124
197
  return this.productBuilder.fetchApp(tag);
125
198
  },
199
+ /**
200
+ * Updates an app by access tag.
201
+ * @param {string} accessTag - The app access tag.
202
+ * @param {Partial<IProductApp>} data - The app data to update.
203
+ * @returns {Promise<void>} Resolves when the app is updated. Throws on error.
204
+ */
126
205
  update: async (accessTag, data) => {
127
206
  this.checkProductInit();
128
207
  return this.productBuilder.updateApp(accessTag, data);
129
208
  },
130
209
  webhooks: {
210
+ /**
211
+ * Fetches all webhooks for an app by access tag.
212
+ * @param {string} accessTag - The app access tag.
213
+ * @returns {Promise<IAppWebhook[]>} The list of webhooks.
214
+ */
131
215
  fetchAll: async (accessTag) => {
132
216
  this.checkProductInit();
133
217
  return this.productBuilder.fetchAppWebhooks(accessTag);
134
218
  },
219
+ /**
220
+ * Enables a webhook for an app.
221
+ * @param {IRegisterWebhook} data - The webhook registration data.
222
+ * @returns {Promise<void>} Resolves when the webhook is enabled. Throws on error.
223
+ */
135
224
  enable: async (data) => {
136
225
  const processorService = await this.createNewProcessor();
137
226
  return processorService.registerWebhook(data);
138
227
  },
228
+ /**
229
+ * Generates a webhook link for an app.
230
+ * @param {IGenerateWebhookLink} data - The webhook link data.
231
+ * @returns {Promise<string>} The generated webhook link.
232
+ */
139
233
  generateLink: async (data) => {
140
234
  const processorService = await this.createNewProcessor();
141
235
  return processorService.generateWebhookLink(data);
142
236
  },
143
237
  },
238
+ health: {
239
+ /**
240
+ * Creates a health check for an app.
241
+ * @param {Partial<IProductAppHealth>} data - The health check data.
242
+ * @returns {Promise<void>} Resolves when the health check is created. Throws on error.
243
+ */
244
+ create: async (data) => {
245
+ await this.checkProductInit();
246
+ return await this.productBuilder.createHealthcheck(data);
247
+ },
248
+ /**
249
+ * Updates a health check by tag.
250
+ * @param {string} tag - The health check tag.
251
+ * @param {Partial<IProductAppHealth>} data - The health check data to update.
252
+ * @returns {Promise<void>} Resolves when the health check is updated. Throws on error.
253
+ */
254
+ update: async (tag, data) => {
255
+ this.checkProductInit();
256
+ return this.productBuilder.updateHealthcheck(tag, data);
257
+ },
258
+ /**
259
+ * Fetches a health check by access tag and tag.
260
+ * @param {string} access_tag - The app access tag.
261
+ * @param {string} tag - The health check tag.
262
+ * @returns {Promise<IProductAppHealth|null>} The fetched health check, or null if not found.
263
+ */
264
+ fetch: async (access_tag, tag) => {
265
+ this.checkProductInit();
266
+ return this.productBuilder.fetchHealthcheck(access_tag, tag);
267
+ },
268
+ /**
269
+ * Fetches all health checks for an app by access tag.
270
+ * @param {string} access_tag - The app access tag.
271
+ * @returns {Promise<IProductAppHealth[]>} The list of health checks.
272
+ */
273
+ fetchAll: async (access_tag) => {
274
+ this.checkProductInit();
275
+ return this.productBuilder.fetchHealthchecks(access_tag);
276
+ },
277
+ }
144
278
  },
279
+ /**
280
+ * Creates a quota for a product.
281
+ * @param {Partial<IProductQuota>} data - The quota data.
282
+ * @returns {Promise<void>} Resolves when the quota is created. Throws on error.
283
+ */
145
284
  quota: {
146
285
  create: async (data) => {
147
286
  await this.initProduct();
148
287
  return this.productBuilder.createQuota(data);
149
288
  },
289
+ /**
290
+ * Fetches a quota by tag.
291
+ * @param {string} tag - The quota tag.
292
+ * @returns {IProductQuota|null} The fetched quota, or null if not found.
293
+ */
150
294
  fetch: (tag) => {
151
295
  return this.productBuilder.fetchQuota(tag);
152
296
  },
297
+ /**
298
+ * Fetches all quotas for a product.
299
+ * @returns {IProductQuota[]} The list of quotas.
300
+ */
153
301
  fetchAll: () => {
154
302
  return this.productBuilder.fetchQuotas();
155
303
  },
304
+ /**
305
+ * Updates a quota by tag.
306
+ * @param {string} tag - The quota tag.
307
+ * @param {Partial<IProductQuota>} data - The quota data to update.
308
+ * @returns {Promise<void>} Resolves when the quota is updated. Throws on error.
309
+ */
156
310
  update: async (tag, data) => {
157
311
  await this.initProduct();
158
312
  return this.productBuilder.updateQuota(tag, data);
159
313
  },
160
314
  },
315
+ /**
316
+ * Creates a fallback for a product.
317
+ * @param {Partial<IProductFallback>} data - The fallback data.
318
+ * @returns {Promise<void>} Resolves when the fallback is created. Throws on error.
319
+ */
161
320
  fallback: {
162
321
  create: async (data) => {
163
322
  this.checkProductInit();
164
323
  return this.productBuilder.createFallback(data);
165
324
  },
325
+ /**
326
+ * Fetches a fallback by tag.
327
+ * @param {string} tag - The fallback tag.
328
+ * @returns {IProductFallback|null} The fetched fallback, or null if not found.
329
+ */
166
330
  fetch: (tag) => {
167
331
  this.checkProductInit();
168
332
  return this.productBuilder.fetchFallback(tag);
169
333
  },
334
+ /**
335
+ * Fetches all fallbacks for a product.
336
+ * @returns {IProductFallback[]} The list of fallbacks.
337
+ */
170
338
  fetchAll: () => {
171
339
  this.checkProductInit();
172
340
  return this.productBuilder.fetchFallbacks();
173
341
  },
342
+ /**
343
+ * Updates a fallback by tag.
344
+ * @param {string} tag - The fallback tag.
345
+ * @param {Partial<IProductFallback>} data - The fallback data to update.
346
+ * @returns {Promise<void>} Resolves when the fallback is updated. Throws on error.
347
+ */
174
348
  update: async (tag, data) => {
175
349
  this.checkProductInit();
176
350
  return this.productBuilder.updateFallback(tag, data);
177
351
  },
178
352
  },
353
+ /**
354
+ * Updates data validation for a product.
355
+ * @param {string} tag - The product tag.
356
+ * @param {Partial<IParsedSample>} update - The update data.
357
+ * @returns {Promise<void>} Resolves when the validation is updated. Throws on error.
358
+ */
179
359
  updateValidation: async (tag, update) => {
180
360
  this.checkProductInit();
181
361
  return this.productBuilder.updateDataValidation(tag, update);
182
362
  },
183
363
  environments: {
364
+ /**
365
+ * Creates an environment for a product.
366
+ * @param {IProductEnv} data - The environment data.
367
+ * @returns {Promise<void>} Resolves when the environment is created. Throws on error.
368
+ */
184
369
  create: async (data) => {
185
370
  this.checkProductInit();
186
371
  return this.productBuilder.createEnv(data);
187
372
  },
373
+ /**
374
+ * Fetches all environments for a product.
375
+ * @returns {IAppEnv[]} The list of environments.
376
+ */
188
377
  fetchAll: () => {
189
378
  this.checkProductInit();
190
379
  return this.productBuilder.fetchEnvs();
191
380
  },
381
+ /**
382
+ * Fetches an environment by slug.
383
+ * @param {string} slug - The environment slug.
384
+ * @returns {IAppEnv|null} The fetched environment, or null if not found.
385
+ */
192
386
  fetch: (slug) => {
193
387
  this.checkProductInit();
194
388
  return this.productBuilder.fetchEnv(slug);
195
389
  },
390
+ /**
391
+ * Updates an environment by slug.
392
+ * @param {string} slug - The environment slug.
393
+ * @param {Partial<IProductEnv>} data - The environment data to update.
394
+ * @returns {Promise<void>} Resolves when the environment is updated. Throws on error.
395
+ */
196
396
  update: async (slug, data) => {
197
397
  this.checkProductInit();
198
398
  return this.productBuilder.updateEnv(slug, data);
199
399
  },
200
400
  },
201
401
  storage: {
402
+ /**
403
+ * Creates a storage for a product.
404
+ * @param {IProductStorage} data - The storage data.
405
+ * @returns {Promise<void>} Resolves when the storage is created. Throws on error.
406
+ */
202
407
  create: async (data) => {
203
408
  this.checkProductInit();
204
409
  return this.productBuilder.createStorage(data);
205
410
  },
411
+ /**
412
+ * Fetches all storages for a product.
413
+ * @returns {IProductStorage[]} The list of storages.
414
+ */
206
415
  fetchAll: () => {
207
416
  this.checkProductInit();
208
417
  return this.productBuilder.fetchStorages();
209
418
  },
419
+ /**
420
+ * Fetches a storage by tag.
421
+ * @param {string} tag - The storage tag.
422
+ * @returns {IProductStorage|null} The fetched storage, or null if not found.
423
+ */
210
424
  fetch: (tag) => {
211
425
  this.checkProductInit();
212
426
  return this.productBuilder.fetchStorage(tag);
213
427
  },
428
+ /**
429
+ * Updates a storage by tag.
430
+ * @param {string} tag - The storage tag.
431
+ * @param {Partial<IProductStorage>} data - The storage data to update.
432
+ * @returns {Promise<void>} Resolves when the storage is updated. Throws on error.
433
+ */
214
434
  update: async (tag, data) => {
215
435
  this.checkProductInit();
216
436
  return this.productBuilder.updateStorage(tag, data);
217
437
  },
438
+ /**
439
+ * Fetches storage files for a product.
440
+ * @param {IFetchFilesPayload} data - The fetch files payload.
441
+ * @returns {Promise<void>} Resolves when the storage files are fetched. Throws on error.
442
+ */
443
+ files: async (data) => {
444
+ this.checkProductInit();
445
+ return this.productBuilder.fetchStorageFiles(data);
446
+ }
218
447
  },
219
- /*cloudFunctions: {
220
- create: async (data: IProductFunction) => {
221
- this.checkProductInit();
222
- return this.productBuilder.createFunction(data);
223
- },
224
- fetchAll: () => {
225
- this.checkProductInit();
226
- return this.productBuilder.fetchFunctions();
227
- },
228
- fetch: (tag: string) => {
229
- this.checkProductInit();
230
- return this.productBuilder.fetchFunction(tag);
231
- },
232
- update: async (tag: string, data: Partial<IProductFunction>) => {
233
- this.checkProductInit();
234
- return this.productBuilder.updateFunction(tag, data);
235
- },
236
- },*/
237
448
  messageBrokers: {
449
+ /**
450
+ * Creates a message broker for a product.
451
+ * @param {Partial<IProductMessageBroker>} data - The message broker data.
452
+ * @returns {Promise<void>} Resolves when the message broker is created. Throws on error.
453
+ */
238
454
  create: async (data) => {
239
455
  this.checkProductInit();
240
456
  return this.productBuilder.createMessageBroker(data);
241
457
  },
458
+ /**
459
+ * Fetches all message brokers for a product.
460
+ * @returns {IProductMessageBroker[]} The list of message brokers.
461
+ */
242
462
  fetchAll: () => {
243
463
  this.checkProductInit();
244
464
  return this.productBuilder.fetchMessageBrokers();
245
465
  },
466
+ /**
467
+ * Fetches a message broker by tag.
468
+ * @param {string} tag - The message broker tag.
469
+ * @returns {IProductMessageBroker|null} The fetched message broker, or null if not found.
470
+ */
246
471
  fetch: (tag) => {
247
472
  this.checkProductInit();
248
473
  return this.productBuilder.fetchMessageBroker(tag);
249
474
  },
475
+ /**
476
+ * Updates a message broker by tag.
477
+ * @param {string} tag - The message broker tag.
478
+ * @param {Partial<IProductMessageBroker>} data - The message broker data to update.
479
+ * @returns {Promise<void>} Resolves when the message broker is updated. Throws on error.
480
+ */
250
481
  update: async (tag, data) => {
251
482
  this.checkProductInit();
252
483
  return this.productBuilder.updateMessageBroker(tag, data);
253
484
  },
254
485
  topics: {
486
+ /**
487
+ * Creates a message broker topic for a product.
488
+ * @param {IProductMessageBrokerTopic} data - The message broker topic data.
489
+ * @returns {Promise<void>} Resolves when the message broker topic is created. Throws on error.
490
+ */
255
491
  create: async (data) => {
256
492
  this.checkProductInit();
257
493
  return this.productBuilder.createMessageBrokerTopic(data);
258
494
  },
495
+ /**
496
+ * Fetches all message broker topics for a message broker by tag.
497
+ * @param {string} messageBrokerTag - The message broker tag.
498
+ * @returns {IProductMessageBrokerTopic[]} The list of message broker topics.
499
+ */
259
500
  fetchAll: (messageBrokerTag) => {
260
501
  this.checkProductInit();
261
502
  return this.productBuilder.fetchMessageBrokerTopics(messageBrokerTag);
262
503
  },
504
+ /**
505
+ * Fetches a message broker topic by tag.
506
+ * @param {string} tag - The message broker topic tag.
507
+ * @returns {IProductMessageBrokerTopic|null} The fetched message broker topic, or null if not found.
508
+ */
263
509
  fetch: (tag) => {
264
510
  this.checkProductInit();
265
511
  return this.productBuilder.fetchMessageBrokerTopic(tag);
266
512
  },
513
+ /**
514
+ * Updates a message broker topic by tag.
515
+ * @param {string} tag - The message broker topic tag.
516
+ * @param {Partial<IProductMessageBrokerTopic>} data - The message broker topic data to update.
517
+ * @returns {Promise<void>} Resolves when the message broker topic is updated. Throws on error.
518
+ */
267
519
  update: (tag, data) => {
268
520
  this.checkProductInit();
269
521
  return this.productBuilder.updateMessageBrokerTopic(Object.assign(Object.assign({}, data), { tag }));
@@ -271,35 +523,76 @@ class Ductape {
271
523
  },
272
524
  },
273
525
  notifications: {
526
+ /**
527
+ * Creates a notification for a product.
528
+ * @param {IProductNotification} data - The notification data.
529
+ * @returns {Promise<void>} Resolves when the notification is created. Throws on error.
530
+ */
274
531
  create: async (data) => {
275
532
  this.checkProductInit();
276
533
  return this.productBuilder.createNotification(data);
277
534
  },
535
+ /**
536
+ * Fetches all notifications for a product.
537
+ * @returns {IProductNotification[]} The list of notifications.
538
+ */
278
539
  fetchAll: () => {
279
540
  this.checkProductInit();
280
541
  return this.productBuilder.fetchNotifications();
281
542
  },
543
+ /**
544
+ * Fetches a notification by tag.
545
+ * @param {string} tag - The notification tag.
546
+ * @returns {IProductNotification|null} The fetched notification, or null if not found.
547
+ */
282
548
  fetch: (tag) => {
283
549
  this.checkProductInit();
284
550
  return this.productBuilder.fetchNotification(tag);
285
551
  },
552
+ /**
553
+ * Updates a notification by tag.
554
+ * @param {string} tag - The notification tag.
555
+ * @param {Partial<IProductNotification>} data - The notification data to update.
556
+ * @returns {Promise<void>} Resolves when the notification is updated. Throws on error.
557
+ */
286
558
  update: async (tag, data) => {
287
559
  this.checkProductInit();
288
560
  return this.productBuilder.updateNotification(tag, data);
289
561
  },
290
562
  messages: {
563
+ /**
564
+ * Creates a notification message for a product.
565
+ * @param {IProductNotificationTemplate} data - The notification message data.
566
+ * @returns {Promise<void>} Resolves when the notification message is created. Throws on error.
567
+ */
291
568
  create: async (data) => {
292
569
  this.checkProductInit();
293
570
  return this.productBuilder.createNotificationMessage(data);
294
571
  },
572
+ /**
573
+ * Fetches all notification messages for a notification by tag.
574
+ * @param {string} notificationTag - The notification tag.
575
+ * @returns {IProductNotificationTemplate[]} The list of notification messages.
576
+ */
295
577
  fetchAll: (notificationTag) => {
296
578
  this.checkProductInit();
297
579
  return this.productBuilder.fetchNotificationMessages(notificationTag);
298
580
  },
581
+ /**
582
+ * Fetches a notification message by tag.
583
+ * @param {string} tag - The notification message tag.
584
+ * @returns {IProductNotificationTemplate|null} The fetched notification message, or null if not found.
585
+ */
299
586
  fetch: (tag) => {
300
587
  this.checkProductInit();
301
588
  return this.productBuilder.fetchNotificationMessage(tag);
302
589
  },
590
+ /**
591
+ * Updates a notification message by tag.
592
+ * @param {string} tag - The notification message tag.
593
+ * @param {Partial<IProductNotificationTemplate>} data - The notification message data to update.
594
+ * @returns {Promise<void>} Resolves when the notification message is updated. Throws on error.
595
+ */
303
596
  update: async (tag, data) => {
304
597
  this.checkProductInit();
305
598
  return this.productBuilder.updateNotificationMessage(Object.assign(Object.assign({}, data), { tag }));
@@ -307,53 +600,115 @@ class Ductape {
307
600
  },
308
601
  },
309
602
  databases: {
603
+ /**
604
+ * Creates a database for a product.
605
+ * @param {IProductDatabase} data - The database data.
606
+ * @returns {Promise<void>} Resolves when the database is created. Throws on error.
607
+ */
310
608
  create: async (data) => {
311
609
  this.checkProductInit();
312
610
  return this.productBuilder.createDatabase(data);
313
611
  },
612
+ /**
613
+ * Fetches all databases for a product.
614
+ * @returns {IProductDatabase[]} The list of databases.
615
+ */
314
616
  fetchAll: () => {
315
617
  this.checkProductInit();
316
618
  return this.productBuilder.fetchDatabases();
317
619
  },
620
+ /**
621
+ * Fetches a database by tag.
622
+ * @param {string} tag - The database tag.
623
+ * @returns {IProductDatabase|null} The fetched database, or null if not found.
624
+ */
318
625
  fetch: (tag) => {
319
626
  this.checkProductInit();
320
627
  return this.productBuilder.fetchDatabase(tag);
321
628
  },
629
+ /**
630
+ * Updates a database by tag.
631
+ * @param {string} tag - The database tag.
632
+ * @param {Partial<IProductDatabase>} data - The database data to update.
633
+ * @returns {Promise<void>} Resolves when the database is updated. Throws on error.
634
+ */
322
635
  update: async (tag, data) => {
323
636
  this.checkProductInit();
324
637
  return this.productBuilder.updateDatabase(tag, data);
325
638
  },
326
639
  actions: {
640
+ /**
641
+ * Creates a database action for a product.
642
+ * @param {IProductDatabaseAction} data - The database action data.
643
+ * @returns {Promise<void>} Resolves when the database action is created. Throws on error.
644
+ */
327
645
  create: async (data) => {
328
646
  this.checkProductInit();
329
647
  return this.productBuilder.createDatabaseAction(data);
330
648
  },
649
+ /**
650
+ * Fetches all database actions for a product.
651
+ * @param {string} databaseTag - The database tag.
652
+ * @returns {IProductDatabaseAction[]} The list of database actions.
653
+ */
331
654
  fetchAll: (databaseTag) => {
332
655
  this.checkProductInit();
333
656
  return this.productBuilder.fetchDatabaseActions(databaseTag);
334
657
  },
658
+ /**
659
+ * Fetches a database action by tag.
660
+ * @param {string} tag - The database action tag.
661
+ * @returns {IProductDatabaseAction|null} The fetched database action, or null if not found.
662
+ */
335
663
  fetch: (tag) => {
336
664
  this.checkProductInit();
337
665
  return this.productBuilder.fetchDatabaseAction(tag);
338
666
  },
667
+ /**
668
+ * Updates a database action by tag.
669
+ * @param {string} tag - The database action tag.
670
+ * @param {Partial<IProductDatabaseAction>} data - The database action data to update.
671
+ * @returns {Promise<void>} Resolves when the database action is updated. Throws on error.
672
+ */
339
673
  update: async (tag, data) => {
340
674
  this.checkProductInit();
341
675
  return this.productBuilder.updateDatabaseAction(Object.assign(Object.assign({}, data), { tag }));
342
676
  },
343
677
  },
344
678
  migrations: {
679
+ /**
680
+ * Creates a database migration for a product.
681
+ * @param {IProductDatabaseMigration} data - The database migration data.
682
+ * @returns {void} Resolves when the database migration is created. Throws on error.
683
+ */
345
684
  create: (data) => {
346
685
  this.checkProductInit();
347
686
  return this.productBuilder.createDatabaseMigration(data);
348
687
  },
688
+ /**
689
+ * Fetches all database migrations for a product.
690
+ * @param {string} databaseTag - The database tag.
691
+ * @returns {IProductDatabaseMigration[]} The list of database migrations.
692
+ */
349
693
  fetchAll: (databaseTag) => {
350
694
  this.checkProductInit();
351
695
  return this.productBuilder.fetchDatabaseMigrations(databaseTag);
352
696
  },
697
+ /**
698
+ * Fetches a database migration by tag.
699
+ * @param {string} tag - The database migration tag.
700
+ * @returns {IProductDatabaseMigration|null} The fetched database migration, or null if not found.
701
+ */
353
702
  fetch: (tag) => {
354
703
  this.checkProductInit();
355
704
  return this.productBuilder.fetchDatabaseMigration(tag);
356
705
  },
706
+ /**
707
+ * Updates a database migration by tag.
708
+ * @param {string} tag - The database migration tag.
709
+ * @param {Partial<IProductDatabaseMigration>} data - The database migration data to update.
710
+ * @returns {void} Resolves when the database migration is updated. Throws on error.
711
+ */
357
712
  update: (tag, data) => {
358
713
  this.checkProductInit();
359
714
  return this.productBuilder.updateDatabaseMigration(Object.assign(Object.assign({}, data), { tag }));
@@ -361,36 +716,76 @@ class Ductape {
361
716
  },
362
717
  },
363
718
  jobs: {
719
+ /**
720
+ * Creates a job for a product.
721
+ * @param {Partial<IProductJobs>} data - The job data.
722
+ * @returns {Promise<void>} Resolves when the job is created. Throws on error.
723
+ */
364
724
  create: async (data) => {
365
725
  this.checkProductInit();
366
726
  return this.productBuilder.createJob(data);
367
727
  },
728
+ /**
729
+ * Fetches all jobs for a product.
730
+ * @returns {IProductJobs[]} The list of jobs.
731
+ */
368
732
  fetchAll: () => {
369
733
  this.checkProductInit();
370
734
  return this.productBuilder.fetchJobs();
371
735
  },
736
+ /**
737
+ * Fetches a job by tag.
738
+ * @param {string} tag - The job tag.
739
+ * @returns {IProductJobs|null} The fetched job, or null if not found.
740
+ */
372
741
  fetch: (tag) => {
373
742
  this.checkProductInit();
374
743
  return this.productBuilder.fetchJob(tag);
375
744
  },
745
+ /**
746
+ * Updates a job by tag.
747
+ * @param {string} tag - The job tag.
748
+ * @param {Partial<IProductJobs>} data - The job data to update.
749
+ * @returns {Promise<void>} Resolves when the job is updated. Throws on error.
750
+ */
376
751
  update: async (tag, data) => {
377
752
  this.checkProductInit();
378
753
  return this.productBuilder.updateJob(tag, data);
379
754
  },
380
755
  },
381
756
  caches: {
757
+ /**
758
+ * Creates a cache for a product.
759
+ * @param {IProductCache} data - The cache data.
760
+ * @returns {Promise<void>} Resolves when the cache is created. Throws on error.
761
+ */
382
762
  create: async (data) => {
383
763
  this.checkProductInit();
384
764
  return this.productBuilder.createCache(data);
385
765
  },
766
+ /**
767
+ * Fetches all caches for a product.
768
+ * @returns {IProductCache[]} The list of caches.
769
+ */
386
770
  fetchAll: () => {
387
771
  this.checkProductInit();
388
772
  return this.productBuilder.fetchCaches();
389
773
  },
774
+ /**
775
+ * Fetches a cache by tag.
776
+ * @param {string} tag - The cache tag.
777
+ * @returns {IProductCache|null} The fetched cache, or null if not found.
778
+ */
390
779
  fetch: (tag) => {
391
780
  this.checkProductInit();
392
781
  return this.productBuilder.fetchCache(tag);
393
782
  },
783
+ /**
784
+ * Updates a cache by tag.
785
+ * @param {string} tag - The cache tag.
786
+ * @param {Partial<IProductCache>} data - The cache data to update.
787
+ * @returns {Promise<void>} Resolves when the cache is updated. Throws on error.
788
+ */
394
789
  update: async (tag, data) => {
395
790
  this.checkProductInit();
396
791
  return this.productBuilder.updateCache(tag, data);
@@ -401,41 +796,85 @@ class Ductape {
401
796
  },
402
797
  },
403
798
  features: {
799
+ /**
800
+ * Creates a feature for a product.
801
+ * @param {Partial<IProductFeature>} data - The feature data.
802
+ * @returns {Promise<void>} Resolves when the feature is created. Throws on error.
803
+ */
404
804
  create: async (data) => {
405
805
  this.checkProductInit();
406
806
  return this.productBuilder.createFeature(data);
407
807
  },
808
+ /**
809
+ * Fetches all features for a product.
810
+ * @returns {IProductFeature[]} The list of features.
811
+ */
408
812
  fetchAll: () => {
409
813
  this.checkProductInit();
410
814
  return this.productBuilder.fetchFeatures();
411
815
  },
816
+ /**
817
+ * Fetches a feature by tag.
818
+ * @param {string} tag - The feature tag.
819
+ * @returns {IProductFeature|null} The fetched feature, or null if not found.
820
+ */
412
821
  fetch: (tag) => {
413
822
  this.checkProductInit();
414
823
  return this.productBuilder.fetchFeature(tag);
415
824
  },
825
+ /**
826
+ * Updates a feature by tag.
827
+ * @param {string} tag - The feature tag.
828
+ * @param {Partial<IProductCache>} data - The feature data to update.
829
+ * @returns {Promise<void>} Resolves when the feature is updated. Throws on error.
830
+ */
416
831
  update: async (tag, data) => {
417
832
  this.checkProductInit();
418
833
  return this.productBuilder.updateFeature(tag, data);
419
834
  },
420
835
  },
421
836
  };
837
+ /**
838
+ * App-related operations for managing apps, variables, constants, actions, auths, webhooks, environments, and validation.
839
+ */
422
840
  this.app = {
841
+ /**
842
+ * Creates a new app.
843
+ * @param {ICreateAppBuilder} data - The app data.
844
+ * @returns {Promise<{ app_id: string }>} The ID of the created app.
845
+ */
423
846
  create: async (data) => {
424
847
  await this.initApp();
425
848
  return this.appBuilder.createApp(data);
426
849
  },
850
+ /**
851
+ * Fetches an app by tag.
852
+ * @param {string} tag - The app tag.
853
+ * @returns {Promise<IApp|null>} The fetched app, or null if not found.
854
+ */
427
855
  fetch: async (tag) => {
428
856
  await this.initApp();
429
857
  await this.appBuilder.initializeAppByTag(tag);
430
858
  this.appInit = false;
431
859
  return this.appBuilder.fetchApp();
432
860
  },
861
+ /**
862
+ * Updates an app by tag.
863
+ * @param {string} tag - The app tag.
864
+ * @param {Partial<IApp>} data - The app data to update.
865
+ * @returns {Promise<void>} Resolves when the app is updated. Throws on error.
866
+ */
433
867
  update: async (tag, data) => {
434
868
  await this.initApp();
435
869
  await this.appBuilder.initializeAppByTag(tag);
436
870
  this.appInit = false;
437
871
  return this.appBuilder.updateApp(data);
438
872
  },
873
+ /**
874
+ * Initializes an app by tag.
875
+ * @param {string} appTag - The app tag.
876
+ * @returns {Promise<void>} Resolves when initialization is complete. Throws on error.
877
+ */
439
878
  init: async (appTag) => {
440
879
  console.log(`App initialized with tag: ${appTag}`);
441
880
  await this.initApp();
@@ -443,43 +882,93 @@ class Ductape {
443
882
  this.appInit = true;
444
883
  },
445
884
  variables: {
885
+ /**
886
+ * Creates a variable for an app.
887
+ * @param {IAppVariables} data - The variable data.
888
+ * @returns {Promise<void>} Resolves when the variable is created. Throws on error.
889
+ */
446
890
  create: async (data) => {
447
891
  this.checkAppInit();
448
892
  return this.appBuilder.createVariable(data);
449
893
  },
894
+ /**
895
+ * Fetches all variables for an app.
896
+ * @returns {IAppVariables[]} The list of variables.
897
+ */
450
898
  fetchAll: () => {
451
899
  this.checkAppInit();
452
900
  return this.appBuilder.fetchVariables();
453
901
  },
902
+ /**
903
+ * Fetches a variable by tag.
904
+ * @param {string} tag - The variable tag.
905
+ * @returns {IAppVariables|null} The fetched variable, or null if not found.
906
+ */
454
907
  fetch: (tag) => {
455
908
  this.checkAppInit();
456
909
  return this.appBuilder.fetchVariable(tag);
457
910
  },
911
+ /**
912
+ * Updates a variable by tag.
913
+ * @param {string} tag - The variable tag.
914
+ * @param {Partial<IAppVariables>} data - The variable data to update.
915
+ * @returns {Promise<void>} Resolves when the variable is updated. Throws on error.
916
+ */
458
917
  update: async (tag, data) => {
459
918
  this.checkAppInit();
460
919
  return this.appBuilder.updateVariable(tag, data);
461
920
  },
462
921
  },
463
922
  constants: {
923
+ /**
924
+ * Creates a constant for an app.
925
+ * @param {IAppConstants} data - The constant data.
926
+ * @returns {Promise<void>} Resolves when the constant is created. Throws on error.
927
+ */
464
928
  create: async (data) => {
465
929
  this.checkAppInit();
466
930
  return this.appBuilder.createConstant(data);
467
931
  },
932
+ /**
933
+ * Fetches all constants for an app.
934
+ * @returns {IAppConstants[]} The list of constants.
935
+ */
468
936
  fetchAll: () => {
469
937
  this.checkAppInit();
470
938
  return this.appBuilder.fetchConstants();
471
939
  },
940
+ /**
941
+ * Fetches a constant by tag.
942
+ * @param {string} tag - The constant tag.
943
+ * @returns {IAppConstants|null} The fetched constant, or null if not found.
944
+ */
472
945
  fetch: (tag) => {
473
946
  this.checkAppInit();
474
947
  return this.appBuilder.fetchConstant(tag);
475
948
  },
949
+ /**
950
+ * Updates a constant by tag.
951
+ * @param {string} tag - The constant tag.
952
+ * @param {Partial<IAppVariables>} data - The constant data to update.
953
+ * @returns {Promise<void>} Resolves when the constant is updated. Throws on error.
954
+ */
476
955
  update: async (tag, data) => {
477
956
  this.checkAppInit();
478
957
  return this.appBuilder.updateConstant(tag, data);
479
958
  },
480
959
  },
481
960
  actions: {
482
- import: async ({ file, type, version, appTag, updateIfExists, }) => {
961
+ /**
962
+ * Imports actions for an app from a file.
963
+ * @param {Object} params - The import parameters.
964
+ * @param {Buffer} params.file - The file buffer.
965
+ * @param {ImportDocsTypes} params.type - The import type.
966
+ * @param {string} params.version - The version.
967
+ * @param {string} [params.appTag] - The app tag (optional).
968
+ * @param {boolean} [params.updateIfExists] - Whether to update if actions exist (optional).
969
+ * @returns {Promise<void>} Resolves when the import is complete. Throws on error.
970
+ */
971
+ import: async ({ file, type, version, appTag, updateIfExists, isAdminImport, }) => {
483
972
  var _a;
484
973
  if (!this.token)
485
974
  await this.initUserAuth();
@@ -499,69 +988,145 @@ class Ductape {
499
988
  }
500
989
  app_id = app._id;
501
990
  }
502
- return this.importService.importApp(file, type, version, updateIfExists, app_id);
503
- },
991
+ return this.importService.importApp(file, type, version, updateIfExists, app_id, isAdminImport);
992
+ },
993
+ /**
994
+ * Updates an action by tag.
995
+ * @param {string} tag - The action tag.
996
+ * @param {Partial<IActionUpdate>} data - The action data to update.
997
+ * @returns {Promise<void>} Resolves when the action is updated. Throws on error.
998
+ */
504
999
  update: async (tag, data) => {
505
1000
  this.checkAppInit();
506
1001
  return this.appBuilder.updateAction(tag, data);
507
1002
  },
1003
+ /**
1004
+ * Fetches all actions for an app.
1005
+ * @returns {IAppAction[]} The list of actions.
1006
+ */
508
1007
  fetchAll: () => {
509
1008
  this.checkAppInit();
510
1009
  return this.appBuilder.fetchActions();
511
1010
  },
1011
+ /**
1012
+ * Fetches an action by tag.
1013
+ * @param {string} tag - The action tag.
1014
+ * @returns {IAppAction|null} The fetched action, or null if not found.
1015
+ */
512
1016
  fetch: (tag) => {
513
1017
  this.checkAppInit();
514
1018
  return this.appBuilder.fetchAction(tag);
515
1019
  },
516
1020
  },
517
1021
  auths: {
1022
+ /**
1023
+ * Creates an auth for an app.
1024
+ * @param {IAppAuth} data - The auth data.
1025
+ * @returns {Promise<void>} Resolves when the auth is created. Throws on error.
1026
+ */
518
1027
  create: async (data) => {
519
1028
  this.checkAppInit();
520
1029
  return this.appBuilder.createAuth(data);
521
1030
  },
1031
+ /**
1032
+ * Fetches all auths for an app.
1033
+ * @returns {IAppAuth[]} The list of auths.
1034
+ */
522
1035
  fetchAll: () => {
523
1036
  this.checkAppInit();
524
1037
  return this.appBuilder.fetchAuths();
525
1038
  },
1039
+ /**
1040
+ * Fetches an auth by tag.
1041
+ * @param {string} tag - The auth tag.
1042
+ * @returns {IAppAuth|null} The fetched auth, or null if not found.
1043
+ */
526
1044
  fetch: (tag) => {
527
1045
  this.checkAppInit();
528
1046
  return this.appBuilder.fetchAuth(tag);
529
1047
  },
1048
+ /**
1049
+ * Updates an auth by tag.
1050
+ * @param {string} tag - The auth tag.
1051
+ * @param {Partial<IAppAuth>} data - The auth data to update.
1052
+ * @returns {Promise<void>} Resolves when the auth is updated. Throws on error.
1053
+ */
530
1054
  update: async (tag, data) => {
531
1055
  this.checkAppInit();
532
1056
  return this.appBuilder.updateAuth(tag, data);
533
1057
  },
534
1058
  },
535
1059
  webhooks: {
1060
+ /**
1061
+ * Creates a webhook for an app.
1062
+ * @param {Partial<IAppWebhook>} data - The webhook data.
1063
+ * @returns {Promise<void>} Resolves when the webhook is created. Throws on error.
1064
+ */
536
1065
  create: async (data) => {
537
1066
  this.checkAppInit();
538
1067
  return this.appBuilder.createWebhook(data);
539
1068
  },
1069
+ /**
1070
+ * Fetches all webhooks for an app.
1071
+ * @returns {IAppWebhook[]} The list of webhooks.
1072
+ */
540
1073
  fetchAll: () => {
541
1074
  this.checkAppInit();
542
1075
  return this.appBuilder.fetchWebhooks();
543
1076
  },
1077
+ /**
1078
+ * Fetches a webhook by tag.
1079
+ * @param {string} tag - The webhook tag.
1080
+ * @returns {IAppWebhook|null} The fetched webhook, or null if not found.
1081
+ */
544
1082
  fetch: (tag) => {
545
1083
  this.checkAppInit();
546
1084
  return this.appBuilder.fetchWebhook(tag);
547
1085
  },
1086
+ /**
1087
+ * Updates a webhook by tag.
1088
+ * @param {string} tag - The webhook tag.
1089
+ * @param {Partial<IAppWebhook>} data - The webhook data to update.
1090
+ * @returns {Promise<void>} Resolves when the webhook is updated. Throws on error.
1091
+ */
548
1092
  update: async (tag, data) => {
549
1093
  this.checkAppInit();
550
1094
  return this.appBuilder.updateWebhook(tag, data);
551
1095
  },
552
1096
  events: {
1097
+ /**
1098
+ * Creates a webhook event for an app.
1099
+ * @param {IAppWebhookEvent} data - The webhook event data.
1100
+ * @returns {Promise<void>} Resolves when the webhook event is created. Throws on error.
1101
+ */
553
1102
  create: async (data) => {
554
1103
  this.checkAppInit();
555
1104
  return this.appBuilder.createWebhookEvent(data);
556
1105
  },
1106
+ /**
1107
+ * Fetches all webhook events for a webhook by tag.
1108
+ * @param {string} webhookTag - The webhook tag.
1109
+ * @returns {IAppWebhookEvent[]} The list of webhook events.
1110
+ */
557
1111
  fetchAll: (webhookTag) => {
558
1112
  this.checkAppInit();
559
1113
  return this.appBuilder.fetchWebhookEvents(webhookTag);
560
1114
  },
1115
+ /**
1116
+ * Fetches a webhook event by tag.
1117
+ * @param {string} tag - The webhook event tag.
1118
+ * @returns {IAppWebhookEvent|null} The fetched webhook event, or null if not found.
1119
+ */
561
1120
  fetch: (tag) => {
562
1121
  this.checkAppInit();
563
1122
  return this.appBuilder.fetchWebhookEvent(tag);
564
1123
  },
1124
+ /**
1125
+ * Updates a webhook event by tag.
1126
+ * @param {string} tag - The webhook event tag.
1127
+ * @param {Partial<IAppWebhookEvent>} data - The webhook event data to update.
1128
+ * @returns {Promise<void>} Resolves when the webhook event is updated. Throws on error.
1129
+ */
565
1130
  update: async (tag, data) => {
566
1131
  this.checkAppInit();
567
1132
  return this.appBuilder.updateWebhookEvent(Object.assign(Object.assign({}, data), { tag }));
@@ -569,102 +1134,223 @@ class Ductape {
569
1134
  },
570
1135
  },
571
1136
  environments: {
1137
+ /**
1138
+ * Creates an environment for an app.
1139
+ * @param {IAppEnv} data - The environment data.
1140
+ * @returns {Promise<void>} Resolves when the environment is created. Throws on error.
1141
+ */
572
1142
  create: async (data) => {
573
1143
  this.checkAppInit();
574
1144
  return this.appBuilder.createEnv(data);
575
1145
  },
1146
+ /**
1147
+ * Fetches all environments for an app.
1148
+ * @returns {IAppEnv[]} The list of environments.
1149
+ */
576
1150
  fetchAll: () => {
577
1151
  this.checkAppInit();
578
1152
  return this.appBuilder.fetchEnvs();
579
1153
  },
1154
+ /**
1155
+ * Fetches an environment by slug.
1156
+ * @param {string} slug - The environment slug.
1157
+ * @returns {IAppEnv|null} The fetched environment, or null if not found.
1158
+ */
580
1159
  fetch: (slug) => {
581
1160
  this.checkAppInit();
582
1161
  return this.appBuilder.fetchEnv(slug);
583
1162
  },
1163
+ /**
1164
+ * Updates an environment by slug.
1165
+ * @param {string} slug - The environment slug.
1166
+ * @param {Partial<IAppEnv>} data - The environment data to update.
1167
+ * @returns {Promise<void>} Resolves when the environment is updated. Throws on error.
1168
+ */
584
1169
  update: async (slug, data) => {
585
1170
  this.checkAppInit();
586
1171
  return this.appBuilder.updateEnv(slug, data);
587
1172
  },
588
1173
  },
1174
+ /**
1175
+ * Updates data validation for an app.
1176
+ * @param {string} selector - The selector for the data validation.
1177
+ * @param {Partial<IParsedSample>} update - The update data.
1178
+ * @returns {Promise<void>} Resolves when the validation is updated. Throws on error.
1179
+ */
589
1180
  validation: (selector, update) => {
590
1181
  this.checkAppInit();
591
1182
  return this.appBuilder.updateDataValidation(selector, update);
592
1183
  },
593
1184
  };
1185
+ /**
1186
+ * Processor-related operations for running jobs, actions, database actions, sessions, features, quotas, fallbacks, notifications, storage, and message broker.
1187
+ */
594
1188
  this.processor = {
595
1189
  job: {
1190
+ /**
1191
+ * Schedules a job for a product.
1192
+ * @param {IProduct} data - The product data.
1193
+ * @returns {Promise<any>} The result of the job scheduling.
1194
+ */
596
1195
  schedule: async (data) => {
597
1196
  const processorService = await this.createNewProcessor();
598
1197
  //return processorService.processJob()
599
1198
  },
600
1199
  },
601
1200
  action: {
1201
+ /**
1202
+ * Runs an action processor.
1203
+ * @param {IActionProcessorInput} data - The action processor input.
1204
+ * @returns {Promise<any>} The result of the action processing.
1205
+ */
602
1206
  run: async (data) => {
603
1207
  const processorService = await this.createNewProcessor();
604
1208
  return processorService.processAction(data);
605
1209
  },
606
1210
  },
607
1211
  db: {
1212
+ /**
1213
+ * Executes a database action processor.
1214
+ * @param {IDBActionProcessorInput} data - The database action processor input.
1215
+ * @returns {Promise<any>} The result of the database action processing.
1216
+ */
608
1217
  execute: async (data) => {
609
1218
  const processorService = await this.createNewProcessor();
610
1219
  return processorService.processDBAction(data);
611
1220
  },
612
1221
  migration: {
1222
+ /**
1223
+ * Runs a database migration.
1224
+ * @param {Object} params - The migration parameters.
1225
+ * @param {string} params.migration - The migration name.
1226
+ * @param {string} params.env - The environment.
1227
+ * @param {string} params.product - The product name.
1228
+ * @returns {Promise<any>} The result of the migration.
1229
+ */
613
1230
  run: async ({ migration, env, product }) => {
614
- //this.checkProductInit();
615
1231
  const processorService = await this.createNewProcessor();
616
1232
  return processorService.runMigration(product, migration, env, 'up');
617
1233
  },
1234
+ /**
1235
+ * Rolls back a database migration.
1236
+ * @param {Object} params - The migration parameters.
1237
+ * @param {string} params.migration - The migration name.
1238
+ * @param {string} params.env - The environment.
1239
+ * @param {string} params.product - The product name.
1240
+ * @returns {Promise<any>} The result of the rollback.
1241
+ */
618
1242
  rollback: async ({ migration, env, product }) => {
619
- //this.checkProductInit();
620
1243
  const processorService = await this.createNewProcessor();
621
1244
  return processorService.runMigration(product, migration, env, 'down');
622
1245
  },
623
1246
  },
624
1247
  },
625
1248
  sessions: {
626
- generate: async (data) => {
1249
+ /**
1250
+ * Starts a new session.
1251
+ * @param {ISessionInput} data - The session input data.
1252
+ * @returns {Promise<any>} The result of the session generation.
1253
+ */
1254
+ start: async (data) => {
627
1255
  const processorService = await this.createNewProcessor();
628
1256
  return processorService.generateSession(data);
1257
+ },
1258
+ /**
1259
+ * Decrypts a session.
1260
+ * @param {ISessionPayload} data - The session payload.
1261
+ * @returns {Promise<any>} The decrypted session.
1262
+ */
1263
+ decrypt: async (data) => {
1264
+ const processorService = await this.createNewProcessor();
1265
+ return processorService.decryptSession(data);
1266
+ },
1267
+ /**
1268
+ * Refreshes a session.
1269
+ * @param {ISessionRefreshPayload} data - The session refresh payload.
1270
+ * @returns {Promise<any>} The refreshed session.
1271
+ */
1272
+ refresh: async (data) => {
1273
+ const processorService = await this.createNewProcessor();
1274
+ return processorService.refreshSession(data);
629
1275
  }
630
1276
  },
631
1277
  feature: {
1278
+ /**
1279
+ * Runs a feature processor.
1280
+ * @param {IProcessorInput} data - The feature processor input.
1281
+ * @returns {Promise<any>} The result of the feature processing.
1282
+ */
632
1283
  run: async (data) => {
633
1284
  const processorService = await this.createNewProcessor();
634
1285
  return await processorService.processFeature(data);
635
1286
  },
1287
+ /**
1288
+ * Generates output for a process by ID.
1289
+ * @param {string} process_id - The process ID.
1290
+ * @returns {Promise<any>} The generated output.
1291
+ */
636
1292
  output: async (process_id) => {
637
1293
  const processorService = await this.createNewProcessor();
638
1294
  return await processorService.generateOutput(process_id);
639
1295
  },
1296
+ /**
1297
+ * Replays a process by ID.
1298
+ * @param {string} process_id - The process ID.
1299
+ * @returns {Promise<any>} The result of the replay.
1300
+ */
640
1301
  replay: async (process_id) => {
641
1302
  const processorService = await this.createNewProcessor();
642
1303
  return await processorService.replayProcess(process_id);
643
1304
  },
1305
+ /**
1306
+ * Resumes a process by ID.
1307
+ * @param {string} process_id - The process ID.
1308
+ * @returns {Promise<any>} The result of the resume.
1309
+ */
644
1310
  resume: async (process_id) => {
645
1311
  const processorService = await this.createNewProcessor();
646
1312
  return await processorService.resumeProcess(process_id);
647
1313
  },
648
1314
  },
649
1315
  quota: {
1316
+ /**
1317
+ * Runs a quota processor.
1318
+ * @param {IProcessorInput} data - The quota processor input.
1319
+ * @returns {Promise<any>} The result of the quota processing.
1320
+ */
650
1321
  run: async (data) => {
651
1322
  const processorService = await this.createNewProcessor();
652
1323
  return processorService.processQuota(data);
653
1324
  },
654
1325
  },
655
1326
  fallback: {
1327
+ /**
1328
+ * Runs a fallback processor.
1329
+ * @param {IProcessorInput} data - The fallback processor input.
1330
+ * @returns {Promise<any>} The result of the fallback processing.
1331
+ */
656
1332
  run: async (data) => {
657
1333
  const processorService = await this.createNewProcessor();
658
1334
  return processorService.processFallback(data);
659
1335
  },
660
1336
  },
661
1337
  notification: {
1338
+ /**
1339
+ * Sends a notification using the notification processor.
1340
+ * @param {INotificationProcessorInput} data - The notification processor input.
1341
+ * @returns {Promise<any>} The result of the notification processing.
1342
+ */
662
1343
  send: async (data) => {
663
1344
  const processorService = await this.createNewProcessor();
664
1345
  return processorService.processNotification(data);
665
1346
  },
666
1347
  },
667
1348
  storage: {
1349
+ /**
1350
+ * Reads a file from storage.
1351
+ * @param {string} path - The file path.
1352
+ * @returns {Promise<IFileReadResult>} The file read result.
1353
+ */
668
1354
  readFile: async (path) => {
669
1355
  try {
670
1356
  const buffer = await fs_1.promises.readFile(path);
@@ -676,29 +1362,48 @@ class Ductape {
676
1362
  throw error;
677
1363
  }
678
1364
  },
1365
+ /**
1366
+ * Saves data to storage using the storage processor.
1367
+ * @param {IStorageProcessorInput} data - The storage processor input.
1368
+ * @returns {Promise<any>} The result of the storage processing.
1369
+ */
679
1370
  save: async (data) => {
680
1371
  const processorService = await this.createNewProcessor();
681
1372
  return processorService.processStorage(data);
682
1373
  },
683
1374
  },
684
- /*cloudFunction: {
685
- invoke: async (data: IFunctionProcessorInput) => {
686
- const processorService = this.createNewProcessor();
687
- return processorService.processFunction(data);
688
- },
689
- },*/
690
1375
  messageBroker: {
1376
+ /**
1377
+ * Publishes a message using the message broker processor.
1378
+ * @param {IMessageBrokerPublishInput} data - The publish input.
1379
+ * @returns {Promise<any>} The result of the publish operation.
1380
+ */
691
1381
  publish: async (data) => {
692
1382
  const processorService = await this.createNewProcessor();
693
1383
  return processorService.processMessageBrokerPublish(data);
694
1384
  },
1385
+ /**
1386
+ * Subscribes to a message broker topic.
1387
+ * @param {IMessageBrokerSubscribeInput} data - The subscribe input.
1388
+ * @returns {Promise<any>} The result of the subscribe operation.
1389
+ */
695
1390
  subcribe: async (data) => {
696
1391
  const processorService = await this.createNewProcessor();
697
1392
  return processorService.processMessageBrokerSubscribe(data);
698
1393
  },
699
1394
  },
700
1395
  };
1396
+ /**
1397
+ * Logs-related operations for initializing and fetching logs.
1398
+ */
701
1399
  this.logs = {
1400
+ /**
1401
+ * Initializes the logger service for a product or app.
1402
+ * @param {string} [productTag] - The product tag (optional).
1403
+ * @param {string} [appTag] - The app tag (optional).
1404
+ * @throws {Error} If neither productTag nor appTag is provided.
1405
+ * @returns {Promise<void>} Resolves when logger is initialized.
1406
+ */
702
1407
  init: async (productTag, appTag) => {
703
1408
  if (!productTag && !appTag) {
704
1409
  throw new Error('At least one of productTag or appTag must be provided');
@@ -717,48 +1422,9 @@ class Ductape {
717
1422
  },
718
1423
  add: async () => { },
719
1424
  /**
720
- * Fetches logs based on provded query parameters.
721
- *
722
- * @param params.component - Required. Specifies the component type ('app' or 'product')
723
- * @param params.type - Optional. Type of analysis ('apps', 'process', 'feature', 'integrations', etc.)
724
- * @param params.groupBy - Optional. Time period for grouping ('day', 'week', 'month', 'year')
725
- * @param params.search - Optional. Search term for filtering logs
726
- * @param params.page - Optional. Page number for pagination (≥ 1)
727
- * @param params.limit - Optional. Number of items per page (≥ 1)
728
- * @param params.status - Optional. Filter by status ('success', 'processing', 'fail')
729
- *
730
- * For component='app':
731
- * @param params.tag - Optional. Tag identifier (only valid when type='actions')
732
- * @param params.env - Optional. Environment filter
733
- * @param params.name - Optional. Name filter
734
- * @param params.action - Optional. Specific action filter
735
- *
736
- * For component='product':
737
- * @param params.env - Optional. Environment filter
738
- * @param params.name - Optional. Name filter
739
- * @param params.action - Optional. Specific action filter
740
- *
741
- * @throws {Error} If logger service is not initialized
742
- * @throws {Error} If required parameters are missing or invalid
743
- * @throws {Error} If API request fails
744
- *
745
- * @returns {Promise<any>} The fetched log data
746
- *
747
- * @example
748
- * // Fetch app logs
749
- * const appLogs = await logs.fetch({
750
- * component: 'app',
751
- * type: 'actions',
752
- * groupBy: 'day',
753
- * limit: 20
754
- * });
755
- *
756
- * // Fetch product logs
757
- * const productLogs = await logs.fetch({
758
- * component: 'product',
759
- * type: 'database',
760
- * status: 'success'
761
- * });
1425
+ * Fetches logs based on provided query parameters.
1426
+ * @param {LogQueryParams} params - The log query parameters.
1427
+ * @returns {Promise<any>} The fetched log data.
762
1428
  */
763
1429
  fetch: async (params) => {
764
1430
  if (!this.loggerService) {
@@ -785,7 +1451,23 @@ class Ductape {
785
1451
  this.redis_url = redis_url;
786
1452
  return (0, utils_1.createDeepProxy)(this, this.environment);
787
1453
  }
788
- async connectRedis() {
1454
+ async loadBullMQ() {
1455
+ if (typeof window !== 'undefined') {
1456
+ throw new Error("Bullmq can only be used in a server environment.");
1457
+ }
1458
+ const bull = await Promise.resolve().then(() => __importStar(require('bullmq')));
1459
+ return {
1460
+ Queue: bull.Queue,
1461
+ Worker: bull.Worker,
1462
+ Job: bull.Job,
1463
+ };
1464
+ }
1465
+ /**
1466
+ * Connects to Redis and initializes job and health check queues and workers.
1467
+ * @throws {Error} If called in a browser environment or if Redis URL is missing.
1468
+ * @returns {Promise<void>} Resolves when Redis and queues are initialized.
1469
+ */
1470
+ async monitor() {
789
1471
  if (typeof window !== 'undefined') {
790
1472
  throw new Error("RedisService can only be used in a server environment.");
791
1473
  }
@@ -793,16 +1475,162 @@ class Ductape {
793
1475
  throw new Error("Redis URL is not provided.");
794
1476
  }
795
1477
  if (this.redisClient) {
796
- // Already connected — reuse existing client
1478
+ // Already connected
1479
+ return;
1480
+ }
1481
+ // TODO: remove this requirement
1482
+ if (!this.redisClient) {
797
1483
  return;
798
1484
  }
799
- const { createClient } = await this.loadRedis();
800
- this.redisClient = createClient({ url: this.redis_url });
801
- await this.redisClient.connect();
1485
+ if (!this.public_key) {
1486
+ await this.initUserAuth(false);
1487
+ }
1488
+ const Redis = await this.loadRedis();
1489
+ const { Queue, Worker: BullWorker } = await this.loadBullMQ();
1490
+ // Create Redis client with required options for BullMQ
1491
+ this.redisClient = new Redis.default(this.redis_url, {
1492
+ maxRetriesPerRequest: null, // Required by BullMQ
1493
+ });
1494
+ // Initialize job queues
1495
+ this.jobsQueue = new Queue('ductape_jobs', {
1496
+ connection: this.redisClient,
1497
+ });
1498
+ this.healthCheckQueue = new Queue('ductape_healthchecks', {
1499
+ connection: this.redisClient,
1500
+ });
1501
+ this.healthCheckUpdaterQueue = new Queue('healthchecks-updater', {
1502
+ connection: this.redisClient
1503
+ });
1504
+ // Schedule healthcheck jobs for all products/environments
1505
+ await this.scheduleAllHealthcheckJobs();
1506
+ // Initialize job worker
1507
+ this.jobsWorker = new BullWorker('ductape_jobs', async (job) => {
1508
+ console.log(`Processing job ${job.id} of type ${job.name}`, job.data);
1509
+ const processor = await this.createNewProcessor();
1510
+ await processor.runJobs(job);
1511
+ }, {
1512
+ connection: this.redisClient,
1513
+ });
1514
+ // Initialize health check worker
1515
+ this.healthCheckWorker = new BullWorker('ductape_healthchecks', async (job) => {
1516
+ console.log(`Running health check job ${job.id}`, job.data);
1517
+ const processor = await this.createNewProcessor();
1518
+ console.log("FIND JOB!!!!", job.data);
1519
+ if (job && job.data && Object.keys(job.data).length) {
1520
+ // Call processAction with job.data
1521
+ const result = await processor.processAction(job.data);
1522
+ // Write result to Redis cache
1523
+ await processor.writeHealthcheckResultToCache(job.data, Object.assign({ status: (result === null || result === void 0 ? void 0 : result.status) || 'unknown', lastChecked: Date.now() }, result));
1524
+ // Re-enqueue the job for continuous healthchecks
1525
+ //await this.scheduleHealthcheckJob(job.data);
1526
+ }
1527
+ }, {
1528
+ connection: this.redisClient,
1529
+ });
1530
+ // Add a repeatable job to update DB every 10 minutes
1531
+ await this.healthCheckUpdaterQueue.add('healthchecks-updater', {}, {
1532
+ jobId: 'healthchecks-updater',
1533
+ repeat: { every: 5 * 60 * 1000 }
1534
+ });
1535
+ // Healthcheck updater worker
1536
+ this.healthCheckUpdaterWorker = new BullWorker('healthchecks-updater', async (job) => {
1537
+ console.log('Init Processor for healthcheck Updater');
1538
+ if (job.name !== 'healthchecks-updater')
1539
+ return;
1540
+ // Gather all healthcheck results from Redis
1541
+ const keys = await this.redisClient.keys('healthcheck:*');
1542
+ console.log("Found Keys for healthcheck updater", JSON.stringify(keys));
1543
+ const envResults = {};
1544
+ for (const key of keys) {
1545
+ const [_, productTag, tag, envSlug] = key.split(':');
1546
+ console.log(`${productTag} , ${tag}, ${envSlug}`);
1547
+ const data = JSON.parse(await this.redisClient.get(key));
1548
+ if (!envResults[productTag])
1549
+ envResults[productTag] = {};
1550
+ if (!envResults[productTag][tag])
1551
+ envResults[productTag][tag] = {};
1552
+ envResults[productTag][tag][envSlug] = data;
1553
+ }
1554
+ for (const productTag in envResults) {
1555
+ const tagsData = Object.entries(envResults[productTag]).map(([tag, envs]) => ({
1556
+ tag,
1557
+ environments: Object.entries(envs).map(([slug, data]) => (Object.assign({ slug }, data))),
1558
+ }));
1559
+ console.log();
1560
+ const processor = await this.createNewProcessor();
1561
+ console.log('PROCESSING ENV RESULT', productTag, tagsData);
1562
+ await processor.updateHealthcheckOnProcessor(productTag, tagsData);
1563
+ }
1564
+ }, {
1565
+ connection: this.redisClient,
1566
+ });
1567
+ // Attach error listeners
1568
+ this.jobsWorker.on('failed', (job, err) => {
1569
+ console.error(`Job ${job === null || job === void 0 ? void 0 : job.id} failed:`, err);
1570
+ });
1571
+ this.healthCheckWorker.on('failed', (job, err) => {
1572
+ console.error(`Health check ${job === null || job === void 0 ? void 0 : job.id} failed:`, err);
1573
+ });
1574
+ }
1575
+ /**
1576
+ * Schedules all healthcheck jobs for all products and environments.
1577
+ */
1578
+ async scheduleAllHealthcheckJobs() {
1579
+ // Fetch all products (or use this.products if already loaded)
1580
+ const products = this.products || await this.productsApi.fetchWorkspaceProducts(enums_1.PublicStates.ALL, {
1581
+ token: this.token,
1582
+ public_key: this.public_key,
1583
+ user_id: this.user_id,
1584
+ workspace_id: this.workspace_id,
1585
+ });
1586
+ for (const product of products) {
1587
+ const healthchecks = product.healthchecks || [];
1588
+ const privateKey = product.private_key;
1589
+ for (const healthcheck of healthchecks) {
1590
+ for (const env of healthcheck.envs) {
1591
+ let decryptedInput = env.input;
1592
+ if (typeof decryptedInput === 'string') {
1593
+ decryptedInput = JSON.parse((0, processor_utils_1.decrypt)(decryptedInput, privateKey));
1594
+ }
1595
+ const jobData = {
1596
+ healthcheck: healthcheck.tag,
1597
+ env: env.slug,
1598
+ product: product.tag,
1599
+ app: healthcheck.app,
1600
+ input: decryptedInput,
1601
+ event: healthcheck.event,
1602
+ retries: healthcheck.retries || 0,
1603
+ };
1604
+ const jobId = `healthcheck-exec-${healthcheck.tag}-${env.slug}`;
1605
+ await this.scheduleHealthcheckJob(jobId, jobData, healthcheck.interval);
1606
+ }
1607
+ }
1608
+ }
1609
+ }
1610
+ /**
1611
+ * Schedules a single healthcheck job with the given interval (ms).
1612
+ * If interval is not provided, defaults to 60s.
1613
+ */
1614
+ async scheduleHealthcheckJob(jobId, jobData, interval) {
1615
+ console.log("JOBBERMAN", { jobId, jobData, interval });
1616
+ const job = await this.healthCheckQueue.getJob(jobId);
1617
+ if (job) {
1618
+ await job.remove();
1619
+ }
1620
+ const repeat = interval ? { every: interval } : { every: 60000 };
1621
+ await this.healthCheckQueue.add('healthchecks-updater', jobData, { repeat, jobId });
802
1622
  }
1623
+ /**
1624
+ * Sets the authentication token for API requests.
1625
+ * @param {string} token - The authentication token.
1626
+ */
803
1627
  setToken(token) {
804
1628
  this.token = token;
805
1629
  }
1630
+ /**
1631
+ * Sets the public key for API requests.
1632
+ * @param {string} public_key - The public key.
1633
+ */
806
1634
  setPublicKey(public_key) {
807
1635
  this.public_key = public_key;
808
1636
  }
@@ -874,6 +1702,8 @@ class Ductape {
874
1702
  user_id: this.user_id,
875
1703
  token: this.token,
876
1704
  env_type: this.environment,
1705
+ redis_client: this.redisClient,
1706
+ queues: { health: this.healthCheckQueue, jobs: this.jobsQueue }
877
1707
  });
878
1708
  }
879
1709
  createNewImporter() {
@@ -992,6 +1822,13 @@ class Ductape {
992
1822
  throw error;
993
1823
  }
994
1824
  }
1825
+ /**
1826
+ * Fetches the latest healthcheck status for a product/env from Redis cache via processor service.
1827
+ */
1828
+ async getHealthcheckStatus(productTag, envSlug) {
1829
+ const processor = await this.createNewProcessor();
1830
+ return processor.getHealthcheckStatusFromCache(productTag, envSlug);
1831
+ }
995
1832
  }
996
1833
  exports.default = Ductape;
997
1834
  //# sourceMappingURL=index.js.map