@jmlq/auth 0.0.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +306 -0
- package/dist/examples/bcrypt-password-hasher.example.d.ts +3 -0
- package/dist/examples/bcrypt-password-hasher.example.js +78 -0
- package/dist/examples/entity-object.example.d.ts +39 -0
- package/dist/examples/entity-object.example.js +411 -0
- package/dist/examples/factory-auth-service-example.d.ts +3 -0
- package/dist/examples/factory-auth-service-example.js +84 -0
- package/dist/examples/index.example.d.ts +12 -0
- package/dist/examples/index.example.js +171 -0
- package/dist/examples/jwt-algoritm.example.d.ts +47 -0
- package/dist/examples/jwt-algoritm.example.js +447 -0
- package/dist/examples/jwt-token-generator.example.d.ts +6 -0
- package/dist/examples/jwt-token-generator.example.js +49 -0
- package/dist/examples/jwt-verifier.example.d.ts +3 -0
- package/dist/examples/jwt-verifier.example.js +80 -0
- package/dist/examples/password-policy.example.d.ts +7 -0
- package/dist/examples/password-policy.example.js +57 -0
- package/dist/examples/service-jwt-token.example.d.ts +3 -0
- package/dist/examples/service-jwt-token.example.js +154 -0
- package/dist/examples/service-token-session.example.d.ts +3 -0
- package/dist/examples/service-token-session.example.js +139 -0
- package/dist/examples/use-case-login-with-password.example.d.ts +6 -0
- package/dist/examples/use-case-login-with-password.example.js +105 -0
- package/dist/examples/use-case-logout.example.d.ts +7 -0
- package/dist/examples/use-case-logout.example.js +134 -0
- package/dist/examples/use-case-refresh-token.example.d.ts +11 -0
- package/dist/examples/use-case-refresh-token.example.js +164 -0
- package/dist/examples/use-case-register-user.example.d.ts +9 -0
- package/dist/examples/use-case-register-user.example.js +110 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/src/application/dtos/index.d.ts +4 -0
- package/dist/src/application/dtos/index.js +20 -0
- package/dist/src/application/dtos/login.dto.d.ts +9 -0
- package/dist/src/application/dtos/login.dto.js +2 -0
- package/dist/src/application/dtos/logout.dto.d.ts +7 -0
- package/dist/src/application/dtos/logout.dto.js +2 -0
- package/dist/src/application/dtos/refresh-token.dto.d.ts +7 -0
- package/dist/src/application/dtos/refresh-token.dto.js +2 -0
- package/dist/src/application/dtos/register-user.dto.d.ts +16 -0
- package/dist/src/application/dtos/register-user.dto.js +2 -0
- package/dist/src/application/factories/auth-service.factory.d.ts +5 -0
- package/dist/src/application/factories/auth-service.factory.js +51 -0
- package/dist/src/application/factories/index.d.ts +1 -0
- package/dist/src/application/factories/index.js +17 -0
- package/dist/src/application/index.d.ts +3 -0
- package/dist/src/application/index.js +19 -0
- package/dist/src/application/use-cases/index.d.ts +4 -0
- package/dist/src/application/use-cases/index.js +20 -0
- package/dist/src/application/use-cases/login-with-password.use-case.d.ts +9 -0
- package/dist/src/application/use-cases/login-with-password.use-case.js +36 -0
- package/dist/src/application/use-cases/logout.use-case.d.ts +7 -0
- package/dist/src/application/use-cases/logout.use-case.js +22 -0
- package/dist/src/application/use-cases/refresh-token.use-case.d.ts +7 -0
- package/dist/src/application/use-cases/refresh-token.use-case.js +23 -0
- package/dist/src/application/use-cases/register-user.use-case.d.ts +10 -0
- package/dist/src/application/use-cases/register-user.use-case.js +37 -0
- package/dist/src/domain/entities/credential.entity.d.ts +78 -0
- package/dist/src/domain/entities/credential.entity.js +92 -0
- package/dist/src/domain/entities/index.d.ts +2 -0
- package/dist/src/domain/entities/index.js +18 -0
- package/dist/src/domain/entities/user.entity.d.ts +97 -0
- package/dist/src/domain/entities/user.entity.js +116 -0
- package/dist/src/domain/errors/auth-domain-error.d.ts +82 -0
- package/dist/src/domain/errors/auth-domain-error.js +112 -0
- package/dist/src/domain/errors/auth.errors.d.ts +56 -0
- package/dist/src/domain/errors/auth.errors.js +76 -0
- package/dist/src/domain/errors/identity.errors.d.ts +34 -0
- package/dist/src/domain/errors/identity.errors.js +82 -0
- package/dist/src/domain/errors/index.d.ts +2 -0
- package/dist/src/domain/errors/index.js +18 -0
- package/dist/src/domain/index.d.ts +6 -0
- package/dist/src/domain/index.js +22 -0
- package/dist/src/domain/object-values/email.d.ts +37 -0
- package/dist/src/domain/object-values/email.js +56 -0
- package/dist/src/domain/object-values/hashed-password.d.ts +28 -0
- package/dist/src/domain/object-values/hashed-password.js +73 -0
- package/dist/src/domain/object-values/id.d.ts +8 -0
- package/dist/src/domain/object-values/id.js +28 -0
- package/dist/src/domain/object-values/index.d.ts +5 -0
- package/dist/src/domain/object-values/index.js +13 -0
- package/dist/src/domain/object-values/permission.d.ts +15 -0
- package/dist/src/domain/object-values/permission.js +57 -0
- package/dist/src/domain/object-values/role.d.ts +25 -0
- package/dist/src/domain/object-values/role.js +108 -0
- package/dist/src/domain/ports/auth/password-hasher.d.ts +7 -0
- package/dist/src/domain/ports/auth/password-hasher.js +2 -0
- package/dist/src/domain/ports/auth/password-policy-config.port.d.ts +0 -0
- package/dist/src/domain/ports/auth/password-policy-config.port.js +10 -0
- package/dist/src/domain/ports/auth/password-policy.port.d.ts +10 -0
- package/dist/src/domain/ports/auth/password-policy.port.js +2 -0
- package/dist/src/domain/ports/config/auth-config.port.d.ts +19 -0
- package/dist/src/domain/ports/config/auth-config.port.js +3 -0
- package/dist/src/domain/ports/index.d.ts +9 -0
- package/dist/src/domain/ports/index.js +25 -0
- package/dist/src/domain/ports/jwt/factory/signature-strategy-factory.port.d.ts +14 -0
- package/dist/src/domain/ports/jwt/factory/signature-strategy-factory.port.js +2 -0
- package/dist/src/domain/ports/jwt/payload/jwt-payload.port.d.ts +12 -0
- package/dist/src/domain/ports/jwt/payload/jwt-payload.port.js +2 -0
- package/dist/src/domain/ports/jwt/signature-strategy-factory.port.d.ts +14 -0
- package/dist/src/domain/ports/jwt/signature-strategy-factory.port.js +2 -0
- package/dist/src/domain/ports/jwt/signature-strategy.d.ts +30 -0
- package/dist/src/domain/ports/jwt/signature-strategy.js +4 -0
- package/dist/src/domain/ports/jwt/signature-strategy.port.d.ts +31 -0
- package/dist/src/domain/ports/jwt/signature-strategy.port.js +4 -0
- package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.d.ts +31 -0
- package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.js +4 -0
- package/dist/src/domain/ports/repository/credential.repository.d.ts +10 -0
- package/dist/src/domain/ports/repository/credential.repository.js +2 -0
- package/dist/src/domain/ports/repository/index.d.ts +2 -0
- package/dist/src/domain/ports/repository/index.js +18 -0
- package/dist/src/domain/ports/repository/user.repository.d.ts +13 -0
- package/dist/src/domain/ports/repository/user.repository.js +2 -0
- package/dist/src/domain/ports/token/token-session.port.d.ts +7 -0
- package/dist/src/domain/ports/token/token-session.port.js +2 -0
- package/dist/src/domain/ports/token/token.service.port.d.ts +9 -0
- package/dist/src/domain/ports/token/token.service.port.js +2 -0
- package/dist/src/domain/props/create-payload-props.port.d.ts +0 -0
- package/dist/src/domain/props/create-payload-props.port.js +8 -0
- package/dist/src/domain/props/entities/credential.props.d.ts +8 -0
- package/dist/src/domain/props/entities/credential.props.js +2 -0
- package/dist/src/domain/props/entities/index.d.ts +2 -0
- package/dist/src/domain/props/entities/index.js +18 -0
- package/dist/src/domain/props/entities/user.props.d.ts +10 -0
- package/dist/src/domain/props/entities/user.props.js +2 -0
- package/dist/src/domain/props/index.d.ts +2 -0
- package/dist/src/domain/props/index.js +18 -0
- package/dist/src/domain/props/jwt/create-payload.props.d.ts +9 -0
- package/dist/src/domain/props/jwt/create-payload.props.js +2 -0
- package/dist/src/domain/props/jwt/generate-access-token.props.d.ts +8 -0
- package/dist/src/domain/props/jwt/generate-access-token.props.js +2 -0
- package/dist/src/domain/props/jwt/generate-refresh-token.props.d.ts +8 -0
- package/dist/src/domain/props/jwt/generate-refresh-token.props.js +2 -0
- package/dist/src/domain/props/jwt/generate-token.props.d.ts +10 -0
- package/dist/src/domain/props/jwt/generate-token.props.js +2 -0
- package/dist/src/domain/props/jwt/index.d.ts +5 -0
- package/dist/src/domain/props/jwt/index.js +21 -0
- package/dist/src/domain/props/jwt/jwt-subject.d.ts +7 -0
- package/dist/src/domain/props/jwt/jwt-subject.js +2 -0
- package/dist/src/domain/props/jwt/jwt-user.d.ts +7 -0
- package/dist/src/domain/props/jwt/jwt-user.js +2 -0
- package/dist/src/domain/props/services/generate-access-token.props.d.ts +8 -0
- package/dist/src/domain/props/services/generate-access-token.props.js +2 -0
- package/dist/src/domain/props/services/generate-refresh-token.props.d.ts +8 -0
- package/dist/src/domain/props/services/generate-refresh-token.props.js +2 -0
- package/dist/src/domain/props/services/index.d.ts +2 -0
- package/dist/src/domain/props/services/index.js +18 -0
- package/dist/src/domain/services/index.d.ts +1 -0
- package/dist/src/domain/services/index.js +17 -0
- package/dist/src/domain/services/password-policy.service.d.ts +8 -0
- package/dist/src/domain/services/password-policy.service.js +29 -0
- package/dist/src/domain/services/token.service.port.d.ts +9 -0
- package/dist/src/domain/services/token.service.port.js +2 -0
- package/dist/src/index.d.ts +78 -0
- package/dist/src/index.js +94 -0
- package/dist/src/infrastructure/index.d.ts +5 -0
- package/dist/src/infrastructure/index.js +21 -0
- package/dist/src/infrastructure/jwt/factory/index.d.ts +1 -0
- package/dist/src/infrastructure/jwt/factory/index.js +17 -0
- package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.d.ts +21 -0
- package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.js +61 -0
- package/dist/src/infrastructure/jwt/index.d.ts +3 -0
- package/dist/src/infrastructure/jwt/index.js +19 -0
- package/dist/src/infrastructure/jwt/signature-strategy.factory.d.ts +21 -0
- package/dist/src/infrastructure/jwt/signature-strategy.factory.js +61 -0
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.d.ts +47 -0
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.js +124 -0
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.d.ts +47 -0
- package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.js +124 -0
- package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.d.ts +54 -0
- package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.js +129 -0
- package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.d.ts +54 -0
- package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.js +129 -0
- package/dist/src/infrastructure/jwt/strategies/index.d.ts +3 -0
- package/dist/src/infrastructure/jwt/strategies/index.js +19 -0
- package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.d.ts +47 -0
- package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.js +124 -0
- package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.d.ts +47 -0
- package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.js +124 -0
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.d.ts +57 -0
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.js +123 -0
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.d.ts +59 -0
- package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.js +100 -0
- package/dist/src/infrastructure/jwt/token/index.d.ts +5 -0
- package/dist/src/infrastructure/jwt/token/index.js +21 -0
- package/dist/src/infrastructure/jwt/token/jwt-signer.d.ts +33 -0
- package/dist/src/infrastructure/jwt/token/jwt-signer.js +46 -0
- package/dist/src/infrastructure/jwt/token/jwt-token-parser.d.ts +29 -0
- package/dist/src/infrastructure/jwt/token/jwt-token-parser.js +57 -0
- package/dist/src/infrastructure/jwt/token/jwt-token-validator.d.ts +32 -0
- package/dist/src/infrastructure/jwt/token/jwt-token-validator.js +77 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-signer.d.ts +33 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-signer.js +46 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.d.ts +30 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.js +57 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.d.ts +32 -0
- package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.js +77 -0
- package/dist/src/infrastructure/repositories/index.d.ts +1 -0
- package/dist/src/infrastructure/repositories/index.js +17 -0
- package/dist/src/infrastructure/repositories/test/in-memory-credential.repository.d.ts +12 -0
- package/dist/src/infrastructure/repositories/test/in-memory-credential.repository.js +68 -0
- package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.d.ts +67 -0
- package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.js +128 -0
- package/dist/src/infrastructure/repositories/test/in-memory-user.repository.d.ts +11 -0
- package/dist/src/infrastructure/repositories/test/in-memory-user.repository.js +49 -0
- package/dist/src/infrastructure/repositories/test/index.d.ts +2 -0
- package/dist/src/infrastructure/repositories/test/index.js +18 -0
- package/dist/src/infrastructure/security/bcrypt-password-hasher.d.ts +6 -0
- package/dist/src/infrastructure/security/bcrypt-password-hasher.js +19 -0
- package/dist/src/infrastructure/security/index.d.ts +1 -0
- package/dist/src/infrastructure/security/index.js +17 -0
- package/dist/src/infrastructure/services/default-token-session.service.d.ts +18 -0
- package/dist/src/infrastructure/services/default-token-session.service.js +88 -0
- package/dist/src/infrastructure/services/index.d.ts +2 -0
- package/dist/src/infrastructure/services/index.js +18 -0
- package/dist/src/infrastructure/services/jwt-token.service.d.ts +15 -0
- package/dist/src/infrastructure/services/jwt-token.service.js +44 -0
- package/dist/src/infrastructure/services/simple-jwt-token.service.d.ts +15 -0
- package/dist/src/infrastructure/services/simple-jwt-token.service.js +46 -0
- package/dist/src/infrastructure/services/token-session.service.d.ts +24 -0
- package/dist/src/infrastructure/services/token-session.service.js +131 -0
- package/dist/src/infrastructure/types/auth-service-container.d.ts +14 -0
- package/dist/src/infrastructure/types/auth-service-container.js +2 -0
- package/dist/src/infrastructure/types/index.d.ts +1 -0
- package/dist/src/infrastructure/types/index.js +17 -0
- package/dist/src/shared/constants/index.d.ts +1 -0
- package/dist/src/shared/constants/index.js +17 -0
- package/dist/src/shared/constants/jwt-algorithms.d.ts +17 -0
- package/dist/src/shared/constants/jwt-algorithms.js +23 -0
- package/dist/src/shared/encoders/base64-url-encoder.d.ts +29 -0
- package/dist/src/shared/encoders/base64-url-encoder.js +45 -0
- package/dist/src/shared/encoders/index.d.ts +1 -0
- package/dist/src/shared/encoders/index.js +17 -0
- package/dist/src/shared/index.d.ts +4 -0
- package/dist/src/shared/index.js +20 -0
- package/dist/src/shared/types/index.d.ts +1 -0
- package/dist/src/shared/types/index.js +17 -0
- package/dist/src/shared/types/jwt.d.ts +25 -0
- package/dist/src/shared/types/jwt.js +2 -0
- package/dist/src/shared/types/jwt.types.d.ts +39 -0
- package/dist/src/shared/types/jwt.types.js +2 -0
- package/dist/src/shared/utils/index.d.ts +1 -0
- package/dist/src/shared/utils/index.js +17 -0
- package/dist/src/shared/utils/time-parser.d.ts +28 -0
- package/dist/src/shared/utils/time-parser.js +76 -0
- package/dist/tests/application/factory/auth-service-factory.spec.d.ts +1 -0
- package/dist/tests/application/factory/auth-service-factory.spec.js +97 -0
- package/dist/tests/application/use-cases/login-with-password.integration.spec.d.ts +1 -0
- package/dist/tests/application/use-cases/login-with-password.integration.spec.js +140 -0
- package/dist/tests/application/use-cases/logout-use-case.spec.d.ts +1 -0
- package/dist/tests/application/use-cases/logout-use-case.spec.js +40 -0
- package/dist/tests/application/use-cases/refresh-token-use-case.spec.d.ts +1 -0
- package/dist/tests/application/use-cases/refresh-token-use-case.spec.js +116 -0
- package/dist/tests/application/use-cases/register-user.usecase.spec.d.ts +1 -0
- package/dist/tests/application/use-cases/register-user.usecase.spec.js +151 -0
- package/dist/tests/domain/entities/credential.spec.d.ts +1 -0
- package/dist/tests/domain/entities/credential.spec.js +93 -0
- package/dist/tests/domain/entities/user.spec.d.ts +1 -0
- package/dist/tests/domain/entities/user.spec.js +93 -0
- package/dist/tests/domain/object-values/email.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/email.spec.js +77 -0
- package/dist/tests/domain/object-values/hashed-password.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/hashed-password.spec.js +54 -0
- package/dist/tests/domain/object-values/id.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/id.spec.js +48 -0
- package/dist/tests/domain/object-values/permission.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/permission.spec.js +75 -0
- package/dist/tests/domain/object-values/role.spec.d.ts +1 -0
- package/dist/tests/domain/object-values/role.spec.js +139 -0
- package/dist/tests/domain/services/default-password-policy.spec.d.ts +1 -0
- package/dist/tests/domain/services/default-password-policy.spec.js +69 -0
- package/dist/tests/doman/entities/credential.spec.d.ts +1 -0
- package/dist/tests/doman/entities/credential.spec.js +93 -0
- package/dist/tests/doman/entities/user.spec.d.ts +1 -0
- package/dist/tests/doman/entities/user.spec.js +93 -0
- package/dist/tests/doman/object-values/email.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/email.spec.js +77 -0
- package/dist/tests/doman/object-values/hashed-password.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/hashed-password.spec.js +54 -0
- package/dist/tests/doman/object-values/id.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/id.spec.js +48 -0
- package/dist/tests/doman/object-values/permission.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/permission.spec.js +75 -0
- package/dist/tests/doman/object-values/role.spec.d.ts +1 -0
- package/dist/tests/doman/object-values/role.spec.js +139 -0
- package/dist/tests/helpers/make-jwt-subject.d.ts +7 -0
- package/dist/tests/helpers/make-jwt-subject.js +16 -0
- package/dist/tests/helpers/make-jwt-user.d.ts +7 -0
- package/dist/tests/helpers/make-jwt-user.js +16 -0
- package/dist/tests/helpers/make-user.d.ts +2 -0
- package/dist/tests/helpers/make-user.js +15 -0
- package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.js +127 -0
- package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.js +157 -0
- package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.js +150 -0
- package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.js +156 -0
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.js +179 -0
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.js +142 -0
- package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.js +125 -0
- package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.js +116 -0
- package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.js +88 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.js +126 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.js +116 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.d.ts +1 -0
- package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.js +88 -0
- package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.d.ts +1 -0
- package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.js +37 -0
- package/dist/tests/infrastructure/services/jwt-token-service.spec.d.ts +1 -0
- package/dist/tests/infrastructure/services/jwt-token-service.spec.js +145 -0
- package/dist/tests/infrastructure/services/token-session.service.spec.d.ts +1 -0
- package/dist/tests/infrastructure/services/token-session.service.spec.js +269 -0
- package/dist/tests/shared/constants/jwt-algorithms.spec.d.ts +1 -0
- package/dist/tests/shared/constants/jwt-algorithms.spec.js +27 -0
- package/dist/tests/shared/encoders/base64-url-encoder.spec.d.ts +1 -0
- package/dist/tests/shared/encoders/base64-url-encoder.spec.js +70 -0
- package/dist/tests/shared/utils/time-parser.spec.d.ts +1 -0
- package/dist/tests/shared/utils/time-parser.spec.js +80 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/time-parser.d.ts +28 -0
- package/dist/utils/time-parser.js +76 -0
- package/package.json +48 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./entities"), exports);
|
|
18
|
+
__exportStar(require("./jwt"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { JwtUser } from ".";
|
|
2
|
+
import { JwtTokenServiceConfig } from "../../../shared";
|
|
3
|
+
export interface ICreatePayloadProps {
|
|
4
|
+
user: JwtUser;
|
|
5
|
+
expiresIn: string | undefined;
|
|
6
|
+
defaultExpirationMs: number;
|
|
7
|
+
customClaims?: Record<string, any>;
|
|
8
|
+
config: JwtTokenServiceConfig;
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { JwtUser } from ".";
|
|
2
|
+
import { JwtTokenServiceConfig } from "../../../shared";
|
|
3
|
+
export interface IGenerateTokenProps {
|
|
4
|
+
user: JwtUser;
|
|
5
|
+
expiresIn: string | undefined;
|
|
6
|
+
defaultExpirationMs: number;
|
|
7
|
+
secret: string;
|
|
8
|
+
config: JwtTokenServiceConfig;
|
|
9
|
+
customClaims?: Record<string, any>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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("./create-payload.props"), exports);
|
|
18
|
+
__exportStar(require("./generate-access-token.props"), exports);
|
|
19
|
+
__exportStar(require("./generate-refresh-token.props"), exports);
|
|
20
|
+
__exportStar(require("./generate-token.props"), exports);
|
|
21
|
+
__exportStar(require("./jwt-user"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./generate-access-token.props"), exports);
|
|
18
|
+
__exportStar(require("./generate-refresh-token.props"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./password-policy.service";
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./password-policy.service"), exports);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultPasswordPolicy = void 0;
|
|
4
|
+
class DefaultPasswordPolicy {
|
|
5
|
+
validateStrength(password) {
|
|
6
|
+
const errors = [];
|
|
7
|
+
if (password.length < 8)
|
|
8
|
+
errors.push("Password must be at least 8 characters long");
|
|
9
|
+
if (!/[A-Z]/.test(password))
|
|
10
|
+
errors.push("Password must include at least one uppercase letter");
|
|
11
|
+
if (!/[a-z]/.test(password))
|
|
12
|
+
errors.push("Password must include at least one lowercase letter");
|
|
13
|
+
if (!/\d/.test(password))
|
|
14
|
+
errors.push("Password must include at least one number");
|
|
15
|
+
if (!/[!@#$%^&*]/.test(password))
|
|
16
|
+
errors.push("Password must include at least one special character (!@#$%^&*)");
|
|
17
|
+
return { isValid: errors.length === 0, errors };
|
|
18
|
+
}
|
|
19
|
+
getRequirements() {
|
|
20
|
+
return [
|
|
21
|
+
"Minimum 8 characters",
|
|
22
|
+
"At least one uppercase letter",
|
|
23
|
+
"At least one lowercase letter",
|
|
24
|
+
"At least one number",
|
|
25
|
+
"At least one special character (!@#$%^&*)",
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.DefaultPasswordPolicy = DefaultPasswordPolicy;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IJWTPayload } from "../ports";
|
|
2
|
+
import { IGenerateAccessTokenProps, IGenerateRefreshTokenProps } from "../props";
|
|
3
|
+
export interface ITokenService {
|
|
4
|
+
generateAccessToken(props: IGenerateAccessTokenProps): Promise<string>;
|
|
5
|
+
generateRefreshToken(props: IGenerateRefreshTokenProps): Promise<string>;
|
|
6
|
+
verifyAccessToken(token: string): Promise<IJWTPayload>;
|
|
7
|
+
verifyRefreshToken(token: string): Promise<IJWTPayload>;
|
|
8
|
+
getTokenExpiration(token: string): Promise<Date>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export * from "./application";
|
|
2
|
+
export * from "./domain";
|
|
3
|
+
export * from "./infrastructure";
|
|
4
|
+
export * from "./shared";
|
|
5
|
+
/**
|
|
6
|
+
* Quick Start Example:
|
|
7
|
+
*
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import {
|
|
10
|
+
* AuthServiceFactory,
|
|
11
|
+
* IAuthConfig,
|
|
12
|
+
* InMemoryUserRepository,
|
|
13
|
+
* InMemoryCredentialRepository
|
|
14
|
+
* } from '@ml-dev-core/jwt.auth';
|
|
15
|
+
*
|
|
16
|
+
* const config: IAuthConfig = {
|
|
17
|
+
* jwt: {
|
|
18
|
+
* accessTokenSecret: 'your-secret',
|
|
19
|
+
* refreshTokenSecret: 'your-refresh-secret',
|
|
20
|
+
* accessTokenExpirationMs: 15 * 60 * 1000,
|
|
21
|
+
* refreshTokenExpirationMs: 7 * 24 * 60 * 60 * 1000,
|
|
22
|
+
* accessTokenExpiration: '15m',
|
|
23
|
+
* refreshTokenExpiration: '7d'
|
|
24
|
+
* },
|
|
25
|
+
* bcrypt: { saltRounds: 12 },
|
|
26
|
+
* algorithm: 'HS256',
|
|
27
|
+
* info: {
|
|
28
|
+
* issuer: 'your-app',
|
|
29
|
+
* audience: 'your-client'
|
|
30
|
+
* }
|
|
31
|
+
* };
|
|
32
|
+
*
|
|
33
|
+
* const authServices = AuthServiceFactory.create(
|
|
34
|
+
* config,
|
|
35
|
+
* new InMemoryUserRepository(),
|
|
36
|
+
* new InMemoryCredentialRepository()
|
|
37
|
+
* );
|
|
38
|
+
*
|
|
39
|
+
* // Use authServices.registerUserUseCase, loginWithPasswordUseCase, etc.
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* Quick Start Example:
|
|
44
|
+
*
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import {
|
|
47
|
+
* AuthServiceFactory,
|
|
48
|
+
* IAuthConfig,
|
|
49
|
+
* InMemoryUserRepository,
|
|
50
|
+
* InMemoryCredentialRepository
|
|
51
|
+
* } from '@ml-dev-core/jwt.auth';
|
|
52
|
+
*
|
|
53
|
+
* const config: IAuthConfig = {
|
|
54
|
+
* jwt: {
|
|
55
|
+
* accessTokenSecret: 'your-secret',
|
|
56
|
+
* refreshTokenSecret: 'your-refresh-secret',
|
|
57
|
+
* accessTokenExpirationMs: 15 * 60 * 1000,
|
|
58
|
+
* refreshTokenExpirationMs: 7 * 24 * 60 * 60 * 1000,
|
|
59
|
+
* accessTokenExpiration: '15m',
|
|
60
|
+
* refreshTokenExpiration: '7d'
|
|
61
|
+
* },
|
|
62
|
+
* bcrypt: { saltRounds: 12 },
|
|
63
|
+
* algorithm: 'HS256',
|
|
64
|
+
* info: {
|
|
65
|
+
* issuer: 'your-app',
|
|
66
|
+
* audience: 'your-client'
|
|
67
|
+
* }
|
|
68
|
+
* };
|
|
69
|
+
*
|
|
70
|
+
* const authServices = AuthServiceFactory.create(
|
|
71
|
+
* config,
|
|
72
|
+
* new InMemoryUserRepository(),
|
|
73
|
+
* new InMemoryCredentialRepository()
|
|
74
|
+
* );
|
|
75
|
+
*
|
|
76
|
+
* // Use authServices.registerUserUseCase, loginWithPasswordUseCase, etc.
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
@@ -0,0 +1,94 @@
|
|
|
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("./application"), exports);
|
|
18
|
+
__exportStar(require("./domain"), exports);
|
|
19
|
+
__exportStar(require("./infrastructure"), exports);
|
|
20
|
+
__exportStar(require("./shared"), exports);
|
|
21
|
+
/**
|
|
22
|
+
* Quick Start Example:
|
|
23
|
+
*
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import {
|
|
26
|
+
* AuthServiceFactory,
|
|
27
|
+
* IAuthConfig,
|
|
28
|
+
* InMemoryUserRepository,
|
|
29
|
+
* InMemoryCredentialRepository
|
|
30
|
+
* } from '@ml-dev-core/jwt.auth';
|
|
31
|
+
*
|
|
32
|
+
* const config: IAuthConfig = {
|
|
33
|
+
* jwt: {
|
|
34
|
+
* accessTokenSecret: 'your-secret',
|
|
35
|
+
* refreshTokenSecret: 'your-refresh-secret',
|
|
36
|
+
* accessTokenExpirationMs: 15 * 60 * 1000,
|
|
37
|
+
* refreshTokenExpirationMs: 7 * 24 * 60 * 60 * 1000,
|
|
38
|
+
* accessTokenExpiration: '15m',
|
|
39
|
+
* refreshTokenExpiration: '7d'
|
|
40
|
+
* },
|
|
41
|
+
* bcrypt: { saltRounds: 12 },
|
|
42
|
+
* algorithm: 'HS256',
|
|
43
|
+
* info: {
|
|
44
|
+
* issuer: 'your-app',
|
|
45
|
+
* audience: 'your-client'
|
|
46
|
+
* }
|
|
47
|
+
* };
|
|
48
|
+
*
|
|
49
|
+
* const authServices = AuthServiceFactory.create(
|
|
50
|
+
* config,
|
|
51
|
+
* new InMemoryUserRepository(),
|
|
52
|
+
* new InMemoryCredentialRepository()
|
|
53
|
+
* );
|
|
54
|
+
*
|
|
55
|
+
* // Use authServices.registerUserUseCase, loginWithPasswordUseCase, etc.
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
/**
|
|
59
|
+
* Quick Start Example:
|
|
60
|
+
*
|
|
61
|
+
* ```typescript
|
|
62
|
+
* import {
|
|
63
|
+
* AuthServiceFactory,
|
|
64
|
+
* IAuthConfig,
|
|
65
|
+
* InMemoryUserRepository,
|
|
66
|
+
* InMemoryCredentialRepository
|
|
67
|
+
* } from '@ml-dev-core/jwt.auth';
|
|
68
|
+
*
|
|
69
|
+
* const config: IAuthConfig = {
|
|
70
|
+
* jwt: {
|
|
71
|
+
* accessTokenSecret: 'your-secret',
|
|
72
|
+
* refreshTokenSecret: 'your-refresh-secret',
|
|
73
|
+
* accessTokenExpirationMs: 15 * 60 * 1000,
|
|
74
|
+
* refreshTokenExpirationMs: 7 * 24 * 60 * 60 * 1000,
|
|
75
|
+
* accessTokenExpiration: '15m',
|
|
76
|
+
* refreshTokenExpiration: '7d'
|
|
77
|
+
* },
|
|
78
|
+
* bcrypt: { saltRounds: 12 },
|
|
79
|
+
* algorithm: 'HS256',
|
|
80
|
+
* info: {
|
|
81
|
+
* issuer: 'your-app',
|
|
82
|
+
* audience: 'your-client'
|
|
83
|
+
* }
|
|
84
|
+
* };
|
|
85
|
+
*
|
|
86
|
+
* const authServices = AuthServiceFactory.create(
|
|
87
|
+
* config,
|
|
88
|
+
* new InMemoryUserRepository(),
|
|
89
|
+
* new InMemoryCredentialRepository()
|
|
90
|
+
* );
|
|
91
|
+
*
|
|
92
|
+
* // Use authServices.registerUserUseCase, loginWithPasswordUseCase, etc.
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
@@ -0,0 +1,21 @@
|
|
|
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("./jwt"), exports);
|
|
18
|
+
__exportStar(require("./repositories"), exports);
|
|
19
|
+
__exportStar(require("./security"), exports);
|
|
20
|
+
__exportStar(require("./services"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./signature-strategy.factory";
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./signature-strategy.factory"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ISignatureStrategy, ISignatureStrategyFactory } from "../../../domain/ports";
|
|
2
|
+
import { AlgorithmName, AnyAlgorithm, Base64UrlEncoder } from "../../../shared";
|
|
3
|
+
/**
|
|
4
|
+
* Selector de estrategia de firma JWT (HMAC, RSA, ECDSA).
|
|
5
|
+
* Infraestructura: implementa el port del dominio.
|
|
6
|
+
*/
|
|
7
|
+
export declare class SignatureStrategyFactory implements ISignatureStrategyFactory {
|
|
8
|
+
private readonly encoder;
|
|
9
|
+
constructor(encoder?: Base64UrlEncoder);
|
|
10
|
+
/**
|
|
11
|
+
* Devuelve la lista de algoritmos soportados por este factory.
|
|
12
|
+
*/
|
|
13
|
+
supported(): ReadonlyArray<AlgorithmName>;
|
|
14
|
+
/**
|
|
15
|
+
* Crea la estrategia adecuada según el algoritmo (HS*, RS*, ES*).
|
|
16
|
+
*/
|
|
17
|
+
create(algorithm: AnyAlgorithm): ISignatureStrategy;
|
|
18
|
+
private isHmacAlgorithm;
|
|
19
|
+
private isRsaAlgorithm;
|
|
20
|
+
private isEcdsaAlgorithm;
|
|
21
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignatureStrategyFactory = void 0;
|
|
4
|
+
const domain_1 = require("../../../domain");
|
|
5
|
+
const shared_1 = require("../../../shared");
|
|
6
|
+
const strategies_1 = require("../strategies");
|
|
7
|
+
// Prepara sets para membership rápido (evita recalcular Object.values en cada llamada)
|
|
8
|
+
const HMAC_SET = new Set(Object.values(shared_1.algorithms.hmac));
|
|
9
|
+
const RSA_SET = new Set([
|
|
10
|
+
...Object.values(shared_1.algorithms.rsa),
|
|
11
|
+
// Si soportas PSS (PS256, PS384, PS512), añádelos aquí:
|
|
12
|
+
// ...Object.values(algoritms.rsaPss),
|
|
13
|
+
]);
|
|
14
|
+
const ECDSA_SET = new Set(Object.values(shared_1.algorithms.ecdsa));
|
|
15
|
+
/**
|
|
16
|
+
* Selector de estrategia de firma JWT (HMAC, RSA, ECDSA).
|
|
17
|
+
* Infraestructura: implementa el port del dominio.
|
|
18
|
+
*/
|
|
19
|
+
class SignatureStrategyFactory {
|
|
20
|
+
constructor(encoder = new shared_1.Base64UrlEncoder()) {
|
|
21
|
+
this.encoder = encoder;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Devuelve la lista de algoritmos soportados por este factory.
|
|
25
|
+
*/
|
|
26
|
+
supported() {
|
|
27
|
+
return [
|
|
28
|
+
...Object.values(shared_1.algorithms.hmac),
|
|
29
|
+
...Object.values(shared_1.algorithms.rsa),
|
|
30
|
+
...Object.values(shared_1.algorithms.ecdsa),
|
|
31
|
+
// Si más adelante agregas PSS:
|
|
32
|
+
// ...Object.values(algorithms.rsaPss),
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Crea la estrategia adecuada según el algoritmo (HS*, RS*, ES*).
|
|
37
|
+
*/
|
|
38
|
+
create(algorithm) {
|
|
39
|
+
const alg = algorithm.toUpperCase(); // defensivo
|
|
40
|
+
if (this.isHmacAlgorithm(alg)) {
|
|
41
|
+
return new strategies_1.HmacSignatureStrategy(alg, this.encoder);
|
|
42
|
+
}
|
|
43
|
+
if (this.isRsaAlgorithm(alg)) {
|
|
44
|
+
return new strategies_1.RsaSignatureStrategy(alg, this.encoder);
|
|
45
|
+
}
|
|
46
|
+
if (this.isEcdsaAlgorithm(alg)) {
|
|
47
|
+
return new strategies_1.EcdsaSignatureStrategy(alg, this.encoder);
|
|
48
|
+
}
|
|
49
|
+
throw new domain_1.UnsupportedAlgorithmError(`Unsupported algorithm: ${algorithm}`);
|
|
50
|
+
}
|
|
51
|
+
isHmacAlgorithm(algorithm) {
|
|
52
|
+
return HMAC_SET.has(algorithm);
|
|
53
|
+
}
|
|
54
|
+
isRsaAlgorithm(algorithm) {
|
|
55
|
+
return RSA_SET.has(algorithm);
|
|
56
|
+
}
|
|
57
|
+
isEcdsaAlgorithm(algorithm) {
|
|
58
|
+
return ECDSA_SET.has(algorithm);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.SignatureStrategyFactory = SignatureStrategyFactory;
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./factory"), exports);
|
|
18
|
+
__exportStar(require("./strategies"), exports);
|
|
19
|
+
__exportStar(require("./token"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ISignatureStrategy, ISignatureStrategyFactory } from "../../domain/ports";
|
|
2
|
+
import { AlgorithmName, AnyAlgorithm, Base64UrlEncoder } from "../../shared";
|
|
3
|
+
/**
|
|
4
|
+
* Selector de estrategia de firma JWT (HMAC, RSA, ECDSA).
|
|
5
|
+
* Infraestructura: implementa el port del dominio.
|
|
6
|
+
*/
|
|
7
|
+
export declare class SignatureStrategyFactory implements ISignatureStrategyFactory {
|
|
8
|
+
private readonly encoder;
|
|
9
|
+
constructor(encoder?: Base64UrlEncoder);
|
|
10
|
+
/**
|
|
11
|
+
* Devuelve la lista de algoritmos soportados por este factory.
|
|
12
|
+
*/
|
|
13
|
+
supported(): ReadonlyArray<AlgorithmName>;
|
|
14
|
+
/**
|
|
15
|
+
* Crea la estrategia adecuada según el algoritmo (HS*, RS*, ES*).
|
|
16
|
+
*/
|
|
17
|
+
create(algorithm: AnyAlgorithm): ISignatureStrategy;
|
|
18
|
+
private isHmacAlgorithm;
|
|
19
|
+
private isRsaAlgorithm;
|
|
20
|
+
private isEcdsaAlgorithm;
|
|
21
|
+
}
|