@ductape/sdk 0.0.4-v43 → 0.0.4-v44

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 (39) hide show
  1. package/dist/apps/services/app.service.js +16 -69
  2. package/dist/apps/services/app.service.js.map +1 -1
  3. package/dist/apps/validators/joi-validators/create.appWebhook.validator.d.ts +1 -2
  4. package/dist/apps/validators/joi-validators/create.appWebhook.validator.js +2 -15
  5. package/dist/apps/validators/joi-validators/create.appWebhook.validator.js.map +1 -1
  6. package/dist/apps/validators/joi-validators/update.appWebhook.validator.d.ts +1 -2
  7. package/dist/apps/validators/joi-validators/update.appWebhook.validator.js +2 -14
  8. package/dist/apps/validators/joi-validators/update.appWebhook.validator.js.map +1 -1
  9. package/dist/database/adapters/dynamodb.adapter.d.ts +8 -0
  10. package/dist/database/adapters/dynamodb.adapter.js +243 -11
  11. package/dist/database/adapters/dynamodb.adapter.js.map +1 -1
  12. package/dist/database/adapters/mongodb.adapter.d.ts +1 -0
  13. package/dist/database/adapters/mongodb.adapter.js +170 -5
  14. package/dist/database/adapters/mongodb.adapter.js.map +1 -1
  15. package/dist/database/adapters/mysql.adapter.d.ts +5 -0
  16. package/dist/database/adapters/mysql.adapter.js +215 -19
  17. package/dist/database/adapters/mysql.adapter.js.map +1 -1
  18. package/dist/database/adapters/postgresql.adapter.d.ts +5 -0
  19. package/dist/database/adapters/postgresql.adapter.js +199 -15
  20. package/dist/database/adapters/postgresql.adapter.js.map +1 -1
  21. package/dist/database/database.service.d.ts +5 -0
  22. package/dist/database/database.service.js +45 -95
  23. package/dist/database/database.service.js.map +1 -1
  24. package/dist/database/types/aggregation.types.d.ts +28 -28
  25. package/dist/database/types/database.types.d.ts +2 -1
  26. package/dist/database/types/database.types.js +1 -0
  27. package/dist/database/types/database.types.js.map +1 -1
  28. package/dist/database/types/index.types.d.ts +20 -20
  29. package/dist/database/types/migration.types.d.ts +12 -12
  30. package/dist/database/types/query.types.d.ts +59 -28
  31. package/dist/index.d.ts +169 -142
  32. package/dist/index.js +196 -169
  33. package/dist/index.js.map +1 -1
  34. package/dist/processor/services/processor.service.js +51 -35
  35. package/dist/processor/services/processor.service.js.map +1 -1
  36. package/dist/test/test.processor.js +1 -3
  37. package/dist/test/test.processor.js.map +1 -1
  38. package/dist/types/appBuilder.types.d.ts +1 -1
  39. package/package.json +1 -1
@@ -297,15 +297,27 @@ class ProcessorService {
297
297
  await this.productBuilderService.initializeProductByTag(product_tag);
298
298
  const { version, envs: appEnvs } = await this.productBuilderService.fetchApp(access_tag);
299
299
  const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(access_tag);
300
- const { webhooks } = app.versions.find((data) => data.tag === version);
300
+ const appVersion = app.versions.find((data) => data.tag === version);
301
+ if (!appVersion) {
302
+ throw new Error(`Version ${version} not found for app ${access_tag}`);
303
+ }
304
+ const { webhooks, actions } = appVersion;
301
305
  if (!webhooks) {
302
306
  throw new Error(`Webhooks not found for app ${access_tag}`);
303
307
  }
308
+ if (!actions) {
309
+ throw new Error(`Actions not found for app ${access_tag}`);
310
+ }
304
311
  await validators_1.RegisterWebhookEnvSchema.validateAsync(envs);
305
312
  const webhook = webhooks.find((data) => data.tag === webhook_tag);
306
313
  if (!webhook) {
307
314
  throw new Error(`Webhook tag ${webhook_tag} not found`);
308
315
  }
316
+ // Get the action associated with this webhook
317
+ const action = actions.find((act) => act.tag === webhook.action);
318
+ if (!action) {
319
+ throw new Error(`Action ${webhook.action} not found for webhook ${webhook_tag}`);
320
+ }
309
321
  const productEnvs = await this.productBuilderService.fetchEnvs();
310
322
  productEnvs.map((env) => {
311
323
  const exists = envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
@@ -314,6 +326,7 @@ class ProcessorService {
314
326
  }
315
327
  });
316
328
  const dataArray = await Promise.all(envs.map(async (env) => {
329
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
317
330
  await this.validateActionDataMappingInput(env.auth, types_1.WebhookEventTypes.WEBHOOK_REGISTER);
318
331
  const productEnvData = productEnvs.find((data) => data.slug === env.slug);
319
332
  if (!productEnvData) {
@@ -324,44 +337,47 @@ class ProcessorService {
324
337
  throw new Error(`Error finding env data for ${env.slug}`);
325
338
  }
326
339
  const { app_env_slug: appEnv, product_env_slug: productEnv } = envData;
327
- const envWebhookData = webhook.envs.find((webhookEnv) => webhookEnv.slug === appEnv);
328
- if (!envWebhookData) {
329
- throw new Error(`Error finding webhook registration sample ${webhook_tag} for env ${env.slug}`);
340
+ // Get the action's environment configuration
341
+ const actionEnvConfig = (_a = action.envs) === null || _a === void 0 ? void 0 : _a.find((actionEnv) => actionEnv.slug === appEnv);
342
+ if (!actionEnvConfig) {
343
+ throw new Error(`Action ${action.tag} is not configured for env ${appEnv}`);
330
344
  }
331
345
  const uuid = (0, uuid_1.v4)();
332
346
  const url = `${urls_1.WEBHOOK_BASE_URL}/webhooks/v1/process/${uuid}`;
333
347
  let active = false;
334
- if (envWebhookData.sample) {
335
- const samples = {
336
- query: envWebhookData.sample_data.filter((data) => data.parent_key === 'query'),
337
- params: envWebhookData.sample_data.filter((data) => data.parent_key === 'params'),
338
- body: envWebhookData.sample_data.filter((data) => data.parent_key === 'body'),
339
- headers: envWebhookData.sample_data.filter((data) => data.parent_key === 'headers'),
340
- };
341
- let payload = (await this.constructJSONDataPayloads(env.auth, {}, samples, {
342
- app: access_tag,
343
- event: '',
344
- input: env.auth,
345
- type: types_1.FeatureEventTypes.ACTION,
346
- retries: 0,
347
- allow_fail: false,
348
- }));
349
- const { updatedObj, replacedUrl } = (0, processor_utils_1.updateUrlsInObject)(payload, url);
350
- if (replacedUrl && replacedUrl !== env.url && replacedUrl) {
351
- throw new Error(`Ductape expects the url ${replacedUrl} in request body to match inputted url ${env.url}`);
352
- }
353
- const exists = await this.fetchEnv(env.slug, {});
354
- if (!exists) {
355
- throw new Error(`Env ${env.slug} does not exist`);
356
- }
357
- payload = updatedObj;
358
- if (!replacedUrl) {
359
- payload.body.url = url;
360
- }
361
- const parsedUrl = new URL(envWebhookData.registration_url);
362
- await this.sendActionRequest(parsedUrl.origin, parsedUrl.pathname, payload, envWebhookData.method, env.slug);
363
- active = true;
364
- }
348
+ // Construct the registration payload using the action's configuration
349
+ const samples = {
350
+ query: ((_c = (_b = action.query) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.filter((data) => data.parent_key === 'query')) || [],
351
+ params: ((_e = (_d = action.params) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.filter((data) => data.parent_key === 'params')) || [],
352
+ body: ((_g = (_f = action.body) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.filter((data) => data.parent_key === 'body')) || [],
353
+ headers: ((_j = (_h = action.headers) === null || _h === void 0 ? void 0 : _h.data) === null || _j === void 0 ? void 0 : _j.filter((data) => data.parent_key === 'headers')) || [],
354
+ };
355
+ let payload = (await this.constructJSONDataPayloads(env.auth, {}, samples, {
356
+ app: access_tag,
357
+ event: '',
358
+ input: env.auth,
359
+ type: types_1.FeatureEventTypes.ACTION,
360
+ retries: 0,
361
+ allow_fail: false,
362
+ }));
363
+ const { updatedObj, replacedUrl } = (0, processor_utils_1.updateUrlsInObject)(payload, url);
364
+ if (replacedUrl && replacedUrl !== env.url && replacedUrl) {
365
+ throw new Error(`Ductape expects the url ${replacedUrl} in request body to match inputted url ${env.url}`);
366
+ }
367
+ const exists = await this.fetchEnv(env.slug, {});
368
+ if (!exists) {
369
+ throw new Error(`Env ${env.slug} does not exist`);
370
+ }
371
+ payload = updatedObj;
372
+ if (!replacedUrl) {
373
+ payload.body.url = url;
374
+ }
375
+ // Use the action's resource and base_url to construct the registration URL
376
+ const baseUrl = actionEnvConfig.base_url || action.base_url || '';
377
+ const resource = action.resource || '';
378
+ const registrationUrl = new URL(resource, baseUrl);
379
+ await this.sendActionRequest(registrationUrl.origin, registrationUrl.pathname, payload, action.method, env.slug);
380
+ active = true;
365
381
  return {
366
382
  appEnv,
367
383
  productEnv,