Transport for the Supabase Management API.

Per-call credentials. Every API-calling function in this package takes an optional trailing opts Map, resolved by resolve: opts first, then the supabase.access.token context variable, then the defaults. Nothing from opts is written to ctx, so one run can act for many accounts and parallel flows don't share credentials. An access-token present but blank or null is an error, never a fallback to context.

  • access-token: the Personal Access Token for this call
  • base-url: another API root, such as a proxy. It needs an access-token in the same opts: supabase.access.token is never sent to a per-call URL.

Functions

blank-credential

fn (opts: Map, names: Vec): Str?

The first of names that opts has but with a blank or null value, else null. Such a key is an error, never a fallback to context: a tenant whose key is missing must not run on the project's credentials.

Example

::supabase::admin::api/blank-credential({access-token: ""}, ["access-token"])  // "access-token"
::supabase::admin::api/blank-credential({}, ["access-token"])  // null

build-request

fn (method: Str, path: Str, additional-headers: Map, body: Any, resolved: Map): ::hot::http/HttpRequest

The outgoing HttpRequest from resolved settings (see resolve). additional-headers win over the defaults, and an empty body sends no Content-Type. Pure; exposed for testing.

Example

resolved {access-token: "test-token", base-url: "https://api.supabase.com/v1"}
req ::supabase::admin::api/build-request("GET", "/projects", {}, {}, resolved)
req.url  // "https://api.supabase.com/v1/projects"
req.body  // ""

request

fn (method: Str, path: Str): Any
fn (method: Str, path: Str, additional-headers: Map, body: Any): Any
fn (method: Str, path: Str, additional-headers: Map, body: Any, access-token: Str): Any
fn (method: Str, path: Str, additional-headers: Map, body: Any, opts: Map): Any

Call the Supabase Management API. Authentication uses a Personal Access Token (PAT) as a Bearer token.

Example

::api ::supabase::admin::api

response ::api/request("GET", "/projects")

// Per-call credentials
other ::api/request("GET", "/projects", {}, {}, {access-token: "sbp_tenant_b"})
Context Vars: supabase.access.token

request-raw

fn (method: Str, path: Str): ::hot::http/HttpResponse
fn (method: Str, path: Str, additional-headers: Map, body: Any): ::hot::http/HttpResponse
fn (method: Str, path: Str, additional-headers: Map, body: Any, access-token: Str): ::hot::http/HttpResponse
fn (method: Str, path: Str, additional-headers: Map, body: Any, opts: Map): ::hot::http/HttpResponse

Call the Supabase Management API and return the full HttpResponse including status and headers.

Example

::api ::supabase::admin::api

response ::api/request-raw("GET", "/projects")
response.status
response.body

// Per-call credentials
other ::api/request-raw("GET", "/projects", {}, {}, {access-token: ::hot::ctx/get("tenant_b.supabase.token")})
Context Vars: supabase.access.token

resolve

fn (opts: Map): Map

Credentials and settings for one call (see resolve-from). opts values are never written to ctx. A credential from opts is masked in the run's call records.

Example

::supabase::admin::api/resolve({access-token: "sbp_tenant_b"}).base-url  // "https://api.supabase.com/v1"
Context Vars: supabase.access.token

resolve-from

fn (opts: Map, ctx-values: Map): Map

The one resolver, pure: {access-token, base-url} for a call from opts first, then ctx-values (a Map of context variables), then defaults. An Err when no token is set, when access-token is in opts but blank or null (that never falls back to context), or when opts has base-url without access-token. Exposed for testing; resolve feeds it the context.

Example

::supabase::admin::api/resolve-from({}, {"supabase.access.token": "test-token"}).base-url  // "https://api.supabase.com/v1"
is-err(::supabase::admin::api/resolve-from({}, {}))  // true

Types

HttpError

HttpError type {
    status: Int,
    headers: Map,
    body: Any
}