@classic-homes/notifications 1.27.0 → 1.42.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/dist/index.js CHANGED
@@ -423,6 +423,12 @@ var NotificationStore = class {
423
423
  this.filters = {};
424
424
  /** Bumped by every list request; a response from an older one is dropped. */
425
425
  this.requestSeq = 0;
426
+ /**
427
+ * Bumped by reset() (sign-out, account switch). A mutation captures it
428
+ * before its request and drops its result, success or error, if the store
429
+ * was reset meanwhile: it belongs to the previous user's list.
430
+ */
431
+ this.generation = 0;
426
432
  this.state = {
427
433
  notifications: [],
428
434
  unreadCount: 0,
@@ -548,8 +554,10 @@ var NotificationStore = class {
548
554
  * Mark a notification as read.
549
555
  */
550
556
  async markRead(id) {
557
+ const generation = this.generation;
551
558
  try {
552
559
  await notificationsApi.markRead(id);
560
+ if (generation !== this.generation) return;
553
561
  const target = this.state.notifications.find((n) => n.id === id);
554
562
  const notifications2 = this.state.notifications.map(
555
563
  (n) => n.id === id ? { ...n, read: true, readAt: (/* @__PURE__ */ new Date()).toISOString() } : n
@@ -557,6 +565,7 @@ var NotificationStore = class {
557
565
  const unreadCount2 = target && !target.read ? Math.max(0, this.state.unreadCount - 1) : this.state.unreadCount;
558
566
  this.setState({ notifications: notifications2, unreadCount: unreadCount2 });
559
567
  } catch (error) {
568
+ if (generation !== this.generation) return;
560
569
  this.setState({
561
570
  error: error instanceof Error ? error.message : "Failed to mark notification as read"
562
571
  });
@@ -566,8 +575,10 @@ var NotificationStore = class {
566
575
  * Mark multiple notifications as read.
567
576
  */
568
577
  async markManyRead(ids) {
578
+ const generation = this.generation;
569
579
  try {
570
580
  const response = await notificationsApi.markManyRead(ids);
581
+ if (generation !== this.generation) return;
571
582
  const failedIds = new Set(response.failedIds ?? []);
572
583
  const succeededIds = ids.filter((id) => !failedIds.has(id));
573
584
  const notifications2 = this.state.notifications.map(
@@ -584,6 +595,7 @@ var NotificationStore = class {
584
595
  error: partialFailure ? "Some notifications could not be marked as read" : null
585
596
  });
586
597
  } catch (error) {
598
+ if (generation !== this.generation) return;
587
599
  this.setState({
588
600
  error: error instanceof Error ? error.message : "Failed to mark notifications as read"
589
601
  });
@@ -593,8 +605,10 @@ var NotificationStore = class {
593
605
  * Mark all notifications as read.
594
606
  */
595
607
  async markAllRead() {
608
+ const generation = this.generation;
596
609
  try {
597
610
  const response = await notificationsApi.markAllRead();
611
+ if (generation !== this.generation) return;
598
612
  const notifications2 = this.state.notifications.map((n) => ({
599
613
  ...n,
600
614
  read: true,
@@ -607,6 +621,7 @@ var NotificationStore = class {
607
621
  error: partialFailure ? "Some notifications could not be marked as read" : null
608
622
  });
609
623
  } catch (error) {
624
+ if (generation !== this.generation) return;
610
625
  this.setState({
611
626
  error: error instanceof Error ? error.message : "Failed to mark all notifications as read"
612
627
  });
@@ -616,13 +631,16 @@ var NotificationStore = class {
616
631
  * Dismiss (delete) a notification.
617
632
  */
618
633
  async dismiss(id) {
634
+ const generation = this.generation;
619
635
  try {
620
636
  await notificationsApi.dismiss(id);
637
+ if (generation !== this.generation) return;
621
638
  const dismissed = this.state.notifications.find((n) => n.id === id);
622
639
  const notifications2 = this.state.notifications.filter((n) => n.id !== id);
623
640
  const unreadCount2 = dismissed && !dismissed.read ? Math.max(0, this.state.unreadCount - 1) : this.state.unreadCount;
624
641
  this.setState({ notifications: notifications2, unreadCount: unreadCount2 });
625
642
  } catch (error) {
643
+ if (generation !== this.generation) return;
626
644
  this.setState({
627
645
  error: error instanceof Error ? error.message : "Failed to dismiss notification"
628
646
  });
@@ -632,10 +650,13 @@ var NotificationStore = class {
632
650
  * Delete all notifications.
633
651
  */
634
652
  async deleteAll() {
653
+ const generation = this.generation;
635
654
  try {
636
655
  await notificationsApi.deleteAll();
656
+ if (generation !== this.generation) return;
637
657
  this.setState({ notifications: [], unreadCount: 0 });
638
658
  } catch (error) {
659
+ if (generation !== this.generation) return;
639
660
  this.setState({
640
661
  error: error instanceof Error ? error.message : "Failed to delete all notifications"
641
662
  });
@@ -653,6 +674,7 @@ var NotificationStore = class {
653
674
  reset() {
654
675
  this.filters = {};
655
676
  this.requestSeq++;
677
+ this.generation++;
656
678
  this.setState({
657
679
  notifications: [],
658
680
  unreadCount: 0,
@@ -29,6 +29,12 @@ declare class NotificationStore {
29
29
  private filters;
30
30
  /** Bumped by every list request; a response from an older one is dropped. */
31
31
  private requestSeq;
32
+ /**
33
+ * Bumped by reset() (sign-out, account switch). A mutation captures it
34
+ * before its request and drops its result, success or error, if the store
35
+ * was reset meanwhile: it belongs to the previous user's list.
36
+ */
37
+ private generation;
32
38
  constructor();
33
39
  /**
34
40
  * Subscribe to state changes (Svelte store contract).
@@ -195,6 +195,12 @@ var NotificationStore = class {
195
195
  this.filters = {};
196
196
  /** Bumped by every list request; a response from an older one is dropped. */
197
197
  this.requestSeq = 0;
198
+ /**
199
+ * Bumped by reset() (sign-out, account switch). A mutation captures it
200
+ * before its request and drops its result, success or error, if the store
201
+ * was reset meanwhile: it belongs to the previous user's list.
202
+ */
203
+ this.generation = 0;
198
204
  this.state = {
199
205
  notifications: [],
200
206
  unreadCount: 0,
@@ -320,8 +326,10 @@ var NotificationStore = class {
320
326
  * Mark a notification as read.
321
327
  */
322
328
  async markRead(id) {
329
+ const generation = this.generation;
323
330
  try {
324
331
  await notificationsApi.markRead(id);
332
+ if (generation !== this.generation) return;
325
333
  const target = this.state.notifications.find((n) => n.id === id);
326
334
  const notifications2 = this.state.notifications.map(
327
335
  (n) => n.id === id ? { ...n, read: true, readAt: (/* @__PURE__ */ new Date()).toISOString() } : n
@@ -329,6 +337,7 @@ var NotificationStore = class {
329
337
  const unreadCount2 = target && !target.read ? Math.max(0, this.state.unreadCount - 1) : this.state.unreadCount;
330
338
  this.setState({ notifications: notifications2, unreadCount: unreadCount2 });
331
339
  } catch (error) {
340
+ if (generation !== this.generation) return;
332
341
  this.setState({
333
342
  error: error instanceof Error ? error.message : "Failed to mark notification as read"
334
343
  });
@@ -338,8 +347,10 @@ var NotificationStore = class {
338
347
  * Mark multiple notifications as read.
339
348
  */
340
349
  async markManyRead(ids) {
350
+ const generation = this.generation;
341
351
  try {
342
352
  const response = await notificationsApi.markManyRead(ids);
353
+ if (generation !== this.generation) return;
343
354
  const failedIds = new Set(response.failedIds ?? []);
344
355
  const succeededIds = ids.filter((id) => !failedIds.has(id));
345
356
  const notifications2 = this.state.notifications.map(
@@ -356,6 +367,7 @@ var NotificationStore = class {
356
367
  error: partialFailure ? "Some notifications could not be marked as read" : null
357
368
  });
358
369
  } catch (error) {
370
+ if (generation !== this.generation) return;
359
371
  this.setState({
360
372
  error: error instanceof Error ? error.message : "Failed to mark notifications as read"
361
373
  });
@@ -365,8 +377,10 @@ var NotificationStore = class {
365
377
  * Mark all notifications as read.
366
378
  */
367
379
  async markAllRead() {
380
+ const generation = this.generation;
368
381
  try {
369
382
  const response = await notificationsApi.markAllRead();
383
+ if (generation !== this.generation) return;
370
384
  const notifications2 = this.state.notifications.map((n) => ({
371
385
  ...n,
372
386
  read: true,
@@ -379,6 +393,7 @@ var NotificationStore = class {
379
393
  error: partialFailure ? "Some notifications could not be marked as read" : null
380
394
  });
381
395
  } catch (error) {
396
+ if (generation !== this.generation) return;
382
397
  this.setState({
383
398
  error: error instanceof Error ? error.message : "Failed to mark all notifications as read"
384
399
  });
@@ -388,13 +403,16 @@ var NotificationStore = class {
388
403
  * Dismiss (delete) a notification.
389
404
  */
390
405
  async dismiss(id) {
406
+ const generation = this.generation;
391
407
  try {
392
408
  await notificationsApi.dismiss(id);
409
+ if (generation !== this.generation) return;
393
410
  const dismissed = this.state.notifications.find((n) => n.id === id);
394
411
  const notifications2 = this.state.notifications.filter((n) => n.id !== id);
395
412
  const unreadCount2 = dismissed && !dismissed.read ? Math.max(0, this.state.unreadCount - 1) : this.state.unreadCount;
396
413
  this.setState({ notifications: notifications2, unreadCount: unreadCount2 });
397
414
  } catch (error) {
415
+ if (generation !== this.generation) return;
398
416
  this.setState({
399
417
  error: error instanceof Error ? error.message : "Failed to dismiss notification"
400
418
  });
@@ -404,10 +422,13 @@ var NotificationStore = class {
404
422
  * Delete all notifications.
405
423
  */
406
424
  async deleteAll() {
425
+ const generation = this.generation;
407
426
  try {
408
427
  await notificationsApi.deleteAll();
428
+ if (generation !== this.generation) return;
409
429
  this.setState({ notifications: [], unreadCount: 0 });
410
430
  } catch (error) {
431
+ if (generation !== this.generation) return;
411
432
  this.setState({
412
433
  error: error instanceof Error ? error.message : "Failed to delete all notifications"
413
434
  });
@@ -425,6 +446,7 @@ var NotificationStore = class {
425
446
  reset() {
426
447
  this.filters = {};
427
448
  this.requestSeq++;
449
+ this.generation++;
428
450
  this.setState({
429
451
  notifications: [],
430
452
  unreadCount: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/notifications",
3
- "version": "1.27.0",
3
+ "version": "1.42.0",
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.27.0"
50
+ "@classic-homes/auth": "^1.42.0"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "svelte": "^5.0.0"