@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/dist/blob-Bx8QPWEd.d.mts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import "./folds-DLUzfibJ.mjs";
|
|
2
|
-
import "./errors-2vGs49Db.mjs";
|
|
3
|
-
//#region src/server/blob.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Where attachments' bytes live. The board writes each file once, under a key
|
|
6
|
-
* it chose, and never overwrites it; `vercelBlob()` from `@vercel/board/backend-a2/blob-vercel` is the
|
|
7
|
-
* production one.
|
|
8
|
-
*/
|
|
9
|
-
type BlobStore = {
|
|
10
|
-
put(key: string, data: Uint8Array, contentType: string): Promise<void>;
|
|
11
|
-
/** Null when there's nothing under the key. */
|
|
12
|
-
get(key: string): Promise<{
|
|
13
|
-
data: ReadableStream<Uint8Array> | Uint8Array;
|
|
14
|
-
contentType: string;
|
|
15
|
-
} | null>;
|
|
16
|
-
/**
|
|
17
|
-
* For direct uploads, files too big for a request: a URL a client `PUT`s `key`'s bytes to,
|
|
18
|
-
* straight to the store, with `headers`. The store must bind it to `key`, refuse more than
|
|
19
|
-
* `maxBytes`, refuse to overwrite what's there, and stop taking it at `expiresAt`. With `head`,
|
|
20
|
-
* the board takes files up to `DIRECT_UPLOAD_BYTES_MAX`; without, uploads stay at 4 MB.
|
|
21
|
-
*/
|
|
22
|
-
uploadUrl?(key: string, options: {
|
|
23
|
-
contentType: string;
|
|
24
|
-
maxBytes: number;
|
|
25
|
-
expiresAt: Date;
|
|
26
|
-
}): Promise<{
|
|
27
|
-
url: string;
|
|
28
|
-
headers: Record<string, string>;
|
|
29
|
-
}>;
|
|
30
|
-
/** The size of what's under the key, or null when there's nothing: how the board checks a direct upload landed. */
|
|
31
|
-
head?(key: string): Promise<{
|
|
32
|
-
size: number;
|
|
33
|
-
} | null>;
|
|
34
|
-
};
|
|
35
|
-
/** Files in memory, for tests: forgets everything when the process ends. */
|
|
36
|
-
declare function memoryBlob(): BlobStore;
|
|
37
|
-
/** Files on disk, for development and `vb serve`: under `dir`, `.a2/attachments` by default. */
|
|
38
|
-
declare function fsBlob(dir?: string): BlobStore;
|
|
39
|
-
//#endregion
|
|
40
|
-
export { fsBlob as n, memoryBlob as r, BlobStore as t };
|
package/dist/blob-WbB2DJKn.mjs
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { n as DIRECT_UPLOAD_BYTES_MAX, t as ATTACHMENT_BYTES_MAX } from "./files-SniSmeEr.mjs";
|
|
2
|
-
import { i as Attachment } from "./schemas-DBmUO6pr.mjs";
|
|
3
|
-
import { r as badRequest, s as notFound, t as HttpError } from "./errors-CJXhhzvT.mjs";
|
|
4
|
-
import { randomBytes } from "node:crypto";
|
|
5
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
6
|
-
import { dirname, join } from "node:path";
|
|
7
|
-
//#region src/server/blob.ts
|
|
8
|
-
/** Files in memory, for tests: forgets everything when the process ends. */
|
|
9
|
-
function memoryBlob() {
|
|
10
|
-
const files = /* @__PURE__ */ new Map();
|
|
11
|
-
return {
|
|
12
|
-
put: async (key, data, contentType) => void files.set(key, {
|
|
13
|
-
data: data.slice(),
|
|
14
|
-
contentType
|
|
15
|
-
}),
|
|
16
|
-
get: async (key) => files.get(key) ?? null
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
/** Files on disk, for development and `vb serve`: under `dir`, `.a2/attachments` by default. */
|
|
20
|
-
function fsBlob(dir = ".a2/attachments") {
|
|
21
|
-
const path = (key) => join(dir, ...key.split("/"));
|
|
22
|
-
return {
|
|
23
|
-
async put(key, data, contentType) {
|
|
24
|
-
await mkdir(dirname(path(key)), { recursive: true });
|
|
25
|
-
await writeFile(path(key), data);
|
|
26
|
-
await writeFile(`${path(key)}.type`, contentType);
|
|
27
|
-
},
|
|
28
|
-
async get(key) {
|
|
29
|
-
try {
|
|
30
|
-
const [data, contentType] = await Promise.all([readFile(path(key)), readFile(`${path(key)}.type`, "utf8")]);
|
|
31
|
-
return {
|
|
32
|
-
data: new Uint8Array(data),
|
|
33
|
-
contentType
|
|
34
|
-
};
|
|
35
|
-
} catch {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
const dataKey = (id) => `board/attachments/${id}`;
|
|
42
|
-
/** A direct upload the board signed, until it's finished: what it's called, and who may finish it. */
|
|
43
|
-
const ticketKey = (id) => `board/uploads/${id}.json`;
|
|
44
|
-
const metaKey = (id) => `board/attachments/${id}.json`;
|
|
45
|
-
/** `shot.png`, as the board stores a name: no paths, no control characters. */
|
|
46
|
-
function fileName(name) {
|
|
47
|
-
return (name ?? "").split(/[\\/]/).pop().replace(/[\u0000-\u001f\u007f]/g, "").trim().slice(0, 255) || "file";
|
|
48
|
-
}
|
|
49
|
-
/** `image/png`, or `application/octet-stream` when the type isn't one. */
|
|
50
|
-
function mediaType(type) {
|
|
51
|
-
const value = (type ?? "").split(";")[0].trim().toLowerCase();
|
|
52
|
-
return /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/.test(value) && value.length <= 255 ? value : "application/octet-stream";
|
|
53
|
-
}
|
|
54
|
-
/** A board without a blob store keeps no files: every file route says so. */
|
|
55
|
-
const noBlob = () => new HttpError(501, "no_files", "this board keeps no files: pass `blob` to `a2()`");
|
|
56
|
-
/** 128 random bits, base64url, drawn again when they'd start with `-`, which a command line reads as a flag. */
|
|
57
|
-
function attachmentId() {
|
|
58
|
-
for (;;) {
|
|
59
|
-
const id = randomBytes(16).toString("base64url");
|
|
60
|
-
if (!id.startsWith("-")) return id;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Whether an upload is the caller's own, to read and attach before a message carries it: its
|
|
65
|
-
* principal sent it, and the caller holds no board token, or holds the one it came with or one
|
|
66
|
-
* that token was minted with. A token acts as its minter, so the principal alone would hand it
|
|
67
|
-
* every file its minter, or another of its minter's tokens, uploaded.
|
|
68
|
-
*/
|
|
69
|
-
function ownUpload(upload, caller) {
|
|
70
|
-
if (upload.uploadedBy !== caller.id) return false;
|
|
71
|
-
return caller.token === void 0 || (upload.uploadedWith?.includes(caller.token) ?? false);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Stores an upload under a fresh ID, with its metadata beside it. `uploadedBy`
|
|
75
|
-
* is the principal that sent it, who can read it before any message carries it,
|
|
76
|
-
* and `uploadedWith` the board tokens it came with (`ownUpload`).
|
|
77
|
-
* `max` is the most it can be: `ATTACHMENT_BYTES_MAX` unless the board's own sync imports it.
|
|
78
|
-
*/
|
|
79
|
-
async function writeUpload(blob, input, max = ATTACHMENT_BYTES_MAX) {
|
|
80
|
-
if (!blob) throw noBlob();
|
|
81
|
-
if (input.data.byteLength === 0) throw badRequest("the file is empty");
|
|
82
|
-
if (input.data.byteLength > max) throw new HttpError(413, "too_large", `attachments are at most ${max / 1024 / 1024} MB`);
|
|
83
|
-
const attachment = {
|
|
84
|
-
id: attachmentId(),
|
|
85
|
-
name: fileName(input.name),
|
|
86
|
-
type: mediaType(input.type),
|
|
87
|
-
size: input.data.byteLength
|
|
88
|
-
};
|
|
89
|
-
await blob.put(dataKey(attachment.id), input.data, attachment.type);
|
|
90
|
-
const meta = input.uploadedBy === void 0 ? attachment : {
|
|
91
|
-
...attachment,
|
|
92
|
-
uploadedBy: input.uploadedBy,
|
|
93
|
-
...input.uploadedWith ? { uploadedWith: input.uploadedWith } : {}
|
|
94
|
-
};
|
|
95
|
-
await blob.put(metaKey(attachment.id), new TextEncoder().encode(JSON.stringify(meta)), "application/json");
|
|
96
|
-
return attachment;
|
|
97
|
-
}
|
|
98
|
-
async function bytes(data) {
|
|
99
|
-
return data instanceof Uint8Array ? data : new Uint8Array(await new Response(data).arrayBuffer());
|
|
100
|
-
}
|
|
101
|
-
const attachmentNotFound = (id) => notFound(`no attachment: ${id}`, "attachment_not_found");
|
|
102
|
-
/**
|
|
103
|
-
* An upload's metadata, as the board recorded it, never what a request says,
|
|
104
|
-
* and who uploaded it: null for files the board imported itself, or stored
|
|
105
|
-
* before it recorded that.
|
|
106
|
-
*/
|
|
107
|
-
async function readUpload(blob, id) {
|
|
108
|
-
if (!blob) throw noBlob();
|
|
109
|
-
const found = Attachment.shape.id.safeParse(id).success ? await blob.get(metaKey(id)) : null;
|
|
110
|
-
if (!found) throw attachmentNotFound(id);
|
|
111
|
-
const meta = JSON.parse(new TextDecoder().decode(await bytes(found.data)));
|
|
112
|
-
const tokens = Array.isArray(meta.uploadedWith) && meta.uploadedWith.every((token) => typeof token === "string") ? meta.uploadedWith : null;
|
|
113
|
-
return {
|
|
114
|
-
attachment: Attachment.parse(meta),
|
|
115
|
-
uploadedBy: typeof meta.uploadedBy === "string" ? meta.uploadedBy : null,
|
|
116
|
-
uploadedWith: tokens
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
/** An attachment's bytes as the store keeps them, a stream or the bytes, for board() to serve. */
|
|
120
|
-
async function attachmentBody(blob, id) {
|
|
121
|
-
if (!blob) throw noBlob();
|
|
122
|
-
const found = await blob.get(dataKey(id));
|
|
123
|
-
if (!found) throw attachmentNotFound(id);
|
|
124
|
-
return found.data;
|
|
125
|
-
}
|
|
126
|
-
/** How long a direct upload's URL takes bytes: long enough for 100 MB on a slow link. */
|
|
127
|
-
const DIRECT_UPLOAD_TTL_MS = 18e5;
|
|
128
|
-
const noDirectUploads = () => new HttpError(501, "no_direct_uploads", `this board's blob store can't take direct uploads, so files are at most ${ATTACHMENT_BYTES_MAX / 1024 / 1024} MB`);
|
|
129
|
-
/**
|
|
130
|
-
* Starts a direct upload: a fresh ID, and a URL in the store to `PUT` its bytes to. The board
|
|
131
|
-
* keeps what the request said the file is until `finishUpload` checks the store has it.
|
|
132
|
-
*/
|
|
133
|
-
async function startUpload(blob, input) {
|
|
134
|
-
if (!blob) throw noBlob();
|
|
135
|
-
if (!blob.uploadUrl || !blob.head) throw noDirectUploads();
|
|
136
|
-
if (input.size > 104857600) throw new HttpError(413, "too_large", `direct uploads are at most ${DIRECT_UPLOAD_BYTES_MAX / 1024 / 1024} MB`);
|
|
137
|
-
const expires = new Date(Date.now() + DIRECT_UPLOAD_TTL_MS);
|
|
138
|
-
const ticket = {
|
|
139
|
-
id: attachmentId(),
|
|
140
|
-
name: fileName(input.name),
|
|
141
|
-
type: mediaType(input.type),
|
|
142
|
-
size: input.size,
|
|
143
|
-
uploadedBy: input.uploadedBy,
|
|
144
|
-
...input.uploadedWith ? { uploadedWith: input.uploadedWith } : {},
|
|
145
|
-
expiresAt: expires.toISOString()
|
|
146
|
-
};
|
|
147
|
-
await blob.put(ticketKey(ticket.id), new TextEncoder().encode(JSON.stringify(ticket)), "application/json");
|
|
148
|
-
const { url, headers } = await blob.uploadUrl(dataKey(ticket.id), {
|
|
149
|
-
contentType: ticket.type,
|
|
150
|
-
maxBytes: ticket.size,
|
|
151
|
-
expiresAt: expires
|
|
152
|
-
});
|
|
153
|
-
return {
|
|
154
|
-
id: ticket.id,
|
|
155
|
-
url,
|
|
156
|
-
headers: {
|
|
157
|
-
...headers,
|
|
158
|
-
"content-type": ticket.type
|
|
159
|
-
},
|
|
160
|
-
expiresAt: ticket.expiresAt
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Finishes a direct upload: once the store has exactly the bytes its start said, the board records
|
|
165
|
-
* the attachment, as `writeUpload` does. Only its uploader may finish it (`ownUpload`); a second
|
|
166
|
-
* finish answers the same attachment. It never reads the record before writing it: a store with a
|
|
167
|
-
* cache (Vercel Blob's CDN) would keep that miss, and the post that names the file would find nothing.
|
|
168
|
-
*/
|
|
169
|
-
async function finishUpload(blob, id, caller) {
|
|
170
|
-
if (!blob) throw noBlob();
|
|
171
|
-
const found = Attachment.shape.id.safeParse(id).success ? await blob.get(ticketKey(id)) : null;
|
|
172
|
-
const ticket = found ? JSON.parse(new TextDecoder().decode(await bytes(found.data))) : null;
|
|
173
|
-
if (!ticket || !ownUpload(ticket, caller)) throw notFound(`no upload: ${id}`, "upload_not_found");
|
|
174
|
-
if (!blob.head) throw noDirectUploads();
|
|
175
|
-
const stored = await blob.head(dataKey(id));
|
|
176
|
-
if (!stored) throw new HttpError(409, "not_uploaded", `nothing's been uploaded for ${id} yet: PUT the file to its URL first`);
|
|
177
|
-
if (stored.size !== ticket.size) throw badRequest(`the store has ${stored.size} bytes for ${id}, but its upload said ${ticket.size}`, "size_mismatch");
|
|
178
|
-
const attachment = {
|
|
179
|
-
id,
|
|
180
|
-
name: ticket.name,
|
|
181
|
-
type: ticket.type,
|
|
182
|
-
size: stored.size
|
|
183
|
-
};
|
|
184
|
-
try {
|
|
185
|
-
const uploader = {
|
|
186
|
-
uploadedBy: ticket.uploadedBy,
|
|
187
|
-
...ticket.uploadedWith ? { uploadedWith: ticket.uploadedWith } : {}
|
|
188
|
-
};
|
|
189
|
-
await blob.put(metaKey(id), new TextEncoder().encode(JSON.stringify({
|
|
190
|
-
...attachment,
|
|
191
|
-
...uploader
|
|
192
|
-
})), "application/json");
|
|
193
|
-
} catch (error) {
|
|
194
|
-
const done = await blob.get(metaKey(id)).catch(() => null);
|
|
195
|
-
if (!done) throw error;
|
|
196
|
-
return Attachment.parse(JSON.parse(new TextDecoder().decode(await bytes(done.data))));
|
|
197
|
-
}
|
|
198
|
-
return attachment;
|
|
199
|
-
}
|
|
200
|
-
//#endregion
|
|
201
|
-
export { fsBlob as a, ownUpload as c, writeUpload as d, finishUpload as i, readUpload as l, attachmentNotFound as n, mediaType as o, fileName as r, memoryBlob as s, attachmentBody as t, startUpload as u };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { r as ErrorOrigin } from "./client-COfYrgfV.mjs";
|
|
2
|
-
//#region src/server/errors.d.ts
|
|
3
|
-
declare class HttpError extends Error {
|
|
4
|
-
readonly status: number;
|
|
5
|
-
readonly code: string;
|
|
6
|
-
/** What fixes it, when there's one (`BoardError`'s `hint`). */
|
|
7
|
-
readonly hint: string | undefined;
|
|
8
|
-
/** `handle` for a handle's own error on its way through: everything else is the board's. */
|
|
9
|
-
readonly origin: ErrorOrigin;
|
|
10
|
-
constructor(status: number, code: string, message: string, options?: {
|
|
11
|
-
hint?: string;
|
|
12
|
-
origin?: ErrorOrigin;
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
16
|
-
export { HttpError as t };
|