@gusto/baerly-storage 0.1.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 (115) hide show
  1. package/README.md +97 -0
  2. package/dist/API.md +850 -0
  3. package/dist/app-config-Cb5dO2s9.d.ts +480 -0
  4. package/dist/app-config.d.ts +2 -0
  5. package/dist/app-config.js +8 -0
  6. package/dist/app-config.js.map +1 -0
  7. package/dist/auth.d.ts +237 -0
  8. package/dist/auth.js +1335 -0
  9. package/dist/auth.js.map +1 -0
  10. package/dist/baerly.js +761 -0
  11. package/dist/baerly.js.map +1 -0
  12. package/dist/bucket-uri-BrDEYvzy.js +4922 -0
  13. package/dist/bucket-uri-BrDEYvzy.js.map +1 -0
  14. package/dist/chunk-EAsCxrDo.js +14 -0
  15. package/dist/client-BLf3Ae5s.d.ts +233 -0
  16. package/dist/client-react.d.ts +131 -0
  17. package/dist/client-react.js +559 -0
  18. package/dist/client-react.js.map +1 -0
  19. package/dist/client.d.ts +4 -0
  20. package/dist/client.js +160 -0
  21. package/dist/client.js.map +1 -0
  22. package/dist/cloudflare-CINJPKCW.js +911 -0
  23. package/dist/cloudflare-CINJPKCW.js.map +1 -0
  24. package/dist/cloudflare.d.ts +211 -0
  25. package/dist/cloudflare.js +445 -0
  26. package/dist/cloudflare.js.map +1 -0
  27. package/dist/config-Bsg8wgwo.js +198 -0
  28. package/dist/config-Bsg8wgwo.js.map +1 -0
  29. package/dist/context-Oj7ffwD-.js +187 -0
  30. package/dist/context-Oj7ffwD-.js.map +1 -0
  31. package/dist/cost-B1WiZxlf.js +203 -0
  32. package/dist/cost-B1WiZxlf.js.map +1 -0
  33. package/dist/current-json-BkatBzF7.js +252 -0
  34. package/dist/current-json-BkatBzF7.js.map +1 -0
  35. package/dist/db-D62JguBc.d.ts +336 -0
  36. package/dist/deploy-BB-wqbhf.js +83 -0
  37. package/dist/deploy-BB-wqbhf.js.map +1 -0
  38. package/dist/dev-banner-CWHIk8tH.d.ts +26 -0
  39. package/dist/dev-vite.d.ts +146 -0
  40. package/dist/dev-vite.js +223 -0
  41. package/dist/dev-vite.js.map +1 -0
  42. package/dist/dev.d.ts +3 -0
  43. package/dist/dev.js +2 -0
  44. package/dist/doctor-B8h9GCN9.js +331 -0
  45. package/dist/doctor-B8h9GCN9.js.map +1 -0
  46. package/dist/dump-BHo_sIMZ.js +116 -0
  47. package/dist/dump-BHo_sIMZ.js.map +1 -0
  48. package/dist/errors-DOdL95kK.js +58 -0
  49. package/dist/errors-DOdL95kK.js.map +1 -0
  50. package/dist/export-Dz2PZKSR.js +423 -0
  51. package/dist/export-Dz2PZKSR.js.map +1 -0
  52. package/dist/fsck-DEz9lyCy.js +293 -0
  53. package/dist/fsck-DEz9lyCy.js.map +1 -0
  54. package/dist/http-CjUO1Bec.js +1756 -0
  55. package/dist/http-CjUO1Bec.js.map +1 -0
  56. package/dist/http.d.ts +1619 -0
  57. package/dist/http.js +2 -0
  58. package/dist/index-BGC-ENnj.d.ts +1065 -0
  59. package/dist/index-BYv0hb8M.d.ts +1457 -0
  60. package/dist/index-BquQkhJi.d.ts +112 -0
  61. package/dist/index-COsQ-Mlz.d.ts +146 -0
  62. package/dist/index.d.ts +6 -0
  63. package/dist/index.js +6 -0
  64. package/dist/indexes-BXn7a06a.js +297 -0
  65. package/dist/indexes-BXn7a06a.js.map +1 -0
  66. package/dist/indexes-DwOXkn1Y.d.ts +22 -0
  67. package/dist/inspect-x02aFWnh.js +149 -0
  68. package/dist/inspect-x02aFWnh.js.map +1 -0
  69. package/dist/log-walk-DIru96UT.js +260 -0
  70. package/dist/log-walk-DIru96UT.js.map +1 -0
  71. package/dist/maintenance-Bn6ul9aV.js +758 -0
  72. package/dist/maintenance-Bn6ul9aV.js.map +1 -0
  73. package/dist/maintenance.d.ts +323 -0
  74. package/dist/maintenance.js +2 -0
  75. package/dist/node.d.ts +422 -0
  76. package/dist/node.js +2 -0
  77. package/dist/normalize-XWY25_sG.js +133 -0
  78. package/dist/normalize-XWY25_sG.js.map +1 -0
  79. package/dist/observability-2IDYRuZK.js +2333 -0
  80. package/dist/observability-2IDYRuZK.js.map +1 -0
  81. package/dist/observability.d.ts +3 -0
  82. package/dist/observability.js +3 -0
  83. package/dist/plan-Cs17VqjU.js +224 -0
  84. package/dist/plan-Cs17VqjU.js.map +1 -0
  85. package/dist/query-DcSbFLJt.js +1880 -0
  86. package/dist/query-DcSbFLJt.js.map +1 -0
  87. package/dist/rebuild-index-C5gTXryd.js +119 -0
  88. package/dist/rebuild-index-C5gTXryd.js.map +1 -0
  89. package/dist/rebuild-index-DwXM0WfA.js +104 -0
  90. package/dist/rebuild-index-DwXM0WfA.js.map +1 -0
  91. package/dist/request-BEF_OvMh.js +72 -0
  92. package/dist/request-BEF_OvMh.js.map +1 -0
  93. package/dist/restore-CbKVMMpm.js +847 -0
  94. package/dist/restore-CbKVMMpm.js.map +1 -0
  95. package/dist/shared-secret-BJdSwpgw.js +71 -0
  96. package/dist/shared-secret-BJdSwpgw.js.map +1 -0
  97. package/dist/snapshot-D7C4_FSl.js +71 -0
  98. package/dist/snapshot-D7C4_FSl.js.map +1 -0
  99. package/dist/snapshot-z_N9hpTe.js +917 -0
  100. package/dist/snapshot-z_N9hpTe.js.map +1 -0
  101. package/dist/src-Chafbw8r.js +522 -0
  102. package/dist/src-Chafbw8r.js.map +1 -0
  103. package/dist/src-DyET_VPP.js +6199 -0
  104. package/dist/src-DyET_VPP.js.map +1 -0
  105. package/dist/src-n0Te1r98.js +352 -0
  106. package/dist/src-n0Te1r98.js.map +1 -0
  107. package/dist/subcommand-BWs6K7zb.js +110 -0
  108. package/dist/subcommand-BWs6K7zb.js.map +1 -0
  109. package/dist/usage-RVUQMLop.js +339 -0
  110. package/dist/usage-RVUQMLop.js.map +1 -0
  111. package/dist/validate-DhH1lO8I.js +377 -0
  112. package/dist/validate-DhH1lO8I.js.map +1 -0
  113. package/dist/wire-izfGZDvr.js +7 -0
  114. package/dist/wire-izfGZDvr.js.map +1 -0
  115. package/package.json +189 -0
package/dist/auth.d.ts ADDED
@@ -0,0 +1,237 @@
1
+ import { r as Verifier } from "./index-BGC-ENnj.js";
2
+
3
+ //#region packages/server/src/auth/presets/shared-secret.d.ts
4
+ /**
5
+ * Options for {@link sharedSecret}.
6
+ *
7
+ * - `secret` — the bearer token clients must present. Compared with
8
+ * constant-time `timingSafeEqual` — see {@link sharedSecret} for
9
+ * why naive `===` is not enough.
10
+ * - `tenantPrefix` — the value returned in `VerifierResult.tenantPrefix`.
11
+ * Single-tenant deployments pass a constant (`"acme"`). Multi-tenant
12
+ * deployments don't use `sharedSecret`; they reach for `bearerJwt`
13
+ * or `cloudflareAccess` instead.
14
+ */
15
+ interface SharedSecretOptions {
16
+ readonly secret: string;
17
+ readonly tenantPrefix: string;
18
+ }
19
+ /**
20
+ * Build a `Verifier` that accepts `Authorization: Bearer <secret>`
21
+ * and pins every request to a single tenant. The simplest preset —
22
+ * use for single-tenant deployments before you've stood up an IdP.
23
+ *
24
+ * **Why constant-time compare:** a naive `===` against the bearer
25
+ * token leaks timing information about which character first
26
+ * differed. Real-world relevance over HTTPS is debated, but
27
+ * `timingSafeEqual` is one line of code and erases the question.
28
+ *
29
+ * **Identity shape.** On success the returned `VerifierResult` has:
30
+ * ```ts
31
+ * { tenantPrefix: "<configured>", identity: { kind: "shared-secret" } }
32
+ * ```
33
+ * `sharedSecret` has no notion of a per-user subject — every caller
34
+ * presenting the bearer is the same principal. Downstream code that
35
+ * wants a stable per-request `sender_sub` should fall back to a
36
+ * synthetic value (`"shared-secret:" + tenantPrefix`) when
37
+ * `identity.kind === "shared-secret"`. The `kind` field is the
38
+ * discriminant across all preset identities; switch on it instead of
39
+ * sniffing properties.
40
+ *
41
+ * @throws BaerlyError code="InvalidConfig" — `secret` empty or
42
+ * `tenantPrefix` empty / contains "/".
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * import { sharedSecret } from "@gusto/baerly-storage/auth";
47
+ * const verifier = sharedSecret({
48
+ * secret: env.SHARED_SECRET,
49
+ * tenantPrefix: "acme",
50
+ * });
51
+ * ```
52
+ */
53
+ declare const sharedSecret: (opts: SharedSecretOptions) => Verifier;
54
+ //#endregion
55
+ //#region packages/server/src/auth/presets/bearer-jwt.d.ts
56
+ /**
57
+ * Options for {@link bearerJwt}.
58
+ *
59
+ * - `jwks` — JWKS URL (`https://<idp>/.well-known/jwks.json`) OR a
60
+ * pre-loaded JWKS object. URLs are fetched lazily and cached for
61
+ * {@link BearerJwtOptions.jwksCacheTtlMs} (default 10 minutes).
62
+ * - `issuer` — required `iss` claim. JWTs with a different `iss` are
63
+ * rejected. Set to the issuer URL of your IdP (e.g.
64
+ * `https://login.example.com/`).
65
+ * - `audience` — required `aud` claim. JWTs with a different `aud`
66
+ * are rejected. Set to the API's identifier (e.g.
67
+ * `https://api.example.com/`).
68
+ * - `tenantClaim` — name of the claim that carries the tenant
69
+ * identifier. Defaults to `"tenant"`. Custom IdPs may use a
70
+ * namespaced claim (`"https://example.com/tenant"`); set to that
71
+ * string. Mutually exclusive with `tenantPrefix`.
72
+ * - `tenantPrefix` — pin every verified token to a fixed tenant
73
+ * string, bypassing claim lookup. Use for single-tenant
74
+ * deployments where the IdP doesn't ship a tenant claim (the
75
+ * common case for vanilla CF Access). The signature, `iss`,
76
+ * `aud`, `exp`, and algorithm allowlist are still enforced —
77
+ * only the tenant-derivation step is replaced. Mutually exclusive
78
+ * with `tenantClaim`; must be non-empty and contain no `/`.
79
+ * - `algorithms` — allowlist of `alg` header values. Defaults to
80
+ * `["RS256", "ES256", "EdDSA"]`. `none`, `HS256`, anything else
81
+ * is rejected without consulting the JWKS.
82
+ * - `clockSkewMs` — tolerance for `exp` / `nbf` checks. Defaults to
83
+ * 60 000 (60 s).
84
+ * - `jwksCacheTtlMs` — JWKS HTTP cache TTL. Defaults to 600 000
85
+ * (10 min). The cache is per-factory-call; a fresh `bearerJwt()`
86
+ * call starts cold.
87
+ * - `fetch` — `fetch` override. Defaults to `globalThis.fetch`.
88
+ * Tests inject a stub.
89
+ */
90
+ interface BearerJwtOptions {
91
+ readonly jwks: string | JwksDocument;
92
+ readonly issuer: string;
93
+ readonly audience: string;
94
+ readonly tenantClaim?: string;
95
+ readonly tenantPrefix?: string;
96
+ readonly algorithms?: readonly JwtAlgorithm[];
97
+ readonly clockSkewMs?: number;
98
+ readonly jwksCacheTtlMs?: number;
99
+ readonly fetch?: typeof fetch;
100
+ }
101
+ /** Supported JWT signing algorithms. HS256 is intentionally absent — a
102
+ * shared-secret JWT is just `sharedSecret` with a JSON envelope. */
103
+ type JwtAlgorithm = "RS256" | "ES256" | "EdDSA";
104
+ /**
105
+ * JWKS document — `{ keys: [...] }`. Each key is a JWK with `kty`,
106
+ * `kid`, and algorithm-specific fields. Re-typed locally to keep
107
+ * the factory's public surface library-agnostic.
108
+ */
109
+ interface JwksDocument {
110
+ readonly keys: readonly Jwk[];
111
+ }
112
+ /**
113
+ * Minimal JWK shape consumed by {@link bearerJwt}. Algorithm-specific
114
+ * fields (`n`/`e` for RSA, `x`/`y`/`crv` for EC, `x`/`crv` for OKP)
115
+ * are forwarded to `jose` directly so we don't have to enumerate them.
116
+ */
117
+ interface Jwk {
118
+ readonly kty: string;
119
+ readonly kid?: string;
120
+ readonly alg?: string;
121
+ readonly use?: string;
122
+ readonly [extra: string]: unknown;
123
+ }
124
+ /**
125
+ * Build a `Verifier` that accepts `Authorization: Bearer <jwt>`
126
+ * and verifies the signature against a JWKS. Multi-tenant IdPs
127
+ * (Auth0, Okta, Azure AD, Keycloak) ship a `/.well-known/jwks.json`
128
+ * endpoint suitable for the `jwks` option.
129
+ *
130
+ * **Identity shape.** On success the returned `VerifierResult` has:
131
+ * ```ts
132
+ * { tenantPrefix: <payload[tenantClaim]>, identity: <verified JWTPayload> }
133
+ * ```
134
+ * `identity` is the raw, validated JWT payload — `identity.sub` is
135
+ * the canonical per-user subject; other claims (`email`, `name`,
136
+ * `groups`, …) pass through verbatim. The kernel types it as
137
+ * `unknown` to keep `Verifier` plain; cast at the call site with the
138
+ * payload shape your IdP emits, e.g. `const id = result.identity as
139
+ * { sub: string }`. Token-level failures (bad signature, expired,
140
+ * wrong audience, missing/non-string tenant claim) return `null`.
141
+ *
142
+ * @throws BaerlyError code="InvalidConfig" — required option
143
+ * missing, `issuer`/`audience` empty, `algorithms` empty.
144
+ * @throws BaerlyError code="NetworkError" — JWKS fetch failed AND
145
+ * the cache is cold. A stale cache hit on a network failure is
146
+ * preferred over throwing (jose serves the stale JWKS until the
147
+ * `cacheMaxAge` window elapses).
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * import { bearerJwt } from "@gusto/baerly-storage/auth";
152
+ * const verifier = bearerJwt({
153
+ * jwks: "https://example.auth0.com/.well-known/jwks.json",
154
+ * issuer: "https://example.auth0.com/",
155
+ * audience: "https://api.example.com/",
156
+ * tenantClaim: "https://example.com/tenant",
157
+ * });
158
+ * ```
159
+ */
160
+ declare const bearerJwt: (opts: BearerJwtOptions) => Verifier;
161
+ //#endregion
162
+ //#region packages/server/src/auth/presets/cloudflare-access.d.ts
163
+ /**
164
+ * Options for {@link cloudflareAccess}.
165
+ *
166
+ * - `teamDomain` — your CF Access team domain, e.g. `acme`. The
167
+ * factory derives the JWKS URL from this:
168
+ * `https://<teamDomain>.cloudflareaccess.com/cdn-cgi/access/certs`
169
+ * and the issuer as
170
+ * `https://<teamDomain>.cloudflareaccess.com`.
171
+ * - `audienceTag` — the "Application Audience (AUD) Tag" from
172
+ * the CF Access app config. 64-character hex string.
173
+ * - `tenantClaim` — same as `BearerJwtOptions.tenantClaim`.
174
+ * Defaults to `"tenant"`. Set to a custom claim if you've wired
175
+ * CF Access to a SAML / OIDC provider that ships a tenant in a
176
+ * namespaced claim. Mutually exclusive with `tenantPrefix`.
177
+ * - `tenantPrefix` — pin every verified token to a fixed tenant
178
+ * string. Use for single-tenant CF Access deployments: vanilla
179
+ * CF Access JWTs ship `sub`/`email` but no `tenant` claim, so
180
+ * the default claim-based derivation 401s every request. Signature
181
+ * + audience + expiry checks are still enforced; only the
182
+ * tenant-derivation step is replaced. Must be non-empty and
183
+ * contain no `/`. Mutually exclusive with `tenantClaim`.
184
+ * - `fetch` / `clockSkewMs` / `jwksCacheTtlMs` — forwarded to the
185
+ * inner `bearerJwt`.
186
+ */
187
+ interface CloudflareAccessOptions {
188
+ readonly teamDomain: string;
189
+ readonly audienceTag: string;
190
+ readonly tenantClaim?: string;
191
+ readonly tenantPrefix?: string;
192
+ readonly fetch?: typeof fetch;
193
+ readonly clockSkewMs?: number;
194
+ readonly jwksCacheTtlMs?: number;
195
+ }
196
+ /**
197
+ * Build a `Verifier` that consumes the `Cf-Access-Jwt-Assertion`
198
+ * header CF Access injects in front of a protected Worker. The
199
+ * Cloudflare-side scaffold (`examples/minimal-cloudflare/`) defaults
200
+ * to this factory.
201
+ *
202
+ * Internally a thin shim over `bearerJwt` — pulls the JWT from the
203
+ * CF-specific header, points at CF Access's JWKS, and pins
204
+ * issuer/audience to the CF-Access shape.
205
+ *
206
+ * **Identity shape.** Same as {@link bearerJwt}: the returned
207
+ * `identity` is the verified JWT payload CF Access mints (after IdP
208
+ * sign-in). Useful claims are `identity.sub` (user id), `identity.email`,
209
+ * `identity.identity_nonce` — see Cloudflare's "Application Token"
210
+ * reference. The kernel types it as `unknown`; cast at the call site.
211
+ *
212
+ * @throws BaerlyError code="InvalidConfig" — `teamDomain` or
213
+ * `audienceTag` empty, or `audienceTag` not 64 lowercase-hex chars.
214
+ *
215
+ * @example
216
+ * ```ts
217
+ * import { cloudflareAccess } from "@gusto/baerly-storage/auth";
218
+ * const verifier = cloudflareAccess({
219
+ * teamDomain: "acme",
220
+ * audienceTag: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
221
+ * });
222
+ * ```
223
+ *
224
+ * @example Single-tenant CF Access (no `tenant` claim in the JWT)
225
+ * ```ts
226
+ * import { cloudflareAccess } from "@gusto/baerly-storage/auth";
227
+ * const verifier = cloudflareAccess({
228
+ * teamDomain: "acme",
229
+ * audienceTag: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
230
+ * tenantPrefix: "main",
231
+ * });
232
+ * ```
233
+ */
234
+ declare const cloudflareAccess: (opts: CloudflareAccessOptions) => Verifier;
235
+ //#endregion
236
+ export { type BearerJwtOptions, type CloudflareAccessOptions, type Jwk, type JwksDocument, type JwtAlgorithm, type SharedSecretOptions, bearerJwt, cloudflareAccess, sharedSecret };
237
+ //# sourceMappingURL=auth.d.ts.map