@kody/supabase
README.md
202 lines · 7.3 KB · Markdown@kody/supabase
Intent
Provide reusable, account-agnostic Supabase helpers so Kody agents can list
projects, administer Auth users, read and write PostgREST tables, manage
Storage, and call the Management API through saved secrets — without
hand-rolling REST or hard-coding a project. Mutations are previewable with
dryRun: true and only run live after confirm: true.
This listing is meant to be forked. After you fork, save your personal
access token and project service role / secret key. Do not treat the live
@kody/supabase package storage as yours.
When To Use
- List or inspect organizations and projects on the Management API
- List, create, update, or delete Auth users on a project
- Select, insert, update, or delete PostgREST table rows
- List buckets and objects; upload, delete, or sign Storage objects
- Call an unwrapped Management API or project API path
Auth
Supabase is secret-backed. There is no built-in Kody OAuth app for this package. Choose the secret that matches the surface:
| Lane | Secret | Host | Used for |
|---|---|---|---|
| Personal access token | supabasePat (or supabasePat-<purpose>) | api.supabase.com | Projects, organizations, ./management-request |
| Service role / secret key | supabaseServiceRoleKey (or supabaseServiceRoleKey-<purpose>) | {projectRef}.supabase.co | Auth admin, PostgREST, Storage, ./request |
Create a PAT at https://supabase.com/dashboard/account/tokens
Copy a project service role or secret key at https://supabase.com/dashboard/project/_/settings/api-keys/
The service role / secret key bypasses Row Level Security. Keep it in Kody secrets only. Never paste it into chat.
Save the personal access token
Approve host api.supabase.com in the account secrets UI.
Save the project service role / secret key
Replace YOUR_PROJECT_REF with the project ref (the subdomain of
YOUR_PROJECT_REF.supabase.co):
Approve host YOUR_PROJECT_REF.supabase.co. For a custom API domain, pass
projectUrl on every project call and approve that host instead.
Pass projectRef (or projectUrl) on Auth, table, Storage, and ./request
helpers. Do not hard-code a personal project ref in forks of this package.
Multiple accounts
Every export accepts:
account—work→supabasePat-work/supabaseServiceRoleKey-workpatSecretName— Management API secret overrideserviceRoleSecretName— project API secret overridesecretName— alias for the PAT on Management helpers, or the service role on project helpers
Safety
Mutating helpers require confirm: true. Pass dryRun: true to inspect the
method, path, and body without calling Supabase. ./request and
./management-request treat GET / HEAD / OPTIONS as read-only; POST / PUT /
PATCH / DELETE need confirmation.
Unfiltered ./update-rows and ./delete-rows also need
allowUnfiltered: true so a missing filter cannot rewrite or empty a table.
The package-owned smoke job is declared with "enabled": false.
Exports
| Export | Description |
|---|---|
. | Overview, setup URLs, and a safe smoke test |
./accounts | Resolve secret names and report what is saved |
./setup | Prefill /account/secrets/new URLs |
./smoke-test | Local dry-run checks plus optional live reads |
./list-projects | List Management API projects |
./get-project | Get one project by ref |
./list-organizations | List organizations |
./list-users | List Auth users (no email/phone unless includeIdentifiers) |
./get-user | Get one Auth user |
./create-user | Preview or create an Auth user |
./update-user | Preview or update an Auth user |
./delete-user | Preview or delete an Auth user |
./select-rows | PostgREST select |
./insert-rows | Preview or insert / upsert rows |
./update-rows | Preview or patch rows |
./delete-rows | Preview or delete rows |
./list-buckets | List Storage buckets |
./list-objects | List objects in a bucket |
./upload-object | Preview or upload an object |
./delete-object | Preview or delete objects |
./create-signed-url | Preview or create a signed URL |
./request | Generic project API escape hatch |
./management-request | Generic Management API escape hatch |
./types | Shared TypeScript types |
Smoke test
import supabase from 'kody:@kody/supabase'
export default async function main() {
return await supabase()
}Without credentials this returns { smoke: { ok: true, live: false } } plus
the PAT and service-role setup URLs. After secrets are saved it performs
read-only list calls (project refs, optional bucket names) and never writes.
Preview a mutation without credentials:
import insertRows from 'kody:@kody/supabase/insert-rows'
export default async function main() {
return await insertRows({
projectRef: 'yourprojectref00000',
table: 'items',
rows: [{ name: 'Preview only' }],
dryRun: true,
})
}Examples
import listProjects from 'kody:@kody/supabase/list-projects'
export default async function main() {
return await listProjects({ limit: 20 })
}import selectRows from 'kody:@kody/supabase/select-rows'
import insertRows from 'kody:@kody/supabase/insert-rows'
export default async function main() {
const rows = await selectRows({
projectRef: 'yourprojectref00000',
table: 'items',
select: 'id,name',
limit: 10,
})
const preview = await insertRows({
projectRef: 'yourprojectref00000',
table: 'items',
rows: [{ name: 'Follow up' }],
dryRun: true,
})
return { rows, preview }
}Unwrapped Management API:
import managementRequest from 'kody:@kody/supabase/management-request'
export default async function main() {
return await managementRequest({ path: '/v1/projects' })
}Notes
- Management API base:
https://api.supabase.com - Project API base:
https://{projectRef}.supabase.co - PostgREST filters use operator strings such as
{ id: 'eq.1' } ./list-usersomits email and phone unless you passincludeIdentifiers: true- This package is not affiliated with or endorsed by Supabase, Inc.
Branding
The community icon is Supabase's official logo icon from
Supabase brand assets
(brand-assets/supabase-logo-icon.svg). Paths are unmodified. Supabase® is a
trademark of Supabase, Inc.