@classic-homes/notifications 1.10.2 → 1.22.2

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 CHANGED
@@ -296,7 +296,7 @@ import {
296
296
 
297
297
  // Get icon for notification type
298
298
  getNotificationIconName('security'); // 'shield'
299
- getNotificationIconColor('security'); // 'text-red-500'
299
+ getNotificationIconColor('security'); // 'text-destructive'
300
300
 
301
301
  // Get badge variants
302
302
  getPriorityBadgeVariant('urgent'); // 'destructive'
@@ -192,7 +192,8 @@ type BadgeVariant = 'default' | 'secondary' | 'destructive' | 'outline' | 'succe
192
192
  declare function getNotificationIconName(type: NotificationType): string;
193
193
  /**
194
194
  * Get the icon color class for a notification type.
195
- * Returns Tailwind CSS color classes.
195
+ * Returns semantic Tailwind color classes from the shared preset, so icons
196
+ * follow the theme (including dark mode) instead of fixed palette shades.
196
197
  */
197
198
  declare function getNotificationIconColor(type: NotificationType): string;
198
199
  /**
@@ -57,7 +57,7 @@ var notificationsApi = {
57
57
  */
58
58
  async get(id, customFetch) {
59
59
  const response = await api.get(
60
- `/notifications/${id}`,
60
+ `/notifications/${encodeURIComponent(id)}`,
61
61
  true,
62
62
  customFetch
63
63
  );
@@ -68,7 +68,7 @@ var notificationsApi = {
68
68
  * Mark a notification as read.
69
69
  */
70
70
  async markRead(id) {
71
- await api.patch(`/notifications/${id}/read`, {}, true);
71
+ await api.patch(`/notifications/${encodeURIComponent(id)}/read`, {}, true);
72
72
  },
73
73
  /**
74
74
  * Mark multiple notifications as read.
@@ -96,7 +96,7 @@ var notificationsApi = {
96
96
  * Dismiss (delete) a notification.
97
97
  */
98
98
  async dismiss(id) {
99
- await api.delete(`/notifications/${id}`, true);
99
+ await api.delete(`/notifications/${encodeURIComponent(id)}`, true);
100
100
  },
101
101
  /**
102
102
  * Delete multiple notifications in bulk.
@@ -165,7 +165,7 @@ var notificationsApi = {
165
165
  */
166
166
  async deletePreference(subscriptionId) {
167
167
  const response = await api.delete(
168
- `/notifications/preferences/${subscriptionId}`,
168
+ `/notifications/preferences/${encodeURIComponent(subscriptionId)}`,
169
169
  true
170
170
  );
171
171
  return response;
@@ -302,14 +302,14 @@ function getNotificationIconName(type) {
302
302
  }
303
303
  function getNotificationIconColor(type) {
304
304
  const colorMap = {
305
- security: "text-red-500",
306
- system: "text-blue-500",
307
- feature: "text-purple-500",
308
- update: "text-green-500",
309
- alert: "text-yellow-500",
310
- info: "text-gray-500"
305
+ security: "text-destructive",
306
+ system: "text-info",
307
+ feature: "text-primary",
308
+ update: "text-success",
309
+ alert: "text-warning",
310
+ info: "text-muted-foreground"
311
311
  };
312
- return colorMap[type] ?? "text-gray-500";
312
+ return colorMap[type] ?? "text-muted-foreground";
313
313
  }
314
314
  function getPriorityBadgeVariant(priority) {
315
315
  const variantMap = {
package/dist/index.js CHANGED
@@ -57,7 +57,7 @@ var notificationsApi = {
57
57
  */
58
58
  async get(id, customFetch) {
59
59
  const response = await api.get(
60
- `/notifications/${id}`,
60
+ `/notifications/${encodeURIComponent(id)}`,
61
61
  true,
62
62
  customFetch
63
63
  );
@@ -68,7 +68,7 @@ var notificationsApi = {
68
68
  * Mark a notification as read.
69
69
  */
70
70
  async markRead(id) {
71
- await api.patch(`/notifications/${id}/read`, {}, true);
71
+ await api.patch(`/notifications/${encodeURIComponent(id)}/read`, {}, true);
72
72
  },
73
73
  /**
74
74
  * Mark multiple notifications as read.
@@ -96,7 +96,7 @@ var notificationsApi = {
96
96
  * Dismiss (delete) a notification.
97
97
  */
98
98
  async dismiss(id) {
99
- await api.delete(`/notifications/${id}`, true);
99
+ await api.delete(`/notifications/${encodeURIComponent(id)}`, true);
100
100
  },
101
101
  /**
102
102
  * Delete multiple notifications in bulk.
@@ -165,7 +165,7 @@ var notificationsApi = {
165
165
  */
166
166
  async deletePreference(subscriptionId) {
167
167
  const response = await api.delete(
168
- `/notifications/preferences/${subscriptionId}`,
168
+ `/notifications/preferences/${encodeURIComponent(subscriptionId)}`,
169
169
  true
170
170
  );
171
171
  return response;
@@ -302,14 +302,14 @@ function getNotificationIconName(type) {
302
302
  }
303
303
  function getNotificationIconColor(type) {
304
304
  const colorMap = {
305
- security: "text-red-500",
306
- system: "text-blue-500",
307
- feature: "text-purple-500",
308
- update: "text-green-500",
309
- alert: "text-yellow-500",
310
- info: "text-gray-500"
305
+ security: "text-destructive",
306
+ system: "text-info",
307
+ feature: "text-primary",
308
+ update: "text-success",
309
+ alert: "text-warning",
310
+ info: "text-muted-foreground"
311
311
  };
312
- return colorMap[type] ?? "text-gray-500";
312
+ return colorMap[type] ?? "text-muted-foreground";
313
313
  }
314
314
  function getPriorityBadgeVariant(priority) {
315
315
  const variantMap = {
@@ -419,6 +419,10 @@ function getPrioritySortValue(priority) {
419
419
  var NotificationStore = class {
420
420
  constructor() {
421
421
  this.subscribers = /* @__PURE__ */ new Set();
422
+ /** Filters from the last fetch(), reapplied by refresh() and loadMore(). */
423
+ this.filters = {};
424
+ /** Bumped by every list request; a response from an older one is dropped. */
425
+ this.requestSeq = 0;
422
426
  this.state = {
423
427
  notifications: [],
424
428
  unreadCount: 0,
@@ -470,9 +474,15 @@ var NotificationStore = class {
470
474
  * Fetch notifications from the API.
471
475
  */
472
476
  async fetch(params) {
477
+ const filters = { ...params };
478
+ delete filters.page;
479
+ delete filters.limit;
480
+ this.filters = filters;
481
+ const seq = ++this.requestSeq;
473
482
  this.setState({ isLoading: true, error: null });
474
483
  try {
475
484
  const response = await notificationsApi.list(params);
485
+ if (seq !== this.requestSeq) return;
476
486
  this.setState({
477
487
  notifications: response.notifications,
478
488
  unreadCount: response.unreadCount,
@@ -480,6 +490,7 @@ var NotificationStore = class {
480
490
  isLoading: false
481
491
  });
482
492
  } catch (error) {
493
+ if (seq !== this.requestSeq) return;
483
494
  this.setState({
484
495
  error: error instanceof Error ? error.message : "Failed to fetch notifications",
485
496
  isLoading: false
@@ -487,11 +498,14 @@ var NotificationStore = class {
487
498
  }
488
499
  }
489
500
  /**
490
- * Refresh notifications (re-fetch with current params).
501
+ * Refresh notifications: re-fetch from the first page with the current
502
+ * filters and page size. Re-fetching only the current page would replace
503
+ * the list with that page alone after loadMore().
491
504
  */
492
505
  async refresh() {
493
506
  await this.fetch({
494
- page: this.state.pagination.page,
507
+ ...this.filters,
508
+ page: 1,
495
509
  limit: this.state.pagination.limit
496
510
  });
497
511
  }
@@ -505,12 +519,15 @@ var NotificationStore = class {
505
519
  if (this.state.pagination.page >= this.state.pagination.totalPages) {
506
520
  return;
507
521
  }
522
+ const seq = ++this.requestSeq;
508
523
  this.setState({ isLoading: true, error: null });
509
524
  try {
510
525
  const response = await notificationsApi.list({
526
+ ...this.filters,
511
527
  page: this.state.pagination.page + 1,
512
528
  limit: this.state.pagination.limit
513
529
  });
530
+ if (seq !== this.requestSeq) return;
514
531
  const existingIds = new Set(this.state.notifications.map((n) => n.id));
515
532
  const newNotifications = response.notifications.filter((n) => !existingIds.has(n.id));
516
533
  this.setState({
@@ -520,6 +537,7 @@ var NotificationStore = class {
520
537
  isLoading: false
521
538
  });
522
539
  } catch (error) {
540
+ if (seq !== this.requestSeq) return;
523
541
  this.setState({
524
542
  error: error instanceof Error ? error.message : "Failed to load more notifications",
525
543
  isLoading: false
@@ -532,10 +550,11 @@ var NotificationStore = class {
532
550
  async markRead(id) {
533
551
  try {
534
552
  await notificationsApi.markRead(id);
553
+ const target = this.state.notifications.find((n) => n.id === id);
535
554
  const notifications2 = this.state.notifications.map(
536
555
  (n) => n.id === id ? { ...n, read: true, readAt: (/* @__PURE__ */ new Date()).toISOString() } : n
537
556
  );
538
- const unreadCount2 = Math.max(0, this.state.unreadCount - 1);
557
+ const unreadCount2 = target && !target.read ? Math.max(0, this.state.unreadCount - 1) : this.state.unreadCount;
539
558
  this.setState({ notifications: notifications2, unreadCount: unreadCount2 });
540
559
  } catch (error) {
541
560
  this.setState({
@@ -632,6 +651,8 @@ var NotificationStore = class {
632
651
  * Reset the store to initial state.
633
652
  */
634
653
  reset() {
654
+ this.filters = {};
655
+ this.requestSeq++;
635
656
  this.setState({
636
657
  notifications: [],
637
658
  unreadCount: 0,
@@ -25,6 +25,10 @@ interface NotificationState {
25
25
  declare class NotificationStore {
26
26
  private state;
27
27
  private subscribers;
28
+ /** Filters from the last fetch(), reapplied by refresh() and loadMore(). */
29
+ private filters;
30
+ /** Bumped by every list request; a response from an older one is dropped. */
31
+ private requestSeq;
28
32
  constructor();
29
33
  /**
30
34
  * Subscribe to state changes (Svelte store contract).
@@ -41,7 +45,9 @@ declare class NotificationStore {
41
45
  */
42
46
  fetch(params?: NotificationListParams): Promise<void>;
43
47
  /**
44
- * Refresh notifications (re-fetch with current params).
48
+ * Refresh notifications: re-fetch from the first page with the current
49
+ * filters and page size. Re-fetching only the current page would replace
50
+ * the list with that page alone after loadMore().
45
51
  */
46
52
  refresh(): Promise<void>;
47
53
  /**
@@ -57,7 +57,7 @@ var notificationsApi = {
57
57
  */
58
58
  async get(id, customFetch) {
59
59
  const response = await api.get(
60
- `/notifications/${id}`,
60
+ `/notifications/${encodeURIComponent(id)}`,
61
61
  true,
62
62
  customFetch
63
63
  );
@@ -68,7 +68,7 @@ var notificationsApi = {
68
68
  * Mark a notification as read.
69
69
  */
70
70
  async markRead(id) {
71
- await api.patch(`/notifications/${id}/read`, {}, true);
71
+ await api.patch(`/notifications/${encodeURIComponent(id)}/read`, {}, true);
72
72
  },
73
73
  /**
74
74
  * Mark multiple notifications as read.
@@ -96,7 +96,7 @@ var notificationsApi = {
96
96
  * Dismiss (delete) a notification.
97
97
  */
98
98
  async dismiss(id) {
99
- await api.delete(`/notifications/${id}`, true);
99
+ await api.delete(`/notifications/${encodeURIComponent(id)}`, true);
100
100
  },
101
101
  /**
102
102
  * Delete multiple notifications in bulk.
@@ -165,7 +165,7 @@ var notificationsApi = {
165
165
  */
166
166
  async deletePreference(subscriptionId) {
167
167
  const response = await api.delete(
168
- `/notifications/preferences/${subscriptionId}`,
168
+ `/notifications/preferences/${encodeURIComponent(subscriptionId)}`,
169
169
  true
170
170
  );
171
171
  return response;
@@ -191,6 +191,10 @@ var notificationsApi = {
191
191
  var NotificationStore = class {
192
192
  constructor() {
193
193
  this.subscribers = /* @__PURE__ */ new Set();
194
+ /** Filters from the last fetch(), reapplied by refresh() and loadMore(). */
195
+ this.filters = {};
196
+ /** Bumped by every list request; a response from an older one is dropped. */
197
+ this.requestSeq = 0;
194
198
  this.state = {
195
199
  notifications: [],
196
200
  unreadCount: 0,
@@ -242,9 +246,15 @@ var NotificationStore = class {
242
246
  * Fetch notifications from the API.
243
247
  */
244
248
  async fetch(params) {
249
+ const filters = { ...params };
250
+ delete filters.page;
251
+ delete filters.limit;
252
+ this.filters = filters;
253
+ const seq = ++this.requestSeq;
245
254
  this.setState({ isLoading: true, error: null });
246
255
  try {
247
256
  const response = await notificationsApi.list(params);
257
+ if (seq !== this.requestSeq) return;
248
258
  this.setState({
249
259
  notifications: response.notifications,
250
260
  unreadCount: response.unreadCount,
@@ -252,6 +262,7 @@ var NotificationStore = class {
252
262
  isLoading: false
253
263
  });
254
264
  } catch (error) {
265
+ if (seq !== this.requestSeq) return;
255
266
  this.setState({
256
267
  error: error instanceof Error ? error.message : "Failed to fetch notifications",
257
268
  isLoading: false
@@ -259,11 +270,14 @@ var NotificationStore = class {
259
270
  }
260
271
  }
261
272
  /**
262
- * Refresh notifications (re-fetch with current params).
273
+ * Refresh notifications: re-fetch from the first page with the current
274
+ * filters and page size. Re-fetching only the current page would replace
275
+ * the list with that page alone after loadMore().
263
276
  */
264
277
  async refresh() {
265
278
  await this.fetch({
266
- page: this.state.pagination.page,
279
+ ...this.filters,
280
+ page: 1,
267
281
  limit: this.state.pagination.limit
268
282
  });
269
283
  }
@@ -277,12 +291,15 @@ var NotificationStore = class {
277
291
  if (this.state.pagination.page >= this.state.pagination.totalPages) {
278
292
  return;
279
293
  }
294
+ const seq = ++this.requestSeq;
280
295
  this.setState({ isLoading: true, error: null });
281
296
  try {
282
297
  const response = await notificationsApi.list({
298
+ ...this.filters,
283
299
  page: this.state.pagination.page + 1,
284
300
  limit: this.state.pagination.limit
285
301
  });
302
+ if (seq !== this.requestSeq) return;
286
303
  const existingIds = new Set(this.state.notifications.map((n) => n.id));
287
304
  const newNotifications = response.notifications.filter((n) => !existingIds.has(n.id));
288
305
  this.setState({
@@ -292,6 +309,7 @@ var NotificationStore = class {
292
309
  isLoading: false
293
310
  });
294
311
  } catch (error) {
312
+ if (seq !== this.requestSeq) return;
295
313
  this.setState({
296
314
  error: error instanceof Error ? error.message : "Failed to load more notifications",
297
315
  isLoading: false
@@ -304,10 +322,11 @@ var NotificationStore = class {
304
322
  async markRead(id) {
305
323
  try {
306
324
  await notificationsApi.markRead(id);
325
+ const target = this.state.notifications.find((n) => n.id === id);
307
326
  const notifications2 = this.state.notifications.map(
308
327
  (n) => n.id === id ? { ...n, read: true, readAt: (/* @__PURE__ */ new Date()).toISOString() } : n
309
328
  );
310
- const unreadCount2 = Math.max(0, this.state.unreadCount - 1);
329
+ const unreadCount2 = target && !target.read ? Math.max(0, this.state.unreadCount - 1) : this.state.unreadCount;
311
330
  this.setState({ notifications: notifications2, unreadCount: unreadCount2 });
312
331
  } catch (error) {
313
332
  this.setState({
@@ -404,6 +423,8 @@ var NotificationStore = class {
404
423
  * Reset the store to initial state.
405
424
  */
406
425
  reset() {
426
+ this.filters = {};
427
+ this.requestSeq++;
407
428
  this.setState({
408
429
  notifications: [],
409
430
  unreadCount: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/notifications",
3
- "version": "1.10.2",
3
+ "version": "1.22.2",
4
4
  "description": "Notification services and Svelte bindings for Classic Theme apps",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -47,7 +47,7 @@
47
47
  "access": "public"
48
48
  },
49
49
  "dependencies": {
50
- "@classic-homes/auth": "^1.0.0"
50
+ "@classic-homes/auth": "^1.22.2"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "svelte": "^5.0.0"