@vercel/board 0.32.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 (167) hide show
  1. package/README.md +25 -20
  2. package/dist/{access-CY5xVMIK.mjs → access-CdBcYPQH.mjs} +170 -13
  3. package/dist/access.d.mts +4 -5
  4. package/dist/access.mjs +5 -5
  5. package/dist/{actors-Bm-ojWWT.mjs → actors-MrIEr9LI.mjs} +3 -3
  6. package/dist/auth-DjoJygbG.mjs +599 -0
  7. package/dist/{auth-K8dY1nBY.d.mts → auth-aaoKt5DK.d.mts} +133 -100
  8. package/dist/backend-local.d.mts +28 -0
  9. package/dist/backend-local.mjs +2 -0
  10. package/dist/{backend-DxE9wGKm.d.mts → backend-u1sVvybh.d.mts} +108 -55
  11. package/dist/{chat-provider-DkFp2hrh.mjs → chat-provider-9hCT654s.mjs} +2 -2
  12. package/dist/{chat-provider-BChYrrA7.d.mts → chat-provider-De0iDnUB.d.mts} +2 -3
  13. package/dist/cli-commands.d.mts +1 -1
  14. package/dist/cli-commands.mjs +1 -1
  15. package/dist/cli-embedded.d.mts +2 -2
  16. package/dist/cli-embedded.mjs +1 -1
  17. package/dist/cli.mjs +6 -6
  18. package/dist/{commands-DsnQKTdB.mjs → commands-B8oZEByR.mjs} +37 -52
  19. package/dist/{commands-CpyPV_tk.d.mts → commands-BkVMdXP1.d.mts} +9 -6
  20. package/dist/{conformance-3RBKxwbp.mjs → conformance-gqYBkXFS.mjs} +79 -86
  21. package/dist/conformance.d.mts +1 -1
  22. package/dist/conformance.mjs +1 -1
  23. package/dist/{engine-DurYIRt8.mjs → engine-rtOVWsiF.mjs} +6 -8
  24. package/dist/{errors-CJXhhzvT.mjs → errors-D8ifv16L.mjs} +75 -6
  25. package/dist/{events-lujPA3gQ.mjs → events-IQg0k281.mjs} +2 -2
  26. package/dist/exports-Bx2dGpzr.mjs +3252 -0
  27. package/dist/exports-uwRl5qIj.d.mts +4 -0
  28. package/dist/{external-D3p5T57R.mjs → external-CYe424fO.mjs} +1 -1
  29. package/dist/index-D6mK0Ial.d.mts +11 -0
  30. package/dist/index.d.mts +10 -9
  31. package/dist/index.mjs +21 -8
  32. package/dist/index.node.d.mts +6 -7
  33. package/dist/index.node.mjs +3 -3
  34. package/dist/inspect/app.js +95 -95
  35. package/dist/{internal-CvsrprnU-zZMpDiRY.mjs → internal-CvsrprnU-CEPOUpAv.mjs} +63 -43
  36. package/dist/local-CPz22MQ8.mjs +9225 -0
  37. package/dist/{main-CcYDo9Hb.mjs → main-DScDKwQN.mjs} +129 -54
  38. package/dist/{backend-a2/store-memory.mjs → memory-7RRnLa4X.mjs} +3 -3
  39. package/dist/middleware-BjYpk4yq.mjs +103 -0
  40. package/dist/{provider-gynDUoyW.d.mts → provider-hB8QNrwm.d.mts} +369 -3
  41. package/dist/{client-COfYrgfV.d.mts → routes-De4W6lEs.d.mts} +997 -367
  42. package/dist/{schemas-DBmUO6pr.mjs → schemas-BG205xds.mjs} +2 -5
  43. package/dist/{serve-Bplieh0C.mjs → serve-B1noQRkn.mjs} +33 -24
  44. package/dist/{node-BgeGcwX0.mjs → server-Ov6GBJ8j.mjs} +419 -6
  45. package/dist/{serving-Y7s7VDjB.mjs → serving-2s7lqSBS.mjs} +1 -1
  46. package/dist/{sql-E1K5g_ih.mjs → sql-BQzKUqQt.mjs} +349 -114
  47. package/dist/sqlite-DCtZFEVm.mjs +30 -0
  48. package/dist/{sqlite-db-CzcD_FW8.mjs → sqlite-db-qLTs52Ny.mjs} +2 -3
  49. package/dist/{store-codec-pAG2oPgQ-SqDXlPBR.mjs → store-N8PXxDAS-BdL4Sq-f.mjs} +6 -2
  50. package/dist/{store-memory-B0PkVSuQ.mjs → store-memory-CKQVEzXN.mjs} +2 -4
  51. package/dist/store-memory-OdGsc-t_.mjs +2 -0
  52. package/dist/{store-polling-BZt2Rf3D-Div-bJ_D.mjs → store-polling-BZt2Rf3D-oh3aU_An.mjs} +1 -1
  53. package/dist/store-sqlite-CTxAVCcz.mjs +2 -0
  54. package/dist/{store-sqlite-D85t3tE7.mjs → store-sqlite-D6fIszST.mjs} +3 -4
  55. package/dist/sync-chat-sdk.d.mts +2 -2
  56. package/dist/sync-chat-sdk.mjs +2 -2
  57. package/dist/sync-github.d.mts +2 -2
  58. package/dist/sync-github.mjs +2 -2
  59. package/dist/sync-linear.d.mts +3 -3
  60. package/dist/sync-linear.mjs +2 -2
  61. package/dist/sync-slack.d.mts +3 -3
  62. package/dist/sync-slack.mjs +4 -4
  63. package/dist/sync.d.mts +2 -2
  64. package/dist/sync.mjs +2 -2
  65. package/dist/{watchers-hash-CurCzwhe.mjs → targets-aMdbp84G.mjs} +134 -16
  66. package/dist/{tokens-C7kYyrAG.mjs → tokens-LHLrnV_P.mjs} +15 -43
  67. package/docs/01-board/01-mounting.md +245 -288
  68. package/docs/01-board/03-identity.md +42 -50
  69. package/docs/01-board/04-messages.md +15 -14
  70. package/docs/01-board/05-reading.md +3 -3
  71. package/docs/01-board/06-watchers.md +58 -105
  72. package/docs/01-board/07-schedules.md +21 -41
  73. package/docs/01-board/08-middleware.md +11 -17
  74. package/docs/01-board/09-access.md +187 -343
  75. package/docs/01-board/10-local.md +81 -0
  76. package/docs/01-quickstart.md +49 -126
  77. package/docs/02-sync/01-overview.md +25 -80
  78. package/docs/02-sync/02-functions.md +10 -16
  79. package/docs/02-sync/03-slack.md +13 -26
  80. package/docs/02-sync/04-github.md +8 -20
  81. package/docs/02-sync/07-linear.md +6 -10
  82. package/docs/03-guides/02-inspector.md +3 -3
  83. package/docs/03-guides/03-ci.md +88 -128
  84. package/docs/03-guides/04-triage.md +7 -15
  85. package/docs/03-guides/05-agent-factory.md +29 -36
  86. package/docs/04-reference/01-cli.md +113 -38
  87. package/docs/04-reference/02-board.md +79 -82
  88. package/docs/04-reference/03-http.md +138 -69
  89. package/docs/04-reference/05-conformance.md +32 -46
  90. package/docs/index.md +41 -65
  91. package/package.json +12 -83
  92. package/dist/a2-DiDc77Uf.mjs +0 -4238
  93. package/dist/access-DPcrKIH_.d.mts +0 -37
  94. package/dist/auth-8pRZnF1M.mjs +0 -393
  95. package/dist/backend-a2/blob-vercel.d.mts +0 -8
  96. package/dist/backend-a2/blob-vercel.mjs +0 -81
  97. package/dist/backend-a2/contract.d.mts +0 -828
  98. package/dist/backend-a2/contract.mjs +0 -5
  99. package/dist/backend-a2/scheduler-local.d.mts +0 -11
  100. package/dist/backend-a2/scheduler-local.mjs +0 -2
  101. package/dist/backend-a2/scheduler-qstash.d.mts +0 -79
  102. package/dist/backend-a2/scheduler-qstash.mjs +0 -522
  103. package/dist/backend-a2/scheduler-vercel.d.mts +0 -38
  104. package/dist/backend-a2/scheduler-vercel.mjs +0 -204
  105. package/dist/backend-a2/store-memory.d.mts +0 -11
  106. package/dist/backend-a2/store-postgres.d.mts +0 -38
  107. package/dist/backend-a2/store-postgres.mjs +0 -2977
  108. package/dist/backend-a2/store-redis-http.d.mts +0 -17
  109. package/dist/backend-a2/store-redis-http.mjs +0 -520
  110. package/dist/backend-a2/store-redis.d.mts +0 -31
  111. package/dist/backend-a2/store-redis.mjs +0 -88
  112. package/dist/backend-a2/store-sqlite.d.mts +0 -12
  113. package/dist/backend-a2/store-sqlite.mjs +0 -31
  114. package/dist/backend-a2.d.mts +0 -2633
  115. package/dist/backend-a2.mjs +0 -3
  116. package/dist/backend-http-CaN06CaD.d.mts +0 -672
  117. package/dist/backend-http-CoaCghuJ.mjs +0 -18
  118. package/dist/backend-http-l5A8UmL-.mjs +0 -585
  119. package/dist/backend-http.d.mts +0 -10
  120. package/dist/backend-http.mjs +0 -2
  121. package/dist/backend-http.node.d.mts +0 -10
  122. package/dist/backend-http.node.mjs +0 -2
  123. package/dist/backend-vercel-BE65okBC.mjs +0 -86
  124. package/dist/backend-vercel-CVxoTNF2.mjs +0 -1744
  125. package/dist/backend-vercel-jg-6PAgD.d.mts +0 -674
  126. package/dist/backend-vercel.d.mts +0 -9
  127. package/dist/backend-vercel.mjs +0 -11
  128. package/dist/backend-vercel.node.d.mts +0 -17
  129. package/dist/backend-vercel.node.mjs +0 -2
  130. package/dist/blob-Bx8QPWEd.d.mts +0 -40
  131. package/dist/blob-WbB2DJKn.mjs +0 -201
  132. package/dist/errors-2vGs49Db.d.mts +0 -16
  133. package/dist/exports-BnUZuRm9.mjs +0 -1389
  134. package/dist/exports-u5mApVvn.d.mts +0 -5
  135. package/dist/files-SniSmeEr.mjs +0 -47
  136. package/dist/folds-DLUzfibJ.d.mts +0 -558
  137. package/dist/folds-DsWfIftc.mjs +0 -208
  138. package/dist/index-UXpTPWNc.d.mts +0 -11
  139. package/dist/index.default-Dp8gexln.mjs +0 -12
  140. package/dist/local-C76Fy5ad.mjs +0 -44
  141. package/dist/middleware-BavYSDUa.mjs +0 -62
  142. package/dist/platform-B4TnJtWu-Do3agKr5.mjs +0 -32
  143. package/dist/project-4Vl7_uy5.mjs +0 -124
  144. package/dist/redis-tables-BFRj_SEJ.mjs +0 -3895
  145. package/dist/reducer-Bswr11ar-P324o9vn.mjs +0 -74
  146. package/dist/reducer-CYPHsSmd-BXjGiptm.d.mts +0 -170
  147. package/dist/reducers-DQVSP3kk.mjs +0 -538
  148. package/dist/retryable-lazy-DZWmHpii-DpTc5PIP.mjs +0 -19
  149. package/dist/scheduler-task-X1SToDjP-D2Il2rln.mjs +0 -69
  150. package/dist/server-B9gu0qi1-DI1WvcVK.d.mts +0 -391
  151. package/dist/server-DX7mM6nm-D7N_7bug.mjs +0 -3611
  152. package/dist/server-wIpAEjpX.mjs +0 -17
  153. package/dist/session-clear-XJYpmUpg-2q8l_FJR.mjs +0 -63
  154. package/dist/store-DEzcHZOA-B-5vhxef.d.mts +0 -540
  155. package/dist/store-N8PXxDAS-DWWgv-Vz.mjs +0 -5
  156. package/dist/store-memory-4IBl0Ztu.mjs +0 -2
  157. package/dist/store-presence-polling-JuAy2Ck2-Dh-g_KYM.mjs +0 -109
  158. package/dist/store-sqlite-iBTYYKBj.mjs +0 -2
  159. package/dist/stream-buffer-DrTyiIuo-Be10yOBR.mjs +0 -53
  160. package/dist/targets-Cgjs29T0.mjs +0 -33
  161. package/dist/types-CmrFjpml.d.mts +0 -102
  162. package/dist/wait-until-Dw4XrIDQ.mjs +0 -42
  163. package/docs/01-board/02-database.md +0 -258
  164. package/docs/04-reference/04-log.md +0 -247
  165. package/sql/postgres/board.sql +0 -145
  166. package/sql/postgres/notifications.sql +0 -24
  167. package/sql/postgres/schema.sql +0 -451
@@ -1,37 +0,0 @@
1
- //#region src/server/access.d.ts
2
- /**
3
- * What a principal may do in a channel. `read` covers messages, threads,
4
- * `/events`, and schedules; `post` starts threads and edits your own messages;
5
- * `manage` is the board's own bookkeeping (inbox, sources).
6
- */
7
- declare const PERMISSIONS: readonly ['read', 'post', 'react', 'label', 'sync', 'manage'];
8
- type Permission = (typeof PERMISSIONS)[number];
9
- /** `*`, a channel (`feedback`), or a channel and its subtree (`feedback/`). */
10
- type ChannelPattern = string;
11
- type Grant = 'all' | readonly Permission[];
12
- /** `'all'`, a list for every channel (`['post']` is `{ '*': ['post'] }`), or a map from pattern to grant. */
13
- type Can = Grant | Readonly<Record<ChannelPattern, Grant>>;
14
- /** Each pattern's whole answer, implications included. */
15
- type AccessSummary = Readonly<Record<ChannelPattern, readonly Permission[]>>;
16
- type Access = {
17
- can(permission: Permission, channel: string): boolean;
18
- /** The hot path for feeds: memoized per channel. */
19
- readable(channel: string): boolean;
20
- /** `read` in every channel, including ones that don't exist yet. */
21
- readsAll: boolean;
22
- /** `permission` in every channel, including ones that don't exist yet: `everywhere('manage')` is full access. */
23
- everywhere(permission: Permission): boolean;
24
- /** `permission` in some channel. */
25
- anywhere(permission: Permission): boolean;
26
- /** Only what both this and `scope` allow, channel by channel. It never widens. */
27
- narrow(scope: Can | Access): Access;
28
- /** Each pattern and its permissions, `*` first and the rest sorted; an empty `*` is left out. */
29
- summary(): AccessSummary;
30
- };
31
- /** Access from config: `'all'`, a list for every channel, or a map from pattern to grant. Throws on a bad pattern or permission. */
32
- declare function compileAccess(can: Can): Access;
33
- declare const FULL_ACCESS: Access;
34
- /** What any of `accesses` allows, channel by channel: grants that match one principal add up. */
35
- declare function union(accesses: readonly Access[]): Access;
36
- //#endregion
37
- export { FULL_ACCESS as a, compileAccess as c, ChannelPattern as i, union as l, AccessSummary as n, Grant as o, Can as r, Permission as s, Access as t };
@@ -1,393 +0,0 @@
1
- import { a as forbidden, l as unauthorized, r as badRequest } from "./errors-CJXhhzvT.mjs";
2
- import { i as parseScope, o as union, r as compileAccess, t as FULL_ACCESS } from "./access-CY5xVMIK.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
- /** A token no rule matches, and the rule that would let it in. */
18
- const notInAccess = (rule) => forbidden(`this token can't use this board: add ${rule} to access`);
19
- /** A rule's `can`, compiled. A rule without one says which rule and what to write. */
20
- function accessOf(rule, can) {
21
- if (can === void 0 || can === null) throw new Error(`${rule} needs can: say what it may do, like can: { 'ci/': ['read', 'post'] }, or can: 'all'`);
22
- return compileAccess(can);
23
- }
24
- const oneOf = (value, allowed) => allowed === void 0 || typeof value === "string" && (typeof allowed === "string" ? [allowed] : allowed).includes(value);
25
- /**
26
- * A Vercel project's deployments, by name or ID. A name is only unique within
27
- * a team, so without `team` it means the board's own team, and matches nothing
28
- * when that isn't known. An ID is unique on Vercel, so it matches on any team.
29
- * `'self'` is the board's own project: its deployments in the environment the
30
- * board runs in have full access unless a rule says otherwise, and its other
31
- * environments have none unless one lists them. Its development tokens are
32
- * people, which no rule changes.
33
- */
34
- function vercelProject(options) {
35
- if (options.project === "self" && options.team !== void 0) throw new Error("vercelProject({ project: 'self' }) is the board's own project: drop team");
36
- return {
37
- issuer: "vercel",
38
- access: accessOf(`vercelProject({ project: '${options.project}' })`, options.can),
39
- matches: (claims, { teamId, projectId }) => (options.project === "self" ? projectId !== null && claims.project_id === projectId : claims.project_id === options.project || claims.project === options.project && (options.team === void 0 ? teamId !== null && claims.owner_id === teamId : claims.owner === options.team || claims.owner_id === options.team)) && oneOf(claims.environment, options.environments)
40
- };
41
- }
42
- /**
43
- * A GitHub Actions workflow. A `pull_request` run's token carries
44
- * `ref: refs/pull/<n>/merge`, so match those on `event` and `workflow`, not `ref`.
45
- */
46
- function githubActions(options) {
47
- return {
48
- issuer: "github",
49
- access: accessOf(`githubActions({ repository: '${options.repository}' })`, options.can),
50
- matches: (claims) => claims.repository === options.repository && oneOf(claims.event_name, options.event) && (options.ref === void 0 || claims.ref === options.ref) && (options.workflow === void 0 || typeof claims.workflow_ref === "string" && claims.workflow_ref.startsWith(`${options.repository}/${options.workflow}@`))
51
- };
52
- }
53
- /**
54
- * Any OIDC issuer's tokens: GitLab, Buildkite, a cloud's workload identity.
55
- * The issuer is pinned here, and only issuers some rule names are trusted or
56
- * have their keys fetched. Every listed claim must match exactly (a list is
57
- * any of its values), and there must be at least one, since an issuer signs
58
- * tokens for everyone it serves. The principal is `oidc:<issuer host and path>:<sub>`,
59
- * with any `:` or `%` in the issuer part percent-encoded, so it ends at the first `:`.
60
- */
61
- function oidc(options) {
62
- let url;
63
- try {
64
- url = new URL(options.issuer);
65
- } catch {
66
- throw new Error(`oidc: issuer must be a URL, got ${options.issuer}`);
67
- }
68
- if (url.protocol !== "https:" || url.search || url.hash || url.username || url.password) throw new Error(`oidc: issuer must be an https URL with no query or credentials, got ${options.issuer}`);
69
- if (VERCEL_ISSUER.test(options.issuer)) throw new Error("oidc: use vercelProject() for Vercel tokens");
70
- if (options.issuer === "https://token.actions.githubusercontent.com") throw new Error("oidc: use githubActions() for GitHub Actions tokens");
71
- const required = Object.entries(options.claims);
72
- if (required.length === 0) throw new Error(`oidc: name at least one claim to match for ${options.issuer}`);
73
- for (const [name, allowed] of required) {
74
- const values = typeof allowed === "string" ? [allowed] : Array.isArray(allowed) ? allowed : [];
75
- if (values.length === 0 || values.some((value) => typeof value !== "string" || value === "")) throw new Error(`oidc: claim ${name} has no value to match for ${options.issuer}`);
76
- }
77
- return {
78
- issuer: "oidc",
79
- url: options.issuer,
80
- access: accessOf(`oidc({ issuer: '${options.issuer}' })`, options.can),
81
- matches: (claims) => required.every(([name, allowed]) => oneOf(claims[name], allowed))
82
- };
83
- }
84
- const VERCEL_ISSUER = /^https:\/\/oidc\.vercel\.com(?:\/[a-z0-9-]+)?$/;
85
- const GITHUB_ISSUER = "https://token.actions.githubusercontent.com";
86
- /**
87
- * `gitlab.com`, `example.com/oidc`, `ci.test%3A8443`: an issuer as a principal
88
- * names it. A `:` (a port) and a `%` are percent-encoded, so the name has no `:`
89
- * and the `sub` after it can hold anything. Issuers that differ only in what the
90
- * URL normalizes (a trailing slash, the host's case) share a name, so the board
91
- * refuses to trust two of them.
92
- */
93
- const issuerName = (iss) => {
94
- const url = new URL(iss);
95
- return `${url.host}${url.pathname.replace(/\/+$/, "")}`.replace(/[%:]/g, (char) => char === "%" ? "%25" : "%3A");
96
- };
97
- /** OIDC issuers to trust, checked: two that name the same principals can't both be. */
98
- function trustedIssuers(issuers) {
99
- const named = /* @__PURE__ */ new Map();
100
- for (const iss of issuers) {
101
- const name = issuerName(iss);
102
- const other = named.get(name);
103
- if (other !== void 0 && other !== iss) throw new Error(`access: oidc issuers ${other} and ${iss} name the same principals, oidc:${name}:<sub>: pin one of them`);
104
- named.set(name, iss);
105
- }
106
- return new Set(issuers);
107
- }
108
- /** The OIDC issuers rules name: the only ones whose tokens are verified for them. */
109
- const issuersOf = (rules) => [...new Set(rules.flatMap((rule) => typeof rule !== "function" && rule.issuer === "oidc" ? [rule.url] : []))];
110
- /** What a board token starts with, so board() knows its own before it tries any other verifier. */
111
- const BOARD_TOKEN_PREFIX = "board_";
112
- /**
113
- * A board token's SHA-256, hex: what the board keeps instead of the secret, both when it mints one
114
- * and when a request carries one. A token is 32 random bytes, so no salt or key is needed.
115
- */
116
- async function tokenHash(secret) {
117
- const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(secret)));
118
- return Array.from(digest, (byte) => byte.toString(16).padStart(2, "0")).join("");
119
- }
120
- /**
121
- * What a grant or a token left without `can` gives: what Vercel's API gives a project it lets use a
122
- * board. Frozen all the way down: board reads it for every such grant, and @vercel/board/access
123
- * exports it, so code that imports it can't widen them.
124
- */
125
- const DEFAULT_CAN = Object.freeze({ "*": Object.freeze([
126
- "read",
127
- "post",
128
- "react",
129
- "label"
130
- ]) });
131
- const GRANT_CLAIMS_MAX = 32;
132
- const GRANT_VALUES_MAX = 32;
133
- const GRANT_VALUE_MAX = 1e3;
134
- const invalidGrant = (message) => badRequest(message, "invalid_grant");
135
- /** Whether `host` names something on the board's own network rather than on the internet. */
136
- function privateHost(host) {
137
- const name = host.toLowerCase().replace(/\.$/, "");
138
- if (name.startsWith("[") || /^\d+(\.\d+){3}$/.test(name) || /^\d+$/.test(name)) return true;
139
- if (!name.includes(".") || name === "localhost") return true;
140
- return /\.(localhost|local|internal|home|lan|corp|intranet)$/.test(name);
141
- }
142
- /**
143
- * A grant checked and put in one form: its issuer, its claims with keys and lists sorted, its
144
- * `can`, and the key that says it's the same grant as another. A 400 `invalid_grant` that says
145
- * what to write. `trusted`: the issuers the board's rules and other grants name, which no two may
146
- * share principals between.
147
- */
148
- function checkGrant(spec, trusted) {
149
- const { issuer } = spec;
150
- if (typeof issuer !== "string" || issuer === "") throw invalidGrant("a grant needs an issuer: vercel, github, or an https URL");
151
- if (issuer !== "vercel" && issuer !== "github") {
152
- let url;
153
- try {
154
- url = new URL(issuer);
155
- } catch {
156
- throw invalidGrant(`a grant's issuer is vercel, github, or an https URL, got ${issuer}`);
157
- }
158
- if (VERCEL_ISSUER.test(issuer)) throw invalidGrant("write the issuer as vercel, and another team's projects with owner_id");
159
- if (issuer === "https://token.actions.githubusercontent.com") throw invalidGrant("write the issuer as github");
160
- 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}`);
161
- if (privateHost(url.hostname)) throw invalidGrant(`a grant's issuer is on the internet, not ${url.hostname}`);
162
- const name = issuerName(issuer);
163
- const other = trusted.find((candidate) => candidate !== issuer && /^https:/.test(candidate) && issuerName(candidate) === name);
164
- if (other !== void 0) throw invalidGrant(`issuers ${other} and ${issuer} name the same principals, oidc:${name}:<sub>: use ${other}`);
165
- }
166
- const entries = typeof spec.claims === "object" && spec.claims !== null ? Object.entries(spec.claims) : [];
167
- if (entries.length === 0) throw invalidGrant(`name at least one claim for ${issuer}: its issuer signs tokens for everyone it serves`);
168
- if (entries.length > GRANT_CLAIMS_MAX) throw invalidGrant(`a grant names at most ${GRANT_CLAIMS_MAX} claims`);
169
- const claims = {};
170
- for (const [name, value] of entries.sort(([a], [b]) => a.localeCompare(b))) {
171
- const values = typeof value === "string" ? [value] : Array.isArray(value) ? [...new Set(value)] : [];
172
- 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`);
173
- 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`);
174
- const sorted = values.sort();
175
- claims[name] = sorted.length === 1 ? sorted[0] : sorted;
176
- }
177
- 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");
178
- 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");
179
- const can = spec.can ?? DEFAULT_CAN;
180
- try {
181
- compileAccess(can);
182
- } catch (error) {
183
- throw invalidGrant(error.message);
184
- }
185
- return {
186
- issuer,
187
- claims,
188
- can,
189
- key: JSON.stringify([issuer, claims])
190
- };
191
- }
192
- /** Whether a verified token's facts are a grant's: its issuer, and every claim it names. */
193
- function grantMatches(grant, facts) {
194
- if (!(grant.issuer === "vercel" || grant.issuer === "github" ? facts.issuer === grant.issuer : facts.issuer === "oidc" && facts.iss === grant.issuer)) return false;
195
- return Object.entries(grant.claims).every(([name, allowed]) => {
196
- const value = facts.claims[name];
197
- if (value === void 0) return false;
198
- const text = String(value);
199
- return typeof allowed === "string" ? text === allowed : allowed.includes(text);
200
- });
201
- }
202
- /** The OIDC issuers grants name past Vercel and GitHub: their tokens are verified too. */
203
- const grantIssuers = (grants) => [...new Set(grants.flatMap((grant) => grant.issuer === "vercel" || grant.issuer === "github" ? [] : [grant.issuer]))];
204
- /**
205
- * What principals may do, under a board's rules: `vercelProject()`, `githubActions()`, `oidc()`,
206
- * and functions of your own, the first that matches deciding, with the board's grants adding to it,
207
- * past the defaults (people, and the board's own deployments in its environment, may do
208
- * everything). Or a host's own function of the principal.
209
- */
210
- function createAuthority(options) {
211
- const rules = typeof options.access === "function" ? [] : options.access;
212
- const host = typeof options.access === "function" ? options.access : null;
213
- const oidcIssuers = trustedIssuers(issuersOf(rules));
214
- /**
215
- * What the rules give a principal, in order: a token's rule when its facts match, a function when
216
- * it answers. Every grant that matches its token adds to that, so a grant never goes unused
217
- * because a rule matched first. The board's own deployments in its environment get everything
218
- * unless a token's rule says otherwise, no function is asked about them, and no grant is theirs;
219
- * a function that answers null refuses, grants or not. A 401 or 403 that says which rule would
220
- * let it in, when nothing does.
221
- */
222
- async function byRules(principal, facts) {
223
- if (facts?.issuer === "host") throw forbidden("this token can't use this board: its board no longer takes a host's principals");
224
- const claims = facts?.claims ?? {};
225
- const own = facts?.issuer === "vercel" ? await options.project() : null;
226
- const context = own ? {
227
- teamId: facts.team ?? own.teamId,
228
- projectId: own.id
229
- } : {
230
- teamId: null,
231
- projectId: null
232
- };
233
- const environment = String(claims.environment ?? "");
234
- const here = boardEnvironment();
235
- const ownDeployment = own !== null && own.id !== null && claims.project_id === own.id;
236
- const ownHere = ownDeployment && here !== null && environment === here;
237
- let ruled = null;
238
- for (const rule of rules) {
239
- if (typeof rule === "function") {
240
- if (ownHere) continue;
241
- const can = await rule(principal);
242
- if (can === void 0) continue;
243
- if (can === null) throw forbidden("this token can't use this board");
244
- ruled = compileAccess(can);
245
- break;
246
- }
247
- if (facts && rule.issuer === facts.issuer && (rule.issuer !== "oidc" || rule.url === facts.iss) && rule.matches(claims, context)) {
248
- ruled = rule.access;
249
- break;
250
- }
251
- }
252
- if (ownHere) return ruled ?? FULL_ACCESS;
253
- if (!facts) {
254
- if (ruled) return ruled;
255
- throw forbidden("this token can't use this board");
256
- }
257
- const grants = options.grants ? await options.grants() : [];
258
- const granted = grants.filter((grant) => grantMatches(grant, facts)).map((grant) => compileAccess(grant.can));
259
- if (ruled) return granted.length > 0 ? union([ruled, ...granted]) : ruled;
260
- if (granted.length > 0) return union(granted);
261
- if (facts.issuer === "oidc" && !oidcIssuers.has(facts.iss) && !grants.some((grant) => grant.issuer === facts.iss)) throw unauthorized(`untrusted issuer: ${facts.iss}`);
262
- if (facts.issuer === "oidc" && !oidcIssuers.has(facts.iss)) throw forbidden("this token can't use this board: no grant lets in its claims");
263
- if (facts.issuer === "oidc") throw notInAccess(`oidc({ issuer: '${facts.iss}', claims, can })`);
264
- if (facts.issuer === "github") throw notInAccess(`githubActions({ repository: '${String(claims.repository)}', can })`);
265
- if (ownDeployment) throw forbidden(`this token can't use this board: it runs in ${here ?? "no Vercel environment"}, so its ${environment || "unnamed"} deployments need vercelProject({ project: 'self', environments: ['${environment}'], can })`);
266
- throw notInAccess(`vercelProject({ project: '${String(claims.project ?? "") || String(claims.project_id)}', can })`);
267
- }
268
- /**
269
- * What a principal may do now, narrowed by its scope: the board's own code and the platform users
270
- * sync writes as everything; anyone else what a host's function says, or under the rules, a person
271
- * everything and anyone else whatever the first rule that matches gives. A host's principal is
272
- * what its kind is, until it expires. A 401 or 403 when it may do nothing.
273
- */
274
- async function grant(principal) {
275
- let access = FULL_ACCESS;
276
- const hosted = principal.facts?.issuer === "host";
277
- if (principal.id.startsWith("board:") || principal.kind === "external" && !hosted) access = FULL_ACCESS;
278
- else {
279
- if (hosted) {
280
- if (!options.hosts) throw forbidden("this token can't use this board: its board no longer takes a host's principals");
281
- const { exp } = principal.facts.claims;
282
- if (typeof exp === "number" && exp * 1e3 <= Date.now()) throw unauthorized("token expired");
283
- }
284
- if (host) {
285
- const can = await host(principal);
286
- if (can === null || can === void 0) throw forbidden("this token can't use this board");
287
- access = compileAccess(can);
288
- } else if (principal.kind !== "person") access = await byRules(principal, (hosted ? void 0 : principal.facts) ?? factsFromId(principal.id));
289
- }
290
- return principal.scope === void 0 ? access : access.narrow(parseScope(principal.scope));
291
- }
292
- /** What a stored principal (a schedule's creator, a watcher's registrant) may do now: null once nothing. */
293
- async function accessNow(principal) {
294
- try {
295
- return await grant(principal);
296
- } catch (error) {
297
- const status = error.status;
298
- if (status === 401 || status === 403) return null;
299
- throw error;
300
- }
301
- }
302
- return {
303
- grant,
304
- accessNow
305
- };
306
- }
307
- /**
308
- * What a principal may do under `rules` (`vercelProject()`, `githubActions()`, `oidc()`, and
309
- * functions of your own), the first that matches deciding, past the defaults: people, and the
310
- * board's own deployments in the environment it runs in, may do everything. Its scope narrows what
311
- * it gets. A 401 or 403 that names the rule that would let it in, when it may do nothing.
312
- */
313
- function compileRules(rules, board) {
314
- return createAuthority({
315
- access: rules,
316
- project: () => board.project(),
317
- hosts: true
318
- }).grant;
319
- }
320
- /**
321
- * The Vercel environment the board runs in: `production`, `preview`, or a
322
- * custom environment's name. `VERCEL_TARGET_ENV` names custom environments,
323
- * where `VERCEL_ENV` says `preview`. Null outside Vercel, where only people
324
- * get in without a rule.
325
- */
326
- const boardEnvironment = () => process.env.VERCEL_TARGET_ENV || process.env.VERCEL_ENV || null;
327
- /**
328
- * What a principal's ID still says, for one stored before the board kept
329
- * claims: a deployment's project ID and environment. A workflow's ID names
330
- * neither its repository nor its run, so it says nothing, and a rule that
331
- * needs more than the ID no longer matches.
332
- */
333
- function factsFromId(id) {
334
- const deployment = id.match(/^vercel:project:([^:]+):([^:]+)$/);
335
- return deployment ? {
336
- issuer: "vercel",
337
- iss: "",
338
- claims: {
339
- project_id: deployment[1],
340
- environment: deployment[2]
341
- }
342
- } : null;
343
- }
344
- /** What marks `oidcTokens()`, so board() can tell it makes no host's principals. */
345
- const TOKENS = Symbol("board.oidcTokens");
346
- /** The principals `oidcTokens()` made: board() takes them as they are, and checks the rest as a host's. */
347
- const verifiedTokens = /* @__PURE__ */ new WeakSet();
348
- /** Marks a principal `oidcTokens()` made. */
349
- function markVerified(principal) {
350
- verifiedTokens.add(principal);
351
- return principal;
352
- }
353
- /** Whether `authenticate` is `oidcTokens()`'s alone: it makes no host's principals. */
354
- const verifiesTokens = (authenticate) => TOKENS in authenticate;
355
- /** Whether `oidcTokens()` made `principal`, as opposed to a host's own verifier. */
356
- const fromTokens = (principal) => verifiedTokens.has(principal);
357
- const PRINCIPAL_ID = /^[a-z][a-z0-9-]*:[a-z][a-z0-9-]*:[^\s+\]]{1,200}$/;
358
- const KINDS = [
359
- "person",
360
- "deployment",
361
- "workflow",
362
- "external"
363
- ];
364
- /**
365
- * Checks what a host's own verifier returned. A malformed principal is the host's bug, so it
366
- * fails the request rather than letting a half-identity write.
367
- */
368
- function hostPrincipal(value) {
369
- const fail = (why) => {
370
- throw new TypeError(`authenticate returned an invalid principal: ${why}`);
371
- };
372
- if (typeof value !== "object" || value === null) fail("not an object");
373
- 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)}`);
374
- if (!KINDS.includes(value.kind)) fail(`kind must be one of ${KINDS.join(", ")}`);
375
- if (typeof value.handle !== "string" || !/^\S{1,64}$/.test(value.handle)) fail("handle must be 1-64 characters, no spaces");
376
- const expiresAt = value.expiresAt ?? null;
377
- if (expiresAt !== null && (!(expiresAt instanceof Date) || Number.isNaN(expiresAt.getTime()))) fail("expiresAt must be a Date or null");
378
- if (expiresAt !== null && expiresAt.getTime() <= Date.now()) throw unauthorized("token expired");
379
- const claims = expiresAt === null ? {} : { exp: Math.floor(expiresAt.getTime() / 1e3) };
380
- return {
381
- id: value.id,
382
- kind: value.kind,
383
- handle: value.handle,
384
- expiresAt,
385
- facts: {
386
- issuer: "host",
387
- iss: "",
388
- claims
389
- }
390
- };
391
- }
392
- //#endregion
393
- export { wroteAs as C, verifiesTokens as S, oidc as _, VERCEL_ISSUER as a, trustedIssuers as b, compileRules as c, githubActions as d, grantIssuers as f, markVerified as g, issuersOf as h, TOKENS as i, createAuthority as l, issuerName as m, DEFAULT_CAN as n, authenticates as o, hostPrincipal as p, GITHUB_ISSUER as r, checkGrant as s, BOARD_TOKEN_PREFIX as t, fromTokens as u, privateHost as v, vercelProject as x, tokenHash as y };
@@ -1,8 +0,0 @@
1
- import { t as BlobStore } from "../blob-Bx8QPWEd.mjs";
2
- //#region src/blob/vercel.d.ts
3
- export declare function vercelBlob(options?: {
4
- token?: string;
5
- storeId?: string;
6
- prefix?: string;
7
- }): BlobStore;
8
- //#endregion
@@ -1,81 +0,0 @@
1
- import { BlobNotFoundError, get, head, issueSignedToken, presignUrl, put } from "@vercel/blob";
2
- //#region src/blob/vercel.ts
3
- /**
4
- * Attachments in a private Vercel Blob store. Connect one to the board's
5
- * project; the SDK finds it through `BLOB_READ_WRITE_TOKEN`, or the project's
6
- * OIDC token and `BLOB_STORE_ID`. Files are private: the board serves them to
7
- * callers it verified, and the store never hands them out. Direct uploads, for
8
- * files over 4 MB, `PUT` to a URL the store presigns for one pathname, which
9
- * takes at most the file's size and never overwrites.
10
- */
11
- /** The Blob API version `@vercel/blob` speaks, which a presigned `PUT` names. */
12
- const BLOB_API_VERSION = "12";
13
- function vercelBlob(options = {}) {
14
- const auth = {
15
- ...options.token ? { token: options.token } : {},
16
- ...options.storeId ? { storeId: options.storeId } : {}
17
- };
18
- const prefix = options.prefix ? `${options.prefix.replace(/^\/+|\/+$/g, "")}/` : "";
19
- return {
20
- async put(key, data, contentType) {
21
- await put(prefix + key, Buffer.from(data.buffer, data.byteOffset, data.byteLength), {
22
- ...auth,
23
- access: "private",
24
- contentType,
25
- addRandomSuffix: false
26
- });
27
- },
28
- async get(key) {
29
- const found = await get(prefix + key, {
30
- ...auth,
31
- access: "private",
32
- ...key.endsWith(".json") ? { useCache: false } : {}
33
- });
34
- if (!found || found.statusCode !== 200) return null;
35
- return {
36
- data: found.stream,
37
- contentType: found.blob.contentType
38
- };
39
- },
40
- async uploadUrl(key, { contentType, maxBytes, expiresAt }) {
41
- const pathname = prefix + key;
42
- const validUntil = expiresAt.getTime();
43
- const signed = await issueSignedToken({
44
- ...auth,
45
- pathname,
46
- operations: ["put"],
47
- validUntil,
48
- allowedContentTypes: [contentType],
49
- maximumSizeInBytes: maxBytes
50
- });
51
- const { presignedUrl } = await presignUrl(signed, {
52
- operation: "put",
53
- access: "private",
54
- pathname,
55
- validUntil,
56
- allowedContentTypes: [contentType],
57
- maximumSizeInBytes: maxBytes,
58
- allowOverwrite: false,
59
- addRandomSuffix: false
60
- });
61
- return {
62
- url: presignedUrl,
63
- headers: {
64
- "x-api-version": BLOB_API_VERSION,
65
- "x-vercel-blob-access": "private",
66
- "x-content-type": contentType
67
- }
68
- };
69
- },
70
- async head(key) {
71
- try {
72
- return { size: (await head(prefix + key, auth)).size };
73
- } catch (error) {
74
- if (error instanceof BlobNotFoundError) return null;
75
- throw error;
76
- }
77
- }
78
- };
79
- }
80
- //#endregion
81
- export { vercelBlob };