@gusto/baerly-storage 0.6.0 → 0.7.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/README.md +47 -124
- package/dist/API.md +161 -512
- package/dist/CHANGELOG.md +1137 -378
- package/dist/RECIPES.md +398 -80
- package/dist/THIRD-PARTY-LICENSES.txt +5 -26
- package/dist/{app-config-DyiFK3_k.d.ts → app-config-C6qW7m8S.d.ts} +119 -111
- package/dist/app-config.d.ts +31 -1
- package/dist/app-config.js +1 -2
- package/dist/app-config.js.map +1 -1
- package/dist/auth.d.ts +33 -28
- package/dist/auth.js +549 -985
- package/dist/auth.js.map +1 -1
- package/dist/baerly.js +130 -138
- package/dist/baerly.js.map +1 -1
- package/dist/baerly.spec.json +97 -22
- package/dist/capacity-warning-header-BlVopyiI.js +16 -0
- package/dist/capacity-warning-header-BlVopyiI.js.map +1 -0
- package/dist/{client-ypCm3zjt.d.ts → client-CHQTXpef.d.ts} +121 -36
- package/dist/client-react.d.ts +67 -20
- package/dist/client-react.js +240 -54
- package/dist/client-react.js.map +1 -1
- package/dist/client.d.ts +5 -4
- package/dist/client.js +51 -16
- package/dist/client.js.map +1 -1
- package/dist/{cloudflare-wrVYf4bb.js → cloudflare-CKHYXccw.js} +61 -82
- package/dist/cloudflare-CKHYXccw.js.map +1 -0
- package/dist/cloudflare.d.ts +106 -71
- package/dist/cloudflare.js +334 -271
- package/dist/cloudflare.js.map +1 -1
- package/dist/code-resolution-CL_7L0wS.js +22 -0
- package/dist/code-resolution-CL_7L0wS.js.map +1 -0
- package/dist/collection-api-DbyhLAY8.d.ts +1001 -0
- package/dist/config-DEzInG6M.js +4035 -0
- package/dist/config-DEzInG6M.js.map +1 -0
- package/dist/constants-D3GSH3tc.js +469 -0
- package/dist/constants-D3GSH3tc.js.map +1 -0
- package/dist/{context-DRZ3tZ5l.js → context-rlpSnHFA.js} +17 -17
- package/dist/context-rlpSnHFA.js.map +1 -0
- package/dist/cost-B52llVDx.js +330 -0
- package/dist/cost-B52llVDx.js.map +1 -0
- package/dist/{current-json-C6nhPOm1.js → current-json-CC6lE4Aj.js} +115 -32
- package/dist/current-json-CC6lE4Aj.js.map +1 -0
- package/dist/db-plFUNTSF.d.ts +130 -0
- package/dist/db-read-seams-BSs0m1z1.js +3261 -0
- package/dist/db-read-seams-BSs0m1z1.js.map +1 -0
- package/dist/{deploy-Di_Q01qx.js → deploy-Obj4nE-Z.js} +10 -14
- package/dist/deploy-Obj4nE-Z.js.map +1 -0
- package/dist/{dev-banner-CWHIk8tH.d.ts → dev-banner-B5AUHmu1.d.ts} +1 -4
- package/dist/dev-landing-BI5UdmOb.d.ts +32 -0
- package/dist/dev-landing-CD-si4dW.js +50 -0
- package/dist/dev-landing-CD-si4dW.js.map +1 -0
- package/dist/dev-vite.d.ts +9 -14
- package/dist/dev-vite.js +11 -10
- package/dist/dev-vite.js.map +1 -1
- package/dist/dev.d.ts +3 -2
- package/dist/dev.js +2 -1
- package/dist/doctor-BA0i-YAN.js +270 -0
- package/dist/doctor-BA0i-YAN.js.map +1 -0
- package/dist/dump-D1vX8ozg.js +133 -0
- package/dist/dump-D1vX8ozg.js.map +1 -0
- package/dist/errors-7Rk1HGCE.js +160 -0
- package/dist/errors-7Rk1HGCE.js.map +1 -0
- package/dist/{validate-DtljsCh1.js → export-BVL2EvYE.js} +409 -19
- package/dist/export-BVL2EvYE.js.map +1 -0
- package/dist/fsck-BWkPgov4.js +145 -0
- package/dist/fsck-BWkPgov4.js.map +1 -0
- package/dist/{gcs-admin-Bx6xSNJj.d.ts → gcs-admin-Dso1HWQj.d.ts} +18 -14
- package/dist/gcs.d.ts +19 -7
- package/dist/gcs.js +1 -2
- package/dist/{goog4-signer-Z7KnJ1su.js → goog4-signer-CeLIABoE.js} +102 -92
- package/dist/goog4-signer-CeLIABoE.js.map +1 -0
- package/dist/{http-7zT29K3P.js → http-Z5rZyYMX.js} +898 -271
- package/dist/http-Z5rZyYMX.js.map +1 -0
- package/dist/http-transport-DNUM8kU-.js +1299 -0
- package/dist/http-transport-DNUM8kU-.js.map +1 -0
- package/dist/http.d.ts +366 -294
- package/dist/http.js +2 -2
- package/dist/index-JJrIu1pO.d.ts +135 -0
- package/dist/index-LEgHN0qJ.d.ts +50 -0
- package/dist/{index-DP3ClvcA.d.ts → index-RiEYj8t0.d.ts} +291 -78
- package/dist/index.d.ts +27 -6
- package/dist/index.js +3 -5
- package/dist/inspect-BTsVYZKd.js +196 -0
- package/dist/inspect-BTsVYZKd.js.map +1 -0
- package/dist/{key-Di6yyxFu.js → key-C4FPZ9Io.js} +3 -4
- package/dist/{key-Di6yyxFu.js.map → key-C4FPZ9Io.js.map} +1 -1
- package/dist/ledger-Dj_bGgo0.js +192 -0
- package/dist/ledger-Dj_bGgo0.js.map +1 -0
- package/dist/legacy-names-DgZBtgOh.js +47 -0
- package/dist/legacy-names-DgZBtgOh.js.map +1 -0
- package/dist/log-C9W15Dfo.d.ts +94 -0
- package/dist/log-tail-DWJbneBF.js +142 -0
- package/dist/log-tail-DWJbneBF.js.map +1 -0
- package/dist/log-walk-C-vA-WGJ.js +111 -0
- package/dist/log-walk-C-vA-WGJ.js.map +1 -0
- package/dist/maintenance-Dd-Yakqj.js +1709 -0
- package/dist/maintenance-Dd-Yakqj.js.map +1 -0
- package/dist/maintenance-DevB6z4e.js +2237 -0
- package/dist/maintenance-DevB6z4e.js.map +1 -0
- package/dist/maintenance.d.ts +100 -3
- package/dist/maintenance.js +1 -3
- package/dist/node.d.ts +119 -92
- package/dist/node.js +3 -3
- package/dist/{observability-Ch-VQJyE.js → observability-C-ISCCLE.js} +1247 -326
- package/dist/observability-C-ISCCLE.js.map +1 -0
- package/dist/observability.d.ts +27 -3
- package/dist/observability.js +3 -3
- package/dist/path-segment-DBXG26PW.js +363 -0
- package/dist/path-segment-DBXG26PW.js.map +1 -0
- package/dist/{plan-C4qgiXSg.js → plan-BvQbaNMe.js} +19 -11
- package/dist/plan-BvQbaNMe.js.map +1 -0
- package/dist/request-CRWiTrza.js +272 -0
- package/dist/request-CRWiTrza.js.map +1 -0
- package/dist/restore-U6Im8V1V.js +1467 -0
- package/dist/restore-U6Im8V1V.js.map +1 -0
- package/dist/retry-OBtLB2GC.js +126 -0
- package/dist/retry-OBtLB2GC.js.map +1 -0
- package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
- package/dist/{runtime-spec--LykAdl1.js → runtime-spec-B5mg3pHF.js} +189 -28
- package/dist/runtime-spec-B5mg3pHF.js.map +1 -0
- package/dist/{s3-http-DD5gDc7t.d.ts → s3-http-DBC_wiCL.d.ts} +14 -8
- package/dist/s3.d.ts +20 -7
- package/dist/s3.js +4 -5
- package/dist/s3.js.map +1 -1
- package/dist/{sha256-CqcKTjw9.js → sha256-4FfGQNPw.js} +9 -9
- package/dist/sha256-4FfGQNPw.js.map +1 -0
- package/dist/{shared-secret-DgEicd3x.js → shared-secret-Vkur-8r0.js} +27 -15
- package/dist/shared-secret-Vkur-8r0.js.map +1 -0
- package/dist/{aws4fetch.esm-CXE5ZbAa.js → sigv4-sign-5IUflUD_.js} +143 -96
- package/dist/sigv4-sign-5IUflUD_.js.map +1 -0
- package/dist/snapshot-CknzkDM0.js +148 -0
- package/dist/snapshot-CknzkDM0.js.map +1 -0
- package/dist/{src-BMFfDUI2.js → src-Actga-bO.js} +949 -363
- package/dist/src-Actga-bO.js.map +1 -0
- package/dist/src-D0MQfvOp.js +812 -0
- package/dist/src-D0MQfvOp.js.map +1 -0
- package/dist/src-Dr9uo3dc.js +501 -0
- package/dist/src-Dr9uo3dc.js.map +1 -0
- package/dist/{subcommand-BV68pqwJ.js → subcommand-BLoF66dG.js} +89 -16
- package/dist/subcommand-BLoF66dG.js.map +1 -0
- package/dist/{time-DUqvFMHq.js → time-DRxTP9iv.js} +15 -34
- package/dist/time-DRxTP9iv.js.map +1 -0
- package/dist/types-suVbsEWS.d.ts +116 -0
- package/dist/{usage-BMZR8o6U.js → usage-CPzVhrQr.js} +40 -45
- package/dist/usage-CPzVhrQr.js.map +1 -0
- package/dist/uuid-BuT_c404.js +333 -0
- package/dist/uuid-BuT_c404.js.map +1 -0
- package/dist/verifier-Bmlmndzo.d.ts +95 -0
- package/dist/{wire-izfGZDvr.js → wire-DndvKU-K.js} +2 -3
- package/dist/wire-DndvKU-K.js.map +1 -0
- package/package.json +90 -69
- package/dist/aws4fetch.esm-CXE5ZbAa.js.map +0 -1
- package/dist/bytes-BXdamO3L.js +0 -11
- package/dist/bytes-BXdamO3L.js.map +0 -1
- package/dist/cloudflare-wrVYf4bb.js.map +0 -1
- package/dist/config-B6nTy8e2.js +0 -3095
- package/dist/config-B6nTy8e2.js.map +0 -1
- package/dist/constants-CfeMWQWk.js +0 -222
- package/dist/constants-CfeMWQWk.js.map +0 -1
- package/dist/context-DRZ3tZ5l.js.map +0 -1
- package/dist/cost-_SE_SVgZ.js +0 -203
- package/dist/cost-_SE_SVgZ.js.map +0 -1
- package/dist/current-json-C6nhPOm1.js.map +0 -1
- package/dist/db-DjjthkTi.d.ts +0 -254
- package/dist/deploy-Di_Q01qx.js.map +0 -1
- package/dist/doctor-RWVRpvat.js +0 -102
- package/dist/doctor-RWVRpvat.js.map +0 -1
- package/dist/dump-m2vEYDNY.js +0 -94
- package/dist/dump-m2vEYDNY.js.map +0 -1
- package/dist/errors-Dfa3p78c.js +0 -78
- package/dist/errors-Dfa3p78c.js.map +0 -1
- package/dist/export-DenKwEQu.js +0 -401
- package/dist/export-DenKwEQu.js.map +0 -1
- package/dist/fsck-2Vq-7-e2.js +0 -279
- package/dist/fsck-2Vq-7-e2.js.map +0 -1
- package/dist/goog4-signer-Z7KnJ1su.js.map +0 -1
- package/dist/http-7zT29K3P.js.map +0 -1
- package/dist/http-transport-BTgVCY5r.js +0 -1250
- package/dist/http-transport-BTgVCY5r.js.map +0 -1
- package/dist/index-BHz92Acj.d.ts +0 -162
- package/dist/index-CEZKQsKt.d.ts +0 -1113
- package/dist/index-uE-w2dgj.d.ts +0 -115
- package/dist/indexes-Dn9hbGQG.d.ts +0 -22
- package/dist/inspect-BpYbH1DM.js +0 -133
- package/dist/inspect-BpYbH1DM.js.map +0 -1
- package/dist/log-tail-QWU4wlu-.js +0 -514
- package/dist/log-tail-QWU4wlu-.js.map +0 -1
- package/dist/maintenance-BGHGt2Yg.d.ts +0 -537
- package/dist/maintenance-DULFcpd1.js +0 -2144
- package/dist/maintenance-DULFcpd1.js.map +0 -1
- package/dist/maintenance-fEi-UZ2o.js +0 -1412
- package/dist/maintenance-fEi-UZ2o.js.map +0 -1
- package/dist/normalize-rjnZLwS4.js +0 -133
- package/dist/normalize-rjnZLwS4.js.map +0 -1
- package/dist/observability-Ch-VQJyE.js.map +0 -1
- package/dist/plan-C4qgiXSg.js.map +0 -1
- package/dist/query-C43r-6ib.js +0 -1773
- package/dist/query-C43r-6ib.js.map +0 -1
- package/dist/rebuild-index-BH1dc1p6.js +0 -81
- package/dist/rebuild-index-BH1dc1p6.js.map +0 -1
- package/dist/request-u0M51mhJ.js +0 -72
- package/dist/request-u0M51mhJ.js.map +0 -1
- package/dist/restore-D0VYWzfP.js +0 -778
- package/dist/restore-D0VYWzfP.js.map +0 -1
- package/dist/rolldown-runtime-EAsCxrDo.js +0 -14
- package/dist/runtime-spec--LykAdl1.js.map +0 -1
- package/dist/sha256-CqcKTjw9.js.map +0 -1
- package/dist/shared-secret-DgEicd3x.js.map +0 -1
- package/dist/src-BMFfDUI2.js.map +0 -1
- package/dist/src-DYZ4H1aF.js +0 -392
- package/dist/src-DYZ4H1aF.js.map +0 -1
- package/dist/src-DvbTEya2.js +0 -536
- package/dist/src-DvbTEya2.js.map +0 -1
- package/dist/subcommand-BV68pqwJ.js.map +0 -1
- package/dist/time-DUqvFMHq.js.map +0 -1
- package/dist/usage-BMZR8o6U.js.map +0 -1
- package/dist/validate-DtljsCh1.js.map +0 -1
- package/dist/wire-izfGZDvr.js.map +0 -1
|
@@ -1,9 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { t as sharedSecret } from "./shared-secret-Vkur-8r0.js";
|
|
2
|
+
import { C as SHARED_SECRET_MISSING_MESSAGE, S as NO_AUTH_CONFIGURED_MESSAGE } from "./constants-D3GSH3tc.js";
|
|
3
|
+
import { t as BaerlyError } from "./errors-7Rk1HGCE.js";
|
|
4
|
+
// packages/server/src/auth/internal/none-verifier.ts
|
|
5
|
+
/**
|
|
6
|
+
* Internal helper backing `config.auth === "none"`. Returns a
|
|
7
|
+
* `Verifier` that resolves every request to the supplied
|
|
8
|
+
* `tenantPrefix` with `identity: { kind: "none" }`. The kernel
|
|
9
|
+
* NEVER reads the `Authorization` header in this mode — the network
|
|
10
|
+
* seam itself is the trust boundary.
|
|
11
|
+
*
|
|
12
|
+
* Discriminant note: `identity.kind === "none"` distinguishes the
|
|
13
|
+
* "operator opted into auth=none in baerly.config.ts" branch from the
|
|
14
|
+
* bearer-token paths (`kind: "shared-secret"`, `kind: "jwt"`, etc).
|
|
15
|
+
*
|
|
16
|
+
* Not part of the public surface. Consumed by `baerlyWorker` /
|
|
17
|
+
* `baerlyNode` resolution; the operator-facing API is the typed
|
|
18
|
+
* `auth: "none"` field on `BaerlyAppConfig`.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
const noAuthVerifier = (tenantPrefix) => {
|
|
23
|
+
return async () => ({
|
|
24
|
+
tenantPrefix,
|
|
25
|
+
identity: { kind: "none" }
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
// packages/server/src/auth/internal/resolve-verifier.ts
|
|
29
|
+
/**
|
|
30
|
+
* Resolve the per-request `Verifier` for an adapter factory using the
|
|
31
|
+
* fixed order:
|
|
32
|
+
*
|
|
33
|
+
* 1. `factoryVerifier` set → use as-is (highest precedence; enables
|
|
34
|
+
* env-aware construction via `cloudflareAccess(env)` etc).
|
|
35
|
+
* 2. else `config.auth === "shared-secret"` → read `SHARED_SECRET`
|
|
36
|
+
* via `readEnv`; throw `BaerlyError("InvalidConfig",
|
|
37
|
+
* SHARED_SECRET_MISSING_MESSAGE)` when unset/empty; else build
|
|
38
|
+
* `sharedSecret({ secret, tenantPrefix: config.tenant })`.
|
|
39
|
+
* 3. else `config.auth === "none"` → `noAuthVerifier(config.tenant)`.
|
|
40
|
+
* 4. else → throw `BaerlyError("InvalidConfig",
|
|
41
|
+
* NO_AUTH_CONFIGURED_MESSAGE)`.
|
|
42
|
+
*
|
|
43
|
+
* Pure function — no I/O, no side effects beyond `sharedSecret`'s
|
|
44
|
+
* own validation. Caller invokes once at adapter init time (or on
|
|
45
|
+
* first fetch, depending on platform `await`-at-top-level
|
|
46
|
+
* constraints).
|
|
47
|
+
*
|
|
48
|
+
* @throws BaerlyError code="InvalidConfig" — branches 2 and 4 above.
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
const resolveVerifier = (input) => {
|
|
53
|
+
if (input.factoryVerifier !== void 0) return input.factoryVerifier;
|
|
54
|
+
if (input.config.auth === "shared-secret") {
|
|
55
|
+
const secret = input.readEnv("SHARED_SECRET");
|
|
56
|
+
if (secret === void 0 || secret.length === 0) throw new BaerlyError("InvalidConfig", SHARED_SECRET_MISSING_MESSAGE);
|
|
57
|
+
return sharedSecret({
|
|
58
|
+
secret,
|
|
59
|
+
tenantPrefix: input.config.tenant
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (input.config.auth === "none") return noAuthVerifier(input.config.tenant);
|
|
63
|
+
throw new BaerlyError("InvalidConfig", NO_AUTH_CONFIGURED_MESSAGE);
|
|
64
|
+
};
|
|
65
|
+
// packages/server/src/http/security-headers.ts
|
|
66
|
+
/**
|
|
67
|
+
* Add `X-Content-Type-Options: nosniff` so a browser never renders a
|
|
68
|
+
* JSON body or a static asset as a type other than its `Content-Type`.
|
|
69
|
+
* The adapters apply it to every response they send.
|
|
70
|
+
*
|
|
71
|
+
* A `Response` from `fetch()` has immutable headers; that case is
|
|
72
|
+
* re-wrapped (same body stream, status, and headers) before setting.
|
|
73
|
+
*/
|
|
74
|
+
const withNosniff = (res) => {
|
|
75
|
+
if (res.headers.get("x-content-type-options") === "nosniff") return res;
|
|
76
|
+
try {
|
|
77
|
+
res.headers.set("x-content-type-options", "nosniff");
|
|
78
|
+
return res;
|
|
79
|
+
} catch {
|
|
80
|
+
const copy = new Response(res.body, res);
|
|
81
|
+
copy.headers.set("x-content-type-options", "nosniff");
|
|
82
|
+
return copy;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
// packages/server/src/spec/runtime-spec.ts
|
|
3
86
|
const specIr = {
|
|
4
87
|
$schema: "https://baerly.dev/spec/ir-schema.json",
|
|
5
88
|
specVersion: "1",
|
|
6
|
-
serverVersion: "0.
|
|
89
|
+
serverVersion: "0.7.0",
|
|
7
90
|
errorCodes: [
|
|
8
91
|
{
|
|
9
92
|
"code": "InvalidConfig",
|
|
@@ -48,11 +131,39 @@ const specIr = {
|
|
|
48
131
|
"summary": "Document body failed schema validation; carries .issues."
|
|
49
132
|
},
|
|
50
133
|
{
|
|
51
|
-
"code": "
|
|
134
|
+
"code": "WriteConflict",
|
|
52
135
|
"httpStatus": 409,
|
|
53
136
|
"retriable": true,
|
|
54
|
-
"messagePolicy": "
|
|
55
|
-
"summary": "
|
|
137
|
+
"messagePolicy": "scrubbed",
|
|
138
|
+
"summary": "A concurrent write won the race; the losing commit did not land. Re-read, then retry."
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"code": "AlreadyExists",
|
|
142
|
+
"httpStatus": 409,
|
|
143
|
+
"retriable": false,
|
|
144
|
+
"messagePolicy": "public",
|
|
145
|
+
"summary": "The create target already exists (duplicate _id); never retriable."
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"code": "AmbiguousCommit",
|
|
149
|
+
"httpStatus": 409,
|
|
150
|
+
"retriable": false,
|
|
151
|
+
"messagePolicy": "scrubbed",
|
|
152
|
+
"summary": "A committing create may be durable, but its outcome could not be resolved; reconcile before any deliberate retry."
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"code": "CapacityExceeded",
|
|
156
|
+
"httpStatus": 409,
|
|
157
|
+
"retriable": false,
|
|
158
|
+
"messagePolicy": "public",
|
|
159
|
+
"summary": "The request needs more work than this host does in one request and was refused whole: a read returns no rows, a write commits nothing (a batch refused part-way keeps its committed rows). Not retriable unchanged; follow the resolution."
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"code": "MaintenancePending",
|
|
163
|
+
"httpStatus": 503,
|
|
164
|
+
"retriable": true,
|
|
165
|
+
"messagePolicy": "public",
|
|
166
|
+
"summary": "Maintenance is behind on this collection; the write was refused and not committed. Retry after the Retry-After delay."
|
|
56
167
|
},
|
|
57
168
|
{
|
|
58
169
|
"code": "Unauthorized",
|
|
@@ -75,6 +186,13 @@ const specIr = {
|
|
|
75
186
|
"messagePolicy": "public",
|
|
76
187
|
"summary": "Request body exceeded MAX_BODY_BYTES."
|
|
77
188
|
},
|
|
189
|
+
{
|
|
190
|
+
"code": "UnsupportedMediaType",
|
|
191
|
+
"httpStatus": 415,
|
|
192
|
+
"retriable": false,
|
|
193
|
+
"messagePolicy": "public",
|
|
194
|
+
"summary": "A POST, PATCH or PUT body was not sent as application/json (or a +json type)."
|
|
195
|
+
},
|
|
78
196
|
{
|
|
79
197
|
"code": "UnsatisfiablePredicate",
|
|
80
198
|
"httpStatus": 400,
|
|
@@ -82,6 +200,13 @@ const specIr = {
|
|
|
82
200
|
"messagePolicy": "public",
|
|
83
201
|
"summary": "Predicate is well-formed but contradicts itself."
|
|
84
202
|
},
|
|
203
|
+
{
|
|
204
|
+
"code": "CursorExpired",
|
|
205
|
+
"httpStatus": 410,
|
|
206
|
+
"retriable": false,
|
|
207
|
+
"messagePolicy": "public",
|
|
208
|
+
"summary": "A /v1/since cursor can no longer resume (its changes are no longer retained, or its generation was truncated); re-read, then restart with cursor \"\". Never retriable."
|
|
209
|
+
},
|
|
85
210
|
{
|
|
86
211
|
"code": "UseQueryAwaitedRecorder",
|
|
87
212
|
"httpStatus": null,
|
|
@@ -140,22 +265,26 @@ const specIr = {
|
|
|
140
265
|
{
|
|
141
266
|
"name": "first",
|
|
142
267
|
"params": "",
|
|
143
|
-
"returns": "Promise<T | undefined>"
|
|
268
|
+
"returns": "Promise<(T & { _id: string }) | undefined>",
|
|
269
|
+
"throws": ["CapacityExceeded"]
|
|
144
270
|
},
|
|
145
271
|
{
|
|
146
272
|
"name": "all",
|
|
147
273
|
"params": "",
|
|
148
|
-
"returns": "Promise<T[]>"
|
|
274
|
+
"returns": "Promise<(T & { _id: string })[]>",
|
|
275
|
+
"throws": ["CapacityExceeded"]
|
|
149
276
|
},
|
|
150
277
|
{
|
|
151
278
|
"name": "count",
|
|
152
279
|
"params": "",
|
|
153
|
-
"returns": "Promise<number>"
|
|
280
|
+
"returns": "Promise<number>",
|
|
281
|
+
"throws": ["CapacityExceeded"]
|
|
154
282
|
},
|
|
155
283
|
{
|
|
156
284
|
"name": "get",
|
|
157
285
|
"params": "id: string",
|
|
158
|
-
"returns": "Promise<T | undefined>"
|
|
286
|
+
"returns": "Promise<(T & { _id: string }) | undefined>",
|
|
287
|
+
"throws": ["CapacityExceeded"]
|
|
159
288
|
},
|
|
160
289
|
{
|
|
161
290
|
"name": "where",
|
|
@@ -174,15 +303,28 @@ const specIr = {
|
|
|
174
303
|
},
|
|
175
304
|
{
|
|
176
305
|
"name": "insert",
|
|
177
|
-
"params": "doc: Partial<T> & DocumentData",
|
|
306
|
+
"params": "doc: Partial<T> & DocumentData & { _id?: string }",
|
|
178
307
|
"returns": "Promise<{ _id: string }>",
|
|
179
|
-
"throws": [
|
|
308
|
+
"throws": [
|
|
309
|
+
"SchemaError",
|
|
310
|
+
"AlreadyExists",
|
|
311
|
+
"WriteConflict",
|
|
312
|
+
"AmbiguousCommit",
|
|
313
|
+
"CapacityExceeded",
|
|
314
|
+
"MaintenancePending"
|
|
315
|
+
]
|
|
180
316
|
},
|
|
181
317
|
{
|
|
182
318
|
"name": "update",
|
|
183
|
-
"params": "id: string, patch:
|
|
319
|
+
"params": "id: string, patch: MergePatch<T>",
|
|
184
320
|
"returns": "Promise<{ modified: number }>",
|
|
185
|
-
"throws": [
|
|
321
|
+
"throws": [
|
|
322
|
+
"SchemaError",
|
|
323
|
+
"WriteConflict",
|
|
324
|
+
"AmbiguousCommit",
|
|
325
|
+
"CapacityExceeded",
|
|
326
|
+
"MaintenancePending"
|
|
327
|
+
]
|
|
186
328
|
},
|
|
187
329
|
{
|
|
188
330
|
"name": "replace",
|
|
@@ -190,15 +332,22 @@ const specIr = {
|
|
|
190
332
|
"returns": "Promise<void>",
|
|
191
333
|
"throws": [
|
|
192
334
|
"SchemaError",
|
|
193
|
-
"
|
|
194
|
-
"NotFound"
|
|
335
|
+
"WriteConflict",
|
|
336
|
+
"NotFound",
|
|
337
|
+
"AmbiguousCommit",
|
|
338
|
+
"CapacityExceeded",
|
|
339
|
+
"MaintenancePending"
|
|
195
340
|
]
|
|
196
341
|
},
|
|
197
342
|
{
|
|
198
343
|
"name": "delete",
|
|
199
344
|
"params": "id: string",
|
|
200
345
|
"returns": "Promise<{ deleted: number }>",
|
|
201
|
-
"throws": [
|
|
346
|
+
"throws": [
|
|
347
|
+
"WriteConflict",
|
|
348
|
+
"AmbiguousCommit",
|
|
349
|
+
"CapacityExceeded"
|
|
350
|
+
]
|
|
202
351
|
}
|
|
203
352
|
],
|
|
204
353
|
queryMethods: [
|
|
@@ -220,29 +369,42 @@ const specIr = {
|
|
|
220
369
|
{
|
|
221
370
|
"name": "first",
|
|
222
371
|
"params": "",
|
|
223
|
-
"returns": "Promise<T | undefined>"
|
|
372
|
+
"returns": "Promise<(T & { _id: string }) | undefined>",
|
|
373
|
+
"throws": ["CapacityExceeded"]
|
|
224
374
|
},
|
|
225
375
|
{
|
|
226
376
|
"name": "all",
|
|
227
377
|
"params": "",
|
|
228
|
-
"returns": "Promise<T[]>"
|
|
378
|
+
"returns": "Promise<(T & { _id: string })[]>",
|
|
379
|
+
"throws": ["CapacityExceeded"]
|
|
229
380
|
},
|
|
230
381
|
{
|
|
231
382
|
"name": "count",
|
|
232
383
|
"params": "",
|
|
233
|
-
"returns": "Promise<number>"
|
|
384
|
+
"returns": "Promise<number>",
|
|
385
|
+
"throws": ["CapacityExceeded"]
|
|
234
386
|
},
|
|
235
387
|
{
|
|
236
388
|
"name": "update",
|
|
237
|
-
"params": "patch:
|
|
389
|
+
"params": "patch: MergePatch<T>",
|
|
238
390
|
"returns": "Promise<{ modified: number }>",
|
|
239
|
-
"throws": [
|
|
391
|
+
"throws": [
|
|
392
|
+
"SchemaError",
|
|
393
|
+
"WriteConflict",
|
|
394
|
+
"AmbiguousCommit",
|
|
395
|
+
"CapacityExceeded",
|
|
396
|
+
"MaintenancePending"
|
|
397
|
+
]
|
|
240
398
|
},
|
|
241
399
|
{
|
|
242
400
|
"name": "delete",
|
|
243
401
|
"params": "",
|
|
244
402
|
"returns": "Promise<{ deleted: number }>",
|
|
245
|
-
"throws": [
|
|
403
|
+
"throws": [
|
|
404
|
+
"WriteConflict",
|
|
405
|
+
"AmbiguousCommit",
|
|
406
|
+
"CapacityExceeded"
|
|
407
|
+
]
|
|
246
408
|
}
|
|
247
409
|
],
|
|
248
410
|
storageInterface: [
|
|
@@ -310,7 +472,7 @@ const specIr = {
|
|
|
310
472
|
"method": "POST",
|
|
311
473
|
"path": "/v1/c/:collection",
|
|
312
474
|
"auth": "verified",
|
|
313
|
-
"summary": "Insert a document."
|
|
475
|
+
"summary": "Insert a document (body { doc, mintedId? })."
|
|
314
476
|
},
|
|
315
477
|
{
|
|
316
478
|
"method": "PATCH",
|
|
@@ -334,7 +496,7 @@ const specIr = {
|
|
|
334
496
|
"method": "GET",
|
|
335
497
|
"path": "/v1/count",
|
|
336
498
|
"auth": "verified",
|
|
337
|
-
"summary": "Count matching rows."
|
|
499
|
+
"summary": "Count matching rows (?collection=, ?where=, ?limit=)."
|
|
338
500
|
},
|
|
339
501
|
{
|
|
340
502
|
"method": "GET",
|
|
@@ -385,7 +547,6 @@ async function handleSpecRequest(request, resolve) {
|
|
|
385
547
|
headers: { "content-type": "application/json" }
|
|
386
548
|
});
|
|
387
549
|
}
|
|
388
|
-
|
|
389
|
-
export { handleSpecRequest as t };
|
|
550
|
+
export { withNosniff as n, resolveVerifier as r, handleSpecRequest as t };
|
|
390
551
|
|
|
391
|
-
//# sourceMappingURL=runtime-spec
|
|
552
|
+
//# sourceMappingURL=runtime-spec-B5mg3pHF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-spec-B5mg3pHF.js","names":["rawSpecIr"],"sources":["../packages/server/src/auth/internal/none-verifier.ts","../packages/server/src/auth/internal/resolve-verifier.ts","../packages/server/src/http/security-headers.ts","../packages/server/spec/baerly.spec.json","../packages/server/src/spec/runtime-spec.ts"],"sourcesContent":["import type { Verifier } from \"@baerly/protocol\";\n\n/**\n * Internal helper backing `config.auth === \"none\"`. Returns a\n * `Verifier` that resolves every request to the supplied\n * `tenantPrefix` with `identity: { kind: \"none\" }`. The kernel\n * NEVER reads the `Authorization` header in this mode — the network\n * seam itself is the trust boundary.\n *\n * Discriminant note: `identity.kind === \"none\"` distinguishes the\n * \"operator opted into auth=none in baerly.config.ts\" branch from the\n * bearer-token paths (`kind: \"shared-secret\"`, `kind: \"jwt\"`, etc).\n *\n * Not part of the public surface. Consumed by `baerlyWorker` /\n * `baerlyNode` resolution; the operator-facing API is the typed\n * `auth: \"none\"` field on `BaerlyAppConfig`.\n *\n * @internal\n */\nexport const noAuthVerifier = (tenantPrefix: string): Verifier => {\n return async () => ({ tenantPrefix, identity: { kind: \"none\" } });\n};\n","import {\n type BaerlyAppConfig,\n BaerlyError,\n NO_AUTH_CONFIGURED_MESSAGE,\n SHARED_SECRET_MISSING_MESSAGE,\n type Verifier,\n} from \"@baerly/protocol\";\nimport { sharedSecret } from \"../presets/shared-secret.ts\";\nimport { noAuthVerifier } from \"./none-verifier.ts\";\n\n/**\n * Read env var lazily via a host-supplied accessor so the same\n * resolver works in CF Workers (env binding) and Node\n * (`process.env`). Returns `undefined` for an unset OR empty string —\n * both branches mean \"operator forgot to set it\".\n */\ntype EnvAccessor = (name: string) => string | undefined;\n\n/**\n * Inputs to {@link resolveVerifier}. `factoryVerifier` is the\n * adapter-factory `verifier:` option (may be undefined). `config`\n * carries the typed `auth` posture + the `tenant` pin. `readEnv`\n * is the per-host env accessor.\n */\nexport interface ResolveVerifierInput {\n readonly factoryVerifier: Verifier | undefined;\n readonly config: BaerlyAppConfig;\n readonly readEnv: EnvAccessor;\n}\n\n/**\n * Resolve the per-request `Verifier` for an adapter factory using the\n * fixed order:\n *\n * 1. `factoryVerifier` set → use as-is (highest precedence; enables\n * env-aware construction via `cloudflareAccess(env)` etc).\n * 2. else `config.auth === \"shared-secret\"` → read `SHARED_SECRET`\n * via `readEnv`; throw `BaerlyError(\"InvalidConfig\",\n * SHARED_SECRET_MISSING_MESSAGE)` when unset/empty; else build\n * `sharedSecret({ secret, tenantPrefix: config.tenant })`.\n * 3. else `config.auth === \"none\"` → `noAuthVerifier(config.tenant)`.\n * 4. else → throw `BaerlyError(\"InvalidConfig\",\n * NO_AUTH_CONFIGURED_MESSAGE)`.\n *\n * Pure function — no I/O, no side effects beyond `sharedSecret`'s\n * own validation. Caller invokes once at adapter init time (or on\n * first fetch, depending on platform `await`-at-top-level\n * constraints).\n *\n * @throws BaerlyError code=\"InvalidConfig\" — branches 2 and 4 above.\n *\n * @internal\n */\nexport const resolveVerifier = (input: ResolveVerifierInput): Verifier => {\n if (input.factoryVerifier !== undefined) {\n return input.factoryVerifier;\n }\n if (input.config.auth === \"shared-secret\") {\n const secret = input.readEnv(\"SHARED_SECRET\");\n if (secret === undefined || secret.length === 0) {\n throw new BaerlyError(\"InvalidConfig\", SHARED_SECRET_MISSING_MESSAGE);\n }\n return sharedSecret({ secret, tenantPrefix: input.config.tenant });\n }\n if (input.config.auth === \"none\") {\n return noAuthVerifier(input.config.tenant);\n }\n // Exhaustiveness backstop. The AuthConfig union is locked to\n // [\"none\", \"shared-secret\"]; reaching this branch means the caller\n // passed a config that has neither the typed field nor a factory\n // override. Same operator remediation as the type-level error.\n throw new BaerlyError(\"InvalidConfig\", NO_AUTH_CONFIGURED_MESSAGE);\n};\n","/**\n * Add `X-Content-Type-Options: nosniff` so a browser never renders a\n * JSON body or a static asset as a type other than its `Content-Type`.\n * The adapters apply it to every response they send.\n *\n * A `Response` from `fetch()` has immutable headers; that case is\n * re-wrapped (same body stream, status, and headers) before setting.\n */\nexport const withNosniff = (res: Response): Response => {\n if (res.headers.get(\"x-content-type-options\") === \"nosniff\") {\n return res;\n }\n try {\n res.headers.set(\"x-content-type-options\", \"nosniff\");\n return res;\n } catch {\n const copy = new Response(res.body, res);\n copy.headers.set(\"x-content-type-options\", \"nosniff\");\n return copy;\n }\n};\n","","import type { BaerlyConfig, Verifier } from \"@baerly/protocol\";\nimport type { SpecIR } from \"./ir.ts\";\nimport rawSpecIr from \"../../spec/baerly.spec.json\" with { type: \"json\" };\n\n// Import the JSON as data (not ir.ts which drags the HTTP router into\n// the kernel closure). Cast to SpecIR so callers get typed access to\n// errorCodes, specVersion, etc. without following the ir.ts import chain.\nconst specIr = rawSpecIr as unknown as SpecIR;\n\n/** A declared collection summary, emitted only to authed callers. */\nexport interface SpecCollection {\n readonly name: string;\n readonly indexes: ReadonlyArray<string>;\n readonly schemaVendor?: string;\n}\n\n/** The /v1/spec response: the static IR plus an optional authed collections section. */\nexport type SpecResponse = SpecIR & { collections?: ReadonlyArray<SpecCollection> };\n\n/**\n * Build the /v1/spec response body. With no `config` (anonymous caller)\n * the static contract IR is returned verbatim. With a `config` (the\n * request already carried a valid identity), the declared collection\n * names + index names + schema vendor are appended — these are gated\n * behind the verifier so unauthenticated callers can't enumerate tenant\n * collection names.\n */\nexport function buildSpecResponse(config?: BaerlyConfig): SpecResponse {\n if (config === undefined) {\n return specIr as SpecResponse;\n }\n const collections: SpecCollection[] = Object.entries(config.collections).map(\n ([name, def]): SpecCollection => {\n const indexes = (def.indexes ?? []).map((ix) => ix.name);\n if (def.schema !== undefined) {\n return { name, indexes, schemaVendor: def.schema[\"~standard\"].vendor };\n }\n return { name, indexes };\n },\n );\n return { ...(specIr as SpecResponse), collections };\n}\n\n// Shared `GET /v1/spec` handler for both adapters (keeps the response shape\n// from drifting). `resolve` yields the adapter's verifier + tenant config.\n// Run tolerantly: any `resolve` or verifier failure degrades to the anonymous\n// static contract — it is public infra that must stay up when auth/config is\n// unhealthy. Collections are appended only for a non-null identity, so an\n// unauthenticated probe never enumerates them.\nexport async function handleSpecRequest(\n request: Request,\n resolve: () => Promise<{ verifier: Verifier; config: BaerlyConfig | undefined }>,\n): Promise<Response> {\n let config: BaerlyConfig | undefined;\n try {\n const { verifier, config: resolved } = await resolve();\n const identity = await verifier(request);\n if (identity !== null) {\n config = resolved;\n }\n } catch (error) {\n // A verifier *reject* is `null` (handled above); reaching here means\n // resolve() or the verifier *threw* — the auth backend or tenant config\n // is unhealthy. Stay tolerant (the static contract is public infra and\n // must stay up), but emit one operational signal so the outage isn't\n // invisible on this anonymous, pre-observability route. `console.warn`\n // (not a canonical line) matches the adapters' other ops warnings and\n // keeps this light module out of the observability closure. Log only the\n // error *message*, never the error object: an auth-backend failure can\n // carry credential material (tokens, keys, connection strings) in its\n // fields/stack, and this line lands in plaintext logs.\n const reason = error instanceof Error ? error.message : String(error);\n console.warn(`[baerly] /v1/spec degraded to the anonymous contract: ${reason}`);\n }\n return new Response(JSON.stringify(buildSpecResponse(config)), {\n status: 200,\n headers: { \"content-type\": \"application/json\" },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAmBA,MAAa,kBAAkB,iBAAmC;CAChE,OAAO,aAAa;EAAE;EAAc,UAAU,EAAE,MAAM,OAAO;CAAE;AACjE;;;;;;;;;;;;;;;;;;;;;;;;;ACgCA,MAAa,mBAAmB,UAA0C;CACxE,IAAI,MAAM,oBAAoB,KAAA,GAC5B,OAAO,MAAM;CAEf,IAAI,MAAM,OAAO,SAAS,iBAAiB;EACzC,MAAM,SAAS,MAAM,QAAQ,eAAe;EAC5C,IAAI,WAAW,KAAA,KAAa,OAAO,WAAW,GAC5C,MAAM,IAAI,YAAY,iBAAiB,6BAA6B;EAEtE,OAAO,aAAa;GAAE;GAAQ,cAAc,MAAM,OAAO;EAAO,CAAC;CACnE;CACA,IAAI,MAAM,OAAO,SAAS,QACxB,OAAO,eAAe,MAAM,OAAO,MAAM;CAM3C,MAAM,IAAI,YAAY,iBAAiB,0BAA0B;AACnE;;;;;;;;;;AChEA,MAAa,eAAe,QAA4B;CACtD,IAAI,IAAI,QAAQ,IAAI,wBAAwB,MAAM,WAChD,OAAO;CAET,IAAI;EACF,IAAI,QAAQ,IAAI,0BAA0B,SAAS;EACnD,OAAO;CACT,QAAQ;EACN,MAAM,OAAO,IAAI,SAAS,IAAI,MAAM,GAAG;EACvC,KAAK,QAAQ,IAAI,0BAA0B,SAAS;EACpD,OAAO;CACT;AACF;;AEbA,MAAM,SAASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAAA;;;;;;;;;AAoBf,SAAgB,kBAAkB,QAAqC;CACrE,IAAI,WAAW,KAAA,GACb,OAAO;CAET,MAAM,cAAgC,OAAO,QAAQ,OAAO,WAAW,CAAC,CAAC,KACtE,CAAC,MAAM,SAAyB;EAC/B,MAAM,WAAW,IAAI,WAAW,CAAC,EAAA,CAAG,KAAK,OAAO,GAAG,IAAI;EACvD,IAAI,IAAI,WAAW,KAAA,GACjB,OAAO;GAAE;GAAM;GAAS,cAAc,IAAI,OAAO,YAAY,CAAC;EAAO;EAEvE,OAAO;GAAE;GAAM;EAAQ;CACzB,CACF;CACA,OAAO;EAAE,GAAI;EAAyB;CAAY;AACpD;AAQA,eAAsB,kBACpB,SACA,SACmB;CACnB,IAAI;CACJ,IAAI;EACF,MAAM,EAAE,UAAU,QAAQ,aAAa,MAAM,QAAQ;EAErD,IAAI,MADmB,SAAS,OAAO,MACtB,MACf,SAAS;CAEb,SAAS,OAAO;EAWd,MAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EACpE,QAAQ,KAAK,yDAAyD,QAAQ;CAChF;CACA,OAAO,IAAI,SAAS,KAAK,UAAU,kBAAkB,MAAM,CAAC,GAAG;EAC7D,QAAQ;EACR,SAAS,EAAE,gBAAgB,mBAAmB;CAChD,CAAC;AACH"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region packages/adapter-node/src/s3-http.d.ts
|
|
1
|
+
import { a as StoragePutOptions, i as StorageListEntry, n as StorageGetOptions, o as StoragePutResult, r as StorageGetResult, t as Storage } from "./types-suVbsEWS.js";
|
|
4
2
|
/**
|
|
5
3
|
* Construction-time options for {@link S3HttpStorage}. Everything is
|
|
6
4
|
* optional except `endpoint` and `bucket`; the consumer chooses how
|
|
@@ -27,9 +25,19 @@ interface S3HttpStorageOptions {
|
|
|
27
25
|
* directly.
|
|
28
26
|
*/
|
|
29
27
|
sign?: (req: Request) => Promise<Request>;
|
|
30
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Retries after the first attempt, for throttled and transient failures
|
|
30
|
+
* alike (and per `list` page). Default `STORAGE_RETRY_MAX_ATTEMPTS - 1`
|
|
31
|
+
* (2, so 3 attempts in total); `0` sends each request once. Must be a
|
|
32
|
+
* non-negative integer; any other value makes each request reject with
|
|
33
|
+
* `InvalidConfig` before it is sent.
|
|
34
|
+
*/
|
|
31
35
|
retries?: number;
|
|
32
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Backoff base in ms, overriding both default bases (50 ms after a
|
|
38
|
+
* transient failure, 1 s after a throttle). Full jitter applies either
|
|
39
|
+
* way. Omit for the default policy.
|
|
40
|
+
*/
|
|
33
41
|
backoffMs?: number;
|
|
34
42
|
}
|
|
35
43
|
/**
|
|
@@ -57,6 +65,4 @@ declare class S3HttpStorage implements Storage {
|
|
|
57
65
|
signal?: AbortSignal;
|
|
58
66
|
}): AsyncIterable<StorageListEntry>;
|
|
59
67
|
}
|
|
60
|
-
|
|
61
|
-
export { S3HttpStorageOptions as n, S3HttpStorage as t };
|
|
62
|
-
//# sourceMappingURL=s3-http-DD5gDc7t.d.ts.map
|
|
68
|
+
export { S3HttpStorageOptions as n, S3HttpStorage as t };
|
package/dist/s3.d.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Runtime-neutral S3-over-HTTP storage entry
|
|
3
|
+
* (`@gusto/baerly-storage/s3`).
|
|
4
|
+
*
|
|
5
|
+
* Unlike `@gusto/baerly-storage/node`, this subpath's import closure
|
|
6
|
+
* contains **no** `node:` builtins, so it bundles into a Cloudflare
|
|
7
|
+
* Worker. Reach for it when a Worker must talk to S3 / cross-account
|
|
8
|
+
* R2 over the S3 REST API instead of a native R2 binding.
|
|
9
|
+
*
|
|
10
|
+
* Bundle cost: pulls `aws4fetch` (SigV4) + `@rgrove/parse-xml` (XML). Workers
|
|
11
|
+
* that use a same-account R2 binding should stay on
|
|
12
|
+
* `@gusto/baerly-storage/cloudflare`, whose closure carries neither.
|
|
13
|
+
*
|
|
14
|
+
* The Worker-safety of this closure is enforced by the esbuild probe in
|
|
15
|
+
* `tests/integration/s3-worker-safe.test.ts` — the layer linter does not
|
|
16
|
+
* cover it (adapter-node is Node-only by design).
|
|
17
|
+
*/
|
|
18
|
+
import { n as S3HttpStorageOptions, t as S3HttpStorage } from "./s3-http-DBC_wiCL.js";
|
|
4
19
|
/**
|
|
5
20
|
* Static-credential inputs for {@link sigV4Signer}.
|
|
6
21
|
*/
|
|
@@ -41,7 +56,5 @@ interface SigV4SignerOptions {
|
|
|
41
56
|
* });
|
|
42
57
|
* ```
|
|
43
58
|
*/
|
|
44
|
-
declare function sigV4Signer(opts: SigV4SignerOptions): (req: Request) => Promise<Request>;
|
|
45
|
-
|
|
46
|
-
export { S3HttpStorage, type S3HttpStorageOptions, type SigV4SignerOptions, sigV4Signer };
|
|
47
|
-
//# sourceMappingURL=s3.d.ts.map
|
|
59
|
+
export declare function sigV4Signer(opts: SigV4SignerOptions): (req: Request) => Promise<Request>;
|
|
60
|
+
export { S3HttpStorage, type S3HttpStorageOptions, type SigV4SignerOptions };
|
package/dist/s3.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { n as AwsClient, r as S3HttpStorage, t as signHeadersOnly } from "./sigv4-sign-5IUflUD_.js";
|
|
2
|
+
import { t as BaerlyError } from "./errors-7Rk1HGCE.js";
|
|
3
|
+
// packages/adapter-node/src/s3-signer.ts
|
|
4
4
|
/**
|
|
5
5
|
* Static-credential SigV4 signer for {@link S3HttpStorage}, safe inside
|
|
6
6
|
* a Cloudflare Worker: `aws4fetch` signs with WebCrypto, so there is no
|
|
@@ -37,9 +37,8 @@ function sigV4Signer(opts) {
|
|
|
37
37
|
region,
|
|
38
38
|
service: "s3"
|
|
39
39
|
});
|
|
40
|
-
return (req) => client
|
|
40
|
+
return (req) => signHeadersOnly(client, req);
|
|
41
41
|
}
|
|
42
|
-
//#endregion
|
|
43
42
|
export { S3HttpStorage, sigV4Signer };
|
|
44
43
|
|
|
45
44
|
//# sourceMappingURL=s3.js.map
|
package/dist/s3.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"s3.js","names":[],"sources":["../packages/adapter-node/src/s3-signer.ts"],"sourcesContent":["import { BaerlyError } from \"@baerly/protocol\";\nimport { AwsClient } from \"aws4fetch\";\n\n/**\n * Static-credential inputs for {@link sigV4Signer}.\n */\nexport interface SigV4SignerOptions {\n // Typed `string | undefined`, not `string`: the documented usage feeds\n // these straight from a Worker `env` / `process.env`, where an absent key\n // is `undefined` at runtime even when the ambient env type claims `string`.\n // The keys stay required (so a caller can't silently omit one), but the\n // value may be absent — `sigV4Signer` fail-closes on absent/blank below.\n /** AWS access key id (or R2 / Minio equivalent). */\n accessKeyId: string | undefined;\n /** AWS secret access key (or R2 / Minio equivalent). */\n secretAccessKey: string | undefined;\n /**\n * Region, e.g. `\"us-east-1\"`. R2 ignores the value but `aws4fetch`\n * requires one — use `\"auto\"` for R2's S3-compat endpoint.\n */\n region: string | undefined;\n /** Optional STS session token for temporary credentials. */\n sessionToken?: string;\n}\n\n/**\n * Static-credential SigV4 signer for {@link S3HttpStorage}, safe inside\n * a Cloudflare Worker: `aws4fetch` signs with WebCrypto, so there is no\n * `node:crypto` in the closure. Returns the `(req) => Promise<Request>`\n * seam `S3HttpStorageOptions.sign` expects.\n *\n * For rotating credentials, pass your own `(req) => Promise<Request>`\n * to `S3HttpStorage` instead — this helper covers the static case.\n *\n * @example\n * ```ts\n * import { S3HttpStorage, sigV4Signer } from \"@gusto/baerly-storage/s3\";\n *\n * const storage = new S3HttpStorage({\n * endpoint: env.S3_ENDPOINT,\n * bucket: env.S3_BUCKET,\n * sign: sigV4Signer({\n * accessKeyId: env.AWS_ACCESS_KEY_ID,\n * secretAccessKey: env.AWS_SECRET_ACCESS_KEY,\n * region: env.AWS_REGION,\n * }),\n * });\n * ```\n */\nexport function sigV4Signer(opts: SigV4SignerOptions): (req: Request) => Promise<Request> {\n // Fail fast on blank credentials. A wrangler `var` declared but left\n // empty resolves to \"\" — without this guard aws4fetch signs with empty\n // creds and the endpoint answers an opaque 403 on the first request,\n // far from the misconfig. Mirrors the fail-closed contract on\n // `resolveWorkerStorage` and `sharedSecret` (empty `SHARED_SECRET`).\n //\n // Coalesce-then-trim once, then both validate AND sign with the trimmed\n // values. A `var`/env key declared *nowhere* resolves to `undefined` at\n // runtime — the most common misconfig — and a bare `.trim()` on it throws\n // a raw `TypeError` more opaque than the 403 this guard exists to prevent;\n // `?? \"\"` routes absent and blank alike into the fail-closed check.\n // Trimming catches a whitespace-only value (`\" \"`, `\"\\t\\n\"`), truthy in JS\n // but signing-blank in effect, and — critically — feeds the *trimmed*\n // value to `AwsClient`: a stray leading/trailing space on an otherwise\n // valid credential (a copy-paste artifact) would otherwise pass the guard\n // yet sign with the padded value, producing an invalid signature and the\n // same opaque 403. `region` gets the same treatment — an empty region\n // yields a malformed SigV4 scope (`YYYYMMDD//s3/aws4_request`).\n const accessKeyId = (opts.accessKeyId ?? \"\").trim();\n const secretAccessKey = (opts.secretAccessKey ?? \"\").trim();\n const region = (opts.region ?? \"\").trim();\n if (!accessKeyId || !secretAccessKey || !region) {\n throw new BaerlyError(\n \"InvalidConfig\",\n \"sigV4Signer: `accessKeyId`, `secretAccessKey`, and `region` must be \" +\n \"non-empty. Check the credentials passed from your Worker `env` / \" +\n \"process env.\",\n );\n }\n const client = new AwsClient({\n accessKeyId,\n secretAccessKey,\n sessionToken: opts.sessionToken,\n region,\n service: \"s3\",\n });\n return (req: Request) => client
|
|
1
|
+
{"version":3,"file":"s3.js","names":[],"sources":["../packages/adapter-node/src/s3-signer.ts"],"sourcesContent":["import { BaerlyError } from \"@baerly/protocol\";\nimport { AwsClient } from \"aws4fetch\";\nimport { signHeadersOnly } from \"./sigv4-sign.ts\";\n\n/**\n * Static-credential inputs for {@link sigV4Signer}.\n */\nexport interface SigV4SignerOptions {\n // Typed `string | undefined`, not `string`: the documented usage feeds\n // these straight from a Worker `env` / `process.env`, where an absent key\n // is `undefined` at runtime even when the ambient env type claims `string`.\n // The keys stay required (so a caller can't silently omit one), but the\n // value may be absent — `sigV4Signer` fail-closes on absent/blank below.\n /** AWS access key id (or R2 / Minio equivalent). */\n accessKeyId: string | undefined;\n /** AWS secret access key (or R2 / Minio equivalent). */\n secretAccessKey: string | undefined;\n /**\n * Region, e.g. `\"us-east-1\"`. R2 ignores the value but `aws4fetch`\n * requires one — use `\"auto\"` for R2's S3-compat endpoint.\n */\n region: string | undefined;\n /** Optional STS session token for temporary credentials. */\n sessionToken?: string;\n}\n\n/**\n * Static-credential SigV4 signer for {@link S3HttpStorage}, safe inside\n * a Cloudflare Worker: `aws4fetch` signs with WebCrypto, so there is no\n * `node:crypto` in the closure. Returns the `(req) => Promise<Request>`\n * seam `S3HttpStorageOptions.sign` expects.\n *\n * For rotating credentials, pass your own `(req) => Promise<Request>`\n * to `S3HttpStorage` instead — this helper covers the static case.\n *\n * @example\n * ```ts\n * import { S3HttpStorage, sigV4Signer } from \"@gusto/baerly-storage/s3\";\n *\n * const storage = new S3HttpStorage({\n * endpoint: env.S3_ENDPOINT,\n * bucket: env.S3_BUCKET,\n * sign: sigV4Signer({\n * accessKeyId: env.AWS_ACCESS_KEY_ID,\n * secretAccessKey: env.AWS_SECRET_ACCESS_KEY,\n * region: env.AWS_REGION,\n * }),\n * });\n * ```\n */\nexport function sigV4Signer(opts: SigV4SignerOptions): (req: Request) => Promise<Request> {\n // Fail fast on blank credentials. A wrangler `var` declared but left\n // empty resolves to \"\" — without this guard aws4fetch signs with empty\n // creds and the endpoint answers an opaque 403 on the first request,\n // far from the misconfig. Mirrors the fail-closed contract on\n // `resolveWorkerStorage` and `sharedSecret` (empty `SHARED_SECRET`).\n //\n // Coalesce-then-trim once, then both validate AND sign with the trimmed\n // values. A `var`/env key declared *nowhere* resolves to `undefined` at\n // runtime — the most common misconfig — and a bare `.trim()` on it throws\n // a raw `TypeError` more opaque than the 403 this guard exists to prevent;\n // `?? \"\"` routes absent and blank alike into the fail-closed check.\n // Trimming catches a whitespace-only value (`\" \"`, `\"\\t\\n\"`), truthy in JS\n // but signing-blank in effect, and — critically — feeds the *trimmed*\n // value to `AwsClient`: a stray leading/trailing space on an otherwise\n // valid credential (a copy-paste artifact) would otherwise pass the guard\n // yet sign with the padded value, producing an invalid signature and the\n // same opaque 403. `region` gets the same treatment — an empty region\n // yields a malformed SigV4 scope (`YYYYMMDD//s3/aws4_request`).\n const accessKeyId = (opts.accessKeyId ?? \"\").trim();\n const secretAccessKey = (opts.secretAccessKey ?? \"\").trim();\n const region = (opts.region ?? \"\").trim();\n if (!accessKeyId || !secretAccessKey || !region) {\n throw new BaerlyError(\n \"InvalidConfig\",\n \"sigV4Signer: `accessKeyId`, `secretAccessKey`, and `region` must be \" +\n \"non-empty. Check the credentials passed from your Worker `env` / \" +\n \"process env.\",\n );\n }\n const client = new AwsClient({\n accessKeyId,\n secretAccessKey,\n sessionToken: opts.sessionToken,\n region,\n service: \"s3\",\n });\n return (req: Request) => signHeadersOnly(client, req);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,YAAY,MAA8D;CAmBxF,MAAM,eAAe,KAAK,eAAe,GAAA,CAAI,KAAK;CAClD,MAAM,mBAAmB,KAAK,mBAAmB,GAAA,CAAI,KAAK;CAC1D,MAAM,UAAU,KAAK,UAAU,GAAA,CAAI,KAAK;CACxC,IAAI,CAAC,eAAe,CAAC,mBAAmB,CAAC,QACvC,MAAM,IAAI,YACR,iBACA,mJAGF;CAEF,MAAM,SAAS,IAAI,UAAU;EAC3B;EACA;EACA,cAAc,KAAK;EACnB;EACA,SAAS;CACX,CAAC;CACD,QAAQ,QAAiB,gBAAgB,QAAQ,GAAG;AACtD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// packages/protocol/src/sha256.ts
|
|
2
2
|
/**
|
|
3
3
|
* SHA-256 of `bytes` as a 64-char lowercase hex string.
|
|
4
4
|
*
|
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
* (e.g. {@link versionFromContent}'s content keys) slice the return.
|
|
9
9
|
*/
|
|
10
10
|
const sha256Hex = async (bytes) => {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
let view;
|
|
12
|
+
if (bytes.buffer instanceof ArrayBuffer) view = bytes;
|
|
13
|
+
else {
|
|
14
|
+
view = new Uint8Array(bytes.byteLength);
|
|
15
|
+
view.set(bytes);
|
|
16
|
+
}
|
|
13
17
|
const digest = await crypto.subtle.digest("SHA-256", view);
|
|
14
|
-
|
|
15
|
-
let hex = "";
|
|
16
|
-
for (let i = 0; i < out.length; i++) hex += out[i].toString(16).padStart(2, "0");
|
|
17
|
-
return hex;
|
|
18
|
+
return new Uint8Array(digest).toHex();
|
|
18
19
|
};
|
|
19
|
-
//#endregion
|
|
20
20
|
export { sha256Hex as t };
|
|
21
21
|
|
|
22
|
-
//# sourceMappingURL=sha256-
|
|
22
|
+
//# sourceMappingURL=sha256-4FfGQNPw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sha256-4FfGQNPw.js","names":[],"sources":["../packages/protocol/src/sha256.ts"],"sourcesContent":["/**\n * SHA-256 of `bytes` as a 64-char lowercase hex string.\n *\n * Zero-import leaf module on purpose: co-locating this with heavier\n * runtime (snapshot-hash.ts / hashing.ts) would drag that module into\n * every consumer's bundle closure. Callers that want a truncated form\n * (e.g. {@link versionFromContent}'s content keys) slice the return.\n */\nexport const sha256Hex = async (bytes: Uint8Array): Promise<string> => {\n // tsc narrows `Uint8Array` to `Uint8Array<ArrayBufferLike>`, which\n // `crypto.subtle.digest` rejects (wants `ArrayBufferView<ArrayBuffer>`;\n // microsoft/TypeScript#61375). A view over an `ArrayBuffer` is passed\n // through and hashes only its own bytes, even at an offset; digest\n // copies its input synchronously. A `SharedArrayBuffer`-backed view is\n // not a valid `BufferSource`, so copy that case.\n let view: Uint8Array<ArrayBuffer>;\n if (bytes.buffer instanceof ArrayBuffer) {\n // Narrowing `bytes.buffer` does not narrow `bytes`; the check above is the proof.\n view = bytes as Uint8Array<ArrayBuffer>;\n } else {\n view = new Uint8Array(bytes.byteLength);\n view.set(bytes);\n }\n const digest = await crypto.subtle.digest(\"SHA-256\", view);\n return new Uint8Array(digest).toHex();\n};\n"],"mappings":";;;;;;;;;AAQA,MAAa,YAAY,OAAO,UAAuC;CAOrE,IAAI;CACJ,IAAI,MAAM,kBAAkB,aAE1B,OAAO;MACF;EACL,OAAO,IAAI,WAAW,MAAM,UAAU;EACtC,KAAK,IAAI,KAAK;CAChB;CACA,MAAM,SAAS,MAAM,OAAO,OAAO,OAAO,WAAW,IAAI;CACzD,OAAO,IAAI,WAAW,MAAM,CAAC,CAAC,MAAM;AACtC"}
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import { t as BaerlyError } from "./errors-
|
|
2
|
-
|
|
1
|
+
import { t as BaerlyError } from "./errors-7Rk1HGCE.js";
|
|
2
|
+
// packages/protocol/src/auth-resolution.ts
|
|
3
3
|
/** Corrective action for a `sharedSecret(...)` preset misconfig; crosses the wire. */
|
|
4
4
|
const SHARED_SECRET_CONFIG_RESOLUTION = "Pass a non-empty `secret` and a non-empty `tenantPrefix` with no \"/\" to sharedSecret({ secret, tenantPrefix }).";
|
|
5
5
|
/** Corrective action for a `bearerJwt(...)` preset misconfig; crosses the wire. */
|
|
6
|
-
const BEARER_JWT_CONFIG_RESOLUTION = "Provide non-empty `issuer`, `audience`, and at least one `algorithms` entry; `tenantClaim` and `tenantPrefix` are mutually exclusive and `tenantPrefix` must be non-empty with no \"/\".";
|
|
6
|
+
const BEARER_JWT_CONFIG_RESOLUTION = "Provide non-empty `issuer`, `audience`, and at least one `algorithms` entry; `tenantClaim` and `tenantPrefix` are mutually exclusive and `tenantPrefix` must be non-empty with no \"/\"; `clockSkewMs` and `jwksCacheTtlMs`, when set, must be >= 0.";
|
|
7
7
|
/** Corrective action for a `cloudflareAccess(...)` preset misconfig; crosses the wire. */
|
|
8
|
-
const CLOUDFLARE_ACCESS_CONFIG_RESOLUTION = "Pass a
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const CLOUDFLARE_ACCESS_CONFIG_RESOLUTION = "Pass a bare team name as `teamDomain` (lowercase letters, digits and \"-\", e.g. `acme`) and a 64-char lowercase-hex `audienceTag` (the Application Audience (AUD) tag from the CF Access app config).";
|
|
9
|
+
/**
|
|
10
|
+
* Accepted form of a Cloudflare Access `teamDomain`: the bare team name
|
|
11
|
+
* (`acme`), not the `acme.cloudflareaccess.com` host. The
|
|
12
|
+
* `cloudflareAccess` preset interpolates it into the JWKS host
|
|
13
|
+
* `https://<teamDomain>.cloudflareaccess.com`, so a `/`, `@`, `.` or `:`
|
|
14
|
+
* could point the key fetch at another host. Shared by the preset, the
|
|
15
|
+
* CLI config loader and `baerly doctor` so all three accept the same set.
|
|
16
|
+
*
|
|
17
|
+
* Sited here rather than in `constants.ts`: this module is already in
|
|
18
|
+
* the `auth.js` closure, and importing `constants.ts` from the preset
|
|
19
|
+
* would add about 0.6 KB min-gz to it.
|
|
20
|
+
*/
|
|
21
|
+
const CF_ACCESS_TEAM_NAME_PATTERN = /^[a-z0-9-]+$/;
|
|
22
|
+
// packages/server/src/auth/internal/timing-safe-equal.ts
|
|
11
23
|
/**
|
|
12
24
|
* Constant-time byte-array equality. Length mismatch short-circuits —
|
|
13
25
|
* the attacker already knows the expected length is a few-dozen bytes,
|
|
@@ -24,8 +36,8 @@ const timingSafeEqual = (a, b) => {
|
|
|
24
36
|
for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];
|
|
25
37
|
return diff === 0;
|
|
26
38
|
};
|
|
27
|
-
|
|
28
|
-
|
|
39
|
+
// packages/server/src/auth/presets/shared-secret.ts
|
|
40
|
+
const utf8Encoder = new TextEncoder();
|
|
29
41
|
/**
|
|
30
42
|
* Build a `Verifier` that accepts `Authorization: Bearer <secret>`
|
|
31
43
|
* and pins every request to a single tenant. The simplest preset —
|
|
@@ -61,19 +73,19 @@ const timingSafeEqual = (a, b) => {
|
|
|
61
73
|
* ```
|
|
62
74
|
*/
|
|
63
75
|
const sharedSecret = (opts) => {
|
|
64
|
-
if (opts.secret.length === 0) throw new BaerlyError("InvalidConfig", "sharedSecret: secret must be non-empty",
|
|
65
|
-
if (opts.tenantPrefix.length === 0 || opts.tenantPrefix.includes("/")) throw new BaerlyError("InvalidConfig", `sharedSecret: tenantPrefix must be non-empty and "/"-free (got ${JSON.stringify(opts.tenantPrefix)})`,
|
|
66
|
-
const expected =
|
|
76
|
+
if (opts.secret.length === 0) throw new BaerlyError("InvalidConfig", "sharedSecret: secret must be non-empty", { resolution: SHARED_SECRET_CONFIG_RESOLUTION });
|
|
77
|
+
if (opts.tenantPrefix.length === 0 || opts.tenantPrefix.includes("/")) throw new BaerlyError("InvalidConfig", `sharedSecret: tenantPrefix must be non-empty and "/"-free (got ${JSON.stringify(opts.tenantPrefix)})`, { resolution: SHARED_SECRET_CONFIG_RESOLUTION });
|
|
78
|
+
const expected = utf8Encoder.encode(`Bearer ${opts.secret}`);
|
|
67
79
|
return async (req) => {
|
|
68
80
|
const header = req.headers.get("Authorization") ?? "";
|
|
69
|
-
|
|
81
|
+
const actual = utf8Encoder.encode(header);
|
|
82
|
+
if (!timingSafeEqual(expected, actual)) return null;
|
|
70
83
|
return {
|
|
71
84
|
tenantPrefix: opts.tenantPrefix,
|
|
72
85
|
identity: { kind: "shared-secret" }
|
|
73
86
|
};
|
|
74
87
|
};
|
|
75
88
|
};
|
|
76
|
-
|
|
77
|
-
export { BEARER_JWT_CONFIG_RESOLUTION as n, CLOUDFLARE_ACCESS_CONFIG_RESOLUTION as r, sharedSecret as t };
|
|
89
|
+
export { CLOUDFLARE_ACCESS_CONFIG_RESOLUTION as i, BEARER_JWT_CONFIG_RESOLUTION as n, CF_ACCESS_TEAM_NAME_PATTERN as r, sharedSecret as t };
|
|
78
90
|
|
|
79
|
-
//# sourceMappingURL=shared-secret-
|
|
91
|
+
//# sourceMappingURL=shared-secret-Vkur-8r0.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-secret-Vkur-8r0.js","names":[],"sources":["../packages/protocol/src/auth-resolution.ts","../packages/server/src/auth/internal/timing-safe-equal.ts","../packages/server/src/auth/presets/shared-secret.ts"],"sourcesContent":["/** Corrective action for a `sharedSecret(...)` preset misconfig; crosses the wire. */\nexport const SHARED_SECRET_CONFIG_RESOLUTION: string =\n 'Pass a non-empty `secret` and a non-empty `tenantPrefix` with no \"/\" to sharedSecret({ secret, tenantPrefix }).';\n\n/** Corrective action for a `bearerJwt(...)` preset misconfig; crosses the wire. */\nexport const BEARER_JWT_CONFIG_RESOLUTION: string =\n 'Provide non-empty `issuer`, `audience`, and at least one `algorithms` entry; `tenantClaim` and `tenantPrefix` are mutually exclusive and `tenantPrefix` must be non-empty with no \"/\"; `clockSkewMs` and `jwksCacheTtlMs`, when set, must be >= 0.';\n\n/** Corrective action for a `cloudflareAccess(...)` preset misconfig; crosses the wire. */\nexport const CLOUDFLARE_ACCESS_CONFIG_RESOLUTION: string =\n 'Pass a bare team name as `teamDomain` (lowercase letters, digits and \"-\", e.g. `acme`) and a 64-char lowercase-hex `audienceTag` (the Application Audience (AUD) tag from the CF Access app config).';\n\n/**\n * Accepted form of a Cloudflare Access `teamDomain`: the bare team name\n * (`acme`), not the `acme.cloudflareaccess.com` host. The\n * `cloudflareAccess` preset interpolates it into the JWKS host\n * `https://<teamDomain>.cloudflareaccess.com`, so a `/`, `@`, `.` or `:`\n * could point the key fetch at another host. Shared by the preset, the\n * CLI config loader and `baerly doctor` so all three accept the same set.\n *\n * Sited here rather than in `constants.ts`: this module is already in\n * the `auth.js` closure, and importing `constants.ts` from the preset\n * would add about 0.6 KB min-gz to it.\n */\nexport const CF_ACCESS_TEAM_NAME_PATTERN: RegExp = /^[a-z0-9-]+$/;\n","/**\n * Constant-time byte-array equality. Length mismatch short-circuits —\n * the attacker already knows the expected length is a few-dozen bytes,\n * so revealing it is a non-secret. The diff loop only runs when the\n * lengths match, so its timing cannot leak the position of the first\n * differing byte.\n *\n * Hoisted out of {@link sharedSecret} so future verifiers can reuse\n * the same implementation — one TODO is easier to land than two.\n */\nexport const timingSafeEqual = (a: Uint8Array, b: Uint8Array): boolean => {\n if (a.length !== b.length) {\n return false;\n }\n let diff = 0;\n for (let i = 0; i < a.length; i++) {\n diff |= a[i]! ^ b[i]!;\n }\n return diff === 0;\n};\n","import { BaerlyError, SHARED_SECRET_CONFIG_RESOLUTION, type Verifier } from \"@baerly/protocol\";\nimport { timingSafeEqual } from \"../internal/timing-safe-equal.ts\";\n\nconst utf8Encoder = new TextEncoder();\n\n/**\n * Options for {@link sharedSecret}.\n *\n * - `secret` — the bearer token clients must present. Compared with\n * constant-time `timingSafeEqual` — see {@link sharedSecret} for\n * why naive `===` is not enough.\n * - `tenantPrefix` — the value returned in `VerifierResult.tenantPrefix`.\n * Single-tenant deployments pass a constant (`\"acme\"`). Multi-tenant\n * deployments don't use `sharedSecret`; they reach for `bearerJwt`\n * or `cloudflareAccess` instead.\n */\nexport interface SharedSecretOptions {\n readonly secret: string;\n readonly tenantPrefix: string;\n}\n\n/**\n * Build a `Verifier` that accepts `Authorization: Bearer <secret>`\n * and pins every request to a single tenant. The simplest preset —\n * use for single-tenant deployments before you've stood up an IdP.\n *\n * **Why constant-time compare:** a naive `===` against the bearer\n * token leaks timing information about which character first\n * differed. Real-world relevance over HTTPS is debated, but\n * `timingSafeEqual` is one line of code and erases the question.\n *\n * **Identity shape.** On success the returned `VerifierResult` has:\n * ```ts\n * { tenantPrefix: \"<configured>\", identity: { kind: \"shared-secret\" } }\n * ```\n * `sharedSecret` has no notion of a per-user subject — every caller\n * presenting the bearer is the same principal. Downstream code that\n * wants a stable per-request `sender_sub` should fall back to a\n * synthetic value (`\"shared-secret:\" + tenantPrefix`) when\n * `identity.kind === \"shared-secret\"`. The `kind` field is the\n * discriminant across all preset identities; switch on it instead of\n * sniffing properties.\n *\n * @throws BaerlyError code=\"InvalidConfig\" — `secret` empty or\n * `tenantPrefix` empty / contains \"/\".\n *\n * @example\n * ```ts\n * import { sharedSecret } from \"@gusto/baerly-storage/auth\";\n * const verifier = sharedSecret({\n * secret: env.SHARED_SECRET,\n * tenantPrefix: \"acme\",\n * });\n * ```\n */\nexport const sharedSecret = (opts: SharedSecretOptions): Verifier => {\n if (opts.secret.length === 0) {\n throw new BaerlyError(\"InvalidConfig\", \"sharedSecret: secret must be non-empty\", {\n resolution: SHARED_SECRET_CONFIG_RESOLUTION,\n });\n }\n if (opts.tenantPrefix.length === 0 || opts.tenantPrefix.includes(\"/\")) {\n throw new BaerlyError(\n \"InvalidConfig\",\n `sharedSecret: tenantPrefix must be non-empty and \"/\"-free (got ${JSON.stringify(opts.tenantPrefix)})`,\n { resolution: SHARED_SECRET_CONFIG_RESOLUTION },\n );\n }\n const expected = utf8Encoder.encode(`Bearer ${opts.secret}`);\n return async (req: Request) => {\n const header = req.headers.get(\"Authorization\") ?? \"\";\n const actual = utf8Encoder.encode(header);\n if (!timingSafeEqual(expected, actual)) {\n return null;\n }\n return { tenantPrefix: opts.tenantPrefix, identity: { kind: \"shared-secret\" } };\n };\n};\n"],"mappings":";;;AACA,MAAa,kCACX;;AAGF,MAAa,+BACX;;AAGF,MAAa,sCACX;;;;;;;;;;;;;AAcF,MAAa,8BAAsC;;;;;;;;;;;;ACdnD,MAAa,mBAAmB,GAAe,MAA2B;CACxE,IAAI,EAAE,WAAW,EAAE,QACjB,OAAO;CAET,IAAI,OAAO;CACX,KAAK,IAAI,IAAI,GAAG,IAAI,EAAE,QAAQ,KAC5B,QAAQ,EAAE,KAAM,EAAE;CAEpB,OAAO,SAAS;AAClB;;AChBA,MAAM,cAAc,IAAI,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDpC,MAAa,gBAAgB,SAAwC;CACnE,IAAI,KAAK,OAAO,WAAW,GACzB,MAAM,IAAI,YAAY,iBAAiB,0CAA0C,EAC/E,YAAY,gCACd,CAAC;CAEH,IAAI,KAAK,aAAa,WAAW,KAAK,KAAK,aAAa,SAAS,GAAG,GAClE,MAAM,IAAI,YACR,iBACA,kEAAkE,KAAK,UAAU,KAAK,YAAY,EAAE,IACpG,EAAE,YAAY,gCAAgC,CAChD;CAEF,MAAM,WAAW,YAAY,OAAO,UAAU,KAAK,QAAQ;CAC3D,OAAO,OAAO,QAAiB;EAC7B,MAAM,SAAS,IAAI,QAAQ,IAAI,eAAe,KAAK;EACnD,MAAM,SAAS,YAAY,OAAO,MAAM;EACxC,IAAI,CAAC,gBAAgB,UAAU,MAAM,GACnC,OAAO;EAET,OAAO;GAAE,cAAc,KAAK;GAAc,UAAU,EAAE,MAAM,gBAAgB;EAAE;CAChF;AACF"}
|