supabase-admin

Supabase Management API bindings for Hot. Manage projects, organizations, databases, edge functions, preview branches, and custom domains programmatically.

Installation

Add this to the deps in your hot.hot file:

"hot.dev/supabase-admin": "1.1.0"

Configuration

Set the supabase.access.token context variable to a Personal Access Token (PAT) via the Hot app.

Generate a PAT at supabase.com/dashboard/account/tokens.

The package also supports explicit PAT overrides through the low-level ::supabase::admin::api/request arity that accepts an access-token; this is useful for scripts and tests that should not mutate context.

Usage

List Projects

::projects ::supabase::admin::projects

projects ::projects/list-projects()
// => [{id: "abc", name: "My App", region: "us-east-1", ...}, ...]

Get Project API Keys

::projects ::supabase::admin::projects

keys ::projects/get-api-keys("my-project-ref")
// => [{name: "anon", api_key: "eyJ..."}, {name: "service_role", api_key: "eyJ..."}]

Create a Project

::projects ::supabase::admin::projects

project ::projects/create-project(::projects/CreateProjectRequest({
  name: "My New App",
  organization_id: "org-abc-123",
  region: "us-east-1",
  db_pass: "secureDbPassword123!"
}))

Pause / Restore a Project

::projects ::supabase::admin::projects

::projects/pause-project("my-project-ref")
::projects/restore-project("my-project-ref")

List Organizations

::orgs ::supabase::admin::organizations

orgs ::orgs/list-organizations()
members ::orgs/list-members("my-org-slug")

Run a SQL Query

::databases ::supabase::admin::databases

result ::databases/run-query(::databases/RunQueryRequest({
  project_ref: "my-project-ref",
  query: "SELECT count(*) FROM auth.users"
}))

Manage Edge Functions

::functions ::supabase::admin::functions

// List functions
fns ::functions/list-functions("my-project-ref")

// Deploy a function
::functions/create-function(::functions/CreateFunctionRequest({
  project_ref: "my-project-ref",
  slug: "hello-world",
  name: "hello-world",
  body: "Deno.serve(() => new Response('Hello!'))",
  verify_jwt: true
}))

// Delete a function
::functions/delete-function("my-project-ref", "hello-world")

Preview Branches

::branches ::supabase::admin::branches

// List branches
branches ::branches/list-branches("my-project-ref")

// Create a branch
::branches/create-branch(::branches/CreateBranchRequest({
  project_ref: "my-project-ref",
  branch_name: "feat-auth",
  git_branch: "feat/auth"
}))

// Merge back to parent
::branches/merge-branch("branch-id")

Custom Domains

::domains ::supabase::admin::domains

// Configure custom hostname
::domains/update-custom-hostname(::domains/UpdateCustomHostnameRequest({
  project_ref: "my-project-ref",
  custom_hostname: "api.myapp.com"
}))

// Verify DNS and activate
::domains/verify-custom-hostname("my-project-ref")
::domains/activate-custom-hostname("my-project-ref")

Per-call credentials

Every function that calls the Management API takes an optional trailing opts Map, so one run can act for many accounts and parallel flows don't share credentials. Nothing from opts is written to ctx.

A per-call credential is masked in the run's call records, including inside strings like Bearer ${key}. A secret shorter than 8 bytes is masked only as a whole value. Records of your own calls that finished before this one may already be written, so mark a credential your code fetches with ::hot::ctx/mark-secret as soon as you have it.

KeyEffect
access-tokenThe Personal Access Token for this call, instead of supabase.access.token
base-urlAnother API root, such as a proxy. Needs an access-token in the same opts; supabase.access.token is never sent to a per-call URL
tenant {access-token: "sbp_tenant_b"}
projects ::supabase::admin::projects/list-projects(tenant)
orgs ::supabase::admin::organizations/list-organizations(tenant)
openapi ::supabase::admin::projects/get-database-openapi("my-project-ref", null, tenant)

opts always comes last, so pass null or the default value for an optional argument before it. An access-token that is present but blank or null is an error naming the key, never a fallback to supabase.access.token. ::supabase::admin::api/resolve(opts) is the one place this is decided.

API Base URL

https://api.supabase.com/v1

Modules

ModuleDescription
::supabase::admin::projectsProject CRUD, pause/restore, API keys, config, health, usage
::supabase::admin::organizationsOrganization CRUD, members, org projects
::supabase::admin::databasesPostgres config, backups, migrations, SQL query, replicas, upgrades
::supabase::admin::functionsEdge function CRUD, deploy, get source
::supabase::admin::branchesPreview branch CRUD, push, reset, merge
::supabase::admin::domainsCustom hostnames, vanity subdomains
::supabase::admin::apiLow-level Management API client
::supabase::admin::coreShared configuration (BASE_URL)

Integration Tests

Offline unit tests cover known Management API path builders:

cd hot/pkg/supabase-admin
hot test --conf hot.test.hot

1. Generate a Personal Access Token

  1. Go to supabase.com/dashboard/account/tokens
  2. Click Generate new token
  3. Give it a name and copy the token

2. Set Context Variables

supabase.access.token=sbp_your_personal_access_token

3. Run the Tests

hot test hot/pkg/supabase-admin/integration-test/

The tests are read-only -- they list projects, organizations, members, API keys, and health checks. No projects or resources are created or modified.

What the Tests Do

Test FileWhat It TestsSide Effects
projects.hotList projects, get project, API keys, healthRead-only
organizations.hotList orgs, get org, list membersRead-only

Documentation

License

Apache-2.0 - see LICENSE