@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,78 @@
|
|
|
1
|
+
import { f as PermissionsSubject, h as SubjectIdentity } from "./catalog-DA_d1SdC.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/auth-provider/contract.d.ts
|
|
4
|
+
/** Resolves the caller of a request. Implement it once per auth library. */
|
|
5
|
+
interface PermissionsAuthProvider {
|
|
6
|
+
/**
|
|
7
|
+
* Who is calling? `null` = no session (the guest role for checks, 401 for manage routes). A throw
|
|
8
|
+
* is a server error (500), never "no session". The id must not be empty.
|
|
9
|
+
*/
|
|
10
|
+
getSubject(request: Request): Promise<SubjectIdentity | null> | SubjectIdentity | null;
|
|
11
|
+
/**
|
|
12
|
+
* May this subject grant, revoke and set roles? `subject.role` is the effective role. Default:
|
|
13
|
+
* the role is one of the catalog's `managerRoles`.
|
|
14
|
+
*/
|
|
15
|
+
canManage?(subject: PermissionsSubject, request: Request): boolean | Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Look a subject up by id, without a request (ADR 0014): the provider's identity, with the role
|
|
18
|
+
* as `getSubject` would report it, or `null` for an unknown id. Pass it to the engine's
|
|
19
|
+
* `lookupSubject` so checks by id and the panel see the provider's role of any subject.
|
|
20
|
+
*/
|
|
21
|
+
lookupSubject?(id: string): Promise<SubjectIdentity | null> | SubjectIdentity | null;
|
|
22
|
+
}
|
|
23
|
+
/** A by-id lookup a provider can't do on its own (`sessionProvider` / `jwtProvider` `lookup`). */
|
|
24
|
+
type SubjectLookupFn = (id: string) => SubjectIdentity | null | undefined | Promise<SubjectIdentity | null | undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* The engine options that hand role ownership to an auth provider (ADR 0014):
|
|
27
|
+
* `{ roleSource: "external", lookupSubject }`.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const provider = betterAuthProvider(auth);
|
|
32
|
+
* const perms = createPermissions({ catalog, storage, ...externalRoles(provider) });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function externalRoles(provider: Pick<PermissionsAuthProvider, "lookupSubject">): {
|
|
36
|
+
roleSource: "external";
|
|
37
|
+
lookupSubject: ((id: string) => Promise<SubjectIdentity | null>) | undefined;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Wrap a user-supplied lookup like `getSubject`'s result: roles split and mapped, empty fields
|
|
41
|
+
* dropped. `null` for an unknown id.
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
declare function mappedLookup(lookup: SubjectLookupFn, mapRole: RoleMapper | undefined): (id: string) => Promise<SubjectIdentity | null>;
|
|
45
|
+
/**
|
|
46
|
+
* Renames raw roles from the auth library before the catalog parses them: a map
|
|
47
|
+
* (`{ user: "member", "org:admin": "admin" }`, unmapped roles pass through) or a function
|
|
48
|
+
* (return `null`/`undefined` to drop a role).
|
|
49
|
+
*/
|
|
50
|
+
type RoleMapper = Readonly<Record<string, string>> | ((role: string) => string | null | undefined);
|
|
51
|
+
/** Options every bundled provider accepts. */
|
|
52
|
+
interface ProviderRoleOptions {
|
|
53
|
+
/** Rename the library's roles to catalog roles. */
|
|
54
|
+
mapRole?: RoleMapper;
|
|
55
|
+
/** Override who may manage grants (see {@link PermissionsAuthProvider.canManage}). */
|
|
56
|
+
canManage?: PermissionsAuthProvider["canManage"];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Normalize a raw role value: a string is split on commas (better-auth stores `"admin,user"`), an
|
|
60
|
+
* array is flattened the same way, entries are trimmed and empties dropped. Non-strings are
|
|
61
|
+
* ignored.
|
|
62
|
+
*/
|
|
63
|
+
declare function splitRoles(raw: unknown): string[];
|
|
64
|
+
/** {@link splitRoles} then {@link RoleMapper}; `null` when nothing is left. */
|
|
65
|
+
declare function normalizeRoles(raw: unknown, mapRole?: RoleMapper): string[] | null;
|
|
66
|
+
/** A string field of an unknown record, or `undefined`. */
|
|
67
|
+
declare function stringField(source: unknown, key: string): string | undefined;
|
|
68
|
+
/** Build an identity, leaving out empty optional fields (exactOptionalPropertyTypes-friendly). */
|
|
69
|
+
declare function identity(fields: {
|
|
70
|
+
id: string;
|
|
71
|
+
role?: string | readonly string[] | null | undefined;
|
|
72
|
+
name?: string | null | undefined;
|
|
73
|
+
email?: string | null | undefined;
|
|
74
|
+
attributes?: Record<string, unknown> | undefined;
|
|
75
|
+
}): SubjectIdentity;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { externalRoles as a, normalizeRoles as c, SubjectLookupFn as i, splitRoles as l, ProviderRoleOptions as n, identity as o, RoleMapper as r, mappedLookup as s, PermissionsAuthProvider as t, stringField as u };
|
|
78
|
+
//# sourceMappingURL=contract-BAisPHBw.d.cts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//#region src/auth-provider/contract.ts
|
|
2
|
+
/**
|
|
3
|
+
* The engine options that hand role ownership to an auth provider (ADR 0014):
|
|
4
|
+
* `{ roleSource: "external", lookupSubject }`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const provider = betterAuthProvider(auth);
|
|
9
|
+
* const perms = createPermissions({ catalog, storage, ...externalRoles(provider) });
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
function externalRoles(provider) {
|
|
13
|
+
const lookup = provider.lookupSubject;
|
|
14
|
+
return {
|
|
15
|
+
roleSource: "external",
|
|
16
|
+
lookupSubject: lookup ? async (id) => await lookup.call(provider, id) ?? null : void 0
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Wrap a user-supplied lookup like `getSubject`'s result: roles split and mapped, empty fields
|
|
21
|
+
* dropped. `null` for an unknown id.
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
function mappedLookup(lookup, mapRole) {
|
|
25
|
+
return async (id) => {
|
|
26
|
+
const found = await lookup(id);
|
|
27
|
+
if (!found || typeof found.id !== "string" || found.id === "") return null;
|
|
28
|
+
return identity({
|
|
29
|
+
...found,
|
|
30
|
+
role: normalizeRoles(found.role, mapRole)
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Normalize a raw role value: a string is split on commas (better-auth stores `"admin,user"`), an
|
|
36
|
+
* array is flattened the same way, entries are trimmed and empties dropped. Non-strings are
|
|
37
|
+
* ignored.
|
|
38
|
+
*/
|
|
39
|
+
function splitRoles(raw) {
|
|
40
|
+
const out = [];
|
|
41
|
+
const add = (value) => {
|
|
42
|
+
if (typeof value !== "string") return;
|
|
43
|
+
for (const part of value.split(",")) {
|
|
44
|
+
const role = part.trim();
|
|
45
|
+
if (role) out.push(role);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
if (Array.isArray(raw)) for (const value of raw) add(value);
|
|
49
|
+
else add(raw);
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
/** {@link splitRoles} then {@link RoleMapper}; `null` when nothing is left. */
|
|
53
|
+
function normalizeRoles(raw, mapRole) {
|
|
54
|
+
const roles = [];
|
|
55
|
+
for (const role of splitRoles(raw)) {
|
|
56
|
+
const mapped = mapRole === void 0 ? role : typeof mapRole === "function" ? mapRole(role) : Object.hasOwn(mapRole, role) ? mapRole[role] : role;
|
|
57
|
+
if (typeof mapped === "string" && mapped !== "" && !roles.includes(mapped)) roles.push(mapped);
|
|
58
|
+
}
|
|
59
|
+
return roles.length ? roles : null;
|
|
60
|
+
}
|
|
61
|
+
/** A string field of an unknown record, or `undefined`. */
|
|
62
|
+
function stringField(source, key) {
|
|
63
|
+
if (!source || typeof source !== "object") return void 0;
|
|
64
|
+
const value = source[key];
|
|
65
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
66
|
+
}
|
|
67
|
+
/** Build an identity, leaving out empty optional fields (exactOptionalPropertyTypes-friendly). */
|
|
68
|
+
function identity(fields) {
|
|
69
|
+
const out = { id: fields.id };
|
|
70
|
+
if (fields.role !== void 0) out.role = fields.role;
|
|
71
|
+
if (fields.name) out.name = fields.name;
|
|
72
|
+
if (fields.email) out.email = fields.email;
|
|
73
|
+
if (fields.attributes && Object.keys(fields.attributes).length) out.attributes = fields.attributes;
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { splitRoles as a, normalizeRoles as i, identity as n, stringField as o, mappedLookup as r, externalRoles as t };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=contract-BganM0fx.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-BganM0fx.mjs","names":[],"sources":["../src/auth-provider/contract.ts"],"sourcesContent":["/**\n * The auth provider contract (ADR 0006). Answers two questions for the engine, the panel and the\n * router: \"who is calling, and what role does their auth library give them?\" and \"may they manage\n * grants?\".\n *\n * `@xtandard/permissions` ships `auth/better-auth`, `auth/session` and `auth/jwt` implementations;\n * any object satisfying {@link PermissionsAuthProvider} works. {@link toKitAuth} adapts one to the\n * kit's `AuthProvider` + `AuthorizationProvider`.\n *\n * @module\n */\n\nimport type { PermissionsSubject, SubjectIdentity } from \"../catalog.ts\";\n\nexport type { PermissionsSubject, SubjectIdentity };\n\n/** Resolves the caller of a request. Implement it once per auth library. */\nexport interface PermissionsAuthProvider {\n /**\n * Who is calling? `null` = no session (the guest role for checks, 401 for manage routes). A throw\n * is a server error (500), never \"no session\". The id must not be empty.\n */\n getSubject(request: Request): Promise<SubjectIdentity | null> | SubjectIdentity | null;\n /**\n * May this subject grant, revoke and set roles? `subject.role` is the effective role. Default:\n * the role is one of the catalog's `managerRoles`.\n */\n canManage?(subject: PermissionsSubject, request: Request): boolean | Promise<boolean>;\n /**\n * Look a subject up by id, without a request (ADR 0014): the provider's identity, with the role\n * as `getSubject` would report it, or `null` for an unknown id. Pass it to the engine's\n * `lookupSubject` so checks by id and the panel see the provider's role of any subject.\n */\n lookupSubject?(id: string): Promise<SubjectIdentity | null> | SubjectIdentity | null;\n}\n\n/** A by-id lookup a provider can't do on its own (`sessionProvider` / `jwtProvider` `lookup`). */\nexport type SubjectLookupFn = (\n id: string,\n) => SubjectIdentity | null | undefined | Promise<SubjectIdentity | null | undefined>;\n\n/**\n * The engine options that hand role ownership to an auth provider (ADR 0014):\n * `{ roleSource: \"external\", lookupSubject }`.\n *\n * @example\n * ```ts\n * const provider = betterAuthProvider(auth);\n * const perms = createPermissions({ catalog, storage, ...externalRoles(provider) });\n * ```\n */\nexport function externalRoles(provider: Pick<PermissionsAuthProvider, \"lookupSubject\">): {\n roleSource: \"external\";\n lookupSubject: ((id: string) => Promise<SubjectIdentity | null>) | undefined;\n} {\n const lookup = provider.lookupSubject;\n return {\n roleSource: \"external\",\n lookupSubject: lookup ? async (id) => (await lookup.call(provider, id)) ?? null : undefined,\n };\n}\n\n/**\n * Wrap a user-supplied lookup like `getSubject`'s result: roles split and mapped, empty fields\n * dropped. `null` for an unknown id.\n * @internal\n */\nexport function mappedLookup(\n lookup: SubjectLookupFn,\n mapRole: RoleMapper | undefined,\n): (id: string) => Promise<SubjectIdentity | null> {\n return async (id) => {\n const found = await lookup(id);\n if (!found || typeof found.id !== \"string\" || found.id === \"\") return null;\n return identity({ ...found, role: normalizeRoles(found.role, mapRole) });\n };\n}\n\n/**\n * Renames raw roles from the auth library before the catalog parses them: a map\n * (`{ user: \"member\", \"org:admin\": \"admin\" }`, unmapped roles pass through) or a function\n * (return `null`/`undefined` to drop a role).\n */\nexport type RoleMapper =\n | Readonly<Record<string, string>>\n | ((role: string) => string | null | undefined);\n\n/** Options every bundled provider accepts. */\nexport interface ProviderRoleOptions {\n /** Rename the library's roles to catalog roles. */\n mapRole?: RoleMapper;\n /** Override who may manage grants (see {@link PermissionsAuthProvider.canManage}). */\n canManage?: PermissionsAuthProvider[\"canManage\"];\n}\n\n/**\n * Normalize a raw role value: a string is split on commas (better-auth stores `\"admin,user\"`), an\n * array is flattened the same way, entries are trimmed and empties dropped. Non-strings are\n * ignored.\n */\nexport function splitRoles(raw: unknown): string[] {\n const out: string[] = [];\n const add = (value: unknown) => {\n if (typeof value !== \"string\") return;\n for (const part of value.split(\",\")) {\n const role = part.trim();\n if (role) out.push(role);\n }\n };\n if (Array.isArray(raw)) for (const value of raw) add(value);\n else add(raw);\n return out;\n}\n\n/** {@link splitRoles} then {@link RoleMapper}; `null` when nothing is left. */\nexport function normalizeRoles(raw: unknown, mapRole?: RoleMapper): string[] | null {\n const roles: string[] = [];\n for (const role of splitRoles(raw)) {\n const mapped =\n mapRole === undefined\n ? role\n : typeof mapRole === \"function\"\n ? mapRole(role)\n : Object.hasOwn(mapRole, role)\n ? mapRole[role]\n : role;\n if (typeof mapped === \"string\" && mapped !== \"\" && !roles.includes(mapped)) roles.push(mapped);\n }\n return roles.length ? roles : null;\n}\n\n/** A string field of an unknown record, or `undefined`. */\nexport function stringField(source: unknown, key: string): string | undefined {\n if (!source || typeof source !== \"object\") return undefined;\n const value = (source as Record<string, unknown>)[key];\n return typeof value === \"string\" && value !== \"\" ? value : undefined;\n}\n\n/** Build an identity, leaving out empty optional fields (exactOptionalPropertyTypes-friendly). */\nexport function identity(fields: {\n id: string;\n role?: string | readonly string[] | null | undefined;\n name?: string | null | undefined;\n email?: string | null | undefined;\n attributes?: Record<string, unknown> | undefined;\n}): SubjectIdentity {\n const out: SubjectIdentity = { id: fields.id };\n if (fields.role !== undefined) out.role = fields.role;\n if (fields.name) out.name = fields.name;\n if (fields.email) out.email = fields.email;\n if (fields.attributes && Object.keys(fields.attributes).length) {\n out.attributes = fields.attributes;\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;AAmDA,SAAgB,cAAc,UAG5B;CACA,MAAM,SAAS,SAAS;CACxB,OAAO;EACL,YAAY;EACZ,eAAe,SAAS,OAAO,OAAQ,MAAM,OAAO,KAAK,UAAU,EAAE,KAAM,OAAO,KAAA;CACpF;AACF;;;;;;AAOA,SAAgB,aACd,QACA,SACiD;CACjD,OAAO,OAAO,OAAO;EACnB,MAAM,QAAQ,MAAM,OAAO,EAAE;EAC7B,IAAI,CAAC,SAAS,OAAO,MAAM,OAAO,YAAY,MAAM,OAAO,IAAI,OAAO;EACtE,OAAO,SAAS;GAAE,GAAG;GAAO,MAAM,eAAe,MAAM,MAAM,OAAO;EAAE,CAAC;CACzE;AACF;;;;;;AAwBA,SAAgB,WAAW,KAAwB;CACjD,MAAM,MAAgB,CAAC;CACvB,MAAM,OAAO,UAAmB;EAC9B,IAAI,OAAO,UAAU,UAAU;EAC/B,KAAK,MAAM,QAAQ,MAAM,MAAM,GAAG,GAAG;GACnC,MAAM,OAAO,KAAK,KAAK;GACvB,IAAI,MAAM,IAAI,KAAK,IAAI;EACzB;CACF;CACA,IAAI,MAAM,QAAQ,GAAG,GAAG,KAAK,MAAM,SAAS,KAAK,IAAI,KAAK;MACrD,IAAI,GAAG;CACZ,OAAO;AACT;;AAGA,SAAgB,eAAe,KAAc,SAAuC;CAClF,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,QAAQ,WAAW,GAAG,GAAG;EAClC,MAAM,SACJ,YAAY,KAAA,IACR,OACA,OAAO,YAAY,aACjB,QAAQ,IAAI,IACZ,OAAO,OAAO,SAAS,IAAI,IACzB,QAAQ,QACR;EACV,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,KAAK,MAAM;CAC/F;CACA,OAAO,MAAM,SAAS,QAAQ;AAChC;;AAGA,SAAgB,YAAY,QAAiB,KAAiC;CAC5E,IAAI,CAAC,UAAU,OAAO,WAAW,UAAU,OAAO,KAAA;CAClD,MAAM,QAAS,OAAmC;CAClD,OAAO,OAAO,UAAU,YAAY,UAAU,KAAK,QAAQ,KAAA;AAC7D;;AAGA,SAAgB,SAAS,QAML;CAClB,MAAM,MAAuB,EAAE,IAAI,OAAO,GAAG;CAC7C,IAAI,OAAO,SAAS,KAAA,GAAW,IAAI,OAAO,OAAO;CACjD,IAAI,OAAO,MAAM,IAAI,OAAO,OAAO;CACnC,IAAI,OAAO,OAAO,IAAI,QAAQ,OAAO;CACrC,IAAI,OAAO,cAAc,OAAO,KAAK,OAAO,UAAU,EAAE,QACtD,IAAI,aAAa,OAAO;CAE1B,OAAO;AACT"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const require_chunk = require("./chunk-DakpK96I.cjs");
|
|
2
|
+
let _xtandard_kit_authorization = require("@xtandard/kit/authorization");
|
|
3
|
+
//#region src/authorization/contract.ts
|
|
4
|
+
/**
|
|
5
|
+
* Authorization contract for the panel's HTTP API (ADR 0008). Answers: "Can this principal perform
|
|
6
|
+
* this action on this resource?"
|
|
7
|
+
*
|
|
8
|
+
* Every admin route consults the {@link AuthorizationProvider} with one {@link PermissionsAction}
|
|
9
|
+
* and the {@link PermissionsResource} it targets. The runtime routes (`GET /api/me`,
|
|
10
|
+
* `POST /api/me/check`) need only an authenticated principal and never reach the provider.
|
|
11
|
+
* Ships `none` / `roles` / `delegated` implementations (the kit's, with this product's actions).
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
var contract_exports = /* @__PURE__ */ require_chunk.__exportAll({
|
|
16
|
+
ALL_ACTIONS: () => ALL_ACTIONS,
|
|
17
|
+
MUTATING_ACTIONS: () => MUTATING_ACTIONS,
|
|
18
|
+
isMutatingAction: () => isMutatingAction
|
|
19
|
+
});
|
|
20
|
+
const ACTIONS = (0, _xtandard_kit_authorization.defineActions)({
|
|
21
|
+
all: [
|
|
22
|
+
"catalog:read",
|
|
23
|
+
"subjects:read",
|
|
24
|
+
"grants:read",
|
|
25
|
+
"history:read",
|
|
26
|
+
"check:run",
|
|
27
|
+
"relationships:read",
|
|
28
|
+
"grants:write",
|
|
29
|
+
"roles:write",
|
|
30
|
+
"relationships:write"
|
|
31
|
+
],
|
|
32
|
+
mutating: [
|
|
33
|
+
"grants:write",
|
|
34
|
+
"roles:write",
|
|
35
|
+
"relationships:write"
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
/** Every action, in a stable order (role presets, docs, the UI). */
|
|
39
|
+
const ALL_ACTIONS = ACTIONS.ALL_ACTIONS;
|
|
40
|
+
/** Actions that write state: blocked (423) when the panel is readonly. */
|
|
41
|
+
const MUTATING_ACTIONS = ACTIONS.MUTATING_ACTIONS;
|
|
42
|
+
/** True if the action writes state. */
|
|
43
|
+
const isMutatingAction = (action) => ACTIONS.isMutatingAction(action);
|
|
44
|
+
//#endregion
|
|
45
|
+
Object.defineProperty(exports, "ALL_ACTIONS", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function() {
|
|
48
|
+
return ALL_ACTIONS;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, "MUTATING_ACTIONS", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function() {
|
|
54
|
+
return MUTATING_ACTIONS;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(exports, "contract_exports", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function() {
|
|
60
|
+
return contract_exports;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(exports, "isMutatingAction", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function() {
|
|
66
|
+
return isMutatingAction;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=contract-Bpy8yPrS.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-Bpy8yPrS.cjs","names":[],"sources":["../src/authorization/contract.ts"],"sourcesContent":["/**\n * Authorization contract for the panel's HTTP API (ADR 0008). Answers: \"Can this principal perform\n * this action on this resource?\"\n *\n * Every admin route consults the {@link AuthorizationProvider} with one {@link PermissionsAction}\n * and the {@link PermissionsResource} it targets. The runtime routes (`GET /api/me`,\n * `POST /api/me/check`) need only an authenticated principal and never reach the provider.\n * Ships `none` / `roles` / `delegated` implementations (the kit's, with this product's actions).\n *\n * @module\n */\n\nimport {\n defineActions,\n type AuthorizationProvider as KitAuthorizationProvider,\n type AuthorizeInput as KitAuthorizeInput,\n} from \"@xtandard/kit/authorization\";\n\nconst ACTIONS = defineActions({\n all: [\n \"catalog:read\",\n \"subjects:read\",\n \"grants:read\",\n \"history:read\",\n \"check:run\",\n \"relationships:read\",\n \"grants:write\",\n \"roles:write\",\n \"relationships:write\",\n ],\n mutating: [\"grants:write\", \"roles:write\", \"relationships:write\"],\n});\n\n/** The full set of authorizable actions. */\nexport type PermissionsAction = (typeof ACTIONS.ALL_ACTIONS)[number];\n\n/**\n * The resource an action targets. `subject` is absent on collection routes (list subjects, every\n * grant, global history).\n */\nexport type PermissionsResource =\n | { type: \"catalog\" }\n | { type: \"subject\"; subject?: string }\n | { type: \"grant\"; subject?: string; permission?: string }\n | { type: \"history\"; subject?: string }\n | { type: \"check\"; subject?: string | null; role?: string; path?: string }\n | { type: \"relationship\"; object?: string; relation?: string; subject?: string };\n\n/** Input passed to {@link AuthorizationProvider.authorize}. */\nexport type AuthorizeInput = KitAuthorizeInput<PermissionsAction, PermissionsResource>;\n\n/** Decides whether an action is permitted. */\nexport type AuthorizationProvider = KitAuthorizationProvider<\n PermissionsAction,\n PermissionsResource\n>;\n\n/** Every action, in a stable order (role presets, docs, the UI). */\nexport const ALL_ACTIONS: readonly PermissionsAction[] = ACTIONS.ALL_ACTIONS;\n\n/** Actions that write state: blocked (423) when the panel is readonly. */\nexport const MUTATING_ACTIONS: ReadonlySet<PermissionsAction> = ACTIONS.MUTATING_ACTIONS;\n\n/** True if the action writes state. */\nexport const isMutatingAction = (action: PermissionsAction): boolean =>\n ACTIONS.isMutatingAction(action);\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,MAAM,WAAA,GAAA,4BAAA,eAAwB;CAC5B,KAAK;EACH;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,UAAU;EAAC;EAAgB;EAAe;CAAqB;AACjE,CAAC;;AA2BD,MAAa,cAA4C,QAAQ;;AAGjE,MAAa,mBAAmD,QAAQ;;AAGxE,MAAa,oBAAoB,WAC/B,QAAQ,iBAAiB,MAAM"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
//#region src/auth-provider/contract.ts
|
|
2
|
+
/**
|
|
3
|
+
* The engine options that hand role ownership to an auth provider (ADR 0014):
|
|
4
|
+
* `{ roleSource: "external", lookupSubject }`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const provider = betterAuthProvider(auth);
|
|
9
|
+
* const perms = createPermissions({ catalog, storage, ...externalRoles(provider) });
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
function externalRoles(provider) {
|
|
13
|
+
const lookup = provider.lookupSubject;
|
|
14
|
+
return {
|
|
15
|
+
roleSource: "external",
|
|
16
|
+
lookupSubject: lookup ? async (id) => await lookup.call(provider, id) ?? null : void 0
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Wrap a user-supplied lookup like `getSubject`'s result: roles split and mapped, empty fields
|
|
21
|
+
* dropped. `null` for an unknown id.
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
function mappedLookup(lookup, mapRole) {
|
|
25
|
+
return async (id) => {
|
|
26
|
+
const found = await lookup(id);
|
|
27
|
+
if (!found || typeof found.id !== "string" || found.id === "") return null;
|
|
28
|
+
return identity({
|
|
29
|
+
...found,
|
|
30
|
+
role: normalizeRoles(found.role, mapRole)
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Normalize a raw role value: a string is split on commas (better-auth stores `"admin,user"`), an
|
|
36
|
+
* array is flattened the same way, entries are trimmed and empties dropped. Non-strings are
|
|
37
|
+
* ignored.
|
|
38
|
+
*/
|
|
39
|
+
function splitRoles(raw) {
|
|
40
|
+
const out = [];
|
|
41
|
+
const add = (value) => {
|
|
42
|
+
if (typeof value !== "string") return;
|
|
43
|
+
for (const part of value.split(",")) {
|
|
44
|
+
const role = part.trim();
|
|
45
|
+
if (role) out.push(role);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
if (Array.isArray(raw)) for (const value of raw) add(value);
|
|
49
|
+
else add(raw);
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
/** {@link splitRoles} then {@link RoleMapper}; `null` when nothing is left. */
|
|
53
|
+
function normalizeRoles(raw, mapRole) {
|
|
54
|
+
const roles = [];
|
|
55
|
+
for (const role of splitRoles(raw)) {
|
|
56
|
+
const mapped = mapRole === void 0 ? role : typeof mapRole === "function" ? mapRole(role) : Object.hasOwn(mapRole, role) ? mapRole[role] : role;
|
|
57
|
+
if (typeof mapped === "string" && mapped !== "" && !roles.includes(mapped)) roles.push(mapped);
|
|
58
|
+
}
|
|
59
|
+
return roles.length ? roles : null;
|
|
60
|
+
}
|
|
61
|
+
/** A string field of an unknown record, or `undefined`. */
|
|
62
|
+
function stringField(source, key) {
|
|
63
|
+
if (!source || typeof source !== "object") return void 0;
|
|
64
|
+
const value = source[key];
|
|
65
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
66
|
+
}
|
|
67
|
+
/** Build an identity, leaving out empty optional fields (exactOptionalPropertyTypes-friendly). */
|
|
68
|
+
function identity(fields) {
|
|
69
|
+
const out = { id: fields.id };
|
|
70
|
+
if (fields.role !== void 0) out.role = fields.role;
|
|
71
|
+
if (fields.name) out.name = fields.name;
|
|
72
|
+
if (fields.email) out.email = fields.email;
|
|
73
|
+
if (fields.attributes && Object.keys(fields.attributes).length) out.attributes = fields.attributes;
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
Object.defineProperty(exports, "externalRoles", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function() {
|
|
80
|
+
return externalRoles;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
Object.defineProperty(exports, "identity", {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function() {
|
|
86
|
+
return identity;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(exports, "mappedLookup", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
get: function() {
|
|
92
|
+
return mappedLookup;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(exports, "normalizeRoles", {
|
|
96
|
+
enumerable: true,
|
|
97
|
+
get: function() {
|
|
98
|
+
return normalizeRoles;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(exports, "splitRoles", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
get: function() {
|
|
104
|
+
return splitRoles;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(exports, "stringField", {
|
|
108
|
+
enumerable: true,
|
|
109
|
+
get: function() {
|
|
110
|
+
return stringField;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=contract-Brnu9XXo.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-Brnu9XXo.cjs","names":[],"sources":["../src/auth-provider/contract.ts"],"sourcesContent":["/**\n * The auth provider contract (ADR 0006). Answers two questions for the engine, the panel and the\n * router: \"who is calling, and what role does their auth library give them?\" and \"may they manage\n * grants?\".\n *\n * `@xtandard/permissions` ships `auth/better-auth`, `auth/session` and `auth/jwt` implementations;\n * any object satisfying {@link PermissionsAuthProvider} works. {@link toKitAuth} adapts one to the\n * kit's `AuthProvider` + `AuthorizationProvider`.\n *\n * @module\n */\n\nimport type { PermissionsSubject, SubjectIdentity } from \"../catalog.ts\";\n\nexport type { PermissionsSubject, SubjectIdentity };\n\n/** Resolves the caller of a request. Implement it once per auth library. */\nexport interface PermissionsAuthProvider {\n /**\n * Who is calling? `null` = no session (the guest role for checks, 401 for manage routes). A throw\n * is a server error (500), never \"no session\". The id must not be empty.\n */\n getSubject(request: Request): Promise<SubjectIdentity | null> | SubjectIdentity | null;\n /**\n * May this subject grant, revoke and set roles? `subject.role` is the effective role. Default:\n * the role is one of the catalog's `managerRoles`.\n */\n canManage?(subject: PermissionsSubject, request: Request): boolean | Promise<boolean>;\n /**\n * Look a subject up by id, without a request (ADR 0014): the provider's identity, with the role\n * as `getSubject` would report it, or `null` for an unknown id. Pass it to the engine's\n * `lookupSubject` so checks by id and the panel see the provider's role of any subject.\n */\n lookupSubject?(id: string): Promise<SubjectIdentity | null> | SubjectIdentity | null;\n}\n\n/** A by-id lookup a provider can't do on its own (`sessionProvider` / `jwtProvider` `lookup`). */\nexport type SubjectLookupFn = (\n id: string,\n) => SubjectIdentity | null | undefined | Promise<SubjectIdentity | null | undefined>;\n\n/**\n * The engine options that hand role ownership to an auth provider (ADR 0014):\n * `{ roleSource: \"external\", lookupSubject }`.\n *\n * @example\n * ```ts\n * const provider = betterAuthProvider(auth);\n * const perms = createPermissions({ catalog, storage, ...externalRoles(provider) });\n * ```\n */\nexport function externalRoles(provider: Pick<PermissionsAuthProvider, \"lookupSubject\">): {\n roleSource: \"external\";\n lookupSubject: ((id: string) => Promise<SubjectIdentity | null>) | undefined;\n} {\n const lookup = provider.lookupSubject;\n return {\n roleSource: \"external\",\n lookupSubject: lookup ? async (id) => (await lookup.call(provider, id)) ?? null : undefined,\n };\n}\n\n/**\n * Wrap a user-supplied lookup like `getSubject`'s result: roles split and mapped, empty fields\n * dropped. `null` for an unknown id.\n * @internal\n */\nexport function mappedLookup(\n lookup: SubjectLookupFn,\n mapRole: RoleMapper | undefined,\n): (id: string) => Promise<SubjectIdentity | null> {\n return async (id) => {\n const found = await lookup(id);\n if (!found || typeof found.id !== \"string\" || found.id === \"\") return null;\n return identity({ ...found, role: normalizeRoles(found.role, mapRole) });\n };\n}\n\n/**\n * Renames raw roles from the auth library before the catalog parses them: a map\n * (`{ user: \"member\", \"org:admin\": \"admin\" }`, unmapped roles pass through) or a function\n * (return `null`/`undefined` to drop a role).\n */\nexport type RoleMapper =\n | Readonly<Record<string, string>>\n | ((role: string) => string | null | undefined);\n\n/** Options every bundled provider accepts. */\nexport interface ProviderRoleOptions {\n /** Rename the library's roles to catalog roles. */\n mapRole?: RoleMapper;\n /** Override who may manage grants (see {@link PermissionsAuthProvider.canManage}). */\n canManage?: PermissionsAuthProvider[\"canManage\"];\n}\n\n/**\n * Normalize a raw role value: a string is split on commas (better-auth stores `\"admin,user\"`), an\n * array is flattened the same way, entries are trimmed and empties dropped. Non-strings are\n * ignored.\n */\nexport function splitRoles(raw: unknown): string[] {\n const out: string[] = [];\n const add = (value: unknown) => {\n if (typeof value !== \"string\") return;\n for (const part of value.split(\",\")) {\n const role = part.trim();\n if (role) out.push(role);\n }\n };\n if (Array.isArray(raw)) for (const value of raw) add(value);\n else add(raw);\n return out;\n}\n\n/** {@link splitRoles} then {@link RoleMapper}; `null` when nothing is left. */\nexport function normalizeRoles(raw: unknown, mapRole?: RoleMapper): string[] | null {\n const roles: string[] = [];\n for (const role of splitRoles(raw)) {\n const mapped =\n mapRole === undefined\n ? role\n : typeof mapRole === \"function\"\n ? mapRole(role)\n : Object.hasOwn(mapRole, role)\n ? mapRole[role]\n : role;\n if (typeof mapped === \"string\" && mapped !== \"\" && !roles.includes(mapped)) roles.push(mapped);\n }\n return roles.length ? roles : null;\n}\n\n/** A string field of an unknown record, or `undefined`. */\nexport function stringField(source: unknown, key: string): string | undefined {\n if (!source || typeof source !== \"object\") return undefined;\n const value = (source as Record<string, unknown>)[key];\n return typeof value === \"string\" && value !== \"\" ? value : undefined;\n}\n\n/** Build an identity, leaving out empty optional fields (exactOptionalPropertyTypes-friendly). */\nexport function identity(fields: {\n id: string;\n role?: string | readonly string[] | null | undefined;\n name?: string | null | undefined;\n email?: string | null | undefined;\n attributes?: Record<string, unknown> | undefined;\n}): SubjectIdentity {\n const out: SubjectIdentity = { id: fields.id };\n if (fields.role !== undefined) out.role = fields.role;\n if (fields.name) out.name = fields.name;\n if (fields.email) out.email = fields.email;\n if (fields.attributes && Object.keys(fields.attributes).length) {\n out.attributes = fields.attributes;\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;AAmDA,SAAgB,cAAc,UAG5B;CACA,MAAM,SAAS,SAAS;CACxB,OAAO;EACL,YAAY;EACZ,eAAe,SAAS,OAAO,OAAQ,MAAM,OAAO,KAAK,UAAU,EAAE,KAAM,OAAO,KAAA;CACpF;AACF;;;;;;AAOA,SAAgB,aACd,QACA,SACiD;CACjD,OAAO,OAAO,OAAO;EACnB,MAAM,QAAQ,MAAM,OAAO,EAAE;EAC7B,IAAI,CAAC,SAAS,OAAO,MAAM,OAAO,YAAY,MAAM,OAAO,IAAI,OAAO;EACtE,OAAO,SAAS;GAAE,GAAG;GAAO,MAAM,eAAe,MAAM,MAAM,OAAO;EAAE,CAAC;CACzE;AACF;;;;;;AAwBA,SAAgB,WAAW,KAAwB;CACjD,MAAM,MAAgB,CAAC;CACvB,MAAM,OAAO,UAAmB;EAC9B,IAAI,OAAO,UAAU,UAAU;EAC/B,KAAK,MAAM,QAAQ,MAAM,MAAM,GAAG,GAAG;GACnC,MAAM,OAAO,KAAK,KAAK;GACvB,IAAI,MAAM,IAAI,KAAK,IAAI;EACzB;CACF;CACA,IAAI,MAAM,QAAQ,GAAG,GAAG,KAAK,MAAM,SAAS,KAAK,IAAI,KAAK;MACrD,IAAI,GAAG;CACZ,OAAO;AACT;;AAGA,SAAgB,eAAe,KAAc,SAAuC;CAClF,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,QAAQ,WAAW,GAAG,GAAG;EAClC,MAAM,SACJ,YAAY,KAAA,IACR,OACA,OAAO,YAAY,aACjB,QAAQ,IAAI,IACZ,OAAO,OAAO,SAAS,IAAI,IACzB,QAAQ,QACR;EACV,IAAI,OAAO,WAAW,YAAY,WAAW,MAAM,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,KAAK,MAAM;CAC/F;CACA,OAAO,MAAM,SAAS,QAAQ;AAChC;;AAGA,SAAgB,YAAY,QAAiB,KAAiC;CAC5E,IAAI,CAAC,UAAU,OAAO,WAAW,UAAU,OAAO,KAAA;CAClD,MAAM,QAAS,OAAmC;CAClD,OAAO,OAAO,UAAU,YAAY,UAAU,KAAK,QAAQ,KAAA;AAC7D;;AAGA,SAAgB,SAAS,QAML;CAClB,MAAM,MAAuB,EAAE,IAAI,OAAO,GAAG;CAC7C,IAAI,OAAO,SAAS,KAAA,GAAW,IAAI,OAAO,OAAO;CACjD,IAAI,OAAO,MAAM,IAAI,OAAO,OAAO;CACnC,IAAI,OAAO,OAAO,IAAI,QAAQ,OAAO;CACrC,IAAI,OAAO,cAAc,OAAO,KAAK,OAAO,UAAU,EAAE,QACtD,IAAI,aAAa,OAAO;CAE1B,OAAO;AACT"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AuthorizationProvider, AuthorizeInput } from "@xtandard/kit/authorization";
|
|
2
|
+
|
|
3
|
+
//#region src/authorization/contract.d.ts
|
|
4
|
+
declare const ACTIONS: import("@xtandard/kit/authorization").ActionsDefinitionResult<"catalog:read" | "subjects:read" | "grants:read" | "history:read" | "check:run" | "relationships:read" | "grants:write" | "roles:write" | "relationships:write">;
|
|
5
|
+
/** The full set of authorizable actions. */
|
|
6
|
+
type PermissionsAction = (typeof ACTIONS.ALL_ACTIONS)[number];
|
|
7
|
+
/**
|
|
8
|
+
* The resource an action targets. `subject` is absent on collection routes (list subjects, every
|
|
9
|
+
* grant, global history).
|
|
10
|
+
*/
|
|
11
|
+
type PermissionsResource = {
|
|
12
|
+
type: "catalog";
|
|
13
|
+
} | {
|
|
14
|
+
type: "subject";
|
|
15
|
+
subject?: string;
|
|
16
|
+
} | {
|
|
17
|
+
type: "grant";
|
|
18
|
+
subject?: string;
|
|
19
|
+
permission?: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: "history";
|
|
22
|
+
subject?: string;
|
|
23
|
+
} | {
|
|
24
|
+
type: "check";
|
|
25
|
+
subject?: string | null;
|
|
26
|
+
role?: string;
|
|
27
|
+
path?: string;
|
|
28
|
+
} | {
|
|
29
|
+
type: "relationship";
|
|
30
|
+
object?: string;
|
|
31
|
+
relation?: string;
|
|
32
|
+
subject?: string;
|
|
33
|
+
};
|
|
34
|
+
/** Input passed to {@link AuthorizationProvider.authorize}. */
|
|
35
|
+
type AuthorizeInput$1 = AuthorizeInput<PermissionsAction, PermissionsResource>;
|
|
36
|
+
/** Decides whether an action is permitted. */
|
|
37
|
+
type AuthorizationProvider$1 = AuthorizationProvider<PermissionsAction, PermissionsResource>;
|
|
38
|
+
/** Every action, in a stable order (role presets, docs, the UI). */
|
|
39
|
+
declare const ALL_ACTIONS: readonly PermissionsAction[];
|
|
40
|
+
/** Actions that write state: blocked (423) when the panel is readonly. */
|
|
41
|
+
declare const MUTATING_ACTIONS: ReadonlySet<PermissionsAction>;
|
|
42
|
+
/** True if the action writes state. */
|
|
43
|
+
declare const isMutatingAction: (action: PermissionsAction) => boolean;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { PermissionsAction as a, MUTATING_ACTIONS as i, AuthorizationProvider$1 as n, PermissionsResource as o, AuthorizeInput$1 as r, isMutatingAction as s, ALL_ACTIONS as t };
|
|
46
|
+
//# sourceMappingURL=contract-CNgMXr2u.d.cts.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { AuthorizationProvider, AuthorizeInput } from "@xtandard/kit/authorization";
|
|
2
|
+
|
|
3
|
+
//#region src/authorization/contract.d.ts
|
|
4
|
+
declare const ACTIONS: import("@xtandard/kit/authorization").ActionsDefinitionResult<"catalog:read" | "subjects:read" | "grants:read" | "history:read" | "check:run" | "relationships:read" | "grants:write" | "roles:write" | "relationships:write">;
|
|
5
|
+
/** The full set of authorizable actions. */
|
|
6
|
+
type PermissionsAction = (typeof ACTIONS.ALL_ACTIONS)[number];
|
|
7
|
+
/**
|
|
8
|
+
* The resource an action targets. `subject` is absent on collection routes (list subjects, every
|
|
9
|
+
* grant, global history).
|
|
10
|
+
*/
|
|
11
|
+
type PermissionsResource = {
|
|
12
|
+
type: "catalog";
|
|
13
|
+
} | {
|
|
14
|
+
type: "subject";
|
|
15
|
+
subject?: string;
|
|
16
|
+
} | {
|
|
17
|
+
type: "grant";
|
|
18
|
+
subject?: string;
|
|
19
|
+
permission?: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: "history";
|
|
22
|
+
subject?: string;
|
|
23
|
+
} | {
|
|
24
|
+
type: "check";
|
|
25
|
+
subject?: string | null;
|
|
26
|
+
role?: string;
|
|
27
|
+
path?: string;
|
|
28
|
+
} | {
|
|
29
|
+
type: "relationship";
|
|
30
|
+
object?: string;
|
|
31
|
+
relation?: string;
|
|
32
|
+
subject?: string;
|
|
33
|
+
};
|
|
34
|
+
/** Input passed to {@link AuthorizationProvider.authorize}. */
|
|
35
|
+
type AuthorizeInput$1 = AuthorizeInput<PermissionsAction, PermissionsResource>;
|
|
36
|
+
/** Decides whether an action is permitted. */
|
|
37
|
+
type AuthorizationProvider$1 = AuthorizationProvider<PermissionsAction, PermissionsResource>;
|
|
38
|
+
/** Every action, in a stable order (role presets, docs, the UI). */
|
|
39
|
+
declare const ALL_ACTIONS: readonly PermissionsAction[];
|
|
40
|
+
/** Actions that write state: blocked (423) when the panel is readonly. */
|
|
41
|
+
declare const MUTATING_ACTIONS: ReadonlySet<PermissionsAction>;
|
|
42
|
+
/** True if the action writes state. */
|
|
43
|
+
declare const isMutatingAction: (action: PermissionsAction) => boolean;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { PermissionsAction as a, MUTATING_ACTIONS as i, AuthorizationProvider$1 as n, PermissionsResource as o, AuthorizeInput$1 as r, isMutatingAction as s, ALL_ACTIONS as t };
|
|
46
|
+
//# sourceMappingURL=contract-CNgMXr2u.d.mts.map
|