mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 15:27:46 +00:00
feat(ui): audit log api hooks
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
export {
|
||||||
|
useCreateAuditLogStream,
|
||||||
|
useDeleteAuditLogStream,
|
||||||
|
useUpdateAuditLogStream
|
||||||
|
} from "./mutations";
|
||||||
|
export { useGetAuditLogStreamDetails, useGetAuditLogStreams } from "./queries";
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
|
import { apiRequest } from "@app/config/request";
|
||||||
|
|
||||||
|
import { auditLogStreamKeys } from "./queries";
|
||||||
|
import {
|
||||||
|
TAuditLogStream,
|
||||||
|
TCreateAuditLogStreamDTO,
|
||||||
|
TDeleteAuditLogStreamDTO,
|
||||||
|
TUpdateAuditLogStreamDTO
|
||||||
|
} from "./types";
|
||||||
|
|
||||||
|
export const useCreateAuditLogStream = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation<{ auditLogStream: TAuditLogStream }, {}, TCreateAuditLogStreamDTO>({
|
||||||
|
mutationFn: async (dto) => {
|
||||||
|
const { data } = await apiRequest.post<{ auditLogStream: TAuditLogStream }>(
|
||||||
|
"/api/v1/audit-log-streams",
|
||||||
|
dto
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
onSuccess: (_, { projectSlug }) => {
|
||||||
|
queryClient.invalidateQueries(auditLogStreamKeys.list(projectSlug));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useUpdateAuditLogStream = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation<{ auditLogStream: TAuditLogStream }, {}, TUpdateAuditLogStreamDTO>({
|
||||||
|
mutationFn: async (dto) => {
|
||||||
|
const { data } = await apiRequest.patch<{ auditLogStream: TAuditLogStream }>(
|
||||||
|
`/api/v1/audit-log-streams/${dto.id}`,
|
||||||
|
dto
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
onSuccess: (_, { projectSlug }) => {
|
||||||
|
queryClient.invalidateQueries(auditLogStreamKeys.list(projectSlug));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useDeleteAuditLogStream = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation<{ auditLogStream: TAuditLogStream }, {}, TDeleteAuditLogStreamDTO>({
|
||||||
|
mutationFn: async (dto) => {
|
||||||
|
const { data } = await apiRequest.delete<{ auditLogStream: TAuditLogStream }>(
|
||||||
|
`/api/v1/audit-log-streams/${dto.id}`
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
onSuccess: (_, { projectSlug }) => {
|
||||||
|
queryClient.invalidateQueries(auditLogStreamKeys.list(projectSlug));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
|
||||||
|
import { apiRequest } from "@app/config/request";
|
||||||
|
|
||||||
|
import { TAuditLogStream } from "./types";
|
||||||
|
|
||||||
|
export const auditLogStreamKeys = {
|
||||||
|
list: (projectSlug: string) => ["audit-log-stream", { projectSlug }],
|
||||||
|
getById: (id: string) => ["audit-log-stream-details", { id }]
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchAuditLogStreams = async (projectSlug: string) => {
|
||||||
|
const { data } = await apiRequest.get<{ auditLogStreams: TAuditLogStream[] }>(
|
||||||
|
"/api/v1/audit-log-streams",
|
||||||
|
{
|
||||||
|
params: {
|
||||||
|
projectSlug
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return data.auditLogStreams;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useGetAuditLogStreams = (projectSlug: string) =>
|
||||||
|
useQuery({
|
||||||
|
queryKey: auditLogStreamKeys.list(projectSlug),
|
||||||
|
queryFn: () => fetchAuditLogStreams(projectSlug),
|
||||||
|
enabled: Boolean(projectSlug)
|
||||||
|
});
|
||||||
|
|
||||||
|
const fetchAuditLogStreamDetails = async (id: string) => {
|
||||||
|
const { data } = await apiRequest.get<{ auditLogStream: TAuditLogStream }>(
|
||||||
|
`/api/v1/audit-log-streams/${id}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return data.auditLogStream;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useGetAuditLogStreamDetails = (id: string) =>
|
||||||
|
useQuery({
|
||||||
|
queryKey: auditLogStreamKeys.getById(id),
|
||||||
|
queryFn: () => fetchAuditLogStreamDetails(id),
|
||||||
|
enabled: Boolean(id)
|
||||||
|
});
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
export type TAuditLogStream = {
|
||||||
|
id: string;
|
||||||
|
url: string;
|
||||||
|
token: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TCreateAuditLogStreamDTO = {
|
||||||
|
projectSlug: string;
|
||||||
|
url: string;
|
||||||
|
token?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TUpdateAuditLogStreamDTO = {
|
||||||
|
id: string;
|
||||||
|
projectSlug: string;
|
||||||
|
url?: string;
|
||||||
|
token?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TDeleteAuditLogStreamDTO = {
|
||||||
|
id: string;
|
||||||
|
projectSlug: string;
|
||||||
|
};
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
export * from "./admin";
|
export * from "./admin";
|
||||||
export * from "./apiKeys";
|
export * from "./apiKeys";
|
||||||
export * from "./auditLogs";
|
export * from "./auditLogs";
|
||||||
|
export * from "./auditLogStreams";
|
||||||
export * from "./auth";
|
export * from "./auth";
|
||||||
export * from "./bots";
|
export * from "./bots";
|
||||||
export * from "./dynamicSecret";
|
export * from "./dynamicSecret";
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ export type SubscriptionPlan = {
|
|||||||
auditLogs: boolean;
|
auditLogs: boolean;
|
||||||
dynamicSecret: boolean;
|
dynamicSecret: boolean;
|
||||||
auditLogsRetentionDays: number;
|
auditLogsRetentionDays: number;
|
||||||
|
auditLogStreamLimit: number;
|
||||||
|
auditLogStreams: boolean;
|
||||||
customAlerts: boolean;
|
customAlerts: boolean;
|
||||||
customRateLimits: boolean;
|
customRateLimits: boolean;
|
||||||
pitRecovery: boolean;
|
pitRecovery: boolean;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { ZodIssue } from "zod";
|
import { ZodIssue } from "zod";
|
||||||
|
|
||||||
|
export type { TAuditLogStream } from "./auditLogStreams/types";
|
||||||
export type { GetAuthTokenAPI } from "./auth/types";
|
export type { GetAuthTokenAPI } from "./auth/types";
|
||||||
export type { IncidentContact } from "./incidentContacts/types";
|
export type { IncidentContact } from "./incidentContacts/types";
|
||||||
export type { IntegrationAuth } from "./integrationAuth/types";
|
export type { IntegrationAuth } from "./integrationAuth/types";
|
||||||
@@ -48,13 +49,13 @@ export enum ApiErrorTypes {
|
|||||||
|
|
||||||
export type TApiErrors =
|
export type TApiErrors =
|
||||||
| {
|
| {
|
||||||
error: ApiErrorTypes.ValidationError;
|
error: ApiErrorTypes.ValidationError;
|
||||||
message: ZodIssue[];
|
message: ZodIssue[];
|
||||||
statusCode: 403;
|
statusCode: 403;
|
||||||
}
|
}
|
||||||
| { error: ApiErrorTypes.ForbiddenError; message: string; statusCode: 401 }
|
| { error: ApiErrorTypes.ForbiddenError; message: string; statusCode: 401 }
|
||||||
| {
|
| {
|
||||||
statusCode: 400;
|
statusCode: 400;
|
||||||
message: string;
|
message: string;
|
||||||
error: ApiErrorTypes.BadRequestError;
|
error: ApiErrorTypes.BadRequestError;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user