/** * NotificationsService - Main Notifications Service Class * * Provides a unified interface for sending notifications through multiple channels: * - Push notifications (Firebase, Expo) * - Email (SMTP) * - SMS (Twilio, Nexmo, Plivo) * - Callbacks (HTTP webhooks) */ import { IDispatchResult } from '../types/processor.types'; import { INotificationsServiceConfig, INotificationResult, IMultiChannelNotificationResult, IPushOptions, IEmailOptions, ISmsOptions, ICallbackOptions, INotificationOptions } from './types'; /** * NotificationsService - Send notifications through push, email, SMS, and callbacks * * @example * ```typescript * const notifications = new NotificationsService({ * workspace_id: 'ws-123', * public_key: 'pk-123', * user_id: 'user-123', * token: 'token-123', * env_type: 'production', * }); * * // Send push notification * await notifications.push({ * product: 'my-product', * env: 'production', * notification: 'alerts:welcome-message', * input: { * device_tokens: ['token1', 'token2'], * title: { name: 'John' }, * body: { message: 'Welcome!' }, * }, * }); * * // Send email * await notifications.email({ * product: 'my-product', * env: 'production', * notification: 'emails:order-confirmation', * input: { * recipients: ['user@example.com'], * subject: { orderId: '12345' }, * template: { orderDetails: '...' }, * }, * }); * ``` */ export declare class NotificationsService { /** Service configuration */ private config; /** ProductBuilder instances cache (keyed by product tag) */ private productBuilders; /** LogService instance for logging operations */ private logService; /** Current product ID for logging */ private productId; private _privateKey; /** Cache manager for 3-tier caching */ private cacheManager; /** Private keys per product for cache encryption */ private privateKeys; /** Local cache for cache configurations to avoid repeated API calls */ private cacheConfigCache; private readonly productEnv; /** * Create a new NotificationsService instance * @param config - Configuration for authentication and workspace context */ constructor(config: INotificationsServiceConfig & { private_key: string; }); private resolvePE; /** * Create a new ProductBuilder instance */ private createNewProductBuilder; private getOrCreateProductBuilder; /** * Single bootstrap call for send paths: product + notification + message + private_key. */ private ensureNotificationBootstrap; private flushLogs; /** * Get or create a ProductBuilder instance for the given product tag */ private getProductBuilder; /** * Initialize logging service */ private initializeLogService; /** * Validate cache tag exists in product and return cache configuration * Uses local in-memory cache to avoid repeated API calls (5 minute TTL) */ private validateCache; /** * Create a new ProcessorService instance */ private createNewProcessor; /** * Parse notification tag to extract notification and message tags * Format: notification_tag:message_tag */ private parseNotificationTag; /** * Build INotificationRequest from channel-specific input */ private buildNotificationRequest; /** * Send a push notification * * @param options - Push notification options * @returns Notification result * * @example * ```typescript * const result = await notifications.push({ * product: 'my-product', * env: 'production', * notification: 'alerts:welcome', * input: { * device_tokens: ['device-token-1', 'device-token-2'], * title: { name: 'John' }, * body: { message: 'Welcome to our app!' }, * data: { action: 'open_home' }, * }, * }); * ``` */ push(options: IPushOptions): Promise; /** * Send an email * * @param options - Email options * @returns Notification result * * @example * ```typescript * const result = await notifications.email({ * product: 'my-product', * env: 'production', * notification: 'emails:order-confirmation', * input: { * recipients: ['user@example.com', 'admin@example.com'], * subject: { orderId: '12345' }, * template: { * customerName: 'John Doe', * orderTotal: '$99.99', * }, * }, * }); * ``` */ email(options: IEmailOptions): Promise; /** * Send an SMS * * @param options - SMS options * @returns Notification result * * @example * ```typescript * const result = await notifications.sms({ * product: 'my-product', * env: 'production', * notification: 'sms:verification', * input: { * recipients: ['+1234567890', '+0987654321'], * body: { code: '123456' }, * }, * }); * ``` */ sms(options: ISmsOptions): Promise; /** * Send a callback (HTTP webhook) * * @param options - Callback options * @returns Notification result * * @example * ```typescript * const result = await notifications.callback({ * product: 'my-product', * env: 'production', * notification: 'webhooks:order-created', * input: { * body: { * orderId: '12345', * status: 'created', * timestamp: Date.now(), * }, * headers: { * 'X-Custom-Header': 'value', * }, * }, * }); * ``` */ callback(options: ICallbackOptions): Promise; /** * Send notifications to multiple channels at once * * @param options - Multi-channel notification options * @returns Results for each channel * * @example * ```typescript * const result = await notifications.send({ * product: 'my-product', * env: 'production', * notification: 'alerts:order-placed', * push_notification: { * device_tokens: ['token1'], * title: { order: 'New Order' }, * body: { message: 'Order #12345 placed' }, * }, * email: { * recipients: ['user@example.com'], * subject: { orderId: '12345' }, * template: { orderDetails: '...' }, * }, * sms: { * recipients: ['+1234567890'], * body: { message: 'Order #12345 placed' }, * }, * }); * ``` */ send(options: INotificationOptions): Promise; /** * Schedule a notification to be sent at a later time * * @param options - Notification options with scheduling * @returns Dispatch result with job ID * * @example * ```typescript * const result = await notifications.dispatch({ * product: 'my-product', * env: 'production', * notification: 'reminders:payment-due', * input: { * push_notification: { * device_tokens: ['token1'], * title: { name: 'Payment' }, * body: { message: 'Your payment is due' }, * }, * }, * schedule: { * start_at: Date.now() + 86400000, // 24 hours from now * }, * }); * ``` */ dispatch(options: INotificationOptions & { schedule: { start_at?: number | string; cron?: string; every?: number; limit?: number; endDate?: number | string; tz?: string; }; retries?: number; }): Promise; } /** * Factory function for creating NotificationsService instances */ export declare function notificationsService(config: INotificationsServiceConfig & { private_key: string; }): NotificationsService; export default NotificationsService;