The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: show uninstall progress (#42860)
Raminder Singh3d14b5e7bf41
diff --git a/apps/studio/components/interfaces/Integrations/Integration/IntegrationOverviewTab.tsx b/apps/studio/components/interfaces/Integrations/Integration/IntegrationOverviewTab.tsxindex 78c379c1c82..2846e1dae46 100644--- a/apps/studio/components/interfaces/Integrations/Integration/IntegrationOverviewTab.tsx+++ b/apps/studio/components/interfaces/Integrations/Integration/IntegrationOverviewTab.tsx@@ -1,9 +1,9 @@-import { PropsWithChildren, ReactNode } from 'react'-import { useParams } from 'common'import { useDatabaseExtensionsQuery } from 'data/database-extensions/database-extensions-query'import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'+import { PropsWithChildren, ReactNode } from 'react'import { Badge, Card, CardContent, cn, Separator } from 'ui'+import { INTEGRATIONS } from '../Landing/Integrations.constants'import { BuiltBySection } from './BuildBySection'import { MarkdownContent } from './MarkdownContent'@@ -53,8 +53,8 @@ export const IntegrationOverviewTab = ({<MarkdownContent key={integration.id} integrationId={integration.id} /><Separator />{dependsOnExtension && (- <div className="px-4 md:px-10 max-w-4xl">- <h3 className="heading-default mb-4">Required extensions</h3>+ <div className="px-4 md:px-10 max-w-4xl flex flex-col gap-y-4">+ <h4>Required extensions</h4><Card><CardContent className="p-0"><ul className="text-foreground-light text-sm">diff --git a/apps/studio/components/interfaces/Integrations/Landing/useInstalledIntegrations.tsx b/apps/studio/components/interfaces/Integrations/Landing/useInstalledIntegrations.tsxindex 8b9d954af0a..ed565b7ff44 100644--- a/apps/studio/components/interfaces/Integrations/Landing/useInstalledIntegrations.tsx+++ b/apps/studio/components/interfaces/Integrations/Landing/useInstalledIntegrations.tsx@@ -1,19 +1,20 @@-import { useMemo } from 'react'-+import { useFlag } from 'common'import { useDatabaseExtensionsQuery } from 'data/database-extensions/database-extensions-query'import { useSchemasQuery } from 'data/database/schemas-query'import { useFDWsQuery } from 'data/fdw/fdws-query'-import { useFlag } from 'common'import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'import { IS_PLATFORM } from 'lib/constants'import { EMPTY_ARR } from 'lib/void'-import {- INSTALLATION_INSTALLED_SUFFIX,- STRIPE_SCHEMA_COMMENT_PREFIX,-} from 'stripe-experiment-sync/supabase'+import { useMemo } from 'react'+import { wrapperMetaComparator } from '../Wrappers/Wrappers.utils'import { INTEGRATIONS } from './Integrations.constants'+import {+ isInstalled as checkIsInstalled,+ findStripeSchema,+ parseStripeSchemaStatus,+} from '@/components/interfaces/Integrations/templates/StripeSyncEngine/stripe-sync-status'export const useInstalledIntegrations = () => {const { data: project } = useSelectedProjectQuery()@@ -84,11 +85,9 @@ export const useInstalledIntegrations = () => {return true}if (integration.id === 'stripe_sync_engine') {- const stripeSchema = schemas?.find(({ name }) => name === 'stripe')- return (- !!stripeSchema?.comment?.startsWith(STRIPE_SCHEMA_COMMENT_PREFIX) &&- !!stripeSchema.comment?.includes(INSTALLATION_INSTALLED_SUFFIX)- )+ const stripeSchema = findStripeSchema(schemas)+ const status = parseStripeSchemaStatus(stripeSchema)+ return checkIsInstalled(status)}if (integration.type === 'wrapper') {return wrappers.find((w) => wrapperMetaComparator(integration.meta, w))diff --git a/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/InstallationOverview.tsx b/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/InstallationOverview.tsxindex c332f90d8ae..6e0528d6a5d 100644--- a/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/InstallationOverview.tsx+++ b/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/InstallationOverview.tsx@@ -1,27 +1,21 @@import { zodResolver } from '@hookform/resolvers/zod'+import { ButtonTooltip } from 'components/ui/ButtonTooltip'import { useStripeSyncInstallMutation } from 'data/database-integrations/stripe/stripe-sync-install-mutation'import { useStripeSyncUninstallMutation } from 'data/database-integrations/stripe/stripe-sync-uninstall-mutation'-import { useStripeSyncingState } from 'data/database-integrations/stripe/sync-state-query'import { useSchemasQuery } from 'data/database/schemas-query'import { formatRelative } from 'date-fns'import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'import { useTrack } from 'lib/telemetry/track'import { AlertCircle, BadgeCheck, Check, ExternalLink, RefreshCwIcon } from 'lucide-react'import Link from 'next/link'-import { useEffect, useMemo, useRef, useState } from 'react'+import { useCallback, useEffect, useMemo, useRef, useState } from 'react'import { useForm } from 'react-hook-form'import { toast } from 'sonner'-import {- INSTALLATION_ERROR_SUFFIX,- INSTALLATION_INSTALLED_SUFFIX,- INSTALLATION_STARTED_SUFFIX,- STRIPE_SCHEMA_COMMENT_PREFIX,-} from 'stripe-experiment-sync/supabase'import {Button,+ Form_Shadcn_,FormControl_Shadcn_,FormField_Shadcn_,- Form_Shadcn_,Sheet,SheetContent,SheetFooter,@@ -31,41 +25,68 @@ import {} from 'ui'import { Admonition } from 'ui-patterns'import { Input } from 'ui-patterns/DataInputs/Input'+import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'import * as z from 'zod'+import { IntegrationOverviewTab } from '../../Integration/IntegrationOverviewTab'+import {+ canInstall as checkCanInstall,+ hasInstallError,+ hasUninstallError,+ isInstallDone,+ isInstalled,+ isInstalling,+ isSyncRunning,+ isUninstallDone,+ isUninstalling,+} from './stripe-sync-status'import { StripeSyncChangesCard } from './StripeSyncChangesCard'+import { useStripeSyncStatus } from '@/components/interfaces/Integrations/templates/StripeSyncEngine/useStripeSyncStatus'+import { InlineLink } from '@/components/ui/InlineLink'const installFormSchema = z.object({stripeSecretKey: z.string().min(1, 'Stripe API key is required'),})export const StripeSyncInstallationPage = () => {- const { data: project } = useSelectedProjectQuery()const track = useTrack()const hasTrackedInstallFailed = useRef(false)+ const { data: project } = useSelectedProjectQuery()const [shouldShowInstallSheet, setShouldShowInstallSheet] = useState(false)+ const [showUninstallModal, setShowUninstallModal] = useState(false)+ // These flags bridge the gap between mutation success and schema updateconst [isInstallInitiated, setIsInstallInitiated] = useState(false)+ const [isUninstallInitiated, setIsUninstallInitiated] = useState(false)const formId = 'stripe-sync-install-form'const form = useForm<z.infer<typeof installFormSchema>>({resolver: zodResolver(installFormSchema),- defaultValues: {- stripeSecretKey: '',- },+ defaultValues: { stripeSecretKey: '' },mode: 'onSubmit',})- const { data: schemas } = useSchemasQuery({+ // Use the unified status hook+ const { installationStatus, syncState } = useStripeSyncStatus({projectRef: project?.ref,connectionString: project?.connectionString,})+ const isSyncing = isSyncRunning(syncState)++ const installed = isInstalled(installationStatus)+ const installError = hasInstallError(installationStatus)+ const uninstallError = hasUninstallError(installationStatus)+ const installInProgress = isInstalling(installationStatus)+ const uninsallInProgress = isUninstalling(installationStatus)+ const installDone = isInstallDone(installationStatus)+ const uninstallDone = isUninstallDone(installationStatus)+const {mutate: installStripeSync,- isPending: isInstalling,- error: installError,+ isPending: isInstallRequested,+ error: installRequestError,reset: resetInstallError,} = useStripeSyncInstallMutation({onSuccess: () => {@@ -76,103 +97,41 @@ export const StripeSyncInstallationPage = () => {},})- const { mutate: uninstallStripeSync, isPending: isUninstalling } = useStripeSyncUninstallMutation(- {+ const { mutate: uninstallStripeSync, isPending: isUninstallRequested } =+ useStripeSyncUninstallMutation({onSuccess: () => {toast.success('Stripe Sync uninstallation started')+ setShowUninstallModal(false)+ setIsUninstallInitiated(true)},- }- )-- const stripeSchema = schemas?.find((s) => s.name === 'stripe')-- // Determine installation status from schema description- const isInstalled =- stripeSchema &&- stripeSchema.comment?.startsWith(STRIPE_SCHEMA_COMMENT_PREFIX) &&- stripeSchema.comment.includes(INSTALLATION_INSTALLED_SUFFIX)-- const schemaShowsInProgress =- stripeSchema &&- stripeSchema.comment?.startsWith(STRIPE_SCHEMA_COMMENT_PREFIX) &&- stripeSchema.comment?.includes(INSTALLATION_STARTED_SUFFIX)-- const setupInProgress = schemaShowsInProgress || isInstalling || isInstallInitiated-- const setupError =- stripeSchema &&- stripeSchema.comment?.startsWith(STRIPE_SCHEMA_COMMENT_PREFIX) &&- stripeSchema.comment?.includes(INSTALLATION_ERROR_SUFFIX)-- useEffect(() => {- if (!setupError) {- hasTrackedInstallFailed.current = false- return- }-- if (!hasTrackedInstallFailed.current) {- hasTrackedInstallFailed.current = true- // This isn't ideal because it will fire on every page load while in error state- // in the future we should connect this in the backend to track accurately- track('integration_install_failed', {- integrationName: 'stripe_sync_engine',- })- }- }, [setupError, track])-- useEffect(() => {- // Clear the install initiated flag once we detect completion or error from the schema- if (isInstallInitiated && (isInstalled || setupError)) {- setIsInstallInitiated(false)- }- }, [isInstallInitiated, isInstalled, setupError])-- // Check if there's an existing stripe schema that wasn't created by this integration- const hasConflictingSchema =- stripeSchema && !stripeSchema.comment?.startsWith(STRIPE_SCHEMA_COMMENT_PREFIX)-- const canInstall = !hasConflictingSchema && !isInstalled && !setupInProgress+ })- // Sync state query - only enabled when installed- const { data: syncState } = useStripeSyncingState(- {- projectRef: project?.ref!,- connectionString: project?.connectionString,- },- {- refetchInterval: 4000,- enabled: !!isInstalled,- }- )+ // Combine schema status with mutation/initiated states for UI+ const installing = installInProgress || isInstallRequested || isInstallInitiated+ const uninstalling = uninsallInProgress || isUninstallRequested || isUninstallInitiated+ const canInstall = checkCanInstall(installationStatus) && !installed && !installing- // Poll for schema changes during installation+ // Poll for schema changes during transitionsuseSchemasQuery(- {- projectRef: project?.ref,- connectionString: project?.connectionString,- },- {- refetchInterval: setupInProgress ? 5000 : false,- }+ { projectRef: project?.ref, connectionString: project?.connectionString },+ { refetchInterval: installing || uninstalling ? 5000 : false })- const isSyncing = !!syncState && !syncState.closed_at && syncState.status === 'running'-- const handleUninstall = () => {+ const handleUninstall = useCallback(() => {if (!project?.ref) returnuninstallStripeSync({projectRef: project.ref,})- }+ }, [project?.ref, uninstallStripeSync])- const handleOpenInstallSheet = () => {+ const handleOpenInstallSheet = useCallback(() => {resetInstallError()setShouldShowInstallSheet(true)- }+ }, [resetInstallError])const handleCloseInstallSheet = (isOpen: boolean) => {- if (isInstalling) return+ if (isInstallRequested) returnsetShouldShowInstallSheet(isOpen)if (!isOpen) {@@ -184,7 +143,28 @@ export const StripeSyncInstallationPage = () => {const tableEditorUrl = `/project/${project?.ref}/editor?schema=stripe`const alert = useMemo(() => {- if (setupError) {+ if (uninstallError) {+ return (+ <Admonition type="destructive" showIcon={true} title="Uninstallation Error">+ <div>+ There was an error during the uninstallation of the Stripe Sync Engine. Please try+ again. If the problem persists, contact support.+ </div>+ <div className="flex gap-2 mt-4">+ <Button+ type="warning"+ onClick={handleUninstall}+ loading={isUninstallRequested}+ disabled={isUninstallRequested}+ >+ Try Again+ </Button>+ </div>+ </Admonition>+ )+ }++ if (installError) {return (<Admonition type="destructive" showIcon={true} title="Installation Error"><div>@@ -196,8 +176,8 @@ export const StripeSyncInstallationPage = () => {<Buttontype="warning"onClick={handleUninstall}- loading={isUninstalling}- disabled={isUninstalling}+ loading={isUninstallRequested}+ disabled={isUninstallRequested}>Uninstall</Button>@@ -206,7 +186,7 @@ export const StripeSyncInstallationPage = () => {)}- if (syncState) {+ if (syncState && installed && !uninstalling) {return (<Admonition type="default" showIcon={false}><div className="flex items-center justify-between gap-2">@@ -225,7 +205,7 @@ export const StripeSyncInstallationPage = () => {<div className="flex items-center gap-2"><BadgeCheck size={14} className="text-brand" /><div>All up to date</div>- <Button asChild type="link">+ <Button asChild type="text"><Link href={tableEditorUrl}>View data</Link></Button></div>@@ -241,24 +221,44 @@ export const StripeSyncInstallationPage = () => {return null}, [- setupError,- setupInProgress,+ uninstallError,+ installError,syncState,isSyncing,- isUninstalling,+ installed,+ isUninstallRequested,+ tableEditorUrl,+ uninstalling,handleOpenInstallSheet,handleUninstall,])- const status = useMemo(() => {- if (isInstalled) {+ const statusDisplay = useMemo(() => {+ if (uninstallError) {return (<span className="flex items-center gap-2 text-foreground-light text-sm">- <Check size={14} strokeWidth={1.5} className="text-brand" /> Installed+ <AlertCircle size={14} className="text-destructive" />+ Uninstallation error+ </span>+ )+ }+ if (uninstalling) {+ return (+ <span className="flex items-center gap-2 text-foreground-light text-sm">+ <RefreshCwIcon size={14} className="animate-spin text-foreground-lighter" />+ Uninstalling...</span>)}- if (setupInProgress) {+ if (installError) {+ return (+ <span className="flex items-center gap-2 text-foreground-light text-sm">+ <AlertCircle size={14} className="text-destructive" />+ Installation error+ </span>+ )+ }+ if (installing) {return (<span className="flex items-center gap-2 text-foreground-light text-sm"><RefreshCwIcon size={14} className="animate-spin text-foreground-lighter" />@@ -266,7 +266,7 @@ export const StripeSyncInstallationPage = () => {</span>)}- if (syncState) {+ if (isSyncing && installed) {return (<span className="flex items-center gap-2 text-foreground-light text-sm"><RefreshCwIcon size={14} className="animate-spin text-foreground-lighter" />@@ -274,146 +274,220 @@ export const StripeSyncInstallationPage = () => {</span>)}- if (setupError) {+ if (installed) {return (<span className="flex items-center gap-2 text-foreground-light text-sm">- <AlertCircle size={14} className="text-destructive" />- Installation error+ <Check size={14} strokeWidth={1.5} className="text-brand" /> Installed</span>)}return (<span className="flex items-center gap-2 text-foreground-light text-sm">Not installed</span>)- }, [isInstalled, setupInProgress, syncState, setupError])+ }, [uninstallError, uninstalling, installError, installing, isSyncing, installed])++ // Track install failures+ useEffect(() => {+ if (!installError) {+ hasTrackedInstallFailed.current = false+ return+ }++ if (!hasTrackedInstallFailed.current) {+ hasTrackedInstallFailed.current = true+ track('integration_install_failed', {+ integrationName: 'stripe_sync_engine',+ })+ }+ }, [installError, track])++ // Clear install initiated flag once schema reflects completion or error+ useEffect(() => {+ if (isInstallInitiated && installDone) {+ setIsInstallInitiated(false)+ }+ }, [isInstallInitiated, installDone])++ // Clear uninstall initiated flag once schema is removed or error+ useEffect(() => {+ if (isUninstallInitiated && uninstallDone) {+ setIsUninstallInitiated(false)+ }+ }, [isUninstallInitiated, uninstallDone])return (- <IntegrationOverviewTab- alert={alert}- status={status}- actions={- !isInstalled && !setupInProgress && !setupError ? (- <StripeSyncChangesCard- canInstall={canInstall}- onInstall={() => setShouldShowInstallSheet(true)}- />- ) : null- }- >- <Sheet open={!!shouldShowInstallSheet} onOpenChange={handleCloseInstallSheet}>- <SheetContent size="lg" tabIndex={undefined} className="flex flex-col gap-0">- <Form_Shadcn_ {...form}>- <form- id={formId}- onSubmit={form.handleSubmit(({ stripeSecretKey }) => {- if (!project?.ref) return- installStripeSync({ projectRef: project.ref, stripeSecretKey })- })}- className="overflow-auto flex-grow px-0 flex flex-col"- >- <SheetHeader>- <SheetTitle>Install Stripe Sync Engine</SheetTitle>- </SheetHeader>- <SheetSection className="flex-1">- <StripeSyncChangesCard />- <Admonition type="warning" className="mt-6">- <p>- This integration currently requires{' '}- <Link- href="https://supabase.com/docs/guides/platform/ssl-enforcement"- target="_blank"- rel="noopener noreferrer"- className="underline"- >- SSL Enforcement- </Link>{' '}- to be disabled during initial setup. Support for SSL Enforcement will be added- in a future update. Once installed, all webhook and sync operations use- HTTPS/SSL.- </p>- </Admonition>- <h3 className="heading-default mb-4 mt-6">Configuration</h3>- {installError && (- <Admonition type="destructive" className="mb-4">- <div className="flex items-start gap-2">- <AlertCircle size={16} className="mt-0.5 flex-shrink-0" />- <div>- <p className="font-medium">Installation failed</p>- <p className="text-sm">{installError.message}</p>- </div>- </div>+ <>+ <IntegrationOverviewTab+ alert={alert}+ status={statusDisplay}+ actions={+ !installed && !installing && !installError ? (+ <>+ <StripeSyncChangesCard />+ <div className="flex justify-end mt-4">+ <ButtonTooltip+ type="primary"+ onClick={() => setShouldShowInstallSheet(true)}+ disabled={!canInstall}+ tooltip={{+ content: {+ text: !canInstall+ ? 'Your database already uses a schema named "stripe"'+ : undefined,+ },+ }}+ >+ Install integration+ </ButtonTooltip>+ </div>+ </>+ ) : installed && !uninstalling ? (+ <div className="flex justify-end mt-4">+ <Button type="default" onClick={() => setShowUninstallModal(true)}>+ Uninstall integration+ </Button>+ </div>+ ) : null+ }+ >+ <Sheet open={!!shouldShowInstallSheet} onOpenChange={handleCloseInstallSheet}>+ <SheetContent size="lg" tabIndex={undefined} className="flex flex-col gap-0">+ <Form_Shadcn_ {...form}>+ <form+ id={formId}+ onSubmit={form.handleSubmit(({ stripeSecretKey }) => {+ if (!project?.ref) return+ installStripeSync({ projectRef: project.ref, stripeSecretKey })+ })}+ className="overflow-auto flex-grow px-0 flex flex-col"+ >+ <SheetHeader>+ <SheetTitle>Install Stripe Sync Engine</SheetTitle>+ </SheetHeader>+ <SheetSection className="flex-1 flex flex-col gap-y-6">+ <StripeSyncChangesCard />++ <Admonition type="warning">+ <h5 className="mb-0.5">+ This integration currently requires{' '}+ <InlineLink href="https://supabase.com/docs/guides/platform/ssl-enforcement">+ SSL Enforcement+ </InlineLink>{' '}+ to be disabled during initial setup.+ </h5>+ <p className="text-foreground-light">+ Support for SSL Enforcement will be added in a future update. Once installed,+ all webhook and sync operations use HTTPS/SSL.+ </p></Admonition>- )}-- <FormField_Shadcn_- control={form.control}- name="stripeSecretKey"- render={({ field }) => (- <FormItemLayout- layout="flex-row-reverse"- label="Stripe API key"- description="Your Stripe secret key. Requires write access to Webhook Endpoints and read-only access to all other categories."- >- <FormControl_Shadcn_ className="col-span-8">- <Input- id="stripe_api_key"- name="stripe_api_key"- placeholder="Enter your Stripe API key"- autoComplete="stripe-api-key"- reveal={false}- disabled={isInstalling}- type="password"- value={field.value}- onChange={(e) => field.onChange(e.target.value)}- />- </FormControl_Shadcn_>- </FormItemLayout>++ <h3 className="heading-default">Configuration</h3>++ <FormField_Shadcn_+ control={form.control}+ name="stripeSecretKey"+ render={({ field }) => (+ <FormItemLayout+ layout="flex-row-reverse"+ label="Stripe API secret key"+ description="Your Stripe secret key. Requires write access to Webhook Endpoints and read-only access to all other categories."+ >+ <FormControl_Shadcn_ className="col-span-8">+ <Input+ id="stripe_api_key"+ name="stripe_api_key"+ placeholder="Enter your Stripe API key"+ autoComplete="stripe-api-key"+ reveal={false}+ disabled={isInstallRequested}+ type="password"+ value={field.value}+ onChange={(e) => field.onChange(e.target.value)}+ />+ </FormControl_Shadcn_>+ </FormItemLayout>+ )}+ />++ <div className="flex items-center gap-x-2">+ <Button asChild type="default" icon={<ExternalLink />}>+ <Link+ target="_blank"+ rel="noopener noreferrer"+ href="https://dashboard.stripe.com/apikeys"+ >+ Get Stripe API key+ </Link>+ </Button>+ <Button asChild type="default" icon={<ExternalLink />}>+ <Link+ target="_blank"+ rel="noopener noreferrer"+ href="https://support.stripe.com/questions/what-are-stripe-api-keys-and-how-to-find-them"+ >+ What are Stripe API keys?+ </Link>+ </Button>+ </div>++ {installRequestError && (+ <Admonition+ type="destructive"+ title="Installation failed"+ description={installRequestError.message}+ />)}- />-- <div className="flex items-center mt-4 gap-2">- <Button asChild type="default" icon={<ExternalLink />}>- <Link- href="https://dashboard.stripe.com/apikeys"- target="_blank"- rel="noopener noreferrer"- >- Get Stripe API key- </Link>+ </SheetSection>++ <SheetFooter>+ <Button+ type="default"+ disabled={isInstallRequested}+ onClick={() => handleCloseInstallSheet(false)}+ >+ Cancel</Button>- <Button asChild type="default" icon={<ExternalLink />}>- <Link- href="https://support.stripe.com/questions/what-are-stripe-api-keys-and-how-to-find-them"- target="_blank"- rel="noopener noreferrer"- >- What are Stripe API keys?- </Link>+ <Button+ form={formId}+ htmlType="submit"+ type="primary"+ loading={isInstallRequested}+ disabled={!form.formState.isValid || isInstallRequested}+ >+ {isInstallRequested ? 'Installing' : 'Install'}</Button>- </div>- </SheetSection>- <SheetFooter>- <Button- type="default"- disabled={isInstalling}- onClick={() => handleCloseInstallSheet(false)}- >- Cancel- </Button>- <Button- form={formId}- htmlType="submit"- type="primary"- loading={isInstalling}- disabled={!form.formState.isValid || isInstalling}- >- {isInstalling ? 'Starting Installation...' : 'Start Installation'}- </Button>- </SheetFooter>- </form>- </Form_Shadcn_>- </SheetContent>- </Sheet>- </IntegrationOverviewTab>+ </SheetFooter>+ </form>+ </Form_Shadcn_>+ </SheetContent>+ </Sheet>++ <ConfirmationModal+ visible={showUninstallModal}+ title="Uninstall Stripe Sync Engine"+ confirmLabel="Uninstall"+ confirmLabelLoading="Uninstalling..."+ variant="destructive"+ loading={isUninstallRequested}+ onCancel={() => setShowUninstallModal(false)}+ onConfirm={handleUninstall}+ >+ <p className="text-sm text-foreground-light">+ Are you sure you want to uninstall the Stripe Sync Engine? This will:+ </p>+ <ul className="list-disc pl-5 mt-2 text-sm text-foreground-light space-y-1">+ <li>+ Remove the <code className="text-code-inline">stripe</code> schema and all tables+ </li>+ <li>Delete all synced Stripe data</li>+ <li>Remove the associated Edge Functions</li>+ <li>Remove the scheduled sync jobs</li>+ </ul>+ <p className="mt-4 text-sm text-foreground-light font-medium">+ This action cannot be undone.+ </p>+ </ConfirmationModal>+ </IntegrationOverviewTab>+ </>)}diff --git a/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/StripeSyncChangesCard.tsx b/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/StripeSyncChangesCard.tsxindex 6ca75a277a5..0271b45a9c7 100644--- a/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/StripeSyncChangesCard.tsx+++ b/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/StripeSyncChangesCard.tsx@@ -1,40 +1,34 @@-import { ButtonTooltip } from 'components/ui/ButtonTooltip'import { EdgeFunctions } from 'icons'import { Layers, Table } from 'lucide-react'-import { Card, CardContent, CardFooter, cn } from 'ui'+import { Card, CardContent, cn } from 'ui'type StripeSyncChangesCardProps = {className?: string- canInstall?: boolean- onInstall?: () => void}-export const StripeSyncChangesCard = ({- className,- canInstall = true,- onInstall,-}: StripeSyncChangesCardProps) => {- const showInstallButton = typeof onInstall === 'function'+const ListItemClassName = 'flex items-center gap-x-3 py-2 px-3 border-b'+export const StripeSyncChangesCard = ({ className }: StripeSyncChangesCardProps) => {return (- <div>- <h3 className="heading-default mb-4">This integration will modify your Supabase project:</h3>+ <div className="flex flex-col gap-y-4">+ <h4>This integration will modify your Supabase project:</h4><Card className={cn(className)}><CardContent className="p-0"><ul className="text-foreground-light text-sm">- <li className="flex items-center gap-3 py-2 px-3 border-b">+ <li className={ListItemClassName}><Table size={16} strokeWidth={1.5} className="text-foreground-muted shrink-0" /><span>- Creates a new database schema named <code>stripe</code>+ Creates a new database schema named <code className="text-code-inline">stripe</code></span></li>- <li className="flex items-center gap-3 py-2 px-3 border-b">+ <li className={ListItemClassName}><Table size={16} strokeWidth={1.5} className="text-foreground-muted shrink-0" /><span>- Creates tables and views in the <code>stripe</code> schema for synced Stripe data+ Creates tables and views in the <code className="text-code-inline">stripe</code>{' '}+ schema for synced Stripe data</span></li>- <li className="flex items-center gap-3 py-2 px-3 border-b">+ <li className={ListItemClassName}><EdgeFunctionssize={16}strokeWidth={1.5}@@ -42,30 +36,12 @@ export const StripeSyncChangesCard = ({/><span>Deploys Edge Functions to handle incoming webhooks from Stripe</span></li>- <li className="flex items-center gap-3 py-2 px-3">+ <li className="flex items-center gap-x-3 py-2 px-3"><Layers size={16} strokeWidth={1.5} className="text-foreground-muted shrink-0" /><span>Schedules automatic Stripe data syncs using Supabase Queues</span></li></ul></CardContent>- {showInstallButton && (- <CardFooter className="flex justify-end">- <ButtonTooltip- type="primary"- onClick={onInstall}- disabled={!canInstall}- tooltip={{- content: {- text: !canInstall- ? 'Your database already uses a schema named "stripe"'- : undefined,- },- }}- >- Install integration- </ButtonTooltip>- </CardFooter>- )}</Card></div>)diff --git a/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/StripeSyncSettingsPage.tsx b/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/StripeSyncSettingsPage.tsxindex 6d563283210..3075db7778f 100644--- a/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/StripeSyncSettingsPage.tsx+++ b/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/StripeSyncSettingsPage.tsx@@ -1,25 +1,9 @@-import { useSchemasQuery } from 'data/database/schemas-query'-import { useStripeSyncUninstallMutation } from 'data/database-integrations/stripe/stripe-sync-uninstall-mutation'import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'-import { Loader2, Table2 } from 'lucide-react'+import { Table2 } from 'lucide-react'import Link from 'next/link'import { useRouter } from 'next/router'-import { useEffect, useState } from 'react'-import { toast } from 'sonner'-import {- INSTALLATION_INSTALLED_SUFFIX,- STRIPE_SCHEMA_COMMENT_PREFIX,-} from 'stripe-experiment-sync/supabase'-import {- AlertDescription_Shadcn_,- AlertTitle_Shadcn_,- Alert_Shadcn_,- Button,- Card,- CardContent,- WarningIcon,-} from 'ui'-import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'+import { useEffect } from 'react'+import { Button, Card, CardContent } from 'ui'import { PageContainer } from 'ui-patterns/PageContainer'import {PageSection,@@ -30,158 +14,62 @@ import {PageSectionTitle,} from 'ui-patterns/PageSection'+import { isInstalled } from './stripe-sync-status'+import { useStripeSyncStatus } from '@/components/interfaces/Integrations/templates/StripeSyncEngine/useStripeSyncStatus'+export const StripeSyncSettingsPage = () => {const router = useRouter()const { data: project } = useSelectedProjectQuery()- const [showUninstallModal, setShowUninstallModal] = useState(false)- const [isUninstallInitiated, setIsUninstallInitiated] = useState(false)- const { data: schemas, isLoading: isSchemasLoading } = useSchemasQuery({+ const { installationStatus, isLoading: isLoadingInstallationStatus } = useStripeSyncStatus({projectRef: project?.ref,connectionString: project?.connectionString,})+ const installed = isInstalled(installationStatus)- const stripeSchema = schemas?.find((s) => s.name === 'stripe')-- const isInstalled =- stripeSchema &&- stripeSchema.comment?.startsWith(STRIPE_SCHEMA_COMMENT_PREFIX) &&- stripeSchema.comment.includes(INSTALLATION_INSTALLED_SUFFIX)-- // Redirect to overview if not installed+ // Redirect to overview page when integration is not installeduseEffect(() => {- if (!isSchemasLoading && !isInstalled && project?.ref) {- router.push(`/project/${project.ref}/integrations/stripe_sync_engine/overview`)- }- }, [isSchemasLoading, isInstalled, project?.ref, router])-- const { mutate: uninstallStripeSync, isPending: isUninstalling } = useStripeSyncUninstallMutation(- {- onSuccess: () => {- toast.success('Stripe Sync uninstallation started')- setShowUninstallModal(false)- setIsUninstallInitiated(true)- // Redirect to overview after uninstall- if (project?.ref) {- router.push(`/project/${project.ref}/integrations/stripe_sync_engine/overview`)- }- },- }- )+ if (isLoadingInstallationStatus || installed || !project?.ref) return- const handleUninstall = () => {- if (!project?.ref) return- uninstallStripeSync({ projectRef: project.ref })- }-- const tableEditorUrl = `/project/${project?.ref}/editor?schema=stripe`-- // Show loading state while checking installation status- if (isSchemasLoading || !isInstalled) {- return (- <div className="flex items-center justify-center py-20">- <Loader2 className="animate-spin text-foreground-muted" size={24} />- </div>- )- }+ router.push(`/project/${project.ref}/integrations/stripe_sync_engine/overview`)+ }, [isLoadingInstallationStatus, installed, project?.ref, router])return (- <>- <PageContainer size="small">- <PageSection id="stripe-schema">- <PageSectionMeta>- <PageSectionSummary>- <PageSectionTitle>Stripe Schema</PageSectionTitle>- <PageSectionDescription>- Access and manage the synced Stripe data in your database.- </PageSectionDescription>- </PageSectionSummary>- </PageSectionMeta>- <PageSectionContent>- <Card>- <CardContent>- <div className="flex space-x-4 @container">+ <PageContainer>+ <PageSection id="stripe-schema">+ <PageSectionMeta>+ <PageSectionSummary>+ <PageSectionTitle>Stripe Schema</PageSectionTitle>+ <PageSectionDescription>+ Access and manage the synced Stripe data in your database.+ </PageSectionDescription>+ </PageSectionSummary>+ </PageSectionMeta>+ <PageSectionContent>+ <Card>+ <CardContent className="@container">+ <div className="flex flex-col items-start justify-between gap-4 @md:flex-row @md:items-center">+ <div className="flex gap-x-4"><Table2 className="w-5 h-5 shrink-0" />- <div className="flex flex-col items-start @lg:flex-row @lg:items-center gap-4">- <div className="flex flex-col gap-1">- <h5 className="text-sm mb-1">Open Stripe schema in Table Editor</h5>- <p className="text-sm text-foreground-light">- The Stripe Sync Engine stores all synced data in the <code>stripe</code>{' '}- schema. You can view and query this data directly in the Table Editor.- </p>- </div>- <Button asChild type="default">- <Link href={tableEditorUrl}>Open Table Editor</Link>- </Button>+ <div className="flex flex-col gap-1">+ <h5 className="text-sm mb-1">Open Stripe schema in Table Editor</h5>+ <p className="text-sm text-foreground-light text-balance">+ The Stripe Sync Engine stores all synced data in the{' '}+ <code className="text-code-inline !break-keep">stripe</code> schema. You can+ view and query this data directly in the Table Editor.+ </p></div></div>- </CardContent>- </Card>- </PageSectionContent>- </PageSection>-- <PageSection id="uninstall-stripe-sync">- <PageSectionMeta>- <PageSectionSummary>- <PageSectionTitle>Uninstall Stripe Sync Engine</PageSectionTitle>- <PageSectionDescription>- Remove the integration and all synced data from your project.- </PageSectionDescription>- </PageSectionSummary>- </PageSectionMeta>- <PageSectionContent>- <Alert_Shadcn_ variant="warning" className="flex space-x-4 @container">- <div>- <WarningIcon className="w-5 h-5 shrink-0" />+ <Button asChild type="default" className="ml-8 @md:ml-0">+ <Link href={`/project/${project?.ref}/editor?schema=stripe`}>+ Open Table Editor+ </Link>+ </Button></div>- <div className="flex flex-col items-start @lg:flex-row @lg:items-center gap-4 p-0 m-0">- <div>- <AlertTitle_Shadcn_>- Uninstalling will remove the <code>stripe</code> schema and all synced data.- </AlertTitle_Shadcn_>- <AlertDescription_Shadcn_>This action cannot be undone.</AlertDescription_Shadcn_>- </div>- <div className="mt-2">- <Button- type="default"- onClick={() => setShowUninstallModal(true)}- loading={isUninstalling || isUninstallInitiated}- disabled={isUninstalling || isUninstallInitiated}- >- {isUninstallInitiated ? 'Uninstalling...' : 'Uninstall Stripe Sync Engine'}- </Button>- </div>- </div>- </Alert_Shadcn_>- </PageSectionContent>- </PageSection>- </PageContainer>-- <ConfirmationModal- visible={showUninstallModal}- title="Uninstall Stripe Sync Engine"- confirmLabel="Uninstall"- confirmLabelLoading="Uninstalling..."- variant="destructive"- loading={isUninstalling}- onCancel={() => setShowUninstallModal(false)}- onConfirm={handleUninstall}- >- <p className="text-sm text-foreground-light">- Are you sure you want to uninstall the Stripe Sync Engine? This will:- </p>- <ul className="list-disc pl-5 mt-2 text-sm text-foreground-light space-y-1">- <li>- Remove the <code>stripe</code> schema and all tables- </li>- <li>Delete all synced Stripe data</li>- <li>Remove the associated Edge Functions</li>- <li>Remove the scheduled sync jobs</li>- </ul>- <p className="mt-4 text-sm text-foreground-light font-medium">- This action cannot be undone.- </p>- </ConfirmationModal>- </>+ </CardContent>+ </Card>+ </PageSectionContent>+ </PageSection>+ </PageContainer>)}diff --git a/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/stripe-sync-status.ts b/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/stripe-sync-status.tsnew file mode 100644index 00000000000..190f76ad643--- /dev/null+++ b/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/stripe-sync-status.ts@@ -0,0 +1,136 @@+import type {+ StripeSyncState,+ StripeSyncStateData,+} from 'data/database-integrations/stripe/sync-state-query'+import type { Schema } from 'data/database/schemas-query'+import {+ INSTALLATION_ERROR_SUFFIX,+ INSTALLATION_INSTALLED_SUFFIX,+ INSTALLATION_STARTED_SUFFIX,+ STRIPE_SCHEMA_COMMENT_PREFIX,+} from 'stripe-experiment-sync/supabase'++/**+ * All possible Stripe Sync installation states.+ */+export type StripeInstallationStatus =+ | 'installing'+ | 'installed'+ | 'install_error'+ | 'uninstalling'+ | 'uninstalled'+ | 'uninstall_error'++/**+ * Complete Stripe Sync status including schema, installation state, and sync state+ */+export interface StripeSyncStatusResult {+ /** The installation status */+ installationStatus: StripeInstallationStatus++ /** Current sync run state (only available when installationStatus is installed) */+ syncState: StripeSyncState | undefined++ /** Whether the status is still being determined (schemas query is loading) */+ isLoading: boolean+}++// TODO: The current version of the package 'stripe-experiment-sync' doesn't export+// these constants, but we plan to export them in future version. For now we+// declare the same constants here to deploy this code without waiting for+// a new version. We'll import them when we bump 'stripe-experiment-sync' package+// version.+const UNINSTALLATION_STARTED_SUFFIX = 'uninstallation:started'+const UNINSTALLATION_ERROR_SUFFIX = 'uninstallation:error'++export function findStripeSchema(schemas: Schema[] | undefined): Schema | undefined {+ return schemas?.find((s) => s.name === 'stripe')+}++function isStripeSyncSchema(schema: Schema | undefined): boolean {+ return !!schema?.comment?.startsWith(STRIPE_SCHEMA_COMMENT_PREFIX)+}++function hasStatusSuffix(schema: Schema | undefined, suffix: string): boolean {+ return isStripeSyncSchema(schema) && !!schema?.comment?.endsWith(suffix)+}++/**+ * Parse the installation status from a stripe schema.+ *+ * @param stripeSchema - The stripe schema from the database, if it exists+ * @returns The installation status+ */+export function parseStripeSchemaStatus(+ stripeSchema: Schema | undefined+): StripeInstallationStatus {+ if (hasStatusSuffix(stripeSchema, UNINSTALLATION_ERROR_SUFFIX)) {+ return 'uninstall_error'+ }++ if (hasStatusSuffix(stripeSchema, INSTALLATION_ERROR_SUFFIX)) {+ return 'install_error'+ }++ if (hasStatusSuffix(stripeSchema, UNINSTALLATION_STARTED_SUFFIX)) {+ return 'uninstalling'+ }++ if (hasStatusSuffix(stripeSchema, INSTALLATION_STARTED_SUFFIX)) {+ return 'installing'+ }++ if (hasStatusSuffix(stripeSchema, INSTALLATION_INSTALLED_SUFFIX)) {+ return 'installed'+ }++ return 'uninstalled'+}++export function isInstalled(status: StripeInstallationStatus): boolean {+ return status === 'installed'+}++export function isUninstalled(status: StripeInstallationStatus): boolean {+ return status === 'uninstalled'+}++export function hasInstallError(status: StripeInstallationStatus): boolean {+ return status === 'install_error'+}++export function hasUninstallError(status: StripeInstallationStatus): boolean {+ return status === 'uninstall_error'+}++export function hasError(status: StripeInstallationStatus): boolean {+ return hasInstallError(status) || hasUninstallError(status)+}++export function isInstalling(status: StripeInstallationStatus): boolean {+ return status === 'installing'+}++export function isUninstalling(status: StripeInstallationStatus): boolean {+ return status === 'uninstalling'+}++export function isInProgress(status: StripeInstallationStatus): boolean {+ return isInstalling(status) || isUninstalling(status)+}++export function isInstallDone(status: StripeInstallationStatus): boolean {+ return isInstalled(status) || hasInstallError(status)+}++export function isUninstallDone(status: StripeInstallationStatus): boolean {+ return isUninstalled(status) || hasUninstallError(status)+}++export function canInstall(status: StripeInstallationStatus): boolean {+ return isUninstalled(status) || hasError(status)+}++export function isSyncRunning(syncState: StripeSyncStateData | undefined): boolean {+ return !!syncState && !syncState.closed_at && syncState.status === 'running'+}diff --git a/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/useStripeSyncStatus.ts b/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/useStripeSyncStatus.tsnew file mode 100644index 00000000000..a28f8405984--- /dev/null+++ b/apps/studio/components/interfaces/Integrations/templates/StripeSyncEngine/useStripeSyncStatus.ts@@ -0,0 +1,65 @@+import { useStripeSyncingState } from 'data/database-integrations/stripe/sync-state-query'+import { SchemasVariables, useSchemasQuery } from 'data/database/schemas-query'+import { useEffect } from 'react'++import {+ findStripeSchema,+ isInProgress,+ isInstalled,+ parseStripeSchemaStatus,+ type StripeSyncStatusResult,+} from '@/components/interfaces/Integrations/templates/StripeSyncEngine/stripe-sync-status'++/**+ * Unified hook for Stripe Sync installation status.+ *+ * This hook consolidates all schema querying, status parsing, and polling logic+ * into a single source of truth. It returns a discriminated union status that+ * makes impossible states unrepresentable.+ */+export function useStripeSyncStatus({+ projectRef,+ connectionString,+}: SchemasVariables): StripeSyncStatusResult {+ // Query schemas once+ const {+ data: schemas,+ isLoading: isSchemasLoading,+ refetch,+ } = useSchemasQuery({ projectRef, connectionString }, { enabled: !!projectRef })++ // Find and parse stripe schema status+ const stripeSchema = findStripeSchema(schemas)+ const installationStatus = parseStripeSchemaStatus(stripeSchema)++ const installed = isInstalled(installationStatus)+ const inProgress = isInProgress(installationStatus)++ // Poll schemas during install/uninstall operations+ useEffect(() => {+ // Return if installation/uninstallation is not in progress+ // inProgres is likely to be false during initial render+ if (!inProgress) return++ const interval = setInterval(() => {+ refetch()+ }, 5000)++ return () => clearInterval(interval)+ }, [inProgress, refetch])++ // Query sync state only when installed+ const { data: syncState, isLoading: isSyncStateLoading } = useStripeSyncingState(+ { projectRef: projectRef!, connectionString },+ {+ refetchInterval: 4000,+ enabled: !!projectRef && installed,+ }+ )++ return {+ installationStatus,+ syncState: installed ? syncState : undefined,+ isLoading: isSchemasLoading,+ }+}diff --git a/apps/studio/pages/api/integrations/stripe-sync.ts b/apps/studio/pages/api/integrations/stripe-sync.tsindex e88c53f5b28..0c355302027 100644--- a/apps/studio/pages/api/integrations/stripe-sync.ts+++ b/apps/studio/pages/api/integrations/stripe-sync.ts@@ -1,8 +1,8 @@+import { waitUntil } from '@vercel/functions'import { NextApiRequest, NextApiResponse } from 'next'-import { z } from 'zod'-import { install, uninstall } from 'stripe-experiment-sync/supabase'import { VERSION } from 'stripe-experiment-sync'-import { waitUntil } from '@vercel/functions'+import { install, uninstall } from 'stripe-experiment-sync/supabase'+import { z } from 'zod'const ENABLE_FLAG_KEY = 'enableStripeSyncEngineIntegration'@@ -112,7 +112,7 @@ async function handleSetupStripeSyncInstall(req: NextApiRequest, res: NextApiReserrorData.error?.message || `Invalid Stripe API key (HTTP ${stripeResponse.status})`return res.status(400).json({data: null,- error: { message: `Invalid Stripe API key: ${errorMessage}` },+ error: { message: errorMessage },})}} catch (error: any) {