1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-10-08 19:00:28 +03:00

refactor: Removal of request lib from the code (#6413)

* refactor: Removal of request lib from the code
This commit is contained in:
Omar Ajoue 2023-06-14 16:40:16 +02:00 committed by कारतोफ्फेलस्क्रिप्ट™
parent 1197811a1e
commit 632ea275b7
6 changed files with 19 additions and 76 deletions

View File

@ -10,7 +10,6 @@ import type { AuthenticatedRequest } from '@/requests';
import config from '@/config';
import { AUTH_COOKIE_NAME, EDITOR_UI_DIST_DIR } from '@/constants';
import { issueCookie, resolveJwtContent } from '@/auth/jwt';
import type { UserRepository } from '@db/repositories';
import { canSkipAuth } from '@/decorators/registerController';
const jwtFromRequest = (req: Request) => {

View File

@ -60,8 +60,6 @@
"p-cancelable": "^2.0.0",
"pretty-bytes": "^5.6.0",
"qs": "^6.10.1",
"request": "^2.88.2",
"request-promise-native": "^1.0.7",
"uuid": "^8.3.2"
}
}

View File

@ -97,9 +97,8 @@ import get from 'lodash/get';
import type { Request, Response } from 'express';
import FormData from 'form-data';
import path from 'path';
import type { OptionsWithUri, OptionsWithUrl, RequestCallback, RequiredUriUrl } from 'request';
import type { OptionsWithUri, OptionsWithUrl } from 'request';
import type { RequestPromiseOptions } from 'request-promise-native';
import requestPromise from 'request-promise-native';
import FileType from 'file-type';
import { lookup, extension } from 'mime-types';
import type { IncomingHttpHeaders } from 'http';
@ -142,10 +141,6 @@ axios.defaults.paramsSerializer = (params) => {
return stringify(params, { arrayFormat: 'indices' });
};
const requestPromiseWithDefaults = requestPromise.defaults({
timeout: 300000, // 5 minutes
});
const pushFormDataValue = (form: FormData, key: string, value: any) => {
if (value?.hasOwnProperty('value') && value.hasOwnProperty('options')) {
form.append(key, value.value, value.options);
@ -596,21 +591,12 @@ type ConfigObject = {
};
export async function proxyRequestToAxios(
workflow: Workflow,
additionalData: IWorkflowExecuteAdditionalData,
node: INode,
uriOrObject: string | IDataObject,
options?: IDataObject,
workflow: Workflow | undefined,
additionalData: IWorkflowExecuteAdditionalData | undefined,
node: INode | undefined,
uriOrObject: string | object,
options?: object,
): Promise<any> {
// Check if there's a better way of getting this config here
if (process.env.N8N_USE_DEPRECATED_REQUEST_LIB) {
return requestPromiseWithDefaults.call(
null,
uriOrObject as unknown as RequiredUriUrl & RequestPromiseOptions,
options as unknown as RequestCallback,
);
}
let axiosConfig: AxiosRequestConfig = {
maxBodyLength: Infinity,
maxContentLength: Infinity,
@ -667,7 +653,7 @@ export async function proxyRequestToAxios(
body = undefined;
}
}
await additionalData.hooks?.executeHookFunctions('nodeFetchedData', [workflow.id, node]);
await additionalData?.hooks?.executeHookFunctions('nodeFetchedData', [workflow?.id, node]);
return {
body,
headers: response.headers,
@ -684,7 +670,7 @@ export async function proxyRequestToAxios(
body = undefined;
}
}
await additionalData.hooks?.executeHookFunctions('nodeFetchedData', [workflow.id, node]);
await additionalData?.hooks?.executeHookFunctions('nodeFetchedData', [workflow?.id, node]);
return body;
}
} catch (error) {
@ -1074,13 +1060,13 @@ async function prepareBinaryData(
/**
* Makes a request using OAuth data for authentication
*
* @param {(OptionsWithUri | requestPromise.RequestPromiseOptions)} requestOptions
* @param {(OptionsWithUri | RequestPromiseOptions)} requestOptions
*
*/
export async function requestOAuth2(
this: IAllExecuteFunctions,
credentialsType: string,
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions | IHttpRequestOptions,
requestOptions: OptionsWithUri | RequestPromiseOptions | IHttpRequestOptions,
node: INode,
additionalData: IWorkflowExecuteAdditionalData,
oAuth2Options?: IOAuth2Options,
@ -1311,11 +1297,7 @@ export async function requestOAuth2(
export async function requestOAuth1(
this: IAllExecuteFunctions,
credentialsType: string,
requestOptions:
| OptionsWithUrl
| OptionsWithUri
| requestPromise.RequestPromiseOptions
| IHttpRequestOptions,
requestOptions: OptionsWithUrl | OptionsWithUri | RequestPromiseOptions | IHttpRequestOptions,
isN8nRequest = false,
) {
const credentials = await this.getCredentials(credentialsType);
@ -1569,7 +1551,7 @@ export function normalizeItems(
export async function requestWithAuthentication(
this: IAllExecuteFunctions,
credentialsType: string,
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
requestOptions: OptionsWithUri | RequestPromiseOptions,
workflow: Workflow,
node: INode,
additionalData: IWorkflowExecuteAdditionalData,
@ -2228,7 +2210,7 @@ const getRequestHelperFunctions = (
async requestOAuth1(
this: IAllExecuteFunctions,
credentialsType: string,
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
requestOptions: OptionsWithUrl | RequestPromiseOptions,
): Promise<any> {
return requestOAuth1.call(this, credentialsType, requestOptions);
},
@ -2236,7 +2218,7 @@ const getRequestHelperFunctions = (
async requestOAuth2(
this: IAllExecuteFunctions,
credentialsType: string,
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
requestOptions: OptionsWithUri | RequestPromiseOptions,
oAuth2Options?: IOAuth2Options,
): Promise<any> {
return requestOAuth2.call(
@ -2732,7 +2714,9 @@ export function getExecuteSingleFunctions(
export function getCredentialTestFunctions(): ICredentialTestFunctions {
return {
helpers: {
request: requestPromiseWithDefaults,
request: async (uriOrObject: string | object, options?: object) => {
return proxyRequestToAxios(undefined, undefined, undefined, uriOrObject, options);
},
},
};
}

View File

@ -828,7 +828,6 @@
"promise-ftp": "^1.3.5",
"pyodide": "^0.22.1",
"redis": "^3.1.1",
"request": "^2.88.2",
"rhea": "^1.0.11",
"rss-parser": "^3.7.0",
"semver": "^7.3.8",

View File

@ -6,7 +6,7 @@ import type { IncomingHttpHeaders } from 'http';
import type { Readable } from 'stream';
import type { URLSearchParams } from 'url';
import type { OptionsWithUri, OptionsWithUrl } from 'request';
import type { RequestPromiseOptions, RequestPromiseAPI } from 'request-promise-native';
import type { RequestPromiseOptions } from 'request-promise-native';
import type { PathLike } from 'fs';
import type { CODE_EXECUTION_MODES, CODE_LANGUAGES } from './Constants';
@ -657,7 +657,7 @@ export type ICredentialTestFunction = (
export interface ICredentialTestFunctions {
helpers: {
request: RequestPromiseAPI;
request: (uriOrObject: string | object, options?: object) => Promise<any>;
};
}

View File

@ -621,12 +621,6 @@ importers:
qs:
specifier: ^6.10.1
version: 6.11.0
request:
specifier: ^2.88.2
version: 2.88.2
request-promise-native:
specifier: ^1.0.7
version: 1.0.9(request@2.88.2)
uuid:
specifier: ^8.3.2
version: 8.3.2
@ -1159,9 +1153,6 @@ importers:
redis:
specifier: ^3.1.1
version: 3.1.2
request:
specifier: ^2.88.2
version: 2.88.2
rhea:
specifier: ^1.0.11
version: 1.0.24
@ -19222,29 +19213,6 @@ packages:
throttleit: 1.0.0
dev: true
/request-promise-core@1.1.4(request@2.88.2):
resolution: {integrity: sha512-TTbAfBBRdWD7aNNOoVOBH4pN/KigV6LyapYNNlAPA8JwbovRti1E88m3sYAwsLi5ryhPKsE9APwnjFTgdUjTpw==}
engines: {node: '>=0.10.0'}
peerDependencies:
request: ^2.34
dependencies:
lodash: 4.17.21
request: 2.88.2
dev: false
/request-promise-native@1.0.9(request@2.88.2):
resolution: {integrity: sha512-wcW+sIUiWnKgNY0dqCpOZkUbF/I+YPi+f09JZIDa39Ec+q82CpSYniDp+ISgTTbKmnpJWASeJBPZmoxH84wt3g==}
engines: {node: '>=0.12.0'}
deprecated: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
peerDependencies:
request: ^2.34
dependencies:
request: 2.88.2
request-promise-core: 1.1.4(request@2.88.2)
stealthy-require: 1.1.1
tough-cookie: 2.5.0
dev: false
/request@2.88.2:
resolution: {integrity: sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==}
engines: {node: '>= 6'}
@ -20289,11 +20257,6 @@ packages:
resolution: {integrity: sha512-uUZI65yrV2Qva5gqE0+A7uVAvO40iPo6jGhs7s8keRfHCmtg+uB2X6EiLGCI9IgL1J17xGhvoOqSz79lzICPTA==}
dev: true
/stealthy-require@1.1.1:
resolution: {integrity: sha512-ZnWpYnYugiOVEY5GkcuJK1io5V8QmNYChG62gSit9pQVGErXtrKuPC55ITaVSukmMta5qpMU7vqLt2Lnni4f/g==}
engines: {node: '>=0.10.0'}
dev: false
/stop-iteration-iterator@1.0.0:
resolution: {integrity: sha512-iCGQj+0l0HOdZ2AEeBADlsRC+vsnDsZsbdSiH1yNSjcfKM7fdpCMfqAL/dwF5BLiw/XhRft/Wax6zQbhq2BcjQ==}
engines: {node: '>= 0.4'}