@carlonicora/nestjs-neo4jsonapi 1.39.0 → 1.40.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/dist/config/base.config.d.ts.map +1 -1
- package/dist/config/base.config.js +9 -0
- package/dist/config/base.config.js.map +1 -1
- package/dist/config/interfaces/base.config.interface.d.ts +2 -0
- package/dist/config/interfaces/base.config.interface.d.ts.map +1 -1
- package/dist/config/interfaces/config.two.factor.interface.d.ts +27 -0
- package/dist/config/interfaces/config.two.factor.interface.d.ts.map +1 -0
- package/dist/config/interfaces/config.two.factor.interface.js +3 -0
- package/dist/config/interfaces/config.two.factor.interface.js.map +1 -0
- package/dist/config/interfaces/index.d.ts +1 -0
- package/dist/config/interfaces/index.d.ts.map +1 -1
- package/dist/config/interfaces/index.js +1 -0
- package/dist/config/interfaces/index.js.map +1 -1
- package/dist/core/jsonapi/services/jsonapi.service.d.ts.map +1 -1
- package/dist/core/jsonapi/services/jsonapi.service.js +3 -1
- package/dist/core/jsonapi/services/jsonapi.service.js.map +1 -1
- package/dist/core/llm/services/vision.llm.service.d.ts.map +1 -1
- package/dist/core/llm/services/vision.llm.service.js +0 -1
- package/dist/core/llm/services/vision.llm.service.js.map +1 -1
- package/dist/core/security/services/security.service.d.ts +27 -0
- package/dist/core/security/services/security.service.d.ts.map +1 -1
- package/dist/core/security/services/security.service.js +37 -0
- package/dist/core/security/services/security.service.js.map +1 -1
- package/dist/foundations/auth/auth.module.d.ts.map +1 -1
- package/dist/foundations/auth/auth.module.js +6 -0
- package/dist/foundations/auth/auth.module.js.map +1 -1
- package/dist/foundations/auth/entities/pending-auth.entity.d.ts +16 -0
- package/dist/foundations/auth/entities/pending-auth.entity.d.ts.map +1 -0
- package/dist/foundations/auth/entities/pending-auth.entity.js +3 -0
- package/dist/foundations/auth/entities/pending-auth.entity.js.map +1 -0
- package/dist/foundations/auth/entities/pending-auth.map.d.ts +6 -0
- package/dist/foundations/auth/entities/pending-auth.map.d.ts.map +1 -0
- package/dist/foundations/auth/entities/pending-auth.map.js +20 -0
- package/dist/foundations/auth/entities/pending-auth.map.js.map +1 -0
- package/dist/foundations/auth/entities/pending-auth.meta.d.ts +3 -0
- package/dist/foundations/auth/entities/pending-auth.meta.d.ts.map +1 -0
- package/dist/foundations/auth/entities/pending-auth.meta.js +10 -0
- package/dist/foundations/auth/entities/pending-auth.meta.js.map +1 -0
- package/dist/foundations/auth/entities/pending-auth.model.d.ts +9 -0
- package/dist/foundations/auth/entities/pending-auth.model.d.ts.map +1 -0
- package/dist/foundations/auth/entities/pending-auth.model.js +19 -0
- package/dist/foundations/auth/entities/pending-auth.model.js.map +1 -0
- package/dist/foundations/auth/serialisers/pending-auth.serialiser.d.ts +18 -0
- package/dist/foundations/auth/serialisers/pending-auth.serialiser.d.ts.map +1 -0
- package/dist/foundations/auth/serialisers/pending-auth.serialiser.js +49 -0
- package/dist/foundations/auth/serialisers/pending-auth.serialiser.js.map +1 -0
- package/dist/foundations/auth/services/auth.service.d.ts +12 -1
- package/dist/foundations/auth/services/auth.service.d.ts.map +1 -1
- package/dist/foundations/auth/services/auth.service.js +60 -6
- package/dist/foundations/auth/services/auth.service.js.map +1 -1
- package/dist/foundations/foundations.modules.d.ts.map +1 -1
- package/dist/foundations/foundations.modules.js +2 -0
- package/dist/foundations/foundations.modules.js.map +1 -1
- package/dist/foundations/index.d.ts +1 -0
- package/dist/foundations/index.d.ts.map +1 -1
- package/dist/foundations/index.js +1 -0
- package/dist/foundations/index.js.map +1 -1
- package/dist/foundations/stripe/services/billing.service.d.ts +3 -4
- package/dist/foundations/stripe/services/billing.service.d.ts.map +1 -1
- package/dist/foundations/stripe/services/billing.service.js +1 -1
- package/dist/foundations/stripe/services/billing.service.js.map +1 -1
- package/dist/foundations/stripe-invoice/services/stripe-invoice-admin.service.d.ts +1 -1
- package/dist/foundations/stripe-invoice/services/stripe-invoice-admin.service.js +1 -1
- package/dist/foundations/stripe-invoice/services/stripe-invoice-api.service.d.ts +1 -1
- package/dist/foundations/stripe-invoice/services/stripe-invoice-api.service.d.ts.map +1 -1
- package/dist/foundations/stripe-invoice/services/stripe-invoice-api.service.js +2 -2
- package/dist/foundations/stripe-invoice/services/stripe-invoice-api.service.js.map +1 -1
- package/dist/foundations/stripe-subscription/controllers/stripe-subscription.controller.d.ts.map +1 -1
- package/dist/foundations/stripe-subscription/controllers/stripe-subscription.controller.js +0 -3
- package/dist/foundations/stripe-subscription/controllers/stripe-subscription.controller.js.map +1 -1
- package/dist/foundations/stripe-subscription/services/stripe-subscription-admin.service.d.ts +1 -1
- package/dist/foundations/stripe-subscription/services/stripe-subscription-admin.service.d.ts.map +1 -1
- package/dist/foundations/stripe-subscription/services/stripe-subscription-admin.service.js +1 -3
- package/dist/foundations/stripe-subscription/services/stripe-subscription-admin.service.js.map +1 -1
- package/dist/foundations/stripe-subscription/services/stripe-subscription-api.service.d.ts +1 -1
- package/dist/foundations/stripe-subscription/services/stripe-subscription-api.service.d.ts.map +1 -1
- package/dist/foundations/stripe-subscription/services/stripe-subscription-api.service.js +1 -5
- package/dist/foundations/stripe-subscription/services/stripe-subscription-api.service.js.map +1 -1
- package/dist/foundations/two-factor/controllers/passkey.controller.d.ts +52 -0
- package/dist/foundations/two-factor/controllers/passkey.controller.d.ts.map +1 -0
- package/dist/foundations/two-factor/controllers/passkey.controller.js +155 -0
- package/dist/foundations/two-factor/controllers/passkey.controller.js.map +1 -0
- package/dist/foundations/two-factor/controllers/totp.controller.d.ts +47 -0
- package/dist/foundations/two-factor/controllers/totp.controller.d.ts.map +1 -0
- package/dist/foundations/two-factor/controllers/totp.controller.js +132 -0
- package/dist/foundations/two-factor/controllers/totp.controller.js.map +1 -0
- package/dist/foundations/two-factor/controllers/two-factor.controller.d.ts +124 -0
- package/dist/foundations/two-factor/controllers/two-factor.controller.d.ts.map +1 -0
- package/dist/foundations/two-factor/controllers/two-factor.controller.js +352 -0
- package/dist/foundations/two-factor/controllers/two-factor.controller.js.map +1 -0
- package/dist/foundations/two-factor/dtos/passkey-options.dto.d.ts +42 -0
- package/dist/foundations/two-factor/dtos/passkey-options.dto.d.ts.map +1 -0
- package/dist/foundations/two-factor/dtos/passkey-options.dto.js +77 -0
- package/dist/foundations/two-factor/dtos/passkey-options.dto.js.map +1 -0
- package/dist/foundations/two-factor/dtos/passkey-verify.dto.d.ts +120 -0
- package/dist/foundations/two-factor/dtos/passkey-verify.dto.d.ts.map +1 -0
- package/dist/foundations/two-factor/dtos/passkey-verify.dto.js +226 -0
- package/dist/foundations/two-factor/dtos/passkey-verify.dto.js.map +1 -0
- package/dist/foundations/two-factor/dtos/totp-setup.dto.d.ts +32 -0
- package/dist/foundations/two-factor/dtos/totp-setup.dto.d.ts.map +1 -0
- package/dist/foundations/two-factor/dtos/totp-setup.dto.js +67 -0
- package/dist/foundations/two-factor/dtos/totp-setup.dto.js.map +1 -0
- package/dist/foundations/two-factor/dtos/totp-verify.dto.d.ts +62 -0
- package/dist/foundations/two-factor/dtos/totp-verify.dto.d.ts.map +1 -0
- package/dist/foundations/two-factor/dtos/totp-verify.dto.js +118 -0
- package/dist/foundations/two-factor/dtos/totp-verify.dto.js.map +1 -0
- package/dist/foundations/two-factor/dtos/two-factor-verify.dto.d.ts +83 -0
- package/dist/foundations/two-factor/dtos/two-factor-verify.dto.d.ts.map +1 -0
- package/dist/foundations/two-factor/dtos/two-factor-verify.dto.js +161 -0
- package/dist/foundations/two-factor/dtos/two-factor-verify.dto.js.map +1 -0
- package/dist/foundations/two-factor/entities/backup-code.d.ts +22 -0
- package/dist/foundations/two-factor/entities/backup-code.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/backup-code.js +25 -0
- package/dist/foundations/two-factor/entities/backup-code.js.map +1 -0
- package/dist/foundations/two-factor/entities/backup-code.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/backup-code.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/backup-code.meta.js +10 -0
- package/dist/foundations/two-factor/entities/backup-code.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/backup-codes-count.d.ts +18 -0
- package/dist/foundations/two-factor/entities/backup-codes-count.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/backup-codes-count.js +19 -0
- package/dist/foundations/two-factor/entities/backup-codes-count.js.map +1 -0
- package/dist/foundations/two-factor/entities/backup-codes-count.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/backup-codes-count.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/backup-codes-count.meta.js +10 -0
- package/dist/foundations/two-factor/entities/backup-codes-count.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/backup-codes-generation.d.ts +19 -0
- package/dist/foundations/two-factor/entities/backup-codes-generation.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/backup-codes-generation.js +20 -0
- package/dist/foundations/two-factor/entities/backup-codes-generation.js.map +1 -0
- package/dist/foundations/two-factor/entities/backup-codes-generation.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/backup-codes-generation.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/backup-codes-generation.meta.js +10 -0
- package/dist/foundations/two-factor/entities/backup-codes-generation.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/passkey-authentication-options.d.ts +19 -0
- package/dist/foundations/two-factor/entities/passkey-authentication-options.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/passkey-authentication-options.js +20 -0
- package/dist/foundations/two-factor/entities/passkey-authentication-options.js.map +1 -0
- package/dist/foundations/two-factor/entities/passkey-authentication-options.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/passkey-authentication-options.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/passkey-authentication-options.meta.js +10 -0
- package/dist/foundations/two-factor/entities/passkey-authentication-options.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/passkey-registration-options.d.ts +19 -0
- package/dist/foundations/two-factor/entities/passkey-registration-options.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/passkey-registration-options.js +20 -0
- package/dist/foundations/two-factor/entities/passkey-registration-options.js.map +1 -0
- package/dist/foundations/two-factor/entities/passkey-registration-options.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/passkey-registration-options.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/passkey-registration-options.meta.js +10 -0
- package/dist/foundations/two-factor/entities/passkey-registration-options.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/passkey.d.ts +27 -0
- package/dist/foundations/two-factor/entities/passkey.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/passkey.js +30 -0
- package/dist/foundations/two-factor/entities/passkey.js.map +1 -0
- package/dist/foundations/two-factor/entities/passkey.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/passkey.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/passkey.meta.js +10 -0
- package/dist/foundations/two-factor/entities/passkey.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/pending-two-factor.d.ts +24 -0
- package/dist/foundations/two-factor/entities/pending-two-factor.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/pending-two-factor.js +27 -0
- package/dist/foundations/two-factor/entities/pending-two-factor.js.map +1 -0
- package/dist/foundations/two-factor/entities/pending-two-factor.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/pending-two-factor.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/pending-two-factor.meta.js +10 -0
- package/dist/foundations/two-factor/entities/pending-two-factor.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/totp-authenticator.d.ts +24 -0
- package/dist/foundations/two-factor/entities/totp-authenticator.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/totp-authenticator.js +27 -0
- package/dist/foundations/two-factor/entities/totp-authenticator.js.map +1 -0
- package/dist/foundations/two-factor/entities/totp-authenticator.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/totp-authenticator.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/totp-authenticator.meta.js +10 -0
- package/dist/foundations/two-factor/entities/totp-authenticator.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/totp-setup.d.ts +20 -0
- package/dist/foundations/two-factor/entities/totp-setup.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/totp-setup.js +21 -0
- package/dist/foundations/two-factor/entities/totp-setup.js.map +1 -0
- package/dist/foundations/two-factor/entities/totp-setup.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/totp-setup.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/totp-setup.meta.js +10 -0
- package/dist/foundations/two-factor/entities/totp-setup.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-challenge.d.ts +21 -0
- package/dist/foundations/two-factor/entities/two-factor-challenge.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-challenge.js +22 -0
- package/dist/foundations/two-factor/entities/two-factor-challenge.js.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-challenge.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/two-factor-challenge.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-challenge.meta.js +10 -0
- package/dist/foundations/two-factor/entities/two-factor-challenge.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-config.d.ts +21 -0
- package/dist/foundations/two-factor/entities/two-factor-config.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-config.js +23 -0
- package/dist/foundations/two-factor/entities/two-factor-config.js.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-config.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/two-factor-config.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-config.meta.js +10 -0
- package/dist/foundations/two-factor/entities/two-factor-config.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-status.d.ts +25 -0
- package/dist/foundations/two-factor/entities/two-factor-status.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-status.js +22 -0
- package/dist/foundations/two-factor/entities/two-factor-status.js.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-status.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/two-factor-status.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-status.meta.js +10 -0
- package/dist/foundations/two-factor/entities/two-factor-status.meta.js.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-verification.d.ts +19 -0
- package/dist/foundations/two-factor/entities/two-factor-verification.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-verification.js +20 -0
- package/dist/foundations/two-factor/entities/two-factor-verification.js.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-verification.meta.d.ts +3 -0
- package/dist/foundations/two-factor/entities/two-factor-verification.meta.d.ts.map +1 -0
- package/dist/foundations/two-factor/entities/two-factor-verification.meta.js +10 -0
- package/dist/foundations/two-factor/entities/two-factor-verification.meta.js.map +1 -0
- package/dist/foundations/two-factor/guards/pending-auth.guard.d.ts +35 -0
- package/dist/foundations/two-factor/guards/pending-auth.guard.d.ts.map +1 -0
- package/dist/foundations/two-factor/guards/pending-auth.guard.js +70 -0
- package/dist/foundations/two-factor/guards/pending-auth.guard.js.map +1 -0
- package/dist/foundations/two-factor/index.d.ts +47 -0
- package/dist/foundations/two-factor/index.d.ts.map +1 -0
- package/dist/foundations/two-factor/index.js +134 -0
- package/dist/foundations/two-factor/index.js.map +1 -0
- package/dist/foundations/two-factor/repositories/backup-code.repository.d.ts +34 -0
- package/dist/foundations/two-factor/repositories/backup-code.repository.d.ts.map +1 -0
- package/dist/foundations/two-factor/repositories/backup-code.repository.js +107 -0
- package/dist/foundations/two-factor/repositories/backup-code.repository.js.map +1 -0
- package/dist/foundations/two-factor/repositories/passkey.repository.d.ts +51 -0
- package/dist/foundations/two-factor/repositories/passkey.repository.d.ts.map +1 -0
- package/dist/foundations/two-factor/repositories/passkey.repository.js +159 -0
- package/dist/foundations/two-factor/repositories/passkey.repository.js.map +1 -0
- package/dist/foundations/two-factor/repositories/pending-two-factor.repository.d.ts +47 -0
- package/dist/foundations/two-factor/repositories/pending-two-factor.repository.d.ts.map +1 -0
- package/dist/foundations/two-factor/repositories/pending-two-factor.repository.js +159 -0
- package/dist/foundations/two-factor/repositories/pending-two-factor.repository.js.map +1 -0
- package/dist/foundations/two-factor/repositories/totp-authenticator.repository.d.ts +51 -0
- package/dist/foundations/two-factor/repositories/totp-authenticator.repository.d.ts.map +1 -0
- package/dist/foundations/two-factor/repositories/totp-authenticator.repository.js +156 -0
- package/dist/foundations/two-factor/repositories/totp-authenticator.repository.js.map +1 -0
- package/dist/foundations/two-factor/repositories/two-factor-config.repository.d.ts +32 -0
- package/dist/foundations/two-factor/repositories/two-factor-config.repository.d.ts.map +1 -0
- package/dist/foundations/two-factor/repositories/two-factor-config.repository.js +105 -0
- package/dist/foundations/two-factor/repositories/two-factor-config.repository.js.map +1 -0
- package/dist/foundations/two-factor/services/backup-code.service.d.ts +95 -0
- package/dist/foundations/two-factor/services/backup-code.service.d.ts.map +1 -0
- package/dist/foundations/two-factor/services/backup-code.service.js +216 -0
- package/dist/foundations/two-factor/services/backup-code.service.js.map +1 -0
- package/dist/foundations/two-factor/services/index.d.ts +6 -0
- package/dist/foundations/two-factor/services/index.d.ts.map +1 -0
- package/dist/foundations/two-factor/services/index.js +14 -0
- package/dist/foundations/two-factor/services/index.js.map +1 -0
- package/dist/foundations/two-factor/services/passkey.service.d.ts +132 -0
- package/dist/foundations/two-factor/services/passkey.service.d.ts.map +1 -0
- package/dist/foundations/two-factor/services/passkey.service.js +400 -0
- package/dist/foundations/two-factor/services/passkey.service.js.map +1 -0
- package/dist/foundations/two-factor/services/totp-encryption.service.d.ts +42 -0
- package/dist/foundations/two-factor/services/totp-encryption.service.d.ts.map +1 -0
- package/dist/foundations/two-factor/services/totp-encryption.service.js +136 -0
- package/dist/foundations/two-factor/services/totp-encryption.service.js.map +1 -0
- package/dist/foundations/two-factor/services/totp.service.d.ts +132 -0
- package/dist/foundations/two-factor/services/totp.service.d.ts.map +1 -0
- package/dist/foundations/two-factor/services/totp.service.js +324 -0
- package/dist/foundations/two-factor/services/totp.service.js.map +1 -0
- package/dist/foundations/two-factor/services/two-factor.service.d.ts +165 -0
- package/dist/foundations/two-factor/services/two-factor.service.d.ts.map +1 -0
- package/dist/foundations/two-factor/services/two-factor.service.js +468 -0
- package/dist/foundations/two-factor/services/two-factor.service.js.map +1 -0
- package/dist/foundations/two-factor/two-factor.module.d.ts +23 -0
- package/dist/foundations/two-factor/two-factor.module.d.ts.map +1 -0
- package/dist/foundations/two-factor/two-factor.module.js +132 -0
- package/dist/foundations/two-factor/two-factor.module.js.map +1 -0
- package/dist/foundations/user/repositories/user.repository.d.ts +8 -0
- package/dist/foundations/user/repositories/user.repository.d.ts.map +1 -1
- package/dist/foundations/user/repositories/user.repository.js +28 -1
- package/dist/foundations/user/repositories/user.repository.js.map +1 -1
- package/dist/foundations/waitlist/controllers/waitlist.controller.d.ts.map +1 -1
- package/dist/foundations/waitlist/controllers/waitlist.controller.js +0 -4
- package/dist/foundations/waitlist/controllers/waitlist.controller.js.map +1 -1
- package/dist/foundations/waitlist/repositories/waitlist.repository.d.ts.map +1 -1
- package/dist/foundations/waitlist/repositories/waitlist.repository.js +0 -2
- package/dist/foundations/waitlist/repositories/waitlist.repository.js.map +1 -1
- package/dist/foundations/waitlist/services/waitlist.service.d.ts +1 -0
- package/dist/foundations/waitlist/services/waitlist.service.d.ts.map +1 -1
- package/dist/foundations/waitlist/services/waitlist.service.js +6 -7
- package/dist/foundations/waitlist/services/waitlist.service.js.map +1 -1
- package/dist/scripts/generate-module/generator.js +13 -13
- package/dist/scripts/generate-module/generator.js.map +1 -1
- package/dist/scripts/generate-module/index.js +6 -6
- package/dist/scripts/generate-module/index.js.map +1 -1
- package/dist/scripts/generate-module/utils/file-writer.js +2 -2
- package/dist/scripts/generate-module/utils/file-writer.js.map +1 -1
- package/dist/scripts/generate-module/utils/module-registrar.js +7 -7
- package/dist/scripts/generate-module/utils/module-registrar.js.map +1 -1
- package/dist/tools/migrate-entity/index.js +3 -3
- package/dist/tools/migrate-entity/lib/descriptor-generator.js +6 -6
- package/dist/tools/migrate-entity/lib/entity-migrator.js +13 -13
- package/package.json +5 -1
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { JsonApiService } from "../../../core/jsonapi/services/jsonapi.service";
|
|
2
|
+
import { TotpAuthenticatorRepository } from "../repositories/totp-authenticator.repository";
|
|
3
|
+
import { TotpEncryptionService } from "./totp-encryption.service";
|
|
4
|
+
export interface TotpSetupResponse {
|
|
5
|
+
authenticatorId: string;
|
|
6
|
+
secret: string;
|
|
7
|
+
qrCodeUri: string;
|
|
8
|
+
qrCodeDataUrl: string;
|
|
9
|
+
}
|
|
10
|
+
export interface TotpAuthenticatorInfo {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
verified: boolean;
|
|
14
|
+
lastUsedAt?: Date;
|
|
15
|
+
createdAt: Date;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* TOTP Service
|
|
19
|
+
*
|
|
20
|
+
* Manages TOTP (Time-based One-Time Password) authenticators for two-factor authentication.
|
|
21
|
+
* Provides secret generation, QR code creation, code verification, and authenticator management.
|
|
22
|
+
*/
|
|
23
|
+
export declare class TotpService {
|
|
24
|
+
private readonly jsonApiService;
|
|
25
|
+
private readonly totpAuthenticatorRepository;
|
|
26
|
+
private readonly totpEncryptionService;
|
|
27
|
+
private readonly logger;
|
|
28
|
+
private readonly issuer;
|
|
29
|
+
private readonly algorithm;
|
|
30
|
+
private readonly digits;
|
|
31
|
+
private readonly period;
|
|
32
|
+
constructor(jsonApiService: JsonApiService, totpAuthenticatorRepository: TotpAuthenticatorRepository, totpEncryptionService: TotpEncryptionService);
|
|
33
|
+
/**
|
|
34
|
+
* Generate a new TOTP secret and return setup information.
|
|
35
|
+
*
|
|
36
|
+
* @param params.userId - The user's ID
|
|
37
|
+
* @param params.name - A friendly name for this authenticator (e.g., "Google Authenticator")
|
|
38
|
+
* @param params.accountName - The account name to display in authenticator apps (typically email)
|
|
39
|
+
* @returns JSON:API response with setup info (QR code, secret)
|
|
40
|
+
*/
|
|
41
|
+
generateSecret(params: {
|
|
42
|
+
userId: string;
|
|
43
|
+
name: string;
|
|
44
|
+
accountName: string;
|
|
45
|
+
}): Promise<any>;
|
|
46
|
+
/**
|
|
47
|
+
* Generate QR code URI for an existing authenticator.
|
|
48
|
+
* Only works for unverified authenticators.
|
|
49
|
+
*
|
|
50
|
+
* @param params.authenticatorId - The authenticator ID
|
|
51
|
+
* @param params.accountName - The account name for the QR code
|
|
52
|
+
* @returns QR code URI and data URL
|
|
53
|
+
*/
|
|
54
|
+
generateQRCodeUri(params: {
|
|
55
|
+
authenticatorId: string;
|
|
56
|
+
accountName: string;
|
|
57
|
+
}): Promise<{
|
|
58
|
+
qrCodeUri: string;
|
|
59
|
+
qrCodeDataUrl: string;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Verify a TOTP code against an authenticator.
|
|
63
|
+
*
|
|
64
|
+
* @param params.authenticatorId - The authenticator ID
|
|
65
|
+
* @param params.code - The 6-digit TOTP code
|
|
66
|
+
* @returns true if the code is valid
|
|
67
|
+
*/
|
|
68
|
+
verifyCode(params: {
|
|
69
|
+
authenticatorId: string;
|
|
70
|
+
code: string;
|
|
71
|
+
}): Promise<boolean>;
|
|
72
|
+
/**
|
|
73
|
+
* Verify a TOTP code for any verified authenticator belonging to a user.
|
|
74
|
+
*
|
|
75
|
+
* @param params.userId - The user's ID
|
|
76
|
+
* @param params.code - The 6-digit TOTP code
|
|
77
|
+
* @returns The authenticator ID if verification succeeds, null otherwise
|
|
78
|
+
*/
|
|
79
|
+
verifyCodeForUser(params: {
|
|
80
|
+
userId: string;
|
|
81
|
+
code: string;
|
|
82
|
+
}): Promise<string | null>;
|
|
83
|
+
/**
|
|
84
|
+
* Add (verify) an authenticator by validating a TOTP code.
|
|
85
|
+
* This marks the authenticator as verified and ready for use.
|
|
86
|
+
*
|
|
87
|
+
* @param params.authenticatorId - The authenticator ID from generateSecret
|
|
88
|
+
* @param params.code - The 6-digit TOTP code from the authenticator app
|
|
89
|
+
* @returns JSON:API response with verified authenticator, or null if verification failed
|
|
90
|
+
*/
|
|
91
|
+
addAuthenticator(params: {
|
|
92
|
+
authenticatorId: string;
|
|
93
|
+
code: string;
|
|
94
|
+
}): Promise<any>;
|
|
95
|
+
/**
|
|
96
|
+
* Remove an authenticator.
|
|
97
|
+
*
|
|
98
|
+
* @param params.authenticatorId - The authenticator ID to remove
|
|
99
|
+
*/
|
|
100
|
+
removeAuthenticator(params: {
|
|
101
|
+
authenticatorId: string;
|
|
102
|
+
}): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* List all authenticators for a user.
|
|
105
|
+
*
|
|
106
|
+
* @param params.userId - The user's ID
|
|
107
|
+
* @param params.verifiedOnly - If true, only return verified authenticators
|
|
108
|
+
* @returns JSON:API response with list of authenticators
|
|
109
|
+
*/
|
|
110
|
+
listAuthenticators(params: {
|
|
111
|
+
userId: string;
|
|
112
|
+
verifiedOnly?: boolean;
|
|
113
|
+
}): Promise<any>;
|
|
114
|
+
/**
|
|
115
|
+
* Check if a user has any verified TOTP authenticators.
|
|
116
|
+
*
|
|
117
|
+
* @param params.userId - The user's ID
|
|
118
|
+
* @returns true if the user has at least one verified authenticator
|
|
119
|
+
*/
|
|
120
|
+
hasVerifiedAuthenticator(params: {
|
|
121
|
+
userId: string;
|
|
122
|
+
}): Promise<boolean>;
|
|
123
|
+
/**
|
|
124
|
+
* Delete an unverified authenticator (cleanup for abandoned setup).
|
|
125
|
+
*
|
|
126
|
+
* @param params.authenticatorId - The authenticator ID
|
|
127
|
+
*/
|
|
128
|
+
deleteUnverifiedAuthenticator(params: {
|
|
129
|
+
authenticatorId: string;
|
|
130
|
+
}): Promise<void>;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=totp.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1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&& this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
var TotpService_1;
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.TotpService = void 0;
|
|
47
|
+
const common_1 = require("@nestjs/common");
|
|
48
|
+
const crypto = __importStar(require("crypto"));
|
|
49
|
+
const OTPAuth = __importStar(require("otpauth"));
|
|
50
|
+
const QRCode = __importStar(require("qrcode"));
|
|
51
|
+
const jsonapi_service_1 = require("../../../core/jsonapi/services/jsonapi.service");
|
|
52
|
+
const totp_authenticator_1 = require("../entities/totp-authenticator");
|
|
53
|
+
const totp_setup_1 = require("../entities/totp-setup");
|
|
54
|
+
const totp_authenticator_repository_1 = require("../repositories/totp-authenticator.repository");
|
|
55
|
+
const totp_encryption_service_1 = require("./totp-encryption.service");
|
|
56
|
+
/**
|
|
57
|
+
* TOTP Service
|
|
58
|
+
*
|
|
59
|
+
* Manages TOTP (Time-based One-Time Password) authenticators for two-factor authentication.
|
|
60
|
+
* Provides secret generation, QR code creation, code verification, and authenticator management.
|
|
61
|
+
*/
|
|
62
|
+
let TotpService = TotpService_1 = class TotpService {
|
|
63
|
+
constructor(jsonApiService, totpAuthenticatorRepository, totpEncryptionService) {
|
|
64
|
+
this.jsonApiService = jsonApiService;
|
|
65
|
+
this.totpAuthenticatorRepository = totpAuthenticatorRepository;
|
|
66
|
+
this.totpEncryptionService = totpEncryptionService;
|
|
67
|
+
this.logger = new common_1.Logger(TotpService_1.name);
|
|
68
|
+
this.issuer = "Only35";
|
|
69
|
+
this.algorithm = "SHA1";
|
|
70
|
+
this.digits = 6;
|
|
71
|
+
this.period = 30; // seconds
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Generate a new TOTP secret and return setup information.
|
|
75
|
+
*
|
|
76
|
+
* @param params.userId - The user's ID
|
|
77
|
+
* @param params.name - A friendly name for this authenticator (e.g., "Google Authenticator")
|
|
78
|
+
* @param params.accountName - The account name to display in authenticator apps (typically email)
|
|
79
|
+
* @returns JSON:API response with setup info (QR code, secret)
|
|
80
|
+
*/
|
|
81
|
+
async generateSecret(params) {
|
|
82
|
+
// Generate a new TOTP secret
|
|
83
|
+
const secret = new OTPAuth.Secret({ size: 20 });
|
|
84
|
+
// Create TOTP instance for URI generation
|
|
85
|
+
const totp = new OTPAuth.TOTP({
|
|
86
|
+
issuer: this.issuer,
|
|
87
|
+
label: params.accountName,
|
|
88
|
+
algorithm: this.algorithm,
|
|
89
|
+
digits: this.digits,
|
|
90
|
+
period: this.period,
|
|
91
|
+
secret: secret,
|
|
92
|
+
});
|
|
93
|
+
// Get the otpauth:// URI for QR code
|
|
94
|
+
const qrCodeUri = totp.toString();
|
|
95
|
+
// Generate QR code as data URL
|
|
96
|
+
const qrCodeDataUrl = await QRCode.toDataURL(qrCodeUri);
|
|
97
|
+
// Encrypt the secret before storing
|
|
98
|
+
const encryptedSecret = this.totpEncryptionService.encrypt(secret.base32);
|
|
99
|
+
// Create the authenticator in pending (unverified) state
|
|
100
|
+
const authenticatorId = crypto.randomUUID();
|
|
101
|
+
await this.totpAuthenticatorRepository.createForUser({
|
|
102
|
+
authenticatorId,
|
|
103
|
+
userId: params.userId,
|
|
104
|
+
name: params.name,
|
|
105
|
+
secret: encryptedSecret,
|
|
106
|
+
verified: false,
|
|
107
|
+
});
|
|
108
|
+
return this.jsonApiService.buildSingle(totp_setup_1.TotpSetupDescriptor.model, {
|
|
109
|
+
id: authenticatorId,
|
|
110
|
+
secret: secret.base32,
|
|
111
|
+
qrCodeUri,
|
|
112
|
+
qrCodeDataUrl,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Generate QR code URI for an existing authenticator.
|
|
117
|
+
* Only works for unverified authenticators.
|
|
118
|
+
*
|
|
119
|
+
* @param params.authenticatorId - The authenticator ID
|
|
120
|
+
* @param params.accountName - The account name for the QR code
|
|
121
|
+
* @returns QR code URI and data URL
|
|
122
|
+
*/
|
|
123
|
+
async generateQRCodeUri(params) {
|
|
124
|
+
const authenticator = await this.totpAuthenticatorRepository.findByIdWithSecret({
|
|
125
|
+
authenticatorId: params.authenticatorId,
|
|
126
|
+
});
|
|
127
|
+
if (!authenticator) {
|
|
128
|
+
throw new common_1.NotFoundException("Authenticator not found");
|
|
129
|
+
}
|
|
130
|
+
if (authenticator.verified) {
|
|
131
|
+
throw new common_1.BadRequestException("Cannot regenerate QR code for verified authenticator");
|
|
132
|
+
}
|
|
133
|
+
// Decrypt the secret
|
|
134
|
+
const decryptedSecret = this.totpEncryptionService.decrypt(authenticator.secret);
|
|
135
|
+
// Create TOTP instance for URI generation
|
|
136
|
+
const totp = new OTPAuth.TOTP({
|
|
137
|
+
issuer: this.issuer,
|
|
138
|
+
label: params.accountName,
|
|
139
|
+
algorithm: this.algorithm,
|
|
140
|
+
digits: this.digits,
|
|
141
|
+
period: this.period,
|
|
142
|
+
secret: OTPAuth.Secret.fromBase32(decryptedSecret),
|
|
143
|
+
});
|
|
144
|
+
const qrCodeUri = totp.toString();
|
|
145
|
+
const qrCodeDataUrl = await QRCode.toDataURL(qrCodeUri);
|
|
146
|
+
return { qrCodeUri, qrCodeDataUrl };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Verify a TOTP code against an authenticator.
|
|
150
|
+
*
|
|
151
|
+
* @param params.authenticatorId - The authenticator ID
|
|
152
|
+
* @param params.code - The 6-digit TOTP code
|
|
153
|
+
* @returns true if the code is valid
|
|
154
|
+
*/
|
|
155
|
+
async verifyCode(params) {
|
|
156
|
+
const authenticator = await this.totpAuthenticatorRepository.findByIdWithSecret({
|
|
157
|
+
authenticatorId: params.authenticatorId,
|
|
158
|
+
});
|
|
159
|
+
if (!authenticator) {
|
|
160
|
+
throw new common_1.NotFoundException("Authenticator not found");
|
|
161
|
+
}
|
|
162
|
+
// Decrypt the secret
|
|
163
|
+
const decryptedSecret = this.totpEncryptionService.decrypt(authenticator.secret);
|
|
164
|
+
// Create TOTP instance
|
|
165
|
+
const totp = new OTPAuth.TOTP({
|
|
166
|
+
issuer: this.issuer,
|
|
167
|
+
algorithm: this.algorithm,
|
|
168
|
+
digits: this.digits,
|
|
169
|
+
period: this.period,
|
|
170
|
+
secret: OTPAuth.Secret.fromBase32(decryptedSecret),
|
|
171
|
+
});
|
|
172
|
+
// Validate with 1 period window (allows for time drift)
|
|
173
|
+
const delta = totp.validate({ token: params.code, window: 1 });
|
|
174
|
+
if (delta !== null) {
|
|
175
|
+
// Update last used time
|
|
176
|
+
await this.totpAuthenticatorRepository.updateAuthenticator({
|
|
177
|
+
authenticatorId: params.authenticatorId,
|
|
178
|
+
lastUsedAt: new Date(),
|
|
179
|
+
});
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Verify a TOTP code for any verified authenticator belonging to a user.
|
|
186
|
+
*
|
|
187
|
+
* @param params.userId - The user's ID
|
|
188
|
+
* @param params.code - The 6-digit TOTP code
|
|
189
|
+
* @returns The authenticator ID if verification succeeds, null otherwise
|
|
190
|
+
*/
|
|
191
|
+
async verifyCodeForUser(params) {
|
|
192
|
+
const authenticators = await this.totpAuthenticatorRepository.findAllByUserIdWithSecrets({
|
|
193
|
+
userId: params.userId,
|
|
194
|
+
});
|
|
195
|
+
for (const authenticator of authenticators) {
|
|
196
|
+
// Skip unverified authenticators
|
|
197
|
+
if (!authenticator.verified) {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
// Decrypt the secret
|
|
201
|
+
const decryptedSecret = this.totpEncryptionService.decrypt(authenticator.secret);
|
|
202
|
+
// Create TOTP instance
|
|
203
|
+
const totp = new OTPAuth.TOTP({
|
|
204
|
+
issuer: this.issuer,
|
|
205
|
+
algorithm: this.algorithm,
|
|
206
|
+
digits: this.digits,
|
|
207
|
+
period: this.period,
|
|
208
|
+
secret: OTPAuth.Secret.fromBase32(decryptedSecret),
|
|
209
|
+
});
|
|
210
|
+
// Validate with 1 period window
|
|
211
|
+
const delta = totp.validate({ token: params.code, window: 1 });
|
|
212
|
+
if (delta !== null) {
|
|
213
|
+
// Update last used time
|
|
214
|
+
await this.totpAuthenticatorRepository.updateAuthenticator({
|
|
215
|
+
authenticatorId: authenticator.id,
|
|
216
|
+
lastUsedAt: new Date(),
|
|
217
|
+
});
|
|
218
|
+
return authenticator.id;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Add (verify) an authenticator by validating a TOTP code.
|
|
225
|
+
* This marks the authenticator as verified and ready for use.
|
|
226
|
+
*
|
|
227
|
+
* @param params.authenticatorId - The authenticator ID from generateSecret
|
|
228
|
+
* @param params.code - The 6-digit TOTP code from the authenticator app
|
|
229
|
+
* @returns JSON:API response with verified authenticator, or null if verification failed
|
|
230
|
+
*/
|
|
231
|
+
async addAuthenticator(params) {
|
|
232
|
+
const authenticator = await this.totpAuthenticatorRepository.findByIdWithSecret({
|
|
233
|
+
authenticatorId: params.authenticatorId,
|
|
234
|
+
});
|
|
235
|
+
if (!authenticator) {
|
|
236
|
+
throw new common_1.NotFoundException("Authenticator not found");
|
|
237
|
+
}
|
|
238
|
+
if (authenticator.verified) {
|
|
239
|
+
throw new common_1.BadRequestException("Authenticator is already verified");
|
|
240
|
+
}
|
|
241
|
+
// Verify the code
|
|
242
|
+
const isValid = await this.verifyCode({
|
|
243
|
+
authenticatorId: params.authenticatorId,
|
|
244
|
+
code: params.code,
|
|
245
|
+
});
|
|
246
|
+
if (!isValid) {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
// Mark as verified and get updated authenticator
|
|
250
|
+
const verifiedAuthenticator = await this.totpAuthenticatorRepository.updateAuthenticator({
|
|
251
|
+
authenticatorId: params.authenticatorId,
|
|
252
|
+
verified: true,
|
|
253
|
+
});
|
|
254
|
+
return this.jsonApiService.buildSingle(totp_authenticator_1.TotpAuthenticatorDescriptor.model, verifiedAuthenticator);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Remove an authenticator.
|
|
258
|
+
*
|
|
259
|
+
* @param params.authenticatorId - The authenticator ID to remove
|
|
260
|
+
*/
|
|
261
|
+
async removeAuthenticator(params) {
|
|
262
|
+
const authenticator = await this.totpAuthenticatorRepository.findByIdForUser({
|
|
263
|
+
authenticatorId: params.authenticatorId,
|
|
264
|
+
});
|
|
265
|
+
if (!authenticator) {
|
|
266
|
+
throw new common_1.NotFoundException("Authenticator not found");
|
|
267
|
+
}
|
|
268
|
+
await this.totpAuthenticatorRepository.deleteAuthenticator({
|
|
269
|
+
authenticatorId: params.authenticatorId,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* List all authenticators for a user.
|
|
274
|
+
*
|
|
275
|
+
* @param params.userId - The user's ID
|
|
276
|
+
* @param params.verifiedOnly - If true, only return verified authenticators
|
|
277
|
+
* @returns JSON:API response with list of authenticators
|
|
278
|
+
*/
|
|
279
|
+
async listAuthenticators(params) {
|
|
280
|
+
const authenticators = params.verifiedOnly
|
|
281
|
+
? await this.totpAuthenticatorRepository.findVerifiedByUserId({ userId: params.userId })
|
|
282
|
+
: await this.totpAuthenticatorRepository.findAllByUserIdWithSecrets({ userId: params.userId });
|
|
283
|
+
return this.jsonApiService.buildList(totp_authenticator_1.TotpAuthenticatorDescriptor.model, authenticators);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Check if a user has any verified TOTP authenticators.
|
|
287
|
+
*
|
|
288
|
+
* @param params.userId - The user's ID
|
|
289
|
+
* @returns true if the user has at least one verified authenticator
|
|
290
|
+
*/
|
|
291
|
+
async hasVerifiedAuthenticator(params) {
|
|
292
|
+
const count = await this.totpAuthenticatorRepository.countVerifiedByUserId({
|
|
293
|
+
userId: params.userId,
|
|
294
|
+
});
|
|
295
|
+
return count > 0;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Delete an unverified authenticator (cleanup for abandoned setup).
|
|
299
|
+
*
|
|
300
|
+
* @param params.authenticatorId - The authenticator ID
|
|
301
|
+
*/
|
|
302
|
+
async deleteUnverifiedAuthenticator(params) {
|
|
303
|
+
const authenticator = await this.totpAuthenticatorRepository.findByIdForUser({
|
|
304
|
+
authenticatorId: params.authenticatorId,
|
|
305
|
+
});
|
|
306
|
+
if (!authenticator) {
|
|
307
|
+
throw new common_1.NotFoundException("Authenticator not found");
|
|
308
|
+
}
|
|
309
|
+
if (authenticator.verified) {
|
|
310
|
+
throw new common_1.BadRequestException("Cannot delete a verified authenticator using this method");
|
|
311
|
+
}
|
|
312
|
+
await this.totpAuthenticatorRepository.deleteAuthenticator({
|
|
313
|
+
authenticatorId: params.authenticatorId,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
exports.TotpService = TotpService;
|
|
318
|
+
exports.TotpService = TotpService = TotpService_1 = __decorate([
|
|
319
|
+
(0, common_1.Injectable)(),
|
|
320
|
+
__metadata("design:paramtypes", [jsonapi_service_1.JsonApiService,
|
|
321
|
+
totp_authenticator_repository_1.TotpAuthenticatorRepository,
|
|
322
|
+
totp_encryption_service_1.TotpEncryptionService])
|
|
323
|
+
], TotpService);
|
|
324
|
+
//# sourceMappingURL=totp.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"totp.service.js","sourceRoot":"","sources":["../../../../src/foundations/two-factor/services/totp.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4F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BAA2B,CAAC,mBAAmB,CAAC;YACzD,eAAe,EAAE,MAAM,CAAC,eAAe;SACxC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AA/SY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;qCASwB,gCAAc;QACD,2DAA2B;QACjC,+CAAqB;GAVpD,WAAW,CA+SvB"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { JsonApiService } from "../../../core/jsonapi/services/jsonapi.service";
|
|
2
|
+
import { PendingTwoFactor } from "../entities/pending-two-factor";
|
|
3
|
+
import { TwoFactorConfig } from "../entities/two-factor-config";
|
|
4
|
+
import { PendingTwoFactorRepository } from "../repositories/pending-two-factor.repository";
|
|
5
|
+
import { TwoFactorConfigRepository } from "../repositories/two-factor-config.repository";
|
|
6
|
+
import { BackupCodeService } from "./backup-code.service";
|
|
7
|
+
import { PasskeyService } from "./passkey.service";
|
|
8
|
+
import { TotpService } from "./totp.service";
|
|
9
|
+
export type TwoFactorMethod = "totp" | "passkey" | "backup";
|
|
10
|
+
export interface TwoFactorStatus {
|
|
11
|
+
isEnabled: boolean;
|
|
12
|
+
preferredMethod: TwoFactorMethod;
|
|
13
|
+
methods: {
|
|
14
|
+
totp: boolean;
|
|
15
|
+
passkey: boolean;
|
|
16
|
+
backup: boolean;
|
|
17
|
+
};
|
|
18
|
+
backupCodesCount: number;
|
|
19
|
+
}
|
|
20
|
+
export interface PendingSession {
|
|
21
|
+
pendingId: string;
|
|
22
|
+
expiration: Date;
|
|
23
|
+
}
|
|
24
|
+
export interface VerificationResult {
|
|
25
|
+
success: boolean;
|
|
26
|
+
userId?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Two-Factor Orchestration Service
|
|
30
|
+
*
|
|
31
|
+
* Coordinates all 2FA functionality including status management, method verification,
|
|
32
|
+
* and pending session handling. This service is the main entry point for 2FA operations
|
|
33
|
+
* and delegates to specialized services (TOTP, Passkey, BackupCode) for specific tasks.
|
|
34
|
+
*/
|
|
35
|
+
export declare class TwoFactorService {
|
|
36
|
+
private readonly jsonApiService;
|
|
37
|
+
private readonly twoFactorConfigRepository;
|
|
38
|
+
private readonly pendingTwoFactorRepository;
|
|
39
|
+
private readonly totpService;
|
|
40
|
+
private readonly passkeyService;
|
|
41
|
+
private readonly backupCodeService;
|
|
42
|
+
private readonly pendingTtlSeconds;
|
|
43
|
+
private readonly maxTotpAttempts;
|
|
44
|
+
private readonly maxPasskeyAttempts;
|
|
45
|
+
private readonly maxBackupAttempts;
|
|
46
|
+
constructor(jsonApiService: JsonApiService, twoFactorConfigRepository: TwoFactorConfigRepository, pendingTwoFactorRepository: PendingTwoFactorRepository, totpService: TotpService, passkeyService: PasskeyService, backupCodeService: BackupCodeService);
|
|
47
|
+
/**
|
|
48
|
+
* Get the 2FA configuration for a user.
|
|
49
|
+
*
|
|
50
|
+
* @param userId - The user's ID
|
|
51
|
+
* @returns The user's TwoFactorConfig, or null if not configured
|
|
52
|
+
*/
|
|
53
|
+
getConfig(userId: string): Promise<TwoFactorConfig | null>;
|
|
54
|
+
/**
|
|
55
|
+
* Get the full 2FA status for a user including available methods.
|
|
56
|
+
*
|
|
57
|
+
* @param userId - The user's ID
|
|
58
|
+
* @returns JSON:API response with 2FA status
|
|
59
|
+
*/
|
|
60
|
+
getStatus(userId: string): Promise<any>;
|
|
61
|
+
/**
|
|
62
|
+
* Enable 2FA for a user.
|
|
63
|
+
* Requires at least one 2FA method to be configured.
|
|
64
|
+
*
|
|
65
|
+
* @param userId - The user's ID
|
|
66
|
+
* @param preferredMethod - The preferred 2FA method (default: 'totp')
|
|
67
|
+
* @throws BadRequestException if no 2FA methods are configured
|
|
68
|
+
* @returns JSON:API response with the 2FA config
|
|
69
|
+
*/
|
|
70
|
+
enable(userId: string, preferredMethod?: TwoFactorMethod): Promise<any>;
|
|
71
|
+
/**
|
|
72
|
+
* Disable 2FA for a user.
|
|
73
|
+
*
|
|
74
|
+
* @param userId - The user's ID
|
|
75
|
+
*/
|
|
76
|
+
disable(userId: string): Promise<TwoFactorConfig | null>;
|
|
77
|
+
/**
|
|
78
|
+
* Set the preferred 2FA method for a user.
|
|
79
|
+
*
|
|
80
|
+
* @param userId - The user's ID
|
|
81
|
+
* @param method - The preferred method
|
|
82
|
+
* @throws BadRequestException if the method is not available
|
|
83
|
+
*/
|
|
84
|
+
setPreferredMethod(userId: string, method: TwoFactorMethod): Promise<TwoFactorConfig>;
|
|
85
|
+
/**
|
|
86
|
+
* Create a pending 2FA session after successful password validation.
|
|
87
|
+
* This is called by the auth service when a user with 2FA enabled logs in.
|
|
88
|
+
*
|
|
89
|
+
* @param userId - The user's ID
|
|
90
|
+
* @returns The pending session info
|
|
91
|
+
*/
|
|
92
|
+
createPendingSession(userId: string): Promise<PendingSession>;
|
|
93
|
+
/**
|
|
94
|
+
* Get available 2FA methods for a user during login.
|
|
95
|
+
*
|
|
96
|
+
* @param userId - The user's ID
|
|
97
|
+
* @returns Array of available method names
|
|
98
|
+
*/
|
|
99
|
+
getAvailableMethods(userId: string): Promise<TwoFactorMethod[]>;
|
|
100
|
+
/**
|
|
101
|
+
* Verify a TOTP code for 2FA login.
|
|
102
|
+
*
|
|
103
|
+
* @param pendingId - The pending session ID from createPendingSession
|
|
104
|
+
* @param code - The 6-digit TOTP code
|
|
105
|
+
* @returns JSON:API response with verification result
|
|
106
|
+
*/
|
|
107
|
+
verifyTotp(pendingId: string, code: string): Promise<any>;
|
|
108
|
+
/**
|
|
109
|
+
* Verify a passkey for 2FA login.
|
|
110
|
+
*
|
|
111
|
+
* @param pendingId - The pending session ID
|
|
112
|
+
* @param response - The WebAuthn authentication response
|
|
113
|
+
* @returns JSON:API response with verification result
|
|
114
|
+
*/
|
|
115
|
+
verifyPasskey(pendingId: string, response: Parameters<typeof PasskeyService.prototype.verifyAuthentication>[0]["response"]): Promise<any>;
|
|
116
|
+
/**
|
|
117
|
+
* Verify a backup code for 2FA login.
|
|
118
|
+
*
|
|
119
|
+
* @param pendingId - The pending session ID
|
|
120
|
+
* @param code - The backup code
|
|
121
|
+
* @returns JSON:API response with verification result
|
|
122
|
+
*/
|
|
123
|
+
verifyBackupCode(pendingId: string, code: string): Promise<any>;
|
|
124
|
+
/**
|
|
125
|
+
* Get pending session info by ID.
|
|
126
|
+
*
|
|
127
|
+
* @param pendingId - The pending session ID
|
|
128
|
+
* @returns The pending session data if found
|
|
129
|
+
*/
|
|
130
|
+
getPendingSession(pendingId: string): Promise<{
|
|
131
|
+
pending: PendingTwoFactor;
|
|
132
|
+
userId: string;
|
|
133
|
+
} | null>;
|
|
134
|
+
/**
|
|
135
|
+
* Delete a pending session.
|
|
136
|
+
*
|
|
137
|
+
* @param pendingId - The pending session ID
|
|
138
|
+
*/
|
|
139
|
+
deletePendingSession(pendingId: string): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Update backup codes count in the config.
|
|
142
|
+
* Called after generating or using backup codes.
|
|
143
|
+
*
|
|
144
|
+
* @param userId - The user's ID
|
|
145
|
+
*/
|
|
146
|
+
updateBackupCodesCount(userId: string): Promise<void>;
|
|
147
|
+
/**
|
|
148
|
+
* Check if 2FA should be automatically disabled due to no methods remaining.
|
|
149
|
+
* Called when removing the last TOTP authenticator or passkey.
|
|
150
|
+
*
|
|
151
|
+
* @param userId - The user's ID
|
|
152
|
+
* @returns true if 2FA was disabled
|
|
153
|
+
*/
|
|
154
|
+
checkAndDisableIfNoMethods(userId: string): Promise<boolean>;
|
|
155
|
+
/**
|
|
156
|
+
* Validate a pending session and return its data.
|
|
157
|
+
*
|
|
158
|
+
* @param pendingId - The pending session ID
|
|
159
|
+
* @param expectedType - The expected challenge type
|
|
160
|
+
* @throws NotFoundException if session not found
|
|
161
|
+
* @throws BadRequestException if session expired or wrong type
|
|
162
|
+
*/
|
|
163
|
+
private validateAndGetPending;
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=two-factor.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"two-factor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