@vercel/board 0.34.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.
- package/dist/{access-CdBcYPQH.mjs → access-BsP0hvcC.mjs} +1 -1
- package/dist/access.d.mts +2 -2
- package/dist/access.mjs +4 -4
- package/dist/{actors-MrIEr9LI.mjs → actors-DFOpTw89.mjs} +2 -2
- package/dist/{auth-aaoKt5DK.d.mts → auth-C21V0EK1.d.mts} +1 -1
- package/dist/{auth-DjoJygbG.mjs → auth-CrjXLgOb.mjs} +2 -2
- package/dist/{backend-u1sVvybh.d.mts → backend-D21q8mdm.d.mts} +3 -3
- package/dist/backend-local.d.mts +1 -1
- package/dist/backend-local.mjs +1 -1
- package/dist/{chat-provider-De0iDnUB.d.mts → chat-provider-DmZCmBkb.d.mts} +2 -2
- package/dist/cli-commands.d.mts +1 -1
- package/dist/cli-commands.mjs +1 -1
- package/dist/cli-embedded.d.mts +2 -2
- package/dist/cli-embedded.mjs +1 -1
- package/dist/cli.mjs +5 -5
- package/dist/{commands-BkVMdXP1.d.mts → commands-BorACIFS.d.mts} +173 -0
- package/dist/{commands-B8oZEByR.mjs → commands-CENWob9m.mjs} +322 -26
- package/dist/{conformance-gqYBkXFS.mjs → conformance-CKrwglzA.mjs} +480 -87
- package/dist/conformance.d.mts +20 -2
- package/dist/conformance.mjs +1 -1
- package/dist/{engine-rtOVWsiF.mjs → engine-wN7quvbU.mjs} +2 -2
- package/dist/{errors-D8ifv16L.mjs → errors-rYDxZEuN.mjs} +98 -4
- package/dist/exports-BxljH73E.d.mts +4 -0
- package/dist/{exports-Bx2dGpzr.mjs → exports-GIRJm2Ja.mjs} +87 -22
- package/dist/{index-D6mK0Ial.d.mts → index-LREsSZb2.d.mts} +2 -2
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +4 -4
- package/dist/index.node.d.mts +6 -6
- package/dist/index.node.mjs +3 -3
- package/dist/inspect/app.js +32 -32
- package/dist/{local-CPz22MQ8.mjs → local-yKwdgukb.mjs} +6 -6
- package/dist/{main-DScDKwQN.mjs → main-DjokcEAL.mjs} +406 -23
- package/dist/{middleware-BjYpk4yq.mjs → middleware-BxgizazV.mjs} +1 -1
- package/dist/{provider-hB8QNrwm.d.mts → provider-DEOfc4Ls.d.mts} +21 -3
- package/dist/{routes-De4W6lEs.d.mts → routes-BpKdMvgX.d.mts} +19 -8
- package/dist/{serve-B1noQRkn.mjs → serve-CJ8hauK2.mjs} +4 -4
- package/dist/{server-Ov6GBJ8j.mjs → server-CtaTtyhw.mjs} +6 -6
- package/dist/{serving-2s7lqSBS.mjs → serving-6_bhBNAW.mjs} +1 -1
- package/dist/sync-chat-sdk.d.mts +2 -2
- package/dist/sync-github.d.mts +2 -2
- package/dist/sync-linear.d.mts +3 -3
- package/dist/sync-slack.d.mts +3 -3
- package/dist/sync.d.mts +2 -2
- package/dist/{targets-aMdbp84G.mjs → targets-n2i2ZOWI.mjs} +9 -5
- package/dist/{tokens-LHLrnV_P.mjs → tokens-Dn4cPZIr.mjs} +2 -2
- package/docs/01-board/01-mounting.md +7 -2
- package/docs/01-board/09-access.md +31 -0
- package/docs/03-guides/03-ci.md +4 -2
- package/docs/04-reference/01-cli.md +98 -14
- package/docs/04-reference/02-board.md +23 -3
- package/docs/04-reference/03-http.md +1 -1
- package/docs/04-reference/05-conformance.md +31 -5
- package/package.json +1 -1
- package/dist/exports-uwRl5qIj.d.mts +0 -4
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { a as forbidden$1, c as toErrorResponse, f as duration, g as fileName, h as IMPORT_BYTES_MAX, i as duplicateId, l as unauthorized, m as DIRECT_UPLOAD_BYTES_MAX, p as ATTACHMENT_BYTES_MAX, r as badRequest, s as notFound, t as HttpError, u as BoardError, v as mediaType } from "./errors-
|
|
1
|
+
import { a as forbidden$1, c as toErrorResponse, f as duration, g as fileName, h as IMPORT_BYTES_MAX, i as duplicateId, l as unauthorized, m as DIRECT_UPLOAD_BYTES_MAX, p as ATTACHMENT_BYTES_MAX, r as badRequest, s as notFound, t as HttpError, u as BoardError, v as mediaType } from "./errors-rYDxZEuN.mjs";
|
|
2
2
|
import { _ as actorKind, a as ChannelPath, c as LabelKey, f as MessageId, g as SeenActorKind, h as SCOPE_MAX, i as Author, m as RemoteWatcherId, n as Attachment, o as Emoji, p as MessageText, s as Handle, t as ActorId, u as Labels, v as platformAvatar, y as storable } from "./schemas-BG205xds.mjs";
|
|
3
3
|
import { a as Link, i as ExternalTarget, n as ExternalEvent, o as Origin } from "./external-CYe424fO.mjs";
|
|
4
|
-
import { a as compileWatcher, c as METHODS, h as VERSION, i as canonicalWatchers, m as SYNC, n as syncTarget, o as hasCriteria, r as withEmailMentions } from "./targets-
|
|
5
|
-
import { i as waitUntil, n as MIDDLEWARE_ACTOR, o as derivedId, s as isKeyIdOf, t as DroppedError } from "./middleware-
|
|
6
|
-
import { a as checkGrantChange, d as scopeOf, i as authorize, s as compileAccess, t as FULL_ACCESS, u as parseScope } from "./access-
|
|
7
|
-
import { C as workflowPath, c as checkGrant, f as grantIssuers, h as joined, l as checkPrincipal, m as issuerName, n as DEFAULT_CAN, o as authenticates, r as GITHUB_ISSUER, s as checkCan, t as BOARD_TOKEN_PREFIX, v as removes, w as wroteAs, y as tokenHash } from "./auth-
|
|
4
|
+
import { a as compileWatcher, c as METHODS, h as VERSION, i as canonicalWatchers, m as SYNC, n as syncTarget, o as hasCriteria, r as withEmailMentions } from "./targets-n2i2ZOWI.mjs";
|
|
5
|
+
import { i as waitUntil, n as MIDDLEWARE_ACTOR, o as derivedId, s as isKeyIdOf, t as DroppedError } from "./middleware-BxgizazV.mjs";
|
|
6
|
+
import { a as checkGrantChange, d as scopeOf, i as authorize, s as compileAccess, t as FULL_ACCESS, u as parseScope } from "./access-BsP0hvcC.mjs";
|
|
7
|
+
import { C as workflowPath, c as checkGrant, f as grantIssuers, h as joined, l as checkPrincipal, m as issuerName, n as DEFAULT_CAN, o as authenticates, r as GITHUB_ISSUER, s as checkCan, t as BOARD_TOKEN_PREFIX, v as removes, w as wroteAs, y as tokenHash } from "./auth-CrjXLgOb.mjs";
|
|
8
8
|
import { n as setOwn, t as own } from "./own-OwgPWdmh.mjs";
|
|
9
9
|
import { n as replaceMentions } from "./mentions-CB6ShY4R.mjs";
|
|
10
|
-
import { a as resolveMentions, n as actorSeen } from "./actors-
|
|
10
|
+
import { a as resolveMentions, n as actorSeen } from "./actors-DFOpTw89.mjs";
|
|
11
11
|
import { C as sessionClearedError, a as SOCKET_TIMINGS, c as drainSettledHooks, d as nullProtoRecord, f as runtimeConsumerFactory, g as A2Error, h as stateTailReaders, i as RESERVED_PARTICIPANT_IDS, l as failedPreviousAttempt, m as serverInternals, n as POLL_TIMINGS, o as STATE_CACHE, p as runtimeConsumers, r as PRESENCE_TIMINGS, s as STREAM_TIMINGS, t as DRAIN_TIMINGS, u as markSchedulerSendFailure, v as NonRetriableError, x as isSessionCleared, y as asStoreUnavailable } from "./internal-CvsrprnU-CEPOUpAv.mjs";
|
|
12
12
|
import { i as streamActivities, n as defaultSleep, t as createStreamActivity } from "./store-polling-BZt2Rf3D-oh3aU_An.mjs";
|
|
13
13
|
import { a as foldActors, i as concernedMessageId, o as foldMessages, s as iso, t as TABLES_CONSUMER } from "./sql-BQzKUqQt.mjs";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { _ as fileSize, m as DIRECT_UPLOAD_BYTES_MAX, u as BoardError } from "./errors-
|
|
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-
|
|
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 { u as parseScope } from "./access-
|
|
6
|
-
import { i as isApiMessageId, n as isBoardName } from "./exports-
|
|
7
|
-
import { i as groups, n as filters$1, o as options, r as globalOptions, s as usage$1, t as commands } from "./commands-
|
|
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-
|
|
9
|
-
import { t as conformance } from "./conformance-
|
|
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,7 +414,8 @@ 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
|
-
|
|
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) => {
|
|
@@ -204,14 +456,17 @@ function grantCan(can, capped) {
|
|
|
204
456
|
}
|
|
205
457
|
return patterns.map((pattern) => `${pattern}=${words(can[pattern])}`).join(" ");
|
|
206
458
|
}
|
|
459
|
+
const grantCells = (grant) => [
|
|
460
|
+
grant.id,
|
|
461
|
+
grant.principals.map(principalFlags).join(" "),
|
|
462
|
+
grantCan(grant.can, grant.capped)
|
|
463
|
+
];
|
|
207
464
|
/** Each grant on a row: its ID, who it names (as the flags that would), and what it lets them do. */
|
|
208
465
|
function formatGrants(grants) {
|
|
209
|
-
return table(grants.map(
|
|
210
|
-
grant.id,
|
|
211
|
-
grant.principals.map(principalFlags).join(" "),
|
|
212
|
-
grantCan(grant.can, grant.capped)
|
|
213
|
-
]));
|
|
466
|
+
return table(grants.map(grantCells));
|
|
214
467
|
}
|
|
468
|
+
/** One grant as its row: `g3 --everyone security/=none`. */
|
|
469
|
+
const grantRow = (grant) => grantCells(grant).join(" ");
|
|
215
470
|
/** Each token on a row: its ID, its name, what it may do, and when it expires. */
|
|
216
471
|
function formatTokens(tokens, now = Date.now()) {
|
|
217
472
|
return table(tokens.map((token) => [
|
|
@@ -800,6 +1055,8 @@ let app = {
|
|
|
800
1055
|
};
|
|
801
1056
|
let flags = {};
|
|
802
1057
|
let positionals = [];
|
|
1058
|
+
/** Every option as it was typed, in order: what reads principal flags and the modifiers after each. */
|
|
1059
|
+
let ordered = [];
|
|
803
1060
|
/** The command this run runs, by its own name, and what follows it: what a failure says it was doing. */
|
|
804
1061
|
let current = {
|
|
805
1062
|
command: void 0,
|
|
@@ -841,6 +1098,15 @@ function parse(argv) {
|
|
|
841
1098
|
if (removed) throw removed;
|
|
842
1099
|
try {
|
|
843
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
|
+
}] : []);
|
|
844
1110
|
flags = parsed.values;
|
|
845
1111
|
positionals = parsed.positionals.map((arg) => arg.startsWith(MARK) ? arg.slice(1) : arg);
|
|
846
1112
|
} catch (error) {
|
|
@@ -1024,12 +1290,42 @@ function trustId(what, value) {
|
|
|
1024
1290
|
if (!/^[^\s/]+$/.test(value)) throw usage(`${value} isn't a ${what} ID like ${like}.`);
|
|
1025
1291
|
return value;
|
|
1026
1292
|
}
|
|
1027
|
-
/**
|
|
1028
|
-
|
|
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(";");
|
|
1306
|
+
try {
|
|
1307
|
+
return parseScope(scope);
|
|
1308
|
+
} catch (error) {
|
|
1309
|
+
throw usage(`${error.message.replace(/x-board-scope/g, "--can").replace(/, or all$/, ", all, or none")}.`);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
/** What a grant's flags say, or the misuse in them. */
|
|
1313
|
+
function grantFlags(read) {
|
|
1029
1314
|
try {
|
|
1030
|
-
return
|
|
1315
|
+
return read();
|
|
1031
1316
|
} catch (error) {
|
|
1032
|
-
throw usage(
|
|
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}.`);
|
|
1033
1329
|
}
|
|
1034
1330
|
}
|
|
1035
1331
|
/** A time flag: anything `Date` reads, as ISO. */
|
|
@@ -1103,7 +1399,7 @@ function doing() {
|
|
|
1103
1399
|
case "channels": return a === "create" ? `create ${b ?? "the channel"}` : "list channels";
|
|
1104
1400
|
case "schedules":
|
|
1105
1401
|
case "actors": return `list ${command}`;
|
|
1106
|
-
case "grants": return a === "create" ? `grant ${b ?? "
|
|
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";
|
|
1107
1403
|
case "tokens": return a === "create" ? `mint token ${b ?? ""}`.trimEnd() : a === "revoke" ? `revoke token ${b}` : "list tokens";
|
|
1108
1404
|
case "sources": return b === void 0 ? "list sources" : `${b} ${c ?? "it"} on ${a}`;
|
|
1109
1405
|
case "download": return `download ${a ?? "the attachment"}`;
|
|
@@ -1138,7 +1434,7 @@ function missing() {
|
|
|
1138
1434
|
"schedule"
|
|
1139
1435
|
].includes(command) && isMessageRef(a)) return `message ${ref(a)}`;
|
|
1140
1436
|
if (command === "schedule" && a === "cancel" && b !== void 0) return `schedule ${b}`;
|
|
1141
|
-
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}`;
|
|
1142
1438
|
if (command === "download") return `attachment ${a}`;
|
|
1143
1439
|
}
|
|
1144
1440
|
/**
|
|
@@ -1194,6 +1490,8 @@ function failureOf(error) {
|
|
|
1194
1490
|
}]);
|
|
1195
1491
|
case "board_name_taken": return own("conflict", "board_name_taken");
|
|
1196
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");
|
|
1197
1495
|
case "invalid_board_name": return own("usage", "invalid_arguments", [helpRecovery()]);
|
|
1198
1496
|
case "too_many_redirects": return own("network", "network_error");
|
|
1199
1497
|
case "invalid_duration": return own("usage", "invalid_arguments", [helpRecovery()]);
|
|
@@ -1220,6 +1518,9 @@ function failureOf(error) {
|
|
|
1220
1518
|
message: `Failed to ${doing()}.`,
|
|
1221
1519
|
details: [message]
|
|
1222
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");
|
|
1223
1524
|
case "port_taken": return own("conflict", "port_taken", [{
|
|
1224
1525
|
instruction: "Pick another port",
|
|
1225
1526
|
argv: [
|
|
@@ -1555,7 +1856,8 @@ async function run(command, args) {
|
|
|
1555
1856
|
argv: rerun("--url", "<URL>")
|
|
1556
1857
|
}]
|
|
1557
1858
|
});
|
|
1558
|
-
const
|
|
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 };
|
|
1559
1861
|
const report = await conformance(client(), {
|
|
1560
1862
|
...flags.channel ? { channel: flags.channel } : {},
|
|
1561
1863
|
...withToken
|
|
@@ -1570,12 +1872,16 @@ async function run(command, args) {
|
|
|
1570
1872
|
const [path, extra] = rest;
|
|
1571
1873
|
if (!path) throw usage("Missing the channel to create, such as dev/alerts.", { reason: "missing_arguments" });
|
|
1572
1874
|
if (extra !== void 0) throw usage(`channels create takes one channel: ${extra} is one too many.`);
|
|
1573
|
-
const { channel, created } = await client().createChannel(path);
|
|
1875
|
+
const { channel, created, grants } = await client().createChannel(path, flags.private ? { private: true } : {});
|
|
1574
1876
|
if (flags.json) result({
|
|
1575
1877
|
channel,
|
|
1576
|
-
outcome: created ? "created" : "unchanged"
|
|
1878
|
+
outcome: created ? "created" : "unchanged",
|
|
1879
|
+
...grants ? { grants } : {}
|
|
1577
1880
|
});
|
|
1578
|
-
else
|
|
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`);
|
|
1579
1885
|
return 0;
|
|
1580
1886
|
}
|
|
1581
1887
|
if (sub !== void 0 && sub !== "list") throw usage(`Unknown command ${sub} for ${named()} channels.`, { reason: "unknown_command" });
|
|
@@ -1759,6 +2065,83 @@ async function run(command, args) {
|
|
|
1759
2065
|
out(list.length === 0 ? "no grants" : formatGrants(list));
|
|
1760
2066
|
return 0;
|
|
1761
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
|
+
}
|
|
1762
2145
|
if (verb === "revoke") {
|
|
1763
2146
|
const id = trustId("grant", rest[0]);
|
|
1764
2147
|
const { revoked } = await client().revokeGrant(id);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $t as ExternalCopy, C as InboxItem, Ct as ThreadsPage, Dt as TokenInput, F as MessagesPage, J as RegistrationView, L as MessagesQueryInput, Mt as UpdateGrantInput, N as Me, Ot as TokenView, P as MessageView, Qt as Actor, S as InboxEntry, St as ThreadView, Tt as ThreadsQueryInput, an as ExternalFile, b as GrantView, bt as SyncedView, d as EventsPage, en as Attachment, et as ScheduleView, ft as SyncFindInput, g as FiltersInput, gt as SyncImportInput, h as Explanation, i as BoardEventView, in as ExternalEvent, it as SourceJoin, j as MatchView, l as Discovery, mt as SyncFindView, nt as SchedulesQueryInput, o as ChannelView, on as ExternalLink, q as RegisterInput, rn as ExternalAuthor, sn as Link, st as SourceRead, vt as SyncReceiptInput, y as GrantInput, yt as SyncThreadView } from "./routes-BpKdMvgX.mjs";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
//#region src/client/client.d.ts
|
|
4
4
|
/**
|
|
@@ -143,10 +143,28 @@ declare function createBoardClient(options: ClientOptions): {
|
|
|
143
143
|
/**
|
|
144
144
|
* Makes a channel before anything posts to it, as a first post would. Needs `read` and `post`
|
|
145
145
|
* there. `created` is false when it was there already; it's left as it is.
|
|
146
|
+
*
|
|
147
|
+
* `private` makes it closed to everyone but you, from the protocol's own methods: a grant
|
|
148
|
+
* letting you in at `<path>/`, then one closing `<path>/` to everyone else, then the channel,
|
|
149
|
+
* answering the two grants as `grants`. A failure part way leaves the channel open with a grant
|
|
150
|
+
* too many, or closed and not made yet, and never shuts you out. Before it writes anything, it
|
|
151
|
+
* refuses a caller that's neither a person nor a project's deployment (400 `no_own_principal`),
|
|
152
|
+
* one that can't list grants, a path a grant other than `*`'s reaches already (409
|
|
153
|
+
* `channel_granted`: the channel, `<path>/`, or a pattern under it, whose grants would still let
|
|
154
|
+
* in whoever they name), and a path where it or a channel under it is there already (409
|
|
155
|
+
* `channel_exists`), since closing `security/` closes `security/incidents` too. A board that
|
|
156
|
+
* keeps no grants fails on the listing, with nothing made. Once its own grant is made it lists
|
|
157
|
+
* them again, and takes its own back when another reaches the path, so of two callers making
|
|
158
|
+
* the same channel at once, at most one keeps a way in; and once the lock is made, it lists them
|
|
159
|
+
* a last time, and takes both back when a grant made in between still reaches the path, or its
|
|
160
|
+
* own two aren't as it made them (someone added themselves to its grant, or opened the lock).
|
|
146
161
|
*/
|
|
147
|
-
createChannel: (path: string
|
|
162
|
+
createChannel: (path: string, options?: {
|
|
163
|
+
private?: boolean;
|
|
164
|
+
}) => Promise<{
|
|
148
165
|
channel: ChannelView;
|
|
149
166
|
created: boolean;
|
|
167
|
+
grants?: GrantView[];
|
|
150
168
|
}>;
|
|
151
169
|
actors: () => Promise<Actor[]>;
|
|
152
170
|
messages: (query?: Filters & Omit<MessagesQueryInput, keyof FiltersInput>) => Promise<MessagesPage>;
|
|
@@ -185,7 +203,7 @@ declare function createBoardClient(options: ClientOptions): {
|
|
|
185
203
|
grant: GrantView;
|
|
186
204
|
}>;
|
|
187
205
|
/** Adds and removes principals (by who they are, environments aside), or replaces its `can`. Needs what `checkGrantChange` says, for the grant as it was and as it'd be. */
|
|
188
|
-
updateGrant: (id: string,
|
|
206
|
+
updateGrant: (id: string, { add, remove, can }: UpdateGrantInput) => Promise<{
|
|
189
207
|
grant: GrantView;
|
|
190
208
|
}>;
|
|
191
209
|
/**
|