Make it use of full webhook path more generic

This commit is contained in:
Jan Oberhauser 2020-06-10 15:39:15 +02:00
parent 1f4b8f8999
commit 5ed86670a8
8 changed files with 33 additions and 19 deletions

View file

@ -211,7 +211,7 @@ export class ActiveWorkflowRunner {
*/ */
async addWorkflowWebhooks(workflow: Workflow, additionalData: IWorkflowExecuteAdditionalDataWorkflow, mode: WorkflowExecuteMode): Promise<void> { async addWorkflowWebhooks(workflow: Workflow, additionalData: IWorkflowExecuteAdditionalDataWorkflow, mode: WorkflowExecuteMode): Promise<void> {
const webhooks = WebhookHelpers.getWorkflowWebhooks(workflow, additionalData); const webhooks = WebhookHelpers.getWorkflowWebhooks(workflow, additionalData);
let path = ''; let path = '' as string | undefined;
for (const webhookData of webhooks) { for (const webhookData of webhooks) {
@ -221,12 +221,20 @@ export class ActiveWorkflowRunner {
path = node.parameters.path as string; path = node.parameters.path as string;
if (node.parameters.path === undefined) { if (node.parameters.path === undefined) {
path = workflow.getSimpleParameterValue(node, webhookData.webhookDescription['path'], 'GET') as string; path = workflow.getSimpleParameterValue(node, webhookData.webhookDescription['path']) as string | undefined;
if (path === undefined) {
// TODO: Use a proper logger
console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflow.id}".`);
continue;
}
} }
const isFullPath: boolean = workflow.getSimpleParameterValue(node, webhookData.webhookDescription['isFullPath'], false) as boolean;
const webhook = { const webhook = {
workflowId: webhookData.workflowId, workflowId: webhookData.workflowId,
webhookPath: NodeHelpers.getNodeWebhookPath(workflow.id as string, node, path), webhookPath: NodeHelpers.getNodeWebhookPath(workflow.id as string, node, path, isFullPath),
node: node.name, node: node.name,
method: webhookData.httpMethod, method: webhookData.httpMethod,
} as IWebhookDb; } as IWebhookDb;
@ -257,7 +265,7 @@ export class ActiveWorkflowRunner {
// it's a error runnig the webhook methods (checkExists, create) // it's a error runnig the webhook methods (checkExists, create)
errorMessage = error.detail; errorMessage = error.detail;
} else { } else {
errorMessage = error; errorMessage = error.message;
} }
throw new Error(errorMessage); throw new Error(errorMessage);

View file

@ -46,7 +46,6 @@ import {
WorkflowCredentials, WorkflowCredentials,
WebhookHelpers, WebhookHelpers,
WorkflowExecuteAdditionalData, WorkflowExecuteAdditionalData,
WorkflowHelpers,
WorkflowRunner, WorkflowRunner,
GenericHelpers, GenericHelpers,
} from './'; } from './';

View file

@ -289,7 +289,8 @@ export function getNodeWebhookUrl(name: string, workflow: Workflow, node: INode,
return undefined; return undefined;
} }
return NodeHelpers.getNodeWebhookUrl(baseUrl, workflow.id!, node, path.toString()); const isFullPath: boolean = workflow.getSimpleParameterValue(node, webhookDescription['isFullPath'], false) as boolean;
return NodeHelpers.getNodeWebhookUrl(baseUrl, workflow.id!, node, path.toString(), isFullPath);
} }

View file

@ -110,8 +110,9 @@ export default mixins(
const workflowId = this.$store.getters.workflowId; const workflowId = this.$store.getters.workflowId;
const path = this.getValue(webhookData, 'path'); const path = this.getValue(webhookData, 'path');
const isFullPath = this.getValue(webhookData, 'isFullPath') as unknown as boolean || false;
return NodeHelpers.getNodeWebhookUrl(baseUrl, workflowId, this.node, path); return NodeHelpers.getNodeWebhookUrl(baseUrl, workflowId, this.node, path, isFullPath);
}, },
}, },
watch: { watch: {

View file

@ -77,6 +77,7 @@ export class Webhook implements INodeType {
{ {
name: 'default', name: 'default',
httpMethod: '={{$parameter["httpMethod"]}}', httpMethod: '={{$parameter["httpMethod"]}}',
isFullPath: true,
responseCode: '={{$parameter["responseCode"]}}', responseCode: '={{$parameter["responseCode"]}}',
responseMode: '={{$parameter["responseMode"]}}', responseMode: '={{$parameter["responseMode"]}}',
responseData: '={{$parameter["responseData"]}}', responseData: '={{$parameter["responseData"]}}',

View file

@ -520,8 +520,9 @@ export interface IWebhookData {
} }
export interface IWebhookDescription { export interface IWebhookDescription {
[key: string]: WebhookHttpMethod | WebhookResponseMode | string | undefined; [key: string]: WebhookHttpMethod | WebhookResponseMode | boolean | string | undefined;
httpMethod: WebhookHttpMethod | string; httpMethod: WebhookHttpMethod | string;
isFullPath?: boolean;
name: string; name: string;
path: string; path: string;
responseBinaryPropertyName?: string; responseBinaryPropertyName?: string;

View file

@ -755,7 +755,7 @@ export function getNodeWebhooks(workflow: Workflow, node: INode, additionalData:
const returnData: IWebhookData[] = []; const returnData: IWebhookData[] = [];
for (const webhookDescription of nodeType.description.webhooks) { for (const webhookDescription of nodeType.description.webhooks) {
let nodeWebhookPath = workflow.getSimpleParameterValue(node, webhookDescription['path'], 'GET'); let nodeWebhookPath = workflow.getSimpleParameterValue(node, webhookDescription['path']);
if (nodeWebhookPath === undefined) { if (nodeWebhookPath === undefined) {
// TODO: Use a proper logger // TODO: Use a proper logger
console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflowId}".`); console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflowId}".`);
@ -768,7 +768,8 @@ export function getNodeWebhooks(workflow: Workflow, node: INode, additionalData:
nodeWebhookPath = nodeWebhookPath.slice(1); nodeWebhookPath = nodeWebhookPath.slice(1);
} }
const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath); const isFullPath: boolean = workflow.getSimpleParameterValue(node, webhookDescription['isFullPath'], false) as boolean;
const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath, isFullPath);
const httpMethod = workflow.getSimpleParameterValue(node, webhookDescription['httpMethod'], 'GET'); const httpMethod = workflow.getSimpleParameterValue(node, webhookDescription['httpMethod'], 'GET');
@ -808,7 +809,7 @@ export function getNodeWebhooksBasic(workflow: Workflow, node: INode): IWebhookD
const returnData: IWebhookData[] = []; const returnData: IWebhookData[] = [];
for (const webhookDescription of nodeType.description.webhooks) { for (const webhookDescription of nodeType.description.webhooks) {
let nodeWebhookPath = workflow.getSimpleParameterValue(node, webhookDescription['path'], 'GET'); let nodeWebhookPath = workflow.getSimpleParameterValue(node, webhookDescription['path']);
if (nodeWebhookPath === undefined) { if (nodeWebhookPath === undefined) {
// TODO: Use a proper logger // TODO: Use a proper logger
console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflowId}".`); console.error(`No webhook path could be found for node "${node.name}" in workflow "${workflowId}".`);
@ -821,9 +822,11 @@ export function getNodeWebhooksBasic(workflow: Workflow, node: INode): IWebhookD
nodeWebhookPath = nodeWebhookPath.slice(1); nodeWebhookPath = nodeWebhookPath.slice(1);
} }
const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath); const isFullPath: boolean = workflow.getSimpleParameterValue(node, webhookDescription['isFullPath'], false) as boolean;
const httpMethod = workflow.getSimpleParameterValue(node, webhookDescription['httpMethod'], 'GET'); const path = getNodeWebhookPath(workflowId, node, nodeWebhookPath, isFullPath);
const httpMethod = workflow.getSimpleParameterValue(node, webhookDescription['httpMethod']);
if (httpMethod === undefined) { if (httpMethod === undefined) {
// TODO: Use a proper logger // TODO: Use a proper logger
@ -854,12 +857,12 @@ export function getNodeWebhooksBasic(workflow: Workflow, node: INode): IWebhookD
* @param {string} path * @param {string} path
* @returns {string} * @returns {string}
*/ */
export function getNodeWebhookPath(workflowId: string, node: INode, path: string): string { export function getNodeWebhookPath(workflowId: string, node: INode, path: string, isFullPath?: boolean): string {
let webhookPath = ''; let webhookPath = '';
if (node.webhookPath === undefined) { if (node.webhookPath === undefined) {
webhookPath = `${workflowId}/${encodeURIComponent(node.name.toLowerCase())}/${path}`; webhookPath = `${workflowId}/${encodeURIComponent(node.name.toLowerCase())}/${path}`;
} else { } else {
if (node.type === 'n8n-nodes-base.webhook') { if (isFullPath === true) {
return path; return path;
} }
webhookPath = `${node.webhookPath}/${path}`; webhookPath = `${node.webhookPath}/${path}`;
@ -876,11 +879,11 @@ export function getNodeWebhookPath(workflowId: string, node: INode, path: string
* @param {string} workflowId * @param {string} workflowId
* @param {string} nodeTypeName * @param {string} nodeTypeName
* @param {string} path * @param {string} path
* @param {boolean} isFullPath
* @returns {string} * @returns {string}
*/ */
export function getNodeWebhookUrl(baseUrl: string, workflowId: string, node: INode, path: string): string { export function getNodeWebhookUrl(baseUrl: string, workflowId: string, node: INode, path: string, isFullPath?: boolean): string {
// return `${baseUrl}/${workflowId}/${nodeTypeName}/${path}`; return `${baseUrl}/${getNodeWebhookPath(workflowId, node, path, isFullPath)}`;
return `${baseUrl}/${getNodeWebhookPath(workflowId, node, path)}`;
} }

View file

@ -715,7 +715,7 @@ export class Workflow {
* @returns {(string | undefined)} * @returns {(string | undefined)}
* @memberof Workflow * @memberof Workflow
*/ */
getSimpleParameterValue(node: INode, parameterValue: string | undefined, defaultValue?: boolean | number | string): boolean | number | string | undefined { getSimpleParameterValue(node: INode, parameterValue: string | boolean | undefined, defaultValue?: boolean | number | string): boolean | number | string | undefined {
if (parameterValue === undefined) { if (parameterValue === undefined) {
// Value is not set so return the default // Value is not set so return the default
return defaultValue; return defaultValue;