mirror of
https://github.com/supabase/supabase.git
synced 2026-10-18 15:49:09 +03:00
Occasionally results in a 429 in API - there are plans to fix this on the API level, but it's not a quick change, so hoping to reduce the likeliness of 429 with a higher stale time. Subscriptions and project addons rarely change and if they are changed, it's invalidated on the client anyway.
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
|
|
import { get, handleError } from 'data/fetchers'
|
|
import { IS_PLATFORM } from 'lib/constants'
|
|
import type { ResponseError } from 'types'
|
|
import { subscriptionKeys } from './keys'
|
|
|
|
export type ProjectAddonsVariables = {
|
|
projectRef?: string
|
|
}
|
|
|
|
export async function getProjectAddons(
|
|
{ projectRef }: ProjectAddonsVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
|
|
const { error, data } = await get(`/platform/projects/{ref}/billing/addons`, {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type ProjectAddonsData = Awaited<ReturnType<typeof getProjectAddons>>
|
|
export type ProjectAddonsError = ResponseError
|
|
|
|
export const useProjectAddonsQuery = <TData = ProjectAddonsData>(
|
|
{ projectRef }: ProjectAddonsVariables,
|
|
{ enabled = true, ...options }: UseQueryOptions<ProjectAddonsData, ProjectAddonsError, TData> = {}
|
|
) =>
|
|
useQuery<ProjectAddonsData, ProjectAddonsError, TData>(
|
|
subscriptionKeys.addons(projectRef),
|
|
({ signal }) => getProjectAddons({ projectRef }, signal),
|
|
{
|
|
enabled: enabled && IS_PLATFORM && typeof projectRef !== 'undefined',
|
|
staleTime: 60 * 60 * 1000, // 60 minutes
|
|
...options,
|
|
}
|
|
)
|