rez_core 2.2.181 → 2.2.182
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.js.map +1 -1
- package/dist/module/communication/service/communication.service.d.ts +2 -2
- package/dist/module/communication/service/communication.service.js +31 -10
- package/dist/module/communication/service/communication.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 +2 -1
- package/src/module/communication/service/communication.service.ts +86 -41
package/package.json
CHANGED
|
@@ -85,7 +85,8 @@ export class CommunicationController {
|
|
|
85
85
|
async getLevelConfigs(
|
|
86
86
|
@Param('id', ParseIntPipe) levelId: number,
|
|
87
87
|
@Param('type') levelType: string,
|
|
88
|
-
@Query('communication_config_type')
|
|
88
|
+
@Query('communication_config_type')
|
|
89
|
+
configType?: 'WA' | 'SMS' | 'EMAIL' | 'TELEPHONE',
|
|
89
90
|
@Query('service') service?: 'API' | 'THIRD_PARTY' | 'SMTP',
|
|
90
91
|
@Query('provider') provider?: string,
|
|
91
92
|
) {
|
|
@@ -146,7 +146,11 @@ export class CommunicationService {
|
|
|
146
146
|
): Promise<CommunicationHubWithConfig[]> {
|
|
147
147
|
let query = this.hubRepository
|
|
148
148
|
.createQueryBuilder('hub')
|
|
149
|
-
.leftJoin(
|
|
149
|
+
.leftJoin(
|
|
150
|
+
'cr_communication_config',
|
|
151
|
+
'config',
|
|
152
|
+
'config.id = hub.config_id',
|
|
153
|
+
)
|
|
150
154
|
.select([
|
|
151
155
|
'hub.id as hub_id',
|
|
152
156
|
'hub.level_id as hub_level_id',
|
|
@@ -219,7 +223,11 @@ export class CommunicationService {
|
|
|
219
223
|
hub.provider,
|
|
220
224
|
);
|
|
221
225
|
|
|
222
|
-
const result = await strategy.sendMessage(
|
|
226
|
+
const result = await strategy.sendMessage(
|
|
227
|
+
to,
|
|
228
|
+
message,
|
|
229
|
+
hub.config.config_json,
|
|
230
|
+
);
|
|
223
231
|
|
|
224
232
|
// If token was refreshed, update it in the database
|
|
225
233
|
if (result.refreshedToken && result.success) {
|
|
@@ -229,11 +237,11 @@ export class CommunicationService {
|
|
|
229
237
|
...currentConfig,
|
|
230
238
|
accessToken: result.refreshedToken,
|
|
231
239
|
};
|
|
232
|
-
|
|
240
|
+
|
|
233
241
|
await this.configRepository.update(hub.config.id, {
|
|
234
242
|
config_json: updatedConfig,
|
|
235
243
|
} as any);
|
|
236
|
-
|
|
244
|
+
|
|
237
245
|
this.logger.log(
|
|
238
246
|
`Updated access token for ${hub.provider}/${hub.service} configuration`,
|
|
239
247
|
);
|
|
@@ -309,13 +317,11 @@ export class CommunicationService {
|
|
|
309
317
|
);
|
|
310
318
|
}
|
|
311
319
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}[]
|
|
318
|
-
> {
|
|
320
|
+
getSupportedCombinations(): {
|
|
321
|
+
mode: string;
|
|
322
|
+
service: string;
|
|
323
|
+
provider: string;
|
|
324
|
+
}[] {
|
|
319
325
|
return this.communicationFactory.getAllSupportedCombinations();
|
|
320
326
|
}
|
|
321
327
|
|
|
@@ -327,7 +333,9 @@ export class CommunicationService {
|
|
|
327
333
|
service?: 'API' | 'THIRD_PARTY' | 'SMTP';
|
|
328
334
|
provider?: string;
|
|
329
335
|
},
|
|
330
|
-
): Promise<
|
|
336
|
+
): Promise<
|
|
337
|
+
Array<CommunicationHub & { linkedSource?: string; configDetails?: any }>
|
|
338
|
+
> {
|
|
331
339
|
const where: any = { level_id: levelId, level_type: levelType, status: 1 };
|
|
332
340
|
|
|
333
341
|
if (filters?.communication_config_type) {
|
|
@@ -421,25 +429,25 @@ export class CommunicationService {
|
|
|
421
429
|
|
|
422
430
|
// WhatsApp configurations
|
|
423
431
|
case 'wa_api_whatsapp':
|
|
424
|
-
return configJson?.phoneNumberId
|
|
425
|
-
? `WhatsApp Business: ${configJson.phoneNumberId}`
|
|
432
|
+
return configJson?.phoneNumberId
|
|
433
|
+
? `WhatsApp Business: ${configJson.phoneNumberId}`
|
|
426
434
|
: 'WhatsApp not configured';
|
|
427
435
|
|
|
428
436
|
// SMS configurations
|
|
429
437
|
case 'sms_third_party_twilio':
|
|
430
|
-
return configJson?.fromNumber
|
|
431
|
-
? `Twilio: ${configJson.fromNumber}`
|
|
438
|
+
return configJson?.fromNumber
|
|
439
|
+
? `Twilio: ${configJson.fromNumber}`
|
|
432
440
|
: 'Twilio number not configured';
|
|
433
441
|
|
|
434
442
|
case 'sms_third_party_knowlarity':
|
|
435
|
-
return configJson?.callerNumber
|
|
436
|
-
? `Knowlarity: ${configJson.callerNumber}`
|
|
443
|
+
return configJson?.callerNumber
|
|
444
|
+
? `Knowlarity: ${configJson.callerNumber}`
|
|
437
445
|
: 'Knowlarity number not configured';
|
|
438
446
|
|
|
439
447
|
// Telephone configurations
|
|
440
448
|
case 'telephone_third_party_knowlarity':
|
|
441
|
-
return configJson?.callerNumber
|
|
442
|
-
? `Knowlarity Voice: ${configJson.callerNumber}`
|
|
449
|
+
return configJson?.callerNumber
|
|
450
|
+
? `Knowlarity Voice: ${configJson.callerNumber}`
|
|
443
451
|
: 'Knowlarity voice number not configured';
|
|
444
452
|
|
|
445
453
|
// AWS SES configurations
|
|
@@ -464,7 +472,7 @@ export class CommunicationService {
|
|
|
464
472
|
if (configJson?.phoneNumberId) return configJson.phoneNumberId;
|
|
465
473
|
if (configJson?.fromNumber) return configJson.fromNumber;
|
|
466
474
|
if (configJson?.callerNumber) return configJson.callerNumber;
|
|
467
|
-
|
|
475
|
+
|
|
468
476
|
return `${provider} configured`;
|
|
469
477
|
}
|
|
470
478
|
} catch (error) {
|
|
@@ -488,7 +496,9 @@ export class CommunicationService {
|
|
|
488
496
|
email: configJson?.email,
|
|
489
497
|
authMethod: configJson?.authMethod || 'OAUTH2',
|
|
490
498
|
hasRefreshToken: !!configJson?.refreshToken,
|
|
491
|
-
isExpired: configJson?.expiryDate
|
|
499
|
+
isExpired: configJson?.expiryDate
|
|
500
|
+
? new Date(configJson.expiryDate) < new Date()
|
|
501
|
+
: false,
|
|
492
502
|
};
|
|
493
503
|
|
|
494
504
|
case 'email_smtp_gmail':
|
|
@@ -498,7 +508,7 @@ export class CommunicationService {
|
|
|
498
508
|
hasPassword: !!configJson?.password,
|
|
499
509
|
};
|
|
500
510
|
|
|
501
|
-
// Outlook configurations
|
|
511
|
+
// Outlook configurations
|
|
502
512
|
case 'email_api_outlook':
|
|
503
513
|
return {
|
|
504
514
|
email: configJson?.email,
|
|
@@ -526,7 +536,9 @@ export class CommunicationService {
|
|
|
526
536
|
case 'sms_third_party_twilio':
|
|
527
537
|
return {
|
|
528
538
|
fromNumber: configJson?.fromNumber,
|
|
529
|
-
accountSid: configJson?.accountSid
|
|
539
|
+
accountSid: configJson?.accountSid
|
|
540
|
+
? configJson.accountSid.substring(0, 8) + '...'
|
|
541
|
+
: null,
|
|
530
542
|
hasAuthToken: !!configJson?.authToken,
|
|
531
543
|
};
|
|
532
544
|
|
|
@@ -552,7 +564,9 @@ export class CommunicationService {
|
|
|
552
564
|
return {
|
|
553
565
|
fromEmail: configJson?.fromEmail,
|
|
554
566
|
region: configJson?.region,
|
|
555
|
-
hasCredentials: !!(
|
|
567
|
+
hasCredentials: !!(
|
|
568
|
+
configJson?.accessKeyId && configJson?.secretAccessKey
|
|
569
|
+
),
|
|
556
570
|
};
|
|
557
571
|
|
|
558
572
|
// SendGrid configurations
|
|
@@ -577,15 +591,26 @@ export class CommunicationService {
|
|
|
577
591
|
default:
|
|
578
592
|
// Generic details - return safe subset of config
|
|
579
593
|
const safeConfig: any = {};
|
|
580
|
-
|
|
594
|
+
|
|
581
595
|
// Include non-sensitive fields
|
|
582
596
|
const safeFields = [
|
|
583
|
-
'email',
|
|
584
|
-
'
|
|
585
|
-
'
|
|
597
|
+
'email',
|
|
598
|
+
'from',
|
|
599
|
+
'user',
|
|
600
|
+
'host',
|
|
601
|
+
'port',
|
|
602
|
+
'secure',
|
|
603
|
+
'phoneNumberId',
|
|
604
|
+
'fromNumber',
|
|
605
|
+
'callerNumber',
|
|
606
|
+
'region',
|
|
607
|
+
'apiVersion',
|
|
608
|
+
'callType',
|
|
609
|
+
'language',
|
|
610
|
+
'templateId',
|
|
586
611
|
];
|
|
587
|
-
|
|
588
|
-
safeFields.forEach(field => {
|
|
612
|
+
|
|
613
|
+
safeFields.forEach((field) => {
|
|
589
614
|
if (configJson?.[field]) {
|
|
590
615
|
safeConfig[field] = configJson[field];
|
|
591
616
|
}
|
|
@@ -593,13 +618,21 @@ export class CommunicationService {
|
|
|
593
618
|
|
|
594
619
|
// Include boolean indicators for sensitive fields
|
|
595
620
|
const sensitiveFields = [
|
|
596
|
-
'accessToken',
|
|
597
|
-
'
|
|
621
|
+
'accessToken',
|
|
622
|
+
'refreshToken',
|
|
623
|
+
'password',
|
|
624
|
+
'authToken',
|
|
625
|
+
'apiKey',
|
|
626
|
+
'apiSecret',
|
|
627
|
+
'clientSecret',
|
|
628
|
+
'secretAccessKey',
|
|
598
629
|
];
|
|
599
|
-
|
|
600
|
-
sensitiveFields.forEach(field => {
|
|
630
|
+
|
|
631
|
+
sensitiveFields.forEach((field) => {
|
|
601
632
|
if (configJson?.[field]) {
|
|
602
|
-
safeConfig[
|
|
633
|
+
safeConfig[
|
|
634
|
+
`has${field.charAt(0).toUpperCase() + field.slice(1)}`
|
|
635
|
+
] = true;
|
|
603
636
|
}
|
|
604
637
|
});
|
|
605
638
|
|
|
@@ -647,7 +680,7 @@ export class CommunicationService {
|
|
|
647
680
|
|
|
648
681
|
if (!hubs.length) {
|
|
649
682
|
this.logger.warn(
|
|
650
|
-
`No communication hubs found for ${levelType} ${levelId}. Please configure communication providers using the createCommunicationConfig method
|
|
683
|
+
`No communication hubs found for ${levelType} ${levelId}. Please configure communication providers using the createCommunicationConfig method.`,
|
|
651
684
|
);
|
|
652
685
|
throw new Error(
|
|
653
686
|
`No active ${communicationType} configuration found for ${levelType} ${levelId}. Please configure a communication provider first.`,
|
|
@@ -1555,7 +1588,11 @@ export class CommunicationService {
|
|
|
1555
1588
|
|
|
1556
1589
|
async queueMessage(
|
|
1557
1590
|
messageDto: GenericMessageDto & { useQueue?: boolean; scheduledFor?: Date },
|
|
1558
|
-
): Promise<{
|
|
1591
|
+
): Promise<{
|
|
1592
|
+
queued: boolean;
|
|
1593
|
+
messageId?: string;
|
|
1594
|
+
result?: CommunicationResult;
|
|
1595
|
+
}> {
|
|
1559
1596
|
if (!this.queueService || !messageDto.useQueue) {
|
|
1560
1597
|
// Fallback to immediate sending if queue is not available or not requested
|
|
1561
1598
|
const result = await this.sendGenericMessage(messageDto);
|
|
@@ -1587,7 +1624,10 @@ export class CommunicationService {
|
|
|
1587
1624
|
|
|
1588
1625
|
return { queued: true, messageId };
|
|
1589
1626
|
} catch (error) {
|
|
1590
|
-
this.logger.error(
|
|
1627
|
+
this.logger.error(
|
|
1628
|
+
'Error queuing message, falling back to immediate send:',
|
|
1629
|
+
error.message,
|
|
1630
|
+
);
|
|
1591
1631
|
// Fallback to immediate sending
|
|
1592
1632
|
const result = await this.sendGenericMessage(messageDto);
|
|
1593
1633
|
return { queued: false, result };
|
|
@@ -1623,7 +1663,10 @@ export class CommunicationService {
|
|
|
1623
1663
|
|
|
1624
1664
|
return { queued: true, messageIds };
|
|
1625
1665
|
} catch (error) {
|
|
1626
|
-
this.logger.error(
|
|
1666
|
+
this.logger.error(
|
|
1667
|
+
'Error queuing bulk message, falling back to immediate send:',
|
|
1668
|
+
error.message,
|
|
1669
|
+
);
|
|
1627
1670
|
// Fallback to immediate sending
|
|
1628
1671
|
const result = await this.sendBulkMessage(bulkDto);
|
|
1629
1672
|
return { queued: false, result };
|
|
@@ -1653,7 +1696,9 @@ export class CommunicationService {
|
|
|
1653
1696
|
return this.queueService.cancelMessage(messageId);
|
|
1654
1697
|
}
|
|
1655
1698
|
|
|
1656
|
-
private mapPriorityToSimpleQueue(
|
|
1699
|
+
private mapPriorityToSimpleQueue(
|
|
1700
|
+
priority?: string,
|
|
1701
|
+
): 'high' | 'medium' | 'low' {
|
|
1657
1702
|
switch (priority?.toLowerCase()) {
|
|
1658
1703
|
case 'high':
|
|
1659
1704
|
case 'urgent':
|