mirror of
https://github.com/supabase/supabase.git
synced 2026-05-08 01:40:13 -04:00
bd55ad23a6
Edit: Can be merged, mgmt api deployed Dashboard addition to frontend for access to the ISO 27001 certificate. View for Team customers: <img width="1737" height="1151" alt="image" src="https://github.com/user-attachments/assets/cd62d24f-8b6e-4600-9ded-943a170cd124" /> Resolves SEC-799 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * ISO 27001 certificate added to Documents with a Download action, confirmation modal, new-tab open on success, and error toast on failure. * Users without billing permission see a no-permission view; users missing entitlement see an “Upgrade to Team” prompt. * **Refactor** * Upgrade-to-Team flows for SOC2 and related upgrade UI standardized to use the shared upgrade component. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import { documentKeys } from './keys'
|
|
import { get, handleError } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomQueryOptions } from '@/types'
|
|
|
|
export type DocType =
|
|
| 'standard-security-questionnaire'
|
|
| 'soc2-type-2-report'
|
|
| 'iso27001-certificate'
|
|
|
|
export type DocumentVariables = {
|
|
orgSlug?: string
|
|
docType?: DocType
|
|
}
|
|
|
|
export async function getDocument({ orgSlug, docType }: DocumentVariables, signal?: AbortSignal) {
|
|
if (!orgSlug) throw new Error('orgSlug is required')
|
|
|
|
if (docType === 'standard-security-questionnaire') {
|
|
const { data, error } = await get(
|
|
`/platform/organizations/{slug}/documents/standard-security-questionnaire`,
|
|
{
|
|
params: { path: { slug: orgSlug } },
|
|
signal,
|
|
}
|
|
)
|
|
|
|
if (error) handleError(error)
|
|
return data as { fileUrl: string }
|
|
}
|
|
|
|
if (docType === 'soc2-type-2-report') {
|
|
const { data, error } = await get(
|
|
`/platform/organizations/{slug}/documents/soc2-type-2-report`,
|
|
{
|
|
params: { path: { slug: orgSlug } },
|
|
signal,
|
|
}
|
|
)
|
|
if (error) throw error
|
|
|
|
return data as { fileUrl: string }
|
|
}
|
|
|
|
if (docType === 'iso27001-certificate') {
|
|
const { data, error } = await get(
|
|
`/platform/organizations/{slug}/documents/iso27001-certificate`,
|
|
{
|
|
params: { path: { slug: orgSlug } },
|
|
signal,
|
|
}
|
|
)
|
|
if (error) throw error
|
|
|
|
return data as { fileUrl: string }
|
|
}
|
|
}
|
|
|
|
export type DocumentData = Awaited<ReturnType<typeof getDocument>>
|
|
export type DocumentError = ResponseError
|
|
|
|
export const useDocumentQuery = <TData = DocumentData>(
|
|
{ orgSlug, docType }: DocumentVariables,
|
|
{ enabled = true, ...options }: UseCustomQueryOptions<DocumentData, DocumentError, TData> = {}
|
|
) =>
|
|
useQuery<DocumentData, DocumentError, TData>({
|
|
queryKey: documentKeys.resource(orgSlug, docType),
|
|
queryFn: ({ signal }) => getDocument({ orgSlug, docType }, signal),
|
|
enabled: enabled && typeof orgSlug !== 'undefined' && typeof docType !== 'undefined',
|
|
...options,
|
|
})
|