@ductape/sdk 0.0.4-v10 → 0.0.4-v12

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