@hilbras/keystone 1.6.0 → 1.9.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 +239 -0
- package/README.md +55 -25
- package/dist/cli.js +25 -27
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +15 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +45 -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/{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/_journal.json +49 -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 +2521 -53
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +118 -3
- 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 +26 -2
- 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/metrics.d.ts.map +1 -1
- package/dist/plugins/mtls.d.ts.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 +15 -0
- package/dist/plugins/rateLimit.d.ts.map +1 -1
- package/dist/plugins/rateLimit.js +11 -1
- 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.map +1 -1
- package/dist/repositories/application.js +1 -1
- 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 +23 -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 +112 -5
- 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 +76 -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 +22 -3
- package/dist/routes/oauth.js.map +1 -1
- package/dist/routes/oauth2.d.ts.map +1 -1
- package/dist/routes/oauth2.js +104 -11
- 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 +9 -0
- package/dist/routes/saml.d.ts.map +1 -1
- package/dist/routes/saml.js +187 -11
- 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 +2 -1
- 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 +113 -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 +60 -29
- 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 +11 -7
- 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.map +1 -1
- package/dist/services/connectors/google.js +3 -2
- package/dist/services/connectors/google.js.map +1 -1
- package/dist/services/connectors/oidc.d.ts.map +1 -1
- package/dist/services/connectors/oidc.js +6 -3
- package/dist/services/connectors/oidc.js.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 +82 -20
- 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 +6 -9
- 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 +27 -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/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 +16 -12
- package/dist/services/oauth2.d.ts.map +1 -1
- package/dist/services/oauth2.js +22 -13
- 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/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/setup/configWriter.d.ts.map +1 -1
- package/dist/services/setup/configWriter.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 +37 -11
- package/dist/services/tokens.d.ts.map +1 -1
- package/dist/services/tokens.js +75 -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/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.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 +26 -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
package/src/routes/webauthn.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import type { FastifyInstance, FastifyRequest, FastifyReply } from "fastify";
|
|
3
|
-
import {
|
|
4
|
-
type RegistrationResponseJSON,
|
|
5
|
-
type AuthenticationResponseJSON,
|
|
6
|
-
} from "@simplewebauthn/server";
|
|
7
|
-
import {
|
|
8
|
-
buildRegistrationOptions,
|
|
9
|
-
verifyAndStoreRegistration,
|
|
10
|
-
buildAuthenticationOptions,
|
|
11
|
-
verifyAuthentication,
|
|
12
|
-
consumeChallenge,
|
|
13
|
-
} from "../services/webauthn.js";
|
|
14
|
-
import { createTokenSet } from "../services/tokens.js";
|
|
15
|
-
import { setSessionCookies } from "../plugins/auth.js";
|
|
16
|
-
import { fingerprintFromRequest, recordDevice } from "../services/devices.js";
|
|
17
|
-
import { toPublicUser } from "../types.js";
|
|
18
|
-
|
|
19
|
-
const ChallengeCookieName = "keystone_webauthn_challenge";
|
|
20
|
-
|
|
21
|
-
function setChallengeCookie(reply: FastifyReply, challenge: string): void {
|
|
22
|
-
reply.setCookie(ChallengeCookieName, challenge, {
|
|
23
|
-
path: "/",
|
|
24
|
-
httpOnly: true,
|
|
25
|
-
secure: process.env.COOKIE_SECURE === "true",
|
|
26
|
-
sameSite: "lax",
|
|
27
|
-
maxAge: 300,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function getChallengeCookie(request: FastifyRequest): string | undefined {
|
|
32
|
-
return request.cookies[ChallengeCookieName];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function clearChallengeCookie(reply: FastifyReply): void {
|
|
36
|
-
reply.clearCookie(ChallengeCookieName, { path: "/" });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const RegisterVerifySchema = z.object({
|
|
40
|
-
response: z.record(z.string(), z.unknown()),
|
|
41
|
-
deviceName: z.string().max(100).optional(),
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const AuthenticateOptionsSchema = z.object({
|
|
45
|
-
email: z.string().email().optional(),
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const AuthenticateVerifySchema = z.object({
|
|
49
|
-
response: z.record(z.string(), z.unknown()),
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
export default async function webauthnRoutes(app: FastifyInstance) {
|
|
53
|
-
app.get(
|
|
54
|
-
"/webauthn/register/options",
|
|
55
|
-
{ preHandler: [app.authenticate] },
|
|
56
|
-
async (request: FastifyRequest, reply: FastifyReply) => {
|
|
57
|
-
const user = request.user!;
|
|
58
|
-
const options = await buildRegistrationOptions(user);
|
|
59
|
-
setChallengeCookie(reply, options.challenge);
|
|
60
|
-
return options;
|
|
61
|
-
}
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
app.post(
|
|
65
|
-
"/webauthn/register/verify",
|
|
66
|
-
{ preHandler: [app.authenticate] },
|
|
67
|
-
async (request: FastifyRequest, reply: FastifyReply) => {
|
|
68
|
-
const user = request.user!;
|
|
69
|
-
const body = RegisterVerifySchema.parse(request.body);
|
|
70
|
-
const challenge = getChallengeCookie(request);
|
|
71
|
-
if (!challenge) {
|
|
72
|
-
return reply.status(400).send({ error: "Challenge expired or missing" });
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const stored = consumeChallenge(challenge);
|
|
76
|
-
if (!stored || stored.userId !== user.id) {
|
|
77
|
-
clearChallengeCookie(reply);
|
|
78
|
-
return reply.status(400).send({ error: "Invalid challenge" });
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
try {
|
|
82
|
-
await verifyAndStoreRegistration(
|
|
83
|
-
user,
|
|
84
|
-
body.response as unknown as RegistrationResponseJSON,
|
|
85
|
-
challenge,
|
|
86
|
-
body.deviceName
|
|
87
|
-
);
|
|
88
|
-
clearChallengeCookie(reply);
|
|
89
|
-
await request.audit("webauthn_registered", { userId: user.id });
|
|
90
|
-
return { success: true };
|
|
91
|
-
} catch (err) {
|
|
92
|
-
const message = err instanceof Error ? err.message : "Registration failed";
|
|
93
|
-
return reply.status(400).send({ error: message });
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
app.post("/webauthn/authenticate/options", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
99
|
-
const body = AuthenticateOptionsSchema.parse(request.body);
|
|
100
|
-
const options = await buildAuthenticationOptions(body.email);
|
|
101
|
-
setChallengeCookie(reply, options.challenge);
|
|
102
|
-
return options;
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
app.post("/webauthn/authenticate/verify", async (request: FastifyRequest, reply: FastifyReply) => {
|
|
106
|
-
const body = AuthenticateVerifySchema.parse(request.body);
|
|
107
|
-
const challenge = getChallengeCookie(request);
|
|
108
|
-
if (!challenge) {
|
|
109
|
-
return reply.status(400).send({ error: "Challenge expired or missing" });
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const stored = consumeChallenge(challenge);
|
|
113
|
-
if (!stored) {
|
|
114
|
-
clearChallengeCookie(reply);
|
|
115
|
-
return reply.status(400).send({ error: "Invalid challenge" });
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
try {
|
|
119
|
-
const { user } = await verifyAuthentication(
|
|
120
|
-
body.response as unknown as AuthenticationResponseJSON,
|
|
121
|
-
challenge
|
|
122
|
-
);
|
|
123
|
-
clearChallengeCookie(reply);
|
|
124
|
-
|
|
125
|
-
const fingerprint = fingerprintFromRequest(request);
|
|
126
|
-
await recordDevice(user.id, fingerprint, request.ip, request.headers["user-agent"]);
|
|
127
|
-
const tokens = await createTokenSet(
|
|
128
|
-
user,
|
|
129
|
-
request.ip,
|
|
130
|
-
request.headers["user-agent"],
|
|
131
|
-
{},
|
|
132
|
-
fingerprint
|
|
133
|
-
);
|
|
134
|
-
setSessionCookies(reply, tokens.accessToken, tokens.refreshToken);
|
|
135
|
-
|
|
136
|
-
await request.audit("webauthn_authenticated", { userId: user.id });
|
|
137
|
-
return {
|
|
138
|
-
user: toPublicUser(user),
|
|
139
|
-
accessToken: tokens.accessToken,
|
|
140
|
-
refreshToken: tokens.refreshToken,
|
|
141
|
-
};
|
|
142
|
-
} catch (err) {
|
|
143
|
-
const message = err instanceof Error ? err.message : "Authentication failed";
|
|
144
|
-
return reply.status(400).send({ error: message });
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
package/src/routes/workflows.ts
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import type { FastifyInstance, FastifyRequest, FastifyReply } from "fastify";
|
|
3
|
-
import { eq, and } from "drizzle-orm";
|
|
4
|
-
import { db } from "../db/index.js";
|
|
5
|
-
import { workflows, orgMemberships } from "../db/schema.js";
|
|
6
|
-
import { registerWorkflow, listWorkflowRuns } from "../services/workflows/engine.js";
|
|
7
|
-
|
|
8
|
-
const WorkflowStepSchema = z.object({
|
|
9
|
-
type: z.string(),
|
|
10
|
-
name: z.string().optional(),
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const CreateWorkflowSchema = z.object({
|
|
14
|
-
orgId: z.string().uuid(),
|
|
15
|
-
name: z.string().min(1).max(255),
|
|
16
|
-
trigger: z.enum(["user_registered", "user_login", "organization_created"]),
|
|
17
|
-
definition: z.object({
|
|
18
|
-
steps: z.array(WorkflowStepSchema.and(z.record(z.string(), z.unknown()))),
|
|
19
|
-
}),
|
|
20
|
-
isActive: z.boolean().optional(),
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
async function requireOrgMembership(request: FastifyRequest, reply: FastifyReply, orgId: string) {
|
|
24
|
-
await request.server.authenticate(request, reply);
|
|
25
|
-
if (reply.sent) return false;
|
|
26
|
-
|
|
27
|
-
const userId = request.user!.id;
|
|
28
|
-
const [membership] = await db
|
|
29
|
-
.select()
|
|
30
|
-
.from(orgMemberships)
|
|
31
|
-
.where(and(eq(orgMemberships.orgId, orgId), eq(orgMemberships.userId, userId)))
|
|
32
|
-
.limit(1);
|
|
33
|
-
|
|
34
|
-
if (!membership) {
|
|
35
|
-
reply.status(403).send({ error: "Forbidden: not a member of this organization" });
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export default async function workflowRoutes(app: FastifyInstance) {
|
|
42
|
-
app.get("/workflows", { preHandler: [app.authenticate] }, async (request, reply) => {
|
|
43
|
-
const query = request.query as { orgId?: string };
|
|
44
|
-
const orgId = query?.orgId;
|
|
45
|
-
|
|
46
|
-
if (!orgId) {
|
|
47
|
-
return reply.status(400).send({ error: "orgId query parameter is required" });
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Verify org membership
|
|
51
|
-
const userId = request.user!.id;
|
|
52
|
-
const [membership] = await db
|
|
53
|
-
.select()
|
|
54
|
-
.from(orgMemberships)
|
|
55
|
-
.where(and(eq(orgMemberships.orgId, orgId), eq(orgMemberships.userId, userId)))
|
|
56
|
-
.limit(1);
|
|
57
|
-
if (!membership) {
|
|
58
|
-
return reply.status(403).send({ error: "Forbidden: not a member of this organization" });
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const all = await db.select().from(workflows).where(eq(workflows.orgId, orgId));
|
|
62
|
-
return { workflows: all };
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
app.post("/workflows", { preHandler: [app.authenticate] }, async (request, reply) => {
|
|
66
|
-
const body = CreateWorkflowSchema.parse(request.body);
|
|
67
|
-
|
|
68
|
-
// Verify org membership
|
|
69
|
-
const userId = request.user!.id;
|
|
70
|
-
const [membership] = await db
|
|
71
|
-
.select()
|
|
72
|
-
.from(orgMemberships)
|
|
73
|
-
.where(and(eq(orgMemberships.orgId, body.orgId), eq(orgMemberships.userId, userId)))
|
|
74
|
-
.limit(1);
|
|
75
|
-
if (!membership) {
|
|
76
|
-
return reply.status(403).send({ error: "Forbidden: not a member of this organization" });
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const workflow = await registerWorkflow({
|
|
80
|
-
orgId: body.orgId,
|
|
81
|
-
name: body.name,
|
|
82
|
-
trigger: body.trigger,
|
|
83
|
-
definition: body.definition,
|
|
84
|
-
});
|
|
85
|
-
await request.audit("workflow_created", { workflowId: workflow.id, trigger: body.trigger, orgId: body.orgId });
|
|
86
|
-
return reply.status(201).send(workflow);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
app.get("/workflows/:id", { preHandler: [app.authenticate] }, async (request, reply) => {
|
|
90
|
-
const { id } = request.params as { id: string };
|
|
91
|
-
const [workflow] = await db.select().from(workflows).where(eq(workflows.id, id)).limit(1);
|
|
92
|
-
if (!workflow) return reply.status(404).send({ error: "Workflow not found" });
|
|
93
|
-
|
|
94
|
-
// Verify org membership
|
|
95
|
-
if (workflow.orgId) {
|
|
96
|
-
const userId = request.user!.id;
|
|
97
|
-
const [membership] = await db
|
|
98
|
-
.select()
|
|
99
|
-
.from(orgMemberships)
|
|
100
|
-
.where(and(eq(orgMemberships.orgId, workflow.orgId), eq(orgMemberships.userId, userId)))
|
|
101
|
-
.limit(1);
|
|
102
|
-
if (!membership) {
|
|
103
|
-
return reply.status(403).send({ error: "Forbidden" });
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return { workflow };
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
app.delete("/workflows/:id", { preHandler: [app.authenticate] }, async (request, reply) => {
|
|
111
|
-
const { id } = request.params as { id: string };
|
|
112
|
-
const userId = request.user!.id;
|
|
113
|
-
|
|
114
|
-
// Find the workflow and verify org membership
|
|
115
|
-
const [workflow] = await db.select().from(workflows).where(eq(workflows.id, id)).limit(1);
|
|
116
|
-
if (!workflow) return reply.status(404).send({ error: "Workflow not found" });
|
|
117
|
-
|
|
118
|
-
// Verify org membership
|
|
119
|
-
if (workflow.orgId) {
|
|
120
|
-
const [membership] = await db
|
|
121
|
-
.select()
|
|
122
|
-
.from(orgMemberships)
|
|
123
|
-
.where(and(eq(orgMemberships.orgId, workflow.orgId), eq(orgMemberships.userId, userId)))
|
|
124
|
-
.limit(1);
|
|
125
|
-
if (!membership) {
|
|
126
|
-
return reply.status(403).send({ error: "Forbidden" });
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const [record] = await db.delete(workflows).where(eq(workflows.id, id)).returning();
|
|
131
|
-
if (!record) return reply.status(404).send({ error: "Workflow not found" });
|
|
132
|
-
await request.audit("workflow_deleted", { workflowId: record.id });
|
|
133
|
-
return { success: true };
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
app.get("/workflows/:id/runs", { preHandler: [app.authenticate] }, async (request, reply) => {
|
|
137
|
-
const { id } = request.params as { id: string };
|
|
138
|
-
const [workflow] = await db.select().from(workflows).where(eq(workflows.id, id)).limit(1);
|
|
139
|
-
if (!workflow) return reply.status(404).send({ error: "Workflow not found" });
|
|
140
|
-
|
|
141
|
-
// Verify org membership
|
|
142
|
-
if (workflow.orgId) {
|
|
143
|
-
const userId = request.user!.id;
|
|
144
|
-
const [membership] = await db
|
|
145
|
-
.select()
|
|
146
|
-
.from(orgMemberships)
|
|
147
|
-
.where(and(eq(orgMemberships.orgId, workflow.orgId), eq(orgMemberships.userId, userId)))
|
|
148
|
-
.limit(1);
|
|
149
|
-
if (!membership) {
|
|
150
|
-
return reply.status(403).send({ error: "Forbidden" });
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const runs = await listWorkflowRuns(id);
|
|
155
|
-
return { runs };
|
|
156
|
-
});
|
|
157
|
-
}
|
package/src/sdk/index.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import type { KeystoneSdk, AuthenticationSdk, IdentitySdk, OrganizationSdk, AuthorizationSdk } from "./types.js";
|
|
2
|
-
import type {
|
|
3
|
-
AuthenticationApplicationService,
|
|
4
|
-
IdentityApplicationService,
|
|
5
|
-
OrganizationApplicationService,
|
|
6
|
-
} from "../services/application/index.js";
|
|
7
|
-
import type { AuthorizationDomainService } from "../services/domain/authorization.js";
|
|
8
|
-
import { getContainer } from "../container.js";
|
|
9
|
-
import { buildApplicationServices } from "../di.js";
|
|
10
|
-
|
|
11
|
-
class SdkAuthenticationClient implements AuthenticationSdk {
|
|
12
|
-
constructor(private readonly app: AuthenticationApplicationService) {}
|
|
13
|
-
|
|
14
|
-
register(input: { username: string; email: string; password: string; name?: string; clientId?: string; metadata?: Record<string, unknown> }) {
|
|
15
|
-
return this.app.register(input);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
login(input: { email: string; password: string; clientId?: string }) {
|
|
19
|
-
return this.app.login(input);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async refresh(refreshToken: string, clientId?: string) {
|
|
23
|
-
const result = await this.app.refresh(refreshToken, clientId);
|
|
24
|
-
if (!result.success) return result;
|
|
25
|
-
return { success: true as const, data: { accessToken: result.data.accessToken, refreshToken: result.data.refreshToken, expiresAt: result.data.expiresAt } };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
logout(refreshToken?: string) {
|
|
29
|
-
return this.app.logout(refreshToken);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
createPasswordResetToken(email: string) {
|
|
33
|
-
return this.app.createPasswordResetToken(email);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
resetPasswordWithToken(token: string, newPassword: string) {
|
|
37
|
-
return this.app.resetPasswordWithToken(token, newPassword);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
class SdkIdentityClient implements IdentitySdk {
|
|
42
|
-
constructor(private readonly app: IdentityApplicationService) {}
|
|
43
|
-
|
|
44
|
-
findUser(id: string) {
|
|
45
|
-
return this.app.findUser(id);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
findUserByEmail(email: string) {
|
|
49
|
-
return this.app.findUserByEmail(email);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
upsertInvitedUser(input: { email: string; name?: string; username?: string }) {
|
|
53
|
-
return this.app.upsertInvitedUser(input);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
updateUserProfile(userId: string, updates: Partial<{ name: string; username: string; role: string; emailVerified: boolean }>) {
|
|
57
|
-
return this.app.updateUserProfile(userId, updates);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
deactivate(userId: string) {
|
|
61
|
-
return this.app.deactivate(userId);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
listOrganizationUsers(orgId: string) {
|
|
65
|
-
return this.app.listOrganizationUsers(orgId);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
linkUserIdentity(userId: string, providerId: string, providerType: string, externalSub: string, email?: string) {
|
|
69
|
-
return this.app.linkUserIdentity(userId, providerId, providerType, externalSub, email);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
getFederationAuthorizeUrl(provider: string, state: string, redirectUri: string) {
|
|
73
|
-
return this.app.getFederationAuthorizeUrl(provider, state, redirectUri);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
completeFederationLogin(provider: string, code: string, redirectUri: string) {
|
|
77
|
-
return this.app.completeFederationLogin(provider, code, redirectUri);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
class SdkOrganizationClient implements OrganizationSdk {
|
|
82
|
-
constructor(private readonly app: OrganizationApplicationService) {}
|
|
83
|
-
|
|
84
|
-
createOrganization(userId: string, input: { name: string; slug?: string; plan?: string }) {
|
|
85
|
-
return this.app.createOrganization(userId, input);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
getOrganization(userId: string, orgId: string) {
|
|
89
|
-
return this.app.getOrganization(userId, orgId);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
listUserOrganizations(userId: string) {
|
|
93
|
-
return this.app.listUserOrganizations(userId);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
inviteMember(actorId: string, orgId: string, input: { email: string; role: "owner" | "admin" | "member" }) {
|
|
97
|
-
return this.app.inviteMember(actorId, orgId, input);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
createApplication(actorId: string, orgId: string, input: { name: string; redirectUris?: string[]; allowedOrigins?: string[] }) {
|
|
101
|
-
return this.app.createApplication(actorId, orgId, input);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
listOrganizationApplications(actorId: string, orgId: string) {
|
|
105
|
-
return this.app.listOrganizationApplications(actorId, orgId);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
updateApplication(actorId: string, orgId: string, appId: string, updates: Partial<{ name: string; redirectUris: string[]; allowedOrigins: string[]; allowedIps: string[]; blockedIps: string[]; isActive: boolean; branding: Record<string, unknown> }>) {
|
|
109
|
-
return this.app.updateApplication(actorId, orgId, appId, updates);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
class SdkAuthorizationClient implements AuthorizationSdk {
|
|
114
|
-
constructor(private readonly domain: AuthorizationDomainService) {}
|
|
115
|
-
|
|
116
|
-
hasPermission(role: string, resource: string, action: string) {
|
|
117
|
-
return this.domain.hasPermission(role, resource, action);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
requirePermission(role: string, resource: string, action: string) {
|
|
121
|
-
return this.domain.requirePermission(role, resource, action);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
requireOrgRole(userId: string, orgId: string, allowedRoles: Array<"owner" | "admin" | "member">) {
|
|
125
|
-
return this.domain.requireOrgRole(userId, orgId, allowedRoles);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
isOrgMember(userId: string, orgId: string) {
|
|
129
|
-
return this.domain.isOrgMember(userId, orgId);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
let cachedSdk: KeystoneSdk | null = null;
|
|
134
|
-
|
|
135
|
-
export function getSdk(): KeystoneSdk {
|
|
136
|
-
if (cachedSdk) return cachedSdk;
|
|
137
|
-
const container = getContainer();
|
|
138
|
-
const apps = buildApplicationServices(container);
|
|
139
|
-
cachedSdk = {
|
|
140
|
-
authentication: new SdkAuthenticationClient(apps.auth),
|
|
141
|
-
identity: new SdkIdentityClient(apps.identity),
|
|
142
|
-
organization: new SdkOrganizationClient(apps.organization),
|
|
143
|
-
authorization: new SdkAuthorizationClient(apps.authorization),
|
|
144
|
-
};
|
|
145
|
-
return cachedSdk;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export function setSdk(sdk: KeystoneSdk): void {
|
|
149
|
-
cachedSdk = sdk;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export type { KeystoneSdk, AuthenticationSdk, IdentitySdk, OrganizationSdk, AuthorizationSdk } from "./types.js";
|
package/src/sdk/types.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { User, Organization, Application, OrgMembership } from "../db/schema.js";
|
|
2
|
-
import type { Result } from "../lib/result.js";
|
|
3
|
-
|
|
4
|
-
export interface AuthResponse {
|
|
5
|
-
user: User;
|
|
6
|
-
accessToken: string;
|
|
7
|
-
refreshToken: string;
|
|
8
|
-
expiresAt: Date;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface AuthenticationSdk {
|
|
12
|
-
register(input: { username: string; email: string; password: string; name?: string; clientId?: string; metadata?: Record<string, unknown> }): Promise<Result<AuthResponse>>;
|
|
13
|
-
login(input: { email: string; password: string; clientId?: string }): Promise<Result<AuthResponse>>;
|
|
14
|
-
refresh(refreshToken: string, clientId?: string): Promise<Result<{ accessToken: string; refreshToken: string; expiresAt: Date }>>;
|
|
15
|
-
logout(refreshToken?: string): Promise<Result<void>>;
|
|
16
|
-
createPasswordResetToken(email: string): Promise<Result<{ token: string; user: User } | null>>;
|
|
17
|
-
resetPasswordWithToken(token: string, newPassword: string): Promise<Result<User>>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface IdentitySdk {
|
|
21
|
-
findUser(id: string): Promise<Result<User>>;
|
|
22
|
-
findUserByEmail(email: string): Promise<Result<User>>;
|
|
23
|
-
upsertInvitedUser(input: { email: string; name?: string; username?: string }): Promise<Result<User>>;
|
|
24
|
-
updateUserProfile(userId: string, updates: Partial<{ name: string; username: string; role: string; emailVerified: boolean }>): Promise<Result<User>>;
|
|
25
|
-
deactivate(userId: string): Promise<Result<void>>;
|
|
26
|
-
listOrganizationUsers(orgId: string): Promise<User[]>;
|
|
27
|
-
linkUserIdentity(userId: string, providerId: string, providerType: string, externalSub: string, email?: string): Promise<Result<void>>;
|
|
28
|
-
getFederationAuthorizeUrl(provider: string, state: string, redirectUri: string): Promise<Result<{ url: string }>>;
|
|
29
|
-
completeFederationLogin(provider: string, code: string, redirectUri: string): Promise<Result<{ user: User; tokens: { accessToken: string; refreshToken: string } }>>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface OrganizationSdk {
|
|
33
|
-
createOrganization(userId: string, input: { name: string; slug?: string; plan?: string }): Promise<Result<Organization>>;
|
|
34
|
-
getOrganization(userId: string, orgId: string): Promise<Result<Organization>>;
|
|
35
|
-
listUserOrganizations(userId: string): Promise<Organization[]>;
|
|
36
|
-
inviteMember(actorId: string, orgId: string, input: { email: string; role: "owner" | "admin" | "member" }): Promise<Result<{ user: { id: string }; membership: OrgMembership }>>;
|
|
37
|
-
createApplication(actorId: string, orgId: string, input: { name: string; redirectUris?: string[]; allowedOrigins?: string[] }): Promise<Result<Application & { clientSecret: string }>>;
|
|
38
|
-
listOrganizationApplications(actorId: string, orgId: string): Promise<Result<Application[]>>;
|
|
39
|
-
updateApplication(actorId: string, orgId: string, appId: string, updates: Partial<{ name: string; redirectUris: string[]; allowedOrigins: string[]; allowedIps: string[]; blockedIps: string[]; isActive: boolean; branding: Record<string, unknown> }>): Promise<Result<Application>>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface AuthorizationSdk {
|
|
43
|
-
hasPermission(role: string, resource: string, action: string): Promise<boolean>;
|
|
44
|
-
requirePermission(role: string, resource: string, action: string): Promise<Result<void>>;
|
|
45
|
-
requireOrgRole(userId: string, orgId: string, allowedRoles: Array<"owner" | "admin" | "member">): Promise<Result<OrgMembership>>;
|
|
46
|
-
isOrgMember(userId: string, orgId: string): Promise<OrgMembership | undefined>;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface KeystoneSdk {
|
|
50
|
-
authentication: AuthenticationSdk;
|
|
51
|
-
identity: IdentitySdk;
|
|
52
|
-
organization: OrganizationSdk;
|
|
53
|
-
authorization: AuthorizationSdk;
|
|
54
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { redis } from "./redis.js";
|
|
2
|
-
|
|
3
|
-
const ANOMALY_WINDOW_SECONDS = 300;
|
|
4
|
-
const FAILED_LOGIN_THRESHOLD = 10;
|
|
5
|
-
const NEW_DEVICE_THRESHOLD = 3;
|
|
6
|
-
// Two logins from different IPs within this window are flagged as
|
|
7
|
-
// suspicious (approximation of impossible travel without a GeoIP database).
|
|
8
|
-
const IMPOSSIBLE_TRAVEL_WINDOW_SECONDS = 900;
|
|
9
|
-
|
|
10
|
-
export async function recordFailedLogin(identifier: string): Promise<number> {
|
|
11
|
-
if (redis.status !== "ready" && redis.status !== "connect") return 0;
|
|
12
|
-
const key = `anomaly:failed_login:${identifier}`;
|
|
13
|
-
const now = Date.now();
|
|
14
|
-
const windowStart = now - ANOMALY_WINDOW_SECONDS * 1000;
|
|
15
|
-
|
|
16
|
-
const pipeline = redis.pipeline();
|
|
17
|
-
pipeline.zremrangebyscore(key, 0, windowStart);
|
|
18
|
-
pipeline.zadd(key, now, `${now}:${Math.random().toString(36).slice(2)}`);
|
|
19
|
-
pipeline.zcard(key);
|
|
20
|
-
pipeline.pexpire(key, ANOMALY_WINDOW_SECONDS * 1000);
|
|
21
|
-
const results = await pipeline.exec();
|
|
22
|
-
return (results?.[2]?.[1] as number) ?? 0;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export async function isFailedLoginAnomaly(identifier: string): Promise<boolean> {
|
|
26
|
-
const count = await recordFailedLogin(identifier);
|
|
27
|
-
return count >= FAILED_LOGIN_THRESHOLD;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export async function recordNewDevice(userId: string): Promise<number> {
|
|
31
|
-
if (redis.status !== "ready" && redis.status !== "connect") return 0;
|
|
32
|
-
const key = `anomaly:new_device:${userId}`;
|
|
33
|
-
const now = Date.now();
|
|
34
|
-
const windowStart = now - ANOMALY_WINDOW_SECONDS * 1000;
|
|
35
|
-
|
|
36
|
-
const pipeline = redis.pipeline();
|
|
37
|
-
pipeline.zremrangebyscore(key, 0, windowStart);
|
|
38
|
-
pipeline.zadd(key, now, `${now}:${Math.random().toString(36).slice(2)}`);
|
|
39
|
-
pipeline.zcard(key);
|
|
40
|
-
pipeline.pexpire(key, ANOMALY_WINDOW_SECONDS * 1000);
|
|
41
|
-
const results = await pipeline.exec();
|
|
42
|
-
return (results?.[2]?.[1] as number) ?? 0;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function isNewDeviceAnomaly(userId: string): Promise<boolean> {
|
|
46
|
-
const count = await recordNewDevice(userId);
|
|
47
|
-
return count >= NEW_DEVICE_THRESHOLD;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Records the login location (IP) for a user and returns true when the
|
|
52
|
-
* previous login happened from a *different* IP within the impossible-travel
|
|
53
|
-
* window. Without a GeoIP database this is an approximation: physically
|
|
54
|
-
* changing networks within a few minutes usually indicates credential misuse
|
|
55
|
-
* (or a VPN/mobile network switch, so alerts should say "suspicious", not
|
|
56
|
-
* "blocked").
|
|
57
|
-
*/
|
|
58
|
-
export async function checkImpossibleTravel(userId: string, ip: string | undefined): Promise<boolean> {
|
|
59
|
-
if (!ip || (redis.status !== "ready" && redis.status !== "connect")) return false;
|
|
60
|
-
const key = `anomaly:last_login:${userId}`;
|
|
61
|
-
const now = Date.now();
|
|
62
|
-
|
|
63
|
-
const previous = await redis.hgetall(key);
|
|
64
|
-
await redis
|
|
65
|
-
.multi()
|
|
66
|
-
.hset(key, "ip", ip, "ts", String(now))
|
|
67
|
-
.pexpire(key, 30 * 24 * 60 * 60 * 1000)
|
|
68
|
-
.exec();
|
|
69
|
-
|
|
70
|
-
if (!previous?.ip || !previous?.ts) return false;
|
|
71
|
-
const elapsed = now - Number(previous.ts);
|
|
72
|
-
return previous.ip !== ip && elapsed < IMPOSSIBLE_TRAVEL_WINDOW_SECONDS * 1000;
|
|
73
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { AuthenticationDomainService } from "../domain/authentication.js";
|
|
2
|
-
import type { TokenSet } from "../tokens.js";
|
|
3
|
-
import type { User } from "../../db/schema.js";
|
|
4
|
-
import type { Result } from "../../lib/result.js";
|
|
5
|
-
|
|
6
|
-
export interface RegisterRequest {
|
|
7
|
-
username: string;
|
|
8
|
-
email: string;
|
|
9
|
-
password: string;
|
|
10
|
-
name?: string;
|
|
11
|
-
clientId?: string;
|
|
12
|
-
metadata?: Record<string, unknown>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface LoginRequest {
|
|
16
|
-
email: string;
|
|
17
|
-
password: string;
|
|
18
|
-
clientId?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface AuthResponse {
|
|
22
|
-
user: User;
|
|
23
|
-
accessToken: string;
|
|
24
|
-
refreshToken: string;
|
|
25
|
-
expiresAt: Date;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export class AuthenticationApplicationService {
|
|
29
|
-
constructor(private readonly domain: AuthenticationDomainService) {}
|
|
30
|
-
|
|
31
|
-
async register(request: RegisterRequest): Promise<Result<AuthResponse>> {
|
|
32
|
-
const result = await this.domain.register(request);
|
|
33
|
-
if (!result.success) return result;
|
|
34
|
-
return {
|
|
35
|
-
success: true,
|
|
36
|
-
data: this.toAuthResponse(result.data.user, result.data.tokens),
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async login(request: LoginRequest): Promise<Result<AuthResponse>> {
|
|
41
|
-
const result = await this.domain.login(request);
|
|
42
|
-
if (!result.success) return result;
|
|
43
|
-
return {
|
|
44
|
-
success: true,
|
|
45
|
-
data: this.toAuthResponse(result.data.user, result.data.tokens),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async refresh(refreshToken: string, clientId?: string): Promise<Result<TokenSet>> {
|
|
50
|
-
const result = await this.domain.refresh(refreshToken, clientId);
|
|
51
|
-
if (!result.success) return result;
|
|
52
|
-
return { success: true, data: result.data.tokens };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async logout(refreshToken?: string): Promise<Result<void>> {
|
|
56
|
-
return this.domain.logout(refreshToken);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async createPasswordResetToken(email: string): Promise<Result<{ token: string; user: User } | null>> {
|
|
60
|
-
return this.domain.createPasswordResetToken(email);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async resetPasswordWithToken(token: string, newPassword: string): Promise<Result<User>> {
|
|
64
|
-
return this.domain.resetPasswordWithToken(token, newPassword);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
private toAuthResponse(user: User, tokens: TokenSet): AuthResponse {
|
|
68
|
-
return {
|
|
69
|
-
user,
|
|
70
|
-
accessToken: tokens.accessToken,
|
|
71
|
-
refreshToken: tokens.refreshToken,
|
|
72
|
-
expiresAt: tokens.expiresAt,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
}
|