@quickback-dev/cli 0.38.0 → 0.40.0

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 (109) hide show
  1. package/dist/commands/compile.d.ts.map +1 -1
  2. package/dist/commands/compile.js +36 -2
  3. package/dist/commands/compile.js.map +1 -1
  4. package/dist/commands/compile.test.d.ts +2 -0
  5. package/dist/commands/compile.test.d.ts.map +1 -0
  6. package/dist/commands/compile.test.js +83 -0
  7. package/dist/commands/compile.test.js.map +1 -0
  8. package/dist/commands/create.js +15 -11
  9. package/dist/commands/create.js.map +1 -1
  10. package/dist/commands/migrations.d.ts +33 -0
  11. package/dist/commands/migrations.d.ts.map +1 -1
  12. package/dist/commands/migrations.js +41 -2
  13. package/dist/commands/migrations.js.map +1 -1
  14. package/dist/commands/migrations.test.d.ts +2 -0
  15. package/dist/commands/migrations.test.d.ts.map +1 -0
  16. package/dist/commands/migrations.test.js +67 -0
  17. package/dist/commands/migrations.test.js.map +1 -0
  18. package/dist/docs/content.js +24 -24
  19. package/dist/docs/content.js.map +1 -1
  20. package/dist/examples/recruitment.tar.gz +0 -0
  21. package/dist/index.js +1 -1
  22. package/dist/lib/action-harvest.d.ts +48 -0
  23. package/dist/lib/action-harvest.d.ts.map +1 -0
  24. package/dist/lib/action-harvest.js +292 -0
  25. package/dist/lib/action-harvest.js.map +1 -0
  26. package/dist/lib/action-harvest.test.d.ts +2 -0
  27. package/dist/lib/action-harvest.test.d.ts.map +1 -0
  28. package/dist/lib/action-harvest.test.js +112 -0
  29. package/dist/lib/action-harvest.test.js.map +1 -0
  30. package/dist/lib/api-client.d.ts +10 -0
  31. package/dist/lib/api-client.d.ts.map +1 -1
  32. package/dist/lib/api-client.js +17 -1
  33. package/dist/lib/api-client.js.map +1 -1
  34. package/dist/lib/api-client.test.js +19 -0
  35. package/dist/lib/api-client.test.js.map +1 -1
  36. package/dist/lib/artifact-routing.d.ts +1 -0
  37. package/dist/lib/artifact-routing.d.ts.map +1 -1
  38. package/dist/lib/artifact-routing.js +15 -3
  39. package/dist/lib/artifact-routing.js.map +1 -1
  40. package/dist/lib/artifact-routing.test.js +12 -1
  41. package/dist/lib/artifact-routing.test.js.map +1 -1
  42. package/dist/lib/file-loader.d.ts +1 -0
  43. package/dist/lib/file-loader.d.ts.map +1 -1
  44. package/dist/lib/file-loader.js +34 -1
  45. package/dist/lib/file-loader.js.map +1 -1
  46. package/dist/lib/file-loader.test.js +28 -4
  47. package/dist/lib/file-loader.test.js.map +1 -1
  48. package/dist/lib/prepare-state-output.d.ts +8 -0
  49. package/dist/lib/prepare-state-output.d.ts.map +1 -0
  50. package/dist/lib/prepare-state-output.js +17 -0
  51. package/dist/lib/prepare-state-output.js.map +1 -0
  52. package/dist/lib/prepare-state-output.test.d.ts +2 -0
  53. package/dist/lib/prepare-state-output.test.d.ts.map +1 -0
  54. package/dist/lib/prepare-state-output.test.js +31 -0
  55. package/dist/lib/prepare-state-output.test.js.map +1 -0
  56. package/dist/skill/SKILL.md +1 -1
  57. package/dist/skill/docs/changelog.md +262 -0
  58. package/dist/skill/docs/compiler/config/agents.md +1 -1
  59. package/dist/skill/docs/compiler/config/auth.md +1 -1
  60. package/dist/skill/docs/compiler/config/index.md +8 -9
  61. package/dist/skill/docs/compiler/config/providers.md +3 -0
  62. package/dist/skill/docs/compiler/config/single-tenant.md +65 -73
  63. package/dist/skill/docs/compiler/definitions/access.md +40 -33
  64. package/dist/skill/docs/compiler/definitions/actions.md +1 -1
  65. package/dist/skill/docs/compiler/definitions/firewall.md +1 -1
  66. package/dist/skill/docs/compiler/definitions/schema.md +8 -2
  67. package/dist/skill/docs/compiler/getting-started/template-blog.md +7 -7
  68. package/dist/skill/docs/compiler/getting-started/template-empty.md +1 -4
  69. package/dist/skill/docs/compiler/getting-started/templates.md +6 -6
  70. package/dist/skill/docs/compiler/targets/hono-api/using-the-api/actions-api.md +2 -2
  71. package/dist/skill/docs/stack/account-ui/features/admin.md +1 -1
  72. package/dist/skill/docs/stack/account-ui/features/index.md +2 -2
  73. package/dist/skill/docs/stack/cms/connecting.md +17 -16
  74. package/dist/skill/docs/stack/cms/index.md +7 -7
  75. package/dist/skill/docs/stack/cms/schema-format.md +0 -2
  76. package/dist/skill/docs/stack/cms/schema-registry.md +0 -6
  77. package/dist/skill/docs/stack/cms/security.md +6 -6
  78. package/dist/skill/docs/stack/realtime/durable-objects.md +5 -7
  79. package/dist/skill/docs/stack/storage/r2.md +142 -4
  80. package/dist/skill/docs/stack/storage/using-r2.md +30 -10
  81. package/dist/templates/registry.js +2 -2
  82. package/dist/templates/registry.js.map +1 -1
  83. package/package.json +1 -1
  84. package/src/examples/recruitment.tar.gz +0 -0
  85. package/src/skill/SKILL.md +1 -1
  86. package/src/skill/docs/changelog.md +262 -0
  87. package/src/skill/docs/compiler/config/agents.md +1 -1
  88. package/src/skill/docs/compiler/config/auth.md +1 -1
  89. package/src/skill/docs/compiler/config/index.md +8 -9
  90. package/src/skill/docs/compiler/config/providers.md +3 -0
  91. package/src/skill/docs/compiler/config/single-tenant.md +65 -73
  92. package/src/skill/docs/compiler/definitions/access.md +40 -33
  93. package/src/skill/docs/compiler/definitions/actions.md +1 -1
  94. package/src/skill/docs/compiler/definitions/firewall.md +1 -1
  95. package/src/skill/docs/compiler/definitions/schema.md +8 -2
  96. package/src/skill/docs/compiler/getting-started/template-blog.md +7 -7
  97. package/src/skill/docs/compiler/getting-started/template-empty.md +1 -4
  98. package/src/skill/docs/compiler/getting-started/templates.md +6 -6
  99. package/src/skill/docs/compiler/targets/hono-api/using-the-api/actions-api.md +2 -2
  100. package/src/skill/docs/stack/account-ui/features/admin.md +1 -1
  101. package/src/skill/docs/stack/account-ui/features/index.md +2 -2
  102. package/src/skill/docs/stack/cms/connecting.md +17 -16
  103. package/src/skill/docs/stack/cms/index.md +7 -7
  104. package/src/skill/docs/stack/cms/schema-format.md +0 -2
  105. package/src/skill/docs/stack/cms/schema-registry.md +0 -6
  106. package/src/skill/docs/stack/cms/security.md +6 -6
  107. package/src/skill/docs/stack/realtime/durable-objects.md +5 -7
  108. package/src/skill/docs/stack/storage/r2.md +142 -4
  109. package/src/skill/docs/stack/storage/using-r2.md +30 -10
@@ -0,0 +1,31 @@
1
+ import { afterEach, describe, expect, it } from 'bun:test';
2
+ import { promises as fs } from 'fs';
3
+ import { join } from 'path';
4
+ import { tmpdir } from 'os';
5
+ import { prepareStateArtifacts } from './prepare-state-output.js';
6
+ const tempDirs = [];
7
+ async function createTempDir() {
8
+ const dir = await fs.mkdtemp(join(tmpdir(), 'quickback-cli-state-'));
9
+ tempDirs.push(dir);
10
+ return dir;
11
+ }
12
+ afterEach(async () => {
13
+ await Promise.all(tempDirs.splice(0).map((dir) => fs.rm(dir, { recursive: true, force: true })));
14
+ });
15
+ describe('prepareStateArtifacts', () => {
16
+ // User story: As a Neon user rerunning compile locally, I need stale
17
+ // top-level drizzle migrations removed from quickback/drizzle/ so only the
18
+ // compiler's current manifest is synced back to disk.
19
+ it('wipes compiler-owned drizzle state before syncing fresh files', async () => {
20
+ const stateDir = await createTempDir();
21
+ await fs.mkdir(join(stateDir, 'drizzle', 'meta'), { recursive: true });
22
+ await fs.writeFile(join(stateDir, 'drizzle', '0000_stale.sql'), '-- stale');
23
+ await fs.writeFile(join(stateDir, 'drizzle', 'meta', '_journal.json'), '{"version":"7"}');
24
+ await prepareStateArtifacts(stateDir, [
25
+ { path: 'drizzle/0000_current.sql', content: '-- current' },
26
+ { path: 'drizzle/meta/_journal.json', content: '{"version":"7"}' },
27
+ ]);
28
+ expect(await fs.readdir(join(stateDir, 'drizzle')).catch(() => [])).toEqual([]);
29
+ });
30
+ });
31
+ //# sourceMappingURL=prepare-state-output.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepare-state-output.test.js","sourceRoot":"","sources":["../../src/lib/prepare-state-output.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAE5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE,MAAM,QAAQ,GAAa,EAAE,CAAC;AAE9B,KAAK,UAAU,aAAa;IAC1B,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,sBAAsB,CAAC,CAAC,CAAC;IACrE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,CAAC,KAAK,IAAI,EAAE;IACnB,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AACnG,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,qEAAqE;IACrE,2EAA2E;IAC3E,sDAAsD;IACtD,EAAE,CAAC,+DAA+D,EAAE,KAAK,IAAI,EAAE;QAC7E,MAAM,QAAQ,GAAG,MAAM,aAAa,EAAE,CAAC;QACvC,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACvE,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,gBAAgB,CAAC,EAAE,UAAU,CAAC,CAAC;QAC5E,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,iBAAiB,CAAC,CAAC;QAE1F,MAAM,qBAAqB,CAAC,QAAQ,EAAE;YACpC,EAAE,IAAI,EAAE,0BAA0B,EAAE,OAAO,EAAE,YAAY,EAAE;YAC3D,EAAE,IAAI,EAAE,4BAA4B,EAAE,OAAO,EAAE,iBAAiB,EAAE;SACnE,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAClF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -214,7 +214,7 @@ The path layout mirrors the public docs site (https://docs.quickback.dev). Open
214
214
  - `output` — `build.outputDir`, custom dependencies
215
215
  - `domains` — multi-domain hostname routing (CMS / account / admin)
216
216
  - `spa` — single-worker SPA mount (your product app at the apex)
217
- - `single-tenant` — disable organizations
217
+ - `single-tenant` — pinned organization mode and migration away from removed `organizations: false`
218
218
  - `agents` — robots.txt, llms.txt, MCP, OAuth discovery
219
219
 
220
220
  **Stack — runtime services** (`docs/stack/<topic>.md`)
@@ -1,5 +1,267 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.40.0 — June 2, 2026
4
+
5
+ R2 file storage is now **presign-only by default**. Adding
6
+ `defineFileStorage("cloudflare-r2")` emits just the `ctx.storage` signer — no
7
+ FILES_DB database, no `/storage/v1/*` endpoints, no files worker. You sign
8
+ presigned URLs against a bucket and store references in your own table. The
9
+ turnkey managed subsystem is still available, now behind `managed: true`.
10
+
11
+ This decouples the lightweight primitive from the heavyweight subsystem so you
12
+ can add uploads without standing up a metadata database you don't use.
13
+
14
+ ### Presign-only by default; managed is opt-in
15
+
16
+ ```ts
17
+ // Presign-only (default) — ctx.storage against a bucket, nothing else
18
+ defineFileStorage("cloudflare-r2", { bucketName: "my-app-media" })
19
+
20
+ // Managed subsystem — FILES_DB + /storage/v1/* + files worker
21
+ defineFileStorage("cloudflare-r2", { managed: true })
22
+ ```
23
+
24
+ - New projects can omit `bucketName` — it defaults to `<project>-media`, so
25
+ setup is one `wrangler r2 bucket create` plus the R2 API-token secrets.
26
+ - Existing projects set `bucketName` to a bucket they already have. Presign-only
27
+ emits **no** R2 bucket binding and **no** FILES_DB binding — nothing to
28
+ provision, nothing to migrate.
29
+
30
+ ### Per-call bucket + custom secret names
31
+
32
+ ```ts
33
+ // Sign against a different bucket than the configured default
34
+ await storage.signPutUrl(key, { bucket: "my-app-public", contentType });
35
+ ```
36
+
37
+ If your project already stores R2 credentials under different env-var names,
38
+ map them so the signer reads yours:
39
+
40
+ ```ts
41
+ defineFileStorage("cloudflare-r2", {
42
+ bucketName: "my-app-media",
43
+ presign: { accountIdEnv: "CF_ACCOUNT_ID", accessKeyIdEnv: "S3_KEY", secretAccessKeyEnv: "S3_SECRET" },
44
+ })
45
+ ```
46
+
47
+ ### Fixes
48
+
49
+ - `maxFileSize` now accepts a human string (`"100mb"`, `"5gb"`) as well as a
50
+ number of bytes — previously a string emitted invalid TypeScript.
51
+ - Presign-only no longer emits a stray `FILES_DB` `[[d1_databases]]` block (with
52
+ an invalid `database_id = "local-files"`) into `wrangler.toml`, which would
53
+ have made `wrangler deploy` reject the worker.
54
+
55
+ ## v0.39.1 — June 2, 2026
56
+
57
+ Deduplicate colliding OpenAPI `operationId`s. The auto-generated list id
58
+ `list<Resource>` collided when a user named an action `list<Resource>` (e.g.
59
+ `message_reactions` + an action `listMessageReactions`), producing a duplicate
60
+ operationId that failed OpenAPI validation and broke `api-types.gen.ts`. The
61
+ user's action keeps its id; the colliding auto-generated CRUD op is suffixed,
62
+ with a `[quickback:openapi]` warning per rename.
63
+
64
+ ## v0.39.0 — June 2, 2026
65
+
66
+ Media and large-binary uploads are now first-class. Instead of streaming file
67
+ bytes through your Worker — which hits the request-body cap and burns Worker
68
+ CPU/duration — an action mints a short-lived **presigned URL** and the client
69
+ uploads the bytes **directly to R2**. The Worker only signs; it never sits in
70
+ the data path. This is the supported way to author image/video/document upload
71
+ endpoints, and it survives every `quickback compile` with no generated-file
72
+ patching.
73
+
74
+ Requires R2 file storage (`defineFileStorage("cloudflare-r2", …)`).
75
+
76
+ ### `ctx.storage` — sign uploads from any action
77
+
78
+ When R2 file storage is configured, every `defineAction` execute receives a
79
+ typed `storage` signer. Your action runs all the usual security layers (auth,
80
+ roles, org/relationship scope), computes a tenant-scoped key, hands the client
81
+ an upload URL, and stores the key in **your own table** — no separate metadata
82
+ system required:
83
+
84
+ ```ts
85
+ export default defineAction({
86
+ path: "/event/:eventId/media/upload-file-binary",
87
+ method: "POST",
88
+ input: z.object({ filename: z.string(), contentType: z.string() }),
89
+ access: { roles: ["admin", "member", "scope:event:attendee"] },
90
+ async execute({ input, ctx, c, db, storage }) {
91
+ const eventId = c.req.param("eventId");
92
+ const key = `org/${ctx.activeOrgId}/event/${eventId}/${crypto.randomUUID()}-${input.filename}`;
93
+ const upload = await storage.signPutUrl(key, { contentType: input.contentType, expiresIn: 600 });
94
+ await db.insert(images).values({ key, eventId });
95
+ return { uploadUrl: upload.url, key, headers: upload.headers, expiresAt: upload.expiresAt };
96
+ },
97
+ });
98
+ ```
99
+
100
+ `storage` exposes `signPutUrl(key, { contentType?, expiresIn? })` (returns
101
+ `{ url, method, headers, key, expiresAt }`) and
102
+ `signGetUrl(key, { expiresIn?, downloadFilename? })` (returns a presigned GET
103
+ URL). Construction is zero-cost — actions that never touch `storage` pay
104
+ nothing.
105
+
106
+ ### Managed presign + confirm endpoints
107
+
108
+ For the zero-config path, the built-in storage API now exposes a presigned
109
+ upload alongside the existing through-Worker upload:
110
+
111
+ - `POST /storage/v1/presign/:bucket/*path` — runs the bucket's auth/role/scope
112
+ checks, validates the declared `contentType` + `size` against bucket limits,
113
+ records a pending object row, and returns `{ id, key, uploadUrl, method,
114
+ headers, expiresAt }`
115
+ - `POST /storage/v1/confirm/:bucket/*path` — reconciles the recorded size and
116
+ etag against what actually landed in R2 (`HEAD`)
117
+
118
+ ### Setup: R2 API token
119
+
120
+ Presigning uses R2's S3 API, which needs an **R2 API token** — the Workers R2
121
+ binding cannot presign on its own. Set three secrets:
122
+
123
+ ```bash
124
+ wrangler secret put R2_ACCOUNT_ID
125
+ wrangler secret put R2_ACCESS_KEY_ID
126
+ wrangler secret put R2_SECRET_ACCESS_KEY
127
+ ```
128
+
129
+ `aws4fetch` is added to the generated `package.json` automatically, and the R2
130
+ presign secrets are added to the generated `Env` type. If you pass `contentType`
131
+ to `signPutUrl`, the client must replay exactly that `Content-Type` header on
132
+ the `PUT`.
133
+
134
+ ### No raw-body action flag
135
+
136
+ Streaming a raw binary request body through an action is intentionally **not**
137
+ supported. Presigning delivers the same result — large files, no body cap —
138
+ without poking a hole in the body-parsing layer, so JSON actions and the ~1 MiB
139
+ JSON cap stay intact for every other route.
140
+
141
+ ### Storage routes hardened
142
+
143
+ Enabling R2 file storage previously exposed several latent type errors in the
144
+ generated `/storage/v1/*` routes (dead references from an old multipart
145
+ refactor, JSON-string role columns treated as arrays, a few undefined
146
+ variables). The full storage surface now type-checks cleanly when file storage
147
+ is configured.
148
+
149
+ ## v0.38.1 — May 26, 2026
150
+
151
+ Custom action handlers get the same typed ergonomics as generated CRUD paths:
152
+ typed Cloudflare bindings on `env`, a first-class typed `realtime` helper when
153
+ realtime is enabled, and no more `createRealtime(...)` boilerplate inside every
154
+ action just to emit an explicit broadcast.
155
+
156
+ ### Neon compile output and local recompile state are now stable
157
+
158
+ The Neon + Cloudflare path now emits a correct runtime/output surface instead
159
+ of leaking SQLite-era state.
160
+
161
+ - `wrangler.toml` no longer emits a stray `[[d1_databases]]` block for Neon
162
+ projects
163
+ - repeated local Neon compiles now upload and sync the root PostgreSQL Drizzle
164
+ state correctly, so `drizzle-kit` can report "No schema changes" instead of
165
+ regenerating duplicate `0000_*.sql` files
166
+ - stale root Drizzle migrations from earlier bad compiles are pruned during the
167
+ compile/sync path
168
+
169
+ ### Shared-target namespace hydration now works for bulk-grant lanes
170
+
171
+ Bulk-grant namespace callers (`{ roles: [...] }`, `{ team: true }`) now inherit
172
+ the namespace's shared hydration target when every relationship lane points at
173
+ the same resource load shape.
174
+
175
+ That fixes the case where a namespace like:
176
+
177
+ ```ts
178
+ via: ['attendeeOf', 'organizerOf', { roles: ['admin', 'owner'] }]
179
+ ```
180
+
181
+ would authorize an org admin through the bulk lane but leave `ctx.event`
182
+ undefined, even though the sibling relationship lanes all hydrated the same
183
+ `events` row.
184
+
185
+ Runtime behavior is now split cleanly:
186
+
187
+ - **Shared target** — if all hydrating lanes share the same `loads`,
188
+ `exposeAs`, and resource key, hydration runs unconditionally after the gate
189
+ passes, so bulk callers get the same `ctx.<exposeAs>` as relationship callers
190
+ - **Distinct targets** — if lanes hydrate different tables / keys / ctx slots,
191
+ hydration stays per-matched-lane to avoid cross-table false 404s
192
+
193
+ Standalone action typing now matches that runtime behavior too: shared-target
194
+ hydration remains non-optional, while distinct-target multi-lane hydration stays
195
+ optional.
196
+
197
+ ### Platform role split: `appmanager` for control-plane, `sysadmin` for cross-tenant
198
+
199
+ Quickback no longer treats `user.role === "admin"` as the platform-wide role.
200
+ The control-plane role is now `user.role === "appmanager"` (CMS shell, Better
201
+ Auth admin endpoints, support tooling), while `user.role === "sysadmin"`
202
+ remains the only true cross-tenant data-plane tier.
203
+
204
+ This also retires the `ADMIN` pseudo-role. Any `roles: ["ADMIN"]` usage now
205
+ fails the compile with migration guidance:
206
+
207
+ - `userRole: ["appmanager"]` for platform control-plane access
208
+ - `roles: ["admin"]` for org-membership admin access
209
+ - `roles: ["SYSADMIN"]` for true cross-tenant access
210
+
211
+ Runtime behavior now matches that split end-to-end:
212
+
213
+ - Better Auth's admin plugin is generated with `adminRoles: ["appmanager", "sysadmin"]`
214
+ - CMS / OpenAPI / auth-admin surfaces gate on `appmanager` (and admit
215
+ `sysadmin` where appropriate)
216
+ - unsafe cross-tenant actions and tenant-bypass helpers require `sysadmin` only
217
+
218
+ ### Typed `env` + injected `realtime` in action handlers
219
+
220
+ The generated `<feature>/.quickback/define-action.ts` helper now types action
221
+ `env` from the project's runtime bindings surface instead of `any`, so custom
222
+ bindings like R2 buckets, queues, Durable Objects, auth env vars, and split DB
223
+ bindings no longer need `(env as any)` casts inside action handlers.
224
+
225
+ When realtime is enabled in config, action handlers also receive a typed
226
+ `realtime` helper directly in `execute(...)`. It exposes the same
227
+ `insert/update/delete/broadcast` methods as `createRealtime(env)`, but without
228
+ the extra import or hand-rolled factory call in every custom action.
229
+
230
+ This is a DX-only change. The auto-broadcast boundary is unchanged: generated
231
+ CRUD routes still broadcast automatically, while custom action writes still
232
+ broadcast explicitly.
233
+
234
+ ### `generateId: "cuid"` docs now reflect the split runtime/schema behavior
235
+
236
+ Quickback's `cuid` strategy is now documented as the split path it actually is:
237
+ compiler-managed schema auto-injection keeps the `createId()` call site but may
238
+ back it with a file-local `crypto.randomUUID()` polyfill, while import-capable
239
+ runtime paths still emit real `createId()` usage.
240
+
241
+ That matters most for `compiler.injectId` and other schema-emission paths that
242
+ run in sandboxes where project `node_modules` are not visible. The generated
243
+ schema can safely keep:
244
+
245
+ ```ts
246
+ id: text("id").primaryKey().$defaultFn(() => createId())
247
+ ```
248
+
249
+ while satisfying the reference via:
250
+
251
+ ```ts
252
+ const createId = () => crypto.randomUUID();
253
+ ```
254
+
255
+ instead of importing `@paralleldrive/cuid2` inside the schema-generation
256
+ environment.
257
+
258
+ **Important nuance:** this is not a guarantee that every generated id is a true
259
+ cuid2 string. Auto-injected schema paths may produce UUID-shaped strings
260
+ through the polyfill, while runtime paths that can import helpers may still use
261
+ real `createId()`. If you need strict cuid2 shape everywhere, explicitly import
262
+ `createId` from `@paralleldrive/cuid2` in the authored schema file; the
263
+ compiler preserves that import and skips the polyfill.
264
+
3
265
  ## v0.38.0 — May 26, 2026
4
266
 
5
267
  **Per-matched-lane authorization** for multi-lane namespaces — across both the
@@ -70,7 +70,7 @@ Every operation in your generated OpenAPI spec becomes one MCP tool. The tool na
70
70
  `tools/list` only returns tools the calling identity could actually invoke. Each generated tool entry carries the operation's access metadata (`roles`, `userRole`, `or` / `and` combinators) and `tools/list` filters against `ctx` before responding:
71
71
 
72
72
  - **Unauthenticated callers** see only tools whose access declares the `PUBLIC` pseudo-role, or operations that have no security requirement at all (e.g. sign-in / sign-up).
73
- - **Authenticated callers** see tools whose role gate intersects their `ctx.roles` or `ctx.userRole`. Admin-only endpoints don't appear for non-admins.
73
+ - **Authenticated callers** see tools whose role gate intersects their `ctx.roles` or `ctx.userRole`. Platform-operator endpoints don't appear for callers outside the required user roles.
74
74
  - **Function-form access** (escape hatch) is opaque at list time — surfaced to any authenticated caller, then evaluated for real on `tools/call`.
75
75
  - **Record predicates** are dropped from the list-time check (no record yet) and applied normally on the actual call.
76
76
 
@@ -125,7 +125,7 @@ export default defineConfig({
125
125
  Both fields override compiler-emitted browser redirects in the CMS shell:
126
126
 
127
127
  - **Unauthenticated visitor hits a CMS route** → `302 → <loginUrl>?redirect=<original-url>`
128
- - **Authenticated user fails the `cms.access: 'admin'` role check** → `302 → <profileUrl>`
128
+ - **Authenticated user fails the `cms.access: 'admin'` platform-role check** → `302 → <profileUrl>`
129
129
 
130
130
  The `?redirect=…` query param is preserved unchanged so the central sign-in surface can bounce the user back after authentication.
131
131
 
@@ -8,7 +8,6 @@ import { defineConfig, defineRuntime, defineDatabase, defineAuth } from "@quickb
8
8
  export default defineConfig({
9
9
  name: "my-app",
10
10
  template: "hono",
11
- features: { organizations: true },
12
11
  providers: {
13
12
  runtime: defineRuntime("cloudflare"),
14
13
  database: defineDatabase("cloudflare-d1"),
@@ -87,7 +86,7 @@ quickback compile --no-sync-config
87
86
 
88
87
  | Field | Type | Description |
89
88
  |-------|------|-------------|
90
- | `features` | `object` | Feature flags — see [Single-Tenant Mode](/compiler/config/single-tenant) |
89
+ | `features` | `object` | Feature flags such as `pinnedOrganizationId` — see [Pinned Organization Mode](/compiler/config/single-tenant) |
91
90
  | `build` | `object` | Build options (`outputDir`, `packageManager`, `dependencies`) |
92
91
  | `compiler` | `object` | Compiler options — `features.auditFields: false` disables audit field injection project-wide; `migrations.renames` provides rename hints for headless CI; `securityContracts` tunes the route/SQL invariants checker |
93
92
  | `openapi` | `object` | OpenAPI spec generation (`generate`, `publish`, `docs: 'scalar' \| 'swagger'` for an in-browser API reference) — see [OpenAPI](/compiler/targets/hono-api/using-the-api/openapi) |
@@ -304,8 +303,8 @@ cms: { domain: "cms.example.com", sysadmin: true },
304
303
  | Option | Type | Default | Description |
305
304
  |--------|------|---------|-------------|
306
305
  | `domain` | `string` | — | Custom domain for CMS. Adds a `custom_domain` route to `wrangler.toml`. |
307
- | `access` | `"user" \| "admin"` | `"user"` | Controls who can access the CMS. When `"admin"`, only users with `user.role === "admin"` can enter — enforced at the Worker level (SPA shell, `/api/v1/schema`, and `custom_view` CRUD all return 403 to non-admins) and in the SPA. Also hides the CMS link in Account UI. See [CMS Connecting](/stack/cms/connecting) for the full enforcement model. |
308
- | `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 `"admin"`. Off by default. See [`SYSADMIN` pseudo-role](/compiler/definitions/access#sysadmin--cross-tenant-db-admin-tier). |
306
+ | `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](/stack/cms/connecting) for the full enforcement model. |
307
+ | `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](/compiler/definitions/access#sysadmin--cross-tenant-db-admin-tier). |
309
308
 
310
309
  ### Sysadmin tier (`cms.sysadmin: true`)
311
310
 
@@ -313,11 +312,11 @@ Quickback's default model assumes every CMS user belongs to at least one organiz
313
312
 
314
313
  `cms: { sysadmin: true }` introduces a separate role tier:
315
314
 
316
- - **Role**: `user.role === "sysadmin"` (set on the Better Auth user table). Distinct from `"admin"` — admins keep org-scoped CMS access via the membership switcher; sysadmins get cross-tenant. The two roles are independent at the pseudo-role evaluator level: `ADMIN` admits `'admin'` only, `SYSADMIN` admits `'sysadmin'` only. Routes that need both write `access: { roles: ['ADMIN', 'SYSADMIN'] }` explicitly.
315
+ - **Role**: `user.role === "sysadmin"` (set on the Better Auth user table). Distinct from `"appmanager"` — appmanagers keep platform control-plane access (CMS shell, Better Auth admin surfaces, support tooling), while sysadmins get true cross-tenant data access. `ADMIN` is now a rejected legacy pseudo-role; use `userRole: ["appmanager"]` for control-plane gates and `roles: ["SYSADMIN"]` for cross-tenant access.
317
316
  - **Firewall**: every `buildFirewallConditions()` emits an `if (ctx.userRole === "sysadmin") return undefined` (or just the soft-delete predicate when present) at the top, so sysadmins see every tenant's rows. See [Firewall escape hatch](/compiler/definitions/firewall#sysadmin-escape-hatch).
318
317
  - **Org listing**: a `GET /auth/v1/admin/list-organizations` endpoint selects directly from the auth-schema `organization` table — every row, every tenant. Sits under Better Auth's admin URL namespace (sibling of `/auth/v1/admin/list-users`) so the URL shape matches BA convention; the handler is Quickback-emitted and gated to `user.role === "sysadmin"` only. For the membership-bound caller's-orgs listing, use BA's own `/auth/v1/organization/list`.
319
318
  - **CMS SPA**: when the user is a sysadmin, the header switcher loads from the cross-tenant endpoint, defaults to "All organizations" (which omits `?organizationId=` and reaches the firewall escape), and pins selected tenants via `?organizationId=` on every API call. Org admins keep the existing membership-based switcher.
320
- - **CMS HTML gate**: admits `userRole === "sysadmin"` alongside `"admin"`. Org admins are not locked out — both roles can enter the CMS in `cms.access: "admin"` mode.
319
+ - **CMS HTML gate**: admits `userRole === "sysadmin"` alongside `"appmanager"`. Org admins are not locked out when you set `cms.access: "user"`; `cms.access: "admin"` is specifically the platform control-plane gate.
321
320
 
322
321
  Off by default. Projects that don't enable it get zero behavior change; setting `cms.sysadmin: true` and granting a user `user.role = "sysadmin"` is the only way to unlock the cross-tenant view.
323
322
 
@@ -369,8 +368,8 @@ Control which authentication features are exposed. Disabled features are exclude
369
368
  | `auth.emailOTP` | `boolean` | `false` | adds `emailOtp` plugin | Email one-time password login — adds plugin server-side, surfaces UI |
370
369
  | `auth.passkey` | `boolean` | `false` | adds `passkey` plugin | WebAuthn/FIDO2 passkey authentication — adds plugin server-side, surfaces UI |
371
370
  | `auth.signup` | `boolean` | `true` | `emailAndPassword.disableSignUp` (inverted) | Self-service account registration — false hides the UI **and** rejects the server endpoint with 403 |
372
- | `auth.organizations` | `boolean` | `false` | UI surface only — server gating lives under `features.organizations` | Multi-tenant organization management UI (dashboard, invitations, roles). The BA `organization` plugin is auto-added by `features.organizations` for server-side reasons (org tables) independent of this UI flag |
373
- | `auth.admin` | `boolean` | `false` | UI surface only — BA `admin` plugin is auto-added when `features.organizations` is on | Admin panel for user management in the Account SPA |
371
+ | `auth.organizations` | `boolean` | `true` | UI surface only | Organization management UI (dashboard, invitations, roles). Server-side organization support stays on regardless; set `features.pinnedOrganizationId` when you want one fixed org with no switching UI |
372
+ | `auth.admin` | `boolean` | `false` | UI surface only | Admin panel for user management in the Account SPA. The Better Auth admin plugin is compiler-managed separately from this UI toggle |
374
373
  | `auth.emailVerification` | `boolean` | `false` | `emailAndPassword.requireEmailVerification` | Require email verification before sessions are issued. False = sessions usable immediately after signup |
375
374
 
376
375
  ## Trusted Origins
@@ -506,5 +505,5 @@ See the sub-pages for detailed reference on each section:
506
505
  - [Providers](/compiler/config/providers) — Runtime, database, and auth options
507
506
  - [Variables](/compiler/config/variables) — Environment variables and flags
508
507
  - [Output](/compiler/config/output) — Generated file structure
509
- - [Single-Tenant Mode](/compiler/config/single-tenant) — Admin-only and public-facing apps without organizations
508
+ - [Pinned Organization Mode](/compiler/config/single-tenant) — Fixed-org deployments without org switching UI
510
509
  - [Multi-Domain Architecture](/compiler/config/domains) — Custom domains, hostname routing, and cross-subdomain auth
@@ -226,6 +226,9 @@ See [Realtime](/stack/realtime) for the client-side connection flow and helper e
226
226
  > `"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.
227
227
 
228
228
 
229
+ > `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.
230
+
231
+
229
232
  ## Auth Providers
230
233
 
231
234
  | Provider | Description |
@@ -1,10 +1,12 @@
1
- # Single-Tenant Mode
1
+ # Pinned Organization Mode
2
2
 
3
- Single-tenant mode disables the Better Auth organization plugin, removing the `organizationId` requirement from your API. This is ideal for personal sites, blogs, admin panels, or any app with a single tenant.
3
+ Single-tenant mode has been removed. If you want a one-org deployment without org switching overhead, use `features.pinnedOrganizationId` instead.
4
4
 
5
- ## Enabling Single-Tenant Mode
5
+ Pinned organization mode keeps Better Auth's organization plugin, organization membership roles, and org-scoped firewalls enabled. The only difference is that Quickback hard-codes one active organization id at runtime and hides the switching UI.
6
6
 
7
- Set `features.organizations` to `false` in your config:
7
+ ## Enabling Pinned Organization Mode
8
+
9
+ Set a real organization id in your config:
8
10
 
9
11
  ```typescript
10
12
  import { defineConfig, defineRuntime, defineDatabase, defineAuth } from "@quickback/compiler";
@@ -13,7 +15,7 @@ export default defineConfig({
13
15
  name: "my-site",
14
16
  template: "hono",
15
17
  features: {
16
- organizations: false,
18
+ pinnedOrganizationId: "org_123",
17
19
  },
18
20
  providers: {
19
21
  runtime: defineRuntime("cloudflare"),
@@ -23,100 +25,90 @@ export default defineConfig({
23
25
  });
24
26
  ```
25
27
 
26
- ## What Changes
28
+ > **Use a Real Organization ID**
29
+ >
30
+ > `pinnedOrganizationId` must point at an organization that actually exists in your Better Auth data. The compiler does not create the organization for you.
27
31
 
28
- | Aspect | Multi-Tenant (default) | Single-Tenant |
29
- |--------|----------------------|---------------|
30
- | Organization plugin | Enabled | Disabled |
31
- | `organizationId` columns | Required on resources | Not used |
32
- | Role source | Org membership table | `user.role` field |
33
- | Firewall scopes | `owner`, `organization`, `team`, `exception` | `owner`, `exception` only |
34
- | Admin org endpoints | Use Better Auth's `/auth/v1/organization/list` (caller's orgs) and `/auth/v1/admin/list-organizations` when `cms.sysadmin: true` (cross-tenant) | N/A (no org plugin) |
35
- | `ctx.activeOrgId` | From session/JWT | Always `undefined` |
36
- | `ctx.roles` | From org member role | From `user.role` |
37
32
 
38
- ## Firewall Configuration
33
+ ## Removed Single-Tenant Settings
39
34
 
40
- In single-tenant mode, resources use either **owner** scope (user-scoped data) or **exception** (public/system data):
35
+ These older settings now fail the compile with a migration error:
41
36
 
42
- ```typescript
43
- // User-scoped data (requires authentication)
44
- export default defineTable(posts, {
45
- firewall: [{ field: 'ownerId', equals: 'ctx.userId' }],
46
- read: {
47
- access: { roles: ['user', 'admin'] },
48
- },
49
- create: { access: { roles: ['admin'] } },
50
- });
37
+ - `features.organizations: false`
38
+ - `providers.database.config.organizations: false`
39
+ - `providers.auth.config.plugins.organization = false`
51
40
 
52
- // Public data (no ownership filtering)
53
- export default defineTable(pages, {
54
- firewall: [{ exception: true }],
55
- read: {
56
- access: { roles: ['PUBLIC'] },
57
- },
58
- create: { access: { roles: ['admin'] } },
59
- update: { access: { roles: ['admin'] } },
60
- delete: { access: { roles: ['admin'] } },
61
- });
62
- ```
41
+ Replace them with `features.pinnedOrganizationId`.
42
+
43
+ ## What Changes
63
44
 
64
- > Using `q.scope('organization')` / `q.scope('team')` (or any firewall predicate referencing `ctx.activeOrgId` / `ctx.activeTeamId`) with `organizations: false` will cause a compile error. These scopes require the organization plugin.
45
+ | Aspect | Default Org Mode | Pinned Organization Mode |
46
+ |--------|------------------|--------------------------|
47
+ | Organization plugin | Enabled | Enabled |
48
+ | Role source | Org membership table | Org membership table in the pinned org |
49
+ | Firewall scopes | `owner`, `organization`, `team`, `exception` | Same |
50
+ | `ctx.activeOrgId` | From session / JWT / API key context | Always the configured org id |
51
+ | CMS org selector | Visible when caller can switch orgs | Hidden |
52
+ | CMS org gate | Requires an active org selection | Bypassed; pinned org is injected automatically |
65
53
 
54
+ ## Access and Roles
66
55
 
67
- ## Public Routes
56
+ Pinned organization mode does **not** bring back the old `user.role` mirror on `ctx.roles`.
68
57
 
69
- Use the `PUBLIC` role to expose routes without authentication. This works the same as in multi-tenant mode:
58
+ - Use `roles: ["owner" | "admin" | "member"]` for data-plane access based on membership in the pinned org.
59
+ - Use `userRole: [...]` for platform-wide Better Auth roles stored on `user.role` (`appmanager`, `sysadmin`, etc.).
70
60
 
71
61
  ```typescript
72
- read: {
73
- access: { roles: ['PUBLIC'] }, // GET / and GET /:id — no auth required
74
- },
75
- create: { access: { roles: ['admin'] } }, // Admin only
62
+ export default defineActions({
63
+ publish: {
64
+ access: {
65
+ or: [
66
+ { roles: ["admin"] }, // admin in the pinned org
67
+ { userRole: ["appmanager"] }, // platform control-plane role
68
+ ],
69
+ },
70
+ execute: async () => ({ ok: true }),
71
+ },
72
+ });
76
73
  ```
77
74
 
78
- ## Role-Based Access
75
+ ## Firewalls and Resource Scopes
79
76
 
80
- Roles come from the `user.role` field (managed by Better Auth's [admin plugin](https://www.better-auth.com/docs/plugins/admin)).
77
+ Organization-scoped resources keep working in pinned mode. `q.scope("organization")`, `q.scope("team")`, and any firewall predicate that references `ctx.activeOrgId` still compile and run normally — they just see the pinned organization id instead of a user-selected one.
81
78
 
82
- > In single-tenant mode `ctx.roles` mirrors `user.role`, so `roles: ["admin"]` and `userRole: ["admin"]` behave the same. Prefer [`userRole`](/compiler/definitions/access#userrole-vs-roles) — it documents intent and keeps the gate correct if you later enable multi-tenant.
79
+ Owner-scoped and public resources are unchanged.
83
80
 
81
+ ## CMS Behavior
84
82
 
83
+ When `features.pinnedOrganizationId` is set:
85
84
 
86
- | Role | Description |
87
- |------|-------------|
88
- | `admin` | Full access, set via Better Auth admin plugin |
89
- | `user` | Default role for authenticated users |
90
- | `PUBLIC` | Unauthenticated access (special keyword) |
85
+ - the CMS hides the org switcher
86
+ - the CMS skips the org-selection gate
87
+ - API calls and realtime connections use the pinned org automatically
88
+ - role checks still come from the caller's membership in that org
91
89
 
92
- ```typescript
93
- // Admin-only action
94
- export default defineActions({
95
- publish: {
96
- access: { roles: ['admin'] },
97
- execute: async ({ ctx, db }) => {
98
- // ctx.userRole === 'admin'
99
- // ctx.roles === ['admin']
100
- },
101
- },
102
- });
103
- ```
90
+ This is the intended replacement for the old single-tenant CMS flow.
91
+
92
+ ## Migration from Single-Tenant Mode
93
+
94
+ 1. Remove `features.organizations: false`.
95
+ 2. Add `features.pinnedOrganizationId: "<real-org-id>"`.
96
+ 3. Remove any assumptions that `ctx.roles` mirrors `user.role`.
97
+ 4. If you need platform-wide roles, keep those checks on `userRole`, not `roles`.
104
98
 
105
99
  ## Consuming the API
106
100
 
107
- Since single-tenant mode produces a JSON API, pair it with any frontend framework:
101
+ Pinned organization mode still produces the same JSON API shape. Pair it with any frontend framework:
108
102
 
109
103
  ```typescript
110
- // Astro, Next.js, SvelteKit, etc.
111
- const posts = await fetch('https://api.mysite.com/api/v1/posts').then(r => r.json());
104
+ const posts = await fetch("https://api.mysite.com/api/v1/posts").then((r) => r.json());
112
105
 
113
- // Admin operations require authentication
114
- const res = await fetch('https://api.mysite.com/api/v1/posts', {
115
- method: 'POST',
106
+ const res = await fetch("https://api.mysite.com/api/v1/posts", {
107
+ method: "POST",
116
108
  headers: {
117
- 'Authorization': `Bearer ${token}`,
118
- 'Content-Type': 'application/json',
109
+ Authorization: `Bearer ${token}`,
110
+ "Content-Type": "application/json",
119
111
  },
120
- body: JSON.stringify({ title: 'New Post', content: '...' }),
112
+ body: JSON.stringify({ title: "New Post", content: "..." }),
121
113
  });
122
114
  ```