@app-connect/core 1.7.1 → 1.7.3
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/README.md +1 -1
- package/connector/proxy/engine.js +163 -0
- package/connector/proxy/index.js +492 -0
- package/connector/registry.js +11 -8
- package/handlers/admin.js +12 -3
- package/handlers/auth.js +20 -10
- package/handlers/contact.js +26 -9
- package/handlers/disposition.js +19 -6
- package/handlers/log.js +62 -18
- package/index.js +48 -2
- package/lib/callLogComposer.js +196 -10
- package/lib/oauth.js +0 -1
- package/models/dynamo/connectorSchema.js +146 -0
- package/package.json +1 -1
- package/releaseNotes.json +40 -0
- package/test/connector/proxy/engine.test.js +93 -0
- package/test/connector/proxy/index.test.js +279 -0
- package/test/connector/proxy/sample.json +161 -0
- package/test/{adapter → connector}/registry.test.js +4 -4
- package/test/handlers/auth.test.js +3 -1
package/connector/registry.js
CHANGED
|
@@ -89,18 +89,21 @@ class ConnectorRegistry {
|
|
|
89
89
|
* @returns {Object} Composed connector with interface functions
|
|
90
90
|
*/
|
|
91
91
|
getConnector(platform) {
|
|
92
|
-
|
|
92
|
+
let connector = this.connectors.get(platform);
|
|
93
93
|
const platformInterfaceMap = this.platformInterfaces.get(platform);
|
|
94
|
-
|
|
95
|
-
// If no connector and no interfaces, throw error
|
|
94
|
+
|
|
96
95
|
if (!connector && (!platformInterfaceMap || platformInterfaceMap.size === 0)) {
|
|
97
|
-
|
|
96
|
+
connector = this.connectors.get('proxy');
|
|
97
|
+
if (connector) {
|
|
98
|
+
return connector;
|
|
99
|
+
}
|
|
100
|
+
throw new Error(`Connector not found for platform: ${platform}`);
|
|
98
101
|
}
|
|
99
102
|
|
|
100
103
|
// If no connector but interfaces exist, create a composed object with just interfaces
|
|
101
104
|
if (!connector && platformInterfaceMap && platformInterfaceMap.size > 0) {
|
|
102
105
|
const composedConnector = {};
|
|
103
|
-
|
|
106
|
+
|
|
104
107
|
// Add interface functions to the composed connector
|
|
105
108
|
for (const [interfaceName, interfaceFunction] of platformInterfaceMap) {
|
|
106
109
|
composedConnector[interfaceName] = interfaceFunction;
|
|
@@ -117,7 +120,7 @@ class ConnectorRegistry {
|
|
|
117
120
|
|
|
118
121
|
// If both connector and interfaces exist, create a composed object
|
|
119
122
|
const composedConnector = Object.create(connector);
|
|
120
|
-
|
|
123
|
+
|
|
121
124
|
// Add interface functions to the composed connector
|
|
122
125
|
for (const [interfaceName, interfaceFunction] of platformInterfaceMap) {
|
|
123
126
|
// Only add if the interface doesn't already exist in the connector
|
|
@@ -216,7 +219,7 @@ class ConnectorRegistry {
|
|
|
216
219
|
* @param {string} platform - Platform identifier
|
|
217
220
|
* @returns {Object} Connector capabilities
|
|
218
221
|
*/
|
|
219
|
-
getConnectorCapabilities(platform) {
|
|
222
|
+
async getConnectorCapabilities(platform) {
|
|
220
223
|
const originalConnector = this.getOriginalConnector(platform);
|
|
221
224
|
const composedConnector = this.getConnector(platform);
|
|
222
225
|
const platformInterfaceMap = this.getPlatformInterfaces(platform);
|
|
@@ -232,7 +235,7 @@ class ConnectorRegistry {
|
|
|
232
235
|
// Get auth type if available
|
|
233
236
|
if (typeof originalConnector.getAuthType === 'function') {
|
|
234
237
|
try {
|
|
235
|
-
capabilities.authType = originalConnector.getAuthType();
|
|
238
|
+
capabilities.authType = await originalConnector.getAuthType();
|
|
236
239
|
} catch (error) {
|
|
237
240
|
capabilities.authType = 'unknown';
|
|
238
241
|
}
|
package/handlers/admin.js
CHANGED
|
@@ -3,6 +3,7 @@ const { AdminConfigModel } = require('../models/adminConfigModel');
|
|
|
3
3
|
const connectorRegistry = require('../connector/registry');
|
|
4
4
|
const oauth = require('../lib/oauth');
|
|
5
5
|
const { RingCentral } = require('../lib/ringcentral');
|
|
6
|
+
const { Connector } = require('../models/dynamo/connectorSchema');
|
|
6
7
|
|
|
7
8
|
async function validateAdminRole({ rcAccessToken }) {
|
|
8
9
|
const rcExtensionResponse = await axios.get(
|
|
@@ -202,11 +203,19 @@ async function getUserMapping({ user, hashedRcAccountId, rcExtensionList }) {
|
|
|
202
203
|
const adminConfig = await getAdminSettings({ hashedRcAccountId });
|
|
203
204
|
const platformModule = connectorRegistry.getConnector(user.platform);
|
|
204
205
|
if (platformModule.getUserList) {
|
|
205
|
-
const
|
|
206
|
+
const proxyId = user.platformAdditionalInfo?.proxyId;
|
|
207
|
+
let proxyConfig = null;
|
|
208
|
+
if (proxyId) {
|
|
209
|
+
proxyConfig = await Connector.getProxyConfig(proxyId);
|
|
210
|
+
if (!proxyConfig?.operations?.getUserList) {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const authType = await platformModule.getAuthType({ proxyId, proxyConfig });
|
|
206
215
|
let authHeader = '';
|
|
207
216
|
switch (authType) {
|
|
208
217
|
case 'oauth':
|
|
209
|
-
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname })));
|
|
218
|
+
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname, proxyId, proxyConfig })));
|
|
210
219
|
// eslint-disable-next-line no-param-reassign
|
|
211
220
|
user = await oauth.checkAndRefreshAccessToken(oauthApp, user);
|
|
212
221
|
authHeader = `Bearer ${user.accessToken}`;
|
|
@@ -216,7 +225,7 @@ async function getUserMapping({ user, hashedRcAccountId, rcExtensionList }) {
|
|
|
216
225
|
authHeader = `Basic ${basicAuth}`;
|
|
217
226
|
break;
|
|
218
227
|
}
|
|
219
|
-
const crmUserList = await platformModule.getUserList({ user, authHeader });
|
|
228
|
+
const crmUserList = await platformModule.getUserList({ user, authHeader, proxyConfig });
|
|
220
229
|
const userMappingResult = [];
|
|
221
230
|
const newUserMappings = [];
|
|
222
231
|
for (const crmUser of crmUserList) {
|
package/handlers/auth.js
CHANGED
|
@@ -4,10 +4,15 @@ const connectorRegistry = require('../connector/registry');
|
|
|
4
4
|
const Op = require('sequelize').Op;
|
|
5
5
|
const { RingCentral } = require('../lib/ringcentral');
|
|
6
6
|
const adminCore = require('./admin');
|
|
7
|
+
const { Connector } = require('../models/dynamo/connectorSchema');
|
|
7
8
|
|
|
8
|
-
async function onOAuthCallback({ platform, hostname, tokenUrl, callbackUri, apiUrl, username, query }) {
|
|
9
|
+
async function onOAuthCallback({ platform, hostname, tokenUrl, callbackUri, apiUrl, username, query, proxyId }) {
|
|
9
10
|
const platformModule = connectorRegistry.getConnector(platform);
|
|
10
|
-
|
|
11
|
+
let proxyConfig = null;
|
|
12
|
+
if (proxyId) {
|
|
13
|
+
proxyConfig = await Connector.getProxyConfig(proxyId);
|
|
14
|
+
}
|
|
15
|
+
const oauthInfo = await platformModule.getOauthInfo({ tokenUrl, hostname, rcAccountId: query.rcAccountId, proxyId, proxyConfig });
|
|
11
16
|
|
|
12
17
|
if (oauthInfo.failMessage) {
|
|
13
18
|
return {
|
|
@@ -27,7 +32,8 @@ async function onOAuthCallback({ platform, hostname, tokenUrl, callbackUri, apiU
|
|
|
27
32
|
const oauthApp = oauth.getOAuthApp(oauthInfo);
|
|
28
33
|
const { accessToken, refreshToken, expires } = await oauthApp.code.getToken(callbackUri, overridingOAuthOption);
|
|
29
34
|
const authHeader = `Bearer ${accessToken}`;
|
|
30
|
-
const { successful, platformUserInfo, returnMessage } = await platformModule.getUserInfo({ authHeader, tokenUrl, apiUrl, hostname, username, callbackUri, query });
|
|
35
|
+
const { successful, platformUserInfo, returnMessage } = await platformModule.getUserInfo({ authHeader, tokenUrl, apiUrl, hostname, platform, username, callbackUri, query, proxyId, proxyConfig });
|
|
36
|
+
|
|
31
37
|
if (successful) {
|
|
32
38
|
let userInfo = await saveUserInfo({
|
|
33
39
|
platformUserInfo,
|
|
@@ -39,7 +45,8 @@ async function onOAuthCallback({ platform, hostname, tokenUrl, callbackUri, apiU
|
|
|
39
45
|
accessToken,
|
|
40
46
|
refreshToken,
|
|
41
47
|
tokenExpiry: expires,
|
|
42
|
-
rcAccountId: query.rcAccountId
|
|
48
|
+
rcAccountId: query.rcAccountId,
|
|
49
|
+
proxyId
|
|
43
50
|
});
|
|
44
51
|
if (platformModule.postSaveUserInfo) {
|
|
45
52
|
userInfo = await platformModule.postSaveUserInfo({ userInfo, oauthApp });
|
|
@@ -57,15 +64,16 @@ async function onOAuthCallback({ platform, hostname, tokenUrl, callbackUri, apiU
|
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
66
|
|
|
60
|
-
async function onApiKeyLogin({ platform, hostname, apiKey, additionalInfo }) {
|
|
67
|
+
async function onApiKeyLogin({ platform, hostname, apiKey, proxyId, additionalInfo }) {
|
|
61
68
|
const platformModule = connectorRegistry.getConnector(platform);
|
|
62
69
|
const basicAuth = platformModule.getBasicAuth({ apiKey });
|
|
63
|
-
const { successful, platformUserInfo, returnMessage } = await platformModule.getUserInfo({ authHeader: `Basic ${basicAuth}`, hostname, additionalInfo, apiKey });
|
|
70
|
+
const { successful, platformUserInfo, returnMessage } = await platformModule.getUserInfo({ authHeader: `Basic ${basicAuth}`, hostname, platform, additionalInfo, apiKey, proxyId });
|
|
64
71
|
if (successful) {
|
|
65
72
|
let userInfo = await saveUserInfo({
|
|
66
73
|
platformUserInfo,
|
|
67
74
|
platform,
|
|
68
75
|
hostname,
|
|
76
|
+
proxyId,
|
|
69
77
|
accessToken: platformUserInfo.overridingApiKey ?? apiKey
|
|
70
78
|
});
|
|
71
79
|
if (platformModule.postSaveUserInfo) {
|
|
@@ -84,13 +92,14 @@ async function onApiKeyLogin({ platform, hostname, apiKey, additionalInfo }) {
|
|
|
84
92
|
}
|
|
85
93
|
}
|
|
86
94
|
|
|
87
|
-
async function saveUserInfo({ platformUserInfo, platform, hostname, accessToken, refreshToken, tokenExpiry, rcAccountId }) {
|
|
95
|
+
async function saveUserInfo({ platformUserInfo, platform, hostname, accessToken, refreshToken, tokenExpiry, rcAccountId, proxyId }) {
|
|
88
96
|
const id = platformUserInfo.id;
|
|
89
97
|
const name = platformUserInfo.name;
|
|
90
98
|
const existingUser = await UserModel.findByPk(id);
|
|
91
99
|
const timezoneName = platformUserInfo.timezoneName;
|
|
92
100
|
const timezoneOffset = platformUserInfo.timezoneOffset;
|
|
93
|
-
const platformAdditionalInfo = platformUserInfo.platformAdditionalInfo;
|
|
101
|
+
const platformAdditionalInfo = platformUserInfo.platformAdditionalInfo || {};
|
|
102
|
+
platformAdditionalInfo.proxyId = proxyId;
|
|
94
103
|
if (existingUser) {
|
|
95
104
|
await existingUser.update(
|
|
96
105
|
{
|
|
@@ -170,7 +179,7 @@ async function saveUserInfo({ platformUserInfo, platform, hostname, accessToken,
|
|
|
170
179
|
|
|
171
180
|
async function getLicenseStatus({ userId, platform }) {
|
|
172
181
|
const platformModule = connectorRegistry.getConnector(platform);
|
|
173
|
-
const licenseStatus = await platformModule.getLicenseStatus({ userId });
|
|
182
|
+
const licenseStatus = await platformModule.getLicenseStatus({ userId, platform });
|
|
174
183
|
return licenseStatus;
|
|
175
184
|
}
|
|
176
185
|
|
|
@@ -188,7 +197,8 @@ async function authValidation({ platform, userId }) {
|
|
|
188
197
|
});
|
|
189
198
|
if (existingUser) {
|
|
190
199
|
const platformModule = connectorRegistry.getConnector(platform);
|
|
191
|
-
const
|
|
200
|
+
const proxyId = existingUser?.platformAdditionalInfo?.proxyId;
|
|
201
|
+
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: existingUser?.platformAdditionalInfo?.tokenUrl, hostname: existingUser?.hostname, proxyId })));
|
|
192
202
|
existingUser = await oauth.checkAndRefreshAccessToken(oauthApp, existingUser);
|
|
193
203
|
const { successful, returnMessage, status } = await platformModule.authValidation({ user: existingUser });
|
|
194
204
|
return {
|
package/handlers/contact.js
CHANGED
|
@@ -2,6 +2,8 @@ const oauth = require('../lib/oauth');
|
|
|
2
2
|
const { UserModel } = require('../models/userModel');
|
|
3
3
|
const errorMessage = require('../lib/generalErrorMessage');
|
|
4
4
|
const connectorRegistry = require('../connector/registry');
|
|
5
|
+
const { Connector } = require('../models/dynamo/connectorSchema');
|
|
6
|
+
|
|
5
7
|
async function findContact({ platform, userId, phoneNumber, overridingFormat, isExtension }) {
|
|
6
8
|
try {
|
|
7
9
|
let user = await UserModel.findOne({
|
|
@@ -20,12 +22,17 @@ async function findContact({ platform, userId, phoneNumber, overridingFormat, is
|
|
|
20
22
|
}
|
|
21
23
|
};
|
|
22
24
|
}
|
|
25
|
+
const proxyId = user.platformAdditionalInfo?.proxyId;
|
|
26
|
+
let proxyConfig = null;
|
|
27
|
+
if (proxyId) {
|
|
28
|
+
proxyConfig = await Connector.getProxyConfig(proxyId);
|
|
29
|
+
}
|
|
23
30
|
const platformModule = connectorRegistry.getConnector(platform);
|
|
24
|
-
const authType = platformModule.getAuthType();
|
|
31
|
+
const authType = await platformModule.getAuthType({ proxyId, proxyConfig });
|
|
25
32
|
let authHeader = '';
|
|
26
33
|
switch (authType) {
|
|
27
34
|
case 'oauth':
|
|
28
|
-
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname })));
|
|
35
|
+
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname, proxyId, proxyConfig })));
|
|
29
36
|
user = await oauth.checkAndRefreshAccessToken(oauthApp, user);
|
|
30
37
|
authHeader = `Bearer ${user.accessToken}`;
|
|
31
38
|
break;
|
|
@@ -34,7 +41,7 @@ async function findContact({ platform, userId, phoneNumber, overridingFormat, is
|
|
|
34
41
|
authHeader = `Basic ${basicAuth}`;
|
|
35
42
|
break;
|
|
36
43
|
}
|
|
37
|
-
const { successful, matchedContactInfo, returnMessage, extraDataTracking } = await platformModule.findContact({ user, authHeader, phoneNumber, overridingFormat, isExtension });
|
|
44
|
+
const { successful, matchedContactInfo, returnMessage, extraDataTracking } = await platformModule.findContact({ user, authHeader, phoneNumber, overridingFormat, isExtension, proxyConfig });
|
|
38
45
|
if (matchedContactInfo != null && matchedContactInfo?.filter(c => !c.isNewContact)?.length > 0) {
|
|
39
46
|
return { successful, returnMessage, contact: matchedContactInfo, extraDataTracking };
|
|
40
47
|
}
|
|
@@ -127,12 +134,17 @@ async function createContact({ platform, userId, phoneNumber, newContactName, ne
|
|
|
127
134
|
if (!user || !user.accessToken) {
|
|
128
135
|
return { successful: false, message: `Contact not found` };
|
|
129
136
|
}
|
|
137
|
+
const proxyId = user.platformAdditionalInfo?.proxyId;
|
|
138
|
+
let proxyConfig = null;
|
|
139
|
+
if (proxyId) {
|
|
140
|
+
proxyConfig = await Connector.getProxyConfig(proxyId);
|
|
141
|
+
}
|
|
130
142
|
const platformModule = connectorRegistry.getConnector(platform);
|
|
131
|
-
const authType = platformModule.getAuthType();
|
|
143
|
+
const authType = await platformModule.getAuthType({ proxyId, proxyConfig });
|
|
132
144
|
let authHeader = '';
|
|
133
145
|
switch (authType) {
|
|
134
146
|
case 'oauth':
|
|
135
|
-
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname })));
|
|
147
|
+
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname, proxyId, proxyConfig })));
|
|
136
148
|
user = await oauth.checkAndRefreshAccessToken(oauthApp, user);
|
|
137
149
|
authHeader = `Bearer ${user.accessToken}`;
|
|
138
150
|
break;
|
|
@@ -141,7 +153,7 @@ async function createContact({ platform, userId, phoneNumber, newContactName, ne
|
|
|
141
153
|
authHeader = `Basic ${basicAuth}`;
|
|
142
154
|
break;
|
|
143
155
|
}
|
|
144
|
-
const { contactInfo, returnMessage, extraDataTracking } = await platformModule.createContact({ user, authHeader, phoneNumber, newContactName, newContactType, additionalSubmission });
|
|
156
|
+
const { contactInfo, returnMessage, extraDataTracking } = await platformModule.createContact({ user, authHeader, phoneNumber, newContactName, newContactType, additionalSubmission, proxyConfig });
|
|
145
157
|
if (contactInfo != null) {
|
|
146
158
|
return { successful: true, returnMessage, contact: contactInfo, extraDataTracking };
|
|
147
159
|
}
|
|
@@ -207,12 +219,17 @@ async function findContactWithName({ platform, userId, name }) {
|
|
|
207
219
|
}
|
|
208
220
|
};
|
|
209
221
|
}
|
|
222
|
+
const proxyId = user.platformAdditionalInfo?.proxyId;
|
|
223
|
+
let proxyConfig = null;
|
|
224
|
+
if (proxyId) {
|
|
225
|
+
proxyConfig = await Connector.getProxyConfig(proxyId);
|
|
226
|
+
}
|
|
210
227
|
const platformModule = connectorRegistry.getConnector(platform);
|
|
211
|
-
const authType = platformModule.getAuthType();
|
|
228
|
+
const authType = await platformModule.getAuthType({ proxyId, proxyConfig });
|
|
212
229
|
let authHeader = '';
|
|
213
230
|
switch (authType) {
|
|
214
231
|
case 'oauth':
|
|
215
|
-
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname })));
|
|
232
|
+
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname, proxyId, proxyConfig })));
|
|
216
233
|
user = await oauth.checkAndRefreshAccessToken(oauthApp, user);
|
|
217
234
|
authHeader = `Bearer ${user.accessToken}`;
|
|
218
235
|
break;
|
|
@@ -221,7 +238,7 @@ async function findContactWithName({ platform, userId, name }) {
|
|
|
221
238
|
authHeader = `Basic ${basicAuth}`;
|
|
222
239
|
break;
|
|
223
240
|
}
|
|
224
|
-
const { successful, matchedContactInfo, returnMessage } = await platformModule.findContactWithName({ user, authHeader, name });
|
|
241
|
+
const { successful, matchedContactInfo, returnMessage } = await platformModule.findContactWithName({ user, authHeader, name, proxyConfig });
|
|
225
242
|
if (matchedContactInfo != null && matchedContactInfo?.filter(c => !c.isNewContact)?.length > 0) {
|
|
226
243
|
return { successful, returnMessage, contact: matchedContactInfo };
|
|
227
244
|
}
|
package/handlers/disposition.js
CHANGED
|
@@ -6,6 +6,7 @@ const oauth = require('../lib/oauth');
|
|
|
6
6
|
// const userCore = require('../handlers/user');
|
|
7
7
|
const errorMessage = require('../lib/generalErrorMessage');
|
|
8
8
|
const connectorRegistry = require('../connector/registry');
|
|
9
|
+
const { Connector } = require('../models/dynamo/connectorSchema');
|
|
9
10
|
|
|
10
11
|
async function upsertCallDisposition({ platform, userId, sessionId, dispositions, additionalSubmission, userSettings }) {
|
|
11
12
|
try {
|
|
@@ -35,12 +36,17 @@ async function upsertCallDisposition({ platform, userId, sessionId, dispositions
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
}
|
|
39
|
+
const proxyId = user.platformAdditionalInfo?.proxyId;
|
|
40
|
+
let proxyConfig = null;
|
|
41
|
+
if (proxyId) {
|
|
42
|
+
proxyConfig = await Connector.getProxyConfig(proxyId);
|
|
43
|
+
}
|
|
38
44
|
const platformModule = connectorRegistry.getConnector(platform);
|
|
39
|
-
const authType = platformModule.getAuthType();
|
|
45
|
+
const authType = await platformModule.getAuthType({ proxyId, proxyConfig });
|
|
40
46
|
let authHeader = '';
|
|
41
47
|
switch (authType) {
|
|
42
48
|
case 'oauth':
|
|
43
|
-
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname })));
|
|
49
|
+
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname, proxyId, proxyConfig })));
|
|
44
50
|
user = await oauth.checkAndRefreshAccessToken(oauthApp, user);
|
|
45
51
|
authHeader = `Bearer ${user.accessToken}`;
|
|
46
52
|
break;
|
|
@@ -53,7 +59,8 @@ async function upsertCallDisposition({ platform, userId, sessionId, dispositions
|
|
|
53
59
|
user,
|
|
54
60
|
existingCallLog: log,
|
|
55
61
|
authHeader,
|
|
56
|
-
dispositions
|
|
62
|
+
dispositions,
|
|
63
|
+
proxyConfig
|
|
57
64
|
});
|
|
58
65
|
return { successful: !!logId, logId, returnMessage, extraDataTracking };
|
|
59
66
|
}
|
|
@@ -126,12 +133,17 @@ async function upsertCallDisposition({ platform, userId, sessionId, dispositions
|
|
|
126
133
|
// }
|
|
127
134
|
// }
|
|
128
135
|
// }
|
|
136
|
+
// const proxyId = user.platformAdditionalInfo?.proxyId;
|
|
137
|
+
// let proxyConfig = null;
|
|
138
|
+
// if (proxyId) {
|
|
139
|
+
// proxyConfig = await Connector.getProxyConfig(proxyId);
|
|
140
|
+
// }
|
|
129
141
|
// const platformModule = connectorRegistry.getConnector(platform);
|
|
130
|
-
// const authType = platformModule.getAuthType();
|
|
142
|
+
// const authType = await platformModule.getAuthType({ proxyId, proxyConfig });
|
|
131
143
|
// let authHeader = '';
|
|
132
144
|
// switch (authType) {
|
|
133
145
|
// case 'oauth':
|
|
134
|
-
// const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname })));
|
|
146
|
+
// const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname, proxyId, proxyConfig })));
|
|
135
147
|
// user = await oauth.checkAndRefreshAccessToken(oauthApp, user);
|
|
136
148
|
// authHeader = `Bearer ${user.accessToken}`;
|
|
137
149
|
// break;
|
|
@@ -144,7 +156,8 @@ async function upsertCallDisposition({ platform, userId, sessionId, dispositions
|
|
|
144
156
|
// user,
|
|
145
157
|
// existingMessageLog: existingSameDateMessageLog,
|
|
146
158
|
// authHeader,
|
|
147
|
-
// dispositions
|
|
159
|
+
// dispositions,
|
|
160
|
+
// proxyConfig
|
|
148
161
|
// });
|
|
149
162
|
// return { successful: !!logId, logId, returnMessage, extraDataTracking };
|
|
150
163
|
// }
|
package/handlers/log.js
CHANGED
|
@@ -8,6 +8,7 @@ const { composeCallLog } = require('../lib/callLogComposer');
|
|
|
8
8
|
const connectorRegistry = require('../connector/registry');
|
|
9
9
|
const { LOG_DETAILS_FORMAT_TYPE } = require('../lib/constants');
|
|
10
10
|
const { NoteCache } = require('../models/dynamo/noteCacheSchema');
|
|
11
|
+
const { Connector } = require('../models/dynamo/connectorSchema');
|
|
11
12
|
const moment = require('moment');
|
|
12
13
|
const { getMediaReaderLinkByPlatformMediaLink } = require('../lib/util');
|
|
13
14
|
|
|
@@ -51,11 +52,16 @@ async function createCallLog({ platform, userId, incomingData, hashedAccountId,
|
|
|
51
52
|
}
|
|
52
53
|
const aiNote = incomingData.aiNote;
|
|
53
54
|
const transcript = incomingData.transcript;
|
|
54
|
-
|
|
55
|
+
let proxyConfig;
|
|
56
|
+
const proxyId = user.platformAdditionalInfo?.proxyId;
|
|
57
|
+
if (proxyId) {
|
|
58
|
+
proxyConfig = await Connector.getProxyConfig(proxyId);
|
|
59
|
+
}
|
|
60
|
+
const authType = await platformModule.getAuthType({ proxyId, proxyConfig });
|
|
55
61
|
let authHeader = '';
|
|
56
62
|
switch (authType) {
|
|
57
63
|
case 'oauth':
|
|
58
|
-
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname })));
|
|
64
|
+
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname, proxyId, proxyConfig })));
|
|
59
65
|
user = await oauth.checkAndRefreshAccessToken(oauthApp, user);
|
|
60
66
|
authHeader = `Bearer ${user.accessToken}`;
|
|
61
67
|
break;
|
|
@@ -82,9 +88,9 @@ async function createCallLog({ platform, userId, incomingData, hashedAccountId,
|
|
|
82
88
|
type: incomingData.contactType ?? "",
|
|
83
89
|
name: incomingData.contactName ?? ""
|
|
84
90
|
};
|
|
85
|
-
|
|
91
|
+
|
|
86
92
|
// Compose call log details centrally
|
|
87
|
-
const logFormat = platformModule.getLogFormatType ? platformModule.getLogFormatType(platform) : LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT;
|
|
93
|
+
const logFormat = platformModule.getLogFormatType ? platformModule.getLogFormatType(platform, proxyConfig) : LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT;
|
|
88
94
|
let composedLogDetails = '';
|
|
89
95
|
if (logFormat === LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT || logFormat === LOG_DETAILS_FORMAT_TYPE.HTML || logFormat === LOG_DETAILS_FORMAT_TYPE.MARKDOWN) {
|
|
90
96
|
composedLogDetails = await composeCallLog({
|
|
@@ -100,7 +106,12 @@ async function createCallLog({ platform, userId, incomingData, hashedAccountId,
|
|
|
100
106
|
startTime: callLog.startTime,
|
|
101
107
|
duration: callLog.duration,
|
|
102
108
|
result: callLog.result,
|
|
103
|
-
platform
|
|
109
|
+
platform,
|
|
110
|
+
ringSenseTranscript: incomingData.ringSenseTranscript,
|
|
111
|
+
ringSenseSummary: incomingData.ringSenseSummary,
|
|
112
|
+
ringSenseAIScore: incomingData.ringSenseAIScore,
|
|
113
|
+
ringSenseBulletedSummary: incomingData.ringSenseBulletedSummary,
|
|
114
|
+
ringSenseLink: incomingData.ringSenseLink,
|
|
104
115
|
});
|
|
105
116
|
}
|
|
106
117
|
|
|
@@ -113,9 +124,15 @@ async function createCallLog({ platform, userId, incomingData, hashedAccountId,
|
|
|
113
124
|
additionalSubmission,
|
|
114
125
|
aiNote,
|
|
115
126
|
transcript,
|
|
127
|
+
ringSenseTranscript: incomingData.ringSenseTranscript,
|
|
128
|
+
ringSenseSummary: incomingData.ringSenseSummary,
|
|
129
|
+
ringSenseAIScore: incomingData.ringSenseAIScore,
|
|
130
|
+
ringSenseBulletedSummary: incomingData.ringSenseBulletedSummary,
|
|
131
|
+
ringSenseLink: incomingData.ringSenseLink,
|
|
116
132
|
composedLogDetails,
|
|
117
133
|
hashedAccountId,
|
|
118
|
-
isFromSSCL
|
|
134
|
+
isFromSSCL,
|
|
135
|
+
proxyConfig,
|
|
119
136
|
});
|
|
120
137
|
if (logId) {
|
|
121
138
|
await CallLogModel.create({
|
|
@@ -189,12 +206,17 @@ async function getCallLog({ userId, sessionIds, platform, requireDetails }) {
|
|
|
189
206
|
sessionIdsArray = sessionIdsArray.slice(0, 5);
|
|
190
207
|
}
|
|
191
208
|
if (requireDetails) {
|
|
209
|
+
const proxyId = user.platformAdditionalInfo?.proxyId;
|
|
210
|
+
let proxyConfig = null;
|
|
211
|
+
if (proxyId) {
|
|
212
|
+
proxyConfig = await Connector.getProxyConfig(proxyId);
|
|
213
|
+
}
|
|
192
214
|
const platformModule = connectorRegistry.getConnector(platform);
|
|
193
|
-
const authType = platformModule.getAuthType();
|
|
215
|
+
const authType = await platformModule.getAuthType({ proxyId, proxyConfig });
|
|
194
216
|
let authHeader = '';
|
|
195
217
|
switch (authType) {
|
|
196
218
|
case 'oauth':
|
|
197
|
-
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname })));
|
|
219
|
+
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname, proxyId, proxyConfig })));
|
|
198
220
|
user = await oauth.checkAndRefreshAccessToken(oauthApp, user);
|
|
199
221
|
authHeader = `Bearer ${user.accessToken}`;
|
|
200
222
|
break;
|
|
@@ -221,7 +243,7 @@ async function getCallLog({ userId, sessionIds, platform, requireDetails }) {
|
|
|
221
243
|
logs.push({ sessionId: sId, matched: false });
|
|
222
244
|
}
|
|
223
245
|
else {
|
|
224
|
-
const getCallLogResult = await platformModule.getCallLog({ user, callLogId: callLog.thirdPartyLogId, contactId: callLog.contactId, authHeader });
|
|
246
|
+
const getCallLogResult = await platformModule.getCallLog({ user, callLogId: callLog.thirdPartyLogId, contactId: callLog.contactId, authHeader, proxyConfig });
|
|
225
247
|
returnMessage = getCallLogResult.returnMessage;
|
|
226
248
|
extraDataTracking = getCallLogResult.extraDataTracking;
|
|
227
249
|
logs.push({ sessionId: callLog.sessionId, matched: true, logId: callLog.thirdPartyLogId, logData: getCallLogResult.callLogInfo });
|
|
@@ -308,11 +330,16 @@ async function updateCallLog({ platform, userId, incomingData, hashedAccountId,
|
|
|
308
330
|
if (!user || !user.accessToken) {
|
|
309
331
|
return { successful: false, message: `Contact not found` };
|
|
310
332
|
}
|
|
311
|
-
const
|
|
333
|
+
const proxyId = user.platformAdditionalInfo?.proxyId;
|
|
334
|
+
let proxyConfig = null;
|
|
335
|
+
if (proxyId) {
|
|
336
|
+
proxyConfig = await Connector.getProxyConfig(proxyId);
|
|
337
|
+
}
|
|
338
|
+
const authType = await platformModule.getAuthType({ proxyId, proxyConfig });
|
|
312
339
|
let authHeader = '';
|
|
313
340
|
switch (authType) {
|
|
314
341
|
case 'oauth':
|
|
315
|
-
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname })));
|
|
342
|
+
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname, proxyId, proxyConfig })));
|
|
316
343
|
user = await oauth.checkAndRefreshAccessToken(oauthApp, user);
|
|
317
344
|
authHeader = `Bearer ${user.accessToken}`;
|
|
318
345
|
break;
|
|
@@ -324,7 +351,7 @@ async function updateCallLog({ platform, userId, incomingData, hashedAccountId,
|
|
|
324
351
|
|
|
325
352
|
// Fetch existing call log details once to avoid duplicate API calls
|
|
326
353
|
let existingCallLogDetails = null; // Compose updated call log details centrally
|
|
327
|
-
const logFormat = platformModule.getLogFormatType ? platformModule.getLogFormatType(platform) : LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT;
|
|
354
|
+
const logFormat = platformModule.getLogFormatType ? platformModule.getLogFormatType(platform, proxyConfig) : LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT;
|
|
328
355
|
let composedLogDetails = '';
|
|
329
356
|
if (logFormat === LOG_DETAILS_FORMAT_TYPE.PLAIN_TEXT || logFormat === LOG_DETAILS_FORMAT_TYPE.HTML || logFormat === LOG_DETAILS_FORMAT_TYPE.MARKDOWN) {
|
|
330
357
|
let existingBody = '';
|
|
@@ -332,7 +359,8 @@ async function updateCallLog({ platform, userId, incomingData, hashedAccountId,
|
|
|
332
359
|
const getLogResult = await platformModule.getCallLog({
|
|
333
360
|
user,
|
|
334
361
|
callLogId: existingCallLog.thirdPartyLogId,
|
|
335
|
-
authHeader
|
|
362
|
+
authHeader,
|
|
363
|
+
proxyConfig,
|
|
336
364
|
});
|
|
337
365
|
existingCallLogDetails = getLogResult?.callLogInfo?.fullLogResponse;
|
|
338
366
|
// Extract existing body from the platform-specific response
|
|
@@ -367,6 +395,11 @@ async function updateCallLog({ platform, userId, incomingData, hashedAccountId,
|
|
|
367
395
|
startTime: incomingData.startTime,
|
|
368
396
|
duration: incomingData.duration,
|
|
369
397
|
result: incomingData.result,
|
|
398
|
+
ringSenseTranscript: incomingData.ringSenseTranscript,
|
|
399
|
+
ringSenseSummary: incomingData.ringSenseSummary,
|
|
400
|
+
ringSenseAIScore: incomingData.ringSenseAIScore,
|
|
401
|
+
ringSenseBulletedSummary: incomingData.ringSenseBulletedSummary,
|
|
402
|
+
ringSenseLink: incomingData.ringSenseLink,
|
|
370
403
|
});
|
|
371
404
|
}
|
|
372
405
|
|
|
@@ -384,11 +417,17 @@ async function updateCallLog({ platform, userId, incomingData, hashedAccountId,
|
|
|
384
417
|
aiNote: incomingData.aiNote,
|
|
385
418
|
transcript: incomingData.transcript,
|
|
386
419
|
legs: incomingData.legs || [],
|
|
420
|
+
ringSenseTranscript: incomingData.ringSenseTranscript,
|
|
421
|
+
ringSenseSummary: incomingData.ringSenseSummary,
|
|
422
|
+
ringSenseAIScore: incomingData.ringSenseAIScore,
|
|
423
|
+
ringSenseBulletedSummary: incomingData.ringSenseBulletedSummary,
|
|
424
|
+
ringSenseLink: incomingData.ringSenseLink,
|
|
387
425
|
additionalSubmission: incomingData.additionalSubmission,
|
|
388
426
|
composedLogDetails,
|
|
389
427
|
existingCallLogDetails, // Pass the fetched details to avoid duplicate API calls
|
|
390
428
|
hashedAccountId,
|
|
391
|
-
isFromSSCL
|
|
429
|
+
isFromSSCL,
|
|
430
|
+
proxyConfig,
|
|
392
431
|
});
|
|
393
432
|
return { successful: true, logId: existingCallLog.thirdPartyLogId, updatedNote, returnMessage, extraDataTracking };
|
|
394
433
|
}
|
|
@@ -470,11 +509,16 @@ async function createMessageLog({ platform, userId, incomingData }) {
|
|
|
470
509
|
}
|
|
471
510
|
};
|
|
472
511
|
}
|
|
473
|
-
const
|
|
512
|
+
const proxyId = user.platformAdditionalInfo?.proxyId;
|
|
513
|
+
let proxyConfig = null;
|
|
514
|
+
if (proxyId) {
|
|
515
|
+
proxyConfig = await Connector.getProxyConfig(proxyId);
|
|
516
|
+
}
|
|
517
|
+
const authType = await platformModule.getAuthType({ proxyId, proxyConfig });
|
|
474
518
|
let authHeader = '';
|
|
475
519
|
switch (authType) {
|
|
476
520
|
case 'oauth':
|
|
477
|
-
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname })));
|
|
521
|
+
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname, proxyId, proxyConfig })));
|
|
478
522
|
user = await oauth.checkAndRefreshAccessToken(oauthApp, user);
|
|
479
523
|
authHeader = `Bearer ${user.accessToken}`;
|
|
480
524
|
break;
|
|
@@ -544,12 +588,12 @@ async function createMessageLog({ platform, userId, incomingData }) {
|
|
|
544
588
|
});
|
|
545
589
|
let crmLogId = ''
|
|
546
590
|
if (existingSameDateMessageLog) {
|
|
547
|
-
const updateMessageResult = await platformModule.updateMessageLog({ user, contactInfo, existingMessageLog: existingSameDateMessageLog, message, authHeader, additionalSubmission, imageLink, videoLink });
|
|
591
|
+
const updateMessageResult = await platformModule.updateMessageLog({ user, contactInfo, existingMessageLog: existingSameDateMessageLog, message, authHeader, additionalSubmission, imageLink, videoLink, proxyConfig });
|
|
548
592
|
crmLogId = existingSameDateMessageLog.thirdPartyLogId;
|
|
549
593
|
returnMessage = updateMessageResult?.returnMessage;
|
|
550
594
|
}
|
|
551
595
|
else {
|
|
552
|
-
const createMessageLogResult = await platformModule.createMessageLog({ user, contactInfo, authHeader, message, additionalSubmission, recordingLink, faxDocLink, faxDownloadLink, imageLink, videoLink });
|
|
596
|
+
const createMessageLogResult = await platformModule.createMessageLog({ user, contactInfo, authHeader, message, additionalSubmission, recordingLink, faxDocLink, faxDownloadLink, imageLink, videoLink, proxyConfig });
|
|
553
597
|
crmLogId = createMessageLogResult.logId;
|
|
554
598
|
returnMessage = createMessageLogResult?.returnMessage;
|
|
555
599
|
extraDataTracking = createMessageLogResult.extraDataTracking;
|
package/index.js
CHANGED
|
@@ -18,6 +18,7 @@ const adminCore = require('./handlers/admin');
|
|
|
18
18
|
const userCore = require('./handlers/user');
|
|
19
19
|
const dispositionCore = require('./handlers/disposition');
|
|
20
20
|
const mock = require('./connector/mock');
|
|
21
|
+
const proxyConnector = require('./connector/proxy');
|
|
21
22
|
const releaseNotes = require('./releaseNotes.json');
|
|
22
23
|
const analytics = require('./lib/analytics');
|
|
23
24
|
const util = require('./lib/util');
|
|
@@ -124,6 +125,48 @@ function createCoreRouter() {
|
|
|
124
125
|
res.send(`OK`);
|
|
125
126
|
});
|
|
126
127
|
|
|
128
|
+
router.get('/implementedInterfaces', (req, res) => {
|
|
129
|
+
try {
|
|
130
|
+
const platform = req.query.platform;
|
|
131
|
+
if (platform) {
|
|
132
|
+
const platformModule = connectorRegistry.getConnector(platform);
|
|
133
|
+
const result = {};
|
|
134
|
+
const authType = platformModule.getAuthType();
|
|
135
|
+
result.getAuthType = !!platformModule.getAuthType;
|
|
136
|
+
switch(authType){
|
|
137
|
+
case 'oauth':
|
|
138
|
+
result.getOauthInfo = !!platformModule.getOauthInfo;
|
|
139
|
+
break;
|
|
140
|
+
case 'apiKey':
|
|
141
|
+
result.getBasicAuth = !!platformModule.getBasicAuth;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
result.getUserInfo = !!platformModule.getUserInfo;
|
|
145
|
+
result.createCallLog = !!platformModule.createCallLog;
|
|
146
|
+
result.updateCallLog = !!platformModule.updateCallLog;
|
|
147
|
+
result.getCallLog = !!platformModule.getCallLog;
|
|
148
|
+
result.createMessageLog = !!platformModule.createMessageLog;
|
|
149
|
+
result.updateMessageLog = !!platformModule.updateMessageLog;
|
|
150
|
+
result.createContact = !!platformModule.createContact;
|
|
151
|
+
result.findContact = !!platformModule.findContact;
|
|
152
|
+
result.unAuthorize = !!platformModule.unAuthorize;
|
|
153
|
+
result.upsertCallDisposition = !!platformModule.upsertCallDisposition;
|
|
154
|
+
result.findContactWithName = !!platformModule.findContactWithName;
|
|
155
|
+
result.getUserList = !!platformModule.getUserList;
|
|
156
|
+
result.getLicenseStatus = !!platformModule.getLicenseStatus;
|
|
157
|
+
result.getLogFormatType = !!platformModule.getLogFormatType;
|
|
158
|
+
res.status(200).send(result);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
res.status(400).send('Please provide platform.');
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
res.status(400).send(e);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
127
170
|
router.get('/licenseStatus', async (req, res) => {
|
|
128
171
|
const requestStartTime = new Date().getTime();
|
|
129
172
|
let platformName = null;
|
|
@@ -647,7 +690,8 @@ function createCoreRouter() {
|
|
|
647
690
|
callbackUri: req.query.callbackUri,
|
|
648
691
|
apiUrl: req.query.apiUrl,
|
|
649
692
|
username: req.query.username,
|
|
650
|
-
query: req.query
|
|
693
|
+
query: req.query,
|
|
694
|
+
proxyId: req.query.proxyId
|
|
651
695
|
});
|
|
652
696
|
if (userInfo) {
|
|
653
697
|
const jwtToken = jwt.generateJwt({
|
|
@@ -692,6 +736,7 @@ function createCoreRouter() {
|
|
|
692
736
|
platformName = platform;
|
|
693
737
|
const apiKey = req.body.apiKey;
|
|
694
738
|
const hostname = req.body.hostname;
|
|
739
|
+
const proxyId = req.body.proxyId;
|
|
695
740
|
const additionalInfo = req.body.additionalInfo;
|
|
696
741
|
if (!platform) {
|
|
697
742
|
throw 'Missing platform name';
|
|
@@ -699,7 +744,7 @@ function createCoreRouter() {
|
|
|
699
744
|
if (!apiKey) {
|
|
700
745
|
throw 'Missing api key';
|
|
701
746
|
}
|
|
702
|
-
const { userInfo, returnMessage } = await authCore.onApiKeyLogin({ platform, hostname, apiKey, additionalInfo });
|
|
747
|
+
const { userInfo, returnMessage } = await authCore.onApiKeyLogin({ platform, hostname, apiKey, proxyId, additionalInfo });
|
|
703
748
|
if (userInfo) {
|
|
704
749
|
const jwtToken = jwt.generateJwt({
|
|
705
750
|
id: userInfo.id.toString(),
|
|
@@ -1626,3 +1671,4 @@ exports.createCoreMiddleware = createCoreMiddleware;
|
|
|
1626
1671
|
exports.createCoreApp = createCoreApp;
|
|
1627
1672
|
exports.initializeCore = initializeCore;
|
|
1628
1673
|
exports.connectorRegistry = connectorRegistry;
|
|
1674
|
+
exports.proxyConnector = proxyConnector;
|