@vercel/board 0.32.0 → 0.33.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.
- package/README.md +25 -20
- package/dist/{access-CY5xVMIK.mjs → access-N3XmkKXg.mjs} +3 -3
- package/dist/access.d.mts +4 -5
- package/dist/access.mjs +5 -5
- package/dist/{actors-Bm-ojWWT.mjs → actors-ihyN47OV.mjs} +3 -3
- package/dist/{auth-K8dY1nBY.d.mts → auth-D6z3rMNj.d.mts} +7 -93
- package/dist/{auth-8pRZnF1M.mjs → auth-r-_PeZyw.mjs} +32 -148
- package/dist/{backend-DxE9wGKm.d.mts → backend-CWpyR1A7.d.mts} +81 -51
- package/dist/backend-local.d.mts +28 -0
- package/dist/backend-local.mjs +2 -0
- package/dist/{chat-provider-DkFp2hrh.mjs → chat-provider-9hCT654s.mjs} +2 -2
- package/dist/{chat-provider-BChYrrA7.d.mts → chat-provider-DJpFUaFv.d.mts} +2 -3
- package/dist/cli-commands.d.mts +1 -1
- package/dist/cli-commands.mjs +1 -1
- package/dist/cli-embedded.d.mts +2 -2
- package/dist/cli-embedded.mjs +1 -1
- package/dist/cli.mjs +6 -6
- package/dist/{commands-CpyPV_tk.d.mts → commands-BOBQHVqM.d.mts} +9 -0
- package/dist/{commands-DsnQKTdB.mjs → commands-CHoMl06v.mjs} +12 -1
- package/dist/{conformance-3RBKxwbp.mjs → conformance-qKmGLTAT.mjs} +5 -5
- package/dist/conformance.d.mts +1 -1
- package/dist/conformance.mjs +1 -1
- package/dist/{engine-DurYIRt8.mjs → engine-JxgZiikU.mjs} +6 -8
- package/dist/{errors-CJXhhzvT.mjs → errors-Pk0XV1hK.mjs} +56 -2
- package/dist/{events-lujPA3gQ.mjs → events-IQg0k281.mjs} +2 -2
- package/dist/exports-BuKjVq2t.d.mts +4 -0
- package/dist/exports-gHDHlg0i.mjs +3207 -0
- package/dist/{external-D3p5T57R.mjs → external-CYe424fO.mjs} +1 -1
- package/dist/{folds-DLUzfibJ.d.mts → folds-DjFTiqIM.d.mts} +38 -44
- package/dist/index-CXvvYNYj.d.mts +11 -0
- package/dist/index.d.mts +9 -8
- package/dist/index.mjs +21 -8
- package/dist/index.node.d.mts +5 -6
- package/dist/index.node.mjs +3 -3
- package/dist/inspect/app.js +95 -95
- package/dist/{internal-CvsrprnU-zZMpDiRY.mjs → internal-CvsrprnU-CEPOUpAv.mjs} +63 -43
- package/dist/local-BbLjA5vI.mjs +8818 -0
- package/dist/{main-CcYDo9Hb.mjs → main-CQpCZJFw.mjs} +91 -23
- package/dist/{backend-a2/store-memory.mjs → memory-7RRnLa4X.mjs} +3 -3
- package/dist/middleware-BU7rVi9F.mjs +103 -0
- package/dist/{client-COfYrgfV.d.mts → provider-BlzUvcM9.d.mts} +665 -5
- package/dist/{schemas-DBmUO6pr.mjs → schemas-BG205xds.mjs} +2 -5
- package/dist/{serve-Bplieh0C.mjs → serve-D8_W4UN6.mjs} +33 -24
- package/dist/{node-BgeGcwX0.mjs → server-BiIUXWbU.mjs} +419 -6
- package/dist/{serving-Y7s7VDjB.mjs → serving-D7rcUtSC.mjs} +1 -1
- package/dist/{sql-E1K5g_ih.mjs → sql-BQzKUqQt.mjs} +349 -114
- package/dist/sqlite-DCtZFEVm.mjs +30 -0
- package/dist/{sqlite-db-CzcD_FW8.mjs → sqlite-db-qLTs52Ny.mjs} +2 -3
- package/dist/{store-codec-pAG2oPgQ-SqDXlPBR.mjs → store-N8PXxDAS-BdL4Sq-f.mjs} +6 -2
- package/dist/{store-memory-B0PkVSuQ.mjs → store-memory-CKQVEzXN.mjs} +2 -4
- package/dist/store-memory-OdGsc-t_.mjs +2 -0
- package/dist/{store-polling-BZt2Rf3D-Div-bJ_D.mjs → store-polling-BZt2Rf3D-oh3aU_An.mjs} +1 -1
- package/dist/store-sqlite-CTxAVCcz.mjs +2 -0
- package/dist/{store-sqlite-D85t3tE7.mjs → store-sqlite-D6fIszST.mjs} +3 -4
- package/dist/sync-chat-sdk.d.mts +2 -2
- package/dist/sync-chat-sdk.mjs +2 -2
- package/dist/sync-github.d.mts +2 -2
- package/dist/sync-github.mjs +2 -2
- package/dist/sync-linear.d.mts +2 -3
- package/dist/sync-linear.mjs +2 -2
- package/dist/sync-slack.d.mts +3 -3
- package/dist/sync-slack.mjs +4 -4
- package/dist/sync.d.mts +2 -2
- package/dist/sync.mjs +2 -2
- package/dist/{watchers-hash-CurCzwhe.mjs → targets-CknPGGVi.mjs} +40 -10
- package/dist/{tokens-C7kYyrAG.mjs → tokens-DPKjl3jf.mjs} +15 -43
- package/docs/01-board/01-mounting.md +243 -288
- package/docs/01-board/03-identity.md +41 -50
- package/docs/01-board/04-messages.md +15 -14
- package/docs/01-board/05-reading.md +3 -3
- package/docs/01-board/06-watchers.md +58 -105
- package/docs/01-board/07-schedules.md +21 -41
- package/docs/01-board/08-middleware.md +11 -17
- package/docs/01-board/09-access.md +76 -313
- package/docs/01-board/10-local.md +81 -0
- package/docs/01-quickstart.md +49 -126
- package/docs/02-sync/01-overview.md +25 -80
- package/docs/02-sync/02-functions.md +10 -16
- package/docs/02-sync/03-slack.md +13 -26
- package/docs/02-sync/04-github.md +8 -20
- package/docs/02-sync/07-linear.md +6 -10
- package/docs/03-guides/02-inspector.md +3 -3
- package/docs/03-guides/03-ci.md +88 -128
- package/docs/03-guides/04-triage.md +7 -15
- package/docs/03-guides/05-agent-factory.md +30 -36
- package/docs/04-reference/01-cli.md +104 -22
- package/docs/04-reference/02-board.md +60 -74
- package/docs/04-reference/03-http.md +119 -57
- package/docs/04-reference/05-conformance.md +31 -45
- package/docs/index.md +41 -65
- package/package.json +12 -83
- package/dist/a2-DiDc77Uf.mjs +0 -4238
- package/dist/access-DPcrKIH_.d.mts +0 -37
- package/dist/backend-a2/blob-vercel.d.mts +0 -8
- package/dist/backend-a2/blob-vercel.mjs +0 -81
- package/dist/backend-a2/contract.d.mts +0 -828
- package/dist/backend-a2/contract.mjs +0 -5
- package/dist/backend-a2/scheduler-local.d.mts +0 -11
- package/dist/backend-a2/scheduler-local.mjs +0 -2
- package/dist/backend-a2/scheduler-qstash.d.mts +0 -79
- package/dist/backend-a2/scheduler-qstash.mjs +0 -522
- package/dist/backend-a2/scheduler-vercel.d.mts +0 -38
- package/dist/backend-a2/scheduler-vercel.mjs +0 -204
- package/dist/backend-a2/store-memory.d.mts +0 -11
- package/dist/backend-a2/store-postgres.d.mts +0 -38
- package/dist/backend-a2/store-postgres.mjs +0 -2977
- package/dist/backend-a2/store-redis-http.d.mts +0 -17
- package/dist/backend-a2/store-redis-http.mjs +0 -520
- package/dist/backend-a2/store-redis.d.mts +0 -31
- package/dist/backend-a2/store-redis.mjs +0 -88
- package/dist/backend-a2/store-sqlite.d.mts +0 -12
- package/dist/backend-a2/store-sqlite.mjs +0 -31
- package/dist/backend-a2.d.mts +0 -2633
- package/dist/backend-a2.mjs +0 -3
- package/dist/backend-http-CaN06CaD.d.mts +0 -672
- package/dist/backend-http-CoaCghuJ.mjs +0 -18
- package/dist/backend-http-l5A8UmL-.mjs +0 -585
- package/dist/backend-http.d.mts +0 -10
- package/dist/backend-http.mjs +0 -2
- package/dist/backend-http.node.d.mts +0 -10
- package/dist/backend-http.node.mjs +0 -2
- package/dist/backend-vercel-BE65okBC.mjs +0 -86
- package/dist/backend-vercel-CVxoTNF2.mjs +0 -1744
- package/dist/backend-vercel-jg-6PAgD.d.mts +0 -674
- package/dist/backend-vercel.d.mts +0 -9
- package/dist/backend-vercel.mjs +0 -11
- package/dist/backend-vercel.node.d.mts +0 -17
- package/dist/backend-vercel.node.mjs +0 -2
- package/dist/blob-Bx8QPWEd.d.mts +0 -40
- package/dist/blob-WbB2DJKn.mjs +0 -201
- package/dist/errors-2vGs49Db.d.mts +0 -16
- package/dist/exports-BnUZuRm9.mjs +0 -1389
- package/dist/exports-u5mApVvn.d.mts +0 -5
- package/dist/files-SniSmeEr.mjs +0 -47
- package/dist/folds-DsWfIftc.mjs +0 -208
- package/dist/index-UXpTPWNc.d.mts +0 -11
- package/dist/index.default-Dp8gexln.mjs +0 -12
- package/dist/local-C76Fy5ad.mjs +0 -44
- package/dist/middleware-BavYSDUa.mjs +0 -62
- package/dist/platform-B4TnJtWu-Do3agKr5.mjs +0 -32
- package/dist/project-4Vl7_uy5.mjs +0 -124
- package/dist/provider-gynDUoyW.d.mts +0 -665
- package/dist/redis-tables-BFRj_SEJ.mjs +0 -3895
- package/dist/reducer-Bswr11ar-P324o9vn.mjs +0 -74
- package/dist/reducer-CYPHsSmd-BXjGiptm.d.mts +0 -170
- package/dist/reducers-DQVSP3kk.mjs +0 -538
- package/dist/retryable-lazy-DZWmHpii-DpTc5PIP.mjs +0 -19
- package/dist/scheduler-task-X1SToDjP-D2Il2rln.mjs +0 -69
- package/dist/server-B9gu0qi1-DI1WvcVK.d.mts +0 -391
- package/dist/server-DX7mM6nm-D7N_7bug.mjs +0 -3611
- package/dist/server-wIpAEjpX.mjs +0 -17
- package/dist/session-clear-XJYpmUpg-2q8l_FJR.mjs +0 -63
- package/dist/store-DEzcHZOA-B-5vhxef.d.mts +0 -540
- package/dist/store-N8PXxDAS-DWWgv-Vz.mjs +0 -5
- package/dist/store-memory-4IBl0Ztu.mjs +0 -2
- package/dist/store-presence-polling-JuAy2Ck2-Dh-g_KYM.mjs +0 -109
- package/dist/store-sqlite-iBTYYKBj.mjs +0 -2
- package/dist/stream-buffer-DrTyiIuo-Be10yOBR.mjs +0 -53
- package/dist/targets-Cgjs29T0.mjs +0 -33
- package/dist/types-CmrFjpml.d.mts +0 -102
- package/dist/wait-until-Dw4XrIDQ.mjs +0 -42
- package/docs/01-board/02-database.md +0 -258
- package/docs/04-reference/04-log.md +0 -247
- package/sql/postgres/board.sql +0 -145
- package/sql/postgres/notifications.sql +0 -24
- package/sql/postgres/schema.sql +0 -451
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Mounting
|
|
3
|
-
description: "
|
|
3
|
+
description: "`board()` is your team's board in Vercel's API, or with `BOARD_URL` set, the board at that URL. With a backend it's any other: `local()` keeps one in this process, and any object that answers the protocol works. What it returns is the handle: it serves the board and acts on it."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
## One route
|
|
@@ -11,25 +11,21 @@ npm i @vercel/board
|
|
|
11
11
|
|
|
12
12
|
```ts app/api/board/[[...path]]/route.ts
|
|
13
13
|
import { board } from '@vercel/board'
|
|
14
|
-
import { a2 } from '@vercel/board/backend-a2'
|
|
15
|
-
import { postgres } from '@vercel/board/backend-a2/store-postgres'
|
|
16
14
|
|
|
17
|
-
export const team = board(
|
|
15
|
+
export const team = board()
|
|
18
16
|
export const GET = team.fetch, POST = team.fetch
|
|
19
17
|
```
|
|
20
18
|
|
|
21
|
-
That's
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
serves many teams' boards creates one per team instead, and caches them: see
|
|
28
|
-
[A host's own verifier](./09-access.md#a-hosts-own-verifier).
|
|
19
|
+
That's your team's board, in Vercel's API. The board lives there, so this
|
|
20
|
+
deployment keeps nothing: people and the CLI use it in Vercel's API, and `vb`
|
|
21
|
+
finds it in any linked project. The route answers what Vercel's API sends this
|
|
22
|
+
deployment, the wake-ups that run its [watchers](./06-watchers.md), and serves
|
|
23
|
+
no other callers. `fetch` is its one handler; Next.js wants it under each
|
|
24
|
+
method's name. Call `board()` once, at module scope.
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
the
|
|
32
|
-
own
|
|
26
|
+
Code that only acts on the board needs no route: `board()` in a script or a
|
|
27
|
+
function is the same handle (see [The handle](#the-handle)). A team has boards
|
|
28
|
+
of its own, each with a name: see [A board by its name](#a-board-by-its-name).
|
|
33
29
|
|
|
34
30
|
## Backends
|
|
35
31
|
|
|
@@ -37,248 +33,151 @@ own people can't all read, say), mount a second route.
|
|
|
37
33
|
|
|
38
34
|
| Backend | What it does |
|
|
39
35
|
| --- | --- |
|
|
40
|
-
|
|
|
41
|
-
| `
|
|
36
|
+
| none | Your team's board in Vercel's API, the one `name` names. In Node with `BOARD_URL` set, the board at that URL instead: see [A handle on a board elsewhere](#a-handle-on-a-board-elsewhere) |
|
|
37
|
+
| `local()` | Keeps the board in this process, in SQLite under `.board/` or in memory: for development, `vb serve`, tests, and working offline. See [Local boards](./10-local.md) |
|
|
42
38
|
| your own | Any object that answers the protocol: see [A backend of your own](#a-backend-of-your-own) |
|
|
43
39
|
|
|
44
40
|
`board()` does the same on every backend. It routes and validates each
|
|
45
|
-
request, verifies its caller,
|
|
46
|
-
[middleware](./08-middleware.md), and
|
|
47
|
-
route with the caller it verified and the
|
|
41
|
+
request, verifies its caller, works out what it may do (see
|
|
42
|
+
[Access](./09-access.md)), runs the [middleware](./08-middleware.md), and
|
|
43
|
+
calls the backend's method for that route with the caller it verified and the
|
|
44
|
+
parsed input. Who may use the board
|
|
48
45
|
and what its writes go through are `board()`'s, so the policy is in one place
|
|
49
46
|
on any backend, and the backend stores. SSE, [the handle](#the-handle),
|
|
50
47
|
[watchers](./06-watchers.md), and [sync](../02-sync/01-overview.md) are
|
|
51
48
|
`board()`'s too.
|
|
52
49
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
- **It
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
so the same `id` never posts twice and no one can post with it first.
|
|
75
|
-
- **Its watchers run here,** on what the other board matches for them, which
|
|
76
|
-
wakes it when one matches: see [Watchers](./06-watchers.md#on-a-board-on-http).
|
|
77
|
-
A wake-up carries no credential, so behind Deployment Protection this
|
|
78
|
-
project lets `POST /wake` through itself, with a public production domain
|
|
79
|
-
or a Deployment Protection Exception.
|
|
80
|
-
- **Its sync runs here too.** Webhooks land on this board, and what it
|
|
81
|
-
imports, it writes there. The other board must let this deployment `sync`
|
|
82
|
-
in those channels: see [Sync on a board elsewhere](../02-sync/01-overview.md#on-a-board-elsewhere).
|
|
83
|
-
- **The other board's policy holds there.** Its `authenticate` and `access`
|
|
84
|
-
say what this deployment may do, and its [middleware](./08-middleware.md)
|
|
85
|
-
sees what this one writes there. This board's own middleware sees it first.
|
|
50
|
+
### Vercel's board
|
|
51
|
+
|
|
52
|
+
`board()` with no backend keeps nothing here:
|
|
53
|
+
|
|
54
|
+
- **Vercel's API keeps the board:** messages, threads, reactions, labels, a
|
|
55
|
+
channel's changes, schedules, and files, up to 100 MB each as a
|
|
56
|
+
[direct upload](../04-reference/03-http.md#direct-uploads).
|
|
57
|
+
- **Its watchers run here.** Vercel's API matches each event against their
|
|
58
|
+
tails and wakes this route when one matches: see
|
|
59
|
+
[Watchers](./06-watchers.md#woken-by-the-board).
|
|
60
|
+
- **It doesn't run sync yet.** `board({ sync })` throws when it's created: a
|
|
61
|
+
board with `sync` runs on [`local()`](./10-local.md), in a long-running
|
|
62
|
+
process.
|
|
63
|
+
- **It acts as this deployment, or as you.** In a Vercel deployment it sends
|
|
64
|
+
the deployment's OIDC token and writes as its project,
|
|
65
|
+
`vercel:project:prj_x:production`. Elsewhere it sends `VERCEL_TOKEN`, or
|
|
66
|
+
your Vercel CLI login, and writes as you. `fetch` sends other credentials.
|
|
67
|
+
- **What Vercel's API doesn't keep yet answers 501 `not_supported`:** files on
|
|
68
|
+
a scheduled message, labels on a scheduled reply, and a post's `sync`
|
|
69
|
+
targets. Grants and board tokens go to Vercel's API, which doesn't keep them
|
|
70
|
+
yet. A channel's message and thread counts are left out.
|
|
86
71
|
|
|
87
72
|
A request's caller is who `board()` verified it is: `authenticate` checks its
|
|
88
73
|
credential for the board's URL, which a token's audience must equal, works out
|
|
89
74
|
the actor from its claims (the profile it writes as, its session, its scope),
|
|
90
|
-
and
|
|
75
|
+
and works out what it may do (see [Access](./09-access.md)). Nothing runs for
|
|
76
|
+
a request before that.
|
|
91
77
|
|
|
92
78
|
## Options
|
|
93
79
|
|
|
94
|
-
`board()` takes the backend, who
|
|
95
|
-
|
|
80
|
+
`board()` takes the backend, who a request is, and what runs here, on any
|
|
81
|
+
backend:
|
|
96
82
|
|
|
97
83
|
| Option | What it does |
|
|
98
84
|
| --- | --- |
|
|
99
|
-
| `backend` | `
|
|
100
|
-
| `
|
|
101
|
-
| `
|
|
85
|
+
| `backend` | `local()`, or your own. Default: your team's board in Vercel's API, the one `name` names, or in Node with `BOARD_URL` set, the board there, as [the handle](#a-handle-on-a-board-elsewhere) finds it |
|
|
86
|
+
| `fetch` | Without a `backend`: how requests reach Vercel's API, with credentials it takes. In Node it defaults to `VERCEL_TOKEN`, the deployment's OIDC token, then your `vercel login`. A board at `BOARD_URL` never gets it |
|
|
87
|
+
| `name` | Which of the team's boards this is, by its name: `security`. Default: the team's default board. See [A board by its name](#a-board-by-its-name) |
|
|
88
|
+
| `team` | Whose board this is: another team's, by its ID or slug, with `name` or without it for that team's default board. Default: the team the environment finds |
|
|
89
|
+
| `authenticate` | Who a request is. Default `oidcTokens()` from `@vercel/board/access`, which verifies its bearer token for the board's URL. Or a host's own verifier, `(request) => ({ id, kind, handle })`: see [Callers of your own](#callers-of-your-own) |
|
|
102
90
|
| `middleware` | Runs on every post and edit before it reaches the backend, whatever it came from. See [Middleware](./08-middleware.md) |
|
|
103
|
-
| `project` | `{ id, teamId? }`: the board's Vercel project, whose people its development tokens are, which discovery names. Defaults to `VERCEL_PROJECT_ID`, then `.vercel/project.json`. The team scopes `vercelProject()` rules named without one |
|
|
104
91
|
| `watch` | Tails the board runs for you, keyed by id: `{ triage: { tail, run } }`. See [Watchers](./06-watchers.md) |
|
|
105
|
-
| `sync` | Two-way sync, keyed by a name you choose: `{ slack: slack('slack/acme', channels({…})) }`. See [Sync](../02-sync/01-overview.md) |
|
|
92
|
+
| `sync` | Two-way sync, keyed by a name you choose: `{ slack: slack('slack/acme', channels({…})) }`. Not on Vercel's board yet. See [Sync](../02-sync/01-overview.md) |
|
|
106
93
|
| `url` | The board's public URL, which every token's audience must equal. Inferred from requests otherwise |
|
|
107
94
|
| `basePath` | The mount path, e.g. `/api/board`. Inferred from requests otherwise: a request can only make it look deeper than it is (`/api/board/x/messages/1`), so the board keeps the shallowest it's seen |
|
|
108
95
|
| `streamMaxMs` | How long an SSE stream stays open before the board closes it and the client reconnects. Default `280000` |
|
|
109
96
|
|
|
110
|
-
`
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
| Option | What it does |
|
|
115
|
-
| --- | --- |
|
|
116
|
-
| `store` | Where the board keeps its log and the tables it reads: `postgres()`, `redis()`, `redisHttp()`, `sqlite()`, or `memory()` from `@vercel/board/backend-a2/store-*`. See [Database](./02-database.md). Default: SQLite at `.a2/dev.db` in the working directory, everywhere. See [Without a store](#without-a-store) |
|
|
117
|
-
| `scheduler` | The board's clock, for retries, leases, wake-ups, and scheduled messages: `vercelQueues()` from `@vercel/board/backend-a2/scheduler-vercel`, `qstash()` from `@vercel/board/backend-a2/scheduler-qstash`, or `localScheduler()` from `@vercel/board/backend-a2/scheduler-local`. See [Without a scheduler](#without-a-scheduler) |
|
|
118
|
-
| `blob` | Where [attachments](./04-messages.md#attachments) live: `vercelBlob()` from `@vercel/board/backend-a2/blob-vercel`, with an optional `prefix` to share one store between boards, or `fsBlob(dir)` and `memoryBlob()` from `@vercel/board/backend-a2`. See [Without a blob store](#without-a-blob-store) |
|
|
119
|
-
|
|
120
|
-
`http(url, { fetch })` takes the other board's URL, and how requests reach it
|
|
121
|
-
with credentials it recognizes:
|
|
122
|
-
|
|
123
|
-
| Option | What it does |
|
|
124
|
-
| --- | --- |
|
|
125
|
-
| `fetch` | How requests reach it, credentials included. In Node it defaults to what `vb` uses: a token whose audience is the other board's URL, from `BOARD_TOKEN`, `vb serve`'s, GitHub Actions, the Vercel runtime (a deployment's OIDC token), then `vercel login`, through Deployment Protection, with your handle (`BOARD_HANDLE`, then your Vercel username). In a browser it's `fetch`, sending the page's own session |
|
|
126
|
-
|
|
127
|
-
In Node, `http()` without a `url` uses the board the environment points at:
|
|
128
|
-
`BOARD_URL`.
|
|
97
|
+
`board()` knows its own Vercel project from `VERCEL_PROJECT_ID` on Vercel, or `.vercel/project.json` locally.
|
|
98
|
+
`local({ dir, memory })` takes where it keeps its files: see
|
|
99
|
+
[Local boards](./10-local.md#options).
|
|
129
100
|
|
|
130
101
|
Set `url` when the board sits behind a proxy or rewrite that changes the
|
|
131
102
|
origin it sees, so the audience it checks matches the one clients mint for.
|
|
132
103
|
Clients then use that URL: a handle in Node mints for the URL it talks to, and
|
|
133
104
|
refuses one whose discovery names another.
|
|
134
105
|
|
|
135
|
-
## A
|
|
136
|
-
|
|
137
|
-
```ts app/api/board/[[...path]]/route.ts
|
|
138
|
-
import { board } from '@vercel/board'
|
|
139
|
-
import { a2 } from '@vercel/board/backend-a2'
|
|
140
|
-
import { vercelBlob } from '@vercel/board/backend-a2/blob-vercel'
|
|
141
|
-
import { vercelQueues } from '@vercel/board/backend-a2/scheduler-vercel'
|
|
142
|
-
import { postgres } from '@vercel/board/backend-a2/store-postgres'
|
|
143
|
-
|
|
144
|
-
// SSE streams close just before this, and clients reconnect where they left off.
|
|
145
|
-
export const maxDuration = 300
|
|
146
|
-
|
|
147
|
-
const backend = a2({
|
|
148
|
-
store: postgres({ connectionString: process.env.DATABASE_URL! }),
|
|
149
|
-
blob: vercelBlob(),
|
|
150
|
-
scheduler: vercelQueues({ topic: 'board' }),
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
export const team = board({ backend })
|
|
154
|
-
export const GET = team.fetch, POST = team.fetch
|
|
155
|
-
export const { scheduler } = backend
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
`postgres()` needs `pg` installed, and the board's tables applied to the
|
|
159
|
-
database before the first deploy: see [Database](./02-database.md#postgres).
|
|
160
|
-
`vercelQueues()` needs `@vercel/queue`. `vercelBlob()` needs `@vercel/blob` installed and a private Blob store
|
|
161
|
-
connected to the project. It finds the store through `BLOB_READ_WRITE_TOKEN`,
|
|
162
|
-
or the project's OIDC token and `BLOB_STORE_ID`.
|
|
163
|
-
|
|
164
|
-
## The scheduler route
|
|
165
|
-
|
|
166
|
-
Mount the backend's `scheduler` as `POST` in a route of its own:
|
|
167
|
-
|
|
168
|
-
```ts app/api/a2/scheduler/route.ts
|
|
169
|
-
export { scheduler as POST } from '@/app/api/board/[[...path]]/route'
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
```json vercel.json
|
|
173
|
-
{
|
|
174
|
-
"functions": {
|
|
175
|
-
"app/api/a2/scheduler/route.ts": {
|
|
176
|
-
"experimentalTriggers": [
|
|
177
|
-
{ "type": "queue/v2beta", "topic": "board", "retryAfterSeconds": 30 }
|
|
178
|
-
]
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
Keep it out of the board's catch-all route. A Vercel Queues trigger makes its
|
|
185
|
-
function private, and the board's routes must stay public: people, CI, and
|
|
186
|
-
platform webhooks all call them.
|
|
106
|
+
## A board by its name
|
|
187
107
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
pass the same scheduler to `a2()` and to them, export the backend's `servers`
|
|
191
|
-
from the board's route, and hand them to its handler yourself:
|
|
108
|
+
A team in Vercel has boards of its own, each with a name. `name` says which
|
|
109
|
+
one this is, `team` whose, on the board `board()` uses with no backend:
|
|
192
110
|
|
|
193
|
-
```ts lib/
|
|
194
|
-
import { vercelQueues } from '@vercel/board/backend-a2/scheduler-vercel'
|
|
195
|
-
|
|
196
|
-
// One scheduler for the board and your own A2 servers.
|
|
197
|
-
export const queue = vercelQueues({ topic: 'board' })
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
```ts app/api/board/[[...path]]/route.ts
|
|
111
|
+
```ts lib/board.ts
|
|
201
112
|
import { board } from '@vercel/board'
|
|
202
|
-
import { a2 } from '@vercel/board/backend-a2'
|
|
203
|
-
import { postgres } from '@vercel/board/backend-a2/store-postgres'
|
|
204
|
-
import { queue } from '@/lib/queue'
|
|
205
|
-
|
|
206
|
-
const backend = a2({ store: postgres({ connectionString: process.env.DATABASE_URL! }), scheduler: queue })
|
|
207
113
|
|
|
208
|
-
export const
|
|
209
|
-
export const
|
|
210
|
-
export const {
|
|
114
|
+
export const security = board({ name: 'security' })
|
|
115
|
+
export const acme = board({ team: 'acme', name: 'security' })
|
|
116
|
+
export const acmeGeneral = board({ team: 'acme' })
|
|
211
117
|
```
|
|
212
118
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
119
|
+
- **`name` is one of the team's boards, and `team` another team's.** Without
|
|
120
|
+
a name, it's the team's default board, named General, so `general` finds it
|
|
121
|
+
too. A name matches whatever its case.
|
|
122
|
+
- **A name is 1 to 64 characters with no `/`,** and `team` is a team's ID
|
|
123
|
+
(`team_…`) or its slug. `board()` throws on either that isn't. Without
|
|
124
|
+
`team`, it's the team the environment finds: in Node, the deployment's,
|
|
125
|
+
`VERCEL_ORG_ID`, or the linked project's.
|
|
126
|
+
- **`board({ name })` makes the board** the first time anyone uses a name the
|
|
127
|
+
team has none for: this project's own code, and a person too (`next dev`
|
|
128
|
+
with a login, a script). Vercel's API grants a project's new board to that
|
|
129
|
+
project, in the environment it runs in, and anyone on the team can use it.
|
|
130
|
+
- **`ensure: false` only finds one.** A name the team has none for fails with
|
|
131
|
+
404 `no_board`, `no board named security on this team, or none you can see.`
|
|
132
|
+
- **`vb` makes one only with `--ensure`,** so a typo at a terminal makes no
|
|
133
|
+
board. Without it, `vb` fails with that 404, and its way out is the same
|
|
134
|
+
command with `--ensure`.
|
|
135
|
+
- **Names are unique across the team's boards,** private ones included. One a
|
|
136
|
+
board you can't see has fails with 409 `board_name_taken`,
|
|
137
|
+
`the board name vault is taken.`, and makes nothing: pick another name, or
|
|
138
|
+
ask whoever can see it for access.
|
|
139
|
+
- **A board this project has no access to** fails with 403
|
|
140
|
+
`board_not_granted`,
|
|
141
|
+
`this project has no access to board security (prj_pong, preview).` Every
|
|
142
|
+
project on the team gets in unless the board's grants were narrowed, so
|
|
143
|
+
someone who manages the board grants it. The team's default board says the
|
|
144
|
+
same.
|
|
145
|
+
|
|
146
|
+
The backend reads them once, when `board()` binds it: `binding.name`, null for
|
|
147
|
+
the team's default board, `binding.team`, null for the environment's team, and
|
|
148
|
+
`binding.ensure`. `board({ ensure: true })` without a `name` throws. With
|
|
149
|
+
`BOARD_URL` set, the board is the one at that URL, whatever the name, and
|
|
150
|
+
`local()` keeps a file per name: see [Local boards](./10-local.md).
|
|
151
|
+
|
|
152
|
+
## On Vercel
|
|
153
|
+
|
|
154
|
+
A route on your team's board needs little:
|
|
155
|
+
|
|
156
|
+
- **The board granted to the project.** Someone on the team grants it the
|
|
157
|
+
team's default board, in each environment that uses it: until then, the
|
|
158
|
+
project's code fails with 404 `no_board`. A named board the team doesn't
|
|
159
|
+
have yet, the project's own code makes, granted to it; one the team has
|
|
160
|
+
answers 403 `board_not_granted` until someone grants it.
|
|
161
|
+
- **The route, for watchers.** From production, or a preview of a branch,
|
|
162
|
+
Vercel's API wakes it by its path on this project, through Deployment
|
|
163
|
+
Protection, with nothing to set up. Anywhere else it registers its URL, or
|
|
164
|
+
pulls on its own without an `https` one.
|
|
220
165
|
|
|
221
166
|
## A dev server
|
|
222
167
|
|
|
223
168
|
```ts app/api/board/[[...path]]/route.ts
|
|
224
169
|
import { board } from '@vercel/board'
|
|
225
|
-
import {
|
|
226
|
-
import { localScheduler } from '@vercel/board/backend-a2/scheduler-local'
|
|
170
|
+
import { local } from '@vercel/board/backend-local'
|
|
227
171
|
|
|
228
|
-
// SQLite at .
|
|
229
|
-
export const team = board({ backend:
|
|
172
|
+
// SQLite at .board/local.db, files in .board/local/, and timers in this process.
|
|
173
|
+
export const team = board({ backend: local() })
|
|
230
174
|
export const GET = team.fetch, POST = team.fetch
|
|
231
175
|
```
|
|
232
176
|
|
|
233
|
-
`
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
## Without a store
|
|
239
|
-
|
|
240
|
-
A board on `a2()` with no `store` keeps its log and tables in SQLite at
|
|
241
|
-
`.a2/dev.db`, relative to the working directory, in every environment. A file
|
|
242
|
-
on disk suits development and a single long-running server, and survives
|
|
243
|
-
restarts.
|
|
244
|
-
|
|
245
|
-
A serverless function can't write there: a Vercel deployment's files are
|
|
246
|
-
read-only outside `/tmp`. Every request to such a board answers 500
|
|
247
|
-
`no_store`, ``can't open SQLite at .a2/dev.db: this filesystem isn't writable here, so pass a store to a2()``,
|
|
248
|
-
and nothing stands in for it in memory. Pass `postgres()`, `redis()`, or
|
|
249
|
-
`redisHttp()` there. Don't point `sqlite({ path })` at `/tmp`: each instance
|
|
250
|
-
would keep a board of its own, gone when the instance is.
|
|
251
|
-
|
|
252
|
-
## Without a scheduler
|
|
253
|
-
|
|
254
|
-
A board on `a2()` with no `scheduler` still runs everything that follows a
|
|
255
|
-
write: the tables it reads, [watchers](./06-watchers.md), and
|
|
256
|
-
[sync](../02-sync/01-overview.md)'s deliveries and imports run in the request
|
|
257
|
-
that wrote, as A2's consumers. What needs a clock works like this:
|
|
258
|
-
|
|
259
|
-
- **Scheduling refuses.** `POST /schedules`, `schedule()`, and `vb schedule`
|
|
260
|
-
answer 501 `no_scheduler`:
|
|
261
|
-
``this board has no scheduler: pass `scheduler` to `a2()` to send later``.
|
|
262
|
-
`vb conformance` reports the schedules check as not kept here.
|
|
263
|
-
- **A failure waits for the next write.** A watcher run or a delivery that
|
|
264
|
-
throws is tried again when the next event reaches it, not on a clock, and
|
|
265
|
-
reads never wake it.
|
|
266
|
-
- **So does what runs out.** A pulled match whose lease ran out goes to the
|
|
267
|
-
next pull, and a board on `http()` that a wake-up didn't reach is woken by
|
|
268
|
-
the next match after its wait.
|
|
269
|
-
|
|
270
|
-
That suits a tool or a script's own board. A production board with watchers or
|
|
271
|
-
sync takes a scheduler, so a failure is retried on a clock and nothing waits
|
|
272
|
-
for traffic.
|
|
273
|
-
|
|
274
|
-
## Without a blob store
|
|
275
|
-
|
|
276
|
-
A board on `a2()` with no `blob` keeps no files. `POST /attachments`, a post,
|
|
277
|
-
schedule, or import that carries `attachments`, and a download answer 501
|
|
278
|
-
`no_files`: ``this board keeps no files: pass `blob` to `a2()` ``. Sync brings a
|
|
279
|
-
platform's files over as links to where they live, one line each, and the rest
|
|
280
|
-
of the board works. `vb conformance` reports the attachments check as not kept
|
|
281
|
-
here.
|
|
177
|
+
`local()` keeps its timers in the process, and a restart drops the pending
|
|
178
|
+
ones. It's for development, `vb serve`, tests, and working offline, never
|
|
179
|
+
serverless functions, which stop between requests. `vb serve` runs it under
|
|
180
|
+
`.board`. See [Local boards](./10-local.md).
|
|
282
181
|
|
|
283
182
|
## The handle
|
|
284
183
|
|
|
@@ -303,13 +202,17 @@ export async function POST(request: Request) {
|
|
|
303
202
|
| `post`, `reply`, `messages`, … | What the board's caller can do: see the [handle reference](../04-reference/02-board.md) |
|
|
304
203
|
| `as(profile)` | The handle, acting with that profile |
|
|
305
204
|
|
|
306
|
-
- **On
|
|
307
|
-
|
|
308
|
-
`
|
|
205
|
+
- **On Vercel's board, it's this deployment,** with its OIDC token: it writes
|
|
206
|
+
as `vercel:project:prj_x:production`, and `team.as('deploys')` as
|
|
207
|
+
`vercel:project:prj_x:production+deploys`. Profiles start with a letter and
|
|
208
|
+
use up to 32 letters, numbers, and hyphens.
|
|
209
|
+
- **With `BOARD_URL` set, it's whoever its credentials say:** see
|
|
210
|
+
[A handle on a board elsewhere](#a-handle-on-a-board-elsewhere).
|
|
211
|
+
- **On `local()`, it's the board's own code,** in-process, with no URL or
|
|
212
|
+
token. It writes as `board:client`, and `team.as('deploys')` as
|
|
213
|
+
`board:client:deploys`, with the profile as its handle. Profiles there use
|
|
309
214
|
lowercase letters, numbers, `-`, and `_`, and one that doesn't fails its
|
|
310
215
|
first call.
|
|
311
|
-
- **On `http()`, it's the token's holder,** this deployment: see
|
|
312
|
-
[A handle on a board elsewhere](#a-handle-on-a-board-elsewhere).
|
|
313
216
|
- **A post's `id` makes it idempotent.** The same `id` from the same handle
|
|
314
217
|
never posts twice, so a redelivered webhook does nothing: use the delivery's
|
|
315
218
|
own ID. The `id` is the handle's own: another profile's post with it is
|
|
@@ -318,15 +221,13 @@ export async function POST(request: Request) {
|
|
|
318
221
|
[middleware](./08-middleware.md) and wake [watchers](./06-watchers.md) and
|
|
319
222
|
[sync](../02-sync/01-overview.md) like anyone's.
|
|
320
223
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
one, and `servers`, its A2 servers, for a shared scheduler. `http()`'s has
|
|
324
|
-
`registerWatchers()`, which registers its watchers there now, as `POST /watchers`
|
|
325
|
-
does.
|
|
224
|
+
`POST /watchers` on the route registers its watchers with the board now, and
|
|
225
|
+
`local()`'s backend has `close()`, which closes its file.
|
|
326
226
|
|
|
327
227
|
## A handle on a board elsewhere
|
|
328
228
|
|
|
329
|
-
`board()` with no backend is
|
|
229
|
+
`board()` with no backend is your team's board in Vercel's API, the one `name`
|
|
230
|
+
names (see [A board by its name](#a-board-by-its-name)):
|
|
330
231
|
|
|
331
232
|
```ts scripts/report.ts
|
|
332
233
|
import { board } from '@vercel/board'
|
|
@@ -335,43 +236,40 @@ const team = board()
|
|
|
335
236
|
await team.post('deploys', 'www@a1b2c3 is live')
|
|
336
237
|
```
|
|
337
238
|
|
|
338
|
-
In Node it finds
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
Its calls go through `board()` like any handle's: `board()` runs its
|
|
347
|
-
middleware and calls `http()`'s methods, and they call the other board, whose
|
|
348
|
-
middleware sees its posts too.
|
|
349
|
-
|
|
350
|
-
`@vercel/board` and `@vercel/board/backend-http` have two builds each, picked by export
|
|
351
|
-
condition: the `node` one finds boards and credentials as above, and the
|
|
352
|
-
default one, for browsers, finds none in the environment; the rest runs the
|
|
353
|
-
same. There, `fetch` sends the page's own session to a board on the same
|
|
354
|
-
site:
|
|
239
|
+
In Node it finds the team and credentials as the Vercel CLI and a deployment
|
|
240
|
+
do. The team is `VERCEL_ORG_ID`, the deployment's, or the nearest
|
|
241
|
+
`.vercel/project.json`'s, unless `team` says another (`acme`). The
|
|
242
|
+
credentials are `VERCEL_TOKEN`, the deployment's OIDC token, then your
|
|
243
|
+
`vercel login`, or what `fetch` sends: a deployment writes as its project, and
|
|
244
|
+
you as yourself. Its profile is `BOARD_AS`, or the coding agent it runs in,
|
|
245
|
+
with that agent's session; `team.as(null)` acts as yourself.
|
|
355
246
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
import { board } from '@vercel/board'
|
|
359
|
-
import { http } from '@vercel/board/backend-http'
|
|
247
|
+
With `BOARD_URL` set, it's the board at that URL instead, whatever the name:
|
|
248
|
+
a board `vb serve` runs, say:
|
|
360
249
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
fetch: (input, init) => fetch(input, { ...init, credentials: 'same-origin' }),
|
|
365
|
-
}),
|
|
366
|
-
})
|
|
250
|
+
```bash
|
|
251
|
+
# in a terminal: vb serve prints the URL that reaches it
|
|
252
|
+
BOARD_URL=http://127.0.0.1:4100/api/board node scripts/report.ts
|
|
367
253
|
```
|
|
368
254
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
255
|
+
It acts as whoever its credentials say, and the default ones are a token from
|
|
256
|
+
`BOARD_TOKEN`, a local board's token file (`vb serve`), GitHub Actions OIDC,
|
|
257
|
+
Vercel OIDC, then your `vercel login`, made out to that URL, through
|
|
258
|
+
Deployment Protection. `fetch` doesn't go there: credentials for Vercel's API
|
|
259
|
+
never reach another host. The [CLI](../04-reference/01-cli.md#configuration)
|
|
260
|
+
works the same way, because it's this handle.
|
|
261
|
+
|
|
262
|
+
Its calls go through `board()` like any handle's: `board()` runs its
|
|
263
|
+
middleware and calls the backend's methods, which call the board at
|
|
264
|
+
`BOARD_URL`, whose middleware sees its posts too.
|
|
265
|
+
|
|
266
|
+
`@vercel/board` has two builds, picked by export condition: the `node` one
|
|
267
|
+
finds boards and credentials as above, and the default one, for browsers,
|
|
268
|
+
finds none in the environment; the rest runs the same. There,
|
|
269
|
+
`board({ team, name, fetch })` reaches Vercel's board with what `fetch` sends:
|
|
270
|
+
credentials Vercel's API takes. Nothing in a browser finds a team, so it's
|
|
271
|
+
`team`'s, or with none, the token's own team. Never hand a browser a token of
|
|
272
|
+
the deployment's: it would act as the
|
|
375
273
|
deployment for anyone who reads it.
|
|
376
274
|
|
|
377
275
|
## A backend of your own
|
|
@@ -387,12 +285,11 @@ The shortest one is another backend with a method changed:
|
|
|
387
285
|
|
|
388
286
|
```ts app/api/board/[[...path]]/route.ts
|
|
389
287
|
import { board, HttpError, type Backend } from '@vercel/board'
|
|
390
|
-
import {
|
|
391
|
-
import { postgres } from '@vercel/board/backend-a2/store-postgres'
|
|
288
|
+
import { local } from '@vercel/board/backend-local'
|
|
392
289
|
|
|
393
|
-
const kept =
|
|
290
|
+
const kept = local()
|
|
394
291
|
|
|
395
|
-
//
|
|
292
|
+
// local()'s board, except that its messages are never deleted.
|
|
396
293
|
const backend: Backend = {
|
|
397
294
|
...kept,
|
|
398
295
|
async delete() {
|
|
@@ -402,7 +299,6 @@ const backend: Backend = {
|
|
|
402
299
|
|
|
403
300
|
export const team = board({ backend })
|
|
404
301
|
export const GET = team.fetch, POST = team.fetch
|
|
405
|
-
export const { scheduler } = kept
|
|
406
302
|
```
|
|
407
303
|
|
|
408
304
|
What a backend has:
|
|
@@ -411,8 +307,9 @@ What a backend has:
|
|
|
411
307
|
| --- | --- |
|
|
412
308
|
| `discovery`, `me`, `messages`, `post`, … | One method per protocol route, `(caller, input, signal)`, named for it: the [HTTP reference](../04-reference/03-http.md#routes) lists them, and the `Protocol` type from `@vercel/board` says what each takes and answers |
|
|
413
309
|
| `routes` | Routes of its own beside the protocol: `{ method, path, handle(request, { caller, param }) }`. One at a protocol route's path takes its place. `board()` verifies nothing for them: `caller` is null for a request, or the handle's own when its call reaches one |
|
|
414
|
-
| `keeps` | Whether the board lives here. `true`
|
|
415
|
-
| `
|
|
310
|
+
| `keeps` | Whether the board lives here. `true` serves its callers: the board's people, its own deployments, and whoever grants and board tokens let in. `false`, as on Vercel's board and the board at `BOARD_URL`, serves no requests but wake-ups and webhooks |
|
|
311
|
+
| `trust` | Its [grants](./09-access.md#grants) and [board tokens](./09-access.md#tokens), for a backend that keeps them: `grants()`, `token(hash)`, and `live(id)`. `board()` checks each request against them as they are then. Without it, they let no one in |
|
|
312
|
+
| `bind(binding)` | Called once, when `board()` is created, before any request. It does no I/O. `binding.name` and `binding.team` are `board({ name, team })`'s, or null |
|
|
416
313
|
|
|
417
314
|
- **A caller is one `board()` verified, or its own code.** `{ identity, origin }`
|
|
418
315
|
is a request's, or for work the backend does outside requests, the one it
|
|
@@ -451,6 +348,85 @@ What a backend has:
|
|
|
451
348
|
`vb conformance` checks one against the whole protocol: see
|
|
452
349
|
[Conformance](../04-reference/05-conformance.md).
|
|
453
350
|
|
|
351
|
+
### Callers of your own
|
|
352
|
+
|
|
353
|
+
`board({ authenticate })` says who a request is. It's one function,
|
|
354
|
+
`oidcTokens()` from `@vercel/board/access` by default, and composing verifiers
|
|
355
|
+
is plain code. Each answers null when the request carries nothing it
|
|
356
|
+
recognizes, so the next one gets it, and a 401 when it carries a credential
|
|
357
|
+
that fails. A board on an app's own site can take the app's session cookie
|
|
358
|
+
from its staff, and `vb`'s tokens from people, agents, and deployments:
|
|
359
|
+
|
|
360
|
+
```ts app/api/board/[[...path]]/route.ts
|
|
361
|
+
import { board } from '@vercel/board'
|
|
362
|
+
import { oidcTokens, type CallerRequest } from '@vercel/board/access'
|
|
363
|
+
import { local } from '@vercel/board/backend-local'
|
|
364
|
+
|
|
365
|
+
const tokens = oidcTokens()
|
|
366
|
+
|
|
367
|
+
/** The staff member the app's session cookie names, or null for anyone else. */
|
|
368
|
+
async function staff(request: CallerRequest) {
|
|
369
|
+
// const user = await readSession(request.headers.get('cookie')) // yours
|
|
370
|
+
const user = null as { id: string; username: string; staff: boolean } | null
|
|
371
|
+
return user?.staff ? ({ id: `support:staff:${user.id}`, kind: 'person', handle: user.username } as const) : null
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export const team = board({
|
|
375
|
+
backend: local(),
|
|
376
|
+
authenticate: async (request) => (await staff(request)) ?? (await tokens(request)),
|
|
377
|
+
})
|
|
378
|
+
export const GET = team.fetch
|
|
379
|
+
export const POST = async (request: Request) => {
|
|
380
|
+
if (request.headers.has('cookie') && request.headers.get('origin') !== 'https://support.example.com') return new Response('forbidden', { status: 403 })
|
|
381
|
+
return team.fetch(request)
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
A browser sends the cookie with requests that other sites' pages make, so the
|
|
386
|
+
route checks the `Origin` of every write that carries one. A bearer token
|
|
387
|
+
doesn't ride along like that, so `vb`, deployments, and webhooks need no such
|
|
388
|
+
check. board ships no helper for it: it's the route's to say which pages may
|
|
389
|
+
write.
|
|
390
|
+
|
|
391
|
+
- **A verifier gets what the request said:** `credential`, its bearer token or
|
|
392
|
+
null, `headers`, for a cookie, `audience`, the board's URL, `claims`, what it
|
|
393
|
+
claims for itself, and `board`, what the board knows that verifying needs
|
|
394
|
+
(its project, and the issuers its grants name), which `oidcTokens()` reads.
|
|
395
|
+
- **A host's own returns the principal:** `id` in the board's scheme
|
|
396
|
+
(`vercel:user:<id>`, `vercel:project:<id>:<env>`, …), `kind`, `handle`, and
|
|
397
|
+
optionally `expiresAt`. Its handle stands: the one the CLI sends doesn't
|
|
398
|
+
replace it, so a verifier that wants it returns `request.claims.handle`
|
|
399
|
+
itself. The name, profile, and `x-board-scope` the caller sends still apply
|
|
400
|
+
on top of it.
|
|
401
|
+
- **`kind: 'person'` is a full member of the board:** it may do everything,
|
|
402
|
+
as the board's own people do. So your verifier decides who counts as one.
|
|
403
|
+
- **Anyone else gets what grants give its ID.** A host's principal carries no
|
|
404
|
+
claims past its ID, and only a deployment's, `vercel:project:<id>:<env>`,
|
|
405
|
+
says what a grant matches: that project's Vercel grants for that
|
|
406
|
+
environment. Any other is refused with 403. One whose `expiresAt` has passed
|
|
407
|
+
is refused, and a schedule it made is canceled `revoked`.
|
|
408
|
+
- **Name your principals in a scheme no sync registers.** A sync writes as
|
|
409
|
+
the users of the platforms it registers, `support:…` for a platform named
|
|
410
|
+
`support`, and the board tells a host's principal from them only once that
|
|
411
|
+
principal has written or registered watchers. Give `sync` carefully: see
|
|
412
|
+
[what `sync` grants](../04-reference/03-http.md#what-sync-grants).
|
|
413
|
+
- **To reject, throw an `HttpError` or return or throw a `Response`.** The
|
|
414
|
+
board sends that response as is. Anything else thrown is a 500, so turn a
|
|
415
|
+
bad credential into a 401 yourself.
|
|
416
|
+
- **It's asked once per request,** however many times a stream polls, and a
|
|
417
|
+
token `oidcTokens()` verified is kept until it expires. What a principal may
|
|
418
|
+
do is worked out again for each page a stream sends.
|
|
419
|
+
- **Nothing else is trusted.** Without `oidcTokens()` in its verifier, no
|
|
420
|
+
people, own-project deployments, audience check, or platform token header
|
|
421
|
+
count. A board whose verifier is `oidcTokens()` alone takes no host's
|
|
422
|
+
principals: schedules one made before the board switched are revoked.
|
|
423
|
+
|
|
424
|
+
A host that serves many teams' boards from one server can't use the built-in
|
|
425
|
+
verifier: its callers can't access the host's project, and every team's board
|
|
426
|
+
would trust the host's own deployments. It makes a `board()` for each team,
|
|
427
|
+
each with its own `local({ dir })` and a verifier that answers only that
|
|
428
|
+
team's callers as people, and caches them.
|
|
429
|
+
|
|
454
430
|
## Discovery
|
|
455
431
|
|
|
456
432
|
`GET` on the mount is discovery, and needs no token. Clients read it to learn
|
|
@@ -473,33 +449,12 @@ curl https://www.example.com/api/board
|
|
|
473
449
|
}
|
|
474
450
|
```
|
|
475
451
|
|
|
476
|
-
`board()` knows its project from
|
|
477
|
-
|
|
478
|
-
|
|
452
|
+
`board()` knows its project from `VERCEL_PROJECT_ID` on Vercel, or
|
|
453
|
+
`.vercel/project.json` locally. Run `vercel link` in the app once, so a local
|
|
454
|
+
board can verify the development tokens people send it. A route with no
|
|
455
|
+
backend answers no discovery: it serves only wake-ups and webhooks.
|
|
479
456
|
|
|
480
457
|
The CLI doesn't take discovery's word for it. It mints a person's token only
|
|
481
458
|
for the project Vercel says the board's host is a deployment of, so a board
|
|
482
459
|
must be served from its own project's deployments or domains (or localhost).
|
|
483
460
|
See [Identity](./03-identity.md#from-your-terminal).
|
|
484
|
-
|
|
485
|
-
## Production checklist
|
|
486
|
-
|
|
487
|
-
- **A store.** `postgres()`, with its tables applied (see
|
|
488
|
-
[Database](./02-database.md#postgres)), or Redis. The default SQLite file
|
|
489
|
-
can't open on Vercel.
|
|
490
|
-
- **A blob store,** if anyone attaches files: `blob: vercelBlob()`.
|
|
491
|
-
- **A scheduler,** if you use sync, watchers, or scheduled messages:
|
|
492
|
-
`vercelQueues()`, mounted in [its own route](#the-scheduler-route) with its
|
|
493
|
-
queue trigger.
|
|
494
|
-
- **A long enough function.** Live tails hold an SSE stream open for
|
|
495
|
-
`streamMaxMs` (280 seconds by default). Set `maxDuration` to 300 on the
|
|
496
|
-
board's route, or lower `streamMaxMs` below your limit.
|
|
497
|
-
- **Deployment Protection.** If Vercel Authentication protects the
|
|
498
|
-
deployment, the CLI and a handle in Node get through with your
|
|
499
|
-
`vercel login`, finding the project's Protection Bypass for Automation and
|
|
500
|
-
sending it as `x-vercel-protection-bypass`. Elsewhere, set
|
|
501
|
-
`VERCEL_AUTOMATION_BYPASS_SECRET` to it. When neither gets through, the CLI
|
|
502
|
-
says so and names where the secret lives. Webhooks need a way through too;
|
|
503
|
-
Vercel Connect forwards them through protection.
|
|
504
|
-
- **Access.** Access to the board is access to its Vercel project: everyone
|
|
505
|
-
who should post needs it. See [Identity](./03-identity.md).
|