Files
EvoFirewall/apps/web/src/queries/index.ts
T
DenozordecandCursor 0bed4367c7
Build and Push EvoFirewall Docker Image / build-and-push (push) Successful in 1m44s
Build and Push EvoFirewall Docker Image / create-release (push) Skipped
feat(policy): именованные наборы правил с DNS и M:N привязкой к агентам
Правила живут в policy_sets; evaluate мержит назначенные наборы; источник list|CIDR|hostname с кэшем DNS.

Co-authored-by: Cursor <[email protected]>
2026-07-20 22:11:03 +07:00

119 lines
2.9 KiB
TypeScript

import { queryOptions } from '@tanstack/react-query'
import { apiFetch } from '@/lib/api'
import type {
Agent,
DashboardStats,
IpList,
PolicyRule,
PolicySet,
} from '@evofw/shared'
export const dashboardQueryOptions = () =>
queryOptions({
queryKey: ['dashboard'],
queryFn: () => apiFetch<DashboardStats>('/api/v1/dashboard'),
})
export const agentsQueryOptions = () =>
queryOptions({
queryKey: ['agents'],
queryFn: () => apiFetch<{ items: Agent[] }>('/api/v1/agents'),
})
export const agentQueryOptions = (id: string) =>
queryOptions({
queryKey: ['agents', id],
queryFn: () => apiFetch<Agent>(`/api/v1/agents/${id}`),
})
export const listsQueryOptions = () =>
queryOptions({
queryKey: ['lists'],
queryFn: () => apiFetch<{ items: IpList[] }>('/api/v1/lists'),
})
export const policySetsQueryOptions = () =>
queryOptions({
queryKey: ['policy-sets'],
queryFn: () => apiFetch<{ items: PolicySet[] }>('/api/v1/policy-sets'),
})
export const policySetQueryOptions = (id: string) =>
queryOptions({
queryKey: ['policy-sets', id],
queryFn: () =>
apiFetch<PolicySet & { agent_ids: string[] }>(
`/api/v1/policy-sets/${id}`,
),
})
export const policySetRulesQueryOptions = (setId: string) =>
queryOptions({
queryKey: ['policy-sets', setId, 'rules'],
queryFn: () =>
apiFetch<{ items: PolicyRule[] }>(
`/api/v1/policy-sets/${setId}/rules`,
),
})
export const agentPolicySetsQueryOptions = (agentId: string) =>
queryOptions({
queryKey: ['agents', agentId, 'policy-sets'],
queryFn: () =>
apiFetch<{
items: {
set_id: string
sort: number
name: string
description?: string | null
enabled: boolean
}[]
}>(`/api/v1/agents/${agentId}/policy-sets`),
})
export const installContextQueryOptions = () =>
queryOptions({
queryKey: ['install-context'],
queryFn: () =>
apiFetch<{
suggested_cp_url: string
enroll_seed: string
install_sh_url: string
mikrotik_url: string
sync_interval_sec: number
}>('/api/v1/install-context'),
})
export const settingsQueryOptions = () =>
queryOptions({
queryKey: ['settings'],
queryFn: () => apiFetch<Record<string, string>>('/api/v1/settings'),
})
export const agentStatsQueryOptions = (id: string) =>
queryOptions({
queryKey: ['agent-stats', id],
queryFn: () =>
apiFetch<{
items: {
packets_dropped: number
packets_accepted: number
recorded_at: string
}[]
}>(`/api/v1/agents/${id}/stats`),
})
export const recentStatsQueryOptions = () =>
queryOptions({
queryKey: ['stats-recent'],
queryFn: () =>
apiFetch<{
items: {
agent_id: string
packets_dropped: number
packets_accepted: number
recorded_at: string
}[]
}>('/api/v1/stats/recent'),
})