@classic-homes/notifications 1.0.0 → 1.10.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.
@@ -1,5 +1,5 @@
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';
1
+ import { l as NotificationsListResponse, c as ChapiNotificationsListResponse, g as NotificationListParams, N as Notification, M as MarkReadResponse, b as ChannelsResponse, k as NotificationType, P as PreferencesResponse, U as UpdatePreferenceData, n as UpdatePreferenceResponse, B as BatchPreferenceUpdate, a as BulkPreferenceResponse, D as DeletePreferenceResponse, T as TestNotificationParams, m as TestNotificationResponse, d as NotificationChannel, h as NotificationPreference, j as NotificationPriority } from '../types-C3dITqDG.js';
2
+ export { C as ChannelType, e as NotificationError, f as NotificationFrequency, i as NotificationPreferenceResult } from '../types-C3dITqDG.js';
3
3
 
4
4
  /**
5
5
  * Notifications API
@@ -8,6 +8,18 @@ export { C as ChannelType, d as NotificationError, e as NotificationFrequency, h
8
8
  * Uses the auth package's HTTP client for making requests.
9
9
  */
10
10
 
11
+ type RawNotificationsListResponse = NotificationsListResponse | ChapiNotificationsListResponse;
12
+ /**
13
+ * Normalize a list response into NotificationsListResponse.
14
+ *
15
+ * CHAPI returns `{ data, pagination: { page, pageSize, total, pages },
16
+ * meta: { unreadCount } }`; older backends return the package shape
17
+ * directly. Both are accepted so the store works against either.
18
+ */
19
+ declare function normalizeListResponse(raw: RawNotificationsListResponse, requested: {
20
+ page: number;
21
+ limit: number;
22
+ }): NotificationsListResponse;
11
23
  declare const notificationsApi: {
12
24
  /**
13
25
  * List notifications with optional filters.
@@ -229,4 +241,4 @@ interface NotificationCounts {
229
241
  read: number;
230
242
  }
231
243
 
232
- export { type BadgeVariant, BatchPreferenceUpdate, BulkPreferenceResponse, ChannelsResponse, DeletePreferenceResponse, Notification, NotificationChannel, type NotificationCounts, type NotificationFilter, NotificationListParams, NotificationPreference, NotificationPriority, NotificationService, NotificationType, NotificationsListResponse, PreferencesResponse, TestNotificationParams, TestNotificationResponse, UpdatePreferenceData, UpdatePreferenceResponse, formatFullTimestamp, formatNotificationTime, formatRelativeTime, getNotificationIconColor, getNotificationIconName, getPriorityBadgeVariant, getPriorityLabel, getPrioritySortValue, getTypeBadgeVariant, getTypeLabel, notificationService, notificationsApi };
244
+ export { type BadgeVariant, BatchPreferenceUpdate, BulkPreferenceResponse, ChannelsResponse, ChapiNotificationsListResponse, DeletePreferenceResponse, Notification, NotificationChannel, type NotificationCounts, type NotificationFilter, NotificationListParams, NotificationPreference, NotificationPriority, NotificationService, NotificationType, NotificationsListResponse, PreferencesResponse, TestNotificationParams, TestNotificationResponse, UpdatePreferenceData, UpdatePreferenceResponse, formatFullTimestamp, formatNotificationTime, formatRelativeTime, getNotificationIconColor, getNotificationIconName, getPriorityBadgeVariant, getPriorityLabel, getPrioritySortValue, getTypeBadgeVariant, getTypeLabel, normalizeListResponse, notificationService, notificationsApi };
@@ -1,6 +1,26 @@
1
1
  import { api } from '@classic-homes/auth/core';
2
2
 
3
3
  // src/core/api.ts
4
+ function normalizeListResponse(raw, requested) {
5
+ if ("notifications" in raw && Array.isArray(raw.notifications)) {
6
+ return raw;
7
+ }
8
+ const chapi = raw;
9
+ const notifications = Array.isArray(chapi.data) ? chapi.data : [];
10
+ const pagination = chapi.pagination;
11
+ const limit = pagination?.pageSize ?? requested.limit;
12
+ const total = pagination?.total ?? notifications.length;
13
+ return {
14
+ notifications,
15
+ unreadCount: chapi.meta?.unreadCount ?? notifications.filter((n) => !n.read).length,
16
+ pagination: {
17
+ page: pagination?.page ?? requested.page,
18
+ limit,
19
+ total,
20
+ totalPages: pagination?.pages ?? Math.max(1, Math.ceil(total / limit))
21
+ }
22
+ };
23
+ }
4
24
  var notificationsApi = {
5
25
  // ============================================================================
6
26
  // Notifications CRUD
@@ -13,6 +33,8 @@ var notificationsApi = {
13
33
  const page = params?.page || 1;
14
34
  const limit = params?.limit || 20;
15
35
  const offset = (page - 1) * limit;
36
+ queryParams.append("page", page.toString());
37
+ queryParams.append("pageSize", limit.toString());
16
38
  queryParams.append("limit", limit.toString());
17
39
  queryParams.append("offset", offset.toString());
18
40
  if (params?.unreadOnly) {
@@ -28,7 +50,7 @@ var notificationsApi = {
28
50
  true,
29
51
  customFetch
30
52
  );
31
- return response;
53
+ return normalizeListResponse(response, { page, limit });
32
54
  },
33
55
  /**
34
56
  * Get a single notification by ID.
@@ -39,7 +61,8 @@ var notificationsApi = {
39
61
  true,
40
62
  customFetch
41
63
  );
42
- return response.notification;
64
+ const body = response;
65
+ return body.notification ?? body.data;
43
66
  },
44
67
  /**
45
68
  * Mark a notification as read.
@@ -392,4 +415,4 @@ function getPrioritySortValue(priority) {
392
415
  return sortMap[priority] ?? 2;
393
416
  }
394
417
 
395
- export { NotificationService, formatFullTimestamp, formatNotificationTime, formatRelativeTime, getNotificationIconColor, getNotificationIconName, getPriorityBadgeVariant, getPriorityLabel, getPrioritySortValue, getTypeBadgeVariant, getTypeLabel, notificationService, notificationsApi };
418
+ export { NotificationService, formatFullTimestamp, formatNotificationTime, formatRelativeTime, getNotificationIconColor, getNotificationIconName, getPriorityBadgeVariant, getPriorityLabel, getPrioritySortValue, getTypeBadgeVariant, getTypeLabel, normalizeListResponse, notificationService, notificationsApi };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
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-VWF2niWE.js';
1
+ export { BadgeVariant, NotificationCounts, NotificationFilter, NotificationService, formatFullTimestamp, formatNotificationTime, formatRelativeTime, getNotificationIconColor, getNotificationIconName, getPriorityBadgeVariant, getPriorityLabel, getPrioritySortValue, getTypeBadgeVariant, getTypeLabel, normalizeListResponse, notificationService, notificationsApi } from './core/index.js';
2
+ export { B as BatchPreferenceUpdate, a as BulkPreferenceResponse, C as ChannelType, b as ChannelsResponse, c as ChapiNotificationsListResponse, D as DeletePreferenceResponse, N as Notification, d as NotificationChannel, e as NotificationError, f as NotificationFrequency, g as NotificationListParams, h as NotificationPreference, i as NotificationPreferenceResult, j as NotificationPriority, k as NotificationType, l as NotificationsListResponse, P as PreferencesResponse, T as TestNotificationParams, m as TestNotificationResponse, U as UpdatePreferenceData, n as UpdatePreferenceResponse } from './types-C3dITqDG.js';
3
3
  export { isLoadingNotifications, notificationStore, notifications, unreadCount } from './svelte/index.js';
package/dist/index.js CHANGED
@@ -1,6 +1,26 @@
1
1
  import { api } from '@classic-homes/auth/core';
2
2
 
3
3
  // src/core/api.ts
4
+ function normalizeListResponse(raw, requested) {
5
+ if ("notifications" in raw && Array.isArray(raw.notifications)) {
6
+ return raw;
7
+ }
8
+ const chapi = raw;
9
+ const notifications2 = Array.isArray(chapi.data) ? chapi.data : [];
10
+ const pagination = chapi.pagination;
11
+ const limit = pagination?.pageSize ?? requested.limit;
12
+ const total = pagination?.total ?? notifications2.length;
13
+ return {
14
+ notifications: notifications2,
15
+ unreadCount: chapi.meta?.unreadCount ?? notifications2.filter((n) => !n.read).length,
16
+ pagination: {
17
+ page: pagination?.page ?? requested.page,
18
+ limit,
19
+ total,
20
+ totalPages: pagination?.pages ?? Math.max(1, Math.ceil(total / limit))
21
+ }
22
+ };
23
+ }
4
24
  var notificationsApi = {
5
25
  // ============================================================================
6
26
  // Notifications CRUD
@@ -13,6 +33,8 @@ var notificationsApi = {
13
33
  const page = params?.page || 1;
14
34
  const limit = params?.limit || 20;
15
35
  const offset = (page - 1) * limit;
36
+ queryParams.append("page", page.toString());
37
+ queryParams.append("pageSize", limit.toString());
16
38
  queryParams.append("limit", limit.toString());
17
39
  queryParams.append("offset", offset.toString());
18
40
  if (params?.unreadOnly) {
@@ -28,7 +50,7 @@ var notificationsApi = {
28
50
  true,
29
51
  customFetch
30
52
  );
31
- return response;
53
+ return normalizeListResponse(response, { page, limit });
32
54
  },
33
55
  /**
34
56
  * Get a single notification by ID.
@@ -39,7 +61,8 @@ var notificationsApi = {
39
61
  true,
40
62
  customFetch
41
63
  );
42
- return response.notification;
64
+ const body = response;
65
+ return body.notification ?? body.data;
43
66
  },
44
67
  /**
45
68
  * Mark a notification as read.
@@ -640,4 +663,4 @@ var isLoadingNotifications = {
640
663
  }
641
664
  };
642
665
 
643
- export { NotificationService, formatFullTimestamp, formatNotificationTime, formatRelativeTime, getNotificationIconColor, getNotificationIconName, getPriorityBadgeVariant, getPriorityLabel, getPrioritySortValue, getTypeBadgeVariant, getTypeLabel, isLoadingNotifications, notificationService, notificationStore, notifications, notificationsApi, unreadCount };
666
+ export { NotificationService, formatFullTimestamp, formatNotificationTime, formatRelativeTime, getNotificationIconColor, getNotificationIconName, getPriorityBadgeVariant, getPriorityLabel, getPrioritySortValue, getTypeBadgeVariant, getTypeLabel, isLoadingNotifications, normalizeListResponse, notificationService, notificationStore, notifications, notificationsApi, unreadCount };
@@ -1,5 +1,5 @@
1
- import { N as Notification, f as NotificationListParams } from '../types-VWF2niWE.js';
2
- export { i as NotificationPriority, j as NotificationType } from '../types-VWF2niWE.js';
1
+ import { N as Notification, g as NotificationListParams } from '../types-C3dITqDG.js';
2
+ export { j as NotificationPriority, k as NotificationType } from '../types-C3dITqDG.js';
3
3
 
4
4
  /**
5
5
  * Notifications Store
@@ -1,6 +1,26 @@
1
1
  import { api } from '@classic-homes/auth/core';
2
2
 
3
3
  // src/core/api.ts
4
+ function normalizeListResponse(raw, requested) {
5
+ if ("notifications" in raw && Array.isArray(raw.notifications)) {
6
+ return raw;
7
+ }
8
+ const chapi = raw;
9
+ const notifications2 = Array.isArray(chapi.data) ? chapi.data : [];
10
+ const pagination = chapi.pagination;
11
+ const limit = pagination?.pageSize ?? requested.limit;
12
+ const total = pagination?.total ?? notifications2.length;
13
+ return {
14
+ notifications: notifications2,
15
+ unreadCount: chapi.meta?.unreadCount ?? notifications2.filter((n) => !n.read).length,
16
+ pagination: {
17
+ page: pagination?.page ?? requested.page,
18
+ limit,
19
+ total,
20
+ totalPages: pagination?.pages ?? Math.max(1, Math.ceil(total / limit))
21
+ }
22
+ };
23
+ }
4
24
  var notificationsApi = {
5
25
  // ============================================================================
6
26
  // Notifications CRUD
@@ -13,6 +33,8 @@ var notificationsApi = {
13
33
  const page = params?.page || 1;
14
34
  const limit = params?.limit || 20;
15
35
  const offset = (page - 1) * limit;
36
+ queryParams.append("page", page.toString());
37
+ queryParams.append("pageSize", limit.toString());
16
38
  queryParams.append("limit", limit.toString());
17
39
  queryParams.append("offset", offset.toString());
18
40
  if (params?.unreadOnly) {
@@ -28,7 +50,7 @@ var notificationsApi = {
28
50
  true,
29
51
  customFetch
30
52
  );
31
- return response;
53
+ return normalizeListResponse(response, { page, limit });
32
54
  },
33
55
  /**
34
56
  * Get a single notification by ID.
@@ -39,7 +61,8 @@ var notificationsApi = {
39
61
  true,
40
62
  customFetch
41
63
  );
42
- return response.notification;
64
+ const body = response;
65
+ return body.notification ?? body.data;
43
66
  },
44
67
  /**
45
68
  * Mark a notification as read.
@@ -34,6 +34,23 @@ interface NotificationsListResponse {
34
34
  totalPages: number;
35
35
  };
36
36
  }
37
+ /**
38
+ * Raw list response as returned by CHAPI `GET /v1/notifications`.
39
+ * Normalized into NotificationsListResponse by notificationsApi.list().
40
+ */
41
+ interface ChapiNotificationsListResponse {
42
+ data: Notification[];
43
+ pagination?: {
44
+ page: number;
45
+ pageSize: number;
46
+ total: number;
47
+ pages: number;
48
+ };
49
+ meta?: {
50
+ unreadCount?: number;
51
+ timestamp?: string;
52
+ };
53
+ }
37
54
  interface NotificationListParams {
38
55
  page?: number;
39
56
  limit?: number;
@@ -152,4 +169,4 @@ interface TestNotificationResponse {
152
169
  };
153
170
  }
154
171
 
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 };
172
+ 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, ChapiNotificationsListResponse as c, NotificationChannel as d, NotificationError as e, NotificationFrequency as f, NotificationListParams as g, NotificationPreference as h, NotificationPreferenceResult as i, NotificationPriority as j, NotificationType as k, NotificationsListResponse as l, TestNotificationResponse as m, UpdatePreferenceResponse as n };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/notifications",
3
- "version": "1.0.0",
3
+ "version": "1.10.2",
4
4
  "description": "Notification services and Svelte bindings for Classic Theme apps",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",