@ductape/sdk 0.0.4-v44 → 0.0.4-v45
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.
- package/dist/apps/services/app.service.js +0 -17
- package/dist/apps/services/app.service.js.map +1 -1
- package/dist/apps/validators/joi-validators/create.appWebhook.validator.js +1 -1
- package/dist/apps/validators/joi-validators/create.appWebhook.validator.js.map +1 -1
- package/dist/index.d.ts +1 -7
- package/dist/index.js +0 -9
- package/dist/index.js.map +1 -1
- package/dist/processor/services/processor.service.d.ts +1 -3
- package/dist/processor/services/processor.service.js +0 -106
- package/dist/processor/services/processor.service.js.map +1 -1
- package/dist/types/appBuilder.types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -59,9 +59,7 @@ const handlebars_1 = require("handlebars");
|
|
|
59
59
|
const functions_utils_1 = require("../../products/services/utils/functions.utils");
|
|
60
60
|
const string_utils_1 = require("../../products/services/utils/string.utils");
|
|
61
61
|
const create_productFeature_validator_1 = require("../../products/validators/joi-validators/create.productFeature.validator");
|
|
62
|
-
const validators_1 = require("../../products/validators");
|
|
63
62
|
const uuid_1 = require("uuid");
|
|
64
|
-
const urls_1 = require("../../api/urls");
|
|
65
63
|
//import { createBrokerService } from './messagebrokers';
|
|
66
64
|
const date_fns_1 = require("date-fns");
|
|
67
65
|
const mongo_repo_1 = require("../repos/mongo.repo");
|
|
@@ -292,110 +290,6 @@ class ProcessorService {
|
|
|
292
290
|
throw new Error("Invalid/Expired token");
|
|
293
291
|
}
|
|
294
292
|
}
|
|
295
|
-
async registerWebhook(data) {
|
|
296
|
-
const { product: product_tag, access_tag, webhook_tag, envs } = data;
|
|
297
|
-
await this.productBuilderService.initializeProductByTag(product_tag);
|
|
298
|
-
const { version, envs: appEnvs } = await this.productBuilderService.fetchApp(access_tag);
|
|
299
|
-
const app = await this.productBuilderService.fetchThirdPartyAppByAccessTag(access_tag);
|
|
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;
|
|
305
|
-
if (!webhooks) {
|
|
306
|
-
throw new Error(`Webhooks not found for app ${access_tag}`);
|
|
307
|
-
}
|
|
308
|
-
if (!actions) {
|
|
309
|
-
throw new Error(`Actions not found for app ${access_tag}`);
|
|
310
|
-
}
|
|
311
|
-
await validators_1.RegisterWebhookEnvSchema.validateAsync(envs);
|
|
312
|
-
const webhook = webhooks.find((data) => data.tag === webhook_tag);
|
|
313
|
-
if (!webhook) {
|
|
314
|
-
throw new Error(`Webhook tag ${webhook_tag} not found`);
|
|
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
|
-
}
|
|
321
|
-
const productEnvs = await this.productBuilderService.fetchEnvs();
|
|
322
|
-
productEnvs.map((env) => {
|
|
323
|
-
const exists = envs.findIndex((dbEnv) => dbEnv.slug === env.slug);
|
|
324
|
-
if (exists === -1) {
|
|
325
|
-
throw new Error(`Product env ${env.slug} is not defined, please provide connection details`);
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
const dataArray = await Promise.all(envs.map(async (env) => {
|
|
329
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
330
|
-
await this.validateActionDataMappingInput(env.auth, types_1.WebhookEventTypes.WEBHOOK_REGISTER);
|
|
331
|
-
const productEnvData = productEnvs.find((data) => data.slug === env.slug);
|
|
332
|
-
if (!productEnvData) {
|
|
333
|
-
throw new Error(`Error finding product env ${env.slug}`);
|
|
334
|
-
}
|
|
335
|
-
const envData = productEnvData.envs.find((productEnvMap) => productEnvMap.product_env_slug === env.slug);
|
|
336
|
-
if (!envData) {
|
|
337
|
-
throw new Error(`Error finding env data for ${env.slug}`);
|
|
338
|
-
}
|
|
339
|
-
const { app_env_slug: appEnv, product_env_slug: productEnv } = envData;
|
|
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}`);
|
|
344
|
-
}
|
|
345
|
-
const uuid = (0, uuid_1.v4)();
|
|
346
|
-
const url = `${urls_1.WEBHOOK_BASE_URL}/webhooks/v1/process/${uuid}`;
|
|
347
|
-
let active = false;
|
|
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;
|
|
381
|
-
return {
|
|
382
|
-
appEnv,
|
|
383
|
-
productEnv,
|
|
384
|
-
uuid,
|
|
385
|
-
url: env.url,
|
|
386
|
-
method: env.method,
|
|
387
|
-
access_tag,
|
|
388
|
-
webhook_tag,
|
|
389
|
-
version,
|
|
390
|
-
sender_workspace_id: app.workspace_id,
|
|
391
|
-
receiver_workspace_id: this.getUserAccess().workspace_id,
|
|
392
|
-
app_tag: app.tag,
|
|
393
|
-
product_tag,
|
|
394
|
-
active,
|
|
395
|
-
};
|
|
396
|
-
}));
|
|
397
|
-
await this.webhookApi.registerWebhooks(dataArray, this.getUserAccess());
|
|
398
|
-
}
|
|
399
293
|
async generateWebhookLink(data) {
|
|
400
294
|
const { product: product_tag, access_tag, webhook_tag, env: product_env, url, method } = data;
|
|
401
295
|
await this.productBuilderService.initializeProductByTag(product_tag);
|