Skip to content

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

Use live and open-api proxy

Joshen Limf961b9040ba1
diff --git a/studio/components/interfaces/Functions/EdgeFunctionDetails.tsx b/studio/components/interfaces/Functions/EdgeFunctionDetails.tsx
index c93c1fefb66..10c2fffa641 100644
--- a/studio/components/interfaces/Functions/EdgeFunctionDetails.tsx
+++ b/studio/components/interfaces/Functions/EdgeFunctionDetails.tsx
@@ -47,7 +47,7 @@ const EdgeFunctionDetails: FC<Props> = () => {
const apiService = settings?.autoApiService
const anonKey = apiService?.service_api_keys.find((x) => x.name === 'anon key')
? apiService.defaultApiKey
- : undefined
+ : '[YOUR ANON KEY]'
const endpoint = apiService?.app_config.endpoint ?? ''
const endpointSections = endpoint.split('.')
diff --git a/studio/components/interfaces/Functions/TerminalInstructions.tsx b/studio/components/interfaces/Functions/TerminalInstructions.tsx
index 16a2e2eea21..a5770812ef0 100644
--- a/studio/components/interfaces/Functions/TerminalInstructions.tsx
+++ b/studio/components/interfaces/Functions/TerminalInstructions.tsx
@@ -23,7 +23,7 @@ const TerminalInstructions: FC<Props> = ({ closable = false, removeBorder = fals
const apiService = settings?.autoApiService
const anonKey = apiService?.service_api_keys.find((x) => x.name === 'anon key')
? apiService.defaultApiKey
- : undefined
+ : '[YOUR ANON KEY]'
const endpoint = settings?.autoApiService.app_config.endpoint ?? ''
const endpointSections = endpoint.split('.')
diff --git a/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx b/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
index 158d28883b5..de8c2b04ddf 100644
--- a/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
+++ b/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
@@ -122,17 +122,12 @@ const TableGridEditor: FC<Props> = ({
const anonKey = apiService?.service_api_keys.find((x) => x.name === 'anon key')
? apiService.defaultApiKey
: undefined
- const swaggerUrl = settings?.autoApiService?.restUrl
const {
data: jsonSchema,
error: jsonSchemaError,
refetch,
- } = useProjectJsonSchemaQuery({
- projectRef,
- swaggerUrl,
- apiKey: anonKey,
- })
+ } = useProjectJsonSchemaQuery({ projectRef })
if (jsonSchemaError) console.log('jsonSchemaError', jsonSchemaError)
diff --git a/studio/components/layouts/ProjectLayout/ConnectingState.tsx b/studio/components/layouts/ProjectLayout/ConnectingState.tsx
index a4124474256..4378343983b 100644
--- a/studio/components/layouts/ProjectLayout/ConnectingState.tsx
+++ b/studio/components/layouts/ProjectLayout/ConnectingState.tsx
@@ -37,9 +37,7 @@ const ConnectingState: FC<Props> = ({ project }) => {
}, [project])
const testProjectConnection = async () => {
- const result = await pingPostgrest(project.restUrl!, project.ref, {
- kpsVersion: project.kpsVersion,
- })
+ const result = await pingPostgrest(project.ref, { kpsVersion: project.kpsVersion })
if (result) {
clearInterval(checkProjectConnectionIntervalRef.current)
app.onProjectPostgrestStatusUpdated(project.id, 'ONLINE')
diff --git a/studio/components/to-be-cleaned/Docs/Pages/Authentication.js b/studio/components/to-be-cleaned/Docs/Pages/Authentication.js
index 4ad66d322f3..651fe8142e7 100644
--- a/studio/components/to-be-cleaned/Docs/Pages/Authentication.js
+++ b/studio/components/to-be-cleaned/Docs/Pages/Authentication.js
@@ -5,9 +5,13 @@ import CodeSnippet from '../CodeSnippet'
export default function Authentication({ autoApiService, selectedLang, showApiKey }) {
// [Joshen] ShowApiKey should really be a boolean, its confusing
const defaultApiKey =
- showApiKey !== 'SUPABASE_KEY' ? autoApiService.defaultApiKey : 'SUPABASE_CLIENT_API_KEY'
+ showApiKey !== 'SUPABASE_KEY'
+ ? autoApiService?.defaultApiKey ?? 'SUPABASE_CLIENT_API_KEY'
+ : 'SUPABASE_CLIENT_API_KEY'
const serviceApiKey =
- showApiKey !== 'SUPABASE_KEY' ? autoApiService.serviceApiKey : 'SUPABASE_SERVICE_KEY'
+ showApiKey !== 'SUPABASE_KEY'
+ ? autoApiService?.serviceApiKey ?? 'SUPABASE_SERVICE_KEY'
+ : 'SUPABASE_SERVICE_KEY'
return (
<>
diff --git a/studio/data/docs/keys.ts b/studio/data/docs/keys.ts
index b0f66362945..266c1512311 100644
--- a/studio/data/docs/keys.ts
+++ b/studio/data/docs/keys.ts
@@ -1,7 +1,3 @@
export const docsKeys = {
- jsonSchema: (
- projectRef: string | undefined,
- swaggerUrl: string | undefined,
- apiKey: string | undefined
- ) => ['projects', projectRef, 'docs', { swaggerUrl, apiKey }] as const,
+ jsonSchema: (projectRef: string | undefined) => ['projects', projectRef, 'docs'] as const,
}
diff --git a/studio/data/docs/project-json-schema-query.ts b/studio/data/docs/project-json-schema-query.ts
index f37f6dd55cb..a70c59c6d96 100644
--- a/studio/data/docs/project-json-schema-query.ts
+++ b/studio/data/docs/project-json-schema-query.ts
@@ -1,41 +1,26 @@
import { useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'
import { get } from 'lib/common/fetch'
+import { API_URL } from 'lib/constants'
import { useCallback } from 'react'
import { docsKeys } from './keys'
export type ProjectJsonSchemaVariables = {
projectRef?: string
- swaggerUrl?: string
- apiKey?: string
}
export type ProjectJsonSchemaResponse = any
export async function getProjectJsonSchema(
- { projectRef, swaggerUrl, apiKey }: ProjectJsonSchemaVariables,
+ { projectRef }: ProjectJsonSchemaVariables,
signal?: AbortSignal
) {
if (!projectRef) {
throw new Error('projectRef is required')
}
- if (!swaggerUrl) {
- throw new Error('id is required')
- }
-
- let headers: {
- [key: string]: string | undefined
- } = { apikey: apiKey }
- if ((apiKey?.length ?? 0) > 40) headers['Authorization'] = `Bearer ${apiKey}`
-
- const response = await get(swaggerUrl, {
- signal,
- headers,
- credentials: 'omit',
- })
- if (response.error) {
- throw response.error
- }
+ const url = `${API_URL}/projects/${projectRef}/open-api`
+ const response = await get(url, { signal })
+ if (response.error) throw response.error
return response as ProjectJsonSchemaResponse
}
@@ -43,33 +28,29 @@ export type ProjectJsonSchemaData = Awaited<ReturnType<typeof getProjectJsonSche
export type ProjectJsonSchemaError = unknown
export const useProjectJsonSchemaQuery = <TData = ProjectJsonSchemaData>(
- { projectRef, swaggerUrl, apiKey }: ProjectJsonSchemaVariables,
+ { projectRef }: ProjectJsonSchemaVariables,
{
enabled = true,
...options
}: UseQueryOptions<ProjectJsonSchemaData, ProjectJsonSchemaError, TData> = {}
) =>
useQuery<ProjectJsonSchemaData, ProjectJsonSchemaError, TData>(
- docsKeys.jsonSchema(projectRef, swaggerUrl, apiKey),
- ({ signal }) => getProjectJsonSchema({ projectRef, swaggerUrl, apiKey }, signal),
+ docsKeys.jsonSchema(projectRef),
+ ({ signal }) => getProjectJsonSchema({ projectRef }, signal),
{
- enabled: enabled && typeof projectRef !== 'undefined' && typeof swaggerUrl !== 'undefined',
+ enabled: enabled && typeof projectRef !== 'undefined',
...options,
}
)
-export const useProjectJsonSchemaPrefetch = ({
- projectRef,
- swaggerUrl,
- apiKey,
-}: ProjectJsonSchemaVariables) => {
+export const useProjectJsonSchemaPrefetch = ({ projectRef }: ProjectJsonSchemaVariables) => {
const client = useQueryClient()
return useCallback(() => {
- if (projectRef && swaggerUrl) {
- client.prefetchQuery(docsKeys.jsonSchema(projectRef, swaggerUrl, apiKey), ({ signal }) =>
- getProjectJsonSchema({ projectRef, swaggerUrl, apiKey }, signal)
+ if (projectRef) {
+ client.prefetchQuery(docsKeys.jsonSchema(projectRef), ({ signal }) =>
+ getProjectJsonSchema({ projectRef }, signal)
)
}
- }, [projectRef, swaggerUrl])
+ }, [projectRef])
}
diff --git a/studio/lib/pingPostgrest.ts b/studio/lib/pingPostgrest.ts
index 623775327d8..1680fffe296 100644
--- a/studio/lib/pingPostgrest.ts
+++ b/studio/lib/pingPostgrest.ts
@@ -2,6 +2,8 @@ import semver from 'semver'
import { headWithTimeout, getWithTimeout } from './common/fetch'
import { API_URL } from './constants'
+const DEFAULT_TIMEOUT_MILLISECONDS = 2000
+
/**
* Ping Postgrest for health check. Default timeout in 2s.
*
@@ -15,7 +17,6 @@ import { API_URL } from './constants'
* @return true if ping is successful else false
*/
async function pingPostgrest(
- restUrl: string,
projectRef: string,
options?: {
kpsVersion?: string
@@ -23,8 +24,6 @@ async function pingPostgrest(
}
) {
if (projectRef === undefined) return false
- const apiKey = await getApiKey(projectRef, options?.timeout)
- if (apiKey === undefined) return false
const { kpsVersion, timeout } = options ?? {}
const healthCheckApiEnable = semver.gte(
@@ -33,35 +32,21 @@ async function pingPostgrest(
semver.coerce('kps-v3.8.6')
)
if (healthCheckApiEnable) {
- const healthCheckUrl = `${restUrl.replace('/rest/', '/rest-admin/')}live`
- return pingHealthCheckApi(healthCheckUrl, apiKey, timeout)
+ return pingHealthCheckApi(projectRef, timeout)
+ } else {
+ return pingOpenApi(projectRef, timeout)
}
-
- return pingOpenApi(restUrl, apiKey, timeout)
}
-export default pingPostgrest
-const getApiKey = async (
- projectRef: string,
- timeout = DEFAULT_TIMEOUT_MILLISECONDS
-): Promise<string | undefined> => {
- const response = await getWithTimeout(`${API_URL}/props/project/${projectRef}/api`, { timeout })
- if (response.error || response.autoApiService.service_api_keys.length === 0) return undefined
- return response.autoApiService.defaultApiKey
-}
-
-const DEFAULT_TIMEOUT_MILLISECONDS = 2000
+export default pingPostgrest
/**
* Send a HEAD request to postgrest OpenAPI.
*
* @return true if there's no error else false
*/
-async function pingOpenApi(url: string, apikey: string, timeout?: number) {
- const headers = { apikey, Authorization: `Bearer ${apikey}` }
- const { error } = await headWithTimeout(url, [], {
- headers,
- credentials: 'omit',
+async function pingOpenApi(ref: string, timeout?: number) {
+ const { error } = await headWithTimeout(`${API_URL}/projects/${ref}/open-api`, [], {
timeout: timeout ?? DEFAULT_TIMEOUT_MILLISECONDS,
})
return error === undefined
@@ -72,11 +57,8 @@ async function pingOpenApi(url: string, apikey: string, timeout?: number) {
*
* @return true if there's no error else false
*/
-async function pingHealthCheckApi(url: string, apikey: string, timeout?: number) {
- const headers = { apikey }
- const { error } = await getWithTimeout(url, {
- headers,
- credentials: 'omit',
+async function pingHealthCheckApi(ref: string, timeout?: number) {
+ const { error } = await getWithTimeout(`${API_URL}/projects/${ref}/live`, {
timeout: timeout ?? DEFAULT_TIMEOUT_MILLISECONDS,
})
return error === undefined
diff --git a/studio/pages/project/[ref]/api/index.tsx b/studio/pages/project/[ref]/api/index.tsx
index 5f4e22b9031..3ceb55c3383 100644
--- a/studio/pages/project/[ref]/api/index.tsx
+++ b/studio/pages/project/[ref]/api/index.tsx
@@ -77,17 +77,12 @@ const DocView: FC<any> = observer(({}) => {
const anonKey = apiService?.service_api_keys.find((x) => x.name === 'anon key')
? apiService.defaultApiKey
: undefined
- const swaggerUrl = data?.autoApiService?.restUrl
const {
data: jsonSchema,
error: jsonSchemaError,
refetch,
- } = useProjectJsonSchemaQuery({
- projectRef,
- swaggerUrl,
- apiKey: anonKey,
- })
+ } = useProjectJsonSchemaQuery({ projectRef })
useEffect(() => {
PageState.setJsonSchema(jsonSchema)
diff --git a/studio/pages/project/[ref]/reports/query-performance.tsx b/studio/pages/project/[ref]/reports/query-performance.tsx
index 5bd5bed4459..ea6acc972d9 100644
--- a/studio/pages/project/[ref]/reports/query-performance.tsx
+++ b/studio/pages/project/[ref]/reports/query-performance.tsx
@@ -62,7 +62,7 @@ const QueryPerformanceReport: NextPageWithLayout = () => {
It relies on the \`pg_stat_statements\` table. Read more about [examining query performance]((https://supabase.com/docs/guides/platform/performance#examining-query-performance)).
- Consider resetting the analysis after optimising any queries.
+ Consider resetting the analysis after optimizing any queries.
`
diff --git a/studio/stores/app/ProjectStore.ts b/studio/stores/app/ProjectStore.ts
index d6f13efb066..d43814c29a6 100644
--- a/studio/stores/app/ProjectStore.ts
+++ b/studio/stores/app/ProjectStore.ts
@@ -68,9 +68,7 @@ export default class ProjectStore extends PostgresMetaInterface<Project> {
async pingPostgrest(project: Project): Promise<'ONLINE' | 'OFFLINE' | undefined> {
if (project.status === PROJECT_STATUS.ACTIVE_HEALTHY && project.restUrl) {
- const success = await pingPostgrest(project.restUrl, project.ref, {
- kpsVersion: project.kpsVersion,
- })
+ const success = await pingPostgrest(project.ref, { kpsVersion: project.kpsVersion })
return success ? 'ONLINE' : 'OFFLINE'
}
return undefined
diff --git a/studio/stores/pgmeta/MetaStore.ts b/studio/stores/pgmeta/MetaStore.ts
index 3d0a73e40d0..0ef0f14d607 100644
--- a/studio/stores/pgmeta/MetaStore.ts
+++ b/studio/stores/pgmeta/MetaStore.ts
@@ -183,7 +183,7 @@ export default class MetaStore implements IMetaStore {
this.openApi = new OpenApiStore(
this.rootStore,
- `${API_URL}/props/project/${this.projectRef}/api`
+ `${API_URL}/projects/${this.projectRef}/open-api`
)
this.tables = new TableStore(this.rootStore, `${this.baseUrl}/tables`, this.headers)
this.columns = new ColumnStore(this.rootStore, `${this.baseUrl}/columns`, this.headers)
@@ -895,7 +895,7 @@ export default class MetaStore implements IMetaStore {
this.headers['x-connection-encrypted'] = connectionString
}
- this.openApi.setUrl(`${API_URL}/props/project/${this.projectRef}/api`)
+ this.openApi.setUrl(`${API_URL}/projects/${this.projectRef}/open-api`)
this.openApi.setHeaders(this.headers)
this.tables.setUrl(`${this.baseUrl}/tables`)
diff --git a/studio/stores/pgmeta/OpenApiStore.ts b/studio/stores/pgmeta/OpenApiStore.ts
index 0b8f35150d2..c66a2095989 100644
--- a/studio/stores/pgmeta/OpenApiStore.ts
+++ b/studio/stores/pgmeta/OpenApiStore.ts
@@ -52,17 +52,7 @@ export default class OpenApiStore implements IOpenApiStore {
}
async fetchData() {
- const headers = { 'Content-Type': 'application/json', ...this.headers }
- const projectConfig = await get(this.url, { headers })
- if (projectConfig.error) throw projectConfig.error
-
- const apiKey = projectConfig.autoApiService?.defaultApiKey
- const restApiUrl = projectConfig.autoApiService?.restUrl
-
- const response = await get<OpenAPIV2.Document>(`${restApiUrl}?apikey=${apiKey}`, {
- headers: { ...headers, apiKey: apiKey, Authorization: `Bearer ${apiKey}` },
- credentials: 'omit',
- })
+ const response = await get<OpenAPIV2.Document>(this.url)
if (response.error) throw response.error
const tables = response.definitions