@vynelix/vynemit-core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +400 -0
- package/dist/index.d.mts +335 -0
- package/dist/index.d.ts +335 -0
- package/dist/index.js +829 -0
- package/dist/index.mjs +799 -0
- package/package.json +67 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
type ChannelType = 'inapp' | 'push' | 'email' | 'sms' | 'webhook';
|
|
2
|
+
type NotificationStatus = 'pending' | 'sent' | 'delivered' | 'failed' | 'read';
|
|
3
|
+
type NotificationPriority = 'low' | 'normal' | 'high' | 'urgent';
|
|
4
|
+
type DeliveryStatus = 'pending' | 'sent' | 'delivered' | 'failed' | 'bounced';
|
|
5
|
+
type DigestFrequency = 'hourly' | 'daily' | 'weekly';
|
|
6
|
+
type ChannelFrequency = 'realtime' | 'batched' | 'digest';
|
|
7
|
+
interface NotificationAction {
|
|
8
|
+
id: string;
|
|
9
|
+
label: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
handler?: string;
|
|
12
|
+
}
|
|
13
|
+
interface Notification {
|
|
14
|
+
id: string;
|
|
15
|
+
type: string;
|
|
16
|
+
title: string;
|
|
17
|
+
body: string;
|
|
18
|
+
text?: string;
|
|
19
|
+
html?: string;
|
|
20
|
+
data?: Record<string, unknown>;
|
|
21
|
+
userId: string;
|
|
22
|
+
groupId?: string;
|
|
23
|
+
priority: NotificationPriority;
|
|
24
|
+
category?: string;
|
|
25
|
+
status: NotificationStatus;
|
|
26
|
+
readAt?: Date;
|
|
27
|
+
createdAt: Date;
|
|
28
|
+
scheduledFor?: Date;
|
|
29
|
+
expiresAt?: Date;
|
|
30
|
+
channels: ChannelType[];
|
|
31
|
+
actions?: NotificationAction[];
|
|
32
|
+
}
|
|
33
|
+
interface EmailNotification extends Notification {
|
|
34
|
+
data: {
|
|
35
|
+
email?: string;
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
interface SmsNotification extends Notification {
|
|
40
|
+
data: {
|
|
41
|
+
phoneNumber?: string;
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
interface PushNotification extends Notification {
|
|
46
|
+
data: {
|
|
47
|
+
deviceToken?: string;
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
interface InAppNotification extends Notification {
|
|
52
|
+
data?: Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
interface NotificationInput {
|
|
55
|
+
type: string;
|
|
56
|
+
title: string;
|
|
57
|
+
body: string;
|
|
58
|
+
text?: string;
|
|
59
|
+
html?: string;
|
|
60
|
+
userId: string;
|
|
61
|
+
groupId?: string;
|
|
62
|
+
data?: Record<string, unknown>;
|
|
63
|
+
priority?: NotificationPriority;
|
|
64
|
+
category?: string;
|
|
65
|
+
channels?: ChannelType[];
|
|
66
|
+
scheduledFor?: Date;
|
|
67
|
+
expiresAt?: Date;
|
|
68
|
+
actions?: NotificationAction[];
|
|
69
|
+
template?: string;
|
|
70
|
+
}
|
|
71
|
+
interface NotificationMulticastInput {
|
|
72
|
+
type: string;
|
|
73
|
+
title: string;
|
|
74
|
+
body: string;
|
|
75
|
+
text?: string;
|
|
76
|
+
html?: string;
|
|
77
|
+
userIds: string[];
|
|
78
|
+
data?: Record<string, unknown>;
|
|
79
|
+
priority?: NotificationPriority;
|
|
80
|
+
category?: string;
|
|
81
|
+
channels?: ChannelType[];
|
|
82
|
+
scheduledFor?: Date;
|
|
83
|
+
expiresAt?: Date;
|
|
84
|
+
actions?: NotificationAction[];
|
|
85
|
+
template?: string;
|
|
86
|
+
}
|
|
87
|
+
interface NotificationFilters {
|
|
88
|
+
status?: NotificationStatus | NotificationStatus[];
|
|
89
|
+
type?: string | string[];
|
|
90
|
+
category?: string | string[];
|
|
91
|
+
channels?: ChannelType | ChannelType[];
|
|
92
|
+
priority?: NotificationPriority | NotificationPriority[];
|
|
93
|
+
startDate?: Date;
|
|
94
|
+
endDate?: Date;
|
|
95
|
+
limit?: number;
|
|
96
|
+
offset?: number;
|
|
97
|
+
sortBy?: 'createdAt' | 'priority' | 'readAt';
|
|
98
|
+
sortOrder?: 'asc' | 'desc';
|
|
99
|
+
}
|
|
100
|
+
interface ChannelPreferences {
|
|
101
|
+
enabled: boolean;
|
|
102
|
+
categories?: string[];
|
|
103
|
+
quietHours?: QuietHours;
|
|
104
|
+
frequency?: ChannelFrequency;
|
|
105
|
+
}
|
|
106
|
+
interface QuietHours {
|
|
107
|
+
start: string;
|
|
108
|
+
end: string;
|
|
109
|
+
timezone?: string;
|
|
110
|
+
}
|
|
111
|
+
interface NotificationPreferences {
|
|
112
|
+
userId: string;
|
|
113
|
+
channels: {
|
|
114
|
+
[key in ChannelType]?: ChannelPreferences;
|
|
115
|
+
};
|
|
116
|
+
globalMute?: boolean;
|
|
117
|
+
updatedAt?: Date;
|
|
118
|
+
data?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
interface DeliveryReceipt {
|
|
121
|
+
notificationId: string;
|
|
122
|
+
channel: ChannelType;
|
|
123
|
+
status: DeliveryStatus;
|
|
124
|
+
attempts: number;
|
|
125
|
+
lastAttempt: Date;
|
|
126
|
+
nextRetry?: Date;
|
|
127
|
+
error?: string;
|
|
128
|
+
metadata?: Record<string, unknown>;
|
|
129
|
+
}
|
|
130
|
+
interface NotificationTemplate {
|
|
131
|
+
id: string;
|
|
132
|
+
type: string;
|
|
133
|
+
defaults: {
|
|
134
|
+
title: string | ((data: any) => string);
|
|
135
|
+
body: string | ((data: any) => string);
|
|
136
|
+
text?: string | ((data: any) => string);
|
|
137
|
+
html?: string | ((data: any) => string);
|
|
138
|
+
channels: ChannelType[];
|
|
139
|
+
priority: NotificationPriority;
|
|
140
|
+
category?: string;
|
|
141
|
+
expiresIn?: number;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
interface DigestConfig {
|
|
145
|
+
userId: string;
|
|
146
|
+
frequency: DigestFrequency;
|
|
147
|
+
channels: ChannelType[];
|
|
148
|
+
categories?: string[];
|
|
149
|
+
enabled: boolean;
|
|
150
|
+
}
|
|
151
|
+
interface NotificationMiddleware {
|
|
152
|
+
name: string;
|
|
153
|
+
beforeSend?(notification: Notification): Promise<Notification | null>;
|
|
154
|
+
afterSend?(notification: Notification): Promise<void>;
|
|
155
|
+
onError?(error: Error, notification: Notification): Promise<void>;
|
|
156
|
+
}
|
|
157
|
+
interface StorageAdapter {
|
|
158
|
+
initialize?(): Promise<void>;
|
|
159
|
+
save(notification: Notification): Promise<void>;
|
|
160
|
+
saveBatch(notifications: Notification[]): Promise<void>;
|
|
161
|
+
findById(id: string): Promise<Notification | null>;
|
|
162
|
+
findByUser(userId: string, filters?: NotificationFilters): Promise<Notification[]>;
|
|
163
|
+
countUnread(userId: string): Promise<number>;
|
|
164
|
+
markAsRead(id: string): Promise<void>;
|
|
165
|
+
markAllAsRead(userId: string): Promise<void>;
|
|
166
|
+
markAsUnread(id: string): Promise<void>;
|
|
167
|
+
markAllAsUnread(userId: string): Promise<void>;
|
|
168
|
+
delete(id: string): Promise<void>;
|
|
169
|
+
getPreferences(userId: string): Promise<NotificationPreferences>;
|
|
170
|
+
savePreferences(userId: string, prefs: NotificationPreferences): Promise<void>;
|
|
171
|
+
deleteExpired(): Promise<number>;
|
|
172
|
+
saveReceipt?(receipt: DeliveryReceipt): Promise<void>;
|
|
173
|
+
getReceipts?(notificationId: string): Promise<DeliveryReceipt[]>;
|
|
174
|
+
}
|
|
175
|
+
interface TransportAdapter {
|
|
176
|
+
name: ChannelType;
|
|
177
|
+
send(notification: Notification, preferences: NotificationPreferences): Promise<DeliveryReceipt>;
|
|
178
|
+
sendBatch?(notifications: Notification[], preferences: NotificationPreferences): Promise<DeliveryReceipt[]>;
|
|
179
|
+
sendMulticast?(notifications: Notification[], preferences: NotificationPreferences): Promise<DeliveryReceipt[]>;
|
|
180
|
+
canSend(notification: Notification, preferences: NotificationPreferences): boolean;
|
|
181
|
+
healthCheck?(): Promise<boolean>;
|
|
182
|
+
}
|
|
183
|
+
interface QueueAdapter {
|
|
184
|
+
enqueue(notification: Notification): Promise<void>;
|
|
185
|
+
enqueueBatch(notifications: Notification[]): Promise<void>;
|
|
186
|
+
enqueueDelayed(notification: Notification, delay: number): Promise<void>;
|
|
187
|
+
dequeue(): Promise<Notification | null>;
|
|
188
|
+
dequeueBatch(count: number): Promise<Notification[]>;
|
|
189
|
+
getQueueSize(): Promise<number>;
|
|
190
|
+
clear(): Promise<void>;
|
|
191
|
+
start(): Promise<void>;
|
|
192
|
+
stop(): Promise<void>;
|
|
193
|
+
}
|
|
194
|
+
interface NotificationConfig {
|
|
195
|
+
storage: StorageAdapter;
|
|
196
|
+
transports: TransportAdapter[];
|
|
197
|
+
queue?: QueueAdapter;
|
|
198
|
+
workers?: {
|
|
199
|
+
enabled?: boolean;
|
|
200
|
+
concurrency?: number;
|
|
201
|
+
pollInterval?: number;
|
|
202
|
+
};
|
|
203
|
+
retry?: {
|
|
204
|
+
maxAttempts?: number;
|
|
205
|
+
backoff?: 'linear' | 'exponential';
|
|
206
|
+
initialDelay?: number;
|
|
207
|
+
maxDelay?: number;
|
|
208
|
+
};
|
|
209
|
+
cleanup?: {
|
|
210
|
+
enabled?: boolean;
|
|
211
|
+
interval?: number;
|
|
212
|
+
retentionDays?: number;
|
|
213
|
+
};
|
|
214
|
+
middleware?: NotificationMiddleware[];
|
|
215
|
+
}
|
|
216
|
+
type Unsubscribe = () => void;
|
|
217
|
+
interface NotificationEvent {
|
|
218
|
+
type: 'sent' | 'delivered' | 'read' | 'unread' | 'failed';
|
|
219
|
+
notification: Notification;
|
|
220
|
+
timestamp: Date;
|
|
221
|
+
}
|
|
222
|
+
interface NotificationStats {
|
|
223
|
+
total: number;
|
|
224
|
+
unread: number;
|
|
225
|
+
byStatus: Record<NotificationStatus, number>;
|
|
226
|
+
byChannel: Record<ChannelType, number>;
|
|
227
|
+
byPriority: Record<NotificationPriority, number>;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
declare class NotificationCenter {
|
|
231
|
+
private config;
|
|
232
|
+
private storage;
|
|
233
|
+
private transports;
|
|
234
|
+
private queue?;
|
|
235
|
+
private templates;
|
|
236
|
+
private middleware;
|
|
237
|
+
private subscribers;
|
|
238
|
+
private eventSubscribers;
|
|
239
|
+
private unreadSubscribers;
|
|
240
|
+
private isRunning;
|
|
241
|
+
private workerInterval?;
|
|
242
|
+
constructor(config: NotificationConfig);
|
|
243
|
+
send(input: NotificationInput): Promise<Notification>;
|
|
244
|
+
sendBatch(inputs: NotificationInput[]): Promise<Notification[]>;
|
|
245
|
+
sendMulticast(input: NotificationMulticastInput): Promise<Notification[]>;
|
|
246
|
+
schedule(input: NotificationInput, when: Date): Promise<string>;
|
|
247
|
+
getForUser(userId: string, filters?: NotificationFilters): Promise<Notification[]>;
|
|
248
|
+
getUnreadCount(userId: string): Promise<number>;
|
|
249
|
+
getById(id: string): Promise<Notification | null>;
|
|
250
|
+
getStats(userId: string): Promise<NotificationStats>;
|
|
251
|
+
markAsRead(notificationId: string): Promise<void>;
|
|
252
|
+
markAllAsRead(userId: string): Promise<void>;
|
|
253
|
+
markAsUnread(notificationId: string): Promise<void>;
|
|
254
|
+
markAllAsUnread(userId: string): Promise<void>;
|
|
255
|
+
delete(notificationId: string): Promise<void>;
|
|
256
|
+
deleteAll(userId: string): Promise<void>;
|
|
257
|
+
getPreferences(userId: string): Promise<NotificationPreferences>;
|
|
258
|
+
updatePreferences(userId: string, prefs: Partial<NotificationPreferences>): Promise<void>;
|
|
259
|
+
registerTemplate(template: NotificationTemplate): void;
|
|
260
|
+
getTemplate(id: string): NotificationTemplate | undefined;
|
|
261
|
+
unregisterTemplate(id: string): void;
|
|
262
|
+
enableDigest(userId: string, config: DigestConfig): Promise<void>;
|
|
263
|
+
disableDigest(userId: string): Promise<void>;
|
|
264
|
+
getDigestConfig(userId: string): Promise<DigestConfig | null>;
|
|
265
|
+
getDeliveryStatus(notificationId: string): Promise<DeliveryReceipt[]>;
|
|
266
|
+
retryFailed(notificationId: string, channel?: ChannelType): Promise<void>;
|
|
267
|
+
subscribe(userId: string, callback: (notification: Notification) => void): Unsubscribe;
|
|
268
|
+
subscribeToEvents(userId: string, callback: (event: NotificationEvent) => void): Unsubscribe;
|
|
269
|
+
onUnreadCountChange(userId: string, callback: (count: number, userId: string) => void): Unsubscribe;
|
|
270
|
+
use(middleware: NotificationMiddleware): void;
|
|
271
|
+
removeMiddleware(name: string): void;
|
|
272
|
+
start(): Promise<void>;
|
|
273
|
+
stop(): Promise<void>;
|
|
274
|
+
healthCheck(): Promise<Record<string, boolean>>;
|
|
275
|
+
private buildNotification;
|
|
276
|
+
private sendNow;
|
|
277
|
+
private castNotification;
|
|
278
|
+
private startWorker;
|
|
279
|
+
private startCleanup;
|
|
280
|
+
private applyBeforeSendMiddleware;
|
|
281
|
+
private applyAfterSendMiddleware;
|
|
282
|
+
private applyErrorMiddleware;
|
|
283
|
+
private notifySubscribers;
|
|
284
|
+
private notifyEventSubscribers;
|
|
285
|
+
private notifyUnreadSubscribers;
|
|
286
|
+
private generateId;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
declare class ConsoleTransportAdapter implements TransportAdapter {
|
|
290
|
+
name: ChannelType;
|
|
291
|
+
constructor(name?: ChannelType);
|
|
292
|
+
send(notification: Notification): Promise<DeliveryReceipt>;
|
|
293
|
+
canSend(notification: Notification, preferences: NotificationPreferences): boolean;
|
|
294
|
+
healthCheck(): Promise<boolean>;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
declare class MemoryQueueAdapter implements QueueAdapter {
|
|
298
|
+
private queue;
|
|
299
|
+
private delayedQueue;
|
|
300
|
+
protected isRunning: boolean;
|
|
301
|
+
private checkInterval?;
|
|
302
|
+
enqueue(notification: Notification): Promise<void>;
|
|
303
|
+
enqueueBatch(notifications: Notification[]): Promise<void>;
|
|
304
|
+
enqueueDelayed(notification: Notification, delay: number): Promise<void>;
|
|
305
|
+
dequeue(): Promise<Notification | null>;
|
|
306
|
+
dequeueBatch(count: number): Promise<Notification[]>;
|
|
307
|
+
getQueueSize(): Promise<number>;
|
|
308
|
+
clear(): Promise<void>;
|
|
309
|
+
start(): Promise<void>;
|
|
310
|
+
stop(): Promise<void>;
|
|
311
|
+
private processDelayed;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
declare class MemoryStorageAdapter implements StorageAdapter {
|
|
315
|
+
private notifications;
|
|
316
|
+
private preferences;
|
|
317
|
+
private receipts;
|
|
318
|
+
save(notification: Notification): Promise<void>;
|
|
319
|
+
saveBatch(notifications: Notification[]): Promise<void>;
|
|
320
|
+
findById(id: string): Promise<Notification | null>;
|
|
321
|
+
findByUser(userId: string, filters?: NotificationFilters): Promise<Notification[]>;
|
|
322
|
+
countUnread(userId: string): Promise<number>;
|
|
323
|
+
markAsRead(id: string): Promise<void>;
|
|
324
|
+
markAllAsRead(userId: string): Promise<void>;
|
|
325
|
+
markAsUnread(id: string): Promise<void>;
|
|
326
|
+
markAllAsUnread(userId: string): Promise<void>;
|
|
327
|
+
delete(id: string): Promise<void>;
|
|
328
|
+
getPreferences(userId: string): Promise<NotificationPreferences>;
|
|
329
|
+
savePreferences(userId: string, prefs: NotificationPreferences): Promise<void>;
|
|
330
|
+
deleteExpired(): Promise<number>;
|
|
331
|
+
saveReceipt(receipt: DeliveryReceipt): Promise<void>;
|
|
332
|
+
getReceipts(notificationId: string): Promise<DeliveryReceipt[]>;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export { ChannelFrequency, ChannelPreferences, ChannelType, ConsoleTransportAdapter, DeliveryReceipt, DeliveryStatus, DigestConfig, DigestFrequency, EmailNotification, InAppNotification, MemoryQueueAdapter, MemoryStorageAdapter, Notification, NotificationAction, NotificationCenter, NotificationConfig, NotificationEvent, NotificationFilters, NotificationInput, NotificationMiddleware, NotificationMulticastInput, NotificationPreferences, NotificationPriority, NotificationStats, NotificationStatus, NotificationTemplate, PushNotification, QueueAdapter, QuietHours, SmsNotification, StorageAdapter, TransportAdapter, Unsubscribe };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
type ChannelType = 'inapp' | 'push' | 'email' | 'sms' | 'webhook';
|
|
2
|
+
type NotificationStatus = 'pending' | 'sent' | 'delivered' | 'failed' | 'read';
|
|
3
|
+
type NotificationPriority = 'low' | 'normal' | 'high' | 'urgent';
|
|
4
|
+
type DeliveryStatus = 'pending' | 'sent' | 'delivered' | 'failed' | 'bounced';
|
|
5
|
+
type DigestFrequency = 'hourly' | 'daily' | 'weekly';
|
|
6
|
+
type ChannelFrequency = 'realtime' | 'batched' | 'digest';
|
|
7
|
+
interface NotificationAction {
|
|
8
|
+
id: string;
|
|
9
|
+
label: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
handler?: string;
|
|
12
|
+
}
|
|
13
|
+
interface Notification {
|
|
14
|
+
id: string;
|
|
15
|
+
type: string;
|
|
16
|
+
title: string;
|
|
17
|
+
body: string;
|
|
18
|
+
text?: string;
|
|
19
|
+
html?: string;
|
|
20
|
+
data?: Record<string, unknown>;
|
|
21
|
+
userId: string;
|
|
22
|
+
groupId?: string;
|
|
23
|
+
priority: NotificationPriority;
|
|
24
|
+
category?: string;
|
|
25
|
+
status: NotificationStatus;
|
|
26
|
+
readAt?: Date;
|
|
27
|
+
createdAt: Date;
|
|
28
|
+
scheduledFor?: Date;
|
|
29
|
+
expiresAt?: Date;
|
|
30
|
+
channels: ChannelType[];
|
|
31
|
+
actions?: NotificationAction[];
|
|
32
|
+
}
|
|
33
|
+
interface EmailNotification extends Notification {
|
|
34
|
+
data: {
|
|
35
|
+
email?: string;
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
interface SmsNotification extends Notification {
|
|
40
|
+
data: {
|
|
41
|
+
phoneNumber?: string;
|
|
42
|
+
[key: string]: unknown;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
interface PushNotification extends Notification {
|
|
46
|
+
data: {
|
|
47
|
+
deviceToken?: string;
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
interface InAppNotification extends Notification {
|
|
52
|
+
data?: Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
interface NotificationInput {
|
|
55
|
+
type: string;
|
|
56
|
+
title: string;
|
|
57
|
+
body: string;
|
|
58
|
+
text?: string;
|
|
59
|
+
html?: string;
|
|
60
|
+
userId: string;
|
|
61
|
+
groupId?: string;
|
|
62
|
+
data?: Record<string, unknown>;
|
|
63
|
+
priority?: NotificationPriority;
|
|
64
|
+
category?: string;
|
|
65
|
+
channels?: ChannelType[];
|
|
66
|
+
scheduledFor?: Date;
|
|
67
|
+
expiresAt?: Date;
|
|
68
|
+
actions?: NotificationAction[];
|
|
69
|
+
template?: string;
|
|
70
|
+
}
|
|
71
|
+
interface NotificationMulticastInput {
|
|
72
|
+
type: string;
|
|
73
|
+
title: string;
|
|
74
|
+
body: string;
|
|
75
|
+
text?: string;
|
|
76
|
+
html?: string;
|
|
77
|
+
userIds: string[];
|
|
78
|
+
data?: Record<string, unknown>;
|
|
79
|
+
priority?: NotificationPriority;
|
|
80
|
+
category?: string;
|
|
81
|
+
channels?: ChannelType[];
|
|
82
|
+
scheduledFor?: Date;
|
|
83
|
+
expiresAt?: Date;
|
|
84
|
+
actions?: NotificationAction[];
|
|
85
|
+
template?: string;
|
|
86
|
+
}
|
|
87
|
+
interface NotificationFilters {
|
|
88
|
+
status?: NotificationStatus | NotificationStatus[];
|
|
89
|
+
type?: string | string[];
|
|
90
|
+
category?: string | string[];
|
|
91
|
+
channels?: ChannelType | ChannelType[];
|
|
92
|
+
priority?: NotificationPriority | NotificationPriority[];
|
|
93
|
+
startDate?: Date;
|
|
94
|
+
endDate?: Date;
|
|
95
|
+
limit?: number;
|
|
96
|
+
offset?: number;
|
|
97
|
+
sortBy?: 'createdAt' | 'priority' | 'readAt';
|
|
98
|
+
sortOrder?: 'asc' | 'desc';
|
|
99
|
+
}
|
|
100
|
+
interface ChannelPreferences {
|
|
101
|
+
enabled: boolean;
|
|
102
|
+
categories?: string[];
|
|
103
|
+
quietHours?: QuietHours;
|
|
104
|
+
frequency?: ChannelFrequency;
|
|
105
|
+
}
|
|
106
|
+
interface QuietHours {
|
|
107
|
+
start: string;
|
|
108
|
+
end: string;
|
|
109
|
+
timezone?: string;
|
|
110
|
+
}
|
|
111
|
+
interface NotificationPreferences {
|
|
112
|
+
userId: string;
|
|
113
|
+
channels: {
|
|
114
|
+
[key in ChannelType]?: ChannelPreferences;
|
|
115
|
+
};
|
|
116
|
+
globalMute?: boolean;
|
|
117
|
+
updatedAt?: Date;
|
|
118
|
+
data?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
interface DeliveryReceipt {
|
|
121
|
+
notificationId: string;
|
|
122
|
+
channel: ChannelType;
|
|
123
|
+
status: DeliveryStatus;
|
|
124
|
+
attempts: number;
|
|
125
|
+
lastAttempt: Date;
|
|
126
|
+
nextRetry?: Date;
|
|
127
|
+
error?: string;
|
|
128
|
+
metadata?: Record<string, unknown>;
|
|
129
|
+
}
|
|
130
|
+
interface NotificationTemplate {
|
|
131
|
+
id: string;
|
|
132
|
+
type: string;
|
|
133
|
+
defaults: {
|
|
134
|
+
title: string | ((data: any) => string);
|
|
135
|
+
body: string | ((data: any) => string);
|
|
136
|
+
text?: string | ((data: any) => string);
|
|
137
|
+
html?: string | ((data: any) => string);
|
|
138
|
+
channels: ChannelType[];
|
|
139
|
+
priority: NotificationPriority;
|
|
140
|
+
category?: string;
|
|
141
|
+
expiresIn?: number;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
interface DigestConfig {
|
|
145
|
+
userId: string;
|
|
146
|
+
frequency: DigestFrequency;
|
|
147
|
+
channels: ChannelType[];
|
|
148
|
+
categories?: string[];
|
|
149
|
+
enabled: boolean;
|
|
150
|
+
}
|
|
151
|
+
interface NotificationMiddleware {
|
|
152
|
+
name: string;
|
|
153
|
+
beforeSend?(notification: Notification): Promise<Notification | null>;
|
|
154
|
+
afterSend?(notification: Notification): Promise<void>;
|
|
155
|
+
onError?(error: Error, notification: Notification): Promise<void>;
|
|
156
|
+
}
|
|
157
|
+
interface StorageAdapter {
|
|
158
|
+
initialize?(): Promise<void>;
|
|
159
|
+
save(notification: Notification): Promise<void>;
|
|
160
|
+
saveBatch(notifications: Notification[]): Promise<void>;
|
|
161
|
+
findById(id: string): Promise<Notification | null>;
|
|
162
|
+
findByUser(userId: string, filters?: NotificationFilters): Promise<Notification[]>;
|
|
163
|
+
countUnread(userId: string): Promise<number>;
|
|
164
|
+
markAsRead(id: string): Promise<void>;
|
|
165
|
+
markAllAsRead(userId: string): Promise<void>;
|
|
166
|
+
markAsUnread(id: string): Promise<void>;
|
|
167
|
+
markAllAsUnread(userId: string): Promise<void>;
|
|
168
|
+
delete(id: string): Promise<void>;
|
|
169
|
+
getPreferences(userId: string): Promise<NotificationPreferences>;
|
|
170
|
+
savePreferences(userId: string, prefs: NotificationPreferences): Promise<void>;
|
|
171
|
+
deleteExpired(): Promise<number>;
|
|
172
|
+
saveReceipt?(receipt: DeliveryReceipt): Promise<void>;
|
|
173
|
+
getReceipts?(notificationId: string): Promise<DeliveryReceipt[]>;
|
|
174
|
+
}
|
|
175
|
+
interface TransportAdapter {
|
|
176
|
+
name: ChannelType;
|
|
177
|
+
send(notification: Notification, preferences: NotificationPreferences): Promise<DeliveryReceipt>;
|
|
178
|
+
sendBatch?(notifications: Notification[], preferences: NotificationPreferences): Promise<DeliveryReceipt[]>;
|
|
179
|
+
sendMulticast?(notifications: Notification[], preferences: NotificationPreferences): Promise<DeliveryReceipt[]>;
|
|
180
|
+
canSend(notification: Notification, preferences: NotificationPreferences): boolean;
|
|
181
|
+
healthCheck?(): Promise<boolean>;
|
|
182
|
+
}
|
|
183
|
+
interface QueueAdapter {
|
|
184
|
+
enqueue(notification: Notification): Promise<void>;
|
|
185
|
+
enqueueBatch(notifications: Notification[]): Promise<void>;
|
|
186
|
+
enqueueDelayed(notification: Notification, delay: number): Promise<void>;
|
|
187
|
+
dequeue(): Promise<Notification | null>;
|
|
188
|
+
dequeueBatch(count: number): Promise<Notification[]>;
|
|
189
|
+
getQueueSize(): Promise<number>;
|
|
190
|
+
clear(): Promise<void>;
|
|
191
|
+
start(): Promise<void>;
|
|
192
|
+
stop(): Promise<void>;
|
|
193
|
+
}
|
|
194
|
+
interface NotificationConfig {
|
|
195
|
+
storage: StorageAdapter;
|
|
196
|
+
transports: TransportAdapter[];
|
|
197
|
+
queue?: QueueAdapter;
|
|
198
|
+
workers?: {
|
|
199
|
+
enabled?: boolean;
|
|
200
|
+
concurrency?: number;
|
|
201
|
+
pollInterval?: number;
|
|
202
|
+
};
|
|
203
|
+
retry?: {
|
|
204
|
+
maxAttempts?: number;
|
|
205
|
+
backoff?: 'linear' | 'exponential';
|
|
206
|
+
initialDelay?: number;
|
|
207
|
+
maxDelay?: number;
|
|
208
|
+
};
|
|
209
|
+
cleanup?: {
|
|
210
|
+
enabled?: boolean;
|
|
211
|
+
interval?: number;
|
|
212
|
+
retentionDays?: number;
|
|
213
|
+
};
|
|
214
|
+
middleware?: NotificationMiddleware[];
|
|
215
|
+
}
|
|
216
|
+
type Unsubscribe = () => void;
|
|
217
|
+
interface NotificationEvent {
|
|
218
|
+
type: 'sent' | 'delivered' | 'read' | 'unread' | 'failed';
|
|
219
|
+
notification: Notification;
|
|
220
|
+
timestamp: Date;
|
|
221
|
+
}
|
|
222
|
+
interface NotificationStats {
|
|
223
|
+
total: number;
|
|
224
|
+
unread: number;
|
|
225
|
+
byStatus: Record<NotificationStatus, number>;
|
|
226
|
+
byChannel: Record<ChannelType, number>;
|
|
227
|
+
byPriority: Record<NotificationPriority, number>;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
declare class NotificationCenter {
|
|
231
|
+
private config;
|
|
232
|
+
private storage;
|
|
233
|
+
private transports;
|
|
234
|
+
private queue?;
|
|
235
|
+
private templates;
|
|
236
|
+
private middleware;
|
|
237
|
+
private subscribers;
|
|
238
|
+
private eventSubscribers;
|
|
239
|
+
private unreadSubscribers;
|
|
240
|
+
private isRunning;
|
|
241
|
+
private workerInterval?;
|
|
242
|
+
constructor(config: NotificationConfig);
|
|
243
|
+
send(input: NotificationInput): Promise<Notification>;
|
|
244
|
+
sendBatch(inputs: NotificationInput[]): Promise<Notification[]>;
|
|
245
|
+
sendMulticast(input: NotificationMulticastInput): Promise<Notification[]>;
|
|
246
|
+
schedule(input: NotificationInput, when: Date): Promise<string>;
|
|
247
|
+
getForUser(userId: string, filters?: NotificationFilters): Promise<Notification[]>;
|
|
248
|
+
getUnreadCount(userId: string): Promise<number>;
|
|
249
|
+
getById(id: string): Promise<Notification | null>;
|
|
250
|
+
getStats(userId: string): Promise<NotificationStats>;
|
|
251
|
+
markAsRead(notificationId: string): Promise<void>;
|
|
252
|
+
markAllAsRead(userId: string): Promise<void>;
|
|
253
|
+
markAsUnread(notificationId: string): Promise<void>;
|
|
254
|
+
markAllAsUnread(userId: string): Promise<void>;
|
|
255
|
+
delete(notificationId: string): Promise<void>;
|
|
256
|
+
deleteAll(userId: string): Promise<void>;
|
|
257
|
+
getPreferences(userId: string): Promise<NotificationPreferences>;
|
|
258
|
+
updatePreferences(userId: string, prefs: Partial<NotificationPreferences>): Promise<void>;
|
|
259
|
+
registerTemplate(template: NotificationTemplate): void;
|
|
260
|
+
getTemplate(id: string): NotificationTemplate | undefined;
|
|
261
|
+
unregisterTemplate(id: string): void;
|
|
262
|
+
enableDigest(userId: string, config: DigestConfig): Promise<void>;
|
|
263
|
+
disableDigest(userId: string): Promise<void>;
|
|
264
|
+
getDigestConfig(userId: string): Promise<DigestConfig | null>;
|
|
265
|
+
getDeliveryStatus(notificationId: string): Promise<DeliveryReceipt[]>;
|
|
266
|
+
retryFailed(notificationId: string, channel?: ChannelType): Promise<void>;
|
|
267
|
+
subscribe(userId: string, callback: (notification: Notification) => void): Unsubscribe;
|
|
268
|
+
subscribeToEvents(userId: string, callback: (event: NotificationEvent) => void): Unsubscribe;
|
|
269
|
+
onUnreadCountChange(userId: string, callback: (count: number, userId: string) => void): Unsubscribe;
|
|
270
|
+
use(middleware: NotificationMiddleware): void;
|
|
271
|
+
removeMiddleware(name: string): void;
|
|
272
|
+
start(): Promise<void>;
|
|
273
|
+
stop(): Promise<void>;
|
|
274
|
+
healthCheck(): Promise<Record<string, boolean>>;
|
|
275
|
+
private buildNotification;
|
|
276
|
+
private sendNow;
|
|
277
|
+
private castNotification;
|
|
278
|
+
private startWorker;
|
|
279
|
+
private startCleanup;
|
|
280
|
+
private applyBeforeSendMiddleware;
|
|
281
|
+
private applyAfterSendMiddleware;
|
|
282
|
+
private applyErrorMiddleware;
|
|
283
|
+
private notifySubscribers;
|
|
284
|
+
private notifyEventSubscribers;
|
|
285
|
+
private notifyUnreadSubscribers;
|
|
286
|
+
private generateId;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
declare class ConsoleTransportAdapter implements TransportAdapter {
|
|
290
|
+
name: ChannelType;
|
|
291
|
+
constructor(name?: ChannelType);
|
|
292
|
+
send(notification: Notification): Promise<DeliveryReceipt>;
|
|
293
|
+
canSend(notification: Notification, preferences: NotificationPreferences): boolean;
|
|
294
|
+
healthCheck(): Promise<boolean>;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
declare class MemoryQueueAdapter implements QueueAdapter {
|
|
298
|
+
private queue;
|
|
299
|
+
private delayedQueue;
|
|
300
|
+
protected isRunning: boolean;
|
|
301
|
+
private checkInterval?;
|
|
302
|
+
enqueue(notification: Notification): Promise<void>;
|
|
303
|
+
enqueueBatch(notifications: Notification[]): Promise<void>;
|
|
304
|
+
enqueueDelayed(notification: Notification, delay: number): Promise<void>;
|
|
305
|
+
dequeue(): Promise<Notification | null>;
|
|
306
|
+
dequeueBatch(count: number): Promise<Notification[]>;
|
|
307
|
+
getQueueSize(): Promise<number>;
|
|
308
|
+
clear(): Promise<void>;
|
|
309
|
+
start(): Promise<void>;
|
|
310
|
+
stop(): Promise<void>;
|
|
311
|
+
private processDelayed;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
declare class MemoryStorageAdapter implements StorageAdapter {
|
|
315
|
+
private notifications;
|
|
316
|
+
private preferences;
|
|
317
|
+
private receipts;
|
|
318
|
+
save(notification: Notification): Promise<void>;
|
|
319
|
+
saveBatch(notifications: Notification[]): Promise<void>;
|
|
320
|
+
findById(id: string): Promise<Notification | null>;
|
|
321
|
+
findByUser(userId: string, filters?: NotificationFilters): Promise<Notification[]>;
|
|
322
|
+
countUnread(userId: string): Promise<number>;
|
|
323
|
+
markAsRead(id: string): Promise<void>;
|
|
324
|
+
markAllAsRead(userId: string): Promise<void>;
|
|
325
|
+
markAsUnread(id: string): Promise<void>;
|
|
326
|
+
markAllAsUnread(userId: string): Promise<void>;
|
|
327
|
+
delete(id: string): Promise<void>;
|
|
328
|
+
getPreferences(userId: string): Promise<NotificationPreferences>;
|
|
329
|
+
savePreferences(userId: string, prefs: NotificationPreferences): Promise<void>;
|
|
330
|
+
deleteExpired(): Promise<number>;
|
|
331
|
+
saveReceipt(receipt: DeliveryReceipt): Promise<void>;
|
|
332
|
+
getReceipts(notificationId: string): Promise<DeliveryReceipt[]>;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export { ChannelFrequency, ChannelPreferences, ChannelType, ConsoleTransportAdapter, DeliveryReceipt, DeliveryStatus, DigestConfig, DigestFrequency, EmailNotification, InAppNotification, MemoryQueueAdapter, MemoryStorageAdapter, Notification, NotificationAction, NotificationCenter, NotificationConfig, NotificationEvent, NotificationFilters, NotificationInput, NotificationMiddleware, NotificationMulticastInput, NotificationPreferences, NotificationPriority, NotificationStats, NotificationStatus, NotificationTemplate, PushNotification, QueueAdapter, QuietHours, SmsNotification, StorageAdapter, TransportAdapter, Unsubscribe };
|