@xtandard/permissions 0.0.0-stage → 0.2.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 +21 -0
- package/README.md +364 -2
- package/bin/xtandard-permissions.mjs +3 -0
- package/dist/better-auth-BEmX8qyz.mjs +94 -0
- package/dist/better-auth-BEmX8qyz.mjs.map +1 -0
- package/dist/better-auth-DQET1sXa.d.mts +75 -0
- package/dist/better-auth-MR7dBtpo.cjs +111 -0
- package/dist/better-auth-MR7dBtpo.cjs.map +1 -0
- package/dist/better-auth-vgRYgjYK.d.cts +75 -0
- package/dist/catalog-DA_d1SdC.d.cts +153 -0
- package/dist/catalog-DJcJ3ycq.d.mts +153 -0
- package/dist/catalog.cjs +198 -0
- package/dist/catalog.cjs.map +1 -0
- package/dist/catalog.d.cts +3 -0
- package/dist/catalog.d.mts +3 -0
- package/dist/catalog.mjs +141 -0
- package/dist/catalog.mjs.map +1 -0
- package/dist/chunk-DakpK96I.cjs +43 -0
- package/dist/cli.cjs +554 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +28 -0
- package/dist/cli.d.mts +28 -0
- package/dist/cli.mjs +550 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/contract-BAisPHBw.d.cts +78 -0
- package/dist/contract-BganM0fx.mjs +79 -0
- package/dist/contract-BganM0fx.mjs.map +1 -0
- package/dist/contract-Bpy8yPrS.cjs +70 -0
- package/dist/contract-Bpy8yPrS.cjs.map +1 -0
- package/dist/contract-Brnu9XXo.cjs +114 -0
- package/dist/contract-Brnu9XXo.cjs.map +1 -0
- package/dist/contract-CNgMXr2u.d.cts +46 -0
- package/dist/contract-CNgMXr2u.d.mts +46 -0
- package/dist/contract-CXPMGuHk.d.cts +391 -0
- package/dist/contract-D6j-yrBL.d.mts +78 -0
- package/dist/contract-DTdTXZtJ.mjs +47 -0
- package/dist/contract-DTdTXZtJ.mjs.map +1 -0
- package/dist/contract-DhS23Pcp.d.mts +391 -0
- package/dist/contract-RMkmERhT.d.cts +2 -0
- package/dist/contract-RMkmERhT.d.mts +2 -0
- package/dist/create-fetch-handler-B0twltQL.mjs +673 -0
- package/dist/create-fetch-handler-B0twltQL.mjs.map +1 -0
- package/dist/create-fetch-handler-B711wb64.d.mts +77 -0
- package/dist/create-fetch-handler-BHT4vSZs.cjs +690 -0
- package/dist/create-fetch-handler-BHT4vSZs.cjs.map +1 -0
- package/dist/create-fetch-handler-DxhvXuBA.d.cts +77 -0
- package/dist/elysia-shared-BFcWzfc9.cjs +101 -0
- package/dist/elysia-shared-BFcWzfc9.cjs.map +1 -0
- package/dist/elysia-shared-BwUYg0Ln.mjs +78 -0
- package/dist/elysia-shared-BwUYg0Ln.mjs.map +1 -0
- package/dist/elysia-shared-C2LnDOj3.d.cts +58 -0
- package/dist/elysia-shared-WuDr0jco.d.mts +58 -0
- package/dist/engine--C7zo-4M.cjs +667 -0
- package/dist/engine--C7zo-4M.cjs.map +1 -0
- package/dist/engine-BTgwbHeO.d.cts +336 -0
- package/dist/engine-C3xHfi3q.d.mts +336 -0
- package/dist/engine-CR75K253.mjs +654 -0
- package/dist/engine-CR75K253.mjs.map +1 -0
- package/dist/entry-auth-basic.cjs +40 -0
- package/dist/entry-auth-basic.cjs.map +1 -0
- package/dist/entry-auth-basic.d.cts +24 -0
- package/dist/entry-auth-basic.d.mts +24 -0
- package/dist/entry-auth-basic.mjs +26 -0
- package/dist/entry-auth-basic.mjs.map +1 -0
- package/dist/entry-auth-better-auth.cjs +15 -0
- package/dist/entry-auth-better-auth.d.cts +5 -0
- package/dist/entry-auth-better-auth.d.mts +5 -0
- package/dist/entry-auth-better-auth.mjs +4 -0
- package/dist/entry-auth-delegated.cjs +8 -0
- package/dist/entry-auth-delegated.d.cts +2 -0
- package/dist/entry-auth-delegated.d.mts +2 -0
- package/dist/entry-auth-delegated.mjs +2 -0
- package/dist/entry-auth-jwt.cjs +120 -0
- package/dist/entry-auth-jwt.cjs.map +1 -0
- package/dist/entry-auth-jwt.d.cts +71 -0
- package/dist/entry-auth-jwt.d.mts +71 -0
- package/dist/entry-auth-jwt.mjs +109 -0
- package/dist/entry-auth-jwt.mjs.map +1 -0
- package/dist/entry-auth-none.cjs +14 -0
- package/dist/entry-auth-none.d.cts +2 -0
- package/dist/entry-auth-none.d.mts +2 -0
- package/dist/entry-auth-none.mjs +2 -0
- package/dist/entry-auth-session.cjs +86 -0
- package/dist/entry-auth-session.cjs.map +1 -0
- package/dist/entry-auth-session.d.cts +25 -0
- package/dist/entry-auth-session.d.mts +25 -0
- package/dist/entry-auth-session.mjs +76 -0
- package/dist/entry-auth-session.mjs.map +1 -0
- package/dist/entry-authorization-delegated.cjs +31 -0
- package/dist/entry-authorization-delegated.cjs.map +1 -0
- package/dist/entry-authorization-delegated.d.cts +27 -0
- package/dist/entry-authorization-delegated.d.mts +27 -0
- package/dist/entry-authorization-delegated.mjs +30 -0
- package/dist/entry-authorization-delegated.mjs.map +1 -0
- package/dist/entry-authorization-none.cjs +29 -0
- package/dist/entry-authorization-none.cjs.map +1 -0
- package/dist/entry-authorization-none.d.cts +17 -0
- package/dist/entry-authorization-none.d.mts +17 -0
- package/dist/entry-authorization-none.mjs +28 -0
- package/dist/entry-authorization-none.mjs.map +1 -0
- package/dist/entry-authorization-permissions.cjs +4 -0
- package/dist/entry-authorization-permissions.d.cts +49 -0
- package/dist/entry-authorization-permissions.d.mts +49 -0
- package/dist/entry-authorization-permissions.mjs +2 -0
- package/dist/entry-authorization-roles.cjs +9 -0
- package/dist/entry-authorization-roles.d.cts +37 -0
- package/dist/entry-authorization-roles.d.mts +37 -0
- package/dist/entry-authorization-roles.mjs +3 -0
- package/dist/entry-better-auth-client.cjs +31 -0
- package/dist/entry-better-auth-client.cjs.map +1 -0
- package/dist/entry-better-auth-client.d.cts +63 -0
- package/dist/entry-better-auth-client.d.mts +63 -0
- package/dist/entry-better-auth-client.mjs +29 -0
- package/dist/entry-better-auth-client.mjs.map +1 -0
- package/dist/entry-better-auth.cjs +289 -0
- package/dist/entry-better-auth.cjs.map +1 -0
- package/dist/entry-better-auth.d.cts +3 -0
- package/dist/entry-better-auth.d.mts +3 -0
- package/dist/entry-better-auth.mjs +284 -0
- package/dist/entry-better-auth.mjs.map +1 -0
- package/dist/entry-bridges-audit.cjs +106 -0
- package/dist/entry-bridges-audit.cjs.map +1 -0
- package/dist/entry-bridges-audit.d.cts +58 -0
- package/dist/entry-bridges-audit.d.mts +58 -0
- package/dist/entry-bridges-audit.mjs +105 -0
- package/dist/entry-bridges-audit.mjs.map +1 -0
- package/dist/entry-bridges-webhooks.cjs +90 -0
- package/dist/entry-bridges-webhooks.cjs.map +1 -0
- package/dist/entry-bridges-webhooks.d.cts +46 -0
- package/dist/entry-bridges-webhooks.d.mts +46 -0
- package/dist/entry-bridges-webhooks.mjs +88 -0
- package/dist/entry-bridges-webhooks.mjs.map +1 -0
- package/dist/entry-bun.cjs +33 -0
- package/dist/entry-bun.cjs.map +1 -0
- package/dist/entry-bun.d.cts +31 -0
- package/dist/entry-bun.d.mts +31 -0
- package/dist/entry-bun.mjs +30 -0
- package/dist/entry-bun.mjs.map +1 -0
- package/dist/entry-drizzle-mysql.cjs +34 -0
- package/dist/entry-drizzle-mysql.cjs.map +1 -0
- package/dist/entry-drizzle-mysql.d.cts +20 -0
- package/dist/entry-drizzle-mysql.d.mts +20 -0
- package/dist/entry-drizzle-mysql.mjs +33 -0
- package/dist/entry-drizzle-mysql.mjs.map +1 -0
- package/dist/entry-drizzle-pg.cjs +44 -0
- package/dist/entry-drizzle-pg.cjs.map +1 -0
- package/dist/entry-drizzle-pg.d.cts +20 -0
- package/dist/entry-drizzle-pg.d.mts +20 -0
- package/dist/entry-drizzle-pg.mjs +43 -0
- package/dist/entry-drizzle-pg.mjs.map +1 -0
- package/dist/entry-drizzle-sqlite.cjs +34 -0
- package/dist/entry-drizzle-sqlite.cjs.map +1 -0
- package/dist/entry-drizzle-sqlite.d.cts +15 -0
- package/dist/entry-drizzle-sqlite.d.mts +15 -0
- package/dist/entry-drizzle-sqlite.mjs +33 -0
- package/dist/entry-drizzle-sqlite.mjs.map +1 -0
- package/dist/entry-elysia.cjs +117 -0
- package/dist/entry-elysia.cjs.map +1 -0
- package/dist/entry-elysia.d.cts +446 -0
- package/dist/entry-elysia.d.mts +446 -0
- package/dist/entry-elysia.mjs +113 -0
- package/dist/entry-elysia.mjs.map +1 -0
- package/dist/entry-elysia2.cjs +117 -0
- package/dist/entry-elysia2.cjs.map +1 -0
- package/dist/entry-elysia2.d.cts +571 -0
- package/dist/entry-elysia2.d.mts +571 -0
- package/dist/entry-elysia2.mjs +113 -0
- package/dist/entry-elysia2.mjs.map +1 -0
- package/dist/entry-express.cjs +101 -0
- package/dist/entry-express.cjs.map +1 -0
- package/dist/entry-express.d.cts +36 -0
- package/dist/entry-express.d.mts +36 -0
- package/dist/entry-express.mjs +97 -0
- package/dist/entry-express.mjs.map +1 -0
- package/dist/entry-hono.cjs +63 -0
- package/dist/entry-hono.cjs.map +1 -0
- package/dist/entry-hono.d.cts +40 -0
- package/dist/entry-hono.d.mts +40 -0
- package/dist/entry-hono.mjs +60 -0
- package/dist/entry-hono.mjs.map +1 -0
- package/dist/entry-hooks-log.cjs +39 -0
- package/dist/entry-hooks-log.cjs.map +1 -0
- package/dist/entry-hooks-log.d.cts +19 -0
- package/dist/entry-hooks-log.d.mts +19 -0
- package/dist/entry-hooks-log.mjs +36 -0
- package/dist/entry-hooks-log.mjs.map +1 -0
- package/dist/entry-next.cjs +67 -0
- package/dist/entry-next.cjs.map +1 -0
- package/dist/entry-next.d.cts +60 -0
- package/dist/entry-next.d.mts +60 -0
- package/dist/entry-next.mjs +57 -0
- package/dist/entry-next.mjs.map +1 -0
- package/dist/entry-react.cjs +401 -0
- package/dist/entry-react.cjs.map +1 -0
- package/dist/entry-react.d.cts +206 -0
- package/dist/entry-react.d.mts +206 -0
- package/dist/entry-react.mjs +388 -0
- package/dist/entry-react.mjs.map +1 -0
- package/dist/entry-storage-cloudflare-kv.cjs +8 -0
- package/dist/entry-storage-cloudflare-kv.d.cts +2 -0
- package/dist/entry-storage-cloudflare-kv.d.mts +2 -0
- package/dist/entry-storage-cloudflare-kv.mjs +2 -0
- package/dist/entry-storage-drizzle.cjs +71 -0
- package/dist/entry-storage-drizzle.cjs.map +1 -0
- package/dist/entry-storage-drizzle.d.cts +27 -0
- package/dist/entry-storage-drizzle.d.mts +27 -0
- package/dist/entry-storage-drizzle.mjs +68 -0
- package/dist/entry-storage-drizzle.mjs.map +1 -0
- package/dist/entry-storage-file.cjs +54 -0
- package/dist/entry-storage-file.cjs.map +1 -0
- package/dist/entry-storage-file.d.cts +24 -0
- package/dist/entry-storage-file.d.mts +24 -0
- package/dist/entry-storage-file.mjs +46 -0
- package/dist/entry-storage-file.mjs.map +1 -0
- package/dist/entry-storage-libsql.cjs +64 -0
- package/dist/entry-storage-libsql.cjs.map +1 -0
- package/dist/entry-storage-libsql.d.cts +28 -0
- package/dist/entry-storage-libsql.d.mts +28 -0
- package/dist/entry-storage-libsql.mjs +61 -0
- package/dist/entry-storage-libsql.mjs.map +1 -0
- package/dist/entry-storage-memory.cjs +3 -0
- package/dist/entry-storage-memory.d.cts +25 -0
- package/dist/entry-storage-memory.d.mts +25 -0
- package/dist/entry-storage-memory.mjs +2 -0
- package/dist/entry-storage-mongodb.cjs +61 -0
- package/dist/entry-storage-mongodb.cjs.map +1 -0
- package/dist/entry-storage-mongodb.d.cts +25 -0
- package/dist/entry-storage-mongodb.d.mts +25 -0
- package/dist/entry-storage-mongodb.mjs +58 -0
- package/dist/entry-storage-mongodb.mjs.map +1 -0
- package/dist/entry-storage-postgres.cjs +62 -0
- package/dist/entry-storage-postgres.cjs.map +1 -0
- package/dist/entry-storage-postgres.d.cts +29 -0
- package/dist/entry-storage-postgres.d.mts +29 -0
- package/dist/entry-storage-postgres.mjs +58 -0
- package/dist/entry-storage-postgres.mjs.map +1 -0
- package/dist/entry-storage-redis.cjs +76 -0
- package/dist/entry-storage-redis.cjs.map +1 -0
- package/dist/entry-storage-redis.d.cts +29 -0
- package/dist/entry-storage-redis.d.mts +29 -0
- package/dist/entry-storage-redis.mjs +72 -0
- package/dist/entry-storage-redis.mjs.map +1 -0
- package/dist/entry-storage-sqlite.cjs +46 -0
- package/dist/entry-storage-sqlite.cjs.map +1 -0
- package/dist/entry-storage-sqlite.d.cts +22 -0
- package/dist/entry-storage-sqlite.d.mts +22 -0
- package/dist/entry-storage-sqlite.mjs +43 -0
- package/dist/entry-storage-sqlite.mjs.map +1 -0
- package/dist/entry-storage-unstorage.cjs +8 -0
- package/dist/entry-storage-unstorage.d.cts +2 -0
- package/dist/entry-storage-unstorage.d.mts +2 -0
- package/dist/entry-storage-unstorage.mjs +2 -0
- package/dist/error-codes-9MRMSSMQ.cjs +49 -0
- package/dist/error-codes-9MRMSSMQ.cjs.map +1 -0
- package/dist/error-codes-CCKuDDu7.mjs +44 -0
- package/dist/error-codes-CCKuDDu7.mjs.map +1 -0
- package/dist/errors-CG_OLEEv.mjs +64 -0
- package/dist/errors-CG_OLEEv.mjs.map +1 -0
- package/dist/errors-CjpymzFj.cjs +105 -0
- package/dist/errors-CjpymzFj.cjs.map +1 -0
- package/dist/events-AE4Ytqmz.d.cts +6 -0
- package/dist/events-AE4Ytqmz.d.mts +6 -0
- package/dist/events-DYZShrYB.mjs +15 -0
- package/dist/events-DYZShrYB.mjs.map +1 -0
- package/dist/events-FJ2K0wly.cjs +26 -0
- package/dist/events-FJ2K0wly.cjs.map +1 -0
- package/dist/guard-Bj8zk23F.mjs +141 -0
- package/dist/guard-Bj8zk23F.mjs.map +1 -0
- package/dist/guard-DvaoUgjk.cjs +188 -0
- package/dist/guard-DvaoUgjk.cjs.map +1 -0
- package/dist/guard-VEK0W8ug.d.cts +62 -0
- package/dist/guard-k7A71SWC.d.mts +62 -0
- package/dist/index-BVVgDSdq.d.cts +1 -0
- package/dist/index-BVVgDSdq.d.mts +1 -0
- package/dist/index.cjs +243 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +213 -0
- package/dist/index.d.mts +213 -0
- package/dist/index.mjs +60 -0
- package/dist/index.mjs.map +1 -0
- package/dist/kit-51JtMxsn.d.mts +62 -0
- package/dist/kit-BM3uosfV.mjs +80 -0
- package/dist/kit-BM3uosfV.mjs.map +1 -0
- package/dist/kit-BrqnCcDw.cjs +97 -0
- package/dist/kit-BrqnCcDw.cjs.map +1 -0
- package/dist/kit-DLF7DZrp.d.cts +62 -0
- package/dist/memory-BbBbbY8-.mjs +32 -0
- package/dist/memory-BbBbbY8-.mjs.map +1 -0
- package/dist/memory-knijqKw_.cjs +39 -0
- package/dist/memory-knijqKw_.cjs.map +1 -0
- package/dist/permissions-CeV6M3v7.mjs +62 -0
- package/dist/permissions-CeV6M3v7.mjs.map +1 -0
- package/dist/permissions-DDEkHNvN.cjs +73 -0
- package/dist/permissions-DDEkHNvN.cjs.map +1 -0
- package/dist/policy-BQmlo2lu.mjs +3 -0
- package/dist/policy-CGA6QD0a.d.mts +4 -0
- package/dist/policy-DFq_SYR3.d.cts +4 -0
- package/dist/react-embed.js +18735 -0
- package/dist/react.css +1 -0
- package/dist/relationships-BLYEJ9tc.cjs +907 -0
- package/dist/relationships-BLYEJ9tc.cjs.map +1 -0
- package/dist/relationships-BfLonEMI.mjs +756 -0
- package/dist/relationships-BfLonEMI.mjs.map +1 -0
- package/dist/roles-DBk4i8b5.mjs +69 -0
- package/dist/roles-DBk4i8b5.mjs.map +1 -0
- package/dist/roles-a8B5uZ35.cjs +104 -0
- package/dist/roles-a8B5uZ35.cjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/routes-B2LrYpT0.cjs +1055 -0
- package/dist/routes-B2LrYpT0.cjs.map +1 -0
- package/dist/routes-Cx-kl4PY.mjs +1007 -0
- package/dist/routes-Cx-kl4PY.mjs.map +1 -0
- package/dist/server-Bn643UOy.d.mts +886 -0
- package/dist/server-YdH25OEA.d.cts +886 -0
- package/dist/table-DA98mVVT.d.cts +2 -0
- package/dist/table-DA98mVVT.d.mts +2 -0
- package/dist/testing.cjs +59 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +37 -0
- package/dist/testing.d.mts +37 -0
- package/dist/testing.mjs +57 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/types-elysia2/adapters/elysia-shared.d.ts +71 -0
- package/dist/types-elysia2/adapters/elysia2.d.ts +432 -0
- package/dist/types-elysia2/adapters/guard.d.ts +140 -0
- package/dist/types-elysia2/auth/contract.d.ts +9 -0
- package/dist/types-elysia2/auth-provider/contract.d.ts +85 -0
- package/dist/types-elysia2/auth-provider/kit.d.ts +62 -0
- package/dist/types-elysia2/authorization/contract.d.ts +53 -0
- package/dist/types-elysia2/authorization/permissions.d.ts +54 -0
- package/dist/types-elysia2/catalog.d.ts +197 -0
- package/dist/types-elysia2/engine.d.ts +233 -0
- package/dist/types-elysia2/entry-elysia2.d.ts +9 -0
- package/dist/types-elysia2/errors.d.ts +55 -0
- package/dist/types-elysia2/hooks/contract.d.ts +100 -0
- package/dist/types-elysia2/keys.d.ts +78 -0
- package/dist/types-elysia2/policy.d.ts +13 -0
- package/dist/types-elysia2/relationships.d.ts +162 -0
- package/dist/types-elysia2/schema.d.ts +315 -0
- package/dist/types-elysia2/server/cors.d.ts +8 -0
- package/dist/types-elysia2/server/create-fetch-handler.d.ts +87 -0
- package/dist/types-elysia2/server/openapi.d.ts +29 -0
- package/dist/types-elysia2/server/routes.d.ts +143 -0
- package/dist/types-elysia2/server/validation.d.ts +205 -0
- package/dist/types-elysia2/storage/contract.d.ts +18 -0
- package/dist/types-react/catalog.d.ts +197 -0
- package/dist/types-react/engine.d.ts +233 -0
- package/dist/types-react/entry-react-embed.d.ts +20 -0
- package/dist/types-react/errors.d.ts +55 -0
- package/dist/types-react/hooks/contract.d.ts +100 -0
- package/dist/types-react/keys.d.ts +78 -0
- package/dist/types-react/policy.d.ts +13 -0
- package/dist/types-react/react-embed.d.ts +37 -0
- package/dist/types-react/relationships.d.ts +162 -0
- package/dist/types-react/schema.d.ts +315 -0
- package/dist/types-react/storage/contract.d.ts +18 -0
- package/dist/types-react/ui/App.d.ts +28 -0
- package/dist/types-react/ui/api.d.ts +73 -0
- package/dist/types-react/ui/components/perm-bits.d.ts +68 -0
- package/dist/types-react/ui/lib/queries.d.ts +46 -0
- package/dist/types-react/ui/theme.d.ts +10 -0
- package/dist/types-react/ui/types.d.ts +118 -0
- package/dist/types-react/ui/views/CatalogView.d.ts +3 -0
- package/dist/types-react/ui/views/HistoryView.d.ts +6 -0
- package/dist/types-react/ui/views/PlaygroundView.d.ts +14 -0
- package/dist/types-react/ui/views/RelationshipsView.d.ts +6 -0
- package/dist/types-react/ui/views/SubjectDetailView.d.ts +7 -0
- package/dist/types-react/ui/views/SubjectsView.d.ts +6 -0
- package/dist/ui/apple-touch-icon.png +0 -0
- package/dist/ui/assets/index-DCPZRo-Z.css +1 -0
- package/dist/ui/assets/index-DdvxpphI.js +104 -0
- package/dist/ui/favicon.ico +0 -0
- package/dist/ui/favicon.svg +15 -0
- package/dist/ui/index.html +20 -0
- package/package.json +587 -4
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { a as splitRoles, i as normalizeRoles, n as identity, o as stringField, r as mappedLookup, t as externalRoles } from "./contract-BganM0fx.mjs";
|
|
2
|
+
import { n as subjectOf, r as toKitAuth, t as identityOf } from "./kit-BM3uosfV.mjs";
|
|
3
|
+
import { importPeer } from "@xtandard/kit/storage";
|
|
4
|
+
//#region src/auth-provider/jwt.ts
|
|
5
|
+
/**
|
|
6
|
+
* A Bearer / cookie JWT as a {@link PermissionsAuthProvider} (ADR 0006), verified with `jose` (an
|
|
7
|
+
* optional peer, imported on first use): an HS256 shared secret, or a JWKS (remote URL or inline
|
|
8
|
+
* key set) for asymmetric tokens from an identity provider.
|
|
9
|
+
*
|
|
10
|
+
* An invalid, expired or wrongly-signed token is "no session" (`null` → guest / 401), never a 500.
|
|
11
|
+
* A JWKS endpoint that times out is an error (500): it says nothing about the caller.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
const SUBPATH = "@xtandard/permissions/auth/jwt";
|
|
16
|
+
/** The token of a request: the Bearer header first, then the cookie. */
|
|
17
|
+
function readToken(request, options) {
|
|
18
|
+
if (options.header !== false) {
|
|
19
|
+
const match = /^Bearer\s+(\S+)\s*$/i.exec(request.headers.get("authorization") ?? "");
|
|
20
|
+
if (match) return match[1];
|
|
21
|
+
}
|
|
22
|
+
if (options.cookie) for (const part of (request.headers.get("cookie") ?? "").split(";")) {
|
|
23
|
+
const eq = part.indexOf("=");
|
|
24
|
+
if (eq === -1 || part.slice(0, eq).trim() !== options.cookie) continue;
|
|
25
|
+
const value = part.slice(eq + 1).trim();
|
|
26
|
+
if (!value) return null;
|
|
27
|
+
try {
|
|
28
|
+
return decodeURIComponent(value);
|
|
29
|
+
} catch {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
/** The default claims → identity mapping. */
|
|
36
|
+
function defaultMap(claims, roleClaim) {
|
|
37
|
+
const id = stringField(claims, "sub");
|
|
38
|
+
if (!id) return null;
|
|
39
|
+
return identity({
|
|
40
|
+
id,
|
|
41
|
+
role: roleClaim ? claims[roleClaim] : claims.role ?? claims.roles,
|
|
42
|
+
name: stringField(claims, "name"),
|
|
43
|
+
email: stringField(claims, "email")
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/** True for a `jose` error that means "this token is not valid" (not an infrastructure failure). */
|
|
47
|
+
function isInvalidToken(jose, error) {
|
|
48
|
+
return error instanceof jose.errors.JOSEError && !(error instanceof jose.errors.JWKSTimeout);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A {@link PermissionsAuthProvider} that verifies a JWT from the request.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { jwtProvider } from "@xtandard/permissions/auth/jwt";
|
|
56
|
+
*
|
|
57
|
+
* jwtProvider({ secret: process.env.JWT_SECRET!, issuer: "my-app", cookie: "token" });
|
|
58
|
+
* jwtProvider({ jwks: "https://idp.example.com/.well-known/jwks.json", audience: "api" });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
function jwtProvider(options) {
|
|
62
|
+
if (!options.secret && !options.jwks) throw new TypeError("jwtProvider: pass `secret` (HS256) or `jwks`");
|
|
63
|
+
if (options.secret && options.jwks) throw new TypeError("jwtProvider: pass either `secret` or `jwks`, not both");
|
|
64
|
+
let ready;
|
|
65
|
+
const load = () => (ready ??= importPeer("jose", SUBPATH, () => import("jose")).then((jose) => {
|
|
66
|
+
let key;
|
|
67
|
+
if (options.secret !== void 0) key = typeof options.secret === "string" ? new TextEncoder().encode(options.secret) : options.secret;
|
|
68
|
+
else if (typeof options.jwks === "string" || options.jwks instanceof URL) key = jose.createRemoteJWKSet(new URL(options.jwks));
|
|
69
|
+
else key = jose.createLocalJWKSet(options.jwks);
|
|
70
|
+
return {
|
|
71
|
+
jose,
|
|
72
|
+
key
|
|
73
|
+
};
|
|
74
|
+
})).catch((error) => {
|
|
75
|
+
ready = void 0;
|
|
76
|
+
throw error;
|
|
77
|
+
});
|
|
78
|
+
const algorithms = options.algorithms ?? (options.secret !== void 0 ? ["HS256"] : void 0);
|
|
79
|
+
const verifyOptions = {};
|
|
80
|
+
if (algorithms) verifyOptions.algorithms = algorithms;
|
|
81
|
+
if (options.issuer !== void 0) verifyOptions.issuer = options.issuer;
|
|
82
|
+
if (options.audience !== void 0) verifyOptions.audience = options.audience;
|
|
83
|
+
if (options.clockTolerance !== void 0) verifyOptions.clockTolerance = options.clockTolerance;
|
|
84
|
+
const provider = { async getSubject(request) {
|
|
85
|
+
const token = readToken(request, options);
|
|
86
|
+
if (!token) return null;
|
|
87
|
+
const { jose, key } = await load();
|
|
88
|
+
let claims;
|
|
89
|
+
try {
|
|
90
|
+
claims = (await jose.jwtVerify(token, key, verifyOptions)).payload;
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (isInvalidToken(jose, error)) return null;
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
const mapped = options.map ? options.map(claims, request) : defaultMap(claims, options.roleClaim);
|
|
96
|
+
if (!mapped) return null;
|
|
97
|
+
return identity({
|
|
98
|
+
...mapped,
|
|
99
|
+
role: normalizeRoles(mapped.role, options.mapRole)
|
|
100
|
+
});
|
|
101
|
+
} };
|
|
102
|
+
if (options.canManage) provider.canManage = options.canManage;
|
|
103
|
+
if (options.lookup) provider.lookupSubject = mappedLookup(options.lookup, options.mapRole);
|
|
104
|
+
return provider;
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { externalRoles, identity, identityOf, jwtProvider, mappedLookup, normalizeRoles, readToken, splitRoles, stringField, subjectOf, toKitAuth };
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=entry-auth-jwt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-auth-jwt.mjs","names":[],"sources":["../src/auth-provider/jwt.ts"],"sourcesContent":["/**\n * A Bearer / cookie JWT as a {@link PermissionsAuthProvider} (ADR 0006), verified with `jose` (an\n * optional peer, imported on first use): an HS256 shared secret, or a JWKS (remote URL or inline\n * key set) for asymmetric tokens from an identity provider.\n *\n * An invalid, expired or wrongly-signed token is \"no session\" (`null` → guest / 401), never a 500.\n * A JWKS endpoint that times out is an error (500): it says nothing about the caller.\n *\n * @module\n */\n\nimport { importPeer } from \"@xtandard/kit/storage\";\nimport {\n identity,\n mappedLookup,\n normalizeRoles,\n stringField,\n type PermissionsAuthProvider,\n type ProviderRoleOptions,\n type SubjectIdentity,\n type SubjectLookupFn,\n} from \"./contract.ts\";\n\n/** Verified JWT claims. */\nexport type JwtClaims = Record<string, unknown> & {\n sub?: string;\n iss?: string;\n aud?: string | string[];\n exp?: number;\n iat?: number;\n};\n\n/** A JSON Web Key Set (`{ keys: [...] }`). */\nexport interface JsonWebKeySet {\n keys: Record<string, unknown>[];\n}\n\ninterface JwtProviderBase extends ProviderRoleOptions {\n /** Expected `iss`. */\n issuer?: string | string[];\n /** Expected `aud`. */\n audience?: string | string[];\n /** Accepted algorithms. Default: `[\"HS256\"]` with `secret`; the key set's with `jwks`. */\n algorithms?: string[];\n /** Clock skew tolerance, seconds or a `jose` duration string (`\"30s\"`). */\n clockTolerance?: number | string;\n /** Read the token from this cookie when there is no `Authorization: Bearer` header. */\n cookie?: string;\n /** Read `Authorization: Bearer <token>`. Default `true`. */\n header?: boolean;\n /** Claim holding the role(s). Default: `role`, then `roles`. */\n roleClaim?: string;\n /**\n * Map verified claims to a subject. Default: `sub` → id, the role claim, `name`, `email`.\n * Return `null` to treat a valid token as no session (e.g. a machine token without `sub`).\n */\n map?(claims: JwtClaims, request: Request): SubjectIdentity | null | undefined;\n /**\n * Look a subject up by id without a token (a token only describes its bearer): your user table\n * or identity provider's admin API. Becomes the provider's `lookupSubject`; `role` is split and\n * mapped like the claims'. ADR 0014.\n */\n lookup?: SubjectLookupFn;\n}\n\n/** Options for {@link jwtProvider}: exactly one of `secret` or `jwks`. */\nexport type JwtProviderOptions =\n | (JwtProviderBase & { secret: string | Uint8Array; jwks?: never })\n | (JwtProviderBase & { jwks: string | URL | JsonWebKeySet; secret?: never });\n\ntype Jose = typeof import(\"jose\");\ntype VerifyKey = Parameters<Jose[\"jwtVerify\"]>[1];\n\nconst SUBPATH = \"@xtandard/permissions/auth/jwt\";\n\n/** The token of a request: the Bearer header first, then the cookie. */\nexport function readToken(\n request: Request,\n options: { cookie?: string | undefined; header?: boolean | undefined },\n): string | null {\n if (options.header !== false) {\n const match = /^Bearer\\s+(\\S+)\\s*$/i.exec(request.headers.get(\"authorization\") ?? \"\");\n if (match) return match[1]!;\n }\n if (options.cookie) {\n for (const part of (request.headers.get(\"cookie\") ?? \"\").split(\";\")) {\n const eq = part.indexOf(\"=\");\n if (eq === -1 || part.slice(0, eq).trim() !== options.cookie) continue;\n const value = part.slice(eq + 1).trim();\n if (!value) return null;\n try {\n return decodeURIComponent(value);\n } catch {\n return value;\n }\n }\n }\n return null;\n}\n\n/** The default claims → identity mapping. */\nfunction defaultMap(claims: JwtClaims, roleClaim: string | undefined): SubjectIdentity | null {\n const id = stringField(claims, \"sub\");\n if (!id) return null;\n const role = roleClaim ? claims[roleClaim] : (claims.role ?? claims.roles);\n return identity({\n id,\n role: role as string | string[] | undefined,\n name: stringField(claims, \"name\"),\n email: stringField(claims, \"email\"),\n });\n}\n\n/** True for a `jose` error that means \"this token is not valid\" (not an infrastructure failure). */\nfunction isInvalidToken(jose: Jose, error: unknown): boolean {\n return error instanceof jose.errors.JOSEError && !(error instanceof jose.errors.JWKSTimeout);\n}\n\n/**\n * A {@link PermissionsAuthProvider} that verifies a JWT from the request.\n *\n * @example\n * ```ts\n * import { jwtProvider } from \"@xtandard/permissions/auth/jwt\";\n *\n * jwtProvider({ secret: process.env.JWT_SECRET!, issuer: \"my-app\", cookie: \"token\" });\n * jwtProvider({ jwks: \"https://idp.example.com/.well-known/jwks.json\", audience: \"api\" });\n * ```\n */\nexport function jwtProvider(options: JwtProviderOptions): PermissionsAuthProvider {\n if (!options.secret && !options.jwks) {\n throw new TypeError(\"jwtProvider: pass `secret` (HS256) or `jwks`\");\n }\n if (options.secret && options.jwks) {\n throw new TypeError(\"jwtProvider: pass either `secret` or `jwks`, not both\");\n }\n let ready: Promise<{ jose: Jose; key: VerifyKey }> | undefined;\n const load = () =>\n (ready ??= importPeer(\"jose\", SUBPATH, () => import(\"jose\")).then((jose) => {\n let key: VerifyKey;\n if (options.secret !== undefined) {\n key =\n typeof options.secret === \"string\"\n ? new TextEncoder().encode(options.secret)\n : options.secret;\n } else if (typeof options.jwks === \"string\" || options.jwks instanceof URL) {\n key = jose.createRemoteJWKSet(new URL(options.jwks));\n } else {\n key = jose.createLocalJWKSet(options.jwks as Parameters<Jose[\"createLocalJWKSet\"]>[0]);\n }\n return { jose, key };\n })).catch((error: unknown) => {\n ready = undefined; // a missing peer may be installed later; don't cache the failure\n throw error;\n });\n\n const algorithms = options.algorithms ?? (options.secret !== undefined ? [\"HS256\"] : undefined);\n const verifyOptions: Record<string, unknown> = {};\n if (algorithms) verifyOptions.algorithms = algorithms;\n if (options.issuer !== undefined) verifyOptions.issuer = options.issuer;\n if (options.audience !== undefined) verifyOptions.audience = options.audience;\n if (options.clockTolerance !== undefined) verifyOptions.clockTolerance = options.clockTolerance;\n\n const provider: PermissionsAuthProvider = {\n async getSubject(request) {\n const token = readToken(request, options);\n if (!token) return null;\n const { jose, key } = await load();\n let claims: JwtClaims;\n try {\n claims = (await jose.jwtVerify(token, key, verifyOptions)).payload as JwtClaims;\n } catch (error) {\n if (isInvalidToken(jose, error)) return null;\n throw error;\n }\n const mapped = options.map\n ? options.map(claims, request)\n : defaultMap(claims, options.roleClaim);\n if (!mapped) return null;\n return identity({ ...mapped, role: normalizeRoles(mapped.role, options.mapRole) });\n },\n };\n if (options.canManage) provider.canManage = options.canManage;\n if (options.lookup) provider.lookupSubject = mappedLookup(options.lookup, options.mapRole);\n return provider;\n}\n"],"mappings":";;;;;;;;;;;;;;AAyEA,MAAM,UAAU;;AAGhB,SAAgB,UACd,SACA,SACe;CACf,IAAI,QAAQ,WAAW,OAAO;EAC5B,MAAM,QAAQ,uBAAuB,KAAK,QAAQ,QAAQ,IAAI,eAAe,KAAK,EAAE;EACpF,IAAI,OAAO,OAAO,MAAM;CAC1B;CACA,IAAI,QAAQ,QACV,KAAK,MAAM,SAAS,QAAQ,QAAQ,IAAI,QAAQ,KAAK,IAAI,MAAM,GAAG,GAAG;EACnE,MAAM,KAAK,KAAK,QAAQ,GAAG;EAC3B,IAAI,OAAO,MAAM,KAAK,MAAM,GAAG,EAAE,EAAE,KAAK,MAAM,QAAQ,QAAQ;EAC9D,MAAM,QAAQ,KAAK,MAAM,KAAK,CAAC,EAAE,KAAK;EACtC,IAAI,CAAC,OAAO,OAAO;EACnB,IAAI;GACF,OAAO,mBAAmB,KAAK;EACjC,QAAQ;GACN,OAAO;EACT;CACF;CAEF,OAAO;AACT;;AAGA,SAAS,WAAW,QAAmB,WAAuD;CAC5F,MAAM,KAAK,YAAY,QAAQ,KAAK;CACpC,IAAI,CAAC,IAAI,OAAO;CAEhB,OAAO,SAAS;EACd;EACA,MAHW,YAAY,OAAO,aAAc,OAAO,QAAQ,OAAO;EAIlE,MAAM,YAAY,QAAQ,MAAM;EAChC,OAAO,YAAY,QAAQ,OAAO;CACpC,CAAC;AACH;;AAGA,SAAS,eAAe,MAAY,OAAyB;CAC3D,OAAO,iBAAiB,KAAK,OAAO,aAAa,EAAE,iBAAiB,KAAK,OAAO;AAClF;;;;;;;;;;;;AAaA,SAAgB,YAAY,SAAsD;CAChF,IAAI,CAAC,QAAQ,UAAU,CAAC,QAAQ,MAC9B,MAAM,IAAI,UAAU,8CAA8C;CAEpE,IAAI,QAAQ,UAAU,QAAQ,MAC5B,MAAM,IAAI,UAAU,uDAAuD;CAE7E,IAAI;CACJ,MAAM,cACH,UAAU,WAAW,QAAQ,eAAe,OAAO,OAAO,EAAE,MAAM,SAAS;EAC1E,IAAI;EACJ,IAAI,QAAQ,WAAW,KAAA,GACrB,MACE,OAAO,QAAQ,WAAW,WACtB,IAAI,YAAY,EAAE,OAAO,QAAQ,MAAM,IACvC,QAAQ;OACT,IAAI,OAAO,QAAQ,SAAS,YAAY,QAAQ,gBAAgB,KACrE,MAAM,KAAK,mBAAmB,IAAI,IAAI,QAAQ,IAAI,CAAC;OAEnD,MAAM,KAAK,kBAAkB,QAAQ,IAAgD;EAEvF,OAAO;GAAE;GAAM;EAAI;CACrB,CAAC,GAAG,OAAO,UAAmB;EAC5B,QAAQ,KAAA;EACR,MAAM;CACR,CAAC;CAEH,MAAM,aAAa,QAAQ,eAAe,QAAQ,WAAW,KAAA,IAAY,CAAC,OAAO,IAAI,KAAA;CACrF,MAAM,gBAAyC,CAAC;CAChD,IAAI,YAAY,cAAc,aAAa;CAC3C,IAAI,QAAQ,WAAW,KAAA,GAAW,cAAc,SAAS,QAAQ;CACjE,IAAI,QAAQ,aAAa,KAAA,GAAW,cAAc,WAAW,QAAQ;CACrE,IAAI,QAAQ,mBAAmB,KAAA,GAAW,cAAc,iBAAiB,QAAQ;CAEjF,MAAM,WAAoC,EACxC,MAAM,WAAW,SAAS;EACxB,MAAM,QAAQ,UAAU,SAAS,OAAO;EACxC,IAAI,CAAC,OAAO,OAAO;EACnB,MAAM,EAAE,MAAM,QAAQ,MAAM,KAAK;EACjC,IAAI;EACJ,IAAI;GACF,UAAU,MAAM,KAAK,UAAU,OAAO,KAAK,aAAa,GAAG;EAC7D,SAAS,OAAO;GACd,IAAI,eAAe,MAAM,KAAK,GAAG,OAAO;GACxC,MAAM;EACR;EACA,MAAM,SAAS,QAAQ,MACnB,QAAQ,IAAI,QAAQ,OAAO,IAC3B,WAAW,QAAQ,QAAQ,SAAS;EACxC,IAAI,CAAC,QAAQ,OAAO;EACpB,OAAO,SAAS;GAAE,GAAG;GAAQ,MAAM,eAAe,OAAO,MAAM,QAAQ,OAAO;EAAE,CAAC;CACnF,EACF;CACA,IAAI,QAAQ,WAAW,SAAS,YAAY,QAAQ;CACpD,IAAI,QAAQ,QAAQ,SAAS,gBAAgB,aAAa,QAAQ,QAAQ,QAAQ,OAAO;CACzF,OAAO;AACT"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _xtandard_kit_auth_none = require("@xtandard/kit/auth/none");
|
|
3
|
+
Object.defineProperty(exports, "ANONYMOUS_PRINCIPAL", {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: function() {
|
|
6
|
+
return _xtandard_kit_auth_none.ANONYMOUS_PRINCIPAL;
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(exports, "noAuth", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return _xtandard_kit_auth_none.noAuth;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_contract = require("./contract-Brnu9XXo.cjs");
|
|
3
|
+
const require_kit = require("./kit-BrqnCcDw.cjs");
|
|
4
|
+
//#region src/auth-provider/session.ts
|
|
5
|
+
/**
|
|
6
|
+
* A generic session getter as a {@link PermissionsAuthProvider} (ADR 0006): you say how to load the
|
|
7
|
+
* session for a request and how to read a subject from it. Covers Auth.js, Clerk, Lucia-style
|
|
8
|
+
* session tables and home-grown cookies in a few lines (recipes below and in `docs/AUTH.md`).
|
|
9
|
+
*
|
|
10
|
+
* @example Auth.js (Next.js) — the role exists only if your `jwt`/`session` callbacks copy it
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { auth } from "@/auth";
|
|
13
|
+
* sessionProvider({
|
|
14
|
+
* getSession: () => auth(),
|
|
15
|
+
* map: (s) => (s.user?.id ? { id: s.user.id, role: s.user.role, name: s.user.name, email: s.user.email } : null),
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example Auth.js (any framework, `@auth/core`)
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { Auth } from "@auth/core";
|
|
22
|
+
* sessionProvider({
|
|
23
|
+
* getSession: async (request) => {
|
|
24
|
+
* const url = new URL("/auth/session", request.url); // your Auth.js basePath
|
|
25
|
+
* const res = await Auth(new Request(url, { headers: request.headers }), authConfig);
|
|
26
|
+
* const data = await res.json();
|
|
27
|
+
* return data && Object.keys(data).length ? data : null;
|
|
28
|
+
* },
|
|
29
|
+
* map: (s) => (s.user?.id ? { id: s.user.id, role: s.user.role } : null),
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example Clerk (`@clerk/backend`) — `orgRole` is namespaced (`"org:admin"`)
|
|
34
|
+
* ```ts
|
|
35
|
+
* sessionProvider({
|
|
36
|
+
* getSession: async (request) => {
|
|
37
|
+
* const state = await clerkClient.authenticateRequest(request, { authorizedParties });
|
|
38
|
+
* return state.isAuthenticated ? state.toAuth() : null;
|
|
39
|
+
* },
|
|
40
|
+
* map: (a) => ({ id: a.userId, role: a.orgRole ?? a.sessionClaims?.metadata?.role }),
|
|
41
|
+
* mapRole: { "org:admin": "admin", "org:member": "member" },
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example Lucia-style session table
|
|
46
|
+
* ```ts
|
|
47
|
+
* sessionProvider({
|
|
48
|
+
* getSession: (request) => {
|
|
49
|
+
* const token = parseCookie(request.headers.get("cookie"))["session"];
|
|
50
|
+
* return token ? validateSessionToken(token) : null; // → { session, user } | null
|
|
51
|
+
* },
|
|
52
|
+
* map: ({ user }) => ({ id: user.id, role: user.role, email: user.email }),
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @module
|
|
57
|
+
*/
|
|
58
|
+
/** A {@link PermissionsAuthProvider} from a session getter and a mapping. */
|
|
59
|
+
function sessionProvider(options) {
|
|
60
|
+
const provider = { async getSubject(request) {
|
|
61
|
+
const session = await options.getSession(request);
|
|
62
|
+
if (session === null || session === void 0) return null;
|
|
63
|
+
const mapped = options.map(session, request);
|
|
64
|
+
if (!mapped) return null;
|
|
65
|
+
return require_contract.identity({
|
|
66
|
+
...mapped,
|
|
67
|
+
role: require_contract.normalizeRoles(mapped.role, options.mapRole)
|
|
68
|
+
});
|
|
69
|
+
} };
|
|
70
|
+
if (options.canManage) provider.canManage = options.canManage;
|
|
71
|
+
if (options.lookup) provider.lookupSubject = require_contract.mappedLookup(options.lookup, options.mapRole);
|
|
72
|
+
return provider;
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
exports.externalRoles = require_contract.externalRoles;
|
|
76
|
+
exports.identity = require_contract.identity;
|
|
77
|
+
exports.identityOf = require_kit.identityOf;
|
|
78
|
+
exports.mappedLookup = require_contract.mappedLookup;
|
|
79
|
+
exports.normalizeRoles = require_contract.normalizeRoles;
|
|
80
|
+
exports.sessionProvider = sessionProvider;
|
|
81
|
+
exports.splitRoles = require_contract.splitRoles;
|
|
82
|
+
exports.stringField = require_contract.stringField;
|
|
83
|
+
exports.subjectOf = require_kit.subjectOf;
|
|
84
|
+
exports.toKitAuth = require_kit.toKitAuth;
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=entry-auth-session.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-auth-session.cjs","names":["identity","normalizeRoles","mappedLookup"],"sources":["../src/auth-provider/session.ts"],"sourcesContent":["/**\n * A generic session getter as a {@link PermissionsAuthProvider} (ADR 0006): you say how to load the\n * session for a request and how to read a subject from it. Covers Auth.js, Clerk, Lucia-style\n * session tables and home-grown cookies in a few lines (recipes below and in `docs/AUTH.md`).\n *\n * @example Auth.js (Next.js) — the role exists only if your `jwt`/`session` callbacks copy it\n * ```ts\n * import { auth } from \"@/auth\";\n * sessionProvider({\n * getSession: () => auth(),\n * map: (s) => (s.user?.id ? { id: s.user.id, role: s.user.role, name: s.user.name, email: s.user.email } : null),\n * });\n * ```\n *\n * @example Auth.js (any framework, `@auth/core`)\n * ```ts\n * import { Auth } from \"@auth/core\";\n * sessionProvider({\n * getSession: async (request) => {\n * const url = new URL(\"/auth/session\", request.url); // your Auth.js basePath\n * const res = await Auth(new Request(url, { headers: request.headers }), authConfig);\n * const data = await res.json();\n * return data && Object.keys(data).length ? data : null;\n * },\n * map: (s) => (s.user?.id ? { id: s.user.id, role: s.user.role } : null),\n * });\n * ```\n *\n * @example Clerk (`@clerk/backend`) — `orgRole` is namespaced (`\"org:admin\"`)\n * ```ts\n * sessionProvider({\n * getSession: async (request) => {\n * const state = await clerkClient.authenticateRequest(request, { authorizedParties });\n * return state.isAuthenticated ? state.toAuth() : null;\n * },\n * map: (a) => ({ id: a.userId, role: a.orgRole ?? a.sessionClaims?.metadata?.role }),\n * mapRole: { \"org:admin\": \"admin\", \"org:member\": \"member\" },\n * });\n * ```\n *\n * @example Lucia-style session table\n * ```ts\n * sessionProvider({\n * getSession: (request) => {\n * const token = parseCookie(request.headers.get(\"cookie\"))[\"session\"];\n * return token ? validateSessionToken(token) : null; // → { session, user } | null\n * },\n * map: ({ user }) => ({ id: user.id, role: user.role, email: user.email }),\n * });\n * ```\n *\n * @module\n */\n\nimport {\n identity,\n mappedLookup,\n normalizeRoles,\n type PermissionsAuthProvider,\n type ProviderRoleOptions,\n type SubjectIdentity,\n type SubjectLookupFn,\n} from \"./contract.ts\";\n\n/** Options for {@link sessionProvider}. */\nexport interface SessionProviderOptions<S> extends ProviderRoleOptions {\n /** Load the session for a request. `null`/`undefined` = no session. Throwing = 500. */\n getSession(request: Request): S | null | undefined | Promise<S | null | undefined>;\n /**\n * Read the subject from a session. Return `null`/`undefined` when the session has no usable user\n * (e.g. an Auth.js session without `user.id`). `role` may be a string, a comma list or an array;\n * it is split and passed through `mapRole`.\n */\n map(session: S, request: Request): SubjectIdentity | null | undefined;\n /**\n * Look a subject up by id without a session (your user table, your auth library's admin API).\n * Becomes the provider's `lookupSubject`; `role` is split and mapped like `map`'s. ADR 0014.\n */\n lookup?: SubjectLookupFn;\n}\n\n/** A {@link PermissionsAuthProvider} from a session getter and a mapping. */\nexport function sessionProvider<S>(options: SessionProviderOptions<S>): PermissionsAuthProvider {\n const provider: PermissionsAuthProvider = {\n async getSubject(request) {\n const session = await options.getSession(request);\n if (session === null || session === undefined) return null;\n const mapped = options.map(session, request);\n if (!mapped) return null;\n return identity({ ...mapped, role: normalizeRoles(mapped.role, options.mapRole) });\n },\n };\n if (options.canManage) provider.canManage = options.canManage;\n if (options.lookup) provider.lookupSubject = mappedLookup(options.lookup, options.mapRole);\n return provider;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,gBAAmB,SAA6D;CAC9F,MAAM,WAAoC,EACxC,MAAM,WAAW,SAAS;EACxB,MAAM,UAAU,MAAM,QAAQ,WAAW,OAAO;EAChD,IAAI,YAAY,QAAQ,YAAY,KAAA,GAAW,OAAO;EACtD,MAAM,SAAS,QAAQ,IAAI,SAAS,OAAO;EAC3C,IAAI,CAAC,QAAQ,OAAO;EACpB,OAAOA,iBAAAA,SAAS;GAAE,GAAG;GAAQ,MAAMC,iBAAAA,eAAe,OAAO,MAAM,QAAQ,OAAO;EAAE,CAAC;CACnF,EACF;CACA,IAAI,QAAQ,WAAW,SAAS,YAAY,QAAQ;CACpD,IAAI,QAAQ,QAAQ,SAAS,gBAAgBC,iBAAAA,aAAa,QAAQ,QAAQ,QAAQ,OAAO;CACzF,OAAO;AACT"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { f as PermissionsSubject, h as SubjectIdentity } from "./catalog-DA_d1SdC.cjs";
|
|
2
|
+
import { a as externalRoles, c as normalizeRoles, i as SubjectLookupFn, l as splitRoles, n as ProviderRoleOptions, o as identity, r as RoleMapper, s as mappedLookup, t as PermissionsAuthProvider, u as stringField } from "./contract-BAisPHBw.cjs";
|
|
3
|
+
import { a as subjectOf, i as identityOf, n as KitAuthEngine, o as toKitAuth, r as ToKitAuthOptions, t as KitAuth } from "./kit-DLF7DZrp.cjs";
|
|
4
|
+
//#region src/auth-provider/session.d.ts
|
|
5
|
+
/** Options for {@link sessionProvider}. */
|
|
6
|
+
interface SessionProviderOptions<S> extends ProviderRoleOptions {
|
|
7
|
+
/** Load the session for a request. `null`/`undefined` = no session. Throwing = 500. */
|
|
8
|
+
getSession(request: Request): S | null | undefined | Promise<S | null | undefined>;
|
|
9
|
+
/**
|
|
10
|
+
* Read the subject from a session. Return `null`/`undefined` when the session has no usable user
|
|
11
|
+
* (e.g. an Auth.js session without `user.id`). `role` may be a string, a comma list or an array;
|
|
12
|
+
* it is split and passed through `mapRole`.
|
|
13
|
+
*/
|
|
14
|
+
map(session: S, request: Request): SubjectIdentity | null | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Look a subject up by id without a session (your user table, your auth library's admin API).
|
|
17
|
+
* Becomes the provider's `lookupSubject`; `role` is split and mapped like `map`'s. ADR 0014.
|
|
18
|
+
*/
|
|
19
|
+
lookup?: SubjectLookupFn;
|
|
20
|
+
}
|
|
21
|
+
/** A {@link PermissionsAuthProvider} from a session getter and a mapping. */
|
|
22
|
+
declare function sessionProvider<S>(options: SessionProviderOptions<S>): PermissionsAuthProvider;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { KitAuth, KitAuthEngine, PermissionsAuthProvider, type PermissionsSubject, ProviderRoleOptions, RoleMapper, type SessionProviderOptions, type SubjectIdentity, SubjectLookupFn, ToKitAuthOptions, externalRoles, identity, identityOf, mappedLookup, normalizeRoles, sessionProvider, splitRoles, stringField, subjectOf, toKitAuth };
|
|
25
|
+
//# sourceMappingURL=entry-auth-session.d.cts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { f as PermissionsSubject, h as SubjectIdentity } from "./catalog-DJcJ3ycq.mjs";
|
|
2
|
+
import { a as externalRoles, c as normalizeRoles, i as SubjectLookupFn, l as splitRoles, n as ProviderRoleOptions, o as identity, r as RoleMapper, s as mappedLookup, t as PermissionsAuthProvider, u as stringField } from "./contract-D6j-yrBL.mjs";
|
|
3
|
+
import { a as subjectOf, i as identityOf, n as KitAuthEngine, o as toKitAuth, r as ToKitAuthOptions, t as KitAuth } from "./kit-51JtMxsn.mjs";
|
|
4
|
+
//#region src/auth-provider/session.d.ts
|
|
5
|
+
/** Options for {@link sessionProvider}. */
|
|
6
|
+
interface SessionProviderOptions<S> extends ProviderRoleOptions {
|
|
7
|
+
/** Load the session for a request. `null`/`undefined` = no session. Throwing = 500. */
|
|
8
|
+
getSession(request: Request): S | null | undefined | Promise<S | null | undefined>;
|
|
9
|
+
/**
|
|
10
|
+
* Read the subject from a session. Return `null`/`undefined` when the session has no usable user
|
|
11
|
+
* (e.g. an Auth.js session without `user.id`). `role` may be a string, a comma list or an array;
|
|
12
|
+
* it is split and passed through `mapRole`.
|
|
13
|
+
*/
|
|
14
|
+
map(session: S, request: Request): SubjectIdentity | null | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Look a subject up by id without a session (your user table, your auth library's admin API).
|
|
17
|
+
* Becomes the provider's `lookupSubject`; `role` is split and mapped like `map`'s. ADR 0014.
|
|
18
|
+
*/
|
|
19
|
+
lookup?: SubjectLookupFn;
|
|
20
|
+
}
|
|
21
|
+
/** A {@link PermissionsAuthProvider} from a session getter and a mapping. */
|
|
22
|
+
declare function sessionProvider<S>(options: SessionProviderOptions<S>): PermissionsAuthProvider;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { KitAuth, KitAuthEngine, PermissionsAuthProvider, type PermissionsSubject, ProviderRoleOptions, RoleMapper, type SessionProviderOptions, type SubjectIdentity, SubjectLookupFn, ToKitAuthOptions, externalRoles, identity, identityOf, mappedLookup, normalizeRoles, sessionProvider, splitRoles, stringField, subjectOf, toKitAuth };
|
|
25
|
+
//# sourceMappingURL=entry-auth-session.d.mts.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { a as splitRoles, i as normalizeRoles, n as identity, o as stringField, r as mappedLookup, t as externalRoles } from "./contract-BganM0fx.mjs";
|
|
2
|
+
import { n as subjectOf, r as toKitAuth, t as identityOf } from "./kit-BM3uosfV.mjs";
|
|
3
|
+
//#region src/auth-provider/session.ts
|
|
4
|
+
/**
|
|
5
|
+
* A generic session getter as a {@link PermissionsAuthProvider} (ADR 0006): you say how to load the
|
|
6
|
+
* session for a request and how to read a subject from it. Covers Auth.js, Clerk, Lucia-style
|
|
7
|
+
* session tables and home-grown cookies in a few lines (recipes below and in `docs/AUTH.md`).
|
|
8
|
+
*
|
|
9
|
+
* @example Auth.js (Next.js) — the role exists only if your `jwt`/`session` callbacks copy it
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { auth } from "@/auth";
|
|
12
|
+
* sessionProvider({
|
|
13
|
+
* getSession: () => auth(),
|
|
14
|
+
* map: (s) => (s.user?.id ? { id: s.user.id, role: s.user.role, name: s.user.name, email: s.user.email } : null),
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @example Auth.js (any framework, `@auth/core`)
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { Auth } from "@auth/core";
|
|
21
|
+
* sessionProvider({
|
|
22
|
+
* getSession: async (request) => {
|
|
23
|
+
* const url = new URL("/auth/session", request.url); // your Auth.js basePath
|
|
24
|
+
* const res = await Auth(new Request(url, { headers: request.headers }), authConfig);
|
|
25
|
+
* const data = await res.json();
|
|
26
|
+
* return data && Object.keys(data).length ? data : null;
|
|
27
|
+
* },
|
|
28
|
+
* map: (s) => (s.user?.id ? { id: s.user.id, role: s.user.role } : null),
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example Clerk (`@clerk/backend`) — `orgRole` is namespaced (`"org:admin"`)
|
|
33
|
+
* ```ts
|
|
34
|
+
* sessionProvider({
|
|
35
|
+
* getSession: async (request) => {
|
|
36
|
+
* const state = await clerkClient.authenticateRequest(request, { authorizedParties });
|
|
37
|
+
* return state.isAuthenticated ? state.toAuth() : null;
|
|
38
|
+
* },
|
|
39
|
+
* map: (a) => ({ id: a.userId, role: a.orgRole ?? a.sessionClaims?.metadata?.role }),
|
|
40
|
+
* mapRole: { "org:admin": "admin", "org:member": "member" },
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @example Lucia-style session table
|
|
45
|
+
* ```ts
|
|
46
|
+
* sessionProvider({
|
|
47
|
+
* getSession: (request) => {
|
|
48
|
+
* const token = parseCookie(request.headers.get("cookie"))["session"];
|
|
49
|
+
* return token ? validateSessionToken(token) : null; // → { session, user } | null
|
|
50
|
+
* },
|
|
51
|
+
* map: ({ user }) => ({ id: user.id, role: user.role, email: user.email }),
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @module
|
|
56
|
+
*/
|
|
57
|
+
/** A {@link PermissionsAuthProvider} from a session getter and a mapping. */
|
|
58
|
+
function sessionProvider(options) {
|
|
59
|
+
const provider = { async getSubject(request) {
|
|
60
|
+
const session = await options.getSession(request);
|
|
61
|
+
if (session === null || session === void 0) return null;
|
|
62
|
+
const mapped = options.map(session, request);
|
|
63
|
+
if (!mapped) return null;
|
|
64
|
+
return identity({
|
|
65
|
+
...mapped,
|
|
66
|
+
role: normalizeRoles(mapped.role, options.mapRole)
|
|
67
|
+
});
|
|
68
|
+
} };
|
|
69
|
+
if (options.canManage) provider.canManage = options.canManage;
|
|
70
|
+
if (options.lookup) provider.lookupSubject = mappedLookup(options.lookup, options.mapRole);
|
|
71
|
+
return provider;
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { externalRoles, identity, identityOf, mappedLookup, normalizeRoles, sessionProvider, splitRoles, stringField, subjectOf, toKitAuth };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=entry-auth-session.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-auth-session.mjs","names":[],"sources":["../src/auth-provider/session.ts"],"sourcesContent":["/**\n * A generic session getter as a {@link PermissionsAuthProvider} (ADR 0006): you say how to load the\n * session for a request and how to read a subject from it. Covers Auth.js, Clerk, Lucia-style\n * session tables and home-grown cookies in a few lines (recipes below and in `docs/AUTH.md`).\n *\n * @example Auth.js (Next.js) — the role exists only if your `jwt`/`session` callbacks copy it\n * ```ts\n * import { auth } from \"@/auth\";\n * sessionProvider({\n * getSession: () => auth(),\n * map: (s) => (s.user?.id ? { id: s.user.id, role: s.user.role, name: s.user.name, email: s.user.email } : null),\n * });\n * ```\n *\n * @example Auth.js (any framework, `@auth/core`)\n * ```ts\n * import { Auth } from \"@auth/core\";\n * sessionProvider({\n * getSession: async (request) => {\n * const url = new URL(\"/auth/session\", request.url); // your Auth.js basePath\n * const res = await Auth(new Request(url, { headers: request.headers }), authConfig);\n * const data = await res.json();\n * return data && Object.keys(data).length ? data : null;\n * },\n * map: (s) => (s.user?.id ? { id: s.user.id, role: s.user.role } : null),\n * });\n * ```\n *\n * @example Clerk (`@clerk/backend`) — `orgRole` is namespaced (`\"org:admin\"`)\n * ```ts\n * sessionProvider({\n * getSession: async (request) => {\n * const state = await clerkClient.authenticateRequest(request, { authorizedParties });\n * return state.isAuthenticated ? state.toAuth() : null;\n * },\n * map: (a) => ({ id: a.userId, role: a.orgRole ?? a.sessionClaims?.metadata?.role }),\n * mapRole: { \"org:admin\": \"admin\", \"org:member\": \"member\" },\n * });\n * ```\n *\n * @example Lucia-style session table\n * ```ts\n * sessionProvider({\n * getSession: (request) => {\n * const token = parseCookie(request.headers.get(\"cookie\"))[\"session\"];\n * return token ? validateSessionToken(token) : null; // → { session, user } | null\n * },\n * map: ({ user }) => ({ id: user.id, role: user.role, email: user.email }),\n * });\n * ```\n *\n * @module\n */\n\nimport {\n identity,\n mappedLookup,\n normalizeRoles,\n type PermissionsAuthProvider,\n type ProviderRoleOptions,\n type SubjectIdentity,\n type SubjectLookupFn,\n} from \"./contract.ts\";\n\n/** Options for {@link sessionProvider}. */\nexport interface SessionProviderOptions<S> extends ProviderRoleOptions {\n /** Load the session for a request. `null`/`undefined` = no session. Throwing = 500. */\n getSession(request: Request): S | null | undefined | Promise<S | null | undefined>;\n /**\n * Read the subject from a session. Return `null`/`undefined` when the session has no usable user\n * (e.g. an Auth.js session without `user.id`). `role` may be a string, a comma list or an array;\n * it is split and passed through `mapRole`.\n */\n map(session: S, request: Request): SubjectIdentity | null | undefined;\n /**\n * Look a subject up by id without a session (your user table, your auth library's admin API).\n * Becomes the provider's `lookupSubject`; `role` is split and mapped like `map`'s. ADR 0014.\n */\n lookup?: SubjectLookupFn;\n}\n\n/** A {@link PermissionsAuthProvider} from a session getter and a mapping. */\nexport function sessionProvider<S>(options: SessionProviderOptions<S>): PermissionsAuthProvider {\n const provider: PermissionsAuthProvider = {\n async getSubject(request) {\n const session = await options.getSession(request);\n if (session === null || session === undefined) return null;\n const mapped = options.map(session, request);\n if (!mapped) return null;\n return identity({ ...mapped, role: normalizeRoles(mapped.role, options.mapRole) });\n },\n };\n if (options.canManage) provider.canManage = options.canManage;\n if (options.lookup) provider.lookupSubject = mappedLookup(options.lookup, options.mapRole);\n return provider;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,gBAAmB,SAA6D;CAC9F,MAAM,WAAoC,EACxC,MAAM,WAAW,SAAS;EACxB,MAAM,UAAU,MAAM,QAAQ,WAAW,OAAO;EAChD,IAAI,YAAY,QAAQ,YAAY,KAAA,GAAW,OAAO;EACtD,MAAM,SAAS,QAAQ,IAAI,SAAS,OAAO;EAC3C,IAAI,CAAC,QAAQ,OAAO;EACpB,OAAO,SAAS;GAAE,GAAG;GAAQ,MAAM,eAAe,OAAO,MAAM,QAAQ,OAAO;EAAE,CAAC;CACnF,EACF;CACA,IAAI,QAAQ,WAAW,SAAS,YAAY,QAAQ;CACpD,IAAI,QAAQ,QAAQ,SAAS,gBAAgB,aAAa,QAAQ,QAAQ,QAAQ,OAAO;CACzF,OAAO;AACT"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _xtandard_kit_authorization_delegated = require("@xtandard/kit/authorization/delegated");
|
|
3
|
+
//#region src/authorization/delegated.ts
|
|
4
|
+
/**
|
|
5
|
+
* Delegated {@link AuthorizationProvider}: wraps a decision function (sync or async) so any policy
|
|
6
|
+
* works (per-subject ownership, an external policy engine) without implementing the interface.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Create an {@link AuthorizationProvider} from a plain decision function.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { delegatedAuthorization } from "@xtandard/permissions/authorization/delegated";
|
|
16
|
+
*
|
|
17
|
+
* // Support staff may read everything but only grant on their own team's subjects.
|
|
18
|
+
* const authz = delegatedAuthorization({
|
|
19
|
+
* authorize: ({ principal, action, resource }) =>
|
|
20
|
+
* action !== "grants:write" ||
|
|
21
|
+
* ("subject" in resource && resource.subject?.startsWith(`${principal?.id}-team-`) === true),
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function delegatedAuthorization(options) {
|
|
26
|
+
return (0, _xtandard_kit_authorization_delegated.delegatedAuthorization)(options);
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.delegatedAuthorization = delegatedAuthorization;
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=entry-authorization-delegated.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-authorization-delegated.cjs","names":[],"sources":["../src/authorization/delegated.ts"],"sourcesContent":["/**\n * Delegated {@link AuthorizationProvider}: wraps a decision function (sync or async) so any policy\n * works (per-subject ownership, an external policy engine) without implementing the interface.\n *\n * @module\n */\n\nimport { delegatedAuthorization as kitDelegated } from \"@xtandard/kit/authorization/delegated\";\nimport type { AuthorizationProvider, AuthorizeInput } from \"./contract.ts\";\n\n/** Options for {@link delegatedAuthorization}. */\nexport interface DelegatedAuthorizationOptions {\n /** Return `true` to allow the {@link AuthorizeInput}. May be async. */\n authorize: (input: AuthorizeInput) => Promise<boolean> | boolean;\n}\n\n/**\n * Create an {@link AuthorizationProvider} from a plain decision function.\n *\n * @example\n * ```ts\n * import { delegatedAuthorization } from \"@xtandard/permissions/authorization/delegated\";\n *\n * // Support staff may read everything but only grant on their own team's subjects.\n * const authz = delegatedAuthorization({\n * authorize: ({ principal, action, resource }) =>\n * action !== \"grants:write\" ||\n * (\"subject\" in resource && resource.subject?.startsWith(`${principal?.id}-team-`) === true),\n * });\n * ```\n */\nexport function delegatedAuthorization(\n options: DelegatedAuthorizationOptions,\n): AuthorizationProvider {\n return kitDelegated(options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,uBACd,SACuB;CACvB,QAAA,GAAA,sCAAA,wBAAoB,OAAO;AAC7B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { n as AuthorizationProvider, r as AuthorizeInput } from "./contract-CNgMXr2u.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/authorization/delegated.d.ts
|
|
4
|
+
/** Options for {@link delegatedAuthorization}. */
|
|
5
|
+
interface DelegatedAuthorizationOptions {
|
|
6
|
+
/** Return `true` to allow the {@link AuthorizeInput}. May be async. */
|
|
7
|
+
authorize: (input: AuthorizeInput) => Promise<boolean> | boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create an {@link AuthorizationProvider} from a plain decision function.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { delegatedAuthorization } from "@xtandard/permissions/authorization/delegated";
|
|
15
|
+
*
|
|
16
|
+
* // Support staff may read everything but only grant on their own team's subjects.
|
|
17
|
+
* const authz = delegatedAuthorization({
|
|
18
|
+
* authorize: ({ principal, action, resource }) =>
|
|
19
|
+
* action !== "grants:write" ||
|
|
20
|
+
* ("subject" in resource && resource.subject?.startsWith(`${principal?.id}-team-`) === true),
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare function delegatedAuthorization(options: DelegatedAuthorizationOptions): AuthorizationProvider;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { DelegatedAuthorizationOptions, delegatedAuthorization };
|
|
27
|
+
//# sourceMappingURL=entry-authorization-delegated.d.cts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { n as AuthorizationProvider, r as AuthorizeInput } from "./contract-CNgMXr2u.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/authorization/delegated.d.ts
|
|
4
|
+
/** Options for {@link delegatedAuthorization}. */
|
|
5
|
+
interface DelegatedAuthorizationOptions {
|
|
6
|
+
/** Return `true` to allow the {@link AuthorizeInput}. May be async. */
|
|
7
|
+
authorize: (input: AuthorizeInput) => Promise<boolean> | boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create an {@link AuthorizationProvider} from a plain decision function.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { delegatedAuthorization } from "@xtandard/permissions/authorization/delegated";
|
|
15
|
+
*
|
|
16
|
+
* // Support staff may read everything but only grant on their own team's subjects.
|
|
17
|
+
* const authz = delegatedAuthorization({
|
|
18
|
+
* authorize: ({ principal, action, resource }) =>
|
|
19
|
+
* action !== "grants:write" ||
|
|
20
|
+
* ("subject" in resource && resource.subject?.startsWith(`${principal?.id}-team-`) === true),
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare function delegatedAuthorization(options: DelegatedAuthorizationOptions): AuthorizationProvider;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { DelegatedAuthorizationOptions, delegatedAuthorization };
|
|
27
|
+
//# sourceMappingURL=entry-authorization-delegated.d.mts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { delegatedAuthorization as delegatedAuthorization$1 } from "@xtandard/kit/authorization/delegated";
|
|
2
|
+
//#region src/authorization/delegated.ts
|
|
3
|
+
/**
|
|
4
|
+
* Delegated {@link AuthorizationProvider}: wraps a decision function (sync or async) so any policy
|
|
5
|
+
* works (per-subject ownership, an external policy engine) without implementing the interface.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Create an {@link AuthorizationProvider} from a plain decision function.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { delegatedAuthorization } from "@xtandard/permissions/authorization/delegated";
|
|
15
|
+
*
|
|
16
|
+
* // Support staff may read everything but only grant on their own team's subjects.
|
|
17
|
+
* const authz = delegatedAuthorization({
|
|
18
|
+
* authorize: ({ principal, action, resource }) =>
|
|
19
|
+
* action !== "grants:write" ||
|
|
20
|
+
* ("subject" in resource && resource.subject?.startsWith(`${principal?.id}-team-`) === true),
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function delegatedAuthorization(options) {
|
|
25
|
+
return delegatedAuthorization$1(options);
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { delegatedAuthorization };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=entry-authorization-delegated.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-authorization-delegated.mjs","names":["kitDelegated"],"sources":["../src/authorization/delegated.ts"],"sourcesContent":["/**\n * Delegated {@link AuthorizationProvider}: wraps a decision function (sync or async) so any policy\n * works (per-subject ownership, an external policy engine) without implementing the interface.\n *\n * @module\n */\n\nimport { delegatedAuthorization as kitDelegated } from \"@xtandard/kit/authorization/delegated\";\nimport type { AuthorizationProvider, AuthorizeInput } from \"./contract.ts\";\n\n/** Options for {@link delegatedAuthorization}. */\nexport interface DelegatedAuthorizationOptions {\n /** Return `true` to allow the {@link AuthorizeInput}. May be async. */\n authorize: (input: AuthorizeInput) => Promise<boolean> | boolean;\n}\n\n/**\n * Create an {@link AuthorizationProvider} from a plain decision function.\n *\n * @example\n * ```ts\n * import { delegatedAuthorization } from \"@xtandard/permissions/authorization/delegated\";\n *\n * // Support staff may read everything but only grant on their own team's subjects.\n * const authz = delegatedAuthorization({\n * authorize: ({ principal, action, resource }) =>\n * action !== \"grants:write\" ||\n * (\"subject\" in resource && resource.subject?.startsWith(`${principal?.id}-team-`) === true),\n * });\n * ```\n */\nexport function delegatedAuthorization(\n options: DelegatedAuthorizationOptions,\n): AuthorizationProvider {\n return kitDelegated(options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,uBACd,SACuB;CACvB,OAAOA,yBAAa,OAAO;AAC7B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _xtandard_kit_authorization_none = require("@xtandard/kit/authorization/none");
|
|
3
|
+
//#region src/authorization/none.ts
|
|
4
|
+
/**
|
|
5
|
+
* The "no authorization" {@link AuthorizationProvider}: every action is allowed, whoever asks.
|
|
6
|
+
*
|
|
7
|
+
* Right for embedded usage and local development where the admin API is not exposed to untrusted
|
|
8
|
+
* callers (commonly with `noAuth()`). Never for a network-exposed panel: use
|
|
9
|
+
* `rolesAuthorization()`, a delegated provider, or `toKitAuth(provider, perms)`.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Create an {@link AuthorizationProvider} that authorizes everything.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { noAuthorization } from "@xtandard/permissions/authorization/none";
|
|
19
|
+
*
|
|
20
|
+
* createFetchHandler({ permissions: perms, authorization: noAuthorization() });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function noAuthorization() {
|
|
24
|
+
return (0, _xtandard_kit_authorization_none.noAuthorization)();
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.noAuthorization = noAuthorization;
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=entry-authorization-none.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-authorization-none.cjs","names":[],"sources":["../src/authorization/none.ts"],"sourcesContent":["/**\n * The \"no authorization\" {@link AuthorizationProvider}: every action is allowed, whoever asks.\n *\n * Right for embedded usage and local development where the admin API is not exposed to untrusted\n * callers (commonly with `noAuth()`). Never for a network-exposed panel: use\n * `rolesAuthorization()`, a delegated provider, or `toKitAuth(provider, perms)`.\n *\n * @module\n */\n\nimport { noAuthorization as kitNoAuthorization } from \"@xtandard/kit/authorization/none\";\nimport type { AuthorizationProvider } from \"./contract.ts\";\n\n/**\n * Create an {@link AuthorizationProvider} that authorizes everything.\n *\n * @example\n * ```ts\n * import { noAuthorization } from \"@xtandard/permissions/authorization/none\";\n *\n * createFetchHandler({ permissions: perms, authorization: noAuthorization() });\n * ```\n */\nexport function noAuthorization(): AuthorizationProvider {\n return kitNoAuthorization();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,kBAAyC;CACvD,QAAA,GAAA,iCAAA,iBAA0B;AAC5B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { n as AuthorizationProvider } from "./contract-CNgMXr2u.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/authorization/none.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Create an {@link AuthorizationProvider} that authorizes everything.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { noAuthorization } from "@xtandard/permissions/authorization/none";
|
|
10
|
+
*
|
|
11
|
+
* createFetchHandler({ permissions: perms, authorization: noAuthorization() });
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
declare function noAuthorization(): AuthorizationProvider;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { noAuthorization };
|
|
17
|
+
//# sourceMappingURL=entry-authorization-none.d.cts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { n as AuthorizationProvider } from "./contract-CNgMXr2u.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/authorization/none.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Create an {@link AuthorizationProvider} that authorizes everything.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { noAuthorization } from "@xtandard/permissions/authorization/none";
|
|
10
|
+
*
|
|
11
|
+
* createFetchHandler({ permissions: perms, authorization: noAuthorization() });
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
declare function noAuthorization(): AuthorizationProvider;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { noAuthorization };
|
|
17
|
+
//# sourceMappingURL=entry-authorization-none.d.mts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { noAuthorization as noAuthorization$1 } from "@xtandard/kit/authorization/none";
|
|
2
|
+
//#region src/authorization/none.ts
|
|
3
|
+
/**
|
|
4
|
+
* The "no authorization" {@link AuthorizationProvider}: every action is allowed, whoever asks.
|
|
5
|
+
*
|
|
6
|
+
* Right for embedded usage and local development where the admin API is not exposed to untrusted
|
|
7
|
+
* callers (commonly with `noAuth()`). Never for a network-exposed panel: use
|
|
8
|
+
* `rolesAuthorization()`, a delegated provider, or `toKitAuth(provider, perms)`.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Create an {@link AuthorizationProvider} that authorizes everything.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { noAuthorization } from "@xtandard/permissions/authorization/none";
|
|
18
|
+
*
|
|
19
|
+
* createFetchHandler({ permissions: perms, authorization: noAuthorization() });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function noAuthorization() {
|
|
23
|
+
return noAuthorization$1();
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { noAuthorization };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=entry-authorization-none.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-authorization-none.mjs","names":["kitNoAuthorization"],"sources":["../src/authorization/none.ts"],"sourcesContent":["/**\n * The \"no authorization\" {@link AuthorizationProvider}: every action is allowed, whoever asks.\n *\n * Right for embedded usage and local development where the admin API is not exposed to untrusted\n * callers (commonly with `noAuth()`). Never for a network-exposed panel: use\n * `rolesAuthorization()`, a delegated provider, or `toKitAuth(provider, perms)`.\n *\n * @module\n */\n\nimport { noAuthorization as kitNoAuthorization } from \"@xtandard/kit/authorization/none\";\nimport type { AuthorizationProvider } from \"./contract.ts\";\n\n/**\n * Create an {@link AuthorizationProvider} that authorizes everything.\n *\n * @example\n * ```ts\n * import { noAuthorization } from \"@xtandard/permissions/authorization/none\";\n *\n * createFetchHandler({ permissions: perms, authorization: noAuthorization() });\n * ```\n */\nexport function noAuthorization(): AuthorizationProvider {\n return kitNoAuthorization();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,kBAAyC;CACvD,OAAOA,kBAAmB;AAC5B"}
|