@xtandard/permissions 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +364 -2
- package/bin/xtandard-permissions.mjs +3 -0
- package/dist/better-auth-BEmX8qyz.mjs +94 -0
- package/dist/better-auth-BEmX8qyz.mjs.map +1 -0
- package/dist/better-auth-DQET1sXa.d.mts +75 -0
- package/dist/better-auth-MR7dBtpo.cjs +111 -0
- package/dist/better-auth-MR7dBtpo.cjs.map +1 -0
- package/dist/better-auth-vgRYgjYK.d.cts +75 -0
- package/dist/catalog-DA_d1SdC.d.cts +153 -0
- package/dist/catalog-DJcJ3ycq.d.mts +153 -0
- package/dist/catalog.cjs +198 -0
- package/dist/catalog.cjs.map +1 -0
- package/dist/catalog.d.cts +3 -0
- package/dist/catalog.d.mts +3 -0
- package/dist/catalog.mjs +141 -0
- package/dist/catalog.mjs.map +1 -0
- package/dist/chunk-DakpK96I.cjs +43 -0
- package/dist/cli.cjs +554 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +28 -0
- package/dist/cli.d.mts +28 -0
- package/dist/cli.mjs +550 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/contract-BAisPHBw.d.cts +78 -0
- package/dist/contract-BganM0fx.mjs +79 -0
- package/dist/contract-BganM0fx.mjs.map +1 -0
- package/dist/contract-Bpy8yPrS.cjs +70 -0
- package/dist/contract-Bpy8yPrS.cjs.map +1 -0
- package/dist/contract-Brnu9XXo.cjs +114 -0
- package/dist/contract-Brnu9XXo.cjs.map +1 -0
- package/dist/contract-CNgMXr2u.d.cts +46 -0
- package/dist/contract-CNgMXr2u.d.mts +46 -0
- package/dist/contract-CXPMGuHk.d.cts +391 -0
- package/dist/contract-D6j-yrBL.d.mts +78 -0
- package/dist/contract-DTdTXZtJ.mjs +47 -0
- package/dist/contract-DTdTXZtJ.mjs.map +1 -0
- package/dist/contract-DhS23Pcp.d.mts +391 -0
- package/dist/contract-RMkmERhT.d.cts +2 -0
- package/dist/contract-RMkmERhT.d.mts +2 -0
- package/dist/create-fetch-handler-B0twltQL.mjs +673 -0
- package/dist/create-fetch-handler-B0twltQL.mjs.map +1 -0
- package/dist/create-fetch-handler-B711wb64.d.mts +77 -0
- package/dist/create-fetch-handler-BHT4vSZs.cjs +690 -0
- package/dist/create-fetch-handler-BHT4vSZs.cjs.map +1 -0
- package/dist/create-fetch-handler-DxhvXuBA.d.cts +77 -0
- package/dist/elysia-shared-BFcWzfc9.cjs +101 -0
- package/dist/elysia-shared-BFcWzfc9.cjs.map +1 -0
- package/dist/elysia-shared-BwUYg0Ln.mjs +78 -0
- package/dist/elysia-shared-BwUYg0Ln.mjs.map +1 -0
- package/dist/elysia-shared-C2LnDOj3.d.cts +58 -0
- package/dist/elysia-shared-WuDr0jco.d.mts +58 -0
- package/dist/engine--C7zo-4M.cjs +667 -0
- package/dist/engine--C7zo-4M.cjs.map +1 -0
- package/dist/engine-BTgwbHeO.d.cts +336 -0
- package/dist/engine-C3xHfi3q.d.mts +336 -0
- package/dist/engine-CR75K253.mjs +654 -0
- package/dist/engine-CR75K253.mjs.map +1 -0
- package/dist/entry-auth-basic.cjs +40 -0
- package/dist/entry-auth-basic.cjs.map +1 -0
- package/dist/entry-auth-basic.d.cts +24 -0
- package/dist/entry-auth-basic.d.mts +24 -0
- package/dist/entry-auth-basic.mjs +26 -0
- package/dist/entry-auth-basic.mjs.map +1 -0
- package/dist/entry-auth-better-auth.cjs +15 -0
- package/dist/entry-auth-better-auth.d.cts +5 -0
- package/dist/entry-auth-better-auth.d.mts +5 -0
- package/dist/entry-auth-better-auth.mjs +4 -0
- package/dist/entry-auth-delegated.cjs +8 -0
- package/dist/entry-auth-delegated.d.cts +2 -0
- package/dist/entry-auth-delegated.d.mts +2 -0
- package/dist/entry-auth-delegated.mjs +2 -0
- package/dist/entry-auth-jwt.cjs +120 -0
- package/dist/entry-auth-jwt.cjs.map +1 -0
- package/dist/entry-auth-jwt.d.cts +71 -0
- package/dist/entry-auth-jwt.d.mts +71 -0
- package/dist/entry-auth-jwt.mjs +109 -0
- package/dist/entry-auth-jwt.mjs.map +1 -0
- package/dist/entry-auth-none.cjs +14 -0
- package/dist/entry-auth-none.d.cts +2 -0
- package/dist/entry-auth-none.d.mts +2 -0
- package/dist/entry-auth-none.mjs +2 -0
- package/dist/entry-auth-session.cjs +86 -0
- package/dist/entry-auth-session.cjs.map +1 -0
- package/dist/entry-auth-session.d.cts +25 -0
- package/dist/entry-auth-session.d.mts +25 -0
- package/dist/entry-auth-session.mjs +76 -0
- package/dist/entry-auth-session.mjs.map +1 -0
- package/dist/entry-authorization-delegated.cjs +31 -0
- package/dist/entry-authorization-delegated.cjs.map +1 -0
- package/dist/entry-authorization-delegated.d.cts +27 -0
- package/dist/entry-authorization-delegated.d.mts +27 -0
- package/dist/entry-authorization-delegated.mjs +30 -0
- package/dist/entry-authorization-delegated.mjs.map +1 -0
- package/dist/entry-authorization-none.cjs +29 -0
- package/dist/entry-authorization-none.cjs.map +1 -0
- package/dist/entry-authorization-none.d.cts +17 -0
- package/dist/entry-authorization-none.d.mts +17 -0
- package/dist/entry-authorization-none.mjs +28 -0
- package/dist/entry-authorization-none.mjs.map +1 -0
- package/dist/entry-authorization-permissions.cjs +4 -0
- package/dist/entry-authorization-permissions.d.cts +49 -0
- package/dist/entry-authorization-permissions.d.mts +49 -0
- package/dist/entry-authorization-permissions.mjs +2 -0
- package/dist/entry-authorization-roles.cjs +9 -0
- package/dist/entry-authorization-roles.d.cts +37 -0
- package/dist/entry-authorization-roles.d.mts +37 -0
- package/dist/entry-authorization-roles.mjs +3 -0
- package/dist/entry-better-auth-client.cjs +31 -0
- package/dist/entry-better-auth-client.cjs.map +1 -0
- package/dist/entry-better-auth-client.d.cts +63 -0
- package/dist/entry-better-auth-client.d.mts +63 -0
- package/dist/entry-better-auth-client.mjs +29 -0
- package/dist/entry-better-auth-client.mjs.map +1 -0
- package/dist/entry-better-auth.cjs +289 -0
- package/dist/entry-better-auth.cjs.map +1 -0
- package/dist/entry-better-auth.d.cts +3 -0
- package/dist/entry-better-auth.d.mts +3 -0
- package/dist/entry-better-auth.mjs +284 -0
- package/dist/entry-better-auth.mjs.map +1 -0
- package/dist/entry-bridges-audit.cjs +106 -0
- package/dist/entry-bridges-audit.cjs.map +1 -0
- package/dist/entry-bridges-audit.d.cts +58 -0
- package/dist/entry-bridges-audit.d.mts +58 -0
- package/dist/entry-bridges-audit.mjs +105 -0
- package/dist/entry-bridges-audit.mjs.map +1 -0
- package/dist/entry-bridges-webhooks.cjs +90 -0
- package/dist/entry-bridges-webhooks.cjs.map +1 -0
- package/dist/entry-bridges-webhooks.d.cts +46 -0
- package/dist/entry-bridges-webhooks.d.mts +46 -0
- package/dist/entry-bridges-webhooks.mjs +88 -0
- package/dist/entry-bridges-webhooks.mjs.map +1 -0
- package/dist/entry-bun.cjs +33 -0
- package/dist/entry-bun.cjs.map +1 -0
- package/dist/entry-bun.d.cts +31 -0
- package/dist/entry-bun.d.mts +31 -0
- package/dist/entry-bun.mjs +30 -0
- package/dist/entry-bun.mjs.map +1 -0
- package/dist/entry-drizzle-mysql.cjs +34 -0
- package/dist/entry-drizzle-mysql.cjs.map +1 -0
- package/dist/entry-drizzle-mysql.d.cts +20 -0
- package/dist/entry-drizzle-mysql.d.mts +20 -0
- package/dist/entry-drizzle-mysql.mjs +33 -0
- package/dist/entry-drizzle-mysql.mjs.map +1 -0
- package/dist/entry-drizzle-pg.cjs +44 -0
- package/dist/entry-drizzle-pg.cjs.map +1 -0
- package/dist/entry-drizzle-pg.d.cts +20 -0
- package/dist/entry-drizzle-pg.d.mts +20 -0
- package/dist/entry-drizzle-pg.mjs +43 -0
- package/dist/entry-drizzle-pg.mjs.map +1 -0
- package/dist/entry-drizzle-sqlite.cjs +34 -0
- package/dist/entry-drizzle-sqlite.cjs.map +1 -0
- package/dist/entry-drizzle-sqlite.d.cts +15 -0
- package/dist/entry-drizzle-sqlite.d.mts +15 -0
- package/dist/entry-drizzle-sqlite.mjs +33 -0
- package/dist/entry-drizzle-sqlite.mjs.map +1 -0
- package/dist/entry-elysia.cjs +117 -0
- package/dist/entry-elysia.cjs.map +1 -0
- package/dist/entry-elysia.d.cts +446 -0
- package/dist/entry-elysia.d.mts +446 -0
- package/dist/entry-elysia.mjs +113 -0
- package/dist/entry-elysia.mjs.map +1 -0
- package/dist/entry-elysia2.cjs +117 -0
- package/dist/entry-elysia2.cjs.map +1 -0
- package/dist/entry-elysia2.d.cts +571 -0
- package/dist/entry-elysia2.d.mts +571 -0
- package/dist/entry-elysia2.mjs +113 -0
- package/dist/entry-elysia2.mjs.map +1 -0
- package/dist/entry-express.cjs +101 -0
- package/dist/entry-express.cjs.map +1 -0
- package/dist/entry-express.d.cts +36 -0
- package/dist/entry-express.d.mts +36 -0
- package/dist/entry-express.mjs +97 -0
- package/dist/entry-express.mjs.map +1 -0
- package/dist/entry-hono.cjs +63 -0
- package/dist/entry-hono.cjs.map +1 -0
- package/dist/entry-hono.d.cts +40 -0
- package/dist/entry-hono.d.mts +40 -0
- package/dist/entry-hono.mjs +60 -0
- package/dist/entry-hono.mjs.map +1 -0
- package/dist/entry-hooks-log.cjs +39 -0
- package/dist/entry-hooks-log.cjs.map +1 -0
- package/dist/entry-hooks-log.d.cts +19 -0
- package/dist/entry-hooks-log.d.mts +19 -0
- package/dist/entry-hooks-log.mjs +36 -0
- package/dist/entry-hooks-log.mjs.map +1 -0
- package/dist/entry-next.cjs +67 -0
- package/dist/entry-next.cjs.map +1 -0
- package/dist/entry-next.d.cts +60 -0
- package/dist/entry-next.d.mts +60 -0
- package/dist/entry-next.mjs +57 -0
- package/dist/entry-next.mjs.map +1 -0
- package/dist/entry-react.cjs +401 -0
- package/dist/entry-react.cjs.map +1 -0
- package/dist/entry-react.d.cts +206 -0
- package/dist/entry-react.d.mts +206 -0
- package/dist/entry-react.mjs +388 -0
- package/dist/entry-react.mjs.map +1 -0
- package/dist/entry-storage-cloudflare-kv.cjs +8 -0
- package/dist/entry-storage-cloudflare-kv.d.cts +2 -0
- package/dist/entry-storage-cloudflare-kv.d.mts +2 -0
- package/dist/entry-storage-cloudflare-kv.mjs +2 -0
- package/dist/entry-storage-drizzle.cjs +71 -0
- package/dist/entry-storage-drizzle.cjs.map +1 -0
- package/dist/entry-storage-drizzle.d.cts +27 -0
- package/dist/entry-storage-drizzle.d.mts +27 -0
- package/dist/entry-storage-drizzle.mjs +68 -0
- package/dist/entry-storage-drizzle.mjs.map +1 -0
- package/dist/entry-storage-file.cjs +54 -0
- package/dist/entry-storage-file.cjs.map +1 -0
- package/dist/entry-storage-file.d.cts +24 -0
- package/dist/entry-storage-file.d.mts +24 -0
- package/dist/entry-storage-file.mjs +46 -0
- package/dist/entry-storage-file.mjs.map +1 -0
- package/dist/entry-storage-libsql.cjs +64 -0
- package/dist/entry-storage-libsql.cjs.map +1 -0
- package/dist/entry-storage-libsql.d.cts +28 -0
- package/dist/entry-storage-libsql.d.mts +28 -0
- package/dist/entry-storage-libsql.mjs +61 -0
- package/dist/entry-storage-libsql.mjs.map +1 -0
- package/dist/entry-storage-memory.cjs +3 -0
- package/dist/entry-storage-memory.d.cts +25 -0
- package/dist/entry-storage-memory.d.mts +25 -0
- package/dist/entry-storage-memory.mjs +2 -0
- package/dist/entry-storage-mongodb.cjs +61 -0
- package/dist/entry-storage-mongodb.cjs.map +1 -0
- package/dist/entry-storage-mongodb.d.cts +25 -0
- package/dist/entry-storage-mongodb.d.mts +25 -0
- package/dist/entry-storage-mongodb.mjs +58 -0
- package/dist/entry-storage-mongodb.mjs.map +1 -0
- package/dist/entry-storage-postgres.cjs +62 -0
- package/dist/entry-storage-postgres.cjs.map +1 -0
- package/dist/entry-storage-postgres.d.cts +29 -0
- package/dist/entry-storage-postgres.d.mts +29 -0
- package/dist/entry-storage-postgres.mjs +58 -0
- package/dist/entry-storage-postgres.mjs.map +1 -0
- package/dist/entry-storage-redis.cjs +76 -0
- package/dist/entry-storage-redis.cjs.map +1 -0
- package/dist/entry-storage-redis.d.cts +29 -0
- package/dist/entry-storage-redis.d.mts +29 -0
- package/dist/entry-storage-redis.mjs +72 -0
- package/dist/entry-storage-redis.mjs.map +1 -0
- package/dist/entry-storage-sqlite.cjs +46 -0
- package/dist/entry-storage-sqlite.cjs.map +1 -0
- package/dist/entry-storage-sqlite.d.cts +22 -0
- package/dist/entry-storage-sqlite.d.mts +22 -0
- package/dist/entry-storage-sqlite.mjs +43 -0
- package/dist/entry-storage-sqlite.mjs.map +1 -0
- package/dist/entry-storage-unstorage.cjs +8 -0
- package/dist/entry-storage-unstorage.d.cts +2 -0
- package/dist/entry-storage-unstorage.d.mts +2 -0
- package/dist/entry-storage-unstorage.mjs +2 -0
- package/dist/error-codes-9MRMSSMQ.cjs +49 -0
- package/dist/error-codes-9MRMSSMQ.cjs.map +1 -0
- package/dist/error-codes-CCKuDDu7.mjs +44 -0
- package/dist/error-codes-CCKuDDu7.mjs.map +1 -0
- package/dist/errors-CG_OLEEv.mjs +64 -0
- package/dist/errors-CG_OLEEv.mjs.map +1 -0
- package/dist/errors-CjpymzFj.cjs +105 -0
- package/dist/errors-CjpymzFj.cjs.map +1 -0
- package/dist/events-AE4Ytqmz.d.cts +6 -0
- package/dist/events-AE4Ytqmz.d.mts +6 -0
- package/dist/events-DYZShrYB.mjs +15 -0
- package/dist/events-DYZShrYB.mjs.map +1 -0
- package/dist/events-FJ2K0wly.cjs +26 -0
- package/dist/events-FJ2K0wly.cjs.map +1 -0
- package/dist/guard-Bj8zk23F.mjs +141 -0
- package/dist/guard-Bj8zk23F.mjs.map +1 -0
- package/dist/guard-DvaoUgjk.cjs +188 -0
- package/dist/guard-DvaoUgjk.cjs.map +1 -0
- package/dist/guard-VEK0W8ug.d.cts +62 -0
- package/dist/guard-k7A71SWC.d.mts +62 -0
- package/dist/index-BVVgDSdq.d.cts +1 -0
- package/dist/index-BVVgDSdq.d.mts +1 -0
- package/dist/index.cjs +243 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +213 -0
- package/dist/index.d.mts +213 -0
- package/dist/index.mjs +60 -0
- package/dist/index.mjs.map +1 -0
- package/dist/kit-51JtMxsn.d.mts +62 -0
- package/dist/kit-BM3uosfV.mjs +80 -0
- package/dist/kit-BM3uosfV.mjs.map +1 -0
- package/dist/kit-BrqnCcDw.cjs +97 -0
- package/dist/kit-BrqnCcDw.cjs.map +1 -0
- package/dist/kit-DLF7DZrp.d.cts +62 -0
- package/dist/memory-BbBbbY8-.mjs +32 -0
- package/dist/memory-BbBbbY8-.mjs.map +1 -0
- package/dist/memory-knijqKw_.cjs +39 -0
- package/dist/memory-knijqKw_.cjs.map +1 -0
- package/dist/permissions-CeV6M3v7.mjs +62 -0
- package/dist/permissions-CeV6M3v7.mjs.map +1 -0
- package/dist/permissions-DDEkHNvN.cjs +73 -0
- package/dist/permissions-DDEkHNvN.cjs.map +1 -0
- package/dist/policy-BQmlo2lu.mjs +3 -0
- package/dist/policy-CGA6QD0a.d.mts +4 -0
- package/dist/policy-DFq_SYR3.d.cts +4 -0
- package/dist/react-embed.js +18735 -0
- package/dist/react.css +1 -0
- package/dist/relationships-BLYEJ9tc.cjs +907 -0
- package/dist/relationships-BLYEJ9tc.cjs.map +1 -0
- package/dist/relationships-BfLonEMI.mjs +756 -0
- package/dist/relationships-BfLonEMI.mjs.map +1 -0
- package/dist/roles-DBk4i8b5.mjs +69 -0
- package/dist/roles-DBk4i8b5.mjs.map +1 -0
- package/dist/roles-a8B5uZ35.cjs +104 -0
- package/dist/roles-a8B5uZ35.cjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/routes-B2LrYpT0.cjs +1055 -0
- package/dist/routes-B2LrYpT0.cjs.map +1 -0
- package/dist/routes-Cx-kl4PY.mjs +1007 -0
- package/dist/routes-Cx-kl4PY.mjs.map +1 -0
- package/dist/server-Bn643UOy.d.mts +886 -0
- package/dist/server-YdH25OEA.d.cts +886 -0
- package/dist/table-DA98mVVT.d.cts +2 -0
- package/dist/table-DA98mVVT.d.mts +2 -0
- package/dist/testing.cjs +59 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +37 -0
- package/dist/testing.d.mts +37 -0
- package/dist/testing.mjs +57 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/types-elysia2/adapters/elysia-shared.d.ts +71 -0
- package/dist/types-elysia2/adapters/elysia2.d.ts +432 -0
- package/dist/types-elysia2/adapters/guard.d.ts +140 -0
- package/dist/types-elysia2/auth/contract.d.ts +9 -0
- package/dist/types-elysia2/auth-provider/contract.d.ts +85 -0
- package/dist/types-elysia2/auth-provider/kit.d.ts +62 -0
- package/dist/types-elysia2/authorization/contract.d.ts +53 -0
- package/dist/types-elysia2/authorization/permissions.d.ts +54 -0
- package/dist/types-elysia2/catalog.d.ts +197 -0
- package/dist/types-elysia2/engine.d.ts +233 -0
- package/dist/types-elysia2/entry-elysia2.d.ts +9 -0
- package/dist/types-elysia2/errors.d.ts +55 -0
- package/dist/types-elysia2/hooks/contract.d.ts +100 -0
- package/dist/types-elysia2/keys.d.ts +78 -0
- package/dist/types-elysia2/policy.d.ts +13 -0
- package/dist/types-elysia2/relationships.d.ts +162 -0
- package/dist/types-elysia2/schema.d.ts +315 -0
- package/dist/types-elysia2/server/cors.d.ts +8 -0
- package/dist/types-elysia2/server/create-fetch-handler.d.ts +87 -0
- package/dist/types-elysia2/server/openapi.d.ts +29 -0
- package/dist/types-elysia2/server/routes.d.ts +143 -0
- package/dist/types-elysia2/server/validation.d.ts +205 -0
- package/dist/types-elysia2/storage/contract.d.ts +18 -0
- package/dist/types-react/catalog.d.ts +197 -0
- package/dist/types-react/engine.d.ts +233 -0
- package/dist/types-react/entry-react-embed.d.ts +20 -0
- package/dist/types-react/errors.d.ts +55 -0
- package/dist/types-react/hooks/contract.d.ts +100 -0
- package/dist/types-react/keys.d.ts +78 -0
- package/dist/types-react/policy.d.ts +13 -0
- package/dist/types-react/react-embed.d.ts +37 -0
- package/dist/types-react/relationships.d.ts +162 -0
- package/dist/types-react/schema.d.ts +315 -0
- package/dist/types-react/storage/contract.d.ts +18 -0
- package/dist/types-react/ui/App.d.ts +28 -0
- package/dist/types-react/ui/api.d.ts +73 -0
- package/dist/types-react/ui/components/perm-bits.d.ts +68 -0
- package/dist/types-react/ui/lib/queries.d.ts +46 -0
- package/dist/types-react/ui/theme.d.ts +10 -0
- package/dist/types-react/ui/types.d.ts +118 -0
- package/dist/types-react/ui/views/CatalogView.d.ts +3 -0
- package/dist/types-react/ui/views/HistoryView.d.ts +6 -0
- package/dist/types-react/ui/views/PlaygroundView.d.ts +14 -0
- package/dist/types-react/ui/views/RelationshipsView.d.ts +6 -0
- package/dist/types-react/ui/views/SubjectDetailView.d.ts +7 -0
- package/dist/types-react/ui/views/SubjectsView.d.ts +6 -0
- package/dist/ui/apple-touch-icon.png +0 -0
- package/dist/ui/assets/index-DCPZRo-Z.css +1 -0
- package/dist/ui/assets/index-DdvxpphI.js +104 -0
- package/dist/ui/favicon.ico +0 -0
- package/dist/ui/favicon.svg +15 -0
- package/dist/ui/index.html +20 -0
- package/package.json +587 -4
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The engine: `createPermissions({ catalog, storage, hooks, cache, now, readonly })`.
|
|
3
|
+
*
|
|
4
|
+
* Writes (grant, revoke, role assignment, subject records) go to the storage
|
|
5
|
+
* under the `perm/` key root (ADR 0003) and fire the hooks. Checks load the
|
|
6
|
+
* subject's stored role and grants (async, cached per subject), resolve the
|
|
7
|
+
* effective role from the `roleSource` (ADR 0014), then evaluate
|
|
8
|
+
* the catalog's rules **synchronously** with `@xtandard/lib/policy/permix`
|
|
9
|
+
* (ADR 0005).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { createPermissions } from "@xtandard/permissions";
|
|
14
|
+
* import { createMemoryStorage } from "@xtandard/permissions/storage/memory";
|
|
15
|
+
* import { permissions } from "./permissions.ts"; // definePermissions(...)
|
|
16
|
+
*
|
|
17
|
+
* const perms = createPermissions({ catalog: permissions, storage: createMemoryStorage() });
|
|
18
|
+
* await perms.grant({ subject: "user_1", permission: "post:moderate", actor: "admin_1" });
|
|
19
|
+
* await perms.can({ id: "user_1", role: "member" }, "post.publish", post); // true
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @module
|
|
23
|
+
*/
|
|
24
|
+
import type { PermissionsCatalog, PermissionsSubject, SubjectIdentity } from "./catalog.ts";
|
|
25
|
+
export type { SubjectIdentity } from "./catalog.ts";
|
|
26
|
+
import { type HookErrorReporter, type PermissionsHooksInput } from "./hooks/contract.ts";
|
|
27
|
+
import type { Ability, DataAtPath, Definition, RelationSchema, RulesPaths } from "./policy.ts";
|
|
28
|
+
import { type RelationshipsApi, type RelationsOptions } from "./relationships.ts";
|
|
29
|
+
import { type CheckResult, type Grant, type GrantInput, type HistoryPage, type HistoryQuery, type ListQuery, type PermissionsSnapshot, type RevokeInput, type RoleSource, type RoleSourceMode, type SetRoleInput, type SubjectRecord, type UpsertSubjectInput } from "./schema.ts";
|
|
30
|
+
import { type PermissionsStorage } from "./storage/contract.ts";
|
|
31
|
+
/** Options for {@link createPermissions}. */
|
|
32
|
+
export interface PermissionsOptions<D extends Definition = Definition, R extends string = string, P extends string = string, X = undefined, S extends RelationSchema = RelationSchema> {
|
|
33
|
+
/** The catalog from `definePermissions()`. */
|
|
34
|
+
catalog: PermissionsCatalog<D, R, P, X, S>;
|
|
35
|
+
/** Where grants, role assignments and history live (any `@xtandard/permissions/storage/*`). */
|
|
36
|
+
storage: PermissionsStorage;
|
|
37
|
+
/** `before` (veto) / `after` (side effects) hooks around grant, revoke and role writes. */
|
|
38
|
+
hooks?: PermissionsHooksInput;
|
|
39
|
+
/** Receives errors thrown by `after` hooks. Default: a prefixed `console.warn`. */
|
|
40
|
+
onHookError?: HookErrorReporter;
|
|
41
|
+
/**
|
|
42
|
+
* Per-subject cache of the stored role and grants used by checks (and of `lookupSubject`
|
|
43
|
+
* results). Entries expire after `ttlMs`
|
|
44
|
+
* (default 5 000), are dropped on this engine's writes and, when the storage is watchable, on
|
|
45
|
+
* every change it reports. `false` disables it (every check reads the storage).
|
|
46
|
+
*/
|
|
47
|
+
cache?: false | {
|
|
48
|
+
ttlMs?: number;
|
|
49
|
+
max?: number;
|
|
50
|
+
};
|
|
51
|
+
/** Clock (unix ms). Default `Date.now`. Decides grant expiry and every stored timestamp. */
|
|
52
|
+
now?: () => number;
|
|
53
|
+
/** When `true`, every write throws {@link ReadonlyError}. */
|
|
54
|
+
readonly?: boolean;
|
|
55
|
+
/** Where operational warnings go. Default: a prefixed `console.warn`. */
|
|
56
|
+
logger?: {
|
|
57
|
+
warn(message: string, error?: unknown): void;
|
|
58
|
+
};
|
|
59
|
+
/** ReBAC tuning (the catalog's `relations`): `maxDepth` of checks and listing walks. */
|
|
60
|
+
relations?: RelationsOptions;
|
|
61
|
+
/**
|
|
62
|
+
* Who owns roles (ADR 0014). `"stored"` (default, the 0.1 behaviour): a role set with
|
|
63
|
+
* `setRole()` wins over the auth provider's. `"external"`: the auth provider owns roles; stored
|
|
64
|
+
* roles are ignored and `setRole()` throws {@link ExternalRolesError}.
|
|
65
|
+
*/
|
|
66
|
+
roleSource?: RoleSourceMode;
|
|
67
|
+
/**
|
|
68
|
+
* Resolve a subject by id when a check (or the panel) only has the id, not a session: returns
|
|
69
|
+
* the auth provider's identity (`role`, `name`, `email`). Used in both role-source modes, only
|
|
70
|
+
* when the identity passed carries no `role`; cached with the per-subject cache. Needed for the
|
|
71
|
+
* panel to show the provider's role of subjects other than the caller. Every bundled auth
|
|
72
|
+
* provider can supply one (`provider.lookupSubject`).
|
|
73
|
+
*/
|
|
74
|
+
lookupSubject?: SubjectLookup | undefined;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Looks a subject up by id in the auth provider (see {@link PermissionsOptions.lookupSubject}).
|
|
78
|
+
* `null` = unknown subject (the catalog's `defaultRole` applies). A throw fails the check.
|
|
79
|
+
*/
|
|
80
|
+
export type SubjectLookup = (id: string) => SubjectIdentity | null | undefined | Promise<SubjectIdentity | null | undefined>;
|
|
81
|
+
/** A subject id, an identity, or `null` / `undefined` for a guest (no session). */
|
|
82
|
+
export type SubjectInput = string | SubjectIdentity | null | undefined;
|
|
83
|
+
/** The app context argument of checks: required when the catalog's context type is. */
|
|
84
|
+
export type FactsArgs<X> = undefined extends X ? [facts?: {
|
|
85
|
+
ctx?: X;
|
|
86
|
+
}] : [facts: {
|
|
87
|
+
ctx: X;
|
|
88
|
+
}];
|
|
89
|
+
/** The data a typed check at `Path` takes (`undefined` when the action takes none). */
|
|
90
|
+
export type PathData<D extends Definition, Path extends string> = DataAtPath<D, Path> extends readonly [] ? undefined : DataAtPath<D, Path>[0];
|
|
91
|
+
/** The lib `Ability` of one subject, plus the engine's decision with reasons. */
|
|
92
|
+
export interface PermissionsAbility<D extends Definition = Definition, R extends string = string, P extends string = string> extends Ability<D, R, P, PermissionsSubject> {
|
|
93
|
+
/** The subject id, `null` for a guest. */
|
|
94
|
+
subject: string | null;
|
|
95
|
+
/** The non-expired grants the ability was built from (assignable or not). */
|
|
96
|
+
grants: readonly Grant<P>[];
|
|
97
|
+
/**
|
|
98
|
+
* Decide `path` with reasons (see {@link CheckResult}). Takes an untyped path (e.g. from an HTTP
|
|
99
|
+
* request); an unknown path is denied with `reason: "unknown-path"`. Throws `AsyncRuleError` when
|
|
100
|
+
* the rule returns a Promise (the check denies).
|
|
101
|
+
*/
|
|
102
|
+
check(path: string, data?: unknown): CheckResult<R, P>;
|
|
103
|
+
/**
|
|
104
|
+
* Like {@link check}, and also evaluates rules wrapped in the lib's `asyncRule()` (which the
|
|
105
|
+
* synchronous `check` refuses with `AsyncRuleError`). The engine's `check()` / `can()` use it.
|
|
106
|
+
*/
|
|
107
|
+
checkAsync(path: string, data?: unknown): Promise<CheckResult<R, P>>;
|
|
108
|
+
}
|
|
109
|
+
/** What `revoke()` returns. */
|
|
110
|
+
export interface RevokeResult<P extends string = string> {
|
|
111
|
+
/** `false` when there was nothing to revoke. */
|
|
112
|
+
removed: boolean;
|
|
113
|
+
/** The revoked grant, when there was one. */
|
|
114
|
+
grant: Grant<P> | null;
|
|
115
|
+
}
|
|
116
|
+
/** What `setRole()` returns. */
|
|
117
|
+
export interface SetRoleResult {
|
|
118
|
+
/** The subject record after the write (`null` when none exists and the role was cleared). */
|
|
119
|
+
record: SubjectRecord | null;
|
|
120
|
+
/** `false` when the stored role already was the requested one. */
|
|
121
|
+
changed: boolean;
|
|
122
|
+
}
|
|
123
|
+
/** A subject as stored: its record and grants. */
|
|
124
|
+
export interface SubjectView<R extends string = string, P extends string = string> {
|
|
125
|
+
id: string;
|
|
126
|
+
/** The stored record, `null` when the subject has none. */
|
|
127
|
+
record: SubjectRecord | null;
|
|
128
|
+
/**
|
|
129
|
+
* The stored role assignment when it is a known, assignable role; else `null`. Ignored by checks
|
|
130
|
+
* when the engine's `roleSource` is `"external"`.
|
|
131
|
+
*/
|
|
132
|
+
role: R | null;
|
|
133
|
+
/** The role checks use: see {@link roleSource} for what decided it. */
|
|
134
|
+
effectiveRole: R;
|
|
135
|
+
/** Which source decided {@link effectiveRole}. */
|
|
136
|
+
roleSource: RoleSource;
|
|
137
|
+
/** The subject's grants (non-expired unless `includeExpired`). */
|
|
138
|
+
grants: Grant<P>[];
|
|
139
|
+
}
|
|
140
|
+
/** One row of `listSubjects()`. */
|
|
141
|
+
export interface SubjectSummary {
|
|
142
|
+
id: string;
|
|
143
|
+
/** The stored role assignment, if any (ignored by checks when `roleSource` is `"external"`). */
|
|
144
|
+
role: string | null;
|
|
145
|
+
/** The role checks use (the stored role, the auth provider's, or `defaultRole`). */
|
|
146
|
+
effectiveRole: string;
|
|
147
|
+
/** Which source decided {@link effectiveRole}. */
|
|
148
|
+
roleSource: RoleSource;
|
|
149
|
+
name?: string;
|
|
150
|
+
email?: string;
|
|
151
|
+
/** Stored grants (expired ones included). */
|
|
152
|
+
grantCount: number;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The engine. The relationship methods (`writeRelationship`, `checkRelation`, `listObjects`, …;
|
|
156
|
+
* see {@link RelationshipsApi}) need the catalog's `relations`.
|
|
157
|
+
*/
|
|
158
|
+
export interface Permissions<D extends Definition = Definition, R extends string = string, P extends string = string, X = undefined, S extends RelationSchema = RelationSchema> extends RelationshipsApi<S> {
|
|
159
|
+
readonly catalog: PermissionsCatalog<D, R, P, X, S>;
|
|
160
|
+
readonly storage: PermissionsStorage;
|
|
161
|
+
readonly readonly: boolean;
|
|
162
|
+
/** Who owns roles: `"stored"` (default) or `"external"` (the auth provider; ADR 0014). */
|
|
163
|
+
readonly roleSource: RoleSourceMode;
|
|
164
|
+
/**
|
|
165
|
+
* Grant a permission. Idempotent: re-granting returns the existing grant with `created: false`
|
|
166
|
+
* (no history entry, no hooks). An **expired** existing grant is replaced (`created: true`).
|
|
167
|
+
*
|
|
168
|
+
* @throws {NoSubjectError} empty subject. {@link UnknownPermissionError} not assignable.
|
|
169
|
+
* `ValidationError` malformed input or `expiresAt` not in the future. {@link ReadonlyError}.
|
|
170
|
+
*/
|
|
171
|
+
grant(input: GrantInput<P>): Promise<{
|
|
172
|
+
grant: Grant<P>;
|
|
173
|
+
created: boolean;
|
|
174
|
+
}>;
|
|
175
|
+
/** Revoke a permission. Idempotent (`removed: false` when absent). Validates like `grant`. */
|
|
176
|
+
revoke(input: RevokeInput<P>): Promise<RevokeResult<P>>;
|
|
177
|
+
/**
|
|
178
|
+
* Grants by subject, by permission (a key scan with a suffix filter), both, or all. Expired
|
|
179
|
+
* grants are left out unless `includeExpired`. Sorted by subject, then permission.
|
|
180
|
+
*/
|
|
181
|
+
list(query?: ListQuery<P>): Promise<Grant<P>[]>;
|
|
182
|
+
/**
|
|
183
|
+
* Store a role assignment (overrides the auth provider's role); `role: null` clears it.
|
|
184
|
+
*
|
|
185
|
+
* @throws {UnknownRoleError} not one of `roles`, or the guest role. {@link ExternalRolesError}
|
|
186
|
+
* when `roleSource` is `"external"` (the auth provider owns roles).
|
|
187
|
+
*/
|
|
188
|
+
setRole(input: SetRoleInput<R>): Promise<SetRoleResult>;
|
|
189
|
+
/**
|
|
190
|
+
* A subject's stored record and grants (an empty view when nothing is stored), with its effective
|
|
191
|
+
* role and the source that decided it (the auth provider's role comes from `lookupSubject`).
|
|
192
|
+
*/
|
|
193
|
+
getSubject(id: string, options?: {
|
|
194
|
+
includeExpired?: boolean;
|
|
195
|
+
}): Promise<SubjectView<R, P>>;
|
|
196
|
+
/**
|
|
197
|
+
* Every subject with a record or a grant, sorted by id, with effective roles. A failing
|
|
198
|
+
* `lookupSubject` is logged and reported as `roleSource: "default"` (the list still loads).
|
|
199
|
+
*/
|
|
200
|
+
listSubjects(): Promise<SubjectSummary[]>;
|
|
201
|
+
/** Create or update a subject's display fields (`null` clears one). Keeps the stored role. */
|
|
202
|
+
upsertSubject(input: UpsertSubjectInput): Promise<SubjectRecord>;
|
|
203
|
+
/** The grant / revoke / role history, newest first, paginated by `cursor`. */
|
|
204
|
+
history(query?: HistoryQuery): Promise<HistoryPage>;
|
|
205
|
+
/**
|
|
206
|
+
* A synchronous ability for many checks against one loaded snapshot of the subject. `null` /
|
|
207
|
+
* `undefined` is a guest (the guest role, no grants).
|
|
208
|
+
*/
|
|
209
|
+
ability(subject: SubjectInput, ...facts: FactsArgs<X>): Promise<PermissionsAbility<D, R, P>>;
|
|
210
|
+
/** Decide one typed path with reasons. */
|
|
211
|
+
check<Path extends RulesPaths<D>>(subject: SubjectInput, path: Path, data?: PathData<D, Path>, ...facts: FactsArgs<X>): Promise<CheckResult<R, P>>;
|
|
212
|
+
/** `(await check(...)).allowed`. */
|
|
213
|
+
can<Path extends RulesPaths<D>>(subject: SubjectInput, path: Path, data?: PathData<D, Path>, ...facts: FactsArgs<X>): Promise<boolean>;
|
|
214
|
+
/** The effective role and active assignable permissions, for client hydration (ADR 0009). */
|
|
215
|
+
snapshot(subject: SubjectInput): Promise<PermissionsSnapshot<R, P>>;
|
|
216
|
+
/** Drop one subject's cache entry, or all of them. */
|
|
217
|
+
invalidate(subject?: string): void;
|
|
218
|
+
/** Stop watching the storage. */
|
|
219
|
+
close(): Promise<void>;
|
|
220
|
+
}
|
|
221
|
+
/** Any engine, generics erased (for integrations: auth providers, servers, bridges). */
|
|
222
|
+
export type AnyPermissions = Permissions<any, any, any, any, any>;
|
|
223
|
+
/**
|
|
224
|
+
* Create the engine.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* const perms = createPermissions({ catalog, storage, cache: { ttlMs: 5_000 } });
|
|
229
|
+
* const decision = await perms.check({ id: "u1", role: "member" }, "post.publish", post);
|
|
230
|
+
* // { allowed, path, subject, role, reason: "role-rule" | "denied-by-rule" | …, explanation }
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
export declare function createPermissions<D extends Definition, R extends string, P extends string, X, S extends RelationSchema = RelationSchema>(options: PermissionsOptions<D, R, P, X, S>): Permissions<D, R, P, X, S>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@xtandard/permissions/react/embed` — the admin panel as a React component,
|
|
3
|
+
* for hosts that want it inside their own React tree instead of the bundled
|
|
4
|
+
* SPA the adapters serve.
|
|
5
|
+
*
|
|
6
|
+
* ```tsx
|
|
7
|
+
* import { PermissionsDashboard } from "@xtandard/permissions/react/embed";
|
|
8
|
+
* import "@xtandard/permissions/react/styles.css";
|
|
9
|
+
*
|
|
10
|
+
* <PermissionsDashboard apiBaseUrl="/permissions" />
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* `react` and `react-dom` are peers; everything else is bundled. The stylesheet
|
|
14
|
+
* is scoped under `.xtandard-permissions`. For gating your own UI (`useCan`,
|
|
15
|
+
* `<Can>`), use `@xtandard/permissions/react`.
|
|
16
|
+
*
|
|
17
|
+
* @module react/embed
|
|
18
|
+
*/
|
|
19
|
+
export * from "./react-embed.tsx";
|
|
20
|
+
export { default } from "./react-embed.tsx";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed errors. Every class sets a distinct `name`: the kit maps errors to HTTP
|
|
3
|
+
* responses **by name** (`isNamed`), so a copy from another bundle still maps.
|
|
4
|
+
*
|
|
5
|
+
* | name | when |
|
|
6
|
+
* | ------------------------ | --------------------------------------------------------------- |
|
|
7
|
+
* | `NoSubjectError` | a write (or a check) without a subject id — never `""` |
|
|
8
|
+
* | `UnknownPermissionError` | a permission not in the catalog's `assignable` list |
|
|
9
|
+
* | `UnknownRoleError` | a role not in the catalog's `roles` |
|
|
10
|
+
* | `ForbiddenError` | the caller may not manage permissions |
|
|
11
|
+
* | `NotFoundError` | a referenced record does not exist |
|
|
12
|
+
* | `ReadonlyError` | a mutation on a `readonly` engine |
|
|
13
|
+
* | `ExternalRolesError` | `setRole()` with `roleSource: "external"` (the provider owns roles) |
|
|
14
|
+
* | `ValidationError` | malformed input (the kit's, with `errors` / `issues`) |
|
|
15
|
+
* | `AsyncRuleError` | a rule returned a Promise (the lib's; the check denied) |
|
|
16
|
+
*
|
|
17
|
+
* @module
|
|
18
|
+
*/
|
|
19
|
+
export { ValidationError, type ValidationIssue } from "@xtandard/kit/util";
|
|
20
|
+
export { AsyncRuleError } from "./policy.ts";
|
|
21
|
+
/** A write (or a check) needs a subject id and got none (no session, or an empty id). */
|
|
22
|
+
export declare class NoSubjectError extends Error {
|
|
23
|
+
constructor(message?: string);
|
|
24
|
+
}
|
|
25
|
+
/** The permission is not in the catalog's `assignable` list. */
|
|
26
|
+
export declare class UnknownPermissionError extends Error {
|
|
27
|
+
/** The rejected permission. */
|
|
28
|
+
readonly permission: string;
|
|
29
|
+
constructor(permission: unknown);
|
|
30
|
+
}
|
|
31
|
+
/** The role is not one of the catalog's `roles` (or may not be assigned). */
|
|
32
|
+
export declare class UnknownRoleError extends Error {
|
|
33
|
+
/** The rejected role. */
|
|
34
|
+
readonly role: string;
|
|
35
|
+
constructor(role: unknown, message?: string);
|
|
36
|
+
}
|
|
37
|
+
/** The caller may not perform the operation (e.g. grant without a manager role). */
|
|
38
|
+
export declare class ForbiddenError extends Error {
|
|
39
|
+
constructor(message?: string);
|
|
40
|
+
}
|
|
41
|
+
/** A referenced record does not exist. */
|
|
42
|
+
export declare class NotFoundError extends Error {
|
|
43
|
+
constructor(message: string);
|
|
44
|
+
}
|
|
45
|
+
/** Thrown by mutating operations when the engine is readonly. */
|
|
46
|
+
export declare class ReadonlyError extends Error {
|
|
47
|
+
constructor(operation: string);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* `setRole()` on an engine whose `roleSource` is `"external"`: roles are managed by the auth
|
|
51
|
+
* provider, so a stored role would be ignored (ADR 0014). HTTP 409 `ROLES_EXTERNAL`.
|
|
52
|
+
*/
|
|
53
|
+
export declare class ExternalRolesError extends Error {
|
|
54
|
+
constructor(message?: string);
|
|
55
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Control-plane hooks fired around grant, revoke, role and relationship writes (mirrors the
|
|
3
|
+
* family's hooks contract, `@xtandard/kit/hooks`).
|
|
4
|
+
*
|
|
5
|
+
* - `before` runs sequentially before the write commits. **Throw to deny**
|
|
6
|
+
* (e.g. {@link HookDeniedError}); the error propagates to the caller.
|
|
7
|
+
* - `after` runs once committed, for side effects (audit, webhooks, cache
|
|
8
|
+
* busting). Errors are isolated and reported via `onHookError`.
|
|
9
|
+
*
|
|
10
|
+
* A re-grant of an existing grant, a revoke of nothing, a role set to the
|
|
11
|
+
* role already stored, a re-write of a stored relationship and a delete of a
|
|
12
|
+
* missing one are no-ops: they fire neither `before` nor `after`.
|
|
13
|
+
* Checks never go through hooks.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
import { type HookErrorReporter as KitHookErrorReporter, type Hooks, type HooksInput } from "@xtandard/kit/hooks";
|
|
18
|
+
import type { Actor, Grant, Relationship, SubjectRecord } from "../schema.ts";
|
|
19
|
+
/** Events delivered to `before` hooks (the write has not happened yet). */
|
|
20
|
+
export type BeforeEvent = {
|
|
21
|
+
type: "grant.create";
|
|
22
|
+
subject: string;
|
|
23
|
+
grant: Grant;
|
|
24
|
+
actor: Actor | null;
|
|
25
|
+
} | {
|
|
26
|
+
type: "grant.revoke";
|
|
27
|
+
subject: string;
|
|
28
|
+
grant: Grant;
|
|
29
|
+
actor: Actor | null;
|
|
30
|
+
reason?: string;
|
|
31
|
+
} | {
|
|
32
|
+
type: "role.set";
|
|
33
|
+
subject: string;
|
|
34
|
+
/** The new role; `null` clears the stored assignment. */
|
|
35
|
+
role: string | null;
|
|
36
|
+
previous: string | null;
|
|
37
|
+
actor: Actor | null;
|
|
38
|
+
reason?: string;
|
|
39
|
+
} | {
|
|
40
|
+
type: "relationship.write";
|
|
41
|
+
/** The tuple's subject reference (`user:ana`, `group:eng#member`). */
|
|
42
|
+
subject: string;
|
|
43
|
+
relationship: Relationship;
|
|
44
|
+
actor: Actor | null;
|
|
45
|
+
} | {
|
|
46
|
+
type: "relationship.delete";
|
|
47
|
+
subject: string;
|
|
48
|
+
relationship: Relationship;
|
|
49
|
+
actor: Actor | null;
|
|
50
|
+
reason?: string;
|
|
51
|
+
};
|
|
52
|
+
/** Events delivered to `after` hooks (committed). */
|
|
53
|
+
export type AfterEvent = {
|
|
54
|
+
type: "grant.created";
|
|
55
|
+
subject: string;
|
|
56
|
+
grant: Grant;
|
|
57
|
+
actor: Actor | null;
|
|
58
|
+
at: string;
|
|
59
|
+
} | {
|
|
60
|
+
type: "grant.revoked";
|
|
61
|
+
subject: string;
|
|
62
|
+
grant: Grant;
|
|
63
|
+
actor: Actor | null;
|
|
64
|
+
reason?: string;
|
|
65
|
+
at: string;
|
|
66
|
+
} | {
|
|
67
|
+
type: "role.changed";
|
|
68
|
+
subject: string;
|
|
69
|
+
role: string | null;
|
|
70
|
+
previous: string | null;
|
|
71
|
+
record: SubjectRecord;
|
|
72
|
+
actor: Actor | null;
|
|
73
|
+
reason?: string;
|
|
74
|
+
at: string;
|
|
75
|
+
} | {
|
|
76
|
+
type: "relationship.written";
|
|
77
|
+
subject: string;
|
|
78
|
+
relationship: Relationship;
|
|
79
|
+
actor: Actor | null;
|
|
80
|
+
at: string;
|
|
81
|
+
} | {
|
|
82
|
+
type: "relationship.deleted";
|
|
83
|
+
subject: string;
|
|
84
|
+
relationship: Relationship;
|
|
85
|
+
actor: Actor | null;
|
|
86
|
+
reason?: string;
|
|
87
|
+
at: string;
|
|
88
|
+
};
|
|
89
|
+
/** The discriminant strings of {@link BeforeEvent} / {@link AfterEvent}. */
|
|
90
|
+
export type BeforeEventType = BeforeEvent["type"];
|
|
91
|
+
export type AfterEventType = AfterEvent["type"];
|
|
92
|
+
export { HookDeniedError, normalizeHooks, runAfter, runBefore } from "@xtandard/kit/hooks";
|
|
93
|
+
/** A hook: implement either side or both. */
|
|
94
|
+
export type PermissionsHooks = Hooks<BeforeEvent, AfterEvent>;
|
|
95
|
+
/** Accepts a single hook, an array, or nothing. */
|
|
96
|
+
export type PermissionsHooksInput = HooksInput<BeforeEvent, AfterEvent>;
|
|
97
|
+
/** Reports an error thrown by an `after` hook. */
|
|
98
|
+
export type HookErrorReporter = KitHookErrorReporter<AfterEvent>;
|
|
99
|
+
/** Default `after`-hook error reporter: warn with the `[@xtandard/permissions]` prefix, never throw. */
|
|
100
|
+
export declare const defaultHookErrorReporter: HookErrorReporter;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key layout (ADR 0003). Pure string helpers; every id segment is
|
|
3
|
+
* `encodeURIComponent`-ed, so any subject id or permission name is safe in a
|
|
4
|
+
* key and can't contain the `/` separator.
|
|
5
|
+
*
|
|
6
|
+
* ```txt
|
|
7
|
+
* perm/grants/{subject}/{permission} -> Grant one key per pair: unique on every driver
|
|
8
|
+
* perm/subjects/{subject} -> SubjectRecord optional role assignment + display fields
|
|
9
|
+
* perm/history/{subject}/{at}-{id} -> HistoryEntry append-only; sortable by the last segment
|
|
10
|
+
*
|
|
11
|
+
* perm/rel/{objectType}/{objectId}/{relation}/{subject} -> Relationship
|
|
12
|
+
* perm/relrev/{subjectType}/{subjectId}/{subjectRel}/{objectType}/{objectId}/{relation}
|
|
13
|
+
* -> RelationshipRef
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Relationships (ADR 0013): one forward key per tuple (unique on every driver, so writes are
|
|
17
|
+
* idempotent), read by `(object, relation)` with one prefix scan; the reverse key serves
|
|
18
|
+
* `listObjects` (every tuple naming a subject, plain or as a userset). `{subject}` is the whole
|
|
19
|
+
* subject reference (`user:ana`, `group:eng#member`, `user:*`) as one segment; `{subjectRel}` is
|
|
20
|
+
* `_` for a plain subject or a wildcard and `#{relation}` (encoded `%23…`) for a userset, so it
|
|
21
|
+
* can't collide with a relation named `_`.
|
|
22
|
+
*
|
|
23
|
+
* @module
|
|
24
|
+
*/
|
|
25
|
+
/** Root namespace of every key. */
|
|
26
|
+
export declare const ROOT = "perm";
|
|
27
|
+
/** Prefix of every grant. */
|
|
28
|
+
export declare const grantsPrefix: () => string;
|
|
29
|
+
/** Prefix of one subject's grants. */
|
|
30
|
+
export declare const subjectGrantsPrefix: (subject: string) => string;
|
|
31
|
+
/** One grant. */
|
|
32
|
+
export declare const grantKey: (subject: string, permission: string) => string;
|
|
33
|
+
/** Prefix of every subject record. */
|
|
34
|
+
export declare const subjectsPrefix: () => string;
|
|
35
|
+
/** One subject record. */
|
|
36
|
+
export declare const subjectKey: (subject: string) => string;
|
|
37
|
+
/** Prefix of the whole history log. */
|
|
38
|
+
export declare const historyPrefix: () => string;
|
|
39
|
+
/** Prefix of one subject's history. */
|
|
40
|
+
export declare const subjectHistoryPrefix: (subject: string) => string;
|
|
41
|
+
/** One history entry: the last segment (`{at}-{id}`) sorts by time. */
|
|
42
|
+
export declare const historyKey: (subject: string, at: string, id: string) => string;
|
|
43
|
+
/** Prefix of every relationship (forward keys). */
|
|
44
|
+
export declare const relationshipsPrefix: () => string;
|
|
45
|
+
/** Prefix of one object type's relationships. */
|
|
46
|
+
export declare const relationshipTypePrefix: (type: string) => string;
|
|
47
|
+
/** Prefix of one object's relationships (`doc:1`). */
|
|
48
|
+
export declare const objectRelationshipsPrefix: (object: string) => string;
|
|
49
|
+
/** Prefix of the subjects stored on `(object, relation)`: what a tuple reader scans. */
|
|
50
|
+
export declare const relationSubjectsPrefix: (object: string, relation: string) => string;
|
|
51
|
+
/** One relationship's forward key. */
|
|
52
|
+
export declare const relationshipKey: (object: string, relation: string, subject: string) => string;
|
|
53
|
+
/** Prefix of every reverse key. */
|
|
54
|
+
export declare const reverseRelationshipsPrefix: () => string;
|
|
55
|
+
/** Prefix of the reverse keys of one subject object (`user:ana`), plain and as any userset. */
|
|
56
|
+
export declare const subjectObjectReversePrefix: (object: string) => string;
|
|
57
|
+
/** Prefix of the reverse keys of exactly `subject` (`user:ana`, `user:*`, `group:eng#member`). */
|
|
58
|
+
export declare const subjectReversePrefix: (subject: string) => string;
|
|
59
|
+
/** One relationship's reverse key. */
|
|
60
|
+
export declare const reverseRelationshipKey: (object: string, relation: string, subject: string) => string;
|
|
61
|
+
/** A forward key back to its tuple; `null` when it is not one. */
|
|
62
|
+
export declare function parseRelationshipKey(key: string): {
|
|
63
|
+
object: string;
|
|
64
|
+
relation: string;
|
|
65
|
+
subject: string;
|
|
66
|
+
} | null;
|
|
67
|
+
/** A reverse key back to its tuple; `null` when it is not one. */
|
|
68
|
+
export declare function parseReverseRelationshipKey(key: string): {
|
|
69
|
+
object: string;
|
|
70
|
+
relation: string;
|
|
71
|
+
subject: string;
|
|
72
|
+
} | null;
|
|
73
|
+
/** The decoded segments after the root's area (`grants`, `subjects`, `history`). */
|
|
74
|
+
export declare function parseKey(key: string): {
|
|
75
|
+
area: "grants" | "subjects" | "history";
|
|
76
|
+
subject: string;
|
|
77
|
+
rest?: string;
|
|
78
|
+
} | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one place `@xtandard/lib/policy/permix` (and its `permix` peer) and
|
|
3
|
+
* `@xtandard/lib/policy/rebac` are imported. Every other module imports the policy primitives from here, so
|
|
4
|
+
* moving from the local link to the published `@xtandard/lib` range is a
|
|
5
|
+
* one-line change in `package.json`.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
export { AsyncRuleError, asyncRule, checkRulesAtPathAsync, isAsyncRule, checkRulesAtPath, defineAuthorization, hasAssignedPermission, hasPermission, toPermissionSet, } from "@xtandard/lib/policy/permix";
|
|
10
|
+
export type { Ability, AsyncRule, DefaultUser, AbilityFacts, Authorization, AuthorizationConfig, CheckExplanation, CheckerFn, Definition, PermissionPath, RuleContext, RuleHelpers, Rules, RulesPaths, UnknownCheckResult, } from "@xtandard/lib/policy/permix";
|
|
11
|
+
export type { DataAtPath } from "permix";
|
|
12
|
+
export { computed, createMemoryTuples, createRelationChecker, defineRelations, direct, exclusion, from, hasRelation, incomingEdges, intersection, isAllowedTuple, RelationDepthError, relationEdges, RelationSchemaError, union, } from "@xtandard/lib/policy/rebac";
|
|
13
|
+
export type { ComputedRelation, DirectRelation, ExclusionRelation, FromRelation, IntersectionRelation, MemoryTuples, ObjectRef, RelationChecker, RelationCheckerOptions, RelationEdge, RelationExplanation, RelationExpr, RelationQuery, RelationSchema, RelationTuple, SubjectRef, TupleReadContext, TupleReader, UnionRelation, } from "@xtandard/lib/policy/rebac";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@xtandard/permissions/react/embed` — the admin panel as a React component,
|
|
3
|
+
* for hosts that want it inside their own React tree instead of the bundled
|
|
4
|
+
* SPA the adapters serve.
|
|
5
|
+
*
|
|
6
|
+
* ```tsx
|
|
7
|
+
* import { PermissionsDashboard } from "@xtandard/permissions/react/embed";
|
|
8
|
+
* import "@xtandard/permissions/react/styles.css";
|
|
9
|
+
*
|
|
10
|
+
* <PermissionsDashboard apiBaseUrl="/permissions" />
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* `react` and `react-dom` are peers; everything else (TanStack Query, Base UI,
|
|
14
|
+
* styles) is bundled. The stylesheet is scoped under `.xtandard-permissions`, so
|
|
15
|
+
* it cannot leak into the host. For gating your own UI (`useCan`, `<Can>`), use
|
|
16
|
+
* the much smaller `@xtandard/permissions/react` instead.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
import type { FetchLike } from "@xtandard/kit/ui";
|
|
21
|
+
import { type EmbedBaseProps } from "@xtandard/kit/ui/embed";
|
|
22
|
+
import "./ui/styles.css";
|
|
23
|
+
export type { EmbedRouting, EmbedTheme } from "@xtandard/kit/ui/embed";
|
|
24
|
+
/**
|
|
25
|
+
* Props for {@link PermissionsDashboard}: `apiBaseUrl` (where the panel is mounted), `credentials`
|
|
26
|
+
* (`"include"` for a cross-origin cookie embed, with `cors` on the panel), a custom `fetch`, a
|
|
27
|
+
* `queryClient`, `theme` (`"auto"` | `"inherit"` | `"light"` | `"dark"`), `routing` (`"hash"` by
|
|
28
|
+
* default, `"browser"` under `routerBase`, `"memory"`, or a wouter hook), `logoUrl` and `className`.
|
|
29
|
+
*/
|
|
30
|
+
export interface PermissionsDashboardProps extends EmbedBaseProps {
|
|
31
|
+
}
|
|
32
|
+
/** The admin panel (Subjects, Catalog, Check, History) as a React component. */
|
|
33
|
+
export declare const PermissionsDashboard: React.FC<PermissionsDashboardProps>;
|
|
34
|
+
export { setApiBase, setApiToken } from "./ui/api.ts";
|
|
35
|
+
export type { FetchLike };
|
|
36
|
+
export { setThemePref, getThemePref, detectHostTheme, type ThemePref, type ResolvedTheme, } from "./ui/theme.ts";
|
|
37
|
+
export default PermissionsDashboard;
|