refactor(webhook): remove singleton webhook logic
This commit is contained in:
@@ -35,9 +35,6 @@ export default defineTrigger({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
useSingletonWebhook: true,
|
|
||||||
singletonWebhookRefValueParameter: 'phoneNumberSid',
|
|
||||||
|
|
||||||
async run($) {
|
async run($) {
|
||||||
const dataItem = {
|
const dataItem = {
|
||||||
raw: $.request.body,
|
raw: $.request.body,
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
import path from 'node:path';
|
|
||||||
|
|
||||||
import Connection from '../../models/connection.js';
|
|
||||||
import logger from '../../helpers/logger.js';
|
|
||||||
import handler from '../../helpers/webhook-handler.js';
|
|
||||||
|
|
||||||
export default async (request, response) => {
|
|
||||||
const computedRequestPayload = {
|
|
||||||
headers: request.headers,
|
|
||||||
body: request.body,
|
|
||||||
query: request.query,
|
|
||||||
params: request.params,
|
|
||||||
};
|
|
||||||
logger.debug(`Handling incoming webhook request at ${request.originalUrl}.`);
|
|
||||||
logger.debug(JSON.stringify(computedRequestPayload, null, 2));
|
|
||||||
|
|
||||||
const { connectionId } = request.params;
|
|
||||||
|
|
||||||
const connection = await Connection.query()
|
|
||||||
.findById(connectionId)
|
|
||||||
.throwIfNotFound();
|
|
||||||
|
|
||||||
if (!(await connection.verifyWebhook(request))) {
|
|
||||||
return response.sendStatus(401);
|
|
||||||
}
|
|
||||||
|
|
||||||
const triggerSteps = await connection
|
|
||||||
.$relatedQuery('triggerSteps')
|
|
||||||
.where('webhook_path', path.join(request.baseUrl, request.path));
|
|
||||||
|
|
||||||
if (triggerSteps.length === 0) return response.sendStatus(404);
|
|
||||||
|
|
||||||
for (const triggerStep of triggerSteps) {
|
|
||||||
await handler(triggerStep.flowId, request, response);
|
|
||||||
}
|
|
||||||
|
|
||||||
response.sendStatus(204);
|
|
||||||
};
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import { URL } from 'node:url';
|
import { URL } from 'node:url';
|
||||||
import get from 'lodash.get';
|
|
||||||
import Base from './base.js';
|
import Base from './base.js';
|
||||||
import App from './app.js';
|
import App from './app.js';
|
||||||
import Flow from './flow.js';
|
import Flow from './flow.js';
|
||||||
@@ -109,25 +108,10 @@ class Step extends Base {
|
|||||||
|
|
||||||
if (!triggerCommand) return null;
|
if (!triggerCommand) return null;
|
||||||
|
|
||||||
const { useSingletonWebhook, singletonWebhookRefValueParameter, type } =
|
const isWebhook = triggerCommand.type === 'webhook';
|
||||||
triggerCommand;
|
|
||||||
|
|
||||||
const isWebhook = type === 'webhook';
|
|
||||||
|
|
||||||
if (!isWebhook) return null;
|
if (!isWebhook) return null;
|
||||||
|
|
||||||
if (singletonWebhookRefValueParameter) {
|
|
||||||
const parameterValue = get(
|
|
||||||
this.parameters,
|
|
||||||
singletonWebhookRefValueParameter
|
|
||||||
);
|
|
||||||
return `/webhooks/connections/${this.connectionId}/${parameterValue}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (useSingletonWebhook) {
|
|
||||||
return `/webhooks/connections/${this.connectionId}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.parameters.workSynchronously) {
|
if (this.parameters.workSynchronously) {
|
||||||
return `/webhooks/flows/${this.flowId}/sync`;
|
return `/webhooks/flows/${this.flowId}/sync`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import multer from 'multer';
|
|||||||
import appConfig from '../config/app.js';
|
import appConfig from '../config/app.js';
|
||||||
import webhookHandlerByFlowId from '../controllers/webhooks/handler-by-flow-id.js';
|
import webhookHandlerByFlowId from '../controllers/webhooks/handler-by-flow-id.js';
|
||||||
import webhookHandlerSyncByFlowId from '../controllers/webhooks/handler-sync-by-flow-id.js';
|
import webhookHandlerSyncByFlowId from '../controllers/webhooks/handler-sync-by-flow-id.js';
|
||||||
import webhookHandlerByConnectionIdAndRefValue from '../controllers/webhooks/handler-by-connection-id-and-ref-value.js';
|
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
const upload = multer();
|
const upload = multer();
|
||||||
@@ -39,14 +38,6 @@ function createRouteHandler(path, handler) {
|
|||||||
.post(wrappedHandler);
|
.post(wrappedHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
createRouteHandler(
|
|
||||||
'/connections/:connectionId/:refValue',
|
|
||||||
webhookHandlerByConnectionIdAndRefValue
|
|
||||||
);
|
|
||||||
createRouteHandler(
|
|
||||||
'/connections/:connectionId',
|
|
||||||
webhookHandlerByConnectionIdAndRefValue
|
|
||||||
);
|
|
||||||
createRouteHandler('/flows/:flowId/sync', webhookHandlerSyncByFlowId);
|
createRouteHandler('/flows/:flowId/sync', webhookHandlerSyncByFlowId);
|
||||||
createRouteHandler('/flows/:flowId', webhookHandlerByFlowId);
|
createRouteHandler('/flows/:flowId', webhookHandlerByFlowId);
|
||||||
createRouteHandler('/:flowId', webhookHandlerByFlowId);
|
createRouteHandler('/:flowId', webhookHandlerByFlowId);
|
||||||
|
|||||||
@@ -123,8 +123,6 @@ export const RawTriggerPropType = PropTypes.shape({
|
|||||||
showWebhookUrl: PropTypes.bool,
|
showWebhookUrl: PropTypes.bool,
|
||||||
pollInterval: PropTypes.number,
|
pollInterval: PropTypes.number,
|
||||||
description: PropTypes.string,
|
description: PropTypes.string,
|
||||||
useSingletonWebhook: PropTypes.bool,
|
|
||||||
singletonWebhookRefValueParameter: PropTypes.string,
|
|
||||||
getInterval: PropTypes.func,
|
getInterval: PropTypes.func,
|
||||||
run: PropTypes.func,
|
run: PropTypes.func,
|
||||||
testRun: PropTypes.func,
|
testRun: PropTypes.func,
|
||||||
@@ -140,8 +138,6 @@ export const TriggerPropType = PropTypes.shape({
|
|||||||
showWebhookUrl: PropTypes.bool,
|
showWebhookUrl: PropTypes.bool,
|
||||||
pollInterval: PropTypes.number,
|
pollInterval: PropTypes.number,
|
||||||
description: PropTypes.string,
|
description: PropTypes.string,
|
||||||
useSingletonWebhook: PropTypes.bool,
|
|
||||||
singletonWebhookRefValueParameter: PropTypes.string,
|
|
||||||
getInterval: PropTypes.func,
|
getInterval: PropTypes.func,
|
||||||
run: PropTypes.func,
|
run: PropTypes.func,
|
||||||
testRun: PropTypes.func,
|
testRun: PropTypes.func,
|
||||||
|
|||||||
Reference in New Issue
Block a user