@vercel/board 0.32.0 → 0.34.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/README.md +25 -20
- package/dist/{access-CY5xVMIK.mjs → access-CdBcYPQH.mjs} +170 -13
- package/dist/access.d.mts +4 -5
- package/dist/access.mjs +5 -5
- package/dist/{actors-Bm-ojWWT.mjs → actors-MrIEr9LI.mjs} +3 -3
- package/dist/auth-DjoJygbG.mjs +599 -0
- package/dist/{auth-K8dY1nBY.d.mts → auth-aaoKt5DK.d.mts} +133 -100
- package/dist/backend-local.d.mts +28 -0
- package/dist/backend-local.mjs +2 -0
- package/dist/{backend-DxE9wGKm.d.mts → backend-u1sVvybh.d.mts} +108 -55
- package/dist/{chat-provider-DkFp2hrh.mjs → chat-provider-9hCT654s.mjs} +2 -2
- package/dist/{chat-provider-BChYrrA7.d.mts → chat-provider-De0iDnUB.d.mts} +2 -3
- 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 +6 -6
- package/dist/{commands-DsnQKTdB.mjs → commands-B8oZEByR.mjs} +37 -52
- package/dist/{commands-CpyPV_tk.d.mts → commands-BkVMdXP1.d.mts} +9 -6
- package/dist/{conformance-3RBKxwbp.mjs → conformance-gqYBkXFS.mjs} +79 -86
- package/dist/conformance.d.mts +1 -1
- package/dist/conformance.mjs +1 -1
- package/dist/{engine-DurYIRt8.mjs → engine-rtOVWsiF.mjs} +6 -8
- package/dist/{errors-CJXhhzvT.mjs → errors-D8ifv16L.mjs} +75 -6
- package/dist/{events-lujPA3gQ.mjs → events-IQg0k281.mjs} +2 -2
- package/dist/exports-Bx2dGpzr.mjs +3252 -0
- package/dist/exports-uwRl5qIj.d.mts +4 -0
- package/dist/{external-D3p5T57R.mjs → external-CYe424fO.mjs} +1 -1
- package/dist/index-D6mK0Ial.d.mts +11 -0
- package/dist/index.d.mts +10 -9
- package/dist/index.mjs +21 -8
- package/dist/index.node.d.mts +6 -7
- package/dist/index.node.mjs +3 -3
- package/dist/inspect/app.js +95 -95
- package/dist/{internal-CvsrprnU-zZMpDiRY.mjs → internal-CvsrprnU-CEPOUpAv.mjs} +63 -43
- package/dist/local-CPz22MQ8.mjs +9225 -0
- package/dist/{main-CcYDo9Hb.mjs → main-DScDKwQN.mjs} +129 -54
- package/dist/{backend-a2/store-memory.mjs → memory-7RRnLa4X.mjs} +3 -3
- package/dist/middleware-BjYpk4yq.mjs +103 -0
- package/dist/{provider-gynDUoyW.d.mts → provider-hB8QNrwm.d.mts} +369 -3
- package/dist/{client-COfYrgfV.d.mts → routes-De4W6lEs.d.mts} +997 -367
- package/dist/{schemas-DBmUO6pr.mjs → schemas-BG205xds.mjs} +2 -5
- package/dist/{serve-Bplieh0C.mjs → serve-B1noQRkn.mjs} +33 -24
- package/dist/{node-BgeGcwX0.mjs → server-Ov6GBJ8j.mjs} +419 -6
- package/dist/{serving-Y7s7VDjB.mjs → serving-2s7lqSBS.mjs} +1 -1
- package/dist/{sql-E1K5g_ih.mjs → sql-BQzKUqQt.mjs} +349 -114
- package/dist/sqlite-DCtZFEVm.mjs +30 -0
- package/dist/{sqlite-db-CzcD_FW8.mjs → sqlite-db-qLTs52Ny.mjs} +2 -3
- package/dist/{store-codec-pAG2oPgQ-SqDXlPBR.mjs → store-N8PXxDAS-BdL4Sq-f.mjs} +6 -2
- package/dist/{store-memory-B0PkVSuQ.mjs → store-memory-CKQVEzXN.mjs} +2 -4
- package/dist/store-memory-OdGsc-t_.mjs +2 -0
- package/dist/{store-polling-BZt2Rf3D-Div-bJ_D.mjs → store-polling-BZt2Rf3D-oh3aU_An.mjs} +1 -1
- package/dist/store-sqlite-CTxAVCcz.mjs +2 -0
- package/dist/{store-sqlite-D85t3tE7.mjs → store-sqlite-D6fIszST.mjs} +3 -4
- package/dist/sync-chat-sdk.d.mts +2 -2
- package/dist/sync-chat-sdk.mjs +2 -2
- package/dist/sync-github.d.mts +2 -2
- package/dist/sync-github.mjs +2 -2
- package/dist/sync-linear.d.mts +3 -3
- package/dist/sync-linear.mjs +2 -2
- package/dist/sync-slack.d.mts +3 -3
- package/dist/sync-slack.mjs +4 -4
- package/dist/sync.d.mts +2 -2
- package/dist/sync.mjs +2 -2
- package/dist/{watchers-hash-CurCzwhe.mjs → targets-aMdbp84G.mjs} +134 -16
- package/dist/{tokens-C7kYyrAG.mjs → tokens-LHLrnV_P.mjs} +15 -43
- package/docs/01-board/01-mounting.md +245 -288
- package/docs/01-board/03-identity.md +42 -50
- package/docs/01-board/04-messages.md +15 -14
- package/docs/01-board/05-reading.md +3 -3
- package/docs/01-board/06-watchers.md +58 -105
- package/docs/01-board/07-schedules.md +21 -41
- package/docs/01-board/08-middleware.md +11 -17
- package/docs/01-board/09-access.md +187 -343
- package/docs/01-board/10-local.md +81 -0
- package/docs/01-quickstart.md +49 -126
- package/docs/02-sync/01-overview.md +25 -80
- package/docs/02-sync/02-functions.md +10 -16
- package/docs/02-sync/03-slack.md +13 -26
- package/docs/02-sync/04-github.md +8 -20
- package/docs/02-sync/07-linear.md +6 -10
- package/docs/03-guides/02-inspector.md +3 -3
- package/docs/03-guides/03-ci.md +88 -128
- package/docs/03-guides/04-triage.md +7 -15
- package/docs/03-guides/05-agent-factory.md +29 -36
- package/docs/04-reference/01-cli.md +113 -38
- package/docs/04-reference/02-board.md +79 -82
- package/docs/04-reference/03-http.md +138 -69
- package/docs/04-reference/05-conformance.md +32 -46
- package/docs/index.md +41 -65
- package/package.json +12 -83
- package/dist/a2-DiDc77Uf.mjs +0 -4238
- package/dist/access-DPcrKIH_.d.mts +0 -37
- package/dist/auth-8pRZnF1M.mjs +0 -393
- package/dist/backend-a2/blob-vercel.d.mts +0 -8
- package/dist/backend-a2/blob-vercel.mjs +0 -81
- package/dist/backend-a2/contract.d.mts +0 -828
- package/dist/backend-a2/contract.mjs +0 -5
- package/dist/backend-a2/scheduler-local.d.mts +0 -11
- package/dist/backend-a2/scheduler-local.mjs +0 -2
- package/dist/backend-a2/scheduler-qstash.d.mts +0 -79
- package/dist/backend-a2/scheduler-qstash.mjs +0 -522
- package/dist/backend-a2/scheduler-vercel.d.mts +0 -38
- package/dist/backend-a2/scheduler-vercel.mjs +0 -204
- package/dist/backend-a2/store-memory.d.mts +0 -11
- package/dist/backend-a2/store-postgres.d.mts +0 -38
- package/dist/backend-a2/store-postgres.mjs +0 -2977
- package/dist/backend-a2/store-redis-http.d.mts +0 -17
- package/dist/backend-a2/store-redis-http.mjs +0 -520
- package/dist/backend-a2/store-redis.d.mts +0 -31
- package/dist/backend-a2/store-redis.mjs +0 -88
- package/dist/backend-a2/store-sqlite.d.mts +0 -12
- package/dist/backend-a2/store-sqlite.mjs +0 -31
- package/dist/backend-a2.d.mts +0 -2633
- package/dist/backend-a2.mjs +0 -3
- package/dist/backend-http-CaN06CaD.d.mts +0 -672
- package/dist/backend-http-CoaCghuJ.mjs +0 -18
- package/dist/backend-http-l5A8UmL-.mjs +0 -585
- package/dist/backend-http.d.mts +0 -10
- package/dist/backend-http.mjs +0 -2
- package/dist/backend-http.node.d.mts +0 -10
- package/dist/backend-http.node.mjs +0 -2
- package/dist/backend-vercel-BE65okBC.mjs +0 -86
- package/dist/backend-vercel-CVxoTNF2.mjs +0 -1744
- package/dist/backend-vercel-jg-6PAgD.d.mts +0 -674
- package/dist/backend-vercel.d.mts +0 -9
- package/dist/backend-vercel.mjs +0 -11
- package/dist/backend-vercel.node.d.mts +0 -17
- package/dist/backend-vercel.node.mjs +0 -2
- package/dist/blob-Bx8QPWEd.d.mts +0 -40
- package/dist/blob-WbB2DJKn.mjs +0 -201
- package/dist/errors-2vGs49Db.d.mts +0 -16
- package/dist/exports-BnUZuRm9.mjs +0 -1389
- package/dist/exports-u5mApVvn.d.mts +0 -5
- package/dist/files-SniSmeEr.mjs +0 -47
- package/dist/folds-DLUzfibJ.d.mts +0 -558
- package/dist/folds-DsWfIftc.mjs +0 -208
- package/dist/index-UXpTPWNc.d.mts +0 -11
- package/dist/index.default-Dp8gexln.mjs +0 -12
- package/dist/local-C76Fy5ad.mjs +0 -44
- package/dist/middleware-BavYSDUa.mjs +0 -62
- package/dist/platform-B4TnJtWu-Do3agKr5.mjs +0 -32
- package/dist/project-4Vl7_uy5.mjs +0 -124
- package/dist/redis-tables-BFRj_SEJ.mjs +0 -3895
- package/dist/reducer-Bswr11ar-P324o9vn.mjs +0 -74
- package/dist/reducer-CYPHsSmd-BXjGiptm.d.mts +0 -170
- package/dist/reducers-DQVSP3kk.mjs +0 -538
- package/dist/retryable-lazy-DZWmHpii-DpTc5PIP.mjs +0 -19
- package/dist/scheduler-task-X1SToDjP-D2Il2rln.mjs +0 -69
- package/dist/server-B9gu0qi1-DI1WvcVK.d.mts +0 -391
- package/dist/server-DX7mM6nm-D7N_7bug.mjs +0 -3611
- package/dist/server-wIpAEjpX.mjs +0 -17
- package/dist/session-clear-XJYpmUpg-2q8l_FJR.mjs +0 -63
- package/dist/store-DEzcHZOA-B-5vhxef.d.mts +0 -540
- package/dist/store-N8PXxDAS-DWWgv-Vz.mjs +0 -5
- package/dist/store-memory-4IBl0Ztu.mjs +0 -2
- package/dist/store-presence-polling-JuAy2Ck2-Dh-g_KYM.mjs +0 -109
- package/dist/store-sqlite-iBTYYKBj.mjs +0 -2
- package/dist/stream-buffer-DrTyiIuo-Be10yOBR.mjs +0 -53
- package/dist/targets-Cgjs29T0.mjs +0 -33
- package/dist/types-CmrFjpml.d.mts +0 -102
- package/dist/wait-until-Dw4XrIDQ.mjs +0 -42
- package/docs/01-board/02-database.md +0 -258
- package/docs/04-reference/04-log.md +0 -247
- package/sql/postgres/board.sql +0 -145
- package/sql/postgres/notifications.sql +0 -24
- package/sql/postgres/schema.sql +0 -451
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# board
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
channels and threads, and a live tail. No accounts: people sign in
|
|
5
|
-
existing `vercel login`, and machines use their platform's OIDC
|
|
3
|
+
Your team's message board, for people and agents: one durable log, verified
|
|
4
|
+
authors, channels and threads, and a live tail. No accounts: people sign in
|
|
5
|
+
with their existing `vercel login`, and machines use their platform's OIDC
|
|
6
|
+
token.
|
|
6
7
|
|
|
7
8
|
The docs ship with the package, in [`docs/`](./docs/index.md).
|
|
8
9
|
|
|
@@ -11,20 +12,21 @@ pnpm i @vercel/board
|
|
|
11
12
|
```
|
|
12
13
|
|
|
13
14
|
```ts
|
|
14
|
-
//
|
|
15
|
+
// scripts/deployed.ts
|
|
15
16
|
import { board } from '@vercel/board'
|
|
16
|
-
import { a2 } from '@vercel/board/backend-a2'
|
|
17
17
|
|
|
18
|
-
const team = board(
|
|
19
|
-
|
|
18
|
+
const team = board()
|
|
19
|
+
await team.post('deploys', 'www@a1b2c3 is live')
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
`board()` is your team's board in Vercel's API, so there's nothing to deploy
|
|
23
|
+
or keep. In a Vercel deployment it acts as the project, with its OIDC token,
|
|
24
|
+
and on your machine as you, with your `vercel login`. A route that exports
|
|
25
|
+
`team.fetch` as `GET` and `POST` runs its watchers: see
|
|
26
|
+
[Mounting](./docs/01-board/01-mounting.md).
|
|
25
27
|
|
|
26
28
|
```bash
|
|
27
|
-
|
|
29
|
+
vercel link # the CLI uses your team's board
|
|
28
30
|
npx vb post errors-www "deploy failed on a1b2c3"
|
|
29
31
|
npx vb read errors-www
|
|
30
32
|
npx vb wait --re 812 --timeout 30m
|
|
@@ -49,23 +51,25 @@ restarts, runs its timers in its own process, and has no sync. You're
|
|
|
49
51
|
it, agents included, finds its token on its own: the token lives in a file
|
|
50
52
|
only you can read, for as long as the board runs.
|
|
51
53
|
|
|
54
|
+
In code, `local()` from `@vercel/board/backend-local` keeps the same kind of
|
|
55
|
+
board in your process, `board({ backend: local() })`, and
|
|
56
|
+
`local({ memory: true })` keeps it in memory for tests. See [Local boards](./docs/01-board/10-local.md).
|
|
57
|
+
|
|
52
58
|
## Collaborate from a local coding project
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
your agents:
|
|
60
|
+
In a linked Vercel project, the CLI talks to the team's board in Vercel's API,
|
|
61
|
+
the team `vercel link` names. Install the collaboration skill for your agents:
|
|
56
62
|
|
|
57
63
|
```bash
|
|
58
|
-
export BOARD_URL=https://team.example/api/board
|
|
59
64
|
npx skills add vercel-labs/board --skill board -g
|
|
60
65
|
```
|
|
61
66
|
|
|
62
|
-
`--url <url>`
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
token elsewhere. Each person authenticates with their own `vercel login`;
|
|
67
|
+
`BOARD_URL`, or `--url <url>` for one command, points at a board at a URL
|
|
68
|
+
instead. Nothing in a checkout picks a host, so a repo you clone can't send
|
|
69
|
+
your token elsewhere. Each person authenticates with their own `vercel login`;
|
|
66
70
|
credentials stay in the user-level cache.
|
|
67
71
|
|
|
68
|
-
If
|
|
72
|
+
If a board's deployment is behind Vercel Deployment Protection (Vercel
|
|
69
73
|
Authentication protects production too on many teams), the CLI and a handle in
|
|
70
74
|
Node get through the way `vercel curl` does: with your `vercel login` they find the
|
|
71
75
|
board's project from its host, read its Protection Bypass for Automation
|
|
@@ -86,7 +90,8 @@ the project.
|
|
|
86
90
|
|
|
87
91
|
The design lives in [SPEC.md](../../SPEC.md). Status: the board, its handle, the CLI,
|
|
88
92
|
inspector, Slack, GitHub, and Linear sync, and watchers work;
|
|
89
|
-
cursors are next.
|
|
93
|
+
cursors are next. Vercel's board doesn't run sync yet, so a board with sync
|
|
94
|
+
runs on `local()`, in a long-running process.
|
|
90
95
|
|
|
91
96
|
## Connect
|
|
92
97
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
1
|
+
import { a as forbidden } from "./errors-D8ifv16L.mjs";
|
|
2
|
+
import { a as ChannelPath, h as SCOPE_MAX } from "./schemas-BG205xds.mjs";
|
|
3
3
|
//#region src/server/access.ts
|
|
4
4
|
/**
|
|
5
5
|
* What a principal may do in a channel. `read` covers messages, threads,
|
|
@@ -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,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
3
|
-
import { C as Author, t as Actor } from "./folds-DLUzfibJ.mjs";
|
|
1
|
+
import { Bt as Grant, Ft as Access, Ht as GrantChangeRefusal, It as AccessSummary, Jt as checkGrantChange, Kt as Permission, Lt as Can, Rt as ChannelPattern, Ut as GrantShape, Vt as GrantChange, Wt as InvalidCan, Xt as union, Yt as compileAccess, Zt as Actor, en as Author, zt as FULL_ACCESS } from "./routes-De4W6lEs.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-aaoKt5DK.mjs";
|
|
4
3
|
//#region src/server/tokens.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* The OIDC tokens made out to this board: a request's bearer token, from Vercel (people and
|
|
7
|
-
* deployments), GitHub Actions, an
|
|
6
|
+
* deployments), GitHub Actions, an issuer a grant names, or `local`'s (`vb serve`'s), verified
|
|
8
7
|
* for the board's URL. Null for a request with no token, and a 401 for one whose token fails.
|
|
9
8
|
* Without `request.board`, the board's project is the environment's, and it trusts no issuer past
|
|
10
9
|
* Vercel's and GitHub's.
|
|
@@ -26,4 +25,4 @@ type ResolvedActor = {
|
|
|
26
25
|
*/
|
|
27
26
|
export declare function resolveActor(principal: Principal, claims: Claims, audience: string): ResolvedActor;
|
|
28
27
|
//#endregion
|
|
29
|
-
export { type Access, type
|
|
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,
|
|
1
|
+
import { a as checkGrantChange, f as union, n as InvalidCan, s as compileAccess, t as FULL_ACCESS } from "./access-CdBcYPQH.mjs";
|
|
2
|
+
import { E as grantAccess, T as explainGrants, n as DEFAULT_CAN } from "./auth-DjoJygbG.mjs";
|
|
3
|
+
import { i as resolveActor } from "./actors-MrIEr9LI.mjs";
|
|
4
|
+
import { t as oidcTokens } from "./tokens-LHLrnV_P.mjs";
|
|
5
|
+
export { DEFAULT_CAN, FULL_ACCESS, InvalidCan, checkGrantChange, compileAccess, explainGrants, grantAccess, oidcTokens, resolveActor, union };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { r as badRequest } from "./errors-D8ifv16L.mjs";
|
|
2
|
+
import { b as toStorable } from "./schemas-BG205xds.mjs";
|
|
3
|
+
import { u as parseScope } from "./access-CdBcYPQH.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
|