mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 19:32:15 +00:00
refactor(core): Introduce overload for number-type node parameter (no-changelog) (#4644)
* 📘 Set up overloads * 📘 Add temporary assertion * 🔥 Remove inferrable number assertions * ✏️ Add ticket ref
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
IBinaryKeyData,
|
||||
@@ -23,29 +21,15 @@ import {
|
||||
parseRawEmail,
|
||||
} from '../GenericFunctions';
|
||||
|
||||
import {
|
||||
messageFields,
|
||||
messageOperations,
|
||||
} from './MessageDescription';
|
||||
import { messageFields, messageOperations } from './MessageDescription';
|
||||
|
||||
import {
|
||||
messageLabelFields,
|
||||
messageLabelOperations,
|
||||
} from './MessageLabelDescription';
|
||||
import { messageLabelFields, messageLabelOperations } from './MessageLabelDescription';
|
||||
|
||||
import {
|
||||
labelFields,
|
||||
labelOperations,
|
||||
} from './LabelDescription';
|
||||
import { labelFields, labelOperations } from './LabelDescription';
|
||||
|
||||
import {
|
||||
draftFields,
|
||||
draftOperations,
|
||||
} from './DraftDescription';
|
||||
import { draftFields, draftOperations } from './DraftDescription';
|
||||
|
||||
import {
|
||||
isEmpty,
|
||||
} from 'lodash';
|
||||
import { isEmpty } from 'lodash';
|
||||
|
||||
const versionDescription: INodeTypeDescription = {
|
||||
displayName: 'Gmail',
|
||||
@@ -66,9 +50,7 @@ const versionDescription: INodeTypeDescription = {
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'serviceAccount',
|
||||
],
|
||||
authentication: ['serviceAccount'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -77,9 +59,7 @@ const versionDescription: INodeTypeDescription = {
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'oAuth2',
|
||||
],
|
||||
authentication: ['oAuth2'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -165,9 +145,7 @@ export class GmailV1 implements INodeType {
|
||||
loadOptions: {
|
||||
// Get all the labels to display them to user so that he can
|
||||
// select them easily
|
||||
async getLabels(
|
||||
this: ILoadOptionsFunctions,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
async getLabels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const labels = await googleApiRequestAllItems.call(
|
||||
this,
|
||||
@@ -182,8 +160,12 @@ export class GmailV1 implements INodeType {
|
||||
});
|
||||
}
|
||||
return returnData.sort((a, b) => {
|
||||
if (a.name < b.name) { return -1; }
|
||||
if (a.name > b.name) { return 1; }
|
||||
if (a.name < b.name) {
|
||||
return -1;
|
||||
}
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
},
|
||||
@@ -209,7 +191,10 @@ export class GmailV1 implements INodeType {
|
||||
//https://developers.google.com/gmail/api/v1/reference/users/labels/create
|
||||
const labelName = this.getNodeParameter('name', i) as string;
|
||||
const labelListVisibility = this.getNodeParameter('labelListVisibility', i) as string;
|
||||
const messageListVisibility = this.getNodeParameter('messageListVisibility', i) as string;
|
||||
const messageListVisibility = this.getNodeParameter(
|
||||
'messageListVisibility',
|
||||
i,
|
||||
) as string;
|
||||
|
||||
method = 'POST';
|
||||
endpoint = '/gmail/v1/users/me/labels';
|
||||
@@ -230,7 +215,6 @@ export class GmailV1 implements INodeType {
|
||||
endpoint = `/gmail/v1/users/me/labels/${labelId}`;
|
||||
responseData = await googleApiRequest.call(this, method, endpoint, body, qs);
|
||||
responseData = { success: true };
|
||||
|
||||
}
|
||||
if (operation === 'get') {
|
||||
// https://developers.google.com/gmail/api/v1/reference/users/labels/get
|
||||
@@ -255,7 +239,7 @@ export class GmailV1 implements INodeType {
|
||||
responseData = responseData.labels;
|
||||
|
||||
if (!returnAll) {
|
||||
const limit = this.getNodeParameter('limit', i) as number;
|
||||
const limit = this.getNodeParameter('limit', i);
|
||||
responseData = responseData.splice(0, limit);
|
||||
}
|
||||
}
|
||||
@@ -325,15 +309,20 @@ export class GmailV1 implements INodeType {
|
||||
const attachmentsUi = additionalFields.attachmentsUi as IDataObject;
|
||||
const attachmentsBinary = [];
|
||||
if (!isEmpty(attachmentsUi)) {
|
||||
if (attachmentsUi.hasOwnProperty('attachmentsBinary')
|
||||
&& !isEmpty(attachmentsUi.attachmentsBinary)
|
||||
&& items[i].binary) {
|
||||
if (
|
||||
attachmentsUi.hasOwnProperty('attachmentsBinary') &&
|
||||
!isEmpty(attachmentsUi.attachmentsBinary) &&
|
||||
items[i].binary
|
||||
) {
|
||||
// @ts-ignore
|
||||
for (const { property } of attachmentsUi.attachmentsBinary as IDataObject[]) {
|
||||
for (const binaryProperty of (property as string).split(',')) {
|
||||
if (items[i].binary![binaryProperty] !== undefined) {
|
||||
const binaryData = items[i].binary![binaryProperty];
|
||||
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
|
||||
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
|
||||
i,
|
||||
binaryProperty,
|
||||
);
|
||||
attachmentsBinary.push({
|
||||
name: binaryData.fileName || 'unknown',
|
||||
content: binaryDataBuffer,
|
||||
@@ -353,7 +342,7 @@ export class GmailV1 implements INodeType {
|
||||
}
|
||||
|
||||
const email: IEmail = {
|
||||
from: additionalFields.senderName as string || '',
|
||||
from: (additionalFields.senderName as string) || '',
|
||||
to: toStr,
|
||||
cc: ccStr,
|
||||
bcc: bccStr,
|
||||
@@ -362,7 +351,7 @@ export class GmailV1 implements INodeType {
|
||||
attachments: attachmentsList,
|
||||
};
|
||||
|
||||
if (this.getNodeParameter('includeHtml', i, false) as boolean === true) {
|
||||
if ((this.getNodeParameter('includeHtml', i, false) as boolean) === true) {
|
||||
email.htmlBody = this.getNodeParameter('htmlMessage', i) as string;
|
||||
}
|
||||
|
||||
@@ -376,7 +365,6 @@ export class GmailV1 implements INodeType {
|
||||
responseData = await googleApiRequest.call(this, method, endpoint, body, qs);
|
||||
}
|
||||
if (operation === 'reply') {
|
||||
|
||||
const id = this.getNodeParameter('messageId', i) as string;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
||||
@@ -411,15 +399,20 @@ export class GmailV1 implements INodeType {
|
||||
const attachmentsUi = additionalFields.attachmentsUi as IDataObject;
|
||||
const attachmentsBinary = [];
|
||||
if (!isEmpty(attachmentsUi)) {
|
||||
if (attachmentsUi.hasOwnProperty('attachmentsBinary')
|
||||
&& !isEmpty(attachmentsUi.attachmentsBinary)
|
||||
&& items[i].binary) {
|
||||
if (
|
||||
attachmentsUi.hasOwnProperty('attachmentsBinary') &&
|
||||
!isEmpty(attachmentsUi.attachmentsBinary) &&
|
||||
items[i].binary
|
||||
) {
|
||||
// @ts-ignore
|
||||
for (const { property } of attachmentsUi.attachmentsBinary as IDataObject[]) {
|
||||
for (const binaryProperty of (property as string).split(',')) {
|
||||
if (items[i].binary![binaryProperty] !== undefined) {
|
||||
const binaryData = items[i].binary![binaryProperty];
|
||||
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
|
||||
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
|
||||
i,
|
||||
binaryProperty,
|
||||
);
|
||||
attachmentsBinary.push({
|
||||
name: binaryData.fileName || 'unknown',
|
||||
content: binaryDataBuffer,
|
||||
@@ -453,11 +446,17 @@ export class GmailV1 implements INodeType {
|
||||
}
|
||||
}
|
||||
|
||||
const subject = payload.headers.filter((data: { [key: string]: string }) => data.name === 'Subject')[0]?.value || '';
|
||||
const references = payload.headers.filter((data: { [key: string]: string }) => data.name === 'References')[0]?.value || '';
|
||||
const subject =
|
||||
payload.headers.filter(
|
||||
(data: { [key: string]: string }) => data.name === 'Subject',
|
||||
)[0]?.value || '';
|
||||
const references =
|
||||
payload.headers.filter(
|
||||
(data: { [key: string]: string }) => data.name === 'References',
|
||||
)[0]?.value || '';
|
||||
|
||||
const email: IEmail = {
|
||||
from: additionalFields.senderName as string || '',
|
||||
from: (additionalFields.senderName as string) || '',
|
||||
to: toStr,
|
||||
cc: ccStr,
|
||||
bcc: bccStr,
|
||||
@@ -466,7 +465,7 @@ export class GmailV1 implements INodeType {
|
||||
attachments: attachmentsList,
|
||||
};
|
||||
|
||||
if (this.getNodeParameter('includeHtml', i, false) as boolean === true) {
|
||||
if ((this.getNodeParameter('includeHtml', i, false) as boolean) === true) {
|
||||
email.htmlBody = this.getNodeParameter('htmlMessage', i) as string;
|
||||
}
|
||||
|
||||
@@ -504,9 +503,14 @@ export class GmailV1 implements INodeType {
|
||||
|
||||
let nodeExecutionData: INodeExecutionData;
|
||||
if (format === 'resolved') {
|
||||
const dataPropertyNameDownload = additionalFields.dataPropertyAttachmentsPrefixName as string || 'attachment_';
|
||||
const dataPropertyNameDownload =
|
||||
(additionalFields.dataPropertyAttachmentsPrefixName as string) || 'attachment_';
|
||||
|
||||
nodeExecutionData = await parseRawEmail.call(this, responseData, dataPropertyNameDownload);
|
||||
nodeExecutionData = await parseRawEmail.call(
|
||||
this,
|
||||
responseData,
|
||||
dataPropertyNameDownload,
|
||||
);
|
||||
} else {
|
||||
nodeExecutionData = {
|
||||
json: responseData,
|
||||
@@ -539,7 +543,7 @@ export class GmailV1 implements INodeType {
|
||||
qs,
|
||||
);
|
||||
} else {
|
||||
qs.maxResults = this.getNodeParameter('limit', i) as number;
|
||||
qs.maxResults = this.getNodeParameter('limit', i);
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
@@ -557,7 +561,6 @@ export class GmailV1 implements INodeType {
|
||||
const format = additionalFields.format || 'resolved';
|
||||
|
||||
if (format !== 'ids') {
|
||||
|
||||
if (format === 'resolved') {
|
||||
qs.format = 'raw';
|
||||
} else {
|
||||
@@ -574,9 +577,14 @@ export class GmailV1 implements INodeType {
|
||||
);
|
||||
|
||||
if (format === 'resolved') {
|
||||
const dataPropertyNameDownload = additionalFields.dataPropertyAttachmentsPrefixName as string || 'attachment_';
|
||||
const dataPropertyNameDownload =
|
||||
(additionalFields.dataPropertyAttachmentsPrefixName as string) || 'attachment_';
|
||||
|
||||
responseData[i] = await parseRawEmail.call(this, responseData[i], dataPropertyNameDownload);
|
||||
responseData[i] = await parseRawEmail.call(
|
||||
this,
|
||||
responseData[i],
|
||||
dataPropertyNameDownload,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -584,7 +592,6 @@ export class GmailV1 implements INodeType {
|
||||
if (format !== 'resolved') {
|
||||
responseData = this.helpers.returnJsonArray(responseData);
|
||||
}
|
||||
|
||||
}
|
||||
if (operation === 'delete') {
|
||||
// https://developers.google.com/gmail/api/v1/reference/users/messages/delete
|
||||
@@ -638,14 +645,19 @@ export class GmailV1 implements INodeType {
|
||||
const attachmentsBinary = [];
|
||||
if (!isEmpty(attachmentsUi)) {
|
||||
if (!isEmpty(attachmentsUi)) {
|
||||
if (attachmentsUi.hasOwnProperty('attachmentsBinary')
|
||||
&& !isEmpty(attachmentsUi.attachmentsBinary)
|
||||
&& items[i].binary) {
|
||||
if (
|
||||
attachmentsUi.hasOwnProperty('attachmentsBinary') &&
|
||||
!isEmpty(attachmentsUi.attachmentsBinary) &&
|
||||
items[i].binary
|
||||
) {
|
||||
for (const { property } of attachmentsUi.attachmentsBinary as IDataObject[]) {
|
||||
for (const binaryProperty of (property as string).split(',')) {
|
||||
if (items[i].binary![binaryProperty] !== undefined) {
|
||||
const binaryData = items[i].binary![binaryProperty];
|
||||
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
|
||||
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
|
||||
i,
|
||||
binaryProperty,
|
||||
);
|
||||
attachmentsBinary.push({
|
||||
name: binaryData.fileName || 'unknown',
|
||||
content: binaryDataBuffer,
|
||||
@@ -675,7 +687,7 @@ export class GmailV1 implements INodeType {
|
||||
attachments: attachmentsList,
|
||||
};
|
||||
|
||||
if (this.getNodeParameter('includeHtml', i, false) as boolean === true) {
|
||||
if ((this.getNodeParameter('includeHtml', i, false) as boolean) === true) {
|
||||
email.htmlBody = this.getNodeParameter('htmlMessage', i) as string;
|
||||
}
|
||||
|
||||
@@ -712,9 +724,14 @@ export class GmailV1 implements INodeType {
|
||||
|
||||
let nodeExecutionData: INodeExecutionData;
|
||||
if (format === 'resolved') {
|
||||
const dataPropertyNameDownload = additionalFields.dataPropertyAttachmentsPrefixName as string || 'attachment_';
|
||||
const dataPropertyNameDownload =
|
||||
(additionalFields.dataPropertyAttachmentsPrefixName as string) || 'attachment_';
|
||||
|
||||
nodeExecutionData = await parseRawEmail.call(this, responseData.message, dataPropertyNameDownload);
|
||||
nodeExecutionData = await parseRawEmail.call(
|
||||
this,
|
||||
responseData.message,
|
||||
dataPropertyNameDownload,
|
||||
);
|
||||
|
||||
// Add the draft-id
|
||||
nodeExecutionData.json.messageId = nodeExecutionData.json.id;
|
||||
@@ -754,7 +771,7 @@ export class GmailV1 implements INodeType {
|
||||
qs,
|
||||
);
|
||||
} else {
|
||||
qs.maxResults = this.getNodeParameter('limit', i) as number;
|
||||
qs.maxResults = this.getNodeParameter('limit', i);
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
@@ -779,7 +796,6 @@ export class GmailV1 implements INodeType {
|
||||
}
|
||||
|
||||
for (let i = 0; i < responseData.length; i++) {
|
||||
|
||||
responseData[i] = await googleApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
@@ -789,9 +805,14 @@ export class GmailV1 implements INodeType {
|
||||
);
|
||||
|
||||
if (format === 'resolved') {
|
||||
const dataPropertyNameDownload = additionalFields.dataPropertyAttachmentsPrefixName as string || 'attachment_';
|
||||
const dataPropertyNameDownload =
|
||||
(additionalFields.dataPropertyAttachmentsPrefixName as string) || 'attachment_';
|
||||
const id = responseData[i].id;
|
||||
responseData[i] = await parseRawEmail.call(this, responseData[i].message, dataPropertyNameDownload);
|
||||
responseData[i] = await parseRawEmail.call(
|
||||
this,
|
||||
responseData[i].message,
|
||||
dataPropertyNameDownload,
|
||||
);
|
||||
|
||||
// Add the draft-id
|
||||
responseData[i].json.messageId = responseData[i].json.id;
|
||||
|
||||
Reference in New Issue
Block a user