@quickback-dev/cli 0.66.21 → 0.66.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/dist/commands/check.js +1 -1
  2. package/dist/commands/check.js.map +1 -1
  3. package/dist/commands/create.js +82 -165
  4. package/dist/commands/create.js.map +1 -1
  5. package/dist/commands/mcp.d.ts.map +1 -1
  6. package/dist/commands/mcp.js +92 -1
  7. package/dist/commands/mcp.js.map +1 -1
  8. package/dist/index.js +1 -1
  9. package/dist/lib/api-client.d.ts +3 -0
  10. package/dist/lib/api-client.d.ts.map +1 -1
  11. package/dist/lib/api-client.js +1 -1
  12. package/dist/lib/api-client.js.map +1 -1
  13. package/dist/lib/file-writer.d.ts +2 -0
  14. package/dist/lib/file-writer.d.ts.map +1 -1
  15. package/dist/lib/file-writer.js.map +1 -1
  16. package/dist/lib/harness.d.ts +59 -0
  17. package/dist/lib/harness.d.ts.map +1 -0
  18. package/dist/lib/harness.js +178 -0
  19. package/dist/lib/harness.js.map +1 -0
  20. package/dist/lib/migrations/drizzle-prompts.d.ts +2 -0
  21. package/dist/lib/migrations/drizzle-prompts.d.ts.map +1 -1
  22. package/dist/lib/migrations/drizzle-prompts.js +11 -0
  23. package/dist/lib/migrations/drizzle-prompts.js.map +1 -1
  24. package/dist/lib/migrations/file-envelopes.d.ts.map +1 -1
  25. package/dist/lib/migrations/file-envelopes.js +21 -51
  26. package/dist/lib/migrations/file-envelopes.js.map +1 -1
  27. package/dist/lib/migrations/prompt-runner.d.ts.map +1 -1
  28. package/dist/lib/migrations/prompt-runner.js +6 -1
  29. package/dist/lib/migrations/prompt-runner.js.map +1 -1
  30. package/dist/skill/docs/api/actions.md +13 -6
  31. package/dist/skill/docs/api/batch-operations.md +6 -2
  32. package/dist/skill/docs/api/crud.md +72 -9
  33. package/dist/skill/docs/api/errors.md +78 -6
  34. package/dist/skill/docs/api/openapi.md +1 -1
  35. package/dist/skill/docs/api/query-params.md +6 -7
  36. package/dist/skill/docs/api/typescript.md +193 -0
  37. package/dist/skill/docs/configure/index.md +36 -2
  38. package/dist/skill/docs/configure/providers.md +32 -7
  39. package/dist/skill/docs/define/changesets.md +2 -0
  40. package/dist/skill/docs/define/guards.md +7 -2
  41. package/dist/skill/docs/define/masking.md +14 -0
  42. package/dist/skill/docs/define/read.md +3 -0
  43. package/dist/skill/docs/define/schema.md +13 -10
  44. package/dist/skill/docs/define/transitions.md +9 -4
  45. package/dist/skill/docs/index.md +1 -0
  46. package/dist/skill/docs/platform/auth/plugins/agent-auth.md +1 -1
  47. package/dist/skill/docs/platform/payments/index.md +1 -1
  48. package/dist/skill/docs/start/frontend.md +278 -0
  49. package/dist/skill/docs/start/index.md +1 -0
  50. package/dist/skill/docs/start/template-blog.md +36 -58
  51. package/dist/skill/docs/start/templates.md +3 -3
  52. package/dist/skill/docs/tooling/claude-skill.md +10 -1
  53. package/dist/skill/docs/tooling/cli.md +5 -1
  54. package/dist/skill/docs/tooling/cloud-compiler/endpoints.md +10 -0
  55. package/dist/skill/docs/tooling/cloud-compiler/troubleshooting.md +6 -0
  56. package/dist/skill/docs/tooling/output.md +38 -9
  57. package/dist/skill/docs/tooling/troubleshooting.md +67 -0
  58. package/dist/skill/docs/ui/admin/actions.md +6 -2
  59. package/dist/skill/docs/ui/admin/index.md +1 -1
  60. package/dist/skill/docs/ui/admin/inline-editing.md +6 -2
  61. package/dist/skill/docs/ui/admin/schema-format.md +74 -36
  62. package/dist/skill/docs/ui/admin/schema-registry.md +22 -9
  63. package/dist/skill/docs/ui/admin/security.md +2 -2
  64. package/dist/skill/docs/ui/components/action-dialog.md +62 -0
  65. package/dist/skill/docs/ui/components/auth.md +90 -0
  66. package/dist/skill/docs/ui/components/index.md +48 -0
  67. package/dist/skill/docs/ui/components/install.md +118 -0
  68. package/dist/skill/docs/ui/components/quickback-provider.md +123 -0
  69. package/dist/skill/docs/ui/components/resource-form.md +80 -0
  70. package/dist/skill/docs/ui/components/resource-table.md +46 -0
  71. package/dist/templates/registry.js +1 -1
  72. package/dist/templates/registry.js.map +1 -1
  73. package/package.json +1 -1
  74. package/src/skill/docs/api/actions.md +13 -6
  75. package/src/skill/docs/api/batch-operations.md +6 -2
  76. package/src/skill/docs/api/crud.md +72 -9
  77. package/src/skill/docs/api/errors.md +78 -6
  78. package/src/skill/docs/api/openapi.md +1 -1
  79. package/src/skill/docs/api/query-params.md +6 -7
  80. package/src/skill/docs/api/typescript.md +193 -0
  81. package/src/skill/docs/configure/index.md +36 -2
  82. package/src/skill/docs/configure/providers.md +32 -7
  83. package/src/skill/docs/define/changesets.md +2 -0
  84. package/src/skill/docs/define/guards.md +7 -2
  85. package/src/skill/docs/define/masking.md +14 -0
  86. package/src/skill/docs/define/read.md +3 -0
  87. package/src/skill/docs/define/schema.md +13 -10
  88. package/src/skill/docs/define/transitions.md +9 -4
  89. package/src/skill/docs/index.md +1 -0
  90. package/src/skill/docs/platform/auth/plugins/agent-auth.md +1 -1
  91. package/src/skill/docs/platform/payments/index.md +1 -1
  92. package/src/skill/docs/start/frontend.md +278 -0
  93. package/src/skill/docs/start/index.md +1 -0
  94. package/src/skill/docs/start/template-blog.md +36 -58
  95. package/src/skill/docs/start/templates.md +3 -3
  96. package/src/skill/docs/tooling/claude-skill.md +10 -1
  97. package/src/skill/docs/tooling/cli.md +5 -1
  98. package/src/skill/docs/tooling/cloud-compiler/endpoints.md +10 -0
  99. package/src/skill/docs/tooling/cloud-compiler/troubleshooting.md +6 -0
  100. package/src/skill/docs/tooling/output.md +38 -9
  101. package/src/skill/docs/tooling/troubleshooting.md +67 -0
  102. package/src/skill/docs/ui/admin/actions.md +6 -2
  103. package/src/skill/docs/ui/admin/index.md +1 -1
  104. package/src/skill/docs/ui/admin/inline-editing.md +6 -2
  105. package/src/skill/docs/ui/admin/schema-format.md +74 -36
  106. package/src/skill/docs/ui/admin/schema-registry.md +22 -9
  107. package/src/skill/docs/ui/admin/security.md +2 -2
  108. package/src/skill/docs/ui/components/action-dialog.md +62 -0
  109. package/src/skill/docs/ui/components/auth.md +90 -0
  110. package/src/skill/docs/ui/components/index.md +48 -0
  111. package/src/skill/docs/ui/components/install.md +118 -0
  112. package/src/skill/docs/ui/components/quickback-provider.md +123 -0
  113. package/src/skill/docs/ui/components/resource-form.md +80 -0
  114. package/src/skill/docs/ui/components/resource-table.md +46 -0
@@ -112,6 +112,23 @@ function that requires the real value cannot silently accept the default row.
112
112
  Name the role you fetched with to get the revealed type; a union role
113
113
  (`Row<"member" | "admin">`) yields `T | Qb.Masked<T>`.
114
114
 
115
+ A masked value narrower than a free string — a number, boolean, array, JSON
116
+ value or enum literal — cannot keep its type once masked: the `redact` mask
117
+ replaces it with the string `"[REDACTED]"`. `Qb.Masked<T>` admits that
118
+ marker, typed `Qb.Redacted`, so narrow before using the value:
119
+
120
+ ```typescript
121
+ // masking: { salary: { type: 'redact', show: { roles: ['admin'] } } } — q.int()
122
+ declare const row: Api.jobs.Row;
123
+ row.salary; // Qb.Masked<number> | null (includes Qb.Redacted)
124
+ if (typeof row.salary === "number") console.log(row.salary * 12);
125
+ ```
126
+
127
+ OpenAPI documents the same thing: the column's schema becomes
128
+ `anyOf: [<schema>, { type: "string", enum: ["[REDACTED]"] }]`. String-shaped
129
+ masks (`email`, `phone`, …) can't mask such columns at all — see
130
+ [Masking](/define/masking#non-string-columns).
131
+
115
132
  `show: { or: 'owner' }` reveals by record ownership, which no type parameter
116
133
  can see, so those columns stay `Masked` for every role outside `show.roles`.
117
134
 
@@ -208,6 +225,182 @@ const api = createClient<paths>({ baseUrl: "https://api.example.com" });
208
225
  const { data } = await api.GET("/api/v1/jobs/{id}", { params: { path: { id } } });
209
226
  ```
210
227
 
228
+ ## Fetch client
229
+
230
+ Set `client: true` and every compile also emits `quickback.client.ts`: a
231
+ zero-dependency `fetch` client with one method per generated route, typed
232
+ through `quickback.gen.ts`. It has no React and no runtime package, and it is
233
+ the only generated code that knows the wire format (list envelopes, filter
234
+ syntax, Problem Details), so UI code built on it never builds a URL or parses a
235
+ response.
236
+
237
+ ```typescript
238
+ export default defineConfig({
239
+ client: true, // quickback.client.ts
240
+ // client: "apps/web/src/lib/api.ts", // or one custom path
241
+ // client: ["apps/web/src/api.ts", "apps/admin/src/api.ts"],
242
+ });
243
+ ```
244
+
245
+ `client` requires `types` — the client imports `Api` and `Qb` from the first
246
+ `types` output, and the compile fails if `types` is `false`. It is off by
247
+ default.
248
+
249
+ ```typescript
250
+ import { createClient, QuickbackError } from "./quickback.client";
251
+
252
+ const api = createClient({
253
+ baseUrl: "https://api.example.com", // paths already include /api/v1
254
+ // credentials: "include" by default — the Better Auth session cookie
255
+ // headers: () => ({ authorization: `Bearer ${token}` }),
256
+ });
257
+
258
+ // GET /api/v1/applications?stage.in=screen,offer&sort=-createdAt&total=true
259
+ const page = await api.applications.list({
260
+ filter: { "stage.in": ["screen", "offer"] },
261
+ sort: "-createdAt",
262
+ total: true,
263
+ });
264
+ page.data; // Api.applications.Row[]
265
+ page.pagination.total; // present because total: true
266
+
267
+ const app = await api.applications.get(id); // bare record
268
+ await api.applications.update(id, { notes: "…" }); // bare record
269
+ await api.applications.delete(id); // void ({ success: true } on the wire)
270
+ await api.applications.views.pipeline({ limit: 25 });
271
+ await api.applications.actions.advance(id, { notes: "Strong interview" });
272
+
273
+ try {
274
+ await api.applications.create({ candidateId, jobId });
275
+ } catch (err) {
276
+ if (err instanceof QuickbackError) {
277
+ err.status; // HTTP status
278
+ err.problem; // Qb.Problem when the body was application/problem+json, else null
279
+ err.fields; // { [field]: message } from details.fields — guards and validation alike — else null
280
+ }
281
+ }
282
+ ```
283
+
284
+ ### Batch, upsert and pagination
285
+
286
+ Where the batch routes exist, `api.<x>.batch` sends the documented
287
+ [batch bodies](/api/batch-operations); `207` partial success resolves (read
288
+ `errors` and `meta.transactional`), a fail-fast stop throws. `upsert(id, body)`
289
+ is `PUT /:id` and exists only on tables that mount it (`guards: false` +
290
+ `generateId: false`).
291
+
292
+ ```typescript
293
+ const result = await api.applications.batch.create(records, { failFast: true });
294
+ result.success; // Api.applications.Row[]
295
+ result.errors; // [{ index, record, error: { code, details: { fields } } }]
296
+ await api.applications.batch.update([{ id, stage: "offer" }]);
297
+ await api.applications.batch.delete([id1, id2]);
298
+
299
+ // Every page, following pagination.nextCursor (?starting_after=). When the
300
+ // cursor is null — sorting by a column masked for you — it pages by offset.
301
+ import { paginate } from "./quickback.client";
302
+ for await (const page of paginate(api.applications.list, { limit: 100 })) {
303
+ page.data;
304
+ }
305
+ ```
306
+
307
+ ### Bearer lane (React Native, native clients)
308
+
309
+ By default the client authenticates with the Better Auth session cookie
310
+ (`credentials: "include"`). React Native and other non-browser clients send
311
+ no `Origin` header, so every cookie-authenticated write is refused with
312
+ `403 CSRF_ORIGIN_REJECTED` — the [CSRF guard](/platform/auth/security) only
313
+ admits cookie mutations from a trusted origin. Use the bearer lane instead:
314
+
315
+ ```typescript
316
+ import * as SecureStore from "expo-secure-store";
317
+
318
+ const api = createClient({
319
+ baseUrl: "https://api.example.com",
320
+ auth: "bearer", // no cookies; credentials default to "omit"
321
+ sessionStore: { // default: memory, lost on reload
322
+ get: () => SecureStore.getItemAsync("qb.session"),
323
+ set: (token) => (token
324
+ ? SecureStore.setItemAsync("qb.session", token)
325
+ : SecureStore.deleteItemAsync("qb.session")),
326
+ },
327
+ });
328
+
329
+ // Sign in through the client: the session token arrives in set-auth-token
330
+ // on /auth/v1/* and is saved to sessionStore.
331
+ await api.request("POST", "/auth/v1/sign-in/email", { body: { email, password } });
332
+ await api.applications.list();
333
+ ```
334
+
335
+ Every request carries `Authorization: Bearer <token>`:
336
+
337
+ 1. the JWT the API returned last in `set-auth-token` (kept in memory — with
338
+ [`auth.jwt`](/platform/auth/jwt-optimization) every session-authenticated
339
+ call returns one), else
340
+ 2. the session token from `sessionStore`.
341
+
342
+ `set-auth-token` means two things by path: under `/auth/v1` it is Better
343
+ Auth's **session** token (saved to `sessionStore`); anywhere else it is a
344
+ short-lived **JWT** (cached in memory). When the API answers `401` to a JWT —
345
+ expired, key rotated, [revoked](/platform/auth/jwt-optimization#revocation--revocationcheck-kv) —
346
+ the client drops it and retries the request **once** on the session token;
347
+ the session path re-validates and returns a fresh JWT. A `401` on the session
348
+ token itself is final. An `authorization` header you pass in `headers` wins
349
+ over the lane.
350
+
351
+ ### Realtime
352
+
353
+ With realtime enabled, `api.realtime.subscribe(handler, { ticket? })` opens
354
+ the WebSocket for you: it mints a [ws-ticket](/platform/realtime/using-realtime)
355
+ through the same auth lane (a fresh one for every reconnect — tickets live 60
356
+ seconds), shares one socket between subscribers with the same `ticket` body,
357
+ reconnects two seconds after a drop, and closes when the last subscriber
358
+ unsubscribes. Frames are CloudEvents envelopes — switch on `qbframe`.
359
+
360
+ ```typescript
361
+ const unsubscribe = api.realtime.subscribe((frame) => {
362
+ if (frame.qbframe === "postgres_changes") refetch(frame.data.table);
363
+ });
364
+ ```
365
+
366
+ The client mirrors the type tree: `api.<x>` exists wherever `Api.<x>` is a
367
+ table with routes, and a method exists **only** if its route does — a table
368
+ without `delete` access has no `delete`. Record actions take the record id
369
+ first; standalone actions with path parameters take a `params` object; `GET`
370
+ actions send their input as query parameters. Actions declared
371
+ `responseType: 'stream'` or `'file'` resolve to the raw `Response`.
372
+ List-shaped methods accept `limit`, `offset`, `sort`, `search`, `total`,
373
+ `fields`, `include`, `startingAfter` / `endingBefore` and `filter` — see
374
+ [Query Parameters](/api/query-params); array filter values are comma-joined for
375
+ `.in`, and an unknown filter field is a `400`, not an ignored key.
376
+ Changeset (`application/vnd.quickback.changeset+json`) writes are not in the
377
+ client; send them with `api.request`.
378
+
379
+ Runtime extras for generic UI and native clients:
380
+
381
+ - `resources` — keyed by **schema-registry table name** (the key of
382
+ `SchemaRegistry.tables`, the table's JS name), so UI holding a registry
383
+ table can reach its routes without building a URL:
384
+ `{ client, table, ops, views, actions, recordActions, routes }`. `client` is
385
+ the dotted path on the client (`"applications"`, `"crm.contacts"`);
386
+ `recordActions` is the subset of `actions` that take the record id;
387
+ `routes` maps `list` / `get` / `create` / `update` / `delete` / `upsert`,
388
+ `batchCreate` / `batchUpdate` / `batchDelete` / `batchUpsert`,
389
+ `views.<name>` and `actions.<name>` to `{ method, path }` (path templates
390
+ with `{id}`) for clients that build requests themselves (Swift, Kotlin).
391
+ - `api.schema()` — `GET /api/v1/schema`, typed as `SchemaRegistry` (see
392
+ [Schema Registry](/ui/admin/schema-registry)). The registry is **fetched,
393
+ never embedded**: it describes columns, roles and masking, so it stays
394
+ behind that route's auth gate instead of shipping in every frontend bundle.
395
+ The gate defaults to platform sysadmins; open it to your frontend's users
396
+ with [`schemaRegistry.access`](/configure#schema-registry-access).
397
+ - `api.request(method, path, { query, body })` — any other route (Better Auth,
398
+ changesets, custom paths) through the same auth lane and error handling.
399
+
400
+ The emitted file is plain TypeScript that passes `strict`,
401
+ `erasableSyntaxOnly`, `verbatimModuleSyntax` and `noUnused*` — it drops into a
402
+ Vite / shadcn template as-is.
403
+
211
404
  ## Configuration
212
405
 
213
406
  The artifact is on by default:
@@ -108,7 +108,8 @@ Every optional top-level key the config accepts is listed below. You never have
108
108
  | `security` | `object \| false` | HTTP response security headers (CSP, HSTS, COOP/COEP, Referrer/Permissions-Policy) — see [Security Headers](/configure/security) |
109
109
  | `openapi` | `object` | OpenAPI spec generation (`generate`, `publish`, `docs: 'scalar' \| 'swagger'`, `types`) — see [OpenAPI](/api/openapi) |
110
110
  | `types` | `boolean \| object` | Quickback's first-party TypeScript contract (`output`, `brandIds`) — see [TypeScript](/api/typescript) |
111
- | `schemaRegistry` | `object` | Schema registry generation for the CMS (`{ generate: false }` to disable) — see [Schema Registry](/ui/admin/schema-registry) |
111
+ | `client` | `boolean \| string \| string[]` | Emit `quickback.client.ts`, a zero-dependency `fetch` client typed by `types` (default off; requires `types`) — see [Fetch client](/api/typescript#fetch-client) |
112
+ | `schemaRegistry` | `object` | Schema registry for the CMS and generic UI: `{ generate: false }` disables it; `access` sets who may read `GET /api/v1/schema` — see [Schema registry access](#schema-registry-access) and [Schema Registry](/ui/admin/schema-registry) |
112
113
  | `etag` | `object` | ETag caching for GET responses (`{ enabled: false }` to disable) — see [Caching & ETags](/api/caching) |
113
114
  | `email` | `object` | Email delivery config (`provider`, `from`, `fromName`, `region`) — see [Email Configuration](#email-configuration) |
114
115
  | `push` | `object` | Web Push (VAPID keys, TTL/urgency defaults, queue fan-out) — see [Push](/platform/push) |
@@ -557,6 +558,39 @@ If you only want Better Auth to **advertise** itself on a different URL (e.g. so
557
558
 
558
559
  `auth.domain` (Shape 1, above) is the heavier option: it binds an actual hostname to the Worker, configures CORS/cookies/CSP for it, and adds the path-shortcut rewriter. Use it when you want the dedicated hostname as a real ingress, not just a label.
559
560
 
561
+ ## Schema registry access
562
+
563
+ `GET /api/v1/schema` serves the [schema registry](/ui/admin/schema-registry) —
564
+ the columns, validation rules, views, actions, masking and access metadata
565
+ that generic UI renders from (the CMS, and components built on the
566
+ [fetch client](/api/typescript#fetch-client)'s `api.schema()`). It describes
567
+ your data model, so it is gated, by default to platform sysadmins.
568
+
569
+ A frontend for your own users opens it with `schemaRegistry.access`, with or
570
+ without the CMS:
571
+
572
+ ```typescript
573
+ export default defineConfig({
574
+ client: true,
575
+ schemaRegistry: { access: "member" },
576
+ });
577
+ ```
578
+
579
+ | `schemaRegistry.access` | Admits | Denied with |
580
+ |---|---|---|
581
+ | omitted | whatever `cms.access` admits (`"sysadmin"` by default) | `403 CMS_ACCESS_DENIED` |
582
+ | `"sysadmin"` | `user.role === "sysadmin"` | `403 CMS_ACCESS_DENIED` |
583
+ | `"member"` | sysadmins, and any caller holding an organization membership | `403 CMS_ACCESS_DENIED` |
584
+ | `"authenticated"` | any signed-in caller — for owner-scoped apps with no organizations | `401 AUTH_MISSING` |
585
+
586
+ In every mode an anonymous caller gets `401 AUTH_MISSING` (sign in) first;
587
+ `403 CMS_ACCESS_DENIED` is only ever sent to a signed-in caller who lacks the
588
+ role.
589
+
590
+ The route is also the CMS's gate, so with `cms` enabled `schemaRegistry.access`
591
+ must equal `cms.access` — a mismatch is a compile error rather than a silent
592
+ widening of the CMS. The CMS has no `"authenticated"` mode.
593
+
560
594
  ## CMS Configuration
561
595
 
562
596
  Embed the [Admin UI](/ui/admin) in your compiled Worker. It reads your schema registry and renders a complete admin interface — zero UI code per table.
@@ -578,7 +612,7 @@ cms: { domain: "cms.example.com", sysadmin: true },
578
612
  | Option | Type | Default | Description |
579
613
  |--------|------|---------|-------------|
580
614
  | `domain` | `string` | — | Custom domain for CMS. Adds a `custom_domain` route to `wrangler.toml`. |
581
- | `access` | `"user" \| "admin"` | `"admin"` | Controls who can access the CMS. When `"admin"`, platform control-plane users (`user.role === "appmanager"`) can enter; when `sysadmin` mode is also on, `user.role === "sysadmin"` is admitted too. The gate is enforced at the Worker level (SPA shell, `/api/v1/schema`, and `custom_view` CRUD all return 403 to callers outside those roles) and in the SPA. Also hides the CMS link in Account UI. See [CMS Connecting](/ui/admin/connecting) for the full enforcement model. |
615
+ | `access` | `"sysadmin" \| "member"` | `"sysadmin"` | Who can use the CMS. `"sysadmin"` admits `user.role === "sysadmin"` only; `"member"` also admits any caller holding an organization membership, scoped to their active organization. `appmanager` is admitted by neither. The real gate is `GET /api/v1/schema` (and `custom_view` CRUD) — both answer 403 with `CMS_ACCESS_DENIED` naming the requirement (401 `AUTH_MISSING` when not signed in); the SPA shell is served to any signed-in caller so it can explain. The pre-v0.62 values `"admin"` and `"user"` are compile errors. See [CMS Connecting](/ui/admin/connecting) for the full enforcement model. |
582
616
  | `sysadmin` | `boolean` | `false` | Cross-tenant DB-admin tier. When `true`, opts into the `SYSADMIN` pseudo-role (`user.role === "sysadmin"`), the firewall escape hatch (sysadmins bypass tenant scopes, soft-delete still enforced), the cross-tenant `/auth/v1/admin/list-organizations` endpoint (sibling of Better Auth's `/auth/v1/admin/list-users`, gated to sysadmin only), and the SPA's "All organizations" sentinel. The CMS HTML gate admits `userRole === "sysadmin"` alongside `"appmanager"`. Off by default. See [`SYSADMIN` pseudo-role](/define/access#sysadmin--cross-tenant-db-admin-tier). |
583
617
 
584
618
  ### Sysadmin tier (`cms.sysadmin: true`)
@@ -85,8 +85,9 @@ import { defineDatabase } from "@quickback/compiler";
85
85
 
86
86
  providers: {
87
87
  database: defineDatabase("cloudflare-d1", {
88
- generateId: "prefixed", // "uuid" | "cuid" | "nanoid" | "prefixed" | "serial" | false
88
+ generateId: "uuid", // default; "cuid" | "nanoid" | "short" | "prefixed" | "serial" | false
89
89
  allowClientIds: false, // true: POST bodies MAY carry a strategy-shaped id
90
+ validateIdParams: true, // false: /:id is a plain string again (see the hazard below)
90
91
  namingConvention: "snake_case", // "camelCase" | "snake_case"
91
92
  usePlurals: false, // Auth table names: "users" vs "user"
92
93
  }),
@@ -101,8 +102,9 @@ single Postgres database with no bindings or split mode (see
101
102
 
102
103
  | Option | Type | Default (D1) | Description |
103
104
  |--------|------|---------|-------------|
104
- | `generateId` | `string \| false` | `"prefixed"` | ID generation strategy |
105
+ | `generateId` | `string \| false` | `"uuid"` (every provider) | ID generation strategy — see [ID Generation Options](#id-generation-options) |
105
106
  | `allowClientIds` | `boolean` | `false` | Accept an optional client-supplied `id` on create, shaped like the `generateId` strategy — see [Client-supplied IDs](/api/crud#client-supplied-ids-optimistic-updates). Ignored under `generateId: false` (ids are already client-supplied and required) and `"serial"` / numeric PKs |
107
+ | `validateIdParams` | `boolean` | `true` | Check a record route's `:id` against the table's id format and answer `400 INVALID_ID` before any database work — see [Malformed ids](/api/crud#malformed-ids-400-invalid_id). **Set `false` if any table holds rows whose ids don't match the current `generateId` shape** (the strategy changed after rows were written, imported data, ids hand-minted by actions): with the check on, those rows answer 400 instead of the row. Tables whose format the compiler can't know (`generateId: false`, an authored id default) are never checked |
106
108
  | `namingConvention` | `string` | `"snake_case"` | Column naming convention |
107
109
  | `usePlurals` | `boolean` | `false` | Pluralize auth table names (e.g. `user` vs `users`) |
108
110
  | `splitDatabases` | `boolean` | `true` | Separate auth and features databases (D1 only) |
@@ -269,7 +271,7 @@ See [Realtime](/platform/realtime) for the client-side connection flow and helpe
269
271
 
270
272
  | Value | Description | Example |
271
273
  |-------|-------------|---------|
272
- | `"uuid"` | Server generates UUID | `550e8400-e29b-41d4-a716-446655440000` |
274
+ | `"uuid"` (default) | Server generates UUID | `550e8400-e29b-41d4-a716-446655440000` |
273
275
  | `"cuid"` | Server generates CUID | `clh2v8k9g0000l508h5gx8j1a` |
274
276
  | `"nanoid"` | Server generates nanoid (21-char, URL-safe) | `V1StGXR8_Z5jdHi6B-myT` |
275
277
  | `"short"` | 6-char alphanumeric (nanoid `customAlphabet`) | `a3F9xK` |
@@ -277,10 +279,33 @@ See [Realtime](/platform/realtime) for the client-side connection flow and helpe
277
279
  | `"serial"` | Database auto-increments | `1`, `2`, `3` |
278
280
  | `false` | Client provides ID (enables PUT/upsert) | Any string |
279
281
 
280
- > `"short"` produces IDs with ~56.8 billion possible values (62^6). That's fine for small/scoped tables like rooms, invites, or share codes — but at roughly 238,000 rows you hit a 50% chance of collision (birthday bound). Don't use it for high-volume records. `"nanoid"` and `"short"` both require the `nanoid` package in your project.
281
-
282
-
283
- > `generateId: "cuid"` is not byte-for-byte uniform across every compiler path. Import-capable runtime paths emit real `createId()` usage, but compiler-managed schema auto-injection may preserve the `createId()` call site with a file-local `crypto.randomUUID()` polyfill so schema-generation sandboxes stay dependency-free. If you require true cuid2 strings everywhere, explicitly import `createId` from `@paralleldrive/cuid2` in the authored schema file.
282
+ Leave `generateId` unset and every provider mints UUIDs, in the CRUD route and
283
+ in the schema default an action's `db.insert()` falls back on alike.
284
+
285
+ > **Upgrading: the default changed from prefixed to uuid**
286
+ >
287
+ > Before this release an unset `generateId` minted **prefixed** ids on D1
288
+ > (`job_550e8400e29b41d4a716446655440000`), and on every provider the CRUD route
289
+ > fell back to prefixed. Unset now means `"uuid"` everywhere. Existing rows keep
290
+ > their ids, so a table that was on the old default holds both shapes:
291
+ >
292
+ > - **Old rows stay reachable.** While `generateId` is unset, record routes'
293
+ > [`:id` check](/api/crud#malformed-ids-400-invalid_id) accepts a UUID **or**
294
+ > any prefixed id the old default minted, and the OpenAPI spec declares no
295
+ > `format` on ids, so a strict client doesn't reject old ids.
296
+ > - **New rows are UUIDs**, including client-supplied ids under `allowClientIds`.
297
+ > - **To keep minting prefixed ids**, set `generateId: "prefixed"` explicitly.
298
+ > - **Once every row is a UUID** (or on a new project), set `generateId: "uuid"`
299
+ > explicitly. That is a promise about every row, so `:id` then accepts only a
300
+ > UUID and ids get `format: "uuid"` in OpenAPI.
301
+ >
302
+ > Code that parses the `<prefix>_` part of an id breaks on new rows either way.
303
+
304
+
305
+ > `"short"` produces IDs with ~56.8 billion possible values (62^6). That's fine for small/scoped tables like rooms, invites, or share codes — but at roughly 238,000 rows you hit a 50% chance of collision (birthday bound). Don't use it for high-volume records.
306
+
307
+
308
+ > `"cuid"`, `"nanoid"`, and `"short"` mint with an npm package: `@paralleldrive/cuid2` for `"cuid"`, and `nanoid` for the other two. The compiler adds the package to the generated `package.json` and imports it wherever it mints an id, so don't add it yourself, and don't import it in a table file (table files can't import it). Every server-side mint produces the shape in the table: the CRUD route, and the schema default that a `db.insert()` in an action falls back on. Older compilers backed the schema-side `createId()` with a `crypto.randomUUID()` polyfill, so a `cuid` table can hold UUID rows; record routes' [`:id` check](/api/crud#malformed-ids-400-invalid_id) accepts both.
284
309
 
285
310
 
286
311
  ## Auth Providers
@@ -197,6 +197,8 @@ Every **child op** then pays:
197
197
  8. **Server-minted child ids** — a client-supplied child primary key on an
198
198
  insert is rejected (like the plain POST's strict body schema), unless the
199
199
  project is configured for client-provided ids (`generateId: false`).
200
+ There the id is exempt from the child's `guards.createable`, as on the
201
+ plain POST.
200
202
 
201
203
  Child `delete` ops stamp the **fixed `deletedAt`** audit column — exactly what
202
204
  the plain DELETE route stamps (the audit wrapper then auto-stamps
@@ -65,7 +65,7 @@ guards: {
65
65
 
66
66
  | List | What it controls |
67
67
  |------|------------------|
68
- | `createable` | Fields allowed in create (POST) request body |
68
+ | `createable` | Fields allowed in create (POST) request body. A client-supplied `id` (`generateId: false` or `allowClientIds`) is exempt and need not be listed |
69
69
  | `updatable` | Fields allowed in update (PATCH) request body |
70
70
  | `protected` | Fields blocked from direct writes; writable only by the actions named for them |
71
71
  | `immutable` | Fields allowed on create, then never written again — by CRUD, batch, changeset, **or actions** |
@@ -284,7 +284,12 @@ When upsert creates a new record, ownership fields are auto-set from context:
284
284
  | `'short'` | No | Server generates 6-char alphanumeric ID (e.g. `a3F9xK`) |
285
285
  | `'prefixed'` | No | Server generates prefixed ID (e.g. `room_abc123`) |
286
286
  | `'serial'` | No | Database auto-increments |
287
- | `false` | Yes (if guards: false) | Client provides ID |
287
+ | `false` | Yes (if guards: false) | Client provides ID (required on create) |
288
+
289
+ Under `generateId: false` a guarded table still creates normally: the
290
+ client-supplied `id` is compiler-managed, not a guarded field, so it is exempt
291
+ from `createable` — list only the fields the client may set. Guards keep
292
+ rejecting every other field outside `createable`.
288
293
 
289
294
  Need client-generated ids without giving up server minting or guards? Set
290
295
  `allowClientIds: true` instead — creates accept an **optional**
@@ -168,6 +168,20 @@ export default feature('candidates', {
168
168
  | `'redact'` | `anything` | `[REDACTED]` |
169
169
  | `'custom'` | (your logic) | (your output) |
170
170
 
171
+ ### Non-string columns
172
+
173
+ The string-shaped masks (`email`, `phone`, `ssn`, `creditCard`, `name`) format
174
+ text, so they are a compile error on a column whose value isn't a string —
175
+ `q.int()`, `q.bigint()`, `q.smallint()`, `q.bool()`, `q.json()`,
176
+ `q.timestamp()` (a `Date` on Postgres), or any `.array()`. Use `'redact'` or
177
+ `'custom'` there.
178
+
179
+ A redacted non-string value arrives as the string `"[REDACTED]"` — a masked
180
+ `q.int()` is not a number for that caller. The generated types say so:
181
+ [`Qb.Masked<number>`](/api/typescript#masked-columns) admits `Qb.Redacted`,
182
+ and OpenAPI documents the column as
183
+ `anyOf: [{ type: "integer" }, { type: "string", enum: ["[REDACTED]"] }]`.
184
+
171
185
  ## Configuration
172
186
 
173
187
  ```typescript
@@ -115,6 +115,9 @@ Single-record `GET /:id` evaluates checks in this order to close the
115
115
  404-vs-403 ID-probe channel:
116
116
 
117
117
  1. **Auth gate** — 401 if unauthenticated
118
+ - **Id shape** — 400 `INVALID_ID` if `:id` can't be one of this table's ids
119
+ (see [Malformed ids](/api/crud#malformed-ids-400-invalid_id)); depends on
120
+ the URL string alone, so it reveals nothing about which rows exist
118
121
  2. **Pre-record access** — role-only check (skips `access.record` predicates)
119
122
  3. **Firewall query** — `WHERE` clause filters by ownership
120
123
  4. **Post-record access** — full check including record-level predicates
@@ -110,7 +110,7 @@ A few mechanics to know:
110
110
  | Builder | Drizzle equivalent | Zod type |
111
111
  |---------|---------------------|----------|
112
112
  | `q.text()` | `text(...)` | `z.string()` |
113
- | `q.url()` | `text(...)` | `z.string().url()` |
113
+ | `q.url()` | `text(...)` | `z.string().url({ protocol: /^https?$/ })` |
114
114
  | `q.int()` | `integer(...)` | `z.number().int()` |
115
115
  | `q.bigint()` | `bigint(..., { mode: 'number' })` | `z.number().int()` within ±(2^53 − 1) |
116
116
  | `q.smallint()` | `smallint(...)` | `z.number().int()` within −32768..32767 |
@@ -132,9 +132,9 @@ In request bodies a column that is not `.required()` is `.optional().nullable()`
132
132
 
133
133
  `q.text()` and `q.url()` accept either a SQL-name string or an options object — `q.text({ sqlName: 'org_id', maxLength: 80 })`. `maxLength` adds `z.string().max(n)` at the validation edge; the SQL column stays `text` (D1 ignores `VARCHAR(n)` length anyway).
134
134
 
135
- `q.url()` is `q.text()` plus `z.string().url()` at the validation edge, so `javascript:` / `data:` URIs and free-form strings are rejected before they ever land in storage or get rendered in the CMS.
135
+ `q.url()` is `q.text()` plus an absolute-`http(s)`-URL check at the validation edge, so `javascript:` / `data:` / `ftp:` URIs and free-form strings are rejected before they ever land in storage or get rendered in the CMS.
136
136
 
137
- `q.id()` emits a plain text primary key. Actual ID assignment at insert time is driven by the provider's `generateId` setting. This keeps q's output decoupled from any specific ID library.
137
+ `q.id()` emits a plain text primary key. Actual ID assignment at insert time is driven by the provider's `generateId` setting (default `"uuid"`). This keeps q's output decoupled from any specific ID library.
138
138
 
139
139
  #### Typed JSON columns
140
140
 
@@ -168,11 +168,12 @@ The schema must be written inline from `z` and literals, because the compiler co
168
168
  - using `z` anywhere else in the table file
169
169
  - importing anything from `zod` other than `{ z }`
170
170
 
171
- For `generateId: "cuid"`, there is one important nuance: import-capable runtime
172
- paths can emit real `createId()` usage, but compiler-managed schema
173
- auto-injection may keep the same `createId()` call site and back it with a
174
- file-local `crypto.randomUUID()` polyfill so schema-generation sandboxes do not
175
- depend on project `node_modules`.
171
+ Under `generateId: "cuid"`, `"nanoid"`, or `"short"`, the `q.id()` default
172
+ calls an npm helper (`createId` from `@paralleldrive/cuid2`, or `nanoid` /
173
+ `customAlphabet` from `nanoid`). Don't import it in the table file, which may
174
+ not import either package. The compiler adds the import to the generated
175
+ `schema.ts` and the package to `package.json`, so the default mints the same
176
+ id shape as the CRUD route.
176
177
 
177
178
  ### Decimals, dates, 64-bit integers, and arrays
178
179
 
@@ -229,6 +230,8 @@ What you can query depends on the type. The compiler refuses the rest at compile
229
230
 
230
231
  `.searchable()` and `.filterable("like")` are text-only. Masks that format strings (`email`, `phone`, `partial`, and the rest) are refused on `q.bigint()`, `q.smallint()`, and array columns; use `redact` or `custom` there. Decimal and date values are strings, so every mask type works on them. `.defaultNow()` is only accepted on `q.timestamp()`.
231
232
 
233
+ `.defaultNow()` stamps the insert time whenever an insert omits the column. On Postgres it is a real `DEFAULT now()`. On SQLite / D1 the column carries a constant `DEFAULT '1970-01-01T00:00:00.000Z'` (D1 refuses a non-constant default on `ALTER TABLE ADD COLUMN`) plus a `$defaultFn`, and the generated `src/db/index.ts` makes every Drizzle insert use the `$defaultFn` — so only raw SQL that omits the column gets the epoch. Compilers from v0.33.2 until this fix wrote the epoch for Drizzle inserts too; see [Troubleshooting → timestamps read 1970-01-01](/tooling/troubleshooting#timestamps-read-1970-01-01-sqlite--d1) to find and repair affected rows.
234
+
232
235
  ### q.scope() — tenant scope columns
233
236
 
234
237
  `q.scope(kind)` is the canonical way to declare a column that holds a tenant-scope value (org / owner / team). It compiles to `text(...).notNull()` like a regular required text column, plus metadata that the compiler reads to:
@@ -672,7 +675,7 @@ Opt out of audit injection entirely with `compiler.features.auditFields: false`
672
675
 
673
676
  The scoped `db` injected into actions stamps these four columns for you. A handle built directly from `createDb()` does not — that's the documented escape hatch for system writes, sessionless principals, and broad reads the scoped wrapper over-narrows.
674
677
 
675
- Those writes still land in audit-managed tables, and the managed columns carry a DDL default of the unix epoch (so `ALTER TABLE ADD COLUMN` works on populated tables). An omitted column therefore **does not** fail loudly on `NOT NULL` — it silently persists `1970-01-01T00:00:00.000Z`, which reads as a real timestamp everywhere downstream.
678
+ Those writes still land in audit-managed tables. A Drizzle insert that omits `createdAt` / `modifiedAt` gets the insert time (Postgres `DEFAULT now()`; on SQLite the column's `$defaultFn`), but nothing fills `createdBy` / `modifiedBy` — they stay `NULL`. On SQLite the managed timestamps also carry a DDL default of the unix epoch (so `ALTER TABLE ADD COLUMN` works on populated tables), so **raw SQL** that omits them does not fail on `NOT NULL` — it silently persists `1970-01-01T00:00:00.000Z`, which reads as a real timestamp everywhere downstream.
676
679
 
677
680
  Spread the stamp instead of hand-writing four columns at each call site:
678
681
 
@@ -771,7 +774,7 @@ If this is an intentional system-side write, use the unwrapped db directly.
771
774
  Two paths to fix it, depending on intent:
772
775
 
773
776
  - **Mint a synthetic actor** (preferred — preserves attribution) — populate `ctx.userId` with one of the conventions above before calling into your handler.
774
- - **Bypass the wrapper entirely** — use the unwrapped `createDb` instead of the request-context `db`. Use this only for migrations, schema repair, or backfill scripts where you genuinely don't want any audit attribution. The audit columns will fall back to DB defaults (`createdAt`/`modifiedAt` populate from `defaultNow()`; `createdBy`/`modifiedBy` end up `NULL`).
777
+ - **Bypass the wrapper entirely** — use the unwrapped `createDb` instead of the request-context `db`. Use this only for migrations, schema repair, or backfill scripts where you genuinely don't want any audit attribution. `createdAt`/`modifiedAt` still get the insert time from their column default (a raw SQL insert that omits them on SQLite gets the epoch — set them yourself); `createdBy`/`modifiedBy` end up `NULL`.
775
778
 
776
779
  ### Disabling Audit Fields
777
780
 
@@ -256,14 +256,19 @@ otherwise the action would be unreachable, which is almost certainly a bug.
256
256
 
257
257
  ### Wire-level errors
258
258
 
259
- The compiled guard returns **409 `ACCESS_ACTION_NOT_ALLOWED_FOR_STATE`** with
260
- the field, the current value, the requested target, and the allowed set:
259
+ The compiled guard returns **409 `ACCESS_ACTION_NOT_ALLOWED_FOR_STATE`** as
260
+ `application/problem+json` (like every [API error](/api/errors)), with the
261
+ field, the current value, the requested target, and the allowed set:
261
262
 
262
263
  ```json
263
264
  {
264
- "error": "Action not allowed for current record state",
265
- "layer": "access",
265
+ "type": "https://quickback.dev/problems/access-action-not-allowed-for-state",
266
+ "title": "Access action not allowed for state",
267
+ "status": 409,
266
268
  "code": "ACCESS_ACTION_NOT_ALLOWED_FOR_STATE",
269
+ "detail": "Action not allowed for current record state",
270
+ "instance": "/api/v1/applications/app_123/advance",
271
+ "layer": "access",
267
272
  "details": {
268
273
  "field": "status",
269
274
  "current": "interview",
@@ -76,5 +76,6 @@ The runtime services around your compiled code. Everything you need for a comple
76
76
  - **[Webhooks](/platform/webhooks)** — Inbound (signed) and outbound (retried)
77
77
  - **[Admin UI](/ui/admin)** — Schema-driven admin UI
78
78
  - **[Account UI](/ui/account)** — Pre-built auth and profile pages
79
+ - **[Components](/ui/components)** — shadcn tables, forms, and action dialogs for your own React app
79
80
 
80
81
  Everything runs on **your own Cloudflare account** — no Quickback infrastructure between you and your data.
@@ -124,7 +124,7 @@ When `fromOpenAPI: false`, the emitted call has `capabilities: []` and no proxy
124
124
  - **WebAuthn step-up isn't wired in the approval UI yet.** Capabilities tagged `approvalStrength: "webauthn"` show a Step-up badge but the actual escalation call isn't made — the upstream API for that escalation is still settling. Until it lands, those capabilities will fail server-side regardless of approval.
125
125
  - **No CLI helpers for listing / revoking agents.** Use the BA admin API directly.
126
126
  - **Self-fetch on Cloudflare Workers** adds one subrequest per capability call (~50ms). For typical agent traffic this is fine; for very high-frequency agents consider pinning a custom `onExecute` that uses `app.request()` for in-process routing.
127
- - **`@better-auth/agent-auth` 0.4.5 ships ESM-only exports** without a `require` condition. The compiler image patches the package's `package.json` at install time so the Better Auth CLI's `auth generate` step (jiti / CJS) can resolve it. Remove the patch in the Dockerfile when upstream ships proper exports.
127
+ - **`@better-auth/agent-auth` 0.6.2 ships ESM-only exports** without a `require` condition. The compiler image patches the package's `package.json` at install time so the Better Auth CLI's `auth generate` step (jiti / CJS) can resolve it. Remove the patch in the Dockerfile when upstream ships proper exports.
128
128
 
129
129
  ## Why bearer-only?
130
130
 
@@ -39,7 +39,7 @@ Condition 2 is broader than it may look, and deliberately so. There is no
39
39
  per-provider inbound webhook configuration surface: the inbound route registers
40
40
  exactly one provider, Stripe, so *any* project that turned webhooks on is a
41
41
  project that can receive Stripe events. The same condition adds `stripe` to the
42
- generated `package.json` (pinned at `^22.5.0`), so the dependency and the client
42
+ generated `package.json` (pinned at `^22.6.1`), so the dependency and the client
43
43
  can never disagree about whether Stripe is in play.
44
44
 
45
45
  > **Accepted over-trigger.** A project that only *receives* Stripe webhooks and