@app-connect/core 1.7.10 → 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.
Files changed (55) hide show
  1. package/connector/developerPortal.js +43 -0
  2. package/connector/proxy/index.js +10 -3
  3. package/connector/registry.js +8 -6
  4. package/handlers/admin.js +44 -21
  5. package/handlers/auth.js +89 -67
  6. package/handlers/calldown.js +10 -4
  7. package/handlers/contact.js +4 -104
  8. package/handlers/disposition.js +4 -142
  9. package/handlers/log.js +172 -257
  10. package/handlers/user.js +19 -6
  11. package/index.js +213 -47
  12. package/lib/analytics.js +3 -1
  13. package/lib/authSession.js +68 -0
  14. package/lib/callLogComposer.js +498 -420
  15. package/lib/errorHandler.js +206 -0
  16. package/lib/jwt.js +2 -0
  17. package/lib/logger.js +190 -0
  18. package/lib/oauth.js +21 -10
  19. package/lib/ringcentral.js +2 -10
  20. package/lib/sharedSMSComposer.js +471 -0
  21. package/mcp/SupportedPlatforms.md +12 -0
  22. package/mcp/lib/validator.js +91 -0
  23. package/mcp/mcpHandler.js +166 -0
  24. package/mcp/tools/checkAuthStatus.js +90 -0
  25. package/mcp/tools/collectAuthInfo.js +86 -0
  26. package/mcp/tools/createCallLog.js +299 -0
  27. package/mcp/tools/createMessageLog.js +283 -0
  28. package/mcp/tools/doAuth.js +185 -0
  29. package/mcp/tools/findContactByName.js +87 -0
  30. package/mcp/tools/findContactByPhone.js +96 -0
  31. package/mcp/tools/getCallLog.js +98 -0
  32. package/mcp/tools/getHelp.js +39 -0
  33. package/mcp/tools/getPublicConnectors.js +46 -0
  34. package/mcp/tools/index.js +58 -0
  35. package/mcp/tools/logout.js +63 -0
  36. package/mcp/tools/rcGetCallLogs.js +73 -0
  37. package/mcp/tools/setConnector.js +64 -0
  38. package/mcp/tools/updateCallLog.js +122 -0
  39. package/models/cacheModel.js +3 -0
  40. package/package.json +71 -70
  41. package/releaseNotes.json +12 -0
  42. package/test/handlers/log.test.js +6 -2
  43. package/test/lib/logger.test.js +206 -0
  44. package/test/lib/sharedSMSComposer.test.js +1084 -0
  45. package/test/mcp/tools/collectAuthInfo.test.js +192 -0
  46. package/test/mcp/tools/createCallLog.test.js +412 -0
  47. package/test/mcp/tools/createMessageLog.test.js +580 -0
  48. package/test/mcp/tools/doAuth.test.js +363 -0
  49. package/test/mcp/tools/findContactByName.test.js +263 -0
  50. package/test/mcp/tools/findContactByPhone.test.js +284 -0
  51. package/test/mcp/tools/getCallLog.test.js +286 -0
  52. package/test/mcp/tools/getPublicConnectors.test.js +128 -0
  53. package/test/mcp/tools/logout.test.js +169 -0
  54. package/test/mcp/tools/setConnector.test.js +177 -0
  55. package/test/mcp/tools/updateCallLog.test.js +346 -0
package/package.json CHANGED
@@ -1,70 +1,71 @@
1
- {
2
- "name": "@app-connect/core",
3
- "version": "1.7.10",
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
- "body-parser": "^1.20.4",
29
- "body-parser-xml": "^2.0.5",
30
- "client-oauth2": "^4.3.3",
31
- "cors": "^2.8.5",
32
- "country-state-city": "^3.2.1",
33
- "dotenv": "^16.0.3",
34
- "dynamoose": "^4.0.3",
35
- "jsonwebtoken": "^9.0.0",
36
- "mixpanel": "^0.18.0",
37
- "shortid": "^2.2.17",
38
- "tz-lookup": "^6.1.25",
39
- "ua-parser-js": "^1.0.38"
40
- },
41
- "scripts": {
42
- "test": "jest",
43
- "test:watch": "jest --watch",
44
- "test:coverage": "jest --coverage",
45
- "test:ci": "jest --ci --coverage --watchAll=false"
46
- },
47
- "devDependencies": {
48
- "@eslint/js": "^9.22.0",
49
- "@octokit/rest": "^19.0.5",
50
- "axios": "^1.12.2",
51
- "eslint": "^9.22.0",
52
- "express": "^4.22.1",
53
- "globals": "^16.0.0",
54
- "jest": "^29.3.1",
55
- "moment": "^2.29.4",
56
- "moment-timezone": "^0.5.39",
57
- "nock": "^13.2.9",
58
- "pg": "^8.8.0",
59
- "sequelize": "^6.29.0",
60
- "sqlite3": "^5.1.2",
61
- "supertest": "^6.3.1"
62
- },
63
- "overrides": {
64
- "js-object-utilities": "2.2.1"
65
- },
66
- "bugs": {
67
- "url": "https://github.com/ringcentral/rc-unified-crm-extension/issues"
68
- },
69
- "homepage": "https://github.com/ringcentral/rc-unified-crm-extension#readme"
70
- }
1
+ {
2
+ "name": "@app-connect/core",
3
+ "version": "1.7.11",
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
+ "@modelcontextprotocol/sdk": "^1.21.1",
27
+ "@aws-sdk/client-s3": "^3.947.0",
28
+ "@aws-sdk/s3-request-presigner": "^3.947.0",
29
+ "body-parser": "^1.20.4",
30
+ "body-parser-xml": "^2.0.5",
31
+ "client-oauth2": "^4.3.3",
32
+ "cors": "^2.8.5",
33
+ "country-state-city": "^3.2.1",
34
+ "dotenv": "^16.0.3",
35
+ "dynamoose": "^4.0.3",
36
+ "jsonwebtoken": "^9.0.0",
37
+ "mixpanel": "^0.18.0",
38
+ "shortid": "^2.2.17",
39
+ "tz-lookup": "^6.1.25",
40
+ "ua-parser-js": "^1.0.38"
41
+ },
42
+ "scripts": {
43
+ "test": "jest",
44
+ "test:watch": "jest --watch",
45
+ "test:coverage": "jest --coverage",
46
+ "test:ci": "jest --ci --coverage --watchAll=false"
47
+ },
48
+ "devDependencies": {
49
+ "@eslint/js": "^9.22.0",
50
+ "@octokit/rest": "^19.0.5",
51
+ "axios": "^1.12.2",
52
+ "eslint": "^9.22.0",
53
+ "express": "^4.22.1",
54
+ "globals": "^16.0.0",
55
+ "jest": "^29.3.1",
56
+ "moment": "^2.29.4",
57
+ "moment-timezone": "^0.5.39",
58
+ "nock": "^13.2.9",
59
+ "pg": "^8.8.0",
60
+ "sequelize": "^6.29.0",
61
+ "sqlite3": "^5.1.2",
62
+ "supertest": "^6.3.1"
63
+ },
64
+ "overrides": {
65
+ "js-object-utilities": "2.2.1"
66
+ },
67
+ "bugs": {
68
+ "url": "https://github.com/ringcentral/rc-unified-crm-extension/issues"
69
+ },
70
+ "homepage": "https://github.com/ringcentral/rc-unified-crm-extension#readme"
71
+ }
package/releaseNotes.json CHANGED
@@ -1,4 +1,16 @@
1
1
  {
2
+ "1.7.11": {
3
+ "global": [
4
+ {
5
+ "type": "New",
6
+ "description": "Shared-SMS logging"
7
+ },
8
+ {
9
+ "type": "New",
10
+ "description": "MCP tools"
11
+ }
12
+ ]
13
+ },
2
14
  "1.7.10": {
3
15
  "global": [
4
16
  {
@@ -705,6 +705,9 @@ describe('Log Handler', () => {
705
705
  createMessageLog: jest.fn().mockResolvedValue({
706
706
  logId: 'msg-log-new',
707
707
  returnMessage: { message: 'Message logged', messageType: 'success', ttl: 2000 }
708
+ }),
709
+ updateMessageLog: jest.fn().mockResolvedValue({
710
+ returnMessage: { message: 'Message updated', messageType: 'success', ttl: 2000 }
708
711
  })
709
712
  };
710
713
  connectorRegistry.getConnector.mockReturnValue(mockConnector);
@@ -733,8 +736,9 @@ describe('Log Handler', () => {
733
736
 
734
737
  // Assert
735
738
  expect(result.successful).toBe(true);
736
- // Only the new message should be logged
737
- expect(mockConnector.createMessageLog).toHaveBeenCalledTimes(1);
739
+ // msg-1 is skipped (already logged), msg-2 uses updateMessageLog because same conversationId exists
740
+ expect(mockConnector.createMessageLog).toHaveBeenCalledTimes(0);
741
+ expect(mockConnector.updateMessageLog).toHaveBeenCalledTimes(1);
738
742
  });
739
743
  });
740
744
 
@@ -0,0 +1,206 @@
1
+ const { Logger, LOG_LEVELS } = require('../../lib/logger');
2
+
3
+ describe('Logger', () => {
4
+ let originalEnv;
5
+ let consoleSpy;
6
+ let consoleErrorSpy;
7
+
8
+ beforeEach(() => {
9
+ originalEnv = process.env.NODE_ENV;
10
+ consoleSpy = jest.spyOn(console, 'log').mockImplementation();
11
+ consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
12
+ });
13
+
14
+ afterEach(() => {
15
+ process.env.NODE_ENV = originalEnv;
16
+ consoleSpy.mockRestore();
17
+ consoleErrorSpy.mockRestore();
18
+ });
19
+
20
+ describe('Log Levels', () => {
21
+ test('should only log messages at or above the configured level', () => {
22
+ const logger = new Logger({ level: 'WARN' });
23
+
24
+ logger.debug('debug message');
25
+ logger.info('info message');
26
+ logger.warn('warn message');
27
+ logger.error('error message');
28
+
29
+ // Only warn and error should be logged
30
+ expect(consoleSpy).not.toHaveBeenCalled();
31
+ expect(consoleErrorSpy).toHaveBeenCalledTimes(2);
32
+ });
33
+
34
+ test('should log all messages when level is DEBUG', () => {
35
+ const logger = new Logger({ level: 'DEBUG' });
36
+
37
+ logger.debug('debug message');
38
+ logger.info('info message');
39
+ logger.warn('warn message');
40
+ logger.error('error message');
41
+
42
+ expect(consoleSpy).toHaveBeenCalledTimes(2); // debug and info
43
+ expect(consoleErrorSpy).toHaveBeenCalledTimes(2); // warn and error
44
+ });
45
+ });
46
+
47
+ describe('Production vs Development', () => {
48
+ test('should output JSON in production', () => {
49
+ process.env.NODE_ENV = 'production';
50
+ const logger = new Logger({ level: 'INFO' });
51
+
52
+ logger.info('test message', { userId: '123' });
53
+
54
+ const logOutput = consoleSpy.mock.calls[0][0];
55
+ const parsed = JSON.parse(logOutput);
56
+
57
+ expect(parsed).toHaveProperty('timestamp');
58
+ expect(parsed).toHaveProperty('level', 'INFO');
59
+ expect(parsed).toHaveProperty('message', 'test message');
60
+ expect(parsed).toHaveProperty('userId', '123');
61
+ });
62
+
63
+ test('should output human-readable format in development', () => {
64
+ process.env.NODE_ENV = 'development';
65
+ const logger = new Logger({ level: 'INFO' });
66
+
67
+ logger.info('test message', { userId: '123' });
68
+
69
+ const logOutput = consoleSpy.mock.calls[0][0];
70
+ expect(logOutput).toContain('[INFO]');
71
+ expect(logOutput).toContain('test message');
72
+ });
73
+ });
74
+
75
+ describe('Error Handling', () => {
76
+ test('should extract error information from Error objects', () => {
77
+ process.env.NODE_ENV = 'production';
78
+ const logger = new Logger({ level: 'ERROR' });
79
+ const error = new Error('Test error');
80
+ error.response = {
81
+ status: 500,
82
+ data: { message: 'Server error' },
83
+ };
84
+
85
+ logger.error('Operation failed', { error });
86
+
87
+ const logOutput = consoleErrorSpy.mock.calls[0][0];
88
+ const parsed = JSON.parse(logOutput);
89
+
90
+ expect(parsed).toHaveProperty('errorMessage', 'Test error');
91
+ expect(parsed).toHaveProperty('errorStack');
92
+ expect(parsed).toHaveProperty('errorStatus', 500);
93
+ expect(parsed).toHaveProperty('errorResponse');
94
+ expect(parsed).not.toHaveProperty('error'); // Should be removed
95
+ });
96
+ });
97
+
98
+ describe('Child Logger', () => {
99
+ test('should create child logger with default context', () => {
100
+ process.env.NODE_ENV = 'production';
101
+ const logger = new Logger({ level: 'INFO' });
102
+ const childLogger = logger.child({ platform: 'clio', userId: '123' });
103
+
104
+ childLogger.info('test message', { operation: 'createLog' });
105
+
106
+ const logOutput = consoleSpy.mock.calls[0][0];
107
+ const parsed = JSON.parse(logOutput);
108
+
109
+ expect(parsed).toHaveProperty('platform', 'clio');
110
+ expect(parsed).toHaveProperty('userId', '123');
111
+ expect(parsed).toHaveProperty('operation', 'createLog');
112
+ });
113
+
114
+ test('should support nested child loggers', () => {
115
+ process.env.NODE_ENV = 'production';
116
+ const logger = new Logger({ level: 'INFO' });
117
+ const child1 = logger.child({ platform: 'clio' });
118
+ const child2 = child1.child({ userId: '123' });
119
+
120
+ child2.info('test message');
121
+
122
+ const logOutput = consoleSpy.mock.calls[0][0];
123
+ const parsed = JSON.parse(logOutput);
124
+
125
+ expect(parsed).toHaveProperty('platform', 'clio');
126
+ expect(parsed).toHaveProperty('userId', '123');
127
+ });
128
+ });
129
+
130
+ describe('API Request Logging', () => {
131
+ test('should log successful API requests at DEBUG level', () => {
132
+ const logger = new Logger({ level: 'DEBUG' });
133
+
134
+ logger.logApiRequest({
135
+ method: 'GET',
136
+ url: 'https://api.example.com/users',
137
+ status: 200,
138
+ duration: 150,
139
+ platform: 'clio',
140
+ });
141
+
142
+ expect(consoleSpy).toHaveBeenCalledTimes(1);
143
+ expect(consoleErrorSpy).not.toHaveBeenCalled();
144
+ });
145
+
146
+ test('should log failed API requests at ERROR level', () => {
147
+ const logger = new Logger({ level: 'ERROR' });
148
+ const error = new Error('Request failed');
149
+
150
+ logger.logApiRequest({
151
+ method: 'POST',
152
+ url: 'https://api.example.com/logs',
153
+ status: 500,
154
+ duration: 300,
155
+ platform: 'clio',
156
+ error,
157
+ });
158
+
159
+ expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
160
+ expect(consoleSpy).not.toHaveBeenCalled();
161
+ });
162
+
163
+ test('should log 4xx errors at WARN level', () => {
164
+ const logger = new Logger({ level: 'WARN' });
165
+
166
+ logger.logApiRequest({
167
+ method: 'GET',
168
+ url: 'https://api.example.com/contact/999',
169
+ status: 404,
170
+ duration: 100,
171
+ platform: 'clio',
172
+ });
173
+
174
+ expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
175
+ });
176
+ });
177
+
178
+ describe('Database Query Logging', () => {
179
+ test('should log successful queries at DEBUG level', () => {
180
+ const logger = new Logger({ level: 'DEBUG' });
181
+
182
+ logger.logDatabaseQuery({
183
+ operation: 'SELECT',
184
+ table: 'users',
185
+ duration: 50,
186
+ });
187
+
188
+ expect(consoleSpy).toHaveBeenCalledTimes(1);
189
+ });
190
+
191
+ test('should log failed queries at ERROR level', () => {
192
+ const logger = new Logger({ level: 'ERROR' });
193
+ const error = new Error('Constraint violation');
194
+
195
+ logger.logDatabaseQuery({
196
+ operation: 'INSERT',
197
+ table: 'call_logs',
198
+ duration: 20,
199
+ error,
200
+ });
201
+
202
+ expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
203
+ });
204
+ });
205
+ });
206
+