79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
import { apiClient } from "@/shared/api/axios.instance";
|
|
import type {
|
|
AgentInfo,
|
|
TokenCreate,
|
|
TokenUser,
|
|
LogEntry,
|
|
LogFilters,
|
|
InsertLogRequest,
|
|
InsertLogsRequest,
|
|
} from "../types/agent.types";
|
|
|
|
class AgentApiService {
|
|
private readonly basePath = "/agents";
|
|
private readonly authBasePath = "/auth";
|
|
private readonly logsBasePath = "/logs";
|
|
|
|
async getAgents(): Promise<AgentInfo[]> {
|
|
const response = await apiClient.get<AgentInfo[]>(this.basePath);
|
|
return response.data;
|
|
}
|
|
|
|
async getUsers(): Promise<TokenUser[]> {
|
|
const response = await apiClient.get<TokenUser[]>(`${this.authBasePath}/tokens`);
|
|
return response.data;
|
|
}
|
|
|
|
async createUser(data: TokenCreate): Promise<void> {
|
|
await apiClient.post(`${this.authBasePath}/token`, data);
|
|
}
|
|
|
|
async deleteUser(login: string): Promise<void> {
|
|
await apiClient.delete(`${this.authBasePath}/tokens/${login}`);
|
|
}
|
|
|
|
async deleteMyAccount(): Promise<void> {
|
|
await apiClient.delete(`${this.authBasePath}/token`);
|
|
}
|
|
|
|
async searchLogs(filters?: LogFilters): Promise<LogEntry[]> {
|
|
const response = await apiClient.get<LogEntry[]>(this.logsBasePath, {
|
|
params: {
|
|
level: filters?.level,
|
|
service: filters?.service,
|
|
agent: filters?.agent,
|
|
date_from: filters?.date_from,
|
|
date_to: filters?.date_to,
|
|
limit: filters?.limit ?? 100,
|
|
offset: filters?.offset ?? 0,
|
|
},
|
|
});
|
|
return response.data;
|
|
}
|
|
|
|
async insertLog(entry: InsertLogRequest): Promise<void> {
|
|
await apiClient.post(this.logsBasePath, entry);
|
|
}
|
|
|
|
async insertLogsBatch(data: InsertLogsRequest): Promise<void> {
|
|
await apiClient.post(`${this.logsBasePath}/batch`, data);
|
|
}
|
|
|
|
async getDistinctAgents(): Promise<string[]> {
|
|
const response = await apiClient.get<string[]>(`${this.logsBasePath}/agents`);
|
|
return response.data;
|
|
}
|
|
|
|
async getDistinctLevels(): Promise<string[]> {
|
|
const response = await apiClient.get<string[]>(`${this.logsBasePath}/levels`);
|
|
return response.data;
|
|
}
|
|
|
|
async getDistinctServices(): Promise<string[]> {
|
|
const response = await apiClient.get<string[]>(`${this.logsBasePath}/services`);
|
|
return response.data;
|
|
}
|
|
}
|
|
|
|
export const agentApiService = new AgentApiService();
|