@jmlq/auth 0.0.1-alpha.1 → 0.0.1-alpha.2
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 +259 -306
- package/dist/application/dtos/index.d.ts +3 -0
- package/dist/application/dtos/index.js +19 -0
- package/dist/application/dtos/request/index.d.ts +4 -0
- package/dist/{src/application/dtos → application/dtos/request}/index.js +4 -4
- package/dist/{src/application/dtos/login.dto.d.ts → application/dtos/request/login.request.d.ts} +0 -4
- package/dist/application/dtos/request/logout.request.d.ts +3 -0
- package/dist/application/dtos/request/refresh-token.request.d.ts +3 -0
- package/dist/application/dtos/request/register-user.request.d.ts +6 -0
- package/dist/application/dtos/response/index.d.ts +4 -0
- package/dist/application/dtos/response/index.js +20 -0
- package/dist/application/dtos/response/login.response.d.ts +4 -0
- package/dist/{src/application/dtos/logout.dto.d.ts → application/dtos/response/logout.response.d.ts} +0 -3
- package/dist/{src/application/dtos/refresh-token.dto.d.ts → application/dtos/response/refresh-token.response.d.ts} +0 -3
- package/dist/application/dtos/response/register-user.response.d.ts +7 -0
- package/dist/application/dtos/type/index.d.ts +1 -0
- package/dist/{src/shared/constants → application/dtos/type}/index.js +1 -1
- package/dist/application/dtos/type/user-role.type.d.ts +4 -0
- package/dist/application/factories/auth-service.factory.d.ts +11 -0
- package/dist/application/factories/auth-service.factory.js +40 -0
- package/dist/{src/application → application}/index.d.ts +1 -0
- package/dist/{src/application → application}/index.js +1 -0
- package/dist/application/types/auth-service-factory-options.type.d.ts +5 -0
- package/dist/application/types/index.d.ts +1 -0
- package/dist/{src/infrastructure/jwt/factory → application/types}/index.js +1 -1
- package/dist/{src/application → application}/use-cases/login-with-password.use-case.d.ts +2 -2
- package/dist/{src/application → application}/use-cases/login-with-password.use-case.js +6 -5
- package/dist/{src/application → application}/use-cases/logout.use-case.d.ts +2 -2
- package/dist/{src/application → application}/use-cases/logout.use-case.js +2 -2
- package/dist/{src/application → application}/use-cases/refresh-token.use-case.d.ts +2 -2
- package/dist/{src/application → application}/use-cases/refresh-token.use-case.js +2 -2
- package/dist/application/use-cases/register-user.use-case.d.ts +12 -0
- package/dist/{src/application → application}/use-cases/register-user.use-case.js +27 -1
- package/dist/{src/domain → domain}/errors/auth.errors.d.ts +1 -14
- package/dist/{src/domain → domain}/errors/auth.errors.js +1 -15
- package/dist/{src/domain → domain}/index.d.ts +0 -1
- package/dist/{src/domain → domain}/index.js +0 -1
- package/dist/domain/ports/auth/index.d.ts +2 -0
- package/dist/domain/ports/auth/index.js +18 -0
- package/dist/{src/domain/ports/auth/password-hasher.d.ts → domain/ports/auth/password-hasher.port.d.ts} +1 -1
- package/dist/{src/domain → domain}/ports/auth/password-policy.port.d.ts +1 -1
- package/dist/domain/ports/index.d.ts +4 -0
- package/dist/{src/infrastructure/jwt → domain/ports}/index.js +3 -2
- package/dist/domain/ports/jwt/index.d.ts +1 -0
- package/dist/{src/shared/types → domain/ports/jwt}/index.js +1 -1
- package/dist/domain/ports/jwt/payload/index.d.ts +1 -0
- package/dist/domain/ports/jwt/payload/index.js +17 -0
- package/dist/{src/domain → domain}/ports/repository/credential.repository.d.ts +1 -1
- package/dist/{src/domain → domain}/ports/repository/index.d.ts +1 -1
- package/dist/{src/domain → domain}/ports/repository/index.js +1 -1
- package/dist/{src/domain/ports/repository/user.repository.d.ts → domain/ports/repository/user-repository.port.d.ts} +1 -1
- package/dist/domain/ports/token/index.d.ts +2 -0
- package/dist/domain/ports/token/index.js +18 -0
- package/dist/{src/domain → domain}/ports/token/token-session.port.d.ts +2 -2
- package/dist/{src/domain → domain}/ports/token/token.service.port.d.ts +2 -2
- package/dist/{src/domain → domain}/props/jwt/generate-access-token.props.d.ts +0 -2
- package/dist/{src/domain → domain}/props/jwt/generate-refresh-token.props.d.ts +0 -2
- package/dist/{src/domain/props/services → domain/props/jwt}/index.d.ts +1 -0
- package/dist/{src/domain/props/services → domain/props/jwt}/index.js +1 -0
- package/dist/{src/domain → domain}/services/password-policy.service.d.ts +2 -2
- package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-credential.repository.d.ts +2 -2
- package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-credential.repository.js +12 -2
- package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-user.repository.d.ts +2 -2
- package/dist/index.d.ts +4 -1
- package/dist/index.js +11 -1
- package/dist/infrastructure/index.js +1 -0
- package/dist/{src/infrastructure → infrastructure}/security/bcrypt-password-hasher.d.ts +7 -2
- package/dist/{src/infrastructure → infrastructure}/security/bcrypt-password-hasher.js +7 -2
- package/dist/{src/infrastructure → infrastructure}/services/index.d.ts +0 -1
- package/dist/{src/infrastructure → infrastructure}/services/index.js +0 -1
- package/dist/infrastructure/services/token-session.service.d.ts +22 -0
- package/dist/{src/infrastructure/services/default-token-session.service.js → infrastructure/services/token-session.service.js} +30 -31
- package/dist/infrastructure/types/auth-service-container.d.ts +14 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/{src/infrastructure/repositories → shared}/index.js +1 -1
- package/package.json +5 -8
- package/dist/examples/bcrypt-password-hasher.example.d.ts +0 -3
- package/dist/examples/bcrypt-password-hasher.example.js +0 -78
- package/dist/examples/entity-object.example.d.ts +0 -39
- package/dist/examples/entity-object.example.js +0 -411
- package/dist/examples/factory-auth-service-example.d.ts +0 -3
- package/dist/examples/factory-auth-service-example.js +0 -84
- package/dist/examples/index.example.d.ts +0 -12
- package/dist/examples/index.example.js +0 -171
- package/dist/examples/jwt-algoritm.example.d.ts +0 -47
- package/dist/examples/jwt-algoritm.example.js +0 -447
- package/dist/examples/jwt-token-generator.example.d.ts +0 -6
- package/dist/examples/jwt-token-generator.example.js +0 -49
- package/dist/examples/jwt-verifier.example.d.ts +0 -3
- package/dist/examples/jwt-verifier.example.js +0 -80
- package/dist/examples/password-policy.example.d.ts +0 -7
- package/dist/examples/password-policy.example.js +0 -57
- package/dist/examples/service-jwt-token.example.d.ts +0 -3
- package/dist/examples/service-jwt-token.example.js +0 -154
- package/dist/examples/service-token-session.example.d.ts +0 -3
- package/dist/examples/service-token-session.example.js +0 -139
- package/dist/examples/use-case-login-with-password.example.d.ts +0 -6
- package/dist/examples/use-case-login-with-password.example.js +0 -105
- package/dist/examples/use-case-logout.example.d.ts +0 -7
- package/dist/examples/use-case-logout.example.js +0 -134
- package/dist/examples/use-case-refresh-token.example.d.ts +0 -11
- package/dist/examples/use-case-refresh-token.example.js +0 -164
- package/dist/examples/use-case-register-user.example.d.ts +0 -9
- package/dist/examples/use-case-register-user.example.js +0 -110
- package/dist/src/application/dtos/index.d.ts +0 -4
- package/dist/src/application/dtos/register-user.dto.d.ts +0 -16
- package/dist/src/application/factories/auth-service.factory.d.ts +0 -5
- package/dist/src/application/factories/auth-service.factory.js +0 -51
- package/dist/src/application/use-cases/register-user.use-case.d.ts +0 -10
- package/dist/src/domain/errors/auth-domain-error.d.ts +0 -82
- package/dist/src/domain/errors/auth-domain-error.js +0 -112
- package/dist/src/domain/ports/auth/password-policy-config.port.js +0 -10
- package/dist/src/domain/ports/config/auth-config.port.d.ts +0 -19
- package/dist/src/domain/ports/config/auth-config.port.js +0 -3
- package/dist/src/domain/ports/index.d.ts +0 -9
- package/dist/src/domain/ports/index.js +0 -25
- package/dist/src/domain/ports/jwt/factory/signature-strategy-factory.port.d.ts +0 -14
- package/dist/src/domain/ports/jwt/signature-strategy-factory.port.d.ts +0 -14
- package/dist/src/domain/ports/jwt/signature-strategy.d.ts +0 -30
- package/dist/src/domain/ports/jwt/signature-strategy.js +0 -4
- package/dist/src/domain/ports/jwt/signature-strategy.port.d.ts +0 -31
- package/dist/src/domain/ports/jwt/signature-strategy.port.js +0 -4
- package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.d.ts +0 -31
- package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.js +0 -4
- package/dist/src/domain/props/create-payload-props.port.d.ts +0 -0
- package/dist/src/domain/props/create-payload-props.port.js +0 -8
- package/dist/src/domain/props/jwt/create-payload.props.d.ts +0 -9
- package/dist/src/domain/props/jwt/generate-token.props.d.ts +0 -10
- package/dist/src/domain/props/jwt/generate-token.props.js +0 -2
- package/dist/src/domain/props/jwt/index.d.ts +0 -5
- package/dist/src/domain/props/jwt/index.js +0 -21
- package/dist/src/domain/props/jwt/jwt-subject.d.ts +0 -7
- package/dist/src/domain/props/jwt/jwt-subject.js +0 -2
- package/dist/src/domain/props/services/generate-access-token.props.d.ts +0 -8
- package/dist/src/domain/props/services/generate-refresh-token.props.d.ts +0 -8
- package/dist/src/domain/services/token.service.port.d.ts +0 -9
- package/dist/src/index.d.ts +0 -78
- package/dist/src/index.js +0 -94
- package/dist/src/infrastructure/index.d.ts +0 -5
- package/dist/src/infrastructure/index.js +0 -21
- package/dist/src/infrastructure/jwt/factory/index.d.ts +0 -1
- package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.d.ts +0 -21
- package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.js +0 -61
- package/dist/src/infrastructure/jwt/index.d.ts +0 -3
- package/dist/src/infrastructure/jwt/signature-strategy.factory.d.ts +0 -21
- package/dist/src/infrastructure/jwt/signature-strategy.factory.js +0 -61
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.d.ts +0 -47
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.js +0 -124
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.d.ts +0 -47
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.js +0 -124
- package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.d.ts +0 -54
- package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.js +0 -129
- package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.d.ts +0 -54
- package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.js +0 -129
- package/dist/src/infrastructure/jwt/strategies/index.d.ts +0 -3
- package/dist/src/infrastructure/jwt/strategies/index.js +0 -19
- package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.d.ts +0 -47
- package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.js +0 -124
- package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.d.ts +0 -47
- package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.js +0 -124
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.d.ts +0 -57
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.js +0 -123
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.d.ts +0 -59
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.js +0 -100
- package/dist/src/infrastructure/jwt/token/index.d.ts +0 -5
- package/dist/src/infrastructure/jwt/token/index.js +0 -21
- package/dist/src/infrastructure/jwt/token/jwt-signer.d.ts +0 -33
- package/dist/src/infrastructure/jwt/token/jwt-signer.js +0 -46
- package/dist/src/infrastructure/jwt/token/jwt-token-parser.d.ts +0 -29
- package/dist/src/infrastructure/jwt/token/jwt-token-parser.js +0 -57
- package/dist/src/infrastructure/jwt/token/jwt-token-validator.d.ts +0 -32
- package/dist/src/infrastructure/jwt/token/jwt-token-validator.js +0 -77
- package/dist/src/infrastructure/jwt/token/tools/jwt-signer.d.ts +0 -33
- package/dist/src/infrastructure/jwt/token/tools/jwt-signer.js +0 -46
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.d.ts +0 -30
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.js +0 -57
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.d.ts +0 -32
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.js +0 -77
- package/dist/src/infrastructure/repositories/index.d.ts +0 -1
- package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.d.ts +0 -67
- package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.js +0 -128
- package/dist/src/infrastructure/services/default-token-session.service.d.ts +0 -18
- package/dist/src/infrastructure/services/jwt-token.service.d.ts +0 -15
- package/dist/src/infrastructure/services/jwt-token.service.js +0 -44
- package/dist/src/infrastructure/services/simple-jwt-token.service.d.ts +0 -15
- package/dist/src/infrastructure/services/simple-jwt-token.service.js +0 -46
- package/dist/src/infrastructure/services/token-session.service.d.ts +0 -24
- package/dist/src/infrastructure/services/token-session.service.js +0 -131
- package/dist/src/infrastructure/types/auth-service-container.d.ts +0 -14
- package/dist/src/shared/constants/index.d.ts +0 -1
- package/dist/src/shared/constants/jwt-algorithms.d.ts +0 -17
- package/dist/src/shared/constants/jwt-algorithms.js +0 -23
- package/dist/src/shared/encoders/base64-url-encoder.d.ts +0 -29
- package/dist/src/shared/encoders/base64-url-encoder.js +0 -45
- package/dist/src/shared/encoders/index.d.ts +0 -1
- package/dist/src/shared/encoders/index.js +0 -17
- package/dist/src/shared/index.d.ts +0 -4
- package/dist/src/shared/index.js +0 -20
- package/dist/src/shared/types/index.d.ts +0 -1
- package/dist/src/shared/types/jwt.d.ts +0 -25
- package/dist/src/shared/types/jwt.js +0 -2
- package/dist/src/shared/types/jwt.types.d.ts +0 -39
- package/dist/src/shared/types/jwt.types.js +0 -2
- package/dist/tests/application/factory/auth-service-factory.spec.d.ts +0 -1
- package/dist/tests/application/factory/auth-service-factory.spec.js +0 -97
- package/dist/tests/application/use-cases/login-with-password.integration.spec.d.ts +0 -1
- package/dist/tests/application/use-cases/login-with-password.integration.spec.js +0 -140
- package/dist/tests/application/use-cases/logout-use-case.spec.d.ts +0 -1
- package/dist/tests/application/use-cases/logout-use-case.spec.js +0 -40
- package/dist/tests/application/use-cases/refresh-token-use-case.spec.d.ts +0 -1
- package/dist/tests/application/use-cases/refresh-token-use-case.spec.js +0 -116
- package/dist/tests/application/use-cases/register-user.usecase.spec.d.ts +0 -1
- package/dist/tests/application/use-cases/register-user.usecase.spec.js +0 -151
- package/dist/tests/domain/entities/credential.spec.d.ts +0 -1
- package/dist/tests/domain/entities/credential.spec.js +0 -93
- package/dist/tests/domain/entities/user.spec.d.ts +0 -1
- package/dist/tests/domain/entities/user.spec.js +0 -93
- package/dist/tests/domain/object-values/email.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/email.spec.js +0 -77
- package/dist/tests/domain/object-values/hashed-password.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/hashed-password.spec.js +0 -54
- package/dist/tests/domain/object-values/id.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/id.spec.js +0 -48
- package/dist/tests/domain/object-values/permission.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/permission.spec.js +0 -75
- package/dist/tests/domain/object-values/role.spec.d.ts +0 -1
- package/dist/tests/domain/object-values/role.spec.js +0 -139
- package/dist/tests/domain/services/default-password-policy.spec.d.ts +0 -1
- package/dist/tests/domain/services/default-password-policy.spec.js +0 -69
- package/dist/tests/doman/entities/credential.spec.d.ts +0 -1
- package/dist/tests/doman/entities/credential.spec.js +0 -93
- package/dist/tests/doman/entities/user.spec.d.ts +0 -1
- package/dist/tests/doman/entities/user.spec.js +0 -93
- package/dist/tests/doman/object-values/email.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/email.spec.js +0 -77
- package/dist/tests/doman/object-values/hashed-password.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/hashed-password.spec.js +0 -54
- package/dist/tests/doman/object-values/id.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/id.spec.js +0 -48
- package/dist/tests/doman/object-values/permission.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/permission.spec.js +0 -75
- package/dist/tests/doman/object-values/role.spec.d.ts +0 -1
- package/dist/tests/doman/object-values/role.spec.js +0 -139
- package/dist/tests/helpers/make-jwt-subject.d.ts +0 -7
- package/dist/tests/helpers/make-jwt-subject.js +0 -16
- package/dist/tests/helpers/make-jwt-user.d.ts +0 -7
- package/dist/tests/helpers/make-jwt-user.js +0 -16
- package/dist/tests/helpers/make-user.d.ts +0 -2
- package/dist/tests/helpers/make-user.js +0 -15
- package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.js +0 -127
- package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.js +0 -157
- package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.js +0 -150
- package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.js +0 -156
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.js +0 -179
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.js +0 -142
- package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.js +0 -125
- package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.js +0 -116
- package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.js +0 -88
- package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.js +0 -126
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.js +0 -116
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.d.ts +0 -1
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.js +0 -88
- package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.d.ts +0 -1
- package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.js +0 -37
- package/dist/tests/infrastructure/services/jwt-token-service.spec.d.ts +0 -1
- package/dist/tests/infrastructure/services/jwt-token-service.spec.js +0 -145
- package/dist/tests/infrastructure/services/token-session.service.spec.d.ts +0 -1
- package/dist/tests/infrastructure/services/token-session.service.spec.js +0 -269
- package/dist/tests/shared/constants/jwt-algorithms.spec.d.ts +0 -1
- package/dist/tests/shared/constants/jwt-algorithms.spec.js +0 -27
- package/dist/tests/shared/encoders/base64-url-encoder.spec.d.ts +0 -1
- package/dist/tests/shared/encoders/base64-url-encoder.spec.js +0 -70
- package/dist/tests/shared/utils/time-parser.spec.d.ts +0 -1
- package/dist/tests/shared/utils/time-parser.spec.js +0 -80
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -17
- package/dist/utils/time-parser.d.ts +0 -28
- package/dist/utils/time-parser.js +0 -76
- /package/dist/{src/application/dtos/login.dto.js → application/dtos/request/login.request.js} +0 -0
- /package/dist/{src/application/dtos/logout.dto.js → application/dtos/request/logout.request.js} +0 -0
- /package/dist/{src/application/dtos/refresh-token.dto.js → application/dtos/request/refresh-token.request.js} +0 -0
- /package/dist/{src/application/dtos/register-user.dto.js → application/dtos/request/register-user.request.js} +0 -0
- /package/dist/{src/domain/ports/auth/password-hasher.js → application/dtos/response/login.response.js} +0 -0
- /package/dist/{src/domain/ports/auth/password-policy.port.js → application/dtos/response/logout.response.js} +0 -0
- /package/dist/{src/domain/ports/jwt/factory/signature-strategy-factory.port.js → application/dtos/response/refresh-token.response.js} +0 -0
- /package/dist/{src/domain/ports/jwt/payload/jwt-payload.port.js → application/dtos/response/register-user.response.js} +0 -0
- /package/dist/{src/domain/ports/jwt/signature-strategy-factory.port.js → application/dtos/type/user-role.type.js} +0 -0
- /package/dist/{src/application → application}/factories/index.d.ts +0 -0
- /package/dist/{src/application → application}/factories/index.js +0 -0
- /package/dist/{src/domain/ports/repository/credential.repository.js → application/types/auth-service-factory-options.type.js} +0 -0
- /package/dist/{src/application → application}/use-cases/index.d.ts +0 -0
- /package/dist/{src/application → application}/use-cases/index.js +0 -0
- /package/dist/{src/domain → domain}/entities/credential.entity.d.ts +0 -0
- /package/dist/{src/domain → domain}/entities/credential.entity.js +0 -0
- /package/dist/{src/domain → domain}/entities/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/entities/index.js +0 -0
- /package/dist/{src/domain → domain}/entities/user.entity.d.ts +0 -0
- /package/dist/{src/domain → domain}/entities/user.entity.js +0 -0
- /package/dist/{src/domain → domain}/errors/identity.errors.d.ts +0 -0
- /package/dist/{src/domain → domain}/errors/identity.errors.js +0 -0
- /package/dist/{src/domain → domain}/errors/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/errors/index.js +0 -0
- /package/dist/{src/domain → domain}/object-values/email.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/email.js +0 -0
- /package/dist/{src/domain → domain}/object-values/hashed-password.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/hashed-password.js +0 -0
- /package/dist/{src/domain → domain}/object-values/id.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/id.js +0 -0
- /package/dist/{src/domain → domain}/object-values/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/index.js +0 -0
- /package/dist/{src/domain → domain}/object-values/permission.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/permission.js +0 -0
- /package/dist/{src/domain → domain}/object-values/role.d.ts +0 -0
- /package/dist/{src/domain → domain}/object-values/role.js +0 -0
- /package/dist/{src/domain/ports/repository/user.repository.js → domain/ports/auth/password-hasher.port.js} +0 -0
- /package/dist/{src/domain/ports/token/token-session.port.js → domain/ports/auth/password-policy.port.js} +0 -0
- /package/dist/{src/domain → domain}/ports/jwt/payload/jwt-payload.port.d.ts +0 -0
- /package/dist/{src/domain/ports/token/token.service.port.js → domain/ports/jwt/payload/jwt-payload.port.js} +0 -0
- /package/dist/{src/domain/props/entities/credential.props.js → domain/ports/repository/credential.repository.js} +0 -0
- /package/dist/{src/domain/props/entities/user.props.js → domain/ports/repository/user-repository.port.js} +0 -0
- /package/dist/{src/domain/props/jwt/create-payload.props.js → domain/ports/token/token-session.port.js} +0 -0
- /package/dist/{src/domain/services → domain/ports/token}/token.service.port.js +0 -0
- /package/dist/{src/domain → domain}/props/entities/credential.props.d.ts +0 -0
- /package/dist/{src/domain/props/jwt/generate-access-token.props.js → domain/props/entities/credential.props.js} +0 -0
- /package/dist/{src/domain → domain}/props/entities/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/props/entities/index.js +0 -0
- /package/dist/{src/domain → domain}/props/entities/user.props.d.ts +0 -0
- /package/dist/{src/domain/props/jwt/generate-refresh-token.props.js → domain/props/entities/user.props.js} +0 -0
- /package/dist/{src/domain → domain}/props/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/props/index.js +0 -0
- /package/dist/{src/domain/props/services → domain/props/jwt}/generate-access-token.props.js +0 -0
- /package/dist/{src/domain/props/services → domain/props/jwt}/generate-refresh-token.props.js +0 -0
- /package/dist/{src/domain → domain}/props/jwt/jwt-user.d.ts +0 -0
- /package/dist/{src/domain → domain}/props/jwt/jwt-user.js +0 -0
- /package/dist/{src/domain → domain}/services/index.d.ts +0 -0
- /package/dist/{src/domain → domain}/services/index.js +0 -0
- /package/dist/{src/domain → domain}/services/password-policy.service.js +0 -0
- /package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-user.repository.js +0 -0
- /package/dist/{src/infrastructure/repositories/test → in-memory}/index.d.ts +0 -0
- /package/dist/{src/infrastructure/repositories/test → in-memory}/index.js +0 -0
- /package/dist/{src/domain/ports/auth/password-policy-config.port.d.ts → infrastructure/index.d.ts} +0 -0
- /package/dist/{src/infrastructure → infrastructure}/security/index.d.ts +0 -0
- /package/dist/{src/infrastructure → infrastructure}/security/index.js +0 -0
- /package/dist/{src/infrastructure → infrastructure}/types/auth-service-container.js +0 -0
- /package/dist/{src/infrastructure → infrastructure}/types/index.d.ts +0 -0
- /package/dist/{src/infrastructure → infrastructure}/types/index.js +0 -0
- /package/dist/{src/shared → shared}/utils/index.d.ts +0 -0
- /package/dist/{src/shared → shared}/utils/index.js +0 -0
- /package/dist/{src/shared → shared}/utils/time-parser.d.ts +0 -0
- /package/dist/{src/shared → shared}/utils/time-parser.js +0 -0
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const errors_1 = require("../../../src/domain/errors");
|
|
4
|
-
const id_1 = require("../../../src/domain/object-values/id");
|
|
5
|
-
describe("Id (Value Object)", () => {
|
|
6
|
-
describe("constructor", () => {
|
|
7
|
-
it.each([null, undefined, "", " "])("lanza error si id es inválido (%p)", (invalid) => {
|
|
8
|
-
expect(() => new id_1.Id(invalid)).toThrowError(new errors_1.InvalidIdError("User ID cannot be empty"));
|
|
9
|
-
});
|
|
10
|
-
it("trimea espacios y guarda el valor limpio", () => {
|
|
11
|
-
const id = new id_1.Id(" user-123 ");
|
|
12
|
-
expect(id.getValue()).toBe("user-123");
|
|
13
|
-
expect(id.toString()).toBe("user-123");
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
describe("equals", () => {
|
|
17
|
-
it("retorna true para Id con mismo valor", () => {
|
|
18
|
-
const a = new id_1.Id("abc123");
|
|
19
|
-
const b = new id_1.Id("abc123");
|
|
20
|
-
expect(a.equals(b)).toBe(true);
|
|
21
|
-
});
|
|
22
|
-
it("retorna false para Id con valores diferentes", () => {
|
|
23
|
-
const a = new id_1.Id("abc123");
|
|
24
|
-
const b = new id_1.Id("xyz789");
|
|
25
|
-
expect(a.equals(b)).toBe(false);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
describe("generate", () => {
|
|
29
|
-
it("crea un Id válido no vacío", () => {
|
|
30
|
-
const id = id_1.Id.generate();
|
|
31
|
-
const value = id.getValue();
|
|
32
|
-
expect(typeof value).toBe("string");
|
|
33
|
-
expect(value.length).toBeGreaterThan(0);
|
|
34
|
-
expect(id).toBeInstanceOf(id_1.Id);
|
|
35
|
-
});
|
|
36
|
-
it("genera IDs distintos en llamadas separadas", () => {
|
|
37
|
-
const id1 = id_1.Id.generate().getValue();
|
|
38
|
-
const id2 = id_1.Id.generate().getValue();
|
|
39
|
-
expect(id1).not.toBe(id2);
|
|
40
|
-
});
|
|
41
|
-
it("el formato incluye timestamp y parte aleatoria", () => {
|
|
42
|
-
const id = id_1.Id.generate().getValue();
|
|
43
|
-
const [timestamp, random] = id.split("-");
|
|
44
|
-
expect(!isNaN(Number(timestamp))).toBe(true);
|
|
45
|
-
expect(random).toMatch(/^[a-z0-9]+$/);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const errors_1 = require("../../../src/domain/errors");
|
|
4
|
-
const permission_1 = require("../../../src/domain/object-values/permission");
|
|
5
|
-
describe("Permission (Value Object)", () => {
|
|
6
|
-
describe("constructor/crear", () => {
|
|
7
|
-
it.each([null, undefined])("lanza si es %p", (input) => {
|
|
8
|
-
expect(() => new permission_1.Permission(input)).toThrow(new errors_1.InvalidPermissionError("Permission cannot be null or undefined"));
|
|
9
|
-
});
|
|
10
|
-
it("lanza si no es string", () => {
|
|
11
|
-
expect(() => new permission_1.Permission(123)).toThrow(new errors_1.InvalidPermissionError("Permission must be a string"));
|
|
12
|
-
});
|
|
13
|
-
it("lanza si está vacío tras trim", () => {
|
|
14
|
-
expect(() => new permission_1.Permission(" ")).toThrow(new errors_1.InvalidPermissionError("Permission cannot be empty"));
|
|
15
|
-
});
|
|
16
|
-
it("normaliza a minúsculas y trim", () => {
|
|
17
|
-
const p = new permission_1.Permission(" READ:Users ");
|
|
18
|
-
expect(p.getValue()).toBe("read:users");
|
|
19
|
-
expect(p.toString()).toBe("read:users");
|
|
20
|
-
});
|
|
21
|
-
it("create es un alias del constructor", () => {
|
|
22
|
-
const p = permission_1.Permission.create("Write:Posts");
|
|
23
|
-
expect(p.getValue()).toBe("write:posts");
|
|
24
|
-
expect(p).toBeInstanceOf(permission_1.Permission);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
describe("equals", () => {
|
|
28
|
-
it("compara por valor normalizado", () => {
|
|
29
|
-
const a = new permission_1.Permission("read:users");
|
|
30
|
-
const b = new permission_1.Permission("READ:USERS");
|
|
31
|
-
const c = new permission_1.Permission("read:posts");
|
|
32
|
-
expect(a.equals(b)).toBe(true);
|
|
33
|
-
expect(a.equals(c)).toBe(false);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
describe("isWildcard", () => {
|
|
37
|
-
it("true solo para '*'", () => {
|
|
38
|
-
expect(new permission_1.Permission("*").isWildcard()).toBe(true);
|
|
39
|
-
expect(new permission_1.Permission("read:*").isWildcard()).toBe(false);
|
|
40
|
-
expect(new permission_1.Permission("read:users").isWildcard()).toBe(false);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
describe("matches", () => {
|
|
44
|
-
it("comodín total '*' hace match con cualquier target", () => {
|
|
45
|
-
const p = new permission_1.Permission("*");
|
|
46
|
-
expect(p.matches("read:users")).toBe(true);
|
|
47
|
-
expect(p.matches("WRITE:POSTS")).toBe(true);
|
|
48
|
-
});
|
|
49
|
-
it("match exacto", () => {
|
|
50
|
-
const p = new permission_1.Permission("read:users");
|
|
51
|
-
expect(p.matches("read:users")).toBe(true);
|
|
52
|
-
expect(p.matches("READ:USERS")).toBe(true); // case-insensitive en target
|
|
53
|
-
expect(p.matches("read:posts")).toBe(false);
|
|
54
|
-
});
|
|
55
|
-
it("prefijo 'read:*' coincide con 'read:algo'", () => {
|
|
56
|
-
const p = new permission_1.Permission("read:*");
|
|
57
|
-
expect(p.matches("read:users")).toBe(true);
|
|
58
|
-
expect(p.matches("read:posts")).toBe(true);
|
|
59
|
-
expect(p.matches("write:users")).toBe(false);
|
|
60
|
-
});
|
|
61
|
-
it("no coincide cuando el prefijo no aplica", () => {
|
|
62
|
-
const p = new permission_1.Permission("admin:*");
|
|
63
|
-
expect(p.matches("admin")).toBe(false); // requiere 'admin:...'
|
|
64
|
-
expect(p.matches("administrator:users")).toBe(false);
|
|
65
|
-
});
|
|
66
|
-
it("target inválido (no string o vacío) devuelve false", () => {
|
|
67
|
-
const p = new permission_1.Permission("read:*");
|
|
68
|
-
expect(p.matches("")).toBe(false);
|
|
69
|
-
expect(p.matches(" ")).toBe(false);
|
|
70
|
-
expect(p.matches(null)).toBe(false);
|
|
71
|
-
expect(p.matches(undefined)).toBe(false);
|
|
72
|
-
expect(p.matches(123)).toBe(false);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const errors_1 = require("../../../src/domain/errors");
|
|
4
|
-
const permission_1 = require("../../../src/domain/object-values/permission");
|
|
5
|
-
const role_1 = require("../../../src/domain/object-values/role");
|
|
6
|
-
describe("Role (Value Object)", () => {
|
|
7
|
-
const P = {
|
|
8
|
-
READ_USERS: permission_1.Permission.create("read:users"),
|
|
9
|
-
READ_ANY: permission_1.Permission.create("read:*"),
|
|
10
|
-
WRITE_POSTS: permission_1.Permission.create("write:posts"),
|
|
11
|
-
STAR: permission_1.Permission.create("*"),
|
|
12
|
-
};
|
|
13
|
-
describe("constructor & validRoles", () => {
|
|
14
|
-
it.each([null, undefined])("lanza si role es %p", (input) => {
|
|
15
|
-
expect(() => new role_1.Role(input)).toThrow(new errors_1.InvalidRoleError("Role cannot be null or undefined"));
|
|
16
|
-
});
|
|
17
|
-
it("lanza si role no es string", () => {
|
|
18
|
-
// @ts-expect-error (intencional para probar runtime)
|
|
19
|
-
expect(() => new role_1.Role(123)).toThrow(new errors_1.InvalidRoleError("Role must be a string"));
|
|
20
|
-
});
|
|
21
|
-
it("lanza si role está vacío tras trim", () => {
|
|
22
|
-
expect(() => new role_1.Role(" ")).toThrow(new errors_1.InvalidRoleError("Role cannot be empty"));
|
|
23
|
-
});
|
|
24
|
-
it("acepta cualquier role no vacío cuando no se provee validRoles", () => {
|
|
25
|
-
const r = new role_1.Role(" Admin ");
|
|
26
|
-
expect(r.toString()).toBe("admin");
|
|
27
|
-
});
|
|
28
|
-
it("valida role contra validRoles (case-insensitive) y lanza si no está incluido", () => {
|
|
29
|
-
expect(() => new role_1.Role("manager", [], ["Admin", "User"])).toThrow(new errors_1.InvalidRoleError("Invalid role: manager. Valid roles are: Admin, User"));
|
|
30
|
-
});
|
|
31
|
-
it("valida role contra validRoles (case-insensitive) y permite si está incluido", () => {
|
|
32
|
-
const r = new role_1.Role("ADMIN", [], ["admin", "user"]);
|
|
33
|
-
expect(r.toString()).toBe("admin");
|
|
34
|
-
});
|
|
35
|
-
it("lanza si algún validRole no es string", () => {
|
|
36
|
-
expect(() => new role_1.Role("admin", [], ["user", null])).toThrow(new errors_1.InvalidRoleError("Valid roles must be strings"));
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
describe("permissions input", () => {
|
|
40
|
-
it("lanza si algún permission no es instancia de Permission", () => {
|
|
41
|
-
expect(() => new role_1.Role("admin", [P.READ_USERS, "write:posts"])).toThrow(new errors_1.InvalidPermissionError("Permissions must be Permission instances"));
|
|
42
|
-
});
|
|
43
|
-
it("almacena permisos normalizados y sin duplicados", () => {
|
|
44
|
-
const r = new role_1.Role("admin", [
|
|
45
|
-
permission_1.Permission.create("READ:USERS"),
|
|
46
|
-
permission_1.Permission.create("read:users"),
|
|
47
|
-
]);
|
|
48
|
-
const { permissions } = r.getValue();
|
|
49
|
-
// Un solo elemento y normalizado
|
|
50
|
-
expect(permissions).toEqual(["read:users"]);
|
|
51
|
-
});
|
|
52
|
-
it("getPermissions devuelve nuevas instancias de Permission", () => {
|
|
53
|
-
const r = new role_1.Role("admin", [P.READ_USERS, P.WRITE_POSTS]);
|
|
54
|
-
const perms = r.getPermissions();
|
|
55
|
-
expect(perms).toHaveLength(2);
|
|
56
|
-
expect(perms[0]).toBeInstanceOf(permission_1.Permission);
|
|
57
|
-
expect(perms.map((p) => p.getValue())).toEqual(expect.arrayContaining(["read:users", "write:posts"]));
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
describe("consultas de permisos", () => {
|
|
61
|
-
it("hasPermission true para match exacto (string y Permission)", () => {
|
|
62
|
-
const r = new role_1.Role("user", [P.READ_USERS]);
|
|
63
|
-
expect(r.hasPermission("read:users")).toBe(true);
|
|
64
|
-
expect(r.hasPermission(permission_1.Permission.create("READ:USERS"))).toBe(true);
|
|
65
|
-
expect(r.hasPermission("read:posts")).toBe(false);
|
|
66
|
-
});
|
|
67
|
-
it("soporta comodín total '*'", () => {
|
|
68
|
-
const r = new role_1.Role("user", [P.STAR]);
|
|
69
|
-
expect(r.hasPermission("cualquier:cosa")).toBe(true);
|
|
70
|
-
expect(r.hasPermission("otra")).toBe(true);
|
|
71
|
-
});
|
|
72
|
-
it("soporta prefijo 'read:*'", () => {
|
|
73
|
-
const r = new role_1.Role("user", [P.READ_ANY]);
|
|
74
|
-
expect(r.hasPermission("read:users")).toBe(true);
|
|
75
|
-
expect(r.hasPermission("read:posts")).toBe(true);
|
|
76
|
-
expect(r.hasPermission("write:users")).toBe(false);
|
|
77
|
-
});
|
|
78
|
-
it("hasAnyPermission true si al menos uno coincide", () => {
|
|
79
|
-
const r = new role_1.Role("user", [P.READ_USERS]);
|
|
80
|
-
expect(r.hasAnyPermission(["read:posts", "read:users"])).toBe(true);
|
|
81
|
-
expect(r.hasAnyPermission(["write:posts", "write:users"])).toBe(false);
|
|
82
|
-
});
|
|
83
|
-
it("hasAllPermissions true si todos coinciden", () => {
|
|
84
|
-
const r = new role_1.Role("user", [P.READ_USERS, P.WRITE_POSTS]);
|
|
85
|
-
expect(r.hasAllPermissions(["read:users", "write:posts"])).toBe(true);
|
|
86
|
-
expect(r.hasAllPermissions(["read:users", "write:users"])).toBe(false);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
describe("utilidades y estáticos", () => {
|
|
90
|
-
it("equals compara por nombre normalizado", () => {
|
|
91
|
-
const a = new role_1.Role("ADMIN");
|
|
92
|
-
const b = new role_1.Role("admin");
|
|
93
|
-
const c = new role_1.Role("user");
|
|
94
|
-
expect(a.equals(b)).toBe(true);
|
|
95
|
-
expect(a.equals(c)).toBe(false);
|
|
96
|
-
});
|
|
97
|
-
it("hasRole es case-insensitive", () => {
|
|
98
|
-
const r = new role_1.Role("manager");
|
|
99
|
-
expect(r.hasRole(" MANAGER ")).toBe(true);
|
|
100
|
-
expect(r.hasRole("user")).toBe(false);
|
|
101
|
-
});
|
|
102
|
-
it("toString devuelve el nombre del rol", () => {
|
|
103
|
-
expect(new role_1.Role("Admin").toString()).toBe("admin");
|
|
104
|
-
});
|
|
105
|
-
it("create crea sin validRoles, withValidRoles valida", () => {
|
|
106
|
-
const a = role_1.Role.create("User", [P.READ_USERS]);
|
|
107
|
-
expect(a.getValue()).toEqual({
|
|
108
|
-
role: "user",
|
|
109
|
-
permissions: ["read:users"],
|
|
110
|
-
});
|
|
111
|
-
const b = role_1.Role.withValidRoles("User", [P.READ_USERS], ["admin", "user"]);
|
|
112
|
-
expect(b.getValuePublic()).toEqual({ role: "user" });
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
describe("withPermissions y canPerform", () => {
|
|
116
|
-
it("withPermissions retorna un NUEVO Role sin mutar el original", () => {
|
|
117
|
-
const base = new role_1.Role("user", [P.READ_USERS]);
|
|
118
|
-
const added = base.withPermissions([P.WRITE_POSTS]);
|
|
119
|
-
// original intacto
|
|
120
|
-
expect(base.getValue().permissions).toEqual(["read:users"]);
|
|
121
|
-
// nuevo con ambos
|
|
122
|
-
expect(added.getValue().permissions).toEqual(expect.arrayContaining(["read:users", "write:posts"]));
|
|
123
|
-
// y siguen sin duplicados si se repiten
|
|
124
|
-
const again = added.withPermissions([permission_1.Permission.create("WRITE:POSTS")]);
|
|
125
|
-
expect(again.getValue().permissions).toEqual(expect.arrayContaining(["read:users", "write:posts"]));
|
|
126
|
-
expect(again.getValue().permissions).toHaveLength(2);
|
|
127
|
-
});
|
|
128
|
-
it("canPerform(action) delega a hasPermission con acción simple", () => {
|
|
129
|
-
const r = new role_1.Role("user", [permission_1.Permission.create("export")]);
|
|
130
|
-
expect(r.canPerform("export")).toBe(true);
|
|
131
|
-
expect(r.canPerform("import")).toBe(false);
|
|
132
|
-
});
|
|
133
|
-
it("canPerform(action, resource) compone 'action:resource'", () => {
|
|
134
|
-
const r = new role_1.Role("user", [permission_1.Permission.create("read:*")]);
|
|
135
|
-
expect(r.canPerform("read", "users")).toBe(true);
|
|
136
|
-
expect(r.canPerform("write", "users")).toBe(false);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const domain_1 = require("src/domain");
|
|
4
|
-
describe("DefaultPasswordPolicy", () => {
|
|
5
|
-
let policy;
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
policy = new domain_1.DefaultPasswordPolicy();
|
|
8
|
-
});
|
|
9
|
-
it("debe aceptar una contraseña que cumple todos los requisitos", () => {
|
|
10
|
-
const password = "Str0ng!Pass";
|
|
11
|
-
const result = policy.validateStrength(password);
|
|
12
|
-
expect(result.isValid).toBe(true);
|
|
13
|
-
expect(result.errors).toHaveLength(0);
|
|
14
|
-
});
|
|
15
|
-
it("debe rechazar contraseñas demasiado cortas", () => {
|
|
16
|
-
const password = "S1!aB"; // < 8
|
|
17
|
-
const result = policy.validateStrength(password);
|
|
18
|
-
expect(result.isValid).toBe(false);
|
|
19
|
-
expect(result.errors).toContain("Password must be at least 8 characters long");
|
|
20
|
-
});
|
|
21
|
-
it("debe rechazar contraseñas sin mayúsculas", () => {
|
|
22
|
-
const password = "str0ng!pass";
|
|
23
|
-
const result = policy.validateStrength(password);
|
|
24
|
-
expect(result.isValid).toBe(false);
|
|
25
|
-
expect(result.errors).toContain("Password must include at least one uppercase letter");
|
|
26
|
-
});
|
|
27
|
-
it("debe rechazar contraseñas sin minúsculas", () => {
|
|
28
|
-
const password = "STR0NG!PASS";
|
|
29
|
-
const result = policy.validateStrength(password);
|
|
30
|
-
expect(result.isValid).toBe(false);
|
|
31
|
-
expect(result.errors).toContain("Password must include at least one lowercase letter");
|
|
32
|
-
});
|
|
33
|
-
it("debe rechazar contraseñas sin número", () => {
|
|
34
|
-
const password = "Strong!Pass";
|
|
35
|
-
const result = policy.validateStrength(password);
|
|
36
|
-
expect(result.isValid).toBe(false);
|
|
37
|
-
expect(result.errors).toContain("Password must include at least one number");
|
|
38
|
-
});
|
|
39
|
-
it("debe rechazar contraseñas sin carácter especial", () => {
|
|
40
|
-
const password = "Str0ngPass";
|
|
41
|
-
const result = policy.validateStrength(password);
|
|
42
|
-
expect(result.isValid).toBe(false);
|
|
43
|
-
expect(result.errors).toContain("Password must include at least one special character (!@#$%^&*)");
|
|
44
|
-
});
|
|
45
|
-
it("debe reportar múltiples errores si faltan varias reglas", () => {
|
|
46
|
-
const password = "short"; // corto, sin mayúscula, sin número, sin especial
|
|
47
|
-
const result = policy.validateStrength(password);
|
|
48
|
-
expect(result.isValid).toBe(false);
|
|
49
|
-
// esperar al menos 3 errores: length, uppercase, number, special, lowercase may also fail depending on input
|
|
50
|
-
expect(result.errors.length).toBeGreaterThanOrEqual(3);
|
|
51
|
-
expect(result.errors).toEqual(expect.arrayContaining([
|
|
52
|
-
"Password must be at least 8 characters long",
|
|
53
|
-
"Password must include at least one uppercase letter",
|
|
54
|
-
"Password must include at least one number",
|
|
55
|
-
"Password must include at least one special character (!@#$%^&*)",
|
|
56
|
-
]));
|
|
57
|
-
});
|
|
58
|
-
it("getRequirements debe devolver la lista de requisitos legible", () => {
|
|
59
|
-
const req = policy.getRequirements();
|
|
60
|
-
expect(Array.isArray(req)).toBe(true);
|
|
61
|
-
expect(req).toEqual(expect.arrayContaining([
|
|
62
|
-
"Minimum 8 characters",
|
|
63
|
-
"At least one uppercase letter",
|
|
64
|
-
"At least one lowercase letter",
|
|
65
|
-
"At least one number",
|
|
66
|
-
"At least one special character (!@#$%^&*)",
|
|
67
|
-
]));
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const credential_entity_1 = require("../../../src/domain/entities/credential.entity");
|
|
4
|
-
const object_values_1 = require("../../../src/domain/object-values");
|
|
5
|
-
describe("Credential", () => {
|
|
6
|
-
const ACCESS = "access.jwt.token.mock";
|
|
7
|
-
const REFRESH = "refresh.jwt.token.mock";
|
|
8
|
-
beforeAll(() => {
|
|
9
|
-
// Controlamos el tiempo del sistema para pruebas deterministas
|
|
10
|
-
jest.useFakeTimers();
|
|
11
|
-
});
|
|
12
|
-
afterAll(() => {
|
|
13
|
-
// Restauramos el tiempo real
|
|
14
|
-
jest.useRealTimers();
|
|
15
|
-
});
|
|
16
|
-
test("create(): crea credenciales válidas con timestamps correctos", () => {
|
|
17
|
-
const now = new Date("2025-01-01T10:00:00.000Z");
|
|
18
|
-
jest.setSystemTime(now);
|
|
19
|
-
const userId = new object_values_1.Id("user-123");
|
|
20
|
-
const expiresAt = new Date(now.getTime() + 60 * 60 * 1000); // +1h
|
|
21
|
-
const cred = credential_entity_1.Credential.create(userId, ACCESS, REFRESH, expiresAt);
|
|
22
|
-
expect(cred.userId.equals(userId)).toBe(true);
|
|
23
|
-
expect(cred.accessToken).toBe(ACCESS);
|
|
24
|
-
expect(cred.refreshToken).toBe(REFRESH);
|
|
25
|
-
// createdAt debe ser ~ now, y expiresAt exactamente el pasado
|
|
26
|
-
expect(cred.createdAt.toISOString()).toBe(now.toISOString());
|
|
27
|
-
expect(cred.expiresAt.toISOString()).toBe(expiresAt.toISOString());
|
|
28
|
-
// Estado
|
|
29
|
-
expect(cred.isExpired()).toBe(false);
|
|
30
|
-
expect(cred.isValid()).toBe(true);
|
|
31
|
-
});
|
|
32
|
-
test("isExpired(): expira cuando now > expiresAt", () => {
|
|
33
|
-
const base = new Date("2025-01-01T10:00:00.000Z");
|
|
34
|
-
const expires = new Date("2025-01-01T10:10:00.000Z");
|
|
35
|
-
jest.setSystemTime(base);
|
|
36
|
-
const cred = credential_entity_1.Credential.create(new object_values_1.Id("u-1"), ACCESS, REFRESH, expires);
|
|
37
|
-
// Antes de expirar
|
|
38
|
-
jest.setSystemTime(new Date("2025-01-01T10:09:59.000Z"));
|
|
39
|
-
expect(cred.isExpired()).toBe(false);
|
|
40
|
-
expect(cred.isValid()).toBe(true);
|
|
41
|
-
// Justo en el borde (now === expiresAt) → NO está expirado (usa >, no >=)
|
|
42
|
-
jest.setSystemTime(new Date("2025-01-01T10:10:00.000Z"));
|
|
43
|
-
expect(cred.isExpired()).toBe(false);
|
|
44
|
-
expect(cred.isValid()).toBe(true);
|
|
45
|
-
// Después de expirar
|
|
46
|
-
jest.setSystemTime(new Date("2025-01-01T10:10:01.000Z"));
|
|
47
|
-
expect(cred.isExpired()).toBe(true);
|
|
48
|
-
expect(cred.isValid()).toBe(false);
|
|
49
|
-
});
|
|
50
|
-
test("getters de Date devuelven copias (no exponen estado interno)", () => {
|
|
51
|
-
const now = new Date("2025-01-01T12:00:00.000Z");
|
|
52
|
-
jest.setSystemTime(now);
|
|
53
|
-
const expires = new Date(now.getTime() + 5 * 60 * 1000); // +5m
|
|
54
|
-
const cred = credential_entity_1.Credential.create(new object_values_1.Id("u-2"), ACCESS, REFRESH, expires);
|
|
55
|
-
const createdAtCopy = cred.createdAt;
|
|
56
|
-
const expiresAtCopy = cred.expiresAt;
|
|
57
|
-
// Mutamos las copias
|
|
58
|
-
createdAtCopy.setFullYear(1999);
|
|
59
|
-
expiresAtCopy.setFullYear(1999);
|
|
60
|
-
// El estado interno debe mantenerse intacto
|
|
61
|
-
expect(cred.createdAt.toISOString()).toBe(now.toISOString());
|
|
62
|
-
expect(cred.expiresAt.toISOString()).toBe(expires.toISOString());
|
|
63
|
-
});
|
|
64
|
-
test("reconstitute(): reconstruye desde props sin alterar valores", () => {
|
|
65
|
-
const propsNow = new Date("2025-02-02T08:00:00.000Z");
|
|
66
|
-
const propsExp = new Date("2025-02-02T09:00:00.000Z");
|
|
67
|
-
const userId = new object_values_1.Id("user-xyz");
|
|
68
|
-
const cred = credential_entity_1.Credential.reconstitute({
|
|
69
|
-
userId,
|
|
70
|
-
accessToken: ACCESS,
|
|
71
|
-
refreshToken: REFRESH,
|
|
72
|
-
createdAt: propsNow,
|
|
73
|
-
expiresAt: propsExp,
|
|
74
|
-
});
|
|
75
|
-
expect(cred.userId.equals(userId)).toBe(true);
|
|
76
|
-
expect(cred.accessToken).toBe(ACCESS);
|
|
77
|
-
expect(cred.refreshToken).toBe(REFRESH);
|
|
78
|
-
expect(cred.createdAt.toISOString()).toBe(propsNow.toISOString());
|
|
79
|
-
expect(cred.expiresAt.toISOString()).toBe(propsExp.toISOString());
|
|
80
|
-
expect(cred.isExpired()).toBe(false);
|
|
81
|
-
expect(cred.isValid()).toBe(true);
|
|
82
|
-
});
|
|
83
|
-
test("soporta IDs generados", () => {
|
|
84
|
-
const id = object_values_1.Id.generate();
|
|
85
|
-
const exp = new Date(Date.now() + 1000);
|
|
86
|
-
const cred = credential_entity_1.Credential.create(id, ACCESS, REFRESH, exp);
|
|
87
|
-
// Simple smoke tests
|
|
88
|
-
expect(typeof cred.userId.getValue).toBe("function");
|
|
89
|
-
expect(cred.accessToken).toBe(ACCESS);
|
|
90
|
-
expect(cred.refreshToken).toBe(REFRESH);
|
|
91
|
-
expect(cred.isValid()).toBe(true);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const domain_1 = require("src/domain");
|
|
4
|
-
describe("User (Entity)", () => {
|
|
5
|
-
// Genera la cola EXACTA de 53 caracteres válidos para bcrypt
|
|
6
|
-
const makeBcrypt = (cost = 10) => `$2b$${String(cost).padStart(2, "0")}$${"A".repeat(53)}`;
|
|
7
|
-
let mockId;
|
|
8
|
-
let mockEmail;
|
|
9
|
-
let mockPassword;
|
|
10
|
-
let mockRole;
|
|
11
|
-
let baseDate;
|
|
12
|
-
let baseProps;
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
mockId = new domain_1.Id("user-123");
|
|
15
|
-
mockEmail = new domain_1.Email("test@example.com");
|
|
16
|
-
mockPassword = new domain_1.HashedPassword(makeBcrypt(10)); // ✅ válido: $2b$10$ + 53 chars
|
|
17
|
-
mockRole = new domain_1.Role("admin", [domain_1.Permission.create("read:*")]);
|
|
18
|
-
baseDate = new Date("2025-01-01T00:00:00.000Z");
|
|
19
|
-
baseProps = {
|
|
20
|
-
id: mockId,
|
|
21
|
-
email: mockEmail,
|
|
22
|
-
roles: [mockRole],
|
|
23
|
-
password: mockPassword,
|
|
24
|
-
isActive: true,
|
|
25
|
-
createdAt: baseDate,
|
|
26
|
-
updatedAt: baseDate,
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
describe("constructor & getters", () => {
|
|
30
|
-
it("crea correctamente una instancia con todas las propiedades", () => {
|
|
31
|
-
const user = new domain_1.User(baseProps);
|
|
32
|
-
expect(user.id).toBe(mockId);
|
|
33
|
-
expect(user.email).toBe(mockEmail);
|
|
34
|
-
expect(user.roles).toEqual([mockRole]);
|
|
35
|
-
expect(user.password).toBe(mockPassword);
|
|
36
|
-
expect(user.isActive).toBe(true);
|
|
37
|
-
expect(user.createdAt).toEqual(baseDate);
|
|
38
|
-
expect(user.updatedAt).toEqual(baseDate);
|
|
39
|
-
});
|
|
40
|
-
it("devuelve nuevas instancias de fecha (copia defensiva)", () => {
|
|
41
|
-
const user = new domain_1.User(baseProps);
|
|
42
|
-
const c1 = user.createdAt;
|
|
43
|
-
const c2 = user.createdAt;
|
|
44
|
-
const u1 = user.updatedAt;
|
|
45
|
-
const u2 = user.updatedAt;
|
|
46
|
-
expect(c1).not.toBe(c2);
|
|
47
|
-
expect(u1).not.toBe(u2);
|
|
48
|
-
expect(c1.getTime()).toBe(c2.getTime());
|
|
49
|
-
expect(u1.getTime()).toBe(u2.getTime());
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
describe("business methods", () => {
|
|
53
|
-
it("activate() cambia isActive a true y actualiza updatedAt", () => {
|
|
54
|
-
const user = new domain_1.User({ ...baseProps, isActive: false });
|
|
55
|
-
const before = user.updatedAt.getTime();
|
|
56
|
-
user.activate();
|
|
57
|
-
expect(user.isActive).toBe(true);
|
|
58
|
-
expect(user.updatedAt.getTime()).toBeGreaterThan(before);
|
|
59
|
-
});
|
|
60
|
-
it("deactivate() cambia isActive a false y actualiza updatedAt", () => {
|
|
61
|
-
const user = new domain_1.User({ ...baseProps, isActive: true });
|
|
62
|
-
const before = user.updatedAt.getTime();
|
|
63
|
-
user.deactivate();
|
|
64
|
-
expect(user.isActive).toBe(false);
|
|
65
|
-
expect(user.updatedAt.getTime()).toBeGreaterThan(before);
|
|
66
|
-
});
|
|
67
|
-
it("canLogin() refleja el estado activo", () => {
|
|
68
|
-
expect(new domain_1.User({ ...baseProps, isActive: true }).canLogin()).toBe(true);
|
|
69
|
-
expect(new domain_1.User({ ...baseProps, isActive: false }).canLogin()).toBe(false);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
describe("factory methods", () => {
|
|
73
|
-
it("create() genera valores válidos", () => {
|
|
74
|
-
const roles = [new domain_1.Role("user")];
|
|
75
|
-
const user = domain_1.User.create("person@example.com", roles, makeBcrypt(12));
|
|
76
|
-
expect(user).toBeInstanceOf(domain_1.User);
|
|
77
|
-
expect(user.id).toBeInstanceOf(domain_1.Id);
|
|
78
|
-
expect(user.email.getValue()).toBe("person@example.com");
|
|
79
|
-
expect(user.roles).toEqual(roles);
|
|
80
|
-
expect(user.password).toBeInstanceOf(domain_1.HashedPassword);
|
|
81
|
-
expect(user.isActive).toBe(true);
|
|
82
|
-
expect(user.createdAt).toBeInstanceOf(Date);
|
|
83
|
-
expect(user.updatedAt).toBeInstanceOf(Date);
|
|
84
|
-
});
|
|
85
|
-
it("reconstitute() reconstruye desde props", () => {
|
|
86
|
-
const user = domain_1.User.reconstitute(baseProps);
|
|
87
|
-
expect(user.id).toBe(mockId);
|
|
88
|
-
expect(user.email).toBe(mockEmail);
|
|
89
|
-
expect(user.roles[0]).toBe(mockRole);
|
|
90
|
-
expect(user.password).toBe(mockPassword);
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const errors_1 = require("src/domain/errors");
|
|
4
|
-
const email_1 = require("src/domain/object-values/email");
|
|
5
|
-
describe("Email Value Object", () => {
|
|
6
|
-
// 1️⃣ Casos válidos
|
|
7
|
-
describe("creación válida", () => {
|
|
8
|
-
test("crea correctamente un email bien formado", () => {
|
|
9
|
-
const email = new email_1.Email("User@Test.COM");
|
|
10
|
-
expect(email.getValue()).toBe("user@test.com");
|
|
11
|
-
});
|
|
12
|
-
test("elimina espacios al inicio y final y convierte a minúsculas", () => {
|
|
13
|
-
const email = new email_1.Email(" MyMail@Example.COM ");
|
|
14
|
-
expect(email.getValue()).toBe("mymail@example.com");
|
|
15
|
-
});
|
|
16
|
-
test("toString devuelve el mismo valor normalizado", () => {
|
|
17
|
-
const email = new email_1.Email("Example@Mail.COM");
|
|
18
|
-
expect(email.toString()).toBe("example@mail.com");
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
// 2️⃣ Casos inválidos de formato
|
|
22
|
-
describe("formato inválido", () => {
|
|
23
|
-
test("lanza InvalidEmailError si falta el símbolo '@'", () => {
|
|
24
|
-
expect(() => new email_1.Email("invalidemail.com")).toThrow(errors_1.InvalidEmailError);
|
|
25
|
-
});
|
|
26
|
-
test("lanza InvalidEmailError si falta dominio", () => {
|
|
27
|
-
expect(() => new email_1.Email("user@")).toThrow(errors_1.InvalidEmailError);
|
|
28
|
-
});
|
|
29
|
-
test("lanza InvalidEmailError si falta usuario", () => {
|
|
30
|
-
expect(() => new email_1.Email("@domain.com")).toThrow(errors_1.InvalidEmailError);
|
|
31
|
-
});
|
|
32
|
-
test("lanza InvalidEmailError si el dominio no tiene punto", () => {
|
|
33
|
-
expect(() => new email_1.Email("user@domain")).toThrow(errors_1.InvalidEmailError);
|
|
34
|
-
});
|
|
35
|
-
test("lanza InvalidEmailError si hay caracteres inválidos", () => {
|
|
36
|
-
expect(() => new email_1.Email("user@@domain.com")).toThrow(errors_1.InvalidEmailError);
|
|
37
|
-
expect(() => new email_1.Email("user domain@com")).toThrow(errors_1.InvalidEmailError);
|
|
38
|
-
});
|
|
39
|
-
test("lanza InvalidEmailError si excede 254 caracteres", () => {
|
|
40
|
-
const longLocalPart = "a".repeat(245);
|
|
41
|
-
const tooLong = `${longLocalPart}@example.com`;
|
|
42
|
-
expect(() => new email_1.Email(tooLong)).toThrow(errors_1.InvalidEmailError);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
// 3️⃣ Igualdad
|
|
46
|
-
describe("equals", () => {
|
|
47
|
-
test("devuelve true si los valores normalizados coinciden", () => {
|
|
48
|
-
const a = new email_1.Email("User@Test.com");
|
|
49
|
-
const b = new email_1.Email("user@test.com");
|
|
50
|
-
expect(a.equals(b)).toBe(true);
|
|
51
|
-
});
|
|
52
|
-
test("devuelve false si los valores son distintos", () => {
|
|
53
|
-
const a = new email_1.Email("user1@test.com");
|
|
54
|
-
const b = new email_1.Email("user2@test.com");
|
|
55
|
-
expect(a.equals(b)).toBe(false);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
// 4️⃣ Robustez ante espacios y casos mixtos
|
|
59
|
-
describe("normalización", () => {
|
|
60
|
-
test("ignora espacios extra y respeta minúsculas", () => {
|
|
61
|
-
const email = new email_1.Email(" TestUser@Example.COM ");
|
|
62
|
-
expect(email.getValue()).toBe("testuser@example.com");
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
// 5️⃣ Mensaje de error (opcional)
|
|
66
|
-
describe("mensaje de error", () => {
|
|
67
|
-
test("incluye el valor original en el mensaje del InvalidEmailError", () => {
|
|
68
|
-
try {
|
|
69
|
-
new email_1.Email("bad-email");
|
|
70
|
-
}
|
|
71
|
-
catch (err) {
|
|
72
|
-
expect(err).toBeInstanceOf(errors_1.InvalidEmailError);
|
|
73
|
-
expect(err.message).toMatch(/bad-email/);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|