mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
Update several files to use data fetcher methods
This commit is contained in:
1 parent
6bba977213
commit
22dd096928
11 files changed
+100
-155
No files matched your search
@@ -1,25 +1,21 @@
|
||||
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
|
||||
import { get } from 'lib/common/fetch'
|
||||
import { API_URL } from 'lib/constants'
|
||||
import { get, handleError } from 'data/fetchers'
|
||||
import type { ResponseError } from 'types'
|
||||
import type { Integration, IntegrationsVariables } from './integrations.types'
|
||||
import { integrationKeys } from './keys'
|
||||
|
||||
export type IntegrationsResponse = Integration[]
|
||||
type IntegrationsVariables = {
|
||||
orgSlug?: string
|
||||
}
|
||||
|
||||
export async function getIntegrations({ orgSlug }: IntegrationsVariables, signal?: AbortSignal) {
|
||||
if (!orgSlug) {
|
||||
throw new Error('orgSlug is required')
|
||||
}
|
||||
const response = await get(`${API_URL}/integrations/${orgSlug}?expand=true`, {
|
||||
signal,
|
||||
})
|
||||
if (response.error) {
|
||||
throw response.error
|
||||
}
|
||||
if (!orgSlug) throw new Error('orgSlug is required')
|
||||
|
||||
return response as IntegrationsResponse
|
||||
const { data, error } = await get('/platform/integrations/{slug}', {
|
||||
params: { path: { slug: orgSlug } },
|
||||
})
|
||||
if (error) handleError(error)
|
||||
return data
|
||||
}
|
||||
|
||||
export type IntegrationsData = Awaited<ReturnType<typeof getIntegrations>>
|
||||
|
||||
+10
-16
@@ -1,8 +1,8 @@
|
||||
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
|
||||
import { delete_, isResponseOk } from 'lib/common/fetch'
|
||||
import { API_URL } from 'lib/constants'
|
||||
import { toast } from 'sonner'
|
||||
import type { ResponseError, UserContent } from 'types'
|
||||
|
||||
import { del, handleError } from 'data/fetchers'
|
||||
import type { ResponseError } from 'types'
|
||||
import { integrationKeys } from './keys'
|
||||
|
||||
type DeleteVariables = {
|
||||
@@ -15,21 +15,15 @@ export async function deleteConnection(
|
||||
{ organization_integration_id, id }: DeleteVariables,
|
||||
signal?: AbortSignal
|
||||
) {
|
||||
if (!organization_integration_id) {
|
||||
throw new Error('organization_integration_id is required')
|
||||
}
|
||||
if (!organization_integration_id) throw new Error('organization_integration_id is required')
|
||||
|
||||
const response = await delete_<UserContent>(
|
||||
`${API_URL}/integrations/vercel/connections/${id}`,
|
||||
{ organization_integration_id },
|
||||
{ signal }
|
||||
)
|
||||
const { data, error } = await del('/platform/integrations/vercel/connections/{connection_id}', {
|
||||
params: { path: { connection_id: id } },
|
||||
signal,
|
||||
})
|
||||
|
||||
if (!isResponseOk(response)) {
|
||||
throw response.error
|
||||
}
|
||||
|
||||
return response
|
||||
if (error) handleError(error)
|
||||
return data
|
||||
}
|
||||
|
||||
type DeleteContentData = Awaited<ReturnType<typeof deleteConnection>>
|
||||
|
||||
@@ -160,10 +160,6 @@ export type IntegrationProjectConnection = {
|
||||
metadata: Imetadata
|
||||
}
|
||||
|
||||
export type IntegrationsVariables = {
|
||||
orgSlug?: string
|
||||
}
|
||||
|
||||
export type IntegrationProjectConnectionPayload = {
|
||||
foreignProjectId: string
|
||||
supabaseProjectId: string
|
||||
@@ -177,7 +173,6 @@ export type userDetails = {
|
||||
primary_email: string
|
||||
}
|
||||
type addedBy = userDetails
|
||||
type updatedBy = userDetails
|
||||
|
||||
export type IntegrationName = 'Vercel' | 'GitHub' // | 'Netlify'
|
||||
export type VercelAccountType = 'Team' | 'Personal'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
|
||||
import { post } from 'lib/common/fetch'
|
||||
import { API_URL } from 'lib/constants'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
import { handleError, post } from 'data/fetchers'
|
||||
import type { ResponseError } from 'types'
|
||||
import { integrationKeys } from './keys'
|
||||
|
||||
@@ -24,19 +24,21 @@ export async function createVercelIntegration({
|
||||
source,
|
||||
teamId,
|
||||
}: VercelIntegrationCreateVariables) {
|
||||
const response = await post(`${API_URL}/integrations/vercel`, {
|
||||
code,
|
||||
configuration_id: configurationId,
|
||||
organization_slug: orgSlug,
|
||||
metadata,
|
||||
source,
|
||||
teamId,
|
||||
const { data, error } = await post('/platform/integrations/vercel', {
|
||||
body: {
|
||||
code,
|
||||
configuration_id: configurationId,
|
||||
organization_slug: orgSlug,
|
||||
metadata: metadata as Record<string, never>,
|
||||
source,
|
||||
teamId,
|
||||
},
|
||||
})
|
||||
if (response.error) {
|
||||
throw response.error
|
||||
}
|
||||
|
||||
return response
|
||||
if (error) handleError(error)
|
||||
// [Joshen] API isn't typed on this endpoint
|
||||
// https://github.com/supabase/infrastructure/blob/develop/api/src/routes/platform/integrations/vercel/vercel-integration.controller.ts#L50
|
||||
return data as { id: string }
|
||||
}
|
||||
|
||||
type VercelIntegrationCreateData = Awaited<ReturnType<typeof createVercelIntegration>>
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
import { post } from 'lib/common/fetch'
|
||||
import { API_URL } from 'lib/constants'
|
||||
import { handleError, post } from 'data/fetchers'
|
||||
import type { ResponseError } from 'types'
|
||||
import { oauthAppKeys } from './keys'
|
||||
|
||||
@@ -15,9 +14,12 @@ export async function revokeAuthorizedApp({ id, slug }: AuthorizedAppRevokeVaria
|
||||
if (!id) throw new Error('App ID is required')
|
||||
if (!slug) throw new Error('Organization slug is required')
|
||||
|
||||
const response = await post(`${API_URL}/organizations/${slug}/oauth/apps/${id}/revoke`, {})
|
||||
if (response.error) throw response.error
|
||||
return response
|
||||
const { data, error } = await post('/platform/organizations/{slug}/oauth/apps/{id}/revoke', {
|
||||
params: { path: { slug, id } },
|
||||
})
|
||||
|
||||
if (error) handleError(error)
|
||||
return data
|
||||
}
|
||||
|
||||
type AuthorizedAppRevokeData = Awaited<ReturnType<typeof revokeAuthorizedApp>>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
import { get } from 'lib/common/fetch'
|
||||
import { API_URL } from 'lib/constants'
|
||||
import { oauthAppKeys } from './keys'
|
||||
|
||||
import { get, handleError } from 'data/fetchers'
|
||||
import type { ResponseError } from 'types'
|
||||
import { oauthAppKeys } from './keys'
|
||||
|
||||
export type AuthorizedAppsVariables = {
|
||||
slug?: string
|
||||
@@ -19,11 +19,12 @@ export type AuthorizedApp = {
|
||||
export async function getAuthorizedApps({ slug }: AuthorizedAppsVariables, signal?: AbortSignal) {
|
||||
if (!slug) throw new Error('Organization slug is required')
|
||||
|
||||
const response = await get(`${API_URL}/organizations/${slug}/oauth/apps?type=authorized`, {
|
||||
signal,
|
||||
const { data, error } = await get('/platform/organizations/{slug}/oauth/apps', {
|
||||
params: { path: { slug }, query: { type: 'authorized' } },
|
||||
})
|
||||
if (response.error) throw response.error
|
||||
return response as AuthorizedApp[]
|
||||
|
||||
if (error) handleError(error)
|
||||
return data
|
||||
}
|
||||
|
||||
export type AuthorizedAppsData = Awaited<ReturnType<typeof getAuthorizedApps>>
|
||||
|
||||
@@ -2,8 +2,8 @@ import type { OAuthScope } from '@supabase/shared-types/out/constants'
|
||||
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
import { post } from 'lib/common/fetch'
|
||||
import { API_URL } from 'lib/constants'
|
||||
import { components } from 'api-types'
|
||||
import { handleError, post } from 'data/fetchers'
|
||||
import type { ResponseError } from 'types'
|
||||
import { oauthAppKeys } from './keys'
|
||||
|
||||
@@ -16,11 +16,7 @@ export type OAuthAppCreateVariables = {
|
||||
redirect_uris: string[]
|
||||
}
|
||||
|
||||
export type OAuthAppCreateResponse = {
|
||||
id: string
|
||||
client_id: string
|
||||
client_secret: string
|
||||
}
|
||||
export type OAuthAppCreateResponse = components['schemas']['CreateOAuthAppResponse']
|
||||
|
||||
export async function createOAuthApp({
|
||||
slug,
|
||||
@@ -30,15 +26,19 @@ export async function createOAuthApp({
|
||||
scopes,
|
||||
redirect_uris,
|
||||
}: OAuthAppCreateVariables) {
|
||||
const response = await post(`${API_URL}/organizations/${slug}/oauth/apps`, {
|
||||
name,
|
||||
website,
|
||||
icon,
|
||||
scopes,
|
||||
redirect_uris,
|
||||
const { data, error } = await post('/platform/organizations/{slug}/oauth/apps', {
|
||||
params: { path: { slug } },
|
||||
body: {
|
||||
name,
|
||||
website,
|
||||
icon,
|
||||
scopes,
|
||||
redirect_uris,
|
||||
},
|
||||
})
|
||||
if (response.error) throw response.error
|
||||
return response as OAuthAppCreateResponse
|
||||
|
||||
if (error) handleError(error)
|
||||
return data
|
||||
}
|
||||
|
||||
type OAuthAppCreateData = Awaited<ReturnType<typeof createOAuthApp>>
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
import { delete_ } from 'lib/common/fetch'
|
||||
import { API_URL } from 'lib/constants'
|
||||
import { del, handleError } from 'data/fetchers'
|
||||
import type { ResponseError } from 'types'
|
||||
import { oauthAppKeys } from './keys'
|
||||
|
||||
@@ -15,9 +14,12 @@ export async function deleteOAuthApp({ id, slug }: OAuthAppDeleteVariables) {
|
||||
if (!id) throw new Error('OAuth app ID is required')
|
||||
if (!slug) throw new Error('Organization slug is required')
|
||||
|
||||
const response = await delete_(`${API_URL}/organizations/${slug}/oauth/apps/${id}?type=published`)
|
||||
if (response.error) throw response.error
|
||||
return response
|
||||
const { data, error } = await del('/platform/organizations/{slug}/oauth/apps/{id}', {
|
||||
params: { path: { slug, id } },
|
||||
})
|
||||
|
||||
if (error) handleError(error)
|
||||
return data
|
||||
}
|
||||
|
||||
type OAuthAppDeleteData = Awaited<ReturnType<typeof deleteOAuthApp>>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { OAuthScope } from '@supabase/shared-types/out/constants'
|
||||
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
import { get } from 'lib/common/fetch'
|
||||
import { API_URL } from 'lib/constants'
|
||||
|
||||
import { components } from 'api-types'
|
||||
import { get, handleError } from 'data/fetchers'
|
||||
import type { ResponseError } from 'types'
|
||||
import { oauthAppKeys } from './keys'
|
||||
|
||||
@@ -9,26 +9,17 @@ export type OAuthAppsVariables = {
|
||||
slug?: string
|
||||
}
|
||||
|
||||
export type OAuthApp = {
|
||||
id: string
|
||||
icon: string | null
|
||||
client_id: string
|
||||
client_secret_alias: string
|
||||
created_at: string
|
||||
name: string
|
||||
website: string
|
||||
scopes: OAuthScope[]
|
||||
redirect_uris: string[]
|
||||
}
|
||||
export type OAuthApp = components['schemas']['OAuthAppResponse']
|
||||
|
||||
export async function getOAuthApps({ slug }: OAuthAppsVariables, signal?: AbortSignal) {
|
||||
if (!slug) throw new Error('Organization slug is required')
|
||||
|
||||
const response = await get(`${API_URL}/organizations/${slug}/oauth/apps?type=published`, {
|
||||
signal,
|
||||
const { data, error } = await get('/platform/organizations/{slug}/oauth/apps', {
|
||||
params: { path: { slug }, query: { type: 'published' } },
|
||||
})
|
||||
if (response.error) throw response.error
|
||||
return response as OAuthApp[]
|
||||
|
||||
if (error) handleError(error)
|
||||
return data
|
||||
}
|
||||
|
||||
export type OAuthAppsData = Awaited<ReturnType<typeof getOAuthApps>>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
import { post } from 'lib/common/fetch'
|
||||
import { API_URL } from 'lib/constants'
|
||||
import { handleError, post } from 'data/fetchers'
|
||||
import { ResponseError } from 'types'
|
||||
import { projectKeys } from './keys'
|
||||
|
||||
export type ProjectTransferVariables = {
|
||||
@@ -10,10 +10,6 @@ export type ProjectTransferVariables = {
|
||||
targetOrganizationSlug?: string
|
||||
}
|
||||
|
||||
type ProjectTransferError = {
|
||||
message: string
|
||||
}
|
||||
|
||||
export async function transferProject({
|
||||
projectRef,
|
||||
targetOrganizationSlug,
|
||||
@@ -25,10 +21,12 @@ export async function transferProject({
|
||||
target_organization_slug: targetOrganizationSlug,
|
||||
}
|
||||
|
||||
const response = await post(`${API_URL}/projects/${projectRef}/transfer`, payload)
|
||||
if (response.error) throw response.error
|
||||
|
||||
return response
|
||||
const { data, error } = await post('/platform/projects/{ref}/transfer', {
|
||||
params: { path: { ref: projectRef } },
|
||||
body: payload,
|
||||
})
|
||||
if (error) handleError(error)
|
||||
return data
|
||||
}
|
||||
|
||||
type ProjectTransferData = Awaited<ReturnType<typeof transferProject>>
|
||||
@@ -38,12 +36,12 @@ export const useProjectTransferMutation = ({
|
||||
onError,
|
||||
...options
|
||||
}: Omit<
|
||||
UseMutationOptions<ProjectTransferData, ProjectTransferError, ProjectTransferVariables>,
|
||||
UseMutationOptions<ProjectTransferData, ResponseError, ProjectTransferVariables>,
|
||||
'mutationFn'
|
||||
> = {}) => {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation<ProjectTransferData, ProjectTransferError, ProjectTransferVariables>(
|
||||
return useMutation<ProjectTransferData, ResponseError, ProjectTransferVariables>(
|
||||
(vars) => transferProject(vars),
|
||||
{
|
||||
async onSuccess(data, variables, context) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
import { post } from 'lib/common/fetch'
|
||||
import { API_URL } from 'lib/constants'
|
||||
|
||||
import { handleError, post } from 'data/fetchers'
|
||||
import { projectKeys } from './keys'
|
||||
|
||||
export type ProjectTransferPreviewVariables = {
|
||||
@@ -10,40 +10,6 @@ export type ProjectTransferPreviewVariables = {
|
||||
|
||||
export type PlanId = 'free' | 'pro' | 'team' | 'enterprise'
|
||||
|
||||
type MemberExceedingFreeProjectLimit = {
|
||||
name: string
|
||||
limit: number
|
||||
}
|
||||
|
||||
type PreviewTransferInfo = {
|
||||
key: string
|
||||
message: string
|
||||
}
|
||||
|
||||
export type PreviewProjectTransferResponse = {
|
||||
valid: boolean
|
||||
|
||||
warnings: PreviewTransferInfo[]
|
||||
errors: PreviewTransferInfo[]
|
||||
|
||||
members_exceeding_free_project_limit: MemberExceedingFreeProjectLimit[]
|
||||
|
||||
has_permissions_on_source_organization: boolean
|
||||
has_access_to_target_organization: boolean
|
||||
|
||||
source_project_eligible: boolean
|
||||
|
||||
target_organization_eligible: boolean | null
|
||||
target_organization_has_free_project_slots: boolean | null
|
||||
|
||||
credits_on_source_organization: number
|
||||
costs_on_target_organization: number
|
||||
charge_on_target_organization: number
|
||||
|
||||
source_subscription_plan: PlanId
|
||||
target_subscription_plan: PlanId | null
|
||||
}
|
||||
|
||||
export async function previewProjectTransfer(
|
||||
{ projectRef, targetOrganizationSlug }: ProjectTransferPreviewVariables,
|
||||
signal?: AbortSignal
|
||||
@@ -51,16 +17,14 @@ export async function previewProjectTransfer(
|
||||
if (!projectRef) throw new Error('projectRef is required')
|
||||
if (!targetOrganizationSlug) throw new Error('targetOrganizationSlug is required')
|
||||
|
||||
const response = await post(
|
||||
`${API_URL}/projects/${projectRef}/transfer/preview`,
|
||||
{
|
||||
target_organization_slug: targetOrganizationSlug,
|
||||
},
|
||||
{ signal }
|
||||
)
|
||||
if (response.error) throw response.error
|
||||
const { data, error } = await post('/platform/projects/{ref}/transfer/preview', {
|
||||
params: { path: { ref: projectRef } },
|
||||
body: { target_organization_slug: targetOrganizationSlug },
|
||||
signal,
|
||||
})
|
||||
|
||||
return response as PreviewProjectTransferResponse
|
||||
if (error) handleError(error)
|
||||
return data
|
||||
}
|
||||
|
||||
export type ProjectTransferPreviewData = Awaited<ReturnType<typeof previewProjectTransfer>>
|
||||
|
||||
Reference in new issue
Block a user