mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
n8n-3867-progressively-apply-prettier-to-all (#3873)
* 🔨 formatting nodes with prettier
This commit is contained in:
@@ -1,16 +1,8 @@
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
import {
|
||||
simpleParser,
|
||||
} from 'mailparser';
|
||||
import { simpleParser } from 'mailparser';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions, IExecuteSingleFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IBinaryKeyData,
|
||||
@@ -20,9 +12,7 @@ import {
|
||||
NodeOperationError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
IEmail,
|
||||
} from './Gmail.node';
|
||||
import { IEmail } from './Gmail.node';
|
||||
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
@@ -37,12 +27,25 @@ interface IGoogleAuthCredentials {
|
||||
|
||||
const mailComposer = require('nodemailer/lib/mail-composer');
|
||||
|
||||
export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string,
|
||||
endpoint: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
const authenticationMethod = this.getNodeParameter('authentication', 0, 'serviceAccount') as string;
|
||||
export async function googleApiRequest(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
body: any = {},
|
||||
qs: IDataObject = {},
|
||||
uri?: string,
|
||||
option: IDataObject = {},
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const authenticationMethod = this.getNodeParameter(
|
||||
'authentication',
|
||||
0,
|
||||
'serviceAccount',
|
||||
) as string;
|
||||
let options: OptionsWithUri = {
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method,
|
||||
@@ -65,7 +68,10 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
if (authenticationMethod === 'serviceAccount') {
|
||||
const credentials = await this.getCredentials('googleApi');
|
||||
|
||||
const { access_token } = await getAccessToken.call(this, credentials as unknown as IGoogleAuthCredentials);
|
||||
const { access_token } = await getAccessToken.call(
|
||||
this,
|
||||
credentials as unknown as IGoogleAuthCredentials,
|
||||
);
|
||||
|
||||
options.headers!.Authorization = `Bearer ${access_token}`;
|
||||
//@ts-ignore
|
||||
@@ -74,7 +80,6 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
//@ts-ignore
|
||||
return await this.helpers.requestOAuth2.call(this, 'gmailOAuth2', options);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
if (error.code === 'ERR_OSSL_PEM_NO_START_LINE') {
|
||||
error.statusCode = '401';
|
||||
@@ -84,9 +89,12 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export async function parseRawEmail(this: IExecuteFunctions, messageData: any, dataPropertyNameDownload: string): Promise<INodeExecutionData> { // tslint:disable-line:no-any
|
||||
|
||||
export async function parseRawEmail(
|
||||
this: IExecuteFunctions,
|
||||
// tslint:disable-next-line:no-any
|
||||
messageData: any,
|
||||
dataPropertyNameDownload: string,
|
||||
): Promise<INodeExecutionData> {
|
||||
const messageEncoded = Buffer.from(messageData.raw, 'base64').toString('utf8');
|
||||
let responseData = await simpleParser(messageEncoded);
|
||||
|
||||
@@ -103,10 +111,13 @@ export async function parseRawEmail(this: IExecuteFunctions, messageData: any, d
|
||||
|
||||
const binaryData: IBinaryKeyData = {};
|
||||
if (responseData.attachments) {
|
||||
|
||||
for (let i = 0; i < responseData.attachments.length; i++) {
|
||||
const attachment = responseData.attachments[i];
|
||||
binaryData[`${dataPropertyNameDownload}${i}`] = await this.helpers.prepareBinaryData(attachment.content, attachment.filename, attachment.contentType);
|
||||
binaryData[`${dataPropertyNameDownload}${i}`] = await this.helpers.prepareBinaryData(
|
||||
attachment.content,
|
||||
attachment.filename,
|
||||
attachment.contentType,
|
||||
);
|
||||
}
|
||||
// @ts-ignore
|
||||
responseData.attachments = undefined;
|
||||
@@ -114,12 +125,7 @@ export async function parseRawEmail(this: IExecuteFunctions, messageData: any, d
|
||||
|
||||
const mailBaseData: IDataObject = {};
|
||||
|
||||
const resolvedModeAddProperties = [
|
||||
'id',
|
||||
'threadId',
|
||||
'labelIds',
|
||||
'sizeEstimate',
|
||||
];
|
||||
const resolvedModeAddProperties = ['id', 'threadId', 'labelIds', 'sizeEstimate'];
|
||||
|
||||
for (const key of resolvedModeAddProperties) {
|
||||
// @ts-ignore
|
||||
@@ -134,7 +140,6 @@ export async function parseRawEmail(this: IExecuteFunctions, messageData: any, d
|
||||
} as INodeExecutionData;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// This function converts an email object into a MIME encoded email and then converts that string into base64 encoding
|
||||
// for more info on MIME, https://docs.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2010/aa494197(v%3Dexchg.140)
|
||||
@@ -158,7 +163,11 @@ export async function encodeEmail(email: IEmail) {
|
||||
mailOptions.html = email.htmlBody;
|
||||
}
|
||||
|
||||
if (email.attachments !== undefined && Array.isArray(email.attachments) && email.attachments.length > 0) {
|
||||
if (
|
||||
email.attachments !== undefined &&
|
||||
Array.isArray(email.attachments) &&
|
||||
email.attachments.length > 0
|
||||
) {
|
||||
const attachments = email.attachments.map((attachment) => ({
|
||||
filename: attachment.name,
|
||||
content: attachment.content,
|
||||
@@ -182,8 +191,16 @@ export async function encodeEmail(email: IEmail) {
|
||||
return mailBody.toString('base64').replace(/\+/g, '-').replace(/\//g, '_');
|
||||
}
|
||||
|
||||
export async function googleApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions, propertyName: string, method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
export async function googleApiRequestAllItems(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
propertyName: string,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
body: any = {},
|
||||
query: IDataObject = {},
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let responseData;
|
||||
@@ -193,10 +210,7 @@ export async function googleApiRequestAllItems(this: IExecuteFunctions | ILoadOp
|
||||
responseData = await googleApiRequest.call(this, method, endpoint, body, query);
|
||||
query.pageToken = responseData['nextPageToken'];
|
||||
returnData.push.apply(returnData, responseData[propertyName]);
|
||||
} while (
|
||||
responseData['nextPageToken'] !== undefined &&
|
||||
responseData['nextPageToken'] !== ''
|
||||
);
|
||||
} while (responseData['nextPageToken'] !== undefined && responseData['nextPageToken'] !== '');
|
||||
|
||||
return returnData;
|
||||
}
|
||||
@@ -206,7 +220,10 @@ export function extractEmail(s: string) {
|
||||
return data.substring(0, data.length - 1);
|
||||
}
|
||||
|
||||
function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, credentials: IGoogleAuthCredentials): Promise<IDataObject> {
|
||||
function getAccessToken(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
credentials: IGoogleAuthCredentials,
|
||||
): Promise<IDataObject> {
|
||||
//https://developers.google.com/identity/protocols/oauth2/service-account#httprest
|
||||
|
||||
const scopes = [
|
||||
@@ -225,20 +242,20 @@ function getAccessToken(this: IExecuteFunctions | IExecuteSingleFunctions | ILoa
|
||||
|
||||
const signature = jwt.sign(
|
||||
{
|
||||
'iss': credentials.email as string,
|
||||
'sub': credentials.delegatedEmail || credentials.email as string,
|
||||
'scope': scopes.join(' '),
|
||||
'aud': `https://oauth2.googleapis.com/token`,
|
||||
'iat': now,
|
||||
'exp': now + 3600,
|
||||
iss: credentials.email as string,
|
||||
sub: credentials.delegatedEmail || (credentials.email as string),
|
||||
scope: scopes.join(' '),
|
||||
aud: `https://oauth2.googleapis.com/token`,
|
||||
iat: now,
|
||||
exp: now + 3600,
|
||||
},
|
||||
privateKey,
|
||||
{
|
||||
algorithm: 'RS256',
|
||||
header: {
|
||||
'kid': privateKey,
|
||||
'typ': 'JWT',
|
||||
'alg': 'RS256',
|
||||
kid: privateKey,
|
||||
typ: 'JWT',
|
||||
alg: 'RS256',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user