Skip to content

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

feat(studio): show icon on tables exposed by data api (#41416)

Charis1d49e9e9546f
diff --git a/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx b/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx
index cab44ab4f0f..fc77f12c9c4 100644
--- a/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx
@@ -304,7 +304,7 @@ export const GridHeaderActions = ({ table, isRefetching }: GridHeaderActionsProp
) : (
<Popover_Shadcn_ modal={false} open={showWarning} onOpenChange={setShowWarning}>
<PopoverTrigger_Shadcn_ asChild>
- <Button type="warning" icon={<Lock strokeWidth={1.5} />}>
+ <Button type="danger" icon={<Lock strokeWidth={1.5} />}>
RLS disabled
</Button>
</PopoverTrigger_Shadcn_>
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx
index 4485a06f332..44b4841fbb4 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx
@@ -15,6 +15,7 @@ import type { ForeignKeyConstraint } from 'data/database/foreign-key-constraints
import { databaseKeys } from 'data/database/keys'
import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
import { entityTypeKeys } from 'data/entity-types/keys'
+import { privilegeKeys } from 'data/privileges/keys'
import { tableEditorKeys } from 'data/table-editor/keys'
import { isTableLike } from 'data/table-editor/table-editor-types'
import { tableRowKeys } from 'data/table-rows/keys'
@@ -525,6 +526,9 @@ export const SidePanelEditor = ({
}),
queryClient.invalidateQueries({ queryKey: entityTypeKeys.list(project?.ref) }),
queryClient.invalidateQueries({ queryKey: databasePoliciesKeys.list(project?.ref) }),
+ queryClient.invalidateQueries({
+ queryKey: privilegeKeys.tablePrivilegesList(project?.ref),
+ }),
])
// Show success toast after everything is complete
@@ -575,6 +579,9 @@ export const SidePanelEditor = ({
queryKey: tableKeys.list(project?.ref, table.schema, includeColumns),
}),
queryClient.invalidateQueries({ queryKey: entityTypeKeys.list(project?.ref) }),
+ queryClient.invalidateQueries({
+ queryKey: privilegeKeys.tablePrivilegesList(project?.ref),
+ }),
])
toast.success(
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ForeignKeysManagement/ForeignKeysManagement.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ForeignKeysManagement/ForeignKeysManagement.tsx
index 73ac7f84752..4b739c59335 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ForeignKeysManagement/ForeignKeysManagement.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ForeignKeysManagement/ForeignKeysManagement.tsx
@@ -74,52 +74,54 @@ export const ForeignKeysManagement = ({
)}
{isSuccess && (
- <div>
- {relations.map((fk) => {
- const status = getRelationStatus(fk)
- return (
- <ForeignKeyRow
- key={fk.id}
- status={status}
- foreignKey={fk}
- closePanel={closePanel}
- onSelectEdit={() => {
- setOpen(true)
- setSelectedFk(fk)
- }}
- onSelectRemove={() => {
- setEditorDirty()
- if (status === 'ADD') {
- const updatedRelations = relations.filter((x) => x.id !== fk.id)
- onUpdateFkRelations(updatedRelations)
- } else {
+ <>
+ <div>
+ {relations.map((fk) => {
+ const status = getRelationStatus(fk)
+ return (
+ <ForeignKeyRow
+ key={fk.id}
+ status={status}
+ foreignKey={fk}
+ closePanel={closePanel}
+ onSelectEdit={() => {
+ setOpen(true)
+ setSelectedFk(fk)
+ }}
+ onSelectRemove={() => {
+ setEditorDirty()
+ if (status === 'ADD') {
+ const updatedRelations = relations.filter((x) => x.id !== fk.id)
+ onUpdateFkRelations(updatedRelations)
+ } else {
+ const updatedRelations = relations.map((x) => {
+ if (x.id === fk.id) return { ...x, toRemove: true }
+ else return x
+ })
+ onUpdateFkRelations(updatedRelations)
+ }
+ }}
+ onSelectUndoRemove={() => {
+ setEditorDirty()
const updatedRelations = relations.map((x) => {
- if (x.id === fk.id) return { ...x, toRemove: true }
+ if (x.id === fk.id) return { ...x, toRemove: false }
else return x
})
onUpdateFkRelations(updatedRelations)
- }
- }}
- onSelectUndoRemove={() => {
- setEditorDirty()
- const updatedRelations = relations.map((x) => {
- if (x.id === fk.id) return { ...x, toRemove: false }
- else return x
- })
- onUpdateFkRelations(updatedRelations)
- }}
- />
- )
- })}
- </div>
+ }}
+ />
+ )
+ })}
+ </div>
+ <div className="flex items-center justify-center rounded border border-strong border-dashed py-3">
+ <Button type="default" onClick={() => setOpen(true)}>
+ Add foreign key relation
+ </Button>
+ </div>
+ </>
)}
-
- <div className="flex items-center justify-center rounded border border-strong border-dashed py-3">
- <Button type="default" onClick={() => setOpen(true)}>
- Add foreign key relation
- </Button>
- </div>
</div>
+
<ForeignKeySelector
visible={open}
table={{ id: table.id, name: table.name, columns: table.columns }}
diff --git a/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx b/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
index a4237116cf2..7cc2fe5bd53 100644
--- a/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
+++ b/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
@@ -1,9 +1,9 @@
-import { Copy, Download, Edit, Lock, MoreVertical, Trash } from 'lucide-react'
+import { Copy, Download, Edit, Globe, Lock, MoreVertical, Trash } from 'lucide-react'
import Link from 'next/link'
import { type CSSProperties } from 'react'
import { toast } from 'sonner'
-import { useParams } from 'common'
+import { useFlag, useParams } from 'common'
import { useTableFilter } from 'components/grid/hooks/useTableFilter'
import { buildTableEditorUrl } from 'components/grid/SupabaseGrid.utils'
import { getEntityLintDetails } from 'components/interfaces/TableGridEditor/TableEntity.utils'
@@ -14,6 +14,7 @@ import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
import { Entity } from 'data/entity-types/entity-types-infinite-query'
import { useProjectLintsQuery } from 'data/lint/lint-query'
import { EditorTablePageLink } from 'data/prefetchers/project.$ref.editor.$id'
+import type { TableApiAccessData, TableApiAccessMap } from 'data/privileges/table-api-access-query'
import { useTableRowsCountQuery } from 'data/table-rows/table-rows-count-query'
import { useQuerySchemaState } from 'hooks/misc/useSchemaQueryState'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
@@ -52,6 +53,7 @@ export interface EntityListItemProps {
isActive?: boolean
style?: CSSProperties
onExportCLI: () => void
+ apiAccessMap?: TableApiAccessMap
}
// [jordi] Used to determine the entity is a table and not a view or other unsupported entity type
@@ -59,7 +61,7 @@ function isTableLikeEntityListItem(entity: { type?: string }) {
return entity?.type === ENTITY_TYPE.TABLE || entity?.type === ENTITY_TYPE.PARTITIONED_TABLE
}
-const EntityListItem = ({
+export const EntityListItem = ({
id,
projectRef,
item: entity,
@@ -67,6 +69,7 @@ const EntityListItem = ({
isActive: _isActive,
style,
onExportCLI,
+ apiAccessMap,
}: EntityListItemProps) => {
const { data: project } = useSelectedProjectQuery()
const snap = useTableEditorStateSnapshot()
@@ -133,6 +136,8 @@ const EntityListItem = ({
selectedSchema
).hasLint
+ const apiAccessData = apiAccessMap?.[entity.name]
+
const formatTooltipText = (entityType: string) => {
const text =
Object.entries(ENTITY_TYPE)
@@ -206,15 +211,14 @@ const EntityListItem = ({
>
{entity.name}
</span>
- <div>
- <EntityTooltipTrigger
- entity={entity}
- tableHasLints={tableHasLints}
- viewHasLints={viewHasLints}
- materializedViewHasLints={materializedViewHasLints}
- foreignTableHasLints={foreignTableHasLints}
- />
- </div>
+ <EntityTooltipTrigger
+ entity={entity}
+ tableHasLints={tableHasLints}
+ viewHasLints={viewHasLints}
+ materializedViewHasLints={materializedViewHasLints}
+ foreignTableHasLints={foreignTableHasLints}
+ apiAccessData={apiAccessData}
+ />
</div>
{canEdit && (
@@ -381,14 +385,17 @@ const EntityTooltipTrigger = ({
viewHasLints,
materializedViewHasLints,
foreignTableHasLints,
+ apiAccessData,
}: {
entity: Entity
tableHasLints: boolean
viewHasLints: boolean
materializedViewHasLints: boolean
foreignTableHasLints: boolean
+ apiAccessData?: TableApiAccessData
}) => {
const { ref } = useParams()
+ const isDataApiExposedBadgeEnabled = useFlag('dataApiExposedBadge')
let tooltipContent = null
const accessWarning = 'Data is publicly accessible via API'
@@ -447,14 +454,23 @@ const EntityTooltipTrigger = ({
<TooltipTrigger className="min-w-4">
<Badge variant="destructive">Unrestricted</Badge>
</TooltipTrigger>
- <TooltipContent side="right" className="max-w-52 text-center">
+ <TooltipContent side="right" className="max-w-52">
{tooltipContent}
</TooltipContent>
</Tooltip>
)
}
+ if (isDataApiExposedBadgeEnabled && apiAccessData?.hasApiAccess) {
+ return (
+ <Tooltip>
+ <TooltipTrigger className="min-w-4" aria-label="Table exposed via Data API">
+ <Globe size={14} strokeWidth={1} className="text-foreground-lighter" />
+ </TooltipTrigger>
+ <TooltipContent side="right">This table is exposed via the Data API</TooltipContent>
+ </Tooltip>
+ )
+ }
+
return null
}
-
-export default EntityListItem
diff --git a/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx b/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
index bd2960ae959..d93e8f39490 100644
--- a/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
+++ b/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
@@ -2,6 +2,7 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'
import { Filter, Plus } from 'lucide-react'
import { useCallback, useEffect, useMemo, useState } from 'react'
+import { keepPreviousData } from '@tanstack/react-query'
import { useParams } from 'common'
import { useBreakpoint } from 'common/hooks/useBreakpoint'
import { ExportDialog } from 'components/grid/components/header/ExportDialog'
@@ -15,6 +16,7 @@ import { InfiniteListDefault, LoaderForIconMenuItems } from 'components/ui/Infin
import SchemaSelector from 'components/ui/SchemaSelector'
import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
import { useEntityTypesQuery } from 'data/entity-types/entity-types-infinite-query'
+import { useTableApiAccessQuery } from 'data/privileges/table-api-access-query'
import { getTableEditor, useTableEditorQuery } from 'data/table-editor/table-editor-query'
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useLocalStorage } from 'hooks/misc/useLocalStorage'
@@ -38,9 +40,8 @@ import {
InnerSideBarFilters,
} from 'ui-patterns/InnerSideMenu'
import { useTableEditorTabsCleanUp } from '../Tabs/Tabs.utils'
-import EntityListItem from './EntityListItem'
+import { EntityListItem } from './EntityListItem'
import { TableMenuEmptyState } from './TableMenuEmptyState'
-import { keepPreviousData } from '@tanstack/react-query'
export const TableEditorMenu = () => {
const { id: _id, ref: projectRef } = useParams()
@@ -85,6 +86,17 @@ export const TableEditorMenu = () => {
() => data?.pages.flatMap((page) => page.data.entities),
[data?.pages]
)
+ const entityNames = useMemo(() => entityTypes?.map((entity) => entity.name) ?? [], [entityTypes])
+
+ const { data: apiAccessByTableName } = useTableApiAccessQuery(
+ {
+ projectRef: project?.ref,
+ connectionString: project?.connectionString ?? undefined,
+ schemaName: selectedSchema,
+ tableNames: entityNames,
+ },
+ { enabled: Boolean(selectedSchema && entityNames.length > 0) }
+ )
const { can: canCreateTables } = useAsyncCheckPermissions(
PermissionAction.TENANT_SQL_ADMIN_WRITE,
@@ -132,8 +144,9 @@ export const TableEditorMenu = () => {
id: Number(id),
isLocked: isSchemaLocked,
onExportCLI: () => onSelectExportCLI(Number(id)),
+ apiAccessMap: apiAccessByTableName,
}),
- [project?.ref, id, isSchemaLocked, onSelectExportCLI]
+ [project?.ref, id, isSchemaLocked, onSelectExportCLI, apiAccessByTableName]
)
useEffect(() => {
diff --git a/apps/studio/data/common.types.ts b/apps/studio/data/common.types.ts
new file mode 100644
index 00000000000..5f0415c52d6
--- /dev/null
+++ b/apps/studio/data/common.types.ts
@@ -0,0 +1,4 @@
+export type ConnectionVars = {
+ projectRef?: string
+ connectionString?: string
+}
diff --git a/apps/studio/data/privileges/keys.ts b/apps/studio/data/privileges/keys.ts
index 387ddef6dac..9e92f4ed95c 100644
--- a/apps/studio/data/privileges/keys.ts
+++ b/apps/studio/data/privileges/keys.ts
@@ -1,6 +1,6 @@
export const privilegeKeys = {
tablePrivilegesList: (projectRef: string | undefined) =>
- [projectRef, 'database', 'table-privileges'] as const,
+ ['projects', projectRef, 'database', 'table-privileges'] as const,
columnPrivilegesList: (projectRef: string | undefined) =>
- [projectRef, 'database', 'column-privileges'] as const,
+ ['projects', projectRef, 'database', 'column-privileges'] as const,
}
diff --git a/apps/studio/data/privileges/table-api-access-query.ts b/apps/studio/data/privileges/table-api-access-query.ts
new file mode 100644
index 00000000000..5cadf938bf6
--- /dev/null
+++ b/apps/studio/data/privileges/table-api-access-query.ts
@@ -0,0 +1,225 @@
+import { useMemo } from 'react'
+
+import type { ConnectionVars } from 'data/common.types'
+import { useProjectPostgrestConfigQuery } from 'data/config/project-postgrest-config-query'
+import { isApiAccessRole, isApiPrivilegeType, type ApiPrivilegesByRole } from 'lib/data-api-types'
+import type { Prettify } from 'lib/type-helpers'
+import type { UseCustomQueryOptions } from 'types'
+import {
+ useTablePrivilegesQuery,
+ type TablePrivilegesData,
+ type TablePrivilegesError,
+} from './table-privileges-query'
+
+// The contents of this array are never used, so any will allow
+// it to be used anywhere an array of any type is required.
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+const STABLE_EMPTY_ARRAY: any[] = []
+const STABLE_EMPTY_OBJECT = {}
+
+/**
+ * Parses the exposed schema string returned from PostgREST config.
+ *
+ * @param schemaString - e.g., `public,graphql_public`
+ */
+const parseDbSchemaString = (schemaString: string): string[] => {
+ return schemaString
+ .split(',')
+ .map((s) => s.trim())
+ .filter((s) => s.length > 0)
+}
+
+const getApiPrivilegesByRole = (
+ privileges: TablePrivilegesData[number]['privileges']
+): ApiPrivilegesByRole => {
+ const privilegesByRole: ApiPrivilegesByRole = {
+ anon: [],
+ authenticated: [],
+ }
+
+ privileges.forEach((privilege) => {
+ const { grantee, privilege_type } = privilege
+ if (isApiAccessRole(grantee) && isApiPrivilegeType(privilege_type)) {
+ privilegesByRole[grantee].push(privilege_type)
+ }
+ })
+
+ return privilegesByRole
+}
+
+const mapPrivilegesByTableName = (
+ privileges: TablePrivilegesData | undefined,
+ schemaName: string,
+ tableNames: Set<string>
+): Record<string, ApiPrivilegesByRole> => {
+ if (!privileges) return {}
+
+ const result: Record<string, ApiPrivilegesByRole> = {}
+
+ privileges.forEach((entry) => {
+ if (entry.schema !== schemaName) return
+ if (!tableNames.has(entry.name)) return
+ result[entry.name] = getApiPrivilegesByRole(entry.privileges)
+ })
+
+ return result
+}
+
+export type UseTableApiAccessQueryParams = Prettify<
+ ConnectionVars & {
+ schemaName: string
+ tableNames: string[]
+ }
+>
+
+export type TableApiAccessData =
+ | {
+ hasApiAccess: true
+ privileges: ApiPrivilegesByRole
+ }
+ | {
+ hasApiAccess: false
+ }
+
+export type TableApiAccessMap = Record<string, TableApiAccessData>
+
+export type UseTableApiAccessQueryReturn =
+ | {
+ data: TableApiAccessMap
+ isSuccess: true
+ isPending: false
+ isError: false
+ }
+ | {
+ data: undefined
+ isSuccess: false
+ isPending: true
+ isError: false
+ }
+ | {
+ data: undefined
+ isSuccess: false
+ isPending: false
+ isError: true
+ }
+
+export const useTableApiAccessQuery = (
+ {
+ projectRef,
+ connectionString,
+ schemaName,
+ tableNames = STABLE_EMPTY_ARRAY,
+ }: UseTableApiAccessQueryParams,
+ {
+ enabled = true,
+ ...options
+ }: { enabled?: boolean } & Omit<
+ UseCustomQueryOptions<TablePrivilegesData, TablePrivilegesError>,
+ 'enabled'
+ > = {}
+): UseTableApiAccessQueryReturn => {
+ const {
+ data: dbSchemaString,
+ isPending: isConfigPending,
+ isError: isConfigError,
+ } = useProjectPostgrestConfigQuery(
+ { projectRef },
+ { enabled, select: ({ db_schema }) => db_schema }
+ )
+ const exposedSchemas = useMemo((): string[] => {
+ if (!dbSchemaString) return []
+ return parseDbSchemaString(dbSchemaString)
+ }, [dbSchemaString])
+
+ const uniqueTableNames = useMemo(() => {
+ return new Set(
+ tableNames.filter((tableName) => typeof tableName === 'string' && tableName.length > 0)
+ )
+ }, [tableNames])
+ const hasTables = uniqueTableNames.size > 0
+ const isSchemaExposed = exposedSchemas.includes(schemaName)
+ const enablePrivilegesQuery = enabled && isSchemaExposed && hasTables
+
+ const {
+ data: privileges,
+ isPending: isPrivilegesPending,
+ isError: isPrivilegesError,
+ } = useTablePrivilegesQuery(
+ { projectRef, connectionString },
+ { enabled: enablePrivilegesQuery, ...options }
+ )
+
+ const result: UseTableApiAccessQueryReturn = useMemo(() => {
+ const isPending = isConfigPending || (enablePrivilegesQuery && isPrivilegesPending)
+ if (isPending) {
+ return {
+ data: undefined,
+ isSuccess: false,
+ isPending: true,
+ isError: false,
+ }
+ }
+
+ const isError = isConfigError || (enablePrivilegesQuery && isPrivilegesError)
+ if (isError) {
+ return {
+ data: undefined,
+ isSuccess: false,
+ isPending: false,
+ isError: true,
+ }
+ }
+
+ if (!hasTables) {
+ return {
+ data: STABLE_EMPTY_OBJECT,
+ isSuccess: true,
+ isPending: false,
+ isError: false,
+ }
+ }
+
+ const resultData: TableApiAccessMap = {}
+ const tablePrivilegesByName = isSchemaExposed
+ ? mapPrivilegesByTableName(privileges, schemaName, uniqueTableNames)
+ : {}
+
+ uniqueTableNames.forEach((tableName) => {
+ if (!isSchemaExposed) {
+ resultData[tableName] = { hasApiAccess: false }
+ return
+ }
+
+ const tablePrivileges = tablePrivilegesByName[tableName] ?? { anon: [], authenticated: [] }
+ const hasAnonOrAuthenticatedPrivileges =
+ tablePrivileges.anon.length > 0 || tablePrivileges.authenticated.length > 0
+
+ resultData[tableName] = hasAnonOrAuthenticatedPrivileges
+ ? {
+ hasApiAccess: true,
+ privileges: tablePrivileges,
+ }
+ : { hasApiAccess: false }
+ })
+
+ return {
+ data: resultData,
+ isSuccess: true,
+ isPending: false,
+ isError: false,
+ }
+ }, [
+ enablePrivilegesQuery,
+ hasTables,
+ isConfigError,
+ isConfigPending,
+ isPrivilegesError,
+ isPrivilegesPending,
+ isSchemaExposed,
+ privileges,
+ schemaName,
+ uniqueTableNames,
+ ])
+
+ return result
+}
diff --git a/apps/studio/data/storage/buckets-max-size-limit-query.ts b/apps/studio/data/storage/buckets-max-size-limit-query.ts
index 033d027b7df..7bfa7d17be5 100644
--- a/apps/studio/data/storage/buckets-max-size-limit-query.ts
+++ b/apps/studio/data/storage/buckets-max-size-limit-query.ts
@@ -1,6 +1,7 @@
import { useQuery, useQueryClient } from '@tanstack/react-query'
import { useCallback } from 'react'
+import type { ConnectionVars } from 'data/common.types'
import { executeSql } from 'data/sql/execute-sql-query'
import {
getLargestSizeLimitBucketsKey,
@@ -13,11 +14,6 @@ import {
export const THRESHOLD_FOR_AUTO_QUERYING_BUCKET_LIMITS = 10_000
-type ConnectionVars = {
- projectRef?: string
- connectionString?: string
-}
-
const getBucketNumberEstimateKey = (projectRef: string | undefined) =>
getLiveTupleEstimateKey(projectRef, 'buckets', 'storage')
diff --git a/apps/studio/data/tables/table-create-mutation.ts b/apps/studio/data/tables/table-create-mutation.ts
index 9f08095fae8..7129ce74531 100644
--- a/apps/studio/data/tables/table-create-mutation.ts
+++ b/apps/studio/data/tables/table-create-mutation.ts
@@ -3,6 +3,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
import { executeSql } from 'data/sql/execute-sql-query'
+import { privilegeKeys } from 'data/privileges/keys'
import type { ResponseError, UseCustomMutationOptions } from 'types'
import { tableKeys } from './keys'
@@ -56,6 +57,9 @@ export const useTableCreateMutation = ({
queryClient.invalidateQueries({
queryKey: tableKeys.list(projectRef, payload.schema, false),
}),
+ queryClient.invalidateQueries({
+ queryKey: privilegeKeys.tablePrivilegesList(projectRef),
+ }),
])
await onSuccess?.(data, variables, context)
},
diff --git a/apps/studio/lib/data-api-types.ts b/apps/studio/lib/data-api-types.ts
new file mode 100644
index 00000000000..5259530b762
--- /dev/null
+++ b/apps/studio/lib/data-api-types.ts
@@ -0,0 +1,25 @@
+import type { TablePrivilegesGrant } from 'data/privileges/table-privileges-grant-mutation'
+
+export const API_ACCESS_ROLES = ['anon', 'authenticated'] as const
+export type ApiAccessRole = (typeof API_ACCESS_ROLES)[number]
+
+export const isApiAccessRole = (value: string): value is ApiAccessRole => {
+ return API_ACCESS_ROLES.includes(value as ApiAccessRole)
+}
+
+export type ApiPrivilegeType = Extract<
+ TablePrivilegesGrant['privilegeType'],
+ 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE'
+>
+export const API_PRIVILEGE_TYPES = [
+ 'SELECT',
+ 'INSERT',
+ 'UPDATE',
+ 'DELETE',
+] as const satisfies readonly ApiPrivilegeType[]
+
+export const isApiPrivilegeType = (value: string): value is ApiPrivilegeType => {
+ return API_PRIVILEGE_TYPES.includes(value as ApiPrivilegeType)
+}
+
+export type ApiPrivilegesByRole = Record<ApiAccessRole, ApiPrivilegeType[]>
diff --git a/apps/studio/lib/type-helpers.ts b/apps/studio/lib/type-helpers.ts
index 72551b9d9ca..26e2273a496 100644
--- a/apps/studio/lib/type-helpers.ts
+++ b/apps/studio/lib/type-helpers.ts
@@ -1 +1,3 @@
export type PlainObject<Value = unknown> = Record<string | number | symbol, Value>
+
+export type Prettify<T> = { [K in keyof T]: T[K] } & {}