@jmlq/auth 0.0.1-alpha.1 → 0.0.1-alpha.3
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 +5 -1
- package/dist/index.js +13 -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,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TokenSessionService = void 0;
|
|
4
|
-
const domain_1 = require("../../domain");
|
|
5
|
-
const shared_1 = require("../../shared");
|
|
6
|
-
/**
|
|
7
|
-
* Servicio de gestión de sesiones de usuario mediante tokens JWT.
|
|
8
|
-
* Proporciona métodos para crear, refrescar, validar y revocar sesiones.
|
|
9
|
-
*/
|
|
10
|
-
class TokenSessionService {
|
|
11
|
-
constructor(
|
|
12
|
-
// Servicio de tokens JWT
|
|
13
|
-
tokenService,
|
|
14
|
-
// Repositorio de usuarios
|
|
15
|
-
userRepository,
|
|
16
|
-
// Repositorio de credenciales
|
|
17
|
-
credentialRepository,
|
|
18
|
-
// Algoritmo JWT a usar
|
|
19
|
-
algorithm,
|
|
20
|
-
// Configuración de expiraciones y secretos
|
|
21
|
-
accessTokenExpiration = "15m", refreshTokenExpiration = "7d", accessTokenSecret, refreshTokenSecret) {
|
|
22
|
-
this.tokenService = tokenService;
|
|
23
|
-
this.userRepository = userRepository;
|
|
24
|
-
this.credentialRepository = credentialRepository;
|
|
25
|
-
this.algorithm = algorithm;
|
|
26
|
-
this.accessTokenExpiration = accessTokenExpiration;
|
|
27
|
-
this.refreshTokenExpiration = refreshTokenExpiration;
|
|
28
|
-
this.accessTokenSecret = accessTokenSecret;
|
|
29
|
-
this.refreshTokenSecret = refreshTokenSecret;
|
|
30
|
-
// Validar que los secretos estén presentes
|
|
31
|
-
if (!accessTokenSecret || !refreshTokenSecret)
|
|
32
|
-
throw new domain_1.JwtSecretError("Missing JWT secrets");
|
|
33
|
-
// Parsear las expiraciones a milisegundos
|
|
34
|
-
try {
|
|
35
|
-
this.accessMs = shared_1.TimeParser.parseToMilliseconds(accessTokenExpiration);
|
|
36
|
-
this.refreshMs = shared_1.TimeParser.parseToMilliseconds(refreshTokenExpiration);
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
throw new Error(`Invalid token expiration configuration: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
// Construir configuración JWT para generación de tokens
|
|
43
|
-
buildJwtConfig() {
|
|
44
|
-
return {
|
|
45
|
-
accessTokenExpirationMs: this.accessMs,
|
|
46
|
-
refreshTokenExpirationMs: this.refreshMs,
|
|
47
|
-
accessTokenSecret: this.accessTokenSecret,
|
|
48
|
-
refreshTokenSecret: this.refreshTokenSecret,
|
|
49
|
-
algorithm: this.algorithm,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
// Crear una nueva sesión de usuario
|
|
53
|
-
async createSession(user) {
|
|
54
|
-
const config = this.buildJwtConfig();
|
|
55
|
-
// Generar tokens
|
|
56
|
-
const accessToken = await this.tokenService.generateAccessToken({
|
|
57
|
-
user: {
|
|
58
|
-
id: user.id.toString(),
|
|
59
|
-
email: user.email.toString(),
|
|
60
|
-
roles: user.roles.map((role) => role.getValuePublic()),
|
|
61
|
-
},
|
|
62
|
-
expiresIn: this.accessTokenExpiration,
|
|
63
|
-
config,
|
|
64
|
-
});
|
|
65
|
-
// Generar refresh token
|
|
66
|
-
const refreshToken = await this.tokenService.generateRefreshToken({
|
|
67
|
-
user: {
|
|
68
|
-
id: user.id.toString(),
|
|
69
|
-
email: user.email.toString(),
|
|
70
|
-
roles: user.roles.map((role) => role.getValuePublic()),
|
|
71
|
-
},
|
|
72
|
-
expiresIn: this.refreshTokenExpiration,
|
|
73
|
-
config,
|
|
74
|
-
});
|
|
75
|
-
// Crear y guardar la credencial
|
|
76
|
-
const credential = domain_1.Credential.create(user.id, accessToken, refreshToken, new Date(Date.now() + this.accessMs));
|
|
77
|
-
// Guardar la credencial en el repositorio
|
|
78
|
-
await this.credentialRepository.save(credential);
|
|
79
|
-
// Retornar la credencial creada
|
|
80
|
-
return credential;
|
|
81
|
-
}
|
|
82
|
-
// Refrescar una sesión existente usando el refresh token
|
|
83
|
-
async refreshSession(refreshToken) {
|
|
84
|
-
// Verificar si la credencial con el refresh token existe
|
|
85
|
-
const existing = await this.credentialRepository.findByRefreshToken(refreshToken);
|
|
86
|
-
// Si no existe, lanzar error
|
|
87
|
-
if (!existing) {
|
|
88
|
-
throw new domain_1.InvalidOrExpiredRefreshTokenError();
|
|
89
|
-
}
|
|
90
|
-
// Verificar y obtener el payload del refresh token
|
|
91
|
-
const payload = await this.tokenService
|
|
92
|
-
.verifyRefreshToken(refreshToken)
|
|
93
|
-
.catch(() => {
|
|
94
|
-
throw new domain_1.InvalidOrExpiredRefreshTokenError();
|
|
95
|
-
});
|
|
96
|
-
// Obtener el usuario asociado al payload
|
|
97
|
-
const user = await this.userRepository.findById(new domain_1.Id(payload.sub));
|
|
98
|
-
// Validar que el usuario exista y pueda iniciar sesión
|
|
99
|
-
if (!user)
|
|
100
|
-
throw new domain_1.UserNotFoundError();
|
|
101
|
-
// Validar que el usuario no esté deshabilitado
|
|
102
|
-
if (!user.canLogin())
|
|
103
|
-
throw new domain_1.UserDisabledError();
|
|
104
|
-
// Crear una nueva sesión para el usuario
|
|
105
|
-
const newCredential = await this.createSession(user);
|
|
106
|
-
// Eliminar la credencial antigua asociada al refresh token
|
|
107
|
-
await this.credentialRepository.deleteByRefreshToken(refreshToken); // rotación
|
|
108
|
-
// Retornar la nueva credencial
|
|
109
|
-
return newCredential;
|
|
110
|
-
}
|
|
111
|
-
// Validar una sesión usando el access token
|
|
112
|
-
async validateSession(accessToken) {
|
|
113
|
-
try {
|
|
114
|
-
// Verificar y obtener el payload del access token
|
|
115
|
-
const payload = await this.tokenService.verifyAccessToken(accessToken);
|
|
116
|
-
// Obtener el usuario asociado al payload
|
|
117
|
-
const user = await this.userRepository.findById(new domain_1.Id(payload.sub));
|
|
118
|
-
// Retornar el usuario si existe y puede iniciar sesión, sino retornar null
|
|
119
|
-
return user && user.canLogin() ? user : null;
|
|
120
|
-
}
|
|
121
|
-
catch {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
// Revocar una sesión usando el refresh token
|
|
126
|
-
async revokeSession(refreshToken) {
|
|
127
|
-
// Eliminar la credencial asociada al refresh token
|
|
128
|
-
await this.credentialRepository.deleteByRefreshToken(refreshToken);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
exports.TokenSessionService = TokenSessionService;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { LoginWithPasswordUseCase, LogoutUseCase, RefreshTokenUseCase, RegisterUserUseCase } from "../../application";
|
|
2
|
-
import { ICredentialRepository, IPasswordHasher, IPasswordPolicy, ITokenService, ITokenSession, IUserRepository } from "../../domain";
|
|
3
|
-
export interface IAuthServiceContainer {
|
|
4
|
-
userRepository: IUserRepository;
|
|
5
|
-
credentialRepository: ICredentialRepository;
|
|
6
|
-
passwordHasher: IPasswordHasher;
|
|
7
|
-
tokenService: ITokenService;
|
|
8
|
-
passwordPolicy: IPasswordPolicy;
|
|
9
|
-
tokenSession: ITokenSession;
|
|
10
|
-
registerUserUseCase: RegisterUserUseCase;
|
|
11
|
-
loginWithPasswordUseCase: LoginWithPasswordUseCase;
|
|
12
|
-
refreshTokenUseCase: RefreshTokenUseCase;
|
|
13
|
-
logoutUseCase: LogoutUseCase;
|
|
14
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./jwt-algorithms";
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare const algorithms: {
|
|
2
|
-
readonly hmac: {
|
|
3
|
-
readonly HS256: "HS256";
|
|
4
|
-
readonly HS384: "HS384";
|
|
5
|
-
readonly HS512: "HS512";
|
|
6
|
-
};
|
|
7
|
-
readonly rsa: {
|
|
8
|
-
readonly RS256: "RS256";
|
|
9
|
-
readonly RS384: "RS384";
|
|
10
|
-
readonly RS512: "RS512";
|
|
11
|
-
};
|
|
12
|
-
readonly ecdsa: {
|
|
13
|
-
readonly ES256: "ES256";
|
|
14
|
-
readonly ES384: "ES384";
|
|
15
|
-
readonly ES512: "ES512";
|
|
16
|
-
};
|
|
17
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.algorithms = void 0;
|
|
4
|
-
exports.algorithms = {
|
|
5
|
-
// simétrica (una sola clave)
|
|
6
|
-
hmac: {
|
|
7
|
-
HS256: "HS256",
|
|
8
|
-
HS384: "HS384",
|
|
9
|
-
HS512: "HS512",
|
|
10
|
-
},
|
|
11
|
-
// asimétrica (clave pública/privada)
|
|
12
|
-
rsa: {
|
|
13
|
-
RS256: "RS256",
|
|
14
|
-
RS384: "RS384",
|
|
15
|
-
RS512: "RS512",
|
|
16
|
-
},
|
|
17
|
-
// curvas elípticas
|
|
18
|
-
ecdsa: {
|
|
19
|
-
ES256: "ES256",
|
|
20
|
-
ES384: "ES384",
|
|
21
|
-
ES512: "ES512",
|
|
22
|
-
},
|
|
23
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*Esta clase implementa la codificación y decodificación Base64 URL-safe,
|
|
3
|
-
*que es una variante del estándar Base64 diseñada para ser segura en URLs.
|
|
4
|
-
*/
|
|
5
|
-
export declare class Base64UrlEncoder {
|
|
6
|
-
/**
|
|
7
|
-
* Convierte una cadena de texto a formato Base64 URL-safe
|
|
8
|
-
* @param str La cadena a codificar
|
|
9
|
-
* @returns La cadena codificada en Base64 URL-safe
|
|
10
|
-
*/
|
|
11
|
-
encode(str: string): string;
|
|
12
|
-
/**
|
|
13
|
-
* Convierte de Base64 URL-safe de vuelta a texto original
|
|
14
|
-
* @param str La cadena codificada en Base64 URL-safe
|
|
15
|
-
* @returns La cadena decodificada
|
|
16
|
-
*/
|
|
17
|
-
decode(str: string): string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* El Base64 estándar usa caracteres (+, /, =) que tienen significado especial en URLs.
|
|
21
|
-
* Base64 URL-safe los reemplaza para evitar problemas cuando se usan en:
|
|
22
|
-
*
|
|
23
|
-
* - Parámetros de URL
|
|
24
|
-
* - Tokens JWT (muy común)
|
|
25
|
-
* - Headers HTTP
|
|
26
|
-
* - Rutas de API
|
|
27
|
-
*
|
|
28
|
-
* Esta implementación es típicamente usada para codificar/decodificar las partes de un JWT (header y payload) de forma segura para transmisión web.
|
|
29
|
-
*/
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Base64UrlEncoder = void 0;
|
|
4
|
-
/**
|
|
5
|
-
*Esta clase implementa la codificación y decodificación Base64 URL-safe,
|
|
6
|
-
*que es una variante del estándar Base64 diseñada para ser segura en URLs.
|
|
7
|
-
*/
|
|
8
|
-
class Base64UrlEncoder {
|
|
9
|
-
/**
|
|
10
|
-
* Convierte una cadena de texto a formato Base64 URL-safe
|
|
11
|
-
* @param str La cadena a codificar
|
|
12
|
-
* @returns La cadena codificada en Base64 URL-safe
|
|
13
|
-
*/
|
|
14
|
-
encode(str) {
|
|
15
|
-
return Buffer.from(str)
|
|
16
|
-
.toString("base64")
|
|
17
|
-
.replace(/\+/g, "-")
|
|
18
|
-
.replace(/\//g, "_")
|
|
19
|
-
.replace(/=/g, "");
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Convierte de Base64 URL-safe de vuelta a texto original
|
|
23
|
-
* @param str La cadena codificada en Base64 URL-safe
|
|
24
|
-
* @returns La cadena decodificada
|
|
25
|
-
*/
|
|
26
|
-
decode(str) {
|
|
27
|
-
const padding = 4 - (str.length % 4);
|
|
28
|
-
if (padding !== 4) {
|
|
29
|
-
str += "=".repeat(padding);
|
|
30
|
-
}
|
|
31
|
-
return Buffer.from(str.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.Base64UrlEncoder = Base64UrlEncoder;
|
|
35
|
-
/**
|
|
36
|
-
* El Base64 estándar usa caracteres (+, /, =) que tienen significado especial en URLs.
|
|
37
|
-
* Base64 URL-safe los reemplaza para evitar problemas cuando se usan en:
|
|
38
|
-
*
|
|
39
|
-
* - Parámetros de URL
|
|
40
|
-
* - Tokens JWT (muy común)
|
|
41
|
-
* - Headers HTTP
|
|
42
|
-
* - Rutas de API
|
|
43
|
-
*
|
|
44
|
-
* Esta implementación es típicamente usada para codificar/decodificar las partes de un JWT (header y payload) de forma segura para transmisión web.
|
|
45
|
-
*/
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./base64-url-encoder";
|
|
@@ -1,17 +0,0 @@
|
|
|
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("./base64-url-encoder"), exports);
|
package/dist/src/shared/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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("./utils"), exports);
|
|
18
|
-
__exportStar(require("./encoders"), exports);
|
|
19
|
-
__exportStar(require("./constants"), exports);
|
|
20
|
-
__exportStar(require("./types"), exports);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./jwt.types";
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { algorithms } from "../constants";
|
|
2
|
-
/**
|
|
3
|
-
* Tipos de algoritmos JWT soportados.
|
|
4
|
-
*/
|
|
5
|
-
export type AlgorithmCategory = keyof typeof algorithms;
|
|
6
|
-
/**
|
|
7
|
-
* Nombres de todos los algoritmos soportados.
|
|
8
|
-
*/
|
|
9
|
-
export type AlgorithmName = (typeof algorithms.hmac)[keyof typeof algorithms.hmac] | (typeof algorithms.rsa)[keyof typeof algorithms.rsa] | (typeof algorithms.ecdsa)[keyof typeof algorithms.ecdsa];
|
|
10
|
-
/**
|
|
11
|
-
* Tipos específicos de algoritmos por categoría.
|
|
12
|
-
*/
|
|
13
|
-
export type HmacAlgorithm = (typeof algorithms.hmac)[keyof typeof algorithms.hmac];
|
|
14
|
-
/**
|
|
15
|
-
* Tipos específicos de algoritmos por categoría.
|
|
16
|
-
*/
|
|
17
|
-
export type RsaAlgorithm = (typeof algorithms.rsa)[keyof typeof algorithms.rsa];
|
|
18
|
-
/**
|
|
19
|
-
* Tipos específicos de algoritmos por categoría.
|
|
20
|
-
*/
|
|
21
|
-
export type EcdsaAlgorithm = (typeof algorithms.ecdsa)[keyof typeof algorithms.ecdsa];
|
|
22
|
-
/**
|
|
23
|
-
* Tipo que agrupa todos los algoritmos posibles.
|
|
24
|
-
*/
|
|
25
|
-
export type AnyAlgorithm = HmacAlgorithm | RsaAlgorithm | EcdsaAlgorithm;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { IAuthConfig } from "../../domain/ports";
|
|
2
|
-
import { algorithms } from "../constants";
|
|
3
|
-
/**
|
|
4
|
-
* Tipos de algoritmos JWT soportados.
|
|
5
|
-
*/
|
|
6
|
-
export type AlgorithmCategory = keyof typeof algorithms;
|
|
7
|
-
/**
|
|
8
|
-
* Nombres de todos los algoritmos soportados.
|
|
9
|
-
*/
|
|
10
|
-
export type AlgorithmName = (typeof algorithms.hmac)[keyof typeof algorithms.hmac] | (typeof algorithms.rsa)[keyof typeof algorithms.rsa] | (typeof algorithms.ecdsa)[keyof typeof algorithms.ecdsa];
|
|
11
|
-
/**
|
|
12
|
-
* Tipos específicos de algoritmos por categoría.
|
|
13
|
-
*/
|
|
14
|
-
export type HmacAlgorithm = (typeof algorithms.hmac)[keyof typeof algorithms.hmac];
|
|
15
|
-
/**
|
|
16
|
-
* Tipos específicos de algoritmos por categoría.
|
|
17
|
-
*/
|
|
18
|
-
export type RsaAlgorithm = (typeof algorithms.rsa)[keyof typeof algorithms.rsa];
|
|
19
|
-
/**
|
|
20
|
-
* Tipos específicos de algoritmos por categoría.
|
|
21
|
-
*/
|
|
22
|
-
export type EcdsaAlgorithm = (typeof algorithms.ecdsa)[keyof typeof algorithms.ecdsa];
|
|
23
|
-
/**
|
|
24
|
-
* Tipo que agrupa todos los algoritmos posibles.
|
|
25
|
-
*/
|
|
26
|
-
export type AnyAlgorithm = HmacAlgorithm | RsaAlgorithm | EcdsaAlgorithm;
|
|
27
|
-
/**
|
|
28
|
-
* Configuración necesaria para los servicios de tokens JWT.
|
|
29
|
-
* Esto lo usan clases como JwtTokenGenerator o JwtTokenVerifier paara saber cómo firmar y con qué tipo de clave.
|
|
30
|
-
* Incluye opciones de JWT e información adicional.
|
|
31
|
-
* @param algorithm Algoritmo de firma (opcional).
|
|
32
|
-
* @param privateKey Clave privada para algoritmos RSA/ECDSA (opcional).
|
|
33
|
-
* @param publicKey Clave pública para algoritmos RSA/ECDSA (opcional).
|
|
34
|
-
*/
|
|
35
|
-
export type JwtTokenServiceConfig = IAuthConfig["jwt"] & IAuthConfig["info"] & {
|
|
36
|
-
algorithm: AnyAlgorithm;
|
|
37
|
-
privateKey?: string;
|
|
38
|
-
publicKey?: string;
|
|
39
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// tests/application/factory/auth-service-factory.spec.ts
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const domain_1 = require("../../../src/domain");
|
|
5
|
-
const infrastructure_1 = require("../../../src/infrastructure");
|
|
6
|
-
const use_cases_1 = require("../../../src/application/use-cases");
|
|
7
|
-
const application_1 = require("src/application");
|
|
8
|
-
describe("AuthServiceFactory", () => {
|
|
9
|
-
let config;
|
|
10
|
-
let userRepository;
|
|
11
|
-
let credentialRepository;
|
|
12
|
-
// const algorithm: AnyAlgorithm = "HS256";
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
config = {
|
|
15
|
-
jwt: {
|
|
16
|
-
accessTokenSecret: "access-secret",
|
|
17
|
-
refreshTokenSecret: "refresh-secret",
|
|
18
|
-
accessTokenExpirationMs: 15 * 60 * 1000,
|
|
19
|
-
refreshTokenExpirationMs: 7 * 24 * 60 * 60 * 1000,
|
|
20
|
-
accessTokenExpiration: "15m",
|
|
21
|
-
refreshTokenExpiration: "7d",
|
|
22
|
-
},
|
|
23
|
-
info: {
|
|
24
|
-
issuer: "test-issuer",
|
|
25
|
-
audience: "test-audience",
|
|
26
|
-
},
|
|
27
|
-
bcrypt: {
|
|
28
|
-
saltRounds: 10,
|
|
29
|
-
},
|
|
30
|
-
algorithm: "HS256",
|
|
31
|
-
};
|
|
32
|
-
userRepository = new infrastructure_1.InMemoryUserRepository();
|
|
33
|
-
credentialRepository = new infrastructure_1.InMemoryCredentialRepository();
|
|
34
|
-
});
|
|
35
|
-
it("debería crear un contenedor con todas las dependencias correctamente instanciadas", () => {
|
|
36
|
-
const container = application_1.AuthServiceFactory.create(config, userRepository, credentialRepository);
|
|
37
|
-
// Repositorios: deben ser exactamente los mismos que pasamos
|
|
38
|
-
expect(container.userRepository).toBe(userRepository);
|
|
39
|
-
expect(container.credentialRepository).toBe(credentialRepository);
|
|
40
|
-
// Servicios de dominio / infraestructura
|
|
41
|
-
expect(container.passwordHasher).toBeInstanceOf(infrastructure_1.BcryptPasswordHasher);
|
|
42
|
-
expect(container.passwordPolicy).toBeInstanceOf(domain_1.DefaultPasswordPolicy);
|
|
43
|
-
expect(container.tokenService).toBeInstanceOf(infrastructure_1.JwtTokenService);
|
|
44
|
-
expect(container.tokenSession).toBeInstanceOf(infrastructure_1.TokenSessionService);
|
|
45
|
-
// Casos de uso
|
|
46
|
-
expect(container.registerUserUseCase).toBeInstanceOf(use_cases_1.RegisterUserUseCase);
|
|
47
|
-
expect(container.loginWithPasswordUseCase).toBeInstanceOf(use_cases_1.LoginWithPasswordUseCase);
|
|
48
|
-
expect(container.refreshTokenUseCase).toBeInstanceOf(use_cases_1.RefreshTokenUseCase);
|
|
49
|
-
expect(container.logoutUseCase).toBeInstanceOf(use_cases_1.LogoutUseCase);
|
|
50
|
-
});
|
|
51
|
-
it("debería inyectar correctamente JwtTokenService con la configuración JWT recibida", () => {
|
|
52
|
-
const container = application_1.AuthServiceFactory.create(config, userRepository, credentialRepository);
|
|
53
|
-
const tokenService = container.tokenService;
|
|
54
|
-
const jwtConfig = tokenService.config;
|
|
55
|
-
expect(jwtConfig.accessTokenSecret).toBe(config.jwt.accessTokenSecret);
|
|
56
|
-
expect(jwtConfig.refreshTokenSecret).toBe(config.jwt.refreshTokenSecret);
|
|
57
|
-
expect(jwtConfig.accessTokenExpirationMs).toBe(config.jwt.accessTokenExpirationMs);
|
|
58
|
-
expect(jwtConfig.refreshTokenExpirationMs).toBe(config.jwt.refreshTokenExpirationMs);
|
|
59
|
-
expect(tokenService.jwtGenerator).toBeInstanceOf(infrastructure_1.JwtTokenGenerator);
|
|
60
|
-
expect(tokenService.jwtVerifier).toBeInstanceOf(infrastructure_1.JwtTokenVerifier);
|
|
61
|
-
expect(tokenService.jwtValidator).toBeInstanceOf(infrastructure_1.JwtTokenValidator);
|
|
62
|
-
const jwtGenerator = tokenService.jwtGenerator;
|
|
63
|
-
expect(jwtGenerator.signer).toBeInstanceOf(infrastructure_1.JwtSigner);
|
|
64
|
-
expect(jwtGenerator.encoder).toBeDefined();
|
|
65
|
-
});
|
|
66
|
-
it("debería compartir las mismas instancias de repositorios y servicios entre los casos de uso", () => {
|
|
67
|
-
const container = application_1.AuthServiceFactory.create(config, userRepository, credentialRepository);
|
|
68
|
-
const { userRepository: ur, credentialRepository: cr, passwordHasher, passwordPolicy, tokenService, tokenSession, registerUserUseCase, loginWithPasswordUseCase, refreshTokenUseCase, logoutUseCase, } = container;
|
|
69
|
-
// RegisterUserUseCase
|
|
70
|
-
expect(registerUserUseCase.userRepository).toBe(ur);
|
|
71
|
-
expect(registerUserUseCase.passwordHasher).toBe(passwordHasher);
|
|
72
|
-
expect(registerUserUseCase.passwordPolicy).toBe(passwordPolicy);
|
|
73
|
-
// LoginWithPasswordUseCase
|
|
74
|
-
expect(loginWithPasswordUseCase.userRepository).toBe(ur);
|
|
75
|
-
expect(loginWithPasswordUseCase.passwordHasher).toBe(passwordHasher);
|
|
76
|
-
expect(loginWithPasswordUseCase.tokenSessionService).toBe(tokenSession);
|
|
77
|
-
// RefreshTokenUseCase
|
|
78
|
-
const refreshValues = Object.values(refreshTokenUseCase);
|
|
79
|
-
expect(refreshValues).toContain(tokenSession);
|
|
80
|
-
// LogoutUseCase
|
|
81
|
-
const logoutValues = Object.values(logoutUseCase);
|
|
82
|
-
expect(logoutValues).toContain(tokenSession);
|
|
83
|
-
// TokenSessionService wiring interno
|
|
84
|
-
expect(tokenSession.userRepository).toBe(ur);
|
|
85
|
-
expect(tokenSession.credentialRepository).toBe(cr);
|
|
86
|
-
expect(tokenSession.tokenService).toBe(tokenService);
|
|
87
|
-
});
|
|
88
|
-
it("debería respetar las instancias de repositorios entregadas por el llamador", () => {
|
|
89
|
-
const otherUserRepo = new infrastructure_1.InMemoryUserRepository();
|
|
90
|
-
const otherCredRepo = new infrastructure_1.InMemoryCredentialRepository();
|
|
91
|
-
const container = application_1.AuthServiceFactory.create(config, otherUserRepo, otherCredRepo);
|
|
92
|
-
expect(container.userRepository).toBe(otherUserRepo);
|
|
93
|
-
expect(container.credentialRepository).toBe(otherCredRepo);
|
|
94
|
-
expect(container.userRepository).not.toBe(userRepository);
|
|
95
|
-
expect(container.credentialRepository).not.toBe(credentialRepository);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const application_1 = require("src/application");
|
|
4
|
-
const domain_1 = require("src/domain");
|
|
5
|
-
const infrastructure_1 = require("src/infrastructure");
|
|
6
|
-
/**
|
|
7
|
-
* FakeTokenSession usa el repositorio de credenciales real,
|
|
8
|
-
* pero genera tokens simples sin firmar, sólo para pruebas.
|
|
9
|
-
*/
|
|
10
|
-
class FakeTokenSession {
|
|
11
|
-
constructor(credentialRepo) {
|
|
12
|
-
this.credentialRepo = credentialRepo;
|
|
13
|
-
}
|
|
14
|
-
async createSession(user) {
|
|
15
|
-
const credential = new domain_1.Credential({
|
|
16
|
-
userId: user.id,
|
|
17
|
-
accessToken: `access-${user.id.getValue()}`,
|
|
18
|
-
refreshToken: `refresh-${user.id.getValue()}`,
|
|
19
|
-
expiresAt: new Date(Date.now() + 60 * 60 * 1000),
|
|
20
|
-
createdAt: new Date(),
|
|
21
|
-
});
|
|
22
|
-
await this.credentialRepo.save(credential);
|
|
23
|
-
return credential;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
// Constantes comunes
|
|
27
|
-
const plainPassword = "MySecureP@ssw0rd";
|
|
28
|
-
const bcryptHash = "$2b$10$CwTycUXWue0Thq9StjUM0uJ8E9aG7vlYgSi0hd0eZBwbNG0Ax7Anm";
|
|
29
|
-
describe("LoginWithPasswordUseCase (integración con repositorios en memoria)", () => {
|
|
30
|
-
let userRepository;
|
|
31
|
-
let credentialRepository;
|
|
32
|
-
let passwordHasher;
|
|
33
|
-
let tokenSessionService;
|
|
34
|
-
let createSessionSpy;
|
|
35
|
-
let useCase;
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
userRepository = new infrastructure_1.InMemoryUserRepository();
|
|
38
|
-
credentialRepository = new infrastructure_1.InMemoryCredentialRepository();
|
|
39
|
-
passwordHasher = {
|
|
40
|
-
hash: jest.fn(),
|
|
41
|
-
compare: jest.fn(),
|
|
42
|
-
};
|
|
43
|
-
tokenSessionService = new FakeTokenSession(credentialRepository);
|
|
44
|
-
createSessionSpy = jest.spyOn(tokenSessionService, "createSession");
|
|
45
|
-
useCase = new application_1.LoginWithPasswordUseCase(userRepository, passwordHasher, tokenSessionService);
|
|
46
|
-
});
|
|
47
|
-
afterEach(() => {
|
|
48
|
-
jest.clearAllMocks();
|
|
49
|
-
});
|
|
50
|
-
const createUser = (props) => new domain_1.User({
|
|
51
|
-
id: new domain_1.Id("user-123"),
|
|
52
|
-
email: new domain_1.Email("login@example.com"),
|
|
53
|
-
password: new domain_1.HashedPassword(bcryptHash),
|
|
54
|
-
isActive: true,
|
|
55
|
-
roles: [new domain_1.Role("user")],
|
|
56
|
-
createdAt: new Date(),
|
|
57
|
-
updatedAt: new Date(),
|
|
58
|
-
...props,
|
|
59
|
-
});
|
|
60
|
-
it("debe crear una sesión persistida al loguear correctamente", async () => {
|
|
61
|
-
const emailValue = "login@example.com";
|
|
62
|
-
const user = createUser({ email: new domain_1.Email(emailValue) });
|
|
63
|
-
await userRepository.save(user);
|
|
64
|
-
passwordHasher.compare.mockResolvedValue(true);
|
|
65
|
-
const request = {
|
|
66
|
-
email: emailValue,
|
|
67
|
-
password: plainPassword,
|
|
68
|
-
};
|
|
69
|
-
// Act
|
|
70
|
-
const response = await useCase.execute(request);
|
|
71
|
-
// Assert: respuesta
|
|
72
|
-
expect(response.accessToken).toBe("access-user-123");
|
|
73
|
-
expect(response.refreshToken).toBe("refresh-user-123");
|
|
74
|
-
// Assert: credencial persistida en el repositorio
|
|
75
|
-
const storedCredential = await credentialRepository.findByUserId(user.id);
|
|
76
|
-
expect(storedCredential).not.toBeNull();
|
|
77
|
-
expect(storedCredential?.accessToken).toBe("access-user-123");
|
|
78
|
-
expect(storedCredential?.refreshToken).toBe("refresh-user-123");
|
|
79
|
-
// Assert: se llamó a createSession
|
|
80
|
-
expect(createSessionSpy).toHaveBeenCalledTimes(1);
|
|
81
|
-
expect(createSessionSpy).toHaveBeenCalledWith(user);
|
|
82
|
-
});
|
|
83
|
-
it("debe loguear correctamente cuando las credenciales son válidas y el usuario está activo", async () => {
|
|
84
|
-
const emailValue = "user@example.com";
|
|
85
|
-
const user = createUser({ email: new domain_1.Email(emailValue) });
|
|
86
|
-
await userRepository.save(user);
|
|
87
|
-
passwordHasher.compare.mockResolvedValue(true);
|
|
88
|
-
const request = {
|
|
89
|
-
email: emailValue,
|
|
90
|
-
password: plainPassword,
|
|
91
|
-
};
|
|
92
|
-
// Act
|
|
93
|
-
const response = await useCase.execute(request);
|
|
94
|
-
// Assert
|
|
95
|
-
expect(passwordHasher.compare).toHaveBeenCalledTimes(1);
|
|
96
|
-
expect(passwordHasher.compare).toHaveBeenCalledWith(request.password, user.password.serialize());
|
|
97
|
-
expect(createSessionSpy).toHaveBeenCalledTimes(1);
|
|
98
|
-
expect(createSessionSpy).toHaveBeenCalledWith(user);
|
|
99
|
-
expect(response).toEqual({
|
|
100
|
-
accessToken: "access-user-123",
|
|
101
|
-
refreshToken: "refresh-user-123",
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
it("debe lanzar UserNotFoundError cuando el usuario no existe", async () => {
|
|
105
|
-
const request = {
|
|
106
|
-
email: "unknown@example.com",
|
|
107
|
-
password: "whatever",
|
|
108
|
-
};
|
|
109
|
-
await expect(useCase.execute(request)).rejects.toBeInstanceOf(domain_1.UserNotFoundError);
|
|
110
|
-
expect(passwordHasher.compare).not.toHaveBeenCalled();
|
|
111
|
-
expect(createSessionSpy).not.toHaveBeenCalled();
|
|
112
|
-
});
|
|
113
|
-
it("debe lanzar UserDisabledError cuando el usuario está inactivo", async () => {
|
|
114
|
-
const emailValue = "disabled@example.com";
|
|
115
|
-
const user = createUser({ email: new domain_1.Email(emailValue) });
|
|
116
|
-
// Forzamos que canLogin() devuelva false
|
|
117
|
-
jest.spyOn(user, "canLogin").mockReturnValue(false);
|
|
118
|
-
await userRepository.save(user);
|
|
119
|
-
const request = {
|
|
120
|
-
email: emailValue,
|
|
121
|
-
password: "any-password",
|
|
122
|
-
};
|
|
123
|
-
await expect(useCase.execute(request)).rejects.toBeInstanceOf(domain_1.UserDisabledError);
|
|
124
|
-
expect(passwordHasher.compare).not.toHaveBeenCalled();
|
|
125
|
-
expect(createSessionSpy).not.toHaveBeenCalled();
|
|
126
|
-
});
|
|
127
|
-
it("debe lanzar PasswordMismatchError cuando la contraseña es incorrecta", async () => {
|
|
128
|
-
const emailValue = "user@example.com";
|
|
129
|
-
const user = createUser({ email: new domain_1.Email(emailValue) });
|
|
130
|
-
await userRepository.save(user);
|
|
131
|
-
passwordHasher.compare.mockResolvedValue(false);
|
|
132
|
-
const request = {
|
|
133
|
-
email: emailValue,
|
|
134
|
-
password: "wrong-password",
|
|
135
|
-
};
|
|
136
|
-
await expect(useCase.execute(request)).rejects.toBeInstanceOf(domain_1.PasswordMismatchError);
|
|
137
|
-
expect(passwordHasher.compare).toHaveBeenCalledTimes(1);
|
|
138
|
-
expect(createSessionSpy).not.toHaveBeenCalled();
|
|
139
|
-
});
|
|
140
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|