@xtandard/permissions 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (375) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +362 -2
  3. package/bin/xtandard-permissions.mjs +3 -0
  4. package/dist/better-auth-Bp9YVyQa.d.cts +56 -0
  5. package/dist/better-auth-DHyW5-yt.cjs +91 -0
  6. package/dist/better-auth-DHyW5-yt.cjs.map +1 -0
  7. package/dist/better-auth-NO40ZqSM.mjs +74 -0
  8. package/dist/better-auth-NO40ZqSM.mjs.map +1 -0
  9. package/dist/better-auth-NSXgt6ZU.d.mts +56 -0
  10. package/dist/catalog-DA_d1SdC.d.cts +153 -0
  11. package/dist/catalog-DJcJ3ycq.d.mts +153 -0
  12. package/dist/catalog.cjs +198 -0
  13. package/dist/catalog.cjs.map +1 -0
  14. package/dist/catalog.d.cts +3 -0
  15. package/dist/catalog.d.mts +3 -0
  16. package/dist/catalog.mjs +141 -0
  17. package/dist/catalog.mjs.map +1 -0
  18. package/dist/chunk-DakpK96I.cjs +43 -0
  19. package/dist/cli.cjs +548 -0
  20. package/dist/cli.cjs.map +1 -0
  21. package/dist/cli.d.cts +28 -0
  22. package/dist/cli.d.mts +28 -0
  23. package/dist/cli.mjs +544 -0
  24. package/dist/cli.mjs.map +1 -0
  25. package/dist/contract-BMiOmg2f.d.cts +50 -0
  26. package/dist/contract-Bpy8yPrS.cjs +70 -0
  27. package/dist/contract-Bpy8yPrS.cjs.map +1 -0
  28. package/dist/contract-CNgMXr2u.d.cts +46 -0
  29. package/dist/contract-CNgMXr2u.d.mts +46 -0
  30. package/dist/contract-CPmJVoRx.cjs +70 -0
  31. package/dist/contract-CPmJVoRx.cjs.map +1 -0
  32. package/dist/contract-D32H1t0u.d.mts +50 -0
  33. package/dist/contract-DTdTXZtJ.mjs +47 -0
  34. package/dist/contract-DTdTXZtJ.mjs.map +1 -0
  35. package/dist/contract-DUzgB-He.d.mts +375 -0
  36. package/dist/contract-Dk6d2ylD.d.cts +375 -0
  37. package/dist/contract-RMkmERhT.d.cts +2 -0
  38. package/dist/contract-RMkmERhT.d.mts +2 -0
  39. package/dist/contract-Yc5AZuvv.mjs +47 -0
  40. package/dist/contract-Yc5AZuvv.mjs.map +1 -0
  41. package/dist/create-fetch-handler-BHDU4chu.d.mts +77 -0
  42. package/dist/create-fetch-handler-BtX64_rS.d.cts +77 -0
  43. package/dist/create-fetch-handler-C-WyaRCR.cjs +653 -0
  44. package/dist/create-fetch-handler-C-WyaRCR.cjs.map +1 -0
  45. package/dist/create-fetch-handler-ojjpk1Iw.mjs +636 -0
  46. package/dist/create-fetch-handler-ojjpk1Iw.mjs.map +1 -0
  47. package/dist/elysia-shared-BM6cPoCU.mjs +78 -0
  48. package/dist/elysia-shared-BM6cPoCU.mjs.map +1 -0
  49. package/dist/elysia-shared-BUTFTeal.cjs +101 -0
  50. package/dist/elysia-shared-BUTFTeal.cjs.map +1 -0
  51. package/dist/elysia-shared-DtKViycb.d.cts +58 -0
  52. package/dist/elysia-shared-g8zsb_pU.d.mts +58 -0
  53. package/dist/engine-Bufv0TbD.mjs +574 -0
  54. package/dist/engine-Bufv0TbD.mjs.map +1 -0
  55. package/dist/engine-CGGVDCqi.d.cts +296 -0
  56. package/dist/engine-DpFIcbgh.d.mts +296 -0
  57. package/dist/engine-bMoz3iW-.cjs +587 -0
  58. package/dist/engine-bMoz3iW-.cjs.map +1 -0
  59. package/dist/entry-auth-basic.cjs +40 -0
  60. package/dist/entry-auth-basic.cjs.map +1 -0
  61. package/dist/entry-auth-basic.d.cts +24 -0
  62. package/dist/entry-auth-basic.d.mts +24 -0
  63. package/dist/entry-auth-basic.mjs +26 -0
  64. package/dist/entry-auth-basic.mjs.map +1 -0
  65. package/dist/entry-auth-better-auth.cjs +12 -0
  66. package/dist/entry-auth-better-auth.d.cts +5 -0
  67. package/dist/entry-auth-better-auth.d.mts +5 -0
  68. package/dist/entry-auth-better-auth.mjs +4 -0
  69. package/dist/entry-auth-delegated.cjs +8 -0
  70. package/dist/entry-auth-delegated.d.cts +2 -0
  71. package/dist/entry-auth-delegated.d.mts +2 -0
  72. package/dist/entry-auth-delegated.mjs +2 -0
  73. package/dist/entry-auth-jwt.cjs +116 -0
  74. package/dist/entry-auth-jwt.cjs.map +1 -0
  75. package/dist/entry-auth-jwt.d.cts +65 -0
  76. package/dist/entry-auth-jwt.d.mts +65 -0
  77. package/dist/entry-auth-jwt.mjs +108 -0
  78. package/dist/entry-auth-jwt.mjs.map +1 -0
  79. package/dist/entry-auth-none.cjs +14 -0
  80. package/dist/entry-auth-none.d.cts +2 -0
  81. package/dist/entry-auth-none.d.mts +2 -0
  82. package/dist/entry-auth-none.mjs +2 -0
  83. package/dist/entry-auth-session.cjs +82 -0
  84. package/dist/entry-auth-session.cjs.map +1 -0
  85. package/dist/entry-auth-session.d.cts +20 -0
  86. package/dist/entry-auth-session.d.mts +20 -0
  87. package/dist/entry-auth-session.mjs +75 -0
  88. package/dist/entry-auth-session.mjs.map +1 -0
  89. package/dist/entry-authorization-delegated.cjs +31 -0
  90. package/dist/entry-authorization-delegated.cjs.map +1 -0
  91. package/dist/entry-authorization-delegated.d.cts +27 -0
  92. package/dist/entry-authorization-delegated.d.mts +27 -0
  93. package/dist/entry-authorization-delegated.mjs +30 -0
  94. package/dist/entry-authorization-delegated.mjs.map +1 -0
  95. package/dist/entry-authorization-none.cjs +29 -0
  96. package/dist/entry-authorization-none.cjs.map +1 -0
  97. package/dist/entry-authorization-none.d.cts +17 -0
  98. package/dist/entry-authorization-none.d.mts +17 -0
  99. package/dist/entry-authorization-none.mjs +28 -0
  100. package/dist/entry-authorization-none.mjs.map +1 -0
  101. package/dist/entry-authorization-permissions.cjs +4 -0
  102. package/dist/entry-authorization-permissions.d.cts +49 -0
  103. package/dist/entry-authorization-permissions.d.mts +49 -0
  104. package/dist/entry-authorization-permissions.mjs +2 -0
  105. package/dist/entry-authorization-roles.cjs +9 -0
  106. package/dist/entry-authorization-roles.d.cts +37 -0
  107. package/dist/entry-authorization-roles.d.mts +37 -0
  108. package/dist/entry-authorization-roles.mjs +3 -0
  109. package/dist/entry-better-auth-client.cjs +31 -0
  110. package/dist/entry-better-auth-client.cjs.map +1 -0
  111. package/dist/entry-better-auth-client.d.cts +63 -0
  112. package/dist/entry-better-auth-client.d.mts +63 -0
  113. package/dist/entry-better-auth-client.mjs +29 -0
  114. package/dist/entry-better-auth-client.mjs.map +1 -0
  115. package/dist/entry-better-auth.cjs +289 -0
  116. package/dist/entry-better-auth.cjs.map +1 -0
  117. package/dist/entry-better-auth.d.cts +3 -0
  118. package/dist/entry-better-auth.d.mts +3 -0
  119. package/dist/entry-better-auth.mjs +284 -0
  120. package/dist/entry-better-auth.mjs.map +1 -0
  121. package/dist/entry-bridges-audit.cjs +106 -0
  122. package/dist/entry-bridges-audit.cjs.map +1 -0
  123. package/dist/entry-bridges-audit.d.cts +58 -0
  124. package/dist/entry-bridges-audit.d.mts +58 -0
  125. package/dist/entry-bridges-audit.mjs +105 -0
  126. package/dist/entry-bridges-audit.mjs.map +1 -0
  127. package/dist/entry-bridges-webhooks.cjs +90 -0
  128. package/dist/entry-bridges-webhooks.cjs.map +1 -0
  129. package/dist/entry-bridges-webhooks.d.cts +46 -0
  130. package/dist/entry-bridges-webhooks.d.mts +46 -0
  131. package/dist/entry-bridges-webhooks.mjs +88 -0
  132. package/dist/entry-bridges-webhooks.mjs.map +1 -0
  133. package/dist/entry-bun.cjs +33 -0
  134. package/dist/entry-bun.cjs.map +1 -0
  135. package/dist/entry-bun.d.cts +31 -0
  136. package/dist/entry-bun.d.mts +31 -0
  137. package/dist/entry-bun.mjs +30 -0
  138. package/dist/entry-bun.mjs.map +1 -0
  139. package/dist/entry-drizzle-mysql.cjs +34 -0
  140. package/dist/entry-drizzle-mysql.cjs.map +1 -0
  141. package/dist/entry-drizzle-mysql.d.cts +20 -0
  142. package/dist/entry-drizzle-mysql.d.mts +20 -0
  143. package/dist/entry-drizzle-mysql.mjs +33 -0
  144. package/dist/entry-drizzle-mysql.mjs.map +1 -0
  145. package/dist/entry-drizzle-pg.cjs +44 -0
  146. package/dist/entry-drizzle-pg.cjs.map +1 -0
  147. package/dist/entry-drizzle-pg.d.cts +20 -0
  148. package/dist/entry-drizzle-pg.d.mts +20 -0
  149. package/dist/entry-drizzle-pg.mjs +43 -0
  150. package/dist/entry-drizzle-pg.mjs.map +1 -0
  151. package/dist/entry-drizzle-sqlite.cjs +34 -0
  152. package/dist/entry-drizzle-sqlite.cjs.map +1 -0
  153. package/dist/entry-drizzle-sqlite.d.cts +15 -0
  154. package/dist/entry-drizzle-sqlite.d.mts +15 -0
  155. package/dist/entry-drizzle-sqlite.mjs +33 -0
  156. package/dist/entry-drizzle-sqlite.mjs.map +1 -0
  157. package/dist/entry-elysia.cjs +117 -0
  158. package/dist/entry-elysia.cjs.map +1 -0
  159. package/dist/entry-elysia.d.cts +446 -0
  160. package/dist/entry-elysia.d.mts +446 -0
  161. package/dist/entry-elysia.mjs +113 -0
  162. package/dist/entry-elysia.mjs.map +1 -0
  163. package/dist/entry-elysia2.cjs +117 -0
  164. package/dist/entry-elysia2.cjs.map +1 -0
  165. package/dist/entry-elysia2.d.cts +571 -0
  166. package/dist/entry-elysia2.d.mts +571 -0
  167. package/dist/entry-elysia2.mjs +113 -0
  168. package/dist/entry-elysia2.mjs.map +1 -0
  169. package/dist/entry-express.cjs +101 -0
  170. package/dist/entry-express.cjs.map +1 -0
  171. package/dist/entry-express.d.cts +36 -0
  172. package/dist/entry-express.d.mts +36 -0
  173. package/dist/entry-express.mjs +97 -0
  174. package/dist/entry-express.mjs.map +1 -0
  175. package/dist/entry-hono.cjs +63 -0
  176. package/dist/entry-hono.cjs.map +1 -0
  177. package/dist/entry-hono.d.cts +40 -0
  178. package/dist/entry-hono.d.mts +40 -0
  179. package/dist/entry-hono.mjs +60 -0
  180. package/dist/entry-hono.mjs.map +1 -0
  181. package/dist/entry-hooks-log.cjs +39 -0
  182. package/dist/entry-hooks-log.cjs.map +1 -0
  183. package/dist/entry-hooks-log.d.cts +19 -0
  184. package/dist/entry-hooks-log.d.mts +19 -0
  185. package/dist/entry-hooks-log.mjs +36 -0
  186. package/dist/entry-hooks-log.mjs.map +1 -0
  187. package/dist/entry-next.cjs +67 -0
  188. package/dist/entry-next.cjs.map +1 -0
  189. package/dist/entry-next.d.cts +60 -0
  190. package/dist/entry-next.d.mts +60 -0
  191. package/dist/entry-next.mjs +57 -0
  192. package/dist/entry-next.mjs.map +1 -0
  193. package/dist/entry-react.cjs +401 -0
  194. package/dist/entry-react.cjs.map +1 -0
  195. package/dist/entry-react.d.cts +206 -0
  196. package/dist/entry-react.d.mts +206 -0
  197. package/dist/entry-react.mjs +388 -0
  198. package/dist/entry-react.mjs.map +1 -0
  199. package/dist/entry-storage-cloudflare-kv.cjs +8 -0
  200. package/dist/entry-storage-cloudflare-kv.d.cts +2 -0
  201. package/dist/entry-storage-cloudflare-kv.d.mts +2 -0
  202. package/dist/entry-storage-cloudflare-kv.mjs +2 -0
  203. package/dist/entry-storage-drizzle.cjs +71 -0
  204. package/dist/entry-storage-drizzle.cjs.map +1 -0
  205. package/dist/entry-storage-drizzle.d.cts +27 -0
  206. package/dist/entry-storage-drizzle.d.mts +27 -0
  207. package/dist/entry-storage-drizzle.mjs +68 -0
  208. package/dist/entry-storage-drizzle.mjs.map +1 -0
  209. package/dist/entry-storage-file.cjs +54 -0
  210. package/dist/entry-storage-file.cjs.map +1 -0
  211. package/dist/entry-storage-file.d.cts +24 -0
  212. package/dist/entry-storage-file.d.mts +24 -0
  213. package/dist/entry-storage-file.mjs +46 -0
  214. package/dist/entry-storage-file.mjs.map +1 -0
  215. package/dist/entry-storage-libsql.cjs +64 -0
  216. package/dist/entry-storage-libsql.cjs.map +1 -0
  217. package/dist/entry-storage-libsql.d.cts +28 -0
  218. package/dist/entry-storage-libsql.d.mts +28 -0
  219. package/dist/entry-storage-libsql.mjs +61 -0
  220. package/dist/entry-storage-libsql.mjs.map +1 -0
  221. package/dist/entry-storage-memory.cjs +3 -0
  222. package/dist/entry-storage-memory.d.cts +25 -0
  223. package/dist/entry-storage-memory.d.mts +25 -0
  224. package/dist/entry-storage-memory.mjs +2 -0
  225. package/dist/entry-storage-mongodb.cjs +61 -0
  226. package/dist/entry-storage-mongodb.cjs.map +1 -0
  227. package/dist/entry-storage-mongodb.d.cts +25 -0
  228. package/dist/entry-storage-mongodb.d.mts +25 -0
  229. package/dist/entry-storage-mongodb.mjs +58 -0
  230. package/dist/entry-storage-mongodb.mjs.map +1 -0
  231. package/dist/entry-storage-postgres.cjs +62 -0
  232. package/dist/entry-storage-postgres.cjs.map +1 -0
  233. package/dist/entry-storage-postgres.d.cts +29 -0
  234. package/dist/entry-storage-postgres.d.mts +29 -0
  235. package/dist/entry-storage-postgres.mjs +58 -0
  236. package/dist/entry-storage-postgres.mjs.map +1 -0
  237. package/dist/entry-storage-redis.cjs +76 -0
  238. package/dist/entry-storage-redis.cjs.map +1 -0
  239. package/dist/entry-storage-redis.d.cts +29 -0
  240. package/dist/entry-storage-redis.d.mts +29 -0
  241. package/dist/entry-storage-redis.mjs +72 -0
  242. package/dist/entry-storage-redis.mjs.map +1 -0
  243. package/dist/entry-storage-sqlite.cjs +46 -0
  244. package/dist/entry-storage-sqlite.cjs.map +1 -0
  245. package/dist/entry-storage-sqlite.d.cts +22 -0
  246. package/dist/entry-storage-sqlite.d.mts +22 -0
  247. package/dist/entry-storage-sqlite.mjs +43 -0
  248. package/dist/entry-storage-sqlite.mjs.map +1 -0
  249. package/dist/entry-storage-unstorage.cjs +8 -0
  250. package/dist/entry-storage-unstorage.d.cts +2 -0
  251. package/dist/entry-storage-unstorage.d.mts +2 -0
  252. package/dist/entry-storage-unstorage.mjs +2 -0
  253. package/dist/error-codes-9MRMSSMQ.cjs +49 -0
  254. package/dist/error-codes-9MRMSSMQ.cjs.map +1 -0
  255. package/dist/error-codes-CCKuDDu7.mjs +44 -0
  256. package/dist/error-codes-CCKuDDu7.mjs.map +1 -0
  257. package/dist/errors-bL3XQLfE.mjs +54 -0
  258. package/dist/errors-bL3XQLfE.mjs.map +1 -0
  259. package/dist/errors-vVYic8gz.cjs +89 -0
  260. package/dist/errors-vVYic8gz.cjs.map +1 -0
  261. package/dist/events-AE4Ytqmz.d.cts +6 -0
  262. package/dist/events-AE4Ytqmz.d.mts +6 -0
  263. package/dist/events-DYZShrYB.mjs +15 -0
  264. package/dist/events-DYZShrYB.mjs.map +1 -0
  265. package/dist/events-FJ2K0wly.cjs +26 -0
  266. package/dist/events-FJ2K0wly.cjs.map +1 -0
  267. package/dist/guard-BOx5cnMP.mjs +141 -0
  268. package/dist/guard-BOx5cnMP.mjs.map +1 -0
  269. package/dist/guard-C3o7V14m.d.cts +62 -0
  270. package/dist/guard-DCbTnqPz.d.mts +62 -0
  271. package/dist/guard-nwdOYe90.cjs +188 -0
  272. package/dist/guard-nwdOYe90.cjs.map +1 -0
  273. package/dist/index-BVVgDSdq.d.cts +1 -0
  274. package/dist/index-BVVgDSdq.d.mts +1 -0
  275. package/dist/index.cjs +240 -0
  276. package/dist/index.cjs.map +1 -0
  277. package/dist/index.d.cts +195 -0
  278. package/dist/index.d.mts +195 -0
  279. package/dist/index.mjs +60 -0
  280. package/dist/index.mjs.map +1 -0
  281. package/dist/kit-C7tepDB2.cjs +76 -0
  282. package/dist/kit-C7tepDB2.cjs.map +1 -0
  283. package/dist/kit-DMVBLBI9.d.mts +57 -0
  284. package/dist/kit-fzXHYb1l.mjs +65 -0
  285. package/dist/kit-fzXHYb1l.mjs.map +1 -0
  286. package/dist/kit-qAROuhOI.d.cts +57 -0
  287. package/dist/memory-BbBbbY8-.mjs +32 -0
  288. package/dist/memory-BbBbbY8-.mjs.map +1 -0
  289. package/dist/memory-knijqKw_.cjs +39 -0
  290. package/dist/memory-knijqKw_.cjs.map +1 -0
  291. package/dist/permissions-C9PjftY6.mjs +59 -0
  292. package/dist/permissions-C9PjftY6.mjs.map +1 -0
  293. package/dist/permissions-Cxri_P_k.cjs +70 -0
  294. package/dist/permissions-Cxri_P_k.cjs.map +1 -0
  295. package/dist/policy-BQmlo2lu.mjs +3 -0
  296. package/dist/policy-CGA6QD0a.d.mts +4 -0
  297. package/dist/policy-DFq_SYR3.d.cts +4 -0
  298. package/dist/react-embed.js +18710 -0
  299. package/dist/react.css +1 -0
  300. package/dist/relationships-BLYEJ9tc.cjs +907 -0
  301. package/dist/relationships-BLYEJ9tc.cjs.map +1 -0
  302. package/dist/relationships-BfLonEMI.mjs +756 -0
  303. package/dist/relationships-BfLonEMI.mjs.map +1 -0
  304. package/dist/roles-DBk4i8b5.mjs +69 -0
  305. package/dist/roles-DBk4i8b5.mjs.map +1 -0
  306. package/dist/roles-a8B5uZ35.cjs +104 -0
  307. package/dist/roles-a8B5uZ35.cjs.map +1 -0
  308. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  309. package/dist/routes-DtRb3EO0.mjs +1001 -0
  310. package/dist/routes-DtRb3EO0.mjs.map +1 -0
  311. package/dist/routes-irNuuZqo.cjs +1049 -0
  312. package/dist/routes-irNuuZqo.cjs.map +1 -0
  313. package/dist/server-C2F4H6bR.d.cts +886 -0
  314. package/dist/server-CJ7AIJpO.d.mts +886 -0
  315. package/dist/table-DA98mVVT.d.cts +2 -0
  316. package/dist/table-DA98mVVT.d.mts +2 -0
  317. package/dist/testing.cjs +59 -0
  318. package/dist/testing.cjs.map +1 -0
  319. package/dist/testing.d.cts +37 -0
  320. package/dist/testing.d.mts +37 -0
  321. package/dist/testing.mjs +57 -0
  322. package/dist/testing.mjs.map +1 -0
  323. package/dist/types-elysia2/adapters/elysia-shared.d.ts +71 -0
  324. package/dist/types-elysia2/adapters/elysia2.d.ts +432 -0
  325. package/dist/types-elysia2/adapters/guard.d.ts +140 -0
  326. package/dist/types-elysia2/auth/contract.d.ts +9 -0
  327. package/dist/types-elysia2/auth-provider/contract.d.ts +57 -0
  328. package/dist/types-elysia2/auth-provider/kit.d.ts +57 -0
  329. package/dist/types-elysia2/authorization/contract.d.ts +53 -0
  330. package/dist/types-elysia2/authorization/permissions.d.ts +54 -0
  331. package/dist/types-elysia2/catalog.d.ts +197 -0
  332. package/dist/types-elysia2/engine.d.ts +192 -0
  333. package/dist/types-elysia2/entry-elysia2.d.ts +9 -0
  334. package/dist/types-elysia2/errors.d.ts +47 -0
  335. package/dist/types-elysia2/hooks/contract.d.ts +100 -0
  336. package/dist/types-elysia2/keys.d.ts +78 -0
  337. package/dist/types-elysia2/policy.d.ts +13 -0
  338. package/dist/types-elysia2/relationships.d.ts +162 -0
  339. package/dist/types-elysia2/schema.d.ts +299 -0
  340. package/dist/types-elysia2/server/cors.d.ts +8 -0
  341. package/dist/types-elysia2/server/create-fetch-handler.d.ts +87 -0
  342. package/dist/types-elysia2/server/openapi.d.ts +29 -0
  343. package/dist/types-elysia2/server/routes.d.ts +132 -0
  344. package/dist/types-elysia2/server/validation.d.ts +205 -0
  345. package/dist/types-elysia2/storage/contract.d.ts +18 -0
  346. package/dist/types-react/catalog.d.ts +197 -0
  347. package/dist/types-react/engine.d.ts +192 -0
  348. package/dist/types-react/entry-react-embed.d.ts +20 -0
  349. package/dist/types-react/errors.d.ts +47 -0
  350. package/dist/types-react/hooks/contract.d.ts +100 -0
  351. package/dist/types-react/keys.d.ts +78 -0
  352. package/dist/types-react/policy.d.ts +13 -0
  353. package/dist/types-react/react-embed.d.ts +37 -0
  354. package/dist/types-react/relationships.d.ts +162 -0
  355. package/dist/types-react/schema.d.ts +299 -0
  356. package/dist/types-react/storage/contract.d.ts +18 -0
  357. package/dist/types-react/ui/App.d.ts +23 -0
  358. package/dist/types-react/ui/api.d.ts +73 -0
  359. package/dist/types-react/ui/components/perm-bits.d.ts +64 -0
  360. package/dist/types-react/ui/lib/queries.d.ts +46 -0
  361. package/dist/types-react/ui/theme.d.ts +10 -0
  362. package/dist/types-react/ui/types.d.ts +109 -0
  363. package/dist/types-react/ui/views/CatalogView.d.ts +3 -0
  364. package/dist/types-react/ui/views/HistoryView.d.ts +6 -0
  365. package/dist/types-react/ui/views/PlaygroundView.d.ts +14 -0
  366. package/dist/types-react/ui/views/RelationshipsView.d.ts +6 -0
  367. package/dist/types-react/ui/views/SubjectDetailView.d.ts +7 -0
  368. package/dist/types-react/ui/views/SubjectsView.d.ts +6 -0
  369. package/dist/ui/apple-touch-icon.png +0 -0
  370. package/dist/ui/assets/index-DCPZRo-Z.css +1 -0
  371. package/dist/ui/assets/index-uXGOtyuj.js +104 -0
  372. package/dist/ui/favicon.ico +0 -0
  373. package/dist/ui/favicon.svg +15 -0
  374. package/dist/ui/index.html +20 -0
  375. package/package.json +587 -4
@@ -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>;
@@ -0,0 +1,192 @@
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), then evaluate
7
+ * the catalog's rules **synchronously** with `@xtandard/lib/policy/permix`
8
+ * (ADR 0005).
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { createPermissions } from "@xtandard/permissions";
13
+ * import { createMemoryStorage } from "@xtandard/permissions/storage/memory";
14
+ * import { permissions } from "./permissions.ts"; // definePermissions(...)
15
+ *
16
+ * const perms = createPermissions({ catalog: permissions, storage: createMemoryStorage() });
17
+ * await perms.grant({ subject: "user_1", permission: "post:moderate", actor: "admin_1" });
18
+ * await perms.can({ id: "user_1", role: "member" }, "post.publish", post); // true
19
+ * ```
20
+ *
21
+ * @module
22
+ */
23
+ import type { PermissionsCatalog, PermissionsSubject, SubjectIdentity } from "./catalog.ts";
24
+ export type { SubjectIdentity } from "./catalog.ts";
25
+ import { type HookErrorReporter, type PermissionsHooksInput } from "./hooks/contract.ts";
26
+ import type { Ability, DataAtPath, Definition, RelationSchema, RulesPaths } from "./policy.ts";
27
+ import { type RelationshipsApi, type RelationsOptions } from "./relationships.ts";
28
+ import { type CheckResult, type Grant, type GrantInput, type HistoryPage, type HistoryQuery, type ListQuery, type PermissionsSnapshot, type RevokeInput, type SetRoleInput, type SubjectRecord, type UpsertSubjectInput } from "./schema.ts";
29
+ import { type PermissionsStorage } from "./storage/contract.ts";
30
+ /** Options for {@link createPermissions}. */
31
+ export interface PermissionsOptions<D extends Definition = Definition, R extends string = string, P extends string = string, X = undefined, S extends RelationSchema = RelationSchema> {
32
+ /** The catalog from `definePermissions()`. */
33
+ catalog: PermissionsCatalog<D, R, P, X, S>;
34
+ /** Where grants, role assignments and history live (any `@xtandard/permissions/storage/*`). */
35
+ storage: PermissionsStorage;
36
+ /** `before` (veto) / `after` (side effects) hooks around grant, revoke and role writes. */
37
+ hooks?: PermissionsHooksInput;
38
+ /** Receives errors thrown by `after` hooks. Default: a prefixed `console.warn`. */
39
+ onHookError?: HookErrorReporter;
40
+ /**
41
+ * Per-subject cache of the stored role and grants used by checks. Entries expire after `ttlMs`
42
+ * (default 5 000), are dropped on this engine's writes and, when the storage is watchable, on
43
+ * every change it reports. `false` disables it (every check reads the storage).
44
+ */
45
+ cache?: false | {
46
+ ttlMs?: number;
47
+ max?: number;
48
+ };
49
+ /** Clock (unix ms). Default `Date.now`. Decides grant expiry and every stored timestamp. */
50
+ now?: () => number;
51
+ /** When `true`, every write throws {@link ReadonlyError}. */
52
+ readonly?: boolean;
53
+ /** Where operational warnings go. Default: a prefixed `console.warn`. */
54
+ logger?: {
55
+ warn(message: string, error?: unknown): void;
56
+ };
57
+ /** ReBAC tuning (the catalog's `relations`): `maxDepth` of checks and listing walks. */
58
+ relations?: RelationsOptions;
59
+ }
60
+ /** A subject id, an identity, or `null` / `undefined` for a guest (no session). */
61
+ export type SubjectInput = string | SubjectIdentity | null | undefined;
62
+ /** The app context argument of checks: required when the catalog's context type is. */
63
+ export type FactsArgs<X> = undefined extends X ? [facts?: {
64
+ ctx?: X;
65
+ }] : [facts: {
66
+ ctx: X;
67
+ }];
68
+ /** The data a typed check at `Path` takes (`undefined` when the action takes none). */
69
+ export type PathData<D extends Definition, Path extends string> = DataAtPath<D, Path> extends readonly [] ? undefined : DataAtPath<D, Path>[0];
70
+ /** The lib `Ability` of one subject, plus the engine's decision with reasons. */
71
+ export interface PermissionsAbility<D extends Definition = Definition, R extends string = string, P extends string = string> extends Ability<D, R, P, PermissionsSubject> {
72
+ /** The subject id, `null` for a guest. */
73
+ subject: string | null;
74
+ /** The non-expired grants the ability was built from (assignable or not). */
75
+ grants: readonly Grant<P>[];
76
+ /**
77
+ * Decide `path` with reasons (see {@link CheckResult}). Takes an untyped path (e.g. from an HTTP
78
+ * request); an unknown path is denied with `reason: "unknown-path"`. Throws `AsyncRuleError` when
79
+ * the rule returns a Promise (the check denies).
80
+ */
81
+ check(path: string, data?: unknown): CheckResult<R, P>;
82
+ /**
83
+ * Like {@link check}, and also evaluates rules wrapped in the lib's `asyncRule()` (which the
84
+ * synchronous `check` refuses with `AsyncRuleError`). The engine's `check()` / `can()` use it.
85
+ */
86
+ checkAsync(path: string, data?: unknown): Promise<CheckResult<R, P>>;
87
+ }
88
+ /** What `revoke()` returns. */
89
+ export interface RevokeResult<P extends string = string> {
90
+ /** `false` when there was nothing to revoke. */
91
+ removed: boolean;
92
+ /** The revoked grant, when there was one. */
93
+ grant: Grant<P> | null;
94
+ }
95
+ /** What `setRole()` returns. */
96
+ export interface SetRoleResult {
97
+ /** The subject record after the write (`null` when none exists and the role was cleared). */
98
+ record: SubjectRecord | null;
99
+ /** `false` when the stored role already was the requested one. */
100
+ changed: boolean;
101
+ }
102
+ /** A subject as stored: its record and grants. */
103
+ export interface SubjectView<R extends string = string, P extends string = string> {
104
+ id: string;
105
+ /** The stored record, `null` when the subject has none. */
106
+ record: SubjectRecord | null;
107
+ /** The stored role assignment when it is a known, assignable role; else `null`. */
108
+ role: R | null;
109
+ /** The subject's grants (non-expired unless `includeExpired`). */
110
+ grants: Grant<P>[];
111
+ }
112
+ /** One row of `listSubjects()`. */
113
+ export interface SubjectSummary {
114
+ id: string;
115
+ /** The stored role assignment, if any. */
116
+ role: string | null;
117
+ name?: string;
118
+ email?: string;
119
+ /** Stored grants (expired ones included). */
120
+ grantCount: number;
121
+ }
122
+ /**
123
+ * The engine. The relationship methods (`writeRelationship`, `checkRelation`, `listObjects`, …;
124
+ * see {@link RelationshipsApi}) need the catalog's `relations`.
125
+ */
126
+ export interface Permissions<D extends Definition = Definition, R extends string = string, P extends string = string, X = undefined, S extends RelationSchema = RelationSchema> extends RelationshipsApi<S> {
127
+ readonly catalog: PermissionsCatalog<D, R, P, X, S>;
128
+ readonly storage: PermissionsStorage;
129
+ readonly readonly: boolean;
130
+ /**
131
+ * Grant a permission. Idempotent: re-granting returns the existing grant with `created: false`
132
+ * (no history entry, no hooks). An **expired** existing grant is replaced (`created: true`).
133
+ *
134
+ * @throws {NoSubjectError} empty subject. {@link UnknownPermissionError} not assignable.
135
+ * `ValidationError` malformed input or `expiresAt` not in the future. {@link ReadonlyError}.
136
+ */
137
+ grant(input: GrantInput<P>): Promise<{
138
+ grant: Grant<P>;
139
+ created: boolean;
140
+ }>;
141
+ /** Revoke a permission. Idempotent (`removed: false` when absent). Validates like `grant`. */
142
+ revoke(input: RevokeInput<P>): Promise<RevokeResult<P>>;
143
+ /**
144
+ * Grants by subject, by permission (a key scan with a suffix filter), both, or all. Expired
145
+ * grants are left out unless `includeExpired`. Sorted by subject, then permission.
146
+ */
147
+ list(query?: ListQuery<P>): Promise<Grant<P>[]>;
148
+ /**
149
+ * Store a role assignment (overrides the auth provider's role); `role: null` clears it.
150
+ *
151
+ * @throws {UnknownRoleError} not one of `roles`, or the guest role.
152
+ */
153
+ setRole(input: SetRoleInput<R>): Promise<SetRoleResult>;
154
+ /** A subject's stored record and grants (an empty view when nothing is stored). */
155
+ getSubject(id: string, options?: {
156
+ includeExpired?: boolean;
157
+ }): Promise<SubjectView<R, P>>;
158
+ /** Every subject with a record or a grant, sorted by id. */
159
+ listSubjects(): Promise<SubjectSummary[]>;
160
+ /** Create or update a subject's display fields (`null` clears one). Keeps the stored role. */
161
+ upsertSubject(input: UpsertSubjectInput): Promise<SubjectRecord>;
162
+ /** The grant / revoke / role history, newest first, paginated by `cursor`. */
163
+ history(query?: HistoryQuery): Promise<HistoryPage>;
164
+ /**
165
+ * A synchronous ability for many checks against one loaded snapshot of the subject. `null` /
166
+ * `undefined` is a guest (the guest role, no grants).
167
+ */
168
+ ability(subject: SubjectInput, ...facts: FactsArgs<X>): Promise<PermissionsAbility<D, R, P>>;
169
+ /** Decide one typed path with reasons. */
170
+ check<Path extends RulesPaths<D>>(subject: SubjectInput, path: Path, data?: PathData<D, Path>, ...facts: FactsArgs<X>): Promise<CheckResult<R, P>>;
171
+ /** `(await check(...)).allowed`. */
172
+ can<Path extends RulesPaths<D>>(subject: SubjectInput, path: Path, data?: PathData<D, Path>, ...facts: FactsArgs<X>): Promise<boolean>;
173
+ /** The effective role and active assignable permissions, for client hydration (ADR 0009). */
174
+ snapshot(subject: SubjectInput): Promise<PermissionsSnapshot<R, P>>;
175
+ /** Drop one subject's cache entry, or all of them. */
176
+ invalidate(subject?: string): void;
177
+ /** Stop watching the storage. */
178
+ close(): Promise<void>;
179
+ }
180
+ /** Any engine, generics erased (for integrations: auth providers, servers, bridges). */
181
+ export type AnyPermissions = Permissions<any, any, any, any, any>;
182
+ /**
183
+ * Create the engine.
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * const perms = createPermissions({ catalog, storage, cache: { ttlMs: 5_000 } });
188
+ * const decision = await perms.check({ id: "u1", role: "member" }, "post.publish", post);
189
+ * // { allowed, path, subject, role, reason: "role-rule" | "denied-by-rule" | …, explanation }
190
+ * ```
191
+ */
192
+ 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,47 @@
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
+ * | `ValidationError` | malformed input (the kit's, with `errors` / `issues`) |
14
+ * | `AsyncRuleError` | a rule returned a Promise (the lib's; the check denied) |
15
+ *
16
+ * @module
17
+ */
18
+ export { ValidationError, type ValidationIssue } from "@xtandard/kit/util";
19
+ export { AsyncRuleError } from "./policy.ts";
20
+ /** A write (or a check) needs a subject id and got none (no session, or an empty id). */
21
+ export declare class NoSubjectError extends Error {
22
+ constructor(message?: string);
23
+ }
24
+ /** The permission is not in the catalog's `assignable` list. */
25
+ export declare class UnknownPermissionError extends Error {
26
+ /** The rejected permission. */
27
+ readonly permission: string;
28
+ constructor(permission: unknown);
29
+ }
30
+ /** The role is not one of the catalog's `roles` (or may not be assigned). */
31
+ export declare class UnknownRoleError extends Error {
32
+ /** The rejected role. */
33
+ readonly role: string;
34
+ constructor(role: unknown, message?: string);
35
+ }
36
+ /** The caller may not perform the operation (e.g. grant without a manager role). */
37
+ export declare class ForbiddenError extends Error {
38
+ constructor(message?: string);
39
+ }
40
+ /** A referenced record does not exist. */
41
+ export declare class NotFoundError extends Error {
42
+ constructor(message: string);
43
+ }
44
+ /** Thrown by mutating operations when the engine is readonly. */
45
+ export declare class ReadonlyError extends Error {
46
+ constructor(operation: string);
47
+ }
@@ -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";