@app-connect/core 1.7.20 → 1.7.21

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.
@@ -80,7 +80,8 @@ async function findContact({ platform, userId, phoneNumber, overridingFormat, is
80
80
  const { successful, matchedContactInfo, returnMessage, extraDataTracking } = await platformModule.findContact({ user, authHeader, phoneNumber, overridingFormat, isExtension, proxyConfig, tracer, isForceRefreshAccountData });
81
81
  tracer?.trace('handler.findContact:platformFindResult', { successful, matchedContactInfo });
82
82
 
83
- if (matchedContactInfo != null && matchedContactInfo?.filter(c => !c.isNewContact)?.length > 0) {
83
+ const matchedNonNewContacts = matchedContactInfo?.filter(c => !c.isNewContact) ?? [];
84
+ if (matchedContactInfo != null && matchedNonNewContacts.length > 0) {
84
85
  tracer?.trace('handler.findContact:contactsFound', { count: matchedContactInfo.length });
85
86
  // save in org data
86
87
  // Danger: it does NOT support one RC account mapping to multiple CRM platforms, because contacts will be shared
@@ -104,6 +105,10 @@ async function findContact({ platform, userId, phoneNumber, overridingFormat, is
104
105
  }
105
106
  else {
106
107
  tracer?.trace('handler.findContact:noContactsMatched', { matchedContactInfo });
108
+ if (isForceRefreshAccountData && existingMatchedContactInfo) {
109
+ await existingMatchedContactInfo.destroy();
110
+ tracer?.trace('handler.findContact:staleCacheRemoved', { phoneNumber });
111
+ }
107
112
  if (returnMessage) {
108
113
  return {
109
114
  successful,
@@ -272,4 +277,4 @@ async function findContactWithName({ platform, userId, name }) {
272
277
 
273
278
  exports.findContact = findContact;
274
279
  exports.createContact = createContact;
275
- exports.findContactWithName = findContactWithName;
280
+ exports.findContactWithName = findContactWithName;
package/index.js CHANGED
@@ -967,12 +967,7 @@ function createCoreRouter() {
967
967
  res.status(400).send(tracer ? tracer.wrapResponse('Missing platform name') : 'Missing platform name');
968
968
  return;
969
969
  }
970
- if (!apiKey) {
971
- tracer?.trace('apiKeyLogin:missingApiKey', {});
972
- res.status(400).send(tracer ? tracer.wrapResponse('Missing api key') : 'Missing api key');
973
- return;
974
- }
975
- const { userInfo, returnMessage } = await authCore.onApiKeyLogin({ platform, hostname, apiKey, proxyId, rcAccountId: query.rcAccountId, hashedRcExtensionId: hashedExtensionId, additionalInfo });
970
+ const { userInfo, returnMessage } = await authCore.onApiKeyLogin({ platform, hostname, apiKey, proxyId, rcAccountId: req.body.rcAccountId, hashedRcExtensionId: hashedExtensionId, additionalInfo });
976
971
  if (userInfo) {
977
972
  const jwtToken = jwt.generateJwt({
978
973
  id: userInfo.id.toString(),
package/package.json CHANGED
@@ -1,72 +1,72 @@
1
- {
2
- "name": "@app-connect/core",
3
- "version": "1.7.20",
4
- "description": "RingCentral App Connect Core",
5
- "main": "index.js",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/ringcentral/rc-unified-crm-extension.git"
9
- },
10
- "keywords": [
11
- "RingCentral",
12
- "App Connect"
13
- ],
14
- "author": "RingCentral Labs",
15
- "license": "MIT",
16
- "peerDependencies": {
17
- "axios": "^1.12.2",
18
- "express": "^4.22.1",
19
- "moment": "^2.29.4",
20
- "moment-timezone": "^0.5.39",
21
- "pg": "^8.8.0",
22
- "sequelize": "^6.29.0"
23
- },
24
- "dependencies": {
25
- "@aws-sdk/client-dynamodb": "^3.751.0",
26
- "@aws-sdk/client-s3": "^3.947.0",
27
- "@aws-sdk/s3-request-presigner": "^3.947.0",
28
- "@modelcontextprotocol/sdk": "^1.26.0",
29
- "awesome-phonenumber": "^5.6.0",
30
- "body-parser": "^1.20.4",
31
- "body-parser-xml": "^2.0.5",
32
- "client-oauth2": "^4.3.3",
33
- "cors": "^2.8.5",
34
- "country-state-city": "^3.2.1",
35
- "dotenv": "^16.0.3",
36
- "dynamoose": "^4.0.3",
37
- "jsonwebtoken": "^9.0.0",
38
- "mixpanel": "^0.18.0",
39
- "shortid": "^2.2.17",
40
- "tz-lookup": "^6.1.25",
41
- "ua-parser-js": "^1.0.38"
42
- },
43
- "scripts": {
44
- "test": "jest",
45
- "test:watch": "jest --watch",
46
- "test:coverage": "jest --coverage",
47
- "test:ci": "jest --ci --coverage --watchAll=false"
48
- },
49
- "devDependencies": {
50
- "@eslint/js": "^9.22.0",
51
- "@octokit/rest": "^19.0.5",
52
- "axios": "^1.12.2",
53
- "eslint": "^9.22.0",
54
- "express": "^4.22.1",
55
- "globals": "^16.0.0",
56
- "jest": "^29.3.1",
57
- "moment": "^2.29.4",
58
- "moment-timezone": "^0.5.39",
59
- "nock": "^13.2.9",
60
- "pg": "^8.8.0",
61
- "sequelize": "^6.29.0",
62
- "sqlite3": "^5.1.2",
63
- "supertest": "^6.3.1"
64
- },
65
- "overrides": {
66
- "js-object-utilities": "2.2.1"
67
- },
68
- "bugs": {
69
- "url": "https://github.com/ringcentral/rc-unified-crm-extension/issues"
70
- },
71
- "homepage": "https://github.com/ringcentral/rc-unified-crm-extension#readme"
72
- }
1
+ {
2
+ "name": "@app-connect/core",
3
+ "version": "1.7.21",
4
+ "description": "RingCentral App Connect Core",
5
+ "main": "index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/ringcentral/rc-unified-crm-extension.git"
9
+ },
10
+ "keywords": [
11
+ "RingCentral",
12
+ "App Connect"
13
+ ],
14
+ "author": "RingCentral Labs",
15
+ "license": "MIT",
16
+ "peerDependencies": {
17
+ "axios": "^1.12.2",
18
+ "express": "^4.22.1",
19
+ "moment": "^2.29.4",
20
+ "moment-timezone": "^0.5.39",
21
+ "pg": "^8.8.0",
22
+ "sequelize": "^6.29.0"
23
+ },
24
+ "dependencies": {
25
+ "@aws-sdk/client-dynamodb": "^3.751.0",
26
+ "@aws-sdk/client-s3": "^3.947.0",
27
+ "@aws-sdk/s3-request-presigner": "^3.947.0",
28
+ "@modelcontextprotocol/sdk": "^1.26.0",
29
+ "awesome-phonenumber": "^5.6.0",
30
+ "body-parser": "^1.20.4",
31
+ "body-parser-xml": "^2.0.5",
32
+ "client-oauth2": "^4.3.3",
33
+ "cors": "^2.8.5",
34
+ "country-state-city": "^3.2.1",
35
+ "dotenv": "^16.0.3",
36
+ "dynamoose": "^4.0.3",
37
+ "jsonwebtoken": "^9.0.0",
38
+ "mixpanel": "^0.18.0",
39
+ "shortid": "^2.2.17",
40
+ "tz-lookup": "^6.1.25",
41
+ "ua-parser-js": "^1.0.38"
42
+ },
43
+ "scripts": {
44
+ "test": "jest",
45
+ "test:watch": "jest --watch",
46
+ "test:coverage": "jest --coverage",
47
+ "test:ci": "jest --ci --coverage --watchAll=false"
48
+ },
49
+ "devDependencies": {
50
+ "@eslint/js": "^9.22.0",
51
+ "@octokit/rest": "^19.0.5",
52
+ "axios": "^1.12.2",
53
+ "eslint": "^9.22.0",
54
+ "express": "^4.22.1",
55
+ "globals": "^16.0.0",
56
+ "jest": "^29.3.1",
57
+ "moment": "^2.29.4",
58
+ "moment-timezone": "^0.5.39",
59
+ "nock": "^13.2.9",
60
+ "pg": "^8.8.0",
61
+ "sequelize": "^6.29.0",
62
+ "sqlite3": "^5.1.2",
63
+ "supertest": "^6.3.1"
64
+ },
65
+ "overrides": {
66
+ "js-object-utilities": "2.2.1"
67
+ },
68
+ "bugs": {
69
+ "url": "https://github.com/ringcentral/rc-unified-crm-extension/issues"
70
+ },
71
+ "homepage": "https://github.com/ringcentral/rc-unified-crm-extension#readme"
72
+ }
package/releaseNotes.json CHANGED
@@ -1,4 +1,16 @@
1
1
  {
2
+ "1.7.21": {
3
+ "global": [
4
+ {
5
+ "type": "Fix",
6
+ "description": "Refresh contact for deleted contact issue"
7
+ },
8
+ {
9
+ "type": "Fix",
10
+ "description": "Click-to-sms button issue"
11
+ }
12
+ ]
13
+ },
2
14
  "1.7.20": {
3
15
  "global": [
4
16
  {
@@ -436,6 +436,168 @@ describe('Contact Handler', () => {
436
436
  expect(cachedData.data).toEqual(updatedContact);
437
437
  });
438
438
 
439
+ test('should remove cached contact when force refresh returns null', async () => {
440
+ // Arrange
441
+ await UserModel.create(mockUser);
442
+ await AccountDataModel.create({
443
+ rcAccountId: 'rc-account-123',
444
+ platformName: 'testCRM',
445
+ dataKey: 'contact-+3333333333',
446
+ data: [{ id: 'stale-contact', name: 'Stale Contact' }]
447
+ });
448
+
449
+ const mockConnector = {
450
+ getAuthType: jest.fn().mockResolvedValue('apiKey'),
451
+ getBasicAuth: jest.fn().mockReturnValue('base64-encoded'),
452
+ findContact: jest.fn().mockResolvedValue({
453
+ successful: false,
454
+ matchedContactInfo: null
455
+ })
456
+ };
457
+ connectorRegistry.getConnector.mockReturnValue(mockConnector);
458
+
459
+ // Act
460
+ const result = await contactHandler.findContact({
461
+ platform: 'testCRM',
462
+ userId: 'test-user-id',
463
+ phoneNumber: '+3333333333',
464
+ isForceRefreshAccountData: true
465
+ });
466
+
467
+ // Assert
468
+ expect(result.successful).toBe(false);
469
+ const cachedData = await AccountDataModel.findOne({
470
+ where: {
471
+ rcAccountId: 'rc-account-123',
472
+ platformName: 'testCRM',
473
+ dataKey: 'contact-+3333333333'
474
+ }
475
+ });
476
+ expect(cachedData).toBeNull();
477
+ });
478
+
479
+ test('should remove cached contact when force refresh returns empty array', async () => {
480
+ // Arrange
481
+ await UserModel.create(mockUser);
482
+ await AccountDataModel.create({
483
+ rcAccountId: 'rc-account-123',
484
+ platformName: 'testCRM',
485
+ dataKey: 'contact-+1212121212',
486
+ data: [{ id: 'stale-contact', name: 'Stale Contact' }]
487
+ });
488
+
489
+ const mockConnector = {
490
+ getAuthType: jest.fn().mockResolvedValue('apiKey'),
491
+ getBasicAuth: jest.fn().mockReturnValue('base64-encoded'),
492
+ findContact: jest.fn().mockResolvedValue({
493
+ successful: false,
494
+ matchedContactInfo: []
495
+ })
496
+ };
497
+ connectorRegistry.getConnector.mockReturnValue(mockConnector);
498
+
499
+ // Act
500
+ await contactHandler.findContact({
501
+ platform: 'testCRM',
502
+ userId: 'test-user-id',
503
+ phoneNumber: '+1212121212',
504
+ isForceRefreshAccountData: true
505
+ });
506
+
507
+ // Assert
508
+ const cachedData = await AccountDataModel.findOne({
509
+ where: {
510
+ rcAccountId: 'rc-account-123',
511
+ platformName: 'testCRM',
512
+ dataKey: 'contact-+1212121212'
513
+ }
514
+ });
515
+ expect(cachedData).toBeNull();
516
+ });
517
+
518
+ test('should remove cached contact when force refresh returns only new contact placeholder', async () => {
519
+ // Arrange
520
+ await UserModel.create(mockUser);
521
+ await AccountDataModel.create({
522
+ rcAccountId: 'rc-account-123',
523
+ platformName: 'testCRM',
524
+ dataKey: 'contact-+3434343434',
525
+ data: [{ id: 'stale-contact', name: 'Stale Contact' }]
526
+ });
527
+
528
+ const placeholderContact = [
529
+ { id: 'new-contact', name: 'Create Contact', isNewContact: true }
530
+ ];
531
+ const mockConnector = {
532
+ getAuthType: jest.fn().mockResolvedValue('apiKey'),
533
+ getBasicAuth: jest.fn().mockReturnValue('base64-encoded'),
534
+ findContact: jest.fn().mockResolvedValue({
535
+ successful: false,
536
+ matchedContactInfo: placeholderContact
537
+ })
538
+ };
539
+ connectorRegistry.getConnector.mockReturnValue(mockConnector);
540
+
541
+ // Act
542
+ const result = await contactHandler.findContact({
543
+ platform: 'testCRM',
544
+ userId: 'test-user-id',
545
+ phoneNumber: '+3434343434',
546
+ isForceRefreshAccountData: true
547
+ });
548
+
549
+ // Assert
550
+ expect(result.contact).toEqual(placeholderContact);
551
+ const cachedData = await AccountDataModel.findOne({
552
+ where: {
553
+ rcAccountId: 'rc-account-123',
554
+ platformName: 'testCRM',
555
+ dataKey: 'contact-+3434343434'
556
+ }
557
+ });
558
+ expect(cachedData).toBeNull();
559
+ });
560
+
561
+ test('should keep cached contact when force refresh connector call errors', async () => {
562
+ // Arrange
563
+ await UserModel.create(mockUser);
564
+ await AccountDataModel.create({
565
+ rcAccountId: 'rc-account-123',
566
+ platformName: 'testCRM',
567
+ dataKey: 'contact-+5656565656',
568
+ data: [{ id: 'stale-contact', name: 'Stale Contact' }]
569
+ });
570
+
571
+ const mockConnector = {
572
+ getAuthType: jest.fn().mockResolvedValue('apiKey'),
573
+ getBasicAuth: jest.fn().mockReturnValue('base64-encoded'),
574
+ findContact: jest.fn().mockRejectedValue({
575
+ response: { status: 500 }
576
+ })
577
+ };
578
+ connectorRegistry.getConnector.mockReturnValue(mockConnector);
579
+
580
+ // Act
581
+ const result = await contactHandler.findContact({
582
+ platform: 'testCRM',
583
+ userId: 'test-user-id',
584
+ phoneNumber: '+5656565656',
585
+ isForceRefreshAccountData: true
586
+ });
587
+
588
+ // Assert
589
+ expect(result.successful).toBe(false);
590
+ const cachedData = await AccountDataModel.findOne({
591
+ where: {
592
+ rcAccountId: 'rc-account-123',
593
+ platformName: 'testCRM',
594
+ dataKey: 'contact-+5656565656'
595
+ }
596
+ });
597
+ expect(cachedData).not.toBeNull();
598
+ expect(cachedData.data).toEqual([{ id: 'stale-contact', name: 'Stale Contact' }]);
599
+ });
600
+
439
601
  test('should work with tracer when provided', async () => {
440
602
  // Arrange
441
603
  await UserModel.create(mockUser);