@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,1049 @@
1
+ const require_chunk = require("./chunk-DakpK96I.cjs");
2
+ const require_relationships = require("./relationships-BLYEJ9tc.cjs");
3
+ const require_errors = require("./errors-vVYic8gz.cjs");
4
+ const require_contract = require("./contract-Bpy8yPrS.cjs");
5
+ const require_permissions = require("./permissions-Cxri_P_k.cjs");
6
+ let valibot = require("valibot");
7
+ valibot = require_chunk.__toESM(valibot, 1);
8
+ let _xtandard_kit_util = require("@xtandard/kit/util");
9
+ let _xtandard_kit_server = require("@xtandard/kit/server");
10
+ let _xtandard_kit_server_router = require("@xtandard/kit/server/router");
11
+ //#region src/server/validation.ts
12
+ /**
13
+ * Valibot schemas of the HTTP request bodies (docs: the OpenAPI component schemas of the same
14
+ * names). Unknown keys are dropped: the actor of every write is the authenticated principal, never
15
+ * a body field. The engine validates the domain (assignable permission, known role, future expiry).
16
+ *
17
+ * @module
18
+ */
19
+ const nonEmpty = valibot.pipe(valibot.string(), valibot.minLength(1, "must not be empty"));
20
+ const reason = valibot.pipe(valibot.string(), valibot.maxLength(1e3, "must be at most 1000 characters"));
21
+ const display = valibot.nullable(valibot.pipe(valibot.string(), valibot.maxLength(500, "must be at most 500 characters")));
22
+ /** `POST /api/grants`: `{ subject, permission, reason?, expiresAt? }`. */
23
+ const grantBodySchema = valibot.omit(require_relationships.grantInputSchema, ["actor"]);
24
+ /** `DELETE /api/grants/:subject/:permission`: optional `{ reason }`. */
25
+ const revokeBodySchema = valibot.pick(require_relationships.revokeInputSchema, ["reason"]);
26
+ /**
27
+ * `PUT /api/subjects/:id`: any of `role` (`null` clears the stored assignment), `name`, `email`
28
+ * (`null` clears), plus the `reason` recorded with a role change.
29
+ */
30
+ const subjectUpdateBodySchema = valibot.object({
31
+ role: valibot.optional(valibot.nullable(nonEmpty)),
32
+ name: valibot.optional(display),
33
+ email: valibot.optional(display),
34
+ reason: valibot.optional(reason)
35
+ });
36
+ /**
37
+ * `POST /api/check` (playground): a stored subject, a bare role (no subject, no grants), both (the
38
+ * role is the provider's, a stored role still wins) or neither (a guest).
39
+ */
40
+ const checkBodySchema = valibot.object({
41
+ subject: valibot.optional(valibot.nullable(nonEmpty)),
42
+ role: valibot.optional(nonEmpty),
43
+ path: nonEmpty,
44
+ data: valibot.optional(valibot.unknown()),
45
+ ctx: valibot.optional(valibot.unknown())
46
+ });
47
+ /** `POST /api/me/check`: the caller's own check. */
48
+ const meCheckBodySchema = valibot.object({
49
+ path: nonEmpty,
50
+ data: valibot.optional(valibot.unknown())
51
+ });
52
+ /** `POST /api/relationships` and `DELETE /api/relationships`: `{ object, relation, subject, reason? }`. */
53
+ const relationshipBodySchema = valibot.omit(require_relationships.relationshipInputSchema, ["actor"]);
54
+ /** `POST /api/relationships/check`: `{ subject, relation, object }`. */
55
+ const relationCheckBodySchema = require_relationships.relationCheckSchema;
56
+ /** `POST /api/me/relation`: the caller's own relationship check. */
57
+ const meRelationBodySchema = valibot.object({
58
+ relation: nonEmpty,
59
+ object: valibot.pipe(valibot.string(), valibot.regex(/^[^:#]+:[^#]+$/, "must be \"type:id\""))
60
+ });
61
+ //#endregion
62
+ //#region src/server/routes.ts
63
+ /**
64
+ * The panel's JSON API (ADR 0008): the route table on the kit's declarative router
65
+ * (`@xtandard/kit/server/router`), wired to authentication, authorization, the readonly switch
66
+ * (423) and valibot body validation. Returns `null` for non-API paths so the panel falls through
67
+ * to static assets / the SPA.
68
+ *
69
+ * Every route is one entry of {@link API_ROUTES}: method, path, action, resource and handler. The
70
+ * OpenAPI document is generated from the same table, so the two cannot drift.
71
+ *
72
+ * Two kinds of routes:
73
+ *
74
+ * - **admin** routes carry an action (`catalog:read`, `subjects:read`, `grants:read`,
75
+ * `history:read`, `check:run`, `relationships:read`, and the mutating `grants:write`,
76
+ * `roles:write`, `relationships:write`) and go through the authorization provider;
77
+ * - **runtime** routes (`GET /api/me`, `POST /api/me/check`, `POST /api/me/relation`) answer for
78
+ * the caller and need only an authenticated principal (401 otherwise): the provider is not
79
+ * consulted.
80
+ *
81
+ * The actor of every write is the authenticated principal.
82
+ *
83
+ * @module
84
+ */
85
+ var routes_exports = /* @__PURE__ */ require_chunk.__exportAll({
86
+ API_ROUTES: () => API_ROUTES,
87
+ CONFIG_PATHS: () => CONFIG_PATHS,
88
+ ERRORS: () => ERRORS,
89
+ catalogPaths: () => catalogPaths,
90
+ catalogView: () => catalogView,
91
+ createApiRouter: () => createApiRouter,
92
+ mapError: () => mapError,
93
+ serializeCheck: () => serializeCheck
94
+ });
95
+ /** The actor of a write: the authenticated principal. */
96
+ function actorOf(c) {
97
+ const p = c.principal;
98
+ if (!p) return null;
99
+ return {
100
+ id: p.id,
101
+ type: "user",
102
+ ...p.name !== void 0 ? { name: p.name } : {},
103
+ ...p.email !== void 0 ? { email: p.email } : {}
104
+ };
105
+ }
106
+ const labeled = (key, label) => ({
107
+ key,
108
+ label: label.label,
109
+ ...label.description !== void 0 ? { description: label.description } : {}
110
+ });
111
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
112
+ const pathsCache = /* @__PURE__ */ new WeakMap();
113
+ /**
114
+ * Every leaf path of every role's rules tree. The trees are built (never evaluated) with a
115
+ * placeholder subject and no grants; a role whose rules can't be built that way is skipped.
116
+ */
117
+ function catalogPaths(catalog) {
118
+ const cached = pathsCache.get(catalog);
119
+ if (cached) return cached;
120
+ const paths = /* @__PURE__ */ new Set();
121
+ const walk = (node, prefix) => {
122
+ if (!isRecord(node)) {
123
+ if (prefix && (typeof node === "boolean" || typeof node === "function")) paths.add(prefix);
124
+ return;
125
+ }
126
+ for (const key of Object.keys(node)) walk(node[key], prefix ? `${prefix}.${key}` : key);
127
+ };
128
+ const createRules = catalog.authorization.createRules;
129
+ for (const role of catalog.roles) {
130
+ const user = role === catalog.guestRole ? void 0 : {
131
+ id: "",
132
+ role
133
+ };
134
+ try {
135
+ walk(createRules(user, { permissions: [] }), "");
136
+ } catch {}
137
+ }
138
+ const out = [...paths].sort();
139
+ pathsCache.set(catalog, out);
140
+ return out;
141
+ }
142
+ /** The catalog view served at `/api/catalog`. */
143
+ function catalogView(catalog) {
144
+ const roles = catalog.roles;
145
+ const assignable = catalog.assignable;
146
+ const labels = catalog.labels;
147
+ return {
148
+ roles: roles.map((role) => labeled(role, labels.roles[role] ?? { label: role })),
149
+ assignable: assignable.map((p) => labeled(p, labels.permissions[p] ?? { label: p })),
150
+ guestRole: catalog.guestRole,
151
+ defaultRole: catalog.defaultRole,
152
+ managerRoles: [...catalog.managerRoles],
153
+ directGrants: catalog.directGrants,
154
+ paths: catalogPaths(catalog),
155
+ relations: catalog.relations ? require_relationships.relationSchemaView(catalog.relations) : null
156
+ };
157
+ }
158
+ /** A check result as JSON: `explanation.error` (a thrown value) becomes its message. */
159
+ function serializeCheck(result) {
160
+ const error = result.explanation.error;
161
+ if (error === void 0) return result;
162
+ const message = error instanceof Error ? error.message || error.name : typeof error === "string" ? error : "";
163
+ return {
164
+ ...result,
165
+ explanation: {
166
+ ...result.explanation,
167
+ error: message || String(error)
168
+ }
169
+ };
170
+ }
171
+ /** The subject detail served at `/api/subjects/:id`. */
172
+ async function subjectDetail(engine, id) {
173
+ const [view, snapshot] = await Promise.all([engine.getSubject(id), engine.snapshot(id)]);
174
+ return {
175
+ ...view,
176
+ effectiveRole: snapshot.subject.role,
177
+ permissions: snapshot.permissions
178
+ };
179
+ }
180
+ /** The resource every action is evaluated on for the bootstrap's `allowed` list. */
181
+ const COLLECTION = {
182
+ "catalog:read": { type: "catalog" },
183
+ "subjects:read": { type: "subject" },
184
+ "grants:read": { type: "grant" },
185
+ "history:read": { type: "history" },
186
+ "check:run": { type: "check" },
187
+ "relationships:read": { type: "relationship" },
188
+ "grants:write": { type: "grant" },
189
+ "roles:write": { type: "subject" },
190
+ "relationships:write": { type: "relationship" }
191
+ };
192
+ async function panelConfig(c) {
193
+ const { ctx, principal, request } = c;
194
+ let who = null;
195
+ const allowed = [];
196
+ if (principal) {
197
+ const identity = require_permissions.principalIdentity(principal);
198
+ const snapshot = await ctx.engine.snapshot(identity);
199
+ who = {
200
+ id: principal.id,
201
+ role: snapshot.subject.role,
202
+ ...identity.name !== void 0 ? { name: identity.name } : {},
203
+ ...identity.email !== void 0 ? { email: identity.email } : {}
204
+ };
205
+ const decisions = await Promise.all(require_contract.ALL_ACTIONS.map((action) => ctx.readonly && require_contract.isMutatingAction(action) ? false : ctx.authorization.authorize({
206
+ principal,
207
+ action,
208
+ resource: COLLECTION[action],
209
+ request
210
+ })));
211
+ require_contract.ALL_ACTIONS.forEach((action, i) => decisions[i] && allowed.push(action));
212
+ }
213
+ return {
214
+ title: ctx.title,
215
+ ...ctx.logoUrl !== void 0 ? { logoUrl: ctx.logoUrl } : {},
216
+ basePath: ctx.basePath,
217
+ readonly: ctx.readonly,
218
+ authenticated: principal !== null,
219
+ principal: who,
220
+ allowed
221
+ };
222
+ }
223
+ const NO_PRINCIPAL = () => (0, _xtandard_kit_server.json)({
224
+ error: "Unauthorized: no authenticated subject",
225
+ code: "NO_SUBJECT"
226
+ }, 401);
227
+ /** The caller as a subject (runtime routes). */
228
+ function callerOf(principal) {
229
+ return require_permissions.principalIdentity(principal);
230
+ }
231
+ const subjectRes = (c) => ({
232
+ type: "subject",
233
+ subject: c.params.id
234
+ });
235
+ const truthy = (value) => value === "true" || value === "1";
236
+ /** The caller's ReBAC subject (`POST /api/me/relation`). */
237
+ const relationSubjectOf = (c, principal) => c.ctx.relationSubject?.(principal) ?? `user:${principal.id}`;
238
+ /** `?name=` or `undefined` when absent / empty. */
239
+ const queryOf = (c, name) => c.query.get(name) || void 0;
240
+ /** The relationship a request names: the JSON body, or `?object=&relation=&subject=` (DELETE). */
241
+ async function relationshipOf(c) {
242
+ if (queryOf(c, "object") === void 0) return c.body(relationshipBodySchema);
243
+ const fromQuery = {};
244
+ for (const name of [
245
+ "object",
246
+ "relation",
247
+ "subject",
248
+ "reason"
249
+ ]) {
250
+ const value = queryOf(c, name);
251
+ if (value !== void 0) fromQuery[name] = value;
252
+ }
253
+ return (0, _xtandard_kit_util.parseInput)(relationshipBodySchema, fromQuery);
254
+ }
255
+ /** A role-only playground check runs as this placeholder (no record, no grants). */
256
+ const ROLE_PREVIEW_ID = "\0role-preview";
257
+ const ROUTES = [
258
+ {
259
+ method: "GET",
260
+ path: "/healthcheck",
261
+ operationId: "healthcheck",
262
+ summary: "Liveness probe",
263
+ tag: "panel",
264
+ response: {
265
+ status: 200,
266
+ schema: "Health",
267
+ description: "Alive"
268
+ },
269
+ handle: () => (0, _xtandard_kit_server.json)({ ok: true })
270
+ },
271
+ {
272
+ method: "GET",
273
+ path: "/api/openapi.json",
274
+ operationId: "getOpenApi",
275
+ summary: "This OpenAPI 3.1 document",
276
+ tag: "panel",
277
+ response: {
278
+ status: 200,
279
+ schema: { type: "object" },
280
+ description: "OpenAPI 3.1"
281
+ },
282
+ handle: (c) => (0, _xtandard_kit_server.json)(c.ctx.openapi?.() ?? {})
283
+ },
284
+ {
285
+ method: "GET",
286
+ path: "/api/catalog",
287
+ operationId: "getCatalog",
288
+ summary: "The catalog: roles, assignable permissions, labels and every rule path",
289
+ tag: "catalog",
290
+ action: "catalog:read",
291
+ resource: () => ({ type: "catalog" }),
292
+ response: {
293
+ status: 200,
294
+ schema: "CatalogView",
295
+ description: "Catalog"
296
+ },
297
+ handle: (c) => (0, _xtandard_kit_server.json)(catalogView(c.ctx.engine.catalog))
298
+ },
299
+ {
300
+ method: "GET",
301
+ path: "/api/subjects",
302
+ operationId: "listSubjects",
303
+ summary: "Every subject with a record or a grant, sorted by id",
304
+ tag: "subjects",
305
+ action: "subjects:read",
306
+ query: [{
307
+ name: "search",
308
+ type: "string",
309
+ description: "Substring of id, name or email."
310
+ }],
311
+ resource: () => ({ type: "subject" }),
312
+ response: {
313
+ status: 200,
314
+ schema: "SubjectList",
315
+ description: "Subjects"
316
+ },
317
+ async handle(c) {
318
+ const search = c.query.get("search")?.trim().toLowerCase() || void 0;
319
+ let subjects = await c.ctx.engine.listSubjects();
320
+ if (search !== void 0) subjects = subjects.filter((s) => [
321
+ s.id,
322
+ s.name,
323
+ s.email
324
+ ].some((f) => f?.toLowerCase().includes(search)));
325
+ return (0, _xtandard_kit_server.json)({ subjects });
326
+ }
327
+ },
328
+ {
329
+ method: "GET",
330
+ path: "/api/subjects/:id",
331
+ operationId: "getSubject",
332
+ summary: "A subject's record, grants, effective role and active permissions",
333
+ tag: "subjects",
334
+ action: "subjects:read",
335
+ query: [{
336
+ name: "includeExpired",
337
+ type: "string",
338
+ description: "`true` to include expired grants."
339
+ }],
340
+ resource: subjectRes,
341
+ response: {
342
+ status: 200,
343
+ schema: "SubjectDetail",
344
+ description: "Subject"
345
+ },
346
+ async handle(c) {
347
+ const id = c.params.id;
348
+ const detail = await subjectDetail(c.ctx.engine, id);
349
+ if (truthy(c.query.get("includeExpired"))) detail.grants = (await c.ctx.engine.getSubject(id, { includeExpired: true })).grants;
350
+ return (0, _xtandard_kit_server.json)(detail);
351
+ }
352
+ },
353
+ {
354
+ method: "PUT",
355
+ path: "/api/subjects/:id",
356
+ operationId: "updateSubject",
357
+ summary: "Assign or clear a stored role; set or clear the display name / email",
358
+ description: "`role: null` clears the stored assignment (the auth provider's role, or `defaultRole`, applies again). A field left out is kept. The role change is recorded in the history with the principal as actor.",
359
+ tag: "subjects",
360
+ action: "roles:write",
361
+ resource: subjectRes,
362
+ body: "SubjectUpdate",
363
+ response: {
364
+ status: 200,
365
+ schema: "SubjectDetail",
366
+ description: "The updated subject"
367
+ },
368
+ async handle(c) {
369
+ const id = c.params.id;
370
+ const body = await c.body(subjectUpdateBodySchema);
371
+ const { engine } = c.ctx;
372
+ if (body.role !== void 0) {
373
+ if (body.role !== null && !engine.catalog.isRole(body.role)) throw new require_errors.UnknownRoleError(body.role);
374
+ await engine.setRole({
375
+ subject: id,
376
+ role: body.role,
377
+ actor: actorOf(c),
378
+ ...body.reason !== void 0 ? { reason: body.reason } : {}
379
+ });
380
+ }
381
+ if (body.name !== void 0 || body.email !== void 0) await engine.upsertSubject({
382
+ id,
383
+ ...body.name !== void 0 ? { name: body.name } : {},
384
+ ...body.email !== void 0 ? { email: body.email } : {}
385
+ });
386
+ return (0, _xtandard_kit_server.json)(await subjectDetail(engine, id));
387
+ }
388
+ },
389
+ {
390
+ method: "GET",
391
+ path: "/api/grants",
392
+ operationId: "listGrants",
393
+ summary: "Grants by subject, by permission, both, or all (sorted by subject, permission)",
394
+ tag: "grants",
395
+ action: "grants:read",
396
+ query: [
397
+ {
398
+ name: "subject",
399
+ type: "string",
400
+ description: "One subject's grants."
401
+ },
402
+ {
403
+ name: "permission",
404
+ type: "string",
405
+ description: "One permission's grants."
406
+ },
407
+ {
408
+ name: "includeExpired",
409
+ type: "string",
410
+ description: "`true` to include expired."
411
+ }
412
+ ],
413
+ resource: (c) => ({
414
+ type: "grant",
415
+ ...c.query.get("subject") ? { subject: c.query.get("subject") } : {},
416
+ ...c.query.get("permission") ? { permission: c.query.get("permission") } : {}
417
+ }),
418
+ response: {
419
+ status: 200,
420
+ schema: "GrantList",
421
+ description: "Grants"
422
+ },
423
+ async handle(c) {
424
+ const subject = c.query.get("subject") || void 0;
425
+ const permission = c.query.get("permission") || void 0;
426
+ return (0, _xtandard_kit_server.json)({ grants: await c.ctx.engine.list({
427
+ ...subject !== void 0 ? { subject } : {},
428
+ ...permission !== void 0 ? { permission } : {},
429
+ ...truthy(c.query.get("includeExpired")) ? { includeExpired: true } : {}
430
+ }) });
431
+ }
432
+ },
433
+ {
434
+ method: "POST",
435
+ path: "/api/grants",
436
+ operationId: "grant",
437
+ summary: "Grant a permission (idempotent: 201 when created, 200 when it already existed)",
438
+ tag: "grants",
439
+ action: "grants:write",
440
+ async resource(c) {
441
+ const { subject, permission } = await c.body(grantBodySchema);
442
+ return {
443
+ type: "grant",
444
+ subject,
445
+ permission
446
+ };
447
+ },
448
+ body: "GrantInput",
449
+ response: {
450
+ status: 201,
451
+ schema: "GrantResult",
452
+ description: "Granted"
453
+ },
454
+ async handle(c) {
455
+ const body = await c.body(grantBodySchema);
456
+ const result = await c.ctx.engine.grant({
457
+ ...body,
458
+ actor: actorOf(c)
459
+ });
460
+ return (0, _xtandard_kit_server.json)(result, result.created ? 201 : 200);
461
+ }
462
+ },
463
+ {
464
+ method: "DELETE",
465
+ path: "/api/grants/:subject/:permission",
466
+ operationId: "revoke",
467
+ summary: "Revoke a permission (idempotent: `removed: false` when absent)",
468
+ description: "The reason is read from the JSON body `{ reason }` or the `?reason=` query.",
469
+ tag: "grants",
470
+ action: "grants:write",
471
+ query: [{
472
+ name: "reason",
473
+ type: "string",
474
+ description: "Why (when there is no body)."
475
+ }],
476
+ resource: (c) => ({
477
+ type: "grant",
478
+ subject: c.params.subject,
479
+ permission: c.params.permission
480
+ }),
481
+ body: "RevokeInput",
482
+ bodyRequired: false,
483
+ response: {
484
+ status: 200,
485
+ schema: "RevokeResult",
486
+ description: "Revoked (or nothing to do)"
487
+ },
488
+ async handle(c) {
489
+ const reason = (await c.body(revokeBodySchema)).reason ?? (c.query.get("reason") || void 0);
490
+ return (0, _xtandard_kit_server.json)(await c.ctx.engine.revoke({
491
+ subject: c.params.subject,
492
+ permission: c.params.permission,
493
+ actor: actorOf(c),
494
+ ...reason !== void 0 ? { reason } : {}
495
+ }));
496
+ }
497
+ },
498
+ {
499
+ method: "GET",
500
+ path: "/api/history",
501
+ operationId: "history",
502
+ summary: "Grant / revoke / role history, newest first (cursor pagination)",
503
+ tag: "history",
504
+ action: "history:read",
505
+ query: [
506
+ {
507
+ name: "subject",
508
+ type: "string",
509
+ description: "One subject's history."
510
+ },
511
+ {
512
+ name: "limit",
513
+ type: "integer",
514
+ description: "Page size, 1–1000 (default 50)."
515
+ },
516
+ {
517
+ name: "cursor",
518
+ type: "string",
519
+ description: "The previous page's `nextCursor`."
520
+ }
521
+ ],
522
+ resource: (c) => ({
523
+ type: "history",
524
+ ...c.query.get("subject") ? { subject: c.query.get("subject") } : {}
525
+ }),
526
+ response: {
527
+ status: 200,
528
+ schema: "HistoryPage",
529
+ description: "A page of history"
530
+ },
531
+ async handle(c) {
532
+ const subject = c.query.get("subject") || void 0;
533
+ const cursor = c.query.get("cursor") || void 0;
534
+ const limit = (0, _xtandard_kit_server.intParam)(c.query.get("limit"), { name: "limit" });
535
+ return (0, _xtandard_kit_server.json)(await c.ctx.engine.history({
536
+ ...subject !== void 0 ? { subject } : {},
537
+ ...limit !== void 0 ? { limit } : {},
538
+ ...cursor !== void 0 ? { cursor } : {}
539
+ }));
540
+ }
541
+ },
542
+ {
543
+ method: "POST",
544
+ path: "/api/check",
545
+ operationId: "check",
546
+ summary: "Check playground: decide a path for a subject, a role, or a guest, with reasons",
547
+ description: "`subject` checks a stored subject (its stored role and grants). `role` alone checks the role with no subject and no grants (`subject: null` in the result). Both: `role` is the provider's role (a stored role still wins). Neither: a guest. A denial is `200` with `allowed: false`.",
548
+ tag: "check",
549
+ action: "check:run",
550
+ async resource(c) {
551
+ const body = await c.body(checkBodySchema);
552
+ return {
553
+ type: "check",
554
+ subject: body.subject ?? null,
555
+ ...body.role !== void 0 ? { role: body.role } : {},
556
+ path: body.path
557
+ };
558
+ },
559
+ body: "CheckInput",
560
+ response: {
561
+ status: 200,
562
+ schema: "CheckResult",
563
+ description: "The decision"
564
+ },
565
+ async handle(c) {
566
+ const body = await c.body(checkBodySchema);
567
+ const { engine } = c.ctx;
568
+ const catalog = engine.catalog;
569
+ if (body.role !== void 0 && !catalog.isRole(body.role)) throw new require_errors.UnknownRoleError(body.role);
570
+ let subject = null;
571
+ let preview = false;
572
+ if (body.subject) subject = {
573
+ id: body.subject,
574
+ ...body.role !== void 0 ? { role: body.role } : {}
575
+ };
576
+ else if (body.role !== void 0 && body.role !== catalog.guestRole) {
577
+ subject = {
578
+ id: ROLE_PREVIEW_ID,
579
+ role: body.role
580
+ };
581
+ preview = true;
582
+ }
583
+ const facts = body.ctx !== void 0 ? [{ ctx: body.ctx }] : [];
584
+ const result = await (await engine.ability(subject, ...facts)).checkAsync(body.path, body.data);
585
+ return (0, _xtandard_kit_server.json)(serializeCheck(preview ? {
586
+ ...result,
587
+ subject: null
588
+ } : result));
589
+ }
590
+ },
591
+ {
592
+ method: "GET",
593
+ path: "/api/relationships",
594
+ operationId: "readRelationships",
595
+ summary: "Stored relationships by object (or type), relation and/or subject (paginated)",
596
+ tag: "relationships",
597
+ action: "relationships:read",
598
+ query: [
599
+ {
600
+ name: "object",
601
+ type: "string",
602
+ description: "`type:id`, or a bare `type`."
603
+ },
604
+ {
605
+ name: "relation",
606
+ type: "string",
607
+ description: "One relation."
608
+ },
609
+ {
610
+ name: "subject",
611
+ type: "string",
612
+ description: "Exactly this subject reference."
613
+ },
614
+ {
615
+ name: "limit",
616
+ type: "integer",
617
+ description: "Page size, 1–1000 (default 100)."
618
+ },
619
+ {
620
+ name: "cursor",
621
+ type: "string",
622
+ description: "The previous page's `nextCursor`."
623
+ }
624
+ ],
625
+ resource: (c) => ({
626
+ type: "relationship",
627
+ ...queryOf(c, "object") ? { object: queryOf(c, "object") } : {},
628
+ ...queryOf(c, "relation") ? { relation: queryOf(c, "relation") } : {},
629
+ ...queryOf(c, "subject") ? { subject: queryOf(c, "subject") } : {}
630
+ }),
631
+ response: {
632
+ status: 200,
633
+ schema: "RelationshipPage",
634
+ description: "A page of relationships"
635
+ },
636
+ async handle(c) {
637
+ const limit = (0, _xtandard_kit_server.intParam)(c.query.get("limit"), { name: "limit" });
638
+ const query = {};
639
+ for (const name of [
640
+ "object",
641
+ "relation",
642
+ "subject",
643
+ "cursor"
644
+ ]) {
645
+ const value = queryOf(c, name);
646
+ if (value !== void 0) query[name] = value;
647
+ }
648
+ if (limit !== void 0) query.limit = limit;
649
+ return (0, _xtandard_kit_server.json)(await c.ctx.engine.readRelationships(query));
650
+ }
651
+ },
652
+ {
653
+ method: "POST",
654
+ path: "/api/relationships",
655
+ operationId: "writeRelationship",
656
+ summary: "Write a relationship (idempotent: 201 when created, 200 when it already existed)",
657
+ description: "Validated against the catalog's relation schema (400 `INVALID_RELATION` when the schema doesn't allow the subject on that relation).",
658
+ tag: "relationships",
659
+ action: "relationships:write",
660
+ async resource(c) {
661
+ const { object, relation, subject } = await c.body(relationshipBodySchema);
662
+ return {
663
+ type: "relationship",
664
+ object,
665
+ relation,
666
+ subject
667
+ };
668
+ },
669
+ body: "RelationshipInput",
670
+ response: {
671
+ status: 201,
672
+ schema: "WriteRelationshipResult",
673
+ description: "Written"
674
+ },
675
+ async handle(c) {
676
+ const body = await c.body(relationshipBodySchema);
677
+ const result = await c.ctx.engine.writeRelationship({
678
+ ...body,
679
+ actor: actorOf(c)
680
+ });
681
+ return (0, _xtandard_kit_server.json)(result, result.created ? 201 : 200);
682
+ }
683
+ },
684
+ {
685
+ method: "DELETE",
686
+ path: "/api/relationships",
687
+ operationId: "deleteRelationship",
688
+ summary: "Delete a relationship (idempotent: `removed: false` when absent)",
689
+ description: "The tuple comes from the JSON body `{ object, relation, subject, reason? }` or the `?object=&relation=&subject=&reason=` query.",
690
+ tag: "relationships",
691
+ action: "relationships:write",
692
+ query: [
693
+ {
694
+ name: "object",
695
+ type: "string",
696
+ description: "When there is no body."
697
+ },
698
+ {
699
+ name: "relation",
700
+ type: "string",
701
+ description: "When there is no body."
702
+ },
703
+ {
704
+ name: "subject",
705
+ type: "string",
706
+ description: "When there is no body."
707
+ },
708
+ {
709
+ name: "reason",
710
+ type: "string",
711
+ description: "When there is no body."
712
+ }
713
+ ],
714
+ async resource(c) {
715
+ const { object, relation, subject } = await relationshipOf(c);
716
+ return {
717
+ type: "relationship",
718
+ object,
719
+ relation,
720
+ subject
721
+ };
722
+ },
723
+ body: "RelationshipInput",
724
+ bodyRequired: false,
725
+ response: {
726
+ status: 200,
727
+ schema: "DeleteRelationshipResult",
728
+ description: "Deleted (or nothing to do)"
729
+ },
730
+ async handle(c) {
731
+ const tuple = await relationshipOf(c);
732
+ return (0, _xtandard_kit_server.json)(await c.ctx.engine.deleteRelationship({
733
+ ...tuple,
734
+ actor: actorOf(c)
735
+ }));
736
+ }
737
+ },
738
+ {
739
+ method: "POST",
740
+ path: "/api/relationships/check",
741
+ operationId: "checkRelation",
742
+ summary: "Does a subject have a relation on an object? With the path of relations that decided it",
743
+ description: "A denial is `200` with `allowed: false` and an empty `path`.",
744
+ tag: "relationships",
745
+ action: "relationships:read",
746
+ async resource(c) {
747
+ const { object, relation, subject } = await c.body(relationCheckBodySchema);
748
+ return {
749
+ type: "relationship",
750
+ object,
751
+ relation,
752
+ subject
753
+ };
754
+ },
755
+ body: "RelationCheckInput",
756
+ response: {
757
+ status: 200,
758
+ schema: "RelationCheckResult",
759
+ description: "The decision"
760
+ },
761
+ async handle(c) {
762
+ return (0, _xtandard_kit_server.json)(await c.ctx.engine.checkRelation(await c.body(relationCheckBodySchema)));
763
+ }
764
+ },
765
+ {
766
+ method: "GET",
767
+ path: "/api/relationships/objects",
768
+ operationId: "listObjects",
769
+ summary: "The objects of a type on which a subject has a relation",
770
+ description: "A walk backwards over the reverse index, bounded by `maxDepth`; fine for app-scale data (see docs/REBAC.md).",
771
+ tag: "relationships",
772
+ action: "relationships:read",
773
+ query: [
774
+ {
775
+ name: "subject",
776
+ type: "string",
777
+ description: "`user:ana`, `group:eng#member`.",
778
+ required: true
779
+ },
780
+ {
781
+ name: "relation",
782
+ type: "string",
783
+ description: "A relation of `type`.",
784
+ required: true
785
+ },
786
+ {
787
+ name: "type",
788
+ type: "string",
789
+ description: "The object type.",
790
+ required: true
791
+ }
792
+ ],
793
+ resource: (c) => ({
794
+ type: "relationship",
795
+ ...queryOf(c, "subject") ? { subject: queryOf(c, "subject") } : {},
796
+ ...queryOf(c, "relation") ? { relation: queryOf(c, "relation") } : {}
797
+ }),
798
+ response: {
799
+ status: 200,
800
+ schema: "ObjectList",
801
+ description: "Objects, sorted"
802
+ },
803
+ async handle(c) {
804
+ return (0, _xtandard_kit_server.json)({ objects: await c.ctx.engine.listObjects({
805
+ subject: c.query.get("subject") ?? "",
806
+ relation: c.query.get("relation") ?? "",
807
+ type: c.query.get("type") ?? ""
808
+ }) });
809
+ }
810
+ },
811
+ {
812
+ method: "GET",
813
+ path: "/api/relationships/subjects",
814
+ operationId: "listRelationSubjects",
815
+ summary: "The subjects that have a relation on an object (usersets expanded)",
816
+ tag: "relationships",
817
+ action: "relationships:read",
818
+ query: [
819
+ {
820
+ name: "object",
821
+ type: "string",
822
+ description: "`type:id`.",
823
+ required: true
824
+ },
825
+ {
826
+ name: "relation",
827
+ type: "string",
828
+ description: "A relation of the object's type.",
829
+ required: true
830
+ },
831
+ {
832
+ name: "type",
833
+ type: "string",
834
+ description: "Only subjects of this type."
835
+ }
836
+ ],
837
+ resource: (c) => ({
838
+ type: "relationship",
839
+ ...queryOf(c, "object") ? { object: queryOf(c, "object") } : {},
840
+ ...queryOf(c, "relation") ? { relation: queryOf(c, "relation") } : {}
841
+ }),
842
+ response: {
843
+ status: 200,
844
+ schema: "SubjectRefList",
845
+ description: "Subjects, sorted"
846
+ },
847
+ async handle(c) {
848
+ const type = queryOf(c, "type");
849
+ return (0, _xtandard_kit_server.json)({ subjects: await c.ctx.engine.listRelationSubjects({
850
+ object: c.query.get("object") ?? "",
851
+ relation: c.query.get("relation") ?? "",
852
+ ...type !== void 0 ? { type } : {}
853
+ }) });
854
+ }
855
+ },
856
+ {
857
+ method: "GET",
858
+ path: "/api/me",
859
+ operationId: "me",
860
+ summary: "The caller's snapshot: id, effective role and active permissions (ADR 0009)",
861
+ tag: "runtime",
862
+ authenticate: true,
863
+ runtime: true,
864
+ response: {
865
+ status: 200,
866
+ schema: "PermissionsSnapshot",
867
+ description: "Snapshot"
868
+ },
869
+ async handle(c) {
870
+ if (!c.principal) return NO_PRINCIPAL();
871
+ return (0, _xtandard_kit_server.json)(await c.ctx.engine.snapshot(callerOf(c.principal)));
872
+ }
873
+ },
874
+ {
875
+ method: "POST",
876
+ path: "/api/me/check",
877
+ operationId: "meCheck",
878
+ summary: "Decide a path for the caller, with reasons",
879
+ description: "Advisory (for UI gating): `data` comes from the caller. Enforce on the server with the engine. The rules' `ctx` comes from the server's `checkContext` option, never from the body.",
880
+ tag: "runtime",
881
+ authenticate: true,
882
+ runtime: true,
883
+ body: "MeCheckInput",
884
+ response: {
885
+ status: 200,
886
+ schema: "CheckResult",
887
+ description: "The decision"
888
+ },
889
+ async handle(c) {
890
+ if (!c.principal) return NO_PRINCIPAL();
891
+ const body = await c.body(meCheckBodySchema);
892
+ const subject = callerOf(c.principal);
893
+ const facts = c.ctx.checkContext ? [{ ctx: await c.ctx.checkContext(c.request, subject) }] : [];
894
+ return (0, _xtandard_kit_server.json)(serializeCheck(await (await c.ctx.engine.ability(subject, ...facts)).checkAsync(body.path, body.data)));
895
+ }
896
+ },
897
+ {
898
+ method: "POST",
899
+ path: "/api/me/relation",
900
+ operationId: "meRelation",
901
+ summary: "Does the caller have a relation on an object? (ReBAC, with the path)",
902
+ description: "The caller is the subject `user:{id}` unless the server's `relationSubject` option maps it. Advisory for UI gating; enforce on the server.",
903
+ tag: "runtime",
904
+ authenticate: true,
905
+ runtime: true,
906
+ body: "MeRelationInput",
907
+ response: {
908
+ status: 200,
909
+ schema: "RelationCheckResult",
910
+ description: "The decision"
911
+ },
912
+ async handle(c) {
913
+ if (!c.principal) return NO_PRINCIPAL();
914
+ const body = await c.body(meRelationBodySchema);
915
+ return (0, _xtandard_kit_server.json)(await c.ctx.engine.checkRelation({
916
+ subject: relationSubjectOf(c, c.principal),
917
+ relation: body.relation,
918
+ object: body.object
919
+ }));
920
+ }
921
+ }
922
+ ];
923
+ /** The documented route table (every API route, in match order). */
924
+ const API_ROUTES = ROUTES;
925
+ /** The paths served as the bootstrap config (not in {@link API_ROUTES}). */
926
+ const CONFIG_PATHS = ["/config", "/api/config"];
927
+ const CONFIG_ROUTES = CONFIG_PATHS.map((path) => ({
928
+ method: "GET",
929
+ path,
930
+ operationId: path === "/config" ? "getConfig" : "getApiConfig",
931
+ summary: "SPA bootstrap config: title, readonly, the caller and the actions it may perform",
932
+ tag: "panel",
933
+ authenticate: true,
934
+ hidden: true,
935
+ response: {
936
+ status: 200,
937
+ schema: "PanelConfig",
938
+ description: "Panel config"
939
+ },
940
+ handle: async (c) => (0, _xtandard_kit_server.json)(await panelConfig(c))
941
+ }));
942
+ /** Domain errors by name (ADR 0008); see `@xtandard/kit/server` `mapError`. */
943
+ const ERRORS = {
944
+ NoSubjectError: {
945
+ status: 401,
946
+ code: "NO_SUBJECT"
947
+ },
948
+ ForbiddenError: {
949
+ status: 403,
950
+ code: "FORBIDDEN"
951
+ },
952
+ UnknownPermissionError: {
953
+ status: 400,
954
+ code: "UNKNOWN_PERMISSION"
955
+ },
956
+ UnknownRoleError: {
957
+ status: 400,
958
+ code: "UNKNOWN_ROLE"
959
+ },
960
+ NotFoundError: {
961
+ status: 404,
962
+ code: "NOT_FOUND"
963
+ },
964
+ ReadonlyError: {
965
+ status: 423,
966
+ code: "READONLY"
967
+ },
968
+ AsyncRuleError: {
969
+ status: 500,
970
+ code: "ASYNC_RULE"
971
+ },
972
+ RelationSchemaError: {
973
+ status: 400,
974
+ code: "INVALID_RELATION"
975
+ },
976
+ RelationDepthError: {
977
+ status: 422,
978
+ code: "RELATION_DEPTH"
979
+ }
980
+ };
981
+ /** Build the API router for one panel. */
982
+ function createApiRouter(ctx) {
983
+ return (0, _xtandard_kit_server_router.createRouter)({
984
+ routes: [...CONFIG_ROUTES, ...ROUTES],
985
+ context: ctx,
986
+ readonly: ctx.readonly,
987
+ isMutatingAction: require_contract.isMutatingAction,
988
+ readonlyStatus: 423,
989
+ readonlyMessage: (route) => `Cannot ${route.operationId}: @xtandard/permissions is in readonly mode.`,
990
+ auth: ctx.auth,
991
+ authorization: ctx.authorization,
992
+ errors: ERRORS
993
+ });
994
+ }
995
+ /** Map domain errors to HTTP responses (ADR 0008), by name across bundles. */
996
+ function mapError(err) {
997
+ return (0, _xtandard_kit_server.mapError)(err, ERRORS);
998
+ }
999
+ //#endregion
1000
+ Object.defineProperty(exports, "API_ROUTES", {
1001
+ enumerable: true,
1002
+ get: function() {
1003
+ return API_ROUTES;
1004
+ }
1005
+ });
1006
+ Object.defineProperty(exports, "CONFIG_PATHS", {
1007
+ enumerable: true,
1008
+ get: function() {
1009
+ return CONFIG_PATHS;
1010
+ }
1011
+ });
1012
+ Object.defineProperty(exports, "catalogPaths", {
1013
+ enumerable: true,
1014
+ get: function() {
1015
+ return catalogPaths;
1016
+ }
1017
+ });
1018
+ Object.defineProperty(exports, "catalogView", {
1019
+ enumerable: true,
1020
+ get: function() {
1021
+ return catalogView;
1022
+ }
1023
+ });
1024
+ Object.defineProperty(exports, "createApiRouter", {
1025
+ enumerable: true,
1026
+ get: function() {
1027
+ return createApiRouter;
1028
+ }
1029
+ });
1030
+ Object.defineProperty(exports, "mapError", {
1031
+ enumerable: true,
1032
+ get: function() {
1033
+ return mapError;
1034
+ }
1035
+ });
1036
+ Object.defineProperty(exports, "routes_exports", {
1037
+ enumerable: true,
1038
+ get: function() {
1039
+ return routes_exports;
1040
+ }
1041
+ });
1042
+ Object.defineProperty(exports, "serializeCheck", {
1043
+ enumerable: true,
1044
+ get: function() {
1045
+ return serializeCheck;
1046
+ }
1047
+ });
1048
+
1049
+ //# sourceMappingURL=routes-irNuuZqo.cjs.map