@vercel/board 0.40.0 → 0.41.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 +1 -1
- package/dist/{access-Bl_k_Hpa.mjs → access-C5HaO42b.mjs} +2 -2
- package/dist/access.d.mts +6 -6
- package/dist/access.mjs +5 -5
- package/dist/{actors-yBRWTpt5.mjs → actors-nrOf7Y7z.mjs} +59 -40
- package/dist/{auth-DtmZzlHm.d.mts → auth-Bn8J_1F2.d.mts} +12 -30
- package/dist/{auth-C8URZHLx.mjs → auth-DAlYi6TN.mjs} +9 -19
- package/dist/{backend-BW5NbBsp.d.mts → backend-CYsTLxtP.d.mts} +116 -46
- package/dist/backend-local.d.mts +1 -1
- package/dist/backend-local.mjs +1 -1
- package/dist/{chat-provider-1WKsLEnM.mjs → chat-provider-CPZg2MQb.mjs} +2 -2
- package/dist/{chat-provider-Bbb9JguG.d.mts → chat-provider-Cgkh9xJw.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 +3 -3
- package/dist/cli-embedded.mjs +4 -4
- package/dist/cli.mjs +8 -13
- package/dist/{commands-BJLocuXj.d.mts → commands-CrEVjASe.d.mts} +8 -30
- package/dist/{commands-D6VWegVY.mjs → commands-QRD0U9AQ.mjs} +30 -101
- package/dist/{conformance-BWhZ0k8T.mjs → conformance-ClxEEZ9C.mjs} +139 -109
- package/dist/conformance.d.mts +9 -8
- package/dist/conformance.mjs +1 -1
- package/dist/digest-Dna1CGa_.mjs +4 -0
- package/dist/{engine-Djif8XVk.mjs → engine-8BcNeckB.mjs} +11 -12
- package/dist/{errors-CNRJqUuL.mjs → errors-DcQf5WeM.mjs} +109 -30
- package/dist/{events-C6HwB046.mjs → events-BT8y_81j.mjs} +2 -2
- package/dist/{exports-C2OWIbLU.mjs → exports-B6udRV_E.mjs} +363 -161
- package/dist/exports-C8zsIL1A.d.mts +4 -0
- package/dist/{external-CHDxWIVf.mjs → external-DymyhUzl.mjs} +1 -1
- package/dist/{index-Cuxbz_E0.d.mts → index-fcpEFCTR.d.mts} +2 -2
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +6 -5
- package/dist/index.node.d.mts +6 -6
- package/dist/index.node.mjs +3 -3
- package/dist/inspect/app.js +31 -31
- package/dist/inspect/engine.js +2 -2
- package/dist/inspect-BsF3mYMY.mjs +2 -0
- package/dist/{inspect-cGcP8ZO9.mjs → inspect-DPRoC_Gg.mjs} +6 -6
- package/dist/{local-CsleYuyM.mjs → local-B9y4p6N7.mjs} +113 -358
- package/dist/{main-D97xuqWZ.mjs → main-S0A-c_kP.mjs} +392 -139
- package/dist/{memory-BvVoglGv.mjs → memory-DhduVbUu.mjs} +2 -2
- package/dist/{mentions-CT2bN5eP.mjs → mentions-DfZGp3B-.mjs} +1 -1
- package/dist/{middleware-BF9vnPPS.mjs → middleware-DHdrxmoc.mjs} +2 -2
- package/dist/{origin-DLCmrwmE.mjs → origin-B3m2lnZC.mjs} +7 -36
- package/dist/{page-6BTCZWGY.mjs → page-2jjHZmIW.mjs} +2 -2
- package/dist/page-CAUe4GmQ.mjs +2 -0
- package/dist/{provider-YqkF1E2k.d.mts → provider-dY54GFNz.d.mts} +1 -25
- package/dist/{routes-CAjd5ARa.d.mts → routes-By9lmvUD.d.mts} +1 -63
- package/dist/{schemas-AZkxk06N.mjs → schemas-DAzSsgWk.mjs} +8 -3
- package/dist/{serve-Cs-e0Jke.mjs → serve-B15I2Ibf.mjs} +5 -5
- package/dist/{server-CIfMdIt3.mjs → server-DgpRZ4Nu.mjs} +74 -127
- package/dist/{serving-B4l0nLng.mjs → serving-CALKWs9K.mjs} +1 -1
- package/dist/{sql-Bv-RQu8n.mjs → sql-P9g-rLIF.mjs} +3 -3
- package/dist/{sqlite-D4mkYihG.mjs → sqlite-B3rCcIof.mjs} +2 -2
- package/dist/{sqlite-db-BraLvHtf.mjs → sqlite-db-D0Fyju-4.mjs} +1 -1
- 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/{tokens-CrrXAVGz.mjs → tokens-D7_ZIWpX.mjs} +4 -4
- package/docs/01-board/01-mounting.md +12 -17
- package/docs/01-board/03-identity.md +45 -39
- package/docs/01-board/04-messages.md +3 -1
- package/docs/01-board/05-reading.md +8 -2
- package/docs/01-board/06-watchers.md +15 -10
- package/docs/01-board/07-schedules.md +6 -2
- package/docs/01-board/09-access.md +56 -111
- package/docs/02-sync/01-overview.md +5 -2
- package/docs/02-sync/03-slack.md +12 -12
- package/docs/03-guides/01-coding-agents.md +18 -22
- package/docs/03-guides/02-inspector.md +4 -5
- package/docs/03-guides/03-ci.md +7 -26
- package/docs/03-guides/04-triage.md +2 -2
- package/docs/03-guides/05-agent-factory.md +7 -9
- package/docs/03-guides/06-sandboxed-agents.md +149 -0
- package/docs/04-reference/01-cli.md +52 -87
- package/docs/04-reference/02-board.md +35 -36
- package/docs/04-reference/03-http.md +32 -53
- package/docs/04-reference/05-conformance.md +37 -18
- package/docs/index.md +4 -4
- package/package.json +1 -1
- package/dist/digest-D32GV_mX.mjs +0 -4
- package/dist/exports-FyRBIAMs.d.mts +0 -4
- package/dist/inspect-CLy6FrOZ.mjs +0 -2
- package/dist/page-BnY8FhPn.mjs +0 -2
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { a as forbidden, c as toErrorResponse, d as createBoardClient, f as duration,
|
|
2
|
-
import { h as RemoteWatcherId } from "./schemas-
|
|
1
|
+
import { _ as IMPORT_BYTES_MAX, a as forbidden, b as mediaType, c as toErrorResponse, d as createBoardClient, f as duration, h as ATTACHMENT_BYTES_MAX, l as unauthorized, n as RejectedError, o as json, p as formatProfileHeader, r as badRequest, s as notFound, t as HttpError, u as BoardError, v as fileName } from "./errors-DcQf5WeM.mjs";
|
|
2
|
+
import { h as RemoteWatcherId } from "./schemas-DAzSsgWk.mjs";
|
|
3
3
|
import { f as schemaId, n as blocksIn, r as findBlocks } from "./blocks-CVoBC7ur.mjs";
|
|
4
|
-
import { A as MessagesQuery, B as SyncBody, C as InboxAckBody, D as LabelBody, E as InboxQuery, F as ScheduleBody, G as ThreadsQuery, H as SyncFindQuery, I as SchedulesQuery, J as
|
|
5
|
-
import { _ as sha256, a as waitUntil, c as platformProfile, d as userIdOf, m as derivedId, o as actorParts, r as runMiddleware, s as importedHandle, t as DroppedError, u as underPrincipal } from "./middleware-
|
|
6
|
-
import { a as canText, c as compileAccess, d as parsePattern, r as PERMISSIONS, u as parseCan } from "./access-
|
|
7
|
-
import {
|
|
8
|
-
import { a as
|
|
4
|
+
import { A as MessagesQuery, B as SyncBody, C as InboxAckBody, D as LabelBody, E as InboxQuery, F as ScheduleBody, G as ThreadsQuery, H as SyncFindQuery, I as SchedulesQuery, J as UploadStartBody, K as TypingBody, L as SchemaBody, M as ReactBody, N as Ref, O as LinkedQuery, P as RegisterBody, R as SourceJoinBody, S as GrantBody, T as InboxPushBody, U as SyncImportBody, V as SyncCopiesQuery, W as SyncReceiptBody, Y as routes, _ as CreateChannelBody, a as compileWatcher, b as EventsQuery, c as METHODS, d as queryObject, f as readCapped, g as AckBody, h as VERSION, i as runMatch, j as PostBody, k as MatchesQuery, l as createRouter, m as SYNC, n as syncTarget, p as readJson, q as UpdateGrantBody, r as canonicalWatchers, t as SYNC_ACTOR, u as openapi, v as DeleteBody, w as InboxNextQuery, x as ExplainQuery, y as EditBody, z as SourceReadQuery } from "./origin-B3m2lnZC.mjs";
|
|
5
|
+
import { _ as sha256, a as waitUntil, c as platformProfile, d as userIdOf, m as derivedId, o as actorParts, r as runMiddleware, s as importedHandle, t as DroppedError, u as underPrincipal } from "./middleware-DHdrxmoc.mjs";
|
|
6
|
+
import { a as canText, c as compileAccess, d as parsePattern, n as InvalidCan, r as PERMISSIONS, u as parseCan } from "./access-C5HaO42b.mjs";
|
|
7
|
+
import { C as explainGrants, b as verifiesTokens, d as grantIssuers, f as hostPrincipal, i as VERCEL_ISSUER, l as createAuthority, t as DEFAULT_CAN$1, u as fromTokens, y as verifiedIssuers } from "./auth-DAlYi6TN.mjs";
|
|
8
|
+
import { a as resolveActor, o as viaOf, r as claimsOf, t as KNOWN_AGENTS } from "./actors-nrOf7Y7z.mjs";
|
|
9
9
|
import { t as checkValue } from "./data-values-C-Cq80hz.mjs";
|
|
10
10
|
//#region src/server/registrant.ts
|
|
11
11
|
/** Registering again this soon after the same registration only repeats it. */
|
|
@@ -248,7 +248,7 @@ function tailWatchers(options) {
|
|
|
248
248
|
}
|
|
249
249
|
after = page.cursor;
|
|
250
250
|
for (const event of page.events) {
|
|
251
|
-
if (event.actor?.id === own) continue;
|
|
251
|
+
if (event.actor?.id === own && !(event.type === "message.posted" && event.message?.schedule)) continue;
|
|
252
252
|
const thread = event.message?.thread ?? "";
|
|
253
253
|
const match = {
|
|
254
254
|
id: `${boot}:${matched++}`,
|
|
@@ -306,9 +306,251 @@ const sleep = (ms, signal) => new Promise((resolve) => {
|
|
|
306
306
|
signal.addEventListener("abort", () => (clearTimeout(timer), resolve()), { once: true });
|
|
307
307
|
});
|
|
308
308
|
//#endregion
|
|
309
|
+
//#region src/server/sandbox.ts
|
|
310
|
+
/** Outside Node there's no deployment credential to find: a sandbox's policy needs the one it's given. */
|
|
311
|
+
const withoutToken = (url) => {
|
|
312
|
+
throw new HttpError(400, "no_token", `There's no credential here to hand a sandbox for ${url}: pass one, sandboxPolicy({ token }).`, { origin: "handle" });
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* `x-board-can` for `can`, read here as the board reads it, so a bad one fails before the sandbox
|
|
316
|
+
* does: any `Can` (`'all'`, a list for every channel, a map from pattern to grant, a grant's `'none'`
|
|
317
|
+
* included), or a header's own text (`dev/=read,post`).
|
|
318
|
+
*/
|
|
319
|
+
function canHeader(can) {
|
|
320
|
+
if (typeof can === "string" && can !== "all") {
|
|
321
|
+
parseCan(can);
|
|
322
|
+
return can;
|
|
323
|
+
}
|
|
324
|
+
const given = can === void 0 ? DEFAULT_CAN$1 : can === "all" || Array.isArray(can) ? can : Object.fromEntries(Object.entries(can).map(([pattern, grant]) => [pattern, grant === "none" ? [] : grant]));
|
|
325
|
+
return canText(compileAccess(given));
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Routes under a board that the policy never adds the credential to: what hands out what outreaches
|
|
329
|
+
* the policy (a grant, a watcher's registration, sync's records and a platform's events), and what a
|
|
330
|
+
* platform or the board's own deployments call (webhooks, wake-ups), where the credential could speak
|
|
331
|
+
* for them.
|
|
332
|
+
*/
|
|
333
|
+
const WITHHELD = [
|
|
334
|
+
"grants",
|
|
335
|
+
"watchers",
|
|
336
|
+
"wake",
|
|
337
|
+
"webhooks",
|
|
338
|
+
"sync",
|
|
339
|
+
"inbox",
|
|
340
|
+
"sources"
|
|
341
|
+
];
|
|
342
|
+
const escaped = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
343
|
+
/** `value` in any case, as a router that ignores case reads it: a regular expression without flags, as RE2 and JavaScript both take it. */
|
|
344
|
+
const caseless = (value) => [...value].map((char) => /[a-z]/i.test(char) ? `[${char.toLowerCase()}${char.toUpperCase()}]` : escaped(char)).join("");
|
|
345
|
+
/** A path segment, percent-encoded as clients write them; the first rule refuses a dot segment and an encoded slash or dot. */
|
|
346
|
+
const SEGMENT = "(?:[A-Za-z0-9_.@~:+=,!$&'*-]|%[0-9A-Fa-f]{2})+";
|
|
347
|
+
/**
|
|
348
|
+
* The protocol's routes a sandbox reaches: every route but those under a withheld segment. Each is
|
|
349
|
+
* named whole, because a board mounted without a `basePath` matches a route as the end of a path, and
|
|
350
|
+
* `/api/board/x/grants` would be its `/grants` under `/api/board/x`.
|
|
351
|
+
*/
|
|
352
|
+
const PROTOCOL_ROUTES = Object.values(routes).filter(({ path }) => !WITHHELD.includes(path.split("/").filter(Boolean)[0] ?? "")).map(({ method, path }) => ({
|
|
353
|
+
method,
|
|
354
|
+
path: path === "/" ? "" : path
|
|
355
|
+
}));
|
|
356
|
+
/** `routes`' rules: one a method, its paths' shapes in one expression after `prefix`. */
|
|
357
|
+
function routeRules(prefix, routes, scoped, transform) {
|
|
358
|
+
const byMethod = /* @__PURE__ */ new Map();
|
|
359
|
+
for (const { method, path } of routes) {
|
|
360
|
+
const shape = path.split("/").filter(Boolean).map((part) => part.startsWith(":") ? `/${SEGMENT}` : `/${escaped(part)}`).join("");
|
|
361
|
+
byMethod.set(method, [...byMethod.get(method) ?? [], shape]);
|
|
362
|
+
}
|
|
363
|
+
return [...byMethod].map(([method, shapes]) => ({
|
|
364
|
+
match: scoped({
|
|
365
|
+
method: [method],
|
|
366
|
+
path: { regex: `^${prefix}(?:${shapes.join("|")})/?$` }
|
|
367
|
+
}),
|
|
368
|
+
transform
|
|
369
|
+
}));
|
|
370
|
+
}
|
|
371
|
+
const refused = (why) => ({ response: {
|
|
372
|
+
statusCode: 403,
|
|
373
|
+
body: JSON.stringify({ error: {
|
|
374
|
+
code: "forbidden",
|
|
375
|
+
message: why
|
|
376
|
+
} }),
|
|
377
|
+
contentType: "application/json"
|
|
378
|
+
} });
|
|
379
|
+
/**
|
|
380
|
+
* The policy that hands the board `reach` names to a sandbox: its host, and on it only the board's
|
|
381
|
+
* own routes, under its URL's path and with its query (`teamId`), each request carrying `reach`'s
|
|
382
|
+
* headers. Anything else on the host is refused there; any other host, the sandbox doesn't reach.
|
|
383
|
+
*/
|
|
384
|
+
function boardPolicy(reach) {
|
|
385
|
+
const url = new URL(reach.url);
|
|
386
|
+
const prefix = escaped(url.pathname.replace(/\/+$/, ""));
|
|
387
|
+
const query = [...url.searchParams].map(([key, value]) => ({
|
|
388
|
+
key: { exact: key },
|
|
389
|
+
value: { exact: value }
|
|
390
|
+
}));
|
|
391
|
+
const scoped = (match) => query.length > 0 ? {
|
|
392
|
+
...match,
|
|
393
|
+
queryString: query
|
|
394
|
+
} : match;
|
|
395
|
+
const transform = [{ headers: { ...reach.headers } }];
|
|
396
|
+
return { allow: { [url.host]: [
|
|
397
|
+
{
|
|
398
|
+
match: { path: { regex: "(?:^|/)\\.\\.?(?:/|$)|%2[eEfF]|%5[cC]|\\\\" } },
|
|
399
|
+
...refused("not a board route")
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
match: { queryString: [{ key: { regex: `^${caseless("x-vercel-set-bypass-cookie")}$` } }] },
|
|
403
|
+
...refused("not a board route")
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
match: { headers: [{ key: { exact: "x-vercel-set-bypass-cookie" } }] },
|
|
407
|
+
...refused("not a board route")
|
|
408
|
+
},
|
|
409
|
+
...routeRules(prefix, reach.routes, scoped, transform),
|
|
410
|
+
...(reach.reads ?? []).map((path) => ({
|
|
411
|
+
match: scoped({
|
|
412
|
+
path: { exact: path },
|
|
413
|
+
method: ["GET"]
|
|
414
|
+
}),
|
|
415
|
+
transform
|
|
416
|
+
})),
|
|
417
|
+
{
|
|
418
|
+
match: { path: { regex: `^${prefix}/(?:${WITHHELD.map(caseless).join("|")})(?:/|$)` } },
|
|
419
|
+
...refused("not a route this sandbox's policy hands it")
|
|
420
|
+
},
|
|
421
|
+
refused("not this board's")
|
|
422
|
+
] } };
|
|
423
|
+
}
|
|
424
|
+
//#endregion
|
|
309
425
|
//#region src/server/backend-vercel.ts
|
|
310
426
|
const PROFILE = /^[A-Za-z][A-Za-z0-9-]{0,31}$/;
|
|
311
|
-
|
|
427
|
+
/**
|
|
428
|
+
* What `vb` on this board calls in Vercel's API for what a sandboxed agent does, by method and path
|
|
429
|
+
* under `/boards/<id>`: reading, posting and replying, editing and deleting its own, reacting and
|
|
430
|
+
* labeling, files, schedules, and finding a platform link's message. A sandbox's policy hands it these
|
|
431
|
+
* and nothing else under the board: not the board itself (`PATCH`, `DELETE`), its members, its
|
|
432
|
+
* grants, watchers, or sync's records, nor a route the API adds later.
|
|
433
|
+
*/
|
|
434
|
+
const SANDBOX_ROUTES = [
|
|
435
|
+
{
|
|
436
|
+
method: "GET",
|
|
437
|
+
path: ""
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
method: "GET",
|
|
441
|
+
path: "/me"
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
method: "GET",
|
|
445
|
+
path: "/channels"
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
method: "POST",
|
|
449
|
+
path: "/channels"
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
method: "GET",
|
|
453
|
+
path: "/actors"
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
method: "GET",
|
|
457
|
+
path: "/messages"
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
method: "GET",
|
|
461
|
+
path: "/messages/:id"
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
method: "GET",
|
|
465
|
+
path: "/messages/:id/synced"
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
method: "GET",
|
|
469
|
+
path: "/changes"
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
method: "GET",
|
|
473
|
+
path: "/threads"
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
method: "POST",
|
|
477
|
+
path: "/threads"
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
method: "GET",
|
|
481
|
+
path: "/threads/:thread/messages"
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
method: "POST",
|
|
485
|
+
path: "/threads/:thread/messages"
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
method: "PATCH",
|
|
489
|
+
path: "/threads/:thread/messages/:n"
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
method: "POST",
|
|
493
|
+
path: "/threads/:thread/messages/:n/delete"
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
method: "GET",
|
|
497
|
+
path: "/threads/:thread/messages/:n/reactions"
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
method: "POST",
|
|
501
|
+
path: "/threads/:thread/messages/:n/reactions"
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
method: "POST",
|
|
505
|
+
path: "/threads/:thread/messages/:n/labels"
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
method: "GET",
|
|
509
|
+
path: "/posts/:id"
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
method: "POST",
|
|
513
|
+
path: "/attachments"
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
method: "GET",
|
|
517
|
+
path: "/attachments/:id"
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
method: "POST",
|
|
521
|
+
path: "/attachments/:id/complete"
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
method: "GET",
|
|
525
|
+
path: "/schedules"
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
method: "POST",
|
|
529
|
+
path: "/schedules"
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
method: "POST",
|
|
533
|
+
path: "/schedules/:id/cancel"
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
method: "GET",
|
|
537
|
+
path: "/sync/linked"
|
|
538
|
+
}
|
|
539
|
+
];
|
|
540
|
+
/**
|
|
541
|
+
* Who a request to Vercel's API writes as, as the API reads it today: the profile's name alone in
|
|
542
|
+
* `x-board-profile`, and its avatar in `x-board-avatar`, which board's protocol refuses for the
|
|
543
|
+
* avatar parameter of `x-board-profile` (`formatProfileHeader`). Every request and sandbox policy
|
|
544
|
+
* for the API gets its profile from here, so this is the one place that changes once the API reads
|
|
545
|
+
* the profile header as the protocol has it.
|
|
546
|
+
*/
|
|
547
|
+
function apiProfileHeaders(profile) {
|
|
548
|
+
if (!profile) return {};
|
|
549
|
+
return {
|
|
550
|
+
"x-board-profile": profile.name,
|
|
551
|
+
...profile.avatar?.startsWith("https://") ? { "x-board-avatar": profile.avatar } : {}
|
|
552
|
+
};
|
|
553
|
+
}
|
|
312
554
|
const CLIENT_ID = /^[A-Za-z0-9_.:-]{1,128}$/;
|
|
313
555
|
const MESSAGE_ID = /^msg_([0-9a-f-]{36})_([1-9]\d*)$/;
|
|
314
556
|
/** Whether `value` is a message ID Vercel's API hands out (`msg_<thread>_<n>`): the CLI takes one as a message, even where a channel has its name. */
|
|
@@ -435,12 +677,6 @@ const grantFrom = (grant) => ({
|
|
|
435
677
|
...grant,
|
|
436
678
|
at: expiryOf(grant.at)
|
|
437
679
|
});
|
|
438
|
-
/** A token as the API answers it, its times in milliseconds, as the protocol has them. */
|
|
439
|
-
const tokenFrom = (token) => ({
|
|
440
|
-
...token,
|
|
441
|
-
at: expiryOf(token.at) ?? token.at,
|
|
442
|
-
expiresAt: expiryOf(token.expiresAt) ?? token.expiresAt
|
|
443
|
-
});
|
|
444
680
|
/** A schema the API keeps, as the protocol shows it. */
|
|
445
681
|
const schemaFrom = (schema) => ({
|
|
446
682
|
id: schema.id,
|
|
@@ -583,15 +819,13 @@ const shortName = (principal) => principal.type === "user" ? `user-${principal.u
|
|
|
583
819
|
const authorOf = (actor) => ({
|
|
584
820
|
actor: actor.id,
|
|
585
821
|
principal: principalId(actor.principal),
|
|
586
|
-
profile: actor.profile?.name ?? null
|
|
587
|
-
session: actor.session ?? null
|
|
822
|
+
profile: actor.profile?.name ?? null
|
|
588
823
|
});
|
|
589
824
|
/** Who cancels a schedule when no one did: the API, once its creator can no longer post it, as a local board's scheduler. */
|
|
590
825
|
const SCHEDULER = {
|
|
591
826
|
actor: "board:schedule",
|
|
592
827
|
principal: "board:schedule",
|
|
593
|
-
profile: null
|
|
594
|
-
session: null
|
|
828
|
+
profile: null
|
|
595
829
|
};
|
|
596
830
|
/**
|
|
597
831
|
* An actor where the API doesn't name them: its handle is its profile, or a short form of its
|
|
@@ -699,10 +933,10 @@ function createVercel(options, environment) {
|
|
|
699
933
|
if (typeof value === "string") url.searchParams.set(name, value);
|
|
700
934
|
else for (const one of value) url.searchParams.append(name, one);
|
|
701
935
|
}
|
|
702
|
-
const headers = {
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
936
|
+
const headers = {
|
|
937
|
+
"content-type": "application/json",
|
|
938
|
+
...apiProfileHeaders(who.profile)
|
|
939
|
+
};
|
|
706
940
|
const repeatable = method !== "POST" && method !== "PATCH" || typeof init.body?.operationId === "string";
|
|
707
941
|
for (let attempt = 0;; attempt++) {
|
|
708
942
|
let response;
|
|
@@ -730,10 +964,6 @@ function createVercel(options, environment) {
|
|
|
730
964
|
continue;
|
|
731
965
|
}
|
|
732
966
|
const error = body?.error;
|
|
733
|
-
if (error?.code === "board_token_scope") throw new HttpError(403, "board_token_scope", "a board token reaches only its own board, by its ID.", {
|
|
734
|
-
hint: "Name its board by URL or ID: BOARD_URL, --url, or vercel({ board }).",
|
|
735
|
-
origin: "handle"
|
|
736
|
-
});
|
|
737
967
|
throw new HttpError(response.status, error?.code ?? "remote_error", error?.message ?? `Vercel's API answered ${response.status}`);
|
|
738
968
|
}
|
|
739
969
|
}
|
|
@@ -1094,8 +1324,7 @@ function createVercel(options, environment) {
|
|
|
1094
1324
|
const by = {
|
|
1095
1325
|
id: await actorOf(who),
|
|
1096
1326
|
principal: actor.principal,
|
|
1097
|
-
...who.profile ? { profile: who.profile } : {}
|
|
1098
|
-
...who.session ? { session: who.session } : {}
|
|
1327
|
+
...who.profile ? { profile: who.profile } : {}
|
|
1099
1328
|
};
|
|
1100
1329
|
const attachments = (await Promise.all((input.attachments ?? []).map(async (id) => api(who, "GET", await onBoard(who, `/attachments/${encodeURIComponent(id)}`)).then(({ attachment }) => fileOf(attachment), () => null)))).filter((file) => file !== null);
|
|
1101
1330
|
return {
|
|
@@ -1291,7 +1520,7 @@ function createVercel(options, environment) {
|
|
|
1291
1520
|
});
|
|
1292
1521
|
/** The actor `who` writes as: the credentials' principal, and its profile, as the API names it. */
|
|
1293
1522
|
const actorOf = async (who) => `${principalId((await self(who)).actor.principal)}${who.profile ? `+${who.profile.name.toLowerCase()}` : ""}`;
|
|
1294
|
-
/** Who a caller acts as there: its profile
|
|
1523
|
+
/** Who a caller acts as there: its profile, beside this deployment's credentials. */
|
|
1295
1524
|
function whoOf(caller) {
|
|
1296
1525
|
if ("identity" in caller) throw servesNone();
|
|
1297
1526
|
const named = (profile) => {
|
|
@@ -1305,23 +1534,9 @@ function createVercel(options, environment) {
|
|
|
1305
1534
|
};
|
|
1306
1535
|
if (caller.origin.via?.kind === "client") {
|
|
1307
1536
|
const asked = "profile" in caller ? caller.profile : caller.self ?? void 0;
|
|
1308
|
-
|
|
1309
|
-
profile: null,
|
|
1310
|
-
session: null
|
|
1311
|
-
};
|
|
1312
|
-
if (asked === void 0) return {
|
|
1313
|
-
profile: named(found.profile),
|
|
1314
|
-
session: found.session
|
|
1315
|
-
};
|
|
1316
|
-
return {
|
|
1317
|
-
profile: named(asked),
|
|
1318
|
-
session: asked === null ? null : found.session
|
|
1319
|
-
};
|
|
1537
|
+
return { profile: named(asked === void 0 ? environment?.profile() ?? null : asked) };
|
|
1320
1538
|
}
|
|
1321
|
-
return {
|
|
1322
|
-
profile: named(caller.self ?? "client"),
|
|
1323
|
-
session: null
|
|
1324
|
-
};
|
|
1539
|
+
return { profile: named(caller.self ?? "client") };
|
|
1325
1540
|
}
|
|
1326
1541
|
/** A post's client ID, as the API takes one: its own when it fits, a hash of it when it doesn't. */
|
|
1327
1542
|
const clientIdOf = async (id) => CLIENT_ID.test(id) ? id : `h.${(await sha256(id)).slice(0, 64)}`;
|
|
@@ -1800,12 +2015,11 @@ function createVercel(options, environment) {
|
|
|
1800
2015
|
...found.branch ? { branch: found.branch } : {}
|
|
1801
2016
|
} : { url: null };
|
|
1802
2017
|
/**
|
|
1803
|
-
* Vercel's API takes watchers only from a deployment's own credentials: never a person's
|
|
1804
|
-
*
|
|
1805
|
-
* `watchers_need_project`.
|
|
2018
|
+
* Vercel's API takes watchers only from a deployment's own credentials: never a person's or an
|
|
2019
|
+
* app's. Anyone else's registration, pull, or ack is its 403 `watchers_need_project`.
|
|
1806
2020
|
*/
|
|
1807
2021
|
const notADeployment = () => new HttpError(403, "watchers_need_project", "Vercel's API takes watchers only from a deployment's own credentials.", {
|
|
1808
|
-
hint: "Register them from the project's deployment
|
|
2022
|
+
hint: "Register them from the project's deployment. Watchers in board()'s config run in this process instead.",
|
|
1809
2023
|
origin: "handle"
|
|
1810
2024
|
});
|
|
1811
2025
|
const needsProject = (error) => error instanceof HttpError && error.code === "watchers_need_project" ? notADeployment() : error;
|
|
@@ -1960,10 +2174,7 @@ function createVercel(options, environment) {
|
|
|
1960
2174
|
} });
|
|
1961
2175
|
}
|
|
1962
2176
|
/** This deployment's own: what its config's watchers run as. */
|
|
1963
|
-
const deployment = {
|
|
1964
|
-
profile: null,
|
|
1965
|
-
session: null
|
|
1966
|
-
};
|
|
2177
|
+
const deployment = { profile: null };
|
|
1967
2178
|
/** This board's config's watchers, which run here when the API wakes it. */
|
|
1968
2179
|
let tails = {};
|
|
1969
2180
|
const bound = () => {
|
|
@@ -1973,14 +2184,7 @@ function createVercel(options, environment) {
|
|
|
1973
2184
|
const runner = registrant({
|
|
1974
2185
|
remote: "Vercel's API",
|
|
1975
2186
|
registry: {
|
|
1976
|
-
register: (where) => registerAs(deployment, where, tails, bound().sync, true, holding)
|
|
1977
|
-
if (error instanceof HttpError && error.code === "watchers_need_project") {
|
|
1978
|
-
refused = true;
|
|
1979
|
-
runner.close();
|
|
1980
|
-
runHere();
|
|
1981
|
-
}
|
|
1982
|
-
throw error;
|
|
1983
|
-
}),
|
|
2187
|
+
register: (where) => registerAs(deployment, where, tails, bound().sync, true, holding),
|
|
1984
2188
|
matches: ({ signal, ...query }) => pullAs(deployment, query, signal, tails),
|
|
1985
2189
|
ack: (id, body) => ackAs(deployment, id, body)
|
|
1986
2190
|
},
|
|
@@ -1994,19 +2198,11 @@ function createVercel(options, environment) {
|
|
|
1994
2198
|
registerFor: async (caller, request) => json(await methods.register(caller, RegisterBody.parse(await request.json()), request.signal))
|
|
1995
2199
|
});
|
|
1996
2200
|
let deployed = null;
|
|
1997
|
-
/** Whether
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
*/
|
|
2003
|
-
const isDeployment = async () => {
|
|
2004
|
-
if (refused || !options.fetch && environment?.boardToken()) return false;
|
|
2005
|
-
return (deployed ??= self(deployment).then((found) => found.actor.principal.type === "project")).catch((error) => {
|
|
2006
|
-
deployed = null;
|
|
2007
|
-
throw error;
|
|
2008
|
-
});
|
|
2009
|
-
};
|
|
2201
|
+
/** Whether this board's own credentials are a deployment's own: a project's. */
|
|
2202
|
+
const isDeployment = () => (deployed ??= self(deployment).then((found) => found.actor.principal.type === "project")).catch((error) => {
|
|
2203
|
+
deployed = null;
|
|
2204
|
+
throw error;
|
|
2205
|
+
});
|
|
2010
2206
|
let here = null;
|
|
2011
2207
|
let deployedElse = false;
|
|
2012
2208
|
/** Anyone else's watchers run in this process, as tails: nothing wakes a person. */
|
|
@@ -2014,7 +2210,7 @@ function createVercel(options, environment) {
|
|
|
2014
2210
|
if (here || deployedElse) return;
|
|
2015
2211
|
if (deployedOnVercel()) {
|
|
2016
2212
|
deployedElse = true;
|
|
2017
|
-
console.error("[board] watchers on a deployment need its own OIDC token: with
|
|
2213
|
+
console.error("[board] watchers on a deployment need its own OIDC token: with another Vercel token, none run here");
|
|
2018
2214
|
return;
|
|
2019
2215
|
}
|
|
2020
2216
|
const { sync, run } = bound();
|
|
@@ -2028,10 +2224,7 @@ function createVercel(options, environment) {
|
|
|
2028
2224
|
here = tailWatchers({
|
|
2029
2225
|
watchers,
|
|
2030
2226
|
events: (query, signal) => eventsAs(deployment, query, signal),
|
|
2031
|
-
actorOf: (id) => actorOf({
|
|
2032
|
-
profile: { name: id },
|
|
2033
|
-
session: null
|
|
2034
|
-
}),
|
|
2227
|
+
actorOf: (id) => actorOf({ profile: { name: id } }),
|
|
2035
2228
|
run
|
|
2036
2229
|
});
|
|
2037
2230
|
here.start();
|
|
@@ -2148,23 +2341,12 @@ function createVercel(options, environment) {
|
|
|
2148
2341
|
});
|
|
2149
2342
|
throw error;
|
|
2150
2343
|
};
|
|
2151
|
-
/** A mint Vercel's API won't make: only a deployment mints board tokens there, and a board token mints from itself. */
|
|
2152
|
-
const mintRefused = (error) => {
|
|
2153
|
-
if (error instanceof HttpError && error.code === "unsupported_principal") throw new HttpError(403, "unsupported_principal", "Vercel's board mints board tokens only for a deployment.", {
|
|
2154
|
-
hint: "Mint it from a deployment, with its OIDC token, or from a board token.",
|
|
2155
|
-
origin: "handle"
|
|
2156
|
-
});
|
|
2157
|
-
throw error;
|
|
2158
|
-
};
|
|
2159
2344
|
const methods = {
|
|
2160
2345
|
...Object.fromEntries(METHODS.map((method) => [method, async () => {
|
|
2161
2346
|
throw notSupported(method === "register" || method === "watchers" || method === "matches" || method === "ack" ? "watchers" : method);
|
|
2162
2347
|
}])),
|
|
2163
2348
|
async discovery() {
|
|
2164
|
-
const who = {
|
|
2165
|
-
profile: null,
|
|
2166
|
-
session: null
|
|
2167
|
-
};
|
|
2349
|
+
const who = { profile: null };
|
|
2168
2350
|
const team = await teamId();
|
|
2169
2351
|
if (options.board) await api(who, "GET", await onBoard(who));
|
|
2170
2352
|
const id = team?.startsWith("team_") ? team : (await self(who)).teamId;
|
|
@@ -2207,7 +2389,6 @@ function createVercel(options, environment) {
|
|
|
2207
2389
|
avatar: shown.avatar,
|
|
2208
2390
|
profile: found.actor.profile?.name ?? null,
|
|
2209
2391
|
...via,
|
|
2210
|
-
session: found.actor.session ?? null,
|
|
2211
2392
|
expiresAt: expiryOf(found.expiresAt),
|
|
2212
2393
|
can: canOf(found.can)
|
|
2213
2394
|
};
|
|
@@ -2599,31 +2780,6 @@ function createVercel(options, environment) {
|
|
|
2599
2780
|
...signal ? { signal } : {}
|
|
2600
2781
|
});
|
|
2601
2782
|
},
|
|
2602
|
-
async tokens(caller, _input, signal) {
|
|
2603
|
-
const who = whoOf(caller);
|
|
2604
|
-
return { tokens: (await all(who, await onBoard(who, "/tokens"), "tokens", {}, signal)).map(tokenFrom) };
|
|
2605
|
-
},
|
|
2606
|
-
async createToken(caller, input, signal) {
|
|
2607
|
-
const who = whoOf(caller);
|
|
2608
|
-
const created = await api(who, "POST", await onBoard(who, "/tokens"), {
|
|
2609
|
-
body: {
|
|
2610
|
-
operationId: operationId(),
|
|
2611
|
-
...input
|
|
2612
|
-
},
|
|
2613
|
-
...signal ? { signal } : {}
|
|
2614
|
-
}).catch(mintRefused);
|
|
2615
|
-
return {
|
|
2616
|
-
...created,
|
|
2617
|
-
token: tokenFrom(created.token)
|
|
2618
|
-
};
|
|
2619
|
-
},
|
|
2620
|
-
async revokeToken(caller, { id }, signal) {
|
|
2621
|
-
const who = whoOf(caller);
|
|
2622
|
-
return api(who, "POST", await onBoard(who, `/tokens/${encodeURIComponent(id)}/revoke`), {
|
|
2623
|
-
body: { operationId: operationId() },
|
|
2624
|
-
...signal ? { signal } : {}
|
|
2625
|
-
});
|
|
2626
|
-
},
|
|
2627
2783
|
async schemas(caller, _input, signal) {
|
|
2628
2784
|
const schemas = (await all(whoOf(caller), "/schemas", "schemas", {}, signal)).map(schemaFrom);
|
|
2629
2785
|
const order = (schema) => schema.builtIn ? 0 : 1;
|
|
@@ -2916,6 +3072,28 @@ function createVercel(options, environment) {
|
|
|
2916
3072
|
}])),
|
|
2917
3073
|
routes,
|
|
2918
3074
|
keeps: false,
|
|
3075
|
+
/**
|
|
3076
|
+
* A sandbox's way to this board in Vercel's API: its routes, by its ID and team, and `/me`, which a
|
|
3077
|
+
* handle on it asks, held to `can` by `x-board-can` as a board of its own would be. The API reads the
|
|
3078
|
+
* profile as `apiProfileHeaders` sends it.
|
|
3079
|
+
*/
|
|
3080
|
+
async sandbox({ profile, can, token }) {
|
|
3081
|
+
if (profile.avatar !== void 0 && !profile.avatar.startsWith("https://")) throw new HttpError(400, "invalid_profile", `${profile.avatar} isn't an avatar Vercel's API takes: one is an https URL.`, { origin: "handle" });
|
|
3082
|
+
const who = { profile: null };
|
|
3083
|
+
const team = await teamId();
|
|
3084
|
+
const id = team?.startsWith("team_") ? team : (await self(who)).teamId;
|
|
3085
|
+
const url = `${origin}/v1/messageboard${await onBoard(who)}?teamId=${encodeURIComponent(id)}`;
|
|
3086
|
+
return {
|
|
3087
|
+
url,
|
|
3088
|
+
headers: {
|
|
3089
|
+
...environment ? await environment.sandbox(url, token) : token === void 0 ? withoutToken(url) : { authorization: `Bearer ${token}` },
|
|
3090
|
+
...apiProfileHeaders(profile),
|
|
3091
|
+
"x-board-can": can
|
|
3092
|
+
},
|
|
3093
|
+
routes: SANDBOX_ROUTES,
|
|
3094
|
+
reads: ["/v1/messageboard/me"]
|
|
3095
|
+
};
|
|
3096
|
+
},
|
|
2919
3097
|
sendsSchedulesHere: false,
|
|
2920
3098
|
syncedHere: holds,
|
|
2921
3099
|
bind(next) {
|
|
@@ -2997,18 +3175,6 @@ function createPolicy(options, keeps, serving, trust = null) {
|
|
|
2997
3175
|
const issuers = verifiedIssuers([], grantIssuers(await grants()));
|
|
2998
3176
|
if (issuers.join("\n") !== context.issuers.join("\n")) context.issuers = issuers;
|
|
2999
3177
|
}
|
|
3000
|
-
/** Who a board token is: the principal that minted it, narrowed, until it's revoked or expires. */
|
|
3001
|
-
async function tokenPrincipal(secret) {
|
|
3002
|
-
if (!trust) throw unauthorized("this board issues no tokens: send a board token to the board that minted it");
|
|
3003
|
-
const found = await trust.token(await tokenHash(secret));
|
|
3004
|
-
if (!found || found.expiresAt.getTime() <= Date.now()) throw unauthorized("invalid token: revoked, expired, or not this board's");
|
|
3005
|
-
return {
|
|
3006
|
-
...found.minter,
|
|
3007
|
-
expiresAt: found.expiresAt,
|
|
3008
|
-
token: found.id,
|
|
3009
|
-
pinned: found.pinned
|
|
3010
|
-
};
|
|
3011
|
-
}
|
|
3012
3178
|
/** Verified principals by credential, until they expire, so a stream's polls don't verify from scratch. */
|
|
3013
3179
|
const verified = /* @__PURE__ */ new Map();
|
|
3014
3180
|
/** And by request, for one with no credential (a session cookie), for as long as it's served. */
|
|
@@ -3030,7 +3196,7 @@ function createPolicy(options, keeps, serving, trust = null) {
|
|
|
3030
3196
|
const principal = verify(request);
|
|
3031
3197
|
perRequest.set(request, principal);
|
|
3032
3198
|
if (key !== null) principal.then((found) => {
|
|
3033
|
-
if (found.facts?.issuer === "host" || found.expiresAt === null
|
|
3199
|
+
if (found.facts?.issuer === "host" || found.expiresAt === null) return;
|
|
3034
3200
|
if (verified.size >= 1e3) verified.delete(verified.keys().next().value);
|
|
3035
3201
|
verified.set(key, {
|
|
3036
3202
|
principal,
|
|
@@ -3040,7 +3206,6 @@ function createPolicy(options, keeps, serving, trust = null) {
|
|
|
3040
3206
|
return principal;
|
|
3041
3207
|
}
|
|
3042
3208
|
async function verify(request) {
|
|
3043
|
-
if (request.credential?.startsWith("board_")) return tokenPrincipal(request.credential);
|
|
3044
3209
|
if (request.credential !== null) await learnIssuers(request.credential);
|
|
3045
3210
|
const authenticate = await verifier();
|
|
3046
3211
|
let result;
|
|
@@ -3107,13 +3272,12 @@ function createPolicy(options, keeps, serving, trust = null) {
|
|
|
3107
3272
|
*/
|
|
3108
3273
|
async identify(request) {
|
|
3109
3274
|
const found = await principalOf(request);
|
|
3110
|
-
const claims =
|
|
3111
|
-
const
|
|
3112
|
-
const principal = scope === void 0 ? found : {
|
|
3275
|
+
const { claims } = request;
|
|
3276
|
+
const principal = claims.scope === null ? found : {
|
|
3113
3277
|
...found,
|
|
3114
|
-
scope
|
|
3278
|
+
scope: claims.scope
|
|
3115
3279
|
};
|
|
3116
|
-
const { author, actor } = resolveActor(principal, claims
|
|
3280
|
+
const { author, actor } = resolveActor(principal, claims);
|
|
3117
3281
|
return {
|
|
3118
3282
|
principal: {
|
|
3119
3283
|
...principal,
|
|
@@ -3124,26 +3288,13 @@ function createPolicy(options, keeps, serving, trust = null) {
|
|
|
3124
3288
|
};
|
|
3125
3289
|
},
|
|
3126
3290
|
explain,
|
|
3127
|
-
/** What a stored principal (a schedule's creator, a watcher's registrant) may do now: null once nothing,
|
|
3291
|
+
/** What a stored principal (a schedule's creator, a watcher's registrant) may do now: null once nothing, or once it was made with a board token. */
|
|
3128
3292
|
async accessNow(principal, grants) {
|
|
3129
|
-
if (principal.token !== void 0
|
|
3293
|
+
if (principal.token !== void 0) return null;
|
|
3130
3294
|
return authority.accessNow(principal, grants);
|
|
3131
3295
|
}
|
|
3132
3296
|
};
|
|
3133
3297
|
}
|
|
3134
|
-
/** A board token's pins, over what the request says: its profile and session win, and a person's name is the minter's. */
|
|
3135
|
-
function pinnedClaims(pinned, claims) {
|
|
3136
|
-
return {
|
|
3137
|
-
...claims,
|
|
3138
|
-
...pinned.profile !== null ? {
|
|
3139
|
-
profile: pinned.profile,
|
|
3140
|
-
avatar: pinned.avatar
|
|
3141
|
-
} : {},
|
|
3142
|
-
...pinned.session !== null ? { session: pinned.session } : {},
|
|
3143
|
-
handle: pinned.handle,
|
|
3144
|
-
name: pinned.name
|
|
3145
|
-
};
|
|
3146
|
-
}
|
|
3147
3298
|
/** A JWT's `iss`, read but not verified: which issuer's keys would check it. Null for anything else. */
|
|
3148
3299
|
function issuerOf(credential) {
|
|
3149
3300
|
const payload = credential.split(".")[1];
|
|
@@ -3194,7 +3345,7 @@ const STYLES = {
|
|
|
3194
3345
|
mark: { glyph: "π" }
|
|
3195
3346
|
}
|
|
3196
3347
|
};
|
|
3197
|
-
/** A
|
|
3348
|
+
/** A known agent's mark, for a caller to pass as its avatar; other names get their initial. */
|
|
3198
3349
|
function avatarSvg(name) {
|
|
3199
3350
|
const style = STYLES[name] ?? {
|
|
3200
3351
|
background: "#666666",
|
|
@@ -3242,14 +3393,12 @@ async function inputOf(name, request, url, params) {
|
|
|
3242
3393
|
case "actors":
|
|
3243
3394
|
case "watchers":
|
|
3244
3395
|
case "grants":
|
|
3245
|
-
case "tokens":
|
|
3246
3396
|
case "schemas": return {};
|
|
3247
3397
|
case "message":
|
|
3248
3398
|
case "posted":
|
|
3249
3399
|
case "synced":
|
|
3250
3400
|
case "cancelSchedule":
|
|
3251
3401
|
case "revokeGrant":
|
|
3252
|
-
case "revokeToken":
|
|
3253
3402
|
case "schema":
|
|
3254
3403
|
case "attachment":
|
|
3255
3404
|
case "uploadFinish": return { id };
|
|
@@ -3272,7 +3421,6 @@ async function inputOf(name, request, url, params) {
|
|
|
3272
3421
|
...UpdateGrantBody.parse(await body())
|
|
3273
3422
|
};
|
|
3274
3423
|
case "explain": return ExplainQuery.parse(queryObject(url));
|
|
3275
|
-
case "createToken": return TokenBody.parse(await body());
|
|
3276
3424
|
case "createSchema": return SchemaBody.parse(await body());
|
|
3277
3425
|
case "register": return RegisterBody.parse(await body());
|
|
3278
3426
|
case "edit": return {
|
|
@@ -4150,6 +4298,13 @@ async function createServe(context) {
|
|
|
4150
4298
|
//#region src/server/board.ts
|
|
4151
4299
|
/** How long a handle's live events wait for the next, in seconds, before asking again. */
|
|
4152
4300
|
const EVENTS_WAIT_S = 25;
|
|
4301
|
+
/** A profile's name, as the board takes one in `x-board-profile`. */
|
|
4302
|
+
const SANDBOX_PROFILE = /^[A-Za-z][A-Za-z0-9-]{0,31}$/;
|
|
4303
|
+
/** An avatar the board takes: an https URL, or http on localhost. */
|
|
4304
|
+
const avatarUrl = (value) => {
|
|
4305
|
+
const url = URL.parse(value);
|
|
4306
|
+
return url !== null && (url.protocol === "https:" || url.protocol === "http:" && ["localhost", "127.0.0.1"].includes(url.hostname));
|
|
4307
|
+
};
|
|
4153
4308
|
/** A board's name: 1 to 64 characters, no `/`. */
|
|
4154
4309
|
const BOARD_NAME = /^[^/]{1,64}$/;
|
|
4155
4310
|
/** A team, by its ID or its slug. */
|
|
@@ -4200,12 +4355,59 @@ function createBoard(options, runtime) {
|
|
|
4200
4355
|
});
|
|
4201
4356
|
}
|
|
4202
4357
|
const serve = async (request) => (await server()).dispatch(request, null);
|
|
4358
|
+
/** How a sandbox reaches this board, where it keeps the board itself: at its own URL, with this deployment's credential. */
|
|
4359
|
+
async function ownReach({ profile, can, token }) {
|
|
4360
|
+
const url = ownUrl();
|
|
4361
|
+
if (url === null) throw new HttpError(400, "no_url", "A sandbox reaches this board at its URL, and it doesn't know it yet.", {
|
|
4362
|
+
hint: "Pass board({ url }).",
|
|
4363
|
+
origin: "handle"
|
|
4364
|
+
});
|
|
4365
|
+
return {
|
|
4366
|
+
url,
|
|
4367
|
+
headers: {
|
|
4368
|
+
...runtime.sandbox ? await runtime.sandbox(url, token) : token === void 0 ? withoutToken(url) : { authorization: `Bearer ${token}` },
|
|
4369
|
+
"x-board-profile": formatProfileHeader(profile),
|
|
4370
|
+
"x-board-can": can
|
|
4371
|
+
},
|
|
4372
|
+
routes: PROTOCOL_ROUTES
|
|
4373
|
+
};
|
|
4374
|
+
}
|
|
4375
|
+
/** The policy that hands this board to a sandbox, for a handle as `caller`. */
|
|
4376
|
+
async function sandboxPolicy(caller, options = {}) {
|
|
4377
|
+
const own = "profile" in caller ? caller.profile : null;
|
|
4378
|
+
const named = options.profile ?? (own === null || own === void 0 ? null : typeof own === "string" ? { name: own } : own);
|
|
4379
|
+
if (named === null) throw new BoardError("invalid_profile", "A sandbox writes as a profile of this deployment, and this names none: the sandbox could send its own, and write as any.", 400, { hint: "Name one: sandboxPolicy({ profile: { name } }), or team.as('<name>').sandboxPolicy()." });
|
|
4380
|
+
if (!SANDBOX_PROFILE.test(named.name)) throw new BoardError("invalid_profile", `${named.name} isn't a profile's name: one starts with a letter and uses up to 32 letters, numbers, and hyphens.`, 400);
|
|
4381
|
+
if (named.avatar !== void 0 && !avatarUrl(named.avatar)) throw new BoardError("invalid_profile", `${named.avatar} isn't an avatar: one is an https URL, or http on localhost.`, 400);
|
|
4382
|
+
let can;
|
|
4383
|
+
try {
|
|
4384
|
+
can = canHeader(options.can);
|
|
4385
|
+
} catch (error) {
|
|
4386
|
+
if (error instanceof InvalidCan) throw new BoardError("invalid_scope", error.message, 400);
|
|
4387
|
+
throw error;
|
|
4388
|
+
}
|
|
4389
|
+
const input = {
|
|
4390
|
+
profile: named,
|
|
4391
|
+
can,
|
|
4392
|
+
token: options.token
|
|
4393
|
+
};
|
|
4394
|
+
try {
|
|
4395
|
+
return boardPolicy(backend.sandbox ? await backend.sandbox(input) : await ownReach(input));
|
|
4396
|
+
} catch (error) {
|
|
4397
|
+
if (error instanceof HttpError) throw new BoardError(error.code, error.message, error.status, {
|
|
4398
|
+
...error.hint !== void 0 ? { hint: error.hint } : {},
|
|
4399
|
+
origin: error.origin
|
|
4400
|
+
});
|
|
4401
|
+
throw error;
|
|
4402
|
+
}
|
|
4403
|
+
}
|
|
4203
4404
|
/** A handle on `client`, which `as` gives other profiles of. */
|
|
4204
|
-
function handle(client, url) {
|
|
4405
|
+
function handle(client, url, caller) {
|
|
4205
4406
|
const made = {
|
|
4206
4407
|
...client,
|
|
4207
4408
|
fetch: serve,
|
|
4208
|
-
as
|
|
4409
|
+
as,
|
|
4410
|
+
sandboxPolicy: (options) => sandboxPolicy(caller, options)
|
|
4209
4411
|
};
|
|
4210
4412
|
if (url) Object.defineProperty(made, "url", {
|
|
4211
4413
|
get: url,
|
|
@@ -4223,7 +4425,7 @@ function createBoard(options, runtime) {
|
|
|
4223
4425
|
if ("identity" in caller) return handle({
|
|
4224
4426
|
...client,
|
|
4225
4427
|
events: (query, opts) => events(client, query, opts)
|
|
4226
|
-
}, () => ownUrl() ?? inProcess);
|
|
4428
|
+
}, () => ownUrl() ?? inProcess, caller);
|
|
4227
4429
|
const via = caller.origin.via?.kind ?? "client";
|
|
4228
4430
|
const id = (given) => derivedId(`board-${via === "watcher" ? "watch" : via}`, caller.self ?? "", given);
|
|
4229
4431
|
const owned = async (input) => typeof input === "string" || input.id === void 0 ? input : {
|
|
@@ -4240,7 +4442,7 @@ function createBoard(options, runtime) {
|
|
|
4240
4442
|
return profile !== void 0 ? as(profile).request(path, rest) : client.request(path, rest);
|
|
4241
4443
|
},
|
|
4242
4444
|
events: (query, opts) => events(client, query, opts)
|
|
4243
|
-
}, () => ownUrl() ?? inProcess);
|
|
4445
|
+
}, () => ownUrl() ?? inProcess, caller);
|
|
4244
4446
|
}
|
|
4245
4447
|
const profileCaller = (profile) => {
|
|
4246
4448
|
const name = profile === null ? null : typeof profile === "string" ? profile : profile.name;
|
|
@@ -4353,4 +4555,4 @@ async function* events(client, query = {}, opts = {}) {
|
|
|
4353
4555
|
}
|
|
4354
4556
|
}
|
|
4355
4557
|
//#endregion
|
|
4356
|
-
export {
|
|
4558
|
+
export { PROTOCOL_ROUTES as a, deployedOnVercel as c, isApiMessageId as i, isBoardName as n, withoutToken as o, createVercel as r, tailWatchers as s, createBoard as t };
|