rez_core 2.2.211 → 2.2.213

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 (82) hide show
  1. package/dist/module/communication/communication.module.js +11 -11
  2. package/dist/module/communication/communication.module.js.map +1 -1
  3. package/dist/module/communication/factories/email.factory.d.ts +6 -6
  4. package/dist/module/communication/factories/email.factory.js +9 -9
  5. package/dist/module/communication/factories/email.factory.js.map +1 -1
  6. package/dist/module/communication/factories/sms.factory.d.ts +2 -2
  7. package/dist/module/communication/factories/sms.factory.js +4 -4
  8. package/dist/module/communication/factories/sms.factory.js.map +1 -1
  9. package/dist/module/communication/factories/telephone.factory.d.ts +2 -2
  10. package/dist/module/communication/factories/telephone.factory.js +2 -2
  11. package/dist/module/communication/factories/telephone.factory.js.map +1 -1
  12. package/dist/module/communication/factories/whatsapp.factory.d.ts +1 -1
  13. package/dist/module/communication/factories/whatsapp.factory.js +1 -1
  14. package/dist/module/communication/factories/whatsapp.factory.js.map +1 -1
  15. package/dist/module/communication/service/communication.service.js +45 -39
  16. package/dist/module/communication/service/communication.service.js.map +1 -1
  17. package/dist/module/communication/service/wrapper.service.js +1 -1
  18. package/dist/module/communication/service/wrapper.service.js.map +1 -1
  19. package/dist/module/communication/strategies/communication.strategy.js.map +1 -1
  20. package/dist/module/communication/strategies/email/gmail-api.strategy.d.ts +1 -0
  21. package/dist/module/communication/strategies/email/gmail-api.strategy.js +53 -61
  22. package/dist/module/communication/strategies/email/gmail-api.strategy.js.map +1 -1
  23. package/dist/module/communication/strategies/{gmail-smtp.strategy.d.ts → email/gmail-smtp-v2.strategy.d.ts} +1 -1
  24. package/dist/module/communication/strategies/{gmail-smtp.strategy.js → email/gmail-smtp-v2.strategy.js} +1 -1
  25. package/dist/module/communication/strategies/email/gmail-smtp-v2.strategy.js.map +1 -0
  26. package/dist/module/communication/strategies/{outlook-smtp.strategy.d.ts → email/outlook-smtp.strategy.d.ts} +1 -1
  27. package/dist/module/communication/strategies/email/outlook-smtp.strategy.js.map +1 -0
  28. package/dist/module/communication/strategies/{outlook.strategy.d.ts → email/outlook.strategy.d.ts} +1 -1
  29. package/dist/module/communication/strategies/email/outlook.strategy.js.map +1 -0
  30. package/dist/module/communication/strategies/email/sendgrid-api.strategy.js +1 -12
  31. package/dist/module/communication/strategies/email/sendgrid-api.strategy.js.map +1 -1
  32. package/dist/module/communication/strategies/{knowlarity.strategy.d.ts → sms/knowlarity-multi.strategy.d.ts} +1 -1
  33. package/dist/module/communication/strategies/{knowlarity.strategy.js → sms/knowlarity-multi.strategy.js} +1 -1
  34. package/dist/module/communication/strategies/sms/knowlarity-multi.strategy.js.map +1 -0
  35. package/dist/module/communication/strategies/{sms.strategy.d.ts → sms/twilio-v2.strategy.d.ts} +1 -1
  36. package/dist/module/communication/strategies/{sms.strategy.js → sms/twilio-v2.strategy.js} +1 -1
  37. package/dist/module/communication/strategies/sms/twilio-v2.strategy.js.map +1 -0
  38. package/dist/module/communication/strategies/telephone/knowlarity-multi.strategy.d.ts +6 -0
  39. package/dist/module/communication/strategies/telephone/knowlarity-multi.strategy.js +121 -0
  40. package/dist/module/communication/strategies/telephone/knowlarity-multi.strategy.js.map +1 -0
  41. package/dist/module/communication/strategies/{whatsapp.strategy.d.ts → whatsapp/whatsapp.strategy.d.ts} +1 -1
  42. package/dist/module/communication/strategies/whatsapp/whatsapp.strategy.js.map +1 -0
  43. package/dist/module/user/controller/login.controller.d.ts +1 -1
  44. package/dist/module/user/controller/login.controller.js +20 -2
  45. package/dist/module/user/controller/login.controller.js.map +1 -1
  46. package/dist/module/workflow/entity/task-data.entity.d.ts +1 -0
  47. package/dist/module/workflow/entity/task-data.entity.js +4 -0
  48. package/dist/module/workflow/entity/task-data.entity.js.map +1 -1
  49. package/dist/tsconfig.build.tsbuildinfo +1 -1
  50. package/package.json +1 -1
  51. package/src/module/communication/communication.module.ts +9 -9
  52. package/src/module/communication/factories/email.factory.ts +6 -6
  53. package/src/module/communication/factories/sms.factory.ts +2 -2
  54. package/src/module/communication/factories/telephone.factory.ts +2 -2
  55. package/src/module/communication/factories/whatsapp.factory.ts +1 -1
  56. package/src/module/communication/service/communication.service.ts +7 -3
  57. package/src/module/communication/service/wrapper.service.ts +1 -1
  58. package/src/module/communication/strategies/communication.strategy.ts +8 -2
  59. package/src/module/communication/strategies/email/gmail-api.strategy.ts +82 -79
  60. package/src/module/communication/strategies/{gmail-smtp.strategy.ts → email/gmail-smtp-v2.strategy.ts} +1 -1
  61. package/src/module/communication/strategies/{outlook-smtp.strategy.ts → email/outlook-smtp.strategy.ts} +1 -1
  62. package/src/module/communication/strategies/{outlook.strategy.ts → email/outlook.strategy.ts} +1 -1
  63. package/src/module/communication/strategies/email/sendgrid-api.strategy.ts +7 -9
  64. package/src/module/communication/strategies/{knowlarity.strategy.ts → sms/knowlarity-multi.strategy.ts} +1 -1
  65. package/src/module/communication/strategies/{sms.strategy.ts → sms/twilio-v2.strategy.ts} +1 -1
  66. package/src/module/communication/strategies/telephone/knowlarity-multi.strategy.ts +158 -0
  67. package/src/module/communication/strategies/{whatsapp.strategy.ts → whatsapp/whatsapp.strategy.ts} +1 -1
  68. package/src/module/user/controller/login.controller.ts +22 -2
  69. package/src/module/workflow/entity/task-data.entity.ts +3 -0
  70. package/dist/module/communication/strategies/gmail-smtp.strategy.js.map +0 -1
  71. package/dist/module/communication/strategies/gmail.strategy.d.ts +0 -8
  72. package/dist/module/communication/strategies/gmail.strategy.js +0 -100
  73. package/dist/module/communication/strategies/gmail.strategy.js.map +0 -1
  74. package/dist/module/communication/strategies/knowlarity.strategy.js.map +0 -1
  75. package/dist/module/communication/strategies/outlook-smtp.strategy.js.map +0 -1
  76. package/dist/module/communication/strategies/outlook.strategy.js.map +0 -1
  77. package/dist/module/communication/strategies/sms.strategy.js.map +0 -1
  78. package/dist/module/communication/strategies/whatsapp.strategy.js.map +0 -1
  79. package/src/module/communication/strategies/gmail.strategy.ts +0 -119
  80. /package/dist/module/communication/strategies/{outlook-smtp.strategy.js → email/outlook-smtp.strategy.js} +0 -0
  81. /package/dist/module/communication/strategies/{outlook.strategy.js → email/outlook.strategy.js} +0 -0
  82. /package/dist/module/communication/strategies/{whatsapp.strategy.js → whatsapp/whatsapp.strategy.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.2.211",
3
+ "version": "2.2.213",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -23,13 +23,13 @@ import { WhatsAppCloudStrategy } from './strategies/whatsapp/whatsapp-cloud.stra
23
23
  import { KnowlarityVoiceStrategy } from './strategies/telephone/knowlarity-voice.strategy';
24
24
 
25
25
  // New unified strategies
26
- import { GmailStrategy } from './strategies/gmail.strategy';
27
- import { OutlookStrategy } from './strategies/outlook.strategy';
28
- import { GmailSMTPStrategy } from './strategies/gmail-smtp.strategy';
29
- import { OutlookSMTPStrategy } from './strategies/outlook-smtp.strategy';
30
- import { SmsStrategy } from './strategies/sms.strategy';
31
- import { KnowlarityStrategy } from './strategies/knowlarity.strategy';
32
- import { WhatsAppStrategy } from './strategies/whatsapp.strategy';
26
+ import { OutlookStrategy } from './strategies/email/outlook.strategy';
27
+ import { GmailSMTPStrategy } from './strategies/email/gmail-smtp-v2.strategy';
28
+ import { OutlookSMTPStrategy } from './strategies/email/outlook-smtp.strategy';
29
+ import { SmsStrategy } from './strategies/sms/twilio-v2.strategy';
30
+ import { KnowlarityStrategy as KnowlarityMultiStrategy } from './strategies/sms/knowlarity-multi.strategy';
31
+ import { KnowlarityStrategy as TelephoneKnowlarityStrategy } from './strategies/telephone/knowlarity-multi.strategy';
32
+ import { WhatsAppStrategy } from './strategies/whatsapp/whatsapp.strategy';
33
33
  import { OAuthService } from './service/oauth.service';
34
34
 
35
35
  // Factories
@@ -69,12 +69,12 @@ import { IcsMeetingModule } from '../ics/ics.module';
69
69
  KnowlarityVoiceStrategy,
70
70
 
71
71
  // New unified strategies
72
- GmailStrategy,
73
72
  OutlookStrategy,
74
73
  GmailSMTPStrategy,
75
74
  OutlookSMTPStrategy,
76
75
  SmsStrategy,
77
- KnowlarityStrategy,
76
+ KnowlarityMultiStrategy,
77
+ TelephoneKnowlarityStrategy,
78
78
  WhatsAppStrategy,
79
79
 
80
80
  // Factories
@@ -1,16 +1,16 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { BaseFactory } from './base.factory';
3
3
  import { CommunicationStrategy } from '../strategies/communication.strategy';
4
- import { GmailStrategy } from '../strategies/gmail.strategy';
5
- import { OutlookStrategy } from '../strategies/outlook.strategy';
6
- import { GmailSMTPStrategy } from '../strategies/gmail-smtp.strategy';
7
- import { OutlookSMTPStrategy } from '../strategies/outlook-smtp.strategy';
4
+ import { GmailApiStrategy } from '../strategies/email/gmail-api.strategy';
5
+ import { OutlookStrategy } from '../strategies/email/outlook.strategy';
6
+ import { GmailSMTPStrategy } from '../strategies/email/gmail-smtp-v2.strategy';
7
+ import { OutlookSMTPStrategy } from '../strategies/email/outlook-smtp.strategy';
8
8
  import { SendGridApiStrategy } from '../strategies/email/sendgrid-api.strategy';
9
9
 
10
10
  @Injectable()
11
11
  export class EmailFactory implements BaseFactory {
12
12
  constructor(
13
- private gmailStrategy: GmailStrategy,
13
+ private gmailApiStrategy: GmailApiStrategy,
14
14
  private outlookStrategy: OutlookStrategy,
15
15
  private gmailSMTPStrategy: GmailSMTPStrategy,
16
16
  private outlookSMTPStrategy: OutlookSMTPStrategy,
@@ -22,7 +22,7 @@ export class EmailFactory implements BaseFactory {
22
22
 
23
23
  switch (key) {
24
24
  case 'api_gmail':
25
- return this.gmailStrategy;
25
+ return this.gmailApiStrategy;
26
26
  case 'api_outlook':
27
27
  return this.outlookStrategy;
28
28
  case 'api_sendgrid':
@@ -1,8 +1,8 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { BaseFactory } from './base.factory';
3
3
  import { CommunicationStrategy } from '../strategies/communication.strategy';
4
- import { SmsStrategy } from '../strategies/sms.strategy';
5
- import { KnowlarityStrategy } from '../strategies/knowlarity.strategy';
4
+ import { SmsStrategy } from '../strategies/sms/twilio-v2.strategy';
5
+ import { KnowlarityStrategy } from '../strategies/sms/knowlarity-multi.strategy';
6
6
 
7
7
  @Injectable()
8
8
  export class SmsFactory implements BaseFactory {
@@ -1,11 +1,11 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { BaseFactory } from './base.factory';
3
3
  import { CommunicationStrategy } from '../strategies/communication.strategy';
4
- import { KnowlarityStrategy } from '../strategies/knowlarity.strategy';
4
+ import { KnowlarityStrategy as TelephoneKnowlarityStrategy } from '../strategies/telephone/knowlarity-multi.strategy';
5
5
 
6
6
  @Injectable()
7
7
  export class TelephoneFactory implements BaseFactory {
8
- constructor(private knowlarityStrategy: KnowlarityStrategy) {}
8
+ constructor(private knowlarityStrategy: TelephoneKnowlarityStrategy) {}
9
9
 
10
10
  createProvider(service: string, provider: string): CommunicationStrategy {
11
11
  const key = `${service.toLowerCase()}_${provider.toLowerCase()}`;
@@ -1,7 +1,7 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { BaseFactory } from './base.factory';
3
3
  import { CommunicationStrategy } from '../strategies/communication.strategy';
4
- import { WhatsAppStrategy } from '../strategies/whatsapp.strategy';
4
+ import { WhatsAppStrategy } from '../strategies/whatsapp/whatsapp.strategy';
5
5
  import { WhatsAppCloudStrategy } from '../strategies/whatsapp/whatsapp-cloud.strategy';
6
6
 
7
7
  @Injectable()
@@ -595,7 +595,7 @@ export class CommunicationService {
595
595
 
596
596
  default:
597
597
  // Generic details - return safe subset of config
598
- const safeConfig: any = {};
598
+ { const safeConfig: any = {};
599
599
 
600
600
  // Include non-sensitive fields
601
601
  const safeFields = [
@@ -641,7 +641,7 @@ export class CommunicationService {
641
641
  }
642
642
  });
643
643
 
644
- return safeConfig;
644
+ return safeConfig; }
645
645
  }
646
646
  } catch (error) {
647
647
  return { error: 'Unable to extract configuration details' };
@@ -871,6 +871,8 @@ export class CommunicationService {
871
871
  const finalConfig = {
872
872
  ...hub.config.config_json,
873
873
  ...enhancedConfig,
874
+ templateId,
875
+ variables,
874
876
  };
875
877
 
876
878
  const result = await strategy.sendMessage(
@@ -922,7 +924,7 @@ export class CommunicationService {
922
924
 
923
925
  // Process template if provided
924
926
  let processedMessage = message;
925
- if (templateId && variables) {
927
+ if (html && variables) {
926
928
  processedMessage = this.processTemplate(
927
929
  html ? html : message,
928
930
  variables,
@@ -933,6 +935,8 @@ export class CommunicationService {
933
935
  const finalConfig = {
934
936
  ...hub.config.config_json,
935
937
  ...enhancedConfig,
938
+ templateId,
939
+ variables,
936
940
  };
937
941
 
938
942
  const result = await strategy.sendMessage(
@@ -94,7 +94,7 @@ export class WrapperService {
94
94
  type: 'EMAIL',
95
95
  cc: payload.cc,
96
96
  bcc: payload.bcc,
97
- html: templateCode,
97
+ html: payload.html,
98
98
  attachments: payload.attachments,
99
99
  templateId: templateCode,
100
100
  variables: payload.variables,
@@ -32,7 +32,11 @@ export interface MessageTemplate {
32
32
  }
33
33
 
34
34
  export class EmailAttachmentValidator {
35
- static validate(attachments: EmailAttachment[], maxSizeBytes: number, providerName: string): void {
35
+ static validate(
36
+ attachments: EmailAttachment[],
37
+ maxSizeBytes: number,
38
+ providerName: string,
39
+ ): void {
36
40
  let totalSize = 0;
37
41
 
38
42
  for (const attachment of attachments) {
@@ -66,7 +70,9 @@ export class EmailAttachmentValidator {
66
70
 
67
71
  if (totalSize > maxSizeBytes) {
68
72
  const maxSizeMB = Math.floor(maxSizeBytes / (1024 * 1024));
69
- throw new Error(`Total attachment size exceeds ${providerName} limit of ${maxSizeMB}MB`);
73
+ throw new Error(
74
+ `Total attachment size exceeds ${providerName} limit of ${maxSizeMB}MB`,
75
+ );
70
76
  }
71
77
  }
72
78
  }
@@ -1,6 +1,6 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { ConfigService } from '@nestjs/config';
3
- import axios from 'axios';
3
+ import { google } from 'googleapis';
4
4
  import {
5
5
  CommunicationStrategy,
6
6
  CommunicationResult,
@@ -23,20 +23,26 @@ export class GmailApiStrategy implements CommunicationStrategy {
23
23
  );
24
24
  }
25
25
 
26
- const { subject, html, cc, bcc, attachments } = config;
26
+ const { subject, cc, bcc, attachments } = config;
27
27
 
28
- console.log('---- Using HTTP Gmail API ----');
29
- console.log('Always refreshing token before send...');
28
+ console.log('---- Using Google SDK Gmail API ----');
30
29
 
31
30
  // Validate attachments if present
32
31
  if (attachments && attachments.length > 0) {
33
- EmailAttachmentValidator.validate(attachments, 25 * 1024 * 1024, 'Gmail');
32
+ EmailAttachmentValidator.validate(
33
+ attachments,
34
+ 25 * 1024 * 1024,
35
+ 'Gmail',
36
+ );
34
37
  }
35
38
 
36
- // ALWAYS refresh token first - no expiration checking
37
- const freshAccessToken = await this.refreshAccessToken(config);
39
+ // Setup OAuth2 client with Google SDK
40
+ const oauth2Client = await this.setupOAuth2Client(config);
41
+
42
+ // Initialize Gmail API
43
+ const gmail = google.gmail({ version: 'v1', auth: oauth2Client });
38
44
 
39
- console.log('---- Fresh token obtained, preparing email ----');
45
+ console.log('---- Gmail SDK client initialized, preparing email ----');
40
46
 
41
47
  const toRecipients = Array.isArray(to) ? to.join(', ') : to;
42
48
  const ccRecipients = cc
@@ -59,7 +65,6 @@ export class GmailApiStrategy implements CommunicationStrategy {
59
65
  bccRecipients,
60
66
  subject,
61
67
  message,
62
- html,
63
68
  attachments,
64
69
  )
65
70
  : this.buildSimpleEmail(
@@ -68,46 +73,41 @@ export class GmailApiStrategy implements CommunicationStrategy {
68
73
  bccRecipients,
69
74
  subject,
70
75
  message,
71
- html,
72
76
  );
77
+
73
78
  const encodedMessage = Buffer.from(emailContent)
74
79
  .toString('base64')
75
80
  .replace(/\+/g, '-')
76
81
  .replace(/\//g, '_')
77
82
  .replace(/=+$/, '');
78
83
 
79
- // Send with fresh token
80
- const response = await axios.post(
81
- 'https://gmail.googleapis.com/gmail/v1/users/me/messages/send',
82
- {
84
+ // Send email using Google SDK
85
+ const result = await gmail.users.messages.send({
86
+ userId: 'me',
87
+ requestBody: {
83
88
  raw: encodedMessage,
84
89
  },
85
- {
86
- headers: {
87
- Authorization: `Bearer ${freshAccessToken}`,
88
- 'Content-Type': 'application/json',
89
- },
90
- timeout: 30000, // 30 second timeout
91
- },
92
- );
90
+ });
91
+
92
+ console.log('---- Gmail SDK API Success ----');
93
+ console.log('Message ID:', result.data.id);
93
94
 
94
- console.log('---- Gmail HTTP API Success ----');
95
- console.log('Response status:', response.status);
96
- console.log('Message ID:', response.data?.id);
95
+ // Get fresh access token for database update
96
+ const credentials = oauth2Client.credentials;
97
+ const freshAccessToken = credentials.access_token;
97
98
 
98
99
  return {
99
100
  success: true,
100
- messageId: response.data?.id || undefined,
101
+ messageId: result.data.id || undefined,
101
102
  provider: 'gmail',
102
103
  service: 'API',
103
104
  timestamp: new Date(),
104
- refreshedToken: freshAccessToken, // Always return the fresh token for database update
105
+ refreshedToken: freshAccessToken, // Return fresh token for database update
105
106
  };
106
107
  } catch (error) {
107
- console.error('---- Gmail HTTP API Error ----');
108
+ console.error('---- Gmail SDK API Error ----');
108
109
  console.error('Error message:', error.message);
109
- console.error('Status:', error.response?.status);
110
- console.error('Response data:', error.response?.data);
110
+ console.error('Error details:', error.response?.data || error.errors);
111
111
 
112
112
  return {
113
113
  success: false,
@@ -125,16 +125,16 @@ export class GmailApiStrategy implements CommunicationStrategy {
125
125
  validateConfig(config: any): boolean {
126
126
  if (!config) return false;
127
127
 
128
- // For always-refresh strategy, we only need a refresh token
128
+ // For Google SDK strategy, we need a refresh token
129
129
  return config.refreshToken && typeof config.refreshToken === 'string';
130
130
  }
131
131
 
132
- async refreshAccessToken(config: any): Promise<string> {
132
+ private async setupOAuth2Client(config: any): Promise<any> {
133
133
  try {
134
134
  const { refreshToken } = config;
135
135
 
136
136
  if (!refreshToken) {
137
- throw new Error('Missing refresh token for token refresh');
137
+ throw new Error('Missing refresh token for OAuth2 setup');
138
138
  }
139
139
 
140
140
  // Get system OAuth credentials
@@ -145,37 +145,54 @@ export class GmailApiStrategy implements CommunicationStrategy {
145
145
  throw new Error('Gmail OAuth system credentials not configured');
146
146
  }
147
147
 
148
- console.log('---- Refreshing token with system credentials ----');
148
+ console.log('---- Setting up OAuth2 client with Google SDK ----');
149
149
 
150
- // Use Google's OAuth endpoint to refresh token with system credentials
151
- const response = await axios.post(
152
- 'https://oauth2.googleapis.com/token',
153
- {
154
- client_id: clientId,
155
- client_secret: clientSecret,
156
- refresh_token: refreshToken,
157
- grant_type: 'refresh_token',
158
- },
159
- {
160
- headers: {
161
- 'Content-Type': 'application/x-www-form-urlencoded',
162
- },
163
- },
150
+ // Create OAuth2 client using Google SDK
151
+ const oauth2Client = new google.auth.OAuth2(
152
+ clientId,
153
+ clientSecret,
154
+ 'urn:ietf:wg:oauth:2.0:oob', // For server-to-server
164
155
  );
165
156
 
166
- if (!response.data.access_token) {
167
- throw new Error('No access token received from refresh');
157
+ // Set the refresh token
158
+ oauth2Client.setCredentials({
159
+ refresh_token: refreshToken,
160
+ });
161
+
162
+ // Refresh access token automatically
163
+ await oauth2Client.getAccessToken();
164
+
165
+ console.log('---- OAuth2 client setup completed ----');
166
+ return oauth2Client;
167
+ } catch (error) {
168
+ console.error(
169
+ 'Failed to setup OAuth2 client:',
170
+ error.message,
171
+ );
172
+ throw new Error(
173
+ `Failed to setup Gmail OAuth2 client: ${error.message}`,
174
+ );
175
+ }
176
+ }
177
+
178
+ async refreshAccessToken(config: any): Promise<string> {
179
+ try {
180
+ const oauth2Client = await this.setupOAuth2Client(config);
181
+ const { token } = await oauth2Client.getAccessToken();
182
+
183
+ if (!token) {
184
+ throw new Error('No access token received from OAuth2 client');
168
185
  }
169
186
 
170
- console.log('---- Token refreshed successfully ----');
171
- return response.data.access_token;
187
+ console.log('---- Token refreshed successfully via Google SDK ----');
188
+ return token;
172
189
  } catch (error) {
173
190
  console.error(
174
- 'Failed to refresh access token:',
175
- error.response?.data || error.message,
191
+ 'Failed to refresh access token via Google SDK:',
192
+ error.message,
176
193
  );
177
194
  throw new Error(
178
- `Failed to refresh Gmail access token: ${error.response?.data?.error_description || error.message}`,
195
+ `Failed to refresh Gmail access token: ${error.message}`,
179
196
  );
180
197
  }
181
198
  }
@@ -186,24 +203,20 @@ export class GmailApiStrategy implements CommunicationStrategy {
186
203
  return false;
187
204
  }
188
205
 
189
- const { accessToken } = config;
206
+ // Setup OAuth2 client and test the connection
207
+ const oauth2Client = await this.setupOAuth2Client(config);
208
+ const gmail = google.gmail({ version: 'v1', auth: oauth2Client });
190
209
 
191
210
  // Test the connection by getting user profile
192
- const response = await axios.get(
193
- 'https://gmail.googleapis.com/gmail/v1/users/me/profile',
194
- {
195
- headers: {
196
- Authorization: `Bearer ${accessToken}`,
197
- },
198
- timeout: 10000, // 10 second timeout for validation
199
- },
200
- );
211
+ const profile = await gmail.users.getProfile({
212
+ userId: 'me',
213
+ });
201
214
 
202
- return response.status === 200 && response.data.emailAddress;
215
+ return !!(profile.data && profile.data.emailAddress);
203
216
  } catch (error) {
204
217
  console.error(
205
218
  'Gmail connection validation failed:',
206
- error.response?.data || error.message,
219
+ error.message,
207
220
  );
208
221
  return false;
209
222
  }
@@ -215,7 +228,6 @@ export class GmailApiStrategy implements CommunicationStrategy {
215
228
  bcc?: string,
216
229
  subject?: string,
217
230
  message?: string,
218
- html?: string,
219
231
  ): string {
220
232
  const emailLines = [`To: ${to}`, `Subject: ${subject || 'Notification'}`];
221
233
 
@@ -230,11 +242,7 @@ export class GmailApiStrategy implements CommunicationStrategy {
230
242
  emailLines.push('Content-Type: text/html; charset=utf-8');
231
243
  emailLines.push('');
232
244
 
233
- if (html) {
234
- emailLines.push(html);
235
- } else {
236
- emailLines.push(message || '');
237
- }
245
+ emailLines.push(message || '');
238
246
 
239
247
  return emailLines.join('\n');
240
248
  }
@@ -245,7 +253,6 @@ export class GmailApiStrategy implements CommunicationStrategy {
245
253
  bcc?: string,
246
254
  subject?: string,
247
255
  message?: string,
248
- html?: string,
249
256
  attachments?: EmailAttachment[],
250
257
  ): string {
251
258
  const boundary = `----GmailBoundary${Date.now()}${Math.random().toString(36).substr(2, 9)}`;
@@ -268,11 +275,7 @@ export class GmailApiStrategy implements CommunicationStrategy {
268
275
  emailLines.push('Content-Type: text/html; charset=utf-8');
269
276
  emailLines.push('');
270
277
 
271
- if (html) {
272
- emailLines.push(html);
273
- } else {
274
- emailLines.push(message || '');
275
- }
278
+ emailLines.push(message || '');
276
279
 
277
280
  // Add attachment parts
278
281
  if (attachments) {
@@ -3,7 +3,7 @@ import * as nodemailer from 'nodemailer';
3
3
  import {
4
4
  CommunicationStrategy,
5
5
  CommunicationResult,
6
- } from './communication.strategy';
6
+ } from '../communication.strategy';
7
7
 
8
8
  @Injectable()
9
9
  export class GmailSMTPStrategy implements CommunicationStrategy {
@@ -3,7 +3,7 @@ import * as nodemailer from 'nodemailer';
3
3
  import {
4
4
  CommunicationStrategy,
5
5
  CommunicationResult,
6
- } from './communication.strategy';
6
+ } from '../communication.strategy';
7
7
 
8
8
  @Injectable()
9
9
  export class OutlookSMTPStrategy implements CommunicationStrategy {
@@ -3,7 +3,7 @@ import { Client } from '@microsoft/microsoft-graph-client';
3
3
  import {
4
4
  CommunicationStrategy,
5
5
  CommunicationResult,
6
- } from './communication.strategy';
6
+ } from '../communication.strategy';
7
7
 
8
8
  @Injectable()
9
9
  export class OutlookStrategy implements CommunicationStrategy {
@@ -48,14 +48,7 @@ export class SendGridApiStrategy implements CommunicationStrategy {
48
48
  }
49
49
  } else {
50
50
  // Regular email content
51
- if (html && message) {
52
- mailData.html = html;
53
- mailData.text = message;
54
- } else if (html) {
55
- mailData.html = html;
56
- } else {
57
- mailData.text = message || 'Hello from SendGrid!';
58
- }
51
+ mailData.html = message || 'Hello from SendGrid!';
59
52
  }
60
53
 
61
54
  // Add CC/BCC if provided
@@ -68,7 +61,12 @@ export class SendGridApiStrategy implements CommunicationStrategy {
68
61
 
69
62
  // Handle attachments with validation
70
63
  if (config.attachments) {
71
- EmailAttachmentValidator.validate(config.attachments, 30 * 1024 * 1024, 'SendGrid');
64
+ //FIXME: Temporarily disable attachment validation to allow larger files
65
+ // EmailAttachmentValidator.validate(
66
+ // config.attachments,
67
+ // 30 * 1024 * 1024,
68
+ // 'SendGrid',
69
+ // );
72
70
  mailData.attachments = this.convertAttachmentsToSendGridFormat(
73
71
  config.attachments,
74
72
  );
@@ -3,7 +3,7 @@ import axios from 'axios';
3
3
  import {
4
4
  CommunicationStrategy,
5
5
  CommunicationResult,
6
- } from './communication.strategy';
6
+ } from '../communication.strategy';
7
7
 
8
8
  @Injectable()
9
9
  export class KnowlarityStrategy implements CommunicationStrategy {
@@ -3,7 +3,7 @@ import { Twilio } from 'twilio';
3
3
  import {
4
4
  CommunicationStrategy,
5
5
  CommunicationResult,
6
- } from './communication.strategy';
6
+ } from '../communication.strategy';
7
7
 
8
8
  @Injectable()
9
9
  export class SmsStrategy implements CommunicationStrategy {