@classic-homes/notifications 0.1.53 → 0.1.56

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.
@@ -1,5 +1,5 @@
1
- import { d as NotificationListParams, c as NotificationsListResponse, b as Notification, k as ChannelsResponse, N as NotificationType, P as PreferencesResponse, U as UpdatePreferenceData, l as UpdatePreferenceResponse, B as BatchPreferenceUpdate, j as BulkPreferenceResponse, D as DeletePreferenceResponse, T as TestNotificationParams, m as TestNotificationResponse, e as NotificationChannel, g as NotificationPreference, a as NotificationPriority } from '../types-BSztr7EQ.js';
2
- export { C as ChannelType, i as NotificationError, f as NotificationFrequency, h as NotificationPreferenceResult } from '../types-BSztr7EQ.js';
1
+ import { f as NotificationListParams, k as NotificationsListResponse, N as Notification, M as MarkReadResponse, b as ChannelsResponse, j as NotificationType, P as PreferencesResponse, U as UpdatePreferenceData, m as UpdatePreferenceResponse, B as BatchPreferenceUpdate, a as BulkPreferenceResponse, D as DeletePreferenceResponse, T as TestNotificationParams, l as TestNotificationResponse, c as NotificationChannel, g as NotificationPreference, i as NotificationPriority } from '../types-VWF2niWE.js';
2
+ export { C as ChannelType, d as NotificationError, e as NotificationFrequency, h as NotificationPreferenceResult } from '../types-VWF2niWE.js';
3
3
 
4
4
  /**
5
5
  * Notifications API
@@ -23,12 +23,14 @@ declare const notificationsApi: {
23
23
  markRead(id: string): Promise<void>;
24
24
  /**
25
25
  * Mark multiple notifications as read.
26
+ * Returns the server payload so callers can detect partial failures;
27
+ * fields are optional because not every backend reports them.
26
28
  */
27
- markManyRead(ids: string[]): Promise<void>;
29
+ markManyRead(ids: string[]): Promise<MarkReadResponse>;
28
30
  /**
29
31
  * Mark all notifications as read.
30
32
  */
31
- markAllRead(): Promise<void>;
33
+ markAllRead(): Promise<MarkReadResponse>;
32
34
  /**
33
35
  * Dismiss (delete) a notification.
34
36
  */
@@ -49,15 +49,25 @@ var notificationsApi = {
49
49
  },
50
50
  /**
51
51
  * Mark multiple notifications as read.
52
+ * Returns the server payload so callers can detect partial failures;
53
+ * fields are optional because not every backend reports them.
52
54
  */
53
55
  async markManyRead(ids) {
54
- await api.post("/notifications/mark-read", { ids }, true);
56
+ const response = await api.post("/notifications/mark-read", { ids }, true);
57
+ const data = response;
58
+ return data.data || data;
55
59
  },
56
60
  /**
57
61
  * Mark all notifications as read.
58
62
  */
59
63
  async markAllRead() {
60
- await api.post("/notifications/mark-read", { all: true }, true);
64
+ const response = await api.post(
65
+ "/notifications/mark-read",
66
+ { all: true },
67
+ true
68
+ );
69
+ const data = response;
70
+ return data.data || data;
61
71
  },
62
72
  /**
63
73
  * Dismiss (delete) a notification.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { BadgeVariant, NotificationCounts, NotificationFilter, NotificationService, formatFullTimestamp, formatNotificationTime, formatRelativeTime, getNotificationIconColor, getNotificationIconName, getPriorityBadgeVariant, getPriorityLabel, getPrioritySortValue, getTypeBadgeVariant, getTypeLabel, notificationService, notificationsApi } from './core/index.js';
2
- export { B as BatchPreferenceUpdate, j as BulkPreferenceResponse, C as ChannelType, k as ChannelsResponse, D as DeletePreferenceResponse, b as Notification, e as NotificationChannel, i as NotificationError, f as NotificationFrequency, d as NotificationListParams, g as NotificationPreference, h as NotificationPreferenceResult, a as NotificationPriority, N as NotificationType, c as NotificationsListResponse, P as PreferencesResponse, T as TestNotificationParams, m as TestNotificationResponse, U as UpdatePreferenceData, l as UpdatePreferenceResponse } from './types-BSztr7EQ.js';
2
+ export { B as BatchPreferenceUpdate, a as BulkPreferenceResponse, C as ChannelType, b as ChannelsResponse, D as DeletePreferenceResponse, N as Notification, c as NotificationChannel, d as NotificationError, e as NotificationFrequency, f as NotificationListParams, g as NotificationPreference, h as NotificationPreferenceResult, i as NotificationPriority, j as NotificationType, k as NotificationsListResponse, P as PreferencesResponse, T as TestNotificationParams, l as TestNotificationResponse, U as UpdatePreferenceData, m as UpdatePreferenceResponse } from './types-VWF2niWE.js';
3
3
  export { isLoadingNotifications, notificationStore, notifications, unreadCount } from './svelte/index.js';
package/dist/index.js CHANGED
@@ -49,15 +49,25 @@ var notificationsApi = {
49
49
  },
50
50
  /**
51
51
  * Mark multiple notifications as read.
52
+ * Returns the server payload so callers can detect partial failures;
53
+ * fields are optional because not every backend reports them.
52
54
  */
53
55
  async markManyRead(ids) {
54
- await api.post("/notifications/mark-read", { ids }, true);
56
+ const response = await api.post("/notifications/mark-read", { ids }, true);
57
+ const data = response;
58
+ return data.data || data;
55
59
  },
56
60
  /**
57
61
  * Mark all notifications as read.
58
62
  */
59
63
  async markAllRead() {
60
- await api.post("/notifications/mark-read", { all: true }, true);
64
+ const response = await api.post(
65
+ "/notifications/mark-read",
66
+ { all: true },
67
+ true
68
+ );
69
+ const data = response;
70
+ return data.data || data;
61
71
  },
62
72
  /**
63
73
  * Dismiss (delete) a notification.
@@ -408,7 +418,13 @@ var NotificationStore = class {
408
418
  return () => this.subscribers.delete(subscriber);
409
419
  }
410
420
  notify() {
411
- this.subscribers.forEach((sub) => sub(this.state));
421
+ this.subscribers.forEach((sub) => {
422
+ try {
423
+ sub(this.state);
424
+ } catch (e) {
425
+ console.error("Notification store subscriber error:", e);
426
+ }
427
+ });
412
428
  }
413
429
  setState(partial) {
414
430
  this.state = { ...this.state, ...partial };
@@ -460,6 +476,9 @@ var NotificationStore = class {
460
476
  * Load more notifications (next page).
461
477
  */
462
478
  async loadMore() {
479
+ if (this.state.isLoading) {
480
+ return;
481
+ }
463
482
  if (this.state.pagination.page >= this.state.pagination.totalPages) {
464
483
  return;
465
484
  }
@@ -469,8 +488,10 @@ var NotificationStore = class {
469
488
  page: this.state.pagination.page + 1,
470
489
  limit: this.state.pagination.limit
471
490
  });
491
+ const existingIds = new Set(this.state.notifications.map((n) => n.id));
492
+ const newNotifications = response.notifications.filter((n) => !existingIds.has(n.id));
472
493
  this.setState({
473
- notifications: [...this.state.notifications, ...response.notifications],
494
+ notifications: [...this.state.notifications, ...newNotifications],
474
495
  unreadCount: response.unreadCount,
475
496
  pagination: response.pagination,
476
497
  isLoading: false
@@ -504,15 +525,22 @@ var NotificationStore = class {
504
525
  */
505
526
  async markManyRead(ids) {
506
527
  try {
507
- await notificationsApi.markManyRead(ids);
528
+ const response = await notificationsApi.markManyRead(ids);
529
+ const failedIds = new Set(response.failedIds ?? []);
530
+ const succeededIds = ids.filter((id) => !failedIds.has(id));
508
531
  const notifications2 = this.state.notifications.map(
509
- (n) => ids.includes(n.id) ? { ...n, read: true, readAt: (/* @__PURE__ */ new Date()).toISOString() } : n
532
+ (n) => succeededIds.includes(n.id) ? { ...n, read: true, readAt: (/* @__PURE__ */ new Date()).toISOString() } : n
510
533
  );
511
534
  const readCount = this.state.notifications.filter(
512
- (n) => ids.includes(n.id) && !n.read
535
+ (n) => succeededIds.includes(n.id) && !n.read
513
536
  ).length;
514
537
  const unreadCount2 = Math.max(0, this.state.unreadCount - readCount);
515
- this.setState({ notifications: notifications2, unreadCount: unreadCount2 });
538
+ const partialFailure = response.success === false || (response.failed ?? 0) > 0;
539
+ this.setState({
540
+ notifications: notifications2,
541
+ unreadCount: unreadCount2,
542
+ error: partialFailure ? "Some notifications could not be marked as read" : null
543
+ });
516
544
  } catch (error) {
517
545
  this.setState({
518
546
  error: error instanceof Error ? error.message : "Failed to mark notifications as read"
@@ -524,13 +552,18 @@ var NotificationStore = class {
524
552
  */
525
553
  async markAllRead() {
526
554
  try {
527
- await notificationsApi.markAllRead();
555
+ const response = await notificationsApi.markAllRead();
528
556
  const notifications2 = this.state.notifications.map((n) => ({
529
557
  ...n,
530
558
  read: true,
531
559
  readAt: n.readAt || (/* @__PURE__ */ new Date()).toISOString()
532
560
  }));
533
- this.setState({ notifications: notifications2, unreadCount: 0 });
561
+ const partialFailure = response.success === false || (response.failed ?? 0) > 0;
562
+ this.setState({
563
+ notifications: notifications2,
564
+ unreadCount: 0,
565
+ error: partialFailure ? "Some notifications could not be marked as read" : null
566
+ });
534
567
  } catch (error) {
535
568
  this.setState({
536
569
  error: error instanceof Error ? error.message : "Failed to mark all notifications as read"
@@ -1,5 +1,5 @@
1
- import { b as Notification, d as NotificationListParams } from '../types-BSztr7EQ.js';
2
- export { a as NotificationPriority, N as NotificationType } from '../types-BSztr7EQ.js';
1
+ import { N as Notification, f as NotificationListParams } from '../types-VWF2niWE.js';
2
+ export { i as NotificationPriority, j as NotificationType } from '../types-VWF2niWE.js';
3
3
 
4
4
  /**
5
5
  * Notifications Store
@@ -49,15 +49,25 @@ var notificationsApi = {
49
49
  },
50
50
  /**
51
51
  * Mark multiple notifications as read.
52
+ * Returns the server payload so callers can detect partial failures;
53
+ * fields are optional because not every backend reports them.
52
54
  */
53
55
  async markManyRead(ids) {
54
- await api.post("/notifications/mark-read", { ids }, true);
56
+ const response = await api.post("/notifications/mark-read", { ids }, true);
57
+ const data = response;
58
+ return data.data || data;
55
59
  },
56
60
  /**
57
61
  * Mark all notifications as read.
58
62
  */
59
63
  async markAllRead() {
60
- await api.post("/notifications/mark-read", { all: true }, true);
64
+ const response = await api.post(
65
+ "/notifications/mark-read",
66
+ { all: true },
67
+ true
68
+ );
69
+ const data = response;
70
+ return data.data || data;
61
71
  },
62
72
  /**
63
73
  * Dismiss (delete) a notification.
@@ -180,7 +190,13 @@ var NotificationStore = class {
180
190
  return () => this.subscribers.delete(subscriber);
181
191
  }
182
192
  notify() {
183
- this.subscribers.forEach((sub) => sub(this.state));
193
+ this.subscribers.forEach((sub) => {
194
+ try {
195
+ sub(this.state);
196
+ } catch (e) {
197
+ console.error("Notification store subscriber error:", e);
198
+ }
199
+ });
184
200
  }
185
201
  setState(partial) {
186
202
  this.state = { ...this.state, ...partial };
@@ -232,6 +248,9 @@ var NotificationStore = class {
232
248
  * Load more notifications (next page).
233
249
  */
234
250
  async loadMore() {
251
+ if (this.state.isLoading) {
252
+ return;
253
+ }
235
254
  if (this.state.pagination.page >= this.state.pagination.totalPages) {
236
255
  return;
237
256
  }
@@ -241,8 +260,10 @@ var NotificationStore = class {
241
260
  page: this.state.pagination.page + 1,
242
261
  limit: this.state.pagination.limit
243
262
  });
263
+ const existingIds = new Set(this.state.notifications.map((n) => n.id));
264
+ const newNotifications = response.notifications.filter((n) => !existingIds.has(n.id));
244
265
  this.setState({
245
- notifications: [...this.state.notifications, ...response.notifications],
266
+ notifications: [...this.state.notifications, ...newNotifications],
246
267
  unreadCount: response.unreadCount,
247
268
  pagination: response.pagination,
248
269
  isLoading: false
@@ -276,15 +297,22 @@ var NotificationStore = class {
276
297
  */
277
298
  async markManyRead(ids) {
278
299
  try {
279
- await notificationsApi.markManyRead(ids);
300
+ const response = await notificationsApi.markManyRead(ids);
301
+ const failedIds = new Set(response.failedIds ?? []);
302
+ const succeededIds = ids.filter((id) => !failedIds.has(id));
280
303
  const notifications2 = this.state.notifications.map(
281
- (n) => ids.includes(n.id) ? { ...n, read: true, readAt: (/* @__PURE__ */ new Date()).toISOString() } : n
304
+ (n) => succeededIds.includes(n.id) ? { ...n, read: true, readAt: (/* @__PURE__ */ new Date()).toISOString() } : n
282
305
  );
283
306
  const readCount = this.state.notifications.filter(
284
- (n) => ids.includes(n.id) && !n.read
307
+ (n) => succeededIds.includes(n.id) && !n.read
285
308
  ).length;
286
309
  const unreadCount2 = Math.max(0, this.state.unreadCount - readCount);
287
- this.setState({ notifications: notifications2, unreadCount: unreadCount2 });
310
+ const partialFailure = response.success === false || (response.failed ?? 0) > 0;
311
+ this.setState({
312
+ notifications: notifications2,
313
+ unreadCount: unreadCount2,
314
+ error: partialFailure ? "Some notifications could not be marked as read" : null
315
+ });
288
316
  } catch (error) {
289
317
  this.setState({
290
318
  error: error instanceof Error ? error.message : "Failed to mark notifications as read"
@@ -296,13 +324,18 @@ var NotificationStore = class {
296
324
  */
297
325
  async markAllRead() {
298
326
  try {
299
- await notificationsApi.markAllRead();
327
+ const response = await notificationsApi.markAllRead();
300
328
  const notifications2 = this.state.notifications.map((n) => ({
301
329
  ...n,
302
330
  read: true,
303
331
  readAt: n.readAt || (/* @__PURE__ */ new Date()).toISOString()
304
332
  }));
305
- this.setState({ notifications: notifications2, unreadCount: 0 });
333
+ const partialFailure = response.success === false || (response.failed ?? 0) > 0;
334
+ this.setState({
335
+ notifications: notifications2,
336
+ unreadCount: 0,
337
+ error: partialFailure ? "Some notifications could not be marked as read" : null
338
+ });
306
339
  } catch (error) {
307
340
  this.setState({
308
341
  error: error instanceof Error ? error.message : "Failed to mark all notifications as read"
@@ -97,6 +97,20 @@ interface NotificationError {
97
97
  message: string;
98
98
  code?: string;
99
99
  }
100
+ /**
101
+ * Server payload for mark-read operations. All fields are optional —
102
+ * backends that don't report per-item outcomes return an empty object.
103
+ */
104
+ interface MarkReadResponse {
105
+ success?: boolean;
106
+ /** Number of notifications actually updated */
107
+ updated?: number;
108
+ /** Number of notifications that failed to update */
109
+ failed?: number;
110
+ /** IDs that failed to update, when the backend reports them */
111
+ failedIds?: string[];
112
+ errors?: NotificationError[];
113
+ }
100
114
  interface BulkPreferenceResponse {
101
115
  success: boolean;
102
116
  total: number;
@@ -138,4 +152,4 @@ interface TestNotificationResponse {
138
152
  };
139
153
  }
140
154
 
141
- export type { BatchPreferenceUpdate as B, ChannelType as C, DeletePreferenceResponse as D, NotificationType as N, PreferencesResponse as P, TestNotificationParams as T, UpdatePreferenceData as U, NotificationPriority as a, Notification as b, NotificationsListResponse as c, NotificationListParams as d, NotificationChannel as e, NotificationFrequency as f, NotificationPreference as g, NotificationPreferenceResult as h, NotificationError as i, BulkPreferenceResponse as j, ChannelsResponse as k, UpdatePreferenceResponse as l, TestNotificationResponse as m };
155
+ export type { BatchPreferenceUpdate as B, ChannelType as C, DeletePreferenceResponse as D, MarkReadResponse as M, Notification as N, PreferencesResponse as P, TestNotificationParams as T, UpdatePreferenceData as U, BulkPreferenceResponse as a, ChannelsResponse as b, NotificationChannel as c, NotificationError as d, NotificationFrequency as e, NotificationListParams as f, NotificationPreference as g, NotificationPreferenceResult as h, NotificationPriority as i, NotificationType as j, NotificationsListResponse as k, TestNotificationResponse as l, UpdatePreferenceResponse as m };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/notifications",
3
- "version": "0.1.53",
3
+ "version": "0.1.56",
4
4
  "description": "Notification services and Svelte bindings for Classic Theme apps",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -27,8 +27,10 @@
27
27
  "scripts": {
28
28
  "build": "tsup",
29
29
  "dev": "tsup --watch",
30
- "clean": "rm -rf dist",
31
- "typecheck": "tsc --noEmit"
30
+ "clean": "node ../../scripts/rm.mjs dist",
31
+ "typecheck": "tsc --noEmit",
32
+ "test": "vitest run",
33
+ "test:watch": "vitest"
32
34
  },
33
35
  "keywords": [
34
36
  "notifications",
@@ -45,7 +47,7 @@
45
47
  "access": "public"
46
48
  },
47
49
  "dependencies": {
48
- "@classic-homes/auth": "*"
50
+ "@classic-homes/auth": "^0.1.56"
49
51
  },
50
52
  "peerDependencies": {
51
53
  "svelte": "^5.0.0"
@@ -58,6 +60,7 @@
58
60
  "devDependencies": {
59
61
  "svelte": "^5.0.0",
60
62
  "tsup": "^8.0.0",
61
- "typescript": "^5.3.0"
63
+ "typescript": "^5.3.0",
64
+ "vitest": "^4.1.10"
62
65
  }
63
66
  }