@hed-hog/core 0.0.356 → 0.0.359

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 (250) hide show
  1. package/dist/auth/guards/auth.guard.d.ts +6 -1
  2. package/dist/auth/guards/auth.guard.d.ts.map +1 -1
  3. package/dist/auth/guards/auth.guard.js +33 -2
  4. package/dist/auth/guards/auth.guard.js.map +1 -1
  5. package/dist/file/file.controller.d.ts +4 -2
  6. package/dist/file/file.controller.d.ts.map +1 -1
  7. package/dist/file/file.controller.js +44 -38
  8. package/dist/file/file.controller.js.map +1 -1
  9. package/dist/file/file.service.d.ts +2 -2
  10. package/dist/file/file.service.d.ts.map +1 -1
  11. package/dist/file/file.service.js +25 -42
  12. package/dist/file/file.service.js.map +1 -1
  13. package/dist/file/provider/azure.provider.d.ts.map +1 -1
  14. package/dist/file/provider/azure.provider.js +10 -15
  15. package/dist/file/provider/azure.provider.js.map +1 -1
  16. package/dist/file/provider/gcs.provider.d.ts.map +1 -1
  17. package/dist/file/provider/gcs.provider.js +8 -9
  18. package/dist/file/provider/gcs.provider.js.map +1 -1
  19. package/dist/file/provider/local.provider.d.ts.map +1 -1
  20. package/dist/file/provider/local.provider.js +11 -10
  21. package/dist/file/provider/local.provider.js.map +1 -1
  22. package/dist/file/provider/provider.factory.d.ts +1 -1
  23. package/dist/file/provider/provider.factory.d.ts.map +1 -1
  24. package/dist/file/provider/provider.factory.js +16 -6
  25. package/dist/file/provider/provider.factory.js.map +1 -1
  26. package/dist/file/provider/s3.provider.d.ts.map +1 -1
  27. package/dist/file/provider/s3.provider.js +4 -20
  28. package/dist/file/provider/s3.provider.js.map +1 -1
  29. package/dist/file/provider/spaces.provider.d.ts.map +1 -1
  30. package/dist/file/provider/spaces.provider.js +4 -19
  31. package/dist/file/provider/spaces.provider.js.map +1 -1
  32. package/dist/integration-profile/integration-profile.controller.d.ts +1 -1
  33. package/dist/integration-profile/integration-profile.controller.d.ts.map +1 -1
  34. package/dist/integration-profile/integration-profile.controller.js +4 -3
  35. package/dist/integration-profile/integration-profile.controller.js.map +1 -1
  36. package/dist/integration-profile/integration-profile.service.d.ts +1 -1
  37. package/dist/integration-profile/integration-profile.service.d.ts.map +1 -1
  38. package/dist/integration-profile/integration-profile.service.js +7 -4
  39. package/dist/integration-profile/integration-profile.service.js.map +1 -1
  40. package/dist/integration-profile/integration-profile.utils.d.ts +6 -0
  41. package/dist/integration-profile/integration-profile.utils.d.ts.map +1 -1
  42. package/dist/integration-profile/integration-profile.utils.js +9 -0
  43. package/dist/integration-profile/integration-profile.utils.js.map +1 -1
  44. package/dist/mail/mail.module.d.ts.map +1 -1
  45. package/dist/mail/mail.module.js +9 -4
  46. package/dist/mail/mail.module.js.map +1 -1
  47. package/dist/mail/mail.service.d.ts +2 -1
  48. package/dist/mail/mail.service.d.ts.map +1 -1
  49. package/dist/mail/mail.service.js +11 -7
  50. package/dist/mail/mail.service.js.map +1 -1
  51. package/dist/mcp/guards/mcp-auth.guard.js +1 -1
  52. package/dist/mcp/guards/mcp-auth.guard.js.map +1 -1
  53. package/dist/mcp/mcp-api-key.controller.d.ts +2 -0
  54. package/dist/mcp/mcp-api-key.controller.d.ts.map +1 -1
  55. package/dist/mcp/mcp-api-key.controller.js +1 -1
  56. package/dist/mcp/mcp-api-key.controller.js.map +1 -1
  57. package/dist/mcp/mcp-api-key.service.d.ts +2 -1
  58. package/dist/mcp/mcp-api-key.service.d.ts.map +1 -1
  59. package/dist/mcp/mcp-api-key.service.js +6 -2
  60. package/dist/mcp/mcp-api-key.service.js.map +1 -1
  61. package/dist/mcp/mcp.module.d.ts.map +1 -1
  62. package/dist/mcp/mcp.module.js +1 -3
  63. package/dist/mcp/mcp.module.js.map +1 -1
  64. package/dist/oauth/interfaces/OAuthProvider.d.ts +1 -1
  65. package/dist/oauth/interfaces/OAuthProvider.d.ts.map +1 -1
  66. package/dist/oauth/oauth.controller.d.ts +4 -1
  67. package/dist/oauth/oauth.controller.d.ts.map +1 -1
  68. package/dist/oauth/oauth.controller.js +31 -5
  69. package/dist/oauth/oauth.controller.js.map +1 -1
  70. package/dist/oauth/oauth.service.d.ts +12 -1
  71. package/dist/oauth/oauth.service.d.ts.map +1 -1
  72. package/dist/oauth/oauth.service.js +125 -23
  73. package/dist/oauth/oauth.service.js.map +1 -1
  74. package/dist/oauth/providers/abstract.provider.d.ts +1 -1
  75. package/dist/oauth/providers/abstract.provider.d.ts.map +1 -1
  76. package/dist/oauth/providers/facebook.provider.d.ts +5 -2
  77. package/dist/oauth/providers/facebook.provider.d.ts.map +1 -1
  78. package/dist/oauth/providers/facebook.provider.js +34 -19
  79. package/dist/oauth/providers/facebook.provider.js.map +1 -1
  80. package/dist/oauth/providers/github.provider.d.ts +6 -2
  81. package/dist/oauth/providers/github.provider.d.ts.map +1 -1
  82. package/dist/oauth/providers/github.provider.js +43 -20
  83. package/dist/oauth/providers/github.provider.js.map +1 -1
  84. package/dist/oauth/providers/google.provider.d.ts +5 -2
  85. package/dist/oauth/providers/google.provider.d.ts.map +1 -1
  86. package/dist/oauth/providers/google.provider.js +34 -19
  87. package/dist/oauth/providers/google.provider.js.map +1 -1
  88. package/dist/oauth/providers/microsoft-entra-id.provider.d.ts +5 -2
  89. package/dist/oauth/providers/microsoft-entra-id.provider.d.ts.map +1 -1
  90. package/dist/oauth/providers/microsoft-entra-id.provider.js +43 -40
  91. package/dist/oauth/providers/microsoft-entra-id.provider.js.map +1 -1
  92. package/dist/oauth/providers/microsoft.provider.d.ts +5 -2
  93. package/dist/oauth/providers/microsoft.provider.d.ts.map +1 -1
  94. package/dist/oauth/providers/microsoft.provider.js +34 -19
  95. package/dist/oauth/providers/microsoft.provider.js.map +1 -1
  96. package/dist/profile/profile.controller.js +1 -1
  97. package/dist/profile/profile.controller.js.map +1 -1
  98. package/dist/security/security.service.d.ts +2 -0
  99. package/dist/security/security.service.d.ts.map +1 -1
  100. package/dist/security/security.service.js +21 -0
  101. package/dist/security/security.service.js.map +1 -1
  102. package/dist/setting/setting.service.d.ts +26 -1
  103. package/dist/setting/setting.service.d.ts.map +1 -1
  104. package/dist/setting/setting.service.js +240 -5
  105. package/dist/setting/setting.service.js.map +1 -1
  106. package/dist/user/user.controller.d.ts +2 -1
  107. package/dist/user/user.controller.d.ts.map +1 -1
  108. package/dist/user/user.controller.js +5 -4
  109. package/dist/user/user.controller.js.map +1 -1
  110. package/dist/user/user.service.d.ts +4 -2
  111. package/dist/user/user.service.d.ts.map +1 -1
  112. package/dist/user/user.service.js +19 -4
  113. package/dist/user/user.service.js.map +1 -1
  114. package/dist/webhook-integration/dto/webhook-action.dto.d.ts +17 -2
  115. package/dist/webhook-integration/dto/webhook-action.dto.d.ts.map +1 -1
  116. package/dist/webhook-integration/dto/webhook-action.dto.js +93 -2
  117. package/dist/webhook-integration/dto/webhook-action.dto.js.map +1 -1
  118. package/dist/webhook-integration/webhook-command.registry.d.ts +15 -0
  119. package/dist/webhook-integration/webhook-command.registry.d.ts.map +1 -0
  120. package/dist/webhook-integration/webhook-command.registry.js +36 -0
  121. package/dist/webhook-integration/webhook-command.registry.js.map +1 -0
  122. package/dist/webhook-integration/webhook-integration.controller.d.ts +19 -0
  123. package/dist/webhook-integration/webhook-integration.controller.d.ts.map +1 -1
  124. package/dist/webhook-integration/webhook-integration.controller.js +38 -0
  125. package/dist/webhook-integration/webhook-integration.controller.js.map +1 -1
  126. package/dist/webhook-integration/webhook-integration.module.d.ts.map +1 -1
  127. package/dist/webhook-integration/webhook-integration.module.js +5 -0
  128. package/dist/webhook-integration/webhook-integration.module.js.map +1 -1
  129. package/dist/webhook-integration/webhook-integration.service.d.ts +25 -1
  130. package/dist/webhook-integration/webhook-integration.service.d.ts.map +1 -1
  131. package/dist/webhook-integration/webhook-integration.service.js +332 -23
  132. package/dist/webhook-integration/webhook-integration.service.js.map +1 -1
  133. package/hedhog/data/integration_provider.yaml +16 -0
  134. package/hedhog/data/menu.yaml +0 -16
  135. package/hedhog/data/route.yaml +32 -383
  136. package/hedhog/data/setting_group.yaml +179 -174
  137. package/hedhog/data/setting_subgroup.yaml +16 -0
  138. package/hedhog/frontend/app/account/components/tokens.tsx.ejs +421 -0
  139. package/hedhog/frontend/app/account/layout.tsx.ejs +6 -3
  140. package/hedhog/frontend/app/account/mcp-tokens/page.tsx.ejs +2 -2
  141. package/hedhog/frontend/app/account/tokens/page.tsx.ejs +5 -0
  142. package/hedhog/frontend/app/configurations/[slug]/components/setting-field.tsx.ejs +414 -76
  143. package/hedhog/frontend/app/configurations/layout.tsx.ejs +1 -1
  144. package/hedhog/frontend/app/dashboard/dashboard-home-tabs.tsx.ejs +3 -1
  145. package/hedhog/frontend/app/integration/profiles/page.tsx.ejs +186 -18
  146. package/hedhog/frontend/app/integrations-webhooks/page.tsx.ejs +597 -21
  147. package/hedhog/frontend/app/mail/profiles/page.tsx.ejs +2 -2
  148. package/hedhog/frontend/app/setting-list/page.tsx.ejs +229 -395
  149. package/hedhog/frontend/messages/en.json +67 -3
  150. package/hedhog/frontend/messages/pt.json +67 -3
  151. package/hedhog/table/file.yaml +1 -1
  152. package/hedhog/table/mcp_api_key.yaml +4 -0
  153. package/hedhog/table/webhook_action.yaml +57 -1
  154. package/package.json +5 -4
  155. package/src/auth/guards/auth.guard.ts +32 -0
  156. package/src/file/file.controller.ts +51 -42
  157. package/src/file/file.service.ts +31 -52
  158. package/src/file/provider/azure.provider.ts +14 -28
  159. package/src/file/provider/gcs.provider.ts +9 -9
  160. package/src/file/provider/local.provider.ts +10 -13
  161. package/src/file/provider/provider.factory.ts +19 -7
  162. package/src/file/provider/s3.provider.ts +4 -20
  163. package/src/file/provider/spaces.provider.ts +4 -19
  164. package/src/integration-profile/integration-profile.controller.ts +2 -0
  165. package/src/integration-profile/integration-profile.service.ts +7 -2
  166. package/src/integration-profile/integration-profile.utils.ts +17 -0
  167. package/src/mail/mail.module.ts +14 -4
  168. package/src/mail/mail.service.ts +12 -7
  169. package/src/mcp/guards/mcp-auth.guard.ts +1 -1
  170. package/src/mcp/mcp-api-key.controller.ts +2 -2
  171. package/src/mcp/mcp-api-key.service.ts +6 -2
  172. package/src/mcp/mcp.module.ts +1 -3
  173. package/src/oauth/interfaces/OAuthProvider.ts +1 -1
  174. package/src/oauth/oauth.controller.ts +30 -2
  175. package/src/oauth/oauth.service.ts +194 -35
  176. package/src/oauth/providers/abstract.provider.ts +1 -1
  177. package/src/oauth/providers/facebook.provider.ts +36 -20
  178. package/src/oauth/providers/github.provider.ts +46 -23
  179. package/src/oauth/providers/google.provider.ts +36 -20
  180. package/src/oauth/providers/microsoft-entra-id.provider.ts +42 -46
  181. package/src/oauth/providers/microsoft.provider.ts +36 -21
  182. package/src/profile/profile.controller.ts +2 -2
  183. package/src/security/security.service.ts +34 -1
  184. package/src/setting/setting.service.ts +307 -7
  185. package/src/user/user.controller.ts +4 -1
  186. package/src/user/user.service.ts +20 -2
  187. package/src/webhook-integration/dto/webhook-action.dto.ts +85 -4
  188. package/src/webhook-integration/webhook-command.registry.ts +42 -0
  189. package/src/webhook-integration/webhook-integration.controller.ts +20 -0
  190. package/src/webhook-integration/webhook-integration.module.ts +50 -45
  191. package/src/webhook-integration/webhook-integration.service.ts +374 -11
  192. package/dist/mail-profile/dto/create.dto.d.ts +0 -23
  193. package/dist/mail-profile/dto/create.dto.d.ts.map +0 -1
  194. package/dist/mail-profile/dto/create.dto.js +0 -139
  195. package/dist/mail-profile/dto/create.dto.js.map +0 -1
  196. package/dist/mail-profile/dto/update.dto.d.ts +0 -6
  197. package/dist/mail-profile/dto/update.dto.d.ts.map +0 -1
  198. package/dist/mail-profile/dto/update.dto.js +0 -9
  199. package/dist/mail-profile/dto/update.dto.js.map +0 -1
  200. package/dist/mail-profile/mail-profile.controller.d.ts +0 -94
  201. package/dist/mail-profile/mail-profile.controller.d.ts.map +0 -1
  202. package/dist/mail-profile/mail-profile.controller.js +0 -95
  203. package/dist/mail-profile/mail-profile.controller.js.map +0 -1
  204. package/dist/mail-profile/mail-profile.module.d.ts +0 -3
  205. package/dist/mail-profile/mail-profile.module.d.ts.map +0 -1
  206. package/dist/mail-profile/mail-profile.module.js +0 -31
  207. package/dist/mail-profile/mail-profile.module.js.map +0 -1
  208. package/dist/mail-profile/mail-profile.service.d.ts +0 -109
  209. package/dist/mail-profile/mail-profile.service.d.ts.map +0 -1
  210. package/dist/mail-profile/mail-profile.service.js +0 -278
  211. package/dist/mail-profile/mail-profile.service.js.map +0 -1
  212. package/dist/mcp/tools/core-mail-profile.mcp-tools.d.ts +0 -20
  213. package/dist/mcp/tools/core-mail-profile.mcp-tools.d.ts.map +0 -1
  214. package/dist/mcp/tools/core-mail-profile.mcp-tools.js +0 -96
  215. package/dist/mcp/tools/core-mail-profile.mcp-tools.js.map +0 -1
  216. package/dist/whatsapp-profile/dto/create.dto.d.ts +0 -11
  217. package/dist/whatsapp-profile/dto/create.dto.d.ts.map +0 -1
  218. package/dist/whatsapp-profile/dto/create.dto.js +0 -55
  219. package/dist/whatsapp-profile/dto/create.dto.js.map +0 -1
  220. package/dist/whatsapp-profile/dto/update.dto.d.ts +0 -6
  221. package/dist/whatsapp-profile/dto/update.dto.d.ts.map +0 -1
  222. package/dist/whatsapp-profile/dto/update.dto.js +0 -9
  223. package/dist/whatsapp-profile/dto/update.dto.js.map +0 -1
  224. package/dist/whatsapp-profile/whatsapp-profile.controller.d.ts +0 -54
  225. package/dist/whatsapp-profile/whatsapp-profile.controller.d.ts.map +0 -1
  226. package/dist/whatsapp-profile/whatsapp-profile.controller.js +0 -85
  227. package/dist/whatsapp-profile/whatsapp-profile.controller.js.map +0 -1
  228. package/dist/whatsapp-profile/whatsapp-profile.module.d.ts +0 -3
  229. package/dist/whatsapp-profile/whatsapp-profile.module.d.ts.map +0 -1
  230. package/dist/whatsapp-profile/whatsapp-profile.module.js +0 -26
  231. package/dist/whatsapp-profile/whatsapp-profile.module.js.map +0 -1
  232. package/dist/whatsapp-profile/whatsapp-profile.service.d.ts +0 -63
  233. package/dist/whatsapp-profile/whatsapp-profile.service.d.ts.map +0 -1
  234. package/dist/whatsapp-profile/whatsapp-profile.service.js +0 -138
  235. package/dist/whatsapp-profile/whatsapp-profile.service.js.map +0 -1
  236. package/hedhog/data/mail_profile.yaml +0 -18
  237. package/hedhog/data/whatsapp_profile.yaml +0 -6
  238. package/hedhog/table/mail_profile.yaml +0 -75
  239. package/hedhog/table/whatsapp_profile.yaml +0 -26
  240. package/src/mail-profile/dto/create.dto.ts +0 -145
  241. package/src/mail-profile/dto/update.dto.ts +0 -4
  242. package/src/mail-profile/mail-profile.controller.ts +0 -56
  243. package/src/mail-profile/mail-profile.module.ts +0 -18
  244. package/src/mail-profile/mail-profile.service.ts +0 -308
  245. package/src/mcp/tools/core-mail-profile.mcp-tools.ts +0 -69
  246. package/src/whatsapp-profile/dto/create.dto.ts +0 -36
  247. package/src/whatsapp-profile/dto/update.dto.ts +0 -4
  248. package/src/whatsapp-profile/whatsapp-profile.controller.ts +0 -51
  249. package/src/whatsapp-profile/whatsapp-profile.module.ts +0 -13
  250. package/src/whatsapp-profile/whatsapp-profile.service.ts +0 -160
@@ -1,56 +0,0 @@
1
- import { DeleteDTO, Role } from '@hed-hog/api';
2
- import { Pagination } from '@hed-hog/api-pagination';
3
- import {
4
- Body,
5
- Controller,
6
- Delete,
7
- Get,
8
- Inject,
9
- Param,
10
- ParseIntPipe,
11
- Patch,
12
- Post,
13
- forwardRef,
14
- } from '@nestjs/common';
15
- import { CreateDTO } from './dto/create.dto';
16
- import { UpdateDTO } from './dto/update.dto';
17
- import { MailProfileService } from './mail-profile.service';
18
-
19
- @Role()
20
- @Controller('mail-profile')
21
- export class MailProfileController {
22
- constructor(
23
- @Inject(forwardRef(() => MailProfileService))
24
- private readonly mailProfileService: MailProfileService,
25
- ) {}
26
-
27
- @Get()
28
- async list(@Pagination() paginationParams) {
29
- return this.mailProfileService.list(paginationParams);
30
- }
31
-
32
- @Get(':id')
33
- async get(@Param('id', ParseIntPipe) id: number) {
34
- return this.mailProfileService.get(id);
35
- }
36
-
37
- @Post()
38
- async create(@Body() data: CreateDTO) {
39
- return this.mailProfileService.create(data);
40
- }
41
-
42
- @Post('test')
43
- async test(@Body() data: CreateDTO) {
44
- return this.mailProfileService.test(data);
45
- }
46
-
47
- @Patch(':id')
48
- async update(@Param('id', ParseIntPipe) id: number, @Body() data: UpdateDTO) {
49
- return this.mailProfileService.update({ id, data });
50
- }
51
-
52
- @Delete()
53
- async delete(@Body() data: DeleteDTO) {
54
- return this.mailProfileService.delete(data);
55
- }
56
- }
@@ -1,18 +0,0 @@
1
- import { PaginationModule } from '@hed-hog/api-pagination';
2
- import { PrismaModule } from '@hed-hog/api-prisma';
3
- import { forwardRef, Module } from '@nestjs/common';
4
- import { MailModule } from '../mail/mail.module';
5
- import { MailProfileController } from './mail-profile.controller';
6
- import { MailProfileService } from './mail-profile.service';
7
-
8
- @Module({
9
- imports: [
10
- forwardRef(() => PrismaModule),
11
- forwardRef(() => PaginationModule),
12
- forwardRef(() => MailModule),
13
- ],
14
- controllers: [MailProfileController],
15
- providers: [MailProfileService],
16
- exports: [MailProfileService],
17
- })
18
- export class MailProfileModule {}
@@ -1,308 +0,0 @@
1
- import { DeleteDTO } from '@hed-hog/api';
2
- import { MailService as MailMainService } from '@hed-hog/api-mail';
3
- import { PaginationDTO, PaginationService } from '@hed-hog/api-pagination';
4
- import { PrismaService } from '@hed-hog/api-prisma';
5
- import {
6
- BadRequestException,
7
- Inject,
8
- Injectable,
9
- NotFoundException,
10
- forwardRef,
11
- } from '@nestjs/common';
12
- import { MailService } from '../mail/mail.service';
13
- import { CreateDTO } from './dto/create.dto';
14
- import { UpdateDTO } from './dto/update.dto';
15
-
16
- @Injectable()
17
- export class MailProfileService {
18
- constructor(
19
- @Inject(forwardRef(() => PrismaService))
20
- private readonly prismaService: PrismaService,
21
- @Inject(forwardRef(() => PaginationService))
22
- private readonly paginationService: PaginationService,
23
- @Inject(forwardRef(() => MailMainService))
24
- private readonly mailMainService: MailMainService,
25
- @Inject(forwardRef(() => MailService))
26
- private readonly mailService: MailService,
27
- ) {}
28
-
29
- async list(paginationParams: PaginationDTO) {
30
- const fields = ['slug', 'name', 'from_email', 'reply_to_email'];
31
- const OR = this.prismaService.createInsensitiveSearch(fields, paginationParams);
32
-
33
- return this.paginationService.paginate(
34
- this.prismaService.mail_profile,
35
- paginationParams,
36
- {
37
- where: OR.length > 0 ? { OR } : {},
38
- select: {
39
- id: true,
40
- slug: true,
41
- name: true,
42
- provider: true,
43
- from_name: true,
44
- from_email: true,
45
- reply_to_name: true,
46
- reply_to_email: true,
47
- created_at: true,
48
- updated_at: true,
49
- },
50
- orderBy: [{ updated_at: 'desc' }, { id: 'desc' }],
51
- },
52
- );
53
- }
54
-
55
- async get(id: number) {
56
- const profile = await this.prismaService.mail_profile.findUnique({
57
- where: { id },
58
- });
59
-
60
- if (!profile) {
61
- throw new NotFoundException(`Mail profile with id ${id} not found.`);
62
- }
63
-
64
- return profile;
65
- }
66
-
67
- async create(data: CreateDTO) {
68
- await this.ensureSlugIsAvailable(data.slug);
69
- this.validateProviderFields(data as unknown as Record<string, unknown>);
70
-
71
- return this.prismaService.mail_profile.create({
72
- data: this.normalizeData(data as unknown as Record<string, unknown>) as any,
73
- });
74
- }
75
-
76
- async update({ id, data }: { id: number; data: UpdateDTO }) {
77
- const existing = await this.prismaService.mail_profile.findUnique({
78
- where: { id },
79
- });
80
-
81
- if (!existing) {
82
- throw new NotFoundException(`Mail profile with id ${id} not found.`);
83
- }
84
-
85
- if (data.slug && data.slug !== existing.slug) {
86
- await this.ensureSlugIsAvailable(data.slug);
87
- }
88
-
89
- const merged = {
90
- ...existing,
91
- ...data,
92
- } satisfies Record<string, unknown>;
93
-
94
- this.validateProviderFields(merged);
95
-
96
- return this.prismaService.mail_profile.update({
97
- where: { id },
98
- data: this.normalizeData(merged) as any,
99
- });
100
- }
101
-
102
- async delete({ ids }: DeleteDTO): Promise<{ count: number }> {
103
- if (!ids?.length) {
104
- throw new BadRequestException('You must select at least one item to delete.');
105
- }
106
-
107
- return this.prismaService.mail_profile.deleteMany({
108
- where: {
109
- id: {
110
- in: ids,
111
- },
112
- },
113
- });
114
- }
115
-
116
- async test(data: CreateDTO) {
117
- this.validateProviderFields(data as unknown as Record<string, unknown>);
118
-
119
- const normalized = this.normalizeData(data as unknown as Record<string, unknown>);
120
- const config = this.buildMailConfig(normalized);
121
- const destinationEmail = normalized.from_email;
122
- const sender = normalized.from_name
123
- ? `${normalized.from_name} <${normalized.from_email}>`
124
- : normalized.from_email;
125
- const replyTo = normalized.reply_to_email
126
- ? normalized.reply_to_name
127
- ? `${normalized.reply_to_name} <${normalized.reply_to_email}>`
128
- : normalized.reply_to_email
129
- : undefined;
130
-
131
- try {
132
- this.mailMainService.setConfig(config);
133
-
134
- await this.mailMainService.send({
135
- to: destinationEmail,
136
- from: sender,
137
- replyTo,
138
- subject: `[HedHog] Teste do perfil ${normalized.name}`,
139
- body: `
140
- <p>Este e-mail confirma que o perfil <strong>${normalized.name}</strong> foi validado com sucesso.</p>
141
- <p><strong>Slug:</strong> ${normalized.slug}</p>
142
- <p><strong>Provedor:</strong> ${normalized.provider}</p>
143
- <p><strong>Remetente:</strong> ${sender}</p>
144
- `,
145
- });
146
-
147
- return {
148
- success: true,
149
- destination: destinationEmail,
150
- };
151
- } finally {
152
- await this.mailService.reloadConfig().catch(() => undefined);
153
- }
154
- }
155
-
156
- private async ensureSlugIsAvailable(slug: string) {
157
- const existing = await this.prismaService.mail_profile.findUnique({
158
- where: { slug },
159
- select: { id: true },
160
- });
161
-
162
- if (existing) {
163
- throw new BadRequestException(`Mail profile with slug "${slug}" already exists.`);
164
- }
165
- }
166
-
167
- private validateProviderFields(input: Record<string, unknown>) {
168
- const provider = String(input.provider ?? '').toUpperCase();
169
-
170
- if (!provider) {
171
- throw new BadRequestException('Provider is required.');
172
- }
173
-
174
- if (!String(input.from_email ?? '').trim()) {
175
- throw new BadRequestException('Sender email is required.');
176
- }
177
-
178
- switch (provider) {
179
- case 'SMTP':
180
- if (!String(input.smtp_host ?? '').trim()) {
181
- throw new BadRequestException('SMTP host is required.');
182
- }
183
- if (!input.smtp_port) {
184
- throw new BadRequestException('SMTP port is required.');
185
- }
186
- if (!String(input.smtp_username ?? '').trim()) {
187
- throw new BadRequestException('SMTP username is required.');
188
- }
189
- if (!String(input.smtp_password ?? '').trim()) {
190
- throw new BadRequestException('SMTP password is required.');
191
- }
192
- break;
193
- case 'GMAIL':
194
- if (!String(input.gmail_client_id ?? '').trim()) {
195
- throw new BadRequestException('Gmail client ID is required.');
196
- }
197
- if (!String(input.gmail_client_secret ?? '').trim()) {
198
- throw new BadRequestException('Gmail client secret is required.');
199
- }
200
- if (!String(input.gmail_refresh_token ?? '').trim()) {
201
- throw new BadRequestException('Gmail refresh token is required.');
202
- }
203
- break;
204
- case 'SES':
205
- if (!String(input.ses_access_key_id ?? '').trim()) {
206
- throw new BadRequestException('SES access key ID is required.');
207
- }
208
- if (!String(input.ses_secret_access_key ?? '').trim()) {
209
- throw new BadRequestException('SES secret access key is required.');
210
- }
211
- if (!String(input.ses_region ?? '').trim()) {
212
- throw new BadRequestException('SES region is required.');
213
- }
214
- break;
215
- default:
216
- throw new BadRequestException(`Invalid provider: ${provider}`);
217
- }
218
- }
219
-
220
- private normalizeData(input: Record<string, unknown>) {
221
- const provider = String(input.provider ?? '').toUpperCase();
222
-
223
- return {
224
- slug: this.normalizeString(input.slug),
225
- name: this.normalizeString(input.name),
226
- provider,
227
- from_name: this.normalizeNullableString(input.from_name),
228
- from_email: this.normalizeString(input.from_email),
229
- reply_to_name: this.normalizeNullableString(input.reply_to_name),
230
- reply_to_email: this.normalizeNullableString(input.reply_to_email),
231
- smtp_host: provider === 'SMTP' ? this.normalizeNullableString(input.smtp_host) : null,
232
- smtp_port:
233
- provider === 'SMTP' && input.smtp_port !== undefined && input.smtp_port !== null
234
- ? Number(input.smtp_port)
235
- : null,
236
- smtp_secure: provider === 'SMTP' ? Boolean(input.smtp_secure) : false,
237
- smtp_username:
238
- provider === 'SMTP' ? this.normalizeNullableString(input.smtp_username) : null,
239
- smtp_password:
240
- provider === 'SMTP' ? this.normalizeNullableString(input.smtp_password) : null,
241
- gmail_client_id:
242
- provider === 'GMAIL' ? this.normalizeNullableString(input.gmail_client_id) : null,
243
- gmail_client_secret:
244
- provider === 'GMAIL'
245
- ? this.normalizeNullableString(input.gmail_client_secret)
246
- : null,
247
- gmail_refresh_token:
248
- provider === 'GMAIL'
249
- ? this.normalizeNullableString(input.gmail_refresh_token)
250
- : null,
251
- ses_access_key_id:
252
- provider === 'SES' ? this.normalizeNullableString(input.ses_access_key_id) : null,
253
- ses_secret_access_key:
254
- provider === 'SES'
255
- ? this.normalizeNullableString(input.ses_secret_access_key)
256
- : null,
257
- ses_region: provider === 'SES' ? this.normalizeNullableString(input.ses_region) : null,
258
- };
259
- }
260
-
261
- private buildMailConfig(input: ReturnType<MailProfileService['normalizeData']>) {
262
- switch (input.provider) {
263
- case 'SMTP':
264
- return {
265
- global: true,
266
- type: 'SMTP' as const,
267
- host: input.smtp_host ?? '',
268
- port: input.smtp_port ?? 587,
269
- secure: input.smtp_secure,
270
- username: input.smtp_username ?? '',
271
- password: input.smtp_password ?? '',
272
- };
273
- case 'GMAIL':
274
- return {
275
- global: true,
276
- type: 'GMAIL' as const,
277
- clientId: input.gmail_client_id ?? '',
278
- clientSecret: input.gmail_client_secret ?? '',
279
- refreshToken: input.gmail_refresh_token ?? '',
280
- from: input.from_email,
281
- };
282
- case 'SES':
283
- return {
284
- global: true,
285
- type: 'SES' as const,
286
- region: input.ses_region ?? '',
287
- accessKeyId: input.ses_access_key_id ?? '',
288
- secretAccessKey: input.ses_secret_access_key ?? '',
289
- from: input.from_email,
290
- };
291
- default:
292
- throw new BadRequestException(`Invalid provider: ${input.provider}`);
293
- }
294
- }
295
-
296
- private normalizeString(value: unknown) {
297
- return String(value ?? '').trim();
298
- }
299
-
300
- private normalizeNullableString(value: unknown) {
301
- if (value === undefined || value === null) {
302
- return null;
303
- }
304
-
305
- const normalized = String(value).trim();
306
- return normalized.length > 0 ? normalized : null;
307
- }
308
- }
@@ -1,69 +0,0 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { IntegrationProfileService } from '../../integration-profile/integration-profile.service';
3
- import { McpTool } from '../decorators/mcp-tool.decorator';
4
- import { McpContext } from '../types/mcp-context.type';
5
-
6
- @Injectable()
7
- export class CoreMailProfileMcpTools {
8
- constructor(private readonly integrationProfileService: IntegrationProfileService) {}
9
-
10
- @McpTool({
11
- name: 'core.mail-profile.list',
12
- description: 'Lists integration profiles with optional pagination. Admin only.',
13
- inputSchema: {
14
- type: 'object',
15
- properties: {
16
- page: { type: 'number', description: 'Page number (default: 1)' },
17
- pageSize: { type: 'number', description: 'Items per page (default: 20)' },
18
- search: { type: 'string', description: 'Search term' },
19
- sortField: { type: 'string', description: 'Field to sort by' },
20
- sortOrder: { type: 'string', enum: ['asc', 'desc'], description: 'Sort direction' },
21
- },
22
- },
23
- readOnly: true,
24
- })
25
- async listMailProfiles(
26
- args: { page?: number; pageSize?: number; search?: string; sortField?: string; sortOrder?: string },
27
- _context: McpContext,
28
- ): Promise<any> {
29
- return this.integrationProfileService.list({
30
- page: args.page ?? 1,
31
- pageSize: args.pageSize ?? 20,
32
- search: args.search ?? '',
33
- sortField: args.sortField ?? 'id',
34
- sortOrder: (args.sortOrder as any) ?? 'asc',
35
- fields: '',
36
- });
37
- }
38
-
39
- @McpTool({
40
- name: 'core.mail-profile.get',
41
- description: 'Returns a single integration profile by ID. Admin only.',
42
- inputSchema: {
43
- type: 'object',
44
- properties: {
45
- id: { type: 'number', description: 'Profile ID' },
46
- },
47
- required: ['id'],
48
- },
49
- readOnly: true,
50
- })
51
- async getMailProfile(args: { id: number }, _context: McpContext): Promise<any> {
52
- return this.integrationProfileService.get(args.id);
53
- }
54
-
55
- @McpTool({
56
- name: 'core.mail-profile.delete',
57
- description: 'Deletes one or more integration profiles by their IDs. Admin only.',
58
- inputSchema: {
59
- type: 'object',
60
- properties: {
61
- ids: { type: 'array', items: { type: 'number' }, description: 'Profile IDs to delete' },
62
- },
63
- required: ['ids'],
64
- },
65
- })
66
- async deleteMailProfiles(args: { ids: number[] }, _context: McpContext): Promise<any> {
67
- return this.integrationProfileService.delete({ ids: args.ids });
68
- }
69
- }
@@ -1,36 +0,0 @@
1
- import { getLocaleText } from '@hed-hog/api-locale';
2
- import { Transform } from 'class-transformer';
3
- import { IsIn, IsString, MaxLength } from 'class-validator';
4
-
5
- const providerOptions = ['WHATSAPP_API'] as const;
6
-
7
- export class CreateDTO {
8
- @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
9
- @MaxLength(127)
10
- @Transform(({ value }) => String(value ?? '').trim())
11
- slug: string;
12
-
13
- @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
14
- @MaxLength(127)
15
- @Transform(({ value }) => String(value ?? '').trim())
16
- name: string;
17
-
18
- @IsIn(providerOptions)
19
- @Transform(({ value }) => String(value ?? '').trim().toUpperCase())
20
- provider: (typeof providerOptions)[number];
21
-
22
- @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
23
- @MaxLength(255)
24
- @Transform(({ value }) => String(value ?? '').trim())
25
- host: string;
26
-
27
- @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
28
- @MaxLength(255)
29
- @Transform(({ value }) => String(value ?? '').trim())
30
- token: string;
31
-
32
- @IsString({ message: (args) => getLocaleText('validation.stringRequired', args.value) })
33
- @MaxLength(127)
34
- @Transform(({ value }) => String(value ?? '').trim())
35
- instance_name: string;
36
- }
@@ -1,4 +0,0 @@
1
- import { PartialType } from '@nestjs/mapped-types';
2
- import { CreateDTO } from './create.dto';
3
-
4
- export class UpdateDTO extends PartialType(CreateDTO) {}
@@ -1,51 +0,0 @@
1
- import { DeleteDTO, Role } from '@hed-hog/api';
2
- import { Pagination } from '@hed-hog/api-pagination';
3
- import {
4
- Body,
5
- Controller,
6
- Delete,
7
- Get,
8
- Inject,
9
- Param,
10
- ParseIntPipe,
11
- Patch,
12
- Post,
13
- forwardRef,
14
- } from '@nestjs/common';
15
- import { CreateDTO } from './dto/create.dto';
16
- import { UpdateDTO } from './dto/update.dto';
17
- import { WhatsAppProfileService } from './whatsapp-profile.service';
18
-
19
- @Role()
20
- @Controller('whatsapp-profile')
21
- export class WhatsAppProfileController {
22
- constructor(
23
- @Inject(forwardRef(() => WhatsAppProfileService))
24
- private readonly whatsappProfileService: WhatsAppProfileService,
25
- ) {}
26
-
27
- @Get()
28
- async list(@Pagination() paginationParams) {
29
- return this.whatsappProfileService.list(paginationParams);
30
- }
31
-
32
- @Get(':id')
33
- async get(@Param('id', ParseIntPipe) id: number) {
34
- return this.whatsappProfileService.get(id);
35
- }
36
-
37
- @Post()
38
- async create(@Body() data: CreateDTO) {
39
- return this.whatsappProfileService.create(data);
40
- }
41
-
42
- @Patch(':id')
43
- async update(@Param('id', ParseIntPipe) id: number, @Body() data: UpdateDTO) {
44
- return this.whatsappProfileService.update({ id, data });
45
- }
46
-
47
- @Delete()
48
- async delete(@Body() data: DeleteDTO) {
49
- return this.whatsappProfileService.delete(data);
50
- }
51
- }
@@ -1,13 +0,0 @@
1
- import { PaginationModule } from '@hed-hog/api-pagination';
2
- import { PrismaModule } from '@hed-hog/api-prisma';
3
- import { forwardRef, Module } from '@nestjs/common';
4
- import { WhatsAppProfileController } from './whatsapp-profile.controller';
5
- import { WhatsAppProfileService } from './whatsapp-profile.service';
6
-
7
- @Module({
8
- imports: [forwardRef(() => PrismaModule), forwardRef(() => PaginationModule)],
9
- controllers: [WhatsAppProfileController],
10
- providers: [WhatsAppProfileService],
11
- exports: [WhatsAppProfileService],
12
- })
13
- export class WhatsAppProfileModule {}