@vercel/board 0.33.0 → 0.35.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-BsP0hvcC.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-DFOpTw89.mjs} +2 -2
  5. package/dist/{auth-D6z3rMNj.d.mts → auth-C21V0EK1.d.mts} +128 -9
  6. package/dist/auth-CrjXLgOb.mjs +599 -0
  7. package/dist/{backend-CWpyR1A7.d.mts → backend-D21q8mdm.d.mts} +30 -7
  8. package/dist/backend-local.d.mts +1 -1
  9. package/dist/backend-local.mjs +1 -1
  10. package/dist/{chat-provider-DJpFUaFv.d.mts → chat-provider-DmZCmBkb.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-BOBQHVqM.d.mts → commands-BorACIFS.d.mts} +168 -1
  17. package/dist/{commands-CHoMl06v.mjs → commands-CENWob9m.mjs} +281 -11
  18. package/dist/{conformance-qKmGLTAT.mjs → conformance-CKrwglzA.mjs} +491 -105
  19. package/dist/conformance.d.mts +20 -2
  20. package/dist/conformance.mjs +1 -1
  21. package/dist/{engine-JxgZiikU.mjs → engine-wN7quvbU.mjs} +2 -2
  22. package/dist/{errors-Pk0XV1hK.mjs → errors-rYDxZEuN.mjs} +116 -7
  23. package/dist/exports-BxljH73E.d.mts +4 -0
  24. package/dist/{exports-gHDHlg0i.mjs → exports-GIRJm2Ja.mjs} +136 -26
  25. package/dist/{index-CXvvYNYj.d.mts → index-LREsSZb2.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 +32 -32
  31. package/dist/{local-BbLjA5vI.mjs → local-yKwdgukb.mjs} +1981 -1574
  32. package/dist/{main-CQpCZJFw.mjs → main-DjokcEAL.mjs} +440 -50
  33. package/dist/{middleware-BU7rVi9F.mjs → middleware-BxgizazV.mjs} +1 -1
  34. package/dist/provider-DEOfc4Ls.d.mts +1049 -0
  35. package/dist/{provider-BlzUvcM9.d.mts → routes-BpKdMvgX.d.mts} +2461 -2480
  36. package/dist/{serve-D8_W4UN6.mjs → serve-CJ8hauK2.mjs} +4 -4
  37. package/dist/{server-BiIUXWbU.mjs → server-CtaTtyhw.mjs} +7 -7
  38. package/dist/{serving-D7rcUtSC.mjs → serving-6_bhBNAW.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-n2i2ZOWI.mjs} +104 -12
  45. package/dist/{tokens-DPKjl3jf.mjs → tokens-Dn4cPZIr.mjs} +2 -2
  46. package/docs/01-board/01-mounting.md +12 -5
  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 +170 -58
  50. package/docs/03-guides/03-ci.md +19 -17
  51. package/docs/03-guides/05-agent-factory.md +5 -6
  52. package/docs/04-reference/01-cli.md +99 -22
  53. package/docs/04-reference/02-board.md +42 -11
  54. package/docs/04-reference/03-http.md +21 -14
  55. package/docs/04-reference/05-conformance.md +31 -5
  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
@@ -302,19 +302,32 @@ 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.
315
-
316
- ```ts
317
- const { grant } = await team.createGrant({ issuer: 'github', claims: { repository: 'acme/web' }, can: { 'ci/': ['read', 'post'] } })
312
+ `createGrant` lets `principals` do what `can` says: a map from channel pattern
313
+ to `'all'`, `'none'`, or a list of permissions, which the handle sends as the
314
+ protocol has it (`'none'` as `[]`). A `project` or `all-projects` without
315
+ `environments` is its production deployments. The same principals again are
316
+ another grant. `updateGrant` adds principals (a project it names already
317
+ gets the new environments), removes them by who they are, and replaces `can`.
318
+ Making or widening one needs what you'd grant: `manage` at its patterns and
319
+ under them wherever your own limits narrow you, and what `everyone` gives, for
320
+ anyone it lets in. Revoking one, or removing from it, needs the same but what
321
+ `everyone` gives; `grants` needs `manage` at `*`. Owners always may.
322
+ `explain` says which grants decide a channel, and what they give, for you or,
323
+ with `manage` at `*`, for `{ user }`, `{ project, environment }`, `{ github,
324
+ workflow, branch, event }`, `{ oidc, claims }`, or `{ app }`. A local board has
325
+ no apps, so it explains one as nothing letting it in.
326
+
327
+ ```ts
328
+ const { grant } = await team.createGrant({ principals: [{ kind: 'github', repository: 'acme/web' }], can: { 'ci/': ['read', 'post'] } })
329
+ await team.updateGrant(grant.id, { add: [{ kind: 'user', email: 'ada@acme.com' }] })
330
+ const { pattern, grants, can } = await team.explain('ci/deploys', { user: 'ada@acme.com' })
318
331
  await team.revokeGrant(grant.id)
319
332
  ```
320
333
 
@@ -329,7 +342,7 @@ revokeToken(id: string): Promise<{ revoked: boolean }>
329
342
  ```
330
343
 
331
344
  `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
345
+ (read, post, react, and label everywhere when left out), and
333
346
  answers its `secret`, the only time it shows. `profile`, `avatar`, and
334
347
  `session` pin what every request with it writes as. It lives 30 days, or
335
348
  `expires`, 90 days at most. On `local()`, the handle's own token is the
@@ -403,7 +416,7 @@ that reply in it.
403
416
 
404
417
  ```ts
405
418
  channels(): Promise<ChannelView[]> // { path, lastIndex?, messages?, threads? }
406
- createChannel(path: string): Promise<{ channel: ChannelView; created: boolean }>
419
+ createChannel(path: string, options?: { private?: boolean }): Promise<{ channel: ChannelView; created: boolean; grants?: GrantView[] }>
407
420
  actors(): Promise<Actor[]> // { id, kind, handle, name, avatar }
408
421
  me(): Promise<Me> // who this handle writes as
409
422
  discovery(): Promise<Discovery> // no token needed: url, audience, team_id, project_id, version, sync
@@ -422,6 +435,24 @@ and Vercel's board, which counts nothing in a channel, leaves them out.
422
435
  would. It needs `read` and `post` there. `created` is false for one that's
423
436
  there already, made by a post or another create, which it leaves as it is.
424
437
 
438
+ `{ private: true }` closes it to everyone but you, with the grant methods
439
+ alone: a grant letting you in at `<path>/`, then one closing `<path>/` to
440
+ `everyone`, then the channel, answered as `grants`. Before it writes anything,
441
+ it refuses a caller that's neither a person nor a project's deployment (400
442
+ `no_own_principal`), one that can't list grants, a path a grant other than
443
+ `*`'s reaches (409 `channel_granted`, naming it), since that grant would still
444
+ let in whom it names, and a path where it or a channel under it is there (409
445
+ `channel_exists`), since closing `security/` closes `security/incidents` too.
446
+ A failure part way never shuts you out: it leaves the channel open with a
447
+ grant too many, or closed and not made yet. A board that keeps no grants fails
448
+ on the listing, with nothing made. Once its own grant is made, it lists the
449
+ grants again and takes its own back if another reaches the path, so two people
450
+ making the same channel at once never both keep a way in. Once the lock is
451
+ made, it lists them a last time: a grant someone made before the lock landed,
452
+ or its own two changed (someone added to its grant, or the lock opened), would
453
+ still let them in, so it takes both of its grants back, the lock first, and
454
+ refuses with `channel_granted`.
455
+
425
456
  `discovery()` is the backend's: on `local()`, the board's own, and with
426
457
  `BOARD_URL` set, the board at that URL's.
427
458
 
@@ -99,7 +99,7 @@ a refused write it can read answers 403. `GET /me` returns the caller's
99
99
  | GET | `/` | Discovery (no token): `{ version, url, audience, team_id, project_id, sync, wake_by_path? }`, where `sync` lists each entry's `key` and `platform`, and `wake_by_path` says `POST /watchers` takes a `path`. A board with no backend has none: it answers only wake-ups and webhooks |
100
100
  | GET | `/me` | Who this token and profile write as: `{ actor, principal, kind, handle, name, avatar, profile, session, expiresAt, can }`, where `can` maps each channel pattern to its permissions |
101
101
  | GET | `/channels` | `{ channels, cursor }`: each `{ path, lastIndex?, messages?, threads? }`, sorted by path. A board that doesn't count them, as one on Vercel's API doesn't, leaves the counts out |
102
- | POST | `/channels` | `{ path }`: makes a channel before anything posts to it. `{ channel, created }`, 201 when it made it, and 200 with `created: false` for one that's there, which it leaves as it is |
102
+ | POST | `/channels` | `{ path }`: makes a channel before anything posts to it. `{ channel, created }`, 201 when it made it, and 200 with `created: false` for one that's there, which it leaves as it is. A key it doesn't know is 400, so `private` makes nothing |
103
103
  | GET | `/actors` | `{ actors, cursor }`: each `{ id, kind, handle, name, avatar }`, sorted by handle |
104
104
  | GET | `/messages` | `{ messages, cursor }`, filtered. See [Listing messages](#listing-messages) |
105
105
  | GET | `/threads` | `{ threads, cursor }`: a summary per matching thread. See [Listing threads](#listing-threads) |
@@ -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
@@ -51,6 +51,30 @@ that secret as the credential, as `BOARD_TOKEN` sends it. `vb conformance`
51
51
  passes it. From code, pass your own, which a backend of your own can make with
52
52
  `board({ backend })`, or that check is skipped.
53
53
 
54
+ Every grant it makes is in `conformance/grants/`, the same subtree and the same
55
+ channels each run, so a run leaves no channel behind and no grant reaches
56
+ outside it. It revokes them all when a check ends, and a revoke that fails
57
+ fails the check. Two runs on one board at once see each other's grants there,
58
+ so run one at a time, on a scratch board.
59
+
60
+ The grants checks name a project, a GitHub repository, a person who's a
61
+ viewer, and an app installed on the team. A board that verifies tokens
62
+ itself, as `vb serve` does, takes the made-up IDs they use by default, and
63
+ skips the app's check, since it has no apps. One that looks names up, as a
64
+ board on Vercel's API does, needs real ones on its team, or skips the checks
65
+ that name them: pass `principals`, with a repository no grant names. None may
66
+ be the run's own project, repository, or app, since the checks would change
67
+ what the run itself may do: it throws before it writes anything, or, for a
68
+ project named by name, which only the board can resolve, after one grant that
69
+ changes nothing for the run, which it revokes.
70
+
71
+ ```ts scripts/conformance.ts
72
+ import { board } from '@vercel/board'
73
+ import { conformance } from '@vercel/board/conformance'
74
+
75
+ const report = await conformance(board(), { principals: { project: 'web', repository: 'acme/web', viewer: 'val@acme.com', app: 'ship' } })
76
+ ```
77
+
54
78
  ## What it checks
55
79
 
56
80
  The whole protocol, on every board:
@@ -89,10 +113,10 @@ Then the rest, a group each in the report:
89
113
  | Group | Check |
90
114
  | --- | --- |
91
115
  | `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 |
116
+ | `grants` | grants a project, lists it, and revokes it twice. Makes a second grant for the same principals, adds a repository and the project again (joining its environments) 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. Through `explain`, in `conformance/grants/`: the most specific pattern decides, then the closest principal there, ties add up, `everyone` lets no one in and loses to `all-projects`, and a viewer reads but neither posts nor manages. Names an app and keeps it by client ID, then every app as a group. A token without `manage` changes no grant, and one with it only under `conformance/grants/inner/` only there. A token kept out of a pattern grants no one past it, even once `everyone` is kept out too, and lets no one in while `everyone` gets more than it has somewhere. Skipped when the token can't change the board's grants, when the board mints no tokens (501, 404, or 403), for a caller no grant could keep in a pattern closed to everyone, without a viewer or an app to check (a local board has no apps), for a name the board can't look up, for a member shut out under a lock (a run couldn't lift the lock after), and across teams, which isn't specified yet |
93
117
  | `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
118
  | `attachments` | uploads a file, posts it, and downloads it |
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 |
119
+ | `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, and on a board token Vercel's API won't register watchers for yet (403 `board_token_unsupported`) |
96
120
  | `sync` | imports a message as a platform user of its own (`conformance:user:<id>`), finds it by its platform IDs, imports it again to the same message, refuses a second root from the same platform thread, records a receipt and reads the copy back, lists where the thread is synced with it, answers 404 for a link no sync there knows, and deletes it. Pushes two events on one platform thread to the sync's inbox, and the first again, then leases them one at a time and in order, each once the one before is acked. Pulls the sync's `@sync` match for a post. Each of these is skipped when the token can't register a sync or `sync` in the channel, or already has watchers or a sync registered. Then, registering nothing: reads a post's and a reply's `noSync` back |
97
121
 
98
122
  Every board answers all of them: see
@@ -100,12 +124,14 @@ Every board answers all of them: see
100
124
  schedules, grants, or files, or issue no tokens, and say so: one that answers
101
125
  one of those groups' checks with a 501 has it skipped, `not kept here`, with
102
126
  what the board said. A board that's meant to keep them and doesn't yet answers
103
- otherwise, and fails: Vercel's boards fail both groups until Vercel's API keeps
104
- grants and tokens. A
127
+ otherwise, and fails: Vercel's boards fail the tokens group until Vercel's API
128
+ keeps tokens. A
105
129
  [backend of your own](../01-board/01-mounting.md#a-backend-of-your-own) that
106
130
  keeps no grants, schedules, or files answers 501 `no_grants`, `no_scheduler`,
107
131
  or `no_files`.
108
- `vb serve` keeps everything, so it passes every check.
132
+ `vb serve` keeps everything, so it passes every check but four: it has no
133
+ team roles to cap anyone with and no apps, no run can check a member shut out
134
+ under a lock, and grants across teams aren't specified yet.
109
135
 
110
136
  ## The report
111
137
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/board",
3
- "version": "0.33.0",
3
+ "version": "0.35.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";