@adonis-agora/authkit-server 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +158 -0
- package/build/assets/grafana/authkit-dashboard.json +118 -0
- package/build/commands/clients_create.d.ts +27 -0
- package/build/commands/clients_create.js +121 -0
- package/build/commands/commands.json +292 -0
- package/build/commands/configure.d.ts +2 -0
- package/build/commands/configure.js +45 -0
- package/build/commands/doctor.d.ts +10 -0
- package/build/commands/doctor.js +113 -0
- package/build/commands/eject.d.ts +11 -0
- package/build/commands/eject.js +96 -0
- package/build/commands/expire_scan.d.ts +28 -0
- package/build/commands/expire_scan.js +92 -0
- package/build/commands/import_users.d.ts +17 -0
- package/build/commands/import_users.js +80 -0
- package/build/commands/keys_rotate.d.ts +21 -0
- package/build/commands/keys_rotate.js +126 -0
- package/build/commands/main.d.ts +12 -0
- package/build/commands/main.js +38 -0
- package/build/commands/settings_get.d.ts +18 -0
- package/build/commands/settings_get.js +43 -0
- package/build/commands/settings_list.d.ts +17 -0
- package/build/commands/settings_list.js +39 -0
- package/build/commands/settings_set.d.ts +20 -0
- package/build/commands/settings_set.js +55 -0
- package/build/commands/settings_unset.d.ts +18 -0
- package/build/commands/settings_unset.js +46 -0
- package/build/commands/ui_preset.d.ts +4 -0
- package/build/commands/ui_preset.js +32 -0
- package/build/database/migrations/make_authkit_oidc_table.d.ts +6 -0
- package/build/database/migrations/make_authkit_oidc_table.js +19 -0
- package/build/host/ui/admin.html +29 -0
- package/build/host/views/account/apps.edge +59 -0
- package/build/host/views/account/confirm.edge +70 -0
- package/build/host/views/account/email-confirmed.edge +16 -0
- package/build/host/views/account/login.edge +33 -0
- package/build/host/views/account/mfa.edge +152 -0
- package/build/host/views/account/orgs.edge +58 -0
- package/build/host/views/account/security.edge +215 -0
- package/build/host/views/account/tokens.edge +75 -0
- package/build/host/views/consent.edge +20 -0
- package/build/host/views/forgot.edge +43 -0
- package/build/host/views/login.edge +251 -0
- package/build/host/views/maintenance.edge +32 -0
- package/build/host/views/mfa-challenge.edge +107 -0
- package/build/host/views/otp-unlock.edge +40 -0
- package/build/host/views/partials/styles.edge +2 -0
- package/build/host/views/reset.edge +30 -0
- package/build/host/views/signup.edge +62 -0
- package/build/host/views/verify-email.edge +17 -0
- package/build/index.d.ts +115 -0
- package/build/index.js +76 -0
- package/build/password/common_passwords.txt +10000 -0
- package/build/providers/authkit_server_provider.d.ts +27 -0
- package/build/providers/authkit_server_provider.js +242 -0
- package/build/src/accounts/account_store.d.ts +578 -0
- package/build/src/accounts/account_store.js +60 -0
- package/build/src/accounts/lucid_account_store.d.ts +156 -0
- package/build/src/accounts/lucid_account_store.js +294 -0
- package/build/src/accounts/lucid_store/core.d.ts +9 -0
- package/build/src/accounts/lucid_store/core.js +306 -0
- package/build/src/accounts/lucid_store/mfa.d.ts +15 -0
- package/build/src/accounts/lucid_store/mfa.js +108 -0
- package/build/src/accounts/lucid_store/organizations.d.ts +13 -0
- package/build/src/accounts/lucid_store/organizations.js +294 -0
- package/build/src/accounts/lucid_store/password_hygiene.d.ts +20 -0
- package/build/src/accounts/lucid_store/password_hygiene.js +130 -0
- package/build/src/accounts/lucid_store/provider_identity.d.ts +8 -0
- package/build/src/accounts/lucid_store/provider_identity.js +59 -0
- package/build/src/accounts/lucid_store/shared.d.ts +113 -0
- package/build/src/accounts/lucid_store/shared.js +130 -0
- package/build/src/accounts/lucid_store/status_profile.d.ts +34 -0
- package/build/src/accounts/lucid_store/status_profile.js +100 -0
- package/build/src/accounts/lucid_store/webauthn.d.ts +8 -0
- package/build/src/accounts/lucid_store/webauthn.js +140 -0
- package/build/src/accounts/lucid_stores.d.ts +45 -0
- package/build/src/accounts/lucid_stores.js +30 -0
- package/build/src/adapters/adapter_contract.d.ts +37 -0
- package/build/src/adapters/adapter_contract.js +1 -0
- package/build/src/adapters/database_adapter.d.ts +21 -0
- package/build/src/adapters/database_adapter.js +79 -0
- package/build/src/adapters/factory.d.ts +30 -0
- package/build/src/adapters/factory.js +43 -0
- package/build/src/adapters/redis_adapter.d.ts +24 -0
- package/build/src/adapters/redis_adapter.js +122 -0
- package/build/src/audit/audit_sink.d.ts +63 -0
- package/build/src/audit/audit_sink.js +1 -0
- package/build/src/audit/lucid_audit_sink.d.ts +10 -0
- package/build/src/audit/lucid_audit_sink.js +99 -0
- package/build/src/commands/expire_scan_command.d.ts +60 -0
- package/build/src/commands/expire_scan_command.js +229 -0
- package/build/src/commands/import_clients.d.ts +40 -0
- package/build/src/commands/import_clients.js +79 -0
- package/build/src/commands/import_users.d.ts +51 -0
- package/build/src/commands/import_users.js +94 -0
- package/build/src/commands/resolve_config.d.ts +13 -0
- package/build/src/commands/resolve_config.js +18 -0
- package/build/src/commands/settings_commands.d.ts +47 -0
- package/build/src/commands/settings_commands.js +270 -0
- package/build/src/controllers/oidc_callback_controller.d.ts +22 -0
- package/build/src/controllers/oidc_callback_controller.js +33 -0
- package/build/src/define_config.d.ts +772 -0
- package/build/src/define_config.js +351 -0
- package/build/src/doctor/checks.d.ts +197 -0
- package/build/src/doctor/checks.js +858 -0
- package/build/src/events/dispatcher.d.ts +45 -0
- package/build/src/events/dispatcher.js +117 -0
- package/build/src/host/account_api/account_api_controller.d.ts +245 -0
- package/build/src/host/account_api/account_api_controller.js +827 -0
- package/build/src/host/account_deletion_ops.d.ts +80 -0
- package/build/src/host/account_deletion_ops.js +118 -0
- package/build/src/host/account_deletion_service.d.ts +63 -0
- package/build/src/host/account_deletion_service.js +133 -0
- package/build/src/host/account_export_service.d.ts +76 -0
- package/build/src/host/account_export_service.js +140 -0
- package/build/src/host/account_home.d.ts +11 -0
- package/build/src/host/account_home.js +11 -0
- package/build/src/host/account_lockout.d.ts +86 -0
- package/build/src/host/account_lockout.js +185 -0
- package/build/src/host/active_org_cookie.d.ts +28 -0
- package/build/src/host/active_org_cookie.js +47 -0
- package/build/src/host/admin_api/admin_api_guard.d.ts +16 -0
- package/build/src/host/admin_api/admin_api_guard.js +59 -0
- package/build/src/host/admin_api/admin_orgs_service.d.ts +125 -0
- package/build/src/host/admin_api/admin_orgs_service.js +324 -0
- package/build/src/host/admin_api/admin_users_service.d.ts +163 -0
- package/build/src/host/admin_api/admin_users_service.js +308 -0
- package/build/src/host/admin_api/api_clients_controller.d.ts +54 -0
- package/build/src/host/admin_api/api_clients_controller.js +89 -0
- package/build/src/host/admin_api/api_keys_controller.d.ts +19 -0
- package/build/src/host/admin_api/api_keys_controller.js +36 -0
- package/build/src/host/admin_api/api_misc_controller.d.ts +19 -0
- package/build/src/host/admin_api/api_misc_controller.js +44 -0
- package/build/src/host/admin_api/api_orgs_controller.d.ts +108 -0
- package/build/src/host/admin_api/api_orgs_controller.js +189 -0
- package/build/src/host/admin_api/api_settings_controller.d.ts +55 -0
- package/build/src/host/admin_api/api_settings_controller.js +134 -0
- package/build/src/host/admin_api/api_users_controller.d.ts +108 -0
- package/build/src/host/admin_api/api_users_controller.js +187 -0
- package/build/src/host/admin_api/dto.d.ts +131 -0
- package/build/src/host/admin_api/dto.js +122 -0
- package/build/src/host/admin_api/token_verify_service.d.ts +34 -0
- package/build/src/host/admin_api/token_verify_service.js +74 -0
- package/build/src/host/admin_clients_service.d.ts +88 -0
- package/build/src/host/admin_clients_service.js +181 -0
- package/build/src/host/admin_console/admin_shell_controller.d.ts +27 -0
- package/build/src/host/admin_console/admin_shell_controller.js +167 -0
- package/build/src/host/admin_console/console_audit_controller.d.ts +17 -0
- package/build/src/host/admin_console/console_audit_controller.js +25 -0
- package/build/src/host/admin_console/console_clients_controller.d.ts +53 -0
- package/build/src/host/admin_console/console_clients_controller.js +102 -0
- package/build/src/host/admin_console/console_impersonation_controller.d.ts +23 -0
- package/build/src/host/admin_console/console_impersonation_controller.js +45 -0
- package/build/src/host/admin_console/console_keys_controller.d.ts +24 -0
- package/build/src/host/admin_console/console_keys_controller.js +41 -0
- package/build/src/host/admin_console/console_orgs_controller.d.ts +96 -0
- package/build/src/host/admin_console/console_orgs_controller.js +238 -0
- package/build/src/host/admin_console/console_overview_controller.d.ts +27 -0
- package/build/src/host/admin_console/console_overview_controller.js +44 -0
- package/build/src/host/admin_console/console_roles_controller.d.ts +31 -0
- package/build/src/host/admin_console/console_roles_controller.js +108 -0
- package/build/src/host/admin_console/console_sessions_controller.d.ts +91 -0
- package/build/src/host/admin_console/console_sessions_controller.js +125 -0
- package/build/src/host/admin_console/console_settings_controller.d.ts +47 -0
- package/build/src/host/admin_console/console_settings_controller.js +115 -0
- package/build/src/host/admin_console/console_users_controller.d.ts +110 -0
- package/build/src/host/admin_console/console_users_controller.js +212 -0
- package/build/src/host/admin_prefix.d.ts +50 -0
- package/build/src/host/admin_prefix.js +77 -0
- package/build/src/host/admin_sessions_service.d.ts +119 -0
- package/build/src/host/admin_sessions_service.js +284 -0
- package/build/src/host/admin_stats_service.d.ts +44 -0
- package/build/src/host/admin_stats_service.js +130 -0
- package/build/src/host/admin_validators.d.ts +247 -0
- package/build/src/host/admin_validators.js +197 -0
- package/build/src/host/augmentations.d.ts +12 -0
- package/build/src/host/augmentations.js +1 -0
- package/build/src/host/auth_host_config.d.ts +22 -0
- package/build/src/host/auth_host_config.js +13 -0
- package/build/src/host/avatar_storage.d.ts +68 -0
- package/build/src/host/avatar_storage.js +166 -0
- package/build/src/host/bot_protection.d.ts +187 -0
- package/build/src/host/bot_protection.js +132 -0
- package/build/src/host/branding.d.ts +19 -0
- package/build/src/host/branding.js +8 -0
- package/build/src/host/config_locks.d.ts +38 -0
- package/build/src/host/config_locks.js +70 -0
- package/build/src/host/console_session.d.ts +27 -0
- package/build/src/host/console_session.js +36 -0
- package/build/src/host/controllers/account_apps_controller.d.ts +15 -0
- package/build/src/host/controllers/account_apps_controller.js +61 -0
- package/build/src/host/controllers/account_confirm_controller.d.ts +24 -0
- package/build/src/host/controllers/account_confirm_controller.js +144 -0
- package/build/src/host/controllers/account_mfa_controller.d.ts +28 -0
- package/build/src/host/controllers/account_mfa_controller.js +208 -0
- package/build/src/host/controllers/account_orgs_controller.d.ts +80 -0
- package/build/src/host/controllers/account_orgs_controller.js +401 -0
- package/build/src/host/controllers/account_security_controller.d.ts +43 -0
- package/build/src/host/controllers/account_security_controller.js +546 -0
- package/build/src/host/controllers/account_session_controller.d.ts +21 -0
- package/build/src/host/controllers/account_session_controller.js +113 -0
- package/build/src/host/controllers/account_tokens_controller.d.ts +7 -0
- package/build/src/host/controllers/account_tokens_controller.js +67 -0
- package/build/src/host/controllers/interaction_controller.d.ts +125 -0
- package/build/src/host/controllers/interaction_controller.js +981 -0
- package/build/src/host/controllers/pat_introspection_controller.d.ts +22 -0
- package/build/src/host/controllers/pat_introspection_controller.js +46 -0
- package/build/src/host/controllers/registration_controller.d.ts +18 -0
- package/build/src/host/controllers/registration_controller.js +382 -0
- package/build/src/host/controllers/social_controller.d.ts +8 -0
- package/build/src/host/controllers/social_controller.js +89 -0
- package/build/src/host/csrf.d.ts +29 -0
- package/build/src/host/csrf.js +14 -0
- package/build/src/host/default_mailer.d.ts +112 -0
- package/build/src/host/default_mailer.js +417 -0
- package/build/src/host/durable/account_deletion_workflow.d.ts +48 -0
- package/build/src/host/durable/account_deletion_workflow.js +86 -0
- package/build/src/host/durable/account_export_workflow.d.ts +68 -0
- package/build/src/host/durable/account_export_workflow.js +93 -0
- package/build/src/host/durable/index.d.ts +68 -0
- package/build/src/host/durable/index.js +77 -0
- package/build/src/host/email_templates.d.ts +39 -0
- package/build/src/host/email_templates.js +69 -0
- package/build/src/host/geo.d.ts +22 -0
- package/build/src/host/geo.js +39 -0
- package/build/src/host/i18n.d.ts +1416 -0
- package/build/src/host/i18n.js +1583 -0
- package/build/src/host/impersonation.d.ts +25 -0
- package/build/src/host/impersonation.js +31 -0
- package/build/src/host/key_rotation.d.ts +14 -0
- package/build/src/host/key_rotation.js +27 -0
- package/build/src/host/key_rotation_actions.d.ts +42 -0
- package/build/src/host/key_rotation_actions.js +27 -0
- package/build/src/host/login_attempt.d.ts +98 -0
- package/build/src/host/login_attempt.js +211 -0
- package/build/src/host/login_notify.d.ts +27 -0
- package/build/src/host/login_notify.js +142 -0
- package/build/src/host/middleware/account_auth.d.ts +7 -0
- package/build/src/host/middleware/account_auth.js +11 -0
- package/build/src/host/otp_lockout.d.ts +103 -0
- package/build/src/host/otp_lockout.js +221 -0
- package/build/src/host/rate_limit.d.ts +39 -0
- package/build/src/host/rate_limit.js +94 -0
- package/build/src/host/register_auth_host.d.ts +97 -0
- package/build/src/host/register_auth_host.js +466 -0
- package/build/src/host/renderers/edge_renderer.d.ts +12 -0
- package/build/src/host/renderers/edge_renderer.js +38 -0
- package/build/src/host/renderers/inertia_renderer.d.ts +70 -0
- package/build/src/host/renderers/inertia_renderer.js +54 -0
- package/build/src/host/runtime_settings.d.ts +181 -0
- package/build/src/host/runtime_settings.js +307 -0
- package/build/src/host/runtime_toggles.d.ts +807 -0
- package/build/src/host/runtime_toggles.js +784 -0
- package/build/src/host/security_notice_service.d.ts +36 -0
- package/build/src/host/security_notice_service.js +87 -0
- package/build/src/host/session_context.d.ts +23 -0
- package/build/src/host/session_context.js +89 -0
- package/build/src/host/sudo_mode.d.ts +56 -0
- package/build/src/host/sudo_mode.js +99 -0
- package/build/src/host/svg_chart.d.ts +15 -0
- package/build/src/host/svg_chart.js +45 -0
- package/build/src/host/trusted_device.d.ts +61 -0
- package/build/src/host/trusted_device.js +65 -0
- package/build/src/host/ui-dist/assets/index-CRWcmsex.js +137 -0
- package/build/src/host/ui-dist/assets/index-DTSmD4RU.css +1 -0
- package/build/src/host/ui-dist/index.html +17 -0
- package/build/src/host/user_agent.d.ts +18 -0
- package/build/src/host/user_agent.js +50 -0
- package/build/src/host/validators.d.ts +127 -0
- package/build/src/host/validators.js +53 -0
- package/build/src/keys/jwks_manager.d.ts +6 -0
- package/build/src/keys/jwks_manager.js +11 -0
- package/build/src/keys/keystore.d.ts +52 -0
- package/build/src/keys/keystore.js +68 -0
- package/build/src/keys/keystore_codec.d.ts +20 -0
- package/build/src/keys/keystore_codec.js +42 -0
- package/build/src/keys/keystore_crypto.d.ts +9 -0
- package/build/src/keys/keystore_crypto.js +27 -0
- package/build/src/keys/keystore_manager.d.ts +43 -0
- package/build/src/keys/keystore_manager.js +104 -0
- package/build/src/keys/keystore_vault.d.ts +113 -0
- package/build/src/keys/keystore_vault.js +265 -0
- package/build/src/mixins/json_column.d.ts +33 -0
- package/build/src/mixins/json_column.js +38 -0
- package/build/src/mixins/with_audit_log.d.ts +19 -0
- package/build/src/mixins/with_audit_log.js +39 -0
- package/build/src/mixins/with_auth_user.d.ts +24 -0
- package/build/src/mixins/with_auth_user.js +46 -0
- package/build/src/mixins/with_credentials.d.ts +20 -0
- package/build/src/mixins/with_credentials.js +29 -0
- package/build/src/mixins/with_mfa.d.ts +35 -0
- package/build/src/mixins/with_mfa.js +21 -0
- package/build/src/mixins/with_personal_access_token.d.ts +19 -0
- package/build/src/mixins/with_personal_access_token.js +42 -0
- package/build/src/mixins/with_provider_identity.d.ts +20 -0
- package/build/src/mixins/with_provider_identity.js +32 -0
- package/build/src/mixins/with_webauthn_credential.d.ts +37 -0
- package/build/src/mixins/with_webauthn_credential.js +46 -0
- package/build/src/observability/diagnostics_bridge.d.ts +6 -0
- package/build/src/observability/diagnostics_bridge.js +27 -0
- package/build/src/observability/metrics_controller.d.ts +5 -0
- package/build/src/observability/metrics_controller.js +24 -0
- package/build/src/observability/metrics_service.d.ts +2 -0
- package/build/src/observability/metrics_service.js +7 -0
- package/build/src/observability/otel_recorder.d.ts +10 -0
- package/build/src/observability/otel_recorder.js +59 -0
- package/build/src/observability/telescope/data_providers.d.ts +24 -0
- package/build/src/observability/telescope/data_providers.js +235 -0
- package/build/src/observability/telescope/extension.d.ts +29 -0
- package/build/src/observability/telescope/extension.js +167 -0
- package/build/src/observability/telescope/index.d.ts +8 -0
- package/build/src/observability/telescope/index.js +8 -0
- package/build/src/observability/wire_provider_events.d.ts +12 -0
- package/build/src/observability/wire_provider_events.js +30 -0
- package/build/src/password/common_passwords.d.ts +31 -0
- package/build/src/password/common_passwords.js +73 -0
- package/build/src/password/password_manager.d.ts +163 -0
- package/build/src/password/password_manager.js +191 -0
- package/build/src/password/policy.d.ts +71 -0
- package/build/src/password/policy.js +55 -0
- package/build/src/password/pwned.d.ts +36 -0
- package/build/src/password/pwned.js +52 -0
- package/build/src/pat/lucid_pat_store.d.ts +6 -0
- package/build/src/pat/lucid_pat_store.js +62 -0
- package/build/src/pat/pat_store.d.ts +31 -0
- package/build/src/pat/pat_store.js +1 -0
- package/build/src/pat/pat_tokens.d.ts +4 -0
- package/build/src/pat/pat_tokens.js +9 -0
- package/build/src/provider/build_provider.d.ts +45 -0
- package/build/src/provider/build_provider.js +219 -0
- package/build/src/provider/device_sources.d.ts +6 -0
- package/build/src/provider/device_sources.js +65 -0
- package/build/src/provider/interaction_actions.d.ts +36 -0
- package/build/src/provider/interaction_actions.js +55 -0
- package/build/src/provider/key_rotation_scheduler.d.ts +28 -0
- package/build/src/provider/key_rotation_scheduler.js +40 -0
- package/build/src/provider/keystore_reload.d.ts +21 -0
- package/build/src/provider/keystore_reload.js +39 -0
- package/build/src/provider/logout_sources.d.ts +13 -0
- package/build/src/provider/logout_sources.js +64 -0
- package/build/src/provider/oidc_service.d.ts +81 -0
- package/build/src/provider/oidc_service.js +254 -0
- package/build/src/provider/single_flight_lock.d.ts +18 -0
- package/build/src/provider/single_flight_lock.js +31 -0
- package/build/src/provider/token_exchange.d.ts +21 -0
- package/build/src/provider/token_exchange.js +124 -0
- package/build/src/register_routes.d.ts +16 -0
- package/build/src/register_routes.js +21 -0
- package/build/src/schema/ensure.d.ts +41 -0
- package/build/src/schema/ensure.js +262 -0
- package/build/stubs/config/authkit.stub +20 -0
- package/build/stubs/config/authkit_react.stub +52 -0
- package/build/stubs/main.d.ts +1 -0
- package/build/stubs/main.js +2 -0
- package/build/stubs/models/auth_user.stub +22 -0
- package/build/stubs/ui/edge/views/consent.edge +13 -0
- package/build/stubs/ui/edge/views/login.edge +19 -0
- package/build/stubs/ui/react/components/auth_shell.tsx +67 -0
- package/build/stubs/ui/react/pages/account/login.tsx +56 -0
- package/build/stubs/ui/react/pages/account/mfa.tsx +132 -0
- package/build/stubs/ui/react/pages/account/tokens.tsx +88 -0
- package/build/stubs/ui/react/pages/consent.tsx +39 -0
- package/build/stubs/ui/react/pages/forgot.tsx +44 -0
- package/build/stubs/ui/react/pages/login.tsx +171 -0
- package/build/stubs/ui/react/pages/mfa-challenge.tsx +72 -0
- package/build/stubs/ui/react/pages/reset.tsx +58 -0
- package/build/stubs/ui/react/pages/signup.tsx +78 -0
- package/build/stubs/ui/react/pages/verify-email.tsx +24 -0
- package/build/types.d.ts +7 -0
- package/build/types.js +1 -0
- package/package.json +147 -0
- package/stubs/config/authkit.stub +20 -0
- package/stubs/config/authkit_react.stub +52 -0
- package/stubs/main.ts +2 -0
- package/stubs/models/auth_user.stub +22 -0
- package/stubs/ui/edge/views/consent.edge +13 -0
- package/stubs/ui/edge/views/login.edge +19 -0
- package/stubs/ui/react/components/auth_shell.tsx +67 -0
- package/stubs/ui/react/pages/account/login.tsx +56 -0
- package/stubs/ui/react/pages/account/mfa.tsx +132 -0
- package/stubs/ui/react/pages/account/tokens.tsx +88 -0
- package/stubs/ui/react/pages/consent.tsx +39 -0
- package/stubs/ui/react/pages/forgot.tsx +44 -0
- package/stubs/ui/react/pages/login.tsx +171 -0
- package/stubs/ui/react/pages/mfa-challenge.tsx +72 -0
- package/stubs/ui/react/pages/reset.tsx +58 -0
- package/stubs/ui/react/pages/signup.tsx +78 -0
- package/stubs/ui/react/pages/verify-email.tsx +24 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import '../augmentations.js';
|
|
2
|
+
import type { HttpContext } from '@adonisjs/core/http';
|
|
3
|
+
/**
|
|
4
|
+
* Endpoints JSON de runtime settings do console admin React.
|
|
5
|
+
*
|
|
6
|
+
* GET {prefix}/api/settings → lista settings globais
|
|
7
|
+
* GET {prefix}/api/settings?organizationId={id} → lista settings da org
|
|
8
|
+
* PUT {prefix}/api/settings/:key → upsert de setting global
|
|
9
|
+
* PUT {prefix}/api/settings/:key?organizationId= → upsert de setting org-scoped
|
|
10
|
+
* DELETE {prefix}/api/settings/:key → remover setting global
|
|
11
|
+
* DELETE {prefix}/api/settings/:key?organizationId= → remover setting org-scoped
|
|
12
|
+
*
|
|
13
|
+
* 404 honesto (`capability_unsupported`) quando a tabela auth_settings está ausente.
|
|
14
|
+
*
|
|
15
|
+
* Keys org-scopáveis: `organizations_policy`, `roles_catalog`.
|
|
16
|
+
*/
|
|
17
|
+
export default class ConsoleSettingsController {
|
|
18
|
+
/** GET {prefix}/api/settings */
|
|
19
|
+
index(ctx: HttpContext): Promise<void | {
|
|
20
|
+
data: {
|
|
21
|
+
lockedBy?: "config" | undefined;
|
|
22
|
+
key: string;
|
|
23
|
+
organizationId: string | null;
|
|
24
|
+
value: unknown;
|
|
25
|
+
updatedAt: string | null;
|
|
26
|
+
updatedBy: string | null;
|
|
27
|
+
locked: boolean;
|
|
28
|
+
}[];
|
|
29
|
+
locked: string[];
|
|
30
|
+
}>;
|
|
31
|
+
/** PUT {prefix}/api/settings/:key — body: { value: any } */
|
|
32
|
+
upsert(ctx: HttpContext): Promise<void | {
|
|
33
|
+
lockedBy?: "config" | undefined;
|
|
34
|
+
key: string;
|
|
35
|
+
organizationId: string | null;
|
|
36
|
+
value: unknown;
|
|
37
|
+
updatedAt: string | null;
|
|
38
|
+
updatedBy: string | null;
|
|
39
|
+
locked: boolean;
|
|
40
|
+
}>;
|
|
41
|
+
/** DELETE {prefix}/api/settings/:key */
|
|
42
|
+
destroy(ctx: HttpContext): Promise<void | {
|
|
43
|
+
key: string;
|
|
44
|
+
organizationId: string | null;
|
|
45
|
+
deleted: boolean;
|
|
46
|
+
}>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import '../augmentations.js';
|
|
2
|
+
import { resolveRuntimeSettings } from '../runtime_settings.js';
|
|
3
|
+
import { settingDto, apiError } from '../admin_api/dto.js';
|
|
4
|
+
import { isSettingLocked, lockedSettingKeys, SettingLockedError } from '../config_locks.js';
|
|
5
|
+
/** 423 Locked: setting travada via defineConfig. */
|
|
6
|
+
function lockedResponse(ctx, err) {
|
|
7
|
+
return ctx.response
|
|
8
|
+
.status(423)
|
|
9
|
+
.send(apiError('setting_locked', err.message, { key: err.key, lockedBy: 'config' }));
|
|
10
|
+
}
|
|
11
|
+
function notSupported(ctx) {
|
|
12
|
+
return ctx.response.notFound(apiError('capability_unsupported', 'Runtime settings não é suportado nesta instalação (tabela auth_settings ausente).'));
|
|
13
|
+
}
|
|
14
|
+
/** Extrai organizationId do query string. undefined = não foi passado (usa global null). */
|
|
15
|
+
function resolveOrgId(ctx) {
|
|
16
|
+
const qs = ctx.request.qs();
|
|
17
|
+
if ('organizationId' in qs) {
|
|
18
|
+
const v = qs['organizationId'];
|
|
19
|
+
return v && v.trim() ? v.trim() : null;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Endpoints JSON de runtime settings do console admin React.
|
|
25
|
+
*
|
|
26
|
+
* GET {prefix}/api/settings → lista settings globais
|
|
27
|
+
* GET {prefix}/api/settings?organizationId={id} → lista settings da org
|
|
28
|
+
* PUT {prefix}/api/settings/:key → upsert de setting global
|
|
29
|
+
* PUT {prefix}/api/settings/:key?organizationId= → upsert de setting org-scoped
|
|
30
|
+
* DELETE {prefix}/api/settings/:key → remover setting global
|
|
31
|
+
* DELETE {prefix}/api/settings/:key?organizationId= → remover setting org-scoped
|
|
32
|
+
*
|
|
33
|
+
* 404 honesto (`capability_unsupported`) quando a tabela auth_settings está ausente.
|
|
34
|
+
*
|
|
35
|
+
* Keys org-scopáveis: `organizations_policy`, `roles_catalog`.
|
|
36
|
+
*/
|
|
37
|
+
export default class ConsoleSettingsController {
|
|
38
|
+
/** GET {prefix}/api/settings */
|
|
39
|
+
async index(ctx) {
|
|
40
|
+
const svc = await resolveRuntimeSettings(ctx);
|
|
41
|
+
if (!svc)
|
|
42
|
+
return notSupported(ctx);
|
|
43
|
+
const tablePresent = await svc.isTablePresent();
|
|
44
|
+
if (!tablePresent)
|
|
45
|
+
return notSupported(ctx);
|
|
46
|
+
const orgId = resolveOrgId(ctx);
|
|
47
|
+
const rows = await svc.listSettings(orgId);
|
|
48
|
+
return { data: rows.map(settingDto), locked: lockedSettingKeys() };
|
|
49
|
+
}
|
|
50
|
+
/** PUT {prefix}/api/settings/:key — body: { value: any } */
|
|
51
|
+
async upsert(ctx) {
|
|
52
|
+
const key = ctx.request.param('key');
|
|
53
|
+
const body = ctx.request.body();
|
|
54
|
+
if (!body || !('value' in body)) {
|
|
55
|
+
return ctx.response.badRequest(apiError('invalid_request', 'O campo `value` é obrigatório.'));
|
|
56
|
+
}
|
|
57
|
+
const svc = await resolveRuntimeSettings(ctx);
|
|
58
|
+
if (!svc)
|
|
59
|
+
return notSupported(ctx);
|
|
60
|
+
const tablePresent = await svc.isTablePresent();
|
|
61
|
+
if (!tablePresent)
|
|
62
|
+
return notSupported(ctx);
|
|
63
|
+
if (isSettingLocked(key))
|
|
64
|
+
return lockedResponse(ctx, new SettingLockedError(key));
|
|
65
|
+
const orgId = resolveOrgId(ctx);
|
|
66
|
+
const service = await ctx.containerResolver.make('authkit.server');
|
|
67
|
+
const cfg = service.config;
|
|
68
|
+
try {
|
|
69
|
+
await svc.setSetting(key, body.value, null, orgId);
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
if (err instanceof SettingLockedError)
|
|
73
|
+
return lockedResponse(ctx, err);
|
|
74
|
+
throw err;
|
|
75
|
+
}
|
|
76
|
+
await cfg.audit?.record({
|
|
77
|
+
type: 'settings.updated',
|
|
78
|
+
actorId: null,
|
|
79
|
+
ip: ctx.request.ip?.() ?? null,
|
|
80
|
+
metadata: { key, value: body.value, source: 'admin-console', organizationId: orgId },
|
|
81
|
+
});
|
|
82
|
+
const saved = await svc.getSetting(key, orgId);
|
|
83
|
+
return settingDto({ key, organizationId: orgId, value: saved, updatedAt: new Date(), updatedBy: null });
|
|
84
|
+
}
|
|
85
|
+
/** DELETE {prefix}/api/settings/:key */
|
|
86
|
+
async destroy(ctx) {
|
|
87
|
+
const key = ctx.request.param('key');
|
|
88
|
+
const svc = await resolveRuntimeSettings(ctx);
|
|
89
|
+
if (!svc)
|
|
90
|
+
return notSupported(ctx);
|
|
91
|
+
const tablePresent = await svc.isTablePresent();
|
|
92
|
+
if (!tablePresent)
|
|
93
|
+
return notSupported(ctx);
|
|
94
|
+
if (isSettingLocked(key))
|
|
95
|
+
return lockedResponse(ctx, new SettingLockedError(key));
|
|
96
|
+
const orgId = resolveOrgId(ctx);
|
|
97
|
+
const service = await ctx.containerResolver.make('authkit.server');
|
|
98
|
+
const cfg = service.config;
|
|
99
|
+
try {
|
|
100
|
+
await svc.deleteSetting(key, orgId);
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
if (err instanceof SettingLockedError)
|
|
104
|
+
return lockedResponse(ctx, err);
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
107
|
+
await cfg.audit?.record({
|
|
108
|
+
type: 'settings.updated',
|
|
109
|
+
actorId: null,
|
|
110
|
+
ip: ctx.request.ip?.() ?? null,
|
|
111
|
+
metadata: { key, action: 'deleted', source: 'admin-console', organizationId: orgId },
|
|
112
|
+
});
|
|
113
|
+
return { key, organizationId: orgId, deleted: true };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import "../augmentations.js";
|
|
2
|
+
import type { HttpContext } from "@adonisjs/core/http";
|
|
3
|
+
/**
|
|
4
|
+
* Endpoints JSON de usuários do console admin React.
|
|
5
|
+
*
|
|
6
|
+
* GET {prefix}/api/users?search=&page=&perPage= → lista paginada + roles
|
|
7
|
+
* GET {prefix}/api/users/:id → detalhe + sessões + identidades + MFA status
|
|
8
|
+
* POST {prefix}/api/users → criar usuário
|
|
9
|
+
* PATCH {prefix}/api/users/:id/roles → substituir roles globais
|
|
10
|
+
* POST {prefix}/api/users/:id/disable → desabilitar conta
|
|
11
|
+
* POST {prefix}/api/users/:id/enable → reabilitar conta
|
|
12
|
+
* POST {prefix}/api/users/:id/reset-password → emitir token de reset + enviar e-mail
|
|
13
|
+
* DELETE {prefix}/api/users/:id → deleção completa (cascade)
|
|
14
|
+
*
|
|
15
|
+
* Todos os mutating endpoints retornam 403 sem sessão/role (adminGuard upstream).
|
|
16
|
+
* CSRF: o `adminGuard` não aplica CSRF por si só — o shield do AdonisJS protege
|
|
17
|
+
* automaticamente POST/PATCH/DELETE; o shell injeta `csrfToken` na SPA.
|
|
18
|
+
*/
|
|
19
|
+
export default class ConsoleUsersController {
|
|
20
|
+
#private;
|
|
21
|
+
/** GET {prefix}/api/users */
|
|
22
|
+
index(ctx: HttpContext): Promise<{
|
|
23
|
+
data: any[];
|
|
24
|
+
total: any;
|
|
25
|
+
page: number;
|
|
26
|
+
perPage: number;
|
|
27
|
+
}>;
|
|
28
|
+
/** GET {prefix}/api/users/:id */
|
|
29
|
+
show(ctx: HttpContext): Promise<void | {
|
|
30
|
+
sessionsSupported: boolean;
|
|
31
|
+
sessions: {
|
|
32
|
+
id: string;
|
|
33
|
+
accountId: string;
|
|
34
|
+
email: string | null;
|
|
35
|
+
loginTs: number | null;
|
|
36
|
+
amr: string[];
|
|
37
|
+
userAgent: string | null;
|
|
38
|
+
browser: string | null;
|
|
39
|
+
os: string | null;
|
|
40
|
+
ip: string | null;
|
|
41
|
+
location: string | null;
|
|
42
|
+
}[];
|
|
43
|
+
grants: {
|
|
44
|
+
id: string;
|
|
45
|
+
accountId: string;
|
|
46
|
+
clientId: string | null;
|
|
47
|
+
accessTokens: number;
|
|
48
|
+
refreshTokens: number;
|
|
49
|
+
}[];
|
|
50
|
+
statusSupported: boolean;
|
|
51
|
+
deletionSupported: boolean;
|
|
52
|
+
catalogRoles: {
|
|
53
|
+
name: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
}[];
|
|
56
|
+
id: string;
|
|
57
|
+
email: string;
|
|
58
|
+
name: string | null;
|
|
59
|
+
avatarUrl: string | null;
|
|
60
|
+
globalRoles: string[];
|
|
61
|
+
disabled: boolean;
|
|
62
|
+
}>;
|
|
63
|
+
/** POST {prefix}/api/users */
|
|
64
|
+
store(ctx: HttpContext): Promise<void | {
|
|
65
|
+
invited: boolean;
|
|
66
|
+
id: string;
|
|
67
|
+
email: string;
|
|
68
|
+
name: string | null;
|
|
69
|
+
avatarUrl: string | null;
|
|
70
|
+
globalRoles: string[];
|
|
71
|
+
disabled: boolean;
|
|
72
|
+
}>;
|
|
73
|
+
/** PATCH {prefix}/api/users/:id/roles */
|
|
74
|
+
updateRoles(ctx: HttpContext): Promise<void | {
|
|
75
|
+
id: string;
|
|
76
|
+
email: string;
|
|
77
|
+
name: string | null;
|
|
78
|
+
avatarUrl: string | null;
|
|
79
|
+
globalRoles: string[];
|
|
80
|
+
disabled: boolean;
|
|
81
|
+
}>;
|
|
82
|
+
/** POST {prefix}/api/users/:id/disable */
|
|
83
|
+
disable(ctx: HttpContext): Promise<void | {
|
|
84
|
+
id: string;
|
|
85
|
+
email: string;
|
|
86
|
+
name: string | null;
|
|
87
|
+
avatarUrl: string | null;
|
|
88
|
+
globalRoles: string[];
|
|
89
|
+
disabled: boolean;
|
|
90
|
+
}>;
|
|
91
|
+
/** POST {prefix}/api/users/:id/enable */
|
|
92
|
+
enable(ctx: HttpContext): Promise<void | {
|
|
93
|
+
id: string;
|
|
94
|
+
email: string;
|
|
95
|
+
name: string | null;
|
|
96
|
+
avatarUrl: string | null;
|
|
97
|
+
globalRoles: string[];
|
|
98
|
+
disabled: boolean;
|
|
99
|
+
}>;
|
|
100
|
+
/** POST {prefix}/api/users/:id/reset-password */
|
|
101
|
+
resetPassword(ctx: HttpContext): Promise<void | {
|
|
102
|
+
ok: boolean;
|
|
103
|
+
email: string;
|
|
104
|
+
}>;
|
|
105
|
+
/** DELETE {prefix}/api/users/:id */
|
|
106
|
+
destroy(ctx: HttpContext): Promise<void | {
|
|
107
|
+
ok: boolean;
|
|
108
|
+
deleted: string;
|
|
109
|
+
}>;
|
|
110
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import "../augmentations.js";
|
|
2
|
+
import { AdminUsersService } from "../admin_api/admin_users_service.js";
|
|
3
|
+
import { AdminSessionsService } from "../admin_sessions_service.js";
|
|
4
|
+
import { enrichSessionsWithContext } from "../session_context.js";
|
|
5
|
+
import { resolveRuntimeSettings } from "../runtime_settings.js";
|
|
6
|
+
import { resolveEffectiveRolesCatalog } from "../runtime_toggles.js";
|
|
7
|
+
import { userDto, sessionDto, grantDto, apiError } from "../admin_api/dto.js";
|
|
8
|
+
import { ACCOUNT_SESSION_KEY } from "../middleware/account_auth.js";
|
|
9
|
+
import { supportsAccountDeletion, supportsAccountStatus, } from "../../accounts/account_store.js";
|
|
10
|
+
import { adminUserCreateValidator, adminUserRolesValidator, } from "../admin_validators.js";
|
|
11
|
+
const PAGE_SIZE = 20;
|
|
12
|
+
/**
|
|
13
|
+
* Endpoints JSON de usuários do console admin React.
|
|
14
|
+
*
|
|
15
|
+
* GET {prefix}/api/users?search=&page=&perPage= → lista paginada + roles
|
|
16
|
+
* GET {prefix}/api/users/:id → detalhe + sessões + identidades + MFA status
|
|
17
|
+
* POST {prefix}/api/users → criar usuário
|
|
18
|
+
* PATCH {prefix}/api/users/:id/roles → substituir roles globais
|
|
19
|
+
* POST {prefix}/api/users/:id/disable → desabilitar conta
|
|
20
|
+
* POST {prefix}/api/users/:id/enable → reabilitar conta
|
|
21
|
+
* POST {prefix}/api/users/:id/reset-password → emitir token de reset + enviar e-mail
|
|
22
|
+
* DELETE {prefix}/api/users/:id → deleção completa (cascade)
|
|
23
|
+
*
|
|
24
|
+
* Todos os mutating endpoints retornam 403 sem sessão/role (adminGuard upstream).
|
|
25
|
+
* CSRF: o `adminGuard` não aplica CSRF por si só — o shield do AdonisJS protege
|
|
26
|
+
* automaticamente POST/PATCH/DELETE; o shell injeta `csrfToken` na SPA.
|
|
27
|
+
*/
|
|
28
|
+
export default class ConsoleUsersController {
|
|
29
|
+
/** GET {prefix}/api/users */
|
|
30
|
+
async index(ctx) {
|
|
31
|
+
const service = await ctx.containerResolver.make("authkit.server");
|
|
32
|
+
const cfg = service.config;
|
|
33
|
+
const search = ctx.request.input("search", "").trim();
|
|
34
|
+
const page = Math.max(1, Number.parseInt(ctx.request.input("page", "1"), 10) || 1);
|
|
35
|
+
const perPage = Math.max(1, Math.min(100, Number.parseInt(ctx.request.input("perPage", String(PAGE_SIZE)), 10) ||
|
|
36
|
+
PAGE_SIZE));
|
|
37
|
+
const result = await cfg.accountStore.listAccounts({
|
|
38
|
+
search,
|
|
39
|
+
page,
|
|
40
|
+
limit: perPage,
|
|
41
|
+
});
|
|
42
|
+
const users = new AdminUsersService(cfg);
|
|
43
|
+
const data = await Promise.all(result.data.map(async (u) => userDto(u, await users.isDisabled(u.id))));
|
|
44
|
+
return { data, total: result.total, page, perPage };
|
|
45
|
+
}
|
|
46
|
+
/** GET {prefix}/api/users/:id */
|
|
47
|
+
async show(ctx) {
|
|
48
|
+
const service = await ctx.containerResolver.make("authkit.server");
|
|
49
|
+
const cfg = service.config;
|
|
50
|
+
const id = ctx.request.param("id");
|
|
51
|
+
const account = await cfg.accountStore.findById(id);
|
|
52
|
+
if (!account)
|
|
53
|
+
return ctx.response.notFound(apiError("not_found", "Usuário não encontrado."));
|
|
54
|
+
const users = new AdminUsersService(cfg);
|
|
55
|
+
const disabled = await users.isDisabled(id);
|
|
56
|
+
// Sessões ativas (degradam quando adapter não enumera).
|
|
57
|
+
const sessions = new AdminSessionsService(service);
|
|
58
|
+
const rawSessions = sessions.canList ? await sessions.listSessions(id) : [];
|
|
59
|
+
const enriched = await enrichSessionsWithContext(cfg, id, rawSessions);
|
|
60
|
+
const grants = sessions.canList ? await sessions.listGrants(id) : [];
|
|
61
|
+
// Catálogo de roles (fail-safe).
|
|
62
|
+
let catalogRoles = [];
|
|
63
|
+
try {
|
|
64
|
+
const rs = await resolveRuntimeSettings(ctx);
|
|
65
|
+
if (rs) {
|
|
66
|
+
const catalog = await resolveEffectiveRolesCatalog(rs);
|
|
67
|
+
catalogRoles = catalog.roles;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// fail-safe
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
...userDto(account, disabled),
|
|
75
|
+
sessionsSupported: sessions.canList,
|
|
76
|
+
sessions: enriched.map(sessionDto),
|
|
77
|
+
grants: grants.map(grantDto),
|
|
78
|
+
statusSupported: supportsAccountStatus(cfg.accountStore),
|
|
79
|
+
deletionSupported: supportsAccountDeletion(cfg.accountStore),
|
|
80
|
+
catalogRoles,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** POST {prefix}/api/users */
|
|
84
|
+
async store(ctx) {
|
|
85
|
+
const service = await ctx.containerResolver.make("authkit.server");
|
|
86
|
+
const cfg = service.config;
|
|
87
|
+
const actorId = ctx.session?.get(ACCOUNT_SESSION_KEY) ?? null;
|
|
88
|
+
const ip = ctx.request.ip?.() ?? null;
|
|
89
|
+
const { email, name, password, invite } = await ctx.request.validateUsing(adminUserCreateValidator);
|
|
90
|
+
const users = new AdminUsersService(cfg);
|
|
91
|
+
const result = await users.create(ctx, {
|
|
92
|
+
email,
|
|
93
|
+
name: name ?? null,
|
|
94
|
+
password: password ?? null,
|
|
95
|
+
invite: invite ?? false,
|
|
96
|
+
}, { actorId, ip, source: "admin" });
|
|
97
|
+
if (!result.ok) {
|
|
98
|
+
if (result.reason === "password_policy") {
|
|
99
|
+
return ctx.response.badRequest(apiError("password_policy", cfg.messages[result.messageKey] ?? result.messageKey));
|
|
100
|
+
}
|
|
101
|
+
return ctx.response.conflict(apiError("email_taken", "Já existe uma conta com este e-mail."));
|
|
102
|
+
}
|
|
103
|
+
ctx.response.status(201);
|
|
104
|
+
return { ...userDto(result.account), invited: result.invited };
|
|
105
|
+
}
|
|
106
|
+
/** PATCH {prefix}/api/users/:id/roles */
|
|
107
|
+
async updateRoles(ctx) {
|
|
108
|
+
const service = await ctx.containerResolver.make("authkit.server");
|
|
109
|
+
const cfg = service.config;
|
|
110
|
+
const id = ctx.request.param("id");
|
|
111
|
+
const account = await cfg.accountStore.findById(id);
|
|
112
|
+
if (!account)
|
|
113
|
+
return ctx.response.notFound(apiError("not_found", "Usuário não encontrado."));
|
|
114
|
+
const actorId = ctx.session?.get(ACCOUNT_SESSION_KEY) ?? null;
|
|
115
|
+
const { roles: rolesInput } = await ctx.request.validateUsing(adminUserRolesValidator);
|
|
116
|
+
const roles = Array.from(new Set((rolesInput ?? []).map((r) => r.trim()).filter(Boolean)));
|
|
117
|
+
const users = new AdminUsersService(cfg);
|
|
118
|
+
// Proteções de escalonamento/lockout: último admin + auto-rebaixamento.
|
|
119
|
+
const guard = await users.guardGlobalRolesChange(id, roles, actorId);
|
|
120
|
+
if (guard === "last_admin") {
|
|
121
|
+
return ctx.response
|
|
122
|
+
.status(409)
|
|
123
|
+
.send(apiError("last_admin", "Não é possível remover a última conta com a role de administrador."));
|
|
124
|
+
}
|
|
125
|
+
if (guard === "cannot_self_demote") {
|
|
126
|
+
return ctx.response
|
|
127
|
+
.status(409)
|
|
128
|
+
.send(apiError("cannot_self_demote", "Você não pode remover a sua própria role de administrador."));
|
|
129
|
+
}
|
|
130
|
+
// Resolve RuntimeSettings para validação contra catálogo (fail-safe).
|
|
131
|
+
const runtimeSettings = await resolveRuntimeSettings(ctx);
|
|
132
|
+
const errorKey = await users.setGlobalRolesValidated(id, roles, runtimeSettings);
|
|
133
|
+
if (errorKey) {
|
|
134
|
+
return ctx.response.badRequest(apiError("invalid_role", cfg.messages[errorKey] ?? errorKey));
|
|
135
|
+
}
|
|
136
|
+
const updated = await cfg.accountStore.findById(id);
|
|
137
|
+
const disabled = await users.isDisabled(id);
|
|
138
|
+
return userDto(updated, disabled);
|
|
139
|
+
}
|
|
140
|
+
/** POST {prefix}/api/users/:id/disable */
|
|
141
|
+
async disable(ctx) {
|
|
142
|
+
return this.#setStatus(ctx, true);
|
|
143
|
+
}
|
|
144
|
+
/** POST {prefix}/api/users/:id/enable */
|
|
145
|
+
async enable(ctx) {
|
|
146
|
+
return this.#setStatus(ctx, false);
|
|
147
|
+
}
|
|
148
|
+
async #setStatus(ctx, disable) {
|
|
149
|
+
const service = await ctx.containerResolver.make("authkit.server");
|
|
150
|
+
const cfg = service.config;
|
|
151
|
+
const actorId = ctx.session?.get(ACCOUNT_SESSION_KEY) ?? null;
|
|
152
|
+
const ip = ctx.request.ip?.() ?? null;
|
|
153
|
+
const id = ctx.request.param("id");
|
|
154
|
+
const account = await cfg.accountStore.findById(id);
|
|
155
|
+
if (!account)
|
|
156
|
+
return ctx.response.notFound(apiError("not_found", "Usuário não encontrado."));
|
|
157
|
+
const users = new AdminUsersService(cfg);
|
|
158
|
+
const applied = await users.setStatus(id, disable, {
|
|
159
|
+
actorId,
|
|
160
|
+
ip,
|
|
161
|
+
source: "admin",
|
|
162
|
+
});
|
|
163
|
+
if (!applied) {
|
|
164
|
+
return ctx.response
|
|
165
|
+
.status(409)
|
|
166
|
+
.send(apiError("capability_unsupported", "O store não suporta habilitar/desabilitar contas."));
|
|
167
|
+
}
|
|
168
|
+
const updated = await cfg.accountStore.findById(id);
|
|
169
|
+
const disabled = await users.isDisabled(id);
|
|
170
|
+
return userDto(updated, disabled);
|
|
171
|
+
}
|
|
172
|
+
/** POST {prefix}/api/users/:id/reset-password */
|
|
173
|
+
async resetPassword(ctx) {
|
|
174
|
+
const service = await ctx.containerResolver.make("authkit.server");
|
|
175
|
+
const cfg = service.config;
|
|
176
|
+
const actorId = ctx.session?.get(ACCOUNT_SESSION_KEY) ?? null;
|
|
177
|
+
const ip = ctx.request.ip?.() ?? null;
|
|
178
|
+
const id = ctx.request.param("id");
|
|
179
|
+
const users = new AdminUsersService(cfg);
|
|
180
|
+
const account = await users.resetPassword(ctx, id, {
|
|
181
|
+
actorId,
|
|
182
|
+
ip,
|
|
183
|
+
source: "admin",
|
|
184
|
+
});
|
|
185
|
+
if (!account)
|
|
186
|
+
return ctx.response.notFound(apiError("not_found", "Usuário não encontrado."));
|
|
187
|
+
return { ok: true, email: account.email };
|
|
188
|
+
}
|
|
189
|
+
/** DELETE {prefix}/api/users/:id */
|
|
190
|
+
async destroy(ctx) {
|
|
191
|
+
const service = await ctx.containerResolver.make("authkit.server");
|
|
192
|
+
const cfg = service.config;
|
|
193
|
+
const actorId = ctx.session?.get(ACCOUNT_SESSION_KEY) ?? null;
|
|
194
|
+
const ip = ctx.request.ip?.() ?? null;
|
|
195
|
+
const id = ctx.request.param("id");
|
|
196
|
+
const users = new AdminUsersService(cfg);
|
|
197
|
+
// OPT-IN durável: passa o enqueue (cascade async); senão delete() roda síncrono.
|
|
198
|
+
const enqueue = cfg.accountLifecycle?.durable
|
|
199
|
+
? (await import("../durable/index.js")).enqueueDeletionVia(ctx.containerResolver)
|
|
200
|
+
: undefined;
|
|
201
|
+
const outcome = await users.delete(service, id, { actorId, ip, source: "admin" }, enqueue);
|
|
202
|
+
if (!outcome.ok) {
|
|
203
|
+
if (outcome.reason === "not_found") {
|
|
204
|
+
return ctx.response.notFound(apiError("not_found", "Usuário não encontrado."));
|
|
205
|
+
}
|
|
206
|
+
return ctx.response
|
|
207
|
+
.status(409)
|
|
208
|
+
.send(apiError("capability_unsupported", "O store não suporta deleção de contas."));
|
|
209
|
+
}
|
|
210
|
+
return { ok: true, deleted: id };
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prefixo do console admin e da Admin REST API — singletons de processo.
|
|
3
|
+
*
|
|
4
|
+
* Definidos em tempo de registro das rotas (`registerAuthHost`) e lidos em
|
|
5
|
+
* runtime pelos controllers e pelo `adminGuard`. Garantia de normalização:
|
|
6
|
+
* começa com '/', sem trailing slash, defaults '/admin' e '/api/authkit/v1'.
|
|
7
|
+
*
|
|
8
|
+
* Por que módulos singleton e não bindings do container?
|
|
9
|
+
* O container do AdonisJS só está disponível no ciclo de vida de uma request;
|
|
10
|
+
* os prefixos precisam estar disponíveis ANTES da primeira request (ex.: na
|
|
11
|
+
* closure do `adminGuard`, que é construída em tempo de registro) e DENTRO de
|
|
12
|
+
* cada request. Um módulo ESM é inicializado uma vez por processo — perfeito
|
|
13
|
+
* para configuração imutável definida no boot.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Normaliza o prefixo: começa com '/', sem trailing slash.
|
|
17
|
+
* `'/'` → `''` (raiz) é improvável mas seguro.
|
|
18
|
+
*/
|
|
19
|
+
export declare function normalizeAdminPrefix(raw: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Define o prefixo do console admin para este processo.
|
|
22
|
+
* Chamado UMA VEZ por `registerAuthHost` no boot da aplicação.
|
|
23
|
+
*
|
|
24
|
+
* @param prefix Caminho base do console (ex.: `'/admin'`, `'/auth/admin'`).
|
|
25
|
+
* Normalizado automaticamente.
|
|
26
|
+
*/
|
|
27
|
+
export declare function setAdminPrefix(prefix: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Retorna o prefixo do console admin (default `'/admin'`).
|
|
30
|
+
* Usado pelos controllers e pelo `adminGuard` para construir redirects/links.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getAdminPrefix(): string;
|
|
33
|
+
/**
|
|
34
|
+
* Normaliza o prefixo da Admin REST API: começa com '/', sem trailing slash.
|
|
35
|
+
* Mesma semântica de `normalizeAdminPrefix`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function normalizeAdminApiPrefix(raw: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Define o prefixo da Admin REST API para este processo.
|
|
40
|
+
* Chamado UMA VEZ por `registerAuthHost` no boot da aplicação.
|
|
41
|
+
*
|
|
42
|
+
* @param prefix Caminho base da API (ex.: `'/api/authkit/v1'`, `'/authkit/api'`).
|
|
43
|
+
* Normalizado automaticamente.
|
|
44
|
+
*/
|
|
45
|
+
export declare function setAdminApiPrefix(prefix: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* Retorna o prefixo da Admin REST API (default `'/api/authkit/v1'`).
|
|
48
|
+
* Usado pelo `adminApiGuard` e pelo SDK remoto para construir as URLs.
|
|
49
|
+
*/
|
|
50
|
+
export declare function getAdminApiPrefix(): string;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prefixo do console admin e da Admin REST API — singletons de processo.
|
|
3
|
+
*
|
|
4
|
+
* Definidos em tempo de registro das rotas (`registerAuthHost`) e lidos em
|
|
5
|
+
* runtime pelos controllers e pelo `adminGuard`. Garantia de normalização:
|
|
6
|
+
* começa com '/', sem trailing slash, defaults '/admin' e '/api/authkit/v1'.
|
|
7
|
+
*
|
|
8
|
+
* Por que módulos singleton e não bindings do container?
|
|
9
|
+
* O container do AdonisJS só está disponível no ciclo de vida de uma request;
|
|
10
|
+
* os prefixos precisam estar disponíveis ANTES da primeira request (ex.: na
|
|
11
|
+
* closure do `adminGuard`, que é construída em tempo de registro) e DENTRO de
|
|
12
|
+
* cada request. Um módulo ESM é inicializado uma vez por processo — perfeito
|
|
13
|
+
* para configuração imutável definida no boot.
|
|
14
|
+
*/
|
|
15
|
+
// ─── Console admin ───────────────────────────────────────────────────────────
|
|
16
|
+
const DEFAULT_ADMIN_PREFIX = '/admin';
|
|
17
|
+
let _prefix = DEFAULT_ADMIN_PREFIX;
|
|
18
|
+
/**
|
|
19
|
+
* Normaliza o prefixo: começa com '/', sem trailing slash.
|
|
20
|
+
* `'/'` → `''` (raiz) é improvável mas seguro.
|
|
21
|
+
*/
|
|
22
|
+
export function normalizeAdminPrefix(raw) {
|
|
23
|
+
let p = raw.trim();
|
|
24
|
+
if (!p.startsWith('/'))
|
|
25
|
+
p = '/' + p;
|
|
26
|
+
p = p.replace(/\/+$/, '');
|
|
27
|
+
return p || '/';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Define o prefixo do console admin para este processo.
|
|
31
|
+
* Chamado UMA VEZ por `registerAuthHost` no boot da aplicação.
|
|
32
|
+
*
|
|
33
|
+
* @param prefix Caminho base do console (ex.: `'/admin'`, `'/auth/admin'`).
|
|
34
|
+
* Normalizado automaticamente.
|
|
35
|
+
*/
|
|
36
|
+
export function setAdminPrefix(prefix) {
|
|
37
|
+
_prefix = normalizeAdminPrefix(prefix);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Retorna o prefixo do console admin (default `'/admin'`).
|
|
41
|
+
* Usado pelos controllers e pelo `adminGuard` para construir redirects/links.
|
|
42
|
+
*/
|
|
43
|
+
export function getAdminPrefix() {
|
|
44
|
+
return _prefix;
|
|
45
|
+
}
|
|
46
|
+
// ─── Admin REST API ───────────────────────────────────────────────────────────
|
|
47
|
+
const DEFAULT_ADMIN_API_PREFIX = '/api/authkit/v1';
|
|
48
|
+
let _apiPrefix = DEFAULT_ADMIN_API_PREFIX;
|
|
49
|
+
/**
|
|
50
|
+
* Normaliza o prefixo da Admin REST API: começa com '/', sem trailing slash.
|
|
51
|
+
* Mesma semântica de `normalizeAdminPrefix`.
|
|
52
|
+
*/
|
|
53
|
+
export function normalizeAdminApiPrefix(raw) {
|
|
54
|
+
let p = raw.trim();
|
|
55
|
+
if (!p.startsWith('/'))
|
|
56
|
+
p = '/' + p;
|
|
57
|
+
p = p.replace(/\/+$/, '');
|
|
58
|
+
return p || '/';
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Define o prefixo da Admin REST API para este processo.
|
|
62
|
+
* Chamado UMA VEZ por `registerAuthHost` no boot da aplicação.
|
|
63
|
+
*
|
|
64
|
+
* @param prefix Caminho base da API (ex.: `'/api/authkit/v1'`, `'/authkit/api'`).
|
|
65
|
+
* Normalizado automaticamente.
|
|
66
|
+
*/
|
|
67
|
+
export function setAdminApiPrefix(prefix) {
|
|
68
|
+
_apiPrefix = normalizeAdminApiPrefix(prefix);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Retorna o prefixo da Admin REST API (default `'/api/authkit/v1'`).
|
|
72
|
+
* Usado pelo `adminApiGuard` e pelo SDK remoto para construir as URLs.
|
|
73
|
+
*/
|
|
74
|
+
export function getAdminApiPrefix() {
|
|
75
|
+
return _apiPrefix;
|
|
76
|
+
}
|
|
77
|
+
// ─── Admin UI mode ────────────────────────────────────────────────────────────
|