@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.
Files changed (375) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +364 -2
  3. package/bin/xtandard-permissions.mjs +3 -0
  4. package/dist/better-auth-BEmX8qyz.mjs +94 -0
  5. package/dist/better-auth-BEmX8qyz.mjs.map +1 -0
  6. package/dist/better-auth-DQET1sXa.d.mts +75 -0
  7. package/dist/better-auth-MR7dBtpo.cjs +111 -0
  8. package/dist/better-auth-MR7dBtpo.cjs.map +1 -0
  9. package/dist/better-auth-vgRYgjYK.d.cts +75 -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 +554 -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 +550 -0
  24. package/dist/cli.mjs.map +1 -0
  25. package/dist/contract-BAisPHBw.d.cts +78 -0
  26. package/dist/contract-BganM0fx.mjs +79 -0
  27. package/dist/contract-BganM0fx.mjs.map +1 -0
  28. package/dist/contract-Bpy8yPrS.cjs +70 -0
  29. package/dist/contract-Bpy8yPrS.cjs.map +1 -0
  30. package/dist/contract-Brnu9XXo.cjs +114 -0
  31. package/dist/contract-Brnu9XXo.cjs.map +1 -0
  32. package/dist/contract-CNgMXr2u.d.cts +46 -0
  33. package/dist/contract-CNgMXr2u.d.mts +46 -0
  34. package/dist/contract-CXPMGuHk.d.cts +391 -0
  35. package/dist/contract-D6j-yrBL.d.mts +78 -0
  36. package/dist/contract-DTdTXZtJ.mjs +47 -0
  37. package/dist/contract-DTdTXZtJ.mjs.map +1 -0
  38. package/dist/contract-DhS23Pcp.d.mts +391 -0
  39. package/dist/contract-RMkmERhT.d.cts +2 -0
  40. package/dist/contract-RMkmERhT.d.mts +2 -0
  41. package/dist/create-fetch-handler-B0twltQL.mjs +673 -0
  42. package/dist/create-fetch-handler-B0twltQL.mjs.map +1 -0
  43. package/dist/create-fetch-handler-B711wb64.d.mts +77 -0
  44. package/dist/create-fetch-handler-BHT4vSZs.cjs +690 -0
  45. package/dist/create-fetch-handler-BHT4vSZs.cjs.map +1 -0
  46. package/dist/create-fetch-handler-DxhvXuBA.d.cts +77 -0
  47. package/dist/elysia-shared-BFcWzfc9.cjs +101 -0
  48. package/dist/elysia-shared-BFcWzfc9.cjs.map +1 -0
  49. package/dist/elysia-shared-BwUYg0Ln.mjs +78 -0
  50. package/dist/elysia-shared-BwUYg0Ln.mjs.map +1 -0
  51. package/dist/elysia-shared-C2LnDOj3.d.cts +58 -0
  52. package/dist/elysia-shared-WuDr0jco.d.mts +58 -0
  53. package/dist/engine--C7zo-4M.cjs +667 -0
  54. package/dist/engine--C7zo-4M.cjs.map +1 -0
  55. package/dist/engine-BTgwbHeO.d.cts +336 -0
  56. package/dist/engine-C3xHfi3q.d.mts +336 -0
  57. package/dist/engine-CR75K253.mjs +654 -0
  58. package/dist/engine-CR75K253.mjs.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 +15 -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 +120 -0
  74. package/dist/entry-auth-jwt.cjs.map +1 -0
  75. package/dist/entry-auth-jwt.d.cts +71 -0
  76. package/dist/entry-auth-jwt.d.mts +71 -0
  77. package/dist/entry-auth-jwt.mjs +109 -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 +86 -0
  84. package/dist/entry-auth-session.cjs.map +1 -0
  85. package/dist/entry-auth-session.d.cts +25 -0
  86. package/dist/entry-auth-session.d.mts +25 -0
  87. package/dist/entry-auth-session.mjs +76 -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-CG_OLEEv.mjs +64 -0
  258. package/dist/errors-CG_OLEEv.mjs.map +1 -0
  259. package/dist/errors-CjpymzFj.cjs +105 -0
  260. package/dist/errors-CjpymzFj.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-Bj8zk23F.mjs +141 -0
  268. package/dist/guard-Bj8zk23F.mjs.map +1 -0
  269. package/dist/guard-DvaoUgjk.cjs +188 -0
  270. package/dist/guard-DvaoUgjk.cjs.map +1 -0
  271. package/dist/guard-VEK0W8ug.d.cts +62 -0
  272. package/dist/guard-k7A71SWC.d.mts +62 -0
  273. package/dist/index-BVVgDSdq.d.cts +1 -0
  274. package/dist/index-BVVgDSdq.d.mts +1 -0
  275. package/dist/index.cjs +243 -0
  276. package/dist/index.cjs.map +1 -0
  277. package/dist/index.d.cts +213 -0
  278. package/dist/index.d.mts +213 -0
  279. package/dist/index.mjs +60 -0
  280. package/dist/index.mjs.map +1 -0
  281. package/dist/kit-51JtMxsn.d.mts +62 -0
  282. package/dist/kit-BM3uosfV.mjs +80 -0
  283. package/dist/kit-BM3uosfV.mjs.map +1 -0
  284. package/dist/kit-BrqnCcDw.cjs +97 -0
  285. package/dist/kit-BrqnCcDw.cjs.map +1 -0
  286. package/dist/kit-DLF7DZrp.d.cts +62 -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-CeV6M3v7.mjs +62 -0
  292. package/dist/permissions-CeV6M3v7.mjs.map +1 -0
  293. package/dist/permissions-DDEkHNvN.cjs +73 -0
  294. package/dist/permissions-DDEkHNvN.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 +18735 -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-B2LrYpT0.cjs +1055 -0
  310. package/dist/routes-B2LrYpT0.cjs.map +1 -0
  311. package/dist/routes-Cx-kl4PY.mjs +1007 -0
  312. package/dist/routes-Cx-kl4PY.mjs.map +1 -0
  313. package/dist/server-Bn643UOy.d.mts +886 -0
  314. package/dist/server-YdH25OEA.d.cts +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 +85 -0
  328. package/dist/types-elysia2/auth-provider/kit.d.ts +62 -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 +233 -0
  333. package/dist/types-elysia2/entry-elysia2.d.ts +9 -0
  334. package/dist/types-elysia2/errors.d.ts +55 -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 +315 -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 +143 -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 +233 -0
  348. package/dist/types-react/entry-react-embed.d.ts +20 -0
  349. package/dist/types-react/errors.d.ts +55 -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 +315 -0
  356. package/dist/types-react/storage/contract.d.ts +18 -0
  357. package/dist/types-react/ui/App.d.ts +28 -0
  358. package/dist/types-react/ui/api.d.ts +73 -0
  359. package/dist/types-react/ui/components/perm-bits.d.ts +68 -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 +118 -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-DdvxpphI.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,315 @@
1
+ /**
2
+ * The data model (what is stored and what checks return) and the valibot
3
+ * schemas of the engine's write inputs. The engine validates every write with
4
+ * them, and the HTTP layer reuses them for request bodies.
5
+ *
6
+ * @module schema
7
+ */
8
+ import type { Actor } from "@xtandard/kit/util";
9
+ import * as v from "valibot";
10
+ import type { CheckExplanation } from "./policy.ts";
11
+ export type { Actor };
12
+ /** A permission granted to one subject. Stored at `perm/grants/{subject}/{permission}`. */
13
+ export interface Grant<P extends string = string> {
14
+ /** The subject id. */
15
+ subject: string;
16
+ /** The permission (one of the catalog's `assignable`). */
17
+ permission: P;
18
+ /** The actor id that granted it: plain data, never a reference (ADR 0003). */
19
+ grantedBy: string | null;
20
+ /** ISO-8601. */
21
+ grantedAt: string;
22
+ /** Why it was granted. */
23
+ reason?: string;
24
+ /** ISO-8601; the grant stops counting at this instant. `null` / absent: never expires. */
25
+ expiresAt?: string | null;
26
+ }
27
+ /** Optional per-subject data. Stored at `perm/subjects/{subject}`. */
28
+ export interface SubjectRecord {
29
+ id: string;
30
+ /** A stored role assignment; when absent, the auth provider's role (or `defaultRole`) applies. */
31
+ role?: string;
32
+ name?: string;
33
+ email?: string;
34
+ /** ISO-8601. */
35
+ updatedAt: string;
36
+ }
37
+ /**
38
+ * A stored relationship (ReBAC tuple, ADR 0013): `subject` has `relation` on `object`. Stored at
39
+ * `perm/rel/{objectType}/{objectId}/{relation}/{subject}`, plus a reverse key for listing.
40
+ */
41
+ export interface Relationship {
42
+ /** The object: `"doc:1"`. */
43
+ object: string;
44
+ /** A relation of the object's type: `"viewer"`. */
45
+ relation: string;
46
+ /** Who: `"user:ana"`, a userset `"group:eng#member"`, or a wildcard `"user:*"`. */
47
+ subject: string;
48
+ /** The actor id that wrote it: plain data, never a reference (ADR 0003). */
49
+ createdBy: string | null;
50
+ /** ISO-8601. */
51
+ createdAt: string;
52
+ /** Why it was written. */
53
+ reason?: string;
54
+ }
55
+ /** The kinds of {@link HistoryEntry}. */
56
+ export type HistoryType = "grant" | "revoke" | "role" | "relate" | "unrelate";
57
+ /**
58
+ * One append-only history entry. Stored at `perm/history/{subject}/{at}-{id}`; for `relate` /
59
+ * `unrelate` the subject is the tuple's subject reference (`user:ana`, `group:eng#member`).
60
+ */
61
+ export interface HistoryEntry {
62
+ id: string;
63
+ type: HistoryType;
64
+ subject: string;
65
+ /** For `relate` / `unrelate`: the tuple's object. */
66
+ object?: string;
67
+ /** For `relate` / `unrelate`: the tuple's relation. */
68
+ relation?: string;
69
+ /** For `grant` / `revoke`. */
70
+ permission?: string;
71
+ /** For `role`: the new role, `null` when the assignment was cleared. */
72
+ role?: string | null;
73
+ /** For `role`: the role before the change (`null`: none was stored). */
74
+ previousRole?: string | null;
75
+ /** For `grant`: the expiry the grant was created with. */
76
+ expiresAt?: string | null;
77
+ /** The actor id. */
78
+ actor: string | null;
79
+ reason?: string;
80
+ /** ISO-8601. */
81
+ at: string;
82
+ }
83
+ /**
84
+ * Why a check came out the way it did (ADR 0005):
85
+ *
86
+ * - `grant`: `directGrants` is on and a non-expired grant named like the path allowed it;
87
+ * - `role-rule`: the role's rule allowed it;
88
+ * - `denied-by-rule`: the role's rule denied it (a `false` constant or a predicate that did not
89
+ * return `true`);
90
+ * - `rule-threw`: the rule threw (denied);
91
+ * - `unknown-path`: the role has no rule at that path (denied).
92
+ */
93
+ export type CheckReason = "grant" | "role-rule" | "denied-by-rule" | "rule-threw" | "unknown-path";
94
+ /** The outcome of `check()`. */
95
+ export interface CheckResult<R extends string = string, P extends string = string> {
96
+ allowed: boolean;
97
+ /** The permix path, e.g. `"post.publish"`. */
98
+ path: string;
99
+ /** The subject id, `null` for a guest. */
100
+ subject: string | null;
101
+ /** The effective role the rules ran as. */
102
+ role: R;
103
+ /** Which source decided {@link role} (absent for a guest). See {@link RoleSource}. */
104
+ roleSource?: RoleSource;
105
+ reason: CheckReason;
106
+ /** The lib's `explain()` detail of the rule alone (role, permissions seen, what decided). */
107
+ explanation: CheckExplanation<R, P>;
108
+ }
109
+ /**
110
+ * Who owns role assignments (the engine's `roleSource` option, ADR 0014). `"stored"` (default): a
111
+ * role set with `setRole()` wins over the auth provider's. `"external"`: the auth provider owns
112
+ * roles; stored roles are ignored and `setRole()` throws `ExternalRolesError`.
113
+ */
114
+ export type RoleSourceMode = "stored" | "external";
115
+ /**
116
+ * Which source decided a subject's effective role: a stored assignment (`"stored"`), the auth
117
+ * provider's role — passed with the identity or from `lookupSubject` (`"provider"`), or the
118
+ * catalog's `defaultRole` because neither gave a known role (`"default"`).
119
+ */
120
+ export type RoleSource = "stored" | "provider" | "default";
121
+ /** The serializable state a client needs to rebuild a subject's ability (React, SSR). */
122
+ export interface PermissionsSnapshot<R extends string = string, P extends string = string> {
123
+ /** The subject and its effective role; `roleSource` is absent for a guest. */
124
+ subject: {
125
+ id: string | null;
126
+ role: R;
127
+ roleSource?: RoleSource;
128
+ };
129
+ /** The non-expired, assignable granted permissions. */
130
+ permissions: P[];
131
+ }
132
+ /** Who performs a write: an actor id, an {@link Actor}, or `null` (system). */
133
+ export declare const actorSchema: v.NullableSchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, v.ObjectSchema<{
134
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
135
+ readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
136
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
137
+ readonly email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
138
+ }, undefined>], undefined>, undefined>;
139
+ /** Input of `grant()`. */
140
+ export declare const grantInputSchema: v.ObjectSchema<{
141
+ readonly subject: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
142
+ readonly permission: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
143
+ readonly actor: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, v.ObjectSchema<{
144
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
145
+ readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
146
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
147
+ readonly email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
148
+ }, undefined>], undefined>, undefined>, undefined>;
149
+ readonly reason: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1000, "must be at most 1000 characters">]>, undefined>;
150
+ /** ISO string, `Date` or unix ms; `null` = never. */
151
+ 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>;
152
+ }, undefined>;
153
+ /** Input of `revoke()`. */
154
+ export declare const revokeInputSchema: v.ObjectSchema<{
155
+ readonly subject: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
156
+ readonly permission: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
157
+ readonly actor: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, v.ObjectSchema<{
158
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
159
+ readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
160
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
161
+ readonly email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
162
+ }, undefined>], undefined>, undefined>, undefined>;
163
+ readonly reason: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1000, "must be at most 1000 characters">]>, undefined>;
164
+ }, undefined>;
165
+ /** Input of `setRole()`; `role: null` clears the stored assignment. */
166
+ export declare const setRoleInputSchema: v.ObjectSchema<{
167
+ readonly subject: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
168
+ readonly role: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, undefined>;
169
+ readonly actor: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, v.ObjectSchema<{
170
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
171
+ readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
172
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
173
+ readonly email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
174
+ }, undefined>], undefined>, undefined>, undefined>;
175
+ readonly reason: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1000, "must be at most 1000 characters">]>, undefined>;
176
+ }, undefined>;
177
+ /** Input of `upsertSubject()`. `null` clears a field. */
178
+ export declare const upsertSubjectInputSchema: v.ObjectSchema<{
179
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
180
+ readonly name: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 500, undefined>]>, undefined>, undefined>;
181
+ readonly email: v.OptionalSchema<v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 500, undefined>]>, undefined>, undefined>;
182
+ }, undefined>;
183
+ /** Query of `list()`. */
184
+ export declare const listQuerySchema: v.ObjectSchema<{
185
+ readonly subject: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, undefined>;
186
+ readonly permission: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, undefined>;
187
+ readonly includeExpired: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
188
+ }, undefined>;
189
+ /** Input of `writeRelationship()` / `deleteRelationship()`. */
190
+ export declare const relationshipInputSchema: v.ObjectSchema<{
191
+ 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)">]>;
192
+ readonly relation: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
193
+ 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:*\"">]>;
194
+ readonly actor: v.OptionalSchema<v.NullableSchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, v.ObjectSchema<{
195
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
196
+ readonly type: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
197
+ readonly name: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
198
+ readonly email: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
199
+ }, undefined>], undefined>, undefined>, undefined>;
200
+ readonly reason: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 1000, "must be at most 1000 characters">]>, undefined>;
201
+ }, undefined>;
202
+ /** Query of `readRelationships()`. */
203
+ export declare const relationshipQuerySchema: v.ObjectSchema<{
204
+ /** `type:id`, or just `type` for every object of a type. */
205
+ readonly object: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, undefined>;
206
+ readonly relation: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, undefined>;
207
+ readonly subject: v.OptionalSchema<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:*\"">]>, undefined>;
208
+ readonly limit: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 1000, undefined>]>, undefined>;
209
+ readonly cursor: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
210
+ }, undefined>;
211
+ /** Input of `checkRelation()`. */
212
+ export declare const relationCheckSchema: v.ObjectSchema<{
213
+ 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:*\"">]>;
214
+ readonly relation: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
215
+ 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)">]>;
216
+ }, undefined>;
217
+ /** Query of `listObjects()`. */
218
+ export declare const listObjectsQuerySchema: v.ObjectSchema<{
219
+ 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:*\"">]>;
220
+ readonly relation: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
221
+ readonly type: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
222
+ }, undefined>;
223
+ /** Query of `listRelationSubjects()`. */
224
+ export declare const listRelationSubjectsQuerySchema: v.ObjectSchema<{
225
+ 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)">]>;
226
+ readonly relation: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>;
227
+ /** Only subjects of this type. */
228
+ readonly type: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, undefined>;
229
+ }, undefined>;
230
+ /** Query of `history()`. */
231
+ export declare const historyQuerySchema: v.ObjectSchema<{
232
+ readonly subject: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, "must not be empty">]>, undefined>;
233
+ readonly limit: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 1000, undefined>]>, undefined>;
234
+ readonly cursor: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
235
+ }, undefined>;
236
+ /** An ISO string, `Date` or unix ms. */
237
+ export type InstantInput = string | Date | number;
238
+ /** Input of `grant()`, typed with the catalog's permissions. */
239
+ export interface GrantInput<P extends string = string> {
240
+ subject: string;
241
+ permission: P;
242
+ actor?: string | Actor | null;
243
+ reason?: string;
244
+ /** When the grant stops counting; `null` / absent = never. */
245
+ expiresAt?: InstantInput | null;
246
+ }
247
+ /** Input of `revoke()`. */
248
+ export interface RevokeInput<P extends string = string> {
249
+ subject: string;
250
+ permission: P;
251
+ actor?: string | Actor | null;
252
+ reason?: string;
253
+ }
254
+ /** Input of `setRole()`. */
255
+ export interface SetRoleInput<R extends string = string> {
256
+ subject: string;
257
+ /** `null` clears the stored role (the auth provider's role, or `defaultRole`, applies again). */
258
+ role: R | null;
259
+ actor?: string | Actor | null;
260
+ reason?: string;
261
+ }
262
+ /** Input of `upsertSubject()`. A field left out is kept; `null` clears it. */
263
+ export interface UpsertSubjectInput {
264
+ id: string;
265
+ name?: string | null;
266
+ email?: string | null;
267
+ }
268
+ /** Query of `list()`. Neither: every grant. */
269
+ export interface ListQuery<P extends string = string> {
270
+ subject?: string;
271
+ permission?: P;
272
+ /** Include grants whose `expiresAt` has passed. Default `false`. */
273
+ includeExpired?: boolean;
274
+ }
275
+ /** Query of `history()`. */
276
+ export interface HistoryQuery {
277
+ /** One subject's history; absent = everyone's. */
278
+ subject?: string;
279
+ /** Page size, 1–1000. Default 50. */
280
+ limit?: number;
281
+ /** The `nextCursor` of the previous page. */
282
+ cursor?: string;
283
+ }
284
+ /** Input of `writeRelationship()` / `deleteRelationship()`. */
285
+ export interface RelationshipInput {
286
+ object: string;
287
+ relation: string;
288
+ subject: string;
289
+ actor?: string | Actor | null;
290
+ reason?: string;
291
+ }
292
+ /** Query of `readRelationships()`. Every field narrows; none: every relationship. */
293
+ export interface RelationshipQuery {
294
+ /** `"doc:1"`, or a bare type (`"doc"`) for every object of that type. */
295
+ object?: string;
296
+ relation?: string;
297
+ /** Exactly this subject reference (`user:ana`, `group:eng#member`, `user:*`). */
298
+ subject?: string;
299
+ /** Page size, 1–1000. Default 100. */
300
+ limit?: number;
301
+ /** The `nextCursor` of the previous page. */
302
+ cursor?: string;
303
+ }
304
+ /** A page of relationships, sorted by object, relation, subject. */
305
+ export interface RelationshipPage {
306
+ relationships: Relationship[];
307
+ /** Pass as `cursor` for the next page; `null` at the end. */
308
+ nextCursor: string | null;
309
+ }
310
+ /** A page of history, newest first. */
311
+ export interface HistoryPage {
312
+ entries: HistoryEntry[];
313
+ /** Pass as `cursor` for the next (older) page; `null` at the end. */
314
+ nextCursor: string | null;
315
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Framework-independent CORS for the mounted panel: with a `cors` option, the handler answers
3
+ * `OPTIONS` preflights itself and decorates every response, so a cross-origin SPA (or
4
+ * `/api/me` from another origin) works whatever the host framework does. The kit's.
5
+ *
6
+ * @module
7
+ */
8
+ export type { CorsOptions as PermissionsCorsOptions } from "@xtandard/kit/server";
@@ -0,0 +1,87 @@
1
+ /**
2
+ * The web-standard fetch handler behind every framework adapter, the CLI's `serve` and the
3
+ * standalone app (ADR 0008): the kit's `createPanelHandler` (healthcheck, static UI, SPA fallback,
4
+ * CORS, OpenAPI) around the permissions API router.
5
+ *
6
+ * Auth plugs in three ways:
7
+ *
8
+ * - `auth` + `authorization`: any kit `AuthProvider` / `AuthorizationProvider` (e.g. `basicAuth` +
9
+ * `rolesAuthorization`, or the pair `toKitAuth(provider, perms)` returns);
10
+ * - `provider`: a `PermissionsAuthProvider` (better-auth, session, JWT), adapted with `toKitAuth`
11
+ * (explicit `auth` / `authorization` still win);
12
+ * - nothing: anonymous, allow-all (embedded / local use only).
13
+ *
14
+ * @module
15
+ */
16
+ import { type ToKitAuthOptions } from "../auth-provider/kit.ts";
17
+ import type { PermissionsAuthProvider } from "../auth-provider/contract.ts";
18
+ import type { AuthProvider, Principal } from "../auth/contract.ts";
19
+ import type { AuthorizationProvider } from "../authorization/contract.ts";
20
+ import type { SubjectIdentity } from "../catalog.ts";
21
+ import { type Permissions, type PermissionsOptions } from "../engine.ts";
22
+ import type { Definition } from "../policy.ts";
23
+ import type { PermissionsCorsOptions } from "./cors.ts";
24
+ /** Options for the panel handler (shared by every framework adapter). */
25
+ export interface PermissionsPanelOptions<D extends Definition = Definition, R extends string = string, P extends string = string, X = undefined> extends Partial<PermissionsOptions<D, R, P, X>> {
26
+ /**
27
+ * The engine to serve. When omitted, one is built from the engine options on this object
28
+ * (`catalog` and `storage` are then required; `hooks`, `cache`, … as for `createPermissions`).
29
+ */
30
+ permissions?: Permissions<D, R, P, X>;
31
+ /** Mount prefix, e.g. `"/permissions"`. Default `""` (root). */
32
+ basePath?: string;
33
+ /** Authentication. Default: from `provider`, else anonymous. */
34
+ auth?: AuthProvider;
35
+ /** Authorization of the admin routes. Default: from `provider`, else allow all. */
36
+ authorization?: AuthorizationProvider;
37
+ /**
38
+ * A `PermissionsAuthProvider` (`auth/better-auth`, `auth/session`, `auth/jwt`, or your own),
39
+ * adapted with `toKitAuth(provider, engine, providerOptions)`: managers (the catalog's
40
+ * `managerRoles`, or the provider's `canManage`) may use the panel.
41
+ */
42
+ provider?: PermissionsAuthProvider;
43
+ /** Options for the `toKitAuth` adaptation of `provider`. */
44
+ providerOptions?: ToKitAuthOptions;
45
+ /** Block grants and role changes (423). Also passed to a constructed engine. */
46
+ readonly?: boolean;
47
+ /** UI title. Default `"@xtandard/permissions"`. */
48
+ title?: string;
49
+ /** Logo image URL shown in the navbar in place of the title. */
50
+ logoUrl?: string;
51
+ /** Override the directory the bundled UI is served from (default `./ui` beside this module). */
52
+ uiDir?: string;
53
+ /** Answer CORS preflights and decorate every response. */
54
+ cors?: PermissionsCorsOptions;
55
+ /** The rules' `ctx` for the caller's runtime checks (`POST /api/me/check`). */
56
+ checkContext?: (request: Request, subject: SubjectIdentity) => unknown;
57
+ /** The caller's ReBAC subject for `POST /api/me/relation`. Default `user:{principal id}`. */
58
+ relationSubject?: (principal: Principal) => string;
59
+ }
60
+ /** Return shape of {@link createFetchHandler}. */
61
+ export interface CreateFetchHandlerResult<D extends Definition = Definition, R extends string = string, P extends string = string, X = undefined> {
62
+ /** Web-standard request handler. */
63
+ fetch(request: Request): Promise<Response>;
64
+ /** The engine (given or constructed): use it in-process for checks. */
65
+ engine: Permissions<D, R, P, X>;
66
+ /** The HTTP API as an OpenAPI 3.1 document (also served at `{basePath}/api/openapi.json`). */
67
+ openapi(): Record<string, unknown>;
68
+ /** Stop the panel's background work (the engine is the caller's to `close()`). */
69
+ close(): void;
70
+ }
71
+ /**
72
+ * Build the panel fetch handler.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * import { createFetchHandler } from "@xtandard/permissions";
77
+ * import { betterAuthProvider } from "@xtandard/permissions/auth/better-auth";
78
+ *
79
+ * const { fetch } = createFetchHandler({
80
+ * permissions: perms,
81
+ * provider: betterAuthProvider(auth, { mapRole: { user: "member" } }),
82
+ * basePath: "/permissions",
83
+ * });
84
+ * Bun.serve({ port: 3000, fetch });
85
+ * ```
86
+ */
87
+ export declare function createFetchHandler<D extends Definition = Definition, R extends string = string, P extends string = string, X = undefined>(options: PermissionsPanelOptions<D, R, P, X>): CreateFetchHandlerResult<D, R, P, X>;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * OpenAPI 3.1 description of the panel's HTTP API, served at `GET {basePath}/api/openapi.json`
3
+ * and returned by `createFetchHandler(...).openapi()` (merge it into the host's document).
4
+ *
5
+ * Paths come from the router's own table ({@link API_ROUTES}), so every served route is
6
+ * documented; admin routes carry their action as `x-action`, runtime routes `x-runtime: true`.
7
+ * Component schemas are hand-authored (no generation dependency, the family's precedent).
8
+ *
9
+ * @module
10
+ */
11
+ /** Options for {@link buildOpenApiDocument}. */
12
+ export interface OpenApiOptions {
13
+ /** Mount prefix used in the `servers` url (e.g. `"/permissions"`). */
14
+ basePath?: string;
15
+ /** Document title. Default `"@xtandard/permissions"`. */
16
+ title?: string;
17
+ /** Document version. Default `"1"` (the HTTP API version, not the package version). */
18
+ version?: string;
19
+ }
20
+ /**
21
+ * Build the OpenAPI 3.1 document for the panel API.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { buildOpenApiDocument } from "@xtandard/permissions";
26
+ * const doc = buildOpenApiDocument({ basePath: "/permissions" });
27
+ * ```
28
+ */
29
+ export declare function buildOpenApiDocument(options?: OpenApiOptions): Record<string, unknown>;
@@ -0,0 +1,143 @@
1
+ /**
2
+ * The panel's JSON API (ADR 0008): the route table on the kit's declarative router
3
+ * (`@xtandard/kit/server/router`), wired to authentication, authorization, the readonly switch
4
+ * (423) and valibot body validation. Returns `null` for non-API paths so the panel falls through
5
+ * to static assets / the SPA.
6
+ *
7
+ * Every route is one entry of {@link API_ROUTES}: method, path, action, resource and handler. The
8
+ * OpenAPI document is generated from the same table, so the two cannot drift.
9
+ *
10
+ * Two kinds of routes:
11
+ *
12
+ * - **admin** routes carry an action (`catalog:read`, `subjects:read`, `grants:read`,
13
+ * `history:read`, `check:run`, `relationships:read`, and the mutating `grants:write`,
14
+ * `roles:write`, `relationships:write`) and go through the authorization provider;
15
+ * - **runtime** routes (`GET /api/me`, `POST /api/me/check`, `POST /api/me/relation`) answer for
16
+ * the caller and need only an authenticated principal (401 otherwise): the provider is not
17
+ * consulted.
18
+ *
19
+ * The actor of every write is the authenticated principal.
20
+ *
21
+ * @module
22
+ */
23
+ import { type ErrorMap } from "@xtandard/kit/server";
24
+ import { type RouteMethod as KitRouteMethod, type RouteQueryParam as KitRouteQueryParam, type RouteSpec as KitRouteSpec, type Router } from "@xtandard/kit/server/router";
25
+ import type { AuthProvider, Principal } from "../auth/contract.ts";
26
+ import { type AuthorizationProvider, type PermissionsAction, type PermissionsResource } from "../authorization/contract.ts";
27
+ import type { AnyPermissionsCatalog, SubjectIdentity } from "../catalog.ts";
28
+ import type { AnyPermissions, SubjectSummary, SubjectView } from "../engine.ts";
29
+ import { type RelationTypeView } from "../relationships.ts";
30
+ import type { CheckResult, RoleSource, RoleSourceMode } from "../schema.ts";
31
+ /** Everything the API router needs. */
32
+ export interface ApiContext {
33
+ engine: AnyPermissions;
34
+ auth: AuthProvider;
35
+ authorization: AuthorizationProvider;
36
+ title: string;
37
+ readonly: boolean;
38
+ basePath: string;
39
+ logoUrl?: string;
40
+ /** The document served at `/api/openapi.json`. */
41
+ openapi?: () => Record<string, unknown>;
42
+ /**
43
+ * The rules' `ctx` for the caller's runtime checks (`/api/me/check`), for catalogs whose rules
44
+ * read app facts. The caller can't supply `ctx` on that route.
45
+ */
46
+ checkContext?: (request: Request, subject: SubjectIdentity) => unknown;
47
+ /**
48
+ * The ReBAC subject of the caller for `POST /api/me/relation`. Default `user:{principal id}`.
49
+ */
50
+ relationSubject?: (principal: Principal) => string;
51
+ }
52
+ /** `GET /config` (and `/api/config`): the SPA bootstrap. */
53
+ export interface PanelConfig {
54
+ title: string;
55
+ logoUrl?: string;
56
+ basePath: string;
57
+ readonly: boolean;
58
+ /** Who owns roles (ADR 0014): `"external"` hides role changes (the auth provider owns them). */
59
+ roleSource: RoleSourceMode;
60
+ authenticated: boolean;
61
+ /**
62
+ * The caller, with its effective catalog role and the source that decided it; `null` when not
63
+ * authenticated.
64
+ */
65
+ principal: {
66
+ id: string;
67
+ role: string;
68
+ roleSource?: RoleSource;
69
+ name?: string;
70
+ email?: string;
71
+ } | null;
72
+ /**
73
+ * The ADR 0008 actions the caller may perform. Mutating actions are left out of a readonly
74
+ * panel, so the SPA can hide write UI from this list alone.
75
+ */
76
+ allowed: PermissionsAction[];
77
+ }
78
+ /** A role or permission with its label. */
79
+ export interface LabeledKey {
80
+ key: string;
81
+ label: string;
82
+ description?: string;
83
+ }
84
+ /** `GET /api/catalog`. */
85
+ export interface CatalogView {
86
+ /** Least → most privileged. */
87
+ roles: LabeledKey[];
88
+ assignable: LabeledKey[];
89
+ guestRole: string;
90
+ defaultRole: string;
91
+ managerRoles: string[];
92
+ directGrants: boolean;
93
+ /** Who owns roles: `"stored"` (role changes allowed) or `"external"` (the auth provider's). */
94
+ roleSource: RoleSourceMode;
95
+ /** Every leaf permix path of every role's rules tree, sorted (for the playground). */
96
+ paths: string[];
97
+ /** The relation schema (ReBAC), `null` when the catalog declares none. */
98
+ relations: RelationTypeView[] | null;
99
+ }
100
+ /** `GET /api/subjects`. */
101
+ export interface SubjectList {
102
+ subjects: SubjectSummary[];
103
+ }
104
+ /** `GET /api/subjects/:id`: the stored view plus the effective role and active permissions. */
105
+ export interface SubjectDetail extends SubjectView {
106
+ /**
107
+ * The role checks use: the stored role (`roleSource: "stored"` mode only), else the auth
108
+ * provider's (`lookupSubject`), else the catalog's `defaultRole`; `roleSource` says which.
109
+ */
110
+ effectiveRole: string;
111
+ /** The non-expired, assignable granted permissions. */
112
+ permissions: string[];
113
+ }
114
+ /** Route tags (OpenAPI grouping). */
115
+ export type RouteTag = "panel" | "catalog" | "subjects" | "grants" | "history" | "check" | "relationships" | "runtime";
116
+ /** HTTP methods the router serves. */
117
+ export type RouteMethod = KitRouteMethod;
118
+ /** A query parameter a route documents. */
119
+ export type RouteQueryParam = KitRouteQueryParam;
120
+ /** The documented shape of one route (consumed by the OpenAPI builder). */
121
+ export type RouteSpec = KitRouteSpec<PermissionsAction, RouteTag> & {
122
+ /** Runtime route: needs an authenticated principal, no action. */
123
+ runtime?: boolean;
124
+ };
125
+ /**
126
+ * Every leaf path of every role's rules tree. The trees are built (never evaluated) with a
127
+ * placeholder subject and no grants; a role whose rules can't be built that way is skipped.
128
+ */
129
+ export declare function catalogPaths(catalog: AnyPermissionsCatalog): string[];
130
+ /** The catalog view served at `/api/catalog` (`roleSource`: the engine's, default `"stored"`). */
131
+ export declare function catalogView(catalog: AnyPermissionsCatalog, roleSource?: RoleSourceMode): CatalogView;
132
+ /** A check result as JSON: `explanation.error` (a thrown value) becomes its message. */
133
+ export declare function serializeCheck(result: CheckResult): CheckResult;
134
+ /** The documented route table (every API route, in match order). */
135
+ export declare const API_ROUTES: readonly RouteSpec[];
136
+ /** The paths served as the bootstrap config (not in {@link API_ROUTES}). */
137
+ export declare const CONFIG_PATHS: readonly string[];
138
+ /** Domain errors by name (ADR 0008); see `@xtandard/kit/server` `mapError`. */
139
+ export declare const ERRORS: ErrorMap;
140
+ /** Build the API router for one panel. */
141
+ export declare function createApiRouter(ctx: ApiContext): Router<PermissionsAction, PermissionsResource, ApiContext, never, RouteTag>;
142
+ /** Map domain errors to HTTP responses (ADR 0008), by name across bundles. */
143
+ export declare function mapError(err: unknown): Response;