@pfm-platform/alerts-data-access 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 +166 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +157 -0
- package/dist/index.d.ts +157 -0
- package/dist/index.js +152 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var reactQuery = require('@tanstack/react-query');
|
|
4
|
+
var shared = require('@pfm-platform/shared');
|
|
5
|
+
var axios = require('axios');
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var axios__default = /*#__PURE__*/_interopDefault(axios);
|
|
10
|
+
|
|
11
|
+
// src/queries/useAlerts.ts
|
|
12
|
+
var api = axios__default.default.create({
|
|
13
|
+
baseURL: "/api",
|
|
14
|
+
headers: {
|
|
15
|
+
"Content-Type": "application/json"
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// src/keys.ts
|
|
20
|
+
var alertKeys = {
|
|
21
|
+
all: ["alerts"],
|
|
22
|
+
// Alert lists and details
|
|
23
|
+
lists: () => [...alertKeys.all, "list"],
|
|
24
|
+
list: (userId) => [...alertKeys.lists(), userId],
|
|
25
|
+
details: () => [...alertKeys.all, "detail"],
|
|
26
|
+
detail: (userId, alertId) => [...alertKeys.details(), userId, alertId],
|
|
27
|
+
// Alert destinations
|
|
28
|
+
destinations: (userId) => [...alertKeys.all, "destinations", userId]
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// src/queries/useAlerts.ts
|
|
32
|
+
function useAlerts({ userId }, options) {
|
|
33
|
+
return reactQuery.useQuery({
|
|
34
|
+
queryKey: alertKeys.list(userId),
|
|
35
|
+
queryFn: async () => {
|
|
36
|
+
const response = await api.get(`/users/${userId}/alerts`);
|
|
37
|
+
const validated = shared.AlertsResponseSchema.parse(response.data);
|
|
38
|
+
return validated.alerts;
|
|
39
|
+
},
|
|
40
|
+
staleTime: 1e3 * 60 * 5,
|
|
41
|
+
// 5 minutes (alerts change moderately)
|
|
42
|
+
...options
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function useAlert({ userId, alertId }, options) {
|
|
46
|
+
return reactQuery.useQuery({
|
|
47
|
+
queryKey: alertKeys.detail(userId, alertId),
|
|
48
|
+
queryFn: async () => {
|
|
49
|
+
const response = await api.get(`/users/${userId}/alerts/${alertId}`);
|
|
50
|
+
return shared.AlertSchema.parse(response.data);
|
|
51
|
+
},
|
|
52
|
+
staleTime: 1e3 * 60 * 5,
|
|
53
|
+
// 5 minutes
|
|
54
|
+
...options
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function useAlertDestinations({ userId }, options) {
|
|
58
|
+
return reactQuery.useQuery({
|
|
59
|
+
queryKey: alertKeys.destinations(userId),
|
|
60
|
+
queryFn: async () => {
|
|
61
|
+
const response = await api.get(`/users/${userId}/alert_destinations`);
|
|
62
|
+
return shared.AlertDestinationsSchema.parse(response.data);
|
|
63
|
+
},
|
|
64
|
+
staleTime: 1e3 * 60 * 10,
|
|
65
|
+
// 10 minutes (destinations rarely change)
|
|
66
|
+
...options
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function useCreateAlert(options) {
|
|
70
|
+
const queryClient = reactQuery.useQueryClient();
|
|
71
|
+
const getEndpoint = (type) => {
|
|
72
|
+
const mapping = {
|
|
73
|
+
AccountThresholdAlert: "account_threshold_alerts",
|
|
74
|
+
GoalAlert: "goal_alerts",
|
|
75
|
+
MerchantNameAlert: "merchant_name_alerts",
|
|
76
|
+
SpendingTargetAlert: "spending_target_alerts",
|
|
77
|
+
TransactionLimitAlert: "transaction_limit_alerts",
|
|
78
|
+
UpcomingBillAlert: "upcoming_bill_alerts"
|
|
79
|
+
};
|
|
80
|
+
return mapping[type];
|
|
81
|
+
};
|
|
82
|
+
return reactQuery.useMutation({
|
|
83
|
+
mutationFn: async ({ userId, type, data }) => {
|
|
84
|
+
const validated = shared.AlertCreateSchema.parse(data);
|
|
85
|
+
const endpoint = getEndpoint(type);
|
|
86
|
+
const response = await api.post(`/users/${userId}/${endpoint}`, {
|
|
87
|
+
alert: validated
|
|
88
|
+
});
|
|
89
|
+
return shared.AlertSchema.parse(response.data);
|
|
90
|
+
},
|
|
91
|
+
onSuccess: (_, { userId }) => {
|
|
92
|
+
queryClient.invalidateQueries({ queryKey: alertKeys.list(userId) });
|
|
93
|
+
},
|
|
94
|
+
...options
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function useUpdateAlert(options) {
|
|
98
|
+
const queryClient = reactQuery.useQueryClient();
|
|
99
|
+
const getEndpoint = (type) => {
|
|
100
|
+
const mapping = {
|
|
101
|
+
AccountThresholdAlert: "account_threshold_alerts",
|
|
102
|
+
GoalAlert: "goal_alerts",
|
|
103
|
+
MerchantNameAlert: "merchant_name_alerts",
|
|
104
|
+
SpendingTargetAlert: "spending_target_alerts",
|
|
105
|
+
TransactionLimitAlert: "transaction_limit_alerts",
|
|
106
|
+
UpcomingBillAlert: "upcoming_bill_alerts"
|
|
107
|
+
};
|
|
108
|
+
return mapping[type];
|
|
109
|
+
};
|
|
110
|
+
return reactQuery.useMutation({
|
|
111
|
+
mutationFn: async ({ userId, alertId, type, data }) => {
|
|
112
|
+
const validated = shared.AlertUpdateSchema.parse(data);
|
|
113
|
+
const endpoint = getEndpoint(type);
|
|
114
|
+
const response = await api.put(`/users/${userId}/${endpoint}/${alertId}`, {
|
|
115
|
+
alert: validated
|
|
116
|
+
});
|
|
117
|
+
return shared.AlertSchema.parse(response.data);
|
|
118
|
+
},
|
|
119
|
+
onSuccess: (_, { userId, alertId }) => {
|
|
120
|
+
queryClient.invalidateQueries({ queryKey: alertKeys.list(userId) });
|
|
121
|
+
queryClient.invalidateQueries({ queryKey: alertKeys.detail(userId, alertId) });
|
|
122
|
+
},
|
|
123
|
+
...options
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function useDeleteAlert(options) {
|
|
127
|
+
const queryClient = reactQuery.useQueryClient();
|
|
128
|
+
return reactQuery.useMutation({
|
|
129
|
+
mutationFn: async ({ userId, alertId }) => {
|
|
130
|
+
await api.delete(`/users/${userId}/alerts/${alertId}`);
|
|
131
|
+
},
|
|
132
|
+
onSuccess: (_, { userId, alertId }) => {
|
|
133
|
+
queryClient.invalidateQueries({ queryKey: alertKeys.list(userId) });
|
|
134
|
+
queryClient.removeQueries({ queryKey: alertKeys.detail(userId, alertId) });
|
|
135
|
+
},
|
|
136
|
+
...options
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function useUpdateAlertDestinations(options) {
|
|
140
|
+
const queryClient = reactQuery.useQueryClient();
|
|
141
|
+
return reactQuery.useMutation({
|
|
142
|
+
mutationFn: async ({ userId, data }) => {
|
|
143
|
+
const validated = shared.AlertDestinationsUpdateSchema.parse(data);
|
|
144
|
+
const response = await api.put(`/users/${userId}/alert_destinations`, {
|
|
145
|
+
destinations: validated
|
|
146
|
+
});
|
|
147
|
+
return shared.AlertDestinationsSchema.parse(response.data);
|
|
148
|
+
},
|
|
149
|
+
onSuccess: (_, { userId }) => {
|
|
150
|
+
queryClient.invalidateQueries({ queryKey: alertKeys.destinations(userId) });
|
|
151
|
+
},
|
|
152
|
+
...options
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
exports.alertKeys = alertKeys;
|
|
157
|
+
exports.api = api;
|
|
158
|
+
exports.useAlert = useAlert;
|
|
159
|
+
exports.useAlertDestinations = useAlertDestinations;
|
|
160
|
+
exports.useAlerts = useAlerts;
|
|
161
|
+
exports.useCreateAlert = useCreateAlert;
|
|
162
|
+
exports.useDeleteAlert = useDeleteAlert;
|
|
163
|
+
exports.useUpdateAlert = useUpdateAlert;
|
|
164
|
+
exports.useUpdateAlertDestinations = useUpdateAlertDestinations;
|
|
165
|
+
//# sourceMappingURL=index.cjs.map
|
|
166
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/keys.ts","../src/queries/useAlerts.ts","../src/queries/useAlert.ts","../src/queries/useAlertDestinations.ts","../src/mutations/useCreateAlert.ts","../src/mutations/useUpdateAlert.ts","../src/mutations/useDeleteAlert.ts","../src/mutations/useUpdateAlertDestinations.ts"],"names":["axios","useQuery","AlertsResponseSchema","AlertSchema","AlertDestinationsSchema","useQueryClient","useMutation","AlertCreateSchema","AlertUpdateSchema","AlertDestinationsUpdateSchema"],"mappings":";;;;;;;;;;;AAMO,IAAM,GAAA,GAAMA,uBAAM,MAAA,CAAO;AAAA,EAC9B,OAAA,EAAS,MAAA;AAAA,EACT,OAAA,EAAS;AAAA,IACP,cAAA,EAAgB;AAAA;AAEpB,CAAC;;;ACPM,IAAM,SAAA,GAAY;AAAA,EACvB,GAAA,EAAK,CAAC,QAAQ,CAAA;AAAA;AAAA,EAGd,OAAO,MAAM,CAAC,GAAG,SAAA,CAAU,KAAK,MAAM,CAAA;AAAA,EACtC,IAAA,EAAM,CAAC,MAAA,KAAmB,CAAC,GAAG,SAAA,CAAU,KAAA,IAAS,MAAM,CAAA;AAAA,EACvD,SAAS,MAAM,CAAC,GAAG,SAAA,CAAU,KAAK,QAAQ,CAAA;AAAA,EAC1C,MAAA,EAAQ,CAAC,MAAA,EAAgB,OAAA,KACvB,CAAC,GAAG,SAAA,CAAU,OAAA,EAAQ,EAAG,MAAA,EAAQ,OAAO,CAAA;AAAA;AAAA,EAG1C,YAAA,EAAc,CAAC,MAAA,KACb,CAAC,GAAG,SAAA,CAAU,GAAA,EAAK,gBAAgB,MAAM;AAC7C;;;ACJO,SAAS,SAAA,CACd,EAAE,MAAA,EAAO,EACT,OAAA,EACA;AACA,EAAA,OAAOC,mBAAA,CAAS;AAAA,IACd,QAAA,EAAU,SAA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"index.cjs","sourcesContent":["import axios from 'axios';\n\n/**\n * Axios instance for Alerts API\n * Base URL configured through environment variables or defaults to relative path\n */\nexport const api = axios.create({\n baseURL: '/api',\n headers: {\n 'Content-Type': 'application/json',\n },\n});\n","/**\n * Query key factory for Alerts domain\n */\n\nexport const alertKeys = {\n all: ['alerts'] as const,\n\n // Alert lists and details\n lists: () => [...alertKeys.all, 'list'] as const,\n list: (userId: string) => [...alertKeys.lists(), userId] as const,\n details: () => [...alertKeys.all, 'detail'] as const,\n detail: (userId: string, alertId: number) =>\n [...alertKeys.details(), userId, alertId] as const,\n\n // Alert destinations\n destinations: (userId: string) =>\n [...alertKeys.all, 'destinations', userId] as const,\n};\n","import { useQuery, UseQueryOptions } from '@tanstack/react-query';\nimport { Alert, AlertsResponseSchema } from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { alertKeys } from '../keys.js';\n\nexport interface UseAlertsParams {\n userId: string;\n}\n\n/**\n * Fetch all alerts for a user\n * GET /users/:userId/alerts\n */\nexport function useAlerts(\n { userId }: UseAlertsParams,\n options?: Omit<UseQueryOptions<Alert[]>, 'queryKey' | 'queryFn'>\n) {\n return useQuery({\n queryKey: alertKeys.list(userId),\n queryFn: async () => {\n const response = await api.get(`/users/${userId}/alerts`);\n const validated = AlertsResponseSchema.parse(response.data);\n return validated.alerts;\n },\n staleTime: 1000 * 60 * 5, // 5 minutes (alerts change moderately)\n ...options,\n });\n}\n","import { useQuery, UseQueryOptions } from '@tanstack/react-query';\nimport { Alert, AlertSchema } from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { alertKeys } from '../keys.js';\n\nexport interface UseAlertParams {\n userId: string;\n alertId: number;\n}\n\n/**\n * Fetch a single alert by ID\n * GET /users/:userId/alerts/:alertId\n */\nexport function useAlert(\n { userId, alertId }: UseAlertParams,\n options?: Omit<UseQueryOptions<Alert>, 'queryKey' | 'queryFn'>\n) {\n return useQuery({\n queryKey: alertKeys.detail(userId, alertId),\n queryFn: async () => {\n const response = await api.get(`/users/${userId}/alerts/${alertId}`);\n return AlertSchema.parse(response.data);\n },\n staleTime: 1000 * 60 * 5, // 5 minutes\n ...options,\n });\n}\n","import { useQuery, UseQueryOptions } from '@tanstack/react-query';\nimport { AlertDestinations, AlertDestinationsSchema } from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { alertKeys } from '../keys.js';\n\nexport interface UseAlertDestinationsParams {\n userId: string;\n}\n\n/**\n * Fetch alert destinations for a user\n * GET /users/:userId/alert_destinations\n */\nexport function useAlertDestinations(\n { userId }: UseAlertDestinationsParams,\n options?: Omit<UseQueryOptions<AlertDestinations>, 'queryKey' | 'queryFn'>\n) {\n return useQuery({\n queryKey: alertKeys.destinations(userId),\n queryFn: async () => {\n const response = await api.get(`/users/${userId}/alert_destinations`);\n return AlertDestinationsSchema.parse(response.data);\n },\n staleTime: 1000 * 60 * 10, // 10 minutes (destinations rarely change)\n ...options,\n });\n}\n","import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query';\nimport { Alert, AlertCreate, AlertCreateSchema, AlertSchema, AlertType } from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { alertKeys } from '../keys.js';\n\nexport interface CreateAlertParams {\n userId: string;\n type: AlertType;\n data: AlertCreate;\n}\n\n/**\n * Create a new alert\n * POST /users/:userId/alerts/:type\n *\n * Type-based routing from legacy API routeMapping:\n * - AccountThresholdAlert → account_threshold_alerts\n * - GoalAlert → goal_alerts\n * - MerchantNameAlert → merchant_name_alerts\n * - SpendingTargetAlert → spending_target_alerts\n * - TransactionLimitAlert → transaction_limit_alerts\n * - UpcomingBillAlert → upcoming_bill_alerts\n */\nexport function useCreateAlert(\n options?: Omit<UseMutationOptions<Alert, Error, CreateAlertParams>, 'mutationFn'>\n) {\n const queryClient = useQueryClient();\n\n // Type to endpoint mapping\n const getEndpoint = (type: AlertType): string => {\n const mapping: Record<AlertType, string> = {\n AccountThresholdAlert: 'account_threshold_alerts',\n GoalAlert: 'goal_alerts',\n MerchantNameAlert: 'merchant_name_alerts',\n SpendingTargetAlert: 'spending_target_alerts',\n TransactionLimitAlert: 'transaction_limit_alerts',\n UpcomingBillAlert: 'upcoming_bill_alerts',\n };\n return mapping[type];\n };\n\n return useMutation({\n mutationFn: async ({ userId, type, data }: CreateAlertParams) => {\n const validated = AlertCreateSchema.parse(data);\n const endpoint = getEndpoint(type);\n const response = await api.post(`/users/${userId}/${endpoint}`, {\n alert: validated,\n });\n return AlertSchema.parse(response.data);\n },\n onSuccess: (_, { userId }) => {\n queryClient.invalidateQueries({ queryKey: alertKeys.list(userId) });\n },\n ...options,\n });\n}\n","import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query';\nimport { Alert, AlertUpdate, AlertUpdateSchema, AlertSchema, AlertType } from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { alertKeys } from '../keys.js';\n\nexport interface UpdateAlertParams {\n userId: string;\n alertId: number;\n type: AlertType;\n data: AlertUpdate;\n}\n\n/**\n * Update an existing alert\n * PUT /users/:userId/alerts/:type/:alertId\n *\n * Type-based routing - same mapping as create\n */\nexport function useUpdateAlert(\n options?: Omit<UseMutationOptions<Alert, Error, UpdateAlertParams>, 'mutationFn'>\n) {\n const queryClient = useQueryClient();\n\n // Type to endpoint mapping\n const getEndpoint = (type: AlertType): string => {\n const mapping: Record<AlertType, string> = {\n AccountThresholdAlert: 'account_threshold_alerts',\n GoalAlert: 'goal_alerts',\n MerchantNameAlert: 'merchant_name_alerts',\n SpendingTargetAlert: 'spending_target_alerts',\n TransactionLimitAlert: 'transaction_limit_alerts',\n UpcomingBillAlert: 'upcoming_bill_alerts',\n };\n return mapping[type];\n };\n\n return useMutation({\n mutationFn: async ({ userId, alertId, type, data }: UpdateAlertParams) => {\n const validated = AlertUpdateSchema.parse(data);\n const endpoint = getEndpoint(type);\n const response = await api.put(`/users/${userId}/${endpoint}/${alertId}`, {\n alert: validated,\n });\n return AlertSchema.parse(response.data);\n },\n onSuccess: (_, { userId, alertId }) => {\n queryClient.invalidateQueries({ queryKey: alertKeys.list(userId) });\n queryClient.invalidateQueries({ queryKey: alertKeys.detail(userId, alertId) });\n },\n ...options,\n });\n}\n","import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query';\nimport { api } from '../client.js';\nimport { alertKeys } from '../keys.js';\n\nexport interface DeleteAlertParams {\n userId: string;\n alertId: number;\n}\n\n/**\n * Delete an alert\n * DELETE /users/:userId/alerts/:alertId\n */\nexport function useDeleteAlert(\n options?: Omit<UseMutationOptions<void, Error, DeleteAlertParams>, 'mutationFn'>\n) {\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ userId, alertId }: DeleteAlertParams) => {\n await api.delete(`/users/${userId}/alerts/${alertId}`);\n },\n onSuccess: (_, { userId, alertId }) => {\n queryClient.invalidateQueries({ queryKey: alertKeys.list(userId) });\n queryClient.removeQueries({ queryKey: alertKeys.detail(userId, alertId) });\n },\n ...options,\n });\n}\n","import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query';\nimport {\n AlertDestinations,\n AlertDestinationsUpdate,\n AlertDestinationsUpdateSchema,\n AlertDestinationsSchema,\n} from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { alertKeys } from '../keys.js';\n\nexport interface UpdateAlertDestinationsParams {\n userId: string;\n data: AlertDestinationsUpdate;\n}\n\n/**\n * Update alert destinations for a user\n * PUT /users/:userId/alert_destinations\n */\nexport function useUpdateAlertDestinations(\n options?: Omit<UseMutationOptions<AlertDestinations, Error, UpdateAlertDestinationsParams>, 'mutationFn'>\n) {\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ userId, data }: UpdateAlertDestinationsParams) => {\n const validated = AlertDestinationsUpdateSchema.parse(data);\n const response = await api.put(`/users/${userId}/alert_destinations`, {\n destinations: validated,\n });\n return AlertDestinationsSchema.parse(response.data);\n },\n onSuccess: (_, { userId }) => {\n queryClient.invalidateQueries({ queryKey: alertKeys.destinations(userId) });\n },\n ...options,\n });\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
|
+
import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
3
|
+
import { Alert, AlertDestinations, AlertType, AlertCreate, AlertUpdate, AlertDestinationsUpdate } from '@pfm-platform/shared';
|
|
4
|
+
import * as axios from 'axios';
|
|
5
|
+
|
|
6
|
+
interface UseAlertsParams {
|
|
7
|
+
userId: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Fetch all alerts for a user
|
|
11
|
+
* GET /users/:userId/alerts
|
|
12
|
+
*/
|
|
13
|
+
declare function useAlerts({ userId }: UseAlertsParams, options?: Omit<UseQueryOptions<Alert[]>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<{
|
|
14
|
+
id: number;
|
|
15
|
+
type: "AccountThresholdAlert" | "GoalAlert" | "MerchantNameAlert" | "SpendingTargetAlert" | "TransactionLimitAlert" | "UpcomingBillAlert";
|
|
16
|
+
options: {
|
|
17
|
+
[x: string]: unknown;
|
|
18
|
+
};
|
|
19
|
+
email_delivery: boolean;
|
|
20
|
+
sms_delivery: boolean;
|
|
21
|
+
source_type: "Account" | "Budget" | "CashflowTransaction" | "PayoffGoal" | "SavingsGoal" | null;
|
|
22
|
+
source_id?: string | number | undefined;
|
|
23
|
+
source?: unknown;
|
|
24
|
+
}[], Error>;
|
|
25
|
+
|
|
26
|
+
interface UseAlertParams {
|
|
27
|
+
userId: string;
|
|
28
|
+
alertId: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Fetch a single alert by ID
|
|
32
|
+
* GET /users/:userId/alerts/:alertId
|
|
33
|
+
*/
|
|
34
|
+
declare function useAlert({ userId, alertId }: UseAlertParams, options?: Omit<UseQueryOptions<Alert>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<{
|
|
35
|
+
id: number;
|
|
36
|
+
type: "AccountThresholdAlert" | "GoalAlert" | "MerchantNameAlert" | "SpendingTargetAlert" | "TransactionLimitAlert" | "UpcomingBillAlert";
|
|
37
|
+
options: {
|
|
38
|
+
[x: string]: unknown;
|
|
39
|
+
};
|
|
40
|
+
email_delivery: boolean;
|
|
41
|
+
sms_delivery: boolean;
|
|
42
|
+
source_type: "Account" | "Budget" | "CashflowTransaction" | "PayoffGoal" | "SavingsGoal" | null;
|
|
43
|
+
source_id?: string | number | undefined;
|
|
44
|
+
source?: unknown;
|
|
45
|
+
}, Error>;
|
|
46
|
+
|
|
47
|
+
interface UseAlertDestinationsParams {
|
|
48
|
+
userId: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Fetch alert destinations for a user
|
|
52
|
+
* GET /users/:userId/alert_destinations
|
|
53
|
+
*/
|
|
54
|
+
declare function useAlertDestinations({ userId }: UseAlertDestinationsParams, options?: Omit<UseQueryOptions<AlertDestinations>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<{
|
|
55
|
+
email_address: string | null;
|
|
56
|
+
sms_number: string | null;
|
|
57
|
+
partner_sms_enabled: boolean;
|
|
58
|
+
}, Error>;
|
|
59
|
+
|
|
60
|
+
interface CreateAlertParams {
|
|
61
|
+
userId: string;
|
|
62
|
+
type: AlertType;
|
|
63
|
+
data: AlertCreate;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a new alert
|
|
67
|
+
* POST /users/:userId/alerts/:type
|
|
68
|
+
*
|
|
69
|
+
* Type-based routing from legacy API routeMapping:
|
|
70
|
+
* - AccountThresholdAlert → account_threshold_alerts
|
|
71
|
+
* - GoalAlert → goal_alerts
|
|
72
|
+
* - MerchantNameAlert → merchant_name_alerts
|
|
73
|
+
* - SpendingTargetAlert → spending_target_alerts
|
|
74
|
+
* - TransactionLimitAlert → transaction_limit_alerts
|
|
75
|
+
* - UpcomingBillAlert → upcoming_bill_alerts
|
|
76
|
+
*/
|
|
77
|
+
declare function useCreateAlert(options?: Omit<UseMutationOptions<Alert, Error, CreateAlertParams>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<{
|
|
78
|
+
id: number;
|
|
79
|
+
type: "AccountThresholdAlert" | "GoalAlert" | "MerchantNameAlert" | "SpendingTargetAlert" | "TransactionLimitAlert" | "UpcomingBillAlert";
|
|
80
|
+
options: {
|
|
81
|
+
[x: string]: unknown;
|
|
82
|
+
};
|
|
83
|
+
email_delivery: boolean;
|
|
84
|
+
sms_delivery: boolean;
|
|
85
|
+
source_type: "Account" | "Budget" | "CashflowTransaction" | "PayoffGoal" | "SavingsGoal" | null;
|
|
86
|
+
source_id?: string | number | undefined;
|
|
87
|
+
source?: unknown;
|
|
88
|
+
}, Error, CreateAlertParams, unknown>;
|
|
89
|
+
|
|
90
|
+
interface UpdateAlertParams {
|
|
91
|
+
userId: string;
|
|
92
|
+
alertId: number;
|
|
93
|
+
type: AlertType;
|
|
94
|
+
data: AlertUpdate;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Update an existing alert
|
|
98
|
+
* PUT /users/:userId/alerts/:type/:alertId
|
|
99
|
+
*
|
|
100
|
+
* Type-based routing - same mapping as create
|
|
101
|
+
*/
|
|
102
|
+
declare function useUpdateAlert(options?: Omit<UseMutationOptions<Alert, Error, UpdateAlertParams>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<{
|
|
103
|
+
id: number;
|
|
104
|
+
type: "AccountThresholdAlert" | "GoalAlert" | "MerchantNameAlert" | "SpendingTargetAlert" | "TransactionLimitAlert" | "UpcomingBillAlert";
|
|
105
|
+
options: {
|
|
106
|
+
[x: string]: unknown;
|
|
107
|
+
};
|
|
108
|
+
email_delivery: boolean;
|
|
109
|
+
sms_delivery: boolean;
|
|
110
|
+
source_type: "Account" | "Budget" | "CashflowTransaction" | "PayoffGoal" | "SavingsGoal" | null;
|
|
111
|
+
source_id?: string | number | undefined;
|
|
112
|
+
source?: unknown;
|
|
113
|
+
}, Error, UpdateAlertParams, unknown>;
|
|
114
|
+
|
|
115
|
+
interface DeleteAlertParams {
|
|
116
|
+
userId: string;
|
|
117
|
+
alertId: number;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Delete an alert
|
|
121
|
+
* DELETE /users/:userId/alerts/:alertId
|
|
122
|
+
*/
|
|
123
|
+
declare function useDeleteAlert(options?: Omit<UseMutationOptions<void, Error, DeleteAlertParams>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<void, Error, DeleteAlertParams, unknown>;
|
|
124
|
+
|
|
125
|
+
interface UpdateAlertDestinationsParams {
|
|
126
|
+
userId: string;
|
|
127
|
+
data: AlertDestinationsUpdate;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Update alert destinations for a user
|
|
131
|
+
* PUT /users/:userId/alert_destinations
|
|
132
|
+
*/
|
|
133
|
+
declare function useUpdateAlertDestinations(options?: Omit<UseMutationOptions<AlertDestinations, Error, UpdateAlertDestinationsParams>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<{
|
|
134
|
+
email_address: string | null;
|
|
135
|
+
sms_number: string | null;
|
|
136
|
+
partner_sms_enabled: boolean;
|
|
137
|
+
}, Error, UpdateAlertDestinationsParams, unknown>;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Query key factory for Alerts domain
|
|
141
|
+
*/
|
|
142
|
+
declare const alertKeys: {
|
|
143
|
+
all: readonly ["alerts"];
|
|
144
|
+
lists: () => readonly ["alerts", "list"];
|
|
145
|
+
list: (userId: string) => readonly ["alerts", "list", string];
|
|
146
|
+
details: () => readonly ["alerts", "detail"];
|
|
147
|
+
detail: (userId: string, alertId: number) => readonly ["alerts", "detail", string, number];
|
|
148
|
+
destinations: (userId: string) => readonly ["alerts", "destinations", string];
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Axios instance for Alerts API
|
|
153
|
+
* Base URL configured through environment variables or defaults to relative path
|
|
154
|
+
*/
|
|
155
|
+
declare const api: axios.AxiosInstance;
|
|
156
|
+
|
|
157
|
+
export { type CreateAlertParams, type DeleteAlertParams, type UpdateAlertDestinationsParams, type UpdateAlertParams, type UseAlertDestinationsParams, type UseAlertParams, type UseAlertsParams, alertKeys, api, useAlert, useAlertDestinations, useAlerts, useCreateAlert, useDeleteAlert, useUpdateAlert, useUpdateAlertDestinations };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
2
|
+
import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
3
|
+
import { Alert, AlertDestinations, AlertType, AlertCreate, AlertUpdate, AlertDestinationsUpdate } from '@pfm-platform/shared';
|
|
4
|
+
import * as axios from 'axios';
|
|
5
|
+
|
|
6
|
+
interface UseAlertsParams {
|
|
7
|
+
userId: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Fetch all alerts for a user
|
|
11
|
+
* GET /users/:userId/alerts
|
|
12
|
+
*/
|
|
13
|
+
declare function useAlerts({ userId }: UseAlertsParams, options?: Omit<UseQueryOptions<Alert[]>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<{
|
|
14
|
+
id: number;
|
|
15
|
+
type: "AccountThresholdAlert" | "GoalAlert" | "MerchantNameAlert" | "SpendingTargetAlert" | "TransactionLimitAlert" | "UpcomingBillAlert";
|
|
16
|
+
options: {
|
|
17
|
+
[x: string]: unknown;
|
|
18
|
+
};
|
|
19
|
+
email_delivery: boolean;
|
|
20
|
+
sms_delivery: boolean;
|
|
21
|
+
source_type: "Account" | "Budget" | "CashflowTransaction" | "PayoffGoal" | "SavingsGoal" | null;
|
|
22
|
+
source_id?: string | number | undefined;
|
|
23
|
+
source?: unknown;
|
|
24
|
+
}[], Error>;
|
|
25
|
+
|
|
26
|
+
interface UseAlertParams {
|
|
27
|
+
userId: string;
|
|
28
|
+
alertId: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Fetch a single alert by ID
|
|
32
|
+
* GET /users/:userId/alerts/:alertId
|
|
33
|
+
*/
|
|
34
|
+
declare function useAlert({ userId, alertId }: UseAlertParams, options?: Omit<UseQueryOptions<Alert>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<{
|
|
35
|
+
id: number;
|
|
36
|
+
type: "AccountThresholdAlert" | "GoalAlert" | "MerchantNameAlert" | "SpendingTargetAlert" | "TransactionLimitAlert" | "UpcomingBillAlert";
|
|
37
|
+
options: {
|
|
38
|
+
[x: string]: unknown;
|
|
39
|
+
};
|
|
40
|
+
email_delivery: boolean;
|
|
41
|
+
sms_delivery: boolean;
|
|
42
|
+
source_type: "Account" | "Budget" | "CashflowTransaction" | "PayoffGoal" | "SavingsGoal" | null;
|
|
43
|
+
source_id?: string | number | undefined;
|
|
44
|
+
source?: unknown;
|
|
45
|
+
}, Error>;
|
|
46
|
+
|
|
47
|
+
interface UseAlertDestinationsParams {
|
|
48
|
+
userId: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Fetch alert destinations for a user
|
|
52
|
+
* GET /users/:userId/alert_destinations
|
|
53
|
+
*/
|
|
54
|
+
declare function useAlertDestinations({ userId }: UseAlertDestinationsParams, options?: Omit<UseQueryOptions<AlertDestinations>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<{
|
|
55
|
+
email_address: string | null;
|
|
56
|
+
sms_number: string | null;
|
|
57
|
+
partner_sms_enabled: boolean;
|
|
58
|
+
}, Error>;
|
|
59
|
+
|
|
60
|
+
interface CreateAlertParams {
|
|
61
|
+
userId: string;
|
|
62
|
+
type: AlertType;
|
|
63
|
+
data: AlertCreate;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a new alert
|
|
67
|
+
* POST /users/:userId/alerts/:type
|
|
68
|
+
*
|
|
69
|
+
* Type-based routing from legacy API routeMapping:
|
|
70
|
+
* - AccountThresholdAlert → account_threshold_alerts
|
|
71
|
+
* - GoalAlert → goal_alerts
|
|
72
|
+
* - MerchantNameAlert → merchant_name_alerts
|
|
73
|
+
* - SpendingTargetAlert → spending_target_alerts
|
|
74
|
+
* - TransactionLimitAlert → transaction_limit_alerts
|
|
75
|
+
* - UpcomingBillAlert → upcoming_bill_alerts
|
|
76
|
+
*/
|
|
77
|
+
declare function useCreateAlert(options?: Omit<UseMutationOptions<Alert, Error, CreateAlertParams>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<{
|
|
78
|
+
id: number;
|
|
79
|
+
type: "AccountThresholdAlert" | "GoalAlert" | "MerchantNameAlert" | "SpendingTargetAlert" | "TransactionLimitAlert" | "UpcomingBillAlert";
|
|
80
|
+
options: {
|
|
81
|
+
[x: string]: unknown;
|
|
82
|
+
};
|
|
83
|
+
email_delivery: boolean;
|
|
84
|
+
sms_delivery: boolean;
|
|
85
|
+
source_type: "Account" | "Budget" | "CashflowTransaction" | "PayoffGoal" | "SavingsGoal" | null;
|
|
86
|
+
source_id?: string | number | undefined;
|
|
87
|
+
source?: unknown;
|
|
88
|
+
}, Error, CreateAlertParams, unknown>;
|
|
89
|
+
|
|
90
|
+
interface UpdateAlertParams {
|
|
91
|
+
userId: string;
|
|
92
|
+
alertId: number;
|
|
93
|
+
type: AlertType;
|
|
94
|
+
data: AlertUpdate;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Update an existing alert
|
|
98
|
+
* PUT /users/:userId/alerts/:type/:alertId
|
|
99
|
+
*
|
|
100
|
+
* Type-based routing - same mapping as create
|
|
101
|
+
*/
|
|
102
|
+
declare function useUpdateAlert(options?: Omit<UseMutationOptions<Alert, Error, UpdateAlertParams>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<{
|
|
103
|
+
id: number;
|
|
104
|
+
type: "AccountThresholdAlert" | "GoalAlert" | "MerchantNameAlert" | "SpendingTargetAlert" | "TransactionLimitAlert" | "UpcomingBillAlert";
|
|
105
|
+
options: {
|
|
106
|
+
[x: string]: unknown;
|
|
107
|
+
};
|
|
108
|
+
email_delivery: boolean;
|
|
109
|
+
sms_delivery: boolean;
|
|
110
|
+
source_type: "Account" | "Budget" | "CashflowTransaction" | "PayoffGoal" | "SavingsGoal" | null;
|
|
111
|
+
source_id?: string | number | undefined;
|
|
112
|
+
source?: unknown;
|
|
113
|
+
}, Error, UpdateAlertParams, unknown>;
|
|
114
|
+
|
|
115
|
+
interface DeleteAlertParams {
|
|
116
|
+
userId: string;
|
|
117
|
+
alertId: number;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Delete an alert
|
|
121
|
+
* DELETE /users/:userId/alerts/:alertId
|
|
122
|
+
*/
|
|
123
|
+
declare function useDeleteAlert(options?: Omit<UseMutationOptions<void, Error, DeleteAlertParams>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<void, Error, DeleteAlertParams, unknown>;
|
|
124
|
+
|
|
125
|
+
interface UpdateAlertDestinationsParams {
|
|
126
|
+
userId: string;
|
|
127
|
+
data: AlertDestinationsUpdate;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Update alert destinations for a user
|
|
131
|
+
* PUT /users/:userId/alert_destinations
|
|
132
|
+
*/
|
|
133
|
+
declare function useUpdateAlertDestinations(options?: Omit<UseMutationOptions<AlertDestinations, Error, UpdateAlertDestinationsParams>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<{
|
|
134
|
+
email_address: string | null;
|
|
135
|
+
sms_number: string | null;
|
|
136
|
+
partner_sms_enabled: boolean;
|
|
137
|
+
}, Error, UpdateAlertDestinationsParams, unknown>;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Query key factory for Alerts domain
|
|
141
|
+
*/
|
|
142
|
+
declare const alertKeys: {
|
|
143
|
+
all: readonly ["alerts"];
|
|
144
|
+
lists: () => readonly ["alerts", "list"];
|
|
145
|
+
list: (userId: string) => readonly ["alerts", "list", string];
|
|
146
|
+
details: () => readonly ["alerts", "detail"];
|
|
147
|
+
detail: (userId: string, alertId: number) => readonly ["alerts", "detail", string, number];
|
|
148
|
+
destinations: (userId: string) => readonly ["alerts", "destinations", string];
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Axios instance for Alerts API
|
|
153
|
+
* Base URL configured through environment variables or defaults to relative path
|
|
154
|
+
*/
|
|
155
|
+
declare const api: axios.AxiosInstance;
|
|
156
|
+
|
|
157
|
+
export { type CreateAlertParams, type DeleteAlertParams, type UpdateAlertDestinationsParams, type UpdateAlertParams, type UseAlertDestinationsParams, type UseAlertParams, type UseAlertsParams, alertKeys, api, useAlert, useAlertDestinations, useAlerts, useCreateAlert, useDeleteAlert, useUpdateAlert, useUpdateAlertDestinations };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { AlertsResponseSchema, AlertSchema, AlertDestinationsSchema, AlertCreateSchema, AlertUpdateSchema, AlertDestinationsUpdateSchema } from '@pfm-platform/shared';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
|
|
5
|
+
// src/queries/useAlerts.ts
|
|
6
|
+
var api = axios.create({
|
|
7
|
+
baseURL: "/api",
|
|
8
|
+
headers: {
|
|
9
|
+
"Content-Type": "application/json"
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// src/keys.ts
|
|
14
|
+
var alertKeys = {
|
|
15
|
+
all: ["alerts"],
|
|
16
|
+
// Alert lists and details
|
|
17
|
+
lists: () => [...alertKeys.all, "list"],
|
|
18
|
+
list: (userId) => [...alertKeys.lists(), userId],
|
|
19
|
+
details: () => [...alertKeys.all, "detail"],
|
|
20
|
+
detail: (userId, alertId) => [...alertKeys.details(), userId, alertId],
|
|
21
|
+
// Alert destinations
|
|
22
|
+
destinations: (userId) => [...alertKeys.all, "destinations", userId]
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// src/queries/useAlerts.ts
|
|
26
|
+
function useAlerts({ userId }, options) {
|
|
27
|
+
return useQuery({
|
|
28
|
+
queryKey: alertKeys.list(userId),
|
|
29
|
+
queryFn: async () => {
|
|
30
|
+
const response = await api.get(`/users/${userId}/alerts`);
|
|
31
|
+
const validated = AlertsResponseSchema.parse(response.data);
|
|
32
|
+
return validated.alerts;
|
|
33
|
+
},
|
|
34
|
+
staleTime: 1e3 * 60 * 5,
|
|
35
|
+
// 5 minutes (alerts change moderately)
|
|
36
|
+
...options
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function useAlert({ userId, alertId }, options) {
|
|
40
|
+
return useQuery({
|
|
41
|
+
queryKey: alertKeys.detail(userId, alertId),
|
|
42
|
+
queryFn: async () => {
|
|
43
|
+
const response = await api.get(`/users/${userId}/alerts/${alertId}`);
|
|
44
|
+
return AlertSchema.parse(response.data);
|
|
45
|
+
},
|
|
46
|
+
staleTime: 1e3 * 60 * 5,
|
|
47
|
+
// 5 minutes
|
|
48
|
+
...options
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function useAlertDestinations({ userId }, options) {
|
|
52
|
+
return useQuery({
|
|
53
|
+
queryKey: alertKeys.destinations(userId),
|
|
54
|
+
queryFn: async () => {
|
|
55
|
+
const response = await api.get(`/users/${userId}/alert_destinations`);
|
|
56
|
+
return AlertDestinationsSchema.parse(response.data);
|
|
57
|
+
},
|
|
58
|
+
staleTime: 1e3 * 60 * 10,
|
|
59
|
+
// 10 minutes (destinations rarely change)
|
|
60
|
+
...options
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function useCreateAlert(options) {
|
|
64
|
+
const queryClient = useQueryClient();
|
|
65
|
+
const getEndpoint = (type) => {
|
|
66
|
+
const mapping = {
|
|
67
|
+
AccountThresholdAlert: "account_threshold_alerts",
|
|
68
|
+
GoalAlert: "goal_alerts",
|
|
69
|
+
MerchantNameAlert: "merchant_name_alerts",
|
|
70
|
+
SpendingTargetAlert: "spending_target_alerts",
|
|
71
|
+
TransactionLimitAlert: "transaction_limit_alerts",
|
|
72
|
+
UpcomingBillAlert: "upcoming_bill_alerts"
|
|
73
|
+
};
|
|
74
|
+
return mapping[type];
|
|
75
|
+
};
|
|
76
|
+
return useMutation({
|
|
77
|
+
mutationFn: async ({ userId, type, data }) => {
|
|
78
|
+
const validated = AlertCreateSchema.parse(data);
|
|
79
|
+
const endpoint = getEndpoint(type);
|
|
80
|
+
const response = await api.post(`/users/${userId}/${endpoint}`, {
|
|
81
|
+
alert: validated
|
|
82
|
+
});
|
|
83
|
+
return AlertSchema.parse(response.data);
|
|
84
|
+
},
|
|
85
|
+
onSuccess: (_, { userId }) => {
|
|
86
|
+
queryClient.invalidateQueries({ queryKey: alertKeys.list(userId) });
|
|
87
|
+
},
|
|
88
|
+
...options
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
function useUpdateAlert(options) {
|
|
92
|
+
const queryClient = useQueryClient();
|
|
93
|
+
const getEndpoint = (type) => {
|
|
94
|
+
const mapping = {
|
|
95
|
+
AccountThresholdAlert: "account_threshold_alerts",
|
|
96
|
+
GoalAlert: "goal_alerts",
|
|
97
|
+
MerchantNameAlert: "merchant_name_alerts",
|
|
98
|
+
SpendingTargetAlert: "spending_target_alerts",
|
|
99
|
+
TransactionLimitAlert: "transaction_limit_alerts",
|
|
100
|
+
UpcomingBillAlert: "upcoming_bill_alerts"
|
|
101
|
+
};
|
|
102
|
+
return mapping[type];
|
|
103
|
+
};
|
|
104
|
+
return useMutation({
|
|
105
|
+
mutationFn: async ({ userId, alertId, type, data }) => {
|
|
106
|
+
const validated = AlertUpdateSchema.parse(data);
|
|
107
|
+
const endpoint = getEndpoint(type);
|
|
108
|
+
const response = await api.put(`/users/${userId}/${endpoint}/${alertId}`, {
|
|
109
|
+
alert: validated
|
|
110
|
+
});
|
|
111
|
+
return AlertSchema.parse(response.data);
|
|
112
|
+
},
|
|
113
|
+
onSuccess: (_, { userId, alertId }) => {
|
|
114
|
+
queryClient.invalidateQueries({ queryKey: alertKeys.list(userId) });
|
|
115
|
+
queryClient.invalidateQueries({ queryKey: alertKeys.detail(userId, alertId) });
|
|
116
|
+
},
|
|
117
|
+
...options
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function useDeleteAlert(options) {
|
|
121
|
+
const queryClient = useQueryClient();
|
|
122
|
+
return useMutation({
|
|
123
|
+
mutationFn: async ({ userId, alertId }) => {
|
|
124
|
+
await api.delete(`/users/${userId}/alerts/${alertId}`);
|
|
125
|
+
},
|
|
126
|
+
onSuccess: (_, { userId, alertId }) => {
|
|
127
|
+
queryClient.invalidateQueries({ queryKey: alertKeys.list(userId) });
|
|
128
|
+
queryClient.removeQueries({ queryKey: alertKeys.detail(userId, alertId) });
|
|
129
|
+
},
|
|
130
|
+
...options
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function useUpdateAlertDestinations(options) {
|
|
134
|
+
const queryClient = useQueryClient();
|
|
135
|
+
return useMutation({
|
|
136
|
+
mutationFn: async ({ userId, data }) => {
|
|
137
|
+
const validated = AlertDestinationsUpdateSchema.parse(data);
|
|
138
|
+
const response = await api.put(`/users/${userId}/alert_destinations`, {
|
|
139
|
+
destinations: validated
|
|
140
|
+
});
|
|
141
|
+
return AlertDestinationsSchema.parse(response.data);
|
|
142
|
+
},
|
|
143
|
+
onSuccess: (_, { userId }) => {
|
|
144
|
+
queryClient.invalidateQueries({ queryKey: alertKeys.destinations(userId) });
|
|
145
|
+
},
|
|
146
|
+
...options
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export { alertKeys, api, useAlert, useAlertDestinations, useAlerts, useCreateAlert, useDeleteAlert, useUpdateAlert, useUpdateAlertDestinations };
|
|
151
|
+
//# sourceMappingURL=index.js.map
|
|
152
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/keys.ts","../src/queries/useAlerts.ts","../src/queries/useAlert.ts","../src/queries/useAlertDestinations.ts","../src/mutations/useCreateAlert.ts","../src/mutations/useUpdateAlert.ts","../src/mutations/useDeleteAlert.ts","../src/mutations/useUpdateAlertDestinations.ts"],"names":["useQuery","AlertSchema","useQueryClient","useMutation","AlertDestinationsSchema"],"mappings":";;;;;AAMO,IAAM,GAAA,GAAM,MAAM,MAAA,CAAO;AAAA,EAC9B,OAAA,EAAS,MAAA;AAAA,EACT,OAAA,EAAS;AAAA,IACP,cAAA,EAAgB;AAAA;AAEpB,CAAC;;;ACPM,IAAM,SAAA,GAAY;AAAA,EACvB,GAAA,EAAK,CAAC,QAAQ,CAAA;AAAA;AAAA,EAGd,OAAO,MAAM,CAAC,GAAG,SAAA,CAAU,KAAK,MAAM,CAAA;AAAA,EACtC,IAAA,EAAM,CAAC,MAAA,KAAmB,CAAC,GAAG,SAAA,CAAU,KAAA,IAAS,MAAM,CAAA;AAAA,EACvD,SAAS,MAAM,CAAC,GAAG,SAAA,CAAU,KAAK,QAAQ,CAAA;AAAA,EAC1C,MAAA,EAAQ,CAAC,MAAA,EAAgB,OAAA,KACvB,CAAC,GAAG,SAAA,CAAU,OAAA,EAAQ,EAAG,MAAA,EAAQ,OAAO,CAAA;AAAA;AAAA,EAG1C,YAAA,EAAc,CAAC,MAAA,KACb,CAAC,GAAG,SAAA,CAAU,GAAA,EAAK,gBAAgB,MAAM;AAC7C;;;ACJO,SAAS,SAAA,CACd,EAAE,MAAA,EAAO,EACT,OAAA,EACA;AACA,EAAA,OAAO,QAAA,CAAS;AAAA,IACd,QAAA,EAAU,SAAA,CAAU,IAAA,CAAK,MAAM,CAAA;AAAA,IAC/B,SAAS,YAAY;AACnB,MAAA,MAAM,WAAW,MAAM,GAAA,CAAI,GAAA,CAAI,CAAA,OAAA,EAAU,MAAM,CAAA,OAAA,CAAS,CAAA;AACxD,MAAA,MAAM,SAAA,GAAY,oBAAA,CAAqB,KAAA,CAAM,QAAA,CAAS,IAAI,CAAA;AAC1D,MAAA,OAAO,SAAA,CAAU,MAAA;AAAA,IACnB,CA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A,WAAA,CAAY,kBAAkB,EAAE,QAAA,EAAU,UAAU,IAAA,CAAK,MAAM,GAAG,CAAA;AAClE,MAAA,WAAA,CAAY,aAAA,CAAc,EAAE,QAAA,EAAU,SAAA,CAAU,OAAO,MAAA,EAAQ,OAAO,GAAG,CAAA;AAAA,IAC3E,CAAA;AAAA,IACA,GAAG;AAAA,GACJ,CAAA;AACH;ACTO,SAAS,2BACd,OAAA,EACA;AACA,EAAA,MAAM,cAAcD,cAAAA,EAAe;AAEnC,EAAA,OAAOC,WAAAA,CAAY;AAAA,IACjB,UAAA,EAAY,OAAO,EAAE,MAAA,EAAQ,MAAK,KAAqC;AACrE,MAAA,MAAM,SAAA,GAAY,6BAAA,CAA8B,KAAA,CAAM,IAAI,CAAA;AAC1D,MAAA,MAAM,WAAW,MAAM,GAAA,CAAI,GAAA,CAAI,CAAA,OAAA,EAAU,MAAM,CAAA,mBAAA,CAAA,EAAuB;AAAA,QACpE,YAAA,EAAc;AAAA,OACf,CAAA;AACD,MAAA,OAAOC,uBAAAA,CAAwB,KAAA,CAAM,QAAA,CAAS,IAAI,CAAA;AAAA,IACpD,CAAA;AAAA,IACA,SAAA,EAAW,CAAC,CAAA,EAAG,EAAE,QAAO,KAAM;AAC5B,MAAA,WAAA,CAAY,kBAAkB,EAAE,QAAA,EAAU,UAAU,YAAA,CAAa,MAAM,GAAG,CAAA;AAAA,IAC5E,CAAA;AAAA,IACA,GAAG;AAAA,GACJ,CAAA;AACH","file":"index.js","sourcesContent":["import axios from 'axios';\n\n/**\n * Axios instance for Alerts API\n * Base URL configured through environment variables or defaults to relative path\n */\nexport const api = axios.create({\n baseURL: '/api',\n headers: {\n 'Content-Type': 'application/json',\n },\n});\n","/**\n * Query key factory for Alerts domain\n */\n\nexport const alertKeys = {\n all: ['alerts'] as const,\n\n // Alert lists and details\n lists: () => [...alertKeys.all, 'list'] as const,\n list: (userId: string) => [...alertKeys.lists(), userId] as const,\n details: () => [...alertKeys.all, 'detail'] as const,\n detail: (userId: string, alertId: number) =>\n [...alertKeys.details(), userId, alertId] as const,\n\n // Alert destinations\n destinations: (userId: string) =>\n [...alertKeys.all, 'destinations', userId] as const,\n};\n","import { useQuery, UseQueryOptions } from '@tanstack/react-query';\nimport { Alert, AlertsResponseSchema } from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { alertKeys } from '../keys.js';\n\nexport interface UseAlertsParams {\n userId: string;\n}\n\n/**\n * Fetch all alerts for a user\n * GET /users/:userId/alerts\n */\nexport function useAlerts(\n { userId }: UseAlertsParams,\n options?: Omit<UseQueryOptions<Alert[]>, 'queryKey' | 'queryFn'>\n) {\n return useQuery({\n queryKey: alertKeys.list(userId),\n queryFn: async () => {\n const response = await api.get(`/users/${userId}/alerts`);\n const validated = AlertsResponseSchema.parse(response.data);\n return validated.alerts;\n },\n staleTime: 1000 * 60 * 5, // 5 minutes (alerts change moderately)\n ...options,\n });\n}\n","import { useQuery, UseQueryOptions } from '@tanstack/react-query';\nimport { Alert, AlertSchema } from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { alertKeys } from '../keys.js';\n\nexport interface UseAlertParams {\n userId: string;\n alertId: number;\n}\n\n/**\n * Fetch a single alert by ID\n * GET /users/:userId/alerts/:alertId\n */\nexport function useAlert(\n { userId, alertId }: UseAlertParams,\n options?: Omit<UseQueryOptions<Alert>, 'queryKey' | 'queryFn'>\n) {\n return useQuery({\n queryKey: alertKeys.detail(userId, alertId),\n queryFn: async () => {\n const response = await api.get(`/users/${userId}/alerts/${alertId}`);\n return AlertSchema.parse(response.data);\n },\n staleTime: 1000 * 60 * 5, // 5 minutes\n ...options,\n });\n}\n","import { useQuery, UseQueryOptions } from '@tanstack/react-query';\nimport { AlertDestinations, AlertDestinationsSchema } from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { alertKeys } from '../keys.js';\n\nexport interface UseAlertDestinationsParams {\n userId: string;\n}\n\n/**\n * Fetch alert destinations for a user\n * GET /users/:userId/alert_destinations\n */\nexport function useAlertDestinations(\n { userId }: UseAlertDestinationsParams,\n options?: Omit<UseQueryOptions<AlertDestinations>, 'queryKey' | 'queryFn'>\n) {\n return useQuery({\n queryKey: alertKeys.destinations(userId),\n queryFn: async () => {\n const response = await api.get(`/users/${userId}/alert_destinations`);\n return AlertDestinationsSchema.parse(response.data);\n },\n staleTime: 1000 * 60 * 10, // 10 minutes (destinations rarely change)\n ...options,\n });\n}\n","import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query';\nimport { Alert, AlertCreate, AlertCreateSchema, AlertSchema, AlertType } from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { alertKeys } from '../keys.js';\n\nexport interface CreateAlertParams {\n userId: string;\n type: AlertType;\n data: AlertCreate;\n}\n\n/**\n * Create a new alert\n * POST /users/:userId/alerts/:type\n *\n * Type-based routing from legacy API routeMapping:\n * - AccountThresholdAlert → account_threshold_alerts\n * - GoalAlert → goal_alerts\n * - MerchantNameAlert → merchant_name_alerts\n * - SpendingTargetAlert → spending_target_alerts\n * - TransactionLimitAlert → transaction_limit_alerts\n * - UpcomingBillAlert → upcoming_bill_alerts\n */\nexport function useCreateAlert(\n options?: Omit<UseMutationOptions<Alert, Error, CreateAlertParams>, 'mutationFn'>\n) {\n const queryClient = useQueryClient();\n\n // Type to endpoint mapping\n const getEndpoint = (type: AlertType): string => {\n const mapping: Record<AlertType, string> = {\n AccountThresholdAlert: 'account_threshold_alerts',\n GoalAlert: 'goal_alerts',\n MerchantNameAlert: 'merchant_name_alerts',\n SpendingTargetAlert: 'spending_target_alerts',\n TransactionLimitAlert: 'transaction_limit_alerts',\n UpcomingBillAlert: 'upcoming_bill_alerts',\n };\n return mapping[type];\n };\n\n return useMutation({\n mutationFn: async ({ userId, type, data }: CreateAlertParams) => {\n const validated = AlertCreateSchema.parse(data);\n const endpoint = getEndpoint(type);\n const response = await api.post(`/users/${userId}/${endpoint}`, {\n alert: validated,\n });\n return AlertSchema.parse(response.data);\n },\n onSuccess: (_, { userId }) => {\n queryClient.invalidateQueries({ queryKey: alertKeys.list(userId) });\n },\n ...options,\n });\n}\n","import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query';\nimport { Alert, AlertUpdate, AlertUpdateSchema, AlertSchema, AlertType } from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { alertKeys } from '../keys.js';\n\nexport interface UpdateAlertParams {\n userId: string;\n alertId: number;\n type: AlertType;\n data: AlertUpdate;\n}\n\n/**\n * Update an existing alert\n * PUT /users/:userId/alerts/:type/:alertId\n *\n * Type-based routing - same mapping as create\n */\nexport function useUpdateAlert(\n options?: Omit<UseMutationOptions<Alert, Error, UpdateAlertParams>, 'mutationFn'>\n) {\n const queryClient = useQueryClient();\n\n // Type to endpoint mapping\n const getEndpoint = (type: AlertType): string => {\n const mapping: Record<AlertType, string> = {\n AccountThresholdAlert: 'account_threshold_alerts',\n GoalAlert: 'goal_alerts',\n MerchantNameAlert: 'merchant_name_alerts',\n SpendingTargetAlert: 'spending_target_alerts',\n TransactionLimitAlert: 'transaction_limit_alerts',\n UpcomingBillAlert: 'upcoming_bill_alerts',\n };\n return mapping[type];\n };\n\n return useMutation({\n mutationFn: async ({ userId, alertId, type, data }: UpdateAlertParams) => {\n const validated = AlertUpdateSchema.parse(data);\n const endpoint = getEndpoint(type);\n const response = await api.put(`/users/${userId}/${endpoint}/${alertId}`, {\n alert: validated,\n });\n return AlertSchema.parse(response.data);\n },\n onSuccess: (_, { userId, alertId }) => {\n queryClient.invalidateQueries({ queryKey: alertKeys.list(userId) });\n queryClient.invalidateQueries({ queryKey: alertKeys.detail(userId, alertId) });\n },\n ...options,\n });\n}\n","import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query';\nimport { api } from '../client.js';\nimport { alertKeys } from '../keys.js';\n\nexport interface DeleteAlertParams {\n userId: string;\n alertId: number;\n}\n\n/**\n * Delete an alert\n * DELETE /users/:userId/alerts/:alertId\n */\nexport function useDeleteAlert(\n options?: Omit<UseMutationOptions<void, Error, DeleteAlertParams>, 'mutationFn'>\n) {\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ userId, alertId }: DeleteAlertParams) => {\n await api.delete(`/users/${userId}/alerts/${alertId}`);\n },\n onSuccess: (_, { userId, alertId }) => {\n queryClient.invalidateQueries({ queryKey: alertKeys.list(userId) });\n queryClient.removeQueries({ queryKey: alertKeys.detail(userId, alertId) });\n },\n ...options,\n });\n}\n","import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query';\nimport {\n AlertDestinations,\n AlertDestinationsUpdate,\n AlertDestinationsUpdateSchema,\n AlertDestinationsSchema,\n} from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { alertKeys } from '../keys.js';\n\nexport interface UpdateAlertDestinationsParams {\n userId: string;\n data: AlertDestinationsUpdate;\n}\n\n/**\n * Update alert destinations for a user\n * PUT /users/:userId/alert_destinations\n */\nexport function useUpdateAlertDestinations(\n options?: Omit<UseMutationOptions<AlertDestinations, Error, UpdateAlertDestinationsParams>, 'mutationFn'>\n) {\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ userId, data }: UpdateAlertDestinationsParams) => {\n const validated = AlertDestinationsUpdateSchema.parse(data);\n const response = await api.put(`/users/${userId}/alert_destinations`, {\n destinations: validated,\n });\n return AlertDestinationsSchema.parse(response.data);\n },\n onSuccess: (_, { userId }) => {\n queryClient.invalidateQueries({ queryKey: alertKeys.destinations(userId) });\n },\n ...options,\n });\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pfm-platform/alerts-data-access",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"axios": "^1.13.2",
|
|
9
|
+
"zod": "4.1.12",
|
|
10
|
+
"@pfm-platform/shared": "0.0.1"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@testing-library/react": "^16.3.0",
|
|
14
|
+
"@vitejs/plugin-react": "^5.1.1",
|
|
15
|
+
"@vitest/coverage-v8": "^4.0.9",
|
|
16
|
+
"jsdom": "^27.2.0",
|
|
17
|
+
"react-dom": "19.2.0",
|
|
18
|
+
"typescript": "5.9.3",
|
|
19
|
+
"vitest": "4.0.9"
|
|
20
|
+
},
|
|
21
|
+
"module": "./dist/index.js",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js",
|
|
26
|
+
"require": "./dist/index.cjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md"
|
|
32
|
+
],
|
|
33
|
+
"description": "Personal Finance Management - ALERTS data-access layer",
|
|
34
|
+
"keywords": [
|
|
35
|
+
"pfm",
|
|
36
|
+
"finance",
|
|
37
|
+
"alerts",
|
|
38
|
+
"data-access",
|
|
39
|
+
"react",
|
|
40
|
+
"typescript"
|
|
41
|
+
],
|
|
42
|
+
"author": "Lenny Miller",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/lennylmiller/pfm-research",
|
|
47
|
+
"directory": "packages/alerts/data-access"
|
|
48
|
+
},
|
|
49
|
+
"bugs": "https://github.com/lennylmiller/pfm-research/issues",
|
|
50
|
+
"homepage": "https://github.com/lennylmiller/pfm-research#readme",
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@tanstack/react-query": "5.90.9",
|
|
53
|
+
"react": "19.2.0"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"test:watch": "vitest",
|
|
58
|
+
"test:coverage": "vitest run --coverage",
|
|
59
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean"
|
|
60
|
+
}
|
|
61
|
+
}
|