@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.
- package/dist/{access-N3XmkKXg.mjs → access-BsP0hvcC.mjs} +169 -12
- package/dist/access.d.mts +3 -3
- package/dist/access.mjs +5 -5
- package/dist/{actors-ihyN47OV.mjs → actors-DFOpTw89.mjs} +2 -2
- package/dist/{auth-D6z3rMNj.d.mts → auth-C21V0EK1.d.mts} +128 -9
- package/dist/auth-CrjXLgOb.mjs +599 -0
- package/dist/{backend-CWpyR1A7.d.mts → backend-D21q8mdm.d.mts} +30 -7
- package/dist/backend-local.d.mts +1 -1
- package/dist/backend-local.mjs +1 -1
- package/dist/{chat-provider-DJpFUaFv.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-BOBQHVqM.d.mts → commands-BorACIFS.d.mts} +168 -1
- package/dist/{commands-CHoMl06v.mjs → commands-CENWob9m.mjs} +281 -11
- package/dist/{conformance-qKmGLTAT.mjs → conformance-CKrwglzA.mjs} +491 -105
- package/dist/conformance.d.mts +20 -2
- package/dist/conformance.mjs +1 -1
- package/dist/{engine-JxgZiikU.mjs → engine-wN7quvbU.mjs} +2 -2
- package/dist/{errors-Pk0XV1hK.mjs → errors-rYDxZEuN.mjs} +116 -7
- package/dist/exports-BxljH73E.d.mts +4 -0
- package/dist/{exports-gHDHlg0i.mjs → exports-GIRJm2Ja.mjs} +136 -26
- package/dist/{index-CXvvYNYj.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-BbLjA5vI.mjs → local-yKwdgukb.mjs} +1981 -1574
- package/dist/{main-CQpCZJFw.mjs → main-DjokcEAL.mjs} +440 -50
- package/dist/{middleware-BU7rVi9F.mjs → middleware-BxgizazV.mjs} +1 -1
- package/dist/provider-DEOfc4Ls.d.mts +1049 -0
- package/dist/{provider-BlzUvcM9.d.mts → routes-BpKdMvgX.d.mts} +2461 -2480
- package/dist/{serve-D8_W4UN6.mjs → serve-CJ8hauK2.mjs} +4 -4
- package/dist/{server-BiIUXWbU.mjs → server-CtaTtyhw.mjs} +7 -7
- package/dist/{serving-D7rcUtSC.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 -2
- package/dist/sync-slack.d.mts +3 -3
- package/dist/sync.d.mts +2 -2
- package/dist/{targets-CknPGGVi.mjs → targets-n2i2ZOWI.mjs} +104 -12
- package/dist/{tokens-DPKjl3jf.mjs → tokens-Dn4cPZIr.mjs} +2 -2
- package/docs/01-board/01-mounting.md +12 -5
- package/docs/01-board/03-identity.md +14 -13
- package/docs/01-board/07-schedules.md +1 -1
- package/docs/01-board/09-access.md +170 -58
- package/docs/03-guides/03-ci.md +19 -17
- package/docs/03-guides/05-agent-factory.md +5 -6
- package/docs/04-reference/01-cli.md +99 -22
- package/docs/04-reference/02-board.md +42 -11
- package/docs/04-reference/03-http.md +21 -14
- package/docs/04-reference/05-conformance.md +31 -5
- package/package.json +1 -1
- package/dist/auth-r-_PeZyw.mjs +0 -277
- package/dist/exports-BuKjVq2t.d.mts +0 -4
- package/dist/folds-DjFTiqIM.d.mts +0 -552
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as forbidden } from "./errors-
|
|
1
|
+
import { a as forbidden } from "./errors-rYDxZEuN.mjs";
|
|
2
2
|
import { a as ChannelPath, h as SCOPE_MAX } from "./schemas-BG205xds.mjs";
|
|
3
3
|
//#region src/server/access.ts
|
|
4
4
|
/**
|
|
@@ -15,6 +15,17 @@ const PERMISSIONS = [
|
|
|
15
15
|
"manage"
|
|
16
16
|
];
|
|
17
17
|
/**
|
|
18
|
+
* A `can`, a channel pattern, a permission, or a scope that doesn't parse, saying what to write
|
|
19
|
+
* instead: what a board answers 400 for. Its `code` is `invalid_can`.
|
|
20
|
+
*/
|
|
21
|
+
var InvalidCan = class extends Error {
|
|
22
|
+
code = "invalid_can";
|
|
23
|
+
constructor(message) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = "InvalidCan";
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
18
29
|
* One hop of implication, kept as data like Vercel's git broker
|
|
19
30
|
* (`ACTION_IMPLICATIONS`). Each verb that addresses a message by ID implies
|
|
20
31
|
* `read`, so none of them is a blind existence oracle. `post` implies nothing:
|
|
@@ -41,12 +52,11 @@ function parsePattern(pattern) {
|
|
|
41
52
|
if (pattern === "*") return { kind: "all" };
|
|
42
53
|
if (pattern.includes("*")) {
|
|
43
54
|
const before = pattern.slice(0, pattern.indexOf("*")).replace(/\/+$/, "");
|
|
44
|
-
|
|
45
|
-
throw new Error(`invalid channel pattern ${pattern}: ${hint}`);
|
|
55
|
+
throw new InvalidCan(`invalid channel pattern ${pattern}: ${before === "" ? "write * for every channel" : ChannelPath.safeParse(before).success ? `write ${before}/ for ${before} and its subtree` : SHAPE}`);
|
|
46
56
|
}
|
|
47
57
|
const subtree = pattern.endsWith("/");
|
|
48
58
|
const path = subtree ? pattern.slice(0, -1) : pattern;
|
|
49
|
-
if (!ChannelPath.safeParse(path).success) throw new
|
|
59
|
+
if (!ChannelPath.safeParse(path).success) throw new InvalidCan(`invalid channel pattern ${pattern || "(empty)"}: ${SHAPE}`);
|
|
50
60
|
return subtree ? {
|
|
51
61
|
kind: "subtree",
|
|
52
62
|
path
|
|
@@ -60,7 +70,7 @@ const key = (pattern) => pattern.kind === "all" ? "*" : pattern.kind === "subtre
|
|
|
60
70
|
function expand(grant) {
|
|
61
71
|
const out = /* @__PURE__ */ new Set();
|
|
62
72
|
const add = (permission) => {
|
|
63
|
-
if (!ORDER.has(permission)) throw new
|
|
73
|
+
if (!ORDER.has(permission)) throw new InvalidCan(`unknown permission ${String(permission)}: use ${PERMISSIONS.join(", ")}`);
|
|
64
74
|
if (out.has(permission)) return;
|
|
65
75
|
out.add(permission);
|
|
66
76
|
for (const implied of IMPLIES[permission]) add(implied);
|
|
@@ -130,22 +140,30 @@ const entriesIn = (rules) => [
|
|
|
130
140
|
}, permissions])
|
|
131
141
|
];
|
|
132
142
|
const RULES = Symbol("board.access");
|
|
143
|
+
/** How many channels an access remembers whether it may read. */
|
|
144
|
+
const READABLE_MAX = 4096;
|
|
133
145
|
const isAccess = (value) => typeof value === "object" && RULES in value;
|
|
134
146
|
function fromRules(rules) {
|
|
135
147
|
const entries = entriesIn(rules);
|
|
136
148
|
const everywhere = (permission) => (rules.all?.has(permission) ?? false) && entries.every(([, permissions]) => permissions.has(permission));
|
|
149
|
+
const uniform = rules.exact.size === 0 && rules.subtrees.length === 0 ? rules.all?.has("read") ?? false : null;
|
|
137
150
|
const readable = /* @__PURE__ */ new Map();
|
|
138
151
|
const compiled = {
|
|
139
152
|
[RULES]: rules,
|
|
140
153
|
can: (permission, channel) => resolve(rules, channel).has(permission),
|
|
141
154
|
readable(channel) {
|
|
155
|
+
if (uniform !== null) return uniform;
|
|
142
156
|
let found = readable.get(channel);
|
|
143
|
-
if (found === void 0)
|
|
157
|
+
if (found === void 0) {
|
|
158
|
+
if (readable.size >= READABLE_MAX) readable.clear();
|
|
159
|
+
readable.set(channel, found = resolve(rules, channel).has("read"));
|
|
160
|
+
}
|
|
144
161
|
return found;
|
|
145
162
|
},
|
|
146
163
|
readsAll: everywhere("read"),
|
|
147
164
|
everywhere,
|
|
148
165
|
anywhere: (permission) => entries.some(([, permissions]) => permissions.has(permission)),
|
|
166
|
+
at: (permission, pattern) => at(rules, parsePattern(pattern)).has(permission),
|
|
149
167
|
narrow(scope) {
|
|
150
168
|
const other = isAccess(scope) ? scope[RULES] : canonical(entriesOf(scope));
|
|
151
169
|
const patterns = /* @__PURE__ */ new Map([["*", { kind: "all" }]]);
|
|
@@ -180,6 +198,86 @@ function union(accesses) {
|
|
|
180
198
|
for (const side of rules) for (const [pattern] of entriesIn(side)) patterns.set(key(pattern), pattern);
|
|
181
199
|
return fromRules(canonical([...patterns.values()].map((pattern) => [pattern, new Set(rules.flatMap((side) => [...at(side, pattern)]))])));
|
|
182
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* A grant's `can`, checked and kept as written, patterns and all, since each pattern counts where
|
|
203
|
+
* grants meet: `{ 'security/': [] }` closes `security/` though it gives nothing. Its lists are
|
|
204
|
+
* sorted, without repeats. A bad pattern or permission throws, saying what to write.
|
|
205
|
+
*/
|
|
206
|
+
function writtenCan(can, max = 64) {
|
|
207
|
+
if (typeof can !== "object" || can === null || Array.isArray(can)) throw new InvalidCan("a grant's can is a map from channel pattern to permissions, like { 'ci/': ['read', 'post'] }");
|
|
208
|
+
const entries = Object.entries(can);
|
|
209
|
+
if (entries.length === 0) throw new InvalidCan("a grant's can names at least one channel pattern, like { '*': ['read'] }");
|
|
210
|
+
if (entries.length > max) throw new InvalidCan(`a grant's can names at most ${max} channel patterns`);
|
|
211
|
+
const out = {};
|
|
212
|
+
for (const [pattern, grant] of entries.sort(([a], [b]) => a === "*" ? -1 : b === "*" ? 1 : a.localeCompare(b))) {
|
|
213
|
+
parsePattern(pattern);
|
|
214
|
+
if (grant === "all") {
|
|
215
|
+
out[pattern] = "all";
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (!Array.isArray(grant)) throw new InvalidCan(`${pattern} takes 'all' or a list of permissions: ${PERMISSIONS.join(", ")}`);
|
|
219
|
+
for (const permission of grant) if (!ORDER.has(permission)) throw new InvalidCan(`unknown permission ${String(permission)} at ${pattern}: use ${PERMISSIONS.join(", ")}, or all`);
|
|
220
|
+
out[pattern] = [...new Set(grant)].sort((a, b) => ORDER.get(a) - ORDER.get(b));
|
|
221
|
+
}
|
|
222
|
+
return out;
|
|
223
|
+
}
|
|
224
|
+
const RANK = new Map([
|
|
225
|
+
"principal",
|
|
226
|
+
"group",
|
|
227
|
+
"everyone"
|
|
228
|
+
].map((level, index) => [level, index]));
|
|
229
|
+
/** Each pattern a `can` names, with what it gives, implications included. */
|
|
230
|
+
const namedIn = (can) => entriesOf(can);
|
|
231
|
+
/**
|
|
232
|
+
* For each pattern any matched grant names: the closest level among the grants naming it, and
|
|
233
|
+
* what those grants give there, added up.
|
|
234
|
+
*/
|
|
235
|
+
function closest(matched) {
|
|
236
|
+
const byPattern = /* @__PURE__ */ new Map();
|
|
237
|
+
for (const grant of matched) for (const [pattern, permissions] of namedIn(grant.can)) {
|
|
238
|
+
const name = key(pattern);
|
|
239
|
+
const found = byPattern.get(name);
|
|
240
|
+
if (!found || RANK.get(grant.level) < RANK.get(found.level)) byPattern.set(name, {
|
|
241
|
+
pattern,
|
|
242
|
+
level: grant.level,
|
|
243
|
+
permissions: new Set(permissions),
|
|
244
|
+
sources: [grant.source]
|
|
245
|
+
});
|
|
246
|
+
else if (found.level === grant.level) {
|
|
247
|
+
for (const permission of permissions) found.permissions.add(permission);
|
|
248
|
+
if (!found.sources.includes(grant.source)) found.sources.push(grant.source);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return byPattern;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* What a caller may do from the grants that match it. At each channel, the most specific pattern
|
|
255
|
+
* any of them names decides (an exact channel, then the longest subtree, then `*`); among the
|
|
256
|
+
* grants naming that pattern, the closest principal does; and grants tied there add up.
|
|
257
|
+
*/
|
|
258
|
+
function combine(matched) {
|
|
259
|
+
return fromRules(canonical([...closest(matched).values()].map(({ pattern, permissions }) => [pattern, permissions])));
|
|
260
|
+
}
|
|
261
|
+
/** Which pattern, level, and grants decide `channel` for a caller, and what they give: `combine`'s answer, explained. */
|
|
262
|
+
function decide(matched, channel) {
|
|
263
|
+
const covering = [...closest(matched).values()].filter(({ pattern }) => pattern.kind === "all" ? true : pattern.kind === "exact" ? pattern.path === channel : under(channel, pattern.path));
|
|
264
|
+
const specificity = ({ pattern }) => pattern.kind === "exact" ? Infinity : pattern.kind === "subtree" ? pattern.path.length : -1;
|
|
265
|
+
const [winner, ...beaten] = covering.sort((a, b) => specificity(b) - specificity(a));
|
|
266
|
+
if (!winner) return {
|
|
267
|
+
pattern: null,
|
|
268
|
+
over: [],
|
|
269
|
+
level: null,
|
|
270
|
+
sources: [],
|
|
271
|
+
permissions: []
|
|
272
|
+
};
|
|
273
|
+
return {
|
|
274
|
+
pattern: key(winner.pattern),
|
|
275
|
+
over: beaten.map(({ pattern }) => key(pattern)),
|
|
276
|
+
level: winner.level,
|
|
277
|
+
sources: winner.sources,
|
|
278
|
+
permissions: [...winner.permissions].sort((a, b) => ORDER.get(a) - ORDER.get(b))
|
|
279
|
+
};
|
|
280
|
+
}
|
|
183
281
|
/** An access as `x-board-scope` writes it, `dev/=read,post;ci/=read`, or `*=` for nothing: what a stored principal keeps. */
|
|
184
282
|
function scopeOf(access) {
|
|
185
283
|
const entries = Object.entries(access.summary()).map(([pattern, permissions]) => `${pattern}=${permissions.join(",")}`);
|
|
@@ -193,24 +291,24 @@ function scopeOf(access) {
|
|
|
193
291
|
* nothing by sending it.
|
|
194
292
|
*/
|
|
195
293
|
function parseScope(header) {
|
|
196
|
-
if (header.length > 4e3) throw new
|
|
294
|
+
if (header.length > 4e3) throw new InvalidCan(`x-board-scope is longer than ${SCOPE_MAX} characters`);
|
|
197
295
|
const out = {};
|
|
198
296
|
const entries = header.split(";").map((entry) => entry.trim());
|
|
199
|
-
if (entries.every((entry) => entry === "")) throw new
|
|
297
|
+
if (entries.every((entry) => entry === "")) throw new InvalidCan("x-board-scope is empty: write pattern=permissions, like dev/=read,post");
|
|
200
298
|
for (const entry of entries) {
|
|
201
299
|
if (entry === "") continue;
|
|
202
300
|
const split = entry.indexOf("=");
|
|
203
|
-
if (split < 0) throw new
|
|
301
|
+
if (split < 0) throw new InvalidCan(`x-board-scope entry ${entry} needs =: write pattern=permissions, like dev/=read,post`);
|
|
204
302
|
const pattern = entry.slice(0, split).trim();
|
|
205
303
|
const list = entry.slice(split + 1).trim();
|
|
206
|
-
if (Object.hasOwn(out, pattern)) throw new
|
|
304
|
+
if (Object.hasOwn(out, pattern)) throw new InvalidCan(`x-board-scope lists ${pattern} twice`);
|
|
207
305
|
parsePattern(pattern);
|
|
208
306
|
const permissions = list === "" ? [] : list.split(",").map((permission) => permission.trim());
|
|
209
307
|
if (permissions.length === 1 && permissions[0] === "all") {
|
|
210
308
|
out[pattern] = "all";
|
|
211
309
|
continue;
|
|
212
310
|
}
|
|
213
|
-
for (const permission of permissions) if (!ORDER.has(permission)) throw new
|
|
311
|
+
for (const permission of permissions) if (!ORDER.has(permission)) throw new InvalidCan(`x-board-scope: unknown permission ${permission || "(empty)"}: use ${PERMISSIONS.join(", ")}, or all`);
|
|
214
312
|
out[pattern] = permissions;
|
|
215
313
|
}
|
|
216
314
|
return out;
|
|
@@ -238,5 +336,64 @@ function authorize(access, permission, channel, hidden) {
|
|
|
238
336
|
channel
|
|
239
337
|
});
|
|
240
338
|
}
|
|
339
|
+
/** Whether `other` is a pattern more specific than `pattern`, and under it. */
|
|
340
|
+
const isUnder = (other, pattern) => other !== pattern && (pattern === "*" || pattern.endsWith("/") && (other === pattern.slice(0, -1) || other.startsWith(pattern)));
|
|
341
|
+
/**
|
|
342
|
+
* Whether a caller may change grants so: make or widen one (`changed`), or revoke one or remove
|
|
343
|
+
* from it (`revoked`). You can't grant what you don't have. Your token's and your own grants'
|
|
344
|
+
* limits count, an `everyone` lock doesn't, and anyone you let in gets what `everyone` gets. Null
|
|
345
|
+
* when it may; otherwise why not, and where.
|
|
346
|
+
*
|
|
347
|
+
* - **Reach:** `manage` at each of the changed grant's patterns, by `caller` and by `own`, and at
|
|
348
|
+
* every more specific spot under them by `own`. A lock binds whoever the grant names as much as
|
|
349
|
+
* the caller, now and once it's lifted, so it doesn't count against the caller there; the
|
|
350
|
+
* caller's own limits do. At the grant's own patterns it counts too: there the grant would meet
|
|
351
|
+
* the lock at the same pattern, and its principal is closer.
|
|
352
|
+
* - **Admission:** wherever `everyone` gives something, `caller` has it too, since any principal a
|
|
353
|
+
* grant lets in gets what `everyone` gives. A revoke or a removal lets no one in, so it's judged
|
|
354
|
+
* by reach alone, at the patterns of the grant as it was.
|
|
355
|
+
*
|
|
356
|
+
* It looks only at the spots where access can change: the grants' patterns, the `everyone`
|
|
357
|
+
* grants', and the caller's own, from `summary()`. It does no I/O, so a board and Vercel's API run
|
|
358
|
+
* the same rule.
|
|
359
|
+
*/
|
|
360
|
+
function checkGrantChange(change) {
|
|
361
|
+
if (change.owner) return null;
|
|
362
|
+
const { caller, own } = change;
|
|
363
|
+
const everyone = change.after.filter((grant) => grant.principals.some((principal) => principal.kind === "everyone"));
|
|
364
|
+
const lifted = Object.keys(change.revoked?.can ?? {});
|
|
365
|
+
const made = Object.keys(change.changed?.can ?? {});
|
|
366
|
+
const spots = [.../* @__PURE__ */ new Set([
|
|
367
|
+
...lifted,
|
|
368
|
+
...made,
|
|
369
|
+
...everyone.flatMap((grant) => Object.keys(grant.can)),
|
|
370
|
+
...Object.keys(caller.summary()),
|
|
371
|
+
...Object.keys(own.summary())
|
|
372
|
+
])];
|
|
373
|
+
for (const pattern of /* @__PURE__ */ new Set([...lifted, ...made])) {
|
|
374
|
+
if (!caller.at("manage", pattern) || !own.at("manage", pattern)) return {
|
|
375
|
+
reason: "reach",
|
|
376
|
+
pattern,
|
|
377
|
+
permission: "manage"
|
|
378
|
+
};
|
|
379
|
+
for (const spot of spots) if (isUnder(spot, pattern) && !own.at("manage", spot)) return {
|
|
380
|
+
reason: "reach",
|
|
381
|
+
pattern: spot,
|
|
382
|
+
permission: "manage"
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
if (made.length === 0) return null;
|
|
386
|
+
const gives = combine(everyone.map((grant) => ({
|
|
387
|
+
level: "everyone",
|
|
388
|
+
can: grant.can,
|
|
389
|
+
source: null
|
|
390
|
+
})));
|
|
391
|
+
for (const spot of spots) for (const permission of PERMISSIONS) if (gives.at(permission, spot) && !caller.at(permission, spot)) return {
|
|
392
|
+
reason: "admission",
|
|
393
|
+
pattern: spot,
|
|
394
|
+
permission
|
|
395
|
+
};
|
|
396
|
+
return null;
|
|
397
|
+
}
|
|
241
398
|
//#endregion
|
|
242
|
-
export {
|
|
399
|
+
export { checkGrantChange as a, decide as c, scopeOf as d, union as f, authorize as i, parsePattern as l, InvalidCan as n, combine as o, writtenCan as p, PERMISSIONS as r, compileAccess as s, FULL_ACCESS as t, parseScope as u };
|
package/dist/access.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as DEFAULT_CAN, c as IssuerConfig, f as Principal, i as Claims, l as Known, n as AuthenticateContext, p as PrincipalKind, r as CallerRequest, s as HostPrincipal, t as Authenticate, u as OidcTokensOptions } from "./auth-
|
|
1
|
+
import { Bt as FULL_ACCESS, Gt as InvalidCan, Ht as GrantChange, It as Access, Lt as AccessSummary, Qt as Actor, Rt as Can, Ut as GrantChangeRefusal, Vt as Grant, Wt as GrantShape, Xt as compileAccess, Yt as checkGrantChange, Zt as union, qt as Permission, tn as Author, zt as ChannelPattern } from "./routes-BpKdMvgX.mjs";
|
|
2
|
+
import { _ as GrantExplanation, a as DEFAULT_CAN, b as explainGrants, c as IssuerConfig, f as Principal, g as DecidingGrant, h as Caller, i as Claims, l as Known, n as AuthenticateContext, p as PrincipalKind, r as CallerRequest, s as HostPrincipal, t as Authenticate, u as OidcTokensOptions, v as GrantFacts, x as grantAccess, y as GrantSource } from "./auth-C21V0EK1.mjs";
|
|
3
3
|
//#region src/server/tokens.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* The OIDC tokens made out to this board: a request's bearer token, from Vercel (people and
|
|
@@ -25,4 +25,4 @@ type ResolvedActor = {
|
|
|
25
25
|
*/
|
|
26
26
|
export declare function resolveActor(principal: Principal, claims: Claims, audience: string): ResolvedActor;
|
|
27
27
|
//#endregion
|
|
28
|
-
export { type Access, type AccessSummary, type Authenticate, type AuthenticateContext, type CallerRequest, type Can, type ChannelPattern, type Claims, DEFAULT_CAN, FULL_ACCESS, type Grant, type HostPrincipal, type IssuerConfig, type Known, type OidcTokensOptions, type Permission, type Principal, type PrincipalKind, compileAccess, union };
|
|
28
|
+
export { type Access, type AccessSummary, type Authenticate, type AuthenticateContext, type Caller, type CallerRequest, type Can, type ChannelPattern, type Claims, DEFAULT_CAN, type DecidingGrant, FULL_ACCESS, type Grant, type GrantChange, type GrantChangeRefusal, type GrantExplanation, type GrantFacts, type GrantShape, type GrantSource, type HostPrincipal, InvalidCan, type IssuerConfig, type Known, type OidcTokensOptions, type Permission, type Principal, type PrincipalKind, checkGrantChange, compileAccess, explainGrants, grantAccess, union };
|
package/dist/access.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as oidcTokens } from "./tokens-
|
|
5
|
-
export { DEFAULT_CAN, FULL_ACCESS, compileAccess, oidcTokens, resolveActor, union };
|
|
1
|
+
import { a as checkGrantChange, f as union, n as InvalidCan, s as compileAccess, t as FULL_ACCESS } from "./access-BsP0hvcC.mjs";
|
|
2
|
+
import { E as grantAccess, T as explainGrants, n as DEFAULT_CAN } from "./auth-CrjXLgOb.mjs";
|
|
3
|
+
import { i as resolveActor } from "./actors-DFOpTw89.mjs";
|
|
4
|
+
import { t as oidcTokens } from "./tokens-Dn4cPZIr.mjs";
|
|
5
|
+
export { DEFAULT_CAN, FULL_ACCESS, InvalidCan, checkGrantChange, compileAccess, explainGrants, grantAccess, oidcTokens, resolveActor, union };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { r as badRequest } from "./errors-
|
|
1
|
+
import { r as badRequest } from "./errors-rYDxZEuN.mjs";
|
|
2
2
|
import { b as toStorable } from "./schemas-BG205xds.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { u as parseScope } from "./access-BsP0hvcC.mjs";
|
|
4
4
|
import { t as own } from "./own-OwgPWdmh.mjs";
|
|
5
5
|
import { t as extractMentions } from "./mentions-CB6ShY4R.mjs";
|
|
6
6
|
//#region src/server/actors.ts
|
|
@@ -1,5 +1,88 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { It as Access, Jt as WrittenCan, Kt as Level, Rt as Can, qt as Permission } from "./routes-BpKdMvgX.mjs";
|
|
2
2
|
import { JWTVerifyGetKey } from "jose";
|
|
3
|
+
//#region src/server/grants.d.ts
|
|
4
|
+
/** Who asks, as a verified token says, in the terms grants name them by. */
|
|
5
|
+
type Caller = {
|
|
6
|
+
kind: 'user';
|
|
7
|
+
userId: string;
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'project';
|
|
10
|
+
projectId: string;
|
|
11
|
+
environment: string;
|
|
12
|
+
teamId?: string;
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'github';
|
|
15
|
+
repository: string;
|
|
16
|
+
repositoryId?: string;
|
|
17
|
+
workflowRef?: string;
|
|
18
|
+
ref?: string;
|
|
19
|
+
event?: string;
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'oidc';
|
|
22
|
+
issuer: string;
|
|
23
|
+
claims: Readonly<Record<string, unknown>>;
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'app';
|
|
26
|
+
clientId: string;
|
|
27
|
+
};
|
|
28
|
+
/** A grant as the decision reads it: whom it names, and what it gives where. */
|
|
29
|
+
type DecidingGrant = {
|
|
30
|
+
readonly principals: readonly GrantPrincipal[];
|
|
31
|
+
readonly can: WrittenCan;
|
|
32
|
+
};
|
|
33
|
+
/** What decides a caller's access, all of it plain data or a predicate the backend answers. */
|
|
34
|
+
type GrantFacts<G extends DecidingGrant = DecidingGrant> = {
|
|
35
|
+
caller: Caller;
|
|
36
|
+
/** The board's grants, as they are, or as a write is about to leave them. */
|
|
37
|
+
grants: readonly G[];
|
|
38
|
+
/** Whether the caller, a user, is a person on the board's team: `all-users` names them, and that lets them in. */
|
|
39
|
+
member?: boolean;
|
|
40
|
+
/** Whether the caller, a project, is on the board's team: `all-projects` names it. */
|
|
41
|
+
teamProject?: boolean;
|
|
42
|
+
/** Whether the caller, an app, is installed on the board's team: `all-apps` names it. */
|
|
43
|
+
teamApp?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* The most the caller may do anywhere, whatever the grants say: what a backend makes of a
|
|
46
|
+
* person's team role (a viewer is `['read', 'react']`) or an app's scopes. Nothing caps it,
|
|
47
|
+
* without it.
|
|
48
|
+
*/
|
|
49
|
+
cap?: readonly Permission[];
|
|
50
|
+
/** A token's `can`, which narrows what the grants give. */
|
|
51
|
+
can?: Can;
|
|
52
|
+
};
|
|
53
|
+
/** Where a matched grant came from: one the board keeps. */
|
|
54
|
+
type GrantSource<G extends DecidingGrant = DecidingGrant> = {
|
|
55
|
+
grant: G;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* What the caller may do by the board's grants: `caller`, all of it, as `GET /me` says, and `own`,
|
|
59
|
+
* the same without `everyone`'s grants, what `checkGrantChange` judges reach by. At each channel the
|
|
60
|
+
* most specific pattern a grant naming it gives decides, then the closest principal there, and
|
|
61
|
+
* grants tied there add up; `cap` caps both, and a token's `can` narrows them. Null when
|
|
62
|
+
* nothing but `everyone` names it, since `everyone` lets no one in itself.
|
|
63
|
+
*/
|
|
64
|
+
declare function grantAccess<G extends DecidingGrant>(facts: GrantFacts<G>): {
|
|
65
|
+
caller: Access;
|
|
66
|
+
own: Access;
|
|
67
|
+
} | null;
|
|
68
|
+
/**
|
|
69
|
+
* Which grants decide `channel` for the caller: the `pattern` that wins there, the patterns it wins
|
|
70
|
+
* `over`, most specific first, the `level` that wins at it, the `grants` at that level, which add
|
|
71
|
+
* up, and what the caller may do there, `permissions`, after its `cap` and its token's `can`.
|
|
72
|
+
* `capped` says whether the cap took anything away. `pattern` and `level` are null for a caller
|
|
73
|
+
* nothing lets in, whose `permissions` are empty. What `grantAccess` gives, explained.
|
|
74
|
+
*/
|
|
75
|
+
type GrantExplanation<G extends DecidingGrant = DecidingGrant> = {
|
|
76
|
+
pattern: string | null;
|
|
77
|
+
over: string[];
|
|
78
|
+
level: Level | null;
|
|
79
|
+
grants: G[];
|
|
80
|
+
capped: boolean;
|
|
81
|
+
permissions: Permission[];
|
|
82
|
+
};
|
|
83
|
+
/** Which grants decide `channel` for the caller `facts` describes, from plain data, as a board explains it. */
|
|
84
|
+
declare function explainGrants<G extends DecidingGrant>(facts: GrantFacts<G>, channel: string): GrantExplanation<G>;
|
|
85
|
+
//#endregion
|
|
3
86
|
//#region src/server/auth.d.ts
|
|
4
87
|
/**
|
|
5
88
|
* What a request says about who's calling, beside its credential: labels the caller picks for
|
|
@@ -98,15 +181,51 @@ type OidcTokensOptions = {
|
|
|
98
181
|
};
|
|
99
182
|
/** A principal as the board keeps it to work its access out again: who it is, its token's facts, its scope, and the board token it came with. */
|
|
100
183
|
type Known = Pick<Principal, 'id' | 'kind' | 'handle' | 'facts' | 'scope' | 'token'>;
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Who a grant names, as the board keeps it: IDs, with the names it knows beside them. A board
|
|
186
|
+
* that verifies tokens itself knows none, so it keeps what was written: a user's ID, a project's
|
|
187
|
+
* ID, a repository's `owner/name`.
|
|
188
|
+
*/
|
|
189
|
+
type GrantPrincipal = {
|
|
190
|
+
kind: 'user';
|
|
191
|
+
userId: string;
|
|
192
|
+
email?: string;
|
|
193
|
+
} | {
|
|
194
|
+
kind: 'project';
|
|
195
|
+
projectId: string;
|
|
196
|
+
name?: string;
|
|
197
|
+
environments: readonly string[];
|
|
198
|
+
teamId?: string;
|
|
199
|
+
} | {
|
|
200
|
+
kind: 'github';
|
|
201
|
+
repository: string;
|
|
202
|
+
repositoryId?: string;
|
|
203
|
+
workflow?: string;
|
|
204
|
+
branch?: string;
|
|
205
|
+
event?: string;
|
|
206
|
+
} | {
|
|
207
|
+
kind: 'oidc';
|
|
104
208
|
issuer: string;
|
|
105
209
|
claims: Readonly<Record<string, string | readonly string[]>>;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
210
|
+
} | {
|
|
211
|
+
kind: 'all-users';
|
|
212
|
+
} | {
|
|
213
|
+
kind: 'all-projects';
|
|
214
|
+
environments: readonly string[];
|
|
215
|
+
} | {
|
|
216
|
+
kind: 'app';
|
|
217
|
+
clientId: string;
|
|
218
|
+
name?: string;
|
|
219
|
+
} | {
|
|
220
|
+
kind: 'all-apps';
|
|
221
|
+
} | {
|
|
222
|
+
kind: 'everyone';
|
|
223
|
+
};
|
|
224
|
+
/** A grant the board keeps: who it names, and one `can` for all of them, as written. */
|
|
225
|
+
type StoredGrant = {
|
|
226
|
+
id: string;
|
|
227
|
+
principals: readonly GrantPrincipal[];
|
|
228
|
+
can: WrittenCan;
|
|
110
229
|
};
|
|
111
230
|
/**
|
|
112
231
|
* What a grant or a token left without `can` gives: what Vercel's API gives a project it lets use a
|
|
@@ -147,4 +266,4 @@ type HostPrincipal = {
|
|
|
147
266
|
expiresAt?: Date | null;
|
|
148
267
|
};
|
|
149
268
|
//#endregion
|
|
150
|
-
export { DEFAULT_CAN as a, IssuerConfig as c, Pinned as d, Principal as f, Claims as i, Known as l, StoredGrant as m, AuthenticateContext as n, Granted as o, PrincipalKind as p, CallerRequest as r, HostPrincipal as s, Authenticate as t, OidcTokensOptions as u };
|
|
269
|
+
export { GrantExplanation as _, DEFAULT_CAN as a, explainGrants as b, IssuerConfig as c, Pinned as d, Principal as f, DecidingGrant as g, Caller as h, Claims as i, Known as l, StoredGrant as m, AuthenticateContext as n, Granted as o, PrincipalKind as p, CallerRequest as r, HostPrincipal as s, Authenticate as t, OidcTokensOptions as u, GrantFacts as v, grantAccess as x, GrantSource as y };
|