wip
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Infrastructure Adapter: EmailNotificationAdapter (Stub)
|
||||
*
|
||||
* Handles email notifications.
|
||||
* Currently a stub - to be implemented when email integration is needed.
|
||||
*/
|
||||
|
||||
import type { Notification } from '../../domain/entities/Notification';
|
||||
import type {
|
||||
INotificationGateway,
|
||||
NotificationDeliveryResult
|
||||
} from '../../application/ports/INotificationGateway';
|
||||
import type { NotificationChannel } from '../../domain/value-objects/NotificationChannel';
|
||||
|
||||
export interface EmailAdapterConfig {
|
||||
smtpHost?: string;
|
||||
smtpPort?: number;
|
||||
smtpUser?: string;
|
||||
smtpPassword?: string;
|
||||
fromAddress?: string;
|
||||
}
|
||||
|
||||
export class EmailNotificationAdapter implements INotificationGateway {
|
||||
private readonly channel: NotificationChannel = 'email';
|
||||
private config: EmailAdapterConfig;
|
||||
|
||||
constructor(config: EmailAdapterConfig = {}) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
async send(notification: Notification): Promise<NotificationDeliveryResult> {
|
||||
if (!this.isConfigured()) {
|
||||
return {
|
||||
success: false,
|
||||
channel: this.channel,
|
||||
error: 'Email SMTP not configured',
|
||||
attemptedAt: new Date(),
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: Implement actual email sending
|
||||
// For now, this is a stub that logs and returns success
|
||||
console.log(`[Email Stub] Would send email:`, {
|
||||
to: notification.recipientId, // Would need to resolve to actual email
|
||||
subject: notification.title,
|
||||
body: notification.body,
|
||||
type: notification.type,
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
channel: this.channel,
|
||||
externalId: `email-stub-${notification.id}`,
|
||||
attemptedAt: new Date(),
|
||||
};
|
||||
}
|
||||
|
||||
supportsChannel(channel: NotificationChannel): boolean {
|
||||
return channel === this.channel;
|
||||
}
|
||||
|
||||
isConfigured(): boolean {
|
||||
return !!(this.config.smtpHost && this.config.fromAddress);
|
||||
}
|
||||
|
||||
getChannel(): NotificationChannel {
|
||||
return this.channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update SMTP configuration
|
||||
*/
|
||||
configure(config: EmailAdapterConfig): void {
|
||||
this.config = { ...this.config, ...config };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user