The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Second round of wrapping RQ errors with handleError (#26428)
Joshen Limbb6349f34f89
diff --git a/apps/studio/components/to-be-cleaned/Storage/StorageSettings/CreateCredentialModal.tsx b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/CreateCredentialModal.tsxnew file mode 100644index 00000000000..2a3da7be680--- /dev/null+++ b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/CreateCredentialModal.tsx@@ -0,0 +1,175 @@+import { zodResolver } from '@hookform/resolvers/zod'+import { useState } from 'react'+import { useForm } from 'react-hook-form'+import { z } from 'zod'++import { FormField } from '@ui/components/shadcn/ui/form'+import { useParams } from 'common'+import { useIsProjectActive } from 'components/layouts/ProjectLayout/ProjectContext'+import { useS3AccessKeyCreateMutation } from 'data/storage/s3-access-key-create-mutation'+import {+ Button,+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogSection,+ DialogSectionSeparator,+ DialogTitle,+ DialogTrigger,+ Form_Shadcn_,+ TooltipContent_Shadcn_,+ TooltipTrigger_Shadcn_,+ Tooltip_Shadcn_,+} from 'ui'+import { Input } from 'ui-patterns/DataInputs/Input'+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'++interface CreateCredentialModalProps {+ visible: boolean+ onOpenChange: (value: boolean) => void+}++export const CreateCredentialModal = ({ visible, onOpenChange }: CreateCredentialModalProps) => {+ const { ref: projectRef } = useParams()+ const isProjectActive = useIsProjectActive()+ const [showSuccess, setShowSuccess] = useState(false)++ const FormSchema = z.object({+ description: z.string().min(3, {+ message: 'Description must be at least 3 characters long',+ }),+ })+ const form = useForm<z.infer<typeof FormSchema>>({+ resolver: zodResolver(FormSchema),+ defaultValues: {+ description: '',+ },+ })++ const {+ data: createS3KeyData,+ mutate: createS3AccessKey,+ isLoading: isCreating,+ } = useS3AccessKeyCreateMutation({+ onSuccess: () => {+ setShowSuccess(true)+ form.reset()+ },+ })++ async function onSubmit(data: z.infer<typeof FormSchema>) {+ createS3AccessKey({ projectRef, ...data })+ }++ return (+ <Dialog+ open={visible}+ onOpenChange={(open) => {+ onOpenChange(open)+ if (!open) setShowSuccess(false)+ }}+ >+ <Tooltip_Shadcn_>+ <TooltipTrigger_Shadcn_ asChild>+ <DialogTrigger asChild>+ <Button type="default" disabled={!isProjectActive}>+ New access key+ </Button>+ </DialogTrigger>+ </TooltipTrigger_Shadcn_>+ {!isProjectActive && (+ <TooltipContent_Shadcn_>+ Restore your project to create new access keys+ </TooltipContent_Shadcn_>+ )}+ </Tooltip_Shadcn_>++ <DialogContent+ onInteractOutside={(e) => {+ if (showSuccess) e.preventDefault()+ }}+ >+ {showSuccess ? (+ <>+ <DialogHeader>+ <DialogTitle>Save your new S3 access keys</DialogTitle>+ <DialogDescription>+ You won't be able to see them again. If you lose these access keys, you'll need to+ create a new ones.+ </DialogDescription>+ </DialogHeader>+ <DialogSectionSeparator />+ <DialogSection className="flex flex-col gap-4">+ <FormItemLayout label="Access key ID" isReactForm={false}>+ <Input+ className="input-mono"+ readOnly+ copy+ disabled+ value={createS3KeyData?.access_key}+ />+ </FormItemLayout>+ <FormItemLayout label={'Secret access key'} isReactForm={false}>+ <Input+ className="input-mono"+ readOnly+ copy+ disabled+ value={createS3KeyData?.secret_key}+ />+ </FormItemLayout>+ </DialogSection>+ <DialogFooter>+ <Button+ onClick={() => {+ onOpenChange(false)+ setShowSuccess(false)+ }}+ >+ Done+ </Button>+ </DialogFooter>+ </>+ ) : (+ <>+ <DialogHeader>+ <DialogTitle>Create new S3 access keys</DialogTitle>+ <DialogDescription>+ S3 access keys provide full access to all S3 operations across all buckets and+ bypass any existing RLS policies.+ </DialogDescription>+ </DialogHeader>+ <DialogSectionSeparator />+ <Form_Shadcn_ {...form}>+ <form onSubmit={form.handleSubmit(onSubmit)}>+ <DialogSection>+ <FormField+ name="description"+ render={({ field }) => (+ <FormItemLayout label="Description">+ <Input+ autoComplete="off"+ placeholder="My test key"+ type="text"+ {...form.register('description')}+ />+ </FormItemLayout>+ )}+ />+ </DialogSection>++ <DialogFooter>+ <Button className="mt-4" htmlType="submit" loading={isCreating}>+ Create access key+ </Button>+ </DialogFooter>+ </form>+ </Form_Shadcn_>+ </>+ )}+ </DialogContent>+ </Dialog>+ )+}diff --git a/apps/studio/components/to-be-cleaned/Storage/StorageSettings/RevokeCredentialModal.tsx b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/RevokeCredentialModal.tsxnew file mode 100644index 00000000000..c5ff7113090--- /dev/null+++ b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/RevokeCredentialModal.tsx@@ -0,0 +1,68 @@+import toast from 'react-hot-toast'++import { useParams } from 'common'+import { useS3AccessKeyDeleteMutation } from 'data/storage/s3-access-key-delete-mutation'+import {+ Button,+ Dialog,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogSection,+ DialogSectionSeparator,+ DialogTitle,+} from 'ui'++interface RevokeCredentialModalProps {+ visible: boolean+ selectedCredential?: { id: string; description: string }+ onClose: () => void+}++export const RevokeCredentialModal = ({+ visible,+ selectedCredential,+ onClose,+}: RevokeCredentialModalProps) => {+ const { ref: projectRef } = useParams()+ const { mutate: deleteS3AccessKey, isLoading: isDeleting } = useS3AccessKeyDeleteMutation({+ onSuccess: () => {+ toast.success('Successfully revoked S3 access key')+ onClose()+ },+ })++ return (+ <Dialog open={visible}>+ <DialogContent size="small">+ <DialogHeader>+ <DialogTitle>+ Revoke credential <code className="text-sm">{selectedCredential?.description}</code>+ </DialogTitle>+ </DialogHeader>+ <DialogSectionSeparator />+ <DialogSection>+ <DialogDescription>+ This action is irreversible and requests made with these access keys will stop working.+ </DialogDescription>+ </DialogSection>+ <DialogFooter className="flex justify-end gap-x-1">+ <Button type="outline" onClick={() => onClose()}>+ Cancel+ </Button>+ <Button+ type="danger"+ loading={isDeleting}+ onClick={async () => {+ if (!selectedCredential) return+ deleteS3AccessKey({ id: selectedCredential.id, projectRef })+ }}+ >+ Yes, revoke access keys+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog>+ )+}diff --git a/apps/studio/components/to-be-cleaned/Storage/StorageSettings/S3Connection.tsx b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/S3Connection.tsxindex a2a20dab4f5..4bbdd85b473 100644--- a/apps/studio/components/to-be-cleaned/Storage/StorageSettings/S3Connection.tsx+++ b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/S3Connection.tsx@@ -1,111 +1,43 @@-import { differenceInDays } from 'date-fns'-import React from 'react'-import toast from 'react-hot-toast'-import { useForm } from 'react-hook-form'-import { z } from 'zod'-import { zodResolver } from '@hookform/resolvers/zod'import { AlertTitle } from '@ui/components/shadcn/ui/alert'+import Link from 'next/link'+import { useState } from 'react'+import { useParams } from 'common'import {useIsProjectActive,useProjectContext,} from 'components/layouts/ProjectLayout/ProjectContext'import Table from 'components/to-be-cleaned/Table'-import CopyButton from 'components/ui/CopyButton'import { FormHeader } from 'components/ui/Forms'import Panel from 'components/ui/Panel'import { useProjectApiQuery } from 'data/config/project-api-query'-import { useS3AccessKeyCreateMutation } from 'data/storage/s3-access-key-create-mutation'-import { useS3AccessKeyDeleteMutation } from 'data/storage/s3-access-key-delete-mutation'import { useStorageCredentialsQuery } from 'data/storage/s3-access-key-query'-import { AlertCircle, MoreVertical, TrashIcon } from 'lucide-react'-import Link from 'next/link'-import {- AlertDescription_Shadcn_,- Alert_Shadcn_,- Button,- Dialog,- DialogContent,- DialogDescription,- DialogFooter,- DialogHeader,- DialogSection,- DialogSectionSeparator,- DialogTitle,- DialogTrigger,- DropdownMenu,- DropdownMenuContent,- DropdownMenuItem,- DropdownMenuTrigger,- Form_Shadcn_,- TooltipContent_Shadcn_,- TooltipTrigger_Shadcn_,- Tooltip_Shadcn_,- cn,-} from 'ui'+import { AlertDescription_Shadcn_, Alert_Shadcn_, Button, cn } from 'ui'import { GenericSkeletonLoader } from 'ui-patterns'import { Input } from 'ui-patterns/DataInputs/Input'+import { WarningIcon } from 'ui-patterns/Icons/StatusIcons'import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'-import { FormField } from '@ui/components/shadcn/ui/form'+import { CreateCredentialModal } from './CreateCredentialModal'+import { RevokeCredentialModal } from './RevokeCredentialModal'+import { StorageCredItem } from './StorageCredItem'+import { getConnectionURL } from './StorageSettings.utils'export const S3Connection = () => {- const [openCreateCred, setOpenCreateCred] = React.useState(false)- const [showSuccess, setShowSuccess] = React.useState(false)- const [openDeleteDialog, setOpenDeleteDialog] = React.useState(false)- const [deleteCred, setDeleteCred] = React.useState<{ id: string; description: string } | null>(- null- )-const { ref: projectRef } = useParams()+ const isProjectActive = useIsProjectActive()const { project, isLoading: projectIsLoading } = useProjectContext()- const isProjectActive = useIsProjectActive()+ const [openCreateCred, setOpenCreateCred] = useState(false)+ const [openDeleteDialog, setOpenDeleteDialog] = useState(false)+ const [deleteCred, setDeleteCred] = useState<{ id: string; description: string }>()+ const { data: projectAPI } = useProjectApiQuery({ projectRef: projectRef })const { data: storageCreds, ...storageCredsQuery } = useStorageCredentialsQuery({projectRef,})const hasStorageCreds = storageCreds?.data && storageCreds.data.length > 0-- const createS3AccessKey = useS3AccessKeyCreateMutation({- projectRef,- })-- const deleteS3AccessKey = useS3AccessKeyDeleteMutation({- projectRef,- })-- const { data: projectAPI } = useProjectApiQuery({ projectRef: projectRef })-- function getConnectionURL() {- const projUrl = projectAPI- ? `${projectAPI.autoApiService.protocol}://${projectAPI.autoApiService.endpoint}`- : `https://${projectRef}.supabase.co`-- const url = new URL(projUrl)- url.pathname = '/storage/v1/s3'- return url.toString()- }-- const s3connectionUrl = getConnectionURL()-- const FormSchema = z.object({- description: z.string().min(3, {- message: 'Description must be at least 3 characters long',- }),- })-- const form = useForm<z.infer<typeof FormSchema>>({- resolver: zodResolver(FormSchema),- defaultValues: {- description: '',- },- })-- async function onSubmit(data: z.infer<typeof FormSchema>) {- await createS3AccessKey.mutateAsync(data)- setShowSuccess(true)- }+ const s3connectionUrl = getConnectionURL(projectRef ?? '', projectAPI)return (<>@@ -115,7 +47,9 @@ export const S3Connection = () => {description="Connect to your bucket via the S3 protocol."docsUrl="https://supabase.com/docs/guides/storage/s3/authentication"/>- {isProjectActive ? (+ {projectIsLoading ? (+ <GenericSkeletonLoader />+ ) : isProjectActive ? (<Panel className="grid gap-4 p-4 !mb-0"><FormItemLayout layout="horizontal" label="Endpoint" isReactForm={false}><Input readOnly copy disabled value={s3connectionUrl} />@@ -128,7 +62,7 @@ export const S3Connection = () => {</Panel>) : (<Alert_Shadcn_ variant="warning">- <AlertCircle />+ <WarningIcon /><AlertTitle>Project is paused</AlertTitle><AlertDescription_Shadcn_>To connect to your S3 bucket, you need to restore your project.@@ -147,295 +81,81 @@ export const S3Connection = () => {title="S3 Access Keys"description="Manage your access keys for this project."actions={- <Dialog- open={openCreateCred}- onOpenChange={(open) => {- setOpenCreateCred(open)- if (!open) setShowSuccess(false)- }}- >- <Tooltip_Shadcn_>- <TooltipTrigger_Shadcn_ asChild>- <DialogTrigger asChild>- <Button type="default" disabled={!isProjectActive}>- New access key- </Button>- </DialogTrigger>- </TooltipTrigger_Shadcn_>- {!isProjectActive && (- <TooltipContent_Shadcn_>- Restore your project to create new access keys- </TooltipContent_Shadcn_>- )}- </Tooltip_Shadcn_>-- <DialogContent- onInteractOutside={(e) => {- if (showSuccess) {- e.preventDefault()- }- }}- >- {showSuccess ? (- <>- <DialogHeader>- <DialogTitle>Save your new S3 access keys</DialogTitle>- <DialogDescription>- You won't be able to see them again. If you lose these access keys, you'll- need to create a new ones.- </DialogDescription>- </DialogHeader>- <DialogSectionSeparator />- <DialogSection className="flex flex-col gap-4">- <FormItemLayout label="Access key ID" isReactForm={false}>- <Input- className="input-mono"- readOnly- copy- disabled- value={createS3AccessKey.data?.data?.access_key}- />- </FormItemLayout>- <FormItemLayout label={'Secret access key'} isReactForm={false}>- <Input- className="input-mono"- readOnly- copy- disabled- value={createS3AccessKey.data?.data?.secret_key}- />- </FormItemLayout>- </DialogSection>- <DialogFooter>- <Button- onClick={() => {- setOpenCreateCred(false)- setShowSuccess(false)- }}- >- Done- </Button>- </DialogFooter>- </>- ) : (- <>- <DialogHeader>- <DialogTitle>Create new S3 access keys</DialogTitle>- <DialogDescription>- S3 access keys provide full access to all S3 operations across all buckets- and bypass any existing RLS policies.- </DialogDescription>- </DialogHeader>- <DialogSectionSeparator />- <Form_Shadcn_ {...form}>- <form onSubmit={form.handleSubmit(onSubmit)}>- <DialogSection>- <FormField- name="description"- render={({ field }) => (- <FormItemLayout label="Description">- <Input- autoComplete="off"- placeholder="My test key"- type="text"- {...form.register('description')}- />- </FormItemLayout>- )}- />- </DialogSection>-- <DialogFooter>- <Button- className="mt-4"- htmlType="submit"- loading={createS3AccessKey.isLoading}- >- Create access key- </Button>- </DialogFooter>- </form>- </Form_Shadcn_>- </>- )}- </DialogContent>- </Dialog>+ <CreateCredentialModal visible={openCreateCred} onOpenChange={setOpenCreateCred} />}/>- <div- className={cn([- 'bg-surface-100',- 'overflow-hidden border-muted',- 'rounded-md border shadow',- ])}- >- {!isProjectActive ? (- <Alert_Shadcn_ variant="warning">- <AlertCircle />- <AlertTitle>Can't fetch S3 access keys</AlertTitle>- <AlertDescription_Shadcn_>- To fetch your S3 access keys, you need to restore your project.- </AlertDescription_Shadcn_>- <div className="mt-3 flex items-center space-x-2">- <Button asChild type="default">- <Link href={`/project/${projectRef}`}>Restore project</Link>- </Button>+ {projectIsLoading ? (+ <GenericSkeletonLoader />+ ) : !isProjectActive ? (+ <Alert_Shadcn_ variant="warning">+ <WarningIcon />+ <AlertTitle>Can't fetch S3 access keys</AlertTitle>+ <AlertDescription_Shadcn_>+ To fetch your S3 access keys, you need to restore your project.+ </AlertDescription_Shadcn_>+ <AlertDescription_Shadcn_>+ <Button asChild type="default" className="mt-3">+ <Link href={`/project/${projectRef}`}>Restore project</Link>+ </Button>+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ ) : (+ <>+ {storageCredsQuery.isLoading ? (+ <div className="p-4">+ <GenericSkeletonLoader />+ </div>+ ) : (+ <div className="overflow-x-auto">+ <Table+ head={[+ <Table.th key="">Description</Table.th>,+ <Table.th key="">Access key ID</Table.th>,+ <Table.th key="">Created at</Table.th>,+ <Table.th key="actions" />,+ ]}+ body={+ hasStorageCreds ? (+ storageCreds.data?.map((cred) => (+ <StorageCredItem+ key={cred.id}+ created_at={cred.created_at}+ access_key={cred.access_key}+ description={cred.description}+ id={cred.id}+ onDeleteClick={() => {+ setDeleteCred(cred)+ setOpenDeleteDialog(true)+ }}+ />+ ))+ ) : (+ <Table.tr>+ <Table.td colSpan={4} className="!rounded-b-md overflow-hidden">+ <p className="text-sm text-foreground">No access keys created</p>+ <p className="text-sm text-foreground-light">+ There are no access keys associated with your project yet+ </p>+ </Table.td>+ </Table.tr>+ )+ }+ /></div>- </Alert_Shadcn_>- ) : (- <>- {storageCredsQuery.isLoading ? (- <div className="p-4">- <GenericSkeletonLoader />- </div>- ) : (- <div className="overflow-x-auto">- <Table- head={[- <Table.th key="">Description</Table.th>,- <Table.th key="">Access key ID</Table.th>,- <Table.th key="">Created at</Table.th>,- <Table.th key="actions" />,- ]}- body={- hasStorageCreds ? (- storageCreds.data?.map((cred) => (- <StorageCredItem- key={cred.id}- created_at={cred.created_at}- access_key={cred.access_key}- description={cred.description}- id={cred.id}- onDeleteClick={() => {- setDeleteCred(cred)- setOpenDeleteDialog(true)- }}- />- ))- ) : (- <Table.tr>- <Table.td colSpan={4}>- <p className="text-sm text-foreground">No access keys created</p>- <p className="text-sm text-foreground-light">- There are no access keys associated with your project yet- </p>- </Table.td>- </Table.tr>- )- }- />- </div>- )}- </>- )}- </div>+ )}+ </>+ )}</div>- <Dialog open={openDeleteDialog} onOpenChange={setOpenDeleteDialog}>- <DialogContent>- <DialogHeader>- <DialogTitle>- Revoke <code>{deleteCred?.description}</code> credential- </DialogTitle>- <DialogDescription>- This action is irreversible and requests made with these access keys will stop- working.- </DialogDescription>- </DialogHeader>- <DialogFooter className="flex justify-end gap-1">- <Button- type="outline"- onClick={() => {- setOpenDeleteDialog(false)- setDeleteCred(null)- }}- >- Cancel- </Button>- <Button- type="danger"- loading={deleteS3AccessKey.isLoading}- onClick={async () => {- if (!deleteCred) return- await deleteS3AccessKey.mutateAsync({ id: deleteCred.id })- setOpenDeleteDialog(false)- toast.success('S3 access keys revoked')- }}- >- Yes, revoke access keys- </Button>- </DialogFooter>- </DialogContent>- </Dialog>+ <RevokeCredentialModal+ visible={openDeleteDialog}+ selectedCredential={deleteCred}+ onClose={() => {+ setOpenDeleteDialog(false)+ setDeleteCred(undefined)+ }}+ /></>)}--function StorageCredItem({- description,- id,- created_at,- access_key,- onDeleteClick,-}: {- description: string- id: string- created_at: string- access_key: string- onDeleteClick: (id: string) => void-}) {- function daysSince(date: string) {- const now = new Date()- const created = new Date(date)- const diffInDays = differenceInDays(now, created)-- if (diffInDays === 0) {- return 'Today'- } else if (diffInDays === 1) {- return `${diffInDays} day ago`- } else {- return `${diffInDays} days ago`- }- }-- return (- <tr className="h-8 text-ellipsis group">- <td>- <span className="text-foreground">{description}</span>- </td>- <td>- <div className="flex items-center justify-between">- <span className="text-ellipsis font-mono cursor-default">{access_key}</span>- <span className="w-24 text-right opacity-0 group-hover:opacity-100 transition-opacity">- <CopyButton text={access_key} type="default" />- </span>- </div>- </td>- <td>{daysSince(created_at)}</td>- <td className="text-right">- <DropdownMenu>- <DropdownMenuTrigger asChild>- <Button- icon={<MoreVertical size={14} strokeWidth={1} />}- type="text"- className="px-1.5 text-foreground-lighter hover:text-foreground"- ></Button>- </DropdownMenuTrigger>- <DropdownMenuContent className="max-w-40" align="end">- <DropdownMenuItem- className="flex gap-1.5 "- onClick={(e) => {- e.preventDefault()- onDeleteClick(id)- }}- >- <TrashIcon size="14" />- Revoke key- </DropdownMenuItem>- </DropdownMenuContent>- </DropdownMenu>- </td>- </tr>- )-}diff --git a/apps/studio/components/to-be-cleaned/Storage/StorageSettings/StorageCredItem.tsx b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/StorageCredItem.tsxnew file mode 100644index 00000000000..e56366eb80f--- /dev/null+++ b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/StorageCredItem.tsx@@ -0,0 +1,79 @@+import { differenceInDays } from 'date-fns'+import { MoreVertical, TrashIcon } from 'lucide-react'++import CopyButton from 'components/ui/CopyButton'+import {+ Button,+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuTrigger,+} from 'ui'++export const StorageCredItem = ({+ description,+ id,+ created_at,+ access_key,+ onDeleteClick,+}: {+ description: string+ id: string+ created_at: string+ access_key: string+ onDeleteClick: (id: string) => void+}) => {+ function daysSince(date: string) {+ const now = new Date()+ const created = new Date(date)+ const diffInDays = differenceInDays(now, created)++ if (diffInDays === 0) {+ return 'Today'+ } else if (diffInDays === 1) {+ return `${diffInDays} day ago`+ } else {+ return `${diffInDays} days ago`+ }+ }++ return (+ <tr className="h-8 text-ellipsis group">+ <td>+ <span className="text-foreground">{description}</span>+ </td>+ <td>+ <div className="flex items-center justify-between">+ <span className="text-ellipsis font-mono cursor-default">{access_key}</span>+ <span className="w-24 text-right opacity-0 group-hover:opacity-100 transition-opacity">+ <CopyButton text={access_key} type="default" />+ </span>+ </div>+ </td>+ <td>{daysSince(created_at)}</td>+ <td className="text-right">+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button+ icon={<MoreVertical size={14} strokeWidth={1} />}+ type="text"+ className="px-1.5 text-foreground-lighter hover:text-foreground"+ ></Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent className="max-w-40" align="end">+ <DropdownMenuItem+ className="flex gap-1.5 "+ onClick={(e) => {+ e.preventDefault()+ onDeleteClick(id)+ }}+ >+ <TrashIcon size="14" />+ Revoke key+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ </td>+ </tr>+ )+}diff --git a/apps/studio/components/to-be-cleaned/Storage/StorageSettings/StorageSettings.utils.ts b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/StorageSettings.utils.tsindex a3d9da5d43a..44cf98726af 100644--- a/apps/studio/components/to-be-cleaned/Storage/StorageSettings/StorageSettings.utils.ts+++ b/apps/studio/components/to-be-cleaned/Storage/StorageSettings/StorageSettings.utils.ts@@ -1,3 +1,4 @@+import { ProjectApiResponse } from 'data/config/project-api-query'import { StorageSizeUnits } from './StorageSettings.constants'const k = 1024@@ -24,3 +25,15 @@ export const convertToBytes = (size: number, unit: StorageSizeUnits = StorageSizreturn size * Math.pow(k, i)}++export function getConnectionURL(projectRef: string, projectAPI?: ProjectApiResponse) {+ if (projectAPI === undefined) return ''++ const projUrl = projectAPI+ ? `${projectAPI.autoApiService.protocol}://${projectAPI.autoApiService.endpoint}`+ : `https://${projectRef}.supabase.co`++ const url = new URL(projUrl)+ url.pathname = '/storage/v1/s3'+ return url.toString()+}diff --git a/apps/studio/data/permissions/permissions-query.ts b/apps/studio/data/permissions/permissions-query.tsindex e247de4f916..1a3e2ff563c 100644--- a/apps/studio/data/permissions/permissions-query.ts+++ b/apps/studio/data/permissions/permissions-query.ts@@ -1,19 +1,16 @@import { useQuery, UseQueryOptions } from '@tanstack/react-query'-import { get } from 'lib/common/fetch'-import { API_URL, IS_PLATFORM } from 'lib/constants'+import { get, handleError } from 'data/fetchers'+import { IS_PLATFORM } from 'lib/constants'import type { Permission, ResponseError } from 'types'import { permissionKeys } from './keys'export type PermissionsResponse = Permission[]export async function getPermissions(signal?: AbortSignal) {- const response = await get(`${API_URL}/profile/permissions`, {- signal,- })- if (response.error) throw response.error-- return response as PermissionsResponse+ const { data, error } = await get('/platform/profile/permissions', { signal })+ if (error) handleError(error)+ return data as PermissionsResponse}export type PermissionsData = Awaited<ReturnType<typeof getPermissions>>diff --git a/apps/studio/data/platform/platform-status-query.ts b/apps/studio/data/platform/platform-status-query.tsindex 0f22169ec1d..6578e2cda9f 100644--- a/apps/studio/data/platform/platform-status-query.ts+++ b/apps/studio/data/platform/platform-status-query.ts@@ -1,6 +1,6 @@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 { platformKeys } from './keys'export type PlatformStatusResponse = {@@ -8,14 +8,9 @@ export type PlatformStatusResponse = {}export async function getPlatformStatus(signal?: AbortSignal) {- const response = await get(`${API_URL}/status`, {- signal,- })- if (response.error) {- throw response.error- }-- return { isHealthy: response.is_healthy } as PlatformStatusResponse+ const { data, error } = await get('/platform/status', { signal })+ if (error) handleError(error)+ return { isHealthy: (data as any).is_healthy } as PlatformStatusResponse}export type PlatformStatusData = Awaited<ReturnType<typeof getPlatformStatus>>diff --git a/apps/studio/data/privileges/column-privileges-grant-mutation.ts b/apps/studio/data/privileges/column-privileges-grant-mutation.tsindex 54c551ea636..3bfdc4c953f 100644--- a/apps/studio/data/privileges/column-privileges-grant-mutation.ts+++ b/apps/studio/data/privileges/column-privileges-grant-mutation.ts@@ -2,7 +2,7 @@ import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/reactimport toast from 'react-hot-toast'import type { components } from 'data/api'-import { post } from 'data/fetchers'+import { handleError, post } from 'data/fetchers'import type { ResponseError } from 'types'import { privilegeKeys } from './keys'@@ -20,27 +20,19 @@ export async function grantColumnPrivileges({grants,}: ColumnPrivilegesGrantVariables) {const headers = new Headers()- if (connectionString) {- headers.set('x-connection-encrypted', connectionString)- }+ if (connectionString) headers.set('x-connection-encrypted', connectionString)const { data, error } = await post('/platform/pg-meta/{ref}/column-privileges', {params: {- path: {- ref: projectRef,- },+ path: { ref: projectRef },// this is needed to satisfy the typescript, but it doesn't pass the actual header- header: {- 'x-connection-encrypted': connectionString!,- },+ header: { 'x-connection-encrypted': connectionString! },},body: grants,headers,})- if (error) {- throw error- }+ if (error) handleError(error)return data}diff --git a/apps/studio/data/privileges/column-privileges-query.ts b/apps/studio/data/privileges/column-privileges-query.tsindex 06b4242489d..83bf2e9f9d4 100644--- a/apps/studio/data/privileges/column-privileges-query.ts+++ b/apps/studio/data/privileges/column-privileges-query.ts@@ -1,9 +1,9 @@import { UseQueryOptions, useQuery } from '@tanstack/react-query'-import { get } from 'data/fetchers'+import type { components } from 'data/api'+import { get, handleError } from 'data/fetchers'import type { ResponseError } from 'types'import { privilegeKeys } from './keys'-import type { components } from 'data/api'export type ColumnPrivilegesVariables = {projectRef?: string@@ -19,25 +19,19 @@ export async function getColumnPrivileges(if (!projectRef) throw new Error('projectRef is required')const headers = new Headers()- if (connectionString) {- headers.set('x-connection-encrypted', connectionString)- }+ if (connectionString) headers.set('x-connection-encrypted', connectionString)const { data, error } = await get('/platform/pg-meta/{ref}/column-privileges', {params: {- path: {- ref: projectRef,- },+ path: { ref: projectRef },// this is needed to satisfy the typescript, but it doesn't pass the actual header- header: {- 'x-connection-encrypted': connectionString!,- },+ header: { 'x-connection-encrypted': connectionString! },},signal,headers,})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/privileges/column-privileges-revoke-mutation.ts b/apps/studio/data/privileges/column-privileges-revoke-mutation.tsindex 5a2bd2d0e51..142410bf9d3 100644--- a/apps/studio/data/privileges/column-privileges-revoke-mutation.ts+++ b/apps/studio/data/privileges/column-privileges-revoke-mutation.ts@@ -2,7 +2,7 @@ import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/reactimport toast from 'react-hot-toast'import type { components } from 'data/api'-import { del } from 'data/fetchers'+import { del, handleError } from 'data/fetchers'import type { ResponseError } from 'types'import { privilegeKeys } from './keys'@@ -20,27 +20,19 @@ export async function revokeColumnPrivileges({revokes,}: ColumnPrivilegesRevokeVariables) {const headers = new Headers()- if (connectionString) {- headers.set('x-connection-encrypted', connectionString)- }+ if (connectionString) headers.set('x-connection-encrypted', connectionString)const { data, error } = await del('/platform/pg-meta/{ref}/column-privileges', {params: {- path: {- ref: projectRef,- },+ path: { ref: projectRef },// this is needed to satisfy the typescript, but it doesn't pass the actual header- header: {- 'x-connection-encrypted': connectionString!,- },+ header: { 'x-connection-encrypted': connectionString! },},body: revokes,headers,})- if (error) {- throw error- }+ if (error) handleError(error)return data}diff --git a/apps/studio/data/privileges/table-privileges-grant-mutation.ts b/apps/studio/data/privileges/table-privileges-grant-mutation.tsindex a609b0f6ffb..33781bd794a 100644--- a/apps/studio/data/privileges/table-privileges-grant-mutation.ts+++ b/apps/studio/data/privileges/table-privileges-grant-mutation.ts@@ -2,7 +2,7 @@ import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/reactimport toast from 'react-hot-toast'import type { components } from 'data/api'-import { post } from 'data/fetchers'+import { handleError, post } from 'data/fetchers'import type { ResponseError } from 'types'import { privilegeKeys } from './keys'@@ -20,27 +20,19 @@ export async function grantTablePrivileges({grants,}: TablePrivilegesGrantVariables) {const headers = new Headers()- if (connectionString) {- headers.set('x-connection-encrypted', connectionString)- }+ if (connectionString) headers.set('x-connection-encrypted', connectionString)const { data, error } = await post('/platform/pg-meta/{ref}/table-privileges', {params: {- path: {- ref: projectRef,- },+ path: { ref: projectRef },// this is needed to satisfy the typescript, but it doesn't pass the actual header- header: {- 'x-connection-encrypted': connectionString!,- },+ header: { 'x-connection-encrypted': connectionString! },},body: grants,headers,})- if (error) {- throw error- }+ if (error) handleError(error)return data}diff --git a/apps/studio/data/privileges/table-privileges-query.ts b/apps/studio/data/privileges/table-privileges-query.tsindex 1e025e6d3db..6d3f961a721 100644--- a/apps/studio/data/privileges/table-privileges-query.ts+++ b/apps/studio/data/privileges/table-privileges-query.ts@@ -1,7 +1,7 @@import { UseQueryOptions, useQuery } from '@tanstack/react-query'import type { components } from 'data/api'-import { get } from 'data/fetchers'+import { get, handleError } from 'data/fetchers'import type { ResponseError } from 'types'import { privilegeKeys } from './keys'@@ -19,25 +19,19 @@ export async function getTablePrivileges(if (!projectRef) throw new Error('projectRef is required')const headers = new Headers()- if (connectionString) {- headers.set('x-connection-encrypted', connectionString)- }+ if (connectionString) headers.set('x-connection-encrypted', connectionString)const { data, error } = await get('/platform/pg-meta/{ref}/table-privileges', {params: {- path: {- ref: projectRef,- },+ path: { ref: projectRef },// this is needed to satisfy the typescript, but it doesn't pass the actual header- header: {- 'x-connection-encrypted': connectionString!,- },+ header: { 'x-connection-encrypted': connectionString! },},signal,headers,})- if (error) throw error+ if (error) throw handleError(error)return data}diff --git a/apps/studio/data/privileges/table-privileges-revoke-mutation.ts b/apps/studio/data/privileges/table-privileges-revoke-mutation.tsindex ae352fbb808..546d1cd1eb1 100644--- a/apps/studio/data/privileges/table-privileges-revoke-mutation.ts+++ b/apps/studio/data/privileges/table-privileges-revoke-mutation.ts@@ -2,7 +2,7 @@ import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/reactimport toast from 'react-hot-toast'import type { components } from 'data/api'-import { del } from 'data/fetchers'+import { del, handleError } from 'data/fetchers'import type { ResponseError } from 'types'import { privilegeKeys } from './keys'@@ -20,27 +20,19 @@ export async function revokeTablePrivileges({revokes,}: TablePrivilegesRevokeVariables) {const headers = new Headers()- if (connectionString) {- headers.set('x-connection-encrypted', connectionString)- }+ if (connectionString) headers.set('x-connection-encrypted', connectionString)const { data, error } = await del('/platform/pg-meta/{ref}/table-privileges', {params: {- path: {- ref: projectRef,- },+ path: { ref: projectRef },// this is needed to satisfy the typescript, but it doesn't pass the actual header- header: {- 'x-connection-encrypted': connectionString!,- },+ header: { 'x-connection-encrypted': connectionString! },},body: revokes,headers,})- if (error) {- throw error- }+ if (error) handleError(error)return data}diff --git a/apps/studio/data/profile/profile-audit-logs-query.ts b/apps/studio/data/profile/profile-audit-logs-query.tsindex 5b850b54a73..daf17be0ed8 100644--- a/apps/studio/data/profile/profile-audit-logs-query.ts+++ b/apps/studio/data/profile/profile-audit-logs-query.ts@@ -1,6 +1,6 @@import { useQuery, UseQueryOptions } from '@tanstack/react-query'-import { get } from 'data/fetchers'+import { get, handleError } from 'data/fetchers'import type { AuditLog } from 'data/organizations/organization-audit-logs-query'import type { ResponseError } from 'types'import { profileKeys } from './keys'@@ -24,7 +24,7 @@ export async function getProfileAuditLogs(signal,})- if (error) throw error+ if (error) handleError(error)return data as unknown as ProfileAuditLogsData}diff --git a/apps/studio/data/projects/project-create-mutation.ts b/apps/studio/data/projects/project-create-mutation.tsindex dd46ed8026e..46beeb8921f 100644--- a/apps/studio/data/projects/project-create-mutation.ts+++ b/apps/studio/data/projects/project-create-mutation.ts@@ -2,7 +2,7 @@ import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/reactimport { toast } from 'react-hot-toast'import type { components } from 'data/api'-import { post } from 'data/fetchers'+import { handleError, post } from 'data/fetchers'import { PROVIDERS } from 'lib/constants'import type { ResponseError } from 'types'import { projectKeys } from './keys'@@ -54,7 +54,7 @@ export async function createProject({body,})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/projects/project-delete-mutation.ts b/apps/studio/data/projects/project-delete-mutation.tsindex 6eaeaf1055b..b3dd4a0293e 100644--- a/apps/studio/data/projects/project-delete-mutation.ts+++ b/apps/studio/data/projects/project-delete-mutation.ts@@ -1,8 +1,7 @@import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'import { toast } from 'react-hot-toast'-import { delete_ } from 'lib/common/fetch'-import { API_URL } from 'lib/constants'+import { del, handleError } from 'data/fetchers'import type { ResponseError } from 'types'import { projectKeys } from './keys'@@ -11,9 +10,12 @@ export type ProjectDeleteVariables = {}export async function deleteProject({ projectRef }: ProjectDeleteVariables) {- const response = await delete_(`${API_URL}/projects/${projectRef}`)- if (response.error) throw response.error- return response+ const { data, error } = await del('/platform/projects/{ref}', {+ params: { path: { ref: projectRef } },+ })++ if (error) handleError(error)+ return data}type ProjectDeleteData = Awaited<ReturnType<typeof deleteProject>>diff --git a/apps/studio/data/projects/project-detail-query.ts b/apps/studio/data/projects/project-detail-query.tsindex 971fbbea5cd..66427808b74 100644--- a/apps/studio/data/projects/project-detail-query.ts+++ b/apps/studio/data/projects/project-detail-query.ts@@ -1,9 +1,9 @@import { QueryClient, useQuery, UseQueryOptions } from '@tanstack/react-query'-import { get } from 'data/fetchers'+import type { components } from 'data/api'+import { get, handleError } from 'data/fetchers'import type { ResponseError } from 'types'import { projectKeys } from './keys'-import type { components } from 'data/api'export type ProjectDetailVariables = { ref?: string }@@ -27,7 +27,7 @@ export async function getProjectDetail({ ref }: ProjectDetailVariables, signal?:signal,})- if (error) throw error+ if (error) handleError(error)return data as unknown as Project}diff --git a/apps/studio/data/projects/project-pause-mutation.ts b/apps/studio/data/projects/project-pause-mutation.tsindex c4de3a1f733..8d56dad2b42 100644--- a/apps/studio/data/projects/project-pause-mutation.ts+++ b/apps/studio/data/projects/project-pause-mutation.ts@@ -1,7 +1,7 @@import { useMutation, UseMutationOptions } from '@tanstack/react-query'import { toast } from 'react-hot-toast'-import { post } from 'data/fetchers'+import { handleError, post } from 'data/fetchers'import type { ResponseError } from 'types'export type ProjectPauseVariables = {@@ -12,7 +12,7 @@ export async function pauseProject({ ref }: ProjectPauseVariables) {const { data, error } = await post('/platform/projects/{ref}/pause', {params: { path: { ref } },})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/projects/project-restart-mutation.ts b/apps/studio/data/projects/project-restart-mutation.tsindex c00e4ad09db..edbe551b304 100644--- a/apps/studio/data/projects/project-restart-mutation.ts+++ b/apps/studio/data/projects/project-restart-mutation.ts@@ -1,7 +1,7 @@import { useMutation, UseMutationOptions } from '@tanstack/react-query'import { toast } from 'react-hot-toast'-import { post } from 'data/fetchers'+import { handleError, post } from 'data/fetchers'import type { ResponseError } from 'types'import type { components } from 'api-types'@@ -20,7 +20,7 @@ export async function restartProject({ ref, identifier }: ProjectRestartVariableparams: { path: { ref } },body: payload,})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/projects/project-restart-services-mutation.ts b/apps/studio/data/projects/project-restart-services-mutation.tsindex edbb5f70935..6904742c8c8 100644--- a/apps/studio/data/projects/project-restart-services-mutation.ts+++ b/apps/studio/data/projects/project-restart-services-mutation.ts@@ -1,7 +1,7 @@import { useMutation, UseMutationOptions } from '@tanstack/react-query'import { toast } from 'react-hot-toast'-import { post } from 'data/fetchers'+import { handleError, post } from 'data/fetchers'import type { ResponseError } from 'types'export type ProjectRestartServicesVariables = {@@ -41,7 +41,7 @@ export async function restartProjectServices({},},})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/projects/project-restore-mutation.ts b/apps/studio/data/projects/project-restore-mutation.tsindex f4ef82e3772..df62b811901 100644--- a/apps/studio/data/projects/project-restore-mutation.ts+++ b/apps/studio/data/projects/project-restore-mutation.ts@@ -1,7 +1,7 @@import { useMutation, UseMutationOptions } from '@tanstack/react-query'import { toast } from 'react-hot-toast'-import { post } from 'data/fetchers'+import { handleError, post } from 'data/fetchers'import type { ResponseError } from 'types'export type ProjectRestoreVariables = {@@ -14,7 +14,7 @@ export async function restoreProject({ ref }: ProjectRestoreVariables) {// @ts-ignorebody: {},})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/projects/project-status-query.ts b/apps/studio/data/projects/project-status-query.tsindex 1d2ac92f0cc..30879f88465 100644--- a/apps/studio/data/projects/project-status-query.ts+++ b/apps/studio/data/projects/project-status-query.ts@@ -1,6 +1,6 @@import { useQuery, UseQueryOptions } from '@tanstack/react-query'-import { get } from 'data/fetchers'+import { get, handleError } from 'data/fetchers'import type { ResponseError } from 'types'import { projectKeys } from './keys'@@ -19,7 +19,7 @@ export async function getProjectStatus(signal,})- if (error) throw error+ if (error) handleError(error)return data as { status: string }}diff --git a/apps/studio/data/projects/project-type-generation-query.ts b/apps/studio/data/projects/project-type-generation-query.tsindex 290c88d0316..59f80875f11 100644--- a/apps/studio/data/projects/project-type-generation-query.ts+++ b/apps/studio/data/projects/project-type-generation-query.ts@@ -1,6 +1,6 @@import { useQuery, UseQueryOptions } from '@tanstack/react-query'-import { get } from 'data/fetchers'+import { get, handleError } from 'data/fetchers'import type { ResponseError } from 'types'import { projectKeys } from './keys'@@ -14,7 +14,7 @@ export async function generateTypes({ ref }: GenerateTypesVariables, signal?: Absignal,})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/projects/project-upgrade-mutation.ts b/apps/studio/data/projects/project-upgrade-mutation.tsindex 8d1040c73fc..44c4f678c35 100644--- a/apps/studio/data/projects/project-upgrade-mutation.ts+++ b/apps/studio/data/projects/project-upgrade-mutation.ts@@ -1,7 +1,7 @@import { useMutation, UseMutationOptions } from '@tanstack/react-query'import { toast } from 'react-hot-toast'-import { post } from 'data/fetchers'+import { handleError, post } from 'data/fetchers'import type { ResponseError } from 'types'export type ProjectUpgradeVariables = {@@ -14,7 +14,7 @@ export async function upgradeProject({ ref, target_version }: ProjectUpgradeVariparams: { path: { ref } },body: { target_version },})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/projects/projects-query.ts b/apps/studio/data/projects/projects-query.tsindex 3bb52c015df..cbb2067adb6 100644--- a/apps/studio/data/projects/projects-query.ts+++ b/apps/studio/data/projects/projects-query.ts@@ -2,7 +2,7 @@ import { QueryClient, useQuery, useQueryClient, UseQueryOptions } from '@tanstacimport { useCallback, useRef } from 'react'import type { components } from 'data/api'-import { get } from 'data/fetchers'+import { get, handleError } from 'data/fetchers'import type { ResponseError } from 'types'import { projectKeys } from './keys'import type { Project } from './project-detail-query'@@ -16,7 +16,7 @@ export type ProjectInfo = components['schemas']['ProjectInfo']export async function getProjects(signal?: AbortSignal) {const { data, error } = await get('/platform/projects', { signal })- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/read-replicas/replica-remove-mutation.ts b/apps/studio/data/read-replicas/replica-remove-mutation.tsindex 0bb56ddee17..99b211d39c2 100644--- a/apps/studio/data/read-replicas/replica-remove-mutation.ts+++ b/apps/studio/data/read-replicas/replica-remove-mutation.ts@@ -1,7 +1,7 @@import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'import { toast } from 'react-hot-toast'-import { post } from 'data/fetchers'+import { handleError, post } from 'data/fetchers'import type { ResponseError } from 'types'import { replicaKeys } from './keys'@@ -20,7 +20,7 @@ export async function removeReadReplica({ projectRef, identifier }: ReadReplicaRdatabase_identifier: identifier,},})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/read-replicas/replica-setup-mutation.ts b/apps/studio/data/read-replicas/replica-setup-mutation.tsindex 1047e8414ab..d0a9b142dc0 100644--- a/apps/studio/data/read-replicas/replica-setup-mutation.ts+++ b/apps/studio/data/read-replicas/replica-setup-mutation.ts@@ -1,7 +1,7 @@import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'import { toast } from 'react-hot-toast'-import { post } from 'data/fetchers'+import { handleError, post } from 'data/fetchers'import type { ResponseError } from 'types'import { replicaKeys } from './keys'@@ -36,7 +36,7 @@ export async function setUpReadReplica({ projectRef, region }: ReadReplicaSetUpVread_replica_region: region,},})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/read-replicas/replicas-query.ts b/apps/studio/data/read-replicas/replicas-query.tsindex afc080a889d..33f46cadd19 100644--- a/apps/studio/data/read-replicas/replicas-query.ts+++ b/apps/studio/data/read-replicas/replicas-query.ts@@ -1,11 +1,11 @@import { useQuery, UseQueryOptions } from '@tanstack/react-query'+import { IS_PLATFORM } from 'common'import type { components } from 'data/api'-import { get } from 'data/fetchers'+import { get, handleError } from 'data/fetchers'import { useProjectDetailQuery } from 'data/projects/project-detail-query'import type { ResponseError } from 'types'import { replicaKeys } from './keys'-import { IS_PLATFORM } from 'common'export type ReadReplicasVariables = {projectRef?: string@@ -21,7 +21,7 @@ export async function getReadReplicas({ projectRef }: ReadReplicasVariables, sigsignal,})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/read-replicas/replicas-status-query.ts b/apps/studio/data/read-replicas/replicas-status-query.tsindex 20ab2ea501c..dc1bc55952e 100644--- a/apps/studio/data/read-replicas/replicas-status-query.ts+++ b/apps/studio/data/read-replicas/replicas-status-query.ts@@ -1,5 +1,6 @@import { useQuery, UseQueryOptions } from '@tanstack/react-query'-import { get } from 'data/fetchers'++import { get, handleError } from 'data/fetchers'import { useProjectDetailQuery } from 'data/projects/project-detail-query'import type { ResponseError } from 'types'import { replicaKeys } from './keys'@@ -34,7 +35,7 @@ export async function getReadReplicasStatuses(signal,})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/secrets/secrets-create-mutation.ts b/apps/studio/data/secrets/secrets-create-mutation.tsindex d2d6354de70..8c663154c78 100644--- a/apps/studio/data/secrets/secrets-create-mutation.ts+++ b/apps/studio/data/secrets/secrets-create-mutation.ts@@ -1,7 +1,7 @@import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'import { toast } from 'react-hot-toast'-import { post } from 'data/fetchers'+import { handleError, post } from 'data/fetchers'import type { ResponseError } from 'types'import { secretsKeys } from './keys'@@ -18,7 +18,7 @@ export async function createSecrets({ projectRef, secrets }: SecretsCreateVariabbody: secrets,})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/secrets/secrets-delete-mutation.ts b/apps/studio/data/secrets/secrets-delete-mutation.tsindex c887aae19d0..5029d2aa14f 100644--- a/apps/studio/data/secrets/secrets-delete-mutation.ts+++ b/apps/studio/data/secrets/secrets-delete-mutation.ts@@ -1,7 +1,7 @@import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'import { toast } from 'react-hot-toast'-import { del } from 'data/fetchers'+import { del, handleError } from 'data/fetchers'import type { ResponseError } from 'types'import { secretsKeys } from './keys'@@ -18,7 +18,7 @@ export async function deleteSecrets({ projectRef, secrets }: SecretsDeleteVariabbody: secrets,})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/secrets/secrets-query.ts b/apps/studio/data/secrets/secrets-query.tsindex a06a5fbc96d..0219cda3705 100644--- a/apps/studio/data/secrets/secrets-query.ts+++ b/apps/studio/data/secrets/secrets-query.ts@@ -1,8 +1,9 @@import { useQuery, UseQueryOptions } from '@tanstack/react-query'-import { get } from 'data/fetchers'-import { secretsKeys } from './keys'-import type { ResponseError } from 'types'+import type { components } from 'data/api'+import { get, handleError } from 'data/fetchers'+import type { ResponseError } from 'types'+import { secretsKeys } from './keys'export type SecretsVariables = {projectRef?: string@@ -18,7 +19,7 @@ export async function getSecrets({ projectRef }: SecretsVariables, signal?: Aborsignal,})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/service-status/service-status-query.ts b/apps/studio/data/service-status/service-status-query.tsindex 332d01079db..66064d92d2f 100644--- a/apps/studio/data/service-status/service-status-query.ts+++ b/apps/studio/data/service-status/service-status-query.ts@@ -1,6 +1,6 @@import { useQuery, UseQueryOptions } from '@tanstack/react-query'-import { get } from 'data/fetchers'+import { get, handleError } from 'data/fetchers'import type { ResponseError } from 'types'import { serviceStatusKeys } from './keys'@@ -24,7 +24,7 @@ export async function getProjectServiceStatus(signal,})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/storage/bucket-empty-mutation.ts b/apps/studio/data/storage/bucket-empty-mutation.tsindex ab50fda6feb..dfca2053adb 100644--- a/apps/studio/data/storage/bucket-empty-mutation.ts+++ b/apps/studio/data/storage/bucket-empty-mutation.ts@@ -1,7 +1,7 @@import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'import { toast } from 'react-hot-toast'-import { post } from 'data/fetchers'+import { handleError, post } from 'data/fetchers'import type { ResponseError } from 'types'import { storageKeys } from './keys'@@ -18,7 +18,7 @@ export async function emptyBucket({ projectRef, id }: BucketEmptyVariables) {params: { path: { id, ref: projectRef } },})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/storage/buckets-query.ts b/apps/studio/data/storage/buckets-query.tsindex 613578063d1..2cc53817ead 100644--- a/apps/studio/data/storage/buckets-query.ts+++ b/apps/studio/data/storage/buckets-query.ts@@ -1,5 +1,5 @@import { useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'-import { get } from 'data/fetchers'+import { get, handleError } from 'data/fetchers'import { API_URL } from 'lib/constants'import { useCallback } from 'react'import { storageKeys } from './keys'@@ -26,7 +26,7 @@ export async function getBuckets({ projectRef }: BucketsVariables, signal?: Aborsignal,})- if (error) throw error+ if (error) handleError(error)return data as Bucket[]}diff --git a/apps/studio/data/storage/s3-access-key-create-mutation.ts b/apps/studio/data/storage/s3-access-key-create-mutation.tsindex c97b186d714..9e34ae82b54 100644--- a/apps/studio/data/storage/s3-access-key-create-mutation.ts+++ b/apps/studio/data/storage/s3-access-key-create-mutation.ts@@ -1,47 +1,58 @@-import { useMutation, useQueryClient } from '@tanstack/react-query'+import { UseMutationOptions, useMutation, useQueryClient } from '@tanstack/react-query'+import toast from 'react-hot-toast'++import { handleError, post } from 'data/fetchers'+import { ResponseError } from 'types'import { storageCredentialsKeys } from './s3-access-key-keys'-import { post } from 'data/fetchers'-type CreateS3AccessKeyCredential = {+type CreateS3AccessKeyCredentialVariables = {description: stringprojectRef?: string}+const createS3AccessKeyCredential = async ({description,projectRef,-}: CreateS3AccessKeyCredential) => {- if (!projectRef) {- throw new Error('projectRef is required')- }-- const res = await post('/platform/storage/{ref}/credentials', {- params: {- path: {- ref: projectRef,- },- },- body: {- description,- },+}: CreateS3AccessKeyCredentialVariables) => {+ if (!projectRef) throw new Error('projectRef is required')++ const { data, error } = await post('/platform/storage/{ref}/credentials', {+ params: { path: { ref: projectRef } },+ body: { description },})- return res+ if (error) handleError(error)+ return data}-type S3AccessKeyCreateMutation = {- projectRef?: string-}+type S3AccessKeyDeleteData = Awaited<ReturnType<typeof createS3AccessKeyCredential>>-export function useS3AccessKeyCreateMutation({ projectRef }: S3AccessKeyCreateMutation) {+export function useS3AccessKeyCreateMutation({+ onSuccess,+ onError,+ ...options+}: Omit<+ UseMutationOptions<S3AccessKeyDeleteData, ResponseError, CreateS3AccessKeyCredentialVariables>,+ 'mutationFn'+> = {}) {const queryClient = useQueryClient()- const keys = storageCredentialsKeys.credentials(projectRef)-- return useMutation({- mutationFn: ({ description }: { description: string }) =>- createS3AccessKeyCredential({ description, projectRef }),- onSettled: () => {- queryClient.invalidateQueries(keys)- },- })+ return useMutation<S3AccessKeyDeleteData, ResponseError, CreateS3AccessKeyCredentialVariables>(+ (vars) => createS3AccessKeyCredential(vars),+ {+ async onSuccess(data, variables, context) {+ const { projectRef } = variables+ await queryClient.invalidateQueries(storageCredentialsKeys.credentials(projectRef))+ await onSuccess?.(data, variables, context)+ },+ async onError(data, variables, context) {+ if (onError === undefined) {+ toast.error(`Failed to create S3 access key: ${data.message}`)+ } else {+ onError(data, variables, context)+ }+ },+ ...options,+ }+ )}diff --git a/apps/studio/data/storage/s3-access-key-delete-mutation.ts b/apps/studio/data/storage/s3-access-key-delete-mutation.tsindex 06fef9a3717..ba28d8c6e2b 100644--- a/apps/studio/data/storage/s3-access-key-delete-mutation.ts+++ b/apps/studio/data/storage/s3-access-key-delete-mutation.ts@@ -1,38 +1,61 @@-import { useMutation, useQueryClient } from '@tanstack/react-query'+import { UseMutationOptions, useMutation, useQueryClient } from '@tanstack/react-query'+import toast from 'react-hot-toast'++import { del, handleError } from 'data/fetchers'+import { ResponseError } from 'types'import { storageCredentialsKeys } from './s3-access-key-keys'-import { del } from 'data/fetchers'-type S3AccessKeyDeleteMutation = {+type S3AccessKeyDeleteVariables = {projectRef?: stringid?: string}-const deleteS3AccessKeyCredential = async ({ projectRef, id }: S3AccessKeyDeleteMutation) => {- if (!projectRef || !id) {- throw new Error('projectRef and id are required')- }+const deleteS3AccessKeyCredential = async ({ projectRef, id }: S3AccessKeyDeleteVariables) => {+ if (!projectRef || !id) throw new Error('projectRef and id are required')- const res = await del('/platform/storage/{ref}/credentials/{id}', {- params: {- path: {- ref: projectRef,- id,- },- },+ const { data, error } = await del('/platform/storage/{ref}/credentials/{id}', {+ params: { path: { ref: projectRef, id } },})- return res+ if (error) {+ // [Joshen] This is only temporary and should be removed once the issue on API (storage) is resolved+ // Currently the API throws a 500 despite the secret getting removed correctly+ if ((error as ResponseError).message !== 'Failed to delete project storage credential') {+ handleError(error)+ }+ }++ return data}-export function useS3AccessKeyDeleteMutation({ projectRef }: S3AccessKeyDeleteMutation) {- const queryClient = useQueryClient()+type S3AccessKeyDeleteData = Awaited<ReturnType<typeof deleteS3AccessKeyCredential>>- const keys = storageCredentialsKeys.credentials(projectRef)+export function useS3AccessKeyDeleteMutation({+ onSuccess,+ onError,+ ...options+}: Omit<+ UseMutationOptions<S3AccessKeyDeleteData, ResponseError, S3AccessKeyDeleteVariables>,+ 'mutationFn'+> = {}) {+ const queryClient = useQueryClient()- return useMutation({- mutationFn: ({ id }: { id: string }) => deleteS3AccessKeyCredential({ projectRef, id }),- onSettled: () => {- queryClient.invalidateQueries(keys)- },- })+ return useMutation<S3AccessKeyDeleteData, ResponseError, S3AccessKeyDeleteVariables>(+ (vars) => deleteS3AccessKeyCredential(vars),+ {+ async onSuccess(data, variables, context) {+ const { projectRef } = variables+ await queryClient.invalidateQueries(storageCredentialsKeys.credentials(projectRef))+ await onSuccess?.(data, variables, context)+ },+ async onError(data, variables, context) {+ if (onError === undefined) {+ toast.error(`Failed to delete S3 access key: ${data.message}`)+ } else {+ onError(data, variables, context)+ }+ },+ ...options,+ }+ )}diff --git a/apps/studio/data/storage/s3-access-key-query.ts b/apps/studio/data/storage/s3-access-key-query.tsindex 9c8bd3e89b4..67a1e1acc4c 100644--- a/apps/studio/data/storage/s3-access-key-query.ts+++ b/apps/studio/data/storage/s3-access-key-query.ts@@ -1,25 +1,26 @@-import { useQuery } from '@tanstack/react-query'+import { UseQueryOptions, useQuery } from '@tanstack/react-query'++import { get, handleError } from 'data/fetchers'+import { ResponseError } from 'types'import { storageCredentialsKeys } from './s3-access-key-keys'-import { get } from 'data/fetchers'-type FetchStorageCredentials = {- projectRef?: string-}-async function fetchStorageCredentials({ projectRef }: FetchStorageCredentials) {- if (!projectRef) {- throw new Error('projectRef is required')- }+type StorageCredentialsVariables = { projectRef?: string }- const res = await get('/platform/storage/{ref}/credentials', {- params: {- path: {- ref: projectRef,- },- },+async function fetchStorageCredentials(+ { projectRef }: StorageCredentialsVariables,+ signal?: AbortSignal+) {+ if (!projectRef) throw new Error('projectRef is required')++ const { data, error } = await get('/platform/storage/{ref}/credentials', {+ params: { path: { ref: projectRef } },+ signal,})+ if (error) handleError(error)+// Generated types by openapi are wrong so we need to cast it.- return res.data as any as {+ return data as unknown as {data: {id: stringcreated_at: string@@ -29,17 +30,14 @@ async function fetchStorageCredentials({ projectRef }: FetchStorageCredentials)}}-type StorageCredentialsQuery = {- projectRef?: string-}-export function useStorageCredentialsQuery({ projectRef }: StorageCredentialsQuery) {- const keys = storageCredentialsKeys.credentials(projectRef)-- const query = useQuery({- queryKey: keys,- queryFn: () => fetchStorageCredentials({ projectRef }),- enabled: projectRef !== undefined,- })+export type StorageCredentialsData = Awaited<ReturnType<typeof fetchStorageCredentials>>- return query-}+export const useStorageCredentialsQuery = <TData = StorageCredentialsData>(+ { projectRef }: StorageCredentialsVariables,+ { enabled = true, ...options }: UseQueryOptions<StorageCredentialsData, ResponseError, TData> = {}+) =>+ useQuery<StorageCredentialsData, ResponseError, TData>(+ storageCredentialsKeys.credentials(projectRef),+ ({ signal }) => fetchStorageCredentials({ projectRef }, signal),+ { enabled: enabled && typeof projectRef !== 'undefined', ...options }+ )diff --git a/apps/studio/data/stripe/setup-intent-mutation.ts b/apps/studio/data/stripe/setup-intent-mutation.tsindex 37d9153a66b..76f79fe8797 100644--- a/apps/studio/data/stripe/setup-intent-mutation.ts+++ b/apps/studio/data/stripe/setup-intent-mutation.ts@@ -1,7 +1,7 @@import { useMutation, UseMutationOptions } from '@tanstack/react-query'import { toast } from 'react-hot-toast'-import { post } from 'data/fetchers'+import { handleError, post } from 'data/fetchers'import type { ResponseError } from 'types'export type SetupIntentVariables = {@@ -12,7 +12,7 @@ export async function setupIntent({ hcaptchaToken }: SetupIntentVariables) {const { data, error } = await post('/platform/stripe/setup-intent', {body: { hcaptchaToken },})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/subscriptions/org-plans-query.ts b/apps/studio/data/subscriptions/org-plans-query.tsindex a3cb6ea3b9e..edc1343c78d 100644--- a/apps/studio/data/subscriptions/org-plans-query.ts+++ b/apps/studio/data/subscriptions/org-plans-query.ts@@ -1,5 +1,5 @@import { useQuery, UseQueryOptions } from '@tanstack/react-query'-import { get } from 'data/fetchers'+import { get, handleError } from 'data/fetchers'import { subscriptionKeys } from './keys'export type OrgPlansVariables = {@@ -13,8 +13,7 @@ export async function getOrgPlans({ orgSlug }: OrgPlansVariables, signal?: Abortparams: { path: { slug: orgSlug } },signal,})- if (error) throw error-+ if (error) handleError(error)return data}diff --git a/apps/studio/data/subscriptions/org-subscription-cancel-schedule-mutation.ts b/apps/studio/data/subscriptions/org-subscription-cancel-schedule-mutation.tsindex a5ecb39b648..893fc05197d 100644--- a/apps/studio/data/subscriptions/org-subscription-cancel-schedule-mutation.ts+++ b/apps/studio/data/subscriptions/org-subscription-cancel-schedule-mutation.ts@@ -1,7 +1,7 @@import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'import { toast } from 'react-hot-toast'-import { del } from 'data/fetchers'+import { del, handleError } from 'data/fetchers'import type { ResponseError } from 'types'import { subscriptionKeys } from './keys'@@ -18,7 +18,7 @@ export async function cancelSubscriptionSchedule({params: { path: { slug } },})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/subscriptions/org-subscription-query.ts b/apps/studio/data/subscriptions/org-subscription-query.tsindex d4faeb1d255..5c1e0e60ec7 100644--- a/apps/studio/data/subscriptions/org-subscription-query.ts+++ b/apps/studio/data/subscriptions/org-subscription-query.ts@@ -1,5 +1,5 @@import { useQuery, UseQueryOptions } from '@tanstack/react-query'-import { get } from 'data/fetchers'+import { get, handleError } from 'data/fetchers'import { subscriptionKeys } from './keys'import type { ResponseError } from 'types'@@ -18,7 +18,7 @@ export async function getOrgSubscription(signal,})- if (error) throw error+ if (error) handleError(error)return data}diff --git a/apps/studio/data/subscriptions/org-subscription-update-mutation.ts b/apps/studio/data/subscriptions/org-subscription-update-mutation.tsindex bb1869fa064..ee47f235d70 100644--- a/apps/studio/data/subscriptions/org-subscription-update-mutation.ts+++ b/apps/studio/data/subscriptions/org-subscription-update-mutation.ts@@ -1,5 +1,5 @@import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'-import { put } from 'data/fetchers'+import { handleError, put } from 'data/fetchers'import { toast } from 'react-hot-toast'import type { ResponseError } from 'types/base'import { subscriptionKeys } from './keys'@@ -32,10 +32,7 @@ export async function updateOrgSubscription({params: { path: { slug } },})- if (error) {- throw error- }-+ if (error) handleError(error)return data}diff --git a/apps/studio/data/subscriptions/project-addon-remove-mutation.ts b/apps/studio/data/subscriptions/project-addon-remove-mutation.tsindex 0b8b5261359..59a6ce581a3 100644--- a/apps/studio/data/subscriptions/project-addon-remove-mutation.ts+++ b/apps/studio/data/subscriptions/project-addon-remove-mutation.ts@@ -1,7 +1,7 @@import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'import { toast } from 'react-hot-toast'-import { del } from 'data/fetchers'+import { del, handleError } from 'data/fetchers'import type { ResponseError } from 'types'import { subscriptionKeys } from './keys'import type { AddonVariantId } from './types'@@ -27,8 +27,7 @@ export async function removeSubscriptionAddon({},})- if (error) throw error-+ if (error) handleError(error)return data}diff --git a/apps/studio/data/subscriptions/project-addon-update-mutation.ts b/apps/studio/data/subscriptions/project-addon-update-mutation.tsindex 73638b12763..ca1974b04f8 100644--- a/apps/studio/data/subscriptions/project-addon-update-mutation.ts+++ b/apps/studio/data/subscriptions/project-addon-update-mutation.ts@@ -1,7 +1,7 @@import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'import { toast } from 'react-hot-toast'-import { post } from 'data/fetchers'+import { handleError, post } from 'data/fetchers'import type { ResponseError } from 'types'import { subscriptionKeys } from './keys'import type { AddonVariantId, ProjectAddonType } from './types'@@ -33,8 +33,7 @@ export async function updateSubscriptionAddon({},})- if (error) throw error-+ if (error) handleError(error)return data}diff --git a/apps/studio/data/subscriptions/project-addons-query.ts b/apps/studio/data/subscriptions/project-addons-query.tsindex eb037de72b0..ed0cf43acd9 100644--- a/apps/studio/data/subscriptions/project-addons-query.ts+++ b/apps/studio/data/subscriptions/project-addons-query.ts@@ -1,7 +1,8 @@import { useQuery, UseQueryOptions } from '@tanstack/react-query'-import { get } from 'data/fetchers'-import { subscriptionKeys } from './keys'++import { get, handleError } from 'data/fetchers'import type { ResponseError } from 'types'+import { subscriptionKeys } from './keys'export type ProjectAddonsVariables = {projectRef?: string@@ -18,7 +19,7 @@ export async function getProjectAddons(signal,})- if (error) throw error+ if (error) handleError(error)return data}