@jmlq/auth 0.0.1-alpha.1
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/README.md +306 -0
- package/dist/examples/bcrypt-password-hasher.example.d.ts +3 -0
- package/dist/examples/bcrypt-password-hasher.example.js +78 -0
- package/dist/examples/entity-object.example.d.ts +39 -0
- package/dist/examples/entity-object.example.js +411 -0
- package/dist/examples/factory-auth-service-example.d.ts +3 -0
- package/dist/examples/factory-auth-service-example.js +84 -0
- package/dist/examples/index.example.d.ts +12 -0
- package/dist/examples/index.example.js +171 -0
- package/dist/examples/jwt-algoritm.example.d.ts +47 -0
- package/dist/examples/jwt-algoritm.example.js +447 -0
- package/dist/examples/jwt-token-generator.example.d.ts +6 -0
- package/dist/examples/jwt-token-generator.example.js +49 -0
- package/dist/examples/jwt-verifier.example.d.ts +3 -0
- package/dist/examples/jwt-verifier.example.js +80 -0
- package/dist/examples/password-policy.example.d.ts +7 -0
- package/dist/examples/password-policy.example.js +57 -0
- package/dist/examples/service-jwt-token.example.d.ts +3 -0
- package/dist/examples/service-jwt-token.example.js +154 -0
- package/dist/examples/service-token-session.example.d.ts +3 -0
- package/dist/examples/service-token-session.example.js +139 -0
- package/dist/examples/use-case-login-with-password.example.d.ts +6 -0
- package/dist/examples/use-case-login-with-password.example.js +105 -0
- package/dist/examples/use-case-logout.example.d.ts +7 -0
- package/dist/examples/use-case-logout.example.js +134 -0
- package/dist/examples/use-case-refresh-token.example.d.ts +11 -0
- package/dist/examples/use-case-refresh-token.example.js +164 -0
- package/dist/examples/use-case-register-user.example.d.ts +9 -0
- package/dist/examples/use-case-register-user.example.js +110 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/src/application/dtos/index.d.ts +4 -0
- package/dist/src/application/dtos/index.js +20 -0
- package/dist/src/application/dtos/login.dto.d.ts +9 -0
- package/dist/src/application/dtos/login.dto.js +2 -0
- package/dist/src/application/dtos/logout.dto.d.ts +7 -0
- package/dist/src/application/dtos/logout.dto.js +2 -0
- package/dist/src/application/dtos/refresh-token.dto.d.ts +7 -0
- package/dist/src/application/dtos/refresh-token.dto.js +2 -0
- package/dist/src/application/dtos/register-user.dto.d.ts +16 -0
- package/dist/src/application/dtos/register-user.dto.js +2 -0
- package/dist/src/application/factories/auth-service.factory.d.ts +5 -0
- package/dist/src/application/factories/auth-service.factory.js +51 -0
- package/dist/src/application/factories/index.d.ts +1 -0
- package/dist/src/application/factories/index.js +17 -0
- package/dist/src/application/index.d.ts +3 -0
- package/dist/src/application/index.js +19 -0
- package/dist/src/application/use-cases/index.d.ts +4 -0
- package/dist/src/application/use-cases/index.js +20 -0
- package/dist/src/application/use-cases/login-with-password.use-case.d.ts +9 -0
- package/dist/src/application/use-cases/login-with-password.use-case.js +36 -0
- package/dist/src/application/use-cases/logout.use-case.d.ts +7 -0
- package/dist/src/application/use-cases/logout.use-case.js +22 -0
- package/dist/src/application/use-cases/refresh-token.use-case.d.ts +7 -0
- package/dist/src/application/use-cases/refresh-token.use-case.js +23 -0
- package/dist/src/application/use-cases/register-user.use-case.d.ts +10 -0
- package/dist/src/application/use-cases/register-user.use-case.js +37 -0
- package/dist/src/domain/entities/credential.entity.d.ts +78 -0
- package/dist/src/domain/entities/credential.entity.js +92 -0
- package/dist/src/domain/entities/index.d.ts +2 -0
- package/dist/src/domain/entities/index.js +18 -0
- package/dist/src/domain/entities/user.entity.d.ts +97 -0
- package/dist/src/domain/entities/user.entity.js +116 -0
- package/dist/src/domain/errors/auth-domain-error.d.ts +82 -0
- package/dist/src/domain/errors/auth-domain-error.js +112 -0
- package/dist/src/domain/errors/auth.errors.d.ts +56 -0
- package/dist/src/domain/errors/auth.errors.js +76 -0
- package/dist/src/domain/errors/identity.errors.d.ts +34 -0
- package/dist/src/domain/errors/identity.errors.js +82 -0
- package/dist/src/domain/errors/index.d.ts +2 -0
- package/dist/src/domain/errors/index.js +18 -0
- package/dist/src/domain/index.d.ts +6 -0
- package/dist/src/domain/index.js +22 -0
- package/dist/src/domain/object-values/email.d.ts +37 -0
- package/dist/src/domain/object-values/email.js +56 -0
- package/dist/src/domain/object-values/hashed-password.d.ts +28 -0
- package/dist/src/domain/object-values/hashed-password.js +73 -0
- package/dist/src/domain/object-values/id.d.ts +8 -0
- package/dist/src/domain/object-values/id.js +28 -0
- package/dist/src/domain/object-values/index.d.ts +5 -0
- package/dist/src/domain/object-values/index.js +13 -0
- package/dist/src/domain/object-values/permission.d.ts +15 -0
- package/dist/src/domain/object-values/permission.js +57 -0
- package/dist/src/domain/object-values/role.d.ts +25 -0
- package/dist/src/domain/object-values/role.js +108 -0
- package/dist/src/domain/ports/auth/password-hasher.d.ts +7 -0
- package/dist/src/domain/ports/auth/password-hasher.js +2 -0
- package/dist/src/domain/ports/auth/password-policy-config.port.d.ts +0 -0
- package/dist/src/domain/ports/auth/password-policy-config.port.js +10 -0
- package/dist/src/domain/ports/auth/password-policy.port.d.ts +10 -0
- package/dist/src/domain/ports/auth/password-policy.port.js +2 -0
- package/dist/src/domain/ports/config/auth-config.port.d.ts +19 -0
- package/dist/src/domain/ports/config/auth-config.port.js +3 -0
- package/dist/src/domain/ports/index.d.ts +9 -0
- package/dist/src/domain/ports/index.js +25 -0
- package/dist/src/domain/ports/jwt/factory/signature-strategy-factory.port.d.ts +14 -0
- package/dist/src/domain/ports/jwt/factory/signature-strategy-factory.port.js +2 -0
- package/dist/src/domain/ports/jwt/payload/jwt-payload.port.d.ts +12 -0
- package/dist/src/domain/ports/jwt/payload/jwt-payload.port.js +2 -0
- package/dist/src/domain/ports/jwt/signature-strategy-factory.port.d.ts +14 -0
- package/dist/src/domain/ports/jwt/signature-strategy-factory.port.js +2 -0
- package/dist/src/domain/ports/jwt/signature-strategy.d.ts +30 -0
- package/dist/src/domain/ports/jwt/signature-strategy.js +4 -0
- package/dist/src/domain/ports/jwt/signature-strategy.port.d.ts +31 -0
- package/dist/src/domain/ports/jwt/signature-strategy.port.js +4 -0
- package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.d.ts +31 -0
- package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.js +4 -0
- package/dist/src/domain/ports/repository/credential.repository.d.ts +10 -0
- package/dist/src/domain/ports/repository/credential.repository.js +2 -0
- package/dist/src/domain/ports/repository/index.d.ts +2 -0
- package/dist/src/domain/ports/repository/index.js +18 -0
- package/dist/src/domain/ports/repository/user.repository.d.ts +13 -0
- package/dist/src/domain/ports/repository/user.repository.js +2 -0
- package/dist/src/domain/ports/token/token-session.port.d.ts +7 -0
- package/dist/src/domain/ports/token/token-session.port.js +2 -0
- package/dist/src/domain/ports/token/token.service.port.d.ts +9 -0
- package/dist/src/domain/ports/token/token.service.port.js +2 -0
- package/dist/src/domain/props/create-payload-props.port.d.ts +0 -0
- package/dist/src/domain/props/create-payload-props.port.js +8 -0
- package/dist/src/domain/props/entities/credential.props.d.ts +8 -0
- package/dist/src/domain/props/entities/credential.props.js +2 -0
- package/dist/src/domain/props/entities/index.d.ts +2 -0
- package/dist/src/domain/props/entities/index.js +18 -0
- package/dist/src/domain/props/entities/user.props.d.ts +10 -0
- package/dist/src/domain/props/entities/user.props.js +2 -0
- package/dist/src/domain/props/index.d.ts +2 -0
- package/dist/src/domain/props/index.js +18 -0
- package/dist/src/domain/props/jwt/create-payload.props.d.ts +9 -0
- package/dist/src/domain/props/jwt/create-payload.props.js +2 -0
- package/dist/src/domain/props/jwt/generate-access-token.props.d.ts +8 -0
- package/dist/src/domain/props/jwt/generate-access-token.props.js +2 -0
- package/dist/src/domain/props/jwt/generate-refresh-token.props.d.ts +8 -0
- package/dist/src/domain/props/jwt/generate-refresh-token.props.js +2 -0
- package/dist/src/domain/props/jwt/generate-token.props.d.ts +10 -0
- package/dist/src/domain/props/jwt/generate-token.props.js +2 -0
- package/dist/src/domain/props/jwt/index.d.ts +5 -0
- package/dist/src/domain/props/jwt/index.js +21 -0
- package/dist/src/domain/props/jwt/jwt-subject.d.ts +7 -0
- package/dist/src/domain/props/jwt/jwt-subject.js +2 -0
- package/dist/src/domain/props/jwt/jwt-user.d.ts +7 -0
- package/dist/src/domain/props/jwt/jwt-user.js +2 -0
- package/dist/src/domain/props/services/generate-access-token.props.d.ts +8 -0
- package/dist/src/domain/props/services/generate-access-token.props.js +2 -0
- package/dist/src/domain/props/services/generate-refresh-token.props.d.ts +8 -0
- package/dist/src/domain/props/services/generate-refresh-token.props.js +2 -0
- package/dist/src/domain/props/services/index.d.ts +2 -0
- package/dist/src/domain/props/services/index.js +18 -0
- package/dist/src/domain/services/index.d.ts +1 -0
- package/dist/src/domain/services/index.js +17 -0
- package/dist/src/domain/services/password-policy.service.d.ts +8 -0
- package/dist/src/domain/services/password-policy.service.js +29 -0
- package/dist/src/domain/services/token.service.port.d.ts +9 -0
- package/dist/src/domain/services/token.service.port.js +2 -0
- package/dist/src/index.d.ts +78 -0
- package/dist/src/index.js +94 -0
- package/dist/src/infrastructure/index.d.ts +5 -0
- package/dist/src/infrastructure/index.js +21 -0
- package/dist/src/infrastructure/jwt/factory/index.d.ts +1 -0
- package/dist/src/infrastructure/jwt/factory/index.js +17 -0
- package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.d.ts +21 -0
- package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.js +61 -0
- package/dist/src/infrastructure/jwt/index.d.ts +3 -0
- package/dist/src/infrastructure/jwt/index.js +19 -0
- package/dist/src/infrastructure/jwt/signature-strategy.factory.d.ts +21 -0
- package/dist/src/infrastructure/jwt/signature-strategy.factory.js +61 -0
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.d.ts +47 -0
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.js +124 -0
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.d.ts +47 -0
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.js +124 -0
- package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.d.ts +54 -0
- package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.js +129 -0
- package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.d.ts +54 -0
- package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.js +129 -0
- package/dist/src/infrastructure/jwt/strategies/index.d.ts +3 -0
- package/dist/src/infrastructure/jwt/strategies/index.js +19 -0
- package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.d.ts +47 -0
- package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.js +124 -0
- package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.d.ts +47 -0
- package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.js +124 -0
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.d.ts +57 -0
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.js +123 -0
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.d.ts +59 -0
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.js +100 -0
- package/dist/src/infrastructure/jwt/token/index.d.ts +5 -0
- package/dist/src/infrastructure/jwt/token/index.js +21 -0
- package/dist/src/infrastructure/jwt/token/jwt-signer.d.ts +33 -0
- package/dist/src/infrastructure/jwt/token/jwt-signer.js +46 -0
- package/dist/src/infrastructure/jwt/token/jwt-token-parser.d.ts +29 -0
- package/dist/src/infrastructure/jwt/token/jwt-token-parser.js +57 -0
- package/dist/src/infrastructure/jwt/token/jwt-token-validator.d.ts +32 -0
- package/dist/src/infrastructure/jwt/token/jwt-token-validator.js +77 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-signer.d.ts +33 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-signer.js +46 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.d.ts +30 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.js +57 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.d.ts +32 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.js +77 -0
- package/dist/src/infrastructure/repositories/index.d.ts +1 -0
- package/dist/src/infrastructure/repositories/index.js +17 -0
- package/dist/src/infrastructure/repositories/test/in-memory-credential.repository.d.ts +12 -0
- package/dist/src/infrastructure/repositories/test/in-memory-credential.repository.js +68 -0
- package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.d.ts +67 -0
- package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.js +128 -0
- package/dist/src/infrastructure/repositories/test/in-memory-user.repository.d.ts +11 -0
- package/dist/src/infrastructure/repositories/test/in-memory-user.repository.js +49 -0
- package/dist/src/infrastructure/repositories/test/index.d.ts +2 -0
- package/dist/src/infrastructure/repositories/test/index.js +18 -0
- package/dist/src/infrastructure/security/bcrypt-password-hasher.d.ts +6 -0
- package/dist/src/infrastructure/security/bcrypt-password-hasher.js +19 -0
- package/dist/src/infrastructure/security/index.d.ts +1 -0
- package/dist/src/infrastructure/security/index.js +17 -0
- package/dist/src/infrastructure/services/default-token-session.service.d.ts +18 -0
- package/dist/src/infrastructure/services/default-token-session.service.js +88 -0
- package/dist/src/infrastructure/services/index.d.ts +2 -0
- package/dist/src/infrastructure/services/index.js +18 -0
- package/dist/src/infrastructure/services/jwt-token.service.d.ts +15 -0
- package/dist/src/infrastructure/services/jwt-token.service.js +44 -0
- package/dist/src/infrastructure/services/simple-jwt-token.service.d.ts +15 -0
- package/dist/src/infrastructure/services/simple-jwt-token.service.js +46 -0
- package/dist/src/infrastructure/services/token-session.service.d.ts +24 -0
- package/dist/src/infrastructure/services/token-session.service.js +131 -0
- package/dist/src/infrastructure/types/auth-service-container.d.ts +14 -0
- package/dist/src/infrastructure/types/auth-service-container.js +2 -0
- package/dist/src/infrastructure/types/index.d.ts +1 -0
- package/dist/src/infrastructure/types/index.js +17 -0
- package/dist/src/shared/constants/index.d.ts +1 -0
- package/dist/src/shared/constants/index.js +17 -0
- package/dist/src/shared/constants/jwt-algorithms.d.ts +17 -0
- package/dist/src/shared/constants/jwt-algorithms.js +23 -0
- package/dist/src/shared/encoders/base64-url-encoder.d.ts +29 -0
- package/dist/src/shared/encoders/base64-url-encoder.js +45 -0
- package/dist/src/shared/encoders/index.d.ts +1 -0
- package/dist/src/shared/encoders/index.js +17 -0
- package/dist/src/shared/index.d.ts +4 -0
- package/dist/src/shared/index.js +20 -0
- package/dist/src/shared/types/index.d.ts +1 -0
- package/dist/src/shared/types/index.js +17 -0
- package/dist/src/shared/types/jwt.d.ts +25 -0
- package/dist/src/shared/types/jwt.js +2 -0
- package/dist/src/shared/types/jwt.types.d.ts +39 -0
- package/dist/src/shared/types/jwt.types.js +2 -0
- package/dist/src/shared/utils/index.d.ts +1 -0
- package/dist/src/shared/utils/index.js +17 -0
- package/dist/src/shared/utils/time-parser.d.ts +28 -0
- package/dist/src/shared/utils/time-parser.js +76 -0
- package/dist/tests/application/factory/auth-service-factory.spec.d.ts +1 -0
- package/dist/tests/application/factory/auth-service-factory.spec.js +97 -0
- package/dist/tests/application/use-cases/login-with-password.integration.spec.d.ts +1 -0
- package/dist/tests/application/use-cases/login-with-password.integration.spec.js +140 -0
- package/dist/tests/application/use-cases/logout-use-case.spec.d.ts +1 -0
- package/dist/tests/application/use-cases/logout-use-case.spec.js +40 -0
- package/dist/tests/application/use-cases/refresh-token-use-case.spec.d.ts +1 -0
- package/dist/tests/application/use-cases/refresh-token-use-case.spec.js +116 -0
- package/dist/tests/application/use-cases/register-user.usecase.spec.d.ts +1 -0
- package/dist/tests/application/use-cases/register-user.usecase.spec.js +151 -0
- package/dist/tests/domain/entities/credential.spec.d.ts +1 -0
- package/dist/tests/domain/entities/credential.spec.js +93 -0
- package/dist/tests/domain/entities/user.spec.d.ts +1 -0
- package/dist/tests/domain/entities/user.spec.js +93 -0
- package/dist/tests/domain/object-values/email.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/email.spec.js +77 -0
- package/dist/tests/domain/object-values/hashed-password.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/hashed-password.spec.js +54 -0
- package/dist/tests/domain/object-values/id.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/id.spec.js +48 -0
- package/dist/tests/domain/object-values/permission.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/permission.spec.js +75 -0
- package/dist/tests/domain/object-values/role.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/role.spec.js +139 -0
- package/dist/tests/domain/services/default-password-policy.spec.d.ts +1 -0
- package/dist/tests/domain/services/default-password-policy.spec.js +69 -0
- package/dist/tests/doman/entities/credential.spec.d.ts +1 -0
- package/dist/tests/doman/entities/credential.spec.js +93 -0
- package/dist/tests/doman/entities/user.spec.d.ts +1 -0
- package/dist/tests/doman/entities/user.spec.js +93 -0
- package/dist/tests/doman/object-values/email.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/email.spec.js +77 -0
- package/dist/tests/doman/object-values/hashed-password.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/hashed-password.spec.js +54 -0
- package/dist/tests/doman/object-values/id.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/id.spec.js +48 -0
- package/dist/tests/doman/object-values/permission.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/permission.spec.js +75 -0
- package/dist/tests/doman/object-values/role.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/role.spec.js +139 -0
- package/dist/tests/helpers/make-jwt-subject.d.ts +7 -0
- package/dist/tests/helpers/make-jwt-subject.js +16 -0
- package/dist/tests/helpers/make-jwt-user.d.ts +7 -0
- package/dist/tests/helpers/make-jwt-user.js +16 -0
- package/dist/tests/helpers/make-user.d.ts +2 -0
- package/dist/tests/helpers/make-user.js +15 -0
- package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.js +127 -0
- package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.js +157 -0
- package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.js +150 -0
- package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.js +156 -0
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.js +179 -0
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.js +142 -0
- package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.js +125 -0
- package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.js +116 -0
- package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.js +88 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.js +126 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.js +116 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.js +88 -0
- package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.d.ts +1 -0
- package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.js +37 -0
- package/dist/tests/infrastructure/services/jwt-token-service.spec.d.ts +1 -0
- package/dist/tests/infrastructure/services/jwt-token-service.spec.js +145 -0
- package/dist/tests/infrastructure/services/token-session.service.spec.d.ts +1 -0
- package/dist/tests/infrastructure/services/token-session.service.spec.js +269 -0
- package/dist/tests/shared/constants/jwt-algorithms.spec.d.ts +1 -0
- package/dist/tests/shared/constants/jwt-algorithms.spec.js +27 -0
- package/dist/tests/shared/encoders/base64-url-encoder.spec.d.ts +1 -0
- package/dist/tests/shared/encoders/base64-url-encoder.spec.js +70 -0
- package/dist/tests/shared/utils/time-parser.spec.d.ts +1 -0
- package/dist/tests/shared/utils/time-parser.spec.js +80 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/time-parser.d.ts +28 -0
- package/dist/utils/time-parser.js +76 -0
- package/package.json +48 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && 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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./login-with-password.use-case"), exports);
|
|
18
|
+
__exportStar(require("./logout.use-case"), exports);
|
|
19
|
+
__exportStar(require("./refresh-token.use-case"), exports);
|
|
20
|
+
__exportStar(require("./register-user.use-case"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IPasswordHasher, ITokenSession, IUserRepository } from "../../domain";
|
|
2
|
+
import { LoginRequest, LoginResponse } from "../dtos";
|
|
3
|
+
export declare class LoginWithPasswordUseCase {
|
|
4
|
+
private readonly userRepository;
|
|
5
|
+
private readonly passwordHasher;
|
|
6
|
+
private readonly tokenSessionService;
|
|
7
|
+
constructor(userRepository: IUserRepository, passwordHasher: IPasswordHasher, tokenSessionService: ITokenSession);
|
|
8
|
+
execute(request: LoginRequest): Promise<LoginResponse>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoginWithPasswordUseCase = void 0;
|
|
4
|
+
const domain_1 = require("../../domain");
|
|
5
|
+
class LoginWithPasswordUseCase {
|
|
6
|
+
constructor(userRepository, passwordHasher, tokenSessionService) {
|
|
7
|
+
this.userRepository = userRepository;
|
|
8
|
+
this.passwordHasher = passwordHasher;
|
|
9
|
+
this.tokenSessionService = tokenSessionService;
|
|
10
|
+
}
|
|
11
|
+
async execute(request) {
|
|
12
|
+
// Buscar usuario por email
|
|
13
|
+
const email = new domain_1.Email(request.email);
|
|
14
|
+
const user = await this.userRepository.findByEmail(email);
|
|
15
|
+
if (!user) {
|
|
16
|
+
throw new domain_1.UserNotFoundError("Invalid credentials");
|
|
17
|
+
}
|
|
18
|
+
// Verificar que el usuario esté activo
|
|
19
|
+
if (!user.canLogin()) {
|
|
20
|
+
throw new domain_1.UserDisabledError("User account is not active");
|
|
21
|
+
}
|
|
22
|
+
// Verificar contraseña
|
|
23
|
+
const isPasswordValid = await this.passwordHasher.compare(request.password, user.password.serialize());
|
|
24
|
+
if (!isPasswordValid) {
|
|
25
|
+
throw new domain_1.PasswordMismatchError("Invalid credentials");
|
|
26
|
+
}
|
|
27
|
+
// Crear sesión con tokens
|
|
28
|
+
const credential = await this.tokenSessionService.createSession(user);
|
|
29
|
+
// Retornar respuesta
|
|
30
|
+
return {
|
|
31
|
+
accessToken: credential.accessToken,
|
|
32
|
+
refreshToken: credential.refreshToken,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.LoginWithPasswordUseCase = LoginWithPasswordUseCase;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ITokenSession } from "../../domain";
|
|
2
|
+
import { LogoutRequest, LogoutResponse } from "../dtos";
|
|
3
|
+
export declare class LogoutUseCase {
|
|
4
|
+
private readonly tokenSession;
|
|
5
|
+
constructor(tokenSession: ITokenSession);
|
|
6
|
+
execute(request: LogoutRequest): Promise<LogoutResponse>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogoutUseCase = void 0;
|
|
4
|
+
const domain_1 = require("../../domain");
|
|
5
|
+
class LogoutUseCase {
|
|
6
|
+
constructor(tokenSession) {
|
|
7
|
+
this.tokenSession = tokenSession;
|
|
8
|
+
}
|
|
9
|
+
async execute(request) {
|
|
10
|
+
try {
|
|
11
|
+
await this.tokenSession.revokeSession(request.refreshToken);
|
|
12
|
+
return {
|
|
13
|
+
success: true,
|
|
14
|
+
message: "Successfully logged out",
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
throw new domain_1.LogoutError("Failed to logout: invalid refresh token");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.LogoutUseCase = LogoutUseCase;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ITokenSession } from "../../domain";
|
|
2
|
+
import { RefreshTokenRequest, RefreshTokenResponse } from "../dtos";
|
|
3
|
+
export declare class RefreshTokenUseCase {
|
|
4
|
+
private readonly tokenSessionService;
|
|
5
|
+
constructor(tokenSessionService: ITokenSession);
|
|
6
|
+
execute(request: RefreshTokenRequest): Promise<RefreshTokenResponse>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RefreshTokenUseCase = void 0;
|
|
4
|
+
const domain_1 = require("../../domain");
|
|
5
|
+
class RefreshTokenUseCase {
|
|
6
|
+
constructor(tokenSessionService) {
|
|
7
|
+
this.tokenSessionService = tokenSessionService;
|
|
8
|
+
}
|
|
9
|
+
async execute(request) {
|
|
10
|
+
try {
|
|
11
|
+
// Refrescar la sesión
|
|
12
|
+
const credential = await this.tokenSessionService.refreshSession(request.refreshToken);
|
|
13
|
+
return {
|
|
14
|
+
accessToken: credential.accessToken,
|
|
15
|
+
refreshToken: credential.refreshToken,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
throw new domain_1.InvalidOrExpiredRefreshTokenError();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.RefreshTokenUseCase = RefreshTokenUseCase;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IPasswordHasher, IPasswordPolicy } from "../../domain";
|
|
2
|
+
import { IUserRepository } from "../../domain/ports/repository";
|
|
3
|
+
import { RegisterUserRequest, RegisterUserResponse } from "../dtos";
|
|
4
|
+
export declare class RegisterUserUseCase {
|
|
5
|
+
private readonly userRepository;
|
|
6
|
+
private readonly passwordHasher;
|
|
7
|
+
private readonly passwordPolicy;
|
|
8
|
+
constructor(userRepository: IUserRepository, passwordHasher: IPasswordHasher, passwordPolicy: IPasswordPolicy);
|
|
9
|
+
execute(request: RegisterUserRequest): Promise<RegisterUserResponse>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RegisterUserUseCase = void 0;
|
|
4
|
+
const domain_1 = require("../../domain");
|
|
5
|
+
class RegisterUserUseCase {
|
|
6
|
+
constructor(userRepository, passwordHasher, passwordPolicy) {
|
|
7
|
+
this.userRepository = userRepository;
|
|
8
|
+
this.passwordHasher = passwordHasher;
|
|
9
|
+
this.passwordPolicy = passwordPolicy;
|
|
10
|
+
}
|
|
11
|
+
async execute(request) {
|
|
12
|
+
// Validar política de contraseñas
|
|
13
|
+
const passwordValidation = this.passwordPolicy.validateStrength(request.password);
|
|
14
|
+
if (!passwordValidation.isValid) {
|
|
15
|
+
throw new domain_1.PasswordPolicyViolationError(passwordValidation.errors);
|
|
16
|
+
}
|
|
17
|
+
// Verificar que el email no esté en uso
|
|
18
|
+
const email = new domain_1.Email(request.email);
|
|
19
|
+
const exists = await this.userRepository.findByEmail(email);
|
|
20
|
+
if (exists) {
|
|
21
|
+
throw new domain_1.EmailAlreadyInUseError();
|
|
22
|
+
}
|
|
23
|
+
// Hash de la contraseña
|
|
24
|
+
const hashedPassword = await this.passwordHasher.hash(request.password);
|
|
25
|
+
// Crear el usuario
|
|
26
|
+
const user = domain_1.User.create(request.email, request.roles?.map((r) => new domain_1.Role(r.role, r.permissions?.map((permission) => new domain_1.Permission(permission)))) || [], hashedPassword);
|
|
27
|
+
// Guardar en repositorio
|
|
28
|
+
await this.userRepository.save(user);
|
|
29
|
+
// Retornar respuesta
|
|
30
|
+
return {
|
|
31
|
+
id: user.id.getValue(),
|
|
32
|
+
roles: user.roles.map((role) => role.getValuePublic()),
|
|
33
|
+
isActive: user.isActive,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.RegisterUserUseCase = RegisterUserUseCase;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Id } from "../object-values";
|
|
2
|
+
import { ICredentialProps } from "../props/entities";
|
|
3
|
+
/**
|
|
4
|
+
* Representa las credenciales activas de un usuario dentro del dominio
|
|
5
|
+
*/
|
|
6
|
+
export declare class Credential {
|
|
7
|
+
/**
|
|
8
|
+
* Identificador del usuario asociado a las credenciales
|
|
9
|
+
*/
|
|
10
|
+
private readonly _userId;
|
|
11
|
+
/**
|
|
12
|
+
* Token de acceso asociado
|
|
13
|
+
*/
|
|
14
|
+
private readonly _accessToken;
|
|
15
|
+
/**
|
|
16
|
+
* Token de refresco asociado
|
|
17
|
+
*/
|
|
18
|
+
private readonly _refreshToken;
|
|
19
|
+
/**
|
|
20
|
+
* Fecha de expiración del token de acceso
|
|
21
|
+
*/
|
|
22
|
+
private readonly _expiresAt;
|
|
23
|
+
/**
|
|
24
|
+
* Fecha de creación de las credenciales
|
|
25
|
+
*/
|
|
26
|
+
private readonly _createdAt;
|
|
27
|
+
/**
|
|
28
|
+
* Constructor privado para evitar instanciación directa
|
|
29
|
+
* @param props Propiedades de las credenciales
|
|
30
|
+
*/
|
|
31
|
+
constructor(props: ICredentialProps);
|
|
32
|
+
/**
|
|
33
|
+
* Obtiene el identificador del usuario asociado a las credenciales
|
|
34
|
+
*/
|
|
35
|
+
get userId(): Id;
|
|
36
|
+
/**
|
|
37
|
+
* Obtiene el token de acceso
|
|
38
|
+
*/
|
|
39
|
+
get accessToken(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Obtiene el token de refresco
|
|
42
|
+
*/
|
|
43
|
+
get refreshToken(): string;
|
|
44
|
+
/**
|
|
45
|
+
* Obtiene la fecha de expiración del token de acceso
|
|
46
|
+
*/
|
|
47
|
+
get expiresAt(): Date;
|
|
48
|
+
/**
|
|
49
|
+
* Obtiene la fecha de creación de las credenciales
|
|
50
|
+
*/
|
|
51
|
+
get createdAt(): Date;
|
|
52
|
+
/**
|
|
53
|
+
* Evalúa si las credenciales han expirado
|
|
54
|
+
* @returns Verdadero si las credenciales han expirado, falso en caso contrario
|
|
55
|
+
*/
|
|
56
|
+
isExpired(): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Evalúa si las credenciales son válidas (no expiradas)
|
|
59
|
+
* @returns Verdadero si las credenciales son válidas (no expiradas), falso en caso contrario
|
|
60
|
+
*/
|
|
61
|
+
isValid(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Crea una nueva instancia de Credential
|
|
64
|
+
* @param userId Identificador del usuario
|
|
65
|
+
* @param accessToken Token de acceso
|
|
66
|
+
* @param refreshToken Token de refresco
|
|
67
|
+
* @param expirationDate Fecha de expiración del token de acceso
|
|
68
|
+
* @returns Nueva instancia de Credential
|
|
69
|
+
*/
|
|
70
|
+
static create(userId: Id, accessToken: string, refreshToken: string, expirationDate: Date): Credential;
|
|
71
|
+
/**
|
|
72
|
+
*Reconstitution method for repository
|
|
73
|
+
*Método usado por un repositorio para reconstruir la entidad desde la base de datos
|
|
74
|
+
* @param props Propiedades de las credenciales
|
|
75
|
+
* @returns Nueva instancia de Credential
|
|
76
|
+
*/
|
|
77
|
+
static reconstitute(props: ICredentialProps): Credential;
|
|
78
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Credential = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Representa las credenciales activas de un usuario dentro del dominio
|
|
6
|
+
*/
|
|
7
|
+
class Credential {
|
|
8
|
+
/**
|
|
9
|
+
* Constructor privado para evitar instanciación directa
|
|
10
|
+
* @param props Propiedades de las credenciales
|
|
11
|
+
*/
|
|
12
|
+
constructor(props) {
|
|
13
|
+
this._userId = props.userId;
|
|
14
|
+
this._accessToken = props.accessToken;
|
|
15
|
+
this._refreshToken = props.refreshToken;
|
|
16
|
+
this._expiresAt = props.expiresAt;
|
|
17
|
+
this._createdAt = props.createdAt;
|
|
18
|
+
}
|
|
19
|
+
// Getters
|
|
20
|
+
/**
|
|
21
|
+
* Obtiene el identificador del usuario asociado a las credenciales
|
|
22
|
+
*/
|
|
23
|
+
get userId() {
|
|
24
|
+
return this._userId;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Obtiene el token de acceso
|
|
28
|
+
*/
|
|
29
|
+
get accessToken() {
|
|
30
|
+
return this._accessToken;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Obtiene el token de refresco
|
|
34
|
+
*/
|
|
35
|
+
get refreshToken() {
|
|
36
|
+
return this._refreshToken;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Obtiene la fecha de expiración del token de acceso
|
|
40
|
+
*/
|
|
41
|
+
get expiresAt() {
|
|
42
|
+
return new Date(this._expiresAt);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Obtiene la fecha de creación de las credenciales
|
|
46
|
+
*/
|
|
47
|
+
get createdAt() {
|
|
48
|
+
return new Date(this._createdAt);
|
|
49
|
+
}
|
|
50
|
+
// Business methods
|
|
51
|
+
/**
|
|
52
|
+
* Evalúa si las credenciales han expirado
|
|
53
|
+
* @returns Verdadero si las credenciales han expirado, falso en caso contrario
|
|
54
|
+
*/
|
|
55
|
+
isExpired() {
|
|
56
|
+
return new Date() > this._expiresAt;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Evalúa si las credenciales son válidas (no expiradas)
|
|
60
|
+
* @returns Verdadero si las credenciales son válidas (no expiradas), falso en caso contrario
|
|
61
|
+
*/
|
|
62
|
+
isValid() {
|
|
63
|
+
return !this.isExpired();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Crea una nueva instancia de Credential
|
|
67
|
+
* @param userId Identificador del usuario
|
|
68
|
+
* @param accessToken Token de acceso
|
|
69
|
+
* @param refreshToken Token de refresco
|
|
70
|
+
* @param expirationDate Fecha de expiración del token de acceso
|
|
71
|
+
* @returns Nueva instancia de Credential
|
|
72
|
+
*/
|
|
73
|
+
static create(userId, accessToken, refreshToken, expirationDate) {
|
|
74
|
+
return new Credential({
|
|
75
|
+
userId,
|
|
76
|
+
accessToken,
|
|
77
|
+
refreshToken,
|
|
78
|
+
expiresAt: expirationDate,
|
|
79
|
+
createdAt: new Date(),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
*Reconstitution method for repository
|
|
84
|
+
*Método usado por un repositorio para reconstruir la entidad desde la base de datos
|
|
85
|
+
* @param props Propiedades de las credenciales
|
|
86
|
+
* @returns Nueva instancia de Credential
|
|
87
|
+
*/
|
|
88
|
+
static reconstitute(props) {
|
|
89
|
+
return new Credential(props);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.Credential = Credential;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && 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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./credential.entity"), exports);
|
|
18
|
+
__exportStar(require("./user.entity"), exports);
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Email, HashedPassword, Id, Role } from "../object-values";
|
|
2
|
+
import { IUserProps } from "../props";
|
|
3
|
+
/**
|
|
4
|
+
*Representa al agregado raíz de dominio del usuario en una arquitectura limpia o DDD (Domain-Driven Design).
|
|
5
|
+
*/
|
|
6
|
+
export declare class User {
|
|
7
|
+
/**
|
|
8
|
+
* Identificador único del usuario
|
|
9
|
+
*/
|
|
10
|
+
private readonly _id;
|
|
11
|
+
/**
|
|
12
|
+
* Correo electrónico del usuario
|
|
13
|
+
*/
|
|
14
|
+
private readonly _email;
|
|
15
|
+
/**
|
|
16
|
+
* Rol del usuario dentro del sistema
|
|
17
|
+
*/
|
|
18
|
+
private readonly _roles;
|
|
19
|
+
/**
|
|
20
|
+
* Contraseña hasheada del usuario
|
|
21
|
+
*/
|
|
22
|
+
private readonly _password;
|
|
23
|
+
/**
|
|
24
|
+
* Indica si el usuario está activo o inactivo
|
|
25
|
+
*/
|
|
26
|
+
private _isActive;
|
|
27
|
+
/**
|
|
28
|
+
* Fecha de creación del usuario
|
|
29
|
+
*/
|
|
30
|
+
private readonly _createdAt;
|
|
31
|
+
/**
|
|
32
|
+
* Fecha de última actualización del usuario
|
|
33
|
+
*/
|
|
34
|
+
private _updatedAt;
|
|
35
|
+
/**
|
|
36
|
+
* Constructor privado para evitar instanciación directa
|
|
37
|
+
* @param props Propiedades del usuario
|
|
38
|
+
*/
|
|
39
|
+
constructor(props: IUserProps);
|
|
40
|
+
/**
|
|
41
|
+
* Obtiene el identificador único del usuario
|
|
42
|
+
*/
|
|
43
|
+
get id(): Id;
|
|
44
|
+
/**
|
|
45
|
+
* Obtiene el correo electrónico del usuario
|
|
46
|
+
*/
|
|
47
|
+
get email(): Email;
|
|
48
|
+
/**
|
|
49
|
+
* Obtiene el rol del usuario
|
|
50
|
+
*/
|
|
51
|
+
get roles(): Role[];
|
|
52
|
+
/**
|
|
53
|
+
* Obtiene la contraseña hasheada del usuario
|
|
54
|
+
*/
|
|
55
|
+
get password(): HashedPassword;
|
|
56
|
+
/**
|
|
57
|
+
* Indica si el usuario está activo o inactivo
|
|
58
|
+
*/
|
|
59
|
+
get isActive(): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Obtiene la fecha de creación del usuario
|
|
62
|
+
*/
|
|
63
|
+
get createdAt(): Date;
|
|
64
|
+
/**
|
|
65
|
+
* Obtiene la fecha de última actualización del usuario
|
|
66
|
+
*/
|
|
67
|
+
get updatedAt(): Date;
|
|
68
|
+
/**
|
|
69
|
+
* Marca al usuario como activo
|
|
70
|
+
*/
|
|
71
|
+
activate(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Marca al usuario como inactivo
|
|
74
|
+
*/
|
|
75
|
+
deactivate(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Evalúa si el usuario puede iniciar sesión
|
|
78
|
+
* @returns Verdadero si el usuario puede iniciar sesión, falso en caso contrario
|
|
79
|
+
*/
|
|
80
|
+
canLogin(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Factory method to create a new User
|
|
83
|
+
* @param email email
|
|
84
|
+
* @param role role
|
|
85
|
+
* @param hashedPassword hashed password
|
|
86
|
+
* @returns New User instance
|
|
87
|
+
*/
|
|
88
|
+
static create(email: string, roles: Role[], hashedPassword: string): User;
|
|
89
|
+
/**
|
|
90
|
+
*Reconstitution method for repository
|
|
91
|
+
*Método usado por los repositorios al reconstruir
|
|
92
|
+
*el usuario desde la base de datos o una fuente persistente
|
|
93
|
+
* @param props Propiedades del usuario
|
|
94
|
+
* @returns Nueva instancia de User
|
|
95
|
+
*/
|
|
96
|
+
static reconstitute(props: IUserProps): User;
|
|
97
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.User = void 0;
|
|
4
|
+
const object_values_1 = require("../object-values");
|
|
5
|
+
/**
|
|
6
|
+
*Representa al agregado raíz de dominio del usuario en una arquitectura limpia o DDD (Domain-Driven Design).
|
|
7
|
+
*/
|
|
8
|
+
class User {
|
|
9
|
+
/**
|
|
10
|
+
* Constructor privado para evitar instanciación directa
|
|
11
|
+
* @param props Propiedades del usuario
|
|
12
|
+
*/
|
|
13
|
+
constructor(props) {
|
|
14
|
+
this._id = props.id;
|
|
15
|
+
this._email = props.email;
|
|
16
|
+
this._roles = props.roles;
|
|
17
|
+
this._password = props.password;
|
|
18
|
+
this._isActive = props.isActive;
|
|
19
|
+
this._createdAt = props.createdAt;
|
|
20
|
+
this._updatedAt = props.updatedAt;
|
|
21
|
+
}
|
|
22
|
+
// Getters
|
|
23
|
+
/**
|
|
24
|
+
* Obtiene el identificador único del usuario
|
|
25
|
+
*/
|
|
26
|
+
get id() {
|
|
27
|
+
return this._id;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Obtiene el correo electrónico del usuario
|
|
31
|
+
*/
|
|
32
|
+
get email() {
|
|
33
|
+
return this._email;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Obtiene el rol del usuario
|
|
37
|
+
*/
|
|
38
|
+
get roles() {
|
|
39
|
+
return this._roles;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Obtiene la contraseña hasheada del usuario
|
|
43
|
+
*/
|
|
44
|
+
get password() {
|
|
45
|
+
return this._password;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Indica si el usuario está activo o inactivo
|
|
49
|
+
*/
|
|
50
|
+
get isActive() {
|
|
51
|
+
return this._isActive;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Obtiene la fecha de creación del usuario
|
|
55
|
+
*/
|
|
56
|
+
get createdAt() {
|
|
57
|
+
return new Date(this._createdAt);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Obtiene la fecha de última actualización del usuario
|
|
61
|
+
*/
|
|
62
|
+
get updatedAt() {
|
|
63
|
+
return new Date(this._updatedAt);
|
|
64
|
+
}
|
|
65
|
+
// Business methods
|
|
66
|
+
/**
|
|
67
|
+
* Marca al usuario como activo
|
|
68
|
+
*/
|
|
69
|
+
activate() {
|
|
70
|
+
this._isActive = true;
|
|
71
|
+
this._updatedAt = new Date();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Marca al usuario como inactivo
|
|
75
|
+
*/
|
|
76
|
+
deactivate() {
|
|
77
|
+
this._isActive = false;
|
|
78
|
+
this._updatedAt = new Date();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Evalúa si el usuario puede iniciar sesión
|
|
82
|
+
* @returns Verdadero si el usuario puede iniciar sesión, falso en caso contrario
|
|
83
|
+
*/
|
|
84
|
+
canLogin() {
|
|
85
|
+
return this._isActive;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Factory method to create a new User
|
|
89
|
+
* @param email email
|
|
90
|
+
* @param role role
|
|
91
|
+
* @param hashedPassword hashed password
|
|
92
|
+
* @returns New User instance
|
|
93
|
+
*/
|
|
94
|
+
static create(email, roles, hashedPassword) {
|
|
95
|
+
return new User({
|
|
96
|
+
id: object_values_1.Id.generate(),
|
|
97
|
+
email: new object_values_1.Email(email),
|
|
98
|
+
roles: roles,
|
|
99
|
+
password: new object_values_1.HashedPassword(hashedPassword),
|
|
100
|
+
isActive: true,
|
|
101
|
+
createdAt: new Date(),
|
|
102
|
+
updatedAt: new Date(),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
*Reconstitution method for repository
|
|
107
|
+
*Método usado por los repositorios al reconstruir
|
|
108
|
+
*el usuario desde la base de datos o una fuente persistente
|
|
109
|
+
* @param props Propiedades del usuario
|
|
110
|
+
* @returns Nueva instancia de User
|
|
111
|
+
*/
|
|
112
|
+
static reconstitute(props) {
|
|
113
|
+
return new User(props);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.User = User;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export type AuthErrorCode = "TOKEN_EXPIRED" | "TOKEN_NOT_YET_VALID" | "TOKEN_INVALID" | "TOKEN_MALFORMED" | "SIGNATURE_INVALID" | "ALGORITHM_UNSUPPORTED" | "KEY_NOT_FOUND" | "KEY_MISMATCH" | "TOKEN_REVOKED" | "CLOCK_SKEW" | "AUTHENTICATION_FAILED" | "CLAIMS_VALIDATION_ERROR";
|
|
2
|
+
export interface ClaimsIssue {
|
|
3
|
+
path: string;
|
|
4
|
+
message: string;
|
|
5
|
+
}
|
|
6
|
+
export declare abstract class AuthDomainError extends Error {
|
|
7
|
+
readonly code: AuthErrorCode;
|
|
8
|
+
readonly details?: unknown;
|
|
9
|
+
constructor(message: string, code: AuthErrorCode, details?: unknown);
|
|
10
|
+
toJSON(): {
|
|
11
|
+
name: string;
|
|
12
|
+
message: string;
|
|
13
|
+
code: AuthErrorCode;
|
|
14
|
+
details: unknown;
|
|
15
|
+
};
|
|
16
|
+
static isAuthError(e: unknown): e is AuthDomainError;
|
|
17
|
+
}
|
|
18
|
+
/** El token ya no es válido por exp (exp < now) */
|
|
19
|
+
export declare class TokenExpiredError extends AuthDomainError {
|
|
20
|
+
constructor(message?: string, details?: {
|
|
21
|
+
exp?: number;
|
|
22
|
+
now?: number;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** El token aún no debe usarse (nbf > now) */
|
|
26
|
+
export declare class TokenNotYetValidError extends AuthDomainError {
|
|
27
|
+
constructor(message?: string, details?: {
|
|
28
|
+
nbf?: number;
|
|
29
|
+
now?: number;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/** Formato inválido (no tiene 3 partes, base64url inválido, JSON inválido) */
|
|
33
|
+
export declare class InvalidTokenFormatError extends AuthDomainError {
|
|
34
|
+
constructor(message?: string, details?: unknown);
|
|
35
|
+
}
|
|
36
|
+
/** Firma inválida (no coincide con datos/clave) */
|
|
37
|
+
export declare class InvalidSignatureError extends AuthDomainError {
|
|
38
|
+
constructor(message?: string, details?: unknown);
|
|
39
|
+
}
|
|
40
|
+
/** Algoritmo no soportado por la librería/política */
|
|
41
|
+
export declare class UnsupportedAlgorithmError extends AuthDomainError {
|
|
42
|
+
constructor(message?: string, details?: {
|
|
43
|
+
alg: string;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/** No se pudo resolver/obtener la clave necesaria (kid, store…) */
|
|
47
|
+
export declare class KeyNotFoundError extends AuthDomainError {
|
|
48
|
+
constructor(message?: string, details?: {
|
|
49
|
+
kid?: string;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/** La clave encontrada no corresponde (key-id/alg desalineado, par incorrecto) */
|
|
53
|
+
export declare class KeyMismatchError extends AuthDomainError {
|
|
54
|
+
constructor(message?: string, details?: {
|
|
55
|
+
alg?: string;
|
|
56
|
+
kid?: string;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/** Token revocado en listas de deny/blacklist */
|
|
60
|
+
export declare class TokenRevokedError extends AuthDomainError {
|
|
61
|
+
constructor(message?: string, details?: {
|
|
62
|
+
jti?: string;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** Desfase de reloj detectado (leeway insuficiente) */
|
|
66
|
+
export declare class ClockSkewError extends AuthDomainError {
|
|
67
|
+
constructor(message?: string, details?: {
|
|
68
|
+
skewSeconds?: number;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/** Claims inválidas a nivel semántico (aud, iss, scope, custom…) */
|
|
72
|
+
export declare class ClaimsValidationError extends AuthDomainError {
|
|
73
|
+
constructor(issues: ClaimsIssue[], message?: string);
|
|
74
|
+
}
|
|
75
|
+
/** Falla general de autenticación (catch-all) */
|
|
76
|
+
export declare class AuthenticationError extends AuthDomainError {
|
|
77
|
+
constructor(message?: string, details?: unknown);
|
|
78
|
+
}
|
|
79
|
+
/** Alias histórico si lo usabas antes */
|
|
80
|
+
export declare class InvalidTokenError extends AuthenticationError {
|
|
81
|
+
constructor(message?: string, details?: unknown);
|
|
82
|
+
}
|