@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Santiago Montoya
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,365 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/xantiagoma/xtandard-permissions/main/docs/assets/lockup-horizontal-dark.svg" />
|
|
5
|
+
<img src="https://raw.githubusercontent.com/xantiagoma/xtandard-permissions/main/docs/assets/lockup-horizontal-light.svg" alt="xtandard-permissions" width="560" />
|
|
6
|
+
</picture>
|
|
7
|
+
|
|
8
|
+
**Roles, grants and permission checks for TypeScript apps — as a library.**
|
|
9
|
+
|
|
10
|
+
Declare roles, the permissions an admin can grant and the rules each role runs once, in code. Keep
|
|
11
|
+
per-user grants in your own database, check synchronously with reasons on the server and in the
|
|
12
|
+
browser, and plug in the auth library you already use. Your database, your process — no
|
|
13
|
+
authorization server to run.
|
|
14
|
+
|
|
15
|
+
[](https://github.com/xantiagoma/xtandard-permissions/actions/workflows/ci.yml)
|
|
16
|
+
[](https://www.npmjs.com/package/@xtandard/permissions)
|
|
17
|
+
[](./LICENSE)
|
|
18
|
+
[](https://me.xantiagoma.com/xtandard-permissions/)
|
|
19
|
+
|
|
20
|
+
**Documentation: [me.xantiagoma.com/xtandard-permissions](https://me.xantiagoma.com/xtandard-permissions/)** — guides and the full API reference.
|
|
21
|
+
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
> A check is pure code over loaded facts: one cached read, then a synchronous rule. Every decision
|
|
25
|
+
> says _why_ — which role, which grants, and whether a constant, a predicate or a missing rule
|
|
26
|
+
> decided.
|
|
27
|
+
|
|
28
|
+
## Contents
|
|
29
|
+
|
|
30
|
+
- [Why another permissions tool?](#why-another-permissions-tool)
|
|
31
|
+
- [Quick start](#quick-start)
|
|
32
|
+
- [The catalog](#the-catalog)
|
|
33
|
+
- [Checks](#checks)
|
|
34
|
+
- [Features](#features)
|
|
35
|
+
- [Storage](#storage)
|
|
36
|
+
- [Auth providers](#auth-providers)
|
|
37
|
+
- [better-auth plugin](#better-auth-plugin)
|
|
38
|
+
- [React](#react)
|
|
39
|
+
- [Admin panel](#admin-panel)
|
|
40
|
+
- [CLI and Docker](#cli-and-docker)
|
|
41
|
+
- [Subpath exports](#subpath-exports)
|
|
42
|
+
- [Documentation](#documentation)
|
|
43
|
+
- [Project status](#project-status)
|
|
44
|
+
- [The xtandard ecosystem](#the-xtandard-ecosystem)
|
|
45
|
+
- [License](#license)
|
|
46
|
+
|
|
47
|
+
## Why another permissions tool?
|
|
48
|
+
|
|
49
|
+
Every app ends up with `if (user.role === "admin")`, then "editors can publish their own posts",
|
|
50
|
+
then "give Ana refund rights until Friday", then "who granted that, and why?". The typed in-process
|
|
51
|
+
engines (CASL, permix, accesscontrol) store nothing and ship no admin UI; Casbin has storage but no
|
|
52
|
+
typed catalog; the Zanzibar-style systems (OpenFGA, SpiceDB, Permify, Cerbos) are servers to run; and
|
|
53
|
+
better-auth's access control checks static roles with no per-user grants or history
|
|
54
|
+
([research](./docs/research/landscape.md)).
|
|
55
|
+
|
|
56
|
+
`@xtandard/permissions` is the missing piece: a **typed catalog in code**, **per-user grants in any
|
|
57
|
+
storage** (unique and idempotent on every driver), **synchronous checks with reasons** evaluated by
|
|
58
|
+
`@xtandard/lib/policy` and permix, **auth-library integrations** (better-auth first), and an admin
|
|
59
|
+
panel — embedded in your app. **Relationship-based access** ("editors of the parent folder") runs
|
|
60
|
+
in-process too: a relation schema in the catalog, tuples in the same storage
|
|
61
|
+
([Relationships](./docs/REBAC.md), [ADR 0013](./docs/ADR/0013-rebac.md)); a Zanzibar server, policy
|
|
62
|
+
languages and identity stay out of scope ([non-goals](./docs/ADR/0012-non-goals.md)).
|
|
63
|
+
|
|
64
|
+
## Quick start
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
bun add @xtandard/permissions permix # or npm i / pnpm add
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
// permissions.ts — the catalog: import it on the server, in the browser and in the panel
|
|
72
|
+
import { definePermissions } from "@xtandard/permissions/catalog";
|
|
73
|
+
|
|
74
|
+
export interface Post {
|
|
75
|
+
id: string;
|
|
76
|
+
authorId: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const permissions = definePermissions<{
|
|
80
|
+
post: ["read", { name: "publish"; type: Post; required: true }];
|
|
81
|
+
}>()({
|
|
82
|
+
roles: ["guest", "member", "editor", "admin"], // least → most privileged
|
|
83
|
+
guestRole: "guest",
|
|
84
|
+
defaultRole: "member",
|
|
85
|
+
assignable: ["post:moderate"], // what an admin can grant one user
|
|
86
|
+
rules: {
|
|
87
|
+
guest: () => ({ post: { read: true, publish: () => false } }),
|
|
88
|
+
member: ({ user, permissions }, { or, fieldEquals, hasPermission }) => ({
|
|
89
|
+
post: {
|
|
90
|
+
read: true,
|
|
91
|
+
publish: or<Post>(fieldEquals(user!.id, { field: "authorId" }), () =>
|
|
92
|
+
hasPermission(permissions, "post:moderate"),
|
|
93
|
+
),
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
editor: () => ({ post: { read: true, publish: () => true } }),
|
|
97
|
+
admin: () => ({ post: { read: true, publish: () => true } }),
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
// server.ts
|
|
104
|
+
import { createPermissions } from "@xtandard/permissions";
|
|
105
|
+
import { createPostgresStorage } from "@xtandard/permissions/storage/postgres";
|
|
106
|
+
import { Pool } from "pg";
|
|
107
|
+
import { permissions } from "./permissions";
|
|
108
|
+
|
|
109
|
+
export const perms = createPermissions({
|
|
110
|
+
catalog: permissions,
|
|
111
|
+
storage: createPostgresStorage({
|
|
112
|
+
client: new Pool({ connectionString: process.env.DATABASE_URL }),
|
|
113
|
+
}),
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
await perms.grant({
|
|
117
|
+
subject: "user_1",
|
|
118
|
+
permission: "post:moderate",
|
|
119
|
+
actor: "admin_1",
|
|
120
|
+
reason: "On call",
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// In a handler: the subject as your auth library reports it.
|
|
124
|
+
const decision = await perms.check(
|
|
125
|
+
{ id: session.user.id, role: session.user.role },
|
|
126
|
+
"post.publish",
|
|
127
|
+
post,
|
|
128
|
+
);
|
|
129
|
+
if (!decision.allowed) return Response.json({ reason: decision.reason }, { status: 403 });
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Full walkthrough: [Getting started](./docs/GETTING_STARTED.md).
|
|
133
|
+
|
|
134
|
+
## The catalog
|
|
135
|
+
|
|
136
|
+
Roles are ordered **least → most privileged**, and the order is a contract: several roles from an auth
|
|
137
|
+
library resolve to the most privileged one, and the default manager is the last role. `guestRole` is
|
|
138
|
+
for requests without a session; `defaultRole` for a signed-in user whose role is missing or unknown —
|
|
139
|
+
never "the first role". `assignable` is the closed list an admin can grant, so a typo can't create a
|
|
140
|
+
grant nobody reads. Rules are synchronous permix rules with combinators (`or`, `and`, `fieldEquals`,
|
|
141
|
+
`within`, …); app facts come in as `ctx`; `asyncRule` is the escape hatch for a rule that must do I/O;
|
|
142
|
+
`directGrants` lets a grant named like a path allow it outright. → [Catalog](./docs/CATALOG.md)
|
|
143
|
+
|
|
144
|
+
## Checks
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
await perms.can(subject, "post.publish", post); // boolean
|
|
148
|
+
await perms.check(subject, "post.publish", post); // { allowed, role, reason, explanation }
|
|
149
|
+
|
|
150
|
+
// Many checks: load once, then everything is synchronous.
|
|
151
|
+
const ability = await perms.ability(subject);
|
|
152
|
+
const publishable = posts.filter((post) => ability.can("post.publish", post));
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
`reason` is `role-rule`, `denied-by-rule`, `rule-threw`, `unknown-path` or `grant`; `explanation` is
|
|
156
|
+
the role, the grants the rule saw, and whether a constant, a predicate, a throw or a missing path
|
|
157
|
+
decided. A rule that returns a Promise never reads as "allowed": the synchronous ability throws
|
|
158
|
+
`AsyncRuleError`. An empty subject id is `NoSubjectError`, never a guest. → [Checks](./docs/CHECKS.md)
|
|
159
|
+
|
|
160
|
+
## Features
|
|
161
|
+
|
|
162
|
+
- **Typed end to end** — paths, checked data, roles, permissions and `ctx` are inferred from the
|
|
163
|
+
catalog.
|
|
164
|
+
- **Grants are data** — one key per (subject, permission): unique on every driver, idempotent
|
|
165
|
+
`grant()` / `revoke()`, optional expiry, a reason, and `grantedBy` as a plain id (deleting the admin
|
|
166
|
+
never breaks a grant).
|
|
167
|
+
- **Relationships (ReBAC)** — a Zanzibar-style relation schema in the catalog (groups, nested
|
|
168
|
+
folders, public links, block lists), tuples in your storage, `checkRelation` with the path that
|
|
169
|
+
decided it, `listObjects` / `listRelationSubjects`, `requireRelation` guards, a panel view and
|
|
170
|
+
`useRelation`. → [Relationships](./docs/REBAC.md)
|
|
171
|
+
- **History** — every grant, revoke, role change and relationship, newest first, paginated.
|
|
172
|
+
- **Stored or external roles** — `setRole()` overrides the auth library's role per subject (the
|
|
173
|
+
panel's "make admin"), or `roleSource: "external"` leaves roles to the auth library, read by id
|
|
174
|
+
with `lookupSubject`. → [Who owns roles](./docs/AUTH.md#who-owns-roles)
|
|
175
|
+
- **Hooks** — `before` (veto) / `after` (side effects) around every write. → [Hooks](./docs/HOOKS.md)
|
|
176
|
+
- **Audit and webhooks** — `permissions.granted` / `.revoked` / `.role_changed` /
|
|
177
|
+
`.relationship_written` / `.relationship_deleted` into
|
|
178
|
+
`@xtandard/audit` and `@xtandard/webhooks`. → [Ecosystem](./docs/ECOSYSTEM.md)
|
|
179
|
+
- **Entitlements-aware** — pass `@xtandard/entitlements` decisions as `ctx`: "the plan pays for it
|
|
180
|
+
**and** the role allows it".
|
|
181
|
+
- **Cache with push invalidation** — per-subject, dropped on writes and on watchable storage events
|
|
182
|
+
from other instances.
|
|
183
|
+
- **Testing** — an in-memory engine with a controllable clock. → [Testing](./docs/TESTING.md)
|
|
184
|
+
|
|
185
|
+
## Storage
|
|
186
|
+
|
|
187
|
+
The same KV contract and ten drivers as every xtandard product: memory, file, Redis, Postgres,
|
|
188
|
+
Drizzle (pg / mysql / sqlite), MongoDB, SQLite (`bun:sqlite`), libSQL / Turso, unstorage and
|
|
189
|
+
Cloudflare KV, each wrapped with the permissions defaults and run through the kit's storage
|
|
190
|
+
conformance **and** a grant conformance suite. → [Storage](./docs/STORAGE.md)
|
|
191
|
+
|
|
192
|
+
| Subpath | Peer |
|
|
193
|
+
| --------------------------------------------------------------------- | ---------------- |
|
|
194
|
+
| `storage/memory` · `storage/file` | — |
|
|
195
|
+
| `storage/redis` | `redis` |
|
|
196
|
+
| `storage/postgres` | `pg` or PGlite |
|
|
197
|
+
| `storage/drizzle` + `drizzle/pg` · `drizzle/mysql` · `drizzle/sqlite` | `drizzle-orm` |
|
|
198
|
+
| `storage/mongodb` | `mongodb` |
|
|
199
|
+
| `storage/sqlite` | — (`bun:sqlite`) |
|
|
200
|
+
| `storage/libsql` | `@libsql/client` |
|
|
201
|
+
| `storage/unstorage` | `unstorage` |
|
|
202
|
+
| `storage/cloudflare-kv` | — (a binding) |
|
|
203
|
+
|
|
204
|
+
## Auth providers
|
|
205
|
+
|
|
206
|
+
The engine doesn't authenticate anyone: a small `PermissionsAuthProvider` says who is calling and
|
|
207
|
+
which role their auth library gives them.
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
import { betterAuthProvider } from "@xtandard/permissions/auth/better-auth";
|
|
211
|
+
import { sessionProvider } from "@xtandard/permissions/auth/session";
|
|
212
|
+
import { jwtProvider } from "@xtandard/permissions/auth/jwt";
|
|
213
|
+
|
|
214
|
+
betterAuthProvider(auth, { mapRole: { user: "member" } }); // or roleSource: "organization"
|
|
215
|
+
sessionProvider({ getSession, map: (s) => ({ id: s.user.id, role: s.user.role }) }); // Auth.js, Clerk, Lucia, …
|
|
216
|
+
jwtProvider({ jwks: "https://idp.example.com/.well-known/jwks.json", audience: "my-api" });
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
`toKitAuth(provider, perms)` turns any of them into the kit's auth + authorization pair for panels and
|
|
220
|
+
routers. If the auth library owns roles, `createPermissions({ ..., ...externalRoles(provider) })`
|
|
221
|
+
makes them read-only here and resolves them by id. → [Auth](./docs/AUTH.md)
|
|
222
|
+
|
|
223
|
+
## better-auth plugin
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
import { betterAuth } from "better-auth";
|
|
227
|
+
import { admin } from "better-auth/plugins";
|
|
228
|
+
import { permissions } from "@xtandard/permissions/better-auth";
|
|
229
|
+
|
|
230
|
+
export const auth = betterAuth({
|
|
231
|
+
plugins: [admin(), permissions({ engine: perms, mapRole: { user: "member" } })],
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// Client: authClient.permissions.{me,check,list,grant,revoke,history}, typed from your catalog.
|
|
235
|
+
import { permissionsClient } from "@xtandard/permissions/better-auth/client";
|
|
236
|
+
createAuthClient({ plugins: [permissionsClient<typeof perms>()] });
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Six endpoints under `/api/auth/permissions/*`, no extra tables (grants live in the engine's storage,
|
|
240
|
+
so it works with every better-auth database adapter). → [Auth: better-auth](./docs/AUTH.md#better-auth)
|
|
241
|
+
|
|
242
|
+
## React
|
|
243
|
+
|
|
244
|
+
```tsx
|
|
245
|
+
import { Can, PermissionsProvider, useCan } from "@xtandard/permissions/react";
|
|
246
|
+
|
|
247
|
+
<PermissionsProvider catalog={permissions} snapshot={snapshot /* perms.snapshot(subject) */}>
|
|
248
|
+
<Can path="post.publish" data={post} fallback={<span>Waiting for review</span>}>
|
|
249
|
+
<PublishButton post={post} />
|
|
250
|
+
</Can>
|
|
251
|
+
</PermissionsProvider>;
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
The browser rebuilds the subject's ability from a small snapshot and the **same** catalog, so every
|
|
255
|
+
`useCan` / `<Can>` is a local, synchronous call — no request per check. Hydrate it from SSR
|
|
256
|
+
(`perms.snapshot(subject)`, or `permissionsFromHeaders` in Next.js server components), from the
|
|
257
|
+
panel's `GET /api/me`, or from better-auth. `createPermissionsReact<typeof permissions>()` types every
|
|
258
|
+
path and its data. Client gates are UX; the server check stays the authority. → [React](./docs/REACT.md)
|
|
259
|
+
|
|
260
|
+
## Admin panel
|
|
261
|
+
|
|
262
|
+
<picture>
|
|
263
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/xantiagoma/xtandard-permissions/main/docs/assets/screenshots/ui-subject-dark.png" />
|
|
264
|
+
<img src="https://raw.githubusercontent.com/xantiagoma/xtandard-permissions/main/docs/assets/screenshots/ui-subject-light.png" alt="Admin panel, subject detail: effective role, grants with who granted them, when, why and until when, and recent history" width="800" />
|
|
265
|
+
</picture>
|
|
266
|
+
|
|
267
|
+
Subjects with their effective role and grants; grant (with a reason and an optional expiry), revoke
|
|
268
|
+
and change roles; the catalog; a **check playground** that shows the full explanation; and the
|
|
269
|
+
history. Mount it with one line per framework, guard your own routes with the same engine:
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
import { permissionsPanel, requirePermission } from "@xtandard/permissions/hono";
|
|
273
|
+
|
|
274
|
+
app.route(
|
|
275
|
+
"/permissions",
|
|
276
|
+
permissionsPanel({ permissions: perms, provider, basePath: "/permissions" }),
|
|
277
|
+
);
|
|
278
|
+
app.post("/refunds", requirePermission(perms, "billing.refund", { provider }), (c) =>
|
|
279
|
+
c.json({ ok: true }),
|
|
280
|
+
);
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Adapters for Bun, Elysia (1 and 2), Express, Hono and Next.js; the panel as a React component with
|
|
284
|
+
`@xtandard/permissions/react/embed`. With `provider`, your auth library says who is calling and the
|
|
285
|
+
catalog's `managerRoles` say who may manage; operator accounts (`basicAuth` + `rolesAuthorization`)
|
|
286
|
+
work too. → [UI](./docs/UI.md) · [HTTP API](./docs/HTTP_API.md) ·
|
|
287
|
+
[Authorization](./docs/AUTHORIZATION.md)
|
|
288
|
+
|
|
289
|
+
## CLI and Docker
|
|
290
|
+
|
|
291
|
+
```sh
|
|
292
|
+
npx @xtandard/permissions serve --catalog ./src/permissions.ts --port 3006 # the panel, no Docker
|
|
293
|
+
xtandard-permissions grant --catalog ./permissions.ts --subject user_42 \
|
|
294
|
+
--permission billing:refund --expires-at 2026-12-31T00:00:00Z --reason "ticket #123"
|
|
295
|
+
xtandard-permissions check --catalog ./permissions.ts --subject user_42 --path billing.refund # exit 2 when denied
|
|
296
|
+
|
|
297
|
+
docker build -f apps/standalone/Dockerfile -t xtandard-permissions .
|
|
298
|
+
docker run -p 3000:3000 -v $PWD/permissions.ts:/app/permissions.ts \
|
|
299
|
+
-e PERMISSIONS_CATALOG=/app/permissions.ts -e STORAGE_DRIVER=postgres -e DATABASE_URL=postgres://… \
|
|
300
|
+
-e AUTH_MODE=basic -e AUTH_PASSWORD_HASH='<scrypt hash>' xtandard-permissions
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
`serve`, `check`, `grant`, `revoke`, `list`, `history`, `rel` (relationships: `write`, `delete`,
|
|
304
|
+
`check`, `list`, `objects`, `subjects`, `repair`) and `catalog` work on the same storage as your
|
|
305
|
+
app; the image serves the panel and the HTTP API with your catalog mounted. → [Deployment](./docs/DEPLOYMENT.md)
|
|
306
|
+
|
|
307
|
+
## Subpath exports
|
|
308
|
+
|
|
309
|
+
| Import | What |
|
|
310
|
+
| ------------------------------------------------------------------------ | ----------------------------------------------------------------- |
|
|
311
|
+
| `@xtandard/permissions` | `createPermissions`, the catalog DSL, schemas, errors, contracts |
|
|
312
|
+
| `@xtandard/permissions/catalog` | `definePermissions`, `fromAuthorization` (browser- and edge-safe) |
|
|
313
|
+
| `@xtandard/permissions/storage/*` · `/drizzle/*` | storage drivers and Drizzle tables |
|
|
314
|
+
| `@xtandard/permissions/auth/{better-auth,session,jwt}` | auth providers |
|
|
315
|
+
| `@xtandard/permissions/better-auth` · `/better-auth/client` | the better-auth server and client plugins |
|
|
316
|
+
| `@xtandard/permissions/bridges/audit` · `/bridges/webhooks` | `@xtandard/audit` and `@xtandard/webhooks` bridges |
|
|
317
|
+
| `@xtandard/permissions/hooks/log` | a logging hook |
|
|
318
|
+
| `@xtandard/permissions/{bun,elysia,elysia2,express,hono,next}` | the admin panel + `requirePermission` guards |
|
|
319
|
+
| `@xtandard/permissions/auth/{none,basic,delegated}` · `/authorization/*` | panel auth and authorization, `permissionsAuthorization` |
|
|
320
|
+
| `@xtandard/permissions/react` · `/react/embed` | hooks + `<Can>`; the embedded admin panel |
|
|
321
|
+
| `@xtandard/permissions/testing` | an in-memory engine with a test clock |
|
|
322
|
+
|
|
323
|
+
The `xtandard-permissions` bin is the CLI.
|
|
324
|
+
|
|
325
|
+
## Documentation
|
|
326
|
+
|
|
327
|
+
[Getting started](./docs/GETTING_STARTED.md) · [Catalog](./docs/CATALOG.md) ·
|
|
328
|
+
[Checks](./docs/CHECKS.md) · [Relationships](./docs/REBAC.md) · [Storage](./docs/STORAGE.md) · [Auth](./docs/AUTH.md) ·
|
|
329
|
+
[Authorization](./docs/AUTHORIZATION.md) · [Hooks](./docs/HOOKS.md) ·
|
|
330
|
+
[Ecosystem](./docs/ECOSYSTEM.md) · [HTTP API](./docs/HTTP_API.md) · [UI](./docs/UI.md) ·
|
|
331
|
+
[React](./docs/REACT.md) · [Deployment](./docs/DEPLOYMENT.md) ·
|
|
332
|
+
[Architecture](./docs/ARCHITECTURE.md) · [Testing](./docs/TESTING.md) ·
|
|
333
|
+
[Releases](./docs/RELEASES.md) · [Brand](./docs/BRAND.md) ·
|
|
334
|
+
[Decisions (ADRs)](./docs/ADR/README.md)
|
|
335
|
+
|
|
336
|
+
## Project status
|
|
337
|
+
|
|
338
|
+
`0.x` (ZeroVer): the API is stabilizing; minor versions may break, patches don't. See the
|
|
339
|
+
[CHANGELOG](./CHANGELOG.md).
|
|
340
|
+
|
|
341
|
+
## The xtandard ecosystem
|
|
342
|
+
|
|
343
|
+
`@xtandard/permissions` is one of a family of open-source, MIT-licensed projects that share the xtandard name. They are independent of each other: use any of them on its own. The products share their building blocks through `@xtandard/kit`, a regular dependency you never install or configure yourself.
|
|
344
|
+
|
|
345
|
+
| Project | What it is | Links |
|
|
346
|
+
| ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
347
|
+
| **`@xtandard/permissions`** (this package) | An embeddable permissions service: a typed catalog of roles and assignable permissions in code, per-user grants in any storage, synchronous checks with reasons, auth-library integrations and an admin panel | [Docs](https://me.xantiagoma.com/xtandard-permissions/) · [GitHub](https://github.com/xantiagoma/xtandard-permissions) · [npm](https://www.npmjs.com/package/@xtandard/permissions) |
|
|
348
|
+
| **`@xtandard/entitlements`** | An embeddable entitlements, plans and usage-metering engine: typed catalog, atomic metering, any billing provider, admin UI and customer portal | [Docs](https://me.xantiagoma.com/xtandard-entitlements/) · [GitHub](https://github.com/xantiagoma/xtandard-entitlements) · [npm](https://www.npmjs.com/package/@xtandard/entitlements) |
|
|
349
|
+
| **`@xtandard/kit`** | The shared building blocks of the xtandard products: storage drivers and conformance suite, auth, HTTP plumbing, adapters, admin shell and tooling | [Docs](https://me.xantiagoma.com/xtandard-kit/) · [GitHub](https://github.com/xantiagoma/xtandard-kit) · [npm](https://www.npmjs.com/package/@xtandard/kit) |
|
|
350
|
+
| **`@xtandard/lib`** | Lightweight, type-safe TypeScript utilities with a zero-dependency core | [Docs](https://me.xantiagoma.com/xtandard/) · [GitHub](https://github.com/xantiagoma/xtandard) · [npm](https://www.npmjs.com/package/@xtandard/lib) |
|
|
351
|
+
| **`@xtandard/flags`** | A self-hosted, embeddable, OpenFeature-compatible feature-flag control plane with pluggable storage | [Docs](https://me.xantiagoma.com/xtandard-flags/) · [GitHub](https://github.com/xantiagoma/xtandard-flags) · [npm](https://www.npmjs.com/package/@xtandard/flags) |
|
|
352
|
+
| **`@xtandard/webhooks`** | A self-hosted, embeddable, Standard Webhooks-compliant outbound-webhooks control plane: a Svix alternative as a library | [Docs](https://me.xantiagoma.com/xtandard-webhooks/) · [GitHub](https://github.com/xantiagoma/xtandard-webhooks) · [npm](https://www.npmjs.com/package/@xtandard/webhooks) |
|
|
353
|
+
| **`@xtandard/audit`** | A self-hosted, embeddable, tamper-evident audit-log control plane for B2B SaaS: a WorkOS Audit Logs alternative as a library | [Docs](https://me.xantiagoma.com/xtandard-audit/) · [GitHub](https://github.com/xantiagoma/xtandard-audit) · [npm](https://www.npmjs.com/package/@xtandard/audit) |
|
|
354
|
+
| **`@xtandard/links`** | Self-hosted, embeddable branded short links with click analytics, conversion attribution and deep links: a Dub / Bitly alternative as a library | [Docs](https://me.xantiagoma.com/xtandard-links/) · [GitHub](https://github.com/xantiagoma/xtandard-links) · [npm](https://www.npmjs.com/package/@xtandard/links) |
|
|
355
|
+
| **`@xtandard/xyte`** | A Zyte API-compatible `/v1/extract` client and server that runs on any proxy provider, or none | [Docs](https://me.xantiagoma.com/xyte/) · [GitHub](https://github.com/xantiagoma/xyte) · [npm](https://www.npmjs.com/package/@xtandard/xyte) |
|
|
356
|
+
| **xtandard-image** | A self-hosted image and video processing server in Go and libvips: imgproxy-compatible URLs plus the imgix, Cloudinary, ImageKit, Cloudflare and Thumbor dialects, with a TypeScript client (`@xtandard/image`) | [Docs](https://me.xantiagoma.com/xtandard-image/) · [GitHub](https://github.com/xantiagoma/xtandard-image) · [npm](https://www.npmjs.com/package/@xtandard/image) |
|
|
357
|
+
|
|
358
|
+
### Related
|
|
359
|
+
|
|
360
|
+
- [drizzle-cursor](https://github.com/xantiagoma/drizzle-cursor): cursor-based pagination for Drizzle ORM
|
|
361
|
+
- [drizzle-audit](https://github.com/xantiagoma/drizzle-audit): configurable audit logging for Drizzle ORM — pairs with `@xtandard/audit/drizzle-audit` to give customers a verifiable log
|
|
362
|
+
|
|
363
|
+
## License
|
|
364
|
+
|
|
365
|
+
[MIT](./LICENSE)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { i as normalizeRoles, n as identity, o as stringField } from "./contract-BganM0fx.mjs";
|
|
2
|
+
//#region src/auth-provider/better-auth.ts
|
|
3
|
+
/**
|
|
4
|
+
* better-auth as a {@link PermissionsAuthProvider} (ADR 0006/0007). The subject is the better-auth
|
|
5
|
+
* user; the role comes from the admin plugin's `user.role` (comma-separated, e.g. `"admin,user"`)
|
|
6
|
+
* or, with `roleSource: "organization"`, from the caller's member role in the active organization.
|
|
7
|
+
*
|
|
8
|
+
* No runtime import of better-auth: `auth` is typed structurally, so any `betterAuth()` instance
|
|
9
|
+
* (with or without plugins) is accepted.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
/** Narrow better-auth's `getSession` result. */
|
|
14
|
+
function asBetterAuthSession(value) {
|
|
15
|
+
if (!value || typeof value !== "object") return null;
|
|
16
|
+
const { user, session } = value;
|
|
17
|
+
if (!stringField(user, "id") || !session || typeof session !== "object") return null;
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the raw role for a better-auth session (shared with the server plugin).
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
async function betterAuthRole(auth, session, headers, options) {
|
|
25
|
+
if (options.roleSource !== "organization") return normalizeRoles(session.user.role, options.mapRole);
|
|
26
|
+
if (!session.session.activeOrganizationId) return null;
|
|
27
|
+
return normalizeRoles((await auth.api.getActiveMemberRole({ headers }))?.role, options.mapRole);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The subject identity of a better-auth session (shared with the server plugin).
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
async function betterAuthIdentity(auth, session, headers, options) {
|
|
34
|
+
const attributes = {};
|
|
35
|
+
const org = session.session.activeOrganizationId;
|
|
36
|
+
if (typeof org === "string" && org) attributes.activeOrganizationId = org;
|
|
37
|
+
Object.assign(attributes, options.attributes?.(session));
|
|
38
|
+
return identity({
|
|
39
|
+
id: session.user.id,
|
|
40
|
+
role: await betterAuthRole(auth, session, headers, options),
|
|
41
|
+
name: stringField(session.user, "name"),
|
|
42
|
+
email: stringField(session.user, "email"),
|
|
43
|
+
attributes
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/** Throw early when `roleSource: "organization"` is used without the organization plugin. */
|
|
47
|
+
function assertRoleSource(auth, options) {
|
|
48
|
+
if (options.roleSource === "organization" && typeof auth.api.getActiveMemberRole !== "function") throw new TypeError("betterAuthProvider: roleSource \"organization\" needs better-auth's organization plugin (auth.api.getActiveMemberRole)");
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The identity of a better-auth user looked up by id (shared with tests).
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
async function betterAuthLookup(auth, id, options) {
|
|
55
|
+
if (!auth.$context) throw new TypeError("betterAuthProvider: lookupSubject needs auth.$context (pass the betterAuth() instance)");
|
|
56
|
+
const user = await (await auth.$context).internalAdapter.findUserById(id);
|
|
57
|
+
const userId = stringField(user, "id");
|
|
58
|
+
if (!userId) return null;
|
|
59
|
+
const raw = user.role;
|
|
60
|
+
return identity({
|
|
61
|
+
id: userId,
|
|
62
|
+
role: options.roleSource === "organization" ? null : normalizeRoles(raw, options.mapRole),
|
|
63
|
+
name: stringField(user, "name"),
|
|
64
|
+
email: stringField(user, "email")
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A {@link PermissionsAuthProvider} over a `betterAuth()` instance, with `lookupSubject` (ADR 0014).
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { betterAuthProvider } from "@xtandard/permissions/auth/better-auth";
|
|
73
|
+
*
|
|
74
|
+
* const provider = betterAuthProvider(auth, { mapRole: { user: "member" } });
|
|
75
|
+
* const { auth: kitAuth, authorization } = toKitAuth(provider, perms);
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
function betterAuthProvider(auth, options = {}) {
|
|
79
|
+
assertRoleSource(auth, options);
|
|
80
|
+
const provider = {
|
|
81
|
+
async getSubject(request) {
|
|
82
|
+
const session = asBetterAuthSession(await auth.api.getSession({ headers: request.headers }));
|
|
83
|
+
if (!session) return null;
|
|
84
|
+
return betterAuthIdentity(auth, session, request.headers, options);
|
|
85
|
+
},
|
|
86
|
+
lookupSubject: (id) => betterAuthLookup(auth, id, options)
|
|
87
|
+
};
|
|
88
|
+
if (options.canManage) provider.canManage = options.canManage;
|
|
89
|
+
return provider;
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
export { betterAuthIdentity as n, betterAuthProvider as r, asBetterAuthSession as t };
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=better-auth-BEmX8qyz.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"better-auth-BEmX8qyz.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 type SubjectIdentity,\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 * `auth.$context`: its `internalAdapter.findUserById(id)` backs `lookupSubject` (server-side, no\n * headers). Every `betterAuth()` instance has it.\n */\n $context?: PromiseLike<{\n internalAdapter: { findUserById(id: string): Promise<unknown> };\n }>;\n}\n\n/** {@link betterAuthProvider}'s provider: `lookupSubject` is always there. */\nexport interface BetterAuthPermissionsProvider extends PermissionsAuthProvider {\n /**\n * The better-auth user by id (`internalAdapter.findUserById`), its admin-plugin `user.role` split\n * and mapped like `getSubject`'s; `null` for an unknown id. With `roleSource: \"organization\"`\n * the role is `null` (an organization role needs a session's active organization).\n */\n lookupSubject(id: string): Promise<SubjectIdentity | null>;\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 * The identity of a better-auth user looked up by id (shared with tests).\n * @internal\n */\nexport async function betterAuthLookup(\n auth: BetterAuthLike,\n id: string,\n options: BetterAuthProviderOptions,\n): Promise<SubjectIdentity | null> {\n if (!auth.$context) {\n throw new TypeError(\n \"betterAuthProvider: lookupSubject needs auth.$context (pass the betterAuth() instance)\",\n );\n }\n const context = await auth.$context;\n const user = await context.internalAdapter.findUserById(id);\n const userId = stringField(user, \"id\");\n if (!userId) return null;\n const raw = (user as { role?: unknown }).role;\n return identity({\n id: userId,\n role: options.roleSource === \"organization\" ? null : normalizeRoles(raw, options.mapRole),\n name: stringField(user, \"name\"),\n email: stringField(user, \"email\"),\n });\n}\n\n/**\n * A {@link PermissionsAuthProvider} over a `betterAuth()` instance, with `lookupSubject` (ADR 0014).\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): BetterAuthPermissionsProvider {\n assertRoleSource(auth, options);\n const provider: BetterAuthPermissionsProvider = {\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 lookupSubject: (id) => betterAuthLookup(auth, id, options),\n };\n if (options.canManage) provider.canManage = options.canManage;\n return provider;\n}\n"],"mappings":";;;;;;;;;;;;;AAwEA,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;;;;;AAMA,eAAsB,iBACpB,MACA,IACA,SACiC;CACjC,IAAI,CAAC,KAAK,UACR,MAAM,IAAI,UACR,wFACF;CAGF,MAAM,OAAO,OAAM,MADG,KAAK,UACA,gBAAgB,aAAa,EAAE;CAC1D,MAAM,SAAS,YAAY,MAAM,IAAI;CACrC,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,MAAO,KAA4B;CACzC,OAAO,SAAS;EACd,IAAI;EACJ,MAAM,QAAQ,eAAe,iBAAiB,OAAO,eAAe,KAAK,QAAQ,OAAO;EACxF,MAAM,YAAY,MAAM,MAAM;EAC9B,OAAO,YAAY,MAAM,OAAO;CAClC,CAAC;AACH;;;;;;;;;;;;AAaA,SAAgB,mBACd,MACA,UAAqC,CAAC,GACP;CAC/B,iBAAiB,MAAM,OAAO;CAC9B,MAAM,WAA0C;EAC9C,MAAM,WAAW,SAAS;GACxB,MAAM,UAAU,oBAAoB,MAAM,KAAK,IAAI,WAAW,EAAE,SAAS,QAAQ,QAAQ,CAAC,CAAC;GAC3F,IAAI,CAAC,SAAS,OAAO;GACrB,OAAO,mBAAmB,MAAM,SAAS,QAAQ,SAAS,OAAO;EACnE;EACA,gBAAgB,OAAO,iBAAiB,MAAM,IAAI,OAAO;CAC3D;CACA,IAAI,QAAQ,WAAW,SAAS,YAAY,QAAQ;CACpD,OAAO;AACT"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { h as SubjectIdentity } from "./catalog-DJcJ3ycq.mjs";
|
|
2
|
+
import { n as ProviderRoleOptions, t as PermissionsAuthProvider } from "./contract-D6j-yrBL.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/auth-provider/better-auth.d.ts
|
|
5
|
+
/** The part of a `betterAuth()` instance this provider calls (structural). */
|
|
6
|
+
interface BetterAuthLike {
|
|
7
|
+
api: {
|
|
8
|
+
/** `auth.api.getSession({ headers })` → `{ session, user } | null`. */getSession(context: {
|
|
9
|
+
headers: Headers;
|
|
10
|
+
}): Promise<unknown>; /** Organization plugin: `auth.api.getActiveMemberRole({ headers })` → `{ role }`. */
|
|
11
|
+
getActiveMemberRole?(context: {
|
|
12
|
+
headers: Headers;
|
|
13
|
+
}): Promise<unknown>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* `auth.$context`: its `internalAdapter.findUserById(id)` backs `lookupSubject` (server-side, no
|
|
17
|
+
* headers). Every `betterAuth()` instance has it.
|
|
18
|
+
*/
|
|
19
|
+
$context?: PromiseLike<{
|
|
20
|
+
internalAdapter: {
|
|
21
|
+
findUserById(id: string): Promise<unknown>;
|
|
22
|
+
};
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
/** {@link betterAuthProvider}'s provider: `lookupSubject` is always there. */
|
|
26
|
+
interface BetterAuthPermissionsProvider extends PermissionsAuthProvider {
|
|
27
|
+
/**
|
|
28
|
+
* The better-auth user by id (`internalAdapter.findUserById`), its admin-plugin `user.role` split
|
|
29
|
+
* and mapped like `getSubject`'s; `null` for an unknown id. With `roleSource: "organization"`
|
|
30
|
+
* the role is `null` (an organization role needs a session's active organization).
|
|
31
|
+
*/
|
|
32
|
+
lookupSubject(id: string): Promise<SubjectIdentity | null>;
|
|
33
|
+
}
|
|
34
|
+
/** The session shape the provider reads (a structural subset of better-auth's). */
|
|
35
|
+
interface BetterAuthSessionLike {
|
|
36
|
+
user: {
|
|
37
|
+
id: string;
|
|
38
|
+
name?: string | null;
|
|
39
|
+
email?: string | null;
|
|
40
|
+
role?: string | string[] | null;
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
};
|
|
43
|
+
session: {
|
|
44
|
+
activeOrganizationId?: string | null;
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** Options for {@link betterAuthProvider}. */
|
|
49
|
+
interface BetterAuthProviderOptions extends ProviderRoleOptions {
|
|
50
|
+
/**
|
|
51
|
+
* Where the raw role comes from. `"user"` (default): the admin plugin's `user.role`.
|
|
52
|
+
* `"organization"`: the caller's role in `session.activeOrganizationId` (organization plugin);
|
|
53
|
+
* without an active organization the role is empty (the catalog's `defaultRole`).
|
|
54
|
+
*/
|
|
55
|
+
roleSource?: "user" | "organization";
|
|
56
|
+
/** Extra subject attributes from the session (merged after `activeOrganizationId`). */
|
|
57
|
+
attributes?(session: BetterAuthSessionLike): Record<string, unknown> | undefined;
|
|
58
|
+
}
|
|
59
|
+
/** Narrow better-auth's `getSession` result. */
|
|
60
|
+
declare function asBetterAuthSession(value: unknown): BetterAuthSessionLike | null;
|
|
61
|
+
/**
|
|
62
|
+
* A {@link PermissionsAuthProvider} over a `betterAuth()` instance, with `lookupSubject` (ADR 0014).
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { betterAuthProvider } from "@xtandard/permissions/auth/better-auth";
|
|
67
|
+
*
|
|
68
|
+
* const provider = betterAuthProvider(auth, { mapRole: { user: "member" } });
|
|
69
|
+
* const { auth: kitAuth, authorization } = toKitAuth(provider, perms);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare function betterAuthProvider(auth: BetterAuthLike, options?: BetterAuthProviderOptions): BetterAuthPermissionsProvider;
|
|
73
|
+
//#endregion
|
|
74
|
+
export { asBetterAuthSession as a, BetterAuthSessionLike as i, BetterAuthPermissionsProvider as n, betterAuthProvider as o, BetterAuthProviderOptions as r, BetterAuthLike as t };
|
|
75
|
+
//# sourceMappingURL=better-auth-DQET1sXa.d.mts.map
|