@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.
Files changed (69) 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 +97 -69
  6. package/handlers/calldown.js +10 -4
  7. package/handlers/contact.js +45 -112
  8. package/handlers/disposition.js +4 -142
  9. package/handlers/log.js +174 -259
  10. package/handlers/user.js +19 -6
  11. package/index.js +310 -122
  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 -12
  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/accountDataModel.js +34 -0
  40. package/models/cacheModel.js +3 -0
  41. package/package.json +6 -4
  42. package/releaseNotes.json +36 -0
  43. package/test/connector/registry.test.js +145 -0
  44. package/test/handlers/admin.test.js +583 -0
  45. package/test/handlers/auth.test.js +355 -0
  46. package/test/handlers/contact.test.js +852 -0
  47. package/test/handlers/log.test.js +872 -0
  48. package/test/lib/callLogComposer.test.js +1231 -0
  49. package/test/lib/debugTracer.test.js +328 -0
  50. package/test/lib/logger.test.js +206 -0
  51. package/test/lib/oauth.test.js +359 -0
  52. package/test/lib/ringcentral.test.js +473 -0
  53. package/test/lib/sharedSMSComposer.test.js +1084 -0
  54. package/test/lib/util.test.js +282 -0
  55. package/test/mcp/tools/collectAuthInfo.test.js +192 -0
  56. package/test/mcp/tools/createCallLog.test.js +412 -0
  57. package/test/mcp/tools/createMessageLog.test.js +580 -0
  58. package/test/mcp/tools/doAuth.test.js +363 -0
  59. package/test/mcp/tools/findContactByName.test.js +263 -0
  60. package/test/mcp/tools/findContactByPhone.test.js +284 -0
  61. package/test/mcp/tools/getCallLog.test.js +286 -0
  62. package/test/mcp/tools/getPublicConnectors.test.js +128 -0
  63. package/test/mcp/tools/logout.test.js +169 -0
  64. package/test/mcp/tools/setConnector.test.js +177 -0
  65. package/test/mcp/tools/updateCallLog.test.js +346 -0
  66. package/test/models/accountDataModel.test.js +98 -0
  67. package/test/models/dynamo/connectorSchema.test.js +189 -0
  68. package/test/models/models.test.js +539 -0
  69. package/test/setup.js +176 -176
@@ -0,0 +1,282 @@
1
+ jest.mock('tz-lookup');
2
+ jest.mock('country-state-city');
3
+
4
+ const tzlookup = require('tz-lookup');
5
+ const { State } = require('country-state-city');
6
+ const {
7
+ getTimeZone,
8
+ getHashValue,
9
+ secondsToHoursMinutesSeconds,
10
+ getMostRecentDate,
11
+ getMediaReaderLinkByPlatformMediaLink
12
+ } = require('../../lib/util');
13
+
14
+ describe('Utility Functions', () => {
15
+ describe('getTimeZone', () => {
16
+ beforeEach(() => {
17
+ jest.clearAllMocks();
18
+ });
19
+
20
+ test('should return timezone for valid state and country', () => {
21
+ // Arrange
22
+ State.getStateByCodeAndCountry = jest.fn().mockReturnValue({
23
+ name: 'California',
24
+ latitude: '36.778259',
25
+ longitude: '-119.417931'
26
+ });
27
+ tzlookup.mockReturnValue('America/Los_Angeles');
28
+
29
+ // Act
30
+ const result = getTimeZone('US', 'CA');
31
+
32
+ // Assert
33
+ expect(State.getStateByCodeAndCountry).toHaveBeenCalledWith('CA', 'US');
34
+ expect(tzlookup).toHaveBeenCalledWith('36.778259', '-119.417931');
35
+ expect(result).toBe('America/Los_Angeles');
36
+ });
37
+
38
+ test('should return "Unknown timezone" when state not found', () => {
39
+ // Arrange
40
+ State.getStateByCodeAndCountry = jest.fn().mockReturnValue(null);
41
+
42
+ // Act
43
+ const result = getTimeZone('XX', 'YY');
44
+
45
+ // Assert
46
+ expect(result).toBe('Unknown timezone');
47
+ expect(tzlookup).not.toHaveBeenCalled();
48
+ });
49
+
50
+ test('should handle different country/state combinations', () => {
51
+ // Arrange
52
+ State.getStateByCodeAndCountry = jest.fn().mockReturnValue({
53
+ name: 'Tokyo',
54
+ latitude: '35.6762',
55
+ longitude: '139.6503'
56
+ });
57
+ tzlookup.mockReturnValue('Asia/Tokyo');
58
+
59
+ // Act
60
+ const result = getTimeZone('JP', 'TK');
61
+
62
+ // Assert
63
+ expect(result).toBe('Asia/Tokyo');
64
+ });
65
+
66
+ test('should handle European timezone', () => {
67
+ // Arrange
68
+ State.getStateByCodeAndCountry = jest.fn().mockReturnValue({
69
+ name: 'Bavaria',
70
+ latitude: '48.7904',
71
+ longitude: '11.4979'
72
+ });
73
+ tzlookup.mockReturnValue('Europe/Berlin');
74
+
75
+ // Act
76
+ const result = getTimeZone('DE', 'BY');
77
+
78
+ // Assert
79
+ expect(result).toBe('Europe/Berlin');
80
+ });
81
+ });
82
+
83
+ describe('getHashValue', () => {
84
+ test('should generate consistent hash for same input', () => {
85
+ const hash1 = getHashValue('test-string', 'secret-key');
86
+ const hash2 = getHashValue('test-string', 'secret-key');
87
+
88
+ expect(hash1).toBe(hash2);
89
+ });
90
+
91
+ test('should generate different hashes for different strings', () => {
92
+ const hash1 = getHashValue('string-1', 'secret-key');
93
+ const hash2 = getHashValue('string-2', 'secret-key');
94
+
95
+ expect(hash1).not.toBe(hash2);
96
+ });
97
+
98
+ test('should generate different hashes for different keys', () => {
99
+ const hash1 = getHashValue('test-string', 'key-1');
100
+ const hash2 = getHashValue('test-string', 'key-2');
101
+
102
+ expect(hash1).not.toBe(hash2);
103
+ });
104
+
105
+ test('should return a 64-character hex string (SHA-256)', () => {
106
+ const hash = getHashValue('test', 'key');
107
+
108
+ expect(hash).toHaveLength(64);
109
+ expect(hash).toMatch(/^[0-9a-f]{64}$/);
110
+ });
111
+
112
+ test('should handle empty string', () => {
113
+ const hash = getHashValue('', 'secret-key');
114
+
115
+ expect(hash).toHaveLength(64);
116
+ expect(hash).toMatch(/^[0-9a-f]{64}$/);
117
+ });
118
+
119
+ test('should handle special characters', () => {
120
+ const hash = getHashValue('test@#$%^&*()', 'key!@#');
121
+
122
+ expect(hash).toHaveLength(64);
123
+ expect(hash).toMatch(/^[0-9a-f]{64}$/);
124
+ });
125
+ });
126
+
127
+ describe('secondsToHoursMinutesSeconds', () => {
128
+ test('should return "0 seconds" for 0', () => {
129
+ expect(secondsToHoursMinutesSeconds(0)).toBe('0 seconds');
130
+ });
131
+
132
+ test('should return singular "second" for 1 second', () => {
133
+ expect(secondsToHoursMinutesSeconds(1)).toBe('1 second');
134
+ });
135
+
136
+ test('should return plural "seconds" for multiple seconds', () => {
137
+ expect(secondsToHoursMinutesSeconds(30)).toBe('30 seconds');
138
+ });
139
+
140
+ test('should return singular "minute" for 60 seconds', () => {
141
+ expect(secondsToHoursMinutesSeconds(60)).toBe('1 minute');
142
+ });
143
+
144
+ test('should return plural "minutes" for multiple minutes', () => {
145
+ expect(secondsToHoursMinutesSeconds(120)).toBe('2 minutes');
146
+ });
147
+
148
+ test('should return minutes and seconds combined', () => {
149
+ expect(secondsToHoursMinutesSeconds(90)).toBe('1 minute, 30 seconds');
150
+ });
151
+
152
+ test('should return singular "hour" for 3600 seconds', () => {
153
+ expect(secondsToHoursMinutesSeconds(3600)).toBe('1 hour');
154
+ });
155
+
156
+ test('should return plural "hours" for multiple hours', () => {
157
+ expect(secondsToHoursMinutesSeconds(7200)).toBe('2 hours');
158
+ });
159
+
160
+ test('should return hours, minutes, and seconds combined', () => {
161
+ expect(secondsToHoursMinutesSeconds(3661)).toBe('1 hour, 1 minute, 1 second');
162
+ });
163
+
164
+ test('should return hours and minutes combined (no seconds)', () => {
165
+ expect(secondsToHoursMinutesSeconds(3660)).toBe('1 hour, 1 minute');
166
+ });
167
+
168
+ test('should return hours and seconds combined (no minutes)', () => {
169
+ expect(secondsToHoursMinutesSeconds(3601)).toBe('1 hour, 1 second');
170
+ });
171
+
172
+ test('should handle large values', () => {
173
+ // 2 hours, 30 minutes, 45 seconds
174
+ expect(secondsToHoursMinutesSeconds(9045)).toBe('2 hours, 30 minutes, 45 seconds');
175
+ });
176
+
177
+ test('should return input directly if not a number', () => {
178
+ expect(secondsToHoursMinutesSeconds('not a number')).toBe('not a number');
179
+ expect(secondsToHoursMinutesSeconds(undefined)).toBe(undefined);
180
+ // Note: null coerces to 0 via isNaN(null) === false, so returns "0 seconds"
181
+ expect(secondsToHoursMinutesSeconds(null)).toBe('0 seconds');
182
+ });
183
+
184
+ test('should handle NaN', () => {
185
+ expect(secondsToHoursMinutesSeconds(NaN)).toBe(NaN);
186
+ });
187
+ });
188
+
189
+ describe('getMostRecentDate', () => {
190
+ test('should return 0 for empty array', () => {
191
+ expect(getMostRecentDate({ allDateValues: [] })).toBe(0);
192
+ });
193
+
194
+ test('should return the single date from single-element array', () => {
195
+ const date = new Date('2024-01-15').getTime();
196
+ expect(getMostRecentDate({ allDateValues: [date] })).toBe(date);
197
+ });
198
+
199
+ test('should return the most recent date from multiple dates', () => {
200
+ const date1 = new Date('2024-01-01').getTime();
201
+ const date2 = new Date('2024-06-15').getTime();
202
+ const date3 = new Date('2024-03-10').getTime();
203
+
204
+ expect(getMostRecentDate({ allDateValues: [date1, date2, date3] })).toBe(date2);
205
+ });
206
+
207
+ test('should handle numeric timestamps', () => {
208
+ const timestamps = [1000, 5000, 3000, 2000];
209
+ expect(getMostRecentDate({ allDateValues: timestamps })).toBe(5000);
210
+ });
211
+
212
+ test('should skip null values', () => {
213
+ const date1 = new Date('2024-01-01').getTime();
214
+ const date2 = new Date('2024-06-15').getTime();
215
+
216
+ expect(getMostRecentDate({ allDateValues: [date1, null, date2, null] })).toBe(date2);
217
+ });
218
+
219
+ test('should skip undefined values', () => {
220
+ const date1 = new Date('2024-01-01').getTime();
221
+ const date2 = new Date('2024-06-15').getTime();
222
+
223
+ expect(getMostRecentDate({ allDateValues: [date1, undefined, date2] })).toBe(date2);
224
+ });
225
+
226
+ test('should return 0 for array with only null/undefined values', () => {
227
+ expect(getMostRecentDate({ allDateValues: [null, undefined, null] })).toBe(0);
228
+ });
229
+
230
+ test('should handle all same dates', () => {
231
+ const sameDate = new Date('2024-05-01').getTime();
232
+ expect(getMostRecentDate({ allDateValues: [sameDate, sameDate, sameDate] })).toBe(sameDate);
233
+ });
234
+ });
235
+
236
+ describe('getMediaReaderLinkByPlatformMediaLink', () => {
237
+ test('should return null for null input', () => {
238
+ expect(getMediaReaderLinkByPlatformMediaLink(null)).toBeNull();
239
+ });
240
+
241
+ test('should return null for undefined input', () => {
242
+ expect(getMediaReaderLinkByPlatformMediaLink(undefined)).toBeNull();
243
+ });
244
+
245
+ test('should return null for empty string', () => {
246
+ expect(getMediaReaderLinkByPlatformMediaLink('')).toBeNull();
247
+ });
248
+
249
+ test('should return media reader link for valid platform media link', () => {
250
+ const platformLink = 'https://media.ringcentral.com/restapi/v1.0/account/123/extension/456/message-store/789/content/abc';
251
+ const result = getMediaReaderLinkByPlatformMediaLink(platformLink);
252
+
253
+ expect(result).toBe(`https://ringcentral.github.io/ringcentral-media-reader/?media=${encodeURIComponent(platformLink)}`);
254
+ });
255
+
256
+ test('should properly encode special characters in URL', () => {
257
+ const platformLink = 'https://media.ringcentral.com/test?param=value&other=123';
258
+ const result = getMediaReaderLinkByPlatformMediaLink(platformLink);
259
+
260
+ expect(result).toContain('https://ringcentral.github.io/ringcentral-media-reader/?media=');
261
+ expect(result).toContain(encodeURIComponent(platformLink));
262
+ });
263
+
264
+ test('should handle simple URL', () => {
265
+ const platformLink = 'https://example.com/media.mp3';
266
+ const result = getMediaReaderLinkByPlatformMediaLink(platformLink);
267
+
268
+ expect(result).toBe(`https://ringcentral.github.io/ringcentral-media-reader/?media=${encodeURIComponent(platformLink)}`);
269
+ });
270
+
271
+ test('should handle URL with query parameters', () => {
272
+ const platformLink = 'https://media.ringcentral.com/file?id=123&type=audio';
273
+ const result = getMediaReaderLinkByPlatformMediaLink(platformLink);
274
+
275
+ expect(result).toContain('ringcentral-media-reader');
276
+ // Verify the URL is properly encoded
277
+ expect(result).not.toContain('&type=');
278
+ expect(result).toContain('%26type%3D');
279
+ });
280
+ });
281
+ });
282
+
@@ -0,0 +1,192 @@
1
+ const collectAuthInfo = require('../../../mcp/tools/collectAuthInfo');
2
+
3
+ describe('MCP Tool: collectAuthInfo', () => {
4
+ describe('tool definition', () => {
5
+ test('should have correct tool definition', () => {
6
+ expect(collectAuthInfo.definition).toBeDefined();
7
+ expect(collectAuthInfo.definition.name).toBe('collectAuthInfo');
8
+ expect(collectAuthInfo.definition.description).toContain('Auth flow step.3');
9
+ expect(collectAuthInfo.definition.inputSchema).toBeDefined();
10
+ });
11
+
12
+ test('should require connectorManifest and connectorName parameters', () => {
13
+ expect(collectAuthInfo.definition.inputSchema.required).toContain('connectorManifest');
14
+ expect(collectAuthInfo.definition.inputSchema.required).toContain('connectorName');
15
+ });
16
+ });
17
+
18
+ describe('execute', () => {
19
+ test('should handle selectable environment type', async () => {
20
+ // Arrange
21
+ const mockManifest = {
22
+ platforms: {
23
+ salesforce: {
24
+ name: 'salesforce',
25
+ environment: {
26
+ type: 'selectable',
27
+ selections: [
28
+ { name: 'Production', const: 'https://login.salesforce.com' },
29
+ { name: 'Sandbox', const: 'https://test.salesforce.com' }
30
+ ]
31
+ }
32
+ }
33
+ }
34
+ };
35
+
36
+ // Act
37
+ const result = await collectAuthInfo.execute({
38
+ connectorManifest: mockManifest,
39
+ connectorName: 'salesforce',
40
+ selection: 'Production'
41
+ });
42
+
43
+ // Assert
44
+ expect(result).toEqual({
45
+ success: true,
46
+ data: {
47
+ hostname: 'login.salesforce.com',
48
+ message: expect.stringContaining('IMPORTANT')
49
+ }
50
+ });
51
+ });
52
+
53
+ test('should handle dynamic environment type', async () => {
54
+ // Arrange
55
+ const mockManifest = {
56
+ platforms: {
57
+ netsuite: {
58
+ name: 'netsuite',
59
+ environment: {
60
+ type: 'dynamic'
61
+ }
62
+ }
63
+ }
64
+ };
65
+
66
+ // Act
67
+ const result = await collectAuthInfo.execute({
68
+ connectorManifest: mockManifest,
69
+ connectorName: 'netsuite',
70
+ hostname: 'https://1234567.app.netsuite.com'
71
+ });
72
+
73
+ // Assert
74
+ expect(result).toEqual({
75
+ success: true,
76
+ data: {
77
+ hostname: '1234567.app.netsuite.com',
78
+ message: expect.stringContaining('IMPORTANT')
79
+ }
80
+ });
81
+ });
82
+
83
+ test('should handle sandbox selection', async () => {
84
+ // Arrange
85
+ const mockManifest = {
86
+ platforms: {
87
+ salesforce: {
88
+ name: 'salesforce',
89
+ environment: {
90
+ type: 'selectable',
91
+ selections: [
92
+ { name: 'Production', const: 'https://login.salesforce.com' },
93
+ { name: 'Sandbox', const: 'https://test.salesforce.com' }
94
+ ]
95
+ }
96
+ }
97
+ }
98
+ };
99
+
100
+ // Act
101
+ const result = await collectAuthInfo.execute({
102
+ connectorManifest: mockManifest,
103
+ connectorName: 'salesforce',
104
+ selection: 'Sandbox'
105
+ });
106
+
107
+ // Assert
108
+ expect(result.success).toBe(true);
109
+ expect(result.data.hostname).toBe('test.salesforce.com');
110
+ });
111
+
112
+ test('should handle invalid hostname URL', async () => {
113
+ // Arrange
114
+ const mockManifest = {
115
+ platforms: {
116
+ netsuite: {
117
+ name: 'netsuite',
118
+ environment: {
119
+ type: 'dynamic'
120
+ }
121
+ }
122
+ }
123
+ };
124
+
125
+ // Act
126
+ const result = await collectAuthInfo.execute({
127
+ connectorManifest: mockManifest,
128
+ connectorName: 'netsuite',
129
+ hostname: 'invalid-url'
130
+ });
131
+
132
+ // Assert
133
+ expect(result.success).toBe(false);
134
+ expect(result.error).toBeDefined();
135
+ expect(result.errorDetails).toBeDefined();
136
+ });
137
+
138
+ test('should handle missing selection for selectable type', async () => {
139
+ // Arrange
140
+ const mockManifest = {
141
+ platforms: {
142
+ salesforce: {
143
+ name: 'salesforce',
144
+ environment: {
145
+ type: 'selectable',
146
+ selections: [
147
+ { name: 'Production', const: 'https://login.salesforce.com' }
148
+ ]
149
+ }
150
+ }
151
+ }
152
+ };
153
+
154
+ // Act
155
+ const result = await collectAuthInfo.execute({
156
+ connectorManifest: mockManifest,
157
+ connectorName: 'salesforce',
158
+ selection: 'NonExistent'
159
+ });
160
+
161
+ // Assert
162
+ expect(result.success).toBe(false);
163
+ expect(result.error).toBeDefined();
164
+ });
165
+
166
+ test('should handle missing hostname for dynamic type', async () => {
167
+ // Arrange
168
+ const mockManifest = {
169
+ platforms: {
170
+ netsuite: {
171
+ name: 'netsuite',
172
+ environment: {
173
+ type: 'dynamic'
174
+ }
175
+ }
176
+ }
177
+ };
178
+
179
+ // Act
180
+ const result = await collectAuthInfo.execute({
181
+ connectorManifest: mockManifest,
182
+ connectorName: 'netsuite'
183
+ // hostname is missing
184
+ });
185
+
186
+ // Assert
187
+ expect(result.success).toBe(false);
188
+ expect(result.error).toBeDefined();
189
+ });
190
+ });
191
+ });
192
+