@ultimat3/storage 31.46.0 → 31.47.1

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 (2) hide show
  1. package/README.md +28 -3
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -7,10 +7,13 @@ Named disks. **Call sites name a disk, never a driver.**
7
7
  ```ts
8
8
  import { defineStorage, disk, localDriver, s3Driver, scopedKey } from '@ultimat3/storage';
9
9
 
10
+ declare const orgId: string;
11
+ declare const bytes: Uint8Array;
12
+
10
13
  defineStorage({
11
14
  disks: {
12
15
  uploads: localDriver({ root: '.storage/uploads' }),
13
- media: s3Driver({ bucket: 'media', endpoint: process.env.S3_ENDPOINT, forcePathStyle: true }),
16
+ media: s3Driver({ bucket: 'media', endpoint: process.env['S3_ENDPOINT'], forcePathStyle: true }),
14
17
  },
15
18
  default: 'uploads', // omit and the first disk wins
16
19
  shared: { media: ['brand/'] }, // the only un-scoped keys /_storage and /media serve (27.0.0)
@@ -408,9 +411,31 @@ policy never allowed.
408
411
 
409
412
  ```ts
410
413
  // 1. server, inside an action's handle: mint the grant
414
+ import { type Ctx } from '@ultimat3/core';
415
+ import {
416
+ acceptSignedUpload,
417
+ disk,
418
+ grantUpload,
419
+ uploadFile,
420
+ uploadPolicy,
421
+ } from '@ultimat3/storage';
422
+
423
+ type UploadInput = Parameters<typeof uploadFile>[0];
424
+ declare function orgOf(actor: Ctx['actor']): string;
425
+ declare const ctx: Ctx;
426
+ declare const request: Request;
427
+ declare const secret: string;
428
+ declare const bytes: Uint8Array;
429
+ declare const filename: string;
430
+ declare const contentType: string;
431
+ declare const size: number;
432
+ declare const file: UploadInput['file'];
433
+ declare const onProgress: UploadInput['onProgress'];
434
+ declare const api: { requestUpload: UploadInput['grant'] };
435
+
411
436
  const grant = await grantUpload({
412
437
  disk: disk('uploads'),
413
- orgId: ctx.actor.orgId, // the ACTOR's org, never one read off the request
438
+ orgId: orgOf(ctx.actor), // the ACTOR's org, never one read off the request
414
439
  request: { filename, contentType, size },
415
440
  policy: uploadPolicy({ maxBytes: 5e6 }),
416
441
  // target: { entity: 'post', id, field: 'cover' } — omit it and the key lands under `pending/`
@@ -424,7 +449,7 @@ const object = await acceptSignedUpload({
424
449
  url: request.url, // baseUrl defaults to `disk.signedUrlBase` — the very base
425
450
  secret, // the driver signed under, `/_storage/<disk name>`. Pass one
426
451
  disk: disk('uploads'), // only for a route mounted somewhere else.
427
- orgId: ctx.actor.orgId,
452
+ orgId: orgOf(ctx.actor),
428
453
  bytes, declaredContentType: request.headers.get('content-type') ?? undefined,
429
454
  policy: uploadPolicy({ maxBytes: 5e6 }),
430
455
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/storage",
3
- "version": "31.46.0",
3
+ "version": "31.47.1",
4
4
  "description": "Named disks over Bun.file and Bun.s3: safe keys, signed URLs, sniffed uploads",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -43,6 +43,6 @@
43
43
  "test": "bun test"
44
44
  },
45
45
  "dependencies": {
46
- "@ultimat3/core": "31.46.0"
46
+ "@ultimat3/core": "31.47.1"
47
47
  }
48
48
  }