@app-connect/core 1.7.8 → 1.7.10
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/handlers/auth.js +10 -4
- package/handlers/contact.js +42 -9
- package/handlers/log.js +4 -4
- package/index.js +101 -79
- package/lib/oauth.js +0 -2
- package/models/accountDataModel.js +34 -0
- package/package.json +70 -69
- package/releaseNotes.json +24 -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 +868 -0
- package/test/lib/callLogComposer.test.js +1231 -0
- package/test/lib/debugTracer.test.js +328 -0
- package/test/lib/oauth.test.js +359 -0
- package/test/lib/ringcentral.test.js +473 -0
- package/test/lib/util.test.js +282 -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/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const express = require('express');
|
|
2
2
|
const cors = require('cors')
|
|
3
3
|
const bodyParser = require('body-parser');
|
|
4
|
+
require('body-parser-xml')(bodyParser);
|
|
4
5
|
const dynamoose = require('dynamoose');
|
|
5
6
|
const axios = require('axios');
|
|
6
7
|
const { UserModel } = require('./models/userModel');
|
|
@@ -10,6 +11,7 @@ const { CallLogModel } = require('./models/callLogModel');
|
|
|
10
11
|
const { MessageLogModel } = require('./models/messageLogModel');
|
|
11
12
|
const { AdminConfigModel } = require('./models/adminConfigModel');
|
|
12
13
|
const { CacheModel } = require('./models/cacheModel');
|
|
14
|
+
const { AccountDataModel } = require('./models/accountDataModel');
|
|
13
15
|
const jwt = require('./lib/jwt');
|
|
14
16
|
const logCore = require('./handlers/log');
|
|
15
17
|
const contactCore = require('./handlers/contact');
|
|
@@ -39,7 +41,13 @@ catch (e) {
|
|
|
39
41
|
if (process.env.DYNAMODB_LOCALHOST) {
|
|
40
42
|
dynamoose.aws.ddb.local(process.env.DYNAMODB_LOCALHOST);
|
|
41
43
|
}
|
|
42
|
-
|
|
44
|
+
// log axios requests
|
|
45
|
+
if (process.env.IS_PROD === 'false') {
|
|
46
|
+
axios.interceptors.request.use(request => {
|
|
47
|
+
console.log('Request:', `[${request.method}]`, request.url);
|
|
48
|
+
return request;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
43
51
|
axios.defaults.headers.common['Unified-CRM-Extension-Version'] = packageJson.version;
|
|
44
52
|
|
|
45
53
|
async function initDB() {
|
|
@@ -51,6 +59,7 @@ async function initDB() {
|
|
|
51
59
|
await AdminConfigModel.sync();
|
|
52
60
|
await CacheModel.sync();
|
|
53
61
|
await CallDownListModel.sync();
|
|
62
|
+
await AccountDataModel.sync();
|
|
54
63
|
}
|
|
55
64
|
}
|
|
56
65
|
|
|
@@ -159,11 +168,11 @@ function createCoreRouter() {
|
|
|
159
168
|
result.getLicenseStatus = !!platformModule.getLicenseStatus;
|
|
160
169
|
result.getLogFormatType = !!platformModule.getLogFormatType;
|
|
161
170
|
result.cacheCallNote = !!process.env.USE_CACHE;
|
|
162
|
-
res.status(200).send(tracer ? tracer.wrapResponse(
|
|
171
|
+
res.status(200).send(tracer ? tracer.wrapResponse(result) : result);
|
|
163
172
|
}
|
|
164
173
|
else {
|
|
165
174
|
tracer?.trace('implementedInterfaces:noPlatform', {});
|
|
166
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
175
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please provide platform.') : 'Please provide platform.');
|
|
167
176
|
return;
|
|
168
177
|
}
|
|
169
178
|
}
|
|
@@ -187,11 +196,11 @@ function createCoreRouter() {
|
|
|
187
196
|
platformName = platform;
|
|
188
197
|
if (!userId) {
|
|
189
198
|
tracer?.trace('licenseStatus:noUserId', {});
|
|
190
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
199
|
+
res.status(400).send(tracer ? tracer.wrapResponse('No user ID') : 'No user ID');
|
|
191
200
|
success = true;
|
|
192
201
|
}
|
|
193
202
|
const licenseStatus = await authCore.getLicenseStatus({ userId, platform });
|
|
194
|
-
res.status(200).send(tracer ? tracer.wrapResponse(
|
|
203
|
+
res.status(200).send(tracer ? tracer.wrapResponse(licenseStatus) : licenseStatus);
|
|
195
204
|
success = true;
|
|
196
205
|
}
|
|
197
206
|
else {
|
|
@@ -253,7 +262,7 @@ function createCoreRouter() {
|
|
|
253
262
|
const decodedToken = jwt.decodeJwt(jwtToken);
|
|
254
263
|
if (!decodedToken) {
|
|
255
264
|
tracer?.trace('authValidation:invalidJwtToken', {});
|
|
256
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
265
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Invalid JWT token') : 'Invalid JWT token');
|
|
257
266
|
return;
|
|
258
267
|
}
|
|
259
268
|
const { id: userId, platform } = decodedToken;
|
|
@@ -267,7 +276,7 @@ function createCoreRouter() {
|
|
|
267
276
|
}
|
|
268
277
|
else {
|
|
269
278
|
tracer?.trace('authValidation:noToken', {});
|
|
270
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
279
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
271
280
|
success = false;
|
|
272
281
|
}
|
|
273
282
|
}
|
|
@@ -314,12 +323,12 @@ function createCoreRouter() {
|
|
|
314
323
|
const hashedRcAccountId = util.getHashValue(rcAccountId, process.env.HASH_KEY);
|
|
315
324
|
if (isValidated) {
|
|
316
325
|
await adminCore.upsertAdminSettings({ hashedRcAccountId, adminSettings: req.body.adminSettings });
|
|
317
|
-
res.status(200).send(tracer ? tracer.wrapResponse(
|
|
326
|
+
res.status(200).send(tracer ? tracer.wrapResponse('Admin settings updated') : 'Admin settings updated');
|
|
318
327
|
success = true;
|
|
319
328
|
}
|
|
320
329
|
else {
|
|
321
330
|
tracer?.trace('setAdminSettings:adminValidationFailed', {});
|
|
322
|
-
res.status(401).send(tracer ? tracer.wrapResponse(
|
|
331
|
+
res.status(401).send(tracer ? tracer.wrapResponse('Admin validation failed') : 'Admin validation failed');
|
|
323
332
|
success = false;
|
|
324
333
|
}
|
|
325
334
|
}
|
|
@@ -358,7 +367,7 @@ function createCoreRouter() {
|
|
|
358
367
|
const user = await UserModel.findByPk(unAuthData?.id);
|
|
359
368
|
if (!user) {
|
|
360
369
|
tracer?.trace('getAdminSettings:userNotFound', {});
|
|
361
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
370
|
+
res.status(400).send(tracer ? tracer.wrapResponse('User not found') : 'User not found');
|
|
362
371
|
return;
|
|
363
372
|
}
|
|
364
373
|
const { isValidated, rcAccountId } = await adminCore.validateAdminRole({ rcAccessToken: req.query.rcAccessToken });
|
|
@@ -366,7 +375,7 @@ function createCoreRouter() {
|
|
|
366
375
|
if (isValidated) {
|
|
367
376
|
const adminSettings = await adminCore.getAdminSettings({ hashedRcAccountId });
|
|
368
377
|
if (adminSettings) {
|
|
369
|
-
res.status(200).send(tracer ? tracer.wrapResponse(
|
|
378
|
+
res.status(200).send(tracer ? tracer.wrapResponse(adminSettings) : adminSettings);
|
|
370
379
|
}
|
|
371
380
|
else {
|
|
372
381
|
res.status(200).send(tracer ? tracer.wrapResponse({
|
|
@@ -381,13 +390,13 @@ function createCoreRouter() {
|
|
|
381
390
|
}
|
|
382
391
|
else {
|
|
383
392
|
tracer?.trace('getAdminSettings:adminValidationFailed', {});
|
|
384
|
-
res.status(401).send(tracer ? tracer.wrapResponse(
|
|
393
|
+
res.status(401).send(tracer ? tracer.wrapResponse('Admin validation failed') : 'Admin validation failed');
|
|
385
394
|
success = true;
|
|
386
395
|
}
|
|
387
396
|
}
|
|
388
397
|
else {
|
|
389
398
|
tracer?.trace('getAdminSettings:noToken', {});
|
|
390
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
399
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
391
400
|
success = false;
|
|
392
401
|
}
|
|
393
402
|
}
|
|
@@ -426,25 +435,25 @@ function createCoreRouter() {
|
|
|
426
435
|
const user = await UserModel.findByPk(unAuthData?.id);
|
|
427
436
|
if (!user) {
|
|
428
437
|
tracer?.trace('getUserMapping:userNotFound', {});
|
|
429
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
438
|
+
res.status(400).send(tracer ? tracer.wrapResponse('User not found') : 'User not found');
|
|
430
439
|
return;
|
|
431
440
|
}
|
|
432
441
|
const { isValidated, rcAccountId } = await adminCore.validateAdminRole({ rcAccessToken: req.query.rcAccessToken });
|
|
433
442
|
const hashedRcAccountId = util.getHashValue(rcAccountId, process.env.HASH_KEY);
|
|
434
443
|
if (isValidated) {
|
|
435
444
|
const userMapping = await adminCore.getUserMapping({ user, hashedRcAccountId, rcExtensionList: req.body.rcExtensionList });
|
|
436
|
-
res.status(200).send(tracer ? tracer.wrapResponse(
|
|
445
|
+
res.status(200).send(tracer ? tracer.wrapResponse(userMapping) : userMapping);
|
|
437
446
|
success = true;
|
|
438
447
|
}
|
|
439
448
|
else {
|
|
440
449
|
tracer?.trace('getUserMapping:adminValidationFailed', {});
|
|
441
|
-
res.status(401).send(tracer ? tracer.wrapResponse(
|
|
450
|
+
res.status(401).send(tracer ? tracer.wrapResponse('Admin validation failed') : 'Admin validation failed');
|
|
442
451
|
success = true;
|
|
443
452
|
}
|
|
444
453
|
}
|
|
445
454
|
else {
|
|
446
455
|
tracer?.trace('getUserMapping:noToken', {});
|
|
447
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
456
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
448
457
|
success = false;
|
|
449
458
|
}
|
|
450
459
|
}
|
|
@@ -477,7 +486,7 @@ function createCoreRouter() {
|
|
|
477
486
|
const jwtToken = req.query.jwtToken;
|
|
478
487
|
if (!jwtToken) {
|
|
479
488
|
tracer?.trace('getServerLoggingSettings:noToken', {});
|
|
480
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
489
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
481
490
|
return;
|
|
482
491
|
}
|
|
483
492
|
const { hashedExtensionId, hashedAccountId, userAgent, ip, author, eventAddedVia } = getAnalyticsVariablesInReqHeaders({ headers: req.headers })
|
|
@@ -485,18 +494,18 @@ function createCoreRouter() {
|
|
|
485
494
|
const unAuthData = jwt.decodeJwt(jwtToken);
|
|
486
495
|
if (!unAuthData?.id) {
|
|
487
496
|
tracer?.trace('getServerLoggingSettings:noToken', {});
|
|
488
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
497
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
489
498
|
return;
|
|
490
499
|
}
|
|
491
500
|
platformName = unAuthData?.platform ?? 'Unknown';
|
|
492
501
|
const user = await UserModel.findByPk(unAuthData?.id);
|
|
493
502
|
if (!user) {
|
|
494
503
|
tracer?.trace('getServerLoggingSettings:userNotFound', {});
|
|
495
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
504
|
+
res.status(400).send(tracer ? tracer.wrapResponse('User not found') : 'User not found');
|
|
496
505
|
return;
|
|
497
506
|
}
|
|
498
507
|
const serverLoggingSettings = await adminCore.getServerLoggingSettings({ user });
|
|
499
|
-
res.status(200).send(tracer ? tracer.wrapResponse(
|
|
508
|
+
res.status(200).send(tracer ? tracer.wrapResponse(serverLoggingSettings) : serverLoggingSettings);
|
|
500
509
|
success = true;
|
|
501
510
|
}
|
|
502
511
|
catch (e) {
|
|
@@ -528,12 +537,12 @@ function createCoreRouter() {
|
|
|
528
537
|
const jwtToken = req.query.jwtToken;
|
|
529
538
|
if (!jwtToken) {
|
|
530
539
|
tracer?.trace('setServerLoggingSettings:noToken', {});
|
|
531
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
540
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
532
541
|
return;
|
|
533
542
|
}
|
|
534
543
|
if (!req.body.additionalFieldValues) {
|
|
535
544
|
tracer?.trace('setServerLoggingSettings:missingAdditionalFieldValues', {});
|
|
536
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
545
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Missing additionalFieldValues') : 'Missing additionalFieldValues');
|
|
537
546
|
return;
|
|
538
547
|
}
|
|
539
548
|
const { hashedExtensionId, hashedAccountId, userAgent, ip, author, eventAddedVia } = getAnalyticsVariablesInReqHeaders({ headers: req.headers })
|
|
@@ -541,14 +550,14 @@ function createCoreRouter() {
|
|
|
541
550
|
const unAuthData = jwt.decodeJwt(jwtToken);
|
|
542
551
|
if (!unAuthData?.id) {
|
|
543
552
|
tracer?.trace('setServerLoggingSettings:noToken', {});
|
|
544
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
553
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
545
554
|
return;
|
|
546
555
|
}
|
|
547
556
|
platformName = unAuthData?.platform ?? 'Unknown';
|
|
548
557
|
const user = await UserModel.findByPk(unAuthData?.id);
|
|
549
558
|
if (!user) {
|
|
550
559
|
tracer?.trace('setServerLoggingSettings:userNotFound', {});
|
|
551
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
560
|
+
res.status(400).send(tracer ? tracer.wrapResponse('User not found') : 'User not found');
|
|
552
561
|
return;
|
|
553
562
|
}
|
|
554
563
|
const { successful, returnMessage } = await adminCore.updateServerLoggingSettings({ user, additionalFieldValues: req.body.additionalFieldValues });
|
|
@@ -584,11 +593,11 @@ function createCoreRouter() {
|
|
|
584
593
|
const rcAccountId = req.query.rcAccountId;
|
|
585
594
|
if (rcAccessToken || rcAccountId) {
|
|
586
595
|
const userSettings = await userCore.getUserSettingsByAdmin({ rcAccessToken, rcAccountId });
|
|
587
|
-
res.status(200).send(tracer ? tracer.wrapResponse(
|
|
596
|
+
res.status(200).send(tracer ? tracer.wrapResponse(userSettings) : userSettings);
|
|
588
597
|
}
|
|
589
598
|
else {
|
|
590
599
|
tracer?.trace('getUserSettingsByAdmin:noRcAccessTokenOrRcAccountId', {});
|
|
591
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
600
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Cannot find rc user login') : 'Cannot find rc user login');
|
|
592
601
|
}
|
|
593
602
|
}
|
|
594
603
|
catch (e) {
|
|
@@ -613,7 +622,7 @@ function createCoreRouter() {
|
|
|
613
622
|
const user = await UserModel.findByPk(unAuthData?.id);
|
|
614
623
|
if (!user) {
|
|
615
624
|
tracer?.trace('getUserSettings:userNotFound', {});
|
|
616
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
625
|
+
res.status(400).send(tracer ? tracer.wrapResponse('User not found') : 'User not found');
|
|
617
626
|
return;
|
|
618
627
|
}
|
|
619
628
|
else {
|
|
@@ -621,13 +630,13 @@ function createCoreRouter() {
|
|
|
621
630
|
const rcAccountId = req.query.rcAccountId;
|
|
622
631
|
const userSettings = await userCore.getUserSettings({ user, rcAccessToken, rcAccountId });
|
|
623
632
|
success = true;
|
|
624
|
-
res.status(200).send(tracer ? tracer.wrapResponse(
|
|
633
|
+
res.status(200).send(tracer ? tracer.wrapResponse(userSettings) : userSettings);
|
|
625
634
|
}
|
|
626
635
|
}
|
|
627
636
|
else {
|
|
628
637
|
success = false;
|
|
629
638
|
tracer?.trace('getUserSettings:noToken', {});
|
|
630
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
639
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
631
640
|
}
|
|
632
641
|
}
|
|
633
642
|
catch (e) {
|
|
@@ -664,13 +673,13 @@ function createCoreRouter() {
|
|
|
664
673
|
platformName = unAuthData?.platform;
|
|
665
674
|
if (!platformName) {
|
|
666
675
|
tracer?.trace('setUserSettings:unknownPlatform', {});
|
|
667
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
676
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Unknown platform') : 'Unknown platform');
|
|
668
677
|
return;
|
|
669
678
|
}
|
|
670
679
|
const user = await UserModel.findByPk(unAuthData?.id);
|
|
671
680
|
if (!user) {
|
|
672
681
|
tracer?.trace('setUserSettings:userNotFound', {});
|
|
673
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
682
|
+
res.status(400).send(tracer ? tracer.wrapResponse('User not found') : 'User not found');
|
|
674
683
|
return;
|
|
675
684
|
}
|
|
676
685
|
const { userSettings } = await userCore.updateUserSettings({ user, userSettings: req.body.userSettings, platformName });
|
|
@@ -679,7 +688,7 @@ function createCoreRouter() {
|
|
|
679
688
|
}
|
|
680
689
|
else {
|
|
681
690
|
tracer?.trace('setUserSettings:noToken', {});
|
|
682
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
691
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
683
692
|
success = false;
|
|
684
693
|
}
|
|
685
694
|
}
|
|
@@ -713,14 +722,14 @@ function createCoreRouter() {
|
|
|
713
722
|
const user = await UserModel.findByPk(unAuthData?.id);
|
|
714
723
|
if (!user) {
|
|
715
724
|
tracer?.trace('hostname:userNotFound', {});
|
|
716
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
725
|
+
res.status(400).send(tracer ? tracer.wrapResponse('User not found') : 'User not found');
|
|
717
726
|
return;
|
|
718
727
|
}
|
|
719
|
-
res.status(200).send(tracer ? tracer.wrapResponse(
|
|
728
|
+
res.status(200).send(tracer ? tracer.wrapResponse(user.hostname) : user.hostname);
|
|
720
729
|
}
|
|
721
730
|
else {
|
|
722
731
|
tracer?.trace('hostname:noToken', {});
|
|
723
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
732
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
724
733
|
}
|
|
725
734
|
}
|
|
726
735
|
catch (e) {
|
|
@@ -739,17 +748,17 @@ function createCoreRouter() {
|
|
|
739
748
|
try {
|
|
740
749
|
if (!req.query?.callbackUri || req.query.callbackUri === 'undefined') {
|
|
741
750
|
tracer?.trace('oauth-callback:missingCallbackUri', {});
|
|
742
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
751
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Missing callbackUri') : 'Missing callbackUri');
|
|
743
752
|
return;
|
|
744
753
|
}
|
|
745
754
|
platformName = req.query.state ?
|
|
746
755
|
req.query.state.split('platform=')[1] :
|
|
747
|
-
decodeURIComponent(req.originalUrl).split('state=')[1].split('&')[0].split('platform=')[1];
|
|
756
|
+
decodeURIComponent(decodeURIComponent(req.originalUrl).split('state=')[1].split('&')[0]).split('platform=')[1];
|
|
748
757
|
const hostname = req.query.hostname;
|
|
749
758
|
const tokenUrl = req.query.tokenUrl;
|
|
750
759
|
if (!platformName) {
|
|
751
760
|
tracer?.trace('oauth-callback:missingPlatformName', {});
|
|
752
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
761
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Missing platform name') : 'Missing platform name');
|
|
753
762
|
return;
|
|
754
763
|
}
|
|
755
764
|
const hasAuthCodeInCallbackUri = req.query.callbackUri.includes('code=');
|
|
@@ -761,11 +770,7 @@ function createCoreRouter() {
|
|
|
761
770
|
platform: platformName,
|
|
762
771
|
hostname,
|
|
763
772
|
tokenUrl,
|
|
764
|
-
|
|
765
|
-
apiUrl: req.query.apiUrl,
|
|
766
|
-
username: req.query.username,
|
|
767
|
-
query: req.query,
|
|
768
|
-
proxyId: req.query.proxyId
|
|
773
|
+
query: req.query
|
|
769
774
|
});
|
|
770
775
|
if (userInfo) {
|
|
771
776
|
const jwtToken = jwt.generateJwt({
|
|
@@ -817,12 +822,12 @@ function createCoreRouter() {
|
|
|
817
822
|
const additionalInfo = req.body.additionalInfo;
|
|
818
823
|
if (!platform) {
|
|
819
824
|
tracer?.trace('apiKeyLogin:missingPlatform', {});
|
|
820
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
825
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Missing platform name') : 'Missing platform name');
|
|
821
826
|
return;
|
|
822
827
|
}
|
|
823
828
|
if (!apiKey) {
|
|
824
829
|
tracer?.trace('apiKeyLogin:missingApiKey', {});
|
|
825
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
830
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Missing api key') : 'Missing api key');
|
|
826
831
|
return;
|
|
827
832
|
}
|
|
828
833
|
const { userInfo, returnMessage } = await authCore.onApiKeyLogin({ platform, hostname, apiKey, proxyId, additionalInfo });
|
|
@@ -875,17 +880,17 @@ function createCoreRouter() {
|
|
|
875
880
|
const userToLogout = await UserModel.findByPk(unAuthData?.id);
|
|
876
881
|
if (!userToLogout) {
|
|
877
882
|
tracer?.trace('unAuthorize:userNotFound', {});
|
|
878
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
883
|
+
res.status(400).send(tracer ? tracer.wrapResponse('User not found') : 'User not found');
|
|
879
884
|
return;
|
|
880
885
|
}
|
|
881
886
|
const platformModule = connectorRegistry.getConnector(unAuthData?.platform ?? 'Unknown');
|
|
882
887
|
const { returnMessage } = await platformModule.unAuthorize({ user: userToLogout });
|
|
883
|
-
res.status(200).send(tracer ? tracer.wrapResponse(
|
|
888
|
+
res.status(200).send(tracer ? tracer.wrapResponse(returnMessage) : returnMessage);
|
|
884
889
|
success = true;
|
|
885
890
|
}
|
|
886
891
|
else {
|
|
887
892
|
tracer?.trace('unAuthorize:noToken', {});
|
|
888
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
893
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
889
894
|
success = false;
|
|
890
895
|
}
|
|
891
896
|
}
|
|
@@ -941,12 +946,20 @@ function createCoreRouter() {
|
|
|
941
946
|
tracer?.trace('findContact:jwtDecoded', { decodedToken });
|
|
942
947
|
if (!decodedToken) {
|
|
943
948
|
tracer?.trace('findContact:invalidToken', {});
|
|
944
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
949
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
945
950
|
return;
|
|
946
951
|
}
|
|
947
952
|
const { id: userId, platform } = decodedToken;
|
|
948
953
|
platformName = platform;
|
|
949
|
-
const { successful, returnMessage, contact, extraDataTracking } = await contactCore.findContact({
|
|
954
|
+
const { successful, returnMessage, contact, extraDataTracking } = await contactCore.findContact({
|
|
955
|
+
platform,
|
|
956
|
+
userId,
|
|
957
|
+
phoneNumber: req.query.phoneNumber.replace(' ', '+'),
|
|
958
|
+
overridingFormat: req.query.overridingFormat,
|
|
959
|
+
isExtension: req.query?.isExtension ?? false,
|
|
960
|
+
tracer,
|
|
961
|
+
isForceRefreshAccountData: req.query?.isForceRefreshAccountData === 'true'
|
|
962
|
+
});
|
|
950
963
|
tracer?.trace('findContact:result', { successful, returnMessage, contact });
|
|
951
964
|
res.status(200).send(tracer ? tracer.wrapResponse({ successful, returnMessage, contact }) : { successful, returnMessage, contact });
|
|
952
965
|
if (successful) {
|
|
@@ -960,7 +973,7 @@ function createCoreRouter() {
|
|
|
960
973
|
}
|
|
961
974
|
else {
|
|
962
975
|
tracer?.trace('findContact:noToken', {});
|
|
963
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
976
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
964
977
|
success = false;
|
|
965
978
|
}
|
|
966
979
|
}
|
|
@@ -1004,7 +1017,7 @@ function createCoreRouter() {
|
|
|
1004
1017
|
const decodedToken = jwt.decodeJwt(jwtToken);
|
|
1005
1018
|
if (!decodedToken) {
|
|
1006
1019
|
tracer?.trace('createContact:invalidToken', {});
|
|
1007
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1020
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1008
1021
|
return;
|
|
1009
1022
|
}
|
|
1010
1023
|
const { id: userId, platform } = decodedToken;
|
|
@@ -1018,7 +1031,7 @@ function createCoreRouter() {
|
|
|
1018
1031
|
}
|
|
1019
1032
|
else {
|
|
1020
1033
|
tracer?.trace('createContact:noToken', {});
|
|
1021
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1034
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1022
1035
|
success = false;
|
|
1023
1036
|
}
|
|
1024
1037
|
}
|
|
@@ -1061,7 +1074,7 @@ function createCoreRouter() {
|
|
|
1061
1074
|
const decodedToken = jwt.decodeJwt(jwtToken);
|
|
1062
1075
|
if (!decodedToken) {
|
|
1063
1076
|
tracer?.trace('saveNoteCache:invalidToken', {});
|
|
1064
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1077
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1065
1078
|
return;
|
|
1066
1079
|
}
|
|
1067
1080
|
const { id: userId, platform } = decodedToken;
|
|
@@ -1104,7 +1117,7 @@ function createCoreRouter() {
|
|
|
1104
1117
|
const decodedToken = jwt.decodeJwt(jwtToken);
|
|
1105
1118
|
if (!decodedToken) {
|
|
1106
1119
|
tracer?.trace('getCallLog:invalidToken', {});
|
|
1107
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1120
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1108
1121
|
return;
|
|
1109
1122
|
}
|
|
1110
1123
|
const { id: userId, platform } = decodedToken;
|
|
@@ -1119,7 +1132,7 @@ function createCoreRouter() {
|
|
|
1119
1132
|
}
|
|
1120
1133
|
else {
|
|
1121
1134
|
tracer?.trace('getCallLog:noToken', {});
|
|
1122
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1135
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1123
1136
|
success = false;
|
|
1124
1137
|
}
|
|
1125
1138
|
}
|
|
@@ -1162,7 +1175,7 @@ function createCoreRouter() {
|
|
|
1162
1175
|
const decodedToken = jwt.decodeJwt(jwtToken);
|
|
1163
1176
|
if (!decodedToken) {
|
|
1164
1177
|
tracer?.trace('createCallLog:invalidToken', {});
|
|
1165
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1178
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1166
1179
|
return;
|
|
1167
1180
|
}
|
|
1168
1181
|
const { id: userId, platform } = decodedToken;
|
|
@@ -1176,7 +1189,7 @@ function createCoreRouter() {
|
|
|
1176
1189
|
}
|
|
1177
1190
|
else {
|
|
1178
1191
|
tracer?.trace('createCallLog:noToken', {});
|
|
1179
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1192
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1180
1193
|
success = false;
|
|
1181
1194
|
}
|
|
1182
1195
|
}
|
|
@@ -1219,7 +1232,7 @@ function createCoreRouter() {
|
|
|
1219
1232
|
const decodedToken = jwt.decodeJwt(jwtToken);
|
|
1220
1233
|
if (!decodedToken) {
|
|
1221
1234
|
tracer?.trace('updateCallLog:invalidToken', {});
|
|
1222
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1235
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1223
1236
|
return;
|
|
1224
1237
|
}
|
|
1225
1238
|
const { id: userId, platform } = decodedToken;
|
|
@@ -1233,7 +1246,7 @@ function createCoreRouter() {
|
|
|
1233
1246
|
}
|
|
1234
1247
|
else {
|
|
1235
1248
|
tracer?.trace('updateCallLog:noToken', {});
|
|
1236
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1249
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1237
1250
|
success = false;
|
|
1238
1251
|
}
|
|
1239
1252
|
}
|
|
@@ -1277,7 +1290,7 @@ function createCoreRouter() {
|
|
|
1277
1290
|
platformName = platform;
|
|
1278
1291
|
if (!userId) {
|
|
1279
1292
|
tracer?.trace('upsertCallDisposition:invalidToken', {});
|
|
1280
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1293
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1281
1294
|
return;
|
|
1282
1295
|
}
|
|
1283
1296
|
const { successful, returnMessage, extraDataTracking } = await dispositionCore.upsertCallDisposition({
|
|
@@ -1295,7 +1308,7 @@ function createCoreRouter() {
|
|
|
1295
1308
|
}
|
|
1296
1309
|
else {
|
|
1297
1310
|
tracer?.trace('upsertCallDisposition:noToken', {});
|
|
1298
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1311
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1299
1312
|
success = false;
|
|
1300
1313
|
}
|
|
1301
1314
|
}
|
|
@@ -1339,7 +1352,7 @@ function createCoreRouter() {
|
|
|
1339
1352
|
const decodedToken = jwt.decodeJwt(jwtToken);
|
|
1340
1353
|
if (!decodedToken) {
|
|
1341
1354
|
tracer?.trace('createMessageLog:invalidToken', {});
|
|
1342
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1355
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1343
1356
|
return;
|
|
1344
1357
|
}
|
|
1345
1358
|
const { id: userId, platform } = decodedToken;
|
|
@@ -1353,7 +1366,7 @@ function createCoreRouter() {
|
|
|
1353
1366
|
}
|
|
1354
1367
|
else {
|
|
1355
1368
|
tracer?.trace('createMessageLog:noToken', {});
|
|
1356
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1369
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1357
1370
|
success = false;
|
|
1358
1371
|
}
|
|
1359
1372
|
}
|
|
@@ -1395,7 +1408,7 @@ function createCoreRouter() {
|
|
|
1395
1408
|
const jwtToken = req.query.jwtToken;
|
|
1396
1409
|
if (!jwtToken) {
|
|
1397
1410
|
tracer?.trace('scheduleCallDown:noToken', {});
|
|
1398
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1411
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1399
1412
|
return;
|
|
1400
1413
|
}
|
|
1401
1414
|
const { id } = await calldown.schedule({ jwtToken, rcAccessToken: req.query.rcAccessToken, body: req.body });
|
|
@@ -1438,7 +1451,7 @@ function createCoreRouter() {
|
|
|
1438
1451
|
const jwtToken = req.query.jwtToken;
|
|
1439
1452
|
if (!jwtToken) {
|
|
1440
1453
|
tracer?.trace('getCallDownList:noToken', {});
|
|
1441
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1454
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1442
1455
|
return;
|
|
1443
1456
|
}
|
|
1444
1457
|
const { items } = await calldown.list({ jwtToken, status: req.query.status });
|
|
@@ -1480,13 +1493,13 @@ function createCoreRouter() {
|
|
|
1480
1493
|
const id = req.query.id;
|
|
1481
1494
|
if (!jwtToken) {
|
|
1482
1495
|
tracer?.trace('deleteCallDownItem:noToken', {});
|
|
1483
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1496
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1484
1497
|
return;
|
|
1485
1498
|
}
|
|
1486
1499
|
const rid = req.params.id || id;
|
|
1487
1500
|
if (!rid) {
|
|
1488
1501
|
tracer?.trace('deleteCallDownItem:missingId', {});
|
|
1489
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1502
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Missing id') : 'Missing id');
|
|
1490
1503
|
return;
|
|
1491
1504
|
}
|
|
1492
1505
|
await calldown.remove({ jwtToken, id: rid });
|
|
@@ -1527,13 +1540,13 @@ function createCoreRouter() {
|
|
|
1527
1540
|
const jwtToken = req.query.jwtToken;
|
|
1528
1541
|
if (!jwtToken) {
|
|
1529
1542
|
tracer?.trace('markCallDownCalled:noToken', {});
|
|
1530
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1543
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1531
1544
|
return;
|
|
1532
1545
|
}
|
|
1533
1546
|
const id = req.params.id || req.body?.id;
|
|
1534
1547
|
if (!id) {
|
|
1535
1548
|
tracer?.trace('markCallDownCalled:missingId', {});
|
|
1536
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1549
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Missing id') : 'Missing id');
|
|
1537
1550
|
return;
|
|
1538
1551
|
}
|
|
1539
1552
|
await calldown.update({ jwtToken, id, updateData: req.body });
|
|
@@ -1582,7 +1595,7 @@ function createCoreRouter() {
|
|
|
1582
1595
|
}
|
|
1583
1596
|
else {
|
|
1584
1597
|
tracer?.trace('contactSearchByName:noToken', {});
|
|
1585
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1598
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Please go to Settings and authorize CRM platform') : 'Please go to Settings and authorize CRM platform');
|
|
1586
1599
|
success = false;
|
|
1587
1600
|
}
|
|
1588
1601
|
|
|
@@ -1625,7 +1638,7 @@ function createCoreRouter() {
|
|
|
1625
1638
|
const user = await UserModel.findByPk(unAuthData?.id);
|
|
1626
1639
|
if (!user) {
|
|
1627
1640
|
tracer?.trace('getAdminReport:userNotFound', {});
|
|
1628
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1641
|
+
res.status(400).send(tracer ? tracer.wrapResponse('User not found') : 'User not found');
|
|
1629
1642
|
return;
|
|
1630
1643
|
}
|
|
1631
1644
|
const report = await adminCore.getAdminReport({ rcAccountId: user.rcAccountId, timezone: req.query.timezone, timeFrom: req.query.timeFrom, timeTo: req.query.timeTo, groupBy: req.query.groupBy });
|
|
@@ -1634,7 +1647,7 @@ function createCoreRouter() {
|
|
|
1634
1647
|
return;
|
|
1635
1648
|
}
|
|
1636
1649
|
tracer?.trace('getAdminReport:invalidRequest', {});
|
|
1637
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1650
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Invalid request') : 'Invalid request');
|
|
1638
1651
|
success = false;
|
|
1639
1652
|
}
|
|
1640
1653
|
catch (e) {
|
|
@@ -1671,7 +1684,7 @@ function createCoreRouter() {
|
|
|
1671
1684
|
const user = await UserModel.findByPk(unAuthData?.id);
|
|
1672
1685
|
if (!user) {
|
|
1673
1686
|
tracer?.trace('getUserReport:userNotFound', {});
|
|
1674
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1687
|
+
res.status(400).send(tracer ? tracer.wrapResponse('User not found') : 'User not found');
|
|
1675
1688
|
return;
|
|
1676
1689
|
}
|
|
1677
1690
|
const report = await adminCore.getUserReport({ rcAccountId: user.rcAccountId, rcExtensionId: req.query.rcExtensionId, timezone: req.query.timezone, timeFrom: req.query.timeFrom, timeTo: req.query.timeTo });
|
|
@@ -1679,7 +1692,7 @@ function createCoreRouter() {
|
|
|
1679
1692
|
return;
|
|
1680
1693
|
}
|
|
1681
1694
|
tracer?.trace('getUserReport:invalidRequest', {});
|
|
1682
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1695
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Invalid request') : 'Invalid request');
|
|
1683
1696
|
success = false;
|
|
1684
1697
|
}
|
|
1685
1698
|
catch (e) {
|
|
@@ -1712,7 +1725,7 @@ function createCoreRouter() {
|
|
|
1712
1725
|
const user = await UserModel.findByPk(unAuthData?.id);
|
|
1713
1726
|
if (!user) {
|
|
1714
1727
|
tracer?.trace('onRingcentralOAuthCallback:userNotFound', {});
|
|
1715
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1728
|
+
res.status(400).send(tracer ? tracer.wrapResponse('User not found') : 'User not found');
|
|
1716
1729
|
return;
|
|
1717
1730
|
}
|
|
1718
1731
|
await authCore.onRingcentralOAuthCallback({ code, rcAccountId: user.rcAccountId });
|
|
@@ -1720,7 +1733,7 @@ function createCoreRouter() {
|
|
|
1720
1733
|
return;
|
|
1721
1734
|
}
|
|
1722
1735
|
tracer?.trace('onRingcentralOAuthCallback:invalidRequest', {});
|
|
1723
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1736
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Invalid request') : 'Invalid request');
|
|
1724
1737
|
});
|
|
1725
1738
|
router.get('/debug/report/url', async function (req, res) {
|
|
1726
1739
|
const requestStartTime = new Date().getTime();
|
|
@@ -1738,7 +1751,7 @@ function createCoreRouter() {
|
|
|
1738
1751
|
}
|
|
1739
1752
|
else {
|
|
1740
1753
|
tracer?.trace('getErrorLogReportURL:invalidRequest', {});
|
|
1741
|
-
res.status(400).send(tracer ? tracer.wrapResponse(
|
|
1754
|
+
res.status(400).send(tracer ? tracer.wrapResponse('Invalid request') : 'Invalid request');
|
|
1742
1755
|
success = false;
|
|
1743
1756
|
}
|
|
1744
1757
|
const requestEndTime = new Date().getTime();
|
|
@@ -1817,6 +1830,15 @@ function createCoreRouter() {
|
|
|
1817
1830
|
function createCoreMiddleware() {
|
|
1818
1831
|
return [
|
|
1819
1832
|
bodyParser.json(),
|
|
1833
|
+
bodyParser.xml({
|
|
1834
|
+
limit: '50mb',
|
|
1835
|
+
xmlParseOptions: {
|
|
1836
|
+
explicitArray: false,
|
|
1837
|
+
normalize: true,
|
|
1838
|
+
normalizeTags: false,
|
|
1839
|
+
trim: true
|
|
1840
|
+
}
|
|
1841
|
+
}),
|
|
1820
1842
|
cors({
|
|
1821
1843
|
methods: ['GET', 'POST', 'PATCH', 'PUT', 'DELETE']
|
|
1822
1844
|
})
|