Presets
A preset is an archetype plus the features, auth, backend, framework, integrations and PermDock Cloud services an app needs, encoded as a short versioned code; permdock/preset generates the application's own files from it, the same in permdock init, the @permdock registry and the /create page.
A preset describes a starting point: a SaaS archetype and the features and stack it runs on. /create builds one in the browser, permdock init writes it into a project, and the code that names it can be shared, opened and changed again.
| Part | Preset key | permdock init flag | Choices |
|---|---|---|---|
| Archetype | archetype | --archetype | b2b, agent, marketplace, api, internal, consumer |
| Features | features | --feature | tenancy, custom-roles, approvals, operations, decision-log, limits, plans, ownership, api-keys, rls |
| Auth | auth | --auth | custom, supabase, better-auth, clerk, jwt |
| Backend | backend | --backend | memory, supabase, drizzle, prisma |
| Framework | framework | --framework | next, hono, express, none |
| Integrations | integrations | --integration | Agent runtimes ai-sdk, mcp; UI recipes shadcn, react-native |
| Services | services | --service | cloud-decision-log, cloud-approvals, cloud-snapshots, cloud-hosted-grants |
The /create steps, the preset keys and the permdock init flags read one catalogue, so they offer the same ids. PRESET_DEFAULTS holds the defaults both start from: b2b, custom auth, the memory backend and next, with no integrations or services. PRESET_FLAGS maps each key to its flag, and presetFlags(preset) returns the flags that select a preset.
An archetype turns on the features it needs (b2b adds tenancy, custom-roles and decision-log); an agent runtime adds operations; custom-roles adds tenancy. Features are only ever added.
Codes
A code is p1 and base64url bytes: the archetype, auth, backend and framework, then a bitset per multi-select list. Each list only grows at the end, so a code keeps its meaning as choices are added; a new layout gets a new prefix, and a version that cannot read it says so.
Generating
permdock/preset is pure: no file system, no network, the same in Node and the browser.
import { encodePreset, generatePreset, resolvePreset } from "permdock/preset";
const preset = resolvePreset({ archetype: "b2b", framework: "hono" });
const { code, files, dependencies, recipes, docs } = generatePreset(preset);| File | What |
|---|---|
src/permissions.ts | The archetype's resources with crud() or readable() and Zod schemas |
src/policy.ts | Roles and grants as data: on, min and assigns with tenancy; where on the owner field with ownership; approval: "human" on destructive actions with approvals; limit with limits; a plan("pro") grant with plans |
src/permdock.ts | definePermDock with the features and services the preset picked and profile from NODE_ENV (apps and profiles) |
src/data.ts | Row loaders: demo rows in memory; Drizzle or Prisma queries with toWhere() lists on those backends, next to src/schema.ts and src/db.ts or prisma/schema.prisma |
src/session.ts | The caller: currentUser() returning null until wired with custom auth, so every check fails closed; currentSubject() through the provider's subjectFrom* otherwise, plus src/auth.ts for Better Auth |
| Framework file | src/permdock/server.ts (Next.js) or src/server.ts (Hono, Express, core) |
src/operations.ts, src/agent.ts, src/mcp.ts | With agent runtimes |
src/keys.ts | With api-keys: a decideCredential call |
permdock.config.ts | Always: permissions, policy, operations with agent runtimes, and rls with that feature |
permdock init lists what each choice writes.
generatePreset(preset, { clientInfo }) passes clientInfo to supabase-js's global.clientInfo in the Supabase clients session.ts and permdock.ts create, so their requests carry the parameters in X-Client-Info, such as via=permdock/<version> (client info specification). supabase-js added the option in 2.120 and its earlier types reject it, so leave it unset for older releases; unset, the clients pass none. proxy.ts refreshes the application's own session and never carries it.
Every generated file is the application's own code. The rules (role ceilings, holder counts, approval binding, limits, verification) are in the permdock package that these files call, so updating the package updates them.
Why
A preset generates declarations and wiring, never rules. A starter that copied authorization logic into the application could not receive a security fix; one that generates definePolicy data and definePermDock wiring can, because npm update replaces everything the generated code calls. The code format is versioned and append-only for the same reason as the wire formats: a link shared today opens the same preset after the catalogue grows.
Last updated on
Apps and profiles
definePermDock binds the data sources, caches, opt-in features and services an app wires once (memberships, custom roles, relations, hosted policies, approval policies, limits, sink, approval store, version and subject caches) to a policy, so createPermDock and every adapter read them from one place; profile dev fills in in-process defaults and profile prod refuses to start when a grant needs a service the app lacks.
Conditions
One portable condition AST evaluates in memory, filters arrays, compiles to Drizzle, Prisma and Kysely where clauses, and generates Postgres RLS.