|
| 1 | +export type NotificationChannel = "email" | "sms" | "push" | "in_app"; |
| 2 | + |
| 3 | +export type NotificationPriority = "low" | "normal" | "high" | "urgent"; |
| 4 | + |
| 5 | +/** |
| 6 | + * A notification recipient. |
| 7 | + */ |
| 8 | +export type NotificationRecipient = { |
| 9 | + userId: string; |
| 10 | + channels?: NotificationChannel[]; |
| 11 | +}; |
| 12 | + |
| 13 | +export type NotificationTemplate = { |
| 14 | + id: string; |
| 15 | + name: string; |
| 16 | + subject?: string; |
| 17 | + body: string; |
| 18 | + channel: NotificationChannel; |
| 19 | +}; |
| 20 | + |
| 21 | +export type SendNotificationParams = { |
| 22 | + recipientId: string; |
| 23 | + templateId?: string; |
| 24 | + channel: NotificationChannel; |
| 25 | + subject?: string; |
| 26 | + body: string; |
| 27 | + priority?: NotificationPriority; |
| 28 | + metadata?: Record<string, string | number | boolean>; |
| 29 | + scheduledAt?: string; |
| 30 | +}; |
| 31 | + |
| 32 | +export type BulkNotificationParams = { |
| 33 | + recipientIds: string[]; |
| 34 | + templateId: string; |
| 35 | + channel: NotificationChannel; |
| 36 | + variables?: Record<string, string>; |
| 37 | + priority?: NotificationPriority; |
| 38 | +}; |
| 39 | + |
| 40 | +export type NotificationResult = { |
| 41 | + id: string; |
| 42 | + status: "queued" | "sent" | "delivered" | "failed"; |
| 43 | + sentAt?: string; |
| 44 | + error?: string; |
| 45 | +}; |
| 46 | + |
| 47 | +export type NotificationPreferences = { |
| 48 | + userId: string; |
| 49 | + enabledChannels: NotificationChannel[]; |
| 50 | + quietHoursStart?: string; |
| 51 | + quietHoursEnd?: string; |
| 52 | + unsubscribedTopics: string[]; |
| 53 | +}; |
| 54 | + |
| 55 | +export type ListNotificationsParams = { |
| 56 | + status?: "queued" | "sent" | "delivered" | "failed"; |
| 57 | + channel?: NotificationChannel; |
| 58 | + limit?: number; |
| 59 | + skip?: number; |
| 60 | +}; |
| 61 | + |
| 62 | +export interface NotificationsModule { |
| 63 | + send(params: SendNotificationParams): Promise<NotificationResult>; |
| 64 | + |
| 65 | + sendBulk(params: BulkNotificationParams): Promise<NotificationResult[]>; |
| 66 | + |
| 67 | + getPreferences(userId: string): Promise<NotificationPreferences>; |
| 68 | + |
| 69 | + updatePreferences( |
| 70 | + userId: string, |
| 71 | + preferences: Partial<Omit<NotificationPreferences, "userId">> |
| 72 | + ): Promise<NotificationPreferences>; |
| 73 | + |
| 74 | + list(params?: ListNotificationsParams): Promise<NotificationResult[]>; |
| 75 | + |
| 76 | + /** |
| 77 | + * Cancels a scheduled notification before it is sent. |
| 78 | + * |
| 79 | + * @param notificationId - The ID of the notification to cancel. |
| 80 | + * @returns Promise resolving to `true` if the notification was successfully cancelled. |
| 81 | + */ |
| 82 | + cancel(notificationId: string): Promise<boolean>; |
| 83 | +} |
0 commit comments