feat(webhook): time-series histogram stats endpoint + frontend chart
This commit is contained in:
@@ -21,6 +21,7 @@ import {
|
||||
type SchemaDependent,
|
||||
type SearchResponse,
|
||||
type WebhookDeliveryPage,
|
||||
type WebhookDeliveryStats,
|
||||
type WebhookSubscription,
|
||||
} from './client'
|
||||
|
||||
@@ -440,6 +441,47 @@ export const webhookDlqQuery = (page: number, size: number) =>
|
||||
export const useWebhookDlq = (page: number, size: number) =>
|
||||
useQuery(webhookDlqQuery(page, size))
|
||||
|
||||
export const webhookStatsQuery = (
|
||||
id: string,
|
||||
bucketBy: 'hour' | 'day',
|
||||
fromIso?: string,
|
||||
toIso?: string,
|
||||
) =>
|
||||
queryOptions({
|
||||
queryKey: [
|
||||
'webhooks',
|
||||
'stats',
|
||||
id,
|
||||
bucketBy,
|
||||
fromIso ?? null,
|
||||
toIso ?? null,
|
||||
] as const,
|
||||
queryFn: async (): Promise<WebhookDeliveryStats> => {
|
||||
const params: Record<string, string> = { bucketBy }
|
||||
if (fromIso) params.from = fromIso
|
||||
if (toIso) params.to = toIso
|
||||
const { data } = await apiClient.get<WebhookDeliveryStats>(
|
||||
`/admin/webhooks/subscriptions/${encodeURIComponent(id)}/stats`,
|
||||
{ params },
|
||||
)
|
||||
return data
|
||||
},
|
||||
// Stats для admin dashboard — fresh data важна, но автополлинг мы
|
||||
// отключаем (юзер сам refresh'ит / меняет range).
|
||||
staleTime: 30 * 1000,
|
||||
})
|
||||
|
||||
export const useWebhookStats = (
|
||||
id: string,
|
||||
bucketBy: 'hour' | 'day',
|
||||
fromIso?: string,
|
||||
toIso?: string,
|
||||
) =>
|
||||
useQuery({
|
||||
...webhookStatsQuery(id, bucketBy, fromIso, toIso),
|
||||
enabled: Boolean(id),
|
||||
})
|
||||
|
||||
// === Dependents (Phase 1 dict-relationships-v2) ===
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user