@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.
Files changed (361) hide show
  1. package/README.md +259 -306
  2. package/dist/application/dtos/index.d.ts +3 -0
  3. package/dist/application/dtos/index.js +19 -0
  4. package/dist/application/dtos/request/index.d.ts +4 -0
  5. package/dist/{src/application/dtos → application/dtos/request}/index.js +4 -4
  6. package/dist/{src/application/dtos/login.dto.d.ts → application/dtos/request/login.request.d.ts} +0 -4
  7. package/dist/application/dtos/request/logout.request.d.ts +3 -0
  8. package/dist/application/dtos/request/refresh-token.request.d.ts +3 -0
  9. package/dist/application/dtos/request/register-user.request.d.ts +6 -0
  10. package/dist/application/dtos/response/index.d.ts +4 -0
  11. package/dist/application/dtos/response/index.js +20 -0
  12. package/dist/application/dtos/response/login.response.d.ts +4 -0
  13. package/dist/{src/application/dtos/logout.dto.d.ts → application/dtos/response/logout.response.d.ts} +0 -3
  14. package/dist/{src/application/dtos/refresh-token.dto.d.ts → application/dtos/response/refresh-token.response.d.ts} +0 -3
  15. package/dist/application/dtos/response/register-user.response.d.ts +7 -0
  16. package/dist/application/dtos/type/index.d.ts +1 -0
  17. package/dist/{src/shared/constants → application/dtos/type}/index.js +1 -1
  18. package/dist/application/dtos/type/user-role.type.d.ts +4 -0
  19. package/dist/application/factories/auth-service.factory.d.ts +11 -0
  20. package/dist/application/factories/auth-service.factory.js +40 -0
  21. package/dist/{src/application → application}/index.d.ts +1 -0
  22. package/dist/{src/application → application}/index.js +1 -0
  23. package/dist/application/types/auth-service-factory-options.type.d.ts +5 -0
  24. package/dist/application/types/index.d.ts +1 -0
  25. package/dist/{src/infrastructure/jwt/factory → application/types}/index.js +1 -1
  26. package/dist/{src/application → application}/use-cases/login-with-password.use-case.d.ts +2 -2
  27. package/dist/{src/application → application}/use-cases/login-with-password.use-case.js +6 -5
  28. package/dist/{src/application → application}/use-cases/logout.use-case.d.ts +2 -2
  29. package/dist/{src/application → application}/use-cases/logout.use-case.js +2 -2
  30. package/dist/{src/application → application}/use-cases/refresh-token.use-case.d.ts +2 -2
  31. package/dist/{src/application → application}/use-cases/refresh-token.use-case.js +2 -2
  32. package/dist/application/use-cases/register-user.use-case.d.ts +12 -0
  33. package/dist/{src/application → application}/use-cases/register-user.use-case.js +27 -1
  34. package/dist/{src/domain → domain}/errors/auth.errors.d.ts +1 -14
  35. package/dist/{src/domain → domain}/errors/auth.errors.js +1 -15
  36. package/dist/{src/domain → domain}/index.d.ts +0 -1
  37. package/dist/{src/domain → domain}/index.js +0 -1
  38. package/dist/domain/ports/auth/index.d.ts +2 -0
  39. package/dist/domain/ports/auth/index.js +18 -0
  40. package/dist/{src/domain/ports/auth/password-hasher.d.ts → domain/ports/auth/password-hasher.port.d.ts} +1 -1
  41. package/dist/{src/domain → domain}/ports/auth/password-policy.port.d.ts +1 -1
  42. package/dist/domain/ports/index.d.ts +4 -0
  43. package/dist/{src/infrastructure/jwt → domain/ports}/index.js +3 -2
  44. package/dist/domain/ports/jwt/index.d.ts +1 -0
  45. package/dist/{src/shared/types → domain/ports/jwt}/index.js +1 -1
  46. package/dist/domain/ports/jwt/payload/index.d.ts +1 -0
  47. package/dist/domain/ports/jwt/payload/index.js +17 -0
  48. package/dist/{src/domain → domain}/ports/repository/credential.repository.d.ts +1 -1
  49. package/dist/{src/domain → domain}/ports/repository/index.d.ts +1 -1
  50. package/dist/{src/domain → domain}/ports/repository/index.js +1 -1
  51. package/dist/{src/domain/ports/repository/user.repository.d.ts → domain/ports/repository/user-repository.port.d.ts} +1 -1
  52. package/dist/domain/ports/token/index.d.ts +2 -0
  53. package/dist/domain/ports/token/index.js +18 -0
  54. package/dist/{src/domain → domain}/ports/token/token-session.port.d.ts +2 -2
  55. package/dist/{src/domain → domain}/ports/token/token.service.port.d.ts +2 -2
  56. package/dist/{src/domain → domain}/props/jwt/generate-access-token.props.d.ts +0 -2
  57. package/dist/{src/domain → domain}/props/jwt/generate-refresh-token.props.d.ts +0 -2
  58. package/dist/{src/domain/props/services → domain/props/jwt}/index.d.ts +1 -0
  59. package/dist/{src/domain/props/services → domain/props/jwt}/index.js +1 -0
  60. package/dist/{src/domain → domain}/services/password-policy.service.d.ts +2 -2
  61. package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-credential.repository.d.ts +2 -2
  62. package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-credential.repository.js +12 -2
  63. package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-user.repository.d.ts +2 -2
  64. package/dist/index.d.ts +5 -1
  65. package/dist/index.js +13 -1
  66. package/dist/infrastructure/index.js +1 -0
  67. package/dist/{src/infrastructure → infrastructure}/security/bcrypt-password-hasher.d.ts +7 -2
  68. package/dist/{src/infrastructure → infrastructure}/security/bcrypt-password-hasher.js +7 -2
  69. package/dist/{src/infrastructure → infrastructure}/services/index.d.ts +0 -1
  70. package/dist/{src/infrastructure → infrastructure}/services/index.js +0 -1
  71. package/dist/infrastructure/services/token-session.service.d.ts +22 -0
  72. package/dist/{src/infrastructure/services/default-token-session.service.js → infrastructure/services/token-session.service.js} +30 -31
  73. package/dist/infrastructure/types/auth-service-container.d.ts +14 -0
  74. package/dist/shared/index.d.ts +1 -0
  75. package/dist/{src/infrastructure/repositories → shared}/index.js +1 -1
  76. package/package.json +5 -8
  77. package/dist/examples/bcrypt-password-hasher.example.d.ts +0 -3
  78. package/dist/examples/bcrypt-password-hasher.example.js +0 -78
  79. package/dist/examples/entity-object.example.d.ts +0 -39
  80. package/dist/examples/entity-object.example.js +0 -411
  81. package/dist/examples/factory-auth-service-example.d.ts +0 -3
  82. package/dist/examples/factory-auth-service-example.js +0 -84
  83. package/dist/examples/index.example.d.ts +0 -12
  84. package/dist/examples/index.example.js +0 -171
  85. package/dist/examples/jwt-algoritm.example.d.ts +0 -47
  86. package/dist/examples/jwt-algoritm.example.js +0 -447
  87. package/dist/examples/jwt-token-generator.example.d.ts +0 -6
  88. package/dist/examples/jwt-token-generator.example.js +0 -49
  89. package/dist/examples/jwt-verifier.example.d.ts +0 -3
  90. package/dist/examples/jwt-verifier.example.js +0 -80
  91. package/dist/examples/password-policy.example.d.ts +0 -7
  92. package/dist/examples/password-policy.example.js +0 -57
  93. package/dist/examples/service-jwt-token.example.d.ts +0 -3
  94. package/dist/examples/service-jwt-token.example.js +0 -154
  95. package/dist/examples/service-token-session.example.d.ts +0 -3
  96. package/dist/examples/service-token-session.example.js +0 -139
  97. package/dist/examples/use-case-login-with-password.example.d.ts +0 -6
  98. package/dist/examples/use-case-login-with-password.example.js +0 -105
  99. package/dist/examples/use-case-logout.example.d.ts +0 -7
  100. package/dist/examples/use-case-logout.example.js +0 -134
  101. package/dist/examples/use-case-refresh-token.example.d.ts +0 -11
  102. package/dist/examples/use-case-refresh-token.example.js +0 -164
  103. package/dist/examples/use-case-register-user.example.d.ts +0 -9
  104. package/dist/examples/use-case-register-user.example.js +0 -110
  105. package/dist/src/application/dtos/index.d.ts +0 -4
  106. package/dist/src/application/dtos/register-user.dto.d.ts +0 -16
  107. package/dist/src/application/factories/auth-service.factory.d.ts +0 -5
  108. package/dist/src/application/factories/auth-service.factory.js +0 -51
  109. package/dist/src/application/use-cases/register-user.use-case.d.ts +0 -10
  110. package/dist/src/domain/errors/auth-domain-error.d.ts +0 -82
  111. package/dist/src/domain/errors/auth-domain-error.js +0 -112
  112. package/dist/src/domain/ports/auth/password-policy-config.port.js +0 -10
  113. package/dist/src/domain/ports/config/auth-config.port.d.ts +0 -19
  114. package/dist/src/domain/ports/config/auth-config.port.js +0 -3
  115. package/dist/src/domain/ports/index.d.ts +0 -9
  116. package/dist/src/domain/ports/index.js +0 -25
  117. package/dist/src/domain/ports/jwt/factory/signature-strategy-factory.port.d.ts +0 -14
  118. package/dist/src/domain/ports/jwt/signature-strategy-factory.port.d.ts +0 -14
  119. package/dist/src/domain/ports/jwt/signature-strategy.d.ts +0 -30
  120. package/dist/src/domain/ports/jwt/signature-strategy.js +0 -4
  121. package/dist/src/domain/ports/jwt/signature-strategy.port.d.ts +0 -31
  122. package/dist/src/domain/ports/jwt/signature-strategy.port.js +0 -4
  123. package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.d.ts +0 -31
  124. package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.js +0 -4
  125. package/dist/src/domain/props/create-payload-props.port.d.ts +0 -0
  126. package/dist/src/domain/props/create-payload-props.port.js +0 -8
  127. package/dist/src/domain/props/jwt/create-payload.props.d.ts +0 -9
  128. package/dist/src/domain/props/jwt/generate-token.props.d.ts +0 -10
  129. package/dist/src/domain/props/jwt/generate-token.props.js +0 -2
  130. package/dist/src/domain/props/jwt/index.d.ts +0 -5
  131. package/dist/src/domain/props/jwt/index.js +0 -21
  132. package/dist/src/domain/props/jwt/jwt-subject.d.ts +0 -7
  133. package/dist/src/domain/props/jwt/jwt-subject.js +0 -2
  134. package/dist/src/domain/props/services/generate-access-token.props.d.ts +0 -8
  135. package/dist/src/domain/props/services/generate-refresh-token.props.d.ts +0 -8
  136. package/dist/src/domain/services/token.service.port.d.ts +0 -9
  137. package/dist/src/index.d.ts +0 -78
  138. package/dist/src/index.js +0 -94
  139. package/dist/src/infrastructure/index.d.ts +0 -5
  140. package/dist/src/infrastructure/index.js +0 -21
  141. package/dist/src/infrastructure/jwt/factory/index.d.ts +0 -1
  142. package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.d.ts +0 -21
  143. package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.js +0 -61
  144. package/dist/src/infrastructure/jwt/index.d.ts +0 -3
  145. package/dist/src/infrastructure/jwt/signature-strategy.factory.d.ts +0 -21
  146. package/dist/src/infrastructure/jwt/signature-strategy.factory.js +0 -61
  147. package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.d.ts +0 -47
  148. package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.js +0 -124
  149. package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.d.ts +0 -47
  150. package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.js +0 -124
  151. package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.d.ts +0 -54
  152. package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.js +0 -129
  153. package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.d.ts +0 -54
  154. package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.js +0 -129
  155. package/dist/src/infrastructure/jwt/strategies/index.d.ts +0 -3
  156. package/dist/src/infrastructure/jwt/strategies/index.js +0 -19
  157. package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.d.ts +0 -47
  158. package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.js +0 -124
  159. package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.d.ts +0 -47
  160. package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.js +0 -124
  161. package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.d.ts +0 -57
  162. package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.js +0 -123
  163. package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.d.ts +0 -59
  164. package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.js +0 -100
  165. package/dist/src/infrastructure/jwt/token/index.d.ts +0 -5
  166. package/dist/src/infrastructure/jwt/token/index.js +0 -21
  167. package/dist/src/infrastructure/jwt/token/jwt-signer.d.ts +0 -33
  168. package/dist/src/infrastructure/jwt/token/jwt-signer.js +0 -46
  169. package/dist/src/infrastructure/jwt/token/jwt-token-parser.d.ts +0 -29
  170. package/dist/src/infrastructure/jwt/token/jwt-token-parser.js +0 -57
  171. package/dist/src/infrastructure/jwt/token/jwt-token-validator.d.ts +0 -32
  172. package/dist/src/infrastructure/jwt/token/jwt-token-validator.js +0 -77
  173. package/dist/src/infrastructure/jwt/token/tools/jwt-signer.d.ts +0 -33
  174. package/dist/src/infrastructure/jwt/token/tools/jwt-signer.js +0 -46
  175. package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.d.ts +0 -30
  176. package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.js +0 -57
  177. package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.d.ts +0 -32
  178. package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.js +0 -77
  179. package/dist/src/infrastructure/repositories/index.d.ts +0 -1
  180. package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.d.ts +0 -67
  181. package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.js +0 -128
  182. package/dist/src/infrastructure/services/default-token-session.service.d.ts +0 -18
  183. package/dist/src/infrastructure/services/jwt-token.service.d.ts +0 -15
  184. package/dist/src/infrastructure/services/jwt-token.service.js +0 -44
  185. package/dist/src/infrastructure/services/simple-jwt-token.service.d.ts +0 -15
  186. package/dist/src/infrastructure/services/simple-jwt-token.service.js +0 -46
  187. package/dist/src/infrastructure/services/token-session.service.d.ts +0 -24
  188. package/dist/src/infrastructure/services/token-session.service.js +0 -131
  189. package/dist/src/infrastructure/types/auth-service-container.d.ts +0 -14
  190. package/dist/src/shared/constants/index.d.ts +0 -1
  191. package/dist/src/shared/constants/jwt-algorithms.d.ts +0 -17
  192. package/dist/src/shared/constants/jwt-algorithms.js +0 -23
  193. package/dist/src/shared/encoders/base64-url-encoder.d.ts +0 -29
  194. package/dist/src/shared/encoders/base64-url-encoder.js +0 -45
  195. package/dist/src/shared/encoders/index.d.ts +0 -1
  196. package/dist/src/shared/encoders/index.js +0 -17
  197. package/dist/src/shared/index.d.ts +0 -4
  198. package/dist/src/shared/index.js +0 -20
  199. package/dist/src/shared/types/index.d.ts +0 -1
  200. package/dist/src/shared/types/jwt.d.ts +0 -25
  201. package/dist/src/shared/types/jwt.js +0 -2
  202. package/dist/src/shared/types/jwt.types.d.ts +0 -39
  203. package/dist/src/shared/types/jwt.types.js +0 -2
  204. package/dist/tests/application/factory/auth-service-factory.spec.d.ts +0 -1
  205. package/dist/tests/application/factory/auth-service-factory.spec.js +0 -97
  206. package/dist/tests/application/use-cases/login-with-password.integration.spec.d.ts +0 -1
  207. package/dist/tests/application/use-cases/login-with-password.integration.spec.js +0 -140
  208. package/dist/tests/application/use-cases/logout-use-case.spec.d.ts +0 -1
  209. package/dist/tests/application/use-cases/logout-use-case.spec.js +0 -40
  210. package/dist/tests/application/use-cases/refresh-token-use-case.spec.d.ts +0 -1
  211. package/dist/tests/application/use-cases/refresh-token-use-case.spec.js +0 -116
  212. package/dist/tests/application/use-cases/register-user.usecase.spec.d.ts +0 -1
  213. package/dist/tests/application/use-cases/register-user.usecase.spec.js +0 -151
  214. package/dist/tests/domain/entities/credential.spec.d.ts +0 -1
  215. package/dist/tests/domain/entities/credential.spec.js +0 -93
  216. package/dist/tests/domain/entities/user.spec.d.ts +0 -1
  217. package/dist/tests/domain/entities/user.spec.js +0 -93
  218. package/dist/tests/domain/object-values/email.spec.d.ts +0 -1
  219. package/dist/tests/domain/object-values/email.spec.js +0 -77
  220. package/dist/tests/domain/object-values/hashed-password.spec.d.ts +0 -1
  221. package/dist/tests/domain/object-values/hashed-password.spec.js +0 -54
  222. package/dist/tests/domain/object-values/id.spec.d.ts +0 -1
  223. package/dist/tests/domain/object-values/id.spec.js +0 -48
  224. package/dist/tests/domain/object-values/permission.spec.d.ts +0 -1
  225. package/dist/tests/domain/object-values/permission.spec.js +0 -75
  226. package/dist/tests/domain/object-values/role.spec.d.ts +0 -1
  227. package/dist/tests/domain/object-values/role.spec.js +0 -139
  228. package/dist/tests/domain/services/default-password-policy.spec.d.ts +0 -1
  229. package/dist/tests/domain/services/default-password-policy.spec.js +0 -69
  230. package/dist/tests/doman/entities/credential.spec.d.ts +0 -1
  231. package/dist/tests/doman/entities/credential.spec.js +0 -93
  232. package/dist/tests/doman/entities/user.spec.d.ts +0 -1
  233. package/dist/tests/doman/entities/user.spec.js +0 -93
  234. package/dist/tests/doman/object-values/email.spec.d.ts +0 -1
  235. package/dist/tests/doman/object-values/email.spec.js +0 -77
  236. package/dist/tests/doman/object-values/hashed-password.spec.d.ts +0 -1
  237. package/dist/tests/doman/object-values/hashed-password.spec.js +0 -54
  238. package/dist/tests/doman/object-values/id.spec.d.ts +0 -1
  239. package/dist/tests/doman/object-values/id.spec.js +0 -48
  240. package/dist/tests/doman/object-values/permission.spec.d.ts +0 -1
  241. package/dist/tests/doman/object-values/permission.spec.js +0 -75
  242. package/dist/tests/doman/object-values/role.spec.d.ts +0 -1
  243. package/dist/tests/doman/object-values/role.spec.js +0 -139
  244. package/dist/tests/helpers/make-jwt-subject.d.ts +0 -7
  245. package/dist/tests/helpers/make-jwt-subject.js +0 -16
  246. package/dist/tests/helpers/make-jwt-user.d.ts +0 -7
  247. package/dist/tests/helpers/make-jwt-user.js +0 -16
  248. package/dist/tests/helpers/make-user.d.ts +0 -2
  249. package/dist/tests/helpers/make-user.js +0 -15
  250. package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.d.ts +0 -1
  251. package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.js +0 -127
  252. package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.d.ts +0 -1
  253. package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.js +0 -157
  254. package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.d.ts +0 -1
  255. package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.js +0 -150
  256. package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.d.ts +0 -1
  257. package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.js +0 -156
  258. package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.d.ts +0 -1
  259. package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.js +0 -179
  260. package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.d.ts +0 -1
  261. package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.js +0 -142
  262. package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.d.ts +0 -1
  263. package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.js +0 -125
  264. package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.d.ts +0 -1
  265. package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.js +0 -116
  266. package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.d.ts +0 -1
  267. package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.js +0 -88
  268. package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.d.ts +0 -1
  269. package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.js +0 -126
  270. package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.d.ts +0 -1
  271. package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.js +0 -116
  272. package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.d.ts +0 -1
  273. package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.js +0 -88
  274. package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.d.ts +0 -1
  275. package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.js +0 -37
  276. package/dist/tests/infrastructure/services/jwt-token-service.spec.d.ts +0 -1
  277. package/dist/tests/infrastructure/services/jwt-token-service.spec.js +0 -145
  278. package/dist/tests/infrastructure/services/token-session.service.spec.d.ts +0 -1
  279. package/dist/tests/infrastructure/services/token-session.service.spec.js +0 -269
  280. package/dist/tests/shared/constants/jwt-algorithms.spec.d.ts +0 -1
  281. package/dist/tests/shared/constants/jwt-algorithms.spec.js +0 -27
  282. package/dist/tests/shared/encoders/base64-url-encoder.spec.d.ts +0 -1
  283. package/dist/tests/shared/encoders/base64-url-encoder.spec.js +0 -70
  284. package/dist/tests/shared/utils/time-parser.spec.d.ts +0 -1
  285. package/dist/tests/shared/utils/time-parser.spec.js +0 -80
  286. package/dist/utils/index.d.ts +0 -1
  287. package/dist/utils/index.js +0 -17
  288. package/dist/utils/time-parser.d.ts +0 -28
  289. package/dist/utils/time-parser.js +0 -76
  290. /package/dist/{src/application/dtos/login.dto.js → application/dtos/request/login.request.js} +0 -0
  291. /package/dist/{src/application/dtos/logout.dto.js → application/dtos/request/logout.request.js} +0 -0
  292. /package/dist/{src/application/dtos/refresh-token.dto.js → application/dtos/request/refresh-token.request.js} +0 -0
  293. /package/dist/{src/application/dtos/register-user.dto.js → application/dtos/request/register-user.request.js} +0 -0
  294. /package/dist/{src/domain/ports/auth/password-hasher.js → application/dtos/response/login.response.js} +0 -0
  295. /package/dist/{src/domain/ports/auth/password-policy.port.js → application/dtos/response/logout.response.js} +0 -0
  296. /package/dist/{src/domain/ports/jwt/factory/signature-strategy-factory.port.js → application/dtos/response/refresh-token.response.js} +0 -0
  297. /package/dist/{src/domain/ports/jwt/payload/jwt-payload.port.js → application/dtos/response/register-user.response.js} +0 -0
  298. /package/dist/{src/domain/ports/jwt/signature-strategy-factory.port.js → application/dtos/type/user-role.type.js} +0 -0
  299. /package/dist/{src/application → application}/factories/index.d.ts +0 -0
  300. /package/dist/{src/application → application}/factories/index.js +0 -0
  301. /package/dist/{src/domain/ports/repository/credential.repository.js → application/types/auth-service-factory-options.type.js} +0 -0
  302. /package/dist/{src/application → application}/use-cases/index.d.ts +0 -0
  303. /package/dist/{src/application → application}/use-cases/index.js +0 -0
  304. /package/dist/{src/domain → domain}/entities/credential.entity.d.ts +0 -0
  305. /package/dist/{src/domain → domain}/entities/credential.entity.js +0 -0
  306. /package/dist/{src/domain → domain}/entities/index.d.ts +0 -0
  307. /package/dist/{src/domain → domain}/entities/index.js +0 -0
  308. /package/dist/{src/domain → domain}/entities/user.entity.d.ts +0 -0
  309. /package/dist/{src/domain → domain}/entities/user.entity.js +0 -0
  310. /package/dist/{src/domain → domain}/errors/identity.errors.d.ts +0 -0
  311. /package/dist/{src/domain → domain}/errors/identity.errors.js +0 -0
  312. /package/dist/{src/domain → domain}/errors/index.d.ts +0 -0
  313. /package/dist/{src/domain → domain}/errors/index.js +0 -0
  314. /package/dist/{src/domain → domain}/object-values/email.d.ts +0 -0
  315. /package/dist/{src/domain → domain}/object-values/email.js +0 -0
  316. /package/dist/{src/domain → domain}/object-values/hashed-password.d.ts +0 -0
  317. /package/dist/{src/domain → domain}/object-values/hashed-password.js +0 -0
  318. /package/dist/{src/domain → domain}/object-values/id.d.ts +0 -0
  319. /package/dist/{src/domain → domain}/object-values/id.js +0 -0
  320. /package/dist/{src/domain → domain}/object-values/index.d.ts +0 -0
  321. /package/dist/{src/domain → domain}/object-values/index.js +0 -0
  322. /package/dist/{src/domain → domain}/object-values/permission.d.ts +0 -0
  323. /package/dist/{src/domain → domain}/object-values/permission.js +0 -0
  324. /package/dist/{src/domain → domain}/object-values/role.d.ts +0 -0
  325. /package/dist/{src/domain → domain}/object-values/role.js +0 -0
  326. /package/dist/{src/domain/ports/repository/user.repository.js → domain/ports/auth/password-hasher.port.js} +0 -0
  327. /package/dist/{src/domain/ports/token/token-session.port.js → domain/ports/auth/password-policy.port.js} +0 -0
  328. /package/dist/{src/domain → domain}/ports/jwt/payload/jwt-payload.port.d.ts +0 -0
  329. /package/dist/{src/domain/ports/token/token.service.port.js → domain/ports/jwt/payload/jwt-payload.port.js} +0 -0
  330. /package/dist/{src/domain/props/entities/credential.props.js → domain/ports/repository/credential.repository.js} +0 -0
  331. /package/dist/{src/domain/props/entities/user.props.js → domain/ports/repository/user-repository.port.js} +0 -0
  332. /package/dist/{src/domain/props/jwt/create-payload.props.js → domain/ports/token/token-session.port.js} +0 -0
  333. /package/dist/{src/domain/services → domain/ports/token}/token.service.port.js +0 -0
  334. /package/dist/{src/domain → domain}/props/entities/credential.props.d.ts +0 -0
  335. /package/dist/{src/domain/props/jwt/generate-access-token.props.js → domain/props/entities/credential.props.js} +0 -0
  336. /package/dist/{src/domain → domain}/props/entities/index.d.ts +0 -0
  337. /package/dist/{src/domain → domain}/props/entities/index.js +0 -0
  338. /package/dist/{src/domain → domain}/props/entities/user.props.d.ts +0 -0
  339. /package/dist/{src/domain/props/jwt/generate-refresh-token.props.js → domain/props/entities/user.props.js} +0 -0
  340. /package/dist/{src/domain → domain}/props/index.d.ts +0 -0
  341. /package/dist/{src/domain → domain}/props/index.js +0 -0
  342. /package/dist/{src/domain/props/services → domain/props/jwt}/generate-access-token.props.js +0 -0
  343. /package/dist/{src/domain/props/services → domain/props/jwt}/generate-refresh-token.props.js +0 -0
  344. /package/dist/{src/domain → domain}/props/jwt/jwt-user.d.ts +0 -0
  345. /package/dist/{src/domain → domain}/props/jwt/jwt-user.js +0 -0
  346. /package/dist/{src/domain → domain}/services/index.d.ts +0 -0
  347. /package/dist/{src/domain → domain}/services/index.js +0 -0
  348. /package/dist/{src/domain → domain}/services/password-policy.service.js +0 -0
  349. /package/dist/{src/infrastructure/repositories/test → in-memory}/in-memory-user.repository.js +0 -0
  350. /package/dist/{src/infrastructure/repositories/test → in-memory}/index.d.ts +0 -0
  351. /package/dist/{src/infrastructure/repositories/test → in-memory}/index.js +0 -0
  352. /package/dist/{src/domain/ports/auth/password-policy-config.port.d.ts → infrastructure/index.d.ts} +0 -0
  353. /package/dist/{src/infrastructure → infrastructure}/security/index.d.ts +0 -0
  354. /package/dist/{src/infrastructure → infrastructure}/security/index.js +0 -0
  355. /package/dist/{src/infrastructure → infrastructure}/types/auth-service-container.js +0 -0
  356. /package/dist/{src/infrastructure → infrastructure}/types/index.d.ts +0 -0
  357. /package/dist/{src/infrastructure → infrastructure}/types/index.js +0 -0
  358. /package/dist/{src/shared → shared}/utils/index.d.ts +0 -0
  359. /package/dist/{src/shared → shared}/utils/index.js +0 -0
  360. /package/dist/{src/shared → shared}/utils/time-parser.d.ts +0 -0
  361. /package/dist/{src/shared → shared}/utils/time-parser.js +0 -0
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const errors_1 = require("../../../src/domain/errors");
4
- const hashed_password_1 = require("../../../src/domain/object-values/hashed-password");
5
- // Tests para HashedPassword
6
- describe("HashedPassword", () => {
7
- // Genera la cola de 53 caracteres válidos para bcrypt
8
- const makePayload = (c = "A") => c.repeat(53);
9
- // Genera un hash bcrypt válido con cost y prefijo dados
10
- const makeHash = (cost, prefix = "2b") => `$${prefix}$${String(cost).padStart(2, "0")}$${makePayload()}`;
11
- // Casos de prueba
12
- it("lanza error si el hash es null", () => {
13
- // Prueba para null
14
- expect(() => new hashed_password_1.HashedPassword(null)).toThrow(new errors_1.InvalidHashedPasswordError("Hashed password cannot be null or undefined"));
15
- });
16
- // Prueba para undefined
17
- it("lanza error si el hash es undefined", () => {
18
- expect(() => new hashed_password_1.HashedPassword(undefined)).toThrow(new errors_1.InvalidHashedPasswordError("Hashed password cannot be null or undefined"));
19
- });
20
- // Prueba para cadena vacía
21
- it("lanza error si el hash está vacío", () => {
22
- expect(() => new hashed_password_1.HashedPassword(" ")).toThrow(new errors_1.InvalidHashedPasswordError("Hashed password cannot be empty"));
23
- });
24
- // Prueba para formato inválido
25
- it("lanza error si el hash no tiene formato bcrypt válido", () => {
26
- // Falta un carácter (52 en lugar de 53) → rompe el regex
27
- const invalidFormat = `$2b$10$${"A".repeat(52)}`;
28
- // Ejecutar prueba
29
- expect(() => new hashed_password_1.HashedPassword(invalidFormat)).toThrow(new errors_1.InvalidHashedPasswordError("Invalid bcrypt hash format"));
30
- });
31
- // Prueba para cost factor inválido (menor a 4)
32
- it("lanza error si el cost factor es menor a 4", () => {
33
- // Generar hash con cost factor 3
34
- const lowCost = makeHash(3); // "03"
35
- // Ejecutar prueba
36
- expect(() => new hashed_password_1.HashedPassword(lowCost)).toThrow(new errors_1.InvalidHashedPasswordError("Invalid bcrypt cost factor"));
37
- });
38
- // Prueba para cost factor inválido (mayor a 31)
39
- it("lanza error si el cost factor es mayor a 31", () => {
40
- const highCost = makeHash(32); // "32"
41
- // Ejecutar prueba
42
- expect(() => new hashed_password_1.HashedPassword(highCost)).toThrow(new errors_1.InvalidHashedPasswordError("Invalid bcrypt cost factor"));
43
- });
44
- it("crea instancia válida con hash correcto", () => {
45
- const valid = makeHash(10); // dentro de [4..31]
46
- const hashed = new hashed_password_1.HashedPassword(valid);
47
- expect(hashed.value).toBe(valid);
48
- });
49
- it("trimea espacios y sigue válido", () => {
50
- const valid = ` ${makeHash(12)} `;
51
- const hashed = new hashed_password_1.HashedPassword(valid);
52
- expect(hashed.value).toBe(valid.trim());
53
- });
54
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const errors_1 = require("../../../src/domain/errors");
4
- const id_1 = require("../../../src/domain/object-values/id");
5
- describe("Id (Value Object)", () => {
6
- describe("constructor", () => {
7
- it.each([null, undefined, "", " "])("lanza error si id es inválido (%p)", (invalid) => {
8
- expect(() => new id_1.Id(invalid)).toThrowError(new errors_1.InvalidIdError("User ID cannot be empty"));
9
- });
10
- it("trimea espacios y guarda el valor limpio", () => {
11
- const id = new id_1.Id(" user-123 ");
12
- expect(id.getValue()).toBe("user-123");
13
- expect(id.toString()).toBe("user-123");
14
- });
15
- });
16
- describe("equals", () => {
17
- it("retorna true para Id con mismo valor", () => {
18
- const a = new id_1.Id("abc123");
19
- const b = new id_1.Id("abc123");
20
- expect(a.equals(b)).toBe(true);
21
- });
22
- it("retorna false para Id con valores diferentes", () => {
23
- const a = new id_1.Id("abc123");
24
- const b = new id_1.Id("xyz789");
25
- expect(a.equals(b)).toBe(false);
26
- });
27
- });
28
- describe("generate", () => {
29
- it("crea un Id válido no vacío", () => {
30
- const id = id_1.Id.generate();
31
- const value = id.getValue();
32
- expect(typeof value).toBe("string");
33
- expect(value.length).toBeGreaterThan(0);
34
- expect(id).toBeInstanceOf(id_1.Id);
35
- });
36
- it("genera IDs distintos en llamadas separadas", () => {
37
- const id1 = id_1.Id.generate().getValue();
38
- const id2 = id_1.Id.generate().getValue();
39
- expect(id1).not.toBe(id2);
40
- });
41
- it("el formato incluye timestamp y parte aleatoria", () => {
42
- const id = id_1.Id.generate().getValue();
43
- const [timestamp, random] = id.split("-");
44
- expect(!isNaN(Number(timestamp))).toBe(true);
45
- expect(random).toMatch(/^[a-z0-9]+$/);
46
- });
47
- });
48
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const errors_1 = require("../../../src/domain/errors");
4
- const permission_1 = require("../../../src/domain/object-values/permission");
5
- describe("Permission (Value Object)", () => {
6
- describe("constructor/crear", () => {
7
- it.each([null, undefined])("lanza si es %p", (input) => {
8
- expect(() => new permission_1.Permission(input)).toThrow(new errors_1.InvalidPermissionError("Permission cannot be null or undefined"));
9
- });
10
- it("lanza si no es string", () => {
11
- expect(() => new permission_1.Permission(123)).toThrow(new errors_1.InvalidPermissionError("Permission must be a string"));
12
- });
13
- it("lanza si está vacío tras trim", () => {
14
- expect(() => new permission_1.Permission(" ")).toThrow(new errors_1.InvalidPermissionError("Permission cannot be empty"));
15
- });
16
- it("normaliza a minúsculas y trim", () => {
17
- const p = new permission_1.Permission(" READ:Users ");
18
- expect(p.getValue()).toBe("read:users");
19
- expect(p.toString()).toBe("read:users");
20
- });
21
- it("create es un alias del constructor", () => {
22
- const p = permission_1.Permission.create("Write:Posts");
23
- expect(p.getValue()).toBe("write:posts");
24
- expect(p).toBeInstanceOf(permission_1.Permission);
25
- });
26
- });
27
- describe("equals", () => {
28
- it("compara por valor normalizado", () => {
29
- const a = new permission_1.Permission("read:users");
30
- const b = new permission_1.Permission("READ:USERS");
31
- const c = new permission_1.Permission("read:posts");
32
- expect(a.equals(b)).toBe(true);
33
- expect(a.equals(c)).toBe(false);
34
- });
35
- });
36
- describe("isWildcard", () => {
37
- it("true solo para '*'", () => {
38
- expect(new permission_1.Permission("*").isWildcard()).toBe(true);
39
- expect(new permission_1.Permission("read:*").isWildcard()).toBe(false);
40
- expect(new permission_1.Permission("read:users").isWildcard()).toBe(false);
41
- });
42
- });
43
- describe("matches", () => {
44
- it("comodín total '*' hace match con cualquier target", () => {
45
- const p = new permission_1.Permission("*");
46
- expect(p.matches("read:users")).toBe(true);
47
- expect(p.matches("WRITE:POSTS")).toBe(true);
48
- });
49
- it("match exacto", () => {
50
- const p = new permission_1.Permission("read:users");
51
- expect(p.matches("read:users")).toBe(true);
52
- expect(p.matches("READ:USERS")).toBe(true); // case-insensitive en target
53
- expect(p.matches("read:posts")).toBe(false);
54
- });
55
- it("prefijo 'read:*' coincide con 'read:algo'", () => {
56
- const p = new permission_1.Permission("read:*");
57
- expect(p.matches("read:users")).toBe(true);
58
- expect(p.matches("read:posts")).toBe(true);
59
- expect(p.matches("write:users")).toBe(false);
60
- });
61
- it("no coincide cuando el prefijo no aplica", () => {
62
- const p = new permission_1.Permission("admin:*");
63
- expect(p.matches("admin")).toBe(false); // requiere 'admin:...'
64
- expect(p.matches("administrator:users")).toBe(false);
65
- });
66
- it("target inválido (no string o vacío) devuelve false", () => {
67
- const p = new permission_1.Permission("read:*");
68
- expect(p.matches("")).toBe(false);
69
- expect(p.matches(" ")).toBe(false);
70
- expect(p.matches(null)).toBe(false);
71
- expect(p.matches(undefined)).toBe(false);
72
- expect(p.matches(123)).toBe(false);
73
- });
74
- });
75
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,139 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const errors_1 = require("../../../src/domain/errors");
4
- const permission_1 = require("../../../src/domain/object-values/permission");
5
- const role_1 = require("../../../src/domain/object-values/role");
6
- describe("Role (Value Object)", () => {
7
- const P = {
8
- READ_USERS: permission_1.Permission.create("read:users"),
9
- READ_ANY: permission_1.Permission.create("read:*"),
10
- WRITE_POSTS: permission_1.Permission.create("write:posts"),
11
- STAR: permission_1.Permission.create("*"),
12
- };
13
- describe("constructor & validRoles", () => {
14
- it.each([null, undefined])("lanza si role es %p", (input) => {
15
- expect(() => new role_1.Role(input)).toThrow(new errors_1.InvalidRoleError("Role cannot be null or undefined"));
16
- });
17
- it("lanza si role no es string", () => {
18
- // @ts-expect-error (intencional para probar runtime)
19
- expect(() => new role_1.Role(123)).toThrow(new errors_1.InvalidRoleError("Role must be a string"));
20
- });
21
- it("lanza si role está vacío tras trim", () => {
22
- expect(() => new role_1.Role(" ")).toThrow(new errors_1.InvalidRoleError("Role cannot be empty"));
23
- });
24
- it("acepta cualquier role no vacío cuando no se provee validRoles", () => {
25
- const r = new role_1.Role(" Admin ");
26
- expect(r.toString()).toBe("admin");
27
- });
28
- it("valida role contra validRoles (case-insensitive) y lanza si no está incluido", () => {
29
- expect(() => new role_1.Role("manager", [], ["Admin", "User"])).toThrow(new errors_1.InvalidRoleError("Invalid role: manager. Valid roles are: Admin, User"));
30
- });
31
- it("valida role contra validRoles (case-insensitive) y permite si está incluido", () => {
32
- const r = new role_1.Role("ADMIN", [], ["admin", "user"]);
33
- expect(r.toString()).toBe("admin");
34
- });
35
- it("lanza si algún validRole no es string", () => {
36
- expect(() => new role_1.Role("admin", [], ["user", null])).toThrow(new errors_1.InvalidRoleError("Valid roles must be strings"));
37
- });
38
- });
39
- describe("permissions input", () => {
40
- it("lanza si algún permission no es instancia de Permission", () => {
41
- expect(() => new role_1.Role("admin", [P.READ_USERS, "write:posts"])).toThrow(new errors_1.InvalidPermissionError("Permissions must be Permission instances"));
42
- });
43
- it("almacena permisos normalizados y sin duplicados", () => {
44
- const r = new role_1.Role("admin", [
45
- permission_1.Permission.create("READ:USERS"),
46
- permission_1.Permission.create("read:users"),
47
- ]);
48
- const { permissions } = r.getValue();
49
- // Un solo elemento y normalizado
50
- expect(permissions).toEqual(["read:users"]);
51
- });
52
- it("getPermissions devuelve nuevas instancias de Permission", () => {
53
- const r = new role_1.Role("admin", [P.READ_USERS, P.WRITE_POSTS]);
54
- const perms = r.getPermissions();
55
- expect(perms).toHaveLength(2);
56
- expect(perms[0]).toBeInstanceOf(permission_1.Permission);
57
- expect(perms.map((p) => p.getValue())).toEqual(expect.arrayContaining(["read:users", "write:posts"]));
58
- });
59
- });
60
- describe("consultas de permisos", () => {
61
- it("hasPermission true para match exacto (string y Permission)", () => {
62
- const r = new role_1.Role("user", [P.READ_USERS]);
63
- expect(r.hasPermission("read:users")).toBe(true);
64
- expect(r.hasPermission(permission_1.Permission.create("READ:USERS"))).toBe(true);
65
- expect(r.hasPermission("read:posts")).toBe(false);
66
- });
67
- it("soporta comodín total '*'", () => {
68
- const r = new role_1.Role("user", [P.STAR]);
69
- expect(r.hasPermission("cualquier:cosa")).toBe(true);
70
- expect(r.hasPermission("otra")).toBe(true);
71
- });
72
- it("soporta prefijo 'read:*'", () => {
73
- const r = new role_1.Role("user", [P.READ_ANY]);
74
- expect(r.hasPermission("read:users")).toBe(true);
75
- expect(r.hasPermission("read:posts")).toBe(true);
76
- expect(r.hasPermission("write:users")).toBe(false);
77
- });
78
- it("hasAnyPermission true si al menos uno coincide", () => {
79
- const r = new role_1.Role("user", [P.READ_USERS]);
80
- expect(r.hasAnyPermission(["read:posts", "read:users"])).toBe(true);
81
- expect(r.hasAnyPermission(["write:posts", "write:users"])).toBe(false);
82
- });
83
- it("hasAllPermissions true si todos coinciden", () => {
84
- const r = new role_1.Role("user", [P.READ_USERS, P.WRITE_POSTS]);
85
- expect(r.hasAllPermissions(["read:users", "write:posts"])).toBe(true);
86
- expect(r.hasAllPermissions(["read:users", "write:users"])).toBe(false);
87
- });
88
- });
89
- describe("utilidades y estáticos", () => {
90
- it("equals compara por nombre normalizado", () => {
91
- const a = new role_1.Role("ADMIN");
92
- const b = new role_1.Role("admin");
93
- const c = new role_1.Role("user");
94
- expect(a.equals(b)).toBe(true);
95
- expect(a.equals(c)).toBe(false);
96
- });
97
- it("hasRole es case-insensitive", () => {
98
- const r = new role_1.Role("manager");
99
- expect(r.hasRole(" MANAGER ")).toBe(true);
100
- expect(r.hasRole("user")).toBe(false);
101
- });
102
- it("toString devuelve el nombre del rol", () => {
103
- expect(new role_1.Role("Admin").toString()).toBe("admin");
104
- });
105
- it("create crea sin validRoles, withValidRoles valida", () => {
106
- const a = role_1.Role.create("User", [P.READ_USERS]);
107
- expect(a.getValue()).toEqual({
108
- role: "user",
109
- permissions: ["read:users"],
110
- });
111
- const b = role_1.Role.withValidRoles("User", [P.READ_USERS], ["admin", "user"]);
112
- expect(b.getValuePublic()).toEqual({ role: "user" });
113
- });
114
- });
115
- describe("withPermissions y canPerform", () => {
116
- it("withPermissions retorna un NUEVO Role sin mutar el original", () => {
117
- const base = new role_1.Role("user", [P.READ_USERS]);
118
- const added = base.withPermissions([P.WRITE_POSTS]);
119
- // original intacto
120
- expect(base.getValue().permissions).toEqual(["read:users"]);
121
- // nuevo con ambos
122
- expect(added.getValue().permissions).toEqual(expect.arrayContaining(["read:users", "write:posts"]));
123
- // y siguen sin duplicados si se repiten
124
- const again = added.withPermissions([permission_1.Permission.create("WRITE:POSTS")]);
125
- expect(again.getValue().permissions).toEqual(expect.arrayContaining(["read:users", "write:posts"]));
126
- expect(again.getValue().permissions).toHaveLength(2);
127
- });
128
- it("canPerform(action) delega a hasPermission con acción simple", () => {
129
- const r = new role_1.Role("user", [permission_1.Permission.create("export")]);
130
- expect(r.canPerform("export")).toBe(true);
131
- expect(r.canPerform("import")).toBe(false);
132
- });
133
- it("canPerform(action, resource) compone 'action:resource'", () => {
134
- const r = new role_1.Role("user", [permission_1.Permission.create("read:*")]);
135
- expect(r.canPerform("read", "users")).toBe(true);
136
- expect(r.canPerform("write", "users")).toBe(false);
137
- });
138
- });
139
- });
@@ -1,7 +0,0 @@
1
- import { JwtUser } from "src/domain";
2
- /**
3
- * Crea un sujeto JWT falso (id, email y roles)
4
- * usado por JwtTokenGenerator en los tests.
5
- * No requiere instanciar entidades reales ni VO con validaciones.
6
- */
7
- export declare function makeJwtSubject(overrides?: Partial<JwtUser>): JwtUser;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeJwtSubject = makeJwtSubject;
4
- /**
5
- * Crea un sujeto JWT falso (id, email y roles)
6
- * usado por JwtTokenGenerator en los tests.
7
- * No requiere instanciar entidades reales ni VO con validaciones.
8
- */
9
- function makeJwtSubject(overrides = {}) {
10
- return {
11
- id: "user-123",
12
- email: "john.doe@example.com",
13
- roles: [{ role: "ADMIN" }, { role: "USER" }],
14
- ...overrides,
15
- };
16
- }
@@ -1,7 +0,0 @@
1
- import { JwtUser } from "src/domain";
2
- /**
3
- * Crea un sujeto JWT falso (id, email y roles)
4
- * usado por JwtTokenGenerator en los tests.
5
- * No requiere instanciar entidades reales ni VO con validaciones.
6
- */
7
- export declare function makeJwtSubject(overrides?: Partial<JwtUser>): JwtUser;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeJwtSubject = makeJwtSubject;
4
- /**
5
- * Crea un sujeto JWT falso (id, email y roles)
6
- * usado por JwtTokenGenerator en los tests.
7
- * No requiere instanciar entidades reales ni VO con validaciones.
8
- */
9
- function makeJwtSubject(overrides = {}) {
10
- return {
11
- id: "user-123",
12
- email: "john.doe@example.com",
13
- roles: [{ role: "ADMIN" }, { role: "USER" }],
14
- ...overrides,
15
- };
16
- }
@@ -1,2 +0,0 @@
1
- import { User } from "src/domain";
2
- export declare function makeUser565456456(): User;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeUser565456456 = makeUser565456456;
4
- const domain_1 = require("src/domain");
5
- function makeUser565456456() {
6
- return new domain_1.User({
7
- id: new domain_1.Id("user-123"),
8
- email: new domain_1.Email("john.doe@example.com"),
9
- roles: [new domain_1.Role("admin"), new domain_1.Role("user")],
10
- password: new domain_1.HashedPassword("$2b$10$W6X...cadenaValidaDeBcrypt.../"),
11
- isActive: true,
12
- createdAt: new Date(),
13
- updatedAt: new Date(),
14
- });
15
- }
@@ -1,127 +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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- // tests/infrastructure/jwt/signature-strategy-factory.spec.ts
37
- const domain_1 = require("src/domain");
38
- const shared_1 = require("src/shared");
39
- // 👇 Mockeamos el módulo ANTES de importar la factory.
40
- jest.mock("../../../src/infrastructure/jwt/strategies", () => {
41
- return {
42
- HmacSignatureStrategy: jest
43
- .fn()
44
- .mockImplementation((alg, enc) => ({
45
- _type: "hmac",
46
- alg,
47
- enc,
48
- })),
49
- RsaSignatureStrategy: jest
50
- .fn()
51
- .mockImplementation((alg, enc) => ({
52
- _type: "rsa",
53
- alg,
54
- enc,
55
- })),
56
- EcdsaSignatureStrategy: jest
57
- .fn()
58
- .mockImplementation((alg, enc) => ({
59
- _type: "ecdsa",
60
- alg,
61
- enc,
62
- })),
63
- };
64
- });
65
- // importamos la factory y el módulo mockeado
66
- const strategies = __importStar(require("../../../src/infrastructure/jwt/strategies"));
67
- const infrastructure_1 = require("src/infrastructure");
68
- describe("SignatureStrategyFactory", () => {
69
- let encoder;
70
- let factory;
71
- beforeEach(() => {
72
- jest.clearAllMocks();
73
- encoder = new shared_1.Base64UrlEncoder();
74
- factory = new infrastructure_1.SignatureStrategyFactory(encoder);
75
- });
76
- it("instancia HmacSignatureStrategy cuando algoritmo es HS*", () => {
77
- const hsAlg = Object.values(shared_1.algorithms.hmac)[0] ?? "HS256";
78
- const result = factory.create(hsAlg);
79
- expect(strategies.HmacSignatureStrategy).toHaveBeenCalledTimes(1);
80
- expect(strategies.HmacSignatureStrategy).toHaveBeenCalledWith(hsAlg.toUpperCase(), encoder);
81
- expect(result).toMatchObject({
82
- _type: "hmac",
83
- alg: hsAlg.toUpperCase(),
84
- enc: encoder,
85
- });
86
- expect(strategies.RsaSignatureStrategy).not.toHaveBeenCalled();
87
- expect(strategies.EcdsaSignatureStrategy).not.toHaveBeenCalled();
88
- });
89
- it("instancia RsaSignatureStrategy cuando algoritmo es RS*", () => {
90
- const rsAlg = Object.values(shared_1.algorithms.rsa)[0] ?? "RS256";
91
- const result = factory.create(rsAlg);
92
- expect(strategies.RsaSignatureStrategy).toHaveBeenCalledTimes(1);
93
- expect(strategies.RsaSignatureStrategy).toHaveBeenCalledWith(rsAlg.toUpperCase(), encoder);
94
- expect(result).toMatchObject({
95
- _type: "rsa",
96
- alg: rsAlg.toUpperCase(),
97
- enc: encoder,
98
- });
99
- expect(strategies.HmacSignatureStrategy).not.toHaveBeenCalled();
100
- expect(strategies.EcdsaSignatureStrategy).not.toHaveBeenCalled();
101
- });
102
- it("instancia EcdsaSignatureStrategy cuando algoritmo es ES*", () => {
103
- const esAlg = Object.values(shared_1.algorithms.ecdsa)[0] ?? "ES256";
104
- const result = factory.create(esAlg);
105
- expect(strategies.EcdsaSignatureStrategy).toHaveBeenCalledTimes(1);
106
- expect(strategies.EcdsaSignatureStrategy).toHaveBeenCalledWith(esAlg.toUpperCase(), encoder);
107
- expect(result).toMatchObject({
108
- _type: "ecdsa",
109
- alg: esAlg.toUpperCase(),
110
- enc: encoder,
111
- });
112
- expect(strategies.HmacSignatureStrategy).not.toHaveBeenCalled();
113
- expect(strategies.RsaSignatureStrategy).not.toHaveBeenCalled();
114
- });
115
- it("es case-insensitive (toUpperCase defensivo)", () => {
116
- const hsAlg = (Object.values(shared_1.algorithms.hmac)[0] ?? "HS256").toLowerCase();
117
- factory.create(hsAlg);
118
- expect(strategies.HmacSignatureStrategy).toHaveBeenCalledWith(hsAlg.toUpperCase(), encoder);
119
- });
120
- it("lanza UnsupportedAlgorithmError si no está soportado", () => {
121
- const unsupported = "PS256";
122
- expect(() => factory.create(unsupported)).toThrow(domain_1.UnsupportedAlgorithmError);
123
- expect(strategies.HmacSignatureStrategy).not.toHaveBeenCalled();
124
- expect(strategies.RsaSignatureStrategy).not.toHaveBeenCalled();
125
- expect(strategies.EcdsaSignatureStrategy).not.toHaveBeenCalled();
126
- });
127
- });