@vercel/board 0.31.0 → 0.33.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 (166) hide show
  1. package/README.md +25 -20
  2. package/dist/{access-CY5xVMIK.mjs → access-N3XmkKXg.mjs} +3 -3
  3. package/dist/access.d.mts +4 -5
  4. package/dist/access.mjs +5 -5
  5. package/dist/{actors-Bm-ojWWT.mjs → actors-ihyN47OV.mjs} +3 -3
  6. package/dist/{auth-DLYSt_-A.d.mts → auth-D6z3rMNj.d.mts} +11 -93
  7. package/dist/{auth-CyO2aw5n.mjs → auth-r-_PeZyw.mjs} +39 -151
  8. package/dist/{backend-Bob-5CM7.d.mts → backend-CWpyR1A7.d.mts} +81 -51
  9. package/dist/backend-local.d.mts +28 -0
  10. package/dist/backend-local.mjs +2 -0
  11. package/dist/{chat-provider-DkFp2hrh.mjs → chat-provider-9hCT654s.mjs} +2 -2
  12. package/dist/{chat-provider-BChYrrA7.d.mts → chat-provider-DJpFUaFv.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 +2 -2
  17. package/dist/cli.mjs +6 -6
  18. package/dist/{commands-DK4W3HCJ.d.mts → commands-BOBQHVqM.d.mts} +14 -0
  19. package/dist/{commands-L1JSGz2Z.mjs → commands-CHoMl06v.mjs} +39 -12
  20. package/dist/{conformance-DK43HiHf.mjs → conformance-qKmGLTAT.mjs} +40 -5
  21. package/dist/conformance.d.mts +1 -1
  22. package/dist/conformance.mjs +1 -1
  23. package/dist/{engine-DurYIRt8.mjs → engine-JxgZiikU.mjs} +6 -8
  24. package/dist/{errors-CJXhhzvT.mjs → errors-Pk0XV1hK.mjs} +56 -2
  25. package/dist/{events-lujPA3gQ.mjs → events-IQg0k281.mjs} +2 -2
  26. package/dist/exports-BuKjVq2t.d.mts +4 -0
  27. package/dist/exports-gHDHlg0i.mjs +3207 -0
  28. package/dist/{external-D3p5T57R.mjs → external-CYe424fO.mjs} +1 -1
  29. package/dist/{folds-DLUzfibJ.d.mts → folds-DjFTiqIM.d.mts} +38 -44
  30. package/dist/index-CXvvYNYj.d.mts +11 -0
  31. package/dist/index.d.mts +9 -8
  32. package/dist/index.mjs +21 -8
  33. package/dist/index.node.d.mts +5 -6
  34. package/dist/index.node.mjs +3 -3
  35. package/dist/inspect/app.js +95 -95
  36. package/dist/{internal-CvsrprnU-zZMpDiRY.mjs → internal-CvsrprnU-CEPOUpAv.mjs} +63 -43
  37. package/dist/local-BbLjA5vI.mjs +8818 -0
  38. package/dist/{main-Dz-8komG.mjs → main-CQpCZJFw.mjs} +140 -36
  39. package/dist/{backend-a2/store-memory.mjs → memory-7RRnLa4X.mjs} +3 -3
  40. package/dist/middleware-BU7rVi9F.mjs +103 -0
  41. package/dist/{client-COfYrgfV.d.mts → provider-BlzUvcM9.d.mts} +665 -5
  42. package/dist/{schemas-DBmUO6pr.mjs → schemas-BG205xds.mjs} +2 -5
  43. package/dist/{serve-CTmow-YH.mjs → serve-D8_W4UN6.mjs} +33 -24
  44. package/dist/{node-BgeGcwX0.mjs → server-BiIUXWbU.mjs} +419 -6
  45. package/dist/{serving-DBFRo6U_.mjs → serving-D7rcUtSC.mjs} +1 -1
  46. package/dist/{sql-CT5xVuGr.mjs → sql-BQzKUqQt.mjs} +349 -114
  47. package/dist/sqlite-DCtZFEVm.mjs +30 -0
  48. package/dist/{sqlite-db-0WeSOEZN.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 +2 -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-BjwlnGD9.mjs → targets-CknPGGVi.mjs} +40 -10
  66. package/dist/{tokens-Dnyd_y1n.mjs → tokens-DPKjl3jf.mjs} +15 -43
  67. package/docs/01-board/01-mounting.md +243 -288
  68. package/docs/01-board/03-identity.md +41 -50
  69. package/docs/01-board/04-messages.md +19 -16
  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 +76 -313
  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 +30 -36
  86. package/docs/04-reference/01-cli.md +118 -32
  87. package/docs/04-reference/02-board.md +60 -74
  88. package/docs/04-reference/03-http.md +119 -57
  89. package/docs/04-reference/05-conformance.md +31 -45
  90. package/docs/index.md +41 -65
  91. package/package.json +12 -83
  92. package/dist/a2-DngWY2Eb.mjs +0 -4238
  93. package/dist/access-DPcrKIH_.d.mts +0 -37
  94. package/dist/backend-a2/blob-vercel.d.mts +0 -8
  95. package/dist/backend-a2/blob-vercel.mjs +0 -81
  96. package/dist/backend-a2/contract.d.mts +0 -828
  97. package/dist/backend-a2/contract.mjs +0 -5
  98. package/dist/backend-a2/scheduler-local.d.mts +0 -11
  99. package/dist/backend-a2/scheduler-local.mjs +0 -2
  100. package/dist/backend-a2/scheduler-qstash.d.mts +0 -79
  101. package/dist/backend-a2/scheduler-qstash.mjs +0 -522
  102. package/dist/backend-a2/scheduler-vercel.d.mts +0 -38
  103. package/dist/backend-a2/scheduler-vercel.mjs +0 -204
  104. package/dist/backend-a2/store-memory.d.mts +0 -11
  105. package/dist/backend-a2/store-postgres.d.mts +0 -38
  106. package/dist/backend-a2/store-postgres.mjs +0 -2977
  107. package/dist/backend-a2/store-redis-http.d.mts +0 -17
  108. package/dist/backend-a2/store-redis-http.mjs +0 -520
  109. package/dist/backend-a2/store-redis.d.mts +0 -31
  110. package/dist/backend-a2/store-redis.mjs +0 -88
  111. package/dist/backend-a2/store-sqlite.d.mts +0 -12
  112. package/dist/backend-a2/store-sqlite.mjs +0 -31
  113. package/dist/backend-a2.d.mts +0 -2633
  114. package/dist/backend-a2.mjs +0 -3
  115. package/dist/backend-http-BRrRbjRx.d.mts +0 -672
  116. package/dist/backend-http-CvUKOn-m.mjs +0 -585
  117. package/dist/backend-http-D8mUzuKQ.mjs +0 -18
  118. package/dist/backend-http.d.mts +0 -10
  119. package/dist/backend-http.mjs +0 -2
  120. package/dist/backend-http.node.d.mts +0 -10
  121. package/dist/backend-http.node.mjs +0 -2
  122. package/dist/backend-vercel-Ba8JDtqW.mjs +0 -86
  123. package/dist/backend-vercel-BaSEUdwg.d.mts +0 -674
  124. package/dist/backend-vercel-CmY9yZ9m.mjs +0 -1656
  125. package/dist/backend-vercel.d.mts +0 -9
  126. package/dist/backend-vercel.mjs +0 -11
  127. package/dist/backend-vercel.node.d.mts +0 -17
  128. package/dist/backend-vercel.node.mjs +0 -2
  129. package/dist/blob-Bx8QPWEd.d.mts +0 -40
  130. package/dist/blob-WbB2DJKn.mjs +0 -201
  131. package/dist/errors-2vGs49Db.d.mts +0 -16
  132. package/dist/exports-CWIdN0Ub.mjs +0 -1389
  133. package/dist/exports-FBOQWT7O.d.mts +0 -5
  134. package/dist/files-SniSmeEr.mjs +0 -47
  135. package/dist/folds-Cu9Q9zyQ.mjs +0 -207
  136. package/dist/index-Ho-ayyQL.d.mts +0 -11
  137. package/dist/index.default-BUcwDaAe.mjs +0 -12
  138. package/dist/local-C76Fy5ad.mjs +0 -44
  139. package/dist/middleware-BavYSDUa.mjs +0 -62
  140. package/dist/platform-B4TnJtWu-Do3agKr5.mjs +0 -32
  141. package/dist/project-CQ4VUibA.mjs +0 -124
  142. package/dist/provider-gynDUoyW.d.mts +0 -665
  143. package/dist/redis-tables-DHf85ixI.mjs +0 -3895
  144. package/dist/reducer-Bswr11ar-P324o9vn.mjs +0 -74
  145. package/dist/reducer-CYPHsSmd-BXjGiptm.d.mts +0 -170
  146. package/dist/reducers-DcENwtwZ.mjs +0 -538
  147. package/dist/retryable-lazy-DZWmHpii-DpTc5PIP.mjs +0 -19
  148. package/dist/scheduler-task-X1SToDjP-D2Il2rln.mjs +0 -69
  149. package/dist/server-B9gu0qi1-DI1WvcVK.d.mts +0 -391
  150. package/dist/server-DG8D6VV0.mjs +0 -17
  151. package/dist/server-DX7mM6nm-D7N_7bug.mjs +0 -3611
  152. package/dist/session-clear-XJYpmUpg-2q8l_FJR.mjs +0 -63
  153. package/dist/store-DEzcHZOA-B-5vhxef.d.mts +0 -540
  154. package/dist/store-N8PXxDAS-DWWgv-Vz.mjs +0 -5
  155. package/dist/store-memory-4IBl0Ztu.mjs +0 -2
  156. package/dist/store-presence-polling-JuAy2Ck2-Dh-g_KYM.mjs +0 -109
  157. package/dist/store-sqlite-iBTYYKBj.mjs +0 -2
  158. package/dist/stream-buffer-DrTyiIuo-Be10yOBR.mjs +0 -53
  159. package/dist/targets-Cgjs29T0.mjs +0 -33
  160. package/dist/types-CmrFjpml.d.mts +0 -102
  161. package/dist/wait-until-Dw4XrIDQ.mjs +0 -42
  162. package/docs/01-board/02-database.md +0 -258
  163. package/docs/04-reference/04-log.md +0 -247
  164. package/sql/postgres/board.sql +0 -145
  165. package/sql/postgres/notifications.sql +0 -24
  166. package/sql/postgres/schema.sql +0 -451
@@ -1,15 +1,12 @@
1
- import { i as fileSize, n as DIRECT_UPLOAD_BYTES_MAX } from "./files-SniSmeEr.mjs";
2
- import { a as AttachmentId } from "./schemas-DBmUO6pr.mjs";
3
- import { d as VERSION, i as withMentions } from "./watchers-hash-BjwlnGD9.mjs";
1
+ import { _ as fileSize, m as DIRECT_UPLOAD_BYTES_MAX, u as BoardError } from "./errors-Pk0XV1hK.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-CknPGGVi.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-L1JSGz2Z.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-D8mUzuKQ.mjs";
10
- import { t as board } from "./server-DG8D6VV0.mjs";
11
- import { t as conformance } from "./conformance-DK43HiHf.mjs";
12
- import { n as handTeam, r as vercel, t as credentialSource } from "./backend-vercel-Ba8JDtqW.mjs";
5
+ import { o as parseScope } from "./access-N3XmkKXg.mjs";
6
+ import { i as isApiMessageId, n as isBoardName } from "./exports-gHDHlg0i.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-CHoMl06v.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-BiIUXWbU.mjs";
9
+ import { t as conformance } from "./conformance-qKmGLTAT.mjs";
13
10
  import { t as displayText } from "./bots-CGkO76qH.mjs";
14
11
  import { spawn } from "node:child_process";
15
12
  import { readFile, stat, writeFile } from "node:fs/promises";
@@ -361,7 +358,7 @@ function writeConfig(path, config) {
361
358
  renameSync(`${path}.board-tmp`, path);
362
359
  }
363
360
  /** An event's entries without ours; a group left with no hooks goes too. */
364
- function without(entries, shape) {
361
+ function without$1(entries, shape) {
365
362
  if (shape === "flat") return entries.filter((entry) => !ours(entry));
366
363
  return entries.map((group) => ({
367
364
  ...group,
@@ -377,7 +374,7 @@ function uninstallHook(agent) {
377
374
  if (spec.shape === "extension") return unlinkSync(spec.file()), true;
378
375
  const config = readConfig(spec.file());
379
376
  const hooks = { ...config.hooks };
380
- const kept = without(hooks[spec.event] ?? [], spec.shape);
377
+ const kept = without$1(hooks[spec.event] ?? [], spec.shape);
381
378
  if (kept.length > 0) hooks[spec.event] = kept;
382
379
  else delete hooks[spec.event];
383
380
  if (Object.keys(config).filter((key) => key !== "hooks" && key !== "version").length === 0 && Object.keys(hooks).length === 0) unlinkSync(spec.file());
@@ -494,7 +491,7 @@ function rootHelp(app, version) {
494
491
  const pad = padOf(listedSections.flat());
495
492
  for (const section of listedSections) lines.push("", ...rows(section, pad));
496
493
  const everywhere = shown(globalOptions).filter((option) => option.name !== "help" && option.name !== "version");
497
- 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`);
494
+ 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`);
498
495
  return lines.join("\n");
499
496
  }
500
497
  /** One command's page: its usage, what it does, and its arguments, subcommands, options, and examples. */
@@ -651,6 +648,22 @@ function rerun(...extra) {
651
648
  ...typed.slice(at)
652
649
  ]];
653
650
  }
651
+ /** A command line without `options` and their values. */
652
+ const without = (argv, ...options) => argv.filter((arg, at) => !options.some((option) => arg === option || argv[at - 1] === option || arg.startsWith(`${option}=`)));
653
+ /**
654
+ * This run's command line without `options`, with `extra` in their place: both before any `--`,
655
+ * since what follows it is text, which a way out mustn't change or add options to.
656
+ */
657
+ function rerunWithout(options, ...extra) {
658
+ const at = typed.indexOf("--");
659
+ const before = at === -1 ? typed : typed.slice(0, at);
660
+ return [
661
+ ...cli(),
662
+ ...without(before, ...options),
663
+ ...extra,
664
+ ...at === -1 ? [] : typed.slice(at)
665
+ ];
666
+ }
654
667
  /** What the parser accepts: every option, by name (`commands.ts`). */
655
668
  const OPTIONS = options;
656
669
  /** Options by their short letter: `n` is `limit`. */
@@ -723,7 +736,7 @@ function removedCommand(word) {
723
736
  "<TEXT>"
724
737
  ]
725
738
  }]),
726
- stuck: () => gone([], " A board on a2() keeps its dead letters in A2, on the backend's `servers`."),
739
+ stuck: () => gone([]),
727
740
  link: () => gone(url),
728
741
  use: () => gone(url)
729
742
  };
@@ -805,7 +818,11 @@ function parse(argv) {
805
818
  function parseFailure(error, argv, word) {
806
819
  const option = error.message.match(/--[a-z][\w-]*/)?.[0] ?? /'(-[^' ,]+)/.exec(error.message)?.[1];
807
820
  if (error.code === "ERR_PARSE_ARGS_UNKNOWN_OPTION" && option) {
808
- const guess = option.startsWith("--") ? closest(option.slice(2), optionsOf(word)) : void 0;
821
+ const token = /^Unknown option '(.*?)'\. /.exec(error.message)?.[1];
822
+ const dash = argv.indexOf("--");
823
+ const options = dash === -1 ? argv : argv.slice(0, dash);
824
+ const spaced = token === void 0 ? void 0 : options.find((arg) => /\s/.test(arg) && (token.startsWith("--") ? arg === token : arg.startsWith(token)));
825
+ const guess = !spaced && option.startsWith("--") ? closest(option.slice(2), optionsOf(word)) : void 0;
809
826
  const next = [{
810
827
  instruction: "See all options",
811
828
  argv: [
@@ -814,17 +831,18 @@ function parseFailure(error, argv, word) {
814
831
  "--help"
815
832
  ]
816
833
  }];
817
- const at = argv.indexOf(option);
834
+ const unknown = spaced ?? option;
835
+ const at = argv.indexOf(unknown);
818
836
  if (word && TEXT.has(word) && at !== -1) {
819
837
  const rest = [...argv.slice(0, at), ...argv.slice(at + 1)];
820
838
  const dash = rest.indexOf("--");
821
839
  const text = dash === -1 ? [
822
840
  ...rest,
823
841
  "--",
824
- option
842
+ unknown
825
843
  ] : [
826
844
  ...rest.slice(0, dash + 1),
827
- option,
845
+ unknown,
828
846
  ...rest.slice(dash + 1)
829
847
  ];
830
848
  next.push({
@@ -832,7 +850,8 @@ function parseFailure(error, argv, word) {
832
850
  argv: [...cli(), ...text]
833
851
  });
834
852
  }
835
- return usage(`Unknown option ${option} for ${`${named()}${word ? ` ${word}` : ""}`}.${guess ? ` Did you mean --${guess}?` : ""}`, {
853
+ const where = `${named()}${word ? ` ${word}` : ""}`;
854
+ return usage(`Unknown option ${spaced ? JSON.stringify(spaced) : option} for ${where}.${guess ? ` Did you mean --${guess}?` : ""}`, {
836
855
  reason: "unknown_option",
837
856
  next
838
857
  });
@@ -885,10 +904,12 @@ const tooLarge = (path) => new Failed({
885
904
  reason: "payload_too_large",
886
905
  message: `Can't attach ${path}. It's over ${DIRECT_UPLOAD_BYTES_MAX / 1024 / 1024} MB, the most an attachment can be.`
887
906
  });
888
- /** Whether an argument names a message rather than a channel: `#<id>`, or a bare number. */
889
- const isMessageRef = (value) => /^#[^\s/]+$/.test(value) || /^\d+$/.test(value);
890
- /** A message's ID as it's passed back: bare when it's a number, `#<id>` when it could be a channel's name. */
891
- const messageRef = (id) => /^\d+$/.test(id) ? id : `#${id}`;
907
+ /** Whether an ID goes in and out bare: a number, or one Vercel's API hands out (`msg_…`), a message even where a channel has its name. */
908
+ const bareId = (value) => /^\d+$/.test(value) || isApiMessageId(value);
909
+ /** Whether an argument names a message rather than a channel: `#<id>`, or an ID that goes bare. */
910
+ const isMessageRef = (value) => /^#[^\s/]+$/.test(value) || bareId(value);
911
+ /** A message's ID as it's passed back: bare when it goes bare, `#<id>` when it could be a channel's name. */
912
+ const messageRef = (id) => bareId(id) ? id : `#${id}`;
892
913
  /** `--if-revision N`, as an edit or a delete takes it. */
893
914
  function ifRevision() {
894
915
  const given = flags["if-revision"];
@@ -905,8 +926,33 @@ function labelPairs(values, wrong = "Labels look like key=value, and {value} isn
905
926
  }
906
927
  return pairs;
907
928
  }
908
- async function text(value) {
909
- if (value === void 0) throw usage("Missing the message's text: pass it, or - to read it from stdin.", { reason: "missing_arguments" });
929
+ /**
930
+ * A message's text: the argument, stdin for `-`, or the file `--text-file` names (`-` for stdin).
931
+ * `optional` when the message can go without, as one with `--attach` files can.
932
+ */
933
+ async function text(value, { optional = false } = {}) {
934
+ const file = flags["text-file"];
935
+ if (file !== void 0) {
936
+ if (value !== void 0) throw usage("Can't use --text-file with text: pass one or the other.");
937
+ if (file === "-") return (await io.stdin()).replace(/\n$/, "");
938
+ const data = await io.readFile(file).catch((error) => {
939
+ if (!(error instanceof Failed) || error.failure.reason !== "payload_too_large") throw error;
940
+ throw new Failed({
941
+ class: "limit",
942
+ reason: "payload_too_large",
943
+ message: `Can't use ${file} as the text. A message's text is at most ${MESSAGE_TEXT_MAX.toLocaleString("en-US")} characters.`
944
+ });
945
+ });
946
+ if (!data) throw usage(`Can't read ${file}. There's no such file.`, {
947
+ reason: "file_not_found",
948
+ next: []
949
+ });
950
+ return new TextDecoder().decode(data).replace(/\n$/, "");
951
+ }
952
+ if (value === void 0) {
953
+ if (optional) return "";
954
+ throw usage("Missing the message's text: pass it, - to read it from stdin, or --text-file <path>.", { reason: "missing_arguments" });
955
+ }
910
956
  if (value !== "-") return value;
911
957
  return (await io.stdin()).replace(/\n$/, "");
912
958
  }
@@ -1119,7 +1165,13 @@ function failureOf(error) {
1119
1165
  case "protected": return own("permission", "deployment_protected");
1120
1166
  case "no_project": return own("platform", "no_project");
1121
1167
  case "no_token": return own("auth", "token_unavailable");
1122
- case "no_board": return own("not_found", "board_not_found");
1168
+ case "no_board": return own("not_found", "board_not_found", [{
1169
+ instruction: "Check the name, or make it",
1170
+ argv: rerun("--ensure")
1171
+ }]);
1172
+ case "board_name_taken": return own("conflict", "board_name_taken");
1173
+ case "board_not_granted": return own("permission", "board_not_granted");
1174
+ case "invalid_board_name": return own("usage", "invalid_arguments", [helpRecovery()]);
1123
1175
  case "too_many_redirects": return own("network", "network_error");
1124
1176
  case "invalid_duration": return own("usage", "invalid_arguments", [helpRecovery()]);
1125
1177
  case "wrong_audience":
@@ -1265,12 +1317,19 @@ function profileFlag() {
1265
1317
  function connection(url = flags.url, options = {}) {
1266
1318
  const profile = profileFlag();
1267
1319
  const team = flags.scope ?? flags.team;
1268
- const configured = url ?? (team === void 0 ? configuredUrl() : null);
1320
+ const name = boardNameFlag(url, team);
1321
+ const configured = url ?? (team === void 0 && name === void 0 ? configuredUrl() : null);
1269
1322
  if (configured === null) {
1270
- const board$1 = board({ backend: vercel({
1271
- ...team !== void 0 ? { team } : {},
1272
- ...sending(options.token)
1273
- }) });
1323
+ const board$1 = board({
1324
+ backend: vercel({
1325
+ ...team !== void 0 ? { team } : {},
1326
+ ...sending(options.token)
1327
+ }),
1328
+ ...name !== void 0 ? {
1329
+ name,
1330
+ ensure: flags.ensure === true
1331
+ } : {}
1332
+ });
1274
1333
  return {
1275
1334
  url: null,
1276
1335
  transport: { source: credentialSource },
@@ -1303,6 +1362,37 @@ function connection(url = flags.url, options = {}) {
1303
1362
  board: profile !== void 0 ? board$2.as(profile) : board$2
1304
1363
  };
1305
1364
  }
1365
+ /**
1366
+ * The team's board this run names: `--name`, or `BOARD_NAME`, on `--scope`'s team or the one the
1367
+ * environment finds. A URL names a board itself, its team included. `BOARD_NAME` is read only
1368
+ * where it picks the board: beside `BOARD_URL`, which names another, nothing says which one.
1369
+ */
1370
+ function boardNameFlag(url, team) {
1371
+ 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" });
1372
+ 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" });
1373
+ 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" });
1374
+ if (url !== void 0) return void 0;
1375
+ const named = process.env.BOARD_NAME || void 0;
1376
+ 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" });
1377
+ const given = flags.name ?? named;
1378
+ if (given === void 0 && flags.ensure) throw usage("--ensure makes the board --name names: pass --name too.", { reason: "missing_arguments" });
1379
+ if (given === void 0) return void 0;
1380
+ const from = flags.name !== void 0 ? "--name" : "BOARD_NAME";
1381
+ if (given.includes("/")) {
1382
+ const [owner, ...rest] = given.split("/");
1383
+ const argv = rerunWithout([
1384
+ "--name",
1385
+ "--scope",
1386
+ "--team"
1387
+ ], "--scope", owner || "<TEAM>", "--name", rest.join("/") || "<NAME>");
1388
+ throw usage(`${from} takes a board's name alone, not its team's.`, { next: [flags.name !== void 0 ? {
1389
+ instruction: "Pass its team with --scope",
1390
+ argv
1391
+ } : { instruction: "Set BOARD_NAME to the name alone, and pass its team with --scope" }] });
1392
+ }
1393
+ if (!isBoardName(given)) throw usage(`${from} ${given} isn't a board's name: one is 1 to 64 characters.`);
1394
+ return given;
1395
+ }
1306
1396
  /** For Vercel's API, `token` in place of your own credentials: a board token's secret. */
1307
1397
  function sending(token) {
1308
1398
  if (token === void 0) return {};
@@ -1363,6 +1453,7 @@ function printDone(id, outcome) {
1363
1453
  message: { id },
1364
1454
  outcome
1365
1455
  });
1456
+ else out(`${outcome} ${messageRef(id)}`);
1366
1457
  }
1367
1458
  /** Best-effort: the URL is printed either way. */
1368
1459
  /** `url`, when it's an http or https URL as `new URL` reads it: the only kind the CLI opens, so a board can't hand the opener a flag or another scheme. */
@@ -1430,6 +1521,17 @@ async function run(command, args) {
1430
1521
  }
1431
1522
  case "conformance": {
1432
1523
  if (args.length > 0) throw usage("conformance takes no arguments: pass its channel with --channel.");
1524
+ const named = flags.name !== void 0 || flags.url !== void 0 || Boolean(process.env.BOARD_URL?.trim()) || Boolean(process.env.BOARD_NAME);
1525
+ if (!io.board && !named) throw usage("conformance posts and changes grants, so name a scratch board for it.", {
1526
+ reason: "needs_scratch_board",
1527
+ next: [{
1528
+ instruction: "Check a scratch board on this team, by its name",
1529
+ argv: rerun("--name", "<BOARD>")
1530
+ }, {
1531
+ instruction: "Or a board by its URL",
1532
+ argv: rerun("--url", "<URL>")
1533
+ }]
1534
+ });
1433
1535
  const withToken = io.board ? {} : { withToken: (secret) => connection(flags.url, { token: secret }).board };
1434
1536
  const report = await conformance(client(), {
1435
1537
  ...flags.channel ? { channel: flags.channel } : {},
@@ -1548,7 +1650,7 @@ async function run(command, args) {
1548
1650
  if (flags.sync?.length && flags["no-sync"]) throw usage("Can't use --sync with --no-sync.");
1549
1651
  if (re === void 0 && flags.after !== void 0) throw usage("Can't use --after on a new thread. It's for replies: the thread's newest message.");
1550
1652
  const board = client();
1551
- const content = body === void 0 && flags.attach?.length ? "" : await text(body);
1653
+ const content = await text(body, { optional: !!flags.attach?.length });
1552
1654
  const files = await attachments(board);
1553
1655
  const options = {
1554
1656
  text: content,
@@ -1571,11 +1673,12 @@ async function run(command, args) {
1571
1673
  case "reply": {
1572
1674
  const id = messageId(args[0]);
1573
1675
  const board = client();
1574
- const content = args[1] === void 0 && flags.attach?.length ? "" : await text(args[1]);
1676
+ const content = await text(args[1], { optional: !!flags.attach?.length });
1575
1677
  const files = await attachments(board);
1576
1678
  const message = await board.reply(id, {
1577
1679
  text: content,
1578
1680
  ...files.length ? { attachments: files } : {},
1681
+ ...flags.label?.length ? { labels: labelPairs(flags.label) } : {},
1579
1682
  ...flags["idempotency-key"] ? { id: flags["idempotency-key"] } : {},
1580
1683
  ...flags["no-sync"] ? { noSync: true } : {},
1581
1684
  ...flags.after !== void 0 ? { after: messageId(flags.after) } : {}
@@ -1601,7 +1704,7 @@ async function run(command, args) {
1601
1704
  const times = flags.times === void 0 ? void 0 : Number(flags.times);
1602
1705
  if (times !== void 0 && !(Number.isInteger(times) && times > 0)) throw usage(`--times takes a count, and ${flags.times} isn't one.`);
1603
1706
  const board = client();
1604
- const content = body === void 0 && flags.attach?.length ? "" : await text(body);
1707
+ const content = await text(body, { optional: !!flags.attach?.length });
1605
1708
  const files = await attachments(board);
1606
1709
  const where = isMessageRef(target) ? { re: messageId(target) } : target;
1607
1710
  const schedule = await board.schedule(where, {
@@ -1998,7 +2101,8 @@ async function runOnce(argv, options) {
1998
2101
  args
1999
2102
  };
2000
2103
  if (io.board) {
2001
- 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: [] });
2104
+ const given = flags.url ? "url" : flags.name !== void 0 ? "name" : flags.ensure ? "ensure" : flags.handle ? "handle" : null;
2105
+ if (given) throw usage(`--${given} doesn't apply in-process: the board handle you pass says which board and who.`, { next: [] });
2002
2106
  if (command !== void 0 && MACHINE.has(command)) throw usage(`${command} isn't available in-process: it's about the machine ${named()} runs on.`, {
2003
2107
  reason: "not_available",
2004
2108
  next: []
@@ -1,6 +1,6 @@
1
- import { r as sqlTables } from "../sql-CT5xVuGr.mjs";
2
- import { t as sqliteDb } from "../sqlite-db-0WeSOEZN.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-Pk0XV1hK.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 };