rez_core 2.2.258 → 2.2.259
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/app.module.js +2 -2
- package/dist/app.module.js.map +1 -1
- package/dist/module/integration/controller/calender-event.controller.js.map +1 -0
- package/dist/module/integration/controller/integration.controller.d.ts +113 -0
- package/dist/module/{communication/controller/communication.controller.js → integration/controller/integration.controller.js} +197 -75
- package/dist/module/integration/controller/integration.controller.js.map +1 -0
- package/dist/module/{communication → integration}/controller/wrapper.controller.d.ts +1 -1
- package/dist/module/integration/controller/wrapper.controller.js.map +1 -0
- package/dist/module/{communication → integration}/dto/create-config.dto.d.ts +48 -4
- package/dist/module/{communication → integration}/dto/create-config.dto.js +96 -18
- package/dist/module/integration/dto/create-config.dto.js.map +1 -0
- package/dist/module/{communication/entity/communication-config.entity.d.ts → integration/entity/integration-config.entity.d.ts} +11 -1
- package/dist/module/integration/entity/integration-config.entity.js +78 -0
- package/dist/module/integration/entity/integration-config.entity.js.map +1 -0
- package/dist/module/{communication → integration}/entity/integration-source.entity.d.ts +1 -1
- package/dist/module/{communication → integration}/entity/integration-source.entity.js +8 -8
- package/dist/module/integration/entity/integration-source.entity.js.map +1 -0
- package/dist/module/integration/entity/user-integration.entity.d.ts +23 -0
- package/dist/module/integration/entity/user-integration.entity.js +70 -0
- package/dist/module/integration/entity/user-integration.entity.js.map +1 -0
- package/dist/module/integration/examples/usage.example.d.ts +16 -0
- package/dist/module/integration/examples/usage.example.js +217 -0
- package/dist/module/integration/examples/usage.example.js.map +1 -0
- package/dist/module/{communication → integration}/factories/base.factory.d.ts +2 -2
- package/dist/module/integration/factories/base.factory.js.map +1 -0
- package/dist/module/{communication → integration}/factories/email.factory.d.ts +3 -7
- package/dist/module/{communication → integration}/factories/email.factory.js +1 -13
- package/dist/module/integration/factories/email.factory.js.map +1 -0
- package/dist/module/{communication/factories/communication.factory.d.ts → integration/factories/integration.factory.d.ts} +4 -4
- package/dist/module/{communication/factories/communication.factory.js → integration/factories/integration.factory.js} +26 -26
- package/dist/module/integration/factories/integration.factory.js.map +1 -0
- package/dist/module/integration/factories/sms.factory.d.ts +9 -0
- package/dist/module/integration/factories/sms.factory.js +26 -0
- package/dist/module/integration/factories/sms.factory.js.map +1 -0
- package/dist/module/{communication → integration}/factories/telephone.factory.d.ts +3 -5
- package/dist/module/{communication → integration}/factories/telephone.factory.js +11 -17
- package/dist/module/integration/factories/telephone.factory.js.map +1 -0
- package/dist/module/{communication → integration}/factories/whatsapp.factory.d.ts +2 -2
- package/dist/module/integration/factories/whatsapp.factory.js.map +1 -0
- package/dist/module/integration/integration.module.d.ts +2 -0
- package/dist/module/{communication/communication.module.js → integration/integration.module.js} +22 -42
- package/dist/module/integration/integration.module.js.map +1 -0
- package/dist/module/integration/service/calendar-event.service.js.map +1 -0
- package/dist/module/{communication/service/communication-queue.service.d.ts → integration/service/integration-queue.service.d.ts} +1 -1
- package/dist/module/{communication/service/communication-queue.service.js → integration/service/integration-queue.service.js} +8 -8
- package/dist/module/integration/service/integration-queue.service.js.map +1 -0
- package/dist/module/integration/service/integration.service.d.ts +155 -0
- package/dist/module/{communication/service/communication.service.js → integration/service/integration.service.js} +391 -307
- package/dist/module/integration/service/integration.service.js.map +1 -0
- package/dist/module/{communication → integration}/service/oauth.service.js +1 -1
- package/dist/module/integration/service/oauth.service.js.map +1 -0
- package/dist/module/{communication → integration}/service/wrapper.service.d.ts +4 -4
- package/dist/module/{communication → integration}/service/wrapper.service.js +25 -26
- package/dist/module/integration/service/wrapper.service.js.map +1 -0
- package/dist/module/{communication → integration}/strategies/email/gmail-api.strategy.d.ts +3 -3
- package/dist/module/{communication → integration}/strategies/email/gmail-api.strategy.js +2 -6
- package/dist/module/integration/strategies/email/gmail-api.strategy.js.map +1 -0
- package/dist/module/integration/strategies/email/outlook-api.strategy.d.ts +5 -0
- package/dist/module/integration/strategies/email/outlook-api.strategy.js.map +1 -0
- package/dist/module/integration/strategies/email/outlook.strategy.d.ts +5 -0
- package/dist/module/integration/strategies/email/outlook.strategy.js.map +1 -0
- package/dist/module/{communication → integration}/strategies/email/sendgrid-api.strategy.d.ts +3 -3
- package/dist/module/integration/strategies/email/sendgrid-api.strategy.js.map +1 -0
- package/dist/module/{communication/strategies/communication.strategy.d.ts → integration/strategies/integration.strategy.d.ts} +4 -3
- package/dist/module/{communication/strategies/communication.strategy.js → integration/strategies/integration.strategy.js} +1 -1
- package/dist/module/integration/strategies/integration.strategy.js.map +1 -0
- package/dist/module/integration/strategies/telephone/ozonetel-voice.strategy.d.ts +17 -0
- package/dist/module/{communication → integration}/strategies/telephone/ozonetel-voice.strategy.js +13 -5
- package/dist/module/integration/strategies/telephone/ozonetel-voice.strategy.js.map +1 -0
- package/dist/module/{communication → integration}/strategies/telephone/tubelight-voice.strategy.d.ts +6 -4
- package/dist/module/{communication → integration}/strategies/telephone/tubelight-voice.strategy.js +3 -7
- package/dist/module/integration/strategies/telephone/tubelight-voice.strategy.js.map +1 -0
- package/dist/module/{communication → integration}/strategies/whatsapp/whatsapp-cloud.strategy.d.ts +3 -3
- package/dist/module/integration/strategies/whatsapp/whatsapp-cloud.strategy.js.map +1 -0
- package/dist/module/integration/strategies/whatsapp/whatsapp.strategy.d.ts +5 -0
- package/dist/module/integration/strategies/whatsapp/whatsapp.strategy.js.map +1 -0
- package/dist/module/meta/entity/entity-master.entity.d.ts +1 -1
- package/dist/module/meta/entity/entity-master.entity.js +2 -2
- package/dist/module/meta/entity/entity-master.entity.js.map +1 -1
- package/dist/module/meta/service/entity-dynamic.service.js +47 -27
- package/dist/module/meta/service/entity-dynamic.service.js.map +1 -1
- package/dist/module/user/controller/login.controller.d.ts +3 -3
- package/dist/module/user/controller/login.controller.js +5 -5
- package/dist/module/user/controller/login.controller.js.map +1 -1
- package/dist/module/user/user.module.js +2 -2
- package/dist/module/user/user.module.js.map +1 -1
- package/dist/module/workflow-automation/entity/workflow-automation-action.entity.d.ts +1 -0
- package/dist/module/workflow-automation/entity/workflow-automation-action.entity.js +4 -0
- package/dist/module/workflow-automation/entity/workflow-automation-action.entity.js.map +1 -1
- package/dist/module/workflow-automation/service/workflow-automation.service.d.ts +2 -1
- package/dist/module/workflow-automation/service/workflow-automation.service.js +8 -4
- package/dist/module/workflow-automation/service/workflow-automation.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/docs/modules/event-driven-integration-design.md +92 -0
- package/docs/modules/integration.md +197 -0
- package/package.json +1 -1
- package/src/app.module.ts +2 -2
- package/src/module/integration/controller/integration.controller.ts +411 -0
- package/src/module/{communication → integration}/dto/create-config.dto.ts +110 -18
- package/src/module/{communication/entity/communication-config.entity.ts → integration/entity/integration-config.entity.ts} +33 -6
- package/src/module/{communication → integration}/entity/integration-source.entity.ts +1 -1
- package/src/module/integration/entity/user-integration.entity.ts +71 -0
- package/src/module/integration/examples/usage.example.ts +338 -0
- package/src/module/{communication → integration}/factories/base.factory.ts +2 -2
- package/src/module/{communication → integration}/factories/email.factory.ts +2 -12
- package/src/module/{communication/factories/communication.factory.ts → integration/factories/integration.factory.ts} +18 -18
- package/src/module/integration/factories/sms.factory.ts +19 -0
- package/src/module/integration/factories/telephone.factory.ts +41 -0
- package/src/module/{communication → integration}/factories/whatsapp.factory.ts +2 -2
- package/src/module/integration/integration.module.ts +86 -0
- package/src/module/{communication/service/communication-queue.service.ts → integration/service/integration-queue.service.ts} +2 -2
- package/src/module/{communication/service/communication.service.ts → integration/service/integration.service.ts} +598 -448
- package/src/module/{communication → integration}/service/oauth.service.ts +1 -1
- package/src/module/{communication → integration}/service/wrapper.service.ts +24 -25
- package/src/module/{communication → integration}/strategies/email/gmail-api.strategy.ts +6 -18
- package/src/module/{communication → integration}/strategies/email/outlook-api.strategy.ts +5 -5
- package/src/module/{communication → integration}/strategies/email/outlook.strategy.ts +5 -5
- package/src/module/{communication → integration}/strategies/email/sendgrid-api.strategy.ts +5 -5
- package/src/module/{communication/strategies/communication.strategy.ts → integration/strategies/integration.strategy.ts} +7 -3
- package/src/module/{communication → integration}/strategies/telephone/ozonetel-voice.strategy.ts +40 -12
- package/src/module/{communication → integration}/strategies/telephone/tubelight-voice.strategy.ts +24 -17
- package/src/module/{communication → integration}/strategies/whatsapp/whatsapp-cloud.strategy.ts +5 -5
- package/src/module/{communication → integration}/strategies/whatsapp/whatsapp.strategy.ts +5 -5
- package/src/module/meta/entity/entity-master.entity.ts +2 -2
- package/src/module/meta/service/entity-dynamic.service.ts +55 -28
- package/src/module/user/controller/login.controller.ts +3 -3
- package/src/module/user/user.module.ts +2 -2
- package/src/module/workflow-automation/entity/workflow-automation-action.entity.ts +3 -0
- package/src/module/workflow-automation/service/workflow-automation.service.ts +8 -4
- package/src/resources/dev.properties.yaml +3 -3
- package/.vscode/extensions.json +0 -5
- package/dist/module/communication/communication.module.d.ts +0 -2
- package/dist/module/communication/communication.module.js.map +0 -1
- package/dist/module/communication/controller/calender-event.controller.js.map +0 -1
- package/dist/module/communication/controller/communication.controller.d.ts +0 -99
- package/dist/module/communication/controller/communication.controller.js.map +0 -1
- package/dist/module/communication/controller/wrapper.controller.js.map +0 -1
- package/dist/module/communication/dto/create-config.dto.js.map +0 -1
- package/dist/module/communication/entity/communication-config.entity.js +0 -45
- package/dist/module/communication/entity/communication-config.entity.js.map +0 -1
- package/dist/module/communication/entity/communication-hub.entity.d.ts +0 -20
- package/dist/module/communication/entity/communication-hub.entity.js +0 -115
- package/dist/module/communication/entity/communication-hub.entity.js.map +0 -1
- package/dist/module/communication/entity/integration-source.entity.js.map +0 -1
- package/dist/module/communication/examples/usage.example.d.ts +0 -11
- package/dist/module/communication/examples/usage.example.js +0 -89
- package/dist/module/communication/examples/usage.example.js.map +0 -1
- package/dist/module/communication/factories/base.factory.js.map +0 -1
- package/dist/module/communication/factories/communication.factory.js.map +0 -1
- package/dist/module/communication/factories/email.factory.js.map +0 -1
- package/dist/module/communication/factories/sms.factory.d.ts +0 -15
- package/dist/module/communication/factories/sms.factory.js +0 -49
- package/dist/module/communication/factories/sms.factory.js.map +0 -1
- package/dist/module/communication/factories/telephone.factory.js.map +0 -1
- package/dist/module/communication/factories/whatsapp.factory.js.map +0 -1
- package/dist/module/communication/service/calendar-event.service.js.map +0 -1
- package/dist/module/communication/service/communication-queue.service.js.map +0 -1
- package/dist/module/communication/service/communication.service.d.ts +0 -155
- package/dist/module/communication/service/communication.service.js.map +0 -1
- package/dist/module/communication/service/oauth.service.js.map +0 -1
- package/dist/module/communication/service/wrapper.service.js.map +0 -1
- package/dist/module/communication/strategies/communication.strategy.js.map +0 -1
- package/dist/module/communication/strategies/email/gmail-api.strategy.js.map +0 -1
- package/dist/module/communication/strategies/email/gmail-smtp-v2.strategy.d.ts +0 -5
- package/dist/module/communication/strategies/email/gmail-smtp-v2.strategy.js +0 -60
- package/dist/module/communication/strategies/email/gmail-smtp-v2.strategy.js.map +0 -1
- package/dist/module/communication/strategies/email/gmail-smtp.strategy.d.ts +0 -5
- package/dist/module/communication/strategies/email/gmail-smtp.strategy.js +0 -49
- package/dist/module/communication/strategies/email/gmail-smtp.strategy.js.map +0 -1
- package/dist/module/communication/strategies/email/outlook-api.strategy.d.ts +0 -5
- package/dist/module/communication/strategies/email/outlook-api.strategy.js.map +0 -1
- package/dist/module/communication/strategies/email/outlook-smtp.strategy.d.ts +0 -5
- package/dist/module/communication/strategies/email/outlook-smtp.strategy.js +0 -65
- package/dist/module/communication/strategies/email/outlook-smtp.strategy.js.map +0 -1
- package/dist/module/communication/strategies/email/outlook.strategy.d.ts +0 -5
- package/dist/module/communication/strategies/email/outlook.strategy.js.map +0 -1
- package/dist/module/communication/strategies/email/sendgrid-api.strategy.js.map +0 -1
- package/dist/module/communication/strategies/sms/knowlarity-multi.strategy.d.ts +0 -6
- package/dist/module/communication/strategies/sms/knowlarity-multi.strategy.js +0 -121
- package/dist/module/communication/strategies/sms/knowlarity-multi.strategy.js.map +0 -1
- package/dist/module/communication/strategies/sms/knowlarity.strategy.d.ts +0 -5
- package/dist/module/communication/strategies/sms/knowlarity.strategy.js +0 -44
- package/dist/module/communication/strategies/sms/knowlarity.strategy.js.map +0 -1
- package/dist/module/communication/strategies/sms/twilio-v2.strategy.d.ts +0 -5
- package/dist/module/communication/strategies/sms/twilio-v2.strategy.js +0 -48
- package/dist/module/communication/strategies/sms/twilio-v2.strategy.js.map +0 -1
- package/dist/module/communication/strategies/sms/twilio.strategy.d.ts +0 -5
- package/dist/module/communication/strategies/sms/twilio.strategy.js +0 -44
- package/dist/module/communication/strategies/sms/twilio.strategy.js.map +0 -1
- package/dist/module/communication/strategies/telephone/knowlarity-multi.strategy.d.ts +0 -6
- package/dist/module/communication/strategies/telephone/knowlarity-multi.strategy.js +0 -121
- package/dist/module/communication/strategies/telephone/knowlarity-multi.strategy.js.map +0 -1
- package/dist/module/communication/strategies/telephone/knowlarity-voice.strategy.d.ts +0 -5
- package/dist/module/communication/strategies/telephone/knowlarity-voice.strategy.js +0 -44
- package/dist/module/communication/strategies/telephone/knowlarity-voice.strategy.js.map +0 -1
- package/dist/module/communication/strategies/telephone/ozonetel-voice.strategy.d.ts +0 -15
- package/dist/module/communication/strategies/telephone/ozonetel-voice.strategy.js.map +0 -1
- package/dist/module/communication/strategies/telephone/tubelight-voice.strategy.js.map +0 -1
- package/dist/module/communication/strategies/whatsapp/whatsapp-cloud.strategy.js.map +0 -1
- package/dist/module/communication/strategies/whatsapp/whatsapp.strategy.d.ts +0 -5
- package/dist/module/communication/strategies/whatsapp/whatsapp.strategy.js.map +0 -1
- package/docs/modules/communication.md +0 -177
- package/src/module/communication/communication.module.ts +0 -106
- package/src/module/communication/controller/communication.controller.ts +0 -293
- package/src/module/communication/entity/communication-hub.entity.ts +0 -103
- package/src/module/communication/examples/usage.example.ts +0 -170
- package/src/module/communication/factories/sms.factory.ts +0 -44
- package/src/module/communication/factories/telephone.factory.ts +0 -49
- package/src/module/communication/strategies/email/gmail-smtp-v2.strategy.ts +0 -68
- package/src/module/communication/strategies/email/gmail-smtp.strategy.ts +0 -51
- package/src/module/communication/strategies/email/outlook-smtp.strategy.ts +0 -73
- package/src/module/communication/strategies/sms/knowlarity-multi.strategy.ts +0 -158
- package/src/module/communication/strategies/sms/knowlarity.strategy.ts +0 -44
- package/src/module/communication/strategies/sms/twilio-v2.strategy.ts +0 -47
- package/src/module/communication/strategies/sms/twilio.strategy.ts +0 -44
- package/src/module/communication/strategies/telephone/knowlarity-multi.strategy.ts +0 -158
- package/src/module/communication/strategies/telephone/knowlarity-voice.strategy.ts +0 -44
- /package/dist/module/{communication → integration}/controller/calender-event.controller.d.ts +0 -0
- /package/dist/module/{communication → integration}/controller/calender-event.controller.js +0 -0
- /package/dist/module/{communication → integration}/controller/wrapper.controller.js +0 -0
- /package/dist/module/{communication → integration}/factories/base.factory.js +0 -0
- /package/dist/module/{communication → integration}/factories/whatsapp.factory.js +0 -0
- /package/dist/module/{communication → integration}/service/calendar-event.service.d.ts +0 -0
- /package/dist/module/{communication → integration}/service/calendar-event.service.js +0 -0
- /package/dist/module/{communication → integration}/service/oauth.service.d.ts +0 -0
- /package/dist/module/{communication → integration}/strategies/email/outlook-api.strategy.js +0 -0
- /package/dist/module/{communication → integration}/strategies/email/outlook.strategy.js +0 -0
- /package/dist/module/{communication → integration}/strategies/email/sendgrid-api.strategy.js +0 -0
- /package/dist/module/{communication → integration}/strategies/whatsapp/whatsapp-cloud.strategy.js +0 -0
- /package/dist/module/{communication → integration}/strategies/whatsapp/whatsapp.strategy.js +0 -0
- /package/src/module/{communication → integration}/controller/calender-event.controller.ts +0 -0
- /package/src/module/{communication → integration}/controller/wrapper.controller.ts +0 -0
- /package/src/module/{communication → integration}/service/calendar-event.service.ts +0 -0
|
@@ -11,50 +11,53 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
-
var
|
|
14
|
+
var IntegrationService_1;
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.
|
|
16
|
+
exports.IntegrationService = void 0;
|
|
17
17
|
const common_1 = require("@nestjs/common");
|
|
18
18
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
19
19
|
const typeorm_2 = require("typeorm");
|
|
20
20
|
const config_1 = require("@nestjs/config");
|
|
21
21
|
const googleapis_1 = require("googleapis");
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
22
|
+
const integration_config_entity_1 = require("../entity/integration-config.entity");
|
|
23
|
+
const user_integration_entity_1 = require("../entity/user-integration.entity");
|
|
24
|
+
const integration_factory_1 = require("../factories/integration.factory");
|
|
25
25
|
const gmail_api_strategy_1 = require("../strategies/email/gmail-api.strategy");
|
|
26
26
|
const sendgrid_api_strategy_1 = require("../strategies/email/sendgrid-api.strategy");
|
|
27
|
-
const
|
|
28
|
-
let
|
|
29
|
-
constructor(
|
|
30
|
-
this.hubRepository = hubRepository;
|
|
27
|
+
const integration_queue_service_1 = require("./integration-queue.service");
|
|
28
|
+
let IntegrationService = IntegrationService_1 = class IntegrationService {
|
|
29
|
+
constructor(configRepository, userIntegrationRepository, integrationFactory, gmailApiStrategy, sendGridApiStrategy, configService, queueService) {
|
|
31
30
|
this.configRepository = configRepository;
|
|
32
|
-
this.
|
|
31
|
+
this.userIntegrationRepository = userIntegrationRepository;
|
|
32
|
+
this.integrationFactory = integrationFactory;
|
|
33
33
|
this.gmailApiStrategy = gmailApiStrategy;
|
|
34
34
|
this.sendGridApiStrategy = sendGridApiStrategy;
|
|
35
35
|
this.configService = configService;
|
|
36
36
|
this.queueService = queueService;
|
|
37
|
-
this.logger = new common_1.Logger(
|
|
37
|
+
this.logger = new common_1.Logger(IntegrationService_1.name);
|
|
38
38
|
this.gmailOAuthStates = new Map();
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
deriveServiceType(integration_type, integration_provider, config_json) {
|
|
41
|
+
return 'API';
|
|
42
|
+
}
|
|
43
|
+
async sendMessage({ levelId, levelType, app_code, to, message, mode, priority = 1, user_id, }) {
|
|
41
44
|
try {
|
|
42
|
-
const
|
|
43
|
-
if (!
|
|
45
|
+
const configs = await this.getActiveConfigs(levelId, levelType, app_code, mode);
|
|
46
|
+
if (!configs.length) {
|
|
44
47
|
throw new Error(`No active communication configuration found for ${levelType} ${levelId}`);
|
|
45
48
|
}
|
|
46
|
-
const
|
|
47
|
-
for (const
|
|
49
|
+
const sortedConfigs = this.sortConfigsByPriority(configs, priority);
|
|
50
|
+
for (const config of sortedConfigs) {
|
|
48
51
|
try {
|
|
49
|
-
const result = await this.
|
|
52
|
+
const result = await this.sendViaConfig(config, to, message, user_id);
|
|
50
53
|
if (result.success) {
|
|
51
|
-
this.logger.log(`Message sent successfully via ${
|
|
54
|
+
this.logger.log(`Message sent successfully via ${config.integration_provider}`);
|
|
52
55
|
return result;
|
|
53
56
|
}
|
|
54
|
-
this.logger.warn(`Failed to send via ${
|
|
57
|
+
this.logger.warn(`Failed to send via ${config.integration_provider}: ${result.error}`);
|
|
55
58
|
}
|
|
56
59
|
catch (error) {
|
|
57
|
-
this.logger.error(`Error sending via ${
|
|
60
|
+
this.logger.error(`Error sending via ${config.integration_provider}:`, error.message);
|
|
58
61
|
continue;
|
|
59
62
|
}
|
|
60
63
|
}
|
|
@@ -65,74 +68,50 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
65
68
|
throw error;
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
|
-
async
|
|
69
|
-
|
|
70
|
-
.createQueryBuilder('
|
|
71
|
-
.
|
|
72
|
-
.
|
|
73
|
-
'
|
|
74
|
-
'
|
|
75
|
-
'hub.level_type as hub_level_type',
|
|
76
|
-
'hub.status as hub_status',
|
|
77
|
-
'hub.config_id as hub_config_id',
|
|
78
|
-
'hub.communication_config_type as hub_communication_config_type',
|
|
79
|
-
'hub.service as hub_service',
|
|
80
|
-
'hub.provider as hub_provider',
|
|
81
|
-
'hub.priority as hub_priority',
|
|
82
|
-
'hub.is_default as hub_is_default',
|
|
83
|
-
'hub.created_at as hub_created_at',
|
|
84
|
-
'hub.updated_at as hub_updated_at',
|
|
85
|
-
'config.id as config_id',
|
|
86
|
-
'config.config_json as config_json',
|
|
87
|
-
'config.created_at as config_created_at',
|
|
88
|
-
'config.updated_at as config_updated_at',
|
|
89
|
-
])
|
|
90
|
-
.where('hub.level_id = :levelId', { levelId })
|
|
91
|
-
.andWhere('hub.level_type = :levelType', { levelType })
|
|
92
|
-
.andWhere('hub.status = :status', { status: 1 });
|
|
71
|
+
async getActiveConfigs(levelId, levelType, app_code, mode) {
|
|
72
|
+
const queryBuilder = this.configRepository
|
|
73
|
+
.createQueryBuilder('config')
|
|
74
|
+
.where('config.level_id = :levelId', { levelId })
|
|
75
|
+
.andWhere('config.level_type = :levelType', { levelType })
|
|
76
|
+
.andWhere('config.app_code = :app_code', { app_code })
|
|
77
|
+
.andWhere('config.status = 1');
|
|
93
78
|
if (mode) {
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const hubsWithConfig = results.map((row) => ({
|
|
98
|
-
id: row.hub_id,
|
|
99
|
-
level_id: row.hub_level_id,
|
|
100
|
-
level_type: row.hub_level_type,
|
|
101
|
-
status: row.hub_status,
|
|
102
|
-
config_id: row.hub_config_id,
|
|
103
|
-
communication_config_type: row.hub_communication_config_type,
|
|
104
|
-
service: row.hub_service,
|
|
105
|
-
provider: row.hub_provider,
|
|
106
|
-
priority: row.hub_priority || 1,
|
|
107
|
-
is_default: row.hub_is_default || false,
|
|
108
|
-
created_at: row.hub_created_at,
|
|
109
|
-
updated_at: row.hub_updated_at,
|
|
110
|
-
config: {
|
|
111
|
-
id: row.config_id,
|
|
112
|
-
config_json: row.config_json,
|
|
113
|
-
created_at: row.config_created_at,
|
|
114
|
-
updated_at: row.config_updated_at,
|
|
115
|
-
},
|
|
116
|
-
}));
|
|
117
|
-
return hubsWithConfig;
|
|
79
|
+
queryBuilder.andWhere('config.integration_type = :mode', { mode });
|
|
80
|
+
}
|
|
81
|
+
return await queryBuilder.getMany();
|
|
118
82
|
}
|
|
119
|
-
|
|
120
|
-
return
|
|
83
|
+
sortConfigsByPriority(configs, _priority) {
|
|
84
|
+
return configs.sort((a, b) => {
|
|
85
|
+
if (a.is_default !== b.is_default) {
|
|
86
|
+
return a.is_default ? -1 : 1;
|
|
87
|
+
}
|
|
88
|
+
return a.priority - b.priority;
|
|
89
|
+
});
|
|
121
90
|
}
|
|
122
|
-
async
|
|
123
|
-
const strategy = this.
|
|
124
|
-
|
|
91
|
+
async sendViaConfig(config, to, message, user_id) {
|
|
92
|
+
const strategy = this.integrationFactory.create(config.integration_type, 'API', config.integration_provider);
|
|
93
|
+
let finalConfig = config.config_json;
|
|
94
|
+
if (user_id) {
|
|
95
|
+
const userIntegrationData = await this.getUserIntegrationForStrategy(user_id, config.id);
|
|
96
|
+
if (userIntegrationData) {
|
|
97
|
+
finalConfig = {
|
|
98
|
+
...config.config_json,
|
|
99
|
+
external_user_id: userIntegrationData.external_user_id,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const result = await strategy.sendMessage(to, message, finalConfig);
|
|
125
104
|
if (result.refreshedToken && result.success) {
|
|
126
105
|
try {
|
|
127
|
-
const currentConfig =
|
|
106
|
+
const currentConfig = config.config_json;
|
|
128
107
|
const updatedConfig = {
|
|
129
108
|
...currentConfig,
|
|
130
109
|
accessToken: result.refreshedToken,
|
|
131
110
|
};
|
|
132
|
-
await this.configRepository.update(
|
|
111
|
+
await this.configRepository.update(config.id, {
|
|
133
112
|
config_json: updatedConfig,
|
|
134
113
|
});
|
|
135
|
-
this.logger.log(`Updated access token for ${
|
|
114
|
+
this.logger.log(`Updated access token for ${config.integration_provider} configuration`);
|
|
136
115
|
}
|
|
137
116
|
catch (error) {
|
|
138
117
|
this.logger.warn(`Failed to update refreshed token in database: ${error.message}`);
|
|
@@ -140,53 +119,60 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
140
119
|
}
|
|
141
120
|
return result;
|
|
142
121
|
}
|
|
143
|
-
async
|
|
144
|
-
await this.validateUniqueActiveConfig(levelId, levelType, configType);
|
|
122
|
+
async createIntegrationConfig(levelId, levelType, app_code, configType, provider, integration_source_id, config, priority, is_default) {
|
|
123
|
+
await this.validateUniqueActiveConfig(levelId, levelType, app_code, configType, provider);
|
|
124
|
+
await this.configRepository.update({
|
|
125
|
+
level_id: levelId,
|
|
126
|
+
level_type: levelType,
|
|
127
|
+
app_code: app_code,
|
|
128
|
+
integration_type: configType,
|
|
129
|
+
status: 1,
|
|
130
|
+
}, { status: 0 });
|
|
145
131
|
const supportedCombinations = await this.getSupportedCombinations();
|
|
146
|
-
const
|
|
147
|
-
combo.service.toLowerCase() === service.toLowerCase() &&
|
|
132
|
+
const validCombination = supportedCombinations.find((combo) => combo.mode === configType &&
|
|
148
133
|
combo.provider.toLowerCase() === provider.toLowerCase());
|
|
149
|
-
if (!
|
|
150
|
-
throw new Error(`Unsupported combination: ${configType}/${
|
|
134
|
+
if (!validCombination) {
|
|
135
|
+
throw new Error(`Unsupported combination: ${configType}/${provider}`);
|
|
151
136
|
}
|
|
152
|
-
const
|
|
137
|
+
const service = validCombination.service;
|
|
138
|
+
const requiresOAuth = this.requiresOAuthFlow(configType, provider, config);
|
|
153
139
|
if (requiresOAuth) {
|
|
154
|
-
return await this.generateOAuthUrl(levelId, levelType,
|
|
140
|
+
return await this.generateOAuthUrl(levelId, levelType, app_code, configType, provider, integration_source_id, config, priority, is_default);
|
|
155
141
|
}
|
|
156
|
-
return await this.createDirectConfig(levelId, levelType,
|
|
142
|
+
return await this.createDirectConfig(levelId, levelType, app_code, configType, provider, integration_source_id, config, priority, is_default);
|
|
157
143
|
}
|
|
158
144
|
getSupportedCombinations() {
|
|
159
|
-
return this.
|
|
145
|
+
return this.integrationFactory.getAllSupportedCombinations();
|
|
160
146
|
}
|
|
161
147
|
async getLevelConfigs(levelId, levelType, filters) {
|
|
162
148
|
const where = { level_id: levelId, level_type: levelType };
|
|
163
|
-
if (filters?.
|
|
164
|
-
where.
|
|
149
|
+
if (filters?.app_code) {
|
|
150
|
+
where.app_code = filters.app_code;
|
|
165
151
|
}
|
|
166
|
-
if (filters?.
|
|
167
|
-
where.
|
|
152
|
+
if (filters?.integration_type) {
|
|
153
|
+
where.integration_type = filters.integration_type;
|
|
168
154
|
}
|
|
169
|
-
if (filters?.
|
|
170
|
-
where.
|
|
155
|
+
if (filters?.integration_provider) {
|
|
156
|
+
where.integration_provider = filters.integration_provider;
|
|
171
157
|
}
|
|
172
|
-
const hubs = await this.
|
|
158
|
+
const hubs = await this.configRepository.find({
|
|
173
159
|
where,
|
|
174
160
|
order: { created_at: 'DESC' },
|
|
175
161
|
});
|
|
176
162
|
const enhancedHubs = await Promise.all(hubs.map(async (hub) => {
|
|
177
163
|
try {
|
|
178
|
-
const
|
|
179
|
-
where: { id: hub.
|
|
164
|
+
const relatedConfig = await this.configRepository.findOne({
|
|
165
|
+
where: { id: hub.id },
|
|
180
166
|
});
|
|
181
|
-
if (!
|
|
167
|
+
if (!relatedConfig) {
|
|
182
168
|
return {
|
|
183
169
|
...hub,
|
|
184
170
|
linkedSource: 'Configuration not found',
|
|
185
171
|
configDetails: null,
|
|
186
172
|
};
|
|
187
173
|
}
|
|
188
|
-
const linkedSource = this.extractLinkedSource(hub.
|
|
189
|
-
const configDetails = this.extractConfigDetails(hub.
|
|
174
|
+
const linkedSource = this.extractLinkedSource(hub.integration_type, hub.integration_provider, relatedConfig.config_json);
|
|
175
|
+
const configDetails = this.extractConfigDetails(hub.integration_type, hub.integration_provider, relatedConfig.config_json);
|
|
190
176
|
return {
|
|
191
177
|
...hub,
|
|
192
178
|
linkedSource,
|
|
@@ -204,14 +190,14 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
204
190
|
}));
|
|
205
191
|
return enhancedHubs;
|
|
206
192
|
}
|
|
207
|
-
extractLinkedSource(configType,
|
|
208
|
-
const key = `${configType.toLowerCase()}_${
|
|
193
|
+
extractLinkedSource(configType, provider, configJson) {
|
|
194
|
+
const key = `${configType.toLowerCase()}_${provider.toLowerCase()}`;
|
|
209
195
|
try {
|
|
210
196
|
switch (key) {
|
|
211
|
-
case '
|
|
197
|
+
case 'email_gmail':
|
|
212
198
|
case 'email_smtp_gmail':
|
|
213
199
|
return configJson?.email || 'Gmail account not configured';
|
|
214
|
-
case '
|
|
200
|
+
case 'email_outlook':
|
|
215
201
|
case 'email_smtp_outlook':
|
|
216
202
|
return configJson?.email || 'Outlook account not configured';
|
|
217
203
|
case 'wa_api_whatsapp':
|
|
@@ -234,8 +220,8 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
234
220
|
return configJson?.userName
|
|
235
221
|
? `Ozonetel Voice: ${configJson.userName}`
|
|
236
222
|
: 'Ozonetel voice not configured';
|
|
237
|
-
case '
|
|
238
|
-
case '
|
|
223
|
+
case 'email_aws-ses':
|
|
224
|
+
case 'email_ses':
|
|
239
225
|
return configJson?.fromEmail || 'AWS SES not configured';
|
|
240
226
|
case 'email_smtp_sendgrid':
|
|
241
227
|
return configJson?.from || 'SendGrid not configured';
|
|
@@ -262,11 +248,11 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
262
248
|
return 'Configuration error';
|
|
263
249
|
}
|
|
264
250
|
}
|
|
265
|
-
extractConfigDetails(configType,
|
|
266
|
-
const key = `${configType.toLowerCase()}_${
|
|
251
|
+
extractConfigDetails(configType, provider, configJson) {
|
|
252
|
+
const key = `${configType.toLowerCase()}_${provider.toLowerCase()}`;
|
|
267
253
|
try {
|
|
268
254
|
switch (key) {
|
|
269
|
-
case '
|
|
255
|
+
case 'email_gmail':
|
|
270
256
|
return {
|
|
271
257
|
email: configJson?.email,
|
|
272
258
|
authMethod: configJson?.authMethod || 'OAUTH2',
|
|
@@ -281,7 +267,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
281
267
|
authMethod: 'SMTP',
|
|
282
268
|
hasPassword: !!configJson?.password,
|
|
283
269
|
};
|
|
284
|
-
case '
|
|
270
|
+
case 'email_outlook':
|
|
285
271
|
return {
|
|
286
272
|
email: configJson?.email,
|
|
287
273
|
authMethod: 'OAUTH2',
|
|
@@ -329,8 +315,8 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
329
315
|
agentLoginUrl: configJson?.agentLoginUrl,
|
|
330
316
|
hasApiKey: !!configJson?.apiKey,
|
|
331
317
|
};
|
|
332
|
-
case '
|
|
333
|
-
case '
|
|
318
|
+
case 'email_aws-ses':
|
|
319
|
+
case 'email_ses':
|
|
334
320
|
return {
|
|
335
321
|
fromEmail: configJson?.fromEmail,
|
|
336
322
|
region: configJson?.region,
|
|
@@ -398,102 +384,86 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
398
384
|
}
|
|
399
385
|
}
|
|
400
386
|
async updateConfigStatus(hubId, status) {
|
|
401
|
-
const
|
|
387
|
+
const config = await this.configRepository.findOne({
|
|
402
388
|
where: { id: hubId },
|
|
403
389
|
});
|
|
404
|
-
if (!
|
|
405
|
-
throw new Error('
|
|
390
|
+
if (!config) {
|
|
391
|
+
throw new Error('Integration configuration not found');
|
|
406
392
|
}
|
|
407
393
|
if (status === 1) {
|
|
408
|
-
await this.
|
|
409
|
-
level_id:
|
|
410
|
-
level_type:
|
|
411
|
-
|
|
394
|
+
await this.configRepository.update({
|
|
395
|
+
level_id: config.level_id,
|
|
396
|
+
level_type: config.level_type,
|
|
397
|
+
app_code: config.app_code,
|
|
398
|
+
integration_type: config.integration_type,
|
|
412
399
|
status: 1,
|
|
413
400
|
id: (0, typeorm_2.Not)(hubId),
|
|
414
401
|
}, { status: 0 });
|
|
415
402
|
}
|
|
416
|
-
await this.
|
|
403
|
+
await this.configRepository.update(hubId, { status });
|
|
417
404
|
}
|
|
418
|
-
async deleteConfiguration(
|
|
419
|
-
const
|
|
420
|
-
where: { id:
|
|
405
|
+
async deleteConfiguration(configId) {
|
|
406
|
+
const config = await this.configRepository.findOne({
|
|
407
|
+
where: { id: configId },
|
|
421
408
|
});
|
|
422
|
-
if (!
|
|
423
|
-
throw new Error('
|
|
409
|
+
if (!config) {
|
|
410
|
+
throw new Error('Integration configuration not found');
|
|
424
411
|
}
|
|
425
|
-
await this.
|
|
426
|
-
|
|
427
|
-
this.logger.log(`Communication configuration deleted: Hub ${hubId}, Config ${hub.config_id}`);
|
|
412
|
+
await this.configRepository.delete(configId);
|
|
413
|
+
this.logger.log(`Integration configuration deleted: ${configId}`);
|
|
428
414
|
}
|
|
429
415
|
async updateConfiguration(hubId, updateData) {
|
|
430
|
-
const
|
|
416
|
+
const config = await this.configRepository.findOne({
|
|
431
417
|
where: { id: hubId },
|
|
432
418
|
});
|
|
433
|
-
if (!
|
|
434
|
-
throw new Error('
|
|
419
|
+
if (!config) {
|
|
420
|
+
throw new Error('Integration configuration not found');
|
|
435
421
|
}
|
|
436
422
|
if (updateData.config) {
|
|
437
|
-
const existingConfig = await this.configRepository.findOne({
|
|
438
|
-
where: { id: hub.config_id },
|
|
439
|
-
});
|
|
440
|
-
if (!existingConfig) {
|
|
441
|
-
throw new Error('Configuration record not found');
|
|
442
|
-
}
|
|
443
423
|
const updatedConfigJson = {
|
|
444
|
-
...
|
|
424
|
+
...config.config_json,
|
|
445
425
|
...updateData.config,
|
|
446
426
|
};
|
|
447
|
-
await this.configRepository.update(
|
|
427
|
+
await this.configRepository.update(config.id, {
|
|
448
428
|
config_json: updatedConfigJson,
|
|
449
429
|
});
|
|
450
430
|
}
|
|
451
|
-
if (updateData.status === 1) {
|
|
452
|
-
await this.validateUniqueActiveConfig(hub.level_id, hub.level_type, hub.communication_config_type, hubId);
|
|
453
|
-
}
|
|
454
431
|
if (updateData.is_default === true) {
|
|
455
|
-
await this.
|
|
456
|
-
level_id:
|
|
457
|
-
level_type:
|
|
458
|
-
|
|
432
|
+
await this.configRepository.update({
|
|
433
|
+
level_id: config.level_id,
|
|
434
|
+
level_type: config.level_type,
|
|
435
|
+
integration_type: config.integration_type,
|
|
459
436
|
id: (0, typeorm_2.Not)(hubId),
|
|
460
437
|
}, { is_default: false });
|
|
461
438
|
}
|
|
462
|
-
const
|
|
463
|
-
if (updateData.priority !== undefined)
|
|
464
|
-
|
|
439
|
+
const directUpdates = {};
|
|
440
|
+
if (updateData.priority !== undefined)
|
|
441
|
+
directUpdates.priority = updateData.priority;
|
|
442
|
+
if (updateData.is_default !== undefined)
|
|
443
|
+
directUpdates.is_default = updateData.is_default;
|
|
444
|
+
if (updateData.status !== undefined)
|
|
445
|
+
directUpdates.status = updateData.status;
|
|
446
|
+
if (Object.keys(directUpdates).length > 0) {
|
|
447
|
+
await this.configRepository.update(config.id, directUpdates);
|
|
465
448
|
}
|
|
466
|
-
if (updateData.is_default !== undefined) {
|
|
467
|
-
hubUpdateData.is_default = updateData.is_default;
|
|
468
|
-
}
|
|
469
|
-
if (updateData.status !== undefined) {
|
|
470
|
-
hubUpdateData.status = updateData.status;
|
|
471
|
-
}
|
|
472
|
-
if (Object.keys(hubUpdateData).length > 0) {
|
|
473
|
-
await this.hubRepository.update(hubId, hubUpdateData);
|
|
474
|
-
}
|
|
475
|
-
const updatedHub = await this.hubRepository.findOne({
|
|
476
|
-
where: { id: hubId },
|
|
477
|
-
});
|
|
478
449
|
const updatedConfig = await this.configRepository.findOne({
|
|
479
|
-
where: { id:
|
|
450
|
+
where: { id: hubId },
|
|
480
451
|
});
|
|
481
|
-
this.logger.log(`Communication configuration updated: Hub ${hubId}, Type ${hub.communication_config_type}`);
|
|
482
452
|
return {
|
|
483
|
-
...
|
|
453
|
+
...updatedConfig,
|
|
484
454
|
config: updatedConfig?.config_json,
|
|
485
455
|
};
|
|
486
456
|
}
|
|
487
457
|
async sendGenericMessage(messageDto) {
|
|
488
458
|
try {
|
|
489
|
-
const { levelId, levelType, to, message, type, priority = 'medium', subject, html, cc, bcc, attachments, mediaUrl, templateId, variables, } = messageDto;
|
|
459
|
+
const { levelId, levelType, app_code, to, message, type, priority = 'medium', subject, html, cc, bcc, attachments, mediaUrl, templateId, variables, user_id, } = messageDto;
|
|
490
460
|
const communicationType = this.detectCommunicationType(to, type);
|
|
491
|
-
const
|
|
492
|
-
if (!
|
|
493
|
-
this.logger.warn(`No communication hubs found for ${levelType} ${levelId}. Please configure
|
|
461
|
+
const configs = await this.getActiveConfigs(levelId, levelType, app_code, communicationType);
|
|
462
|
+
if (!configs.length) {
|
|
463
|
+
this.logger.warn(`No communication hubs found for ${levelType} ${levelId}. Please configure integration providers using the createIntegrationConfig method.`);
|
|
494
464
|
throw new Error(`No active ${communicationType} configuration found for ${levelType} ${levelId}. Please configure a communication provider first.`);
|
|
495
465
|
}
|
|
496
|
-
const
|
|
466
|
+
const sortedConfigs = this.sortConfigsByPriorityAndDefault(configs, priority);
|
|
497
467
|
const enhancedConfig = {
|
|
498
468
|
subject,
|
|
499
469
|
html,
|
|
@@ -506,30 +476,40 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
506
476
|
const results = [];
|
|
507
477
|
let hasSuccess = false;
|
|
508
478
|
for (const recipient of to) {
|
|
509
|
-
for (const hub of
|
|
479
|
+
for (const hub of sortedConfigs) {
|
|
510
480
|
try {
|
|
511
|
-
const
|
|
481
|
+
const serviceType = this.deriveServiceType(hub.integration_type, hub.integration_provider, hub.config_json);
|
|
482
|
+
const strategy = this.integrationFactory.create(hub.integration_type, serviceType, hub.integration_provider);
|
|
512
483
|
let processedMessage = message;
|
|
513
484
|
if (templateId && variables) {
|
|
514
485
|
processedMessage = this.processTemplate(message, variables);
|
|
515
486
|
}
|
|
516
|
-
|
|
517
|
-
...hub.
|
|
487
|
+
let finalConfig = {
|
|
488
|
+
...hub.config_json,
|
|
518
489
|
...enhancedConfig,
|
|
519
490
|
templateId,
|
|
520
491
|
variables,
|
|
521
492
|
};
|
|
493
|
+
if (user_id) {
|
|
494
|
+
const userIntegrationData = await this.getUserIntegrationForStrategy(user_id, hub.id);
|
|
495
|
+
if (userIntegrationData) {
|
|
496
|
+
finalConfig = {
|
|
497
|
+
...finalConfig,
|
|
498
|
+
external_user_id: userIntegrationData.external_user_id,
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
}
|
|
522
502
|
const result = await strategy.sendMessage(recipient, processedMessage, finalConfig);
|
|
523
503
|
if (result.success) {
|
|
524
|
-
this.logger.log(`Generic message sent successfully via ${hub.
|
|
504
|
+
this.logger.log(`Generic message sent successfully via ${hub.integration_provider} to ${recipient}`);
|
|
525
505
|
results.push(result);
|
|
526
506
|
hasSuccess = true;
|
|
527
507
|
break;
|
|
528
508
|
}
|
|
529
|
-
this.logger.warn(`Failed to send via ${hub.
|
|
509
|
+
this.logger.warn(`Failed to send via ${hub.integration_provider} to ${recipient}: ${result.error}`);
|
|
530
510
|
}
|
|
531
511
|
catch (error) {
|
|
532
|
-
this.logger.error(`Error sending via ${hub.
|
|
512
|
+
this.logger.error(`Error sending via ${hub.integration_provider} to ${recipient}:`, error.message);
|
|
533
513
|
continue;
|
|
534
514
|
}
|
|
535
515
|
}
|
|
@@ -545,28 +525,38 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
545
525
|
}
|
|
546
526
|
}
|
|
547
527
|
else {
|
|
548
|
-
for (const hub of
|
|
528
|
+
for (const hub of sortedConfigs) {
|
|
549
529
|
try {
|
|
550
|
-
const
|
|
530
|
+
const serviceType = this.deriveServiceType(hub.integration_type, hub.integration_provider, hub.config_json);
|
|
531
|
+
const strategy = this.integrationFactory.create(hub.integration_type, serviceType, hub.integration_provider);
|
|
551
532
|
let processedMessage = message;
|
|
552
533
|
if (html && variables) {
|
|
553
534
|
processedMessage = this.processTemplate(html ? html : message, variables);
|
|
554
535
|
}
|
|
555
|
-
|
|
556
|
-
...hub.
|
|
536
|
+
let finalConfig = {
|
|
537
|
+
...hub.config_json,
|
|
557
538
|
...enhancedConfig,
|
|
558
539
|
templateId,
|
|
559
540
|
variables,
|
|
560
541
|
};
|
|
542
|
+
if (user_id) {
|
|
543
|
+
const userIntegrationData = await this.getUserIntegrationForStrategy(user_id, hub.id);
|
|
544
|
+
if (userIntegrationData) {
|
|
545
|
+
finalConfig = {
|
|
546
|
+
...finalConfig,
|
|
547
|
+
external_user_id: userIntegrationData.external_user_id,
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
}
|
|
561
551
|
const result = await strategy.sendMessage(to, processedMessage, finalConfig);
|
|
562
552
|
if (result.success) {
|
|
563
|
-
this.logger.log(`Generic message sent successfully via ${hub.
|
|
553
|
+
this.logger.log(`Generic message sent successfully via ${hub.integration_provider} to ${to}`);
|
|
564
554
|
return result;
|
|
565
555
|
}
|
|
566
|
-
this.logger.warn(`Failed to send via ${hub.
|
|
556
|
+
this.logger.warn(`Failed to send via ${hub.integration_provider}: ${result.error}`);
|
|
567
557
|
}
|
|
568
558
|
catch (error) {
|
|
569
|
-
this.logger.error(`Error sending via ${hub.
|
|
559
|
+
this.logger.error(`Error sending via ${hub.integration_provider}:`, error.message);
|
|
570
560
|
continue;
|
|
571
561
|
}
|
|
572
562
|
}
|
|
@@ -580,7 +570,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
580
570
|
}
|
|
581
571
|
async sendBulkMessage(bulkDto) {
|
|
582
572
|
try {
|
|
583
|
-
const { levelId, levelType, recipients, message, type, priority = 'low', subject, html, templateId, variables, batchSize = 10, } = bulkDto;
|
|
573
|
+
const { levelId, levelType, app_code, recipients, message, type, priority = 'low', subject, html, templateId, variables, batchSize = 10, } = bulkDto;
|
|
584
574
|
const results = [];
|
|
585
575
|
const batches = this.chunkArray(recipients, batchSize);
|
|
586
576
|
for (let i = 0; i < batches.length; i++) {
|
|
@@ -591,6 +581,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
591
581
|
const messageDto = {
|
|
592
582
|
levelId,
|
|
593
583
|
levelType,
|
|
584
|
+
app_code,
|
|
594
585
|
to: recipient,
|
|
595
586
|
message,
|
|
596
587
|
type,
|
|
@@ -663,6 +654,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
663
654
|
const messageDto = {
|
|
664
655
|
levelId: templateDto.levelId,
|
|
665
656
|
levelType: templateDto.levelType,
|
|
657
|
+
app_code: templateDto.app_code,
|
|
666
658
|
to: templateDto.to,
|
|
667
659
|
message: processedMessage,
|
|
668
660
|
subject: processedSubject,
|
|
@@ -678,15 +670,15 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
678
670
|
}
|
|
679
671
|
const recipient = Array.isArray(to) ? to[0] : to;
|
|
680
672
|
if (recipient.includes('@')) {
|
|
681
|
-
return
|
|
673
|
+
return 'EMAIL';
|
|
682
674
|
}
|
|
683
675
|
if (/^\+?[\d\s\-\(\)]+$/.test(recipient)) {
|
|
684
|
-
return
|
|
676
|
+
return 'SMS';
|
|
685
677
|
}
|
|
686
|
-
return
|
|
678
|
+
return 'EMAIL';
|
|
687
679
|
}
|
|
688
|
-
|
|
689
|
-
return
|
|
680
|
+
sortConfigsByPriorityAndDefault(configs, _priority) {
|
|
681
|
+
return configs.sort((a, b) => {
|
|
690
682
|
if (a.is_default !== b.is_default) {
|
|
691
683
|
return b.is_default ? 1 : -1;
|
|
692
684
|
}
|
|
@@ -716,7 +708,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
716
708
|
}
|
|
717
709
|
return chunks;
|
|
718
710
|
}
|
|
719
|
-
async initGmailOAuth(levelId, levelType, email) {
|
|
711
|
+
async initGmailOAuth(levelId, levelType, app_code, email) {
|
|
720
712
|
try {
|
|
721
713
|
const clientId = this.configService.get('CLIENT_ID');
|
|
722
714
|
const clientSecret = this.configService.get('CLIENT_SECRET');
|
|
@@ -729,6 +721,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
729
721
|
this.gmailOAuthStates.set(state, {
|
|
730
722
|
levelId,
|
|
731
723
|
levelType,
|
|
724
|
+
app_code,
|
|
732
725
|
email,
|
|
733
726
|
timestamp: Date.now(),
|
|
734
727
|
});
|
|
@@ -795,24 +788,23 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
795
788
|
tokenType: tokens.token_type,
|
|
796
789
|
expiryDate: tokens.expiry_date,
|
|
797
790
|
};
|
|
798
|
-
await this.validateUniqueActiveConfig(oauthState.levelId, oauthState.levelType,
|
|
799
|
-
const
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
791
|
+
await this.validateUniqueActiveConfig(oauthState.levelId, oauthState.levelType, oauthState.app_code, 'EMAIL', 'gmail');
|
|
792
|
+
const config = this.configRepository.create({
|
|
793
|
+
app_code: oauthState.app_code,
|
|
794
|
+
integration_type: 'EMAIL',
|
|
795
|
+
integration_provider: 'gmail',
|
|
796
|
+
integration_source_id: 1,
|
|
804
797
|
level_id: oauthState.levelId,
|
|
805
798
|
level_type: oauthState.levelType,
|
|
806
|
-
config_id: savedConfig.id,
|
|
807
|
-
communication_config_type: communication_hub_entity_1.CommunicationConfigType.EMAIL,
|
|
808
|
-
service: 'API',
|
|
809
|
-
provider: 'gmail',
|
|
810
799
|
status: 1,
|
|
800
|
+
priority: 1,
|
|
801
|
+
is_default: false,
|
|
802
|
+
config_json: gmailConfig,
|
|
811
803
|
});
|
|
812
|
-
const
|
|
804
|
+
const savedConfig = await this.configRepository.save(config);
|
|
813
805
|
this.logger.log(`Gmail OAuth configuration created successfully for ${oauthState.levelType} ${oauthState.levelId} and email ${email}`);
|
|
814
806
|
return {
|
|
815
|
-
hubId:
|
|
807
|
+
hubId: savedConfig.id,
|
|
816
808
|
configId: savedConfig.id,
|
|
817
809
|
};
|
|
818
810
|
}
|
|
@@ -834,7 +826,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
834
826
|
if (oauthState.email && oauthState.email !== email) {
|
|
835
827
|
throw new Error('Email mismatch with OAuth hint');
|
|
836
828
|
}
|
|
837
|
-
await this.validateUniqueActiveConfig(oauthState.levelId, oauthState.levelType,
|
|
829
|
+
await this.validateUniqueActiveConfig(oauthState.levelId, oauthState.levelType, oauthState.app_code, 'EMAIL', 'gmail');
|
|
838
830
|
const gmailConfig = {
|
|
839
831
|
email: email,
|
|
840
832
|
accessToken: accessToken,
|
|
@@ -845,23 +837,22 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
845
837
|
'https://www.googleapis.com/auth/userinfo.email',
|
|
846
838
|
],
|
|
847
839
|
};
|
|
848
|
-
const
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
840
|
+
const config = this.configRepository.create({
|
|
841
|
+
app_code: oauthState.app_code,
|
|
842
|
+
integration_type: 'EMAIL',
|
|
843
|
+
integration_provider: 'gmail',
|
|
844
|
+
integration_source_id: 1,
|
|
853
845
|
level_id: oauthState.levelId,
|
|
854
846
|
level_type: oauthState.levelType,
|
|
855
|
-
config_id: savedConfig.id,
|
|
856
|
-
communication_config_type: communication_hub_entity_1.CommunicationConfigType.EMAIL,
|
|
857
|
-
service: 'API',
|
|
858
|
-
provider: 'gmail',
|
|
859
847
|
status: 1,
|
|
848
|
+
priority: 1,
|
|
849
|
+
is_default: false,
|
|
850
|
+
config_json: gmailConfig,
|
|
860
851
|
});
|
|
861
|
-
const
|
|
852
|
+
const savedConfig = await this.configRepository.save(config);
|
|
862
853
|
this.logger.log(`Gmail tokens configuration created successfully for ${oauthState.levelType} ${oauthState.levelId} and email ${email}`);
|
|
863
854
|
return {
|
|
864
|
-
hubId:
|
|
855
|
+
hubId: savedConfig.id,
|
|
865
856
|
configId: savedConfig.id,
|
|
866
857
|
};
|
|
867
858
|
}
|
|
@@ -872,19 +863,13 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
872
863
|
}
|
|
873
864
|
async testGmailConfig(hubId) {
|
|
874
865
|
try {
|
|
875
|
-
const
|
|
866
|
+
const integrationConfig = await this.configRepository.findOne({
|
|
876
867
|
where: { id: hubId },
|
|
877
868
|
});
|
|
878
|
-
if (!
|
|
879
|
-
throw new Error('
|
|
880
|
-
}
|
|
881
|
-
const config = await this.configRepository.findOne({
|
|
882
|
-
where: { id: hub.config_id },
|
|
883
|
-
});
|
|
884
|
-
if (!config) {
|
|
885
|
-
throw new Error('Configuration not found');
|
|
869
|
+
if (!integrationConfig) {
|
|
870
|
+
throw new Error('Integration config not found');
|
|
886
871
|
}
|
|
887
|
-
const isValid = await this.gmailApiStrategy.validateConnection(
|
|
872
|
+
const isValid = await this.gmailApiStrategy.validateConnection(integrationConfig.config_json);
|
|
888
873
|
if (!isValid) {
|
|
889
874
|
return {
|
|
890
875
|
success: false,
|
|
@@ -901,89 +886,89 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
901
886
|
generateSecureState() {
|
|
902
887
|
return Math.random().toString(36).substring(2) + Date.now().toString(36);
|
|
903
888
|
}
|
|
904
|
-
async validateUniqueActiveConfig(levelId, levelType, configType, excludeHubId) {
|
|
905
|
-
const query = this.
|
|
889
|
+
async validateUniqueActiveConfig(levelId, levelType, app_code, configType, provider, excludeHubId) {
|
|
890
|
+
const query = this.configRepository
|
|
906
891
|
.createQueryBuilder('hub')
|
|
907
892
|
.where('hub.level_id = :levelId', { levelId })
|
|
908
893
|
.andWhere('hub.level_type = :levelType', { levelType })
|
|
909
|
-
.andWhere('hub.
|
|
894
|
+
.andWhere('hub.app_code = :app_code', { app_code })
|
|
895
|
+
.andWhere('hub.integration_type = :configType', { configType })
|
|
896
|
+
.andWhere('hub.integration_provider = :provider', { provider })
|
|
910
897
|
.andWhere('hub.status = :status', { status: 1 });
|
|
911
898
|
if (excludeHubId) {
|
|
912
899
|
query.andWhere('hub.id != :excludeHubId', { excludeHubId });
|
|
913
900
|
}
|
|
914
901
|
const existingActiveConfigs = await query.getMany();
|
|
915
902
|
if (existingActiveConfigs.length > 0) {
|
|
916
|
-
|
|
917
|
-
level_id: levelId,
|
|
918
|
-
level_type: levelType,
|
|
919
|
-
communication_config_type: configType,
|
|
920
|
-
status: 1,
|
|
921
|
-
...(excludeHubId && { id: (0, typeorm_2.Not)(excludeHubId) }),
|
|
922
|
-
}, { status: 0 });
|
|
923
|
-
this.logger.log(`Deactivated ${existingActiveConfigs.length} existing ${configType} configuration(s) for ${levelType} ${levelId} to maintain single active provider rule.`);
|
|
903
|
+
throw new Error(`A ${provider} configuration already exists for ${configType} in app_code ${app_code}, ${levelType} ${levelId}. Only one configuration per provider is allowed.`);
|
|
924
904
|
}
|
|
925
905
|
}
|
|
926
|
-
requiresOAuthFlow(configType,
|
|
927
|
-
const key = `${configType.toLowerCase()}_${
|
|
906
|
+
requiresOAuthFlow(configType, provider, config) {
|
|
907
|
+
const key = `${configType.toLowerCase()}_${provider.toLowerCase()}`;
|
|
928
908
|
switch (key) {
|
|
929
|
-
case '
|
|
909
|
+
case 'email_gmail':
|
|
930
910
|
return !config.accessToken || config.useOAuth === true;
|
|
931
|
-
case '
|
|
911
|
+
case 'email_outlook':
|
|
932
912
|
return !config.accessToken || config.useOAuth === true;
|
|
933
913
|
default:
|
|
934
914
|
return false;
|
|
935
915
|
}
|
|
936
916
|
}
|
|
937
|
-
async generateOAuthUrl(levelId, levelType,
|
|
938
|
-
const key = `${configType.toLowerCase()}_${
|
|
917
|
+
async generateOAuthUrl(levelId, levelType, app_code, configType, provider, integration_source_id, config, priority, is_default) {
|
|
918
|
+
const key = `${configType.toLowerCase()}_${provider.toLowerCase()}`;
|
|
939
919
|
switch (key) {
|
|
940
|
-
case '
|
|
941
|
-
const gmailResult = await this.initGmailOAuth(levelId, levelType, config.email);
|
|
920
|
+
case 'email_gmail':
|
|
921
|
+
const gmailResult = await this.initGmailOAuth(levelId, levelType, app_code, config.email);
|
|
942
922
|
return {
|
|
943
923
|
authUrl: gmailResult.authUrl,
|
|
944
924
|
state: gmailResult.state,
|
|
945
925
|
message: 'Please complete Gmail OAuth authorization. Configuration will be created automatically after authorization.',
|
|
946
926
|
};
|
|
947
|
-
case '
|
|
948
|
-
const outlookResult = await this.initOutlookOAuth(levelId, levelType, config.email);
|
|
927
|
+
case 'email_outlook':
|
|
928
|
+
const outlookResult = await this.initOutlookOAuth(levelId, levelType, app_code, config.email);
|
|
949
929
|
return {
|
|
950
930
|
authUrl: outlookResult.authUrl,
|
|
951
931
|
state: outlookResult.state,
|
|
952
932
|
message: 'Please complete Outlook OAuth authorization. Configuration will be created automatically after authorization.',
|
|
953
933
|
};
|
|
954
934
|
default:
|
|
955
|
-
throw new Error(`OAuth not supported for ${configType}/${
|
|
935
|
+
throw new Error(`OAuth not supported for ${configType}/${provider}`);
|
|
956
936
|
}
|
|
957
937
|
}
|
|
958
|
-
async createDirectConfig(levelId, levelType,
|
|
959
|
-
await this.validateUniqueActiveConfig(levelId, levelType, configType);
|
|
938
|
+
async createDirectConfig(levelId, levelType, app_code, configType, provider, integration_source_id, config, priority, is_default) {
|
|
939
|
+
await this.validateUniqueActiveConfig(levelId, levelType, app_code, configType, provider);
|
|
940
|
+
await this.configRepository.update({
|
|
941
|
+
level_id: levelId,
|
|
942
|
+
level_type: levelType,
|
|
943
|
+
app_code: app_code,
|
|
944
|
+
integration_type: configType,
|
|
945
|
+
status: 1,
|
|
946
|
+
}, { status: 0 });
|
|
960
947
|
if (is_default) {
|
|
961
|
-
await this.
|
|
948
|
+
await this.configRepository.update({
|
|
962
949
|
level_id: levelId,
|
|
963
950
|
level_type: levelType,
|
|
964
|
-
|
|
951
|
+
app_code: app_code,
|
|
952
|
+
integration_type: configType,
|
|
965
953
|
}, { is_default: false });
|
|
966
954
|
}
|
|
967
|
-
const
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
955
|
+
const integrationConfig = this.configRepository.create({
|
|
956
|
+
app_code: app_code,
|
|
957
|
+
integration_type: configType,
|
|
958
|
+
integration_provider: provider,
|
|
959
|
+
integration_source_id: integration_source_id,
|
|
972
960
|
level_id: levelId,
|
|
973
961
|
level_type: levelType,
|
|
974
|
-
|
|
975
|
-
communication_config_type: configType,
|
|
976
|
-
service: service,
|
|
977
|
-
provider: provider,
|
|
962
|
+
status: 1,
|
|
978
963
|
priority: priority || 1,
|
|
979
964
|
is_default: is_default || false,
|
|
980
|
-
|
|
965
|
+
config_json: config,
|
|
981
966
|
});
|
|
982
|
-
const
|
|
983
|
-
this.logger.log(`Communication config created: ${configType}/${
|
|
984
|
-
return Array.isArray(
|
|
967
|
+
const savedConfig = await this.configRepository.save(integrationConfig);
|
|
968
|
+
this.logger.log(`Communication config created: ${configType}/${provider} for ${levelType} ${levelId}`);
|
|
969
|
+
return Array.isArray(savedConfig) ? savedConfig[0] : savedConfig;
|
|
985
970
|
}
|
|
986
|
-
async initOutlookOAuth(levelId, levelType, email) {
|
|
971
|
+
async initOutlookOAuth(levelId, levelType, app_code, email) {
|
|
987
972
|
try {
|
|
988
973
|
const clientId = this.configService.get('OUTLOOK_CLIENT_ID');
|
|
989
974
|
const tenantId = this.configService.get('OUTLOOK_TENANT_ID');
|
|
@@ -996,6 +981,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
996
981
|
this.gmailOAuthStates.set(state, {
|
|
997
982
|
levelId,
|
|
998
983
|
levelType,
|
|
984
|
+
app_code,
|
|
999
985
|
email,
|
|
1000
986
|
timestamp: Date.now(),
|
|
1001
987
|
});
|
|
@@ -1064,7 +1050,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
1064
1050
|
if (!email) {
|
|
1065
1051
|
throw new Error('Failed to get user email');
|
|
1066
1052
|
}
|
|
1067
|
-
await this.validateUniqueActiveConfig(oauthState.levelId, oauthState.levelType,
|
|
1053
|
+
await this.validateUniqueActiveConfig(oauthState.levelId, oauthState.levelType, oauthState.app_code, 'EMAIL', 'outlook');
|
|
1068
1054
|
const outlookConfig = {
|
|
1069
1055
|
clientId,
|
|
1070
1056
|
tenantId,
|
|
@@ -1075,23 +1061,22 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
1075
1061
|
tokenType: tokens.token_type,
|
|
1076
1062
|
expiresIn: tokens.expires_in,
|
|
1077
1063
|
};
|
|
1078
|
-
const
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1064
|
+
const config = this.configRepository.create({
|
|
1065
|
+
app_code: oauthState.app_code,
|
|
1066
|
+
integration_type: 'EMAIL',
|
|
1067
|
+
integration_provider: 'outlook',
|
|
1068
|
+
integration_source_id: 1,
|
|
1083
1069
|
level_id: oauthState.levelId,
|
|
1084
1070
|
level_type: oauthState.levelType,
|
|
1085
|
-
config_id: savedConfig.id,
|
|
1086
|
-
communication_config_type: communication_hub_entity_1.CommunicationConfigType.EMAIL,
|
|
1087
|
-
service: 'API',
|
|
1088
|
-
provider: 'outlook',
|
|
1089
1071
|
status: 1,
|
|
1072
|
+
priority: 1,
|
|
1073
|
+
is_default: false,
|
|
1074
|
+
config_json: outlookConfig,
|
|
1090
1075
|
});
|
|
1091
|
-
const
|
|
1076
|
+
const savedConfig = await this.configRepository.save(config);
|
|
1092
1077
|
this.logger.log(`Outlook OAuth configuration created successfully for ${oauthState.levelType} ${oauthState.levelId} and email ${email}`);
|
|
1093
1078
|
return {
|
|
1094
|
-
hubId:
|
|
1079
|
+
hubId: savedConfig.id,
|
|
1095
1080
|
configId: savedConfig.id,
|
|
1096
1081
|
};
|
|
1097
1082
|
}
|
|
@@ -1100,31 +1085,19 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
1100
1085
|
throw new Error(`Failed to complete Outlook OAuth: ${error.message}`);
|
|
1101
1086
|
}
|
|
1102
1087
|
}
|
|
1103
|
-
async
|
|
1088
|
+
async getIntegrationConfigById(hubId) {
|
|
1104
1089
|
try {
|
|
1105
|
-
const
|
|
1090
|
+
const integrationConfig = await this.configRepository.findOne({
|
|
1106
1091
|
where: { id: hubId },
|
|
1107
1092
|
});
|
|
1108
|
-
if (!
|
|
1093
|
+
if (!integrationConfig) {
|
|
1109
1094
|
return null;
|
|
1110
1095
|
}
|
|
1111
|
-
const
|
|
1112
|
-
|
|
1113
|
-
});
|
|
1114
|
-
if (!config) {
|
|
1115
|
-
this.logger.warn(`Configuration not found for hub ${hubId} with config_id ${hub.config_id}`);
|
|
1116
|
-
return {
|
|
1117
|
-
...hub,
|
|
1118
|
-
config: null,
|
|
1119
|
-
linkedSource: 'Configuration not found',
|
|
1120
|
-
configDetails: null,
|
|
1121
|
-
};
|
|
1122
|
-
}
|
|
1123
|
-
const linkedSource = this.extractLinkedSource(hub.communication_config_type, hub.service, hub.provider, config.config_json);
|
|
1124
|
-
const configDetails = this.extractConfigDetails(hub.communication_config_type, hub.service, hub.provider, config.config_json);
|
|
1096
|
+
const linkedSource = this.extractLinkedSource(integrationConfig.integration_type, integrationConfig.integration_provider, integrationConfig.config_json);
|
|
1097
|
+
const configDetails = this.extractConfigDetails(integrationConfig.integration_type, integrationConfig.integration_provider, integrationConfig.config_json);
|
|
1125
1098
|
return {
|
|
1126
|
-
...
|
|
1127
|
-
config,
|
|
1099
|
+
...integrationConfig,
|
|
1100
|
+
config: integrationConfig,
|
|
1128
1101
|
linkedSource,
|
|
1129
1102
|
configDetails,
|
|
1130
1103
|
};
|
|
@@ -1134,17 +1107,17 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
1134
1107
|
throw new Error(`Failed to fetch communication configuration: ${error.message}`);
|
|
1135
1108
|
}
|
|
1136
1109
|
}
|
|
1137
|
-
async getSendGridTemplates(levelId, levelType) {
|
|
1110
|
+
async getSendGridTemplates(levelId, levelType, app_code) {
|
|
1138
1111
|
try {
|
|
1139
|
-
const hubs = await this.
|
|
1140
|
-
const sendGridHub = hubs.find((hub) => hub.
|
|
1112
|
+
const hubs = await this.getActiveConfigs(levelId, levelType, app_code, 'EMAIL');
|
|
1113
|
+
const sendGridHub = hubs.find((hub) => hub.integration_provider === 'sendgrid');
|
|
1141
1114
|
if (!sendGridHub) {
|
|
1142
1115
|
return {
|
|
1143
1116
|
success: false,
|
|
1144
1117
|
error: 'No active SendGrid configuration found for this level',
|
|
1145
1118
|
};
|
|
1146
1119
|
}
|
|
1147
|
-
const apiKey = sendGridHub.
|
|
1120
|
+
const apiKey = sendGridHub.config_json?.apiKey;
|
|
1148
1121
|
if (!apiKey) {
|
|
1149
1122
|
return {
|
|
1150
1123
|
success: false,
|
|
@@ -1179,19 +1152,130 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
1179
1152
|
};
|
|
1180
1153
|
}
|
|
1181
1154
|
}
|
|
1155
|
+
async createUserIntegration(createDto) {
|
|
1156
|
+
try {
|
|
1157
|
+
const existing = await this.userIntegrationRepository.findOne({
|
|
1158
|
+
where: {
|
|
1159
|
+
user_id: createDto.user_id,
|
|
1160
|
+
integration_config_id: createDto.integration_config_id,
|
|
1161
|
+
},
|
|
1162
|
+
});
|
|
1163
|
+
if (existing) {
|
|
1164
|
+
throw new Error('User integration mapping already exists');
|
|
1165
|
+
}
|
|
1166
|
+
const config = await this.configRepository.findOne({
|
|
1167
|
+
where: { id: createDto.integration_config_id },
|
|
1168
|
+
});
|
|
1169
|
+
if (!config) {
|
|
1170
|
+
throw new Error('Integration configuration not found');
|
|
1171
|
+
}
|
|
1172
|
+
const userIntegration = this.userIntegrationRepository.create(createDto);
|
|
1173
|
+
return await this.userIntegrationRepository.save(userIntegration);
|
|
1174
|
+
}
|
|
1175
|
+
catch (error) {
|
|
1176
|
+
this.logger.error(`Error creating user integration mapping: ${error.message}`);
|
|
1177
|
+
throw error;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
async getUserIntegrations(userId) {
|
|
1181
|
+
try {
|
|
1182
|
+
return await this.userIntegrationRepository.find({
|
|
1183
|
+
where: { user_id: userId, is_active: true },
|
|
1184
|
+
order: { created_at: 'DESC' },
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
catch (error) {
|
|
1188
|
+
this.logger.error(`Error fetching user integrations for user ${userId}: ${error.message}`);
|
|
1189
|
+
throw error;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
async getConfigUserIntegrations(configId) {
|
|
1193
|
+
try {
|
|
1194
|
+
return await this.userIntegrationRepository.find({
|
|
1195
|
+
where: { integration_config_id: configId, is_active: true },
|
|
1196
|
+
order: { created_at: 'DESC' },
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
catch (error) {
|
|
1200
|
+
this.logger.error(`Error fetching user integrations for config ${configId}: ${error.message}`);
|
|
1201
|
+
throw error;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
async getUserIntegrationByUserAndConfig(userId, configId) {
|
|
1205
|
+
try {
|
|
1206
|
+
return await this.userIntegrationRepository.findOne({
|
|
1207
|
+
where: {
|
|
1208
|
+
user_id: userId,
|
|
1209
|
+
integration_config_id: configId,
|
|
1210
|
+
is_active: true,
|
|
1211
|
+
},
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
catch (error) {
|
|
1215
|
+
this.logger.error(`Error fetching user integration for user ${userId} and config ${configId}: ${error.message}`);
|
|
1216
|
+
throw error;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
async updateUserIntegration(id, updateDto) {
|
|
1220
|
+
try {
|
|
1221
|
+
const userIntegration = await this.userIntegrationRepository.findOne({
|
|
1222
|
+
where: { id },
|
|
1223
|
+
});
|
|
1224
|
+
if (!userIntegration) {
|
|
1225
|
+
throw new Error('User integration mapping not found');
|
|
1226
|
+
}
|
|
1227
|
+
Object.assign(userIntegration, updateDto);
|
|
1228
|
+
return await this.userIntegrationRepository.save(userIntegration);
|
|
1229
|
+
}
|
|
1230
|
+
catch (error) {
|
|
1231
|
+
this.logger.error(`Error updating user integration ${id}: ${error.message}`);
|
|
1232
|
+
throw error;
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
async deleteUserIntegration(id) {
|
|
1236
|
+
try {
|
|
1237
|
+
const userIntegration = await this.userIntegrationRepository.findOne({
|
|
1238
|
+
where: { id },
|
|
1239
|
+
});
|
|
1240
|
+
if (!userIntegration) {
|
|
1241
|
+
throw new Error('User integration mapping not found');
|
|
1242
|
+
}
|
|
1243
|
+
await this.userIntegrationRepository.remove(userIntegration);
|
|
1244
|
+
}
|
|
1245
|
+
catch (error) {
|
|
1246
|
+
this.logger.error(`Error deleting user integration ${id}: ${error.message}`);
|
|
1247
|
+
throw error;
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
async getUserIntegrationForStrategy(userId, integrationConfigId) {
|
|
1251
|
+
try {
|
|
1252
|
+
const userIntegration = await this.getUserIntegrationByUserAndConfig(userId, integrationConfigId);
|
|
1253
|
+
if (!userIntegration) {
|
|
1254
|
+
return null;
|
|
1255
|
+
}
|
|
1256
|
+
return {
|
|
1257
|
+
external_user_id: userIntegration.external_user_id,
|
|
1258
|
+
external_user_data: userIntegration.external_user_data,
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
catch (error) {
|
|
1262
|
+
this.logger.error(`Error fetching user integration data for strategy: ${error.message}`);
|
|
1263
|
+
return null;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1182
1266
|
};
|
|
1183
|
-
exports.
|
|
1184
|
-
exports.
|
|
1267
|
+
exports.IntegrationService = IntegrationService;
|
|
1268
|
+
exports.IntegrationService = IntegrationService = IntegrationService_1 = __decorate([
|
|
1185
1269
|
(0, common_1.Injectable)(),
|
|
1186
|
-
__param(0, (0, typeorm_1.InjectRepository)(
|
|
1187
|
-
__param(1, (0, typeorm_1.InjectRepository)(
|
|
1188
|
-
__param(6, (0, common_1.Inject)((0, common_1.forwardRef)(() =>
|
|
1270
|
+
__param(0, (0, typeorm_1.InjectRepository)(integration_config_entity_1.IntegrationConfig)),
|
|
1271
|
+
__param(1, (0, typeorm_1.InjectRepository)(user_integration_entity_1.UserIntegration)),
|
|
1272
|
+
__param(6, (0, common_1.Inject)((0, common_1.forwardRef)(() => integration_queue_service_1.IntegrationQueueService))),
|
|
1189
1273
|
__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
1190
1274
|
typeorm_2.Repository,
|
|
1191
|
-
|
|
1275
|
+
integration_factory_1.IntegrationFactory,
|
|
1192
1276
|
gmail_api_strategy_1.GmailApiStrategy,
|
|
1193
1277
|
sendgrid_api_strategy_1.SendGridApiStrategy,
|
|
1194
1278
|
config_1.ConfigService,
|
|
1195
|
-
|
|
1196
|
-
],
|
|
1197
|
-
//# sourceMappingURL=
|
|
1279
|
+
integration_queue_service_1.IntegrationQueueService])
|
|
1280
|
+
], IntegrationService);
|
|
1281
|
+
//# sourceMappingURL=integration.service.js.map
|