Spaces:
Sleeping
Sleeping
Download befree-frontend/hooks/useOverwatchAPI.ts from Coeinterns/bank-statement-api: direct link, hf CLI and curl.
- Browser
- Download file 3.45 kB
-
https://huggingface.co/spaces/Coeinterns/bank-statement-api/resolve/main/befree-frontend/hooks/useOverwatchAPI.ts
- Command line
-
hf download hf://spaces/Coeinterns/bank-statement-api/befree-frontend/hooks/useOverwatchAPI.ts
-
curl -L -o useOverwatchAPI.ts https://huggingface.co/spaces/Coeinterns/bank-statement-api/resolve/main/befree-frontend/hooks/useOverwatchAPI.ts
3.45 kB
| import { | |
| useQuery, | |
| useMutation, | |
| } from '@tanstack/react-query'; | |
| import { apiClient } from '@/services/api-client'; | |
| import type { | |
| OverwatchDocumentsParams, | |
| OverwatchEventsParams, | |
| OverwatchInsights, | |
| } from '@/types'; | |
| export const overwatchKeys = { | |
| all: ['overwatch'] as const, | |
| insights: () => [...overwatchKeys.all, 'insights'] as const, | |
| logs: (filters?: Record<string, unknown>) => | |
| [...overwatchKeys.all, 'logs', filters ?? {}] as const, | |
| documents: (params?: OverwatchDocumentsParams) => | |
| [...overwatchKeys.all, 'documents', params ?? {}] as const, | |
| documentSummary: (documentId: string) => | |
| [...overwatchKeys.all, 'document', documentId, 'summary'] as const, | |
| events: (params?: OverwatchEventsParams) => | |
| [...overwatchKeys.all, 'events', params ?? {}] as const, | |
| }; | |
| // ββ Legacy UAT hooks (kept for backward compatibility) ββββββββββββββββββββββββ | |
| export const useOverwatchInsights = () => { | |
| return useQuery<OverwatchInsights>({ | |
| queryKey: overwatchKeys.insights(), | |
| queryFn: () => apiClient.getOverwatchInsights(), | |
| refetchInterval: 30 * 1000, | |
| }); | |
| }; | |
| export const useOverwatchLogs = (params: { | |
| log_type: 'audit' | 'classification'; | |
| username?: string; | |
| action?: string; | |
| category?: string; | |
| engine?: string; | |
| from_date?: string; | |
| to_date?: string; | |
| search?: string; | |
| page?: number; | |
| page_size?: number; | |
| }) => { | |
| return useQuery({ | |
| queryKey: overwatchKeys.logs(params), | |
| queryFn: () => apiClient.getOverwatchLogs(params), | |
| }); | |
| }; | |
| export const useEmailOverwatchReport = () => { | |
| return useMutation({ | |
| mutationFn: (payload: { | |
| email: string; | |
| log_type: 'audit' | 'classification' | 'both'; | |
| from_date?: string; | |
| to_date?: string; | |
| username?: string; | |
| category?: string; | |
| engine?: string; | |
| }) => apiClient.emailOverwatchReport(payload), | |
| }); | |
| }; | |
| // ββ Structured Event Store hooks ββββββββββββββββββββββββββββββββββββββββββββββ | |
| /** Paginated list of documents with their processing health summary. */ | |
| export const useOverwatchDocuments = (params: OverwatchDocumentsParams) => { | |
| return useQuery({ | |
| queryKey: overwatchKeys.documents(params), | |
| queryFn: () => apiClient.getOverwatchDocuments(params), | |
| staleTime: 10_000, | |
| }); | |
| }; | |
| /** | |
| * Full detail for a single document: extraction pipeline, classification | |
| * summary, and counters. Returns `isError` on 404 (no events yet) or 422. | |
| */ | |
| export const useOverwatchDocumentSummary = (documentId: string) => { | |
| return useQuery({ | |
| queryKey: overwatchKeys.documentSummary(documentId), | |
| queryFn: () => apiClient.getOverwatchDocumentSummary(documentId), | |
| enabled: documentId.length > 0, | |
| retry: (failureCount, error: unknown) => { | |
| // Don't retry on 404/422 β these are definitive responses | |
| const status = (error as { response?: { status?: number } })?.response?.status; | |
| if (status === 404 || status === 422) return false; | |
| return failureCount < 2; | |
| }, | |
| }); | |
| }; | |
| /** Paginated, filterable event log. */ | |
| export const useOverwatchEvents = (params: OverwatchEventsParams) => { | |
| return useQuery({ | |
| queryKey: overwatchKeys.events(params), | |
| queryFn: () => apiClient.getOverwatchEvents(params), | |
| }); | |
| }; | |