rez_core 2.2.192 → 2.2.193
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.
- package/dist/module/communication/controller/communication.controller.d.ts +11 -4
- package/dist/module/communication/controller/communication.controller.js +14 -6
- package/dist/module/communication/controller/communication.controller.js.map +1 -1
- package/dist/module/communication/dto/create-config.dto.d.ts +16 -1
- package/dist/module/communication/dto/create-config.dto.js +51 -2
- package/dist/module/communication/dto/create-config.dto.js.map +1 -1
- package/dist/module/communication/service/communication.service.d.ts +20 -1
- package/dist/module/communication/service/communication.service.js +93 -2
- package/dist/module/communication/service/communication.service.js.map +1 -1
- package/dist/module/communication/service/wrapper.service.d.ts +28 -0
- package/dist/module/communication/service/wrapper.service.js +151 -0
- package/dist/module/communication/service/wrapper.service.js.map +1 -0
- package/dist/module/communication/strategies/communication.strategy.d.ts +12 -1
- package/dist/module/communication/strategies/communication.strategy.js +37 -0
- package/dist/module/communication/strategies/communication.strategy.js.map +1 -1
- package/dist/module/communication/strategies/email/gmail-api.strategy.d.ts +2 -0
- package/dist/module/communication/strategies/email/gmail-api.strategy.js +64 -20
- package/dist/module/communication/strategies/email/gmail-api.strategy.js.map +1 -1
- package/dist/module/communication/strategies/email/sendgrid-api.strategy.d.ts +10 -0
- package/dist/module/communication/strategies/email/sendgrid-api.strategy.js +61 -1
- package/dist/module/communication/strategies/email/sendgrid-api.strategy.js.map +1 -1
- package/dist/module/workflow/service/populate-workflow.service.js +1 -1
- package/dist/module/workflow/service/populate-workflow.service.js.map +1 -1
- package/dist/module/workflow/service/task.service.js +3 -0
- package/dist/module/workflow/service/task.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/communication/controller/communication.controller.ts +14 -3
- package/src/module/communication/dto/create-config.dto.ts +38 -1
- package/src/module/communication/service/communication.service.ts +157 -3
- package/src/module/communication/service/wrapper.service.ts +185 -0
- package/src/module/communication/strategies/communication.strategy.ts +63 -1
- package/src/module/communication/strategies/email/gmail-api.strategy.ts +121 -24
- package/src/module/communication/strategies/email/sendgrid-api.strategy.ts +82 -2
- package/src/module/workflow/service/populate-workflow.service.ts +1 -1
- package/src/module/workflow/service/task.service.ts +3 -1
|
@@ -4,6 +4,8 @@ import axios from 'axios';
|
|
|
4
4
|
import {
|
|
5
5
|
CommunicationStrategy,
|
|
6
6
|
CommunicationResult,
|
|
7
|
+
EmailAttachment,
|
|
8
|
+
EmailAttachmentValidator,
|
|
7
9
|
} from '../communication.strategy';
|
|
8
10
|
|
|
9
11
|
@Injectable()
|
|
@@ -21,11 +23,16 @@ export class GmailApiStrategy implements CommunicationStrategy {
|
|
|
21
23
|
);
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
const { subject, html, cc, bcc } = config;
|
|
26
|
+
const { subject, html, cc, bcc, attachments } = config;
|
|
25
27
|
|
|
26
28
|
console.log('---- Using HTTP Gmail API ----');
|
|
27
29
|
console.log('Always refreshing token before send...');
|
|
28
30
|
|
|
31
|
+
// Validate attachments if present
|
|
32
|
+
if (attachments && attachments.length > 0) {
|
|
33
|
+
EmailAttachmentValidator.validate(attachments, 25 * 1024 * 1024, 'Gmail');
|
|
34
|
+
}
|
|
35
|
+
|
|
29
36
|
// ALWAYS refresh token first - no expiration checking
|
|
30
37
|
const freshAccessToken = await this.refreshAccessToken(config);
|
|
31
38
|
|
|
@@ -43,29 +50,26 @@ export class GmailApiStrategy implements CommunicationStrategy {
|
|
|
43
50
|
: bcc
|
|
44
51
|
: undefined;
|
|
45
52
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const emailContent = emailLines.join('\n');
|
|
53
|
+
// Build email content with or without attachments
|
|
54
|
+
const emailContent =
|
|
55
|
+
attachments && attachments.length > 0
|
|
56
|
+
? this.buildMultipartEmail(
|
|
57
|
+
toRecipients,
|
|
58
|
+
ccRecipients,
|
|
59
|
+
bccRecipients,
|
|
60
|
+
subject,
|
|
61
|
+
message,
|
|
62
|
+
html,
|
|
63
|
+
attachments,
|
|
64
|
+
)
|
|
65
|
+
: this.buildSimpleEmail(
|
|
66
|
+
toRecipients,
|
|
67
|
+
ccRecipients,
|
|
68
|
+
bccRecipients,
|
|
69
|
+
subject,
|
|
70
|
+
message,
|
|
71
|
+
html,
|
|
72
|
+
);
|
|
69
73
|
const encodedMessage = Buffer.from(emailContent)
|
|
70
74
|
.toString('base64')
|
|
71
75
|
.replace(/\+/g, '-')
|
|
@@ -204,4 +208,97 @@ export class GmailApiStrategy implements CommunicationStrategy {
|
|
|
204
208
|
return false;
|
|
205
209
|
}
|
|
206
210
|
}
|
|
211
|
+
|
|
212
|
+
private buildSimpleEmail(
|
|
213
|
+
to: string,
|
|
214
|
+
cc?: string,
|
|
215
|
+
bcc?: string,
|
|
216
|
+
subject?: string,
|
|
217
|
+
message?: string,
|
|
218
|
+
html?: string,
|
|
219
|
+
): string {
|
|
220
|
+
const emailLines = [`To: ${to}`, `Subject: ${subject || 'Notification'}`];
|
|
221
|
+
|
|
222
|
+
if (cc) {
|
|
223
|
+
emailLines.push(`Cc: ${cc}`);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (bcc) {
|
|
227
|
+
emailLines.push(`Bcc: ${bcc}`);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
emailLines.push('Content-Type: text/html; charset=utf-8');
|
|
231
|
+
emailLines.push('');
|
|
232
|
+
|
|
233
|
+
if (html) {
|
|
234
|
+
emailLines.push(html);
|
|
235
|
+
} else {
|
|
236
|
+
emailLines.push(message || '');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return emailLines.join('\n');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
private buildMultipartEmail(
|
|
243
|
+
to: string,
|
|
244
|
+
cc?: string,
|
|
245
|
+
bcc?: string,
|
|
246
|
+
subject?: string,
|
|
247
|
+
message?: string,
|
|
248
|
+
html?: string,
|
|
249
|
+
attachments?: EmailAttachment[],
|
|
250
|
+
): string {
|
|
251
|
+
const boundary = `----GmailBoundary${Date.now()}${Math.random().toString(36).substr(2, 9)}`;
|
|
252
|
+
|
|
253
|
+
const emailLines = [`To: ${to}`, `Subject: ${subject || 'Notification'}`];
|
|
254
|
+
|
|
255
|
+
if (cc) {
|
|
256
|
+
emailLines.push(`Cc: ${cc}`);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (bcc) {
|
|
260
|
+
emailLines.push(`Bcc: ${bcc}`);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
emailLines.push(`Content-Type: multipart/mixed; boundary="${boundary}"`);
|
|
264
|
+
emailLines.push('');
|
|
265
|
+
|
|
266
|
+
// Add main content part
|
|
267
|
+
emailLines.push(`--${boundary}`);
|
|
268
|
+
emailLines.push('Content-Type: text/html; charset=utf-8');
|
|
269
|
+
emailLines.push('');
|
|
270
|
+
|
|
271
|
+
if (html) {
|
|
272
|
+
emailLines.push(html);
|
|
273
|
+
} else {
|
|
274
|
+
emailLines.push(message || '');
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// Add attachment parts
|
|
278
|
+
if (attachments) {
|
|
279
|
+
for (const attachment of attachments) {
|
|
280
|
+
emailLines.push(`--${boundary}`);
|
|
281
|
+
emailLines.push(`Content-Type: ${attachment.contentType}`);
|
|
282
|
+
emailLines.push(
|
|
283
|
+
`Content-Disposition: ${attachment.disposition || 'attachment'}; filename="${attachment.filename}"`,
|
|
284
|
+
);
|
|
285
|
+
emailLines.push('Content-Transfer-Encoding: base64');
|
|
286
|
+
|
|
287
|
+
if (attachment.contentId) {
|
|
288
|
+
emailLines.push(`Content-ID: <${attachment.contentId}>`);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
emailLines.push('');
|
|
292
|
+
|
|
293
|
+
// Add base64 content in chunks of 76 characters (RFC 2045)
|
|
294
|
+
const base64Content = attachment.content;
|
|
295
|
+
const chunks = base64Content.match(/.{1,76}/g) || [];
|
|
296
|
+
emailLines.push(...chunks);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
emailLines.push(`--${boundary}--`);
|
|
301
|
+
|
|
302
|
+
return emailLines.join('\n');
|
|
303
|
+
}
|
|
207
304
|
}
|
|
@@ -4,6 +4,8 @@ import axios from 'axios';
|
|
|
4
4
|
import {
|
|
5
5
|
CommunicationStrategy,
|
|
6
6
|
CommunicationResult,
|
|
7
|
+
EmailAttachment,
|
|
8
|
+
EmailAttachmentValidator,
|
|
7
9
|
} from '../communication.strategy';
|
|
8
10
|
|
|
9
11
|
@Injectable()
|
|
@@ -64,9 +66,12 @@ export class SendGridApiStrategy implements CommunicationStrategy {
|
|
|
64
66
|
mailData.bcc = Array.isArray(config.bcc) ? config.bcc : [config.bcc];
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
//
|
|
69
|
+
// Handle attachments with validation
|
|
68
70
|
if (config.attachments) {
|
|
69
|
-
|
|
71
|
+
EmailAttachmentValidator.validate(config.attachments, 30 * 1024 * 1024, 'SendGrid');
|
|
72
|
+
mailData.attachments = this.convertAttachmentsToSendGridFormat(
|
|
73
|
+
config.attachments,
|
|
74
|
+
);
|
|
70
75
|
}
|
|
71
76
|
if (config.categories) {
|
|
72
77
|
mailData.categories = Array.isArray(config.categories)
|
|
@@ -179,4 +184,79 @@ export class SendGridApiStrategy implements CommunicationStrategy {
|
|
|
179
184
|
};
|
|
180
185
|
}
|
|
181
186
|
}
|
|
187
|
+
|
|
188
|
+
async getTemplates(apiKey: string): Promise<{
|
|
189
|
+
success: boolean;
|
|
190
|
+
data?: Array<{
|
|
191
|
+
id: string;
|
|
192
|
+
name: string;
|
|
193
|
+
generation: string;
|
|
194
|
+
}>;
|
|
195
|
+
error?: string;
|
|
196
|
+
}> {
|
|
197
|
+
try {
|
|
198
|
+
if (!apiKey) {
|
|
199
|
+
throw new Error('SendGrid API key is required');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const response = await axios.get(
|
|
203
|
+
'https://api.sendgrid.com/v3/templates?generations=dynamic',
|
|
204
|
+
{
|
|
205
|
+
headers: {
|
|
206
|
+
Authorization: `Bearer ${apiKey}`,
|
|
207
|
+
'Content-Type': 'application/json',
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
const templates = response.data.result || response.data.templates || [];
|
|
213
|
+
|
|
214
|
+
// Format the response for dropdown usage
|
|
215
|
+
const formattedTemplates = templates
|
|
216
|
+
.filter((template: any) => template.generation === 'dynamic')
|
|
217
|
+
.map((template: any) => ({
|
|
218
|
+
id: template.id,
|
|
219
|
+
name: template.name || `Template ${template.id}`,
|
|
220
|
+
generation: template.generation,
|
|
221
|
+
}));
|
|
222
|
+
|
|
223
|
+
return {
|
|
224
|
+
success: true,
|
|
225
|
+
data: formattedTemplates,
|
|
226
|
+
};
|
|
227
|
+
} catch (error) {
|
|
228
|
+
let errorMessage = 'Failed to fetch templates';
|
|
229
|
+
|
|
230
|
+
if (error.response?.status === 401) {
|
|
231
|
+
errorMessage = 'Invalid SendGrid API key';
|
|
232
|
+
} else if (error.response?.status === 403) {
|
|
233
|
+
errorMessage = 'SendGrid API key does not have required permissions';
|
|
234
|
+
} else if (error.response?.data?.errors) {
|
|
235
|
+
errorMessage = error.response.data.errors
|
|
236
|
+
.map((err: any) => err.message)
|
|
237
|
+
.join(', ');
|
|
238
|
+
} else if (error.response?.data?.message) {
|
|
239
|
+
errorMessage = error.response.data.message;
|
|
240
|
+
} else if (error.message) {
|
|
241
|
+
errorMessage = error.message;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
success: false,
|
|
246
|
+
error: errorMessage,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
private convertAttachmentsToSendGridFormat(
|
|
252
|
+
attachments: EmailAttachment[],
|
|
253
|
+
): any[] {
|
|
254
|
+
return attachments.map((attachment) => ({
|
|
255
|
+
content: attachment.content,
|
|
256
|
+
filename: attachment.filename,
|
|
257
|
+
type: attachment.contentType,
|
|
258
|
+
disposition: attachment.disposition || 'attachment',
|
|
259
|
+
content_id: attachment.contentId,
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
182
262
|
}
|
|
@@ -308,7 +308,7 @@ export class PopulateWorkflowService extends EntityServiceImpl {
|
|
|
308
308
|
organization_id,
|
|
309
309
|
action_requirement: matchedNewMandatory?.id ?? null,
|
|
310
310
|
level_id: organization_id,
|
|
311
|
-
entity_type: '
|
|
311
|
+
entity_type: 'WFA',
|
|
312
312
|
form: formActionCategory.length > 0 ? formViewMaster[0]?.id : null,
|
|
313
313
|
status: statusValue,
|
|
314
314
|
},
|
|
@@ -462,8 +462,10 @@ export class TaskService extends EntityServiceImpl {
|
|
|
462
462
|
[completedId, now, in30Min],
|
|
463
463
|
);
|
|
464
464
|
|
|
465
|
+
if (tasks.length > 0) console.log('Tasks due in 30 mins', tasks);
|
|
466
|
+
|
|
465
467
|
if (!tasks.length) {
|
|
466
|
-
|
|
468
|
+
console.log('No tasks due in 30 mins');
|
|
467
469
|
return;
|
|
468
470
|
}
|
|
469
471
|
|