@quickback-dev/cli 0.72.2 → 0.72.3

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.
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@
10
10
  */
11
11
  import pc from "picocolors";
12
12
  // Version injected at build time by scripts/inject-version.ts
13
- const CLI_VERSION = "0.72.2";
13
+ const CLI_VERSION = "0.72.3";
14
14
  function getPackageVersion() {
15
15
  return CLI_VERSION;
16
16
  }
@@ -303,6 +303,70 @@ throw new ActionError("Not enough balance", "INSUFFICIENT_FUNDS", 400, { availab
303
303
 
304
304
  Constructor: `(message, code, statusCode = 400, details?)`. Do **NOT** throw Hono's `HTTPException` — it isn't unwrapped and surfaces as a 500 `ACTION_EXECUTION_FAILED`. Returning `c.json({...}, 400)` directly also works (the executor receives `c`).
305
305
 
306
+ ## Custom CMS pages (`definePage`)
307
+
308
+ Reach for a custom page before building a separate admin app. The CMS gives every table a list and record view. When the job is *working across two tables* (reconciling, matching, assigning, triaging), one `definePage()` file gives the operator a split-panel screen with drag-and-drop, scored match suggestions, and a button that runs a real action. You write no UI code.
309
+
310
+ Good fits: bank transactions ↔ ledger entries, applicants ↔ open roles, support tickets ↔ agents, imported rows ↔ existing records, invoices ↔ payments.
311
+
312
+ ```ts
313
+ // quickback/features/banking/pages/bank-reconciliation.ts
314
+ import { definePage } from "@quickback/compiler";
315
+
316
+ export default definePage({
317
+ slug: "bank-reconciliation", // lowercase, digits, hyphens
318
+ title: "Bank Reconciliation",
319
+ feature: "banking",
320
+ access: { roles: ["owner", "admin"] },
321
+ dataSources: {
322
+ bank: { table: "bankTransaction", defaultFilters: { status: "pending" }, displayColumns: ["date", "description", "amount"] },
323
+ ledger: { table: "ledgerEntry", defaultSort: { field: "date", order: "desc" }, displayColumns: ["date", "memo", "amount"] },
324
+ },
325
+ layout: {
326
+ type: "split-panel",
327
+ panels: [
328
+ { id: "bank", title: "Bank", dataSource: "bank", position: "left", features: ["drag-source"] },
329
+ { id: "ledger", title: "Ledger", dataSource: "ledger", position: "right", features: ["drop-target"] },
330
+ ],
331
+ },
332
+ matching: {
333
+ enabled: true,
334
+ confidenceThreshold: 0.5,
335
+ rules: [
336
+ { name: "Amount", weight: 0.5, condition: { left: "bank.amount", right: "ledger.amount", operator: "abs-equals" } },
337
+ { name: "Date", weight: 0.3, condition: { left: "bank.date", right: "ledger.date", operator: "within-days", value: 7 } },
338
+ { name: "Memo", weight: 0.2, condition: { left: "bank.description", right: "ledger.memo", operator: "fuzzy-match" } },
339
+ ],
340
+ },
341
+ pageActions: {
342
+ reconcile: {
343
+ table: "bankTransaction", action: "reconcile", label: "Reconcile",
344
+ confirm: "Match this transaction to the selected entry?",
345
+ inputMapping: { transactionId: "bank.$id", ledgerEntryId: "ledger.$id" },
346
+ },
347
+ },
348
+ });
349
+ ```
350
+
351
+ How to craft one:
352
+
353
+ 1. **Write the action first.** A page only *calls* actions; it never writes data itself. Define `actions/reconcile.ts` on the target table, with its own `access`, guards, and input schema, then map page fields into its input with `inputMapping` (`"<dataSource>.$<field>"`; `$id` is the record id). Dropping a row from the drag-source panel onto a row in the drop-target panel opens the first page action's dialog, with both records as context.
354
+ 2. **Narrow each panel.** `defaultFilters` (e.g. `status: "pending"`) keeps the panels to the work still to do, and `displayColumns` keeps them readable (the default is just `id`).
355
+ 3. **Weight the match rules to sum to 1.** Each weight and `confidenceThreshold` must be within 0–1. Operators: `abs-equals` (amounts with opposite signs), `within-days` (`value` = max days, default 7), `fuzzy-match` (word overlap). The score is the weighted average; suggestions below the threshold are hidden.
356
+ 4. **`access.roles` on a page only controls who sees it** (it's checked in the browser). Panels read through each table's normal list endpoint, and buttons call each action's endpoint, so the tables' Firewall/Access/Masking rules still decide what data comes back and what can change. Never rely on page `access` to hide data.
357
+
358
+ One page per file in `features/<feature>/pages/`; the compiler validates slugs, data-source references and weights at compile time. Only `split-panel` exists as a layout today. Details: `quickback docs ui/admin/pages`.
359
+
360
+ ## Clients that stay fast on slow networks
361
+
362
+ Each round trip costs ~150 ms on a slow phone connection. When you build or change the client that calls the API, count the requests it makes before the first useful paint:
363
+
364
+ - **One request per screen.** A screen that needs more than two lists gets a `defineBundle`, not several list calls (`quickback docs define/bundles`). Never fetch records one at a time in a loop from the client. Use `?include=` for parents, and a filtered list for children.
365
+ - **Start fetches in the route, not the component.** Fetch in the router's `loader` (TanStack Router: `loader: () => queryClient.ensureQueryData(...)`), so the request starts during navigation instead of after the component mounts. Set `defaultPreload: 'intent'` so hovering or focusing a link starts its code and data early.
366
+ - **Run independent awaits in parallel.** In actions and hooks, start unrelated lookups together with `Promise.all([...])`. Two sequential `await`s that don't depend on each other add a full round trip each time.
367
+ - **Link previews read only the HTML.** iMessage, Slack, and similar bots never run JavaScript. A prebuilt `apps.<name>` SPA must put its `<title>` and `og:*` meta tags in `index.html` itself.
368
+ - **Don't trust the User-Agent for routing.** Anyone can fake it, and it also matches Lighthouse. If bots really must get a different response, use Cloudflare's verified-bot signal: `request.cf.botManagement.verifiedBot` on Bot Management plans, or the `cf.client.bot` field in a WAF rule.
369
+
306
370
  ## Reaching auth tables (org members, users)
307
371
 
308
372
  The scoped feature `db` never includes Better Auth tables — that is by design.
@@ -97,9 +97,11 @@ interface ReadConfig {
97
97
  // and the HYPERDRIVE_CACHED binding. See Neon → Cached public reads.
98
98
  cache?: "hyperdrive";
99
99
 
100
- // Pagination defaults for collection reads.
101
- pageSize?: number; // Default page size (default: 50)
102
- maxPageSize?: number; // Hard cap (default: 100)
100
+ // Pagination for the collection GET and every view (one setting per
101
+ // resource). `?limit=` above maxPageSize is clamped to it; OpenAPI
102
+ // documents both. A pageSize above 100 raises the cap with it.
103
+ pageSize?: number; // Default `limit` (default: 50)
104
+ maxPageSize?: number; // Hard cap on `limit` (default: 100)
103
105
 
104
106
  // Named field projections. Each view has its own access and field list.
105
107
  views?: {
@@ -114,8 +116,8 @@ interface ReadConfig {
114
116
  interface ViewConfig {
115
117
  fields: string[]; // Columns returned by this view
116
118
  access?: Access; // Per-view access (falls back to read.access)
117
- pageSize?: number;
118
- maxPageSize?: number;
119
+ // No per-view pagination: read.pageSize / read.maxPageSize apply to every
120
+ // view, and a view-level copy is a compile error.
119
121
  }
120
122
  ```
121
123
 
@@ -99,7 +99,11 @@ before the stale-claim takeover, so a foreign caller can neither read nor
99
99
  overwrite your claim.
100
100
 
101
101
  **Unauthenticated requests carrying the header are rejected (400)** — an
102
- anonymous caller has no principal to bind the claim to. A PUBLIC standalone
102
+ anonymous caller has no principal to bind the claim to. Better Auth's own
103
+ routes (`/auth/v1/*` and `/cli/*`) are the exception: Better Auth
104
+ authenticates them itself, so the header is ignored there rather than
105
+ rejected, and a client can attach it to every write. The operator endpoints
106
+ mounted under the auth prefix still honor it. A PUBLIC standalone
103
107
  action may opt in explicitly:
104
108
 
105
109
  ```ts title="quickback/features/orders/actions/submitForm.ts"
@@ -878,6 +878,15 @@ for stub errors:
878
878
  | `Subrequest depth limit exceeded` | Not retried; logged as `durable_object.failed` |
879
879
  | anything else | Not retried; logged as `durable_object.failed` |
880
880
 
881
+ Every call into the Broadcaster (the publish including its one retry, the
882
+ live-view `seq` read, and in separate-Worker mode the service-binding fetch)
883
+ also races a **5-second deadline**. A stalled Broadcaster therefore costs the
884
+ emitting request at most 5 seconds, not the client's whole timeout, even
885
+ though the write has already committed. An expired call is logged like any other
886
+ failed publish (`durable_object.failed` for the inline stub), and the tenant
887
+ outbox treats it as retryable. If the
888
+ first attempt lands late, the publish id dedupes it.
889
+
881
890
  Every send carries one **publish id**, and a retry reuses it. The Broadcaster
882
891
  remembers its 64 most recent ids. When a retry arrives for a first attempt that
883
892
  actually landed (only the reply was lost), it is acknowledged without a second
@@ -120,7 +120,7 @@ export default defineConfig({
120
120
  ```
121
121
 
122
122
  When you run `quickback build`, the CLI:
123
- 1. Builds the CMS SPA from source and places assets in `src/apps/cms/`
123
+ 1. Copies the prebuilt CMS SPA into `src/apps/cms/` (the compiler ships one generic bundle; per-project settings reach it at serve time)
124
124
  2. Adds `[assets]` config to `wrangler.toml` with `run_worker_first = true`
125
125
  3. Generates Worker routing to serve the CMS SPA
126
126
 
@@ -139,8 +139,8 @@ This adds a custom domain route to `wrangler.toml`. Both `api.example.com` and `
139
139
  CMS access defaults to `access: "sysadmin"` — only `user.role === "sysadmin"` (the cross-tenant data-plane tier) can use `/cms/*`. Set `access: "member"` to also admit anyone holding an organization membership. `user.role === "appmanager"` opens the CMS in neither mode: it is the control-plane tier and belongs at `/account/admin`. The gate is enforced at multiple layers:
140
140
 
141
141
  - **Account UI** hides the "Go to CMS" button for callers outside those roles.
142
- - **CMS SPA shell** — the Worker returns `403` (or redirects unauthenticated requests to login) before serving `index.html` to a non-operator. A non-operator who types the CMS URL directly cannot load the app.
143
- - **`/api/v1/schema`** returns `403 Platform operator access required` to callers outside those roles, so schema metadata can't be scraped by hitting the API directly.
142
+ - **CMS SPA shell** — the Worker redirects unauthenticated requests to login. Sign-in is the only shell-level gate; the app itself is a generic bundle. For a caller `/api/v1/schema` would admit, the Worker also inlines the schema registry in the shell as a non-executing `<script type="application/json" id="__qb-cms-bootstrap">` block, so the CMS starts without fetching it. The block uses the same admission check as `/api/v1/schema`, so it never carries anything that route would refuse. With [Cloudflare Access](/configure/cloudflare-access), it is inlined only when `/api/v1/schema` needs no Access application or the same one the shell request passed. The CMS shell is served `Cache-Control: private, no-store`.
143
+ - **`/api/v1/schema`** returns `401 AUTH_MISSING` to anonymous callers `403 CMS_ACCESS_DENIED` (naming the role required) to signed-in callers outside those roles, and `403 MFA_REQUIRED` to an operator whose session lacks the second factor `auth.operatorMfa` demands, so schema metadata can't be scraped by hitting the API directly.
144
144
  - **`custom_view` routes** are gated on `userRole: ["appmanager"]` rather than org membership, so saved views can't be listed or modified without platform-control-plane rights.
145
145
  - **In-SPA screen** — a signed-in caller who isn't admitted is served the shell and shown a screen naming what they'd need. There is no wrong-role redirect.
146
146
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quickback-dev/cli",
3
- "version": "0.72.2",
3
+ "version": "0.72.3",
4
4
  "description": "CLI for Quickback — define your backend in TypeScript, compile to a fully wired Cloudflare Worker (or Bun / Node) with auth, database, migrations, security, CMS, and Account UI.",
5
5
  "author": "Kardoe Incorporated <paul@kardoe.com>",
6
6
  "license": "MIT",
@@ -303,6 +303,70 @@ throw new ActionError("Not enough balance", "INSUFFICIENT_FUNDS", 400, { availab
303
303
 
304
304
  Constructor: `(message, code, statusCode = 400, details?)`. Do **NOT** throw Hono's `HTTPException` — it isn't unwrapped and surfaces as a 500 `ACTION_EXECUTION_FAILED`. Returning `c.json({...}, 400)` directly also works (the executor receives `c`).
305
305
 
306
+ ## Custom CMS pages (`definePage`)
307
+
308
+ Reach for a custom page before building a separate admin app. The CMS gives every table a list and record view. When the job is *working across two tables* (reconciling, matching, assigning, triaging), one `definePage()` file gives the operator a split-panel screen with drag-and-drop, scored match suggestions, and a button that runs a real action. You write no UI code.
309
+
310
+ Good fits: bank transactions ↔ ledger entries, applicants ↔ open roles, support tickets ↔ agents, imported rows ↔ existing records, invoices ↔ payments.
311
+
312
+ ```ts
313
+ // quickback/features/banking/pages/bank-reconciliation.ts
314
+ import { definePage } from "@quickback/compiler";
315
+
316
+ export default definePage({
317
+ slug: "bank-reconciliation", // lowercase, digits, hyphens
318
+ title: "Bank Reconciliation",
319
+ feature: "banking",
320
+ access: { roles: ["owner", "admin"] },
321
+ dataSources: {
322
+ bank: { table: "bankTransaction", defaultFilters: { status: "pending" }, displayColumns: ["date", "description", "amount"] },
323
+ ledger: { table: "ledgerEntry", defaultSort: { field: "date", order: "desc" }, displayColumns: ["date", "memo", "amount"] },
324
+ },
325
+ layout: {
326
+ type: "split-panel",
327
+ panels: [
328
+ { id: "bank", title: "Bank", dataSource: "bank", position: "left", features: ["drag-source"] },
329
+ { id: "ledger", title: "Ledger", dataSource: "ledger", position: "right", features: ["drop-target"] },
330
+ ],
331
+ },
332
+ matching: {
333
+ enabled: true,
334
+ confidenceThreshold: 0.5,
335
+ rules: [
336
+ { name: "Amount", weight: 0.5, condition: { left: "bank.amount", right: "ledger.amount", operator: "abs-equals" } },
337
+ { name: "Date", weight: 0.3, condition: { left: "bank.date", right: "ledger.date", operator: "within-days", value: 7 } },
338
+ { name: "Memo", weight: 0.2, condition: { left: "bank.description", right: "ledger.memo", operator: "fuzzy-match" } },
339
+ ],
340
+ },
341
+ pageActions: {
342
+ reconcile: {
343
+ table: "bankTransaction", action: "reconcile", label: "Reconcile",
344
+ confirm: "Match this transaction to the selected entry?",
345
+ inputMapping: { transactionId: "bank.$id", ledgerEntryId: "ledger.$id" },
346
+ },
347
+ },
348
+ });
349
+ ```
350
+
351
+ How to craft one:
352
+
353
+ 1. **Write the action first.** A page only *calls* actions; it never writes data itself. Define `actions/reconcile.ts` on the target table, with its own `access`, guards, and input schema, then map page fields into its input with `inputMapping` (`"<dataSource>.$<field>"`; `$id` is the record id). Dropping a row from the drag-source panel onto a row in the drop-target panel opens the first page action's dialog, with both records as context.
354
+ 2. **Narrow each panel.** `defaultFilters` (e.g. `status: "pending"`) keeps the panels to the work still to do, and `displayColumns` keeps them readable (the default is just `id`).
355
+ 3. **Weight the match rules to sum to 1.** Each weight and `confidenceThreshold` must be within 0–1. Operators: `abs-equals` (amounts with opposite signs), `within-days` (`value` = max days, default 7), `fuzzy-match` (word overlap). The score is the weighted average; suggestions below the threshold are hidden.
356
+ 4. **`access.roles` on a page only controls who sees it** (it's checked in the browser). Panels read through each table's normal list endpoint, and buttons call each action's endpoint, so the tables' Firewall/Access/Masking rules still decide what data comes back and what can change. Never rely on page `access` to hide data.
357
+
358
+ One page per file in `features/<feature>/pages/`; the compiler validates slugs, data-source references and weights at compile time. Only `split-panel` exists as a layout today. Details: `quickback docs ui/admin/pages`.
359
+
360
+ ## Clients that stay fast on slow networks
361
+
362
+ Each round trip costs ~150 ms on a slow phone connection. When you build or change the client that calls the API, count the requests it makes before the first useful paint:
363
+
364
+ - **One request per screen.** A screen that needs more than two lists gets a `defineBundle`, not several list calls (`quickback docs define/bundles`). Never fetch records one at a time in a loop from the client. Use `?include=` for parents, and a filtered list for children.
365
+ - **Start fetches in the route, not the component.** Fetch in the router's `loader` (TanStack Router: `loader: () => queryClient.ensureQueryData(...)`), so the request starts during navigation instead of after the component mounts. Set `defaultPreload: 'intent'` so hovering or focusing a link starts its code and data early.
366
+ - **Run independent awaits in parallel.** In actions and hooks, start unrelated lookups together with `Promise.all([...])`. Two sequential `await`s that don't depend on each other add a full round trip each time.
367
+ - **Link previews read only the HTML.** iMessage, Slack, and similar bots never run JavaScript. A prebuilt `apps.<name>` SPA must put its `<title>` and `og:*` meta tags in `index.html` itself.
368
+ - **Don't trust the User-Agent for routing.** Anyone can fake it, and it also matches Lighthouse. If bots really must get a different response, use Cloudflare's verified-bot signal: `request.cf.botManagement.verifiedBot` on Bot Management plans, or the `cf.client.bot` field in a WAF rule.
369
+
306
370
  ## Reaching auth tables (org members, users)
307
371
 
308
372
  The scoped feature `db` never includes Better Auth tables — that is by design.
@@ -97,9 +97,11 @@ interface ReadConfig {
97
97
  // and the HYPERDRIVE_CACHED binding. See Neon → Cached public reads.
98
98
  cache?: "hyperdrive";
99
99
 
100
- // Pagination defaults for collection reads.
101
- pageSize?: number; // Default page size (default: 50)
102
- maxPageSize?: number; // Hard cap (default: 100)
100
+ // Pagination for the collection GET and every view (one setting per
101
+ // resource). `?limit=` above maxPageSize is clamped to it; OpenAPI
102
+ // documents both. A pageSize above 100 raises the cap with it.
103
+ pageSize?: number; // Default `limit` (default: 50)
104
+ maxPageSize?: number; // Hard cap on `limit` (default: 100)
103
105
 
104
106
  // Named field projections. Each view has its own access and field list.
105
107
  views?: {
@@ -114,8 +116,8 @@ interface ReadConfig {
114
116
  interface ViewConfig {
115
117
  fields: string[]; // Columns returned by this view
116
118
  access?: Access; // Per-view access (falls back to read.access)
117
- pageSize?: number;
118
- maxPageSize?: number;
119
+ // No per-view pagination: read.pageSize / read.maxPageSize apply to every
120
+ // view, and a view-level copy is a compile error.
119
121
  }
120
122
  ```
121
123
 
@@ -99,7 +99,11 @@ before the stale-claim takeover, so a foreign caller can neither read nor
99
99
  overwrite your claim.
100
100
 
101
101
  **Unauthenticated requests carrying the header are rejected (400)** — an
102
- anonymous caller has no principal to bind the claim to. A PUBLIC standalone
102
+ anonymous caller has no principal to bind the claim to. Better Auth's own
103
+ routes (`/auth/v1/*` and `/cli/*`) are the exception: Better Auth
104
+ authenticates them itself, so the header is ignored there rather than
105
+ rejected, and a client can attach it to every write. The operator endpoints
106
+ mounted under the auth prefix still honor it. A PUBLIC standalone
103
107
  action may opt in explicitly:
104
108
 
105
109
  ```ts title="quickback/features/orders/actions/submitForm.ts"
@@ -878,6 +878,15 @@ for stub errors:
878
878
  | `Subrequest depth limit exceeded` | Not retried; logged as `durable_object.failed` |
879
879
  | anything else | Not retried; logged as `durable_object.failed` |
880
880
 
881
+ Every call into the Broadcaster (the publish including its one retry, the
882
+ live-view `seq` read, and in separate-Worker mode the service-binding fetch)
883
+ also races a **5-second deadline**. A stalled Broadcaster therefore costs the
884
+ emitting request at most 5 seconds, not the client's whole timeout, even
885
+ though the write has already committed. An expired call is logged like any other
886
+ failed publish (`durable_object.failed` for the inline stub), and the tenant
887
+ outbox treats it as retryable. If the
888
+ first attempt lands late, the publish id dedupes it.
889
+
881
890
  Every send carries one **publish id**, and a retry reuses it. The Broadcaster
882
891
  remembers its 64 most recent ids. When a retry arrives for a first attempt that
883
892
  actually landed (only the reply was lost), it is acknowledged without a second
@@ -120,7 +120,7 @@ export default defineConfig({
120
120
  ```
121
121
 
122
122
  When you run `quickback build`, the CLI:
123
- 1. Builds the CMS SPA from source and places assets in `src/apps/cms/`
123
+ 1. Copies the prebuilt CMS SPA into `src/apps/cms/` (the compiler ships one generic bundle; per-project settings reach it at serve time)
124
124
  2. Adds `[assets]` config to `wrangler.toml` with `run_worker_first = true`
125
125
  3. Generates Worker routing to serve the CMS SPA
126
126
 
@@ -139,8 +139,8 @@ This adds a custom domain route to `wrangler.toml`. Both `api.example.com` and `
139
139
  CMS access defaults to `access: "sysadmin"` — only `user.role === "sysadmin"` (the cross-tenant data-plane tier) can use `/cms/*`. Set `access: "member"` to also admit anyone holding an organization membership. `user.role === "appmanager"` opens the CMS in neither mode: it is the control-plane tier and belongs at `/account/admin`. The gate is enforced at multiple layers:
140
140
 
141
141
  - **Account UI** hides the "Go to CMS" button for callers outside those roles.
142
- - **CMS SPA shell** — the Worker returns `403` (or redirects unauthenticated requests to login) before serving `index.html` to a non-operator. A non-operator who types the CMS URL directly cannot load the app.
143
- - **`/api/v1/schema`** returns `403 Platform operator access required` to callers outside those roles, so schema metadata can't be scraped by hitting the API directly.
142
+ - **CMS SPA shell** — the Worker redirects unauthenticated requests to login. Sign-in is the only shell-level gate; the app itself is a generic bundle. For a caller `/api/v1/schema` would admit, the Worker also inlines the schema registry in the shell as a non-executing `<script type="application/json" id="__qb-cms-bootstrap">` block, so the CMS starts without fetching it. The block uses the same admission check as `/api/v1/schema`, so it never carries anything that route would refuse. With [Cloudflare Access](/configure/cloudflare-access), it is inlined only when `/api/v1/schema` needs no Access application or the same one the shell request passed. The CMS shell is served `Cache-Control: private, no-store`.
143
+ - **`/api/v1/schema`** returns `401 AUTH_MISSING` to anonymous callers `403 CMS_ACCESS_DENIED` (naming the role required) to signed-in callers outside those roles, and `403 MFA_REQUIRED` to an operator whose session lacks the second factor `auth.operatorMfa` demands, so schema metadata can't be scraped by hitting the API directly.
144
144
  - **`custom_view` routes** are gated on `userRole: ["appmanager"]` rather than org membership, so saved views can't be listed or modified without platform-control-plane rights.
145
145
  - **In-SPA screen** — a signed-in caller who isn't admitted is served the shell and shown a screen naming what they'd need. There is no wrong-role redirect.
146
146