mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
✨ Implement Wait functionality (#1817)
* refactor saving * refactor api layer to be stateless * refactor header details * set variable for menu height * clean up scss * clean up indentation * clean up dropdown impl * refactor no tags view * split away header * Fix tslint issues * Refactor tag manager * add tags to patch request * clean up scss * ⚡ Refactor types to entities * fix issues * update no workflow error * clean up tagscontainer * use getters instead of state * remove imports * use custom colors * clean up tags container * clean up dropdown * clean up focusoncreate * ⚡ Ignore mistaken ID in POST /workflows * ⚡ Fix undefined tag ID in PATCH /workflows * ⚡ Shorten response for POST /tags * remove scss mixins * clean up imports * ⚡ Implement validation with class-validator * address ivan's comments * implement modals * Fix lint issues * fix disabling shortcuts * fix focus issues * fix focus issues * fix focus issues with modal * fix linting issues * use dispatch * use constants for modal keys * fix focus * fix lint issues * remove unused prop * add modal root * fix lint issues * remove unused methods * fix shortcut * remove max width * ⚡ Fix duplicate entry error for pg and MySQL * update rename messaging * update order of buttons * fix firefox overflow on windows * fix dropdown height * 🔨 refactor tag crud controllers * 🧹 remove unused imports * use variable for number of items * fix dropdown spacing * ⚡ Restore type to fix build * ⚡ Fix post-refactor PATCH /workflows/:id * ⚡ Fix PATCH /workflows/:id for zero tags * ⚡ Fix usage count becoming stringified * address max's comments * fix filter spacing * fix blur bug * address most of ivan's comments * address tags type concern * remove defaults * ⚡ return tag id as string * 🔨 add hooks to tag CUD operations * 🏎 simplify timestamp pruning * remove blur event * fix onblur bug * ⚡ Fix fs import to fix build * address max's comments * implement responsive tag container * fix lint issues * update tag limits * address ivan's comments * remove rename, refactor header, implement new designs for save, remove responsive tag container * update styling * update styling * implement responsive tag container * implement header tags edit * implement header tags edit * fix lint issues * implement expandable input * minor fixes * minor fixes * use variable * rename save as * duplicate fixes * minor edit fixes * lint fixes * style fixes * hook up saving name * hook up tags * clean up impl * fix dirty state bug * update limit * update notification messages * on click outside * fix minor bug with count * lint fixes * handle minor edge cases * handle minor edge cases * handle minor bugs; fix firefox dropdown issue * Fix min width * apply tags only after api success * remove count fix * clean up workflow tags impl, fix tags delete bug * fix minor issue * fix minor spacing issue * disable wrap for ops * fix viewport root; save on click in dropdown * save button loading when saving name/tags * implement max width on tags container * implement cleaner create experience * disable edit while updating * codacy hex color * refactor tags container * fix clickability * fix workflow open and count * clean up structure * fix up lint issues * fix button size * increase workflow name limit for larger screen * tslint fixes * disable responsiveness for workflow modal * rename event * change min width for tags * clean up pr * address max's comments on styles * remove success toasts * add hover mode to name * minor fixes * refactor name preview * fix name input not to jiggle * finish up name input * Fix up add tags * clean up param * clean up scss * fix resizing name * fix resizing name * fix resize bug * clean up edit spacing * ignore on esc * fix input bug * focus input on clear * build * fix up add tags clickablity * remove scrollbars * move into folders * clean up multiple patch req * remove padding top from edit * update tags on enter * build * rollout blur on enter behavior * rollout esc behavior * fix tags bug when duplicating tags * move key to reload tags * update header spacing * build * update hex case * refactor workflow title * remove unusued prop * keep focus on error, fix bug on error * Fix bug with name / tags toggle on error * fix connection push bug * :spakles: Implement wait functionality * 🐛 Do not delete waiting executions with prune * ⚡ Improve SQLite migration to not lose execution data anymore * ⚡ Make it possible to restart waiting execution via webhook * ⚡ Add missing file * 🐛 Some more merge fixes * ⚡ Do not show error for Wait-Nodes if in time-mode * ⚡ Make $executionId available in expressions * 👕 Fix lint issue * 👕 Fix lint issue * 👕 Fix lint issue * ⚡ Set the unlimited sleep time as a variable * ⚡ Add also sleeping webhook path to config * ⚡ Make it possible to retrieve restartUrl in workflow * ⚡ Add authentication to Wait-Node in Webhook-Mode * ⚡ Return 404 when trying to restart execution via webhook which does not support it * ✨ Make it possible to set absolute time on Wait-Node * ⚡ Remove not needed imports * ⚡ Fix description format * ✨ Implement missing webhook features on Wait-Node * ⚡ Display webhook variable in NodeWebhooks * ⚡ Include also date in displayed sleep time * ⚡ Make it possible to see sleep time on node * ⚡ Make sure that no executions does get executed twice * ⚡ Add comment * ⚡ Further improvements * ⚡ Make Wait-Node easier to use * ✨ Add support for "notice" parameter type * Fixing wait node to work with queue, improved logging and execution view * Added support for mysql and pg * ✨ Add support for webhook postfix path * ✨ Make it possible to stop sleeping executions * ⚡ Fix issue with webhook paths in not webhook mode * ⚡ Remove not needed console.log * ⚡ Update TODOs * ⚡ Increase min time of workflow staying active to descrease possible issue with overlap * 👕 Fix lint issue * 🐛 Fix issues with webhooks * ⚡ Make error message clearer * ⚡ Fix issue with missing execution ID in scaling mode * Fixed execution list to correctly display waiting executins * Feature: enable webhook wait workflows to continue after specified time * Fixed linting * ⚡ Improve waiting description text * ⚡ Fix parameter display issue and rename * ⚡ Remove comment * ⚡ Do not display webhooks on Wait-Node * Changed wording from restart to resume on wait node * Fixed wording and inconsistent screen when changing resume modes * Removed dots from the descriptions * Changed docs url and renaming postfix to suffix * Changed names from sleep to wait * ⚡ Apply suggestions from ben Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com> * Some fixes by Ben * ⚡ Remove console.logs * ⚡ Fixes and improvements Co-authored-by: Mutasem <mutdmour@gmail.com> Co-authored-by: Iván Ovejero <ivov.src@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com> Co-authored-by: Omar Ajoue <krynble@gmail.com>
This commit is contained in:
887
packages/nodes-base/nodes/Wait.node.ts
Normal file
887
packages/nodes-base/nodes/Wait.node.ts
Normal file
@@ -0,0 +1,887 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
WAIT_TIME_UNLIMITED,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
IWebhookFunctions,
|
||||
IWebhookResponseData,
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import * as basicAuth from 'basic-auth';
|
||||
|
||||
import { Response } from 'express';
|
||||
|
||||
import * as fs from 'fs';
|
||||
|
||||
import * as formidable from 'formidable';
|
||||
|
||||
|
||||
function authorizationError(resp: Response, realm: string, responseCode: number, message?: string) {
|
||||
if (message === undefined) {
|
||||
message = 'Authorization problem!';
|
||||
if (responseCode === 401) {
|
||||
message = 'Authorization is required!';
|
||||
} else if (responseCode === 403) {
|
||||
message = 'Authorization data is wrong!';
|
||||
}
|
||||
}
|
||||
|
||||
resp.writeHead(responseCode, { 'WWW-Authenticate': `Basic realm="${realm}"` });
|
||||
resp.end(message);
|
||||
return {
|
||||
noWebhookResponse: true,
|
||||
};
|
||||
}
|
||||
|
||||
export class Wait implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Wait',
|
||||
name: 'wait',
|
||||
icon: 'fa:pause-circle',
|
||||
group: ['organization'],
|
||||
version: 1,
|
||||
description: 'Wait before continue with execution',
|
||||
defaults: {
|
||||
name: 'Wait',
|
||||
color: '#804050',
|
||||
},
|
||||
inputs: ['main'],
|
||||
outputs: ['main'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'httpBasicAuth',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
incomingAuthentication: [
|
||||
'basicAuth',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'httpHeaderAuth',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
incomingAuthentication: [
|
||||
'headerAuth',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
webhooks: [
|
||||
{
|
||||
name: 'default',
|
||||
httpMethod: '={{$parameter["httpMethod"]}}',
|
||||
isFullPath: true,
|
||||
responseCode: '={{$parameter["responseCode"]}}',
|
||||
responseMode: '={{$parameter["responseMode"]}}',
|
||||
responseData: '={{$parameter["responseData"]}}',
|
||||
responseBinaryPropertyName: '={{$parameter["responseBinaryPropertyName"]}}',
|
||||
responseContentType: '={{$parameter["options"]["responseContentType"]}}',
|
||||
responsePropertyName: '={{$parameter["options"]["responsePropertyName"]}}',
|
||||
responseHeaders: '={{$parameter["options"]["responseHeaders"]}}',
|
||||
path: '={{$parameter["options"]["webhookSuffix"] || ""}}',
|
||||
restartWebhook: true,
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Webhook authentication',
|
||||
name: 'incomingAuthentication',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resume: [
|
||||
'webhook',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Basic Auth',
|
||||
value: 'basicAuth',
|
||||
},
|
||||
{
|
||||
name: 'Header Auth',
|
||||
value: 'headerAuth',
|
||||
},
|
||||
{
|
||||
name: 'None',
|
||||
value: 'none',
|
||||
},
|
||||
],
|
||||
default: 'none',
|
||||
description: 'If and how incoming resume-webhook-requests to $resumeWebhookUrl should be authenticated for additional security.',
|
||||
},
|
||||
{
|
||||
displayName: 'Resume',
|
||||
name: 'resume',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'After time interval',
|
||||
value: 'timeInterval',
|
||||
description: 'Waits for a certain amount of time',
|
||||
},
|
||||
{
|
||||
name: 'At specified time',
|
||||
value: 'specificTime',
|
||||
description: 'Waits until the set date time to continue',
|
||||
},
|
||||
{
|
||||
name: 'On webhook call',
|
||||
value: 'webhook',
|
||||
description: 'Waits for a webhook call',
|
||||
},
|
||||
],
|
||||
default: 'timeInterval',
|
||||
description: 'For what the node should wait for before to continue with the execution',
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// resume:specificTime
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Date and Time',
|
||||
name: 'dateTime',
|
||||
type: 'dateTime',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resume: [
|
||||
'specificTime',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'The date and time to wait for before continuing',
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// resume:timeInterval
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Amount',
|
||||
name: 'amount',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resume: [
|
||||
'timeInterval',
|
||||
],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
numberPrecision: 2,
|
||||
},
|
||||
default: 1,
|
||||
description: 'The time to wait',
|
||||
},
|
||||
{
|
||||
displayName: 'Unit',
|
||||
name: 'unit',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resume: [
|
||||
'timeInterval',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Seconds',
|
||||
value: 'seconds',
|
||||
},
|
||||
{
|
||||
name: 'Minutes',
|
||||
value: 'minutes',
|
||||
},
|
||||
{
|
||||
name: 'Hours',
|
||||
value: 'hours',
|
||||
},
|
||||
{
|
||||
name: 'Days',
|
||||
value: 'days',
|
||||
},
|
||||
],
|
||||
default: 'hours',
|
||||
description: 'Unit of the interval value',
|
||||
},
|
||||
|
||||
|
||||
// ----------------------------------
|
||||
// resume:webhook
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'The URL to call will be generated at run time, and can be referenced under <strong>$resumeWebhookUrl</strong>. Send it somewhere before getting to this node. <a href="https://docs.n8n.io/nodes/n8n-nodes-base.wait?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=n8n-nodes-base.wait" target="_blank">More info</a>',
|
||||
name: 'webhookNotice',
|
||||
type: 'notice',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resume: [
|
||||
'webhook',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'HTTP Method',
|
||||
name: 'httpMethod',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resume: [
|
||||
'webhook',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'GET',
|
||||
value: 'GET',
|
||||
},
|
||||
{
|
||||
name: 'HEAD',
|
||||
value: 'HEAD',
|
||||
},
|
||||
{
|
||||
name: 'POST',
|
||||
value: 'POST',
|
||||
},
|
||||
],
|
||||
default: 'GET',
|
||||
description: 'The HTTP method to liste to',
|
||||
},
|
||||
{
|
||||
displayName: 'Response Code',
|
||||
name: 'responseCode',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resume: [
|
||||
'webhook',
|
||||
],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 100,
|
||||
maxValue: 599,
|
||||
},
|
||||
default: 200,
|
||||
description: 'The HTTP Response code to return',
|
||||
},
|
||||
{
|
||||
displayName: 'Response Mode',
|
||||
name: 'responseMode',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resume: [
|
||||
'webhook',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'On Received',
|
||||
value: 'onReceived',
|
||||
description: 'Returns directly with defined Response Code',
|
||||
},
|
||||
{
|
||||
name: 'Last Node',
|
||||
value: 'lastNode',
|
||||
description: 'Returns data of the last executed node',
|
||||
},
|
||||
],
|
||||
default: 'onReceived',
|
||||
description: 'When and how to respond to the webhook',
|
||||
},
|
||||
{
|
||||
displayName: 'Response Data',
|
||||
name: 'responseData',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resume: [
|
||||
'webhook',
|
||||
],
|
||||
responseMode: [
|
||||
'lastNode',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'All Entries',
|
||||
value: 'allEntries',
|
||||
description: 'Returns all the entries of the last node. Always returns an array',
|
||||
},
|
||||
{
|
||||
name: 'First Entry JSON',
|
||||
value: 'firstEntryJson',
|
||||
description: 'Returns the JSON data of the first entry of the last node. Always returns a JSON object',
|
||||
},
|
||||
{
|
||||
name: 'First Entry Binary',
|
||||
value: 'firstEntryBinary',
|
||||
description: 'Returns the binary data of the first entry of the last node. Always returns a binary file',
|
||||
},
|
||||
],
|
||||
default: 'firstEntryJson',
|
||||
description: 'What data should be returned. If it should return<br />all the itemsas array or only the first item as object',
|
||||
},
|
||||
{
|
||||
displayName: 'Property Name',
|
||||
name: 'responseBinaryPropertyName',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: 'data',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resume: [
|
||||
'webhook',
|
||||
],
|
||||
responseData: [
|
||||
'firstEntryBinary',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'Name of the binary property to return',
|
||||
},
|
||||
{
|
||||
displayName: 'Limit wait time',
|
||||
name: 'limitWaitTime',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: `If no webhook call is received, the workflow will automatically<br />
|
||||
resume execution after specified condition.`,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resume: [
|
||||
'webhook',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Limit type',
|
||||
name: 'limitType',
|
||||
type: 'options',
|
||||
default: 'afterTimeInterval',
|
||||
description: `Sets the condition for the execution to resume.<br />
|
||||
Can be a specified date or after some time.`,
|
||||
displayOptions: {
|
||||
show: {
|
||||
limitWaitTime: [
|
||||
true,
|
||||
],
|
||||
resume: [
|
||||
'webhook',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'After time interval',
|
||||
value: 'afterTimeInterval',
|
||||
},
|
||||
{
|
||||
name: 'At specified time',
|
||||
value: 'atSpecifiedTime',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Amount',
|
||||
name: 'resumeAmount',
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
limitType: [
|
||||
'afterTimeInterval',
|
||||
],
|
||||
limitWaitTime: [
|
||||
true,
|
||||
],
|
||||
resume: [
|
||||
'webhook',
|
||||
],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
numberPrecision: 2,
|
||||
},
|
||||
default: 1,
|
||||
description: 'The time to wait',
|
||||
},
|
||||
{
|
||||
displayName: 'Unit',
|
||||
name: 'resumeUnit',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
limitType: [
|
||||
'afterTimeInterval',
|
||||
],
|
||||
limitWaitTime: [
|
||||
true,
|
||||
],
|
||||
resume: [
|
||||
'webhook',
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: 'Seconds',
|
||||
value: 'seconds',
|
||||
},
|
||||
{
|
||||
name: 'Minutes',
|
||||
value: 'minutes',
|
||||
},
|
||||
{
|
||||
name: 'Hours',
|
||||
value: 'hours',
|
||||
},
|
||||
{
|
||||
name: 'Days',
|
||||
value: 'days',
|
||||
},
|
||||
],
|
||||
default: 'hours',
|
||||
description: 'Unit of the interval value',
|
||||
},
|
||||
{
|
||||
displayName: 'Max Date and Time',
|
||||
name: 'maxDateAndTime',
|
||||
type: 'dateTime',
|
||||
displayOptions: {
|
||||
show: {
|
||||
limitType: [
|
||||
'atSpecifiedTime',
|
||||
],
|
||||
limitWaitTime: [
|
||||
true,
|
||||
],
|
||||
resume: [
|
||||
'webhook',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Continue execution on the informed date',
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resume: [
|
||||
'webhook',
|
||||
],
|
||||
},
|
||||
},
|
||||
placeholder: 'Add Option',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Binary Data',
|
||||
name: 'binaryData',
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'/httpMethod': [
|
||||
'POST',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
description: 'Set to true if webhook will receive binary data',
|
||||
},
|
||||
{
|
||||
displayName: 'Binary Property',
|
||||
name: 'binaryPropertyName',
|
||||
type: 'string',
|
||||
default: 'data',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
binaryData: [
|
||||
true,
|
||||
],
|
||||
},
|
||||
},
|
||||
description: `Name of the binary property to which to write the data of<br />
|
||||
the received file. If the data gets received via "Form-Data Multipart"<br />
|
||||
it will be the prefix and a number starting with 0 will be attached to it.`,
|
||||
},
|
||||
{
|
||||
displayName: 'Response Data',
|
||||
name: 'responseData',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'/responseMode': [
|
||||
'onReceived',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
placeholder: 'success',
|
||||
description: 'Custom response data to send',
|
||||
},
|
||||
{
|
||||
displayName: 'Response Content-Type',
|
||||
name: 'responseContentType',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'/responseData': [
|
||||
'firstEntryJson',
|
||||
],
|
||||
'/responseMode': [
|
||||
'lastNode',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
placeholder: 'application/xml',
|
||||
description: 'Set a custom content-type to return if another one as the "application/json" should be returned',
|
||||
},
|
||||
{
|
||||
displayName: 'Response Headers',
|
||||
name: 'responseHeaders',
|
||||
placeholder: 'Add Response Header',
|
||||
description: 'Add headers to the webhook response',
|
||||
type: 'fixedCollection',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
name: 'entries',
|
||||
displayName: 'Entries',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Name of the header',
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Value of the header',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
displayName: 'Property Name',
|
||||
name: 'responsePropertyName',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
'/responseData': [
|
||||
'firstEntryJson',
|
||||
],
|
||||
'/responseMode': [
|
||||
'lastNode',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: 'data',
|
||||
description: 'Name of the property to return the data of instead of the whole JSON',
|
||||
},
|
||||
{
|
||||
displayName: 'Webhook Suffix',
|
||||
name: 'webhookSuffix',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'webhook',
|
||||
description: 'The webhook suffix path that will be appended to the restart URL. Important: Does currently not support expressions.',
|
||||
},
|
||||
// {
|
||||
// displayName: 'Raw Body',
|
||||
// name: 'rawBody',
|
||||
// type: 'boolean',
|
||||
// displayOptions: {
|
||||
// hide: {
|
||||
// binaryData: [
|
||||
// true,
|
||||
// ],
|
||||
// },
|
||||
// },
|
||||
// default: false,
|
||||
// description: 'Raw body (binary)',
|
||||
// },
|
||||
],
|
||||
},
|
||||
|
||||
],
|
||||
};
|
||||
|
||||
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
||||
// INFO: Currently (20.06.2021) 100% identical with Webook-Node
|
||||
const incomingAuthentication = this.getNodeParameter('incomingAuthentication') as string;
|
||||
const options = this.getNodeParameter('options', {}) as IDataObject;
|
||||
const req = this.getRequestObject();
|
||||
const resp = this.getResponseObject();
|
||||
const headers = this.getHeaderData();
|
||||
const realm = 'Webhook';
|
||||
|
||||
if (incomingAuthentication === 'basicAuth') {
|
||||
// Basic authorization is needed to call webhook
|
||||
const httpBasicAuth = await this.getCredentials('httpBasicAuth');
|
||||
|
||||
if (httpBasicAuth === undefined || !httpBasicAuth.user || !httpBasicAuth.password) {
|
||||
// Data is not defined on node so can not authenticate
|
||||
return authorizationError(resp, realm, 500, 'No authentication data defined on node!');
|
||||
}
|
||||
|
||||
const basicAuthData = basicAuth(req);
|
||||
|
||||
if (basicAuthData === undefined) {
|
||||
// Authorization data is missing
|
||||
return authorizationError(resp, realm, 401);
|
||||
}
|
||||
|
||||
if (basicAuthData.name !== httpBasicAuth!.user || basicAuthData.pass !== httpBasicAuth!.password) {
|
||||
// Provided authentication data is wrong
|
||||
return authorizationError(resp, realm, 403);
|
||||
}
|
||||
} else if (incomingAuthentication === 'headerAuth') {
|
||||
// Special header with value is needed to call webhook
|
||||
const httpHeaderAuth = await this.getCredentials('httpHeaderAuth');
|
||||
|
||||
if (httpHeaderAuth === undefined || !httpHeaderAuth.name || !httpHeaderAuth.value) {
|
||||
// Data is not defined on node so can not authenticate
|
||||
return authorizationError(resp, realm, 500, 'No authentication data defined on node!');
|
||||
}
|
||||
const headerName = (httpHeaderAuth.name as string).toLowerCase();
|
||||
const headerValue = (httpHeaderAuth.value as string);
|
||||
|
||||
if (!headers.hasOwnProperty(headerName) || (headers as IDataObject)[headerName] !== headerValue) {
|
||||
// Provided authentication data is wrong
|
||||
return authorizationError(resp, realm, 403);
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const mimeType = headers['content-type'] || 'application/json';
|
||||
if (mimeType.includes('multipart/form-data')) {
|
||||
const form = new formidable.IncomingForm({});
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
form.parse(req, async (err, data, files) => {
|
||||
const returnItem: INodeExecutionData = {
|
||||
binary: {},
|
||||
json: {
|
||||
headers,
|
||||
params: this.getParamsData(),
|
||||
query: this.getQueryData(),
|
||||
body: data,
|
||||
},
|
||||
};
|
||||
|
||||
let count = 0;
|
||||
for (const file of Object.keys(files)) {
|
||||
|
||||
let binaryPropertyName = file;
|
||||
if (options.binaryPropertyName) {
|
||||
binaryPropertyName = `${options.binaryPropertyName}${count}`;
|
||||
}
|
||||
|
||||
const fileJson = (files[file] as formidable.File).toJSON() as unknown as IDataObject;
|
||||
const fileContent = await fs.promises.readFile((files[file] as formidable.File).path);
|
||||
|
||||
returnItem.binary![binaryPropertyName] = await this.helpers.prepareBinaryData(Buffer.from(fileContent), fileJson.name as string, fileJson.type as string);
|
||||
|
||||
count += 1;
|
||||
}
|
||||
resolve({
|
||||
workflowData: [
|
||||
[
|
||||
returnItem,
|
||||
],
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
if (options.binaryData === true) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const binaryPropertyName = options.binaryPropertyName || 'data';
|
||||
const data: Buffer[] = [];
|
||||
|
||||
req.on('data', (chunk) => {
|
||||
data.push(chunk);
|
||||
});
|
||||
|
||||
req.on('end', async () => {
|
||||
const returnItem: INodeExecutionData = {
|
||||
binary: {},
|
||||
json: {
|
||||
headers,
|
||||
params: this.getParamsData(),
|
||||
query: this.getQueryData(),
|
||||
body: this.getBodyData(),
|
||||
},
|
||||
};
|
||||
|
||||
returnItem.binary![binaryPropertyName as string] = await this.helpers.prepareBinaryData(Buffer.concat(data));
|
||||
|
||||
return resolve({
|
||||
workflowData: [
|
||||
[
|
||||
returnItem,
|
||||
],
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (error) => {
|
||||
throw new NodeOperationError(this.getNode(), error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const response: INodeExecutionData = {
|
||||
json: {
|
||||
headers,
|
||||
params: this.getParamsData(),
|
||||
query: this.getQueryData(),
|
||||
body: this.getBodyData(),
|
||||
},
|
||||
};
|
||||
|
||||
if (options.rawBody) {
|
||||
response.binary = {
|
||||
data: {
|
||||
// @ts-ignore
|
||||
data: req.rawBody.toString(BINARY_ENCODING),
|
||||
mimeType,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
let webhookResponse: string | undefined;
|
||||
if (options.responseData) {
|
||||
webhookResponse = options.responseData as string;
|
||||
}
|
||||
|
||||
return {
|
||||
webhookResponse,
|
||||
workflowData: [
|
||||
[
|
||||
response,
|
||||
],
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const resume = this.getNodeParameter('resume', 0) as string;
|
||||
|
||||
if (resume === 'webhook') {
|
||||
let waitTill = new Date(WAIT_TIME_UNLIMITED);
|
||||
|
||||
const limitWaitTime = this.getNodeParameter('limitWaitTime', 0);
|
||||
|
||||
if (limitWaitTime === true) {
|
||||
const limitType = this.getNodeParameter('limitType', 0);
|
||||
if (limitType === 'afterTimeInterval') {
|
||||
let waitAmount = this.getNodeParameter('resumeAmount', 0) as number;
|
||||
const resumeUnit = this.getNodeParameter('resumeUnit', 0);
|
||||
if (resumeUnit === 'minutes') {
|
||||
waitAmount *= 60;
|
||||
}
|
||||
if (resumeUnit === 'hours') {
|
||||
waitAmount *= 60 * 60;
|
||||
}
|
||||
if (resumeUnit === 'days') {
|
||||
waitAmount *= 60 * 60 * 24;
|
||||
}
|
||||
|
||||
waitAmount *= 1000;
|
||||
|
||||
waitTill = new Date(new Date().getTime() + waitAmount);
|
||||
} else {
|
||||
waitTill = new Date(this.getNodeParameter('maxDateAndTime', 0) as string);
|
||||
}
|
||||
}
|
||||
|
||||
await this.putExecutionToWait(waitTill);
|
||||
|
||||
return [this.getInputData()];
|
||||
}
|
||||
|
||||
let waitTill: Date;
|
||||
if (resume === 'timeInterval') {
|
||||
const unit = this.getNodeParameter('unit', 0) as string;
|
||||
|
||||
let waitAmount = this.getNodeParameter('amount', 0) as number;
|
||||
if (unit === 'minutes') {
|
||||
waitAmount *= 60;
|
||||
}
|
||||
if (unit === 'hours') {
|
||||
waitAmount *= 60 * 60;
|
||||
}
|
||||
if (unit === 'days') {
|
||||
waitAmount *= 60 * 60 * 24;
|
||||
}
|
||||
|
||||
waitAmount *= 1000;
|
||||
|
||||
waitTill = new Date(new Date().getTime() + waitAmount);
|
||||
|
||||
} else {
|
||||
// resume: dateTime
|
||||
const dateTime = this.getNodeParameter('dateTime', 0) as string;
|
||||
console.log('dateTime', dateTime);
|
||||
|
||||
waitTill = new Date(dateTime);
|
||||
}
|
||||
|
||||
const waitValue = Math.max(waitTill.getTime() - new Date().getTime(), 0);
|
||||
|
||||
if (waitValue < 65000) {
|
||||
// If wait time is shorter than 65 seconds leave execution active because
|
||||
// we just check the database every 60 seconds.
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve([this.getInputData()]);
|
||||
}, waitValue);
|
||||
});
|
||||
}
|
||||
|
||||
// If longer than 60 seconds put execution to wait
|
||||
await this.putExecutionToWait(waitTill);
|
||||
|
||||
return [this.getInputData()];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user