@quickback-dev/cli 0.66.2 → 0.66.4

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 (84) hide show
  1. package/dist/commands/build.d.ts.map +1 -1
  2. package/dist/commands/build.js +11 -0
  3. package/dist/commands/build.js.map +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/skill/docs/api/actions.md +27 -3
  6. package/dist/skill/docs/api/batch-operations.md +4 -0
  7. package/dist/skill/docs/api/crud.md +57 -0
  8. package/dist/skill/docs/api/errors.md +1 -1
  9. package/dist/skill/docs/api/openapi.md +26 -6
  10. package/dist/skill/docs/api/query-params.md +19 -2
  11. package/dist/skill/docs/changelog/index.md +28 -0
  12. package/dist/skill/docs/configure/agents.md +2 -2
  13. package/dist/skill/docs/configure/auth.md +13 -0
  14. package/dist/skill/docs/configure/providers.md +2 -0
  15. package/dist/skill/docs/define/actions/defining.md +4 -1
  16. package/dist/skill/docs/define/firewall.md +1 -0
  17. package/dist/skill/docs/define/guards.md +7 -0
  18. package/dist/skill/docs/define/schema.md +5 -3
  19. package/dist/skill/docs/define/scopes.md +32 -0
  20. package/dist/skill/docs/platform/api-contract/index.md +36 -1
  21. package/dist/skill/docs/platform/auth/security.md +40 -15
  22. package/dist/skill/docs/platform/realtime/using-realtime.md +8 -0
  23. package/dist/skill/docs/platform/storage/r2.md +9 -6
  24. package/dist/skill/docs/platform/storage/using-r2.md +23 -8
  25. package/dist/skill/docs/tooling/cli.md +22 -6
  26. package/dist/skill/docs/tooling/output.md +9 -0
  27. package/dist/skill/docs/ui/account/features/admin.md +3 -1
  28. package/package.json +1 -1
  29. package/src/skill/docs/api/actions.md +27 -3
  30. package/src/skill/docs/api/batch-operations.md +4 -0
  31. package/src/skill/docs/api/crud.md +57 -0
  32. package/src/skill/docs/api/errors.md +1 -1
  33. package/src/skill/docs/api/openapi.md +26 -6
  34. package/src/skill/docs/api/query-params.md +19 -2
  35. package/src/skill/docs/changelog/index.md +28 -0
  36. package/src/skill/docs/configure/agents.md +2 -2
  37. package/src/skill/docs/configure/auth.md +13 -0
  38. package/src/skill/docs/configure/providers.md +2 -0
  39. package/src/skill/docs/define/actions/defining.md +4 -1
  40. package/src/skill/docs/define/firewall.md +1 -0
  41. package/src/skill/docs/define/guards.md +7 -0
  42. package/src/skill/docs/define/schema.md +5 -3
  43. package/src/skill/docs/define/scopes.md +32 -0
  44. package/src/skill/docs/platform/api-contract/index.md +36 -1
  45. package/src/skill/docs/platform/auth/security.md +40 -15
  46. package/src/skill/docs/platform/realtime/using-realtime.md +8 -0
  47. package/src/skill/docs/platform/storage/r2.md +9 -6
  48. package/src/skill/docs/platform/storage/using-r2.md +23 -8
  49. package/src/skill/docs/tooling/cli.md +22 -6
  50. package/src/skill/docs/tooling/output.md +9 -0
  51. package/src/skill/docs/ui/account/features/admin.md +3 -1
  52. package/dist/codex/AGENTS.md +0 -290
  53. package/dist/commands/codex.d.ts +0 -16
  54. package/dist/commands/codex.d.ts.map +0 -1
  55. package/dist/commands/codex.js +0 -159
  56. package/dist/commands/codex.js.map +0 -1
  57. package/dist/commands/compile.d.ts +0 -62
  58. package/dist/commands/compile.d.ts.map +0 -1
  59. package/dist/commands/compile.js +0 -830
  60. package/dist/commands/compile.js.map +0 -1
  61. package/dist/commands/compile.test.d.ts +0 -2
  62. package/dist/commands/compile.test.d.ts.map +0 -1
  63. package/dist/commands/compile.test.js +0 -150
  64. package/dist/commands/compile.test.js.map +0 -1
  65. package/dist/commands/init.d.ts +0 -6
  66. package/dist/commands/init.d.ts.map +0 -1
  67. package/dist/commands/init.js +0 -405
  68. package/dist/commands/init.js.map +0 -1
  69. package/dist/docs/content.d.ts +0 -7
  70. package/dist/docs/content.d.ts.map +0 -1
  71. package/dist/docs/content.js +0 -672
  72. package/dist/docs/content.js.map +0 -1
  73. package/dist/lib/helpers.d.ts +0 -39
  74. package/dist/lib/helpers.d.ts.map +0 -1
  75. package/dist/lib/helpers.js +0 -299
  76. package/dist/lib/helpers.js.map +0 -1
  77. package/dist/lib/sweep-stale.d.ts +0 -25
  78. package/dist/lib/sweep-stale.d.ts.map +0 -1
  79. package/dist/lib/sweep-stale.js +0 -179
  80. package/dist/lib/sweep-stale.js.map +0 -1
  81. package/dist/lib/sweep-stale.test.d.ts +0 -2
  82. package/dist/lib/sweep-stale.test.d.ts.map +0 -1
  83. package/dist/lib/sweep-stale.test.js +0 -130
  84. package/dist/lib/sweep-stale.test.js.map +0 -1
@@ -78,6 +78,7 @@ import { defineDatabase } from "@quickback/compiler";
78
78
  providers: {
79
79
  database: defineDatabase("cloudflare-d1", {
80
80
  generateId: "prefixed", // "uuid" | "cuid" | "nanoid" | "prefixed" | "serial" | false
81
+ allowClientIds: false, // true: POST bodies MAY carry a strategy-shaped id
81
82
  namingConvention: "snake_case", // "camelCase" | "snake_case"
82
83
  usePlurals: false, // Auth table names: "users" vs "user"
83
84
  }),
@@ -93,6 +94,7 @@ single Postgres database with no bindings or split mode (see
93
94
  | Option | Type | Default (D1) | Description |
94
95
  |--------|------|---------|-------------|
95
96
  | `generateId` | `string \| false` | `"prefixed"` | ID generation strategy |
97
+ | `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 |
96
98
  | `namingConvention` | `string` | `"snake_case"` | Column naming convention |
97
99
  | `usePlurals` | `boolean` | `false` | Pluralize auth table names (e.g. `user` vs `users`) |
98
100
  | `splitDatabases` | `boolean` | `true` | Separate auth and features databases (D1 only) |
@@ -57,7 +57,10 @@ export default defineAction({
57
57
 
58
58
  > **Your editor is typed too.** `quickback build` writes the same typed
59
59
  > helpers into `quickback/features/<feature>/.quickback/` (plus a
60
- > `quickback/tsconfig.json`), so the import above resolves — and typechecks —
60
+ > `quickback/tsconfig.json` and a `quickback/.quickback/compiler/` snapshot
61
+ > of the `@quickback/compiler` types, so `feature`/`q`/`defineTable` imports
62
+ > in table files and `quickback.config.ts` resolve as well). The import above
63
+ > resolves — and typechecks —
61
64
  > in the tree you actually edit, not just in the generated output. The helper
62
65
  > also **re-exports every table in the feature** typed with the generated schema, so
63
66
  > compiler-managed columns (`createdAt`, `modifiedBy`, `deletedAt`,
@@ -129,6 +129,7 @@ firewall: {
129
129
  Null-safe scope semantics make this safe (these apply **inside `all`/`any` groups**, opt-in via the new syntax):
130
130
 
131
131
  - A **scope** arm (`ctx.activeOrgId`, `ctx.activeTeamId`, `ctx.scope.*`) whose claim is **absent never binds `undefined`** (the classic 500 / "match every row" trap). In an `any` group an absent arm **drops**; if **every** arm drops, the group denies with `sql\`1 = 0\`` (the empty-guard) — never a full-table read. In an `all` group an absent required scope **denies** the group.
132
+ - **An `any` group with an org arm tenant-binds its scope and relationship arms.** Beside `{ field: 'organizationId', equals: 'ctx.activeOrgId' }`, a `ctx.scope.*` arm, a `via:` arm, or a `{ permission }` arm is emitted as `scope-arm AND (organizationId = ctx.activeOrgId OR the caller has no org claim)`. A caller with **no** org claim (a scope-only or relationship principal) is unaffected; a caller who carries org B's membership *and* a scope claim or relationship row on an org-A instance cannot ride the scope arm into org A's rows. Owner arms (`ctx.userId`), team arms, and literal `in` lists are not tenant-bound. An org claim and a scope claim in one request are therefore always the same tenant — or the scope arm yields nothing.
132
133
  - Mark an arm `{ optional: true }` to **drop-instead-of-deny** when absent inside an `all` group (the teamless rest-of-org slice — `ctx.activeTeamId` is implicitly optional).
133
134
  - **Owner** (`ctx.userId`) and **soft-delete** (`isNull deletedAt`) are always present / always AND'd — never relaxed.
134
135
 
@@ -280,6 +280,13 @@ When upsert creates a new record, ownership fields are auto-set from context:
280
280
  | `'serial'` | No | Database auto-increments |
281
281
  | `false` | Yes (if guards: false) | Client provides ID |
282
282
 
283
+ Need client-generated ids without giving up server minting or guards? Set
284
+ `allowClientIds: true` instead — creates accept an **optional**
285
+ strategy-shaped `id` (for optimistic updates), guards stay on, and the id is
286
+ exempt from `createable`. See
287
+ [Client-supplied IDs](/api/crud#client-supplied-ids-optimistic-updates).
288
+ Upsert still requires `generateId: false` + `guards: false`.
289
+
283
290
  ## Compile-Time Validation
284
291
 
285
292
  The Quickback compiler validates your guards configuration and will error if:
@@ -625,14 +625,16 @@ compliance.
625
625
 
626
626
  ### Protected system fields
627
627
 
628
- The audit and soft-delete columns are always protected from client input, even with `guards: false`:
628
+ These fields never take their value from client input, even with `guards: false` — but the mechanism differs by field class:
629
629
 
630
- - `id` (when `generateId` is not `false`)
631
630
  - `createdAt`, `createdBy` *(audit — always present)*
632
631
  - `modifiedAt`, `modifiedBy` *(audit — always present)*
633
632
  - `deletedAt`, `deletedBy` *(soft-delete — present when delete mode allows soft)*
634
633
 
635
- Protection is enforced by the runtime wrapper — even if a request body passes one of these, it gets overwritten before the SQL is built.
634
+ The six audit/soft-delete columns are **overwritten** by the runtime wrapper — a request body that carries one is server-stamped before the SQL is built.
635
+
636
+ `id` (when `generateId` is not `false`) is **rejected at the edge** instead: it is omitted from the `.strict()` Zod body schema, so a body carrying it is a `400 VALIDATION_ERROR`, and the guards `createable` allow-list backstops that. Nothing overwrites `id` at the insert — the Zod/guards boundary is the protection. Under
637
+ [`allowClientIds: true`](/api/crud#client-supplied-ids-optimistic-updates) a strategy-shaped `id` is accepted on create only.
636
638
 
637
639
  ## Auto-Indexes
638
640
 
@@ -347,6 +347,38 @@ so it can only ever carry the role the caller actually proved this request.
347
347
 
348
348
  - A **multi-lane `via:`** (e.g. `via: ['attendeeOf', 'organizerOf']`) mints the matched lane's role — `attendeeOf` → `scope.event.roles = ['attendee']`, `organizerOf` → `['organizer']`. The resolver records which lane opened the gate, so there is no ambiguity.
349
349
  - A **bulk-grant lane** (`{ roles: [...] }` or `{ team: true }`) mints **no** scope role — it opens the gate via the caller's org role without proving a relationship. The gate passes; the caller carries their org role, not a minted scope role.
350
+ - **The org claim is only ever signed beside a membership role.** Every mint site — `/scope/v1/enter`, the namespace resolver, `/api/v1/token` — writes `orgId` into the token only when a membership `role` accompanies it, and the auth middleware ignores an `orgId` claim that arrives without a `role`. A relationship-promoted tenant (the in-request `ctx.activeOrgId` stamped from the proven row so the firewall resolves) is never persisted as a bare tenant grant.
351
+
352
+ ### The bulk-grant lane is tenant-bound
353
+
354
+ An org role is only good **inside the caller's own org**. When the namespace
355
+ hydrates a shared resource whose table carries an organization column (the
356
+ `loads` / `exposeAs` target), the resolver checks that the requested instance
357
+ belongs to `ctx.activeOrgId` *before* honouring a `{ roles }` / `{ team }`
358
+ lane. If it does not — an org-B admin entering an org-A event — the lane does
359
+ not apply: the caller is re-evaluated through the relationship lanes as a
360
+ **relationship-only principal**, with `ctx.roles = []` and the in-request tenant
361
+ re-stamped from the proven row (exactly the state a caller with no org seat
362
+ gets). No relationship → `403`. Any `ctx.roles`-based check in the action then
363
+ fails for them, scoped-db inserts stamp the *instance's* org, and the
364
+ namespace re-mint carries no org claim.
365
+
366
+ Multi-target namespaces (lanes that hydrate *different* tables) hydrate nothing
367
+ for a role caller, so there is nothing to bind there — put the tenant check in
368
+ the firewall of each table instead (an org arm in an [`any` group tenant-binds
369
+ its scope arms](/define/firewall#allany-groups--null-safe-scope-semantics) automatically).
370
+
371
+ ### Dropping the org claim on purpose
372
+
373
+ Guest and crew clients that must never ride the user's org membership into a
374
+ scope can mint an identity token without it:
375
+
376
+ ```bash
377
+ curl -X POST https://api.example.com/api/v1/token \
378
+ -H "Cookie: <session>" -H "Content-Type: application/json" \
379
+ -d '{ "dropOrg": true }'
380
+ # → { token } with no orgId / role claim; scope entry then proves only relationships
381
+ ```
350
382
 
351
383
  > The realtime [ws-ticket](/platform/realtime/durable-objects#namespace-backed-tickets-per-matched-lane) can authorize through this same namespace `via:`, issuing a per-matched-lane WebSocket ticket — so the socket gate and the REST gate stay identical.
352
384
 
@@ -115,11 +115,14 @@ export default defineAction({
115
115
 
116
116
  ## One axis: routes
117
117
 
118
- `contract` has a single key. It selects the URL prefix and nothing else.
118
+ `contract.routes` is the one behavioural axis. It selects the URL prefix and
119
+ nothing else. (`contract.redirects`, below, adds same-origin path redirects —
120
+ it changes no behaviour of the canonical routes.)
119
121
 
120
122
  | Key | Controls | Default |
121
123
  |---|---|---|
122
124
  | `routes` | The URL prefix, and nothing else | `'v1'` |
125
+ | `redirects` | Same-origin path redirects, emitted natively | none |
123
126
 
124
127
  A project with no `contract` block serves `/api/v1`. Set `routes: "v2"` to
125
128
  serve `/api/v2` instead — the behavior is identical either way.
@@ -176,6 +179,38 @@ service, so an older CLI gets the same output.
176
179
  | Auth base | `/auth/v1` | `/auth/v2` |
177
180
  | Realtime base | `/broadcast/v1` | `/broadcast/v2` |
178
181
 
182
+ ### `redirects` — keep answering an old prefix
183
+
184
+ A project that keeps `routes: "v1"` can still answer an older `/api/v2/*`
185
+ prefix by declaring the redirect — as config, not as a hand-edit of the
186
+ generated `src/index.ts` that the next compile clobbers:
187
+
188
+ {/* doc-compile: skip — config fragment, not a compilable project */}
189
+ ```typescript
190
+ contract: {
191
+ routes: "v1",
192
+ redirects: [
193
+ { from: "/api/v2/*", to: "/api/v1/*" }, // 308 by default
194
+ { from: "/auth/v2/*", to: "/auth/v1/*" },
195
+ { from: "/broadcast/v2/*", to: "/broadcast/v1/*" },
196
+ { from: "/legacy/health", to: "/health", status: 301 },
197
+ ],
198
+ }
199
+ ```
200
+
201
+ - `from` / `to` are **paths** — they must start with `/` and can never be a
202
+ full URL or a `//host` form, so a rule cannot become an open redirect. The
203
+ emitted `Location` is always same-origin.
204
+ - A trailing `/*` makes a **prefix** rule: it matches the bare prefix and
205
+ everything under it, and carries the remainder across (`/api/v2/events/7`
206
+ → `/api/v1/events/7`). `from` and `to` must both end with `/*` or neither.
207
+ - The query string is preserved; `status` is `308` (method + body preserving)
208
+ by default, or `301` / `302` / `307`.
209
+ - Rules are validated at compile time (self-redirects and prefix loops are
210
+ rejected) and emitted right after the CORS mount, ahead of auth, so
211
+ preflights still get their headers and every later layer sees canonical
212
+ paths only.
213
+
179
214
  ## Machine-readable contract
180
215
 
181
216
  - `GET /openapi.json` — OpenAPI 3.1: Problem responses, cursor params,
@@ -89,28 +89,53 @@ auth: defineAuth("better-auth", {
89
89
  enabled: true,
90
90
  window: 60, // 60 second window
91
91
  max: 100, // 100 requests per IP per window
92
+ storage: "database", // default on Cloudflare Workers — see below
92
93
  customRules: {
94
+ // Merged ON TOP of the built-in per-route rules (same path → yours wins)
93
95
  "/sign-in/email": { window: 60, max: 10 },
94
- "/sign-in/social": { window: 60, max: 10 },
95
- "/device/init": { window: 60, max: 5 },
96
- "/device/poll": { window: 60, max: 30 },
97
- "/device/token": { window: 60, max: 10 },
98
96
  }
99
97
  }
100
98
  })
101
99
  ```
102
100
 
103
- ### Custom Rules by Endpoint
104
-
105
- Set different limits based on endpoint sensitivity:
106
-
107
- | Endpoint Type | Recommended Limit | Reasoning |
108
- |---------------|-------------------|-----------|
109
- | Sign-in | 10/min per IP | Prevent credential stuffing |
110
- | Device codes | 5/min per IP | Prevent device code enumeration |
111
- | Token exchange | 10/min per IP | Prevent token brute-force |
112
- | Polling | 30/min per IP | Allow reasonable polling (every 2s) |
113
- | General API | 100/min per IP | Balance abuse prevention and usability |
101
+ ### Counter storage
102
+
103
+ Better Auth's own default keeps the counters in **process memory**. On
104
+ Cloudflare Workers that memory is per-isolate and per-colo, so counters reset
105
+ constantly and are bypassed by spreading requests across edges — an in-memory
106
+ limiter is decorative on the target runtime. The compiler therefore defaults
107
+ `rateLimit.storage` to **`"database"`** on Cloudflare: counters live in the auth
108
+ database (Better Auth adds a `rateLimit` table through the normal schema
109
+ generation, so a recompile produces the migration). On bun / node — one
110
+ long-lived process — the default is `"memory"`.
111
+
112
+ | `storage` | Where counters live | Use when |
113
+ |-----------|---------------------|----------|
114
+ | `"database"` | Auth database (`rateLimit` table) | Cloudflare Workers (default there) |
115
+ | `"memory"` | Process memory | Single long-lived process (bun / node default) |
116
+
117
+ ### Built-in rules for every credential door
118
+
119
+ The compiler always emits a per-route rule for **every** credential endpoint
120
+ Better Auth mounts — not just password sign-in — so an OTP verify door (a
121
+ 6-digit, 10<sup>6</sup>-space code) is never left under the 100/min general
122
+ limit. Your `customRules` **merge on top**: declare a path to change its limit,
123
+ or add paths for project plugins.
124
+
125
+ | Route(s) | Default | Reasoning |
126
+ |----------|---------|-----------|
127
+ | `/sign-in/email`, `/sign-in/username`, `/sign-in/social`, `/sign-in/anonymous` | 10/min per IP | Credential stuffing |
128
+ | `/sign-up/email` | 5/min per IP | Account-creation abuse |
129
+ | `/forget-password`, `/request-password-reset`, `/reset-password` | 5/min per IP | Reset-token brute force, mail bombing |
130
+ | `/sign-in/email-otp`, `/email-otp/send-verification-otp`, `/email-otp/verify-email`, `/email-otp/check-verification-otp`, `/email-otp/reset-password`, `/email-otp/request-password-reset` | 5/min per IP | OTP brute force + mail bombing |
131
+ | `/send-verification-email`, `/verify-email`, `/sign-in/magic-link`, `/magic-link/verify` | 5–10/min per IP | Link/token brute force |
132
+ | `/phone-number/send-otp`, `/phone-number/verify`, `/phone-number/request-password-reset`, `/phone-number/reset-password` | 5/min per IP | SMS OTP brute force + SMS cost |
133
+ | `/two-factor/send-otp`, `/two-factor/verify-otp`, `/two-factor/verify-totp`, `/two-factor/verify-backup-code` | 5/min per IP | Second-factor brute force |
134
+ | `/device/init` / `/device/poll` / `/device/token` | 5 / 30 / 10 per min per IP | Device-code enumeration, polling, token exchange |
135
+ | Everything else under `/auth/v1` | `max` (100/min per IP) | General abuse prevention |
136
+
137
+ Set an edge rate-limit binding as well for defence in depth
138
+ ([`rateLimit`](/define/rate-limit)) — the two layers are independent.
114
139
 
115
140
  ### Why Per-IP?
116
141
 
@@ -184,6 +184,14 @@ Events can target a specific user lane. Only that user receives the broadcast
184
184
 
185
185
  Each WebSocket connection is attached to exactly one resolved scope: `scopeKey`, `organizationId`, or `userId`. Users can only subscribe to the scope stamped into their ws ticket, enforced during authentication and ticket minting.
186
186
 
187
+ There is **no shared fallback room**. A signed-in caller with no active
188
+ organization (a self-registered account, an attendee-only account, external
189
+ crew) gets a non-scoped ticket bound to their **own user room**
190
+ (`user-<userId>`), so the only frames it can ever receive are ones addressed to
191
+ that user. Emits from a request with no `ctx.activeOrgId` and no resource scope
192
+ are skipped rather than delivered somewhere every org-less subscriber could
193
+ read, and a broadcast target that names no room is refused.
194
+
187
195
  ## Reconnection
188
196
 
189
197
  WebSocket connections can drop due to network issues. Implement reconnection logic in your client — note that you need to fetch a fresh ticket on each reconnect since tickets expire after 60 seconds:
@@ -290,7 +290,7 @@ curl -X POST https://api.example.com/storage/v1/presign/videos/clip.mp4 \
290
290
  # "key": "org_abc/videos/clip.mp4",
291
291
  # "uploadUrl": "https://<account>.r2.cloudflarestorage.com/...&X-Amz-Signature=...",
292
292
  # "method": "PUT",
293
- # "headers": { "Content-Type": "video/mp4" },
293
+ # "headers": { "Content-Length": "73400320", "Content-Type": "video/mp4" },
294
294
  # "expiresAt": "2026-06-02T12:10:00.000Z"
295
295
  # }
296
296
 
@@ -302,9 +302,11 @@ curl -X POST https://api.example.com/storage/v1/confirm/videos/clip.mp4 \
302
302
  -H "Authorization: Bearer <token>"
303
303
  ```
304
304
 
305
- > If `contentType` is supplied at step 1 it is **bound into the signature** — the
306
- > client MUST send exactly that `Content-Type` header on the PUT, or R2 rejects
307
- > it. Omit it to let the client send any type.
305
+ > The `size` and `contentType` from step 1 are **bound into the signature** as
306
+ > `Content-Length` and `Content-Type` — the client MUST replay the returned
307
+ > `headers` verbatim on the PUT, or R2 rejects it. That is what makes
308
+ > `maxFileSize` and `allowedTypes` real limits on the object that lands, not
309
+ > just on the request that asked for a URL.
308
310
 
309
311
 
310
312
  ### Required secrets
@@ -336,13 +338,14 @@ export default defineAction({
336
338
  description: 'Issue a presigned R2 upload URL for a media file on an event.',
337
339
  path: '/event/:eventId/media/sign-upload',
338
340
  method: 'POST',
339
- input: z.object({ filename: z.string(), contentType: z.string() }),
341
+ input: z.object({ filename: z.string(), contentType: z.string(), size: z.number().int().nonnegative() }),
340
342
  access: { roles: ['admin', 'member', 'scope:event:attendee'] },
341
343
  async execute({ input, ctx, db, storage }) {
342
344
  // Tenant-scoped key — secure by construction
343
345
  const key = `org/${ctx.activeOrgId}/event/${input.eventId}/${crypto.randomUUID()}-${input.filename}`;
344
346
  const upload = await storage.signPutUrl(key, {
345
347
  contentType: input.contentType,
348
+ contentLength: input.size,
346
349
  expiresIn: 600,
347
350
  });
348
351
  await db.insert(images).values({ key, eventId: input.eventId /* … */ });
@@ -355,7 +358,7 @@ export default defineAction({
355
358
 
356
359
  | Method | Returns | Use |
357
360
  |--------|---------|-----|
358
- | `signPutUrl(key, { contentType?, expiresIn? })` | `{ url, method, headers, key, expiresAt }` | Client uploads directly to R2 |
361
+ | `signPutUrl(key, { contentLength, contentType?, expiresIn? })` | `{ url, method, headers, key, expiresAt }` | Client uploads directly to R2 — size (and type) are signed and checked against `maxFileSize` / `allowedTypes` |
359
362
  | `signGetUrl(key, { expiresIn?, downloadFilename? })` | `string` | Client downloads directly from R2 |
360
363
 
361
364
  This is the supported replacement for streaming a raw binary body through an
@@ -92,11 +92,15 @@ export default defineAction({
92
92
  description: "Sign a direct-to-R2 upload URL and record the object key on the media row.",
93
93
  path: "/media/sign-upload",
94
94
  method: "POST",
95
- input: z.object({ filename: z.string(), contentType: z.string() }),
95
+ input: z.object({ filename: z.string(), contentType: z.string(), size: z.number().int().nonnegative() }),
96
96
  access: { roles: ["member"] },
97
97
  async execute({ input, ctx, db, storage }) {
98
98
  const key = `org/${ctx.activeOrgId}/${crypto.randomUUID()}-${input.filename}`;
99
- const upload = await storage.signPutUrl(key, { contentType: input.contentType, expiresIn: 600 });
99
+ const upload = await storage.signPutUrl(key, {
100
+ contentType: input.contentType, // bound into the signature
101
+ contentLength: input.size, // required — bound into the signature, checked against maxFileSize
102
+ expiresIn: 600,
103
+ });
100
104
  await db.insert(media).values({ key /* … */ });
101
105
  return { uploadUrl: upload.url, key, headers: upload.headers };
102
106
  },
@@ -107,17 +111,28 @@ export default defineAction({
107
111
  # 1. Ask your action for a signed URL (your auth/roles run here)
108
112
  curl -X POST https://api.example.com/api/v1/media/sign-upload \
109
113
  -H "Authorization: Bearer <token>" -H "Content-Type: application/json" \
110
- -d '{ "filename": "report.pdf", "contentType": "application/pdf" }'
111
- # → { "uploadUrl": "https://<account>.r2.cloudflarestorage.com/...&X-Amz-Signature=...", "key": "...", "headers": { "Content-Type": "application/pdf" } }
114
+ -d '{ "filename": "report.pdf", "contentType": "application/pdf", "size": 48213 }'
115
+ # → { "uploadUrl": "https://<account>.r2.cloudflarestorage.com/...&X-Amz-Signature=...", "key": "...", "headers": { "Content-Length": "48213", "Content-Type": "application/pdf" } }
112
116
 
113
117
  # 2. Upload the bytes straight to R2 (replay the returned headers verbatim)
114
118
  curl -X PUT "<uploadUrl>" -H "Content-Type: application/pdf" --data-binary @report.pdf
115
119
  ```
116
120
 
117
- `storage.signPutUrl(key, { contentType?, expiresIn?, bucket? })` returns
118
- `{ url, method, headers, key, expiresAt }`; `storage.signGetUrl(key, { expiresIn?, downloadFilename?, bucket? })`
119
- returns a presigned GET URL. Pass `bucket` to target a bucket other than the
120
- configured default.
121
+ `storage.signPutUrl(key, { contentLength, contentType?, expiresIn?, bucket? })`
122
+ returns `{ url, method, headers, key, expiresAt }`;
123
+ `storage.signGetUrl(key, { expiresIn?, downloadFilename?, bucket? })` returns a
124
+ presigned GET URL. Pass `bucket` to target a bucket other than the configured
125
+ default.
126
+
127
+ **The size and type are signed, and the declared limits are enforced.**
128
+ `contentLength` is required: it is checked against `fileStorage.maxFileSize`
129
+ (the presign is refused above it) and bound into the signature as the
130
+ `Content-Length` header, so the URL cannot upload a different size than the
131
+ action approved. `contentType` is bound the same way, and when the project
132
+ declares `fileStorage.allowedTypes` it is required and must be on the list. A
133
+ PUT that does not replay the returned `headers` verbatim is rejected by R2. A
134
+ project that declares neither limit gets no ceiling and no allowlist — the
135
+ signature is still size-bound.
121
136
 
122
137
  Presigning needs an R2 API token — set the `R2_ACCOUNT_ID`, `R2_ACCESS_KEY_ID`,
123
138
  and `R2_SECRET_ACCESS_KEY` secrets. A [browser deploy](/start/deploy-browser)
@@ -125,15 +125,31 @@ quickback check --watch # re-check on change (tsc --watch)
125
125
  ```
126
126
 
127
127
  Runs `tsc` over `quickback/tsconfig.json` — the config the compiler emits on
128
- every compile, which typechecks the tree you actually edit (actions, lib,
129
- table files) against the generated `.quickback/` typed helpers. No compile,
130
- no server: this is your editor's view of the source, on demand.
128
+ every compile, which typechecks the tree you actually edit against two
129
+ generated typing surfaces:
130
+
131
+ - **Action typing** — the per-feature `.quickback/define-action` helpers:
132
+ `record`, `ctx`, `input`, and the scoped `db` typed against your tables.
133
+ - **Definition typing** — `quickback/.quickback/compiler/`, a
134
+ declaration-file snapshot of the compiler's real `@quickback/compiler`
135
+ surface. `import { feature, q, defineTable, defineConfig } from
136
+ "@quickback/compiler"` resolves in table files and `quickback.config.ts`,
137
+ so a bad builder call or an unknown resource-config key is a type error at
138
+ the desk, not a compile-round-trip later.
139
+
140
+ No compile, no server: this is your editor's view of the source, on demand.
131
141
 
132
142
  Exit codes: `0` clean · `1` type errors · `2` setup missing. A fresh clone
133
143
  (or a project that has never compiled) exits `2` with a pointer at
134
- `quickback build`, which generates the tsconfig and helpers the check
135
- resolves against. Re-run `quickback build` after schema changes so the
136
- helpers track your tables.
144
+ `quickback build`, which generates the tsconfig, helpers, and compiler types
145
+ the check resolves against. Re-run `quickback build` after schema changes so
146
+ they track your tables.
147
+
148
+ Actions that still import a table from the authored feature file
149
+ (`import { tickets } from "../tickets"`) fail the check — the q-DSL feature
150
+ file has only a default export. Import the table from the typed helper
151
+ instead (`import { defineAction, tickets } from "../.quickback/define-action"`);
152
+ `quickback migrate helper-imports` rewrites the safe cases for you.
137
153
 
138
154
  ### Synchronize Managed Columns
139
155
 
@@ -44,6 +44,15 @@ src/
44
44
  ├── db.ts # Database instance middleware
45
45
  └── services.ts # Service injection middleware
46
46
 
47
+ # Authored-tree typing (regenerated on every compile, gitignored)
48
+ quickback/tsconfig.json # Typechecks the authored quickback/ tree (`quickback check`)
49
+ quickback/.quickback/
50
+ └── compiler/ # @quickback/compiler declaration snapshot — resolves
51
+ └── … # `import { feature, q, defineTable } from "@quickback/compiler"`
52
+ quickback/features/{feature}/
53
+ └── .quickback/
54
+ └── define-action.ts # Authored-tree twin of the typed helper below
55
+
47
56
  quickback/drizzle/
48
57
  ├── auth/ # Auth migrations (dual mode)
49
58
  │ ├── meta/
@@ -45,7 +45,9 @@ These run on `/auth/v1/admin/*`, emitted by Quickback because Better Auth's orga
45
45
 
46
46
  The admin panel is restricted to platform roles on the Better Auth user record: **`appmanager`** (the control plane) and **`sysadmin`** (which adds cross-tenant data access on top). Everyone else is redirected away from `/admin`.
47
47
 
48
- > **`role: "admin"` is not a platform role.** The compiler seeds the admin plugin with `adminRoles: ["appmanager", "sysadmin"]`, so a user set to `"admin"` passed the UI guard and then got `403` from every admin API call — an operator who looked promoted and could not act. Removed in v0.62; migrate those rows to `"appmanager"`.
48
+ > **`role: "admin"` is not a platform role.** By default the compiler seeds the admin plugin with `adminRoles: ["appmanager", "sysadmin"]`, so a user set to `"admin"` passed the UI guard and then got `403` from every admin API call — an operator who looked promoted and could not act. Removed in v0.62; migrate those rows to `"appmanager"`.
49
+ >
50
+ > A project that declares `plugins: { admin: { adminRoles, roles } }` gets **exactly** that: the declared `adminRoles` list and role → access-controller map are emitted verbatim (`appmanager: userAc` narrows the provisioning operator to no admin API at all; `adminRoles: ["sysadmin"]` keeps set-role / impersonate / ban for `sysadmin` only). The compiler never re-widens a declared role, and refuses a declaration it cannot honour.
49
51
 
50
52
 
51
53
  To grant operator access to a user: