@pfm-platform/alerts-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 +48 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +25 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var alertsDataAccess = require('@pfm-platform/alerts-data-access');
|
|
5
|
+
|
|
6
|
+
// src/hooks/useAlertFilters.ts
|
|
7
|
+
function useAlertFilters(userId) {
|
|
8
|
+
const { data: alerts } = alertsDataAccess.useAlerts({ userId });
|
|
9
|
+
return react.useMemo(() => {
|
|
10
|
+
if (!alerts || alerts.length === 0) {
|
|
11
|
+
return {
|
|
12
|
+
byType: {},
|
|
13
|
+
byDelivery: { email: [], sms: [], both: [] },
|
|
14
|
+
bySource: {}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const byType = {};
|
|
18
|
+
alerts.forEach((alert) => {
|
|
19
|
+
if (!byType[alert.type]) {
|
|
20
|
+
byType[alert.type] = [];
|
|
21
|
+
}
|
|
22
|
+
byType[alert.type].push(alert);
|
|
23
|
+
});
|
|
24
|
+
const byDelivery = {
|
|
25
|
+
email: alerts.filter((alert) => alert.email_delivery && !alert.sms_delivery),
|
|
26
|
+
sms: alerts.filter((alert) => !alert.email_delivery && alert.sms_delivery),
|
|
27
|
+
both: alerts.filter((alert) => alert.email_delivery && alert.sms_delivery)
|
|
28
|
+
};
|
|
29
|
+
const bySource = {};
|
|
30
|
+
alerts.forEach((alert) => {
|
|
31
|
+
if (alert.source_type) {
|
|
32
|
+
if (!bySource[alert.source_type]) {
|
|
33
|
+
bySource[alert.source_type] = [];
|
|
34
|
+
}
|
|
35
|
+
bySource[alert.source_type].push(alert);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
byType,
|
|
40
|
+
byDelivery,
|
|
41
|
+
bySource
|
|
42
|
+
};
|
|
43
|
+
}, [alerts]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
exports.useAlertFilters = useAlertFilters;
|
|
47
|
+
//# sourceMappingURL=index.cjs.map
|
|
48
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useAlertFilters.ts"],"names":["useAlerts","useMemo"],"mappings":";;;;;;AAyBO,SAAS,gBAAgB,MAAA,EAA8B;AAC5D,EAAA,MAAM,EAAE,IAAA,EAAM,MAAA,KAAWA,0BAAA,CAAU,EAAE,QAAQ,CAAA;AAE7C,EAAA,OAAOC,cAAQ,MAAM;AACnB,IAAA,IAAI,CAAC,MAAA,IAAU,MAAA,CAAO,MAAA,KAAW,CAAA,EAAG;AAClC,MAAA,OAAO;AAAA,QACL,QAAQ,EAAC;AAAA,QACT,UAAA,EAAY,EAAE,KAAA,EAAO,EAAC,EAAG,KAAK,EAAC,EAAG,IAAA,EAAM,EAAC,EAAE;AAAA,QAC3C,UAAU;AAAC,OACb;AAAA,IACF;AAGA,IAAA,MAAM,SAAkC,EAAC;AACzC,IAAA,MAAA,CAAO,OAAA,CAAQ,CAAC,KAAA,KAAU;AACxB,MAAA,IAAI,CAAC,MAAA,CAAO,KAAA,CAAM,IAAI,CAAA,EAAG;AACvB,QAAA,MAAA,CAAO,KAAA,CAAM,IAAI,CAAA,GAAI,EAAC;AAAA,MACxB;AACA,MAAA,MAAA,CAAO,KAAA,CAAM,IAAI,CAAA,CAAE,IAAA,CAAK,KAAK,CAAA;AAAA,IAC/B,CAAC,CAAA;AAGD,IAAA,MAAM,UAAA,GAAa;AAAA,MACjB,KAAA,EAAO,OAAO,MAAA,CAAO,CAAC,UAAU,KAAA,CAAM,cAAA,IAAkB,CAAC,KAAA,CAAM,YAAY,CAAA;AAAA,MAC3E,GAAA,EAAK,OAAO,MAAA,CAAO,CAAC,UAAU,CAAC,KAAA,CAAM,cAAA,IAAkB,KAAA,CAAM,YAAY,CAAA;AAAA,MACzE,IAAA,EAAM,OAAO,MAAA,CAAO,CAAC,UAAU,KAAA,CAAM,cAAA,IAAkB,MAAM,YAAY;AAAA,KAC3E;AAGA,IAAA,MAAM,WAAoC,EAAC;AAC3C,IAAA,MAAA,CAAO,OAAA,CAAQ,CAAC,KAAA,KAAU;AACxB,MAAA,IAAI,MAAM,WAAA,EAAa;AACrB,QAAA,IAAI,CAAC,QAAA,CAAS,KAAA,CAAM,WAAW,CAAA,EAAG;AAChC,UAAA,QAAA,CAAS,KAAA,CAAM,WAAW,CAAA,GAAI,EAAC;AAAA,QACjC;AACA,QAAA,QAAA,CAAS,KAAA,CAAM,WAAW,CAAA,CAAE,IAAA,CAAK,KAAK,CAAA;AAAA,MACxC;AAAA,IACF,CAAC,CAAA;AAED,IAAA,OAAO;AAAA,MACL,MAAA;AAAA,MACA,UAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF,CAAA,EAAG,CAAC,MAAM,CAAC,CAAA;AACb","file":"index.cjs","sourcesContent":["import { useMemo } from 'react';\nimport { useAlerts } from '@pfm-platform/alerts-data-access';\nimport type { Alert } from '@pfm-platform/shared';\n\nexport interface AlertFilters {\n byType: Record<string, Alert[]>;\n byDelivery: {\n email: Alert[];\n sms: Alert[];\n both: Alert[];\n };\n bySource: Record<string, Alert[]>;\n}\n\n/**\n * Filter and categorize alerts by type, delivery method, and source\n *\n * Business logic:\n * - byType: Group alerts by alert type (AccountThresholdAlert, GoalAlert, etc.)\n * - byDelivery: Categorize by delivery method (email only, SMS only, both)\n * - bySource: Group by source type (Account, Budget, Goal, etc.)\n *\n * @param userId - User ID to fetch alerts for\n * @returns Object with categorized alert arrays\n */\nexport function useAlertFilters(userId: string): AlertFilters {\n const { data: alerts } = useAlerts({ userId });\n\n return useMemo(() => {\n if (!alerts || alerts.length === 0) {\n return {\n byType: {},\n byDelivery: { email: [], sms: [], both: [] },\n bySource: {},\n };\n }\n\n // Group by alert type\n const byType: Record<string, Alert[]> = {};\n alerts.forEach((alert) => {\n if (!byType[alert.type]) {\n byType[alert.type] = [];\n }\n byType[alert.type].push(alert);\n });\n\n // Categorize by delivery method\n const byDelivery = {\n email: alerts.filter((alert) => alert.email_delivery && !alert.sms_delivery),\n sms: alerts.filter((alert) => !alert.email_delivery && alert.sms_delivery),\n both: alerts.filter((alert) => alert.email_delivery && alert.sms_delivery),\n };\n\n // Group by source type\n const bySource: Record<string, Alert[]> = {};\n alerts.forEach((alert) => {\n if (alert.source_type) {\n if (!bySource[alert.source_type]) {\n bySource[alert.source_type] = [];\n }\n bySource[alert.source_type].push(alert);\n }\n });\n\n return {\n byType,\n byDelivery,\n bySource,\n };\n }, [alerts]);\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Alert } from '@pfm-platform/shared';
|
|
2
|
+
|
|
3
|
+
interface AlertFilters {
|
|
4
|
+
byType: Record<string, Alert[]>;
|
|
5
|
+
byDelivery: {
|
|
6
|
+
email: Alert[];
|
|
7
|
+
sms: Alert[];
|
|
8
|
+
both: Alert[];
|
|
9
|
+
};
|
|
10
|
+
bySource: Record<string, Alert[]>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Filter and categorize alerts by type, delivery method, and source
|
|
14
|
+
*
|
|
15
|
+
* Business logic:
|
|
16
|
+
* - byType: Group alerts by alert type (AccountThresholdAlert, GoalAlert, etc.)
|
|
17
|
+
* - byDelivery: Categorize by delivery method (email only, SMS only, both)
|
|
18
|
+
* - bySource: Group by source type (Account, Budget, Goal, etc.)
|
|
19
|
+
*
|
|
20
|
+
* @param userId - User ID to fetch alerts for
|
|
21
|
+
* @returns Object with categorized alert arrays
|
|
22
|
+
*/
|
|
23
|
+
declare function useAlertFilters(userId: string): AlertFilters;
|
|
24
|
+
|
|
25
|
+
export { type AlertFilters, useAlertFilters };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Alert } from '@pfm-platform/shared';
|
|
2
|
+
|
|
3
|
+
interface AlertFilters {
|
|
4
|
+
byType: Record<string, Alert[]>;
|
|
5
|
+
byDelivery: {
|
|
6
|
+
email: Alert[];
|
|
7
|
+
sms: Alert[];
|
|
8
|
+
both: Alert[];
|
|
9
|
+
};
|
|
10
|
+
bySource: Record<string, Alert[]>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Filter and categorize alerts by type, delivery method, and source
|
|
14
|
+
*
|
|
15
|
+
* Business logic:
|
|
16
|
+
* - byType: Group alerts by alert type (AccountThresholdAlert, GoalAlert, etc.)
|
|
17
|
+
* - byDelivery: Categorize by delivery method (email only, SMS only, both)
|
|
18
|
+
* - bySource: Group by source type (Account, Budget, Goal, etc.)
|
|
19
|
+
*
|
|
20
|
+
* @param userId - User ID to fetch alerts for
|
|
21
|
+
* @returns Object with categorized alert arrays
|
|
22
|
+
*/
|
|
23
|
+
declare function useAlertFilters(userId: string): AlertFilters;
|
|
24
|
+
|
|
25
|
+
export { type AlertFilters, useAlertFilters };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useAlerts } from '@pfm-platform/alerts-data-access';
|
|
3
|
+
|
|
4
|
+
// src/hooks/useAlertFilters.ts
|
|
5
|
+
function useAlertFilters(userId) {
|
|
6
|
+
const { data: alerts } = useAlerts({ userId });
|
|
7
|
+
return useMemo(() => {
|
|
8
|
+
if (!alerts || alerts.length === 0) {
|
|
9
|
+
return {
|
|
10
|
+
byType: {},
|
|
11
|
+
byDelivery: { email: [], sms: [], both: [] },
|
|
12
|
+
bySource: {}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const byType = {};
|
|
16
|
+
alerts.forEach((alert) => {
|
|
17
|
+
if (!byType[alert.type]) {
|
|
18
|
+
byType[alert.type] = [];
|
|
19
|
+
}
|
|
20
|
+
byType[alert.type].push(alert);
|
|
21
|
+
});
|
|
22
|
+
const byDelivery = {
|
|
23
|
+
email: alerts.filter((alert) => alert.email_delivery && !alert.sms_delivery),
|
|
24
|
+
sms: alerts.filter((alert) => !alert.email_delivery && alert.sms_delivery),
|
|
25
|
+
both: alerts.filter((alert) => alert.email_delivery && alert.sms_delivery)
|
|
26
|
+
};
|
|
27
|
+
const bySource = {};
|
|
28
|
+
alerts.forEach((alert) => {
|
|
29
|
+
if (alert.source_type) {
|
|
30
|
+
if (!bySource[alert.source_type]) {
|
|
31
|
+
bySource[alert.source_type] = [];
|
|
32
|
+
}
|
|
33
|
+
bySource[alert.source_type].push(alert);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
byType,
|
|
38
|
+
byDelivery,
|
|
39
|
+
bySource
|
|
40
|
+
};
|
|
41
|
+
}, [alerts]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { useAlertFilters };
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
46
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useAlertFilters.ts"],"names":[],"mappings":";;;;AAyBO,SAAS,gBAAgB,MAAA,EAA8B;AAC5D,EAAA,MAAM,EAAE,IAAA,EAAM,MAAA,KAAW,SAAA,CAAU,EAAE,QAAQ,CAAA;AAE7C,EAAA,OAAO,QAAQ,MAAM;AACnB,IAAA,IAAI,CAAC,MAAA,IAAU,MAAA,CAAO,MAAA,KAAW,CAAA,EAAG;AAClC,MAAA,OAAO;AAAA,QACL,QAAQ,EAAC;AAAA,QACT,UAAA,EAAY,EAAE,KAAA,EAAO,EAAC,EAAG,KAAK,EAAC,EAAG,IAAA,EAAM,EAAC,EAAE;AAAA,QAC3C,UAAU;AAAC,OACb;AAAA,IACF;AAGA,IAAA,M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access';\nimport type { Alert } from '@pfm-platform/shared';\n\nexport interface AlertFilters {\n byType: Record<string, Alert[]>;\n byDelivery: {\n email: Alert[];\n sms: Alert[];\n both: Alert[];\n };\n bySource: Record<string, Alert[]>;\n}\n\n/**\n * Filter and categorize alerts by type, delivery method, and source\n *\n * Business logic:\n * - byType: Group alerts by alert type (AccountThresholdAlert, GoalAlert, etc.)\n * - byDelivery: Categorize by delivery method (email only, SMS only, both)\n * - bySource: Group by source type (Account, Budget, Goal, etc.)\n *\n * @param userId - User ID to fetch alerts for\n * @returns Object with categorized alert arrays\n */\nexport function useAlertFilters(userId: string): AlertFilters {\n const { data: alerts } = useAlerts({ userId });\n\n return useMemo(() => {\n if (!alerts || alerts.length === 0) {\n return {\n byType: {},\n byDelivery: { email: [], sms: [], both: [] },\n bySource: {},\n };\n }\n\n // Group by alert type\n const byType: Record<string, Alert[]> = {};\n alerts.forEach((alert) => {\n if (!byType[alert.type]) {\n byType[alert.type] = [];\n }\n byType[alert.type].push(alert);\n });\n\n // Categorize by delivery method\n const byDelivery = {\n email: alerts.filter((alert) => alert.email_delivery && !alert.sms_delivery),\n sms: alerts.filter((alert) => !alert.email_delivery && alert.sms_delivery),\n both: alerts.filter((alert) => alert.email_delivery && alert.sms_delivery),\n };\n\n // Group by source type\n const bySource: Record<string, Alert[]> = {};\n alerts.forEach((alert) => {\n if (alert.source_type) {\n if (!bySource[alert.source_type]) {\n bySource[alert.source_type] = [];\n }\n bySource[alert.source_type].push(alert);\n }\n });\n\n return {\n byType,\n byDelivery,\n bySource,\n };\n }, [alerts]);\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pfm-platform/alerts-feature",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"react": "19.2.0",
|
|
8
|
+
"@pfm-platform/alerts-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 - ALERTS feature layer",
|
|
36
|
+
"keywords": [
|
|
37
|
+
"pfm",
|
|
38
|
+
"finance",
|
|
39
|
+
"alerts",
|
|
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/alerts/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
|
+
}
|