@vercel/board 0.33.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/{access-N3XmkKXg.mjs → access-CdBcYPQH.mjs} +169 -12
  2. package/dist/access.d.mts +3 -3
  3. package/dist/access.mjs +5 -5
  4. package/dist/{actors-ihyN47OV.mjs → actors-MrIEr9LI.mjs} +2 -2
  5. package/dist/auth-DjoJygbG.mjs +599 -0
  6. package/dist/{auth-D6z3rMNj.d.mts → auth-aaoKt5DK.d.mts} +128 -9
  7. package/dist/backend-local.d.mts +1 -1
  8. package/dist/backend-local.mjs +1 -1
  9. package/dist/{backend-CWpyR1A7.d.mts → backend-u1sVvybh.d.mts} +30 -7
  10. package/dist/{chat-provider-DJpFUaFv.d.mts → chat-provider-De0iDnUB.d.mts} +2 -2
  11. package/dist/cli-commands.d.mts +1 -1
  12. package/dist/cli-commands.mjs +1 -1
  13. package/dist/cli-embedded.d.mts +2 -2
  14. package/dist/cli-embedded.mjs +1 -1
  15. package/dist/cli.mjs +5 -5
  16. package/dist/{commands-CHoMl06v.mjs → commands-B8oZEByR.mjs} +25 -51
  17. package/dist/{commands-BOBQHVqM.d.mts → commands-BkVMdXP1.d.mts} +0 -6
  18. package/dist/{conformance-qKmGLTAT.mjs → conformance-gqYBkXFS.mjs} +76 -83
  19. package/dist/conformance.d.mts +1 -1
  20. package/dist/conformance.mjs +1 -1
  21. package/dist/{engine-JxgZiikU.mjs → engine-rtOVWsiF.mjs} +2 -2
  22. package/dist/{errors-Pk0XV1hK.mjs → errors-D8ifv16L.mjs} +19 -4
  23. package/dist/{exports-gHDHlg0i.mjs → exports-Bx2dGpzr.mjs} +55 -10
  24. package/dist/exports-uwRl5qIj.d.mts +4 -0
  25. package/dist/{index-CXvvYNYj.d.mts → index-D6mK0Ial.d.mts} +2 -2
  26. package/dist/index.d.mts +6 -6
  27. package/dist/index.mjs +4 -4
  28. package/dist/index.node.d.mts +6 -6
  29. package/dist/index.node.mjs +3 -3
  30. package/dist/inspect/app.js +31 -31
  31. package/dist/{local-BbLjA5vI.mjs → local-CPz22MQ8.mjs} +1981 -1574
  32. package/dist/{main-CQpCZJFw.mjs → main-DScDKwQN.mjs} +45 -38
  33. package/dist/{middleware-BU7rVi9F.mjs → middleware-BjYpk4yq.mjs} +1 -1
  34. package/dist/provider-hB8QNrwm.d.mts +1031 -0
  35. package/dist/{provider-BlzUvcM9.d.mts → routes-De4W6lEs.d.mts} +2439 -2469
  36. package/dist/{serve-D8_W4UN6.mjs → serve-B1noQRkn.mjs} +4 -4
  37. package/dist/{server-BiIUXWbU.mjs → server-Ov6GBJ8j.mjs} +7 -7
  38. package/dist/{serving-D7rcUtSC.mjs → serving-2s7lqSBS.mjs} +1 -1
  39. package/dist/sync-chat-sdk.d.mts +2 -2
  40. package/dist/sync-github.d.mts +2 -2
  41. package/dist/sync-linear.d.mts +3 -2
  42. package/dist/sync-slack.d.mts +3 -3
  43. package/dist/sync.d.mts +2 -2
  44. package/dist/{targets-CknPGGVi.mjs → targets-aMdbp84G.mjs} +98 -10
  45. package/dist/{tokens-DPKjl3jf.mjs → tokens-LHLrnV_P.mjs} +2 -2
  46. package/docs/01-board/01-mounting.md +5 -3
  47. package/docs/01-board/03-identity.md +14 -13
  48. package/docs/01-board/07-schedules.md +1 -1
  49. package/docs/01-board/09-access.md +140 -59
  50. package/docs/03-guides/03-ci.md +15 -15
  51. package/docs/03-guides/05-agent-factory.md +5 -6
  52. package/docs/04-reference/01-cli.md +9 -16
  53. package/docs/04-reference/02-board.md +19 -8
  54. package/docs/04-reference/03-http.md +20 -13
  55. package/docs/04-reference/05-conformance.md +1 -1
  56. package/package.json +1 -1
  57. package/dist/auth-r-_PeZyw.mjs +0 -277
  58. package/dist/exports-BuKjVq2t.d.mts +0 -4
  59. package/dist/folds-DjFTiqIM.d.mts +0 -552
@@ -55,16 +55,15 @@ Vercel's board doesn't keep grants yet. Someone with `manage` in every channel
55
55
  grants the repo's runs what they may do, with no deploy:
56
56
 
57
57
  ```text
58
- $ vb grants create github --claim repository=acme/www --claim event_name=push --can 'errors-www=post,label;deploys=read,post'
59
- granted g1
58
+ $ vb grants create --github acme/www --event push --can 'errors-www=post,label;deploys=read,post'
59
+ created g4 --github acme/www --event push errors-www=post,label deploys=read,post
60
60
  ```
61
61
 
62
- The grant matches the token's `repository` and `event_name`, each exactly, and
63
- any other claim you add, such as `--claim ref=refs/heads/main`. A name given
64
- twice is any of its values. The workflow writes as
65
- `github:repo:<repository_id>`, with the handle `acme/www`. A workflow no grant
66
- lets in gets a 403 whose hint is the grant to create:
67
- `Grant it: vb grants create github --claim repository=acme/www`.
62
+ The grant matches the token's `repository` and `event_name`, and a
63
+ `--workflow` or `--branch` you add narrows it to that workflow file or
64
+ branch. The workflow writes as `github:repo:<repository_id>`, with the
65
+ handle `acme/www`. A workflow no grant lets in gets a 403 whose hint is the
66
+ grant to create: `Grant it: vb grants create --github acme/www`.
68
67
 
69
68
  `--can` says what it may do where. This one posts and labels in `errors-www`,
70
69
  for the step above, and reads and posts in `deploys`, which the wait below
@@ -146,12 +145,13 @@ export async function POST(request: Request) {
146
145
 
147
146
  See [Mounting](../01-board/01-mounting.md#the-handle) for the rest of the
148
147
  handle. With `BOARD_URL` set, `board()` takes the deployment's OIDC token to
149
- the board at that URL the same way. There, a project other than the board's
150
- own needs a grant, for its ID and the environment it runs in:
148
+ the board at that URL the same way. There, g2 lets in every project on the
149
+ board's team; a grant for a project and the environment it runs in says
150
+ what it may do instead:
151
151
 
152
152
  ```text
153
- $ vb grants create vercel --claim project_id=prj_deploys --claim environment=production --can deploys=post
154
- granted g2
153
+ $ vb grants create --project prj_deploys --environment production --can deploys=post
154
+ created g4 --project prj_deploys --environment production deploys=post
155
155
  ```
156
156
 
157
157
  A project on another team takes a [board token](#from-anywhere-else) instead,
@@ -175,11 +175,11 @@ curl -s https://team.example/api/board | jq -r .audience
175
175
  ```
176
176
 
177
177
  Another CI's tokens work through a grant that names its issuer by URL, with
178
- the claims to match:
178
+ the claims to match, each exactly:
179
179
 
180
180
  ```text
181
- $ vb grants create https://gitlab.com --claim project_path=acme/api --claim ref=main --can deploys=post
182
- granted g3
181
+ $ vb grants create --oidc https://gitlab.com --claim project_path=acme/api --claim ref=main --can deploys=post
182
+ created g4 --oidc https://gitlab.com --claim project_path=acme/api --claim ref=main deploys=post
183
183
  ```
184
184
 
185
185
  In GitLab, a job's `id_tokens` with the board's audience is the token:
@@ -25,15 +25,14 @@ There are two independent checks. Configure both on the board's project.
25
25
  Vercel's board doesn't keep grants yet.
26
26
 
27
27
  ```text
28
- $ vb grants create vercel --claim project_id=prj_FACTORY_ID --claim environment=production --can '*=read,post;factory/=read,post,label'
29
- granted g1
28
+ $ vb grants create --project prj_FACTORY_ID --environment production --can '*=read,post;factory/=read,post,label'
29
+ created g4 --project prj_FACTORY_ID --environment production *=read,post factory/=read,post,label
30
30
  ```
31
31
 
32
32
  - **Name the project by its ID.** The ID above is a placeholder.
33
- - **Name the environment.** A Vercel grant names one, since a preview runs any
34
- branch's code, and another environment is another grant. Add preview or
35
- development only when you mean to: anyone who can access the Factory's
36
- project can mint its development tokens.
33
+ - **Name the environments.** A project grant names them, since a preview runs
34
+ any branch's code. Add preview or development only when you mean to: anyone
35
+ who can access the Factory's project can mint its development tokens.
37
36
  - **The grant reads and posts in every channel,** and labels only in
38
37
  `factory/`, since a Factory post carries labels. It never reacts or syncs.
39
38
  - **A Factory on another team has only a board token,** until cross-team
@@ -485,28 +485,21 @@ t1 feedback-widget feedback/=post expires in 30d
485
485
 
486
486
  ```text
487
487
  vb grants [list]
488
- vb grants create <issuer> --claim <name=value>... [--can <scope>]
489
488
  vb grants revoke <grant>
490
489
  ```
491
490
 
492
- `grants create` lets in tokens from an OIDC issuer (`vercel`, `github`, or an
493
- https URL) that carry every `--claim`. A name given twice is any of its values.
494
- Creating one with the same issuer and claims again changes its `--can` and
495
- prints `updated g3`. `--can` left out is read, post, react, and label
496
- everywhere. `vb grants` lists each one's ID, issuer, claims, and what it lets
497
- them do. All three need `manage` in every channel. See
498
- [Grants](../01-board/09-access.md#grants).
491
+ `vb grants` lists each grant's ID, the principals it names as the flags that
492
+ name them, and what it lets them do: `*` alone in words, any other pattern as
493
+ `pattern=permissions`, `none` for a closed one. It needs `manage` at `*`.
494
+ `grants revoke g3` stops one and prints `revoked g3`, and needs `manage` at
495
+ each pattern it names. See [Grants](../01-board/09-access.md#grants).
499
496
 
500
497
  ```text
501
- $ vb grants create github --claim repository=acme/web --can ci/=read,post
502
- granted g3
503
- $ vb grants create vercel --claim project_id=prj_front --claim environment=production --can feedback/=post
504
- granted g4
505
498
  $ vb grants
506
- g3 github repository=acme/web ci/=read,post
507
- g4 vercel environment=production project_id=prj_front feedback/=post
508
- $ vb grants revoke g3
509
- revoked g3
499
+ g1 --all-users everything
500
+ g2 --all-projects --environment production,preview,development read post react label
501
+ $ vb grants revoke g2
502
+ revoked g2
510
503
  ```
511
504
 
512
505
  ## Reading
@@ -302,19 +302,30 @@ with 501 `no_scheduler`. See
302
302
  ### createGrant
303
303
 
304
304
  ```ts
305
- createGrant(input: { issuer: string; claims: Record<string, string | string[]>; can?: Can }): Promise<{ grant: GrantView; created: boolean }>
305
+ createGrant(input: { principals: PrincipalInput[]; can: GrantCan }): Promise<{ grant: GrantView }>
306
+ updateGrant(id: string, input: { add?: PrincipalInput[]; remove?: PrincipalInput[]; can?: GrantCan }): Promise<{ grant: GrantView }>
306
307
  grants(): Promise<GrantView[]>
308
+ explain(channel: string, principal?: ExplainPrincipal): Promise<Explanation>
307
309
  revokeGrant(id: string): Promise<{ revoked: boolean }>
308
310
  ```
309
311
 
310
- `createGrant` lets in OIDC tokens from `issuer` (`vercel`, `github`, or an https URL)
311
- that carry every one of `claims`, to do what `can` says: read, post, react,
312
- and label everywhere when it's left out. The same issuer and claims are one
313
- grant, so creating it again changes its `can`, and `created` is false. All
314
- three need `manage` in every channel.
312
+ `createGrant` lets `principals` do what `can` says: a map from channel pattern
313
+ to `'all'` or a list of permissions, `[]` for none. The same principals again
314
+ are another grant. `updateGrant` adds principals (a project it names already
315
+ gets the new environments), removes them by who they are, and replaces `can`.
316
+ Making or widening one needs what you'd grant: `manage` at its patterns and
317
+ under them wherever your own limits narrow you, and what `everyone` gives, for
318
+ anyone it lets in. Revoking one, or removing from it, needs the same but what
319
+ `everyone` gives; `grants` needs `manage` at `*`. Owners always may.
320
+ `explain` says which grants decide a channel, and what they give, for you or,
321
+ with `manage` at `*`, for `{ user }`, `{ project, environment }`, `{ github,
322
+ workflow, branch, event }`, `{ oidc, claims }`, or `{ app }`. A local board has
323
+ no apps, so it explains one as nothing letting it in.
315
324
 
316
325
  ```ts
317
- const { grant } = await team.createGrant({ issuer: 'github', claims: { repository: 'acme/web' }, can: { 'ci/': ['read', 'post'] } })
326
+ const { grant } = await team.createGrant({ principals: [{ kind: 'github', repository: 'acme/web' }], can: { 'ci/': ['read', 'post'] } })
327
+ await team.updateGrant(grant.id, { add: [{ kind: 'user', email: 'ada@acme.com' }] })
328
+ const { pattern, grants, can } = await team.explain('ci/deploys', { user: 'ada@acme.com' })
318
329
  await team.revokeGrant(grant.id)
319
330
  ```
320
331
 
@@ -329,7 +340,7 @@ revokeToken(id: string): Promise<{ revoked: boolean }>
329
340
  ```
330
341
 
331
342
  `createToken` mints a token that acts as the handle's caller, narrowed to `can`
332
- (read, post, react, and label everywhere when left out, as for a grant), and
343
+ (read, post, react, and label everywhere when left out), and
333
344
  answers its `secret`, the only time it shows. `profile`, `avatar`, and
334
345
  `session` pin what every request with it writes as. It lives 30 days, or
335
346
  `expires`, 90 days at most. On `local()`, the handle's own token is the
@@ -119,9 +119,11 @@ a refused write it can read answers 403. `GET /me` returns the caller's
119
119
  | POST | `/schedules` | Schedule a message. Answers 201 `{ schedule }`, with `unknownMentions` like a post. See [Schedules](#schedules) |
120
120
  | GET | `/schedules` | `{ schedules }`. Query: `re`, `channel`, `by`, `all` |
121
121
  | POST | `/schedules/:id/cancel` | Cancel one, by the ID the board gave it (`s12` on `local()`, which also takes `12`). Its creator, or `manage` in its channel. Answers `{ schedule, canceled }` |
122
- | GET | `/grants` | `{ grants }`: each one's `id`, `issuer`, `claims`, `can`, `by`, and `at`. Needs `manage` in every channel. See [Grants and tokens](#grants-and-tokens) |
123
- | POST | `/grants` | `{ issuer, claims, can? }`: set a grant, or the `can` of the one with that issuer and claims. Answers `{ grant, created }` |
124
- | POST | `/grants/:id/revoke` | Answers `{ revoked }`, false when it was already gone |
122
+ | GET | `/grants` | `{ grants }`: each one's `id`, `principals`, `can`, `capped`, `by`, and `at`. Needs `manage` at `*`, or a team owner. See [Grants and tokens](#grants-and-tokens) |
123
+ | POST | `/grants` | `{ principals, can }`: a new grant, even for principals another grant names. Needs `manage` at each pattern in `can`, and under each wherever your token's or your own grants' limits narrow you, and what `everyone` gives wherever it gives something; `manage` everywhere to name an `oidc` principal. A key it doesn't know is 400. Answers `{ grant }` |
124
+ | PATCH | `/grants/:id` | `{ add?, remove?, can? }`: adds principals, removes them by who they are, or replaces `can`. Needs, at the grant as it was, what `POST /grants` needs but what `everyone` gives, and to add principals or set `can`, all of it. Answers `{ grant }`; 404 `grant_not_found`, 400 `not_in_grant` or `grant_empty` |
125
+ | GET | `/grants/explain` | Which grants decide a channel: `{ channel, pattern, over, level, grants, capped, can }`, `over` the other patterns that cover it, most specific first. Query: `channel`, and for someone else (with `manage` at `*`) `user`, `project` and `environment`, `github` and `workflow`, `branch`, `event`, `oidc` and `claim=name=value`, or `app`. `grants` is empty for a caller that can't list them |
126
+ | POST | `/grants/:id/revoke` | Answers `{ revoked }`, false when it was already gone. Needs what `POST /grants` needs at its patterns, but what `everyone` gives |
125
127
  | GET | `/tokens` | `{ tokens }`: yours, or everyone's with `manage` in every channel. With a token, yours are it and those minted with it. Each one's `can` is what it may do now. Each one's `id`, `name`, `can`, `profile`, `session`, `by`, `at`, `expiresAt`, and `parent`, never its secret |
126
128
  | POST | `/tokens` | `{ name, can?, profile?, avatar?, session?, expires? }`: mint a token acting as you. Answers `{ token, secret }`, the only time the secret shows |
127
129
  | POST | `/tokens/:id/revoke` | Revoke one of yours, or anyone's with `manage` in every channel: it and every token minted with it stop. Answers `{ revoked }`, false for one that's gone, never was, or isn't yours, alike |
@@ -193,7 +195,8 @@ though each sees and changes only its own copies, so give each key one sync.
193
195
  Who a platform user is (name, avatar) is board-wide too, so only `sync` in
194
196
  every channel changes it. Give it to the deployment that runs
195
197
  a board's sync, in the channels it syncs, and to no one else:
196
- `vb grants create vercel --claim project_id=prj_support --claim environment=production --can support=all`. A sync with it in one subtree can't import into
198
+ `vb grants create --project prj_support --environment production --can support=all`.
199
+ A sync with it in one subtree can't import into
197
200
  another, and a message it can't sync is as good as missing to it.
198
201
 
199
202
  ### IDs and cursors
@@ -347,23 +350,27 @@ that keeps no schedules answers 501 `no_scheduler`. See
347
350
  ### Grants and tokens
348
351
 
349
352
  ```json
350
- { "issuer": "github", "claims": { "repository": "acme/web", "event_name": ["push", "schedule"] }, "can": { "ci/": ["read", "post"] } }
353
+ { "principals": [{ "kind": "github", "repository": "acme/web", "workflow": "ci.yml", "branch": "main" }, { "kind": "user", "email": "ada@acme.com" }], "can": { "ci/": ["read", "post"] } }
351
354
  ```
352
355
 
353
- `POST /grants` lets in OIDC tokens from `issuer` (`vercel`, `github`, or an
354
- https URL on the internet) that carry every one of `claims`, a list being any
355
- of its values. A Vercel grant names `project_id` and `environment`, and a
356
- GitHub grant `repository` or `repository_id`; anything less is 400
357
- `invalid_grant`. The same issuer and claims are one grant, so setting it again
358
- answers `created: false` with its `can` changed. `can` left out is read, post,
359
- react, and label everywhere.
356
+ `POST /grants` names principals: `{ kind: 'user', email }` (or `userId`),
357
+ `{ kind: 'project', project, environments }`, `{ kind: 'github', repository,
358
+ workflow?, branch?, event? }`, `{ kind: 'oidc', issuer, claims }`, `{ kind:
359
+ 'all-users' }`, `{ kind: 'all-projects', environments }`, and `{ kind:
360
+ 'everyone' }`. Its `can` maps each channel pattern to `"all"` or a list, `[]`
361
+ for none, and is kept as written. A board resolves names and keeps IDs: views
362
+ show `{ kind: 'user', userId, email }`, `{ kind: 'project', projectId, name,
363
+ environments }`, and `{ kind: 'github', repositoryId, repository, … }`. One
364
+ that verifies tokens itself takes a user's ID and a project's `prj_…`, and
365
+ answers 400 `invalid_grant` for a name, as for a principal that would name
366
+ more than it says. See [how grants combine](../01-board/09-access.md#how-grants-combine).
360
367
 
361
368
  ```json
362
369
  { "name": "sandbox-1956", "can": { "dev/": ["read", "post", "react"] }, "profile": "clever-lemur", "session": "thread-1956", "expires": "7d" }
363
370
  ```
364
371
 
365
372
  `POST /tokens` mints a token that acts as the caller, narrowed to `can` (read,
366
- post, react, and label everywhere when left out, as for a grant), until
373
+ post, react, and label everywhere when left out), until
367
374
  it's revoked or it expires: 30 days, or `expires`, 90 days at most. Every
368
375
  request with it writes as the `profile`, `avatar`, and `session` it pins,
369
376
  whatever its headers say. A token minted with a token keeps its pins, is
@@ -89,7 +89,7 @@ Then the rest, a group each in the report:
89
89
  | Group | Check |
90
90
  | --- | --- |
91
91
  | `schedules` | schedules a reply a day out, lists it, and cancels it; and keeps a schedule's `noSync`, so its sends stay off every platform |
92
- | `grants` | grants a project that doesn't exist, lists it, takes the same issuer and claims again as one grant, revokes it twice, and changes a grant's `can` by creating it again. Grants a GitHub repository's workflows and another team's project, and keeps two environments of one project as two grants. Skipped when the token can't change the board's grants |
92
+ | `grants` | grants a project that doesn't exist, by ID, lists it, and revokes it twice. Makes a second grant for the same principals, adds a repository and replaces `can` by the grant's ID, removes the project whatever its environments, and refuses to remove one it doesn't name (`not_in_grant`) or the last (`grant_empty`). Keeps `can` as written, a pattern with `[]` included. Skipped when the token can't change the board's grants |
93
93
  | `tokens` | mints a token for an hour that reads the channel, checks its `can` and its expiry, lists it without its secret, and revokes it twice. Then, with another one's secret: `/me` names its minter and only what it may read, it reads the channel and can't post there, and once it's revoked, it's refused with a 401 |
94
94
  | `attachments` | uploads a file, posts it, and downloads it |
95
95
  | `watchers` | registers a tail, pulls the match for a post, and acks it. Skipped when the token already has watchers or a sync registered there, since registering replaces them |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/board",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
4
4
  "description": "A message board you mount in one route: one durable log, verified authors, live tail, and two-way sync.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,277 +0,0 @@
1
- import { a as forbidden, l as unauthorized, r as badRequest, t as HttpError } from "./errors-Pk0XV1hK.mjs";
2
- import { c as union, i as compileAccess, o as parseScope, t as FULL_ACCESS } from "./access-N3XmkKXg.mjs";
3
- //#region src/server/auth.ts
4
- /**
5
- * Whether a caller wrote what `by` says, as far as changing it goes (editing, deleting, canceling a
6
- * schedule): its principal did, and when a board token pins the profile it writes as, as that
7
- * profile. A token acts as its minter, so the principal alone would let one agent's token change
8
- * what its minter or another agent wrote. Another token that pins the same profile writes as the
9
- * same author, so a renewed one picks up where the last left off.
10
- */
11
- const wroteAs = (caller, by) => by.principal === caller.principal.id && ((caller.principal.pinned?.profile ?? null) === null || by.actor === caller.actor.id);
12
- /**
13
- * Principal IDs a board authenticates: its people, deployments, workflows, and its own code. No
14
- * platform actor sync writes as may have one, or an import could pass for someone signed in.
15
- */
16
- const authenticates = (id) => /^(vercel|oidc|local|board):/.test(id) || id.startsWith("github:repo:");
17
- const VERCEL_ISSUER = /^https:\/\/oidc\.vercel\.com(?:\/[a-z0-9-]+)?$/;
18
- const GITHUB_ISSUER = "https://token.actions.githubusercontent.com";
19
- /**
20
- * `gitlab.com`, `example.com/oidc`, `ci.test%3A8443`: an issuer as a principal
21
- * names it. A `:` (a port) and a `%` are percent-encoded, so the name has no `:`
22
- * and the `sub` after it can hold anything. Issuers that differ only in what the
23
- * URL normalizes (a trailing slash, the host's case) share a name, so the board
24
- * refuses to trust two of them.
25
- */
26
- const issuerName = (iss) => {
27
- const url = new URL(iss);
28
- return `${url.host}${url.pathname.replace(/\/+$/, "")}`.replace(/[%:]/g, (char) => char === "%" ? "%25" : "%3A");
29
- };
30
- /** OIDC issuers to trust, checked: two that name the same principals can't both be. */
31
- function trustedIssuers(issuers) {
32
- const named = /* @__PURE__ */ new Map();
33
- for (const iss of issuers) {
34
- const name = issuerName(iss);
35
- const other = named.get(name);
36
- if (other !== void 0 && other !== iss) throw new Error(`oidc issuers ${other} and ${iss} name the same principals, oidc:${name}:<sub>: pin one of them`);
37
- named.set(name, iss);
38
- }
39
- return new Set(issuers);
40
- }
41
- /** What a board token starts with, so board() knows its own before it tries any other verifier. */
42
- const BOARD_TOKEN_PREFIX = "board_";
43
- /**
44
- * A board token's SHA-256, hex: what the board keeps instead of the secret, both when it mints one
45
- * and when a request carries one. A token is 32 random bytes, so no salt or key is needed.
46
- */
47
- async function tokenHash(secret) {
48
- const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(secret)));
49
- return Array.from(digest, (byte) => byte.toString(16).padStart(2, "0")).join("");
50
- }
51
- /**
52
- * What a grant or a token left without `can` gives: what Vercel's API gives a project it lets use a
53
- * board. Frozen all the way down: board reads it for every such grant, and @vercel/board/access
54
- * exports it, so code that imports it can't widen them.
55
- */
56
- const DEFAULT_CAN = Object.freeze({ "*": Object.freeze([
57
- "read",
58
- "post",
59
- "react",
60
- "label"
61
- ]) });
62
- const GRANT_CLAIMS_MAX = 32;
63
- const GRANT_VALUES_MAX = 32;
64
- const GRANT_VALUE_MAX = 1e3;
65
- const invalidGrant = (message) => badRequest(message, "invalid_grant");
66
- /** Whether `host` names something on the board's own network rather than on the internet. */
67
- function privateHost(host) {
68
- const name = host.toLowerCase().replace(/\.$/, "");
69
- if (name.startsWith("[") || /^\d+(\.\d+){3}$/.test(name) || /^\d+$/.test(name)) return true;
70
- if (!name.includes(".") || name === "localhost") return true;
71
- return /\.(localhost|local|internal|home|lan|corp|intranet)$/.test(name);
72
- }
73
- /**
74
- * A grant checked and put in one form: its issuer, its claims with keys and lists sorted, its
75
- * `can`, and the key that says it's the same grant as another. A 400 `invalid_grant` that says
76
- * what to write. `trusted`: the issuers other grants name, which no two may share principals
77
- * between.
78
- */
79
- function checkGrant(spec, trusted) {
80
- const { issuer } = spec;
81
- if (typeof issuer !== "string" || issuer === "") throw invalidGrant("a grant needs an issuer: vercel, github, or an https URL");
82
- if (issuer !== "vercel" && issuer !== "github") {
83
- let url;
84
- try {
85
- url = new URL(issuer);
86
- } catch {
87
- throw invalidGrant(`a grant's issuer is vercel, github, or an https URL, got ${issuer}`);
88
- }
89
- if (VERCEL_ISSUER.test(issuer)) throw invalidGrant("write the issuer as vercel, and another team's projects with owner_id");
90
- if (issuer === "https://token.actions.githubusercontent.com") throw invalidGrant("write the issuer as github");
91
- if (url.protocol !== "https:" || url.search || url.hash || url.username || url.password) throw invalidGrant(`a grant's issuer is an https URL with no query or credentials, got ${issuer}`);
92
- if (privateHost(url.hostname)) throw invalidGrant(`a grant's issuer is on the internet, not ${url.hostname}`);
93
- const name = issuerName(issuer);
94
- const other = trusted.find((candidate) => candidate !== issuer && /^https:/.test(candidate) && issuerName(candidate) === name);
95
- if (other !== void 0) throw invalidGrant(`issuers ${other} and ${issuer} name the same principals, oidc:${name}:<sub>: use ${other}`);
96
- }
97
- const entries = typeof spec.claims === "object" && spec.claims !== null ? Object.entries(spec.claims) : [];
98
- if (entries.length === 0) throw invalidGrant(`name at least one claim for ${issuer}: its issuer signs tokens for everyone it serves`);
99
- if (entries.length > GRANT_CLAIMS_MAX) throw invalidGrant(`a grant names at most ${GRANT_CLAIMS_MAX} claims`);
100
- const claims = {};
101
- for (const [name, value] of entries.sort(([a], [b]) => a.localeCompare(b))) {
102
- const values = typeof value === "string" ? [value] : Array.isArray(value) ? [...new Set(value)] : [];
103
- if (values.length === 0 || values.some((one) => typeof one !== "string" || one === "")) throw invalidGrant(`claim ${name} has no value to match: give a string, or a list of them`);
104
- if (values.length > GRANT_VALUES_MAX || values.some((one) => one.length > GRANT_VALUE_MAX)) throw invalidGrant(`claim ${name} lists at most ${GRANT_VALUES_MAX} values of up to ${GRANT_VALUE_MAX} characters`);
105
- const sorted = values.sort();
106
- claims[name] = sorted.length === 1 ? sorted[0] : sorted;
107
- }
108
- if (issuer === "vercel" && (claims.project_id === void 0 || claims.environment === void 0)) throw invalidGrant("a Vercel grant names project_id and environment: a preview runs any branch, so it says outright whether they get in");
109
- if (issuer === "github" && claims.repository === void 0 && claims.repository_id === void 0) throw invalidGrant("a GitHub grant names repository or repository_id: GitHub signs tokens for every repository");
110
- const can = spec.can ?? DEFAULT_CAN;
111
- try {
112
- compileAccess(can);
113
- } catch (error) {
114
- throw invalidGrant(error.message);
115
- }
116
- return {
117
- issuer,
118
- claims,
119
- can,
120
- key: JSON.stringify([issuer, claims])
121
- };
122
- }
123
- /** Whether a verified token's facts are a grant's: its issuer, and every claim it names. */
124
- function grantMatches(grant, facts) {
125
- if (!(grant.issuer === "vercel" || grant.issuer === "github" ? facts.issuer === grant.issuer : facts.issuer === "oidc" && facts.iss === grant.issuer)) return false;
126
- return Object.entries(grant.claims).every(([name, allowed]) => {
127
- const value = facts.claims[name];
128
- if (value === void 0) return false;
129
- const text = String(value);
130
- return typeof allowed === "string" ? text === allowed : allowed.includes(text);
131
- });
132
- }
133
- /** The OIDC issuers grants name past Vercel and GitHub: their tokens are verified too. */
134
- const grantIssuers = (grants) => [...new Set(grants.flatMap((grant) => grant.issuer === "vercel" || grant.issuer === "github" ? [] : [grant.issuer]))];
135
- /** A token no grant lets in, and the grant that would. */
136
- const notGranted = (who, grant) => new HttpError(403, "forbidden", `this token can't use this board: no grant lets in ${who}`, { hint: `Grant it: vb grants create ${grant}` });
137
- /**
138
- * What principals may do: people, and the board's own deployments in its environment, everything;
139
- * anyone else what the board's grants that match its token give, all of them adding up. A board
140
- * token's principal is the one that minted it, narrowed.
141
- */
142
- function createAuthority(options) {
143
- /**
144
- * What a principal that isn't a person may do: everything for the board's own deployments in its
145
- * environment, and for anyone else, every grant that matches its token, added up. A 401 or 403
146
- * that says which grant would let it in, when none does.
147
- */
148
- async function byGrants(facts) {
149
- const claims = facts?.claims ?? {};
150
- const own = facts?.issuer === "vercel" ? await options.project() : null;
151
- const environment = String(claims.environment ?? "");
152
- const here = boardEnvironment();
153
- const ownDeployment = own !== null && own.id !== null && claims.project_id === own.id;
154
- if (ownDeployment && here !== null && environment === here) return FULL_ACCESS;
155
- if (!facts) throw forbidden("this token can't use this board");
156
- const grants = options.grants ? await options.grants() : [];
157
- const granted = grants.filter((grant) => grantMatches(grant, facts)).map((grant) => compileAccess(grant.can));
158
- if (granted.length > 0) return union(granted);
159
- if (facts.issuer === "oidc" && !grants.some((grant) => grant.issuer === facts.iss)) throw unauthorized(`untrusted issuer: ${facts.iss}`);
160
- if (facts.issuer === "oidc") throw forbidden("this token can't use this board: no grant lets in its claims");
161
- if (facts.issuer === "github") {
162
- const repository = String(claims.repository ?? "");
163
- throw notGranted(repository || "its repository", `github --claim repository=${repository || "<OWNER/REPO>"}`);
164
- }
165
- const project = String(claims.project_id ?? "") || "<PROJECT_ID>";
166
- const grant = `vercel --claim project_id=${project} --claim environment=${environment || "<ENVIRONMENT>"}`;
167
- if (ownDeployment) throw new HttpError(403, "forbidden", `this token can't use this board: it runs in ${here ?? "no Vercel environment"}, and its ${environment || "unnamed"} deployments need a grant`, { hint: `Grant them: vb grants create ${grant}` });
168
- throw notGranted(`project ${project} in ${environment || "no environment"}`, grant);
169
- }
170
- /**
171
- * What a principal may do now, narrowed by its scope: the board's own code and the platform users
172
- * sync writes as everything; a person everything; anyone else what the board's grants give. A
173
- * host's principal is what its kind is, until it expires. A 401 or 403 when it may do nothing.
174
- */
175
- async function grant(principal) {
176
- let access = FULL_ACCESS;
177
- const hosted = principal.facts?.issuer === "host";
178
- if (principal.id.startsWith("board:") || principal.kind === "external" && !hosted) access = FULL_ACCESS;
179
- else {
180
- if (hosted) {
181
- if (!options.hosts) throw forbidden("this token can't use this board: its board no longer takes a host's principals");
182
- const { exp } = principal.facts.claims;
183
- if (typeof exp === "number" && exp * 1e3 <= Date.now()) throw unauthorized("token expired");
184
- }
185
- if (principal.kind !== "person") access = await byGrants((hosted ? void 0 : principal.facts) ?? factsFromId(principal.id));
186
- }
187
- return principal.scope === void 0 ? access : access.narrow(parseScope(principal.scope));
188
- }
189
- /** What a stored principal (a schedule's creator, a watcher's registrant) may do now: null once nothing. */
190
- async function accessNow(principal) {
191
- try {
192
- return await grant(principal);
193
- } catch (error) {
194
- const status = error.status;
195
- if (status === 401 || status === 403) return null;
196
- throw error;
197
- }
198
- }
199
- return {
200
- grant,
201
- accessNow
202
- };
203
- }
204
- /**
205
- * The Vercel environment the board runs in: `production`, `preview`, or a
206
- * custom environment's name. `VERCEL_TARGET_ENV` names custom environments,
207
- * where `VERCEL_ENV` says `preview`. Null outside Vercel, where only people
208
- * get in without a grant.
209
- */
210
- const boardEnvironment = () => process.env.VERCEL_TARGET_ENV || process.env.VERCEL_ENV || null;
211
- /**
212
- * What a principal's ID still says, for one stored before the board kept
213
- * claims: a deployment's project ID and environment. A workflow's ID names
214
- * neither its repository nor its run, so it says nothing, and a grant that
215
- * needs more than the ID no longer matches.
216
- */
217
- function factsFromId(id) {
218
- const deployment = id.match(/^vercel:project:([^:]+):([^:]+)$/);
219
- return deployment ? {
220
- issuer: "vercel",
221
- iss: "",
222
- claims: {
223
- project_id: deployment[1],
224
- environment: deployment[2]
225
- }
226
- } : null;
227
- }
228
- /** What marks `oidcTokens()`, so board() can tell it makes no host's principals. */
229
- const TOKENS = Symbol("board.oidcTokens");
230
- /** The principals `oidcTokens()` made: board() takes them as they are, and checks the rest as a host's. */
231
- const verifiedTokens = /* @__PURE__ */ new WeakSet();
232
- /** Marks a principal `oidcTokens()` made. */
233
- function markVerified(principal) {
234
- verifiedTokens.add(principal);
235
- return principal;
236
- }
237
- /** Whether `authenticate` is `oidcTokens()`'s alone: it makes no host's principals. */
238
- const verifiesTokens = (authenticate) => TOKENS in authenticate;
239
- /** Whether `oidcTokens()` made `principal`, as opposed to a host's own verifier. */
240
- const fromTokens = (principal) => verifiedTokens.has(principal);
241
- const PRINCIPAL_ID = /^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*:[^\s+\]]{1,200}$/;
242
- const KINDS = [
243
- "person",
244
- "deployment",
245
- "workflow",
246
- "external"
247
- ];
248
- /**
249
- * Checks what a host's own verifier returned. A malformed principal is the host's bug, so it
250
- * fails the request rather than letting a half-identity write.
251
- */
252
- function hostPrincipal(value) {
253
- const fail = (why) => {
254
- throw new TypeError(`authenticate returned an invalid principal: ${why}`);
255
- };
256
- if (typeof value !== "object" || value === null) fail("not an object");
257
- if (typeof value.id !== "string" || !PRINCIPAL_ID.test(value.id) || value.id.startsWith("board:")) fail(`id must look like \`vercel:user:<id>\`, got ${JSON.stringify(value.id)}`);
258
- if (!KINDS.includes(value.kind)) fail(`kind must be one of ${KINDS.join(", ")}`);
259
- if (typeof value.handle !== "string" || !/^\S{1,64}$/.test(value.handle)) fail("handle must be 1-64 characters, no spaces");
260
- const expiresAt = value.expiresAt ?? null;
261
- if (expiresAt !== null && (!(expiresAt instanceof Date) || Number.isNaN(expiresAt.getTime()))) fail("expiresAt must be a Date or null");
262
- if (expiresAt !== null && expiresAt.getTime() <= Date.now()) throw unauthorized("token expired");
263
- const claims = expiresAt === null ? {} : { exp: Math.floor(expiresAt.getTime() / 1e3) };
264
- return {
265
- id: value.id,
266
- kind: value.kind,
267
- handle: value.handle,
268
- expiresAt,
269
- facts: {
270
- issuer: "host",
271
- iss: "",
272
- claims
273
- }
274
- };
275
- }
276
- //#endregion
277
- export { verifiesTokens as _, VERCEL_ISSUER as a, createAuthority as c, hostPrincipal as d, issuerName as f, trustedIssuers as g, tokenHash as h, TOKENS as i, fromTokens as l, privateHost as m, DEFAULT_CAN as n, authenticates as o, markVerified as p, GITHUB_ISSUER as r, checkGrant as s, BOARD_TOKEN_PREFIX as t, grantIssuers as u, wroteAs as v };
@@ -1,4 +0,0 @@
1
- import "./folds-DjFTiqIM.mjs";
2
- import "./auth-D6z3rMNj.mjs";
3
- import "./provider-BlzUvcM9.mjs";
4
- import "./backend-CWpyR1A7.mjs";