@app-connect/core 1.7.8 → 1.7.11
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/connector/developerPortal.js +43 -0
- package/connector/proxy/index.js +10 -3
- package/connector/registry.js +8 -6
- package/handlers/admin.js +44 -21
- package/handlers/auth.js +97 -69
- package/handlers/calldown.js +10 -4
- package/handlers/contact.js +45 -112
- package/handlers/disposition.js +4 -142
- package/handlers/log.js +174 -259
- package/handlers/user.js +19 -6
- package/index.js +310 -122
- package/lib/analytics.js +3 -1
- package/lib/authSession.js +68 -0
- package/lib/callLogComposer.js +498 -420
- package/lib/errorHandler.js +206 -0
- package/lib/jwt.js +2 -0
- package/lib/logger.js +190 -0
- package/lib/oauth.js +21 -12
- package/lib/ringcentral.js +2 -10
- package/lib/sharedSMSComposer.js +471 -0
- package/mcp/SupportedPlatforms.md +12 -0
- package/mcp/lib/validator.js +91 -0
- package/mcp/mcpHandler.js +166 -0
- package/mcp/tools/checkAuthStatus.js +90 -0
- package/mcp/tools/collectAuthInfo.js +86 -0
- package/mcp/tools/createCallLog.js +299 -0
- package/mcp/tools/createMessageLog.js +283 -0
- package/mcp/tools/doAuth.js +185 -0
- package/mcp/tools/findContactByName.js +87 -0
- package/mcp/tools/findContactByPhone.js +96 -0
- package/mcp/tools/getCallLog.js +98 -0
- package/mcp/tools/getHelp.js +39 -0
- package/mcp/tools/getPublicConnectors.js +46 -0
- package/mcp/tools/index.js +58 -0
- package/mcp/tools/logout.js +63 -0
- package/mcp/tools/rcGetCallLogs.js +73 -0
- package/mcp/tools/setConnector.js +64 -0
- package/mcp/tools/updateCallLog.js +122 -0
- package/models/accountDataModel.js +34 -0
- package/models/cacheModel.js +3 -0
- package/package.json +6 -4
- package/releaseNotes.json +36 -0
- package/test/connector/registry.test.js +145 -0
- package/test/handlers/admin.test.js +583 -0
- package/test/handlers/auth.test.js +355 -0
- package/test/handlers/contact.test.js +852 -0
- package/test/handlers/log.test.js +872 -0
- package/test/lib/callLogComposer.test.js +1231 -0
- package/test/lib/debugTracer.test.js +328 -0
- package/test/lib/logger.test.js +206 -0
- package/test/lib/oauth.test.js +359 -0
- package/test/lib/ringcentral.test.js +473 -0
- package/test/lib/sharedSMSComposer.test.js +1084 -0
- package/test/lib/util.test.js +282 -0
- package/test/mcp/tools/collectAuthInfo.test.js +192 -0
- package/test/mcp/tools/createCallLog.test.js +412 -0
- package/test/mcp/tools/createMessageLog.test.js +580 -0
- package/test/mcp/tools/doAuth.test.js +363 -0
- package/test/mcp/tools/findContactByName.test.js +263 -0
- package/test/mcp/tools/findContactByPhone.test.js +284 -0
- package/test/mcp/tools/getCallLog.test.js +286 -0
- package/test/mcp/tools/getPublicConnectors.test.js +128 -0
- package/test/mcp/tools/logout.test.js +169 -0
- package/test/mcp/tools/setConnector.test.js +177 -0
- package/test/mcp/tools/updateCallLog.test.js +346 -0
- package/test/models/accountDataModel.test.js +98 -0
- package/test/models/dynamo/connectorSchema.test.js +189 -0
- package/test/models/models.test.js +539 -0
- package/test/setup.js +176 -176
package/handlers/contact.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
const oauth = require('../lib/oauth');
|
|
2
2
|
const { UserModel } = require('../models/userModel');
|
|
3
|
-
const errorMessage = require('../lib/generalErrorMessage');
|
|
4
3
|
const connectorRegistry = require('../connector/registry');
|
|
5
4
|
const { Connector } = require('../models/dynamo/connectorSchema');
|
|
6
|
-
const {
|
|
5
|
+
const { handleApiError } = require('../lib/errorHandler');
|
|
6
|
+
const { AccountDataModel } = require('../models/accountDataModel');
|
|
7
7
|
|
|
8
|
-
async function findContact({ platform, userId, phoneNumber, overridingFormat, isExtension, tracer }) {
|
|
8
|
+
async function findContact({ platform, userId, phoneNumber, overridingFormat, isExtension, tracer, isForceRefreshAccountData = false }) {
|
|
9
9
|
tracer?.trace('handler.findContact:entered', { platform, userId, phoneNumber });
|
|
10
|
-
|
|
11
10
|
try {
|
|
12
11
|
let user = await UserModel.findOne({
|
|
13
12
|
where: {
|
|
@@ -16,7 +15,7 @@ async function findContact({ platform, userId, phoneNumber, overridingFormat, is
|
|
|
16
15
|
}
|
|
17
16
|
});
|
|
18
17
|
tracer?.trace('handler.findContact:userFound', { user });
|
|
19
|
-
|
|
18
|
+
|
|
20
19
|
if (!user || !user.accessToken) {
|
|
21
20
|
tracer?.trace('handler.findContact:noUser', { userId });
|
|
22
21
|
return {
|
|
@@ -28,6 +27,20 @@ async function findContact({ platform, userId, phoneNumber, overridingFormat, is
|
|
|
28
27
|
}
|
|
29
28
|
};
|
|
30
29
|
}
|
|
30
|
+
// find cached contact by composite key; findByPk expects raw PK values, so use where clause
|
|
31
|
+
const existingMatchedContactInfo = await AccountDataModel.findOne({
|
|
32
|
+
where: {
|
|
33
|
+
rcAccountId: user.rcAccountId,
|
|
34
|
+
platformName: platform,
|
|
35
|
+
dataKey: `contact-${phoneNumber}`
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
if (!isForceRefreshAccountData) {
|
|
39
|
+
if (existingMatchedContactInfo) {
|
|
40
|
+
console.log('found existing matched contact info in account data');
|
|
41
|
+
return { successful: true, returnMessage: null, contact: existingMatchedContactInfo.data, extraDataTracking: null };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
31
44
|
const proxyId = user.platformAdditionalInfo?.proxyId;
|
|
32
45
|
let proxyConfig = null;
|
|
33
46
|
if (proxyId) {
|
|
@@ -37,7 +50,7 @@ async function findContact({ platform, userId, phoneNumber, overridingFormat, is
|
|
|
37
50
|
const platformModule = connectorRegistry.getConnector(platform);
|
|
38
51
|
const authType = await platformModule.getAuthType({ proxyId, proxyConfig });
|
|
39
52
|
tracer?.trace('handler.findContact:authType', { authType });
|
|
40
|
-
|
|
53
|
+
|
|
41
54
|
let authHeader = '';
|
|
42
55
|
switch (authType) {
|
|
43
56
|
case 'oauth':
|
|
@@ -52,12 +65,31 @@ async function findContact({ platform, userId, phoneNumber, overridingFormat, is
|
|
|
52
65
|
tracer?.trace('handler.findContact:apiKeyAuth', {});
|
|
53
66
|
break;
|
|
54
67
|
}
|
|
55
|
-
|
|
56
|
-
const { successful, matchedContactInfo, returnMessage, extraDataTracking } = await platformModule.findContact({ user, authHeader, phoneNumber, overridingFormat, isExtension, proxyConfig, tracer });
|
|
68
|
+
|
|
69
|
+
const { successful, matchedContactInfo, returnMessage, extraDataTracking } = await platformModule.findContact({ user, authHeader, phoneNumber, overridingFormat, isExtension, proxyConfig, tracer, isForceRefreshAccountData });
|
|
57
70
|
tracer?.trace('handler.findContact:platformFindResult', { successful, matchedContactInfo });
|
|
58
|
-
|
|
71
|
+
|
|
59
72
|
if (matchedContactInfo != null && matchedContactInfo?.filter(c => !c.isNewContact)?.length > 0) {
|
|
60
73
|
tracer?.trace('handler.findContact:contactsFound', { count: matchedContactInfo.length });
|
|
74
|
+
// save in org data
|
|
75
|
+
// Danger: it does NOT support one RC account mapping to multiple CRM platforms, because contacts will be shared
|
|
76
|
+
if (user.rcAccountId) {
|
|
77
|
+
if(existingMatchedContactInfo)
|
|
78
|
+
{
|
|
79
|
+
await existingMatchedContactInfo.update({
|
|
80
|
+
data: matchedContactInfo
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
else{
|
|
84
|
+
await AccountDataModel.create({
|
|
85
|
+
rcAccountId: user.rcAccountId,
|
|
86
|
+
platformName: platform,
|
|
87
|
+
dataKey: `contact-${phoneNumber}`,
|
|
88
|
+
data: matchedContactInfo
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
console.log('store new matched contact info in account data');
|
|
92
|
+
}
|
|
61
93
|
return { successful, returnMessage, contact: matchedContactInfo, extraDataTracking };
|
|
62
94
|
}
|
|
63
95
|
else {
|
|
@@ -93,51 +125,9 @@ async function findContact({ platform, userId, phoneNumber, overridingFormat, is
|
|
|
93
125
|
};
|
|
94
126
|
}
|
|
95
127
|
} catch (e) {
|
|
96
|
-
console.error(`platform: ${platform} \n${e.stack} \n${JSON.stringify(e.response?.data)}`);
|
|
97
128
|
tracer?.traceError('handler.findContact:error', e, { platform, statusCode: e.response?.status });
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
successful: false,
|
|
102
|
-
returnMessage: errorMessage.rateLimitErrorMessage({ platform }),
|
|
103
|
-
extraDataTracking: {
|
|
104
|
-
statusCode: e.response?.status,
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
else if (e.response?.status >= 400 && e.response?.status < 410) {
|
|
109
|
-
return {
|
|
110
|
-
successful: false,
|
|
111
|
-
returnMessage: errorMessage.authorizationErrorMessage({ platform }),
|
|
112
|
-
extraDataTracking: {
|
|
113
|
-
statusCode: e.response?.status,
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
successful: false,
|
|
119
|
-
returnMessage:
|
|
120
|
-
{
|
|
121
|
-
message: `Error finding contacts`,
|
|
122
|
-
messageType: 'warning',
|
|
123
|
-
details: [
|
|
124
|
-
{
|
|
125
|
-
title: 'Details',
|
|
126
|
-
items: [
|
|
127
|
-
{
|
|
128
|
-
id: '1',
|
|
129
|
-
type: 'text',
|
|
130
|
-
text: `Please check if your account has permission to VIEW and LIST contacts`
|
|
131
|
-
}
|
|
132
|
-
]
|
|
133
|
-
}
|
|
134
|
-
],
|
|
135
|
-
ttl: 5000
|
|
136
|
-
},
|
|
137
|
-
extraDataTracking: {
|
|
138
|
-
statusCode: e.response?.status,
|
|
139
|
-
}
|
|
140
|
-
};
|
|
129
|
+
return handleApiError(e, platform, 'findContact', { userId, overridingFormat, isExtension });
|
|
130
|
+
|
|
141
131
|
}
|
|
142
132
|
}
|
|
143
133
|
|
|
@@ -179,43 +169,7 @@ async function createContact({ platform, userId, phoneNumber, newContactName, ne
|
|
|
179
169
|
return { successful: false, returnMessage };
|
|
180
170
|
}
|
|
181
171
|
} catch (e) {
|
|
182
|
-
|
|
183
|
-
if (e.response?.status === 429) {
|
|
184
|
-
return {
|
|
185
|
-
successful: false,
|
|
186
|
-
returnMessage: errorMessage.rateLimitErrorMessage({ platform }),
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
else if (e.response?.status >= 400 && e.response?.status < 410) {
|
|
190
|
-
return {
|
|
191
|
-
successful: false,
|
|
192
|
-
returnMessage: errorMessage.authorizationErrorMessage({ platform }),
|
|
193
|
-
extraDataTracking: {
|
|
194
|
-
statusCode: e.response?.status,
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
return {
|
|
199
|
-
successful: false,
|
|
200
|
-
returnMessage:
|
|
201
|
-
{
|
|
202
|
-
message: `Error creating contact`,
|
|
203
|
-
messageType: 'warning',
|
|
204
|
-
details: [
|
|
205
|
-
{
|
|
206
|
-
title: 'Details',
|
|
207
|
-
items: [
|
|
208
|
-
{
|
|
209
|
-
id: '1',
|
|
210
|
-
type: 'text',
|
|
211
|
-
text: `A contact with the phone number ${phoneNumber} could not be created. Make sure you have permission to create contacts in ${platform}.`
|
|
212
|
-
}
|
|
213
|
-
]
|
|
214
|
-
}
|
|
215
|
-
],
|
|
216
|
-
ttl: 5000
|
|
217
|
-
}
|
|
218
|
-
};
|
|
172
|
+
return handleApiError(e, platform, 'createContact', { userId, phoneNumber, newContactName, newContactType, additionalSubmission });
|
|
219
173
|
}
|
|
220
174
|
}
|
|
221
175
|
|
|
@@ -280,28 +234,7 @@ async function findContactWithName({ platform, userId, name }) {
|
|
|
280
234
|
};
|
|
281
235
|
}
|
|
282
236
|
} catch (e) {
|
|
283
|
-
|
|
284
|
-
if (e.response?.status === 429) {
|
|
285
|
-
return {
|
|
286
|
-
successful: false,
|
|
287
|
-
returnMessage: errorMessage.rateLimitErrorMessage({ platform })
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
else if (e.response?.status >= 400 && e.response?.status < 410) {
|
|
291
|
-
return {
|
|
292
|
-
successful: false,
|
|
293
|
-
returnMessage: errorMessage.authorizationErrorMessage({ platform }),
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
return {
|
|
297
|
-
successful: false,
|
|
298
|
-
returnMessage:
|
|
299
|
-
{
|
|
300
|
-
message: `Error finding contacts`,
|
|
301
|
-
messageType: 'warning',
|
|
302
|
-
ttl: 5000
|
|
303
|
-
}
|
|
304
|
-
};
|
|
237
|
+
return handleApiError(e, platform, 'findContactWithName', { userId, name });
|
|
305
238
|
}
|
|
306
239
|
}
|
|
307
240
|
|
package/handlers/disposition.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
// const Op = require('sequelize').Op;
|
|
2
1
|
const { CallLogModel } = require('../models/callLogModel');
|
|
3
|
-
// const { MessageLogModel } = require('../models/messageLogModel');
|
|
4
2
|
const { UserModel } = require('../models/userModel');
|
|
5
3
|
const oauth = require('../lib/oauth');
|
|
6
|
-
// const userCore = require('../handlers/user');
|
|
7
|
-
const errorMessage = require('../lib/generalErrorMessage');
|
|
8
4
|
const connectorRegistry = require('../connector/registry');
|
|
9
5
|
const { Connector } = require('../models/dynamo/connectorSchema');
|
|
6
|
+
const { handleApiError } = require('../lib/errorHandler');
|
|
10
7
|
|
|
11
|
-
async function upsertCallDisposition({ platform, userId, sessionId, dispositions
|
|
8
|
+
async function upsertCallDisposition({ platform, userId, sessionId, dispositions }) {
|
|
12
9
|
try {
|
|
13
10
|
const log = await CallLogModel.findOne({
|
|
14
11
|
where: {
|
|
@@ -65,143 +62,8 @@ async function upsertCallDisposition({ platform, userId, sessionId, dispositions
|
|
|
65
62
|
return { successful: !!logId, logId, returnMessage, extraDataTracking };
|
|
66
63
|
}
|
|
67
64
|
catch (e) {
|
|
68
|
-
|
|
69
|
-
if (e.response?.status === 429) {
|
|
70
|
-
return {
|
|
71
|
-
successful: false,
|
|
72
|
-
returnMessage: errorMessage.rateLimitErrorMessage({ platform })
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
else if (e.response?.status >= 400 && e.response?.status < 410) {
|
|
76
|
-
return {
|
|
77
|
-
successful: false,
|
|
78
|
-
returnMessage: errorMessage.authorizationErrorMessage({ platform }),
|
|
79
|
-
extraDataTracking: {
|
|
80
|
-
statusCode: e.response?.status,
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
successful: false,
|
|
86
|
-
returnMessage:
|
|
87
|
-
{
|
|
88
|
-
message: `Error dispositioning call log`,
|
|
89
|
-
messageType: 'warning',
|
|
90
|
-
details: [
|
|
91
|
-
{
|
|
92
|
-
title: 'Details',
|
|
93
|
-
items: [
|
|
94
|
-
{
|
|
95
|
-
id: '1',
|
|
96
|
-
type: 'text',
|
|
97
|
-
text: `Please check if your account has permission to UPDATE logs.`
|
|
98
|
-
}
|
|
99
|
-
]
|
|
100
|
-
}
|
|
101
|
-
],
|
|
102
|
-
ttl: 5000
|
|
103
|
-
}
|
|
104
|
-
};
|
|
65
|
+
return handleApiError(e, platform, 'upsertCallDisposition', { userId, sessionId, dispositions });
|
|
105
66
|
}
|
|
106
67
|
}
|
|
107
68
|
|
|
108
|
-
|
|
109
|
-
// try {
|
|
110
|
-
// const existingSameDateMessageLog = await MessageLogModel.findOne({
|
|
111
|
-
// where: {
|
|
112
|
-
// conversationLogId
|
|
113
|
-
// }
|
|
114
|
-
// });
|
|
115
|
-
// if (!existingSameDateMessageLog) {
|
|
116
|
-
// return {
|
|
117
|
-
// successful: false,
|
|
118
|
-
// returnMessage: {
|
|
119
|
-
// message: `Cannot find log`,
|
|
120
|
-
// messageType: 'warning',
|
|
121
|
-
// ttl: 3000
|
|
122
|
-
// }
|
|
123
|
-
// }
|
|
124
|
-
// }
|
|
125
|
-
// let user = await UserModel.findByPk(userId);
|
|
126
|
-
// if (!user) {
|
|
127
|
-
// return {
|
|
128
|
-
// successful: false,
|
|
129
|
-
// returnMessage: {
|
|
130
|
-
// message: `Cannot find user`,
|
|
131
|
-
// messageType: 'warning',
|
|
132
|
-
// ttl: 3000
|
|
133
|
-
// }
|
|
134
|
-
// }
|
|
135
|
-
// }
|
|
136
|
-
// const proxyId = user.platformAdditionalInfo?.proxyId;
|
|
137
|
-
// let proxyConfig = null;
|
|
138
|
-
// if (proxyId) {
|
|
139
|
-
// proxyConfig = await Connector.getProxyConfig(proxyId);
|
|
140
|
-
// }
|
|
141
|
-
// const platformModule = connectorRegistry.getConnector(platform);
|
|
142
|
-
// const authType = await platformModule.getAuthType({ proxyId, proxyConfig });
|
|
143
|
-
// let authHeader = '';
|
|
144
|
-
// switch (authType) {
|
|
145
|
-
// case 'oauth':
|
|
146
|
-
// const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname, proxyId, proxyConfig })));
|
|
147
|
-
// user = await oauth.checkAndRefreshAccessToken(oauthApp, user);
|
|
148
|
-
// authHeader = `Bearer ${user.accessToken}`;
|
|
149
|
-
// break;
|
|
150
|
-
// case 'apiKey':
|
|
151
|
-
// const basicAuth = platformModule.getBasicAuth({ apiKey: user.accessToken });
|
|
152
|
-
// authHeader = `Basic ${basicAuth}`;
|
|
153
|
-
// break;
|
|
154
|
-
// }
|
|
155
|
-
// const { logId, returnMessage, extraDataTracking } = await platformModule.upsertMessageDisposition({
|
|
156
|
-
// user,
|
|
157
|
-
// existingMessageLog: existingSameDateMessageLog,
|
|
158
|
-
// authHeader,
|
|
159
|
-
// dispositions,
|
|
160
|
-
// proxyConfig
|
|
161
|
-
// });
|
|
162
|
-
// return { successful: !!logId, logId, returnMessage, extraDataTracking };
|
|
163
|
-
// }
|
|
164
|
-
// catch (e) {
|
|
165
|
-
// console.error(`platform: ${platform} \n${e.stack} \n${JSON.stringify(e.response?.data)}`);
|
|
166
|
-
// if (e.response?.status === 429) {
|
|
167
|
-
// return {
|
|
168
|
-
// successful: false,
|
|
169
|
-
// returnMessage: errorMessage.rateLimitErrorMessage({ platform })
|
|
170
|
-
// };
|
|
171
|
-
// }
|
|
172
|
-
// else if (e.response?.status >= 400 && e.response?.status < 410) {
|
|
173
|
-
// return {
|
|
174
|
-
// successful: false,
|
|
175
|
-
// returnMessage: errorMessage.authorizationErrorMessage({ platform }),
|
|
176
|
-
// extraDataTracking: {
|
|
177
|
-
// statusCode: e.response?.status,
|
|
178
|
-
// }
|
|
179
|
-
// };
|
|
180
|
-
// }
|
|
181
|
-
// return {
|
|
182
|
-
// successful: false,
|
|
183
|
-
// returnMessage:
|
|
184
|
-
// {
|
|
185
|
-
// message: `Error dispositioning message log`,
|
|
186
|
-
// messageType: 'warning',
|
|
187
|
-
// details: [
|
|
188
|
-
// {
|
|
189
|
-
// title: 'Details',
|
|
190
|
-
// items: [
|
|
191
|
-
// {
|
|
192
|
-
// id: '1',
|
|
193
|
-
// type: 'text',
|
|
194
|
-
// text: `Please check if your account has correct permissions.`
|
|
195
|
-
// }
|
|
196
|
-
// ]
|
|
197
|
-
// }
|
|
198
|
-
// ],
|
|
199
|
-
// ttl: 5000
|
|
200
|
-
// }
|
|
201
|
-
// };
|
|
202
|
-
// }
|
|
203
|
-
// }
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
exports.upsertCallDisposition = upsertCallDisposition;
|
|
207
|
-
// exports.upsertMessageDisposition = upsertMessageDisposition;
|
|
69
|
+
exports.upsertCallDisposition = upsertCallDisposition;
|