-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnotification-service.ts
More file actions
78 lines (71 loc) · 2.49 KB
/
Copy pathnotification-service.ts
File metadata and controls
78 lines (71 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
/**
* INotificationService - Notification Service Contract
*
* Defines the interface for sending notifications in ObjectStack.
* Concrete implementations (Email, Push, SMS, Slack, etc.)
* should implement this interface.
*
* Follows Dependency Inversion Principle - plugins depend on this interface,
* not on concrete notification provider implementations.
*
* Aligned with CoreServiceName 'notification' in core-services.zod.ts.
*/
/**
* Supported notification delivery channels
*
* ⚠️ PARTIALLY ENFORCED — mirrors `NotificationChannelSchema`
* (system/notification.zod.ts); the delivery channels actually registered by
* `service-messaging` are `inbox`, `email`, and `sms` only (#3197). Messages
* addressed to an unregistered channel are dead-lettered, not delivered.
*/
export type NotificationChannel = 'email' | 'sms' | 'push' | 'in-app' | 'slack' | 'teams' | 'webhook';
/**
* A notification message to be sent
*/
export interface NotificationMessage {
/** Notification channel to use */
channel: NotificationChannel;
/** Recipient identifier (email, phone, user ID, etc.) */
to: string | string[];
/** Notification subject/title */
subject?: string;
/** Notification body content */
body: string;
/** Template identifier (if using a pre-defined template) */
templateId?: string;
/** Template variable values */
templateData?: Record<string, unknown>;
/** Additional metadata */
metadata?: Record<string, unknown>;
}
/**
* Result of sending a notification
*/
export interface NotificationResult {
/** Whether the notification was sent successfully */
success: boolean;
/** Unique identifier for tracking */
messageId?: string;
/** Error message if sending failed */
error?: string;
}
export interface INotificationService {
/**
* Send a notification
* @param message - The notification message to send
* @returns Result indicating success or failure
*/
send(message: NotificationMessage): Promise<NotificationResult>;
/**
* Send multiple notifications in a batch
* @param messages - Array of notification messages
* @returns Array of results for each message
*/
sendBatch?(messages: NotificationMessage[]): Promise<NotificationResult[]>;
/**
* List available notification channels
* @returns Array of supported channel names
*/
getChannels?(): NotificationChannel[];
}