@gusto/baerly-storage 0.4.1 → 0.6.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 (104) hide show
  1. package/dist/API.md +3 -2
  2. package/dist/CHANGELOG.md +125 -0
  3. package/dist/THIRD-PARTY-LICENSES.txt +1 -1
  4. package/dist/auth.d.ts +1 -1
  5. package/dist/aws4fetch.esm-CXE5ZbAa.js +460 -0
  6. package/dist/aws4fetch.esm-CXE5ZbAa.js.map +1 -0
  7. package/dist/baerly.js +10 -10
  8. package/dist/baerly.spec.json +1 -1
  9. package/dist/client-react.d.ts +2 -2
  10. package/dist/{client-Fe8CwB73.d.ts → client-ypCm3zjt.d.ts} +2 -2
  11. package/dist/client.d.ts +2 -2
  12. package/dist/{cloudflare-DzKBrUlg.js → cloudflare-wrVYf4bb.js} +457 -56
  13. package/dist/cloudflare-wrVYf4bb.js.map +1 -0
  14. package/dist/cloudflare.d.ts +13 -10
  15. package/dist/cloudflare.js +6 -6
  16. package/dist/cloudflare.js.map +1 -1
  17. package/dist/{config-1tv0-Yzm.js → config-B6nTy8e2.js} +435 -33
  18. package/dist/config-B6nTy8e2.js.map +1 -0
  19. package/dist/constants-CfeMWQWk.js.map +1 -1
  20. package/dist/{cost-DSMIVqzL.js → cost-_SE_SVgZ.js} +4 -4
  21. package/dist/{cost-DSMIVqzL.js.map → cost-_SE_SVgZ.js.map} +1 -1
  22. package/dist/{db-DsPkOVEH.d.ts → db-DjjthkTi.d.ts} +2 -2
  23. package/dist/{deploy-DonTr-CV.js → deploy-Di_Q01qx.js} +5 -5
  24. package/dist/deploy-Di_Q01qx.js.map +1 -0
  25. package/dist/dev-vite.d.ts +31 -27
  26. package/dist/dev-vite.js +60 -30
  27. package/dist/dev-vite.js.map +1 -1
  28. package/dist/dev.d.ts +1 -1
  29. package/dist/doctor-RWVRpvat.js +102 -0
  30. package/dist/doctor-RWVRpvat.js.map +1 -0
  31. package/dist/{dump-Bh5k26VQ.js → dump-m2vEYDNY.js} +4 -4
  32. package/dist/{dump-Bh5k26VQ.js.map → dump-m2vEYDNY.js.map} +1 -1
  33. package/dist/{export-DtF5tDIM.js → export-DenKwEQu.js} +4 -4
  34. package/dist/{export-DtF5tDIM.js.map → export-DenKwEQu.js.map} +1 -1
  35. package/dist/{fsck-D_djMO5D.js → fsck-2Vq-7-e2.js} +5 -5
  36. package/dist/{fsck-D_djMO5D.js.map → fsck-2Vq-7-e2.js.map} +1 -1
  37. package/dist/gcs-admin-Bx6xSNJj.d.ts +123 -0
  38. package/dist/gcs.d.ts +18 -0
  39. package/dist/gcs.js +2 -0
  40. package/dist/goog4-signer-Z7KnJ1su.js +321 -0
  41. package/dist/goog4-signer-Z7KnJ1su.js.map +1 -0
  42. package/dist/{http-DxM9MflO.js → http-7zT29K3P.js} +4 -4
  43. package/dist/{http-DxM9MflO.js.map → http-7zT29K3P.js.map} +1 -1
  44. package/dist/{aws4fetch.esm-p7eEzLCs.js → http-transport-BTgVCY5r.js} +24 -476
  45. package/dist/http-transport-BTgVCY5r.js.map +1 -0
  46. package/dist/http.d.ts +2 -2
  47. package/dist/http.js +2 -2
  48. package/dist/{index-BNRh23K9.d.ts → index-BHz92Acj.d.ts} +2 -2
  49. package/dist/{index-BYk9oCNf.d.ts → index-CEZKQsKt.d.ts} +3 -2
  50. package/dist/{index-B6oexfOB.d.ts → index-DP3ClvcA.d.ts} +12 -10
  51. package/dist/{index-0rZcMBwy.d.ts → index-uE-w2dgj.d.ts} +2 -2
  52. package/dist/index.d.ts +3 -3
  53. package/dist/index.js +3 -3
  54. package/dist/{inspect-6WZ-pC7-.js → inspect-BpYbH1DM.js} +5 -5
  55. package/dist/{inspect-6WZ-pC7-.js.map → inspect-BpYbH1DM.js.map} +1 -1
  56. package/dist/{log-tail-D98U1JBo.js → log-tail-QWU4wlu-.js} +3 -11
  57. package/dist/log-tail-QWU4wlu-.js.map +1 -0
  58. package/dist/{maintenance-B_e0T99L.d.ts → maintenance-BGHGt2Yg.d.ts} +2 -2
  59. package/dist/{maintenance-B4Dki6Ig.js → maintenance-DULFcpd1.js} +4 -17
  60. package/dist/maintenance-DULFcpd1.js.map +1 -0
  61. package/dist/{maintenance-C7coQp4c.js → maintenance-fEi-UZ2o.js} +5 -11
  62. package/dist/maintenance-fEi-UZ2o.js.map +1 -0
  63. package/dist/maintenance.d.ts +1 -1
  64. package/dist/maintenance.js +1 -1
  65. package/dist/node.d.ts +22 -61
  66. package/dist/node.js +4 -3
  67. package/dist/{observability-wzs3-BL_.js → observability-Ch-VQJyE.js} +85 -27
  68. package/dist/{observability-wzs3-BL_.js.map → observability-Ch-VQJyE.js.map} +1 -1
  69. package/dist/observability.d.ts +2 -2
  70. package/dist/observability.js +1 -1
  71. package/dist/{plan-a7PJHBCy.js → plan-C4qgiXSg.js} +2 -2
  72. package/dist/{plan-a7PJHBCy.js.map → plan-C4qgiXSg.js.map} +1 -1
  73. package/dist/{query-rAtXNQQB.js → query-C43r-6ib.js} +2 -2
  74. package/dist/{query-rAtXNQQB.js.map → query-C43r-6ib.js.map} +1 -1
  75. package/dist/{rebuild-index-BVzQSZlm.js → rebuild-index-BH1dc1p6.js} +4 -4
  76. package/dist/{rebuild-index-BVzQSZlm.js.map → rebuild-index-BH1dc1p6.js.map} +1 -1
  77. package/dist/{restore-R-4rbciV.js → restore-D0VYWzfP.js} +5 -5
  78. package/dist/{restore-R-4rbciV.js.map → restore-D0VYWzfP.js.map} +1 -1
  79. package/dist/{runtime-spec-_GTdeSMo.js → runtime-spec--LykAdl1.js} +2 -2
  80. package/dist/{runtime-spec-_GTdeSMo.js.map → runtime-spec--LykAdl1.js.map} +1 -1
  81. package/dist/{s3-http-B-z8th6O.d.ts → s3-http-DD5gDc7t.d.ts} +6 -4
  82. package/dist/s3.d.ts +1 -1
  83. package/dist/s3.js +1 -1
  84. package/dist/sha256-CqcKTjw9.js +22 -0
  85. package/dist/sha256-CqcKTjw9.js.map +1 -0
  86. package/dist/{src-D__mHQmQ.js → src-BMFfDUI2.js} +69 -29
  87. package/dist/src-BMFfDUI2.js.map +1 -0
  88. package/dist/{src-CYHFDrKz.js → src-DvbTEya2.js} +3 -3
  89. package/dist/{src-CYHFDrKz.js.map → src-DvbTEya2.js.map} +1 -1
  90. package/dist/{subcommand-DoDA-K7d.js → subcommand-BV68pqwJ.js} +2 -2
  91. package/dist/{subcommand-DoDA-K7d.js.map → subcommand-BV68pqwJ.js.map} +1 -1
  92. package/dist/{usage-DBV1eQHC.js → usage-BMZR8o6U.js} +3 -3
  93. package/dist/{usage-DBV1eQHC.js.map → usage-BMZR8o6U.js.map} +1 -1
  94. package/package.json +12 -6
  95. package/dist/aws4fetch.esm-p7eEzLCs.js.map +0 -1
  96. package/dist/cloudflare-DzKBrUlg.js.map +0 -1
  97. package/dist/config-1tv0-Yzm.js.map +0 -1
  98. package/dist/deploy-DonTr-CV.js.map +0 -1
  99. package/dist/doctor-DSIyCDg_.js +0 -346
  100. package/dist/doctor-DSIyCDg_.js.map +0 -1
  101. package/dist/log-tail-D98U1JBo.js.map +0 -1
  102. package/dist/maintenance-B4Dki6Ig.js.map +0 -1
  103. package/dist/maintenance-C7coQp4c.js.map +0 -1
  104. package/dist/src-D__mHQmQ.js.map +0 -1
package/dist/API.md CHANGED
@@ -749,8 +749,9 @@ export default baerlyWorker(() => ({ config }));
749
749
 
750
750
  `s3Storage` / `r2Storage` / `minioStorage` / `gcsStorage` from
751
751
  `@gusto/baerly-storage/node` are re-exports of one factory family — same
752
- shape (bucket + credentials), all hide `aws4fetch` / `@xmldom/xmldom`
753
- behind the package boundary.
752
+ shape (bucket + credentials), all hide their request signer (SigV4 for
753
+ S3/R2/MinIO, GOOG4-HMAC for GCS) and XML parsing behind the package
754
+ boundary.
754
755
 
755
756
  ### Verifier presets
756
757
 
package/dist/CHANGELOG.md CHANGED
@@ -1,5 +1,130 @@
1
1
  # @gusto/baerly-storage
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c806852: `baerlyDev` can now load `baerly.config` itself instead of requiring the caller
8
+ to import it and pass the object.
9
+
10
+ `BaerlyDevOptions.config` is now optional; two new resolution modes:
11
+
12
+ - `configPath` — absolute path to the config module, loaded lazily at
13
+ dev-server startup via Vite's `ssrLoadModule`.
14
+ - **convention** (nothing passed) — loads `<viteRoot>/src/baerly.config.ts`,
15
+ mirroring how `reactRouter()` loads `react-router.config.ts`.
16
+
17
+ Passing an explicit `config` object still works and is unchanged, including
18
+ fail-fast verifier resolution at factory time.
19
+
20
+ **Why:** when an app's `vite.config.ts` imports its `baerly.config` to pass the
21
+ object in, Nx's `@nx/vite` / `@nx/vitest` inference plugins bundle that config
22
+ during project-graph creation, dragging the config module's transitive imports
23
+ (`@gusto/baerly-storage/config`, `zod`) into the config bundle. Those fail to
24
+ resolve in CI and crash graph creation, forcing every baerly app into the root
25
+ `nx.json` inference-plugin exclusion lists — a global edit that marks the whole
26
+ monorepo affected. Letting `baerlyDev` load the config itself keeps the caller's
27
+ `vite.config` import-free, so the exclusion is no longer needed.
28
+
29
+ - 6336a06: Native Google Cloud Storage adapter: `gcsStorage` now drives GCS's own
30
+ generation-precondition conditional writes over the native XML API
31
+ (`x-goog-if-generation-match`), promoting GCS to a Tier-1 backend.
32
+
33
+ **Migration.** The `gcsStorage({ bucket, credentials })` signature is
34
+ unchanged, so existing callers keep compiling. What changes is the wire
35
+ behavior: the factory previously produced an S3-interop client whose
36
+ conditional headers GCS silently ignored on writes (it could not
37
+ linearize the commit log and was unsupported); it now speaks the native
38
+ GCS XML API and gains real create-if-absent + CAS, returning `412` →
39
+ `Conflict` on a lost write. Credentials remain GCS HMAC interop keys
40
+ (`accessKeyId` / `secretAccessKey`). Node host only — no Worker `/gcs`
41
+ subpath and no GCP deploy target in v1.
42
+
43
+ ### Patch Changes
44
+
45
+ - 8322ce2: Canonical HTTP log lines now classify by wire status alone: any 4xx is
46
+ `warn`, not `error`, even when a structured error is attached. Previously
47
+ an attached error forced `error` level regardless of status, so a
48
+ `409 Conflict` logged at `error`.
49
+
50
+ **Why:** a 4xx is the caller's fault, not a server fault. The reachable
51
+ 409 is a duplicate-`_id` insert (a reused id or a double-submitted POST);
52
+ ordinary storage write contention is absorbed internally by the log
53
+ forward-probe and never reaches the client as a 409. Logging these at
54
+ `error` polluted error budgets and could page on-call for normal
55
+ operation. `error` is now reserved for genuine server faults: 5xx, a
56
+ 2xx/3xx that anomalously carries an error, or a thrown error with no wire
57
+ status to classify by. The line still carries the structured
58
+ `{ code, message }` on the failure path; only the stack (unneeded for a
59
+ routine client error) drops off at `warn`.
60
+
61
+ - a1cd0a3: Bump `@logtape/logtape` 2.2.2 → 2.2.4 to pick up the upstream fix for the
62
+ `configure()` process exit-listener leak ([dahlia/logtape#192](https://github.com/dahlia/logtape/issues/192)).
63
+ Previously each `configure()` registered a new `process.on("exit", …)` hook
64
+ without removing the prior one; 2.2.4 unregisters the previous dispose hook
65
+ before registering a new one. Production adapters call `configureObservability`
66
+ once so nothing shipped broken, but repeated reconfiguration in one process
67
+ (test suites, hot-reload) no longer leaks listeners. No public API changes.
68
+
69
+ - 3387380: S3/GCS adapter `delete()` now surfaces an unexpected non-2xx/404 status
70
+ as an error instead of silently treating it as success. `200`/`204`/`404`
71
+ stay a success (delete is idempotent; a `404` is a no-op); anything else
72
+ maps through the shared classifier (`403` → `AccessDenied`; `429` and
73
+ `≥500` → retryable `NetworkError`; anything else → `InvalidResponse`).
74
+
75
+ **Why:** the previous inline path swallowed every non-2xx as success, so
76
+ a `403` on delete during GC/compaction looked like it removed an object
77
+ it never touched — the bucket would grow while maintenance reported
78
+ success. Surfacing the status is a correctness fix. It is safe on the
79
+ write path: GC deletes in parallel and a thrown delete aborts only the
80
+ rest of that sweep (landed deletes are durable, `pending.json` is
81
+ CAS-merged), and the maintenance runner already swallows every
82
+ non-`Conflict` throw after counting + logging it, so a delete error never
83
+ propagates to crash a write-tick.
84
+
85
+ ## 0.5.0
86
+
87
+ ### Minor Changes
88
+
89
+ - 5afe09a: Observability: coexist with a host app's LogTape config instead of clobbering it.
90
+
91
+ baerly-storage is a library, and LogTape's guidance is that only the application
92
+ configures LogTape. Previously the Node and Cloudflare adapters called
93
+ `configure({ reset: true })` at boot unconditionally, which silently wiped
94
+ the sinks and loggers of any app that had already configured LogTape (and,
95
+ depending on boot order, could itself be wiped). The documented "leave the
96
+ field unset to skip configuration" escape hatch never actually worked.
97
+
98
+ Now:
99
+
100
+ - `configureObservability` checks `getConfig()` first. When LogTape is
101
+ already configured by something other than baerly-storage, it leaves that config
102
+ intact and emits a single `["logtape", "meta"]` notice rather than
103
+ resetting it. baerly-storage's own config is still reconfigured last-call-wins, so
104
+ standalone servers and dev hot-reload are unchanged.
105
+ - `baerlyNode` / `baerlyWorker` accept `observability: false` to skip
106
+ auto-configuration entirely, for apps that own the process-wide
107
+ (isolate-wide on Workers) LogTape configuration themselves.
108
+
109
+ ### Patch Changes
110
+
111
+ - d94b57b: Rename the `/v1/spec` field `kernelVersion` → `serverVersion`.
112
+
113
+ `kernelVersion` was a build-provenance stamp (= the published package
114
+ version) whose name wrongly implied a separate "kernel" contract axis.
115
+ `serverVersion` names it honestly. The value and meaning are unchanged,
116
+ and `specVersion` stays `"1"`: the wire-contract axis is `specVersion`,
117
+ and pre-consumer wire shape may change without bumping it (see
118
+ `docs/contributing/conventions/versioning.md`).
119
+
120
+ **Migration — agents: if you read the LEFT, read the RIGHT:**
121
+
122
+ GET /v1/spec → { "specVersion": "1", "kernelVersion": "0.4.1", ... } // before
123
+ GET /v1/spec → { "specVersion": "1", "serverVersion": "0.4.1", ... } // after
124
+
125
+ Key contract decisions off `specVersion`, never off `serverVersion` — the
126
+ latter is build provenance, equal to the package version.
127
+
3
128
  ## 0.4.1
4
129
 
5
130
  ### Patch Changes
@@ -36,7 +36,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36
36
  SOFTWARE.
37
37
 
38
38
  ==============================================================================
39
- @logtape/logtape@2.2.2
39
+ @logtape/logtape@2.2.4
40
40
  License: MIT
41
41
  Repository: git+https://github.com/dahlia/logtape.git
42
42
 
package/dist/auth.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { r as Verifier } from "./index-BYk9oCNf.js";
1
+ import { r as Verifier } from "./index-CEZKQsKt.js";
2
2
 
3
3
  //#region packages/server/src/auth/presets/shared-secret.d.ts
4
4
  /**
@@ -0,0 +1,460 @@
1
+ import { g as RATE_LIMIT_BACKOFF_MILLIS } from "./constants-CfeMWQWk.js";
2
+ import { t as BaerlyError } from "./errors-Dfa3p78c.js";
3
+ import { t as assertValidStorageKey } from "./key-Di6yyxFu.js";
4
+ import { t as delay } from "./time-DUqvFMHq.js";
5
+ import { i as retryAfterCause, n as parseRetryAfter, o as parseListObjectsV2CommandOutput, r as retry, t as mapStorageError } from "./http-transport-BTgVCY5r.js";
6
+ //#region packages/adapter-node/src/s3-http.ts
7
+ /**
8
+ * `Storage` impl that speaks the S3 REST API directly. Works against
9
+ * any S3-compatible endpoint — AWS S3, R2 (S3-compat), Minio. Does not
10
+ * depend on any AWS SDK. GCS is NOT supported over this S3-interop path
11
+ * (its conditional-write semantics can't linearize the commit log); use
12
+ * the native `GcsHttpStorage` adapter instead.
13
+ *
14
+ * Authentication is plugged in via the `sign` callback; this class
15
+ * itself does no SigV4. For Cloudflare Workers, the R2 binding fast
16
+ * path lives in `@baerly/adapter-cloudflare`.
17
+ */
18
+ var S3HttpStorage = class {
19
+ #endpoint;
20
+ #bucket;
21
+ #fetch;
22
+ #sign;
23
+ #retries;
24
+ #backoffMs;
25
+ constructor(options) {
26
+ this.#endpoint = options.endpoint.replace(/\/+$/, "");
27
+ this.#bucket = options.bucket;
28
+ this.#fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
29
+ this.#sign = options.sign;
30
+ this.#retries = options.retries ?? 8;
31
+ this.#backoffMs = options.backoffMs ?? 100;
32
+ }
33
+ #objectUrl(key, versionId) {
34
+ assertValidStorageKey(key);
35
+ const base = `${this.#endpoint}/${this.#bucket}/${encodeURIComponent(key)}`;
36
+ return versionId !== void 0 ? `${base}?versionId=${encodeURIComponent(versionId)}` : base;
37
+ }
38
+ async #dispatch(req) {
39
+ const signed = this.#sign ? await this.#sign(req) : req;
40
+ try {
41
+ return await this.#fetch(signed);
42
+ } catch (error) {
43
+ if (error instanceof BaerlyError) throw error;
44
+ throw new BaerlyError("NetworkError", error instanceof Error ? error.message : String(error), error);
45
+ }
46
+ }
47
+ #retry(fn) {
48
+ return retry(fn, {
49
+ retries: this.#retries,
50
+ backoffMs: this.#backoffMs
51
+ });
52
+ }
53
+ async get(key, opts) {
54
+ opts?.signal?.throwIfAborted();
55
+ const url = this.#objectUrl(key, opts?.versionId);
56
+ const headers = new Headers();
57
+ if (opts?.ifNoneMatch !== void 0) headers.set("If-None-Match", opts.ifNoneMatch);
58
+ return this.#retry(async () => {
59
+ const res = await this.#dispatch(new Request(url, {
60
+ method: "GET",
61
+ headers,
62
+ signal: opts?.signal ?? null
63
+ }));
64
+ switch (res.status) {
65
+ case 200: {
66
+ const etag = res.headers.get("ETag");
67
+ if (etag === null) throw new BaerlyError("InvalidResponse", `GET ${key}: missing ETag`);
68
+ const body = new Uint8Array(await res.arrayBuffer());
69
+ const versionId = res.headers.get("x-amz-version-id") ?? void 0;
70
+ return versionId !== void 0 ? {
71
+ body,
72
+ etag,
73
+ versionId
74
+ } : {
75
+ body,
76
+ etag
77
+ };
78
+ }
79
+ case 304:
80
+ case 404: return null;
81
+ default: throw await mapStorageError(res, "GET", key);
82
+ }
83
+ });
84
+ }
85
+ async put(key, body, opts) {
86
+ opts?.signal?.throwIfAborted();
87
+ const url = this.#objectUrl(key);
88
+ const headers = new Headers();
89
+ headers.set("Content-Type", opts?.contentType ?? "application/octet-stream");
90
+ if (opts?.ifMatch !== void 0) headers.set("If-Match", opts.ifMatch);
91
+ if (opts?.ifNoneMatch === "*") headers.set("If-None-Match", "*");
92
+ return this.#retry(async () => {
93
+ const res = await this.#dispatch(new Request(url, {
94
+ method: "PUT",
95
+ headers,
96
+ body,
97
+ signal: opts?.signal ?? null
98
+ }));
99
+ if (res.status === 412) throw new BaerlyError("Conflict", `PUT ${key}: precondition failed`);
100
+ if (res.status === 409 && opts?.ifNoneMatch === "*") throw new BaerlyError("NetworkError", `PUT ${key}: 409 ConditionalRequestConflict (contended conditional create; retryable)`, {
101
+ status: res.status,
102
+ ...retryAfterCause(res)
103
+ });
104
+ if (res.status === 404 && opts?.ifMatch !== void 0) throw new BaerlyError("Conflict", `PUT ${key}: precondition failed (ifMatch=${opts.ifMatch} but key does not exist)`);
105
+ if (res.status !== 200 && res.status !== 204) throw await mapStorageError(res, "PUT", key);
106
+ const etag = res.headers.get("ETag");
107
+ if (etag === null) throw new BaerlyError("InvalidResponse", `PUT ${key}: missing ETag`);
108
+ const dateStr = res.headers.get("Date");
109
+ const versionId = res.headers.get("x-amz-version-id") ?? void 0;
110
+ const result = { etag };
111
+ if (dateStr !== null) result.serverDate = new Date(dateStr);
112
+ if (versionId !== void 0) result.versionId = versionId;
113
+ return result;
114
+ });
115
+ }
116
+ async delete(key, opts) {
117
+ opts?.signal?.throwIfAborted();
118
+ const url = this.#objectUrl(key);
119
+ await this.#retry(async () => {
120
+ const res = await this.#dispatch(new Request(url, {
121
+ method: "DELETE",
122
+ signal: opts?.signal ?? null
123
+ }));
124
+ if (res.status !== 200 && res.status !== 204 && res.status !== 404) throw await mapStorageError(res, "DELETE", key);
125
+ });
126
+ }
127
+ async *list(prefix, opts) {
128
+ opts?.signal?.throwIfAborted();
129
+ let yielded = 0;
130
+ let continuationToken;
131
+ const startAfter = opts?.startAfter ?? "";
132
+ while (true) {
133
+ opts?.signal?.throwIfAborted();
134
+ const params = new URLSearchParams();
135
+ params.set("list-type", "2");
136
+ params.set("prefix", prefix);
137
+ params.set("encoding-type", "url");
138
+ if (continuationToken !== void 0) params.set("continuation-token", continuationToken);
139
+ else if (startAfter !== "") params.set("start-after", startAfter);
140
+ if (opts?.maxKeys !== void 0) {
141
+ const remaining = opts.maxKeys - yielded;
142
+ params.set("max-keys", String(Math.min(remaining, 1e3)));
143
+ }
144
+ const url = `${this.#endpoint}/${this.#bucket}/?${params.toString()}`;
145
+ let parsed;
146
+ let lastHint;
147
+ for (let attempt = 0; attempt < 10; attempt++) {
148
+ const outcome = await this.#retry(async () => {
149
+ const res = await this.#dispatch(new Request(url, {
150
+ method: "GET",
151
+ signal: opts?.signal ?? null
152
+ }));
153
+ if (res.status === 200) return {
154
+ kind: "ok",
155
+ body: await res.text()
156
+ };
157
+ if (res.status === 429) return {
158
+ kind: "ratelimited",
159
+ retryAfterSeconds: parseRetryAfter(res.headers.get("Retry-After"))
160
+ };
161
+ throw await mapStorageError(res, "LIST", prefix);
162
+ });
163
+ if (outcome.kind === "ok") {
164
+ parsed = parseListObjectsV2CommandOutput(outcome.body);
165
+ break;
166
+ }
167
+ lastHint = outcome.retryAfterSeconds;
168
+ const hintMs = outcome.retryAfterSeconds !== void 0 ? outcome.retryAfterSeconds * 1e3 : 0;
169
+ await delay(Math.max(hintMs, RATE_LIMIT_BACKOFF_MILLIS));
170
+ }
171
+ if (parsed === void 0) throw new BaerlyError("NetworkError", `LIST ${prefix}: rate-limited`, {
172
+ status: 429,
173
+ ...lastHint !== void 0 ? { retryAfterSeconds: lastHint } : {}
174
+ });
175
+ for (const entry of parsed.Contents ?? []) {
176
+ if (entry.Key === void 0) continue;
177
+ yield {
178
+ key: entry.Key,
179
+ etag: entry.ETag ?? "",
180
+ ...entry.LastModified !== void 0 && { lastModified: entry.LastModified }
181
+ };
182
+ yielded += 1;
183
+ if (opts?.maxKeys !== void 0 && yielded >= opts.maxKeys) return;
184
+ }
185
+ continuationToken = parsed.NextContinuationToken;
186
+ if (continuationToken === void 0 || continuationToken === "") return;
187
+ }
188
+ }
189
+ };
190
+ //#endregion
191
+ //#region node_modules/.pnpm/aws4fetch@1.0.20/node_modules/aws4fetch/dist/aws4fetch.esm.mjs
192
+ /**
193
+ * @license MIT <https://opensource.org/licenses/MIT>
194
+ * @copyright Michael Hart 2024
195
+ */
196
+ const encoder = new TextEncoder();
197
+ const HOST_SERVICES = {
198
+ appstream2: "appstream",
199
+ cloudhsmv2: "cloudhsm",
200
+ email: "ses",
201
+ marketplace: "aws-marketplace",
202
+ mobile: "AWSMobileHubService",
203
+ pinpoint: "mobiletargeting",
204
+ queue: "sqs",
205
+ "git-codecommit": "codecommit",
206
+ "mturk-requester-sandbox": "mturk-requester",
207
+ "personalize-runtime": "personalize"
208
+ };
209
+ const UNSIGNABLE_HEADERS = /* @__PURE__ */ new Set([
210
+ "authorization",
211
+ "content-type",
212
+ "content-length",
213
+ "user-agent",
214
+ "presigned-expires",
215
+ "expect",
216
+ "x-amzn-trace-id",
217
+ "range",
218
+ "connection"
219
+ ]);
220
+ var AwsClient = class {
221
+ constructor({ accessKeyId, secretAccessKey, sessionToken, service, region, cache, retries, initRetryMs }) {
222
+ if (accessKeyId == null) throw new TypeError("accessKeyId is a required option");
223
+ if (secretAccessKey == null) throw new TypeError("secretAccessKey is a required option");
224
+ this.accessKeyId = accessKeyId;
225
+ this.secretAccessKey = secretAccessKey;
226
+ this.sessionToken = sessionToken;
227
+ this.service = service;
228
+ this.region = region;
229
+ this.cache = cache || /* @__PURE__ */ new Map();
230
+ this.retries = retries != null ? retries : 10;
231
+ this.initRetryMs = initRetryMs || 50;
232
+ }
233
+ async sign(input, init) {
234
+ if (input instanceof Request) {
235
+ const { method, url, headers, body } = input;
236
+ init = Object.assign({
237
+ method,
238
+ url,
239
+ headers
240
+ }, init);
241
+ if (init.body == null && headers.has("Content-Type")) init.body = body != null && headers.has("X-Amz-Content-Sha256") ? body : await input.clone().arrayBuffer();
242
+ input = url;
243
+ }
244
+ const signer = new AwsV4Signer(Object.assign({ url: input.toString() }, init, this, init && init.aws));
245
+ const signed = Object.assign({}, init, await signer.sign());
246
+ delete signed.aws;
247
+ try {
248
+ return new Request(signed.url.toString(), signed);
249
+ } catch (e) {
250
+ if (e instanceof TypeError) return new Request(signed.url.toString(), Object.assign({ duplex: "half" }, signed));
251
+ throw e;
252
+ }
253
+ }
254
+ async fetch(input, init) {
255
+ for (let i = 0; i <= this.retries; i++) {
256
+ const fetched = fetch(await this.sign(input, init));
257
+ if (i === this.retries) return fetched;
258
+ const res = await fetched;
259
+ if (res.status < 500 && res.status !== 429) return res;
260
+ await new Promise((resolve) => setTimeout(resolve, Math.random() * this.initRetryMs * Math.pow(2, i)));
261
+ }
262
+ throw new Error("An unknown error occurred, ensure retries is not negative");
263
+ }
264
+ };
265
+ var AwsV4Signer = class {
266
+ constructor({ method, url, headers, body, accessKeyId, secretAccessKey, sessionToken, service, region, cache, datetime, signQuery, appendSessionToken, allHeaders, singleEncode }) {
267
+ if (url == null) throw new TypeError("url is a required option");
268
+ if (accessKeyId == null) throw new TypeError("accessKeyId is a required option");
269
+ if (secretAccessKey == null) throw new TypeError("secretAccessKey is a required option");
270
+ this.method = method || (body ? "POST" : "GET");
271
+ this.url = new URL(url);
272
+ this.headers = new Headers(headers || {});
273
+ this.body = body;
274
+ this.accessKeyId = accessKeyId;
275
+ this.secretAccessKey = secretAccessKey;
276
+ this.sessionToken = sessionToken;
277
+ let guessedService, guessedRegion;
278
+ if (!service || !region) [guessedService, guessedRegion] = guessServiceRegion(this.url, this.headers);
279
+ this.service = service || guessedService || "";
280
+ this.region = region || guessedRegion || "us-east-1";
281
+ this.cache = cache || /* @__PURE__ */ new Map();
282
+ this.datetime = datetime || (/* @__PURE__ */ new Date()).toISOString().replace(/[:-]|\.\d{3}/g, "");
283
+ this.signQuery = signQuery;
284
+ this.appendSessionToken = appendSessionToken || this.service === "iotdevicegateway";
285
+ this.headers.delete("Host");
286
+ if (this.service === "s3" && !this.signQuery && !this.headers.has("X-Amz-Content-Sha256")) this.headers.set("X-Amz-Content-Sha256", "UNSIGNED-PAYLOAD");
287
+ const params = this.signQuery ? this.url.searchParams : this.headers;
288
+ params.set("X-Amz-Date", this.datetime);
289
+ if (this.sessionToken && !this.appendSessionToken) params.set("X-Amz-Security-Token", this.sessionToken);
290
+ this.signableHeaders = ["host", ...this.headers.keys()].filter((header) => allHeaders || !UNSIGNABLE_HEADERS.has(header)).sort();
291
+ this.signedHeaders = this.signableHeaders.join(";");
292
+ this.canonicalHeaders = this.signableHeaders.map((header) => header + ":" + (header === "host" ? this.url.host : (this.headers.get(header) || "").replace(/\s+/g, " "))).join("\n");
293
+ this.credentialString = [
294
+ this.datetime.slice(0, 8),
295
+ this.region,
296
+ this.service,
297
+ "aws4_request"
298
+ ].join("/");
299
+ if (this.signQuery) {
300
+ if (this.service === "s3" && !params.has("X-Amz-Expires")) params.set("X-Amz-Expires", "86400");
301
+ params.set("X-Amz-Algorithm", "AWS4-HMAC-SHA256");
302
+ params.set("X-Amz-Credential", this.accessKeyId + "/" + this.credentialString);
303
+ params.set("X-Amz-SignedHeaders", this.signedHeaders);
304
+ }
305
+ if (this.service === "s3") try {
306
+ this.encodedPath = decodeURIComponent(this.url.pathname.replace(/\+/g, " "));
307
+ } catch (e) {
308
+ this.encodedPath = this.url.pathname;
309
+ }
310
+ else this.encodedPath = this.url.pathname.replace(/\/+/g, "/");
311
+ if (!singleEncode) this.encodedPath = encodeURIComponent(this.encodedPath).replace(/%2F/g, "/");
312
+ this.encodedPath = encodeRfc3986(this.encodedPath);
313
+ const seenKeys = /* @__PURE__ */ new Set();
314
+ this.encodedSearch = [...this.url.searchParams].filter(([k]) => {
315
+ if (!k) return false;
316
+ if (this.service === "s3") {
317
+ if (seenKeys.has(k)) return false;
318
+ seenKeys.add(k);
319
+ }
320
+ return true;
321
+ }).map((pair) => pair.map((p) => encodeRfc3986(encodeURIComponent(p)))).sort(([k1, v1], [k2, v2]) => k1 < k2 ? -1 : k1 > k2 ? 1 : v1 < v2 ? -1 : v1 > v2 ? 1 : 0).map((pair) => pair.join("=")).join("&");
322
+ }
323
+ async sign() {
324
+ if (this.signQuery) {
325
+ this.url.searchParams.set("X-Amz-Signature", await this.signature());
326
+ if (this.sessionToken && this.appendSessionToken) this.url.searchParams.set("X-Amz-Security-Token", this.sessionToken);
327
+ } else this.headers.set("Authorization", await this.authHeader());
328
+ return {
329
+ method: this.method,
330
+ url: this.url,
331
+ headers: this.headers,
332
+ body: this.body
333
+ };
334
+ }
335
+ async authHeader() {
336
+ return [
337
+ "AWS4-HMAC-SHA256 Credential=" + this.accessKeyId + "/" + this.credentialString,
338
+ "SignedHeaders=" + this.signedHeaders,
339
+ "Signature=" + await this.signature()
340
+ ].join(", ");
341
+ }
342
+ async signature() {
343
+ const date = this.datetime.slice(0, 8);
344
+ const cacheKey = [
345
+ this.secretAccessKey,
346
+ date,
347
+ this.region,
348
+ this.service
349
+ ].join();
350
+ let kCredentials = this.cache.get(cacheKey);
351
+ if (!kCredentials) {
352
+ kCredentials = await hmac(await hmac(await hmac(await hmac("AWS4" + this.secretAccessKey, date), this.region), this.service), "aws4_request");
353
+ this.cache.set(cacheKey, kCredentials);
354
+ }
355
+ return buf2hex(await hmac(kCredentials, await this.stringToSign()));
356
+ }
357
+ async stringToSign() {
358
+ return [
359
+ "AWS4-HMAC-SHA256",
360
+ this.datetime,
361
+ this.credentialString,
362
+ buf2hex(await hash(await this.canonicalString()))
363
+ ].join("\n");
364
+ }
365
+ async canonicalString() {
366
+ return [
367
+ this.method.toUpperCase(),
368
+ this.encodedPath,
369
+ this.encodedSearch,
370
+ this.canonicalHeaders + "\n",
371
+ this.signedHeaders,
372
+ await this.hexBodyHash()
373
+ ].join("\n");
374
+ }
375
+ async hexBodyHash() {
376
+ let hashHeader = this.headers.get("X-Amz-Content-Sha256") || (this.service === "s3" && this.signQuery ? "UNSIGNED-PAYLOAD" : null);
377
+ if (hashHeader == null) {
378
+ if (this.body && typeof this.body !== "string" && !("byteLength" in this.body)) throw new Error("body must be a string, ArrayBuffer or ArrayBufferView, unless you include the X-Amz-Content-Sha256 header");
379
+ hashHeader = buf2hex(await hash(this.body || ""));
380
+ }
381
+ return hashHeader;
382
+ }
383
+ };
384
+ async function hmac(key, string) {
385
+ const cryptoKey = await crypto.subtle.importKey("raw", typeof key === "string" ? encoder.encode(key) : key, {
386
+ name: "HMAC",
387
+ hash: { name: "SHA-256" }
388
+ }, false, ["sign"]);
389
+ return crypto.subtle.sign("HMAC", cryptoKey, encoder.encode(string));
390
+ }
391
+ async function hash(content) {
392
+ return crypto.subtle.digest("SHA-256", typeof content === "string" ? encoder.encode(content) : content);
393
+ }
394
+ const HEX_CHARS = [
395
+ "0",
396
+ "1",
397
+ "2",
398
+ "3",
399
+ "4",
400
+ "5",
401
+ "6",
402
+ "7",
403
+ "8",
404
+ "9",
405
+ "a",
406
+ "b",
407
+ "c",
408
+ "d",
409
+ "e",
410
+ "f"
411
+ ];
412
+ function buf2hex(arrayBuffer) {
413
+ const buffer = new Uint8Array(arrayBuffer);
414
+ let out = "";
415
+ for (let idx = 0; idx < buffer.length; idx++) {
416
+ const n = buffer[idx];
417
+ out += HEX_CHARS[n >>> 4 & 15];
418
+ out += HEX_CHARS[n & 15];
419
+ }
420
+ return out;
421
+ }
422
+ function encodeRfc3986(urlEncodedStr) {
423
+ return urlEncodedStr.replace(/[!'()*]/g, (c) => "%" + c.charCodeAt(0).toString(16).toUpperCase());
424
+ }
425
+ function guessServiceRegion(url, headers) {
426
+ const { hostname, pathname } = url;
427
+ if (hostname.endsWith(".on.aws")) {
428
+ const match = hostname.match(/^[^.]{1,63}\.lambda-url\.([^.]{1,63})\.on\.aws$/);
429
+ return match != null ? ["lambda", match[1] || ""] : ["", ""];
430
+ }
431
+ if (hostname.endsWith(".r2.cloudflarestorage.com")) return ["s3", "auto"];
432
+ if (hostname.endsWith(".backblazeb2.com")) {
433
+ const match = hostname.match(/^(?:[^.]{1,63}\.)?s3\.([^.]{1,63})\.backblazeb2\.com$/);
434
+ return match != null ? ["s3", match[1] || ""] : ["", ""];
435
+ }
436
+ const match = hostname.replace("dualstack.", "").match(/([^.]{1,63})\.(?:([^.]{0,63})\.)?amazonaws\.com(?:\.cn)?$/);
437
+ let service = match && match[1] || "";
438
+ let region = match && match[2];
439
+ if (region === "us-gov") region = "us-gov-west-1";
440
+ else if (region === "s3" || region === "s3-accelerate") {
441
+ region = "us-east-1";
442
+ service = "s3";
443
+ } else if (service === "iot") if (hostname.startsWith("iot.")) service = "execute-api";
444
+ else if (hostname.startsWith("data.jobs.iot.")) service = "iot-jobs-data";
445
+ else service = pathname === "/mqtt" ? "iotdevicegateway" : "iotdata";
446
+ else if (service === "autoscaling") {
447
+ const targetPrefix = (headers.get("X-Amz-Target") || "").split(".")[0];
448
+ if (targetPrefix === "AnyScaleFrontendService") service = "application-autoscaling";
449
+ else if (targetPrefix === "AnyScaleScalingPlannerFrontendService") service = "autoscaling-plans";
450
+ } else if (region == null && service.startsWith("s3-")) {
451
+ region = service.slice(3).replace(/^fips-|^external-1/, "");
452
+ service = "s3";
453
+ } else if (service.endsWith("-fips")) service = service.slice(0, -5);
454
+ else if (region && /-\d$/.test(service) && !/-\d$/.test(region)) [service, region] = [region, service];
455
+ return [HOST_SERVICES[service] || service, region || ""];
456
+ }
457
+ //#endregion
458
+ export { S3HttpStorage as n, AwsClient as t };
459
+
460
+ //# sourceMappingURL=aws4fetch.esm-CXE5ZbAa.js.map