@vercel/board 0.33.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/{access-N3XmkKXg.mjs → access-BsP0hvcC.mjs} +169 -12
  2. package/dist/access.d.mts +3 -3
  3. package/dist/access.mjs +5 -5
  4. package/dist/{actors-ihyN47OV.mjs → actors-DFOpTw89.mjs} +2 -2
  5. package/dist/{auth-D6z3rMNj.d.mts → auth-C21V0EK1.d.mts} +128 -9
  6. package/dist/auth-CrjXLgOb.mjs +599 -0
  7. package/dist/{backend-CWpyR1A7.d.mts → backend-D21q8mdm.d.mts} +30 -7
  8. package/dist/backend-local.d.mts +1 -1
  9. package/dist/backend-local.mjs +1 -1
  10. package/dist/{chat-provider-DJpFUaFv.d.mts → chat-provider-DmZCmBkb.d.mts} +2 -2
  11. package/dist/cli-commands.d.mts +1 -1
  12. package/dist/cli-commands.mjs +1 -1
  13. package/dist/cli-embedded.d.mts +2 -2
  14. package/dist/cli-embedded.mjs +1 -1
  15. package/dist/cli.mjs +5 -5
  16. package/dist/{commands-BOBQHVqM.d.mts → commands-BorACIFS.d.mts} +168 -1
  17. package/dist/{commands-CHoMl06v.mjs → commands-CENWob9m.mjs} +281 -11
  18. package/dist/{conformance-qKmGLTAT.mjs → conformance-CKrwglzA.mjs} +491 -105
  19. package/dist/conformance.d.mts +20 -2
  20. package/dist/conformance.mjs +1 -1
  21. package/dist/{engine-JxgZiikU.mjs → engine-wN7quvbU.mjs} +2 -2
  22. package/dist/{errors-Pk0XV1hK.mjs → errors-rYDxZEuN.mjs} +116 -7
  23. package/dist/exports-BxljH73E.d.mts +4 -0
  24. package/dist/{exports-gHDHlg0i.mjs → exports-GIRJm2Ja.mjs} +136 -26
  25. package/dist/{index-CXvvYNYj.d.mts → index-LREsSZb2.d.mts} +2 -2
  26. package/dist/index.d.mts +6 -6
  27. package/dist/index.mjs +4 -4
  28. package/dist/index.node.d.mts +6 -6
  29. package/dist/index.node.mjs +3 -3
  30. package/dist/inspect/app.js +32 -32
  31. package/dist/{local-BbLjA5vI.mjs → local-yKwdgukb.mjs} +1981 -1574
  32. package/dist/{main-CQpCZJFw.mjs → main-DjokcEAL.mjs} +440 -50
  33. package/dist/{middleware-BU7rVi9F.mjs → middleware-BxgizazV.mjs} +1 -1
  34. package/dist/provider-DEOfc4Ls.d.mts +1049 -0
  35. package/dist/{provider-BlzUvcM9.d.mts → routes-BpKdMvgX.d.mts} +2461 -2480
  36. package/dist/{serve-D8_W4UN6.mjs → serve-CJ8hauK2.mjs} +4 -4
  37. package/dist/{server-BiIUXWbU.mjs → server-CtaTtyhw.mjs} +7 -7
  38. package/dist/{serving-D7rcUtSC.mjs → serving-6_bhBNAW.mjs} +1 -1
  39. package/dist/sync-chat-sdk.d.mts +2 -2
  40. package/dist/sync-github.d.mts +2 -2
  41. package/dist/sync-linear.d.mts +3 -2
  42. package/dist/sync-slack.d.mts +3 -3
  43. package/dist/sync.d.mts +2 -2
  44. package/dist/{targets-CknPGGVi.mjs → targets-n2i2ZOWI.mjs} +104 -12
  45. package/dist/{tokens-DPKjl3jf.mjs → tokens-Dn4cPZIr.mjs} +2 -2
  46. package/docs/01-board/01-mounting.md +12 -5
  47. package/docs/01-board/03-identity.md +14 -13
  48. package/docs/01-board/07-schedules.md +1 -1
  49. package/docs/01-board/09-access.md +170 -58
  50. package/docs/03-guides/03-ci.md +19 -17
  51. package/docs/03-guides/05-agent-factory.md +5 -6
  52. package/docs/04-reference/01-cli.md +99 -22
  53. package/docs/04-reference/02-board.md +42 -11
  54. package/docs/04-reference/03-http.md +21 -14
  55. package/docs/04-reference/05-conformance.md +31 -5
  56. package/package.json +1 -1
  57. package/dist/auth-r-_PeZyw.mjs +0 -277
  58. package/dist/exports-BuKjVq2t.d.mts +0 -4
  59. package/dist/folds-DjFTiqIM.d.mts +0 -552
@@ -1,12 +1,12 @@
1
- import { _ as fileSize, m as DIRECT_UPLOAD_BYTES_MAX, u as BoardError } from "./errors-Pk0XV1hK.mjs";
1
+ import { _ as fileSize, m as DIRECT_UPLOAD_BYTES_MAX, u as BoardError } from "./errors-rYDxZEuN.mjs";
2
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";
3
+ import { h as VERSION, s as withMentions } from "./targets-n2i2ZOWI.mjs";
4
4
  import { n as displayEmoji, r as normalizeEmoji } from "./emoji-CTLpvH-A.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";
5
+ import { r as PERMISSIONS, u as parseScope } from "./access-BsP0hvcC.mjs";
6
+ import { i as isApiMessageId, n as isBoardName } from "./exports-GIRJm2Ja.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-CENWob9m.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-CtaTtyhw.mjs";
9
+ import { t as conformance } from "./conformance-CKrwglzA.mjs";
10
10
  import { t as displayText } from "./bots-CGkO76qH.mjs";
11
11
  import { spawn } from "node:child_process";
12
12
  import { readFile, stat, writeFile } from "node:fs/promises";
@@ -14,6 +14,257 @@ import { mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "
14
14
  import { homedir } from "node:os";
15
15
  import { basename, dirname, join } from "node:path";
16
16
  import { parseArgs } from "node:util";
17
+ //#region src/cli/grants.ts
18
+ /** What's wrong with the flags, as misuse: the headline, and its ways out when they aren't help. */
19
+ var GrantMisuse = class extends Error {
20
+ next;
21
+ constructor(message, next) {
22
+ super(message);
23
+ this.next = next;
24
+ }
25
+ };
26
+ /** What starts a principal, after `--`, `--add-`, or `--remove-`. */
27
+ const KINDS = [
28
+ "user",
29
+ "project",
30
+ "github",
31
+ "oidc",
32
+ "app",
33
+ "all-users",
34
+ "all-projects",
35
+ "all-apps",
36
+ "everyone"
37
+ ];
38
+ /** Each modifier, and the principals it fits. */
39
+ const MODIFIERS = {
40
+ environment: ["project", "all-projects"],
41
+ workflow: ["github"],
42
+ branch: ["github"],
43
+ event: ["github"],
44
+ claim: ["oidc"]
45
+ };
46
+ const fits = (modifier) => MODIFIERS[modifier].map((kind) => `--${kind}`).join(" or ");
47
+ const flagOf = (started) => `--${started.prefix}${started.kind}${started.value !== void 0 ? ` ${started.value}` : ""}`;
48
+ /** The principals the flags name, each with the prefix its flag had, in the order they were typed. */
49
+ function principalsIn(tokens, prefixes, removal) {
50
+ const started = [];
51
+ for (const { name, value } of tokens) {
52
+ const prefix = prefixes.find((candidate) => KINDS.includes(name.slice(candidate.length)) && name.startsWith(candidate));
53
+ if (prefix !== void 0) {
54
+ const kind = name.slice(prefix.length);
55
+ if (kind === "github" && !/^[^/\s]+\/[^/\s]+$/.test(value ?? "")) throw new GrantMisuse(`--${name} takes owner/repo, like acme/web: got ${value}.`);
56
+ started.push({
57
+ prefix,
58
+ kind,
59
+ value
60
+ });
61
+ continue;
62
+ }
63
+ if (!Object.hasOwn(MODIFIERS, name)) continue;
64
+ const last = started.at(-1);
65
+ if (!last) throw new GrantMisuse(`--${name} goes after the ${fits(name)} it's for.`);
66
+ if (!MODIFIERS[name].includes(last.kind)) throw new GrantMisuse(`--${name} is for ${fits(name)}, not ${flagOf(last)}.`);
67
+ const given = value ?? "";
68
+ switch (name) {
69
+ case "environment": {
70
+ if (last.prefix === "remove-") throw new GrantMisuse(`${flagOf(last)} removes it whatever its environments, so it takes no --environment.`, removal?.({
71
+ kind: last.kind,
72
+ value: last.value
73
+ }));
74
+ const environments = given.split(",").map((environment) => environment.trim());
75
+ if (environments.some((environment) => environment === "")) throw new GrantMisuse(`--environment takes environments, comma-separated, like production,preview: got ${JSON.stringify(given)}.`);
76
+ last.environments = [.../* @__PURE__ */ new Set([...last.environments ?? [], ...environments])];
77
+ break;
78
+ }
79
+ case "workflow":
80
+ case "branch":
81
+ case "event":
82
+ if (last[name] !== void 0) throw new GrantMisuse(`${flagOf(last)} takes one --${name}: name the repository again for another.`);
83
+ last[name] = given;
84
+ break;
85
+ case "claim": {
86
+ const at = given.indexOf("=");
87
+ if (at <= 0) throw new GrantMisuse(`--claim takes name=value, like project_id=42: got ${JSON.stringify(given)}.`);
88
+ const claims = last.claims ??= {};
89
+ const [claim, one] = [given.slice(0, at), given.slice(at + 1)];
90
+ const had = claims[claim];
91
+ claims[claim] = had === void 0 ? one : [...[had].flat(), one];
92
+ break;
93
+ }
94
+ }
95
+ }
96
+ return started.map((one) => ({
97
+ prefix: one.prefix,
98
+ principal: inputOf(one)
99
+ }));
100
+ }
101
+ /** A principal as the handle takes it, which makes a project's environments production when they're left out. */
102
+ function inputOf(started) {
103
+ const { environments } = started;
104
+ const value = started.value;
105
+ switch (started.kind) {
106
+ case "user": return value.includes("@") ? {
107
+ kind: "user",
108
+ email: value
109
+ } : {
110
+ kind: "user",
111
+ userId: value
112
+ };
113
+ case "project": return {
114
+ kind: "project",
115
+ project: value,
116
+ ...environments ? { environments } : {}
117
+ };
118
+ case "github": return {
119
+ kind: "github",
120
+ repository: value,
121
+ ...started.workflow !== void 0 ? { workflow: started.workflow } : {},
122
+ ...started.branch !== void 0 ? { branch: started.branch } : {},
123
+ ...started.event !== void 0 ? { event: started.event } : {}
124
+ };
125
+ case "oidc": return {
126
+ kind: "oidc",
127
+ issuer: value,
128
+ claims: started.claims ?? {}
129
+ };
130
+ case "app": return {
131
+ kind: "app",
132
+ app: value
133
+ };
134
+ case "all-projects": return {
135
+ kind: "all-projects",
136
+ ...environments ? { environments } : {}
137
+ };
138
+ default: return { kind: started.kind };
139
+ }
140
+ }
141
+ const WORDS = [
142
+ ...PERMISSIONS,
143
+ "all",
144
+ "none"
145
+ ];
146
+ /**
147
+ * A grant's `can`, from each `--can pattern=permissions`, repeated or `;`-joined: `all` for every
148
+ * permission and `none` for no permissions, each alone. The board keeps it as written.
149
+ */
150
+ function grantCanOf(values) {
151
+ const can = {};
152
+ for (const entry of values.flatMap((value) => value.split(";")).map((one) => one.trim()).filter(Boolean)) {
153
+ const at = entry.indexOf("=");
154
+ if (at <= 0) throw new GrantMisuse(`--can takes pattern=permissions, like ci/=read,post: got ${JSON.stringify(entry)}.`);
155
+ const pattern = entry.slice(0, at).trim();
156
+ if (Object.hasOwn(can, pattern)) throw new GrantMisuse(`--can names ${pattern} twice: say it once, with every permission it gives.`);
157
+ const words = entry.slice(at + 1).split(",").map((word) => word.trim()).filter(Boolean);
158
+ for (const word of words) if (!WORDS.includes(word)) throw new GrantMisuse(`--can: ${word} isn't a permission. Permissions are ${WORDS.slice(0, -1).join(", ")}, or ${WORDS.at(-1)}.`);
159
+ for (const alone of ["all", "none"]) if (words.includes(alone) && words.length > 1) throw new GrantMisuse(`--can: ${alone} is ${alone === "all" ? "every permission" : "no permissions"}, so it goes alone: ${pattern}=${alone}.`);
160
+ can[pattern] = words[0] === "all" ? "all" : words[0] === "none" ? [] : words;
161
+ }
162
+ return can;
163
+ }
164
+ /** Whom explain asks about, from the one principal its flags name, as the board takes it. */
165
+ function explainPrincipalOf(tokens) {
166
+ const named = principalsIn(tokens, [""]);
167
+ if (named.length === 0) return {
168
+ principal: {},
169
+ subject: null,
170
+ kind: null
171
+ };
172
+ if (named.length > 1) throw new GrantMisuse("explain asks about one principal at a time.");
173
+ const { principal } = named[0];
174
+ switch (principal.kind) {
175
+ case "user": {
176
+ const user = principal.email ?? principal.userId;
177
+ return {
178
+ principal: { user },
179
+ subject: user,
180
+ kind: "user"
181
+ };
182
+ }
183
+ case "project": {
184
+ const environments = principal.environments ?? [];
185
+ if (environments.length > 1) throw new GrantMisuse(`explain asks about one environment at a time: --environment ${environments[0]}.`);
186
+ const environment = environments[0] ?? "production";
187
+ return {
188
+ principal: {
189
+ project: principal.project,
190
+ environment
191
+ },
192
+ subject: `${principal.project} in ${environment}`,
193
+ kind: "project"
194
+ };
195
+ }
196
+ case "github": {
197
+ const { repository, workflow, branch, event } = principal;
198
+ return {
199
+ principal: {
200
+ github: repository,
201
+ ...workflow ? { workflow } : {},
202
+ ...branch ? { branch } : {},
203
+ ...event ? { event } : {}
204
+ },
205
+ subject: repository,
206
+ kind: "github"
207
+ };
208
+ }
209
+ case "oidc": {
210
+ const claims = {};
211
+ for (const [name, value] of Object.entries(principal.claims)) {
212
+ if (Array.isArray(value)) throw new GrantMisuse(`explain asks about one token: give --claim ${name} once.`);
213
+ claims[name] = value;
214
+ }
215
+ return {
216
+ principal: {
217
+ oidc: principal.issuer,
218
+ claims
219
+ },
220
+ subject: principal.issuer,
221
+ kind: "oidc"
222
+ };
223
+ }
224
+ case "app": return {
225
+ principal: { app: principal.app },
226
+ subject: principal.app,
227
+ kind: "app"
228
+ };
229
+ default: throw new GrantMisuse(`explain asks about someone: --user, --project, --github, --oidc, or --app, not --${principal.kind}.`);
230
+ }
231
+ }
232
+ /** Permissions as `--can` writes them: `all` for every one, `none` for none. */
233
+ const canWords = (can) => can.length === PERMISSIONS.length ? "all" : can.length === 0 ? "none" : can.join(",");
234
+ /** The principal flag a level names, for whom explain asked about: `--user`, `--all-projects`, `--everyone`. */
235
+ function levelFlag(level, kind, grants) {
236
+ if (level === "everyone") return "--everyone";
237
+ const kinds = [...new Set(grants.flatMap((grant) => grant.principals.map((principal) => principal.kind)))];
238
+ const group = level === "group";
239
+ const of = kinds.filter((one) => (one === "all-users" || one === "all-projects" || one === "all-apps") === group && one !== "everyone");
240
+ if (group) {
241
+ if (kind === "user") return "--all-users";
242
+ if (kind === "project") return "--all-projects";
243
+ if (kind === "app") return "--all-apps";
244
+ return of.length === 1 ? `--${of[0]}` : null;
245
+ }
246
+ if (kind !== null) return `--${kind}`;
247
+ return of.length === 1 ? `--${of[0]}` : null;
248
+ }
249
+ /**
250
+ * Explain's answer in a sentence or two: which pattern won, and over what; the closest grants
251
+ * there; and what they give.
252
+ * `security/ wins over *. Closest grant for bob@acme.com: g4 (--user): all.`
253
+ */
254
+ function explanationLine(answer, subject, kind) {
255
+ const whom = subject ?? "you";
256
+ const given = `${canWords(answer.can)}${answer.capped !== null ? `, capped by the ${answer.capped} role` : ""}`;
257
+ if (answer.pattern === null || answer.level === null) {
258
+ if (answer.can.length === 0) return `Nothing lets ${whom} into ${answer.channel}.`;
259
+ return `The board lets ${whom} in itself, outside its grants: ${given}.`;
260
+ }
261
+ const wins = answer.over.length > 0 ? `${answer.pattern} wins over ${answer.over.join(", ")}.` : `${answer.pattern} wins.`;
262
+ const flag = levelFlag(answer.level, kind, answer.grants);
263
+ const at = flag ? ` (${flag})` : "";
264
+ const which = answer.grants.map((grant) => `${grant.id}${at}`);
265
+ return `${wins} Closest ${which.length > 0 ? `${which.length === 1 ? "grant" : "grants"} for ${whom}: ${which.join(", ")}` : `grant for ${whom}: ${flag ? `a ${flag} grant` : "one"} you can't list`}: ${given}.`;
266
+ }
267
+ //#endregion
17
268
  //#region src/cli/format.ts
18
269
  /** "claude via julian" for a profile, the name otherwise. */
19
270
  /**
@@ -163,22 +414,59 @@ function formatCan(can) {
163
414
  const patterns = Object.keys(can);
164
415
  if (patterns.length === 1 && patterns[0] === "*" && can["*"].includes("manage")) return "all";
165
416
  if (patterns.length === 0) return "nothing";
166
- return patterns.map((pattern) => `${pattern}=${can[pattern].includes("manage") ? "all" : can[pattern].join(",")}`).join(";");
417
+ const permissions = (list) => list.includes("manage") ? "all" : list.length === 0 ? "none" : list.join(",");
418
+ return patterns.map((pattern) => `${pattern}=${permissions(can[pattern])}`).join(";");
167
419
  }
168
420
  /** Rows of cells, each column padded to its widest, two spaces apart. */
169
421
  const table = (rows) => {
170
422
  const widths = rows[0].map((_, column) => Math.max(...rows.map((row) => row[column].length)));
171
423
  return rows.map((row) => row.map((cell, column) => column === row.length - 1 ? cell : cell.padEnd(widths[column])).join(" ").trimEnd()).join("\n");
172
424
  };
173
- /** Each grant on a row: its ID, its issuer, the claims it matches, and what it lets do. */
425
+ /** A workflow as people name it: `ci.yml` for `.github/workflows/ci.yml`. */
426
+ const workflowName = (workflow) => workflow.replace(/^\.github\/workflows\/(?=[^/]+$)/, "");
427
+ /** A principal as the flags that name it: `--user ada@acme.com`, `--project web --environment production,preview`. */
428
+ function principalFlags(principal) {
429
+ switch (principal.kind) {
430
+ case "user": return `--user ${principal.email ?? principal.userId}`;
431
+ case "project": return `--project ${principal.name ?? principal.projectId} --environment ${principal.environments.join(",")}`;
432
+ case "github": return [
433
+ `--github ${principal.repository}`,
434
+ ...principal.workflow !== void 0 ? [`--workflow ${workflowName(principal.workflow)}`] : [],
435
+ ...principal.branch !== void 0 ? [`--branch ${principal.branch}`] : [],
436
+ ...principal.event !== void 0 ? [`--event ${principal.event}`] : []
437
+ ].join(" ");
438
+ case "oidc": return [`--oidc ${principal.issuer}`, ...Object.entries(principal.claims).flatMap(([name, value]) => [value].flat().map((one) => `--claim ${name}=${one}`))].join(" ");
439
+ case "all-projects": return `--all-projects --environment ${principal.environments.join(",")}`;
440
+ case "app": return `--app ${principal.name ?? principal.clientId}`;
441
+ default: return `--${principal.kind}`;
442
+ }
443
+ }
444
+ /**
445
+ * What a grant lets do, as `--can` writes it, `security/=none ci/=read,post`, or in words for
446
+ * `*` alone: `read post react label`, or `everything your role allows` for all of it where team
447
+ * roles cap it.
448
+ */
449
+ function grantCan(can, capped) {
450
+ const patterns = Object.keys(can);
451
+ const words = (grant) => grant === "all" ? "all" : grant.length === 0 ? "none" : grant.join(",");
452
+ if (patterns.length === 1 && patterns[0] === "*") {
453
+ const all = can["*"];
454
+ if (all === "all" || all.includes("manage")) return capped ? "everything your role allows" : "everything";
455
+ return all.length === 0 ? "nothing" : all.join(" ");
456
+ }
457
+ return patterns.map((pattern) => `${pattern}=${words(can[pattern])}`).join(" ");
458
+ }
459
+ const grantCells = (grant) => [
460
+ grant.id,
461
+ grant.principals.map(principalFlags).join(" "),
462
+ grantCan(grant.can, grant.capped)
463
+ ];
464
+ /** Each grant on a row: its ID, who it names (as the flags that would), and what it lets them do. */
174
465
  function formatGrants(grants) {
175
- return table(grants.map((grant) => [
176
- grant.id,
177
- grant.issuer,
178
- Object.entries(grant.claims).map(([name, value]) => `${name}=${typeof value === "string" ? value : value.join("|")}`).join(" "),
179
- formatCan(grant.can)
180
- ]));
466
+ return table(grants.map(grantCells));
181
467
  }
468
+ /** One grant as its row: `g3 --everyone security/=none`. */
469
+ const grantRow = (grant) => grantCells(grant).join(" ");
182
470
  /** Each token on a row: its ID, its name, what it may do, and when it expires. */
183
471
  function formatTokens(tokens, now = Date.now()) {
184
472
  return table(tokens.map((token) => [
@@ -767,6 +1055,8 @@ let app = {
767
1055
  };
768
1056
  let flags = {};
769
1057
  let positionals = [];
1058
+ /** Every option as it was typed, in order: what reads principal flags and the modifiers after each. */
1059
+ let ordered = [];
770
1060
  /** The command this run runs, by its own name, and what follows it: what a failure says it was doing. */
771
1061
  let current = {
772
1062
  command: void 0,
@@ -808,6 +1098,15 @@ function parse(argv) {
808
1098
  if (removed) throw removed;
809
1099
  try {
810
1100
  const parsed = parseAll(markAttachmentId(args));
1101
+ ordered = parseArgs({
1102
+ args: markAttachmentId(args),
1103
+ allowPositionals: true,
1104
+ options: OPTIONS,
1105
+ tokens: true
1106
+ }).tokens.flatMap((token) => token.kind === "option" ? [{
1107
+ name: token.name,
1108
+ value: token.value
1109
+ }] : []);
811
1110
  flags = parsed.values;
812
1111
  positionals = parsed.positionals.map((arg) => arg.startsWith(MARK) ? arg.slice(1) : arg);
813
1112
  } catch (error) {
@@ -991,23 +1290,43 @@ function trustId(what, value) {
991
1290
  if (!/^[^\s/]+$/.test(value)) throw usage(`${value} isn't a ${what} ID like ${like}.`);
992
1291
  return value;
993
1292
  }
994
- /** `--can`, as `x-board-scope` writes it: `dev/=read,post;ci/=read`. */
995
- function canFlag(value) {
1293
+ /**
1294
+ * A token's `--can`, as `x-board-scope` writes it (`dev/=read,post;ci/=read`), repeated or
1295
+ * `;`-joined, with `none` for no permissions, as `all` is every one: `*=all;security/=none` closes a
1296
+ * subtree. `security/=` means the same. The board takes an empty list, so `none` never leaves the CLI.
1297
+ */
1298
+ function canFlag(values) {
1299
+ const scope = values.flatMap((value) => value.split(";")).map((entry) => {
1300
+ const at = entry.indexOf("=");
1301
+ if (at === -1) return entry;
1302
+ const permissions = entry.slice(at + 1).split(",").map((permission) => permission.trim());
1303
+ if (permissions.includes("none") && permissions.length > 1) throw usage(`--can: none is no permissions, so it goes alone: ${entry.slice(0, at).trim()}=none.`);
1304
+ return permissions[0] === "none" ? entry.slice(0, at + 1) : entry;
1305
+ }).join(";");
996
1306
  try {
997
- return parseScope(value);
1307
+ return parseScope(scope);
998
1308
  } catch (error) {
999
- throw usage(`${error.message.replace(/x-board-scope/g, "--can")}.`);
1309
+ throw usage(`${error.message.replace(/x-board-scope/g, "--can").replace(/, or all$/, ", all, or none")}.`);
1000
1310
  }
1001
1311
  }
1002
- /** `--claim k=v`, each again: the same name twice is any of its values. */
1003
- function claimPairs(values) {
1004
- const claims = {};
1005
- for (const value of values ?? []) {
1006
- const at = value.indexOf("=");
1007
- if (at <= 0 || at === value.length - 1) throw usage(`Claims look like name=value, and ${value} isn't one.`);
1008
- (claims[value.slice(0, at)] ??= []).push(value.slice(at + 1));
1312
+ /** What a grant's flags say, or the misuse in them. */
1313
+ function grantFlags(read) {
1314
+ try {
1315
+ return read();
1316
+ } catch (error) {
1317
+ if (error instanceof GrantMisuse) throw usage(error.message, error.next ? { next: error.next } : {});
1318
+ throw error;
1319
+ }
1320
+ }
1321
+ /** Refuses the principal flags `verb` doesn't take: plain ones on update, `--add-` and `--remove-` ones elsewhere. */
1322
+ function onlyPrincipalFlags(verb) {
1323
+ for (const { name } of ordered) {
1324
+ const kind = name.replace(/^(add|remove)-/, "");
1325
+ if (!KINDS.includes(kind)) continue;
1326
+ const prefixed = kind !== name;
1327
+ if (verb === "update" && !prefixed) throw usage(`grants update adds and removes principals: --add-${kind} or --remove-${kind}, not --${kind}.`);
1328
+ if (verb !== "update" && prefixed) throw usage(`--${name} is for grants update: grants ${verb} names principals as --${kind}.`);
1009
1329
  }
1010
- return Object.fromEntries(Object.entries(claims).map(([name, list]) => [name, list.length === 1 ? list[0] : list]));
1011
1330
  }
1012
1331
  /** A time flag: anything `Date` reads, as ISO. */
1013
1332
  function instant(flag, value) {
@@ -1080,7 +1399,7 @@ function doing() {
1080
1399
  case "channels": return a === "create" ? `create ${b ?? "the channel"}` : "list channels";
1081
1400
  case "schedules":
1082
1401
  case "actors": return `list ${command}`;
1083
- case "grants": return a === "create" ? `grant ${b ?? "an issuer"}` : a === "revoke" ? `revoke grant ${b}` : "list grants";
1402
+ case "grants": return a === "create" ? "create the grant" : a === "update" ? `update grant ${b}` : a === "explain" ? `explain ${b ?? "the channel"}` : a === "revoke" ? `revoke grant ${b}` : "list grants";
1084
1403
  case "tokens": return a === "create" ? `mint token ${b ?? ""}`.trimEnd() : a === "revoke" ? `revoke token ${b}` : "list tokens";
1085
1404
  case "sources": return b === void 0 ? "list sources" : `${b} ${c ?? "it"} on ${a}`;
1086
1405
  case "download": return `download ${a ?? "the attachment"}`;
@@ -1115,7 +1434,7 @@ function missing() {
1115
1434
  "schedule"
1116
1435
  ].includes(command) && isMessageRef(a)) return `message ${ref(a)}`;
1117
1436
  if (command === "schedule" && a === "cancel" && b !== void 0) return `schedule ${b}`;
1118
- if ((command === "grants" || command === "tokens") && a === "revoke" && b !== void 0) return `${command === "grants" ? "grant" : "token"} ${b}`;
1437
+ if ((command === "grants" || command === "tokens") && (a === "revoke" || a === "update") && b !== void 0) return `${command === "grants" ? "grant" : "token"} ${b}`;
1119
1438
  if (command === "download") return `attachment ${a}`;
1120
1439
  }
1121
1440
  /**
@@ -1171,6 +1490,8 @@ function failureOf(error) {
1171
1490
  }]);
1172
1491
  case "board_name_taken": return own("conflict", "board_name_taken");
1173
1492
  case "board_not_granted": return own("permission", "board_not_granted");
1493
+ case "board_token_unsupported": return own("permission", "board_token_unsupported");
1494
+ case "board_token_scope": return own("permission", "board_token_scope");
1174
1495
  case "invalid_board_name": return own("usage", "invalid_arguments", [helpRecovery()]);
1175
1496
  case "too_many_redirects": return own("network", "network_error");
1176
1497
  case "invalid_duration": return own("usage", "invalid_arguments", [helpRecovery()]);
@@ -1197,6 +1518,9 @@ function failureOf(error) {
1197
1518
  message: `Failed to ${doing()}.`,
1198
1519
  details: [message]
1199
1520
  };
1521
+ case "channel_exists": return own("conflict", "channel_exists");
1522
+ case "channel_granted": return own("conflict", "channel_granted");
1523
+ case "no_own_principal": return own("usage", "no_own_principal");
1200
1524
  case "port_taken": return own("conflict", "port_taken", [{
1201
1525
  instruction: "Pick another port",
1202
1526
  argv: [
@@ -1532,7 +1856,8 @@ async function run(command, args) {
1532
1856
  argv: rerun("--url", "<URL>")
1533
1857
  }]
1534
1858
  });
1535
- const withToken = io.board ? {} : { withToken: (secret) => connection(flags.url, { token: secret }).board };
1859
+ const tokenUrl = io.board ? void 0 : connection().url === null ? (await client().discovery()).url : flags.url;
1860
+ const withToken = io.board ? {} : { withToken: (secret) => connection(tokenUrl, { token: secret }).board };
1536
1861
  const report = await conformance(client(), {
1537
1862
  ...flags.channel ? { channel: flags.channel } : {},
1538
1863
  ...withToken
@@ -1547,12 +1872,16 @@ async function run(command, args) {
1547
1872
  const [path, extra] = rest;
1548
1873
  if (!path) throw usage("Missing the channel to create, such as dev/alerts.", { reason: "missing_arguments" });
1549
1874
  if (extra !== void 0) throw usage(`channels create takes one channel: ${extra} is one too many.`);
1550
- const { channel, created } = await client().createChannel(path);
1875
+ const { channel, created, grants } = await client().createChannel(path, flags.private ? { private: true } : {});
1551
1876
  if (flags.json) result({
1552
1877
  channel,
1553
- outcome: created ? "created" : "unchanged"
1878
+ outcome: created ? "created" : "unchanged",
1879
+ ...grants ? { grants } : {}
1554
1880
  });
1555
- else out(created ? `created ${channel.path}` : `${channel.path} already exists`);
1881
+ else if (grants) {
1882
+ out(`created channel ${channel.path}`);
1883
+ for (const grant of grants) out(`created ${grantRow(grant)}`);
1884
+ } else out(created ? `created ${channel.path}` : `${channel.path} already exists`);
1556
1885
  return 0;
1557
1886
  }
1558
1887
  if (sub !== void 0 && sub !== "list") throw usage(`Unknown command ${sub} for ${named()} channels.`, { reason: "unknown_command" });
@@ -1736,6 +2065,83 @@ async function run(command, args) {
1736
2065
  out(list.length === 0 ? "no grants" : formatGrants(list));
1737
2066
  return 0;
1738
2067
  }
2068
+ if (verb === "create") {
2069
+ if (rest.length > 0) throw usage(`grants create takes no arguments: ${rest[0]} is one too many.`);
2070
+ onlyPrincipalFlags("create");
2071
+ const principals = grantFlags(() => principalsIn(ordered, [""])).map(({ principal }) => principal);
2072
+ if (principals.length === 0) throw usage("A grant names whom it lets in: --user, --project, --github, --oidc, --all-users, --all-projects, or --everyone.", { reason: "missing_arguments" });
2073
+ const can = grantFlags(() => grantCanOf(flags.can ?? []));
2074
+ if (Object.keys(can).length === 0) throw usage("A grant says what it lets them do: --can pattern=permissions, like --can 'ci/=read,post'.", { reason: "missing_arguments" });
2075
+ const { grant } = await client().createGrant({
2076
+ principals,
2077
+ can
2078
+ });
2079
+ const unsigned = principals.some((principal) => principal.kind === "github" || principal.kind === "oidc") && vercelBoard((await client().discovery()).url) !== null;
2080
+ const note = "Vercel's board doesn't sign in GitHub or OIDC callers yet: this grant works once it does";
2081
+ if (flags.json) {
2082
+ if (unsigned) warnings.push({
2083
+ reason: "callers_not_signed_in",
2084
+ message: note
2085
+ });
2086
+ result({
2087
+ grant,
2088
+ outcome: "created"
2089
+ });
2090
+ } else {
2091
+ out(`created ${grantRow(grant)}`);
2092
+ if (unsigned) out(`note ${note}`);
2093
+ }
2094
+ return 0;
2095
+ }
2096
+ if (verb === "update") {
2097
+ const id = trustId("grant", rest[0]);
2098
+ if (rest.length > 1) throw usage(`grants update takes one grant: ${rest[1]} is one too many.`);
2099
+ onlyPrincipalFlags("update");
2100
+ const named = grantFlags(() => principalsIn(ordered, ["add-", "remove-"], ({ kind, value }) => {
2101
+ const named = value !== void 0 ? [value] : [];
2102
+ return [{
2103
+ instruction: "Remove it and add it back with the environments it keeps",
2104
+ argv: [
2105
+ ...cli(),
2106
+ "grants",
2107
+ "update",
2108
+ id,
2109
+ `--remove-${kind}`,
2110
+ ...named,
2111
+ `--add-${kind}`,
2112
+ ...named,
2113
+ "--environment",
2114
+ "<ENVIRONMENTS>"
2115
+ ]
2116
+ }];
2117
+ }));
2118
+ const add = named.filter(({ prefix }) => prefix === "add-").map(({ principal }) => principal);
2119
+ const remove = named.filter(({ prefix }) => prefix === "remove-").map(({ principal }) => principal);
2120
+ const can = flags.can !== void 0 ? grantFlags(() => grantCanOf(flags.can)) : void 0;
2121
+ if (add.length === 0 && remove.length === 0 && can === void 0) throw usage(`grants update ${id} changes nothing: add or remove a principal (--add-user, --remove-project, …), or give --can.`, { reason: "missing_arguments" });
2122
+ const { grant } = await client().updateGrant(id, {
2123
+ ...add.length > 0 ? { add } : {},
2124
+ ...remove.length > 0 ? { remove } : {},
2125
+ ...can !== void 0 ? { can } : {}
2126
+ });
2127
+ if (flags.json) result({
2128
+ grant,
2129
+ outcome: "updated"
2130
+ });
2131
+ else out(`updated ${grantRow(grant)}`);
2132
+ return 0;
2133
+ }
2134
+ if (verb === "explain") {
2135
+ const [channel, extra] = rest;
2136
+ if (channel === void 0) throw usage("Missing the channel to explain, such as security/incidents.", { reason: "missing_arguments" });
2137
+ if (extra !== void 0) throw usage(`grants explain takes one channel: ${extra} is one too many.`);
2138
+ onlyPrincipalFlags("explain");
2139
+ const { principal, subject, kind } = grantFlags(() => explainPrincipalOf(ordered));
2140
+ const explanation = await client().explain(channel, principal);
2141
+ if (flags.json) result({ explanation });
2142
+ else out(explanationLine(explanation, subject, kind));
2143
+ return 0;
2144
+ }
1739
2145
  if (verb === "revoke") {
1740
2146
  const id = trustId("grant", rest[0]);
1741
2147
  const { revoked } = await client().revokeGrant(id);
@@ -1746,23 +2152,7 @@ async function run(command, args) {
1746
2152
  else out(revoked ? `revoked ${id}` : `${id} is already gone`);
1747
2153
  return 0;
1748
2154
  }
1749
- if (verb !== "create") throw usage(`Unknown command ${verb} for ${named()} grants.`, { reason: "unknown_command" });
1750
- const [issuer, extra] = rest;
1751
- if (!issuer) throw usage("Missing the issuer to grant: vercel, github, or an https URL.", { reason: "missing_arguments" });
1752
- if (extra !== void 0) throw usage(`grants create takes one issuer, and its claims as --claim name=value: ${extra} is one too many.`);
1753
- const claims = claimPairs(flags.claim);
1754
- if (Object.keys(claims).length === 0) throw usage(`Missing the claims ${issuer}'s tokens must carry: pass --claim name=value.`, { reason: "missing_arguments" });
1755
- const { grant, created } = await client().createGrant({
1756
- issuer,
1757
- claims,
1758
- ...flags.can !== void 0 ? { can: canFlag(flags.can) } : {}
1759
- });
1760
- if (flags.json) result({
1761
- grant,
1762
- outcome: created ? "granted" : "updated"
1763
- });
1764
- else out(`${created ? "granted" : "updated"} ${grant.id}`);
1765
- return 0;
2155
+ throw usage(`Unknown command ${verb} for ${named()} grants.`, { reason: "unknown_command" });
1766
2156
  }
1767
2157
  case "tokens": {
1768
2158
  const [verb, ...rest] = args;
@@ -1,4 +1,4 @@
1
- import { t as HttpError } from "./errors-Pk0XV1hK.mjs";
1
+ import { t as HttpError } from "./errors-rYDxZEuN.mjs";
2
2
  import { d as MESSAGE_TEXT_MAX, u as Labels } from "./schemas-BG205xds.mjs";
3
3
  import { z } from "zod";
4
4
  //#region src/client/ids.ts