Quickstart
Install the client, wire in your Supabase URL and anon key, then call a resource. Most flows need Auth and tenant context for tenant-scoped data. This page shows the minimal path.
Grab the URL and anon key under Project Settings → API. Tenant-scoped lists require a signed-in user and client.setTenant(...) plus a session refresh. See Tenant context.
Install the SDK
npm install @workorder-systems/sdk @supabase/supabase-js
The SDK exposes resources (tenants, workOrders, assets, …) and helpers for tenant context on top of a typed client.supabase.
How the pieces connect
Your code talks to PostgREST (views + RPCs). Postgres and RLS enforce tenant safety under the hood.
Mermaid is enabled site-wide: use a fenced code block with the mermaid language tag, or the exported Mermaid component with a chart string prop.
Create a client and call the API
Listing tenants (after sign-in) does not require tenant context. Work orders and most domain APIs do: set tenant and refresh the session first.
Client + list tenants (after auth)
import { createDbClient } from '@workorder-systems/sdk'
const client = createDbClient(
process.env.SUPABASE_URL!,
process.env.SUPABASE_ANON_KEY!
)
const tenants = await client.tenants.list()
Tenant-scoped: sign in, set tenant, list work orders
await client.supabase.auth.signInWithPassword({
email: 'user@example.com',
password: 'password',
})
await client.setTenant(tenantId)
const { data: session } = await client.supabase.auth.getSession()
if (session.session) {
await client.supabase.auth.setSession({
access_token: session.session.access_token,
refresh_token: session.session.refresh_token,
})
}
const workOrders = await client.workOrders.list()
Tenant-scoped calls need both a signed-in user and a JWT that includes tenant_id after setTenant and session refresh:
Next steps
- Installation: peers, edge runtimes, env vars
- Authentication: Supabase Auth and the SDK session
- Tenant context: when and how to set
tenant_id - Errors:
SdkErrorand common codes