@gusto/baerly-storage 0.2.0 → 0.4.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/LICENSE +202 -0
- package/NOTICE +29 -0
- package/README.md +176 -70
- package/dist/API.md +213 -139
- package/dist/CHANGELOG.md +434 -0
- package/dist/RECIPES.md +125 -0
- package/dist/THIRD-PARTY-LICENSES.txt +238 -0
- package/dist/{app-config-C0Bbw_Z6.d.ts → app-config-DyiFK3_k.d.ts} +55 -11
- package/dist/app-config.d.ts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +301 -301
- package/dist/auth.js.map +1 -1
- package/dist/aws4fetch.esm-p7eEzLCs.js +1702 -0
- package/dist/aws4fetch.esm-p7eEzLCs.js.map +1 -0
- package/dist/baerly.js +35 -15
- package/dist/baerly.js.map +1 -1
- package/dist/baerly.spec.json +342 -0
- package/dist/bytes-BXdamO3L.js.map +1 -1
- package/dist/{client-DYZfoZb9.d.ts → client-Fe8CwB73.d.ts} +10 -10
- package/dist/client-react.d.ts +3 -3
- package/dist/client-react.js +4 -4
- package/dist/client-react.js.map +1 -1
- package/dist/client.d.ts +4 -4
- package/dist/client.js +3 -3
- package/dist/client.js.map +1 -1
- package/dist/{cloudflare-CINJPKCW.js → cloudflare-DzKBrUlg.js} +178 -2
- package/dist/cloudflare-DzKBrUlg.js.map +1 -0
- package/dist/cloudflare.d.ts +49 -6
- package/dist/cloudflare.js +59 -26
- package/dist/cloudflare.js.map +1 -1
- package/dist/config-1tv0-Yzm.js +2693 -0
- package/dist/config-1tv0-Yzm.js.map +1 -0
- package/dist/constants-CfeMWQWk.js +222 -0
- package/dist/constants-CfeMWQWk.js.map +1 -0
- package/dist/context-DRZ3tZ5l.js.map +1 -1
- package/dist/{cost-CQt1YRkA.js → cost-DSMIVqzL.js} +43 -42
- package/dist/cost-DSMIVqzL.js.map +1 -0
- package/dist/current-json-C6nhPOm1.js +190 -0
- package/dist/current-json-C6nhPOm1.js.map +1 -0
- package/dist/{db-BM3y2JQw.d.ts → db-DsPkOVEH.d.ts} +26 -108
- package/dist/{deploy-CrAbfgCq.js → deploy-DonTr-CV.js} +12 -5
- package/dist/deploy-DonTr-CV.js.map +1 -0
- package/dist/dev-vite.d.ts +11 -7
- package/dist/dev-vite.js +7 -6
- package/dist/dev-vite.js.map +1 -1
- package/dist/dev.d.ts +1 -1
- package/dist/dev.js +1 -1
- package/dist/{doctor-Db-hzPmE.js → doctor-DSIyCDg_.js} +14 -136
- package/dist/doctor-DSIyCDg_.js.map +1 -0
- package/dist/{dump-BYA55NLP.js → dump-Bh5k26VQ.js} +10 -31
- package/dist/dump-Bh5k26VQ.js.map +1 -0
- package/dist/{errors-DOdL95kK.js → errors-Dfa3p78c.js} +25 -5
- package/dist/errors-Dfa3p78c.js.map +1 -0
- package/dist/{export-Bhbz90-z.js → export-DtF5tDIM.js} +11 -32
- package/dist/{export-Bhbz90-z.js.map → export-DtF5tDIM.js.map} +1 -1
- package/dist/{fsck-CPPZWt9p.js → fsck-D_djMO5D.js} +28 -39
- package/dist/fsck-D_djMO5D.js.map +1 -0
- package/dist/{http-Cw8p6y5b.js → http-DxM9MflO.js} +151 -79
- package/dist/http-DxM9MflO.js.map +1 -0
- package/dist/http.d.ts +42 -26
- package/dist/http.js +3 -2
- package/dist/{index-DwDTWPSU.d.ts → index-0rZcMBwy.d.ts} +10 -7
- package/dist/{index-C3JAH1Yo.d.ts → index-B6oexfOB.d.ts} +9 -9
- package/dist/{index-cUY-36AN.d.ts → index-BNRh23K9.d.ts} +21 -5
- package/dist/{index-DSvwEUeF.d.ts → index-BYk9oCNf.d.ts} +240 -202
- package/dist/index.d.ts +6 -6
- package/dist/index.js +5 -5
- package/dist/{indexes-DAu2AkTW.d.ts → indexes-Dn9hbGQG.d.ts} +2 -2
- package/dist/{inspect-Bdbzvi-_.js → inspect-6WZ-pC7-.js} +21 -36
- package/dist/inspect-6WZ-pC7-.js.map +1 -0
- package/dist/key-Di6yyxFu.js +35 -0
- package/dist/key-Di6yyxFu.js.map +1 -0
- package/dist/{snapshot-SS8USDUF.js → log-tail-D98U1JBo.js} +179 -84
- package/dist/log-tail-D98U1JBo.js.map +1 -0
- package/dist/{maintenance-ClzBC1Vv.js → maintenance-B4Dki6Ig.js} +438 -176
- package/dist/maintenance-B4Dki6Ig.js.map +1 -0
- package/dist/{maintenance-BRrThz8V.d.ts → maintenance-B_e0T99L.d.ts} +114 -26
- package/dist/{maintenance-BvOv6BMM.js → maintenance-C7coQp4c.js} +217 -94
- package/dist/maintenance-C7coQp4c.js.map +1 -0
- package/dist/maintenance.d.ts +3 -2
- package/dist/maintenance.js +3 -2
- package/dist/node.d.ts +176 -68
- package/dist/node.js +3 -2
- package/dist/{normalize-XWY25_sG.js → normalize-rjnZLwS4.js} +2 -2
- package/dist/normalize-rjnZLwS4.js.map +1 -0
- package/dist/{observability-CpOiEN0k.js → observability-wzs3-BL_.js} +279 -109
- package/dist/observability-wzs3-BL_.js.map +1 -0
- package/dist/observability.d.ts +3 -3
- package/dist/observability.js +1 -1
- package/dist/{plan-DOTl21vq.js → plan-a7PJHBCy.js} +7 -4
- package/dist/plan-a7PJHBCy.js.map +1 -0
- package/dist/{query-BmiQy328.js → query-rAtXNQQB.js} +1063 -1202
- package/dist/query-rAtXNQQB.js.map +1 -0
- package/dist/{rebuild-index-DC_nR6wP.js → rebuild-index-BVzQSZlm.js} +10 -32
- package/dist/rebuild-index-BVzQSZlm.js.map +1 -0
- package/dist/{request-BEF_OvMh.js → request-u0M51mhJ.js} +3 -3
- package/dist/{request-BEF_OvMh.js.map → request-u0M51mhJ.js.map} +1 -1
- package/dist/restore-R-4rbciV.js +778 -0
- package/dist/restore-R-4rbciV.js.map +1 -0
- package/dist/runtime-spec-qL3_lTTU.js +391 -0
- package/dist/runtime-spec-qL3_lTTU.js.map +1 -0
- package/dist/s3-http-B-z8th6O.d.ts +60 -0
- package/dist/s3.d.ts +47 -0
- package/dist/s3.js +45 -0
- package/dist/s3.js.map +1 -0
- package/dist/{shared-secret-BJdSwpgw.js → shared-secret-DgEicd3x.js} +13 -5
- package/dist/shared-secret-DgEicd3x.js.map +1 -0
- package/dist/src-BG20LZs7.js +2271 -0
- package/dist/src-BG20LZs7.js.map +1 -0
- package/dist/{src-zhEAmmF7.js → src-CYHFDrKz.js} +82 -99
- package/dist/src-CYHFDrKz.js.map +1 -0
- package/dist/{src-QQ7jDeL2.js → src-DYZ4H1aF.js} +44 -23
- package/dist/src-DYZ4H1aF.js.map +1 -0
- package/dist/subcommand-DoDA-K7d.js +197 -0
- package/dist/subcommand-DoDA-K7d.js.map +1 -0
- package/dist/time-DUqvFMHq.js +119 -0
- package/dist/time-DUqvFMHq.js.map +1 -0
- package/dist/{usage-CLjirdD-.js → usage-DBV1eQHC.js} +7 -22
- package/dist/usage-DBV1eQHC.js.map +1 -0
- package/dist/{validate-DCq_0DIn.js → validate-DtljsCh1.js} +51 -51
- package/dist/{validate-DCq_0DIn.js.map → validate-DtljsCh1.js.map} +1 -1
- package/dist/wire-izfGZDvr.js.map +1 -1
- package/package.json +77 -42
- package/dist/cloudflare-CINJPKCW.js.map +0 -1
- package/dist/config-DVfDGyw1.js +0 -278
- package/dist/config-DVfDGyw1.js.map +0 -1
- package/dist/cost-CQt1YRkA.js.map +0 -1
- package/dist/current-json-C-EyJqs0.js +0 -354
- package/dist/current-json-C-EyJqs0.js.map +0 -1
- package/dist/deploy-CrAbfgCq.js.map +0 -1
- package/dist/doctor-Db-hzPmE.js.map +0 -1
- package/dist/dump-BYA55NLP.js.map +0 -1
- package/dist/errors-DOdL95kK.js.map +0 -1
- package/dist/fsck-CPPZWt9p.js.map +0 -1
- package/dist/http-Cw8p6y5b.js.map +0 -1
- package/dist/inspect-Bdbzvi-_.js.map +0 -1
- package/dist/maintenance-BvOv6BMM.js.map +0 -1
- package/dist/maintenance-ClzBC1Vv.js.map +0 -1
- package/dist/normalize-XWY25_sG.js.map +0 -1
- package/dist/observability-CpOiEN0k.js.map +0 -1
- package/dist/plan-DOTl21vq.js.map +0 -1
- package/dist/query-BmiQy328.js.map +0 -1
- package/dist/rebuild-index-DC_nR6wP.js.map +0 -1
- package/dist/restore-C6IcmLeA.js +0 -771
- package/dist/restore-C6IcmLeA.js.map +0 -1
- package/dist/shared-secret-BJdSwpgw.js.map +0 -1
- package/dist/snapshot-SS8USDUF.js.map +0 -1
- package/dist/src-DU1sCMlr.js +0 -6236
- package/dist/src-DU1sCMlr.js.map +0 -1
- package/dist/src-QQ7jDeL2.js.map +0 -1
- package/dist/src-zhEAmmF7.js.map +0 -1
- package/dist/subcommand-DZcHcsYp.js +0 -5122
- package/dist/subcommand-DZcHcsYp.js.map +0 -1
- package/dist/usage-CLjirdD-.js.map +0 -1
- /package/dist/{chunk-EAsCxrDo.js → rolldown-runtime-EAsCxrDo.js} +0 -0
package/dist/s3.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { n as S3HttpStorageOptions, t as S3HttpStorage } from "./s3-http-B-z8th6O.js";
|
|
2
|
+
|
|
3
|
+
//#region packages/adapter-node/src/s3-signer.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Static-credential inputs for {@link sigV4Signer}.
|
|
6
|
+
*/
|
|
7
|
+
interface SigV4SignerOptions {
|
|
8
|
+
/** AWS access key id (or R2 / Minio equivalent). */
|
|
9
|
+
accessKeyId: string | undefined;
|
|
10
|
+
/** AWS secret access key (or R2 / Minio equivalent). */
|
|
11
|
+
secretAccessKey: string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Region, e.g. `"us-east-1"`. R2 ignores the value but `aws4fetch`
|
|
14
|
+
* requires one — use `"auto"` for R2's S3-compat endpoint.
|
|
15
|
+
*/
|
|
16
|
+
region: string | undefined;
|
|
17
|
+
/** Optional STS session token for temporary credentials. */
|
|
18
|
+
sessionToken?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Static-credential SigV4 signer for {@link S3HttpStorage}, safe inside
|
|
22
|
+
* a Cloudflare Worker: `aws4fetch` signs with WebCrypto, so there is no
|
|
23
|
+
* `node:crypto` in the closure. Returns the `(req) => Promise<Request>`
|
|
24
|
+
* seam `S3HttpStorageOptions.sign` expects.
|
|
25
|
+
*
|
|
26
|
+
* For rotating credentials, pass your own `(req) => Promise<Request>`
|
|
27
|
+
* to `S3HttpStorage` instead — this helper covers the static case.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { S3HttpStorage, sigV4Signer } from "@gusto/baerly-storage/s3";
|
|
32
|
+
*
|
|
33
|
+
* const storage = new S3HttpStorage({
|
|
34
|
+
* endpoint: env.S3_ENDPOINT,
|
|
35
|
+
* bucket: env.S3_BUCKET,
|
|
36
|
+
* sign: sigV4Signer({
|
|
37
|
+
* accessKeyId: env.AWS_ACCESS_KEY_ID,
|
|
38
|
+
* secretAccessKey: env.AWS_SECRET_ACCESS_KEY,
|
|
39
|
+
* region: env.AWS_REGION,
|
|
40
|
+
* }),
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function sigV4Signer(opts: SigV4SignerOptions): (req: Request) => Promise<Request>;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { S3HttpStorage, type S3HttpStorageOptions, type SigV4SignerOptions, sigV4Signer };
|
|
47
|
+
//# sourceMappingURL=s3.d.ts.map
|
package/dist/s3.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { t as BaerlyError } from "./errors-Dfa3p78c.js";
|
|
2
|
+
import { n as S3HttpStorage, t as AwsClient } from "./aws4fetch.esm-p7eEzLCs.js";
|
|
3
|
+
//#region packages/adapter-node/src/s3-signer.ts
|
|
4
|
+
/**
|
|
5
|
+
* Static-credential SigV4 signer for {@link S3HttpStorage}, safe inside
|
|
6
|
+
* a Cloudflare Worker: `aws4fetch` signs with WebCrypto, so there is no
|
|
7
|
+
* `node:crypto` in the closure. Returns the `(req) => Promise<Request>`
|
|
8
|
+
* seam `S3HttpStorageOptions.sign` expects.
|
|
9
|
+
*
|
|
10
|
+
* For rotating credentials, pass your own `(req) => Promise<Request>`
|
|
11
|
+
* to `S3HttpStorage` instead — this helper covers the static case.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { S3HttpStorage, sigV4Signer } from "@gusto/baerly-storage/s3";
|
|
16
|
+
*
|
|
17
|
+
* const storage = new S3HttpStorage({
|
|
18
|
+
* endpoint: env.S3_ENDPOINT,
|
|
19
|
+
* bucket: env.S3_BUCKET,
|
|
20
|
+
* sign: sigV4Signer({
|
|
21
|
+
* accessKeyId: env.AWS_ACCESS_KEY_ID,
|
|
22
|
+
* secretAccessKey: env.AWS_SECRET_ACCESS_KEY,
|
|
23
|
+
* region: env.AWS_REGION,
|
|
24
|
+
* }),
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
function sigV4Signer(opts) {
|
|
29
|
+
const accessKeyId = (opts.accessKeyId ?? "").trim();
|
|
30
|
+
const secretAccessKey = (opts.secretAccessKey ?? "").trim();
|
|
31
|
+
const region = (opts.region ?? "").trim();
|
|
32
|
+
if (!accessKeyId || !secretAccessKey || !region) throw new BaerlyError("InvalidConfig", "sigV4Signer: `accessKeyId`, `secretAccessKey`, and `region` must be non-empty. Check the credentials passed from your Worker `env` / process env.");
|
|
33
|
+
const client = new AwsClient({
|
|
34
|
+
accessKeyId,
|
|
35
|
+
secretAccessKey,
|
|
36
|
+
sessionToken: opts.sessionToken,
|
|
37
|
+
region,
|
|
38
|
+
service: "s3"
|
|
39
|
+
});
|
|
40
|
+
return (req) => client.sign(req);
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { S3HttpStorage, sigV4Signer };
|
|
44
|
+
|
|
45
|
+
//# sourceMappingURL=s3.js.map
|
package/dist/s3.js.map
ADDED
|
@@ -0,0 +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.sign(req);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,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,OAAO,KAAK,GAAG;AAC1C"}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import { t as BaerlyError } from "./errors-
|
|
1
|
+
import { t as BaerlyError } from "./errors-Dfa3p78c.js";
|
|
2
|
+
//#region packages/protocol/src/auth-resolution.ts
|
|
3
|
+
/** Corrective action for a `sharedSecret(...)` preset misconfig; crosses the wire. */
|
|
4
|
+
const SHARED_SECRET_CONFIG_RESOLUTION = "Pass a non-empty `secret` and a non-empty `tenantPrefix` with no \"/\" to sharedSecret({ secret, tenantPrefix }).";
|
|
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 \"/\".";
|
|
7
|
+
/** Corrective action for a `cloudflareAccess(...)` preset misconfig; crosses the wire. */
|
|
8
|
+
const CLOUDFLARE_ACCESS_CONFIG_RESOLUTION = "Pass a non-empty `teamDomain` and a 64-char lowercase-hex `audienceTag` (the Application Audience (AUD) tag from the CF Access app config).";
|
|
9
|
+
//#endregion
|
|
2
10
|
//#region packages/server/src/auth/internal/timing-safe-equal.ts
|
|
3
11
|
/**
|
|
4
12
|
* Constant-time byte-array equality. Length mismatch short-circuits —
|
|
@@ -53,8 +61,8 @@ const timingSafeEqual = (a, b) => {
|
|
|
53
61
|
* ```
|
|
54
62
|
*/
|
|
55
63
|
const sharedSecret = (opts) => {
|
|
56
|
-
if (opts.secret.length === 0) throw new BaerlyError("InvalidConfig", "sharedSecret: secret must be non-empty");
|
|
57
|
-
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)})
|
|
64
|
+
if (opts.secret.length === 0) throw new BaerlyError("InvalidConfig", "sharedSecret: secret must be non-empty", void 0, void 0, void 0, SHARED_SECRET_CONFIG_RESOLUTION);
|
|
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)})`, void 0, void 0, void 0, SHARED_SECRET_CONFIG_RESOLUTION);
|
|
58
66
|
const expected = new TextEncoder().encode(`Bearer ${opts.secret}`);
|
|
59
67
|
return async (req) => {
|
|
60
68
|
const header = req.headers.get("Authorization") ?? "";
|
|
@@ -66,6 +74,6 @@ const sharedSecret = (opts) => {
|
|
|
66
74
|
};
|
|
67
75
|
};
|
|
68
76
|
//#endregion
|
|
69
|
-
export { sharedSecret as t };
|
|
77
|
+
export { BEARER_JWT_CONFIG_RESOLUTION as n, CLOUDFLARE_ACCESS_CONFIG_RESOLUTION as r, sharedSecret as t };
|
|
70
78
|
|
|
71
|
-
//# sourceMappingURL=shared-secret-
|
|
79
|
+
//# sourceMappingURL=shared-secret-DgEicd3x.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-secret-DgEicd3x.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 \"/\".';\n\n/** Corrective action for a `cloudflareAccess(...)` preset misconfig; crosses the wire. */\nexport const CLOUDFLARE_ACCESS_CONFIG_RESOLUTION: string =\n \"Pass a non-empty `teamDomain` and a 64-char lowercase-hex `audienceTag` (the Application Audience (AUD) tag from the CF Access app config).\";\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\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(\n \"InvalidConfig\",\n \"sharedSecret: secret must be non-empty\",\n undefined,\n undefined,\n undefined,\n 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 undefined,\n undefined,\n undefined,\n SHARED_SECRET_CONFIG_RESOLUTION,\n );\n }\n const expected = new TextEncoder().encode(`Bearer ${opts.secret}`);\n return async (req: Request) => {\n const header = req.headers.get(\"Authorization\") ?? \"\";\n const actual = new TextEncoder().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;;;;;;;;;;;;;ACAF,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACkCA,MAAa,gBAAgB,SAAwC;CACnE,IAAI,KAAK,OAAO,WAAW,GACzB,MAAM,IAAI,YACR,iBACA,0CACA,KAAA,GACA,KAAA,GACA,KAAA,GACA,+BACF;CAEF,IAAI,KAAK,aAAa,WAAW,KAAK,KAAK,aAAa,SAAS,GAAG,GAClE,MAAM,IAAI,YACR,iBACA,kEAAkE,KAAK,UAAU,KAAK,YAAY,EAAE,IACpG,KAAA,GACA,KAAA,GACA,KAAA,GACA,+BACF;CAEF,MAAM,WAAW,IAAI,YAAY,CAAC,CAAC,OAAO,UAAU,KAAK,QAAQ;CACjE,OAAO,OAAO,QAAiB;EAC7B,MAAM,SAAS,IAAI,QAAQ,IAAI,eAAe,KAAK;EAEnD,IAAI,CAAC,gBAAgB,UADN,IAAI,YAAY,CAAC,CAAC,OAAO,MACJ,CAAC,GACnC,OAAO;EAET,OAAO;GAAE,cAAc,KAAK;GAAc,UAAU,EAAE,MAAM,gBAAgB;EAAE;CAChF;AACF"}
|