The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
feat(studio): move data api docs to integrations section (#42749)
Charisf7bf7d7ce459
diff --git a/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/index.tsx b/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/index.tsxindex 19c0031b096..a2ef83a4e49 100644--- a/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/index.tsx+++ b/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/index.tsx@@ -1,12 +1,7 @@import type { PostgresPolicy } from '@supabase/postgres-meta'+import { useParams } from 'common'import { noop } from 'lodash'import { memo, useMemo } from 'react'--import { useParams } from 'common'-import AlertError from 'components/ui/AlertError'-import { InlineLink } from 'components/ui/InlineLink'-import { useTablesRolesAccessQuery } from 'data/tables/tables-roles-access-query'-import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'import {Card,CardContent,@@ -20,10 +15,15 @@ import {} from 'ui'import { Admonition } from 'ui-patterns'import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'+import { usePoliciesData } from '../PoliciesDataContext'import { PolicyRow } from './PolicyRow'import type { PolicyTable } from './PolicyTableRow.types'import { PolicyTableRowHeader } from './PolicyTableRowHeader'+import AlertError from '@/components/ui/AlertError'+import { InlineLink } from '@/components/ui/InlineLink'+import { useTablesRolesAccessQuery } from '@/data/tables/tables-roles-access-query'+import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'export interface PolicyTableRowProps {table: PolicyTable@@ -120,7 +120,10 @@ const PolicyTableRowComponent = ({<p className="text-foreground-light">No data will be selectable via Supabase APIs as this schema is not exposed. You mayconfigure this in your project’s{' '}- <InlineLink href={`/project/${ref}/settings/api`}>API settings</InlineLink>.+ <InlineLink href={`/project/${ref}/integrations/data_api/settings`}>+ API settings+ </InlineLink>+ .</p></Admonition>)}diff --git a/apps/studio/components/interfaces/Docs/Authentication.tsx b/apps/studio/components/interfaces/Docs/Authentication.tsxindex 88a063b844d..aa4d72d1668 100644--- a/apps/studio/components/interfaces/Docs/Authentication.tsx+++ b/apps/studio/components/interfaces/Docs/Authentication.tsx@@ -1,12 +1,13 @@import { PermissionAction } from '@supabase/shared-types/out/constants'-import Link from 'next/link'-import { useParams } from 'common'-import { getKeys, useAPIKeysQuery } from 'data/api-keys/api-keys-query'-import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'-import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'+import CodeSnippet from './CodeSnippet'+import { DocSection } from './DocSection'import Snippets from './Snippets'+import { InlineLink } from '@/components/ui/InlineLink'+import { getKeys, useAPIKeysQuery } from '@/data/api-keys/api-keys-query'+import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query'+import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'interface AuthenticationProps {selectedLang: 'bash' | 'js'@@ -35,83 +36,102 @@ const Authentication = ({ selectedLang, showApiKey }: AuthenticationProps) => {: 'SUPABASE_SERVICE_KEY'return (- <>- <h2 className="doc-heading">Authentication</h2>- <div className="doc-section">- <article className="code-column text-foreground">- <p>Supabase works through a mixture of JWT and Key auth.</p>- <p>- If no <code>Authorization</code> header is included, the API will assume that you are- making a request with an anonymous user.- </p>- <p>- If an <code>Authorization</code> header is included, the API will "switch" to the role- of the user making the request. See the User Management section for more details.- </p>- <p>We recommend setting your keys as Environment Variables.</p>- </article>- </div>+ <div className="flex flex-col flex-1">+ <DocSection+ title="Authentication"+ content={+ <>+ <p>Supabase works through a mixture of JWT and Key auth.</p>+ <p>+ If no <code>Authorization</code> header is included, the API will assume that you are+ making a request with an anonymous user.+ </p>+ <p>+ If an <code>Authorization</code> header is included, the API will "switch" to the role+ of the user making the request. See the User Management section for more details.+ </p>+ <p>We recommend setting your keys as Environment Variables.</p>+ </>+ }+ />- <h2 className="doc-heading">Client API Keys</h2>- <div className="doc-section">- <article className="code-column text-foreground">- <p>- Client keys allow "anonymous access" to your database, until the user has logged in.- After logging in the keys will switch to the user's own login token.- </p>- <p>- In this documentation, we will refer to the key using the name <code>SUPABASE_KEY</code>- .- </p>- <p>- We have provided you a Client Key to get started. You will soon be able to add as many- keys as you like. You can find the <code>anon</code> key in the{' '}- <Link href={`/project/${projectRef}/settings/api`}>API Settings</Link> page.- </p>- </article>- <article className="code">- <CodeSnippet- selectedLang={selectedLang}- snippet={Snippets.authKey('CLIENT API KEY', 'SUPABASE_KEY', defaultApiKey)}- />- <CodeSnippet- selectedLang={selectedLang}- snippet={Snippets.authKeyExample(defaultApiKey, endpoint, {- showBearer: false,- })}- />- </article>- </div>+ <DocSection+ title="Client API Keys"+ content={+ <>+ <p>+ Client keys allow "anonymous access" to your database, until the user has logged in.+ After logging in the keys will switch to the user's own login token.+ </p>+ <p>+ In this documentation, we will refer to the key using the name{' '}+ <code>SUPABASE_KEY</code>.+ </p>+ <p>+ We have provided you a Client Key to get started. You will soon be able to add as many+ keys as you like. You can find the <code>anon</code> key in the{' '}+ <InlineLink href={`/project/${projectRef}/settings/api-keys`}>+ API Keys Settings+ </InlineLink>{' '}+ page.+ </p>+ </>+ }+ snippets={+ <>+ <CodeSnippet+ selectedLang={selectedLang}+ snippet={Snippets.authKey('CLIENT API KEY', 'SUPABASE_KEY', defaultApiKey)}+ />+ <CodeSnippet+ selectedLang={selectedLang}+ snippet={Snippets.authKeyExample(defaultApiKey, endpoint, {+ showBearer: false,+ })}+ />+ </>+ }+ />- <h2 className="doc-heading">Service Keys</h2>- <div className="doc-section">- <article className="code-column text-foreground">- <p>- Service keys have FULL access to your data, bypassing any security policies. Be VERY- careful where you expose these keys. They should only be used on a server and never on a- client or browser.- </p>- <p>- In this documentation, we will refer to the key using the name <code>SERVICE_KEY</code>.- </p>- <p>- We have provided you with a Service Key to get started. Soon you will be able to add as- many keys as you like. You can find the <code>service_role</code> in the{' '}- <Link href={`/project/${projectRef}/settings/api`}>API Settings</Link> page.- </p>- </article>- <article className="code">- <CodeSnippet- selectedLang={selectedLang}- snippet={Snippets.authKey('SERVICE KEY', 'SERVICE_KEY', serviceApiKey)}- />- <CodeSnippet- selectedLang={selectedLang}- snippet={Snippets.authKeyExample(serviceApiKey, endpoint, { keyName: 'SERVICE_KEY' })}- />- </article>- </div>- </>+ <DocSection+ title="Service Keys"+ content={+ <>+ <p>+ Service keys have FULL access to your data, bypassing any security policies. Be VERY+ careful where you expose these keys. They should only be used on a server and never on+ a client or browser.+ </p>+ <p>+ In this documentation, we will refer to the key using the name{' '}+ <code>SERVICE_KEY</code>.+ </p>+ <p>+ We have provided you with a Service Key to get started. Soon you will be able to add+ as many keys as you like. You can find the <code>service_role</code> in the{' '}+ <InlineLink href={`/project/${projectRef}/settings/api-keys`}>+ API Keys Settings+ </InlineLink>{' '}+ page.+ </p>+ </>+ }+ snippets={+ <>+ <CodeSnippet+ selectedLang={selectedLang}+ snippet={Snippets.authKey('SERVICE KEY', 'SERVICE_KEY', serviceApiKey)}+ />+ <CodeSnippet+ selectedLang={selectedLang}+ snippet={Snippets.authKeyExample(serviceApiKey, endpoint, {+ keyName: 'SERVICE_KEY',+ })}+ />+ </>+ }+ />+ </div>)}diff --git a/apps/studio/components/interfaces/Docs/CodeSnippet.tsx b/apps/studio/components/interfaces/Docs/CodeSnippet.tsxindex fe2db105f64..daa780fc026 100644--- a/apps/studio/components/interfaces/Docs/CodeSnippet.tsx+++ b/apps/studio/components/interfaces/Docs/CodeSnippet.tsx@@ -1,8 +1,9 @@import { useParams } from 'common'-import { useSendEventMutation } from 'data/telemetry/send-event-mutation'-import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'import { SimpleCodeBlock } from 'ui'+import { useSendEventMutation } from '@/data/telemetry/send-event-mutation'+import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'+interface CodeSnippetProps {selectedLang: 'bash' | 'js'snippet: {@@ -33,11 +34,13 @@ const CodeSnippet = ({ selectedLang, snippet }: CodeSnippetProps) => {if (!snippet[selectedLang]) return nullreturn (- <div className="codeblock-container">- <h4>{snippet.title}</h4>- <SimpleCodeBlock className={snippet[selectedLang]?.language} onCopy={handleCopy}>- {snippet[selectedLang]?.code}- </SimpleCodeBlock>+ <div>+ <h4 className="heading-default mb-2">{snippet.title}</h4>+ <div className="[&_.codeBlock]:p-0 [&_.token-line]:text-sm">+ <SimpleCodeBlock className={snippet[selectedLang]?.language} onCopy={handleCopy}>+ {snippet[selectedLang]?.code}+ </SimpleCodeBlock>+ </div></div>)}diff --git a/apps/studio/components/interfaces/Docs/DocSection.tsx b/apps/studio/components/interfaces/Docs/DocSection.tsxnew file mode 100644index 00000000000..00da8e39756--- /dev/null+++ b/apps/studio/components/interfaces/Docs/DocSection.tsx@@ -0,0 +1,24 @@+import { ReactNode } from 'react'+import { cn } from 'ui'++interface DocSectionProps {+ title: ReactNode+ id?: string+ content: ReactNode+ snippets?: ReactNode+ className?: string+}++export const DocSection = ({ title, id, content, snippets, className }: DocSectionProps) => {+ return (+ <div className={cn('grid grid-cols-1 lg:grid-cols-2 border-b', className)} id={id}>+ <article className="text-foreground-light prose prose-sm p-6 lg:py-10 lg:pr-10 lg:pl-0 flex-1">+ {title && <h2 className="heading-subTitle mb-4">{title}</h2>}+ {content}+ </article>+ <article className={cn('bg flex-1 lg:border-l space-y-6 px-6 pb-6 lg:py-10')}>+ {snippets}+ </article>+ </div>+ )+}diff --git a/apps/studio/components/interfaces/Docs/Docs.types.ts b/apps/studio/components/interfaces/Docs/Docs.types.tsindex 7ea36375c90..200dcb6f7c1 100644--- a/apps/studio/components/interfaces/Docs/Docs.types.ts+++ b/apps/studio/components/interfaces/Docs/Docs.types.ts@@ -1,4 +1,4 @@-export type showApiKey = {+export type ShowApiKey = {key: stringname: string}diff --git a/apps/studio/components/interfaces/Docs/GeneralContent.tsx b/apps/studio/components/interfaces/Docs/GeneralContent.tsxindex 72be21d3d76..bb428100c35 100644--- a/apps/studio/components/interfaces/Docs/GeneralContent.tsx+++ b/apps/studio/components/interfaces/Docs/GeneralContent.tsx@@ -1,8 +1,9 @@-import Authentication from 'components/interfaces/Docs/Authentication'-import Introduction from 'components/interfaces/Docs/Introduction'-import RpcIntroduction from 'components/interfaces/Docs/Pages/Rpc/Introduction'-import TablesIntroduction from 'components/interfaces/Docs/Pages/Tables/Introduction'-import { UserManagement } from 'components/interfaces/Docs/Pages/UserManagement'+import { DocSection } from './DocSection'+import Authentication from '@/components/interfaces/Docs/Authentication'+import Introduction from '@/components/interfaces/Docs/Introduction'+import RpcIntroduction from '@/components/interfaces/Docs/Pages/Rpc/Introduction'+import TablesIntroduction from '@/components/interfaces/Docs/Pages/Tables/Introduction'+import { UserManagement } from '@/components/interfaces/Docs/Pages/UserManagement'interface GeneralContentProps {page?: string@@ -21,9 +22,9 @@ export const GeneralContent = ({ selectedLang, page, showApiKey }: GeneralContenif (selected == 'rpc-intro') return <RpcIntroduction />elsereturn (- <div>- <h2 className="m-4">Not found</h2>- <p className="m-4"> Looks like you went somewhere that nobody knows.</p>- </div>+ <DocSection+ title="Not found"+ content={<p>Looks like you went somewhere that nobody knows.</p>}+ />)}diff --git a/apps/studio/components/interfaces/Docs/GeneratingTypes.tsx b/apps/studio/components/interfaces/Docs/GeneratingTypes.tsxindex 6605631c78e..9460c6d2e44 100644--- a/apps/studio/components/interfaces/Docs/GeneratingTypes.tsx+++ b/apps/studio/components/interfaces/Docs/GeneratingTypes.tsx@@ -1,21 +1,22 @@+import { useParams } from 'common'import { Download } from 'lucide-react'-import Link from 'next/link'import { useState } from 'react'import { toast } from 'sonner'--import { useParams } from 'common'-import CodeSnippet from 'components/interfaces/Docs/CodeSnippet'-import { DocsButton } from 'components/ui/DocsButton'-import { useProjectPostgrestConfigQuery } from 'data/config/project-postgrest-config-query'-import { generateTypes } from 'data/projects/project-type-generation-query'-import { DOCS_URL } from 'lib/constants'import { Button } from 'ui'+import { DocSection } from './DocSection'+import CodeSnippet from '@/components/interfaces/Docs/CodeSnippet'+import { DocsButton } from '@/components/ui/DocsButton'+import { InlineLink } from '@/components/ui/InlineLink'+import { useProjectPostgrestConfigQuery } from '@/data/config/project-postgrest-config-query'+import { generateTypes } from '@/data/projects/project-type-generation-query'+import { DOCS_URL } from '@/lib/constants'+interface Props {selectedLang: 'bash' | 'js'}-export default function GeneratingTypes({ selectedLang }: Props) {+export function GeneratingTypes({ selectedLang }: Props) {const { ref } = useParams()const [isGeneratingTypes, setIsGeneratingTypes] = useState(false)@@ -41,42 +42,48 @@ export default function GeneratingTypes({ selectedLang }: Props) {}return (- <>- <h2 className="doc-heading flex items-center justify-between">- <span>Generating types</span>- <DocsButton href={`${DOCS_URL}/guides/database/api/generating-types`} />- </h2>- <div className="doc-section">- <article className="code-column text-foreground">+ <DocSection+ title={+ <span className="flex items-center justify-between">+ <span>Generating types</span>+ <DocsButton href={`${DOCS_URL}/guides/database/api/generating-types`} />+ </span>+ }+ content={+ <><p>Supabase APIs are generated from your database, which means that we can use databaseintrospection to generate type-safe API definitions.</p><p>You can generate types from your database either through the{' '}- <Link href={`${DOCS_URL}/guides/database/api/generating-types`}>Supabase CLI</Link>, or- by downloading the types file via the button on the right and importing it in your+ <InlineLink href={`${DOCS_URL}/guides/database/api/generating-types`}>+ Supabase CLI+ </InlineLink>+ , or by downloading the types file via the button on the right and importing it in yourapplication within <code>src/index.ts</code>.</p>- </article>- <article- className={`code ${selectedLang === 'js' ? 'flex items-center justify-center' : ''}`}+ </>+ }+ snippets={+ <div+ className={+ selectedLang === 'js' ? 'flex flex-col items-center justify-center h-full' : ''+ }>- <div className="grid gap-2">- <p className="text-center">- {selectedLang === 'js' && (- <Button- type="default"- disabled={isGeneratingTypes}- loading={isGeneratingTypes}- icon={<Download strokeWidth={1.5} />}- onClick={onClickGenerateTypes}- >- Generate and download types- </Button>- )}- </p>- <p className="text-xs text-center text-foreground-light bg-studio p-4">+ <div className="flex flex-col items-center justify-center p-10">+ {selectedLang === 'js' && (+ <Button+ type="default"+ disabled={isGeneratingTypes}+ loading={isGeneratingTypes}+ icon={<Download strokeWidth={1.5} />}+ onClick={onClickGenerateTypes}+ >+ Generate and download types+ </Button>+ )}+ <p className="text-xs text-center text-foreground-light mt-4">Remember to re-generate and download this file as you make changes to your tables.</p></div>@@ -85,9 +92,9 @@ export default function GeneratingTypes({ selectedLang }: Props) {selectedLang={selectedLang}snippet={localSnippets.generateTypes(ref ?? '')}/>- </article>- </div>- </>+ </div>+ }+ />)}diff --git a/apps/studio/components/interfaces/Docs/Introduction.tsx b/apps/studio/components/interfaces/Docs/Introduction.tsxindex 18ee355957d..49bc91da599 100644--- a/apps/studio/components/interfaces/Docs/Introduction.tsx+++ b/apps/studio/components/interfaces/Docs/Introduction.tsx@@ -1,11 +1,12 @@import { useParams } from 'common'-import Snippets from 'components/interfaces/Docs/Snippets'-import { useProjectPostgrestConfigQuery } from 'data/config/project-postgrest-config-query'-import { InlineLink } from 'components/ui/InlineLink'-import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'import CodeSnippet from './CodeSnippet'+import { DocSection } from './DocSection'import PublicSchemaNotEnabledAlert from './PublicSchemaNotEnabledAlert'+import Snippets from '@/components/interfaces/Docs/Snippets'+import { InlineLink } from '@/components/ui/InlineLink'+import { useProjectPostgrestConfigQuery } from '@/data/config/project-postgrest-config-query'+import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query'interface Props {selectedLang: 'bash' | 'js'@@ -27,26 +28,31 @@ export default function Introduction({ selectedLang }: Props) {.includes('public')return (- <>- <h2 className="doc-heading">Connect to your project</h2>- <div className="doc-section">- <article className="code-column text-foreground">+ <DocSection+ title="Connect to your project"+ content={+ <><p>All projects have a RESTful endpoint that you can use with your project's API key toquery and manage your database. These can be obtained from the{' '}- <InlineLink href={`/project/${projectRef}/settings/api`}>API settings</InlineLink>.+ <InlineLink href={`/project/${projectRef}/integrations/data_api/overview`}>+ API settings+ </InlineLink>+ .</p><p>You can initialize a new Supabase client using the <code>createClient()</code> method.The Supabase client is your entrypoint to the rest of the Supabase functionality and isthe easiest way to interact with everything we offer within the Supabase ecosystem.</p>- </article>- <article className="code flex flex-col gap-y-2">+ </>+ }+ snippets={+ <><CodeSnippet selectedLang={selectedLang} snippet={Snippets.init(endpoint)} />{isSuccess && !isPublicSchemaEnabled && <PublicSchemaNotEnabledAlert />}- </article>- </div>- </>+ </>+ }+ />)}diff --git a/apps/studio/components/interfaces/Docs/LangSelector.tsx b/apps/studio/components/interfaces/Docs/LangSelector.tsxindex 18558668c93..dc34caa2ef3 100644--- a/apps/studio/components/interfaces/Docs/LangSelector.tsx+++ b/apps/studio/components/interfaces/Docs/LangSelector.tsx@@ -1,11 +1,7 @@import { PermissionAction } from '@supabase/shared-types/out/constants'-import { Key } from 'lucide-react'-import { useMemo } from 'react'-import { useParams } from 'common'-import type { showApiKey } from 'components/interfaces/Docs/Docs.types'-import { useAPIKeysQuery } from 'data/api-keys/api-keys-query'-import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'+import { EyeOff, Key } from 'lucide-react'+import { useMemo } from 'react'import {Button,DropdownMenu,@@ -16,15 +12,21 @@ import {DropdownMenuRadioItem,DropdownMenuSeparator,DropdownMenuTrigger,+ ToggleGroup,+ ToggleGroupItem,} from 'ui'+import type { ShowApiKey } from '@/components/interfaces/Docs/Docs.types'+import { useAPIKeysQuery } from '@/data/api-keys/api-keys-query'+import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'+const DEFAULT_KEY = { name: 'hide', key: 'SUPABASE_KEY' }interface LangSelectorProps {- selectedLang: string- selectedApiKey: showApiKey- setSelectedLang: (selectedLang: string) => void- setSelectedApiKey: (showApiKey: showApiKey) => void+ selectedLang: 'js' | 'bash'+ selectedApiKey: ShowApiKey+ setSelectedLang: (selectedLang: 'js' | 'bash') => void+ setSelectedApiKey: (key: ShowApiKey) => void}export const LangSelector = ({@@ -52,103 +54,97 @@ export const LangSelector = ({const secretKeys = useMemo(() => apiKeys.filter(({ type }) => type === 'secret'), [apiKeys])return (- <div className="p-1 w-1/2 ml-auto">- <div className="z-0 flex justify-end">- <button- type="button"- onClick={() => setSelectedLang('js')}- className={`${- selectedLang == 'js'- ? 'bg-surface-100 font-medium text-foreground'- : 'bg-alternative text-foreground-lighter'- } relative inline-flex items-center border-r border-background p-1 px-2 text-sm transition hover:text-foreground focus:outline-none`}- >+ <div className="flex items-center gap-x-1">+ <ToggleGroup+ type="single"+ value={selectedLang}+ variant="outline"+ onValueChange={(value) => {+ if (value) setSelectedLang(value as 'js' | 'bash')+ }}+ size="sm"+ className="flex-1 flex"+ >+ <ToggleGroupItem value="js" className="flex-1 px-2 py-1 h-7 text-xs">JavaScript- </button>- <button- type="button"- onClick={() => setSelectedLang('bash')}- className={`${- selectedLang == 'bash'- ? 'bg-surface-100 font-medium text-foreground'- : 'bg-alternative text-foreground-lighter'- } relative inline-flex items-center border-r border-background p-1 px-2 text-sm transition hover:text-foreground focus:outline-none`}- >+ </ToggleGroupItem>+ <ToggleGroupItem value="bash" className="flex-1 px-2 py-1 h-7 text-xs">Bash- </button>- {selectedLang == 'bash' &&- canReadAPIKeys &&- !isLoadingAPIKeys &&- apiKeys &&- apiKeys.length > 0 && (- <div className="flex gap-x-1">- <div className="flex items-center gap-2 p-1 pl-2 text-xs text-foreground-lighter">- <Key size={12} strokeWidth={1.5} />- <span>Project API key:</span>- </div>- <DropdownMenu>- <DropdownMenuTrigger asChild>- <Button type="outline">- {selectedApiKey.name === 'hide' ? 'Hide keys' : selectedApiKey.name}- </Button>- </DropdownMenuTrigger>- <DropdownMenuContent align="end" side="bottom">- <DropdownMenuRadioGroup value={selectedApiKey.key}>- <DropdownMenuRadioItem- key="hide"- value={DEFAULT_KEY.key}- onClick={() => setSelectedApiKey(DEFAULT_KEY)}- >- Hide keys- </DropdownMenuRadioItem>+ </ToggleGroupItem>+ </ToggleGroup>+ {selectedLang == 'bash' ? (+ canReadAPIKeys &&+ !isLoadingAPIKeys &&+ apiKeys &&+ apiKeys.length > 0 && (+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button type="default" size="tiny" className="p-0 h-7 w-7">+ {selectedApiKey.key === DEFAULT_KEY.key ? (+ <EyeOff size={12} strokeWidth={1.5} />+ ) : (+ <Key size={12} strokeWidth={1.5} />+ )}+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end" side="bottom" className="w-48">+ <DropdownMenuRadioGroup value={selectedApiKey.key}>+ <DropdownMenuRadioItem+ key="hide"+ value={DEFAULT_KEY.key}+ onClick={() => setSelectedApiKey(DEFAULT_KEY)}+ >+ Hide keys+ </DropdownMenuRadioItem>- {publishableKeys.length > 0 && (- <>- <DropdownMenuSeparator />- <DropdownMenuLabel>Publishable keys</DropdownMenuLabel>- {publishableKeys.map((key) => {- const value = key.api_key- return (- <DropdownMenuRadioItem- key={key.id}- value={value}- onClick={() =>- setSelectedApiKey({- name: `Publishable key: ${key.name}`,- key: value,- })- }- >- {key.name}- </DropdownMenuRadioItem>- )- })}- </>- )}-- {secretKeys.length > 0 && (- <>- <DropdownMenuSeparator />- <DropdownMenuLabel>Secret keys</DropdownMenuLabel>- {secretKeys.map((key) => {- const value = key.prefix + '...'- return (- <DropdownMenuRadioItem- key={key.id}- value={value}- onClick={() =>- setSelectedApiKey({ name: `Secret key: ${key.name}`, key: value })- }- >- {key.name}- </DropdownMenuRadioItem>- )- })}- </>- )}+ {publishableKeys.length > 0 && (+ <>+ <DropdownMenuSeparator />+ <DropdownMenuLabel>Publishable keys</DropdownMenuLabel>+ {publishableKeys.map((key) => {+ const value = key.api_key+ return (+ <DropdownMenuRadioItem+ key={key.id}+ value={value}+ onClick={() =>+ setSelectedApiKey({+ name: `Publishable key: ${key.name}`,+ key: value,+ })+ }+ >+ {key.name}+ </DropdownMenuRadioItem>+ )+ })}+ </>+ )}+ {secretKeys.length > 0 && (+ <><DropdownMenuSeparator />+ <DropdownMenuLabel>Secret keys</DropdownMenuLabel>+ {secretKeys.map((key) => {+ const value = key.prefix + '...'+ return (+ <DropdownMenuRadioItem+ key={key.id}+ value={value}+ onClick={() =>+ setSelectedApiKey({ name: `Secret key: ${key.name}`, key: value })+ }+ >+ {key.name}+ </DropdownMenuRadioItem>+ )+ })}+ </>+ )}+ {legacyKeys.length > 0 && (+ <>+ <DropdownMenuSeparator /><DropdownMenuGroup><DropdownMenuLabel>JWT-based legacy keys</DropdownMenuLabel>{legacyKeys.map((key) => {@@ -166,12 +162,15 @@ export const LangSelector = ({)})}</DropdownMenuGroup>- </DropdownMenuRadioGroup>- </DropdownMenuContent>- </DropdownMenu>- </div>- )}- </div>+ </>+ )}+ </DropdownMenuRadioGroup>+ </DropdownMenuContent>+ </DropdownMenu>+ )+ ) : (+ <div className="w-7 h-7" />+ )}</div>)}diff --git a/apps/studio/components/interfaces/Docs/Pages/Rpc/Introduction.tsx b/apps/studio/components/interfaces/Docs/Pages/Rpc/Introduction.tsxindex bc78b7ef7b6..48e4a853803 100644--- a/apps/studio/components/interfaces/Docs/Pages/Rpc/Introduction.tsx+++ b/apps/studio/components/interfaces/Docs/Pages/Rpc/Introduction.tsx@@ -1,17 +1,19 @@+import { DocSection } from '../../DocSection'+const Introduction = () => {return (- <>- <h2 className="doc-heading">Introduction</h2>- <div className="doc-section">- <article className="code-column text-foreground">+ <DocSection+ title="Introduction"+ content={+ <><p>All of your database stored procedures are available on your API. This means you canbuild your logic directly into the database (if you're brave enough)!</p><p>The API endpoint supports POST (and in some cases GET) to execute the function.</p>- </article>- </div>- </>+ </>+ }+ />)}diff --git a/apps/studio/components/interfaces/Docs/Pages/Tables/Introduction.tsx b/apps/studio/components/interfaces/Docs/Pages/Tables/Introduction.tsxindex b8c130e216e..b5a2e9e019f 100644--- a/apps/studio/components/interfaces/Docs/Pages/Tables/Introduction.tsx+++ b/apps/studio/components/interfaces/Docs/Pages/Tables/Introduction.tsx@@ -1,10 +1,11 @@import { useParams } from 'common'-import Link from 'next/link'-import CodeSnippet from 'components/interfaces/Docs/CodeSnippet'-import GeneratingTypes from 'components/interfaces/Docs/GeneratingTypes'-import { useProjectPostgrestConfigQuery } from 'data/config/project-postgrest-config-query'+import { DocSection } from '../../DocSection'import PublicSchemaNotEnabledAlert from '../../PublicSchemaNotEnabledAlert'+import CodeSnippet from '@/components/interfaces/Docs/CodeSnippet'+import { GeneratingTypes } from '@/components/interfaces/Docs/GeneratingTypes'+import { InlineLink } from '@/components/ui/InlineLink'+import { useProjectPostgrestConfigQuery } from '@/data/config/project-postgrest-config-query'interface IntroductionProps {selectedLang: 'bash' | 'js'@@ -21,62 +22,65 @@ const Introduction = ({ selectedLang }: IntroductionProps) => {.includes('public')return (- <>- <h2 className="doc-heading">Introduction</h2>- <div className="doc-section">- <article className="code-column text-foreground flex flex-col gap-y-2">+ <div className="flex flex-col flex-1">+ <DocSection+ title="Introduction"+ content={<p>All views and tables in the <code>public</code> schema and accessible by the activedatabase role for a request are available for querying.</p>- </article>- <article className="code">- {isSuccess && !isPublicSchemaEnabled && <PublicSchemaNotEnabledAlert />}- </article>- </div>+ }+ snippets={isSuccess && !isPublicSchemaEnabled && <PublicSchemaNotEnabledAlert />}+ />- <h2 className="doc-heading">Non-exposed tables</h2>- <div className="doc-section">- <article className="code-column text-foreground">+ <DocSection+ title="Non-exposed tables"+ content={<p>If you don't want to expose tables in your API, simply add them to a different schema(not the <code>public</code> schema).</p>- </article>- <article className="code"></article>- </div>+ }+ /><GeneratingTypes selectedLang={selectedLang} />- <h2 className="doc-heading">- GraphQL <span className="lowercase">vs</span> Supabase- </h2>- <div className="doc-section">- <article className="code-column text-foreground">- <p>- If you have a GraphQL background, you might be wondering if you can fetch your data in a- single round-trip. The answer is yes!- </p>- <p>- The syntax is very similar. This example shows how you might achieve the same thing with- Apollo GraphQL and Supabase.- <br />- <br />- </p>- <h4>Still want GraphQL?</h4>- <p>- If you still want to use GraphQL, you can. Supabase provides you with a full Postgres- database, so as long as your middleware can connect to the database then you can still- use the tools you love. You can find the database connection details{' '}- <Link href={`/project/${projectRef}/database/settings`}>in the settings.</Link>- </p>- </article>- <article className="code">- <CodeSnippet selectedLang={selectedLang} snippet={localSnippets.withApollo()} />- <CodeSnippet selectedLang={selectedLang} snippet={localSnippets.withSupabase()} />- </article>- </div>- </>+ <DocSection+ title={+ <>+ GraphQL <span className="lowercase font-normal">vs</span> Supabase+ </>+ }+ content={+ <>+ <p>+ If you have a GraphQL background, you might be wondering if you can fetch your data in+ a single round-trip. The answer is yes!+ </p>+ <p>+ The syntax is very similar. This example shows how you might achieve the same thing+ with Apollo GraphQL and Supabase.+ </p>+ <h4 className="text-foreground-light mt-8 font-medium">Still want GraphQL?</h4>+ <p>+ If you still want to use GraphQL, you can. Supabase provides you with a full Postgres+ database, so as long as your middleware can connect to the database then you can still+ use the tools you love. You can find the database connection details{' '}+ <InlineLink href={`/project/${projectRef}/database/settings`}>+ in the settings.+ </InlineLink>+ </p>+ </>+ }+ snippets={+ <>+ <CodeSnippet selectedLang={selectedLang} snippet={localSnippets.withApollo()} />+ <CodeSnippet selectedLang={selectedLang} snippet={localSnippets.withSupabase()} />+ </>+ }+ />+ </div>)}diff --git a/apps/studio/components/interfaces/Docs/Pages/UserManagement.tsx b/apps/studio/components/interfaces/Docs/Pages/UserManagement.tsxindex 35a056b4a02..776c904d21a 100644--- a/apps/studio/components/interfaces/Docs/Pages/UserManagement.tsx+++ b/apps/studio/components/interfaces/Docs/Pages/UserManagement.tsx@@ -1,13 +1,14 @@-import Link from 'next/link'+import { useParams } from 'common'import { useRouter } from 'next/router'-import { useParams } from 'common'-import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'-import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'-import { DOCS_URL } from 'lib/constants'-import { makeRandomString } from 'lib/helpers'import CodeSnippet from '../CodeSnippet'+import { DocSection } from '../DocSection'import Snippets from '../Snippets'+import { InlineLink } from '@/components/ui/InlineLink'+import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query'+import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'+import { DOCS_URL } from '@/lib/constants'+import { makeRandomString } from '@/lib/helpers'const randomPassword = makeRandomString(20)@@ -31,158 +32,172 @@ export const UserManagement = ({ selectedLang, showApiKey }: UserManagementPropsconst endpoint = `${protocol}://${hostEndpoint ?? ''}`return (- <>- <h2 className="doc-heading">User Management</h2>- <div className="doc-section">- <article className="code-column text-foreground">- <p>Supabase makes it easy to manage your users.</p>- <p>- Supabase assigns each user a unique ID. You can reference this ID anywhere in your- database. For example, you might create a <code>profiles</code> table references the- user using a <code>user_id</code> field.- </p>- <p>- Supabase already has built in the routes to sign up, login, and log out for managing- users in your apps and websites.- </p>- </article>- </div>+ <div className="flex flex-col flex-1">+ <DocSection+ title="User Management"+ content={+ <>+ <p>Supabase makes it easy to manage your users.</p>+ <p>+ Supabase assigns each user a unique ID. You can reference this ID anywhere in your+ database. For example, you might create a <code>profiles</code> table that references+ the user using a <code>user_id</code> field.+ </p>+ <p>+ Supabase already has built in the routes to sign up, login, and log out for managing+ users in your apps and websites.+ </p>+ </>+ }+ />- <h2 className="doc-heading">Sign up</h2>- <div className="doc-section ">- <article className="code-column text-foreground">- <p>Allow your users to sign up and create a new account.</p>- <p>- After they have signed up, all interactions using the Supabase JS client will be- performed as "that user".- </p>- </article>- <article className="code">+ <DocSection+ title="Sign up"+ content={+ <>+ <p>Allow your users to sign up and create a new account.</p>+ <p>+ After they have signed up, all interactions using the Supabase JS client will be+ performed as "that user".+ </p>+ </>+ }+ snippets={<CodeSnippetselectedLang={selectedLang}snippet={Snippets.authSignup(endpoint, keyToShow, randomPassword)}/>- </article>- </div>+ }+ />- <h2 className="doc-heading">Log in with Email/Password</h2>- <div className="doc-section ">- <article className="code-column text-foreground">- <p>If an account is created, users can login to your app.</p>- <p>- After they have logged in, all interactions using the Supabase JS client will be- performed as "that user".- </p>- </article>- <article className="code">+ <DocSection+ title="Log in with Email/Password"+ content={+ <>+ <p>If an account is created, users can login to your app.</p>+ <p>+ After they have logged in, all interactions using the Supabase JS client will be+ performed as "that user".+ </p>+ </>+ }+ snippets={<CodeSnippetselectedLang={selectedLang}snippet={Snippets.authLogin(endpoint, keyToShow, randomPassword)}/>- </article>- </div>+ }+ />- <h2 className="doc-heading">Log in with Magic Link via Email</h2>- <div className="doc-section ">- <article className="code-column text-foreground">- <p>Send a user a passwordless link which they can use to redeem an access_token.</p>- <p>- After they have clicked the link, all interactions using the Supabase JS client will be- performed as "that user".- </p>- </article>- <article className="code">+ <DocSection+ title="Log in with Magic Link via Email"+ content={+ <>+ <p>Send a user a passwordless link which they can use to redeem an access_token.</p>+ <p>+ After they have clicked the link, all interactions using the Supabase JS client will+ be performed as "that user".+ </p>+ </>+ }+ snippets={<CodeSnippetselectedLang={selectedLang}snippet={Snippets.authMagicLink(endpoint, keyToShow)}/>- </article>- </div>+ }+ />- <h2 className="doc-heading">Sign Up with Phone/Password</h2>- <div className="doc-section ">- <article className="code-column text-foreground">- <p>- A phone number can be used instead of an email as a primary account confirmation- mechanism.- </p>- <p>- The user will receive a mobile OTP via sms with which they can verify that they control- the phone number.- </p>- <p>- You must enter your own twilio credentials on the auth settings page to enable sms- confirmations.- </p>- </article>- <article className="code">+ <DocSection+ title="Sign Up with Phone/Password"+ content={+ <>+ <p>+ A phone number can be used instead of an email as a primary account confirmation+ mechanism.+ </p>+ <p>+ The user will receive a mobile OTP via sms with which they can verify that they+ control the phone number.+ </p>+ <p>+ You must enter your own twilio credentials on the auth settings page to enable sms+ confirmations.+ </p>+ </>+ }+ snippets={<CodeSnippetselectedLang={selectedLang}snippet={Snippets.authPhoneSignUp(endpoint, keyToShow)}/>- </article>- </div>+ }+ />- <h2 className="doc-heading">Login via SMS OTP</h2>- <div className="doc-section ">- <article className="code-column text-foreground">- <p>- SMS OTPs work like magic links, except you have to provide an interface for the user to- verify the 6 digit number they receive.- </p>- <p>- You must enter your own twilio credentials on the auth settings page to enable SMS-based- Logins.- </p>- </article>- <article className="code">+ <DocSection+ title="Login via SMS OTP"+ content={+ <>+ <p>+ SMS OTPs work like magic links, except you have to provide an interface for the user+ to verify the 6 digit number they receive.+ </p>+ <p>+ You must enter your own twilio credentials on the auth settings page to enable+ SMS-based Logins.+ </p>+ </>+ }+ snippets={<CodeSnippetselectedLang={selectedLang}snippet={Snippets.authMobileOTPLogin(endpoint, keyToShow)}/>- </article>- </div>+ }+ />- <h2 className="doc-heading">Verify an SMS OTP</h2>- <div className="doc-section ">- <article className="code-column text-foreground">- <p>- Once the user has received the OTP, have them enter it in a form and send it for- verification- </p>- <p>- You must enter your own twilio credentials on the auth settings page to enable SMS-based- OTP verification.- </p>- </article>- <article className="code">+ <DocSection+ title="Verify an SMS OTP"+ content={+ <>+ <p>+ Once the user has received the OTP, have them enter it in a form and send it for+ verification+ </p>+ <p>+ You must enter your own twilio credentials on the auth settings page to enable+ SMS-based OTP verification.+ </p>+ </>+ }+ snippets={<CodeSnippetselectedLang={selectedLang}snippet={Snippets.authMobileOTPVerify(endpoint, keyToShow)}/>- </article>- </div>+ }+ />{authenticationSignInProviders && (- <>- <h2 className="doc-heading">Log in with Third Party OAuth</h2>- <div className="doc-section ">- <article className="code-column text-foreground">+ <DocSection+ title="Log in with Third Party OAuth"+ content={+ <><p>Users can log in with Third Party OAuth like Google, Facebook, GitHub, and more. Youmust first enable each of these in the Auth Providers settings{' '}<span className="text-green-500">- <Link key={'AUTH'} href={`/project/${router.query.ref}/auth/providers`}>+ <InlineLink key={'AUTH'} href={`/project/${projectRef}/auth/providers`}>here- </Link>+ </InlineLink></span>{' '}.</p><p>View all the available{' '}- <a href={`${DOCS_URL}/guides/auth#providers`} target="_blank" rel="noreferrer">+ <InlineLink href={`${DOCS_URL}/guides/auth#providers`}>Third Party OAuth providers- </a>+ </InlineLink></p><p>After they have logged in, all interactions using the Supabase JS client will be@@ -190,131 +205,111 @@ export const UserManagement = ({ selectedLang, showApiKey }: UserManagementProps</p><p>Generate your Client ID and secret from:{` `}- <a- href="https://console.developers.google.com/apis/credentials"- target="_blank"- rel="noreferrer"- >+ <InlineLink href="https://console.developers.google.com/apis/credentials">- </a>- ,{` `}- <a- href="https://github.com/settings/applications/new"- target="_blank"- rel="noreferrer"- >- GitHub- </a>- ,{` `}- <a href="https://gitlab.com/oauth/applications" target="_blank" rel="noreferrer">- GitLab- </a>- ,{` `}- <a href="https://developers.facebook.com/apps/" target="_blank" rel="noreferrer">- </a>+ </InlineLink>,{` `}- <a- href="https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/"- target="_blank"- rel="noreferrer"- >+ <InlineLink href="https://github.com/settings/applications/new">GitHub</InlineLink>,+ {` `}+ <InlineLink href="https://gitlab.com/oauth/applications">GitLab</InlineLink>,{` `}+ <InlineLink href="https://developers.facebook.com/apps/">Facebook</InlineLink>,{` `}+ <InlineLink href="https://support.atlassian.com/bitbucket-cloud/docs/use-oauth-on-bitbucket-cloud/">Bitbucket- </a>+ </InlineLink>.</p>- </article>- <article className="code">- <CodeSnippet- selectedLang={selectedLang}- snippet={Snippets.authThirdPartyLogin(endpoint, keyToShow)}- />- </article>- </div>- </>+ </>+ }+ snippets={+ <CodeSnippet+ selectedLang={selectedLang}+ snippet={Snippets.authThirdPartyLogin(endpoint, keyToShow)}+ />+ }+ />)}- <h2 className="doc-heading">User</h2>- <div className="doc-section ">- <article className="code-column text-foreground">- <p>Get the JSON object for the logged in user.</p>- </article>- <article className="code">+ <DocSection+ title="User"+ content={<p>Get the JSON object for the logged in user.</p>}+ snippets={<CodeSnippetselectedLang={selectedLang}snippet={Snippets.authUser(endpoint, keyToShow)}/>- </article>- </div>+ }+ />- <h2 className="doc-heading">Forgotten Password Email</h2>- <div className="doc-section ">- <article className="code-column text-foreground">+ <DocSection+ title="Forgotten Password Email"+ content={<p>Sends the user a log in link via email. Once logged in you should direct the user to anew password form. And use "Update User" below to save the new password.</p>- </article>- <article className="code">+ }+ snippets={<CodeSnippetselectedLang={selectedLang}snippet={Snippets.authRecover(endpoint, keyToShow)}/>- </article>- </div>+ }+ />- <h2 className="doc-heading">Update User</h2>- <div className="doc-section ">- <article className="code-column text-foreground">+ <DocSection+ title="Update User"+ content={<p>Update the user with a new email or password. Each key (email, password, and data) isoptional</p>- </article>- <article className="code">+ }+ snippets={<CodeSnippetselectedLang={selectedLang}snippet={Snippets.authUpdate(endpoint, keyToShow)}/>- </article>- </div>+ }+ />- <h2 className="doc-heading">Log out</h2>- <div className="doc-section ">- <article className="code-column text-foreground">+ <DocSection+ title="Log out"+ content={<p>After calling log out, all interactions using the Supabase JS client will be"anonymous".</p>- </article>- <article className="code">+ }+ snippets={<CodeSnippetselectedLang={selectedLang}snippet={Snippets.authLogout(endpoint, keyToShow)}/>- </article>- </div>+ }+ />- <h2 className="doc-heading">Send a User an Invite over Email</h2>- <div className="doc-section ">- <article className="code-column text-foreground">- <p>Send a user a passwordless link which they can use to sign up and log in.</p>- <p>- After they have clicked the link, all interactions using the Supabase JS client will be- performed as "that user".- </p>- <p>- This endpoint requires you use the <code>service_role_key</code> when initializing the- client, and should only be invoked from the server, never from the client.- </p>- </article>- <article className="code">+ <DocSection+ title="Send a User an Invite over Email"+ content={+ <>+ <p>Send a user a passwordless link which they can use to sign up and log in.</p>+ <p>+ After they have clicked the link, all interactions using the Supabase JS client will+ be performed as "that user".+ </p>+ <p>+ This endpoint requires you use the <code>service_role_key</code> when initializing the+ client, and should only be invoked from the server, never from the client.+ </p>+ </>+ }+ snippets={<CodeSnippetselectedLang={selectedLang}snippet={Snippets.authInvite(endpoint, keyToShow)}/>- </article>- </div>- </>+ }+ />+ </div>)}diff --git a/apps/studio/components/interfaces/Docs/Param.tsx b/apps/studio/components/interfaces/Docs/Param.tsxindex 88ebeda3f46..41ef4b7d5bf 100644--- a/apps/studio/components/interfaces/Docs/Param.tsx+++ b/apps/studio/components/interfaces/Docs/Param.tsx@@ -1,8 +1,7 @@import { noop } from 'lodash'import { Badge } from 'ui'-import Description from 'components/interfaces/Docs/Description'-import { Code, Database } from 'lucide-react'+import Description from '@/components/interfaces/Docs/Description'function getColumnType(type: string, format: string) {// json and jsonb both have type=undefined, so check format instead@@ -43,65 +42,35 @@ const Param = ({onDesciptionUpdated = noop,}: ParamProps) => {return (- <>- <div className="mb-4 flex items-center justify-between ">- <div className="flex gap-2 items-center">- <div className="flex items-center gap-2">- <label className="font-mono text-xs uppercase text-foreground-lighter min-w-[55px]">- Column- </label>-- <div className="flex items-center gap-4">- <span className="text-md text-foreground pb-0.5">{name}</span>- </div>- </div>- </div>+ <div className="not-prose">+ <div className="mb-4 flex items-center gap-4">+ <h3 className="heading-default text-foreground mb-0 mt-0">{name}</h3><Badge variant={required ? 'warning' : 'default'}>{required ? 'Required' : 'Optional'}</Badge></div>{format && (- <div className="grid gap-2 mt-6">- <div className="mb-4 flex items-center gap-2">- <label className="font-mono text-xs uppercase text-foreground-lighter min-w-[55px]">- Type- </label>- <div>- <span className="flex grow-0 bg-slate-300 px-2 py-0.5 rounded-md text-foreground-light">- <span className="flex items-center gap-2 text-sm">- <Code size="14" />- <span>{getColumnType(type, format)}</span>- </span>- </span>- </div>- </div>- <div className="mb-4 flex items-center gap-2">- <label className="font-mono text-xs uppercase text-foreground-lighter min-w-[55px]">- Format- </label>- <div>- <span className="flex grow-0 bg-slate-300 px-2 py-0.5 rounded-md text-foreground-light">- <span className="flex items-center gap-2 text-sm">- <Database size="14" />- <span>{format}</span>- </span>- </span>- </div>- </div>- </div>- )}- {description !== false && (- <div className="grid gap-2 mt-2">- <label className="font-mono text-xs uppercase text-foreground-lighter">Description</label>- <Description- content={description?.toString()}- metadata={metadata}- onChange={onDesciptionUpdated}- />+ <div className="grid grid-cols-[auto_1fr] gap-y-2 gap-x-10 text-sm">+ <label className="text-foreground-lighter">Type</label>+ <div className="text-foreground">{getColumnType(type, format)}</div>+ <label className="text-foreground-lighter">Format</label>+ <div className="text-foreground">{format}</div>+ {description !== false && (+ <>+ <label className="text-foreground-lighter">Description</label>+ <div className="text-foreground pt-1">+ <Description+ content={description?.toString()}+ metadata={metadata}+ onChange={onDesciptionUpdated}+ />+ </div>+ </>+ )}</div>)}- </>+ </div>)}export default Paramdiff --git a/apps/studio/components/interfaces/Docs/ResourceContent.tsx b/apps/studio/components/interfaces/Docs/ResourceContent.tsxindex e0550213412..f5f58076ab5 100644--- a/apps/studio/components/interfaces/Docs/ResourceContent.tsx+++ b/apps/studio/components/interfaces/Docs/ResourceContent.tsx@@ -1,14 +1,16 @@+import { useParams } from 'common'import { Table2 } from 'lucide-react'-import { useParams } from 'common'-import CodeSnippet from 'components/interfaces/Docs/CodeSnippet'-import Description from 'components/interfaces/Docs/Description'-import Param from 'components/interfaces/Docs/Param'-import Snippets from 'components/interfaces/Docs/Snippets'-import { useCustomDomainsQuery } from 'data/custom-domains/custom-domains-query'-import { useProjectJsonSchemaQuery } from 'data/docs/project-json-schema-query'-import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'-import { DOCS_URL } from 'lib/constants'+import { DocSection } from './DocSection'+import CodeSnippet from '@/components/interfaces/Docs/CodeSnippet'+import Description from '@/components/interfaces/Docs/Description'+import Param from '@/components/interfaces/Docs/Param'+import Snippets from '@/components/interfaces/Docs/Snippets'+import { InlineLink } from '@/components/ui/InlineLink'+import { useCustomDomainsQuery } from '@/data/custom-domains/custom-domains-query'+import { useProjectJsonSchemaQuery } from '@/data/docs/project-json-schema-query'+import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'+import { DOCS_URL } from '@/lib/constants'interface ResourceContentProps {apiEndpoint: string@@ -55,32 +57,35 @@ export const ResourceContent = ({if (!paths || !definitions) return nullreturn (- <>- <h2 className="doc-section__table-name text-foreground mt-0 flex items-center px-6 gap-2">- <span className="bg-slate-300 p-2 rounded-lg">- <Table2 size={18} />- </span>- <span className="text-2xl font-bold">{resourceId}</span>- </h2>+ <div className="flex flex-col flex-1">+ <DocSection+ title={+ <span className="flex items-center gap-2 text-subTitle">+ <Table2 size={16} strokeWidth={1.5} />+ {resourceId}+ </span>+ }+ content={+ <>+ <label className="font-mono text-xs uppercase text-foreground-lighter inline-block mb-2">+ Description+ </label>+ <Description+ content={description}+ metadata={{ table: resourceId }}+ onChange={refreshDocs}+ />+ </>+ }+ />- <div className="doc-section">- <article className="code-column text-foreground">- <label className="font-mono text-xs uppercase text-foreground-lighter inline-block mb-2">- Description- </label>- <Description- content={description}- metadata={{ table: resourceId }}- onChange={refreshDocs}- />- </article>- <article className="code"></article>- </div>{properties.length > 0 && (- <div>+ <div className="flex flex-col flex-1">{properties.map((x) => (- <div className="doc-section py-4" key={x.id}>- <div className="code-column text-foreground">+ <DocSection+ key={x.id}+ title={null}+ content={<Paramkey={x.id}name={x.id}@@ -94,8 +99,8 @@ export const ResourceContent = ({}}onDesciptionUpdated={refreshDocs}/>- </div>- <div className="code">+ }+ snippets={<CodeSnippetselectedLang={selectedLang}snippet={Snippets.readColumns({@@ -106,30 +111,34 @@ export const ResourceContent = ({columnName: x.id,})}/>- </div>- </div>+ }+ />))}</div>)}+{methods.includes('GET') && (- <>- <h3 className="text-foreground mt-4 px-6">Read rows</h3>- <div className="doc-section">- <article className="code-column text-foreground">+ <DocSection+ title="Read rows"+ content={+ <><p>To read rows in <code>{resourceId}</code>, use the <code>select</code> method.</p><p>- <a- href={`${DOCS_URL}/reference/javascript/select`}- target="_blank"- rel="noreferrer"- >+ <InlineLink href={`${DOCS_URL}/reference/javascript/select`}>Learn more</InlineLink>+ </p>+ <h4 className="text-default">Filtering</h4>+ <p>Supabase provides a wide range of filters.</p>+ <p>+ <InlineLink href={`${DOCS_URL}/reference/javascript/using-filters`}>Learn more- </a>+ </InlineLink></p>- </article>- <article className="code">+ </>+ }+ snippets={+ <><CodeSnippetselectedLang={selectedLang}snippet={Snippets.readAll(resourceId, endpoint, keyToShow)}@@ -150,36 +159,20 @@ export const ResourceContent = ({selectedLang={selectedLang}snippet={Snippets.readRange(resourceId, endpoint, keyToShow)}/>- </article>- </div>- <div className="doc-section">- <article className="code-column text-foreground">- <h4 className="mt-0 text-white">Filtering</h4>- <p>Supabase provides a wide range of filters.</p>- <p>- <a- href={`${DOCS_URL}/reference/javascript/using-filters`}- target="_blank"- rel="noreferrer"- >- Learn more- </a>- </p>- </article>- <article className="code"><CodeSnippetselectedLang={selectedLang}snippet={Snippets.readFilters(resourceId, endpoint, keyToShow)}/>- </article>- </div>- </>+ </>+ }+ />)}+{methods.includes('POST') && (- <>- <h3 className="text-foreground mt-4 px-6">Insert rows</h3>- <div className="doc-section">- <article className="code-column text-foreground">+ <DocSection+ title="Insert rows"+ content={+ <><p><code>insert</code> lets you insert into your tables. You can also insert in bulkand do UPSERT.@@ -188,16 +181,12 @@ export const ResourceContent = ({<code>insert</code> will also return the replaced values for UPSERT.</p><p>- <a- href={`${DOCS_URL}/reference/javascript/insert`}- target="_blank"- rel="noreferrer"- >- Learn more- </a>+ <InlineLink href={`${DOCS_URL}/reference/javascript/insert`}>Learn more</InlineLink></p>- </article>- <article className="code">+ </>+ }+ snippets={+ <><CodeSnippetselectedLang={selectedLang}snippet={Snippets.insertSingle(resourceId, endpoint, keyToShow)}@@ -210,15 +199,16 @@ export const ResourceContent = ({selectedLang={selectedLang}snippet={Snippets.upsert(resourceId, endpoint, keyToShow)}/>- </article>- </div>- </>+ </>+ }+ />)}+{methods.includes('PATCH') && (- <>- <h3 className="text-foreground mt-4 px-6">Update rows</h3>- <div className="doc-section">- <article className="code-column text-foreground">+ <DocSection+ title="Update rows"+ content={+ <><p><code>update</code> lets you update rows. <code>update</code> will match all rows bydefault. You can update specific rows using horizontal filters, e.g. <code>eq</code>@@ -228,73 +218,61 @@ export const ResourceContent = ({<code>update</code> will also return the replaced values for UPDATE.</p><p>- <a- href={`${DOCS_URL}/reference/javascript/update`}- target="_blank"- rel="noreferrer"- >- Learn more- </a>+ <InlineLink href={`${DOCS_URL}/reference/javascript/update`}>Learn more</InlineLink></p>- </article>- <article className="code">- <CodeSnippet- selectedLang={selectedLang}- snippet={Snippets.update(resourceId, endpoint, keyToShow)}- />- </article>- </div>- </>+ </>+ }+ snippets={+ <CodeSnippet+ selectedLang={selectedLang}+ snippet={Snippets.update(resourceId, endpoint, keyToShow)}+ />+ }+ />)}+{methods.includes('DELETE') && (- <>- <h3 className="text-foreground mt-4 px-6">Delete rows</h3>- <div className="doc-section">- <article className="code-column text-foreground">+ <DocSection+ title="Delete rows"+ content={+ <><p><code>delete</code> lets you delete rows. <code>delete</code> will match all rows bydefault, so remember to specify your filters!</p><p>- <a- href={`${DOCS_URL}/reference/javascript/delete`}- target="_blank"- rel="noreferrer"- >- Learn more- </a>+ <InlineLink href={`${DOCS_URL}/reference/javascript/delete`}>Learn more</InlineLink></p>- </article>- <article className="code">- <CodeSnippet- selectedLang={selectedLang}- snippet={Snippets.delete(resourceId, endpoint, keyToShow)}- />- </article>- </div>- </>+ </>+ }+ snippets={+ <CodeSnippet+ selectedLang={selectedLang}+ snippet={Snippets.delete(resourceId, endpoint, keyToShow)}+ />+ }+ />)}+{realtimeEnabled &&(methods.includes('DELETE') || methods.includes('POST') || methods.includes('PATCH')) && (- <>- <h3 className="text-foreground mt-4 px-6">Subscribe to changes</h3>- <div className="doc-section">- <article className="code-column text-foreground">+ <DocSection+ title="Subscribe to changes"+ content={+ <><p>Supabase provides realtime functionality and broadcasts database changes toauthorized users depending on Row Level Security (RLS) policies.</p><p>- <a- href={`${DOCS_URL}/reference/javascript/subscribe`}- target="_blank"- rel="noreferrer"- >+ <InlineLink href={`${DOCS_URL}/reference/javascript/subscribe`}>Learn more- </a>+ </InlineLink></p>- </article>- <article className="code">+ </>+ }+ snippets={+ <><CodeSnippetselectedLang={selectedLang}snippet={Snippets.subscribeAll(resourceMeta.camelCase, resourceId)}@@ -320,10 +298,10 @@ export const ResourceContent = ({'someValue')}/>- </article>- </div>- </>+ </>+ }+ />)}- </>+ </div>)}diff --git a/apps/studio/components/interfaces/Docs/RpcContent.tsx b/apps/studio/components/interfaces/Docs/RpcContent.tsxindex 8f02ea9ee48..5fb8d1ac6f6 100644--- a/apps/studio/components/interfaces/Docs/RpcContent.tsx+++ b/apps/studio/components/interfaces/Docs/RpcContent.tsx@@ -1,10 +1,12 @@import { useParams } from 'common'-import CodeSnippet from 'components/interfaces/Docs/CodeSnippet'-import Description from 'components/interfaces/Docs/Description'-import Param from 'components/interfaces/Docs/Param'-import Snippets from 'components/interfaces/Docs/Snippets'-import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'-import { ProjectJsonSchemaPaths } from 'data/docs/project-json-schema-query'++import { DocSection } from './DocSection'+import CodeSnippet from '@/components/interfaces/Docs/CodeSnippet'+import Description from '@/components/interfaces/Docs/Description'+import Param from '@/components/interfaces/Docs/Param'+import Snippets from '@/components/interfaces/Docs/Snippets'+import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query'+import { ProjectJsonSchemaPaths } from '@/data/docs/project-json-schema-query'/*** TODO: need to support rpc with the same name and different params type@@ -50,17 +52,18 @@ export const RpcContent = ({if (!path) return nullreturn (- <>- <h2 className="text-foreground mt-0">- <span className="px-6 text-2xl">{meta.id}</span>- </h2>-- <div className="doc-section">- <article className="code-column text-foreground">- <label className="font-mono text-xs uppercase text-foreground-lighter">Description</label>- <Description content={summary ?? ''} metadata={{ rpc: rpcId }} onChange={refreshDocs} />- </article>- <article className="code">+ <div className="flex flex-col flex-1">+ <DocSection+ title={meta.id}+ content={+ <>+ <label className="font-mono text-xs uppercase text-foreground-lighter inline-block mb-2">+ Description+ </label>+ <Description content={summary ?? ''} metadata={{ rpc: rpcId }} onChange={refreshDocs} />+ </>+ }+ snippets={<CodeSnippetselectedLang={selectedLang}snippet={Snippets.rpcSingle({@@ -72,15 +75,18 @@ export const RpcContent = ({endpoint: endpoint,})}/>- </article>- </div>+ }+ />+{rpcParams.length > 0 && (- <div>- <h3 className="text-foreground mt-0 px-6 capitalize">Function Arguments</h3>+ <div className="flex flex-col flex-1">+ <DocSection title="Function Arguments" content={null} />{rpcParams.map((x, i) => {return (- <div key={i} className="doc-section">- <article className="code-column text-foreground">+ <DocSection+ key={i}+ title={null}+ content={<Paramkey={x.name}name={x.name}@@ -89,13 +95,12 @@ export const RpcContent = ({required={true}description={false}/>- </article>- <article className="code"></article>- </div>+ }+ />)})}</div>)}- </>+ </div>)}diff --git a/apps/studio/components/interfaces/Home/NewProjectPanel/NewProjectPanel.tsx b/apps/studio/components/interfaces/Home/NewProjectPanel/NewProjectPanel.tsxindex 55b77743b21..44db9c1c7dc 100644--- a/apps/studio/components/interfaces/Home/NewProjectPanel/NewProjectPanel.tsx+++ b/apps/studio/components/interfaces/Home/NewProjectPanel/NewProjectPanel.tsx@@ -1,17 +1,17 @@-import { ExternalLink, Settings } from 'lucide-react'-import Link from 'next/link'-import { useParams } from 'common'-import { DocsButton } from 'components/ui/DocsButton'-import { InlineLink } from 'components/ui/InlineLink'-import Panel from 'components/ui/Panel'-import { EditorIndexPageLink } from 'data/prefetchers/project.$ref.editor'-import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'import { Auth, EdgeFunctions, Realtime, SqlEditor, Storage, TableEditor } from 'icons'-import { DOCS_URL } from 'lib/constants'+import { ExternalLink, Settings } from 'lucide-react'+import Link from 'next/link'import { Button } from 'ui'+import { APIKeys } from './APIKeys'import { GetStartedHero } from './GetStartedHero'+import { DocsButton } from '@/components/ui/DocsButton'+import { InlineLink } from '@/components/ui/InlineLink'+import Panel from '@/components/ui/Panel'+import { EditorIndexPageLink } from '@/data/prefetchers/project.$ref.editor'+import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'+import { DOCS_URL } from '@/lib/constants'export const NewProjectPanel = () => {const { ref } = useParams()@@ -222,7 +222,7 @@ export const NewProjectPanel = () => {</div><div className="flex items-center space-x-2"><Button asChild type="default" icon={<Settings size={16} strokeWidth={1.5} />}>- <Link href={`/project/${ref}/settings/api`}>API settings</Link>+ <Link href={`/project/${ref}/settings/api-keys`}>API Keys settings</Link></Button><DocsButton href={`${DOCS_URL}/guides/database/api`} /></div>diff --git a/apps/studio/components/interfaces/Integrations/DataApi/DataApi.utils.test.ts b/apps/studio/components/interfaces/Integrations/DataApi/DataApi.utils.test.tsnew file mode 100644index 00000000000..838bc0f7233--- /dev/null+++ b/apps/studio/components/interfaces/Integrations/DataApi/DataApi.utils.test.ts@@ -0,0 +1,248 @@+import { describe, expect, it } from 'vitest'++import { buildEntityMaps, getApiEndpoint, getProjectApiEndpoint } from './DataApi.utils'+import type { ProjectSettings } from '@/data/config/project-settings-v2-query'+import type {+ CustomDomainResponse,+ CustomDomainsData,+} from '@/data/custom-domains/custom-domains-query'+import type { ProjectJsonSchemaPaths } from '@/data/docs/project-json-schema-query'+import type { LoadBalancer } from '@/data/read-replicas/load-balancers-query'+import type { Database } from '@/data/read-replicas/replicas-query'++const makeCustomDomainData = (hostname: string): CustomDomainsData => ({+ customDomain: {+ id: '',+ ssl: {} as CustomDomainResponse['ssl'],+ hostname,+ status: 'active',+ created_at: '',+ custom_metadata: null,+ custom_origin_server: '',+ },+ status: '5_services_reconfigured',+})++const makeDatabase = (+ identifier: string,+ restUrl: string+): Pick<Database, 'identifier' | 'restUrl'> => ({ identifier, restUrl })++const makeLoadBalancer = (endpoint: string): Pick<LoadBalancer, 'endpoint'> => ({ endpoint })++describe('getProjectApiEndpoint', () => {+ it('returns custom domain URL when custom domain is active', () => {+ expect(+ getProjectApiEndpoint({+ settings: undefined,+ customDomainData: makeCustomDomainData('api.example.com'),+ })+ ).toBe('https://api.example.com')+ })++ it('returns settings-based URL when no custom domain', () => {+ expect(+ getProjectApiEndpoint({+ settings: {+ app_config: { protocol: 'https', endpoint: 'abc.supabase.co' },+ } as ProjectSettings,+ customDomainData: undefined,+ })+ ).toBe('https://abc.supabase.co')+ })++ it('respects protocol from settings', () => {+ expect(+ getProjectApiEndpoint({+ settings: {+ app_config: { protocol: 'http', endpoint: 'localhost:54321' },+ } as ProjectSettings,+ customDomainData: undefined,+ })+ ).toBe('http://localhost:54321')+ })++ it('returns placeholder when settings are undefined', () => {+ expect(+ getProjectApiEndpoint({+ settings: undefined,+ customDomainData: undefined,+ })+ ).toBe('https://-')+ })++ it('ignores inactive custom domain', () => {+ const inactiveCustomDomain: CustomDomainsData = {+ customDomain: null,+ status: '0_no_hostname_configured',+ }++ expect(+ getProjectApiEndpoint({+ settings: {+ app_config: { protocol: 'https', endpoint: 'abc.supabase.co' },+ } as ProjectSettings,+ customDomainData: inactiveCustomDomain,+ })+ ).toBe('https://abc.supabase.co')+ })+})++describe('getApiEndpoint', () => {+ it('returns custom domain URL when custom domain is active and primary database is selected', () => {+ expect(+ getApiEndpoint({+ selectedDatabaseId: 'project-ref',+ projectRef: 'project-ref',+ customDomainData: makeCustomDomainData('api.example.com'),+ loadBalancers: undefined,+ selectedDatabase: makeDatabase(+ 'project-ref',+ 'https://project-ref.supabase.co/rest/v1'+ ) as Database,+ })+ ).toBe('https://api.example.com')+ })++ it('returns database restUrl when custom domain is active but a replica is selected', () => {+ expect(+ getApiEndpoint({+ selectedDatabaseId: 'replica-1',+ projectRef: 'project-ref',+ customDomainData: makeCustomDomainData('api.example.com'),+ loadBalancers: undefined,+ selectedDatabase: makeDatabase(+ 'replica-1',+ 'https://replica-1.supabase.co/rest/v1'+ ) as Database,+ })+ ).toBe('https://replica-1.supabase.co/rest/v1')+ })++ it('returns load balancer endpoint when load balancer is selected', () => {+ expect(+ getApiEndpoint({+ selectedDatabaseId: 'load-balancer',+ projectRef: 'project-ref',+ customDomainData: undefined,+ loadBalancers: [makeLoadBalancer('https://lb.supabase.co') as LoadBalancer],+ selectedDatabase: undefined,+ })+ ).toBe('https://lb.supabase.co')+ })++ it('returns empty string when load balancer is selected but none exist', () => {+ expect(+ getApiEndpoint({+ selectedDatabaseId: 'load-balancer',+ projectRef: 'project-ref',+ customDomainData: undefined,+ loadBalancers: undefined,+ selectedDatabase: undefined,+ })+ ).toBe('')+ })++ it('returns database restUrl for a normal database selection', () => {+ expect(+ getApiEndpoint({+ selectedDatabaseId: 'project-ref',+ projectRef: 'project-ref',+ customDomainData: undefined,+ loadBalancers: undefined,+ selectedDatabase: makeDatabase(+ 'project-ref',+ 'https://project-ref.supabase.co/rest/v1'+ ) as Database,+ })+ ).toBe('https://project-ref.supabase.co/rest/v1')+ })++ it('ignores custom domain when it is not active', () => {+ const inactiveCustomDomain: CustomDomainsData = {+ customDomain: null,+ status: '0_no_hostname_configured',+ }++ expect(+ getApiEndpoint({+ selectedDatabaseId: 'project-ref',+ projectRef: 'project-ref',+ customDomainData: inactiveCustomDomain,+ loadBalancers: undefined,+ selectedDatabase: makeDatabase(+ 'project-ref',+ 'https://project-ref.supabase.co/rest/v1'+ ) as Database,+ })+ ).toBe('https://project-ref.supabase.co/rest/v1')+ })+})++describe('buildEntityMaps', () => {+ it('returns empty maps for undefined paths', () => {+ expect(buildEntityMaps(undefined)).toEqual({ resources: {}, rpcs: {} })+ })++ it('returns empty maps for empty paths', () => {+ expect(buildEntityMaps({})).toEqual({ resources: {}, rpcs: {} })+ })++ it('skips the root path', () => {+ const paths: ProjectJsonSchemaPaths = {+ '/': { get: {} as ProjectJsonSchemaPaths[string]['get'] },+ }+ expect(buildEntityMaps(paths)).toEqual({ resources: {}, rpcs: {} })+ })++ it('classifies non-rpc paths as resources', () => {+ const paths: ProjectJsonSchemaPaths = {+ '/users': { get: {} as ProjectJsonSchemaPaths[string]['get'] },+ '/posts': { get: {} as ProjectJsonSchemaPaths[string]['get'] },+ }+ const result = buildEntityMaps(paths)+ expect(Object.keys(result.resources)).toEqual(['users', 'posts'])+ expect(result.rpcs).toEqual({})+ })++ it('classifies rpc/ paths as rpcs', () => {+ const paths: ProjectJsonSchemaPaths = {+ '/rpc/my_function': { post: {} as ProjectJsonSchemaPaths[string]['post'] },+ }+ const result = buildEntityMaps(paths)+ expect(result.resources).toEqual({})+ expect(Object.keys(result.rpcs)).toEqual(['my_function'])+ })++ it('enriches entities with displayName and camelCase', () => {+ const paths: ProjectJsonSchemaPaths = {+ '/user_profiles': { get: {} as ProjectJsonSchemaPaths[string]['get'] },+ '/rpc/get_user_count': { post: {} as ProjectJsonSchemaPaths[string]['post'] },+ }+ const result = buildEntityMaps(paths)++ expect(result.resources['user_profiles']).toEqual({+ id: 'user_profiles',+ displayName: 'user profiles',+ camelCase: 'userProfiles',+ })+ expect(result.rpcs['get_user_count']).toEqual({+ id: 'get_user_count',+ displayName: 'get user count',+ camelCase: 'getUserCount',+ })+ })++ it('handles mixed resources and rpcs', () => {+ const paths: ProjectJsonSchemaPaths = {+ '/': { get: {} as ProjectJsonSchemaPaths[string]['get'] },+ '/users': { get: {} as ProjectJsonSchemaPaths[string]['get'] },+ '/rpc/hello': { post: {} as ProjectJsonSchemaPaths[string]['post'] },+ '/posts': { get: {} as ProjectJsonSchemaPaths[string]['get'] },+ '/rpc/goodbye': { post: {} as ProjectJsonSchemaPaths[string]['post'] },+ }+ const result = buildEntityMaps(paths)+ expect(Object.keys(result.resources)).toEqual(['users', 'posts'])+ expect(Object.keys(result.rpcs)).toEqual(['hello', 'goodbye'])+ })+})diff --git a/apps/studio/components/interfaces/Integrations/DataApi/DataApi.utils.ts b/apps/studio/components/interfaces/Integrations/DataApi/DataApi.utils.tsnew file mode 100644index 00000000000..61990329ea5--- /dev/null+++ b/apps/studio/components/interfaces/Integrations/DataApi/DataApi.utils.ts@@ -0,0 +1,93 @@+import type { ProjectSettings } from '@/data/config/project-settings-v2-query'+import type { CustomDomainsData } from '@/data/custom-domains/custom-domains-query'+import type { ProjectJsonSchemaPaths } from '@/data/docs/project-json-schema-query'+import type { LoadBalancer } from '@/data/read-replicas/load-balancers-query'+import type { Database } from '@/data/read-replicas/replicas-query'+import { snakeToCamel } from '@/lib/helpers'++/**+ * Resolves the primary project API endpoint, respecting custom domains.+ */+export function getProjectApiEndpoint({+ settings,+ customDomainData,+}: {+ settings: ProjectSettings | undefined+ customDomainData: CustomDomainsData | undefined+}): string {+ if (customDomainData?.customDomain?.status === 'active') {+ return `https://${customDomainData.customDomain.hostname}`+ }++ const protocol = settings?.app_config?.protocol ?? 'https'+ const endpoint = settings?.app_config?.endpoint+ return `${protocol}://${endpoint ?? '-'}`+}++/**+ * Resolves the API endpoint URL based on the selected database, custom domain+ * status, and load balancer configuration.+ */+export function getApiEndpoint({+ selectedDatabaseId,+ projectRef,+ customDomainData,+ loadBalancers,+ selectedDatabase,+}: {+ selectedDatabaseId: string | undefined+ projectRef: string | undefined+ customDomainData: CustomDomainsData | undefined+ loadBalancers: Array<LoadBalancer> | undefined+ selectedDatabase: Database | undefined+}): string {+ const isCustomDomainActive = customDomainData?.customDomain?.status === 'active'+ const loadBalancerSelected = selectedDatabaseId === 'load-balancer'++ if (isCustomDomainActive && selectedDatabaseId === projectRef) {+ return `https://${customDomainData.customDomain.hostname}`+ }++ if (loadBalancerSelected) {+ return loadBalancers?.[0]?.endpoint ?? ''+ }++ return selectedDatabase?.restUrl ?? ''+}++export type EnrichedEntity = { id: string; displayName: string; camelCase: string }+export type EntityMap = Record<string, EnrichedEntity>++/**+ * Partitions JSON schema paths into resource and RPC entity maps.+ */+export function buildEntityMaps(paths: ProjectJsonSchemaPaths | undefined): {+ resources: EntityMap+ rpcs: EntityMap+} {+ const RPC_PREFIX = 'rpc/'++ return Object.keys(paths ?? {}).reduce<{ resources: EntityMap; rpcs: EntityMap }>(+ (acc, name) => {+ const trimmedName = name.slice(1)+ if (!trimmedName.length) return acc++ const isRpc = trimmedName.startsWith(RPC_PREFIX)+ const id = isRpc ? trimmedName.slice(RPC_PREFIX.length) : trimmedName+ const enriched: EnrichedEntity = {+ id,+ displayName: id.replace(/_/g, ' '),+ camelCase: snakeToCamel(id),+ }++ if (isRpc) {+ acc.rpcs[id] = enriched+ } else {+ acc.resources[id] = enriched+ }++ return acc+ },+ { resources: {}, rpcs: {} }+ )+}diff --git a/apps/studio/components/interfaces/Integrations/DataApi/DataApiDisabledState.tsx b/apps/studio/components/interfaces/Integrations/DataApi/DataApiDisabledState.tsxnew file mode 100644index 00000000000..ba316e61e4e--- /dev/null+++ b/apps/studio/components/interfaces/Integrations/DataApi/DataApiDisabledState.tsx@@ -0,0 +1,31 @@+import { useParams } from 'common'+import { AlertCircle } from 'lucide-react'+import Link from 'next/link'+import { Alert_Shadcn_, AlertDescription_Shadcn_, AlertTitle_Shadcn_ } from 'ui'++interface DataApiDisabledStateProps {+ description: string+}++export const DataApiDisabledState = ({ description }: DataApiDisabledStateProps) => {+ const { ref: projectRef } = useParams()++ return (+ <div className="flex w-full flex-1 items-center justify-center p-10">+ <Alert_Shadcn_ className="max-w-md">+ <AlertCircle size={16} />+ <AlertTitle_Shadcn_>Data API is disabled</AlertTitle_Shadcn_>+ <AlertDescription_Shadcn_>+ Enable the Data API in the{' '}+ <Link+ href={`/project/${projectRef}/integrations/data_api/overview`}+ className="text-foreground underline hover:decoration-foreground-muted"+ >+ Overview+ </Link>{' '}+ tab to {description}.+ </AlertDescription_Shadcn_>+ </Alert_Shadcn_>+ </div>+ )+}diff --git a/apps/studio/components/interfaces/Integrations/DataApi/DocView.tsx b/apps/studio/components/interfaces/Integrations/DataApi/DocView.tsxnew file mode 100644index 00000000000..7316245f00e--- /dev/null+++ b/apps/studio/components/interfaces/Integrations/DataApi/DocView.tsx@@ -0,0 +1,76 @@+import { useParams } from 'common'++import type { ShowApiKey } from '../../Docs/Docs.types'+import { GeneralContent } from '@/components/interfaces/Docs/GeneralContent'+import { ResourceContent } from '@/components/interfaces/Docs/ResourceContent'+import { RpcContent } from '@/components/interfaces/Docs/RpcContent'+import {+ buildEntityMaps,+ getProjectApiEndpoint,+} from '@/components/interfaces/Integrations/DataApi/DataApi.utils'+import { DocViewError } from '@/components/interfaces/Integrations/DataApi/DocViewError'+import { DocViewLoading } from '@/components/interfaces/Integrations/DataApi/DocViewLoading'+import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query'+import { useCustomDomainsQuery } from '@/data/custom-domains/custom-domains-query'+import { useProjectJsonSchemaQuery } from '@/data/docs/project-json-schema-query'++interface DocViewProps {+ selectedLang: 'js' | 'bash'+ selectedApiKey: ShowApiKey+}++export const DocView = ({ selectedLang, selectedApiKey }: DocViewProps) => {+ const { ref: projectRef, page, resource, rpc } = useParams()++ const { data: settings, error: settingsError } = useProjectSettingsV2Query({ projectRef })+ const {+ data: jsonSchema,+ error: jsonSchemaError,+ isPending: isLoading,+ refetch,+ } = useProjectJsonSchemaQuery({ projectRef })+ const { data: customDomainData } = useCustomDomainsQuery({ projectRef })++ const endpoint = getProjectApiEndpoint({ settings, customDomainData })++ const { paths } = jsonSchema || {}+ const PAGE_KEY = resource || rpc || page || 'index'++ const { resources, rpcs } = buildEntityMaps(paths)++ if (settingsError || jsonSchemaError) {+ return <DocViewError error={settingsError || jsonSchemaError} />+ }++ if (isLoading || !settings || !jsonSchema) {+ return <DocViewLoading />+ }++ return (+ <div className="w-full h-full overflow-y-auto flex flex-col" key={PAGE_KEY}>+ <div className="flex-1 flex flex-col">+ {resource ? (+ <ResourceContent+ apiEndpoint={endpoint}+ selectedLang={selectedLang}+ resourceId={resource}+ resources={resources}+ showApiKey={selectedApiKey.key}+ refreshDocs={refetch}+ />+ ) : rpc ? (+ <RpcContent+ selectedLang={selectedLang}+ rpcId={rpc}+ paths={paths}+ rpcs={rpcs}+ showApiKey={selectedApiKey.key}+ refreshDocs={refetch}+ />+ ) : (+ <GeneralContent selectedLang={selectedLang} showApiKey={selectedApiKey.key} page={page} />+ )}+ </div>+ </div>+ )+}diff --git a/apps/studio/components/interfaces/Integrations/DataApi/DocViewError.tsx b/apps/studio/components/interfaces/Integrations/DataApi/DocViewError.tsxnew file mode 100644index 00000000000..02bdf11d74a--- /dev/null+++ b/apps/studio/components/interfaces/Integrations/DataApi/DocViewError.tsx@@ -0,0 +1,14 @@+interface DocViewErrorProps {+ error: Error | null+}++export const DocViewError = ({ error }: DocViewErrorProps) => {+ return (+ <div className="p-6 mx-auto text-center sm:w-full md:w-3/4">+ <div className="text-foreground-light">+ <p>Error connecting to API</p>+ <p>{error?.message ?? 'An unexpected error occurred'}</p>+ </div>+ </div>+ )+}diff --git a/apps/studio/components/interfaces/Integrations/DataApi/DocViewLoading.tsx b/apps/studio/components/interfaces/Integrations/DataApi/DocViewLoading.tsxnew file mode 100644index 00000000000..87d27d4d4fa--- /dev/null+++ b/apps/studio/components/interfaces/Integrations/DataApi/DocViewLoading.tsx@@ -0,0 +1,12 @@+import { ShimmeringLoader } from 'ui-patterns'++export const DocViewLoading = () => {+ return (+ <div className="w-full h-full overflow-y-auto flex flex-col py-10 space-y-2">+ <ShimmeringLoader className="h-2 w-24 max-w-full" />+ <ShimmeringLoader className="h-2 w-96 max-w-full" />+ <ShimmeringLoader className="h-2 w-96 max-w-full" />+ <ShimmeringLoader className="h-2 w-96 max-w-full" />+ </div>+ )+}diff --git a/apps/studio/components/interfaces/Integrations/DataApi/DocsMenu.tsx b/apps/studio/components/interfaces/Integrations/DataApi/DocsMenu.tsxnew file mode 100644index 00000000000..e514c777660--- /dev/null+++ b/apps/studio/components/interfaces/Integrations/DataApi/DocsMenu.tsx@@ -0,0 +1,83 @@+import Link from 'next/link'+import { cn } from 'ui'++import { ProductMenuGroup } from '@/components/ui/ProductMenu/ProductMenu.types'++export const DocsMenu = ({+ menu,+ activePage,+}: {+ menu: Array<ProductMenuGroup>+ activePage?: string+}) => {+ return (+ <nav className="space-y-6 text-xs">+ {menu.map((group, idx) => (+ <div key={group.key || group.title || idx}>+ {group.title && (+ <div className="heading-meta mb-2 text-foreground-lighter">{group.title}</div>+ )}+ <div className="space-y-2">+ {group.items.map((item) => {+ const isActive = item.pages+ ? item.pages.includes(activePage ?? '')+ : activePage === item.key+ const isDisabled = !!item.disabled+ const content = (+ <span+ className={cn(+ 'flex items-center',+ isActive ? 'text-foreground' : 'text-foreground-light hover:text-foreground'+ )}+ >+ <span className="truncate">{item.name}</span>+ {item.rightIcon && (+ <span className="ml-auto text-foreground-lighter">{item.rightIcon}</span>+ )}+ </span>+ )++ if (isDisabled) {+ return (+ <span+ key={item.key}+ className="block pointer-events-none opacity-50"+ aria-disabled="true"+ tabIndex={-1}+ >+ {content}+ </span>+ )+ }++ if (item.isExternal) {+ return (+ <a+ key={item.key}+ href={item.url}+ target="_blank"+ rel="noopener noreferrer"+ className="block"+ >+ {content}+ </a>+ )+ }++ return (+ <Link+ key={item.key}+ href={item.url}+ className="block"+ aria-current={isActive ? 'page' : undefined}+ >+ {content}+ </Link>+ )+ })}+ </div>+ </div>+ ))}+ </nav>+ )+}diff --git a/apps/studio/components/interfaces/Integrations/DataApi/DocsMobileNav.tsx b/apps/studio/components/interfaces/Integrations/DataApi/DocsMobileNav.tsxnew file mode 100644index 00000000000..379f6703ef2--- /dev/null+++ b/apps/studio/components/interfaces/Integrations/DataApi/DocsMobileNav.tsx@@ -0,0 +1,60 @@+import { Menu } from 'lucide-react'+import { useEffect, useState } from 'react'+import { Button, Sheet, SheetContent, SheetHeader, SheetTitle } from 'ui'++import type { ShowApiKey } from '../../Docs/Docs.types'+import { LangSelector } from '../../Docs/LangSelector'+import { DocsMenu } from '@/components/interfaces/Integrations/DataApi/DocsMenu'+import { ProductMenuGroup } from '@/components/ui/ProductMenu/ProductMenu.types'++interface DocsMobileNavProps {+ activePage: string+ menu: Array<ProductMenuGroup>+ selectedLang: 'js' | 'bash'+ selectedApiKey: ShowApiKey+ setSelectedLang: (lang: 'js' | 'bash') => void+ setSelectedApiKey: (key: ShowApiKey) => void+}++export const DocsMobileNav = ({+ activePage,+ menu,+ selectedLang,+ selectedApiKey,+ setSelectedLang,+ setSelectedApiKey,+}: DocsMobileNavProps) => {+ const [open, setOpen] = useState(false)++ // Close mobile nav when the active page changes+ useEffect(() => {+ setOpen(false)+ }, [activePage])++ return (+ <>+ <div className="sticky top-0 z-10 flex lg:hidden items-center border-b bg-surface-100 px-4 py-3">+ <Button type="default" icon={<Menu size={16} />} onClick={() => setOpen(true)}>+ Menu+ </Button>+ </div>++ <Sheet open={open} onOpenChange={setOpen}>+ <SheetContent side="left" size="content" className="w-72 overflow-y-auto">+ <SheetHeader className="border-b-0">+ <SheetTitle>Data API Docs</SheetTitle>+ </SheetHeader>+ <div className="flex flex-col gap-y-6 px-5 pb-6">+ <LangSelector+ selectedLang={selectedLang}+ selectedApiKey={selectedApiKey}+ setSelectedLang={setSelectedLang}+ setSelectedApiKey={setSelectedApiKey}+ />+ <DocsMenu activePage={activePage} menu={menu} />+ </div>+ </SheetContent>+ </Sheet>+ </>+ )+}diff --git a/apps/studio/components/interfaces/Integrations/DataApi/DocsTab.tsx b/apps/studio/components/interfaces/Integrations/DataApi/DocsTab.tsxnew file mode 100644index 00000000000..859d733578b--- /dev/null+++ b/apps/studio/components/interfaces/Integrations/DataApi/DocsTab.tsx@@ -0,0 +1,91 @@+import { useParams } from 'common'+import { useMemo, useState } from 'react'+import { ShimmeringLoader } from 'ui-patterns'++import type { ShowApiKey } from '../../Docs/Docs.types'+import { LangSelector } from '../../Docs/LangSelector'+import { DataApiDisabledState } from '@/components/interfaces/Integrations/DataApi/DataApiDisabledState'+import { DocsMenu } from '@/components/interfaces/Integrations/DataApi/DocsMenu'+import { DocsMobileNav } from '@/components/interfaces/Integrations/DataApi/DocsMobileNav'+import { DocView } from '@/components/interfaces/Integrations/DataApi/DocView'+import { generateDocsMenu, getActivePage } from '@/components/layouts/DocsLayout/DocsLayout.utils'+import { useOpenAPISpecQuery } from '@/data/open-api/api-spec-query'+import { useIsDataApiEnabled } from '@/hooks/misc/useIsDataApiEnabled'+import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'+import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'+import { PROJECT_STATUS } from '@/lib/constants'++export const DataApiDocsTab = () => {+ const DEFAULT_KEY = { name: 'hide', key: 'SUPABASE_KEY' }+ const { ref: projectRef, page, resource, rpc } = useParams()+ const { data: project } = useSelectedProjectQuery()+ const { projectAuthAll: authEnabled } = useIsFeatureEnabled(['project_auth:all'])+ const isPaused = project?.status === PROJECT_STATUS.INACTIVE++ const [selectedLang, setSelectedLang] = useState<'js' | 'bash'>('js')+ const [selectedApiKey, setSelectedApiKey] = useState<ShowApiKey>(DEFAULT_KEY)++ const { isEnabled, isPending: isConfigLoading } = useIsDataApiEnabled({ projectRef })++ const { data: openApiSpec } = useOpenAPISpecQuery(+ { projectRef },+ {+ enabled: !!projectRef && !isPaused && isEnabled,+ }+ )++ const tableNames = useMemo(+ () => (openApiSpec?.tables ?? []).map((table) => table.name),+ [openApiSpec]+ )+ const functionNames = useMemo(+ () => (openApiSpec?.functions ?? []).map((fn) => fn.name),+ [openApiSpec]+ )++ const activePage = useMemo(() => getActivePage({ page, resource, rpc }), [page, resource, rpc])++ const docsBasePath = projectRef ? `/project/${projectRef}/integrations/data_api/docs` : undefined++ const menu = useMemo(() => {+ if (!projectRef) return []+ return generateDocsMenu(projectRef, tableNames, functionNames, { authEnabled }, docsBasePath)+ }, [projectRef, tableNames, functionNames, authEnabled, docsBasePath])++ if (isConfigLoading) {+ return (+ <div className="flex w-full bg-surface-100 flex-1 items-stretch p-10">+ <ShimmeringLoader className="w-full h-full" />+ </div>+ )+ }++ if (!isEnabled) {+ return <DataApiDisabledState description="view the documentation" />+ }++ return (+ <div className="flex w-full bg-surface-100 flex-1 items-stretch">+ <aside className="hidden lg:flex flex-col gap-y-6 w-60 shrink-0 p-10">+ <LangSelector+ selectedLang={selectedLang}+ selectedApiKey={selectedApiKey}+ setSelectedLang={(lang: 'js' | 'bash') => setSelectedLang(lang)}+ setSelectedApiKey={setSelectedApiKey}+ />+ <DocsMenu activePage={activePage} menu={menu} />+ </aside>+ <div className="flex-1 min-w-0 relative">+ <DocsMobileNav+ activePage={activePage}+ menu={menu}+ selectedLang={selectedLang}+ selectedApiKey={selectedApiKey}+ setSelectedLang={setSelectedLang}+ setSelectedApiKey={setSelectedApiKey}+ />+ <DocView selectedLang={selectedLang} selectedApiKey={selectedApiKey} />+ </div>+ </div>+ )+}diff --git a/apps/studio/components/interfaces/Integrations/DataApi/SettingsTab.tsx b/apps/studio/components/interfaces/Integrations/DataApi/SettingsTab.tsxindex 819323890c7..fba36e35630 100644--- a/apps/studio/components/interfaces/Integrations/DataApi/SettingsTab.tsx+++ b/apps/studio/components/interfaces/Integrations/DataApi/SettingsTab.tsx@@ -1,9 +1,7 @@import { useParams } from 'common'-import { AlertCircle } from 'lucide-react'-import Link from 'next/link'-import { Alert_Shadcn_, AlertDescription_Shadcn_, AlertTitle_Shadcn_ } from 'ui'import { PageContainer } from 'ui-patterns'+import { DataApiDisabledState } from '@/components/interfaces/Integrations/DataApi/DataApiDisabledState'import { ServiceList } from '@/components/interfaces/Settings/API/ServiceList'import { useIsDataApiEnabled } from '@/hooks/misc/useIsDataApiEnabled'@@ -12,24 +10,7 @@ export const DataApiSettingsTab = () => {const { isEnabled, isPending } = useIsDataApiEnabled({ projectRef })if (!isPending && !isEnabled) {- return (- <div className="flex w-full flex-1 items-center justify-center p-10">- <Alert_Shadcn_ className="max-w-md">- <AlertCircle size={16} />- <AlertTitle_Shadcn_>Data API is disabled</AlertTitle_Shadcn_>- <AlertDescription_Shadcn_>- Enable the Data API in the{' '}- <Link- href={`/project/${projectRef}/integrations/data_api/overview`}- className="text-foreground underline hover:decoration-foreground-muted"- >- Overview- </Link>{' '}- tab to configure settings.- </AlertDescription_Shadcn_>- </Alert_Shadcn_>- </div>- )+ return <DataApiDisabledState description="configure settings" />}return (diff --git a/apps/studio/components/interfaces/Integrations/Landing/Integrations.constants.tsx b/apps/studio/components/interfaces/Integrations/Landing/Integrations.constants.tsxindex c9ad5e65f21..56df1d9e3eb 100644--- a/apps/studio/components/interfaces/Integrations/Landing/Integrations.constants.tsx+++ b/apps/studio/components/interfaces/Integrations/Landing/Integrations.constants.tsx@@ -2,13 +2,13 @@ import { Clock5, Code2, Layers, Timer, Vault, Webhook } from 'lucide-react'import dynamic from 'next/dynamic'import Image from 'next/image'import { ComponentType, ReactNode } from 'react'--import { BASE_PATH, DOCS_URL } from 'lib/constants'import { cn } from 'ui'import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'+import { UpgradeDatabaseAlert } from '../Queues/UpgradeDatabaseAlert'import { WRAPPERS } from '../Wrappers/Wrappers.constants'import { WrapperMeta } from '../Wrappers/Wrappers.types'+import { BASE_PATH, DOCS_URL } from '@/lib/constants'export type Navigation = {route: string@@ -35,10 +35,10 @@ export type IntegrationDefinition = {name: stringwebsiteUrl: string}- requiredExtensions: string[]+ requiredExtensions: Array<string>/** Optional component to render if the integration requires extensions that are not available on the current database image */missingExtensionsAlert?: ReactNode- navigation?: Navigation[]+ navigation?: Array<Navigation>navigate: (id: string,pageId: string | undefined,@@ -51,7 +51,7 @@ const authorSupabase = {websiteUrl: 'https://supabase.com',}-const SUPABASE_INTEGRATIONS: IntegrationDefinition[] = [+const SUPABASE_INTEGRATIONS: Array<IntegrationDefinition> = [{id: 'queues',type: 'postgres_extension' as const,@@ -280,6 +280,10 @@ const SUPABASE_INTEGRATIONS: IntegrationDefinition[] = [route: 'settings',label: 'Settings',},+ {+ route: 'docs',+ label: 'Docs',+ },],navigate: (_id: string, pageId: string = 'overview', _childId: string | undefined) => {switch (pageId) {@@ -303,6 +307,16 @@ const SUPABASE_INTEGRATIONS: IntegrationDefinition[] = [loading: Loading,})+ case 'docs':+ return dynamic(+ () =>+ import('components/interfaces/Integrations/DataApi/DocsTab').then(+ (mod) => mod.DataApiDocsTab+ ),+ {+ loading: Loading,+ }+ )}return null},@@ -362,7 +376,7 @@ const SUPABASE_INTEGRATIONS: IntegrationDefinition[] = [},] as const-const WRAPPER_INTEGRATIONS: IntegrationDefinition[] = WRAPPERS.map((w) => {+const WRAPPER_INTEGRATIONS: Array<IntegrationDefinition> = WRAPPERS.map((w) => {return {id: w.name,type: 'wrapper' as const,@@ -413,7 +427,7 @@ const WRAPPER_INTEGRATIONS: IntegrationDefinition[] = WRAPPERS.map((w) => {}})-const TEMPLATE_INTEGRATIONS: IntegrationDefinition[] = [+const TEMPLATE_INTEGRATIONS: Array<IntegrationDefinition> = [{id: 'stripe_sync_engine',type: 'custom' as const,@@ -471,7 +485,7 @@ const TEMPLATE_INTEGRATIONS: IntegrationDefinition[] = [},]-export const INTEGRATIONS: IntegrationDefinition[] = [+export const INTEGRATIONS: Array<IntegrationDefinition> = [...WRAPPER_INTEGRATIONS,...SUPABASE_INTEGRATIONS,...TEMPLATE_INTEGRATIONS,diff --git a/apps/studio/components/interfaces/Linter/Linter.utils.tsx b/apps/studio/components/interfaces/Linter/Linter.utils.tsxindex 40f689d731a..6cf1078d4f3 100644--- a/apps/studio/components/interfaces/Linter/Linter.utils.tsx+++ b/apps/studio/components/interfaces/Linter/Linter.utils.tsx@@ -12,12 +12,12 @@ import {User,} from 'lucide-react'import Link from 'next/link'--import { LINTER_LEVELS, LintInfo } from 'components/interfaces/Linter/Linter.constants'-import { LINT_TYPES, Lint } from 'data/lint/lint-query'-import { DOCS_URL } from 'lib/constants'import { Badge, Button } from 'ui'+import { LINTER_LEVELS, LintInfo } from '@/components/interfaces/Linter/Linter.constants'+import { Lint, LINT_TYPES } from '@/data/lint/lint-query'+import { DOCS_URL } from '@/lib/constants'+export const lintInfoMap: LintInfo[] = [{name: 'unindexed_foreign_keys',@@ -277,7 +277,7 @@ export const lintInfoMap: LintInfo[] = [name: 'leaked_service_key',title: 'Leaked Service Key Detected',icon: <LockIcon className="text-foreground-muted" size={15} strokeWidth={1} />,- link: ({ projectRef }) => `/project/${projectRef}/settings/api`,+ link: ({ projectRef }) => `/project/${projectRef}/settings/api-keys`,linkText: 'View settings',docsLink: `${DOCS_URL}/guides/api/api-keys#the-servicerole-key`,category: 'security',diff --git a/apps/studio/components/interfaces/ProjectAPIDocs/FirstLevelNav.tsx b/apps/studio/components/interfaces/ProjectAPIDocs/FirstLevelNav.tsxindex ce2206a198b..d6b81fb57c3 100644--- a/apps/studio/components/interfaces/ProjectAPIDocs/FirstLevelNav.tsx+++ b/apps/studio/components/interfaces/ProjectAPIDocs/FirstLevelNav.tsx@@ -118,7 +118,7 @@ export const FirstLevelNav = (): ReactNode => {}onClick={() => snap.setShowProjectApiDocs(false)}>- <Link className="!justify-start" href={`/project/${ref}/api/graphiql`}>+ <Link className="!justify-start" href={`/project/${ref}/integrations/graphiql`}>GraphiQL</Link></Button>diff --git a/apps/studio/components/interfaces/ProjectAPIDocs/ProjectAPIDocs.Commands.tsx b/apps/studio/components/interfaces/ProjectAPIDocs/ProjectAPIDocs.Commands.tsxindex ab6ecb60372..7a0bcf3ba2e 100644--- a/apps/studio/components/interfaces/ProjectAPIDocs/ProjectAPIDocs.Commands.tsx+++ b/apps/studio/components/interfaces/ProjectAPIDocs/ProjectAPIDocs.Commands.tsx@@ -13,25 +13,25 @@ export function useApiDocsGotoCommands(options?: CommandOptions) {{id: 'nav-api',name: 'Project API Docs',- route: `/project/${ref}/api`,+ route: `/project/${ref}/integrations/data_api/docs`,defaultHidden: true,},{id: 'nav-api-auth',name: 'Auth Docs',- route: `/project/${ref}/api?page=auth`,+ route: `/project/${ref}/integrations/data_api/docs?page=auth`,defaultHidden: true,},{id: 'nav-api-user-management',name: 'User Management Docs',- route: `/project/${ref}/api?page=users-management`,+ route: `/project/${ref}/integrations/data_api/docs?page=users-management`,defaultHidden: true,},{id: 'nav-api-graphql',name: 'GraphQL Docs',- route: `/project/${ref}/api/graphiql`,+ route: `/project/${ref}/integrations/graphiql`,defaultHidden: true,},],diff --git a/apps/studio/components/interfaces/Settings/API/DataApiProjectUrlCard.tsx b/apps/studio/components/interfaces/Settings/API/DataApiProjectUrlCard.tsxindex bbee03d3ba8..698832d1afe 100644--- a/apps/studio/components/interfaces/Settings/API/DataApiProjectUrlCard.tsx+++ b/apps/studio/components/interfaces/Settings/API/DataApiProjectUrlCard.tsx@@ -22,7 +22,7 @@ import { useReadReplicasQuery } from '@/data/read-replicas/replicas-query'import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'import { useStaticEffectEvent } from '@/hooks/useStaticEffectEvent'import { useDatabaseSelectorStateSnapshot } from '@/state/database-selector'-import { getApiEndpoint } from './DataApiProjectUrlCard.utils'+import { getApiEndpoint } from '@/components/interfaces/Integrations/DataApi/DataApi.utils'export const DataApiProjectUrlCard = () => {const { isPending: isLoading } = useSelectedProjectQuery()diff --git a/apps/studio/components/interfaces/Settings/API/DataApiProjectUrlCard.utils.test.ts b/apps/studio/components/interfaces/Settings/API/DataApiProjectUrlCard.utils.test.tsdeleted file mode 100644index 56bdea65cc6..00000000000--- a/apps/studio/components/interfaces/Settings/API/DataApiProjectUrlCard.utils.test.ts+++ /dev/null@@ -1,120 +0,0 @@-import { describe, expect, it } from 'vitest'--import { getApiEndpoint } from './DataApiProjectUrlCard.utils'-import type {- CustomDomainResponse,- CustomDomainsData,-} from '@/data/custom-domains/custom-domains-query'-import type { LoadBalancer } from '@/data/read-replicas/load-balancers-query'-import type { Database } from '@/data/read-replicas/replicas-query'--const makeCustomDomainData = (hostname: string): CustomDomainsData => ({- customDomain: {- id: '',- ssl: {} as CustomDomainResponse['ssl'],- hostname,- status: 'active',- created_at: '',- custom_metadata: null,- custom_origin_server: '',- },- status: '5_services_reconfigured',-})--const makeDatabase = (- identifier: string,- restUrl: string-): Pick<Database, 'identifier' | 'restUrl'> => ({ identifier, restUrl })--const makeLoadBalancer = (endpoint: string): Pick<LoadBalancer, 'endpoint'> => ({ endpoint })--describe('getApiEndpoint', () => {- it('returns custom domain URL when custom domain is active and primary database is selected', () => {- expect(- getApiEndpoint({- selectedDatabaseId: 'project-ref',- projectRef: 'project-ref',- customDomainData: makeCustomDomainData('api.example.com'),- loadBalancers: undefined,- selectedDatabase: makeDatabase(- 'project-ref',- 'https://project-ref.supabase.co/rest/v1'- ) as Database,- })- ).toBe('https://api.example.com')- })-- it('returns database restUrl when custom domain is active but a replica is selected', () => {- expect(- getApiEndpoint({- selectedDatabaseId: 'replica-1',- projectRef: 'project-ref',- customDomainData: makeCustomDomainData('api.example.com'),- loadBalancers: undefined,- selectedDatabase: makeDatabase(- 'replica-1',- 'https://replica-1.supabase.co/rest/v1'- ) as Database,- })- ).toBe('https://replica-1.supabase.co/rest/v1')- })-- it('returns load balancer endpoint when load balancer is selected', () => {- expect(- getApiEndpoint({- selectedDatabaseId: 'load-balancer',- projectRef: 'project-ref',- customDomainData: undefined,- loadBalancers: [makeLoadBalancer('https://lb.supabase.co') as LoadBalancer],- selectedDatabase: undefined,- })- ).toBe('https://lb.supabase.co')- })-- it('returns empty string when load balancer is selected but none exist', () => {- expect(- getApiEndpoint({- selectedDatabaseId: 'load-balancer',- projectRef: 'project-ref',- customDomainData: undefined,- loadBalancers: undefined,- selectedDatabase: undefined,- })- ).toBe('')- })-- it('returns database restUrl for a normal database selection', () => {- expect(- getApiEndpoint({- selectedDatabaseId: 'project-ref',- projectRef: 'project-ref',- customDomainData: undefined,- loadBalancers: undefined,- selectedDatabase: makeDatabase(- 'project-ref',- 'https://project-ref.supabase.co/rest/v1'- ) as Database,- })- ).toBe('https://project-ref.supabase.co/rest/v1')- })-- it('ignores custom domain when it is not active', () => {- const inactiveCustomDomain: CustomDomainsData = {- customDomain: null,- status: '0_no_hostname_configured',- }-- expect(- getApiEndpoint({- selectedDatabaseId: 'project-ref',- projectRef: 'project-ref',- customDomainData: inactiveCustomDomain,- loadBalancers: undefined,- selectedDatabase: makeDatabase(- 'project-ref',- 'https://project-ref.supabase.co/rest/v1'- ) as Database,- })- ).toBe('https://project-ref.supabase.co/rest/v1')- })-})diff --git a/apps/studio/components/interfaces/Settings/API/DataApiProjectUrlCard.utils.ts b/apps/studio/components/interfaces/Settings/API/DataApiProjectUrlCard.utils.tsdeleted file mode 100644index 880dbbb6c4f..00000000000--- a/apps/studio/components/interfaces/Settings/API/DataApiProjectUrlCard.utils.ts+++ /dev/null@@ -1,34 +0,0 @@-import type { CustomDomainsData } from '@/data/custom-domains/custom-domains-query'-import type { LoadBalancer } from '@/data/read-replicas/load-balancers-query'-import type { Database } from '@/data/read-replicas/replicas-query'--/**- * Resolves the API endpoint URL based on the selected database, custom domain- * status, and load balancer configuration.- */-export function getApiEndpoint({- selectedDatabaseId,- projectRef,- customDomainData,- loadBalancers,- selectedDatabase,-}: {- selectedDatabaseId: string | undefined- projectRef: string | undefined- customDomainData: CustomDomainsData | undefined- loadBalancers: Array<LoadBalancer> | undefined- selectedDatabase: Database | undefined-}): string {- const isCustomDomainActive = customDomainData?.customDomain?.status === 'active'- const loadBalancerSelected = selectedDatabaseId === 'load-balancer'-- if (isCustomDomainActive && selectedDatabaseId === projectRef) {- return `https://${customDomainData.customDomain.hostname}`- }-- if (loadBalancerSelected) {- return loadBalancers?.[0]?.endpoint ?? ''- }-- return selectedDatabase?.restUrl ?? ''-}diff --git a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceNode.tsx b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceNode.tsxindex 46a5afafd94..30c9b1ab014 100644--- a/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceNode.tsx+++ b/apps/studio/components/interfaces/Settings/Infrastructure/InfrastructureConfiguration/InstanceNode.tsx@@ -96,7 +96,9 @@ export const LoadBalancerNode = ({ data }: NodeProps<LoadBalancerData>) => {</DropdownMenuTrigger><DropdownMenuContent className="w-40" side="bottom" align="end"><DropdownMenuItem asChild className="gap-x-2">- <Link href={`/project/${ref}/settings/api?source=load-balancer`}>View API URL</Link>+ <Link href={`/project/${ref}/integrations/data_api/overview?source=load-balancer`}>+ View API URL+ </Link></DropdownMenuItem></DropdownMenuContent></DropdownMenu>diff --git a/apps/studio/components/interfaces/Sidebar.tsx b/apps/studio/components/interfaces/Sidebar.tsxindex 321c961d158..dc65c2d2a1e 100644--- a/apps/studio/components/interfaces/Sidebar.tsx+++ b/apps/studio/components/interfaces/Sidebar.tsx@@ -262,6 +262,7 @@ const ProjectLinks = () => {const otherRoutes = generateOtherRoutes(ref, project, {unifiedLogs: isUnifiedLogsEnabled,showReports,+ apiDocsSidePanel: isNewAPIDocsEnabled,})const settingsRoutes = generateSettingsRoutes(ref, project)diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ApiAccessToggle.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ApiAccessToggle.tsxindex 5b0613c0ee8..5083475f832 100644--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ApiAccessToggle.tsx+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ApiAccessToggle.tsx@@ -483,7 +483,7 @@ const SchemaExposureOptions = ({To enable API access for this table, you need to first expose the{' '}<code className="text-xs">{schemaName}</code> schema in your{' '}<Link- href={`/project/${projectRef}/settings/api`}+ href={`/project/${projectRef}/integrations/data_api/overview`}className="text-foreground hover:underline">API settingsdiff --git a/apps/studio/components/layouts/DocsLayout/DocsLayout.tsx b/apps/studio/components/layouts/DocsLayout/DocsLayout.tsxindex c8679c24aa6..1046fbc4a6d 100644--- a/apps/studio/components/layouts/DocsLayout/DocsLayout.tsx+++ b/apps/studio/components/layouts/DocsLayout/DocsLayout.tsx@@ -11,7 +11,7 @@ import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'import { withAuth } from 'hooks/misc/withAuth'import { PROJECT_STATUS } from 'lib/constants'import { ProjectLayout } from '../ProjectLayout'-import { generateDocsMenu } from './DocsLayout.utils'+import { generateDocsMenu, getActivePage } from './DocsLayout.utils'function DocsLayout({ title, children }: { title: string; children: ReactElement }) {const router = useRouter()@@ -34,8 +34,11 @@ function DocsLayout({ title, children }: { title: string; children: ReactElementif (router.pathname.endsWith('graphiql')) return 'graphiql'const { page, rpc, resource } = router.query- if (!page && !resource && !rpc) return 'introduction'- return (page || rpc || resource || '') as string+ return getActivePage({+ page: page as string | undefined,+ resource: resource as string | undefined,+ rpc: rpc as string | undefined,+ })}if (error) {diff --git a/apps/studio/components/layouts/DocsLayout/DocsLayout.utils.tsx b/apps/studio/components/layouts/DocsLayout/DocsLayout.utils.tsxindex 2356d309900..d1586daaa85 100644--- a/apps/studio/components/layouts/DocsLayout/DocsLayout.utils.tsx+++ b/apps/studio/components/layouts/DocsLayout/DocsLayout.utils.tsx@@ -1,23 +1,37 @@-import type { ProductMenuGroup } from 'components/ui/ProductMenu/ProductMenu.types'-import { BASE_PATH, DOCS_URL } from 'lib/constants'import { ArrowUpRight, Book, BookOpen } from 'lucide-react'import SVG from 'react-inlinesvg'+import type { ProductMenuGroup } from '@/components/ui/ProductMenu/ProductMenu.types'+import { BASE_PATH, DOCS_URL } from '@/lib/constants'++export const getActivePage = (params: {+ page?: string+ resource?: string+ rpc?: string+}): string => {+ const { page, resource, rpc } = params+ if (!page && !resource && !rpc) return 'introduction'+ return (page || rpc || resource) as string+}+export const generateDocsMenu = (ref: string,- tables: string[],- functions: string[],- flags?: { authEnabled: boolean }-): ProductMenuGroup[] => {+ tables: Array<string>,+ functions: Array<string>,+ flags?: { authEnabled: boolean },+ basePath?: string+): Array<ProductMenuGroup> => {+ const docsBasePath = basePath ?? `/project/${ref}/integrations/data_api/docs`+return [{title: 'Getting Started',items: [- { name: 'Introduction', key: 'introduction', url: `/project/${ref}/api`, items: [] },+ { name: 'Introduction', key: 'introduction', url: docsBasePath, items: [] },{name: 'Authentication',key: 'auth',- url: `/project/${ref}/api?page=auth`,+ url: `${docsBasePath}?page=auth`,items: [],},...(flags?.authEnabled@@ -25,7 +39,7 @@ export const generateDocsMenu = ({name: 'User Management',key: 'users-management',- url: `/project/${ref}/api?page=users-management`,+ url: `${docsBasePath}?page=users-management`,items: [],},]@@ -38,14 +52,14 @@ export const generateDocsMenu = ({name: 'Introduction',key: 'tables-intro',- url: `/project/${ref}/api?page=tables-intro`,+ url: `${docsBasePath}?page=tables-intro`,items: [],},...tables.sort().map((table) => {return {name: table,key: table,- url: `/project/${ref}/api?resource=${table}`,+ url: `${docsBasePath}?resource=${table}`,items: [],}}),@@ -57,11 +71,11 @@ export const generateDocsMenu = ({name: 'Introduction',key: 'rpc-intro',- url: `/project/${ref}/api?page=rpc-intro`,+ url: `${docsBasePath}?page=rpc-intro`,items: [],},...functions.map((fn) => {- return { name: fn, key: fn, url: `/project/${ref}/api?rpc=${fn}`, items: [] }+ return { name: fn, key: fn, url: `${docsBasePath}?rpc=${fn}`, items: [] }}),],},diff --git a/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.utils.tsx b/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.utils.tsxindex 5914bd62821..4a06b218dfe 100644--- a/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.utils.tsx+++ b/apps/studio/components/layouts/ProjectLayout/NavigationBar/NavigationBar.utils.tsx@@ -121,14 +121,15 @@ export const generateProductRoutes = (export const generateOtherRoutes = (ref?: string,project?: Project,- features?: { unifiedLogs?: boolean; showReports?: boolean }+ features?: { unifiedLogs?: boolean; showReports?: boolean; apiDocsSidePanel?: boolean }): Route[] => {const isProjectBuilding = project?.status === PROJECT_STATUS.COMING_UPconst buildingUrl = `/project/${ref}`- const { unifiedLogs, showReports } = features ?? {}+ const { unifiedLogs, showReports, apiDocsSidePanel } = features ?? {}const unifiedLogsEnabled = unifiedLogs ?? falseconst reportsEnabled = showReports ?? true+ const apiDocsSidePanelEnabled = apiDocsSidePanel ?? falsereturn [{@@ -159,12 +160,18 @@ export const generateOtherRoutes = (? `/project/${ref}/logs`: `/project/${ref}/logs/explorer`),},- {- key: 'api',- label: 'API Docs',- icon: <FileText size={ICON_SIZE} strokeWidth={ICON_STROKE_WIDTH} />,- link: ref && (isProjectBuilding ? buildingUrl : `/project/${ref}/api`),- },+ ...(apiDocsSidePanelEnabled+ ? [+ {+ key: 'api',+ label: 'API Docs',+ icon: <FileText size={ICON_SIZE} strokeWidth={ICON_STROKE_WIDTH} />,+ link:+ ref &&+ (isProjectBuilding ? buildingUrl : `/project/${ref}/integrations/data_api/docs`),+ },+ ]+ : []),{key: 'integrations',label: 'Integrations',diff --git a/apps/studio/components/layouts/ProjectSettingsLayout/ProjectSettings.Commands.tsx b/apps/studio/components/layouts/ProjectSettingsLayout/ProjectSettings.Commands.tsxindex b5c5e893a02..0caaf7a425b 100644--- a/apps/studio/components/layouts/ProjectSettingsLayout/ProjectSettings.Commands.tsx+++ b/apps/studio/components/layouts/ProjectSettingsLayout/ProjectSettings.Commands.tsx@@ -1,11 +1,12 @@-import { useRouter } from 'next/router'import { useParams } from 'common'-import { COMMAND_MENU_SECTIONS } from 'components/interfaces/App/CommandMenu/CommandMenu.utils'-import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'+import { useRouter } from 'next/router'import type { CommandOptions, ICommand } from 'ui-patterns/CommandMenu'import { useRegisterCommands, useSetCommandMenuOpen } from 'ui-patterns/CommandMenu'import { IRouteCommand } from 'ui-patterns/CommandMenu/internal/types'+import { COMMAND_MENU_SECTIONS } from '@/components/interfaces/App/CommandMenu/CommandMenu.utils'+import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'+export function useProjectSettingsGotoCommands(options?: CommandOptions) {const router = useRouter()const setIsOpen = useSetCommandMenuOpen()@@ -45,7 +46,7 @@ export function useProjectSettingsGotoCommands(options?: CommandOptions) {{id: 'nav-project-settings-api',name: 'API Settings',- route: `/project/${ref}/settings/api`,+ route: `/project/${ref}/integrations/data_api/settings`,defaultHidden: true,},{diff --git a/apps/studio/next.config.js b/apps/studio/next.config.jsindex b440009d0d9..c615c69b2b3 100644--- a/apps/studio/next.config.js+++ b/apps/studio/next.config.js@@ -444,6 +444,11 @@ const nextConfig = {destination: '/project/:ref/integrations/data_api/overview',permanent: false,},+ {+ source: '/project/:ref/api',+ destination: '/project/:ref/integrations/data_api/docs',+ permanent: false,+ },...(process.env.NEXT_PUBLIC_BASE_PATH?.length? [diff --git a/apps/studio/pages/project/[ref]/api/index.tsx b/apps/studio/pages/project/[ref]/api/index.tsxindex 045bd19fe92..d03be4be4fe 100644--- a/apps/studio/pages/project/[ref]/api/index.tsx+++ b/apps/studio/pages/project/[ref]/api/index.tsx@@ -1,152 +1,25 @@import { useParams } from 'common'-import { useState } from 'react'+import { useRouter } from 'next/router'+import { useEffect } from 'react'-import { GeneralContent } from 'components/interfaces/Docs/GeneralContent'-import { LangSelector } from 'components/interfaces/Docs/LangSelector'-import { ResourceContent } from 'components/interfaces/Docs/ResourceContent'-import { RpcContent } from 'components/interfaces/Docs/RpcContent'-import DefaultLayout from 'components/layouts/DefaultLayout'-import DocsLayout from 'components/layouts/DocsLayout/DocsLayout'-import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'-import { useCustomDomainsQuery } from 'data/custom-domains/custom-domains-query'-import { useProjectJsonSchemaQuery } from 'data/docs/project-json-schema-query'-import { snakeToCamel } from 'lib/helpers'-import type { NextPageWithLayout } from 'types'+import type { NextPageWithLayout } from '@/types'-const PageConfig: NextPageWithLayout = () => {- return <DocView />-}--PageConfig.getLayout = (page) => (- <DefaultLayout>- <DocsLayout title="API">{page}</DocsLayout>- </DefaultLayout>-)--export default PageConfig--const DocView = () => {- const functionPath = 'rpc/'- const DEFAULT_KEY = { name: 'hide', key: 'SUPABASE_KEY' }-- const { ref: projectRef, page, resource, rpc } = useParams()- const [selectedLang, setSelectedLang] = useState<any>('js')- const [selectedApikey, setSelectedApiKey] = useState<any>(DEFAULT_KEY)-- const { data: settings, error: settingsError } = useProjectSettingsV2Query({ projectRef })- const {- data: jsonSchema,- error: jsonSchemaError,- isPending: isLoading,- refetch,- } = useProjectJsonSchemaQuery({ projectRef })- const { data: customDomainData } = useCustomDomainsQuery({ projectRef })-- const refreshDocs = async () => await refetch()+const ApiDocsRedirect: NextPageWithLayout = () => {+ const router = useRouter()+ const { ref } = useParams()- const protocol = settings?.app_config?.protocol ?? 'https'- const hostEndpoint = settings?.app_config?.endpoint- const endpoint =- customDomainData?.customDomain?.status === 'active'- ? `https://${customDomainData.customDomain?.hostname}`- : `${protocol}://${hostEndpoint ?? '-'}`+ useEffect(() => {+ if (!router.isReady || !ref) return+ const { ref: _ref, ...query } = router.query+ router.replace({+ pathname: `/project/${ref}/integrations/data_api/docs`,+ query,+ })+ }, [router, ref])- const { paths } = jsonSchema || {}- const PAGE_KEY: any = resource || rpc || page || 'index'-- const { resources, rpcs } = Object.entries(paths || {}).reduce(- (a, [name]) => {- const trimmedName = name.slice(1)- const id = trimmedName.replace(functionPath, '')-- const displayName = id.replace(/_/g, ' ')- const camelCase = snakeToCamel(id)- const enriched = { id, displayName, camelCase }-- if (!trimmedName.length) {- return a- }-- return {- resources: {- ...a.resources,- ...(!trimmedName.includes(functionPath)- ? {- [id]: enriched,- }- : {}),- },- rpcs: {- ...a.rpcs,- ...(trimmedName.includes(functionPath)- ? {- [id]: enriched,- }- : {}),- },- }- },- { resources: {}, rpcs: {} }- )-- if (settingsError || jsonSchemaError) {- return (- <div className="p-6 mx-auto text-center sm:w-full md:w-3/4">- <p className="text-foreground-light">- <p>Error connecting to API</p>- <p>{`${settingsError || jsonSchemaError}`}</p>- </p>- </div>- )- }+ return null+}- if (isLoading || !settings || !jsonSchema) {- return (- <div className="p-6 mx-auto text-center sm:w-full md:w-3/4">- <h3 className="text-xl">Building docs ...</h3>- </div>- )- }+ApiDocsRedirect.getLayout = (page) => <>{page}</>- return (- <div className="w-full h-full overflow-y-auto Docs Docs--api-page" key={PAGE_KEY}>- <div className="Docs--inner-wrapper">- <div className="sticky top-0 z-40 flex flex-row-reverse w-full ">- <LangSelector- selectedLang={selectedLang}- selectedApiKey={selectedApikey}- setSelectedLang={setSelectedLang}- setSelectedApiKey={setSelectedApiKey}- />- </div>- <div>- {resource ? (- <ResourceContent- apiEndpoint={endpoint}- selectedLang={selectedLang}- resourceId={resource}- resources={resources}- showApiKey={selectedApikey.key}- refreshDocs={refreshDocs}- />- ) : rpc ? (- <RpcContent- selectedLang={selectedLang}- rpcId={rpc}- paths={paths}- rpcs={rpcs}- showApiKey={selectedApikey.key}- refreshDocs={refreshDocs}- />- ) : (- <GeneralContent- selectedLang={selectedLang}- showApiKey={selectedApikey.key}- page={page}- />- )}- </div>- </div>- </div>- )-}+export default ApiDocsRedirect