@pfm-platform/notifications-feature 0.1.1

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.cjs ADDED
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var notificationsDataAccess = require('@pfm-platform/notifications-data-access');
5
+
6
+ // src/hooks/useNotificationGroups.ts
7
+ function useNotificationGroups(userId) {
8
+ const { data: notifications } = notificationsDataAccess.useNotifications({ userId });
9
+ return react.useMemo(() => {
10
+ if (!notifications || notifications.length === 0) {
11
+ return {
12
+ byAlertType: {},
13
+ recent: [],
14
+ count: 0
15
+ };
16
+ }
17
+ const byAlertType = {};
18
+ notifications.forEach((notification) => {
19
+ if (!byAlertType[notification.alert_type]) {
20
+ byAlertType[notification.alert_type] = [];
21
+ }
22
+ byAlertType[notification.alert_type].push(notification);
23
+ });
24
+ const now = /* @__PURE__ */ new Date();
25
+ const twentyFourHoursAgo = new Date(now.getTime() - 24 * 60 * 60 * 1e3);
26
+ const recent = notifications.filter((notification) => {
27
+ const createdAt = new Date(notification.created_at);
28
+ return createdAt >= twentyFourHoursAgo;
29
+ });
30
+ return {
31
+ byAlertType,
32
+ recent,
33
+ count: notifications.length
34
+ };
35
+ }, [notifications]);
36
+ }
37
+
38
+ // src/hooks/useNotificationCount.ts
39
+ function useNotificationCount(userId) {
40
+ const groups = useNotificationGroups(userId);
41
+ return groups.count;
42
+ }
43
+
44
+ exports.useNotificationCount = useNotificationCount;
45
+ exports.useNotificationGroups = useNotificationGroups;
46
+ //# sourceMappingURL=index.cjs.map
47
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/useNotificationGroups.ts","../src/hooks/useNotificationCount.ts"],"names":["useNotifications","useMemo"],"mappings":";;;;;;AAqBO,SAAS,sBAAsB,MAAA,EAAoC;AACxE,EAAA,MAAM,EAAE,IAAA,EAAM,aAAA,KAAkBA,wCAAA,C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s","sourcesContent":["import { useMemo } from 'react';\nimport { useNotifications } from '@pfm-platform/notifications-data-access';\nimport type { Notification } from '@pfm-platform/shared';\n\nexport interface NotificationGroups {\n byAlertType: Record<string, Notification[]>;\n recent: Notification[];\n count: number;\n}\n\n/**\n * Group notifications by alert type and identify recent notifications\n *\n * Business logic:\n * - byAlertType: Group notifications by their alert_type (AccountThresholdAlert, GoalAlert, etc.)\n * - recent: Notifications from last 24 hours\n * - count: Total notification count\n *\n * @param userId - User ID to fetch notifications for\n * @returns Object with grouped notifications and counts\n */\nexport function useNotificationGroups(userId: string): NotificationGroups {\n const { data: notifications } = useNotifications({ userId });\n\n return useMemo(() => {\n if (!notifications || notifications.length === 0) {\n return {\n byAlertType: {},\n recent: [],\n count: 0,\n };\n }\n\n // Group by alert type\n const byAlertType: Record<string, Notification[]> = {};\n notifications.forEach((notification) => {\n if (!byAlertType[notification.alert_type]) {\n byAlertType[notification.alert_type] = [];\n }\n byAlertType[notification.alert_type].push(notification);\n });\n\n // Filter recent notifications (last 24 hours)\n const now = new Date();\n const twentyFourHoursAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);\n\n const recent = notifications.filter((notification) => {\n const createdAt = new Date(notification.created_at);\n return createdAt >= twentyFourHoursAgo;\n });\n\n return {\n byAlertType,\n recent,\n count: notifications.length,\n };\n }, [notifications]);\n}\n","import { useNotificationGroups, type NotificationGroups } from './useNotificationGroups';\n\n/**\n * Returns the count of unread notifications for a user\n *\n * @param userId - User ID to get notification count for\n * @returns Number of unread notifications\n *\n * @example\n * ```tsx\n * function NotificationBadge({ userId }: { userId: string }) {\n * const count = useNotificationCount(userId);\n * return <Badge badgeContent={count}>...</Badge>;\n * }\n * ```\n */\nexport function useNotificationCount(userId: string): number {\n const groups: NotificationGroups = useNotificationGroups(userId);\n\n // Return the total count from the groups\n return groups.count;\n}\n"]}
@@ -0,0 +1,37 @@
1
+ import { Notification } from '@pfm-platform/shared';
2
+
3
+ interface NotificationGroups {
4
+ byAlertType: Record<string, Notification[]>;
5
+ recent: Notification[];
6
+ count: number;
7
+ }
8
+ /**
9
+ * Group notifications by alert type and identify recent notifications
10
+ *
11
+ * Business logic:
12
+ * - byAlertType: Group notifications by their alert_type (AccountThresholdAlert, GoalAlert, etc.)
13
+ * - recent: Notifications from last 24 hours
14
+ * - count: Total notification count
15
+ *
16
+ * @param userId - User ID to fetch notifications for
17
+ * @returns Object with grouped notifications and counts
18
+ */
19
+ declare function useNotificationGroups(userId: string): NotificationGroups;
20
+
21
+ /**
22
+ * Returns the count of unread notifications for a user
23
+ *
24
+ * @param userId - User ID to get notification count for
25
+ * @returns Number of unread notifications
26
+ *
27
+ * @example
28
+ * ```tsx
29
+ * function NotificationBadge({ userId }: { userId: string }) {
30
+ * const count = useNotificationCount(userId);
31
+ * return <Badge badgeContent={count}>...</Badge>;
32
+ * }
33
+ * ```
34
+ */
35
+ declare function useNotificationCount(userId: string): number;
36
+
37
+ export { type NotificationGroups, useNotificationCount, useNotificationGroups };
@@ -0,0 +1,37 @@
1
+ import { Notification } from '@pfm-platform/shared';
2
+
3
+ interface NotificationGroups {
4
+ byAlertType: Record<string, Notification[]>;
5
+ recent: Notification[];
6
+ count: number;
7
+ }
8
+ /**
9
+ * Group notifications by alert type and identify recent notifications
10
+ *
11
+ * Business logic:
12
+ * - byAlertType: Group notifications by their alert_type (AccountThresholdAlert, GoalAlert, etc.)
13
+ * - recent: Notifications from last 24 hours
14
+ * - count: Total notification count
15
+ *
16
+ * @param userId - User ID to fetch notifications for
17
+ * @returns Object with grouped notifications and counts
18
+ */
19
+ declare function useNotificationGroups(userId: string): NotificationGroups;
20
+
21
+ /**
22
+ * Returns the count of unread notifications for a user
23
+ *
24
+ * @param userId - User ID to get notification count for
25
+ * @returns Number of unread notifications
26
+ *
27
+ * @example
28
+ * ```tsx
29
+ * function NotificationBadge({ userId }: { userId: string }) {
30
+ * const count = useNotificationCount(userId);
31
+ * return <Badge badgeContent={count}>...</Badge>;
32
+ * }
33
+ * ```
34
+ */
35
+ declare function useNotificationCount(userId: string): number;
36
+
37
+ export { type NotificationGroups, useNotificationCount, useNotificationGroups };
package/dist/index.js ADDED
@@ -0,0 +1,44 @@
1
+ import { useMemo } from 'react';
2
+ import { useNotifications } from '@pfm-platform/notifications-data-access';
3
+
4
+ // src/hooks/useNotificationGroups.ts
5
+ function useNotificationGroups(userId) {
6
+ const { data: notifications } = useNotifications({ userId });
7
+ return useMemo(() => {
8
+ if (!notifications || notifications.length === 0) {
9
+ return {
10
+ byAlertType: {},
11
+ recent: [],
12
+ count: 0
13
+ };
14
+ }
15
+ const byAlertType = {};
16
+ notifications.forEach((notification) => {
17
+ if (!byAlertType[notification.alert_type]) {
18
+ byAlertType[notification.alert_type] = [];
19
+ }
20
+ byAlertType[notification.alert_type].push(notification);
21
+ });
22
+ const now = /* @__PURE__ */ new Date();
23
+ const twentyFourHoursAgo = new Date(now.getTime() - 24 * 60 * 60 * 1e3);
24
+ const recent = notifications.filter((notification) => {
25
+ const createdAt = new Date(notification.created_at);
26
+ return createdAt >= twentyFourHoursAgo;
27
+ });
28
+ return {
29
+ byAlertType,
30
+ recent,
31
+ count: notifications.length
32
+ };
33
+ }, [notifications]);
34
+ }
35
+
36
+ // src/hooks/useNotificationCount.ts
37
+ function useNotificationCount(userId) {
38
+ const groups = useNotificationGroups(userId);
39
+ return groups.count;
40
+ }
41
+
42
+ export { useNotificationCount, useNotificationGroups };
43
+ //# sourceMappingURL=index.js.map
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/useNotificationGroups.ts","../src/hooks/useNotificationCount.ts"],"names":[],"mappings":";;;;AAqBO,SAAS,sBAAsB,MAAA,EAAoC;AACxE,EAAA,MAAM,EAAE,IAAA,EAAM,aAAA,KAAkB,gBAAA,CAAiB,EAAE,QAAQ,CAAA;AAE3D,EAAA,OAAO,QAAQ,MAAM;AACnB,IAAA,IAAI,CAAC,aAAA,IAAiB,aAAA,CAAc,MAAA,KAAW,CAAA,EAAG;AAChD,MAAA,OAAO;AAAA,QACL,aAAa,EAAC;AAAA,QACd,QAAQ,EAAC;AAAA,QACT,KAAA,EAAO;AAAA,OACT;AAAA,IACF;AAGA,IAAA,MAAM,cAA8C,EAAC;AACrD,IAAA,aAAA,CAAc,OAAA,CAAQ,CAAC,YAAA,KAAiB;AACtC,MAAA,IAAI,CAAC,WAAA,CAAY,YAAA,CAAa,UAAU,CAAA,EAAG;AACzC,QAAA,WAAA,CAAY,YAAA,CAAa,UAAU,CAAA,GAAI,EAAC;AAAA,MAC1C;AACA,MAAA,WAAA,CAAY,YAAA,CAAa,UAAU,CAAA,CAAE,IAAA,CAAK,YAAY,CAAA;AAAA,IACxD,CAAC,CAAA;AAGD,IAAA,MAAM,GAAA,uBAAU,IAAA,EAAK;AACrB,IAAA,MAAM,kBAAA,GAAqB,IAAI,IAAA,CAAK,GAAA,CAAI,SAAQ,GAAI,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK,GAAI,CAAA;AAEvE,IAAA,MAAM,MAAA,GAAS,aAAA,CAAc,MAAA,CAAO,CAAC,YAAA,KAAiB;AACpD,MAAA,MAAM,SAAA,GAAY,IAAI,IAAA,CAAK,YAAA,CAAa,UAAU,CAAA;AAClD,MAAA,OAAO,SAAA,IAAa,kBAAA;AAAA,IACtB,CAAC,CAAA;AAED,IAAA,OAAO;AAAA,MACL,WAAA;AAAA,MACA,MAAA;AAAA,MACA,OAAO,aAAA,CAAc;AAAA,KACvB;AAAA,EACF,CAAA,EAAG,CAAC,aAAa,CAAC,CAAA;AACpB;;;ACzCO,SAAS,qBAAqB,MAAA,EAAwB;AAC3D,EAAA,MAAM,MAAA,GAA6B,sBAAsB,MAAM,CAAA;AAG/D,EAAA,OAAO,MAAA,CAAO,KAAA;AAChB","file":"index.js","sourcesContent":["import { useMemo } from 'react';\nimport { useNotifications } from '@pfm-platform/notifications-data-access';\nimport type { Notification } from '@pfm-platform/shared';\n\nexport interface NotificationGroups {\n byAlertType: Record<string, Notification[]>;\n recent: Notification[];\n count: number;\n}\n\n/**\n * Group notifications by alert type and identify recent notifications\n *\n * Business logic:\n * - byAlertType: Group notifications by their alert_type (AccountThresholdAlert, GoalAlert, etc.)\n * - recent: Notifications from last 24 hours\n * - count: Total notification count\n *\n * @param userId - User ID to fetch notifications for\n * @returns Object with grouped notifications and counts\n */\nexport function useNotificationGroups(userId: string): NotificationGroups {\n const { data: notifications } = useNotifications({ userId });\n\n return useMemo(() => {\n if (!notifications || notifications.length === 0) {\n return {\n byAlertType: {},\n recent: [],\n count: 0,\n };\n }\n\n // Group by alert type\n const byAlertType: Record<string, Notification[]> = {};\n notifications.forEach((notification) => {\n if (!byAlertType[notification.alert_type]) {\n byAlertType[notification.alert_type] = [];\n }\n byAlertType[notification.alert_type].push(notification);\n });\n\n // Filter recent notifications (last 24 hours)\n const now = new Date();\n const twentyFourHoursAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);\n\n const recent = notifications.filter((notification) => {\n const createdAt = new Date(notification.created_at);\n return createdAt >= twentyFourHoursAgo;\n });\n\n return {\n byAlertType,\n recent,\n count: notifications.length,\n };\n }, [notifications]);\n}\n","import { useNotificationGroups, type NotificationGroups } from './useNotificationGroups';\n\n/**\n * Returns the count of unread notifications for a user\n *\n * @param userId - User ID to get notification count for\n * @returns Number of unread notifications\n *\n * @example\n * ```tsx\n * function NotificationBadge({ userId }: { userId: string }) {\n * const count = useNotificationCount(userId);\n * return <Badge badgeContent={count}>...</Badge>;\n * }\n * ```\n */\nexport function useNotificationCount(userId: string): number {\n const groups: NotificationGroups = useNotificationGroups(userId);\n\n // Return the total count from the groups\n return groups.count;\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@pfm-platform/notifications-feature",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "dependencies": {
7
+ "react": "19.2.0",
8
+ "@pfm-platform/notifications-data-access": "0.1.1",
9
+ "@pfm-platform/shared": "0.0.1"
10
+ },
11
+ "devDependencies": {
12
+ "@tanstack/react-query": "5.90.9",
13
+ "@testing-library/react": "^16.3.0",
14
+ "@types/react": "^19.2.5",
15
+ "@vitejs/plugin-react": "^5.1.1",
16
+ "@vitest/coverage-v8": "^4.0.9",
17
+ "jsdom": "^27.2.0",
18
+ "react-dom": "19.2.0",
19
+ "typescript": "5.9.3",
20
+ "vitest": "4.0.9"
21
+ },
22
+ "module": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js",
28
+ "require": "./dist/index.cjs"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "README.md"
34
+ ],
35
+ "description": "Personal Finance Management - NOTIFICATIONS feature layer",
36
+ "keywords": [
37
+ "pfm",
38
+ "finance",
39
+ "notifications",
40
+ "feature",
41
+ "react",
42
+ "typescript"
43
+ ],
44
+ "author": "Lenny Miller",
45
+ "license": "MIT",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "https://github.com/lennylmiller/pfm-research",
49
+ "directory": "packages/notifications/feature"
50
+ },
51
+ "bugs": "https://github.com/lennylmiller/pfm-research/issues",
52
+ "homepage": "https://github.com/lennylmiller/pfm-research#readme",
53
+ "scripts": {
54
+ "test": "vitest run",
55
+ "test:watch": "vitest",
56
+ "test:ui": "vitest --ui",
57
+ "test:coverage": "vitest run --coverage",
58
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean"
59
+ }
60
+ }