2021-09-21 10:38:24 -07:00
|
|
|
/* eslint-disable no-lonely-if */
|
2021-08-29 11:58:11 -07:00
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
|
|
/* eslint-disable no-prototype-builtins */
|
|
|
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
|
|
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
|
|
|
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
|
|
/* eslint-disable new-cap */
|
|
|
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
|
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
|
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
|
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
|
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
|
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
|
|
/* eslint-disable @typescript-eslint/no-shadow */
|
|
|
|
/* eslint-disable no-param-reassign */
|
2019-06-23 03:35:23 -07:00
|
|
|
import {
|
2021-09-21 10:38:24 -07:00
|
|
|
GenericValue,
|
2020-01-13 18:46:58 -08:00
|
|
|
IAllExecuteFunctions,
|
2019-06-23 03:35:23 -07:00
|
|
|
IBinaryData,
|
|
|
|
IContextObject,
|
|
|
|
ICredentialDataDecryptedObject,
|
2021-01-24 04:33:57 -08:00
|
|
|
ICredentialsExpressionResolveValues,
|
2019-06-23 03:35:23 -07:00
|
|
|
IDataObject,
|
|
|
|
IExecuteFunctions,
|
2021-11-05 09:45:51 -07:00
|
|
|
IExecuteResponsePromiseData,
|
2019-06-23 03:35:23 -07:00
|
|
|
IExecuteSingleFunctions,
|
2020-01-02 15:13:53 -08:00
|
|
|
IExecuteWorkflowInfo,
|
2021-09-21 10:38:24 -07:00
|
|
|
IHttpRequestOptions,
|
|
|
|
IN8nHttpFullResponse,
|
|
|
|
IN8nHttpResponse,
|
2019-06-23 03:35:23 -07:00
|
|
|
INode,
|
|
|
|
INodeExecutionData,
|
|
|
|
INodeParameters,
|
|
|
|
INodeType,
|
2020-10-22 06:46:03 -07:00
|
|
|
IOAuth2Options,
|
2019-12-31 12:19:37 -08:00
|
|
|
IPollFunctions,
|
2019-06-23 03:35:23 -07:00
|
|
|
IRunExecutionData,
|
|
|
|
ITaskDataConnections,
|
|
|
|
ITriggerFunctions,
|
2019-07-12 02:33:18 -07:00
|
|
|
IWebhookData,
|
2019-06-23 03:35:23 -07:00
|
|
|
IWebhookDescription,
|
|
|
|
IWebhookFunctions,
|
2021-08-21 05:11:32 -07:00
|
|
|
IWorkflowDataProxyAdditionalKeys,
|
2019-09-04 05:53:39 -07:00
|
|
|
IWorkflowDataProxyData,
|
2019-06-23 03:35:23 -07:00
|
|
|
IWorkflowExecuteAdditionalData,
|
2020-02-15 17:07:01 -08:00
|
|
|
IWorkflowMetadata,
|
2019-06-23 03:35:23 -07:00
|
|
|
NodeHelpers,
|
2021-04-16 09:33:36 -07:00
|
|
|
NodeOperationError,
|
2019-06-23 03:35:23 -07:00
|
|
|
NodeParameterValue,
|
|
|
|
Workflow,
|
2021-03-23 11:08:47 -07:00
|
|
|
WorkflowActivateMode,
|
2019-09-04 05:53:39 -07:00
|
|
|
WorkflowDataProxy,
|
2019-06-23 03:35:23 -07:00
|
|
|
WorkflowExecuteMode,
|
2021-08-29 11:58:11 -07:00
|
|
|
LoggerProxy as Logger,
|
2019-06-23 03:35:23 -07:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
2021-09-21 10:38:24 -07:00
|
|
|
import { Agent } from 'https';
|
|
|
|
import { stringify } from 'qs';
|
2020-06-01 17:42:38 -07:00
|
|
|
import * as clientOAuth1 from 'oauth-1.0a';
|
2020-11-03 14:01:38 -08:00
|
|
|
import { Token } from 'oauth-1.0a';
|
2020-01-13 18:46:58 -08:00
|
|
|
import * as clientOAuth2 from 'client-oauth2';
|
2021-08-29 11:58:11 -07:00
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
2020-02-08 21:25:46 -08:00
|
|
|
import { get } from 'lodash';
|
2021-08-29 11:58:11 -07:00
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
2020-02-08 21:25:46 -08:00
|
|
|
import * as express from 'express';
|
2021-09-21 10:38:24 -07:00
|
|
|
import * as FormData from 'form-data';
|
2019-06-23 03:35:23 -07:00
|
|
|
import * as path from 'path';
|
2020-10-22 06:46:03 -07:00
|
|
|
import { OptionsWithUri, OptionsWithUrl } from 'request';
|
2019-06-23 03:35:23 -07:00
|
|
|
import * as requestPromise from 'request-promise-native';
|
2020-06-01 17:42:38 -07:00
|
|
|
import { createHmac } from 'crypto';
|
2020-07-08 00:40:47 -07:00
|
|
|
import { fromBuffer } from 'file-type';
|
|
|
|
import { lookup } from 'mime-types';
|
2021-08-29 11:58:11 -07:00
|
|
|
|
2021-09-21 10:38:24 -07:00
|
|
|
import axios, { AxiosProxyConfig, AxiosRequestConfig, Method } from 'axios';
|
2021-10-28 09:07:09 -07:00
|
|
|
import { URL, URLSearchParams } from 'url';
|
2021-12-23 13:29:04 -08:00
|
|
|
import { BinaryDataManager } from './BinaryDataManager';
|
2021-08-29 11:58:11 -07:00
|
|
|
// eslint-disable-next-line import/no-cycle
|
2021-05-01 20:43:01 -07:00
|
|
|
import {
|
2021-09-11 01:15:36 -07:00
|
|
|
ICredentialTestFunctions,
|
2021-08-29 11:58:11 -07:00
|
|
|
IHookFunctions,
|
|
|
|
ILoadOptionsFunctions,
|
|
|
|
IResponseError,
|
|
|
|
IWorkflowSettings,
|
|
|
|
PLACEHOLDER_EMPTY_EXECUTION_ID,
|
|
|
|
} from '.';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2021-09-21 10:38:24 -07:00
|
|
|
axios.defaults.timeout = 300000;
|
|
|
|
// Prevent axios from adding x-form-www-urlencoded headers by default
|
|
|
|
axios.defaults.headers.post = {};
|
2021-11-15 08:20:28 -08:00
|
|
|
axios.defaults.headers.put = {};
|
|
|
|
axios.defaults.headers.patch = {};
|
2021-10-28 09:09:25 -07:00
|
|
|
axios.defaults.paramsSerializer = (params) => {
|
|
|
|
if (params instanceof URLSearchParams) {
|
|
|
|
return params.toString();
|
|
|
|
}
|
|
|
|
return stringify(params, { arrayFormat: 'indices' });
|
|
|
|
};
|
2021-09-21 10:38:24 -07:00
|
|
|
|
2021-04-17 06:15:33 -07:00
|
|
|
const requestPromiseWithDefaults = requestPromise.defaults({
|
|
|
|
timeout: 300000, // 5 minutes
|
|
|
|
});
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2021-09-30 12:10:56 -07:00
|
|
|
const pushFormDataValue = (form: FormData, key: string, value: any) => {
|
|
|
|
if (value?.hasOwnProperty('value') && value.hasOwnProperty('options')) {
|
|
|
|
// @ts-ignore
|
|
|
|
form.append(key, value.value, value.options);
|
|
|
|
} else {
|
|
|
|
form.append(key, value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const createFormDataObject = (data: object) => {
|
|
|
|
const formData = new FormData();
|
|
|
|
const keys = Object.keys(data);
|
|
|
|
keys.forEach((key) => {
|
|
|
|
// @ts-ignore
|
|
|
|
const formField = data[key];
|
|
|
|
|
|
|
|
if (formField instanceof Array) {
|
|
|
|
formField.forEach((item) => {
|
|
|
|
pushFormDataValue(formData, key, item);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
pushFormDataValue(formData, key, formField);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return formData;
|
|
|
|
};
|
|
|
|
|
2021-10-01 08:43:50 -07:00
|
|
|
function searchForHeader(headers: IDataObject, headerName: string) {
|
|
|
|
if (headers === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const headerNames = Object.keys(headers);
|
|
|
|
headerName = headerName.toLowerCase();
|
|
|
|
return headerNames.find((thisHeader) => thisHeader.toLowerCase() === headerName);
|
|
|
|
}
|
|
|
|
|
2021-11-12 04:55:29 -08:00
|
|
|
async function generateContentLengthHeader(formData: FormData, headers: IDataObject) {
|
|
|
|
if (!formData || !formData.getLength) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
const length = await new Promise((res, rej) => {
|
|
|
|
formData.getLength((error: Error | null, length: number) => {
|
|
|
|
if (error) {
|
|
|
|
rej(error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
res(length);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
headers = Object.assign(headers, {
|
|
|
|
'content-length': length,
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
Logger.error('Unable to calculate form data length', { error });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-21 10:38:24 -07:00
|
|
|
async function parseRequestObject(requestObject: IDataObject) {
|
|
|
|
// This function is a temporary implementation
|
|
|
|
// That translates all http requests done via
|
|
|
|
// the request library to axios directly
|
|
|
|
// We are not using n8n's interface as it would
|
|
|
|
// an unnecessary step, considering the `request`
|
|
|
|
// helper can be deprecated and removed.
|
|
|
|
const axiosConfig: AxiosRequestConfig = {};
|
|
|
|
|
|
|
|
if (requestObject.headers !== undefined) {
|
|
|
|
axiosConfig.headers = requestObject.headers as string;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let's start parsing the hardest part, which is the request body.
|
|
|
|
// The process here is as following?
|
|
|
|
// - Check if we have a `content-type` header. If this was set,
|
|
|
|
// we will follow
|
|
|
|
// - Check if the `form` property was set. If yes, then it's x-www-form-urlencoded
|
|
|
|
// - Check if the `formData` property exists. If yes, then it's multipart/form-data
|
|
|
|
// - Lastly, we should have a regular `body` that is probably a JSON.
|
|
|
|
|
|
|
|
const contentTypeHeaderKeyName =
|
|
|
|
axiosConfig.headers &&
|
|
|
|
Object.keys(axiosConfig.headers).find(
|
|
|
|
(headerName) => headerName.toLowerCase() === 'content-type',
|
|
|
|
);
|
|
|
|
const contentType =
|
|
|
|
contentTypeHeaderKeyName &&
|
|
|
|
(axiosConfig.headers[contentTypeHeaderKeyName] as string | undefined);
|
|
|
|
if (contentType === 'application/x-www-form-urlencoded' && requestObject.formData === undefined) {
|
|
|
|
// there are nodes incorrectly created, informing the content type header
|
|
|
|
// and also using formData. Request lib takes precedence for the formData.
|
|
|
|
// We will do the same.
|
|
|
|
// Merge body and form properties.
|
2021-10-21 13:12:15 -07:00
|
|
|
if (typeof requestObject.body === 'string') {
|
|
|
|
axiosConfig.data = requestObject.body;
|
|
|
|
} else {
|
|
|
|
const allData = Object.assign(requestObject.body || {}, requestObject.form || {}) as Record<
|
|
|
|
string,
|
|
|
|
string
|
|
|
|
>;
|
|
|
|
if (requestObject.useQuerystring === true) {
|
|
|
|
axiosConfig.data = stringify(allData, { arrayFormat: 'repeat' });
|
|
|
|
} else {
|
|
|
|
axiosConfig.data = stringify(allData);
|
|
|
|
}
|
|
|
|
}
|
2021-09-21 10:38:24 -07:00
|
|
|
} else if (contentType && contentType.includes('multipart/form-data') !== false) {
|
|
|
|
if (requestObject.formData !== undefined && requestObject.formData instanceof FormData) {
|
|
|
|
axiosConfig.data = requestObject.formData;
|
|
|
|
} else {
|
2021-09-30 12:10:56 -07:00
|
|
|
const allData = {
|
|
|
|
...(requestObject.body as object | undefined),
|
|
|
|
...(requestObject.formData as object | undefined),
|
|
|
|
};
|
|
|
|
|
|
|
|
axiosConfig.data = createFormDataObject(allData);
|
2021-09-21 10:38:24 -07:00
|
|
|
}
|
|
|
|
// replace the existing header with a new one that
|
|
|
|
// contains the boundary property.
|
|
|
|
// @ts-ignore
|
|
|
|
delete axiosConfig.headers[contentTypeHeaderKeyName];
|
|
|
|
const headers = axiosConfig.data.getHeaders();
|
|
|
|
axiosConfig.headers = Object.assign(axiosConfig.headers || {}, headers);
|
2021-11-12 04:55:29 -08:00
|
|
|
await generateContentLengthHeader(axiosConfig.data, axiosConfig.headers);
|
2021-09-21 10:38:24 -07:00
|
|
|
} else {
|
|
|
|
// When using the `form` property it means the content should be x-www-form-urlencoded.
|
|
|
|
if (requestObject.form !== undefined && requestObject.body === undefined) {
|
|
|
|
// If we have only form
|
2021-10-01 08:43:50 -07:00
|
|
|
axiosConfig.data =
|
|
|
|
typeof requestObject.form === 'string'
|
|
|
|
? stringify(requestObject.form, { format: 'RFC3986' })
|
|
|
|
: stringify(requestObject.form).toString();
|
2021-09-21 10:38:24 -07:00
|
|
|
if (axiosConfig.headers !== undefined) {
|
2021-10-01 08:43:50 -07:00
|
|
|
const headerName = searchForHeader(axiosConfig.headers, 'content-type');
|
|
|
|
if (headerName) {
|
|
|
|
delete axiosConfig.headers[headerName];
|
|
|
|
}
|
2021-09-21 10:38:24 -07:00
|
|
|
axiosConfig.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
|
|
} else {
|
|
|
|
axiosConfig.headers = {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} else if (requestObject.formData !== undefined) {
|
|
|
|
// remove any "content-type" that might exist.
|
|
|
|
if (axiosConfig.headers !== undefined) {
|
|
|
|
const headers = Object.keys(axiosConfig.headers);
|
|
|
|
headers.forEach((header) =>
|
|
|
|
header.toLowerCase() === 'content-type' ? delete axiosConfig.headers[header] : null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requestObject.formData instanceof FormData) {
|
|
|
|
axiosConfig.data = requestObject.formData;
|
|
|
|
} else {
|
2021-09-30 12:10:56 -07:00
|
|
|
axiosConfig.data = createFormDataObject(requestObject.formData as object);
|
2021-09-21 10:38:24 -07:00
|
|
|
}
|
|
|
|
// Mix in headers as FormData creates the boundary.
|
|
|
|
const headers = axiosConfig.data.getHeaders();
|
|
|
|
axiosConfig.headers = Object.assign(axiosConfig.headers || {}, headers);
|
2021-11-12 04:55:29 -08:00
|
|
|
await generateContentLengthHeader(axiosConfig.data, axiosConfig.headers);
|
2021-09-21 10:38:24 -07:00
|
|
|
} else if (requestObject.body !== undefined) {
|
|
|
|
// If we have body and possibly form
|
|
|
|
if (requestObject.form !== undefined) {
|
|
|
|
// merge both objects when exist.
|
|
|
|
requestObject.body = Object.assign(requestObject.body, requestObject.form);
|
|
|
|
}
|
|
|
|
axiosConfig.data = requestObject.body as FormData | GenericValue | GenericValue[];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requestObject.uri !== undefined) {
|
2021-10-12 20:20:51 -07:00
|
|
|
axiosConfig.url = requestObject.uri?.toString() as string;
|
2021-09-21 10:38:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (requestObject.url !== undefined) {
|
2021-10-12 20:20:51 -07:00
|
|
|
axiosConfig.url = requestObject.url?.toString() as string;
|
2021-09-21 10:38:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (requestObject.method !== undefined) {
|
|
|
|
axiosConfig.method = requestObject.method as Method;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requestObject.qs !== undefined && Object.keys(requestObject.qs as object).length > 0) {
|
|
|
|
axiosConfig.params = requestObject.qs as IDataObject;
|
|
|
|
}
|
|
|
|
|
2021-10-06 11:05:28 -07:00
|
|
|
if (
|
|
|
|
requestObject.useQuerystring === true ||
|
|
|
|
// @ts-ignore
|
|
|
|
requestObject.qsStringifyOptions?.arrayFormat === 'repeat'
|
|
|
|
) {
|
2021-09-21 10:38:24 -07:00
|
|
|
axiosConfig.paramsSerializer = (params) => {
|
|
|
|
return stringify(params, { arrayFormat: 'repeat' });
|
|
|
|
};
|
2021-10-14 11:59:34 -07:00
|
|
|
} else if (requestObject.useQuerystring === false) {
|
|
|
|
axiosConfig.paramsSerializer = (params) => {
|
|
|
|
return stringify(params, { arrayFormat: 'indices' });
|
|
|
|
};
|
2021-09-21 10:38:24 -07:00
|
|
|
}
|
|
|
|
|
2021-10-06 11:05:28 -07:00
|
|
|
// @ts-ignore
|
|
|
|
if (requestObject.qsStringifyOptions?.arrayFormat === 'brackets') {
|
|
|
|
axiosConfig.paramsSerializer = (params) => {
|
|
|
|
return stringify(params, { arrayFormat: 'brackets' });
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-21 10:38:24 -07:00
|
|
|
if (requestObject.auth !== undefined) {
|
|
|
|
// Check support for sendImmediately
|
|
|
|
if ((requestObject.auth as IDataObject).bearer !== undefined) {
|
|
|
|
axiosConfig.headers = Object.assign(axiosConfig.headers || {}, {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
|
|
Authorization: `Bearer ${(requestObject.auth as IDataObject).bearer}`,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const authObj = requestObject.auth as IDataObject;
|
|
|
|
// Request accepts both user/username and pass/password
|
|
|
|
axiosConfig.auth = {
|
|
|
|
username: (authObj.user || authObj.username) as string,
|
|
|
|
password: (authObj.password || authObj.pass) as string,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only set header if we have a body, otherwise it may fail
|
|
|
|
if (requestObject.json === true) {
|
|
|
|
// Add application/json headers - do not set charset as it breaks a lot of stuff
|
|
|
|
// only add if no other accept headers was sent.
|
|
|
|
const acceptHeaderExists =
|
|
|
|
axiosConfig.headers === undefined
|
|
|
|
? false
|
|
|
|
: Object.keys(axiosConfig.headers)
|
|
|
|
.map((headerKey) => headerKey.toLowerCase())
|
|
|
|
.includes('accept');
|
|
|
|
if (!acceptHeaderExists) {
|
|
|
|
axiosConfig.headers = Object.assign(axiosConfig.headers || {}, {
|
|
|
|
Accept: 'application/json',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-10-13 16:36:33 -07:00
|
|
|
if (requestObject.json === false || requestObject.json === undefined) {
|
2021-09-21 10:38:24 -07:00
|
|
|
// Prevent json parsing
|
|
|
|
axiosConfig.transformResponse = (res) => res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Axios will follow redirects by default, so we simply tell it otherwise if needed.
|
|
|
|
if (
|
|
|
|
requestObject.followRedirect === false &&
|
|
|
|
((requestObject.method as string | undefined) || 'get').toLowerCase() === 'get'
|
|
|
|
) {
|
|
|
|
axiosConfig.maxRedirects = 0;
|
|
|
|
}
|
|
|
|
if (
|
2021-10-06 10:53:18 -07:00
|
|
|
requestObject.followAllRedirects === false &&
|
2021-09-21 10:38:24 -07:00
|
|
|
((requestObject.method as string | undefined) || 'get').toLowerCase() !== 'get'
|
|
|
|
) {
|
|
|
|
axiosConfig.maxRedirects = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requestObject.rejectUnauthorized === false) {
|
|
|
|
axiosConfig.httpsAgent = new Agent({
|
|
|
|
rejectUnauthorized: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requestObject.timeout !== undefined) {
|
|
|
|
axiosConfig.timeout = requestObject.timeout as number;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requestObject.proxy !== undefined) {
|
2021-10-28 09:07:09 -07:00
|
|
|
// try our best to parse the url provided.
|
|
|
|
if (typeof requestObject.proxy === 'string') {
|
|
|
|
try {
|
|
|
|
const url = new URL(requestObject.proxy);
|
|
|
|
axiosConfig.proxy = {
|
|
|
|
host: url.hostname,
|
|
|
|
port: parseInt(url.port, 10),
|
|
|
|
protocol: url.protocol,
|
|
|
|
};
|
|
|
|
if (!url.port) {
|
|
|
|
// Sets port to a default if not informed
|
|
|
|
if (url.protocol === 'http') {
|
|
|
|
axiosConfig.proxy.port = 80;
|
|
|
|
} else if (url.protocol === 'https') {
|
|
|
|
axiosConfig.proxy.port = 443;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (url.username || url.password) {
|
|
|
|
axiosConfig.proxy.auth = {
|
|
|
|
username: url.username,
|
|
|
|
password: url.password,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
// Not a valid URL. We will try to simply parse stuff
|
|
|
|
// such as user:pass@host:port without protocol (we'll assume http)
|
|
|
|
if (requestObject.proxy.includes('@')) {
|
|
|
|
const [userpass, hostport] = requestObject.proxy.split('@');
|
|
|
|
const [username, password] = userpass.split(':');
|
|
|
|
const [hostname, port] = hostport.split(':');
|
|
|
|
axiosConfig.proxy = {
|
|
|
|
host: hostname,
|
|
|
|
port: parseInt(port, 10),
|
|
|
|
protocol: 'http',
|
|
|
|
auth: {
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
} else if (requestObject.proxy.includes(':')) {
|
|
|
|
const [hostname, port] = requestObject.proxy.split(':');
|
|
|
|
axiosConfig.proxy = {
|
|
|
|
host: hostname,
|
|
|
|
port: parseInt(port, 10),
|
|
|
|
protocol: 'http',
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
axiosConfig.proxy = {
|
|
|
|
host: requestObject.proxy,
|
|
|
|
port: 80,
|
|
|
|
protocol: 'http',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
axiosConfig.proxy = requestObject.proxy as AxiosProxyConfig;
|
|
|
|
}
|
2021-09-21 10:38:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (requestObject.encoding === null) {
|
|
|
|
// When downloading files, return an arrayBuffer.
|
|
|
|
axiosConfig.responseType = 'arraybuffer';
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we don't set an accept header
|
|
|
|
// Axios forces "application/json, text/plan, */*"
|
|
|
|
// Which causes some nodes like NextCloud to break
|
|
|
|
// as the service returns XML unless requested otherwise.
|
|
|
|
const allHeaders = axiosConfig.headers ? Object.keys(axiosConfig.headers) : [];
|
|
|
|
if (!allHeaders.some((headerKey) => headerKey.toLowerCase() === 'accept')) {
|
|
|
|
axiosConfig.headers = Object.assign(axiosConfig.headers || {}, { accept: '*/*' });
|
|
|
|
}
|
|
|
|
if (
|
2021-10-06 10:00:38 -07:00
|
|
|
requestObject.json !== false &&
|
2021-09-21 10:38:24 -07:00
|
|
|
axiosConfig.data !== undefined &&
|
2021-10-28 09:09:25 -07:00
|
|
|
axiosConfig.data !== '' &&
|
2021-09-21 10:38:24 -07:00
|
|
|
!(axiosConfig.data instanceof Buffer) &&
|
|
|
|
!allHeaders.some((headerKey) => headerKey.toLowerCase() === 'content-type')
|
|
|
|
) {
|
|
|
|
// Use default header for application/json
|
|
|
|
// If we don't specify this here, axios will add
|
|
|
|
// application/json; charset=utf-8
|
|
|
|
// and this breaks a lot of stuff
|
|
|
|
axiosConfig.headers = Object.assign(axiosConfig.headers || {}, {
|
|
|
|
'content-type': 'application/json',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Missing properties:
|
|
|
|
* encoding (need testing)
|
|
|
|
* gzip (ignored - default already works)
|
|
|
|
* resolveWithFullResponse (implemented elsewhere)
|
|
|
|
* simple (???)
|
|
|
|
*/
|
|
|
|
|
|
|
|
return axiosConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function proxyRequestToAxios(
|
|
|
|
uriOrObject: string | IDataObject,
|
|
|
|
options?: IDataObject,
|
|
|
|
): Promise<any> {
|
|
|
|
// tslint:disable-line:no-any
|
|
|
|
|
|
|
|
// Check if there's a better way of getting this config here
|
|
|
|
if (process.env.N8N_USE_DEPRECATED_REQUEST_LIB) {
|
|
|
|
// @ts-ignore
|
|
|
|
return requestPromiseWithDefaults.call(null, uriOrObject, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
let axiosConfig: AxiosRequestConfig = {};
|
|
|
|
|
|
|
|
let configObject: IDataObject;
|
|
|
|
if (uriOrObject !== undefined && typeof uriOrObject === 'string') {
|
|
|
|
axiosConfig.url = uriOrObject;
|
|
|
|
}
|
|
|
|
if (uriOrObject !== undefined && typeof uriOrObject === 'object') {
|
|
|
|
configObject = uriOrObject;
|
|
|
|
} else {
|
|
|
|
configObject = options || {};
|
|
|
|
}
|
|
|
|
|
|
|
|
axiosConfig = Object.assign(axiosConfig, await parseRequestObject(configObject));
|
|
|
|
|
2021-10-28 09:09:25 -07:00
|
|
|
Logger.debug('Proxying request to axios', {
|
|
|
|
originalConfig: configObject,
|
|
|
|
parsedConfig: axiosConfig,
|
|
|
|
});
|
|
|
|
|
2021-09-21 10:38:24 -07:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
axios(axiosConfig)
|
|
|
|
.then((response) => {
|
|
|
|
if (configObject.resolveWithFullResponse === true) {
|
2021-09-27 15:50:37 -07:00
|
|
|
let body = response.data;
|
|
|
|
if (response.data === '') {
|
|
|
|
if (axiosConfig.responseType === 'arraybuffer') {
|
|
|
|
body = Buffer.alloc(0);
|
|
|
|
} else {
|
|
|
|
body = undefined;
|
|
|
|
}
|
|
|
|
}
|
2021-09-21 10:38:24 -07:00
|
|
|
resolve({
|
2021-09-27 15:50:37 -07:00
|
|
|
body,
|
2021-09-21 10:38:24 -07:00
|
|
|
headers: response.headers,
|
|
|
|
statusCode: response.status,
|
|
|
|
statusMessage: response.statusText,
|
|
|
|
request: response.request,
|
|
|
|
});
|
|
|
|
} else {
|
2021-09-27 15:50:37 -07:00
|
|
|
let body = response.data;
|
|
|
|
if (response.data === '') {
|
|
|
|
if (axiosConfig.responseType === 'arraybuffer') {
|
|
|
|
body = Buffer.alloc(0);
|
|
|
|
} else {
|
|
|
|
body = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resolve(body);
|
2021-09-21 10:38:24 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
2021-10-19 14:45:59 -07:00
|
|
|
if (configObject.simple === false && error.response) {
|
2021-10-26 16:58:08 -07:00
|
|
|
if (configObject.resolveWithFullResponse) {
|
|
|
|
resolve({
|
|
|
|
body: error.response.data,
|
|
|
|
headers: error.response.headers,
|
|
|
|
statusCode: error.response.status,
|
|
|
|
statusMessage: error.response.statusText,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
resolve(error.response.data);
|
|
|
|
}
|
2021-10-19 14:45:59 -07:00
|
|
|
return;
|
|
|
|
}
|
2021-10-06 10:53:18 -07:00
|
|
|
|
2021-09-30 12:10:56 -07:00
|
|
|
Logger.debug('Request proxied to Axios failed', { error });
|
2021-12-23 12:20:50 -08:00
|
|
|
|
2021-09-30 12:10:56 -07:00
|
|
|
// Axios hydrates the original error with more data. We extract them.
|
|
|
|
// https://github.com/axios/axios/blob/master/lib/core/enhanceError.js
|
|
|
|
// Note: `code` is ignored as it's an expected part of the errorData.
|
|
|
|
const { request, response, isAxiosError, toJSON, config, ...errorData } = error;
|
2021-12-23 12:20:50 -08:00
|
|
|
if (response) {
|
|
|
|
error.message = `${response.status as number} - ${JSON.stringify(response.data)}`;
|
|
|
|
}
|
|
|
|
|
2021-09-30 12:10:56 -07:00
|
|
|
error.cause = errorData;
|
|
|
|
error.error = error.response?.data || errorData;
|
|
|
|
error.statusCode = error.response?.status;
|
2021-10-12 20:20:51 -07:00
|
|
|
error.options = config || {};
|
2021-09-30 12:10:56 -07:00
|
|
|
|
|
|
|
// Remove not needed data and so also remove circular references
|
|
|
|
error.request = undefined;
|
|
|
|
error.config = undefined;
|
|
|
|
error.options.adapter = undefined;
|
|
|
|
error.options.httpsAgent = undefined;
|
|
|
|
error.options.paramsSerializer = undefined;
|
|
|
|
error.options.transformRequest = undefined;
|
|
|
|
error.options.transformResponse = undefined;
|
|
|
|
error.options.validateStatus = undefined;
|
|
|
|
|
2021-09-21 10:38:24 -07:00
|
|
|
reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function convertN8nRequestToAxios(n8nRequest: IHttpRequestOptions): AxiosRequestConfig {
|
|
|
|
// Destructure properties with the same name first.
|
|
|
|
const { headers, method, timeout, auth, proxy, url } = n8nRequest;
|
|
|
|
|
|
|
|
const axiosRequest = {
|
|
|
|
headers: headers ?? {},
|
|
|
|
method,
|
|
|
|
timeout,
|
|
|
|
auth,
|
|
|
|
proxy,
|
|
|
|
url,
|
|
|
|
} as AxiosRequestConfig;
|
|
|
|
|
|
|
|
axiosRequest.params = n8nRequest.qs;
|
|
|
|
|
|
|
|
if (n8nRequest.disableFollowRedirect === true) {
|
|
|
|
axiosRequest.maxRedirects = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n8nRequest.encoding !== undefined) {
|
|
|
|
axiosRequest.responseType = n8nRequest.encoding;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n8nRequest.skipSslCertificateValidation === true) {
|
|
|
|
axiosRequest.httpsAgent = new Agent({
|
|
|
|
rejectUnauthorized: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n8nRequest.arrayFormat !== undefined) {
|
|
|
|
axiosRequest.paramsSerializer = (params) => {
|
|
|
|
return stringify(params, { arrayFormat: n8nRequest.arrayFormat });
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n8nRequest.body) {
|
|
|
|
axiosRequest.data = n8nRequest.body;
|
|
|
|
// Let's add some useful header standards here.
|
|
|
|
const existingContentTypeHeaderKey = searchForHeader(axiosRequest.headers, 'content-type');
|
|
|
|
if (existingContentTypeHeaderKey === undefined) {
|
|
|
|
// We are only setting content type headers if the user did
|
|
|
|
// not set it already manually. We're not overriding, even if it's wrong.
|
|
|
|
if (axiosRequest.data instanceof FormData) {
|
|
|
|
axiosRequest.headers = axiosRequest.headers || {};
|
|
|
|
axiosRequest.headers['Content-Type'] = 'multipart/form-data';
|
|
|
|
} else if (axiosRequest.data instanceof URLSearchParams) {
|
|
|
|
axiosRequest.headers = axiosRequest.headers || {};
|
|
|
|
axiosRequest.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n8nRequest.json) {
|
|
|
|
const key = searchForHeader(axiosRequest.headers, 'accept');
|
|
|
|
// If key exists, then the user has set both accept
|
|
|
|
// header and the json flag. Header should take precedence.
|
|
|
|
if (!key) {
|
|
|
|
axiosRequest.headers.Accept = 'application/json';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const userAgentHeader = searchForHeader(axiosRequest.headers, 'user-agent');
|
|
|
|
// If key exists, then the user has set both accept
|
|
|
|
// header and the json flag. Header should take precedence.
|
|
|
|
if (!userAgentHeader) {
|
|
|
|
axiosRequest.headers['User-Agent'] = 'n8n';
|
|
|
|
}
|
|
|
|
|
|
|
|
return axiosRequest;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function httpRequest(
|
|
|
|
requestParams: IHttpRequestOptions,
|
|
|
|
): Promise<IN8nHttpFullResponse | IN8nHttpResponse> {
|
|
|
|
// tslint:disable-line:no-any
|
|
|
|
const axiosRequest = convertN8nRequestToAxios(requestParams);
|
|
|
|
const result = await axios(axiosRequest);
|
|
|
|
if (requestParams.returnFullResponse) {
|
|
|
|
return {
|
|
|
|
body: result.data,
|
|
|
|
headers: result.headers,
|
|
|
|
statusCode: result.status,
|
|
|
|
statusMessage: result.statusText,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return result.data;
|
|
|
|
}
|
|
|
|
|
2021-08-20 09:08:40 -07:00
|
|
|
/**
|
|
|
|
* Returns binary data buffer for given item index and property name.
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {ITaskDataConnections} inputData
|
|
|
|
* @param {number} itemIndex
|
|
|
|
* @param {string} propertyName
|
|
|
|
* @param {number} inputIndex
|
|
|
|
* @returns {Promise<Buffer>}
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
export async function getBinaryDataBuffer(
|
|
|
|
inputData: ITaskDataConnections,
|
|
|
|
itemIndex: number,
|
|
|
|
propertyName: string,
|
|
|
|
inputIndex: number,
|
|
|
|
): Promise<Buffer> {
|
|
|
|
const binaryData = inputData.main![inputIndex]![itemIndex]!.binary![propertyName]!;
|
2021-12-23 13:29:04 -08:00
|
|
|
return BinaryDataManager.getInstance().retrieveBinaryData(binaryData);
|
2021-08-20 09:08:40 -07:00
|
|
|
}
|
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
/**
|
|
|
|
* Takes a buffer and converts it into the format n8n uses. It encodes the binary data as
|
|
|
|
* base64 and adds metadata.
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {Buffer} binaryData
|
|
|
|
* @param {string} [filePath]
|
|
|
|
* @param {string} [mimeType]
|
|
|
|
* @returns {Promise<IBinaryData>}
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
export async function prepareBinaryData(
|
|
|
|
binaryData: Buffer,
|
2021-12-23 13:29:04 -08:00
|
|
|
executionId: string,
|
2021-08-29 11:58:11 -07:00
|
|
|
filePath?: string,
|
|
|
|
mimeType?: string,
|
|
|
|
): Promise<IBinaryData> {
|
2019-06-23 03:35:23 -07:00
|
|
|
if (!mimeType) {
|
2020-07-08 00:40:47 -07:00
|
|
|
// If no mime type is given figure it out
|
|
|
|
|
|
|
|
if (filePath) {
|
|
|
|
// Use file path to guess mime type
|
|
|
|
const mimeTypeLookup = lookup(filePath);
|
|
|
|
if (mimeTypeLookup) {
|
|
|
|
mimeType = mimeTypeLookup;
|
|
|
|
}
|
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2020-07-08 00:40:47 -07:00
|
|
|
if (!mimeType) {
|
|
|
|
// Use buffer to guess mime type
|
|
|
|
const fileTypeData = await fromBuffer(binaryData);
|
|
|
|
if (fileTypeData) {
|
|
|
|
mimeType = fileTypeData.mime;
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
2020-07-08 00:40:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mimeType) {
|
|
|
|
// Fall back to text
|
|
|
|
mimeType = 'text/plain';
|
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const returnData: IBinaryData = {
|
|
|
|
mimeType,
|
2021-12-23 13:29:04 -08:00
|
|
|
data: '',
|
2019-06-23 03:35:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
if (filePath) {
|
|
|
|
if (filePath.includes('?')) {
|
|
|
|
// Remove maybe present query parameters
|
|
|
|
filePath = filePath.split('?').shift();
|
|
|
|
}
|
|
|
|
|
|
|
|
const filePathParts = path.parse(filePath as string);
|
|
|
|
|
2021-03-18 10:13:24 -07:00
|
|
|
if (filePathParts.dir !== '') {
|
|
|
|
returnData.directory = filePathParts.dir;
|
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
returnData.fileName = filePathParts.base;
|
|
|
|
|
|
|
|
// Remove the dot
|
|
|
|
const fileExtension = filePathParts.ext.slice(1);
|
|
|
|
if (fileExtension) {
|
|
|
|
returnData.fileExtension = fileExtension;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-23 13:29:04 -08:00
|
|
|
return BinaryDataManager.getInstance().storeBinaryData(returnData, binaryData, executionId);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
2020-01-13 18:46:58 -08:00
|
|
|
/**
|
|
|
|
* Makes a request using OAuth data for authentication
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {IAllExecuteFunctions} this
|
|
|
|
* @param {string} credentialsType
|
|
|
|
* @param {(OptionsWithUri | requestPromise.RequestPromiseOptions)} requestOptions
|
|
|
|
* @param {INode} node
|
|
|
|
* @param {IWorkflowExecuteAdditionalData} additionalData
|
2020-07-25 10:58:38 -07:00
|
|
|
*
|
2020-01-13 18:46:58 -08:00
|
|
|
* @returns
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
export async function requestOAuth2(
|
|
|
|
this: IAllExecuteFunctions,
|
|
|
|
credentialsType: string,
|
|
|
|
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
|
|
|
node: INode,
|
|
|
|
additionalData: IWorkflowExecuteAdditionalData,
|
|
|
|
oAuth2Options?: IOAuth2Options,
|
|
|
|
) {
|
|
|
|
const credentials = (await this.getCredentials(
|
|
|
|
credentialsType,
|
|
|
|
)) as ICredentialDataDecryptedObject;
|
2020-01-13 18:46:58 -08:00
|
|
|
|
|
|
|
if (credentials === undefined) {
|
2021-08-27 08:25:54 -07:00
|
|
|
throw new Error('No credentials were returned!');
|
2020-01-13 18:46:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (credentials.oauthTokenData === undefined) {
|
|
|
|
throw new Error('OAuth credentials not connected!');
|
|
|
|
}
|
|
|
|
|
2020-02-08 21:25:46 -08:00
|
|
|
const oAuthClient = new clientOAuth2({
|
|
|
|
clientId: credentials.clientId as string,
|
|
|
|
clientSecret: credentials.clientSecret as string,
|
|
|
|
accessTokenUri: credentials.accessTokenUrl as string,
|
|
|
|
});
|
|
|
|
|
|
|
|
const oauthTokenData = credentials.oauthTokenData as clientOAuth2.Data;
|
2020-01-13 18:46:58 -08:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
const token = oAuthClient.createToken(
|
|
|
|
get(oauthTokenData, oAuth2Options?.property as string) || oauthTokenData.accessToken,
|
|
|
|
oauthTokenData.refreshToken,
|
|
|
|
oAuth2Options?.tokenType || oauthTokenData.tokenType,
|
|
|
|
oauthTokenData,
|
|
|
|
);
|
2020-01-13 18:46:58 -08:00
|
|
|
// Signs the request by adding authorization headers or query parameters depending
|
|
|
|
// on the token-type used.
|
|
|
|
const newRequestOptions = token.sign(requestOptions as clientOAuth2.RequestObject);
|
|
|
|
|
2020-09-16 00:16:06 -07:00
|
|
|
// If keep bearer is false remove the it from the authorization header
|
|
|
|
if (oAuth2Options?.keepBearer === false) {
|
2021-08-29 11:58:11 -07:00
|
|
|
// @ts-ignore
|
|
|
|
newRequestOptions?.headers?.Authorization =
|
|
|
|
// @ts-ignore
|
|
|
|
newRequestOptions?.headers?.Authorization.split(' ')[1];
|
2020-09-16 00:16:06 -07:00
|
|
|
}
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
return this.helpers.request!(newRequestOptions).catch(async (error: IResponseError) => {
|
|
|
|
const statusCodeReturned =
|
|
|
|
oAuth2Options?.tokenExpiredStatusCode === undefined
|
|
|
|
? 401
|
|
|
|
: oAuth2Options?.tokenExpiredStatusCode;
|
|
|
|
|
2021-09-28 06:20:01 -07:00
|
|
|
if (error.statusCode === statusCodeReturned) {
|
2021-08-29 11:58:11 -07:00
|
|
|
// Token is probably not valid anymore. So try refresh it.
|
|
|
|
|
|
|
|
const tokenRefreshOptions: IDataObject = {};
|
|
|
|
|
|
|
|
if (oAuth2Options?.includeCredentialsOnRefreshOnBody) {
|
|
|
|
const body: IDataObject = {
|
|
|
|
client_id: credentials.clientId as string,
|
|
|
|
client_secret: credentials.clientSecret as string,
|
|
|
|
};
|
|
|
|
tokenRefreshOptions.body = body;
|
|
|
|
// Override authorization property so the credentails are not included in it
|
|
|
|
tokenRefreshOptions.headers = {
|
|
|
|
Authorization: '',
|
|
|
|
};
|
|
|
|
}
|
2020-07-25 10:58:38 -07:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
Logger.debug(
|
|
|
|
`OAuth2 token for "${credentialsType}" used by node "${node.name}" expired. Should revalidate.`,
|
|
|
|
);
|
2021-05-01 20:43:01 -07:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
const newToken = await token.refresh(tokenRefreshOptions);
|
2020-01-13 18:46:58 -08:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
Logger.debug(
|
|
|
|
`OAuth2 token for "${credentialsType}" used by node "${node.name}" has been renewed.`,
|
|
|
|
);
|
2021-05-01 20:43:01 -07:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
credentials.oauthTokenData = newToken.data;
|
2020-01-13 18:46:58 -08:00
|
|
|
|
2021-10-13 15:21:00 -07:00
|
|
|
// Find the credentials
|
2021-08-29 11:58:11 -07:00
|
|
|
if (!node.credentials || !node.credentials[credentialsType]) {
|
|
|
|
throw new Error(
|
|
|
|
`The node "${node.name}" does not have credentials of type "${credentialsType}"!`,
|
|
|
|
);
|
|
|
|
}
|
2021-10-13 15:21:00 -07:00
|
|
|
const nodeCredentials = node.credentials[credentialsType];
|
2020-01-13 18:46:58 -08:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
// Save the refreshed token
|
2021-10-13 15:21:00 -07:00
|
|
|
await additionalData.credentialsHelper.updateCredentials(
|
|
|
|
nodeCredentials,
|
|
|
|
credentialsType,
|
|
|
|
credentials,
|
|
|
|
);
|
2020-01-13 18:46:58 -08:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
Logger.debug(
|
|
|
|
`OAuth2 token for "${credentialsType}" used by node "${node.name}" has been saved to database successfully.`,
|
|
|
|
);
|
2021-05-01 20:43:01 -07:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
// Make the request again with the new token
|
|
|
|
const newRequestOptions = newToken.sign(requestOptions as clientOAuth2.RequestObject);
|
2020-01-13 18:46:58 -08:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
return this.helpers.request!(newRequestOptions);
|
|
|
|
}
|
2020-01-13 18:46:58 -08:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
// Unknown error so simply throw it
|
|
|
|
throw error;
|
|
|
|
});
|
2020-01-13 18:46:58 -08:00
|
|
|
}
|
|
|
|
|
2020-06-01 17:42:38 -07:00
|
|
|
/* Makes a request using OAuth1 data for authentication
|
2021-08-29 11:58:11 -07:00
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {IAllExecuteFunctions} this
|
|
|
|
* @param {string} credentialsType
|
|
|
|
* @param {(OptionsWithUrl | requestPromise.RequestPromiseOptions)} requestOptionså
|
|
|
|
* @returns
|
|
|
|
*/
|
|
|
|
export async function requestOAuth1(
|
|
|
|
this: IAllExecuteFunctions,
|
|
|
|
credentialsType: string,
|
|
|
|
requestOptions: OptionsWithUrl | OptionsWithUri | requestPromise.RequestPromiseOptions,
|
|
|
|
) {
|
|
|
|
const credentials = (await this.getCredentials(
|
|
|
|
credentialsType,
|
|
|
|
)) as ICredentialDataDecryptedObject;
|
2020-06-01 17:42:38 -07:00
|
|
|
|
|
|
|
if (credentials === undefined) {
|
2021-08-27 08:25:54 -07:00
|
|
|
throw new Error('No credentials were returned!');
|
2020-06-01 17:42:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (credentials.oauthTokenData === undefined) {
|
|
|
|
throw new Error('OAuth credentials not connected!');
|
|
|
|
}
|
|
|
|
|
|
|
|
const oauth = new clientOAuth1({
|
|
|
|
consumer: {
|
|
|
|
key: credentials.consumerKey as string,
|
|
|
|
secret: credentials.consumerSecret as string,
|
|
|
|
},
|
|
|
|
signature_method: credentials.signatureMethod as string,
|
|
|
|
hash_function(base, key) {
|
2021-08-29 11:58:11 -07:00
|
|
|
const algorithm = credentials.signatureMethod === 'HMAC-SHA1' ? 'sha1' : 'sha256';
|
|
|
|
return createHmac(algorithm, key).update(base).digest('base64');
|
2020-06-01 17:42:38 -07:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const oauthTokenData = credentials.oauthTokenData as IDataObject;
|
|
|
|
|
|
|
|
const token: Token = {
|
|
|
|
key: oauthTokenData.oauth_token as string,
|
|
|
|
secret: oauthTokenData.oauth_token_secret as string,
|
|
|
|
};
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
// @ts-ignore
|
2020-11-03 14:01:38 -08:00
|
|
|
requestOptions.data = { ...requestOptions.qs, ...requestOptions.form };
|
2020-06-01 17:42:38 -07:00
|
|
|
|
2020-12-10 01:39:11 -08:00
|
|
|
// Fixes issue that OAuth1 library only works with "url" property and not with "uri"
|
|
|
|
// @ts-ignore
|
|
|
|
if (requestOptions.uri && !requestOptions.url) {
|
|
|
|
// @ts-ignore
|
|
|
|
requestOptions.url = requestOptions.uri;
|
|
|
|
// @ts-ignore
|
|
|
|
delete requestOptions.uri;
|
|
|
|
}
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
// @ts-ignore
|
2020-11-03 14:01:38 -08:00
|
|
|
requestOptions.headers = oauth.toHeader(oauth.authorize(requestOptions, token));
|
2020-07-25 01:09:52 -07:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
return this.helpers.request!(requestOptions).catch(async (error: IResponseError) => {
|
|
|
|
// Unknown error so simply throw it
|
|
|
|
throw error;
|
|
|
|
});
|
2020-06-01 17:42:38 -07:00
|
|
|
}
|
2020-01-13 18:46:58 -08:00
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
/**
|
|
|
|
* Takes generic input data and brings it into the json format n8n uses.
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {(IDataObject | IDataObject[])} jsonData
|
|
|
|
* @returns {INodeExecutionData[]}
|
|
|
|
*/
|
|
|
|
export function returnJsonArray(jsonData: IDataObject | IDataObject[]): INodeExecutionData[] {
|
|
|
|
const returnData: INodeExecutionData[] = [];
|
|
|
|
|
|
|
|
if (!Array.isArray(jsonData)) {
|
|
|
|
jsonData = [jsonData];
|
|
|
|
}
|
|
|
|
|
|
|
|
jsonData.forEach((data) => {
|
|
|
|
returnData.push({ json: data });
|
|
|
|
});
|
|
|
|
|
|
|
|
return returnData;
|
|
|
|
}
|
|
|
|
|
2021-08-21 05:11:32 -07:00
|
|
|
/**
|
|
|
|
* Returns the additional keys for Expressions and Function-Nodes
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {IWorkflowExecuteAdditionalData} additionalData
|
|
|
|
* @returns {(IWorkflowDataProxyAdditionalKeys)}
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
export function getAdditionalKeys(
|
|
|
|
additionalData: IWorkflowExecuteAdditionalData,
|
|
|
|
): IWorkflowDataProxyAdditionalKeys {
|
2021-08-21 05:11:32 -07:00
|
|
|
const executionId = additionalData.executionId || PLACEHOLDER_EMPTY_EXECUTION_ID;
|
|
|
|
return {
|
|
|
|
$executionId: executionId,
|
|
|
|
$resumeWebhookUrl: `${additionalData.webhookWaitingBaseUrl}/${executionId}`,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
/**
|
|
|
|
* Returns the requested decrypted credentials if the node has access to them.
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {Workflow} workflow Workflow which requests the data
|
|
|
|
* @param {INode} node Node which request the data
|
|
|
|
* @param {string} type The credential type to return
|
|
|
|
* @param {IWorkflowExecuteAdditionalData} additionalData
|
|
|
|
* @returns {(ICredentialDataDecryptedObject | undefined)}
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
export async function getCredentials(
|
|
|
|
workflow: Workflow,
|
|
|
|
node: INode,
|
|
|
|
type: string,
|
|
|
|
additionalData: IWorkflowExecuteAdditionalData,
|
|
|
|
mode: WorkflowExecuteMode,
|
|
|
|
runExecutionData?: IRunExecutionData | null,
|
|
|
|
runIndex?: number,
|
|
|
|
connectionInputData?: INodeExecutionData[],
|
|
|
|
itemIndex?: number,
|
|
|
|
): Promise<ICredentialDataDecryptedObject | undefined> {
|
2019-06-23 03:35:23 -07:00
|
|
|
// Get the NodeType as it has the information if the credentials are required
|
2021-09-21 10:38:24 -07:00
|
|
|
const nodeType = workflow.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
|
2019-06-23 03:35:23 -07:00
|
|
|
if (nodeType === undefined) {
|
2021-08-29 11:58:11 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
node,
|
|
|
|
`Node type "${node.type}" is not known so can not get credentials!`,
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nodeType.description.credentials === undefined) {
|
2021-08-29 11:58:11 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
node,
|
|
|
|
`Node type "${node.type}" does not have any credentials defined!`,
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
const nodeCredentialDescription = nodeType.description.credentials.find(
|
|
|
|
(credentialTypeDescription) => credentialTypeDescription.name === type,
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
if (nodeCredentialDescription === undefined) {
|
2021-08-29 11:58:11 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
node,
|
|
|
|
`Node type "${node.type}" does not have any credentials of type "${type}" defined!`,
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
if (
|
|
|
|
!NodeHelpers.displayParameter(
|
|
|
|
additionalData.currentNodeParameters || node.parameters,
|
|
|
|
nodeCredentialDescription,
|
|
|
|
node.parameters,
|
|
|
|
)
|
|
|
|
) {
|
2019-06-23 03:35:23 -07:00
|
|
|
// Credentials should not be displayed so return undefined even if they would be defined
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if node has any credentials defined
|
|
|
|
if (!node.credentials || !node.credentials[type]) {
|
|
|
|
// If none are defined check if the credentials are required or not
|
|
|
|
|
|
|
|
if (nodeCredentialDescription.required === true) {
|
|
|
|
// Credentials are required so error
|
|
|
|
if (!node.credentials) {
|
2021-08-29 11:58:11 -07:00
|
|
|
throw new NodeOperationError(node, 'Node does not have any credentials set!');
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
if (!node.credentials[type]) {
|
2021-08-29 11:58:11 -07:00
|
|
|
throw new NodeOperationError(node, `Node does not have any credentials set for "${type}"!`);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Credentials are not required so resolve with undefined
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-24 04:33:57 -08:00
|
|
|
let expressionResolveValues: ICredentialsExpressionResolveValues | undefined;
|
|
|
|
if (connectionInputData && runExecutionData && runIndex !== undefined) {
|
|
|
|
expressionResolveValues = {
|
|
|
|
connectionInputData,
|
|
|
|
itemIndex: itemIndex || 0,
|
|
|
|
node,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
workflow,
|
|
|
|
} as ICredentialsExpressionResolveValues;
|
|
|
|
}
|
|
|
|
|
2021-10-13 15:21:00 -07:00
|
|
|
const nodeCredentials = node.credentials[type];
|
|
|
|
|
|
|
|
// TODO: solve using credentials via expression
|
|
|
|
// if (name.charAt(0) === '=') {
|
|
|
|
// // If the credential name is an expression resolve it
|
|
|
|
// const additionalKeys = getAdditionalKeys(additionalData);
|
|
|
|
// name = workflow.expression.getParameterValue(
|
|
|
|
// name,
|
|
|
|
// runExecutionData || null,
|
|
|
|
// runIndex || 0,
|
|
|
|
// itemIndex || 0,
|
|
|
|
// node.name,
|
|
|
|
// connectionInputData || [],
|
|
|
|
// mode,
|
|
|
|
// additionalKeys,
|
|
|
|
// ) as string;
|
|
|
|
// }
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
const decryptedDataObject = await additionalData.credentialsHelper.getDecrypted(
|
2021-10-13 15:21:00 -07:00
|
|
|
nodeCredentials,
|
2021-08-29 11:58:11 -07:00
|
|
|
type,
|
|
|
|
mode,
|
|
|
|
false,
|
|
|
|
expressionResolveValues,
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
|
|
|
|
return decryptedDataObject;
|
|
|
|
}
|
|
|
|
|
2020-02-15 17:07:01 -08:00
|
|
|
/**
|
|
|
|
* Returns a copy of the node
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {INode} node
|
|
|
|
* @returns {INode}
|
|
|
|
*/
|
|
|
|
export function getNode(node: INode): INode {
|
|
|
|
return JSON.parse(JSON.stringify(node));
|
|
|
|
}
|
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
/**
|
|
|
|
* Returns the requested resolved (all expressions replaced) node parameters.
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {Workflow} workflow
|
|
|
|
* @param {(IRunExecutionData | null)} runExecutionData
|
|
|
|
* @param {number} runIndex
|
|
|
|
* @param {INodeExecutionData[]} connectionInputData
|
|
|
|
* @param {INode} node
|
|
|
|
* @param {string} parameterName
|
|
|
|
* @param {number} itemIndex
|
|
|
|
* @param {*} [fallbackValue]
|
|
|
|
* @returns {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object)}
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
export function getNodeParameter(
|
|
|
|
workflow: Workflow,
|
|
|
|
runExecutionData: IRunExecutionData | null,
|
|
|
|
runIndex: number,
|
|
|
|
connectionInputData: INodeExecutionData[],
|
|
|
|
node: INode,
|
|
|
|
parameterName: string,
|
|
|
|
itemIndex: number,
|
|
|
|
mode: WorkflowExecuteMode,
|
|
|
|
additionalKeys: IWorkflowDataProxyAdditionalKeys,
|
|
|
|
fallbackValue?: any,
|
|
|
|
): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object {
|
2021-09-21 10:38:24 -07:00
|
|
|
const nodeType = workflow.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
|
2019-06-23 03:35:23 -07:00
|
|
|
if (nodeType === undefined) {
|
|
|
|
throw new Error(`Node type "${node.type}" is not known so can not return paramter value!`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const value = get(node.parameters, parameterName, fallbackValue);
|
|
|
|
|
|
|
|
if (value === undefined) {
|
|
|
|
throw new Error(`Could not get parameter "${parameterName}"!`);
|
|
|
|
}
|
|
|
|
|
2019-11-07 22:18:01 -08:00
|
|
|
let returnData;
|
|
|
|
try {
|
2021-08-29 11:58:11 -07:00
|
|
|
returnData = workflow.expression.getParameterValue(
|
|
|
|
value,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
node.name,
|
|
|
|
connectionInputData,
|
|
|
|
mode,
|
|
|
|
additionalKeys,
|
|
|
|
);
|
2019-11-07 22:18:01 -08:00
|
|
|
} catch (e) {
|
|
|
|
e.message += ` [Error in parameter: "${parameterName}"]`;
|
|
|
|
throw e;
|
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
|
|
|
|
return returnData;
|
|
|
|
}
|
|
|
|
|
2020-03-17 05:18:04 -07:00
|
|
|
/**
|
|
|
|
* Returns if execution should be continued even if there was an error.
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {INode} node
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function continueOnFail(node: INode): boolean {
|
|
|
|
return get(node, 'continueOnFail', false);
|
|
|
|
}
|
|
|
|
|
2019-07-12 02:33:18 -07:00
|
|
|
/**
|
|
|
|
* Returns the webhook URL of the webhook with the given name
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {string} name
|
|
|
|
* @param {Workflow} workflow
|
|
|
|
* @param {INode} node
|
|
|
|
* @param {IWorkflowExecuteAdditionalData} additionalData
|
|
|
|
* @param {boolean} [isTest]
|
|
|
|
* @returns {(string | undefined)}
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
export function getNodeWebhookUrl(
|
|
|
|
name: string,
|
|
|
|
workflow: Workflow,
|
|
|
|
node: INode,
|
|
|
|
additionalData: IWorkflowExecuteAdditionalData,
|
|
|
|
mode: WorkflowExecuteMode,
|
|
|
|
additionalKeys: IWorkflowDataProxyAdditionalKeys,
|
|
|
|
isTest?: boolean,
|
|
|
|
): string | undefined {
|
2019-07-12 02:33:18 -07:00
|
|
|
let baseUrl = additionalData.webhookBaseUrl;
|
|
|
|
if (isTest === true) {
|
|
|
|
baseUrl = additionalData.webhookTestBaseUrl;
|
|
|
|
}
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
2019-07-12 02:33:18 -07:00
|
|
|
const webhookDescription = getWebhookDescription(name, workflow, node);
|
|
|
|
if (webhookDescription === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
const path = workflow.expression.getSimpleParameterValue(
|
|
|
|
node,
|
|
|
|
webhookDescription.path,
|
|
|
|
mode,
|
|
|
|
additionalKeys,
|
|
|
|
);
|
2019-07-12 02:33:18 -07:00
|
|
|
if (path === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
const isFullPath: boolean = workflow.expression.getSimpleParameterValue(
|
|
|
|
node,
|
|
|
|
webhookDescription.isFullPath,
|
|
|
|
mode,
|
|
|
|
additionalKeys,
|
|
|
|
false,
|
|
|
|
) as boolean;
|
2020-06-10 06:39:15 -07:00
|
|
|
return NodeHelpers.getNodeWebhookUrl(baseUrl, workflow.id!, node, path.toString(), isFullPath);
|
2019-07-12 02:33:18 -07:00
|
|
|
}
|
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
/**
|
|
|
|
* Returns the timezone for the workflow
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {Workflow} workflow
|
|
|
|
* @param {IWorkflowExecuteAdditionalData} additionalData
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
export function getTimezone(
|
|
|
|
workflow: Workflow,
|
|
|
|
additionalData: IWorkflowExecuteAdditionalData,
|
|
|
|
): string {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
2019-06-23 03:35:23 -07:00
|
|
|
if (workflow.settings !== undefined && workflow.settings.timezone !== undefined) {
|
|
|
|
return (workflow.settings as IWorkflowSettings).timezone as string;
|
|
|
|
}
|
|
|
|
return additionalData.timezone;
|
|
|
|
}
|
|
|
|
|
2019-07-12 02:33:18 -07:00
|
|
|
/**
|
|
|
|
* Returns the full webhook description of the webhook with the given name
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {string} name
|
|
|
|
* @param {Workflow} workflow
|
|
|
|
* @param {INode} node
|
|
|
|
* @returns {(IWebhookDescription | undefined)}
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
export function getWebhookDescription(
|
|
|
|
name: string,
|
|
|
|
workflow: Workflow,
|
|
|
|
node: INode,
|
|
|
|
): IWebhookDescription | undefined {
|
2021-09-21 10:38:24 -07:00
|
|
|
const nodeType = workflow.nodeTypes.getByNameAndVersion(node.type, node.typeVersion) as INodeType;
|
2019-07-12 02:33:18 -07:00
|
|
|
|
|
|
|
if (nodeType.description.webhooks === undefined) {
|
|
|
|
// Node does not have any webhooks so return
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2019-07-12 02:33:18 -07:00
|
|
|
for (const webhookDescription of nodeType.description.webhooks) {
|
|
|
|
if (webhookDescription.name === name) {
|
|
|
|
return webhookDescription;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2020-02-15 17:07:01 -08:00
|
|
|
/**
|
|
|
|
* Returns the workflow metadata
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {Workflow} workflow
|
|
|
|
* @returns {IWorkflowMetadata}
|
|
|
|
*/
|
|
|
|
export function getWorkflowMetadata(workflow: Workflow): IWorkflowMetadata {
|
|
|
|
return {
|
|
|
|
id: workflow.id,
|
|
|
|
name: workflow.name,
|
|
|
|
active: workflow.active,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-12-31 12:19:37 -08:00
|
|
|
/**
|
|
|
|
* Returns the execute functions the poll nodes have access to.
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {Workflow} workflow
|
|
|
|
* @param {INode} node
|
|
|
|
* @param {IWorkflowExecuteAdditionalData} additionalData
|
|
|
|
* @param {WorkflowExecuteMode} mode
|
|
|
|
* @returns {ITriggerFunctions}
|
|
|
|
*/
|
|
|
|
// TODO: Check if I can get rid of: additionalData, and so then maybe also at ActiveWorkflowRunner.add
|
2021-08-29 11:58:11 -07:00
|
|
|
export function getExecutePollFunctions(
|
|
|
|
workflow: Workflow,
|
|
|
|
node: INode,
|
|
|
|
additionalData: IWorkflowExecuteAdditionalData,
|
|
|
|
mode: WorkflowExecuteMode,
|
|
|
|
activation: WorkflowActivateMode,
|
|
|
|
): IPollFunctions {
|
2019-12-31 12:19:37 -08:00
|
|
|
return ((workflow: Workflow, node: INode) => {
|
|
|
|
return {
|
|
|
|
__emit: (data: INodeExecutionData[][]): void => {
|
|
|
|
throw new Error('Overwrite NodeExecuteFunctions.getExecutePullFunctions.__emit function!');
|
|
|
|
},
|
2021-08-20 09:57:30 -07:00
|
|
|
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject | undefined> {
|
2021-08-29 11:58:11 -07:00
|
|
|
return getCredentials(workflow, node, type, additionalData, mode);
|
2019-12-31 12:19:37 -08:00
|
|
|
},
|
|
|
|
getMode: (): WorkflowExecuteMode => {
|
|
|
|
return mode;
|
|
|
|
},
|
2021-03-23 11:08:47 -07:00
|
|
|
getActivationMode: (): WorkflowActivateMode => {
|
|
|
|
return activation;
|
|
|
|
},
|
2020-02-15 17:07:01 -08:00
|
|
|
getNode: () => {
|
|
|
|
return getNode(node);
|
|
|
|
},
|
2021-08-29 11:58:11 -07:00
|
|
|
getNodeParameter: (
|
|
|
|
parameterName: string,
|
|
|
|
fallbackValue?: any,
|
|
|
|
):
|
|
|
|
| NodeParameterValue
|
|
|
|
| INodeParameters
|
|
|
|
| NodeParameterValue[]
|
|
|
|
| INodeParameters[]
|
|
|
|
| object => {
|
2019-12-31 12:19:37 -08:00
|
|
|
const runExecutionData: IRunExecutionData | null = null;
|
|
|
|
const itemIndex = 0;
|
|
|
|
const runIndex = 0;
|
|
|
|
const connectionInputData: INodeExecutionData[] = [];
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
return getNodeParameter(
|
|
|
|
workflow,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
connectionInputData,
|
|
|
|
node,
|
|
|
|
parameterName,
|
|
|
|
itemIndex,
|
|
|
|
mode,
|
|
|
|
getAdditionalKeys(additionalData),
|
|
|
|
fallbackValue,
|
|
|
|
);
|
2019-12-31 12:19:37 -08:00
|
|
|
},
|
|
|
|
getRestApiUrl: (): string => {
|
|
|
|
return additionalData.restApiUrl;
|
|
|
|
},
|
|
|
|
getTimezone: (): string => {
|
|
|
|
return getTimezone(workflow, additionalData);
|
|
|
|
},
|
2020-02-15 17:07:01 -08:00
|
|
|
getWorkflow: () => {
|
|
|
|
return getWorkflowMetadata(workflow);
|
|
|
|
},
|
2019-12-31 12:19:37 -08:00
|
|
|
getWorkflowStaticData(type: string): IDataObject {
|
|
|
|
return workflow.getStaticData(type, node);
|
|
|
|
},
|
|
|
|
helpers: {
|
2021-09-21 10:38:24 -07:00
|
|
|
httpRequest,
|
2021-12-23 13:29:04 -08:00
|
|
|
async prepareBinaryData(
|
|
|
|
binaryData: Buffer,
|
|
|
|
filePath?: string,
|
|
|
|
mimeType?: string,
|
|
|
|
): Promise<IBinaryData> {
|
|
|
|
return prepareBinaryData.call(
|
|
|
|
this,
|
|
|
|
binaryData,
|
|
|
|
additionalData.executionId!,
|
|
|
|
filePath,
|
|
|
|
mimeType,
|
|
|
|
);
|
|
|
|
},
|
2021-09-21 10:38:24 -07:00
|
|
|
request: proxyRequestToAxios,
|
2021-08-29 11:58:11 -07:00
|
|
|
async requestOAuth2(
|
|
|
|
this: IAllExecuteFunctions,
|
|
|
|
credentialsType: string,
|
|
|
|
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
|
|
|
oAuth2Options?: IOAuth2Options,
|
|
|
|
): Promise<any> {
|
|
|
|
return requestOAuth2.call(
|
|
|
|
this,
|
|
|
|
credentialsType,
|
|
|
|
requestOptions,
|
|
|
|
node,
|
|
|
|
additionalData,
|
|
|
|
oAuth2Options,
|
|
|
|
);
|
2020-06-01 17:42:38 -07:00
|
|
|
},
|
2021-08-29 11:58:11 -07:00
|
|
|
async requestOAuth1(
|
|
|
|
this: IAllExecuteFunctions,
|
|
|
|
credentialsType: string,
|
|
|
|
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
|
|
|
|
): Promise<any> {
|
2020-06-01 17:42:38 -07:00
|
|
|
return requestOAuth1.call(this, credentialsType, requestOptions);
|
2020-01-13 18:46:58 -08:00
|
|
|
},
|
2019-12-31 12:19:37 -08:00
|
|
|
returnJsonArray,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
})(workflow, node);
|
|
|
|
}
|
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
/**
|
|
|
|
* Returns the execute functions the trigger nodes have access to.
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {Workflow} workflow
|
|
|
|
* @param {INode} node
|
|
|
|
* @param {IWorkflowExecuteAdditionalData} additionalData
|
|
|
|
* @param {WorkflowExecuteMode} mode
|
|
|
|
* @returns {ITriggerFunctions}
|
|
|
|
*/
|
2019-08-08 11:38:25 -07:00
|
|
|
// TODO: Check if I can get rid of: additionalData, and so then maybe also at ActiveWorkflowRunner.add
|
2021-08-29 11:58:11 -07:00
|
|
|
export function getExecuteTriggerFunctions(
|
|
|
|
workflow: Workflow,
|
|
|
|
node: INode,
|
|
|
|
additionalData: IWorkflowExecuteAdditionalData,
|
|
|
|
mode: WorkflowExecuteMode,
|
|
|
|
activation: WorkflowActivateMode,
|
|
|
|
): ITriggerFunctions {
|
2019-06-23 03:35:23 -07:00
|
|
|
return ((workflow: Workflow, node: INode) => {
|
|
|
|
return {
|
|
|
|
emit: (data: INodeExecutionData[][]): void => {
|
2019-08-08 11:38:25 -07:00
|
|
|
throw new Error('Overwrite NodeExecuteFunctions.getExecuteTriggerFunctions.emit function!');
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2021-08-20 09:57:30 -07:00
|
|
|
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject | undefined> {
|
2021-08-29 11:58:11 -07:00
|
|
|
return getCredentials(workflow, node, type, additionalData, mode);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2020-02-15 17:07:01 -08:00
|
|
|
getNode: () => {
|
|
|
|
return getNode(node);
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
getMode: (): WorkflowExecuteMode => {
|
|
|
|
return mode;
|
|
|
|
},
|
2021-03-23 11:08:47 -07:00
|
|
|
getActivationMode: (): WorkflowActivateMode => {
|
|
|
|
return activation;
|
|
|
|
},
|
2021-08-29 11:58:11 -07:00
|
|
|
getNodeParameter: (
|
|
|
|
parameterName: string,
|
|
|
|
fallbackValue?: any,
|
|
|
|
):
|
|
|
|
| NodeParameterValue
|
|
|
|
| INodeParameters
|
|
|
|
| NodeParameterValue[]
|
|
|
|
| INodeParameters[]
|
|
|
|
| object => {
|
2019-06-23 03:35:23 -07:00
|
|
|
const runExecutionData: IRunExecutionData | null = null;
|
|
|
|
const itemIndex = 0;
|
|
|
|
const runIndex = 0;
|
|
|
|
const connectionInputData: INodeExecutionData[] = [];
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
return getNodeParameter(
|
|
|
|
workflow,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
connectionInputData,
|
|
|
|
node,
|
|
|
|
parameterName,
|
|
|
|
itemIndex,
|
|
|
|
mode,
|
|
|
|
getAdditionalKeys(additionalData),
|
|
|
|
fallbackValue,
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2019-12-19 14:07:55 -08:00
|
|
|
getRestApiUrl: (): string => {
|
|
|
|
return additionalData.restApiUrl;
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
getTimezone: (): string => {
|
|
|
|
return getTimezone(workflow, additionalData);
|
|
|
|
},
|
2020-02-15 17:07:01 -08:00
|
|
|
getWorkflow: () => {
|
|
|
|
return getWorkflowMetadata(workflow);
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
getWorkflowStaticData(type: string): IDataObject {
|
|
|
|
return workflow.getStaticData(type, node);
|
|
|
|
},
|
|
|
|
helpers: {
|
2021-09-21 10:38:24 -07:00
|
|
|
httpRequest,
|
2021-12-23 13:29:04 -08:00
|
|
|
async prepareBinaryData(
|
|
|
|
binaryData: Buffer,
|
|
|
|
filePath?: string,
|
|
|
|
mimeType?: string,
|
|
|
|
): Promise<IBinaryData> {
|
|
|
|
return prepareBinaryData.call(
|
|
|
|
this,
|
|
|
|
binaryData,
|
|
|
|
additionalData.executionId!,
|
|
|
|
filePath,
|
|
|
|
mimeType,
|
|
|
|
);
|
|
|
|
},
|
2021-09-21 10:38:24 -07:00
|
|
|
request: proxyRequestToAxios,
|
2021-08-29 11:58:11 -07:00
|
|
|
async requestOAuth2(
|
|
|
|
this: IAllExecuteFunctions,
|
|
|
|
credentialsType: string,
|
|
|
|
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
|
|
|
oAuth2Options?: IOAuth2Options,
|
|
|
|
): Promise<any> {
|
|
|
|
return requestOAuth2.call(
|
|
|
|
this,
|
|
|
|
credentialsType,
|
|
|
|
requestOptions,
|
|
|
|
node,
|
|
|
|
additionalData,
|
|
|
|
oAuth2Options,
|
|
|
|
);
|
2020-06-01 17:42:38 -07:00
|
|
|
},
|
2021-08-29 11:58:11 -07:00
|
|
|
async requestOAuth1(
|
|
|
|
this: IAllExecuteFunctions,
|
|
|
|
credentialsType: string,
|
|
|
|
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
|
|
|
|
): Promise<any> {
|
2020-06-01 17:42:38 -07:00
|
|
|
return requestOAuth1.call(this, credentialsType, requestOptions);
|
2020-01-13 18:46:58 -08:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
returnJsonArray,
|
|
|
|
},
|
|
|
|
};
|
2021-08-29 11:58:11 -07:00
|
|
|
})(workflow, node);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the execute functions regular nodes have access to.
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {Workflow} workflow
|
|
|
|
* @param {IRunExecutionData} runExecutionData
|
|
|
|
* @param {number} runIndex
|
|
|
|
* @param {INodeExecutionData[]} connectionInputData
|
|
|
|
* @param {ITaskDataConnections} inputData
|
|
|
|
* @param {INode} node
|
|
|
|
* @param {IWorkflowExecuteAdditionalData} additionalData
|
|
|
|
* @param {WorkflowExecuteMode} mode
|
|
|
|
* @returns {IExecuteFunctions}
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
export function getExecuteFunctions(
|
|
|
|
workflow: Workflow,
|
|
|
|
runExecutionData: IRunExecutionData,
|
|
|
|
runIndex: number,
|
|
|
|
connectionInputData: INodeExecutionData[],
|
|
|
|
inputData: ITaskDataConnections,
|
|
|
|
node: INode,
|
|
|
|
additionalData: IWorkflowExecuteAdditionalData,
|
|
|
|
mode: WorkflowExecuteMode,
|
|
|
|
): IExecuteFunctions {
|
2019-06-23 03:35:23 -07:00
|
|
|
return ((workflow, runExecutionData, connectionInputData, inputData, node) => {
|
|
|
|
return {
|
2020-03-17 05:18:04 -07:00
|
|
|
continueOnFail: () => {
|
|
|
|
return continueOnFail(node);
|
|
|
|
},
|
2020-03-21 09:25:29 -07:00
|
|
|
evaluateExpression: (expression: string, itemIndex: number) => {
|
2021-08-29 11:58:11 -07:00
|
|
|
return workflow.expression.resolveSimpleParameterValue(
|
|
|
|
`=${expression}`,
|
|
|
|
{},
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
node.name,
|
|
|
|
connectionInputData,
|
|
|
|
mode,
|
|
|
|
getAdditionalKeys(additionalData),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
async executeWorkflow(
|
|
|
|
workflowInfo: IExecuteWorkflowInfo,
|
|
|
|
inputData?: INodeExecutionData[],
|
|
|
|
): Promise<any> {
|
2021-12-23 13:29:04 -08:00
|
|
|
return additionalData
|
|
|
|
.executeWorkflow(workflowInfo, additionalData, inputData)
|
|
|
|
.then(async (result) =>
|
|
|
|
BinaryDataManager.getInstance().duplicateBinaryData(
|
|
|
|
result,
|
|
|
|
additionalData.executionId!,
|
|
|
|
),
|
|
|
|
);
|
2019-12-19 14:07:55 -08:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
getContext(type: string): IContextObject {
|
|
|
|
return NodeHelpers.getContext(runExecutionData, type, node);
|
|
|
|
},
|
2021-08-29 11:58:11 -07:00
|
|
|
async getCredentials(
|
|
|
|
type: string,
|
|
|
|
itemIndex?: number,
|
|
|
|
): Promise<ICredentialDataDecryptedObject | undefined> {
|
|
|
|
return getCredentials(
|
|
|
|
workflow,
|
|
|
|
node,
|
|
|
|
type,
|
|
|
|
additionalData,
|
|
|
|
mode,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
connectionInputData,
|
|
|
|
itemIndex,
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2021-08-21 05:11:32 -07:00
|
|
|
getExecutionId: (): string => {
|
|
|
|
return additionalData.executionId!;
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
getInputData: (inputIndex = 0, inputName = 'main') => {
|
|
|
|
if (!inputData.hasOwnProperty(inputName)) {
|
|
|
|
// Return empty array because else it would throw error when nothing is connected to input
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Check if nodeType has input with that index defined
|
|
|
|
if (inputData[inputName].length < inputIndex) {
|
|
|
|
throw new Error(`Could not get input index "${inputIndex}" of input "${inputName}"!`);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputData[inputName][inputIndex] === null) {
|
|
|
|
// return [];
|
|
|
|
throw new Error(`Value "${inputIndex}" of input "${inputName}" did not get set!`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return inputData[inputName][inputIndex] as INodeExecutionData[];
|
|
|
|
},
|
2021-08-29 11:58:11 -07:00
|
|
|
getNodeParameter: (
|
|
|
|
parameterName: string,
|
|
|
|
itemIndex: number,
|
|
|
|
fallbackValue?: any,
|
|
|
|
):
|
|
|
|
| NodeParameterValue
|
|
|
|
| INodeParameters
|
|
|
|
| NodeParameterValue[]
|
|
|
|
| INodeParameters[]
|
|
|
|
| object => {
|
|
|
|
return getNodeParameter(
|
|
|
|
workflow,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
connectionInputData,
|
|
|
|
node,
|
|
|
|
parameterName,
|
|
|
|
itemIndex,
|
|
|
|
mode,
|
|
|
|
getAdditionalKeys(additionalData),
|
|
|
|
fallbackValue,
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
getMode: (): WorkflowExecuteMode => {
|
|
|
|
return mode;
|
|
|
|
},
|
2020-02-15 17:07:01 -08:00
|
|
|
getNode: () => {
|
|
|
|
return getNode(node);
|
|
|
|
},
|
2019-12-19 14:07:55 -08:00
|
|
|
getRestApiUrl: (): string => {
|
|
|
|
return additionalData.restApiUrl;
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
getTimezone: (): string => {
|
|
|
|
return getTimezone(workflow, additionalData);
|
|
|
|
},
|
2020-02-15 17:07:01 -08:00
|
|
|
getWorkflow: () => {
|
|
|
|
return getWorkflowMetadata(workflow);
|
|
|
|
},
|
2019-09-04 05:53:39 -07:00
|
|
|
getWorkflowDataProxy: (itemIndex: number): IWorkflowDataProxyData => {
|
2021-08-29 11:58:11 -07:00
|
|
|
const dataProxy = new WorkflowDataProxy(
|
|
|
|
workflow,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
node.name,
|
|
|
|
connectionInputData,
|
|
|
|
{},
|
|
|
|
mode,
|
|
|
|
getAdditionalKeys(additionalData),
|
|
|
|
);
|
2019-09-04 05:53:39 -07:00
|
|
|
return dataProxy.getDataProxy();
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
getWorkflowStaticData(type: string): IDataObject {
|
|
|
|
return workflow.getStaticData(type, node);
|
|
|
|
},
|
|
|
|
prepareOutputData: NodeHelpers.prepareOutputData,
|
2021-08-21 05:11:32 -07:00
|
|
|
async putExecutionToWait(waitTill: Date): Promise<void> {
|
|
|
|
runExecutionData.waitTill = waitTill;
|
|
|
|
},
|
2021-12-04 02:57:13 -08:00
|
|
|
sendMessageToUI(...args: any[]): void {
|
2021-05-29 11:41:25 -07:00
|
|
|
if (mode !== 'manual') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (additionalData.sendMessageToUI) {
|
2021-12-04 02:57:13 -08:00
|
|
|
additionalData.sendMessageToUI(node.name, args);
|
2021-05-29 11:41:25 -07:00
|
|
|
}
|
|
|
|
} catch (error) {
|
2021-08-29 11:58:11 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
2021-05-29 11:41:25 -07:00
|
|
|
Logger.warn(`There was a problem sending messsage to UI: ${error.message}`);
|
|
|
|
}
|
|
|
|
},
|
2021-11-05 09:45:51 -07:00
|
|
|
async sendResponse(response: IExecuteResponsePromiseData): Promise<void> {
|
|
|
|
await additionalData.hooks?.executeHookFunctions('sendResponse', [response]);
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
helpers: {
|
2021-09-21 10:38:24 -07:00
|
|
|
httpRequest,
|
2021-12-23 13:29:04 -08:00
|
|
|
async prepareBinaryData(
|
|
|
|
binaryData: Buffer,
|
|
|
|
filePath?: string,
|
|
|
|
mimeType?: string,
|
|
|
|
): Promise<IBinaryData> {
|
|
|
|
return prepareBinaryData.call(
|
|
|
|
this,
|
|
|
|
binaryData,
|
|
|
|
additionalData.executionId!,
|
|
|
|
filePath,
|
|
|
|
mimeType,
|
|
|
|
);
|
|
|
|
},
|
2021-08-29 11:58:11 -07:00
|
|
|
async getBinaryDataBuffer(
|
|
|
|
itemIndex: number,
|
|
|
|
propertyName: string,
|
|
|
|
inputIndex = 0,
|
|
|
|
): Promise<Buffer> {
|
2021-08-20 09:08:40 -07:00
|
|
|
return getBinaryDataBuffer.call(this, inputData, itemIndex, propertyName, inputIndex);
|
|
|
|
},
|
2021-09-21 10:38:24 -07:00
|
|
|
request: proxyRequestToAxios,
|
2021-08-29 11:58:11 -07:00
|
|
|
async requestOAuth2(
|
|
|
|
this: IAllExecuteFunctions,
|
|
|
|
credentialsType: string,
|
|
|
|
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
|
|
|
oAuth2Options?: IOAuth2Options,
|
|
|
|
): Promise<any> {
|
|
|
|
return requestOAuth2.call(
|
|
|
|
this,
|
|
|
|
credentialsType,
|
|
|
|
requestOptions,
|
|
|
|
node,
|
|
|
|
additionalData,
|
|
|
|
oAuth2Options,
|
|
|
|
);
|
2020-06-01 17:42:38 -07:00
|
|
|
},
|
2021-08-29 11:58:11 -07:00
|
|
|
async requestOAuth1(
|
|
|
|
this: IAllExecuteFunctions,
|
|
|
|
credentialsType: string,
|
|
|
|
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
|
|
|
|
): Promise<any> {
|
2020-06-01 17:42:38 -07:00
|
|
|
return requestOAuth1.call(this, credentialsType, requestOptions);
|
2020-01-13 18:46:58 -08:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
returnJsonArray,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
})(workflow, runExecutionData, connectionInputData, inputData, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the execute functions regular nodes have access to when single-function is defined.
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {Workflow} workflow
|
|
|
|
* @param {IRunExecutionData} runExecutionData
|
|
|
|
* @param {number} runIndex
|
|
|
|
* @param {INodeExecutionData[]} connectionInputData
|
|
|
|
* @param {ITaskDataConnections} inputData
|
|
|
|
* @param {INode} node
|
|
|
|
* @param {number} itemIndex
|
|
|
|
* @param {IWorkflowExecuteAdditionalData} additionalData
|
|
|
|
* @param {WorkflowExecuteMode} mode
|
|
|
|
* @returns {IExecuteSingleFunctions}
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
export function getExecuteSingleFunctions(
|
|
|
|
workflow: Workflow,
|
|
|
|
runExecutionData: IRunExecutionData,
|
|
|
|
runIndex: number,
|
|
|
|
connectionInputData: INodeExecutionData[],
|
|
|
|
inputData: ITaskDataConnections,
|
|
|
|
node: INode,
|
|
|
|
itemIndex: number,
|
|
|
|
additionalData: IWorkflowExecuteAdditionalData,
|
|
|
|
mode: WorkflowExecuteMode,
|
|
|
|
): IExecuteSingleFunctions {
|
2019-06-23 03:35:23 -07:00
|
|
|
return ((workflow, runExecutionData, connectionInputData, inputData, node, itemIndex) => {
|
|
|
|
return {
|
2020-03-17 05:18:04 -07:00
|
|
|
continueOnFail: () => {
|
|
|
|
return continueOnFail(node);
|
|
|
|
},
|
2020-03-21 09:25:29 -07:00
|
|
|
evaluateExpression: (expression: string, evaluateItemIndex: number | undefined) => {
|
|
|
|
evaluateItemIndex = evaluateItemIndex === undefined ? itemIndex : evaluateItemIndex;
|
2021-08-29 11:58:11 -07:00
|
|
|
return workflow.expression.resolveSimpleParameterValue(
|
|
|
|
`=${expression}`,
|
|
|
|
{},
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
evaluateItemIndex,
|
|
|
|
node.name,
|
|
|
|
connectionInputData,
|
|
|
|
mode,
|
|
|
|
getAdditionalKeys(additionalData),
|
|
|
|
);
|
2020-03-21 09:25:29 -07:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
getContext(type: string): IContextObject {
|
|
|
|
return NodeHelpers.getContext(runExecutionData, type, node);
|
|
|
|
},
|
2021-08-20 09:57:30 -07:00
|
|
|
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject | undefined> {
|
2021-08-29 11:58:11 -07:00
|
|
|
return getCredentials(
|
|
|
|
workflow,
|
|
|
|
node,
|
|
|
|
type,
|
|
|
|
additionalData,
|
|
|
|
mode,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
connectionInputData,
|
|
|
|
itemIndex,
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
getInputData: (inputIndex = 0, inputName = 'main') => {
|
|
|
|
if (!inputData.hasOwnProperty(inputName)) {
|
|
|
|
// Return empty array because else it would throw error when nothing is connected to input
|
2021-08-29 11:58:11 -07:00
|
|
|
return { json: {} };
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Check if nodeType has input with that index defined
|
|
|
|
if (inputData[inputName].length < inputIndex) {
|
|
|
|
throw new Error(`Could not get input index "${inputIndex}" of input "${inputName}"!`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const allItems = inputData[inputName][inputIndex];
|
|
|
|
|
|
|
|
if (allItems === null) {
|
|
|
|
// return [];
|
|
|
|
throw new Error(`Value "${inputIndex}" of input "${inputName}" did not get set!`);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allItems[itemIndex] === null) {
|
|
|
|
// return [];
|
2021-08-29 11:58:11 -07:00
|
|
|
throw new Error(
|
|
|
|
`Value "${inputIndex}" of input "${inputName}" with itemIndex "${itemIndex}" did not get set!`,
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
return allItems[itemIndex];
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
getMode: (): WorkflowExecuteMode => {
|
|
|
|
return mode;
|
|
|
|
},
|
2020-02-15 17:07:01 -08:00
|
|
|
getNode: () => {
|
|
|
|
return getNode(node);
|
|
|
|
},
|
2019-12-19 14:07:55 -08:00
|
|
|
getRestApiUrl: (): string => {
|
|
|
|
return additionalData.restApiUrl;
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
getTimezone: (): string => {
|
|
|
|
return getTimezone(workflow, additionalData);
|
|
|
|
},
|
2021-08-29 11:58:11 -07:00
|
|
|
getNodeParameter: (
|
|
|
|
parameterName: string,
|
|
|
|
fallbackValue?: any,
|
|
|
|
):
|
|
|
|
| NodeParameterValue
|
|
|
|
| INodeParameters
|
|
|
|
| NodeParameterValue[]
|
|
|
|
| INodeParameters[]
|
|
|
|
| object => {
|
|
|
|
return getNodeParameter(
|
|
|
|
workflow,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
connectionInputData,
|
|
|
|
node,
|
|
|
|
parameterName,
|
|
|
|
itemIndex,
|
|
|
|
mode,
|
|
|
|
getAdditionalKeys(additionalData),
|
|
|
|
fallbackValue,
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2020-02-15 17:07:01 -08:00
|
|
|
getWorkflow: () => {
|
|
|
|
return getWorkflowMetadata(workflow);
|
|
|
|
},
|
2019-09-04 05:53:39 -07:00
|
|
|
getWorkflowDataProxy: (): IWorkflowDataProxyData => {
|
2021-08-29 11:58:11 -07:00
|
|
|
const dataProxy = new WorkflowDataProxy(
|
|
|
|
workflow,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
itemIndex,
|
|
|
|
node.name,
|
|
|
|
connectionInputData,
|
|
|
|
{},
|
|
|
|
mode,
|
|
|
|
getAdditionalKeys(additionalData),
|
|
|
|
);
|
2019-09-04 05:53:39 -07:00
|
|
|
return dataProxy.getDataProxy();
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
getWorkflowStaticData(type: string): IDataObject {
|
|
|
|
return workflow.getStaticData(type, node);
|
|
|
|
},
|
|
|
|
helpers: {
|
2021-09-21 10:38:24 -07:00
|
|
|
httpRequest,
|
2021-12-23 13:29:04 -08:00
|
|
|
async prepareBinaryData(
|
|
|
|
binaryData: Buffer,
|
|
|
|
filePath?: string,
|
|
|
|
mimeType?: string,
|
|
|
|
): Promise<IBinaryData> {
|
|
|
|
return prepareBinaryData.call(
|
|
|
|
this,
|
|
|
|
binaryData,
|
|
|
|
additionalData.executionId!,
|
|
|
|
filePath,
|
|
|
|
mimeType,
|
|
|
|
);
|
|
|
|
},
|
2021-09-21 10:38:24 -07:00
|
|
|
request: proxyRequestToAxios,
|
2021-08-29 11:58:11 -07:00
|
|
|
async requestOAuth2(
|
|
|
|
this: IAllExecuteFunctions,
|
|
|
|
credentialsType: string,
|
|
|
|
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
|
|
|
oAuth2Options?: IOAuth2Options,
|
|
|
|
): Promise<any> {
|
|
|
|
return requestOAuth2.call(
|
|
|
|
this,
|
|
|
|
credentialsType,
|
|
|
|
requestOptions,
|
|
|
|
node,
|
|
|
|
additionalData,
|
|
|
|
oAuth2Options,
|
|
|
|
);
|
2020-06-01 17:42:38 -07:00
|
|
|
},
|
2021-08-29 11:58:11 -07:00
|
|
|
async requestOAuth1(
|
|
|
|
this: IAllExecuteFunctions,
|
|
|
|
credentialsType: string,
|
|
|
|
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
|
|
|
|
): Promise<any> {
|
2020-06-01 17:42:38 -07:00
|
|
|
return requestOAuth1.call(this, credentialsType, requestOptions);
|
2020-01-13 18:46:58 -08:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
})(workflow, runExecutionData, connectionInputData, inputData, node, itemIndex);
|
|
|
|
}
|
|
|
|
|
2021-09-11 01:15:36 -07:00
|
|
|
export function getCredentialTestFunctions(): ICredentialTestFunctions {
|
|
|
|
return {
|
|
|
|
helpers: {
|
|
|
|
request: requestPromiseWithDefaults,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
/**
|
|
|
|
* Returns the execute functions regular nodes have access to in load-options-function.
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {Workflow} workflow
|
|
|
|
* @param {INode} node
|
|
|
|
* @param {IWorkflowExecuteAdditionalData} additionalData
|
|
|
|
* @returns {ILoadOptionsFunctions}
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
export function getLoadOptionsFunctions(
|
|
|
|
workflow: Workflow,
|
|
|
|
node: INode,
|
|
|
|
path: string,
|
|
|
|
additionalData: IWorkflowExecuteAdditionalData,
|
|
|
|
): ILoadOptionsFunctions {
|
2021-05-16 16:16:24 -07:00
|
|
|
return ((workflow: Workflow, node: INode, path: string) => {
|
2019-06-23 03:35:23 -07:00
|
|
|
const that = {
|
2021-08-20 09:57:30 -07:00
|
|
|
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject | undefined> {
|
2021-08-29 11:58:11 -07:00
|
|
|
return getCredentials(workflow, node, type, additionalData, 'internal');
|
|
|
|
},
|
|
|
|
getCurrentNodeParameter: (
|
|
|
|
parameterPath: string,
|
|
|
|
):
|
|
|
|
| NodeParameterValue
|
|
|
|
| INodeParameters
|
|
|
|
| NodeParameterValue[]
|
|
|
|
| INodeParameters[]
|
|
|
|
| object
|
|
|
|
| undefined => {
|
2020-05-04 21:07:19 -07:00
|
|
|
const nodeParameters = additionalData.currentNodeParameters;
|
2021-05-16 16:16:24 -07:00
|
|
|
|
|
|
|
if (parameterPath.charAt(0) === '&') {
|
|
|
|
parameterPath = `${path.split('.').slice(1, -1).join('.')}.${parameterPath.slice(1)}`;
|
2019-10-20 11:55:49 -07:00
|
|
|
}
|
2021-05-16 16:16:24 -07:00
|
|
|
|
|
|
|
return get(nodeParameters, parameterPath);
|
2019-10-20 12:42:34 -07:00
|
|
|
},
|
|
|
|
getCurrentNodeParameters: (): INodeParameters | undefined => {
|
2020-05-04 21:07:19 -07:00
|
|
|
return additionalData.currentNodeParameters;
|
2019-10-20 11:55:49 -07:00
|
|
|
},
|
2020-02-15 17:07:01 -08:00
|
|
|
getNode: () => {
|
|
|
|
return getNode(node);
|
|
|
|
},
|
2021-08-29 11:58:11 -07:00
|
|
|
getNodeParameter: (
|
|
|
|
parameterName: string,
|
|
|
|
fallbackValue?: any,
|
|
|
|
):
|
|
|
|
| NodeParameterValue
|
|
|
|
| INodeParameters
|
|
|
|
| NodeParameterValue[]
|
|
|
|
| INodeParameters[]
|
|
|
|
| object => {
|
2019-06-23 03:35:23 -07:00
|
|
|
const runExecutionData: IRunExecutionData | null = null;
|
|
|
|
const itemIndex = 0;
|
|
|
|
const runIndex = 0;
|
|
|
|
const connectionInputData: INodeExecutionData[] = [];
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
return getNodeParameter(
|
|
|
|
workflow,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
connectionInputData,
|
|
|
|
node,
|
|
|
|
parameterName,
|
|
|
|
itemIndex,
|
|
|
|
'internal' as WorkflowExecuteMode,
|
|
|
|
getAdditionalKeys(additionalData),
|
|
|
|
fallbackValue,
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
getTimezone: (): string => {
|
|
|
|
return getTimezone(workflow, additionalData);
|
|
|
|
},
|
2019-12-19 14:07:55 -08:00
|
|
|
getRestApiUrl: (): string => {
|
|
|
|
return additionalData.restApiUrl;
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
helpers: {
|
2021-09-21 10:38:24 -07:00
|
|
|
httpRequest,
|
|
|
|
request: proxyRequestToAxios,
|
2021-08-29 11:58:11 -07:00
|
|
|
async requestOAuth2(
|
|
|
|
this: IAllExecuteFunctions,
|
|
|
|
credentialsType: string,
|
|
|
|
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
|
|
|
oAuth2Options?: IOAuth2Options,
|
|
|
|
): Promise<any> {
|
|
|
|
return requestOAuth2.call(
|
|
|
|
this,
|
|
|
|
credentialsType,
|
|
|
|
requestOptions,
|
|
|
|
node,
|
|
|
|
additionalData,
|
|
|
|
oAuth2Options,
|
|
|
|
);
|
2020-06-01 17:42:38 -07:00
|
|
|
},
|
2021-08-29 11:58:11 -07:00
|
|
|
async requestOAuth1(
|
|
|
|
this: IAllExecuteFunctions,
|
|
|
|
credentialsType: string,
|
|
|
|
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
|
|
|
|
): Promise<any> {
|
2020-06-01 17:42:38 -07:00
|
|
|
return requestOAuth1.call(this, credentialsType, requestOptions);
|
2020-01-13 18:46:58 -08:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
return that;
|
2021-05-16 16:16:24 -07:00
|
|
|
})(workflow, node, path);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the execute functions regular nodes have access to in hook-function.
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {Workflow} workflow
|
|
|
|
* @param {INode} node
|
|
|
|
* @param {IWorkflowExecuteAdditionalData} additionalData
|
|
|
|
* @param {WorkflowExecuteMode} mode
|
|
|
|
* @returns {IHookFunctions}
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
export function getExecuteHookFunctions(
|
|
|
|
workflow: Workflow,
|
|
|
|
node: INode,
|
|
|
|
additionalData: IWorkflowExecuteAdditionalData,
|
|
|
|
mode: WorkflowExecuteMode,
|
|
|
|
activation: WorkflowActivateMode,
|
|
|
|
isTest?: boolean,
|
|
|
|
webhookData?: IWebhookData,
|
|
|
|
): IHookFunctions {
|
2019-06-23 03:35:23 -07:00
|
|
|
return ((workflow: Workflow, node: INode) => {
|
|
|
|
const that = {
|
2021-08-20 09:57:30 -07:00
|
|
|
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject | undefined> {
|
2021-08-29 11:58:11 -07:00
|
|
|
return getCredentials(workflow, node, type, additionalData, mode);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
getMode: (): WorkflowExecuteMode => {
|
|
|
|
return mode;
|
|
|
|
},
|
2021-03-23 11:08:47 -07:00
|
|
|
getActivationMode: (): WorkflowActivateMode => {
|
|
|
|
return activation;
|
|
|
|
},
|
2020-02-15 17:07:01 -08:00
|
|
|
getNode: () => {
|
|
|
|
return getNode(node);
|
|
|
|
},
|
2021-08-29 11:58:11 -07:00
|
|
|
getNodeParameter: (
|
|
|
|
parameterName: string,
|
|
|
|
fallbackValue?: any,
|
|
|
|
):
|
|
|
|
| NodeParameterValue
|
|
|
|
| INodeParameters
|
|
|
|
| NodeParameterValue[]
|
|
|
|
| INodeParameters[]
|
|
|
|
| object => {
|
2019-06-23 03:35:23 -07:00
|
|
|
const runExecutionData: IRunExecutionData | null = null;
|
|
|
|
const itemIndex = 0;
|
|
|
|
const runIndex = 0;
|
|
|
|
const connectionInputData: INodeExecutionData[] = [];
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
return getNodeParameter(
|
|
|
|
workflow,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
connectionInputData,
|
|
|
|
node,
|
|
|
|
parameterName,
|
|
|
|
itemIndex,
|
|
|
|
mode,
|
|
|
|
getAdditionalKeys(additionalData),
|
|
|
|
fallbackValue,
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
getNodeWebhookUrl: (name: string): string | undefined => {
|
2021-08-29 11:58:11 -07:00
|
|
|
return getNodeWebhookUrl(
|
|
|
|
name,
|
|
|
|
workflow,
|
|
|
|
node,
|
|
|
|
additionalData,
|
|
|
|
mode,
|
|
|
|
getAdditionalKeys(additionalData),
|
|
|
|
isTest,
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
getTimezone: (): string => {
|
|
|
|
return getTimezone(workflow, additionalData);
|
|
|
|
},
|
2019-07-12 02:33:18 -07:00
|
|
|
getWebhookName(): string {
|
|
|
|
if (webhookData === undefined) {
|
|
|
|
throw new Error('Is only supported in webhook functions!');
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
2019-07-12 02:33:18 -07:00
|
|
|
return webhookData.webhookDescription.name;
|
|
|
|
},
|
|
|
|
getWebhookDescription(name: string): IWebhookDescription | undefined {
|
|
|
|
return getWebhookDescription(name, workflow, node);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2020-02-15 17:07:01 -08:00
|
|
|
getWorkflow: () => {
|
|
|
|
return getWorkflowMetadata(workflow);
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
getWorkflowStaticData(type: string): IDataObject {
|
|
|
|
return workflow.getStaticData(type, node);
|
|
|
|
},
|
|
|
|
helpers: {
|
2021-09-21 10:38:24 -07:00
|
|
|
httpRequest,
|
|
|
|
request: proxyRequestToAxios,
|
2021-08-29 11:58:11 -07:00
|
|
|
async requestOAuth2(
|
|
|
|
this: IAllExecuteFunctions,
|
|
|
|
credentialsType: string,
|
|
|
|
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
|
|
|
oAuth2Options?: IOAuth2Options,
|
|
|
|
): Promise<any> {
|
|
|
|
return requestOAuth2.call(
|
|
|
|
this,
|
|
|
|
credentialsType,
|
|
|
|
requestOptions,
|
|
|
|
node,
|
|
|
|
additionalData,
|
|
|
|
oAuth2Options,
|
|
|
|
);
|
2020-06-01 17:42:38 -07:00
|
|
|
},
|
2021-08-29 11:58:11 -07:00
|
|
|
async requestOAuth1(
|
|
|
|
this: IAllExecuteFunctions,
|
|
|
|
credentialsType: string,
|
|
|
|
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
|
|
|
|
): Promise<any> {
|
2020-06-01 17:42:38 -07:00
|
|
|
return requestOAuth1.call(this, credentialsType, requestOptions);
|
2020-01-13 18:46:58 -08:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
return that;
|
|
|
|
})(workflow, node);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the execute functions regular nodes have access to when webhook-function is defined.
|
|
|
|
*
|
|
|
|
* @export
|
|
|
|
* @param {Workflow} workflow
|
|
|
|
* @param {IRunExecutionData} runExecutionData
|
|
|
|
* @param {INode} node
|
|
|
|
* @param {IWorkflowExecuteAdditionalData} additionalData
|
|
|
|
* @param {WorkflowExecuteMode} mode
|
|
|
|
* @returns {IWebhookFunctions}
|
|
|
|
*/
|
2021-08-29 11:58:11 -07:00
|
|
|
export function getExecuteWebhookFunctions(
|
|
|
|
workflow: Workflow,
|
|
|
|
node: INode,
|
|
|
|
additionalData: IWorkflowExecuteAdditionalData,
|
|
|
|
mode: WorkflowExecuteMode,
|
|
|
|
webhookData: IWebhookData,
|
|
|
|
): IWebhookFunctions {
|
2019-06-23 03:35:23 -07:00
|
|
|
return ((workflow: Workflow, node: INode) => {
|
|
|
|
return {
|
|
|
|
getBodyData(): IDataObject {
|
|
|
|
if (additionalData.httpRequest === undefined) {
|
|
|
|
throw new Error('Request is missing!');
|
|
|
|
}
|
|
|
|
return additionalData.httpRequest.body;
|
|
|
|
},
|
2021-08-20 09:57:30 -07:00
|
|
|
async getCredentials(type: string): Promise<ICredentialDataDecryptedObject | undefined> {
|
2021-08-29 11:58:11 -07:00
|
|
|
return getCredentials(workflow, node, type, additionalData, mode);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
getHeaderData(): object {
|
|
|
|
if (additionalData.httpRequest === undefined) {
|
|
|
|
throw new Error('Request is missing!');
|
|
|
|
}
|
|
|
|
return additionalData.httpRequest.headers;
|
|
|
|
},
|
|
|
|
getMode: (): WorkflowExecuteMode => {
|
|
|
|
return mode;
|
|
|
|
},
|
2020-02-15 17:07:01 -08:00
|
|
|
getNode: () => {
|
|
|
|
return getNode(node);
|
|
|
|
},
|
2021-08-29 11:58:11 -07:00
|
|
|
getNodeParameter: (
|
|
|
|
parameterName: string,
|
|
|
|
fallbackValue?: any,
|
|
|
|
):
|
|
|
|
| NodeParameterValue
|
|
|
|
| INodeParameters
|
|
|
|
| NodeParameterValue[]
|
|
|
|
| INodeParameters[]
|
|
|
|
| object => {
|
2019-06-23 03:35:23 -07:00
|
|
|
const runExecutionData: IRunExecutionData | null = null;
|
|
|
|
const itemIndex = 0;
|
|
|
|
const runIndex = 0;
|
|
|
|
const connectionInputData: INodeExecutionData[] = [];
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
return getNodeParameter(
|
|
|
|
workflow,
|
|
|
|
runExecutionData,
|
|
|
|
runIndex,
|
|
|
|
connectionInputData,
|
|
|
|
node,
|
|
|
|
parameterName,
|
|
|
|
itemIndex,
|
|
|
|
mode,
|
|
|
|
getAdditionalKeys(additionalData),
|
|
|
|
fallbackValue,
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2021-01-23 11:00:32 -08:00
|
|
|
getParamsData(): object {
|
|
|
|
if (additionalData.httpRequest === undefined) {
|
|
|
|
throw new Error('Request is missing!');
|
|
|
|
}
|
|
|
|
return additionalData.httpRequest.params;
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
getQueryData(): object {
|
|
|
|
if (additionalData.httpRequest === undefined) {
|
|
|
|
throw new Error('Request is missing!');
|
|
|
|
}
|
|
|
|
return additionalData.httpRequest.query;
|
|
|
|
},
|
|
|
|
getRequestObject(): express.Request {
|
|
|
|
if (additionalData.httpRequest === undefined) {
|
|
|
|
throw new Error('Request is missing!');
|
|
|
|
}
|
|
|
|
return additionalData.httpRequest;
|
|
|
|
},
|
|
|
|
getResponseObject(): express.Response {
|
|
|
|
if (additionalData.httpResponse === undefined) {
|
|
|
|
throw new Error('Response is missing!');
|
|
|
|
}
|
|
|
|
return additionalData.httpResponse;
|
|
|
|
},
|
2019-07-12 02:33:18 -07:00
|
|
|
getNodeWebhookUrl: (name: string): string | undefined => {
|
2021-08-29 11:58:11 -07:00
|
|
|
return getNodeWebhookUrl(
|
|
|
|
name,
|
|
|
|
workflow,
|
|
|
|
node,
|
|
|
|
additionalData,
|
|
|
|
mode,
|
|
|
|
getAdditionalKeys(additionalData),
|
|
|
|
);
|
2019-07-12 02:33:18 -07:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
getTimezone: (): string => {
|
|
|
|
return getTimezone(workflow, additionalData);
|
|
|
|
},
|
2020-02-15 17:07:01 -08:00
|
|
|
getWorkflow: () => {
|
|
|
|
return getWorkflowMetadata(workflow);
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
getWorkflowStaticData(type: string): IDataObject {
|
|
|
|
return workflow.getStaticData(type, node);
|
|
|
|
},
|
2019-07-12 02:33:18 -07:00
|
|
|
getWebhookName(): string {
|
|
|
|
return webhookData.webhookDescription.name;
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
prepareOutputData: NodeHelpers.prepareOutputData,
|
|
|
|
helpers: {
|
2021-09-21 10:38:24 -07:00
|
|
|
httpRequest,
|
2021-12-23 13:29:04 -08:00
|
|
|
async prepareBinaryData(
|
|
|
|
binaryData: Buffer,
|
|
|
|
filePath?: string,
|
|
|
|
mimeType?: string,
|
|
|
|
): Promise<IBinaryData> {
|
|
|
|
return prepareBinaryData.call(
|
|
|
|
this,
|
|
|
|
binaryData,
|
|
|
|
additionalData.executionId!,
|
|
|
|
filePath,
|
|
|
|
mimeType,
|
|
|
|
);
|
|
|
|
},
|
2021-09-21 10:38:24 -07:00
|
|
|
request: proxyRequestToAxios,
|
2021-08-29 11:58:11 -07:00
|
|
|
async requestOAuth2(
|
|
|
|
this: IAllExecuteFunctions,
|
|
|
|
credentialsType: string,
|
|
|
|
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
|
|
|
oAuth2Options?: IOAuth2Options,
|
|
|
|
): Promise<any> {
|
|
|
|
return requestOAuth2.call(
|
|
|
|
this,
|
|
|
|
credentialsType,
|
|
|
|
requestOptions,
|
|
|
|
node,
|
|
|
|
additionalData,
|
|
|
|
oAuth2Options,
|
|
|
|
);
|
2020-06-01 17:42:38 -07:00
|
|
|
},
|
2021-08-29 11:58:11 -07:00
|
|
|
async requestOAuth1(
|
|
|
|
this: IAllExecuteFunctions,
|
|
|
|
credentialsType: string,
|
|
|
|
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
|
|
|
|
): Promise<any> {
|
2020-06-01 17:42:38 -07:00
|
|
|
return requestOAuth1.call(this, credentialsType, requestOptions);
|
2020-01-13 18:46:58 -08:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
returnJsonArray,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
})(workflow, node);
|
|
|
|
}
|