feat: debug log incoming webhook requests
This commit is contained in:
@@ -2,6 +2,7 @@ import Crypto from 'node:crypto';
|
|||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { IRequest, ITriggerItem } from '@automatisch/types';
|
import { IRequest, ITriggerItem } from '@automatisch/types';
|
||||||
|
|
||||||
|
import logger from '../../helpers/logger';
|
||||||
import Flow from '../../models/flow';
|
import Flow from '../../models/flow';
|
||||||
import { processTrigger } from '../../services/trigger';
|
import { processTrigger } from '../../services/trigger';
|
||||||
import actionQueue from '../../queues/action';
|
import actionQueue from '../../queues/action';
|
||||||
@@ -13,8 +14,19 @@ import {
|
|||||||
} from '../../helpers/remove-job-configuration';
|
} from '../../helpers/remove-job-configuration';
|
||||||
|
|
||||||
export default async (request: IRequest, response: Response) => {
|
export default async (request: IRequest, response: Response) => {
|
||||||
|
const flowId = request.params.flowId;
|
||||||
|
|
||||||
|
// in case it's our built-in generic webhook trigger
|
||||||
|
let computedRequestPayload = {
|
||||||
|
headers: request.headers,
|
||||||
|
body: request.body,
|
||||||
|
query: request.query,
|
||||||
|
};
|
||||||
|
logger.debug(`Handling incoming webhook request at ${request.originalUrl}.`);
|
||||||
|
logger.debug(computedRequestPayload);
|
||||||
|
|
||||||
const flow = await Flow.query()
|
const flow = await Flow.query()
|
||||||
.findById(request.params.flowId)
|
.findById(flowId)
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
const user = await flow.$relatedQuery('user');
|
const user = await flow.$relatedQuery('user');
|
||||||
@@ -56,26 +68,19 @@ export default async (request: IRequest, response: Response) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// in case trigger type is 'webhook'
|
// in case trigger type is 'webhook'
|
||||||
let payload = request.body;
|
if (!isWebhookApp) {
|
||||||
|
computedRequestPayload = request.body;
|
||||||
// in case it's our built-in generic webhook trigger
|
|
||||||
if (isWebhookApp) {
|
|
||||||
payload = {
|
|
||||||
headers: request.headers,
|
|
||||||
body: request.body,
|
|
||||||
query: request.query,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const triggerItem: ITriggerItem = {
|
const triggerItem: ITriggerItem = {
|
||||||
raw: payload,
|
raw: computedRequestPayload,
|
||||||
meta: {
|
meta: {
|
||||||
internalId: Crypto.randomUUID(),
|
internalId: Crypto.randomUUID(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const { flowId, executionId } = await processTrigger({
|
const { executionId } = await processTrigger({
|
||||||
flowId: flow.id,
|
flowId,
|
||||||
stepId: triggerStep.id,
|
stepId: triggerStep.id,
|
||||||
triggerItem,
|
triggerItem,
|
||||||
testRun,
|
testRun,
|
||||||
|
Reference in New Issue
Block a user