mirror of
https://github.com/supabase/supabase.git
synced 2026-10-14 05:39:11 +03:00
* fix(studio): early fail query when x-connection-encrypted is invalid * fix(studio): uniformize readDatabase and projectDetails connString handling * chore: update api types * chore: add connectionString null option * fix: only enforce x-connection-encrypted on platform * chore: refactor connString check in a single point * chore: fix guard logic * chore: fix pgMetaGuard * chore: fix types
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
import { Query } from '@supabase/pg-meta/src/query'
|
|
import type { VaultSecret } from 'types'
|
|
import { executeSql, ExecuteSqlError } from '../sql/execute-sql-query'
|
|
import { vaultSecretsKeys } from './keys'
|
|
|
|
export const getVaultSecretsSql = () => {
|
|
const sql = new Query()
|
|
.from('secrets', 'vault')
|
|
.select('id,name,description,secret,created_at,updated_at')
|
|
.toSql()
|
|
|
|
return sql
|
|
}
|
|
|
|
export type VaultSecretsVariables = {
|
|
projectRef?: string
|
|
connectionString?: string | null
|
|
}
|
|
|
|
export async function getVaultSecrets(
|
|
{ projectRef, connectionString }: VaultSecretsVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
const sql = getVaultSecretsSql()
|
|
|
|
const { result } = await executeSql(
|
|
{ projectRef, connectionString, sql, queryKey: ['vault-secrets'] },
|
|
signal
|
|
)
|
|
|
|
return result as VaultSecret[]
|
|
}
|
|
|
|
export type VaultSecretsData = Awaited<ReturnType<typeof getVaultSecrets>>
|
|
export type VaultSecretsError = ExecuteSqlError
|
|
|
|
export const useVaultSecretsQuery = <TData = VaultSecretsData>(
|
|
{ projectRef, connectionString }: VaultSecretsVariables,
|
|
{ enabled = true, ...options }: UseQueryOptions<VaultSecretsData, VaultSecretsError, TData> = {}
|
|
) =>
|
|
useQuery<VaultSecretsData, VaultSecretsError, TData>(
|
|
vaultSecretsKeys.list(projectRef),
|
|
({ signal }) => getVaultSecrets({ projectRef, connectionString }, signal),
|
|
{
|
|
enabled: enabled && typeof projectRef !== 'undefined',
|
|
...options,
|
|
}
|
|
)
|