@quickback-dev/cli 0.65.1 → 0.66.1
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/commands/compile.d.ts +1 -1
- package/dist/commands/compile.d.ts.map +1 -1
- package/dist/commands/compile.js +13 -0
- package/dist/commands/compile.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/action-harvest.d.ts.map +1 -1
- package/dist/lib/action-harvest.js +14 -6
- package/dist/lib/action-harvest.js.map +1 -1
- package/dist/lib/action-harvest.test.js +26 -0
- package/dist/lib/action-harvest.test.js.map +1 -1
- package/dist/lib/migrations/drizzle.d.ts.map +1 -1
- package/dist/lib/migrations/drizzle.js +6 -1
- package/dist/lib/migrations/drizzle.js.map +1 -1
- package/dist/lib/migrations/drizzle.test.js +3 -0
- package/dist/lib/migrations/drizzle.test.js.map +1 -1
- package/dist/lib/wrangler-resources.d.ts.map +1 -1
- package/dist/lib/wrangler-resources.js +5 -2
- package/dist/lib/wrangler-resources.js.map +1 -1
- package/dist/lib/wrangler-resources.test.js +6 -0
- package/dist/lib/wrangler-resources.test.js.map +1 -1
- package/dist/skill/SKILL.md +18 -3
- package/dist/skill/docs/api/batch-operations.md +1 -1
- package/dist/skill/docs/api/crud.md +1 -1
- package/dist/skill/docs/api/index.md +1 -1
- package/dist/skill/docs/api/query-params.md +5 -8
- package/dist/skill/docs/changelog/index.md +87 -1
- package/dist/skill/docs/configure/auth.md +20 -12
- package/dist/skill/docs/configure/domains.md +1 -1
- package/dist/skill/docs/configure/index.md +19 -29
- package/dist/skill/docs/configure/providers.md +6 -4
- package/dist/skill/docs/configure/single-tenant.md +7 -3
- package/dist/skill/docs/define/access.md +3 -0
- package/dist/skill/docs/define/actions/defining.md +2 -2
- package/dist/skill/docs/define/actions/index.md +1 -1
- package/dist/skill/docs/define/actions/record-and-standalone.md +1 -1
- package/dist/skill/docs/define/actions/scoped-db.md +23 -6
- package/dist/skill/docs/define/changesets.md +7 -8
- package/dist/skill/docs/define/feature.md +3 -2
- package/dist/skill/docs/define/firewall.md +2 -0
- package/dist/skill/docs/define/index.md +1 -1
- package/dist/skill/docs/define/read.md +2 -2
- package/dist/skill/docs/define/relationships.md +7 -0
- package/dist/skill/docs/define/schema.md +21 -1
- package/dist/skill/docs/define/triggers.md +14 -3
- package/dist/skill/docs/platform/api-contract/index.md +52 -42
- package/dist/skill/docs/platform/auth/api-keys.md +1 -1
- package/dist/skill/docs/platform/auth/jwt-optimization.md +1 -1
- package/dist/skill/docs/platform/database/d1.md +13 -1
- package/dist/skill/docs/platform/database/neon.md +1 -1
- package/dist/skill/docs/platform/realtime/durable-objects.md +69 -36
- package/dist/skill/docs/platform/realtime/index.md +8 -10
- package/dist/skill/docs/platform/realtime/named-invalidations.md +23 -9
- package/dist/skill/docs/platform/realtime/using-realtime.md +62 -36
- package/dist/skill/docs/platform/webhooks/outbound.md +4 -5
- package/dist/skill/docs/start/deploy-browser.md +2 -2
- package/dist/skill/docs/start/deploy-owner-access.md +49 -50
- package/dist/skill/docs/start/deploy.md +2 -2
- package/dist/skill/docs/start/first-api.md +1 -1
- package/dist/skill/docs/start/patterns.md +17 -2
- package/dist/skill/docs/start/template-cloudflare.md +1 -1
- package/dist/skill/docs/tooling/cli.md +1 -1
- package/dist/skill/docs/tooling/cloud-compiler/authentication.md +1 -1
- package/dist/skill/docs/tooling/cloud-compiler/troubleshooting.md +28 -0
- package/dist/skill/docs/tooling/output.md +1 -1
- package/dist/skill/docs/ui/account/customization.md +1 -1
- package/dist/skill/docs/ui/account/features/api-keys.md +10 -8
- package/dist/skill/docs/ui/account/features/index.md +7 -6
- package/dist/skill/docs/ui/account/features/organizations.md +1 -1
- package/dist/skill/docs/ui/account/hooks.md +2 -1
- package/dist/skill/docs/ui/account/index.md +7 -4
- package/dist/skill/docs/ui/account/with-quickback.md +1 -1
- package/package.json +1 -1
- package/src/skill/SKILL.md +18 -3
- package/src/skill/docs/api/batch-operations.md +1 -1
- package/src/skill/docs/api/crud.md +1 -1
- package/src/skill/docs/api/index.md +1 -1
- package/src/skill/docs/api/query-params.md +5 -8
- package/src/skill/docs/changelog/index.md +87 -1
- package/src/skill/docs/configure/auth.md +20 -12
- package/src/skill/docs/configure/domains.md +1 -1
- package/src/skill/docs/configure/index.md +19 -29
- package/src/skill/docs/configure/providers.md +6 -4
- package/src/skill/docs/configure/single-tenant.md +7 -3
- package/src/skill/docs/define/access.md +3 -0
- package/src/skill/docs/define/actions/defining.md +2 -2
- package/src/skill/docs/define/actions/index.md +1 -1
- package/src/skill/docs/define/actions/record-and-standalone.md +1 -1
- package/src/skill/docs/define/actions/scoped-db.md +23 -6
- package/src/skill/docs/define/changesets.md +7 -8
- package/src/skill/docs/define/feature.md +3 -2
- package/src/skill/docs/define/firewall.md +2 -0
- package/src/skill/docs/define/index.md +1 -1
- package/src/skill/docs/define/read.md +2 -2
- package/src/skill/docs/define/relationships.md +7 -0
- package/src/skill/docs/define/schema.md +21 -1
- package/src/skill/docs/define/triggers.md +14 -3
- package/src/skill/docs/platform/api-contract/index.md +52 -42
- package/src/skill/docs/platform/auth/api-keys.md +1 -1
- package/src/skill/docs/platform/auth/jwt-optimization.md +1 -1
- package/src/skill/docs/platform/database/d1.md +13 -1
- package/src/skill/docs/platform/database/neon.md +1 -1
- package/src/skill/docs/platform/realtime/durable-objects.md +69 -36
- package/src/skill/docs/platform/realtime/index.md +8 -10
- package/src/skill/docs/platform/realtime/named-invalidations.md +23 -9
- package/src/skill/docs/platform/realtime/using-realtime.md +62 -36
- package/src/skill/docs/platform/webhooks/outbound.md +4 -5
- package/src/skill/docs/start/deploy-browser.md +2 -2
- package/src/skill/docs/start/deploy-owner-access.md +49 -50
- package/src/skill/docs/start/deploy.md +2 -2
- package/src/skill/docs/start/first-api.md +1 -1
- package/src/skill/docs/start/patterns.md +17 -2
- package/src/skill/docs/start/template-cloudflare.md +1 -1
- package/src/skill/docs/tooling/cli.md +1 -1
- package/src/skill/docs/tooling/cloud-compiler/authentication.md +1 -1
- package/src/skill/docs/tooling/cloud-compiler/troubleshooting.md +28 -0
- package/src/skill/docs/tooling/output.md +1 -1
- package/src/skill/docs/ui/account/customization.md +1 -1
- package/src/skill/docs/ui/account/features/api-keys.md +10 -8
- package/src/skill/docs/ui/account/features/index.md +7 -6
- package/src/skill/docs/ui/account/features/organizations.md +1 -1
- package/src/skill/docs/ui/account/hooks.md +2 -1
- package/src/skill/docs/ui/account/index.md +7 -4
- package/src/skill/docs/ui/account/with-quickback.md +1 -1
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
# API Contract
|
|
2
2
|
|
|
3
|
-
Every generated API speaks one public HTTP contract
|
|
3
|
+
Every generated API speaks **one** public HTTP contract. There is no version to
|
|
4
|
+
select: the behavior on this page is what every project gets.
|
|
5
|
+
|
|
6
|
+
The only contract choice is the URL prefix, and it defaults to `/api/v1` so
|
|
7
|
+
existing clients keep the address they already call:
|
|
4
8
|
|
|
5
9
|
```ts title="quickback/quickback.config.ts"
|
|
6
10
|
export default defineConfig({
|
|
7
|
-
|
|
8
|
-
contract: { version: "v2" },
|
|
11
|
+
contract: { routes: "v2" }, // optional — serve on /api/v2 instead
|
|
9
12
|
// ...
|
|
10
13
|
});
|
|
11
14
|
```
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
receives no new contract features until it migrates. Your URLs are a separate
|
|
16
|
-
choice — see [below](#two-axes-semantics-and-routes).
|
|
16
|
+
`contract.version` is retired and pinning it is a compile error — see
|
|
17
|
+
[below](#contractversion-is-retired).
|
|
17
18
|
|
|
18
19
|
## Response envelope
|
|
19
20
|
|
|
@@ -29,8 +30,8 @@ object itself:
|
|
|
29
30
|
}
|
|
30
31
|
```
|
|
31
32
|
|
|
32
|
-
`included` appears only when the request carried `?include=`
|
|
33
|
-
|
|
33
|
+
`included` appears only when the request carried `?include=` — see
|
|
34
|
+
[query params](/api/query-params).
|
|
34
35
|
|
|
35
36
|
## Errors — RFC 9457 Problem Details
|
|
36
37
|
|
|
@@ -112,59 +113,68 @@ export default defineAction({
|
|
|
112
113
|
});
|
|
113
114
|
```
|
|
114
115
|
|
|
115
|
-
##
|
|
116
|
+
## One axis: routes
|
|
116
117
|
|
|
117
|
-
`contract` has
|
|
118
|
-
mistake:
|
|
118
|
+
`contract` has a single key. It selects the URL prefix and nothing else.
|
|
119
119
|
|
|
120
120
|
| Key | Controls | Default |
|
|
121
121
|
|---|---|---|
|
|
122
|
-
| `version` | Semantics — framing, strictness, the auth lane | `'v2'` |
|
|
123
122
|
| `routes` | The URL prefix, and nothing else | `'v1'` |
|
|
124
123
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
does not change your semantics.
|
|
124
|
+
A project with no `contract` block serves `/api/v1`. Set `routes: "v2"` to
|
|
125
|
+
serve `/api/v2` instead — the behavior is identical either way.
|
|
128
126
|
|
|
129
127
|
{/* doc-compile: skip — config fragment, not a compilable project */}
|
|
130
128
|
```typescript
|
|
131
|
-
contract: {
|
|
132
|
-
contract: { routes: "v2" } // serve on /api/v2, keep v1 semantics
|
|
133
|
-
contract: { version: "v2", routes: "v2" } // both — the pre-v0.64.0 "v2"
|
|
129
|
+
contract: { routes: "v2" } // serve on /api/v2 instead of /api/v1
|
|
134
130
|
```
|
|
135
131
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
132
|
+
### `contract.version` is retired
|
|
133
|
+
|
|
134
|
+
There is one standard API shape, so there is nothing to select. Pinning
|
|
135
|
+
`contract.version` is a compile error.
|
|
139
136
|
|
|
140
|
-
**
|
|
141
|
-
|
|
142
|
-
key is the only pin.
|
|
137
|
+
**Delete that one line and keep `routes` if you have it.** `routes` is the
|
|
138
|
+
surviving axis and controls your URLs — removing it would move them.
|
|
143
139
|
|
|
144
|
-
|
|
140
|
+
{/* doc-compile: skip — config fragment, not a compilable project */}
|
|
141
|
+
```typescript
|
|
142
|
+
contract: { version: "v2", routes: "v1" } // before
|
|
143
|
+
contract: { routes: "v1" } // after — same URLs, same behavior
|
|
144
|
+
```
|
|
145
145
|
|
|
146
|
-
`version`
|
|
147
|
-
|
|
146
|
+
Deleting `version: "v2"` changes nothing: it selected what is now simply the
|
|
147
|
+
standard shape. Deleting `version: "v1"` is a real migration — that pin opted
|
|
148
|
+
out of four behaviors that are now unconditional:
|
|
148
149
|
|
|
149
|
-
| Surface | v1
|
|
150
|
+
| Surface | What `version: "v1"` did | What you get now |
|
|
150
151
|
|---|---|---|
|
|
151
|
-
| API base | `/api/v1` | `/api/v2` |
|
|
152
|
-
| Auth base | `/auth/v1` | `/auth/v2` |
|
|
153
|
-
| Realtime base | `/broadcast/v1` | `/broadcast/v2` |
|
|
154
152
|
| Quickback HMAC-JWT lane | on by default | only with explicit `auth.jwt` |
|
|
155
153
|
| Realtime data frames | raw (byte-stable) | CloudEvents 1.0 envelopes ([realtime](/platform/realtime)) |
|
|
156
154
|
| Outbound webhook signing | Standard Webhooks **+** legacy `X-Webhook-*` | Standard Webhooks **only** |
|
|
157
|
-
| `?include=` FK embedding | not available | available where allowlisted |
|
|
158
|
-
| Aggregate changesets (`application/vnd.quickback.changeset+json` on PATCH/POST, [`owns`](/define/changesets)) | not available | available where `owns` is declared |
|
|
159
155
|
| Bare `?fields=` unknown names | silently dropped | **400** |
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
156
|
+
|
|
157
|
+
Features that a v1 pin refused are now always available: `?include=` FK
|
|
158
|
+
embedding where allowlisted, aggregate changesets on PATCH/POST where
|
|
159
|
+
[`owns`](/define/changesets) is declared, `fields[<fk>]=` projection (unknown
|
|
160
|
+
names **400**), `auth.principals`, and `atomicAuthRoutes: 'emailOtpSignIn'`.
|
|
161
|
+
|
|
162
|
+
Migrating off a v1 pin: ship subscribers that parse CloudEvents frames, move
|
|
163
|
+
webhook consumers onto the `webhook-*` headers, and either adopt session-first
|
|
164
|
+
auth or declare `auth.jwt`.
|
|
165
|
+
|
|
166
|
+
**Pinning your CLI version does not pin behavior.** The compiler is a hosted
|
|
167
|
+
service, so an older CLI gets the same output.
|
|
168
|
+
|
|
169
|
+
### Base paths
|
|
170
|
+
|
|
171
|
+
`routes` moves all three together:
|
|
172
|
+
|
|
173
|
+
| Surface | `routes: "v1"` (default) | `routes: "v2"` |
|
|
174
|
+
|---|---|---|
|
|
175
|
+
| API base | `/api/v1` | `/api/v2` |
|
|
176
|
+
| Auth base | `/auth/v1` | `/auth/v2` |
|
|
177
|
+
| Realtime base | `/broadcast/v1` | `/broadcast/v2` |
|
|
168
178
|
|
|
169
179
|
## Machine-readable contract
|
|
170
180
|
|
|
@@ -4,7 +4,7 @@ API keys provide programmatic access for CI/CD pipelines, scripts, and server-to
|
|
|
4
4
|
|
|
5
5
|
## Creating API Keys
|
|
6
6
|
|
|
7
|
-
Create API keys from
|
|
7
|
+
Create API keys from [Account UI](/ui/account/features/api-keys) (`/api-keys`, linked from profile). Each key is owned by you and scoped to an organization.
|
|
8
8
|
|
|
9
9
|
## Usage
|
|
10
10
|
|
|
@@ -51,7 +51,7 @@ auth: {
|
|
|
51
51
|
|
|
52
52
|
> **This surface is opt-in by default**
|
|
53
53
|
>
|
|
54
|
-
>
|
|
54
|
+
> The custom JWT surface is emitted only when `auth.jwt` is present. Omit it and the generated output has no token endpoint and no JWT fast-path — cookie and signed session-token bearer auth still work. A project that declares `authz.scopes` does **not** need `auth.jwt`: it gets scope-token admission on its own, without the token endpoint or the identity fast-path. Declaring `auth.jwt` is what opts into the full credential lane. See [Auth & JWT config](/configure/auth).
|
|
55
55
|
>
|
|
56
56
|
> `src/lib/jwt.ts` is still emitted when the project declares [`authz.scopes`](/define/scopes): scope tokens are signed JWTs, so the helper is required for minting and verifying them even with no credential lane.
|
|
57
57
|
|
|
@@ -22,7 +22,7 @@ Quickback generates separate D1 databases for different concerns:
|
|
|
22
22
|
|
|
23
23
|
| Database | Binding | Purpose |
|
|
24
24
|
|----------|---------|---------|
|
|
25
|
-
| `AUTH_DB` | `AUTH_DB` | Better Auth tables (user
|
|
25
|
+
| `AUTH_DB` | `AUTH_DB` | Better Auth tables (`user`, `session`, `account`, `organization`, `member`) |
|
|
26
26
|
| `DB` | `DB` | Your application data |
|
|
27
27
|
| `FILES_DB` | `FILES_DB` | File metadata for R2 uploads |
|
|
28
28
|
| `WEBHOOKS_DB` | `WEBHOOKS_DB` | Webhook delivery tracking |
|
|
@@ -32,6 +32,18 @@ This separation provides:
|
|
|
32
32
|
- **Isolation** - Auth schema changes don't touch your data
|
|
33
33
|
- **Clarity** - Clear ownership of each database
|
|
34
34
|
|
|
35
|
+
SQLite foreign keys cannot cross those databases. Feature columns must never
|
|
36
|
+
`.references()` Better Auth tables (`user` / `users` / `organization` /
|
|
37
|
+
`member`). Store a Better Auth id as plain text (`userId: q.text().required()`).
|
|
38
|
+
A `.references(() => users.id)` on a feature table makes deploy fail with
|
|
39
|
+
`Critical command failed: Generate features database migrations`. See
|
|
40
|
+
[Schema → References](/define/schema).
|
|
41
|
+
|
|
42
|
+
The scoped feature `db` never includes those tables — query them from an
|
|
43
|
+
action with `c.get("authDb")`, not from a trigger. On D1 the membership table
|
|
44
|
+
is `member`, not `organization_membership`. See
|
|
45
|
+
[Scoped DB](/define/actions/scoped-db#reaching-better-auth-tables-authdb).
|
|
46
|
+
|
|
35
47
|
## Drizzle ORM Integration
|
|
36
48
|
|
|
37
49
|
Quickback uses [Drizzle ORM](https://orm.drizzle.team/) for type-safe database access:
|
|
@@ -504,7 +504,7 @@ with neither a stamped user id nor a delegated principal) and a `service_role`
|
|
|
504
504
|
policy (admits Worker-internal contexts — see
|
|
505
505
|
[Background jobs and cross-tenant actions](#background-jobs-and-cross-tenant-actions)).
|
|
506
506
|
|
|
507
|
-
### Delegated principal RLS
|
|
507
|
+
### Delegated principal RLS
|
|
508
508
|
|
|
509
509
|
Delegated principals require Cloudflare + Neon Hyperdrive. Their proof hook
|
|
510
510
|
returns only a digest and receives no database handle. Quickback then runs one
|
|
@@ -212,16 +212,20 @@ await realtime.insert('applications', {
|
|
|
212
212
|
Broadcasts:
|
|
213
213
|
```json
|
|
214
214
|
{
|
|
215
|
-
"
|
|
216
|
-
"
|
|
217
|
-
"
|
|
218
|
-
"
|
|
219
|
-
"
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
215
|
+
"specversion": "1.0",
|
|
216
|
+
"id": "evt_…",
|
|
217
|
+
"source": "/broadcast/v1/websocket",
|
|
218
|
+
"type": "dev.quickback.myapp.applications.insert",
|
|
219
|
+
"time": "2026-08-17T10:04:11.921Z",
|
|
220
|
+
"datacontenttype": "application/json",
|
|
221
|
+
"qbframe": "postgres_changes",
|
|
222
|
+
"data": {
|
|
223
|
+
"table": "applications",
|
|
224
|
+
"schema": "public",
|
|
225
|
+
"eventType": "INSERT",
|
|
226
|
+
"new": { "id": "app_123", "candidateId": "cnd_456", "stage": "applied" },
|
|
227
|
+
"old": null
|
|
228
|
+
}
|
|
225
229
|
}
|
|
226
230
|
```
|
|
227
231
|
|
|
@@ -238,12 +242,20 @@ await realtime.update('applications',
|
|
|
238
242
|
Broadcasts:
|
|
239
243
|
```json
|
|
240
244
|
{
|
|
241
|
-
"
|
|
242
|
-
"
|
|
243
|
-
"
|
|
244
|
-
"
|
|
245
|
-
"
|
|
246
|
-
"
|
|
245
|
+
"specversion": "1.0",
|
|
246
|
+
"id": "evt_…",
|
|
247
|
+
"source": "/broadcast/v1/websocket",
|
|
248
|
+
"type": "dev.quickback.myapp.applications.update",
|
|
249
|
+
"time": "2026-08-17T10:04:11.921Z",
|
|
250
|
+
"datacontenttype": "application/json",
|
|
251
|
+
"qbframe": "postgres_changes",
|
|
252
|
+
"data": {
|
|
253
|
+
"table": "applications",
|
|
254
|
+
"schema": "public",
|
|
255
|
+
"eventType": "UPDATE",
|
|
256
|
+
"new": { "id": "app_123", "stage": "interview" },
|
|
257
|
+
"old": { "id": "app_123", "stage": "screening" }
|
|
258
|
+
}
|
|
247
259
|
}
|
|
248
260
|
```
|
|
249
261
|
|
|
@@ -259,12 +271,20 @@ await realtime.delete('applications',
|
|
|
259
271
|
Broadcasts:
|
|
260
272
|
```json
|
|
261
273
|
{
|
|
262
|
-
"
|
|
263
|
-
"
|
|
264
|
-
"
|
|
265
|
-
"
|
|
266
|
-
"
|
|
267
|
-
"
|
|
274
|
+
"specversion": "1.0",
|
|
275
|
+
"id": "evt_…",
|
|
276
|
+
"source": "/broadcast/v1/websocket",
|
|
277
|
+
"type": "dev.quickback.myapp.applications.delete",
|
|
278
|
+
"time": "2026-08-17T10:04:11.921Z",
|
|
279
|
+
"datacontenttype": "application/json",
|
|
280
|
+
"qbframe": "postgres_changes",
|
|
281
|
+
"data": {
|
|
282
|
+
"table": "applications",
|
|
283
|
+
"schema": "public",
|
|
284
|
+
"eventType": "DELETE",
|
|
285
|
+
"new": null,
|
|
286
|
+
"old": { "id": "app_123" }
|
|
287
|
+
}
|
|
268
288
|
}
|
|
269
289
|
```
|
|
270
290
|
|
|
@@ -290,9 +310,14 @@ subscriber) or `['PUBLIC']`.
|
|
|
290
310
|
Broadcasts:
|
|
291
311
|
```json
|
|
292
312
|
{
|
|
293
|
-
"
|
|
294
|
-
"
|
|
295
|
-
"
|
|
313
|
+
"specversion": "1.0",
|
|
314
|
+
"id": "evt_…",
|
|
315
|
+
"source": "/broadcast/v1/websocket",
|
|
316
|
+
"type": "screening-complete",
|
|
317
|
+
"time": "2026-08-17T10:04:11.921Z",
|
|
318
|
+
"datacontenttype": "application/json",
|
|
319
|
+
"qbframe": "broadcast",
|
|
320
|
+
"data": {
|
|
296
321
|
"applicationId": "app_123",
|
|
297
322
|
"candidateId": "cnd_456",
|
|
298
323
|
"stage": "interview"
|
|
@@ -545,13 +570,16 @@ Tickets expire after 60 seconds, so fetch a fresh one before each connection or
|
|
|
545
570
|
|
|
546
571
|
### Handling Messages
|
|
547
572
|
|
|
573
|
+
Data frames are [CloudEvents 1.0 envelopes](/platform/realtime/using-realtime#cloudevents-envelopes).
|
|
574
|
+
Discriminate on `qbframe`, never on `type`, and read the body from `data`:
|
|
575
|
+
|
|
548
576
|
```typescript
|
|
549
577
|
ws.onmessage = (event) => {
|
|
550
578
|
const msg = JSON.parse(event.data);
|
|
551
579
|
|
|
552
580
|
// Handle CRUD events
|
|
553
|
-
if (msg.
|
|
554
|
-
const { table, eventType, new: newRecord, old: oldRecord } = msg;
|
|
581
|
+
if (msg.qbframe === 'postgres_changes') {
|
|
582
|
+
const { table, eventType, new: newRecord, old: oldRecord } = msg.data;
|
|
555
583
|
|
|
556
584
|
if (eventType === 'INSERT') {
|
|
557
585
|
addRecord(table, newRecord);
|
|
@@ -562,9 +590,10 @@ ws.onmessage = (event) => {
|
|
|
562
590
|
}
|
|
563
591
|
}
|
|
564
592
|
|
|
565
|
-
// Handle custom broadcasts
|
|
566
|
-
if (msg.
|
|
567
|
-
const
|
|
593
|
+
// Handle custom broadcasts — `type` is your wire name verbatim.
|
|
594
|
+
if (msg.qbframe === 'broadcast') {
|
|
595
|
+
const event = msg.type;
|
|
596
|
+
const payload = msg.data;
|
|
568
597
|
|
|
569
598
|
if (event === 'screening-complete') {
|
|
570
599
|
refreshApplication(payload.applicationId);
|
|
@@ -715,15 +744,19 @@ export const execute: ActionExecutor = async ({ ctx, input }) => {
|
|
|
715
744
|
|
|
716
745
|
### Event Format
|
|
717
746
|
|
|
718
|
-
Custom namespace events
|
|
747
|
+
Custom namespace events carry `qbframe: "broadcast"`; the namespaced event
|
|
748
|
+
name is the CloudEvents `type`, verbatim:
|
|
719
749
|
|
|
720
750
|
```json
|
|
721
751
|
{
|
|
722
|
-
"
|
|
723
|
-
"
|
|
724
|
-
"
|
|
725
|
-
|
|
726
|
-
|
|
752
|
+
"specversion": "1.0",
|
|
753
|
+
"id": "evt_…",
|
|
754
|
+
"source": "/broadcast/v1/websocket",
|
|
755
|
+
"type": "screening:started",
|
|
756
|
+
"time": "2026-08-17T10:04:11.921Z",
|
|
757
|
+
"datacontenttype": "application/json",
|
|
758
|
+
"qbframe": "broadcast",
|
|
759
|
+
"data": { "applicationId": "app_123" }
|
|
727
760
|
}
|
|
728
761
|
```
|
|
729
762
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Quickback ships **two parallel realtime primitives**, both backed by Cloudflare Durable Objects:
|
|
4
4
|
|
|
5
|
-
- **`/broadcast/v1/*` — server fan-out.** One DO instance per subscription scope. Postgres-changes events from CRUD routes plus custom broadcast events flow out to every subscriber, with role filtering and per-role field masking applied. Best for "tell every client in this shared scope that something changed." The scope can be an organization, a specific user, or a compiler-resolved resource key like `events:evt_123`. The `/broadcast/v1` version segment tracks `contract.routes` — set it to `"v2"` and the same surface mounts at `/broadcast/v2` (no hidden v1 alias).
|
|
5
|
+
- **`/broadcast/v1/*` — server fan-out.** One DO instance per subscription scope. Postgres-changes events from CRUD routes plus custom broadcast events flow out to every subscriber, with role filtering and per-role field masking applied. Best for "tell every client in this shared scope that something changed." The scope can be an organization, a specific user, or a compiler-resolved resource key like `events:evt_123`. The `/broadcast/v1` version segment tracks `contract.routes` — set it to `"v2"` and the same surface mounts at `/broadcast/v2` (no hidden v1 alias). Framing is independent of the path: frames are [CloudEvents 1.0](/platform/realtime/using-realtime#cloudevents-envelopes) envelopes regardless of which prefix you serve them on. Documented on this page. For **typed, targeted "this changed — refresh" signals** fired from an action after commit (with optional per-recipient narrowing), see [Named invalidations](/platform/realtime/named-invalidations).
|
|
6
6
|
- **`/realtime/<binding>/<room-id>` — bidirectional rooms.** One DO instance per room (per document, per interview, per game). Client↔client messages, presence, and CRDT-friendly state. Use these for collaborative editing. See [PartyServer rooms](/platform/realtime/partyserver-rooms).
|
|
7
7
|
|
|
8
8
|
Both share the same auth model and ride on the same compiled worker; they solve different problems.
|
|
@@ -194,20 +194,18 @@ There are **three declarative emission surfaces** — pick by what did the write
|
|
|
194
194
|
| A custom action | **`invalidates:`** on the action | [Named invalidations](/platform/realtime/named-invalidations) |
|
|
195
195
|
| An [aggregate changeset](/define/changesets) (`owns`) | **`afterCommit`** on the aggregate root — one CloudEvent after commit | [changesets → afterCommit](/define/changesets#aftercommit--emit-a-realtime-signal-after-the-changeset-commits) |
|
|
196
196
|
|
|
197
|
-
## CloudEvents
|
|
197
|
+
## CloudEvents + AsyncAPI
|
|
198
198
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
[Using Realtime](/platform/realtime/using-realtime#cloudevents-envelopes
|
|
199
|
+
Realtime data frames are delivered as CloudEvents 1.0 envelopes (control
|
|
200
|
+
frames stay raw), on whatever path `contract.routes` mounts. Match frames on
|
|
201
|
+
the `qbframe` extension, never on `type`. See
|
|
202
|
+
[Using Realtime](/platform/realtime/using-realtime#cloudevents-envelopes)
|
|
203
203
|
for the frame mapping.
|
|
204
204
|
|
|
205
205
|
The project's event surface — realtime channels, named-invalidation events,
|
|
206
206
|
and outbound webhook messages — is published as an AsyncAPI 3.0 document at
|
|
207
|
-
`GET /asyncapi.json` (same auth gating as `/openapi.json`)
|
|
208
|
-
|
|
209
|
-
or webhooks (v1 included); only the message payload *schemas* are shaped by
|
|
210
|
-
the pinned contract — raw frames on v1, CloudEvents envelopes on v2.
|
|
207
|
+
`GET /asyncapi.json` (same auth gating as `/openapi.json`), for any project
|
|
208
|
+
with realtime or webhooks.
|
|
211
209
|
|
|
212
210
|
## Realtime emit from actions
|
|
213
211
|
|
|
@@ -32,7 +32,7 @@ export const attendRealtime = defineRealtime({
|
|
|
32
32
|
events: {
|
|
33
33
|
mobileBundleChanged: {
|
|
34
34
|
wireName: "event.mobile-bundle.changed", // clients listen for this
|
|
35
|
-
version: 1, //
|
|
35
|
+
version: 1, // event version (rides as qbversion)
|
|
36
36
|
variants: {
|
|
37
37
|
documentCreated: {
|
|
38
38
|
reason: "document.created", // clients branch on this
|
|
@@ -121,26 +121,40 @@ Each `invalidate.<binding>.<variant>(payload)` call queues **one** after-commit
|
|
|
121
121
|
- **After-commit, best-effort.** Calls queue frames that fire only after `execute` returns successfully; a `throw` or a `dryRun` discards them (they ride the after-commit effects collector). A rolled-back batch record fires nothing.
|
|
122
122
|
- **Fail-closed targeting.** An unresolvable scope room or a missing recipient set delivers to nobody — never a broad fan-out.
|
|
123
123
|
- **Projection.** The frame payload is projected to the variant's declared keys; undeclared fields never reach the wire.
|
|
124
|
-
- **Contract fields.** `version` and `reason` are baked from the registry and always present.
|
|
124
|
+
- **Contract fields.** `version` and `reason` are baked from the registry and always present, riding as the `qbversion` / `qbreason` CloudEvents extensions.
|
|
125
125
|
|
|
126
126
|
## The wire frame
|
|
127
127
|
|
|
128
|
-
Clients receive a
|
|
128
|
+
Clients receive a [CloudEvents 1.0](/platform/realtime/using-realtime#cloudevents-envelopes)
|
|
129
|
+
frame on `/broadcast/v{n}` (the segment tracks `contract.routes`):
|
|
129
130
|
|
|
130
131
|
```jsonc
|
|
131
132
|
{
|
|
132
|
-
"
|
|
133
|
-
"
|
|
134
|
-
"
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
"specversion": "1.0",
|
|
134
|
+
"id": "evt_9f2…",
|
|
135
|
+
"source": "/broadcast/v1/websocket",
|
|
136
|
+
"type": "event.mobile-bundle.changed", // the wireName, VERBATIM
|
|
137
|
+
"time": "2026-08-17T10:04:11.921Z",
|
|
138
|
+
"datacontenttype": "application/json",
|
|
139
|
+
"qbframe": "broadcast", // the discriminator — match on this
|
|
140
|
+
"qbversion": 1, // event version → negotiation
|
|
141
|
+
"qbreason": "document.created", // what changed → what to refresh
|
|
142
|
+
"data": { // payload MINUS version/reason
|
|
137
143
|
"eventId": "evt_1",
|
|
138
144
|
"documentId": "doc_9"
|
|
139
145
|
}
|
|
140
146
|
}
|
|
141
147
|
```
|
|
142
148
|
|
|
143
|
-
|
|
149
|
+
`version` and `reason` ride as the `qbversion` / `qbreason` extension
|
|
150
|
+
attributes, not inside `data` — the projected payload keys are `data`'s only
|
|
151
|
+
contents. Your `wireName` is the `type` verbatim: author-supplied event names
|
|
152
|
+
are never reverse-DNS prefixed.
|
|
153
|
+
|
|
154
|
+
Match on `qbframe === "broadcast"` (never on `type`, whose shape is not a
|
|
155
|
+
stable contract), then dispatch on `type` for the wireName, use `qbversion` for
|
|
156
|
+
negotiation, and branch on `qbreason` to decide which query/cache to
|
|
157
|
+
invalidate. Role gating (`targetRoles`) and — when a recipient resolver is used — identity narrowing (`targetTags`) are applied by the Broadcaster before the frame reaches any socket; the client just receives the frames meant for it.
|
|
144
158
|
|
|
145
159
|
## Related
|
|
146
160
|
|
|
@@ -56,14 +56,16 @@ If the ticket is invalid or expired, the WebSocket upgrade is rejected with a 40
|
|
|
56
56
|
|
|
57
57
|
### CRUD Events
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
Data frames are [CloudEvents 1.0 envelopes](#cloudevents-envelopes).
|
|
60
|
+
Discriminate on the `qbframe` extension — **never** on `type`, whose shape is
|
|
61
|
+
not a stable contract — and read the row from `data`:
|
|
60
62
|
|
|
61
63
|
```typescript
|
|
62
64
|
ws.onmessage = (event) => {
|
|
63
65
|
const msg = JSON.parse(event.data);
|
|
64
66
|
|
|
65
|
-
if (msg.
|
|
66
|
-
const { table, eventType, new: newRecord, old: oldRecord } = msg;
|
|
67
|
+
if (msg.qbframe === "postgres_changes") {
|
|
68
|
+
const { table, eventType, new: newRecord, old: oldRecord } = msg.data;
|
|
67
69
|
|
|
68
70
|
switch (eventType) {
|
|
69
71
|
case "INSERT":
|
|
@@ -84,12 +86,20 @@ ws.onmessage = (event) => {
|
|
|
84
86
|
|
|
85
87
|
```json
|
|
86
88
|
{
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
89
|
+
"specversion": "1.0",
|
|
90
|
+
"id": "evt_5b1c…",
|
|
91
|
+
"source": "/broadcast/v1/websocket",
|
|
92
|
+
"type": "dev.quickback.myapp.applications.insert",
|
|
93
|
+
"time": "2026-08-17T10:04:11.921Z",
|
|
94
|
+
"datacontenttype": "application/json",
|
|
95
|
+
"qbframe": "postgres_changes",
|
|
96
|
+
"data": {
|
|
97
|
+
"table": "applications",
|
|
98
|
+
"schema": "public",
|
|
99
|
+
"eventType": "INSERT",
|
|
100
|
+
"new": { "id": "app_123", "candidateId": "cnd_456", "stage": "interview" },
|
|
101
|
+
"old": null
|
|
102
|
+
}
|
|
93
103
|
}
|
|
94
104
|
```
|
|
95
105
|
|
|
@@ -97,11 +107,13 @@ For UPDATE events, both `new` and `old` are populated. For DELETE events, only `
|
|
|
97
107
|
|
|
98
108
|
### Custom Broadcasts
|
|
99
109
|
|
|
100
|
-
Custom events
|
|
110
|
+
Custom events carry `qbframe: "broadcast"`. Their `type` is your wire name
|
|
111
|
+
verbatim — author-supplied names are never prefixed:
|
|
101
112
|
|
|
102
113
|
```typescript
|
|
103
|
-
if (msg.
|
|
104
|
-
const
|
|
114
|
+
if (msg.qbframe === "broadcast") {
|
|
115
|
+
const event = msg.type;
|
|
116
|
+
const payload = msg.data;
|
|
105
117
|
|
|
106
118
|
if (event === "screening-complete") {
|
|
107
119
|
refreshApplication(payload.applicationId);
|
|
@@ -115,9 +127,14 @@ if (msg.type === "broadcast") {
|
|
|
115
127
|
|
|
116
128
|
```json
|
|
117
129
|
{
|
|
118
|
-
"
|
|
119
|
-
"
|
|
120
|
-
"
|
|
130
|
+
"specversion": "1.0",
|
|
131
|
+
"id": "evt_a71f…",
|
|
132
|
+
"source": "/broadcast/v1/websocket",
|
|
133
|
+
"type": "screening-complete",
|
|
134
|
+
"time": "2026-08-17T10:04:11.921Z",
|
|
135
|
+
"datacontenttype": "application/json",
|
|
136
|
+
"qbframe": "broadcast",
|
|
137
|
+
"data": {
|
|
121
138
|
"applicationId": "app_123",
|
|
122
139
|
"candidateId": "cnd_456",
|
|
123
140
|
"stage": "interview"
|
|
@@ -125,6 +142,9 @@ if (msg.type === "broadcast") {
|
|
|
125
142
|
}
|
|
126
143
|
```
|
|
127
144
|
|
|
145
|
+
`type` is your wire name verbatim — author-supplied event names are never
|
|
146
|
+
prefixed. Match on `qbframe`, not `type`.
|
|
147
|
+
|
|
128
148
|
Custom namespaces (from `defineRealtime()`) use the format `namespace:event` — e.g., `screening:started`, `screening:progress`.
|
|
129
149
|
|
|
130
150
|
## Security
|
|
@@ -212,26 +232,32 @@ tag = "v1"
|
|
|
212
232
|
new_classes = ["Broadcaster"]
|
|
213
233
|
```
|
|
214
234
|
|
|
215
|
-
## CloudEvents envelopes
|
|
235
|
+
## CloudEvents envelopes
|
|
216
236
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
`contract.routes` (so `/broadcast/v1` unless you also set `routes: "v2"`);
|
|
221
|
-
`version` changes only the frame format. Control frames (`pong`, `error`,
|
|
222
|
-
`reauth_ok`) stay raw on both versions, and pinned-v1 projects keep the raw
|
|
223
|
-
frames byte-identically.
|
|
237
|
+
Every **data frame** is wrapped in a [CloudEvents 1.0](https://cloudevents.io)
|
|
238
|
+
envelope at the Durable Object's send boundary. Control frames (`pong`,
|
|
239
|
+
`error`, `reauth_ok`) stay raw.
|
|
224
240
|
|
|
225
|
-
|
|
241
|
+
The endpoint path is independent of the framing — it tracks `contract.routes`,
|
|
242
|
+
so `/broadcast/v1` unless you set `routes: "v2"`. Frames are CloudEvents on
|
|
243
|
+
either path.
|
|
244
|
+
|
|
245
|
+
| Frame | CloudEvents `type` | `data` | extensions |
|
|
226
246
|
|---|---|---|---|
|
|
227
247
|
| `broadcast` (named invalidation) | the wire name verbatim | payload minus `version`/`reason` | `qbframe: "broadcast"`, `qbversion`, `qbreason` |
|
|
228
|
-
| `postgres_changes` |
|
|
229
|
-
| `view_changes` |
|
|
248
|
+
| `postgres_changes` | `dev.quickback.<project>.<table>.<insert\|update\|delete>` | `{ table, schema, eventType, new, old }` | `qbframe: "postgres_changes"` |
|
|
249
|
+
| `view_changes` | `dev.quickback.<project>.view.<viewName>.changed` | `{ view, rootId, delta }` | `qbframe: "view_changes"`, `qbseq` (the per-surface monotonic seq — your reconnect/gap-detection contract) |
|
|
250
|
+
|
|
251
|
+
**Discriminate frames on the `qbframe` extension.** Never on `type`, whose
|
|
252
|
+
shape is not a stable contract, and never on payload keys — named-invalidation
|
|
253
|
+
payloads are author-supplied maps, so a broadcast whose payload happens to
|
|
254
|
+
carry `view`/`delta` or `table`/`eventType` keys must not be mistaken for a
|
|
255
|
+
system frame.
|
|
230
256
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
257
|
+
Compiler-defined types carry the `dev.quickback.` reverse-DNS prefix, per the
|
|
258
|
+
CloudEvents core spec: the prefixed domain names whoever defines the event's
|
|
259
|
+
semantics. Your own broadcast wire names are **not** prefixed — that vocabulary
|
|
260
|
+
is yours.
|
|
235
261
|
|
|
236
262
|
A changeset's [`afterCommit`](/define/changesets#aftercommit--emit-a-realtime-signal-after-the-changeset-commits)
|
|
237
263
|
broadcast rides the **same `broadcast` frame** (the referenced typed event's
|
|
@@ -252,12 +278,12 @@ as a normal `postgres_changes` frame on the table's room.
|
|
|
252
278
|
"data": { "eventId": "…", "documentId": "…" } }
|
|
253
279
|
```
|
|
254
280
|
|
|
255
|
-
The bundled CMS
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
281
|
+
The bundled CMS and Account SPAs consume these envelopes as-is:
|
|
282
|
+
match on `qbframe`, read the row from `data`, and (for live views) the
|
|
283
|
+
monotonic seq from `qbseq`. The full channel/message catalog ships as
|
|
284
|
+
`GET /asyncapi.json` (AsyncAPI 3.0), served under the same auth gating as
|
|
285
|
+
`/openapi.json`. Any project with realtime or webhooks serves it, and it
|
|
286
|
+
documents the CloudEvents envelopes above.
|
|
261
287
|
|
|
262
288
|
## Cloudflare Only
|
|
263
289
|
|