@pipilot/client
v0.8.0
Published
Browser SDK for the PiPilot managed backend. Uses a public anon key; access is gated by per-table policies.
Maintainers
Readme
@pipilot/client
Browser SDK for the PiPilot managed backend. Talk to your database directly from the frontend with a public anon key — access is controlled by per-table policies you set as the project owner, so the key is safe to ship in the browser.
For full server-side access (bypasses policies), use
@pipilot/serverwith the service key instead. Never put the service key in a browser.
Install
npm install @pipilot/clientUsage
import { createClient } from '@pipilot/client';
const db = createClient('pk_anon_...'); // public — safe in the browser
// Works if the `posts` table's read policy allows anon:
const posts = await db.from('posts').select({ limit: 20 });
// Works if the `messages` table's write policy allows anon:
await db.from('messages').insert({ text: 'hello' });Policies
By default, everything is denied for the anon key. In your PiPilot project, open the backend's
Policies and allow read and/or write per table:
public— anyone with the anon key can do itnone— denied (default)authed/owner— require an authenticated end-user (coming soon; use@pipilot/serverfor now)
API
createClient(anonKey, { url?, fetch? })db.from(table).select({ limit?, filter? })db.from(table).insert(record | record[])db.from(table).update(id, record)db.from(table).delete(id)db.storage.list()/.upload(path, content, { contentType })/.download(path)/.getUrl(path, expiresIn?)/.remove(path)(each gated by a__storagepolicy)db.functions.invoke(name, body?)(only functions the owner marked public)
