@classic-homes/notifications 0.1.35 → 0.1.36
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 +157 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,11 +93,28 @@ import {
|
|
|
93
93
|
notificationService,
|
|
94
94
|
NotificationService,
|
|
95
95
|
|
|
96
|
+
// Utilities
|
|
97
|
+
getNotificationIconName,
|
|
98
|
+
getNotificationIconColor,
|
|
99
|
+
getPriorityBadgeVariant,
|
|
100
|
+
getTypeBadgeVariant,
|
|
101
|
+
getPriorityLabel,
|
|
102
|
+
getTypeLabel,
|
|
103
|
+
formatRelativeTime,
|
|
104
|
+
formatFullTimestamp,
|
|
105
|
+
formatNotificationTime,
|
|
106
|
+
getPrioritySortValue,
|
|
107
|
+
|
|
96
108
|
// Types
|
|
97
109
|
type Notification,
|
|
98
110
|
type NotificationType,
|
|
99
111
|
type NotificationPriority,
|
|
100
|
-
type
|
|
112
|
+
type NotificationPreference,
|
|
113
|
+
type NotificationChannel,
|
|
114
|
+
type NotificationFrequency,
|
|
115
|
+
type NotificationFilter,
|
|
116
|
+
type NotificationCounts,
|
|
117
|
+
type BadgeVariant,
|
|
101
118
|
} from '@classic-homes/notifications';
|
|
102
119
|
```
|
|
103
120
|
|
|
@@ -176,22 +193,124 @@ notificationStore.reset();
|
|
|
176
193
|
## Notification Types
|
|
177
194
|
|
|
178
195
|
```typescript
|
|
196
|
+
type NotificationType = 'security' | 'system' | 'feature' | 'update' | 'alert' | 'info';
|
|
197
|
+
type NotificationPriority = 'urgent' | 'high' | 'normal' | 'low';
|
|
198
|
+
|
|
179
199
|
interface Notification {
|
|
180
200
|
id: string;
|
|
181
|
-
|
|
182
|
-
|
|
201
|
+
userId: string;
|
|
202
|
+
type: NotificationType;
|
|
203
|
+
category: string;
|
|
183
204
|
title: string;
|
|
184
205
|
message: string;
|
|
206
|
+
icon?: string;
|
|
207
|
+
color?: string;
|
|
208
|
+
priority: NotificationPriority;
|
|
185
209
|
read: boolean;
|
|
186
|
-
|
|
210
|
+
dismissed: boolean;
|
|
187
211
|
actionUrl?: string;
|
|
188
212
|
actionLabel?: string;
|
|
189
213
|
metadata?: Record<string, unknown>;
|
|
190
214
|
createdAt: string;
|
|
191
|
-
|
|
215
|
+
readAt?: string;
|
|
216
|
+
dismissedAt?: string;
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Channels and Preferences
|
|
221
|
+
|
|
222
|
+
The package supports notification channels (email, sms, push, in_app) and user preferences for fine-grained control.
|
|
223
|
+
|
|
224
|
+
### Getting Channels
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
import { notificationService } from '@classic-homes/notifications/core';
|
|
228
|
+
|
|
229
|
+
const { channels } = await notificationService.getChannels();
|
|
230
|
+
// channels: [{ id, name, displayName, enabled, priority }]
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Managing Preferences
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
import { notificationService } from '@classic-homes/notifications/core';
|
|
237
|
+
|
|
238
|
+
// Get user preferences
|
|
239
|
+
const { preferences } = await notificationService.getPreferences();
|
|
240
|
+
|
|
241
|
+
// Update a preference
|
|
242
|
+
await notificationService.updatePreference({
|
|
243
|
+
channelId: 'email',
|
|
244
|
+
notificationType: 'security',
|
|
245
|
+
enabled: true,
|
|
246
|
+
frequency: 'immediate',
|
|
247
|
+
minPriority: 'normal',
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// Batch update preferences
|
|
251
|
+
await notificationService.batchUpdatePreferences([
|
|
252
|
+
{ eventType: 'security', channels: ['email', 'push'], enabled: true },
|
|
253
|
+
{ eventType: 'feature', channels: ['in_app'], enabled: true },
|
|
254
|
+
]);
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Preference Types
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
type ChannelType = 'email' | 'sms' | 'push' | 'in_app';
|
|
261
|
+
type NotificationFrequency = 'immediate' | 'digest_hourly' | 'digest_daily' | 'digest_weekly';
|
|
262
|
+
|
|
263
|
+
interface NotificationPreference {
|
|
264
|
+
id: string;
|
|
265
|
+
userId: string;
|
|
266
|
+
channelId: string;
|
|
267
|
+
notificationType: NotificationType;
|
|
268
|
+
notificationCategory?: string;
|
|
269
|
+
enabled: boolean;
|
|
270
|
+
frequency: NotificationFrequency;
|
|
271
|
+
quietHoursStart?: string;
|
|
272
|
+
quietHoursEnd?: string;
|
|
273
|
+
quietHoursTimezone?: string;
|
|
274
|
+
minPriority: NotificationPriority;
|
|
275
|
+
tags?: string[];
|
|
276
|
+
createdAt: string;
|
|
277
|
+
updatedAt?: string;
|
|
192
278
|
}
|
|
193
279
|
```
|
|
194
280
|
|
|
281
|
+
## Utility Functions
|
|
282
|
+
|
|
283
|
+
Display helpers for consistent notification rendering:
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
import {
|
|
287
|
+
getNotificationIconName,
|
|
288
|
+
getNotificationIconColor,
|
|
289
|
+
getPriorityBadgeVariant,
|
|
290
|
+
getTypeBadgeVariant,
|
|
291
|
+
getPriorityLabel,
|
|
292
|
+
getTypeLabel,
|
|
293
|
+
formatRelativeTime,
|
|
294
|
+
formatNotificationTime,
|
|
295
|
+
} from '@classic-homes/notifications/core';
|
|
296
|
+
|
|
297
|
+
// Get icon for notification type
|
|
298
|
+
getNotificationIconName('security'); // 'shield'
|
|
299
|
+
getNotificationIconColor('security'); // 'text-red-500'
|
|
300
|
+
|
|
301
|
+
// Get badge variants
|
|
302
|
+
getPriorityBadgeVariant('urgent'); // 'destructive'
|
|
303
|
+
getTypeBadgeVariant('update'); // 'success'
|
|
304
|
+
|
|
305
|
+
// Get display labels
|
|
306
|
+
getPriorityLabel('high'); // 'High'
|
|
307
|
+
getTypeLabel('feature'); // 'Feature'
|
|
308
|
+
|
|
309
|
+
// Format timestamps
|
|
310
|
+
formatRelativeTime('2024-01-22T10:00:00Z'); // '2h ago'
|
|
311
|
+
formatNotificationTime('2024-01-15T10:00:00Z'); // 'Jan 15'
|
|
312
|
+
```
|
|
313
|
+
|
|
195
314
|
## Using with Toast Notifications
|
|
196
315
|
|
|
197
316
|
For client-side only toast notifications (not persisted), use `toastStore` from `@classic-homes/theme-svelte`:
|
|
@@ -272,6 +391,39 @@ interface NotificationState {
|
|
|
272
391
|
</DropdownMenu>
|
|
273
392
|
```
|
|
274
393
|
|
|
394
|
+
## Direct API Access
|
|
395
|
+
|
|
396
|
+
For direct API access without the Svelte store:
|
|
397
|
+
|
|
398
|
+
```typescript
|
|
399
|
+
import { notificationsApi } from '@classic-homes/notifications/core';
|
|
400
|
+
|
|
401
|
+
// List notifications
|
|
402
|
+
const response = await notificationsApi.list({ page: 1, limit: 20 });
|
|
403
|
+
|
|
404
|
+
// Get single notification
|
|
405
|
+
const notification = await notificationsApi.get('notification-id');
|
|
406
|
+
|
|
407
|
+
// Mark as read
|
|
408
|
+
await notificationsApi.markRead('notification-id');
|
|
409
|
+
await notificationsApi.markManyRead(['id1', 'id2']);
|
|
410
|
+
await notificationsApi.markAllRead();
|
|
411
|
+
|
|
412
|
+
// Delete notifications
|
|
413
|
+
await notificationsApi.dismiss('notification-id');
|
|
414
|
+
await notificationsApi.bulkDelete(['id1', 'id2']);
|
|
415
|
+
await notificationsApi.deleteAll();
|
|
416
|
+
|
|
417
|
+
// Channels and preferences
|
|
418
|
+
const channels = await notificationsApi.getChannels();
|
|
419
|
+
const preferences = await notificationsApi.getPreferences();
|
|
420
|
+
await notificationsApi.updatePreference(preferenceData);
|
|
421
|
+
await notificationsApi.deletePreference('subscription-id');
|
|
422
|
+
|
|
423
|
+
// Test notifications (dev/admin only)
|
|
424
|
+
await notificationsApi.generateTestNotifications({ type: 'info' });
|
|
425
|
+
```
|
|
426
|
+
|
|
275
427
|
## License
|
|
276
428
|
|
|
277
429
|
MIT
|