mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Cleanup after shipping https://github.com/supabase/supabase/pull/45389, the backend is now defaulting to the new v2 `format`, and made `format` param optional. So this: - removes references to `v2` naming, as this is the only format - removes the `format` query param from the audit logs API calls ## What is the current behavior? Same audit log functionality shown in https://github.com/supabase/supabase/pull/45389 ## What is the new behavior? Functionally the same behavior for audit logs. - [x] Manual test in staging ## Additional context ⚠️ Will leave the `do-not-merge` tag on until: - [ ] backend `format` optional PR lands in production. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Consolidated audit log type definitions and updated internal API request formatting for audit endpoints across Account and Organization audit log components. No changes to user-facing functionality or audit log display. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { profileKeys } from './keys'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import { AuditLog } from '@/data/organizations/organization-audit-logs-query'
|
|
import { IS_PLATFORM } from '@/lib/constants'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type ProfileAuditLogsVariables = {
|
|
iso_timestamp_start: string
|
|
iso_timestamp_end: string
|
|
}
|
|
|
|
export async function getProfileAuditLogs(
|
|
{ iso_timestamp_start, iso_timestamp_end }: ProfileAuditLogsVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
const { data, error } = await get('/platform/profile/audit', {
|
|
params: {
|
|
query: {
|
|
iso_timestamp_start,
|
|
iso_timestamp_end,
|
|
},
|
|
},
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data as unknown as ProfileAuditLogsData
|
|
}
|
|
|
|
export type ProfileAuditLogsError = ResponseError
|
|
export type ProfileAuditLogsData = {
|
|
result: AuditLog[]
|
|
retention_period: number
|
|
}
|
|
|
|
export const useProfileAuditLogsQuery = <TData = ProfileAuditLogsData>(
|
|
vars: ProfileAuditLogsVariables,
|
|
options: UseCustomQueryOptions<ProfileAuditLogsData, ProfileAuditLogsError, TData> = {}
|
|
) => {
|
|
const { iso_timestamp_start, iso_timestamp_end } = vars
|
|
return useQuery<ProfileAuditLogsData, ProfileAuditLogsError, TData>({
|
|
queryKey: profileKeys.auditLogs({
|
|
date_start: iso_timestamp_start,
|
|
date_end: iso_timestamp_end,
|
|
}),
|
|
queryFn: ({ signal }) => getProfileAuditLogs(vars, signal),
|
|
enabled: IS_PLATFORM && options.enabled,
|
|
...options,
|
|
})
|
|
}
|