@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,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Valibot schemas of the HTTP request bodies (docs: the OpenAPI component schemas of the same
|
|
3
|
+
* names). Unknown keys are dropped: the actor of every write is the authenticated principal, never
|
|
4
|
+
* a body field. The engine validates the domain (assignable permission, known role, future expiry).
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import * as v from "valibot";
|
|
9
|
+
/** `POST /api/grants`: `{ subject, permission, reason?, expiresAt? }`. */
|
|
10
|
+
export declare const grantBodySchema: Omit<v.ObjectSchema<{
|
|
11
|
+
readonly subject: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
12
|
+
readonly permission: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
13
|
+
readonly actor: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, v.ObjectSchema<{
|
|
14
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
15
|
+
readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
16
|
+
readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
17
|
+
readonly email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
18
|
+
}, undefined>], undefined>, undefined>, undefined>;
|
|
19
|
+
readonly reason: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1000, "must be at most 1000 characters">]>, undefined>;
|
|
20
|
+
readonly expiresAt: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be an ISO-8601 date">]>, v.SchemaWithPipe<readonly [v.DateSchema<undefined>, v.CheckAction<Date, "must be a valid date">]>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>], undefined>, undefined>, undefined>;
|
|
21
|
+
}, undefined>, "entries" | "~types" | "~run" | "~standard"> & {
|
|
22
|
+
readonly entries: Omit<{
|
|
23
|
+
readonly subject: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
24
|
+
readonly permission: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
25
|
+
readonly actor: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, v.ObjectSchema<{
|
|
26
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
27
|
+
readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
28
|
+
readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
29
|
+
readonly email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
30
|
+
}, undefined>], undefined>, undefined>, undefined>;
|
|
31
|
+
readonly reason: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1000, "must be at most 1000 characters">]>, undefined>;
|
|
32
|
+
readonly expiresAt: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, "must be an ISO-8601 date">]>, v.SchemaWithPipe<readonly [v.DateSchema<undefined>, v.CheckAction<Date, "must be a valid date">]>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>], undefined>, undefined>, undefined>;
|
|
33
|
+
}, "actor">;
|
|
34
|
+
readonly "~standard": v.StandardProps<{
|
|
35
|
+
reason?: string | undefined;
|
|
36
|
+
expiresAt?: string | number | Date | null | undefined;
|
|
37
|
+
subject: string;
|
|
38
|
+
permission: string;
|
|
39
|
+
}, {
|
|
40
|
+
reason?: string | undefined;
|
|
41
|
+
expiresAt?: string | number | Date | null | undefined;
|
|
42
|
+
subject: string;
|
|
43
|
+
permission: string;
|
|
44
|
+
}>;
|
|
45
|
+
readonly "~run": (dataset: v.UnknownDataset, config: v.Config<v.BaseIssue<unknown>>) => v.OutputDataset<{
|
|
46
|
+
reason?: string | undefined;
|
|
47
|
+
expiresAt?: string | number | Date | null | undefined;
|
|
48
|
+
subject: string;
|
|
49
|
+
permission: string;
|
|
50
|
+
}, v.StringIssue | v.MinLengthIssue<string, 1> | v.ObjectIssue | v.MaxLengthIssue<string, 1000> | v.CheckIssue<string> | v.DateIssue | v.CheckIssue<Date> | v.NumberIssue | v.FiniteIssue<number> | v.UnionIssue<v.StringIssue | v.CheckIssue<string> | v.DateIssue | v.CheckIssue<Date> | v.NumberIssue | v.FiniteIssue<number>>>;
|
|
51
|
+
readonly "~types"?: {
|
|
52
|
+
readonly input: {
|
|
53
|
+
reason?: string | undefined;
|
|
54
|
+
expiresAt?: string | number | Date | null | undefined;
|
|
55
|
+
subject: string;
|
|
56
|
+
permission: string;
|
|
57
|
+
};
|
|
58
|
+
readonly output: {
|
|
59
|
+
reason?: string | undefined;
|
|
60
|
+
expiresAt?: string | number | Date | null | undefined;
|
|
61
|
+
subject: string;
|
|
62
|
+
permission: string;
|
|
63
|
+
};
|
|
64
|
+
readonly issue: v.StringIssue | v.MinLengthIssue<string, 1> | v.ObjectIssue | v.MaxLengthIssue<string, 1000> | v.CheckIssue<string> | v.DateIssue | v.CheckIssue<Date> | v.NumberIssue | v.FiniteIssue<number> | v.UnionIssue<v.StringIssue | v.CheckIssue<string> | v.DateIssue | v.CheckIssue<Date> | v.NumberIssue | v.FiniteIssue<number>>;
|
|
65
|
+
} | undefined;
|
|
66
|
+
};
|
|
67
|
+
/** `DELETE /api/grants/:subject/:permission`: optional `{ reason }`. */
|
|
68
|
+
export declare const revokeBodySchema: Omit<v.ObjectSchema<{
|
|
69
|
+
readonly subject: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
70
|
+
readonly permission: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
71
|
+
readonly actor: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, v.ObjectSchema<{
|
|
72
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
73
|
+
readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
74
|
+
readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
75
|
+
readonly email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
76
|
+
}, undefined>], undefined>, undefined>, undefined>;
|
|
77
|
+
readonly reason: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1000, "must be at most 1000 characters">]>, undefined>;
|
|
78
|
+
}, undefined>, "entries" | "~types" | "~run" | "~standard"> & {
|
|
79
|
+
readonly entries: Pick<{
|
|
80
|
+
readonly subject: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
81
|
+
readonly permission: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
82
|
+
readonly actor: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, v.ObjectSchema<{
|
|
83
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
84
|
+
readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
85
|
+
readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
86
|
+
readonly email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
87
|
+
}, undefined>], undefined>, undefined>, undefined>;
|
|
88
|
+
readonly reason: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1000, "must be at most 1000 characters">]>, undefined>;
|
|
89
|
+
}, "reason">;
|
|
90
|
+
readonly "~standard": v.StandardProps<{
|
|
91
|
+
reason?: string | undefined;
|
|
92
|
+
}, {
|
|
93
|
+
reason?: string | undefined;
|
|
94
|
+
}>;
|
|
95
|
+
readonly "~run": (dataset: v.UnknownDataset, config: v.Config<v.BaseIssue<unknown>>) => v.OutputDataset<{
|
|
96
|
+
reason?: string | undefined;
|
|
97
|
+
}, v.StringIssue | v.ObjectIssue | v.MaxLengthIssue<string, 1000>>;
|
|
98
|
+
readonly "~types"?: {
|
|
99
|
+
readonly input: {
|
|
100
|
+
reason?: string | undefined;
|
|
101
|
+
};
|
|
102
|
+
readonly output: {
|
|
103
|
+
reason?: string | undefined;
|
|
104
|
+
};
|
|
105
|
+
readonly issue: v.StringIssue | v.ObjectIssue | v.MaxLengthIssue<string, 1000>;
|
|
106
|
+
} | undefined;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* `PUT /api/subjects/:id`: any of `role` (`null` clears the stored assignment), `name`, `email`
|
|
110
|
+
* (`null` clears), plus the `reason` recorded with a role change.
|
|
111
|
+
*/
|
|
112
|
+
export declare const subjectUpdateBodySchema: v.ObjectSchema<{
|
|
113
|
+
readonly role: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, undefined>, undefined>;
|
|
114
|
+
readonly name: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 500, "must be at most 500 characters">]>, undefined>, undefined>;
|
|
115
|
+
readonly email: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 500, "must be at most 500 characters">]>, undefined>, undefined>;
|
|
116
|
+
readonly reason: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1000, "must be at most 1000 characters">]>, undefined>;
|
|
117
|
+
}, undefined>;
|
|
118
|
+
/**
|
|
119
|
+
* `POST /api/check` (playground): a stored subject, a bare role (no subject, no grants), both (the
|
|
120
|
+
* role is the provider's, a stored role still wins) or neither (a guest).
|
|
121
|
+
*/
|
|
122
|
+
export declare const checkBodySchema: v.ObjectSchema<{
|
|
123
|
+
readonly subject: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, undefined>, undefined>;
|
|
124
|
+
readonly role: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, undefined>;
|
|
125
|
+
readonly path: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
126
|
+
readonly data: v.OptionalSchema<v.UnknownSchema, undefined>;
|
|
127
|
+
readonly ctx: v.OptionalSchema<v.UnknownSchema, undefined>;
|
|
128
|
+
}, undefined>;
|
|
129
|
+
/** `POST /api/me/check`: the caller's own check. */
|
|
130
|
+
export declare const meCheckBodySchema: v.ObjectSchema<{
|
|
131
|
+
readonly path: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
132
|
+
readonly data: v.OptionalSchema<v.UnknownSchema, undefined>;
|
|
133
|
+
}, undefined>;
|
|
134
|
+
/** `POST /api/relationships` and `DELETE /api/relationships`: `{ object, relation, subject, reason? }`. */
|
|
135
|
+
export declare const relationshipBodySchema: Omit<v.ObjectSchema<{
|
|
136
|
+
readonly object: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 512, "must be at most 512 characters">, v.RegexAction<string, "must be \"type:id\" (no \"#\" in the id)">]>;
|
|
137
|
+
readonly relation: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
138
|
+
readonly subject: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 512, "must be at most 512 characters">, v.RegexAction<string, "must be \"type:id\", \"type:id#relation\" or \"type:*\"">]>;
|
|
139
|
+
readonly actor: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, v.ObjectSchema<{
|
|
140
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
141
|
+
readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
142
|
+
readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
143
|
+
readonly email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
144
|
+
}, undefined>], undefined>, undefined>, undefined>;
|
|
145
|
+
readonly reason: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1000, "must be at most 1000 characters">]>, undefined>;
|
|
146
|
+
}, undefined>, "entries" | "~types" | "~run" | "~standard"> & {
|
|
147
|
+
readonly entries: Omit<{
|
|
148
|
+
readonly object: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 512, "must be at most 512 characters">, v.RegexAction<string, "must be \"type:id\" (no \"#\" in the id)">]>;
|
|
149
|
+
readonly relation: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
150
|
+
readonly subject: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 512, "must be at most 512 characters">, v.RegexAction<string, "must be \"type:id\", \"type:id#relation\" or \"type:*\"">]>;
|
|
151
|
+
readonly actor: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, v.ObjectSchema<{
|
|
152
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
153
|
+
readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
154
|
+
readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
155
|
+
readonly email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
156
|
+
}, undefined>], undefined>, undefined>, undefined>;
|
|
157
|
+
readonly reason: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1000, "must be at most 1000 characters">]>, undefined>;
|
|
158
|
+
}, "actor">;
|
|
159
|
+
readonly "~standard": v.StandardProps<{
|
|
160
|
+
object: string;
|
|
161
|
+
reason?: string | undefined;
|
|
162
|
+
subject: string;
|
|
163
|
+
relation: string;
|
|
164
|
+
}, {
|
|
165
|
+
object: string;
|
|
166
|
+
reason?: string | undefined;
|
|
167
|
+
subject: string;
|
|
168
|
+
relation: string;
|
|
169
|
+
}>;
|
|
170
|
+
readonly "~run": (dataset: v.UnknownDataset, config: v.Config<v.BaseIssue<unknown>>) => v.OutputDataset<{
|
|
171
|
+
object: string;
|
|
172
|
+
reason?: string | undefined;
|
|
173
|
+
subject: string;
|
|
174
|
+
relation: string;
|
|
175
|
+
}, v.StringIssue | v.MinLengthIssue<string, 1> | v.ObjectIssue | v.MaxLengthIssue<string, 1000> | v.MaxLengthIssue<string, 512> | v.RegexIssue<string>>;
|
|
176
|
+
readonly "~types"?: {
|
|
177
|
+
readonly input: {
|
|
178
|
+
object: string;
|
|
179
|
+
reason?: string | undefined;
|
|
180
|
+
subject: string;
|
|
181
|
+
relation: string;
|
|
182
|
+
};
|
|
183
|
+
readonly output: {
|
|
184
|
+
object: string;
|
|
185
|
+
reason?: string | undefined;
|
|
186
|
+
subject: string;
|
|
187
|
+
relation: string;
|
|
188
|
+
};
|
|
189
|
+
readonly issue: v.StringIssue | v.MinLengthIssue<string, 1> | v.ObjectIssue | v.MaxLengthIssue<string, 1000> | v.MaxLengthIssue<string, 512> | v.RegexIssue<string>;
|
|
190
|
+
} | undefined;
|
|
191
|
+
};
|
|
192
|
+
/** `POST /api/relationships/check`: `{ subject, relation, object }`. */
|
|
193
|
+
export declare const relationCheckBodySchema: v.ObjectSchema<{
|
|
194
|
+
readonly subject: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 512, "must be at most 512 characters">, v.RegexAction<string, "must be \"type:id\", \"type:id#relation\" or \"type:*\"">]>;
|
|
195
|
+
readonly relation: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
196
|
+
readonly object: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 512, "must be at most 512 characters">, v.RegexAction<string, "must be \"type:id\" (no \"#\" in the id)">]>;
|
|
197
|
+
}, undefined>;
|
|
198
|
+
/** `POST /api/me/relation`: the caller's own relationship check. */
|
|
199
|
+
export declare const meRelationBodySchema: v.ObjectSchema<{
|
|
200
|
+
readonly relation: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
|
|
201
|
+
readonly object: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "must be \"type:id\"">]>;
|
|
202
|
+
}, undefined>;
|
|
203
|
+
export type GrantBody = v.InferOutput<typeof grantBodySchema>;
|
|
204
|
+
export type SubjectUpdateBody = v.InferOutput<typeof subjectUpdateBodySchema>;
|
|
205
|
+
export type CheckBody = v.InferOutput<typeof checkBodySchema>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage contracts. The base {@link PermissionsStorage} is intentionally tiny — four
|
|
3
|
+
* async methods — so users can bring their own backend. Optional capabilities
|
|
4
|
+
* (watch, transactions, compare-and-swap) are separate interfaces that adapters
|
|
5
|
+
* may implement and the core feature-detects.
|
|
6
|
+
*
|
|
7
|
+
* The neutral contract lives in `@xtandard/kit/storage`; these are the
|
|
8
|
+
* permissions names for it.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
export type { CompareAndSwapKvStorage as CompareAndSwapPermissionsStorage, KvStorage as PermissionsStorage, StorageChangeEvent, TransactionalKvStorage as TransactionalPermissionsStorage, WatchableKvStorage as WatchablePermissionsStorage, } from "@xtandard/kit/storage";
|
|
13
|
+
export { isCompareAndSwap, isTransactional, isWatchable } from "@xtandard/kit/storage";
|
|
14
|
+
/**
|
|
15
|
+
* Helper for adapters whose subpath requires an optional peer dependency. Throws
|
|
16
|
+
* a clear, actionable error when the peer is missing.
|
|
17
|
+
*/
|
|
18
|
+
export declare function requirePeer(name: string, subpath: string): never;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The catalog: roles, assignable permissions and per-role rules, declared once
|
|
3
|
+
* in code and shared by the server, the browser and the admin panel (ADR 0002).
|
|
4
|
+
*
|
|
5
|
+
* `definePermissions()` wraps `defineAuthorization` from
|
|
6
|
+
* `@xtandard/lib/policy/permix` (which owns role parsing, the assignable list,
|
|
7
|
+
* the sync-only rule helpers, `createAbility` and `explain`) and adds what the
|
|
8
|
+
* product needs on top: `managerRoles`, labels for the panel, the
|
|
9
|
+
* `directGrants` switch and `effectiveRole()`. The rule user is fixed to
|
|
10
|
+
* {@link PermissionsSubject}, whose `role` the engine sets to the subject's
|
|
11
|
+
* effective role.
|
|
12
|
+
*
|
|
13
|
+
* Depends only on `@xtandard/lib/policy/permix` (and its `permix` peer), so
|
|
14
|
+
* browsers and edge runtimes can import it.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { definePermissions } from "@xtandard/permissions/catalog";
|
|
19
|
+
*
|
|
20
|
+
* type Definition = { post: ["read", { name: "publish"; type: Post }, "delete"] };
|
|
21
|
+
*
|
|
22
|
+
* export const permissions = definePermissions<Definition>()({
|
|
23
|
+
* roles: ["guest", "member", "editor", "admin"], // least → most privileged
|
|
24
|
+
* guestRole: "guest",
|
|
25
|
+
* defaultRole: "member",
|
|
26
|
+
* managerRoles: ["admin"],
|
|
27
|
+
* assignable: ["post:moderate", "billing:refund"],
|
|
28
|
+
* labels: { roles: { admin: "Administrator" }, permissions: { "post:moderate": "Moderate posts" } },
|
|
29
|
+
* rules: {
|
|
30
|
+
* guest: () => ({ post: { read: true, publish: false, delete: false } }),
|
|
31
|
+
* member: ({ user, permissions }, { or, fieldEquals, hasPermission }) => ({
|
|
32
|
+
* post: {
|
|
33
|
+
* read: true,
|
|
34
|
+
* publish: or<Post>(fieldEquals(user!.id, { field: "authorId" }), () =>
|
|
35
|
+
* hasPermission(permissions, "post:moderate"),
|
|
36
|
+
* ),
|
|
37
|
+
* delete: false,
|
|
38
|
+
* },
|
|
39
|
+
* }),
|
|
40
|
+
* editor: () => ({ post: { read: true, publish: true, delete: false } }),
|
|
41
|
+
* admin: () => ({ post: { read: true, publish: true, delete: true } }),
|
|
42
|
+
* },
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @module catalog
|
|
47
|
+
*/
|
|
48
|
+
import { type Authorization, type AuthorizationConfig, type Definition, type RelationSchema } from "./policy.ts";
|
|
49
|
+
/** A catalog without relations (ReBAC off): no object type, so no relation query type-checks. */
|
|
50
|
+
export type NoRelations = Record<never, never>;
|
|
51
|
+
export { computed, defineRelations, direct, exclusion, from, intersection, RelationDepthError, RelationSchemaError, union, } from "./policy.ts";
|
|
52
|
+
export type { ObjectRef, RelationExpr, RelationSchema, RelationTuple, SubjectRef, } from "./policy.ts";
|
|
53
|
+
/** The user the rules see: the engine passes the subject with its effective `role`. */
|
|
54
|
+
export interface PermissionsSubject {
|
|
55
|
+
/** The subject id (a user id in 0.1). */
|
|
56
|
+
id: string;
|
|
57
|
+
/** The effective role (stored assignment, else the auth provider's, else `defaultRole`). */
|
|
58
|
+
role: string;
|
|
59
|
+
name?: string;
|
|
60
|
+
email?: string;
|
|
61
|
+
/** Extra facts from the auth provider (claims, profile fields). */
|
|
62
|
+
attributes?: Record<string, unknown>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Who a check is for, as an auth provider reports it. `role` may be one role, several (the most
|
|
66
|
+
* privileged known one wins, see {@link PermissionsCatalog.effectiveRole}) or missing
|
|
67
|
+
* (`defaultRole`); a stored role assignment overrides it.
|
|
68
|
+
*/
|
|
69
|
+
export interface SubjectIdentity {
|
|
70
|
+
id: string;
|
|
71
|
+
role?: string | readonly string[] | null;
|
|
72
|
+
name?: string;
|
|
73
|
+
email?: string;
|
|
74
|
+
attributes?: Record<string, unknown>;
|
|
75
|
+
}
|
|
76
|
+
/** A human label: a string, or a label with a description. */
|
|
77
|
+
export type LabelInput = string | {
|
|
78
|
+
label: string;
|
|
79
|
+
description?: string;
|
|
80
|
+
};
|
|
81
|
+
/** A normalized label. */
|
|
82
|
+
export interface Label {
|
|
83
|
+
label: string;
|
|
84
|
+
description?: string;
|
|
85
|
+
}
|
|
86
|
+
/** What `definePermissions` adds on top of the lib's `AuthorizationConfig`. */
|
|
87
|
+
export interface CatalogMeta<R extends string, P extends string, S extends RelationSchema = NoRelations> {
|
|
88
|
+
/**
|
|
89
|
+
* The relation schema (ReBAC, ADR 0013), built with `defineRelations` and the `direct` /
|
|
90
|
+
* `computed` / `from` / `union` / `intersection` / `exclusion` builders. Validated again here.
|
|
91
|
+
* Without it, relationship writes and checks throw `RelationSchemaError`.
|
|
92
|
+
*/
|
|
93
|
+
relations?: S;
|
|
94
|
+
/**
|
|
95
|
+
* Roles that may grant / revoke / assign roles by default (an auth provider can override it).
|
|
96
|
+
* Default: the most privileged role (the last of `roles`).
|
|
97
|
+
*/
|
|
98
|
+
managerRoles?: readonly R[];
|
|
99
|
+
/** Labels and descriptions for the admin panel. Missing entries default to the key. */
|
|
100
|
+
labels?: {
|
|
101
|
+
roles?: Partial<Record<R, LabelInput>>;
|
|
102
|
+
permissions?: Partial<Record<P, LabelInput>>;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* When `true`, a non-expired grant whose name equals the checked path allows it outright
|
|
106
|
+
* (`reason: "grant"`), for catalogs whose assignable names are paths. Default `false`: grants
|
|
107
|
+
* only matter through the rules (ADR 0005).
|
|
108
|
+
*/
|
|
109
|
+
directGrants?: boolean;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The configuration of {@link definePermissions}: the lib's `AuthorizationConfig` (roles ordered
|
|
113
|
+
* **least → most privileged**, `guestRole`, `defaultRole`, `assignable`, `rules`) without
|
|
114
|
+
* `getRole` (the engine sets the role), plus {@link CatalogMeta}.
|
|
115
|
+
*/
|
|
116
|
+
export type PermissionsConfig<D extends Definition, R extends string, P extends string, X, S extends RelationSchema = NoRelations> = Omit<AuthorizationConfig<D, R, P, PermissionsSubject, X>, "getRole"> & CatalogMeta<NoInfer<R>, NoInfer<P>, S>;
|
|
117
|
+
/** A catalog: the wrapped lib `Authorization` plus the product metadata. */
|
|
118
|
+
export interface PermissionsCatalog<D extends Definition = Definition, R extends string = string, P extends string = string, X = undefined, S extends RelationSchema = RelationSchema> {
|
|
119
|
+
/** The lib authorization (`createAbility`, `createRules`, `parseRole`, …). */
|
|
120
|
+
readonly authorization: Authorization<D, R, P, PermissionsSubject, X>;
|
|
121
|
+
/** Every role, least → most privileged. */
|
|
122
|
+
readonly roles: readonly R[];
|
|
123
|
+
/** The role of a request without a subject. */
|
|
124
|
+
readonly guestRole: R;
|
|
125
|
+
/** The role of a signed-in subject whose role is missing or unknown. */
|
|
126
|
+
readonly defaultRole: R;
|
|
127
|
+
/** The assignable permissions. */
|
|
128
|
+
readonly assignable: readonly P[];
|
|
129
|
+
/** Roles that may manage permissions by default. */
|
|
130
|
+
readonly managerRoles: readonly R[];
|
|
131
|
+
/** Labels for every role and permission (defaulting to the key). */
|
|
132
|
+
readonly labels: {
|
|
133
|
+
readonly roles: Readonly<Record<R, Label>>;
|
|
134
|
+
readonly permissions: Readonly<Record<P, Label>>;
|
|
135
|
+
};
|
|
136
|
+
/** See {@link CatalogMeta.directGrants}. */
|
|
137
|
+
readonly directGrants: boolean;
|
|
138
|
+
/** The relation schema (ReBAC), `null` when the catalog declares none. */
|
|
139
|
+
readonly relations: S | null;
|
|
140
|
+
/** True when `value` is one of `roles`. */
|
|
141
|
+
isRole(value: unknown): value is R;
|
|
142
|
+
/** True when `value` is one of `assignable`. */
|
|
143
|
+
isAssignable(value: unknown): value is P;
|
|
144
|
+
/** True when `role` is one of `managerRoles`. */
|
|
145
|
+
isManagerRole(role: unknown): boolean;
|
|
146
|
+
/** A signed-in subject's role: `value` when it is a known non-guest role, else `defaultRole`. */
|
|
147
|
+
parseRole(value: unknown): R;
|
|
148
|
+
/**
|
|
149
|
+
* The effective role of a signed-in subject from what an auth provider reports: one role, several
|
|
150
|
+
* (an array, or a comma-separated string as better-auth's admin plugin stores them) → the most
|
|
151
|
+
* privileged known one; none known (or missing) → `defaultRole`. Never the guest role.
|
|
152
|
+
*/
|
|
153
|
+
effectiveRole(raw: string | readonly string[] | null | undefined): R;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The permission type of a catalog: the `assignable` union, or `string` for a roles-only catalog
|
|
157
|
+
* (`assignable: []` infers `never`, which no generic `AnyPermissionsCatalog` slot accepts because
|
|
158
|
+
* rules are contravariant in it). Every permission is still rejected at runtime there.
|
|
159
|
+
*/
|
|
160
|
+
export type PermissionUnion<P extends string> = [P] extends [never] ? string : P;
|
|
161
|
+
/** Any catalog (for generic constraints). */
|
|
162
|
+
export type AnyPermissionsCatalog = PermissionsCatalog<any, any, any, any, any>;
|
|
163
|
+
/** The permix definition of a catalog. */
|
|
164
|
+
export type DefinitionOf<C> = C extends PermissionsCatalog<infer D, any, any, any, any> ? D : never;
|
|
165
|
+
/** The role union of a catalog. */
|
|
166
|
+
export type RoleOf<C> = C extends {
|
|
167
|
+
readonly roles: readonly (infer R)[];
|
|
168
|
+
} ? R : never;
|
|
169
|
+
/** The assignable-permission union of a catalog. */
|
|
170
|
+
export type PermissionOf<C> = C extends {
|
|
171
|
+
readonly assignable: readonly (infer P)[];
|
|
172
|
+
} ? P : never;
|
|
173
|
+
/** The rule context (`ctx`) type of a catalog. */
|
|
174
|
+
export type CtxOf<C> = C extends PermissionsCatalog<any, any, any, infer X, any> ? X : never;
|
|
175
|
+
/** The relation schema of a catalog. */
|
|
176
|
+
export type RelationsOf<C> = C extends PermissionsCatalog<any, any, any, any, infer S> ? S : never;
|
|
177
|
+
/**
|
|
178
|
+
* Define the catalog. Curried like the lib's `defineAuthorization`: the permix definition and the
|
|
179
|
+
* rule context type go in the first call, the roles and permissions are inferred by the second:
|
|
180
|
+
* `definePermissions<Definition, Ctx>()({ ... })`.
|
|
181
|
+
*
|
|
182
|
+
* Rules are synchronous (a rule that returns a Promise denies and throws `AsyncRuleError`); load
|
|
183
|
+
* what they need first and pass it as `ctx` or as the checked data. A rule wrapped in the lib's
|
|
184
|
+
* `asyncRule()` is evaluated only by the engine's async `check()` / `can()`, never by the
|
|
185
|
+
* synchronous `ability()` (ADR 0005).
|
|
186
|
+
*
|
|
187
|
+
* @throws {Error} When `guestRole`, `defaultRole` or a `managerRoles` entry is not in `roles`, a
|
|
188
|
+
* role has no rules, or the guest role is a manager role.
|
|
189
|
+
*/
|
|
190
|
+
export declare function definePermissions<D extends Definition, X = undefined>(): <const R extends string, const P extends string, const S extends RelationSchema = NoRelations>(config: PermissionsConfig<D, R, P, X, S>) => PermissionsCatalog<D, R, PermissionUnion<P>, X, S>;
|
|
191
|
+
/**
|
|
192
|
+
* Wrap an existing lib `Authorization` (from `defineAuthorization`) as a catalog. Its config is
|
|
193
|
+
* re-defined with `getRole: (subject) => subject.role`, so its rules receive a
|
|
194
|
+
* {@link PermissionsSubject} (`{ id, role, name?, email?, attributes? }`) as `user`; rules that read
|
|
195
|
+
* other user fields must move them into `attributes` or `ctx`.
|
|
196
|
+
*/
|
|
197
|
+
export declare function fromAuthorization<D extends Definition, R extends string, P extends string, X, const S extends RelationSchema = NoRelations>(authorization: Authorization<D, R, P, any, X>, meta?: CatalogMeta<NoInfer<R>, NoInfer<P>, S>): PermissionsCatalog<D, R, P, X, S>;
|