rez_core 2.2.158 → 2.2.159
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module/auth/strategies/google.strategy.js +6 -1
- package/dist/module/auth/strategies/google.strategy.js.map +1 -1
- package/dist/module/auth/strategies/jwt.strategy.js +1 -1
- package/dist/module/auth/strategies/jwt.strategy.js.map +1 -1
- package/dist/module/communication/communication.module.js +13 -2
- package/dist/module/communication/communication.module.js.map +1 -1
- package/dist/module/communication/controller/communication.controller.js.map +1 -1
- package/dist/module/communication/dto/create-config.dto.js +11 -1
- package/dist/module/communication/dto/create-config.dto.js.map +1 -1
- package/dist/module/communication/entity/communication-config.entity.js.map +1 -1
- package/dist/module/communication/entity/communication-hub.entity.js +11 -1
- package/dist/module/communication/entity/communication-hub.entity.js.map +1 -1
- package/dist/module/communication/examples/usage.example.js +9 -9
- package/dist/module/communication/examples/usage.example.js.map +1 -1
- package/dist/module/communication/factories/communication.factory.js +4 -4
- package/dist/module/communication/factories/communication.factory.js.map +1 -1
- package/dist/module/communication/factories/email.factory.js +1 -1
- package/dist/module/communication/factories/email.factory.js.map +1 -1
- package/dist/module/communication/factories/sms.factory.js +1 -1
- package/dist/module/communication/factories/sms.factory.js.map +1 -1
- package/dist/module/communication/factories/telephone.factory.js +2 -4
- package/dist/module/communication/factories/telephone.factory.js.map +1 -1
- package/dist/module/communication/factories/whatsapp.factory.js +2 -4
- package/dist/module/communication/factories/whatsapp.factory.js.map +1 -1
- package/dist/module/communication/service/communication-queue.service.d.ts +40 -0
- package/dist/module/communication/service/communication-queue.service.js +147 -0
- package/dist/module/communication/service/communication-queue.service.js.map +1 -0
- package/dist/module/communication/service/communication.service.d.ts +34 -2
- package/dist/module/communication/service/communication.service.js +117 -24
- package/dist/module/communication/service/communication.service.js.map +1 -1
- package/dist/module/communication/service/oauth.service.js +25 -20
- package/dist/module/communication/service/oauth.service.js.map +1 -1
- package/dist/module/communication/strategies/email/gmail-api.strategy.js +16 -7
- package/dist/module/communication/strategies/email/gmail-api.strategy.js.map +1 -1
- package/dist/module/communication/strategies/gmail-smtp.strategy.js +2 -3
- package/dist/module/communication/strategies/gmail-smtp.strategy.js.map +1 -1
- package/dist/module/communication/strategies/gmail.strategy.js.map +1 -1
- package/dist/module/communication/strategies/knowlarity.strategy.js +20 -14
- package/dist/module/communication/strategies/knowlarity.strategy.js.map +1 -1
- package/dist/module/communication/strategies/outlook-smtp.strategy.js +2 -3
- package/dist/module/communication/strategies/outlook-smtp.strategy.js.map +1 -1
- package/dist/module/communication/strategies/outlook.strategy.js +1 -1
- package/dist/module/communication/strategies/outlook.strategy.js.map +1 -1
- package/dist/module/communication/strategies/sms.strategy.js +1 -3
- package/dist/module/communication/strategies/sms.strategy.js.map +1 -1
- package/dist/module/communication/strategies/whatsapp.strategy.js +1 -2
- package/dist/module/communication/strategies/whatsapp.strategy.js.map +1 -1
- package/dist/module/dashboard/dashboard.module.js +1 -1
- package/dist/module/dashboard/repository/dashboard.repository.js.map +1 -1
- package/dist/module/dashboard/service/dashboard.service.js +3 -3
- package/dist/module/dashboard/service/dashboard.service.js.map +1 -1
- package/dist/module/enterprise/repository/organization.repository.js.map +1 -1
- package/dist/module/filter/entity/saved-filter-master.entity.d.ts +1 -1
- package/dist/module/filter/service/filter.service.js +3 -3
- package/dist/module/filter/service/filter.service.js.map +1 -1
- package/dist/module/filter/service/saved-filter.service.js.map +1 -1
- package/dist/module/layout/controller/layout.controller.js +1 -1
- package/dist/module/layout/controller/layout.controller.js.map +1 -1
- package/dist/module/layout/repository/header-section.repository.js.map +1 -1
- package/dist/module/layout/service/header-section.service.js +2 -2
- package/dist/module/layout/service/header-section.service.js.map +1 -1
- package/dist/module/layout_preference/repository/layout_preference.repository.js +1 -1
- package/dist/module/layout_preference/service/layout_preference.service.js +1 -1
- package/dist/module/layout_preference/service/layout_preference.service.js.map +1 -1
- package/dist/module/listmaster/controller/list-master.controller.js +1 -1
- package/dist/module/listmaster/controller/list-master.controller.js.map +1 -1
- package/dist/module/listmaster/repository/list-master.repository.js.map +1 -1
- package/dist/module/listmaster/service/list-master.service.js +2 -2
- package/dist/module/listmaster/service/list-master.service.js.map +1 -1
- package/dist/module/master/controller/master.controller.js +2 -2
- package/dist/module/master/controller/master.controller.js.map +1 -1
- package/dist/module/master/service/master.service.js +1 -1
- package/dist/module/master/service/master.service.js.map +1 -1
- package/dist/module/meta/controller/attribute-master.controller.js +3 -3
- package/dist/module/meta/controller/attribute-master.controller.js.map +1 -1
- package/dist/module/meta/controller/entity-dynamic.controller.js +1 -1
- package/dist/module/meta/controller/entity-dynamic.controller.js.map +1 -1
- package/dist/module/meta/controller/entity.controller.js +2 -2
- package/dist/module/meta/controller/entity.controller.js.map +1 -1
- package/dist/module/meta/controller/media.controller.js +1 -1
- package/dist/module/meta/controller/media.controller.js.map +1 -1
- package/dist/module/meta/controller/meta.controller.js +1 -1
- package/dist/module/meta/controller/meta.controller.js.map +1 -1
- package/dist/module/meta/dto/entity-table.dto.js.map +1 -1
- package/dist/module/meta/entity/entity-master.entity.d.ts +1 -0
- package/dist/module/meta/entity/entity-master.entity.js +4 -0
- package/dist/module/meta/entity/entity-master.entity.js.map +1 -1
- package/dist/module/meta/entity/entity-table.entity.js.map +1 -1
- package/dist/module/meta/service/entity-dynamic.service.js +1 -1
- package/dist/module/meta/service/entity-dynamic.service.js.map +1 -1
- package/dist/module/meta/service/entity-list.service.js +11 -11
- package/dist/module/meta/service/entity-list.service.js.map +1 -1
- package/dist/module/meta/service/entity-service-impl.service.js +2 -2
- package/dist/module/meta/service/entity-service-impl.service.js.map +1 -1
- package/dist/module/meta/service/entity-table-column.service.js +3 -3
- package/dist/module/meta/service/entity-table-column.service.js.map +1 -1
- package/dist/module/meta/service/entity-table.service.js +2 -2
- package/dist/module/meta/service/entity-table.service.js.map +1 -1
- package/dist/module/meta/service/media-data.service.js +3 -3
- package/dist/module/meta/service/media-data.service.js.map +1 -1
- package/dist/module/meta/service/update-form-json.service.d.ts +3 -3
- package/dist/module/meta/service/update-form-json.service.js +1 -1
- package/dist/module/meta/service/update-form-json.service.js.map +1 -1
- package/dist/module/module/controller/menu.controller.js.map +1 -1
- package/dist/module/module/controller/module-access.controller.js +1 -1
- package/dist/module/module/controller/module-access.controller.js.map +1 -1
- package/dist/module/module/entity/module-access.entity.js.map +1 -1
- package/dist/module/module/entity/module.entity.js.map +1 -1
- package/dist/module/module/service/module-access.service.d.ts +1 -1
- package/dist/module/module/service/module-access.service.js +1 -1
- package/dist/module/module/service/module-access.service.js.map +1 -1
- package/dist/module/notification/controller/otp.controller.js +3 -3
- package/dist/module/notification/controller/otp.controller.js.map +1 -1
- package/dist/module/notification/service/email.service.js +2 -2
- package/dist/module/notification/service/email.service.js.map +1 -1
- package/dist/module/notification/service/otp.service.js +1 -1
- package/dist/module/notification/service/otp.service.js.map +1 -1
- package/dist/module/user/controller/login.controller.js +4 -2
- package/dist/module/user/controller/login.controller.js.map +1 -1
- package/dist/module/user/service/login.service.js +3 -3
- package/dist/module/user/service/login.service.js.map +1 -1
- package/dist/module/user/service/role.service.js +1 -1
- package/dist/module/user/service/role.service.js.map +1 -1
- package/dist/module/user/service/user.service.js +5 -5
- package/dist/module/user/service/user.service.js.map +1 -1
- package/dist/module/workflow/controller/workflow-meta.controller.js +1 -1
- package/dist/module/workflow/controller/workflow-meta.controller.js.map +1 -1
- package/dist/module/workflow/service/action.service.js +3 -3
- package/dist/module/workflow/service/action.service.js.map +1 -1
- package/dist/module/workflow/service/stage-group.service.js +1 -1
- package/dist/module/workflow/service/stage-group.service.js.map +1 -1
- package/dist/module/workflow/service/workflow-meta.service.js +5 -5
- package/dist/module/workflow/service/workflow-meta.service.js.map +1 -1
- package/dist/resources/properties.module.js +2 -2
- package/dist/resources/properties.module.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils/service/base64util.service.js.map +1 -1
- package/dist/utils/service/clockIDGenUtil.service.js.map +1 -1
- package/dist/utils/service/dateUtil.service.js +1 -1
- package/dist/utils/service/dateUtil.service.js.map +1 -1
- package/dist/utils/service/encryptUtil.service.js +4 -4
- package/dist/utils/service/encryptUtil.service.js.map +1 -1
- package/dist/utils/service/excel-helper.service.js +4 -1
- package/dist/utils/service/excel-helper.service.js.map +1 -1
- package/dist/utils/service/json-util.service.js.map +1 -1
- package/dist/utils/service/loggingUtil.service.js +3 -3
- package/dist/utils/service/loggingUtil.service.js.map +1 -1
- package/package.json +1 -1
- package/src/decorators/roles.decorator.ts +1 -1
- package/src/module/auth/strategies/google.strategy.ts +6 -1
- package/src/module/auth/strategies/jwt.strategy.ts +1 -1
- package/src/module/communication/communication.module.ts +13 -2
- package/src/module/communication/controller/communication.controller.ts +21 -18
- package/src/module/communication/dto/create-config.dto.ts +32 -13
- package/src/module/communication/entity/communication-config.entity.ts +15 -9
- package/src/module/communication/entity/communication-hub.entity.ts +29 -3
- package/src/module/communication/examples/usage.example.ts +18 -17
- package/src/module/communication/factories/communication.factory.ts +36 -18
- package/src/module/communication/factories/email.factory.ts +8 -5
- package/src/module/communication/factories/sms.factory.ts +8 -5
- package/src/module/communication/factories/telephone.factory.ts +9 -8
- package/src/module/communication/factories/whatsapp.factory.ts +9 -8
- package/src/module/communication/service/communication-queue.service.ts +214 -0
- package/src/module/communication/service/communication.service.ts +340 -101
- package/src/module/communication/service/oauth.service.ts +67 -46
- package/src/module/communication/strategies/email/gmail-api.strategy.ts +44 -24
- package/src/module/communication/strategies/gmail-smtp.strategy.ts +15 -11
- package/src/module/communication/strategies/gmail.strategy.ts +15 -7
- package/src/module/communication/strategies/knowlarity.strategy.ts +67 -33
- package/src/module/communication/strategies/outlook-smtp.strategy.ts +15 -11
- package/src/module/communication/strategies/outlook.strategy.ts +12 -5
- package/src/module/communication/strategies/sms.strategy.ts +13 -10
- package/src/module/communication/strategies/whatsapp.strategy.ts +13 -9
- package/src/module/dashboard/dashboard.module.ts +1 -1
- package/src/module/dashboard/repository/dashboard.repository.ts +4 -2
- package/src/module/dashboard/service/dashboard.service.ts +16 -12
- package/src/module/enterprise/repository/organization.repository.ts +3 -1
- package/src/module/enterprise/service/enterprise.service.ts +2 -2
- package/src/module/filter/entity/saved-filter-master.entity.ts +3 -3
- package/src/module/filter/service/filter.service.ts +3 -3
- package/src/module/filter/service/saved-filter.service.ts +1 -1
- package/src/module/layout/controller/layout.controller.ts +1 -1
- package/src/module/layout/repository/header-section.repository.ts +2 -2
- package/src/module/layout/service/header-section.service.ts +2 -3
- package/src/module/layout_preference/repository/layout_preference.repository.ts +2 -2
- package/src/module/layout_preference/service/layout_preference.service.ts +1 -1
- package/src/module/listmaster/controller/list-master.controller.ts +1 -1
- package/src/module/listmaster/repository/list-master.repository.ts +2 -2
- package/src/module/listmaster/service/list-master.service.ts +2 -2
- package/src/module/master/controller/master.controller.ts +2 -2
- package/src/module/master/service/master.service.ts +1 -1
- package/src/module/meta/controller/attribute-master.controller.ts +3 -3
- package/src/module/meta/controller/entity-dynamic.controller.ts +1 -1
- package/src/module/meta/controller/entity.controller.ts +2 -2
- package/src/module/meta/controller/media.controller.ts +1 -1
- package/src/module/meta/controller/meta.controller.ts +1 -1
- package/src/module/meta/dto/entity-tab.dto.ts +4 -4
- package/src/module/meta/dto/entity-table.dto.ts +5 -6
- package/src/module/meta/entity/entity-master.entity.ts +3 -0
- package/src/module/meta/entity/entity-table.entity.ts +1 -2
- package/src/module/meta/service/entity-dynamic.service.ts +1 -1
- package/src/module/meta/service/entity-list.service.ts +18 -14
- package/src/module/meta/service/entity-service-impl.service.ts +2 -2
- package/src/module/meta/service/entity-table-column.service.ts +3 -3
- package/src/module/meta/service/entity-table.service.ts +2 -2
- package/src/module/meta/service/entity.service.ts +1 -1
- package/src/module/meta/service/media-data.service.ts +3 -3
- package/src/module/meta/service/update-form-json.service.ts +17 -26
- package/src/module/module/controller/menu.controller.ts +0 -1
- package/src/module/module/controller/module-access.controller.ts +2 -3
- package/src/module/module/entity/menu.entity.ts +1 -1
- package/src/module/module/entity/module-access.entity.ts +6 -6
- package/src/module/module/entity/module-action.entity.ts +2 -2
- package/src/module/module/entity/module.entity.ts +0 -1
- package/src/module/module/service/module-access.service.ts +7 -8
- package/src/module/notification/controller/otp.controller.ts +10 -4
- package/src/module/notification/repository/otp.repository.ts +1 -1
- package/src/module/notification/service/email.service.ts +2 -2
- package/src/module/notification/service/otp.service.ts +8 -3
- package/src/module/third-party-module/third-party.module.ts +1 -1
- package/src/module/user/controller/login.controller.ts +27 -12
- package/src/module/user/service/login.service.ts +27 -27
- package/src/module/user/service/role.service.ts +1 -1
- package/src/module/user/service/user.service.ts +5 -5
- package/src/module/workflow/controller/workflow-meta.controller.ts +1 -1
- package/src/module/workflow/service/action.service.ts +3 -3
- package/src/module/workflow/service/stage-group.service.ts +1 -1
- package/src/module/workflow/service/workflow-meta.service.ts +5 -5
- package/src/resources/properties.module.ts +10 -10
- package/src/utils/dto/excel-data.dto.ts +2 -2
- package/src/utils/dto/excelsheet-data.dto.ts +3 -3
- package/src/utils/service/base64util.service.ts +16 -17
- package/src/utils/service/clockIDGenUtil.service.ts +15 -13
- package/src/utils/service/dateUtil.service.ts +6 -6
- package/src/utils/service/encryptUtil.service.ts +4 -4
- package/src/utils/service/excel-helper.service.ts +4 -1
- package/src/utils/service/file-util.service.ts +2 -2
- package/src/utils/service/json-util.service.ts +19 -19
- package/src/utils/service/loggingUtil.service.ts +4 -4
|
@@ -7,9 +7,9 @@ import { TelephoneFactory } from './telephone.factory';
|
|
|
7
7
|
|
|
8
8
|
export enum CommunicationMode {
|
|
9
9
|
EMAIL = 'EMAIL',
|
|
10
|
-
SMS = 'SMS',
|
|
10
|
+
SMS = 'SMS',
|
|
11
11
|
WA = 'WA',
|
|
12
|
-
TELEPHONE = 'TELEPHONE'
|
|
12
|
+
TELEPHONE = 'TELEPHONE',
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
@Injectable()
|
|
@@ -32,9 +32,13 @@ export class CommunicationFactory {
|
|
|
32
32
|
this.modeFactoryMap.set(CommunicationMode.TELEPHONE, this.telephoneFactory);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
create(
|
|
35
|
+
create(
|
|
36
|
+
mode: string,
|
|
37
|
+
service: string,
|
|
38
|
+
provider: string,
|
|
39
|
+
): CommunicationStrategy {
|
|
36
40
|
const communicationMode = mode.toUpperCase() as CommunicationMode;
|
|
37
|
-
|
|
41
|
+
|
|
38
42
|
if (!Object.values(CommunicationMode).includes(communicationMode)) {
|
|
39
43
|
throw new Error(`Unsupported communication mode: ${mode}`);
|
|
40
44
|
}
|
|
@@ -47,43 +51,57 @@ export class CommunicationFactory {
|
|
|
47
51
|
return factory.createProvider(service, provider);
|
|
48
52
|
}
|
|
49
53
|
|
|
50
|
-
getAllSupportedCombinations(): Array<{
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
getAllSupportedCombinations(): Array<{
|
|
55
|
+
mode: string;
|
|
56
|
+
service: string;
|
|
57
|
+
provider: string;
|
|
58
|
+
}> {
|
|
59
|
+
const combinations: Array<{
|
|
60
|
+
mode: string;
|
|
61
|
+
service: string;
|
|
62
|
+
provider: string;
|
|
63
|
+
}> = [];
|
|
64
|
+
|
|
53
65
|
this.modeFactoryMap.forEach((factory, mode) => {
|
|
54
66
|
const factoryCombinations = factory.getSupportedCombinations();
|
|
55
|
-
factoryCombinations.forEach(combo => {
|
|
67
|
+
factoryCombinations.forEach((combo) => {
|
|
56
68
|
combinations.push({
|
|
57
69
|
mode: mode,
|
|
58
70
|
service: combo.service,
|
|
59
|
-
provider: combo.provider
|
|
71
|
+
provider: combo.provider,
|
|
60
72
|
});
|
|
61
73
|
});
|
|
62
74
|
});
|
|
63
|
-
|
|
75
|
+
|
|
64
76
|
return combinations;
|
|
65
77
|
}
|
|
66
78
|
|
|
67
|
-
getSupportedCombinationsForMode(
|
|
79
|
+
getSupportedCombinationsForMode(
|
|
80
|
+
mode: string,
|
|
81
|
+
): Array<{ service: string; provider: string }> {
|
|
68
82
|
const communicationMode = mode.toUpperCase() as CommunicationMode;
|
|
69
83
|
const factory = this.modeFactoryMap.get(communicationMode);
|
|
70
|
-
|
|
84
|
+
|
|
71
85
|
if (!factory) {
|
|
72
86
|
throw new Error(`Factory not found for mode: ${mode}`);
|
|
73
87
|
}
|
|
74
|
-
|
|
88
|
+
|
|
75
89
|
return factory.getSupportedCombinations();
|
|
76
90
|
}
|
|
77
91
|
|
|
78
|
-
validateCombination(
|
|
92
|
+
validateCombination(
|
|
93
|
+
mode: string,
|
|
94
|
+
service: string,
|
|
95
|
+
provider: string,
|
|
96
|
+
): boolean {
|
|
79
97
|
try {
|
|
80
98
|
const communicationMode = mode.toUpperCase() as CommunicationMode;
|
|
81
99
|
const factory = this.modeFactoryMap.get(communicationMode);
|
|
82
|
-
|
|
100
|
+
|
|
83
101
|
if (!factory) {
|
|
84
102
|
return false;
|
|
85
103
|
}
|
|
86
|
-
|
|
104
|
+
|
|
87
105
|
return factory.validateCombination(service, provider);
|
|
88
106
|
} catch {
|
|
89
107
|
return false;
|
|
@@ -97,7 +115,7 @@ export class CommunicationFactory {
|
|
|
97
115
|
getProvidersByModeAndService(mode: string, service: string): string[] {
|
|
98
116
|
const combinations = this.getSupportedCombinationsForMode(mode);
|
|
99
117
|
return combinations
|
|
100
|
-
.filter(combo => combo.service.toLowerCase() === service.toLowerCase())
|
|
101
|
-
.map(combo => combo.provider);
|
|
118
|
+
.filter((combo) => combo.service.toLowerCase() === service.toLowerCase())
|
|
119
|
+
.map((combo) => combo.provider);
|
|
102
120
|
}
|
|
103
121
|
}
|
|
@@ -17,7 +17,7 @@ export class EmailFactory implements BaseFactory {
|
|
|
17
17
|
|
|
18
18
|
createProvider(service: string, provider: string): CommunicationStrategy {
|
|
19
19
|
const key = `${service.toLowerCase()}_${provider.toLowerCase()}`;
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
switch (key) {
|
|
22
22
|
case 'api_gmail':
|
|
23
23
|
return this.gmailStrategy;
|
|
@@ -27,9 +27,11 @@ export class EmailFactory implements BaseFactory {
|
|
|
27
27
|
return this.gmailSMTPStrategy;
|
|
28
28
|
case 'smtp_outlook':
|
|
29
29
|
return this.outlookSMTPStrategy;
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
default:
|
|
32
|
-
throw new Error(
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Unsupported EMAIL service/provider: ${service}/${provider}`,
|
|
34
|
+
);
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
|
|
@@ -44,8 +46,9 @@ export class EmailFactory implements BaseFactory {
|
|
|
44
46
|
|
|
45
47
|
validateCombination(service: string, provider: string): boolean {
|
|
46
48
|
return this.getSupportedCombinations().some(
|
|
47
|
-
combo =>
|
|
48
|
-
|
|
49
|
+
(combo) =>
|
|
50
|
+
combo.service.toLowerCase() === service.toLowerCase() &&
|
|
51
|
+
combo.provider.toLowerCase() === provider.toLowerCase(),
|
|
49
52
|
);
|
|
50
53
|
}
|
|
51
54
|
}
|
|
@@ -13,15 +13,17 @@ export class SmsFactory implements BaseFactory {
|
|
|
13
13
|
|
|
14
14
|
createProvider(service: string, provider: string): CommunicationStrategy {
|
|
15
15
|
const key = `${service.toLowerCase()}_${provider.toLowerCase()}`;
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
switch (key) {
|
|
18
18
|
case 'third_party_twilio':
|
|
19
19
|
return this.twilioStrategy;
|
|
20
20
|
case 'third_party_knowlarity':
|
|
21
21
|
return this.knowlarityStrategy;
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
default:
|
|
24
|
-
throw new Error(
|
|
24
|
+
throw new Error(
|
|
25
|
+
`Unsupported SMS service/provider: ${service}/${provider}`,
|
|
26
|
+
);
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
|
|
@@ -34,8 +36,9 @@ export class SmsFactory implements BaseFactory {
|
|
|
34
36
|
|
|
35
37
|
validateCombination(service: string, provider: string): boolean {
|
|
36
38
|
return this.getSupportedCombinations().some(
|
|
37
|
-
combo =>
|
|
38
|
-
|
|
39
|
+
(combo) =>
|
|
40
|
+
combo.service.toLowerCase() === service.toLowerCase() &&
|
|
41
|
+
combo.provider.toLowerCase() === provider.toLowerCase(),
|
|
39
42
|
);
|
|
40
43
|
}
|
|
41
44
|
}
|
|
@@ -9,26 +9,27 @@ export class TelephoneFactory implements BaseFactory {
|
|
|
9
9
|
|
|
10
10
|
createProvider(service: string, provider: string): CommunicationStrategy {
|
|
11
11
|
const key = `${service.toLowerCase()}_${provider.toLowerCase()}`;
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
switch (key) {
|
|
14
14
|
case 'third_party_knowlarity':
|
|
15
15
|
return this.knowlarityStrategy;
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
default:
|
|
18
|
-
throw new Error(
|
|
18
|
+
throw new Error(
|
|
19
|
+
`Unsupported Telephone service/provider: ${service}/${provider}`,
|
|
20
|
+
);
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
getSupportedCombinations(): Array<{ service: string; provider: string }> {
|
|
23
|
-
return [
|
|
24
|
-
{ service: 'THIRD_PARTY', provider: 'knowlarity' },
|
|
25
|
-
];
|
|
25
|
+
return [{ service: 'THIRD_PARTY', provider: 'knowlarity' }];
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
validateCombination(service: string, provider: string): boolean {
|
|
29
29
|
return this.getSupportedCombinations().some(
|
|
30
|
-
combo =>
|
|
31
|
-
|
|
30
|
+
(combo) =>
|
|
31
|
+
combo.service.toLowerCase() === service.toLowerCase() &&
|
|
32
|
+
combo.provider.toLowerCase() === provider.toLowerCase(),
|
|
32
33
|
);
|
|
33
34
|
}
|
|
34
35
|
}
|
|
@@ -9,26 +9,27 @@ export class WhatsAppFactory implements BaseFactory {
|
|
|
9
9
|
|
|
10
10
|
createProvider(service: string, provider: string): CommunicationStrategy {
|
|
11
11
|
const key = `${service.toLowerCase()}_${provider.toLowerCase()}`;
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
switch (key) {
|
|
14
14
|
case 'api_whatsapp':
|
|
15
15
|
return this.whatsappStrategy;
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
default:
|
|
18
|
-
throw new Error(
|
|
18
|
+
throw new Error(
|
|
19
|
+
`Unsupported WhatsApp service/provider: ${service}/${provider}`,
|
|
20
|
+
);
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
getSupportedCombinations(): Array<{ service: string; provider: string }> {
|
|
23
|
-
return [
|
|
24
|
-
{ service: 'API', provider: 'whatsapp' },
|
|
25
|
-
];
|
|
25
|
+
return [{ service: 'API', provider: 'whatsapp' }];
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
validateCombination(service: string, provider: string): boolean {
|
|
29
29
|
return this.getSupportedCombinations().some(
|
|
30
|
-
combo =>
|
|
31
|
-
|
|
30
|
+
(combo) =>
|
|
31
|
+
combo.service.toLowerCase() === service.toLowerCase() &&
|
|
32
|
+
combo.provider.toLowerCase() === provider.toLowerCase(),
|
|
32
33
|
);
|
|
33
34
|
}
|
|
34
35
|
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { Injectable, Logger } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
export interface QueuedMessage {
|
|
4
|
+
id: string;
|
|
5
|
+
levelId: number;
|
|
6
|
+
levelType: string;
|
|
7
|
+
recipient: string;
|
|
8
|
+
message: string;
|
|
9
|
+
type?: 'EMAIL' | 'SMS' | 'WA' | 'TELEPHONE';
|
|
10
|
+
priority: 'high' | 'medium' | 'low';
|
|
11
|
+
scheduledFor?: Date;
|
|
12
|
+
metadata?: any;
|
|
13
|
+
createdAt: Date;
|
|
14
|
+
retryCount: number;
|
|
15
|
+
maxRetries: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Injectable()
|
|
19
|
+
export class CommunicationQueueService {
|
|
20
|
+
private readonly logger = new Logger(CommunicationQueueService.name);
|
|
21
|
+
private queue: QueuedMessage[] = [];
|
|
22
|
+
private processing = false;
|
|
23
|
+
|
|
24
|
+
constructor() {
|
|
25
|
+
// Start processing queue every 5 seconds
|
|
26
|
+
setInterval(() => this.processQueue(), 5000);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async queueMessage(
|
|
30
|
+
levelId: number,
|
|
31
|
+
levelType: string,
|
|
32
|
+
recipient: string,
|
|
33
|
+
message: string,
|
|
34
|
+
type?: 'EMAIL' | 'SMS' | 'WA' | 'TELEPHONE',
|
|
35
|
+
priority: 'high' | 'medium' | 'low' = 'medium',
|
|
36
|
+
scheduledFor?: Date,
|
|
37
|
+
metadata?: any,
|
|
38
|
+
): Promise<string> {
|
|
39
|
+
const messageId = this.generateMessageId();
|
|
40
|
+
|
|
41
|
+
const queuedMessage: QueuedMessage = {
|
|
42
|
+
id: messageId,
|
|
43
|
+
levelId,
|
|
44
|
+
levelType,
|
|
45
|
+
recipient,
|
|
46
|
+
message,
|
|
47
|
+
type,
|
|
48
|
+
priority,
|
|
49
|
+
scheduledFor,
|
|
50
|
+
metadata,
|
|
51
|
+
createdAt: new Date(),
|
|
52
|
+
retryCount: 0,
|
|
53
|
+
maxRetries: 3,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
this.queue.push(queuedMessage);
|
|
57
|
+
this.sortQueue();
|
|
58
|
+
|
|
59
|
+
this.logger.log(`Message queued: ${messageId} for ${recipient} with priority ${priority}`);
|
|
60
|
+
return messageId;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async queueBulkMessages(
|
|
64
|
+
levelId: number,
|
|
65
|
+
levelType: string,
|
|
66
|
+
recipients: string[],
|
|
67
|
+
message: string,
|
|
68
|
+
type?: 'EMAIL' | 'SMS' | 'WA' | 'TELEPHONE',
|
|
69
|
+
priority: 'high' | 'medium' | 'low' = 'low',
|
|
70
|
+
metadata?: any,
|
|
71
|
+
): Promise<string[]> {
|
|
72
|
+
const messageIds: string[] = [];
|
|
73
|
+
|
|
74
|
+
for (const recipient of recipients) {
|
|
75
|
+
const messageId = await this.queueMessage(
|
|
76
|
+
levelId,
|
|
77
|
+
levelType,
|
|
78
|
+
recipient,
|
|
79
|
+
message,
|
|
80
|
+
type,
|
|
81
|
+
priority,
|
|
82
|
+
undefined,
|
|
83
|
+
metadata,
|
|
84
|
+
);
|
|
85
|
+
messageIds.push(messageId);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return messageIds;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
getQueueStats() {
|
|
92
|
+
const total = this.queue.length;
|
|
93
|
+
const pending = this.queue.filter(m => !m.scheduledFor || m.scheduledFor <= new Date()).length;
|
|
94
|
+
const scheduled = this.queue.filter(m => m.scheduledFor && m.scheduledFor > new Date()).length;
|
|
95
|
+
|
|
96
|
+
const byPriority = {
|
|
97
|
+
high: this.queue.filter(m => m.priority === 'high').length,
|
|
98
|
+
medium: this.queue.filter(m => m.priority === 'medium').length,
|
|
99
|
+
low: this.queue.filter(m => m.priority === 'low').length,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
total,
|
|
104
|
+
pending,
|
|
105
|
+
scheduled,
|
|
106
|
+
byPriority,
|
|
107
|
+
processing: this.processing,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private async processQueue(): Promise<void> {
|
|
112
|
+
if (this.processing || this.queue.length === 0) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
this.processing = true;
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
const now = new Date();
|
|
120
|
+
|
|
121
|
+
// Get messages ready to send (not scheduled or scheduled time has passed)
|
|
122
|
+
const readyMessages = this.queue.filter(
|
|
123
|
+
message => !message.scheduledFor || message.scheduledFor <= now
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
if (readyMessages.length === 0) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Sort by priority (high -> medium -> low)
|
|
131
|
+
const prioritySorted = readyMessages.sort((a, b) => {
|
|
132
|
+
const priorityOrder = { high: 3, medium: 2, low: 1 };
|
|
133
|
+
return priorityOrder[b.priority] - priorityOrder[a.priority];
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Process up to 5 messages at once
|
|
137
|
+
const messagesToProcess = prioritySorted.slice(0, 5);
|
|
138
|
+
|
|
139
|
+
for (const message of messagesToProcess) {
|
|
140
|
+
try {
|
|
141
|
+
// Remove message from queue
|
|
142
|
+
this.queue = this.queue.filter(m => m.id !== message.id);
|
|
143
|
+
|
|
144
|
+
this.logger.log(`Processing queued message ${message.id} for ${message.recipient}`);
|
|
145
|
+
|
|
146
|
+
// Note: In a real implementation, you would call the communication service here
|
|
147
|
+
// For now, we just simulate successful processing
|
|
148
|
+
|
|
149
|
+
} catch (error) {
|
|
150
|
+
this.logger.error(`Failed to process message ${message.id}:`, error.message);
|
|
151
|
+
|
|
152
|
+
// Retry logic
|
|
153
|
+
if (message.retryCount < message.maxRetries) {
|
|
154
|
+
message.retryCount++;
|
|
155
|
+
message.scheduledFor = new Date(Date.now() + (message.retryCount * 60000)); // Retry after 1, 2, 3 minutes
|
|
156
|
+
this.queue.push(message);
|
|
157
|
+
this.logger.warn(`Message ${message.id} will be retried (attempt ${message.retryCount}/${message.maxRetries})`);
|
|
158
|
+
} else {
|
|
159
|
+
this.logger.error(`Message ${message.id} failed permanently after ${message.maxRetries} attempts`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
} catch (error) {
|
|
165
|
+
this.logger.error('Error processing queue:', error.message);
|
|
166
|
+
} finally {
|
|
167
|
+
this.processing = false;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private sortQueue(): void {
|
|
172
|
+
this.queue.sort((a, b) => {
|
|
173
|
+
// Sort by priority first
|
|
174
|
+
const priorityOrder = { high: 3, medium: 2, low: 1 };
|
|
175
|
+
if (priorityOrder[a.priority] !== priorityOrder[b.priority]) {
|
|
176
|
+
return priorityOrder[b.priority] - priorityOrder[a.priority];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Then by creation time (oldest first)
|
|
180
|
+
return a.createdAt.getTime() - b.createdAt.getTime();
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private generateMessageId(): string {
|
|
185
|
+
return `msg_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Helper methods for integration
|
|
189
|
+
isQueueEmpty(): boolean {
|
|
190
|
+
return this.queue.length === 0;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
getQueueLength(): number {
|
|
194
|
+
return this.queue.length;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
clearQueue(): void {
|
|
198
|
+
this.queue = [];
|
|
199
|
+
this.logger.log('Queue cleared');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Cancel a specific message
|
|
203
|
+
cancelMessage(messageId: string): boolean {
|
|
204
|
+
const initialLength = this.queue.length;
|
|
205
|
+
this.queue = this.queue.filter(m => m.id !== messageId);
|
|
206
|
+
const canceled = this.queue.length < initialLength;
|
|
207
|
+
|
|
208
|
+
if (canceled) {
|
|
209
|
+
this.logger.log(`Message ${messageId} canceled`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return canceled;
|
|
213
|
+
}
|
|
214
|
+
}
|