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

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 (377) hide show
  1. package/README.md +55 -2
  2. package/dist/admin/adapters/memory.js +4 -4
  3. package/dist/admin-http/auth/auth-request.d.ts +112 -0
  4. package/dist/admin-http/auth/auth-request.js +32 -0
  5. package/dist/admin-http/auth/boot-redemption.d.ts +9 -0
  6. package/dist/admin-http/auth/boot-redemption.js +17 -0
  7. package/dist/admin-http/auth/boot-session.d.ts +30 -0
  8. package/dist/admin-http/auth/boot-session.js +40 -0
  9. package/dist/admin-http/auth/current-user.d.ts +28 -0
  10. package/dist/admin-http/auth/current-user.js +34 -0
  11. package/dist/admin-http/auth/index.d.ts +17 -0
  12. package/dist/admin-http/auth/index.js +9 -0
  13. package/dist/admin-http/auth/local-boot-session.d.ts +9 -0
  14. package/dist/admin-http/auth/local-boot-session.js +30 -0
  15. package/dist/admin-http/auth/logout.d.ts +10 -0
  16. package/dist/admin-http/auth/logout.js +17 -0
  17. package/dist/admin-http/auth/mfa-login.d.ts +30 -0
  18. package/dist/admin-http/auth/mfa-login.js +43 -0
  19. package/dist/admin-http/auth/password-login.d.ts +35 -0
  20. package/dist/admin-http/auth/password-login.js +52 -0
  21. package/dist/admin-http/auth/password-status.d.ts +34 -0
  22. package/dist/admin-http/auth/password-status.js +42 -0
  23. package/dist/admin-http/http/api-keys.d.ts +45 -0
  24. package/dist/admin-http/http/api-keys.js +28 -0
  25. package/dist/admin-http/http/users.d.ts +71 -0
  26. package/dist/admin-http/http/users.js +42 -0
  27. package/dist/admin-http/owner/mfa-deps.d.ts +41 -0
  28. package/dist/admin-http/owner/mfa-deps.js +26 -0
  29. package/dist/admin-http/owner/mfa-routes.d.ts +72 -0
  30. package/dist/admin-http/owner/mfa-routes.js +105 -0
  31. package/dist/admin-http/owner/passkey-admission.d.ts +46 -0
  32. package/dist/admin-http/owner/passkey-admission.js +23 -0
  33. package/dist/admin-http/owner/passkey-route-deps.d.ts +53 -0
  34. package/dist/admin-http/owner/passkey-route-deps.js +33 -0
  35. package/dist/admin-http/owner/passkey-routes.d.ts +146 -0
  36. package/dist/admin-http/owner/passkey-routes.js +98 -0
  37. package/dist/admin-http/owner/recovery-routes.d.ts +71 -0
  38. package/dist/admin-http/owner/recovery-routes.js +112 -0
  39. package/dist/admin-http/routes/api-keys/create-principal.d.ts +26 -0
  40. package/dist/admin-http/routes/api-keys/create-principal.js +37 -0
  41. package/dist/admin-http/routes/api-keys/issue.d.ts +32 -0
  42. package/dist/admin-http/routes/api-keys/issue.js +38 -0
  43. package/dist/admin-http/routes/api-keys/revoke.d.ts +26 -0
  44. package/dist/admin-http/routes/api-keys/revoke.js +31 -0
  45. package/dist/admin-http/routes/api-keys/shared.d.ts +46 -0
  46. package/dist/admin-http/routes/api-keys/shared.js +38 -0
  47. package/dist/admin-http/routes/users/access-shared.d.ts +103 -0
  48. package/dist/admin-http/routes/users/access-shared.js +85 -0
  49. package/dist/admin-http/routes/users/assign-role.d.ts +24 -0
  50. package/dist/admin-http/routes/users/assign-role.js +30 -0
  51. package/dist/admin-http/routes/users/attach-policy.d.ts +25 -0
  52. package/dist/admin-http/routes/users/attach-policy.js +31 -0
  53. package/dist/admin-http/routes/users/create-policy.d.ts +19 -0
  54. package/dist/admin-http/routes/users/create-policy.js +28 -0
  55. package/dist/admin-http/routes/users/create-role.d.ts +15 -0
  56. package/dist/admin-http/routes/users/create-role.js +21 -0
  57. package/dist/admin-http/routes/users/create.d.ts +32 -0
  58. package/dist/admin-http/routes/users/create.js +67 -0
  59. package/dist/admin-http/routes/users/delete-policy.d.ts +16 -0
  60. package/dist/admin-http/routes/users/delete-policy.js +24 -0
  61. package/dist/admin-http/routes/users/delete-role.d.ts +16 -0
  62. package/dist/admin-http/routes/users/delete-role.js +24 -0
  63. package/dist/admin-http/routes/users/delete.d.ts +35 -0
  64. package/dist/admin-http/routes/users/delete.js +35 -0
  65. package/dist/admin-http/routes/users/disable.d.ts +31 -0
  66. package/dist/admin-http/routes/users/disable.js +38 -0
  67. package/dist/admin-http/routes/users/enable.d.ts +32 -0
  68. package/dist/admin-http/routes/users/enable.js +45 -0
  69. package/dist/admin-http/routes/users/list-policies.d.ts +18 -0
  70. package/dist/admin-http/routes/users/list-policies.js +20 -0
  71. package/dist/admin-http/routes/users/list-policy-permissions.d.ts +28 -0
  72. package/dist/admin-http/routes/users/list-policy-permissions.js +30 -0
  73. package/dist/admin-http/routes/users/list-roles.d.ts +18 -0
  74. package/dist/admin-http/routes/users/list-roles.js +20 -0
  75. package/dist/admin-http/routes/users/list.d.ts +40 -0
  76. package/dist/admin-http/routes/users/list.js +82 -0
  77. package/dist/admin-http/routes/users/remove-policy-permission.d.ts +48 -0
  78. package/dist/admin-http/routes/users/remove-policy-permission.js +62 -0
  79. package/dist/admin-http/routes/users/reset-password.d.ts +33 -0
  80. package/dist/admin-http/routes/users/reset-password.js +52 -0
  81. package/dist/admin-http/routes/users/shared.d.ts +124 -0
  82. package/dist/admin-http/routes/users/shared.js +93 -0
  83. package/dist/admin-http/routes/users/update-policy.d.ts +25 -0
  84. package/dist/admin-http/routes/users/update-policy.js +30 -0
  85. package/dist/admin-http/routes/users/update-role.d.ts +23 -0
  86. package/dist/admin-http/routes/users/update-role.js +29 -0
  87. package/dist/admin-http/routes/users/update.d.ts +35 -0
  88. package/dist/admin-http/routes/users/update.js +78 -0
  89. package/dist/admin-http/routes/users/write-policy-permission.d.ts +31 -0
  90. package/dist/admin-http/routes/users/write-policy-permission.js +45 -0
  91. package/dist/core/ports.d.ts +22 -3
  92. package/dist/core/types.d.ts +17 -5
  93. package/dist/core/types.js +12 -0
  94. package/dist/identity/api-key-secret.d.ts +68 -0
  95. package/dist/identity/api-key-secret.js +229 -0
  96. package/dist/identity/api-key-service.d.ts +144 -0
  97. package/dist/identity/api-key-service.js +389 -0
  98. package/dist/identity/api-key-types.d.ts +79 -0
  99. package/dist/identity/api-key-types.js +2 -0
  100. package/dist/identity/boot-session-token.d.ts +18 -0
  101. package/dist/identity/boot-session-token.js +92 -0
  102. package/dist/identity/builtin-role-grants.d.ts +120 -0
  103. package/dist/identity/builtin-role-grants.js +88 -0
  104. package/dist/identity/delete-user-service.d.ts +195 -0
  105. package/dist/identity/delete-user-service.js +275 -0
  106. package/dist/identity/owner-reset-env.d.ts +37 -0
  107. package/dist/identity/owner-reset-env.js +38 -0
  108. package/dist/identity/permission-grants.d.ts +31 -0
  109. package/dist/identity/permission-grants.js +12 -0
  110. package/dist/identity/permission-list-tool.d.ts +35 -0
  111. package/dist/identity/permission-list-tool.js +47 -0
  112. package/dist/identity/repo.authentication.d.ts +57 -0
  113. package/dist/identity/repo.authentication.js +153 -0
  114. package/dist/identity/repo.authorization.d.ts +82 -0
  115. package/dist/identity/repo.authorization.js +203 -0
  116. package/dist/identity/repo.d.ts +87 -0
  117. package/dist/identity/repo.js +167 -0
  118. package/dist/identity/repo.memory.d.ts +31 -0
  119. package/dist/identity/repo.memory.js +37 -0
  120. package/dist/identity/role-manage-permission.d.ts +34 -0
  121. package/dist/identity/role-manage-permission.js +39 -0
  122. package/dist/identity/site-key-permission.d.ts +66 -0
  123. package/dist/identity/site-key-permission.js +92 -0
  124. package/dist/identity/sql/kernel-user-purge.d.ts +19 -0
  125. package/dist/identity/sql/kernel-user-purge.js +34 -0
  126. package/dist/identity/sql/kernel-user-trash-store.d.ts +15 -0
  127. package/dist/identity/sql/kernel-user-trash-store.js +41 -0
  128. package/dist/identity/sql/user-trash-adapter.d.ts +87 -0
  129. package/dist/identity/sql/user-trash-adapter.js +124 -0
  130. package/dist/identity/tool-registrations.d.ts +100 -0
  131. package/dist/identity/tool-registrations.js +257 -0
  132. package/dist/identity/user-manage-permission.d.ts +8 -0
  133. package/dist/identity/user-manage-permission.js +8 -0
  134. package/dist/identity/user-purge-types.d.ts +85 -0
  135. package/dist/identity/user-purge-types.js +17 -0
  136. package/dist/identity/user-purge.d.ts +69 -0
  137. package/dist/identity/user-purge.js +46 -0
  138. package/dist/identity/username-change-ports.d.ts +15 -0
  139. package/dist/identity/username-change-ports.js +22 -0
  140. package/dist/mail/site/capture-clear.d.ts +58 -0
  141. package/dist/mail/site/capture-clear.js +21 -0
  142. package/dist/mail/status/agent-tools.d.ts +65 -0
  143. package/dist/mail/status/agent-tools.js +22 -0
  144. package/dist/mail/status/delivery-agent-tools.d.ts +206 -0
  145. package/dist/mail/status/delivery-agent-tools.js +63 -0
  146. package/dist/mail/status/delivery-tool-registrations.d.ts +216 -0
  147. package/dist/mail/status/delivery-tool-registrations.js +110 -0
  148. package/dist/mail/status/domain-deps.d.ts +25 -0
  149. package/dist/mail/status/domain-deps.js +23 -0
  150. package/dist/mail/status/permissions.d.ts +43 -0
  151. package/dist/mail/status/permissions.js +45 -0
  152. package/dist/mail/status/provider-agent-tools.d.ts +38 -0
  153. package/dist/mail/status/provider-agent-tools.js +17 -0
  154. package/dist/mail/status/provider-operations.d.ts +166 -0
  155. package/dist/mail/status/provider-operations.js +121 -0
  156. package/dist/mail/status/provider-tool-registrations.d.ts +65 -0
  157. package/dist/mail/status/provider-tool-registrations.js +106 -0
  158. package/dist/mail/status/tool-registrations.d.ts +152 -0
  159. package/dist/mail/status/tool-registrations.js +112 -0
  160. package/dist/member-login/credentials.d.ts +40 -0
  161. package/dist/member-login/credentials.js +26 -0
  162. package/dist/member-login/link-service.d.ts +66 -0
  163. package/dist/member-login/link-service.js +141 -0
  164. package/dist/member-login/oidc-login.d.ts +132 -0
  165. package/dist/member-login/oidc-login.js +206 -0
  166. package/dist/member-login/oidc-request.d.ts +80 -0
  167. package/dist/member-login/oidc-request.js +86 -0
  168. package/dist/member-login/providers.d.ts +79 -0
  169. package/dist/member-login/providers.js +41 -0
  170. package/dist/member-login/ready-providers.d.ts +17 -0
  171. package/dist/member-login/ready-providers.js +11 -0
  172. package/dist/member-login/unlink-identity.d.ts +26 -0
  173. package/dist/member-login/unlink-identity.js +59 -0
  174. package/dist/members/access-resolver.d.ts +107 -0
  175. package/dist/members/access-resolver.js +231 -0
  176. package/dist/members/agent-tools.d.ts +14 -0
  177. package/dist/members/agent-tools.js +139 -0
  178. package/dist/members/auth-mail.d.ts +27 -0
  179. package/dist/members/auth-mail.js +21 -0
  180. package/dist/members/capability-card.d.ts +18 -0
  181. package/dist/members/capability-card.js +27 -0
  182. package/dist/members/consent-service.d.ts +115 -0
  183. package/dist/members/consent-service.js +179 -0
  184. package/dist/members/member-admin-writes.d.ts +73 -0
  185. package/dist/members/member-admin-writes.js +149 -0
  186. package/dist/members/member-challenge-request.d.ts +59 -0
  187. package/dist/members/member-challenge-request.js +145 -0
  188. package/dist/members/member-challenge.d.ts +37 -0
  189. package/dist/members/member-challenge.js +84 -0
  190. package/dist/members/member-credentials.d.ts +35 -0
  191. package/dist/members/member-credentials.js +57 -0
  192. package/dist/members/member-sign-in.d.ts +44 -0
  193. package/dist/members/member-sign-in.js +130 -0
  194. package/dist/members/member-validation.d.ts +5 -0
  195. package/dist/members/member-validation.js +13 -0
  196. package/dist/members/password-auth.d.ts +55 -0
  197. package/dist/members/password-auth.js +177 -0
  198. package/dist/members/ports.d.ts +455 -0
  199. package/dist/members/ports.js +21 -0
  200. package/dist/members/public-member-auth-response.d.ts +68 -0
  201. package/dist/members/public-member-auth-response.js +45 -0
  202. package/dist/members/public-member-response.d.ts +25 -0
  203. package/dist/members/public-member-response.js +15 -0
  204. package/dist/members/repo.d.ts +199 -0
  205. package/dist/members/repo.js +324 -0
  206. package/dist/members/repo.memory.d.ts +276 -0
  207. package/dist/members/repo.memory.js +395 -0
  208. package/dist/members/repo.rows.d.ts +153 -0
  209. package/dist/members/repo.rows.js +250 -0
  210. package/dist/members/repo.sessions.d.ts +80 -0
  211. package/dist/members/repo.sessions.js +166 -0
  212. package/dist/members/repo.sql.d.ts +9 -0
  213. package/dist/members/repo.sql.js +11 -0
  214. package/dist/members/subscriber-directory.d.ts +85 -0
  215. package/dist/members/subscriber-directory.js +70 -0
  216. package/dist/members/tool-registrations.d.ts +143 -0
  217. package/dist/members/tool-registrations.js +247 -0
  218. package/dist/members/trash-member.d.ts +24 -0
  219. package/dist/members/trash-member.js +24 -0
  220. package/dist/members/types.d.ts +321 -0
  221. package/dist/members/types.js +34 -0
  222. package/dist/members/write-service.d.ts +17 -0
  223. package/dist/members/write-service.js +15 -0
  224. package/dist/newsletter/agent-tools.d.ts +20 -0
  225. package/dist/newsletter/agent-tools.js +236 -0
  226. package/dist/newsletter/campaign-write-service.d.ts +92 -0
  227. package/dist/newsletter/campaign-write-service.js +190 -0
  228. package/dist/newsletter/campaign.d.ts +53 -0
  229. package/dist/newsletter/campaign.js +95 -0
  230. package/dist/newsletter/confirmation.d.ts +75 -0
  231. package/dist/newsletter/confirmation.js +142 -0
  232. package/dist/newsletter/data-module-manifest.d.ts +68 -0
  233. package/dist/newsletter/data-module-manifest.js +126 -0
  234. package/dist/newsletter/delivery/tool-registrations.d.ts +67 -0
  235. package/dist/newsletter/delivery/tool-registrations.js +229 -0
  236. package/dist/newsletter/errors.d.ts +93 -0
  237. package/dist/newsletter/errors.js +93 -0
  238. package/dist/newsletter/hooks.d.ts +59 -0
  239. package/dist/newsletter/hooks.js +49 -0
  240. package/dist/newsletter/http-error-responses.d.ts +17 -0
  241. package/dist/newsletter/http-error-responses.js +96 -0
  242. package/dist/newsletter/launch-gate.d.ts +62 -0
  243. package/dist/newsletter/launch-gate.js +29 -0
  244. package/dist/newsletter/lists.d.ts +60 -0
  245. package/dist/newsletter/lists.js +83 -0
  246. package/dist/newsletter/ports.d.ts +278 -0
  247. package/dist/newsletter/ports.js +2 -0
  248. package/dist/newsletter/repo-sends.d.ts +82 -0
  249. package/dist/newsletter/repo-sends.js +178 -0
  250. package/dist/newsletter/repo-subscribers.d.ts +82 -0
  251. package/dist/newsletter/repo-subscribers.js +193 -0
  252. package/dist/newsletter/repo.d.ts +61 -0
  253. package/dist/newsletter/repo.js +147 -0
  254. package/dist/newsletter/repo.memory.d.ts +201 -0
  255. package/dist/newsletter/repo.memory.js +250 -0
  256. package/dist/newsletter/repo.rows.d.ts +221 -0
  257. package/dist/newsletter/repo.rows.js +260 -0
  258. package/dist/newsletter/send-pipeline.d.ts +236 -0
  259. package/dist/newsletter/send-pipeline.js +514 -0
  260. package/dist/newsletter/subscriptions.d.ts +87 -0
  261. package/dist/newsletter/subscriptions.js +119 -0
  262. package/dist/newsletter/tool-registrations.d.ts +89 -0
  263. package/dist/newsletter/tool-registrations.deps.d.ts +9 -0
  264. package/dist/newsletter/tool-registrations.deps.js +9 -0
  265. package/dist/newsletter/tool-registrations.js +133 -0
  266. package/dist/newsletter/tool-registrations.read.d.ts +76 -0
  267. package/dist/newsletter/tool-registrations.read.js +140 -0
  268. package/dist/newsletter/tool-registrations.write.d.ts +54 -0
  269. package/dist/newsletter/tool-registrations.write.js +229 -0
  270. package/dist/newsletter/types.d.ts +279 -0
  271. package/dist/newsletter/types.js +23 -0
  272. package/dist/newsletter/unsubscribe.d.ts +41 -0
  273. package/dist/newsletter/unsubscribe.js +100 -0
  274. package/dist/project-keys/attached-vault.d.ts +23 -0
  275. package/dist/project-keys/attached-vault.js +65 -0
  276. package/dist/project-keys/create-vault.d.ts +17 -0
  277. package/dist/project-keys/create-vault.js +29 -0
  278. package/dist/project-keys/service.d.ts +133 -0
  279. package/dist/project-keys/service.js +128 -0
  280. package/dist/project-keys/site-references.d.ts +30 -0
  281. package/dist/project-keys/site-references.js +63 -0
  282. package/dist/project-keys/site-sealer.d.ts +28 -0
  283. package/dist/project-keys/site-sealer.js +64 -0
  284. package/dist/project-keys/sql/attachments.d.ts +33 -0
  285. package/dist/project-keys/sql/attachments.js +55 -0
  286. package/dist/project-keys/tools.d.ts +86 -0
  287. package/dist/project-keys/tools.js +66 -0
  288. package/dist/public-http/routes/mail/feedback.d.ts +44 -0
  289. package/dist/public-http/routes/mail/feedback.js +17 -0
  290. package/dist/public-http/routes/newsletter/confirm.d.ts +38 -0
  291. package/dist/public-http/routes/newsletter/confirm.js +33 -0
  292. package/dist/public-http/routes/newsletter/page.d.ts +29 -0
  293. package/dist/public-http/routes/newsletter/page.js +34 -0
  294. package/dist/public-http/routes/newsletter/unsubscribe.d.ts +33 -0
  295. package/dist/public-http/routes/newsletter/unsubscribe.js +35 -0
  296. package/dist/react/auth/Passkeys.d.ts +2 -34
  297. package/dist/react/auth/RecoveryCodesCard.d.ts +27 -0
  298. package/dist/react/auth/RecoveryCodesCard.hooks.d.ts +67 -0
  299. package/dist/react/auth/RecoveryCodesCard.hooks.js +38 -0
  300. package/dist/react/auth/RecoveryCodesCard.js +56 -0
  301. package/dist/react/auth/TotpSettings.d.ts +2 -23
  302. package/dist/react/auth/local-owner-signin.d.ts +40 -0
  303. package/dist/react/auth/local-owner-signin.js +25 -0
  304. package/dist/react/auth/owner-mfa-api.d.ts +10 -0
  305. package/dist/react/auth/owner-mfa-api.js +17 -0
  306. package/dist/react/auth/owner-passkey-api.d.ts +11 -0
  307. package/dist/react/auth/owner-passkey-api.js +17 -0
  308. package/dist/react/auth/owner-recovery-api.d.ts +51 -0
  309. package/dist/react/auth/owner-recovery-api.js +29 -0
  310. package/dist/react/auth/owner-request.d.ts +7 -0
  311. package/dist/react/auth/owner-request.js +2 -0
  312. package/dist/react/index.d.ts +10 -0
  313. package/dist/react/index.js +6 -0
  314. package/dist/react/mail/Email.d.ts +20 -0
  315. package/dist/react/mail/Email.js +143 -0
  316. package/dist/react/mail/EmailProviderTab.d.ts +34 -0
  317. package/dist/react/mail/EmailProviderTab.js +132 -0
  318. package/dist/react/mail/EmailSegments.d.ts +24 -0
  319. package/dist/react/mail/EmailSegments.js +15 -0
  320. package/dist/react/mail/EmailTemplateEditor.d.ts +146 -0
  321. package/dist/react/mail/EmailTemplateEditor.js +116 -0
  322. package/dist/react/mail/email-view.types.d.ts +236 -0
  323. package/dist/react/mail/email-view.types.js +2 -0
  324. package/dist/react/members/Members.d.ts +5 -3
  325. package/dist/react/members/Members.js +3 -3
  326. package/dist/react/members/api/members-api.d.ts +37 -0
  327. package/dist/react/members/api/members-api.js +16 -0
  328. package/dist/react/members/hooks/use-members.hooks.js +2 -1
  329. package/dist/react/members/members-i18n.d.ts +23 -0
  330. package/dist/react/members/members-i18n.js +25 -0
  331. package/dist/react/members/members-i18n.locales-a.d.ts +4 -0
  332. package/dist/react/members/members-i18n.locales-a.js +294 -0
  333. package/dist/react/members/members-i18n.locales-b.d.ts +4 -0
  334. package/dist/react/members/members-i18n.locales-b.js +265 -0
  335. package/dist/react/models.d.ts +1 -49
  336. package/dist/react/ports.d.ts +3 -143
  337. package/dist/react/roles/api/roles-api.d.ts +74 -0
  338. package/dist/react/roles/api/roles-api.js +22 -0
  339. package/dist/react/testing.js +18 -9
  340. package/dist/react/users/UsersPanel.d.ts +30 -0
  341. package/dist/react/users/UsersPanel.hooks.d.ts +8 -0
  342. package/dist/react/users/UsersPanel.hooks.js +9 -0
  343. package/dist/react/users/UsersPanel.js +9 -0
  344. package/dist/react/users/api/users-api.d.ts +65 -0
  345. package/dist/react/users/api/users-api.js +46 -0
  346. package/dist/react/users/hooks/use-localized-users.hooks.d.ts +43 -0
  347. package/dist/react/users/hooks/use-localized-users.hooks.js +15 -0
  348. package/dist/react/users/hooks/use-users-state.hooks.d.ts +18 -18
  349. package/dist/react/users/password-reset-notice.d.ts +8 -0
  350. package/dist/react/users/password-reset-notice.js +36 -0
  351. package/dist/server/admin-crud-service.d.ts +4 -10
  352. package/dist/server/admin-crud-service.js +20 -6
  353. package/dist/server/agent-tool-registrations.js +20 -5
  354. package/dist/server/agent-tools.js +16 -3
  355. package/dist/server/auth-challenge.d.ts +1 -1
  356. package/dist/server/auth-service.js +2 -1
  357. package/dist/server/grant-service.d.ts +1 -0
  358. package/dist/server/grant-service.js +7 -4
  359. package/dist/server/mfa/passkey-service.d.ts +2 -2
  360. package/dist/server/mfa/passkey-service.js +1 -1
  361. package/dist/server/mfa/service.js +6 -4
  362. package/dist/server/repo.memory.d.ts +30 -2
  363. package/dist/server/repo.memory.js +58 -4
  364. package/dist/server/seed.js +3 -3
  365. package/dist/server/sql/assignments.d.ts +90 -0
  366. package/dist/server/sql/assignments.js +128 -0
  367. package/dist/server/sql/index.d.ts +6 -0
  368. package/dist/server/sql/index.js +5 -0
  369. package/dist/server/sql/kernel.d.ts +9 -0
  370. package/dist/server/sql/kernel.js +2 -0
  371. package/dist/server/sql/mfa.d.ts +36 -0
  372. package/dist/server/sql/mfa.js +51 -0
  373. package/dist/server/sql/passkeys.d.ts +25 -0
  374. package/dist/server/sql/passkeys.js +33 -0
  375. package/dist/server/sql/recovery-codes.d.ts +22 -0
  376. package/dist/server/sql/recovery-codes.js +32 -0
  377. package/package.json +909 -11
@@ -0,0 +1,87 @@
1
+ import type { TrashAdapter } from "@jini-ai/core/contracts/site/cms-trash";
2
+ import type { DomainEvent } from "@jini-ai/core/contracts/events";
3
+ import type { UserPurgePort } from "../user-purge-types.js";
4
+ /**
5
+ * @file `TrashAdapter` for users (delete-user plan v2, decision 4) — bespoke rather than a
6
+ * `TRASHABLE` registry entry, because `hide` writes two tables (`principals` AND `sessions`) and
7
+ * `purge` must go through `UserPurgePort.purgeUser` (`SqlUserPurge`, `identity/user-purge.ts`) for
8
+ * its own eight-table delete, not through a single-table `compareAndDelete`. Mirrors
9
+ * `@jini-ai/cms/trash/adapters/directory`'s "bespoke adapter" precedent.
10
+ *
11
+ * `entityVersion` is always `null`: `principals` has no version column, so `hide`/`unhide`/`purge`
12
+ * never receive a meaningful `expectedVersion` to compare against (the trash core still passes one
13
+ * through, per the shared `TrashAdapter` contract, but this adapter has nothing to check it against).
14
+ *
15
+ * One Kysely body over the content database's storage kernel, so the same statements run on SQLite,
16
+ * PGlite and Postgres. Each method is read-then-write, so each runs in `kernel.transaction` holding
17
+ * `kernel.lockKey` for the principal (a nested transaction joins the trash core's own). That lock
18
+ * only orders Trash against Trash: `SqlPrincipalRepo.save` never takes it, so on Postgres a
19
+ * re-enable or disable can commit between the read and the write. `hide`/`unhide` therefore repeat
20
+ * the status they read in the `UPDATE`'s `WHERE`, and 0 affected rows is `version-changed` — no
21
+ * stale `priorMarker`, no overwritten status, no event. `hide`/`unhide` insert their own
22
+ * `identity.user.trashed` / `identity.user.restored` outbox event ({@link outboxEventValues}) in that
23
+ * same transaction as the marker write; `purge`'s `purgeUser` joins it too, so the status check and
24
+ * the delete cannot be split by a concurrent restore.
25
+ */
26
+ type Empty = Record<string, never>;
27
+ export interface UserTrashAdapterDeps {
28
+ store: {
29
+ readPrincipal(required: {
30
+ workspaceId: string;
31
+ principalId: string;
32
+ }): Promise<{
33
+ status: string;
34
+ displayName: string;
35
+ } | null>;
36
+ readDisplayUsername(required: {
37
+ workspaceId: string;
38
+ principalId: string;
39
+ fallback: string;
40
+ }): Promise<string>;
41
+ compareAndSetStatus(required: {
42
+ workspaceId: string;
43
+ principalId: string;
44
+ expected: string;
45
+ next: string;
46
+ disabledAt?: string | null;
47
+ }): Promise<number>;
48
+ revokeSessions(required: {
49
+ workspaceId: string;
50
+ principalId: string;
51
+ }): Promise<number>;
52
+ appendEvent(required: {
53
+ event: DomainEvent;
54
+ }): Promise<void>;
55
+ underPrincipalLock<T>(required: {
56
+ workspaceId: string;
57
+ principalId: string;
58
+ run: () => Promise<T>;
59
+ }): Promise<T>;
60
+ };
61
+ policy: {
62
+ entityType: string;
63
+ assertAccountAction?: (required: {
64
+ workspaceId: string;
65
+ principalId: string;
66
+ action: "trash" | "purge";
67
+ }, optional: {
68
+ callerPrincipalId?: string | undefined;
69
+ }) => Promise<void>;
70
+ };
71
+ purge: UserPurgePort;
72
+ idGen: {
73
+ next(): string;
74
+ };
75
+ clock: {
76
+ nowIso(): string;
77
+ };
78
+ }
79
+ /**
80
+ * Builds the user `TrashAdapter`.
81
+ *
82
+ * @complexity O(1) to build; each method is O(1) plus `purge`'s delegated
83
+ * `UserPurgePort.purgeUser` cost (itself O(1), see that file).
84
+ */
85
+ export declare function createUserTrashAdapter(required: UserTrashAdapterDeps, _optional?: Empty): TrashAdapter;
86
+ export {};
87
+ //# sourceMappingURL=user-trash-adapter.d.ts.map
@@ -0,0 +1,124 @@
1
+ function userTrashHide({ policy, store, idGen, clock }) {
2
+ return {
3
+ /**
4
+ * Disables the principal, revokes every session and records `identity.user.trashed`.
5
+ *
6
+ * No idempotency branch for an already-disabled principal: re-trashing one just re-disables it
7
+ * (a no-op write) and reports its current `status` as `priorMarker` again — the "already in the
8
+ * Trash" short-circuit belongs to the caller (`trashUser`, delete-user plan v2 Slice 2), which
9
+ * checks the Trash index before ever reaching this adapter.
10
+ */
11
+ async hide(required, optional = {}) {
12
+ const { workspaceId, entityId } = required;
13
+ return store.underPrincipalLock({ workspaceId, principalId: entityId, run: async () => {
14
+ const before = await store.readPrincipal({ workspaceId, principalId: entityId });
15
+ if (!before)
16
+ return { ok: false, reason: "not-found" };
17
+ await policy.assertAccountAction?.({ workspaceId, principalId: entityId, action: "trash" }, { callerPrincipalId: optional.actor?.principalId });
18
+ const disabled = await store.compareAndSetStatus({ workspaceId, principalId: entityId, expected: before.status, next: "disabled", disabledAt: required.at });
19
+ if (Number(disabled) === 0)
20
+ return { ok: false, reason: "version-changed" };
21
+ const revoked = await store.revokeSessions({ workspaceId, principalId: entityId });
22
+ const username = await store.readDisplayUsername({ workspaceId, principalId: entityId, fallback: before.displayName });
23
+ await store.appendEvent({ event: {
24
+ id: idGen.next(),
25
+ name: "identity.user.trashed",
26
+ occurredAt: clock.nowIso(),
27
+ aggregateId: entityId,
28
+ workspaceId,
29
+ ...(optional.actor ? { actorId: optional.actor.principalId } : {}),
30
+ payload: { principalId: entityId, username, priorStatus: before.status, sessionsRevoked: Number(revoked) },
31
+ } });
32
+ return { ok: true, version: null, priorMarker: before.status };
33
+ } });
34
+ },
35
+ };
36
+ }
37
+ function userTrashUnhide({ policy, store, idGen, clock }) {
38
+ return {
39
+ /**
40
+ * Restores the principal to `priorMarker` (decision 4: `priorMarker ?? "disabled"`) and records
41
+ * `identity.user.restored`. Sessions are never re-created — a restore never revives an old
42
+ * cookie (decision 2).
43
+ */
44
+ async unhide(required, optional = {}) {
45
+ const { workspaceId, entityId } = required;
46
+ return store.underPrincipalLock({ workspaceId, principalId: entityId, run: async () => {
47
+ const before = await store.readPrincipal({ workspaceId, principalId: entityId });
48
+ if (!before)
49
+ return { ok: false, reason: "not-found" };
50
+ const restoredStatus = optional.priorMarker ?? "disabled";
51
+ const restored = await store.compareAndSetStatus({ workspaceId, principalId: entityId, expected: before.status, next: restoredStatus,
52
+ ...(restoredStatus === "active" ? { disabledAt: null } : {}) });
53
+ if (Number(restored) === 0)
54
+ return { ok: false, reason: "version-changed" };
55
+ const username = await store.readDisplayUsername({ workspaceId, principalId: entityId, fallback: before.displayName });
56
+ await store.appendEvent({ event: {
57
+ id: idGen.next(),
58
+ name: "identity.user.restored",
59
+ occurredAt: clock.nowIso(),
60
+ aggregateId: entityId,
61
+ workspaceId,
62
+ ...(optional.actor ? { actorId: optional.actor.principalId } : {}),
63
+ payload: { principalId: entityId, username, restoredStatus },
64
+ } });
65
+ return { ok: true, version: null };
66
+ } });
67
+ },
68
+ };
69
+ }
70
+ function userTrashPurge({ policy, store, purge, idGen, clock }) {
71
+ return {
72
+ /**
73
+ * Hard-deletes the principal's identity rows via {@link UserPurgePort.purgeUser} (decision 4) —
74
+ * never a live principal (an `active` status means it was never trashed, or was re-enabled out
75
+ * from under an index row someone forgot to clear; either way it is not this adapter's call to
76
+ * remove it). Reachable from both `purgeSelected` (an operator, `optional.actor` set — `reason:
77
+ * "manual"`) and the retention sweeper (`optional.actor` absent — `reason: "retention"`,
78
+ * `actorId` left off the event, decision 6).
79
+ */
80
+ async purge(required, optional = {}) {
81
+ const { workspaceId, entityId } = required;
82
+ return store.underPrincipalLock({ workspaceId, principalId: entityId, run: async () => {
83
+ const before = await store.readPrincipal({ workspaceId, principalId: entityId });
84
+ if (!before)
85
+ return "already-gone";
86
+ await policy.assertAccountAction?.({ workspaceId, principalId: entityId, action: "purge" }, { callerPrincipalId: optional.actor?.principalId });
87
+ if (before.status === "active")
88
+ return "version-changed";
89
+ const username = await store.readDisplayUsername({ workspaceId, principalId: entityId, fallback: before.displayName });
90
+ const reason = optional.actor ? "manual" : "retention";
91
+ await purge.purgeUser({
92
+ workspaceId,
93
+ principalId: entityId,
94
+ reason,
95
+ buildEvent: ({ removed }, { reason: builtReason } = {}) => ({
96
+ id: idGen.next(),
97
+ name: "identity.user.deleted",
98
+ occurredAt: clock.nowIso(),
99
+ aggregateId: entityId,
100
+ workspaceId,
101
+ ...(optional.actor ? { actorId: optional.actor.principalId } : {}),
102
+ payload: { principalId: entityId, username, removed, reason: builtReason },
103
+ }),
104
+ });
105
+ return "purged";
106
+ } });
107
+ },
108
+ };
109
+ }
110
+ /**
111
+ * Builds the user `TrashAdapter`.
112
+ *
113
+ * @complexity O(1) to build; each method is O(1) plus `purge`'s delegated
114
+ * `UserPurgePort.purgeUser` cost (itself O(1), see that file).
115
+ */
116
+ export function createUserTrashAdapter(required, _optional = {}) {
117
+ return {
118
+ entityType: required.policy.entityType,
119
+ ...userTrashHide(required),
120
+ ...userTrashUnhide(required),
121
+ ...userTrashPurge(required),
122
+ };
123
+ }
124
+ //# sourceMappingURL=user-trash-adapter.js.map
@@ -0,0 +1,100 @@
1
+ import type { ChatDeleteSurfaceDeps } from "@jini-ai/core/contracts/site/daemon-surface-exchanges";
2
+ import type { assertUserAccountAction, SelfDeleteError } from "@jini-ai/user-management/identity/delete-user-service";
3
+ /**
4
+ * @file Identity tools built by Jini, with host human-confirmation and password-entry adapters.
5
+ * The host owns SurfaceExchangeStore/tool-calls transport, so it wraps the domain handlers here.
6
+ * identity_role_delete and identity_policy_delete permanently delete and require human approval,
7
+ * consistent with the owner's trash/delete/restore-over-existing/publish policy. Granting a role
8
+ * or attaching a policy is not a delete and does not need that gate.
9
+ * identity_user_create takes the first password through the human dialog, browser -> route ->
10
+ * parked handler, so it never enters model context or chat. The composition root installs tools;
11
+ * importing this feature must not register them or create an assistant runtime cycle.
12
+ */
13
+ import type { ToolContributor } from "@jini-ai/core";
14
+ import type { buildIdentityRegistrations, identityDerivedRisk, IdentityToolDeps as BaseIdentityToolDeps } from "../server/agent-tool-registrations.js";
15
+ import type { assertCallerHasAnyPermission, normalizeUsername, parseIdentityToolInput } from "../server/index.js";
16
+ import { type ToolHandler, type ToolRegistration } from "@jini-ai/core";
17
+ import type { Clock } from "@jini-ai/core/primitives";
18
+ import type { SurfaceCardsPort, SurfaceCardSecretOptions, SurfaceCardSecretDeps } from '@jini-ai/core/contracts/cards';
19
+ import type { HumanConfirmSpec } from '@jini-ai/core/contracts/site/human-confirm';
20
+ import type { ToolExecutionContext, ToolExecutionOptions, HumanConfirmer } from '@jini-ai/core';
21
+ import type { SecretCardForm } from "@jini-ai/core/contracts/cards";
22
+ import type { SurfaceOutcomeSpec } from "@jini-ai/core/contracts/cards";
23
+ import type { createUsernameChangePort } from "@jini-ai/user-management/identity/username-change-ports";
24
+ import type { OutboxPort } from "@jini-ai/core/contracts/events";
25
+ /** The host keeps its ISO clock ABI at this adapter; shared service/rationale live in user-management/server. */
26
+ export type IdentityToolDeps = Omit<BaseIdentityToolDeps, "clock"> & {
27
+ clock: Clock | {
28
+ nowIso(): string;
29
+ };
30
+ buildIdentityRegistrations: typeof buildIdentityRegistrations;
31
+ identityDerivedRisk: typeof identityDerivedRisk;
32
+ normalizeUsername: typeof normalizeUsername;
33
+ parseIdentityToolInput: typeof parseIdentityToolInput;
34
+ createUsernameChangePort: typeof createUsernameChangePort;
35
+ SelfDeleteError: typeof SelfDeleteError;
36
+ outbox: OutboxPort;
37
+ isInTrash: (required: {
38
+ principalId: string;
39
+ }, optional?: Record<string, never>) => Promise<boolean>;
40
+ assertUserAccountAction: typeof assertUserAccountAction;
41
+ assertCallerHasAnyPermission: typeof assertCallerHasAnyPermission;
42
+ defineSecretCardTool: SurfaceCardsPort['defineSecretCardTool'];
43
+ askThenReport: SurfaceCardSecretDeps['askThenReport'];
44
+ secretCardOptions: SurfaceCardSecretOptions;
45
+ secretField: {
46
+ readonly secret?: boolean;
47
+ };
48
+ formApp: SecretCardForm['app'];
49
+ outcomeApp: SurfaceOutcomeSpec['app'];
50
+ notConfirmedResult(input: {
51
+ confirmed: false;
52
+ reason: string;
53
+ }): Record<string, unknown>;
54
+ approvalToolHandler: <TPrepared>(steps: {
55
+ surfaces: ChatDeleteSurfaceDeps;
56
+ prepare(input: {
57
+ ctx: ToolExecutionContext;
58
+ }, optional: ToolExecutionOptions): Promise<TPrepared>;
59
+ describe(input: {
60
+ ctx: ToolExecutionContext;
61
+ prepared: TPrepared;
62
+ }): HumanConfirmSpec | Promise<HumanConfirmSpec>;
63
+ run(input: {
64
+ ctx: ToolExecutionContext;
65
+ prepared: TPrepared;
66
+ confirmer: HumanConfirmer;
67
+ choice?: string;
68
+ }, optional: ToolExecutionOptions): Promise<unknown>;
69
+ }, optional: {
70
+ flag: string;
71
+ batch?: boolean;
72
+ }) => ToolHandler;
73
+ };
74
+ /** Exported for the same reason {@link withoutPassword} is — see its doc comment. */
75
+ export declare const USER_CREATE_DESCRIPTION_SUFFIX = " The user types the new user's first password into a form this tool shows; never pass a password, and never ask for one in chat.";
76
+ /**
77
+ * The model-facing schema for `identity_user_create`: Jini's, minus `password`. Exported so
78
+ * `assistant/__tests__/tool-registrations.contracts.test.ts` can assert the wired registration's
79
+ * published schema against a real derivation of the Jini catalog entry instead of either a second,
80
+ * hand-copied expectation (which could silently drift from this function) or a blind id-based skip
81
+ * (which would stop catching a real regression, e.g. `password` ceasing to be stripped).
82
+ */
83
+ export declare function withoutPassword({ schema }: {
84
+ schema: unknown;
85
+ }, _options?: Record<string, never>): unknown;
86
+ /**
87
+ * Jini's identity registrations with `identity_role_delete`/`identity_policy_delete`/
88
+ * `identity_user_create` gated behind the human; every other tool passes through unchanged.
89
+ *
90
+ * @complexity O(n) in the registration count; each gate adds one or two repo reads per call.
91
+ */
92
+ export declare function buildGatedIdentityRegistrations(routeDeps: IdentityToolDeps, surfaces: ChatDeleteSurfaceDeps): ToolRegistration[];
93
+ /**
94
+ * Contributes Identity's AI tools to the assistant's catalog — called once by
95
+ * `host src/server/runtime/composition/tool-catalog-manifest.ts`'s `installFirstPartyToolContributors()`, not by importing this
96
+ * module. `assistant/tool-registrations.ts` no longer imports `buildIdentityRegistrations`/
97
+ * `identityDerivedRisk` by name; this is the seam that replaced it.
98
+ */
99
+ export declare function contributeIdentityTools(required: Pick<IdentityToolDeps, 'identityDerivedRisk'>, _optional?: Record<string, never>): ToolContributor<IdentityToolDeps, ChatDeleteSurfaceDeps>;
100
+ //# sourceMappingURL=tool-registrations.d.ts.map
@@ -0,0 +1,257 @@
1
+ import { isDeepStrictEqual } from "node:util";
2
+ import { toolMetadata } from '@jini-ai/core/tool-metadata/identity';
3
+ import { withToolMetadata } from '@jini-ai/core';
4
+ import { IdentityConflictError, OwnerRequiredError } from "@jini-ai/user-management";
5
+ import { ToolInputError } from "@jini-ai/core";
6
+ const ROLE_DELETE_TOOL_ID = "identity_role_delete";
7
+ const POLICY_DELETE_TOOL_ID = "identity_policy_delete";
8
+ const USER_CREATE_TOOL_ID = "identity_user_create";
9
+ /** Exported for the same reason {@link withoutPassword} is — see its doc comment. */
10
+ export const USER_CREATE_DESCRIPTION_SUFFIX = " The user types the new user's first password into a form this tool shows; never pass a password, and never ask for one in chat.";
11
+ /**
12
+ * Validates `input` against the tool's published schema BEFORE any dialog is drawn, with the same
13
+ * schema-bearing message Jini's own handlers give, so a malformed call never reaches the human.
14
+ */
15
+ function validated({ toolId, schema, input, parseIdentityToolInput }, _options = {}) {
16
+ const parsed = parseIdentityToolInput({ schema: schema, input });
17
+ if (!parsed.ok) {
18
+ throw new ToolInputError({ message: `${parsed.error.message}. Fix the input and retry — this will not resolve on retry without an input change. ` +
19
+ `Schema for '${toolId}': ${JSON.stringify(schema)}` });
20
+ }
21
+ return parsed.value;
22
+ }
23
+ /**
24
+ * The model-facing schema for `identity_user_create`: Jini's, minus `password`. Exported so
25
+ * `assistant/__tests__/tool-registrations.contracts.test.ts` can assert the wired registration's
26
+ * published schema against a real derivation of the Jini catalog entry instead of either a second,
27
+ * hand-copied expectation (which could silently drift from this function) or a blind id-based skip
28
+ * (which would stop catching a real regression, e.g. `password` ceasing to be stripped).
29
+ */
30
+ export function withoutPassword({ schema }, _options = {}) {
31
+ const { properties, required, ...rest } = schema;
32
+ const { password: _password, ...kept } = properties;
33
+ return { ...rest, required: (required ?? []).filter((key) => key !== "password"), properties: kept };
34
+ }
35
+ /** Human-readable dependency snapshots for the identity deletion confirmation. */
36
+ function identityReferenceDetails({ references }, _options = {}) {
37
+ return Object.entries(references).map(([label, rows]) => {
38
+ const names = rows.map(row => row.permission ? `${row.permission} (${row.id})` : row.id).join(", ") || "none";
39
+ return { label, value: `${rows.length}: ${names}` };
40
+ });
41
+ }
42
+ function userCreateForm(required, _optional = {}) {
43
+ const { username, emailSuffix } = required;
44
+ return {
45
+ title: `Create the user ${username}?`,
46
+ description: `A new login named ${username}${emailSuffix} will be created with no roles. Type their first password below.`,
47
+ submitLabel: "Create user",
48
+ fields: [{ kind: "string", name: "password", label: "Password", hint: "Typed here only, never shown to the assistant.", required: true,
49
+ ...required.ports.secretField }],
50
+ cancelLabel: "Cancel", ...(required.ports.formApp === undefined ? {} : { app: required.ports.formApp }),
51
+ preferredFrameSize: ["100%", "360px"],
52
+ };
53
+ }
54
+ function userCreateOutcome(required, _optional = {}) {
55
+ const { run, username } = required;
56
+ if (run.status !== "saved" && run.status !== "blank" && run.status !== "failed")
57
+ return undefined;
58
+ let message;
59
+ if (run.status === "saved")
60
+ message = `${username} can now sign in with the password you typed.`;
61
+ else if (run.status === "blank")
62
+ message = "No password was entered. Nothing was created.";
63
+ else
64
+ message = run.safeMessage;
65
+ return {
66
+ title: run.status === "saved" ? "User created" : "User not created",
67
+ details: [{ label: "Username", value: username }], state: run.status === "saved" ? "success" : "failure",
68
+ message,
69
+ ...(required.app === undefined ? {} : { app: required.app }), preferredFrameSize: ["100%", "240px"],
70
+ };
71
+ }
72
+ /** Each family supplies its own label and service permission; Jini owns the asking sequence.
73
+ * The inner service reauthorizes at write time; the snapshot prevents callback input retargeting. */
74
+ // SQL list ports promise a set, not row order. Canonicalize both snapshots so an
75
+ // unchanged set cannot invalidate confirmation just because query order changed.
76
+ // O(n log n) local sorting across n dependency rows; no additional repo reads.
77
+ function createIdentityDeleteReferences(routeDeps) {
78
+ return async ({ kind, id }, _options = {}) => {
79
+ const references = kind === "role"
80
+ ? { principals: await routeDeps.principalRoleRepo.listByRoleId({ workspaceId: routeDeps.workspaceId, roleId: id }), policies: await routeDeps.rolePolicyRepo.listByRoleId({ workspaceId: routeDeps.workspaceId, roleId: id }) }
81
+ : { principals: await routeDeps.principalPolicyRepo.listByPolicyId({ workspaceId: routeDeps.workspaceId, policyId: id }), roles: await routeDeps.rolePolicyRepo.listByPolicyId({ workspaceId: routeDeps.workspaceId, policyId: id }), permissions: await routeDeps.policyPermissionRepo.listByPolicyId({ workspaceId: routeDeps.workspaceId, policyId: id }) };
82
+ return Object.fromEntries(Object.entries(references).map(([label, rows]) => [label, [...rows].sort((a, b) => {
83
+ if (a.id < b.id)
84
+ return -1;
85
+ if (a.id > b.id)
86
+ return 1;
87
+ return 0;
88
+ })]));
89
+ };
90
+ }
91
+ function createConfirmedIdentityDelete({ routeDeps, surfaces, identity, deleteReferences }) {
92
+ return ({ registration, kind }, _options = {}) => ({
93
+ ...registration,
94
+ handler: routeDeps.approvalToolHandler({ surfaces,
95
+ prepare: async ({ ctx }) => {
96
+ const input = validated({ parseIdentityToolInput: routeDeps.parseIdentityToolInput, toolId: registration.descriptor.id, schema: registration.descriptor.inputSchema, input: ctx.input });
97
+ await routeDeps.assertCallerHasAnyPermission({ deps: identity, workspaceId: routeDeps.workspaceId,
98
+ // Jini owns both role and policy deletion under role.manage.
99
+ callerPrincipalId: ctx.principal.id, permissions: ["role.manage"] });
100
+ const id = input[`${kind}Id`];
101
+ if (id === undefined)
102
+ throw new ToolInputError({ message: `${registration.descriptor.id}: ${kind} ID is missing. Nothing was deleted.` });
103
+ const repo = kind === "role" ? routeDeps.roleRepo : routeDeps.policyRepo;
104
+ const existing = await repo.findById({ workspaceId: routeDeps.workspaceId, id });
105
+ if (!existing)
106
+ throw new ToolInputError({ message: `${registration.descriptor.id}: ${kind} was not found. Nothing was deleted.` });
107
+ const references = await deleteReferences({ kind, id });
108
+ return { id, snapshot: structuredClone(existing), references: structuredClone(references), label: existing.name };
109
+ },
110
+ describe: ({ prepared: { id, label, references } }) => ({
111
+ toolId: registration.descriptor.id, errorCode: "IDENTITY", title: `Delete the ${kind} ${label}?`,
112
+ details: [{ label: "Count", value: "1" }, { label: kind === "role" ? "Role" : "Policy", value: `${label} (${id})` }, ...identityReferenceDetails({ references })],
113
+ warning: `The ${kind} is deleted for good. This can't be undone. Existing assignments prevent deletion; remove them in the Roles admin screen first.`, danger: true, confirmLabel: `Delete ${kind}`,
114
+ }),
115
+ run: async ({ ctx, prepared: { id, snapshot, references } }, options) => {
116
+ const repo = kind === "role" ? routeDeps.roleRepo : routeDeps.policyRepo;
117
+ if (!isDeepStrictEqual(await repo.findById({ workspaceId: routeDeps.workspaceId, id }), snapshot)) {
118
+ throw new ToolInputError({ message: `${registration.descriptor.id}: target changed while confirmation was open. Request a new confirmation; nothing was deleted.` });
119
+ }
120
+ const currentReferences = await deleteReferences({ kind, id });
121
+ if (!isDeepStrictEqual(currentReferences, references))
122
+ throw new ToolInputError({ message: `${registration.descriptor.id}: dependencies changed while confirmation was open. Request a new confirmation; nothing was deleted.` });
123
+ return registration.handler({ ...ctx, input: { [`${kind}Id`]: id } }, options);
124
+ },
125
+ }, { flag: "deleted", batch: true }),
126
+ });
127
+ }
128
+ function createHumanPasswordUserHandler({ routeDeps, surfaces, identity }) {
129
+ return ({ inner, publishedSchema }, _options = {}) => async (ctx, options = {}) => {
130
+ if (typeof ctx.input === "object" && ctx.input !== null && "password" in ctx.input) {
131
+ throw new ToolInputError({ message: `IDENTITY_PASSWORD_NOT_ACCEPTED: ${USER_CREATE_TOOL_ID}: do not pass a password. The user types the new ` +
132
+ "user's first password into the form this tool shows. Nothing was created." });
133
+ }
134
+ const input = validated({ parseIdentityToolInput: routeDeps.parseIdentityToolInput, toolId: USER_CREATE_TOOL_ID, schema: publishedSchema, input: ctx.input });
135
+ const username = input["username"];
136
+ if (username === undefined)
137
+ throw new ToolInputError({ message: `${USER_CREATE_TOOL_ID}: username is missing. Nothing was created.` });
138
+ const emailSuffix = input["email"] ? ` (${input["email"]})` : "";
139
+ let failureMessage;
140
+ const card = routeDeps.defineSecretCardTool({
141
+ toolId: USER_CREATE_TOOL_ID,
142
+ prepare: async () => {
143
+ // Use the service's own permission rule before opening; createUser checks it again at save.
144
+ await routeDeps.assertCallerHasAnyPermission({ deps: identity, workspaceId: routeDeps.workspaceId,
145
+ callerPrincipalId: ctx.principal.id, permissions: ["user.manage"] });
146
+ return input;
147
+ },
148
+ form: () => userCreateForm({ username, emailSuffix, ports: routeDeps }),
149
+ save: async ({ values, prep, signal }) => (await inner({ ...ctx, signal, input: { ...prep, password: values.password } }, options)),
150
+ result: ({ run }) => {
151
+ if (run.status === "saved")
152
+ return { created: true, ...run.saved };
153
+ if (run.status === "blank")
154
+ return { created: false, cancelled: false, note: "The user submitted no password. Nothing was created." };
155
+ if (run.status === "failed") {
156
+ failureMessage = run.safeMessage;
157
+ return undefined;
158
+ }
159
+ return { created: false, ...routeDeps.notConfirmedResult({ confirmed: false, reason: run.status === "cancelled" ? "declined" : run.status }) };
160
+ },
161
+ outcome: ({ run }) => userCreateOutcome({ run, username, app: routeDeps.outcomeApp }),
162
+ }, {
163
+ ...routeDeps.secretCardOptions,
164
+ // Rebuild the known conflict from public input; hasher/repository exceptions can contain the password.
165
+ safeError: error => error instanceof IdentityConflictError ? `username '${routeDeps.normalizeUsername({ raw: username })}' is already in use` : undefined,
166
+ });
167
+ const result = await card.handler({ surfaceExchanges: surfaces.surfaceExchanges, askThenReport: routeDeps.askThenReport })(ctx, options);
168
+ // Preserve the domain's rejection contract after the engine has delivered the safe failure card.
169
+ if (failureMessage !== undefined)
170
+ throw new ToolInputError({ message: failureMessage });
171
+ return result;
172
+ };
173
+ }
174
+ /** Runs the owner account guard in the same transaction as the wrapped disable/enable tool, and
175
+ * turns its refusals into plain tool errors that say nothing was changed. */
176
+ function gateAccountActionTool({ registration, routeDeps, identity, action }, _optional = {}) {
177
+ const toolId = registration.descriptor.id;
178
+ return { ...registration, handler: async (ctx, options = {}) => {
179
+ const input = validated({ parseIdentityToolInput: routeDeps.parseIdentityToolInput, toolId, schema: registration.descriptor.inputSchema, input: ctx.input });
180
+ const principalId = input["principalId"];
181
+ if (principalId === undefined)
182
+ throw new ToolInputError({ message: `${toolId}: principal ID is missing. Nothing was changed.` });
183
+ try {
184
+ return await routeDeps.transactions.run({ workspaceId: routeDeps.workspaceId, execute: async () => {
185
+ await routeDeps.assertUserAccountAction({ deps: identity, workspaceId: routeDeps.workspaceId, principalId, action }, { callerPrincipalId: ctx.principal.id, seededOwnerPrincipalId: await routeDeps.ownerPrincipalId });
186
+ return registration.handler(ctx, options);
187
+ } });
188
+ }
189
+ catch (error) {
190
+ if (error instanceof routeDeps.SelfDeleteError || error instanceof OwnerRequiredError) {
191
+ const code = error instanceof routeDeps.SelfDeleteError ? "SELF_DELETE" : "OWNER_REQUIRED";
192
+ throw new ToolInputError({ message: `${toolId}: ${code}: ${error.message}. Nothing was changed.` });
193
+ }
194
+ throw error;
195
+ }
196
+ } };
197
+ }
198
+ function gateIdentityRegistration(registration, { routeDeps, identity, confirmedDelete, createUserWithHumanPassword }) {
199
+ switch (registration.descriptor.id) {
200
+ case "identity_user_disable":
201
+ return gateAccountActionTool({ registration, routeDeps, identity, action: "disable" });
202
+ // B151: the assistant's enable must obey the same owner-only rule as the HTTP route.
203
+ case "identity_user_enable":
204
+ return gateAccountActionTool({ registration, routeDeps, identity, action: "enable" });
205
+ case ROLE_DELETE_TOOL_ID:
206
+ return confirmedDelete({ registration, kind: "role" });
207
+ case POLICY_DELETE_TOOL_ID:
208
+ return confirmedDelete({ registration, kind: "policy" });
209
+ case USER_CREATE_TOOL_ID: {
210
+ const inputSchema = withoutPassword({ schema: registration.descriptor.inputSchema });
211
+ return {
212
+ ...registration,
213
+ descriptor: {
214
+ ...registration.descriptor,
215
+ description: `${registration.descriptor.description ?? ""}${USER_CREATE_DESCRIPTION_SUFFIX}`,
216
+ inputSchema,
217
+ },
218
+ handler: createUserWithHumanPassword({ inner: registration.handler, publishedSchema: inputSchema }),
219
+ };
220
+ }
221
+ default:
222
+ return registration;
223
+ }
224
+ }
225
+ /**
226
+ * Jini's identity registrations with `identity_role_delete`/`identity_policy_delete`/
227
+ * `identity_user_create` gated behind the human; every other tool passes through unchanged.
228
+ *
229
+ * @complexity O(n) in the registration count; each gate adds one or two repo reads per call.
230
+ */
231
+ export function buildGatedIdentityRegistrations(routeDeps, surfaces) {
232
+ const hostClock = routeDeps.clock;
233
+ const clock = "nowMs" in hostClock ? hostClock : { nowMs: () => Date.parse(hostClock.nowIso()) };
234
+ const identity = {
235
+ repos: { transactions: routeDeps.transactions, principals: routeDeps.principalRepo, users: routeDeps.userRepo,
236
+ sessions: routeDeps.sessionRepo, roles: routeDeps.roleRepo, policies: routeDeps.policyRepo,
237
+ policyPermissions: routeDeps.policyPermissionRepo, rolePolicies: routeDeps.rolePolicyRepo,
238
+ principalRoles: routeDeps.principalRoleRepo, principalPolicies: routeDeps.principalPolicyRepo },
239
+ hasher: routeDeps.passwordHasher, clock, idGen: routeDeps.idGen, tokens: routeDeps.tokens,
240
+ };
241
+ const usernameChanges = routeDeps.createUsernameChangePort({ outbox: routeDeps.outbox, isInTrash: routeDeps.isInTrash, idGen: routeDeps.idGen,
242
+ seededOwnerPrincipalId: routeDeps.ownerPrincipalId });
243
+ const deleteReferences = createIdentityDeleteReferences(routeDeps);
244
+ const confirmedDelete = createConfirmedIdentityDelete({ routeDeps, surfaces, identity, deleteReferences });
245
+ const createUserWithHumanPassword = createHumanPasswordUserHandler({ routeDeps, surfaces, identity });
246
+ return withToolMetadata({ registrations: routeDeps.buildIdentityRegistrations({ ...routeDeps, clock, usernameChanges }), metadata: toolMetadata }).map(registration => gateIdentityRegistration(registration, { routeDeps, identity, confirmedDelete, createUserWithHumanPassword }));
247
+ }
248
+ /**
249
+ * Contributes Identity's AI tools to the assistant's catalog — called once by
250
+ * `host src/server/runtime/composition/tool-catalog-manifest.ts`'s `installFirstPartyToolContributors()`, not by importing this
251
+ * module. `assistant/tool-registrations.ts` no longer imports `buildIdentityRegistrations`/
252
+ * `identityDerivedRisk` by name; this is the seam that replaced it.
253
+ */
254
+ export function contributeIdentityTools(required, _optional = {}) {
255
+ return { domain: "identity", build: buildGatedIdentityRegistrations, risk: required.identityDerivedRisk };
256
+ }
257
+ //# sourceMappingURL=tool-registrations.js.map
@@ -0,0 +1,8 @@
1
+ import type { PermissionGrantRegistry } from "./permission-grants.js";
2
+ /** Owner decision 2026-10-07: builtin admins may manage ordinary users. The target rule in
3
+ * delete-user-service is mandatory at disable/reset/trash/purge boundaries; this grant is not
4
+ * authority over protected admin/owner accounts. Reconciles existing installs without schema work. */
5
+ export declare function registerUserManagePermissionGrants(required: {
6
+ registry: PermissionGrantRegistry;
7
+ }, _optional?: Record<string, never>): void;
8
+ //# sourceMappingURL=user-manage-permission.d.ts.map
@@ -0,0 +1,8 @@
1
+ /** Owner decision 2026-10-07: builtin admins may manage ordinary users. The target rule in
2
+ * delete-user-service is mandatory at disable/reset/trash/purge boundaries; this grant is not
3
+ * authority over protected admin/owner accounts. Reconciles existing installs without schema work. */
4
+ export function registerUserManagePermissionGrants(required, _optional = {}) {
5
+ required.registry.roleGrants.register({ role: "admin", permission: "user.manage",
6
+ reason: "Owner decision 2026-10-07: admins may manage ordinary non-admin users; only owners may delete, trash, disable or reset admin/owner accounts." });
7
+ }
8
+ //# sourceMappingURL=user-manage-permission.js.map