fix(mail/delivery): Centralize runtime/plugin imports and switch modules to use plugins exports; unify EventEmitter usage; update Deno dependencies and small path/server refactors
This commit is contained in:
		| @@ -1,7 +1,4 @@ | ||||
| import * as plugins from '../../plugins.ts'; | ||||
| import { EventEmitter } from 'node:events'; | ||||
| import * as fs from 'node:fs'; | ||||
| import * as path from 'node:path'; | ||||
| import { logger } from '../../logger.ts'; | ||||
| import { type EmailProcessingMode } from '../routing/classes.email.config.ts'; | ||||
| import type { IEmailRoute } from '../routing/interfaces.ts'; | ||||
| @@ -74,7 +71,7 @@ export interface IQueueStats { | ||||
| /** | ||||
|  * A unified queue for all email modes | ||||
|  */ | ||||
| export class UnifiedDeliveryQueue extends EventEmitter { | ||||
| export class UnifiedDeliveryQueue extends plugins.EventEmitter { | ||||
|   private options: Required<IQueueOptions>; | ||||
|   private queue: Map<string, IQueueItem> = new Map(); | ||||
|   private checkTimer?: NodeJS.Timeout; | ||||
|   | ||||
| @@ -1,7 +1,4 @@ | ||||
| import * as plugins from '../../plugins.ts'; | ||||
| import { EventEmitter } from 'node:events'; | ||||
| import * as net from 'node:net'; | ||||
| import * as tls from 'node:tls'; | ||||
| import { logger } from '../../logger.ts'; | ||||
| import {  | ||||
|   SecurityLogger,  | ||||
| @@ -100,7 +97,7 @@ export interface IDeliveryStats { | ||||
| /** | ||||
|  * Handles delivery for all email processing modes | ||||
|  */ | ||||
| export class MultiModeDeliverySystem extends EventEmitter { | ||||
| export class MultiModeDeliverySystem extends plugins.EventEmitter { | ||||
|   private queue: UnifiedDeliveryQueue; | ||||
|   private options: Required<IMultiModeDeliveryOptions>; | ||||
|   private stats: IDeliveryStats; | ||||
|   | ||||
| @@ -1,5 +1,4 @@ | ||||
| import * as plugins from '../../plugins.ts'; | ||||
| import { EventEmitter } from 'node:events'; | ||||
| import { logger } from '../../logger.ts'; | ||||
| import { SecurityLogger, SecurityLogLevel, SecurityEventType } from '../../security/index.ts'; | ||||
|  | ||||
| @@ -84,7 +83,7 @@ export interface IRateLimitResult { | ||||
| /** | ||||
|  * Unified rate limiter for all email processing modes | ||||
|  */ | ||||
| export class UnifiedRateLimiter extends EventEmitter { | ||||
| export class UnifiedRateLimiter extends plugins.EventEmitter { | ||||
|   private config: IHierarchicalRateLimits; | ||||
|   private counters: Map<string, ILimitCounter> = new Map(); | ||||
|   private patternCounters: Map<string, ILimitCounter> = new Map(); | ||||
|   | ||||
| @@ -6,3 +6,9 @@ | ||||
| export class DeliveryPlaceholder { | ||||
|   // Placeholder for delivery functionality | ||||
| } | ||||
|  | ||||
| export class SmtpServer { | ||||
|   // Placeholder SMTP server | ||||
|   async start() {} | ||||
|   async stop() {} | ||||
| } | ||||
|   | ||||
| @@ -3,7 +3,7 @@ | ||||
|  * SMTP command sending and response parsing | ||||
|  */ | ||||
|  | ||||
| import { EventEmitter } from 'node:events'; | ||||
| import * as plugins from '../../../plugins.ts'; | ||||
| import { SMTP_COMMANDS, SMTP_CODES, LINE_ENDINGS } from './constants.ts'; | ||||
| import type {  | ||||
|   ISmtpConnection,  | ||||
| @@ -19,7 +19,7 @@ import { | ||||
| } from './utils/helpers.ts'; | ||||
| import { logCommand, logDebug } from './utils/logging.ts'; | ||||
|  | ||||
| export class CommandHandler extends EventEmitter { | ||||
| export class CommandHandler extends plugins.EventEmitter { | ||||
|   private options: ISmtpClientOptions; | ||||
|   private responseBuffer: string = ''; | ||||
|   private pendingCommand: { resolve: Function; reject: Function; command: string } | null = null; | ||||
|   | ||||
| @@ -3,20 +3,18 @@ | ||||
|  * Connection pooling and lifecycle management | ||||
|  */ | ||||
|  | ||||
| import * as net from 'node:net'; | ||||
| import * as tls from 'node:tls'; | ||||
| import { EventEmitter } from 'node:events'; | ||||
| import * as plugins from '../../../plugins.ts'; | ||||
| import { DEFAULTS, CONNECTION_STATES } from './constants.ts'; | ||||
| import type {  | ||||
|   ISmtpClientOptions,  | ||||
|   ISmtpConnection,  | ||||
| import type { | ||||
|   ISmtpClientOptions, | ||||
|   ISmtpConnection, | ||||
|   IConnectionPoolStatus, | ||||
|   ConnectionState  | ||||
|   ConnectionState | ||||
| } from './interfaces.ts'; | ||||
| import { logConnection, logDebug } from './utils/logging.ts'; | ||||
| import { generateConnectionId } from './utils/helpers.ts'; | ||||
|  | ||||
| export class ConnectionManager extends EventEmitter { | ||||
| export class ConnectionManager extends plugins.EventEmitter { | ||||
|   private options: ISmtpClientOptions; | ||||
|   private connections: Map<string, ISmtpConnection> = new Map(); | ||||
|   private pendingConnections: Set<string> = new Set(); | ||||
|   | ||||
| @@ -3,7 +3,7 @@ | ||||
|  * Main client class with delegation to handlers | ||||
|  */ | ||||
|  | ||||
| import { EventEmitter } from 'node:events'; | ||||
| import * as plugins from '../../../plugins.ts'; | ||||
| import type { Email } from '../../core/classes.email.ts'; | ||||
| import type {  | ||||
|   ISmtpClientOptions, | ||||
| @@ -30,7 +30,7 @@ interface ISmtpClientDependencies { | ||||
|   errorHandler: SmtpErrorHandler; | ||||
| } | ||||
|  | ||||
| export class SmtpClient extends EventEmitter { | ||||
| export class SmtpClient extends plugins.EventEmitter { | ||||
|   private options: ISmtpClientOptions; | ||||
|   private connectionManager: ConnectionManager; | ||||
|   private commandHandler: CommandHandler; | ||||
|   | ||||
| @@ -3,17 +3,16 @@ | ||||
|  * Provides utilities for managing TLS certificates | ||||
|  */ | ||||
|  | ||||
| import * as fs from 'fs'; | ||||
| import * as tls from 'tls'; | ||||
| import * as plugins from '../../../plugins.ts'; | ||||
| import { SmtpLogger } from './utils/logging.ts'; | ||||
|  | ||||
| /** | ||||
|  * Certificate data | ||||
|  */ | ||||
| export interface ICertificateData { | ||||
|   key: Buffer; | ||||
|   cert: Buffer; | ||||
|   ca?: Buffer; | ||||
|   key: plugins.Buffer; | ||||
|   cert: plugins.Buffer; | ||||
|   ca?: plugins.Buffer; | ||||
| } | ||||
|  | ||||
| /** | ||||
| @@ -155,7 +154,7 @@ export function loadCertificatesFromString(options: { | ||||
|       const caBuffer = caStr ? Buffer.from(caStr, 'utf8') : undefined; | ||||
|        | ||||
|       // Test the certificates first | ||||
|       const secureContext = tls.createSecureContext({ | ||||
|       const secureContext = plugins.tls.createSecureContext({ | ||||
|         key: keyBuffer, | ||||
|         cert: certBuffer, | ||||
|         ca: caBuffer | ||||
| @@ -206,7 +205,7 @@ export function loadCertificatesFromString(options: { | ||||
|        | ||||
|       // Validate the certificates by attempting to create a secure context | ||||
|       try { | ||||
|         const secureContext = tls.createSecureContext({ | ||||
|         const secureContext = plugins.tls.createSecureContext({ | ||||
|           key: keyBuffer, | ||||
|           cert: certBuffer, | ||||
|           ca: caBuffer | ||||
| @@ -253,9 +252,9 @@ export function loadCertificatesFromFiles(options: { | ||||
| }): ICertificateData { | ||||
|   try { | ||||
|     // Read files directly as Buffers | ||||
|     const key = fs.readFileSync(options.keyPath); | ||||
|     const cert = fs.readFileSync(options.certPath); | ||||
|     const ca = options.caPath ? fs.readFileSync(options.caPath) : undefined; | ||||
|     const key = plugins.fs.readFileSync(options.keyPath); | ||||
|     const cert = plugins.fs.readFileSync(options.certPath); | ||||
|     const ca = options.caPath ? plugins.fs.readFileSync(options.caPath) : undefined; | ||||
|      | ||||
|     // Log for debugging | ||||
|     SmtpLogger.debug('Certificate file properties', { | ||||
| @@ -266,7 +265,7 @@ export function loadCertificatesFromFiles(options: { | ||||
|      | ||||
|     // Validate the certificates by attempting to create a secure context | ||||
|     try { | ||||
|       const secureContext = tls.createSecureContext({ | ||||
|       const secureContext = plugins.tls.createSecureContext({ | ||||
|         key, | ||||
|         cert, | ||||
|         ca | ||||
| @@ -364,8 +363,8 @@ ORWZbz+8rBL0JIeA7eFxEA== | ||||
| export function createTlsOptions( | ||||
|   certificates: ICertificateData, | ||||
|   isServer: boolean = true | ||||
| ): tls.TlsOptions { | ||||
|   const options: tls.TlsOptions = { | ||||
| ): plugins.tls.TlsOptions { | ||||
|   const options: plugins.tls.TlsOptions = { | ||||
|     key: certificates.key, | ||||
|     cert: certificates.cert, | ||||
|     ca: certificates.ca, | ||||
|   | ||||
| @@ -4,8 +4,6 @@ | ||||
|  */ | ||||
|  | ||||
| import * as plugins from '../../../plugins.ts'; | ||||
| import * as fs from 'fs'; | ||||
| import * as path from 'path'; | ||||
| import { SmtpState } from './interfaces.ts'; | ||||
| import type { ISmtpSession, ISmtpTransactionResult } from './interfaces.ts'; | ||||
| import type { IDataHandler, ISmtpServer } from './interfaces.ts'; | ||||
|   | ||||
| @@ -1,12 +1,11 @@ | ||||
| import * as plugins from '../../plugins.ts'; | ||||
| import { EventEmitter } from 'node:events'; | ||||
| import type { IEmailRoute, IEmailMatch, IEmailAction, IEmailContext } from './interfaces.ts'; | ||||
| import type { Email } from '../core/classes.email.ts'; | ||||
|  | ||||
| /** | ||||
|  * Email router that evaluates routes and determines actions | ||||
|  */ | ||||
| export class EmailRouter extends EventEmitter { | ||||
| export class EmailRouter extends plugins.EventEmitter { | ||||
|   private routes: IEmailRoute[]; | ||||
|   private patternCache: Map<string, boolean> = new Map(); | ||||
|   private storageManager?: any; // StorageManager instance | ||||
|   | ||||
| @@ -1,6 +1,5 @@ | ||||
| import * as plugins from '../../plugins.ts'; | ||||
| import * as paths from '../../paths.ts'; | ||||
| import { EventEmitter } from 'events'; | ||||
| import { logger } from '../../logger.ts'; | ||||
| import {  | ||||
|   SecurityLogger,  | ||||
| @@ -154,7 +153,7 @@ export interface IServerStats { | ||||
| /** | ||||
|  * Unified email server that handles all email traffic with pattern-based routing | ||||
|  */ | ||||
| export class UnifiedEmailServer extends EventEmitter { | ||||
| export class UnifiedEmailServer extends plugins.EventEmitter { | ||||
|   private dcRouter: DcRouter; | ||||
|   private options: IUnifiedEmailServerOptions; | ||||
|   private emailRouter: EmailRouter; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user