@xtandard/permissions 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +362 -2
- package/bin/xtandard-permissions.mjs +3 -0
- package/dist/better-auth-Bp9YVyQa.d.cts +56 -0
- package/dist/better-auth-DHyW5-yt.cjs +91 -0
- package/dist/better-auth-DHyW5-yt.cjs.map +1 -0
- package/dist/better-auth-NO40ZqSM.mjs +74 -0
- package/dist/better-auth-NO40ZqSM.mjs.map +1 -0
- package/dist/better-auth-NSXgt6ZU.d.mts +56 -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 +548 -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 +544 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/contract-BMiOmg2f.d.cts +50 -0
- package/dist/contract-Bpy8yPrS.cjs +70 -0
- package/dist/contract-Bpy8yPrS.cjs.map +1 -0
- package/dist/contract-CNgMXr2u.d.cts +46 -0
- package/dist/contract-CNgMXr2u.d.mts +46 -0
- package/dist/contract-CPmJVoRx.cjs +70 -0
- package/dist/contract-CPmJVoRx.cjs.map +1 -0
- package/dist/contract-D32H1t0u.d.mts +50 -0
- package/dist/contract-DTdTXZtJ.mjs +47 -0
- package/dist/contract-DTdTXZtJ.mjs.map +1 -0
- package/dist/contract-DUzgB-He.d.mts +375 -0
- package/dist/contract-Dk6d2ylD.d.cts +375 -0
- package/dist/contract-RMkmERhT.d.cts +2 -0
- package/dist/contract-RMkmERhT.d.mts +2 -0
- package/dist/contract-Yc5AZuvv.mjs +47 -0
- package/dist/contract-Yc5AZuvv.mjs.map +1 -0
- package/dist/create-fetch-handler-BHDU4chu.d.mts +77 -0
- package/dist/create-fetch-handler-BtX64_rS.d.cts +77 -0
- package/dist/create-fetch-handler-C-WyaRCR.cjs +653 -0
- package/dist/create-fetch-handler-C-WyaRCR.cjs.map +1 -0
- package/dist/create-fetch-handler-ojjpk1Iw.mjs +636 -0
- package/dist/create-fetch-handler-ojjpk1Iw.mjs.map +1 -0
- package/dist/elysia-shared-BM6cPoCU.mjs +78 -0
- package/dist/elysia-shared-BM6cPoCU.mjs.map +1 -0
- package/dist/elysia-shared-BUTFTeal.cjs +101 -0
- package/dist/elysia-shared-BUTFTeal.cjs.map +1 -0
- package/dist/elysia-shared-DtKViycb.d.cts +58 -0
- package/dist/elysia-shared-g8zsb_pU.d.mts +58 -0
- package/dist/engine-Bufv0TbD.mjs +574 -0
- package/dist/engine-Bufv0TbD.mjs.map +1 -0
- package/dist/engine-CGGVDCqi.d.cts +296 -0
- package/dist/engine-DpFIcbgh.d.mts +296 -0
- package/dist/engine-bMoz3iW-.cjs +587 -0
- package/dist/engine-bMoz3iW-.cjs.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 +12 -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 +116 -0
- package/dist/entry-auth-jwt.cjs.map +1 -0
- package/dist/entry-auth-jwt.d.cts +65 -0
- package/dist/entry-auth-jwt.d.mts +65 -0
- package/dist/entry-auth-jwt.mjs +108 -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 +82 -0
- package/dist/entry-auth-session.cjs.map +1 -0
- package/dist/entry-auth-session.d.cts +20 -0
- package/dist/entry-auth-session.d.mts +20 -0
- package/dist/entry-auth-session.mjs +75 -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-bL3XQLfE.mjs +54 -0
- package/dist/errors-bL3XQLfE.mjs.map +1 -0
- package/dist/errors-vVYic8gz.cjs +89 -0
- package/dist/errors-vVYic8gz.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-BOx5cnMP.mjs +141 -0
- package/dist/guard-BOx5cnMP.mjs.map +1 -0
- package/dist/guard-C3o7V14m.d.cts +62 -0
- package/dist/guard-DCbTnqPz.d.mts +62 -0
- package/dist/guard-nwdOYe90.cjs +188 -0
- package/dist/guard-nwdOYe90.cjs.map +1 -0
- package/dist/index-BVVgDSdq.d.cts +1 -0
- package/dist/index-BVVgDSdq.d.mts +1 -0
- package/dist/index.cjs +240 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +195 -0
- package/dist/index.d.mts +195 -0
- package/dist/index.mjs +60 -0
- package/dist/index.mjs.map +1 -0
- package/dist/kit-C7tepDB2.cjs +76 -0
- package/dist/kit-C7tepDB2.cjs.map +1 -0
- package/dist/kit-DMVBLBI9.d.mts +57 -0
- package/dist/kit-fzXHYb1l.mjs +65 -0
- package/dist/kit-fzXHYb1l.mjs.map +1 -0
- package/dist/kit-qAROuhOI.d.cts +57 -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-C9PjftY6.mjs +59 -0
- package/dist/permissions-C9PjftY6.mjs.map +1 -0
- package/dist/permissions-Cxri_P_k.cjs +70 -0
- package/dist/permissions-Cxri_P_k.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 +18710 -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-DtRb3EO0.mjs +1001 -0
- package/dist/routes-DtRb3EO0.mjs.map +1 -0
- package/dist/routes-irNuuZqo.cjs +1049 -0
- package/dist/routes-irNuuZqo.cjs.map +1 -0
- package/dist/server-C2F4H6bR.d.cts +886 -0
- package/dist/server-CJ7AIJpO.d.mts +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 +57 -0
- package/dist/types-elysia2/auth-provider/kit.d.ts +57 -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 +192 -0
- package/dist/types-elysia2/entry-elysia2.d.ts +9 -0
- package/dist/types-elysia2/errors.d.ts +47 -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 +299 -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 +132 -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 +192 -0
- package/dist/types-react/entry-react-embed.d.ts +20 -0
- package/dist/types-react/errors.d.ts +47 -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 +299 -0
- package/dist/types-react/storage/contract.d.ts +18 -0
- package/dist/types-react/ui/App.d.ts +23 -0
- package/dist/types-react/ui/api.d.ts +73 -0
- package/dist/types-react/ui/components/perm-bits.d.ts +64 -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 +109 -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-uXGOtyuj.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 @@
|
|
|
1
|
+
{"version":3,"file":"better-auth-NO40ZqSM.mjs","names":[],"sources":["../src/auth-provider/better-auth.ts"],"sourcesContent":["/**\n * better-auth as a {@link PermissionsAuthProvider} (ADR 0006/0007). The subject is the better-auth\n * user; the role comes from the admin plugin's `user.role` (comma-separated, e.g. `\"admin,user\"`)\n * or, with `roleSource: \"organization\"`, from the caller's member role in the active organization.\n *\n * No runtime import of better-auth: `auth` is typed structurally, so any `betterAuth()` instance\n * (with or without plugins) is accepted.\n *\n * @module\n */\n\nimport {\n identity,\n normalizeRoles,\n stringField,\n type PermissionsAuthProvider,\n type ProviderRoleOptions,\n} from \"./contract.ts\";\n\n/** The part of a `betterAuth()` instance this provider calls (structural). */\nexport interface BetterAuthLike {\n api: {\n /** `auth.api.getSession({ headers })` → `{ session, user } | null`. */\n getSession(context: { headers: Headers }): Promise<unknown>;\n /** Organization plugin: `auth.api.getActiveMemberRole({ headers })` → `{ role }`. */\n getActiveMemberRole?(context: { headers: Headers }): Promise<unknown>;\n };\n}\n\n/** The session shape the provider reads (a structural subset of better-auth's). */\nexport interface BetterAuthSessionLike {\n user: {\n id: string;\n name?: string | null;\n email?: string | null;\n role?: string | string[] | null;\n [key: string]: unknown;\n };\n session: { activeOrganizationId?: string | null; [key: string]: unknown };\n}\n\n/** Options for {@link betterAuthProvider}. */\nexport interface BetterAuthProviderOptions extends ProviderRoleOptions {\n /**\n * Where the raw role comes from. `\"user\"` (default): the admin plugin's `user.role`.\n * `\"organization\"`: the caller's role in `session.activeOrganizationId` (organization plugin);\n * without an active organization the role is empty (the catalog's `defaultRole`).\n */\n roleSource?: \"user\" | \"organization\";\n /** Extra subject attributes from the session (merged after `activeOrganizationId`). */\n attributes?(session: BetterAuthSessionLike): Record<string, unknown> | undefined;\n}\n\n/** Narrow better-auth's `getSession` result. */\nexport function asBetterAuthSession(value: unknown): BetterAuthSessionLike | null {\n if (!value || typeof value !== \"object\") return null;\n const { user, session } = value as { user?: unknown; session?: unknown };\n if (!stringField(user, \"id\") || !session || typeof session !== \"object\") return null;\n return value as BetterAuthSessionLike;\n}\n\n/**\n * Resolve the raw role for a better-auth session (shared with the server plugin).\n * @internal\n */\nexport async function betterAuthRole(\n auth: BetterAuthLike,\n session: BetterAuthSessionLike,\n headers: Headers,\n options: BetterAuthProviderOptions,\n): Promise<string[] | null> {\n if (options.roleSource !== \"organization\")\n return normalizeRoles(session.user.role, options.mapRole);\n if (!session.session.activeOrganizationId) return null;\n const member = await auth.api.getActiveMemberRole!({ headers });\n return normalizeRoles((member as { role?: unknown } | null)?.role, options.mapRole);\n}\n\n/**\n * The subject identity of a better-auth session (shared with the server plugin).\n * @internal\n */\nexport async function betterAuthIdentity(\n auth: BetterAuthLike,\n session: BetterAuthSessionLike,\n headers: Headers,\n options: BetterAuthProviderOptions,\n) {\n const attributes: Record<string, unknown> = {};\n const org = session.session.activeOrganizationId;\n if (typeof org === \"string\" && org) attributes.activeOrganizationId = org;\n Object.assign(attributes, options.attributes?.(session));\n return identity({\n id: session.user.id,\n role: await betterAuthRole(auth, session, headers, options),\n name: stringField(session.user, \"name\"),\n email: stringField(session.user, \"email\"),\n attributes,\n });\n}\n\n/** Throw early when `roleSource: \"organization\"` is used without the organization plugin. */\nexport function assertRoleSource(auth: BetterAuthLike, options: BetterAuthProviderOptions): void {\n if (options.roleSource === \"organization\" && typeof auth.api.getActiveMemberRole !== \"function\") {\n throw new TypeError(\n 'betterAuthProvider: roleSource \"organization\" needs better-auth\\'s organization plugin (auth.api.getActiveMemberRole)',\n );\n }\n}\n\n/**\n * A {@link PermissionsAuthProvider} over a `betterAuth()` instance.\n *\n * @example\n * ```ts\n * import { betterAuthProvider } from \"@xtandard/permissions/auth/better-auth\";\n *\n * const provider = betterAuthProvider(auth, { mapRole: { user: \"member\" } });\n * const { auth: kitAuth, authorization } = toKitAuth(provider, perms);\n * ```\n */\nexport function betterAuthProvider(\n auth: BetterAuthLike,\n options: BetterAuthProviderOptions = {},\n): PermissionsAuthProvider {\n assertRoleSource(auth, options);\n const provider: PermissionsAuthProvider = {\n async getSubject(request) {\n const session = asBetterAuthSession(await auth.api.getSession({ headers: request.headers }));\n if (!session) return null;\n return betterAuthIdentity(auth, session, request.headers, options);\n },\n };\n if (options.canManage) provider.canManage = options.canManage;\n return provider;\n}\n"],"mappings":";;;;;;;;;;;;;AAsDA,SAAgB,oBAAoB,OAA8C;CAChF,IAAI,CAAC,SAAS,OAAO,UAAU,UAAU,OAAO;CAChD,MAAM,EAAE,MAAM,YAAY;CAC1B,IAAI,CAAC,YAAY,MAAM,IAAI,KAAK,CAAC,WAAW,OAAO,YAAY,UAAU,OAAO;CAChF,OAAO;AACT;;;;;AAMA,eAAsB,eACpB,MACA,SACA,SACA,SAC0B;CAC1B,IAAI,QAAQ,eAAe,gBACzB,OAAO,eAAe,QAAQ,KAAK,MAAM,QAAQ,OAAO;CAC1D,IAAI,CAAC,QAAQ,QAAQ,sBAAsB,OAAO;CAElD,OAAO,gBAAgB,MADF,KAAK,IAAI,oBAAqB,EAAE,QAAQ,CAAC,IACD,MAAM,QAAQ,OAAO;AACpF;;;;;AAMA,eAAsB,mBACpB,MACA,SACA,SACA,SACA;CACA,MAAM,aAAsC,CAAC;CAC7C,MAAM,MAAM,QAAQ,QAAQ;CAC5B,IAAI,OAAO,QAAQ,YAAY,KAAK,WAAW,uBAAuB;CACtE,OAAO,OAAO,YAAY,QAAQ,aAAa,OAAO,CAAC;CACvD,OAAO,SAAS;EACd,IAAI,QAAQ,KAAK;EACjB,MAAM,MAAM,eAAe,MAAM,SAAS,SAAS,OAAO;EAC1D,MAAM,YAAY,QAAQ,MAAM,MAAM;EACtC,OAAO,YAAY,QAAQ,MAAM,OAAO;EACxC;CACF,CAAC;AACH;;AAGA,SAAgB,iBAAiB,MAAsB,SAA0C;CAC/F,IAAI,QAAQ,eAAe,kBAAkB,OAAO,KAAK,IAAI,wBAAwB,YACnF,MAAM,IAAI,UACR,wHACF;AAEJ;;;;;;;;;;;;AAaA,SAAgB,mBACd,MACA,UAAqC,CAAC,GACb;CACzB,iBAAiB,MAAM,OAAO;CAC9B,MAAM,WAAoC,EACxC,MAAM,WAAW,SAAS;EACxB,MAAM,UAAU,oBAAoB,MAAM,KAAK,IAAI,WAAW,EAAE,SAAS,QAAQ,QAAQ,CAAC,CAAC;EAC3F,IAAI,CAAC,SAAS,OAAO;EACrB,OAAO,mBAAmB,MAAM,SAAS,QAAQ,SAAS,OAAO;CACnE,EACF;CACA,IAAI,QAAQ,WAAW,SAAS,YAAY,QAAQ;CACpD,OAAO;AACT"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { n as ProviderRoleOptions, t as PermissionsAuthProvider } from "./contract-D32H1t0u.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/auth-provider/better-auth.d.ts
|
|
4
|
+
/** The part of a `betterAuth()` instance this provider calls (structural). */
|
|
5
|
+
interface BetterAuthLike {
|
|
6
|
+
api: {
|
|
7
|
+
/** `auth.api.getSession({ headers })` → `{ session, user } | null`. */getSession(context: {
|
|
8
|
+
headers: Headers;
|
|
9
|
+
}): Promise<unknown>; /** Organization plugin: `auth.api.getActiveMemberRole({ headers })` → `{ role }`. */
|
|
10
|
+
getActiveMemberRole?(context: {
|
|
11
|
+
headers: Headers;
|
|
12
|
+
}): Promise<unknown>;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** The session shape the provider reads (a structural subset of better-auth's). */
|
|
16
|
+
interface BetterAuthSessionLike {
|
|
17
|
+
user: {
|
|
18
|
+
id: string;
|
|
19
|
+
name?: string | null;
|
|
20
|
+
email?: string | null;
|
|
21
|
+
role?: string | string[] | null;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
session: {
|
|
25
|
+
activeOrganizationId?: string | null;
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** Options for {@link betterAuthProvider}. */
|
|
30
|
+
interface BetterAuthProviderOptions extends ProviderRoleOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Where the raw role comes from. `"user"` (default): the admin plugin's `user.role`.
|
|
33
|
+
* `"organization"`: the caller's role in `session.activeOrganizationId` (organization plugin);
|
|
34
|
+
* without an active organization the role is empty (the catalog's `defaultRole`).
|
|
35
|
+
*/
|
|
36
|
+
roleSource?: "user" | "organization";
|
|
37
|
+
/** Extra subject attributes from the session (merged after `activeOrganizationId`). */
|
|
38
|
+
attributes?(session: BetterAuthSessionLike): Record<string, unknown> | undefined;
|
|
39
|
+
}
|
|
40
|
+
/** Narrow better-auth's `getSession` result. */
|
|
41
|
+
declare function asBetterAuthSession(value: unknown): BetterAuthSessionLike | null;
|
|
42
|
+
/**
|
|
43
|
+
* A {@link PermissionsAuthProvider} over a `betterAuth()` instance.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { betterAuthProvider } from "@xtandard/permissions/auth/better-auth";
|
|
48
|
+
*
|
|
49
|
+
* const provider = betterAuthProvider(auth, { mapRole: { user: "member" } });
|
|
50
|
+
* const { auth: kitAuth, authorization } = toKitAuth(provider, perms);
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
declare function betterAuthProvider(auth: BetterAuthLike, options?: BetterAuthProviderOptions): PermissionsAuthProvider;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { betterAuthProvider as a, asBetterAuthSession as i, BetterAuthProviderOptions as n, BetterAuthSessionLike as r, BetterAuthLike as t };
|
|
56
|
+
//# sourceMappingURL=better-auth-NSXgt6ZU.d.mts.map
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { i as AuthorizationConfig, p as RelationSchema, r as Authorization, s as Definition } from "./policy-DFq_SYR3.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/catalog.d.ts
|
|
4
|
+
/** A catalog without relations (ReBAC off): no object type, so no relation query type-checks. */
|
|
5
|
+
type NoRelations = Record<never, never>;
|
|
6
|
+
/** The user the rules see: the engine passes the subject with its effective `role`. */
|
|
7
|
+
interface PermissionsSubject {
|
|
8
|
+
/** The subject id (a user id in 0.1). */
|
|
9
|
+
id: string;
|
|
10
|
+
/** The effective role (stored assignment, else the auth provider's, else `defaultRole`). */
|
|
11
|
+
role: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
email?: string;
|
|
14
|
+
/** Extra facts from the auth provider (claims, profile fields). */
|
|
15
|
+
attributes?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Who a check is for, as an auth provider reports it. `role` may be one role, several (the most
|
|
19
|
+
* privileged known one wins, see {@link PermissionsCatalog.effectiveRole}) or missing
|
|
20
|
+
* (`defaultRole`); a stored role assignment overrides it.
|
|
21
|
+
*/
|
|
22
|
+
interface SubjectIdentity {
|
|
23
|
+
id: string;
|
|
24
|
+
role?: string | readonly string[] | null;
|
|
25
|
+
name?: string;
|
|
26
|
+
email?: string;
|
|
27
|
+
attributes?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
/** A human label: a string, or a label with a description. */
|
|
30
|
+
type LabelInput = string | {
|
|
31
|
+
label: string;
|
|
32
|
+
description?: string;
|
|
33
|
+
};
|
|
34
|
+
/** A normalized label. */
|
|
35
|
+
interface Label {
|
|
36
|
+
label: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
}
|
|
39
|
+
/** What `definePermissions` adds on top of the lib's `AuthorizationConfig`. */
|
|
40
|
+
interface CatalogMeta<R extends string, P extends string, S extends RelationSchema = NoRelations> {
|
|
41
|
+
/**
|
|
42
|
+
* The relation schema (ReBAC, ADR 0013), built with `defineRelations` and the `direct` /
|
|
43
|
+
* `computed` / `from` / `union` / `intersection` / `exclusion` builders. Validated again here.
|
|
44
|
+
* Without it, relationship writes and checks throw `RelationSchemaError`.
|
|
45
|
+
*/
|
|
46
|
+
relations?: S;
|
|
47
|
+
/**
|
|
48
|
+
* Roles that may grant / revoke / assign roles by default (an auth provider can override it).
|
|
49
|
+
* Default: the most privileged role (the last of `roles`).
|
|
50
|
+
*/
|
|
51
|
+
managerRoles?: readonly R[];
|
|
52
|
+
/** Labels and descriptions for the admin panel. Missing entries default to the key. */
|
|
53
|
+
labels?: {
|
|
54
|
+
roles?: Partial<Record<R, LabelInput>>;
|
|
55
|
+
permissions?: Partial<Record<P, LabelInput>>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* When `true`, a non-expired grant whose name equals the checked path allows it outright
|
|
59
|
+
* (`reason: "grant"`), for catalogs whose assignable names are paths. Default `false`: grants
|
|
60
|
+
* only matter through the rules (ADR 0005).
|
|
61
|
+
*/
|
|
62
|
+
directGrants?: boolean;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The configuration of {@link definePermissions}: the lib's `AuthorizationConfig` (roles ordered
|
|
66
|
+
* **least → most privileged**, `guestRole`, `defaultRole`, `assignable`, `rules`) without
|
|
67
|
+
* `getRole` (the engine sets the role), plus {@link CatalogMeta}.
|
|
68
|
+
*/
|
|
69
|
+
type PermissionsConfig<D extends Definition, R extends string, P extends string, X, S extends RelationSchema = NoRelations> = Omit<AuthorizationConfig<D, R, P, PermissionsSubject, X>, "getRole"> & CatalogMeta<NoInfer<R>, NoInfer<P>, S>;
|
|
70
|
+
/** A catalog: the wrapped lib `Authorization` plus the product metadata. */
|
|
71
|
+
interface PermissionsCatalog<D extends Definition = Definition, R extends string = string, P extends string = string, X = undefined, S extends RelationSchema = RelationSchema> {
|
|
72
|
+
/** The lib authorization (`createAbility`, `createRules`, `parseRole`, …). */
|
|
73
|
+
readonly authorization: Authorization<D, R, P, PermissionsSubject, X>;
|
|
74
|
+
/** Every role, least → most privileged. */
|
|
75
|
+
readonly roles: readonly R[];
|
|
76
|
+
/** The role of a request without a subject. */
|
|
77
|
+
readonly guestRole: R;
|
|
78
|
+
/** The role of a signed-in subject whose role is missing or unknown. */
|
|
79
|
+
readonly defaultRole: R;
|
|
80
|
+
/** The assignable permissions. */
|
|
81
|
+
readonly assignable: readonly P[];
|
|
82
|
+
/** Roles that may manage permissions by default. */
|
|
83
|
+
readonly managerRoles: readonly R[];
|
|
84
|
+
/** Labels for every role and permission (defaulting to the key). */
|
|
85
|
+
readonly labels: {
|
|
86
|
+
readonly roles: Readonly<Record<R, Label>>;
|
|
87
|
+
readonly permissions: Readonly<Record<P, Label>>;
|
|
88
|
+
};
|
|
89
|
+
/** See {@link CatalogMeta.directGrants}. */
|
|
90
|
+
readonly directGrants: boolean;
|
|
91
|
+
/** The relation schema (ReBAC), `null` when the catalog declares none. */
|
|
92
|
+
readonly relations: S | null;
|
|
93
|
+
/** True when `value` is one of `roles`. */
|
|
94
|
+
isRole(value: unknown): value is R;
|
|
95
|
+
/** True when `value` is one of `assignable`. */
|
|
96
|
+
isAssignable(value: unknown): value is P;
|
|
97
|
+
/** True when `role` is one of `managerRoles`. */
|
|
98
|
+
isManagerRole(role: unknown): boolean;
|
|
99
|
+
/** A signed-in subject's role: `value` when it is a known non-guest role, else `defaultRole`. */
|
|
100
|
+
parseRole(value: unknown): R;
|
|
101
|
+
/**
|
|
102
|
+
* The effective role of a signed-in subject from what an auth provider reports: one role, several
|
|
103
|
+
* (an array, or a comma-separated string as better-auth's admin plugin stores them) → the most
|
|
104
|
+
* privileged known one; none known (or missing) → `defaultRole`. Never the guest role.
|
|
105
|
+
*/
|
|
106
|
+
effectiveRole(raw: string | readonly string[] | null | undefined): R;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The permission type of a catalog: the `assignable` union, or `string` for a roles-only catalog
|
|
110
|
+
* (`assignable: []` infers `never`, which no generic `AnyPermissionsCatalog` slot accepts because
|
|
111
|
+
* rules are contravariant in it). Every permission is still rejected at runtime there.
|
|
112
|
+
*/
|
|
113
|
+
type PermissionUnion<P extends string> = [P] extends [never] ? string : P;
|
|
114
|
+
/** Any catalog (for generic constraints). */
|
|
115
|
+
type AnyPermissionsCatalog = PermissionsCatalog<any, any, any, any, any>;
|
|
116
|
+
/** The permix definition of a catalog. */
|
|
117
|
+
type DefinitionOf<C> = C extends PermissionsCatalog<infer D, any, any, any, any> ? D : never;
|
|
118
|
+
/** The role union of a catalog. */
|
|
119
|
+
type RoleOf<C> = C extends {
|
|
120
|
+
readonly roles: readonly (infer R)[];
|
|
121
|
+
} ? R : never;
|
|
122
|
+
/** The assignable-permission union of a catalog. */
|
|
123
|
+
type PermissionOf<C> = C extends {
|
|
124
|
+
readonly assignable: readonly (infer P)[];
|
|
125
|
+
} ? P : never;
|
|
126
|
+
/** The rule context (`ctx`) type of a catalog. */
|
|
127
|
+
type CtxOf<C> = C extends PermissionsCatalog<any, any, any, infer X, any> ? X : never;
|
|
128
|
+
/** The relation schema of a catalog. */
|
|
129
|
+
type RelationsOf<C> = C extends PermissionsCatalog<any, any, any, any, infer S> ? S : never;
|
|
130
|
+
/**
|
|
131
|
+
* Define the catalog. Curried like the lib's `defineAuthorization`: the permix definition and the
|
|
132
|
+
* rule context type go in the first call, the roles and permissions are inferred by the second:
|
|
133
|
+
* `definePermissions<Definition, Ctx>()({ ... })`.
|
|
134
|
+
*
|
|
135
|
+
* Rules are synchronous (a rule that returns a Promise denies and throws `AsyncRuleError`); load
|
|
136
|
+
* what they need first and pass it as `ctx` or as the checked data. A rule wrapped in the lib's
|
|
137
|
+
* `asyncRule()` is evaluated only by the engine's async `check()` / `can()`, never by the
|
|
138
|
+
* synchronous `ability()` (ADR 0005).
|
|
139
|
+
*
|
|
140
|
+
* @throws {Error} When `guestRole`, `defaultRole` or a `managerRoles` entry is not in `roles`, a
|
|
141
|
+
* role has no rules, or the guest role is a manager role.
|
|
142
|
+
*/
|
|
143
|
+
declare function definePermissions<D extends Definition, X = undefined>(): <const R extends string, const P extends string, const S extends RelationSchema = NoRelations>(config: PermissionsConfig<D, R, P, X, S>) => PermissionsCatalog<D, R, PermissionUnion<P>, X, S>;
|
|
144
|
+
/**
|
|
145
|
+
* Wrap an existing lib `Authorization` (from `defineAuthorization`) as a catalog. Its config is
|
|
146
|
+
* re-defined with `getRole: (subject) => subject.role`, so its rules receive a
|
|
147
|
+
* {@link PermissionsSubject} (`{ id, role, name?, email?, attributes? }`) as `user`; rules that read
|
|
148
|
+
* other user fields must move them into `attributes` or `ctx`.
|
|
149
|
+
*/
|
|
150
|
+
declare function fromAuthorization<D extends Definition, R extends string, P extends string, X, const S extends RelationSchema = NoRelations>(authorization: Authorization<D, R, P, any, X>, meta?: CatalogMeta<NoInfer<R>, NoInfer<P>, S>): PermissionsCatalog<D, R, P, X, S>;
|
|
151
|
+
//#endregion
|
|
152
|
+
export { fromAuthorization as _, Label as a, PermissionOf as c, PermissionsConfig as d, PermissionsSubject as f, definePermissions as g, SubjectIdentity as h, DefinitionOf as i, PermissionUnion as l, RoleOf as m, CatalogMeta as n, LabelInput as o, RelationsOf as p, CtxOf as r, NoRelations as s, AnyPermissionsCatalog as t, PermissionsCatalog as u };
|
|
153
|
+
//# sourceMappingURL=catalog-DA_d1SdC.d.cts.map
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { i as AuthorizationConfig, p as RelationSchema, r as Authorization, s as Definition } from "./policy-CGA6QD0a.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/catalog.d.ts
|
|
4
|
+
/** A catalog without relations (ReBAC off): no object type, so no relation query type-checks. */
|
|
5
|
+
type NoRelations = Record<never, never>;
|
|
6
|
+
/** The user the rules see: the engine passes the subject with its effective `role`. */
|
|
7
|
+
interface PermissionsSubject {
|
|
8
|
+
/** The subject id (a user id in 0.1). */
|
|
9
|
+
id: string;
|
|
10
|
+
/** The effective role (stored assignment, else the auth provider's, else `defaultRole`). */
|
|
11
|
+
role: string;
|
|
12
|
+
name?: string;
|
|
13
|
+
email?: string;
|
|
14
|
+
/** Extra facts from the auth provider (claims, profile fields). */
|
|
15
|
+
attributes?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Who a check is for, as an auth provider reports it. `role` may be one role, several (the most
|
|
19
|
+
* privileged known one wins, see {@link PermissionsCatalog.effectiveRole}) or missing
|
|
20
|
+
* (`defaultRole`); a stored role assignment overrides it.
|
|
21
|
+
*/
|
|
22
|
+
interface SubjectIdentity {
|
|
23
|
+
id: string;
|
|
24
|
+
role?: string | readonly string[] | null;
|
|
25
|
+
name?: string;
|
|
26
|
+
email?: string;
|
|
27
|
+
attributes?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
/** A human label: a string, or a label with a description. */
|
|
30
|
+
type LabelInput = string | {
|
|
31
|
+
label: string;
|
|
32
|
+
description?: string;
|
|
33
|
+
};
|
|
34
|
+
/** A normalized label. */
|
|
35
|
+
interface Label {
|
|
36
|
+
label: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
}
|
|
39
|
+
/** What `definePermissions` adds on top of the lib's `AuthorizationConfig`. */
|
|
40
|
+
interface CatalogMeta<R extends string, P extends string, S extends RelationSchema = NoRelations> {
|
|
41
|
+
/**
|
|
42
|
+
* The relation schema (ReBAC, ADR 0013), built with `defineRelations` and the `direct` /
|
|
43
|
+
* `computed` / `from` / `union` / `intersection` / `exclusion` builders. Validated again here.
|
|
44
|
+
* Without it, relationship writes and checks throw `RelationSchemaError`.
|
|
45
|
+
*/
|
|
46
|
+
relations?: S;
|
|
47
|
+
/**
|
|
48
|
+
* Roles that may grant / revoke / assign roles by default (an auth provider can override it).
|
|
49
|
+
* Default: the most privileged role (the last of `roles`).
|
|
50
|
+
*/
|
|
51
|
+
managerRoles?: readonly R[];
|
|
52
|
+
/** Labels and descriptions for the admin panel. Missing entries default to the key. */
|
|
53
|
+
labels?: {
|
|
54
|
+
roles?: Partial<Record<R, LabelInput>>;
|
|
55
|
+
permissions?: Partial<Record<P, LabelInput>>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* When `true`, a non-expired grant whose name equals the checked path allows it outright
|
|
59
|
+
* (`reason: "grant"`), for catalogs whose assignable names are paths. Default `false`: grants
|
|
60
|
+
* only matter through the rules (ADR 0005).
|
|
61
|
+
*/
|
|
62
|
+
directGrants?: boolean;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The configuration of {@link definePermissions}: the lib's `AuthorizationConfig` (roles ordered
|
|
66
|
+
* **least → most privileged**, `guestRole`, `defaultRole`, `assignable`, `rules`) without
|
|
67
|
+
* `getRole` (the engine sets the role), plus {@link CatalogMeta}.
|
|
68
|
+
*/
|
|
69
|
+
type PermissionsConfig<D extends Definition, R extends string, P extends string, X, S extends RelationSchema = NoRelations> = Omit<AuthorizationConfig<D, R, P, PermissionsSubject, X>, "getRole"> & CatalogMeta<NoInfer<R>, NoInfer<P>, S>;
|
|
70
|
+
/** A catalog: the wrapped lib `Authorization` plus the product metadata. */
|
|
71
|
+
interface PermissionsCatalog<D extends Definition = Definition, R extends string = string, P extends string = string, X = undefined, S extends RelationSchema = RelationSchema> {
|
|
72
|
+
/** The lib authorization (`createAbility`, `createRules`, `parseRole`, …). */
|
|
73
|
+
readonly authorization: Authorization<D, R, P, PermissionsSubject, X>;
|
|
74
|
+
/** Every role, least → most privileged. */
|
|
75
|
+
readonly roles: readonly R[];
|
|
76
|
+
/** The role of a request without a subject. */
|
|
77
|
+
readonly guestRole: R;
|
|
78
|
+
/** The role of a signed-in subject whose role is missing or unknown. */
|
|
79
|
+
readonly defaultRole: R;
|
|
80
|
+
/** The assignable permissions. */
|
|
81
|
+
readonly assignable: readonly P[];
|
|
82
|
+
/** Roles that may manage permissions by default. */
|
|
83
|
+
readonly managerRoles: readonly R[];
|
|
84
|
+
/** Labels for every role and permission (defaulting to the key). */
|
|
85
|
+
readonly labels: {
|
|
86
|
+
readonly roles: Readonly<Record<R, Label>>;
|
|
87
|
+
readonly permissions: Readonly<Record<P, Label>>;
|
|
88
|
+
};
|
|
89
|
+
/** See {@link CatalogMeta.directGrants}. */
|
|
90
|
+
readonly directGrants: boolean;
|
|
91
|
+
/** The relation schema (ReBAC), `null` when the catalog declares none. */
|
|
92
|
+
readonly relations: S | null;
|
|
93
|
+
/** True when `value` is one of `roles`. */
|
|
94
|
+
isRole(value: unknown): value is R;
|
|
95
|
+
/** True when `value` is one of `assignable`. */
|
|
96
|
+
isAssignable(value: unknown): value is P;
|
|
97
|
+
/** True when `role` is one of `managerRoles`. */
|
|
98
|
+
isManagerRole(role: unknown): boolean;
|
|
99
|
+
/** A signed-in subject's role: `value` when it is a known non-guest role, else `defaultRole`. */
|
|
100
|
+
parseRole(value: unknown): R;
|
|
101
|
+
/**
|
|
102
|
+
* The effective role of a signed-in subject from what an auth provider reports: one role, several
|
|
103
|
+
* (an array, or a comma-separated string as better-auth's admin plugin stores them) → the most
|
|
104
|
+
* privileged known one; none known (or missing) → `defaultRole`. Never the guest role.
|
|
105
|
+
*/
|
|
106
|
+
effectiveRole(raw: string | readonly string[] | null | undefined): R;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The permission type of a catalog: the `assignable` union, or `string` for a roles-only catalog
|
|
110
|
+
* (`assignable: []` infers `never`, which no generic `AnyPermissionsCatalog` slot accepts because
|
|
111
|
+
* rules are contravariant in it). Every permission is still rejected at runtime there.
|
|
112
|
+
*/
|
|
113
|
+
type PermissionUnion<P extends string> = [P] extends [never] ? string : P;
|
|
114
|
+
/** Any catalog (for generic constraints). */
|
|
115
|
+
type AnyPermissionsCatalog = PermissionsCatalog<any, any, any, any, any>;
|
|
116
|
+
/** The permix definition of a catalog. */
|
|
117
|
+
type DefinitionOf<C> = C extends PermissionsCatalog<infer D, any, any, any, any> ? D : never;
|
|
118
|
+
/** The role union of a catalog. */
|
|
119
|
+
type RoleOf<C> = C extends {
|
|
120
|
+
readonly roles: readonly (infer R)[];
|
|
121
|
+
} ? R : never;
|
|
122
|
+
/** The assignable-permission union of a catalog. */
|
|
123
|
+
type PermissionOf<C> = C extends {
|
|
124
|
+
readonly assignable: readonly (infer P)[];
|
|
125
|
+
} ? P : never;
|
|
126
|
+
/** The rule context (`ctx`) type of a catalog. */
|
|
127
|
+
type CtxOf<C> = C extends PermissionsCatalog<any, any, any, infer X, any> ? X : never;
|
|
128
|
+
/** The relation schema of a catalog. */
|
|
129
|
+
type RelationsOf<C> = C extends PermissionsCatalog<any, any, any, any, infer S> ? S : never;
|
|
130
|
+
/**
|
|
131
|
+
* Define the catalog. Curried like the lib's `defineAuthorization`: the permix definition and the
|
|
132
|
+
* rule context type go in the first call, the roles and permissions are inferred by the second:
|
|
133
|
+
* `definePermissions<Definition, Ctx>()({ ... })`.
|
|
134
|
+
*
|
|
135
|
+
* Rules are synchronous (a rule that returns a Promise denies and throws `AsyncRuleError`); load
|
|
136
|
+
* what they need first and pass it as `ctx` or as the checked data. A rule wrapped in the lib's
|
|
137
|
+
* `asyncRule()` is evaluated only by the engine's async `check()` / `can()`, never by the
|
|
138
|
+
* synchronous `ability()` (ADR 0005).
|
|
139
|
+
*
|
|
140
|
+
* @throws {Error} When `guestRole`, `defaultRole` or a `managerRoles` entry is not in `roles`, a
|
|
141
|
+
* role has no rules, or the guest role is a manager role.
|
|
142
|
+
*/
|
|
143
|
+
declare function definePermissions<D extends Definition, X = undefined>(): <const R extends string, const P extends string, const S extends RelationSchema = NoRelations>(config: PermissionsConfig<D, R, P, X, S>) => PermissionsCatalog<D, R, PermissionUnion<P>, X, S>;
|
|
144
|
+
/**
|
|
145
|
+
* Wrap an existing lib `Authorization` (from `defineAuthorization`) as a catalog. Its config is
|
|
146
|
+
* re-defined with `getRole: (subject) => subject.role`, so its rules receive a
|
|
147
|
+
* {@link PermissionsSubject} (`{ id, role, name?, email?, attributes? }`) as `user`; rules that read
|
|
148
|
+
* other user fields must move them into `attributes` or `ctx`.
|
|
149
|
+
*/
|
|
150
|
+
declare function fromAuthorization<D extends Definition, R extends string, P extends string, X, const S extends RelationSchema = NoRelations>(authorization: Authorization<D, R, P, any, X>, meta?: CatalogMeta<NoInfer<R>, NoInfer<P>, S>): PermissionsCatalog<D, R, P, X, S>;
|
|
151
|
+
//#endregion
|
|
152
|
+
export { fromAuthorization as _, Label as a, PermissionOf as c, PermissionsConfig as d, PermissionsSubject as f, definePermissions as g, SubjectIdentity as h, DefinitionOf as i, PermissionUnion as l, RoleOf as m, CatalogMeta as n, LabelInput as o, RelationsOf as p, CtxOf as r, NoRelations as s, AnyPermissionsCatalog as t, PermissionsCatalog as u };
|
|
153
|
+
//# sourceMappingURL=catalog-DJcJ3ycq.d.mts.map
|
package/dist/catalog.cjs
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _xtandard_lib_policy_rebac = require("@xtandard/lib/policy/rebac");
|
|
3
|
+
let _xtandard_lib_policy_permix = require("@xtandard/lib/policy/permix");
|
|
4
|
+
//#region src/catalog.ts
|
|
5
|
+
/**
|
|
6
|
+
* The catalog: roles, assignable permissions and per-role rules, declared once
|
|
7
|
+
* in code and shared by the server, the browser and the admin panel (ADR 0002).
|
|
8
|
+
*
|
|
9
|
+
* `definePermissions()` wraps `defineAuthorization` from
|
|
10
|
+
* `@xtandard/lib/policy/permix` (which owns role parsing, the assignable list,
|
|
11
|
+
* the sync-only rule helpers, `createAbility` and `explain`) and adds what the
|
|
12
|
+
* product needs on top: `managerRoles`, labels for the panel, the
|
|
13
|
+
* `directGrants` switch and `effectiveRole()`. The rule user is fixed to
|
|
14
|
+
* {@link PermissionsSubject}, whose `role` the engine sets to the subject's
|
|
15
|
+
* effective role.
|
|
16
|
+
*
|
|
17
|
+
* Depends only on `@xtandard/lib/policy/permix` (and its `permix` peer), so
|
|
18
|
+
* browsers and edge runtimes can import it.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { definePermissions } from "@xtandard/permissions/catalog";
|
|
23
|
+
*
|
|
24
|
+
* type Definition = { post: ["read", { name: "publish"; type: Post }, "delete"] };
|
|
25
|
+
*
|
|
26
|
+
* export const permissions = definePermissions<Definition>()({
|
|
27
|
+
* roles: ["guest", "member", "editor", "admin"], // least → most privileged
|
|
28
|
+
* guestRole: "guest",
|
|
29
|
+
* defaultRole: "member",
|
|
30
|
+
* managerRoles: ["admin"],
|
|
31
|
+
* assignable: ["post:moderate", "billing:refund"],
|
|
32
|
+
* labels: { roles: { admin: "Administrator" }, permissions: { "post:moderate": "Moderate posts" } },
|
|
33
|
+
* rules: {
|
|
34
|
+
* guest: () => ({ post: { read: true, publish: false, delete: false } }),
|
|
35
|
+
* member: ({ user, permissions }, { or, fieldEquals, hasPermission }) => ({
|
|
36
|
+
* post: {
|
|
37
|
+
* read: true,
|
|
38
|
+
* publish: or<Post>(fieldEquals(user!.id, { field: "authorId" }), () =>
|
|
39
|
+
* hasPermission(permissions, "post:moderate"),
|
|
40
|
+
* ),
|
|
41
|
+
* delete: false,
|
|
42
|
+
* },
|
|
43
|
+
* }),
|
|
44
|
+
* editor: () => ({ post: { read: true, publish: true, delete: false } }),
|
|
45
|
+
* admin: () => ({ post: { read: true, publish: true, delete: true } }),
|
|
46
|
+
* },
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @module catalog
|
|
51
|
+
*/
|
|
52
|
+
const normalizeLabel = (key, input) => input === void 0 ? { label: key } : typeof input === "string" ? { label: input } : {
|
|
53
|
+
label: input.label,
|
|
54
|
+
...input.description ? { description: input.description } : {}
|
|
55
|
+
};
|
|
56
|
+
function labelMap(keys, inputs) {
|
|
57
|
+
const out = Object.create(null);
|
|
58
|
+
for (const key of keys) out[key] = normalizeLabel(key, inputs && Object.hasOwn(inputs, key) ? inputs[key] : void 0);
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
function buildCatalog(authorization, meta) {
|
|
62
|
+
const { roles, guestRole, defaultRole, assignable } = authorization.config;
|
|
63
|
+
if (roles.length === 0) throw new Error("definePermissions: roles must not be empty");
|
|
64
|
+
const managerRoles = meta.managerRoles ?? [roles[roles.length - 1]];
|
|
65
|
+
for (const role of managerRoles) {
|
|
66
|
+
if (!authorization.isRole(role)) throw new Error(`definePermissions: managerRoles "${role}" is not in roles`);
|
|
67
|
+
if (role === guestRole) throw new Error(`definePermissions: the guest role "${role}" can't be a manager role`);
|
|
68
|
+
}
|
|
69
|
+
const managers = new Set(managerRoles);
|
|
70
|
+
const rank = new Map(roles.map((role, index) => [role, index]));
|
|
71
|
+
const effectiveRole = (raw) => {
|
|
72
|
+
const candidates = typeof raw === "string" ? raw.split(",").map((s) => s.trim()) : Array.isArray(raw) ? raw : [];
|
|
73
|
+
let best;
|
|
74
|
+
for (const candidate of candidates) {
|
|
75
|
+
if (!authorization.isRole(candidate) || candidate === guestRole) continue;
|
|
76
|
+
if (best === void 0 || rank.get(candidate) > rank.get(best)) best = candidate;
|
|
77
|
+
}
|
|
78
|
+
return best ?? authorization.parseRole(void 0);
|
|
79
|
+
};
|
|
80
|
+
return Object.freeze({
|
|
81
|
+
authorization,
|
|
82
|
+
roles,
|
|
83
|
+
guestRole,
|
|
84
|
+
defaultRole,
|
|
85
|
+
assignable,
|
|
86
|
+
managerRoles: Object.freeze([...managerRoles]),
|
|
87
|
+
labels: Object.freeze({
|
|
88
|
+
roles: Object.freeze(labelMap(roles, meta.labels?.roles)),
|
|
89
|
+
permissions: Object.freeze(labelMap(assignable, meta.labels?.permissions))
|
|
90
|
+
}),
|
|
91
|
+
directGrants: meta.directGrants ?? false,
|
|
92
|
+
relations: meta.relations ? (0, _xtandard_lib_policy_rebac.defineRelations)(meta.relations) : null,
|
|
93
|
+
isRole: authorization.isRole,
|
|
94
|
+
isAssignable: authorization.isAssignable,
|
|
95
|
+
isManagerRole: (role) => typeof role === "string" && managers.has(role),
|
|
96
|
+
parseRole: authorization.parseRole,
|
|
97
|
+
effectiveRole
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Define the catalog. Curried like the lib's `defineAuthorization`: the permix definition and the
|
|
102
|
+
* rule context type go in the first call, the roles and permissions are inferred by the second:
|
|
103
|
+
* `definePermissions<Definition, Ctx>()({ ... })`.
|
|
104
|
+
*
|
|
105
|
+
* Rules are synchronous (a rule that returns a Promise denies and throws `AsyncRuleError`); load
|
|
106
|
+
* what they need first and pass it as `ctx` or as the checked data. A rule wrapped in the lib's
|
|
107
|
+
* `asyncRule()` is evaluated only by the engine's async `check()` / `can()`, never by the
|
|
108
|
+
* synchronous `ability()` (ADR 0005).
|
|
109
|
+
*
|
|
110
|
+
* @throws {Error} When `guestRole`, `defaultRole` or a `managerRoles` entry is not in `roles`, a
|
|
111
|
+
* role has no rules, or the guest role is a manager role.
|
|
112
|
+
*/
|
|
113
|
+
function definePermissions() {
|
|
114
|
+
return (config) => {
|
|
115
|
+
const { managerRoles, labels, directGrants, relations, ...authorizationConfig } = config;
|
|
116
|
+
return buildCatalog((0, _xtandard_lib_policy_permix.defineAuthorization)()({
|
|
117
|
+
...authorizationConfig,
|
|
118
|
+
getRole: (subject) => subject.role
|
|
119
|
+
}), {
|
|
120
|
+
...managerRoles ? { managerRoles } : {},
|
|
121
|
+
...labels ? { labels } : {},
|
|
122
|
+
...directGrants !== void 0 ? { directGrants } : {},
|
|
123
|
+
...relations ? { relations } : {}
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Wrap an existing lib `Authorization` (from `defineAuthorization`) as a catalog. Its config is
|
|
129
|
+
* re-defined with `getRole: (subject) => subject.role`, so its rules receive a
|
|
130
|
+
* {@link PermissionsSubject} (`{ id, role, name?, email?, attributes? }`) as `user`; rules that read
|
|
131
|
+
* other user fields must move them into `attributes` or `ctx`.
|
|
132
|
+
*/
|
|
133
|
+
function fromAuthorization(authorization, meta = {}) {
|
|
134
|
+
const { getRole: _ignored, ...config } = authorization.config;
|
|
135
|
+
return buildCatalog((0, _xtandard_lib_policy_permix.defineAuthorization)()({
|
|
136
|
+
...config,
|
|
137
|
+
getRole: (subject) => subject.role
|
|
138
|
+
}), meta);
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
Object.defineProperty(exports, "RelationDepthError", {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
get: function() {
|
|
144
|
+
return _xtandard_lib_policy_rebac.RelationDepthError;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
Object.defineProperty(exports, "RelationSchemaError", {
|
|
148
|
+
enumerable: true,
|
|
149
|
+
get: function() {
|
|
150
|
+
return _xtandard_lib_policy_rebac.RelationSchemaError;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
Object.defineProperty(exports, "computed", {
|
|
154
|
+
enumerable: true,
|
|
155
|
+
get: function() {
|
|
156
|
+
return _xtandard_lib_policy_rebac.computed;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
exports.definePermissions = definePermissions;
|
|
160
|
+
Object.defineProperty(exports, "defineRelations", {
|
|
161
|
+
enumerable: true,
|
|
162
|
+
get: function() {
|
|
163
|
+
return _xtandard_lib_policy_rebac.defineRelations;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
Object.defineProperty(exports, "direct", {
|
|
167
|
+
enumerable: true,
|
|
168
|
+
get: function() {
|
|
169
|
+
return _xtandard_lib_policy_rebac.direct;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
Object.defineProperty(exports, "exclusion", {
|
|
173
|
+
enumerable: true,
|
|
174
|
+
get: function() {
|
|
175
|
+
return _xtandard_lib_policy_rebac.exclusion;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
Object.defineProperty(exports, "from", {
|
|
179
|
+
enumerable: true,
|
|
180
|
+
get: function() {
|
|
181
|
+
return _xtandard_lib_policy_rebac.from;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
exports.fromAuthorization = fromAuthorization;
|
|
185
|
+
Object.defineProperty(exports, "intersection", {
|
|
186
|
+
enumerable: true,
|
|
187
|
+
get: function() {
|
|
188
|
+
return _xtandard_lib_policy_rebac.intersection;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
Object.defineProperty(exports, "union", {
|
|
192
|
+
enumerable: true,
|
|
193
|
+
get: function() {
|
|
194
|
+
return _xtandard_lib_policy_rebac.union;
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
//# sourceMappingURL=catalog.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.cjs","names":[],"sources":["../src/catalog.ts"],"sourcesContent":["/**\n * The catalog: roles, assignable permissions and per-role rules, declared once\n * in code and shared by the server, the browser and the admin panel (ADR 0002).\n *\n * `definePermissions()` wraps `defineAuthorization` from\n * `@xtandard/lib/policy/permix` (which owns role parsing, the assignable list,\n * the sync-only rule helpers, `createAbility` and `explain`) and adds what the\n * product needs on top: `managerRoles`, labels for the panel, the\n * `directGrants` switch and `effectiveRole()`. The rule user is fixed to\n * {@link PermissionsSubject}, whose `role` the engine sets to the subject's\n * effective role.\n *\n * Depends only on `@xtandard/lib/policy/permix` (and its `permix` peer), so\n * browsers and edge runtimes can import it.\n *\n * @example\n * ```ts\n * import { definePermissions } from \"@xtandard/permissions/catalog\";\n *\n * type Definition = { post: [\"read\", { name: \"publish\"; type: Post }, \"delete\"] };\n *\n * export const permissions = definePermissions<Definition>()({\n * roles: [\"guest\", \"member\", \"editor\", \"admin\"], // least → most privileged\n * guestRole: \"guest\",\n * defaultRole: \"member\",\n * managerRoles: [\"admin\"],\n * assignable: [\"post:moderate\", \"billing:refund\"],\n * labels: { roles: { admin: \"Administrator\" }, permissions: { \"post:moderate\": \"Moderate posts\" } },\n * rules: {\n * guest: () => ({ post: { read: true, publish: false, delete: false } }),\n * member: ({ user, permissions }, { or, fieldEquals, hasPermission }) => ({\n * post: {\n * read: true,\n * publish: or<Post>(fieldEquals(user!.id, { field: \"authorId\" }), () =>\n * hasPermission(permissions, \"post:moderate\"),\n * ),\n * delete: false,\n * },\n * }),\n * editor: () => ({ post: { read: true, publish: true, delete: false } }),\n * admin: () => ({ post: { read: true, publish: true, delete: true } }),\n * },\n * });\n * ```\n *\n * @module catalog\n */\n\nimport {\n defineAuthorization,\n defineRelations,\n type Authorization,\n type AuthorizationConfig,\n type Definition,\n type RelationSchema,\n} from \"./policy.ts\";\n\n/** A catalog without relations (ReBAC off): no object type, so no relation query type-checks. */\nexport type NoRelations = Record<never, never>;\n\nexport {\n computed,\n defineRelations,\n direct,\n exclusion,\n from,\n intersection,\n RelationDepthError,\n RelationSchemaError,\n union,\n} from \"./policy.ts\";\nexport type {\n ObjectRef,\n RelationExpr,\n RelationSchema,\n RelationTuple,\n SubjectRef,\n} from \"./policy.ts\";\n\n/** The user the rules see: the engine passes the subject with its effective `role`. */\nexport interface PermissionsSubject {\n /** The subject id (a user id in 0.1). */\n id: string;\n /** The effective role (stored assignment, else the auth provider's, else `defaultRole`). */\n role: string;\n name?: string;\n email?: string;\n /** Extra facts from the auth provider (claims, profile fields). */\n attributes?: Record<string, unknown>;\n}\n\n/**\n * Who a check is for, as an auth provider reports it. `role` may be one role, several (the most\n * privileged known one wins, see {@link PermissionsCatalog.effectiveRole}) or missing\n * (`defaultRole`); a stored role assignment overrides it.\n */\nexport interface SubjectIdentity {\n id: string;\n role?: string | readonly string[] | null;\n name?: string;\n email?: string;\n attributes?: Record<string, unknown>;\n}\n\n/** A human label: a string, or a label with a description. */\nexport type LabelInput = string | { label: string; description?: string };\n\n/** A normalized label. */\nexport interface Label {\n label: string;\n description?: string;\n}\n\n/** What `definePermissions` adds on top of the lib's `AuthorizationConfig`. */\nexport interface CatalogMeta<\n R extends string,\n P extends string,\n S extends RelationSchema = NoRelations,\n> {\n /**\n * The relation schema (ReBAC, ADR 0013), built with `defineRelations` and the `direct` /\n * `computed` / `from` / `union` / `intersection` / `exclusion` builders. Validated again here.\n * Without it, relationship writes and checks throw `RelationSchemaError`.\n */\n relations?: S;\n /**\n * Roles that may grant / revoke / assign roles by default (an auth provider can override it).\n * Default: the most privileged role (the last of `roles`).\n */\n managerRoles?: readonly R[];\n /** Labels and descriptions for the admin panel. Missing entries default to the key. */\n labels?: {\n roles?: Partial<Record<R, LabelInput>>;\n permissions?: Partial<Record<P, LabelInput>>;\n };\n /**\n * When `true`, a non-expired grant whose name equals the checked path allows it outright\n * (`reason: \"grant\"`), for catalogs whose assignable names are paths. Default `false`: grants\n * only matter through the rules (ADR 0005).\n */\n directGrants?: boolean;\n}\n\n/**\n * The configuration of {@link definePermissions}: the lib's `AuthorizationConfig` (roles ordered\n * **least → most privileged**, `guestRole`, `defaultRole`, `assignable`, `rules`) without\n * `getRole` (the engine sets the role), plus {@link CatalogMeta}.\n */\nexport type PermissionsConfig<\n D extends Definition,\n R extends string,\n P extends string,\n X,\n S extends RelationSchema = NoRelations,\n> = Omit<AuthorizationConfig<D, R, P, PermissionsSubject, X>, \"getRole\"> &\n CatalogMeta<NoInfer<R>, NoInfer<P>, S>;\n\n/** A catalog: the wrapped lib `Authorization` plus the product metadata. */\nexport interface PermissionsCatalog<\n D extends Definition = Definition,\n R extends string = string,\n P extends string = string,\n X = undefined,\n S extends RelationSchema = RelationSchema,\n> {\n /** The lib authorization (`createAbility`, `createRules`, `parseRole`, …). */\n readonly authorization: Authorization<D, R, P, PermissionsSubject, X>;\n /** Every role, least → most privileged. */\n readonly roles: readonly R[];\n /** The role of a request without a subject. */\n readonly guestRole: R;\n /** The role of a signed-in subject whose role is missing or unknown. */\n readonly defaultRole: R;\n /** The assignable permissions. */\n readonly assignable: readonly P[];\n /** Roles that may manage permissions by default. */\n readonly managerRoles: readonly R[];\n /** Labels for every role and permission (defaulting to the key). */\n readonly labels: {\n readonly roles: Readonly<Record<R, Label>>;\n readonly permissions: Readonly<Record<P, Label>>;\n };\n /** See {@link CatalogMeta.directGrants}. */\n readonly directGrants: boolean;\n /** The relation schema (ReBAC), `null` when the catalog declares none. */\n readonly relations: S | null;\n /** True when `value` is one of `roles`. */\n isRole(value: unknown): value is R;\n /** True when `value` is one of `assignable`. */\n isAssignable(value: unknown): value is P;\n /** True when `role` is one of `managerRoles`. */\n isManagerRole(role: unknown): boolean;\n /** A signed-in subject's role: `value` when it is a known non-guest role, else `defaultRole`. */\n parseRole(value: unknown): R;\n /**\n * The effective role of a signed-in subject from what an auth provider reports: one role, several\n * (an array, or a comma-separated string as better-auth's admin plugin stores them) → the most\n * privileged known one; none known (or missing) → `defaultRole`. Never the guest role.\n */\n effectiveRole(raw: string | readonly string[] | null | undefined): R;\n}\n\n/**\n * The permission type of a catalog: the `assignable` union, or `string` for a roles-only catalog\n * (`assignable: []` infers `never`, which no generic `AnyPermissionsCatalog` slot accepts because\n * rules are contravariant in it). Every permission is still rejected at runtime there.\n */\nexport type PermissionUnion<P extends string> = [P] extends [never] ? string : P;\n\n/** Any catalog (for generic constraints). */\n// oxlint-disable-next-line typescript/no-explicit-any -- variance: rules are contravariant in the role type.\nexport type AnyPermissionsCatalog = PermissionsCatalog<any, any, any, any, any>;\n\n/** The permix definition of a catalog. */\n// oxlint-disable-next-line typescript/no-explicit-any -- variance, see AnyPermissionsCatalog.\nexport type DefinitionOf<C> = C extends PermissionsCatalog<infer D, any, any, any, any> ? D : never;\n/** The role union of a catalog. */\nexport type RoleOf<C> = C extends { readonly roles: readonly (infer R)[] } ? R : never;\n/** The assignable-permission union of a catalog. */\nexport type PermissionOf<C> = C extends { readonly assignable: readonly (infer P)[] } ? P : never;\n/** The rule context (`ctx`) type of a catalog. */\n// oxlint-disable-next-line typescript/no-explicit-any -- variance, see AnyPermissionsCatalog.\nexport type CtxOf<C> = C extends PermissionsCatalog<any, any, any, infer X, any> ? X : never;\n/** The relation schema of a catalog. */\n// oxlint-disable-next-line typescript/no-explicit-any -- variance, see AnyPermissionsCatalog.\nexport type RelationsOf<C> = C extends PermissionsCatalog<any, any, any, any, infer S> ? S : never;\n\nconst normalizeLabel = (key: string, input: LabelInput | undefined): Label =>\n input === undefined\n ? { label: key }\n : typeof input === \"string\"\n ? { label: input }\n : { label: input.label, ...(input.description ? { description: input.description } : {}) };\n\nfunction labelMap<K extends string>(\n keys: readonly K[],\n inputs: Partial<Record<K, LabelInput>> | undefined,\n): Record<K, Label> {\n const out = Object.create(null) as Record<K, Label>;\n for (const key of keys) {\n out[key] = normalizeLabel(key, inputs && Object.hasOwn(inputs, key) ? inputs[key] : undefined);\n }\n return out;\n}\n\nfunction buildCatalog<\n D extends Definition,\n R extends string,\n P extends string,\n X,\n S extends RelationSchema,\n>(\n authorization: Authorization<D, R, P, PermissionsSubject, X>,\n meta: CatalogMeta<R, P, S>,\n): PermissionsCatalog<D, R, P, X, S> {\n const { roles, guestRole, defaultRole, assignable } = authorization.config;\n if (roles.length === 0) throw new Error(\"definePermissions: roles must not be empty\");\n const managerRoles = meta.managerRoles ?? [roles[roles.length - 1]!];\n for (const role of managerRoles) {\n if (!authorization.isRole(role)) {\n throw new Error(`definePermissions: managerRoles \"${role}\" is not in roles`);\n }\n if (role === guestRole) {\n throw new Error(`definePermissions: the guest role \"${role}\" can't be a manager role`);\n }\n }\n const managers = new Set<string>(managerRoles);\n const rank = new Map<string, number>(roles.map((role, index) => [role, index]));\n\n const effectiveRole = (raw: string | readonly string[] | null | undefined): R => {\n const candidates =\n typeof raw === \"string\" ? raw.split(\",\").map((s) => s.trim()) : Array.isArray(raw) ? raw : [];\n let best: R | undefined;\n for (const candidate of candidates) {\n // parseRole maps unknown / guest values to defaultRole; only keep real matches.\n if (!authorization.isRole(candidate) || candidate === guestRole) continue;\n if (best === undefined || rank.get(candidate)! > rank.get(best)!) best = candidate;\n }\n return best ?? authorization.parseRole(undefined);\n };\n\n return Object.freeze({\n authorization,\n roles,\n guestRole,\n defaultRole,\n assignable,\n managerRoles: Object.freeze([...managerRoles]),\n labels: Object.freeze({\n roles: Object.freeze(labelMap(roles, meta.labels?.roles)),\n permissions: Object.freeze(labelMap(assignable, meta.labels?.permissions)),\n }),\n directGrants: meta.directGrants ?? false,\n relations: meta.relations ? defineRelations(meta.relations) : null,\n isRole: authorization.isRole,\n isAssignable: authorization.isAssignable,\n isManagerRole: (role: unknown) => typeof role === \"string\" && managers.has(role),\n parseRole: authorization.parseRole,\n effectiveRole,\n });\n}\n\n/**\n * Define the catalog. Curried like the lib's `defineAuthorization`: the permix definition and the\n * rule context type go in the first call, the roles and permissions are inferred by the second:\n * `definePermissions<Definition, Ctx>()({ ... })`.\n *\n * Rules are synchronous (a rule that returns a Promise denies and throws `AsyncRuleError`); load\n * what they need first and pass it as `ctx` or as the checked data. A rule wrapped in the lib's\n * `asyncRule()` is evaluated only by the engine's async `check()` / `can()`, never by the\n * synchronous `ability()` (ADR 0005).\n *\n * @throws {Error} When `guestRole`, `defaultRole` or a `managerRoles` entry is not in `roles`, a\n * role has no rules, or the guest role is a manager role.\n */\nexport function definePermissions<D extends Definition, X = undefined>() {\n return <\n const R extends string,\n const P extends string,\n const S extends RelationSchema = NoRelations,\n >(\n config: PermissionsConfig<D, R, P, X, S>,\n ): PermissionsCatalog<D, R, PermissionUnion<P>, X, S> => {\n const { managerRoles, labels, directGrants, relations, ...authorizationConfig } = config;\n const authorization = defineAuthorization<D, PermissionsSubject, X>()<R, PermissionUnion<P>>({\n ...authorizationConfig,\n getRole: (subject: PermissionsSubject) => subject.role,\n } as unknown as AuthorizationConfig<D, R, PermissionUnion<P>, PermissionsSubject, X>);\n return buildCatalog<D, R, PermissionUnion<P>, X, S>(authorization, {\n ...(managerRoles ? { managerRoles } : {}),\n ...(labels ? { labels: labels as CatalogMeta<R, PermissionUnion<P>>[\"labels\"] } : {}),\n ...(directGrants !== undefined ? { directGrants } : {}),\n ...(relations ? { relations } : {}),\n });\n };\n}\n\n/**\n * Wrap an existing lib `Authorization` (from `defineAuthorization`) as a catalog. Its config is\n * re-defined with `getRole: (subject) => subject.role`, so its rules receive a\n * {@link PermissionsSubject} (`{ id, role, name?, email?, attributes? }`) as `user`; rules that read\n * other user fields must move them into `attributes` or `ctx`.\n */\nexport function fromAuthorization<\n D extends Definition,\n R extends string,\n P extends string,\n X,\n const S extends RelationSchema = NoRelations,\n>(\n // oxlint-disable-next-line typescript/no-explicit-any -- any user type: the rules are re-bound to PermissionsSubject.\n authorization: Authorization<D, R, P, any, X>,\n meta: CatalogMeta<NoInfer<R>, NoInfer<P>, S> = {},\n): PermissionsCatalog<D, R, P, X, S> {\n const { getRole: _ignored, ...config } = authorization.config;\n const rebound = defineAuthorization<D, PermissionsSubject, X>()<R, P>({\n ...(config as Omit<AuthorizationConfig<D, R, P, PermissionsSubject, X>, \"getRole\">),\n getRole: (subject) => subject.role,\n });\n return buildCatalog(rebound, meta);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmOA,MAAM,kBAAkB,KAAa,UACnC,UAAU,KAAA,IACN,EAAE,OAAO,IAAI,IACb,OAAO,UAAU,WACf,EAAE,OAAO,MAAM,IACf;CAAE,OAAO,MAAM;CAAO,GAAI,MAAM,cAAc,EAAE,aAAa,MAAM,YAAY,IAAI,CAAC;AAAG;AAE/F,SAAS,SACP,MACA,QACkB;CAClB,MAAM,MAAM,OAAO,OAAO,IAAI;CAC9B,KAAK,MAAM,OAAO,MAChB,IAAI,OAAO,eAAe,KAAK,UAAU,OAAO,OAAO,QAAQ,GAAG,IAAI,OAAO,OAAO,KAAA,CAAS;CAE/F,OAAO;AACT;AAEA,SAAS,aAOP,eACA,MACmC;CACnC,MAAM,EAAE,OAAO,WAAW,aAAa,eAAe,cAAc;CACpE,IAAI,MAAM,WAAW,GAAG,MAAM,IAAI,MAAM,4CAA4C;CACpF,MAAM,eAAe,KAAK,gBAAgB,CAAC,MAAM,MAAM,SAAS,EAAG;CACnE,KAAK,MAAM,QAAQ,cAAc;EAC/B,IAAI,CAAC,cAAc,OAAO,IAAI,GAC5B,MAAM,IAAI,MAAM,oCAAoC,KAAK,kBAAkB;EAE7E,IAAI,SAAS,WACX,MAAM,IAAI,MAAM,sCAAsC,KAAK,0BAA0B;CAEzF;CACA,MAAM,WAAW,IAAI,IAAY,YAAY;CAC7C,MAAM,OAAO,IAAI,IAAoB,MAAM,KAAK,MAAM,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC;CAE9E,MAAM,iBAAiB,QAA0D;EAC/E,MAAM,aACJ,OAAO,QAAQ,WAAW,IAAI,MAAM,GAAG,EAAE,KAAK,MAAM,EAAE,KAAK,CAAC,IAAI,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC;EAC9F,IAAI;EACJ,KAAK,MAAM,aAAa,YAAY;GAElC,IAAI,CAAC,cAAc,OAAO,SAAS,KAAK,cAAc,WAAW;GACjE,IAAI,SAAS,KAAA,KAAa,KAAK,IAAI,SAAS,IAAK,KAAK,IAAI,IAAI,GAAI,OAAO;EAC3E;EACA,OAAO,QAAQ,cAAc,UAAU,KAAA,CAAS;CAClD;CAEA,OAAO,OAAO,OAAO;EACnB;EACA;EACA;EACA;EACA;EACA,cAAc,OAAO,OAAO,CAAC,GAAG,YAAY,CAAC;EAC7C,QAAQ,OAAO,OAAO;GACpB,OAAO,OAAO,OAAO,SAAS,OAAO,KAAK,QAAQ,KAAK,CAAC;GACxD,aAAa,OAAO,OAAO,SAAS,YAAY,KAAK,QAAQ,WAAW,CAAC;EAC3E,CAAC;EACD,cAAc,KAAK,gBAAgB;EACnC,WAAW,KAAK,aAAA,GAAA,2BAAA,iBAA4B,KAAK,SAAS,IAAI;EAC9D,QAAQ,cAAc;EACtB,cAAc,cAAc;EAC5B,gBAAgB,SAAkB,OAAO,SAAS,YAAY,SAAS,IAAI,IAAI;EAC/E,WAAW,cAAc;EACzB;CACF,CAAC;AACH;;;;;;;;;;;;;;AAeA,SAAgB,oBAAyD;CACvE,QAKE,WACuD;EACvD,MAAM,EAAE,cAAc,QAAQ,cAAc,WAAW,GAAG,wBAAwB;EAKlF,OAAO,cAAA,GAAA,4BAAA,qBAJ6D,EAAyB;GAC3F,GAAG;GACH,UAAU,YAAgC,QAAQ;EACpD,CACgE,GAAG;GACjE,GAAI,eAAe,EAAE,aAAa,IAAI,CAAC;GACvC,GAAI,SAAS,EAAU,OAAuD,IAAI,CAAC;GACnF,GAAI,iBAAiB,KAAA,IAAY,EAAE,aAAa,IAAI,CAAC;GACrD,GAAI,YAAY,EAAE,UAAU,IAAI,CAAC;EACnC,CAAC;CACH;AACF;;;;;;;AAQA,SAAgB,kBAQd,eACA,OAA+C,CAAC,GACb;CACnC,MAAM,EAAE,SAAS,UAAU,GAAG,WAAW,cAAc;CAKvD,OAAO,cAAA,GAAA,4BAAA,qBAJuD,EAAQ;EACpE,GAAI;EACJ,UAAU,YAAY,QAAQ;CAChC,CAC0B,GAAG,IAAI;AACnC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { A as intersection, C as computed, D as from, E as exclusion, M as union, T as direct, b as SubjectRef, c as ObjectRef, f as RelationExpr, h as RelationTuple, m as RelationSchemaError, p as RelationSchema, u as RelationDepthError, w as defineRelations } from "./policy-DFq_SYR3.cjs";
|
|
2
|
+
import { _ as fromAuthorization, a as Label, c as PermissionOf, d as PermissionsConfig, f as PermissionsSubject, g as definePermissions, h as SubjectIdentity, i as DefinitionOf, l as PermissionUnion, m as RoleOf, n as CatalogMeta, o as LabelInput, p as RelationsOf, r as CtxOf, s as NoRelations, t as AnyPermissionsCatalog, u as PermissionsCatalog } from "./catalog-DA_d1SdC.cjs";
|
|
3
|
+
export { AnyPermissionsCatalog, CatalogMeta, CtxOf, DefinitionOf, Label, LabelInput, NoRelations, type ObjectRef, PermissionOf, PermissionUnion, PermissionsCatalog, PermissionsConfig, PermissionsSubject, RelationDepthError, type RelationExpr, type RelationSchema, RelationSchemaError, type RelationTuple, RelationsOf, RoleOf, SubjectIdentity, type SubjectRef, computed, definePermissions, defineRelations, direct, exclusion, from, fromAuthorization, intersection, union };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { A as intersection, C as computed, D as from, E as exclusion, M as union, T as direct, b as SubjectRef, c as ObjectRef, f as RelationExpr, h as RelationTuple, m as RelationSchemaError, p as RelationSchema, u as RelationDepthError, w as defineRelations } from "./policy-CGA6QD0a.mjs";
|
|
2
|
+
import { _ as fromAuthorization, a as Label, c as PermissionOf, d as PermissionsConfig, f as PermissionsSubject, g as definePermissions, h as SubjectIdentity, i as DefinitionOf, l as PermissionUnion, m as RoleOf, n as CatalogMeta, o as LabelInput, p as RelationsOf, r as CtxOf, s as NoRelations, t as AnyPermissionsCatalog, u as PermissionsCatalog } from "./catalog-DJcJ3ycq.mjs";
|
|
3
|
+
export { AnyPermissionsCatalog, CatalogMeta, CtxOf, DefinitionOf, Label, LabelInput, NoRelations, type ObjectRef, PermissionOf, PermissionUnion, PermissionsCatalog, PermissionsConfig, PermissionsSubject, RelationDepthError, type RelationExpr, type RelationSchema, RelationSchemaError, type RelationTuple, RelationsOf, RoleOf, SubjectIdentity, type SubjectRef, computed, definePermissions, defineRelations, direct, exclusion, from, fromAuthorization, intersection, union };
|