mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-26 02:32:36 +00:00
✨ Add access react query
This commit is contained in:
@@ -2,7 +2,10 @@ import { build } from "@server/build";
|
|||||||
import { StatusHistoryResponse } from "@server/lib/statusHistory";
|
import { StatusHistoryResponse } from "@server/lib/statusHistory";
|
||||||
import type { ListAlertRulesResponse } from "@server/routers/alertRule/types";
|
import type { ListAlertRulesResponse } from "@server/routers/alertRule/types";
|
||||||
import type { QueryRequestAnalyticsResponse } from "@server/routers/auditLogs";
|
import type { QueryRequestAnalyticsResponse } from "@server/routers/auditLogs";
|
||||||
import type { QueryRequestAuditLogResponse } from "@server/routers/auditLogs/types";
|
import type {
|
||||||
|
QueryAccessAuditLogResponse,
|
||||||
|
QueryRequestAuditLogResponse
|
||||||
|
} from "@server/routers/auditLogs/types";
|
||||||
import type { ListClientsResponse } from "@server/routers/client";
|
import type { ListClientsResponse } from "@server/routers/client";
|
||||||
import type {
|
import type {
|
||||||
GetDNSRecordsResponse,
|
GetDNSRecordsResponse,
|
||||||
@@ -592,7 +595,7 @@ export const logAnalyticsFiltersSchema = z.object({
|
|||||||
|
|
||||||
export type LogAnalyticsFilters = z.output<typeof logAnalyticsFiltersSchema>;
|
export type LogAnalyticsFilters = z.output<typeof logAnalyticsFiltersSchema>;
|
||||||
|
|
||||||
export const logsFiltersSchema = z.object({
|
export const httpLogsFiltersSchema = z.object({
|
||||||
timeStart: z
|
timeStart: z
|
||||||
.string()
|
.string()
|
||||||
.refine((val) => !isNaN(Date.parse(val)), {
|
.refine((val) => !isNaN(Date.parse(val)), {
|
||||||
@@ -619,7 +622,32 @@ export const logsFiltersSchema = z.object({
|
|||||||
path: z.string().optional().catch(undefined)
|
path: z.string().optional().catch(undefined)
|
||||||
});
|
});
|
||||||
|
|
||||||
export type LogFilters = z.output<typeof logsFiltersSchema>;
|
export type HttpLogFilters = z.output<typeof httpLogsFiltersSchema>;
|
||||||
|
|
||||||
|
export const accessLogsFiltersSchema = z.object({
|
||||||
|
timeStart: z
|
||||||
|
.string()
|
||||||
|
.refine((val) => !isNaN(Date.parse(val)), {
|
||||||
|
error: "timeStart must be a valid ISO date string"
|
||||||
|
})
|
||||||
|
.optional()
|
||||||
|
.catch(undefined),
|
||||||
|
timeEnd: z
|
||||||
|
.string()
|
||||||
|
.refine((val) => !isNaN(Date.parse(val)), {
|
||||||
|
error: "timeEnd must be a valid ISO date string"
|
||||||
|
})
|
||||||
|
.optional()
|
||||||
|
.catch(undefined),
|
||||||
|
page: z.coerce.number().optional().catch(0).default(0),
|
||||||
|
pageSize: z.coerce.number().optional().catch(20).default(20),
|
||||||
|
resourceId: z.coerce.number().optional().catch(undefined),
|
||||||
|
action: z.string().optional().catch(undefined),
|
||||||
|
location: z.string().optional().catch(undefined),
|
||||||
|
actor: z.string().optional().catch(undefined)
|
||||||
|
});
|
||||||
|
|
||||||
|
export type AccessLogFilters = z.output<typeof accessLogsFiltersSchema>;
|
||||||
|
|
||||||
export const logQueries = {
|
export const logQueries = {
|
||||||
requestAnalytics: ({
|
requestAnalytics: ({
|
||||||
@@ -648,7 +676,13 @@ export const logQueries = {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
requests: ({ orgId, filters }: { orgId: string; filters: LogFilters }) =>
|
requests: ({
|
||||||
|
orgId,
|
||||||
|
filters
|
||||||
|
}: {
|
||||||
|
orgId: string;
|
||||||
|
filters: HttpLogFilters;
|
||||||
|
}) =>
|
||||||
queryOptions({
|
queryOptions({
|
||||||
queryKey: ["REQUEST_LOGS", orgId, "ALL", filters] as const,
|
queryKey: ["REQUEST_LOGS", orgId, "ALL", filters] as const,
|
||||||
queryFn: async ({ signal, meta }) => {
|
queryFn: async ({ signal, meta }) => {
|
||||||
@@ -671,6 +705,31 @@ export const logQueries = {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
access: ({ orgId, filters }: { orgId: string; filters: HttpLogFilters }) =>
|
||||||
|
queryOptions({
|
||||||
|
queryKey: ["ACCESS_LOGS", orgId, "ALL", filters] as const,
|
||||||
|
queryFn: async ({ signal, meta }) => {
|
||||||
|
const { page, pageSize, ...rest } = filters;
|
||||||
|
const res = await meta!.api.get<
|
||||||
|
AxiosResponse<QueryAccessAuditLogResponse>
|
||||||
|
>(`/org/${orgId}/logs/access`, {
|
||||||
|
params: {
|
||||||
|
...rest,
|
||||||
|
limit: pageSize,
|
||||||
|
offset: page * pageSize
|
||||||
|
},
|
||||||
|
signal
|
||||||
|
});
|
||||||
|
return res.data.data;
|
||||||
|
},
|
||||||
|
refetchInterval: (query) => {
|
||||||
|
if (query.state.data) {
|
||||||
|
return durationToMs(30, "seconds");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user