@vercel/board 0.31.0 → 0.33.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.
Files changed (166) hide show
  1. package/README.md +25 -20
  2. package/dist/{access-CY5xVMIK.mjs → access-N3XmkKXg.mjs} +3 -3
  3. package/dist/access.d.mts +4 -5
  4. package/dist/access.mjs +5 -5
  5. package/dist/{actors-Bm-ojWWT.mjs → actors-ihyN47OV.mjs} +3 -3
  6. package/dist/{auth-DLYSt_-A.d.mts → auth-D6z3rMNj.d.mts} +11 -93
  7. package/dist/{auth-CyO2aw5n.mjs → auth-r-_PeZyw.mjs} +39 -151
  8. package/dist/{backend-Bob-5CM7.d.mts → backend-CWpyR1A7.d.mts} +81 -51
  9. package/dist/backend-local.d.mts +28 -0
  10. package/dist/backend-local.mjs +2 -0
  11. package/dist/{chat-provider-DkFp2hrh.mjs → chat-provider-9hCT654s.mjs} +2 -2
  12. package/dist/{chat-provider-BChYrrA7.d.mts → chat-provider-DJpFUaFv.d.mts} +2 -3
  13. package/dist/cli-commands.d.mts +1 -1
  14. package/dist/cli-commands.mjs +1 -1
  15. package/dist/cli-embedded.d.mts +2 -2
  16. package/dist/cli-embedded.mjs +2 -2
  17. package/dist/cli.mjs +6 -6
  18. package/dist/{commands-DK4W3HCJ.d.mts → commands-BOBQHVqM.d.mts} +14 -0
  19. package/dist/{commands-L1JSGz2Z.mjs → commands-CHoMl06v.mjs} +39 -12
  20. package/dist/{conformance-DK43HiHf.mjs → conformance-qKmGLTAT.mjs} +40 -5
  21. package/dist/conformance.d.mts +1 -1
  22. package/dist/conformance.mjs +1 -1
  23. package/dist/{engine-DurYIRt8.mjs → engine-JxgZiikU.mjs} +6 -8
  24. package/dist/{errors-CJXhhzvT.mjs → errors-Pk0XV1hK.mjs} +56 -2
  25. package/dist/{events-lujPA3gQ.mjs → events-IQg0k281.mjs} +2 -2
  26. package/dist/exports-BuKjVq2t.d.mts +4 -0
  27. package/dist/exports-gHDHlg0i.mjs +3207 -0
  28. package/dist/{external-D3p5T57R.mjs → external-CYe424fO.mjs} +1 -1
  29. package/dist/{folds-DLUzfibJ.d.mts → folds-DjFTiqIM.d.mts} +38 -44
  30. package/dist/index-CXvvYNYj.d.mts +11 -0
  31. package/dist/index.d.mts +9 -8
  32. package/dist/index.mjs +21 -8
  33. package/dist/index.node.d.mts +5 -6
  34. package/dist/index.node.mjs +3 -3
  35. package/dist/inspect/app.js +95 -95
  36. package/dist/{internal-CvsrprnU-zZMpDiRY.mjs → internal-CvsrprnU-CEPOUpAv.mjs} +63 -43
  37. package/dist/local-BbLjA5vI.mjs +8818 -0
  38. package/dist/{main-Dz-8komG.mjs → main-CQpCZJFw.mjs} +140 -36
  39. package/dist/{backend-a2/store-memory.mjs → memory-7RRnLa4X.mjs} +3 -3
  40. package/dist/middleware-BU7rVi9F.mjs +103 -0
  41. package/dist/{client-COfYrgfV.d.mts → provider-BlzUvcM9.d.mts} +665 -5
  42. package/dist/{schemas-DBmUO6pr.mjs → schemas-BG205xds.mjs} +2 -5
  43. package/dist/{serve-CTmow-YH.mjs → serve-D8_W4UN6.mjs} +33 -24
  44. package/dist/{node-BgeGcwX0.mjs → server-BiIUXWbU.mjs} +419 -6
  45. package/dist/{serving-DBFRo6U_.mjs → serving-D7rcUtSC.mjs} +1 -1
  46. package/dist/{sql-CT5xVuGr.mjs → sql-BQzKUqQt.mjs} +349 -114
  47. package/dist/sqlite-DCtZFEVm.mjs +30 -0
  48. package/dist/{sqlite-db-0WeSOEZN.mjs → sqlite-db-qLTs52Ny.mjs} +2 -3
  49. package/dist/{store-codec-pAG2oPgQ-SqDXlPBR.mjs → store-N8PXxDAS-BdL4Sq-f.mjs} +6 -2
  50. package/dist/{store-memory-B0PkVSuQ.mjs → store-memory-CKQVEzXN.mjs} +2 -4
  51. package/dist/store-memory-OdGsc-t_.mjs +2 -0
  52. package/dist/{store-polling-BZt2Rf3D-Div-bJ_D.mjs → store-polling-BZt2Rf3D-oh3aU_An.mjs} +1 -1
  53. package/dist/store-sqlite-CTxAVCcz.mjs +2 -0
  54. package/dist/{store-sqlite-D85t3tE7.mjs → store-sqlite-D6fIszST.mjs} +3 -4
  55. package/dist/sync-chat-sdk.d.mts +2 -2
  56. package/dist/sync-chat-sdk.mjs +2 -2
  57. package/dist/sync-github.d.mts +2 -2
  58. package/dist/sync-github.mjs +2 -2
  59. package/dist/sync-linear.d.mts +2 -3
  60. package/dist/sync-linear.mjs +2 -2
  61. package/dist/sync-slack.d.mts +3 -3
  62. package/dist/sync-slack.mjs +4 -4
  63. package/dist/sync.d.mts +2 -2
  64. package/dist/sync.mjs +2 -2
  65. package/dist/{watchers-hash-BjwlnGD9.mjs → targets-CknPGGVi.mjs} +40 -10
  66. package/dist/{tokens-Dnyd_y1n.mjs → tokens-DPKjl3jf.mjs} +15 -43
  67. package/docs/01-board/01-mounting.md +243 -288
  68. package/docs/01-board/03-identity.md +41 -50
  69. package/docs/01-board/04-messages.md +19 -16
  70. package/docs/01-board/05-reading.md +3 -3
  71. package/docs/01-board/06-watchers.md +58 -105
  72. package/docs/01-board/07-schedules.md +21 -41
  73. package/docs/01-board/08-middleware.md +11 -17
  74. package/docs/01-board/09-access.md +76 -313
  75. package/docs/01-board/10-local.md +81 -0
  76. package/docs/01-quickstart.md +49 -126
  77. package/docs/02-sync/01-overview.md +25 -80
  78. package/docs/02-sync/02-functions.md +10 -16
  79. package/docs/02-sync/03-slack.md +13 -26
  80. package/docs/02-sync/04-github.md +8 -20
  81. package/docs/02-sync/07-linear.md +6 -10
  82. package/docs/03-guides/02-inspector.md +3 -3
  83. package/docs/03-guides/03-ci.md +88 -128
  84. package/docs/03-guides/04-triage.md +7 -15
  85. package/docs/03-guides/05-agent-factory.md +30 -36
  86. package/docs/04-reference/01-cli.md +118 -32
  87. package/docs/04-reference/02-board.md +60 -74
  88. package/docs/04-reference/03-http.md +119 -57
  89. package/docs/04-reference/05-conformance.md +31 -45
  90. package/docs/index.md +41 -65
  91. package/package.json +12 -83
  92. package/dist/a2-DngWY2Eb.mjs +0 -4238
  93. package/dist/access-DPcrKIH_.d.mts +0 -37
  94. package/dist/backend-a2/blob-vercel.d.mts +0 -8
  95. package/dist/backend-a2/blob-vercel.mjs +0 -81
  96. package/dist/backend-a2/contract.d.mts +0 -828
  97. package/dist/backend-a2/contract.mjs +0 -5
  98. package/dist/backend-a2/scheduler-local.d.mts +0 -11
  99. package/dist/backend-a2/scheduler-local.mjs +0 -2
  100. package/dist/backend-a2/scheduler-qstash.d.mts +0 -79
  101. package/dist/backend-a2/scheduler-qstash.mjs +0 -522
  102. package/dist/backend-a2/scheduler-vercel.d.mts +0 -38
  103. package/dist/backend-a2/scheduler-vercel.mjs +0 -204
  104. package/dist/backend-a2/store-memory.d.mts +0 -11
  105. package/dist/backend-a2/store-postgres.d.mts +0 -38
  106. package/dist/backend-a2/store-postgres.mjs +0 -2977
  107. package/dist/backend-a2/store-redis-http.d.mts +0 -17
  108. package/dist/backend-a2/store-redis-http.mjs +0 -520
  109. package/dist/backend-a2/store-redis.d.mts +0 -31
  110. package/dist/backend-a2/store-redis.mjs +0 -88
  111. package/dist/backend-a2/store-sqlite.d.mts +0 -12
  112. package/dist/backend-a2/store-sqlite.mjs +0 -31
  113. package/dist/backend-a2.d.mts +0 -2633
  114. package/dist/backend-a2.mjs +0 -3
  115. package/dist/backend-http-BRrRbjRx.d.mts +0 -672
  116. package/dist/backend-http-CvUKOn-m.mjs +0 -585
  117. package/dist/backend-http-D8mUzuKQ.mjs +0 -18
  118. package/dist/backend-http.d.mts +0 -10
  119. package/dist/backend-http.mjs +0 -2
  120. package/dist/backend-http.node.d.mts +0 -10
  121. package/dist/backend-http.node.mjs +0 -2
  122. package/dist/backend-vercel-Ba8JDtqW.mjs +0 -86
  123. package/dist/backend-vercel-BaSEUdwg.d.mts +0 -674
  124. package/dist/backend-vercel-CmY9yZ9m.mjs +0 -1656
  125. package/dist/backend-vercel.d.mts +0 -9
  126. package/dist/backend-vercel.mjs +0 -11
  127. package/dist/backend-vercel.node.d.mts +0 -17
  128. package/dist/backend-vercel.node.mjs +0 -2
  129. package/dist/blob-Bx8QPWEd.d.mts +0 -40
  130. package/dist/blob-WbB2DJKn.mjs +0 -201
  131. package/dist/errors-2vGs49Db.d.mts +0 -16
  132. package/dist/exports-CWIdN0Ub.mjs +0 -1389
  133. package/dist/exports-FBOQWT7O.d.mts +0 -5
  134. package/dist/files-SniSmeEr.mjs +0 -47
  135. package/dist/folds-Cu9Q9zyQ.mjs +0 -207
  136. package/dist/index-Ho-ayyQL.d.mts +0 -11
  137. package/dist/index.default-BUcwDaAe.mjs +0 -12
  138. package/dist/local-C76Fy5ad.mjs +0 -44
  139. package/dist/middleware-BavYSDUa.mjs +0 -62
  140. package/dist/platform-B4TnJtWu-Do3agKr5.mjs +0 -32
  141. package/dist/project-CQ4VUibA.mjs +0 -124
  142. package/dist/provider-gynDUoyW.d.mts +0 -665
  143. package/dist/redis-tables-DHf85ixI.mjs +0 -3895
  144. package/dist/reducer-Bswr11ar-P324o9vn.mjs +0 -74
  145. package/dist/reducer-CYPHsSmd-BXjGiptm.d.mts +0 -170
  146. package/dist/reducers-DcENwtwZ.mjs +0 -538
  147. package/dist/retryable-lazy-DZWmHpii-DpTc5PIP.mjs +0 -19
  148. package/dist/scheduler-task-X1SToDjP-D2Il2rln.mjs +0 -69
  149. package/dist/server-B9gu0qi1-DI1WvcVK.d.mts +0 -391
  150. package/dist/server-DG8D6VV0.mjs +0 -17
  151. package/dist/server-DX7mM6nm-D7N_7bug.mjs +0 -3611
  152. package/dist/session-clear-XJYpmUpg-2q8l_FJR.mjs +0 -63
  153. package/dist/store-DEzcHZOA-B-5vhxef.d.mts +0 -540
  154. package/dist/store-N8PXxDAS-DWWgv-Vz.mjs +0 -5
  155. package/dist/store-memory-4IBl0Ztu.mjs +0 -2
  156. package/dist/store-presence-polling-JuAy2Ck2-Dh-g_KYM.mjs +0 -109
  157. package/dist/store-sqlite-iBTYYKBj.mjs +0 -2
  158. package/dist/stream-buffer-DrTyiIuo-Be10yOBR.mjs +0 -53
  159. package/dist/targets-Cgjs29T0.mjs +0 -33
  160. package/dist/types-CmrFjpml.d.mts +0 -102
  161. package/dist/wait-until-Dw4XrIDQ.mjs +0 -42
  162. package/docs/01-board/02-database.md +0 -258
  163. package/docs/04-reference/04-log.md +0 -247
  164. package/sql/postgres/board.sql +0 -145
  165. package/sql/postgres/notifications.sql +0 -24
  166. package/sql/postgres/schema.sql +0 -451
@@ -1,9 +0,0 @@
1
- import { n as VercelOptions, t as VercelBackend } from "./backend-vercel-BaSEUdwg.mjs";
2
- //#region src/backend-vercel/index.default.d.ts
3
- /**
4
- * Your team's board, in Vercel's API. Outside Node there's no environment to find credentials or
5
- * the team in: pass `team`, and a `fetch` that sends a token Vercel's API takes.
6
- */
7
- export declare function vercel(options?: VercelOptions): VercelBackend;
8
- //#endregion
9
- export type { VercelBackend, VercelOptions };
@@ -1,11 +0,0 @@
1
- import { t as createVercel } from "./backend-vercel-CmY9yZ9m.mjs";
2
- //#region src/backend-vercel/index.default.ts
3
- /**
4
- * Your team's board, in Vercel's API. Outside Node there's no environment to find credentials or
5
- * the team in: pass `team`, and a `fetch` that sends a token Vercel's API takes.
6
- */
7
- function vercel(options = {}) {
8
- return createVercel(options, null);
9
- }
10
- //#endregion
11
- export { vercel };
@@ -1,17 +0,0 @@
1
- import { n as VercelOptions, t as VercelBackend } from "./backend-vercel-BaSEUdwg.mjs";
2
- //#region src/backend-vercel/index.d.ts
3
- /** Where `token` comes from, in words: what `vb whoami` says. */
4
- export declare function credentialSource(): string;
5
- /**
6
- * Hands board the team to use when nothing names one (`--scope` still wins), resolved as the app
7
- * resolves its own and asked for only when a request needs it. Null takes it back.
8
- */
9
- export declare function handTeam(resolve: (() => Promise<string | null>) | null): void;
10
- /**
11
- * Your team's board, in Vercel's API: this board keeps nothing, and reads and writes that one as
12
- * this deployment's project, or as you. Without `board`, the team's board; without `fetch`, it
13
- * sends the credentials the Vercel CLI or the deployment has.
14
- */
15
- export declare function vercel(options?: VercelOptions): VercelBackend;
16
- //#endregion
17
- export type { VercelBackend, VercelOptions };
@@ -1,2 +0,0 @@
1
- import { n as handTeam, r as vercel, t as credentialSource } from "./backend-vercel-Ba8JDtqW.mjs";
2
- export { credentialSource, handTeam, vercel };
@@ -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 };
@@ -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 };