@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,5 +1,5 @@
1
- import { u as BoardError } from "./errors-Pk0XV1hK.mjs";
2
- import { i as compileAccess } from "./access-N3XmkKXg.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,22 +59,131 @@ const needRoot = (ctx) => {
59
59
  reply: ctx.reply
60
60
  };
61
61
  };
62
- /** A grant for a project that doesn't exist, from an environment its deployments would have: it lets nobody in. */
62
+ /** A check's project, in its environments. */
63
+ const projectFor = (ctx, environments = ["preview"]) => ({
64
+ kind: "project",
65
+ project: ctx.principals.project,
66
+ environments
67
+ });
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/`. */
63
75
  const grantFor = (ctx) => ({
64
- issuer: "vercel",
65
- claims: {
66
- environment: "preview",
67
- project_id: `prj_conformance${ctx.labels.conformance}`
68
- }
76
+ principals: [projectFor(ctx)],
77
+ can: { [`${subtreeOf(ctx)}ci/`]: ["post"] }
69
78
  });
70
- /** Sets the check's grant, or says why it can't: changing who the board trusts takes `manage` in every channel. */
71
- async function firstGrant(ctx) {
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;
72
158
  try {
73
- return await ctx.board.createGrant(grantFor(ctx));
159
+ result = await check(grants);
74
160
  } catch (error) {
75
- if (error instanceof BoardError && error.status === 403) return { skip: "this token can't change the board's grants" };
76
- throw error;
161
+ if (error instanceof Skip) result = error.message;
162
+ else failure = error;
77
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;
181
+ }
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)}`);
78
187
  }
79
188
  /** The sync key the sync checks register, a platform of their own, so nothing reaches a real one. */
80
189
  const SYNC_KEY = "conformance";
@@ -497,109 +606,323 @@ const CHECKS = [
497
606
  },
498
607
  {
499
608
  group: "grants",
500
- name: "grants a project, lists it, takes the same grant again as one, and revokes it",
501
- run: async (ctx) => {
502
- const asked = grantFor(ctx);
503
- const first = await firstGrant(ctx);
504
- if ("skip" in first) return first.skip;
505
- try {
506
- isRef(first.grant.id, "a grant's id");
507
- same(first.created, true, "a new grant: created");
508
- same(first.grant.issuer, "vercel", "the grant's issuer");
509
- same(first.grant.claims.project_id, asked.claims.project_id, "the grant's project_id");
510
- check(first.grant.can["*"]?.includes("post"), `a grant with no can should let them post everywhere, got ${show(first.grant.can)}`);
511
- same(first.grant.by, ctx.me.actor, "the grant's by");
512
- const again = await ctx.board.createGrant(asked);
513
- same(again.created, false, "the same issuer and claims again: created");
514
- same(again.grant.id, first.grant.id, "the same issuer and claims again: its id");
515
- same((await ctx.board.grants()).filter((grant) => grant.id === first.grant.id).length, 1, "grants listing it");
516
- } catch (error) {
517
- await ctx.board.revokeGrant(first.grant.id).catch(() => {});
518
- throw error;
519
- }
520
- same((await ctx.board.revokeGrant(first.grant.id)).revoked, true, "revoking it");
521
- same((await ctx.board.revokeGrant(first.grant.id)).revoked, false, "revoking it again");
522
- check(!(await ctx.board.grants()).some((grant) => grant.id === first.grant.id), "grants shouldn't list it once it's revoked");
523
- }
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");
618
+ same((await ctx.board.revokeGrant(grant.id)).revoked, true, "revoking it");
619
+ same((await ctx.board.revokeGrant(grant.id)).revoked, false, "revoking it again");
620
+ check(!(await ctx.board.grants()).some((listed) => listed.id === grant.id), "grants shouldn't list it once it's revoked");
621
+ })
524
622
  },
525
623
  {
526
624
  group: "grants",
527
- name: "changes a grant's can when it's set again",
528
- run: async (ctx) => {
529
- const first = await firstGrant(ctx);
530
- if ("skip" in first) return first.skip;
531
- const { grant } = first;
532
- try {
533
- const narrowed = await ctx.board.createGrant({
534
- ...grantFor(ctx),
535
- can: { [ctx.channel]: ["post"] }
536
- });
537
- same(narrowed.created, false, "setting its can: created");
538
- same(narrowed.grant.id, grant.id, "setting its can: its id");
539
- same(show(narrowed.grant.can), show({ [ctx.channel]: ["post"] }), "the grant's can");
540
- } finally {
541
- await ctx.board.revokeGrant(grant.id).catch(() => {});
542
- }
543
- }
625
+ name: "makes another grant for the same principals, and changes one by its ID",
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: [{
641
+ kind: "github",
642
+ repository
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
+ })
544
665
  },
545
666
  {
546
667
  group: "grants",
547
- name: "grants a GitHub repository's workflows, and another team's project",
548
- run: async (ctx) => {
549
- const first = await firstGrant(ctx);
550
- if ("skip" in first) return first.skip;
551
- const made = [first.grant.id];
552
- try {
553
- const github = await ctx.board.createGrant({
554
- issuer: "github",
555
- claims: { repository: `acme/conformance-${ctx.labels.conformance}` },
556
- can: { [ctx.channel]: ["post"] }
557
- });
558
- made.push(github.grant.id);
559
- same(github.grant.issuer, "github", "the GitHub grant's issuer");
560
- const theirs = await ctx.board.createGrant({
561
- issuer: "vercel",
562
- claims: {
563
- environment: "production",
564
- owner_id: `team_conformance${ctx.labels.conformance}`,
565
- project_id: `prj_conformance${ctx.labels.conformance}x`
566
- }
668
+ name: "keeps a grant's can as written, a pattern with no permissions included",
669
+ run: (ctx) => withGrants(ctx, async ({ make }) => {
670
+ const subtree = subtreeOf(ctx);
671
+ const can = {
672
+ [subtree]: ["read"],
673
+ [`${subtree}hidden/`]: []
674
+ };
675
+ const grant = await make({
676
+ principals: [projectFor(ctx, ["production", "preview"])],
677
+ can
678
+ });
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" }
567
786
  });
568
- made.push(theirs.grant.id);
569
- same(theirs.grant.claims.owner_id, `team_conformance${ctx.labels.conformance}`, "another team's grant's owner_id");
570
- const listed = new Set((await ctx.board.grants()).map((grant) => grant.id));
571
- check(made.every((id) => listed.has(id)), `grants should list ${made.join(", ")}`);
572
- } finally {
573
- for (const id of made) await ctx.board.revokeGrant(id).catch(() => {});
574
- }
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
+ });
575
792
  }
576
793
  },
577
794
  {
578
795
  group: "grants",
579
- name: "keeps two environments of one project as two grants, and revokes one without the other",
580
- run: async (ctx) => {
581
- const first = await firstGrant(ctx);
582
- if ("skip" in first) return first.skip;
583
- const made = [first.grant.id];
584
- try {
585
- const production = await ctx.board.createGrant({
586
- ...grantFor(ctx),
587
- claims: {
588
- ...grantFor(ctx).claims,
589
- environment: "production"
590
- }
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"] }
591
809
  });
592
- made.push(production.grant.id);
593
- same(production.created, true, "another environment: created");
594
- check(production.grant.id !== first.grant.id, "another environment should be another grant");
595
- same((await ctx.board.revokeGrant(first.grant.id)).revoked, true, "revoking the preview grant");
596
- const listed = (await ctx.board.grants()).map((grant) => grant.id);
597
- check(listed.includes(production.grant.id) && !listed.includes(first.grant.id), `grants should list ${production.grant.id} and not ${first.grant.id}, got ${show(listed)}`);
598
- } finally {
599
- for (const id of made) await ctx.board.revokeGrant(id).catch(() => {});
600
- }
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
+ });
601
820
  }
602
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
+ },
603
926
  {
604
927
  group: "tokens",
605
928
  name: "mints a token, shows its secret only then, lists it, and revokes it",
@@ -957,7 +1280,52 @@ const CHECKS = [
957
1280
  }
958
1281
  }
959
1282
  ];
960
- /** 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
+ */
961
1329
  async function conformance(board, options = {}) {
962
1330
  const checks = [];
963
1331
  const discovery = await board.discovery().catch((error) => error);
@@ -982,18 +1350,30 @@ async function conformance(board, options = {}) {
982
1350
  status: "passed"
983
1351
  });
984
1352
  const me = await board.me();
1353
+ const own = namesCaller(me, options.principals);
1354
+ if (own !== null) throw new TypeError(own);
985
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);
986
1359
  const ctx = {
987
1360
  board,
988
1361
  channel,
989
- labels: { conformance: crypto.randomUUID().slice(0, 8) },
1362
+ labels: { conformance: label },
990
1363
  start: (await board.messages({
991
1364
  channel,
992
1365
  limit: 1
993
1366
  })).cursor,
994
1367
  me,
995
1368
  posted: [],
996
- ...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
997
1377
  };
998
1378
  try {
999
1379
  for (const { group, name, run } of CHECKS) try {
@@ -1015,6 +1395,12 @@ async function conformance(board, options = {}) {
1015
1395
  status: "skipped",
1016
1396
  detail: `not kept here: ${error.message}`
1017
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
+ });
1018
1404
  else checks.push({
1019
1405
  group,
1020
1406
  name,