@lunora/cloudflare-access 1.0.0-alpha.12 → 1.0.0-alpha.120

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.md CHANGED
@@ -227,5 +227,219 @@ Repository: git+https://github.com/anolilab/lunora.git
227
227
  >
228
228
  > <!-- DEPENDENCIES -->
229
229
  > <!-- /DEPENDENCIES -->
230
+ >
231
+ >
232
+ >
233
+ > # Licenses of bundled types
234
+ > The published @lunora/server artifact additionally contains code with the following licenses:
235
+ > Apache-2.0
236
+ >
237
+ > # Bundled types:
238
+ > ## @opentelemetry/api
239
+ > License: Apache-2.0
240
+ > By: OpenTelemetry Authors
241
+ > Repository: open-telemetry/opentelemetry-js
242
+ >
243
+ > > Apache License
244
+ > > Version 2.0, January 2004
245
+ > > http://www.apache.org/licenses/
246
+ > >
247
+ > > TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
248
+ > >
249
+ > > 1. Definitions.
250
+ > >
251
+ > > "License" shall mean the terms and conditions for use, reproduction,
252
+ > > and distribution as defined by Sections 1 through 9 of this document.
253
+ > >
254
+ > > "Licensor" shall mean the copyright owner or entity authorized by
255
+ > > the copyright owner that is granting the License.
256
+ > >
257
+ > > "Legal Entity" shall mean the union of the acting entity and all
258
+ > > other entities that control, are controlled by, or are under common
259
+ > > control with that entity. For the purposes of this definition,
260
+ > > "control" means (i) the power, direct or indirect, to cause the
261
+ > > direction or management of such entity, whether by contract or
262
+ > > otherwise, or (ii) ownership of fifty percent (50%) or more of the
263
+ > > outstanding shares, or (iii) beneficial ownership of such entity.
264
+ > >
265
+ > > "You" (or "Your") shall mean an individual or Legal Entity
266
+ > > exercising permissions granted by this License.
267
+ > >
268
+ > > "Source" form shall mean the preferred form for making modifications,
269
+ > > including but not limited to software source code, documentation
270
+ > > source, and configuration files.
271
+ > >
272
+ > > "Object" form shall mean any form resulting from mechanical
273
+ > > transformation or translation of a Source form, including but
274
+ > > not limited to compiled object code, generated documentation,
275
+ > > and conversions to other media types.
276
+ > >
277
+ > > "Work" shall mean the work of authorship, whether in Source or
278
+ > > Object form, made available under the License, as indicated by a
279
+ > > copyright notice that is included in or attached to the work
280
+ > > (an example is provided in the Appendix below).
281
+ > >
282
+ > > "Derivative Works" shall mean any work, whether in Source or Object
283
+ > > form, that is based on (or derived from) the Work and for which the
284
+ > > editorial revisions, annotations, elaborations, or other modifications
285
+ > > represent, as a whole, an original work of authorship. For the purposes
286
+ > > of this License, Derivative Works shall not include works that remain
287
+ > > separable from, or merely link (or bind by name) to the interfaces of,
288
+ > > the Work and Derivative Works thereof.
289
+ > >
290
+ > > "Contribution" shall mean any work of authorship, including
291
+ > > the original version of the Work and any modifications or additions
292
+ > > to that Work or Derivative Works thereof, that is intentionally
293
+ > > submitted to Licensor for inclusion in the Work by the copyright owner
294
+ > > or by an individual or Legal Entity authorized to submit on behalf of
295
+ > > the copyright owner. For the purposes of this definition, "submitted"
296
+ > > means any form of electronic, verbal, or written communication sent
297
+ > > to the Licensor or its representatives, including but not limited to
298
+ > > communication on electronic mailing lists, source code control systems,
299
+ > > and issue tracking systems that are managed by, or on behalf of, the
300
+ > > Licensor for the purpose of discussing and improving the Work, but
301
+ > > excluding communication that is conspicuously marked or otherwise
302
+ > > designated in writing by the copyright owner as "Not a Contribution."
303
+ > >
304
+ > > "Contributor" shall mean Licensor and any individual or Legal Entity
305
+ > > on behalf of whom a Contribution has been received by Licensor and
306
+ > > subsequently incorporated within the Work.
307
+ > >
308
+ > > 2. Grant of Copyright License. Subject to the terms and conditions of
309
+ > > this License, each Contributor hereby grants to You a perpetual,
310
+ > > worldwide, non-exclusive, no-charge, royalty-free, irrevocable
311
+ > > copyright license to reproduce, prepare Derivative Works of,
312
+ > > publicly display, publicly perform, sublicense, and distribute the
313
+ > > Work and such Derivative Works in Source or Object form.
314
+ > >
315
+ > > 3. Grant of Patent License. Subject to the terms and conditions of
316
+ > > this License, each Contributor hereby grants to You a perpetual,
317
+ > > worldwide, non-exclusive, no-charge, royalty-free, irrevocable
318
+ > > (except as stated in this section) patent license to make, have made,
319
+ > > use, offer to sell, sell, import, and otherwise transfer the Work,
320
+ > > where such license applies only to those patent claims licensable
321
+ > > by such Contributor that are necessarily infringed by their
322
+ > > Contribution(s) alone or by combination of their Contribution(s)
323
+ > > with the Work to which such Contribution(s) was submitted. If You
324
+ > > institute patent litigation against any entity (including a
325
+ > > cross-claim or counterclaim in a lawsuit) alleging that the Work
326
+ > > or a Contribution incorporated within the Work constitutes direct
327
+ > > or contributory patent infringement, then any patent licenses
328
+ > > granted to You under this License for that Work shall terminate
329
+ > > as of the date such litigation is filed.
330
+ > >
331
+ > > 4. Redistribution. You may reproduce and distribute copies of the
332
+ > > Work or Derivative Works thereof in any medium, with or without
333
+ > > modifications, and in Source or Object form, provided that You
334
+ > > meet the following conditions:
335
+ > >
336
+ > > (a) You must give any other recipients of the Work or
337
+ > > Derivative Works a copy of this License; and
338
+ > >
339
+ > > (b) You must cause any modified files to carry prominent notices
340
+ > > stating that You changed the files; and
341
+ > >
342
+ > > (c) You must retain, in the Source form of any Derivative Works
343
+ > > that You distribute, all copyright, patent, trademark, and
344
+ > > attribution notices from the Source form of the Work,
345
+ > > excluding those notices that do not pertain to any part of
346
+ > > the Derivative Works; and
347
+ > >
348
+ > > (d) If the Work includes a "NOTICE" text file as part of its
349
+ > > distribution, then any Derivative Works that You distribute must
350
+ > > include a readable copy of the attribution notices contained
351
+ > > within such NOTICE file, excluding those notices that do not
352
+ > > pertain to any part of the Derivative Works, in at least one
353
+ > > of the following places: within a NOTICE text file distributed
354
+ > > as part of the Derivative Works; within the Source form or
355
+ > > documentation, if provided along with the Derivative Works; or,
356
+ > > within a display generated by the Derivative Works, if and
357
+ > > wherever such third-party notices normally appear. The contents
358
+ > > of the NOTICE file are for informational purposes only and
359
+ > > do not modify the License. You may add Your own attribution
360
+ > > notices within Derivative Works that You distribute, alongside
361
+ > > or as an addendum to the NOTICE text from the Work, provided
362
+ > > that such additional attribution notices cannot be construed
363
+ > > as modifying the License.
364
+ > >
365
+ > > You may add Your own copyright statement to Your modifications and
366
+ > > may provide additional or different license terms and conditions
367
+ > > for use, reproduction, or distribution of Your modifications, or
368
+ > > for any such Derivative Works as a whole, provided Your use,
369
+ > > reproduction, and distribution of the Work otherwise complies with
370
+ > > the conditions stated in this License.
371
+ > >
372
+ > > 5. Submission of Contributions. Unless You explicitly state otherwise,
373
+ > > any Contribution intentionally submitted for inclusion in the Work
374
+ > > by You to the Licensor shall be under the terms and conditions of
375
+ > > this License, without any additional terms or conditions.
376
+ > > Notwithstanding the above, nothing herein shall supersede or modify
377
+ > > the terms of any separate license agreement you may have executed
378
+ > > with Licensor regarding such Contributions.
379
+ > >
380
+ > > 6. Trademarks. This License does not grant permission to use the trade
381
+ > > names, trademarks, service marks, or product names of the Licensor,
382
+ > > except as required for reasonable and customary use in describing the
383
+ > > origin of the Work and reproducing the content of the NOTICE file.
384
+ > >
385
+ > > 7. Disclaimer of Warranty. Unless required by applicable law or
386
+ > > agreed to in writing, Licensor provides the Work (and each
387
+ > > Contributor provides its Contributions) on an "AS IS" BASIS,
388
+ > > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
389
+ > > implied, including, without limitation, any warranties or conditions
390
+ > > of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
391
+ > > PARTICULAR PURPOSE. You are solely responsible for determining the
392
+ > > appropriateness of using or redistributing the Work and assume any
393
+ > > risks associated with Your exercise of permissions under this License.
394
+ > >
395
+ > > 8. Limitation of Liability. In no event and under no legal theory,
396
+ > > whether in tort (including negligence), contract, or otherwise,
397
+ > > unless required by applicable law (such as deliberate and grossly
398
+ > > negligent acts) or agreed to in writing, shall any Contributor be
399
+ > > liable to You for damages, including any direct, indirect, special,
400
+ > > incidental, or consequential damages of any character arising as a
401
+ > > result of this License or out of the use or inability to use the
402
+ > > Work (including but not limited to damages for loss of goodwill,
403
+ > > work stoppage, computer failure or malfunction, or any and all
404
+ > > other commercial damages or losses), even if such Contributor
405
+ > > has been advised of the possibility of such damages.
406
+ > >
407
+ > > 9. Accepting Warranty or Additional Liability. While redistributing
408
+ > > the Work or Derivative Works thereof, You may choose to offer,
409
+ > > and charge a fee for, acceptance of support, warranty, indemnity,
410
+ > > or other liability obligations and/or rights consistent with this
411
+ > > License. However, in accepting such obligations, You may act only
412
+ > > on Your own behalf and on Your sole responsibility, not on behalf
413
+ > > of any other Contributor, and only if You agree to indemnify,
414
+ > > defend, and hold each Contributor harmless for any liability
415
+ > > incurred by, or claims asserted against, such Contributor by reason
416
+ > > of your accepting any such warranty or additional liability.
417
+ > >
418
+ > > END OF TERMS AND CONDITIONS
419
+ > >
420
+ > > APPENDIX: How to apply the Apache License to your work.
421
+ > >
422
+ > > To apply the Apache License to your work, attach the following
423
+ > > boilerplate notice, with the fields enclosed by brackets "[]"
424
+ > > replaced with your own identifying information. (Don't include
425
+ > > the brackets!) The text should be enclosed in the appropriate
426
+ > > comment syntax for the file format. We also recommend that a
427
+ > > file or class name and description of purpose be included on the
428
+ > > same "printed page" as the copyright notice for easier
429
+ > > identification within third-party archives.
430
+ > >
431
+ > > Copyright [yyyy] [name of copyright owner]
432
+ > >
433
+ > > Licensed under the Apache License, Version 2.0 (the "License");
434
+ > > you may not use this file except in compliance with the License.
435
+ > > You may obtain a copy of the License at
436
+ > >
437
+ > > http://www.apache.org/licenses/LICENSE-2.0
438
+ > >
439
+ > > Unless required by applicable law or agreed to in writing, software
440
+ > > distributed under the License is distributed on an "AS IS" BASIS,
441
+ > > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
442
+ > > See the License for the specific language governing permissions and
443
+ > > limitations under the License.
230
444
 
231
445
  <!-- /TYPE_DEPENDENCIES -->
package/dist/admin.d.mts CHANGED
@@ -1,36 +1,70 @@
1
- import { A as AccessClaims, R as RequestVerifyOptions } from "./packem_shared/types.d-BO8d74KI.mjs";
1
+ import { A as AccessClaims, a as AccessJwtFallbackOptions, E as ExecutionContextLike } from "./packem_shared/types.d-Dp399TMk.mjs";
2
2
  import 'jose';
3
- /** Options for {@link accessAdminGate}; extends {@link RequestVerifyOptions}. */
4
- interface AccessAdminGateOptions extends RequestVerifyOptions {
3
+ /** Options for {@link accessAdminGate}; extends {@link AccessJwtFallbackOptions}. */
4
+ interface AccessAdminGateOptions extends AccessJwtFallbackOptions {
5
5
  /**
6
- * Decide whether the **verified** claims authorize the Studio/admin plane —
7
- * e.g. `(claims) => claims.groups?.includes("ops") ?? false` or an email-domain
8
- * check. Required: there is no implicit grant, so a verified-but-unprivileged
9
- * identity is denied. Runs only after signature/issuer/audience/expiry pass.
10
- */
6
+ * Decide whether the **verified** claims authorize the Studio/admin plane —
7
+ * e.g. `(claims) => claims.groups?.includes("ops") ?? false` or an email-domain
8
+ * check. Required: there is no implicit grant, so a verified-but-unprivileged
9
+ * identity is denied. Runs only after the caller is authenticated.
10
+ */
11
11
  isAdmin: (claims: AccessClaims) => boolean | Promise<boolean>;
12
12
  }
13
13
  /**
14
- * Build an admin gate for `@lunora/runtime`'s `WorkerOptions.adminGate`: a
15
- * request-only predicate that verifies the request's `Cf-Access-Jwt-Assertion`
16
- * JWT and applies your `isAdmin(claims)` test. When it resolves `true` the
17
- * request authorizes the `/_lunora/admin/*` plane (the Studio's HTTP + WS
18
- * endpoints) in addition to — or instead of — the static admin bearer, so the
19
- * Studio can sit behind Cloudflare Access.
20
- *
21
- * It is **fail-closed**: a missing token, a token that fails verification, or an
22
- * `isAdmin` that returns `false` all resolve to `false` (the bearer remains the
23
- * only other path). Verification needs no `env` binding (static team-domain/aud
24
- * config + the remote JWKS over `fetch`), so the gate takes only the request and
25
- * the runtime can evaluate it without threading async through every admin route.
26
- *
27
- * ```ts
28
- * options.adminGate = accessAdminGate({
29
- * teamDomain: env.CF_ACCESS_TEAM_DOMAIN,
30
- * aud: env.CF_ACCESS_ADMIN_AUD,
31
- * isAdmin: (claims) => claims.groups?.includes("lunora-admins") ?? false,
32
- * });
33
- * ```
34
- */
35
- declare const accessAdminGate: (options: AccessAdminGateOptions) => ((request: Request) => Promise<boolean>);
14
+ * Build an admin gate for `@lunora/runtime`'s `WorkerOptions.adminGate`: a
15
+ * predicate that authenticates the caller through Cloudflare Access and applies
16
+ * your `isAdmin(claims)` test. When it resolves `true` the request authorizes the
17
+ * admin **HTTP** plane (`/_lunora/admin/*` plus `/_lunora/migrate`) in addition
18
+ * to — or instead of — the static admin bearer, so the Studio's pages can sit
19
+ * behind Cloudflare Access.
20
+ *
21
+ * It does NOT cover `/_lunora/ws`, which is not an admin path: the runtime never
22
+ * evaluates the gate there. The Studio's live views authenticate their socket
23
+ * with a sub-token minted at `/_lunora/admin/ws-token`, signed with the static
24
+ * admin token so with no `LUNORA_ADMIN_TOKEN` configured, minting refuses
25
+ * (`ADMIN_TOKEN_NOT_CONFIGURED`) and every live panel fails while the HTTP pages
26
+ * work. Configure both.
27
+ *
28
+ * It accepts exactly one proof, and **which one is your choice, not the
29
+ * platform's**:
30
+ *
31
+ * - Configure `teamDomain` + `aud` and the request's `Cf-Access-Jwt-Assertion`
32
+ * JWT is the only thing accepted. This is the stricter setup, and the point of
33
+ * the `aud`: it proves the caller came through the *specific* Access application
34
+ * you put in front of `/_lunora/admin`, not merely through some application in
35
+ * the same Cloudflare team.
36
+ * - Configure neither and the Worker's own Access identity (`context.access`) is
37
+ * accepted, for a deployment whose Access policy is attached to the Worker.
38
+ *
39
+ * Note this is the **opposite** precedence to `createAccessResolver`, which
40
+ * prefers the platform identity. That is deliberate. A policy attached to the
41
+ * Worker is typically broad — "anyone at the company", covering every route and
42
+ * preview URL — while a configured admin `aud` is deliberately narrow. Letting
43
+ * the broad one satisfy a gate you scoped with the narrow one would widen the
44
+ * admin plane to everyone the Worker policy admits, silently, the moment that
45
+ * policy was attached.
46
+ *
47
+ * It is **fail-closed**: no identity, a token that fails verification, or an
48
+ * `isAdmin` that returns `false` all resolve to `false` (the bearer remains the
49
+ * only other path). Verification needs no `env` binding (static team-domain/aud
50
+ * config + the remote JWKS over `fetch`), so the gate takes only the request and
51
+ * its context and the runtime can evaluate it without threading async through
52
+ * every admin route.
53
+ *
54
+ * ```ts
55
+ * // A dedicated Access application over /_lunora/admin — the JWT is the only proof.
56
+ * options.adminGate = accessAdminGate({
57
+ * teamDomain: env.CF_ACCESS_TEAM_DOMAIN,
58
+ * aud: env.CF_ACCESS_ADMIN_AUD,
59
+ * isAdmin: (claims) => claims.groups?.includes("lunora-admins") ?? false,
60
+ * });
61
+ *
62
+ * // Access policy attached to the Worker — `isAdmin` is the whole boundary, so
63
+ * // make it at least as strict as a dedicated admin application would have been.
64
+ * options.adminGate = accessAdminGate({
65
+ * isAdmin: (claims) => claims.groups?.includes("lunora-admins") ?? false,
66
+ * });
67
+ * ```
68
+ */
69
+ declare const accessAdminGate: (options: AccessAdminGateOptions) => ((request: Request, context?: ExecutionContextLike) => Promise<boolean>);
36
70
  export { type AccessAdminGateOptions, accessAdminGate };
package/dist/admin.d.ts CHANGED
@@ -1,36 +1,70 @@
1
- import { A as AccessClaims, R as RequestVerifyOptions } from "./packem_shared/types.d-BO8d74KI.js";
1
+ import { A as AccessClaims, a as AccessJwtFallbackOptions, E as ExecutionContextLike } from "./packem_shared/types.d-Dp399TMk.js";
2
2
  import 'jose';
3
- /** Options for {@link accessAdminGate}; extends {@link RequestVerifyOptions}. */
4
- interface AccessAdminGateOptions extends RequestVerifyOptions {
3
+ /** Options for {@link accessAdminGate}; extends {@link AccessJwtFallbackOptions}. */
4
+ interface AccessAdminGateOptions extends AccessJwtFallbackOptions {
5
5
  /**
6
- * Decide whether the **verified** claims authorize the Studio/admin plane —
7
- * e.g. `(claims) => claims.groups?.includes("ops") ?? false` or an email-domain
8
- * check. Required: there is no implicit grant, so a verified-but-unprivileged
9
- * identity is denied. Runs only after signature/issuer/audience/expiry pass.
10
- */
6
+ * Decide whether the **verified** claims authorize the Studio/admin plane —
7
+ * e.g. `(claims) => claims.groups?.includes("ops") ?? false` or an email-domain
8
+ * check. Required: there is no implicit grant, so a verified-but-unprivileged
9
+ * identity is denied. Runs only after the caller is authenticated.
10
+ */
11
11
  isAdmin: (claims: AccessClaims) => boolean | Promise<boolean>;
12
12
  }
13
13
  /**
14
- * Build an admin gate for `@lunora/runtime`'s `WorkerOptions.adminGate`: a
15
- * request-only predicate that verifies the request's `Cf-Access-Jwt-Assertion`
16
- * JWT and applies your `isAdmin(claims)` test. When it resolves `true` the
17
- * request authorizes the `/_lunora/admin/*` plane (the Studio's HTTP + WS
18
- * endpoints) in addition to — or instead of — the static admin bearer, so the
19
- * Studio can sit behind Cloudflare Access.
20
- *
21
- * It is **fail-closed**: a missing token, a token that fails verification, or an
22
- * `isAdmin` that returns `false` all resolve to `false` (the bearer remains the
23
- * only other path). Verification needs no `env` binding (static team-domain/aud
24
- * config + the remote JWKS over `fetch`), so the gate takes only the request and
25
- * the runtime can evaluate it without threading async through every admin route.
26
- *
27
- * ```ts
28
- * options.adminGate = accessAdminGate({
29
- * teamDomain: env.CF_ACCESS_TEAM_DOMAIN,
30
- * aud: env.CF_ACCESS_ADMIN_AUD,
31
- * isAdmin: (claims) => claims.groups?.includes("lunora-admins") ?? false,
32
- * });
33
- * ```
34
- */
35
- declare const accessAdminGate: (options: AccessAdminGateOptions) => ((request: Request) => Promise<boolean>);
14
+ * Build an admin gate for `@lunora/runtime`'s `WorkerOptions.adminGate`: a
15
+ * predicate that authenticates the caller through Cloudflare Access and applies
16
+ * your `isAdmin(claims)` test. When it resolves `true` the request authorizes the
17
+ * admin **HTTP** plane (`/_lunora/admin/*` plus `/_lunora/migrate`) in addition
18
+ * to — or instead of — the static admin bearer, so the Studio's pages can sit
19
+ * behind Cloudflare Access.
20
+ *
21
+ * It does NOT cover `/_lunora/ws`, which is not an admin path: the runtime never
22
+ * evaluates the gate there. The Studio's live views authenticate their socket
23
+ * with a sub-token minted at `/_lunora/admin/ws-token`, signed with the static
24
+ * admin token so with no `LUNORA_ADMIN_TOKEN` configured, minting refuses
25
+ * (`ADMIN_TOKEN_NOT_CONFIGURED`) and every live panel fails while the HTTP pages
26
+ * work. Configure both.
27
+ *
28
+ * It accepts exactly one proof, and **which one is your choice, not the
29
+ * platform's**:
30
+ *
31
+ * - Configure `teamDomain` + `aud` and the request's `Cf-Access-Jwt-Assertion`
32
+ * JWT is the only thing accepted. This is the stricter setup, and the point of
33
+ * the `aud`: it proves the caller came through the *specific* Access application
34
+ * you put in front of `/_lunora/admin`, not merely through some application in
35
+ * the same Cloudflare team.
36
+ * - Configure neither and the Worker's own Access identity (`context.access`) is
37
+ * accepted, for a deployment whose Access policy is attached to the Worker.
38
+ *
39
+ * Note this is the **opposite** precedence to `createAccessResolver`, which
40
+ * prefers the platform identity. That is deliberate. A policy attached to the
41
+ * Worker is typically broad — "anyone at the company", covering every route and
42
+ * preview URL — while a configured admin `aud` is deliberately narrow. Letting
43
+ * the broad one satisfy a gate you scoped with the narrow one would widen the
44
+ * admin plane to everyone the Worker policy admits, silently, the moment that
45
+ * policy was attached.
46
+ *
47
+ * It is **fail-closed**: no identity, a token that fails verification, or an
48
+ * `isAdmin` that returns `false` all resolve to `false` (the bearer remains the
49
+ * only other path). Verification needs no `env` binding (static team-domain/aud
50
+ * config + the remote JWKS over `fetch`), so the gate takes only the request and
51
+ * its context and the runtime can evaluate it without threading async through
52
+ * every admin route.
53
+ *
54
+ * ```ts
55
+ * // A dedicated Access application over /_lunora/admin — the JWT is the only proof.
56
+ * options.adminGate = accessAdminGate({
57
+ * teamDomain: env.CF_ACCESS_TEAM_DOMAIN,
58
+ * aud: env.CF_ACCESS_ADMIN_AUD,
59
+ * isAdmin: (claims) => claims.groups?.includes("lunora-admins") ?? false,
60
+ * });
61
+ *
62
+ * // Access policy attached to the Worker — `isAdmin` is the whole boundary, so
63
+ * // make it at least as strict as a dedicated admin application would have been.
64
+ * options.adminGate = accessAdminGate({
65
+ * isAdmin: (claims) => claims.groups?.includes("lunora-admins") ?? false,
66
+ * });
67
+ * ```
68
+ */
69
+ declare const accessAdminGate: (options: AccessAdminGateOptions) => ((request: Request, context?: ExecutionContextLike) => Promise<boolean>);
36
70
  export { type AccessAdminGateOptions, accessAdminGate };
package/dist/admin.mjs CHANGED
@@ -1,8 +1 @@
1
- import { verifyRequest } from './packem_shared/accessIssuer-83KYwaCp.mjs';
2
-
3
- const accessAdminGate = (options) => async (request) => {
4
- const claims = await verifyRequest(request, options);
5
- return claims === void 0 ? false : options.isAdmin(claims);
6
- };
7
-
8
- export { accessAdminGate };
1
+ import{LunoraError as e}from"@lunora/errors";import{r as n}from"./packem_shared/platform-identity-Dy6G1EoF.mjs";import{assertJwtFallbackOptions as o,verifyRequest as m}from"./packem_shared/accessIssuer-CLO6p5MF.mjs";const l=i=>{if(typeof i.isAdmin!="function")throw new e("INTERNAL",'accessAdminGate: `isAdmin` is required and must be a function — it is the entire admin boundary, so there is no implicit grant. Pass e.g. `isAdmin: (claims) => claims.groups?.includes("lunora-admins") ?? false`.');const t=o(i);return async(s,a)=>{const r=t===void 0?await n(a):await m(s,t);return r===void 0?!1:await i.isAdmin(r)===!0}};export{l as accessAdminGate};
@@ -1,14 +1,32 @@
1
- import { M as Middleware } from "./packem_shared/index.d-ByAnpUzP.mjs";
2
- import { A as AccessClaims } from "./packem_shared/types.d-BO8d74KI.mjs";
3
- import '@lunora/errors';
1
+ import { A as AccessClaims } from "./packem_shared/types.d-Dp399TMk.mjs";
4
2
  import 'jose';
5
3
  /**
6
- * The slice of context {@link accessContext} reads: the `auth` facade every
7
- * Lunora ctx carries. `getIdentity()` returns the verified identity envelope —
8
- * `createAccessResolver`'s {@link import("./types").ResolvedAccessIdentity}
9
- * output, which carries the full claim set under `access` plus the promoted
10
- * `email` / `groups` / `commonName` fields.
11
- */
4
+ * `next()` advances the middleware chain. Called with no argument it forwards
5
+ * the current context unchanged; called with `{ ctx }` it shallow-merges the
6
+ * extension, and the result type reflects the widened context.
7
+ */
8
+ interface MiddlewareNext<ContextIn> {
9
+ (): Promise<ContextIn>;
10
+ <Extension extends Record<string, unknown>>(options: {
11
+ ctx: Extension;
12
+ }): Promise<ContextIn & Extension>;
13
+ }
14
+ /**
15
+ * A middleware receives the current context and a `next` continuation. Its
16
+ * return type becomes the builder's new context, so `return next({ ctx })`
17
+ * propagates the extension into every downstream `.use()` and the handler.
18
+ */
19
+ type Middleware<ContextIn, ContextOut> = (options: {
20
+ ctx: ContextIn;
21
+ next: MiddlewareNext<ContextIn>;
22
+ }) => ContextOut | Promise<ContextOut>;
23
+ /**
24
+ * The slice of context {@link accessContext} reads: the `auth` facade every
25
+ * Lunora ctx carries. `getIdentity()` returns the verified identity envelope —
26
+ * `createAccessResolver`'s {@link import("./types").ResolvedAccessIdentity}
27
+ * output, which carries the full claim set under `access` plus the promoted
28
+ * `email` / `groups` / `commonName` fields.
29
+ */
12
30
  interface AccessContextInput {
13
31
  auth?: {
14
32
  getIdentity?: () => (Record<string, unknown> | null) | Promise<Record<string, unknown> | null>;
@@ -16,11 +34,11 @@ interface AccessContextInput {
16
34
  };
17
35
  }
18
36
  /**
19
- * The typed, per-request `ctx.access` facade {@link accessContext} attaches. A
20
- * synchronous, Access-shaped read over the already-resolved identity — so a
21
- * handler reads `ctx.access.email` / `ctx.access.hasGroup("ops")` without an
22
- * `await` or a cast off the generic `ctx.auth.getIdentity()` envelope.
23
- */
37
+ * The typed, per-request `ctx.access` facade {@link accessContext} attaches. A
38
+ * synchronous, Access-shaped read over the already-resolved identity — so a
39
+ * handler reads `ctx.access.email` / `ctx.access.hasGroup("ops")` without an
40
+ * `await` or a cast off the generic `ctx.auth.getIdentity()` envelope.
41
+ */
24
42
  interface AccessFacade {
25
43
  /** True when a verified Access identity is present on the request. */
26
44
  readonly authenticated: boolean;
@@ -42,39 +60,39 @@ interface AccessContextOutput extends AccessContextInput {
42
60
  access: AccessFacade;
43
61
  }
44
62
  /**
45
- * Build the `ctx.access` facade from a (possibly absent) resolved identity
46
- * envelope. Returns the anonymous facade when no identity is present, so callers
47
- * never null-check. Shared by {@link accessContext} and the codegen-wired global
48
- * `ctx.access` (which calls this synchronously from the resolved identity locals
49
- * at ctx-build time, so a global `ctx.access` adds only this object construction
50
- * per request — no extra I/O or re-verification).
51
- */
63
+ * Build the `ctx.access` facade from a (possibly absent) resolved identity
64
+ * envelope. Returns the anonymous facade when no identity is present, so callers
65
+ * never null-check. Shared by {@link accessContext} and the codegen-wired global
66
+ * `ctx.access` (which calls this synchronously from the resolved identity locals
67
+ * at ctx-build time, so a global `ctx.access` adds only this object construction
68
+ * per request — no extra I/O or re-verification).
69
+ */
52
70
  declare const accessFacade: (identity: Record<string, unknown> | null | undefined, userId: string | null | undefined) => AccessFacade;
53
71
  /**
54
- * Middleware that attaches a typed `ctx.access` facade derived from the verified
55
- * Cloudflare Access identity. It resolves `ctx.auth.getIdentity()` once and
56
- * exposes a **synchronous**, Access-shaped read — `ctx.access.email`,
57
- * `ctx.access.groups`, `ctx.access.hasGroup("ops")`, `ctx.access.claims` — so a
58
- * handler reads the verified identity ergonomically and with full typing instead
59
- * of casting off the generic `getIdentity()` envelope.
60
- *
61
- * When no identity is resolved (anonymous request) it attaches the anonymous
62
- * facade — `authenticated: false`, empty `groups`, `hasGroup` always `false` —
63
- * so reads stay safe without a null check, and authorization decisions still
64
- * fail closed.
65
- *
66
- * It does not gate the request; pair it with `rls(...)` (or
67
- * `accessRoles(...)` → `rls(...)`) when you need enforcement. It only surfaces
68
- * the identity for branching inside a handler.
69
- *
70
- * ```ts
71
- * export const whoAmI = query
72
- * .use(accessContext())
73
- * .query(async ({ ctx }) => ({
74
- * email: ctx.access.email,
75
- * isOps: ctx.access.hasGroup("ops"),
76
- * }));
77
- * ```
78
- */
72
+ * Middleware that attaches a typed `ctx.access` facade derived from the verified
73
+ * Cloudflare Access identity. It resolves `ctx.auth.getIdentity()` once and
74
+ * exposes a **synchronous**, Access-shaped read — `ctx.access.email`,
75
+ * `ctx.access.groups`, `ctx.access.hasGroup("ops")`, `ctx.access.claims` — so a
76
+ * handler reads the verified identity ergonomically and with full typing instead
77
+ * of casting off the generic `getIdentity()` envelope.
78
+ *
79
+ * When no identity is resolved (anonymous request) it attaches the anonymous
80
+ * facade — `authenticated: false`, empty `groups`, `hasGroup` always `false` —
81
+ * so reads stay safe without a null check, and authorization decisions still
82
+ * fail closed.
83
+ *
84
+ * It does not gate the request; pair it with `rls(...)` (or
85
+ * `rls(...)`) when you need enforcement. It only surfaces
86
+ * the identity for branching inside a handler.
87
+ *
88
+ * ```ts
89
+ * export const whoAmI = query
90
+ * .use(accessContext())
91
+ * .query(async ({ ctx }) => ({
92
+ * email: ctx.access.email,
93
+ * isOps: ctx.access.hasGroup("ops"),
94
+ * }));
95
+ * ```
96
+ */
79
97
  declare const accessContext: <Context extends AccessContextInput>() => Middleware<Context, AccessContextOutput & Context>;
80
98
  export { type AccessContextInput, type AccessContextOutput, type AccessFacade, accessContext, accessFacade };