mirror of
https://github.com/supabase/supabase.git
synced 2026-09-06 18:11:51 +08:00
Adds support for the new `integration_status` installation identification method for OAuth marketplace integrations, which will use the new integration state stored in Marketplace DB and updated via partner callbacks. Fixes INT-123
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { partnersKeys } from './keys'
|
|
import type { components } from '@/data/api'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type IntegrationVariables = {
|
|
projectRef?: string
|
|
}
|
|
|
|
export type IntegrationStatus =
|
|
components['schemas']['PartnerIntegrationListResponse']['integrations'][0]
|
|
|
|
async function getIntegrations({ projectRef }: IntegrationVariables, signal?: AbortSignal) {
|
|
if (!projectRef) throw new Error('Project ref is required')
|
|
|
|
const { data, error } = await get(`/platform/integrations/partners/{ref}`, {
|
|
params: { path: { ref: projectRef } },
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data.integrations
|
|
}
|
|
|
|
export type IntegrationsData = Awaited<ReturnType<typeof getIntegrations>>
|
|
export type IntegrationsError = ResponseError
|
|
|
|
export const usePartnerIntegrationsQuery = <TData = IntegrationsData>(
|
|
{ projectRef }: IntegrationVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseCustomQueryOptions<IntegrationsData, IntegrationsError, TData> = {}
|
|
) =>
|
|
useQuery<IntegrationsData, IntegrationsError, TData>({
|
|
queryKey: partnersKeys.getIntegrations(projectRef),
|
|
queryFn: ({ signal }) => getIntegrations({ projectRef }, signal),
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
})
|