@ultimat3/storage 31.43.0 → 31.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/CLAUDE.md CHANGED
@@ -177,7 +177,7 @@ Gotchas:
177
177
  - **`VARIANT_FORMATS` is this package's format vocabulary, and `IMAGE_FORMATS` is core's.** †
178
178
  - `transformImage()` encodes at exactly `fitDimensions()`'s size, `format` explicit — anything else
179
179
  is a layout shift. †
180
- - Bun's S3 flag is `virtualHostedStyle`; our `forcePathStyle` is its inverse, and in virtual-hosted mode Bun takes the endpoint AS the bucket's host, so `clientTarget` puts the bucket in it (`bucketHost`) — the host `s3ObjectUrl` signs for.
180
+ - Bun's S3 flag is `virtualHostedStyle`; our `forcePathStyle` is its inverse, and in virtual-hosted mode Bun takes the endpoint AS the bucket's host, so `clientTarget` and `s3ObjectUrl` both build that host with one `bucketHost` (`driver-s3-signed.ts`): never the bucket twice.
181
181
  - **No `region` signs for `auto`** (R2's; AWS refuses it) — `regionMismatch()` makes it `X_CONFIG_INVALID` naming `S3_REGION`. Full rule: `docs/history/storage.md`.
182
182
  - The signature check runs BEFORE the expiry check. Do not reorder.
183
183
  - `timingSafeEqual` is `@ultimat3/core`'s (`signed-url.ts` imports it) — the same
package/README.md CHANGED
@@ -79,7 +79,10 @@ literals: a key in `app.config.ts` is a key in git. Missing ones throw `X_ENV_MI
79
79
  Endpoint, region and session token resolve ONCE for both transports, as Bun reads them: the
80
80
  option, then `S3_ENDPOINT`/`AWS_ENDPOINT`, `S3_REGION`/`AWS_REGION`,
81
81
  `S3_SESSION_TOKEN`/`AWS_SESSION_TOKEN` (or the one `sessionTokenEnv` names), from
82
- `s3Driver({ env })` or `process.env`. `s3Driver({ fetch, clock })` inject the signed path's transport and its clock (tests; default the
82
+ `s3Driver({ env })` or `process.env`. With `forcePathStyle: false` both transports address
83
+ `<bucket>.<endpoint host>` — or the endpoint as given when its host already starts with
84
+ `<bucket>.` (`https://media.acct.r2.cloudflarestorage.com`), never the bucket twice.
85
+ `s3Driver({ fetch, clock })` inject the signed path's transport and its clock (tests; default the
83
86
  global `fetch` and `systemClock`); `S3FetchLike` is the shape.
84
87
  `localDriver` keeps content type, etag, `cacheControl` and `metadata` in a `<root>/.meta/`
85
88
  sidecar so `get()`/`list()` round-trip everything `put()` was handed; sidecars never appear in
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/storage",
3
- "version": "31.43.0",
3
+ "version": "31.44.0",
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.43.0"
46
+ "@ultimat3/core": "31.44.0"
47
47
  }
48
48
  }
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { ConfigInvalidError } from '@ultimat3/core';
6
6
  import type { S3DriverOptions } from './driver-s3';
7
- import { requireEnv, resolveS3Target } from './driver-s3-signed';
7
+ import { bucketHost, requireEnv, resolveS3Target } from './driver-s3-signed';
8
8
 
9
9
  /** Structural view of `Bun.S3Client` — typing it here keeps `bun-types` out of the contract. */
10
10
  export interface S3FileLike {
@@ -53,18 +53,6 @@ interface S3ClientConstructor {
53
53
  new (options: Record<string, unknown>): S3ClientLike;
54
54
  }
55
55
 
56
- /**
57
- * Bun's virtual-hosted mode takes the endpoint AS the bucket's host, so the bucket goes into it
58
- * here — the host `s3ObjectUrl` signs for. The bare account endpoint sent every request to the
59
- * account root (on R2: an opaque `S3Error` for a read, `ListBuckets` for a list). An endpoint
60
- * that already names the bucket is kept.
61
- */
62
- function bucketHost(endpoint: string, bucket: string): string {
63
- const base = new URL(endpoint);
64
- if (base.host.startsWith(`${bucket}.`)) return endpoint;
65
- return `${base.protocol}//${bucket}.${base.host}`;
66
- }
67
-
68
56
  /**
69
57
  * Everything but the key pair `Bun.S3Client` is built with — the SAME `resolveS3Target` the signed
70
58
  * path reads, handed over explicitly so Bun never consults a second table.
@@ -76,7 +64,10 @@ export function clientTarget(options: S3DriverOptions): Record<string, unknown>
76
64
  const endpoint =
77
65
  target.endpoint === undefined || pathStyle !== false
78
66
  ? target.endpoint
79
- : bucketHost(target.endpoint, options.bucket);
67
+ : // Bun's virtual-hosted mode takes the endpoint AS the bucket's host: the bare account
68
+ // endpoint sent every request to the account root (on R2: an opaque `S3Error` for a read,
69
+ // `ListBuckets` for a list).
70
+ bucketHost(target.endpoint, options.bucket);
80
71
  return {
81
72
  bucket: options.bucket,
82
73
  ...(target.region === undefined ? {} : { region: target.region }),
@@ -198,6 +198,17 @@ export function s3Credentials(options: S3WireOptions): AwsCredentials {
198
198
  };
199
199
  }
200
200
 
201
+ /**
202
+ * The bucket's virtual-hosted origin: the bucket goes in front of the endpoint's host, unless the
203
+ * endpoint already names it (`https://media.acct.r2…` stays). ONE builder — `clientTarget` hands
204
+ * it to Bun, `s3ObjectUrl` signs for it — so the two transports cannot address two hosts.
205
+ */
206
+ export function bucketHost(endpoint: string, bucket: string): string {
207
+ const base = new URL(endpoint);
208
+ if (base.host.startsWith(`${bucket}.`)) return endpoint;
209
+ return `${base.protocol}//${bucket}.${base.host}`;
210
+ }
211
+
201
212
  /**
202
213
  * Bun's addressing, restated: path style unless `forcePathStyle` is EXPLICITLY false (Bun's own
203
214
  * `virtualHostedStyle` defaults to false), and AWS's regional endpoint when none is configured.
@@ -208,7 +219,8 @@ export function s3ObjectUrl(options: S3WireOptions, key: string): URL {
208
219
  const base = new URL(endpoint);
209
220
  const path = key.split('/').map(encodeURIComponent).join('/');
210
221
  if (options.forcePathStyle === false) {
211
- return new URL(`${base.protocol}//${options.bucket}.${base.host}/${path}`);
222
+ const host = new URL(bucketHost(endpoint, options.bucket));
223
+ return new URL(`${host.protocol}//${host.host}/${path}`);
212
224
  }
213
225
  const prefix = trimTrailingSlashes(base.pathname);
214
226
  return new URL(