@classic-homes/notifications 0.1.55 → 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.
- package/dist/core/index.d.ts +6 -4
- package/dist/core/index.js +12 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +36 -9
- package/dist/svelte/index.d.ts +2 -2
- package/dist/svelte/index.js +36 -9
- package/dist/{types-1JHyPeBO.d.ts → types-VWF2niWE.d.ts} +15 -1
- package/package.json +7 -4
package/dist/core/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { f as NotificationListParams, k as NotificationsListResponse, N as Notification, 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-
|
|
2
|
-
export { C as ChannelType, d as NotificationError, e as NotificationFrequency, h as NotificationPreferenceResult } from '../types-
|
|
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<
|
|
29
|
+
markManyRead(ids: string[]): Promise<MarkReadResponse>;
|
|
28
30
|
/**
|
|
29
31
|
* Mark all notifications as read.
|
|
30
32
|
*/
|
|
31
|
-
markAllRead(): Promise<
|
|
33
|
+
markAllRead(): Promise<MarkReadResponse>;
|
|
32
34
|
/**
|
|
33
35
|
* Dismiss (delete) a notification.
|
|
34
36
|
*/
|
package/dist/core/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(
|
|
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, 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-
|
|
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(
|
|
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.
|
|
@@ -466,6 +476,9 @@ var NotificationStore = class {
|
|
|
466
476
|
* Load more notifications (next page).
|
|
467
477
|
*/
|
|
468
478
|
async loadMore() {
|
|
479
|
+
if (this.state.isLoading) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
469
482
|
if (this.state.pagination.page >= this.state.pagination.totalPages) {
|
|
470
483
|
return;
|
|
471
484
|
}
|
|
@@ -475,8 +488,10 @@ var NotificationStore = class {
|
|
|
475
488
|
page: this.state.pagination.page + 1,
|
|
476
489
|
limit: this.state.pagination.limit
|
|
477
490
|
});
|
|
491
|
+
const existingIds = new Set(this.state.notifications.map((n) => n.id));
|
|
492
|
+
const newNotifications = response.notifications.filter((n) => !existingIds.has(n.id));
|
|
478
493
|
this.setState({
|
|
479
|
-
notifications: [...this.state.notifications, ...
|
|
494
|
+
notifications: [...this.state.notifications, ...newNotifications],
|
|
480
495
|
unreadCount: response.unreadCount,
|
|
481
496
|
pagination: response.pagination,
|
|
482
497
|
isLoading: false
|
|
@@ -510,15 +525,22 @@ var NotificationStore = class {
|
|
|
510
525
|
*/
|
|
511
526
|
async markManyRead(ids) {
|
|
512
527
|
try {
|
|
513
|
-
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));
|
|
514
531
|
const notifications2 = this.state.notifications.map(
|
|
515
|
-
(n) =>
|
|
532
|
+
(n) => succeededIds.includes(n.id) ? { ...n, read: true, readAt: (/* @__PURE__ */ new Date()).toISOString() } : n
|
|
516
533
|
);
|
|
517
534
|
const readCount = this.state.notifications.filter(
|
|
518
|
-
(n) =>
|
|
535
|
+
(n) => succeededIds.includes(n.id) && !n.read
|
|
519
536
|
).length;
|
|
520
537
|
const unreadCount2 = Math.max(0, this.state.unreadCount - readCount);
|
|
521
|
-
|
|
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
|
+
});
|
|
522
544
|
} catch (error) {
|
|
523
545
|
this.setState({
|
|
524
546
|
error: error instanceof Error ? error.message : "Failed to mark notifications as read"
|
|
@@ -530,13 +552,18 @@ var NotificationStore = class {
|
|
|
530
552
|
*/
|
|
531
553
|
async markAllRead() {
|
|
532
554
|
try {
|
|
533
|
-
await notificationsApi.markAllRead();
|
|
555
|
+
const response = await notificationsApi.markAllRead();
|
|
534
556
|
const notifications2 = this.state.notifications.map((n) => ({
|
|
535
557
|
...n,
|
|
536
558
|
read: true,
|
|
537
559
|
readAt: n.readAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
538
560
|
}));
|
|
539
|
-
|
|
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
|
+
});
|
|
540
567
|
} catch (error) {
|
|
541
568
|
this.setState({
|
|
542
569
|
error: error instanceof Error ? error.message : "Failed to mark all notifications as read"
|
package/dist/svelte/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as Notification, f as NotificationListParams } from '../types-
|
|
2
|
-
export { i as NotificationPriority, j as NotificationType } from '../types-
|
|
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
|
package/dist/svelte/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(
|
|
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.
|
|
@@ -238,6 +248,9 @@ var NotificationStore = class {
|
|
|
238
248
|
* Load more notifications (next page).
|
|
239
249
|
*/
|
|
240
250
|
async loadMore() {
|
|
251
|
+
if (this.state.isLoading) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
241
254
|
if (this.state.pagination.page >= this.state.pagination.totalPages) {
|
|
242
255
|
return;
|
|
243
256
|
}
|
|
@@ -247,8 +260,10 @@ var NotificationStore = class {
|
|
|
247
260
|
page: this.state.pagination.page + 1,
|
|
248
261
|
limit: this.state.pagination.limit
|
|
249
262
|
});
|
|
263
|
+
const existingIds = new Set(this.state.notifications.map((n) => n.id));
|
|
264
|
+
const newNotifications = response.notifications.filter((n) => !existingIds.has(n.id));
|
|
250
265
|
this.setState({
|
|
251
|
-
notifications: [...this.state.notifications, ...
|
|
266
|
+
notifications: [...this.state.notifications, ...newNotifications],
|
|
252
267
|
unreadCount: response.unreadCount,
|
|
253
268
|
pagination: response.pagination,
|
|
254
269
|
isLoading: false
|
|
@@ -282,15 +297,22 @@ var NotificationStore = class {
|
|
|
282
297
|
*/
|
|
283
298
|
async markManyRead(ids) {
|
|
284
299
|
try {
|
|
285
|
-
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));
|
|
286
303
|
const notifications2 = this.state.notifications.map(
|
|
287
|
-
(n) =>
|
|
304
|
+
(n) => succeededIds.includes(n.id) ? { ...n, read: true, readAt: (/* @__PURE__ */ new Date()).toISOString() } : n
|
|
288
305
|
);
|
|
289
306
|
const readCount = this.state.notifications.filter(
|
|
290
|
-
(n) =>
|
|
307
|
+
(n) => succeededIds.includes(n.id) && !n.read
|
|
291
308
|
).length;
|
|
292
309
|
const unreadCount2 = Math.max(0, this.state.unreadCount - readCount);
|
|
293
|
-
|
|
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
|
+
});
|
|
294
316
|
} catch (error) {
|
|
295
317
|
this.setState({
|
|
296
318
|
error: error instanceof Error ? error.message : "Failed to mark notifications as read"
|
|
@@ -302,13 +324,18 @@ var NotificationStore = class {
|
|
|
302
324
|
*/
|
|
303
325
|
async markAllRead() {
|
|
304
326
|
try {
|
|
305
|
-
await notificationsApi.markAllRead();
|
|
327
|
+
const response = await notificationsApi.markAllRead();
|
|
306
328
|
const notifications2 = this.state.notifications.map((n) => ({
|
|
307
329
|
...n,
|
|
308
330
|
read: true,
|
|
309
331
|
readAt: n.readAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
310
332
|
}));
|
|
311
|
-
|
|
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
|
+
});
|
|
312
339
|
} catch (error) {
|
|
313
340
|
this.setState({
|
|
314
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, 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 };
|
|
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.
|
|
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",
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"build": "tsup",
|
|
29
29
|
"dev": "tsup --watch",
|
|
30
30
|
"clean": "node ../../scripts/rm.mjs dist",
|
|
31
|
-
"typecheck": "tsc --noEmit"
|
|
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
|
}
|