@vercel/board 0.34.0 → 0.36.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 (67) hide show
  1. package/dist/{access-CdBcYPQH.mjs → access-BsP0hvcC.mjs} +1 -1
  2. package/dist/access.d.mts +2 -2
  3. package/dist/access.mjs +4 -4
  4. package/dist/{actors-MrIEr9LI.mjs → actors-DFOpTw89.mjs} +2 -2
  5. package/dist/{auth-aaoKt5DK.d.mts → auth-C21V0EK1.d.mts} +1 -1
  6. package/dist/{auth-DjoJygbG.mjs → auth-CrjXLgOb.mjs} +2 -2
  7. package/dist/{backend-u1sVvybh.d.mts → backend-D21q8mdm.d.mts} +3 -3
  8. package/dist/backend-local.d.mts +1 -1
  9. package/dist/backend-local.mjs +1 -1
  10. package/dist/{chat-provider-9hCT654s.mjs → chat-provider-Bb-jeJLY.mjs} +2 -2
  11. package/dist/{chat-provider-De0iDnUB.d.mts → chat-provider-DmZCmBkb.d.mts} +2 -2
  12. package/dist/cli-commands.d.mts +1 -1
  13. package/dist/cli-commands.mjs +1 -1
  14. package/dist/cli-embedded.d.mts +2 -2
  15. package/dist/cli-embedded.mjs +1 -1
  16. package/dist/cli.mjs +5 -5
  17. package/dist/{commands-B8oZEByR.mjs → commands-BLtqSwha.mjs} +324 -26
  18. package/dist/{commands-BkVMdXP1.d.mts → commands-DGID-4Z2.d.mts} +175 -0
  19. package/dist/{conformance-gqYBkXFS.mjs → conformance-CKrwglzA.mjs} +480 -87
  20. package/dist/conformance.d.mts +20 -2
  21. package/dist/conformance.mjs +1 -1
  22. package/dist/{engine-rtOVWsiF.mjs → engine-B_prP0b8.mjs} +4 -4
  23. package/dist/{errors-D8ifv16L.mjs → errors-rYDxZEuN.mjs} +98 -4
  24. package/dist/{events-IQg0k281.mjs → events-AEKh9tJm.mjs} +1 -1
  25. package/dist/exports-BxljH73E.d.mts +4 -0
  26. package/dist/{exports-Bx2dGpzr.mjs → exports-Ck4Xu3OV.mjs} +135 -24
  27. package/dist/{external-CYe424fO.mjs → external-BA2aCC_3.mjs} +1 -1
  28. package/dist/{index-D6mK0Ial.d.mts → index-LREsSZb2.d.mts} +2 -2
  29. package/dist/index.d.mts +6 -6
  30. package/dist/index.mjs +4 -4
  31. package/dist/index.node.d.mts +6 -6
  32. package/dist/index.node.mjs +3 -3
  33. package/dist/inspect/app.js +32 -32
  34. package/dist/{local-CPz22MQ8.mjs → local-DJ_qI9q7.mjs} +10 -10
  35. package/dist/{main-DScDKwQN.mjs → main-Jz4nbNJi.mjs} +409 -24
  36. package/dist/{memory-7RRnLa4X.mjs → memory-DqwXlyK4.mjs} +2 -2
  37. package/dist/{middleware-BjYpk4yq.mjs → middleware-BxgizazV.mjs} +1 -1
  38. package/dist/{provider-hB8QNrwm.d.mts → provider-DEOfc4Ls.d.mts} +21 -3
  39. package/dist/{routes-De4W6lEs.d.mts → routes-BpKdMvgX.d.mts} +19 -8
  40. package/dist/{serve-B1noQRkn.mjs → serve-Puf3I-oI.mjs} +4 -4
  41. package/dist/{server-Ov6GBJ8j.mjs → server-CS-1aeTl.mjs} +6 -6
  42. package/dist/{serving-2s7lqSBS.mjs → serving-6_bhBNAW.mjs} +1 -1
  43. package/dist/{sql-BQzKUqQt.mjs → sql-aetuEBZC.mjs} +1 -1
  44. package/dist/{sqlite-DCtZFEVm.mjs → sqlite-DvsB8ENQ.mjs} +2 -2
  45. package/dist/{sqlite-db-qLTs52Ny.mjs → sqlite-db-BPwRoDI7.mjs} +1 -1
  46. package/dist/sync-chat-sdk.d.mts +2 -2
  47. package/dist/sync-chat-sdk.mjs +2 -2
  48. package/dist/sync-github.d.mts +2 -2
  49. package/dist/sync-github.mjs +2 -2
  50. package/dist/sync-linear.d.mts +3 -3
  51. package/dist/sync-linear.mjs +2 -2
  52. package/dist/sync-slack.d.mts +3 -3
  53. package/dist/sync-slack.mjs +3 -3
  54. package/dist/sync.d.mts +2 -2
  55. package/dist/sync.mjs +2 -2
  56. package/dist/{targets-aMdbp84G.mjs → targets-Dk_xgS9q.mjs} +10 -6
  57. package/dist/{tokens-LHLrnV_P.mjs → tokens-Dn4cPZIr.mjs} +2 -2
  58. package/docs/01-board/01-mounting.md +7 -2
  59. package/docs/01-board/03-identity.md +1 -1
  60. package/docs/01-board/09-access.md +31 -0
  61. package/docs/03-guides/03-ci.md +5 -3
  62. package/docs/04-reference/01-cli.md +98 -14
  63. package/docs/04-reference/02-board.md +28 -3
  64. package/docs/04-reference/03-http.md +1 -1
  65. package/docs/04-reference/05-conformance.md +31 -5
  66. package/package.json +1 -1
  67. package/dist/exports-uwRl5qIj.d.mts +0 -4
@@ -1,5 +1,5 @@
1
- import { u as BoardError } from "./errors-D8ifv16L.mjs";
2
- import { s as compileAccess } from "./access-CdBcYPQH.mjs";
1
+ import { u as BoardError } from "./errors-rYDxZEuN.mjs";
2
+ import { s as compileAccess } from "./access-BsP0hvcC.mjs";
3
3
  //#region src/conformance/index.ts
4
4
  var Mismatch = class extends Error {};
5
5
  const show = (value) => JSON.stringify(value) ?? String(value);
@@ -59,26 +59,132 @@ const needRoot = (ctx) => {
59
59
  reply: ctx.reply
60
60
  };
61
61
  };
62
- /** A project that doesn't exist, by ID, which every board takes: a grant naming it lets nobody in. */
62
+ /** A check's project, in its environments. */
63
63
  const projectFor = (ctx, environments = ["preview"]) => ({
64
64
  kind: "project",
65
- project: `prj_conformance${ctx.labels.conformance}`,
65
+ project: ctx.principals.project,
66
66
  environments
67
67
  });
68
- /** The check's grant: that project may post in the check's channel. */
68
+ /**
69
+ * The subtree every grant the grants checks make sits in, `conformance/grants/`, and every channel
70
+ * they ask about: the same for every run, so a run leaves no channel behind, and no grant reaches
71
+ * outside it. Two runs on one board at once see each other's grants there.
72
+ */
73
+ const subtreeOf = (ctx) => `${ctx.channel}/grants/`;
74
+ /** The check's grant: that project may post in the subtree's `ci/`. */
69
75
  const grantFor = (ctx) => ({
70
76
  principals: [projectFor(ctx)],
71
- can: { [ctx.channel]: ["post"] }
77
+ can: { [`${subtreeOf(ctx)}ci/`]: ["post"] }
72
78
  });
73
- /** Makes the check's grant, or says why it can't: changing grants takes `manage` where they apply. */
74
- async function firstGrant(ctx, input = grantFor(ctx)) {
79
+ /** A check that can't run here, and why: it's skipped, not failed. */
80
+ var Skip = class extends Error {};
81
+ /** A board that looks names up and has none for one a check named: what to pass instead. */
82
+ function unnamed(error) {
83
+ if (!(error instanceof BoardError) || error.status !== 400 || !error.code.endsWith("_not_found")) return null;
84
+ return new Skip(`this board looks names up and found none for one the check named (${error.message}): pass principals that are real on its team`);
85
+ }
86
+ const messageOf = (error) => error instanceof Error ? error.message : String(error);
87
+ /**
88
+ * Runs `check` with what it makes grants and tokens with, and revokes them all afterwards, the
89
+ * newest grant first, so one that closes a pattern goes while the one keeping this run in is there.
90
+ * A revoke that fails fails the check: what it made would stay on the board.
91
+ */
92
+ async function withGrants(ctx, check) {
93
+ const made = [];
94
+ const tokens = [];
95
+ const grants = {
96
+ async make(input, by) {
97
+ try {
98
+ const { grant } = await (by ?? ctx.board).createGrant(input);
99
+ made.push(grant.id);
100
+ return grant;
101
+ } catch (error) {
102
+ if (!by && made.length === 0 && error instanceof BoardError && error.status === 403) throw new Skip("this token can't change the board's grants");
103
+ throw unnamed(error) ?? error;
104
+ }
105
+ },
106
+ async deny(by, input, what) {
107
+ try {
108
+ const { grant } = await by.createGrant(input);
109
+ made.push(grant.id);
110
+ } catch (error) {
111
+ if (error instanceof BoardError && error.status === 403) return;
112
+ throw unnamed(error) ?? new Mismatch(`${what}: expected 403, got ${error instanceof BoardError ? `${error.status} ${error.code}` : messageOf(error)}`);
113
+ }
114
+ throw new Mismatch(`${what}: expected 403, and it made the grant`);
115
+ },
116
+ async mint(can) {
117
+ if (!ctx.withToken) throw new Skip("this run can't call the board with a token's secret");
118
+ try {
119
+ const { token, secret } = await ctx.board.createToken({
120
+ name: `conformance-${ctx.labels.conformance}-grants`,
121
+ can,
122
+ expires: "1h"
123
+ });
124
+ tokens.push(token.id);
125
+ return ctx.withToken(secret);
126
+ } catch (error) {
127
+ if (error instanceof BoardError && [
128
+ 403,
129
+ 404,
130
+ 501
131
+ ].includes(error.status)) throw new Skip(`this board mints no tokens to check with: ${error.message}`);
132
+ throw error;
133
+ }
134
+ },
135
+ async keep(pattern) {
136
+ const [source, kind, id, environment] = ctx.me.principal.split(":");
137
+ if (source === "board") return;
138
+ const self = ctx.me.kind === "person" ? {
139
+ kind: "user",
140
+ userId: ctx.me.principal.split(":").slice(2).join(":")
141
+ } : kind === "project" && id && environment ? {
142
+ kind: "project",
143
+ project: id,
144
+ environments: [environment]
145
+ } : kind === "app" && id ? {
146
+ kind: "app",
147
+ app: id
148
+ } : null;
149
+ if (!self) throw new Skip("closing a pattern to everyone would close it to this run too, which no grant could keep in: it's neither a person, a project, nor an app");
150
+ await grants.make({
151
+ principals: [self],
152
+ can: { [pattern]: "all" }
153
+ });
154
+ }
155
+ };
156
+ let result = void 0;
157
+ let failure = null;
75
158
  try {
76
- return await ctx.board.createGrant(input);
159
+ result = await check(grants);
77
160
  } catch (error) {
78
- if (error instanceof BoardError && error.status === 403) return { skip: "this token can't change the board's grants" };
79
- throw error;
161
+ if (error instanceof Skip) result = error.message;
162
+ else failure = error;
163
+ }
164
+ const left = [];
165
+ for (const id of made.reverse()) await ctx.board.revokeGrant(id).catch((error) => {
166
+ left.push(`${id} (${messageOf(error)})`);
167
+ });
168
+ for (const id of tokens) await ctx.board.revokeToken(id).catch((error) => {
169
+ left.push(`token ${id} (${messageOf(error)})`);
170
+ });
171
+ if (left.length > 0) throw new Mismatch(`${failure ? `${messageOf(failure)}; and it ` : ""}couldn't revoke what it made: ${left.join(", ")}`);
172
+ if (failure) throw failure;
173
+ return result;
174
+ }
175
+ /** What decides `channel` for `principal` (the caller, without one), or a skip where the board can't find it by name. */
176
+ async function explain(ctx, channel, principal) {
177
+ try {
178
+ return await ctx.board.explain(channel, principal);
179
+ } catch (error) {
180
+ throw unnamed(error) ?? error;
80
181
  }
81
182
  }
183
+ const sortedOf = (values) => [...values ?? []].sort();
184
+ /** That `actual` shows as `expected` does: a value compared as JSON, shown once when it isn't. */
185
+ function alike(actual, expected, what) {
186
+ if (show(actual) !== show(expected)) throw new Mismatch(`${what}: expected ${show(expected)}, got ${show(actual)}`);
187
+ }
82
188
  /** The sync key the sync checks register, a platform of their own, so nothing reaches a real one. */
83
189
  const SYNC_KEY = "conformance";
84
190
  /**
@@ -500,99 +606,323 @@ const CHECKS = [
500
606
  },
501
607
  {
502
608
  group: "grants",
503
- name: "grants a project, lists it, and revokes it",
504
- run: async (ctx) => {
505
- const first = await firstGrant(ctx);
506
- if ("skip" in first) return first.skip;
507
- const { grant } = first;
508
- try {
509
- isRef(grant.id, "a grant's id");
510
- same(show(grant.principals.map((principal) => principal.kind === "project" ? [
511
- principal.kind,
512
- principal.projectId,
513
- principal.environments
514
- ] : principal.kind)), show([[
515
- "project",
516
- projectFor(ctx).project,
517
- ["preview"]
518
- ]]), "the grant's principals");
519
- same(show(grant.can), show({ [ctx.channel]: ["post"] }), "the grant's can");
520
- same(grant.by, ctx.me.actor, "the grant's by");
521
- same((await ctx.board.grants()).filter((listed) => listed.id === grant.id).length, 1, "grants listing it");
522
- } catch (error) {
523
- await ctx.board.revokeGrant(grant.id).catch(() => {});
524
- throw error;
525
- }
609
+ name: "grants a principal, lists it, and revokes it",
610
+ run: (ctx) => withGrants(ctx, async ({ make }) => {
611
+ const grant = await make(grantFor(ctx));
612
+ isRef(grant.id, "a grant's id");
613
+ const [project] = grant.principals;
614
+ check(grant.principals.length === 1 && project?.kind === "project" && (project.projectId === ctx.principals.project || project.name === ctx.principals.project), `the grant's principals: expected the project ${ctx.principals.project}, got ${show(grant.principals)}`);
615
+ alike(project.environments, ["preview"], "the project's environments");
616
+ alike(grant.can, { [`${subtreeOf(ctx)}ci/`]: ["post"] }, "the grant's can");
617
+ same((await ctx.board.grants()).filter((listed) => listed.id === grant.id).length, 1, "grants listing it");
526
618
  same((await ctx.board.revokeGrant(grant.id)).revoked, true, "revoking it");
527
619
  same((await ctx.board.revokeGrant(grant.id)).revoked, false, "revoking it again");
528
620
  check(!(await ctx.board.grants()).some((listed) => listed.id === grant.id), "grants shouldn't list it once it's revoked");
529
- }
621
+ })
530
622
  },
531
623
  {
532
624
  group: "grants",
533
625
  name: "makes another grant for the same principals, and changes one by its ID",
534
- run: async (ctx) => {
535
- const first = await firstGrant(ctx);
536
- if ("skip" in first) return first.skip;
537
- const made = [first.grant.id];
538
- try {
539
- const again = await ctx.board.createGrant(grantFor(ctx));
540
- made.push(again.grant.id);
541
- check(again.grant.id !== first.grant.id, `the same principals again should be another grant, got ${again.grant.id} twice`);
542
- const repository = `acme/conformance-${ctx.labels.conformance}`;
543
- const added = await ctx.board.updateGrant(first.grant.id, {
544
- add: [{
545
- kind: "github",
546
- repository
547
- }],
548
- can: { [ctx.channel]: ["read", "post"] }
549
- });
550
- same(added.grant.id, first.grant.id, "the updated grant's id");
551
- same(show(added.grant.principals.map((principal) => principal.kind)), show(["project", "github"]), "principals after adding a repository");
552
- same(show(added.grant.can), show({ [ctx.channel]: ["read", "post"] }), "the updated grant's can");
553
- const removed = await ctx.board.updateGrant(first.grant.id, { remove: [{
554
- kind: "project",
555
- project: projectFor(ctx).project
556
- }] });
557
- same(show(removed.grant.principals.map((principal) => principal.kind)), show(["github"]), "principals after removing the project");
558
- await rejects(ctx.board.updateGrant(first.grant.id, { remove: [{
559
- kind: "project",
560
- project: projectFor(ctx).project
561
- }] }), 400, "not_in_grant", "removing a principal the grant no longer names");
562
- await rejects(ctx.board.updateGrant(first.grant.id, { remove: [{
626
+ run: (ctx) => withGrants(ctx, async ({ make }) => {
627
+ const first = await make(grantFor(ctx));
628
+ const again = await make(grantFor(ctx));
629
+ check(again.id !== first.id, `the same principals again should be another grant, got ${again.id} twice`);
630
+ const { repository } = ctx.principals;
631
+ const ci = `${subtreeOf(ctx)}ci/`;
632
+ const update = async (change) => {
633
+ try {
634
+ return await ctx.board.updateGrant(first.id, change);
635
+ } catch (error) {
636
+ throw unnamed(error) ?? error;
637
+ }
638
+ };
639
+ const added = await update({
640
+ add: [{
563
641
  kind: "github",
564
642
  repository
565
- }] }), 400, "grant_empty", "removing the last principal");
566
- await rejects(ctx.board.updateGrant(`${first.grant.id}0`, { can: { [ctx.channel]: ["read"] } }), 404, "grant_not_found", "updating a grant that was never made");
567
- } finally {
568
- for (const id of made) await ctx.board.revokeGrant(id).catch(() => {});
569
- }
570
- }
643
+ }, projectFor(ctx, ["production"])],
644
+ can: { [ci]: ["read", "post"] }
645
+ });
646
+ same(added.grant.id, first.id, "the updated grant's id");
647
+ alike(added.grant.principals.map((principal) => principal.kind), ["project", "github"], "principals after adding a repository, and the project again");
648
+ const project = added.grant.principals[0];
649
+ alike(sortedOf(project?.kind === "project" ? project.environments : void 0), sortedOf(["preview", "production"]), "the project's environments, after adding it again");
650
+ alike(added.grant.can, { [ci]: ["read", "post"] }, "the updated grant's can");
651
+ alike((await update({ remove: [{
652
+ kind: "project",
653
+ project: ctx.principals.project
654
+ }] })).grant.principals.map((principal) => principal.kind), ["github"], "principals after removing the project");
655
+ await rejects(update({ remove: [{
656
+ kind: "project",
657
+ project: ctx.principals.project
658
+ }] }), 400, "not_in_grant", "removing a principal the grant no longer names");
659
+ await rejects(update({ remove: [{
660
+ kind: "github",
661
+ repository
662
+ }] }), 400, "grant_empty", "removing the last principal");
663
+ await rejects(ctx.board.updateGrant(`${first.id}0`, { can: { [ci]: ["read"] } }), 404, "grant_not_found", "updating a grant that was never made");
664
+ })
571
665
  },
572
666
  {
573
667
  group: "grants",
574
668
  name: "keeps a grant's can as written, a pattern with no permissions included",
575
- run: async (ctx) => {
669
+ run: (ctx) => withGrants(ctx, async ({ make }) => {
670
+ const subtree = subtreeOf(ctx);
576
671
  const can = {
577
- "*": ["read"],
578
- [`${ctx.channel}/`]: []
672
+ [subtree]: ["read"],
673
+ [`${subtree}hidden/`]: []
579
674
  };
580
- const first = await firstGrant(ctx, {
675
+ const grant = await make({
581
676
  principals: [projectFor(ctx, ["production", "preview"])],
582
677
  can
583
678
  });
584
- if ("skip" in first) return first.skip;
585
- try {
586
- same(show(first.grant.can), show(can), "the grant's can");
587
- const listed = (await ctx.board.grants()).find((grant) => grant.id === first.grant.id);
588
- same(show(listed?.can), show(can), "the listed grant's can");
589
- const project = listed?.principals[0];
590
- same(show(project?.kind === "project" ? [...project.environments].sort() : null), show(["preview", "production"]), "the project's environments");
591
- } finally {
592
- await ctx.board.revokeGrant(first.grant.id).catch(() => {});
593
- }
679
+ alike(grant.can, can, "the grant's can");
680
+ const listed = (await ctx.board.grants()).find((found) => found.id === grant.id);
681
+ alike(listed?.can, can, "the listed grant's can");
682
+ const project = listed?.principals[0];
683
+ alike(sortedOf(project?.kind === "project" ? project.environments : void 0), sortedOf(["preview", "production"]), "the project's environments");
684
+ })
685
+ },
686
+ {
687
+ group: "grants",
688
+ name: "lets the most specific pattern decide, then the closest principal there, and adds up ties",
689
+ run: (ctx) => withGrants(ctx, async ({ make, keep }) => {
690
+ const subtree = subtreeOf(ctx);
691
+ const closed = `${subtree}closed/`;
692
+ const channel = `${closed}thread`;
693
+ const project = projectFor(ctx, ["production"]);
694
+ const who = {
695
+ project: ctx.principals.project,
696
+ environment: "production"
697
+ };
698
+ await keep(closed);
699
+ await make({
700
+ principals: [project],
701
+ can: { [subtree]: ["read", "post"] }
702
+ });
703
+ const lock = await make({
704
+ principals: [{ kind: "everyone" }],
705
+ can: { [closed]: [] }
706
+ });
707
+ const shut = await explain(ctx, channel, who);
708
+ same(shut.pattern, closed, `the pattern that decides ${channel}`);
709
+ check(shut.over.includes(subtree), `${closed} should win over ${subtree}, got ${show(shut.over)}`);
710
+ same(shut.level, "everyone", `the level that decides ${channel}`);
711
+ check(shut.grants.some((grant) => grant.id === lock.id), `everyone's grant should decide, got ${show(shut.grants.map((grant) => grant.id))}`);
712
+ alike(shut.can, [], `what the project may do in ${channel}`);
713
+ const reads = await make({
714
+ principals: [project],
715
+ can: { [closed]: ["read"] }
716
+ });
717
+ const posts = await make({
718
+ principals: [project],
719
+ can: { [closed]: ["post"] }
720
+ });
721
+ const open = await explain(ctx, channel, who);
722
+ same(open.level, "principal", `the level that decides ${channel} once grants name the project there`);
723
+ alike(sortedOf(open.grants.map((grant) => grant.id)), sortedOf([reads.id, posts.id]), "the grants that decide, which add up");
724
+ alike(open.can, ["read", "post"], "what they give together");
725
+ })
726
+ },
727
+ {
728
+ group: "grants",
729
+ name: "lets everyone narrow what something else lets in, and lets no one in itself",
730
+ run: (ctx) => withGrants(ctx, async ({ make, keep }) => {
731
+ const subtree = subtreeOf(ctx);
732
+ const inner = `${subtree}inner/`;
733
+ const channel = `${inner}thread`;
734
+ await keep(inner);
735
+ await make({
736
+ principals: [{ kind: "everyone" }],
737
+ can: { [inner]: ["read"] }
738
+ });
739
+ const outsider = await explain(ctx, channel, { github: ctx.principals.repository });
740
+ same(outsider.pattern, null, "the pattern that decides for a repository's runs nothing else lets in");
741
+ alike(outsider.can, [], "what everyone's grant gives them");
742
+ if (ctx.team === null) return "this board names no team, so no project is on it for all-projects";
743
+ const who = {
744
+ project: ctx.principals.project,
745
+ environment: "production"
746
+ };
747
+ const every = {
748
+ kind: "all-projects",
749
+ environments: ["production"]
750
+ };
751
+ await keep(subtree);
752
+ await make({
753
+ principals: [every],
754
+ can: { [subtree]: ["read", "post"] }
755
+ });
756
+ const narrowed = await explain(ctx, channel, who);
757
+ same(narrowed.level, "everyone", `the level that decides ${channel} for a project every project's grant lets in`);
758
+ alike(narrowed.can, ["read"], "what it may do there");
759
+ const group = await make({
760
+ principals: [every],
761
+ can: { [inner]: ["post"] }
762
+ });
763
+ const widened = await explain(ctx, channel, who);
764
+ same(widened.level, "group", `the level that decides ${channel} once every project's grant names it`);
765
+ alike(widened.grants.map((grant) => grant.id), [group.id], "the grant that decides");
766
+ alike(widened.can, ["post"], "what it gives, the closer level alone");
767
+ })
768
+ },
769
+ {
770
+ group: "grants",
771
+ name: "caps a person by their team role, so a viewer reads but neither posts nor manages",
772
+ run: (ctx) => {
773
+ const { viewer } = ctx.principals;
774
+ if (viewer === null) return Promise.resolve("name a viewer in principals to check it: a board without team roles caps no one");
775
+ return withGrants(ctx, async ({ make }) => {
776
+ const subtree = subtreeOf(ctx);
777
+ await make({
778
+ principals: [viewer.includes("@") ? {
779
+ kind: "user",
780
+ email: viewer
781
+ } : {
782
+ kind: "user",
783
+ userId: viewer
784
+ }],
785
+ can: { [subtree]: "all" }
786
+ });
787
+ const explained = await explain(ctx, `${subtree}thread`, { user: viewer });
788
+ same(explained.level, "principal", `the level that decides ${subtree}thread for the viewer`);
789
+ check(explained.capped !== null, `the viewer's role should cap what the grant gives, got capped ${show(explained.capped)}`);
790
+ check(explained.can.includes("read") && !explained.can.includes("post") && !explained.can.includes("manage"), `what a viewer may do with a grant of all: expected read, and neither post nor manage, got ${show(explained.can)}`);
791
+ });
792
+ }
793
+ },
794
+ {
795
+ group: "grants",
796
+ name: "names an app by its slug or client ID, keeps it by client ID, and every app as a group",
797
+ run: (ctx) => {
798
+ const { app } = ctx.principals;
799
+ if (app === null) return Promise.resolve("name an app in principals to check it: a local board has no apps");
800
+ return withGrants(ctx, async ({ make, keep }) => {
801
+ const apps = `${subtreeOf(ctx)}apps/`;
802
+ if (ctx.me.principal.startsWith("vercel:app:")) await keep(apps);
803
+ const grant = await make({
804
+ principals: [{
805
+ kind: "app",
806
+ app
807
+ }],
808
+ can: { [apps]: ["post"] }
809
+ });
810
+ const [named] = grant.principals;
811
+ check(grant.principals.length === 1 && named?.kind === "app" && (named.clientId === app || named.name === app), `the grant's principals: expected the app ${app}, got ${show(grant.principals)}`);
812
+ alike((await ctx.board.updateGrant(grant.id, {
813
+ add: [{ kind: "all-apps" }],
814
+ remove: [{
815
+ kind: "app",
816
+ app
817
+ }]
818
+ })).grant.principals, [{ kind: "all-apps" }], "principals after adding every app and removing the one");
819
+ });
594
820
  }
595
821
  },
822
+ {
823
+ group: "grants",
824
+ name: "takes manage at each pattern a grant names to change it, and at * to list them",
825
+ run: (ctx) => withGrants(ctx, async ({ make, deny, mint }) => {
826
+ const subtree = subtreeOf(ctx);
827
+ const inner = `${subtree}inner/`;
828
+ const poster = await mint({ "*": ["read", "post"] });
829
+ const probe = await make(grantFor(ctx));
830
+ await deny(poster, grantFor(ctx), "a grant made without manage");
831
+ await refused(poster.updateGrant(probe.id, { can: { [`${subtree}ci/`]: ["read"] } }), 403, "an update without manage");
832
+ await refused(poster.revokeGrant(probe.id), 403, "a revoke without manage");
833
+ await refused(poster.grants(), 403, "listing grants without manage at *");
834
+ await refused(poster.explain(`${subtree}thread`, { project: ctx.principals.project }), 403, "explaining a principal's access without manage at *");
835
+ alike((await poster.explain(`${subtree}thread`)).grants, [], "which grants decide, for a caller that may not list them");
836
+ const manager = await mint({
837
+ "*": [
838
+ "read",
839
+ "post",
840
+ "react",
841
+ "label",
842
+ "sync"
843
+ ],
844
+ [inner]: "all"
845
+ });
846
+ const grant = await make({
847
+ principals: [projectFor(ctx)],
848
+ can: { [inner]: ["read"] }
849
+ }, manager);
850
+ await deny(manager, {
851
+ principals: [projectFor(ctx)],
852
+ can: { [subtree]: ["read"] }
853
+ }, `a grant on ${subtree} made with manage only at ${inner}`);
854
+ await refused(manager.updateGrant(grant.id, { can: { [subtree]: ["read"] } }), 403, `moving a grant to ${subtree} with manage only at ${inner}`);
855
+ await refused(manager.grants(), 403, `listing grants with manage only at ${inner}`);
856
+ same((await manager.revokeGrant(grant.id)).revoked, true, `revoking a grant on ${inner} with manage there`);
857
+ })
858
+ },
859
+ {
860
+ group: "grants",
861
+ name: "lets no token grant past its own can, even where everyone's grant closes it",
862
+ run: (ctx) => withGrants(ctx, async ({ make, deny, mint, keep }) => {
863
+ const subtree = subtreeOf(ctx);
864
+ const secret = `${subtree}secret/`;
865
+ const run = {
866
+ kind: "github",
867
+ repository: ctx.principals.repository
868
+ };
869
+ const narrowed = await mint({
870
+ "*": "all",
871
+ [secret]: []
872
+ });
873
+ await deny(narrowed, {
874
+ principals: [run],
875
+ can: { [subtree]: ["read"] }
876
+ }, `a grant on ${subtree} from a token kept out of ${secret}`);
877
+ await keep(secret);
878
+ await make({
879
+ principals: [{ kind: "everyone" }],
880
+ can: { [secret]: [] }
881
+ });
882
+ await deny(narrowed, {
883
+ principals: [run],
884
+ can: { [subtree]: ["read"] }
885
+ }, `a grant on ${subtree} from a token kept out of ${secret}, once everyone is too`);
886
+ await make({
887
+ principals: [run],
888
+ can: { [`${subtree}ci/`]: ["post"] }
889
+ }, narrowed);
890
+ })
891
+ },
892
+ {
893
+ group: "grants",
894
+ name: "lets no token let anyone in where everyone gets more than the token has",
895
+ run: (ctx) => withGrants(ctx, async ({ make, deny, mint, keep }) => {
896
+ const subtree = subtreeOf(ctx);
897
+ const open = `${subtree}open/`;
898
+ const narrowed = await mint({
899
+ "*": "all",
900
+ [open]: []
901
+ });
902
+ await keep(open);
903
+ await make({
904
+ principals: [{ kind: "everyone" }],
905
+ can: { [open]: ["read"] }
906
+ });
907
+ await deny(narrowed, {
908
+ principals: [{
909
+ kind: "github",
910
+ repository: ctx.principals.repository
911
+ }],
912
+ can: { [`${subtree}ci/`]: ["post"] }
913
+ }, `a grant from a token kept out of ${open}, which everyone reads`);
914
+ })
915
+ },
916
+ {
917
+ group: "grants",
918
+ name: "lets a member grant on a pattern after a lock under it",
919
+ run: async () => "a run can't be shut out by a lock and lift it afterwards: the board's own tests check it"
920
+ },
921
+ {
922
+ group: "grants",
923
+ name: "lets a project on another team in, in its environments",
924
+ run: async () => "grants across teams aren't specified yet: what a project on another team needs, and what all-projects means for one, comes later"
925
+ },
596
926
  {
597
927
  group: "tokens",
598
928
  name: "mints a token, shows its secret only then, lists it, and revokes it",
@@ -950,7 +1280,52 @@ const CHECKS = [
950
1280
  }
951
1281
  }
952
1282
  ];
953
- /** Runs the checks against `board`, in order, and reports each. It never throws for what the board answers. */
1283
+ /**
1284
+ * Why `principals` can't be the ones the grants checks name: one that is this run's own (its
1285
+ * project, or its repository from a GitHub run) would have the checks change what the run itself
1286
+ * may do, part way through. Null when they're another's.
1287
+ */
1288
+ function namesCaller(me, principals) {
1289
+ const [source, kind, id] = me.principal.split(":");
1290
+ const project = principals?.project;
1291
+ if (project !== void 0 && source === "vercel" && kind === "project" && (project === id || project === me.handle)) return `principals.project is this run's own project, ${project}: the grants checks would change what this run may do. Name another project on the team.`;
1292
+ const repository = principals?.repository?.toLowerCase();
1293
+ if (repository !== void 0 && me.kind === "workflow" && repository === me.handle.toLowerCase()) return `principals.repository is this run's own repository, ${principals.repository}: the grants checks would change what this run may do. Name another repository.`;
1294
+ const app = principals?.app;
1295
+ if (app !== void 0 && source === "vercel" && kind === "app" && (app === id || app === me.handle)) return `principals.app is this run's own app, ${app}: the grants checks would change what this run may do. Name another app on the team.`;
1296
+ return null;
1297
+ }
1298
+ /**
1299
+ * Why `project`, a name the board looks up, can't be the one the grants checks name: it's this run's
1300
+ * own. A name can't be told apart before the board resolves it, so this makes one grant that
1301
+ * changes nothing for the run (the project's deployments in another environment, posting in the
1302
+ * subtree's `ci/`), reads the project it resolved to, and revokes it. Null when it's another's, or
1303
+ * when the board made no such grant, which the grants checks then say why.
1304
+ */
1305
+ async function ownProjectByName(board, me, channel, project) {
1306
+ const [source, kind, id, environment] = me.principal.split(":");
1307
+ if (project === void 0 || source !== "vercel" || kind !== "project" || project === id) return null;
1308
+ let grant;
1309
+ try {
1310
+ ({grant} = await board.createGrant({
1311
+ principals: [{
1312
+ kind: "project",
1313
+ project,
1314
+ environments: [environment === "preview" ? "development" : "preview"]
1315
+ }],
1316
+ can: { [`${channel}/grants/ci/`]: ["post"] }
1317
+ }));
1318
+ } catch {
1319
+ return null;
1320
+ }
1321
+ await board.revokeGrant(grant.id);
1322
+ const [named] = grant.principals;
1323
+ return named?.kind === "project" && named.projectId === id ? `principals.project is this run's own project, ${project} (${id}): the grants checks would change what this run may do. Name another project on the team.` : null;
1324
+ }
1325
+ /**
1326
+ * Runs the checks against `board`, in order, and reports each. It never throws for what the board
1327
+ * answers; it throws before it writes anything when `principals` names the run itself.
1328
+ */
954
1329
  async function conformance(board, options = {}) {
955
1330
  const checks = [];
956
1331
  const discovery = await board.discovery().catch((error) => error);
@@ -975,18 +1350,30 @@ async function conformance(board, options = {}) {
975
1350
  status: "passed"
976
1351
  });
977
1352
  const me = await board.me();
1353
+ const own = namesCaller(me, options.principals);
1354
+ if (own !== null) throw new TypeError(own);
978
1355
  const channel = options.channel ?? "conformance";
1356
+ const ownByName = await ownProjectByName(board, me, channel, options.principals?.project);
1357
+ if (ownByName !== null) throw new TypeError(ownByName);
1358
+ const label = crypto.randomUUID().slice(0, 8);
979
1359
  const ctx = {
980
1360
  board,
981
1361
  channel,
982
- labels: { conformance: crypto.randomUUID().slice(0, 8) },
1362
+ labels: { conformance: label },
983
1363
  start: (await board.messages({
984
1364
  channel,
985
1365
  limit: 1
986
1366
  })).cursor,
987
1367
  me,
988
1368
  posted: [],
989
- ...options.withToken ? { withToken: options.withToken } : {}
1369
+ ...options.withToken ? { withToken: options.withToken } : {},
1370
+ principals: {
1371
+ project: options.principals?.project ?? `prj_conformance${label}`,
1372
+ repository: options.principals?.repository ?? `acme/conformance-${label}`,
1373
+ viewer: options.principals?.viewer ?? null,
1374
+ app: options.principals?.app ?? null
1375
+ },
1376
+ team: discovery.team_id ?? null
990
1377
  };
991
1378
  try {
992
1379
  for (const { group, name, run } of CHECKS) try {
@@ -1008,6 +1395,12 @@ async function conformance(board, options = {}) {
1008
1395
  status: "skipped",
1009
1396
  detail: `not kept here: ${error.message}`
1010
1397
  });
1398
+ else if (group === "watchers" && error instanceof BoardError && error.code === "board_token_unsupported") checks.push({
1399
+ group,
1400
+ name,
1401
+ status: "skipped",
1402
+ detail: "a board token can't register watchers yet"
1403
+ });
1011
1404
  else checks.push({
1012
1405
  group,
1013
1406
  name,