@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,16 +1,12 @@
1
- import { i as fileSize, n as DIRECT_UPLOAD_BYTES_MAX } from "./files-SniSmeEr.mjs";
2
- import { a as AttachmentId, m as MESSAGE_TEXT_MAX } from "./schemas-DBmUO6pr.mjs";
3
- import { d as VERSION, i as withMentions } from "./watchers-hash-CurCzwhe.mjs";
1
+ import { _ as fileSize, m as DIRECT_UPLOAD_BYTES_MAX, u as BoardError } from "./errors-D8ifv16L.mjs";
2
+ import { d as MESSAGE_TEXT_MAX, r as AttachmentId } from "./schemas-BG205xds.mjs";
3
+ import { h as VERSION, s as withMentions } from "./targets-aMdbp84G.mjs";
4
4
  import { n as displayEmoji, r as normalizeEmoji } from "./emoji-CTLpvH-A.mjs";
5
- import { u as BoardError } from "./errors-CJXhhzvT.mjs";
6
- import { i as groups, n as filters$1, o as options, r as globalOptions, s as usage$1, t as commands } from "./commands-DsnQKTdB.mjs";
7
- import { i as parseScope } from "./access-CY5xVMIK.mjs";
8
- import { a as handFetch, d as vercelProjectFile, n as boardUrl, o as handLogin, r as connect } from "./node-BgeGcwX0.mjs";
9
- import { t as http } from "./backend-http-CoaCghuJ.mjs";
10
- import { t as board } from "./server-wIpAEjpX.mjs";
11
- import { t as conformance } from "./conformance-3RBKxwbp.mjs";
12
- import { n as isApiMessageId } from "./backend-vercel-CVxoTNF2.mjs";
13
- import { n as handTeam, r as vercel, t as credentialSource } from "./backend-vercel-BE65okBC.mjs";
5
+ import { u as parseScope } from "./access-CdBcYPQH.mjs";
6
+ import { i as isApiMessageId, n as isBoardName } from "./exports-Bx2dGpzr.mjs";
7
+ import { i as groups, n as filters$1, o as options, r as globalOptions, s as usage$1, t as commands } from "./commands-B8oZEByR.mjs";
8
+ import { a as http, c as handFetch, f as vercelProjectFile, i as vercel, l as handLogin, n as credentialSource, o as boardUrl, r as handTeam, s as connect, t as board } from "./server-Ov6GBJ8j.mjs";
9
+ import { t as conformance } from "./conformance-gqYBkXFS.mjs";
14
10
  import { t as displayText } from "./bots-CGkO76qH.mjs";
15
11
  import { spawn } from "node:child_process";
16
12
  import { readFile, stat, writeFile } from "node:fs/promises";
@@ -174,13 +170,46 @@ const table = (rows) => {
174
170
  const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => row[column].length)));
175
171
  return rows.map((row) => row.map((cell, column) => column === row.length - 1 ? cell : cell.padEnd(widths[column])).join(" ").trimEnd()).join("\n");
176
172
  };
177
- /** Each grant on a row: its ID, its issuer, the claims it matches, and what it lets do. */
173
+ /** A workflow as people name it: `ci.yml` for `.github/workflows/ci.yml`. */
174
+ const workflowName = (workflow) => workflow.replace(/^\.github\/workflows\/(?=[^/]+$)/, "");
175
+ /** A principal as the flags that name it: `--user ada@acme.com`, `--project web --environment production,preview`. */
176
+ function principalFlags(principal) {
177
+ switch (principal.kind) {
178
+ case "user": return `--user ${principal.email ?? principal.userId}`;
179
+ case "project": return `--project ${principal.name ?? principal.projectId} --environment ${principal.environments.join(",")}`;
180
+ case "github": return [
181
+ `--github ${principal.repository}`,
182
+ ...principal.workflow !== void 0 ? [`--workflow ${workflowName(principal.workflow)}`] : [],
183
+ ...principal.branch !== void 0 ? [`--branch ${principal.branch}`] : [],
184
+ ...principal.event !== void 0 ? [`--event ${principal.event}`] : []
185
+ ].join(" ");
186
+ case "oidc": return [`--oidc ${principal.issuer}`, ...Object.entries(principal.claims).flatMap(([name, value]) => [value].flat().map((one) => `--claim ${name}=${one}`))].join(" ");
187
+ case "all-projects": return `--all-projects --environment ${principal.environments.join(",")}`;
188
+ case "app": return `--app ${principal.name ?? principal.clientId}`;
189
+ default: return `--${principal.kind}`;
190
+ }
191
+ }
192
+ /**
193
+ * What a grant lets do, as `--can` writes it, `security/=none ci/=read,post`, or in words for
194
+ * `*` alone: `read post react label`, or `everything your role allows` for all of it where team
195
+ * roles cap it.
196
+ */
197
+ function grantCan(can, capped) {
198
+ const patterns = Object.keys(can);
199
+ const words = (grant) => grant === "all" ? "all" : grant.length === 0 ? "none" : grant.join(",");
200
+ if (patterns.length === 1 && patterns[0] === "*") {
201
+ const all = can["*"];
202
+ if (all === "all" || all.includes("manage")) return capped ? "everything your role allows" : "everything";
203
+ return all.length === 0 ? "nothing" : all.join(" ");
204
+ }
205
+ return patterns.map((pattern) => `${pattern}=${words(can[pattern])}`).join(" ");
206
+ }
207
+ /** Each grant on a row: its ID, who it names (as the flags that would), and what it lets them do. */
178
208
  function formatGrants(grants) {
179
209
  return table(grants.map((grant) => [
180
210
  grant.id,
181
- grant.issuer,
182
- Object.entries(grant.claims).map(([name, value]) => `${name}=${typeof value === "string" ? value : value.join("|")}`).join(" "),
183
- formatCan(grant.can)
211
+ grant.principals.map(principalFlags).join(" "),
212
+ grantCan(grant.can, grant.capped)
184
213
  ]));
185
214
  }
186
215
  /** Each token on a row: its ID, its name, what it may do, and when it expires. */
@@ -362,7 +391,7 @@ function writeConfig(path, config) {
362
391
  renameSync(`${path}.board-tmp`, path);
363
392
  }
364
393
  /** An event's entries without ours; a group left with no hooks goes too. */
365
- function without(entries, shape) {
394
+ function without$1(entries, shape) {
366
395
  if (shape === "flat") return entries.filter((entry) => !ours(entry));
367
396
  return entries.map((group) => ({
368
397
  ...group,
@@ -378,7 +407,7 @@ function uninstallHook(agent) {
378
407
  if (spec.shape === "extension") return unlinkSync(spec.file()), true;
379
408
  const config = readConfig(spec.file());
380
409
  const hooks = { ...config.hooks };
381
- const kept = without(hooks[spec.event] ?? [], spec.shape);
410
+ const kept = without$1(hooks[spec.event] ?? [], spec.shape);
382
411
  if (kept.length > 0) hooks[spec.event] = kept;
383
412
  else delete hooks[spec.event];
384
413
  if (Object.keys(config).filter((key) => key !== "hooks" && key !== "version").length === 0 && Object.keys(hooks).length === 0) unlinkSync(spec.file());
@@ -495,7 +524,7 @@ function rootHelp(app, version) {
495
524
  const pad = padOf(listedSections.flat());
496
525
  for (const section of listedSections) lines.push("", ...rows(section, pad));
497
526
  const everywhere = shown(globalOptions).filter((option) => option.name !== "help" && option.name !== "version");
498
- lines.push("", ...labeled("filters:", shown(filters$1).map(flag).join(" "), " "), ...labeled("", "labels match a message or its thread's root; repeated flags all must match"), ...labeled("global:", everywhere.map(flag).join(" "), " "), ...labeled("json:", "one object per line (JSONL): { message, replies, last } for read <channel>, a message for read <id>"), ...labeled("text:", "pass \"-\" to read it from stdin; it may be left out when you --attach"), ...labeled("env:", "BOARD_URL BOARD_TOKEN BOARD_AS BOARD_AVATAR BOARD_HANDLE", " "), "", `a command's own help: ${app.name} <command> --help`);
527
+ lines.push("", ...labeled("filters:", shown(filters$1).map(flag).join(" "), " "), ...labeled("", "labels match a message or its thread's root; repeated flags all must match"), ...labeled("global:", everywhere.map(flag).join(" "), " "), ...labeled("json:", "one object per line (JSONL): { message, replies, last } for read <channel>, a message for read <id>"), ...labeled("text:", "pass \"-\" to read it from stdin; it may be left out when you --attach"), ...labeled("env:", "BOARD_URL BOARD_NAME BOARD_TOKEN BOARD_AS BOARD_AVATAR BOARD_HANDLE", " "), "", `a command's own help: ${app.name} <command> --help`);
499
528
  return lines.join("\n");
500
529
  }
501
530
  /** One command's page: its usage, what it does, and its arguments, subcommands, options, and examples. */
@@ -652,6 +681,22 @@ function rerun(...extra) {
652
681
  ...typed.slice(at)
653
682
  ]];
654
683
  }
684
+ /** A command line without `options` and their values. */
685
+ const without = (argv, ...options) => argv.filter((arg, at) => !options.some((option) => arg === option || argv[at - 1] === option || arg.startsWith(`${option}=`)));
686
+ /**
687
+ * This run's command line without `options`, with `extra` in their place: both before any `--`,
688
+ * since what follows it is text, which a way out mustn't change or add options to.
689
+ */
690
+ function rerunWithout(options, ...extra) {
691
+ const at = typed.indexOf("--");
692
+ const before = at === -1 ? typed : typed.slice(0, at);
693
+ return [
694
+ ...cli(),
695
+ ...without(before, ...options),
696
+ ...extra,
697
+ ...at === -1 ? [] : typed.slice(at)
698
+ ];
699
+ }
655
700
  /** What the parser accepts: every option, by name (`commands.ts`). */
656
701
  const OPTIONS = options;
657
702
  /** Options by their short letter: `n` is `limit`. */
@@ -724,7 +769,7 @@ function removedCommand(word) {
724
769
  "<TEXT>"
725
770
  ]
726
771
  }]),
727
- stuck: () => gone([], " A board on a2() keeps its dead letters in A2, on the backend's `servers`."),
772
+ stuck: () => gone([]),
728
773
  link: () => gone(url),
729
774
  use: () => gone(url)
730
775
  };
@@ -987,16 +1032,6 @@ function canFlag(value) {
987
1032
  throw usage(`${error.message.replace(/x-board-scope/g, "--can")}.`);
988
1033
  }
989
1034
  }
990
- /** `--claim k=v`, each again: the same name twice is any of its values. */
991
- function claimPairs(values) {
992
- const claims = {};
993
- for (const value of values ?? []) {
994
- const at = value.indexOf("=");
995
- if (at <= 0 || at === value.length - 1) throw usage(`Claims look like name=value, and ${value} isn't one.`);
996
- (claims[value.slice(0, at)] ??= []).push(value.slice(at + 1));
997
- }
998
- return Object.fromEntries(Object.entries(claims).map(([name, list]) => [name, list.length === 1 ? list[0] : list]));
999
- }
1000
1035
  /** A time flag: anything `Date` reads, as ISO. */
1001
1036
  function instant(flag, value) {
1002
1037
  const time = new Date(value);
@@ -1153,7 +1188,13 @@ function failureOf(error) {
1153
1188
  case "protected": return own("permission", "deployment_protected");
1154
1189
  case "no_project": return own("platform", "no_project");
1155
1190
  case "no_token": return own("auth", "token_unavailable");
1156
- case "no_board": return own("not_found", "board_not_found");
1191
+ case "no_board": return own("not_found", "board_not_found", [{
1192
+ instruction: "Check the name, or make it",
1193
+ argv: rerun("--ensure")
1194
+ }]);
1195
+ case "board_name_taken": return own("conflict", "board_name_taken");
1196
+ case "board_not_granted": return own("permission", "board_not_granted");
1197
+ case "invalid_board_name": return own("usage", "invalid_arguments", [helpRecovery()]);
1157
1198
  case "too_many_redirects": return own("network", "network_error");
1158
1199
  case "invalid_duration": return own("usage", "invalid_arguments", [helpRecovery()]);
1159
1200
  case "wrong_audience":
@@ -1299,12 +1340,19 @@ function profileFlag() {
1299
1340
  function connection(url = flags.url, options = {}) {
1300
1341
  const profile = profileFlag();
1301
1342
  const team = flags.scope ?? flags.team;
1302
- const configured = url ?? (team === void 0 ? configuredUrl() : null);
1343
+ const name = boardNameFlag(url, team);
1344
+ const configured = url ?? (team === void 0 && name === void 0 ? configuredUrl() : null);
1303
1345
  if (configured === null) {
1304
- const board$1 = board({ backend: vercel({
1305
- ...team !== void 0 ? { team } : {},
1306
- ...sending(options.token)
1307
- }) });
1346
+ const board$1 = board({
1347
+ backend: vercel({
1348
+ ...team !== void 0 ? { team } : {},
1349
+ ...sending(options.token)
1350
+ }),
1351
+ ...name !== void 0 ? {
1352
+ name,
1353
+ ensure: flags.ensure === true
1354
+ } : {}
1355
+ });
1308
1356
  return {
1309
1357
  url: null,
1310
1358
  transport: { source: credentialSource },
@@ -1337,6 +1385,37 @@ function connection(url = flags.url, options = {}) {
1337
1385
  board: profile !== void 0 ? board$2.as(profile) : board$2
1338
1386
  };
1339
1387
  }
1388
+ /**
1389
+ * The team's board this run names: `--name`, or `BOARD_NAME`, on `--scope`'s team or the one the
1390
+ * environment finds. A URL names a board itself, its team included. `BOARD_NAME` is read only
1391
+ * where it picks the board: beside `BOARD_URL`, which names another, nothing says which one.
1392
+ */
1393
+ function boardNameFlag(url, team) {
1394
+ if (flags.name !== void 0 && flags.url !== void 0) throw usage("--name names a team's board, and --url a board by its URL: pass one of them.", { reason: "conflicting_options" });
1395
+ if (team !== void 0 && flags.url !== void 0) throw usage("--url names its board, its team included, and --scope a team's board: pass one of them.", { reason: "conflicting_options" });
1396
+ if (flags.ensure && flags.url !== void 0) throw usage("--ensure makes a team's board by its name, and --url names a board by its URL: pass one of them.", { reason: "conflicting_options" });
1397
+ if (url !== void 0) return void 0;
1398
+ const named = process.env.BOARD_NAME || void 0;
1399
+ if (flags.name === void 0 && team === void 0 && named !== void 0 && process.env.BOARD_URL?.trim()) throw usage("BOARD_NAME names a team's board, and BOARD_URL a board by its URL: unset one.", { reason: "conflicting_options" });
1400
+ const given = flags.name ?? named;
1401
+ if (given === void 0 && flags.ensure) throw usage("--ensure makes the board --name names: pass --name too.", { reason: "missing_arguments" });
1402
+ if (given === void 0) return void 0;
1403
+ const from = flags.name !== void 0 ? "--name" : "BOARD_NAME";
1404
+ if (given.includes("/")) {
1405
+ const [owner, ...rest] = given.split("/");
1406
+ const argv = rerunWithout([
1407
+ "--name",
1408
+ "--scope",
1409
+ "--team"
1410
+ ], "--scope", owner || "<TEAM>", "--name", rest.join("/") || "<NAME>");
1411
+ throw usage(`${from} takes a board's name alone, not its team's.`, { next: [flags.name !== void 0 ? {
1412
+ instruction: "Pass its team with --scope",
1413
+ argv
1414
+ } : { instruction: "Set BOARD_NAME to the name alone, and pass its team with --scope" }] });
1415
+ }
1416
+ if (!isBoardName(given)) throw usage(`${from} ${given} isn't a board's name: one is 1 to 64 characters.`);
1417
+ return given;
1418
+ }
1340
1419
  /** For Vercel's API, `token` in place of your own credentials: a board token's secret. */
1341
1420
  function sending(token) {
1342
1421
  if (token === void 0) return {};
@@ -1465,6 +1544,17 @@ async function run(command, args) {
1465
1544
  }
1466
1545
  case "conformance": {
1467
1546
  if (args.length > 0) throw usage("conformance takes no arguments: pass its channel with --channel.");
1547
+ const named = flags.name !== void 0 || flags.url !== void 0 || Boolean(process.env.BOARD_URL?.trim()) || Boolean(process.env.BOARD_NAME);
1548
+ if (!io.board && !named) throw usage("conformance posts and changes grants, so name a scratch board for it.", {
1549
+ reason: "needs_scratch_board",
1550
+ next: [{
1551
+ instruction: "Check a scratch board on this team, by its name",
1552
+ argv: rerun("--name", "<BOARD>")
1553
+ }, {
1554
+ instruction: "Or a board by its URL",
1555
+ argv: rerun("--url", "<URL>")
1556
+ }]
1557
+ });
1468
1558
  const withToken = io.board ? {} : { withToken: (secret) => connection(flags.url, { token: secret }).board };
1469
1559
  const report = await conformance(client(), {
1470
1560
  ...flags.channel ? { channel: flags.channel } : {},
@@ -1679,23 +1769,7 @@ async function run(command, args) {
1679
1769
  else out(revoked ? `revoked ${id}` : `${id} is already gone`);
1680
1770
  return 0;
1681
1771
  }
1682
- if (verb !== "create") throw usage(`Unknown command ${verb} for ${named()} grants.`, { reason: "unknown_command" });
1683
- const [issuer, extra] = rest;
1684
- if (!issuer) throw usage("Missing the issuer to grant: vercel, github, or an https URL.", { reason: "missing_arguments" });
1685
- if (extra !== void 0) throw usage(`grants create takes one issuer, and its claims as --claim name=value: ${extra} is one too many.`);
1686
- const claims = claimPairs(flags.claim);
1687
- if (Object.keys(claims).length === 0) throw usage(`Missing the claims ${issuer}'s tokens must carry: pass --claim name=value.`, { reason: "missing_arguments" });
1688
- const { grant, created } = await client().createGrant({
1689
- issuer,
1690
- claims,
1691
- ...flags.can !== void 0 ? { can: canFlag(flags.can) } : {}
1692
- });
1693
- if (flags.json) result({
1694
- grant,
1695
- outcome: created ? "granted" : "updated"
1696
- });
1697
- else out(`${created ? "granted" : "updated"} ${grant.id}`);
1698
- return 0;
1772
+ throw usage(`Unknown command ${verb} for ${named()} grants.`, { reason: "unknown_command" });
1699
1773
  }
1700
1774
  case "tokens": {
1701
1775
  const [verb, ...rest] = args;
@@ -2034,7 +2108,8 @@ async function runOnce(argv, options) {
2034
2108
  args
2035
2109
  };
2036
2110
  if (io.board) {
2037
- if (flags.url || flags.handle) throw usage(`--${flags.url ? "url" : "handle"} doesn't apply in-process: the board handle you pass says which board and who.`, { next: [] });
2111
+ const given = flags.url ? "url" : flags.name !== void 0 ? "name" : flags.ensure ? "ensure" : flags.handle ? "handle" : null;
2112
+ if (given) throw usage(`--${given} doesn't apply in-process: the board handle you pass says which board and who.`, { next: [] });
2038
2113
  if (command !== void 0 && MACHINE.has(command)) throw usage(`${command} isn't available in-process: it's about the machine ${named()} runs on.`, {
2039
2114
  reason: "not_available",
2040
2115
  next: []
@@ -1,6 +1,6 @@
1
- import { r as sqlTables } from "../sql-E1K5g_ih.mjs";
2
- import { t as sqliteDb } from "../sqlite-db-CzcD_FW8.mjs";
3
- import { t as memory$1 } from "../store-memory-B0PkVSuQ.mjs";
1
+ import { r as sqlTables } from "./sql-BQzKUqQt.mjs";
2
+ import { t as memory$1 } from "./store-memory-CKQVEzXN.mjs";
3
+ import { t as sqliteDb } from "./sqlite-db-qLTs52Ny.mjs";
4
4
  //#region src/store/memory.ts
5
5
  /**
6
6
  * A board that lives in memory, for tests: its log in A2's memory store, its
@@ -0,0 +1,103 @@
1
+ import { t as HttpError } from "./errors-D8ifv16L.mjs";
2
+ import { d as MESSAGE_TEXT_MAX, u as Labels } from "./schemas-BG205xds.mjs";
3
+ import { z } from "zod";
4
+ //#region src/client/ids.ts
5
+ const hex = (bytes) => Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
6
+ /** SHA-256 of `text`, in hex. */
7
+ async function sha256(text) {
8
+ return hex(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text))));
9
+ }
10
+ /**
11
+ * A UUIDv8 from `parts`, exactly as A2's `idempotentId` makes one: the IDs a board derives for the
12
+ * writes its own code makes, which no request may post with.
13
+ */
14
+ async function derivedId(...parts) {
15
+ const bytes = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify(parts)))).slice(0, 16);
16
+ bytes[6] = bytes[6] & 15 | 128;
17
+ bytes[8] = bytes[8] & 63 | 128;
18
+ const text = hex(bytes);
19
+ return `${text.slice(0, 8)}-${text.slice(8, 12)}-${text.slice(12, 16)}-${text.slice(16, 20)}-${text.slice(20, 32)}`;
20
+ }
21
+ /** A derived ID's shape. */
22
+ const DERIVED_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-8[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
23
+ /**
24
+ * A post's ID, from one derived for it, under `principal`: a board takes a `key:<principal>:` ID
25
+ * only from that principal, so no one else can post with it first.
26
+ */
27
+ const keyId = async (principal, derived) => `key:${principal}:${(await sha256(`board-key\u001f${derived}`)).slice(0, 32)}`;
28
+ /**
29
+ * Whether `id` is exactly the shape `keyId` makes for `principal`. A prefix check isn't enough:
30
+ * a principal's ID can be the start of another's (`oidc:gitlab.com:acme` and `oidc:gitlab.com:acme:ci`).
31
+ */
32
+ const isKeyIdOf = (id, principal) => id.startsWith(`key:${principal}:`) && /^[0-9a-f]{32}$/.test(id.slice(`key:${principal}:`.length));
33
+ //#endregion
34
+ //#region src/server/wait-until.ts
35
+ /**
36
+ * Keeps `task` running after the response, where the platform offers it: Vercel's request context, as A2
37
+ * reads it too. Elsewhere it runs on in the process.
38
+ */
39
+ function waitUntil(task) {
40
+ try {
41
+ Reflect.get(globalThis, Symbol.for("@vercel/request-context"))?.get?.()?.waitUntil?.(task);
42
+ } catch {}
43
+ }
44
+ //#endregion
45
+ //#region src/server/middleware.ts
46
+ /** A write the middleware didn't let through: the API answers 422 with what it responded. */
47
+ var DroppedError = class extends HttpError {
48
+ /** What the middleware responded, in order: none when it dropped the write without a word. */
49
+ responses;
50
+ constructor(responses) {
51
+ super(422, "dropped", responses.join("\n") || "the board dropped this message");
52
+ this.responses = responses;
53
+ }
54
+ };
55
+ const Patch = z.object({
56
+ text: z.string().max(MESSAGE_TEXT_MAX).optional(),
57
+ labels: Labels.optional()
58
+ }).strict();
59
+ const MIDDLEWARE_ACTOR = "board:middleware";
60
+ /**
61
+ * Runs `write` through `middleware` in order, then `commit`s what the last one
62
+ * passed on. Throws `DroppedError` when one doesn't call `next`.
63
+ */
64
+ async function runMiddleware(middleware, input, commit) {
65
+ const responses = [];
66
+ let committed = null;
67
+ const step = async (i, write) => {
68
+ if (i === middleware.length) {
69
+ if (write.text.trim() === "" && (write.kind === "edit" || write.attachments.length === 0)) return;
70
+ committed = { value: await commit(write) };
71
+ return;
72
+ }
73
+ let next = null;
74
+ await middleware[i]({
75
+ write: Object.freeze({ ...write }),
76
+ author: Object.freeze({ ...input.author }),
77
+ source: Object.freeze({ ...input.source }),
78
+ board: input.board(),
79
+ respond: async (text) => {
80
+ responses.push(text);
81
+ },
82
+ next: (patch = {}) => {
83
+ if (next) throw new Error("next() was already called");
84
+ const { text, labels } = Patch.parse(patch);
85
+ next = step(i + 1, {
86
+ ...write,
87
+ ...text !== void 0 ? { text } : {},
88
+ ...write.kind === "post" && labels ? { labels: {
89
+ ...write.labels,
90
+ ...labels
91
+ } } : {}
92
+ });
93
+ return next;
94
+ }
95
+ });
96
+ if (next) await next;
97
+ };
98
+ await step(0, input.write);
99
+ if (!committed) throw new DroppedError(responses);
100
+ return committed.value;
101
+ }
102
+ //#endregion
103
+ export { DERIVED_ID as a, keyId as c, waitUntil as i, sha256 as l, MIDDLEWARE_ACTOR as n, derivedId as o, runMiddleware as r, isKeyIdOf as s, DroppedError as t };