@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
@@ -0,0 +1,20 @@
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("./login-with-password.use-case"), exports);
18
+ __exportStar(require("./logout.use-case"), exports);
19
+ __exportStar(require("./refresh-token.use-case"), exports);
20
+ __exportStar(require("./register-user.use-case"), exports);
@@ -0,0 +1,9 @@
1
+ import { IPasswordHasher, ITokenSession, IUserRepository } from "../../domain";
2
+ import { LoginRequest, LoginResponse } from "../dtos";
3
+ export declare class LoginWithPasswordUseCase {
4
+ private readonly userRepository;
5
+ private readonly passwordHasher;
6
+ private readonly tokenSessionService;
7
+ constructor(userRepository: IUserRepository, passwordHasher: IPasswordHasher, tokenSessionService: ITokenSession);
8
+ execute(request: LoginRequest): Promise<LoginResponse>;
9
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoginWithPasswordUseCase = void 0;
4
+ const domain_1 = require("../../domain");
5
+ class LoginWithPasswordUseCase {
6
+ constructor(userRepository, passwordHasher, tokenSessionService) {
7
+ this.userRepository = userRepository;
8
+ this.passwordHasher = passwordHasher;
9
+ this.tokenSessionService = tokenSessionService;
10
+ }
11
+ async execute(request) {
12
+ // Buscar usuario por email
13
+ const email = new domain_1.Email(request.email);
14
+ const user = await this.userRepository.findByEmail(email);
15
+ if (!user) {
16
+ throw new domain_1.UserNotFoundError("Invalid credentials");
17
+ }
18
+ // Verificar que el usuario esté activo
19
+ if (!user.canLogin()) {
20
+ throw new domain_1.UserDisabledError("User account is not active");
21
+ }
22
+ // Verificar contraseña
23
+ const isPasswordValid = await this.passwordHasher.compare(request.password, user.password.serialize());
24
+ if (!isPasswordValid) {
25
+ throw new domain_1.PasswordMismatchError("Invalid credentials");
26
+ }
27
+ // Crear sesión con tokens
28
+ const credential = await this.tokenSessionService.createSession(user);
29
+ // Retornar respuesta
30
+ return {
31
+ accessToken: credential.accessToken,
32
+ refreshToken: credential.refreshToken,
33
+ };
34
+ }
35
+ }
36
+ exports.LoginWithPasswordUseCase = LoginWithPasswordUseCase;
@@ -0,0 +1,7 @@
1
+ import { ITokenSession } from "../../domain";
2
+ import { LogoutRequest, LogoutResponse } from "../dtos";
3
+ export declare class LogoutUseCase {
4
+ private readonly tokenSession;
5
+ constructor(tokenSession: ITokenSession);
6
+ execute(request: LogoutRequest): Promise<LogoutResponse>;
7
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogoutUseCase = void 0;
4
+ const domain_1 = require("../../domain");
5
+ class LogoutUseCase {
6
+ constructor(tokenSession) {
7
+ this.tokenSession = tokenSession;
8
+ }
9
+ async execute(request) {
10
+ try {
11
+ await this.tokenSession.revokeSession(request.refreshToken);
12
+ return {
13
+ success: true,
14
+ message: "Successfully logged out",
15
+ };
16
+ }
17
+ catch (error) {
18
+ throw new domain_1.LogoutError("Failed to logout: invalid refresh token");
19
+ }
20
+ }
21
+ }
22
+ exports.LogoutUseCase = LogoutUseCase;
@@ -0,0 +1,7 @@
1
+ import { ITokenSession } from "../../domain";
2
+ import { RefreshTokenRequest, RefreshTokenResponse } from "../dtos";
3
+ export declare class RefreshTokenUseCase {
4
+ private readonly tokenSessionService;
5
+ constructor(tokenSessionService: ITokenSession);
6
+ execute(request: RefreshTokenRequest): Promise<RefreshTokenResponse>;
7
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RefreshTokenUseCase = void 0;
4
+ const domain_1 = require("../../domain");
5
+ class RefreshTokenUseCase {
6
+ constructor(tokenSessionService) {
7
+ this.tokenSessionService = tokenSessionService;
8
+ }
9
+ async execute(request) {
10
+ try {
11
+ // Refrescar la sesión
12
+ const credential = await this.tokenSessionService.refreshSession(request.refreshToken);
13
+ return {
14
+ accessToken: credential.accessToken,
15
+ refreshToken: credential.refreshToken,
16
+ };
17
+ }
18
+ catch (error) {
19
+ throw new domain_1.InvalidOrExpiredRefreshTokenError();
20
+ }
21
+ }
22
+ }
23
+ exports.RefreshTokenUseCase = RefreshTokenUseCase;
@@ -0,0 +1,10 @@
1
+ import { IPasswordHasher, IPasswordPolicy } from "../../domain";
2
+ import { IUserRepository } from "../../domain/ports/repository";
3
+ import { RegisterUserRequest, RegisterUserResponse } from "../dtos";
4
+ export declare class RegisterUserUseCase {
5
+ private readonly userRepository;
6
+ private readonly passwordHasher;
7
+ private readonly passwordPolicy;
8
+ constructor(userRepository: IUserRepository, passwordHasher: IPasswordHasher, passwordPolicy: IPasswordPolicy);
9
+ execute(request: RegisterUserRequest): Promise<RegisterUserResponse>;
10
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RegisterUserUseCase = void 0;
4
+ const domain_1 = require("../../domain");
5
+ class RegisterUserUseCase {
6
+ constructor(userRepository, passwordHasher, passwordPolicy) {
7
+ this.userRepository = userRepository;
8
+ this.passwordHasher = passwordHasher;
9
+ this.passwordPolicy = passwordPolicy;
10
+ }
11
+ async execute(request) {
12
+ // Validar política de contraseñas
13
+ const passwordValidation = this.passwordPolicy.validateStrength(request.password);
14
+ if (!passwordValidation.isValid) {
15
+ throw new domain_1.PasswordPolicyViolationError(passwordValidation.errors);
16
+ }
17
+ // Verificar que el email no esté en uso
18
+ const email = new domain_1.Email(request.email);
19
+ const exists = await this.userRepository.findByEmail(email);
20
+ if (exists) {
21
+ throw new domain_1.EmailAlreadyInUseError();
22
+ }
23
+ // Hash de la contraseña
24
+ const hashedPassword = await this.passwordHasher.hash(request.password);
25
+ // Crear el usuario
26
+ const user = domain_1.User.create(request.email, request.roles?.map((r) => new domain_1.Role(r.role, r.permissions?.map((permission) => new domain_1.Permission(permission)))) || [], hashedPassword);
27
+ // Guardar en repositorio
28
+ await this.userRepository.save(user);
29
+ // Retornar respuesta
30
+ return {
31
+ id: user.id.getValue(),
32
+ roles: user.roles.map((role) => role.getValuePublic()),
33
+ isActive: user.isActive,
34
+ };
35
+ }
36
+ }
37
+ exports.RegisterUserUseCase = RegisterUserUseCase;
@@ -0,0 +1,78 @@
1
+ import { Id } from "../object-values";
2
+ import { ICredentialProps } from "../props/entities";
3
+ /**
4
+ * Representa las credenciales activas de un usuario dentro del dominio
5
+ */
6
+ export declare class Credential {
7
+ /**
8
+ * Identificador del usuario asociado a las credenciales
9
+ */
10
+ private readonly _userId;
11
+ /**
12
+ * Token de acceso asociado
13
+ */
14
+ private readonly _accessToken;
15
+ /**
16
+ * Token de refresco asociado
17
+ */
18
+ private readonly _refreshToken;
19
+ /**
20
+ * Fecha de expiración del token de acceso
21
+ */
22
+ private readonly _expiresAt;
23
+ /**
24
+ * Fecha de creación de las credenciales
25
+ */
26
+ private readonly _createdAt;
27
+ /**
28
+ * Constructor privado para evitar instanciación directa
29
+ * @param props Propiedades de las credenciales
30
+ */
31
+ constructor(props: ICredentialProps);
32
+ /**
33
+ * Obtiene el identificador del usuario asociado a las credenciales
34
+ */
35
+ get userId(): Id;
36
+ /**
37
+ * Obtiene el token de acceso
38
+ */
39
+ get accessToken(): string;
40
+ /**
41
+ * Obtiene el token de refresco
42
+ */
43
+ get refreshToken(): string;
44
+ /**
45
+ * Obtiene la fecha de expiración del token de acceso
46
+ */
47
+ get expiresAt(): Date;
48
+ /**
49
+ * Obtiene la fecha de creación de las credenciales
50
+ */
51
+ get createdAt(): Date;
52
+ /**
53
+ * Evalúa si las credenciales han expirado
54
+ * @returns Verdadero si las credenciales han expirado, falso en caso contrario
55
+ */
56
+ isExpired(): boolean;
57
+ /**
58
+ * Evalúa si las credenciales son válidas (no expiradas)
59
+ * @returns Verdadero si las credenciales son válidas (no expiradas), falso en caso contrario
60
+ */
61
+ isValid(): boolean;
62
+ /**
63
+ * Crea una nueva instancia de Credential
64
+ * @param userId Identificador del usuario
65
+ * @param accessToken Token de acceso
66
+ * @param refreshToken Token de refresco
67
+ * @param expirationDate Fecha de expiración del token de acceso
68
+ * @returns Nueva instancia de Credential
69
+ */
70
+ static create(userId: Id, accessToken: string, refreshToken: string, expirationDate: Date): Credential;
71
+ /**
72
+ *Reconstitution method for repository
73
+ *Método usado por un repositorio para reconstruir la entidad desde la base de datos
74
+ * @param props Propiedades de las credenciales
75
+ * @returns Nueva instancia de Credential
76
+ */
77
+ static reconstitute(props: ICredentialProps): Credential;
78
+ }
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Credential = void 0;
4
+ /**
5
+ * Representa las credenciales activas de un usuario dentro del dominio
6
+ */
7
+ class Credential {
8
+ /**
9
+ * Constructor privado para evitar instanciación directa
10
+ * @param props Propiedades de las credenciales
11
+ */
12
+ constructor(props) {
13
+ this._userId = props.userId;
14
+ this._accessToken = props.accessToken;
15
+ this._refreshToken = props.refreshToken;
16
+ this._expiresAt = props.expiresAt;
17
+ this._createdAt = props.createdAt;
18
+ }
19
+ // Getters
20
+ /**
21
+ * Obtiene el identificador del usuario asociado a las credenciales
22
+ */
23
+ get userId() {
24
+ return this._userId;
25
+ }
26
+ /**
27
+ * Obtiene el token de acceso
28
+ */
29
+ get accessToken() {
30
+ return this._accessToken;
31
+ }
32
+ /**
33
+ * Obtiene el token de refresco
34
+ */
35
+ get refreshToken() {
36
+ return this._refreshToken;
37
+ }
38
+ /**
39
+ * Obtiene la fecha de expiración del token de acceso
40
+ */
41
+ get expiresAt() {
42
+ return new Date(this._expiresAt);
43
+ }
44
+ /**
45
+ * Obtiene la fecha de creación de las credenciales
46
+ */
47
+ get createdAt() {
48
+ return new Date(this._createdAt);
49
+ }
50
+ // Business methods
51
+ /**
52
+ * Evalúa si las credenciales han expirado
53
+ * @returns Verdadero si las credenciales han expirado, falso en caso contrario
54
+ */
55
+ isExpired() {
56
+ return new Date() > this._expiresAt;
57
+ }
58
+ /**
59
+ * Evalúa si las credenciales son válidas (no expiradas)
60
+ * @returns Verdadero si las credenciales son válidas (no expiradas), falso en caso contrario
61
+ */
62
+ isValid() {
63
+ return !this.isExpired();
64
+ }
65
+ /**
66
+ * Crea una nueva instancia de Credential
67
+ * @param userId Identificador del usuario
68
+ * @param accessToken Token de acceso
69
+ * @param refreshToken Token de refresco
70
+ * @param expirationDate Fecha de expiración del token de acceso
71
+ * @returns Nueva instancia de Credential
72
+ */
73
+ static create(userId, accessToken, refreshToken, expirationDate) {
74
+ return new Credential({
75
+ userId,
76
+ accessToken,
77
+ refreshToken,
78
+ expiresAt: expirationDate,
79
+ createdAt: new Date(),
80
+ });
81
+ }
82
+ /**
83
+ *Reconstitution method for repository
84
+ *Método usado por un repositorio para reconstruir la entidad desde la base de datos
85
+ * @param props Propiedades de las credenciales
86
+ * @returns Nueva instancia de Credential
87
+ */
88
+ static reconstitute(props) {
89
+ return new Credential(props);
90
+ }
91
+ }
92
+ exports.Credential = Credential;
@@ -0,0 +1,2 @@
1
+ export * from "./credential.entity";
2
+ export * from "./user.entity";
@@ -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("./credential.entity"), exports);
18
+ __exportStar(require("./user.entity"), exports);
@@ -0,0 +1,97 @@
1
+ import { Email, HashedPassword, Id, Role } from "../object-values";
2
+ import { IUserProps } from "../props";
3
+ /**
4
+ *Representa al agregado raíz de dominio del usuario en una arquitectura limpia o DDD (Domain-Driven Design).
5
+ */
6
+ export declare class User {
7
+ /**
8
+ * Identificador único del usuario
9
+ */
10
+ private readonly _id;
11
+ /**
12
+ * Correo electrónico del usuario
13
+ */
14
+ private readonly _email;
15
+ /**
16
+ * Rol del usuario dentro del sistema
17
+ */
18
+ private readonly _roles;
19
+ /**
20
+ * Contraseña hasheada del usuario
21
+ */
22
+ private readonly _password;
23
+ /**
24
+ * Indica si el usuario está activo o inactivo
25
+ */
26
+ private _isActive;
27
+ /**
28
+ * Fecha de creación del usuario
29
+ */
30
+ private readonly _createdAt;
31
+ /**
32
+ * Fecha de última actualización del usuario
33
+ */
34
+ private _updatedAt;
35
+ /**
36
+ * Constructor privado para evitar instanciación directa
37
+ * @param props Propiedades del usuario
38
+ */
39
+ constructor(props: IUserProps);
40
+ /**
41
+ * Obtiene el identificador único del usuario
42
+ */
43
+ get id(): Id;
44
+ /**
45
+ * Obtiene el correo electrónico del usuario
46
+ */
47
+ get email(): Email;
48
+ /**
49
+ * Obtiene el rol del usuario
50
+ */
51
+ get roles(): Role[];
52
+ /**
53
+ * Obtiene la contraseña hasheada del usuario
54
+ */
55
+ get password(): HashedPassword;
56
+ /**
57
+ * Indica si el usuario está activo o inactivo
58
+ */
59
+ get isActive(): boolean;
60
+ /**
61
+ * Obtiene la fecha de creación del usuario
62
+ */
63
+ get createdAt(): Date;
64
+ /**
65
+ * Obtiene la fecha de última actualización del usuario
66
+ */
67
+ get updatedAt(): Date;
68
+ /**
69
+ * Marca al usuario como activo
70
+ */
71
+ activate(): void;
72
+ /**
73
+ * Marca al usuario como inactivo
74
+ */
75
+ deactivate(): void;
76
+ /**
77
+ * Evalúa si el usuario puede iniciar sesión
78
+ * @returns Verdadero si el usuario puede iniciar sesión, falso en caso contrario
79
+ */
80
+ canLogin(): boolean;
81
+ /**
82
+ * Factory method to create a new User
83
+ * @param email email
84
+ * @param role role
85
+ * @param hashedPassword hashed password
86
+ * @returns New User instance
87
+ */
88
+ static create(email: string, roles: Role[], hashedPassword: string): User;
89
+ /**
90
+ *Reconstitution method for repository
91
+ *Método usado por los repositorios al reconstruir
92
+ *el usuario desde la base de datos o una fuente persistente
93
+ * @param props Propiedades del usuario
94
+ * @returns Nueva instancia de User
95
+ */
96
+ static reconstitute(props: IUserProps): User;
97
+ }
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.User = void 0;
4
+ const object_values_1 = require("../object-values");
5
+ /**
6
+ *Representa al agregado raíz de dominio del usuario en una arquitectura limpia o DDD (Domain-Driven Design).
7
+ */
8
+ class User {
9
+ /**
10
+ * Constructor privado para evitar instanciación directa
11
+ * @param props Propiedades del usuario
12
+ */
13
+ constructor(props) {
14
+ this._id = props.id;
15
+ this._email = props.email;
16
+ this._roles = props.roles;
17
+ this._password = props.password;
18
+ this._isActive = props.isActive;
19
+ this._createdAt = props.createdAt;
20
+ this._updatedAt = props.updatedAt;
21
+ }
22
+ // Getters
23
+ /**
24
+ * Obtiene el identificador único del usuario
25
+ */
26
+ get id() {
27
+ return this._id;
28
+ }
29
+ /**
30
+ * Obtiene el correo electrónico del usuario
31
+ */
32
+ get email() {
33
+ return this._email;
34
+ }
35
+ /**
36
+ * Obtiene el rol del usuario
37
+ */
38
+ get roles() {
39
+ return this._roles;
40
+ }
41
+ /**
42
+ * Obtiene la contraseña hasheada del usuario
43
+ */
44
+ get password() {
45
+ return this._password;
46
+ }
47
+ /**
48
+ * Indica si el usuario está activo o inactivo
49
+ */
50
+ get isActive() {
51
+ return this._isActive;
52
+ }
53
+ /**
54
+ * Obtiene la fecha de creación del usuario
55
+ */
56
+ get createdAt() {
57
+ return new Date(this._createdAt);
58
+ }
59
+ /**
60
+ * Obtiene la fecha de última actualización del usuario
61
+ */
62
+ get updatedAt() {
63
+ return new Date(this._updatedAt);
64
+ }
65
+ // Business methods
66
+ /**
67
+ * Marca al usuario como activo
68
+ */
69
+ activate() {
70
+ this._isActive = true;
71
+ this._updatedAt = new Date();
72
+ }
73
+ /**
74
+ * Marca al usuario como inactivo
75
+ */
76
+ deactivate() {
77
+ this._isActive = false;
78
+ this._updatedAt = new Date();
79
+ }
80
+ /**
81
+ * Evalúa si el usuario puede iniciar sesión
82
+ * @returns Verdadero si el usuario puede iniciar sesión, falso en caso contrario
83
+ */
84
+ canLogin() {
85
+ return this._isActive;
86
+ }
87
+ /**
88
+ * Factory method to create a new User
89
+ * @param email email
90
+ * @param role role
91
+ * @param hashedPassword hashed password
92
+ * @returns New User instance
93
+ */
94
+ static create(email, roles, hashedPassword) {
95
+ return new User({
96
+ id: object_values_1.Id.generate(),
97
+ email: new object_values_1.Email(email),
98
+ roles: roles,
99
+ password: new object_values_1.HashedPassword(hashedPassword),
100
+ isActive: true,
101
+ createdAt: new Date(),
102
+ updatedAt: new Date(),
103
+ });
104
+ }
105
+ /**
106
+ *Reconstitution method for repository
107
+ *Método usado por los repositorios al reconstruir
108
+ *el usuario desde la base de datos o una fuente persistente
109
+ * @param props Propiedades del usuario
110
+ * @returns Nueva instancia de User
111
+ */
112
+ static reconstitute(props) {
113
+ return new User(props);
114
+ }
115
+ }
116
+ exports.User = User;
@@ -0,0 +1,82 @@
1
+ export type AuthErrorCode = "TOKEN_EXPIRED" | "TOKEN_NOT_YET_VALID" | "TOKEN_INVALID" | "TOKEN_MALFORMED" | "SIGNATURE_INVALID" | "ALGORITHM_UNSUPPORTED" | "KEY_NOT_FOUND" | "KEY_MISMATCH" | "TOKEN_REVOKED" | "CLOCK_SKEW" | "AUTHENTICATION_FAILED" | "CLAIMS_VALIDATION_ERROR";
2
+ export interface ClaimsIssue {
3
+ path: string;
4
+ message: string;
5
+ }
6
+ export declare abstract class AuthDomainError extends Error {
7
+ readonly code: AuthErrorCode;
8
+ readonly details?: unknown;
9
+ constructor(message: string, code: AuthErrorCode, details?: unknown);
10
+ toJSON(): {
11
+ name: string;
12
+ message: string;
13
+ code: AuthErrorCode;
14
+ details: unknown;
15
+ };
16
+ static isAuthError(e: unknown): e is AuthDomainError;
17
+ }
18
+ /** El token ya no es válido por exp (exp < now) */
19
+ export declare class TokenExpiredError extends AuthDomainError {
20
+ constructor(message?: string, details?: {
21
+ exp?: number;
22
+ now?: number;
23
+ });
24
+ }
25
+ /** El token aún no debe usarse (nbf > now) */
26
+ export declare class TokenNotYetValidError extends AuthDomainError {
27
+ constructor(message?: string, details?: {
28
+ nbf?: number;
29
+ now?: number;
30
+ });
31
+ }
32
+ /** Formato inválido (no tiene 3 partes, base64url inválido, JSON inválido) */
33
+ export declare class InvalidTokenFormatError extends AuthDomainError {
34
+ constructor(message?: string, details?: unknown);
35
+ }
36
+ /** Firma inválida (no coincide con datos/clave) */
37
+ export declare class InvalidSignatureError extends AuthDomainError {
38
+ constructor(message?: string, details?: unknown);
39
+ }
40
+ /** Algoritmo no soportado por la librería/política */
41
+ export declare class UnsupportedAlgorithmError extends AuthDomainError {
42
+ constructor(message?: string, details?: {
43
+ alg: string;
44
+ });
45
+ }
46
+ /** No se pudo resolver/obtener la clave necesaria (kid, store…) */
47
+ export declare class KeyNotFoundError extends AuthDomainError {
48
+ constructor(message?: string, details?: {
49
+ kid?: string;
50
+ });
51
+ }
52
+ /** La clave encontrada no corresponde (key-id/alg desalineado, par incorrecto) */
53
+ export declare class KeyMismatchError extends AuthDomainError {
54
+ constructor(message?: string, details?: {
55
+ alg?: string;
56
+ kid?: string;
57
+ });
58
+ }
59
+ /** Token revocado en listas de deny/blacklist */
60
+ export declare class TokenRevokedError extends AuthDomainError {
61
+ constructor(message?: string, details?: {
62
+ jti?: string;
63
+ });
64
+ }
65
+ /** Desfase de reloj detectado (leeway insuficiente) */
66
+ export declare class ClockSkewError extends AuthDomainError {
67
+ constructor(message?: string, details?: {
68
+ skewSeconds?: number;
69
+ });
70
+ }
71
+ /** Claims inválidas a nivel semántico (aud, iss, scope, custom…) */
72
+ export declare class ClaimsValidationError extends AuthDomainError {
73
+ constructor(issues: ClaimsIssue[], message?: string);
74
+ }
75
+ /** Falla general de autenticación (catch-all) */
76
+ export declare class AuthenticationError extends AuthDomainError {
77
+ constructor(message?: string, details?: unknown);
78
+ }
79
+ /** Alias histórico si lo usabas antes */
80
+ export declare class InvalidTokenError extends AuthenticationError {
81
+ constructor(message?: string, details?: unknown);
82
+ }