@unito/integration-debugger
Version:
The Unito Integration Debugger
70 lines (69 loc) • 2.52 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const crawler_1 = require("../crawler");
/**
* Check: Webhook subscription actions
*
* When an integration supports webhooks, it is assumed that one can PUT on '/webhooks/register'.
* Where '/webhooks/register' would be the configured relative webhook subscription URL set in the registry.
*
*{
* "itemPath": "/users",
* "targetUrl": "https://integrations-platform.unito.io/webhooks/receive",
* "action": "start"
*}
*/
const check = {
label: 'Webhook - Subscribe/Unsuscribe',
prepareOnPreparedSteps: true,
validateOnError: false,
activatedByDefault: false,
prepare: async (stepResult, crawlerDriver) => {
const step = stepResult.step;
// When we receive an Item that has relations, we create a step to subscribe to changes on the item
if (step.operation === crawler_1.Operation.GetItem && step.payloadOut?.relations.length) {
const payloadIn = {
itemPath: step.path,
targetUrl: 'https://integrations-platform.unito.io/webhooks/receive',
action: 'start',
};
return [
{
path: '',
requestSchema: undefined,
schemaPath: undefined,
parentOperation: step.operation,
parentPath: step.path,
operation: crawler_1.Operation.SubscribeWebhook,
payloadIn,
headersIn: step.headersIn,
warnings: [],
errors: [],
},
];
}
else if (step.operation === crawler_1.Operation.SubscribeWebhook) {
const payloadIn = {
itemPath: step.path,
targetUrl: 'https://integrations-platform.unito.io/webhooks/receive',
action: 'stop',
};
return [
{
path: '',
requestSchema: undefined,
schemaPath: undefined,
parentOperation: step.operation,
parentPath: step.path,
operation: crawler_1.Operation.UnsubscribeWebhook,
payloadIn,
headersIn: step.headersIn,
warnings: [],
errors: [],
},
];
}
return [];
},
};
exports.default = check;
;