@vercel/board 0.43.0 → 0.44.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.d.mts +2 -2
- package/dist/{auth-Bn8J_1F2.d.mts → auth-C8jxty0C.d.mts} +1 -1
- package/dist/{backend-DMrK55mU.d.mts → backend-_3W_5g6y.d.mts} +3 -3
- package/dist/backend-local.d.mts +1 -1
- package/dist/backend-local.mjs +1 -1
- package/dist/{bots-CGkO76qH.mjs → bots-CLKKMgYf.mjs} +6 -1
- package/dist/{chat-provider-CPZg2MQb.mjs → chat-provider-DZ4DsAZ7.mjs} +6 -4
- package/dist/{chat-provider-Cgkh9xJw.d.mts → chat-provider-HQo68RWL.d.mts} +4 -4
- 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 +2 -2
- package/dist/cli.mjs +6 -6
- package/dist/{commands-C4fR0md0.mjs → commands-B75pBXIV.mjs} +1 -1
- package/dist/{commands-BlM-ckFS.d.mts → commands-DHGZWeSZ.d.mts} +1 -1
- package/dist/{conformance-BORt5nky.mjs → conformance-CHqXZoGe.mjs} +66 -0
- package/dist/conformance.d.mts +1 -1
- package/dist/conformance.mjs +1 -1
- package/dist/{data-values-C-Cq80hz.mjs → data-values-CoTP0SQG.mjs} +43 -54
- package/dist/{engine-BVHSH2Kn.mjs → engine-D07DTYSi.mjs} +16 -9
- package/dist/{events-BT8y_81j.mjs → events-voButVQW.mjs} +3 -1
- package/dist/{exports-S2AJNE_O.mjs → exports-BNk4w-b2.mjs} +10 -12
- package/dist/exports-DFwXKst5.d.mts +4 -0
- package/dist/{index-CydxnBND.d.mts → index-CwOOIT0e.d.mts} +2 -2
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +2 -2
- package/dist/index.node.d.mts +6 -6
- package/dist/index.node.mjs +1 -1
- package/dist/inspect/app.js +94 -94
- package/dist/inspect/engine.js +5 -5
- package/dist/inspect-DBLdh9NM.mjs +2 -0
- package/dist/{inspect-ByIt7CxV.mjs → inspect-dtQlHBcq.mjs} +1 -1
- package/dist/{local-0TVbQkzW.mjs → local-CnGNTReZ.mjs} +3 -1
- package/dist/{main-CM0_uZ7w.mjs → main-CpsAmpEy.mjs} +22 -37
- package/dist/origin-D4ER_Tze.mjs +428 -0
- package/dist/{provider-dY54GFNz.d.mts → provider-CVI-DlWl.d.mts} +27 -2
- package/dist/{routes-By9lmvUD.d.mts → routes-CErTwlSZ.d.mts} +3 -1
- package/dist/{origin-DoRR9yql.mjs → routes-DrByOCc1.mjs} +4 -426
- package/dist/schemas.mjs +1 -1
- package/dist/{serve-p_KKFTWm.mjs → serve-BQT5quKD.mjs} +2 -2
- package/dist/{server-CD7qe_Pl.mjs → server-FlDE6BDt.mjs} +4 -3
- 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 +3 -3
- package/dist/sync-slack.d.mts +27 -4
- package/dist/sync-slack.mjs +206 -10
- package/dist/sync.d.mts +3 -3
- package/dist/sync.mjs +1 -1
- package/docs/02-sync/02-functions.md +4 -1
- package/docs/02-sync/03-slack.md +24 -1
- package/docs/02-sync/04-github.md +5 -2
- package/docs/02-sync/06-providers.md +1 -1
- package/docs/04-reference/01-cli.md +2 -2
- package/docs/04-reference/02-board.md +1 -1
- package/docs/04-reference/03-http.md +9 -3
- package/docs/04-reference/05-conformance.md +2 -3
- package/package.json +3 -1
- package/dist/exports-Bw_OYNRl.d.mts +0 -4
- package/dist/inspect-BjDlPHjE.mjs +0 -2
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import { h as ATTACHMENT_BYTES_MAX, r as badRequest, t as HttpError } from "./errors-DUzpDSrJ.mjs";
|
|
2
|
+
import "./schemas-DAzSsgWk.mjs";
|
|
3
|
+
import { l as isThreadTarget } from "./external-DymyhUzl.mjs";
|
|
4
|
+
import { F as routes, s as Filters } from "./routes-DrByOCc1.mjs";
|
|
5
|
+
import { i as afterRetry } from "./middleware-0DUFrav-.mjs";
|
|
6
|
+
import { o as options } from "./commands-B75pBXIV.mjs";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/version.ts
|
|
10
|
+
const VERSION = "0.44.0";
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/server/backend.ts
|
|
13
|
+
/** The subscription sync's outbound runs on, in `BoardBinding.subscriptions`. No watcher's ID starts with `@`. */
|
|
14
|
+
const SYNC = "@sync";
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/server/routing.ts
|
|
17
|
+
/** board()'s own routes: the files it serves, and sync's, which run where board() does. */
|
|
18
|
+
const BOARD_ROUTES = [
|
|
19
|
+
"avatar",
|
|
20
|
+
"openapi",
|
|
21
|
+
"webhook",
|
|
22
|
+
"sync"
|
|
23
|
+
];
|
|
24
|
+
/** Every protocol method, by the route it's served at. */
|
|
25
|
+
const METHODS = [
|
|
26
|
+
"discovery",
|
|
27
|
+
"me",
|
|
28
|
+
"channels",
|
|
29
|
+
"createChannel",
|
|
30
|
+
"actors",
|
|
31
|
+
"messages",
|
|
32
|
+
"threads",
|
|
33
|
+
"message",
|
|
34
|
+
"post",
|
|
35
|
+
"posted",
|
|
36
|
+
"edit",
|
|
37
|
+
"delete",
|
|
38
|
+
"react",
|
|
39
|
+
"label",
|
|
40
|
+
"schedule",
|
|
41
|
+
"schedules",
|
|
42
|
+
"cancelSchedule",
|
|
43
|
+
"grants",
|
|
44
|
+
"createGrant",
|
|
45
|
+
"updateGrant",
|
|
46
|
+
"explain",
|
|
47
|
+
"revokeGrant",
|
|
48
|
+
"schemas",
|
|
49
|
+
"schema",
|
|
50
|
+
"createSchema",
|
|
51
|
+
"upload",
|
|
52
|
+
"attachment",
|
|
53
|
+
"uploadStart",
|
|
54
|
+
"uploadFinish",
|
|
55
|
+
"watchers",
|
|
56
|
+
"register",
|
|
57
|
+
"matches",
|
|
58
|
+
"ack",
|
|
59
|
+
"events",
|
|
60
|
+
"syncImport",
|
|
61
|
+
"syncReceipt",
|
|
62
|
+
"syncThread",
|
|
63
|
+
"syncFind",
|
|
64
|
+
"syncCopies",
|
|
65
|
+
"inboxPush",
|
|
66
|
+
"inboxNext",
|
|
67
|
+
"inboxAck",
|
|
68
|
+
"inbox",
|
|
69
|
+
"typing",
|
|
70
|
+
"readSource",
|
|
71
|
+
"joinSource",
|
|
72
|
+
"synced",
|
|
73
|
+
"linked"
|
|
74
|
+
];
|
|
75
|
+
const escape = (literal) => literal.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
76
|
+
function compile(method, path, target, own) {
|
|
77
|
+
const parts = path.split("/").filter(Boolean);
|
|
78
|
+
const source = parts.map((part) => part.startsWith(":") ? "/([^/]+)" : `/${escape(part)}`).join("");
|
|
79
|
+
return {
|
|
80
|
+
method,
|
|
81
|
+
pattern: new RegExp(`${source}$`),
|
|
82
|
+
names: parts.filter((part) => part.startsWith(":")).map((part) => part.slice(1)),
|
|
83
|
+
target,
|
|
84
|
+
segments: parts.length,
|
|
85
|
+
literals: parts.filter((part) => !part.startsWith(":")).length,
|
|
86
|
+
own
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The routes a board answers, most specific first: each is matched as a suffix of the request's
|
|
91
|
+
* path, so `/api/board/messages/12` is `GET /messages/:id` under `/api/board`. A backend's own
|
|
92
|
+
* route at a protocol path takes its place. Discovery is the mount itself.
|
|
93
|
+
*/
|
|
94
|
+
function createRouter(backendRoutes, basePath) {
|
|
95
|
+
const patterns = [
|
|
96
|
+
...BOARD_ROUTES.map((name) => compile(routes[name].method, routes[name].path, {
|
|
97
|
+
kind: "board",
|
|
98
|
+
name
|
|
99
|
+
}, false)),
|
|
100
|
+
...METHODS.filter((name) => name !== "discovery").map((name) => compile(routes[name].method, routes[name].path, {
|
|
101
|
+
kind: "protocol",
|
|
102
|
+
name
|
|
103
|
+
}, false)),
|
|
104
|
+
...backendRoutes.map((route) => compile(route.method, route.path, {
|
|
105
|
+
kind: "backend",
|
|
106
|
+
route
|
|
107
|
+
}, true))
|
|
108
|
+
].sort((a, b) => b.segments - a.segments || b.literals - a.literals || Number(b.own) - Number(a.own));
|
|
109
|
+
/** A segment that isn't URI-encoded names nothing: no route. */
|
|
110
|
+
const found = (candidate, base, values) => {
|
|
111
|
+
const params = {};
|
|
112
|
+
try {
|
|
113
|
+
candidate.names.forEach((name, i) => params[name] = decodeURIComponent(values[i]));
|
|
114
|
+
} catch {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
const first = candidate.names[0];
|
|
118
|
+
return {
|
|
119
|
+
target: candidate.target,
|
|
120
|
+
base,
|
|
121
|
+
param: first === void 0 ? null : params[first],
|
|
122
|
+
params
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
const discovery = (base) => ({
|
|
126
|
+
target: {
|
|
127
|
+
kind: "protocol",
|
|
128
|
+
name: "discovery"
|
|
129
|
+
},
|
|
130
|
+
base,
|
|
131
|
+
param: null,
|
|
132
|
+
params: {},
|
|
133
|
+
root: true
|
|
134
|
+
});
|
|
135
|
+
return function route(method, pathname) {
|
|
136
|
+
const path = pathname.length > 1 ? pathname.replace(/\/+$/, "") : pathname;
|
|
137
|
+
if (basePath !== void 0) {
|
|
138
|
+
const base = basePath.replace(/\/+$/, "");
|
|
139
|
+
if (path !== base && !path.startsWith(`${base}/`)) return null;
|
|
140
|
+
const rest = path.slice(base.length) || "/";
|
|
141
|
+
if (rest === "/") return method === "GET" ? discovery(base) : null;
|
|
142
|
+
for (const candidate of patterns) {
|
|
143
|
+
const hit = candidate.method === method ? rest.match(new RegExp(`^${candidate.pattern.source}`)) : null;
|
|
144
|
+
if (hit) return found(candidate, base, hit.slice(1));
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
for (const candidate of patterns) {
|
|
149
|
+
if (candidate.method !== method) continue;
|
|
150
|
+
const hit = path.match(candidate.pattern);
|
|
151
|
+
if (hit) return found(candidate, path.slice(0, hit.index), hit.slice(1));
|
|
152
|
+
}
|
|
153
|
+
return method === "GET" ? discovery(path === "/" ? "" : path) : null;
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function queryObject(url) {
|
|
157
|
+
const out = {};
|
|
158
|
+
for (const key of new Set(url.searchParams.keys())) {
|
|
159
|
+
const values = url.searchParams.getAll(key);
|
|
160
|
+
out[key] = values.length > 1 ? values : values[0];
|
|
161
|
+
}
|
|
162
|
+
return out;
|
|
163
|
+
}
|
|
164
|
+
async function readJson(request) {
|
|
165
|
+
const text = await request.text();
|
|
166
|
+
if (text.trim() === "") return void 0;
|
|
167
|
+
try {
|
|
168
|
+
return JSON.parse(text);
|
|
169
|
+
} catch {
|
|
170
|
+
throw badRequest("request body is not valid JSON");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const tooLarge = () => new HttpError(413, "too_large", `attachments are at most ${ATTACHMENT_BYTES_MAX / 1024 / 1024} MB`);
|
|
174
|
+
/** The body, refused as soon as it's past `max`: with or without a `content-length`, it never reads more. */
|
|
175
|
+
async function readCapped(request, max) {
|
|
176
|
+
if (Number(request.headers.get("content-length") ?? 0) > max) throw tooLarge();
|
|
177
|
+
const chunks = [];
|
|
178
|
+
let size = 0;
|
|
179
|
+
for await (const chunk of request.body ?? []) {
|
|
180
|
+
size += chunk.byteLength;
|
|
181
|
+
if (size > max) throw tooLarge();
|
|
182
|
+
chunks.push(chunk);
|
|
183
|
+
}
|
|
184
|
+
const body = new Uint8Array(size);
|
|
185
|
+
let at = 0;
|
|
186
|
+
for (const chunk of chunks) {
|
|
187
|
+
body.set(chunk, at);
|
|
188
|
+
at += chunk.byteLength;
|
|
189
|
+
}
|
|
190
|
+
return body;
|
|
191
|
+
}
|
|
192
|
+
function openapi() {
|
|
193
|
+
const paths = {};
|
|
194
|
+
for (const [name, definition] of Object.entries(routes)) {
|
|
195
|
+
const path = definition.path.replace(/:(\w+)/g, "{$1}");
|
|
196
|
+
const operation = { operationId: name };
|
|
197
|
+
if ("query" in definition) operation["x-query-schema"] = z.toJSONSchema(definition.query, { io: "input" });
|
|
198
|
+
if ("body" in definition) operation.requestBody = { content: { "application/json": { schema: z.toJSONSchema(definition.body, { io: "input" }) } } };
|
|
199
|
+
(paths[path] ??= {})[definition.method.toLowerCase()] = operation;
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
openapi: "3.1.0",
|
|
203
|
+
info: {
|
|
204
|
+
title: "board",
|
|
205
|
+
version: VERSION
|
|
206
|
+
},
|
|
207
|
+
paths
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/api/tail.ts
|
|
212
|
+
/** The filter flags `read`, `tail`, and `wait` share, and that a watcher's `tail` accepts. */
|
|
213
|
+
const FILTER_FLAGS = {
|
|
214
|
+
re: options.re,
|
|
215
|
+
by: options.by,
|
|
216
|
+
mentions: options.mentions,
|
|
217
|
+
label: options.label,
|
|
218
|
+
source: options.source,
|
|
219
|
+
text: options.text
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* What `--mentions` takes as its value when it's the next word: `@ada`, `ada@vercel.com`, or `me`.
|
|
223
|
+
* A channel never has an `@`, and a flag (`--text=a@b`) is never the value.
|
|
224
|
+
*/
|
|
225
|
+
const mentionValue = (word) => word !== void 0 && !word.startsWith("-") && (word === "me" || word.includes("@"));
|
|
226
|
+
/**
|
|
227
|
+
* `--mentions` alone means mentions of me; `--mentions @ada`, mentions of ada; `--mentions
|
|
228
|
+
* ada@vercel.com`, of the user with that email. Nothing after `--` is a flag.
|
|
229
|
+
*/
|
|
230
|
+
function withMentions(args) {
|
|
231
|
+
const out = [];
|
|
232
|
+
for (let i = 0; i < args.length; i++) {
|
|
233
|
+
const arg = args[i];
|
|
234
|
+
if (arg === "--") {
|
|
235
|
+
out.push(...args.slice(i));
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
if (arg !== "--mentions") out.push(arg);
|
|
239
|
+
else if (mentionValue(args[i + 1])) out.push(`--mentions=${args[++i]}`);
|
|
240
|
+
else out.push("--mentions=me");
|
|
241
|
+
}
|
|
242
|
+
return out;
|
|
243
|
+
}
|
|
244
|
+
/** Splits an expression the way a shell would: whitespace separates, quotes group, `\` escapes. */
|
|
245
|
+
function words(expression) {
|
|
246
|
+
const out = [];
|
|
247
|
+
let word = null;
|
|
248
|
+
let quote = null;
|
|
249
|
+
for (let i = 0; i < expression.length; i++) {
|
|
250
|
+
const char = expression[i];
|
|
251
|
+
if (quote) {
|
|
252
|
+
if (char === quote) quote = null;
|
|
253
|
+
else if (char === "\\" && quote === "\"" && i + 1 < expression.length) word += expression[++i];
|
|
254
|
+
else word += char;
|
|
255
|
+
} else if (/\s/.test(char)) {
|
|
256
|
+
if (word !== null) out.push(word);
|
|
257
|
+
word = null;
|
|
258
|
+
} else if (char === "\"" || char === "'") {
|
|
259
|
+
quote = char;
|
|
260
|
+
word ??= "";
|
|
261
|
+
} else if (char === "\\" && i + 1 < expression.length) word = (word ?? "") + expression[++i];
|
|
262
|
+
else word = (word ?? "") + char;
|
|
263
|
+
}
|
|
264
|
+
if (quote) throw new Error(`unterminated ${quote}`);
|
|
265
|
+
if (word !== null) out.push(word);
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
268
|
+
/** A watcher's tail takes the filters and `--all`, which shows receipts as it does in `vb tail`. */
|
|
269
|
+
const TAIL_FLAGS = {
|
|
270
|
+
...FILTER_FLAGS,
|
|
271
|
+
all: { type: "boolean" }
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Parses filter flags as the CLI's parser does (Node's `parseArgs`, strict), written out so a tail
|
|
275
|
+
* parses wherever board() runs, a browser included.
|
|
276
|
+
*/
|
|
277
|
+
function parseFilterFlags(args) {
|
|
278
|
+
const values = {};
|
|
279
|
+
const positionals = [];
|
|
280
|
+
for (let i = 0; i < args.length; i++) {
|
|
281
|
+
const arg = args[i];
|
|
282
|
+
if (arg === "--") {
|
|
283
|
+
positionals.push(...args.slice(i + 1));
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
if (!arg.startsWith("-") || arg === "-") {
|
|
287
|
+
positionals.push(arg);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
const eq = arg.indexOf("=");
|
|
291
|
+
const name = arg.startsWith("--") ? arg.slice(2, eq === -1 ? void 0 : eq) : null;
|
|
292
|
+
const spec = name !== null && Object.hasOwn(TAIL_FLAGS, name) ? TAIL_FLAGS[name] : null;
|
|
293
|
+
if (!spec) throw new Error(`${name !== null ? `--${name}` : arg.slice(0, 2)} isn't a filter`);
|
|
294
|
+
if (spec.type === "boolean") {
|
|
295
|
+
if (eq !== -1) throw new Error(`--${name} takes no value`);
|
|
296
|
+
values[name] = true;
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
let value;
|
|
300
|
+
if (eq !== -1) value = arg.slice(eq + 1);
|
|
301
|
+
else {
|
|
302
|
+
const next = args[i + 1];
|
|
303
|
+
if (next === void 0 || next.length > 1 && next.startsWith("-")) throw new Error(`--${name} needs a value`);
|
|
304
|
+
value = next;
|
|
305
|
+
i++;
|
|
306
|
+
}
|
|
307
|
+
if ("multiple" in spec) values[name] = [...values[name] ?? [], value];
|
|
308
|
+
else values[name] = value;
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
values,
|
|
312
|
+
positionals
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
/** A watcher's `tail`: its filters, and whether `--all` shows it receipts too. */
|
|
316
|
+
function parseWatchTail(expression) {
|
|
317
|
+
const { values, positionals } = parseFilterFlags(withMentions(words(expression)));
|
|
318
|
+
if (positionals.length > 1) throw new Error(`expected one channel, got: ${positionals.join(" ")}`);
|
|
319
|
+
const channel = positionals[0];
|
|
320
|
+
const parsed = Filters.safeParse({
|
|
321
|
+
...channel ? { channel } : {},
|
|
322
|
+
...values.re ? { re: values.re.replace(/^#/, "") } : {},
|
|
323
|
+
...values.by ? { by: values.by.replace(/^@/, "") } : {},
|
|
324
|
+
...values.mentions ? { mentions: values.mentions.replace(/^@/, "") } : {},
|
|
325
|
+
...values.label?.length ? { label: values.label } : {},
|
|
326
|
+
...values.source ? { from: values.source } : {},
|
|
327
|
+
...values.text ? { text: values.text } : {}
|
|
328
|
+
});
|
|
329
|
+
if (!parsed.success) {
|
|
330
|
+
const issue = parsed.error.issues[0];
|
|
331
|
+
throw new Error(`${issue?.path.length ? `--${String(issue.path[0])}: ` : ""}${issue?.message ?? "invalid filters"}`);
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
filters: parsed.data,
|
|
335
|
+
all: values.all === true
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region src/server/watch-spec.ts
|
|
340
|
+
/** Whether filters narrow anything: a view a message can enter. */
|
|
341
|
+
const hasCriteria = (filters) => filters.channel !== void 0 || filters.re !== void 0 || filters.by !== void 0 || filters.mentions !== void 0 || filters.from !== void 0 || filters.text !== void 0 || (filters.label?.length ?? 0) > 0;
|
|
342
|
+
/** A watcher's tail, checked the way a boot checks it: errors name the watcher. */
|
|
343
|
+
function compileWatcher(id, spec) {
|
|
344
|
+
let filters;
|
|
345
|
+
let all;
|
|
346
|
+
try {
|
|
347
|
+
({filters, all} = parseWatchTail(spec.tail));
|
|
348
|
+
} catch (error) {
|
|
349
|
+
throw new Error(`watch ${id}: ${error.message}`);
|
|
350
|
+
}
|
|
351
|
+
if (filters.mentions === "me") throw new Error(`watch ${id}: a watcher has no "me": use --mentions @handle`);
|
|
352
|
+
return {
|
|
353
|
+
filters,
|
|
354
|
+
criteria: hasCriteria(filters),
|
|
355
|
+
all
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
//#endregion
|
|
359
|
+
//#region src/server/watch-run.ts
|
|
360
|
+
/**
|
|
361
|
+
* A2 dead-letters an event after 10 failures, and a dead letter stops its
|
|
362
|
+
* lane, which is the thread's: the watcher would never run on that thread
|
|
363
|
+
* again. So `run` gets a few tries, then the failure is recorded and the
|
|
364
|
+
* thread moves on.
|
|
365
|
+
*/
|
|
366
|
+
const RUN_ATTEMPTS = 5;
|
|
367
|
+
/**
|
|
368
|
+
* A run that's killed (a timeout, out of memory) never throws. A2 counts it
|
|
369
|
+
* toward the 10 failures when the next attempt takes over, and dead-letters
|
|
370
|
+
* the event at that takeover instead of running it: the 10th attempt is the
|
|
371
|
+
* last one a watcher sees. Throws give up at RUN_ATTEMPTS, so getting this far
|
|
372
|
+
* means runs keep dying, and the 10th records the failure without running.
|
|
373
|
+
*/
|
|
374
|
+
const KILLED_ATTEMPTS = 10;
|
|
375
|
+
const describe = (error) => ((error instanceof Error ? error.message : String(error)) || "unknown error").slice(0, 500);
|
|
376
|
+
/**
|
|
377
|
+
* One match, on its thread's lane: `run`, retried while it fails (by A2 on a local board, by the
|
|
378
|
+
* tail on a person's Vercel board), then given up on and recorded so the thread's next event runs.
|
|
379
|
+
*/
|
|
380
|
+
async function runMatch(input) {
|
|
381
|
+
const { watcher, match, attempt } = input;
|
|
382
|
+
const event = match.payload.event;
|
|
383
|
+
const giveUp = async (error) => {
|
|
384
|
+
console.error(`[board] watcher ${watcher.id} gave up on event #${event.cursor} after ${attempt} tries:`, error);
|
|
385
|
+
await input.record({
|
|
386
|
+
matched: match.id,
|
|
387
|
+
thread: match.payload.thread,
|
|
388
|
+
error
|
|
389
|
+
});
|
|
390
|
+
};
|
|
391
|
+
const early = !afterRetry(attempt);
|
|
392
|
+
if (early && attempt >= KILLED_ATTEMPTS) return giveUp(`its run was cut short ${attempt - 1} times (a timeout, or out of memory)`);
|
|
393
|
+
try {
|
|
394
|
+
await watcher.run(event);
|
|
395
|
+
} catch (error) {
|
|
396
|
+
if (!early || attempt < RUN_ATTEMPTS) throw error;
|
|
397
|
+
await giveUp(describe(error));
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region src/server/watchers-hash.ts
|
|
402
|
+
/** By UTF-16 code unit, as `sort()` orders strings: the same in every locale and runtime. */
|
|
403
|
+
const byCodeUnit = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
404
|
+
/**
|
|
405
|
+
* What `watchersHash` hashes, the same on both ends: a board on `http()` hashes its watchers, and
|
|
406
|
+
* whether its sync subscribes, and the board it uses hashes what it holds.
|
|
407
|
+
*/
|
|
408
|
+
function canonicalWatchers(watch, sync = []) {
|
|
409
|
+
const canonical = Object.keys(watch).sort(byCodeUnit).map((id) => [id, watch[id].tail]);
|
|
410
|
+
if (sync.length > 0) canonical.push(["sync", [...sync].sort((a, b) => byCodeUnit(a.key, b.key)).map((entry) => [entry.key, entry.platform])]);
|
|
411
|
+
return JSON.stringify(canonical);
|
|
412
|
+
}
|
|
413
|
+
//#endregion
|
|
414
|
+
//#region src/server/targets.ts
|
|
415
|
+
/** A target as a post or a receipt names it, resolved: a plain one's kind goes by its shape. */
|
|
416
|
+
const syncTarget = (target) => typeof target === "string" ? {
|
|
417
|
+
target,
|
|
418
|
+
kind: isThreadTarget(target) ? "thread" : "channel"
|
|
419
|
+
} : target;
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region src/server/origin.ts
|
|
422
|
+
/**
|
|
423
|
+
* Sync in board() itself, on a board whose log is in this deployment (`local()`): it checked each
|
|
424
|
+
* platform event itself, so what it imports is by the platform user, not a profile of anyone.
|
|
425
|
+
*/
|
|
426
|
+
const SYNC_ACTOR = "board:sync";
|
|
427
|
+
//#endregion
|
|
428
|
+
export { compileWatcher as a, METHODS as c, queryObject as d, readCapped as f, VERSION as h, runMatch as i, createRouter as l, SYNC as m, syncTarget as n, hasCriteria as o, readJson as p, canonicalWatchers as r, withMentions as s, SYNC_ACTOR as t, openapi as u };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { At as ThreadsQueryInput, Ct as SyncReceiptInput, Dt as ThreadView, F as Me, I as MessageView, L as MessagesPage, N as MatchView, Ot as ThreadsPage, Pt as UpdateGrantInput, T as InboxItem, Tt as SyncedView, X as RegistrationView, Y as RegisterInput, _ as FiltersInput, _t as SyncFindInput, a as BoardEventView, b as GrantInput, cn as ExternalEvent, ct as SchemaView, dn as Link, f as EventsPage, ft as SourceRead, g as Explanation, it as SchedulesQueryInput, ln as ExternalFile, lt as SourceJoin, n as ActorView, nn as ExternalCopy, nt as ScheduleView, rn as Attachment, s as ChannelView, sn as ExternalAuthor, st as SchemaInput, tn as Actor, u as Discovery, un as ExternalLink, w as InboxEntry, wt as SyncThreadView, x as GrantView, xt as SyncImportInput, yt as SyncFindView, z as MessagesQueryInput } from "./routes-CErTwlSZ.mjs";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
//#region src/client/client.d.ts
|
|
4
4
|
/**
|
|
@@ -368,6 +368,25 @@ declare function createBoardClient(options: ClientOptions): {
|
|
|
368
368
|
}, opts?: WaitOptions): Promise<BoardEventView | null>;
|
|
369
369
|
};
|
|
370
370
|
//#endregion
|
|
371
|
+
//#region src/contract/bots.d.ts
|
|
372
|
+
/**
|
|
373
|
+
* Known bot messages, shown in a form people can read. The board keeps what the
|
|
374
|
+
* bot wrote (`--json` and the API return it as is); `displayText` is what a
|
|
375
|
+
* person sees in `vb read`, inspect, and the copies on other platforms.
|
|
376
|
+
*/
|
|
377
|
+
type VercelDeployment = {
|
|
378
|
+
project: string;
|
|
379
|
+
projectUrl: string | null;
|
|
380
|
+
status: string;
|
|
381
|
+
deploymentUrl: string | null;
|
|
382
|
+
previewUrl: string | null;
|
|
383
|
+
/** As Vercel wrote it, e.g. `Oct 6, 2026 8:30pm UTC`. */
|
|
384
|
+
updated: string | null;
|
|
385
|
+
/** The same as a time, e.g. `2026-10-06T20:30:32.400Z`, when Vercel's comment carries one. */
|
|
386
|
+
updatedAt: string | null;
|
|
387
|
+
skipped: boolean;
|
|
388
|
+
};
|
|
389
|
+
//#endregion
|
|
371
390
|
//#region src/sync/events.d.ts
|
|
372
391
|
declare const EventBase: z.ZodObject<{
|
|
373
392
|
channel: z.ZodString;
|
|
@@ -826,10 +845,16 @@ type ProviderSender = {
|
|
|
826
845
|
avatar: string | null;
|
|
827
846
|
attribution?: string;
|
|
828
847
|
};
|
|
848
|
+
/**
|
|
849
|
+
* What a platform is asked to post or edit: markdown, which it converts to its own format.
|
|
850
|
+
* `deployments` comes with Vercel's deployment comment, whose markdown lists them a line each,
|
|
851
|
+
* for a platform that lays them out itself (Slack's table).
|
|
852
|
+
*/
|
|
829
853
|
type ProviderPost = {
|
|
830
854
|
markdown: string;
|
|
831
855
|
files?: ProviderFile[];
|
|
832
856
|
as?: ProviderSender;
|
|
857
|
+
deployments?: VercelDeployment[];
|
|
833
858
|
};
|
|
834
859
|
type ProviderDelivery = {
|
|
835
860
|
thread: string;
|
|
@@ -1034,4 +1059,4 @@ declare abstract class SyncProvider<E extends ProviderEvent = ProviderEvent> {
|
|
|
1034
1059
|
render(input: RenderInput): string;
|
|
1035
1060
|
}
|
|
1036
1061
|
//#endregion
|
|
1037
|
-
export { SyncRoot as A,
|
|
1062
|
+
export { SyncRoot as A, ReplyOptions as B, mirror as C, RootOverride as D, ProviderEvent as E, BoardError as F, duration as G, ScheduleTiming as H, ErrorOrigin as I, Filters as L, eventSchema as M, VercelDeployment as N, SyncOverrides as O, BoardClient as P, PostOptions as R, into as S, EventBase as T, UploadInput as U, ScheduleOptions as V, WaitOptions as W, SyncFn as _, ProviderOptions as a, SyncUnit as b, Receive as c, Renderer as d, ResolvedTarget as f, Sync as g, UnreadableError as h, ProviderFile as i, envelope as j, SyncResult as k, ReceivedEvent as l, SyncProvider as m, FileDelivery as n, ProviderPost as o, SyncContext as p, ProviderDelivery as r, ProviderSender as s, FetchedLink as t, RenderInput as u, SyncIn as v, render as w, channels as x, SyncOut as y, ProfileOption as z };
|
|
@@ -1206,6 +1206,8 @@ declare const SyncCopiesQuery: z.ZodObject<{
|
|
|
1206
1206
|
message: z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>, z.ZodTransform<string[], string | string[]>>, z.ZodArray<z.ZodString>>;
|
|
1207
1207
|
}, z.core.$strip>;
|
|
1208
1208
|
/** Platform events for a sync key's inbox, each with the platform's own ID for it, which dedupes it. */
|
|
1209
|
+
/** The longest inbox event ID a board takes: Vercel's API refuses a longer one. */
|
|
1210
|
+
declare const INBOX_EVENT_ID_MAX = 300;
|
|
1209
1211
|
declare const InboxPushBody: z.ZodObject<{
|
|
1210
1212
|
events: z.ZodArray<z.ZodObject<{
|
|
1211
1213
|
id: z.ZodString;
|
|
@@ -2670,4 +2672,4 @@ declare const routes: {
|
|
|
2670
2672
|
};
|
|
2671
2673
|
type RouteName = keyof typeof routes;
|
|
2672
2674
|
//#endregion
|
|
2673
|
-
export {
|
|
2675
|
+
export { ScheduleBody as $, parseCan as $t, LabelBody as A, ThreadsQueryInput as At, ParsedFilters as B, Can as Bt, InboxAckBody as C, SyncReceiptInput as Ct, InboxPushBody as D, ThreadView as Dt, InboxNextQuery as E, ThreadSummaryView as Et, Me as F, UploadStartBody as Ft, REGISTERED_WATCHERS_MAX as G, GrantChangeRefusal as Gt, PostInput as H, FULL_ACCESS as Ht, MessageView as I, UploadTicket as It, RegisterBody as J, Level as Jt, ReactBody as K, GrantShape as Kt, MessagesPage as L, routes as Lt, LinkedQuery as M, TypingResult as Mt, MatchView as N, UpdateGrantBody as Nt, InboxQuery as O, ThreadsPage as Ot, MatchesQuery as P, UpdateGrantInput as Pt, RouteName as Q, compileAccess as Qt, MessagesQuery as R, Access as Rt, INBOX_EVENT_ID_MAX as S, SyncReceiptBody as St, InboxItem as T, SyncedView as Tt, PrincipalInput as U, Grant as Ut, PostBody as V, ChannelPattern as Vt, PrincipalView as W, GrantChange as Wt, RegistrationView as X, WrittenCan as Xt, RegisterInput as Y, Permission as Yt, ResolvedSyncTarget as Z, checkGrantChange as Zt, FiltersInput as _, SyncFindInput as _t, BoardEventView as a, CAN_MAX as an, SchedulesQueryOutput as at, GrantInput as b, SyncImportBody as bt, CreateChannelBody as c, ExternalEvent as cn, SchemaView as ct, EditBody as d, Link as dn, SourceMessage as dt, union as en, ScheduleBodyOutput as et, EventsPage as f, SourceRead as ft, Explanation as g, SyncCopiesView as gt, ExplainQuery as h, SyncCopiesQuery as ht, BlockView as i, Author as in, SchedulesQueryInput as it, LinkView as j, TypingBody as jt, LABEL_CONDITIONS_MAX as k, ThreadsQuery as kt, DeleteBody as l, ExternalFile as ln, SourceJoin as lt, EventsQueryInput as m, SyncBody as mt, ActorView as n, ExternalCopy as nn, ScheduleView as nt, CanAt as o, Labels as on, SchemaBody as ot, EventsQuery as p, SourceReadQuery as pt, Ref as q, InvalidCan as qt, ApiError as r, Attachment as rn, SchedulesQuery as rt, ChannelView as s, ExternalAuthor as sn, SchemaInput as st, AckBody as t, Actor as tn, ScheduleInput as tt, Discovery as u, ExternalLink as un, SourceJoinBody as ut, GrantBody as v, SyncFindQuery as vt, InboxEntry as w, SyncThreadView as wt, GrantView as x, SyncImportInput as xt, GrantCan as y, SyncFindView as yt, MessagesQueryInput as z, AccessSummary as zt };
|