/** * NotificationService - Singleton Notification Manager * * @description Manages notification delivery for the entire application using a singleton pattern. * This service wraps @plyaz/notifications and provides a centralized way to initialize and access * notification capabilities across all domains (transactional, marketing, system alerts, etc.). * * **Architecture:** * - Uses `NotificationService` from @plyaz/notifications which supports multi-provider setup * - Supports email (Infobip primary, SendGrid fallback), SMS, and push notifications * - Automatic failover between providers based on health status * - Event-driven architecture for tracking delivery, opens, clicks * - **Proxy-based method forwarding**: All methods from the underlying service are * automatically available with error handling - no manual wrapping needed * * **Provider Configuration:** * - **Infobip**: Primary email provider (unified omnichannel platform) * - **SendGrid**: Fallback email provider for transactional emails * * **Required Environment Variables (Infobip):** * - INFOBIP_API_KEY: Your Infobip API key * - INFOBIP_BASE_URL: Infobip API base URL * - FROM_EMAIL: Default sender email address * * **Required Environment Variables (SendGrid):** * - SENDGRID_API_KEY: Your SendGrid API key * - FROM_EMAIL: Default sender email address * * @example Using with Core.initialize() (Recommended) * ```typescript * import { Core } from '@plyaz/core'; * * await Core.initialize({ * notifications: { * providers: { * email: [infobipAdapter, sendGridAdapter], * sms: [], * push: [], * }, * events: { * onSent: (event) => console.log('Notification sent:', event), * onFailed: (event) => console.error('Notification failed:', event), * }, * }, * }); * * // Access via Core.notifications - all methods automatically available * await Core.notifications.sendEmail({ * recipientId: 'user-123', * to: 'user@example.com', * templateId: 'welcome', * templateData: { userName: 'John' }, * }); * ``` * * @module services */ import { NotificationService as NotificationServiceImpl } from '@plyaz/notifications'; import type { CoreNotificationConfig, CoreNotificationServiceInstance } from '@plyaz/types/core'; export type { CoreNotificationConfig } from '@plyaz/types/core'; /** * NotificationService - Singleton Notification Manager with Proxy-based method forwarding * * Provides centralized notification management for all domains. * Uses @plyaz/notifications under the hood with configurable providers and templates. * * All methods from the underlying NotificationServiceImpl are automatically available * via Proxy - when new methods are added to @plyaz/notifications, they're instantly * accessible here with automatic error handling. */ export declare class NotificationService implements CoreNotificationServiceInstance { private notificationService; private config; private initialized; private constructor(); /** * Emits a notification error event via CoreEventManager. * Called when notification operations fail to integrate with global error handling. */ private emitNotificationError; /** * Creates merged event handlers that emit to CoreEventManager. * Merges Core's internal handlers with user-provided handlers. * * @param userHandlers - User-provided event handlers from config * @returns Merged handlers with Core event emission + user handlers */ private static createMergedEventHandlers; /** * Gets the singleton instance of NotificationService */ static getInstance(): NotificationService; /** * Checks if the notification service has been initialized */ static isInitialized(): boolean; /** * Resets the notification service by clearing the singleton instance */ static reset(): Promise; /** * Initializes the notification service * * @param config - Notification service configuration * @returns The initialized NotificationService instance */ static initialize(config: CoreNotificationConfig): Promise; /** * Gets the raw underlying notification service instance without error handling wrapper. * Use this only if you need direct access to the underlying service. * * @returns The raw NotificationService instance from @plyaz/notifications * @throws {NotificationsPackageError} When notifications is not initialized */ private getRawNotifications; /** * Gets the notification service with automatic error handling. * All method calls are wrapped with try/catch and emit error events on failure. * Any method added to @plyaz/notifications will be automatically available. * * @example * ```typescript * const notifications = NotificationService.getInstance().getNotifications(); * await notifications.sendEmail({ to: 'user@example.com', templateId: 'welcome' }); * await notifications.sendSMS({ to: '+1234567890', message: 'Hello!' }); * ``` * * @returns NotificationServiceImpl with automatic error handling */ getNotifications(): NotificationServiceImpl; /** * Performs a health check on the notification service. * This method has special handling to transform the response format. */ healthCheck(): Promise<{ isHealthy: boolean; providers?: unknown[]; error?: string; }>; /** * Gets the current configuration */ getConfig(): CoreNotificationConfig | null; /** * Closes the notification service and cleans up resources */ close(): Promise; /** * Creates a dedicated notification service instance (NOT the singleton) * * Use this when you need an isolated notification service with its own configuration. * * @param config - Notification service configuration * @returns Promise that resolves to a new dedicated NotificationService instance */ static createInstance(config: CoreNotificationConfig): Promise; } /** Type alias for NotificationService instance (use for type-only imports to avoid bundling) */ export type NotificationServiceInstance = NotificationService; //# sourceMappingURL=NotificationService.d.ts.map