Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat(ui): audit log api hooks
Akhil Mohan49ae2386c07f
diff --git a/frontend/src/hooks/api/auditLogStreams/index.tsx b/frontend/src/hooks/api/auditLogStreams/index.tsxnew file mode 100644index 0000000000..72b1fba1af--- /dev/null+++ b/frontend/src/hooks/api/auditLogStreams/index.tsx@@ -0,0 +1,6 @@+export {+ useCreateAuditLogStream,+ useDeleteAuditLogStream,+ useUpdateAuditLogStream+} from "./mutations";+export { useGetAuditLogStreamDetails, useGetAuditLogStreams } from "./queries";diff --git a/frontend/src/hooks/api/auditLogStreams/mutations.tsx b/frontend/src/hooks/api/auditLogStreams/mutations.tsxnew file mode 100644index 0000000000..902efbb57d--- /dev/null+++ b/frontend/src/hooks/api/auditLogStreams/mutations.tsx@@ -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));+ }+ });+};diff --git a/frontend/src/hooks/api/auditLogStreams/queries.tsx b/frontend/src/hooks/api/auditLogStreams/queries.tsxnew file mode 100644index 0000000000..4c636ac286--- /dev/null+++ b/frontend/src/hooks/api/auditLogStreams/queries.tsx@@ -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)+ });diff --git a/frontend/src/hooks/api/auditLogStreams/types.ts b/frontend/src/hooks/api/auditLogStreams/types.tsnew file mode 100644index 0000000000..3163f96d7c--- /dev/null+++ b/frontend/src/hooks/api/auditLogStreams/types.ts@@ -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;+};diff --git a/frontend/src/hooks/api/index.tsx b/frontend/src/hooks/api/index.tsxindex b2df27f2da..574da5a319 100644--- a/frontend/src/hooks/api/index.tsx+++ b/frontend/src/hooks/api/index.tsx@@ -1,6 +1,7 @@export * from "./admin";export * from "./apiKeys";export * from "./auditLogs";+export * from "./auditLogStreams";export * from "./auth";export * from "./bots";export * from "./dynamicSecret";diff --git a/frontend/src/hooks/api/subscriptions/types.ts b/frontend/src/hooks/api/subscriptions/types.tsindex 46facedd30..45414292da 100644--- a/frontend/src/hooks/api/subscriptions/types.ts+++ b/frontend/src/hooks/api/subscriptions/types.ts@@ -5,6 +5,8 @@ export type SubscriptionPlan = {auditLogs: boolean;dynamicSecret: boolean;auditLogsRetentionDays: number;+ auditLogStreamLimit: number;+ auditLogStreams: boolean;customAlerts: boolean;customRateLimits: boolean;pitRecovery: boolean;diff --git a/frontend/src/hooks/api/types.ts b/frontend/src/hooks/api/types.tsindex d6b43d6749..49949d88e1 100644--- a/frontend/src/hooks/api/types.ts+++ b/frontend/src/hooks/api/types.ts@@ -1,5 +1,6 @@import { ZodIssue } from "zod";+export type { TAuditLogStream } from "./auditLogStreams/types";export type { GetAuthTokenAPI } from "./auth/types";export type { IncidentContact } from "./incidentContacts/types";export type { IntegrationAuth } from "./integrationAuth/types";@@ -48,13 +49,13 @@ export enum ApiErrorTypes {export type TApiErrors =| {- error: ApiErrorTypes.ValidationError;- message: ZodIssue[];- statusCode: 403;- }+ error: ApiErrorTypes.ValidationError;+ message: ZodIssue[];+ statusCode: 403;+ }| { error: ApiErrorTypes.ForbiddenError; message: string; statusCode: 401 }| {- statusCode: 400;- message: string;- error: ApiErrorTypes.BadRequestError;- };+ statusCode: 400;+ message: string;+ error: ApiErrorTypes.BadRequestError;+ };