@pipilot/client
v0.13.1
Published
Browser SDK for PiPilot Cloud, the PiPilot managed backend. Uses a public anon key; access is gated by per-table policies.
Maintainers
Readme
@pipilot/client
Browser SDK for PiPilot Cloud, 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)
Forgot password (0.13.0+)
A six-digit code sent by email. No reset link, nothing to configure. Postgres backends (ppn_ keys).
await pp.auth.requestPasswordReset(email) // emails the code, valid 15 minutes
await pp.auth.resetPassword({ email, code, password }) // sets the password and signs the user in
await pp.auth.changePassword({ currentPassword, newPassword }) // for a signed-in userrequestPasswordReset answers { ok: true } whether or not the address has an account, so an app cannot be used to find out who is registered. A wrong or expired code rejects; after five wrong codes a new one is needed.
Free AI in the browser (0.12.0+)
No API key, no account, no function to deploy. Works on every backend.
const tip = await pp.ai.text('Give one short tip about invoices')
const { text } = await pp.ai.chat({ system: 'You are a support assistant.', messages, onToken: (piece, soFar) => render(soFar) })
const data = await pp.ai.json({ prompt: emailBody, schema: { client: 'string', amount: 0 } })
const { label } = await pp.ai.classify({ text: review, labels: ['praise', 'complaint', 'question'] })
img.src = pp.ai.imageUrl('a watercolour fox', { aspect: '16:9' }) // the link is the picture
const blob = await pp.ai.image('a watercolour fox') // to keep: pp.storage.upload(path, blob)It runs on free, shared, third-party services (text: Unturf first, Pollinations as the fallback; pictures: a0) with no uptime promise. One request at a time per visitor (the rest are queued), 2 to 10 seconds per answer, a small general model. Always show a loading state and catch the error. Never send secrets or private data: the prompt leaves the visitor's browser for a public service. If you have your own provider key, call that provider from a function instead.
