Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: add edge function secret installation method (#45826)

Raminder Singh897043952ab3
diff --git a/apps/studio/components/interfaces/Integrations/Integration/IntegrationOverviewTabV2/InstallIntegrationSheet/InstallOAuthIntegrationButton.tsx b/apps/studio/components/interfaces/Integrations/Integration/IntegrationOverviewTabV2/InstallIntegrationSheet/InstallOAuthIntegrationButton.tsx
index fb08a5e10c6..c2e5241fe42 100644
--- a/apps/studio/components/interfaces/Integrations/Integration/IntegrationOverviewTabV2/InstallIntegrationSheet/InstallOAuthIntegrationButton.tsx
+++ b/apps/studio/components/interfaces/Integrations/Integration/IntegrationOverviewTabV2/InstallIntegrationSheet/InstallOAuthIntegrationButton.tsx
@@ -6,6 +6,7 @@ import { Button } from 'ui'
import type { IntegrationDefinition } from '@/components/interfaces/Integrations/Landing/Integrations.constants'
import { useAPIKeysQuery } from '@/data/api-keys/api-keys-query'
import { useInstallOAuthIntegrationMutation } from '@/data/marketplace/install-oauth-integration-mutation'
+import { useSecretsQuery } from '@/data/secrets/secrets-query'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
interface InstallOAuthIntegrationButtonProps {
@@ -16,9 +17,21 @@ export function InstallOAuthIntegrationButton({ integration }: InstallOAuthInteg
const { ref: projectRef } = useParams()
const { data: selectedOrg } = useSelectedOrganizationQuery()
+ const requiresApiKeysCheck =
+ integration.installIdentificationMethod === 'secret_key_prefix' && !!integration.secretKeyPrefix
+
+ const requiresEdgeFunctionSecretsCheck =
+ integration.installIdentificationMethod === 'edge_function_secret_name' &&
+ !!integration.edgeFunctionSecretName
+
const { data: apiKeys, isLoading: isApiKeysLoading } = useAPIKeysQuery(
{ projectRef, reveal: false },
- { enabled: !!projectRef }
+ { enabled: requiresApiKeysCheck }
+ )
+
+ const { data: edgeFunctionSecrets, isPending: isEdgeFunctionSecretsLoading } = useSecretsQuery(
+ { projectRef },
+ { enabled: requiresEdgeFunctionSecretsCheck }
)
const { mutate: installOAuthIntegration, isPending: isInstalling } =
@@ -37,18 +50,26 @@ export function InstallOAuthIntegrationButton({ integration }: InstallOAuthInteg
})
const isLoading =
- integration.installIdentificationMethod === 'secret_key_prefix' && isApiKeysLoading
+ (requiresApiKeysCheck && isApiKeysLoading) ||
+ (requiresEdgeFunctionSecretsCheck && isEdgeFunctionSecretsLoading)
const isIntegrationInstalled = useMemo(() => {
if (!integration) return false
- const prefix = integration.secretKeyPrefix
+ if (integration.installIdentificationMethod === 'secret_key_prefix') {
+ const prefix = integration.secretKeyPrefix
+ if (!prefix || isApiKeysLoading || !apiKeys) return false
+ return apiKeys.some((k) => k.type === 'secret' && k.name.startsWith(prefix))
+ }
- if (integration.installIdentificationMethod !== 'secret_key_prefix' || !prefix) return false
- if (isApiKeysLoading || !apiKeys) return false
+ if (integration.installIdentificationMethod === 'edge_function_secret_name') {
+ const secretName = integration.edgeFunctionSecretName
+ if (!secretName || isEdgeFunctionSecretsLoading || !edgeFunctionSecrets) return false
+ return edgeFunctionSecrets.some((secret) => secret.name === secretName)
+ }
- return apiKeys.some((k) => k.type === 'secret' && k.name.startsWith(prefix))
- }, [apiKeys, integration, isApiKeysLoading])
+ return false
+ }, [apiKeys, edgeFunctionSecrets, integration, isApiKeysLoading, isEdgeFunctionSecretsLoading])
const handleInstallClick = async () => {
if (!integration || !projectRef) return
diff --git a/apps/studio/components/interfaces/Integrations/Landing/Integrations.constants.tsx b/apps/studio/components/interfaces/Integrations/Landing/Integrations.constants.tsx
index cf56fec2524..c70895c6f55 100644
--- a/apps/studio/components/interfaces/Integrations/Landing/Integrations.constants.tsx
+++ b/apps/studio/components/interfaces/Integrations/Landing/Integrations.constants.tsx
@@ -1,4 +1,5 @@
import { getEnableWebhooksSQL } from '@supabase/pg-meta'
+import type { Tables } from 'common/marketplace.types'
import { Clock5, Code2, Layers, Timer, Vault, Webhook } from 'lucide-react'
import dynamic from 'next/dynamic'
import Image from 'next/image'
@@ -46,9 +47,9 @@ type IntegrationStep = {
description?: string
}
-type InstallUrlType = 'get' | 'post'
-
-type InstallIdentificationMethod = 'secret_key_prefix'
+type Listing = Tables<'listings'>
+type InstallUrlType = NonNullable<Listing['installation_url_type']>
+type InstallIdentificationMethod = NonNullable<Listing['installation_identification_method']>
/**
* [Joshen] For marketplace, we probably need to revisit this definition
@@ -108,6 +109,7 @@ export type IntegrationDefinition = {
installUrlType?: InstallUrlType
installIdentificationMethod?: InstallIdentificationMethod
secretKeyPrefix?: string
+ edgeFunctionSecretName?: string
listingId?: string
} & (
| { type: 'wrapper'; meta: WrapperMeta }
diff --git a/apps/studio/components/interfaces/Integrations/Landing/Landing.utils.ts b/apps/studio/components/interfaces/Integrations/Landing/Landing.utils.ts
new file mode 100644
index 00000000000..2fc1c9fe088
--- /dev/null
+++ b/apps/studio/components/interfaces/Integrations/Landing/Landing.utils.ts
@@ -0,0 +1,63 @@
+import { parseSchemaComment } from 'stripe-experiment-sync/supabase'
+
+import { type WrapperMeta } from '../Wrappers/Wrappers.types'
+import { wrapperMetaComparator } from '../Wrappers/Wrappers.utils'
+import { type IntegrationDefinition } from './Integrations.constants'
+import {
+ isInstalled as checkIsInstalled,
+ findStripeSchema,
+} from '@/components/interfaces/Integrations/templates/StripeSyncEngine/stripe-sync-status'
+import { type APIKey } from '@/data/api-keys/api-keys-query'
+import { type DatabaseExtension } from '@/data/database-extensions/database-extensions-query'
+import { type Schema } from '@/data/database/schemas-query'
+import { type FDW } from '@/data/fdw/fdws-query'
+import { type ProjectSecret } from '@/data/secrets/secrets-query'
+
+export const isStripeSyncEngineInstalled = (schemas: Schema[]) => {
+ const stripeSchema = findStripeSchema(schemas)
+ const parsedSchema = parseSchemaComment(stripeSchema?.comment)
+ return checkIsInstalled(parsedSchema.status)
+}
+
+export const isOAuthInstalled = ({
+ integration,
+ apiKeys,
+ secrets,
+}: {
+ integration: IntegrationDefinition
+ apiKeys: APIKey[]
+ secrets: ProjectSecret[]
+}) => {
+ if (integration.installIdentificationMethod === 'secret_key_prefix') {
+ const prefix = integration.secretKeyPrefix
+ if (!prefix) return false
+
+ return apiKeys.some((key) => key.type === 'secret' && key.name.startsWith(prefix))
+ }
+
+ if (integration.installIdentificationMethod === 'edge_function_secret_name') {
+ const secretName = integration.edgeFunctionSecretName
+ if (!secretName) return false
+
+ return secrets.some((secret) => secret.name === secretName)
+ }
+
+ return false
+}
+
+export const hasMatchingWrapper = ({ meta, wrappers }: { meta: WrapperMeta; wrappers: FDW[] }) => {
+ return wrappers.find((w) => wrapperMetaComparator(meta, w))
+}
+
+export const hasRequiredExtensions = ({
+ integration,
+ extensions,
+}: {
+ integration: IntegrationDefinition
+ extensions: DatabaseExtension[]
+}) => {
+ return integration.requiredExtensions.every((extName) => {
+ const foundExtension = extensions.find((ext) => ext.name === extName)
+ return !!foundExtension?.installed_version
+ })
+}
diff --git a/apps/studio/components/interfaces/Integrations/Landing/useAvailableIntegrations.tsx b/apps/studio/components/interfaces/Integrations/Landing/useAvailableIntegrations.tsx
index bfb48fcc6b7..1b62826f164 100644
--- a/apps/studio/components/interfaces/Integrations/Landing/useAvailableIntegrations.tsx
+++ b/apps/studio/components/interfaces/Integrations/Landing/useAvailableIntegrations.tsx
@@ -51,6 +51,7 @@ export const useAvailableIntegrations = () => {
installation_url_type: installUrlType,
installation_identification_method: installMethod,
secret_key_prefix: secretKeyPrefix,
+ edge_function_secret_name: edgeFunctionSecretName,
images,
content,
partner_name: authorName,
@@ -78,6 +79,7 @@ export const useAvailableIntegrations = () => {
installUrlType: installUrlType ?? undefined,
installIdentificationMethod: installMethod ?? undefined,
secretKeyPrefix: secretKeyPrefix ?? undefined,
+ edgeFunctionSecretName: edgeFunctionSecretName ?? undefined,
listingId: listingId ?? undefined,
author,
requiredExtensions: [],
diff --git a/apps/studio/components/interfaces/Integrations/Landing/useInstalledIntegrations.tsx b/apps/studio/components/interfaces/Integrations/Landing/useInstalledIntegrations.tsx
index 026c54e41fa..9c1326e3601 100644
--- a/apps/studio/components/interfaces/Integrations/Landing/useInstalledIntegrations.tsx
+++ b/apps/studio/components/interfaces/Integrations/Landing/useInstalledIntegrations.tsx
@@ -1,21 +1,23 @@
import { useMemo } from 'react'
-import { parseSchemaComment } from 'stripe-experiment-sync/supabase'
-import { wrapperMetaComparator } from '../Wrappers/Wrappers.utils'
-import { useAvailableIntegrations } from './useAvailableIntegrations'
import {
- isInstalled as checkIsInstalled,
- findStripeSchema,
-} from '@/components/interfaces/Integrations/templates/StripeSyncEngine/stripe-sync-status'
+ hasMatchingWrapper,
+ hasRequiredExtensions,
+ isOAuthInstalled,
+ isStripeSyncEngineInstalled,
+} from './Landing.utils'
+import { useAvailableIntegrations } from './useAvailableIntegrations'
import { useAPIKeysQuery } from '@/data/api-keys/api-keys-query'
import { useDatabaseExtensionsQuery } from '@/data/database-extensions/database-extensions-query'
import { useSchemasQuery } from '@/data/database/schemas-query'
import { useFDWsQuery } from '@/data/fdw/fdws-query'
+import { useSecretsQuery } from '@/data/secrets/secrets-query'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { EMPTY_ARR } from '@/lib/void'
export const useInstalledIntegrations = () => {
const { data: project } = useSelectedProjectQuery()
+
const {
data: allIntegrations = EMPTY_ARR,
error: availableIntegrationsError,
@@ -33,19 +35,39 @@ export const useInstalledIntegrations = () => {
)
}, [allIntegrations])
+ const hasEdgeFunctionSecretNameIntegration = useMemo(() => {
+ return allIntegrations.some(
+ (integration) =>
+ integration.type === 'oauth' &&
+ integration.installIdentificationMethod === 'edge_function_secret_name' &&
+ !!integration.edgeFunctionSecretName
+ )
+ }, [allIntegrations])
+
const {
- data: apiKeys,
+ data: apiKeys = EMPTY_ARR,
error: apiKeysError,
isError: isErrorApiKeys,
isLoading: isApiKeysLoading,
isSuccess: isSuccessApiKeys,
} = useAPIKeysQuery(
{ projectRef: project?.ref, reveal: false },
- { enabled: !!project?.ref && hasSecretKeyPrefixIntegration }
+ { enabled: hasSecretKeyPrefixIntegration }
+ )
+
+ const {
+ data: edgeFunctionSecrets = EMPTY_ARR,
+ error: edgeFunctionSecretsError,
+ isError: isErrorEdgeFunctionSecrets,
+ isLoading: isEdgeFunctionSecretsLoading,
+ isSuccess: isSuccessEdgeFunctionSecrets,
+ } = useSecretsQuery(
+ { projectRef: project?.ref },
+ { enabled: hasEdgeFunctionSecretNameIntegration }
)
const {
- data,
+ data: wrappers = EMPTY_ARR,
error: fdwError,
isError: isErrorFDWs,
isPending: isFDWLoading,
@@ -55,7 +77,7 @@ export const useInstalledIntegrations = () => {
connectionString: project?.connectionString,
})
const {
- data: extensions,
+ data: extensions = EMPTY_ARR,
error: extensionsError,
isError: isErrorExtensions,
isPending: isExtensionsLoading,
@@ -66,7 +88,7 @@ export const useInstalledIntegrations = () => {
})
const {
- data: schemas,
+ data: schemas = EMPTY_ARR,
error: schemasError,
isError: isErrorSchemas,
isPending: isSchemasLoading,
@@ -77,70 +99,57 @@ export const useInstalledIntegrations = () => {
})
const isHooksEnabled = schemas?.some((schema) => schema.name === 'supabase_functions')
- const wrappers = useMemo(() => data ?? EMPTY_ARR, [data])
const installedIntegrations = useMemo(() => {
return allIntegrations
.filter((integration) => {
- // special handling for supabase webhooks
- if (integration.id === 'webhooks') {
- return isHooksEnabled
- }
- if (integration.id === 'data_api') {
- return true
- }
+ if (integration.id === 'webhooks') return isHooksEnabled
+ if (integration.id === 'data_api') return true
if (integration.id === 'stripe_sync_engine') {
- const stripeSchema = findStripeSchema(schemas)
- const parsedSchema = parseSchemaComment(stripeSchema?.comment)
- return checkIsInstalled(parsedSchema.status)
+ return isStripeSyncEngineInstalled(schemas)
}
if (integration.type === 'wrapper') {
- return wrappers.find((w) => wrapperMetaComparator(integration.meta, w))
+ return hasMatchingWrapper({ meta: integration.meta, wrappers })
}
if (integration.type === 'postgres_extension') {
- return integration.requiredExtensions.every((extName) => {
- const foundExtension = (extensions ?? []).find((ext) => ext.name === extName)
- return !!foundExtension?.installed_version
- })
+ return hasRequiredExtensions({ integration, extensions })
}
if (integration.type === 'oauth') {
- const prefix = integration.secretKeyPrefix
-
- if (integration.installIdentificationMethod !== 'secret_key_prefix' || !prefix) {
- return false
- }
-
- return (apiKeys ?? []).some((key) => key.type === 'secret' && key.name.startsWith(prefix))
+ return isOAuthInstalled({ integration, apiKeys, secrets: edgeFunctionSecrets })
}
return false
})
.sort((a, b) => a.name.localeCompare(b.name))
- }, [allIntegrations, wrappers, extensions, schemas, isHooksEnabled, apiKeys])
+ }, [allIntegrations, wrappers, extensions, schemas, isHooksEnabled, apiKeys, edgeFunctionSecrets])
const error =
fdwError ||
extensionsError ||
schemasError ||
availableIntegrationsError ||
- (hasSecretKeyPrefixIntegration ? apiKeysError : null)
+ (hasSecretKeyPrefixIntegration ? apiKeysError : null) ||
+ (hasEdgeFunctionSecretNameIntegration ? edgeFunctionSecretsError : null)
const isLoading =
isSchemasLoading ||
isFDWLoading ||
isExtensionsLoading ||
isAvailableIntegrationsLoading ||
- (hasSecretKeyPrefixIntegration && isApiKeysLoading)
+ (hasSecretKeyPrefixIntegration && isApiKeysLoading) ||
+ (hasEdgeFunctionSecretNameIntegration && isEdgeFunctionSecretsLoading)
const isError =
isErrorFDWs ||
isErrorExtensions ||
isErrorSchemas ||
isErrorAvailableIntegrations ||
- (hasSecretKeyPrefixIntegration && isErrorApiKeys)
+ (hasSecretKeyPrefixIntegration && isErrorApiKeys) ||
+ (hasEdgeFunctionSecretNameIntegration && isErrorEdgeFunctionSecrets)
const isSuccess =
isSuccessFDWs &&
isSuccessExtensions &&
isSuccessSchemas &&
isSuccessAvailableIntegrations &&
- (!hasSecretKeyPrefixIntegration || isSuccessApiKeys)
+ (!hasSecretKeyPrefixIntegration || isSuccessApiKeys) &&
+ (!hasEdgeFunctionSecretNameIntegration || isSuccessEdgeFunctionSecrets)
return {
// show all integrations at once instead of showing partial results
diff --git a/apps/studio/data/api-keys/api-keys-query.ts b/apps/studio/data/api-keys/api-keys-query.ts
index bf18a6f1d32..be0f873b947 100644
--- a/apps/studio/data/api-keys/api-keys-query.ts
+++ b/apps/studio/data/api-keys/api-keys-query.ts
@@ -48,7 +48,7 @@ interface APIKeysVariables {
reveal?: boolean
}
-type APIKey = LegacyKeys | SecretKeys | PublishableKeys
+export type APIKey = LegacyKeys | SecretKeys | PublishableKeys
async function getAPIKeys({ projectRef, reveal }: APIKeysVariables, signal?: AbortSignal) {
if (!projectRef) throw new Error('projectRef is required')
diff --git a/packages/common/marketplace.types.ts b/packages/common/marketplace.types.ts
index 6354bd0852a..bd7441796df 100644
--- a/packages/common/marketplace.types.ts
+++ b/packages/common/marketplace.types.ts
@@ -34,13 +34,18 @@ export type Database = {
content: string | null
description: string | null
documentation_url: string | null
+ edge_function_secret_name: string | null
featured: boolean | null
id: string | null
images: string[] | null
- installation_identification_method: 'secret_key_prefix' | null
+ installation_identification_method:
+ | 'secret_key_prefix'
+ | 'edge_function_secret_name'
+ | null
installation_url: string | null
installation_url_type: 'get' | 'post' | null
listing_logo: string | null
+ listing_tsv: unknown
marketplace_url: string | null
partner_logo: string | null
partner_name: string | null