@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,269 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const domain_1 = require("../../../src/domain");
|
|
4
|
-
const token_session_service_1 = require("../../../src/infrastructure/services/token-session.service");
|
|
5
|
-
const shared_1 = require("../../../src/shared");
|
|
6
|
-
describe("TokenSessionService", () => {
|
|
7
|
-
let tokenService;
|
|
8
|
-
let userRepository;
|
|
9
|
-
let credentialRepository;
|
|
10
|
-
const accessTokenExpiration = "15m";
|
|
11
|
-
const refreshTokenExpiration = "7d";
|
|
12
|
-
const accessSecret = "access-secret";
|
|
13
|
-
const refreshSecret = "refresh-secret";
|
|
14
|
-
const algorithm = "HS256";
|
|
15
|
-
const makeService = () => new token_session_service_1.TokenSessionService(tokenService, userRepository, credentialRepository, algorithm, accessTokenExpiration, refreshTokenExpiration, accessSecret, refreshSecret);
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
tokenService = {
|
|
18
|
-
generateAccessToken: jest.fn(),
|
|
19
|
-
generateRefreshToken: jest.fn(),
|
|
20
|
-
verifyAccessToken: jest.fn(),
|
|
21
|
-
verifyRefreshToken: jest.fn(),
|
|
22
|
-
getTokenExpiration: jest.fn(),
|
|
23
|
-
};
|
|
24
|
-
userRepository = {
|
|
25
|
-
findById: jest.fn(),
|
|
26
|
-
};
|
|
27
|
-
credentialRepository = {
|
|
28
|
-
save: jest.fn(),
|
|
29
|
-
findByUserId: jest.fn(),
|
|
30
|
-
findByRefreshToken: jest.fn(),
|
|
31
|
-
update: jest.fn(),
|
|
32
|
-
delete: jest.fn(),
|
|
33
|
-
deleteByRefreshToken: jest.fn(),
|
|
34
|
-
};
|
|
35
|
-
jest.restoreAllMocks();
|
|
36
|
-
});
|
|
37
|
-
// ────────────────────────────────────────────────
|
|
38
|
-
// Constructor
|
|
39
|
-
// ────────────────────────────────────────────────
|
|
40
|
-
it("debería lanzar JwtSecretError si faltan los secretos", () => {
|
|
41
|
-
expect(() => new token_session_service_1.TokenSessionService(tokenService, userRepository, credentialRepository, algorithm, accessTokenExpiration, refreshTokenExpiration, undefined, // accessTokenSecret
|
|
42
|
-
undefined // refreshTokenSecret
|
|
43
|
-
)).toThrow(domain_1.JwtSecretError);
|
|
44
|
-
});
|
|
45
|
-
it("debería lanzar error si la configuración de expiración es inválida", () => {
|
|
46
|
-
const spy = jest
|
|
47
|
-
.spyOn(shared_1.TimeParser, "parseToMilliseconds")
|
|
48
|
-
.mockImplementation(() => {
|
|
49
|
-
throw new Error("Formato inválido");
|
|
50
|
-
});
|
|
51
|
-
expect(() => new token_session_service_1.TokenSessionService(tokenService, userRepository, credentialRepository, algorithm, "invalid", // access
|
|
52
|
-
"invalid", // refresh
|
|
53
|
-
accessSecret, refreshSecret)).toThrow("Invalid token expiration configuration");
|
|
54
|
-
spy.mockRestore();
|
|
55
|
-
});
|
|
56
|
-
// ────────────────────────────────────────────────
|
|
57
|
-
// createSession
|
|
58
|
-
// ────────────────────────────────────────────────
|
|
59
|
-
describe("createSession", () => {
|
|
60
|
-
it("debería generar access y refresh tokens, guardar la credencial y retornarla", async () => {
|
|
61
|
-
const service = makeService();
|
|
62
|
-
const mockUserId = "user-123";
|
|
63
|
-
const mockEmail = "user@example.com";
|
|
64
|
-
const mockRolesPublic = [{ role: "user" }];
|
|
65
|
-
const user = {
|
|
66
|
-
id: { toString: () => mockUserId },
|
|
67
|
-
email: { toString: () => mockEmail },
|
|
68
|
-
roles: [
|
|
69
|
-
{
|
|
70
|
-
getValuePublic: () => mockRolesPublic[0],
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
};
|
|
74
|
-
tokenService.generateAccessToken.mockResolvedValue("access-token");
|
|
75
|
-
tokenService.generateRefreshToken.mockResolvedValue("refresh-token");
|
|
76
|
-
const result = await service.createSession(user);
|
|
77
|
-
// Debe generar tokens con los datos del usuario
|
|
78
|
-
expect(tokenService.generateAccessToken).toHaveBeenCalledTimes(1);
|
|
79
|
-
expect(tokenService.generateAccessToken).toHaveBeenCalledWith(expect.objectContaining({
|
|
80
|
-
user: {
|
|
81
|
-
id: mockUserId,
|
|
82
|
-
email: mockEmail,
|
|
83
|
-
roles: mockRolesPublic,
|
|
84
|
-
},
|
|
85
|
-
expiresIn: accessTokenExpiration,
|
|
86
|
-
}));
|
|
87
|
-
expect(tokenService.generateRefreshToken).toHaveBeenCalledTimes(1);
|
|
88
|
-
expect(tokenService.generateRefreshToken).toHaveBeenCalledWith(expect.objectContaining({
|
|
89
|
-
user: {
|
|
90
|
-
id: mockUserId,
|
|
91
|
-
email: mockEmail,
|
|
92
|
-
roles: mockRolesPublic,
|
|
93
|
-
},
|
|
94
|
-
expiresIn: refreshTokenExpiration,
|
|
95
|
-
}));
|
|
96
|
-
// Debe guardar la credencial
|
|
97
|
-
expect(credentialRepository.save).toHaveBeenCalledTimes(1);
|
|
98
|
-
const savedCredential = credentialRepository.save.mock
|
|
99
|
-
.calls[0][0];
|
|
100
|
-
// La credencial retornada debe ser la misma que se guardó
|
|
101
|
-
expect(result).toBe(savedCredential);
|
|
102
|
-
expect(savedCredential).toBeInstanceOf(domain_1.Credential);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
// ────────────────────────────────────────────────
|
|
106
|
-
// refreshSession
|
|
107
|
-
// ────────────────────────────────────────────────
|
|
108
|
-
describe("refreshSession", () => {
|
|
109
|
-
const refreshToken = "refresh-token";
|
|
110
|
-
it("debería lanzar InvalidOrExpiredRefreshTokenError si no existe credencial para el refresh token", async () => {
|
|
111
|
-
const service = makeService();
|
|
112
|
-
credentialRepository.findByRefreshToken.mockResolvedValue(null);
|
|
113
|
-
await expect(service.refreshSession(refreshToken)).rejects.toThrow(domain_1.InvalidOrExpiredRefreshTokenError);
|
|
114
|
-
expect(credentialRepository.findByRefreshToken).toHaveBeenCalledWith(refreshToken);
|
|
115
|
-
});
|
|
116
|
-
it("debería lanzar InvalidOrExpiredRefreshTokenError si verifyRefreshToken falla", async () => {
|
|
117
|
-
const service = makeService();
|
|
118
|
-
credentialRepository.findByRefreshToken.mockResolvedValue({});
|
|
119
|
-
tokenService.verifyRefreshToken.mockRejectedValue(new Error("expired"));
|
|
120
|
-
await expect(service.refreshSession(refreshToken)).rejects.toThrow(domain_1.InvalidOrExpiredRefreshTokenError);
|
|
121
|
-
});
|
|
122
|
-
it("debería lanzar UserNotFoundError si el usuario no existe", async () => {
|
|
123
|
-
const service = makeService();
|
|
124
|
-
credentialRepository.findByRefreshToken.mockResolvedValue({});
|
|
125
|
-
const payload = {
|
|
126
|
-
sub: "user-123",
|
|
127
|
-
iss: "test",
|
|
128
|
-
aud: "test",
|
|
129
|
-
iat: Date.now() / 1000,
|
|
130
|
-
exp: (Date.now() + 1000) / 1000,
|
|
131
|
-
roles: [],
|
|
132
|
-
customClaims: {},
|
|
133
|
-
jti: "id",
|
|
134
|
-
};
|
|
135
|
-
tokenService.verifyRefreshToken.mockResolvedValue(payload);
|
|
136
|
-
userRepository.findById.mockResolvedValue(null);
|
|
137
|
-
await expect(service.refreshSession(refreshToken)).rejects.toThrow(domain_1.UserNotFoundError);
|
|
138
|
-
expect(userRepository.findById).toHaveBeenCalledWith(expect.any(domain_1.Id) // se instancia con payload.sub
|
|
139
|
-
);
|
|
140
|
-
});
|
|
141
|
-
it("debería lanzar UserDisabledError si el usuario está deshabilitado", async () => {
|
|
142
|
-
const service = makeService();
|
|
143
|
-
credentialRepository.findByRefreshToken.mockResolvedValue({});
|
|
144
|
-
const payload = {
|
|
145
|
-
sub: "user-123",
|
|
146
|
-
iss: "test",
|
|
147
|
-
aud: "test",
|
|
148
|
-
iat: Date.now() / 1000,
|
|
149
|
-
exp: (Date.now() + 1000) / 1000,
|
|
150
|
-
roles: [],
|
|
151
|
-
customClaims: {},
|
|
152
|
-
jti: "id",
|
|
153
|
-
};
|
|
154
|
-
tokenService.verifyRefreshToken.mockResolvedValue(payload);
|
|
155
|
-
const user = {
|
|
156
|
-
canLogin: jest.fn().mockReturnValue(false),
|
|
157
|
-
};
|
|
158
|
-
userRepository.findById.mockResolvedValue(user);
|
|
159
|
-
await expect(service.refreshSession(refreshToken)).rejects.toThrow(domain_1.UserDisabledError);
|
|
160
|
-
});
|
|
161
|
-
it("debería crear una nueva sesión, eliminar la credencial anterior y retornar la nueva", async () => {
|
|
162
|
-
const service = makeService();
|
|
163
|
-
// Existe una credencial asociada al refresh token
|
|
164
|
-
credentialRepository.findByRefreshToken.mockResolvedValue({});
|
|
165
|
-
const payload = {
|
|
166
|
-
sub: "user-123",
|
|
167
|
-
iss: "test",
|
|
168
|
-
aud: "test",
|
|
169
|
-
iat: Date.now() / 1000,
|
|
170
|
-
exp: (Date.now() + 1000) / 1000,
|
|
171
|
-
roles: [],
|
|
172
|
-
customClaims: {},
|
|
173
|
-
jti: "id",
|
|
174
|
-
};
|
|
175
|
-
tokenService.verifyRefreshToken.mockResolvedValue(payload);
|
|
176
|
-
const user = {
|
|
177
|
-
id: { toString: () => "user-123" },
|
|
178
|
-
email: { toString: () => "user@example.com" },
|
|
179
|
-
roles: [
|
|
180
|
-
{
|
|
181
|
-
getValuePublic: () => ({ role: "user" }),
|
|
182
|
-
},
|
|
183
|
-
],
|
|
184
|
-
canLogin: jest.fn().mockReturnValue(true),
|
|
185
|
-
};
|
|
186
|
-
userRepository.findById.mockResolvedValue(user);
|
|
187
|
-
tokenService.generateAccessToken.mockResolvedValue("new-access");
|
|
188
|
-
tokenService.generateRefreshToken.mockResolvedValue("new-refresh");
|
|
189
|
-
const result = await service.refreshSession(refreshToken);
|
|
190
|
-
// Debe haber creado y guardado una nueva credencial
|
|
191
|
-
expect(credentialRepository.save).toHaveBeenCalledTimes(1);
|
|
192
|
-
const savedCredential = credentialRepository.save.mock
|
|
193
|
-
.calls[0][0];
|
|
194
|
-
expect(result).toBe(savedCredential);
|
|
195
|
-
expect(savedCredential).toBeInstanceOf(domain_1.Credential);
|
|
196
|
-
// Debe eliminar la credencial vieja asociada al refresh token
|
|
197
|
-
expect(credentialRepository.deleteByRefreshToken).toHaveBeenCalledWith(refreshToken);
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
// ────────────────────────────────────────────────
|
|
201
|
-
// validateSession
|
|
202
|
-
// ────────────────────────────────────────────────
|
|
203
|
-
describe("validateSession", () => {
|
|
204
|
-
it("debería retornar el usuario cuando el token es válido y el usuario puede iniciar sesión", async () => {
|
|
205
|
-
const service = makeService();
|
|
206
|
-
const payload = {
|
|
207
|
-
sub: "user-123",
|
|
208
|
-
iss: "test",
|
|
209
|
-
aud: "test",
|
|
210
|
-
iat: Date.now() / 1000,
|
|
211
|
-
exp: (Date.now() + 1000) / 1000,
|
|
212
|
-
roles: [],
|
|
213
|
-
customClaims: {},
|
|
214
|
-
jti: "id",
|
|
215
|
-
};
|
|
216
|
-
tokenService.verifyAccessToken.mockResolvedValue(payload);
|
|
217
|
-
const user = {
|
|
218
|
-
canLogin: jest.fn().mockReturnValue(true),
|
|
219
|
-
};
|
|
220
|
-
userRepository.findById.mockResolvedValue(user);
|
|
221
|
-
const result = await service.validateSession("access-token");
|
|
222
|
-
expect(tokenService.verifyAccessToken).toHaveBeenCalledWith("access-token");
|
|
223
|
-
expect(userRepository.findById).toHaveBeenCalledWith(expect.any(domain_1.Id));
|
|
224
|
-
expect(result).toBe(user);
|
|
225
|
-
});
|
|
226
|
-
it("debería retornar null si verifyAccessToken lanza error", async () => {
|
|
227
|
-
const service = makeService();
|
|
228
|
-
tokenService.verifyAccessToken.mockRejectedValue(new Error("invalid"));
|
|
229
|
-
const result = await service.validateSession("invalid-token");
|
|
230
|
-
expect(result).toBeNull();
|
|
231
|
-
});
|
|
232
|
-
it("debería retornar null si el usuario no existe o no puede iniciar sesión", async () => {
|
|
233
|
-
const service = makeService();
|
|
234
|
-
const payload = {
|
|
235
|
-
sub: "user-123",
|
|
236
|
-
iss: "test",
|
|
237
|
-
aud: "test",
|
|
238
|
-
iat: Date.now() / 1000,
|
|
239
|
-
exp: (Date.now() + 1000) / 1000,
|
|
240
|
-
roles: [],
|
|
241
|
-
customClaims: {},
|
|
242
|
-
jti: "id",
|
|
243
|
-
};
|
|
244
|
-
tokenService.verifyAccessToken.mockResolvedValue(payload);
|
|
245
|
-
// Caso usuario no existe
|
|
246
|
-
userRepository.findById.mockResolvedValueOnce(null);
|
|
247
|
-
const result1 = await service.validateSession("access-token");
|
|
248
|
-
expect(result1).toBeNull();
|
|
249
|
-
// Caso usuario existe pero no puede iniciar sesión
|
|
250
|
-
const user = {
|
|
251
|
-
canLogin: jest.fn().mockReturnValue(false),
|
|
252
|
-
};
|
|
253
|
-
userRepository.findById.mockResolvedValueOnce(user);
|
|
254
|
-
const result2 = await service.validateSession("access-token");
|
|
255
|
-
expect(result2).toBeNull();
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
// ────────────────────────────────────────────────
|
|
259
|
-
// revokeSession
|
|
260
|
-
// ────────────────────────────────────────────────
|
|
261
|
-
describe("revokeSession", () => {
|
|
262
|
-
it("debería eliminar la credencial asociada al refresh token", async () => {
|
|
263
|
-
const service = makeService();
|
|
264
|
-
const refreshToken = "refresh-token";
|
|
265
|
-
await service.revokeSession(refreshToken);
|
|
266
|
-
expect(credentialRepository.deleteByRefreshToken).toHaveBeenCalledWith(refreshToken);
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const shared_1 = require("src/shared");
|
|
4
|
-
describe("algorithms constant", () => {
|
|
5
|
-
it("define las tres categorías principales", () => {
|
|
6
|
-
expect(Object.keys(shared_1.algorithms)).toEqual(["hmac", "rsa", "ecdsa"]);
|
|
7
|
-
});
|
|
8
|
-
it("cada categoría contiene tres algoritmos esperados", () => {
|
|
9
|
-
expect(Object.keys(shared_1.algorithms.hmac)).toEqual(["HS256", "HS384", "HS512"]);
|
|
10
|
-
expect(Object.keys(shared_1.algorithms.rsa)).toEqual(["RS256", "RS384", "RS512"]);
|
|
11
|
-
expect(Object.keys(shared_1.algorithms.ecdsa)).toEqual(["ES256", "ES384", "ES512"]);
|
|
12
|
-
});
|
|
13
|
-
it("los valores coinciden exactamente con sus claves (autodescriptivos)", () => {
|
|
14
|
-
for (const [family, algos] of Object.entries(shared_1.algorithms)) {
|
|
15
|
-
for (const [key, value] of Object.entries(algos)) {
|
|
16
|
-
expect(value).toBe(key);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
it("no debe contener valores nulos o indefinidos", () => {
|
|
21
|
-
for (const family of Object.values(shared_1.algorithms)) {
|
|
22
|
-
for (const value of Object.values(family)) {
|
|
23
|
-
expect(value).toBeTruthy();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const shared_1 = require("../../../src/shared");
|
|
4
|
-
describe("Base64UrlEncoder", () => {
|
|
5
|
-
const enc = new shared_1.Base64UrlEncoder();
|
|
6
|
-
describe("encode", () => {
|
|
7
|
-
it.each([
|
|
8
|
-
["", ""],
|
|
9
|
-
["f", "Zg"],
|
|
10
|
-
["fo", "Zm8"],
|
|
11
|
-
["foo", "Zm9v"],
|
|
12
|
-
["foob", "Zm9vYg"],
|
|
13
|
-
["fooba", "Zm9vYmE"],
|
|
14
|
-
["foobar", "Zm9vYmFy"],
|
|
15
|
-
["hello", "aGVsbG8"],
|
|
16
|
-
["mañana", "bWHDsWFuYQ"], // UTF-8
|
|
17
|
-
["🔥", "8J-UpQ"], // incluye '-'
|
|
18
|
-
["😺", "8J-Yug"], // incluye '-'
|
|
19
|
-
["00?", "MDA_"], // incluye '_'
|
|
20
|
-
])('encode("%s") → "%s"', (plain, expected) => {
|
|
21
|
-
expect(enc.encode(plain)).toBe(expected);
|
|
22
|
-
});
|
|
23
|
-
it("no contiene +, / ni = (URL-safe y sin padding)", () => {
|
|
24
|
-
const out = enc.encode("texto con símbolos: ~✓🔥/+/=");
|
|
25
|
-
expect(out).not.toMatch(/[+/=]/);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
describe("decode", () => {
|
|
29
|
-
it.each([
|
|
30
|
-
["", ""],
|
|
31
|
-
["Zg", "f"], // sin padding (==)
|
|
32
|
-
["Zm8", "fo"], // sin padding (=)
|
|
33
|
-
["Zm9v", "foo"], // sin padding
|
|
34
|
-
["Zm9vYg", "foob"],
|
|
35
|
-
["Zm9vYmE", "fooba"],
|
|
36
|
-
["Zm9vYmFy", "foobar"],
|
|
37
|
-
["aGVsbG8", "hello"],
|
|
38
|
-
["bWHDsWFuYQ", "mañana"], // UTF-8
|
|
39
|
-
["8J-UpQ", "🔥"], // con '-'
|
|
40
|
-
["MDA_", "00?"], // con '_'
|
|
41
|
-
])('decode("%s") → "%s"', (b64url, expected) => {
|
|
42
|
-
expect(enc.decode(b64url)).toBe(expected);
|
|
43
|
-
});
|
|
44
|
-
it("acepta también Base64 “estándar” con padding", () => {
|
|
45
|
-
// Aunque la clase es URL-safe, su decode soporta base64 estándar.
|
|
46
|
-
expect(enc.decode("aGVsbG8=")).toBe("hello");
|
|
47
|
-
expect(enc.decode("Zm8=")).toBe("fo");
|
|
48
|
-
expect(enc.decode("Zg==")).toBe("f");
|
|
49
|
-
});
|
|
50
|
-
it("reconstituye padding correcto cuando falta", () => {
|
|
51
|
-
// length % 4 === 2 → agrega "=="
|
|
52
|
-
expect(enc.decode("Zg")).toBe("f");
|
|
53
|
-
// length % 4 === 3 → agrega "="
|
|
54
|
-
expect(enc.decode("Zm8")).toBe("fo");
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
describe("round-trip", () => {
|
|
58
|
-
it.each([
|
|
59
|
-
"",
|
|
60
|
-
"hola",
|
|
61
|
-
"The quick brown fox jumps over the lazy dog.",
|
|
62
|
-
"mañana será otro día",
|
|
63
|
-
"🔥😺 ~ ✓ / + _",
|
|
64
|
-
])('decode(encode(x)) === x para "%s"', (plain) => {
|
|
65
|
-
const encoded = enc.encode(plain);
|
|
66
|
-
const decoded = enc.decode(encoded);
|
|
67
|
-
expect(decoded).toBe(plain);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// tests/shared/TimeParser.spec.ts
|
|
4
|
-
const time_parser_1 = require("../../../src/shared/utils/time-parser");
|
|
5
|
-
describe("TimeParser", () => {
|
|
6
|
-
describe("parseToMilliseconds", () => {
|
|
7
|
-
it.each([
|
|
8
|
-
["30s", 30000],
|
|
9
|
-
["1m", 60000],
|
|
10
|
-
["15m", 900000],
|
|
11
|
-
["1h", 3600000],
|
|
12
|
-
["2h", 7200000],
|
|
13
|
-
["1d", 86400000],
|
|
14
|
-
["3d", 259200000],
|
|
15
|
-
])("convierte %s a %d ms", (input, expected) => {
|
|
16
|
-
expect(time_parser_1.TimeParser.parseToMilliseconds(input)).toBe(expected);
|
|
17
|
-
});
|
|
18
|
-
it("ignora espacios y mayúsculas/minúsculas", () => {
|
|
19
|
-
expect(time_parser_1.TimeParser.parseToMilliseconds(" 2H ")).toBe(7200000);
|
|
20
|
-
expect(time_parser_1.TimeParser.parseToMilliseconds(" 45S")).toBe(45000);
|
|
21
|
-
});
|
|
22
|
-
it("lanza si no es string o es falsy", () => {
|
|
23
|
-
expect(() => time_parser_1.TimeParser.parseToMilliseconds("")).toThrow(/must be a string/i);
|
|
24
|
-
// Solo espacios
|
|
25
|
-
expect(() => time_parser_1.TimeParser.parseToMilliseconds(" ")).toThrow(/invalid time format/i);
|
|
26
|
-
});
|
|
27
|
-
it("lanza si el formato no coincide con número+unidad", () => {
|
|
28
|
-
for (const bad of ["15", "m15", "1 h", "1w", "1mh", "-5m"]) {
|
|
29
|
-
expect(() => time_parser_1.TimeParser.parseToMilliseconds(bad)).toThrow(/invalid time format/i);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
it("lanza si el valor es 0 (o no positivo)", () => {
|
|
33
|
-
expect(() => time_parser_1.TimeParser.parseToMilliseconds("0m")).toThrow(/invalid time value/i);
|
|
34
|
-
expect(() => time_parser_1.TimeParser.parseToMilliseconds("000s")).toThrow(/invalid time value/i);
|
|
35
|
-
});
|
|
36
|
-
it("acepta ceros a la izquierda válidos (01h -> 1h)", () => {
|
|
37
|
-
expect(time_parser_1.TimeParser.parseToMilliseconds("01h")).toBe(3600000);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
describe("isValidTimeString", () => {
|
|
41
|
-
it.each(["30s", "1m", "2h", "7d", " 2H "])("devuelve true para %s", (input) => {
|
|
42
|
-
expect(time_parser_1.TimeParser.isValidTimeString(input)).toBe(true);
|
|
43
|
-
});
|
|
44
|
-
it.each(["", " ", "1", "m15", "1 h", "1w", "0m", "-5m"])("devuelve false para %s", (input) => {
|
|
45
|
-
expect(time_parser_1.TimeParser.isValidTimeString(input)).toBe(false);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
describe("getSupportedUnits", () => {
|
|
49
|
-
it("devuelve las unidades soportadas en orden estable", () => {
|
|
50
|
-
const units = time_parser_1.TimeParser.getSupportedUnits();
|
|
51
|
-
expect(units).toEqual(["s", "m", "h", "d"]);
|
|
52
|
-
expect(new Set(units)).toEqual(new Set(["s", "m", "h", "d"]));
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
describe("formatMilliseconds", () => {
|
|
56
|
-
it.each([
|
|
57
|
-
[1000, "1s"],
|
|
58
|
-
[3000, "3s"],
|
|
59
|
-
[60000, "1m"],
|
|
60
|
-
[120000, "2m"],
|
|
61
|
-
[180000, "3m"],
|
|
62
|
-
[3600000, "1h"],
|
|
63
|
-
[7200000, "2h"],
|
|
64
|
-
[86400000, "1d"],
|
|
65
|
-
[172800000, "2d"],
|
|
66
|
-
])("formatea %d como %s", (ms, expected) => {
|
|
67
|
-
expect(time_parser_1.TimeParser.formatMilliseconds(ms)).toBe(expected);
|
|
68
|
-
});
|
|
69
|
-
it("elige la unidad más grande divisible exactamente (90_000 -> 90s, no 1.5m)", () => {
|
|
70
|
-
expect(time_parser_1.TimeParser.formatMilliseconds(90000)).toBe("90s");
|
|
71
|
-
});
|
|
72
|
-
it('cuando no es divisible exacto por 1000, devuelve "Xms"', () => {
|
|
73
|
-
expect(time_parser_1.TimeParser.formatMilliseconds(1501)).toBe("1501ms");
|
|
74
|
-
expect(time_parser_1.TimeParser.formatMilliseconds(65001)).toBe("65001ms");
|
|
75
|
-
});
|
|
76
|
-
it('0ms retorna "0ms"', () => {
|
|
77
|
-
expect(time_parser_1.TimeParser.formatMilliseconds(0)).toBe("0ms");
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|
package/dist/utils/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./time-parser";
|
package/dist/utils/index.js
DELETED
|
@@ -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("./time-parser"), exports);
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export declare class TimeParser {
|
|
2
|
-
private static readonly TIME_UNITS;
|
|
3
|
-
private static readonly TIME_PATTERN;
|
|
4
|
-
/**
|
|
5
|
-
* Convierte una cadena de tiempo (ej: "15m", "1h", "7d") a milisegundos
|
|
6
|
-
* @param timeString - Cadena de tiempo en formato número + unidad
|
|
7
|
-
* @returns Tiempo en milisegundos
|
|
8
|
-
* @throws Error si el formato es inválido
|
|
9
|
-
*/
|
|
10
|
-
static parseToMilliseconds(timeString: string): number;
|
|
11
|
-
/**
|
|
12
|
-
* Valida si una cadena de tiempo tiene el formato correcto
|
|
13
|
-
* @param timeString - Cadena de tiempo a validar
|
|
14
|
-
* @returns true si es válida, false en caso contrario
|
|
15
|
-
*/
|
|
16
|
-
static isValidTimeString(timeString: string): boolean;
|
|
17
|
-
/**
|
|
18
|
-
* Obtiene las unidades de tiempo soportadas
|
|
19
|
-
* @returns Array con las unidades soportadas
|
|
20
|
-
*/
|
|
21
|
-
static getSupportedUnits(): string[];
|
|
22
|
-
/**
|
|
23
|
-
* Convierte milisegundos a formato legible
|
|
24
|
-
* @param milliseconds - Tiempo en milisegundos
|
|
25
|
-
* @returns Cadena de tiempo legible
|
|
26
|
-
*/
|
|
27
|
-
static formatMilliseconds(milliseconds: number): string;
|
|
28
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TimeParser = void 0;
|
|
4
|
-
class TimeParser {
|
|
5
|
-
/**
|
|
6
|
-
* Convierte una cadena de tiempo (ej: "15m", "1h", "7d") a milisegundos
|
|
7
|
-
* @param timeString - Cadena de tiempo en formato número + unidad
|
|
8
|
-
* @returns Tiempo en milisegundos
|
|
9
|
-
* @throws Error si el formato es inválido
|
|
10
|
-
*/
|
|
11
|
-
static parseToMilliseconds(timeString) {
|
|
12
|
-
if (!timeString || typeof timeString !== "string") {
|
|
13
|
-
throw new Error("Time string is required and must be a string");
|
|
14
|
-
}
|
|
15
|
-
const trimmed = timeString.trim().toLowerCase();
|
|
16
|
-
const match = trimmed.match(this.TIME_PATTERN);
|
|
17
|
-
if (!match) {
|
|
18
|
-
throw new Error(`Invalid time format: "${timeString}". Expected format: number + unit (s, m, h, d). Examples: "15m", "1h", "7d"`);
|
|
19
|
-
}
|
|
20
|
-
const [, valueStr, unit] = match;
|
|
21
|
-
const value = parseInt(valueStr, 10);
|
|
22
|
-
if (isNaN(value) || value <= 0) {
|
|
23
|
-
throw new Error(`Invalid time value: "${valueStr}". Must be a positive number`);
|
|
24
|
-
}
|
|
25
|
-
const multiplier = this.TIME_UNITS[unit];
|
|
26
|
-
return value * multiplier;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Valida si una cadena de tiempo tiene el formato correcto
|
|
30
|
-
* @param timeString - Cadena de tiempo a validar
|
|
31
|
-
* @returns true si es válida, false en caso contrario
|
|
32
|
-
*/
|
|
33
|
-
static isValidTimeString(timeString) {
|
|
34
|
-
try {
|
|
35
|
-
this.parseToMilliseconds(timeString);
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Obtiene las unidades de tiempo soportadas
|
|
44
|
-
* @returns Array con las unidades soportadas
|
|
45
|
-
*/
|
|
46
|
-
static getSupportedUnits() {
|
|
47
|
-
return Object.keys(this.TIME_UNITS);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Convierte milisegundos a formato legible
|
|
51
|
-
* @param milliseconds - Tiempo en milisegundos
|
|
52
|
-
* @returns Cadena de tiempo legible
|
|
53
|
-
*/
|
|
54
|
-
static formatMilliseconds(milliseconds) {
|
|
55
|
-
const units = [
|
|
56
|
-
{ unit: "d", value: 24 * 60 * 60 * 1000 },
|
|
57
|
-
{ unit: "h", value: 60 * 60 * 1000 },
|
|
58
|
-
{ unit: "m", value: 60 * 1000 },
|
|
59
|
-
{ unit: "s", value: 1000 },
|
|
60
|
-
];
|
|
61
|
-
for (const { unit, value } of units) {
|
|
62
|
-
if (milliseconds >= value && milliseconds % value === 0) {
|
|
63
|
-
return `${milliseconds / value}${unit}`;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return `${milliseconds}ms`;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
exports.TimeParser = TimeParser;
|
|
70
|
-
TimeParser.TIME_UNITS = {
|
|
71
|
-
s: 1000, // segundos
|
|
72
|
-
m: 60 * 1000, // minutos
|
|
73
|
-
h: 60 * 60 * 1000, // horas
|
|
74
|
-
d: 24 * 60 * 60 * 1000, // días
|
|
75
|
-
};
|
|
76
|
-
TimeParser.TIME_PATTERN = /^(\d+)([smhd])$/;
|
/package/dist/{src/application/dtos/login.dto.js → application/dtos/request/login.request.js}
RENAMED
|
File without changes
|
/package/dist/{src/application/dtos/logout.dto.js → application/dtos/request/logout.request.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|