/** * Notification Types for Ductape SDK * * Defines interfaces for push notifications, email, SMS, and callback operations. */ import { HttpMethods } from '../../types/enums'; import { IActionRequest } from '../../types/productsBuilder.types'; import { IParsedSample } from '../../types/inputs.types'; /** * Supported notification channel types */ export declare enum NotificationChannelType { PUSH = "push", EMAIL = "email", SMS = "sms", CALLBACK = "callback", SLACK = "slack", DISCORD = "discord" } /** * Push notification provider types */ export declare enum PushNotificationProvider { FIREBASE = "firebase", EXPO = "expo" } /** * SMS provider types */ export declare enum SmsProvider { TWILIO = "twilio", NEXMO = "nexmo", PLIVO = "plivo", OTHER = "other" } /** * Email provider types */ export declare enum EmailProvider { SMTP = "smtp", MAILGUN = "mailgun", SENDGRID = "sendgrid", POSTMARK = "postmark", BREVO = "brevo" } /** * Firebase credential configuration */ export interface IFirebaseCredential { type: string; project_id: string; private_key_id: string; private_key: string; client_email: string; client_id: string; auth_uri: string; token_uri: string; auth_provider_x509_cert_url: string; client_x509_cert_url: string; } /** * Push notification handler configuration */ export interface IPushNotificationHandler { type: PushNotificationProvider; credentials?: IFirebaseCredential | object; databaseUrl?: string; /** GCP cloud connection tag. For Firebase, credentials are issued at runtime. */ cloud?: string; /** Must be cloud_connection when cloud is supplied. */ authMode?: 'cloud_connection'; } /** * Push notification input payload */ export interface IPushNotificationInput { /** Device tokens to send notification to */ device_tokens: string[]; /** Notification title (can use template placeholders) */ title?: Record; /** Notification body (can use template placeholders) */ body?: Record; /** Additional data payload */ data?: Record; } /** * Push notification options */ export interface IPushOptions { /** Product tag */ product: string; /** Environment slug */ env: string; /** Notification tag (format: notification_tag:message_tag) */ notification: string; /** Push notification payload */ input: IPushNotificationInput; /** Session token in format: session_tag:jwt_token */ session?: string; /** Cache tag for response caching */ cache?: string; } /** * SMTP email configuration */ export interface ISmtpConfig { host: string; port: string; sender_email: string; auth: { user: string; pass: string; }; secure: boolean; tls?: { rejectUnauthorized: boolean; }; } /** * Mailgun email configuration */ export interface IMailgunConfig { apiKey: string; domain: string; sender_email: string; region?: 'us' | 'eu'; baseUrl?: string; } /** * SendGrid email configuration */ export interface ISendGridConfig { apiKey: string; sender_email: string; } /** * Postmark email configuration */ export interface IPostmarkConfig { serverToken: string; sender_email: string; messageStream?: string; } /** * Brevo (formerly Sendinblue) email configuration */ export interface IBrevoConfig { apiKey: string; sender_email: string; sender_name?: string; } /** * Email handler configuration - supports multiple providers */ export interface IEmailHandler { /** Email provider type */ provider: EmailProvider; /** SMTP configuration (when provider is 'smtp') */ smtp?: ISmtpConfig; /** Mailgun configuration (when provider is 'mailgun') */ mailgun?: IMailgunConfig; /** SendGrid configuration (when provider is 'sendgrid') */ sendgrid?: ISendGridConfig; /** Postmark configuration (when provider is 'postmark') */ postmark?: IPostmarkConfig; /** Brevo configuration (when provider is 'brevo') */ brevo?: IBrevoConfig; } /** * Email input payload */ export interface IEmailInput { /** Email recipients */ recipients: string[]; /** Email subject (can use template placeholders) */ subject?: Record; /** Email template data (can use template placeholders) */ template?: Record; } /** * Email options */ export interface IEmailOptions { /** Product tag */ product: string; /** Environment slug */ env: string; /** Notification tag (format: notification_tag:message_tag) */ notification: string; /** Email payload */ input: IEmailInput; /** Session token in format: session_tag:jwt_token */ session?: string; /** Cache tag for response caching */ cache?: string; } /** * SMS handler configuration */ export interface ISmsHandler { /** SMS provider */ provider: SmsProvider; /** Account SID (for Twilio) */ accountSid?: string; /** Auth token (for Twilio) */ authToken?: string; /** API secret (for Nexmo) */ apiSecret?: string; /** API key (for other providers) */ apiKey?: string; /** Sender phone number or name */ sender: string; } /** * SMS input payload */ export interface ISmsInput { /** Phone number recipients */ recipients: string[]; /** Message body (can use template placeholders) */ body?: Record; } /** * SMS options */ export interface ISmsOptions { /** Product tag */ product: string; /** Environment slug */ env: string; /** Notification tag (format: notification_tag:message_tag) */ notification: string; /** SMS payload */ input: ISmsInput; /** Session token in format: session_tag:jwt_token */ session?: string; /** Cache tag for response caching */ cache?: string; } /** * Callback handler configuration */ export interface ICallbackHandler { url: string; method: HttpMethods; auth?: IActionRequest; } /** * Callback input payload */ export interface ICallbackInput { /** Query parameters */ query?: Record; /** Request headers */ headers?: Record; /** URL parameters */ params?: Record; /** Request body */ body?: Record; } /** * Callback options */ export interface ICallbackOptions { /** Product tag */ product: string; /** Environment slug */ env: string; /** Notification tag (format: notification_tag:message_tag) */ notification: string; /** Callback payload */ input: ICallbackInput; /** Session token in format: session_tag:jwt_token */ session?: string; /** Cache tag for response caching */ cache?: string; } /** * Notification template definition */ export interface INotificationTemplate { /** Template name */ name: string; /** Template tag */ tag: string; /** Template description */ description?: string; /** Push notification template */ push_notification?: { title: string; body: string; data?: Record; }; /** Push notification data placeholders */ push_notification_data?: IParsedSample[]; /** Email template */ email?: { subject: string; template: string; }; /** Email data placeholders */ email_data?: IParsedSample[]; /** Callback configuration */ callback?: IActionRequest; /** Callback data placeholders */ callback_data?: IParsedSample[]; /** SMS template */ sms?: string; /** SMS data placeholders */ sms_data?: IParsedSample[]; } /** * Notification environment configuration */ export interface INotificationEnvConfig { /** Environment slug */ slug: string; /** Push notification handler configuration */ push_notifications?: IPushNotificationHandler; /** Email handler configuration */ emails?: IEmailHandler; /** SMS handler configuration */ sms?: ISmsHandler; /** Callback handler configuration */ callbacks?: ICallbackHandler; } /** * Notification definition */ export interface INotificationDefinition { /** Notification name */ name: string; /** Notification tag */ tag: string; /** Notification description */ description?: string; /** Environment configurations */ envs: INotificationEnvConfig[]; /** Message templates */ messages?: INotificationTemplate[]; } /** * Configuration for NotificationsService */ export interface INotificationsServiceConfig { /** Workspace ID */ workspace_id: string; /** Public key for authentication */ public_key: string; /** User ID */ user_id: string; /** Authentication token */ token: string; /** Environment type */ env_type: string; /** Optional Redis client for caching */ redis_client?: any; default_product?: string; default_env?: string; } /** * Notification send result */ export interface INotificationResult { /** Whether the notification was sent successfully */ success: boolean; /** Channel used for the notification */ channel: NotificationChannelType; /** Unique message/request ID */ messageId?: string; /** Error message if failed */ error?: string; /** Additional metadata */ metadata?: Record; } /** * Multi-channel notification result */ export interface IMultiChannelNotificationResult { /** Overall success (true if at least one channel succeeded) */ success: boolean; /** Results by channel */ channels: { push?: INotificationResult; email?: INotificationResult; sms?: INotificationResult; callback?: INotificationResult; }; } /** * Combined notification request for sending to multiple channels at once */ export interface INotificationOptions { /** Product tag */ product: string; /** Environment slug */ env: string; /** Notification tag (format: notification_tag:message_tag) */ notification: string; /** Push notification payload (optional) */ push_notification?: IPushNotificationInput; /** Email payload (optional) */ email?: IEmailInput; /** SMS payload (optional) */ sms?: ISmsInput; /** Callback payload (optional) */ callback?: ICallbackInput; /** Slack webhook payload */ slack?: { text?: string; blocks?: Record[]; channel?: string; }; /** Discord webhook payload */ discord?: { content?: string; embeds?: Record[]; }; /** Session token in format: session_tag:jwt_token */ session?: string; /** Cache tag for response caching */ cache?: string; } export interface ISlackOptions { product: string; env: string; notification: string; input: { text?: string; blocks?: Record[]; channel?: string; }; session?: string; cache?: string; } export interface IDiscordOptions { product: string; env: string; notification: string; input: { content?: string; embeds?: Record[]; }; session?: string; cache?: string; } /** * Query options for fetching notification message logs (send history) with time filters. * Used by ductape.notifications.getMessages(). */ export interface INotificationMessageLogQuery { product_tag?: string; product_id?: string; env?: string; notification_tag?: string; status?: 'pending' | 'sent' | 'failed' | 'reprocessing'; type?: 'email' | 'push' | 'sms' | 'callback' | 'slack' | 'discord' | 'notification'; process_id?: string; start_date?: string | Date; end_date?: string | Date; page?: number; limit?: number; } /** * Single notification message log entry (send instance for reprocessing). */ export interface INotificationMessageLogEntry { _id?: string; workspace_id: string; product_id: string; product_tag: string; env: string; notification_tag: string; input: Record; status: string; type: string; process_id?: string; error?: string; retries?: number; session?: string; cache?: string; created_at?: string; updated_at?: string; } /** * Response from ductape.notifications.getMessages(). */ export interface INotificationMessageLogResult { items: INotificationMessageLogEntry[]; total: number; page: number; limit: number; hasMore: boolean; }