@pfm-platform/notifications-data-access 0.1.1 → 0.2.0

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 CHANGED
@@ -10,7 +10,7 @@ var axios__default = /*#__PURE__*/_interopDefault(axios);
10
10
 
11
11
  // src/queries/useNotifications.ts
12
12
  var api = axios__default.default.create({
13
- baseURL: "/api",
13
+ baseURL: "http://localhost:3000/api",
14
14
  headers: {
15
15
  "Content-Type": "application/json"
16
16
  }
@@ -20,7 +20,8 @@ var api = axios__default.default.create({
20
20
  var notificationKeys = {
21
21
  all: ["notifications"],
22
22
  lists: () => [...notificationKeys.all, "list"],
23
- list: (userId) => [...notificationKeys.lists(), userId]
23
+ list: (userId) => [...notificationKeys.lists(), userId],
24
+ preferences: (userId) => [...notificationKeys.all, "preferences", userId]
24
25
  };
25
26
 
26
27
  // src/queries/useNotifications.ts
@@ -37,6 +38,19 @@ function useNotifications({ userId }, options) {
37
38
  ...options
38
39
  });
39
40
  }
41
+ function useNotificationPreferences({ userId }, options) {
42
+ return reactQuery.useQuery({
43
+ queryKey: notificationKeys.preferences(userId),
44
+ queryFn: async () => {
45
+ const response = await api.get(`/users/${userId}/notifications/preferences`);
46
+ const validated = shared.NotificationPreferencesSchema.parse(response.data);
47
+ return validated;
48
+ },
49
+ staleTime: 1e3 * 60 * 5,
50
+ // 5 minutes (preferences change infrequently)
51
+ ...options
52
+ });
53
+ }
40
54
  function useCreateNotification(options) {
41
55
  const queryClient = reactQuery.useQueryClient();
42
56
  const { mode } = shared.useAppMode();
@@ -95,12 +109,28 @@ function useDeleteNotification(options) {
95
109
  ...options
96
110
  });
97
111
  }
112
+ function useUpdateNotificationPreferences(options) {
113
+ const queryClient = reactQuery.useQueryClient();
114
+ return reactQuery.useMutation({
115
+ mutationFn: async ({ userId, data }) => {
116
+ const validated = shared.NotificationPreferencesUpdateSchema.parse(data);
117
+ const response = await api.put(`/users/${userId}/notifications/preferences`, validated);
118
+ return shared.NotificationPreferencesSchema.parse(response.data);
119
+ },
120
+ onSuccess: (_, { userId }) => {
121
+ queryClient.invalidateQueries({ queryKey: notificationKeys.preferences(userId) });
122
+ },
123
+ ...options
124
+ });
125
+ }
98
126
 
99
127
  exports.api = api;
100
128
  exports.notificationKeys = notificationKeys;
101
129
  exports.useCreateNotification = useCreateNotification;
102
130
  exports.useDeleteNotification = useDeleteNotification;
131
+ exports.useNotificationPreferences = useNotificationPreferences;
103
132
  exports.useNotifications = useNotifications;
104
133
  exports.useUpdateNotification = useUpdateNotification;
134
+ exports.useUpdateNotificationPreferences = useUpdateNotificationPreferences;
105
135
  //# sourceMappingURL=index.cjs.map
106
136
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts","../src/keys.ts","../src/queries/useNotifications.ts","../src/mutations/useCreateNotification.ts","../src/mutations/useUpdateNotification.ts","../src/mutations/useDeleteNotification.ts"],"names":["axios","useQuery","NotificationsResponseSchema","useQueryClient","useAppMode","useMutation","NotificationCreateSchemaAdmin","NotificationCreateSchemaUser","NotificationSchema","NotificationUpdateSchemaAdmin","NotificationUpdateSchemaUser"],"mappings":";;;;;;;;;;;AAMO,IAAM,GAAA,GAAMA,uBAAM,MAAA,CAAO;AAAA,EAC9B,OAAA,EAAS,MAAA;AAAA,EACT,OAAA,EAAS;AAAA,IACP,cAAA,EAAgB;AAAA;AAEpB,CAAC;;;ACRM,IAAM,gBAAA,GAAmB;AAAA,EAC9B,GAAA,EAAK,CAAC,eAAe,CAAA;AAAA,EACrB,OAAO,MAAM,CAAC,GAAG,gBAAA,CAAiB,KAAK,MAAM,CAAA;AAAA,EAC7C,IAAA,EAAM,CAAC,MAAA,KAAmB,CAAC,GAAG,gBAAA,CAAiB,KAAA,IAAS,MAAM;AAChE;;;ACSO,SAAS,gBAAA,CACd,EAAE,MAAA,EAAO,EACT,OAAA,EACA;AACA,EAAA,OAAOC,mBAAA,CAAS;AAAA,IACd,QAA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E,QAAA,EAAU,iBAAiB,IAAA,CAAK,MAAM,GAAG,CAAA;AAAA,IAC3E,CAAA;AAAA,IACA,GAAG;AAAA,GACJ,CAAA;AACH","file":"index.cjs","sourcesContent":["import axios from 'axios';\n\n/**\n * Axios instance for Notifications 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 Notifications domain\n */\nexport const notificationKeys = {\n all: ['notifications'] as const,\n lists: () => [...notificationKeys.all, 'list'] as const,\n list: (userId: string) => [...notificationKeys.lists(), userId] as const,\n};\n","import { useQuery, UseQueryOptions } from '@tanstack/react-query';\nimport { Notification, NotificationsResponseSchema } from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { notificationKeys } from '../keys.js';\n\nexport interface UseNotificationsParams {\n userId: string;\n}\n\n/**\n * Fetch all notifications for a user\n * GET /users/:userId/alerts/notifications\n *\n * Notifications are system-generated based on alert configurations\n * Read-only domain (no create/update operations)\n */\nexport function useNotifications(\n { userId }: UseNotificationsParams,\n options?: Omit<UseQueryOptions<Notification[]>, 'queryKey' | 'queryFn'>\n) {\n return useQuery({\n queryKey: notificationKeys.list(userId),\n queryFn: async () => {\n const response = await api.get(`/users/${userId}/alerts/notifications`);\n const validated = NotificationsResponseSchema.parse(response.data);\n return validated.notifications;\n },\n staleTime: 1000 * 60 * 2, // 2 minutes (notifications change frequently)\n ...options,\n });\n}\n","import {\n useMutation,\n useQueryClient,\n type UseMutationOptions,\n} from '@tanstack/react-query';\nimport {\n NotificationCreateSchemaAdmin,\n NotificationCreateSchemaUser,\n NotificationSchema,\n useAppMode,\n type AlertType,\n} from '@pfm-platform/shared';\nimport type { Notification } from '@pfm-platform/shared';\nimport { api } from '../client';\nimport { notificationKeys } from '../keys';\n\n/**\n * Notification create data interface\n */\nexport interface NotificationCreate {\n message: string;\n alert_type: AlertType;\n created_at?: string;\n}\n\n/**\n * Parameters for useCreateNotification mutation\n */\nexport interface CreateNotificationParams {\n userId: string;\n data: NotificationCreate;\n}\n\n/**\n * Mutation hook for creating a new notification\n *\n * Creates a notification manually for testing purposes.\n * Uses mode switching for validation:\n * - Admin mode: Allows manual notification creation for test data\n * - User mode: Blocked (notifications are system-generated)\n *\n * @example\n * ```tsx\n * const createNotification = useCreateNotification();\n *\n * createNotification.mutate({\n * userId: 'user123',\n * data: {\n * message: 'Test notification',\n * alert_type: 'AccountThresholdAlert',\n * created_at: new Date().toISOString() // Optional\n * }\n * });\n * ```\n */\nexport function useCreateNotification(\n options?: Omit<\n UseMutationOptions<Notification, Error, CreateNotificationParams>,\n 'mutationFn'\n >\n) {\n const queryClient = useQueryClient();\n const { mode } = useAppMode();\n\n return useMutation({\n mutationFn: async ({ userId, data }: CreateNotificationParams) => {\n // Select schema based on mode\n const schema =\n mode === 'admin'\n ? NotificationCreateSchemaAdmin\n : NotificationCreateSchemaUser;\n\n // Validate notification data\n const validated = schema.parse(data);\n\n // POST to create new notification\n const response = await api.post(\n `/users/${userId}/alerts/notifications`,\n validated\n );\n\n // Return created notification\n return NotificationSchema.parse(response.data);\n },\n onSuccess: (_, { userId }) => {\n // Invalidate notifications query to refetch updated list\n queryClient.invalidateQueries({\n queryKey: notificationKeys.list(userId),\n });\n },\n ...options,\n });\n}\n","import {\n useMutation,\n useQueryClient,\n type UseMutationOptions,\n} from '@tanstack/react-query';\nimport {\n NotificationUpdateSchemaAdmin,\n NotificationUpdateSchemaUser,\n NotificationSchema,\n useAppMode,\n type AlertType,\n} from '@pfm-platform/shared';\nimport type { Notification } from '@pfm-platform/shared';\nimport { api } from '../client';\nimport { notificationKeys } from '../keys';\n\n/**\n * Notification update data interface\n */\nexport interface NotificationUpdate {\n message?: string;\n alert_type?: AlertType;\n}\n\n/**\n * Parameters for useUpdateNotification mutation\n */\nexport interface UpdateNotificationParams {\n userId: string;\n notificationId: number;\n data: NotificationUpdate;\n}\n\n/**\n * Mutation hook for updating a notification\n *\n * Updates notification fields for testing purposes.\n * Uses mode switching for validation:\n * - Admin mode: Allows updating notifications for test scenarios\n * - User mode: Blocked (notifications are system-generated)\n *\n * @example\n * ```tsx\n * const updateNotification = useUpdateNotification();\n *\n * updateNotification.mutate({\n * userId: 'user123',\n * notificationId: 1,\n * data: {\n * message: 'Updated test notification'\n * }\n * });\n * ```\n */\nexport function useUpdateNotification(\n options?: Omit<\n UseMutationOptions<Notification, Error, UpdateNotificationParams>,\n 'mutationFn'\n >\n) {\n const queryClient = useQueryClient();\n const { mode } = useAppMode();\n\n return useMutation({\n mutationFn: async ({\n userId,\n notificationId,\n data,\n }: UpdateNotificationParams) => {\n // Select schema based on mode\n const schema =\n mode === 'admin'\n ? NotificationUpdateSchemaAdmin\n : NotificationUpdateSchemaUser;\n\n // Validate notification update data\n const validated = schema.parse(data);\n\n // PUT to update notification\n const response = await api.put(\n `/users/${userId}/alerts/notifications/${notificationId}`,\n validated\n );\n\n // Return updated notification\n return NotificationSchema.parse(response.data);\n },\n onSuccess: (_, { userId }) => {\n // Invalidate notifications query to refetch updated list\n queryClient.invalidateQueries({\n queryKey: notificationKeys.list(userId),\n });\n },\n ...options,\n });\n}\n","import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query';\nimport { api } from '../client.js';\nimport { notificationKeys } from '../keys.js';\n\nexport interface DeleteNotificationParams {\n userId: string;\n notificationId: number;\n}\n\n/**\n * Delete a notification\n * DELETE /users/:userId/alerts/notifications/:notificationId\n *\n * Notifications are system-generated, deletion only removes from view\n */\nexport function useDeleteNotification(\n options?: Omit<UseMutationOptions<void, Error, DeleteNotificationParams>, 'mutationFn'>\n) {\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ userId, notificationId }: DeleteNotificationParams) => {\n await api.delete(`/users/${userId}/alerts/notifications/${notificationId}`);\n },\n onSuccess: (_, { userId }) => {\n // Invalidate notifications list to refetch without deleted item\n queryClient.invalidateQueries({ queryKey: notificationKeys.list(userId) });\n },\n ...options,\n });\n}\n"]}
1
+ {"version":3,"sources":["../src/client.ts","../src/keys.ts","../src/queries/useNotifications.ts","../src/queries/useNotificationPreferences.ts","../src/mutations/useCreateNotification.ts","../src/mutations/useUpdateNotification.ts","../src/mutations/useDeleteNotification.ts","../src/mutations/useUpdateNotificationPreferences.ts"],"names":["axios","useQuery","NotificationsResponseSchema","NotificationPreferencesSchema","useQueryClient","useAppMode","useMutation","NotificationCreateSchemaAdmin","NotificationCreateSchemaUser","NotificationSchema","NotificationUpdateSchemaAdmin","NotificationUpdateSchemaUser","NotificationPreferencesUpdateSchema"],"mappings":";;;;;;;;;;;AAMO,IAAM,GAAA,GAAMA,uBAAM,MAAA,CAAO;AAAA,EAC9B,OAAA,EAAS,2BAAA;AAAA,EACT,OAAA,EAAS;AAAA,IACP,cAAA,EAAgB;AAAA;AAEpB,CAAC;;;ACRM,IAAM,gBAAA,GAAmB;AAAA,EAC9B,GAAA,EAAK,CAAC,eAAe,CAAA;AAAA,EACrB,OAAO,MAAM,CAAC,GAAG,gBAAA,CAAiB,KAAK,MAAM,CAAA;AAAA,EAC7C,IAAA,EAAM,CAAC,MAAA,KAAmB,CAAC,GAAG,gBAAA,CAAiB,KAAA,IAAS,MAAM,CAAA;AAAA,EAC9D,WAAA,EAAa,CAAC,MAAA,KAAmB,CAAC,GAAG,gBAAA,CAAiB,GAAA,EAAK,eAAe,MAAM;AAClF;;;ACQO,SAAS,gBAAA,CACd,EAAE,MAAA,EAAO,EACT,OAAA,EACA;AACA,EAAA,OAAOC,mBAAA,CAAS;AAAA,IACd,QAAA,EAAU,gBAAA,CAAiB,IAAA,CAAK,MAAM,CAAA;AAAA,IACtC,SAAS,YAAY;AACnB,MAAA,MAAM,WAAW,MAAM,GAAA,CAAI,GAAA,CAAI,CAAA,OAAA,EAAU,MAAM,CAAA,qBAAA,CAAuB,CAAA;AACtE,MAAA,MAAM,SAAA,GAAYC,kCAAA,CAA4B,KAAA,CAAM,QAAA,CAAS,IAAI,CAAA;AACjE,MAAA,OAAO,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C;AAC1E,MAAA,MAAM,IAAI,MAAA,CAAO,CAAA,OAAA,EAAU,MAAM,CAAA,sBAAA,EAAyB,cAAc,CAAA,CAAE,CAAA;AAAA,IAC5E,CAAA;AAAA,IACA,SAAA,EAAW,CAAC,CAAA,EAAG,EAAE,QAAO,KAAM;AAE5B,MAAA,WAAA,CAAY,kBAAkB,EAAE,QAAA,EAAU,iBAAiB,IAAA,CAAK,MAAM,GAAG,CAAA;AAAA,IAC3E,CAAA;AAAA,IACA,GAAG;AAAA,GACJ,CAAA;AACH;ACVO,SAAS,iCACd,OAAA,EAKA;AACA,EAAA,MAAM,cAAcF,yBAAAA,EAAe;AAEnC,EAAA,OAAOE,sBAAAA,CAAY;AAAA,IACjB,UAAA,EAAY,OAAO,EAAE,MAAA,EAAQ,MAAK,KAA2C;AAE3E,MAAA,MAAM,SAAA,GAAYM,0CAAA,CAAoC,KAAA,CAAM,IAAI,CAAA;AAEhE,MAAA,MAAM,WAAW,MAAM,GAAA,CAAI,IAAI,CAAA,OAAA,EAAU,MAAM,8BAA8B,SAAS,CAAA;AACtF,MAAA,OAAOT,oCAAAA,CAA8B,KAAA,CAAM,QAAA,CAAS,IAAI,CAAA;AAAA,IAC1D,CAAA;AAAA,IACA,SAAA,EAAW,CAAC,CAAA,EAAG,EAAE,QAAO,KAAM;AAE5B,MAAA,WAAA,CAAY,kBAAkB,EAAE,QAAA,EAAU,iBAAiB,WAAA,CAAY,MAAM,GAAG,CAAA;AAAA,IAClF,CAAA;AAAA,IACA,GAAG;AAAA,GACJ,CAAA;AACH","file":"index.cjs","sourcesContent":["import axios from 'axios';\n\n/**\n * Axios instance for Notifications API\n * Base URL configured through environment variables or defaults to localhost for tests\n */\nexport const api = axios.create({\n baseURL: 'http://localhost:3000/api',\n headers: {\n 'Content-Type': 'application/json',\n },\n});\n","/**\n * Query key factory for Notifications domain\n */\nexport const notificationKeys = {\n all: ['notifications'] as const,\n lists: () => [...notificationKeys.all, 'list'] as const,\n list: (userId: string) => [...notificationKeys.lists(), userId] as const,\n preferences: (userId: string) => [...notificationKeys.all, 'preferences', userId] as const,\n};\n","import { useQuery, UseQueryOptions } from '@tanstack/react-query';\nimport { Notification, NotificationsResponseSchema } from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { notificationKeys } from '../keys.js';\n\nexport interface UseNotificationsParams {\n userId: string;\n}\n\n/**\n * Fetch all notifications for a user\n * GET /users/:userId/alerts/notifications\n *\n * Notifications are system-generated based on alert configurations\n * Read-only domain (no create/update operations)\n */\nexport function useNotifications(\n { userId }: UseNotificationsParams,\n options?: Omit<UseQueryOptions<Notification[]>, 'queryKey' | 'queryFn'>\n) {\n return useQuery({\n queryKey: notificationKeys.list(userId),\n queryFn: async () => {\n const response = await api.get(`/users/${userId}/alerts/notifications`);\n const validated = NotificationsResponseSchema.parse(response.data);\n return validated.notifications;\n },\n staleTime: 1000 * 60 * 2, // 2 minutes (notifications change frequently)\n ...options,\n });\n}\n","import { useQuery, UseQueryOptions } from '@tanstack/react-query';\nimport { NotificationPreferences, NotificationPreferencesSchema } from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { notificationKeys } from '../keys.js';\n\nexport interface UseNotificationPreferencesParams {\n userId: string;\n}\n\n/**\n * Fetch user notification preferences\n * GET /users/:userId/notifications/preferences\n *\n * Returns user preferences for notification delivery and frequency\n */\nexport function useNotificationPreferences(\n { userId }: UseNotificationPreferencesParams,\n options?: Omit<UseQueryOptions<NotificationPreferences>, 'queryKey' | 'queryFn'>\n) {\n return useQuery({\n queryKey: notificationKeys.preferences(userId),\n queryFn: async () => {\n const response = await api.get(`/users/${userId}/notifications/preferences`);\n const validated = NotificationPreferencesSchema.parse(response.data);\n return validated;\n },\n staleTime: 1000 * 60 * 5, // 5 minutes (preferences change infrequently)\n ...options,\n });\n}\n","import {\n useMutation,\n useQueryClient,\n type UseMutationOptions,\n} from '@tanstack/react-query';\nimport {\n NotificationCreateSchemaAdmin,\n NotificationCreateSchemaUser,\n NotificationSchema,\n useAppMode,\n type AlertType,\n} from '@pfm-platform/shared';\nimport type { Notification } from '@pfm-platform/shared';\nimport { api } from '../client';\nimport { notificationKeys } from '../keys';\n\n/**\n * Notification create data interface\n */\nexport interface NotificationCreate {\n message: string;\n alert_type: AlertType;\n created_at?: string;\n}\n\n/**\n * Parameters for useCreateNotification mutation\n */\nexport interface CreateNotificationParams {\n userId: string;\n data: NotificationCreate;\n}\n\n/**\n * Mutation hook for creating a new notification\n *\n * Creates a notification manually for testing purposes.\n * Uses mode switching for validation:\n * - Admin mode: Allows manual notification creation for test data\n * - User mode: Blocked (notifications are system-generated)\n *\n * @example\n * ```tsx\n * const createNotification = useCreateNotification();\n *\n * createNotification.mutate({\n * userId: 'user123',\n * data: {\n * message: 'Test notification',\n * alert_type: 'AccountThresholdAlert',\n * created_at: new Date().toISOString() // Optional\n * }\n * });\n * ```\n */\nexport function useCreateNotification(\n options?: Omit<\n UseMutationOptions<Notification, Error, CreateNotificationParams>,\n 'mutationFn'\n >\n) {\n const queryClient = useQueryClient();\n const { mode } = useAppMode();\n\n return useMutation({\n mutationFn: async ({ userId, data }: CreateNotificationParams) => {\n // Select schema based on mode\n const schema =\n mode === 'admin'\n ? NotificationCreateSchemaAdmin\n : NotificationCreateSchemaUser;\n\n // Validate notification data\n const validated = schema.parse(data);\n\n // POST to create new notification\n const response = await api.post(\n `/users/${userId}/alerts/notifications`,\n validated\n );\n\n // Return created notification\n return NotificationSchema.parse(response.data);\n },\n onSuccess: (_, { userId }) => {\n // Invalidate notifications query to refetch updated list\n queryClient.invalidateQueries({\n queryKey: notificationKeys.list(userId),\n });\n },\n ...options,\n });\n}\n","import {\n useMutation,\n useQueryClient,\n type UseMutationOptions,\n} from '@tanstack/react-query';\nimport {\n NotificationUpdateSchemaAdmin,\n NotificationUpdateSchemaUser,\n NotificationSchema,\n useAppMode,\n type AlertType,\n} from '@pfm-platform/shared';\nimport type { Notification } from '@pfm-platform/shared';\nimport { api } from '../client';\nimport { notificationKeys } from '../keys';\n\n/**\n * Notification update data interface\n */\nexport interface NotificationUpdate {\n message?: string;\n alert_type?: AlertType;\n is_read?: boolean;\n}\n\n/**\n * Parameters for useUpdateNotification mutation\n */\nexport interface UpdateNotificationParams {\n userId: string;\n notificationId: number;\n data: NotificationUpdate;\n}\n\n/**\n * Mutation hook for updating a notification\n *\n * Uses mode switching for validation:\n * - Admin mode: Allows updating message and alert_type for test scenarios\n * - User mode: Allows marking notifications as read/unread\n *\n * @example\n * ```tsx\n * const updateNotification = useUpdateNotification();\n *\n * // User mode: mark as read\n * updateNotification.mutate({\n * userId: 'user123',\n * notificationId: 1,\n * data: { is_read: true }\n * });\n *\n * // Admin mode: update message\n * updateNotification.mutate({\n * userId: 'user123',\n * notificationId: 1,\n * data: { message: 'Updated test notification' }\n * });\n * ```\n */\nexport function useUpdateNotification(\n options?: Omit<\n UseMutationOptions<Notification, Error, UpdateNotificationParams>,\n 'mutationFn'\n >\n) {\n const queryClient = useQueryClient();\n const { mode } = useAppMode();\n\n return useMutation({\n mutationFn: async ({\n userId,\n notificationId,\n data,\n }: UpdateNotificationParams) => {\n // Select schema based on mode\n const schema =\n mode === 'admin'\n ? NotificationUpdateSchemaAdmin\n : NotificationUpdateSchemaUser;\n\n // Validate notification update data\n const validated = schema.parse(data);\n\n // PUT to update notification\n const response = await api.put(\n `/users/${userId}/alerts/notifications/${notificationId}`,\n validated\n );\n\n // Return updated notification\n return NotificationSchema.parse(response.data);\n },\n onSuccess: (_, { userId }) => {\n // Invalidate notifications query to refetch updated list\n queryClient.invalidateQueries({\n queryKey: notificationKeys.list(userId),\n });\n },\n ...options,\n });\n}\n","import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query';\nimport { api } from '../client.js';\nimport { notificationKeys } from '../keys.js';\n\nexport interface DeleteNotificationParams {\n userId: string;\n notificationId: number;\n}\n\n/**\n * Delete a notification\n * DELETE /users/:userId/alerts/notifications/:notificationId\n *\n * Notifications are system-generated, deletion only removes from view\n */\nexport function useDeleteNotification(\n options?: Omit<UseMutationOptions<void, Error, DeleteNotificationParams>, 'mutationFn'>\n) {\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ userId, notificationId }: DeleteNotificationParams) => {\n await api.delete(`/users/${userId}/alerts/notifications/${notificationId}`);\n },\n onSuccess: (_, { userId }) => {\n // Invalidate notifications list to refetch without deleted item\n queryClient.invalidateQueries({ queryKey: notificationKeys.list(userId) });\n },\n ...options,\n });\n}\n","import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query';\nimport {\n NotificationPreferences,\n NotificationPreferencesSchema,\n NotificationPreferencesUpdateSchema,\n} from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { notificationKeys } from '../keys.js';\n\nexport interface UpdateNotificationPreferencesParams {\n userId: string;\n data: Partial<NotificationPreferences>;\n}\n\n/**\n * Update user notification preferences\n * PUT /users/:userId/notifications/preferences\n *\n * Updates delivery and frequency preferences for notifications\n */\nexport function useUpdateNotificationPreferences(\n options?: UseMutationOptions<\n NotificationPreferences,\n Error,\n UpdateNotificationPreferencesParams\n >\n) {\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ userId, data }: UpdateNotificationPreferencesParams) => {\n // Validate update data\n const validated = NotificationPreferencesUpdateSchema.parse(data);\n\n const response = await api.put(`/users/${userId}/notifications/preferences`, validated);\n return NotificationPreferencesSchema.parse(response.data);\n },\n onSuccess: (_, { userId }) => {\n // Invalidate preferences query to refetch\n queryClient.invalidateQueries({ queryKey: notificationKeys.preferences(userId) });\n },\n ...options,\n });\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _tanstack_react_query from '@tanstack/react-query';
2
2
  import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
3
- import { Notification, AlertType } from '@pfm-platform/shared';
3
+ import { Notification, NotificationPreferences, AlertType } from '@pfm-platform/shared';
4
4
  import * as axios from 'axios';
5
5
 
6
6
  interface UseNotificationsParams {
@@ -15,11 +15,29 @@ interface UseNotificationsParams {
15
15
  */
16
16
  declare function useNotifications({ userId }: UseNotificationsParams, options?: Omit<UseQueryOptions<Notification[]>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<{
17
17
  id: number;
18
+ user_id: string;
19
+ alert_id: number;
18
20
  message: string;
19
21
  alert_type: "AccountThresholdAlert" | "GoalAlert" | "MerchantNameAlert" | "SpendingTargetAlert" | "TransactionLimitAlert" | "UpcomingBillAlert";
22
+ is_read: boolean;
20
23
  created_at: string;
21
24
  }[], Error>;
22
25
 
26
+ interface UseNotificationPreferencesParams {
27
+ userId: string;
28
+ }
29
+ /**
30
+ * Fetch user notification preferences
31
+ * GET /users/:userId/notifications/preferences
32
+ *
33
+ * Returns user preferences for notification delivery and frequency
34
+ */
35
+ declare function useNotificationPreferences({ userId }: UseNotificationPreferencesParams, options?: Omit<UseQueryOptions<NotificationPreferences>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<{
36
+ emailNotifications: boolean;
37
+ pushNotifications: boolean;
38
+ frequency: "weekly" | "realtime" | "daily";
39
+ }, Error>;
40
+
23
41
  /**
24
42
  * Notification create data interface
25
43
  */
@@ -59,8 +77,11 @@ interface CreateNotificationParams {
59
77
  */
60
78
  declare function useCreateNotification(options?: Omit<UseMutationOptions<Notification, Error, CreateNotificationParams>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<{
61
79
  id: number;
80
+ user_id: string;
81
+ alert_id: number;
62
82
  message: string;
63
83
  alert_type: "AccountThresholdAlert" | "GoalAlert" | "MerchantNameAlert" | "SpendingTargetAlert" | "TransactionLimitAlert" | "UpcomingBillAlert";
84
+ is_read: boolean;
64
85
  created_at: string;
65
86
  }, Error, CreateNotificationParams, unknown>;
66
87
 
@@ -70,6 +91,7 @@ declare function useCreateNotification(options?: Omit<UseMutationOptions<Notific
70
91
  interface NotificationUpdate {
71
92
  message?: string;
72
93
  alert_type?: AlertType;
94
+ is_read?: boolean;
73
95
  }
74
96
  /**
75
97
  * Parameters for useUpdateNotification mutation
@@ -82,28 +104,36 @@ interface UpdateNotificationParams {
82
104
  /**
83
105
  * Mutation hook for updating a notification
84
106
  *
85
- * Updates notification fields for testing purposes.
86
107
  * Uses mode switching for validation:
87
- * - Admin mode: Allows updating notifications for test scenarios
88
- * - User mode: Blocked (notifications are system-generated)
108
+ * - Admin mode: Allows updating message and alert_type for test scenarios
109
+ * - User mode: Allows marking notifications as read/unread
89
110
  *
90
111
  * @example
91
112
  * ```tsx
92
113
  * const updateNotification = useUpdateNotification();
93
114
  *
115
+ * // User mode: mark as read
94
116
  * updateNotification.mutate({
95
117
  * userId: 'user123',
96
118
  * notificationId: 1,
97
- * data: {
98
- * message: 'Updated test notification'
99
- * }
119
+ * data: { is_read: true }
120
+ * });
121
+ *
122
+ * // Admin mode: update message
123
+ * updateNotification.mutate({
124
+ * userId: 'user123',
125
+ * notificationId: 1,
126
+ * data: { message: 'Updated test notification' }
100
127
  * });
101
128
  * ```
102
129
  */
103
130
  declare function useUpdateNotification(options?: Omit<UseMutationOptions<Notification, Error, UpdateNotificationParams>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<{
104
131
  id: number;
132
+ user_id: string;
133
+ alert_id: number;
105
134
  message: string;
106
135
  alert_type: "AccountThresholdAlert" | "GoalAlert" | "MerchantNameAlert" | "SpendingTargetAlert" | "TransactionLimitAlert" | "UpcomingBillAlert";
136
+ is_read: boolean;
107
137
  created_at: string;
108
138
  }, Error, UpdateNotificationParams, unknown>;
109
139
 
@@ -119,6 +149,22 @@ interface DeleteNotificationParams {
119
149
  */
120
150
  declare function useDeleteNotification(options?: Omit<UseMutationOptions<void, Error, DeleteNotificationParams>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<void, Error, DeleteNotificationParams, unknown>;
121
151
 
152
+ interface UpdateNotificationPreferencesParams {
153
+ userId: string;
154
+ data: Partial<NotificationPreferences>;
155
+ }
156
+ /**
157
+ * Update user notification preferences
158
+ * PUT /users/:userId/notifications/preferences
159
+ *
160
+ * Updates delivery and frequency preferences for notifications
161
+ */
162
+ declare function useUpdateNotificationPreferences(options?: UseMutationOptions<NotificationPreferences, Error, UpdateNotificationPreferencesParams>): _tanstack_react_query.UseMutationResult<{
163
+ emailNotifications: boolean;
164
+ pushNotifications: boolean;
165
+ frequency: "weekly" | "realtime" | "daily";
166
+ }, Error, UpdateNotificationPreferencesParams, unknown>;
167
+
122
168
  /**
123
169
  * Query key factory for Notifications domain
124
170
  */
@@ -126,12 +172,13 @@ declare const notificationKeys: {
126
172
  all: readonly ["notifications"];
127
173
  lists: () => readonly ["notifications", "list"];
128
174
  list: (userId: string) => readonly ["notifications", "list", string];
175
+ preferences: (userId: string) => readonly ["notifications", "preferences", string];
129
176
  };
130
177
 
131
178
  /**
132
179
  * Axios instance for Notifications API
133
- * Base URL configured through environment variables or defaults to relative path
180
+ * Base URL configured through environment variables or defaults to localhost for tests
134
181
  */
135
182
  declare const api: axios.AxiosInstance;
136
183
 
137
- export { type CreateNotificationParams, type DeleteNotificationParams, type NotificationCreate, type NotificationUpdate, type UpdateNotificationParams, type UseNotificationsParams, api, notificationKeys, useCreateNotification, useDeleteNotification, useNotifications, useUpdateNotification };
184
+ export { type CreateNotificationParams, type DeleteNotificationParams, type NotificationCreate, type NotificationUpdate, type UpdateNotificationParams, type UpdateNotificationPreferencesParams, type UseNotificationPreferencesParams, type UseNotificationsParams, api, notificationKeys, useCreateNotification, useDeleteNotification, useNotificationPreferences, useNotifications, useUpdateNotification, useUpdateNotificationPreferences };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _tanstack_react_query from '@tanstack/react-query';
2
2
  import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
3
- import { Notification, AlertType } from '@pfm-platform/shared';
3
+ import { Notification, NotificationPreferences, AlertType } from '@pfm-platform/shared';
4
4
  import * as axios from 'axios';
5
5
 
6
6
  interface UseNotificationsParams {
@@ -15,11 +15,29 @@ interface UseNotificationsParams {
15
15
  */
16
16
  declare function useNotifications({ userId }: UseNotificationsParams, options?: Omit<UseQueryOptions<Notification[]>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<{
17
17
  id: number;
18
+ user_id: string;
19
+ alert_id: number;
18
20
  message: string;
19
21
  alert_type: "AccountThresholdAlert" | "GoalAlert" | "MerchantNameAlert" | "SpendingTargetAlert" | "TransactionLimitAlert" | "UpcomingBillAlert";
22
+ is_read: boolean;
20
23
  created_at: string;
21
24
  }[], Error>;
22
25
 
26
+ interface UseNotificationPreferencesParams {
27
+ userId: string;
28
+ }
29
+ /**
30
+ * Fetch user notification preferences
31
+ * GET /users/:userId/notifications/preferences
32
+ *
33
+ * Returns user preferences for notification delivery and frequency
34
+ */
35
+ declare function useNotificationPreferences({ userId }: UseNotificationPreferencesParams, options?: Omit<UseQueryOptions<NotificationPreferences>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<{
36
+ emailNotifications: boolean;
37
+ pushNotifications: boolean;
38
+ frequency: "weekly" | "realtime" | "daily";
39
+ }, Error>;
40
+
23
41
  /**
24
42
  * Notification create data interface
25
43
  */
@@ -59,8 +77,11 @@ interface CreateNotificationParams {
59
77
  */
60
78
  declare function useCreateNotification(options?: Omit<UseMutationOptions<Notification, Error, CreateNotificationParams>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<{
61
79
  id: number;
80
+ user_id: string;
81
+ alert_id: number;
62
82
  message: string;
63
83
  alert_type: "AccountThresholdAlert" | "GoalAlert" | "MerchantNameAlert" | "SpendingTargetAlert" | "TransactionLimitAlert" | "UpcomingBillAlert";
84
+ is_read: boolean;
64
85
  created_at: string;
65
86
  }, Error, CreateNotificationParams, unknown>;
66
87
 
@@ -70,6 +91,7 @@ declare function useCreateNotification(options?: Omit<UseMutationOptions<Notific
70
91
  interface NotificationUpdate {
71
92
  message?: string;
72
93
  alert_type?: AlertType;
94
+ is_read?: boolean;
73
95
  }
74
96
  /**
75
97
  * Parameters for useUpdateNotification mutation
@@ -82,28 +104,36 @@ interface UpdateNotificationParams {
82
104
  /**
83
105
  * Mutation hook for updating a notification
84
106
  *
85
- * Updates notification fields for testing purposes.
86
107
  * Uses mode switching for validation:
87
- * - Admin mode: Allows updating notifications for test scenarios
88
- * - User mode: Blocked (notifications are system-generated)
108
+ * - Admin mode: Allows updating message and alert_type for test scenarios
109
+ * - User mode: Allows marking notifications as read/unread
89
110
  *
90
111
  * @example
91
112
  * ```tsx
92
113
  * const updateNotification = useUpdateNotification();
93
114
  *
115
+ * // User mode: mark as read
94
116
  * updateNotification.mutate({
95
117
  * userId: 'user123',
96
118
  * notificationId: 1,
97
- * data: {
98
- * message: 'Updated test notification'
99
- * }
119
+ * data: { is_read: true }
120
+ * });
121
+ *
122
+ * // Admin mode: update message
123
+ * updateNotification.mutate({
124
+ * userId: 'user123',
125
+ * notificationId: 1,
126
+ * data: { message: 'Updated test notification' }
100
127
  * });
101
128
  * ```
102
129
  */
103
130
  declare function useUpdateNotification(options?: Omit<UseMutationOptions<Notification, Error, UpdateNotificationParams>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<{
104
131
  id: number;
132
+ user_id: string;
133
+ alert_id: number;
105
134
  message: string;
106
135
  alert_type: "AccountThresholdAlert" | "GoalAlert" | "MerchantNameAlert" | "SpendingTargetAlert" | "TransactionLimitAlert" | "UpcomingBillAlert";
136
+ is_read: boolean;
107
137
  created_at: string;
108
138
  }, Error, UpdateNotificationParams, unknown>;
109
139
 
@@ -119,6 +149,22 @@ interface DeleteNotificationParams {
119
149
  */
120
150
  declare function useDeleteNotification(options?: Omit<UseMutationOptions<void, Error, DeleteNotificationParams>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<void, Error, DeleteNotificationParams, unknown>;
121
151
 
152
+ interface UpdateNotificationPreferencesParams {
153
+ userId: string;
154
+ data: Partial<NotificationPreferences>;
155
+ }
156
+ /**
157
+ * Update user notification preferences
158
+ * PUT /users/:userId/notifications/preferences
159
+ *
160
+ * Updates delivery and frequency preferences for notifications
161
+ */
162
+ declare function useUpdateNotificationPreferences(options?: UseMutationOptions<NotificationPreferences, Error, UpdateNotificationPreferencesParams>): _tanstack_react_query.UseMutationResult<{
163
+ emailNotifications: boolean;
164
+ pushNotifications: boolean;
165
+ frequency: "weekly" | "realtime" | "daily";
166
+ }, Error, UpdateNotificationPreferencesParams, unknown>;
167
+
122
168
  /**
123
169
  * Query key factory for Notifications domain
124
170
  */
@@ -126,12 +172,13 @@ declare const notificationKeys: {
126
172
  all: readonly ["notifications"];
127
173
  lists: () => readonly ["notifications", "list"];
128
174
  list: (userId: string) => readonly ["notifications", "list", string];
175
+ preferences: (userId: string) => readonly ["notifications", "preferences", string];
129
176
  };
130
177
 
131
178
  /**
132
179
  * Axios instance for Notifications API
133
- * Base URL configured through environment variables or defaults to relative path
180
+ * Base URL configured through environment variables or defaults to localhost for tests
134
181
  */
135
182
  declare const api: axios.AxiosInstance;
136
183
 
137
- export { type CreateNotificationParams, type DeleteNotificationParams, type NotificationCreate, type NotificationUpdate, type UpdateNotificationParams, type UseNotificationsParams, api, notificationKeys, useCreateNotification, useDeleteNotification, useNotifications, useUpdateNotification };
184
+ export { type CreateNotificationParams, type DeleteNotificationParams, type NotificationCreate, type NotificationUpdate, type UpdateNotificationParams, type UpdateNotificationPreferencesParams, type UseNotificationPreferencesParams, type UseNotificationsParams, api, notificationKeys, useCreateNotification, useDeleteNotification, useNotificationPreferences, useNotifications, useUpdateNotification, useUpdateNotificationPreferences };
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
2
- import { NotificationsResponseSchema, useAppMode, NotificationCreateSchemaAdmin, NotificationCreateSchemaUser, NotificationSchema, NotificationUpdateSchemaAdmin, NotificationUpdateSchemaUser } from '@pfm-platform/shared';
2
+ import { NotificationsResponseSchema, NotificationPreferencesSchema, useAppMode, NotificationCreateSchemaAdmin, NotificationCreateSchemaUser, NotificationSchema, NotificationUpdateSchemaAdmin, NotificationUpdateSchemaUser, NotificationPreferencesUpdateSchema } from '@pfm-platform/shared';
3
3
  import axios from 'axios';
4
4
 
5
5
  // src/queries/useNotifications.ts
6
6
  var api = axios.create({
7
- baseURL: "/api",
7
+ baseURL: "http://localhost:3000/api",
8
8
  headers: {
9
9
  "Content-Type": "application/json"
10
10
  }
@@ -14,7 +14,8 @@ var api = axios.create({
14
14
  var notificationKeys = {
15
15
  all: ["notifications"],
16
16
  lists: () => [...notificationKeys.all, "list"],
17
- list: (userId) => [...notificationKeys.lists(), userId]
17
+ list: (userId) => [...notificationKeys.lists(), userId],
18
+ preferences: (userId) => [...notificationKeys.all, "preferences", userId]
18
19
  };
19
20
 
20
21
  // src/queries/useNotifications.ts
@@ -31,6 +32,19 @@ function useNotifications({ userId }, options) {
31
32
  ...options
32
33
  });
33
34
  }
35
+ function useNotificationPreferences({ userId }, options) {
36
+ return useQuery({
37
+ queryKey: notificationKeys.preferences(userId),
38
+ queryFn: async () => {
39
+ const response = await api.get(`/users/${userId}/notifications/preferences`);
40
+ const validated = NotificationPreferencesSchema.parse(response.data);
41
+ return validated;
42
+ },
43
+ staleTime: 1e3 * 60 * 5,
44
+ // 5 minutes (preferences change infrequently)
45
+ ...options
46
+ });
47
+ }
34
48
  function useCreateNotification(options) {
35
49
  const queryClient = useQueryClient();
36
50
  const { mode } = useAppMode();
@@ -89,7 +103,21 @@ function useDeleteNotification(options) {
89
103
  ...options
90
104
  });
91
105
  }
106
+ function useUpdateNotificationPreferences(options) {
107
+ const queryClient = useQueryClient();
108
+ return useMutation({
109
+ mutationFn: async ({ userId, data }) => {
110
+ const validated = NotificationPreferencesUpdateSchema.parse(data);
111
+ const response = await api.put(`/users/${userId}/notifications/preferences`, validated);
112
+ return NotificationPreferencesSchema.parse(response.data);
113
+ },
114
+ onSuccess: (_, { userId }) => {
115
+ queryClient.invalidateQueries({ queryKey: notificationKeys.preferences(userId) });
116
+ },
117
+ ...options
118
+ });
119
+ }
92
120
 
93
- export { api, notificationKeys, useCreateNotification, useDeleteNotification, useNotifications, useUpdateNotification };
121
+ export { api, notificationKeys, useCreateNotification, useDeleteNotification, useNotificationPreferences, useNotifications, useUpdateNotification, useUpdateNotificationPreferences };
94
122
  //# sourceMappingURL=index.js.map
95
123
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts","../src/keys.ts","../src/queries/useNotifications.ts","../src/mutations/useCreateNotification.ts","../src/mutations/useUpdateNotification.ts","../src/mutations/useDeleteNotification.ts"],"names":["useQueryClient","useAppMode","useMutation","NotificationSchema"],"mappings":";;;;;AAMO,IAAM,GAAA,GAAM,MAAM,MAAA,CAAO;AAAA,EAC9B,OAAA,EAAS,MAAA;AAAA,EACT,OAAA,EAAS;AAAA,IACP,cAAA,EAAgB;AAAA;AAEpB,CAAC;;;ACRM,IAAM,gBAAA,GAAmB;AAAA,EAC9B,GAAA,EAAK,CAAC,eAAe,CAAA;AAAA,EACrB,OAAO,MAAM,CAAC,GAAG,gBAAA,CAAiB,KAAK,MAAM,CAAA;AAAA,EAC7C,IAAA,EAAM,CAAC,MAAA,KAAmB,CAAC,GAAG,gBAAA,CAAiB,KAAA,IAAS,MAAM;AAChE;;;ACSO,SAAS,gBAAA,CACd,EAAE,MAAA,EAAO,EACT,OAAA,EACA;AACA,EAAA,OAAO,QAAA,CAAS;AAAA,IACd,QAAA,EAAU,gBAAA,CAAiB,IAAA,CAAK,MAAM,CAAA;AAAA,IACtC,SAAS,YAAY;AACnB,MAAA,MAAM,WAAW,MAAM,GAAA,CAAI,GAAA,CAAI,CAAA,OAAA,EAAU,MAAM,CAAA,qBAAA,CAAuB,CAAA;AACtE,MAAA,MAAM,SAAA,GAAY,2BAAA,CAA4B,KAAA,CAAM,QAAA,CAAS,IAAI,CAAA;AACjE,MAAA,OAAO,SAAA,CAAU,aAAA;AAAA,IACnB,CAAA;AAAA,IACA,SAAA,EAAW,MAAO,EAAA,GAAK,CAAA;AAAA;AAAA,IACvB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AA,GAAW,MAAM,GAAA,CAAI,GAAA;AAAA,QACzB,CAAA,OAAA,EAAU,MAAM,CAAA,sBAAA,EAAyB,cAAc,CAAA,CAAA;AAAA,QACvD;AAAA,OACF;AAGA,MAAA,OAAOC,kBAAAA,CAAmB,KAAA,CAAM,QAAA,CAAS,IAAI,CAAA;AAAA,IAC/C,CAAA;AAAA,IACA,SAAA,EAAW,CAAC,CAAA,EAAG,EAAE,QAAO,KAAM;AAE5B,MAAA,WAAA,CAAY,iBAAA,CAAkB;AAAA,QAC5B,QAAA,EAAU,gBAAA,CAAiB,IAAA,CAAK,MAAM;AAAA,OACvC,CAAA;AAAA,IACH,CAAA;AAAA,IACA,GAAG;AAAA,GACJ,CAAA;AACH;AChFO,SAAS,sBACd,OAAA,EACA;AACA,EAAA,MAAM,cAAcH,cAAAA,EAAe;AAEnC,EAAA,OAAOE,WAAAA,CAAY;AAAA,IACjB,UAAA,EAAY,OAAO,EAAE,MAAA,EAAQ,gBAAe,KAAgC;AAC1E,MAAA,MAAM,IAAI,MAAA,CAAO,CAAA,OAAA,EAAU,MAAM,CAAA,sBAAA,EAAyB,cAAc,CAAA,CAAE,CAAA;AAAA,IAC5E,CAAA;AAAA,IACA,SAAA,EAAW,CAAC,CAAA,EAAG,EAAE,QAAO,KAAM;AAE5B,MAAA,WAAA,CAAY,kBAAkB,EAAE,QAAA,EAAU,iBAAiB,IAAA,CAAK,MAAM,GAAG,CAAA;AAAA,IAC3E,CAAA;AAAA,IACA,GAAG;AAAA,GACJ,CAAA;AACH","file":"index.js","sourcesContent":["import axios from 'axios';\n\n/**\n * Axios instance for Notifications 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 Notifications domain\n */\nexport const notificationKeys = {\n all: ['notifications'] as const,\n lists: () => [...notificationKeys.all, 'list'] as const,\n list: (userId: string) => [...notificationKeys.lists(), userId] as const,\n};\n","import { useQuery, UseQueryOptions } from '@tanstack/react-query';\nimport { Notification, NotificationsResponseSchema } from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { notificationKeys } from '../keys.js';\n\nexport interface UseNotificationsParams {\n userId: string;\n}\n\n/**\n * Fetch all notifications for a user\n * GET /users/:userId/alerts/notifications\n *\n * Notifications are system-generated based on alert configurations\n * Read-only domain (no create/update operations)\n */\nexport function useNotifications(\n { userId }: UseNotificationsParams,\n options?: Omit<UseQueryOptions<Notification[]>, 'queryKey' | 'queryFn'>\n) {\n return useQuery({\n queryKey: notificationKeys.list(userId),\n queryFn: async () => {\n const response = await api.get(`/users/${userId}/alerts/notifications`);\n const validated = NotificationsResponseSchema.parse(response.data);\n return validated.notifications;\n },\n staleTime: 1000 * 60 * 2, // 2 minutes (notifications change frequently)\n ...options,\n });\n}\n","import {\n useMutation,\n useQueryClient,\n type UseMutationOptions,\n} from '@tanstack/react-query';\nimport {\n NotificationCreateSchemaAdmin,\n NotificationCreateSchemaUser,\n NotificationSchema,\n useAppMode,\n type AlertType,\n} from '@pfm-platform/shared';\nimport type { Notification } from '@pfm-platform/shared';\nimport { api } from '../client';\nimport { notificationKeys } from '../keys';\n\n/**\n * Notification create data interface\n */\nexport interface NotificationCreate {\n message: string;\n alert_type: AlertType;\n created_at?: string;\n}\n\n/**\n * Parameters for useCreateNotification mutation\n */\nexport interface CreateNotificationParams {\n userId: string;\n data: NotificationCreate;\n}\n\n/**\n * Mutation hook for creating a new notification\n *\n * Creates a notification manually for testing purposes.\n * Uses mode switching for validation:\n * - Admin mode: Allows manual notification creation for test data\n * - User mode: Blocked (notifications are system-generated)\n *\n * @example\n * ```tsx\n * const createNotification = useCreateNotification();\n *\n * createNotification.mutate({\n * userId: 'user123',\n * data: {\n * message: 'Test notification',\n * alert_type: 'AccountThresholdAlert',\n * created_at: new Date().toISOString() // Optional\n * }\n * });\n * ```\n */\nexport function useCreateNotification(\n options?: Omit<\n UseMutationOptions<Notification, Error, CreateNotificationParams>,\n 'mutationFn'\n >\n) {\n const queryClient = useQueryClient();\n const { mode } = useAppMode();\n\n return useMutation({\n mutationFn: async ({ userId, data }: CreateNotificationParams) => {\n // Select schema based on mode\n const schema =\n mode === 'admin'\n ? NotificationCreateSchemaAdmin\n : NotificationCreateSchemaUser;\n\n // Validate notification data\n const validated = schema.parse(data);\n\n // POST to create new notification\n const response = await api.post(\n `/users/${userId}/alerts/notifications`,\n validated\n );\n\n // Return created notification\n return NotificationSchema.parse(response.data);\n },\n onSuccess: (_, { userId }) => {\n // Invalidate notifications query to refetch updated list\n queryClient.invalidateQueries({\n queryKey: notificationKeys.list(userId),\n });\n },\n ...options,\n });\n}\n","import {\n useMutation,\n useQueryClient,\n type UseMutationOptions,\n} from '@tanstack/react-query';\nimport {\n NotificationUpdateSchemaAdmin,\n NotificationUpdateSchemaUser,\n NotificationSchema,\n useAppMode,\n type AlertType,\n} from '@pfm-platform/shared';\nimport type { Notification } from '@pfm-platform/shared';\nimport { api } from '../client';\nimport { notificationKeys } from '../keys';\n\n/**\n * Notification update data interface\n */\nexport interface NotificationUpdate {\n message?: string;\n alert_type?: AlertType;\n}\n\n/**\n * Parameters for useUpdateNotification mutation\n */\nexport interface UpdateNotificationParams {\n userId: string;\n notificationId: number;\n data: NotificationUpdate;\n}\n\n/**\n * Mutation hook for updating a notification\n *\n * Updates notification fields for testing purposes.\n * Uses mode switching for validation:\n * - Admin mode: Allows updating notifications for test scenarios\n * - User mode: Blocked (notifications are system-generated)\n *\n * @example\n * ```tsx\n * const updateNotification = useUpdateNotification();\n *\n * updateNotification.mutate({\n * userId: 'user123',\n * notificationId: 1,\n * data: {\n * message: 'Updated test notification'\n * }\n * });\n * ```\n */\nexport function useUpdateNotification(\n options?: Omit<\n UseMutationOptions<Notification, Error, UpdateNotificationParams>,\n 'mutationFn'\n >\n) {\n const queryClient = useQueryClient();\n const { mode } = useAppMode();\n\n return useMutation({\n mutationFn: async ({\n userId,\n notificationId,\n data,\n }: UpdateNotificationParams) => {\n // Select schema based on mode\n const schema =\n mode === 'admin'\n ? NotificationUpdateSchemaAdmin\n : NotificationUpdateSchemaUser;\n\n // Validate notification update data\n const validated = schema.parse(data);\n\n // PUT to update notification\n const response = await api.put(\n `/users/${userId}/alerts/notifications/${notificationId}`,\n validated\n );\n\n // Return updated notification\n return NotificationSchema.parse(response.data);\n },\n onSuccess: (_, { userId }) => {\n // Invalidate notifications query to refetch updated list\n queryClient.invalidateQueries({\n queryKey: notificationKeys.list(userId),\n });\n },\n ...options,\n });\n}\n","import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query';\nimport { api } from '../client.js';\nimport { notificationKeys } from '../keys.js';\n\nexport interface DeleteNotificationParams {\n userId: string;\n notificationId: number;\n}\n\n/**\n * Delete a notification\n * DELETE /users/:userId/alerts/notifications/:notificationId\n *\n * Notifications are system-generated, deletion only removes from view\n */\nexport function useDeleteNotification(\n options?: Omit<UseMutationOptions<void, Error, DeleteNotificationParams>, 'mutationFn'>\n) {\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ userId, notificationId }: DeleteNotificationParams) => {\n await api.delete(`/users/${userId}/alerts/notifications/${notificationId}`);\n },\n onSuccess: (_, { userId }) => {\n // Invalidate notifications list to refetch without deleted item\n queryClient.invalidateQueries({ queryKey: notificationKeys.list(userId) });\n },\n ...options,\n });\n}\n"]}
1
+ {"version":3,"sources":["../src/client.ts","../src/keys.ts","../src/queries/useNotifications.ts","../src/queries/useNotificationPreferences.ts","../src/mutations/useCreateNotification.ts","../src/mutations/useUpdateNotification.ts","../src/mutations/useDeleteNotification.ts","../src/mutations/useUpdateNotificationPreferences.ts"],"names":["useQuery","useQueryClient","useAppMode","useMutation","NotificationSchema","NotificationPreferencesSchema"],"mappings":";;;;;AAMO,IAAM,GAAA,GAAM,MAAM,MAAA,CAAO;AAAA,EAC9B,OAAA,EAAS,2BAAA;AAAA,EACT,OAAA,EAAS;AAAA,IACP,cAAA,EAAgB;AAAA;AAEpB,CAAC;;;ACR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KAAA,CAAM,IAAI,CAAA;AAEhE,MAAA,MAAM,WAAW,MAAM,GAAA,CAAI,IAAI,CAAA,OAAA,EAAU,MAAM,8BAA8B,SAAS,CAAA;AACtF,MAAA,OAAOE,6BAAAA,CAA8B,KAAA,CAAM,QAAA,CAAS,IAAI,CAAA;AAAA,IAC1D,CAAA;AAAA,IACA,SAAA,EAAW,CAAC,CAAA,EAAG,EAAE,QAAO,KAAM;AAE5B,MAAA,WAAA,CAAY,kBAAkB,EAAE,QAAA,EAAU,iBAAiB,WAAA,CAAY,MAAM,GAAG,CAAA;AAAA,IAClF,CAAA;AAAA,IACA,GAAG;AAAA,GACJ,CAAA;AACH","file":"index.js","sourcesContent":["import axios from 'axios';\n\n/**\n * Axios instance for Notifications API\n * Base URL configured through environment variables or defaults to localhost for tests\n */\nexport const api = axios.create({\n baseURL: 'http://localhost:3000/api',\n headers: {\n 'Content-Type': 'application/json',\n },\n});\n","/**\n * Query key factory for Notifications domain\n */\nexport const notificationKeys = {\n all: ['notifications'] as const,\n lists: () => [...notificationKeys.all, 'list'] as const,\n list: (userId: string) => [...notificationKeys.lists(), userId] as const,\n preferences: (userId: string) => [...notificationKeys.all, 'preferences', userId] as const,\n};\n","import { useQuery, UseQueryOptions } from '@tanstack/react-query';\nimport { Notification, NotificationsResponseSchema } from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { notificationKeys } from '../keys.js';\n\nexport interface UseNotificationsParams {\n userId: string;\n}\n\n/**\n * Fetch all notifications for a user\n * GET /users/:userId/alerts/notifications\n *\n * Notifications are system-generated based on alert configurations\n * Read-only domain (no create/update operations)\n */\nexport function useNotifications(\n { userId }: UseNotificationsParams,\n options?: Omit<UseQueryOptions<Notification[]>, 'queryKey' | 'queryFn'>\n) {\n return useQuery({\n queryKey: notificationKeys.list(userId),\n queryFn: async () => {\n const response = await api.get(`/users/${userId}/alerts/notifications`);\n const validated = NotificationsResponseSchema.parse(response.data);\n return validated.notifications;\n },\n staleTime: 1000 * 60 * 2, // 2 minutes (notifications change frequently)\n ...options,\n });\n}\n","import { useQuery, UseQueryOptions } from '@tanstack/react-query';\nimport { NotificationPreferences, NotificationPreferencesSchema } from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { notificationKeys } from '../keys.js';\n\nexport interface UseNotificationPreferencesParams {\n userId: string;\n}\n\n/**\n * Fetch user notification preferences\n * GET /users/:userId/notifications/preferences\n *\n * Returns user preferences for notification delivery and frequency\n */\nexport function useNotificationPreferences(\n { userId }: UseNotificationPreferencesParams,\n options?: Omit<UseQueryOptions<NotificationPreferences>, 'queryKey' | 'queryFn'>\n) {\n return useQuery({\n queryKey: notificationKeys.preferences(userId),\n queryFn: async () => {\n const response = await api.get(`/users/${userId}/notifications/preferences`);\n const validated = NotificationPreferencesSchema.parse(response.data);\n return validated;\n },\n staleTime: 1000 * 60 * 5, // 5 minutes (preferences change infrequently)\n ...options,\n });\n}\n","import {\n useMutation,\n useQueryClient,\n type UseMutationOptions,\n} from '@tanstack/react-query';\nimport {\n NotificationCreateSchemaAdmin,\n NotificationCreateSchemaUser,\n NotificationSchema,\n useAppMode,\n type AlertType,\n} from '@pfm-platform/shared';\nimport type { Notification } from '@pfm-platform/shared';\nimport { api } from '../client';\nimport { notificationKeys } from '../keys';\n\n/**\n * Notification create data interface\n */\nexport interface NotificationCreate {\n message: string;\n alert_type: AlertType;\n created_at?: string;\n}\n\n/**\n * Parameters for useCreateNotification mutation\n */\nexport interface CreateNotificationParams {\n userId: string;\n data: NotificationCreate;\n}\n\n/**\n * Mutation hook for creating a new notification\n *\n * Creates a notification manually for testing purposes.\n * Uses mode switching for validation:\n * - Admin mode: Allows manual notification creation for test data\n * - User mode: Blocked (notifications are system-generated)\n *\n * @example\n * ```tsx\n * const createNotification = useCreateNotification();\n *\n * createNotification.mutate({\n * userId: 'user123',\n * data: {\n * message: 'Test notification',\n * alert_type: 'AccountThresholdAlert',\n * created_at: new Date().toISOString() // Optional\n * }\n * });\n * ```\n */\nexport function useCreateNotification(\n options?: Omit<\n UseMutationOptions<Notification, Error, CreateNotificationParams>,\n 'mutationFn'\n >\n) {\n const queryClient = useQueryClient();\n const { mode } = useAppMode();\n\n return useMutation({\n mutationFn: async ({ userId, data }: CreateNotificationParams) => {\n // Select schema based on mode\n const schema =\n mode === 'admin'\n ? NotificationCreateSchemaAdmin\n : NotificationCreateSchemaUser;\n\n // Validate notification data\n const validated = schema.parse(data);\n\n // POST to create new notification\n const response = await api.post(\n `/users/${userId}/alerts/notifications`,\n validated\n );\n\n // Return created notification\n return NotificationSchema.parse(response.data);\n },\n onSuccess: (_, { userId }) => {\n // Invalidate notifications query to refetch updated list\n queryClient.invalidateQueries({\n queryKey: notificationKeys.list(userId),\n });\n },\n ...options,\n });\n}\n","import {\n useMutation,\n useQueryClient,\n type UseMutationOptions,\n} from '@tanstack/react-query';\nimport {\n NotificationUpdateSchemaAdmin,\n NotificationUpdateSchemaUser,\n NotificationSchema,\n useAppMode,\n type AlertType,\n} from '@pfm-platform/shared';\nimport type { Notification } from '@pfm-platform/shared';\nimport { api } from '../client';\nimport { notificationKeys } from '../keys';\n\n/**\n * Notification update data interface\n */\nexport interface NotificationUpdate {\n message?: string;\n alert_type?: AlertType;\n is_read?: boolean;\n}\n\n/**\n * Parameters for useUpdateNotification mutation\n */\nexport interface UpdateNotificationParams {\n userId: string;\n notificationId: number;\n data: NotificationUpdate;\n}\n\n/**\n * Mutation hook for updating a notification\n *\n * Uses mode switching for validation:\n * - Admin mode: Allows updating message and alert_type for test scenarios\n * - User mode: Allows marking notifications as read/unread\n *\n * @example\n * ```tsx\n * const updateNotification = useUpdateNotification();\n *\n * // User mode: mark as read\n * updateNotification.mutate({\n * userId: 'user123',\n * notificationId: 1,\n * data: { is_read: true }\n * });\n *\n * // Admin mode: update message\n * updateNotification.mutate({\n * userId: 'user123',\n * notificationId: 1,\n * data: { message: 'Updated test notification' }\n * });\n * ```\n */\nexport function useUpdateNotification(\n options?: Omit<\n UseMutationOptions<Notification, Error, UpdateNotificationParams>,\n 'mutationFn'\n >\n) {\n const queryClient = useQueryClient();\n const { mode } = useAppMode();\n\n return useMutation({\n mutationFn: async ({\n userId,\n notificationId,\n data,\n }: UpdateNotificationParams) => {\n // Select schema based on mode\n const schema =\n mode === 'admin'\n ? NotificationUpdateSchemaAdmin\n : NotificationUpdateSchemaUser;\n\n // Validate notification update data\n const validated = schema.parse(data);\n\n // PUT to update notification\n const response = await api.put(\n `/users/${userId}/alerts/notifications/${notificationId}`,\n validated\n );\n\n // Return updated notification\n return NotificationSchema.parse(response.data);\n },\n onSuccess: (_, { userId }) => {\n // Invalidate notifications query to refetch updated list\n queryClient.invalidateQueries({\n queryKey: notificationKeys.list(userId),\n });\n },\n ...options,\n });\n}\n","import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query';\nimport { api } from '../client.js';\nimport { notificationKeys } from '../keys.js';\n\nexport interface DeleteNotificationParams {\n userId: string;\n notificationId: number;\n}\n\n/**\n * Delete a notification\n * DELETE /users/:userId/alerts/notifications/:notificationId\n *\n * Notifications are system-generated, deletion only removes from view\n */\nexport function useDeleteNotification(\n options?: Omit<UseMutationOptions<void, Error, DeleteNotificationParams>, 'mutationFn'>\n) {\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ userId, notificationId }: DeleteNotificationParams) => {\n await api.delete(`/users/${userId}/alerts/notifications/${notificationId}`);\n },\n onSuccess: (_, { userId }) => {\n // Invalidate notifications list to refetch without deleted item\n queryClient.invalidateQueries({ queryKey: notificationKeys.list(userId) });\n },\n ...options,\n });\n}\n","import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query';\nimport {\n NotificationPreferences,\n NotificationPreferencesSchema,\n NotificationPreferencesUpdateSchema,\n} from '@pfm-platform/shared';\nimport { api } from '../client.js';\nimport { notificationKeys } from '../keys.js';\n\nexport interface UpdateNotificationPreferencesParams {\n userId: string;\n data: Partial<NotificationPreferences>;\n}\n\n/**\n * Update user notification preferences\n * PUT /users/:userId/notifications/preferences\n *\n * Updates delivery and frequency preferences for notifications\n */\nexport function useUpdateNotificationPreferences(\n options?: UseMutationOptions<\n NotificationPreferences,\n Error,\n UpdateNotificationPreferencesParams\n >\n) {\n const queryClient = useQueryClient();\n\n return useMutation({\n mutationFn: async ({ userId, data }: UpdateNotificationPreferencesParams) => {\n // Validate update data\n const validated = NotificationPreferencesUpdateSchema.parse(data);\n\n const response = await api.put(`/users/${userId}/notifications/preferences`, validated);\n return NotificationPreferencesSchema.parse(response.data);\n },\n onSuccess: (_, { userId }) => {\n // Invalidate preferences query to refetch\n queryClient.invalidateQueries({ queryKey: notificationKeys.preferences(userId) });\n },\n ...options,\n });\n}\n"]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@pfm-platform/notifications-data-access",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "dependencies": {
7
7
  "axios": "^1.13.2",
8
8
  "zod": "4.1.12",
9
- "@pfm-platform/shared": "0.0.1"
9
+ "@pfm-platform/shared": "0.1.0"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@testing-library/react": "^16.3.0",