Skip to content

Commit

Permalink
fix(core): Fix expressions in webhook nodes(Form, Webhook) to access …
Browse files Browse the repository at this point in the history
…previous node's data (#10247)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
  • Loading branch information
michael-radency and netroy authored Aug 1, 2024
1 parent 1608d25 commit 88a1701
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/cli/src/WebhookHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ export async function executeWebhook(
// Prepare everything that is needed to run the workflow
const additionalData = await WorkflowExecuteAdditionalData.getBase();

if (executionId) {
additionalData.executionId = executionId;
}

// Get the responseMode
const responseMode = workflow.expression.getSimpleParameterValue(
workflowStartNode,
Expand Down Expand Up @@ -359,6 +363,7 @@ export async function executeWebhook(
additionalData,
NodeExecuteFunctions,
executionMode,
runExecutionData ?? null,
);
Container.get(WorkflowStatisticsService).emit('nodeFetchedData', {
workflowId: workflow.id,
Expand Down
24 changes: 18 additions & 6 deletions packages/core/src/NodeExecuteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4212,8 +4212,9 @@ export function getExecuteWebhookFunctions(
mode: WorkflowExecuteMode,
webhookData: IWebhookData,
closeFunctions: CloseFunction[],
runExecutionData: IRunExecutionData | null,
): IWebhookFunctions {
return ((workflow: Workflow, node: INode) => {
return ((workflow: Workflow, node: INode, runExecutionData: IRunExecutionData | null) => {
return {
...getCommonWorkflowFunctions(workflow, node, additionalData),
getBodyData(): IDataObject {
Expand Down Expand Up @@ -4274,10 +4275,21 @@ export function getExecuteWebhookFunctions(
fallbackValue?: any,
options?: IGetNodeParameterOptions,
): NodeParameterValueType | object => {
const runExecutionData: IRunExecutionData | null = null;
const itemIndex = 0;
const runIndex = 0;
const connectionInputData: INodeExecutionData[] = [];

let connectionInputData: INodeExecutionData[] = [];
let executionData: IExecuteData | undefined;

if (runExecutionData?.executionData !== undefined) {
executionData = runExecutionData.executionData.nodeExecutionStack[0];

if (executionData !== undefined) {
connectionInputData = executionData.data.main[0]!;
}
}

const additionalKeys = getAdditionalKeys(additionalData, mode, runExecutionData);

return getNodeParameter(
workflow,
Expand All @@ -4288,8 +4300,8 @@ export function getExecuteWebhookFunctions(
parameterName,
itemIndex,
mode,
getAdditionalKeys(additionalData, mode, null),
undefined,
additionalKeys,
executionData,
fallbackValue,
options,
);
Expand Down Expand Up @@ -4336,5 +4348,5 @@ export function getExecuteWebhookFunctions(
},
nodeHelpers: getNodeHelperFunctions(additionalData, workflow.id),
};
})(workflow, node);
})(workflow, node, runExecutionData);
}
1 change: 1 addition & 0 deletions packages/workflow/src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ export interface IGetExecuteWebhookFunctions {
mode: WorkflowExecuteMode,
webhookData: IWebhookData,
closeFunctions: CloseFunction[],
runExecutionData: IRunExecutionData | null,
): IWebhookFunctions;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/workflow/src/Workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,7 @@ export class Workflow {
additionalData: IWorkflowExecuteAdditionalData,
nodeExecuteFunctions: INodeExecuteFunctions,
mode: WorkflowExecuteMode,
runExecutionData: IRunExecutionData | null,
): Promise<IWebhookResponseData> {
const nodeType = this.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
if (nodeType === undefined) {
Expand All @@ -1258,6 +1259,7 @@ export class Workflow {
mode,
webhookData,
closeFunctions,
runExecutionData,
);
return nodeType instanceof Node
? await nodeType.webhook(context)
Expand Down

0 comments on commit 88a1701

Please sign in to comment.