@hilbras/keystone 1.6.0 → 2.5.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/CHANGELOG.md +625 -0
- package/README.md +198 -50
- package/dist/cli.js +25 -27
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +23 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +53 -8
- package/dist/config.js.map +1 -1
- package/dist/container.d.ts +4 -1
- package/dist/container.d.ts.map +1 -1
- package/dist/container.js.map +1 -1
- package/dist/db/migrations/0008_flashy_firestar.sql +5 -0
- package/dist/db/migrations/0009_daffy_changeling.sql +1 -0
- package/dist/db/migrations/0010_wealthy_shadow_king.sql +37 -0
- package/dist/db/migrations/0011_overrated_vector.sql +18 -0
- package/dist/db/migrations/0012_brave_darkhawk.sql +28 -0
- package/dist/db/migrations/0013_wonderful_chimera.sql +5 -0
- package/dist/db/migrations/0014_magical_morph.sql +48 -0
- package/dist/db/migrations/0015_chief_vargas.sql +7 -0
- package/dist/db/migrations/0016_gorgeous_charles_xavier.sql +5 -0
- package/dist/db/migrations/0017_flashy_nekra.sql +1 -0
- package/{src/db/migrations/meta/0007_snapshot.json → dist/db/migrations/meta/0008_snapshot.json} +136 -32
- package/{src/db/migrations/meta/0006_snapshot.json → dist/db/migrations/meta/0009_snapshot.json} +359 -30
- package/{src/db/migrations/meta/0005_snapshot.json → dist/db/migrations/meta/0010_snapshot.json} +459 -29
- package/{src/db/migrations/meta/0004_snapshot.json → dist/db/migrations/meta/0011_snapshot.json} +594 -30
- package/dist/db/migrations/meta/0012_snapshot.json +3891 -0
- package/dist/db/migrations/meta/0013_snapshot.json +3919 -0
- package/dist/db/migrations/meta/0014_snapshot.json +4311 -0
- package/dist/db/migrations/meta/0015_snapshot.json +4340 -0
- package/dist/db/migrations/meta/0016_snapshot.json +4363 -0
- package/dist/db/migrations/meta/0017_snapshot.json +4370 -0
- package/dist/db/migrations/meta/_journal.json +70 -0
- package/dist/db/reencryptOidcSecrets.d.ts +2 -0
- package/dist/db/reencryptOidcSecrets.d.ts.map +1 -0
- package/dist/db/reencryptOidcSecrets.js +41 -0
- package/dist/db/reencryptOidcSecrets.js.map +1 -0
- package/dist/db/schema.d.ts +2693 -88
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +157 -4
- package/dist/db/schema.js.map +1 -1
- package/dist/db/seed.js +67 -40
- package/dist/db/seed.js.map +1 -1
- package/dist/di.d.ts.map +1 -1
- package/dist/di.js +11 -3
- package/dist/di.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/errors.d.ts +2 -1
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +10 -0
- package/dist/lib/errors.js.map +1 -1
- package/dist/plugins/appContext.d.ts.map +1 -1
- package/dist/plugins/appContext.js +3 -12
- package/dist/plugins/appContext.js.map +1 -1
- package/dist/plugins/audit.d.ts.map +1 -1
- package/dist/plugins/audit.js +26 -6
- package/dist/plugins/audit.js.map +1 -1
- package/dist/plugins/auth.d.ts.map +1 -1
- package/dist/plugins/auth.js +32 -7
- package/dist/plugins/auth.js.map +1 -1
- package/dist/plugins/headerSanitization.d.ts +15 -0
- package/dist/plugins/headerSanitization.d.ts.map +1 -0
- package/dist/plugins/headerSanitization.js +39 -0
- package/dist/plugins/headerSanitization.js.map +1 -0
- package/dist/plugins/metrics.d.ts.map +1 -1
- package/dist/plugins/mtls.d.ts +21 -2
- package/dist/plugins/mtls.d.ts.map +1 -1
- package/dist/plugins/mtls.js +94 -47
- package/dist/plugins/mtls.js.map +1 -1
- package/dist/plugins/permissions.d.ts.map +1 -1
- package/dist/plugins/permissions.js +29 -9
- package/dist/plugins/permissions.js.map +1 -1
- package/dist/plugins/rateLimit.d.ts +16 -0
- package/dist/plugins/rateLimit.d.ts.map +1 -1
- package/dist/plugins/rateLimit.js +16 -3
- package/dist/plugins/rateLimit.js.map +1 -1
- package/dist/plugins/requestLogger.d.ts.map +1 -1
- package/dist/repositories/apiKey.d.ts.map +1 -1
- package/dist/repositories/application.d.ts +1 -1
- package/dist/repositories/application.d.ts.map +1 -1
- package/dist/repositories/application.js +9 -3
- package/dist/repositories/application.js.map +1 -1
- package/dist/repositories/audit.d.ts.map +1 -1
- package/dist/repositories/index.d.ts +3 -0
- package/dist/repositories/index.d.ts.map +1 -1
- package/dist/repositories/index.js +3 -0
- package/dist/repositories/index.js.map +1 -1
- package/dist/repositories/mfaChallenge.d.ts +23 -0
- package/dist/repositories/mfaChallenge.d.ts.map +1 -0
- package/dist/repositories/mfaChallenge.js +71 -0
- package/dist/repositories/mfaChallenge.js.map +1 -0
- package/dist/repositories/oidcConnection.d.ts +27 -43
- package/dist/repositories/oidcConnection.d.ts.map +1 -1
- package/dist/repositories/oidcConnection.js +15 -6
- package/dist/repositories/oidcConnection.js.map +1 -1
- package/dist/repositories/organization.d.ts +9 -9
- package/dist/repositories/organization.d.ts.map +1 -1
- package/dist/repositories/organization.js +91 -37
- package/dist/repositories/organization.js.map +1 -1
- package/dist/repositories/permission.d.ts.map +1 -1
- package/dist/repositories/permission.js +27 -5
- package/dist/repositories/permission.js.map +1 -1
- package/dist/repositories/samlConnection.d.ts +28 -28
- package/dist/repositories/samlConnection.d.ts.map +1 -1
- package/dist/repositories/samlConnection.js +12 -4
- package/dist/repositories/samlConnection.js.map +1 -1
- package/dist/repositories/scimConnection.d.ts +38 -0
- package/dist/repositories/scimConnection.d.ts.map +1 -0
- package/dist/repositories/scimConnection.js +123 -0
- package/dist/repositories/scimConnection.js.map +1 -0
- package/dist/repositories/scimGroup.d.ts +36 -0
- package/dist/repositories/scimGroup.d.ts.map +1 -0
- package/dist/repositories/scimGroup.js +113 -0
- package/dist/repositories/scimGroup.js.map +1 -0
- package/dist/repositories/session.d.ts +24 -13
- package/dist/repositories/session.d.ts.map +1 -1
- package/dist/repositories/session.js +13 -1
- package/dist/repositories/session.js.map +1 -1
- package/dist/repositories/types.d.ts +117 -6
- package/dist/repositories/types.d.ts.map +1 -1
- package/dist/repositories/types.js +7 -1
- package/dist/repositories/types.js.map +1 -1
- package/dist/repositories/user.d.ts +23 -1
- package/dist/repositories/user.d.ts.map +1 -1
- package/dist/repositories/user.js +180 -4
- package/dist/repositories/user.js.map +1 -1
- package/dist/routes/admin/billing.js +4 -4
- package/dist/routes/admin/billing.js.map +1 -1
- package/dist/routes/admin/helpers.d.ts +16 -20
- package/dist/routes/admin/helpers.d.ts.map +1 -1
- package/dist/routes/admin/helpers.js +53 -10
- package/dist/routes/admin/helpers.js.map +1 -1
- package/dist/routes/admin/organizations.d.ts.map +1 -1
- package/dist/routes/admin/organizations.js +105 -69
- package/dist/routes/admin/organizations.js.map +1 -1
- package/dist/routes/admin/permissions.d.ts.map +1 -1
- package/dist/routes/admin/permissions.js +48 -14
- package/dist/routes/admin/permissions.js.map +1 -1
- package/dist/routes/admin/platform.d.ts.map +1 -1
- package/dist/routes/admin/platform.js +86 -35
- package/dist/routes/admin/platform.js.map +1 -1
- package/dist/routes/admin/sso.d.ts.map +1 -1
- package/dist/routes/admin/sso.js +143 -12
- package/dist/routes/admin/sso.js.map +1 -1
- package/dist/routes/admin/webhooks.js +8 -8
- package/dist/routes/admin/webhooks.js.map +1 -1
- package/dist/routes/apiKeys.d.ts.map +1 -1
- package/dist/routes/apiKeys.js +23 -5
- package/dist/routes/apiKeys.js.map +1 -1
- package/dist/routes/auth.d.ts.map +1 -1
- package/dist/routes/auth.js +112 -22
- package/dist/routes/auth.js.map +1 -1
- package/dist/routes/authz.d.ts.map +1 -1
- package/dist/routes/authz.js +16 -4
- package/dist/routes/authz.js.map +1 -1
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +16 -14
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/federation.d.ts.map +1 -1
- package/dist/routes/federation.js +17 -3
- package/dist/routes/federation.js.map +1 -1
- package/dist/routes/magicLinks.d.ts.map +1 -1
- package/dist/routes/magicLinks.js +15 -3
- package/dist/routes/magicLinks.js.map +1 -1
- package/dist/routes/oauth.d.ts.map +1 -1
- package/dist/routes/oauth.js +60 -5
- package/dist/routes/oauth.js.map +1 -1
- package/dist/routes/oauth2.d.ts.map +1 -1
- package/dist/routes/oauth2.js +188 -22
- package/dist/routes/oauth2.js.map +1 -1
- package/dist/routes/oidcEnterprise.d.ts.map +1 -1
- package/dist/routes/oidcEnterprise.js +67 -21
- package/dist/routes/oidcEnterprise.js.map +1 -1
- package/dist/routes/password.d.ts.map +1 -1
- package/dist/routes/password.js.map +1 -1
- package/dist/routes/profile.js +4 -4
- package/dist/routes/profile.js.map +1 -1
- package/dist/routes/saml.d.ts +33 -0
- package/dist/routes/saml.d.ts.map +1 -1
- package/dist/routes/saml.js +217 -12
- package/dist/routes/saml.js.map +1 -1
- package/dist/routes/scim.d.ts +13 -0
- package/dist/routes/scim.d.ts.map +1 -1
- package/dist/routes/scim.js +885 -110
- package/dist/routes/scim.js.map +1 -1
- package/dist/routes/sdk.d.ts.map +1 -1
- package/dist/routes/sdk.js +24 -8
- package/dist/routes/sdk.js.map +1 -1
- package/dist/routes/serviceAccounts.d.ts.map +1 -1
- package/dist/routes/serviceAccounts.js +63 -2
- package/dist/routes/serviceAccounts.js.map +1 -1
- package/dist/routes/setup.d.ts.map +1 -1
- package/dist/routes/setup.js +15 -16
- package/dist/routes/setup.js.map +1 -1
- package/dist/routes/smsOtp.js +1 -1
- package/dist/routes/smsOtp.js.map +1 -1
- package/dist/routes/totp.d.ts.map +1 -1
- package/dist/routes/totp.js +112 -23
- package/dist/routes/totp.js.map +1 -1
- package/dist/routes/webauthn.d.ts.map +1 -1
- package/dist/routes/webauthn.js +44 -8
- package/dist/routes/webauthn.js.map +1 -1
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/routes/workflows.js +58 -25
- package/dist/routes/workflows.js.map +1 -1
- package/dist/sdk/index.d.ts.map +1 -1
- package/dist/sdk/index.js +141 -40
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/types.d.ts +64 -30
- package/dist/sdk/types.d.ts.map +1 -1
- package/dist/services/application/authentication.d.ts +39 -1
- package/dist/services/application/authentication.d.ts.map +1 -1
- package/dist/services/application/authentication.js +43 -1
- package/dist/services/application/authentication.js.map +1 -1
- package/dist/services/application/identity.d.ts +10 -7
- package/dist/services/application/identity.d.ts.map +1 -1
- package/dist/services/application/identity.js +13 -10
- package/dist/services/application/identity.js.map +1 -1
- package/dist/services/application/organization.d.ts +16 -8
- package/dist/services/application/organization.d.ts.map +1 -1
- package/dist/services/application/organization.js +160 -12
- package/dist/services/application/organization.js.map +1 -1
- package/dist/services/applications.js +2 -2
- package/dist/services/applications.js.map +1 -1
- package/dist/services/audit.d.ts +1 -0
- package/dist/services/audit.d.ts.map +1 -1
- package/dist/services/audit.js +13 -0
- package/dist/services/audit.js.map +1 -1
- package/dist/services/cache.d.ts.map +1 -1
- package/dist/services/configuration/profiles.d.ts +4 -0
- package/dist/services/configuration/profiles.d.ts.map +1 -1
- package/dist/services/configuration/profiles.js +50 -0
- package/dist/services/configuration/profiles.js.map +1 -1
- package/dist/services/configuration.d.ts.map +1 -1
- package/dist/services/configuration.js.map +1 -1
- package/dist/services/connectors/google.d.ts +18 -1
- package/dist/services/connectors/google.d.ts.map +1 -1
- package/dist/services/connectors/google.js +27 -4
- package/dist/services/connectors/google.js.map +1 -1
- package/dist/services/connectors/oidc.d.ts +14 -2
- package/dist/services/connectors/oidc.d.ts.map +1 -1
- package/dist/services/connectors/oidc.js +35 -6
- package/dist/services/connectors/oidc.js.map +1 -1
- package/dist/services/connectors/types.d.ts +13 -1
- package/dist/services/connectors/types.d.ts.map +1 -1
- package/dist/services/connectors/zitadel.d.ts.map +1 -1
- package/dist/services/connectors/zitadel.js +4 -3
- package/dist/services/connectors/zitadel.js.map +1 -1
- package/dist/services/domain/authentication.d.ts +43 -4
- package/dist/services/domain/authentication.d.ts.map +1 -1
- package/dist/services/domain/authentication.js +119 -40
- package/dist/services/domain/authentication.js.map +1 -1
- package/dist/services/domain/authorization.d.ts +11 -0
- package/dist/services/domain/authorization.d.ts.map +1 -1
- package/dist/services/domain/authorization.js +36 -1
- package/dist/services/domain/authorization.js.map +1 -1
- package/dist/services/domain/identity.d.ts +21 -9
- package/dist/services/domain/identity.d.ts.map +1 -1
- package/dist/services/domain/identity.js +187 -10
- package/dist/services/domain/identity.js.map +1 -1
- package/dist/services/domain/organization.d.ts +11 -10
- package/dist/services/domain/organization.d.ts.map +1 -1
- package/dist/services/domain/organization.js +48 -30
- package/dist/services/domain/organization.js.map +1 -1
- package/dist/services/emailVerification.d.ts +2 -2
- package/dist/services/enterpriseSso.d.ts +13 -6
- package/dist/services/enterpriseSso.d.ts.map +1 -1
- package/dist/services/enterpriseSso.js +75 -6
- package/dist/services/enterpriseSso.js.map +1 -1
- package/dist/services/events/subscribers/auditLog.js +1 -1
- package/dist/services/events/subscribers/auditLog.js.map +1 -1
- package/dist/services/events/types.d.ts +7 -1
- package/dist/services/events/types.d.ts.map +1 -1
- package/dist/services/events/types.js.map +1 -1
- package/dist/services/events/validate.d.ts.map +1 -1
- package/dist/services/events/validate.js +33 -0
- package/dist/services/events/validate.js.map +1 -1
- package/dist/services/features.d.ts.map +1 -1
- package/dist/services/features.js.map +1 -1
- package/dist/services/federation.d.ts +6 -1
- package/dist/services/federation.d.ts.map +1 -1
- package/dist/services/federation.js +31 -4
- package/dist/services/federation.js.map +1 -1
- package/dist/services/ipControls.js +2 -2
- package/dist/services/ipControls.js.map +1 -1
- package/dist/services/magicLinks.d.ts +2 -2
- package/dist/services/magicLinks.d.ts.map +1 -1
- package/dist/services/magicLinks.js +13 -9
- package/dist/services/magicLinks.js.map +1 -1
- package/dist/services/mfa.d.ts +53 -0
- package/dist/services/mfa.d.ts.map +1 -0
- package/dist/services/mfa.js +157 -0
- package/dist/services/mfa.js.map +1 -0
- package/dist/services/oauth2.d.ts +88 -14
- package/dist/services/oauth2.d.ts.map +1 -1
- package/dist/services/oauth2.js +125 -16
- package/dist/services/oauth2.js.map +1 -1
- package/dist/services/oidcSecretFormat.d.ts +3 -0
- package/dist/services/oidcSecretFormat.d.ts.map +1 -0
- package/dist/services/oidcSecretFormat.js +5 -0
- package/dist/services/oidcSecretFormat.js.map +1 -0
- package/dist/services/organizations.d.ts +4 -16
- package/dist/services/organizations.d.ts.map +1 -1
- package/dist/services/organizations.js +0 -62
- package/dist/services/organizations.js.map +1 -1
- package/dist/services/permissions.d.ts.map +1 -1
- package/dist/services/permissions.js +9 -1
- package/dist/services/permissions.js.map +1 -1
- package/dist/services/plugins/registry.d.ts.map +1 -1
- package/dist/services/plugins/registry.js.map +1 -1
- package/dist/services/plugins/types.d.ts.map +1 -1
- package/dist/services/queue/bullmq.d.ts.map +1 -1
- package/dist/services/queue/inProcess.d.ts.map +1 -1
- package/dist/services/redirectUri.d.ts +56 -0
- package/dist/services/redirectUri.d.ts.map +1 -0
- package/dist/services/redirectUri.js +129 -0
- package/dist/services/redirectUri.js.map +1 -0
- package/dist/services/redis.d.ts +1 -1
- package/dist/services/redis.d.ts.map +1 -1
- package/dist/services/scimCredentials.d.ts +46 -0
- package/dist/services/scimCredentials.d.ts.map +1 -0
- package/dist/services/scimCredentials.js +123 -0
- package/dist/services/scimCredentials.js.map +1 -0
- package/dist/services/scimLegacyMigration.d.ts +12 -0
- package/dist/services/scimLegacyMigration.d.ts.map +1 -0
- package/dist/services/scimLegacyMigration.js +44 -0
- package/dist/services/scimLegacyMigration.js.map +1 -0
- package/dist/services/secrets/awsKms.d.ts +2 -2
- package/dist/services/secrets/awsKms.d.ts.map +1 -1
- package/dist/services/secrets/awsKms.js +3 -5
- package/dist/services/secrets/awsKms.js.map +1 -1
- package/dist/services/secrets/azureKeyVault.d.ts.map +1 -1
- package/dist/services/secrets/database.d.ts.map +1 -1
- package/dist/services/secrets/database.js.map +1 -1
- package/dist/services/secrets/environment.d.ts.map +1 -1
- package/dist/services/secrets/environment.js.map +1 -1
- package/dist/services/secrets/index.d.ts.map +1 -1
- package/dist/services/secrets/password.d.ts.map +1 -1
- package/dist/services/secrets/password.js +0 -4
- package/dist/services/secrets/password.js.map +1 -1
- package/dist/services/secrets/provider.d.ts +2 -3
- package/dist/services/secrets/provider.d.ts.map +1 -1
- package/dist/services/secrets/vault.d.ts.map +1 -1
- package/dist/services/serviceAccounts.d.ts +20 -0
- package/dist/services/serviceAccounts.d.ts.map +1 -1
- package/dist/services/serviceAccounts.js +47 -1
- package/dist/services/serviceAccounts.js.map +1 -1
- package/dist/services/sessionRevocation.d.ts +76 -0
- package/dist/services/sessionRevocation.d.ts.map +1 -0
- package/dist/services/sessionRevocation.js +86 -0
- package/dist/services/sessionRevocation.js.map +1 -0
- package/dist/services/setup/configWriter.d.ts.map +1 -1
- package/dist/services/setup/configWriter.js.map +1 -1
- package/dist/services/singleUse.d.ts +68 -0
- package/dist/services/singleUse.d.ts.map +1 -0
- package/dist/services/singleUse.js +54 -0
- package/dist/services/singleUse.js.map +1 -0
- package/dist/services/smsOtp.d.ts.map +1 -1
- package/dist/services/smsOtp.js +12 -8
- package/dist/services/smsOtp.js.map +1 -1
- package/dist/services/ssoEndpointPolicy.d.ts +8 -0
- package/dist/services/ssoEndpointPolicy.d.ts.map +1 -0
- package/dist/services/ssoEndpointPolicy.js +136 -0
- package/dist/services/ssoEndpointPolicy.js.map +1 -0
- package/dist/services/stepUp.d.ts +35 -0
- package/dist/services/stepUp.d.ts.map +1 -0
- package/dist/services/stepUp.js +65 -0
- package/dist/services/stepUp.js.map +1 -0
- package/dist/services/tokens.d.ts +39 -11
- package/dist/services/tokens.d.ts.map +1 -1
- package/dist/services/tokens.js +80 -14
- package/dist/services/tokens.js.map +1 -1
- package/dist/services/totp.d.ts +46 -0
- package/dist/services/totp.d.ts.map +1 -1
- package/dist/services/totp.js +178 -41
- package/dist/services/totp.js.map +1 -1
- package/dist/services/trustedProxies.d.ts +90 -0
- package/dist/services/trustedProxies.d.ts.map +1 -0
- package/dist/services/trustedProxies.js +283 -0
- package/dist/services/trustedProxies.js.map +1 -0
- package/dist/services/users.d.ts +20 -12
- package/dist/services/users.d.ts.map +1 -1
- package/dist/services/users.js +24 -51
- package/dist/services/users.js.map +1 -1
- package/dist/services/webauthn.d.ts +8 -4
- package/dist/services/webauthn.d.ts.map +1 -1
- package/dist/services/webauthn.js +4 -4
- package/dist/services/webauthn.js.map +1 -1
- package/dist/services/webhooks.d.ts +20 -20
- package/dist/services/workflows/engine.d.ts +4 -2
- package/dist/services/workflows/engine.d.ts.map +1 -1
- package/dist/services/workflows/engine.js +181 -12
- package/dist/services/workflows/engine.js.map +1 -1
- package/dist/services/workflows/steps.d.ts +2 -0
- package/dist/services/workflows/steps.d.ts.map +1 -1
- package/dist/services/workflows/steps.js +8 -75
- package/dist/services/workflows/steps.js.map +1 -1
- package/dist/setup-server.js +2 -1
- package/dist/setup-server.js.map +1 -1
- package/dist/types.d.ts +33 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +26 -2
- package/dist/types.js.map +1 -1
- package/package.json +25 -3
- package/dist/tests/errors.test.d.ts +0 -2
- package/dist/tests/errors.test.d.ts.map +0 -1
- package/dist/tests/errors.test.js +0 -64
- package/dist/tests/errors.test.js.map +0 -1
- package/dist/tests/events.test.d.ts +0 -2
- package/dist/tests/events.test.d.ts.map +0 -1
- package/dist/tests/events.test.js +0 -45
- package/dist/tests/events.test.js.map +0 -1
- package/dist/tests/featureFlags.test.d.ts +0 -2
- package/dist/tests/featureFlags.test.d.ts.map +0 -1
- package/dist/tests/featureFlags.test.js +0 -24
- package/dist/tests/featureFlags.test.js.map +0 -1
- package/dist/tests/integration/queue.test.d.ts +0 -2
- package/dist/tests/integration/queue.test.d.ts.map +0 -1
- package/dist/tests/integration/queue.test.js +0 -49
- package/dist/tests/integration/queue.test.js.map +0 -1
- package/dist/tests/plugins.test.d.ts +0 -2
- package/dist/tests/plugins.test.d.ts.map +0 -1
- package/dist/tests/plugins.test.js +0 -56
- package/dist/tests/plugins.test.js.map +0 -1
- package/dist/tests/result.test.d.ts +0 -2
- package/dist/tests/result.test.d.ts.map +0 -1
- package/dist/tests/result.test.js +0 -46
- package/dist/tests/result.test.js.map +0 -1
- package/dist/tests/setup/configWriter.test.d.ts +0 -2
- package/dist/tests/setup/configWriter.test.d.ts.map +0 -1
- package/dist/tests/setup/configWriter.test.js +0 -55
- package/dist/tests/setup/configWriter.test.js.map +0 -1
- package/dist/tests/setup/validation.test.d.ts +0 -2
- package/dist/tests/setup/validation.test.d.ts.map +0 -1
- package/dist/tests/setup/validation.test.js +0 -26
- package/dist/tests/setup/validation.test.js.map +0 -1
- package/dist/tests/smoke.test.d.ts +0 -2
- package/dist/tests/smoke.test.d.ts.map +0 -1
- package/dist/tests/smoke.test.js +0 -124
- package/dist/tests/smoke.test.js.map +0 -1
- package/src/cli.ts +0 -172
- package/src/config.ts +0 -143
- package/src/container.ts +0 -48
- package/src/db/index.ts +0 -53
- package/src/db/migrations/0000_skinny_ben_parker.sql +0 -553
- package/src/db/migrations/0001_brief_joseph.sql +0 -10
- package/src/db/migrations/0002_add_account_lockout.sql +0 -3
- package/src/db/migrations/0003_steep_rachel_grey.sql +0 -1
- package/src/db/migrations/0004_clever_bill_hollister.sql +0 -20
- package/src/db/migrations/0005_steep_the_call.sql +0 -2
- package/src/db/migrations/0006_ambitious_boomer.sql +0 -17
- package/src/db/migrations/0007_greedy_vindicator.sql +0 -40
- package/src/db/migrations/meta/0000_snapshot.json +0 -2964
- package/src/db/migrations/meta/0001_snapshot.json +0 -3031
- package/src/db/migrations/meta/0003_snapshot.json +0 -3051
- package/src/db/migrations/meta/_journal.json +0 -62
- package/src/db/schema.ts +0 -676
- package/src/db/seed.ts +0 -146
- package/src/di.ts +0 -81
- package/src/index.ts +0 -326
- package/src/lib/errors.ts +0 -139
- package/src/lib/result.ts +0 -44
- package/src/lib/webhookSignature.ts +0 -41
- package/src/plugins/appContext.ts +0 -76
- package/src/plugins/audit.ts +0 -42
- package/src/plugins/auth.ts +0 -230
- package/src/plugins/metrics.ts +0 -41
- package/src/plugins/mtls.ts +0 -94
- package/src/plugins/permissions.ts +0 -29
- package/src/plugins/rateLimit.ts +0 -133
- package/src/plugins/requestLogger.ts +0 -25
- package/src/plugins/tracing.ts +0 -22
- package/src/repositories/apiKey.ts +0 -158
- package/src/repositories/application.ts +0 -70
- package/src/repositories/audit.ts +0 -32
- package/src/repositories/index.ts +0 -9
- package/src/repositories/oidcConnection.ts +0 -111
- package/src/repositories/organization.ts +0 -167
- package/src/repositories/permission.ts +0 -153
- package/src/repositories/samlConnection.ts +0 -96
- package/src/repositories/session.ts +0 -86
- package/src/repositories/types.ts +0 -134
- package/src/repositories/user.ts +0 -161
- package/src/routes/admin/billing.ts +0 -48
- package/src/routes/admin/helpers.ts +0 -50
- package/src/routes/admin/index.ts +0 -16
- package/src/routes/admin/organizations.ts +0 -299
- package/src/routes/admin/permissions.ts +0 -80
- package/src/routes/admin/platform.ts +0 -335
- package/src/routes/admin/sso.ts +0 -138
- package/src/routes/admin/webhooks.ts +0 -73
- package/src/routes/admin.ts +0 -1
- package/src/routes/apiKeys.ts +0 -60
- package/src/routes/auth.ts +0 -214
- package/src/routes/authz.ts +0 -38
- package/src/routes/config.ts +0 -67
- package/src/routes/emailVerification.ts +0 -73
- package/src/routes/federation.ts +0 -156
- package/src/routes/helpers.ts +0 -17
- package/src/routes/magicLinks.ts +0 -107
- package/src/routes/oauth.ts +0 -167
- package/src/routes/oauth2.ts +0 -284
- package/src/routes/oidcEnterprise.ts +0 -166
- package/src/routes/password.ts +0 -90
- package/src/routes/profile.ts +0 -44
- package/src/routes/saml.ts +0 -209
- package/src/routes/scim.ts +0 -199
- package/src/routes/sdk.ts +0 -141
- package/src/routes/serviceAccounts.ts +0 -124
- package/src/routes/sessions.ts +0 -62
- package/src/routes/setup.ts +0 -315
- package/src/routes/smsOtp.ts +0 -67
- package/src/routes/totp.ts +0 -122
- package/src/routes/webauthn.ts +0 -147
- package/src/routes/workflows.ts +0 -157
- package/src/sdk/index.ts +0 -152
- package/src/sdk/types.ts +0 -54
- package/src/services/anomalyDetection.ts +0 -73
- package/src/services/application/authentication.ts +0 -75
- package/src/services/application/identity.ts +0 -56
- package/src/services/application/index.ts +0 -3
- package/src/services/application/organization.ts +0 -77
- package/src/services/applications.ts +0 -89
- package/src/services/audit.ts +0 -41
- package/src/services/auditExport.ts +0 -59
- package/src/services/billing.ts +0 -87
- package/src/services/cache.ts +0 -131
- package/src/services/configuration/profiles.ts +0 -115
- package/src/services/configuration.ts +0 -120
- package/src/services/connectors/google.ts +0 -92
- package/src/services/connectors/oidc.ts +0 -111
- package/src/services/connectors/registry.ts +0 -124
- package/src/services/connectors/types.ts +0 -38
- package/src/services/connectors/zitadel.ts +0 -77
- package/src/services/devices.ts +0 -76
- package/src/services/domain/authentication.ts +0 -279
- package/src/services/domain/authorization.ts +0 -49
- package/src/services/domain/identity.ts +0 -108
- package/src/services/domain/index.ts +0 -4
- package/src/services/domain/organization.ts +0 -114
- package/src/services/email.ts +0 -167
- package/src/services/emailVerification.ts +0 -75
- package/src/services/enterpriseSso.ts +0 -58
- package/src/services/events/bus.ts +0 -43
- package/src/services/events/subscribers/anomaly.ts +0 -13
- package/src/services/events/subscribers/auditLog.ts +0 -21
- package/src/services/events/subscribers/webhook.ts +0 -39
- package/src/services/events/subscribers/webhookDispatch.ts +0 -14
- package/src/services/events/types.ts +0 -106
- package/src/services/events/validate.ts +0 -118
- package/src/services/featureFlags.ts +0 -90
- package/src/services/features.ts +0 -22
- package/src/services/federation.ts +0 -30
- package/src/services/hibp.ts +0 -28
- package/src/services/ipControls.ts +0 -99
- package/src/services/magicLinks.ts +0 -51
- package/src/services/oauth2.ts +0 -216
- package/src/services/organizations.ts +0 -171
- package/src/services/permissions.ts +0 -146
- package/src/services/plugins/registry.ts +0 -242
- package/src/services/plugins/types.ts +0 -98
- package/src/services/queue/bullmq.ts +0 -104
- package/src/services/queue/inProcess.ts +0 -75
- package/src/services/queue/index.ts +0 -19
- package/src/services/queue/types.ts +0 -26
- package/src/services/redis.ts +0 -16
- package/src/services/secrets/awsKms.ts +0 -97
- package/src/services/secrets/azureKeyVault.ts +0 -171
- package/src/services/secrets/database.ts +0 -166
- package/src/services/secrets/environment.ts +0 -117
- package/src/services/secrets/index.ts +0 -50
- package/src/services/secrets/password.ts +0 -73
- package/src/services/secrets/provider.ts +0 -36
- package/src/services/secrets/vault.ts +0 -149
- package/src/services/secrets.ts +0 -2
- package/src/services/serviceAccounts.ts +0 -74
- package/src/services/setup/configWriter.ts +0 -200
- package/src/services/setup/diagnostics.ts +0 -76
- package/src/services/setup/token.ts +0 -42
- package/src/services/setup/types.ts +0 -40
- package/src/services/setup/validation.ts +0 -205
- package/src/services/sms.ts +0 -81
- package/src/services/smsOtp.ts +0 -74
- package/src/services/tokens.ts +0 -287
- package/src/services/totp.ts +0 -113
- package/src/services/users.ts +0 -239
- package/src/services/webauthn.ts +0 -193
- package/src/services/webhooks.ts +0 -190
- package/src/services/workflows/engine.ts +0 -125
- package/src/services/workflows/steps.ts +0 -129
- package/src/services/zitadel.ts +0 -277
- package/src/setup-server.ts +0 -71
- package/src/tests/errors.test.ts +0 -74
- package/src/tests/events.test.ts +0 -52
- package/src/tests/featureFlags.test.ts +0 -26
- package/src/tests/integration/queue.test.ts +0 -54
- package/src/tests/plugins.test.ts +0 -73
- package/src/tests/result.test.ts +0 -52
- package/src/tests/setup/configWriter.test.ts +0 -69
- package/src/tests/setup/validation.test.ts +0 -29
- package/src/tests/smoke.test.ts +0 -136
- package/src/types.ts +0 -70
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import type { FastifyInstance, FastifyRequest, FastifyReply } from "fastify";
|
|
3
|
-
import {
|
|
4
|
-
createServiceAccount,
|
|
5
|
-
findServiceAccountsByOrgId,
|
|
6
|
-
findServiceAccountById,
|
|
7
|
-
updateServiceAccount,
|
|
8
|
-
listServiceAccountApiKeys,
|
|
9
|
-
} from "../services/serviceAccounts.js";
|
|
10
|
-
import { generateApiKey, hashApiKey } from "../services/tokens.js";
|
|
11
|
-
|
|
12
|
-
const CreateSchema = z.object({
|
|
13
|
-
name: z.string().min(1).max(100),
|
|
14
|
-
description: z.string().max(500).optional(),
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const UpdateSchema = z.object({
|
|
18
|
-
name: z.string().min(1).max(100).optional(),
|
|
19
|
-
description: z.string().max(500).optional(),
|
|
20
|
-
isActive: z.boolean().optional(),
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const CreateKeySchema = z.object({
|
|
24
|
-
name: z.string().min(1).max(100),
|
|
25
|
-
scopes: z.array(z.string()).optional(),
|
|
26
|
-
expiresAt: z.string().datetime().optional(),
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
export default async function serviceAccountRoutes(app: FastifyInstance) {
|
|
30
|
-
app.post(
|
|
31
|
-
"/organizations/:id/service-accounts",
|
|
32
|
-
{ preHandler: [app.requirePermission("service_account", "create")] },
|
|
33
|
-
async (request: FastifyRequest, reply: FastifyReply) => {
|
|
34
|
-
const { id } = request.params as { id: string };
|
|
35
|
-
const body = CreateSchema.parse(request.body);
|
|
36
|
-
|
|
37
|
-
const record = await createServiceAccount({
|
|
38
|
-
orgId: id,
|
|
39
|
-
name: body.name,
|
|
40
|
-
description: body.description,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
await request.audit("service_account_created", { orgId: id, serviceAccountId: record.id });
|
|
44
|
-
return reply.status(201).send(record);
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
app.get(
|
|
49
|
-
"/organizations/:id/service-accounts",
|
|
50
|
-
{ preHandler: [app.requirePermission("service_account", "read")] },
|
|
51
|
-
async (request: FastifyRequest) => {
|
|
52
|
-
const { id } = request.params as { id: string };
|
|
53
|
-
const accounts = await findServiceAccountsByOrgId(id);
|
|
54
|
-
return { serviceAccounts: accounts };
|
|
55
|
-
}
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
app.get(
|
|
59
|
-
"/organizations/:id/service-accounts/:accountId",
|
|
60
|
-
{ preHandler: [app.requirePermission("service_account", "read")] },
|
|
61
|
-
async (request: FastifyRequest, reply: FastifyReply) => {
|
|
62
|
-
const { id, accountId } = request.params as { id: string; accountId: string };
|
|
63
|
-
const record = await findServiceAccountById(accountId, id);
|
|
64
|
-
if (!record) {
|
|
65
|
-
return reply.status(404).send({ error: "Service account not found" });
|
|
66
|
-
}
|
|
67
|
-
const keys = await listServiceAccountApiKeys(accountId);
|
|
68
|
-
return { ...record, apiKeys: keys };
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
app.patch(
|
|
73
|
-
"/organizations/:id/service-accounts/:accountId",
|
|
74
|
-
{ preHandler: [app.requirePermission("service_account", "update")] },
|
|
75
|
-
async (request: FastifyRequest, reply: FastifyReply) => {
|
|
76
|
-
const { id, accountId } = request.params as { id: string; accountId: string };
|
|
77
|
-
const body = UpdateSchema.parse(request.body);
|
|
78
|
-
|
|
79
|
-
const updated = await updateServiceAccount(accountId, id, body);
|
|
80
|
-
if (!updated) {
|
|
81
|
-
return reply.status(404).send({ error: "Service account not found" });
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
await request.audit("service_account_updated", {
|
|
85
|
-
orgId: id,
|
|
86
|
-
serviceAccountId: updated.id,
|
|
87
|
-
});
|
|
88
|
-
return updated;
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
app.post(
|
|
93
|
-
"/organizations/:id/service-accounts/:accountId/api-keys",
|
|
94
|
-
{ preHandler: [app.requirePermission("api_key", "create")] },
|
|
95
|
-
async (request: FastifyRequest, reply: FastifyReply) => {
|
|
96
|
-
const { id, accountId } = request.params as { id: string; accountId: string };
|
|
97
|
-
const body = CreateKeySchema.parse(request.body);
|
|
98
|
-
|
|
99
|
-
const account = await findServiceAccountById(accountId, id);
|
|
100
|
-
if (!account) {
|
|
101
|
-
return reply.status(404).send({ error: "Service account not found" });
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const { key, prefix } = generateApiKey();
|
|
105
|
-
const record = await app.container.apiKeyRepository.create({
|
|
106
|
-
serviceAccountId: account.id,
|
|
107
|
-
orgId: id,
|
|
108
|
-
name: body.name,
|
|
109
|
-
prefix,
|
|
110
|
-
keyHash: hashApiKey(key),
|
|
111
|
-
scopes: body.scopes?.length ? body.scopes : ["api:read"],
|
|
112
|
-
expiresAt: body.expiresAt ? new Date(body.expiresAt) : null,
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
await request.audit("api_key_created", {
|
|
116
|
-
orgId: id,
|
|
117
|
-
serviceAccountId: account.id,
|
|
118
|
-
keyId: record.id,
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
return { key, apiKey: record };
|
|
122
|
-
}
|
|
123
|
-
);
|
|
124
|
-
}
|
package/src/routes/sessions.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import crypto from "node:crypto";
|
|
2
|
-
import type { FastifyInstance, FastifyRequest, FastifyReply } from "fastify";
|
|
3
|
-
import { config } from "../config.js";
|
|
4
|
-
import { SessionRepository } from "../repositories/session.js";
|
|
5
|
-
|
|
6
|
-
const sessions = new SessionRepository();
|
|
7
|
-
|
|
8
|
-
function hashToken(token: string): string {
|
|
9
|
-
return crypto.createHash("sha256").update(token).digest("hex");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default async function sessionRoutes(app: FastifyInstance) {
|
|
13
|
-
app.get("/sessions", { preHandler: [app.authenticate] }, async (request: FastifyRequest) => {
|
|
14
|
-
const userId = request.user?.id;
|
|
15
|
-
if (!userId) return { sessions: [] };
|
|
16
|
-
const list = await sessions.listByUser(userId);
|
|
17
|
-
return {
|
|
18
|
-
sessions: list.map((s) => ({
|
|
19
|
-
id: s.id,
|
|
20
|
-
deviceFingerprint: s.deviceFingerprint,
|
|
21
|
-
ipAddress: s.ipAddress,
|
|
22
|
-
userAgent: s.userAgent,
|
|
23
|
-
lastSeenAt: s.lastSeenAt,
|
|
24
|
-
expiresAt: s.expiresAt,
|
|
25
|
-
createdAt: s.createdAt,
|
|
26
|
-
})),
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
app.delete("/sessions/:id", { preHandler: [app.authenticate] }, async (request: FastifyRequest, reply: FastifyReply) => {
|
|
31
|
-
const userId = request.user?.id;
|
|
32
|
-
const { id } = request.params as { id: string };
|
|
33
|
-
if (!userId) return reply.status(401).send({ error: "Unauthorized" });
|
|
34
|
-
|
|
35
|
-
const session = await sessions.findById(id);
|
|
36
|
-
if (!session || session.userId !== userId) {
|
|
37
|
-
return reply.status(404).send({ error: "Session not found" });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
await sessions.revokeRefreshToken(session.refreshTokenId);
|
|
41
|
-
await sessions.deleteById(id, userId);
|
|
42
|
-
|
|
43
|
-
await request.audit("session_revoked", { sessionId: id });
|
|
44
|
-
return { success: true };
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
app.post("/sessions/revoke-all", { preHandler: [app.authenticate] }, async (request: FastifyRequest, reply: FastifyReply) => {
|
|
48
|
-
const userId = request.user?.id;
|
|
49
|
-
if (!userId) return reply.status(401).send({ error: "Unauthorized" });
|
|
50
|
-
|
|
51
|
-
const currentRefreshToken = request.cookies?.[config.COOKIE_NAME];
|
|
52
|
-
let currentRefreshTokenId: string | undefined;
|
|
53
|
-
if (currentRefreshToken) {
|
|
54
|
-
const row = await sessions.findRefreshTokenByHash(hashToken(currentRefreshToken));
|
|
55
|
-
currentRefreshTokenId = row?.id;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
await sessions.deleteAllForUser(userId, currentRefreshTokenId);
|
|
59
|
-
await request.audit("sessions_revoked_all", { exceptSessionId: currentRefreshTokenId });
|
|
60
|
-
return { success: true };
|
|
61
|
-
});
|
|
62
|
-
}
|
package/src/routes/setup.ts
DELETED
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import type { FastifyInstance, FastifyRequest, FastifyReply } from "fastify";
|
|
3
|
-
import { eq, count } from "drizzle-orm";
|
|
4
|
-
import { migrate } from "drizzle-orm/postgres-js/migrator";
|
|
5
|
-
import fs from "node:fs/promises";
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
import { fileURLToPath } from "node:url";
|
|
8
|
-
import { db, initDb } from "../db/index.js";
|
|
9
|
-
import { users } from "../db/schema.js";
|
|
10
|
-
import { AuthenticationDomainService } from "../services/domain/authentication.js";
|
|
11
|
-
import { DrizzleUserRepository, DrizzleApplicationRepository } from "../repositories/index.js";
|
|
12
|
-
import { validateDatabase, validateRedis, validateEmail, validateSms } from "../services/setup/validation.js";
|
|
13
|
-
import { createConfigWriter } from "../services/setup/configWriter.js";
|
|
14
|
-
import { getSetupToken, validateSetupToken } from "../services/setup/token.js";
|
|
15
|
-
import { runSetupDiagnostics } from "../services/setup/diagnostics.js";
|
|
16
|
-
import { queue } from "../services/queue/index.js";
|
|
17
|
-
|
|
18
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
19
|
-
const SETUP_MARKER_PATH = path.resolve(__dirname, "../../.keystone-setup-complete");
|
|
20
|
-
|
|
21
|
-
const SetupInitSchema = z.object({
|
|
22
|
-
email: z.string().email(),
|
|
23
|
-
password: z.string().min(8),
|
|
24
|
-
name: z.string().optional(),
|
|
25
|
-
username: z.string().optional(),
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const ValidateDatabaseSchema = z.object({
|
|
29
|
-
databaseUrl: z.string().min(1),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const ValidateRedisSchema = z.object({
|
|
33
|
-
redisUrl: z.string().min(1),
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const ValidateEmailSchema = z.object({
|
|
37
|
-
provider: z.enum(["none", "console", "smtp", "sendgrid", "mailgun"]),
|
|
38
|
-
from: z.string().email(),
|
|
39
|
-
smtpHost: z.string().optional(),
|
|
40
|
-
smtpPort: z.coerce.number().optional(),
|
|
41
|
-
smtpUser: z.string().optional(),
|
|
42
|
-
smtpPass: z.string().optional(),
|
|
43
|
-
smtpSecure: z.boolean().optional(),
|
|
44
|
-
sendgridApiKey: z.string().optional(),
|
|
45
|
-
mailgunApiKey: z.string().optional(),
|
|
46
|
-
mailgunDomain: z.string().optional(),
|
|
47
|
-
to: z.string().email(),
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const ValidateSmsSchema = z.object({
|
|
51
|
-
provider: z.enum(["none", "console", "twilio"]),
|
|
52
|
-
twilioAccountSid: z.string().optional(),
|
|
53
|
-
twilioAuthToken: z.string().optional(),
|
|
54
|
-
twilioFromNumber: z.string().optional(),
|
|
55
|
-
twilioMessagingServiceSid: z.string().optional(),
|
|
56
|
-
to: z.string().min(1),
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const SetupConfigSchema = z.object({
|
|
60
|
-
env: z.record(z.string(), z.string()),
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
function parseBody<T>(schema: z.ZodSchema<T>, body: unknown, reply: FastifyReply): T | null {
|
|
64
|
-
const result = schema.safeParse(body);
|
|
65
|
-
if (!result.success) {
|
|
66
|
-
const issues = result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ");
|
|
67
|
-
reply.status(400).send({ error: `Invalid input: ${issues}`, code: "VALIDATION_ERROR" });
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
return result.data;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async function hasNoUsers(): Promise<boolean> {
|
|
74
|
-
if (!db) return true;
|
|
75
|
-
try {
|
|
76
|
-
const [result] = await db.select({ total: count() }).from(users);
|
|
77
|
-
return (result?.total ?? 0) === 0;
|
|
78
|
-
} catch {
|
|
79
|
-
// Database exists but migrations have not run yet; setup is still required.
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async function hasNoOwners(): Promise<boolean> {
|
|
85
|
-
if (!db) return true;
|
|
86
|
-
try {
|
|
87
|
-
const [result] = await db.select({ total: count() }).from(users).where(eq(users.role, "owner"));
|
|
88
|
-
return (result?.total ?? 0) === 0;
|
|
89
|
-
} catch {
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async function ensureDbInitialized(request: FastifyRequest, reply: FastifyReply): Promise<boolean> {
|
|
95
|
-
if (db) return true;
|
|
96
|
-
try {
|
|
97
|
-
const writer = createConfigWriter();
|
|
98
|
-
const values = await writer.read();
|
|
99
|
-
const databaseUrl = values.DATABASE_URL;
|
|
100
|
-
if (!databaseUrl) {
|
|
101
|
-
request.log.warn({ configKeys: Object.keys(values) }, "DATABASE_URL missing when initializing database");
|
|
102
|
-
reply.status(400).send({ error: "DATABASE_URL is not configured. Apply configuration first.", code: "DATABASE_URL_MISSING" });
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
process.env.DATABASE_URL = databaseUrl;
|
|
106
|
-
initDb();
|
|
107
|
-
return true;
|
|
108
|
-
} catch (err) {
|
|
109
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
110
|
-
request.log.error({ err }, "Database initialization failed");
|
|
111
|
-
reply.status(500).send({ error: message, code: "DB_INIT_FAILED" });
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function assertSetupToken(request: FastifyRequest, reply: FastifyReply): boolean {
|
|
117
|
-
const token = request.headers["x-setup-token"] as string | undefined;
|
|
118
|
-
if (!validateSetupToken(token)) {
|
|
119
|
-
request.log.warn(
|
|
120
|
-
{ hasToken: Boolean(token), tokenLength: token?.length, expectedLength: getSetupToken()?.length },
|
|
121
|
-
"Invalid or missing setup token"
|
|
122
|
-
);
|
|
123
|
-
reply.status(401).send({ error: "Invalid or missing setup token" });
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export default async function setupRoutes(app: FastifyInstance) {
|
|
130
|
-
app.get("/status", async () => {
|
|
131
|
-
return {
|
|
132
|
-
needsSetup: await hasNoOwners(),
|
|
133
|
-
setupToken: Boolean(getSetupToken()),
|
|
134
|
-
};
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
app.get("/diagnostics", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
138
|
-
if (!assertSetupToken(request, reply)) return;
|
|
139
|
-
const checks = await runSetupDiagnostics();
|
|
140
|
-
return { checks, ready: checks.every((c) => c.status === "ok" || c.status === "skipped") };
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
app.post("/config/dry-run", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
144
|
-
if (!assertSetupToken(request, reply)) return;
|
|
145
|
-
const body = parseBody(SetupConfigSchema, request.body, reply);
|
|
146
|
-
if (!body) return;
|
|
147
|
-
|
|
148
|
-
const writer = createConfigWriter();
|
|
149
|
-
const existing = await writer.read();
|
|
150
|
-
const merged = { ...existing, ...body.env };
|
|
151
|
-
|
|
152
|
-
const validationErrors: string[] = [];
|
|
153
|
-
if (!merged.DATABASE_URL) validationErrors.push("DATABASE_URL is required");
|
|
154
|
-
if (!merged.REDIS_URL) validationErrors.push("REDIS_URL is required");
|
|
155
|
-
if (!merged.AUTH_API_PUBLIC_URL) validationErrors.push("AUTH_API_PUBLIC_URL is required");
|
|
156
|
-
|
|
157
|
-
return {
|
|
158
|
-
ok: validationErrors.length === 0,
|
|
159
|
-
validationErrors,
|
|
160
|
-
wouldWrite: Object.keys(body.env),
|
|
161
|
-
mergedPreview: Object.fromEntries(
|
|
162
|
-
Object.entries(merged).map(([k, v]) => [k, k.includes("KEY") || k.includes("SECRET") || k.includes("PASS") ? "***" : v])
|
|
163
|
-
),
|
|
164
|
-
};
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
app.post("/validate/db", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
168
|
-
if (!assertSetupToken(request, reply)) return;
|
|
169
|
-
const body = parseBody(ValidateDatabaseSchema, request.body, reply);
|
|
170
|
-
if (!body) return;
|
|
171
|
-
const result = await validateDatabase(body);
|
|
172
|
-
if (!result.success) {
|
|
173
|
-
request.log.warn({ code: result.error.code, message: result.error.message }, "Database validation failed");
|
|
174
|
-
return reply.status(result.error.statusCode || 400).send({ error: result.error.message, code: result.error.code });
|
|
175
|
-
}
|
|
176
|
-
return { ok: true };
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
app.post("/validate/redis", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
180
|
-
if (!assertSetupToken(request, reply)) return;
|
|
181
|
-
const body = parseBody(ValidateRedisSchema, request.body, reply);
|
|
182
|
-
if (!body) return;
|
|
183
|
-
const result = await validateRedis(body);
|
|
184
|
-
if (!result.success) {
|
|
185
|
-
request.log.warn({ code: result.error.code, message: result.error.message }, "Redis validation failed");
|
|
186
|
-
return reply.status(result.error.statusCode || 400).send({ error: result.error.message, code: result.error.code });
|
|
187
|
-
}
|
|
188
|
-
return { ok: true };
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
app.post("/validate/email", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
192
|
-
if (!assertSetupToken(request, reply)) return;
|
|
193
|
-
const body = parseBody(ValidateEmailSchema, request.body, reply);
|
|
194
|
-
if (!body) return;
|
|
195
|
-
const { to, ...input } = body;
|
|
196
|
-
const result = await validateEmail(input, to);
|
|
197
|
-
if (!result.success) {
|
|
198
|
-
return reply.status(result.error.statusCode || 400).send({ error: result.error.message, code: result.error.code });
|
|
199
|
-
}
|
|
200
|
-
return { ok: true };
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
app.post("/validate/sms", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
204
|
-
if (!assertSetupToken(request, reply)) return;
|
|
205
|
-
const body = parseBody(ValidateSmsSchema, request.body, reply);
|
|
206
|
-
if (!body) return;
|
|
207
|
-
const { to, ...input } = body;
|
|
208
|
-
const result = await validateSms(input, to);
|
|
209
|
-
if (!result.success) {
|
|
210
|
-
return reply.status(result.error.statusCode || 400).send({ error: result.error.message, code: result.error.code });
|
|
211
|
-
}
|
|
212
|
-
return { ok: true };
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
app.post("/config", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
216
|
-
if (!assertSetupToken(request, reply)) return;
|
|
217
|
-
|
|
218
|
-
const body = parseBody(SetupConfigSchema, request.body, reply);
|
|
219
|
-
if (!body) return;
|
|
220
|
-
const writer = createConfigWriter();
|
|
221
|
-
|
|
222
|
-
const backup = await writer.backup();
|
|
223
|
-
if (!backup.success) {
|
|
224
|
-
return reply.status(backup.error.statusCode || 500).send({ error: backup.error.message, code: backup.error.code });
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const writeResult = await writer.write(body.env);
|
|
228
|
-
if (!writeResult.success) {
|
|
229
|
-
return reply.status(writeResult.error.statusCode || 500).send({ error: writeResult.error.message, code: writeResult.error.code });
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return { ok: true, backupPath: backup.data || undefined };
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
app.post("/migrate", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
236
|
-
if (!assertSetupToken(request, reply)) return;
|
|
237
|
-
if (!(await ensureDbInitialized(request, reply))) return;
|
|
238
|
-
try {
|
|
239
|
-
await migrate(db, { migrationsFolder: path.resolve(__dirname, "../db/migrations") });
|
|
240
|
-
return { ok: true };
|
|
241
|
-
} catch (err) {
|
|
242
|
-
request.log.error({ err }, "Migration failed");
|
|
243
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
244
|
-
return reply.status(500).send({ error: message, code: "MIGRATION_FAILED" });
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
app.post("/restart", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
249
|
-
if (!assertSetupToken(request, reply)) return;
|
|
250
|
-
reply.status(202).send({ ok: true, message: "Server is restarting" });
|
|
251
|
-
try {
|
|
252
|
-
await queue.close?.();
|
|
253
|
-
} catch {
|
|
254
|
-
// ignore
|
|
255
|
-
}
|
|
256
|
-
setTimeout(() => process.exit(0), 500);
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
app.post("/init", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
260
|
-
if (!assertSetupToken(request, reply)) return;
|
|
261
|
-
if (!(await ensureDbInitialized(request, reply))) return;
|
|
262
|
-
if (!(await hasNoOwners())) {
|
|
263
|
-
return reply.status(403).send({ error: "Setup has already been completed" });
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const body = parseBody(SetupInitSchema, request.body, reply);
|
|
267
|
-
if (!body) return;
|
|
268
|
-
|
|
269
|
-
// If a user with this email already exists (e.g. from an interrupted setup),
|
|
270
|
-
// promote them to owner instead of failing with a duplicate-key error.
|
|
271
|
-
const [existing] = await db.select().from(users).where(eq(users.email, body.email)).limit(1);
|
|
272
|
-
|
|
273
|
-
let ownerUser;
|
|
274
|
-
if (existing) {
|
|
275
|
-
await db.update(users).set({ role: "owner" }).where(eq(users.id, existing.id));
|
|
276
|
-
ownerUser = existing;
|
|
277
|
-
} else {
|
|
278
|
-
const authService = new AuthenticationDomainService(new DrizzleUserRepository(), new DrizzleApplicationRepository());
|
|
279
|
-
const result = await authService.register({
|
|
280
|
-
email: body.email,
|
|
281
|
-
password: body.password,
|
|
282
|
-
name: body.name,
|
|
283
|
-
username:
|
|
284
|
-
body.username ||
|
|
285
|
-
body.email
|
|
286
|
-
.split("@")[0]
|
|
287
|
-
.toLowerCase()
|
|
288
|
-
.replace(/[^a-z0-9_-]/g, "-")
|
|
289
|
-
.slice(0, 32),
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
if (!result.success) {
|
|
293
|
-
return reply.status(400).send({ error: result.error.message });
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
await db.update(users).set({ role: "owner" }).where(eq(users.id, result.data.user.id));
|
|
297
|
-
ownerUser = result.data.user;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
try {
|
|
301
|
-
await fs.writeFile(SETUP_MARKER_PATH, new Date().toISOString(), "utf-8");
|
|
302
|
-
} catch (err) {
|
|
303
|
-
request.log.warn({ err }, "Could not write setup completion marker");
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
return {
|
|
307
|
-
user: {
|
|
308
|
-
id: ownerUser.id,
|
|
309
|
-
email: ownerUser.email,
|
|
310
|
-
username: ownerUser.username,
|
|
311
|
-
role: "owner",
|
|
312
|
-
},
|
|
313
|
-
};
|
|
314
|
-
});
|
|
315
|
-
}
|
package/src/routes/smsOtp.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import type { FastifyInstance, FastifyRequest, FastifyReply } from "fastify";
|
|
3
|
-
import { sendSmsOtp, verifySmsOtp, markPhoneVerified } from "../services/smsOtp.js";
|
|
4
|
-
import { rateLimit } from "../plugins/rateLimit.js";
|
|
5
|
-
|
|
6
|
-
const SendSchema = z.object({
|
|
7
|
-
phoneNumber: z.string().min(5).max(32),
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const VerifySchema = z.object({
|
|
11
|
-
phoneNumber: z.string().min(5).max(32),
|
|
12
|
-
code: z.string().min(4).max(8),
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export default async function smsOtpRoutes(app: FastifyInstance) {
|
|
16
|
-
app.post(
|
|
17
|
-
"/sms-otp/send",
|
|
18
|
-
{
|
|
19
|
-
preHandler: [
|
|
20
|
-
app.authenticate,
|
|
21
|
-
rateLimit({
|
|
22
|
-
keyPrefix: "sms-otp-send",
|
|
23
|
-
maxAttempts: 3,
|
|
24
|
-
windowSeconds: 300,
|
|
25
|
-
}),
|
|
26
|
-
],
|
|
27
|
-
},
|
|
28
|
-
async (request: FastifyRequest, reply: FastifyReply) => {
|
|
29
|
-
const user = request.user!;
|
|
30
|
-
const body = SendSchema.parse(request.body);
|
|
31
|
-
|
|
32
|
-
await sendSmsOtp(user, body.phoneNumber);
|
|
33
|
-
await request.audit("sms_otp_sent", { userId: user.id, phoneNumber: body.phoneNumber });
|
|
34
|
-
|
|
35
|
-
return { success: true };
|
|
36
|
-
}
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
app.post(
|
|
40
|
-
"/sms-otp/verify",
|
|
41
|
-
{
|
|
42
|
-
preHandler: [
|
|
43
|
-
app.authenticate,
|
|
44
|
-
rateLimit({
|
|
45
|
-
keyPrefix: "sms-otp-verify",
|
|
46
|
-
maxAttempts: 5,
|
|
47
|
-
windowSeconds: 300,
|
|
48
|
-
}),
|
|
49
|
-
],
|
|
50
|
-
},
|
|
51
|
-
async (request: FastifyRequest, reply: FastifyReply) => {
|
|
52
|
-
const user = request.user!;
|
|
53
|
-
const body = VerifySchema.parse(request.body);
|
|
54
|
-
|
|
55
|
-
const valid = await verifySmsOtp(user.id, body.code);
|
|
56
|
-
if (!valid) {
|
|
57
|
-
await request.audit("sms_otp_verify_failed", { userId: user.id });
|
|
58
|
-
return reply.status(400).send({ error: "Invalid or expired code" });
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
await markPhoneVerified(user.id, body.phoneNumber);
|
|
62
|
-
await request.audit("sms_otp_verified", { userId: user.id, phoneNumber: body.phoneNumber });
|
|
63
|
-
|
|
64
|
-
return { success: true };
|
|
65
|
-
}
|
|
66
|
-
);
|
|
67
|
-
}
|
package/src/routes/totp.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import type { FastifyInstance, FastifyRequest, FastifyReply } from "fastify";
|
|
3
|
-
import { config } from "../config.js";
|
|
4
|
-
import {
|
|
5
|
-
generateSecret,
|
|
6
|
-
buildProvisioningUri,
|
|
7
|
-
verifyTOTP,
|
|
8
|
-
encryptSecret,
|
|
9
|
-
decryptSecret,
|
|
10
|
-
generateBackupCodes,
|
|
11
|
-
storeBackupCodes,
|
|
12
|
-
verifyBackupCode,
|
|
13
|
-
} from "../services/totp.js";
|
|
14
|
-
|
|
15
|
-
const CodeSchema = z.object({
|
|
16
|
-
code: z.string().min(6).max(8),
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const BackupCodeSchema = z.object({
|
|
20
|
-
code: z.string().min(8).max(16),
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
export default async function totpRoutes(app: FastifyInstance) {
|
|
24
|
-
app.post(
|
|
25
|
-
"/totp/enroll",
|
|
26
|
-
{ preHandler: [app.authenticate] },
|
|
27
|
-
async (request: FastifyRequest, reply: FastifyReply) => {
|
|
28
|
-
const user = request.user!;
|
|
29
|
-
if (user.totpEnabled) {
|
|
30
|
-
return reply.status(409).send({ error: "TOTP already enrolled" });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const secret = generateSecret();
|
|
34
|
-
const encrypted = encryptSecret(secret);
|
|
35
|
-
const { codes, hashes } = generateBackupCodes();
|
|
36
|
-
|
|
37
|
-
await app.container.userRepository.setTotpSecret(user.id, encrypted);
|
|
38
|
-
await storeBackupCodes(user.id, hashes);
|
|
39
|
-
|
|
40
|
-
const provisioningUri = buildProvisioningUri({
|
|
41
|
-
secret,
|
|
42
|
-
email: user.email,
|
|
43
|
-
issuer: config.TOTP_ISSUER,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
await request.audit("totp_enrolled", { userId: user.id });
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
secret,
|
|
50
|
-
provisioningUri,
|
|
51
|
-
backupCodes: codes,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
app.post(
|
|
57
|
-
"/totp/backup",
|
|
58
|
-
{ preHandler: [app.authenticate] },
|
|
59
|
-
async (request: FastifyRequest, reply: FastifyReply) => {
|
|
60
|
-
const user = request.user!;
|
|
61
|
-
if (!user.totpSecret || !user.totpEnabled) {
|
|
62
|
-
return reply.status(400).send({ error: "TOTP not enabled" });
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const body = BackupCodeSchema.parse(request.body);
|
|
66
|
-
const valid = await verifyBackupCode(user.id, body.code);
|
|
67
|
-
if (!valid) {
|
|
68
|
-
await request.audit("totp_verify_failed", { userId: user.id, method: "backup_code" });
|
|
69
|
-
return reply.status(400).send({ error: "Invalid backup code" });
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
await request.audit("totp_enabled", { userId: user.id, method: "backup_code" });
|
|
73
|
-
return { success: true };
|
|
74
|
-
}
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
app.post(
|
|
78
|
-
"/totp/verify",
|
|
79
|
-
{ preHandler: [app.authenticate] },
|
|
80
|
-
async (request: FastifyRequest, reply: FastifyReply) => {
|
|
81
|
-
const user = request.user!;
|
|
82
|
-
if (!user.totpSecret) {
|
|
83
|
-
return reply.status(400).send({ error: "TOTP not enrolled" });
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const body = CodeSchema.parse(request.body);
|
|
87
|
-
const secret = decryptSecret(user.totpSecret);
|
|
88
|
-
if (!verifyTOTP(secret, body.code)) {
|
|
89
|
-
await request.audit("totp_verify_failed", { userId: user.id });
|
|
90
|
-
return reply.status(400).send({ error: "Invalid code" });
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
await app.container.userRepository.enableTotp(user.id);
|
|
94
|
-
await request.audit("totp_enabled", { userId: user.id });
|
|
95
|
-
|
|
96
|
-
return { success: true };
|
|
97
|
-
}
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
app.post(
|
|
101
|
-
"/totp/disable",
|
|
102
|
-
{ preHandler: [app.authenticate] },
|
|
103
|
-
async (request: FastifyRequest, reply: FastifyReply) => {
|
|
104
|
-
const user = request.user!;
|
|
105
|
-
if (!user.totpSecret || !user.totpEnabled) {
|
|
106
|
-
return reply.status(400).send({ error: "TOTP not enabled" });
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const body = CodeSchema.parse(request.body);
|
|
110
|
-
const secret = decryptSecret(user.totpSecret);
|
|
111
|
-
if (!verifyTOTP(secret, body.code)) {
|
|
112
|
-
await request.audit("totp_disable_failed", { userId: user.id });
|
|
113
|
-
return reply.status(400).send({ error: "Invalid code" });
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
await app.container.userRepository.disableTotp(user.id);
|
|
117
|
-
await request.audit("totp_disabled", { userId: user.id });
|
|
118
|
-
|
|
119
|
-
return { success: true };
|
|
120
|
-
}
|
|
121
|
-
);
|
|
122
|
-
}
|