mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
refactor(core): Remove linting exceptions in nodes-base (#4794)
* ⚡ enabled array-type * ⚡ await-thenable on * ⚡ ban-types on * ⚡ default-param-last on * ⚡ dot-notation on * ⚡ member-delimiter-style on * ⚡ no-duplicate-imports on * ⚡ no-empty-interface on * ⚡ no-floating-promises on * ⚡ no-for-in-array on * ⚡ no-invalid-void-type on * ⚡ no-loop-func on * ⚡ no-shadow on * ⚡ ban-ts-comment re enabled * ⚡ @typescript-eslint/lines-between-class-members on * address my own comment * @typescript-eslint/return-await on * @typescript-eslint/promise-function-async on * @typescript-eslint/no-unnecessary-boolean-literal-compare on * @typescript-eslint/no-unnecessary-type-assertion on * prefer-const on * @typescript-eslint/prefer-optional-chain on Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
@@ -83,7 +83,7 @@ export async function googleApiRequest(
|
||||
|
||||
const { access_token } = await getAccessToken.call(this, credentials);
|
||||
|
||||
(options.headers as IDataObject)['Authorization'] = `Bearer ${access_token}`;
|
||||
(options.headers as IDataObject).Authorization = `Bearer ${access_token}`;
|
||||
}
|
||||
|
||||
const response = await this.helpers.requestWithAuthentication.call(
|
||||
@@ -100,13 +100,13 @@ export async function googleApiRequest(
|
||||
if (error.httpCode === '400') {
|
||||
if (error.cause && ((error.cause.message as string) || '').includes('Invalid id value')) {
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const options = {
|
||||
const errorOptions = {
|
||||
message: `Invalid ${resource} ID`,
|
||||
description: `${
|
||||
resource.charAt(0).toUpperCase() + resource.slice(1)
|
||||
} IDs should look something like this: 182b676d244938bd`,
|
||||
};
|
||||
throw new NodeApiError(this.getNode(), error, options);
|
||||
throw new NodeApiError(this.getNode(), error, errorOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,41 +115,41 @@ export async function googleApiRequest(
|
||||
if (resource === 'label') {
|
||||
resource = 'label ID';
|
||||
}
|
||||
const options = {
|
||||
const errorOptions = {
|
||||
message: `${resource.charAt(0).toUpperCase() + resource.slice(1)} not found`,
|
||||
description: '',
|
||||
};
|
||||
throw new NodeApiError(this.getNode(), error, options);
|
||||
throw new NodeApiError(this.getNode(), error, errorOptions);
|
||||
}
|
||||
|
||||
if (error.httpCode === '409') {
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
if (resource === 'label') {
|
||||
const options = {
|
||||
const errorOptions = {
|
||||
message: `Label name exists already`,
|
||||
description: '',
|
||||
};
|
||||
throw new NodeApiError(this.getNode(), error, options);
|
||||
throw new NodeApiError(this.getNode(), error, errorOptions);
|
||||
}
|
||||
}
|
||||
|
||||
if (error.code === 'EAUTH') {
|
||||
const options = {
|
||||
const errorOptions = {
|
||||
message: error?.body?.error_description || 'Authorization error',
|
||||
description: (error as Error).message,
|
||||
};
|
||||
throw new NodeApiError(this.getNode(), error, options);
|
||||
throw new NodeApiError(this.getNode(), error, errorOptions);
|
||||
}
|
||||
|
||||
if (
|
||||
((error.message as string) || '').includes('Bad request - please check your parameters') &&
|
||||
error.description
|
||||
) {
|
||||
const options = {
|
||||
const errorOptions = {
|
||||
message: error.description,
|
||||
description: ``,
|
||||
};
|
||||
throw new NodeApiError(this.getNode(), error, options);
|
||||
throw new NodeApiError(this.getNode(), error, errorOptions);
|
||||
}
|
||||
|
||||
throw new NodeApiError(this.getNode(), error, {
|
||||
@@ -224,8 +224,6 @@ export async function parseRawEmail(
|
||||
|
||||
export async function encodeEmail(email: IEmail) {
|
||||
// https://nodemailer.com/extras/mailcomposer/#e-mail-message-fields
|
||||
let mailBody: Buffer;
|
||||
|
||||
const mailOptions = {
|
||||
from: email.from,
|
||||
to: email.to,
|
||||
@@ -265,7 +263,7 @@ export async function encodeEmail(email: IEmail) {
|
||||
//https://nodemailer.com/extras/mailcomposer/#bcc
|
||||
mail.keepBcc = true;
|
||||
|
||||
mailBody = await mail.build();
|
||||
const mailBody = await mail.build();
|
||||
|
||||
return mailBody.toString('base64').replace(/\+/g, '-').replace(/\//g, '_');
|
||||
}
|
||||
@@ -286,9 +284,9 @@ export async function googleApiRequestAllItems(
|
||||
|
||||
do {
|
||||
responseData = await googleApiRequest.call(this, method, endpoint, body, query);
|
||||
query.pageToken = responseData['nextPageToken'];
|
||||
query.pageToken = responseData.nextPageToken;
|
||||
returnData.push.apply(returnData, responseData[propertyName]);
|
||||
} while (responseData['nextPageToken'] !== undefined && responseData['nextPageToken'] !== '');
|
||||
} while (responseData.nextPageToken !== undefined && responseData.nextPageToken !== '');
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -301,7 +299,7 @@ export function extractEmail(s: string) {
|
||||
return s;
|
||||
}
|
||||
|
||||
function getAccessToken(
|
||||
async function getAccessToken(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IPollFunctions,
|
||||
credentials: ICredentialDataDecryptedObject,
|
||||
): Promise<IDataObject> {
|
||||
@@ -323,8 +321,8 @@ function getAccessToken(
|
||||
|
||||
const signature = jwt.sign(
|
||||
{
|
||||
iss: credentials.email as string,
|
||||
sub: credentials.delegatedEmail || (credentials.email as string),
|
||||
iss: credentials.email,
|
||||
sub: credentials.delegatedEmail || credentials.email,
|
||||
scope: scopes.join(' '),
|
||||
aud: `https://oauth2.googleapis.com/token`,
|
||||
iat: now,
|
||||
@@ -354,8 +352,7 @@ function getAccessToken(
|
||||
json: true,
|
||||
};
|
||||
|
||||
//@ts-ignore
|
||||
return this.helpers.request(options);
|
||||
return this.helpers.request!(options);
|
||||
}
|
||||
|
||||
export function prepareQuery(
|
||||
@@ -503,7 +500,7 @@ export async function prepareEmailAttachments(
|
||||
itemIndex: number,
|
||||
) {
|
||||
const attachmentsList: IDataObject[] = [];
|
||||
const attachments = (options as IDataObject).attachmentsBinary as IDataObject[];
|
||||
const attachments = options.attachmentsBinary as IDataObject[];
|
||||
|
||||
if (attachments && !isEmpty(attachments)) {
|
||||
for (const { property } of attachments) {
|
||||
@@ -540,27 +537,24 @@ export async function prepareEmailAttachments(
|
||||
|
||||
export function unescapeSnippets(items: INodeExecutionData[]) {
|
||||
const result = items.map((item) => {
|
||||
const snippet = (item.json as IDataObject).snippet as string;
|
||||
const snippet = item.json.snippet as string;
|
||||
if (snippet) {
|
||||
(item.json as IDataObject).snippet = snippet.replace(
|
||||
/&|<|>|'|"/g,
|
||||
(match) => {
|
||||
switch (match) {
|
||||
case '&':
|
||||
return '&';
|
||||
case '<':
|
||||
return '<';
|
||||
case '>':
|
||||
return '>';
|
||||
case ''':
|
||||
return "'";
|
||||
case '"':
|
||||
return '"';
|
||||
default:
|
||||
return match;
|
||||
}
|
||||
},
|
||||
);
|
||||
item.json.snippet = snippet.replace(/&|<|>|'|"/g, (match) => {
|
||||
switch (match) {
|
||||
case '&':
|
||||
return '&';
|
||||
case '<':
|
||||
return '<';
|
||||
case '>':
|
||||
return '>';
|
||||
case ''':
|
||||
return "'";
|
||||
case '"':
|
||||
return '"';
|
||||
default:
|
||||
return match;
|
||||
}
|
||||
});
|
||||
}
|
||||
return item;
|
||||
});
|
||||
@@ -624,6 +618,15 @@ export async function replayToEmail(
|
||||
const replyToSenderOnly =
|
||||
options.replyToSenderOnly === undefined ? false : (options.replyToSenderOnly as boolean);
|
||||
|
||||
const prepareEmailString = (email: string) => {
|
||||
if (email.includes(emailAddress)) return;
|
||||
if (email.includes('<') && email.includes('>')) {
|
||||
to += `${email}, `;
|
||||
} else {
|
||||
to += `<${email}>, `;
|
||||
}
|
||||
};
|
||||
|
||||
for (const header of payload.headers as IDataObject[]) {
|
||||
if (((header.name as string) || '').toLowerCase() === 'from') {
|
||||
const from = header.value as string;
|
||||
@@ -636,14 +639,7 @@ export async function replayToEmail(
|
||||
|
||||
if (((header.name as string) || '').toLowerCase() === 'to' && !replyToSenderOnly) {
|
||||
const toEmails = header.value as string;
|
||||
toEmails.split(',').forEach((email: string) => {
|
||||
if (email.includes(emailAddress)) return;
|
||||
if (email.includes('<') && email.includes('>')) {
|
||||
to += `${email}, `;
|
||||
} else {
|
||||
to += `<${email}>, `;
|
||||
}
|
||||
});
|
||||
toEmails.split(',').forEach(prepareEmailString);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -669,7 +665,7 @@ export async function replayToEmail(
|
||||
threadId,
|
||||
};
|
||||
|
||||
return await googleApiRequest.call(this, 'POST', '/gmail/v1/users/me/messages/send', body, qs);
|
||||
return googleApiRequest.call(this, 'POST', '/gmail/v1/users/me/messages/send', body, qs);
|
||||
}
|
||||
|
||||
export async function simplifyOutput(
|
||||
@@ -681,7 +677,7 @@ export async function simplifyOutput(
|
||||
id,
|
||||
name,
|
||||
}));
|
||||
return ((data as IDataObject[]) || []).map((item) => {
|
||||
return (data || []).map((item) => {
|
||||
if (item.labelIds) {
|
||||
item.labels = labels.filter((label) =>
|
||||
(item.labelIds as string[]).includes(label.id as string),
|
||||
|
||||
Reference in New Issue
Block a user