Files
gridpilot.gg/core/notifications/application/ports/NotificationGateway.ts
2025-12-20 12:22:48 +01:00

68 lines
1.7 KiB
TypeScript

/**
* Application Port: INotificationGateway
*
* Defines the contract for sending notifications through external channels.
* Implementations (adapters) handle the actual delivery mechanism.
*/
import type { Notification } from '../../domain/entities/Notification';
import type { NotificationChannel } from '../../domain/types/NotificationTypes';
export interface NotificationDeliveryResult {
success: boolean;
channel: NotificationChannel;
/** External message ID (e.g., Discord message ID, email ID) */
externalId?: string;
/** Error message if delivery failed */
error?: string;
/** Timestamp of delivery attempt */
attemptedAt: Date;
}
export interface NotificationGateway {
/**
* Send a notification through this gateway's channel
*/
send(notification: Notification): Promise<NotificationDeliveryResult>;
/**
* Check if this gateway supports the given channel
*/
supportsChannel(channel: NotificationChannel): boolean;
/**
* Check if the gateway is configured and ready to send
*/
isConfigured(): boolean;
/**
* Get the channel this gateway handles
*/
getChannel(): NotificationChannel;
}
/**
* Registry for notification gateways
* Allows routing notifications to the appropriate gateway based on channel
*/
export interface NotificationGatewayRegistry {
/**
* Register a gateway for a channel
*/
register(gateway: NotificationGateway): void;
/**
* Get gateway for a specific channel
*/
getGateway(channel: NotificationChannel): NotificationGateway | null;
/**
* Get all registered gateways
*/
getAllGateways(): NotificationGateway[];
/**
* Send notification through appropriate gateway
*/
send(notification: Notification): Promise<NotificationDeliveryResult>;
}