@hed-hog/core 0.0.386 → 0.0.390

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 (556) hide show
  1. package/README.md +12 -11
  2. package/dist/access-log/access-log.interceptor.d.ts.map +1 -1
  3. package/dist/access-log/access-log.interceptor.js +4 -2
  4. package/dist/access-log/access-log.interceptor.js.map +1 -1
  5. package/dist/ai/ai-attachment.fragments.d.ts +23 -0
  6. package/dist/ai/ai-attachment.fragments.d.ts.map +1 -0
  7. package/dist/ai/ai-attachment.fragments.js +34 -0
  8. package/dist/ai/ai-attachment.fragments.js.map +1 -0
  9. package/dist/ai/ai.controller.d.ts +7 -16
  10. package/dist/ai/ai.controller.d.ts.map +1 -1
  11. package/dist/ai/ai.prompts.d.ts +16 -0
  12. package/dist/ai/ai.prompts.d.ts.map +1 -0
  13. package/dist/ai/ai.prompts.js +37 -0
  14. package/dist/ai/ai.prompts.js.map +1 -0
  15. package/dist/ai/ai.service.d.ts +63 -12
  16. package/dist/ai/ai.service.d.ts.map +1 -1
  17. package/dist/ai/ai.service.js +215 -88
  18. package/dist/ai/ai.service.js.map +1 -1
  19. package/dist/ai/dto/chat.dto.d.ts +4 -1
  20. package/dist/ai/dto/chat.dto.d.ts.map +1 -1
  21. package/dist/ai/dto/chat.dto.js +23 -1
  22. package/dist/ai/dto/chat.dto.js.map +1 -1
  23. package/dist/ai/dto/create-agent.dto.d.ts +1 -1
  24. package/dist/ai/dto/create-agent.dto.d.ts.map +1 -1
  25. package/dist/ai/dto/create-agent.dto.js +1 -1
  26. package/dist/ai/dto/create-agent.dto.js.map +1 -1
  27. package/dist/ai/dto/update-agent.dto.d.ts +1 -1
  28. package/dist/ai/dto/update-agent.dto.d.ts.map +1 -1
  29. package/dist/ai/dto/update-agent.dto.js +1 -1
  30. package/dist/ai/dto/update-agent.dto.js.map +1 -1
  31. package/dist/ai-instruction/ai-instruction.controller.d.ts +61 -7
  32. package/dist/ai-instruction/ai-instruction.controller.d.ts.map +1 -1
  33. package/dist/ai-instruction/ai-instruction.controller.js +63 -20
  34. package/dist/ai-instruction/ai-instruction.controller.js.map +1 -1
  35. package/dist/ai-instruction/ai-instruction.module.d.ts.map +1 -1
  36. package/dist/ai-instruction/ai-instruction.module.js +13 -2
  37. package/dist/ai-instruction/ai-instruction.module.js.map +1 -1
  38. package/dist/ai-instruction/ai-instruction.service.d.ts +131 -6
  39. package/dist/ai-instruction/ai-instruction.service.d.ts.map +1 -1
  40. package/dist/ai-instruction/ai-instruction.service.js +533 -60
  41. package/dist/ai-instruction/ai-instruction.service.js.map +1 -1
  42. package/dist/ai-instruction/ai-prompt-builder.service.d.ts +8 -0
  43. package/dist/ai-instruction/ai-prompt-builder.service.d.ts.map +1 -1
  44. package/dist/ai-instruction/ai-prompt-builder.service.js +10 -1
  45. package/dist/ai-instruction/ai-prompt-builder.service.js.map +1 -1
  46. package/dist/ai-instruction/ai-prompt-registry.d.ts +45 -0
  47. package/dist/ai-instruction/ai-prompt-registry.d.ts.map +1 -0
  48. package/dist/ai-instruction/ai-prompt-registry.js +49 -0
  49. package/dist/ai-instruction/ai-prompt-registry.js.map +1 -0
  50. package/dist/ai-instruction/ai-prompt-resolver.service.d.ts +89 -0
  51. package/dist/ai-instruction/ai-prompt-resolver.service.d.ts.map +1 -0
  52. package/dist/ai-instruction/ai-prompt-resolver.service.js +222 -0
  53. package/dist/ai-instruction/ai-prompt-resolver.service.js.map +1 -0
  54. package/dist/ai-instruction/ai-prompt-template.util.d.ts +70 -0
  55. package/dist/ai-instruction/ai-prompt-template.util.d.ts.map +1 -0
  56. package/dist/ai-instruction/ai-prompt-template.util.js +154 -0
  57. package/dist/ai-instruction/ai-prompt-template.util.js.map +1 -0
  58. package/dist/ai-instruction/dto/create-ai-instruction.dto.d.ts +5 -0
  59. package/dist/ai-instruction/dto/create-ai-instruction.dto.d.ts.map +1 -1
  60. package/dist/ai-instruction/dto/create-ai-instruction.dto.js +27 -1
  61. package/dist/ai-instruction/dto/create-ai-instruction.dto.js.map +1 -1
  62. package/dist/ai-instruction/dto/preview-ai-instruction.dto.d.ts +14 -0
  63. package/dist/ai-instruction/dto/preview-ai-instruction.dto.d.ts.map +1 -0
  64. package/dist/ai-instruction/dto/preview-ai-instruction.dto.js +42 -0
  65. package/dist/ai-instruction/dto/preview-ai-instruction.dto.js.map +1 -0
  66. package/dist/ai-instruction/dto/update-ai-instruction.dto.d.ts +11 -0
  67. package/dist/ai-instruction/dto/update-ai-instruction.dto.d.ts.map +1 -1
  68. package/dist/ai-instruction/dto/update-ai-instruction.dto.js +34 -0
  69. package/dist/ai-instruction/dto/update-ai-instruction.dto.js.map +1 -1
  70. package/dist/ai-instruction/types/ai-instruction.types.d.ts +13 -1
  71. package/dist/ai-instruction/types/ai-instruction.types.d.ts.map +1 -1
  72. package/dist/ai-instruction/types/ai-instruction.types.js +10 -0
  73. package/dist/ai-instruction/types/ai-instruction.types.js.map +1 -1
  74. package/dist/auth/auth.controller.d.ts +26 -10
  75. package/dist/auth/auth.controller.d.ts.map +1 -1
  76. package/dist/auth/auth.controller.js +49 -21
  77. package/dist/auth/auth.controller.js.map +1 -1
  78. package/dist/auth/auth.service.d.ts +35 -9
  79. package/dist/auth/auth.service.d.ts.map +1 -1
  80. package/dist/auth/auth.service.js +78 -29
  81. package/dist/auth/auth.service.js.map +1 -1
  82. package/dist/captcha/captcha.module.d.ts +3 -0
  83. package/dist/captcha/captcha.module.d.ts.map +1 -0
  84. package/dist/captcha/captcha.module.js +23 -0
  85. package/dist/captcha/captcha.module.js.map +1 -0
  86. package/dist/captcha/captcha.service.d.ts +38 -0
  87. package/dist/captcha/captcha.service.d.ts.map +1 -0
  88. package/dist/captcha/captcha.service.js +144 -0
  89. package/dist/captcha/captcha.service.js.map +1 -0
  90. package/dist/challenge/challenge.service.d.ts +16 -7
  91. package/dist/challenge/challenge.service.d.ts.map +1 -1
  92. package/dist/challenge/challenge.service.js +64 -16
  93. package/dist/challenge/challenge.service.js.map +1 -1
  94. package/dist/core.module.d.ts +3 -1
  95. package/dist/core.module.d.ts.map +1 -1
  96. package/dist/core.module.js +29 -2
  97. package/dist/core.module.js.map +1 -1
  98. package/dist/dashboard/dashboard/dashboard.controller.d.ts +15 -15
  99. package/dist/dashboard/dashboard/dashboard.service.d.ts +15 -15
  100. package/dist/dashboard/dashboard-component/dashboard-component.controller.d.ts +6 -6
  101. package/dist/dashboard/dashboard-component/dashboard-component.service.d.ts +6 -6
  102. package/dist/dashboard/dashboard-component-role/dashboard-component-role.controller.d.ts +20 -20
  103. package/dist/dashboard/dashboard-component-role/dashboard-component-role.service.d.ts +20 -20
  104. package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts +1 -1
  105. package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts +1 -1
  106. package/dist/dashboard/dashboard-role/dashboard-role.controller.d.ts +13 -13
  107. package/dist/dashboard/dashboard-role/dashboard-role.service.d.ts +13 -13
  108. package/dist/file/file.service.d.ts +6 -0
  109. package/dist/file/file.service.d.ts.map +1 -1
  110. package/dist/file/file.service.js +44 -4
  111. package/dist/file/file.service.js.map +1 -1
  112. package/dist/incident/incident-notifier.service.d.ts +36 -0
  113. package/dist/incident/incident-notifier.service.d.ts.map +1 -0
  114. package/dist/incident/incident-notifier.service.js +208 -0
  115. package/dist/incident/incident-notifier.service.js.map +1 -0
  116. package/dist/incident/incident.controller.d.ts +23 -0
  117. package/dist/incident/incident.controller.d.ts.map +1 -0
  118. package/dist/incident/incident.controller.js +75 -0
  119. package/dist/incident/incident.controller.js.map +1 -0
  120. package/dist/incident/incident.module.d.ts +7 -0
  121. package/dist/incident/incident.module.d.ts.map +1 -0
  122. package/dist/incident/incident.module.js +32 -0
  123. package/dist/incident/incident.module.js.map +1 -0
  124. package/dist/incident/incident.service.d.ts +72 -0
  125. package/dist/incident/incident.service.d.ts.map +1 -0
  126. package/dist/incident/incident.service.js +184 -0
  127. package/dist/incident/incident.service.js.map +1 -0
  128. package/dist/index.d.ts +27 -0
  129. package/dist/index.d.ts.map +1 -1
  130. package/dist/index.js +31 -0
  131. package/dist/index.js.map +1 -1
  132. package/dist/integration-profile/dto/test.dto.d.ts +13 -0
  133. package/dist/integration-profile/dto/test.dto.d.ts.map +1 -0
  134. package/dist/integration-profile/dto/test.dto.js +26 -0
  135. package/dist/integration-profile/dto/test.dto.js.map +1 -0
  136. package/dist/integration-profile/integration-profile.controller.d.ts +12 -1
  137. package/dist/integration-profile/integration-profile.controller.d.ts.map +1 -1
  138. package/dist/integration-profile/integration-profile.controller.js +9 -1
  139. package/dist/integration-profile/integration-profile.controller.js.map +1 -1
  140. package/dist/integration-profile/integration-profile.module.d.ts +6 -1
  141. package/dist/integration-profile/integration-profile.module.d.ts.map +1 -1
  142. package/dist/integration-profile/integration-profile.module.js +26 -3
  143. package/dist/integration-profile/integration-profile.module.js.map +1 -1
  144. package/dist/integration-profile/integration-profile.secrets.d.ts.map +1 -1
  145. package/dist/integration-profile/integration-profile.secrets.js +12 -2
  146. package/dist/integration-profile/integration-profile.secrets.js.map +1 -1
  147. package/dist/integration-profile/integration-profile.service.d.ts +28 -2
  148. package/dist/integration-profile/integration-profile.service.d.ts.map +1 -1
  149. package/dist/integration-profile/integration-profile.service.js +105 -31
  150. package/dist/integration-profile/integration-profile.service.js.map +1 -1
  151. package/dist/integration-profile/integration-profile.utils.d.ts +31 -1
  152. package/dist/integration-profile/integration-profile.utils.d.ts.map +1 -1
  153. package/dist/integration-profile/integration-profile.utils.js +35 -4
  154. package/dist/integration-profile/integration-profile.utils.js.map +1 -1
  155. package/dist/integration-profile/testers/ai.testers.d.ts +3 -0
  156. package/dist/integration-profile/testers/ai.testers.d.ts.map +1 -0
  157. package/dist/integration-profile/testers/ai.testers.js +125 -0
  158. package/dist/integration-profile/testers/ai.testers.js.map +1 -0
  159. package/dist/integration-profile/testers/captcha.testers.d.ts +3 -0
  160. package/dist/integration-profile/testers/captcha.testers.d.ts.map +1 -0
  161. package/dist/integration-profile/testers/captcha.testers.js +121 -0
  162. package/dist/integration-profile/testers/captcha.testers.js.map +1 -0
  163. package/dist/integration-profile/testers/email.testers.d.ts +3 -0
  164. package/dist/integration-profile/testers/email.testers.d.ts.map +1 -0
  165. package/dist/integration-profile/testers/email.testers.js +128 -0
  166. package/dist/integration-profile/testers/email.testers.js.map +1 -0
  167. package/dist/integration-profile/testers/http-probe.d.ts +57 -0
  168. package/dist/integration-profile/testers/http-probe.d.ts.map +1 -0
  169. package/dist/integration-profile/testers/http-probe.js +140 -0
  170. package/dist/integration-profile/testers/http-probe.js.map +1 -0
  171. package/dist/integration-profile/testers/index.d.ts +12 -0
  172. package/dist/integration-profile/testers/index.d.ts.map +1 -0
  173. package/dist/integration-profile/testers/index.js +45 -0
  174. package/dist/integration-profile/testers/index.js.map +1 -0
  175. package/dist/integration-profile/testers/infrastructure.testers.d.ts +3 -0
  176. package/dist/integration-profile/testers/infrastructure.testers.d.ts.map +1 -0
  177. package/dist/integration-profile/testers/infrastructure.testers.js +105 -0
  178. package/dist/integration-profile/testers/infrastructure.testers.js.map +1 -0
  179. package/dist/integration-profile/testers/integration-tester.registry.d.ts +17 -0
  180. package/dist/integration-profile/testers/integration-tester.registry.d.ts.map +1 -0
  181. package/dist/integration-profile/testers/integration-tester.registry.js +52 -0
  182. package/dist/integration-profile/testers/integration-tester.registry.js.map +1 -0
  183. package/dist/integration-profile/testers/integration-tester.types.d.ts +55 -0
  184. package/dist/integration-profile/testers/integration-tester.types.d.ts.map +1 -0
  185. package/dist/integration-profile/testers/integration-tester.types.js +16 -0
  186. package/dist/integration-profile/testers/integration-tester.types.js.map +1 -0
  187. package/dist/integration-profile/testers/messaging.testers.d.ts +3 -0
  188. package/dist/integration-profile/testers/messaging.testers.d.ts.map +1 -0
  189. package/dist/integration-profile/testers/messaging.testers.js +70 -0
  190. package/dist/integration-profile/testers/messaging.testers.js.map +1 -0
  191. package/dist/integration-profile/testers/oauth.testers.d.ts +3 -0
  192. package/dist/integration-profile/testers/oauth.testers.d.ts.map +1 -0
  193. package/dist/integration-profile/testers/oauth.testers.js +285 -0
  194. package/dist/integration-profile/testers/oauth.testers.js.map +1 -0
  195. package/dist/integration-profile/testers/payment.testers.d.ts +3 -0
  196. package/dist/integration-profile/testers/payment.testers.d.ts.map +1 -0
  197. package/dist/integration-profile/testers/payment.testers.js +169 -0
  198. package/dist/integration-profile/testers/payment.testers.js.map +1 -0
  199. package/dist/integration-profile/testers/storage.testers.d.ts +3 -0
  200. package/dist/integration-profile/testers/storage.testers.d.ts.map +1 -0
  201. package/dist/integration-profile/testers/storage.testers.js +208 -0
  202. package/dist/integration-profile/testers/storage.testers.js.map +1 -0
  203. package/dist/language/en.json +4 -2
  204. package/dist/language/pt.json +4 -2
  205. package/dist/leaked-password/leaked-password.controller.d.ts +24 -0
  206. package/dist/leaked-password/leaked-password.controller.d.ts.map +1 -0
  207. package/dist/leaked-password/leaked-password.controller.js +78 -0
  208. package/dist/leaked-password/leaked-password.controller.js.map +1 -0
  209. package/dist/leaked-password/leaked-password.module.d.ts +8 -0
  210. package/dist/leaked-password/leaked-password.module.d.ts.map +1 -0
  211. package/dist/leaked-password/leaked-password.module.js +31 -0
  212. package/dist/leaked-password/leaked-password.module.js.map +1 -0
  213. package/dist/leaked-password/leaked-password.service.d.ts +64 -0
  214. package/dist/leaked-password/leaked-password.service.d.ts.map +1 -0
  215. package/dist/leaked-password/leaked-password.service.js +218 -0
  216. package/dist/leaked-password/leaked-password.service.js.map +1 -0
  217. package/dist/locale/locale.controller.d.ts +1 -1
  218. package/dist/locale/locale.service.d.ts +1 -1
  219. package/dist/mail/dto/preview.dto.d.ts +18 -0
  220. package/dist/mail/dto/preview.dto.d.ts.map +1 -0
  221. package/dist/mail/dto/preview.dto.js +66 -0
  222. package/dist/mail/dto/preview.dto.js.map +1 -0
  223. package/dist/mail/dto/send.dto.d.ts +7 -0
  224. package/dist/mail/dto/send.dto.d.ts.map +1 -1
  225. package/dist/mail/dto/send.dto.js +10 -0
  226. package/dist/mail/dto/send.dto.js.map +1 -1
  227. package/dist/mail/mail.controller.d.ts +4 -0
  228. package/dist/mail/mail.controller.d.ts.map +1 -1
  229. package/dist/mail/mail.controller.js +16 -2
  230. package/dist/mail/mail.controller.js.map +1 -1
  231. package/dist/mail/mail.service.d.ts +23 -2
  232. package/dist/mail/mail.service.d.ts.map +1 -1
  233. package/dist/mail/mail.service.js +102 -13
  234. package/dist/mail/mail.service.js.map +1 -1
  235. package/dist/mail-layout/dto/update.dto.d.ts +17 -0
  236. package/dist/mail-layout/dto/update.dto.d.ts.map +1 -0
  237. package/dist/mail-layout/dto/update.dto.js +27 -0
  238. package/dist/mail-layout/dto/update.dto.js.map +1 -0
  239. package/dist/mail-layout/mail-layout.controller.d.ts +15 -0
  240. package/dist/mail-layout/mail-layout.controller.d.ts.map +1 -0
  241. package/dist/mail-layout/mail-layout.controller.js +71 -0
  242. package/dist/mail-layout/mail-layout.controller.js.map +1 -0
  243. package/dist/mail-layout/mail-layout.module.d.ts +3 -0
  244. package/dist/mail-layout/mail-layout.module.d.ts.map +1 -0
  245. package/dist/mail-layout/mail-layout.module.js +35 -0
  246. package/dist/mail-layout/mail-layout.module.js.map +1 -0
  247. package/dist/mail-layout/mail-layout.service.d.ts +27 -0
  248. package/dist/mail-layout/mail-layout.service.d.ts.map +1 -0
  249. package/dist/mail-layout/mail-layout.service.js +80 -0
  250. package/dist/mail-layout/mail-layout.service.js.map +1 -0
  251. package/dist/mcp-chat/mcp-chat.controller.d.ts +2 -2
  252. package/dist/mcp-chat/mcp-chat.service.d.ts +24 -2
  253. package/dist/mcp-chat/mcp-chat.service.d.ts.map +1 -1
  254. package/dist/mcp-chat/mcp-chat.service.js +80 -24
  255. package/dist/mcp-chat/mcp-chat.service.js.map +1 -1
  256. package/dist/menu/menu.controller.d.ts +3 -3
  257. package/dist/menu/menu.service.d.ts +3 -3
  258. package/dist/notification/notification.controller.d.ts +12 -12
  259. package/dist/notification/notification.service.d.ts +12 -12
  260. package/dist/oauth/oauth-token-broker.service.d.ts +72 -0
  261. package/dist/oauth/oauth-token-broker.service.d.ts.map +1 -0
  262. package/dist/oauth/oauth-token-broker.service.js +258 -0
  263. package/dist/oauth/oauth-token-broker.service.js.map +1 -0
  264. package/dist/oauth/oauth.module.d.ts.map +1 -1
  265. package/dist/oauth/oauth.module.js +3 -1
  266. package/dist/oauth/oauth.module.js.map +1 -1
  267. package/dist/oauth/oauth.service.d.ts +2 -0
  268. package/dist/oauth/oauth.service.d.ts.map +1 -1
  269. package/dist/oauth/oauth.service.js +6 -3
  270. package/dist/oauth/oauth.service.js.map +1 -1
  271. package/dist/pdf/pdf.service.d.ts +8 -0
  272. package/dist/pdf/pdf.service.d.ts.map +1 -1
  273. package/dist/pdf/pdf.service.js +52 -0
  274. package/dist/pdf/pdf.service.js.map +1 -1
  275. package/dist/presence/presence.controller.d.ts +16 -0
  276. package/dist/presence/presence.controller.d.ts.map +1 -0
  277. package/dist/presence/presence.controller.js +60 -0
  278. package/dist/presence/presence.controller.js.map +1 -0
  279. package/dist/presence/presence.listener.d.ts +29 -0
  280. package/dist/presence/presence.listener.d.ts.map +1 -0
  281. package/dist/presence/presence.listener.js +82 -0
  282. package/dist/presence/presence.listener.js.map +1 -0
  283. package/dist/presence/presence.module.d.ts +3 -0
  284. package/dist/presence/presence.module.d.ts.map +1 -0
  285. package/dist/presence/presence.module.js +32 -0
  286. package/dist/presence/presence.module.js.map +1 -0
  287. package/dist/presence/presence.service.d.ts +42 -0
  288. package/dist/presence/presence.service.d.ts.map +1 -0
  289. package/dist/presence/presence.service.js +147 -0
  290. package/dist/presence/presence.service.js.map +1 -0
  291. package/dist/profile/dto/delete-account.dto.d.ts +8 -0
  292. package/dist/profile/dto/delete-account.dto.d.ts.map +1 -0
  293. package/dist/profile/dto/delete-account.dto.js +22 -0
  294. package/dist/profile/dto/delete-account.dto.js.map +1 -0
  295. package/dist/profile/events/profile-account-deleted.event.d.ts +12 -0
  296. package/dist/profile/events/profile-account-deleted.event.d.ts.map +1 -0
  297. package/dist/profile/events/profile-account-deleted.event.js +17 -0
  298. package/dist/profile/events/profile-account-deleted.event.js.map +1 -0
  299. package/dist/profile/profile.controller.d.ts +24 -17
  300. package/dist/profile/profile.controller.d.ts.map +1 -1
  301. package/dist/profile/profile.controller.js +75 -46
  302. package/dist/profile/profile.controller.js.map +1 -1
  303. package/dist/profile/profile.service.d.ts +34 -21
  304. package/dist/profile/profile.service.d.ts.map +1 -1
  305. package/dist/profile/profile.service.js +113 -37
  306. package/dist/profile/profile.service.js.map +1 -1
  307. package/dist/realtime/realtime.gateway.d.ts +48 -0
  308. package/dist/realtime/realtime.gateway.d.ts.map +1 -0
  309. package/dist/realtime/realtime.gateway.js +156 -0
  310. package/dist/realtime/realtime.gateway.js.map +1 -0
  311. package/dist/realtime/realtime.module.d.ts +8 -0
  312. package/dist/realtime/realtime.module.d.ts.map +1 -0
  313. package/dist/realtime/realtime.module.js +29 -0
  314. package/dist/realtime/realtime.module.js.map +1 -0
  315. package/dist/realtime/realtime.service.d.ts +51 -0
  316. package/dist/realtime/realtime.service.d.ts.map +1 -0
  317. package/dist/realtime/realtime.service.js +177 -0
  318. package/dist/realtime/realtime.service.js.map +1 -0
  319. package/dist/redis/redis-pubsub.d.ts +27 -0
  320. package/dist/redis/redis-pubsub.d.ts.map +1 -0
  321. package/dist/redis/redis-pubsub.js +140 -0
  322. package/dist/redis/redis-pubsub.js.map +1 -0
  323. package/dist/role/role.controller.d.ts +3 -3
  324. package/dist/role/role.service.d.ts +3 -3
  325. package/dist/setting/dto/create.dto.d.ts.map +1 -1
  326. package/dist/setting/dto/create.dto.js +9 -2
  327. package/dist/setting/dto/create.dto.js.map +1 -1
  328. package/dist/setting/setting.controller.d.ts +5 -5
  329. package/dist/setting/setting.service.d.ts +8 -5
  330. package/dist/setting/setting.service.d.ts.map +1 -1
  331. package/dist/setting/setting.service.js +25 -1
  332. package/dist/setting/setting.service.js.map +1 -1
  333. package/dist/user/dto/create-with-email-and-password.dto.d.ts +2 -0
  334. package/dist/user/dto/create-with-email-and-password.dto.d.ts.map +1 -1
  335. package/dist/user/dto/create-with-email-and-password.dto.js +5 -0
  336. package/dist/user/dto/create-with-email-and-password.dto.js.map +1 -1
  337. package/dist/user/dto/query-user-mail-list.dto.d.ts +5 -0
  338. package/dist/user/dto/query-user-mail-list.dto.d.ts.map +1 -0
  339. package/dist/user/dto/query-user-mail-list.dto.js +25 -0
  340. package/dist/user/dto/query-user-mail-list.dto.js.map +1 -0
  341. package/dist/user/user-credential.util.d.ts +19 -0
  342. package/dist/user/user-credential.util.d.ts.map +1 -0
  343. package/dist/user/user-credential.util.js +32 -0
  344. package/dist/user/user-credential.util.js.map +1 -0
  345. package/dist/user/user.controller.d.ts +17 -5
  346. package/dist/user/user.controller.d.ts.map +1 -1
  347. package/dist/user/user.controller.js +18 -3
  348. package/dist/user/user.controller.js.map +1 -1
  349. package/dist/user/user.service.d.ts +28 -6
  350. package/dist/user/user.service.d.ts.map +1 -1
  351. package/dist/user/user.service.js +204 -13
  352. package/dist/user/user.service.js.map +1 -1
  353. package/dist/validators/is-strong-password-with-settings.validator.d.ts.map +1 -1
  354. package/dist/validators/is-strong-password-with-settings.validator.js +11 -0
  355. package/dist/validators/is-strong-password-with-settings.validator.js.map +1 -1
  356. package/dist/validators/service-locator.d.ts +9 -0
  357. package/dist/validators/service-locator.d.ts.map +1 -1
  358. package/dist/validators/service-locator.js +12 -0
  359. package/dist/validators/service-locator.js.map +1 -1
  360. package/dist/webhook-integration/webhook-integration.controller.d.ts +5 -8
  361. package/dist/webhook-integration/webhook-integration.controller.d.ts.map +1 -1
  362. package/dist/webhook-integration/webhook-integration.controller.js +31 -8
  363. package/dist/webhook-integration/webhook-integration.controller.js.map +1 -1
  364. package/dist/webhook-integration/webhook-integration.module.d.ts.map +1 -1
  365. package/dist/webhook-integration/webhook-integration.module.js +5 -0
  366. package/dist/webhook-integration/webhook-integration.module.js.map +1 -1
  367. package/dist/webhook-integration/webhook-integration.service.d.ts +33 -1
  368. package/dist/webhook-integration/webhook-integration.service.d.ts.map +1 -1
  369. package/dist/webhook-integration/webhook-integration.service.js +109 -4
  370. package/dist/webhook-integration/webhook-integration.service.js.map +1 -1
  371. package/dist/webhook-integration/webhook-protocol.registry.d.ts +63 -0
  372. package/dist/webhook-integration/webhook-protocol.registry.d.ts.map +1 -0
  373. package/dist/webhook-integration/webhook-protocol.registry.js +51 -0
  374. package/dist/webhook-integration/webhook-protocol.registry.js.map +1 -0
  375. package/dist/whatsapp-sender/whatsapp-sender.module.d.ts +3 -0
  376. package/dist/whatsapp-sender/whatsapp-sender.module.d.ts.map +1 -0
  377. package/dist/whatsapp-sender/whatsapp-sender.module.js +23 -0
  378. package/dist/whatsapp-sender/whatsapp-sender.module.js.map +1 -0
  379. package/dist/whatsapp-sender/whatsapp-sender.service.d.ts +50 -0
  380. package/dist/whatsapp-sender/whatsapp-sender.service.d.ts.map +1 -0
  381. package/dist/whatsapp-sender/whatsapp-sender.service.js +224 -0
  382. package/dist/whatsapp-sender/whatsapp-sender.service.js.map +1 -0
  383. package/hedhog/data/integration_provider.yaml +16 -0
  384. package/hedhog/data/mail.yaml +88 -61
  385. package/hedhog/data/mail_layout.yaml +188 -0
  386. package/hedhog/data/menu.yaml +67 -3
  387. package/hedhog/data/route.yaml +135 -0
  388. package/hedhog/data/setting_group.yaml +139 -1
  389. package/hedhog/frontend/app/account/components/mfa-setup-dialog.tsx.ejs +36 -0
  390. package/hedhog/frontend/app/account/components/two-factor-auth.tsx.ejs +2 -0
  391. package/hedhog/frontend/app/account/hooks/use-mfa-setup.ts.ejs +10 -7
  392. package/hedhog/frontend/app/ai_agent/page.tsx.ejs +7 -4
  393. package/hedhog/frontend/app/ai_instruction/_components/ai-instruction-form.tsx.ejs +580 -0
  394. package/hedhog/frontend/app/ai_instruction/_components/ai-instruction-preview.tsx.ejs +150 -0
  395. package/hedhog/frontend/app/ai_instruction/_components/ai-instruction-versions.tsx.ejs +199 -0
  396. package/hedhog/frontend/app/ai_instruction/_components/prompt-diff.tsx.ejs +63 -0
  397. package/hedhog/frontend/app/ai_instruction/_lib/line-diff.spec.ts.ejs +59 -0
  398. package/hedhog/frontend/app/ai_instruction/_lib/line-diff.ts.ejs +72 -0
  399. package/hedhog/frontend/app/ai_instruction/_lib/prompt-template.spec.ts.ejs +170 -0
  400. package/hedhog/frontend/app/ai_instruction/_lib/prompt-template.ts.ejs +167 -0
  401. package/hedhog/frontend/app/ai_instruction/_lib/types.ts.ejs +99 -0
  402. package/hedhog/frontend/app/ai_instruction/page.tsx.ejs +422 -0
  403. package/hedhog/frontend/app/configurations/[slug]/components/setting-field.tsx.ejs +51 -4
  404. package/hedhog/frontend/app/incidents/page.tsx.ejs +400 -0
  405. package/hedhog/frontend/app/integration/profiles/page.tsx.ejs +169 -92
  406. package/hedhog/frontend/app/mail/layout/page.tsx.ejs +344 -0
  407. package/hedhog/frontend/app/mail/template/page.tsx.ejs +155 -121
  408. package/hedhog/frontend/app/mcp_chat/page.tsx.ejs +129 -17
  409. package/hedhog/frontend/app/pages/_components/page-delete-dialog.tsx.ejs +343 -0
  410. package/hedhog/frontend/app/pages/_components/page-detail-sheet.tsx.ejs +438 -0
  411. package/hedhog/frontend/app/pages/_components/page-wizard-sheet.tsx.ejs +1009 -0
  412. package/hedhog/frontend/app/pages/_components/system-page-types.ts.ejs +56 -0
  413. package/hedhog/frontend/app/pages/_components/use-system-pages.ts.ejs +171 -0
  414. package/hedhog/frontend/app/pages/page.tsx.ejs +514 -0
  415. package/hedhog/frontend/app/users/page.tsx.ejs +119 -13
  416. package/hedhog/frontend/app/users/user-activity-timeline.tsx.ejs +231 -0
  417. package/hedhog/frontend/app/users/user-mails.tsx.ejs +399 -0
  418. package/hedhog/frontend/app/users/user-sheet.tsx.ejs +60 -75
  419. package/hedhog/frontend/messages/en.json +521 -3
  420. package/hedhog/frontend/messages/pt.json +521 -3
  421. package/hedhog/table/ai_agent.yaml +1 -0
  422. package/hedhog/table/ai_instruction.yaml +15 -0
  423. package/hedhog/table/leaked_password.yaml +18 -0
  424. package/hedhog/table/mail_layout.yaml +35 -0
  425. package/hedhog/table/mail_var.yaml +4 -0
  426. package/hedhog/table/setting.yaml +1 -0
  427. package/hedhog/table/system_incident.yaml +59 -0
  428. package/hedhog/table/user_presence.yaml +36 -0
  429. package/hedhog/table/webhook_integration.yaml +64 -43
  430. package/package.json +8 -4
  431. package/src/access-log/access-log.interceptor.ts +4 -2
  432. package/src/ai/ai-attachment.fragments.spec.ts +319 -0
  433. package/src/ai/ai-attachment.fragments.ts +35 -0
  434. package/src/ai/ai.prompts.ts +38 -0
  435. package/src/ai/ai.service.spec.ts +280 -0
  436. package/src/ai/ai.service.ts +338 -82
  437. package/src/ai/dto/chat.dto.ts +33 -3
  438. package/src/ai/dto/create-agent.dto.ts +2 -2
  439. package/src/ai/dto/update-agent.dto.ts +2 -2
  440. package/src/ai-instruction/ai-instruction.controller.ts +40 -9
  441. package/src/ai-instruction/ai-instruction.module.ts +13 -2
  442. package/src/ai-instruction/ai-instruction.service.spec.ts +658 -0
  443. package/src/ai-instruction/ai-instruction.service.ts +661 -62
  444. package/src/ai-instruction/ai-prompt-builder.service.ts +10 -1
  445. package/src/ai-instruction/ai-prompt-registry.ts +87 -0
  446. package/src/ai-instruction/ai-prompt-resolver.service.spec.ts +375 -0
  447. package/src/ai-instruction/ai-prompt-resolver.service.ts +295 -0
  448. package/src/ai-instruction/ai-prompt-template.util.spec.ts +162 -0
  449. package/src/ai-instruction/ai-prompt-template.util.ts +199 -0
  450. package/src/ai-instruction/dto/create-ai-instruction.dto.ts +39 -3
  451. package/src/ai-instruction/dto/preview-ai-instruction.dto.ts +26 -0
  452. package/src/ai-instruction/dto/update-ai-instruction.dto.ts +42 -1
  453. package/src/ai-instruction/types/ai-instruction.types.ts +24 -1
  454. package/src/auth/auth.controller.ts +33 -6
  455. package/src/auth/auth.service.spec.ts +3 -1
  456. package/src/auth/auth.service.ts +103 -37
  457. package/src/captcha/captcha.module.ts +10 -0
  458. package/src/captcha/captcha.service.spec.ts +210 -0
  459. package/src/captcha/captcha.service.ts +191 -0
  460. package/src/challenge/challenge.service.spec.ts +39 -4
  461. package/src/challenge/challenge.service.ts +72 -17
  462. package/src/core.module.ts +27 -1
  463. package/src/file/file.service.spec.ts +105 -0
  464. package/src/file/file.service.ts +60 -3
  465. package/src/incident/incident-notifier.service.spec.ts +205 -0
  466. package/src/incident/incident-notifier.service.ts +241 -0
  467. package/src/incident/incident.controller.ts +38 -0
  468. package/src/incident/incident.module.ts +19 -0
  469. package/src/incident/incident.service.spec.ts +150 -0
  470. package/src/incident/incident.service.ts +209 -0
  471. package/src/index.ts +38 -0
  472. package/src/integration-profile/dto/test.dto.ts +19 -0
  473. package/src/integration-profile/integration-profile.controller.ts +10 -1
  474. package/src/integration-profile/integration-profile.module.spec.ts +51 -0
  475. package/src/integration-profile/integration-profile.module.ts +23 -4
  476. package/src/integration-profile/integration-profile.secrets.ts +12 -2
  477. package/src/integration-profile/integration-profile.service.spec.ts +279 -0
  478. package/src/integration-profile/integration-profile.service.ts +132 -29
  479. package/src/integration-profile/integration-profile.utils.spec.ts +97 -0
  480. package/src/integration-profile/integration-profile.utils.ts +79 -3
  481. package/src/integration-profile/testers/ai.testers.ts +165 -0
  482. package/src/integration-profile/testers/captcha.testers.spec.ts +92 -0
  483. package/src/integration-profile/testers/captcha.testers.ts +139 -0
  484. package/src/integration-profile/testers/email.testers.ts +161 -0
  485. package/src/integration-profile/testers/http-probe.spec.ts +153 -0
  486. package/src/integration-profile/testers/http-probe.ts +171 -0
  487. package/src/integration-profile/testers/index.ts +30 -0
  488. package/src/integration-profile/testers/infrastructure.testers.ts +122 -0
  489. package/src/integration-profile/testers/integration-tester.registry.spec.ts +75 -0
  490. package/src/integration-profile/testers/integration-tester.registry.ts +43 -0
  491. package/src/integration-profile/testers/integration-tester.types.ts +61 -0
  492. package/src/integration-profile/testers/messaging.testers.ts +102 -0
  493. package/src/integration-profile/testers/oauth.testers.spec.ts +220 -0
  494. package/src/integration-profile/testers/oauth.testers.ts +305 -0
  495. package/src/integration-profile/testers/payment.testers.ts +185 -0
  496. package/src/integration-profile/testers/remaining.testers.spec.ts +401 -0
  497. package/src/integration-profile/testers/storage.testers.spec.ts +185 -0
  498. package/src/integration-profile/testers/storage.testers.ts +226 -0
  499. package/src/integration-profile/testers/tester-coverage.spec.ts +58 -0
  500. package/src/language/en.json +4 -2
  501. package/src/language/pt.json +4 -2
  502. package/src/leaked-password/README.md +83 -0
  503. package/src/leaked-password/leaked-password.controller.ts +52 -0
  504. package/src/leaked-password/leaked-password.module.ts +18 -0
  505. package/src/leaked-password/leaked-password.service.ts +242 -0
  506. package/src/leaked-password/seed/build-seed-sql.mjs +180 -0
  507. package/src/leaked-password/seed/common-passwords.txt +335 -0
  508. package/src/mail/dto/preview.dto.ts +50 -0
  509. package/src/mail/dto/send.dto.ts +14 -1
  510. package/src/mail/mail-template.spec.ts +197 -0
  511. package/src/mail/mail.controller.ts +9 -2
  512. package/src/mail/mail.service.spec.ts +116 -1
  513. package/src/mail/mail.service.ts +118 -12
  514. package/src/mail-layout/dto/update.dto.ts +19 -0
  515. package/src/mail-layout/mail-layout.controller.ts +47 -0
  516. package/src/mail-layout/mail-layout.module.ts +22 -0
  517. package/src/mail-layout/mail-layout.service.ts +94 -0
  518. package/src/mcp-chat/mcp-chat.service.spec.ts +236 -0
  519. package/src/mcp-chat/mcp-chat.service.ts +122 -26
  520. package/src/oauth/oauth-token-broker.service.spec.ts +172 -0
  521. package/src/oauth/oauth-token-broker.service.ts +363 -0
  522. package/src/oauth/oauth.module.ts +3 -1
  523. package/src/oauth/oauth.service.ts +8 -2
  524. package/src/pdf/pdf.service.ts +75 -0
  525. package/src/presence/presence.controller.ts +29 -0
  526. package/src/presence/presence.listener.ts +53 -0
  527. package/src/presence/presence.module.ts +19 -0
  528. package/src/presence/presence.service.spec.ts +97 -0
  529. package/src/presence/presence.service.ts +160 -0
  530. package/src/profile/dto/delete-account.dto.ts +11 -0
  531. package/src/profile/events/profile-account-deleted.event.ts +13 -0
  532. package/src/profile/profile.controller.ts +52 -36
  533. package/src/profile/profile.service.ts +143 -41
  534. package/src/realtime/realtime.gateway.ts +138 -0
  535. package/src/realtime/realtime.module.ts +16 -0
  536. package/src/realtime/realtime.service.spec.ts +50 -0
  537. package/src/realtime/realtime.service.ts +187 -0
  538. package/src/redis/redis-pubsub.ts +179 -0
  539. package/src/setting/dto/create.dto.ts +13 -2
  540. package/src/setting/setting.service.spec.ts +56 -0
  541. package/src/setting/setting.service.ts +29 -1
  542. package/src/user/dto/create-with-email-and-password.dto.ts +6 -1
  543. package/src/user/dto/query-user-mail-list.dto.ts +10 -0
  544. package/src/user/user-credential.util.ts +35 -0
  545. package/src/user/user.controller.ts +17 -2
  546. package/src/user/user.service.spec.ts +153 -0
  547. package/src/user/user.service.ts +255 -12
  548. package/src/validators/is-strong-password-with-settings.validator.ts +12 -0
  549. package/src/validators/service-locator.ts +15 -0
  550. package/src/webhook-integration/webhook-integration.controller.ts +40 -2
  551. package/src/webhook-integration/webhook-integration.module.ts +5 -0
  552. package/src/webhook-integration/webhook-integration.service.ts +133 -0
  553. package/src/webhook-integration/webhook-protocol.registry.spec.ts +70 -0
  554. package/src/webhook-integration/webhook-protocol.registry.ts +93 -0
  555. package/src/whatsapp-sender/whatsapp-sender.module.ts +10 -0
  556. package/src/whatsapp-sender/whatsapp-sender.service.ts +313 -0
@@ -0,0 +1,241 @@
1
+ import { PrismaService } from '@hed-hog/api-prisma';
2
+ import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common';
3
+ import { buildWhatsappOfficialConfigFromIntegration } from '../integration-profile/integration-profile.utils';
4
+ import { MailService } from '../mail/mail.service';
5
+ import { SettingService } from '../setting/setting.service';
6
+
7
+ export type IncidentSeverity = 'warning' | 'error' | 'critical';
8
+
9
+ export interface NotifiableIncident {
10
+ id: number;
11
+ source: string;
12
+ code: string;
13
+ severity: IncidentSeverity;
14
+ message: string;
15
+ occurrences: number;
16
+ context?: Record<string, unknown> | null;
17
+ notifiedAt?: Date | null;
18
+ reason: 'created' | 'reopened';
19
+ }
20
+
21
+ const SEVERITY_ORDER: Record<IncidentSeverity, number> = {
22
+ warning: 0,
23
+ error: 1,
24
+ critical: 2,
25
+ };
26
+
27
+ /**
28
+ * Fonte reservada às falhas do próprio aviso. Nunca notifica — senão um SMTP
29
+ * fora do ar geraria aviso, que falharia, que geraria outro aviso, em laço.
30
+ */
31
+ export const INCIDENT_NOTIFY_SOURCE = 'core.incident-notify';
32
+
33
+ const SETTING_KEYS = [
34
+ 'incident.notify-enabled',
35
+ 'incident.notify-min-severity',
36
+ 'incident.notify-cooldown-minutes',
37
+ 'incident.notify-email-to',
38
+ 'incident.notify-whatsapp-profile',
39
+ 'incident.notify-whatsapp-phone-number-id',
40
+ 'incident.notify-whatsapp-to',
41
+ 'incident.notify-whatsapp-template',
42
+ 'incident.notify-whatsapp-template-language',
43
+ ];
44
+
45
+ @Injectable()
46
+ export class IncidentNotifierService {
47
+ private readonly logger = new Logger(IncidentNotifierService.name);
48
+
49
+ constructor(
50
+ @Inject(forwardRef(() => PrismaService)) private readonly prisma: PrismaService,
51
+ @Inject(forwardRef(() => SettingService)) private readonly setting: SettingService,
52
+ @Inject(forwardRef(() => MailService)) private readonly mail: MailService,
53
+ ) {}
54
+
55
+ /** Nunca lança: o aviso é o último elo, não pode derrubar nada acima dele. */
56
+ async notify(incident: NotifiableIncident): Promise<void> {
57
+ try {
58
+ if (incident.source === INCIDENT_NOTIFY_SOURCE) return;
59
+
60
+ const settings = await this.setting.getSettingValues(SETTING_KEYS);
61
+
62
+ if (!this.isTrue(settings['incident.notify-enabled'])) return;
63
+
64
+ const minSeverity = this.parseSeverity(settings['incident.notify-min-severity']);
65
+ if (SEVERITY_ORDER[incident.severity] < SEVERITY_ORDER[minSeverity]) return;
66
+
67
+ if (this.isWithinCooldown(incident, settings['incident.notify-cooldown-minutes'])) return;
68
+
69
+ const subject = `[${incident.severity.toUpperCase()}] ${incident.source} — ${incident.code}`;
70
+ const sent: string[] = [];
71
+
72
+ if (await this.sendEmail(settings['incident.notify-email-to'], subject, incident)) {
73
+ sent.push('email');
74
+ }
75
+
76
+ if (await this.sendWhatsapp(settings, subject, incident)) {
77
+ sent.push('whatsapp');
78
+ }
79
+
80
+ if (!sent.length) return;
81
+
82
+ await (this.prisma as any).system_incident.update({
83
+ where: { id: incident.id },
84
+ data: { notified_at: new Date() },
85
+ });
86
+
87
+ this.logger.log(`Incidente ${incident.id} avisado via ${sent.join(', ')}`);
88
+ } catch (error) {
89
+ const message = error instanceof Error ? error.message : String(error);
90
+ this.logger.warn(`Falha ao avisar sobre o incidente ${incident.id}: ${message}`);
91
+ }
92
+ }
93
+
94
+ private isWithinCooldown(incident: NotifiableIncident, raw: unknown): boolean {
95
+ // Reabertura sempre avisa: o incidente foi dado como resolvido e voltou.
96
+ if (incident.reason === 'reopened') return false;
97
+ if (!incident.notifiedAt) return false;
98
+
99
+ const minutes = Number(raw);
100
+ const cooldown = Number.isFinite(minutes) && minutes > 0 ? minutes : 60;
101
+
102
+ return Date.now() - new Date(incident.notifiedAt).getTime() < cooldown * 60_000;
103
+ }
104
+
105
+ private async sendEmail(
106
+ raw: unknown,
107
+ subject: string,
108
+ incident: NotifiableIncident,
109
+ ): Promise<boolean> {
110
+ const recipients = String(raw ?? '')
111
+ .split(',')
112
+ .map((item) => item.trim())
113
+ .filter(Boolean);
114
+
115
+ if (!recipients.length) return false;
116
+
117
+ const html = [
118
+ `<p><strong>${this.escape(incident.message)}</strong></p>`,
119
+ `<p>Origem: ${this.escape(incident.source)}<br>`,
120
+ `Código: ${this.escape(incident.code)}<br>`,
121
+ `Severidade: ${this.escape(incident.severity)}<br>`,
122
+ `Ocorrências: ${incident.occurrences}</p>`,
123
+ incident.context
124
+ ? `<pre>${this.escape(JSON.stringify(incident.context, null, 2))}</pre>`
125
+ : '',
126
+ ].join('');
127
+
128
+ // sendRawMail não depende de template cadastrado: um alerta de infra não
129
+ // pode depender de seed de banco para sair.
130
+ for (const to of recipients) {
131
+ await this.mail.sendRawMail({ to, subject, html });
132
+ }
133
+
134
+ return true;
135
+ }
136
+
137
+ private async sendWhatsapp(
138
+ settings: Record<string, unknown>,
139
+ subject: string,
140
+ incident: NotifiableIncident,
141
+ ): Promise<boolean> {
142
+ const profileSlug = String(settings['incident.notify-whatsapp-profile'] ?? '').trim();
143
+ const phoneNumberId = String(settings['incident.notify-whatsapp-phone-number-id'] ?? '').trim();
144
+ const to = String(settings['incident.notify-whatsapp-to'] ?? '').replace(/\D/g, '');
145
+
146
+ if (!profileSlug || !phoneNumberId || !to) return false;
147
+
148
+ const profile = await this.prisma.integration_profile.findUnique({
149
+ where: { slug: profileSlug },
150
+ select: { config: true },
151
+ });
152
+
153
+ if (!profile) {
154
+ this.logger.warn(`Perfil de integração "${profileSlug}" não encontrado para aviso.`);
155
+ return false;
156
+ }
157
+
158
+ const cfg = buildWhatsappOfficialConfigFromIntegration(profile.config);
159
+
160
+ if (!cfg.accessToken) {
161
+ this.logger.warn(`Perfil "${profileSlug}" sem access token.`);
162
+ return false;
163
+ }
164
+
165
+ const template = String(settings['incident.notify-whatsapp-template'] ?? '').trim();
166
+ const language =
167
+ String(settings['incident.notify-whatsapp-template-language'] ?? '').trim() || 'pt_BR';
168
+
169
+ // A Meta só aceita mensagem iniciada pela empresa através de template
170
+ // aprovado. Sem template, o texto livre só é entregue se o destinatário
171
+ // tiver falado com o número nas últimas 24h.
172
+ const body = template
173
+ ? {
174
+ messaging_product: 'whatsapp',
175
+ to,
176
+ type: 'template',
177
+ template: {
178
+ name: template,
179
+ language: { code: language },
180
+ components: [
181
+ {
182
+ type: 'body',
183
+ parameters: [
184
+ { type: 'text', text: subject },
185
+ { type: 'text', text: incident.message.slice(0, 400) },
186
+ ],
187
+ },
188
+ ],
189
+ },
190
+ }
191
+ : {
192
+ messaging_product: 'whatsapp',
193
+ to,
194
+ type: 'text',
195
+ text: { body: `${subject}\n\n${incident.message}`.slice(0, 4000) },
196
+ };
197
+
198
+ const url = `https://graph.facebook.com/${cfg.graphApiVersion}/${encodeURIComponent(
199
+ phoneNumberId,
200
+ )}/messages`;
201
+
202
+ const response = await fetch(url, {
203
+ method: 'POST',
204
+ headers: {
205
+ Authorization: `Bearer ${cfg.accessToken}`,
206
+ 'Content-Type': 'application/json',
207
+ },
208
+ body: JSON.stringify(body),
209
+ });
210
+
211
+ if (!response.ok) {
212
+ const payload = (await response.json().catch(() => ({}))) as {
213
+ error?: { message?: string };
214
+ };
215
+ this.logger.warn(
216
+ `WhatsApp recusou o aviso (HTTP ${response.status}): ${
217
+ payload?.error?.message ?? 'sem detalhe'
218
+ }${template ? '' : ' — sem template configurado, a entrega só funciona na janela de 24h'}`,
219
+ );
220
+ return false;
221
+ }
222
+
223
+ return true;
224
+ }
225
+
226
+ private parseSeverity(raw: unknown): IncidentSeverity {
227
+ const value = String(raw ?? '').trim().toLowerCase();
228
+ return value === 'warning' || value === 'error' || value === 'critical' ? value : 'critical';
229
+ }
230
+
231
+ private isTrue(value: unknown): boolean {
232
+ return value === true || value === 'true';
233
+ }
234
+
235
+ private escape(value: string): string {
236
+ return String(value ?? '')
237
+ .replace(/&/g, '&amp;')
238
+ .replace(/</g, '&lt;')
239
+ .replace(/>/g, '&gt;');
240
+ }
241
+ }
@@ -0,0 +1,38 @@
1
+ import { Role, User } from '@hed-hog/api';
2
+ import { Pagination } from '@hed-hog/api-pagination';
3
+ import { Controller, Get, Inject, Param, Patch, Query, forwardRef } from '@nestjs/common';
4
+ import { IncidentService, type IncidentSeverity } from './incident.service';
5
+
6
+ @Role()
7
+ @Controller('incident')
8
+ export class IncidentController {
9
+ constructor(
10
+ @Inject(forwardRef(() => IncidentService))
11
+ private readonly incidentService: IncidentService,
12
+ ) {}
13
+
14
+ @Get()
15
+ async list(
16
+ @Pagination() paginationParams,
17
+ @Query('source') source?: string,
18
+ @Query('severity') severity?: IncidentSeverity,
19
+ @Query('status') status?: 'open' | 'resolved' | 'all',
20
+ ) {
21
+ return this.incidentService.list({ ...paginationParams, source, severity, status });
22
+ }
23
+
24
+ @Get('summary')
25
+ async summary() {
26
+ return this.incidentService.summary();
27
+ }
28
+
29
+ @Patch(':id/resolve')
30
+ async resolve(@Param('id') id: string, @User() user) {
31
+ return this.incidentService.resolve(Number(id), user?.id);
32
+ }
33
+
34
+ @Patch(':id/reopen')
35
+ async reopen(@Param('id') id: string) {
36
+ return this.incidentService.reopen(Number(id));
37
+ }
38
+ }
@@ -0,0 +1,19 @@
1
+ import { PaginationModule } from '@hed-hog/api-pagination';
2
+ import { PrismaModule } from '@hed-hog/api-prisma';
3
+ import { forwardRef, Global, Module } from '@nestjs/common';
4
+ import { IncidentNotifierService } from './incident-notifier.service';
5
+ import { IncidentController } from './incident.controller';
6
+ import { IncidentService } from './incident.service';
7
+
8
+ /**
9
+ * `@Global()` de propósito: qualquer módulo que engula uma falha deve conseguir
10
+ * registrá-la sem precisar importar mais nada.
11
+ */
12
+ @Global()
13
+ @Module({
14
+ imports: [forwardRef(() => PrismaModule), forwardRef(() => PaginationModule)],
15
+ controllers: [IncidentController],
16
+ providers: [IncidentService, IncidentNotifierService],
17
+ exports: [IncidentService, IncidentNotifierService],
18
+ })
19
+ export class IncidentModule {}
@@ -0,0 +1,150 @@
1
+ import { beforeEach, describe, expect, it, jest } from '@jest/globals';
2
+ import { IncidentService } from './incident.service';
3
+
4
+ const makeDeps = () => ({
5
+ prisma: {
6
+ system_incident: {
7
+ findUnique: jest.fn(async () => null),
8
+ upsert: jest.fn(async () => ({ id: 1, occurrences: 1 })),
9
+ count: jest.fn(async () => 0),
10
+ groupBy: jest.fn(async () => []),
11
+ update: jest.fn(async () => ({ id: 1 })),
12
+ },
13
+ },
14
+ pagination: { paginate: jest.fn(async () => ({ data: [], total: 0 })) },
15
+ notifier: { notify: jest.fn(async () => undefined) },
16
+ });
17
+
18
+ const makeService = (deps: any) => new IncidentService(deps.prisma as any, deps.pagination as any, deps.notifier as any);
19
+
20
+ describe('IncidentService.persist', () => {
21
+ beforeEach(() => jest.clearAllMocks());
22
+
23
+ it('agrupa por fingerprint em vez de criar uma linha por ocorrência', async () => {
24
+ const deps = makeDeps();
25
+ await makeService(deps).persist({
26
+ source: 'core.mail',
27
+ code: 'mail_send_failed',
28
+ message: 'SMTP timeout',
29
+ key: 'auth-login-new-device',
30
+ });
31
+
32
+ const [args] = deps.prisma.system_incident.upsert.mock.calls[0] as [any];
33
+ expect(args.where.fingerprint).toMatch(/^[0-9a-f]{64}$/);
34
+ expect(args.update.occurrences).toEqual({ increment: 1 });
35
+ expect(args.create.occurrences).toBe(1);
36
+ });
37
+
38
+ it('o mesmo (source, code, key) gera o mesmo fingerprint', async () => {
39
+ const deps = makeDeps();
40
+ const service = makeService(deps);
41
+ const input = { source: 'core.mail', code: 'x', message: 'm', key: 'slug-a' };
42
+
43
+ await service.persist(input);
44
+ await service.persist({ ...input, message: 'outra mensagem' });
45
+
46
+ const [a] = deps.prisma.system_incident.upsert.mock.calls[0] as [any];
47
+ const [b] = deps.prisma.system_incident.upsert.mock.calls[1] as [any];
48
+ expect(a.where.fingerprint).toBe(b.where.fingerprint);
49
+ });
50
+
51
+ it('key diferente gera incidente diferente', async () => {
52
+ const deps = makeDeps();
53
+ const service = makeService(deps);
54
+
55
+ await service.persist({ source: 'core.mail', code: 'x', message: 'm', key: 'slug-a' });
56
+ await service.persist({ source: 'core.mail', code: 'x', message: 'm', key: 'slug-b' });
57
+
58
+ const [a] = deps.prisma.system_incident.upsert.mock.calls[0] as [any];
59
+ const [b] = deps.prisma.system_incident.upsert.mock.calls[1] as [any];
60
+ expect(a.where.fingerprint).not.toBe(b.where.fingerprint);
61
+ });
62
+
63
+ it('reabre um incidente que voltou a acontecer', async () => {
64
+ const deps = makeDeps();
65
+ await makeService(deps).persist({ source: 's', code: 'c', message: 'm' });
66
+
67
+ const [args] = deps.prisma.system_incident.upsert.mock.calls[0] as [any];
68
+ expect(args.update.resolved_at).toBeNull();
69
+ expect(args.update.resolved_by).toBeNull();
70
+ });
71
+
72
+ it('ignora registro sem source ou code', async () => {
73
+ const deps = makeDeps();
74
+ const service = makeService(deps);
75
+
76
+ await service.persist({ source: '', code: 'c', message: 'm' });
77
+ await service.persist({ source: 's', code: ' ', message: 'm' });
78
+
79
+ expect(deps.prisma.system_incident.upsert).not.toHaveBeenCalled();
80
+ });
81
+
82
+ it('trunca mensagem gigante para não inchar a tabela', async () => {
83
+ const deps = makeDeps();
84
+ await makeService(deps).persist({ source: 's', code: 'c', message: 'x'.repeat(5000) });
85
+
86
+ const [args] = deps.prisma.system_incident.upsert.mock.calls[0] as [any];
87
+ expect(args.create.message.length).toBe(2000);
88
+ });
89
+ });
90
+
91
+ describe('IncidentService.record', () => {
92
+ beforeEach(() => jest.clearAllMocks());
93
+
94
+ it('nunca lança — o remédio não pode virar a doença', async () => {
95
+ const deps = makeDeps();
96
+ deps.prisma.system_incident.upsert = jest.fn(async () => {
97
+ throw new Error('banco fora do ar');
98
+ });
99
+
100
+ expect(() => makeService(deps).record({ source: 's', code: 'c', message: 'm' })).not.toThrow();
101
+ // Deixa o rejection assíncrono resolver antes do teste terminar.
102
+ await new Promise((resolve) => setImmediate(resolve));
103
+ });
104
+ });
105
+
106
+ describe('IncidentService.list', () => {
107
+ beforeEach(() => jest.clearAllMocks());
108
+
109
+ it('mostra só os abertos por padrão — a tela existe para o que pede ação', async () => {
110
+ const deps = makeDeps();
111
+ await makeService(deps).list({});
112
+
113
+ const [, , options] = deps.pagination.paginate.mock.calls[0] as [any, any, any];
114
+ expect(options.where.resolved_at).toBeNull();
115
+ expect(options.orderBy).toEqual({ last_seen_at: 'desc' });
116
+ });
117
+
118
+ it('filtra por resolvidos e por todos', async () => {
119
+ const deps = makeDeps();
120
+ const service = makeService(deps);
121
+
122
+ await service.list({ status: 'resolved' });
123
+ await service.list({ status: 'all' });
124
+
125
+ const [, , resolvidos] = deps.pagination.paginate.mock.calls[0] as [any, any, any];
126
+ const [, , todos] = deps.pagination.paginate.mock.calls[1] as [any, any, any];
127
+ expect(resolvidos.where.resolved_at).toEqual({ not: null });
128
+ expect(todos.where.resolved_at).toBeUndefined();
129
+ });
130
+
131
+ it('busca por mensagem, código e origem', async () => {
132
+ const deps = makeDeps();
133
+ await makeService(deps).list({ search: 'smtp' });
134
+
135
+ const [, , options] = deps.pagination.paginate.mock.calls[0] as [any, any, any];
136
+ expect(options.where.OR).toHaveLength(3);
137
+ });
138
+ });
139
+
140
+ describe('IncidentService.resolve', () => {
141
+ it('registra quem resolveu', async () => {
142
+ const deps = makeDeps();
143
+ await makeService(deps).resolve(7, 42);
144
+
145
+ const [args] = deps.prisma.system_incident.update.mock.calls[0] as [any];
146
+ expect(args.where).toEqual({ id: 7 });
147
+ expect(args.data.resolved_by).toBe(42);
148
+ expect(args.data.resolved_at).toBeInstanceOf(Date);
149
+ });
150
+ });
@@ -0,0 +1,209 @@
1
+ import { PageOrderDirection, PaginationService } from '@hed-hog/api-pagination';
2
+ import { PrismaService } from '@hed-hog/api-prisma';
3
+ import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common';
4
+ import { createHash } from 'crypto';
5
+ import { IncidentNotifierService } from './incident-notifier.service';
6
+
7
+ export type IncidentSeverity = 'warning' | 'error' | 'critical';
8
+
9
+ export interface RecordIncidentInput {
10
+ /** `<modulo>.<area>`, ex.: `core.mail`, `legacy.reconcile`. */
11
+ source: string;
12
+ /** Identificador estável da falha, ex.: `mail_send_failed`. */
13
+ code: string;
14
+ message: string;
15
+ severity?: IncidentSeverity;
16
+ /**
17
+ * Torna o incidente distinto dentro de `(source, code)`. Use algo estável e
18
+ * de baixa cardinalidade — o slug do template, o id do provider. **Nunca** um
19
+ * id de usuário ou timestamp: viraria uma linha por ocorrência, que é
20
+ * exatamente o que esta tabela existe para evitar.
21
+ */
22
+ key?: string;
23
+ context?: Record<string, unknown>;
24
+ }
25
+
26
+ export interface IncidentListParams {
27
+ page?: number;
28
+ pageSize?: number;
29
+ search?: string;
30
+ sortField?: string;
31
+ sortOrder?: PageOrderDirection;
32
+ fields?: string;
33
+ source?: string;
34
+ severity?: IncidentSeverity;
35
+ status?: 'open' | 'resolved' | 'all';
36
+ }
37
+
38
+ const MAX_MESSAGE_LENGTH = 2000;
39
+
40
+ /**
41
+ * Registro central das falhas que hoje somem em `.catch(() => null)` e
42
+ * `logger.error`.
43
+ *
44
+ * Não substitui a fila: job que falha já tem `queue_job_event` com timeline. O
45
+ * alvo aqui são os caminhos fire-and-forget, onde ninguém fica sabendo.
46
+ */
47
+ @Injectable()
48
+ export class IncidentService {
49
+ private readonly logger = new Logger(IncidentService.name);
50
+
51
+ constructor(
52
+ @Inject(forwardRef(() => PrismaService))
53
+ private readonly prisma: PrismaService,
54
+ @Inject(forwardRef(() => PaginationService))
55
+ private readonly pagination: PaginationService,
56
+ @Inject(forwardRef(() => IncidentNotifierService))
57
+ private readonly notifier: IncidentNotifierService,
58
+ ) {}
59
+
60
+ /**
61
+ * Nunca lança e nunca bloqueia quem chamou — o remédio não pode virar a
62
+ * doença. Registrar um incidente jamais pode derrubar o fluxo que já estava
63
+ * degradado.
64
+ */
65
+ record(input: RecordIncidentInput): void {
66
+ void this.persist(input).catch((error) => {
67
+ const message = error instanceof Error ? error.message : String(error);
68
+ this.logger.warn(`Falha ao registrar incidente ${input.source}/${input.code}: ${message}`);
69
+ });
70
+ }
71
+
72
+ /** Versão aguardável, para quem precisa garantir a gravação (testes, jobs). */
73
+ async persist(input: RecordIncidentInput): Promise<void> {
74
+ const source = String(input.source ?? '').trim().slice(0, 120);
75
+ const code = String(input.code ?? '').trim().slice(0, 120);
76
+
77
+ if (!source || !code) return;
78
+
79
+ const fingerprint = createHash('sha256')
80
+ .update(`${source}|${code}|${input.key ?? ''}`)
81
+ .digest('hex');
82
+
83
+ const now = new Date();
84
+ const message = String(input.message ?? '').slice(0, MAX_MESSAGE_LENGTH);
85
+
86
+ // Lido antes do upsert só para saber se é novo ou reabertura — é o que
87
+ // decide se vale um aviso. Repetição pura não avisa.
88
+ const existing = await (this.prisma as any).system_incident.findUnique({
89
+ where: { fingerprint },
90
+ select: { id: true, resolved_at: true, notified_at: true },
91
+ });
92
+
93
+ const incident = await (this.prisma as any).system_incident.upsert({
94
+ where: { fingerprint },
95
+ // Repetição vira contador, não linha nova. `resolved_at: null` reabre um
96
+ // incidente que alguém já tinha dado como resolvido e voltou a acontecer.
97
+ update: {
98
+ occurrences: { increment: 1 },
99
+ last_seen_at: now,
100
+ message,
101
+ context: (input.context ?? undefined) as any,
102
+ severity: input.severity ?? 'error',
103
+ resolved_at: null,
104
+ resolved_by: null,
105
+ updated_at: now,
106
+ },
107
+ create: {
108
+ source,
109
+ code,
110
+ severity: input.severity ?? 'error',
111
+ message,
112
+ context: (input.context ?? undefined) as any,
113
+ fingerprint,
114
+ occurrences: 1,
115
+ first_seen_at: now,
116
+ last_seen_at: now,
117
+ },
118
+ select: { id: true, occurrences: true },
119
+ });
120
+
121
+ const reason = !existing ? 'created' : existing.resolved_at ? 'reopened' : null;
122
+
123
+ if (!reason) return;
124
+
125
+ await this.notifier.notify({
126
+ id: incident.id,
127
+ source,
128
+ code,
129
+ severity: input.severity ?? 'error',
130
+ message,
131
+ occurrences: incident.occurrences,
132
+ context: input.context ?? null,
133
+ notifiedAt: existing?.notified_at ?? null,
134
+ reason,
135
+ });
136
+ }
137
+
138
+ async list(params: IncidentListParams) {
139
+ const where: Record<string, unknown> = {};
140
+
141
+ if (params.source) where.source = params.source;
142
+ if (params.severity) where.severity = params.severity;
143
+
144
+ // Aberto é o default: a tela existe para mostrar o que precisa de ação.
145
+ if (params.status !== 'all') {
146
+ where.resolved_at = params.status === 'resolved' ? { not: null } : null;
147
+ }
148
+
149
+ if (params.search) {
150
+ where.OR = [
151
+ { message: { contains: params.search, mode: 'insensitive' } },
152
+ { code: { contains: params.search, mode: 'insensitive' } },
153
+ { source: { contains: params.search, mode: 'insensitive' } },
154
+ ];
155
+ }
156
+
157
+ return this.pagination.paginate(
158
+ (this.prisma as any).system_incident,
159
+ { ...params, fields: params.fields ?? '' },
160
+ { where, orderBy: { last_seen_at: 'desc' } },
161
+ );
162
+ }
163
+
164
+ /** Contadores da barra de KPI e das abas de filtro. */
165
+ async summary() {
166
+ const [open, resolved, bySeverity, bySource] = await Promise.all([
167
+ (this.prisma as any).system_incident.count({ where: { resolved_at: null } }),
168
+ (this.prisma as any).system_incident.count({ where: { resolved_at: { not: null } } }),
169
+ (this.prisma as any).system_incident.groupBy({
170
+ by: ['severity'],
171
+ where: { resolved_at: null },
172
+ _count: { _all: true },
173
+ _sum: { occurrences: true },
174
+ }),
175
+ (this.prisma as any).system_incident.groupBy({
176
+ by: ['source'],
177
+ where: { resolved_at: null },
178
+ _count: { _all: true },
179
+ orderBy: { _count: { source: 'desc' } },
180
+ take: 20,
181
+ }),
182
+ ]);
183
+
184
+ return {
185
+ open,
186
+ resolved,
187
+ bySeverity: bySeverity.map((row: any) => ({
188
+ severity: row.severity,
189
+ incidents: row._count._all,
190
+ occurrences: Number(row._sum?.occurrences ?? 0),
191
+ })),
192
+ bySource: bySource.map((row: any) => ({ source: row.source, incidents: row._count._all })),
193
+ };
194
+ }
195
+
196
+ async resolve(id: number, userId?: number) {
197
+ return (this.prisma as any).system_incident.update({
198
+ where: { id },
199
+ data: { resolved_at: new Date(), resolved_by: userId ?? null, updated_at: new Date() },
200
+ });
201
+ }
202
+
203
+ async reopen(id: number) {
204
+ return (this.prisma as any).system_incident.update({
205
+ where: { id },
206
+ data: { resolved_at: null, resolved_by: null, updated_at: new Date() },
207
+ });
208
+ }
209
+ }