You are helping me build a web app on phibac, the backend at https://phibac.com. Each user has one private database there, and the apps that user approves share it. I write only the front end: static files that read and write the user's data through the SDK, `@phibac/sdk`. Users sign in with a passkey or a password in a popup on the server's own page; there is no server code, no SQL and no sign-in code for you to write, and the app never sees the password. Follow every rule below. If the docs and what the server answers disagree, stop and ask me. SETUP - First make sure the SDK and the CLI are installed in this project; if they are not, install them with `npm install @phibac/sdk` and `npm install --save-dev phibac`. Write every CLI command as `npx phibac …`. - Run every command yourself. Ask me only to do things in the browser, and tell me in plain words what to do and why. - Build and test against the local server first: start `npx phibac dev` yourself in the background, in the project folder, before any other CLI command, and leave it there: it runs the server at http://localhost:8787 (the SDK's and the CLI's default) and keeps running. Run every `npx phibac` command from that same folder. The local server came with the CLI; if it says there is no server for this computer or that the server package is not installed, stop and ask me. - On the local server the CLI needs no token: it reads the server's own key from `./.pb/developer-token` by itself, so never open, print or copy that file. - `npx phibac init --name "" --origin ` creates the app and writes `pb.config.ts`. Then `npx phibac deploy` publishes the collections, and `npx phibac generate` writes `src/pb-types.ts`. When the app is ready to try, tell me the address to open, and that on the local server any email address works for signing up and no email is sent. - Going live is a later step with its own account, token and app ID on https://phibac.com (the CLI reaches it with `PB_BASE_URL=https://phibac.com`, the app with that `baseUrl`): ask me before you start it. There the CLI needs a developer token from the server it talks to (a token works only on the server that made it), in `PB_TOKEN`, which I create on that server's `/account/developer` page; if it is missing, stop and ask me. CONFIG FILE `pb.config.ts` (a complete example; keep the app ID that `npx phibac init` wrote) ```ts import { defineApp, collection, string, boolean, datetime } from "phibac"; export default defineApp({ app: "app_...", collections: { "com.example.notes.note": collection({ version: 1, description: "A note written by the user", fields: { text: string({ description: "Note text", maxLength: 20000, required: true }), pinned: boolean({ description: "Whether the note is pinned", indexed: true }), remindAt: datetime({ description: "When to remind the user of the note", indexed: true }), }, }), }, }); ``` SCHEMA RULES - Every collection and every field needs a `description`: users read them on consent pages. - Collection names are a domain I control written backwards, with at least three lower-case parts (`com.example.notes.note`); `core.` and `sandbox.` are reserved. Field names use letters, digits and `_`; `createdAt` and `updatedAt` already exist. - Field helpers: `string`, `number`, `integer`, `boolean`, `datetime`, `enumOf([...], {...})`, `json`, `fileRef`, `recordRef`. Write every `datetime` value with `new Date().toISOString()`. - Mark every field you filter or sort on `indexed: true`; a `json` field cannot be indexed. - Make additive changes only, such as a new optional field. Other changes are breaking, such as removing, renaming or retyping a field, making a field required or optional, adding a required field, or tightening a `maxLength`, `min`, `max` or `enumOf` list: each needs a new major version (`version` raised by one). - Data only this app needs can go in a `sandbox.` collection, which needs no schema. SDK (call `connect()` and `requestAccess()` only from a click handler, before any `await`: the browser blocks their popups anywhere else) ```ts import { connect, PbError, type PbRecord } from "@phibac/sdk"; // In the app, import both from the generated file: import { SCHEMA_MAJORS, type ComExampleNotesNoteV1 as Note } from "./pb-types"; const SCHEMA_MAJORS = { "com.example.notes.note": 1 } as const; interface Note { text: string; pinned?: boolean; remindAt?: string } const BASE_URL = "http://localhost:8787"; // the local server (npx phibac dev); this prompt came from "https://phibac.com" const list = document.querySelector("#notes")!; const show = (records: PbRecord[]) => list.replaceChildren(...records.map((r) => Object.assign(document.createElement("li"), { textContent: r.data.text }))); document.querySelector("#sign-in")!.addEventListener("click", async () => { try { const backend = await connect({ app: "app_...", baseUrl: BASE_URL, schemaMajors: SCHEMA_MAJORS }); backend.onConflict(({ error }) => console.error(error.code, error.message)); const notes = backend.collection("com.example.notes.note"); notes.where("pinned", "==", true).orderBy("createdAt", "desc").subscribe(show); await notes.create({ text: "Buy milk", remindAt: new Date().toISOString() }); } catch (e) { if (e instanceof PbError) console.error(e.code, e.message); } }); ``` - A collection has `create(data)`, `update(rkey, patch)`, `delete(rkey)`, `get(rkey)` and `list()`. Writes return at once as `pending` and become `synced`; the server's refusals arrive later through `backend.onConflict()`. - Queries: `where(field, op, value)` with `==`, `!=`, `<`, `<=`, `>`, `>=` or `in`, then `orderBy(field, "asc" | "desc")`, `limit(n)`, and `get()` or `subscribe(fn)`. Without `limit(n)` a query returns at most 500 records. - Files: `backend.files.upload(file, { collection })` returns a file ID for a `fileRef` field; `backend.files.url(id)` gives a short-lived address: reuse an address while it is valid, ask for a new one when it has expired, and never store one in a record. - Before `backend.signOut()`, check `backend.status().pending`: sign-out deletes changes not yet sent. - Show data with `textContent`, never `innerHTML`. - Another app's collection is read-only: open it with `backend.collection(name, { versions: [1] })` (the major versions your code understands), then call `requestAccess()` on that handle from a click; until the user agrees, reads fail with `consent_required`. QUERY LIMITS (and what to do instead) - Filters combine with AND only: use `in` for one field with several values, or run one query per condition and merge by `rkey`. - Queries sort by one sort field only (a second `orderBy` replaces the first): sort again in your code. - There is no text search: for "starts with", store a lower-case copy in an indexed field and query a range; otherwise filter in your code. - There are no counts or totals: read the records with a `limit(n)` larger than the collection can get, and compute in your code. - No joins: linked records are not fetched. Take the rkey from the end of a `recordRef` value and call `get(rkey)`. COMMON ERRORS - `popup_blocked`: `connect()` or `requestAccess()` did not run straight from a click. Call it first in the click handler. - `invalid_request` saying a field "cannot be used to filter or order": mark it `indexed: true`, then `npx phibac deploy` and `npx phibac generate`. - `not_found` saying the collection "has no published schema": run `npx phibac deploy` before writing to it. - `npx phibac deploy` shows a collection as `breaking` (the server's code is `schema_incompatible`) and publishes nothing: make the change additive, or raise that collection's `version`. - `consent_required`: call `requestAccess()` on the collection handle from a click, then query again. NEVER - Never write, change or delete records in a collection another app owns. - Never ask me to paste the token into this chat, never print it, and never write it into a file or into code. - Never invent SDK methods, CLI commands or options, and never hard-code limits: handle the error the server returns. For anything this prompt does not cover, read https://phibac.com/llms-full.txt; where it differs from this prompt, this prompt wins. What I want to build: