Files
supabase/apps/studio/data/subscriptions/project-addons-query.ts
T
Kevin Grüneberg a6bfc44f83 chore: increase stale time for project addons / org subscription (#33911)
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.
2025-03-05 15:39:02 +01:00

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,
}
)