rez_core 2.2.258 → 2.2.260
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 +116 -0
- package/dist/module/{communication/controller/communication.controller.js → integration/controller/integration.controller.js} +212 -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 +157 -0
- package/dist/module/{communication/service/communication.service.js → integration/service/integration.service.js} +407 -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 +432 -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} +624 -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,54 @@ 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, dataSource, integrationFactory, gmailApiStrategy, sendGridApiStrategy, configService, queueService) {
|
|
31
30
|
this.configRepository = configRepository;
|
|
32
|
-
this.
|
|
31
|
+
this.userIntegrationRepository = userIntegrationRepository;
|
|
32
|
+
this.dataSource = dataSource;
|
|
33
|
+
this.integrationFactory = integrationFactory;
|
|
33
34
|
this.gmailApiStrategy = gmailApiStrategy;
|
|
34
35
|
this.sendGridApiStrategy = sendGridApiStrategy;
|
|
35
36
|
this.configService = configService;
|
|
36
37
|
this.queueService = queueService;
|
|
37
|
-
this.logger = new common_1.Logger(
|
|
38
|
+
this.logger = new common_1.Logger(IntegrationService_1.name);
|
|
38
39
|
this.gmailOAuthStates = new Map();
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
+
deriveServiceType(integration_type, integration_provider, config_json) {
|
|
42
|
+
return 'API';
|
|
43
|
+
}
|
|
44
|
+
async sendMessage({ levelId, levelType, app_code, to, message, mode, priority = 1, user_id, }) {
|
|
41
45
|
try {
|
|
42
|
-
const
|
|
43
|
-
if (!
|
|
46
|
+
const configs = await this.getActiveConfigs(levelId, levelType, app_code, mode);
|
|
47
|
+
if (!configs.length) {
|
|
44
48
|
throw new Error(`No active communication configuration found for ${levelType} ${levelId}`);
|
|
45
49
|
}
|
|
46
|
-
const
|
|
47
|
-
for (const
|
|
50
|
+
const sortedConfigs = this.sortConfigsByPriority(configs, priority);
|
|
51
|
+
for (const config of sortedConfigs) {
|
|
48
52
|
try {
|
|
49
|
-
const result = await this.
|
|
53
|
+
const result = await this.sendViaConfig(config, to, message, user_id);
|
|
50
54
|
if (result.success) {
|
|
51
|
-
this.logger.log(`Message sent successfully via ${
|
|
55
|
+
this.logger.log(`Message sent successfully via ${config.integration_provider}`);
|
|
52
56
|
return result;
|
|
53
57
|
}
|
|
54
|
-
this.logger.warn(`Failed to send via ${
|
|
58
|
+
this.logger.warn(`Failed to send via ${config.integration_provider}: ${result.error}`);
|
|
55
59
|
}
|
|
56
60
|
catch (error) {
|
|
57
|
-
this.logger.error(`Error sending via ${
|
|
61
|
+
this.logger.error(`Error sending via ${config.integration_provider}:`, error.message);
|
|
58
62
|
continue;
|
|
59
63
|
}
|
|
60
64
|
}
|
|
@@ -65,74 +69,64 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
65
69
|
throw error;
|
|
66
70
|
}
|
|
67
71
|
}
|
|
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 });
|
|
72
|
+
async getActiveConfigs(levelId, levelType, app_code, mode) {
|
|
73
|
+
const queryBuilder = this.configRepository
|
|
74
|
+
.createQueryBuilder('config')
|
|
75
|
+
.where('config.level_id = :levelId', { levelId })
|
|
76
|
+
.andWhere('config.level_type = :levelType', { levelType })
|
|
77
|
+
.andWhere('config.app_code = :app_code', { app_code })
|
|
78
|
+
.andWhere('config.status = 1');
|
|
93
79
|
if (mode) {
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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;
|
|
80
|
+
queryBuilder.andWhere('config.integration_type = :mode', { mode });
|
|
81
|
+
}
|
|
82
|
+
return await queryBuilder.getMany();
|
|
83
|
+
}
|
|
84
|
+
async getAllIntegrationData(loggedInUser, integration_type) {
|
|
85
|
+
try {
|
|
86
|
+
const allIntegrationData = await this.dataSource.query(`SELECT * FROM cr_integration_master`);
|
|
87
|
+
if (integration_type) {
|
|
88
|
+
return allIntegrationData.filter((data) => data.integration_type.toLowerCase() ===
|
|
89
|
+
integration_type.toLowerCase());
|
|
90
|
+
}
|
|
91
|
+
return allIntegrationData;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
this.logger.error('Error fetching integration data:', error.message);
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
118
97
|
}
|
|
119
|
-
|
|
120
|
-
return
|
|
98
|
+
sortConfigsByPriority(configs, _priority) {
|
|
99
|
+
return configs.sort((a, b) => {
|
|
100
|
+
if (a.is_default !== b.is_default) {
|
|
101
|
+
return a.is_default ? -1 : 1;
|
|
102
|
+
}
|
|
103
|
+
return a.priority - b.priority;
|
|
104
|
+
});
|
|
121
105
|
}
|
|
122
|
-
async
|
|
123
|
-
const strategy = this.
|
|
124
|
-
|
|
106
|
+
async sendViaConfig(config, to, message, user_id) {
|
|
107
|
+
const strategy = this.integrationFactory.create(config.integration_type, 'API', config.integration_provider);
|
|
108
|
+
let finalConfig = config.config_json;
|
|
109
|
+
if (user_id) {
|
|
110
|
+
const userIntegrationData = await this.getUserIntegrationForStrategy(user_id, config.id);
|
|
111
|
+
if (userIntegrationData) {
|
|
112
|
+
finalConfig = {
|
|
113
|
+
...config.config_json,
|
|
114
|
+
external_user_id: userIntegrationData.external_user_id,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const result = await strategy.sendMessage(to, message, finalConfig);
|
|
125
119
|
if (result.refreshedToken && result.success) {
|
|
126
120
|
try {
|
|
127
|
-
const currentConfig =
|
|
121
|
+
const currentConfig = config.config_json;
|
|
128
122
|
const updatedConfig = {
|
|
129
123
|
...currentConfig,
|
|
130
124
|
accessToken: result.refreshedToken,
|
|
131
125
|
};
|
|
132
|
-
await this.configRepository.update(
|
|
126
|
+
await this.configRepository.update(config.id, {
|
|
133
127
|
config_json: updatedConfig,
|
|
134
128
|
});
|
|
135
|
-
this.logger.log(`Updated access token for ${
|
|
129
|
+
this.logger.log(`Updated access token for ${config.integration_provider} configuration`);
|
|
136
130
|
}
|
|
137
131
|
catch (error) {
|
|
138
132
|
this.logger.warn(`Failed to update refreshed token in database: ${error.message}`);
|
|
@@ -140,53 +134,60 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
140
134
|
}
|
|
141
135
|
return result;
|
|
142
136
|
}
|
|
143
|
-
async
|
|
144
|
-
await this.validateUniqueActiveConfig(levelId, levelType, configType);
|
|
137
|
+
async createIntegrationConfig(levelId, levelType, app_code, configType, provider, integration_source_id, config, priority, is_default) {
|
|
138
|
+
await this.validateUniqueActiveConfig(levelId, levelType, app_code, configType, provider);
|
|
139
|
+
await this.configRepository.update({
|
|
140
|
+
level_id: levelId,
|
|
141
|
+
level_type: levelType,
|
|
142
|
+
app_code: app_code,
|
|
143
|
+
integration_type: configType,
|
|
144
|
+
status: 1,
|
|
145
|
+
}, { status: 0 });
|
|
145
146
|
const supportedCombinations = await this.getSupportedCombinations();
|
|
146
|
-
const
|
|
147
|
-
combo.service.toLowerCase() === service.toLowerCase() &&
|
|
147
|
+
const validCombination = supportedCombinations.find((combo) => combo.mode === configType &&
|
|
148
148
|
combo.provider.toLowerCase() === provider.toLowerCase());
|
|
149
|
-
if (!
|
|
150
|
-
throw new Error(`Unsupported combination: ${configType}/${
|
|
149
|
+
if (!validCombination) {
|
|
150
|
+
throw new Error(`Unsupported combination: ${configType}/${provider}`);
|
|
151
151
|
}
|
|
152
|
-
const
|
|
152
|
+
const service = validCombination.service;
|
|
153
|
+
const requiresOAuth = this.requiresOAuthFlow(configType, provider, config);
|
|
153
154
|
if (requiresOAuth) {
|
|
154
|
-
return await this.generateOAuthUrl(levelId, levelType,
|
|
155
|
+
return await this.generateOAuthUrl(levelId, levelType, app_code, configType, provider, integration_source_id, config, priority, is_default);
|
|
155
156
|
}
|
|
156
|
-
return await this.createDirectConfig(levelId, levelType,
|
|
157
|
+
return await this.createDirectConfig(levelId, levelType, app_code, configType, provider, integration_source_id, config, priority, is_default);
|
|
157
158
|
}
|
|
158
159
|
getSupportedCombinations() {
|
|
159
|
-
return this.
|
|
160
|
+
return this.integrationFactory.getAllSupportedCombinations();
|
|
160
161
|
}
|
|
161
162
|
async getLevelConfigs(levelId, levelType, filters) {
|
|
162
163
|
const where = { level_id: levelId, level_type: levelType };
|
|
163
|
-
if (filters?.
|
|
164
|
-
where.
|
|
164
|
+
if (filters?.app_code) {
|
|
165
|
+
where.app_code = filters.app_code;
|
|
165
166
|
}
|
|
166
|
-
if (filters?.
|
|
167
|
-
where.
|
|
167
|
+
if (filters?.integration_type) {
|
|
168
|
+
where.integration_type = filters.integration_type;
|
|
168
169
|
}
|
|
169
|
-
if (filters?.
|
|
170
|
-
where.
|
|
170
|
+
if (filters?.integration_provider) {
|
|
171
|
+
where.integration_provider = filters.integration_provider;
|
|
171
172
|
}
|
|
172
|
-
const hubs = await this.
|
|
173
|
+
const hubs = await this.configRepository.find({
|
|
173
174
|
where,
|
|
174
175
|
order: { created_at: 'DESC' },
|
|
175
176
|
});
|
|
176
177
|
const enhancedHubs = await Promise.all(hubs.map(async (hub) => {
|
|
177
178
|
try {
|
|
178
|
-
const
|
|
179
|
-
where: { id: hub.
|
|
179
|
+
const relatedConfig = await this.configRepository.findOne({
|
|
180
|
+
where: { id: hub.id },
|
|
180
181
|
});
|
|
181
|
-
if (!
|
|
182
|
+
if (!relatedConfig) {
|
|
182
183
|
return {
|
|
183
184
|
...hub,
|
|
184
185
|
linkedSource: 'Configuration not found',
|
|
185
186
|
configDetails: null,
|
|
186
187
|
};
|
|
187
188
|
}
|
|
188
|
-
const linkedSource = this.extractLinkedSource(hub.
|
|
189
|
-
const configDetails = this.extractConfigDetails(hub.
|
|
189
|
+
const linkedSource = this.extractLinkedSource(hub.integration_type, hub.integration_provider, relatedConfig.config_json);
|
|
190
|
+
const configDetails = this.extractConfigDetails(hub.integration_type, hub.integration_provider, relatedConfig.config_json);
|
|
190
191
|
return {
|
|
191
192
|
...hub,
|
|
192
193
|
linkedSource,
|
|
@@ -204,14 +205,14 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
204
205
|
}));
|
|
205
206
|
return enhancedHubs;
|
|
206
207
|
}
|
|
207
|
-
extractLinkedSource(configType,
|
|
208
|
-
const key = `${configType.toLowerCase()}_${
|
|
208
|
+
extractLinkedSource(configType, provider, configJson) {
|
|
209
|
+
const key = `${configType.toLowerCase()}_${provider.toLowerCase()}`;
|
|
209
210
|
try {
|
|
210
211
|
switch (key) {
|
|
211
|
-
case '
|
|
212
|
+
case 'email_gmail':
|
|
212
213
|
case 'email_smtp_gmail':
|
|
213
214
|
return configJson?.email || 'Gmail account not configured';
|
|
214
|
-
case '
|
|
215
|
+
case 'email_outlook':
|
|
215
216
|
case 'email_smtp_outlook':
|
|
216
217
|
return configJson?.email || 'Outlook account not configured';
|
|
217
218
|
case 'wa_api_whatsapp':
|
|
@@ -234,8 +235,8 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
234
235
|
return configJson?.userName
|
|
235
236
|
? `Ozonetel Voice: ${configJson.userName}`
|
|
236
237
|
: 'Ozonetel voice not configured';
|
|
237
|
-
case '
|
|
238
|
-
case '
|
|
238
|
+
case 'email_aws-ses':
|
|
239
|
+
case 'email_ses':
|
|
239
240
|
return configJson?.fromEmail || 'AWS SES not configured';
|
|
240
241
|
case 'email_smtp_sendgrid':
|
|
241
242
|
return configJson?.from || 'SendGrid not configured';
|
|
@@ -262,11 +263,11 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
262
263
|
return 'Configuration error';
|
|
263
264
|
}
|
|
264
265
|
}
|
|
265
|
-
extractConfigDetails(configType,
|
|
266
|
-
const key = `${configType.toLowerCase()}_${
|
|
266
|
+
extractConfigDetails(configType, provider, configJson) {
|
|
267
|
+
const key = `${configType.toLowerCase()}_${provider.toLowerCase()}`;
|
|
267
268
|
try {
|
|
268
269
|
switch (key) {
|
|
269
|
-
case '
|
|
270
|
+
case 'email_gmail':
|
|
270
271
|
return {
|
|
271
272
|
email: configJson?.email,
|
|
272
273
|
authMethod: configJson?.authMethod || 'OAUTH2',
|
|
@@ -281,7 +282,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
281
282
|
authMethod: 'SMTP',
|
|
282
283
|
hasPassword: !!configJson?.password,
|
|
283
284
|
};
|
|
284
|
-
case '
|
|
285
|
+
case 'email_outlook':
|
|
285
286
|
return {
|
|
286
287
|
email: configJson?.email,
|
|
287
288
|
authMethod: 'OAUTH2',
|
|
@@ -329,8 +330,8 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
329
330
|
agentLoginUrl: configJson?.agentLoginUrl,
|
|
330
331
|
hasApiKey: !!configJson?.apiKey,
|
|
331
332
|
};
|
|
332
|
-
case '
|
|
333
|
-
case '
|
|
333
|
+
case 'email_aws-ses':
|
|
334
|
+
case 'email_ses':
|
|
334
335
|
return {
|
|
335
336
|
fromEmail: configJson?.fromEmail,
|
|
336
337
|
region: configJson?.region,
|
|
@@ -398,102 +399,86 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
398
399
|
}
|
|
399
400
|
}
|
|
400
401
|
async updateConfigStatus(hubId, status) {
|
|
401
|
-
const
|
|
402
|
+
const config = await this.configRepository.findOne({
|
|
402
403
|
where: { id: hubId },
|
|
403
404
|
});
|
|
404
|
-
if (!
|
|
405
|
-
throw new Error('
|
|
405
|
+
if (!config) {
|
|
406
|
+
throw new Error('Integration configuration not found');
|
|
406
407
|
}
|
|
407
408
|
if (status === 1) {
|
|
408
|
-
await this.
|
|
409
|
-
level_id:
|
|
410
|
-
level_type:
|
|
411
|
-
|
|
409
|
+
await this.configRepository.update({
|
|
410
|
+
level_id: config.level_id,
|
|
411
|
+
level_type: config.level_type,
|
|
412
|
+
app_code: config.app_code,
|
|
413
|
+
integration_type: config.integration_type,
|
|
412
414
|
status: 1,
|
|
413
415
|
id: (0, typeorm_2.Not)(hubId),
|
|
414
416
|
}, { status: 0 });
|
|
415
417
|
}
|
|
416
|
-
await this.
|
|
418
|
+
await this.configRepository.update(hubId, { status });
|
|
417
419
|
}
|
|
418
|
-
async deleteConfiguration(
|
|
419
|
-
const
|
|
420
|
-
where: { id:
|
|
420
|
+
async deleteConfiguration(configId) {
|
|
421
|
+
const config = await this.configRepository.findOne({
|
|
422
|
+
where: { id: configId },
|
|
421
423
|
});
|
|
422
|
-
if (!
|
|
423
|
-
throw new Error('
|
|
424
|
+
if (!config) {
|
|
425
|
+
throw new Error('Integration configuration not found');
|
|
424
426
|
}
|
|
425
|
-
await this.
|
|
426
|
-
|
|
427
|
-
this.logger.log(`Communication configuration deleted: Hub ${hubId}, Config ${hub.config_id}`);
|
|
427
|
+
await this.configRepository.delete(configId);
|
|
428
|
+
this.logger.log(`Integration configuration deleted: ${configId}`);
|
|
428
429
|
}
|
|
429
430
|
async updateConfiguration(hubId, updateData) {
|
|
430
|
-
const
|
|
431
|
+
const config = await this.configRepository.findOne({
|
|
431
432
|
where: { id: hubId },
|
|
432
433
|
});
|
|
433
|
-
if (!
|
|
434
|
-
throw new Error('
|
|
434
|
+
if (!config) {
|
|
435
|
+
throw new Error('Integration configuration not found');
|
|
435
436
|
}
|
|
436
437
|
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
438
|
const updatedConfigJson = {
|
|
444
|
-
...
|
|
439
|
+
...config.config_json,
|
|
445
440
|
...updateData.config,
|
|
446
441
|
};
|
|
447
|
-
await this.configRepository.update(
|
|
442
|
+
await this.configRepository.update(config.id, {
|
|
448
443
|
config_json: updatedConfigJson,
|
|
449
444
|
});
|
|
450
445
|
}
|
|
451
|
-
if (updateData.status === 1) {
|
|
452
|
-
await this.validateUniqueActiveConfig(hub.level_id, hub.level_type, hub.communication_config_type, hubId);
|
|
453
|
-
}
|
|
454
446
|
if (updateData.is_default === true) {
|
|
455
|
-
await this.
|
|
456
|
-
level_id:
|
|
457
|
-
level_type:
|
|
458
|
-
|
|
447
|
+
await this.configRepository.update({
|
|
448
|
+
level_id: config.level_id,
|
|
449
|
+
level_type: config.level_type,
|
|
450
|
+
integration_type: config.integration_type,
|
|
459
451
|
id: (0, typeorm_2.Not)(hubId),
|
|
460
452
|
}, { is_default: false });
|
|
461
453
|
}
|
|
462
|
-
const
|
|
463
|
-
if (updateData.priority !== undefined)
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
if (
|
|
470
|
-
|
|
454
|
+
const directUpdates = {};
|
|
455
|
+
if (updateData.priority !== undefined)
|
|
456
|
+
directUpdates.priority = updateData.priority;
|
|
457
|
+
if (updateData.is_default !== undefined)
|
|
458
|
+
directUpdates.is_default = updateData.is_default;
|
|
459
|
+
if (updateData.status !== undefined)
|
|
460
|
+
directUpdates.status = updateData.status;
|
|
461
|
+
if (Object.keys(directUpdates).length > 0) {
|
|
462
|
+
await this.configRepository.update(config.id, directUpdates);
|
|
471
463
|
}
|
|
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
464
|
const updatedConfig = await this.configRepository.findOne({
|
|
479
|
-
where: { id:
|
|
465
|
+
where: { id: hubId },
|
|
480
466
|
});
|
|
481
|
-
this.logger.log(`Communication configuration updated: Hub ${hubId}, Type ${hub.communication_config_type}`);
|
|
482
467
|
return {
|
|
483
|
-
...
|
|
468
|
+
...updatedConfig,
|
|
484
469
|
config: updatedConfig?.config_json,
|
|
485
470
|
};
|
|
486
471
|
}
|
|
487
472
|
async sendGenericMessage(messageDto) {
|
|
488
473
|
try {
|
|
489
|
-
const { levelId, levelType, to, message, type, priority = 'medium', subject, html, cc, bcc, attachments, mediaUrl, templateId, variables, } = messageDto;
|
|
474
|
+
const { levelId, levelType, app_code, to, message, type, priority = 'medium', subject, html, cc, bcc, attachments, mediaUrl, templateId, variables, user_id, } = messageDto;
|
|
490
475
|
const communicationType = this.detectCommunicationType(to, type);
|
|
491
|
-
const
|
|
492
|
-
if (!
|
|
493
|
-
this.logger.warn(`No communication hubs found for ${levelType} ${levelId}. Please configure
|
|
476
|
+
const configs = await this.getActiveConfigs(levelId, levelType, app_code, communicationType);
|
|
477
|
+
if (!configs.length) {
|
|
478
|
+
this.logger.warn(`No communication hubs found for ${levelType} ${levelId}. Please configure integration providers using the createIntegrationConfig method.`);
|
|
494
479
|
throw new Error(`No active ${communicationType} configuration found for ${levelType} ${levelId}. Please configure a communication provider first.`);
|
|
495
480
|
}
|
|
496
|
-
const
|
|
481
|
+
const sortedConfigs = this.sortConfigsByPriorityAndDefault(configs, priority);
|
|
497
482
|
const enhancedConfig = {
|
|
498
483
|
subject,
|
|
499
484
|
html,
|
|
@@ -506,30 +491,40 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
506
491
|
const results = [];
|
|
507
492
|
let hasSuccess = false;
|
|
508
493
|
for (const recipient of to) {
|
|
509
|
-
for (const hub of
|
|
494
|
+
for (const hub of sortedConfigs) {
|
|
510
495
|
try {
|
|
511
|
-
const
|
|
496
|
+
const serviceType = this.deriveServiceType(hub.integration_type, hub.integration_provider, hub.config_json);
|
|
497
|
+
const strategy = this.integrationFactory.create(hub.integration_type, serviceType, hub.integration_provider);
|
|
512
498
|
let processedMessage = message;
|
|
513
499
|
if (templateId && variables) {
|
|
514
500
|
processedMessage = this.processTemplate(message, variables);
|
|
515
501
|
}
|
|
516
|
-
|
|
517
|
-
...hub.
|
|
502
|
+
let finalConfig = {
|
|
503
|
+
...hub.config_json,
|
|
518
504
|
...enhancedConfig,
|
|
519
505
|
templateId,
|
|
520
506
|
variables,
|
|
521
507
|
};
|
|
508
|
+
if (user_id) {
|
|
509
|
+
const userIntegrationData = await this.getUserIntegrationForStrategy(user_id, hub.id);
|
|
510
|
+
if (userIntegrationData) {
|
|
511
|
+
finalConfig = {
|
|
512
|
+
...finalConfig,
|
|
513
|
+
external_user_id: userIntegrationData.external_user_id,
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
}
|
|
522
517
|
const result = await strategy.sendMessage(recipient, processedMessage, finalConfig);
|
|
523
518
|
if (result.success) {
|
|
524
|
-
this.logger.log(`Generic message sent successfully via ${hub.
|
|
519
|
+
this.logger.log(`Generic message sent successfully via ${hub.integration_provider} to ${recipient}`);
|
|
525
520
|
results.push(result);
|
|
526
521
|
hasSuccess = true;
|
|
527
522
|
break;
|
|
528
523
|
}
|
|
529
|
-
this.logger.warn(`Failed to send via ${hub.
|
|
524
|
+
this.logger.warn(`Failed to send via ${hub.integration_provider} to ${recipient}: ${result.error}`);
|
|
530
525
|
}
|
|
531
526
|
catch (error) {
|
|
532
|
-
this.logger.error(`Error sending via ${hub.
|
|
527
|
+
this.logger.error(`Error sending via ${hub.integration_provider} to ${recipient}:`, error.message);
|
|
533
528
|
continue;
|
|
534
529
|
}
|
|
535
530
|
}
|
|
@@ -545,28 +540,38 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
545
540
|
}
|
|
546
541
|
}
|
|
547
542
|
else {
|
|
548
|
-
for (const hub of
|
|
543
|
+
for (const hub of sortedConfigs) {
|
|
549
544
|
try {
|
|
550
|
-
const
|
|
545
|
+
const serviceType = this.deriveServiceType(hub.integration_type, hub.integration_provider, hub.config_json);
|
|
546
|
+
const strategy = this.integrationFactory.create(hub.integration_type, serviceType, hub.integration_provider);
|
|
551
547
|
let processedMessage = message;
|
|
552
548
|
if (html && variables) {
|
|
553
549
|
processedMessage = this.processTemplate(html ? html : message, variables);
|
|
554
550
|
}
|
|
555
|
-
|
|
556
|
-
...hub.
|
|
551
|
+
let finalConfig = {
|
|
552
|
+
...hub.config_json,
|
|
557
553
|
...enhancedConfig,
|
|
558
554
|
templateId,
|
|
559
555
|
variables,
|
|
560
556
|
};
|
|
557
|
+
if (user_id) {
|
|
558
|
+
const userIntegrationData = await this.getUserIntegrationForStrategy(user_id, hub.id);
|
|
559
|
+
if (userIntegrationData) {
|
|
560
|
+
finalConfig = {
|
|
561
|
+
...finalConfig,
|
|
562
|
+
external_user_id: userIntegrationData.external_user_id,
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
}
|
|
561
566
|
const result = await strategy.sendMessage(to, processedMessage, finalConfig);
|
|
562
567
|
if (result.success) {
|
|
563
|
-
this.logger.log(`Generic message sent successfully via ${hub.
|
|
568
|
+
this.logger.log(`Generic message sent successfully via ${hub.integration_provider} to ${to}`);
|
|
564
569
|
return result;
|
|
565
570
|
}
|
|
566
|
-
this.logger.warn(`Failed to send via ${hub.
|
|
571
|
+
this.logger.warn(`Failed to send via ${hub.integration_provider}: ${result.error}`);
|
|
567
572
|
}
|
|
568
573
|
catch (error) {
|
|
569
|
-
this.logger.error(`Error sending via ${hub.
|
|
574
|
+
this.logger.error(`Error sending via ${hub.integration_provider}:`, error.message);
|
|
570
575
|
continue;
|
|
571
576
|
}
|
|
572
577
|
}
|
|
@@ -580,7 +585,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
580
585
|
}
|
|
581
586
|
async sendBulkMessage(bulkDto) {
|
|
582
587
|
try {
|
|
583
|
-
const { levelId, levelType, recipients, message, type, priority = 'low', subject, html, templateId, variables, batchSize = 10, } = bulkDto;
|
|
588
|
+
const { levelId, levelType, app_code, recipients, message, type, priority = 'low', subject, html, templateId, variables, batchSize = 10, } = bulkDto;
|
|
584
589
|
const results = [];
|
|
585
590
|
const batches = this.chunkArray(recipients, batchSize);
|
|
586
591
|
for (let i = 0; i < batches.length; i++) {
|
|
@@ -591,6 +596,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
591
596
|
const messageDto = {
|
|
592
597
|
levelId,
|
|
593
598
|
levelType,
|
|
599
|
+
app_code,
|
|
594
600
|
to: recipient,
|
|
595
601
|
message,
|
|
596
602
|
type,
|
|
@@ -663,6 +669,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
663
669
|
const messageDto = {
|
|
664
670
|
levelId: templateDto.levelId,
|
|
665
671
|
levelType: templateDto.levelType,
|
|
672
|
+
app_code: templateDto.app_code,
|
|
666
673
|
to: templateDto.to,
|
|
667
674
|
message: processedMessage,
|
|
668
675
|
subject: processedSubject,
|
|
@@ -678,15 +685,15 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
678
685
|
}
|
|
679
686
|
const recipient = Array.isArray(to) ? to[0] : to;
|
|
680
687
|
if (recipient.includes('@')) {
|
|
681
|
-
return
|
|
688
|
+
return 'EMAIL';
|
|
682
689
|
}
|
|
683
690
|
if (/^\+?[\d\s\-\(\)]+$/.test(recipient)) {
|
|
684
|
-
return
|
|
691
|
+
return 'SMS';
|
|
685
692
|
}
|
|
686
|
-
return
|
|
693
|
+
return 'EMAIL';
|
|
687
694
|
}
|
|
688
|
-
|
|
689
|
-
return
|
|
695
|
+
sortConfigsByPriorityAndDefault(configs, _priority) {
|
|
696
|
+
return configs.sort((a, b) => {
|
|
690
697
|
if (a.is_default !== b.is_default) {
|
|
691
698
|
return b.is_default ? 1 : -1;
|
|
692
699
|
}
|
|
@@ -716,7 +723,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
716
723
|
}
|
|
717
724
|
return chunks;
|
|
718
725
|
}
|
|
719
|
-
async initGmailOAuth(levelId, levelType, email) {
|
|
726
|
+
async initGmailOAuth(levelId, levelType, app_code, email) {
|
|
720
727
|
try {
|
|
721
728
|
const clientId = this.configService.get('CLIENT_ID');
|
|
722
729
|
const clientSecret = this.configService.get('CLIENT_SECRET');
|
|
@@ -729,6 +736,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
729
736
|
this.gmailOAuthStates.set(state, {
|
|
730
737
|
levelId,
|
|
731
738
|
levelType,
|
|
739
|
+
app_code,
|
|
732
740
|
email,
|
|
733
741
|
timestamp: Date.now(),
|
|
734
742
|
});
|
|
@@ -795,24 +803,23 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
795
803
|
tokenType: tokens.token_type,
|
|
796
804
|
expiryDate: tokens.expiry_date,
|
|
797
805
|
};
|
|
798
|
-
await this.validateUniqueActiveConfig(oauthState.levelId, oauthState.levelType,
|
|
799
|
-
const
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
806
|
+
await this.validateUniqueActiveConfig(oauthState.levelId, oauthState.levelType, oauthState.app_code, 'EMAIL', 'gmail');
|
|
807
|
+
const config = this.configRepository.create({
|
|
808
|
+
app_code: oauthState.app_code,
|
|
809
|
+
integration_type: 'EMAIL',
|
|
810
|
+
integration_provider: 'gmail',
|
|
811
|
+
integration_source_id: 1,
|
|
804
812
|
level_id: oauthState.levelId,
|
|
805
813
|
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
814
|
status: 1,
|
|
815
|
+
priority: 1,
|
|
816
|
+
is_default: false,
|
|
817
|
+
config_json: gmailConfig,
|
|
811
818
|
});
|
|
812
|
-
const
|
|
819
|
+
const savedConfig = await this.configRepository.save(config);
|
|
813
820
|
this.logger.log(`Gmail OAuth configuration created successfully for ${oauthState.levelType} ${oauthState.levelId} and email ${email}`);
|
|
814
821
|
return {
|
|
815
|
-
hubId:
|
|
822
|
+
hubId: savedConfig.id,
|
|
816
823
|
configId: savedConfig.id,
|
|
817
824
|
};
|
|
818
825
|
}
|
|
@@ -834,7 +841,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
834
841
|
if (oauthState.email && oauthState.email !== email) {
|
|
835
842
|
throw new Error('Email mismatch with OAuth hint');
|
|
836
843
|
}
|
|
837
|
-
await this.validateUniqueActiveConfig(oauthState.levelId, oauthState.levelType,
|
|
844
|
+
await this.validateUniqueActiveConfig(oauthState.levelId, oauthState.levelType, oauthState.app_code, 'EMAIL', 'gmail');
|
|
838
845
|
const gmailConfig = {
|
|
839
846
|
email: email,
|
|
840
847
|
accessToken: accessToken,
|
|
@@ -845,23 +852,22 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
845
852
|
'https://www.googleapis.com/auth/userinfo.email',
|
|
846
853
|
],
|
|
847
854
|
};
|
|
848
|
-
const
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
855
|
+
const config = this.configRepository.create({
|
|
856
|
+
app_code: oauthState.app_code,
|
|
857
|
+
integration_type: 'EMAIL',
|
|
858
|
+
integration_provider: 'gmail',
|
|
859
|
+
integration_source_id: 1,
|
|
853
860
|
level_id: oauthState.levelId,
|
|
854
861
|
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
862
|
status: 1,
|
|
863
|
+
priority: 1,
|
|
864
|
+
is_default: false,
|
|
865
|
+
config_json: gmailConfig,
|
|
860
866
|
});
|
|
861
|
-
const
|
|
867
|
+
const savedConfig = await this.configRepository.save(config);
|
|
862
868
|
this.logger.log(`Gmail tokens configuration created successfully for ${oauthState.levelType} ${oauthState.levelId} and email ${email}`);
|
|
863
869
|
return {
|
|
864
|
-
hubId:
|
|
870
|
+
hubId: savedConfig.id,
|
|
865
871
|
configId: savedConfig.id,
|
|
866
872
|
};
|
|
867
873
|
}
|
|
@@ -872,19 +878,13 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
872
878
|
}
|
|
873
879
|
async testGmailConfig(hubId) {
|
|
874
880
|
try {
|
|
875
|
-
const
|
|
881
|
+
const integrationConfig = await this.configRepository.findOne({
|
|
876
882
|
where: { id: hubId },
|
|
877
883
|
});
|
|
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');
|
|
884
|
+
if (!integrationConfig) {
|
|
885
|
+
throw new Error('Integration config not found');
|
|
886
886
|
}
|
|
887
|
-
const isValid = await this.gmailApiStrategy.validateConnection(
|
|
887
|
+
const isValid = await this.gmailApiStrategy.validateConnection(integrationConfig.config_json);
|
|
888
888
|
if (!isValid) {
|
|
889
889
|
return {
|
|
890
890
|
success: false,
|
|
@@ -901,89 +901,89 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
901
901
|
generateSecureState() {
|
|
902
902
|
return Math.random().toString(36).substring(2) + Date.now().toString(36);
|
|
903
903
|
}
|
|
904
|
-
async validateUniqueActiveConfig(levelId, levelType, configType, excludeHubId) {
|
|
905
|
-
const query = this.
|
|
904
|
+
async validateUniqueActiveConfig(levelId, levelType, app_code, configType, provider, excludeHubId) {
|
|
905
|
+
const query = this.configRepository
|
|
906
906
|
.createQueryBuilder('hub')
|
|
907
907
|
.where('hub.level_id = :levelId', { levelId })
|
|
908
908
|
.andWhere('hub.level_type = :levelType', { levelType })
|
|
909
|
-
.andWhere('hub.
|
|
909
|
+
.andWhere('hub.app_code = :app_code', { app_code })
|
|
910
|
+
.andWhere('hub.integration_type = :configType', { configType })
|
|
911
|
+
.andWhere('hub.integration_provider = :provider', { provider })
|
|
910
912
|
.andWhere('hub.status = :status', { status: 1 });
|
|
911
913
|
if (excludeHubId) {
|
|
912
914
|
query.andWhere('hub.id != :excludeHubId', { excludeHubId });
|
|
913
915
|
}
|
|
914
916
|
const existingActiveConfigs = await query.getMany();
|
|
915
917
|
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.`);
|
|
918
|
+
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
919
|
}
|
|
925
920
|
}
|
|
926
|
-
requiresOAuthFlow(configType,
|
|
927
|
-
const key = `${configType.toLowerCase()}_${
|
|
921
|
+
requiresOAuthFlow(configType, provider, config) {
|
|
922
|
+
const key = `${configType.toLowerCase()}_${provider.toLowerCase()}`;
|
|
928
923
|
switch (key) {
|
|
929
|
-
case '
|
|
924
|
+
case 'email_gmail':
|
|
930
925
|
return !config.accessToken || config.useOAuth === true;
|
|
931
|
-
case '
|
|
926
|
+
case 'email_outlook':
|
|
932
927
|
return !config.accessToken || config.useOAuth === true;
|
|
933
928
|
default:
|
|
934
929
|
return false;
|
|
935
930
|
}
|
|
936
931
|
}
|
|
937
|
-
async generateOAuthUrl(levelId, levelType,
|
|
938
|
-
const key = `${configType.toLowerCase()}_${
|
|
932
|
+
async generateOAuthUrl(levelId, levelType, app_code, configType, provider, integration_source_id, config, priority, is_default) {
|
|
933
|
+
const key = `${configType.toLowerCase()}_${provider.toLowerCase()}`;
|
|
939
934
|
switch (key) {
|
|
940
|
-
case '
|
|
941
|
-
const gmailResult = await this.initGmailOAuth(levelId, levelType, config.email);
|
|
935
|
+
case 'email_gmail':
|
|
936
|
+
const gmailResult = await this.initGmailOAuth(levelId, levelType, app_code, config.email);
|
|
942
937
|
return {
|
|
943
938
|
authUrl: gmailResult.authUrl,
|
|
944
939
|
state: gmailResult.state,
|
|
945
940
|
message: 'Please complete Gmail OAuth authorization. Configuration will be created automatically after authorization.',
|
|
946
941
|
};
|
|
947
|
-
case '
|
|
948
|
-
const outlookResult = await this.initOutlookOAuth(levelId, levelType, config.email);
|
|
942
|
+
case 'email_outlook':
|
|
943
|
+
const outlookResult = await this.initOutlookOAuth(levelId, levelType, app_code, config.email);
|
|
949
944
|
return {
|
|
950
945
|
authUrl: outlookResult.authUrl,
|
|
951
946
|
state: outlookResult.state,
|
|
952
947
|
message: 'Please complete Outlook OAuth authorization. Configuration will be created automatically after authorization.',
|
|
953
948
|
};
|
|
954
949
|
default:
|
|
955
|
-
throw new Error(`OAuth not supported for ${configType}/${
|
|
950
|
+
throw new Error(`OAuth not supported for ${configType}/${provider}`);
|
|
956
951
|
}
|
|
957
952
|
}
|
|
958
|
-
async createDirectConfig(levelId, levelType,
|
|
959
|
-
await this.validateUniqueActiveConfig(levelId, levelType, configType);
|
|
953
|
+
async createDirectConfig(levelId, levelType, app_code, configType, provider, integration_source_id, config, priority, is_default) {
|
|
954
|
+
await this.validateUniqueActiveConfig(levelId, levelType, app_code, configType, provider);
|
|
955
|
+
await this.configRepository.update({
|
|
956
|
+
level_id: levelId,
|
|
957
|
+
level_type: levelType,
|
|
958
|
+
app_code: app_code,
|
|
959
|
+
integration_type: configType,
|
|
960
|
+
status: 1,
|
|
961
|
+
}, { status: 0 });
|
|
960
962
|
if (is_default) {
|
|
961
|
-
await this.
|
|
963
|
+
await this.configRepository.update({
|
|
962
964
|
level_id: levelId,
|
|
963
965
|
level_type: levelType,
|
|
964
|
-
|
|
966
|
+
app_code: app_code,
|
|
967
|
+
integration_type: configType,
|
|
965
968
|
}, { is_default: false });
|
|
966
969
|
}
|
|
967
|
-
const
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
970
|
+
const integrationConfig = this.configRepository.create({
|
|
971
|
+
app_code: app_code,
|
|
972
|
+
integration_type: configType,
|
|
973
|
+
integration_provider: provider,
|
|
974
|
+
integration_source_id: integration_source_id,
|
|
972
975
|
level_id: levelId,
|
|
973
976
|
level_type: levelType,
|
|
974
|
-
|
|
975
|
-
communication_config_type: configType,
|
|
976
|
-
service: service,
|
|
977
|
-
provider: provider,
|
|
977
|
+
status: 1,
|
|
978
978
|
priority: priority || 1,
|
|
979
979
|
is_default: is_default || false,
|
|
980
|
-
|
|
980
|
+
config_json: config,
|
|
981
981
|
});
|
|
982
|
-
const
|
|
983
|
-
this.logger.log(`Communication config created: ${configType}/${
|
|
984
|
-
return Array.isArray(
|
|
982
|
+
const savedConfig = await this.configRepository.save(integrationConfig);
|
|
983
|
+
this.logger.log(`Communication config created: ${configType}/${provider} for ${levelType} ${levelId}`);
|
|
984
|
+
return Array.isArray(savedConfig) ? savedConfig[0] : savedConfig;
|
|
985
985
|
}
|
|
986
|
-
async initOutlookOAuth(levelId, levelType, email) {
|
|
986
|
+
async initOutlookOAuth(levelId, levelType, app_code, email) {
|
|
987
987
|
try {
|
|
988
988
|
const clientId = this.configService.get('OUTLOOK_CLIENT_ID');
|
|
989
989
|
const tenantId = this.configService.get('OUTLOOK_TENANT_ID');
|
|
@@ -996,6 +996,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
996
996
|
this.gmailOAuthStates.set(state, {
|
|
997
997
|
levelId,
|
|
998
998
|
levelType,
|
|
999
|
+
app_code,
|
|
999
1000
|
email,
|
|
1000
1001
|
timestamp: Date.now(),
|
|
1001
1002
|
});
|
|
@@ -1064,7 +1065,7 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
1064
1065
|
if (!email) {
|
|
1065
1066
|
throw new Error('Failed to get user email');
|
|
1066
1067
|
}
|
|
1067
|
-
await this.validateUniqueActiveConfig(oauthState.levelId, oauthState.levelType,
|
|
1068
|
+
await this.validateUniqueActiveConfig(oauthState.levelId, oauthState.levelType, oauthState.app_code, 'EMAIL', 'outlook');
|
|
1068
1069
|
const outlookConfig = {
|
|
1069
1070
|
clientId,
|
|
1070
1071
|
tenantId,
|
|
@@ -1075,23 +1076,22 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
1075
1076
|
tokenType: tokens.token_type,
|
|
1076
1077
|
expiresIn: tokens.expires_in,
|
|
1077
1078
|
};
|
|
1078
|
-
const
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1079
|
+
const config = this.configRepository.create({
|
|
1080
|
+
app_code: oauthState.app_code,
|
|
1081
|
+
integration_type: 'EMAIL',
|
|
1082
|
+
integration_provider: 'outlook',
|
|
1083
|
+
integration_source_id: 1,
|
|
1083
1084
|
level_id: oauthState.levelId,
|
|
1084
1085
|
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
1086
|
status: 1,
|
|
1087
|
+
priority: 1,
|
|
1088
|
+
is_default: false,
|
|
1089
|
+
config_json: outlookConfig,
|
|
1090
1090
|
});
|
|
1091
|
-
const
|
|
1091
|
+
const savedConfig = await this.configRepository.save(config);
|
|
1092
1092
|
this.logger.log(`Outlook OAuth configuration created successfully for ${oauthState.levelType} ${oauthState.levelId} and email ${email}`);
|
|
1093
1093
|
return {
|
|
1094
|
-
hubId:
|
|
1094
|
+
hubId: savedConfig.id,
|
|
1095
1095
|
configId: savedConfig.id,
|
|
1096
1096
|
};
|
|
1097
1097
|
}
|
|
@@ -1100,31 +1100,19 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
1100
1100
|
throw new Error(`Failed to complete Outlook OAuth: ${error.message}`);
|
|
1101
1101
|
}
|
|
1102
1102
|
}
|
|
1103
|
-
async
|
|
1103
|
+
async getIntegrationConfigById(hubId) {
|
|
1104
1104
|
try {
|
|
1105
|
-
const
|
|
1105
|
+
const integrationConfig = await this.configRepository.findOne({
|
|
1106
1106
|
where: { id: hubId },
|
|
1107
1107
|
});
|
|
1108
|
-
if (!
|
|
1108
|
+
if (!integrationConfig) {
|
|
1109
1109
|
return null;
|
|
1110
1110
|
}
|
|
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);
|
|
1111
|
+
const linkedSource = this.extractLinkedSource(integrationConfig.integration_type, integrationConfig.integration_provider, integrationConfig.config_json);
|
|
1112
|
+
const configDetails = this.extractConfigDetails(integrationConfig.integration_type, integrationConfig.integration_provider, integrationConfig.config_json);
|
|
1125
1113
|
return {
|
|
1126
|
-
...
|
|
1127
|
-
config,
|
|
1114
|
+
...integrationConfig,
|
|
1115
|
+
config: integrationConfig,
|
|
1128
1116
|
linkedSource,
|
|
1129
1117
|
configDetails,
|
|
1130
1118
|
};
|
|
@@ -1134,17 +1122,17 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
1134
1122
|
throw new Error(`Failed to fetch communication configuration: ${error.message}`);
|
|
1135
1123
|
}
|
|
1136
1124
|
}
|
|
1137
|
-
async getSendGridTemplates(levelId, levelType) {
|
|
1125
|
+
async getSendGridTemplates(levelId, levelType, app_code) {
|
|
1138
1126
|
try {
|
|
1139
|
-
const hubs = await this.
|
|
1140
|
-
const sendGridHub = hubs.find((hub) => hub.
|
|
1127
|
+
const hubs = await this.getActiveConfigs(levelId, levelType, app_code, 'EMAIL');
|
|
1128
|
+
const sendGridHub = hubs.find((hub) => hub.integration_provider === 'sendgrid');
|
|
1141
1129
|
if (!sendGridHub) {
|
|
1142
1130
|
return {
|
|
1143
1131
|
success: false,
|
|
1144
1132
|
error: 'No active SendGrid configuration found for this level',
|
|
1145
1133
|
};
|
|
1146
1134
|
}
|
|
1147
|
-
const apiKey = sendGridHub.
|
|
1135
|
+
const apiKey = sendGridHub.config_json?.apiKey;
|
|
1148
1136
|
if (!apiKey) {
|
|
1149
1137
|
return {
|
|
1150
1138
|
success: false,
|
|
@@ -1179,19 +1167,131 @@ let CommunicationService = CommunicationService_1 = class CommunicationService {
|
|
|
1179
1167
|
};
|
|
1180
1168
|
}
|
|
1181
1169
|
}
|
|
1170
|
+
async createUserIntegration(createDto) {
|
|
1171
|
+
try {
|
|
1172
|
+
const existing = await this.userIntegrationRepository.findOne({
|
|
1173
|
+
where: {
|
|
1174
|
+
user_id: createDto.user_id,
|
|
1175
|
+
integration_config_id: createDto.integration_config_id,
|
|
1176
|
+
},
|
|
1177
|
+
});
|
|
1178
|
+
if (existing) {
|
|
1179
|
+
throw new Error('User integration mapping already exists');
|
|
1180
|
+
}
|
|
1181
|
+
const config = await this.configRepository.findOne({
|
|
1182
|
+
where: { id: createDto.integration_config_id },
|
|
1183
|
+
});
|
|
1184
|
+
if (!config) {
|
|
1185
|
+
throw new Error('Integration configuration not found');
|
|
1186
|
+
}
|
|
1187
|
+
const userIntegration = this.userIntegrationRepository.create(createDto);
|
|
1188
|
+
return await this.userIntegrationRepository.save(userIntegration);
|
|
1189
|
+
}
|
|
1190
|
+
catch (error) {
|
|
1191
|
+
this.logger.error(`Error creating user integration mapping: ${error.message}`);
|
|
1192
|
+
throw error;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
async getUserIntegrations(userId) {
|
|
1196
|
+
try {
|
|
1197
|
+
return await this.userIntegrationRepository.find({
|
|
1198
|
+
where: { user_id: userId, is_active: true },
|
|
1199
|
+
order: { created_at: 'DESC' },
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
catch (error) {
|
|
1203
|
+
this.logger.error(`Error fetching user integrations for user ${userId}: ${error.message}`);
|
|
1204
|
+
throw error;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
async getConfigUserIntegrations(configId) {
|
|
1208
|
+
try {
|
|
1209
|
+
return await this.userIntegrationRepository.find({
|
|
1210
|
+
where: { integration_config_id: configId, is_active: true },
|
|
1211
|
+
order: { created_at: 'DESC' },
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
catch (error) {
|
|
1215
|
+
this.logger.error(`Error fetching user integrations for config ${configId}: ${error.message}`);
|
|
1216
|
+
throw error;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
async getUserIntegrationByUserAndConfig(userId, configId) {
|
|
1220
|
+
try {
|
|
1221
|
+
return await this.userIntegrationRepository.findOne({
|
|
1222
|
+
where: {
|
|
1223
|
+
user_id: userId,
|
|
1224
|
+
integration_config_id: configId,
|
|
1225
|
+
is_active: true,
|
|
1226
|
+
},
|
|
1227
|
+
});
|
|
1228
|
+
}
|
|
1229
|
+
catch (error) {
|
|
1230
|
+
this.logger.error(`Error fetching user integration for user ${userId} and config ${configId}: ${error.message}`);
|
|
1231
|
+
throw error;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
async updateUserIntegration(id, updateDto) {
|
|
1235
|
+
try {
|
|
1236
|
+
const userIntegration = await this.userIntegrationRepository.findOne({
|
|
1237
|
+
where: { id },
|
|
1238
|
+
});
|
|
1239
|
+
if (!userIntegration) {
|
|
1240
|
+
throw new Error('User integration mapping not found');
|
|
1241
|
+
}
|
|
1242
|
+
Object.assign(userIntegration, updateDto);
|
|
1243
|
+
return await this.userIntegrationRepository.save(userIntegration);
|
|
1244
|
+
}
|
|
1245
|
+
catch (error) {
|
|
1246
|
+
this.logger.error(`Error updating user integration ${id}: ${error.message}`);
|
|
1247
|
+
throw error;
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
async deleteUserIntegration(id) {
|
|
1251
|
+
try {
|
|
1252
|
+
const userIntegration = await this.userIntegrationRepository.findOne({
|
|
1253
|
+
where: { id },
|
|
1254
|
+
});
|
|
1255
|
+
if (!userIntegration) {
|
|
1256
|
+
throw new Error('User integration mapping not found');
|
|
1257
|
+
}
|
|
1258
|
+
await this.userIntegrationRepository.remove(userIntegration);
|
|
1259
|
+
}
|
|
1260
|
+
catch (error) {
|
|
1261
|
+
this.logger.error(`Error deleting user integration ${id}: ${error.message}`);
|
|
1262
|
+
throw error;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
async getUserIntegrationForStrategy(userId, integrationConfigId) {
|
|
1266
|
+
try {
|
|
1267
|
+
const userIntegration = await this.getUserIntegrationByUserAndConfig(userId, integrationConfigId);
|
|
1268
|
+
if (!userIntegration) {
|
|
1269
|
+
return null;
|
|
1270
|
+
}
|
|
1271
|
+
return {
|
|
1272
|
+
external_user_id: userIntegration.external_user_id,
|
|
1273
|
+
external_user_data: userIntegration.external_user_data,
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
catch (error) {
|
|
1277
|
+
this.logger.error(`Error fetching user integration data for strategy: ${error.message}`);
|
|
1278
|
+
return null;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1182
1281
|
};
|
|
1183
|
-
exports.
|
|
1184
|
-
exports.
|
|
1282
|
+
exports.IntegrationService = IntegrationService;
|
|
1283
|
+
exports.IntegrationService = IntegrationService = IntegrationService_1 = __decorate([
|
|
1185
1284
|
(0, common_1.Injectable)(),
|
|
1186
|
-
__param(0, (0, typeorm_1.InjectRepository)(
|
|
1187
|
-
__param(1, (0, typeorm_1.InjectRepository)(
|
|
1188
|
-
__param(
|
|
1285
|
+
__param(0, (0, typeorm_1.InjectRepository)(integration_config_entity_1.IntegrationConfig)),
|
|
1286
|
+
__param(1, (0, typeorm_1.InjectRepository)(user_integration_entity_1.UserIntegration)),
|
|
1287
|
+
__param(7, (0, common_1.Inject)((0, common_1.forwardRef)(() => integration_queue_service_1.IntegrationQueueService))),
|
|
1189
1288
|
__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
1190
1289
|
typeorm_2.Repository,
|
|
1191
|
-
|
|
1290
|
+
typeorm_2.DataSource,
|
|
1291
|
+
integration_factory_1.IntegrationFactory,
|
|
1192
1292
|
gmail_api_strategy_1.GmailApiStrategy,
|
|
1193
1293
|
sendgrid_api_strategy_1.SendGridApiStrategy,
|
|
1194
1294
|
config_1.ConfigService,
|
|
1195
|
-
|
|
1196
|
-
],
|
|
1197
|
-
//# sourceMappingURL=
|
|
1295
|
+
integration_queue_service_1.IntegrationQueueService])
|
|
1296
|
+
], IntegrationService);
|
|
1297
|
+
//# sourceMappingURL=integration.service.js.map
|