@hed-hog/core 0.0.325 → 0.0.327

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 (100) hide show
  1. package/dist/core.module.d.ts.map +1 -1
  2. package/dist/core.module.js +3 -0
  3. package/dist/core.module.js.map +1 -1
  4. package/dist/index.d.ts +4 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +4 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/integration/services/outbox.processor.d.ts.map +1 -1
  9. package/dist/integration/services/outbox.processor.js +1 -0
  10. package/dist/integration/services/outbox.processor.js.map +1 -1
  11. package/dist/integration/types/event.types.d.ts +1 -0
  12. package/dist/integration/types/event.types.d.ts.map +1 -1
  13. package/dist/mail/mail.controller.d.ts +2 -0
  14. package/dist/mail/mail.controller.d.ts.map +1 -1
  15. package/dist/mail/mail.module.d.ts.map +1 -1
  16. package/dist/mail/mail.module.js +33 -53
  17. package/dist/mail/mail.module.js.map +1 -1
  18. package/dist/mail/mail.service.d.ts +5 -1
  19. package/dist/mail/mail.service.d.ts.map +1 -1
  20. package/dist/mail/mail.service.js +64 -84
  21. package/dist/mail/mail.service.js.map +1 -1
  22. package/dist/role/role.service.d.ts +3 -1
  23. package/dist/role/role.service.d.ts.map +1 -1
  24. package/dist/role/role.service.js +33 -5
  25. package/dist/role/role.service.js.map +1 -1
  26. package/dist/setting/setting.service.d.ts.map +1 -1
  27. package/dist/setting/setting.service.js +1 -0
  28. package/dist/setting/setting.service.js.map +1 -1
  29. package/dist/user/user.service.d.ts +3 -1
  30. package/dist/user/user.service.d.ts.map +1 -1
  31. package/dist/user/user.service.js +31 -4
  32. package/dist/user/user.service.js.map +1 -1
  33. package/dist/webhook-integration/event-webhook.controller.d.ts +29 -0
  34. package/dist/webhook-integration/event-webhook.controller.d.ts.map +1 -0
  35. package/dist/webhook-integration/event-webhook.controller.js +93 -0
  36. package/dist/webhook-integration/event-webhook.controller.js.map +1 -0
  37. package/dist/webhook-integration/event-webhook.service.d.ts +54 -0
  38. package/dist/webhook-integration/event-webhook.service.d.ts.map +1 -0
  39. package/dist/webhook-integration/event-webhook.service.js +334 -0
  40. package/dist/webhook-integration/event-webhook.service.js.map +1 -0
  41. package/dist/webhook-integration/integration-event-catalog.controller.d.ts +21 -0
  42. package/dist/webhook-integration/integration-event-catalog.controller.d.ts.map +1 -0
  43. package/dist/webhook-integration/integration-event-catalog.controller.js +91 -0
  44. package/dist/webhook-integration/integration-event-catalog.controller.js.map +1 -0
  45. package/dist/webhook-integration/integration-event-catalog.service.d.ts +26 -0
  46. package/dist/webhook-integration/integration-event-catalog.service.d.ts.map +1 -0
  47. package/dist/webhook-integration/integration-event-catalog.service.js +112 -0
  48. package/dist/webhook-integration/integration-event-catalog.service.js.map +1 -0
  49. package/dist/webhook-integration/webhook-integration.controller.d.ts +44 -0
  50. package/dist/webhook-integration/webhook-integration.controller.d.ts.map +1 -0
  51. package/dist/webhook-integration/webhook-integration.controller.js +181 -0
  52. package/dist/webhook-integration/webhook-integration.controller.js.map +1 -0
  53. package/dist/webhook-integration/webhook-integration.module.d.ts +3 -0
  54. package/dist/webhook-integration/webhook-integration.module.d.ts.map +1 -0
  55. package/dist/webhook-integration/webhook-integration.module.js +54 -0
  56. package/dist/webhook-integration/webhook-integration.module.js.map +1 -0
  57. package/dist/webhook-integration/webhook-integration.service.d.ts +73 -0
  58. package/dist/webhook-integration/webhook-integration.service.d.ts.map +1 -0
  59. package/dist/webhook-integration/webhook-integration.service.js +569 -0
  60. package/dist/webhook-integration/webhook-integration.service.js.map +1 -0
  61. package/dist/webhook-integration/webhook-utils.d.ts +7 -0
  62. package/dist/webhook-integration/webhook-utils.d.ts.map +1 -0
  63. package/dist/webhook-integration/webhook-utils.js +104 -0
  64. package/dist/webhook-integration/webhook-utils.js.map +1 -0
  65. package/hedhog/data/integration_event_catalog.yaml +118 -0
  66. package/hedhog/data/mail_profile.yaml +18 -0
  67. package/hedhog/data/menu.yaml +26 -12
  68. package/hedhog/data/route.yaml +152 -8
  69. package/hedhog/data/setting_group.yaml +7 -156
  70. package/hedhog/data/setting_subgroup.yaml +0 -32
  71. package/hedhog/frontend/app/configurations/[slug]/components/setting-field.tsx.ejs +205 -0
  72. package/hedhog/frontend/app/integrations-webhooks/page.tsx.ejs +1835 -0
  73. package/hedhog/frontend/messages/en.json +2 -1
  74. package/hedhog/frontend/messages/pt.json +2 -1
  75. package/hedhog/table/event_webhook.yaml +55 -0
  76. package/hedhog/table/event_webhook_delivery_log.yaml +66 -0
  77. package/hedhog/table/event_webhook_event.yaml +26 -0
  78. package/hedhog/table/integration_event_catalog.yaml +41 -0
  79. package/hedhog/table/setting.yaml +1 -0
  80. package/hedhog/table/webhook_action.yaml +85 -0
  81. package/hedhog/table/webhook_call_log.yaml +46 -0
  82. package/hedhog/table/webhook_integration.yaml +43 -0
  83. package/package.json +3 -3
  84. package/src/core.module.ts +10 -7
  85. package/src/index.ts +10 -5
  86. package/src/integration/services/outbox.processor.ts +5 -4
  87. package/src/integration/types/event.types.ts +4 -3
  88. package/src/mail/mail.module.ts +36 -59
  89. package/src/mail/mail.service.ts +84 -89
  90. package/src/role/role.service.ts +41 -8
  91. package/src/setting/setting.service.ts +7 -6
  92. package/src/user/user.service.ts +34 -3
  93. package/src/webhook-integration/event-webhook.controller.ts +50 -0
  94. package/src/webhook-integration/event-webhook.service.ts +384 -0
  95. package/src/webhook-integration/integration-event-catalog.controller.ts +50 -0
  96. package/src/webhook-integration/integration-event-catalog.service.ts +117 -0
  97. package/src/webhook-integration/webhook-integration.controller.ts +103 -0
  98. package/src/webhook-integration/webhook-integration.module.ts +45 -0
  99. package/src/webhook-integration/webhook-integration.service.ts +735 -0
  100. package/src/webhook-integration/webhook-utils.ts +79 -0
@@ -1029,7 +1029,8 @@
1029
1029
  "fileUploadFailed": "Failed to upload file.",
1030
1030
  "uploadedFileAlt": "Uploaded file",
1031
1031
  "fileUrlPlaceholder": "File URL",
1032
- "selectOption": "Select an option"
1032
+ "selectOption": "Select an option",
1033
+ "selectMailProfile": "Select a mail profile"
1033
1034
  },
1034
1035
  "AddWidgetDialog": {
1035
1036
  "title": "Select Dashboard Components",
@@ -1032,7 +1032,8 @@
1032
1032
  "fileUploadFailed": "Falha ao enviar arquivo.",
1033
1033
  "uploadedFileAlt": "Arquivo enviado",
1034
1034
  "fileUrlPlaceholder": "URL do arquivo",
1035
- "selectOption": "Selecione uma opção"
1035
+ "selectOption": "Selecione uma opção",
1036
+ "selectMailProfile": "Selecione um perfil de email"
1036
1037
  },
1037
1038
  "AddWidgetDialog": {
1038
1039
  "title": "Selecionar Componentes do Dashboard",
@@ -0,0 +1,55 @@
1
+ columns:
2
+ - type: pk
3
+ - type: slug
4
+ - name: name
5
+ type: varchar
6
+ length: 127
7
+ - name: description
8
+ type: text
9
+ isNullable: true
10
+ - name: status
11
+ type: enum
12
+ enum:
13
+ - active
14
+ - inactive
15
+ default: active
16
+ - name: priority
17
+ type: int
18
+ default: 0
19
+ - name: url
20
+ type: text
21
+ - name: method
22
+ type: enum
23
+ enum:
24
+ - GET
25
+ - POST
26
+ - PUT
27
+ - PATCH
28
+ - DELETE
29
+ default: POST
30
+ - name: headers
31
+ type: json
32
+ isNullable: true
33
+ - name: query
34
+ type: json
35
+ isNullable: true
36
+ - name: payload
37
+ type: json
38
+ isNullable: true
39
+ - name: timeout_ms
40
+ type: int
41
+ default: 10000
42
+ - name: retry_count
43
+ type: int
44
+ default: 0
45
+ - type: created_at
46
+ - type: updated_at
47
+ indices:
48
+ - columns:
49
+ - slug
50
+ isUnique: true
51
+ - columns:
52
+ - status
53
+ - columns:
54
+ - priority
55
+
@@ -0,0 +1,66 @@
1
+ columns:
2
+ - type: pk
3
+ - type: fk
4
+ name: event_webhook_id
5
+ isNullable: true
6
+ references:
7
+ table: event_webhook
8
+ column: id
9
+ onDelete: set null
10
+ onUpdate: cascade
11
+ - type: fk
12
+ name: integration_event_catalog_id
13
+ isNullable: true
14
+ references:
15
+ table: integration_event_catalog
16
+ column: id
17
+ onDelete: set null
18
+ onUpdate: cascade
19
+ - name: outbox_event_id
20
+ type: int
21
+ isNullable: true
22
+ - name: event_name
23
+ type: varchar
24
+ length: 255
25
+ - name: method
26
+ type: varchar
27
+ length: 15
28
+ - name: url
29
+ type: text
30
+ - name: status
31
+ type: enum
32
+ enum:
33
+ - success
34
+ - failed
35
+ - name: http_status
36
+ type: int
37
+ isNullable: true
38
+ - name: duration_ms
39
+ type: int
40
+ default: 0
41
+ - name: attempt_count
42
+ type: int
43
+ default: 1
44
+ - name: error_message
45
+ type: text
46
+ isNullable: true
47
+ - name: request_summary
48
+ type: json
49
+ isNullable: true
50
+ - name: response_summary
51
+ type: json
52
+ isNullable: true
53
+ - type: created_at
54
+ - type: updated_at
55
+ indices:
56
+ - columns:
57
+ - event_webhook_id
58
+ - columns:
59
+ - integration_event_catalog_id
60
+ - columns:
61
+ - event_name
62
+ - columns:
63
+ - status
64
+ - columns:
65
+ - created_at
66
+
@@ -0,0 +1,26 @@
1
+ columns:
2
+ - type: pk
3
+ - type: fk
4
+ name: event_webhook_id
5
+ references:
6
+ table: event_webhook
7
+ column: id
8
+ onDelete: cascade
9
+ onUpdate: cascade
10
+ - type: fk
11
+ name: integration_event_catalog_id
12
+ references:
13
+ table: integration_event_catalog
14
+ column: id
15
+ onDelete: cascade
16
+ onUpdate: cascade
17
+ - type: created_at
18
+ - type: updated_at
19
+ indices:
20
+ - columns:
21
+ - event_webhook_id
22
+ - integration_event_catalog_id
23
+ isUnique: true
24
+ - columns:
25
+ - integration_event_catalog_id
26
+
@@ -0,0 +1,41 @@
1
+ columns:
2
+ - type: pk
3
+ - type: slug
4
+ - name: name
5
+ type: varchar
6
+ length: 127
7
+ - name: module
8
+ type: varchar
9
+ length: 127
10
+ - name: aggregate_type
11
+ type: varchar
12
+ length: 127
13
+ isNullable: true
14
+ - name: description
15
+ type: text
16
+ isNullable: true
17
+ - name: payload_schema
18
+ type: json
19
+ isNullable: true
20
+ - name: metadata_schema
21
+ type: json
22
+ isNullable: true
23
+ - name: status
24
+ type: enum
25
+ enum:
26
+ - active
27
+ - inactive
28
+ default: active
29
+ - type: created_at
30
+ - type: updated_at
31
+ indices:
32
+ - columns:
33
+ - slug
34
+ isUnique: true
35
+ - columns:
36
+ - module
37
+ - columns:
38
+ - aggregate_type
39
+ - columns:
40
+ - status
41
+
@@ -30,6 +30,7 @@ columns:
30
30
  - color-picker
31
31
  - switch
32
32
  - checkbox
33
+ - entity-picker
33
34
  default: input-text
34
35
  - name: value
35
36
  length: 1023
@@ -0,0 +1,85 @@
1
+ columns:
2
+ - type: pk
3
+ - type: fk
4
+ name: webhook_integration_id
5
+ references:
6
+ table: webhook_integration
7
+ column: id
8
+ onDelete: cascade
9
+ onUpdate: cascade
10
+ - name: type
11
+ type: enum
12
+ enum:
13
+ - email
14
+ - whatsapp_evolution
15
+ - name: name
16
+ type: varchar
17
+ length: 127
18
+ - name: order
19
+ type: int
20
+ default: 0
21
+ - name: status
22
+ type: enum
23
+ enum:
24
+ - active
25
+ - inactive
26
+ default: active
27
+ - type: fk
28
+ name: mail_profile_id
29
+ isNullable: true
30
+ references:
31
+ table: mail_profile
32
+ column: id
33
+ onDelete: set null
34
+ onUpdate: cascade
35
+ - type: fk
36
+ name: mail_id
37
+ isNullable: true
38
+ references:
39
+ table: mail
40
+ column: id
41
+ onDelete: set null
42
+ onUpdate: cascade
43
+ - name: email_to
44
+ type: text
45
+ isNullable: true
46
+ - name: email_cc
47
+ type: text
48
+ isNullable: true
49
+ - name: email_bcc
50
+ type: text
51
+ isNullable: true
52
+ - name: whatsapp_target_type
53
+ type: enum
54
+ enum:
55
+ - phone
56
+ - group
57
+ isNullable: true
58
+ - name: whatsapp_target
59
+ type: varchar
60
+ length: 255
61
+ isNullable: true
62
+ - name: whatsapp_template
63
+ type: text
64
+ isNullable: true
65
+ - name: whatsapp_instance
66
+ type: varchar
67
+ length: 127
68
+ isNullable: true
69
+ - name: whatsapp_base_url
70
+ type: varchar
71
+ length: 255
72
+ isNullable: true
73
+ - name: whatsapp_token
74
+ type: text
75
+ isNullable: true
76
+ - type: created_at
77
+ - type: updated_at
78
+ indices:
79
+ - columns:
80
+ - webhook_integration_id
81
+ - columns:
82
+ - type
83
+ - columns:
84
+ - status
85
+
@@ -0,0 +1,46 @@
1
+ columns:
2
+ - type: pk
3
+ - type: fk
4
+ name: webhook_integration_id
5
+ isNullable: true
6
+ references:
7
+ table: webhook_integration
8
+ column: id
9
+ onDelete: set null
10
+ onUpdate: cascade
11
+ - name: public_uuid
12
+ type: varchar
13
+ length: 36
14
+ - name: status
15
+ type: enum
16
+ enum:
17
+ - success
18
+ - failed
19
+ - name: remote_ip
20
+ type: varchar
21
+ length: 127
22
+ isNullable: true
23
+ - name: duration_ms
24
+ type: int
25
+ default: 0
26
+ - name: error_message
27
+ type: text
28
+ isNullable: true
29
+ - name: payload_summary
30
+ type: json
31
+ isNullable: true
32
+ - name: response_summary
33
+ type: json
34
+ isNullable: true
35
+ - type: created_at
36
+ - type: updated_at
37
+ indices:
38
+ - columns:
39
+ - webhook_integration_id
40
+ - columns:
41
+ - public_uuid
42
+ - columns:
43
+ - status
44
+ - columns:
45
+ - created_at
46
+
@@ -0,0 +1,43 @@
1
+ columns:
2
+ - type: pk
3
+ - type: slug
4
+ - name: name
5
+ type: varchar
6
+ length: 127
7
+ - name: description
8
+ type: text
9
+ isNullable: true
10
+ - name: public_uuid
11
+ type: varchar
12
+ length: 36
13
+ - name: status
14
+ type: enum
15
+ enum:
16
+ - active
17
+ - inactive
18
+ default: active
19
+ - name: require_token
20
+ type: boolean
21
+ default: false
22
+ - name: token_hash
23
+ type: varchar
24
+ length: 128
25
+ isNullable: true
26
+ - name: allowed_ips
27
+ type: json
28
+ isNullable: true
29
+ - name: body_schema
30
+ type: json
31
+ isNullable: true
32
+ - type: created_at
33
+ - type: updated_at
34
+ indices:
35
+ - columns:
36
+ - slug
37
+ isUnique: true
38
+ - columns:
39
+ - public_uuid
40
+ isUnique: true
41
+ - columns:
42
+ - status
43
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hed-hog/core",
3
- "version": "0.0.325",
3
+ "version": "0.0.327",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "dependencies": {
@@ -33,9 +33,9 @@
33
33
  "@hed-hog/api": "0.0.8",
34
34
  "@hed-hog/api-types": "0.0.1",
35
35
  "@hed-hog/api-locale": "0.0.14",
36
- "@hed-hog/api-pagination": "0.0.7",
37
36
  "@hed-hog/api-prisma": "0.0.6",
38
- "@hed-hog/api-mail": "0.0.9"
37
+ "@hed-hog/api-mail": "0.0.9",
38
+ "@hed-hog/api-pagination": "0.0.7"
39
39
  },
40
40
  "exports": {
41
41
  ".": {
@@ -29,7 +29,8 @@ import { SessionModule } from './session/session.module';
29
29
  import { SettingModule } from './setting/setting.module';
30
30
  import { SettingService } from './setting/setting.service';
31
31
  import { TaskModule } from './task/task.module';
32
- import { UserModule } from './user/user.module';
32
+ import { UserModule } from './user/user.module';
33
+ import { WebhookIntegrationModule } from './webhook-integration/webhook-integration.module';
33
34
  import { IsEmailWithSettingsConstraint } from './validators/is-email-with-settings.validator';
34
35
  import { IsPinCodeWithSettingConstraint } from './validators/is-pin-code-with-setting.validator';
35
36
  import { IsStrongPasswordWithSettingsConstraint } from './validators/is-strong-password-with-settings.validator';
@@ -63,9 +64,10 @@ import { ValidatorServiceLocator } from './validators/service-locator';
63
64
  forwardRef(() => SecurityModule),
64
65
  forwardRef(() => ProfileModule),
65
66
  forwardRef(() => SessionModule),
66
- forwardRef(() => OAuthModule),
67
- forwardRef(() => IntegrationModule),
68
- ],
67
+ forwardRef(() => OAuthModule),
68
+ forwardRef(() => IntegrationModule),
69
+ forwardRef(() => WebhookIntegrationModule),
70
+ ],
69
71
  exports: [
70
72
  UserModule,
71
73
  AuthModule,
@@ -79,9 +81,10 @@ import { ValidatorServiceLocator } from './validators/service-locator';
79
81
  SettingModule,
80
82
  FileModule,
81
83
  SessionModule,
82
- AiModule,
83
- IntegrationModule,
84
- IsStrongPasswordWithSettingsConstraint,
84
+ AiModule,
85
+ IntegrationModule,
86
+ WebhookIntegrationModule,
87
+ IsStrongPasswordWithSettingsConstraint,
85
88
  IsEmailWithSettingsConstraint,
86
89
  IsPinCodeWithSettingConstraint,
87
90
  ],
package/src/index.ts CHANGED
@@ -29,11 +29,16 @@ export * from './file/file.service';
29
29
  export * from './setting/setting.module';
30
30
  export * from './setting/setting.service';
31
31
 
32
- export * from './ai/ai.module';
33
- export * from './ai/ai.service';
34
-
35
- // Integration Module
36
- export * from './integration/integration.module';
32
+ export * from './ai/ai.module';
33
+ export * from './ai/ai.service';
34
+
35
+ export * from './webhook-integration/webhook-integration.module';
36
+ export * from './webhook-integration/integration-event-catalog.service';
37
+ export * from './webhook-integration/webhook-integration.service';
38
+ export * from './webhook-integration/event-webhook.service';
39
+
40
+ // Integration Module
41
+ export * from './integration/integration.module';
37
42
  export * from './integration/services/domain-event.publisher';
38
43
  export * from './integration/services/event-subscriber.registry';
39
44
  export * from './integration/services/inbox.service';
@@ -82,10 +82,11 @@ export class OutboxProcessor {
82
82
 
83
83
  try {
84
84
  // Execute handler
85
- await handlerDef.handler(
86
- {
87
- eventName: event.eventName,
88
- sourceModule: event.sourceModule,
85
+ await handlerDef.handler(
86
+ {
87
+ outboxEventId: event.id,
88
+ eventName: event.eventName,
89
+ sourceModule: event.sourceModule,
89
90
  aggregateType: event.aggregateType,
90
91
  aggregateId: event.aggregateId,
91
92
  payload: event.payload,
@@ -32,9 +32,10 @@ export enum LinkType {
32
32
  /**
33
33
  * Domain event interface that is published and processed
34
34
  */
35
- export interface DomainEvent {
36
- eventName: string;
37
- sourceModule: string;
35
+ export interface DomainEvent {
36
+ outboxEventId?: string;
37
+ eventName: string;
38
+ sourceModule: string;
38
39
  aggregateType: string;
39
40
  aggregateId: string;
40
41
  payload: Record<string, any>;
@@ -2,7 +2,7 @@ import { LocaleModule } from '@hed-hog/api-locale';
2
2
  import { MailModule as MailMainModule, MailModuleOptions } from '@hed-hog/api-mail';
3
3
  import { PaginationModule } from '@hed-hog/api-pagination';
4
4
  import { PrismaModule, PrismaService } from '@hed-hog/api-prisma';
5
- import { BadRequestException, forwardRef, Module } from '@nestjs/common';
5
+ import { forwardRef, Module } from '@nestjs/common';
6
6
  import { MailSentModule } from '../mail-sent/mail-sent.module';
7
7
  import { SettingModule } from '../setting/setting.module';
8
8
  import { MailController } from './mail.controller';
@@ -15,82 +15,59 @@ import { MailService } from './mail.service';
15
15
  inject: [PrismaService],
16
16
  useFactory: async (prisma: PrismaService) => {
17
17
  try {
18
- const mailSettings = await prisma.setting.findMany({
19
- where: {
20
- slug: {
21
- in: [
22
-
23
- 'mail-provider',
24
- 'mail-from',
25
- 'mail-gmail-client-id',
26
- 'mail-gmail-client-secret',
27
- 'mail-gmail-refresh-token',
28
- 'mail-smtp-host',
29
- 'mail-smtp-port',
30
- 'mail-smtp-secure',
31
- 'mail-client-secret',
32
- 'mail-client-secret',
33
- 'mail-aws-access-key-id',
34
- 'mail-aws-secret-access-key',
35
- 'mail-aws-region'
36
- ]
37
- }
38
- },
39
- select: {
40
- slug: true,
41
- value: true,
42
- }
18
+ const profileIdSetting = await prisma.setting.findUnique({
19
+ where: { slug: 'mail-profile-id' },
20
+ select: { value: true },
43
21
  });
44
22
 
45
- const settings = new Map<string, string>();
23
+ const profileId = Number(profileIdSetting?.value);
24
+
25
+ if (!profileId || profileId <= 0) {
26
+ return { global: true, type: 'SMTP', host: 'localhost', port: 1025, secure: false, username: '', password: '' } as MailModuleOptions;
27
+ }
28
+
29
+ const profile = await prisma.mail_profile.findUnique({
30
+ where: { id: profileId },
31
+ });
46
32
 
47
- for (const setting of mailSettings) {
48
- settings.set(setting.slug, setting.value);
33
+ if (!profile) {
34
+ return { global: true, type: 'SMTP', host: 'localhost', port: 1025, secure: false, username: '', password: '' } as MailModuleOptions;
49
35
  }
50
36
 
51
- const config: MailModuleOptions = {
52
- global: true,
53
- } as MailModuleOptions;
37
+ const base: MailModuleOptions = { global: true } as MailModuleOptions;
54
38
 
55
- switch (settings.get('mail-provider')) {
39
+ switch (profile.provider) {
56
40
  case 'GMAIL':
57
- Object.assign(config, {
41
+ return Object.assign(base, {
58
42
  type: 'GMAIL',
59
- clientId: settings.get('mail-gmail-client-id'),
60
- clientSecret: settings.get('mail-gmail-client-secret'),
61
- refreshToken: settings.get('mail-gmail-refresh-token'),
62
- from: settings.get('mail-from'),
43
+ clientId: profile.gmail_client_id ?? '',
44
+ clientSecret: profile.gmail_client_secret ?? '',
45
+ refreshToken: profile.gmail_refresh_token ?? '',
46
+ from: profile.from_email,
63
47
  });
64
- break;
65
48
  case 'SMTP':
66
- Object.assign(config, {
49
+ return Object.assign(base, {
67
50
  type: 'SMTP',
68
- host: settings.get('mail-smtp-host'),
69
- port: Number(settings.get('mail-smtp-port')),
70
- secure: settings.get('mail-smtp-secure') === 'true',
71
- username: settings.get('mail-from'),
72
- password: settings.get('mail-client-secret'),
51
+ host: profile.smtp_host ?? 'localhost',
52
+ port: profile.smtp_port ?? 1025,
53
+ secure: profile.smtp_secure ?? false,
54
+ username: profile.smtp_username ?? '',
55
+ password: profile.smtp_password ?? '',
73
56
  });
74
- break;
75
57
  case 'SES':
76
- Object.assign(config, {
58
+ return Object.assign(base, {
77
59
  type: 'SES',
78
- region: settings.get('mail-aws-region'),
79
- accessKeyId: settings.get('mail-aws-access-key-id'),
80
- secretAccessKey: settings.get('mail-aws-secret-access-key'),
81
- from: settings.get('mail-from'),
60
+ region: profile.ses_region ?? '',
61
+ accessKeyId: profile.ses_access_key_id ?? '',
62
+ secretAccessKey: profile.ses_secret_access_key ?? '',
63
+ from: profile.from_email,
82
64
  });
83
- break;
84
65
  default:
85
- throw new BadRequestException(`Invalid mail provider: ${settings.get('mail-provider')}`);
66
+ return { global: true, type: 'SMTP', host: 'localhost', port: 1025, secure: false, username: '', password: '' } as MailModuleOptions;
86
67
  }
87
-
88
- return config;
89
- }
90
-
91
- catch (error) {
68
+ } catch (error) {
92
69
  console.error('Error loading mail settings:', error);
93
- throw error;
70
+ return { global: true, type: 'SMTP', host: 'localhost', port: 1025, secure: false, username: '', password: '' } as MailModuleOptions;
94
71
  }
95
72
  }
96
73
  })),