rl-core-api 0.1.0

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 (338) hide show
  1. package/README.md +99 -0
  2. package/dist/app.module.d.ts +2 -0
  3. package/dist/app.module.js +19 -0
  4. package/dist/core/auth/authenticatedUser.interface.d.ts +16 -0
  5. package/dist/core/auth/authenticatedUser.interface.js +2 -0
  6. package/dist/core/auth/cookie.util.d.ts +9 -0
  7. package/dist/core/auth/cookie.util.js +28 -0
  8. package/dist/core/auth/decorators/currentUser.decorator.d.ts +2 -0
  9. package/dist/core/auth/decorators/currentUser.decorator.js +9 -0
  10. package/dist/core/auth/decorators/public.decorator.d.ts +3 -0
  11. package/dist/core/auth/decorators/public.decorator.js +7 -0
  12. package/dist/core/auth/decorators/requirePermission.decorator.d.ts +5 -0
  13. package/dist/core/auth/decorators/requirePermission.decorator.js +10 -0
  14. package/dist/core/auth/guards/appThrottler.guard.d.ts +5 -0
  15. package/dist/core/auth/guards/appThrottler.guard.js +23 -0
  16. package/dist/core/auth/guards/csrf.guard.d.ts +8 -0
  17. package/dist/core/auth/guards/csrf.guard.js +55 -0
  18. package/dist/core/auth/guards/jwtAuth.guard.d.ts +10 -0
  19. package/dist/core/auth/guards/jwtAuth.guard.js +37 -0
  20. package/dist/core/auth/guards/permissions.guard.d.ts +7 -0
  21. package/dist/core/auth/guards/permissions.guard.js +42 -0
  22. package/dist/core/bootstrap/bootstrapCore.util.d.ts +9 -0
  23. package/dist/core/bootstrap/bootstrapCore.util.js +67 -0
  24. package/dist/core/config/config.module.d.ts +8 -0
  25. package/dist/core/config/config.module.js +34 -0
  26. package/dist/core/config/env.schema.d.ts +65 -0
  27. package/dist/core/config/env.schema.js +94 -0
  28. package/dist/core/config/env.service.d.ts +7 -0
  29. package/dist/core/config/env.service.js +27 -0
  30. package/dist/core/context/auditContext.d.ts +7 -0
  31. package/dist/core/context/auditContext.js +5 -0
  32. package/dist/core/core.module.d.ts +11 -0
  33. package/dist/core/core.module.js +73 -0
  34. package/dist/core/database/base.schema.d.ts +7 -0
  35. package/dist/core/database/base.schema.js +49 -0
  36. package/dist/core/database/createDataSource.util.d.ts +8 -0
  37. package/dist/core/database/createDataSource.util.js +27 -0
  38. package/dist/core/database/migrations/1710000000000-InitialSchema.d.ts +6 -0
  39. package/dist/core/database/migrations/1710000000000-InitialSchema.js +272 -0
  40. package/dist/core/database/migrations/1786060800000-FirstAccessTokenType.d.ts +6 -0
  41. package/dist/core/database/migrations/1786060800000-FirstAccessTokenType.js +19 -0
  42. package/dist/core/database/migrations/1786147200000-PermanentAccountLock.d.ts +6 -0
  43. package/dist/core/database/migrations/1786147200000-PermanentAccountLock.js +15 -0
  44. package/dist/core/database/migrations/1786233600000-Notifications.d.ts +6 -0
  45. package/dist/core/database/migrations/1786233600000-Notifications.js +59 -0
  46. package/dist/core/database/migrations/index.d.ts +3 -0
  47. package/dist/core/database/migrations/index.js +13 -0
  48. package/dist/core/database/seeds/runSeeds.d.ts +1 -0
  49. package/dist/core/database/seeds/runSeeds.js +20 -0
  50. package/dist/core/database/seeds/seedAdmin.d.ts +2 -0
  51. package/dist/core/database/seeds/seedAdmin.js +44 -0
  52. package/dist/core/database/seeds/seedPermissions.d.ts +2 -0
  53. package/dist/core/database/seeds/seedPermissions.js +93 -0
  54. package/dist/core/events/appEvent.enum.d.ts +31 -0
  55. package/dist/core/events/appEvent.enum.js +12 -0
  56. package/dist/core/filters/allExceptions.filter.d.ts +5 -0
  57. package/dist/core/filters/allExceptions.filter.js +61 -0
  58. package/dist/core/filters/appErrorCode.enum.d.ts +9 -0
  59. package/dist/core/filters/appErrorCode.enum.js +13 -0
  60. package/dist/core/health/health.controller.d.ts +11 -0
  61. package/dist/core/health/health.controller.js +56 -0
  62. package/dist/core/logger/winston.config.d.ts +2 -0
  63. package/dist/core/logger/winston.config.js +74 -0
  64. package/dist/core/mailer/mailer.module.d.ts +2 -0
  65. package/dist/core/mailer/mailer.module.js +21 -0
  66. package/dist/core/mailer/mailer.service.d.ts +14 -0
  67. package/dist/core/mailer/mailer.service.js +148 -0
  68. package/dist/core/openapi/exportOpenapi.d.ts +1 -0
  69. package/dist/core/openapi/exportOpenapi.js +25 -0
  70. package/dist/core/query/applyFilter.util.d.ts +11 -0
  71. package/dist/core/query/applyFilter.util.js +122 -0
  72. package/dist/core/query/filter.constants.d.ts +7 -0
  73. package/dist/core/query/filter.constants.js +64 -0
  74. package/dist/core/query/filterField.interface.d.ts +35 -0
  75. package/dist/core/query/filterField.interface.js +2 -0
  76. package/dist/core/query/filterFieldType.enum.d.ts +10 -0
  77. package/dist/core/query/filterFieldType.enum.js +14 -0
  78. package/dist/core/query/filterOperator.enum.d.ts +23 -0
  79. package/dist/core/query/filterOperator.enum.js +28 -0
  80. package/dist/core/query/filterSchema.response.d.ts +17 -0
  81. package/dist/core/query/filterSchema.response.js +82 -0
  82. package/dist/core/query/filterSort.util.d.ts +7 -0
  83. package/dist/core/query/filterSort.util.js +11 -0
  84. package/dist/core/query/paginateWithFilter.util.d.ts +11 -0
  85. package/dist/core/query/paginateWithFilter.util.js +37 -0
  86. package/dist/core/query/parseFilter.util.d.ts +2 -0
  87. package/dist/core/query/parseFilter.util.js +220 -0
  88. package/dist/core/utils/codedError.util.d.ts +5 -0
  89. package/dist/core/utils/codedError.util.js +23 -0
  90. package/dist/core/utils/crypto.util.d.ts +2 -0
  91. package/dist/core/utils/crypto.util.js +39 -0
  92. package/dist/core/utils/hash.util.d.ts +6 -0
  93. package/dist/core/utils/hash.util.js +67 -0
  94. package/dist/core/utils/ip.util.d.ts +1 -0
  95. package/dist/core/utils/ip.util.js +15 -0
  96. package/dist/core/utils/pagination.util.d.ts +21 -0
  97. package/dist/core/utils/pagination.util.js +98 -0
  98. package/dist/core/utils/paginationMeta.response.d.ts +7 -0
  99. package/dist/core/utils/paginationMeta.response.js +32 -0
  100. package/dist/core/utils/password.constants.d.ts +2 -0
  101. package/dist/core/utils/password.constants.js +5 -0
  102. package/dist/core/websocket/baseGateway.d.ts +21 -0
  103. package/dist/core/websocket/baseGateway.js +63 -0
  104. package/dist/core/websocket/socket.constants.d.ts +4 -0
  105. package/dist/core/websocket/socket.constants.js +9 -0
  106. package/dist/core/websocket/socketEvent.envelope.d.ts +8 -0
  107. package/dist/core/websocket/socketEvent.envelope.js +11 -0
  108. package/dist/core/websocket/socketOrigin.util.d.ts +2 -0
  109. package/dist/core/websocket/socketOrigin.util.js +15 -0
  110. package/dist/core/websocket/wsAuth.service.d.ts +20 -0
  111. package/dist/core/websocket/wsAuth.service.js +97 -0
  112. package/dist/core/websocket/wsUserResolver.interface.d.ts +5 -0
  113. package/dist/core/websocket/wsUserResolver.interface.js +4 -0
  114. package/dist/coreEntities.d.ts +12 -0
  115. package/dist/coreEntities.js +35 -0
  116. package/dist/dataSource.d.ts +3 -0
  117. package/dist/dataSource.js +13 -0
  118. package/dist/features/audit/audit.module.d.ts +2 -0
  119. package/dist/features/audit/audit.module.js +44 -0
  120. package/dist/features/audit/domain/audit.service.d.ts +34 -0
  121. package/dist/features/audit/domain/audit.service.js +93 -0
  122. package/dist/features/audit/domain/classifyError.util.d.ts +2 -0
  123. package/dist/features/audit/domain/classifyError.util.js +24 -0
  124. package/dist/features/audit/domain/index.d.ts +2 -0
  125. package/dist/features/audit/domain/index.js +18 -0
  126. package/dist/features/audit/infra/auditData.subscriber.d.ts +17 -0
  127. package/dist/features/audit/infra/auditData.subscriber.js +139 -0
  128. package/dist/features/audit/infra/index.d.ts +7 -0
  129. package/dist/features/audit/infra/index.js +23 -0
  130. package/dist/features/audit/infra/repositories/auditChange.repository.d.ts +7 -0
  131. package/dist/features/audit/infra/repositories/auditChange.repository.js +35 -0
  132. package/dist/features/audit/infra/repositories/auditDataChange.repository.d.ts +7 -0
  133. package/dist/features/audit/infra/repositories/auditDataChange.repository.js +35 -0
  134. package/dist/features/audit/infra/repositories/errorLog.repository.d.ts +7 -0
  135. package/dist/features/audit/infra/repositories/errorLog.repository.js +35 -0
  136. package/dist/features/audit/infra/schema/auditChange.schema.d.ts +14 -0
  137. package/dist/features/audit/infra/schema/auditChange.schema.js +68 -0
  138. package/dist/features/audit/infra/schema/auditDataChange.schema.d.ts +15 -0
  139. package/dist/features/audit/infra/schema/auditDataChange.schema.js +56 -0
  140. package/dist/features/audit/infra/schema/errorLog.schema.d.ts +21 -0
  141. package/dist/features/audit/infra/schema/errorLog.schema.js +69 -0
  142. package/dist/features/audit/presentation/audit.controller.d.ts +16 -0
  143. package/dist/features/audit/presentation/audit.controller.js +107 -0
  144. package/dist/features/audit/presentation/audit.interceptor.d.ts +8 -0
  145. package/dist/features/audit/presentation/audit.interceptor.js +78 -0
  146. package/dist/features/audit/presentation/filters/audit.filters.d.ts +4 -0
  147. package/dist/features/audit/presentation/filters/audit.filters.js +154 -0
  148. package/dist/features/audit/presentation/index.d.ts +2 -0
  149. package/dist/features/audit/presentation/index.js +18 -0
  150. package/dist/features/audit/presentation/responses/auditDataChange.response.d.ts +25 -0
  151. package/dist/features/audit/presentation/responses/auditDataChange.response.js +96 -0
  152. package/dist/features/audit/presentation/responses/log.response.d.ts +45 -0
  153. package/dist/features/audit/presentation/responses/log.response.js +164 -0
  154. package/dist/features/auth/auth.module.d.ts +2 -0
  155. package/dist/features/auth/auth.module.js +55 -0
  156. package/dist/features/auth/domain/auth.service.d.ts +66 -0
  157. package/dist/features/auth/domain/auth.service.js +289 -0
  158. package/dist/features/auth/domain/index.d.ts +5 -0
  159. package/dist/features/auth/domain/index.js +21 -0
  160. package/dist/features/auth/domain/jwtPayload.interface.d.ts +11 -0
  161. package/dist/features/auth/domain/jwtPayload.interface.js +2 -0
  162. package/dist/features/auth/domain/token.service.d.ts +56 -0
  163. package/dist/features/auth/domain/token.service.js +205 -0
  164. package/dist/features/auth/domain/twoFactor.service.d.ts +19 -0
  165. package/dist/features/auth/domain/twoFactor.service.js +103 -0
  166. package/dist/features/auth/domain/wsUserResolver.service.d.ts +10 -0
  167. package/dist/features/auth/domain/wsUserResolver.service.js +34 -0
  168. package/dist/features/auth/infra/index.d.ts +2 -0
  169. package/dist/features/auth/infra/index.js +18 -0
  170. package/dist/features/auth/infra/repositories/authToken.repository.d.ts +5 -0
  171. package/dist/features/auth/infra/repositories/authToken.repository.js +25 -0
  172. package/dist/features/auth/infra/schema/authToken.schema.d.ts +21 -0
  173. package/dist/features/auth/infra/schema/authToken.schema.js +73 -0
  174. package/dist/features/auth/presentation/auth.controller.d.ts +56 -0
  175. package/dist/features/auth/presentation/auth.controller.js +242 -0
  176. package/dist/features/auth/presentation/commands/clientType.enum.d.ts +4 -0
  177. package/dist/features/auth/presentation/commands/clientType.enum.js +8 -0
  178. package/dist/features/auth/presentation/commands/login.command.d.ts +4 -0
  179. package/dist/features/auth/presentation/commands/login.command.js +28 -0
  180. package/dist/features/auth/presentation/commands/password.command.d.ts +7 -0
  181. package/dist/features/auth/presentation/commands/password.command.js +37 -0
  182. package/dist/features/auth/presentation/commands/refreshToken.command.d.ts +3 -0
  183. package/dist/features/auth/presentation/commands/refreshToken.command.js +26 -0
  184. package/dist/features/auth/presentation/commands/twoFactor.command.d.ts +12 -0
  185. package/dist/features/auth/presentation/commands/twoFactor.command.js +68 -0
  186. package/dist/features/auth/presentation/index.d.ts +7 -0
  187. package/dist/features/auth/presentation/index.js +23 -0
  188. package/dist/features/auth/presentation/responses/sessionUser.response.d.ts +19 -0
  189. package/dist/features/auth/presentation/responses/sessionUser.response.js +90 -0
  190. package/dist/features/auth/presentation/strategies/jwt.strategy.d.ts +18 -0
  191. package/dist/features/auth/presentation/strategies/jwt.strategy.js +59 -0
  192. package/dist/features/auth/token.module.d.ts +2 -0
  193. package/dist/features/auth/token.module.js +23 -0
  194. package/dist/features/maintenance/domain/cleanup.service.d.ts +22 -0
  195. package/dist/features/maintenance/domain/cleanup.service.js +142 -0
  196. package/dist/features/maintenance/maintenance.module.d.ts +2 -0
  197. package/dist/features/maintenance/maintenance.module.js +24 -0
  198. package/dist/features/notifications/domain/enums/channelType.enum.d.ts +7 -0
  199. package/dist/features/notifications/domain/enums/channelType.enum.js +11 -0
  200. package/dist/features/notifications/domain/enums/deliveryStatus.enum.d.ts +8 -0
  201. package/dist/features/notifications/domain/enums/deliveryStatus.enum.js +12 -0
  202. package/dist/features/notifications/domain/enums/notificationType.enum.d.ts +6 -0
  203. package/dist/features/notifications/domain/enums/notificationType.enum.js +10 -0
  204. package/dist/features/notifications/domain/enums/scopeType.enum.d.ts +5 -0
  205. package/dist/features/notifications/domain/enums/scopeType.enum.js +9 -0
  206. package/dist/features/notifications/domain/notifications.service.d.ts +45 -0
  207. package/dist/features/notifications/domain/notifications.service.js +101 -0
  208. package/dist/features/notifications/infra/repositories/notification.repository.d.ts +14 -0
  209. package/dist/features/notifications/infra/repositories/notification.repository.js +74 -0
  210. package/dist/features/notifications/infra/repositories/notificationRead.repository.d.ts +6 -0
  211. package/dist/features/notifications/infra/repositories/notificationRead.repository.js +40 -0
  212. package/dist/features/notifications/infra/repositories/notificationScope.repository.d.ts +5 -0
  213. package/dist/features/notifications/infra/repositories/notificationScope.repository.js +25 -0
  214. package/dist/features/notifications/infra/schema/notification.schema.d.ts +13 -0
  215. package/dist/features/notifications/infra/schema/notification.schema.js +52 -0
  216. package/dist/features/notifications/infra/schema/notificationRead.schema.d.ts +7 -0
  217. package/dist/features/notifications/infra/schema/notificationRead.schema.js +38 -0
  218. package/dist/features/notifications/infra/schema/notificationScope.schema.d.ts +9 -0
  219. package/dist/features/notifications/infra/schema/notificationScope.schema.js +43 -0
  220. package/dist/features/notifications/notifications.module.d.ts +2 -0
  221. package/dist/features/notifications/notifications.module.js +45 -0
  222. package/dist/features/notifications/presentation/commands/createNotification.command.d.ts +13 -0
  223. package/dist/features/notifications/presentation/commands/createNotification.command.js +72 -0
  224. package/dist/features/notifications/presentation/domainEvents.listener.d.ts +13 -0
  225. package/dist/features/notifications/presentation/domainEvents.listener.js +121 -0
  226. package/dist/features/notifications/presentation/notifications.controller.d.ts +16 -0
  227. package/dist/features/notifications/presentation/notifications.controller.js +108 -0
  228. package/dist/features/notifications/presentation/notifications.gateway.d.ts +13 -0
  229. package/dist/features/notifications/presentation/notifications.gateway.js +58 -0
  230. package/dist/features/notifications/presentation/notifications.publisher.d.ts +9 -0
  231. package/dist/features/notifications/presentation/notifications.publisher.js +42 -0
  232. package/dist/features/notifications/presentation/responses/notification.response.d.ts +18 -0
  233. package/dist/features/notifications/presentation/responses/notification.response.js +72 -0
  234. package/dist/features/rbac/domain/index.d.ts +2 -0
  235. package/dist/features/rbac/domain/index.js +18 -0
  236. package/dist/features/rbac/domain/rbac.catalog.d.ts +21 -0
  237. package/dist/features/rbac/domain/rbac.catalog.js +153 -0
  238. package/dist/features/rbac/domain/rbac.service.d.ts +68 -0
  239. package/dist/features/rbac/domain/rbac.service.js +436 -0
  240. package/dist/features/rbac/infra/index.d.ts +12 -0
  241. package/dist/features/rbac/infra/index.js +28 -0
  242. package/dist/features/rbac/infra/repositories/action.repository.d.ts +5 -0
  243. package/dist/features/rbac/infra/repositories/action.repository.js +25 -0
  244. package/dist/features/rbac/infra/repositories/group.repository.d.ts +5 -0
  245. package/dist/features/rbac/infra/repositories/group.repository.js +25 -0
  246. package/dist/features/rbac/infra/repositories/permission.repository.d.ts +5 -0
  247. package/dist/features/rbac/infra/repositories/permission.repository.js +25 -0
  248. package/dist/features/rbac/infra/repositories/resource.repository.d.ts +5 -0
  249. package/dist/features/rbac/infra/repositories/resource.repository.js +25 -0
  250. package/dist/features/rbac/infra/repositories/role.repository.d.ts +5 -0
  251. package/dist/features/rbac/infra/repositories/role.repository.js +25 -0
  252. package/dist/features/rbac/infra/repositories/scope.repository.d.ts +5 -0
  253. package/dist/features/rbac/infra/repositories/scope.repository.js +25 -0
  254. package/dist/features/rbac/infra/schema/action.schema.d.ts +6 -0
  255. package/dist/features/rbac/infra/schema/action.schema.js +36 -0
  256. package/dist/features/rbac/infra/schema/group.schema.d.ts +12 -0
  257. package/dist/features/rbac/infra/schema/group.schema.js +60 -0
  258. package/dist/features/rbac/infra/schema/permission.schema.d.ts +15 -0
  259. package/dist/features/rbac/infra/schema/permission.schema.js +66 -0
  260. package/dist/features/rbac/infra/schema/resource.schema.d.ts +6 -0
  261. package/dist/features/rbac/infra/schema/resource.schema.js +36 -0
  262. package/dist/features/rbac/infra/schema/role.schema.d.ts +8 -0
  263. package/dist/features/rbac/infra/schema/role.schema.js +46 -0
  264. package/dist/features/rbac/infra/schema/scope.schema.d.ts +6 -0
  265. package/dist/features/rbac/infra/schema/scope.schema.js +36 -0
  266. package/dist/features/rbac/presentation/commands/createAction.command.d.ts +4 -0
  267. package/dist/features/rbac/presentation/commands/createAction.command.js +32 -0
  268. package/dist/features/rbac/presentation/commands/createGroup.command.d.ts +7 -0
  269. package/dist/features/rbac/presentation/commands/createGroup.command.js +54 -0
  270. package/dist/features/rbac/presentation/commands/createPermission.command.d.ts +4 -0
  271. package/dist/features/rbac/presentation/commands/createPermission.command.js +35 -0
  272. package/dist/features/rbac/presentation/commands/createResource.command.d.ts +4 -0
  273. package/dist/features/rbac/presentation/commands/createResource.command.js +32 -0
  274. package/dist/features/rbac/presentation/commands/createRole.command.d.ts +5 -0
  275. package/dist/features/rbac/presentation/commands/createRole.command.js +38 -0
  276. package/dist/features/rbac/presentation/commands/createScope.command.d.ts +4 -0
  277. package/dist/features/rbac/presentation/commands/createScope.command.js +32 -0
  278. package/dist/features/rbac/presentation/commands/updateAction.command.d.ts +6 -0
  279. package/dist/features/rbac/presentation/commands/updateAction.command.js +24 -0
  280. package/dist/features/rbac/presentation/commands/updateGroup.command.d.ts +6 -0
  281. package/dist/features/rbac/presentation/commands/updateGroup.command.js +24 -0
  282. package/dist/features/rbac/presentation/commands/updatePermission.command.d.ts +6 -0
  283. package/dist/features/rbac/presentation/commands/updatePermission.command.js +24 -0
  284. package/dist/features/rbac/presentation/commands/updateResource.command.d.ts +6 -0
  285. package/dist/features/rbac/presentation/commands/updateResource.command.js +24 -0
  286. package/dist/features/rbac/presentation/commands/updateRole.command.d.ts +6 -0
  287. package/dist/features/rbac/presentation/commands/updateRole.command.js +24 -0
  288. package/dist/features/rbac/presentation/commands/updateScope.command.d.ts +6 -0
  289. package/dist/features/rbac/presentation/commands/updateScope.command.js +24 -0
  290. package/dist/features/rbac/presentation/index.d.ts +13 -0
  291. package/dist/features/rbac/presentation/index.js +29 -0
  292. package/dist/features/rbac/presentation/rbac.controller.d.ts +54 -0
  293. package/dist/features/rbac/presentation/rbac.controller.js +413 -0
  294. package/dist/features/rbac/presentation/responses/rbac.response.d.ts +47 -0
  295. package/dist/features/rbac/presentation/responses/rbac.response.js +161 -0
  296. package/dist/features/rbac/rbac.module.d.ts +2 -0
  297. package/dist/features/rbac/rbac.module.js +55 -0
  298. package/dist/features/users/domain/avatar.service.d.ts +4 -0
  299. package/dist/features/users/domain/avatar.service.js +61 -0
  300. package/dist/features/users/domain/index.d.ts +2 -0
  301. package/dist/features/users/domain/index.js +18 -0
  302. package/dist/features/users/domain/users.service.d.ts +46 -0
  303. package/dist/features/users/domain/users.service.js +291 -0
  304. package/dist/features/users/infra/index.d.ts +4 -0
  305. package/dist/features/users/infra/index.js +20 -0
  306. package/dist/features/users/infra/repositories/passwordHistory.repository.d.ts +5 -0
  307. package/dist/features/users/infra/repositories/passwordHistory.repository.js +25 -0
  308. package/dist/features/users/infra/repositories/user.repository.d.ts +8 -0
  309. package/dist/features/users/infra/repositories/user.repository.js +56 -0
  310. package/dist/features/users/infra/schema/passwordHistory.schema.d.ts +5 -0
  311. package/dist/features/users/infra/schema/passwordHistory.schema.js +29 -0
  312. package/dist/features/users/infra/schema/user.schema.d.ts +28 -0
  313. package/dist/features/users/infra/schema/user.schema.js +153 -0
  314. package/dist/features/users/presentation/commands/changePassword.command.d.ts +4 -0
  315. package/dist/features/users/presentation/commands/changePassword.command.js +29 -0
  316. package/dist/features/users/presentation/commands/createUser.command.d.ts +8 -0
  317. package/dist/features/users/presentation/commands/createUser.command.js +56 -0
  318. package/dist/features/users/presentation/commands/updateProfile.command.d.ts +5 -0
  319. package/dist/features/users/presentation/commands/updateProfile.command.js +38 -0
  320. package/dist/features/users/presentation/commands/updateUser.command.d.ts +5 -0
  321. package/dist/features/users/presentation/commands/updateUser.command.js +8 -0
  322. package/dist/features/users/presentation/filters/users.filters.d.ts +3 -0
  323. package/dist/features/users/presentation/filters/users.filters.js +62 -0
  324. package/dist/features/users/presentation/index.d.ts +5 -0
  325. package/dist/features/users/presentation/index.js +21 -0
  326. package/dist/features/users/presentation/responses/user.response.d.ts +25 -0
  327. package/dist/features/users/presentation/responses/user.response.js +95 -0
  328. package/dist/features/users/presentation/users.controller.d.ts +30 -0
  329. package/dist/features/users/presentation/users.controller.js +247 -0
  330. package/dist/features/users/users.module.d.ts +2 -0
  331. package/dist/features/users/users.module.js +42 -0
  332. package/dist/index.d.ts +61 -0
  333. package/dist/index.js +149 -0
  334. package/dist/main.d.ts +1 -0
  335. package/dist/main.js +5 -0
  336. package/dist/rlCore.module.d.ts +10 -0
  337. package/dist/rlCore.module.js +42 -0
  338. package/package.json +139 -0
@@ -0,0 +1,4 @@
1
+ export declare class AvatarService {
2
+ processAndStore(userId: string, file?: Express.Multer.File): Promise<string>;
3
+ remove(userId: string): Promise<void>;
4
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AvatarService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const fs_1 = require("fs");
15
+ const path_1 = require("path");
16
+ const sharp_1 = __importDefault(require("sharp"));
17
+ const UPLOAD_DIR = (0, path_1.join)(process.cwd(), "uploads", "avatars");
18
+ const ALLOWED = ["image/jpeg", "image/png", "image/webp"];
19
+ const MAX_BYTES = 5 * 1024 * 1024;
20
+ const MAGIC_BYTES_CHECK = {
21
+ "image/jpeg": (buf) => buf.length >= 3 && buf[0] === 0xff && buf[1] === 0xd8 && buf[2] === 0xff,
22
+ "image/png": (buf) => buf.length >= 8 &&
23
+ buf
24
+ .subarray(0, 8)
25
+ .equals(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])),
26
+ "image/webp": (buf) => buf.length >= 12 &&
27
+ buf.subarray(0, 4).toString("ascii") === "RIFF" &&
28
+ buf.subarray(8, 12).toString("ascii") === "WEBP",
29
+ };
30
+ let AvatarService = class AvatarService {
31
+ async processAndStore(userId, file) {
32
+ if (!file) {
33
+ throw new common_1.BadRequestException("Arquivo de imagem é obrigatório");
34
+ }
35
+ if (!ALLOWED.includes(file.mimetype)) {
36
+ throw new common_1.BadRequestException("Formato inválido (use JPEG, PNG ou WebP)");
37
+ }
38
+ if (!MAGIC_BYTES_CHECK[file.mimetype]?.(file.buffer)) {
39
+ throw new common_1.BadRequestException("O conteúdo do arquivo não corresponde ao formato declarado");
40
+ }
41
+ if (file.size > MAX_BYTES) {
42
+ throw new common_1.BadRequestException("Imagem excede o limite de 5MB");
43
+ }
44
+ await fs_1.promises.mkdir(UPLOAD_DIR, { recursive: true });
45
+ const filename = `${userId}.webp`;
46
+ const fullPath = (0, path_1.join)(UPLOAD_DIR, filename);
47
+ await (0, sharp_1.default)(file.buffer)
48
+ .resize(256, 256, { fit: "cover" })
49
+ .webp({ quality: 85 })
50
+ .toFile(fullPath);
51
+ return `/uploads/avatars/${filename}?v=${Date.now()}`;
52
+ }
53
+ async remove(userId) {
54
+ const fullPath = (0, path_1.join)(UPLOAD_DIR, `${userId}.webp`);
55
+ await fs_1.promises.rm(fullPath, { force: true });
56
+ }
57
+ };
58
+ exports.AvatarService = AvatarService;
59
+ exports.AvatarService = AvatarService = __decorate([
60
+ (0, common_1.Injectable)()
61
+ ], AvatarService);
@@ -0,0 +1,2 @@
1
+ export * from "./avatar.service";
2
+ export * from "./users.service";
@@ -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("./avatar.service"), exports);
18
+ __exportStar(require("./users.service"), exports);
@@ -0,0 +1,46 @@
1
+ import { EventEmitter2 } from "@nestjs/event-emitter";
2
+ import { EnvService } from "../../../core/config/env.service";
3
+ import { MailerService } from "../../../core/mailer/mailer.service";
4
+ import { Paginated, PaginationQuery } from "../../../core/utils/pagination.util";
5
+ import { TokenService } from "../../auth/domain/token.service";
6
+ import { RoleRepository } from "../../rbac/infra/repositories/role.repository";
7
+ import { PasswordHistoryRepository } from "../infra/repositories/passwordHistory.repository";
8
+ import { UserRepository } from "../infra/repositories/user.repository";
9
+ import { User } from "../infra/schema/user.schema";
10
+ import { CreateUserCommand } from "../presentation/commands/createUser.command";
11
+ import { UpdateProfileCommand } from "../presentation/commands/updateProfile.command";
12
+ import { UpdateUserCommand } from "../presentation/commands/updateUser.command";
13
+ export declare class UsersService {
14
+ private readonly userRepo;
15
+ private readonly historyRepo;
16
+ private readonly roleRepo;
17
+ private readonly env;
18
+ private readonly mailer;
19
+ private readonly tokens;
20
+ private readonly events;
21
+ constructor(userRepo: UserRepository, historyRepo: PasswordHistoryRepository, roleRepo: RoleRepository, env: EnvService, mailer: MailerService, tokens: TokenService, events: EventEmitter2);
22
+ findByEmail(email: string): Promise<User | null>;
23
+ findById(id: string): Promise<User>;
24
+ list(query: PaginationQuery, actorPermissions?: string[]): Promise<Paginated<User>>;
25
+ create(dto: CreateUserCommand, actorPermissions?: string[]): Promise<User>;
26
+ sendFirstAccessLink(id: string): Promise<void>;
27
+ sendPasswordResetLink(id: string): Promise<void>;
28
+ private invalidateCurrentPassword;
29
+ private issueAndSendFirstAccess;
30
+ private findActiveForLink;
31
+ private requirePasswordChange;
32
+ update(id: string, dto: UpdateUserCommand, actorPermissions?: string[]): Promise<User>;
33
+ remove(id: string): Promise<void>;
34
+ setActive(id: string, isActive: boolean): Promise<User>;
35
+ updateProfile(userId: string, dto: UpdateProfileCommand): Promise<User>;
36
+ setAvatar(userId: string, avatarPath: string): Promise<User>;
37
+ removeAvatar(userId: string): Promise<User>;
38
+ adminResetTwoFactor(id: string): Promise<void>;
39
+ changePassword(userId: string, currentPassword: string, newPassword: string): Promise<void>;
40
+ assertPasswordNotReused(userId: string, newPassword: string): Promise<void>;
41
+ savePasswordToHistory(userId: string, passwordHash: string): Promise<void>;
42
+ resetPassword(userId: string, newPassword: string): Promise<void>;
43
+ registerFailedLogin(user: User): Promise<number>;
44
+ clearLock(user: User): Promise<void>;
45
+ save(user: User): Promise<User>;
46
+ }
@@ -0,0 +1,291 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.UsersService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const event_emitter_1 = require("@nestjs/event-emitter");
15
+ const typeorm_1 = require("typeorm");
16
+ const env_service_1 = require("../../../core/config/env.service");
17
+ const appEvent_enum_1 = require("../../../core/events/appEvent.enum");
18
+ const appErrorCode_enum_1 = require("../../../core/filters/appErrorCode.enum");
19
+ const mailer_service_1 = require("../../../core/mailer/mailer.service");
20
+ const codedError_util_1 = require("../../../core/utils/codedError.util");
21
+ const hash_util_1 = require("../../../core/utils/hash.util");
22
+ const pagination_util_1 = require("../../../core/utils/pagination.util");
23
+ const token_service_1 = require("../../auth/domain/token.service");
24
+ const role_repository_1 = require("../../rbac/infra/repositories/role.repository");
25
+ const passwordHistory_repository_1 = require("../infra/repositories/passwordHistory.repository");
26
+ const user_repository_1 = require("../infra/repositories/user.repository");
27
+ const PASSWORD_HISTORY_LIMIT = 3;
28
+ const PASSWORD_REUSED_MESSAGE = "Esta senha já foi utilizada. Escolha uma senha que você ainda não usou neste sistema";
29
+ let UsersService = class UsersService {
30
+ constructor(userRepo, historyRepo, roleRepo, env, mailer, tokens, events) {
31
+ this.userRepo = userRepo;
32
+ this.historyRepo = historyRepo;
33
+ this.roleRepo = roleRepo;
34
+ this.env = env;
35
+ this.mailer = mailer;
36
+ this.tokens = tokens;
37
+ this.events = events;
38
+ }
39
+ findByEmail(email) {
40
+ return this.userRepo.findOne({ where: { email } });
41
+ }
42
+ async findById(id) {
43
+ const user = await this.userRepo.findOne({
44
+ where: { id },
45
+ relations: { roles: true },
46
+ });
47
+ if (!user) {
48
+ throw new common_1.NotFoundException("Usuário não encontrado");
49
+ }
50
+ return user;
51
+ }
52
+ async list(query, actorPermissions) {
53
+ const [items, total] = await this.userRepo.findPaginated(query, actorPermissions);
54
+ return new pagination_util_1.Paginated(items, total, query.page, query.limit);
55
+ }
56
+ async create(dto, actorPermissions) {
57
+ const exists = await this.userRepo.findOne({
58
+ where: { email: dto.email },
59
+ withDeleted: true,
60
+ });
61
+ if (exists) {
62
+ throw new common_1.ConflictException("Email já cadastrado");
63
+ }
64
+ if (dto.roleIds?.length && !actorPermissions?.includes("users:promote:any")) {
65
+ throw new common_1.ForbiddenException("Definir papéis na criação de um usuário é restrito a administradores");
66
+ }
67
+ const roles = dto.roleIds?.length
68
+ ? await this.roleRepo.findBy({ id: (0, typeorm_1.In)(dto.roleIds) })
69
+ : [];
70
+ const hashed = await (0, hash_util_1.hashPassword)((0, hash_util_1.randomToken)(48));
71
+ const user = this.userRepo.create({
72
+ name: dto.name,
73
+ lastName: dto.lastName,
74
+ phone: dto.phone,
75
+ email: dto.email,
76
+ password: hashed,
77
+ passwordChangedAt: new Date(),
78
+ mustChangePassword: true,
79
+ isActive: dto.isActive ?? true,
80
+ roles,
81
+ });
82
+ const saved = await this.userRepo.save(user);
83
+ await this.savePasswordToHistory(saved.id, hashed);
84
+ void this.issueAndSendFirstAccess(saved).catch(() => undefined);
85
+ return this.findById(saved.id);
86
+ }
87
+ async sendFirstAccessLink(id) {
88
+ const user = await this.findActiveForLink(id);
89
+ await this.issueAndSendFirstAccess(user);
90
+ await this.requirePasswordChange(user);
91
+ }
92
+ async sendPasswordResetLink(id) {
93
+ const user = await this.findActiveForLink(id);
94
+ const token = await this.tokens.issuePasswordReset(user.id);
95
+ await this.mailer.sendPasswordReset(user.email, token, user.name);
96
+ await this.invalidateCurrentPassword(user);
97
+ await this.requirePasswordChange(user);
98
+ await this.tokens.revokeAllRefresh(user.id);
99
+ this.events.emit(appEvent_enum_1.AppEvent.USER_PASSWORD_RESET_REQUESTED, {
100
+ userId: user.id,
101
+ });
102
+ }
103
+ async invalidateCurrentPassword(user) {
104
+ if (user.mustChangePassword) {
105
+ return;
106
+ }
107
+ await this.savePasswordToHistory(user.id, user.password);
108
+ user.password = await (0, hash_util_1.hashPassword)((0, hash_util_1.randomToken)(48));
109
+ }
110
+ async issueAndSendFirstAccess(user) {
111
+ const token = await this.tokens.issueFirstAccess(user.id);
112
+ await this.mailer.sendFirstAccess(user.email, token, user.name);
113
+ }
114
+ async findActiveForLink(id) {
115
+ const user = await this.findById(id);
116
+ if (!user.isActive) {
117
+ throw new common_1.BadRequestException("Usuário inativo — reative antes de enviar o link");
118
+ }
119
+ return user;
120
+ }
121
+ async requirePasswordChange(user) {
122
+ user.mustChangePassword = true;
123
+ user.failedLoginAttempts = 0;
124
+ await this.userRepo.save(user);
125
+ }
126
+ async update(id, dto, actorPermissions) {
127
+ const user = await this.findById(id);
128
+ if (dto.email && dto.email !== user.email) {
129
+ if (!actorPermissions?.includes("users:update-email:any")) {
130
+ throw new common_1.ForbiddenException("Alterar o email de um usuário é restrito a administradores");
131
+ }
132
+ const taken = await this.userRepo.findOne({
133
+ where: { email: dto.email },
134
+ withDeleted: true,
135
+ });
136
+ if (taken) {
137
+ throw new common_1.ConflictException("Email já cadastrado");
138
+ }
139
+ }
140
+ if (dto.isActive !== undefined &&
141
+ dto.isActive !== user.isActive &&
142
+ !actorPermissions?.includes("users:deactivate:any")) {
143
+ throw new common_1.ForbiddenException("Ativar/desativar um usuário é restrito a administradores");
144
+ }
145
+ if (dto.roleIds && !actorPermissions?.includes("users:promote:any")) {
146
+ throw new common_1.ForbiddenException("Alterar papéis de um usuário é restrito a administradores");
147
+ }
148
+ Object.assign(user, {
149
+ name: dto.name ?? user.name,
150
+ lastName: dto.lastName ?? user.lastName,
151
+ phone: dto.phone ?? user.phone,
152
+ email: dto.email ?? user.email,
153
+ isActive: dto.isActive ?? user.isActive,
154
+ });
155
+ if (dto.roleIds) {
156
+ user.roles = await this.roleRepo.findBy({ id: (0, typeorm_1.In)(dto.roleIds) });
157
+ }
158
+ await this.userRepo.save(user);
159
+ return this.findById(id);
160
+ }
161
+ async remove(id) {
162
+ const user = await this.findById(id);
163
+ await this.userRepo.softRemove(user);
164
+ }
165
+ async setActive(id, isActive) {
166
+ const user = await this.findById(id);
167
+ user.isActive = isActive;
168
+ await this.userRepo.save(user);
169
+ return user;
170
+ }
171
+ async updateProfile(userId, dto) {
172
+ const user = await this.findById(userId);
173
+ Object.assign(user, {
174
+ name: dto.name ?? user.name,
175
+ lastName: dto.lastName ?? user.lastName,
176
+ phone: dto.phone ?? user.phone,
177
+ });
178
+ await this.userRepo.save(user);
179
+ return this.findById(userId);
180
+ }
181
+ async setAvatar(userId, avatarPath) {
182
+ const user = await this.findById(userId);
183
+ user.avatar = avatarPath;
184
+ await this.userRepo.save(user);
185
+ return user;
186
+ }
187
+ async removeAvatar(userId) {
188
+ const user = await this.findById(userId);
189
+ user.avatar = null;
190
+ await this.userRepo.save(user);
191
+ return user;
192
+ }
193
+ async adminResetTwoFactor(id) {
194
+ const user = await this.findById(id);
195
+ user.twoFactorEnabled = false;
196
+ user.twoFactorSecret = null;
197
+ user.twoFactorConfirmedAt = null;
198
+ user.backupCodes = null;
199
+ await this.userRepo.save(user);
200
+ await this.tokens.revokeAllRefresh(id);
201
+ this.events.emit(appEvent_enum_1.AppEvent.USER_TWO_FACTOR_RESET, {
202
+ userId: id,
203
+ });
204
+ }
205
+ async changePassword(userId, currentPassword, newPassword) {
206
+ const user = await this.userRepo.findOne({ where: { id: userId } });
207
+ if (!user) {
208
+ throw new common_1.NotFoundException("Usuário não encontrado");
209
+ }
210
+ const ok = await (0, hash_util_1.verifyPassword)(user.password, currentPassword);
211
+ if (!ok) {
212
+ throw new common_1.BadRequestException("Senha atual incorreta");
213
+ }
214
+ await this.assertPasswordNotReused(userId, newPassword);
215
+ await this.savePasswordToHistory(userId, user.password);
216
+ user.password = await (0, hash_util_1.hashPassword)(newPassword);
217
+ user.passwordChangedAt = new Date();
218
+ user.mustChangePassword = false;
219
+ await this.userRepo.save(user);
220
+ await this.tokens.revokeAllRefresh(userId);
221
+ }
222
+ async assertPasswordNotReused(userId, newPassword) {
223
+ const history = await this.historyRepo.find({
224
+ where: { userId },
225
+ order: { createdAt: "DESC" },
226
+ take: PASSWORD_HISTORY_LIMIT,
227
+ });
228
+ for (const entry of history) {
229
+ if (await (0, hash_util_1.verifyPassword)(entry.passwordHash, newPassword)) {
230
+ throw (0, codedError_util_1.codedBadRequest)(PASSWORD_REUSED_MESSAGE, appErrorCode_enum_1.AppErrorCode.PASSWORD_REUSED);
231
+ }
232
+ }
233
+ }
234
+ async savePasswordToHistory(userId, passwordHash) {
235
+ await this.historyRepo.save(this.historyRepo.create({ userId, passwordHash }));
236
+ const all = await this.historyRepo.find({
237
+ where: { userId },
238
+ order: { createdAt: "DESC" },
239
+ });
240
+ const old = all.slice(PASSWORD_HISTORY_LIMIT);
241
+ if (old.length) {
242
+ await this.historyRepo.softRemove(old);
243
+ }
244
+ }
245
+ async resetPassword(userId, newPassword) {
246
+ const user = await this.userRepo.findOne({ where: { id: userId } });
247
+ if (!user) {
248
+ throw new common_1.NotFoundException("Usuário não encontrado");
249
+ }
250
+ await this.assertPasswordNotReused(userId, newPassword);
251
+ await this.savePasswordToHistory(userId, user.password);
252
+ user.password = await (0, hash_util_1.hashPassword)(newPassword);
253
+ user.passwordChangedAt = new Date();
254
+ user.mustChangePassword = false;
255
+ await this.userRepo.save(user);
256
+ }
257
+ async registerFailedLogin(user) {
258
+ const max = this.env.get("LOGIN_MAX_ATTEMPTS");
259
+ user.failedLoginAttempts = Math.min(user.failedLoginAttempts + 1, max);
260
+ await this.userRepo.save(user);
261
+ const remaining = user.remainingAttempts(max);
262
+ if (remaining === 0) {
263
+ this.events.emit(appEvent_enum_1.AppEvent.USER_LOCKED, {
264
+ userId: user.id,
265
+ userName: user.name,
266
+ userEmail: user.email,
267
+ });
268
+ }
269
+ return remaining;
270
+ }
271
+ async clearLock(user) {
272
+ if (user.failedLoginAttempts !== 0) {
273
+ user.failedLoginAttempts = 0;
274
+ await this.userRepo.save(user);
275
+ }
276
+ }
277
+ save(user) {
278
+ return this.userRepo.save(user);
279
+ }
280
+ };
281
+ exports.UsersService = UsersService;
282
+ exports.UsersService = UsersService = __decorate([
283
+ (0, common_1.Injectable)(),
284
+ __metadata("design:paramtypes", [user_repository_1.UserRepository,
285
+ passwordHistory_repository_1.PasswordHistoryRepository,
286
+ role_repository_1.RoleRepository,
287
+ env_service_1.EnvService,
288
+ mailer_service_1.MailerService,
289
+ token_service_1.TokenService,
290
+ event_emitter_1.EventEmitter2])
291
+ ], UsersService);
@@ -0,0 +1,4 @@
1
+ export * from "./repositories/passwordHistory.repository";
2
+ export * from "./repositories/user.repository";
3
+ export * from "./schema/passwordHistory.schema";
4
+ export * from "./schema/user.schema";
@@ -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("./repositories/passwordHistory.repository"), exports);
18
+ __exportStar(require("./repositories/user.repository"), exports);
19
+ __exportStar(require("./schema/passwordHistory.schema"), exports);
20
+ __exportStar(require("./schema/user.schema"), exports);
@@ -0,0 +1,5 @@
1
+ import { DataSource, Repository } from "typeorm";
2
+ import { PasswordHistory } from "../schema/passwordHistory.schema";
3
+ export declare class PasswordHistoryRepository extends Repository<PasswordHistory> {
4
+ constructor(dataSource: DataSource);
5
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PasswordHistoryRepository = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const typeorm_1 = require("typeorm");
15
+ const passwordHistory_schema_1 = require("../schema/passwordHistory.schema");
16
+ let PasswordHistoryRepository = class PasswordHistoryRepository extends typeorm_1.Repository {
17
+ constructor(dataSource) {
18
+ super(passwordHistory_schema_1.PasswordHistory, dataSource.createEntityManager());
19
+ }
20
+ };
21
+ exports.PasswordHistoryRepository = PasswordHistoryRepository;
22
+ exports.PasswordHistoryRepository = PasswordHistoryRepository = __decorate([
23
+ (0, common_1.Injectable)(),
24
+ __metadata("design:paramtypes", [typeorm_1.DataSource])
25
+ ], PasswordHistoryRepository);
@@ -0,0 +1,8 @@
1
+ import { DataSource, Repository } from "typeorm";
2
+ import { PaginationQuery } from "../../../../core/utils/pagination.util";
3
+ import { User } from "../schema/user.schema";
4
+ export declare class UserRepository extends Repository<User> {
5
+ constructor(dataSource: DataSource);
6
+ findPaginated(query: PaginationQuery, permissions?: string[]): Promise<[User[], number]>;
7
+ findWithPasswordExpiringIn(maxAgeDays: number, milestones: number[]): Promise<User[]>;
8
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.UserRepository = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const typeorm_1 = require("typeorm");
15
+ const paginateWithFilter_util_1 = require("../../../../core/query/paginateWithFilter.util");
16
+ const user_schema_1 = require("../schema/user.schema");
17
+ const users_filters_1 = require("../../presentation/filters/users.filters");
18
+ const dayOffset = (days) => {
19
+ const date = new Date();
20
+ date.setHours(0, 0, 0, 0);
21
+ date.setDate(date.getDate() + days);
22
+ return date;
23
+ };
24
+ let UserRepository = class UserRepository extends typeorm_1.Repository {
25
+ constructor(dataSource) {
26
+ super(user_schema_1.User, dataSource.createEntityManager());
27
+ }
28
+ findPaginated(query, permissions) {
29
+ const qb = this.createQueryBuilder("user").leftJoinAndSelect("user.roles", "userRoles");
30
+ return (0, paginateWithFilter_util_1.paginateWithFilter)(qb, {
31
+ query,
32
+ catalog: users_filters_1.USERS_FILTER_CATALOG,
33
+ defaultSort: "createdAt",
34
+ permissions,
35
+ searchFields: users_filters_1.USERS_SEARCH_FIELDS,
36
+ });
37
+ }
38
+ async findWithPasswordExpiringIn(maxAgeDays, milestones) {
39
+ if (milestones.length === 0) {
40
+ return [];
41
+ }
42
+ const from = dayOffset(-(maxAgeDays - Math.min(...milestones)));
43
+ const to = dayOffset(-(maxAgeDays - Math.max(...milestones)) + 1);
44
+ return await this.find({
45
+ where: {
46
+ isActive: true,
47
+ passwordChangedAt: (0, typeorm_1.Between)(from, to),
48
+ },
49
+ });
50
+ }
51
+ };
52
+ exports.UserRepository = UserRepository;
53
+ exports.UserRepository = UserRepository = __decorate([
54
+ (0, common_1.Injectable)(),
55
+ __metadata("design:paramtypes", [typeorm_1.DataSource])
56
+ ], UserRepository);
@@ -0,0 +1,5 @@
1
+ import { BaseEntity } from "../../../../core/database/base.schema";
2
+ export declare class PasswordHistory extends BaseEntity {
3
+ userId: string;
4
+ passwordHash: string;
5
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PasswordHistory = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ const base_schema_1 = require("../../../../core/database/base.schema");
15
+ let PasswordHistory = class PasswordHistory extends base_schema_1.BaseEntity {
16
+ };
17
+ exports.PasswordHistory = PasswordHistory;
18
+ __decorate([
19
+ (0, typeorm_1.Column)({ name: "user_id", type: "char", length: 36 }),
20
+ __metadata("design:type", String)
21
+ ], PasswordHistory.prototype, "userId", void 0);
22
+ __decorate([
23
+ (0, typeorm_1.Column)({ name: "password_hash", type: "varchar", length: 255 }),
24
+ __metadata("design:type", String)
25
+ ], PasswordHistory.prototype, "passwordHash", void 0);
26
+ exports.PasswordHistory = PasswordHistory = __decorate([
27
+ (0, typeorm_1.Entity)("password_history"),
28
+ (0, typeorm_1.Index)(["userId"])
29
+ ], PasswordHistory);
@@ -0,0 +1,28 @@
1
+ import { BaseEntity } from "../../../../core/database/base.schema";
2
+ import { Group } from "../../../rbac/infra/schema/group.schema";
3
+ import { Permission } from "../../../rbac/infra/schema/permission.schema";
4
+ import { Role } from "../../../rbac/infra/schema/role.schema";
5
+ export declare class User extends BaseEntity {
6
+ name: string;
7
+ lastName?: string | null;
8
+ phone?: string | null;
9
+ avatar?: string | null;
10
+ email: string;
11
+ password: string;
12
+ passwordChangedAt?: Date | null;
13
+ mustChangePassword: boolean;
14
+ isActive: boolean;
15
+ twoFactorEnabled: boolean;
16
+ twoFactorSecret?: string | null;
17
+ twoFactorConfirmedAt?: Date | null;
18
+ backupCodes?: string[] | null;
19
+ failedLoginAttempts: number;
20
+ roles: Role[];
21
+ directPermissions: Permission[];
22
+ groups: Group[];
23
+ get fullName(): string;
24
+ isLocked(maxAttempts: number): boolean;
25
+ get locked(): boolean;
26
+ remainingAttempts(maxAttempts: number): number;
27
+ isPasswordExpired(maxAgeDays: number): boolean;
28
+ }