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,17 +7,18 @@ export class OAuthService {
|
|
|
7
7
|
private readonly gmailOAuth2Client = new google.auth.OAuth2(
|
|
8
8
|
process.env.GMAIL_CLIENT_ID,
|
|
9
9
|
process.env.GMAIL_CLIENT_SECRET,
|
|
10
|
-
process.env.GMAIL_REDIRECT_URI ||
|
|
10
|
+
process.env.GMAIL_REDIRECT_URI ||
|
|
11
|
+
'http://localhost:3000/api/communication/oauth/callback/gmail',
|
|
11
12
|
);
|
|
12
13
|
|
|
13
14
|
private readonly outlookScopes = [
|
|
14
15
|
'https://graph.microsoft.com/mail.send',
|
|
15
|
-
'https://graph.microsoft.com/user.read'
|
|
16
|
+
'https://graph.microsoft.com/user.read',
|
|
16
17
|
];
|
|
17
18
|
|
|
18
19
|
private readonly gmailScopes = [
|
|
19
20
|
'https://www.googleapis.com/auth/gmail.send',
|
|
20
|
-
'https://www.googleapis.com/auth/gmail.readonly'
|
|
21
|
+
'https://www.googleapis.com/auth/gmail.readonly',
|
|
21
22
|
];
|
|
22
23
|
|
|
23
24
|
generateGmailAuthUrl(state: string): string {
|
|
@@ -25,47 +26,54 @@ export class OAuthService {
|
|
|
25
26
|
access_type: 'offline',
|
|
26
27
|
scope: this.gmailScopes,
|
|
27
28
|
state: state,
|
|
28
|
-
prompt: 'consent'
|
|
29
|
+
prompt: 'consent',
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
generateOutlookAuthUrl(state: string): string {
|
|
33
34
|
const clientId = process.env.OUTLOOK_CLIENT_ID;
|
|
34
|
-
const redirectUri = encodeURIComponent(
|
|
35
|
+
const redirectUri = encodeURIComponent(
|
|
36
|
+
process.env.OUTLOOK_REDIRECT_URI ||
|
|
37
|
+
'http://localhost:3000/api/communication/oauth/callback/outlook',
|
|
38
|
+
);
|
|
35
39
|
const scope = encodeURIComponent(this.outlookScopes.join(' '));
|
|
36
|
-
|
|
37
|
-
return
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
`https://login.microsoftonline.com/common/oauth2/v2.0/authorize?` +
|
|
43
|
+
`client_id=${clientId}&` +
|
|
44
|
+
`response_type=code&` +
|
|
45
|
+
`redirect_uri=${redirectUri}&` +
|
|
46
|
+
`scope=${scope}&` +
|
|
47
|
+
`response_mode=query&` +
|
|
48
|
+
`state=${state}`
|
|
49
|
+
);
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
async exchangeGmailCode(code: string): Promise<any> {
|
|
47
53
|
try {
|
|
48
54
|
const { tokens } = await this.gmailOAuth2Client.getToken(code);
|
|
49
|
-
|
|
55
|
+
|
|
50
56
|
this.gmailOAuth2Client.setCredentials(tokens);
|
|
51
|
-
|
|
57
|
+
|
|
52
58
|
// Get user info
|
|
53
59
|
const oauth2 = google.oauth2({
|
|
54
60
|
auth: this.gmailOAuth2Client,
|
|
55
|
-
version: 'v2'
|
|
61
|
+
version: 'v2',
|
|
56
62
|
});
|
|
57
63
|
const userInfo = await oauth2.userinfo.get();
|
|
58
|
-
|
|
64
|
+
|
|
59
65
|
return {
|
|
60
66
|
accessToken: tokens.access_token,
|
|
61
67
|
refreshToken: tokens.refresh_token,
|
|
62
68
|
expiresIn: tokens.expiry_date,
|
|
63
69
|
email: userInfo.data.email,
|
|
64
70
|
tokenType: tokens.token_type,
|
|
65
|
-
scope: tokens.scope
|
|
71
|
+
scope: tokens.scope,
|
|
66
72
|
};
|
|
67
73
|
} catch (error) {
|
|
68
|
-
throw new BadRequestException(
|
|
74
|
+
throw new BadRequestException(
|
|
75
|
+
'Failed to exchange Gmail authorization code',
|
|
76
|
+
);
|
|
69
77
|
}
|
|
70
78
|
}
|
|
71
79
|
|
|
@@ -73,10 +81,13 @@ export class OAuthService {
|
|
|
73
81
|
try {
|
|
74
82
|
const clientId = process.env.OUTLOOK_CLIENT_ID;
|
|
75
83
|
const clientSecret = process.env.OUTLOOK_CLIENT_SECRET;
|
|
76
|
-
const redirectUri =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
84
|
+
const redirectUri =
|
|
85
|
+
process.env.OUTLOOK_REDIRECT_URI ||
|
|
86
|
+
'http://localhost:3000/api/communication/oauth/callback/outlook';
|
|
87
|
+
|
|
88
|
+
const tokenUrl =
|
|
89
|
+
'https://login.microsoftonline.com/common/oauth2/v2.0/token';
|
|
90
|
+
|
|
80
91
|
const response = await fetch(tokenUrl, {
|
|
81
92
|
method: 'POST',
|
|
82
93
|
headers: {
|
|
@@ -88,12 +99,12 @@ export class OAuthService {
|
|
|
88
99
|
code: code,
|
|
89
100
|
redirect_uri: redirectUri,
|
|
90
101
|
grant_type: 'authorization_code',
|
|
91
|
-
scope: this.outlookScopes.join(' ')
|
|
92
|
-
})
|
|
102
|
+
scope: this.outlookScopes.join(' '),
|
|
103
|
+
}),
|
|
93
104
|
});
|
|
94
105
|
|
|
95
106
|
const tokenData = await response.json();
|
|
96
|
-
|
|
107
|
+
|
|
97
108
|
if (!response.ok) {
|
|
98
109
|
throw new Error(tokenData.error_description || 'Token exchange failed');
|
|
99
110
|
}
|
|
@@ -106,33 +117,35 @@ export class OAuthService {
|
|
|
106
117
|
});
|
|
107
118
|
|
|
108
119
|
const userInfo = await graphClient.api('/me').get();
|
|
109
|
-
|
|
120
|
+
|
|
110
121
|
return {
|
|
111
122
|
accessToken: tokenData.access_token,
|
|
112
123
|
refreshToken: tokenData.refresh_token,
|
|
113
124
|
expiresIn: tokenData.expires_in,
|
|
114
125
|
email: userInfo.mail || userInfo.userPrincipalName,
|
|
115
126
|
tokenType: tokenData.token_type,
|
|
116
|
-
scope: tokenData.scope
|
|
127
|
+
scope: tokenData.scope,
|
|
117
128
|
};
|
|
118
129
|
} catch (error) {
|
|
119
|
-
throw new BadRequestException(
|
|
130
|
+
throw new BadRequestException(
|
|
131
|
+
'Failed to exchange Outlook authorization code',
|
|
132
|
+
);
|
|
120
133
|
}
|
|
121
134
|
}
|
|
122
135
|
|
|
123
136
|
async refreshGmailToken(refreshToken: string): Promise<any> {
|
|
124
137
|
try {
|
|
125
138
|
this.gmailOAuth2Client.setCredentials({
|
|
126
|
-
refresh_token: refreshToken
|
|
139
|
+
refresh_token: refreshToken,
|
|
127
140
|
});
|
|
128
141
|
|
|
129
142
|
const { credentials } = await this.gmailOAuth2Client.refreshAccessToken();
|
|
130
|
-
|
|
143
|
+
|
|
131
144
|
return {
|
|
132
145
|
accessToken: credentials.access_token,
|
|
133
146
|
refreshToken: credentials.refresh_token || refreshToken,
|
|
134
147
|
expiresIn: credentials.expiry_date,
|
|
135
|
-
tokenType: credentials.token_type
|
|
148
|
+
tokenType: credentials.token_type,
|
|
136
149
|
};
|
|
137
150
|
} catch (error) {
|
|
138
151
|
throw new BadRequestException('Failed to refresh Gmail token');
|
|
@@ -143,9 +156,10 @@ export class OAuthService {
|
|
|
143
156
|
try {
|
|
144
157
|
const clientId = process.env.OUTLOOK_CLIENT_ID;
|
|
145
158
|
const clientSecret = process.env.OUTLOOK_CLIENT_SECRET;
|
|
146
|
-
|
|
147
|
-
const tokenUrl =
|
|
148
|
-
|
|
159
|
+
|
|
160
|
+
const tokenUrl =
|
|
161
|
+
'https://login.microsoftonline.com/common/oauth2/v2.0/token';
|
|
162
|
+
|
|
149
163
|
const response = await fetch(tokenUrl, {
|
|
150
164
|
method: 'POST',
|
|
151
165
|
headers: {
|
|
@@ -156,21 +170,21 @@ export class OAuthService {
|
|
|
156
170
|
client_secret: clientSecret!,
|
|
157
171
|
refresh_token: refreshToken,
|
|
158
172
|
grant_type: 'refresh_token',
|
|
159
|
-
scope: this.outlookScopes.join(' ')
|
|
160
|
-
})
|
|
173
|
+
scope: this.outlookScopes.join(' '),
|
|
174
|
+
}),
|
|
161
175
|
});
|
|
162
176
|
|
|
163
177
|
const tokenData = await response.json();
|
|
164
|
-
|
|
178
|
+
|
|
165
179
|
if (!response.ok) {
|
|
166
180
|
throw new Error(tokenData.error_description || 'Token refresh failed');
|
|
167
181
|
}
|
|
168
|
-
|
|
182
|
+
|
|
169
183
|
return {
|
|
170
184
|
accessToken: tokenData.access_token,
|
|
171
185
|
refreshToken: tokenData.refresh_token || refreshToken,
|
|
172
186
|
expiresIn: tokenData.expires_in,
|
|
173
|
-
tokenType: tokenData.token_type
|
|
187
|
+
tokenType: tokenData.token_type,
|
|
174
188
|
};
|
|
175
189
|
} catch (error) {
|
|
176
190
|
throw new BadRequestException('Failed to refresh Outlook token');
|
|
@@ -184,20 +198,27 @@ export class OAuthService {
|
|
|
184
198
|
return `${prefix}:${timestamp}:${random}:${Buffer.from(data).toString('base64')}`;
|
|
185
199
|
}
|
|
186
200
|
|
|
187
|
-
parseState(state: string): {
|
|
201
|
+
parseState(state: string): {
|
|
202
|
+
prefix: string;
|
|
203
|
+
timestamp: number;
|
|
204
|
+
random: string;
|
|
205
|
+
data: any;
|
|
206
|
+
} {
|
|
188
207
|
const parts = state.split(':');
|
|
189
208
|
if (parts.length !== 4) {
|
|
190
209
|
throw new BadRequestException('Invalid state parameter');
|
|
191
210
|
}
|
|
192
|
-
|
|
211
|
+
|
|
193
212
|
const [prefix, timestamp, random, encodedData] = parts;
|
|
194
|
-
const data = encodedData
|
|
195
|
-
|
|
213
|
+
const data = encodedData
|
|
214
|
+
? JSON.parse(Buffer.from(encodedData, 'base64').toString())
|
|
215
|
+
: null;
|
|
216
|
+
|
|
196
217
|
return {
|
|
197
218
|
prefix,
|
|
198
219
|
timestamp: parseInt(timestamp),
|
|
199
220
|
random,
|
|
200
|
-
data
|
|
221
|
+
data,
|
|
201
222
|
};
|
|
202
223
|
}
|
|
203
|
-
}
|
|
224
|
+
}
|
|
@@ -23,8 +23,16 @@ export class GmailApiStrategy implements CommunicationStrategy {
|
|
|
23
23
|
console.log('accessToken:', accessToken ? 'Present' : 'Missing');
|
|
24
24
|
|
|
25
25
|
const toRecipients = Array.isArray(to) ? to.join(', ') : to;
|
|
26
|
-
const ccRecipients = cc
|
|
27
|
-
|
|
26
|
+
const ccRecipients = cc
|
|
27
|
+
? Array.isArray(cc)
|
|
28
|
+
? cc.join(', ')
|
|
29
|
+
: cc
|
|
30
|
+
: undefined;
|
|
31
|
+
const bccRecipients = bcc
|
|
32
|
+
? Array.isArray(bcc)
|
|
33
|
+
? bcc.join(', ')
|
|
34
|
+
: bcc
|
|
35
|
+
: undefined;
|
|
28
36
|
|
|
29
37
|
const emailLines = [
|
|
30
38
|
`To: ${toRecipients}`,
|
|
@@ -63,11 +71,11 @@ export class GmailApiStrategy implements CommunicationStrategy {
|
|
|
63
71
|
},
|
|
64
72
|
{
|
|
65
73
|
headers: {
|
|
66
|
-
|
|
74
|
+
Authorization: `Bearer ${accessToken}`,
|
|
67
75
|
'Content-Type': 'application/json',
|
|
68
76
|
},
|
|
69
77
|
timeout: 30000, // 30 second timeout
|
|
70
|
-
}
|
|
78
|
+
},
|
|
71
79
|
);
|
|
72
80
|
|
|
73
81
|
console.log('---- Gmail HTTP API Success ----');
|
|
@@ -91,7 +99,10 @@ export class GmailApiStrategy implements CommunicationStrategy {
|
|
|
91
99
|
success: false,
|
|
92
100
|
provider: 'gmail',
|
|
93
101
|
service: 'API',
|
|
94
|
-
error:
|
|
102
|
+
error:
|
|
103
|
+
error.response?.data?.error?.message ||
|
|
104
|
+
error.message ||
|
|
105
|
+
'Gmail API error',
|
|
95
106
|
timestamp: new Date(),
|
|
96
107
|
};
|
|
97
108
|
}
|
|
@@ -101,35 +112,41 @@ export class GmailApiStrategy implements CommunicationStrategy {
|
|
|
101
112
|
if (!config) return false;
|
|
102
113
|
|
|
103
114
|
// For HTTP API, we just need accessToken
|
|
104
|
-
return
|
|
105
|
-
config.accessToken &&
|
|
106
|
-
typeof config.accessToken === 'string'
|
|
107
|
-
);
|
|
115
|
+
return config.accessToken && typeof config.accessToken === 'string';
|
|
108
116
|
}
|
|
109
117
|
|
|
110
118
|
async refreshAccessToken(config: any): Promise<string> {
|
|
111
119
|
try {
|
|
112
120
|
const { clientId, clientSecret, refreshToken } = config;
|
|
113
|
-
|
|
121
|
+
|
|
114
122
|
if (!clientId || !clientSecret || !refreshToken) {
|
|
115
123
|
throw new Error('Missing OAuth credentials for token refresh');
|
|
116
124
|
}
|
|
117
125
|
|
|
118
|
-
const response = await axios.post(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
+
const response = await axios.post(
|
|
127
|
+
'https://oauth2.googleapis.com/token',
|
|
128
|
+
{
|
|
129
|
+
client_id: clientId,
|
|
130
|
+
client_secret: clientSecret,
|
|
131
|
+
refresh_token: refreshToken,
|
|
132
|
+
grant_type: 'refresh_token',
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
headers: {
|
|
136
|
+
'Content-Type': 'application/json',
|
|
137
|
+
},
|
|
126
138
|
},
|
|
127
|
-
|
|
139
|
+
);
|
|
128
140
|
|
|
129
141
|
return response.data.access_token || '';
|
|
130
142
|
} catch (error) {
|
|
131
|
-
console.error(
|
|
132
|
-
|
|
143
|
+
console.error(
|
|
144
|
+
'Failed to refresh access token:',
|
|
145
|
+
error.response?.data || error.message,
|
|
146
|
+
);
|
|
147
|
+
throw new Error(
|
|
148
|
+
`Failed to refresh Gmail access token: ${error.response?.data?.error_description || error.message}`,
|
|
149
|
+
);
|
|
133
150
|
}
|
|
134
151
|
}
|
|
135
152
|
|
|
@@ -146,15 +163,18 @@ export class GmailApiStrategy implements CommunicationStrategy {
|
|
|
146
163
|
'https://gmail.googleapis.com/gmail/v1/users/me/profile',
|
|
147
164
|
{
|
|
148
165
|
headers: {
|
|
149
|
-
|
|
166
|
+
Authorization: `Bearer ${accessToken}`,
|
|
150
167
|
},
|
|
151
168
|
timeout: 10000, // 10 second timeout for validation
|
|
152
|
-
}
|
|
169
|
+
},
|
|
153
170
|
);
|
|
154
171
|
|
|
155
172
|
return response.status === 200 && response.data.emailAddress;
|
|
156
173
|
} catch (error) {
|
|
157
|
-
console.error(
|
|
174
|
+
console.error(
|
|
175
|
+
'Gmail connection validation failed:',
|
|
176
|
+
error.response?.data || error.message,
|
|
177
|
+
);
|
|
158
178
|
return false;
|
|
159
179
|
}
|
|
160
180
|
}
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
2
|
import * as nodemailer from 'nodemailer';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
CommunicationStrategy,
|
|
5
|
+
CommunicationResult,
|
|
6
|
+
} from './communication.strategy';
|
|
4
7
|
|
|
5
8
|
@Injectable()
|
|
6
9
|
export class GmailSMTPStrategy implements CommunicationStrategy {
|
|
7
|
-
async sendMessage(
|
|
10
|
+
async sendMessage(
|
|
11
|
+
to: string,
|
|
12
|
+
message: string,
|
|
13
|
+
config: any,
|
|
14
|
+
): Promise<CommunicationResult> {
|
|
8
15
|
try {
|
|
9
|
-
const {
|
|
10
|
-
email,
|
|
11
|
-
password,
|
|
16
|
+
const {
|
|
17
|
+
email,
|
|
18
|
+
password,
|
|
12
19
|
subject = 'Notification',
|
|
13
20
|
html,
|
|
14
21
|
attachments,
|
|
15
22
|
cc,
|
|
16
|
-
bcc
|
|
23
|
+
bcc,
|
|
17
24
|
} = config;
|
|
18
25
|
|
|
19
26
|
const transporter = nodemailer.createTransport({
|
|
@@ -56,9 +63,6 @@ export class GmailSMTPStrategy implements CommunicationStrategy {
|
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
validateConfig(config: any): boolean {
|
|
59
|
-
return !!(
|
|
60
|
-
config.email &&
|
|
61
|
-
config.password
|
|
62
|
-
);
|
|
66
|
+
return !!(config.email && config.password);
|
|
63
67
|
}
|
|
64
|
-
}
|
|
68
|
+
}
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
2
|
import { google } from 'googleapis';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
CommunicationStrategy,
|
|
5
|
+
CommunicationResult,
|
|
6
|
+
} from './communication.strategy';
|
|
4
7
|
|
|
5
8
|
@Injectable()
|
|
6
9
|
export class GmailStrategy implements CommunicationStrategy {
|
|
7
|
-
async sendMessage(
|
|
10
|
+
async sendMessage(
|
|
11
|
+
to: string,
|
|
12
|
+
message: string,
|
|
13
|
+
config: any,
|
|
14
|
+
): Promise<CommunicationResult> {
|
|
8
15
|
try {
|
|
9
|
-
const { clientId, clientSecret, refreshToken, accessToken, email } =
|
|
10
|
-
|
|
16
|
+
const { clientId, clientSecret, refreshToken, accessToken, email } =
|
|
17
|
+
config;
|
|
18
|
+
|
|
11
19
|
const oauth2Client = new google.auth.OAuth2(clientId, clientSecret);
|
|
12
20
|
oauth2Client.setCredentials({
|
|
13
21
|
refresh_token: refreshToken,
|
|
@@ -15,7 +23,7 @@ export class GmailStrategy implements CommunicationStrategy {
|
|
|
15
23
|
});
|
|
16
24
|
|
|
17
25
|
const gmail = google.gmail({ version: 'v1', auth: oauth2Client });
|
|
18
|
-
|
|
26
|
+
|
|
19
27
|
const subject = config.subject || 'Notification';
|
|
20
28
|
const emailContent = [
|
|
21
29
|
`From: ${email}`,
|
|
@@ -31,7 +39,7 @@ export class GmailStrategy implements CommunicationStrategy {
|
|
|
31
39
|
.replace(/\+/g, '-')
|
|
32
40
|
.replace(/\//g, '_')
|
|
33
41
|
.replace(/=+$/, '');
|
|
34
|
-
|
|
42
|
+
|
|
35
43
|
const result = await gmail.users.messages.send({
|
|
36
44
|
userId: 'me',
|
|
37
45
|
requestBody: {
|
|
@@ -65,4 +73,4 @@ export class GmailStrategy implements CommunicationStrategy {
|
|
|
65
73
|
config.email
|
|
66
74
|
);
|
|
67
75
|
}
|
|
68
|
-
}
|
|
76
|
+
}
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
2
|
import axios from 'axios';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
CommunicationStrategy,
|
|
5
|
+
CommunicationResult,
|
|
6
|
+
} from './communication.strategy';
|
|
4
7
|
|
|
5
8
|
@Injectable()
|
|
6
9
|
export class KnowlarityStrategy implements CommunicationStrategy {
|
|
7
|
-
async sendMessage(
|
|
10
|
+
async sendMessage(
|
|
11
|
+
to: string,
|
|
12
|
+
message: string,
|
|
13
|
+
config: any,
|
|
14
|
+
): Promise<CommunicationResult> {
|
|
8
15
|
try {
|
|
9
|
-
const {
|
|
16
|
+
const {
|
|
10
17
|
apiKey,
|
|
11
|
-
apiSecret,
|
|
18
|
+
apiSecret,
|
|
12
19
|
callerNumber,
|
|
13
20
|
baseUrl = 'https://kpi.knowlarity.com/Basic',
|
|
14
21
|
callType = 'voice',
|
|
15
|
-
language = 'en'
|
|
22
|
+
language = 'en',
|
|
16
23
|
} = config;
|
|
17
24
|
|
|
18
25
|
if (callType === 'voice') {
|
|
@@ -24,19 +31,28 @@ export class KnowlarityStrategy implements CommunicationStrategy {
|
|
|
24
31
|
language: language,
|
|
25
32
|
api_key: apiKey,
|
|
26
33
|
api_secret: apiSecret,
|
|
27
|
-
format: 'json'
|
|
34
|
+
format: 'json',
|
|
28
35
|
};
|
|
29
36
|
|
|
30
|
-
const response = await axios.post(
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
const response = await axios.post(
|
|
38
|
+
`${baseUrl}/start_call.php`,
|
|
39
|
+
callData,
|
|
40
|
+
{
|
|
41
|
+
headers: {
|
|
42
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
43
|
+
},
|
|
44
|
+
transformRequest: [
|
|
45
|
+
(data) => {
|
|
46
|
+
return Object.keys(data)
|
|
47
|
+
.map(
|
|
48
|
+
(key) =>
|
|
49
|
+
`${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`,
|
|
50
|
+
)
|
|
51
|
+
.join('&');
|
|
52
|
+
},
|
|
53
|
+
],
|
|
33
54
|
},
|
|
34
|
-
|
|
35
|
-
return Object.keys(data)
|
|
36
|
-
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`)
|
|
37
|
-
.join('&');
|
|
38
|
-
}]
|
|
39
|
-
});
|
|
55
|
+
);
|
|
40
56
|
|
|
41
57
|
return {
|
|
42
58
|
success: response.data.status === 'success',
|
|
@@ -54,18 +70,23 @@ export class KnowlarityStrategy implements CommunicationStrategy {
|
|
|
54
70
|
sms_text: message,
|
|
55
71
|
api_key: apiKey,
|
|
56
72
|
api_secret: apiSecret,
|
|
57
|
-
format: 'json'
|
|
73
|
+
format: 'json',
|
|
58
74
|
};
|
|
59
75
|
|
|
60
76
|
const response = await axios.post(`${baseUrl}/send_sms.php`, smsData, {
|
|
61
77
|
headers: {
|
|
62
78
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
63
79
|
},
|
|
64
|
-
transformRequest: [
|
|
65
|
-
|
|
66
|
-
.
|
|
67
|
-
|
|
68
|
-
|
|
80
|
+
transformRequest: [
|
|
81
|
+
(data) => {
|
|
82
|
+
return Object.keys(data)
|
|
83
|
+
.map(
|
|
84
|
+
(key) =>
|
|
85
|
+
`${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`,
|
|
86
|
+
)
|
|
87
|
+
.join('&');
|
|
88
|
+
},
|
|
89
|
+
],
|
|
69
90
|
});
|
|
70
91
|
|
|
71
92
|
return {
|
|
@@ -99,26 +120,39 @@ export class KnowlarityStrategy implements CommunicationStrategy {
|
|
|
99
120
|
}
|
|
100
121
|
|
|
101
122
|
async getCallStatus(callId: string, config: any): Promise<any> {
|
|
102
|
-
const {
|
|
123
|
+
const {
|
|
124
|
+
apiKey,
|
|
125
|
+
apiSecret,
|
|
126
|
+
baseUrl = 'https://kpi.knowlarity.com/Basic',
|
|
127
|
+
} = config;
|
|
103
128
|
|
|
104
129
|
const statusData = {
|
|
105
130
|
call_id: callId,
|
|
106
131
|
api_key: apiKey,
|
|
107
132
|
api_secret: apiSecret,
|
|
108
|
-
format: 'json'
|
|
133
|
+
format: 'json',
|
|
109
134
|
};
|
|
110
135
|
|
|
111
|
-
const response = await axios.post(
|
|
112
|
-
|
|
113
|
-
|
|
136
|
+
const response = await axios.post(
|
|
137
|
+
`${baseUrl}/call_details.php`,
|
|
138
|
+
statusData,
|
|
139
|
+
{
|
|
140
|
+
headers: {
|
|
141
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
142
|
+
},
|
|
143
|
+
transformRequest: [
|
|
144
|
+
(data) => {
|
|
145
|
+
return Object.keys(data)
|
|
146
|
+
.map(
|
|
147
|
+
(key) =>
|
|
148
|
+
`${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`,
|
|
149
|
+
)
|
|
150
|
+
.join('&');
|
|
151
|
+
},
|
|
152
|
+
],
|
|
114
153
|
},
|
|
115
|
-
|
|
116
|
-
return Object.keys(data)
|
|
117
|
-
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`)
|
|
118
|
-
.join('&');
|
|
119
|
-
}]
|
|
120
|
-
});
|
|
154
|
+
);
|
|
121
155
|
|
|
122
156
|
return response.data;
|
|
123
157
|
}
|
|
124
|
-
}
|
|
158
|
+
}
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
2
|
import * as nodemailer from 'nodemailer';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
CommunicationStrategy,
|
|
5
|
+
CommunicationResult,
|
|
6
|
+
} from './communication.strategy';
|
|
4
7
|
|
|
5
8
|
@Injectable()
|
|
6
9
|
export class OutlookSMTPStrategy implements CommunicationStrategy {
|
|
7
|
-
async sendMessage(
|
|
10
|
+
async sendMessage(
|
|
11
|
+
to: string,
|
|
12
|
+
message: string,
|
|
13
|
+
config: any,
|
|
14
|
+
): Promise<CommunicationResult> {
|
|
8
15
|
try {
|
|
9
|
-
const {
|
|
10
|
-
email,
|
|
11
|
-
password,
|
|
16
|
+
const {
|
|
17
|
+
email,
|
|
18
|
+
password,
|
|
12
19
|
subject = 'Notification',
|
|
13
20
|
html,
|
|
14
21
|
attachments,
|
|
15
22
|
cc,
|
|
16
|
-
bcc
|
|
23
|
+
bcc,
|
|
17
24
|
} = config;
|
|
18
25
|
|
|
19
26
|
const transporter = nodemailer.createTransport({
|
|
@@ -61,9 +68,6 @@ export class OutlookSMTPStrategy implements CommunicationStrategy {
|
|
|
61
68
|
}
|
|
62
69
|
|
|
63
70
|
validateConfig(config: any): boolean {
|
|
64
|
-
return !!(
|
|
65
|
-
config.email &&
|
|
66
|
-
config.password
|
|
67
|
-
);
|
|
71
|
+
return !!(config.email && config.password);
|
|
68
72
|
}
|
|
69
|
-
}
|
|
73
|
+
}
|