This commit is contained in:
Philipp Kunz 2025-05-27 10:39:29 +00:00
parent 69304dc839
commit c3b14c0f58
6 changed files with 25 additions and 132 deletions

View File

@ -1,5 +1,5 @@
import { SmtpClient } from '../../ts/mail/delivery/classes.smtp.client.js';
import type { ISmtpClientOptions } from '../../ts/mail/delivery/smtpclient/interfaces.js';
import { smtpClientMod } from '../../ts/mail/delivery/index.js';
import type { ISmtpClientOptions, SmtpClient } from '../../ts/mail/delivery/smtpclient/index.js';
import { Email } from '../../ts/mail/core/classes.email.js';
/**
@ -21,7 +21,7 @@ export function createTestSmtpClient(options: Partial<ISmtpClientOptions> = {}):
}
};
return new SmtpClient(defaultOptions);
return smtpClientMod.createSmtpClient(defaultOptions);
}
/**

View File

@ -4,7 +4,7 @@ import * as plugins from '../ts/plugins.js';
import DcRouter from '../ts/classes.dcrouter.js';
import { EmailService } from '../ts/mail/services/classes.emailservice.js';
import { BounceManager } from '../ts/mail/core/classes.bouncemanager.js';
import { SmtpClient } from '../ts/mail/delivery/classes.smtp.client.js';
import { smtpClientMod } from '../ts/mail/delivery/index.js';
import { SmtpServer } from '../ts/mail/delivery/smtpserver/smtp-server.js';
// Test the new integration architecture
@ -83,7 +83,7 @@ tap.test('SMTP client should be able to connect to SMTP server', async (tools) =
socketTimeout: 5000
};
const smtpClient = new SmtpClient(options);
const smtpClient = smtpClientMod.createSmtpClient(options);
// Verify it was created properly
expect(smtpClient).toBeTruthy();

View File

@ -1,6 +1,6 @@
import { tap, expect } from '@git.zone/tstest/tapbundle';
import { SmtpClient } from '../ts/mail/delivery/classes.smtp.client.js';
import type { ISmtpClientOptions } from '../ts/mail/delivery/classes.smtp.client.js';
import { smtpClientMod } from '../ts/mail/delivery/index.js';
import type { ISmtpClientOptions, SmtpClient } from '../ts/mail/delivery/smtpclient/index.js';
import { Email } from '../ts/mail/core/classes.email.js';
/**
@ -18,7 +18,7 @@ tap.test('verify backward compatibility - client creation', async () => {
};
// Create SMTP client instance using legacy constructor
const smtpClient = new SmtpClient(options);
const smtpClient = smtpClientMod.createSmtpClient(options);
// Verify instance was created correctly
expect(smtpClient).toBeTruthy();
@ -32,7 +32,7 @@ tap.test('verify backward compatibility - methods exist', async () => {
secure: false
};
const smtpClient = new SmtpClient(options);
const smtpClient = smtpClientMod.createSmtpClient(options);
// Verify all expected methods exist
expect(typeof smtpClient.sendMail === 'function').toBeTruthy();
@ -53,7 +53,7 @@ tap.test('verify backward compatibility - options update', async () => {
secure: false
};
const smtpClient = new SmtpClient(options);
const smtpClient = smtpClientMod.createSmtpClient(options);
// Test option updates don't throw
expect(() => smtpClient.updateOptions({
@ -76,7 +76,7 @@ tap.test('verify backward compatibility - connection failure handling', async ()
connectionTimeout: 1000 // Short timeout for faster test
};
const smtpClient = new SmtpClient(options);
const smtpClient = smtpClientMod.createSmtpClient(options);
// verify() should return false for invalid hosts
const isValid = await smtpClient.verify();
@ -109,7 +109,7 @@ tap.test('verify backward compatibility - pool status', async () => {
maxConnections: 5
};
const smtpClient = new SmtpClient(options);
const smtpClient = smtpClientMod.createSmtpClient(options);
// Get pool status
const status = smtpClient.getPoolStatus();
@ -133,7 +133,7 @@ tap.test('verify backward compatibility - event handling', async () => {
secure: false
};
const smtpClient = new SmtpClient(options);
const smtpClient = smtpClientMod.createSmtpClient(options);
// Test event listener methods don't throw
const testListener = () => {};

View File

@ -1,8 +1,8 @@
import { tap, expect } from '@git.zone/tstest/tapbundle';
import * as plugins from '../ts/plugins.js';
import * as paths from '../ts/paths.js';
import { SmtpClient } from '../ts/mail/delivery/classes.smtp.client.js';
import type { ISmtpClientOptions } from '../ts/mail/delivery/classes.smtp.client.js';
import { smtpClientMod } from '../ts/mail/delivery/index.js';
import type { ISmtpClientOptions, SmtpClient } from '../ts/mail/delivery/smtpclient/index.js';
import { Email } from '../ts/mail/core/classes.email.js';
/**
@ -19,7 +19,7 @@ tap.test('verify SMTP client initialization', async () => {
};
// Create SMTP client instance
const smtpClient = new SmtpClient(options);
const smtpClient = smtpClientMod.createSmtpClient(options);
// Verify instance was created correctly
expect(smtpClient).toBeTruthy();
@ -35,7 +35,7 @@ tap.test('test SMTP client configuration update', async () => {
};
// Create SMTP client instance
const smtpClient = new SmtpClient(options);
const smtpClient = smtpClientMod.createSmtpClient(options);
// Update configuration
smtpClient.updateOptions({
@ -117,7 +117,7 @@ tap.test('verify SMTP client email delivery functionality with mock', async () =
};
// Create SMTP client instance
const smtpClient = new SmtpClient(options);
const smtpClient = smtpClientMod.createSmtpClient(options);
// Test public methods exist and have correct signatures
expect(typeof smtpClient.sendMail).toEqual('function');
@ -144,7 +144,7 @@ tap.test('verify SMTP client email delivery functionality with mock', async () =
tap.test('test SMTP client error handling with mock', async () => {
// Create SMTP client instance
const smtpClient = new SmtpClient({
const smtpClient = smtpClientMod.createSmtpClient({
host: 'smtp.example.com',
port: 587,
secure: false

View File

@ -1,111 +0,0 @@
/**
* SMTP Client - Legacy Compatibility Facade
*
* @deprecated This file provides backward compatibility for the legacy SmtpClient class.
* New code should use the modular implementation from smtpclient/ directory.
*
* Migration Guide:
* - Replace `new SmtpClient(options)` with `createSmtpClient(options)`
* - Import from `'./smtpclient/index.js'` instead of `'./classes.smtp.client.js'`
* - The new API is fully compatible with the legacy interface
*/
import { createSmtpClient } from './smtpclient/index.js';
import type {
ISmtpClientOptions as ModularOptions,
ISmtpSendResult,
IConnectionPoolStatus
} from './smtpclient/interfaces.js';
import type { SmtpClient as ModularSmtpClient } from './smtpclient/smtp-client.js';
import type { Email } from '../core/classes.email.js';
// Re-export the new interfaces for compatibility
export type { ISmtpSendResult, IConnectionPoolStatus };
/**
* Legacy SMTP client options interface
* @deprecated Use ISmtpClientOptions from smtpclient/interfaces.js
*/
export type ISmtpClientOptions = ModularOptions;
/**
* Legacy SMTP Client class - Compatibility Facade
*
* This class wraps the new modular implementation to maintain backward compatibility.
* All method calls are delegated to the new implementation.
*
* @deprecated Use createSmtpClient() factory function instead
*/
export class SmtpClient {
private client: ModularSmtpClient;
constructor(options: ISmtpClientOptions) {
// Create the new modular client
this.client = createSmtpClient(options);
}
/**
* Send an email
*/
public async sendMail(email: Email): Promise<ISmtpSendResult> {
return this.client.sendMail(email);
}
/**
* Test connection to SMTP server
*/
public async verify(): Promise<boolean> {
return this.client.verify();
}
/**
* Check if client is connected
*/
public isConnected(): boolean {
return this.client.isConnected();
}
/**
* Get connection pool status
*/
public getPoolStatus(): IConnectionPoolStatus {
return this.client.getPoolStatus();
}
/**
* Update client options
*/
public updateOptions(newOptions: Partial<ISmtpClientOptions>): void {
return this.client.updateOptions(newOptions);
}
/**
* Close all connections and shutdown client
*/
public async close(): Promise<void> {
return this.client.close();
}
/**
* Add event listener (delegate to internal client)
*/
public on(event: string, listener: (...args: any[]) => void): this {
this.client.on(event, listener);
return this;
}
/**
* Remove event listener (delegate to internal client)
*/
public off(event: string, listener: (...args: any[]) => void): this {
this.client.off(event, listener);
return this;
}
/**
* Emit event (delegate to internal client)
*/
public emit(event: string, ...args: any[]): boolean {
return this.client.emit(event, ...args);
}
}

View File

@ -1,5 +1,4 @@
// Email delivery components
export * from './smtpserver/index.js';
export * from './classes.emailsignjob.js';
export * from './classes.delivery.queue.js';
export * from './classes.delivery.system.js';
@ -17,4 +16,9 @@ export * from './classes.unified.rate.limiter.js';
// SMTP client and configuration
export * from './classes.mta.config.js';
export * from './classes.smtp.client.js';
// Import and export SMTP modules as namespaces to avoid conflicts
import * as smtpClientMod from './smtpclient/index.js';
import * as smtpServerMod from './smtpserver/index.js';
export { smtpClientMod, smtpServerMod };