Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Webhook Node): Overhaul #8889

Merged
merged 40 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
89e80bd
:zap: setup, WIP
michael-radency Mar 14, 2024
73208f6
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1229…
michael-radency Mar 14, 2024
c4b1939
:zap: setup
michael-radency Mar 15, 2024
cbaaaa9
:zap: response code selector
michael-radency Mar 15, 2024
0bc3997
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1229…
michael-radency Mar 15, 2024
a590c29
:zap: url and mode in webhook json item
michael-radency Mar 15, 2024
8d4767e
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1229…
michael-radency Mar 15, 2024
dc41282
:zap: multiple cors origins support, ips whitelist
michael-radency Mar 18, 2024
4557d0e
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1229…
michael-radency Mar 18, 2024
cde2f0b
:zap: jwt auth setup
michael-radency Mar 18, 2024
5698f02
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1229…
michael-radency Mar 18, 2024
ec99b3b
:zap: jwt payload, respond with jwt token option
michael-radency Mar 19, 2024
62d8fc7
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1229…
michael-radency Mar 19, 2024
9f7c7f0
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1229…
michael-radency Mar 19, 2024
65f2665
:zap: respond to webhook configuration errors
michael-radency Mar 19, 2024
157cc6b
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1229…
michael-radency Mar 20, 2024
c1cf8d4
:zap: throw an actual node operation or api error, not just message w…
michael-radency Mar 20, 2024
c618452
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1229…
michael-radency Mar 20, 2024
d1aaf51
:zap: removed multiple methods support
michael-radency Mar 21, 2024
3af8077
:zap: responseCode selector option
michael-radency Mar 21, 2024
e5b8eb0
:zap: clean up, jwt icon update
michael-radency Mar 21, 2024
9b61137
:zap: fix for responseData option
michael-radency Mar 21, 2024
37fbed2
:zap: path description update
michael-radency Mar 21, 2024
9092533
:zap: jwt credentials update, PEM keys support
michael-radency Mar 21, 2024
fd96ea7
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1229…
michael-radency Mar 21, 2024
fd37661
:zap: credentials check fix in webhook node, options order fix
michael-radency Mar 21, 2024
e3fc996
Various copy tweaks. Reduced the number of available codes.
gandreini Mar 21, 2024
6507c10
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1229…
michael-radency Mar 22, 2024
d348ff5
:zap: shifted authentication property in ui
michael-radency Mar 22, 2024
bfaeadd
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1229…
michael-radency Mar 22, 2024
7d2747b
Merge branch 'node-1229-webhook-node-overhaul' of https://github.com/…
michael-radency Mar 22, 2024
f00b1f9
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1229…
michael-radency Mar 26, 2024
639b13f
:zap: error hint update
michael-radency Mar 26, 2024
bfaa584
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1229…
michael-radency Mar 26, 2024
d538816
:zap: test fix
michael-radency Mar 26, 2024
8533012
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1229…
michael-radency Mar 27, 2024
cc582e9
:zap: review fixes
michael-radency Mar 27, 2024
c09753c
Merge branch 'master' of https://github.com/n8n-io/n8n into node-1229…
michael-radency Mar 27, 2024
b64f2f2
:zap: clean up
michael-radency Mar 27, 2024
7e65050
:zap: e2e test fix
michael-radency Mar 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions cypress/e2e/16-webhook-node.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ const simpleWebhookCall = (options: SimpleWebhookCallOptions) => {
}

if (responseCode) {
cy.getByTestId('parameter-input-responseCode')
.find('.parameter-input')
.find('input')
.clear()
.type(responseCode.toString());
cy.get('.param-options').click();
getVisibleSelect().contains('Response Code').click();
cy.get('.parameter-item-wrapper > .parameter-input-list-wrapper').children().click();
getVisibleSelect().contains('201').click();
}

if (respondWith) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/AbstractServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ export abstract class AbstractServer {

private async setupHealthCheck() {
// health check should not care about DB connections
this.app.get('/healthz', async (req, res) => {
this.app.get('/healthz', async (_req, res) => {
res.send({ status: 'ok' });
});

const { connectionState } = Db;
this.app.use((req, res, next) => {
this.app.use((_req, res, next) => {
if (connectionState.connected) {
if (connectionState.migrated) next();
else res.send('n8n is starting up. Please wait');
Expand Down
32 changes: 25 additions & 7 deletions packages/cli/src/WebhookHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,22 @@ export const webhookRequestHandler =
const options = await webhookManager.findAccessControlOptions(path, requestedMethod);
const { allowedOrigins } = options ?? {};

res.header(
'Access-Control-Allow-Origin',
!allowedOrigins || allowedOrigins === '*' ? req.headers.origin : allowedOrigins,
);
if (allowedOrigins && allowedOrigins !== '*' && allowedOrigins !== req.headers.origin) {
const originsList = allowedOrigins.split(',');
const defaultOrigin = originsList[0];

if (originsList.length === 1) {
res.header('Access-Control-Allow-Origin', defaultOrigin);
}

if (originsList.includes(req.headers.origin as string)) {
res.header('Access-Control-Allow-Origin', req.headers.origin);
} else {
res.header('Access-Control-Allow-Origin', defaultOrigin);
}
} else {
res.header('Access-Control-Allow-Origin', req.headers.origin);
}

if (method === 'OPTIONS') {
res.header('Access-Control-Max-Age', '300');
Expand Down Expand Up @@ -262,14 +274,14 @@ export async function executeWebhook(
);
const responseCode = workflow.expression.getSimpleParameterValue(
workflowStartNode,
webhookData.webhookDescription.responseCode,
webhookData.webhookDescription.responseCode as string,
executionMode,
additionalKeys,
undefined,
200,
) as number;

const responseData = workflow.expression.getSimpleParameterValue(
const responseData = workflow.expression.getComplexParameterValue(
workflowStartNode,
webhookData.webhookDescription.responseData,
executionMode,
Expand Down Expand Up @@ -324,7 +336,7 @@ export async function executeWebhook(
// TODO: pass a custom `fileWriteStreamHandler` to create binary data files directly
});
req.body = await new Promise((resolve) => {
form.parse(req, async (err, data, files) => {
form.parse(req, async (_err, data, files) => {
normalizeFormData(data);
normalizeFormData(files);
resolve({ data, files });
Expand Down Expand Up @@ -455,6 +467,12 @@ export async function executeWebhook(
responseCallback(null, {
responseCode,
});
} else if (responseData) {
// Return the data specified in the response data option
responseCallback(null, {
data: responseData as IDataObject,
responseCode,
});
} else if (webhookResultData.webhookResponse !== undefined) {
// Data to respond with is given
responseCallback(null, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class WebhookNotFoundError extends NotFoundError {

const hintMsg =
hint === 'default'
? "Click the 'Execute workflow' button on the canvas, then try again. (In test mode, the webhook only works for one call after you click this button)"
? "Click the 'Test workflow' button on the canvas, then try again. (In test mode, the webhook only works for one call after you click this button)"
: "The workflow must be active for a production URL to run successfully. You can activate the workflow using the toggle in the top-right of the editor. Note that unlike test URL calls, production URL calls aren't shown on the canvas (only in the executions list)";

super(errorMsg, hintMsg);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Service } from 'typedi';
import { CacheService } from '@/services/cache/cache.service';
import { type IWebhookData } from 'n8n-workflow';
import type { IWebhookData } from 'n8n-workflow';
import type { IWorkflowDb } from '@/Interfaces';
import { TEST_WEBHOOK_TIMEOUT, TEST_WEBHOOK_TIMEOUT_BUFFER } from '@/constants';

Expand Down
30 changes: 29 additions & 1 deletion packages/core/src/NodeExecuteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import type {
NodeExecutionWithMetadata,
NodeHelperFunctions,
NodeParameterValueType,
NodeTypeAndVersion,
PaginationOptions,
RequestHelperFunctions,
Workflow,
Expand Down Expand Up @@ -2798,7 +2799,34 @@ const getCommonWorkflowFunctions = (
active: workflow.active,
}),
getWorkflowStaticData: (type) => workflow.getStaticData(type, node),

getChildNodes: (nodeName: string) => {
const output: NodeTypeAndVersion[] = [];
const nodes = workflow.getChildNodes(nodeName);

for (const nodeName of nodes) {
const node = workflow.nodes[nodeName];
output.push({
name: node.name,
type: node.type,
typeVersion: node.typeVersion,
});
}
return output;
},
getParentNodes: (nodeName: string) => {
const output: NodeTypeAndVersion[] = [];
const nodes = workflow.getParentNodes(nodeName);

for (const nodeName of nodes) {
const node = workflow.nodes[nodeName];
output.push({
name: node.name,
type: node.type,
typeVersion: node.typeVersion,
});
}
return output;
},
getRestApiUrl: () => additionalData.restApiUrl,
getInstanceBaseUrl: () => additionalData.instanceBaseUrl,
getInstanceId: () => Container.get(InstanceSettings).instanceId,
Expand Down
112 changes: 112 additions & 0 deletions packages/nodes-base/credentials/icons/jwt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading