40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
|
|
import { useQuery } from '@tanstack/vue-query';
|
||
|
|
import { apiClient } from '../lib/api/client';
|
||
|
|
|
||
|
|
export interface NotificationStatus {
|
||
|
|
secretConfigured: boolean;
|
||
|
|
secretHint: string | null;
|
||
|
|
webhookSecret: string | null;
|
||
|
|
packageWhitelist: string[];
|
||
|
|
ingestedCount: number;
|
||
|
|
lastNotificationAt: string | null;
|
||
|
|
ingestEndpoint: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
const initialStatus: NotificationStatus = {
|
||
|
|
secretConfigured: false,
|
||
|
|
secretHint: null,
|
||
|
|
webhookSecret: null,
|
||
|
|
packageWhitelist: [],
|
||
|
|
ingestedCount: 0,
|
||
|
|
lastNotificationAt: null,
|
||
|
|
ingestEndpoint: 'http://localhost:4000/api/transactions/notification'
|
||
|
|
};
|
||
|
|
|
||
|
|
export function useNotificationStatusQuery() {
|
||
|
|
return useQuery<NotificationStatus>({
|
||
|
|
queryKey: ['notification-status'],
|
||
|
|
queryFn: async () => {
|
||
|
|
try {
|
||
|
|
const { data } = await apiClient.get('/notifications/status');
|
||
|
|
return data as NotificationStatus;
|
||
|
|
} catch (error) {
|
||
|
|
console.warn('[notifications] using fallback status', error);
|
||
|
|
return initialStatus;
|
||
|
|
}
|
||
|
|
},
|
||
|
|
initialData: initialStatus,
|
||
|
|
staleTime: 30_000
|
||
|
|
});
|
||
|
|
}
|