Files
supabase/apps/docs/lib/fetch/projectApi.ts
Charis 37923df609 fix: move docs off deprecated endpoint (#34490)
Docs is using a deprecated endpoint to get the API keys for the project variables component. Move to a new endpoint.
2025-03-27 16:44:54 -04:00

46 lines
1.2 KiB
TypeScript

import type { ResponseError } from '~/types/fetch'
import { get } from './fetchWrappers'
import { UseQueryOptions, useQuery } from '@tanstack/react-query'
const projectApiKeys = {
api: (projectRef: string | undefined) => ['projects', projectRef, 'api'] as const,
}
export interface ProjectApiVariables {
projectRef?: string
}
async function getProjectApi({ projectRef }: ProjectApiVariables, signal?: AbortSignal) {
if (!projectRef) {
throw Error('projectRef is required')
}
const { data, error } = await get('/platform/projects/{ref}/settings', {
params: {
path: { ref: projectRef },
},
signal,
})
if (error) throw error
return data
}
export type ProjectApiData = Awaited<ReturnType<typeof getProjectApi>>
type ProjectApiError = ResponseError
export function useProjectApiQuery<TData = ProjectApiData>(
{ projectRef }: ProjectApiVariables,
{
enabled = true,
...options
}: Omit<UseQueryOptions<ProjectApiData, ProjectApiError, TData>, 'queryKey'> = {}
) {
return useQuery<ProjectApiData, ProjectApiError, TData>({
queryKey: projectApiKeys.api(projectRef),
queryFn: ({ signal }) => getProjectApi({ projectRef }, signal),
enabled,
...options,
})
}