@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.
- package/CHANGELOG.md +7 -0
- package/README.md +55 -2
- package/dist/admin/adapters/memory.js +4 -4
- package/dist/admin-http/auth/auth-request.d.ts +112 -0
- package/dist/admin-http/auth/auth-request.js +32 -0
- package/dist/admin-http/auth/boot-redemption.d.ts +9 -0
- package/dist/admin-http/auth/boot-redemption.js +17 -0
- package/dist/admin-http/auth/boot-session.d.ts +30 -0
- package/dist/admin-http/auth/boot-session.js +40 -0
- package/dist/admin-http/auth/current-user.d.ts +28 -0
- package/dist/admin-http/auth/current-user.js +34 -0
- package/dist/admin-http/auth/index.d.ts +17 -0
- package/dist/admin-http/auth/index.js +9 -0
- package/dist/admin-http/auth/local-boot-session.d.ts +9 -0
- package/dist/admin-http/auth/local-boot-session.js +30 -0
- package/dist/admin-http/auth/logout.d.ts +10 -0
- package/dist/admin-http/auth/logout.js +17 -0
- package/dist/admin-http/auth/mfa-login.d.ts +30 -0
- package/dist/admin-http/auth/mfa-login.js +43 -0
- package/dist/admin-http/auth/password-login.d.ts +35 -0
- package/dist/admin-http/auth/password-login.js +52 -0
- package/dist/admin-http/auth/password-status.d.ts +34 -0
- package/dist/admin-http/auth/password-status.js +42 -0
- package/dist/admin-http/http/api-keys.d.ts +45 -0
- package/dist/admin-http/http/api-keys.js +28 -0
- package/dist/admin-http/http/users.d.ts +71 -0
- package/dist/admin-http/http/users.js +42 -0
- package/dist/admin-http/owner/mfa-deps.d.ts +41 -0
- package/dist/admin-http/owner/mfa-deps.js +26 -0
- package/dist/admin-http/owner/mfa-routes.d.ts +72 -0
- package/dist/admin-http/owner/mfa-routes.js +105 -0
- package/dist/admin-http/owner/passkey-admission.d.ts +46 -0
- package/dist/admin-http/owner/passkey-admission.js +23 -0
- package/dist/admin-http/owner/passkey-route-deps.d.ts +53 -0
- package/dist/admin-http/owner/passkey-route-deps.js +33 -0
- package/dist/admin-http/owner/passkey-routes.d.ts +146 -0
- package/dist/admin-http/owner/passkey-routes.js +98 -0
- package/dist/admin-http/owner/recovery-routes.d.ts +71 -0
- package/dist/admin-http/owner/recovery-routes.js +112 -0
- package/dist/admin-http/routes/api-keys/create-principal.d.ts +26 -0
- package/dist/admin-http/routes/api-keys/create-principal.js +37 -0
- package/dist/admin-http/routes/api-keys/issue.d.ts +32 -0
- package/dist/admin-http/routes/api-keys/issue.js +38 -0
- package/dist/admin-http/routes/api-keys/revoke.d.ts +26 -0
- package/dist/admin-http/routes/api-keys/revoke.js +31 -0
- package/dist/admin-http/routes/api-keys/shared.d.ts +46 -0
- package/dist/admin-http/routes/api-keys/shared.js +38 -0
- package/dist/admin-http/routes/users/access-shared.d.ts +103 -0
- package/dist/admin-http/routes/users/access-shared.js +85 -0
- package/dist/admin-http/routes/users/assign-role.d.ts +24 -0
- package/dist/admin-http/routes/users/assign-role.js +30 -0
- package/dist/admin-http/routes/users/attach-policy.d.ts +25 -0
- package/dist/admin-http/routes/users/attach-policy.js +31 -0
- package/dist/admin-http/routes/users/create-policy.d.ts +19 -0
- package/dist/admin-http/routes/users/create-policy.js +28 -0
- package/dist/admin-http/routes/users/create-role.d.ts +15 -0
- package/dist/admin-http/routes/users/create-role.js +21 -0
- package/dist/admin-http/routes/users/create.d.ts +32 -0
- package/dist/admin-http/routes/users/create.js +67 -0
- package/dist/admin-http/routes/users/delete-policy.d.ts +16 -0
- package/dist/admin-http/routes/users/delete-policy.js +24 -0
- package/dist/admin-http/routes/users/delete-role.d.ts +16 -0
- package/dist/admin-http/routes/users/delete-role.js +24 -0
- package/dist/admin-http/routes/users/delete.d.ts +35 -0
- package/dist/admin-http/routes/users/delete.js +35 -0
- package/dist/admin-http/routes/users/disable.d.ts +31 -0
- package/dist/admin-http/routes/users/disable.js +38 -0
- package/dist/admin-http/routes/users/enable.d.ts +32 -0
- package/dist/admin-http/routes/users/enable.js +45 -0
- package/dist/admin-http/routes/users/list-policies.d.ts +18 -0
- package/dist/admin-http/routes/users/list-policies.js +20 -0
- package/dist/admin-http/routes/users/list-policy-permissions.d.ts +28 -0
- package/dist/admin-http/routes/users/list-policy-permissions.js +30 -0
- package/dist/admin-http/routes/users/list-roles.d.ts +18 -0
- package/dist/admin-http/routes/users/list-roles.js +20 -0
- package/dist/admin-http/routes/users/list.d.ts +40 -0
- package/dist/admin-http/routes/users/list.js +82 -0
- package/dist/admin-http/routes/users/remove-policy-permission.d.ts +48 -0
- package/dist/admin-http/routes/users/remove-policy-permission.js +62 -0
- package/dist/admin-http/routes/users/reset-password.d.ts +33 -0
- package/dist/admin-http/routes/users/reset-password.js +52 -0
- package/dist/admin-http/routes/users/shared.d.ts +124 -0
- package/dist/admin-http/routes/users/shared.js +93 -0
- package/dist/admin-http/routes/users/update-policy.d.ts +25 -0
- package/dist/admin-http/routes/users/update-policy.js +30 -0
- package/dist/admin-http/routes/users/update-role.d.ts +23 -0
- package/dist/admin-http/routes/users/update-role.js +29 -0
- package/dist/admin-http/routes/users/update.d.ts +35 -0
- package/dist/admin-http/routes/users/update.js +78 -0
- package/dist/admin-http/routes/users/write-policy-permission.d.ts +31 -0
- package/dist/admin-http/routes/users/write-policy-permission.js +45 -0
- package/dist/core/ports.d.ts +22 -3
- package/dist/core/types.d.ts +17 -5
- package/dist/core/types.js +12 -0
- package/dist/identity/api-key-secret.d.ts +68 -0
- package/dist/identity/api-key-secret.js +229 -0
- package/dist/identity/api-key-service.d.ts +144 -0
- package/dist/identity/api-key-service.js +389 -0
- package/dist/identity/api-key-types.d.ts +79 -0
- package/dist/identity/api-key-types.js +2 -0
- package/dist/identity/boot-session-token.d.ts +18 -0
- package/dist/identity/boot-session-token.js +92 -0
- package/dist/identity/builtin-role-grants.d.ts +120 -0
- package/dist/identity/builtin-role-grants.js +88 -0
- package/dist/identity/delete-user-service.d.ts +195 -0
- package/dist/identity/delete-user-service.js +275 -0
- package/dist/identity/owner-reset-env.d.ts +37 -0
- package/dist/identity/owner-reset-env.js +38 -0
- package/dist/identity/permission-grants.d.ts +31 -0
- package/dist/identity/permission-grants.js +12 -0
- package/dist/identity/permission-list-tool.d.ts +35 -0
- package/dist/identity/permission-list-tool.js +47 -0
- package/dist/identity/repo.authentication.d.ts +57 -0
- package/dist/identity/repo.authentication.js +153 -0
- package/dist/identity/repo.authorization.d.ts +82 -0
- package/dist/identity/repo.authorization.js +203 -0
- package/dist/identity/repo.d.ts +87 -0
- package/dist/identity/repo.js +167 -0
- package/dist/identity/repo.memory.d.ts +31 -0
- package/dist/identity/repo.memory.js +37 -0
- package/dist/identity/role-manage-permission.d.ts +34 -0
- package/dist/identity/role-manage-permission.js +39 -0
- package/dist/identity/site-key-permission.d.ts +66 -0
- package/dist/identity/site-key-permission.js +92 -0
- package/dist/identity/sql/kernel-user-purge.d.ts +19 -0
- package/dist/identity/sql/kernel-user-purge.js +34 -0
- package/dist/identity/sql/kernel-user-trash-store.d.ts +15 -0
- package/dist/identity/sql/kernel-user-trash-store.js +41 -0
- package/dist/identity/sql/user-trash-adapter.d.ts +87 -0
- package/dist/identity/sql/user-trash-adapter.js +124 -0
- package/dist/identity/tool-registrations.d.ts +100 -0
- package/dist/identity/tool-registrations.js +257 -0
- package/dist/identity/user-manage-permission.d.ts +8 -0
- package/dist/identity/user-manage-permission.js +8 -0
- package/dist/identity/user-purge-types.d.ts +85 -0
- package/dist/identity/user-purge-types.js +17 -0
- package/dist/identity/user-purge.d.ts +69 -0
- package/dist/identity/user-purge.js +46 -0
- package/dist/identity/username-change-ports.d.ts +15 -0
- package/dist/identity/username-change-ports.js +22 -0
- package/dist/mail/site/capture-clear.d.ts +58 -0
- package/dist/mail/site/capture-clear.js +21 -0
- package/dist/mail/status/agent-tools.d.ts +65 -0
- package/dist/mail/status/agent-tools.js +22 -0
- package/dist/mail/status/delivery-agent-tools.d.ts +206 -0
- package/dist/mail/status/delivery-agent-tools.js +63 -0
- package/dist/mail/status/delivery-tool-registrations.d.ts +216 -0
- package/dist/mail/status/delivery-tool-registrations.js +110 -0
- package/dist/mail/status/domain-deps.d.ts +25 -0
- package/dist/mail/status/domain-deps.js +23 -0
- package/dist/mail/status/permissions.d.ts +43 -0
- package/dist/mail/status/permissions.js +45 -0
- package/dist/mail/status/provider-agent-tools.d.ts +38 -0
- package/dist/mail/status/provider-agent-tools.js +17 -0
- package/dist/mail/status/provider-operations.d.ts +166 -0
- package/dist/mail/status/provider-operations.js +121 -0
- package/dist/mail/status/provider-tool-registrations.d.ts +65 -0
- package/dist/mail/status/provider-tool-registrations.js +106 -0
- package/dist/mail/status/tool-registrations.d.ts +152 -0
- package/dist/mail/status/tool-registrations.js +112 -0
- package/dist/member-login/credentials.d.ts +40 -0
- package/dist/member-login/credentials.js +26 -0
- package/dist/member-login/link-service.d.ts +66 -0
- package/dist/member-login/link-service.js +141 -0
- package/dist/member-login/oidc-login.d.ts +132 -0
- package/dist/member-login/oidc-login.js +206 -0
- package/dist/member-login/oidc-request.d.ts +80 -0
- package/dist/member-login/oidc-request.js +86 -0
- package/dist/member-login/providers.d.ts +79 -0
- package/dist/member-login/providers.js +41 -0
- package/dist/member-login/ready-providers.d.ts +17 -0
- package/dist/member-login/ready-providers.js +11 -0
- package/dist/member-login/unlink-identity.d.ts +26 -0
- package/dist/member-login/unlink-identity.js +59 -0
- package/dist/members/access-resolver.d.ts +107 -0
- package/dist/members/access-resolver.js +231 -0
- package/dist/members/agent-tools.d.ts +14 -0
- package/dist/members/agent-tools.js +139 -0
- package/dist/members/auth-mail.d.ts +27 -0
- package/dist/members/auth-mail.js +21 -0
- package/dist/members/capability-card.d.ts +18 -0
- package/dist/members/capability-card.js +27 -0
- package/dist/members/consent-service.d.ts +115 -0
- package/dist/members/consent-service.js +179 -0
- package/dist/members/member-admin-writes.d.ts +73 -0
- package/dist/members/member-admin-writes.js +149 -0
- package/dist/members/member-challenge-request.d.ts +59 -0
- package/dist/members/member-challenge-request.js +145 -0
- package/dist/members/member-challenge.d.ts +37 -0
- package/dist/members/member-challenge.js +84 -0
- package/dist/members/member-credentials.d.ts +35 -0
- package/dist/members/member-credentials.js +57 -0
- package/dist/members/member-sign-in.d.ts +44 -0
- package/dist/members/member-sign-in.js +130 -0
- package/dist/members/member-validation.d.ts +5 -0
- package/dist/members/member-validation.js +13 -0
- package/dist/members/password-auth.d.ts +55 -0
- package/dist/members/password-auth.js +177 -0
- package/dist/members/ports.d.ts +455 -0
- package/dist/members/ports.js +21 -0
- package/dist/members/public-member-auth-response.d.ts +68 -0
- package/dist/members/public-member-auth-response.js +45 -0
- package/dist/members/public-member-response.d.ts +25 -0
- package/dist/members/public-member-response.js +15 -0
- package/dist/members/repo.d.ts +199 -0
- package/dist/members/repo.js +324 -0
- package/dist/members/repo.memory.d.ts +276 -0
- package/dist/members/repo.memory.js +395 -0
- package/dist/members/repo.rows.d.ts +153 -0
- package/dist/members/repo.rows.js +250 -0
- package/dist/members/repo.sessions.d.ts +80 -0
- package/dist/members/repo.sessions.js +166 -0
- package/dist/members/repo.sql.d.ts +9 -0
- package/dist/members/repo.sql.js +11 -0
- package/dist/members/subscriber-directory.d.ts +85 -0
- package/dist/members/subscriber-directory.js +70 -0
- package/dist/members/tool-registrations.d.ts +143 -0
- package/dist/members/tool-registrations.js +247 -0
- package/dist/members/trash-member.d.ts +24 -0
- package/dist/members/trash-member.js +24 -0
- package/dist/members/types.d.ts +321 -0
- package/dist/members/types.js +34 -0
- package/dist/members/write-service.d.ts +17 -0
- package/dist/members/write-service.js +15 -0
- package/dist/newsletter/agent-tools.d.ts +20 -0
- package/dist/newsletter/agent-tools.js +236 -0
- package/dist/newsletter/campaign-write-service.d.ts +92 -0
- package/dist/newsletter/campaign-write-service.js +190 -0
- package/dist/newsletter/campaign.d.ts +53 -0
- package/dist/newsletter/campaign.js +95 -0
- package/dist/newsletter/confirmation.d.ts +75 -0
- package/dist/newsletter/confirmation.js +142 -0
- package/dist/newsletter/data-module-manifest.d.ts +68 -0
- package/dist/newsletter/data-module-manifest.js +126 -0
- package/dist/newsletter/delivery/tool-registrations.d.ts +67 -0
- package/dist/newsletter/delivery/tool-registrations.js +229 -0
- package/dist/newsletter/errors.d.ts +93 -0
- package/dist/newsletter/errors.js +93 -0
- package/dist/newsletter/hooks.d.ts +59 -0
- package/dist/newsletter/hooks.js +49 -0
- package/dist/newsletter/http-error-responses.d.ts +17 -0
- package/dist/newsletter/http-error-responses.js +96 -0
- package/dist/newsletter/launch-gate.d.ts +62 -0
- package/dist/newsletter/launch-gate.js +29 -0
- package/dist/newsletter/lists.d.ts +60 -0
- package/dist/newsletter/lists.js +83 -0
- package/dist/newsletter/ports.d.ts +283 -0
- package/dist/newsletter/ports.js +2 -0
- package/dist/newsletter/repo-sends.d.ts +82 -0
- package/dist/newsletter/repo-sends.js +178 -0
- package/dist/newsletter/repo-subscribers.d.ts +83 -0
- package/dist/newsletter/repo-subscribers.js +215 -0
- package/dist/newsletter/repo.d.ts +61 -0
- package/dist/newsletter/repo.js +147 -0
- package/dist/newsletter/repo.memory.d.ts +202 -0
- package/dist/newsletter/repo.memory.js +260 -0
- package/dist/newsletter/repo.rows.d.ts +221 -0
- package/dist/newsletter/repo.rows.js +260 -0
- package/dist/newsletter/save-guard.d.ts +32 -0
- package/dist/newsletter/save-guard.js +27 -0
- package/dist/newsletter/send-pipeline.d.ts +240 -0
- package/dist/newsletter/send-pipeline.js +514 -0
- package/dist/newsletter/subscriptions.d.ts +87 -0
- package/dist/newsletter/subscriptions.js +119 -0
- package/dist/newsletter/tool-registrations.d.ts +89 -0
- package/dist/newsletter/tool-registrations.deps.d.ts +9 -0
- package/dist/newsletter/tool-registrations.deps.js +9 -0
- package/dist/newsletter/tool-registrations.js +133 -0
- package/dist/newsletter/tool-registrations.read.d.ts +76 -0
- package/dist/newsletter/tool-registrations.read.js +140 -0
- package/dist/newsletter/tool-registrations.write.d.ts +54 -0
- package/dist/newsletter/tool-registrations.write.js +229 -0
- package/dist/newsletter/types.d.ts +279 -0
- package/dist/newsletter/types.js +23 -0
- package/dist/newsletter/unsubscribe.d.ts +41 -0
- package/dist/newsletter/unsubscribe.js +100 -0
- package/dist/project-keys/attached-vault.d.ts +23 -0
- package/dist/project-keys/attached-vault.js +65 -0
- package/dist/project-keys/create-vault.d.ts +17 -0
- package/dist/project-keys/create-vault.js +29 -0
- package/dist/project-keys/service.d.ts +133 -0
- package/dist/project-keys/service.js +128 -0
- package/dist/project-keys/site-references.d.ts +30 -0
- package/dist/project-keys/site-references.js +63 -0
- package/dist/project-keys/site-sealer.d.ts +28 -0
- package/dist/project-keys/site-sealer.js +64 -0
- package/dist/project-keys/sql/attachments.d.ts +33 -0
- package/dist/project-keys/sql/attachments.js +55 -0
- package/dist/project-keys/tools.d.ts +86 -0
- package/dist/project-keys/tools.js +66 -0
- package/dist/public-http/routes/mail/feedback.d.ts +44 -0
- package/dist/public-http/routes/mail/feedback.js +17 -0
- package/dist/public-http/routes/newsletter/confirm.d.ts +38 -0
- package/dist/public-http/routes/newsletter/confirm.js +33 -0
- package/dist/public-http/routes/newsletter/page.d.ts +29 -0
- package/dist/public-http/routes/newsletter/page.js +34 -0
- package/dist/public-http/routes/newsletter/unsubscribe.d.ts +33 -0
- package/dist/public-http/routes/newsletter/unsubscribe.js +35 -0
- package/dist/react/auth/Passkeys.d.ts +2 -34
- package/dist/react/auth/RecoveryCodesCard.d.ts +27 -0
- package/dist/react/auth/RecoveryCodesCard.hooks.d.ts +67 -0
- package/dist/react/auth/RecoveryCodesCard.hooks.js +38 -0
- package/dist/react/auth/RecoveryCodesCard.js +56 -0
- package/dist/react/auth/TotpSettings.d.ts +2 -23
- package/dist/react/auth/local-owner-signin.d.ts +40 -0
- package/dist/react/auth/local-owner-signin.js +25 -0
- package/dist/react/auth/owner-mfa-api.d.ts +10 -0
- package/dist/react/auth/owner-mfa-api.js +17 -0
- package/dist/react/auth/owner-passkey-api.d.ts +11 -0
- package/dist/react/auth/owner-passkey-api.js +17 -0
- package/dist/react/auth/owner-recovery-api.d.ts +51 -0
- package/dist/react/auth/owner-recovery-api.js +29 -0
- package/dist/react/auth/owner-request.d.ts +7 -0
- package/dist/react/auth/owner-request.js +2 -0
- package/dist/react/index.d.ts +10 -0
- package/dist/react/index.js +6 -0
- package/dist/react/mail/Email.d.ts +20 -0
- package/dist/react/mail/Email.js +143 -0
- package/dist/react/mail/EmailProviderTab.d.ts +34 -0
- package/dist/react/mail/EmailProviderTab.js +132 -0
- package/dist/react/mail/EmailSegments.d.ts +24 -0
- package/dist/react/mail/EmailSegments.js +15 -0
- package/dist/react/mail/EmailTemplateEditor.d.ts +146 -0
- package/dist/react/mail/EmailTemplateEditor.js +116 -0
- package/dist/react/mail/email-view.types.d.ts +236 -0
- package/dist/react/mail/email-view.types.js +2 -0
- package/dist/react/members/Members.d.ts +5 -3
- package/dist/react/members/Members.js +3 -3
- package/dist/react/members/api/members-api.d.ts +37 -0
- package/dist/react/members/api/members-api.js +16 -0
- package/dist/react/members/hooks/use-members.hooks.js +2 -1
- package/dist/react/members/members-i18n.d.ts +23 -0
- package/dist/react/members/members-i18n.js +25 -0
- package/dist/react/members/members-i18n.locales-a.d.ts +4 -0
- package/dist/react/members/members-i18n.locales-a.js +294 -0
- package/dist/react/members/members-i18n.locales-b.d.ts +4 -0
- package/dist/react/members/members-i18n.locales-b.js +265 -0
- package/dist/react/models.d.ts +1 -49
- package/dist/react/ports.d.ts +3 -143
- package/dist/react/roles/api/roles-api.d.ts +74 -0
- package/dist/react/roles/api/roles-api.js +22 -0
- package/dist/react/testing.js +18 -9
- package/dist/react/users/UsersPanel.d.ts +30 -0
- package/dist/react/users/UsersPanel.hooks.d.ts +8 -0
- package/dist/react/users/UsersPanel.hooks.js +9 -0
- package/dist/react/users/UsersPanel.js +9 -0
- package/dist/react/users/api/users-api.d.ts +65 -0
- package/dist/react/users/api/users-api.js +46 -0
- package/dist/react/users/hooks/use-localized-users.hooks.d.ts +43 -0
- package/dist/react/users/hooks/use-localized-users.hooks.js +15 -0
- package/dist/react/users/hooks/use-users-state.hooks.d.ts +18 -18
- package/dist/react/users/password-reset-notice.d.ts +8 -0
- package/dist/react/users/password-reset-notice.js +36 -0
- package/dist/server/admin-crud-service.d.ts +4 -10
- package/dist/server/admin-crud-service.js +20 -6
- package/dist/server/agent-tool-registrations.js +26 -7
- package/dist/server/agent-tools.js +22 -7
- package/dist/server/auth-challenge.d.ts +1 -1
- package/dist/server/auth-service.js +2 -1
- package/dist/server/grant-service.d.ts +1 -0
- package/dist/server/grant-service.js +7 -4
- package/dist/server/mfa/passkey-service.d.ts +2 -2
- package/dist/server/mfa/passkey-service.js +1 -1
- package/dist/server/mfa/service.js +6 -4
- package/dist/server/repo.memory.d.ts +30 -2
- package/dist/server/repo.memory.js +58 -4
- package/dist/server/seed.js +3 -3
- package/dist/server/sql/assignments.d.ts +90 -0
- package/dist/server/sql/assignments.js +128 -0
- package/dist/server/sql/index.d.ts +6 -0
- package/dist/server/sql/index.js +5 -0
- package/dist/server/sql/kernel.d.ts +9 -0
- package/dist/server/sql/kernel.js +2 -0
- package/dist/server/sql/mfa.d.ts +36 -0
- package/dist/server/sql/mfa.js +51 -0
- package/dist/server/sql/passkeys.d.ts +25 -0
- package/dist/server/sql/passkeys.js +33 -0
- package/dist/server/sql/recovery-codes.d.ts +22 -0
- package/dist/server/sql/recovery-codes.js +32 -0
- package/package.json +909 -11
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { IdentityForbiddenError, IdentityNotFoundError, IdentityValidationError, OwnerRequiredError, principalKindMayExercisePermission } from "../core/index.js";
|
|
2
|
+
import { resolveEffectivePermissions } from "../server/authorize.js";
|
|
3
|
+
import { authorizeDepsFrom } from "../server/grant-service.js";
|
|
4
|
+
import { UserDeleteUnsupportedError } from "./user-purge-types.js";
|
|
5
|
+
/**
|
|
6
|
+
* @file `trashUser` (delete-user plan v2, decisions 4/5/7, and the OWNER DECISION 2026-09-24 that
|
|
7
|
+
* supersedes decision 1's "owner-role holders only" default) — moves a `kind='user'` or
|
|
8
|
+
* `kind='api_key'` principal to the Trash (disables it, revokes its sessions, indexes it for
|
|
9
|
+
* restore/purge) instead of hard-deleting it. Renamed from the v1 `deleteUser`, which called
|
|
10
|
+
* `UserPurgePort.purgeUser` directly; that hard-delete path is now reached only through the Trash's
|
|
11
|
+
* own purge (`purgeSelected`, or the retention sweeper 60 days later), never straight from this
|
|
12
|
+
* transition.
|
|
13
|
+
*
|
|
14
|
+
* Purpose:
|
|
15
|
+
* Same shape `admin-crud-service.ts`'s `disablePrincipal` and the v1 `deleteUser` already used
|
|
16
|
+
* (`{ deps: AuthServiceDeps, input: {...} }`, plain-`Error`-subclass control flow), now delegating
|
|
17
|
+
* the actual state change to a `RemoveEntity`-shaped callback (`removeUser`) bound to the Trash at
|
|
18
|
+
* composition, instead of writing to `principals` itself.
|
|
19
|
+
*
|
|
20
|
+
* Architectural role:
|
|
21
|
+
* Ordinary core function, not a port (mirrors `disablePrincipal`'s reasoning). `removeUser`'s type
|
|
22
|
+
* below (`RemoveUserFn`) is a structural copy of `features/trash`'s `RemoveEntity`/`TrashMarkerResult`
|
|
23
|
+
* — this file deliberately does not import the Trash feature, the same "no cross-feature import,
|
|
24
|
+
* only a structurally-compatible callback" convention `features/post/post.ts`'s `RemovePostFn`
|
|
25
|
+
* uses for the identical seam. `principalHoldsOwnerWildcard`/`countActiveOwnerWildcardPrincipals`
|
|
26
|
+
* are a private copy of `admin-crud-service.ts`'s same-named helpers, for the reason given below.
|
|
27
|
+
*/
|
|
28
|
+
/** Self-trash, permanent delete and disable refusal (409 `SELF_DELETE`). */
|
|
29
|
+
export class SelfDeleteError extends Error {
|
|
30
|
+
}
|
|
31
|
+
/** OWNER DECISION 2026-09-24 (delete-user plan v2, decision 7) — thrown by `enable`/`update`/
|
|
32
|
+
* `reset-password` when the target principal currently has a `trashed_items` row: those
|
|
33
|
+
* transitions must refuse a trashed principal rather than silently reactivate one still indexed
|
|
34
|
+
* for purge. Maps to 409 `USER_IN_TRASH` at the route layer. Declared here, not in each route
|
|
35
|
+
* file, so every consumer throws (and every route maps) the exact same error identity. */
|
|
36
|
+
export class UserInTrashError extends Error {
|
|
37
|
+
}
|
|
38
|
+
/** OWNER DECISION 2026-09-24 (delete-user plan v2, decision 7) — thrown by `create` when the
|
|
39
|
+
* requested username belongs to a principal currently in the Trash: the username stays reserved
|
|
40
|
+
* until that principal is restored or purged. Maps to 409 `USERNAME_IN_TRASH`. */
|
|
41
|
+
export class UsernameInTrashError extends Error {
|
|
42
|
+
}
|
|
43
|
+
// Repo-bag assembly and its sharing rationale now live in Jini user-management/server (grant-service.ts).
|
|
44
|
+
/** Private copy of `admin-crud-service.ts`'s same-named helper — see this file's header for why. */
|
|
45
|
+
export async function principalHoldsOwnerWildcard(required, _optional = {}) {
|
|
46
|
+
const { deps, workspaceId, principalId } = required;
|
|
47
|
+
const effectiveRows = await resolveEffectivePermissions({
|
|
48
|
+
deps: authorizeDepsFrom(deps.repos),
|
|
49
|
+
principalId,
|
|
50
|
+
workspaceId,
|
|
51
|
+
});
|
|
52
|
+
return effectiveRows.some((row) => row.permission === "*" && row.resourceType == null && row.constraintJson == null);
|
|
53
|
+
}
|
|
54
|
+
/** Builtin admin identity is role-scoped, never inferred from a custom permission grant.
|
|
55
|
+
* The host reconciles user.manage for builtin admins under the 2026-10-07 target rule. */
|
|
56
|
+
export async function principalHoldsBuiltinAdminRole(required, _optional = {}) {
|
|
57
|
+
const { deps, workspaceId, principalId } = required;
|
|
58
|
+
const roleLinks = await deps.repos.principalRoles.listByPrincipalId({ workspaceId, principalId });
|
|
59
|
+
const roles = await Promise.all(roleLinks.map((link) => deps.repos.roles.findById({ workspaceId, id: link.roleId })));
|
|
60
|
+
return roles.some((role) => role != null && role.isBuiltin && role.name === "admin");
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* OWNER DECISION 2026-10-07 narrows the 2026-09-24 admin trash authority:
|
|
64
|
+
* "other admins should not be able to delete other admins accounts, only the owner can do that"
|
|
65
|
+
* "i shouldnt be allowed to delete my own account right?"
|
|
66
|
+
* Admin callers retain ordinary-user trash authority. Target-aware guards below apply before
|
|
67
|
+
* every destructive transition, regardless of the caller's broader permission grants.
|
|
68
|
+
*/
|
|
69
|
+
/**
|
|
70
|
+
* Caller classification from 2026-09-24, narrowed by the 2026-10-07 target rule above: true
|
|
71
|
+
* iff `callerPrincipalId` is the owner (an unconstrained `*` holder) or holds the built-in `admin`
|
|
72
|
+
* role — never a custom role, even one granted `user.manage` via `role.manage`.
|
|
73
|
+
*
|
|
74
|
+
* Exported (not just `assertCallerMayManageUserTrash` below) so the Trash's generic restore/purge
|
|
75
|
+
* routes can reuse the SAME rule as a boolean check: those routes gate through
|
|
76
|
+
* `TrashAuthorizeFn`/`mayActOnEntityType` (`features/trash/permissions.ts`), which is boolean-
|
|
77
|
+
* shaped, not exception-shaped, and lives in a different feature this file deliberately does not
|
|
78
|
+
* import (see this file's header) — the composition root wraps that boolean callback around this
|
|
79
|
+
* function for `entityType === "user"` only (`server/runtime/composition/trash-user-admin-
|
|
80
|
+
* override.ts`), so the initial trash action and a later restore/purge of the same user can never
|
|
81
|
+
* drift onto two different rules for who may act on it.
|
|
82
|
+
*
|
|
83
|
+
* @complexity O(1) `resolveEffectivePermissions` call plus O(1)
|
|
84
|
+
* `principalHoldsBuiltinAdminRole` call — evaluated in that order so the common case (the owner)
|
|
85
|
+
* never pays for the role lookup.
|
|
86
|
+
*/
|
|
87
|
+
export async function callerMayManageUserTrash(required) {
|
|
88
|
+
const { deps, workspaceId, callerPrincipalId } = required;
|
|
89
|
+
const isOwner = await principalHoldsOwnerWildcard({ deps, workspaceId, principalId: callerPrincipalId });
|
|
90
|
+
if (isOwner)
|
|
91
|
+
return true;
|
|
92
|
+
return principalHoldsBuiltinAdminRole({ deps, workspaceId, principalId: callerPrincipalId });
|
|
93
|
+
}
|
|
94
|
+
/** Throws unless {@link callerMayManageUserTrash} says the caller may act. `IdentityForbiddenError`
|
|
95
|
+
* is the same error `assertCallerHasAnyPermission` throws for every other permission gate in this
|
|
96
|
+
* codebase, so the route layer's existing 403 mapping needs no new branch.
|
|
97
|
+
* @complexity See {@link callerMayManageUserTrash}. */
|
|
98
|
+
async function assertCallerMayManageUserTrash(required) {
|
|
99
|
+
const { deps, workspaceId, callerPrincipalId } = required;
|
|
100
|
+
if (await callerMayManageUserTrash({ deps, workspaceId, callerPrincipalId }))
|
|
101
|
+
return;
|
|
102
|
+
throw new IdentityForbiddenError({ message: `principal '${callerPrincipalId}' is not authorized to trash, restore or permanently delete users`, permission: "*", reason: "no_grant" });
|
|
103
|
+
}
|
|
104
|
+
/** Private copy of `admin-crud-service.ts`'s same-named helper — see this file's header for why.
|
|
105
|
+
* @complexity O(n) in the workspace's principal count, same bound that helper documents. */
|
|
106
|
+
async function countActiveOwnerWildcardPrincipals(required) {
|
|
107
|
+
const { deps, workspaceId } = required;
|
|
108
|
+
const allPrincipals = await deps.repos.principals.list({ workspaceId });
|
|
109
|
+
// Same kind bar as the library helper: a site member can never be the remaining owner, and the
|
|
110
|
+
// member roster costs no grant reads here.
|
|
111
|
+
const activePrincipals = allPrincipals.filter((principal) => principal.status === "active" && principalKindMayExercisePermission({ kind: principal.kind, permission: "*" }));
|
|
112
|
+
const flags = await Promise.all(activePrincipals.map((principal) => principalHoldsOwnerWildcard({ deps, workspaceId, principalId: principal.id })));
|
|
113
|
+
return flags.filter(Boolean).length;
|
|
114
|
+
}
|
|
115
|
+
/** Post-write invariant for grant removal; throw inside the transaction so the write rolls back. */
|
|
116
|
+
export async function assertActiveOwnerFloor(required, _optional = {}) {
|
|
117
|
+
if (await countActiveOwnerWildcardPrincipals(required) <= 0) {
|
|
118
|
+
throw new OwnerRequiredError({ message: "the workspace must keep at least one active owner-`*` principal" });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** Shared classification for the target rule and Users roster affordances. */
|
|
122
|
+
export async function userAccountProtection(required, _optional = {}) {
|
|
123
|
+
const { deps, workspaceId, principalId } = required;
|
|
124
|
+
const isOwner = await principalHoldsOwnerWildcard({ deps, workspaceId, principalId });
|
|
125
|
+
const links = await deps.repos.principalRoles.listByPrincipalId({ workspaceId, principalId });
|
|
126
|
+
const roles = await Promise.all(links.map(link => deps.repos.roles.findById({ workspaceId, id: link.roleId })));
|
|
127
|
+
return { isOwner, isProtectedAccount: isOwner || roles.some(role => role?.isBuiltin && (role.name === "admin" || role.name === "owner")) };
|
|
128
|
+
}
|
|
129
|
+
/** Only the destructive actions guard against self-targeting: resetting your own password is
|
|
130
|
+
* allowed, and a disabled account cannot sign in to re-enable itself (an active owner re-enabling
|
|
131
|
+
* itself is a harmless no-op the roster relies on). */
|
|
132
|
+
const SELF_TARGET_REFUSED = new Set(["trash", "purge", "disable"]);
|
|
133
|
+
/** B151 (owner rule 2026-11-20): "only the owner may re-enable an owner-disabled admin" — so
|
|
134
|
+
* `enable` gets its own plain wording instead of the destructive-action sentence. An owner target
|
|
135
|
+
* keeps the library's existing "modify an owner principal" sentence the roster already shows. */
|
|
136
|
+
function ownerRequiredMessage({ action, targetIsOwner }) {
|
|
137
|
+
if (action !== "enable")
|
|
138
|
+
return "only an owner can delete, trash, disable or reset the password of an admin or owner account";
|
|
139
|
+
return targetIsOwner ? "only an owner can modify an owner principal" : "only an owner can turn an admin account back on";
|
|
140
|
+
}
|
|
141
|
+
/** The owner-only gate, split out of {@link assertUserAccountAction} to keep it within the
|
|
142
|
+
* complexity cap: a protected (admin/owner or seeded-owner) target needs a caller who holds the
|
|
143
|
+
* owner wildcard; a call with no caller (system paths) is not gated here. */
|
|
144
|
+
async function assertCallerMayActOnProtected(required, _optional = {}) {
|
|
145
|
+
const { deps, workspaceId, action, callerPrincipalId, protectedTarget, targetIsOwner } = required;
|
|
146
|
+
if (callerPrincipalId === undefined || !protectedTarget)
|
|
147
|
+
return;
|
|
148
|
+
if (await principalHoldsOwnerWildcard({ deps, workspaceId, principalId: callerPrincipalId }))
|
|
149
|
+
return;
|
|
150
|
+
throw new OwnerRequiredError({ message: ownerRequiredMessage({ action, targetIsOwner }) });
|
|
151
|
+
}
|
|
152
|
+
/** The owner account contract. Run inside the
|
|
153
|
+
* same identity transaction as the write. Retention has no caller, but still preserves owners. */
|
|
154
|
+
export async function assertUserAccountAction(required, optional = {}) {
|
|
155
|
+
const { deps, workspaceId, principalId, action } = required;
|
|
156
|
+
const { callerPrincipalId, seededOwnerPrincipalId } = optional;
|
|
157
|
+
if (SELF_TARGET_REFUSED.has(action) && principalId === callerPrincipalId) {
|
|
158
|
+
throw new SelfDeleteError(action === "disable" ? "you cannot disable your own account" : "you cannot delete your own account");
|
|
159
|
+
}
|
|
160
|
+
const target = await deps.repos.principals.findById({ workspaceId, id: principalId });
|
|
161
|
+
if (!target)
|
|
162
|
+
throw new IdentityNotFoundError({ message: `principal '${principalId}' was not found` });
|
|
163
|
+
const { isOwner: owner, isProtectedAccount } = await userAccountProtection({ deps, workspaceId, principalId });
|
|
164
|
+
const isSeededOwner = principalId === seededOwnerPrincipalId;
|
|
165
|
+
await assertCallerMayActOnProtected({ deps, workspaceId, action, callerPrincipalId,
|
|
166
|
+
protectedTarget: isProtectedAccount || isSeededOwner, targetIsOwner: owner || isSeededOwner });
|
|
167
|
+
await assertDestructiveAccountInvariants({ deps, workspaceId, principalId, action, targetStatus: target.status, owner }, { seededOwnerPrincipalId });
|
|
168
|
+
}
|
|
169
|
+
async function assertDestructiveAccountInvariants(required, optional = {}) {
|
|
170
|
+
const { deps, workspaceId, principalId, action, targetStatus, owner } = required;
|
|
171
|
+
// Neither action removes an active owner, so the seeded-owner and owner-floor checks do not apply.
|
|
172
|
+
if (action === "reset-password" || action === "enable")
|
|
173
|
+
return;
|
|
174
|
+
if (principalId === optional.seededOwnerPrincipalId) {
|
|
175
|
+
throw new OwnerRequiredError({ message: action === "disable" ? "the seeded owner principal can never be disabled" : "the seeded owner principal can never be deleted" });
|
|
176
|
+
}
|
|
177
|
+
if (targetStatus === "active" && owner && await countActiveOwnerWildcardPrincipals({ deps, workspaceId }) <= 1) {
|
|
178
|
+
throw new OwnerRequiredError({ message: "the workspace must keep at least one active owner-`*` principal" });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function trashRemovalInput({ identity, input, target, title, subtitle }) {
|
|
182
|
+
return {
|
|
183
|
+
workspaceId: input.workspaceId,
|
|
184
|
+
id: target.id,
|
|
185
|
+
display: { title, subtitle },
|
|
186
|
+
at: new Date(identity.clock.nowMs()).toISOString(),
|
|
187
|
+
expectedVersion: null,
|
|
188
|
+
actor: { principalId: input.callerPrincipalId },
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Moves a user (or the orphan `api_key` "runner" principal) to the Trash. Checked in order: caller
|
|
193
|
+
* is the owner or holds the built-in `admin` role (OWNER DECISION 2026-09-24), target exists,
|
|
194
|
+
* target is `kind='user'` or `kind='api_key'`, target is not the caller, target is not the seeded
|
|
195
|
+
* owner, target is not the workspace's last active owner-`*` principal. A target already in the
|
|
196
|
+
* Trash is an idempotent no-op. On success, delegates the state change to `deps.removeUser`
|
|
197
|
+
* (disables the principal, revokes its sessions, and indexes it for the Trash screen — see
|
|
198
|
+
* `features/trash/adapters/user.ts`), which records its own `identity.user.trashed` audit event.
|
|
199
|
+
*
|
|
200
|
+
* @complexity O(n) in the workspace's principal count (the owner-count guard, same bound
|
|
201
|
+
* `disablePrincipal` documents) plus `deps.removeUser`'s own O(1) transaction.
|
|
202
|
+
*/
|
|
203
|
+
async function runTrashUser(required) {
|
|
204
|
+
const { deps, input } = required;
|
|
205
|
+
const { identity, removeUser, isInTrash } = deps;
|
|
206
|
+
await assertCallerMayManageUserTrash({
|
|
207
|
+
deps: identity,
|
|
208
|
+
workspaceId: input.workspaceId,
|
|
209
|
+
callerPrincipalId: input.callerPrincipalId,
|
|
210
|
+
});
|
|
211
|
+
const target = await identity.repos.principals.findById({
|
|
212
|
+
workspaceId: input.workspaceId,
|
|
213
|
+
id: input.principalId,
|
|
214
|
+
});
|
|
215
|
+
if (!target)
|
|
216
|
+
throw new IdentityNotFoundError({ message: `principal '${input.principalId}' was not found` });
|
|
217
|
+
if (target.kind !== "user" && target.kind !== "api_key") {
|
|
218
|
+
throw new IdentityValidationError({ message: `DELETE_USER target must be a user or api_key principal, got kind='${target.kind}'` });
|
|
219
|
+
}
|
|
220
|
+
await assertUserAccountAction({ deps: identity, workspaceId: input.workspaceId, principalId: target.id, action: "trash" }, { callerPrincipalId: input.callerPrincipalId, seededOwnerPrincipalId: input.seededOwnerPrincipalId });
|
|
221
|
+
if (await isInTrash({ principalId: target.id })) {
|
|
222
|
+
return { ok: true, version: null, noop: true };
|
|
223
|
+
}
|
|
224
|
+
let title = target.displayName;
|
|
225
|
+
let subtitle = null;
|
|
226
|
+
if (target.kind === "user") {
|
|
227
|
+
const user = await identity.repos.users.findByPrincipalId({
|
|
228
|
+
workspaceId: input.workspaceId,
|
|
229
|
+
principalId: target.id,
|
|
230
|
+
});
|
|
231
|
+
if (!user)
|
|
232
|
+
throw new IdentityNotFoundError({ message: `user '${target.id}' was not found` });
|
|
233
|
+
title = user.username;
|
|
234
|
+
subtitle = user.email ?? null;
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
subtitle = "API key";
|
|
238
|
+
}
|
|
239
|
+
if (!removeUser) {
|
|
240
|
+
throw new UserDeleteUnsupportedError("this identity store has no Trash wiring; users cannot be deleted (composition-only limitation)");
|
|
241
|
+
}
|
|
242
|
+
return removeUser(trashRemovalInput({ identity, input, target, title, subtitle }));
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Serializes `trashUser` calls (decision 4's concurrency rule, carried over unchanged from v1's
|
|
246
|
+
* `deleteUser`): without this, two concurrent trashes targeting the workspace's only two active
|
|
247
|
+
* owner-`*` principals could each read `activeOwnerCount === 2` before either write lands, and both
|
|
248
|
+
* would pass the INV-08 guard — chaining every call onto one promise makes the read-then-write
|
|
249
|
+
* sequence for one call fully finish (or throw) before the next call's read begins.
|
|
250
|
+
* Factory-owned, not module-level: the host creates ONE instance per process at composition, and
|
|
251
|
+
* every caller (the admin route, the assistant's `trash_item` port) shares it. Not per-workspace:
|
|
252
|
+
* a host that runs one workspace per process gets a single chain exactly as serialized as a
|
|
253
|
+
* per-workspace map would be, with no map to leak.
|
|
254
|
+
*
|
|
255
|
+
* @complexity O(1) to enqueue; each call costs {@link runTrashUser}'s own bound once it runs.
|
|
256
|
+
*/
|
|
257
|
+
export function createTrashUserService(_required = {}, _optional = {}) {
|
|
258
|
+
let tail = Promise.resolve();
|
|
259
|
+
return {
|
|
260
|
+
trashUser(required) {
|
|
261
|
+
const { deps, input } = required;
|
|
262
|
+
// Keep the local queue's historical ordering, and join the shared transaction so competing
|
|
263
|
+
// grant/status writers cannot race its owner-floor reads. The Trash runner joins this kernel.
|
|
264
|
+
const atomicRun = () => deps.identity.repos.transactions.run({ workspaceId: input.workspaceId, execute: () => runTrashUser({ deps, input }) });
|
|
265
|
+
const result = tail.then(atomicRun, atomicRun);
|
|
266
|
+
// Swallow the rejection on `tail` itself (not on `result`, which the caller still awaits and
|
|
267
|
+
// sees rejected) so one failed trash never poisons the chain for every trash queued after it —
|
|
268
|
+
// the same "chain for ordering only, never for the value" shape a serialization promise needs
|
|
269
|
+
// to stay usable across repeated failures.
|
|
270
|
+
tail = result.catch(() => undefined);
|
|
271
|
+
return result;
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
//# sourceMappingURL=delete-user-service.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type OwnerRecoveryDeps } from '../server/recovery-codes.js';
|
|
2
|
+
/**
|
|
3
|
+
* Incident-driven (2026-09-03): the admin UI's own "Reset password" flow was used against
|
|
4
|
+
* production, closed with no error, and afterward NEITHER the old nor the new password could log
|
|
5
|
+
* in. Tracing `Users.tsx` -> `api.ts` -> the `reset-password` route -> `@jini-ai/cms`'s
|
|
6
|
+
* `resetUserPassword` -> `Argon2PasswordHasher` found the LOCAL source of every one of those to be
|
|
7
|
+
* logically correct (same hasher instance hashes and verifies; no double-hash; no wrong-field
|
|
8
|
+
* write) — but the host's production image installs `@jini-ai/cms` from the npm registry
|
|
9
|
+
* (`check-no-linked-jini.mjs`), not from this local Jini checkout, so a bug specific to the
|
|
10
|
+
* published package (or to something else entirely) cannot be ruled out from here. This module
|
|
11
|
+
* exists to make that irrelevant: it does not trust that a write succeeded just because
|
|
12
|
+
* `resetUserPassword` returned without throwing — it re-reads the row fresh and calls
|
|
13
|
+
* `hasher.verify()` against the exact password just set, through the SAME hasher instance the real
|
|
14
|
+
* login path (`auth-service.ts`'s `login()`) uses. A hash that was written but does not verify is
|
|
15
|
+
* exactly the failure this incident produced, and is now caught here instead of reported as
|
|
16
|
+
* success.
|
|
17
|
+
*
|
|
18
|
+
* Boot keeps a pre-write restore point (scope boot-admin-password-reset), captured anew for each
|
|
19
|
+
* actual password change. Jini now verifies inside the identity transaction and rolls back a failed
|
|
20
|
+
* verification, instead of restoring an open database inode. The snapshot remains available for
|
|
21
|
+
* operator recovery; a manual file restore requires a restart to reopen the restored database.
|
|
22
|
+
* A satisfied host secret skips hashing, session revocation and the full-database copy.
|
|
23
|
+
*/
|
|
24
|
+
/** Thin host-secret adapter shared by boot and CLI; identity rules and reset live in Jini.
|
|
25
|
+
* A secret left set must not re-salt the credential or revoke sessions again on every boot.
|
|
26
|
+
* @returns Current owner username for safe completion output; never returns the password/hash.
|
|
27
|
+
* @complexity O(1) when satisfied; otherwise O(s) for the existing reset's owner session revocation.
|
|
28
|
+
*/
|
|
29
|
+
export declare function applyOwnerPasswordReset({ deps, workspaceId, password, username }: {
|
|
30
|
+
deps: OwnerRecoveryDeps;
|
|
31
|
+
workspaceId: string;
|
|
32
|
+
password: string;
|
|
33
|
+
username?: string;
|
|
34
|
+
}, { beforeReset }?: {
|
|
35
|
+
beforeReset?: () => Promise<unknown>;
|
|
36
|
+
}): Promise<string>;
|
|
37
|
+
//# sourceMappingURL=owner-reset-env.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { resolveOwnerResetTarget, resetOwnerPassword } from '../server/recovery-codes.js';
|
|
2
|
+
/**
|
|
3
|
+
* Incident-driven (2026-09-03): the admin UI's own "Reset password" flow was used against
|
|
4
|
+
* production, closed with no error, and afterward NEITHER the old nor the new password could log
|
|
5
|
+
* in. Tracing `Users.tsx` -> `api.ts` -> the `reset-password` route -> `@jini-ai/cms`'s
|
|
6
|
+
* `resetUserPassword` -> `Argon2PasswordHasher` found the LOCAL source of every one of those to be
|
|
7
|
+
* logically correct (same hasher instance hashes and verifies; no double-hash; no wrong-field
|
|
8
|
+
* write) — but the host's production image installs `@jini-ai/cms` from the npm registry
|
|
9
|
+
* (`check-no-linked-jini.mjs`), not from this local Jini checkout, so a bug specific to the
|
|
10
|
+
* published package (or to something else entirely) cannot be ruled out from here. This module
|
|
11
|
+
* exists to make that irrelevant: it does not trust that a write succeeded just because
|
|
12
|
+
* `resetUserPassword` returned without throwing — it re-reads the row fresh and calls
|
|
13
|
+
* `hasher.verify()` against the exact password just set, through the SAME hasher instance the real
|
|
14
|
+
* login path (`auth-service.ts`'s `login()`) uses. A hash that was written but does not verify is
|
|
15
|
+
* exactly the failure this incident produced, and is now caught here instead of reported as
|
|
16
|
+
* success.
|
|
17
|
+
*
|
|
18
|
+
* Boot keeps a pre-write restore point (scope boot-admin-password-reset), captured anew for each
|
|
19
|
+
* actual password change. Jini now verifies inside the identity transaction and rolls back a failed
|
|
20
|
+
* verification, instead of restoring an open database inode. The snapshot remains available for
|
|
21
|
+
* operator recovery; a manual file restore requires a restart to reopen the restored database.
|
|
22
|
+
* A satisfied host secret skips hashing, session revocation and the full-database copy.
|
|
23
|
+
*/
|
|
24
|
+
/** Thin host-secret adapter shared by boot and CLI; identity rules and reset live in Jini.
|
|
25
|
+
* A secret left set must not re-salt the credential or revoke sessions again on every boot.
|
|
26
|
+
* @returns Current owner username for safe completion output; never returns the password/hash.
|
|
27
|
+
* @complexity O(1) when satisfied; otherwise O(s) for the existing reset's owner session revocation.
|
|
28
|
+
*/
|
|
29
|
+
export async function applyOwnerPasswordReset({ deps, workspaceId, password, username }, { beforeReset } = {}) {
|
|
30
|
+
const input = { workspaceId, principalId: deps.seededOwnerPrincipalId };
|
|
31
|
+
const owner = await resolveOwnerResetTarget({ deps, input: { ...input, ...(username === undefined ? {} : { username }) } }, {});
|
|
32
|
+
if (!await deps.auth.hasher.verify({ hash: owner.passwordHash, password })) {
|
|
33
|
+
await beforeReset?.();
|
|
34
|
+
await resetOwnerPassword({ deps, input: { ...input, password } }, {});
|
|
35
|
+
}
|
|
36
|
+
return owner.username;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=owner-reset-env.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type PermissionMigrationRegistry } from "../server/permission-migrations.js";
|
|
2
|
+
import { type BuiltinRoleGrantRegistry } from "./builtin-role-grants.js";
|
|
3
|
+
/**
|
|
4
|
+
* @file The one object that says which permission grants boot reconciles.
|
|
5
|
+
*
|
|
6
|
+
* Both boot-time grant paths read it: `migrateDeprecatedPermissionGrants` (`migrations`, the
|
|
7
|
+
* `from`-anchored fan-out) and `applyBuiltinRoleGrants` (`roleGrants`, stated against a built-in
|
|
8
|
+
* role). A composition root creates one, lets each feature that owns a permission register its own
|
|
9
|
+
* grants on it explicitly (`server/runtime/composition/app-permission-grants.ts` is that list), and
|
|
10
|
+
* passes it to identity wiring as a port.
|
|
11
|
+
*
|
|
12
|
+
* Both registries used to be module singletons filled by import side effects, so the grants a
|
|
13
|
+
* process reconciled depended on which modules it happened to import: every real composition root
|
|
14
|
+
* reached `features/pages/permissions.ts` only through an unrelated barrel import, and
|
|
15
|
+
* `development/scripts/backfill-reset-admin-password.ts` did not reach it at all and reconciled
|
|
16
|
+
* against an empty registry (`11aa47080`).
|
|
17
|
+
*/
|
|
18
|
+
export interface PermissionGrantRegistry {
|
|
19
|
+
/** `{from, to}` fan-out pairs, seeded with `@jini-ai/user-management`'s built-in pairs. */
|
|
20
|
+
readonly migrations: PermissionMigrationRegistry;
|
|
21
|
+
/** `{role, permission}` grants onto a built-in role's own built-in policy. */
|
|
22
|
+
readonly roleGrants: BuiltinRoleGrantRegistry;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a registry holding only the library's built-in migration pairs and no host grants. Feature
|
|
26
|
+
* `register*PermissionGrants` functions add to it; nothing is registered by importing a module.
|
|
27
|
+
*
|
|
28
|
+
* @complexity O(b) where b = built-in migration pairs.
|
|
29
|
+
*/
|
|
30
|
+
export declare function createPermissionGrantRegistry(_required?: Record<string, never>, _optional?: Record<string, never>): PermissionGrantRegistry;
|
|
31
|
+
//# sourceMappingURL=permission-grants.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createPermissionMigrationRegistry } from "../server/permission-migrations.js";
|
|
2
|
+
import { createBuiltinRoleGrantRegistry } from "./builtin-role-grants.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create a registry holding only the library's built-in migration pairs and no host grants. Feature
|
|
5
|
+
* `register*PermissionGrants` functions add to it; nothing is registered by importing a module.
|
|
6
|
+
*
|
|
7
|
+
* @complexity O(b) where b = built-in migration pairs.
|
|
8
|
+
*/
|
|
9
|
+
export function createPermissionGrantRegistry(_required = {}, _optional = {}) {
|
|
10
|
+
return { migrations: createPermissionMigrationRegistry({}), roleGrants: createBuiltinRoleGrantRegistry({}) };
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=permission-grants.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type AgentToolSideEffect, type ToolRegistration } from "@jini-ai/core";
|
|
2
|
+
import { type AuthorizeFn } from "@jini-ai/core/contracts/events";
|
|
3
|
+
import type { ToolContributor } from "@jini-ai/core";
|
|
4
|
+
import type { PolicyRepoPort, PolicyPermissionRepoPort } from "../core/index.js";
|
|
5
|
+
/** Read ports only; no permission grants or user credentials. */
|
|
6
|
+
export interface Deps {
|
|
7
|
+
workspaceId: string;
|
|
8
|
+
authorize: AuthorizeFn;
|
|
9
|
+
policyRepo: Pick<PolicyRepoPort, "findById">;
|
|
10
|
+
policyPermissionRepo: Pick<PolicyPermissionRepoPort, "listByPolicyId">;
|
|
11
|
+
}
|
|
12
|
+
/** Independently derived from the service calls below. */
|
|
13
|
+
export declare const derivedRisk: ReadonlyMap<string, AgentToolSideEffect>;
|
|
14
|
+
/**
|
|
15
|
+
* Builds the handler with injectable admin-service dependencies.
|
|
16
|
+
* @param deps - Workspace, authorization and service ports.
|
|
17
|
+
* @returns One registration; readOnly follows the independently checked risk.
|
|
18
|
+
* @throws ToolInputError for actionable input refusals; authorization and service failures propagate.
|
|
19
|
+
* @complexity O(1) wiring; handler cost follows the wrapped service.
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildRegistrations({ deps, policy: hostPolicy }: {
|
|
22
|
+
deps: Deps;
|
|
23
|
+
policy: {
|
|
24
|
+
permission: string;
|
|
25
|
+
policyReadToolId: string;
|
|
26
|
+
};
|
|
27
|
+
}, _optional?: Record<string, never>): ToolRegistration[];
|
|
28
|
+
/** Installs this distinct domain without replacing its existing sibling tools. */
|
|
29
|
+
export declare function contributeIdentityPolicyListPermissionsTools({ policy }: {
|
|
30
|
+
policy: {
|
|
31
|
+
permission: string;
|
|
32
|
+
policyReadToolId: string;
|
|
33
|
+
};
|
|
34
|
+
}, _optional?: Record<string, never>): ToolContributor<Deps, unknown>;
|
|
35
|
+
//# sourceMappingURL=permission-list-tool.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { toolMetadata } from '@jini-ai/core/tool-metadata/identity';
|
|
2
|
+
import { ToolInputError } from "@jini-ai/core";
|
|
3
|
+
import { buildDomainRegistrations, indexCatalogById, requireInputRecord } from "@jini-ai/core";
|
|
4
|
+
import { adaptLegacyAuthorize, requireToolPermission } from "@jini-ai/core";
|
|
5
|
+
import {} from "@jini-ai/core/contracts/events";
|
|
6
|
+
/** Independently derived from the service calls below. */
|
|
7
|
+
export const derivedRisk = new Map([
|
|
8
|
+
// policyRepo.findById + policyPermissionRepo.listByPolicyId: reads only.
|
|
9
|
+
["identity_policy_list_permissions", "none"],
|
|
10
|
+
]);
|
|
11
|
+
/**
|
|
12
|
+
* Builds the handler with injectable admin-service dependencies.
|
|
13
|
+
* @param deps - Workspace, authorization and service ports.
|
|
14
|
+
* @returns One registration; readOnly follows the independently checked risk.
|
|
15
|
+
* @throws ToolInputError for actionable input refusals; authorization and service failures propagate.
|
|
16
|
+
* @complexity O(1) wiring; handler cost follows the wrapped service.
|
|
17
|
+
*/
|
|
18
|
+
export function buildRegistrations({ deps, policy: hostPolicy }, _optional = {}) {
|
|
19
|
+
/** Catalog for the admin service exposed through this standalone contributor. */
|
|
20
|
+
const catalog = [{
|
|
21
|
+
name: "identity_policy_list_permissions",
|
|
22
|
+
description: `Reads the permissions and resource constraints granted by one policy. Call to explain what a role can do after finding its policy id with ${hostPolicy.policyReadToolId}. Returns {policyPermissions}, an empty array when nothing is granted. Read-only: no grants or revocations. Unknown policies are refused with lookup guidance.`,
|
|
23
|
+
sideEffects: "none",
|
|
24
|
+
authorization: { permission: hostPolicy.permission },
|
|
25
|
+
inputSchema: { type: "object", additionalProperties: false, required: ["policyId"], properties: { policyId: { type: "string", minLength: 1 } } },
|
|
26
|
+
}];
|
|
27
|
+
return buildDomainRegistrations({ metadata: toolMetadata,
|
|
28
|
+
domain: "identity-policy-list-permissions", catalogModule: "features/identity/permission-list-tool.ts",
|
|
29
|
+
catalog: indexCatalogById({ catalog: catalog }), derivedRisk,
|
|
30
|
+
handlers: { identity_policy_list_permissions: async (ctx) => {
|
|
31
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: hostPolicy.permission });
|
|
32
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
33
|
+
const policyId = input.policyId;
|
|
34
|
+
if (typeof policyId !== "string" || policyId.trim() === "")
|
|
35
|
+
throw new ToolInputError({ message: "policyId must be a non-empty string." });
|
|
36
|
+
const policy = await deps.policyRepo.findById({ workspaceId: deps.workspaceId, id: policyId });
|
|
37
|
+
if (!policy)
|
|
38
|
+
throw new ToolInputError({ message: `policy '${policyId}' was not found. Use ${hostPolicy.policyReadToolId} to find a policy id.` });
|
|
39
|
+
return { policyPermissions: await deps.policyPermissionRepo.listByPolicyId({ workspaceId: deps.workspaceId, policyId }) };
|
|
40
|
+
} },
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/** Installs this distinct domain without replacing its existing sibling tools. */
|
|
44
|
+
export function contributeIdentityPolicyListPermissionsTools({ policy }, _optional = {}) {
|
|
45
|
+
return { domain: "identity-policy-list-permissions", build: deps => buildRegistrations({ deps, policy }), risk: derivedRisk };
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=permission-list-tool.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { StorageKernel } from "@jini-ai/core/contracts/storage";
|
|
2
|
+
import type { Kysely, RawBuilder } from "kysely";
|
|
3
|
+
import type { ApiKeyRecord, ApiKeyRepoPort } from "./api-key-types.js";
|
|
4
|
+
import type { SessionRepoPort, SessionRecord } from "../core/index.js";
|
|
5
|
+
export declare class SqlSessionRepo implements SessionRepoPort {
|
|
6
|
+
protected readonly kernel: StorageKernel<Kysely<unknown>, unknown>;
|
|
7
|
+
protected readonly table: string;
|
|
8
|
+
private readonly keepStoredRevocation;
|
|
9
|
+
constructor({ kernel, table, keepStoredRevocation }: {
|
|
10
|
+
kernel: StorageKernel<Kysely<unknown>, unknown>;
|
|
11
|
+
table: string;
|
|
12
|
+
keepStoredRevocation: (required: {
|
|
13
|
+
table: string;
|
|
14
|
+
}) => RawBuilder<string | null>;
|
|
15
|
+
}, _optional?: Record<string, never>);
|
|
16
|
+
findById(required: {
|
|
17
|
+
workspaceId: string;
|
|
18
|
+
id: string;
|
|
19
|
+
}): Promise<SessionRecord | null>;
|
|
20
|
+
findByTokenHash(required: {
|
|
21
|
+
workspaceId: string;
|
|
22
|
+
tokenHash: string;
|
|
23
|
+
}): Promise<SessionRecord | null>;
|
|
24
|
+
save(record: SessionRecord): Promise<void>;
|
|
25
|
+
revoke(required: {
|
|
26
|
+
workspaceId: string;
|
|
27
|
+
id: string;
|
|
28
|
+
revokedAt: string;
|
|
29
|
+
}): Promise<void>;
|
|
30
|
+
listByPrincipalId(required: {
|
|
31
|
+
workspaceId: string;
|
|
32
|
+
principalId: string;
|
|
33
|
+
}): Promise<SessionRecord[]>;
|
|
34
|
+
}
|
|
35
|
+
export declare class SqlApiKeyRepo implements ApiKeyRepoPort {
|
|
36
|
+
protected readonly kernel: StorageKernel<Kysely<unknown>, unknown>;
|
|
37
|
+
protected readonly table: string;
|
|
38
|
+
constructor({ kernel, table }: {
|
|
39
|
+
kernel: StorageKernel<Kysely<unknown>, unknown>;
|
|
40
|
+
table: string;
|
|
41
|
+
}, _optional?: Record<string, never>);
|
|
42
|
+
findById(required: {
|
|
43
|
+
workspaceId: string;
|
|
44
|
+
id: string;
|
|
45
|
+
}): Promise<ApiKeyRecord | null>;
|
|
46
|
+
/** The verification hot path — served by `idx_api_keys_workspace_prefix`, never a scan. */
|
|
47
|
+
findByPrefix(required: {
|
|
48
|
+
workspaceId: string;
|
|
49
|
+
prefix: string;
|
|
50
|
+
}): Promise<ApiKeyRecord | null>;
|
|
51
|
+
listByPrincipalId(required: {
|
|
52
|
+
workspaceId: string;
|
|
53
|
+
principalId: string;
|
|
54
|
+
}): Promise<ApiKeyRecord[]>;
|
|
55
|
+
save(record: ApiKeyRecord): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=repo.authentication.d.ts.map
|