@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,4 +1,4 @@
1
- import { a as commandLine, c as failureLines, i as mainWith, l as formatFailure, n as commandWord, o as exitCode, r as main, s as failureDocument, t as Failed } from "./main-CcYDo9Hb.mjs";
1
+ import { a as commandLine, c as failureLines, i as mainWith, l as formatFailure, n as commandWord, o as exitCode, r as main, s as failureDocument, t as Failed } from "./main-DScDKwQN.mjs";
2
2
  //#region src/cli/embedded.ts
3
3
  /**
4
4
  * Board's CLI as `appName` names it in help, usage, and errors (`vercel board`). With no board
package/dist/cli.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { t as ATTACHMENT_BYTES_MAX } from "./files-SniSmeEr.mjs";
3
- import "./schemas-DBmUO6pr.mjs";
4
- import { a as option } from "./commands-DsnQKTdB.mjs";
5
- import { l as projectDir } from "./node-BgeGcwX0.mjs";
6
- import { r as main, u as who } from "./main-CcYDo9Hb.mjs";
2
+ import { p as ATTACHMENT_BYTES_MAX } from "./errors-D8ifv16L.mjs";
3
+ import "./schemas-BG205xds.mjs";
4
+ import { a as option } from "./commands-B8oZEByR.mjs";
5
+ import { d as projectDir } from "./server-Ov6GBJ8j.mjs";
6
+ import { r as main, u as who } from "./main-DScDKwQN.mjs";
7
7
  import { randomBytes, timingSafeEqual } from "node:crypto";
8
8
  import { appendFile, readFile } from "node:fs/promises";
9
9
  import { join } from "node:path";
@@ -661,7 +661,7 @@ const local = {
661
661
  if (args.length > 0) throw usage("serve takes no arguments: pass its port with --port, and its directory with --dir.");
662
662
  const port = portFlag();
663
663
  const root = projectDir();
664
- const { localHandle, serveLocal } = await import("./serve-Bplieh0C.mjs");
664
+ const { localHandle, serveLocal } = await import("./serve-B1noQRkn.mjs");
665
665
  const handle = flags.handle ?? process.env.BOARD_HANDLE;
666
666
  const local = await serveLocal({
667
667
  dir: flags.dir ?? join(root, ".board"),
@@ -48,6 +48,15 @@ const options = {
48
48
  value: "team",
49
49
  description: "a team's board in Vercel's API, by its slug or ID"
50
50
  },
51
+ name: {
52
+ type: "string",
53
+ value: "board",
54
+ description: "the team's board with this name, on --scope's team"
55
+ },
56
+ ensure: {
57
+ type: "boolean",
58
+ description: "with --name: make that board if the team has none by that name"
59
+ },
51
60
  team: {
52
61
  type: "string",
53
62
  value: "team",
@@ -201,12 +210,6 @@ const options = {
201
210
  value: "scope",
202
211
  description: "what it may do (default: *=read,post,react,label)"
203
212
  },
204
- claim: {
205
- type: "string",
206
- multiple: true,
207
- value: "k=v",
208
- description: "a claim its tokens carry; the same name again is any of them"
209
- },
210
213
  profile: {
211
214
  type: "string",
212
215
  value: "name",
@@ -264,6 +267,8 @@ const filters = [
264
267
  const globalOptions = [
265
268
  "url",
266
269
  "scope",
270
+ "name",
271
+ "ensure",
267
272
  "team",
268
273
  "as",
269
274
  "avatar",
@@ -370,7 +375,7 @@ const commands = [
370
375
  {
371
376
  group: "the board",
372
377
  name: "grants",
373
- description: "who the board lets in beside its code's rules: tokens from an OIDC issuer with these claims",
378
+ description: "who may do what where: people, projects, and workflows, and what each grant lets them do",
374
379
  arguments: [],
375
380
  options: [],
376
381
  runsWithoutSubcommand: true,
@@ -378,50 +383,30 @@ const commands = [
378
383
  name: "list the grants",
379
384
  value: "grants"
380
385
  }],
381
- subcommands: [
382
- {
383
- name: "list",
384
- default: true,
385
- description: "the board's grants",
386
- arguments: [],
387
- options: [],
388
- examples: [{
389
- name: "list the grants",
390
- value: "grants list"
391
- }]
392
- },
393
- {
394
- name: "create",
395
- description: "let them in, or change what they may do",
396
- arguments: [{
397
- name: "issuer",
398
- required: true,
399
- description: "vercel, github, or an https URL"
400
- }],
401
- options: [option("claim"), option("can")],
402
- examples: [{
403
- name: "let a workflow post in ci/",
404
- value: "grants create github --claim repository=acme/web --can ci/=read,post"
405
- }, {
406
- name: "let a project's production post feedback",
407
- value: "grants create vercel --claim project_id=prj_123 --claim environment=production --can feedback/=post"
408
- }]
409
- },
410
- {
411
- name: "revoke",
412
- description: "stop letting them in",
413
- arguments: [{
414
- name: "grant",
415
- required: true,
416
- description: "its ID, as grants shows it (g3)"
417
- }],
418
- options: [],
419
- examples: [{
420
- name: "revoke a grant",
421
- value: "grants revoke g3"
422
- }]
423
- }
424
- ]
386
+ subcommands: [{
387
+ name: "list",
388
+ default: true,
389
+ description: "the board's grants",
390
+ arguments: [],
391
+ options: [],
392
+ examples: [{
393
+ name: "list the grants",
394
+ value: "grants list"
395
+ }]
396
+ }, {
397
+ name: "revoke",
398
+ description: "stop letting them in",
399
+ arguments: [{
400
+ name: "grant",
401
+ required: true,
402
+ description: "its ID, as grants shows it (g3)"
403
+ }],
404
+ options: [],
405
+ examples: [{
406
+ name: "revoke a grant",
407
+ value: "grants revoke g3"
408
+ }]
409
+ }]
425
410
  },
426
411
  {
427
412
  group: "the board",
@@ -809,7 +794,7 @@ const commands = [
809
794
  {
810
795
  group: "messages",
811
796
  name: "conformance",
812
- description: "check that the board speaks the protocol (1 if a check fails): it posts, and deletes what it posted",
797
+ description: "check that a board you name speaks the protocol (1 if a check fails): it posts, and deletes what it posted",
813
798
  arguments: [],
814
799
  options: [option("channel", "the channel to check in (default: conformance)")],
815
800
  examples: [{
@@ -96,6 +96,15 @@ declare const options: {
96
96
  readonly value: 'team';
97
97
  readonly description: "a team's board in Vercel's API, by its slug or ID";
98
98
  };
99
+ readonly name: {
100
+ readonly type: 'string';
101
+ readonly value: 'board';
102
+ readonly description: "the team's board with this name, on --scope's team";
103
+ };
104
+ readonly ensure: {
105
+ readonly type: 'boolean';
106
+ readonly description: 'with --name: make that board if the team has none by that name';
107
+ };
99
108
  readonly team: {
100
109
  readonly type: 'string';
101
110
  readonly value: 'team';
@@ -249,12 +258,6 @@ declare const options: {
249
258
  readonly value: 'scope';
250
259
  readonly description: 'what it may do (default: *=read,post,react,label)';
251
260
  };
252
- readonly claim: {
253
- readonly type: 'string';
254
- readonly multiple: true;
255
- readonly value: 'k=v';
256
- readonly description: 'a claim its tokens carry; the same name again is any of them';
257
- };
258
261
  readonly profile: {
259
262
  readonly type: 'string';
260
263
  readonly value: 'name';
@@ -1,5 +1,5 @@
1
- import { u as BoardError } from "./errors-CJXhhzvT.mjs";
2
- import { r as compileAccess } from "./access-CY5xVMIK.mjs";
1
+ import { u as BoardError } from "./errors-D8ifv16L.mjs";
2
+ import { s as compileAccess } from "./access-CdBcYPQH.mjs";
3
3
  //#region src/conformance/index.ts
4
4
  var Mismatch = class extends Error {};
5
5
  const show = (value) => JSON.stringify(value) ?? String(value);
@@ -41,9 +41,9 @@ function isRef(value, what) {
41
41
  check(typeof value === "string" && value.length >= 1 && value.length <= 128, `${what} should be a string of 1 to 128 characters, got ${show(value)}`);
42
42
  }
43
43
  /**
44
- * The groups a board may keep none of, saying so with a 501: a board on `a2()` without a scheduler
45
- * answers `no_scheduler`, and without a blob store `no_files`; one whose `access` is one function keeps
46
- * no grants, `no_grants`. A board that's meant to keep something and doesn't yet answers otherwise,
44
+ * The groups a board may keep none of, saying so with a 501: a board without a scheduler answers
45
+ * `no_scheduler`, and without a blob store `no_files`; a backend of one's own that keeps no grants
46
+ * answers `no_grants`. A board that's meant to keep something and doesn't yet answers otherwise,
47
47
  * and fails.
48
48
  */
49
49
  const OPTIONAL = /* @__PURE__ */ new Set([
@@ -59,18 +59,21 @@ const needRoot = (ctx) => {
59
59
  reply: ctx.reply
60
60
  };
61
61
  };
62
- /** A grant for a project that doesn't exist, from an environment its deployments would have: it lets nobody in. */
62
+ /** A project that doesn't exist, by ID, which every board takes: a grant naming it lets nobody in. */
63
+ const projectFor = (ctx, environments = ["preview"]) => ({
64
+ kind: "project",
65
+ project: `prj_conformance${ctx.labels.conformance}`,
66
+ environments
67
+ });
68
+ /** The check's grant: that project may post in the check's channel. */
63
69
  const grantFor = (ctx) => ({
64
- issuer: "vercel",
65
- claims: {
66
- environment: "preview",
67
- project_id: `prj_conformance${ctx.labels.conformance}`
68
- }
70
+ principals: [projectFor(ctx)],
71
+ can: { [ctx.channel]: ["post"] }
69
72
  });
70
- /** Sets the check's grant, or says why it can't: changing who the board trusts takes `manage` in every channel. */
71
- async function firstGrant(ctx) {
73
+ /** Makes the check's grant, or says why it can't: changing grants takes `manage` where they apply. */
74
+ async function firstGrant(ctx, input = grantFor(ctx)) {
72
75
  try {
73
- return await ctx.board.createGrant(grantFor(ctx));
76
+ return await ctx.board.createGrant(input);
74
77
  } catch (error) {
75
78
  if (error instanceof BoardError && error.status === 403) return { skip: "this token can't change the board's grants" };
76
79
  throw error;
@@ -497,78 +500,70 @@ const CHECKS = [
497
500
  },
498
501
  {
499
502
  group: "grants",
500
- name: "grants a project, lists it, takes the same grant again as one, and revokes it",
501
- run: async (ctx) => {
502
- const asked = grantFor(ctx);
503
- const first = await firstGrant(ctx);
504
- if ("skip" in first) return first.skip;
505
- try {
506
- isRef(first.grant.id, "a grant's id");
507
- same(first.created, true, "a new grant: created");
508
- same(first.grant.issuer, "vercel", "the grant's issuer");
509
- same(first.grant.claims.project_id, asked.claims.project_id, "the grant's project_id");
510
- check(first.grant.can["*"]?.includes("post"), `a grant with no can should let them post everywhere, got ${show(first.grant.can)}`);
511
- same(first.grant.by, ctx.me.actor, "the grant's by");
512
- const again = await ctx.board.createGrant(asked);
513
- same(again.created, false, "the same issuer and claims again: created");
514
- same(again.grant.id, first.grant.id, "the same issuer and claims again: its id");
515
- same((await ctx.board.grants()).filter((grant) => grant.id === first.grant.id).length, 1, "grants listing it");
516
- } catch (error) {
517
- await ctx.board.revokeGrant(first.grant.id).catch(() => {});
518
- throw error;
519
- }
520
- same((await ctx.board.revokeGrant(first.grant.id)).revoked, true, "revoking it");
521
- same((await ctx.board.revokeGrant(first.grant.id)).revoked, false, "revoking it again");
522
- check(!(await ctx.board.grants()).some((grant) => grant.id === first.grant.id), "grants shouldn't list it once it's revoked");
523
- }
524
- },
525
- {
526
- group: "grants",
527
- name: "changes a grant's can when it's set again",
503
+ name: "grants a project, lists it, and revokes it",
528
504
  run: async (ctx) => {
529
505
  const first = await firstGrant(ctx);
530
506
  if ("skip" in first) return first.skip;
531
507
  const { grant } = first;
532
508
  try {
533
- const narrowed = await ctx.board.createGrant({
534
- ...grantFor(ctx),
535
- can: { [ctx.channel]: ["post"] }
536
- });
537
- same(narrowed.created, false, "setting its can: created");
538
- same(narrowed.grant.id, grant.id, "setting its can: its id");
539
- same(show(narrowed.grant.can), show({ [ctx.channel]: ["post"] }), "the grant's can");
540
- } finally {
509
+ isRef(grant.id, "a grant's id");
510
+ same(show(grant.principals.map((principal) => principal.kind === "project" ? [
511
+ principal.kind,
512
+ principal.projectId,
513
+ principal.environments
514
+ ] : principal.kind)), show([[
515
+ "project",
516
+ projectFor(ctx).project,
517
+ ["preview"]
518
+ ]]), "the grant's principals");
519
+ same(show(grant.can), show({ [ctx.channel]: ["post"] }), "the grant's can");
520
+ same(grant.by, ctx.me.actor, "the grant's by");
521
+ same((await ctx.board.grants()).filter((listed) => listed.id === grant.id).length, 1, "grants listing it");
522
+ } catch (error) {
541
523
  await ctx.board.revokeGrant(grant.id).catch(() => {});
524
+ throw error;
542
525
  }
526
+ same((await ctx.board.revokeGrant(grant.id)).revoked, true, "revoking it");
527
+ same((await ctx.board.revokeGrant(grant.id)).revoked, false, "revoking it again");
528
+ check(!(await ctx.board.grants()).some((listed) => listed.id === grant.id), "grants shouldn't list it once it's revoked");
543
529
  }
544
530
  },
545
531
  {
546
532
  group: "grants",
547
- name: "grants a GitHub repository's workflows, and another team's project",
533
+ name: "makes another grant for the same principals, and changes one by its ID",
548
534
  run: async (ctx) => {
549
535
  const first = await firstGrant(ctx);
550
536
  if ("skip" in first) return first.skip;
551
537
  const made = [first.grant.id];
552
538
  try {
553
- const github = await ctx.board.createGrant({
554
- issuer: "github",
555
- claims: { repository: `acme/conformance-${ctx.labels.conformance}` },
556
- can: { [ctx.channel]: ["post"] }
539
+ const again = await ctx.board.createGrant(grantFor(ctx));
540
+ made.push(again.grant.id);
541
+ check(again.grant.id !== first.grant.id, `the same principals again should be another grant, got ${again.grant.id} twice`);
542
+ const repository = `acme/conformance-${ctx.labels.conformance}`;
543
+ const added = await ctx.board.updateGrant(first.grant.id, {
544
+ add: [{
545
+ kind: "github",
546
+ repository
547
+ }],
548
+ can: { [ctx.channel]: ["read", "post"] }
557
549
  });
558
- made.push(github.grant.id);
559
- same(github.grant.issuer, "github", "the GitHub grant's issuer");
560
- const theirs = await ctx.board.createGrant({
561
- issuer: "vercel",
562
- claims: {
563
- environment: "production",
564
- owner_id: `team_conformance${ctx.labels.conformance}`,
565
- project_id: `prj_conformance${ctx.labels.conformance}x`
566
- }
567
- });
568
- made.push(theirs.grant.id);
569
- same(theirs.grant.claims.owner_id, `team_conformance${ctx.labels.conformance}`, "another team's grant's owner_id");
570
- const listed = new Set((await ctx.board.grants()).map((grant) => grant.id));
571
- check(made.every((id) => listed.has(id)), `grants should list ${made.join(", ")}`);
550
+ same(added.grant.id, first.grant.id, "the updated grant's id");
551
+ same(show(added.grant.principals.map((principal) => principal.kind)), show(["project", "github"]), "principals after adding a repository");
552
+ same(show(added.grant.can), show({ [ctx.channel]: ["read", "post"] }), "the updated grant's can");
553
+ const removed = await ctx.board.updateGrant(first.grant.id, { remove: [{
554
+ kind: "project",
555
+ project: projectFor(ctx).project
556
+ }] });
557
+ same(show(removed.grant.principals.map((principal) => principal.kind)), show(["github"]), "principals after removing the project");
558
+ await rejects(ctx.board.updateGrant(first.grant.id, { remove: [{
559
+ kind: "project",
560
+ project: projectFor(ctx).project
561
+ }] }), 400, "not_in_grant", "removing a principal the grant no longer names");
562
+ await rejects(ctx.board.updateGrant(first.grant.id, { remove: [{
563
+ kind: "github",
564
+ repository
565
+ }] }), 400, "grant_empty", "removing the last principal");
566
+ await rejects(ctx.board.updateGrant(`${first.grant.id}0`, { can: { [ctx.channel]: ["read"] } }), 404, "grant_not_found", "updating a grant that was never made");
572
567
  } finally {
573
568
  for (const id of made) await ctx.board.revokeGrant(id).catch(() => {});
574
569
  }
@@ -576,27 +571,25 @@ const CHECKS = [
576
571
  },
577
572
  {
578
573
  group: "grants",
579
- name: "keeps two environments of one project as two grants, and revokes one without the other",
574
+ name: "keeps a grant's can as written, a pattern with no permissions included",
580
575
  run: async (ctx) => {
581
- const first = await firstGrant(ctx);
576
+ const can = {
577
+ "*": ["read"],
578
+ [`${ctx.channel}/`]: []
579
+ };
580
+ const first = await firstGrant(ctx, {
581
+ principals: [projectFor(ctx, ["production", "preview"])],
582
+ can
583
+ });
582
584
  if ("skip" in first) return first.skip;
583
- const made = [first.grant.id];
584
585
  try {
585
- const production = await ctx.board.createGrant({
586
- ...grantFor(ctx),
587
- claims: {
588
- ...grantFor(ctx).claims,
589
- environment: "production"
590
- }
591
- });
592
- made.push(production.grant.id);
593
- same(production.created, true, "another environment: created");
594
- check(production.grant.id !== first.grant.id, "another environment should be another grant");
595
- same((await ctx.board.revokeGrant(first.grant.id)).revoked, true, "revoking the preview grant");
596
- const listed = (await ctx.board.grants()).map((grant) => grant.id);
597
- check(listed.includes(production.grant.id) && !listed.includes(first.grant.id), `grants should list ${production.grant.id} and not ${first.grant.id}, got ${show(listed)}`);
586
+ same(show(first.grant.can), show(can), "the grant's can");
587
+ const listed = (await ctx.board.grants()).find((grant) => grant.id === first.grant.id);
588
+ same(show(listed?.can), show(can), "the listed grant's can");
589
+ const project = listed?.principals[0];
590
+ same(show(project?.kind === "project" ? [...project.environments].sort() : null), show(["preview", "production"]), "the project's environments");
598
591
  } finally {
599
- for (const id of made) await ctx.board.revokeGrant(id).catch(() => {});
592
+ await ctx.board.revokeGrant(first.grant.id).catch(() => {});
600
593
  }
601
594
  }
602
595
  },
@@ -1,4 +1,4 @@
1
- import { f as Board } from "./backend-DxE9wGKm.mjs";
1
+ import { d as Board } from "./backend-u1sVvybh.mjs";
2
2
  //#region src/conformance/index.d.ts
3
3
  /**
4
4
  * Checks that a board speaks the protocol, through a handle on it (`conformance(board())`), as
@@ -1,2 +1,2 @@
1
- import { t as conformance } from "./conformance-3RBKxwbp.mjs";
1
+ import { t as conformance } from "./conformance-gqYBkXFS.mjs";
2
2
  export { conformance };
@@ -1,13 +1,11 @@
1
- import { a as typeOf, i as fileSize, r as IMPORT_BYTES_MAX, t as ATTACHMENT_BYTES_MAX } from "./files-SniSmeEr.mjs";
2
- import { C as toStorable, c as ChannelPath, m as MESSAGE_TEXT_MAX } from "./schemas-DBmUO6pr.mjs";
3
- import { l as isThreadTarget, s as channelOf } from "./external-D3p5T57R.mjs";
1
+ import { _ as fileSize, h as IMPORT_BYTES_MAX, p as ATTACHMENT_BYTES_MAX, r as badRequest, s as notFound, t as HttpError, y as typeOf } from "./errors-D8ifv16L.mjs";
2
+ import { a as ChannelPath, b as toStorable, d as MESSAGE_TEXT_MAX } from "./schemas-BG205xds.mjs";
3
+ import { l as isThreadTarget, s as channelOf } from "./external-CYe424fO.mjs";
4
4
  import { t as canonicalEmoji } from "./emoji-CTLpvH-A.mjs";
5
- import { r as badRequest, s as notFound, t as HttpError } from "./errors-CJXhhzvT.mjs";
6
- import { r as derivedId, t as waitUntil } from "./wait-until-Dw4XrIDQ.mjs";
5
+ import { i as waitUntil, o as derivedId, t as DroppedError } from "./middleware-BjYpk4yq.mjs";
7
6
  import { n as replaceMentions } from "./mentions-CB6ShY4R.mjs";
8
- import { t as DroppedError } from "./middleware-BavYSDUa.mjs";
9
7
  import { t as afterRetry } from "./attempts-HXcskN1w.mjs";
10
- import { a as immutable, d as routesFor, l as UnreadableError, n as SyncOverrides, o as ReceivedEvent, s as ResolvedTarget, u as channelMissing } from "./events-lujPA3gQ.mjs";
8
+ import { a as immutable, d as routesFor, l as UnreadableError, n as SyncOverrides, o as ReceivedEvent, s as ResolvedTarget, u as channelMissing } from "./events-IQg0k281.mjs";
11
9
  import { t as displayText } from "./bots-CGkO76qH.mjs";
12
10
  //#region src/sync/engine.ts
13
11
  /** `files`: a message with files may have no text. */
@@ -90,7 +88,7 @@ function createSyncEngine(entries) {
90
88
  if (!bound) throw new Error("sync used before board() bound it");
91
89
  return bound;
92
90
  };
93
- /** Sync's own caller: on a2(), `board:sync`; on http(), this deployment itself. */
91
+ /** Sync's own caller: on a local board, `board:sync`; on http(), this deployment itself. */
94
92
  const me = {
95
93
  self: "sync",
96
94
  origin: { via: { kind: "engine" } }
@@ -1,6 +1,60 @@
1
- import { a as typeOf, n as DIRECT_UPLOAD_BYTES_MAX, t as ATTACHMENT_BYTES_MAX } from "./files-SniSmeEr.mjs";
2
1
  import { r as normalizeEmoji } from "./emoji-CTLpvH-A.mjs";
3
2
  import { ZodError } from "zod";
3
+ //#region src/contract/files.ts
4
+ /** Under Vercel Functions' 4.5 MB request body limit, so an upload fits in one request. */
5
+ const ATTACHMENT_BYTES_MAX = 4194304;
6
+ /**
7
+ * The most a file sync brings over from a platform can be. Sync fetches it on the server and
8
+ * stores it in-process, so no request carries it and the request limit doesn't apply: this bounds
9
+ * what one import holds in memory.
10
+ */
11
+ const IMPORT_BYTES_MAX = 26214400;
12
+ /**
13
+ * The most a direct upload can be: the client sends the bytes straight to the blob store, on a URL
14
+ * the board signs, so no request to the board carries them. Needs a store with `uploadUrl`.
15
+ */
16
+ const DIRECT_UPLOAD_BYTES_MAX = 104857600;
17
+ /** `120 KB`, `3.4 MB`: a file's size the way people read it. */
18
+ function fileSize(bytes) {
19
+ if (bytes < 1024) return `${bytes} B`;
20
+ if (bytes < 1048576) return `${Math.round(bytes / 1024)} KB`;
21
+ return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
22
+ }
23
+ const TYPES = {
24
+ ".png": "image/png",
25
+ ".jpg": "image/jpeg",
26
+ ".jpeg": "image/jpeg",
27
+ ".gif": "image/gif",
28
+ ".webp": "image/webp",
29
+ ".avif": "image/avif",
30
+ ".svg": "image/svg+xml",
31
+ ".mp4": "video/mp4",
32
+ ".webm": "video/webm",
33
+ ".mov": "video/quicktime",
34
+ ".pdf": "application/pdf",
35
+ ".txt": "text/plain",
36
+ ".log": "text/plain",
37
+ ".md": "text/markdown",
38
+ ".json": "application/json",
39
+ ".csv": "text/csv",
40
+ ".html": "text/html",
41
+ ".zip": "application/zip"
42
+ };
43
+ /** A file's type from its name, for when nothing better says: browsers leave `.log` untyped. */
44
+ function typeOf(name) {
45
+ const dot = name.lastIndexOf(".");
46
+ return dot > 0 && TYPES[name.slice(dot).toLowerCase()] || "application/octet-stream";
47
+ }
48
+ /** `shot.png`, as the board stores a name: no paths, no control characters. */
49
+ function fileName(name) {
50
+ return (name ?? "").split(/[\\/]/).pop().replace(/[\u0000-\u001f\u007f]/g, "").trim().slice(0, 255) || "file";
51
+ }
52
+ /** `image/png`, or `application/octet-stream` when the type isn't one. */
53
+ function mediaType(type) {
54
+ const value = (type ?? "").split(";")[0].trim().toLowerCase();
55
+ return /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/.test(value) && value.length <= 255 ? value : "application/octet-stream";
56
+ }
57
+ //#endregion
4
58
  //#region src/client/sse.ts
5
59
  /** Parses a text/event-stream body into messages. */
6
60
  async function* parseSse(body, signal) {
@@ -223,12 +277,27 @@ function createBoardClient(options) {
223
277
  /** Stops a schedule: yours, or any with manage in its channel. `canceled` is false when it was already done or canceled. */
224
278
  cancelSchedule: (id) => call("POST", `/schedules/${path(id)}/cancel`, { body: {} }),
225
279
  /**
226
- * Lets in callers with an OIDC token from `issuer` that carries every one of `claims`, to do
227
- * what `can` says (read, post, react, and label everywhere when left out). Setting the same
228
- * issuer and claims again changes its `can`: `created` says which. Needs manage in every channel.
280
+ * A new grant: `principals` may do what `can` says, a map from channel pattern to permissions
281
+ * (`[]` for none). The same principals again are another grant. At each channel, the most
282
+ * specific pattern among the grants that name a caller decides, then the closest principal,
283
+ * and grants tied there add up. Needs manage at each pattern `can` names.
229
284
  */
230
285
  createGrant: (input) => call("POST", "/grants", { body: input }),
231
- /** The board's grants. Needs manage in every channel. */
286
+ /** Adds and removes principals (by who they are, environments aside), or replaces its `can`. Needs what `checkGrantChange` says, for the grant as it was and as it'd be. */
287
+ updateGrant: (id, input) => call("PATCH", `/grants/${path(id)}`, { body: input }),
288
+ /**
289
+ * Which grants decide `channel`, and what they give: for you, or with manage at `*`, for the
290
+ * principal `principal` names (`{ user }`, `{ project, environment }`, `{ github, workflow,
291
+ * branch, event }`, or `{ oidc, claims }`).
292
+ */
293
+ explain: (channel, principal = {}) => {
294
+ const { claims, ...rest } = principal;
295
+ const params = new URLSearchParams({ channel });
296
+ for (const [name, value] of Object.entries(rest)) if (value !== void 0) params.set(name, value);
297
+ for (const [name, value] of Object.entries(claims ?? {})) params.append("claim", `${name}=${value}`);
298
+ return call("GET", `/grants/explain?${params}`);
299
+ },
300
+ /** The board's grants. Needs manage at `*`, or a team owner. */
232
301
  grants: async () => (await call("GET", "/grants")).grants,
233
302
  /** `revoked` is false when it was already gone. Its principals' next requests are refused. */
234
303
  revokeGrant: (id) => call("POST", `/grants/${path(id)}/revoke`, { body: {} }),
@@ -510,4 +579,4 @@ function toErrorResponse(error) {
510
579
  } }, 500);
511
580
  }
512
581
  //#endregion
513
- export { forbidden as a, toErrorResponse as c, createBoardClient as d, duration as f, duplicateId as i, unauthorized as l, RejectedError as n, json as o, badRequest as r, notFound as s, HttpError as t, BoardError as u };
582
+ export { fileSize as _, forbidden as a, toErrorResponse as c, createBoardClient as d, duration as f, fileName as g, IMPORT_BYTES_MAX as h, duplicateId as i, unauthorized as l, DIRECT_UPLOAD_BYTES_MAX as m, RejectedError as n, json as o, ATTACHMENT_BYTES_MAX as p, badRequest as r, notFound as s, HttpError as t, BoardError as u, mediaType as v, typeOf as y };
@@ -1,5 +1,5 @@
1
- import { d as LabelKey, p as Labels } from "./schemas-DBmUO6pr.mjs";
2
- import { n as ExternalEvent, r as ExternalLocation } from "./external-D3p5T57R.mjs";
1
+ import { c as LabelKey, u as Labels } from "./schemas-BG205xds.mjs";
2
+ import { n as ExternalEvent, r as ExternalLocation } from "./external-CYe424fO.mjs";
3
3
  import { z } from "zod";
4
4
  //#region src/sync/fn.ts
5
5
  const ROUTES = Symbol.for("board.syncRoutes");