mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
refactor(core): Stop importing LoggerProxy and createDeferredPromise in nodes-base (no-changelog) (#5742)
* refactor(core): Stop importing LoggerProxy in nodes-base * refactor(core): Stop importing createDeferredPromise in nodes-base
This commit is contained in:
committed by
GitHub
parent
40aacf9279
commit
38e91ab730
@@ -7,7 +7,6 @@ import type {
|
||||
ICredentialsDecrypted,
|
||||
ICredentialTestFunctions,
|
||||
IDataObject,
|
||||
IDeferredPromise,
|
||||
INodeCredentialTestResult,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
@@ -15,7 +14,7 @@ import type {
|
||||
INodeTypeDescription,
|
||||
ITriggerResponse,
|
||||
} from 'n8n-workflow';
|
||||
import { createDeferredPromise, LoggerProxy as Logger, NodeOperationError } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import type { ImapSimple, ImapSimpleOptions, Message } from 'imap-simple';
|
||||
import { connect as imapConnect, getParts } from 'imap-simple';
|
||||
@@ -272,7 +271,7 @@ export class EmailReadImapV1 implements INodeType {
|
||||
const options = this.getNodeParameter('options', {}) as IDataObject;
|
||||
|
||||
const staticData = this.getWorkflowStaticData('node');
|
||||
Logger.debug('Loaded static data for node "EmailReadImap"', { staticData });
|
||||
this.logger.debug('Loaded static data for node "EmailReadImap"', { staticData });
|
||||
|
||||
let connection: ImapSimple;
|
||||
|
||||
@@ -501,7 +500,7 @@ export class EmailReadImapV1 implements INodeType {
|
||||
return newEmails;
|
||||
};
|
||||
|
||||
const returnedPromise: IDeferredPromise<void> | undefined = await createDeferredPromise();
|
||||
const returnedPromise = await this.helpers.createDeferredPromise();
|
||||
|
||||
const establishConnection = async (): Promise<ImapSimple> => {
|
||||
let searchCriteria = ['UNSEEN'] as Array<string | string[]>;
|
||||
@@ -538,7 +537,9 @@ export class EmailReadImapV1 implements INodeType {
|
||||
* - You can check if UIDs changed in the above example
|
||||
* by checking UIDValidity.
|
||||
*/
|
||||
Logger.debug('Querying for new messages on node "EmailReadImap"', { searchCriteria });
|
||||
this.logger.debug('Querying for new messages on node "EmailReadImap"', {
|
||||
searchCriteria,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -547,7 +548,7 @@ export class EmailReadImapV1 implements INodeType {
|
||||
this.emit([returnData]);
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error('Email Read Imap node encountered an error fetching new emails', {
|
||||
this.logger.error('Email Read Imap node encountered an error fetching new emails', {
|
||||
error,
|
||||
});
|
||||
// Wait with resolving till the returnedPromise got resolved, else n8n will be unhappy
|
||||
@@ -580,17 +581,19 @@ export class EmailReadImapV1 implements INodeType {
|
||||
conn.on('error', async (error) => {
|
||||
const errorCode = error.code.toUpperCase();
|
||||
if (['ECONNRESET', 'EPIPE'].includes(errorCode as string)) {
|
||||
Logger.verbose(`IMAP connection was reset (${errorCode}) - reconnecting.`, { error });
|
||||
this.logger.verbose(`IMAP connection was reset (${errorCode}) - reconnecting.`, {
|
||||
error,
|
||||
});
|
||||
try {
|
||||
connection = await establishConnection();
|
||||
await connection.openBox(mailbox);
|
||||
return;
|
||||
} catch (e) {
|
||||
Logger.error('IMAP reconnect did fail', { error: e });
|
||||
this.logger.error('IMAP reconnect did fail', { error: e });
|
||||
// If something goes wrong we want to run emitError
|
||||
}
|
||||
} else {
|
||||
Logger.error('Email Read Imap node encountered a connection error', { error });
|
||||
this.logger.error('Email Read Imap node encountered a connection error', { error });
|
||||
this.emitError(error as Error);
|
||||
}
|
||||
});
|
||||
@@ -606,7 +609,7 @@ export class EmailReadImapV1 implements INodeType {
|
||||
|
||||
if (options.forceReconnect !== undefined) {
|
||||
reconnectionInterval = setInterval(async () => {
|
||||
Logger.verbose('Forcing reconnection of IMAP node.');
|
||||
this.logger.verbose('Forcing reconnection of IMAP node.');
|
||||
connection.end();
|
||||
connection = await establishConnection();
|
||||
await connection.openBox(mailbox);
|
||||
|
||||
@@ -6,7 +6,6 @@ import type {
|
||||
ICredentialsDecrypted,
|
||||
ICredentialTestFunctions,
|
||||
IDataObject,
|
||||
IDeferredPromise,
|
||||
INodeCredentialTestResult,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
@@ -14,7 +13,7 @@ import type {
|
||||
INodeTypeDescription,
|
||||
ITriggerResponse,
|
||||
} from 'n8n-workflow';
|
||||
import { createDeferredPromise, LoggerProxy as Logger, NodeOperationError } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import type { ImapSimple, ImapSimpleOptions, Message } from 'imap-simple';
|
||||
import { connect as imapConnect, getParts } from 'imap-simple';
|
||||
@@ -278,7 +277,7 @@ export class EmailReadImapV2 implements INodeType {
|
||||
const options = this.getNodeParameter('options', {}) as IDataObject;
|
||||
|
||||
const staticData = this.getWorkflowStaticData('node');
|
||||
Logger.debug('Loaded static data for node "EmailReadImap"', { staticData });
|
||||
this.logger.debug('Loaded static data for node "EmailReadImap"', { staticData });
|
||||
|
||||
let connection: ImapSimple;
|
||||
let closeFunctionWasCalled = false;
|
||||
@@ -509,7 +508,7 @@ export class EmailReadImapV2 implements INodeType {
|
||||
return newEmails;
|
||||
};
|
||||
|
||||
const returnedPromise: IDeferredPromise<void> | undefined = await createDeferredPromise();
|
||||
const returnedPromise = await this.helpers.createDeferredPromise();
|
||||
|
||||
const establishConnection = async (): Promise<ImapSimple> => {
|
||||
let searchCriteria = ['UNSEEN'] as Array<string | string[]>;
|
||||
@@ -546,7 +545,9 @@ export class EmailReadImapV2 implements INodeType {
|
||||
* - You can check if UIDs changed in the above example
|
||||
* by checking UIDValidity.
|
||||
*/
|
||||
Logger.debug('Querying for new messages on node "EmailReadImap"', { searchCriteria });
|
||||
this.logger.debug('Querying for new messages on node "EmailReadImap"', {
|
||||
searchCriteria,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -555,7 +556,7 @@ export class EmailReadImapV2 implements INodeType {
|
||||
this.emit([returnData]);
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error('Email Read Imap node encountered an error fetching new emails', {
|
||||
this.logger.error('Email Read Imap node encountered an error fetching new emails', {
|
||||
error,
|
||||
});
|
||||
// Wait with resolving till the returnedPromise got resolved, else n8n will be unhappy
|
||||
@@ -567,7 +568,7 @@ export class EmailReadImapV2 implements INodeType {
|
||||
}
|
||||
},
|
||||
onupdate: async (seqno: number, info) => {
|
||||
Logger.verbose(`Email Read Imap:update ${seqno}`, info as IDataObject);
|
||||
this.logger.verbose(`Email Read Imap:update ${seqno}`, info as IDataObject);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -590,17 +591,17 @@ export class EmailReadImapV2 implements INodeType {
|
||||
return imapConnect(config).then(async (conn) => {
|
||||
conn.on('close', async (_hadError: boolean) => {
|
||||
if (isCurrentlyReconnecting) {
|
||||
Logger.debug('Email Read Imap: Connected closed for forced reconnecting');
|
||||
this.logger.debug('Email Read Imap: Connected closed for forced reconnecting');
|
||||
} else if (closeFunctionWasCalled) {
|
||||
Logger.debug('Email Read Imap: Shutting down workflow - connected closed');
|
||||
this.logger.debug('Email Read Imap: Shutting down workflow - connected closed');
|
||||
} else {
|
||||
Logger.error('Email Read Imap: Connected closed unexpectedly');
|
||||
this.logger.error('Email Read Imap: Connected closed unexpectedly');
|
||||
this.emitError(new Error('Imap connection closed unexpectedly'));
|
||||
}
|
||||
});
|
||||
conn.on('error', async (error) => {
|
||||
const errorCode = error.code.toUpperCase();
|
||||
Logger.verbose(`IMAP connection experienced an error: (${errorCode})`, { error });
|
||||
this.logger.verbose(`IMAP connection experienced an error: (${errorCode})`, { error });
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
await closeFunction();
|
||||
this.emitError(error as Error);
|
||||
@@ -617,7 +618,7 @@ export class EmailReadImapV2 implements INodeType {
|
||||
|
||||
if (options.forceReconnect !== undefined) {
|
||||
reconnectionInterval = setInterval(async () => {
|
||||
Logger.verbose('Forcing reconnect to IMAP server');
|
||||
this.logger.verbose('Forcing reconnect to IMAP server');
|
||||
try {
|
||||
isCurrentlyReconnecting = true;
|
||||
if (connection.closeBox) await connection.closeBox(false);
|
||||
@@ -625,7 +626,7 @@ export class EmailReadImapV2 implements INodeType {
|
||||
connection = await establishConnection();
|
||||
await connection.openBox(mailbox);
|
||||
} catch (error) {
|
||||
Logger.error(error as string);
|
||||
this.logger.error(error as string);
|
||||
} finally {
|
||||
isCurrentlyReconnecting = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user