cursedbelt-server 4.61.0 → 4.62.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.
@@ -112,6 +112,13 @@ export interface PutOptions {
112
112
  * bytes at the edge and in every browser for a year.
113
113
  */
114
114
  immutable?: boolean;
115
+ /**
116
+ * Who sent these bytes — the app's own id for its sender, the token's `uid`, exactly as
117
+ * `createUploadSession` names one. binary-server records it on the upload's event, and station's
118
+ * Uploads page says who from it. Pass it on a road a person's file takes; a write the app does
119
+ * for itself (a poster, a derivative) has no sender.
120
+ */
121
+ ownerId?: string;
115
122
  }
116
123
  export interface MediaUrlOptions {
117
124
  filename?: string;
@@ -452,7 +452,7 @@ export function createBinaryStore(cfg) {
452
452
  if (bytes.byteLength > autoChunkBytes) {
453
453
  return await store.putLarge(key, bytes, mime, opts);
454
454
  }
455
- const token = await signToken({ k: appKey(key) }, UPLOAD_TOKEN_TTL_SECONDS);
455
+ const token = await signToken({ k: appKey(key), ...(opts?.ownerId ? { uid: opts.ownerId } : {}) }, UPLOAD_TOKEN_TTL_SECONDS);
456
456
  const title = opts?.title?.trim();
457
457
  const titleQs = title ? `&title=${encodeURIComponent(title)}` : '';
458
458
  const immutableQs = opts?.immutable ? '&immutable=1' : '';
@@ -525,7 +525,7 @@ export function createBinaryStore(cfg) {
525
525
  // object (see `FileTokenClaims.sz` in `./types`). `total` is derived from `blob.size`
526
526
  // two lines up, so the number is already in hand — declaring it costs nothing, and
527
527
  // NOT declaring it is what left 579 of 579 fleet assembles unprovable on 2026-09-18.
528
- const token = await signToken({ k: appKey(key), sid, ci, tc: total, sz: blob.size }, UPLOAD_TOKEN_TTL_SECONDS);
528
+ const token = await signToken({ k: appKey(key), sid, ci, tc: total, sz: blob.size, ...(opts?.ownerId ? { uid: opts.ownerId } : {}) }, UPLOAD_TOKEN_TTL_SECONDS);
529
529
  const slice = new Uint8Array(await blob
530
530
  .slice(ci * chunkBytes, Math.min((ci + 1) * chunkBytes, blob.size))
531
531
  .arrayBuffer());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cursedbelt-server",
3
- "version": "4.61.0",
3
+ "version": "4.62.0",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "description": "The app-facing Bun/Hono server tier of the cursedbelt split — storage, sharing, activity, guard, sync. React-free; cursedbelt-core below it.",
@@ -423,7 +423,7 @@
423
423
  "@node-rs/argon2": "^2.0.2",
424
424
  "@types/bun": "^1.3.14",
425
425
  "@types/node": "^24",
426
- "cursedbelt": "^5.108.0",
426
+ "cursedbelt": "^5.109.0",
427
427
  "hono": "4.12.28",
428
428
  "kysely": "^0.28.17",
429
429
  "kysely-bun-sqlite": "^0.4.0",
@@ -211,6 +211,18 @@ describe('put', () => {
211
211
  expect(tokenOf(call.url).payload.exp - tokenOf(call.url).payload.iat).toBe(600);
212
212
  });
213
213
 
214
+ it('🔴 names its sender on the token only when asked — a whole upload is a road a person takes too', async () => {
215
+ // A browser file small enough for an app's own `/api/upload` comes through here, not through
216
+ // `createUploadSession`. Without the claim binary-server records `from: web` and nobody.
217
+ const store = makeStore();
218
+ reply = () => ok(null, { status: 201 });
219
+ await store.put('file/a', new Uint8Array([1]), 'text/plain', { ownerId: 'acct-1' });
220
+ await store.put('poster/a', new Uint8Array([1]), 'image/png');
221
+
222
+ expect(tokenOf(calls[0]!.url).payload.uid).toBe('acct-1');
223
+ expect('uid' in tokenOf(calls[1]!.url).payload).toBe(false);
224
+ });
225
+
214
226
  it('sends title and immutable as query parameters only when asked', async () => {
215
227
  const store = makeStore();
216
228
  reply = () => ok(null, { status: 201 });
@@ -290,6 +302,15 @@ describe('putLarge', () => {
290
302
  expect(claims.every((p) => p.k === 'roms/video/x')).toBe(true);
291
303
  });
292
304
 
305
+ it('🔴 names its sender on every chunk — `put` above the threshold lands here with the same options', async () => {
306
+ const store = makeStore({ autoChunkBytes: 4 });
307
+ reply = () => ok(null, { status: 201 });
308
+ await store.putLarge('video/x', new Uint8Array(10), 'video/mp4', { ownerId: 'acct-1', chunkBytes: 4 });
309
+ await store.put('video/y', new Uint8Array(10), 'video/mp4', { ownerId: 'acct-1' });
310
+
311
+ expect(calls.map((c) => tokenOf(c.url).payload.uid)).toEqual(['acct-1', 'acct-1', 'acct-1', 'acct-1']);
312
+ });
313
+
293
314
  it('🔴 declares the SOURCE byte length as `sz` on every chunk, whatever the split', async () => {
294
315
  // The claim that makes `tc` above not load-bearing. binary-server checks `sz` before and
295
316
  // after assembly and answers 422 rather than indexing a short object — but only for a
@@ -209,6 +209,13 @@ export interface PutOptions {
209
209
  * bytes at the edge and in every browser for a year.
210
210
  */
211
211
  immutable?: boolean;
212
+ /**
213
+ * Who sent these bytes — the app's own id for its sender, the token's `uid`, exactly as
214
+ * `createUploadSession` names one. binary-server records it on the upload's event, and station's
215
+ * Uploads page says who from it. Pass it on a road a person's file takes; a write the app does
216
+ * for itself (a poster, a derivative) has no sender.
217
+ */
218
+ ownerId?: string;
212
219
  }
213
220
 
214
221
  export interface MediaUrlOptions {
@@ -766,7 +773,10 @@ export function createBinaryStore(cfg: BinaryStoreConfig): BinaryStore {
766
773
  if (bytes.byteLength > autoChunkBytes) {
767
774
  return await store.putLarge(key, bytes, mime, opts);
768
775
  }
769
- const token = await signToken({ k: appKey(key) }, UPLOAD_TOKEN_TTL_SECONDS);
776
+ const token = await signToken(
777
+ { k: appKey(key), ...(opts?.ownerId ? { uid: opts.ownerId } : {}) },
778
+ UPLOAD_TOKEN_TTL_SECONDS,
779
+ );
770
780
  const title = opts?.title?.trim();
771
781
  const titleQs = title ? `&title=${encodeURIComponent(title)}` : '';
772
782
  const immutableQs = opts?.immutable ? '&immutable=1' : '';
@@ -845,7 +855,7 @@ export function createBinaryStore(cfg: BinaryStoreConfig): BinaryStore {
845
855
  // two lines up, so the number is already in hand — declaring it costs nothing, and
846
856
  // NOT declaring it is what left 579 of 579 fleet assembles unprovable on 2026-09-18.
847
857
  const token = await signToken(
848
- { k: appKey(key), sid, ci, tc: total, sz: blob.size },
858
+ { k: appKey(key), sid, ci, tc: total, sz: blob.size, ...(opts?.ownerId ? { uid: opts.ownerId } : {}) },
849
859
  UPLOAD_TOKEN_TTL_SECONDS,
850
860
  );
851
861
  const slice = new Uint8Array(