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.

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.

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

Was this page helpful?