@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.
Files changed (332) hide show
  1. package/README.md +306 -0
  2. package/dist/examples/bcrypt-password-hasher.example.d.ts +3 -0
  3. package/dist/examples/bcrypt-password-hasher.example.js +78 -0
  4. package/dist/examples/entity-object.example.d.ts +39 -0
  5. package/dist/examples/entity-object.example.js +411 -0
  6. package/dist/examples/factory-auth-service-example.d.ts +3 -0
  7. package/dist/examples/factory-auth-service-example.js +84 -0
  8. package/dist/examples/index.example.d.ts +12 -0
  9. package/dist/examples/index.example.js +171 -0
  10. package/dist/examples/jwt-algoritm.example.d.ts +47 -0
  11. package/dist/examples/jwt-algoritm.example.js +447 -0
  12. package/dist/examples/jwt-token-generator.example.d.ts +6 -0
  13. package/dist/examples/jwt-token-generator.example.js +49 -0
  14. package/dist/examples/jwt-verifier.example.d.ts +3 -0
  15. package/dist/examples/jwt-verifier.example.js +80 -0
  16. package/dist/examples/password-policy.example.d.ts +7 -0
  17. package/dist/examples/password-policy.example.js +57 -0
  18. package/dist/examples/service-jwt-token.example.d.ts +3 -0
  19. package/dist/examples/service-jwt-token.example.js +154 -0
  20. package/dist/examples/service-token-session.example.d.ts +3 -0
  21. package/dist/examples/service-token-session.example.js +139 -0
  22. package/dist/examples/use-case-login-with-password.example.d.ts +6 -0
  23. package/dist/examples/use-case-login-with-password.example.js +105 -0
  24. package/dist/examples/use-case-logout.example.d.ts +7 -0
  25. package/dist/examples/use-case-logout.example.js +134 -0
  26. package/dist/examples/use-case-refresh-token.example.d.ts +11 -0
  27. package/dist/examples/use-case-refresh-token.example.js +164 -0
  28. package/dist/examples/use-case-register-user.example.d.ts +9 -0
  29. package/dist/examples/use-case-register-user.example.js +110 -0
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.js +17 -0
  32. package/dist/src/application/dtos/index.d.ts +4 -0
  33. package/dist/src/application/dtos/index.js +20 -0
  34. package/dist/src/application/dtos/login.dto.d.ts +9 -0
  35. package/dist/src/application/dtos/login.dto.js +2 -0
  36. package/dist/src/application/dtos/logout.dto.d.ts +7 -0
  37. package/dist/src/application/dtos/logout.dto.js +2 -0
  38. package/dist/src/application/dtos/refresh-token.dto.d.ts +7 -0
  39. package/dist/src/application/dtos/refresh-token.dto.js +2 -0
  40. package/dist/src/application/dtos/register-user.dto.d.ts +16 -0
  41. package/dist/src/application/dtos/register-user.dto.js +2 -0
  42. package/dist/src/application/factories/auth-service.factory.d.ts +5 -0
  43. package/dist/src/application/factories/auth-service.factory.js +51 -0
  44. package/dist/src/application/factories/index.d.ts +1 -0
  45. package/dist/src/application/factories/index.js +17 -0
  46. package/dist/src/application/index.d.ts +3 -0
  47. package/dist/src/application/index.js +19 -0
  48. package/dist/src/application/use-cases/index.d.ts +4 -0
  49. package/dist/src/application/use-cases/index.js +20 -0
  50. package/dist/src/application/use-cases/login-with-password.use-case.d.ts +9 -0
  51. package/dist/src/application/use-cases/login-with-password.use-case.js +36 -0
  52. package/dist/src/application/use-cases/logout.use-case.d.ts +7 -0
  53. package/dist/src/application/use-cases/logout.use-case.js +22 -0
  54. package/dist/src/application/use-cases/refresh-token.use-case.d.ts +7 -0
  55. package/dist/src/application/use-cases/refresh-token.use-case.js +23 -0
  56. package/dist/src/application/use-cases/register-user.use-case.d.ts +10 -0
  57. package/dist/src/application/use-cases/register-user.use-case.js +37 -0
  58. package/dist/src/domain/entities/credential.entity.d.ts +78 -0
  59. package/dist/src/domain/entities/credential.entity.js +92 -0
  60. package/dist/src/domain/entities/index.d.ts +2 -0
  61. package/dist/src/domain/entities/index.js +18 -0
  62. package/dist/src/domain/entities/user.entity.d.ts +97 -0
  63. package/dist/src/domain/entities/user.entity.js +116 -0
  64. package/dist/src/domain/errors/auth-domain-error.d.ts +82 -0
  65. package/dist/src/domain/errors/auth-domain-error.js +112 -0
  66. package/dist/src/domain/errors/auth.errors.d.ts +56 -0
  67. package/dist/src/domain/errors/auth.errors.js +76 -0
  68. package/dist/src/domain/errors/identity.errors.d.ts +34 -0
  69. package/dist/src/domain/errors/identity.errors.js +82 -0
  70. package/dist/src/domain/errors/index.d.ts +2 -0
  71. package/dist/src/domain/errors/index.js +18 -0
  72. package/dist/src/domain/index.d.ts +6 -0
  73. package/dist/src/domain/index.js +22 -0
  74. package/dist/src/domain/object-values/email.d.ts +37 -0
  75. package/dist/src/domain/object-values/email.js +56 -0
  76. package/dist/src/domain/object-values/hashed-password.d.ts +28 -0
  77. package/dist/src/domain/object-values/hashed-password.js +73 -0
  78. package/dist/src/domain/object-values/id.d.ts +8 -0
  79. package/dist/src/domain/object-values/id.js +28 -0
  80. package/dist/src/domain/object-values/index.d.ts +5 -0
  81. package/dist/src/domain/object-values/index.js +13 -0
  82. package/dist/src/domain/object-values/permission.d.ts +15 -0
  83. package/dist/src/domain/object-values/permission.js +57 -0
  84. package/dist/src/domain/object-values/role.d.ts +25 -0
  85. package/dist/src/domain/object-values/role.js +108 -0
  86. package/dist/src/domain/ports/auth/password-hasher.d.ts +7 -0
  87. package/dist/src/domain/ports/auth/password-hasher.js +2 -0
  88. package/dist/src/domain/ports/auth/password-policy-config.port.d.ts +0 -0
  89. package/dist/src/domain/ports/auth/password-policy-config.port.js +10 -0
  90. package/dist/src/domain/ports/auth/password-policy.port.d.ts +10 -0
  91. package/dist/src/domain/ports/auth/password-policy.port.js +2 -0
  92. package/dist/src/domain/ports/config/auth-config.port.d.ts +19 -0
  93. package/dist/src/domain/ports/config/auth-config.port.js +3 -0
  94. package/dist/src/domain/ports/index.d.ts +9 -0
  95. package/dist/src/domain/ports/index.js +25 -0
  96. package/dist/src/domain/ports/jwt/factory/signature-strategy-factory.port.d.ts +14 -0
  97. package/dist/src/domain/ports/jwt/factory/signature-strategy-factory.port.js +2 -0
  98. package/dist/src/domain/ports/jwt/payload/jwt-payload.port.d.ts +12 -0
  99. package/dist/src/domain/ports/jwt/payload/jwt-payload.port.js +2 -0
  100. package/dist/src/domain/ports/jwt/signature-strategy-factory.port.d.ts +14 -0
  101. package/dist/src/domain/ports/jwt/signature-strategy-factory.port.js +2 -0
  102. package/dist/src/domain/ports/jwt/signature-strategy.d.ts +30 -0
  103. package/dist/src/domain/ports/jwt/signature-strategy.js +4 -0
  104. package/dist/src/domain/ports/jwt/signature-strategy.port.d.ts +31 -0
  105. package/dist/src/domain/ports/jwt/signature-strategy.port.js +4 -0
  106. package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.d.ts +31 -0
  107. package/dist/src/domain/ports/jwt/strategy/signature-strategy.port.js +4 -0
  108. package/dist/src/domain/ports/repository/credential.repository.d.ts +10 -0
  109. package/dist/src/domain/ports/repository/credential.repository.js +2 -0
  110. package/dist/src/domain/ports/repository/index.d.ts +2 -0
  111. package/dist/src/domain/ports/repository/index.js +18 -0
  112. package/dist/src/domain/ports/repository/user.repository.d.ts +13 -0
  113. package/dist/src/domain/ports/repository/user.repository.js +2 -0
  114. package/dist/src/domain/ports/token/token-session.port.d.ts +7 -0
  115. package/dist/src/domain/ports/token/token-session.port.js +2 -0
  116. package/dist/src/domain/ports/token/token.service.port.d.ts +9 -0
  117. package/dist/src/domain/ports/token/token.service.port.js +2 -0
  118. package/dist/src/domain/props/create-payload-props.port.d.ts +0 -0
  119. package/dist/src/domain/props/create-payload-props.port.js +8 -0
  120. package/dist/src/domain/props/entities/credential.props.d.ts +8 -0
  121. package/dist/src/domain/props/entities/credential.props.js +2 -0
  122. package/dist/src/domain/props/entities/index.d.ts +2 -0
  123. package/dist/src/domain/props/entities/index.js +18 -0
  124. package/dist/src/domain/props/entities/user.props.d.ts +10 -0
  125. package/dist/src/domain/props/entities/user.props.js +2 -0
  126. package/dist/src/domain/props/index.d.ts +2 -0
  127. package/dist/src/domain/props/index.js +18 -0
  128. package/dist/src/domain/props/jwt/create-payload.props.d.ts +9 -0
  129. package/dist/src/domain/props/jwt/create-payload.props.js +2 -0
  130. package/dist/src/domain/props/jwt/generate-access-token.props.d.ts +8 -0
  131. package/dist/src/domain/props/jwt/generate-access-token.props.js +2 -0
  132. package/dist/src/domain/props/jwt/generate-refresh-token.props.d.ts +8 -0
  133. package/dist/src/domain/props/jwt/generate-refresh-token.props.js +2 -0
  134. package/dist/src/domain/props/jwt/generate-token.props.d.ts +10 -0
  135. package/dist/src/domain/props/jwt/generate-token.props.js +2 -0
  136. package/dist/src/domain/props/jwt/index.d.ts +5 -0
  137. package/dist/src/domain/props/jwt/index.js +21 -0
  138. package/dist/src/domain/props/jwt/jwt-subject.d.ts +7 -0
  139. package/dist/src/domain/props/jwt/jwt-subject.js +2 -0
  140. package/dist/src/domain/props/jwt/jwt-user.d.ts +7 -0
  141. package/dist/src/domain/props/jwt/jwt-user.js +2 -0
  142. package/dist/src/domain/props/services/generate-access-token.props.d.ts +8 -0
  143. package/dist/src/domain/props/services/generate-access-token.props.js +2 -0
  144. package/dist/src/domain/props/services/generate-refresh-token.props.d.ts +8 -0
  145. package/dist/src/domain/props/services/generate-refresh-token.props.js +2 -0
  146. package/dist/src/domain/props/services/index.d.ts +2 -0
  147. package/dist/src/domain/props/services/index.js +18 -0
  148. package/dist/src/domain/services/index.d.ts +1 -0
  149. package/dist/src/domain/services/index.js +17 -0
  150. package/dist/src/domain/services/password-policy.service.d.ts +8 -0
  151. package/dist/src/domain/services/password-policy.service.js +29 -0
  152. package/dist/src/domain/services/token.service.port.d.ts +9 -0
  153. package/dist/src/domain/services/token.service.port.js +2 -0
  154. package/dist/src/index.d.ts +78 -0
  155. package/dist/src/index.js +94 -0
  156. package/dist/src/infrastructure/index.d.ts +5 -0
  157. package/dist/src/infrastructure/index.js +21 -0
  158. package/dist/src/infrastructure/jwt/factory/index.d.ts +1 -0
  159. package/dist/src/infrastructure/jwt/factory/index.js +17 -0
  160. package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.d.ts +21 -0
  161. package/dist/src/infrastructure/jwt/factory/signature-strategy.factory.js +61 -0
  162. package/dist/src/infrastructure/jwt/index.d.ts +3 -0
  163. package/dist/src/infrastructure/jwt/index.js +19 -0
  164. package/dist/src/infrastructure/jwt/signature-strategy.factory.d.ts +21 -0
  165. package/dist/src/infrastructure/jwt/signature-strategy.factory.js +61 -0
  166. package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.d.ts +47 -0
  167. package/dist/src/infrastructure/jwt/strategies/ecdsa-signature-strategy.js +124 -0
  168. package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.d.ts +47 -0
  169. package/dist/src/infrastructure/jwt/strategies/ecdsa-signature.strategy.js +124 -0
  170. package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.d.ts +54 -0
  171. package/dist/src/infrastructure/jwt/strategies/hmac-signature-strategy.js +129 -0
  172. package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.d.ts +54 -0
  173. package/dist/src/infrastructure/jwt/strategies/hmac-signature.strategy.js +129 -0
  174. package/dist/src/infrastructure/jwt/strategies/index.d.ts +3 -0
  175. package/dist/src/infrastructure/jwt/strategies/index.js +19 -0
  176. package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.d.ts +47 -0
  177. package/dist/src/infrastructure/jwt/strategies/rsa-signature-strategy.js +124 -0
  178. package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.d.ts +47 -0
  179. package/dist/src/infrastructure/jwt/strategies/rsa-signature.strategy.js +124 -0
  180. package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.d.ts +57 -0
  181. package/dist/src/infrastructure/jwt/token/actions/jwt-token-generator.js +123 -0
  182. package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.d.ts +59 -0
  183. package/dist/src/infrastructure/jwt/token/actions/jwt-token-verifier.js +100 -0
  184. package/dist/src/infrastructure/jwt/token/index.d.ts +5 -0
  185. package/dist/src/infrastructure/jwt/token/index.js +21 -0
  186. package/dist/src/infrastructure/jwt/token/jwt-signer.d.ts +33 -0
  187. package/dist/src/infrastructure/jwt/token/jwt-signer.js +46 -0
  188. package/dist/src/infrastructure/jwt/token/jwt-token-parser.d.ts +29 -0
  189. package/dist/src/infrastructure/jwt/token/jwt-token-parser.js +57 -0
  190. package/dist/src/infrastructure/jwt/token/jwt-token-validator.d.ts +32 -0
  191. package/dist/src/infrastructure/jwt/token/jwt-token-validator.js +77 -0
  192. package/dist/src/infrastructure/jwt/token/tools/jwt-signer.d.ts +33 -0
  193. package/dist/src/infrastructure/jwt/token/tools/jwt-signer.js +46 -0
  194. package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.d.ts +30 -0
  195. package/dist/src/infrastructure/jwt/token/tools/jwt-token-parser.js +57 -0
  196. package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.d.ts +32 -0
  197. package/dist/src/infrastructure/jwt/token/tools/jwt-token-validator.js +77 -0
  198. package/dist/src/infrastructure/repositories/index.d.ts +1 -0
  199. package/dist/src/infrastructure/repositories/index.js +17 -0
  200. package/dist/src/infrastructure/repositories/test/in-memory-credential.repository.d.ts +12 -0
  201. package/dist/src/infrastructure/repositories/test/in-memory-credential.repository.js +68 -0
  202. package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.d.ts +67 -0
  203. package/dist/src/infrastructure/repositories/test/in-memory-token-session.repository.js +128 -0
  204. package/dist/src/infrastructure/repositories/test/in-memory-user.repository.d.ts +11 -0
  205. package/dist/src/infrastructure/repositories/test/in-memory-user.repository.js +49 -0
  206. package/dist/src/infrastructure/repositories/test/index.d.ts +2 -0
  207. package/dist/src/infrastructure/repositories/test/index.js +18 -0
  208. package/dist/src/infrastructure/security/bcrypt-password-hasher.d.ts +6 -0
  209. package/dist/src/infrastructure/security/bcrypt-password-hasher.js +19 -0
  210. package/dist/src/infrastructure/security/index.d.ts +1 -0
  211. package/dist/src/infrastructure/security/index.js +17 -0
  212. package/dist/src/infrastructure/services/default-token-session.service.d.ts +18 -0
  213. package/dist/src/infrastructure/services/default-token-session.service.js +88 -0
  214. package/dist/src/infrastructure/services/index.d.ts +2 -0
  215. package/dist/src/infrastructure/services/index.js +18 -0
  216. package/dist/src/infrastructure/services/jwt-token.service.d.ts +15 -0
  217. package/dist/src/infrastructure/services/jwt-token.service.js +44 -0
  218. package/dist/src/infrastructure/services/simple-jwt-token.service.d.ts +15 -0
  219. package/dist/src/infrastructure/services/simple-jwt-token.service.js +46 -0
  220. package/dist/src/infrastructure/services/token-session.service.d.ts +24 -0
  221. package/dist/src/infrastructure/services/token-session.service.js +131 -0
  222. package/dist/src/infrastructure/types/auth-service-container.d.ts +14 -0
  223. package/dist/src/infrastructure/types/auth-service-container.js +2 -0
  224. package/dist/src/infrastructure/types/index.d.ts +1 -0
  225. package/dist/src/infrastructure/types/index.js +17 -0
  226. package/dist/src/shared/constants/index.d.ts +1 -0
  227. package/dist/src/shared/constants/index.js +17 -0
  228. package/dist/src/shared/constants/jwt-algorithms.d.ts +17 -0
  229. package/dist/src/shared/constants/jwt-algorithms.js +23 -0
  230. package/dist/src/shared/encoders/base64-url-encoder.d.ts +29 -0
  231. package/dist/src/shared/encoders/base64-url-encoder.js +45 -0
  232. package/dist/src/shared/encoders/index.d.ts +1 -0
  233. package/dist/src/shared/encoders/index.js +17 -0
  234. package/dist/src/shared/index.d.ts +4 -0
  235. package/dist/src/shared/index.js +20 -0
  236. package/dist/src/shared/types/index.d.ts +1 -0
  237. package/dist/src/shared/types/index.js +17 -0
  238. package/dist/src/shared/types/jwt.d.ts +25 -0
  239. package/dist/src/shared/types/jwt.js +2 -0
  240. package/dist/src/shared/types/jwt.types.d.ts +39 -0
  241. package/dist/src/shared/types/jwt.types.js +2 -0
  242. package/dist/src/shared/utils/index.d.ts +1 -0
  243. package/dist/src/shared/utils/index.js +17 -0
  244. package/dist/src/shared/utils/time-parser.d.ts +28 -0
  245. package/dist/src/shared/utils/time-parser.js +76 -0
  246. package/dist/tests/application/factory/auth-service-factory.spec.d.ts +1 -0
  247. package/dist/tests/application/factory/auth-service-factory.spec.js +97 -0
  248. package/dist/tests/application/use-cases/login-with-password.integration.spec.d.ts +1 -0
  249. package/dist/tests/application/use-cases/login-with-password.integration.spec.js +140 -0
  250. package/dist/tests/application/use-cases/logout-use-case.spec.d.ts +1 -0
  251. package/dist/tests/application/use-cases/logout-use-case.spec.js +40 -0
  252. package/dist/tests/application/use-cases/refresh-token-use-case.spec.d.ts +1 -0
  253. package/dist/tests/application/use-cases/refresh-token-use-case.spec.js +116 -0
  254. package/dist/tests/application/use-cases/register-user.usecase.spec.d.ts +1 -0
  255. package/dist/tests/application/use-cases/register-user.usecase.spec.js +151 -0
  256. package/dist/tests/domain/entities/credential.spec.d.ts +1 -0
  257. package/dist/tests/domain/entities/credential.spec.js +93 -0
  258. package/dist/tests/domain/entities/user.spec.d.ts +1 -0
  259. package/dist/tests/domain/entities/user.spec.js +93 -0
  260. package/dist/tests/domain/object-values/email.spec.d.ts +1 -0
  261. package/dist/tests/domain/object-values/email.spec.js +77 -0
  262. package/dist/tests/domain/object-values/hashed-password.spec.d.ts +1 -0
  263. package/dist/tests/domain/object-values/hashed-password.spec.js +54 -0
  264. package/dist/tests/domain/object-values/id.spec.d.ts +1 -0
  265. package/dist/tests/domain/object-values/id.spec.js +48 -0
  266. package/dist/tests/domain/object-values/permission.spec.d.ts +1 -0
  267. package/dist/tests/domain/object-values/permission.spec.js +75 -0
  268. package/dist/tests/domain/object-values/role.spec.d.ts +1 -0
  269. package/dist/tests/domain/object-values/role.spec.js +139 -0
  270. package/dist/tests/domain/services/default-password-policy.spec.d.ts +1 -0
  271. package/dist/tests/domain/services/default-password-policy.spec.js +69 -0
  272. package/dist/tests/doman/entities/credential.spec.d.ts +1 -0
  273. package/dist/tests/doman/entities/credential.spec.js +93 -0
  274. package/dist/tests/doman/entities/user.spec.d.ts +1 -0
  275. package/dist/tests/doman/entities/user.spec.js +93 -0
  276. package/dist/tests/doman/object-values/email.spec.d.ts +1 -0
  277. package/dist/tests/doman/object-values/email.spec.js +77 -0
  278. package/dist/tests/doman/object-values/hashed-password.spec.d.ts +1 -0
  279. package/dist/tests/doman/object-values/hashed-password.spec.js +54 -0
  280. package/dist/tests/doman/object-values/id.spec.d.ts +1 -0
  281. package/dist/tests/doman/object-values/id.spec.js +48 -0
  282. package/dist/tests/doman/object-values/permission.spec.d.ts +1 -0
  283. package/dist/tests/doman/object-values/permission.spec.js +75 -0
  284. package/dist/tests/doman/object-values/role.spec.d.ts +1 -0
  285. package/dist/tests/doman/object-values/role.spec.js +139 -0
  286. package/dist/tests/helpers/make-jwt-subject.d.ts +7 -0
  287. package/dist/tests/helpers/make-jwt-subject.js +16 -0
  288. package/dist/tests/helpers/make-jwt-user.d.ts +7 -0
  289. package/dist/tests/helpers/make-jwt-user.js +16 -0
  290. package/dist/tests/helpers/make-user.d.ts +2 -0
  291. package/dist/tests/helpers/make-user.js +15 -0
  292. package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.d.ts +1 -0
  293. package/dist/tests/infrastructure/jwt/signature-strategy-factory.spec.js +127 -0
  294. package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.d.ts +1 -0
  295. package/dist/tests/infrastructure/jwt/strategies/ecdsa-signature-strategy.spec.js +157 -0
  296. package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.d.ts +1 -0
  297. package/dist/tests/infrastructure/jwt/strategies/hmac-signature-strategy.spec.js +150 -0
  298. package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.d.ts +1 -0
  299. package/dist/tests/infrastructure/jwt/strategies/rsa-signature-strategy..spec.js +156 -0
  300. package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.d.ts +1 -0
  301. package/dist/tests/infrastructure/jwt/token/actions/jwt-token-generator.spec.js +179 -0
  302. package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.d.ts +1 -0
  303. package/dist/tests/infrastructure/jwt/token/actions/jwt-token-verifier.spec.js +142 -0
  304. package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.d.ts +1 -0
  305. package/dist/tests/infrastructure/jwt/token/jwt-signer.spec.js +125 -0
  306. package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.d.ts +1 -0
  307. package/dist/tests/infrastructure/jwt/token/jwt-token-parser.spec.js +116 -0
  308. package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.d.ts +1 -0
  309. package/dist/tests/infrastructure/jwt/token/jwt-token-validator.spec.js +88 -0
  310. package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.d.ts +1 -0
  311. package/dist/tests/infrastructure/jwt/token/tools/jwt-signer.spec.js +126 -0
  312. package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.d.ts +1 -0
  313. package/dist/tests/infrastructure/jwt/token/tools/jwt-token-parser.spec.js +116 -0
  314. package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.d.ts +1 -0
  315. package/dist/tests/infrastructure/jwt/token/tools/jwt-token-validator.spec.js +88 -0
  316. package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.d.ts +1 -0
  317. package/dist/tests/infrastructure/security/security/bcrypt-password-hasher.spec.js +37 -0
  318. package/dist/tests/infrastructure/services/jwt-token-service.spec.d.ts +1 -0
  319. package/dist/tests/infrastructure/services/jwt-token-service.spec.js +145 -0
  320. package/dist/tests/infrastructure/services/token-session.service.spec.d.ts +1 -0
  321. package/dist/tests/infrastructure/services/token-session.service.spec.js +269 -0
  322. package/dist/tests/shared/constants/jwt-algorithms.spec.d.ts +1 -0
  323. package/dist/tests/shared/constants/jwt-algorithms.spec.js +27 -0
  324. package/dist/tests/shared/encoders/base64-url-encoder.spec.d.ts +1 -0
  325. package/dist/tests/shared/encoders/base64-url-encoder.spec.js +70 -0
  326. package/dist/tests/shared/utils/time-parser.spec.d.ts +1 -0
  327. package/dist/tests/shared/utils/time-parser.spec.js +80 -0
  328. package/dist/utils/index.d.ts +1 -0
  329. package/dist/utils/index.js +17 -0
  330. package/dist/utils/time-parser.d.ts +28 -0
  331. package/dist/utils/time-parser.js +76 -0
  332. package/package.json +48 -0
package/README.md ADDED
@@ -0,0 +1,306 @@
1
+ # @ml-dev-core/jwt.auth
2
+
3
+ 🔐 **Paquete de autenticación JWT** con **Arquitectura Limpia** para aplicaciones TypeScript.
4
+
5
+ ## 🚀 Instalación Rápida
6
+
7
+ ```bash
8
+ npm install @ml-dev-core/jwt.auth bcryptjs
9
+ npm install --save-dev @types/bcryptjs
10
+ ```
11
+
12
+ ## 📖 Documentación
13
+
14
+ - **[📋 Instalación y Configuración](./install.md)** - Guías detalladas para Express.js, NestJS y más
15
+ - **[🏗️ Documentación de Arquitectura](./architecture.md)** - Clean Architecture, capas y patrones
16
+ - **[📚 Ejemplos de Código](./examples/)** - Casos de uso reales y implementaciones
17
+
18
+ ## ✨ Características Principales
19
+
20
+ - ✅ **Clean Architecture**: Separación clara de responsabilidades
21
+ - ✅ **Framework Agnostic**: Compatible con Express, NestJS, Fastify, etc.
22
+ - ✅ **Database Independent**: Repositorios como interfaces
23
+ - ✅ **TypeScript Native**: Tipado fuerte y autocompletado
24
+ - ✅ **JWT Completo**: Access + Refresh tokens con rotación
25
+ - ✅ **Multi-Algorithm**: HS256, RS256, ES256 y más
26
+ - ✅ **Password Security**: Bcrypt con políticas configurables
27
+ - ✅ **Testing Ready**: Repositorios in-memory incluidos
28
+ - ✅ **Production Ready**: Manejo de errores y validaciones
29
+
30
+ ## 🏃‍♂️ Inicio Rápido
31
+
32
+ ### 1. Configuración Básica
33
+
34
+ ```typescript
35
+ import {
36
+ AuthServiceFactory,
37
+ IAuthConfig,
38
+ InMemoryUserRepository,
39
+ InMemoryCredentialRepository,
40
+ } from "@ml-dev-core/jwt.auth";
41
+
42
+ const config: IAuthConfig = {
43
+ jwt: {
44
+ accessTokenSecret: process.env.JWT_ACCESS_SECRET!,
45
+ refreshTokenSecret: process.env.JWT_REFRESH_SECRET!,
46
+ accessTokenExpirationMs: 15 * 60 * 1000, // 15 minutos
47
+ refreshTokenExpirationMs: 7 * 24 * 60 * 60 * 1000, // 7 días
48
+ accessTokenExpiration: "15m",
49
+ refreshTokenExpiration: "7d",
50
+ },
51
+ bcrypt: { saltRounds: 12 },
52
+ algorithm: "HS256",
53
+ info: {
54
+ issuer: "your-app",
55
+ audience: "your-client",
56
+ },
57
+ };
58
+
59
+ const authServices = AuthServiceFactory.create(
60
+ config,
61
+ new InMemoryUserRepository(),
62
+ new InMemoryCredentialRepository()
63
+ );
64
+ ```
65
+
66
+ ### 2. Casos de Uso
67
+
68
+ ```typescript
69
+ // Registro
70
+ const registerResult = await authServices.registerUserUseCase.execute({
71
+ email: "user@example.com",
72
+ password: "SecurePassword123!",
73
+ confirmPassword: "SecurePassword123!",
74
+ });
75
+
76
+ // Login
77
+ const loginResult = await authServices.loginWithPasswordUseCase.execute({
78
+ email: "user@example.com",
79
+ password: "SecurePassword123!",
80
+ });
81
+
82
+ console.log("Access Token:", loginResult.accessToken);
83
+ console.log("Refresh Token:", loginResult.refreshToken);
84
+
85
+ // Refresh
86
+ const refreshResult = await authServices.refreshTokenUseCase.execute({
87
+ refreshToken: loginResult.refreshToken,
88
+ });
89
+
90
+ // Logout
91
+ await authServices.logoutUseCase.execute({
92
+ refreshToken: refreshResult.refreshToken,
93
+ });
94
+ ```
95
+
96
+ ### 3. Middleware (Express)
97
+
98
+ ```typescript
99
+ import { JwtTokenVerifier } from "@ml-dev-core/jwt.auth";
100
+
101
+ export const authMiddleware = async (req, res, next) => {
102
+ try {
103
+ const token = req.headers.authorization?.substring(7);
104
+ const verifier = new JwtTokenVerifier();
105
+
106
+ const isValid = await verifier.verify(
107
+ token,
108
+ config.jwt.accessTokenSecret,
109
+ config.algorithm
110
+ );
111
+
112
+ if (!isValid) {
113
+ return res.status(401).json({ error: "Token inválido" });
114
+ }
115
+
116
+ const payload = await verifier.parsePayload(token);
117
+ req.user = payload;
118
+ next();
119
+ } catch (error) {
120
+ res.status(401).json({ error: "Error de autenticación" });
121
+ }
122
+ };
123
+ ```
124
+
125
+ ## 🏗️ Arquitectura
126
+
127
+ ```
128
+ ┌─────────────────────────────────────────┐
129
+ │ APPLICATION LAYER │
130
+ │ (Use Cases, DTOs, Factories) │
131
+ ├─────────────────────────────────────────┤
132
+ │ DOMAIN LAYER │
133
+ │ (Entities, Value Objects, Ports) │
134
+ ├─────────────────────────────────────────┤
135
+ │ INFRASTRUCTURE LAYER │
136
+ │ (JWT, Repositories, Security) │
137
+ ├─────────────────────────────────────────┤
138
+ │ SHARED LAYER │
139
+ │ (Types, Constants, Utils) │
140
+ └─────────────────────────────────────────┘
141
+ ```
142
+
143
+ ### Capas y Responsabilidades
144
+
145
+ - **Domain**: Lógica de negocio pura (entities, value objects, interfaces)
146
+ - **Application**: Orquestación de casos de uso y DTOs
147
+ - **Infrastructure**: Implementaciones concretas (JWT, bcrypt, repositorios)
148
+ - **Shared**: Utilidades y tipos compartidos
149
+
150
+ ## 📦 Exports Principales
151
+
152
+ ```typescript
153
+ // Factory principal
154
+ import { AuthServiceFactory } from "@ml-dev-core/jwt.auth";
155
+
156
+ // Casos de uso
157
+ import {
158
+ LoginWithPasswordUseCase,
159
+ RegisterUserUseCase,
160
+ RefreshTokenUseCase,
161
+ LogoutUseCase,
162
+ } from "@ml-dev-core/jwt.auth";
163
+
164
+ // DTOs
165
+ import {
166
+ LoginRequest,
167
+ LoginResponse,
168
+ RegisterUserRequest,
169
+ RefreshTokenRequest,
170
+ } from "@ml-dev-core/jwt.auth";
171
+
172
+ // Entidades del dominio
173
+ import { User, Credential } from "@ml-dev-core/jwt.auth";
174
+
175
+ // Value Objects
176
+ import { Email, HashedPassword, Role, Id } from "@ml-dev-core/jwt.auth";
177
+
178
+ // Componentes JWT
179
+ import { JwtTokenGenerator, JwtTokenVerifier } from "@ml-dev-core/jwt.auth";
180
+
181
+ // Implementaciones de seguridad
182
+ import { BcryptPasswordHasher } from "@ml-dev-core/jwt.auth";
183
+
184
+ // Repositorios in-memory (testing)
185
+ import {
186
+ InMemoryUserRepository,
187
+ InMemoryCredentialRepository,
188
+ } from "@ml-dev-core/jwt.auth";
189
+
190
+ // Interfaces
191
+ import {
192
+ IUserRepository,
193
+ ICredentialRepository,
194
+ IAuthConfig,
195
+ } from "@ml-dev-core/jwt.auth";
196
+ ```
197
+
198
+ ## 🔧 Configuración de Variables de Entorno
199
+
200
+ ```bash
201
+ # JWT Secrets
202
+ JWT_ACCESS_SECRET=your_super_secret_access_key_here
203
+ JWT_REFRESH_SECRET=your_super_secret_refresh_key_here
204
+
205
+ # JWT Timing
206
+ JWT_ACCESS_EXPIRATION=15m
207
+ JWT_REFRESH_EXPIRATION=7d
208
+
209
+ # JWT Info
210
+ JWT_ISSUER=your-app-name
211
+ JWT_AUDIENCE=your-client-app
212
+ JWT_ALGORITHM=HS256
213
+
214
+ # Security
215
+ BCRYPT_SALT_ROUNDS=12
216
+ ```
217
+
218
+ ## 🧪 Testing
219
+
220
+ ```typescript
221
+ import {
222
+ AuthServiceFactory,
223
+ InMemoryUserRepository,
224
+ InMemoryCredentialRepository,
225
+ } from "@ml-dev-core/jwt.auth";
226
+
227
+ describe("Auth Tests", () => {
228
+ let authServices;
229
+
230
+ beforeEach(() => {
231
+ authServices = AuthServiceFactory.create(
232
+ testConfig,
233
+ new InMemoryUserRepository(),
234
+ new InMemoryCredentialRepository()
235
+ );
236
+ });
237
+
238
+ it("should register and login user", async () => {
239
+ // Test implementation
240
+ });
241
+ });
242
+ ```
243
+
244
+ ## 📱 Frameworks Soportados
245
+
246
+ ### Express.js
247
+
248
+ ```typescript
249
+ app.use("/auth", authRoutes);
250
+ app.use("/api", authMiddleware);
251
+ ```
252
+
253
+ ### NestJS
254
+
255
+ ```typescript
256
+ @UseGuards(JwtAuthGuard)
257
+ @Controller("protected")
258
+ export class ProtectedController {}
259
+ ```
260
+
261
+ ### Fastify
262
+
263
+ ```typescript
264
+ fastify.addHook("onRequest", authMiddleware);
265
+ ```
266
+
267
+ ## 🔐 Algoritmos JWT Soportados
268
+
269
+ - **HMAC**: HS256, HS384, HS512 (clave simétrica)
270
+ - **RSA**: RS256, RS384, RS512 (clave asimétrica)
271
+ - **ECDSA**: ES256, ES384, ES512 (curva elíptica)
272
+
273
+ ## 📄 Scripts Disponibles
274
+
275
+ ```bash
276
+ # Construcción
277
+ npm run build
278
+
279
+ # Testing
280
+ npm test
281
+ npm run test:coverage
282
+ npm run test:watch
283
+
284
+ # Ejemplos
285
+ npm run example:help # Ver todos los comandos
286
+ npm run example:all # Ejecutar todos los ejemplos
287
+ npm run example:use-cases # Ejemplos de casos de uso
288
+ npm run example:jwt # Ejemplos de JWT
289
+ npm run example:factories # Ejemplos de factories
290
+ ```
291
+
292
+ ## 📋 Roadmap
293
+
294
+ - [ ] Integración con Prisma ORM
295
+ - [ ] Soporte para OAuth2
296
+ - [ ] Rate limiting integrado
297
+ - [ ] Audit logging
298
+ - [ ] Multi-tenancy support
299
+
300
+ ## 📜 Licencia
301
+
302
+ MIT © MLahuasi
303
+
304
+ ---
305
+
306
+ **¿Necesitas ayuda?** Consulta la [documentación completa](./install.md) o revisa los [ejemplos](./examples/).
@@ -0,0 +1,3 @@
1
+ export declare class BcryptPasswordHasherExample {
2
+ static Main(): Promise<void>;
3
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BcryptPasswordHasherExample = void 0;
4
+ const bcrypt_password_hasher_1 = require("../src/infrastructure/security/bcrypt-password-hasher");
5
+ class BcryptPasswordHasherExample {
6
+ static async Main() {
7
+ console.log("=== 🔐 Ejemplo de uso: BcryptPasswordHasher ===\n");
8
+ // 1️⃣ Contraseñas de prueba
9
+ const realPassword = "MyStrongPass#123";
10
+ const wrongPassword = "NotTheRightPass!";
11
+ const anotherWrong = "123456";
12
+ console.log("🧾 Password real de prueba:", realPassword);
13
+ console.log("🧾 Password equivocada 1:", wrongPassword);
14
+ console.log("🧾 Password equivocada 2:", anotherWrong, "\n");
15
+ // 2️⃣ Instanciamos el hasher
16
+ const hasher = new bcrypt_password_hasher_1.BcryptPasswordHasher();
17
+ // 3️⃣ Generar hash bcrypt desde el password real
18
+ const hash = await hasher.hash(realPassword);
19
+ console.log("🔑 Hash generado (bcrypt):");
20
+ console.log(hash, "\n");
21
+ // 4️⃣ Verificar el hash con la contraseña correcta
22
+ const isValid = await hasher.compare(realPassword, hash);
23
+ console.log("✅ ¿La contraseña REAL coincide con el hash?");
24
+ console.log(" Resultado:", isValid, "\n");
25
+ // 5️⃣ Verificar el hash con contraseñas incorrectas
26
+ const isValidWrong1 = await hasher.compare(wrongPassword, hash);
27
+ const isValidWrong2 = await hasher.compare(anotherWrong, hash);
28
+ console.log("❌ ¿Una contraseña equivocada coincide con el hash?");
29
+ console.log(` "${wrongPassword}" ->`, isValidWrong1);
30
+ console.log(` "${anotherWrong}" ->`, isValidWrong2, "\n");
31
+ // 6️⃣ Demostrar que NO se puede obtener el password original desde el hash
32
+ console.log("=== 🔒 Demostración: el hash es unidireccional ===");
33
+ console.log("Intentando 'recuperar' la contraseña solo a partir del hash...\n");
34
+ console.log("⚠️ Importante: no existe ninguna función como hasher.reverse(hash).");
35
+ console.log("Solo podemos PROBAR contraseñas candidatas y comparar.\n");
36
+ // Simulamos un pequeño ataque por diccionario
37
+ const candidatePasswords = [
38
+ "password",
39
+ "admin",
40
+ "qwerty",
41
+ "123456",
42
+ wrongPassword,
43
+ anotherWrong,
44
+ // Nota: aquí a propósito NO incluimos realPassword
45
+ ];
46
+ console.log("📚 Diccionario de prueba:");
47
+ console.log(candidatePasswords, "\n");
48
+ let recovered = null;
49
+ let attempts = 0;
50
+ for (const candidate of candidatePasswords) {
51
+ attempts++;
52
+ const matches = await hasher.compare(candidate, hash);
53
+ console.log(` 🔎 Probando candidato #${attempts}: "${candidate}" -> ${matches ? "COINCIDE" : "no coincide"}`);
54
+ if (matches) {
55
+ recovered = candidate;
56
+ break;
57
+ }
58
+ }
59
+ console.log("");
60
+ if (recovered) {
61
+ console.log("⚠️ El diccionario CONTENÍA la contraseña real.");
62
+ console.log("Se pudo descubrir porque estaba en la lista de candidatos.\n");
63
+ }
64
+ else {
65
+ console.log("✅ El diccionario NO contenía la contraseña real.");
66
+ console.log("No fue posible recuperar el valor original solo con el hash y este conjunto de candidatos.\n");
67
+ }
68
+ console.log("💡 Conclusión:");
69
+ console.log("- Bcrypt es una función de hash unidireccional: no se puede 'deshashear' para obtener el texto plano.");
70
+ console.log("- Lo único que se puede hacer es probar contraseñas candidatas con compare(password, hash).");
71
+ console.log("- Si la contraseña no está en el conjunto que pruebas (diccionario/fuerza bruta), no hay forma práctica de conocerla.");
72
+ }
73
+ }
74
+ exports.BcryptPasswordHasherExample = BcryptPasswordHasherExample;
75
+ // Para ejecutar este ejemplo directamente con Node (compilado a JS):
76
+ // (async () => {
77
+ // await BcryptPasswordHasherExample.Main();
78
+ // })();
@@ -0,0 +1,39 @@
1
+ export declare class EntityObjectExamples {
2
+ static Main(): Promise<void>;
3
+ /**
4
+ * Ejemplo demostrativo de uso de la clase Email.
5
+ * Muestra validaciones, comparaciones y manejo de errores.
6
+ */
7
+ static RunEmailExample(): Promise<void>;
8
+ /**
9
+ * Ejemplo demostrativo de uso de la clase HashedPassword.
10
+ * Muestra validación de formato, comparación de hashes y manejo de errores.
11
+ */
12
+ static RunHashedPasswordExample(): Promise<void>;
13
+ /**
14
+ * Ejemplo demostrativo de uso de la clase Id.
15
+ * Muestra generación, comparación e instanciación manual de identificadores.
16
+ */
17
+ static RunIdExample(): Promise<void>;
18
+ /**
19
+ * Ejemplo demostrativo de uso de la clase Permission.
20
+ * Muestra creación, comparación, coincidencias y manejo de errores.
21
+ */
22
+ static RunPermissionExample(): Promise<void>;
23
+ /**
24
+ * Ejemplo demostrativo de uso de la clase Role.
25
+ * Muestra creación de roles, validación de roles permitidos, manejo de permisos,
26
+ * uso de comodines, y verificación de acciones específicas.
27
+ */
28
+ static RunRoleExample(): Promise<void>;
29
+ /**
30
+ * Ejemplo demostrativo de uso de la entidad User.
31
+ * Muestra la creación, activación, desactivación y verificación de login.
32
+ */
33
+ static RunUserExample(): Promise<void>;
34
+ /**
35
+ * Ejemplo demostrativo de uso de la entidad Credential.
36
+ * Muestra cómo crear, validar y reconstruir credenciales dentro del dominio.
37
+ */
38
+ static RunCredentialExample(): Promise<void>;
39
+ }