@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,667 @@
1
+ const require_chunk = require("./chunk-DakpK96I.cjs");
2
+ const require_relationships = require("./relationships-BLYEJ9tc.cjs");
3
+ const require_errors = require("./errors-CjpymzFj.cjs");
4
+ let _xtandard_kit_util_core = require("@xtandard/kit/util/core");
5
+ let _xtandard_kit_util = require("@xtandard/kit/util");
6
+ let _xtandard_kit_hooks = require("@xtandard/kit/hooks");
7
+ let _xtandard_kit_storage = require("@xtandard/kit/storage");
8
+ //#region src/engine.ts
9
+ /**
10
+ * The engine: `createPermissions({ catalog, storage, hooks, cache, now, readonly })`.
11
+ *
12
+ * Writes (grant, revoke, role assignment, subject records) go to the storage
13
+ * under the `perm/` key root (ADR 0003) and fire the hooks. Checks load the
14
+ * subject's stored role and grants (async, cached per subject), resolve the
15
+ * effective role from the `roleSource` (ADR 0014), then evaluate
16
+ * the catalog's rules **synchronously** with `@xtandard/lib/policy/permix`
17
+ * (ADR 0005).
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { createPermissions } from "@xtandard/permissions";
22
+ * import { createMemoryStorage } from "@xtandard/permissions/storage/memory";
23
+ * import { permissions } from "./permissions.ts"; // definePermissions(...)
24
+ *
25
+ * const perms = createPermissions({ catalog: permissions, storage: createMemoryStorage() });
26
+ * await perms.grant({ subject: "user_1", permission: "post:moderate", actor: "admin_1" });
27
+ * await perms.can({ id: "user_1", role: "member" }, "post.publish", post); // true
28
+ * ```
29
+ *
30
+ * @module
31
+ */
32
+ var engine_exports = /* @__PURE__ */ require_chunk.__exportAll({ createPermissions: () => createPermissions });
33
+ const DEFAULT_HISTORY_LIMIT = 50;
34
+ const CAS_ATTEMPTS = 8;
35
+ const isNonEmptyString = (value) => typeof value === "string" && value.length > 0;
36
+ function requireSubjectId(value) {
37
+ if (!isNonEmptyString(value)) throw new require_errors.NoSubjectError();
38
+ return value;
39
+ }
40
+ function toActor(actor) {
41
+ if (actor === void 0 || actor === null) return null;
42
+ return typeof actor === "string" ? { id: actor } : actor;
43
+ }
44
+ function toIso(at) {
45
+ const ms = typeof at === "number" ? at : typeof at === "string" ? Date.parse(at) : at.getTime();
46
+ return new Date(ms).toISOString();
47
+ }
48
+ /** Last segment of a history key, decoded: the `{at}-{id}` sort token. */
49
+ function historyToken(key) {
50
+ const segment = key.slice(key.lastIndexOf("/") + 1);
51
+ try {
52
+ return `${decodeURIComponent(segment)}\u0000${key}`;
53
+ } catch {
54
+ return `\u0000${key}`;
55
+ }
56
+ }
57
+ /**
58
+ * Create the engine.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const perms = createPermissions({ catalog, storage, cache: { ttlMs: 5_000 } });
63
+ * const decision = await perms.check({ id: "u1", role: "member" }, "post.publish", post);
64
+ * // { allowed, path, subject, role, reason: "role-rule" | "denied-by-rule" | …, explanation }
65
+ * ```
66
+ */
67
+ function createPermissions(options) {
68
+ const { catalog, storage } = options;
69
+ const now = options.now ?? Date.now;
70
+ const readonly = options.readonly ?? false;
71
+ const hooks = (0, _xtandard_kit_hooks.normalizeHooks)(options.hooks);
72
+ const onHookError = options.onHookError ?? require_relationships.defaultHookErrorReporter;
73
+ const logger = options.logger ?? { warn: (message, error) => console.warn(`[@xtandard/permissions] ${message}`, ...error === void 0 ? [] : [error]) };
74
+ const cacheEnabled = options.cache !== false;
75
+ const cacheTtl = (options.cache ? options.cache.ttlMs : void 0) ?? 5e3;
76
+ const cacheMax = (options.cache ? options.cache.max : void 0) ?? 1e4;
77
+ const roleSource = options.roleSource ?? "stored";
78
+ if (roleSource !== "stored" && roleSource !== "external") throw new TypeError(`createPermissions: roleSource must be "stored" or "external"`);
79
+ const lookupSubject = options.lookupSubject;
80
+ const ids = (0, _xtandard_kit_util_core.createIdGenerator)({ format: "ulid-lower22" });
81
+ const nowIso = () => new Date(now()).toISOString();
82
+ const active = (grant) => grant.expiresAt === void 0 || grant.expiresAt === null || Date.parse(grant.expiresAt) > now();
83
+ const assertWritable = (operation) => {
84
+ if (readonly) throw new require_errors.ReadonlyError(operation);
85
+ };
86
+ const requirePermission = (permission) => {
87
+ if (!catalog.isAssignable(permission)) throw new require_errors.UnknownPermissionError(permission);
88
+ return permission;
89
+ };
90
+ const locks = /* @__PURE__ */ new Map();
91
+ async function withLock(key, fn) {
92
+ const prev = locks.get(key) ?? Promise.resolve();
93
+ let release;
94
+ const mine = new Promise((resolve) => release = resolve);
95
+ const chained = prev.then(() => mine);
96
+ locks.set(key, chained);
97
+ await prev.catch(() => {});
98
+ try {
99
+ return await fn();
100
+ } finally {
101
+ release();
102
+ if (locks.get(key) === chained) locks.delete(key);
103
+ }
104
+ }
105
+ /** Write `next` if the key still holds `expected` (CAS), or unconditionally without CAS. */
106
+ async function swap(key, expected, next) {
107
+ if ((0, _xtandard_kit_storage.isCompareAndSwap)(storage)) return storage.compareAndSwap({
108
+ key,
109
+ expected,
110
+ next
111
+ });
112
+ await storage.setItem(key, next);
113
+ return true;
114
+ }
115
+ const cache = /* @__PURE__ */ new Map();
116
+ /** `lookupSubject` results: same TTL, size bound and invalidation as {@link cache}. */
117
+ const lookups = /* @__PURE__ */ new Map();
118
+ const generations = /* @__PURE__ */ new Map();
119
+ const inflight = /* @__PURE__ */ new Map();
120
+ let unwatch = null;
121
+ let watching = null;
122
+ const invalidate = (subject) => {
123
+ if (subject === void 0) {
124
+ cache.clear();
125
+ lookups.clear();
126
+ inflight.clear();
127
+ for (const key of generations.keys()) generations.set(key, (generations.get(key) ?? 0) + 1);
128
+ return;
129
+ }
130
+ cache.delete(subject);
131
+ lookups.delete(subject);
132
+ inflight.delete(subject);
133
+ generations.set(subject, (generations.get(subject) ?? 0) + 1);
134
+ };
135
+ const ensureWatch = () => {
136
+ if (watching || !cacheEnabled || !(0, _xtandard_kit_storage.isWatchable)(storage)) return;
137
+ watching = storage.watch(`${require_relationships.ROOT}/`, (event) => {
138
+ const parsed = require_relationships.parseKey(event.key);
139
+ if (parsed && parsed.area !== "history") invalidate(parsed.subject);
140
+ }).then((off) => {
141
+ unwatch = off;
142
+ }).catch((error) => logger.warn("storage watch failed; relying on the cache TTL", error));
143
+ };
144
+ async function readSubject(subject) {
145
+ const [record, keys] = await Promise.all([storage.getItem(require_relationships.subjectKey(subject)), storage.getKeys(require_relationships.subjectGrantsPrefix(subject))]);
146
+ const grants = (await Promise.all(keys.map((key) => storage.getItem(key)))).filter((grant) => grant !== null && typeof grant === "object");
147
+ return {
148
+ record: record ?? null,
149
+ grants
150
+ };
151
+ }
152
+ function load(subject) {
153
+ if (!cacheEnabled) return readSubject(subject).then((e) => ({
154
+ ...e,
155
+ loadedAt: now()
156
+ }));
157
+ ensureWatch();
158
+ const cached = cache.get(subject);
159
+ if (cached && now() - cached.loadedAt < cacheTtl) return Promise.resolve(cached);
160
+ const pending = inflight.get(subject);
161
+ if (pending) return pending;
162
+ const generation = generations.get(subject) ?? 0;
163
+ const promise = readSubject(subject).then((data) => {
164
+ const entry = {
165
+ ...data,
166
+ loadedAt: now()
167
+ };
168
+ if ((generations.get(subject) ?? 0) === generation) {
169
+ cache.delete(subject);
170
+ cache.set(subject, entry);
171
+ while (cache.size > cacheMax) cache.delete(cache.keys().next().value);
172
+ }
173
+ return entry;
174
+ }).finally(() => {
175
+ if (inflight.get(subject) === promise) inflight.delete(subject);
176
+ });
177
+ inflight.set(subject, promise);
178
+ return promise;
179
+ }
180
+ async function appendHistory(entry, at) {
181
+ const id = ids.newId("hst", Date.parse(at));
182
+ const full = {
183
+ id,
184
+ at,
185
+ ...entry
186
+ };
187
+ await storage.setItem(require_relationships.historyKey(entry.subject, at, id), full);
188
+ }
189
+ const storedRole = (record) => record?.role !== void 0 && catalog.isRole(record.role) && record.role !== catalog.guestRole ? record.role : null;
190
+ /** The provider's identity of `id` from `lookupSubject` (cached; `null` without one). */
191
+ function lookup(id) {
192
+ if (!lookupSubject) return Promise.resolve(null);
193
+ const cached = cacheEnabled ? lookups.get(id) : void 0;
194
+ if (cached && now() - cached.at < cacheTtl) return cached.identity;
195
+ const identity = Promise.resolve().then(() => lookupSubject(id)).then((found) => found && typeof found === "object" ? found : null);
196
+ if (cacheEnabled) {
197
+ lookups.delete(id);
198
+ lookups.set(id, {
199
+ identity,
200
+ at: now()
201
+ });
202
+ while (lookups.size > cacheMax) lookups.delete(lookups.keys().next().value);
203
+ identity.catch(() => {
204
+ if (lookups.get(id)?.identity === identity) lookups.delete(id);
205
+ });
206
+ }
207
+ return identity;
208
+ }
209
+ /** True when a raw provider role names a known, non-guest role (else `defaultRole` applies). */
210
+ const knownRole = (raw) => {
211
+ return (typeof raw === "string" ? raw.split(",").map((s) => s.trim()) : Array.isArray(raw) ? raw : []).some((c) => catalog.isRole(c) && c !== catalog.guestRole);
212
+ };
213
+ /**
214
+ * The effective role (ADR 0014). `external`: the provider's role (passed with the identity, else
215
+ * looked up), else `defaultRole`. `stored`: the stored role, else the same. The lookup runs only
216
+ * when the identity carries no `role` (`null` means "the provider says none": no lookup).
217
+ */
218
+ async function decideRole(id, record, identity, lookupFailed) {
219
+ if (roleSource === "stored") {
220
+ const stored = storedRole(record);
221
+ if (stored !== null) return {
222
+ role: stored,
223
+ source: "stored",
224
+ looked: null
225
+ };
226
+ }
227
+ let looked = null;
228
+ let raw = identity?.role;
229
+ if (raw === void 0) {
230
+ looked = lookupFailed ? await lookup(id).catch(lookupFailed) : await lookup(id);
231
+ raw = looked?.role;
232
+ }
233
+ return knownRole(raw) ? {
234
+ role: catalog.effectiveRole(raw),
235
+ source: "provider",
236
+ looked
237
+ } : {
238
+ role: catalog.defaultRole,
239
+ source: "default",
240
+ looked
241
+ };
242
+ }
243
+ async function resolve(input) {
244
+ if (input === null || input === void 0) return {
245
+ id: null,
246
+ role: catalog.guestRole,
247
+ roleSource: void 0,
248
+ user: void 0,
249
+ grants: []
250
+ };
251
+ const identity = typeof input === "string" ? { id: input } : input;
252
+ const id = requireSubjectId(identity.id);
253
+ const entry = await load(id);
254
+ const { role, source, looked } = await decideRole(id, entry.record, identity);
255
+ const name = identity.name ?? entry.record?.name ?? looked?.name;
256
+ const email = identity.email ?? entry.record?.email ?? looked?.email;
257
+ const attributes = identity.attributes ?? looked?.attributes;
258
+ return {
259
+ id,
260
+ role,
261
+ roleSource: source,
262
+ user: {
263
+ id,
264
+ role,
265
+ ...name !== void 0 ? { name } : {},
266
+ ...email !== void 0 ? { email } : {},
267
+ ...attributes !== void 0 ? { attributes } : {}
268
+ },
269
+ grants: entry.grants.filter(active)
270
+ };
271
+ }
272
+ async function buildAbility(input, facts) {
273
+ const resolved = await resolve(input);
274
+ const createAbility = catalog.authorization.createAbility;
275
+ const ability = createAbility(resolved.user, {
276
+ permissions: resolved.grants.map((grant) => grant.permission),
277
+ ...facts && "ctx" in facts ? { ctx: facts.ctx } : {}
278
+ });
279
+ const decide = (path, explanation) => {
280
+ const base = {
281
+ path,
282
+ subject: resolved.id,
283
+ role: ability.role,
284
+ ...resolved.roleSource !== void 0 ? { roleSource: resolved.roleSource } : {},
285
+ explanation
286
+ };
287
+ if (catalog.directGrants && resolved.id !== null && ability.permissions.has(path)) return {
288
+ ...base,
289
+ allowed: true,
290
+ reason: "grant"
291
+ };
292
+ if (explanation.type === "allowed") return {
293
+ ...base,
294
+ allowed: true,
295
+ reason: "role-rule"
296
+ };
297
+ if (explanation.type === "unknown_path") return {
298
+ ...base,
299
+ allowed: false,
300
+ reason: "unknown-path"
301
+ };
302
+ return {
303
+ ...base,
304
+ allowed: false,
305
+ reason: explanation.decidedBy === "threw" ? "rule-threw" : "denied-by-rule"
306
+ };
307
+ };
308
+ const check = (path, data) => decide(path, ability.explain({
309
+ path,
310
+ data
311
+ }));
312
+ const checkAsync = async (path, data) => decide(path, await ability.explainAsync({
313
+ path,
314
+ data
315
+ }));
316
+ return {
317
+ ...ability,
318
+ subject: resolved.id,
319
+ grants: resolved.grants,
320
+ check,
321
+ checkAsync
322
+ };
323
+ }
324
+ async function grant(input) {
325
+ assertWritable("grant");
326
+ const subject = requireSubjectId(input?.subject);
327
+ const permission = requirePermission(input.permission);
328
+ const parsed = (0, _xtandard_kit_util.parseInput)(require_relationships.grantInputSchema, input);
329
+ const actor = toActor(parsed.actor);
330
+ const expiresAt = parsed.expiresAt === void 0 || parsed.expiresAt === null ? null : toIso(parsed.expiresAt);
331
+ if (expiresAt !== null && Date.parse(expiresAt) <= now()) throw new _xtandard_kit_util.ValidationError([{
332
+ path: "expiresAt",
333
+ message: "must be in the future"
334
+ }]);
335
+ const key = require_relationships.grantKey(subject, permission);
336
+ return withLock(key, async () => {
337
+ for (let attempt = 0; attempt < CAS_ATTEMPTS; attempt++) {
338
+ const existing = await storage.getItem(key);
339
+ if (existing && active(existing)) return {
340
+ grant: existing,
341
+ created: false
342
+ };
343
+ const at = nowIso();
344
+ const next = {
345
+ subject,
346
+ permission,
347
+ grantedBy: actor?.id ?? null,
348
+ grantedAt: at,
349
+ ...parsed.reason !== void 0 ? { reason: parsed.reason } : {},
350
+ ...expiresAt !== null ? { expiresAt } : {}
351
+ };
352
+ await (0, _xtandard_kit_hooks.runBefore)(hooks, {
353
+ type: "grant.create",
354
+ subject,
355
+ grant: next,
356
+ actor
357
+ });
358
+ if (!await swap(key, existing ?? null, next)) continue;
359
+ invalidate(subject);
360
+ await appendHistory({
361
+ type: "grant",
362
+ subject,
363
+ permission,
364
+ actor: actor?.id ?? null,
365
+ ...parsed.reason !== void 0 ? { reason: parsed.reason } : {},
366
+ ...expiresAt !== null ? { expiresAt } : {}
367
+ }, at);
368
+ await (0, _xtandard_kit_hooks.runAfter)(hooks, {
369
+ type: "grant.created",
370
+ subject,
371
+ grant: next,
372
+ actor,
373
+ at
374
+ }, onHookError);
375
+ return {
376
+ grant: next,
377
+ created: true
378
+ };
379
+ }
380
+ throw new Error(`grant: storage kept changing "${key}"; giving up`);
381
+ });
382
+ }
383
+ async function revoke(input) {
384
+ assertWritable("revoke");
385
+ const subject = requireSubjectId(input?.subject);
386
+ const permission = requirePermission(input.permission);
387
+ const parsed = (0, _xtandard_kit_util.parseInput)(require_relationships.revokeInputSchema, input);
388
+ const actor = toActor(parsed.actor);
389
+ const key = require_relationships.grantKey(subject, permission);
390
+ return withLock(key, async () => {
391
+ const existing = await storage.getItem(key);
392
+ if (!existing) return {
393
+ removed: false,
394
+ grant: null
395
+ };
396
+ const reason = parsed.reason !== void 0 ? { reason: parsed.reason } : {};
397
+ await (0, _xtandard_kit_hooks.runBefore)(hooks, {
398
+ type: "grant.revoke",
399
+ subject,
400
+ grant: existing,
401
+ actor,
402
+ ...reason
403
+ });
404
+ await storage.removeItem(key);
405
+ invalidate(subject);
406
+ const at = nowIso();
407
+ await appendHistory({
408
+ type: "revoke",
409
+ subject,
410
+ permission,
411
+ actor: actor?.id ?? null,
412
+ ...reason
413
+ }, at);
414
+ await (0, _xtandard_kit_hooks.runAfter)(hooks, {
415
+ type: "grant.revoked",
416
+ subject,
417
+ grant: existing,
418
+ actor,
419
+ ...reason,
420
+ at
421
+ }, onHookError);
422
+ return {
423
+ removed: true,
424
+ grant: existing
425
+ };
426
+ });
427
+ }
428
+ async function setRole(input) {
429
+ if (roleSource === "external") throw new require_errors.ExternalRolesError();
430
+ assertWritable("set role");
431
+ const subject = requireSubjectId(input?.subject);
432
+ const role = input.role;
433
+ if (role !== null) {
434
+ if (!catalog.isRole(role)) throw new require_errors.UnknownRoleError(role);
435
+ if (role === catalog.guestRole) throw new require_errors.UnknownRoleError(role, `The guest role "${role}" can't be assigned to a subject.`);
436
+ }
437
+ const parsed = (0, _xtandard_kit_util.parseInput)(require_relationships.setRoleInputSchema, input);
438
+ const actor = toActor(parsed.actor);
439
+ const reason = parsed.reason !== void 0 ? { reason: parsed.reason } : {};
440
+ const key = require_relationships.subjectKey(subject);
441
+ return withLock(key, async () => {
442
+ for (let attempt = 0; attempt < CAS_ATTEMPTS; attempt++) {
443
+ const current = await storage.getItem(key);
444
+ const previous = current?.role ?? null;
445
+ if (previous === role) return {
446
+ record: current ?? null,
447
+ changed: false
448
+ };
449
+ const at = nowIso();
450
+ const { role: _old, ...rest } = current ?? { id: subject };
451
+ const next = {
452
+ ...rest,
453
+ id: subject,
454
+ ...role !== null ? { role } : {},
455
+ updatedAt: at
456
+ };
457
+ await (0, _xtandard_kit_hooks.runBefore)(hooks, {
458
+ type: "role.set",
459
+ subject,
460
+ role,
461
+ previous,
462
+ actor,
463
+ ...reason
464
+ });
465
+ if (!await swap(key, current ?? null, next)) continue;
466
+ invalidate(subject);
467
+ await appendHistory({
468
+ type: "role",
469
+ subject,
470
+ role,
471
+ previousRole: previous,
472
+ actor: actor?.id ?? null,
473
+ ...reason
474
+ }, at);
475
+ await (0, _xtandard_kit_hooks.runAfter)(hooks, {
476
+ type: "role.changed",
477
+ subject,
478
+ role,
479
+ previous,
480
+ record: next,
481
+ actor,
482
+ ...reason,
483
+ at
484
+ }, onHookError);
485
+ return {
486
+ record: next,
487
+ changed: true
488
+ };
489
+ }
490
+ throw new Error(`setRole: storage kept changing "${key}"; giving up`);
491
+ });
492
+ }
493
+ async function upsertSubject(input) {
494
+ assertWritable("update subject");
495
+ const subject = requireSubjectId(input?.id);
496
+ const parsed = (0, _xtandard_kit_util.parseInput)(require_relationships.upsertSubjectInputSchema, input);
497
+ const key = require_relationships.subjectKey(subject);
498
+ return withLock(key, async () => {
499
+ for (let attempt = 0; attempt < CAS_ATTEMPTS; attempt++) {
500
+ const current = await storage.getItem(key);
501
+ const next = {
502
+ ...current,
503
+ id: subject,
504
+ updatedAt: nowIso()
505
+ };
506
+ for (const field of ["name", "email"]) {
507
+ const value = parsed[field];
508
+ if (value === null) delete next[field];
509
+ else if (value !== void 0) next[field] = value;
510
+ }
511
+ if (!await swap(key, current ?? null, next)) continue;
512
+ invalidate(subject);
513
+ return next;
514
+ }
515
+ throw new Error(`upsertSubject: storage kept changing "${key}"; giving up`);
516
+ });
517
+ }
518
+ async function list(query = {}) {
519
+ const parsed = (0, _xtandard_kit_util.parseInput)(require_relationships.listQuerySchema, query);
520
+ let keys;
521
+ if (parsed.subject !== void 0 && parsed.permission !== void 0) keys = [require_relationships.grantKey(parsed.subject, parsed.permission)];
522
+ else if (parsed.subject !== void 0) keys = await storage.getKeys(require_relationships.subjectGrantsPrefix(parsed.subject));
523
+ else {
524
+ keys = await storage.getKeys(require_relationships.grantsPrefix());
525
+ if (parsed.permission !== void 0) {
526
+ const permission = parsed.permission;
527
+ keys = keys.filter((key) => {
528
+ const p = require_relationships.parseKey(key);
529
+ return p?.area === "grants" && p.rest === permission;
530
+ });
531
+ }
532
+ }
533
+ return (await Promise.all(keys.map((key) => storage.getItem(key)))).filter((grant) => grant !== null && typeof grant === "object" && (parsed.includeExpired === true || active(grant))).sort((a, b) => a.subject === b.subject ? a.permission < b.permission ? -1 : a.permission > b.permission ? 1 : 0 : a.subject < b.subject ? -1 : 1);
534
+ }
535
+ async function getSubject(id, opts = {}) {
536
+ const subject = requireSubjectId(id);
537
+ const { record, grants } = await readSubject(subject);
538
+ const { role, source } = await decideRole(subject, record, null);
539
+ const shown = opts.includeExpired ? grants : grants.filter(active);
540
+ shown.sort((a, b) => a.permission < b.permission ? -1 : a.permission > b.permission ? 1 : 0);
541
+ return {
542
+ id: subject,
543
+ record,
544
+ role: storedRole(record),
545
+ effectiveRole: role,
546
+ roleSource: source,
547
+ grants: shown
548
+ };
549
+ }
550
+ async function listSubjects() {
551
+ const [recordKeys, grantKeys] = await Promise.all([storage.getKeys(require_relationships.subjectsPrefix()), storage.getKeys(require_relationships.grantsPrefix())]);
552
+ const counts = /* @__PURE__ */ new Map();
553
+ for (const key of grantKeys) {
554
+ const parsed = require_relationships.parseKey(key);
555
+ if (parsed?.area === "grants") counts.set(parsed.subject, (counts.get(parsed.subject) ?? 0) + 1);
556
+ }
557
+ const records = /* @__PURE__ */ new Map();
558
+ await Promise.all(recordKeys.map(async (key) => {
559
+ const parsed = require_relationships.parseKey(key);
560
+ if (parsed?.area !== "subjects" || parsed.rest !== void 0) return;
561
+ const record = await storage.getItem(key);
562
+ if (record) records.set(parsed.subject, record);
563
+ }));
564
+ const ids = [...new Set([...records.keys(), ...counts.keys()])].sort();
565
+ return Promise.all(ids.map(async (id) => {
566
+ const record = records.get(id) ?? null;
567
+ const { role, source, looked } = await decideRole(id, record, null, (error) => {
568
+ logger.warn(`lookupSubject("${id}") failed; listing its default role`, error);
569
+ return null;
570
+ });
571
+ const name = record?.name ?? looked?.name;
572
+ const email = record?.email ?? looked?.email;
573
+ return {
574
+ id,
575
+ role: record?.role ?? null,
576
+ effectiveRole: role,
577
+ roleSource: source,
578
+ ...name !== void 0 ? { name } : {},
579
+ ...email !== void 0 ? { email } : {},
580
+ grantCount: counts.get(id) ?? 0
581
+ };
582
+ }));
583
+ }
584
+ async function history(query = {}) {
585
+ const parsed = (0, _xtandard_kit_util.parseInput)(require_relationships.historyQuerySchema, query);
586
+ const limit = parsed.limit ?? DEFAULT_HISTORY_LIMIT;
587
+ let tokens = (await storage.getKeys(parsed.subject !== void 0 ? require_relationships.subjectHistoryPrefix(parsed.subject) : require_relationships.historyPrefix())).map((key) => ({
588
+ key,
589
+ token: historyToken(key)
590
+ }));
591
+ tokens.sort((a, b) => a.token < b.token ? 1 : a.token > b.token ? -1 : 0);
592
+ if (parsed.cursor !== void 0) {
593
+ const after = historyToken(parsed.cursor);
594
+ tokens = tokens.filter((t) => t.token < after);
595
+ }
596
+ const page = tokens.slice(0, limit);
597
+ const entries = (await Promise.all(page.map((t) => storage.getItem(t.key)))).filter((entry) => entry !== null && typeof entry === "object");
598
+ const last = page[page.length - 1];
599
+ return {
600
+ entries,
601
+ nextCursor: tokens.length > limit && last ? last.key : null
602
+ };
603
+ }
604
+ return {
605
+ ...require_relationships.createRelationships({
606
+ storage,
607
+ schema: catalog.relations,
608
+ options: options.relations,
609
+ hooks,
610
+ onHookError,
611
+ nowIso,
612
+ assertWritable,
613
+ withLock,
614
+ appendHistory,
615
+ toActor
616
+ }),
617
+ catalog,
618
+ storage,
619
+ readonly,
620
+ roleSource,
621
+ grant,
622
+ revoke,
623
+ list,
624
+ setRole,
625
+ getSubject,
626
+ listSubjects,
627
+ upsertSubject,
628
+ history,
629
+ ability: (subject, ...[facts]) => buildAbility(subject, facts),
630
+ check: async (subject, path, data, ...[facts]) => (await buildAbility(subject, facts)).checkAsync(path, data),
631
+ can: async (subject, path, data, ...[facts]) => (await (await buildAbility(subject, facts)).checkAsync(path, data)).allowed,
632
+ async snapshot(subject) {
633
+ const resolved = await resolve(subject);
634
+ const permissions = [...new Set(resolved.grants.map((grant) => grant.permission).filter(catalog.isAssignable))].sort();
635
+ return {
636
+ subject: {
637
+ id: resolved.id,
638
+ role: resolved.role,
639
+ ...resolved.roleSource !== void 0 ? { roleSource: resolved.roleSource } : {}
640
+ },
641
+ permissions
642
+ };
643
+ },
644
+ invalidate,
645
+ async close() {
646
+ await watching;
647
+ const off = unwatch;
648
+ unwatch = null;
649
+ off?.();
650
+ }
651
+ };
652
+ }
653
+ //#endregion
654
+ Object.defineProperty(exports, "createPermissions", {
655
+ enumerable: true,
656
+ get: function() {
657
+ return createPermissions;
658
+ }
659
+ });
660
+ Object.defineProperty(exports, "engine_exports", {
661
+ enumerable: true,
662
+ get: function() {
663
+ return engine_exports;
664
+ }
665
+ });
666
+
667
+ //# sourceMappingURL=engine--C7zo-4M.cjs.map