@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,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// src/examples/login-and-logout-jwt.example.ts
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.UseCaseLogoutExample = void 0;
|
|
5
|
-
const application_1 = require("../src/application");
|
|
6
|
-
const domain_1 = require("../src/domain");
|
|
7
|
-
const infrastructure_1 = require("../src/infrastructure");
|
|
8
|
-
const jwt_1 = require("../src/infrastructure/jwt");
|
|
9
|
-
const shared_1 = require("../src/shared");
|
|
10
|
-
/**
|
|
11
|
-
* TokenSessionJWT
|
|
12
|
-
*
|
|
13
|
-
* Implementación de ITokenSession que utiliza JwtTokenGenerator para crear tokens reales.
|
|
14
|
-
* Guarda la sesión en un repositorio en memoria (InMemoryCredentialRepository).
|
|
15
|
-
*/
|
|
16
|
-
class TokenSessionJWT {
|
|
17
|
-
constructor(credentialRepo, generator, config) {
|
|
18
|
-
this.credentialRepo = credentialRepo;
|
|
19
|
-
this.generator = generator;
|
|
20
|
-
this.config = config;
|
|
21
|
-
}
|
|
22
|
-
async createSession(user) {
|
|
23
|
-
const jwtUser = {
|
|
24
|
-
id: user.id.getValue(),
|
|
25
|
-
email: user.email.toString(),
|
|
26
|
-
roles: user.roles.map((r) => ({ role: r.getValuePublic().role })), // ajusta si usas getValuePublic()
|
|
27
|
-
};
|
|
28
|
-
const accessToken = this.generator.generateAccessToken({
|
|
29
|
-
user: jwtUser,
|
|
30
|
-
config: this.config,
|
|
31
|
-
});
|
|
32
|
-
const refreshToken = this.generator.generateRefreshToken({
|
|
33
|
-
user: jwtUser,
|
|
34
|
-
config: this.config,
|
|
35
|
-
});
|
|
36
|
-
const cred = domain_1.Credential.create(user.id, accessToken, refreshToken, new Date(Date.now() + this.config.accessTokenExpirationMs));
|
|
37
|
-
// Persistimos, pero no dependemos del valor de retorno
|
|
38
|
-
await this.credentialRepo.save(cred);
|
|
39
|
-
// 👇 Esto es lo importante para el caso de uso
|
|
40
|
-
return cred;
|
|
41
|
-
}
|
|
42
|
-
async revokeSession(refreshToken) {
|
|
43
|
-
await this.credentialRepo.deleteByRefreshToken(refreshToken);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Ejemplo demostrativo del flujo completo:
|
|
48
|
-
* Crear usuario → Login → Generar JWTs → Logout
|
|
49
|
-
*/
|
|
50
|
-
class UseCaseLogoutExample {
|
|
51
|
-
static async Main() {
|
|
52
|
-
console.log("=== 🔐🚪 Ejemplo: Login + Logout con JWT ===\n");
|
|
53
|
-
// 1️⃣ Configuración JWT
|
|
54
|
-
const jwtConfig = {
|
|
55
|
-
accessTokenSecret: "ACCESS_SECRET_ABC",
|
|
56
|
-
refreshTokenSecret: "REFRESH_SECRET_DEF",
|
|
57
|
-
accessTokenExpirationMs: shared_1.TimeParser.parseToMilliseconds("15m"),
|
|
58
|
-
refreshTokenExpirationMs: shared_1.TimeParser.parseToMilliseconds("7d"),
|
|
59
|
-
issuer: "auth-service",
|
|
60
|
-
audience: "client-app",
|
|
61
|
-
algorithm: "HS256",
|
|
62
|
-
};
|
|
63
|
-
// 2️⃣ Dependencias
|
|
64
|
-
const userRepo = new infrastructure_1.InMemoryUserRepository();
|
|
65
|
-
const credentialRepo = new infrastructure_1.InMemoryCredentialRepository();
|
|
66
|
-
const passwordHasher = new infrastructure_1.BcryptPasswordHasher();
|
|
67
|
-
// Generador de tokens JWT
|
|
68
|
-
const encoder = new shared_1.Base64UrlEncoder();
|
|
69
|
-
const signer = new jwt_1.JwtSigner(encoder);
|
|
70
|
-
const generator = new jwt_1.JwtTokenGenerator(encoder, signer);
|
|
71
|
-
// Implementación JWT de sesión
|
|
72
|
-
const tokenSession = new TokenSessionJWT(credentialRepo, generator, jwtConfig);
|
|
73
|
-
// Casos de uso
|
|
74
|
-
const loginUseCase = new application_1.LoginWithPasswordUseCase(userRepo, passwordHasher, tokenSession);
|
|
75
|
-
const logoutUseCase = new application_1.LogoutUseCase(tokenSession);
|
|
76
|
-
// 3️⃣ Crear usuario
|
|
77
|
-
const plainPassword = "MyStr0ngP@ss!";
|
|
78
|
-
const hashedPassword = await passwordHasher.hash(plainPassword);
|
|
79
|
-
const user = new domain_1.User({
|
|
80
|
-
id: new domain_1.Id("user-jwt-001"),
|
|
81
|
-
email: new domain_1.Email("jwt.demo@example.com"),
|
|
82
|
-
password: new domain_1.HashedPassword(hashedPassword),
|
|
83
|
-
isActive: true,
|
|
84
|
-
roles: [new domain_1.Role("user")],
|
|
85
|
-
createdAt: new Date(),
|
|
86
|
-
updatedAt: new Date(),
|
|
87
|
-
});
|
|
88
|
-
await userRepo.save(user);
|
|
89
|
-
console.log("→ Usuario creado:");
|
|
90
|
-
console.log(" id:", user.id.getValue());
|
|
91
|
-
console.log(" email:", user.email.toString(), "\n");
|
|
92
|
-
// 4️⃣ Login
|
|
93
|
-
const loginRequest = {
|
|
94
|
-
email: "jwt.demo@example.com",
|
|
95
|
-
password: plainPassword,
|
|
96
|
-
};
|
|
97
|
-
console.log("→ Ejecutando LoginWithPasswordUseCase...\n");
|
|
98
|
-
const loginResponse = await loginUseCase.execute(loginRequest);
|
|
99
|
-
console.log("✅ Login exitoso:");
|
|
100
|
-
console.log(" Access Token:", loginResponse.accessToken);
|
|
101
|
-
console.log(" Refresh Token:", loginResponse.refreshToken, "\n");
|
|
102
|
-
// 5️⃣ Logout con refresh token válido
|
|
103
|
-
const logoutRequest = {
|
|
104
|
-
refreshToken: loginResponse.refreshToken,
|
|
105
|
-
};
|
|
106
|
-
console.log("→ Ejecutando LogoutUseCase...\n");
|
|
107
|
-
try {
|
|
108
|
-
const response = await logoutUseCase.execute(logoutRequest);
|
|
109
|
-
console.log("✅ Logout exitoso:");
|
|
110
|
-
console.log(" ", response, "\n");
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
console.error("❌ Error al hacer logout:", error);
|
|
114
|
-
}
|
|
115
|
-
// 6️⃣ Intentar logout otra vez (token ya revocado)
|
|
116
|
-
console.log("→ Intentando logout nuevamente (debería fallar)...\n");
|
|
117
|
-
try {
|
|
118
|
-
await logoutUseCase.execute(logoutRequest);
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
if (error instanceof domain_1.LogoutError) {
|
|
122
|
-
console.error("⚠️ LogoutError capturado como se esperaba:");
|
|
123
|
-
console.error(" ", error.message, "\n");
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
console.error("❌ Error inesperado:", error);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
console.log("🏁 Flujo Login + JWT + Logout finalizado.\n");
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
exports.UseCaseLogoutExample = UseCaseLogoutExample;
|
|
133
|
-
// Para ejecutar:
|
|
134
|
-
// (async () => await UseCaseLoginAndLogoutJwtExample.Main())();
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ejemplo práctico del flujo:
|
|
3
|
-
* 1) Registrar usuario
|
|
4
|
-
* 2) Login (crea session -> access + refresh)
|
|
5
|
-
* 3) Refrescar token (rota refresh token y genera nueva sesión)
|
|
6
|
-
*
|
|
7
|
-
* No usa mocks: componentes reales en memoria.
|
|
8
|
-
*/
|
|
9
|
-
export declare class UseCaseRefreshTokenExample {
|
|
10
|
-
static Main(): Promise<void>;
|
|
11
|
-
}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UseCaseRefreshTokenExample = void 0;
|
|
4
|
-
const application_1 = require("../src/application");
|
|
5
|
-
const domain_1 = require("../src/domain");
|
|
6
|
-
const infrastructure_1 = require("../src/infrastructure");
|
|
7
|
-
const shared_1 = require("../src/shared");
|
|
8
|
-
/**
|
|
9
|
-
* Ejemplo práctico del flujo:
|
|
10
|
-
* 1) Registrar usuario
|
|
11
|
-
* 2) Login (crea session -> access + refresh)
|
|
12
|
-
* 3) Refrescar token (rota refresh token y genera nueva sesión)
|
|
13
|
-
*
|
|
14
|
-
* No usa mocks: componentes reales en memoria.
|
|
15
|
-
*/
|
|
16
|
-
class UseCaseRefreshTokenExample {
|
|
17
|
-
static async Main() {
|
|
18
|
-
console.log("=== 🔁 Ejemplo: flujo completo de Refresh Token ===\n");
|
|
19
|
-
// 1️⃣ Configuración JWT
|
|
20
|
-
const jwtConfig = {
|
|
21
|
-
accessTokenSecret: "access_secret_key_123",
|
|
22
|
-
refreshTokenSecret: "refresh_secret_key_123",
|
|
23
|
-
accessTokenExpirationMs: 1000 * 60 * 15, // 15 minutos
|
|
24
|
-
refreshTokenExpirationMs: 1000 * 60 * 60 * 24, // 1 día
|
|
25
|
-
accessTokenExpiration: "15m",
|
|
26
|
-
refreshTokenExpiration: "1d",
|
|
27
|
-
algorithm: "HS256",
|
|
28
|
-
issuer: "example-auth",
|
|
29
|
-
audience: "example-client",
|
|
30
|
-
};
|
|
31
|
-
// 2️⃣ Infra y utilidades reales (en memoria)
|
|
32
|
-
const encoder = new shared_1.Base64UrlEncoder();
|
|
33
|
-
const signer = new infrastructure_1.JwtSigner(encoder);
|
|
34
|
-
// Atención: uso el mismo orden que tienes en tu proyecto (encoder, signer).
|
|
35
|
-
const tokenGenerator = new infrastructure_1.JwtTokenGenerator(encoder, signer);
|
|
36
|
-
const userRepo = new infrastructure_1.InMemoryUserRepository();
|
|
37
|
-
const credentialRepo = new infrastructure_1.InMemoryCredentialRepository();
|
|
38
|
-
const passwordHasher = new infrastructure_1.BcryptPasswordHasher();
|
|
39
|
-
// 3️⃣ Implementación simple de ITokenSession usando JwtTokenGenerator + repo
|
|
40
|
-
class TokenSessionJWT {
|
|
41
|
-
constructor(tokenGen, credentialRepo) {
|
|
42
|
-
this.tokenGen = tokenGen;
|
|
43
|
-
this.credentialRepo = credentialRepo;
|
|
44
|
-
}
|
|
45
|
-
// No implementado para este ejemplo
|
|
46
|
-
validateSession(_accessToken) {
|
|
47
|
-
throw new Error("Method not implemented.");
|
|
48
|
-
}
|
|
49
|
-
async createSession(user) {
|
|
50
|
-
// Genera access y refresh con la config (simulando uso real)
|
|
51
|
-
const accessToken = this.tokenGen.generateAccessToken({
|
|
52
|
-
user: {
|
|
53
|
-
id: user.id.getValue(),
|
|
54
|
-
email: user.email.toString(),
|
|
55
|
-
roles: user.roles.map((r) => ({ role: r.getValuePublic().role })),
|
|
56
|
-
},
|
|
57
|
-
config: jwtConfig,
|
|
58
|
-
});
|
|
59
|
-
const refreshToken = this.tokenGen.generateRefreshToken({
|
|
60
|
-
user: {
|
|
61
|
-
id: user.id.getValue(),
|
|
62
|
-
email: user.email.toString(),
|
|
63
|
-
roles: user.roles.map((r) => ({ role: r.getValuePublic().role })),
|
|
64
|
-
},
|
|
65
|
-
config: jwtConfig,
|
|
66
|
-
});
|
|
67
|
-
const credential = new domain_1.Credential({
|
|
68
|
-
userId: new domain_1.Id(user.id.getValue()),
|
|
69
|
-
accessToken,
|
|
70
|
-
refreshToken,
|
|
71
|
-
expiresAt: new Date(Date.now() + jwtConfig.accessTokenExpirationMs),
|
|
72
|
-
createdAt: new Date(),
|
|
73
|
-
});
|
|
74
|
-
await this.credentialRepo.save(credential);
|
|
75
|
-
return credential;
|
|
76
|
-
}
|
|
77
|
-
async refreshSession(refreshToken) {
|
|
78
|
-
// Encuentra la sesión existente por refresh token
|
|
79
|
-
const found = await this.credentialRepo.findByRefreshToken(refreshToken);
|
|
80
|
-
if (!found)
|
|
81
|
-
throw new domain_1.InvalidOrExpiredRefreshTokenError();
|
|
82
|
-
// 👉 Rota / revoca el refresh anterior para evitar reutilización
|
|
83
|
-
await this.credentialRepo.deleteByRefreshToken(refreshToken);
|
|
84
|
-
// Reconstruye un User mínimo a partir de la credencial encontrada
|
|
85
|
-
// (en tu app real obtendrías el usuario del repositorio)
|
|
86
|
-
const user = new domain_1.User({
|
|
87
|
-
id: new domain_1.Id(found.userId.getValue()),
|
|
88
|
-
email: new domain_1.Email("user@example.com"),
|
|
89
|
-
roles: [new domain_1.Role("USER")],
|
|
90
|
-
// Password VO válido (no necesario para el refresh pero User requiere)
|
|
91
|
-
password: new domain_1.HashedPassword("$2b$10$CwTycUXWue0Thq9StjUM0uJ8rS8o9VZqvE8G9W9C6q7CwTycUXWu2"),
|
|
92
|
-
isActive: true,
|
|
93
|
-
createdAt: new Date(),
|
|
94
|
-
updatedAt: new Date(),
|
|
95
|
-
});
|
|
96
|
-
// Crea nueva sesión (nuevo access + refresh)
|
|
97
|
-
return this.createSession(user);
|
|
98
|
-
}
|
|
99
|
-
async revokeSession(refreshToken) {
|
|
100
|
-
await this.credentialRepo.deleteByRefreshToken(refreshToken);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const tokenSessionService = new TokenSessionJWT(tokenGenerator, credentialRepo);
|
|
104
|
-
// 4️⃣ Casos de uso reales
|
|
105
|
-
const passwordPolicy = new domain_1.DefaultPasswordPolicy();
|
|
106
|
-
const registerUser = new application_1.RegisterUserUseCase(userRepo, passwordHasher, passwordPolicy);
|
|
107
|
-
const loginUseCase = new application_1.LoginWithPasswordUseCase(userRepo, passwordHasher, tokenSessionService);
|
|
108
|
-
const refreshUseCase = new application_1.RefreshTokenUseCase(tokenSessionService);
|
|
109
|
-
// --- Flujo: registrar ---
|
|
110
|
-
const email = "user@example.com";
|
|
111
|
-
const password = "Password123!";
|
|
112
|
-
const roles = [{ role: "USER" }];
|
|
113
|
-
console.log("→ Registrando usuario...");
|
|
114
|
-
await registerUser.execute({ email, password, roles });
|
|
115
|
-
console.log(" ✔ Usuario registrado:", email);
|
|
116
|
-
// --- Flujo: login ---
|
|
117
|
-
console.log("\n→ Realizando login...");
|
|
118
|
-
const loginResponse = await loginUseCase.execute({ email, password });
|
|
119
|
-
console.log(" ✔ Login exitoso");
|
|
120
|
-
console.log(" accessToken:", loginResponse.accessToken);
|
|
121
|
-
console.log(" refreshToken:", loginResponse.refreshToken);
|
|
122
|
-
// --- Flujo: refresh (éxito) ---
|
|
123
|
-
console.log("\n→ Solicitando refresh del token...");
|
|
124
|
-
const refreshed = await refreshUseCase.execute({
|
|
125
|
-
refreshToken: loginResponse.refreshToken,
|
|
126
|
-
});
|
|
127
|
-
console.log(" ✔ Refresh exitoso");
|
|
128
|
-
console.log(" new accessToken:", refreshed.accessToken);
|
|
129
|
-
console.log(" new refreshToken:", refreshed.refreshToken);
|
|
130
|
-
console.log(`\n Comparación: refresh anterior === nuevo? ${refreshed.refreshToken === loginResponse.refreshToken ? "SI" : "NO"}`);
|
|
131
|
-
// --- Intento de reutilizar el refresh antiguo (debe fallar si rotamos) ---
|
|
132
|
-
console.log("\n→ Intentando reutilizar el refresh antiguo (debe fallar)...");
|
|
133
|
-
try {
|
|
134
|
-
await refreshUseCase.execute({
|
|
135
|
-
refreshToken: loginResponse.refreshToken,
|
|
136
|
-
});
|
|
137
|
-
console.error(" ❌ ERROR: el refresh antiguo aún es válido (no debió serlo).");
|
|
138
|
-
}
|
|
139
|
-
catch (err) {
|
|
140
|
-
if (err instanceof domain_1.InvalidOrExpiredRefreshTokenError) {
|
|
141
|
-
console.log(" ✅ Reutilización bloqueada: token inválido o expirado (esperado).");
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
console.error(" ⚠️ Error inesperado al reintentar refresh:", err);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
// --- Intento con token inválido ---
|
|
148
|
-
console.log("\n→ Intentando refresh con token inválido...");
|
|
149
|
-
try {
|
|
150
|
-
await refreshUseCase.execute({ refreshToken: "este.no.existe" });
|
|
151
|
-
console.error(" ❌ ERROR: token inválido no lanzó excepción.");
|
|
152
|
-
}
|
|
153
|
-
catch (err) {
|
|
154
|
-
if (err instanceof domain_1.InvalidOrExpiredRefreshTokenError) {
|
|
155
|
-
console.log(" ✅ Token inválido correctamente rechazado.");
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
console.error(" ⚠️ Error inesperado:", err);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
console.log("\n=== ✅ Fin del ejemplo Refresh Token ===");
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
exports.UseCaseRefreshTokenExample = UseCaseRefreshTokenExample;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* UseCaseRegisterUserExample
|
|
3
|
-
*
|
|
4
|
-
* Demostración completa del flujo de registro de usuario usando RegisterUserUseCase.
|
|
5
|
-
* Utiliza implementaciones in-memory y un hasher simple compatible con el dominio.
|
|
6
|
-
*/
|
|
7
|
-
export declare class UseCaseRegisterUserExample {
|
|
8
|
-
static Main(): Promise<void>;
|
|
9
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UseCaseRegisterUserExample = void 0;
|
|
4
|
-
const register_user_use_case_1 = require("../src/application/use-cases/register-user.use-case");
|
|
5
|
-
const domain_1 = require("../src/domain");
|
|
6
|
-
const infrastructure_1 = require("../src/infrastructure");
|
|
7
|
-
const repositories_1 = require("../src/infrastructure/repositories");
|
|
8
|
-
/**
|
|
9
|
-
* UseCaseRegisterUserExample
|
|
10
|
-
*
|
|
11
|
-
* Demostración completa del flujo de registro de usuario usando RegisterUserUseCase.
|
|
12
|
-
* Utiliza implementaciones in-memory y un hasher simple compatible con el dominio.
|
|
13
|
-
*/
|
|
14
|
-
class UseCaseRegisterUserExample {
|
|
15
|
-
static async Main() {
|
|
16
|
-
console.log("=== 🧾 Ejemplo: RegisterUserUseCase ===\n");
|
|
17
|
-
// 1️⃣ Implementaciones de ejemplo
|
|
18
|
-
const userRepository = new repositories_1.InMemoryUserRepository();
|
|
19
|
-
// Política de contraseñas de ejemplo
|
|
20
|
-
class DefaultPasswordPolicy {
|
|
21
|
-
validateStrength(password) {
|
|
22
|
-
const errors = [];
|
|
23
|
-
if (!password || password.length < 8)
|
|
24
|
-
errors.push("Min 8 characters");
|
|
25
|
-
if (!/[A-Z]/.test(password))
|
|
26
|
-
errors.push("Needs uppercase");
|
|
27
|
-
if (!/[a-z]/.test(password))
|
|
28
|
-
errors.push("Needs lowercase");
|
|
29
|
-
if (!/\d/.test(password))
|
|
30
|
-
errors.push("Needs number");
|
|
31
|
-
if (!/[!@#$%^&*]/.test(password))
|
|
32
|
-
errors.push("Needs special char");
|
|
33
|
-
return { isValid: errors.length === 0, errors };
|
|
34
|
-
}
|
|
35
|
-
getRequirements() {
|
|
36
|
-
return [
|
|
37
|
-
"Min 8 characters",
|
|
38
|
-
"At least one uppercase",
|
|
39
|
-
"At least one lowercase",
|
|
40
|
-
"At least one number",
|
|
41
|
-
"At least one special character",
|
|
42
|
-
];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
// 2️⃣ Instancias del caso de uso
|
|
46
|
-
const passwordHasher = new infrastructure_1.BcryptPasswordHasher();
|
|
47
|
-
const passwordPolicy = new DefaultPasswordPolicy();
|
|
48
|
-
const useCase = new register_user_use_case_1.RegisterUserUseCase(userRepository, passwordHasher, passwordPolicy);
|
|
49
|
-
// 3️⃣ Caso: contraseña débil
|
|
50
|
-
const weakRequest = {
|
|
51
|
-
email: "weak@example.com",
|
|
52
|
-
password: "123",
|
|
53
|
-
roles: [],
|
|
54
|
-
};
|
|
55
|
-
console.log("→ Intentando registro con contraseña débil...");
|
|
56
|
-
try {
|
|
57
|
-
await useCase.execute(weakRequest);
|
|
58
|
-
console.log("⚠️ Registro débil no debería pasar (error esperado).");
|
|
59
|
-
}
|
|
60
|
-
catch (err) {
|
|
61
|
-
if (err instanceof domain_1.PasswordPolicyViolationError) {
|
|
62
|
-
console.log("✅ Política de contraseña detectada correctamente.");
|
|
63
|
-
console.log(" ", err.message);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
console.error("❌ Error inesperado:", err);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// 4️⃣ Caso: registro válido
|
|
70
|
-
const validRequest = {
|
|
71
|
-
email: "alice@example.com",
|
|
72
|
-
password: "Str0ngP@ss!",
|
|
73
|
-
roles: [
|
|
74
|
-
{
|
|
75
|
-
role: "ADMIN",
|
|
76
|
-
permissions: ["user.read", "user.write"],
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
};
|
|
80
|
-
console.log("\n→ Intentando registro válido...");
|
|
81
|
-
try {
|
|
82
|
-
const res = await useCase.execute(validRequest);
|
|
83
|
-
console.log("✅ Usuario registrado correctamente:");
|
|
84
|
-
console.log(" id:", res.id);
|
|
85
|
-
console.log(" roles:", res.roles);
|
|
86
|
-
console.log(" isActive:", res.isActive);
|
|
87
|
-
}
|
|
88
|
-
catch (err) {
|
|
89
|
-
console.error("❌ No se pudo registrar usuario válido:", err);
|
|
90
|
-
}
|
|
91
|
-
// 5️⃣ Caso: intento duplicado
|
|
92
|
-
console.log("\n→ Intentando registrar el mismo email nuevamente (duplicado)...");
|
|
93
|
-
try {
|
|
94
|
-
await useCase.execute(validRequest);
|
|
95
|
-
console.log("⚠️ Unexpected: segundo registro con mismo email pasó (no debería).");
|
|
96
|
-
}
|
|
97
|
-
catch (err) {
|
|
98
|
-
if (err instanceof domain_1.EmailAlreadyInUseError) {
|
|
99
|
-
console.log("✅ Duplicado detectado correctamente:", err.message);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
console.error("❌ Error inesperado en duplicado:", err);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
// 6️⃣ Mostrar requisitos de contraseña
|
|
106
|
-
console.log("\n📌 Requisitos de contraseña:");
|
|
107
|
-
console.log(" ", passwordPolicy.getRequirements().join(" | "));
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
exports.UseCaseRegisterUserExample = UseCaseRegisterUserExample;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export interface UserRole {
|
|
2
|
-
role: string;
|
|
3
|
-
permissions?: string[];
|
|
4
|
-
}
|
|
5
|
-
export interface RegisterUserRequest {
|
|
6
|
-
email: string;
|
|
7
|
-
password: string;
|
|
8
|
-
roles: UserRole[];
|
|
9
|
-
}
|
|
10
|
-
export interface RegisterUserResponse {
|
|
11
|
-
id: string;
|
|
12
|
-
roles: {
|
|
13
|
-
role: string;
|
|
14
|
-
}[];
|
|
15
|
-
isActive: boolean;
|
|
16
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { IAuthConfig, ICredentialRepository, IUserRepository } from "../../domain";
|
|
2
|
-
import { IAuthServiceContainer } from "../../infrastructure";
|
|
3
|
-
export declare class AuthServiceFactory {
|
|
4
|
-
static create(config: IAuthConfig, userRepository: IUserRepository, credentialRepository: ICredentialRepository): IAuthServiceContainer;
|
|
5
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AuthServiceFactory = void 0;
|
|
4
|
-
const domain_1 = require("../../domain");
|
|
5
|
-
const infrastructure_1 = require("../../infrastructure");
|
|
6
|
-
const shared_1 = require("../../shared");
|
|
7
|
-
const use_cases_1 = require("../use-cases");
|
|
8
|
-
class AuthServiceFactory {
|
|
9
|
-
static create(config, userRepository, credentialRepository) {
|
|
10
|
-
// JWT Infrastructure components
|
|
11
|
-
const encoder = new shared_1.Base64UrlEncoder();
|
|
12
|
-
const signer = new infrastructure_1.JwtSigner(encoder);
|
|
13
|
-
const parser = new infrastructure_1.JwtTokenParser(encoder);
|
|
14
|
-
const jwtGenerator = new infrastructure_1.JwtTokenGenerator(encoder, signer);
|
|
15
|
-
const jwtVerifier = new infrastructure_1.JwtTokenVerifier(signer, parser, config.algorithm);
|
|
16
|
-
const jwtValidator = new infrastructure_1.JwtTokenValidator();
|
|
17
|
-
// Domain services
|
|
18
|
-
const jwtConfig = {
|
|
19
|
-
accessTokenSecret: config.jwt.accessTokenSecret,
|
|
20
|
-
refreshTokenSecret: config.jwt.refreshTokenSecret,
|
|
21
|
-
accessTokenExpirationMs: config.jwt.accessTokenExpirationMs,
|
|
22
|
-
refreshTokenExpirationMs: config.jwt.refreshTokenExpirationMs,
|
|
23
|
-
algorithm: config.algorithm,
|
|
24
|
-
issuer: config.info.issuer,
|
|
25
|
-
audience: config.info.audience,
|
|
26
|
-
};
|
|
27
|
-
const tokenService = new infrastructure_1.JwtTokenService(jwtConfig, jwtGenerator, jwtVerifier, jwtValidator);
|
|
28
|
-
// Application services
|
|
29
|
-
const passwordPolicy = new domain_1.DefaultPasswordPolicy();
|
|
30
|
-
const passwordHasher = new infrastructure_1.BcryptPasswordHasher();
|
|
31
|
-
const tokenSession = new infrastructure_1.TokenSessionService(tokenService, userRepository, credentialRepository, config.algorithm, config.jwt.accessTokenExpiration, config.jwt.refreshTokenExpiration, config.jwt.accessTokenSecret, config.jwt.refreshTokenSecret);
|
|
32
|
-
// Use cases
|
|
33
|
-
const registerUserUseCase = new use_cases_1.RegisterUserUseCase(userRepository, passwordHasher, passwordPolicy);
|
|
34
|
-
const loginWithPasswordUseCase = new use_cases_1.LoginWithPasswordUseCase(userRepository, passwordHasher, tokenSession);
|
|
35
|
-
const refreshTokenUseCase = new use_cases_1.RefreshTokenUseCase(tokenSession);
|
|
36
|
-
const logoutUseCase = new use_cases_1.LogoutUseCase(tokenSession);
|
|
37
|
-
return {
|
|
38
|
-
userRepository,
|
|
39
|
-
credentialRepository,
|
|
40
|
-
passwordHasher,
|
|
41
|
-
tokenService,
|
|
42
|
-
passwordPolicy,
|
|
43
|
-
tokenSession,
|
|
44
|
-
registerUserUseCase,
|
|
45
|
-
loginWithPasswordUseCase,
|
|
46
|
-
refreshTokenUseCase,
|
|
47
|
-
logoutUseCase,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.AuthServiceFactory = AuthServiceFactory;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { IPasswordHasher, IPasswordPolicy } from "../../domain";
|
|
2
|
-
import { IUserRepository } from "../../domain/ports/repository";
|
|
3
|
-
import { RegisterUserRequest, RegisterUserResponse } from "../dtos";
|
|
4
|
-
export declare class RegisterUserUseCase {
|
|
5
|
-
private readonly userRepository;
|
|
6
|
-
private readonly passwordHasher;
|
|
7
|
-
private readonly passwordPolicy;
|
|
8
|
-
constructor(userRepository: IUserRepository, passwordHasher: IPasswordHasher, passwordPolicy: IPasswordPolicy);
|
|
9
|
-
execute(request: RegisterUserRequest): Promise<RegisterUserResponse>;
|
|
10
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
export type AuthErrorCode = "TOKEN_EXPIRED" | "TOKEN_NOT_YET_VALID" | "TOKEN_INVALID" | "TOKEN_MALFORMED" | "SIGNATURE_INVALID" | "ALGORITHM_UNSUPPORTED" | "KEY_NOT_FOUND" | "KEY_MISMATCH" | "TOKEN_REVOKED" | "CLOCK_SKEW" | "AUTHENTICATION_FAILED" | "CLAIMS_VALIDATION_ERROR";
|
|
2
|
-
export interface ClaimsIssue {
|
|
3
|
-
path: string;
|
|
4
|
-
message: string;
|
|
5
|
-
}
|
|
6
|
-
export declare abstract class AuthDomainError extends Error {
|
|
7
|
-
readonly code: AuthErrorCode;
|
|
8
|
-
readonly details?: unknown;
|
|
9
|
-
constructor(message: string, code: AuthErrorCode, details?: unknown);
|
|
10
|
-
toJSON(): {
|
|
11
|
-
name: string;
|
|
12
|
-
message: string;
|
|
13
|
-
code: AuthErrorCode;
|
|
14
|
-
details: unknown;
|
|
15
|
-
};
|
|
16
|
-
static isAuthError(e: unknown): e is AuthDomainError;
|
|
17
|
-
}
|
|
18
|
-
/** El token ya no es válido por exp (exp < now) */
|
|
19
|
-
export declare class TokenExpiredError extends AuthDomainError {
|
|
20
|
-
constructor(message?: string, details?: {
|
|
21
|
-
exp?: number;
|
|
22
|
-
now?: number;
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
/** El token aún no debe usarse (nbf > now) */
|
|
26
|
-
export declare class TokenNotYetValidError extends AuthDomainError {
|
|
27
|
-
constructor(message?: string, details?: {
|
|
28
|
-
nbf?: number;
|
|
29
|
-
now?: number;
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
/** Formato inválido (no tiene 3 partes, base64url inválido, JSON inválido) */
|
|
33
|
-
export declare class InvalidTokenFormatError extends AuthDomainError {
|
|
34
|
-
constructor(message?: string, details?: unknown);
|
|
35
|
-
}
|
|
36
|
-
/** Firma inválida (no coincide con datos/clave) */
|
|
37
|
-
export declare class InvalidSignatureError extends AuthDomainError {
|
|
38
|
-
constructor(message?: string, details?: unknown);
|
|
39
|
-
}
|
|
40
|
-
/** Algoritmo no soportado por la librería/política */
|
|
41
|
-
export declare class UnsupportedAlgorithmError extends AuthDomainError {
|
|
42
|
-
constructor(message?: string, details?: {
|
|
43
|
-
alg: string;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
/** No se pudo resolver/obtener la clave necesaria (kid, store…) */
|
|
47
|
-
export declare class KeyNotFoundError extends AuthDomainError {
|
|
48
|
-
constructor(message?: string, details?: {
|
|
49
|
-
kid?: string;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
/** La clave encontrada no corresponde (key-id/alg desalineado, par incorrecto) */
|
|
53
|
-
export declare class KeyMismatchError extends AuthDomainError {
|
|
54
|
-
constructor(message?: string, details?: {
|
|
55
|
-
alg?: string;
|
|
56
|
-
kid?: string;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
/** Token revocado en listas de deny/blacklist */
|
|
60
|
-
export declare class TokenRevokedError extends AuthDomainError {
|
|
61
|
-
constructor(message?: string, details?: {
|
|
62
|
-
jti?: string;
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
/** Desfase de reloj detectado (leeway insuficiente) */
|
|
66
|
-
export declare class ClockSkewError extends AuthDomainError {
|
|
67
|
-
constructor(message?: string, details?: {
|
|
68
|
-
skewSeconds?: number;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
/** Claims inválidas a nivel semántico (aud, iss, scope, custom…) */
|
|
72
|
-
export declare class ClaimsValidationError extends AuthDomainError {
|
|
73
|
-
constructor(issues: ClaimsIssue[], message?: string);
|
|
74
|
-
}
|
|
75
|
-
/** Falla general de autenticación (catch-all) */
|
|
76
|
-
export declare class AuthenticationError extends AuthDomainError {
|
|
77
|
-
constructor(message?: string, details?: unknown);
|
|
78
|
-
}
|
|
79
|
-
/** Alias histórico si lo usabas antes */
|
|
80
|
-
export declare class InvalidTokenError extends AuthenticationError {
|
|
81
|
-
constructor(message?: string, details?: unknown);
|
|
82
|
-
}
|