@jini-ai/user-management 0.7.3-next.1 → 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.
- package/CHANGELOG.md +6 -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 +278 -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 +82 -0
- package/dist/newsletter/repo-subscribers.js +193 -0
- package/dist/newsletter/repo.d.ts +61 -0
- package/dist/newsletter/repo.js +147 -0
- package/dist/newsletter/repo.memory.d.ts +201 -0
- package/dist/newsletter/repo.memory.js +250 -0
- package/dist/newsletter/repo.rows.d.ts +221 -0
- package/dist/newsletter/repo.rows.js +260 -0
- package/dist/newsletter/send-pipeline.d.ts +236 -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 +20 -5
- package/dist/server/agent-tools.js +16 -3
- 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 +910 -12
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
|
+
/**
|
|
3
|
+
* @file A single-use, in-memory, per-launch token that can be exchanged once for a real admin
|
|
4
|
+
* session over loopback.
|
|
5
|
+
*
|
|
6
|
+
* Purpose:
|
|
7
|
+
* Lets a parent process that STARTED this server prove it started it, without anybody having to
|
|
8
|
+
* know a password. The token is minted at boot only when the launcher explicitly asks for one
|
|
9
|
+
* (the host's serve command with its `--emit-boot-token` flag), lives in this process's memory for the life of that launch, is
|
|
10
|
+
* handed to the launcher over the child's own stdout pipe, and is destroyed the moment it is
|
|
11
|
+
* redeemed.
|
|
12
|
+
*
|
|
13
|
+
* How it relates to the project:
|
|
14
|
+
* The host's serve command mints and emits it; the host's admin boot-session route
|
|
15
|
+
* (`POST /auth/boot-session`) redeems it. Browser dev uses this same factory with a
|
|
16
|
+
* request-scoped store after local-launch admission (`POST /auth/local-boot-session`), so its
|
|
17
|
+
* internal token never leaves server memory and cannot replace the launcher's process token.
|
|
18
|
+
*
|
|
19
|
+
* **This module knows nothing about who launches the server, and must stay that way.** There is no
|
|
20
|
+
* "am I in Electron" branch here and no host desktop-shell env-var name anywhere in this file or its callers'
|
|
21
|
+
* server-side halves. The contract is only: *hand me a valid single-use loopback token and I will
|
|
22
|
+
* start a session.* Browser dev's admission policy lives outside this store. Whoever redeems is
|
|
23
|
+
* not this store's business, which is what keeps the
|
|
24
|
+
* desktop shell deletable without leaving a server that misses it.
|
|
25
|
+
*
|
|
26
|
+
* Security properties, each one load-bearing:
|
|
27
|
+
*
|
|
28
|
+
* - **Nothing is persisted.** No file, no keystore, no config, no environment variable. A launch
|
|
29
|
+
* that ends takes its token with it. The token also never travels through the child's
|
|
30
|
+
* environment: an env block is readable from the process list by anything running as this user,
|
|
31
|
+
* whereas the stdout pipe is private to the parent that opened it.
|
|
32
|
+
* - **Fail closed when unarmed.** `redeem` on a store that was never minted into returns `false`
|
|
33
|
+
* for every input, including `""` and `undefined`. There is deliberately no branch anywhere in
|
|
34
|
+
* which "no token was minted" means "let this through" — a permissive arm here would turn every
|
|
35
|
+
* launch of the host into an open admin.
|
|
36
|
+
* - **Single use.** The first successful redeem clears the store, so a replay of the same token
|
|
37
|
+
* fails exactly like a wrong one. A FAILED redeem does not clear it: burning the token on a bad
|
|
38
|
+
* guess would let any local process disarm the real launcher's one redemption at will, and the
|
|
39
|
+
* token is 256-bit random, so guessing is not the threat that matters.
|
|
40
|
+
* - **Constant-time comparison.** Both sides are reduced to a fixed-length SHA-256 digest before
|
|
41
|
+
* `timingSafeEqual`, which requires equal lengths and would otherwise throw on a short input.
|
|
42
|
+
*
|
|
43
|
+
* Architectural role:
|
|
44
|
+
* A factory only — this module holds no state. The tests drive the factory, so no test has to
|
|
45
|
+
* reach into module state or reset a singleton between cases. The host builds exactly ONE store
|
|
46
|
+
* per process for the launcher token and hands that same instance to both call sites: its serve
|
|
47
|
+
* command (the minting side) and its boot-session route (the redeeming side). A mint and a redeem
|
|
48
|
+
* on two different stores would refuse every launcher token, so sharing that one instance is the
|
|
49
|
+
* host's job and the host pins it with a test. Neither call site needs the token through a
|
|
50
|
+
* route-deps bag, so the host can keep this state out of its composition root's dependency shape.
|
|
51
|
+
*/
|
|
52
|
+
/** Bytes of entropy per token. 32 bytes = 256 bits, the same size the identity library uses for a
|
|
53
|
+
* session's own raw token. */
|
|
54
|
+
const TOKEN_BYTES = 32;
|
|
55
|
+
/** SHA-256 digest of a raw token. Fixed length, which is what makes `timingSafeEqual` usable. */
|
|
56
|
+
function digest({ rawToken }, _options = {}) {
|
|
57
|
+
return createHash("sha256").update(rawToken, "utf8").digest();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Build an isolated single-use token store.
|
|
61
|
+
*
|
|
62
|
+
* @returns a {@link BootSessionTokenStore} holding at most one armed token.
|
|
63
|
+
* @complexity O(1) per operation; O(1) space (one 32-byte digest).
|
|
64
|
+
*/
|
|
65
|
+
export function createBootSessionTokenStore(_optional = {}) {
|
|
66
|
+
let armed = null;
|
|
67
|
+
return {
|
|
68
|
+
mint() {
|
|
69
|
+
const rawToken = randomBytes(TOKEN_BYTES).toString("base64url");
|
|
70
|
+
armed = digest({ rawToken });
|
|
71
|
+
return rawToken;
|
|
72
|
+
},
|
|
73
|
+
redeem({ rawToken }, _options = {}) {
|
|
74
|
+
if (armed === null)
|
|
75
|
+
return false;
|
|
76
|
+
if (typeof rawToken !== "string" || rawToken.length === 0)
|
|
77
|
+
return false;
|
|
78
|
+
// Compared against a local copy so a concurrent `mint` cannot change what this call is
|
|
79
|
+
// checking halfway through, and so the clear below cannot race a second redeem into
|
|
80
|
+
// succeeding against an already-spent token.
|
|
81
|
+
const expected = armed;
|
|
82
|
+
if (!timingSafeEqual(digest({ rawToken }), expected))
|
|
83
|
+
return false;
|
|
84
|
+
armed = null;
|
|
85
|
+
return true;
|
|
86
|
+
},
|
|
87
|
+
isArmed() {
|
|
88
|
+
return armed !== null;
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=boot-session-token.js.map
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { IdGenerator as IdGeneratorPort, UUID } from "@jini-ai/core/primitives";
|
|
2
|
+
import type { PolicyPermissionRepoPort, PolicyRepoPort, RolePolicyRepoPort, RoleRepoPort } from "../core/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* @file Boot-time backfill of a permission onto a BUILT-IN role's policy, for workspaces that were
|
|
5
|
+
* already seeded before that permission existed.
|
|
6
|
+
*
|
|
7
|
+
* ## The gap this closes
|
|
8
|
+
*
|
|
9
|
+
* There are two ways a permission reaches a policy in this system, and between them they miss a
|
|
10
|
+
* case that every deployed install is in:
|
|
11
|
+
*
|
|
12
|
+
* - `seedIdentity`'s built-in grant lists (`@jini-ai/cms`) reach a workspace exactly once, on first
|
|
13
|
+
* boot. It early-returns the moment an owner user exists, so a string added to those lists later
|
|
14
|
+
* provably never reaches an already-seeded workspace.
|
|
15
|
+
* - `migrateDeprecatedPermissionGrants` (`permission-migrations.ts`) fans a new string out to every
|
|
16
|
+
* policy that already holds some OTHER string. That works only when such an anchor exists in the
|
|
17
|
+
* target workspace — it is a rename/split mechanism, and a `from` row that is absent matches
|
|
18
|
+
* nothing and grants nothing, silently.
|
|
19
|
+
*
|
|
20
|
+
* A permission introduced after a workspace was seeded, whose intended holder happens not to hold a
|
|
21
|
+
* suitable anchor string in THAT workspace, therefore reaches nobody. It is not a fail-open — the
|
|
22
|
+
* gate still evaluates and still refuses — but it is a silent capability REMOVAL: the feature stops
|
|
23
|
+
* working for its intended role, and the only principal left is `owner`, on its `*` wildcard.
|
|
24
|
+
*
|
|
25
|
+
* This module is the third path: state the grant against the built-in ROLE it belongs to, and let
|
|
26
|
+
* boot reconcile it. That is the same thing the seed list says, expressed so it also applies to a
|
|
27
|
+
* workspace the seed will never visit again.
|
|
28
|
+
*
|
|
29
|
+
* ## Why by role, and why that is safe
|
|
30
|
+
*
|
|
31
|
+
* A registration names a built-in role (`"admin"`), not a policy id and not a policy name. The
|
|
32
|
+
* fan-out resolves that to the role's OWN built-in policy — `seedIdentity` creates each built-in
|
|
33
|
+
* role 1:1 with a `${name}-builtin-policy` marked `isBuiltin` — and writes one row there.
|
|
34
|
+
*
|
|
35
|
+
* The safety property is structural rather than incidental: the write targets one specific policy
|
|
36
|
+
* row, so a policy belonging to a DIFFERENT role cannot be reached. Granting to `admin` cannot
|
|
37
|
+
* touch `editor-builtin-policy` for the same reason it cannot touch an unrelated workspace's rows —
|
|
38
|
+
* not because of an ordering, a guard, or a filter that a later edit could weaken.
|
|
39
|
+
*
|
|
40
|
+
* Non-built-in policies bound to the role are skipped. Those are operator-created attachments whose
|
|
41
|
+
* contents are an operator's decision, not the library's; the built-in seed lists are the only
|
|
42
|
+
* thing this mechanism is reconciling.
|
|
43
|
+
*
|
|
44
|
+
* ## Additive-only, like its neighbour
|
|
45
|
+
*
|
|
46
|
+
* Same invariant as `migrateDeprecatedPermissionGrants` and for the same reason: there is no
|
|
47
|
+
* delete, no update, and no rewrite of any existing row anywhere in this file. A partial or failed
|
|
48
|
+
* run leaves the previous, still-functioning state. Re-running is a no-op once the row exists, so
|
|
49
|
+
* it is safe on every boot. Reverting a grant means deleting its registration — after which this
|
|
50
|
+
* module stops ADDING the row, and removing the already-granted row is a deliberate, separate
|
|
51
|
+
* operator action rather than something a code revert performs silently.
|
|
52
|
+
*/
|
|
53
|
+
/** One registered "this built-in role should hold this permission" statement. */
|
|
54
|
+
export interface BuiltinRoleGrant {
|
|
55
|
+
/** Built-in role name as `seedIdentity` creates it — `"owner"`, `"admin"`, `"editor"`, `"viewer"`. */
|
|
56
|
+
readonly role: string;
|
|
57
|
+
/** The permission string that role's built-in policy should hold. */
|
|
58
|
+
readonly permission: string;
|
|
59
|
+
/** Human-readable rationale, surfaced in docs/reviews — not interpreted by this module. */
|
|
60
|
+
readonly reason: string;
|
|
61
|
+
}
|
|
62
|
+
/** A host-owned set of built-in-role grants; see {@link createBuiltinRoleGrantRegistry}. */
|
|
63
|
+
export interface BuiltinRoleGrantRegistry {
|
|
64
|
+
/**
|
|
65
|
+
* Register a built-in-role grant for later fan-out. Idempotent per `{role, permission}` pair:
|
|
66
|
+
* re-registration overwrites rather than duplicating — matches `PermissionMigrationRegistry.register`'s
|
|
67
|
+
* and `PermissionCatalog.register`'s established overwrite semantics.
|
|
68
|
+
*
|
|
69
|
+
* Called at composition by the feature that owns the permission (see
|
|
70
|
+
* `features/pages/permissions.ts`'s `registerPagesPermissionGrants`), so the feature keeps its own
|
|
71
|
+
* policy statement rather than identity holding a list of other features' strings.
|
|
72
|
+
*
|
|
73
|
+
* @complexity O(1).
|
|
74
|
+
*/
|
|
75
|
+
register(grant: BuiltinRoleGrant): void;
|
|
76
|
+
/** Enumerate every registered built-in-role grant, in first-registration order. */
|
|
77
|
+
list(_required: Record<string, never>): BuiltinRoleGrant[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create an empty built-in-role grant registry. One is created per composition root (inside
|
|
81
|
+
* `createPermissionGrantRegistry`, `permission-grants.ts`) and passed to identity wiring as a port.
|
|
82
|
+
* There is deliberately no module-scope registry: one filled by import side effects made which
|
|
83
|
+
* grants existed depend on which modules a process happened to import, and a standalone script that
|
|
84
|
+
* never imported the registering module reconciled against an empty registry (`11aa47080`).
|
|
85
|
+
*
|
|
86
|
+
* @complexity O(g) where g = `optional.grants`.
|
|
87
|
+
*/
|
|
88
|
+
export declare function createBuiltinRoleGrantRegistry(_required?: Record<string, never>, optional?: {
|
|
89
|
+
grants?: readonly BuiltinRoleGrant[];
|
|
90
|
+
}): BuiltinRoleGrantRegistry;
|
|
91
|
+
export interface ApplyBuiltinRoleGrantsDeps {
|
|
92
|
+
/** Every grant to reconcile — normally the composition root's `roleGrants.list({})`. */
|
|
93
|
+
grants: readonly BuiltinRoleGrant[];
|
|
94
|
+
roles: RoleRepoPort;
|
|
95
|
+
rolePolicies: RolePolicyRepoPort;
|
|
96
|
+
policies: PolicyRepoPort;
|
|
97
|
+
policyPermissions: PolicyPermissionRepoPort;
|
|
98
|
+
idGen: IdGeneratorPort;
|
|
99
|
+
workspaceId: UUID;
|
|
100
|
+
}
|
|
101
|
+
export interface ApplyBuiltinRoleGrantsResult {
|
|
102
|
+
/** New `policy_permissions` rows written across every passed grant. `0` once reconciled. */
|
|
103
|
+
grantedCount: number;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* For every `{role, permission}` in `deps.grants`, ensure that built-in role's own built-in policy holds
|
|
107
|
+
* the permission — adding only the rows that are missing.
|
|
108
|
+
*
|
|
109
|
+
* Skips a registration whose role does not exist in this workspace, and skips a role that is not
|
|
110
|
+
* `isBuiltin` (an operator-created role that happens to share a built-in's name is not what a
|
|
111
|
+
* registration means). Never removes or mutates any existing row.
|
|
112
|
+
*
|
|
113
|
+
* Safe to call on every boot: a rerun with nothing to add returns `grantedCount: 0`, mirroring
|
|
114
|
+
* `migrateDeprecatedPermissionGrants`' boot-safety contract.
|
|
115
|
+
*
|
|
116
|
+
* @complexity O(g * p) where g = passed grants and p = policies bound to a named role; both are
|
|
117
|
+
* small, bounded collections (built-in roles are 1:1 with their policy).
|
|
118
|
+
*/
|
|
119
|
+
export declare function applyBuiltinRoleGrants(deps: ApplyBuiltinRoleGrantsDeps): Promise<ApplyBuiltinRoleGrantsResult>;
|
|
120
|
+
//# sourceMappingURL=builtin-role-grants.d.ts.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create an empty built-in-role grant registry. One is created per composition root (inside
|
|
3
|
+
* `createPermissionGrantRegistry`, `permission-grants.ts`) and passed to identity wiring as a port.
|
|
4
|
+
* There is deliberately no module-scope registry: one filled by import side effects made which
|
|
5
|
+
* grants existed depend on which modules a process happened to import, and a standalone script that
|
|
6
|
+
* never imported the registering module reconciled against an empty registry (`11aa47080`).
|
|
7
|
+
*
|
|
8
|
+
* @complexity O(g) where g = `optional.grants`.
|
|
9
|
+
*/
|
|
10
|
+
export function createBuiltinRoleGrantRegistry(_required = {}, optional = {}) {
|
|
11
|
+
const byKey = new Map();
|
|
12
|
+
const register = (grant) => {
|
|
13
|
+
// `\u0000` is the ESCAPED form of the NUL separator this key has always used — same code unit,
|
|
14
|
+
// same comparisons, written so tooling can read this file. A raw NUL byte here made git classify
|
|
15
|
+
// the whole file as binary: `git log --numstat` reported `-\t-` for it, so `ab051e61`'s refactor
|
|
16
|
+
// of this module showed as "Bin 7359 -> 8043 bytes" with no reviewable diff, in a permissions
|
|
17
|
+
// file. Text tools that stop at a NUL byte skipped it for the same reason. Do not paste a literal
|
|
18
|
+
// NUL back in; changing the separator to any other character would change how existing keys
|
|
19
|
+
// compare, which is a different change entirely.
|
|
20
|
+
byKey.set(`${grant.role}\u0000${grant.permission}`, grant);
|
|
21
|
+
};
|
|
22
|
+
for (const grant of optional.grants ?? [])
|
|
23
|
+
register(grant);
|
|
24
|
+
return { register, list: () => [...byKey.values()] };
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Reconcile one grant against one already-resolved built-in role: walk that role's policy
|
|
28
|
+
* bindings, skip anything that is not a built-in policy or that already holds the permission, and
|
|
29
|
+
* add the row where it is missing. Split out of `applyBuiltinRoleGrants` so the grant loop and the
|
|
30
|
+
* binding loop are not both inline in one function.
|
|
31
|
+
*
|
|
32
|
+
* @complexity O(p) where p = policies bound to the role; small and bounded (built-in roles are 1:1
|
|
33
|
+
* with their policy).
|
|
34
|
+
*/
|
|
35
|
+
async function grantToRoleBindings({ deps, grant, roleId }, _options = {}) {
|
|
36
|
+
const { workspaceId } = deps;
|
|
37
|
+
let granted = 0;
|
|
38
|
+
const bindings = await deps.rolePolicies.listByRoleId({ workspaceId, roleId });
|
|
39
|
+
for (const binding of bindings) {
|
|
40
|
+
const policy = await deps.policies.findById({ workspaceId, id: binding.policyId });
|
|
41
|
+
if (!policy?.isBuiltin)
|
|
42
|
+
continue;
|
|
43
|
+
const held = await deps.policyPermissions.listByPolicyId({ workspaceId, policyId: policy.id });
|
|
44
|
+
if (!held.some((row) => row.permission === grant.permission)) {
|
|
45
|
+
await deps.policyPermissions.save({
|
|
46
|
+
id: deps.idGen.newId(),
|
|
47
|
+
workspaceId,
|
|
48
|
+
policyId: policy.id,
|
|
49
|
+
permission: grant.permission,
|
|
50
|
+
// Unscoped, exactly as every seeded built-in grant is — a `resourceType` here would make
|
|
51
|
+
// the row match only one `entityType` and turn a missing grant into a subtler one.
|
|
52
|
+
resourceType: null,
|
|
53
|
+
constraintJson: null,
|
|
54
|
+
});
|
|
55
|
+
granted += 1;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return granted;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* For every `{role, permission}` in `deps.grants`, ensure that built-in role's own built-in policy holds
|
|
62
|
+
* the permission — adding only the rows that are missing.
|
|
63
|
+
*
|
|
64
|
+
* Skips a registration whose role does not exist in this workspace, and skips a role that is not
|
|
65
|
+
* `isBuiltin` (an operator-created role that happens to share a built-in's name is not what a
|
|
66
|
+
* registration means). Never removes or mutates any existing row.
|
|
67
|
+
*
|
|
68
|
+
* Safe to call on every boot: a rerun with nothing to add returns `grantedCount: 0`, mirroring
|
|
69
|
+
* `migrateDeprecatedPermissionGrants`' boot-safety contract.
|
|
70
|
+
*
|
|
71
|
+
* @complexity O(g * p) where g = passed grants and p = policies bound to a named role; both are
|
|
72
|
+
* small, bounded collections (built-in roles are 1:1 with their policy).
|
|
73
|
+
*/
|
|
74
|
+
export async function applyBuiltinRoleGrants(deps) {
|
|
75
|
+
const { grants } = deps;
|
|
76
|
+
if (grants.length === 0)
|
|
77
|
+
return { grantedCount: 0 };
|
|
78
|
+
const { workspaceId } = deps;
|
|
79
|
+
let grantedCount = 0;
|
|
80
|
+
for (const grant of grants) {
|
|
81
|
+
const role = await deps.roles.findByName({ workspaceId, name: grant.role });
|
|
82
|
+
if (!role || !role.isBuiltin)
|
|
83
|
+
continue;
|
|
84
|
+
grantedCount += await grantToRoleBindings({ deps, grant, roleId: role.id });
|
|
85
|
+
}
|
|
86
|
+
return { grantedCount };
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=builtin-role-grants.js.map
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import type { UUID } from "@jini-ai/core/primitives";
|
|
2
|
+
import type { AuthServiceDeps } from "../server/auth-service.js";
|
|
3
|
+
/**
|
|
4
|
+
* @file `trashUser` (delete-user plan v2, decisions 4/5/7, and the OWNER DECISION 2026-09-24 that
|
|
5
|
+
* supersedes decision 1's "owner-role holders only" default) — moves a `kind='user'` or
|
|
6
|
+
* `kind='api_key'` principal to the Trash (disables it, revokes its sessions, indexes it for
|
|
7
|
+
* restore/purge) instead of hard-deleting it. Renamed from the v1 `deleteUser`, which called
|
|
8
|
+
* `UserPurgePort.purgeUser` directly; that hard-delete path is now reached only through the Trash's
|
|
9
|
+
* own purge (`purgeSelected`, or the retention sweeper 60 days later), never straight from this
|
|
10
|
+
* transition.
|
|
11
|
+
*
|
|
12
|
+
* Purpose:
|
|
13
|
+
* Same shape `admin-crud-service.ts`'s `disablePrincipal` and the v1 `deleteUser` already used
|
|
14
|
+
* (`{ deps: AuthServiceDeps, input: {...} }`, plain-`Error`-subclass control flow), now delegating
|
|
15
|
+
* the actual state change to a `RemoveEntity`-shaped callback (`removeUser`) bound to the Trash at
|
|
16
|
+
* composition, instead of writing to `principals` itself.
|
|
17
|
+
*
|
|
18
|
+
* Architectural role:
|
|
19
|
+
* Ordinary core function, not a port (mirrors `disablePrincipal`'s reasoning). `removeUser`'s type
|
|
20
|
+
* below (`RemoveUserFn`) is a structural copy of `features/trash`'s `RemoveEntity`/`TrashMarkerResult`
|
|
21
|
+
* — this file deliberately does not import the Trash feature, the same "no cross-feature import,
|
|
22
|
+
* only a structurally-compatible callback" convention `features/post/post.ts`'s `RemovePostFn`
|
|
23
|
+
* uses for the identical seam. `principalHoldsOwnerWildcard`/`countActiveOwnerWildcardPrincipals`
|
|
24
|
+
* are a private copy of `admin-crud-service.ts`'s same-named helpers, for the reason given below.
|
|
25
|
+
*/
|
|
26
|
+
/** Self-trash, permanent delete and disable refusal (409 `SELF_DELETE`). */
|
|
27
|
+
export declare class SelfDeleteError extends Error {
|
|
28
|
+
}
|
|
29
|
+
/** OWNER DECISION 2026-09-24 (delete-user plan v2, decision 7) — thrown by `enable`/`update`/
|
|
30
|
+
* `reset-password` when the target principal currently has a `trashed_items` row: those
|
|
31
|
+
* transitions must refuse a trashed principal rather than silently reactivate one still indexed
|
|
32
|
+
* for purge. Maps to 409 `USER_IN_TRASH` at the route layer. Declared here, not in each route
|
|
33
|
+
* file, so every consumer throws (and every route maps) the exact same error identity. */
|
|
34
|
+
export declare class UserInTrashError extends Error {
|
|
35
|
+
}
|
|
36
|
+
/** OWNER DECISION 2026-09-24 (delete-user plan v2, decision 7) — thrown by `create` when the
|
|
37
|
+
* requested username belongs to a principal currently in the Trash: the username stays reserved
|
|
38
|
+
* until that principal is restored or purged. Maps to 409 `USERNAME_IN_TRASH`. */
|
|
39
|
+
export declare class UsernameInTrashError extends Error {
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Structurally identical to `features/trash/ports.ts`'s `RemoveEntity`/`TrashMarkerResult` — see
|
|
43
|
+
* this file's header for why `features/identity` copies the shape instead of importing it.
|
|
44
|
+
* `bindRemoveEntity(trash, USER_ENTITY_TYPE)` (composition root) satisfies this type as-is.
|
|
45
|
+
*/
|
|
46
|
+
export type RemoveUserFn = (required: {
|
|
47
|
+
workspaceId: UUID;
|
|
48
|
+
id: UUID;
|
|
49
|
+
display: {
|
|
50
|
+
title: string;
|
|
51
|
+
subtitle?: string | null;
|
|
52
|
+
};
|
|
53
|
+
at: string;
|
|
54
|
+
expectedVersion: number | null;
|
|
55
|
+
actor: {
|
|
56
|
+
principalId: UUID;
|
|
57
|
+
pluginId?: string | null;
|
|
58
|
+
};
|
|
59
|
+
}) => Promise<{
|
|
60
|
+
ok: true;
|
|
61
|
+
version: number | null;
|
|
62
|
+
priorMarker?: string | null;
|
|
63
|
+
noop?: true;
|
|
64
|
+
} | {
|
|
65
|
+
ok: false;
|
|
66
|
+
reason: "not-found" | "version-changed";
|
|
67
|
+
} | {
|
|
68
|
+
ok: false;
|
|
69
|
+
reason: "blocked";
|
|
70
|
+
code: string;
|
|
71
|
+
count: number;
|
|
72
|
+
}>;
|
|
73
|
+
export interface DeleteUserDeps {
|
|
74
|
+
identity: AuthServiceDeps;
|
|
75
|
+
/**
|
|
76
|
+
* Pre-bound to the user entity type at composition. `undefined` only for a composition root with
|
|
77
|
+
* no Trash wiring (the in-memory `app.ts` root) — `trashUser` maps that to
|
|
78
|
+
* `UserDeleteUnsupportedError`, the same 501 the v1 `deleteUser` gave `InMemoryUserPurge`.
|
|
79
|
+
*/
|
|
80
|
+
removeUser?: RemoveUserFn;
|
|
81
|
+
/**
|
|
82
|
+
* True iff `principalId` already has a `trashed_items` row. Checked before calling `removeUser`
|
|
83
|
+
* so a second trash of the same target is an idempotent no-op — the user `TrashAdapter`'s `hide`
|
|
84
|
+
* has no idempotency branch of its own (it would just re-disable and re-report the current status
|
|
85
|
+
* as `priorMarker`, corrupting the ORIGINAL `priorMarker` a restore needs); see that file's header.
|
|
86
|
+
*/
|
|
87
|
+
isInTrash: (required: {
|
|
88
|
+
principalId: UUID;
|
|
89
|
+
}, optional?: Record<string, never>) => Promise<boolean>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* What `trash_item`'s `user` kind (`server/runtime/composition/trash-user-tool-port.ts`) reads from
|
|
93
|
+
* the assistant's route deps beyond `IdentityToolDeps`' repo bag — named here so the assistant's
|
|
94
|
+
* deps union (`assistant/tool-registrations.ts`) can carry it without reaching for `RouteDeps`.
|
|
95
|
+
*/
|
|
96
|
+
export type TrashUserToolDeps = Pick<DeleteUserDeps, "removeUser" | "isInTrash">;
|
|
97
|
+
export interface DeleteUserInput {
|
|
98
|
+
workspaceId: UUID;
|
|
99
|
+
callerPrincipalId: UUID;
|
|
100
|
+
principalId: UUID;
|
|
101
|
+
/** Resolved by the caller (`await deps.ownerPrincipalId` at the route layer), mirroring
|
|
102
|
+
* `disablePrincipal`'s identical convention — keeps this a plain, directly-testable function. */
|
|
103
|
+
seededOwnerPrincipalId: UUID;
|
|
104
|
+
}
|
|
105
|
+
/** Private copy of `admin-crud-service.ts`'s same-named helper — see this file's header for why. */
|
|
106
|
+
export declare function principalHoldsOwnerWildcard(required: {
|
|
107
|
+
deps: AuthServiceDeps;
|
|
108
|
+
workspaceId: UUID;
|
|
109
|
+
principalId: UUID;
|
|
110
|
+
}, _optional?: Record<string, never>): Promise<boolean>;
|
|
111
|
+
/** Builtin admin identity is role-scoped, never inferred from a custom permission grant.
|
|
112
|
+
* The host reconciles user.manage for builtin admins under the 2026-10-07 target rule. */
|
|
113
|
+
export declare function principalHoldsBuiltinAdminRole(required: {
|
|
114
|
+
deps: AuthServiceDeps;
|
|
115
|
+
workspaceId: UUID;
|
|
116
|
+
principalId: UUID;
|
|
117
|
+
}, _optional?: Record<string, never>): Promise<boolean>;
|
|
118
|
+
/**
|
|
119
|
+
* OWNER DECISION 2026-10-07 narrows the 2026-09-24 admin trash authority:
|
|
120
|
+
* "other admins should not be able to delete other admins accounts, only the owner can do that"
|
|
121
|
+
* "i shouldnt be allowed to delete my own account right?"
|
|
122
|
+
* Admin callers retain ordinary-user trash authority. Target-aware guards below apply before
|
|
123
|
+
* every destructive transition, regardless of the caller's broader permission grants.
|
|
124
|
+
*/
|
|
125
|
+
/**
|
|
126
|
+
* Caller classification from 2026-09-24, narrowed by the 2026-10-07 target rule above: true
|
|
127
|
+
* iff `callerPrincipalId` is the owner (an unconstrained `*` holder) or holds the built-in `admin`
|
|
128
|
+
* role — never a custom role, even one granted `user.manage` via `role.manage`.
|
|
129
|
+
*
|
|
130
|
+
* Exported (not just `assertCallerMayManageUserTrash` below) so the Trash's generic restore/purge
|
|
131
|
+
* routes can reuse the SAME rule as a boolean check: those routes gate through
|
|
132
|
+
* `TrashAuthorizeFn`/`mayActOnEntityType` (`features/trash/permissions.ts`), which is boolean-
|
|
133
|
+
* shaped, not exception-shaped, and lives in a different feature this file deliberately does not
|
|
134
|
+
* import (see this file's header) — the composition root wraps that boolean callback around this
|
|
135
|
+
* function for `entityType === "user"` only (`server/runtime/composition/trash-user-admin-
|
|
136
|
+
* override.ts`), so the initial trash action and a later restore/purge of the same user can never
|
|
137
|
+
* drift onto two different rules for who may act on it.
|
|
138
|
+
*
|
|
139
|
+
* @complexity O(1) `resolveEffectivePermissions` call plus O(1)
|
|
140
|
+
* `principalHoldsBuiltinAdminRole` call — evaluated in that order so the common case (the owner)
|
|
141
|
+
* never pays for the role lookup.
|
|
142
|
+
*/
|
|
143
|
+
export declare function callerMayManageUserTrash(required: {
|
|
144
|
+
deps: AuthServiceDeps;
|
|
145
|
+
workspaceId: UUID;
|
|
146
|
+
callerPrincipalId: UUID;
|
|
147
|
+
}): Promise<boolean>;
|
|
148
|
+
/** Post-write invariant for grant removal; throw inside the transaction so the write rolls back. */
|
|
149
|
+
export declare function assertActiveOwnerFloor(required: {
|
|
150
|
+
deps: AuthServiceDeps;
|
|
151
|
+
workspaceId: UUID;
|
|
152
|
+
}, _optional?: Record<string, never>): Promise<void>;
|
|
153
|
+
/** Shared classification for the target rule and Users roster affordances. */
|
|
154
|
+
export declare function userAccountProtection(required: {
|
|
155
|
+
deps: AuthServiceDeps;
|
|
156
|
+
workspaceId: UUID;
|
|
157
|
+
principalId: UUID;
|
|
158
|
+
}, _optional?: Record<string, never>): Promise<{
|
|
159
|
+
isOwner: boolean;
|
|
160
|
+
isProtectedAccount: boolean;
|
|
161
|
+
}>;
|
|
162
|
+
export type UserAccountAction = "trash" | "purge" | "disable" | "reset-password" | "enable";
|
|
163
|
+
/** The owner account contract. Run inside the
|
|
164
|
+
* same identity transaction as the write. Retention has no caller, but still preserves owners. */
|
|
165
|
+
export declare function assertUserAccountAction(required: {
|
|
166
|
+
deps: AuthServiceDeps;
|
|
167
|
+
workspaceId: UUID;
|
|
168
|
+
principalId: UUID;
|
|
169
|
+
action: UserAccountAction;
|
|
170
|
+
}, optional?: {
|
|
171
|
+
callerPrincipalId?: UUID;
|
|
172
|
+
seededOwnerPrincipalId?: UUID;
|
|
173
|
+
}): Promise<void>;
|
|
174
|
+
/** What {@link createTrashUserService} returns: the serialized `trashUser` transition. */
|
|
175
|
+
export interface TrashUserService {
|
|
176
|
+
trashUser(required: {
|
|
177
|
+
deps: DeleteUserDeps;
|
|
178
|
+
input: DeleteUserInput;
|
|
179
|
+
}): ReturnType<RemoveUserFn>;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Serializes `trashUser` calls (decision 4's concurrency rule, carried over unchanged from v1's
|
|
183
|
+
* `deleteUser`): without this, two concurrent trashes targeting the workspace's only two active
|
|
184
|
+
* owner-`*` principals could each read `activeOwnerCount === 2` before either write lands, and both
|
|
185
|
+
* would pass the INV-08 guard — chaining every call onto one promise makes the read-then-write
|
|
186
|
+
* sequence for one call fully finish (or throw) before the next call's read begins.
|
|
187
|
+
* Factory-owned, not module-level: the host creates ONE instance per process at composition, and
|
|
188
|
+
* every caller (the admin route, the assistant's `trash_item` port) shares it. Not per-workspace:
|
|
189
|
+
* a host that runs one workspace per process gets a single chain exactly as serialized as a
|
|
190
|
+
* per-workspace map would be, with no map to leak.
|
|
191
|
+
*
|
|
192
|
+
* @complexity O(1) to enqueue; each call costs {@link runTrashUser}'s own bound once it runs.
|
|
193
|
+
*/
|
|
194
|
+
export declare function createTrashUserService(_required?: Record<string, never>, _optional?: Record<string, never>): TrashUserService;
|
|
195
|
+
//# sourceMappingURL=delete-user-service.d.ts.map
|