mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
refactor: Removal of request lib from the code (#6413)
* refactor: Removal of request lib from the code
This commit is contained in:
committed by
कारतोफ्फेलस्क्रिप्ट™
parent
1197811a1e
commit
632ea275b7
@@ -10,7 +10,6 @@ import type { AuthenticatedRequest } from '@/requests';
|
|||||||
import config from '@/config';
|
import config from '@/config';
|
||||||
import { AUTH_COOKIE_NAME, EDITOR_UI_DIST_DIR } from '@/constants';
|
import { AUTH_COOKIE_NAME, EDITOR_UI_DIST_DIR } from '@/constants';
|
||||||
import { issueCookie, resolveJwtContent } from '@/auth/jwt';
|
import { issueCookie, resolveJwtContent } from '@/auth/jwt';
|
||||||
import type { UserRepository } from '@db/repositories';
|
|
||||||
import { canSkipAuth } from '@/decorators/registerController';
|
import { canSkipAuth } from '@/decorators/registerController';
|
||||||
|
|
||||||
const jwtFromRequest = (req: Request) => {
|
const jwtFromRequest = (req: Request) => {
|
||||||
|
|||||||
@@ -60,8 +60,6 @@
|
|||||||
"p-cancelable": "^2.0.0",
|
"p-cancelable": "^2.0.0",
|
||||||
"pretty-bytes": "^5.6.0",
|
"pretty-bytes": "^5.6.0",
|
||||||
"qs": "^6.10.1",
|
"qs": "^6.10.1",
|
||||||
"request": "^2.88.2",
|
|
||||||
"request-promise-native": "^1.0.7",
|
|
||||||
"uuid": "^8.3.2"
|
"uuid": "^8.3.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,9 +97,8 @@ import get from 'lodash/get';
|
|||||||
import type { Request, Response } from 'express';
|
import type { Request, Response } from 'express';
|
||||||
import FormData from 'form-data';
|
import FormData from 'form-data';
|
||||||
import path from 'path';
|
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 type { RequestPromiseOptions } from 'request-promise-native';
|
||||||
import requestPromise from 'request-promise-native';
|
|
||||||
import FileType from 'file-type';
|
import FileType from 'file-type';
|
||||||
import { lookup, extension } from 'mime-types';
|
import { lookup, extension } from 'mime-types';
|
||||||
import type { IncomingHttpHeaders } from 'http';
|
import type { IncomingHttpHeaders } from 'http';
|
||||||
@@ -142,10 +141,6 @@ axios.defaults.paramsSerializer = (params) => {
|
|||||||
return stringify(params, { arrayFormat: 'indices' });
|
return stringify(params, { arrayFormat: 'indices' });
|
||||||
};
|
};
|
||||||
|
|
||||||
const requestPromiseWithDefaults = requestPromise.defaults({
|
|
||||||
timeout: 300000, // 5 minutes
|
|
||||||
});
|
|
||||||
|
|
||||||
const pushFormDataValue = (form: FormData, key: string, value: any) => {
|
const pushFormDataValue = (form: FormData, key: string, value: any) => {
|
||||||
if (value?.hasOwnProperty('value') && value.hasOwnProperty('options')) {
|
if (value?.hasOwnProperty('value') && value.hasOwnProperty('options')) {
|
||||||
form.append(key, value.value, value.options);
|
form.append(key, value.value, value.options);
|
||||||
@@ -596,21 +591,12 @@ type ConfigObject = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function proxyRequestToAxios(
|
export async function proxyRequestToAxios(
|
||||||
workflow: Workflow,
|
workflow: Workflow | undefined,
|
||||||
additionalData: IWorkflowExecuteAdditionalData,
|
additionalData: IWorkflowExecuteAdditionalData | undefined,
|
||||||
node: INode,
|
node: INode | undefined,
|
||||||
uriOrObject: string | IDataObject,
|
uriOrObject: string | object,
|
||||||
options?: IDataObject,
|
options?: object,
|
||||||
): Promise<any> {
|
): 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 = {
|
let axiosConfig: AxiosRequestConfig = {
|
||||||
maxBodyLength: Infinity,
|
maxBodyLength: Infinity,
|
||||||
maxContentLength: Infinity,
|
maxContentLength: Infinity,
|
||||||
@@ -667,7 +653,7 @@ export async function proxyRequestToAxios(
|
|||||||
body = undefined;
|
body = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await additionalData.hooks?.executeHookFunctions('nodeFetchedData', [workflow.id, node]);
|
await additionalData?.hooks?.executeHookFunctions('nodeFetchedData', [workflow?.id, node]);
|
||||||
return {
|
return {
|
||||||
body,
|
body,
|
||||||
headers: response.headers,
|
headers: response.headers,
|
||||||
@@ -684,7 +670,7 @@ export async function proxyRequestToAxios(
|
|||||||
body = undefined;
|
body = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await additionalData.hooks?.executeHookFunctions('nodeFetchedData', [workflow.id, node]);
|
await additionalData?.hooks?.executeHookFunctions('nodeFetchedData', [workflow?.id, node]);
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -1074,13 +1060,13 @@ async function prepareBinaryData(
|
|||||||
/**
|
/**
|
||||||
* Makes a request using OAuth data for authentication
|
* Makes a request using OAuth data for authentication
|
||||||
*
|
*
|
||||||
* @param {(OptionsWithUri | requestPromise.RequestPromiseOptions)} requestOptions
|
* @param {(OptionsWithUri | RequestPromiseOptions)} requestOptions
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export async function requestOAuth2(
|
export async function requestOAuth2(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions | IHttpRequestOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions | IHttpRequestOptions,
|
||||||
node: INode,
|
node: INode,
|
||||||
additionalData: IWorkflowExecuteAdditionalData,
|
additionalData: IWorkflowExecuteAdditionalData,
|
||||||
oAuth2Options?: IOAuth2Options,
|
oAuth2Options?: IOAuth2Options,
|
||||||
@@ -1311,11 +1297,7 @@ export async function requestOAuth2(
|
|||||||
export async function requestOAuth1(
|
export async function requestOAuth1(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions:
|
requestOptions: OptionsWithUrl | OptionsWithUri | RequestPromiseOptions | IHttpRequestOptions,
|
||||||
| OptionsWithUrl
|
|
||||||
| OptionsWithUri
|
|
||||||
| requestPromise.RequestPromiseOptions
|
|
||||||
| IHttpRequestOptions,
|
|
||||||
isN8nRequest = false,
|
isN8nRequest = false,
|
||||||
) {
|
) {
|
||||||
const credentials = await this.getCredentials(credentialsType);
|
const credentials = await this.getCredentials(credentialsType);
|
||||||
@@ -1569,7 +1551,7 @@ export function normalizeItems(
|
|||||||
export async function requestWithAuthentication(
|
export async function requestWithAuthentication(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||||
workflow: Workflow,
|
workflow: Workflow,
|
||||||
node: INode,
|
node: INode,
|
||||||
additionalData: IWorkflowExecuteAdditionalData,
|
additionalData: IWorkflowExecuteAdditionalData,
|
||||||
@@ -2228,7 +2210,7 @@ const getRequestHelperFunctions = (
|
|||||||
async requestOAuth1(
|
async requestOAuth1(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUrl | RequestPromiseOptions,
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return requestOAuth1.call(this, credentialsType, requestOptions);
|
return requestOAuth1.call(this, credentialsType, requestOptions);
|
||||||
},
|
},
|
||||||
@@ -2236,7 +2218,7 @@ const getRequestHelperFunctions = (
|
|||||||
async requestOAuth2(
|
async requestOAuth2(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||||
oAuth2Options?: IOAuth2Options,
|
oAuth2Options?: IOAuth2Options,
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return requestOAuth2.call(
|
return requestOAuth2.call(
|
||||||
@@ -2732,7 +2714,9 @@ export function getExecuteSingleFunctions(
|
|||||||
export function getCredentialTestFunctions(): ICredentialTestFunctions {
|
export function getCredentialTestFunctions(): ICredentialTestFunctions {
|
||||||
return {
|
return {
|
||||||
helpers: {
|
helpers: {
|
||||||
request: requestPromiseWithDefaults,
|
request: async (uriOrObject: string | object, options?: object) => {
|
||||||
|
return proxyRequestToAxios(undefined, undefined, undefined, uriOrObject, options);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -828,7 +828,6 @@
|
|||||||
"promise-ftp": "^1.3.5",
|
"promise-ftp": "^1.3.5",
|
||||||
"pyodide": "^0.22.1",
|
"pyodide": "^0.22.1",
|
||||||
"redis": "^3.1.1",
|
"redis": "^3.1.1",
|
||||||
"request": "^2.88.2",
|
|
||||||
"rhea": "^1.0.11",
|
"rhea": "^1.0.11",
|
||||||
"rss-parser": "^3.7.0",
|
"rss-parser": "^3.7.0",
|
||||||
"semver": "^7.3.8",
|
"semver": "^7.3.8",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type { IncomingHttpHeaders } from 'http';
|
|||||||
import type { Readable } from 'stream';
|
import type { Readable } from 'stream';
|
||||||
import type { URLSearchParams } from 'url';
|
import type { URLSearchParams } from 'url';
|
||||||
import type { OptionsWithUri, OptionsWithUrl } from 'request';
|
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 { PathLike } from 'fs';
|
||||||
|
|
||||||
import type { CODE_EXECUTION_MODES, CODE_LANGUAGES } from './Constants';
|
import type { CODE_EXECUTION_MODES, CODE_LANGUAGES } from './Constants';
|
||||||
@@ -657,7 +657,7 @@ export type ICredentialTestFunction = (
|
|||||||
|
|
||||||
export interface ICredentialTestFunctions {
|
export interface ICredentialTestFunctions {
|
||||||
helpers: {
|
helpers: {
|
||||||
request: RequestPromiseAPI;
|
request: (uriOrObject: string | object, options?: object) => Promise<any>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
37
pnpm-lock.yaml
generated
37
pnpm-lock.yaml
generated
@@ -621,12 +621,6 @@ importers:
|
|||||||
qs:
|
qs:
|
||||||
specifier: ^6.10.1
|
specifier: ^6.10.1
|
||||||
version: 6.11.0
|
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:
|
uuid:
|
||||||
specifier: ^8.3.2
|
specifier: ^8.3.2
|
||||||
version: 8.3.2
|
version: 8.3.2
|
||||||
@@ -1159,9 +1153,6 @@ importers:
|
|||||||
redis:
|
redis:
|
||||||
specifier: ^3.1.1
|
specifier: ^3.1.1
|
||||||
version: 3.1.2
|
version: 3.1.2
|
||||||
request:
|
|
||||||
specifier: ^2.88.2
|
|
||||||
version: 2.88.2
|
|
||||||
rhea:
|
rhea:
|
||||||
specifier: ^1.0.11
|
specifier: ^1.0.11
|
||||||
version: 1.0.24
|
version: 1.0.24
|
||||||
@@ -19222,29 +19213,6 @@ packages:
|
|||||||
throttleit: 1.0.0
|
throttleit: 1.0.0
|
||||||
dev: true
|
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:
|
/request@2.88.2:
|
||||||
resolution: {integrity: sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==}
|
resolution: {integrity: sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==}
|
||||||
engines: {node: '>= 6'}
|
engines: {node: '>= 6'}
|
||||||
@@ -20289,11 +20257,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-uUZI65yrV2Qva5gqE0+A7uVAvO40iPo6jGhs7s8keRfHCmtg+uB2X6EiLGCI9IgL1J17xGhvoOqSz79lzICPTA==}
|
resolution: {integrity: sha512-uUZI65yrV2Qva5gqE0+A7uVAvO40iPo6jGhs7s8keRfHCmtg+uB2X6EiLGCI9IgL1J17xGhvoOqSz79lzICPTA==}
|
||||||
dev: true
|
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:
|
/stop-iteration-iterator@1.0.0:
|
||||||
resolution: {integrity: sha512-iCGQj+0l0HOdZ2AEeBADlsRC+vsnDsZsbdSiH1yNSjcfKM7fdpCMfqAL/dwF5BLiw/XhRft/Wax6zQbhq2BcjQ==}
|
resolution: {integrity: sha512-iCGQj+0l0HOdZ2AEeBADlsRC+vsnDsZsbdSiH1yNSjcfKM7fdpCMfqAL/dwF5BLiw/XhRft/Wax6zQbhq2BcjQ==}
|
||||||
engines: {node: '>= 0.4'}
|
engines: {node: '>= 0.4'}
|
||||||
|
|||||||
Reference in New Issue
Block a user