@jini-ai/user-management 0.7.3-next.2 → 0.7.4

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 (380) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +55 -2
  3. package/dist/admin/adapters/memory.js +4 -4
  4. package/dist/admin-http/auth/auth-request.d.ts +112 -0
  5. package/dist/admin-http/auth/auth-request.js +32 -0
  6. package/dist/admin-http/auth/boot-redemption.d.ts +9 -0
  7. package/dist/admin-http/auth/boot-redemption.js +17 -0
  8. package/dist/admin-http/auth/boot-session.d.ts +30 -0
  9. package/dist/admin-http/auth/boot-session.js +40 -0
  10. package/dist/admin-http/auth/current-user.d.ts +28 -0
  11. package/dist/admin-http/auth/current-user.js +34 -0
  12. package/dist/admin-http/auth/index.d.ts +17 -0
  13. package/dist/admin-http/auth/index.js +9 -0
  14. package/dist/admin-http/auth/local-boot-session.d.ts +9 -0
  15. package/dist/admin-http/auth/local-boot-session.js +30 -0
  16. package/dist/admin-http/auth/logout.d.ts +10 -0
  17. package/dist/admin-http/auth/logout.js +17 -0
  18. package/dist/admin-http/auth/mfa-login.d.ts +30 -0
  19. package/dist/admin-http/auth/mfa-login.js +43 -0
  20. package/dist/admin-http/auth/password-login.d.ts +35 -0
  21. package/dist/admin-http/auth/password-login.js +52 -0
  22. package/dist/admin-http/auth/password-status.d.ts +34 -0
  23. package/dist/admin-http/auth/password-status.js +42 -0
  24. package/dist/admin-http/http/api-keys.d.ts +45 -0
  25. package/dist/admin-http/http/api-keys.js +28 -0
  26. package/dist/admin-http/http/users.d.ts +71 -0
  27. package/dist/admin-http/http/users.js +42 -0
  28. package/dist/admin-http/owner/mfa-deps.d.ts +41 -0
  29. package/dist/admin-http/owner/mfa-deps.js +26 -0
  30. package/dist/admin-http/owner/mfa-routes.d.ts +72 -0
  31. package/dist/admin-http/owner/mfa-routes.js +105 -0
  32. package/dist/admin-http/owner/passkey-admission.d.ts +46 -0
  33. package/dist/admin-http/owner/passkey-admission.js +23 -0
  34. package/dist/admin-http/owner/passkey-route-deps.d.ts +53 -0
  35. package/dist/admin-http/owner/passkey-route-deps.js +33 -0
  36. package/dist/admin-http/owner/passkey-routes.d.ts +146 -0
  37. package/dist/admin-http/owner/passkey-routes.js +98 -0
  38. package/dist/admin-http/owner/recovery-routes.d.ts +71 -0
  39. package/dist/admin-http/owner/recovery-routes.js +112 -0
  40. package/dist/admin-http/routes/api-keys/create-principal.d.ts +26 -0
  41. package/dist/admin-http/routes/api-keys/create-principal.js +37 -0
  42. package/dist/admin-http/routes/api-keys/issue.d.ts +32 -0
  43. package/dist/admin-http/routes/api-keys/issue.js +38 -0
  44. package/dist/admin-http/routes/api-keys/revoke.d.ts +26 -0
  45. package/dist/admin-http/routes/api-keys/revoke.js +31 -0
  46. package/dist/admin-http/routes/api-keys/shared.d.ts +46 -0
  47. package/dist/admin-http/routes/api-keys/shared.js +38 -0
  48. package/dist/admin-http/routes/users/access-shared.d.ts +103 -0
  49. package/dist/admin-http/routes/users/access-shared.js +85 -0
  50. package/dist/admin-http/routes/users/assign-role.d.ts +24 -0
  51. package/dist/admin-http/routes/users/assign-role.js +30 -0
  52. package/dist/admin-http/routes/users/attach-policy.d.ts +25 -0
  53. package/dist/admin-http/routes/users/attach-policy.js +31 -0
  54. package/dist/admin-http/routes/users/create-policy.d.ts +19 -0
  55. package/dist/admin-http/routes/users/create-policy.js +28 -0
  56. package/dist/admin-http/routes/users/create-role.d.ts +15 -0
  57. package/dist/admin-http/routes/users/create-role.js +21 -0
  58. package/dist/admin-http/routes/users/create.d.ts +32 -0
  59. package/dist/admin-http/routes/users/create.js +67 -0
  60. package/dist/admin-http/routes/users/delete-policy.d.ts +16 -0
  61. package/dist/admin-http/routes/users/delete-policy.js +24 -0
  62. package/dist/admin-http/routes/users/delete-role.d.ts +16 -0
  63. package/dist/admin-http/routes/users/delete-role.js +24 -0
  64. package/dist/admin-http/routes/users/delete.d.ts +35 -0
  65. package/dist/admin-http/routes/users/delete.js +35 -0
  66. package/dist/admin-http/routes/users/disable.d.ts +31 -0
  67. package/dist/admin-http/routes/users/disable.js +38 -0
  68. package/dist/admin-http/routes/users/enable.d.ts +32 -0
  69. package/dist/admin-http/routes/users/enable.js +45 -0
  70. package/dist/admin-http/routes/users/list-policies.d.ts +18 -0
  71. package/dist/admin-http/routes/users/list-policies.js +20 -0
  72. package/dist/admin-http/routes/users/list-policy-permissions.d.ts +28 -0
  73. package/dist/admin-http/routes/users/list-policy-permissions.js +30 -0
  74. package/dist/admin-http/routes/users/list-roles.d.ts +18 -0
  75. package/dist/admin-http/routes/users/list-roles.js +20 -0
  76. package/dist/admin-http/routes/users/list.d.ts +40 -0
  77. package/dist/admin-http/routes/users/list.js +82 -0
  78. package/dist/admin-http/routes/users/remove-policy-permission.d.ts +48 -0
  79. package/dist/admin-http/routes/users/remove-policy-permission.js +62 -0
  80. package/dist/admin-http/routes/users/reset-password.d.ts +33 -0
  81. package/dist/admin-http/routes/users/reset-password.js +52 -0
  82. package/dist/admin-http/routes/users/shared.d.ts +124 -0
  83. package/dist/admin-http/routes/users/shared.js +93 -0
  84. package/dist/admin-http/routes/users/update-policy.d.ts +25 -0
  85. package/dist/admin-http/routes/users/update-policy.js +30 -0
  86. package/dist/admin-http/routes/users/update-role.d.ts +23 -0
  87. package/dist/admin-http/routes/users/update-role.js +29 -0
  88. package/dist/admin-http/routes/users/update.d.ts +35 -0
  89. package/dist/admin-http/routes/users/update.js +78 -0
  90. package/dist/admin-http/routes/users/write-policy-permission.d.ts +31 -0
  91. package/dist/admin-http/routes/users/write-policy-permission.js +45 -0
  92. package/dist/core/ports.d.ts +22 -3
  93. package/dist/core/types.d.ts +17 -5
  94. package/dist/core/types.js +12 -0
  95. package/dist/identity/api-key-secret.d.ts +68 -0
  96. package/dist/identity/api-key-secret.js +229 -0
  97. package/dist/identity/api-key-service.d.ts +144 -0
  98. package/dist/identity/api-key-service.js +389 -0
  99. package/dist/identity/api-key-types.d.ts +79 -0
  100. package/dist/identity/api-key-types.js +2 -0
  101. package/dist/identity/boot-session-token.d.ts +18 -0
  102. package/dist/identity/boot-session-token.js +92 -0
  103. package/dist/identity/builtin-role-grants.d.ts +120 -0
  104. package/dist/identity/builtin-role-grants.js +88 -0
  105. package/dist/identity/delete-user-service.d.ts +195 -0
  106. package/dist/identity/delete-user-service.js +275 -0
  107. package/dist/identity/owner-reset-env.d.ts +37 -0
  108. package/dist/identity/owner-reset-env.js +38 -0
  109. package/dist/identity/permission-grants.d.ts +31 -0
  110. package/dist/identity/permission-grants.js +12 -0
  111. package/dist/identity/permission-list-tool.d.ts +35 -0
  112. package/dist/identity/permission-list-tool.js +47 -0
  113. package/dist/identity/repo.authentication.d.ts +57 -0
  114. package/dist/identity/repo.authentication.js +153 -0
  115. package/dist/identity/repo.authorization.d.ts +82 -0
  116. package/dist/identity/repo.authorization.js +203 -0
  117. package/dist/identity/repo.d.ts +87 -0
  118. package/dist/identity/repo.js +167 -0
  119. package/dist/identity/repo.memory.d.ts +31 -0
  120. package/dist/identity/repo.memory.js +37 -0
  121. package/dist/identity/role-manage-permission.d.ts +34 -0
  122. package/dist/identity/role-manage-permission.js +39 -0
  123. package/dist/identity/site-key-permission.d.ts +66 -0
  124. package/dist/identity/site-key-permission.js +92 -0
  125. package/dist/identity/sql/kernel-user-purge.d.ts +19 -0
  126. package/dist/identity/sql/kernel-user-purge.js +34 -0
  127. package/dist/identity/sql/kernel-user-trash-store.d.ts +15 -0
  128. package/dist/identity/sql/kernel-user-trash-store.js +41 -0
  129. package/dist/identity/sql/user-trash-adapter.d.ts +87 -0
  130. package/dist/identity/sql/user-trash-adapter.js +124 -0
  131. package/dist/identity/tool-registrations.d.ts +100 -0
  132. package/dist/identity/tool-registrations.js +257 -0
  133. package/dist/identity/user-manage-permission.d.ts +8 -0
  134. package/dist/identity/user-manage-permission.js +8 -0
  135. package/dist/identity/user-purge-types.d.ts +85 -0
  136. package/dist/identity/user-purge-types.js +17 -0
  137. package/dist/identity/user-purge.d.ts +69 -0
  138. package/dist/identity/user-purge.js +46 -0
  139. package/dist/identity/username-change-ports.d.ts +15 -0
  140. package/dist/identity/username-change-ports.js +22 -0
  141. package/dist/mail/site/capture-clear.d.ts +58 -0
  142. package/dist/mail/site/capture-clear.js +21 -0
  143. package/dist/mail/status/agent-tools.d.ts +65 -0
  144. package/dist/mail/status/agent-tools.js +22 -0
  145. package/dist/mail/status/delivery-agent-tools.d.ts +206 -0
  146. package/dist/mail/status/delivery-agent-tools.js +63 -0
  147. package/dist/mail/status/delivery-tool-registrations.d.ts +216 -0
  148. package/dist/mail/status/delivery-tool-registrations.js +110 -0
  149. package/dist/mail/status/domain-deps.d.ts +25 -0
  150. package/dist/mail/status/domain-deps.js +23 -0
  151. package/dist/mail/status/permissions.d.ts +43 -0
  152. package/dist/mail/status/permissions.js +45 -0
  153. package/dist/mail/status/provider-agent-tools.d.ts +38 -0
  154. package/dist/mail/status/provider-agent-tools.js +17 -0
  155. package/dist/mail/status/provider-operations.d.ts +166 -0
  156. package/dist/mail/status/provider-operations.js +121 -0
  157. package/dist/mail/status/provider-tool-registrations.d.ts +65 -0
  158. package/dist/mail/status/provider-tool-registrations.js +106 -0
  159. package/dist/mail/status/tool-registrations.d.ts +152 -0
  160. package/dist/mail/status/tool-registrations.js +112 -0
  161. package/dist/member-login/credentials.d.ts +40 -0
  162. package/dist/member-login/credentials.js +26 -0
  163. package/dist/member-login/link-service.d.ts +66 -0
  164. package/dist/member-login/link-service.js +141 -0
  165. package/dist/member-login/oidc-login.d.ts +132 -0
  166. package/dist/member-login/oidc-login.js +206 -0
  167. package/dist/member-login/oidc-request.d.ts +80 -0
  168. package/dist/member-login/oidc-request.js +86 -0
  169. package/dist/member-login/providers.d.ts +79 -0
  170. package/dist/member-login/providers.js +41 -0
  171. package/dist/member-login/ready-providers.d.ts +17 -0
  172. package/dist/member-login/ready-providers.js +11 -0
  173. package/dist/member-login/unlink-identity.d.ts +26 -0
  174. package/dist/member-login/unlink-identity.js +59 -0
  175. package/dist/members/access-resolver.d.ts +107 -0
  176. package/dist/members/access-resolver.js +231 -0
  177. package/dist/members/agent-tools.d.ts +14 -0
  178. package/dist/members/agent-tools.js +139 -0
  179. package/dist/members/auth-mail.d.ts +27 -0
  180. package/dist/members/auth-mail.js +21 -0
  181. package/dist/members/capability-card.d.ts +18 -0
  182. package/dist/members/capability-card.js +27 -0
  183. package/dist/members/consent-service.d.ts +115 -0
  184. package/dist/members/consent-service.js +179 -0
  185. package/dist/members/member-admin-writes.d.ts +73 -0
  186. package/dist/members/member-admin-writes.js +149 -0
  187. package/dist/members/member-challenge-request.d.ts +59 -0
  188. package/dist/members/member-challenge-request.js +145 -0
  189. package/dist/members/member-challenge.d.ts +37 -0
  190. package/dist/members/member-challenge.js +84 -0
  191. package/dist/members/member-credentials.d.ts +35 -0
  192. package/dist/members/member-credentials.js +57 -0
  193. package/dist/members/member-sign-in.d.ts +44 -0
  194. package/dist/members/member-sign-in.js +130 -0
  195. package/dist/members/member-validation.d.ts +5 -0
  196. package/dist/members/member-validation.js +13 -0
  197. package/dist/members/password-auth.d.ts +55 -0
  198. package/dist/members/password-auth.js +177 -0
  199. package/dist/members/ports.d.ts +455 -0
  200. package/dist/members/ports.js +21 -0
  201. package/dist/members/public-member-auth-response.d.ts +68 -0
  202. package/dist/members/public-member-auth-response.js +45 -0
  203. package/dist/members/public-member-response.d.ts +25 -0
  204. package/dist/members/public-member-response.js +15 -0
  205. package/dist/members/repo.d.ts +199 -0
  206. package/dist/members/repo.js +324 -0
  207. package/dist/members/repo.memory.d.ts +276 -0
  208. package/dist/members/repo.memory.js +395 -0
  209. package/dist/members/repo.rows.d.ts +153 -0
  210. package/dist/members/repo.rows.js +250 -0
  211. package/dist/members/repo.sessions.d.ts +80 -0
  212. package/dist/members/repo.sessions.js +166 -0
  213. package/dist/members/repo.sql.d.ts +9 -0
  214. package/dist/members/repo.sql.js +11 -0
  215. package/dist/members/subscriber-directory.d.ts +85 -0
  216. package/dist/members/subscriber-directory.js +70 -0
  217. package/dist/members/tool-registrations.d.ts +143 -0
  218. package/dist/members/tool-registrations.js +247 -0
  219. package/dist/members/trash-member.d.ts +24 -0
  220. package/dist/members/trash-member.js +24 -0
  221. package/dist/members/types.d.ts +321 -0
  222. package/dist/members/types.js +34 -0
  223. package/dist/members/write-service.d.ts +17 -0
  224. package/dist/members/write-service.js +15 -0
  225. package/dist/newsletter/agent-tools.d.ts +20 -0
  226. package/dist/newsletter/agent-tools.js +236 -0
  227. package/dist/newsletter/campaign-write-service.d.ts +92 -0
  228. package/dist/newsletter/campaign-write-service.js +190 -0
  229. package/dist/newsletter/campaign.d.ts +53 -0
  230. package/dist/newsletter/campaign.js +95 -0
  231. package/dist/newsletter/confirmation.d.ts +75 -0
  232. package/dist/newsletter/confirmation.js +142 -0
  233. package/dist/newsletter/data-module-manifest.d.ts +68 -0
  234. package/dist/newsletter/data-module-manifest.js +126 -0
  235. package/dist/newsletter/delivery/tool-registrations.d.ts +67 -0
  236. package/dist/newsletter/delivery/tool-registrations.js +229 -0
  237. package/dist/newsletter/errors.d.ts +93 -0
  238. package/dist/newsletter/errors.js +93 -0
  239. package/dist/newsletter/hooks.d.ts +59 -0
  240. package/dist/newsletter/hooks.js +49 -0
  241. package/dist/newsletter/http-error-responses.d.ts +17 -0
  242. package/dist/newsletter/http-error-responses.js +96 -0
  243. package/dist/newsletter/launch-gate.d.ts +62 -0
  244. package/dist/newsletter/launch-gate.js +29 -0
  245. package/dist/newsletter/lists.d.ts +60 -0
  246. package/dist/newsletter/lists.js +83 -0
  247. package/dist/newsletter/ports.d.ts +283 -0
  248. package/dist/newsletter/ports.js +2 -0
  249. package/dist/newsletter/repo-sends.d.ts +82 -0
  250. package/dist/newsletter/repo-sends.js +178 -0
  251. package/dist/newsletter/repo-subscribers.d.ts +83 -0
  252. package/dist/newsletter/repo-subscribers.js +215 -0
  253. package/dist/newsletter/repo.d.ts +61 -0
  254. package/dist/newsletter/repo.js +147 -0
  255. package/dist/newsletter/repo.memory.d.ts +202 -0
  256. package/dist/newsletter/repo.memory.js +260 -0
  257. package/dist/newsletter/repo.rows.d.ts +221 -0
  258. package/dist/newsletter/repo.rows.js +260 -0
  259. package/dist/newsletter/save-guard.d.ts +32 -0
  260. package/dist/newsletter/save-guard.js +27 -0
  261. package/dist/newsletter/send-pipeline.d.ts +240 -0
  262. package/dist/newsletter/send-pipeline.js +514 -0
  263. package/dist/newsletter/subscriptions.d.ts +87 -0
  264. package/dist/newsletter/subscriptions.js +119 -0
  265. package/dist/newsletter/tool-registrations.d.ts +89 -0
  266. package/dist/newsletter/tool-registrations.deps.d.ts +9 -0
  267. package/dist/newsletter/tool-registrations.deps.js +9 -0
  268. package/dist/newsletter/tool-registrations.js +133 -0
  269. package/dist/newsletter/tool-registrations.read.d.ts +76 -0
  270. package/dist/newsletter/tool-registrations.read.js +140 -0
  271. package/dist/newsletter/tool-registrations.write.d.ts +54 -0
  272. package/dist/newsletter/tool-registrations.write.js +229 -0
  273. package/dist/newsletter/types.d.ts +279 -0
  274. package/dist/newsletter/types.js +23 -0
  275. package/dist/newsletter/unsubscribe.d.ts +41 -0
  276. package/dist/newsletter/unsubscribe.js +100 -0
  277. package/dist/project-keys/attached-vault.d.ts +23 -0
  278. package/dist/project-keys/attached-vault.js +65 -0
  279. package/dist/project-keys/create-vault.d.ts +17 -0
  280. package/dist/project-keys/create-vault.js +29 -0
  281. package/dist/project-keys/service.d.ts +133 -0
  282. package/dist/project-keys/service.js +128 -0
  283. package/dist/project-keys/site-references.d.ts +30 -0
  284. package/dist/project-keys/site-references.js +63 -0
  285. package/dist/project-keys/site-sealer.d.ts +28 -0
  286. package/dist/project-keys/site-sealer.js +64 -0
  287. package/dist/project-keys/sql/attachments.d.ts +33 -0
  288. package/dist/project-keys/sql/attachments.js +55 -0
  289. package/dist/project-keys/tools.d.ts +86 -0
  290. package/dist/project-keys/tools.js +66 -0
  291. package/dist/public-http/routes/mail/feedback.d.ts +44 -0
  292. package/dist/public-http/routes/mail/feedback.js +17 -0
  293. package/dist/public-http/routes/newsletter/confirm.d.ts +38 -0
  294. package/dist/public-http/routes/newsletter/confirm.js +33 -0
  295. package/dist/public-http/routes/newsletter/page.d.ts +29 -0
  296. package/dist/public-http/routes/newsletter/page.js +34 -0
  297. package/dist/public-http/routes/newsletter/unsubscribe.d.ts +33 -0
  298. package/dist/public-http/routes/newsletter/unsubscribe.js +35 -0
  299. package/dist/react/auth/Passkeys.d.ts +2 -34
  300. package/dist/react/auth/RecoveryCodesCard.d.ts +27 -0
  301. package/dist/react/auth/RecoveryCodesCard.hooks.d.ts +67 -0
  302. package/dist/react/auth/RecoveryCodesCard.hooks.js +38 -0
  303. package/dist/react/auth/RecoveryCodesCard.js +56 -0
  304. package/dist/react/auth/TotpSettings.d.ts +2 -23
  305. package/dist/react/auth/local-owner-signin.d.ts +40 -0
  306. package/dist/react/auth/local-owner-signin.js +25 -0
  307. package/dist/react/auth/owner-mfa-api.d.ts +10 -0
  308. package/dist/react/auth/owner-mfa-api.js +17 -0
  309. package/dist/react/auth/owner-passkey-api.d.ts +11 -0
  310. package/dist/react/auth/owner-passkey-api.js +17 -0
  311. package/dist/react/auth/owner-recovery-api.d.ts +51 -0
  312. package/dist/react/auth/owner-recovery-api.js +29 -0
  313. package/dist/react/auth/owner-request.d.ts +7 -0
  314. package/dist/react/auth/owner-request.js +2 -0
  315. package/dist/react/index.d.ts +10 -0
  316. package/dist/react/index.js +6 -0
  317. package/dist/react/mail/Email.d.ts +20 -0
  318. package/dist/react/mail/Email.js +143 -0
  319. package/dist/react/mail/EmailProviderTab.d.ts +34 -0
  320. package/dist/react/mail/EmailProviderTab.js +132 -0
  321. package/dist/react/mail/EmailSegments.d.ts +24 -0
  322. package/dist/react/mail/EmailSegments.js +15 -0
  323. package/dist/react/mail/EmailTemplateEditor.d.ts +146 -0
  324. package/dist/react/mail/EmailTemplateEditor.js +116 -0
  325. package/dist/react/mail/email-view.types.d.ts +236 -0
  326. package/dist/react/mail/email-view.types.js +2 -0
  327. package/dist/react/members/Members.d.ts +5 -3
  328. package/dist/react/members/Members.js +3 -3
  329. package/dist/react/members/api/members-api.d.ts +37 -0
  330. package/dist/react/members/api/members-api.js +16 -0
  331. package/dist/react/members/hooks/use-members.hooks.js +2 -1
  332. package/dist/react/members/members-i18n.d.ts +23 -0
  333. package/dist/react/members/members-i18n.js +25 -0
  334. package/dist/react/members/members-i18n.locales-a.d.ts +4 -0
  335. package/dist/react/members/members-i18n.locales-a.js +294 -0
  336. package/dist/react/members/members-i18n.locales-b.d.ts +4 -0
  337. package/dist/react/members/members-i18n.locales-b.js +265 -0
  338. package/dist/react/models.d.ts +1 -49
  339. package/dist/react/ports.d.ts +3 -143
  340. package/dist/react/roles/api/roles-api.d.ts +74 -0
  341. package/dist/react/roles/api/roles-api.js +22 -0
  342. package/dist/react/testing.js +18 -9
  343. package/dist/react/users/UsersPanel.d.ts +30 -0
  344. package/dist/react/users/UsersPanel.hooks.d.ts +8 -0
  345. package/dist/react/users/UsersPanel.hooks.js +9 -0
  346. package/dist/react/users/UsersPanel.js +9 -0
  347. package/dist/react/users/api/users-api.d.ts +65 -0
  348. package/dist/react/users/api/users-api.js +46 -0
  349. package/dist/react/users/hooks/use-localized-users.hooks.d.ts +43 -0
  350. package/dist/react/users/hooks/use-localized-users.hooks.js +15 -0
  351. package/dist/react/users/hooks/use-users-state.hooks.d.ts +18 -18
  352. package/dist/react/users/password-reset-notice.d.ts +8 -0
  353. package/dist/react/users/password-reset-notice.js +36 -0
  354. package/dist/server/admin-crud-service.d.ts +4 -10
  355. package/dist/server/admin-crud-service.js +20 -6
  356. package/dist/server/agent-tool-registrations.js +26 -7
  357. package/dist/server/agent-tools.js +22 -7
  358. package/dist/server/auth-challenge.d.ts +1 -1
  359. package/dist/server/auth-service.js +2 -1
  360. package/dist/server/grant-service.d.ts +1 -0
  361. package/dist/server/grant-service.js +7 -4
  362. package/dist/server/mfa/passkey-service.d.ts +2 -2
  363. package/dist/server/mfa/passkey-service.js +1 -1
  364. package/dist/server/mfa/service.js +6 -4
  365. package/dist/server/repo.memory.d.ts +30 -2
  366. package/dist/server/repo.memory.js +58 -4
  367. package/dist/server/seed.js +3 -3
  368. package/dist/server/sql/assignments.d.ts +90 -0
  369. package/dist/server/sql/assignments.js +128 -0
  370. package/dist/server/sql/index.d.ts +6 -0
  371. package/dist/server/sql/index.js +5 -0
  372. package/dist/server/sql/kernel.d.ts +9 -0
  373. package/dist/server/sql/kernel.js +2 -0
  374. package/dist/server/sql/mfa.d.ts +36 -0
  375. package/dist/server/sql/mfa.js +51 -0
  376. package/dist/server/sql/passkeys.d.ts +25 -0
  377. package/dist/server/sql/passkeys.js +33 -0
  378. package/dist/server/sql/recovery-codes.d.ts +22 -0
  379. package/dist/server/sql/recovery-codes.js +32 -0
  380. package/package.json +909 -11
@@ -0,0 +1,82 @@
1
+ import { defineJsonRoute, ok } from "@jini-ai/core/contracts/server";
2
+ import { rejectRoute } from "@jini-ai/core/errors/route-refusal";
3
+ import { adminUserWithGrants, userActorId } from "./shared.js";
4
+ /**
5
+ * Gated by `user.manage`/`member.manage` (either) for this read-only roster; operator creation
6
+ * separately requires `user.manage`. No separate `user.read` permission exists in the catalog.
7
+ * 2026-07-16 authz sweep: this route previously had zero permission check beyond session auth,
8
+ * letting any authenticated admin session read the full user roster regardless of role.
9
+ * Both decisions are asked (in parallel, as before); the refusal names `user.manage`'s reason.
10
+ * @complexity O(1) plus two injected decisions.
11
+ */
12
+ async function authorizeUserRoster({ deps, principalId }, _optional = {}) {
13
+ const [userManage, memberManage] = await Promise.all([
14
+ deps.decidePermission({ principalId, permission: "user.manage", workspaceId: deps.workspaceId }),
15
+ deps.decidePermission({ principalId, permission: "member.manage", workspaceId: deps.workspaceId }),
16
+ ]);
17
+ if (userManage.allowed || memberManage.allowed)
18
+ return;
19
+ rejectRoute({
20
+ status: 403,
21
+ error: `principal '${principalId}' is not authorized for 'user.manage' or 'member.manage' (${userManage.reason})`,
22
+ code: "FORBIDDEN",
23
+ details: { permission: "user.manage", reason: userManage.reason },
24
+ });
25
+ }
26
+ /**
27
+ * Non-human principals (`system`, `agent`, `api_key` — including the disabled legacy `user-local`
28
+ * seed row) are filtered out: this screen is "Users" (human operators), not the full roster.
29
+ * @complexity O(n) Trash lookups, n = principal count.
30
+ */
31
+ async function listedHumanPrincipals({ deps, repos }, _optional = {}) {
32
+ const principals = await repos.principals.list({ workspaceId: deps.workspaceId });
33
+ const entries = await Promise.all(principals
34
+ .filter((principal) => principal.kind === "user")
35
+ .map(async (principal) => ({
36
+ principal,
37
+ // OWNER DECISION 2026-09-24 (delete-user plan v2, decision 7's list side): a user
38
+ // trashed via DELETE_USER is `status:'disabled'` plus a `trashed_items` row — this
39
+ // screen must not list them as an ordinary disabled user, since restoring them here
40
+ // means EnablePrincipal, not the Trash's own restore. An intentionally-disabled user
41
+ // (never trashed) has no `trashed_items` row and stays listed.
42
+ trashed: principal.status === "disabled" && (await deps.isInTrash({ principalId: principal.id })),
43
+ })));
44
+ return entries.filter((entry) => !entry.trashed).map((entry) => entry.principal);
45
+ }
46
+ /** One roster row, or `null` for a principal without its paired users row. @complexity O(1) plus four reads. */
47
+ async function listEntry({ deps, services, principal, seededOwnerPrincipalId }, _optional = {}) {
48
+ const user = await services.repos.users.findByPrincipalId({ workspaceId: deps.workspaceId, principalId: principal.id });
49
+ // Every kind='user' principal has a paired users row by construction
50
+ // (CREATE_USER/SEED_FIRST_BOOT's atomicity guarantee) — this null
51
+ // check is defensive, not an expected runtime path.
52
+ if (!user)
53
+ return null;
54
+ const response = await adminUserWithGrants({ repos: services.repos, workspaceId: deps.workspaceId, principal, user });
55
+ const protection = await deps.userAccountProtection({ deps: deps.identityServices(), workspaceId: deps.workspaceId, principalId: principal.id });
56
+ // The bootstrap owner is still found by login at reboot; offer rename only when safe.
57
+ return { ...protection, canRename: principal.id !== seededOwnerPrincipalId, ...response };
58
+ }
59
+ /**
60
+ * GET users — list a workspace's human (`kind='user'`) principals for the admin UI. No dedicated
61
+ * `listUsers` business-logic function exists in this package's server services (they export
62
+ * grant-writing mutations, not read-side wrappers) — this route calls the repo ports directly.
63
+ */
64
+ export const userListRoute = defineJsonRoute({
65
+ method: "get",
66
+ path: "/api/admin/v1/workspaces/:workspaceId/users",
67
+ parse: () => ok({ value: {} }),
68
+ handle: async ({ deps, context }) => {
69
+ await authorizeUserRoster({ deps, principalId: userActorId({ context }) });
70
+ const services = deps.identityServices();
71
+ const principals = await listedHumanPrincipals({ deps, repos: services.repos });
72
+ const seededOwnerPrincipalId = await deps.ownerPrincipalId;
73
+ // O(n) repo round trips, n = human principal count. Unbounded by a caller-controlled
74
+ // collection (this is an operator-managed roster, not member/content scale — the same
75
+ // assumption `resolveEffectivePermissions` already makes) — no cap needed this pass; a future
76
+ // pagination pass would mirror `MemberRepoPort.list`'s afterId/limit shape if this workspace's
77
+ // operator count ever grows unexpectedly large.
78
+ const users = await Promise.all(principals.map((principal) => listEntry({ deps, services, principal, seededOwnerPrincipalId })));
79
+ return ok({ value: { users: users.filter((user) => user !== null) } });
80
+ },
81
+ });
82
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1,48 @@
1
+ import { type RouteReply } from "@jini-ai/core/contracts/server";
2
+ import type { IdentityTransactionPort, PolicyPermissionRepoPort } from "../../../core/ports.js";
3
+ import type { removePolicyPermission } from "../../../server/admin-crud-service.js";
4
+ import type { AuthServiceDeps } from "../../../server/auth-service.js";
5
+ import { type AccessRoutePrincipal, type AccessServiceRouteDeps } from "./access-shared.js";
6
+ /** The host's owner test: does this principal hold the unconstrained `*` grant? (The host owns who is an owner.) */
7
+ export type PrincipalHoldsOwnerWildcardFn = (required: {
8
+ deps: AuthServiceDeps;
9
+ workspaceId: string;
10
+ principalId: string;
11
+ }, optional?: Record<string, never>) => Promise<boolean>;
12
+ /** The host's post-write invariant: throws `OwnerRequiredError` when no active owner would remain. */
13
+ export type AssertActiveOwnerFloorFn = (required: {
14
+ deps: AuthServiceDeps;
15
+ workspaceId: string;
16
+ }, optional?: Record<string, never>) => Promise<void>;
17
+ /** The deps this route reads. */
18
+ export interface PolicyPermissionRemoveRouteDeps extends AccessServiceRouteDeps {
19
+ transactions: Pick<IdentityTransactionPort, "run">;
20
+ policyPermissionRepo: Pick<PolicyPermissionRepoPort, "listByPolicyId">;
21
+ /** Injected: the service lives in the node `./server` entry; the host binds it. */
22
+ removePolicyPermission: typeof removePolicyPermission;
23
+ principalHoldsOwnerWildcard: PrincipalHoldsOwnerWildcardFn;
24
+ assertActiveOwnerFloor: AssertActiveOwnerFloorFn;
25
+ }
26
+ interface RemoveInput {
27
+ policyId: string;
28
+ policyPermissionId: string;
29
+ }
30
+ /**
31
+ * DELETE policies/:policyId/permissions/:policyPermissionId — `REMOVE_POLICY_PERMISSION` (OQ-10),
32
+ * the inverse of `write-policy-permission.ts` and the route that closes the gap `Roles.tsx`'s own
33
+ * header comment flagged: until now a policy's permission set was append-only, and the only way to
34
+ * shrink it was `DELETE_POLICY` + recreate — which INV-09 refuses outright the moment any role or
35
+ * principal references the policy.
36
+ *
37
+ * Gated by `role.manage`, exactly as the ADD route is. A built-in or frozen parent policy is
38
+ * refused `VALIDATION_ERROR` (INV-06/AC-26); a permission id that is absent — or that belongs to a
39
+ * different policy — is `RESOURCE_NOT_FOUND`, never a silent no-op success (the service proves
40
+ * membership from the policy's own rows before deleting).
41
+ *
42
+ * Returns 204, matching `delete-policy.ts`'s convention for a delete with nothing to echo back —
43
+ * as an explicit bodiless `routeReply`, so the host writes a bare `send()` (the hand-written
44
+ * route's `res.status(204).send()`), never a JSON body.
45
+ */
46
+ export declare const policyPermissionRemoveRoute: import("@jini-ai/core/contracts/server").JsonRouteSpec<RemoveInput, RouteReply<unknown>, PolicyPermissionRemoveRouteDeps, AccessRoutePrincipal>;
47
+ export {};
48
+ //# sourceMappingURL=remove-policy-permission.d.ts.map
@@ -0,0 +1,62 @@
1
+ import { defineJsonRoute, ok, routeReply } from "@jini-ai/core/contracts/server";
2
+ import { OwnerRequiredError } from "../../../core/types.js";
3
+ import { ACCESS_FORBIDDEN, ACCESS_NOT_FOUND, ACCESS_OWNER_REQUIRED, ACCESS_VALIDATION, accessActorId, accessPathParam, rejectAccessError, } from "./access-shared.js";
4
+ /** This route's thrown error types onto the admin error envelope — the same mapping
5
+ * `delete-policy.ts` uses, minus `IdentityConflictError`: `removePolicyPermission` has no
6
+ * reference guard to violate (a permission row is a leaf, nothing points at it). */
7
+ const POLICY_PERMISSION_REMOVE_ERRORS = [ACCESS_OWNER_REQUIRED, ACCESS_FORBIDDEN, ACCESS_VALIDATION, ACCESS_NOT_FOUND];
8
+ /** Only an owner may remove an unconstrained owner-`*` row: refused before the service runs.
9
+ * @complexity O(n) in the policy's row count plus the injected owner test. */
10
+ async function refuseNonOwnerWildcardRemoval({ deps, serviceDeps, input, callerPrincipalId }, _optional = {}) {
11
+ const rows = await deps.policyPermissionRepo.listByPolicyId({ workspaceId: deps.workspaceId, policyId: input.policyId });
12
+ const removed = rows.find(row => row.id === input.policyPermissionId);
13
+ if (removed?.permission === "*" && removed.resourceType == null && removed.constraintJson == null
14
+ && !await deps.principalHoldsOwnerWildcard({ deps: serviceDeps, workspaceId: deps.workspaceId, principalId: callerPrincipalId })) {
15
+ throw new OwnerRequiredError({ message: "only an owner can modify an owner principal" });
16
+ }
17
+ }
18
+ /** The guarded removal, the service call and the owner floor, in one identity transaction (the
19
+ * floor throws inside it so the removal rolls back). @complexity O(1) plus the injected work. */
20
+ async function removeInTransaction({ deps, input, callerPrincipalId }, _optional = {}) {
21
+ const serviceDeps = deps.identityServiceDeps();
22
+ await deps.transactions.run({ workspaceId: deps.workspaceId, execute: async () => {
23
+ await refuseNonOwnerWildcardRemoval({ deps, serviceDeps, input, callerPrincipalId });
24
+ await deps.removePolicyPermission({ deps: serviceDeps, input: { workspaceId: deps.workspaceId, callerPrincipalId, ...input } });
25
+ await deps.assertActiveOwnerFloor({ deps: serviceDeps, workspaceId: deps.workspaceId });
26
+ } });
27
+ }
28
+ /**
29
+ * DELETE policies/:policyId/permissions/:policyPermissionId — `REMOVE_POLICY_PERMISSION` (OQ-10),
30
+ * the inverse of `write-policy-permission.ts` and the route that closes the gap `Roles.tsx`'s own
31
+ * header comment flagged: until now a policy's permission set was append-only, and the only way to
32
+ * shrink it was `DELETE_POLICY` + recreate — which INV-09 refuses outright the moment any role or
33
+ * principal references the policy.
34
+ *
35
+ * Gated by `role.manage`, exactly as the ADD route is. A built-in or frozen parent policy is
36
+ * refused `VALIDATION_ERROR` (INV-06/AC-26); a permission id that is absent — or that belongs to a
37
+ * different policy — is `RESOURCE_NOT_FOUND`, never a silent no-op success (the service proves
38
+ * membership from the policy's own rows before deleting).
39
+ *
40
+ * Returns 204, matching `delete-policy.ts`'s convention for a delete with nothing to echo back —
41
+ * as an explicit bodiless `routeReply`, so the host writes a bare `send()` (the hand-written
42
+ * route's `res.status(204).send()`), never a JSON body.
43
+ */
44
+ export const policyPermissionRemoveRoute = defineJsonRoute({
45
+ method: "delete",
46
+ path: "/api/admin/v1/workspaces/:workspaceId/policies/:policyId/permissions/:policyPermissionId",
47
+ parse: (raw) => ok({ value: {
48
+ policyId: accessPathParam({ params: raw.params, name: "policyId" }),
49
+ policyPermissionId: accessPathParam({ params: raw.params, name: "policyPermissionId" }),
50
+ } }),
51
+ handle: async ({ input, deps, context }) => {
52
+ const callerPrincipalId = accessActorId({ context });
53
+ try {
54
+ await removeInTransaction({ deps, input, callerPrincipalId });
55
+ return ok({ value: routeReply({ status: 204 }) });
56
+ }
57
+ catch (err) {
58
+ return rejectAccessError({ err, mappings: POLICY_PERMISSION_REMOVE_ERRORS });
59
+ }
60
+ },
61
+ });
62
+ //# sourceMappingURL=remove-policy-permission.js.map
@@ -0,0 +1,33 @@
1
+ import type { resetUserPassword } from "../../../server/admin-crud-service.js";
2
+ import type { assertCallerHasAnyPermission } from "../../../server/grant-service.js";
3
+ import { type AssertUserAccountActionFn, type HostErrorPredicate, type IdentityServicesFn, type IsInTrashFn, type UserRoutePrincipal } from "./shared.js";
4
+ /** The deps this route reads. */
5
+ export interface UserResetPasswordRouteDeps {
6
+ workspaceId: string;
7
+ /** Identity service(s), injected: the admin-http entry may not reach the `server` source domain
8
+ * (subpath isolation); the host binds them from `@jini-ai/user-management/server`. */
9
+ resetUserPassword: typeof resetUserPassword;
10
+ assertCallerHasAnyPermission: typeof assertCallerHasAnyPermission;
11
+ identityServices: IdentityServicesFn;
12
+ isInTrash: IsInTrashFn;
13
+ /** The seeded (bootstrap) owner's principal id, resolved by the host at boot. */
14
+ ownerPrincipalId: PromiseLike<string> | string;
15
+ assertUserAccountAction: AssertUserAccountActionFn;
16
+ /** Matches the host's "user is in the Trash" error, which its Trash index may throw itself. */
17
+ isUserInTrashError: HostErrorPredicate;
18
+ /** Matches the host's self-target error. */
19
+ isSelfDeleteError: HostErrorPredicate;
20
+ }
21
+ /**
22
+ * POST users/:principalId/reset-password — `RESET_USER_PASSWORD` (SPEC-006 0.6.0, REQ-17). Gated
23
+ * by **`user.manage`** only (stricter than `UPDATE_USER`). No response body — the raw new password
24
+ * is never echoed back (INV-05); revokes every one of the target's active sessions (AC-29). Refuses
25
+ * a THIRD-PARTY caller resetting the seeded owner's password (REQ-11/REQ-13) — the owner may still
26
+ * reset its own — see `server/admin-crud-service.ts`'s `resetUserPassword` for the full contract;
27
+ * `seededOwnerPrincipalId` is resolved exactly as the disable route resolves it.
28
+ */
29
+ export declare const userResetPasswordRoute: import("@jini-ai/core/contracts/server").JsonRouteSpec<{
30
+ principalId: string;
31
+ password: string;
32
+ }, undefined, UserResetPasswordRouteDeps, UserRoutePrincipal>;
33
+ //# sourceMappingURL=reset-password.d.ts.map
@@ -0,0 +1,52 @@
1
+ import { defineJsonRoute, ok } from "@jini-ai/core/contracts/server";
2
+ import { hostRung, principalIdParam, rejectUserError, rejectUserInTrash, USER_FORBIDDEN, USER_NOT_FOUND, USER_OWNER_REQUIRED, USER_VALIDATION, userActorId, } from "./shared.js";
3
+ /**
4
+ * This route's ladder, in the hand-written order. The host's account guard deliberately exempts
5
+ * `reset-password` from its self-target refusal (the owner may reset its own password), so no
6
+ * current path raises the self-target error here — the rung stays as defence-in-depth should that
7
+ * exemption change. @complexity O(1).
8
+ */
9
+ function resetPasswordErrors({ deps }, _optional = {}) {
10
+ return [hostRung({ matches: deps.isUserInTrashError, status: 409, code: "USER_IN_TRASH" }), hostRung({ matches: deps.isSelfDeleteError, status: 409, code: "SELF_DELETE" }), USER_FORBIDDEN, USER_OWNER_REQUIRED, USER_VALIDATION, USER_NOT_FOUND];
11
+ }
12
+ /**
13
+ * POST users/:principalId/reset-password — `RESET_USER_PASSWORD` (SPEC-006 0.6.0, REQ-17). Gated
14
+ * by **`user.manage`** only (stricter than `UPDATE_USER`). No response body — the raw new password
15
+ * is never echoed back (INV-05); revokes every one of the target's active sessions (AC-29). Refuses
16
+ * a THIRD-PARTY caller resetting the seeded owner's password (REQ-11/REQ-13) — the owner may still
17
+ * reset its own — see `server/admin-crud-service.ts`'s `resetUserPassword` for the full contract;
18
+ * `seededOwnerPrincipalId` is resolved exactly as the disable route resolves it.
19
+ */
20
+ export const userResetPasswordRoute = defineJsonRoute({
21
+ method: "post",
22
+ path: "/api/admin/v1/workspaces/:workspaceId/users/:principalId/reset-password",
23
+ parse: (raw) => {
24
+ const body = (raw.body ?? {});
25
+ return ok({ value: { principalId: principalIdParam(raw.params), password: String(body.password ?? "") } });
26
+ },
27
+ handle: async ({ input, deps, context }) => {
28
+ const callerPrincipalId = userActorId({ context });
29
+ const { workspaceId } = deps;
30
+ const { principalId, password } = input;
31
+ try {
32
+ const seededOwnerPrincipalId = await deps.ownerPrincipalId;
33
+ const services = deps.identityServices();
34
+ // B152: Trash membership is private too — check the caller's permission BEFORE looking it up,
35
+ // as `enable.ts` does, so a caller without `user.manage` gets 403, not a 409 that reveals it.
36
+ await deps.assertCallerHasAnyPermission({ deps: services, workspaceId, callerPrincipalId, permissions: ["user.manage"] });
37
+ // OWNER DECISION 2026-09-24 (delete-user plan v2, decision 7) — refuse BEFORE the transition;
38
+ // see `rejectUserInTrash` for why. Not a rung, so `rejectUserError` rethrows it unchanged.
39
+ if (await deps.isInTrash({ principalId }))
40
+ rejectUserInTrash();
41
+ await services.repos.transactions.run({ workspaceId, execute: async () => {
42
+ await deps.assertUserAccountAction({ deps: services, workspaceId, principalId, action: "reset-password" }, { callerPrincipalId, seededOwnerPrincipalId });
43
+ return deps.resetUserPassword({ deps: services, input: { workspaceId, callerPrincipalId, principalId, password, seededOwnerPrincipalId } });
44
+ } });
45
+ return ok({ value: undefined });
46
+ }
47
+ catch (err) {
48
+ return rejectUserError({ err, rungs: resetPasswordErrors({ deps }) });
49
+ }
50
+ },
51
+ }, { successStatus: 204 });
52
+ //# sourceMappingURL=reset-password.js.map
@@ -0,0 +1,124 @@
1
+ import type { IdentityRepos } from "../../../core/ports.js";
2
+ import { type PrincipalRecord, type UserRecord } from "../../../core/types.js";
3
+ import type { AuthServiceDeps } from "../../../server/auth-service.js";
4
+ import { type AdminUserResponse } from "../../http/users.js";
5
+ /**
6
+ * @file Shared guards and error mapping for the users (principal) admin route specs.
7
+ *
8
+ * Each hand-written users route had its own `if (err instanceof X) res.status(...)` ladder. The
9
+ * specs keep each route's exact ladder as an ordered list of rungs (a route lists only the classes
10
+ * it always mapped, in its own order), and the host's `onError` port writes the thrown refusal flat,
11
+ * so every body stays byte-identical — `{ error, code?, details? }` in that key order.
12
+ *
13
+ * Authorization for these routes lives in the identity services (`createUser`, `assignRole`, …
14
+ * check the caller's grants themselves), not in a route-level `authorize` call; the specs only read
15
+ * the caller's id. Host-owned error classes (the Trash/self-target errors) reach the specs as injected
16
+ * predicates, so the engine never imports the host's classes.
17
+ */
18
+ /** The principal fields these routes read: only the id, as the caller of every identity service. */
19
+ export interface UserRoutePrincipal {
20
+ id: string;
21
+ }
22
+ /** Builds the identity services' deps bag per request (the host's assembler over its repo fields). */
23
+ export type IdentityServicesFn = (required?: Record<string, never>) => AuthServiceDeps;
24
+ /** Whether a thrown error is one of the host's own error classes (the engine cannot `instanceof` them). */
25
+ export type HostErrorPredicate = (required: {
26
+ err: unknown;
27
+ }, optional?: Record<string, never>) => boolean;
28
+ /** Is this principal currently in the host's Trash? (`trashed_items` membership, host-owned.) */
29
+ export type IsInTrashFn = (required: {
30
+ principalId: string;
31
+ }, optional?: Record<string, never>) => Promise<boolean>;
32
+ /**
33
+ * The host's account-protection guard run before a disable or password reset (seeded owner,
34
+ * last-owner and admin/owner-target rules). It throws the host's self-target error, which the route
35
+ * maps through {@link HostErrorPredicate}, or the identity errors the rungs below already map.
36
+ */
37
+ export type AssertUserAccountActionFn = (required: {
38
+ deps: AuthServiceDeps;
39
+ workspaceId: string;
40
+ principalId: string;
41
+ action: "disable" | "reset-password" | "enable";
42
+ }, optional: {
43
+ callerPrincipalId: string;
44
+ seededOwnerPrincipalId: string;
45
+ }) => Promise<void>;
46
+ /** One `catch` rung: which thrown error maps to which status, and the body's optional code/details. */
47
+ export interface UserErrorRung {
48
+ readonly matches: (required: {
49
+ err: unknown;
50
+ }, optional?: Record<string, never>) => boolean;
51
+ readonly status: number;
52
+ readonly code?: string | ((required: {
53
+ err: unknown;
54
+ }) => string);
55
+ readonly details?: (required: {
56
+ err: unknown;
57
+ }) => unknown;
58
+ }
59
+ export declare const USER_FORBIDDEN: UserErrorRung;
60
+ export declare const USER_GRANT_EXCEEDS_ISSUER: UserErrorRung;
61
+ export declare const USER_VALIDATION: UserErrorRung;
62
+ export declare const USER_NOT_FOUND: UserErrorRung;
63
+ /** assign-role/attach-policy always answered a missing role/policy/principal without a code. */
64
+ export declare const USER_NOT_FOUND_CODELESS: UserErrorRung;
65
+ export declare const USER_OWNER_REQUIRED: UserErrorRung;
66
+ /** create's username conflict: always `RESOURCE_CONFLICT`, whatever code the service attached. */
67
+ export declare const USER_USERNAME_CONFLICT: UserErrorRung;
68
+ /** update's conflict keeps the service's own code (a rename onto a trashed holder is `USER_IN_TRASH`). */
69
+ export declare const USER_CONFLICT_OWN_CODE: UserErrorRung;
70
+ /** A rung for a host-owned error class, matched through its injected predicate. @complexity O(1). */
71
+ export declare function hostRung(required: {
72
+ matches: HostErrorPredicate;
73
+ status: number;
74
+ code?: string;
75
+ }, _optional?: Record<string, never>): UserErrorRung;
76
+ /**
77
+ * Refuses with the first matching rung's status and the error's own message; anything unmapped is
78
+ * rethrown unchanged — including a refusal the route already threw — so the host's error port
79
+ * answers it (an unexpected failure as the redacted 500).
80
+ * @complexity O(n) in the rung list length, a small fixed list per route.
81
+ */
82
+ export declare function rejectUserError({ err, rungs }: {
83
+ err: unknown;
84
+ rungs: readonly UserErrorRung[];
85
+ }, _optional?: Record<string, never>): never;
86
+ /**
87
+ * The 409 a Trash-member target gets from enable/update/reset-password (delete-user plan v2,
88
+ * decision 7): refused BEFORE the transition — re-activating or editing a trashed principal would
89
+ * leave an ACTIVE user still indexed for purge.
90
+ */
91
+ export declare function rejectUserInTrash(_required?: Record<string, never>, _optional?: Record<string, never>): never;
92
+ /**
93
+ * The authenticated caller's id. The host defers a missing session to the route, so a mount without
94
+ * a principal is a wiring bug that fails closed as the host's redacted 500, as `getAuthedPrincipal` did.
95
+ * @complexity O(1).
96
+ */
97
+ export declare function userActorId({ context }: {
98
+ context: UserRoutePrincipal | undefined;
99
+ }, _optional?: Record<string, never>): string;
100
+ /** The `:principalId` path segment; Express always fills it, the `?? ""` mirrors the host's own guard. @complexity O(1). */
101
+ export declare function principalIdParam(params: Record<string, string | undefined>): string;
102
+ /**
103
+ * Builds the admin user shape for `principal` + its paired `user` row, reading the role/policy links.
104
+ * The identity mutations return only one of the two records, so callers fetch the other first.
105
+ * @complexity O(1) plus two repo reads.
106
+ */
107
+ export declare function adminUserWithGrants({ repos, workspaceId, principal, user }: {
108
+ repos: Pick<IdentityRepos, "principalRoles" | "principalPolicies">;
109
+ workspaceId: string;
110
+ principal: PrincipalRecord;
111
+ user: UserRecord;
112
+ }, _optional?: Record<string, never>): Promise<AdminUserResponse>;
113
+ /**
114
+ * The admin user for a principal a mutation just returned. Every `kind='user'` principal has a paired
115
+ * `UserRecord` by construction (CREATE_USER's atomicity guarantee), so the missing-user throw is
116
+ * defensive, not an expected runtime path; it maps to the route's 404 like any not-found.
117
+ * @complexity O(1) plus three repo reads.
118
+ */
119
+ export declare function adminUserForPrincipal({ repos, workspaceId, principal }: {
120
+ repos: Pick<IdentityRepos, "users" | "principalRoles" | "principalPolicies">;
121
+ workspaceId: string;
122
+ principal: PrincipalRecord;
123
+ }, _optional?: Record<string, never>): Promise<AdminUserResponse>;
124
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1,93 @@
1
+ import { RouteRefusalError } from "@jini-ai/core/errors/route-refusal";
2
+ import { GrantExceedsIssuerError, IdentityConflictError, IdentityForbiddenError, IdentityNotFoundError, IdentityValidationError, OwnerRequiredError, } from "../../../core/types.js";
3
+ import { toAdminUserResponse } from "../../http/users.js";
4
+ export const USER_FORBIDDEN = {
5
+ matches: ({ err }) => err instanceof IdentityForbiddenError, status: 403, code: "FORBIDDEN",
6
+ details: ({ err }) => ({ permission: err.permission, reason: err.reason }),
7
+ };
8
+ export const USER_GRANT_EXCEEDS_ISSUER = {
9
+ matches: ({ err }) => err instanceof GrantExceedsIssuerError, status: 403, code: "GRANT_EXCEEDS_ISSUER",
10
+ details: ({ err }) => ({ offendingPermissions: err.offendingPermissions }),
11
+ };
12
+ export const USER_VALIDATION = { matches: ({ err }) => err instanceof IdentityValidationError, status: 400, code: "VALIDATION_ERROR" };
13
+ export const USER_NOT_FOUND = { matches: ({ err }) => err instanceof IdentityNotFoundError, status: 404, code: "RESOURCE_NOT_FOUND" };
14
+ /** assign-role/attach-policy always answered a missing role/policy/principal without a code. */
15
+ export const USER_NOT_FOUND_CODELESS = { matches: ({ err }) => err instanceof IdentityNotFoundError, status: 404 };
16
+ export const USER_OWNER_REQUIRED = { matches: ({ err }) => err instanceof OwnerRequiredError, status: 409, code: "OWNER_REQUIRED" };
17
+ /** create's username conflict: always `RESOURCE_CONFLICT`, whatever code the service attached. */
18
+ export const USER_USERNAME_CONFLICT = {
19
+ matches: ({ err }) => err instanceof IdentityConflictError, status: 409, code: "RESOURCE_CONFLICT", details: () => ({ field: "username" }),
20
+ };
21
+ /** update's conflict keeps the service's own code (a rename onto a trashed holder is `USER_IN_TRASH`). */
22
+ export const USER_CONFLICT_OWN_CODE = {
23
+ matches: ({ err }) => err instanceof IdentityConflictError, status: 409,
24
+ code: ({ err }) => err.code ?? "RESOURCE_CONFLICT", details: () => ({ field: "username" }),
25
+ };
26
+ /** A rung for a host-owned error class, matched through its injected predicate. @complexity O(1). */
27
+ export function hostRung(required, _optional = {}) {
28
+ return required.code === undefined ? { matches: required.matches, status: required.status } : { matches: required.matches, status: required.status, code: required.code };
29
+ }
30
+ /**
31
+ * Refuses with the first matching rung's status and the error's own message; anything unmapped is
32
+ * rethrown unchanged — including a refusal the route already threw — so the host's error port
33
+ * answers it (an unexpected failure as the redacted 500).
34
+ * @complexity O(n) in the rung list length, a small fixed list per route.
35
+ */
36
+ export function rejectUserError({ err, rungs }, _optional = {}) {
37
+ const rung = rungs.find((candidate) => candidate.matches({ err }));
38
+ if (!rung)
39
+ throw err;
40
+ const body = { error: err instanceof Error ? err.message : String(err) };
41
+ if (rung.code !== undefined)
42
+ body.code = typeof rung.code === "function" ? rung.code({ err }) : rung.code;
43
+ if (rung.details)
44
+ body.details = rung.details({ err });
45
+ throw new RouteRefusalError({ status: rung.status, body });
46
+ }
47
+ /**
48
+ * The 409 a Trash-member target gets from enable/update/reset-password (delete-user plan v2,
49
+ * decision 7): refused BEFORE the transition — re-activating or editing a trashed principal would
50
+ * leave an ACTIVE user still indexed for purge.
51
+ */
52
+ export function rejectUserInTrash(_required = {}, _optional = {}) {
53
+ throw new RouteRefusalError({ status: 409, body: { error: "this user is in the Trash; restore them first", code: "USER_IN_TRASH" } });
54
+ }
55
+ /**
56
+ * The authenticated caller's id. The host defers a missing session to the route, so a mount without
57
+ * a principal is a wiring bug that fails closed as the host's redacted 500, as `getAuthedPrincipal` did.
58
+ * @complexity O(1).
59
+ */
60
+ export function userActorId({ context }, _optional = {}) {
61
+ if (!context)
62
+ throw new Error("users admin route has no authenticated principal");
63
+ return context.id;
64
+ }
65
+ /** The `:principalId` path segment; Express always fills it, the `?? ""` mirrors the host's own guard. @complexity O(1). */
66
+ export function principalIdParam(params) {
67
+ return String(params.principalId ?? "");
68
+ }
69
+ /**
70
+ * Builds the admin user shape for `principal` + its paired `user` row, reading the role/policy links.
71
+ * The identity mutations return only one of the two records, so callers fetch the other first.
72
+ * @complexity O(1) plus two repo reads.
73
+ */
74
+ export async function adminUserWithGrants({ repos, workspaceId, principal, user }, _optional = {}) {
75
+ const [roleLinks, policyLinks] = await Promise.all([
76
+ repos.principalRoles.listByPrincipalId({ workspaceId, principalId: principal.id }),
77
+ repos.principalPolicies.listByPrincipalId({ workspaceId, principalId: principal.id }),
78
+ ]);
79
+ return toAdminUserResponse({ principal, user, roleIds: roleLinks.map((link) => link.roleId), policyIds: policyLinks.map((link) => link.policyId) });
80
+ }
81
+ /**
82
+ * The admin user for a principal a mutation just returned. Every `kind='user'` principal has a paired
83
+ * `UserRecord` by construction (CREATE_USER's atomicity guarantee), so the missing-user throw is
84
+ * defensive, not an expected runtime path; it maps to the route's 404 like any not-found.
85
+ * @complexity O(1) plus three repo reads.
86
+ */
87
+ export async function adminUserForPrincipal({ repos, workspaceId, principal }, _optional = {}) {
88
+ const user = await repos.users.findByPrincipalId({ workspaceId, principalId: principal.id });
89
+ if (!user)
90
+ throw new IdentityNotFoundError({ message: `user '${principal.id}' was not found` });
91
+ return adminUserWithGrants({ repos, workspaceId, principal, user });
92
+ }
93
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1,25 @@
1
+ import type { updatePolicy } from "../../../server/admin-crud-service.js";
2
+ import { type AdminPolicyResponse } from "../../http/users.js";
3
+ import { type AccessRoutePrincipal, type AccessServiceRouteDeps } from "./access-shared.js";
4
+ /** The deps this route reads: the workspace, the identity services' deps bag and the service it calls. */
5
+ export interface PolicyUpdateRouteDeps extends AccessServiceRouteDeps {
6
+ /** Injected: the service lives in the node `./server` entry; the host binds it. */
7
+ updatePolicy: typeof updatePolicy;
8
+ }
9
+ /** The two writable PATCH fields — `undefined` means "leave unchanged" — plus the target id. */
10
+ interface PolicyUpdateInput {
11
+ policyId: string;
12
+ name: string | undefined;
13
+ description: string | undefined;
14
+ expectedVersion?: unknown;
15
+ }
16
+ /**
17
+ * PATCH policies/:policyId — `UPDATE_POLICY` (SPEC-006 0.6.0, REQ-18) — rename/re-describe a
18
+ * non-built-in, non-frozen policy. Gated by `role.manage`; a built-in or frozen target is refused
19
+ * `VALIDATION_ERROR` (INV-06/AC-26, AC-30).
20
+ */
21
+ export declare const policyUpdateRoute: import("@jini-ai/core/contracts/server").JsonRouteSpec<PolicyUpdateInput, {
22
+ policy: AdminPolicyResponse;
23
+ }, PolicyUpdateRouteDeps, AccessRoutePrincipal>;
24
+ export {};
25
+ //# sourceMappingURL=update-policy.d.ts.map
@@ -0,0 +1,30 @@
1
+ import { defineJsonRoute, ok } from "@jini-ai/core/contracts/server";
2
+ import { toAdminPolicyResponse } from "../../http/users.js";
3
+ import { ACCESS_FORBIDDEN, ACCESS_VERSION_CONFLICT, accessExpectedVersion, ACCESS_NOT_FOUND, ACCESS_VALIDATION, accessActorId, accessBody, accessPathParam, optionalString, rejectAccessError, } from "./access-shared.js";
4
+ const POLICY_UPDATE_ERRORS = [ACCESS_VERSION_CONFLICT, ACCESS_FORBIDDEN, ACCESS_VALIDATION, ACCESS_NOT_FOUND];
5
+ /**
6
+ * PATCH policies/:policyId — `UPDATE_POLICY` (SPEC-006 0.6.0, REQ-18) — rename/re-describe a
7
+ * non-built-in, non-frozen policy. Gated by `role.manage`; a built-in or frozen target is refused
8
+ * `VALIDATION_ERROR` (INV-06/AC-26, AC-30).
9
+ */
10
+ export const policyUpdateRoute = defineJsonRoute({
11
+ method: "patch",
12
+ path: "/api/admin/v1/workspaces/:workspaceId/policies/:policyId",
13
+ parse: (raw) => {
14
+ const body = accessBody({ body: raw.body });
15
+ return ok({ value: { policyId: accessPathParam({ params: raw.params, name: "policyId" }), name: optionalString({ value: body.name }), description: optionalString({ value: body.description }), expectedVersion: body.expectedVersion } });
16
+ },
17
+ handle: async ({ input, deps, context }) => {
18
+ const callerPrincipalId = accessActorId({ context });
19
+ // Outside the `try`: a malformed basis is a 400 refusal, not a service error to map.
20
+ const expectedVersion = accessExpectedVersion({ value: input.expectedVersion });
21
+ try {
22
+ const { policy } = await deps.updatePolicy({ deps: deps.identityServiceDeps(), input: { workspaceId: deps.workspaceId, callerPrincipalId, policyId: input.policyId } }, { name: input.name, description: input.description, expectedVersion });
23
+ return ok({ value: { policy: toAdminPolicyResponse(policy) } });
24
+ }
25
+ catch (err) {
26
+ return rejectAccessError({ err, mappings: POLICY_UPDATE_ERRORS });
27
+ }
28
+ },
29
+ });
30
+ //# sourceMappingURL=update-policy.js.map
@@ -0,0 +1,23 @@
1
+ import type { updateRole } from "../../../server/admin-crud-service.js";
2
+ import { type AdminRoleResponse } from "../../http/users.js";
3
+ import { type AccessRoutePrincipal, type AccessServiceRouteDeps } from "./access-shared.js";
4
+ /** The deps this route reads: the workspace, the identity services' deps bag and the service it calls. */
5
+ export interface RoleUpdateRouteDeps extends AccessServiceRouteDeps {
6
+ /** Injected: the service lives in the node `./server` entry; the host binds it. */
7
+ updateRole: typeof updateRole;
8
+ }
9
+ /** The PATCH target and new name, plus the editor basis exactly as the client sent it (parsed in `handle`). */
10
+ interface RoleUpdateInput {
11
+ roleId: string;
12
+ name: string;
13
+ expectedVersion?: unknown;
14
+ }
15
+ /**
16
+ * PATCH roles/:roleId — `UPDATE_ROLE` (SPEC-006 0.6.0, REQ-18) — rename a non-built-in role. Gated
17
+ * by `role.manage`; a built-in target is refused `VALIDATION_ERROR` (INV-06 extended, AC-30).
18
+ */
19
+ export declare const roleUpdateRoute: import("@jini-ai/core/contracts/server").JsonRouteSpec<RoleUpdateInput, {
20
+ role: AdminRoleResponse;
21
+ }, RoleUpdateRouteDeps, AccessRoutePrincipal>;
22
+ export {};
23
+ //# sourceMappingURL=update-role.d.ts.map
@@ -0,0 +1,29 @@
1
+ import { defineJsonRoute, ok } from "@jini-ai/core/contracts/server";
2
+ import { toAdminRoleResponse } from "../../http/users.js";
3
+ import { ACCESS_FORBIDDEN, ACCESS_VERSION_CONFLICT, accessExpectedVersion, ACCESS_NOT_FOUND, ACCESS_VALIDATION, accessActorId, accessBody, accessPathParam, rejectAccessError, } from "./access-shared.js";
4
+ const ROLE_UPDATE_ERRORS = [ACCESS_VERSION_CONFLICT, ACCESS_FORBIDDEN, ACCESS_VALIDATION, ACCESS_NOT_FOUND];
5
+ /**
6
+ * PATCH roles/:roleId — `UPDATE_ROLE` (SPEC-006 0.6.0, REQ-18) — rename a non-built-in role. Gated
7
+ * by `role.manage`; a built-in target is refused `VALIDATION_ERROR` (INV-06 extended, AC-30).
8
+ */
9
+ export const roleUpdateRoute = defineJsonRoute({
10
+ method: "patch",
11
+ path: "/api/admin/v1/workspaces/:workspaceId/roles/:roleId",
12
+ parse: (raw) => {
13
+ const body = accessBody({ body: raw.body });
14
+ return ok({ value: { roleId: accessPathParam({ params: raw.params, name: "roleId" }), name: String(body.name ?? ""), expectedVersion: body.expectedVersion } });
15
+ },
16
+ handle: async ({ input, deps, context }) => {
17
+ const callerPrincipalId = accessActorId({ context });
18
+ // Outside the `try`: a malformed basis is a 400 refusal, not a service error to map.
19
+ const expectedVersion = accessExpectedVersion({ value: input.expectedVersion });
20
+ try {
21
+ const { role } = await deps.updateRole({ deps: deps.identityServiceDeps(), input: { workspaceId: deps.workspaceId, callerPrincipalId, roleId: input.roleId, name: input.name } }, { expectedVersion });
22
+ return ok({ value: { role: toAdminRoleResponse(role) } });
23
+ }
24
+ catch (err) {
25
+ return rejectAccessError({ err, mappings: ROLE_UPDATE_ERRORS });
26
+ }
27
+ },
28
+ });
29
+ //# sourceMappingURL=update-role.js.map