mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
refactor(core): clear @ts-ignore from workflow and core packages (#4467)
* 📘 Clear all `@ts-ignore` comments from workflow package * 👕 Default to error with package-level overrides * refactor(core): clear all `@ts-ignore` comments from core package (#4473) 👕 Clear all `@ts-ignore` comments from core package * ✏️ Update comment
This commit is contained in:
@@ -77,8 +77,8 @@ import { get } from 'lodash';
|
||||
import type { Request, Response } from 'express';
|
||||
import FormData from 'form-data';
|
||||
import path from 'path';
|
||||
import { OptionsWithUri, OptionsWithUrl } from 'request';
|
||||
import requestPromise from 'request-promise-native';
|
||||
import { OptionsWithUri, OptionsWithUrl, RequestCallback, RequiredUriUrl } from 'request';
|
||||
import requestPromise, { RequestPromiseOptions } from 'request-promise-native';
|
||||
import { fromBuffer } from 'file-type';
|
||||
import { lookup } from 'mime-types';
|
||||
|
||||
@@ -123,18 +123,16 @@ const requestPromiseWithDefaults = requestPromise.defaults({
|
||||
|
||||
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 createFormDataObject = (data: Record<string, unknown>) => {
|
||||
const formData = new FormData();
|
||||
const keys = Object.keys(data);
|
||||
keys.forEach((key) => {
|
||||
// @ts-ignore
|
||||
const formField = data[key];
|
||||
|
||||
if (formField instanceof Array) {
|
||||
@@ -231,7 +229,7 @@ async function parseRequestObject(requestObject: IDataObject) {
|
||||
if (requestObject.formData !== undefined && requestObject.formData instanceof FormData) {
|
||||
axiosConfig.data = requestObject.formData;
|
||||
} else {
|
||||
const allData = {
|
||||
const allData: Partial<FormData> = {
|
||||
...(requestObject.body as object | undefined),
|
||||
...(requestObject.formData as object | undefined),
|
||||
};
|
||||
@@ -240,7 +238,6 @@ async function parseRequestObject(requestObject: IDataObject) {
|
||||
}
|
||||
// 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);
|
||||
@@ -276,7 +273,7 @@ async function parseRequestObject(requestObject: IDataObject) {
|
||||
if (requestObject.formData instanceof FormData) {
|
||||
axiosConfig.data = requestObject.formData;
|
||||
} else {
|
||||
axiosConfig.data = createFormDataObject(requestObject.formData as object);
|
||||
axiosConfig.data = createFormDataObject(requestObject.formData as Record<string, unknown>);
|
||||
}
|
||||
// Mix in headers as FormData creates the boundary.
|
||||
const headers = axiosConfig.data.getHeaders();
|
||||
@@ -284,9 +281,8 @@ async function parseRequestObject(requestObject: IDataObject) {
|
||||
await generateContentLengthHeader(axiosConfig.data, axiosConfig.headers);
|
||||
} else if (requestObject.body !== undefined) {
|
||||
// If we have body and possibly form
|
||||
if (requestObject.form !== undefined) {
|
||||
if (requestObject.form !== undefined && requestObject.body) {
|
||||
// merge both objects when exist.
|
||||
// @ts-ignore
|
||||
requestObject.body = Object.assign(requestObject.body, requestObject.form);
|
||||
}
|
||||
axiosConfig.data = requestObject.body as FormData | GenericValue | GenericValue[];
|
||||
@@ -313,10 +309,25 @@ async function parseRequestObject(requestObject: IDataObject) {
|
||||
axiosConfig.params = requestObject.qs as IDataObject;
|
||||
}
|
||||
|
||||
function hasArrayFormatOptions(
|
||||
arg: IDataObject,
|
||||
): arg is IDataObject & { qsStringifyOptions: { arrayFormat: 'repeat' | 'brackets' } } {
|
||||
if (
|
||||
typeof arg.qsStringifyOptions === 'object' &&
|
||||
arg.qsStringifyOptions !== null &&
|
||||
!Array.isArray(arg.qsStringifyOptions) &&
|
||||
'arrayFormat' in arg.qsStringifyOptions
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
requestObject.useQuerystring === true ||
|
||||
// @ts-ignore
|
||||
requestObject.qsStringifyOptions?.arrayFormat === 'repeat'
|
||||
(hasArrayFormatOptions(requestObject) &&
|
||||
requestObject.qsStringifyOptions.arrayFormat === 'repeat')
|
||||
) {
|
||||
axiosConfig.paramsSerializer = (params) => {
|
||||
return stringify(params, { arrayFormat: 'repeat' });
|
||||
@@ -327,8 +338,10 @@ async function parseRequestObject(requestObject: IDataObject) {
|
||||
};
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
if (requestObject.qsStringifyOptions?.arrayFormat === 'brackets') {
|
||||
if (
|
||||
hasArrayFormatOptions(requestObject) &&
|
||||
requestObject.qsStringifyOptions.arrayFormat === 'brackets'
|
||||
) {
|
||||
axiosConfig.paramsSerializer = (params) => {
|
||||
return stringify(params, { arrayFormat: 'brackets' });
|
||||
};
|
||||
@@ -552,8 +565,11 @@ async function proxyRequestToAxios(
|
||||
): Promise<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);
|
||||
return requestPromiseWithDefaults.call(
|
||||
null,
|
||||
uriOrObject as unknown as RequiredUriUrl & RequestPromiseOptions,
|
||||
options as unknown as RequestCallback,
|
||||
);
|
||||
}
|
||||
|
||||
let axiosConfig: AxiosRequestConfig = {
|
||||
@@ -970,10 +986,8 @@ export async function requestOAuth2(
|
||||
const newRequestOptions = token.sign(requestOptions as clientOAuth2.RequestObject);
|
||||
const newRequestHeaders = (newRequestOptions.headers = newRequestOptions.headers ?? {});
|
||||
// If keep bearer is false remove the it from the authorization header
|
||||
if (oAuth2Options?.keepBearer === false) {
|
||||
newRequestHeaders.Authorization =
|
||||
// @ts-ignore
|
||||
newRequestHeaders.Authorization.split(' ')[1];
|
||||
if (oAuth2Options?.keepBearer === false && typeof newRequestHeaders.Authorization === 'string') {
|
||||
newRequestHeaders.Authorization = newRequestHeaders.Authorization.split(' ')[1];
|
||||
}
|
||||
|
||||
if (oAuth2Options?.keyToIncludeInAccessTokenHeader) {
|
||||
@@ -1110,10 +1124,8 @@ export async function requestOAuth2(
|
||||
const newRequestOptions = newToken.sign(requestOptions as clientOAuth2.RequestObject);
|
||||
newRequestOptions.headers = newRequestOptions.headers ?? {};
|
||||
|
||||
// @ts-ignore
|
||||
if (oAuth2Options?.keyToIncludeInAccessTokenHeader) {
|
||||
Object.assign(newRequestOptions.headers, {
|
||||
// @ts-ignore
|
||||
[oAuth2Options.keyToIncludeInAccessTokenHeader]: token.accessToken,
|
||||
});
|
||||
}
|
||||
@@ -1126,9 +1138,8 @@ export async function requestOAuth2(
|
||||
});
|
||||
}
|
||||
|
||||
/* Makes a request using OAuth1 data for authentication
|
||||
*
|
||||
* @param {(OptionsWithUrl | requestPromise.RequestPromiseOptions)} requestOptions
|
||||
/**
|
||||
* Makes a request using OAuth1 data for authentication
|
||||
*/
|
||||
export async function requestOAuth1(
|
||||
this: IAllExecuteFunctions,
|
||||
@@ -1169,20 +1180,21 @@ export async function requestOAuth1(
|
||||
secret: oauthTokenData.oauth_token_secret as string,
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
// @ts-expect-error @TECH_DEBT: Remove request library
|
||||
requestOptions.data = { ...requestOptions.qs, ...requestOptions.form };
|
||||
|
||||
// Fixes issue that OAuth1 library only works with "url" property and not with "uri"
|
||||
// @ts-ignore
|
||||
// @ts-expect-error @TECH_DEBT: Remove request library
|
||||
if (requestOptions.uri && !requestOptions.url) {
|
||||
// @ts-ignore
|
||||
// @ts-expect-error @TECH_DEBT: Remove request library
|
||||
requestOptions.url = requestOptions.uri;
|
||||
// @ts-ignore
|
||||
// @ts-expect-error @TECH_DEBT: Remove request library
|
||||
delete requestOptions.uri;
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
requestOptions.headers = oauth.toHeader(oauth.authorize(requestOptions, token));
|
||||
requestOptions.headers = oauth.toHeader(
|
||||
oauth.authorize(requestOptions as unknown as clientOAuth1.RequestOptions, token),
|
||||
);
|
||||
if (isN8nRequest) {
|
||||
return this.helpers.httpRequest(requestOptions as IHttpRequestOptions);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user