Skip to content

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

feat(api-types): generate fga-requirements.ts from OpenAPI specs (#52093)

Charis6cde55ae3c8b
diff --git a/.github/workflows/verify-production-api-types.yml b/.github/workflows/verify-production-api-types.yml
index bc99921ca89..5bf77c3f756 100644
--- a/.github/workflows/verify-production-api-types.yml
+++ b/.github/workflows/verify-production-api-types.yml
@@ -16,7 +16,7 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
run: |
- if gh api "repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" --paginate --jq '.[].filename' | grep -q '^packages/api-types/types/'; then
+ if gh api "repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" --paginate --jq '.[].filename' | grep -qE '^packages/api-types/(types|scripts)/'; then
echo "api_types_changed=true" >> "$GITHUB_OUTPUT"
else
echo "api_types_changed=false" >> "$GITHUB_OUTPUT"
diff --git a/packages/api-types/index.ts b/packages/api-types/index.ts
index 9c89e97947a..c0d0376864d 100644
--- a/packages/api-types/index.ts
+++ b/packages/api-types/index.ts
@@ -36,3 +36,6 @@ export interface components {
}
export type { platformComponents, apiV1Components, apiV2Components }
+
+export { fgaRequirements } from './types/fga-requirements'
+export type { FgaRequirements, FgaGuardedEndpoint } from './types/fga-requirements'
diff --git a/packages/api-types/package.json b/packages/api-types/package.json
index 2f05083e14a..d3973b61e73 100644
--- a/packages/api-types/package.json
+++ b/packages/api-types/package.json
@@ -7,7 +7,7 @@
"scripts": {
"preinstall": "npx only-allow pnpm",
"clean": "rimraf .turbo tsconfig.tsbuildinfo",
- "codegen": "openapi-typescript --redocly ./redocly.yaml --alphabetize --default-non-nullable=false && prettier --cache --write types/*.d.ts",
+ "codegen": "openapi-typescript --redocly ./redocly.yaml --alphabetize --default-non-nullable=false && node ./scripts/generate-fga-requirements.mjs && prettier --cache --write types/*.d.ts types/fga-requirements.ts",
"codegen:prod": "node ./scripts/generate-production-types.mjs",
"verify-production-types": "node ./scripts/verify-production-types.mjs",
"test": "node --test ./scripts/*.test.mjs"
diff --git a/packages/api-types/scripts/fga-requirements.mjs b/packages/api-types/scripts/fga-requirements.mjs
new file mode 100644
index 00000000000..bdf3bee2df2
--- /dev/null
+++ b/packages/api-types/scripts/fga-requirements.mjs
@@ -0,0 +1,99 @@
+const HTTP_METHODS = ['get', 'post', 'put', 'patch', 'delete', 'options', 'head', 'trace']
+
+export function getKnownFgaPermissions(specs) {
+ for (const { spec } of specs) {
+ const permissions =
+ spec?.components?.schemas?.CreateScopedAccessTokenBody?.properties?.permissions?.items?.enum
+ if (Array.isArray(permissions)) return new Set(permissions)
+ }
+
+ throw new Error(
+ 'Could not find the list of FGA permissions at components.schemas.CreateScopedAccessTokenBody.properties.permissions.items.enum in any OpenAPI specification.'
+ )
+}
+
+function validateRequirement(value, knownPermissions, location) {
+ const isValidShape =
+ Array.isArray(value) &&
+ value.every(
+ (group) =>
+ Array.isArray(group) &&
+ group.length > 0 &&
+ group.every((permission) => typeof permission === 'string')
+ )
+
+ if (!isValidShape) {
+ throw new Error(
+ `Invalid x-fga-permissions for ${location}: expected an array of non-empty arrays of strings.`
+ )
+ }
+
+ for (const permission of value.flat()) {
+ if (!knownPermissions.has(permission)) {
+ throw new Error(
+ `Unknown FGA permission "${permission}" in x-fga-permissions for ${location}.`
+ )
+ }
+ }
+}
+
+export function buildFgaRequirements(specs, knownPermissions) {
+ const requirements = {}
+ const sources = {}
+
+ for (const { name, spec } of specs) {
+ for (const [path, pathItem] of Object.entries(spec?.paths ?? {})) {
+ for (const method of HTTP_METHODS) {
+ const operation = pathItem?.[method]
+ if (!operation || operation['x-fga-permissions'] === undefined) continue
+
+ const key = `${method.toUpperCase()} ${path}`
+ const location = `${key} in the ${name} specification`
+ validateRequirement(operation['x-fga-permissions'], knownPermissions, location)
+
+ // An empty annotation means the endpoint is ungated, so omit it like an unannotated one.
+ if (operation['x-fga-permissions'].length === 0) continue
+
+ if (key in sources) {
+ throw new Error(
+ `Duplicate endpoint ${key} with x-fga-permissions in the ${sources[key]} and ${name} specifications.`
+ )
+ }
+
+ sources[key] = name
+ requirements[key] = operation['x-fga-permissions'].map((group) => [...group])
+ }
+ }
+ }
+
+ return Object.fromEntries(
+ Object.keys(requirements)
+ .sort((a, b) => (a < b ? -1 : a > b ? 1 : 0))
+ .map((key) => [key, requirements[key]])
+ )
+}
+
+export function generateFgaRequirementsSource(parsedSpecs) {
+ return renderFgaRequirements(
+ buildFgaRequirements(parsedSpecs, getKnownFgaPermissions(parsedSpecs))
+ )
+}
+
+export function renderFgaRequirements(requirements) {
+ const entries = Object.entries(requirements)
+ .map(([key, groups]) => ` ${JSON.stringify(key)}: ${JSON.stringify(groups)},`)
+ .join('\n')
+
+ return `// Generated by \`pnpm --filter=api-types codegen:prod\` from the production OpenAPI specifications. Do not edit by hand.
+// Maps each endpoint annotated with \`x-fga-permissions\` to the FGA permissions it requires. A caller
+// needs every permission in at least one group (OR between groups, AND within a group). Keys are the
+// path literals passed to openapi-fetch.
+
+export const fgaRequirements = {
+${entries}
+} as const
+
+export type FgaRequirements = typeof fgaRequirements
+export type FgaGuardedEndpoint = keyof FgaRequirements
+`
+}
diff --git a/packages/api-types/scripts/fga-requirements.test.mjs b/packages/api-types/scripts/fga-requirements.test.mjs
new file mode 100644
index 00000000000..42871a15c53
--- /dev/null
+++ b/packages/api-types/scripts/fga-requirements.test.mjs
@@ -0,0 +1,163 @@
+import assert from 'node:assert/strict'
+import test from 'node:test'
+
+import {
+ buildFgaRequirements,
+ getKnownFgaPermissions,
+ renderFgaRequirements,
+} from './fga-requirements.mjs'
+
+const known = new Set(['a_read', 'a_write', 'b_read'])
+
+const platformSpec = {
+ components: {
+ schemas: {
+ CreateScopedAccessTokenBody: {
+ properties: { permissions: { items: { enum: ['a_read', 'a_write', 'b_read'] } } },
+ },
+ },
+ },
+}
+
+test('getKnownFgaPermissions reads the permission enum from whichever spec has it', () => {
+ const permissions = getKnownFgaPermissions([
+ { name: 'api-v1', spec: { paths: {} } },
+ { name: 'platform', spec: platformSpec },
+ ])
+
+ assert.deepEqual(permissions, known)
+})
+
+test('getKnownFgaPermissions throws when no spec has the permission enum', () => {
+ assert.throws(
+ () => getKnownFgaPermissions([{ name: 'api-v1', spec: { paths: {} } }]),
+ /Could not find the list of FGA permissions/
+ )
+})
+
+test('buildFgaRequirements preserves OR-of-AND groups and ignores non-method keys', () => {
+ const requirements = buildFgaRequirements(
+ [
+ {
+ name: 'api-v1',
+ spec: {
+ paths: {
+ '/v1/z/{ref}': {
+ parameters: [{ 'x-fga-permissions': [['a_read']] }],
+ summary: 'ignored',
+ get: { 'x-fga-permissions': [['b_read', 'a_read'], ['a_write']] },
+ post: {},
+ },
+ '/v1/a': { delete: { 'x-fga-permissions': [['a_write']] } },
+ },
+ },
+ },
+ ],
+ known
+ )
+
+ assert.deepEqual(requirements, {
+ 'DELETE /v1/a': [['a_write']],
+ 'GET /v1/z/{ref}': [['b_read', 'a_read'], ['a_write']],
+ })
+ assert.deepEqual(Object.keys(requirements), ['DELETE /v1/a', 'GET /v1/z/{ref}'])
+})
+
+test('buildFgaRequirements sorts keys across specifications', () => {
+ const requirements = buildFgaRequirements(
+ [
+ {
+ name: 'platform',
+ spec: { paths: { '/platform/x': { get: { 'x-fga-permissions': [['a_read']] } } } },
+ },
+ {
+ name: 'api-v1',
+ spec: { paths: { '/v1/x': { get: { 'x-fga-permissions': [['a_read']] } } } },
+ },
+ ],
+ known
+ )
+
+ assert.deepEqual(Object.keys(requirements), ['GET /platform/x', 'GET /v1/x'])
+})
+
+test('buildFgaRequirements rejects malformed requirements', () => {
+ for (const value of [[[]], 'a_read', ['a_read'], [[1]], [['a_read'], []]]) {
+ assert.throws(
+ () =>
+ buildFgaRequirements(
+ [
+ {
+ name: 'api-v1',
+ spec: { paths: { '/v1/x': { get: { 'x-fga-permissions': value } } } },
+ },
+ ],
+ known
+ ),
+ /Invalid x-fga-permissions for GET \/v1\/x in the api-v1 specification/
+ )
+ }
+})
+
+test('buildFgaRequirements omits endpoints with an empty annotation', () => {
+ const requirements = buildFgaRequirements(
+ [
+ {
+ name: 'api-v1',
+ spec: {
+ paths: {
+ '/v1/open': { get: { 'x-fga-permissions': [] } },
+ '/v1/gated': { get: { 'x-fga-permissions': [['a_read']] } },
+ },
+ },
+ },
+ ],
+ known
+ )
+
+ assert.deepEqual(requirements, { 'GET /v1/gated': [['a_read']] })
+})
+
+test('buildFgaRequirements rejects unknown permissions', () => {
+ assert.throws(
+ () =>
+ buildFgaRequirements(
+ [
+ {
+ name: 'api-v2',
+ spec: { paths: { '/v2/x': { put: { 'x-fga-permissions': [['nope']] } } } },
+ },
+ ],
+ known
+ ),
+ /Unknown FGA permission "nope".*PUT \/v2\/x in the api-v2 specification/
+ )
+})
+
+test('buildFgaRequirements rejects an endpoint that appears in two specifications', () => {
+ const spec = { paths: { '/v1/x': { get: { 'x-fga-permissions': [['a_read']] } } } }
+
+ assert.throws(
+ () =>
+ buildFgaRequirements(
+ [
+ { name: 'api-v1', spec },
+ { name: 'platform', spec },
+ ],
+ known
+ ),
+ /Duplicate endpoint GET \/v1\/x.*api-v1 and platform/
+ )
+})
+
+test('renderFgaRequirements emits a const TypeScript module', () => {
+ const source = renderFgaRequirements({ 'GET /v1/x': [['a_read'], ['a_write', 'b_read']] })
+
+ assert.match(source, /Do not edit by hand/)
+ assert.match(
+ source,
+ /export const fgaRequirements = \{\n {2}"GET \/v1\/x": \[\["a_read"\],\["a_write","b_read"\]\],\n\} as const/
+ )
+ assert.match(source, /export type FgaRequirements = typeof fgaRequirements/)
+ assert.match(source, /export type FgaGuardedEndpoint = keyof FgaRequirements/)
+})
diff --git a/packages/api-types/scripts/generate-fga-requirements.mjs b/packages/api-types/scripts/generate-fga-requirements.mjs
new file mode 100644
index 00000000000..752e6fc27b5
--- /dev/null
+++ b/packages/api-types/scripts/generate-fga-requirements.mjs
@@ -0,0 +1,48 @@
+import { writeFile } from 'node:fs/promises'
+import { dirname, join } from 'node:path'
+import { fileURLToPath } from 'node:url'
+
+import { generateFgaRequirementsSource } from './fga-requirements.mjs'
+
+const packageDirectory = dirname(dirname(fileURLToPath(import.meta.url)))
+const baseUrl = process.env.LOCAL_API_URL ?? 'http://localhost:8080'
+
+// These URLs mirror redocly.yaml.
+export const localSpecifications = [
+ { name: 'api-v1', url: `${baseUrl}/api/v1-json` },
+ { name: 'api-v2', url: `${baseUrl}/api/v2-json` },
+ { name: 'platform', url: `${baseUrl}/api/platform-json` },
+]
+
+export async function generateFgaRequirements({
+ specifications = localSpecifications,
+ fetchImpl = fetch,
+ writeFileImpl = writeFile,
+ outputPath = join(packageDirectory, 'types', 'fga-requirements.ts'),
+} = {}) {
+ const parsedSpecs = await Promise.all(
+ specifications.map(async ({ name, url }) => {
+ let response
+
+ try {
+ response = await fetchImpl(url)
+ } catch {
+ throw new Error(`Could not fetch ${name} OpenAPI specification from ${url}.`)
+ }
+
+ if (!response.ok) {
+ throw new Error(
+ `Could not fetch ${name} OpenAPI specification from ${url}: ${response.status}.`
+ )
+ }
+
+ return { name, spec: JSON.parse(await response.text()) }
+ })
+ )
+
+ await writeFileImpl(outputPath, generateFgaRequirementsSource(parsedSpecs))
+}
+
+if (process.argv[1] === fileURLToPath(import.meta.url)) {
+ await generateFgaRequirements()
+}
diff --git a/packages/api-types/scripts/generate-fga-requirements.test.mjs b/packages/api-types/scripts/generate-fga-requirements.test.mjs
new file mode 100644
index 00000000000..c86de7291f9
--- /dev/null
+++ b/packages/api-types/scripts/generate-fga-requirements.test.mjs
@@ -0,0 +1,69 @@
+import assert from 'node:assert/strict'
+import test from 'node:test'
+
+import { generateFgaRequirements } from './generate-fga-requirements.mjs'
+
+const specifications = [
+ { name: 'api-v1', url: 'http://local/api/v1-json' },
+ { name: 'api-v2', url: 'http://local/api/v2-json' },
+ { name: 'platform', url: 'http://local/api/platform-json' },
+]
+
+const specs = {
+ 'http://local/api/v1-json': {
+ paths: { '/v1/x': { get: { 'x-fga-permissions': [['a_read']] } } },
+ },
+ 'http://local/api/v2-json': {
+ paths: { '/v2/x': { get: { 'x-fga-permissions': [] } } },
+ },
+ 'http://local/api/platform-json': {
+ components: {
+ schemas: {
+ CreateScopedAccessTokenBody: {
+ properties: { permissions: { items: { enum: ['a_read'] } } },
+ },
+ },
+ },
+ paths: {},
+ },
+}
+
+test('generateFgaRequirements writes the rendered requirements', async () => {
+ const writes = []
+
+ await generateFgaRequirements({
+ specifications,
+ outputPath: '/out/fga-requirements.ts',
+ fetchImpl: async (url) => ({ ok: true, text: async () => JSON.stringify(specs[url]) }),
+ writeFileImpl: async (path, content) => writes.push([path, content]),
+ })
+
+ assert.equal(writes.length, 1)
+ assert.equal(writes[0][0], '/out/fga-requirements.ts')
+ assert.match(writes[0][1], /"GET \/v1\/x": \[\["a_read"\]\],/)
+ assert.doesNotMatch(writes[0][1], /\/v2\/x/)
+})
+
+test('generateFgaRequirements rejects when a specification response is not OK', async () => {
+ await assert.rejects(
+ generateFgaRequirements({
+ specifications,
+ fetchImpl: async () => ({ ok: false, status: 503 }),
+ writeFileImpl: async () => assert.fail('should not write'),
+ }),
+ /Could not fetch api-v1 OpenAPI specification from http:\/\/local\/api\/v1-json: 503/
+ )
+})
+
+test('generateFgaRequirements rejects when a fetch fails', async () => {
+ await assert.rejects(
+ generateFgaRequirements({
+ specifications,
+ fetchImpl: async () => {
+ throw new Error('ECONNREFUSED')
+ },
+ writeFileImpl: async () => assert.fail('should not write'),
+ }),
+ /Could not fetch api-v1 OpenAPI specification from http:\/\/local\/api\/v1-json/
+ )
+})
diff --git a/packages/api-types/scripts/generate-production-types.test.mjs b/packages/api-types/scripts/generate-production-types.test.mjs
index cf29896f75b..9398ebe5aeb 100644
--- a/packages/api-types/scripts/generate-production-types.test.mjs
+++ b/packages/api-types/scripts/generate-production-types.test.mjs
@@ -6,6 +6,19 @@ import test from 'node:test'
import { generateTypes } from './verify-production-types.mjs'
+const validSpecification = JSON.stringify({
+ components: {
+ schemas: {
+ CreateScopedAccessTokenBody: {
+ properties: { permissions: { items: { enum: ['project_admin_read'] } } },
+ },
+ },
+ },
+ paths: {
+ '/v1/projects': { get: { 'x-fga-permissions': [['project_admin_read']] } },
+ },
+})
+
const specifications = [{ name: 'api-v1', url: 'https://example.com/api/v1-json' }]
test('generateTypes fetches specifications and generates types straight into the given directory', async (t) => {
@@ -20,7 +33,7 @@ test('generateTypes fetches specifications and generates types straight into the
await generateTypes(specifications, {
temporaryDirectory,
generatedTypesDirectory,
- fetchImpl: async (url) => ({ ok: true, text: async () => `spec from ${url}` }),
+ fetchImpl: async (url) => ({ ok: true, text: async () => validSpecification }),
runImpl: async (command, args) => {
runCalls.push([command, args])
if (args.includes('--find-config-path')) return { stdout: '/repo/.prettierrc\n' }
@@ -29,7 +42,10 @@ test('generateTypes fetches specifications and generates types straight into the
})
const specification = await readFile(join(temporaryDirectory, 'api-v1.json'), 'utf8')
- assert.match(specification, /v1-json/)
+ assert.equal(specification, validSpecification)
+
+ const fga = await readFile(join(generatedTypesDirectory, 'fga-requirements.ts'), 'utf8')
+ assert.match(fga, /"GET \/v1\/projects": \[\["project_admin_read"\]\]/)
const redocly = await readFile(join(temporaryDirectory, 'redocly.yaml'), 'utf8')
assert.match(redocly, new RegExp(`output: ${generatedTypesDirectory}/api-v1.d.ts`))
@@ -40,4 +56,5 @@ test('generateTypes fetches specifications and generates types straight into the
assert.ok(runCalls[1][1].includes('--find-config-path'))
assert.ok(runCalls[2][1].includes('--write'))
assert.ok(runCalls[2][1].includes(join(generatedTypesDirectory, 'api-v1.d.ts')))
+ assert.ok(runCalls[2][1].includes(join(generatedTypesDirectory, 'fga-requirements.ts')))
})
diff --git a/packages/api-types/scripts/verify-production-types.mjs b/packages/api-types/scripts/verify-production-types.mjs
index 03b7673e712..af64d79d5ab 100644
--- a/packages/api-types/scripts/verify-production-types.mjs
+++ b/packages/api-types/scripts/verify-production-types.mjs
@@ -5,6 +5,8 @@ import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { promisify } from 'node:util'
+import { generateFgaRequirementsSource } from './fga-requirements.mjs'
+
const run = promisify(execFile)
const packageDirectory = dirname(dirname(fileURLToPath(import.meta.url)))
const typesDirectory = process.env.API_TYPES_DIRECTORY ?? join(packageDirectory, 'types')
@@ -12,6 +14,8 @@ const platformApiUrl =
process.env.PLATFORM_API_OPENAPI_URL ?? 'https://api.supabase.com/api/platform-json'
const fetchTimeout = 30_000
+export const FGA_REQUIREMENTS_FILENAME = 'fga-requirements.ts'
+
export const specifications = [
{ name: 'api-v1', url: 'https://api.supabase.com/api/v1-json' },
{ name: 'api-v2', url: 'https://api.supabase.com/api/v2-json' },
@@ -51,9 +55,9 @@ export async function findMismatchedTypes(
specifications,
{ readFileImpl = readFile, generatedTypesDirectory, typesDirectory }
) {
+ const filenames = [...specifications.map(({ name }) => `${name}.d.ts`), FGA_REQUIREMENTS_FILENAME]
const mismatches = await Promise.all(
- specifications.map(async ({ name }) => {
- const filename = `${name}.d.ts`
+ filenames.map(async (filename) => {
const [generated, committed] = await Promise.all([
readFileImpl(join(generatedTypesDirectory, filename), 'utf8'),
readFileImpl(join(typesDirectory, filename), 'utf8'),
@@ -123,7 +127,14 @@ export async function reportTypeDifferences(
// committed types directory).
export async function generateTypes(
specifications,
- { temporaryDirectory, generatedTypesDirectory, runImpl = run, fetchImpl, writeFileImpl }
+ {
+ temporaryDirectory,
+ generatedTypesDirectory,
+ runImpl = run,
+ fetchImpl,
+ writeFileImpl,
+ readFileImpl = readFile,
+ }
) {
const config = await fetchOpenApiSpecifications(specifications, {
temporaryDirectory,
@@ -132,6 +143,17 @@ export async function generateTypes(
writeFileImpl,
})
+ const parsedSpecifications = await Promise.all(
+ specifications.map(async ({ name }) => ({
+ name,
+ spec: JSON.parse(await readFileImpl(join(temporaryDirectory, `${name}.json`), 'utf8')),
+ }))
+ )
+ await writeFile(
+ join(generatedTypesDirectory, FGA_REQUIREMENTS_FILENAME),
+ generateFgaRequirementsSource(parsedSpecifications)
+ )
+
await writeFile(join(temporaryDirectory, 'redocly.yaml'), `apis:\n${config.join('\n')}`)
await runImpl(
'pnpm',
@@ -164,6 +186,7 @@ export async function generateTypes(
prettierConfigPath.trim(),
'--write',
...specifications.map(({ name }) => join(generatedTypesDirectory, `${name}.d.ts`)),
+ join(generatedTypesDirectory, FGA_REQUIREMENTS_FILENAME),
],
{ cwd: packageDirectory }
)
diff --git a/packages/api-types/scripts/verify-production-types.test.mjs b/packages/api-types/scripts/verify-production-types.test.mjs
index 97f7e93932f..b092ba7a342 100644
--- a/packages/api-types/scripts/verify-production-types.test.mjs
+++ b/packages/api-types/scripts/verify-production-types.test.mjs
@@ -108,7 +108,7 @@ test('reports every generated type that differs from its committed counterpart',
generatedTypesDirectory: '/generated',
typesDirectory: '/committed',
readFileImpl: async (path) => {
- if (path.endsWith('api-v1.d.ts')) return 'matching type'
+ if (!path.endsWith('platform.d.ts')) return 'matching type'
return path.includes('/generated/') ? 'new platform type' : 'committed platform type'
},
})
@@ -116,6 +116,19 @@ test('reports every generated type that differs from its committed counterpart',
assert.deepEqual(mismatches, ['platform.d.ts'])
})
+test('reports fga-requirements.ts when it differs from the committed file', async () => {
+ const mismatches = await findMismatchedTypes(specifications, {
+ generatedTypesDirectory: '/generated',
+ typesDirectory: '/committed',
+ readFileImpl: async (path) => {
+ if (!path.endsWith('fga-requirements.ts')) return 'matching type'
+ return path.includes('/generated/') ? 'new requirements' : 'committed requirements'
+ },
+ })
+
+ assert.deepEqual(mismatches, ['fga-requirements.ts'])
+})
+
test('rejects unsuccessful OpenAPI responses', async () => {
await assert.rejects(
fetchOpenApiSpecifications([specifications[0]], {
diff --git a/packages/api-types/types/fga-requirements.ts b/packages/api-types/types/fga-requirements.ts
new file mode 100644
index 00000000000..80d4de5efa4
--- /dev/null
+++ b/packages/api-types/types/fga-requirements.ts
@@ -0,0 +1,305 @@
+// Generated by `pnpm --filter=api-types codegen:prod` from the production OpenAPI specifications. Do not edit by hand.
+// Maps each endpoint annotated with `x-fga-permissions` to the FGA permissions it requires. A caller
+// needs every permission in at least one group (OR between groups, AND within a group). Keys are the
+// path literals passed to openapi-fetch.
+
+export const fgaRequirements = {
+ 'DELETE /platform/organizations/{slug}/apps/installations/{installation_id}': [
+ ['organization_admin_write'],
+ ],
+ 'DELETE /platform/organizations/{slug}/apps/{app_id}': [['organization_admin_write']],
+ 'DELETE /platform/organizations/{slug}/apps/{app_id}/signing-keys/{key_id}': [
+ ['organization_admin_write'],
+ ],
+ 'DELETE /platform/organizations/{slug}/members/invitations/{id}': [['members_write']],
+ 'DELETE /v1/branches/{branch_id_or_ref}': [
+ ['branching_development_delete'],
+ ['branching_production_delete'],
+ ],
+ 'DELETE /v1/projects/{ref}': [['project_admin_write']],
+ 'DELETE /v1/projects/{ref}/api-keys/{id}': [['api_gateway_keys_write']],
+ 'DELETE /v1/projects/{ref}/billing/addons/{addon_variant}': [['infra_add_ons_write']],
+ 'DELETE /v1/projects/{ref}/branches': [['branching_production_delete']],
+ 'DELETE /v1/projects/{ref}/claim-token': [['organization_admin_write', 'project_admin_write']],
+ 'DELETE /v1/projects/{ref}/cli/login-role': [['database_write']],
+ 'DELETE /v1/projects/{ref}/config/auth/signing-keys/{id}': [['auth_signing_keys_write']],
+ 'DELETE /v1/projects/{ref}/config/auth/sso/providers/{provider_id}': [['auth_config_write']],
+ 'DELETE /v1/projects/{ref}/config/auth/third-party-auth/{tpa_id}': [['auth_config_write']],
+ 'DELETE /v1/projects/{ref}/custom-hostname': [['custom_domain_write']],
+ 'DELETE /v1/projects/{ref}/database/jit/invite/{invite_id}': [['database_jit_write']],
+ 'DELETE /v1/projects/{ref}/database/jit/{user_id}': [['database_jit_write']],
+ 'DELETE /v1/projects/{ref}/database/migrations': [['database_migrations_write']],
+ 'DELETE /v1/projects/{ref}/functions/{function_slug}': [['edge_functions_write']],
+ 'DELETE /v1/projects/{ref}/network-bans': [['database_network_bans_write']],
+ 'DELETE /v1/projects/{ref}/secrets': [['edge_functions_secrets_write']],
+ 'DELETE /v1/projects/{ref}/vanity-subdomain': [['vanity_subdomain_write']],
+ 'DELETE /v2/organizations/{slug}/members/invitations': [['members_write']],
+ 'DELETE /v2/projects/{ref}/analytics/log-drains/{id}': [['analytics_config_write']],
+ 'DELETE /v2/projects/{ref}/compute/{name}': [['workers_write']],
+ 'DELETE /v2/projects/{ref}/notebooks/{id}': [['project_notebooks_write']],
+ 'DELETE /v2/projects/{ref}/private-link/associations/aws-account/{aws_account_id}': [
+ ['project_admin_write'],
+ ],
+ 'DELETE /v2/projects/{ref}/private-link/associations/aws-account/{aws_account_id}/database/{database_identifier}':
+ [['project_admin_write']],
+ 'GET /platform/database/{ref}/backups': [['backups_read']],
+ 'GET /platform/database/{ref}/backups/downloadable-backups': [['backups_read']],
+ 'GET /platform/oauth/authorizations/{id}': [['organization_admin_read']],
+ 'GET /platform/organizations/{slug}/apps': [['organization_admin_read']],
+ 'GET /platform/organizations/{slug}/apps/installations': [['organization_admin_read']],
+ 'GET /platform/organizations/{slug}/apps/installations/{installation_id}': [
+ ['organization_admin_read'],
+ ],
+ 'GET /platform/organizations/{slug}/apps/{app_id}': [['organization_admin_read']],
+ 'GET /platform/organizations/{slug}/apps/{app_id}/signing-keys': [['organization_admin_read']],
+ 'GET /platform/organizations/{slug}/billing/credits/burndown': [['organization_admin_read']],
+ 'GET /platform/organizations/{slug}/members/invitations': [['members_read']],
+ 'GET /platform/storage/{ref}/archive': [['storage_write']],
+ 'GET /v1/branches/{branch_id_or_ref}': [
+ ['branching_development_read'],
+ ['branching_production_read'],
+ ],
+ 'GET /v1/branches/{branch_id_or_ref}/diff': [
+ ['branching_development_write'],
+ ['branching_production_write'],
+ ],
+ 'GET /v1/oauth/authorize/project-claim': [['organization_admin_write', 'project_admin_write']],
+ 'GET /v1/organizations': [['organizations_read']],
+ 'GET /v1/organizations/{slug}': [['organization_admin_read']],
+ 'GET /v1/organizations/{slug}/entitlements': [['organization_admin_read']],
+ 'GET /v1/organizations/{slug}/members': [['members_read']],
+ 'GET /v1/organizations/{slug}/project-claim/{token}': [['organization_admin_write']],
+ 'GET /v1/organizations/{slug}/projects': [['organization_projects_read']],
+ 'GET /v1/projects': [['projects_read']],
+ 'GET /v1/projects/{ref}': [['project_admin_read']],
+ 'GET /v1/projects/{ref}/actions': [['action_runs_read']],
+ 'GET /v1/projects/{ref}/actions/{run_id}': [['action_runs_read']],
+ 'GET /v1/projects/{ref}/actions/{run_id}/logs': [['action_runs_read']],
+ 'GET /v1/projects/{ref}/advisors/performance': [['advisors_read']],
+ 'GET /v1/projects/{ref}/advisors/security': [['advisors_read']],
+ 'GET /v1/projects/{ref}/analytics/endpoints/functions.combined-stats': [['analytics_usage_read']],
+ 'GET /v1/projects/{ref}/analytics/endpoints/logs': [['analytics_logs_read']],
+ 'GET /v1/projects/{ref}/analytics/endpoints/logs.all': [['analytics_logs_read']],
+ 'GET /v1/projects/{ref}/analytics/endpoints/metrics': [['analytics_logs_read']],
+ 'GET /v1/projects/{ref}/analytics/endpoints/usage.api-counts': [['analytics_usage_read']],
+ 'GET /v1/projects/{ref}/analytics/endpoints/usage.api-requests-count': [['analytics_usage_read']],
+ 'GET /v1/projects/{ref}/api-keys': [
+ ['api_gateway_keys_read'],
+ ['api_gateway_keys_read', 'api_gateway_keys_secret_read'],
+ ],
+ 'GET /v1/projects/{ref}/api-keys/legacy': [['api_gateway_keys_read']],
+ 'GET /v1/projects/{ref}/api-keys/{id}': [
+ ['api_gateway_keys_read'],
+ ['api_gateway_keys_read', 'api_gateway_keys_secret_read'],
+ ],
+ 'GET /v1/projects/{ref}/billing/addons': [['infra_add_ons_read']],
+ 'GET /v1/projects/{ref}/branches': [
+ ['branching_development_read'],
+ ['branching_production_read'],
+ ],
+ 'GET /v1/projects/{ref}/branches/{name}': [
+ ['branching_development_read'],
+ ['branching_production_read'],
+ ],
+ 'GET /v1/projects/{ref}/claim-token': [['project_admin_read']],
+ 'GET /v1/projects/{ref}/config/auth': [['auth_config_read']],
+ 'GET /v1/projects/{ref}/config/auth/signing-keys': [['auth_signing_keys_read']],
+ 'GET /v1/projects/{ref}/config/auth/signing-keys/legacy': [['auth_signing_keys_read']],
+ 'GET /v1/projects/{ref}/config/auth/signing-keys/{id}': [['auth_signing_keys_read']],
+ 'GET /v1/projects/{ref}/config/auth/sso/providers': [['auth_config_read']],
+ 'GET /v1/projects/{ref}/config/auth/sso/providers/{provider_id}': [['auth_config_read']],
+ 'GET /v1/projects/{ref}/config/auth/third-party-auth': [['auth_config_read']],
+ 'GET /v1/projects/{ref}/config/auth/third-party-auth/{tpa_id}': [['auth_config_read']],
+ 'GET /v1/projects/{ref}/config/database/pgbouncer': [['database_read']],
+ 'GET /v1/projects/{ref}/config/database/pooler': [['database_pooling_config_read']],
+ 'GET /v1/projects/{ref}/config/database/postgres': [['database_config_read']],
+ 'GET /v1/projects/{ref}/config/disk': [['infra_disk_config_read']],
+ 'GET /v1/projects/{ref}/config/disk/autoscale': [['infra_disk_config_read']],
+ 'GET /v1/projects/{ref}/config/disk/util': [['infra_disk_config_read']],
+ 'GET /v1/projects/{ref}/config/realtime': [['realtime_config_read']],
+ 'GET /v1/projects/{ref}/config/storage': [['storage_config_read']],
+ 'GET /v1/projects/{ref}/custom-hostname': [['custom_domain_read']],
+ 'GET /v1/projects/{ref}/database/backups': [['backups_read']],
+ 'GET /v1/projects/{ref}/database/backups/restore-point': [['backups_read']],
+ 'GET /v1/projects/{ref}/database/backups/schedule': [['backups_read']],
+ 'GET /v1/projects/{ref}/database/context': [['database_read']],
+ 'GET /v1/projects/{ref}/database/jit': [['database_jit_read']],
+ 'GET /v1/projects/{ref}/database/jit/list': [['database_jit_write']],
+ 'GET /v1/projects/{ref}/database/migrations': [['database_migrations_read']],
+ 'GET /v1/projects/{ref}/database/migrations/{version}': [['database_migrations_read']],
+ 'GET /v1/projects/{ref}/database/openapi': [['database_read']],
+ 'GET /v1/projects/{ref}/functions': [['edge_functions_read']],
+ 'GET /v1/projects/{ref}/functions/{function_slug}': [['edge_functions_read']],
+ 'GET /v1/projects/{ref}/functions/{function_slug}/body': [['edge_functions_read']],
+ 'GET /v1/projects/{ref}/health': [['project_admin_read']],
+ 'GET /v1/projects/{ref}/jit-access': [['project_admin_read']],
+ 'GET /v1/projects/{ref}/network-restrictions': [['database_network_restrictions_read']],
+ 'GET /v1/projects/{ref}/pgsodium': [['project_admin_write']],
+ 'GET /v1/projects/{ref}/postgrest': [
+ ['data_api_config_read'],
+ ['data_api_config_read', 'data_api_config_secret_read'],
+ ],
+ 'GET /v1/projects/{ref}/readonly': [['database_readonly_config_read']],
+ 'GET /v1/projects/{ref}/restore': [['project_admin_read']],
+ 'GET /v1/projects/{ref}/secrets': [['edge_functions_secrets_read']],
+ 'GET /v1/projects/{ref}/ssl-enforcement': [['database_ssl_config_read']],
+ 'GET /v1/projects/{ref}/storage/buckets': [['storage_read']],
+ 'GET /v1/projects/{ref}/types/typescript': [['database_read']],
+ 'GET /v1/projects/{ref}/upgrade/eligibility': [['project_admin_read', 'database_read']],
+ 'GET /v1/projects/{ref}/upgrade/status': [['project_admin_read', 'database_read']],
+ 'GET /v1/projects/{ref}/vanity-subdomain': [['vanity_subdomain_read']],
+ 'GET /v1/snippets': [['snippets_read']],
+ 'GET /v1/snippets/{id}': [['snippets_read']],
+ 'GET /v2/organizations/{slug}/integrations/github/connections': [['organization_projects_read']],
+ 'GET /v2/organizations/{slug}/members': [['members_read']],
+ 'GET /v2/organizations/{slug}/projects': [['organization_projects_read']],
+ 'GET /v2/organizations/{slug}/roles': [['members_read']],
+ 'GET /v2/projects/{ref}/analytics/log-drains': [['analytics_config_read']],
+ 'GET /v2/projects/{ref}/compute': [['workers_read']],
+ 'GET /v2/projects/{ref}/compute/{name}': [['workers_read']],
+ 'GET /v2/projects/{ref}/config': [
+ [
+ 'database_config_read',
+ 'database_read',
+ 'database_ssl_config_read',
+ 'database_network_restrictions_read',
+ 'auth_config_read',
+ 'data_api_config_read',
+ 'realtime_config_read',
+ 'storage_config_read',
+ ],
+ ],
+ 'GET /v2/projects/{ref}/notebooks': [['project_notebooks_read']],
+ 'GET /v2/projects/{ref}/notebooks/{id}': [['project_notebooks_read']],
+ 'GET /v2/projects/{ref}/private-link/associations': [['project_admin_read']],
+ 'HEAD /v1/projects/{ref}/actions': [['action_runs_read']],
+ 'PATCH /platform/feedback/conversations/{conversation_id}/custom-fields': [['database_read']],
+ 'PATCH /platform/organizations/{slug}/apps/installations/{installation_id}': [
+ ['organization_admin_write'],
+ ],
+ 'PATCH /platform/organizations/{slug}/apps/{app_id}': [['organization_admin_write']],
+ 'PATCH /v1/branches/{branch_id_or_ref}': [
+ ['branching_development_write'],
+ ['branching_production_write'],
+ ],
+ 'PATCH /v1/projects/{ref}': [['project_admin_write']],
+ 'PATCH /v1/projects/{ref}/actions/{run_id}/status': [['action_runs_write']],
+ 'PATCH /v1/projects/{ref}/api-keys/{id}': [['api_gateway_keys_write']],
+ 'PATCH /v1/projects/{ref}/billing/addons': [['infra_add_ons_write']],
+ 'PATCH /v1/projects/{ref}/config/auth': [['auth_config_write', 'project_admin_write']],
+ 'PATCH /v1/projects/{ref}/config/auth/signing-keys/{id}': [['auth_signing_keys_write']],
+ 'PATCH /v1/projects/{ref}/config/database/pooler': [['database_pooling_config_write']],
+ 'PATCH /v1/projects/{ref}/config/realtime': [['realtime_config_write']],
+ 'PATCH /v1/projects/{ref}/config/storage': [['storage_config_write']],
+ 'PATCH /v1/projects/{ref}/database/backups/schedule': [['backups_write']],
+ 'PATCH /v1/projects/{ref}/database/migrations/{version}': [['database_migrations_write']],
+ 'PATCH /v1/projects/{ref}/database/password': [['database_config_write']],
+ 'PATCH /v1/projects/{ref}/functions/{function_slug}': [['edge_functions_write']],
+ 'PATCH /v1/projects/{ref}/network-restrictions': [['database_network_restrictions_write']],
+ 'PATCH /v1/projects/{ref}/postgrest': [['data_api_config_write']],
+ 'PATCH /v2/organizations/{slug}/members/{user_id}/roles': [['organization_admin_write']],
+ 'PATCH /v2/projects/{ref}/notebooks/{id}': [['project_notebooks_write']],
+ 'POST /platform/database/{ref}/backups/download': [['backups_write']],
+ 'POST /platform/database/{ref}/backups/pitr': [['backups_write']],
+ 'POST /platform/database/{ref}/backups/restore': [['backups_write']],
+ 'POST /platform/database/{ref}/backups/restore-physical': [['backups_write']],
+ 'POST /platform/feedback/send': [['organization_admin_read'], ['project_admin_read']],
+ 'POST /platform/organizations/{slug}/apps': [['organization_admin_write']],
+ 'POST /platform/organizations/{slug}/apps/installations': [['organization_admin_write']],
+ 'POST /platform/organizations/{slug}/apps/{app_id}/signing-keys': [['organization_admin_write']],
+ 'POST /platform/organizations/{slug}/members/invitations': [['members_write']],
+ 'POST /platform/pg-meta/{ref}/query': [['database_read']],
+ 'POST /platform/projects/{ref}/api/graphql': [['database_read'], ['database_write']],
+ 'POST /platform/projects/{ref}/resize': [['project_admin_write']],
+ 'POST /platform/projects/{ref}/restart': [['database_write']],
+ 'POST /platform/projects/{ref}/restart-services': [['database_write']],
+ 'POST /platform/projects/{ref}/wake': [['project_admin_read']],
+ 'POST /platform/storage/{ref}/archive': [['storage_write']],
+ 'POST /v1/branches/{branch_id_or_ref}/merge': [
+ ['branching_development_write'],
+ ['branching_production_write'],
+ ],
+ 'POST /v1/branches/{branch_id_or_ref}/push': [
+ ['branching_development_write'],
+ ['branching_production_write'],
+ ],
+ 'POST /v1/branches/{branch_id_or_ref}/reset': [
+ ['branching_development_write'],
+ ['branching_production_write'],
+ ],
+ 'POST /v1/branches/{branch_id_or_ref}/restore': [
+ ['branching_development_write'],
+ ['branching_production_write'],
+ ],
+ 'POST /v1/organizations': [['organizations_create']],
+ 'POST /v1/organizations/{slug}/project-claim/{token}': [['organization_admin_write']],
+ 'POST /v1/projects': [['organization_projects_create']],
+ 'POST /v1/projects/{ref}/api-keys': [['api_gateway_keys_write']],
+ 'POST /v1/projects/{ref}/branches': [
+ ['branching_development_create'],
+ ['branching_production_create'],
+ ],
+ 'POST /v1/projects/{ref}/claim-token': [['organization_admin_write', 'project_admin_write']],
+ 'POST /v1/projects/{ref}/cli/login-role': [['database_write']],
+ 'POST /v1/projects/{ref}/config/auth/signing-keys': [['auth_signing_keys_write']],
+ 'POST /v1/projects/{ref}/config/auth/signing-keys/legacy': [['auth_signing_keys_write']],
+ 'POST /v1/projects/{ref}/config/auth/sso/providers': [['auth_config_write']],
+ 'POST /v1/projects/{ref}/config/auth/third-party-auth': [['auth_config_write']],
+ 'POST /v1/projects/{ref}/config/disk': [['infra_disk_config_write']],
+ 'POST /v1/projects/{ref}/config/realtime/shutdown': [['realtime_config_write']],
+ 'POST /v1/projects/{ref}/custom-hostname/activate': [['custom_domain_write']],
+ 'POST /v1/projects/{ref}/custom-hostname/initialize': [['custom_domain_write']],
+ 'POST /v1/projects/{ref}/custom-hostname/reverify': [['custom_domain_write']],
+ 'POST /v1/projects/{ref}/database/backups/restore': [['backups_write']],
+ 'POST /v1/projects/{ref}/database/backups/restore-pitr': [['backups_write']],
+ 'POST /v1/projects/{ref}/database/backups/restore-point': [['backups_write']],
+ 'POST /v1/projects/{ref}/database/backups/undo': [['backups_write']],
+ 'POST /v1/projects/{ref}/database/jit': [['database_jit_read']],
+ 'POST /v1/projects/{ref}/database/jit/invite': [['database_jit_write']],
+ 'POST /v1/projects/{ref}/database/migrations': [['database_migrations_write']],
+ 'POST /v1/projects/{ref}/database/query': [['database_read'], ['database_write']],
+ 'POST /v1/projects/{ref}/database/query/read-only': [['database_read']],
+ 'POST /v1/projects/{ref}/database/webhooks/enable': [['database_webhooks_config_write']],
+ 'POST /v1/projects/{ref}/functions': [['edge_functions_write']],
+ 'POST /v1/projects/{ref}/functions/deploy': [['edge_functions_write']],
+ 'POST /v1/projects/{ref}/network-bans/retrieve': [['database_network_bans_read']],
+ 'POST /v1/projects/{ref}/network-bans/retrieve/enriched': [['database_network_bans_read']],
+ 'POST /v1/projects/{ref}/network-restrictions/apply': [['database_network_restrictions_write']],
+ 'POST /v1/projects/{ref}/pause': [['project_admin_write']],
+ 'POST /v1/projects/{ref}/read-replicas/remove': [['infra_read_replicas_write']],
+ 'POST /v1/projects/{ref}/read-replicas/setup': [['infra_read_replicas_write']],
+ 'POST /v1/projects/{ref}/readonly/temporary-disable': [['database_readonly_config_write']],
+ 'POST /v1/projects/{ref}/restart': [['project_admin_write']],
+ 'POST /v1/projects/{ref}/restore': [['project_admin_write']],
+ 'POST /v1/projects/{ref}/restore/cancel': [['project_admin_write']],
+ 'POST /v1/projects/{ref}/secrets': [['edge_functions_secrets_write']],
+ 'POST /v1/projects/{ref}/upgrade': [['project_admin_write', 'database_write']],
+ 'POST /v1/projects/{ref}/vanity-subdomain/activate': [['vanity_subdomain_write']],
+ 'POST /v1/projects/{ref}/vanity-subdomain/check-availability': [['vanity_subdomain_write']],
+ 'POST /v2/organizations/{slug}/members/invitations': [['members_write']],
+ 'POST /v2/projects/{ref}/advisors/run': [['advisors_read']],
+ 'POST /v2/projects/{ref}/analytics/log-drains': [['analytics_config_write']],
+ 'POST /v2/projects/{ref}/branches': [
+ ['branching_development_create'],
+ ['branching_production_create'],
+ ],
+ 'POST /v2/projects/{ref}/compute/{name}/deploy': [['workers_write']],
+ 'POST /v2/projects/{ref}/compute/{name}/uploads': [['workers_write']],
+ 'POST /v2/projects/{ref}/notebooks': [['project_notebooks_write']],
+ 'POST /v2/projects/{ref}/private-link/associations': [['project_admin_write']],
+ 'POST /v2/projects/{ref}/transfers': [['organization_admin_write']],
+ 'POST /v2/projects/{ref}/transfers/previews': [['project_admin_read']],
+ 'PUT /v1/projects/{ref}/api-keys/legacy': [['api_gateway_keys_write']],
+ 'PUT /v1/projects/{ref}/config/auth/sso/providers/{provider_id}': [['auth_config_write']],
+ 'PUT /v1/projects/{ref}/config/database/postgres': [['database_config_write']],
+ 'PUT /v1/projects/{ref}/database/jit': [['database_jit_write']],
+ 'PUT /v1/projects/{ref}/database/migrations': [['database_migrations_write']],
+ 'PUT /v1/projects/{ref}/functions': [['edge_functions_write']],
+ 'PUT /v1/projects/{ref}/jit-access': [['project_admin_write']],
+ 'PUT /v1/projects/{ref}/pgsodium': [['project_admin_write']],
+ 'PUT /v1/projects/{ref}/ssl-enforcement': [['database_ssl_config_write']],
+ 'PUT /v2/projects/{ref}/analytics/log-drains/{id}': [['analytics_config_write']],
+} as const
+
+export type FgaRequirements = typeof fgaRequirements
+export type FgaGuardedEndpoint = keyof FgaRequirements