@app-connect/core 1.7.37 → 1.7.38

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 (286) hide show
  1. package/README.md +17 -16
  2. package/dist/connector/developerPortal.d.ts +6 -0
  3. package/{connector → dist/connector}/developerPortal.js +29 -12
  4. package/dist/connector/mock.d.ts +1 -0
  5. package/{connector → dist/connector}/mock.js +33 -17
  6. package/dist/connector/proxy/engine.d.ts +10 -0
  7. package/dist/connector/proxy/engine.js +222 -0
  8. package/dist/connector/proxy/index.d.ts +5 -0
  9. package/dist/connector/proxy/index.js +511 -0
  10. package/dist/connector/registry.d.ts +1 -0
  11. package/dist/connector/registry.js +243 -0
  12. package/dist/handlers/admin.d.ts +1 -0
  13. package/{handlers → dist/handlers}/admin.js +137 -78
  14. package/dist/handlers/appointment.d.ts +9 -0
  15. package/{handlers → dist/handlers}/appointment.js +58 -29
  16. package/dist/handlers/auth.d.ts +9 -0
  17. package/{handlers → dist/handlers}/auth.js +68 -40
  18. package/dist/handlers/calldown.d.ts +10 -0
  19. package/dist/handlers/calldown.js +134 -0
  20. package/dist/handlers/contact.d.ts +1 -0
  21. package/{handlers → dist/handlers}/contact.js +61 -39
  22. package/dist/handlers/disposition.d.ts +1 -0
  23. package/{handlers → dist/handlers}/disposition.js +20 -10
  24. package/dist/handlers/log.d.ts +1 -0
  25. package/{handlers → dist/handlers}/log.js +91 -124
  26. package/dist/handlers/managedAuth.d.ts +1 -0
  27. package/{handlers → dist/handlers}/managedAuth.js +134 -61
  28. package/dist/handlers/managedOAuth.d.ts +13 -0
  29. package/{handlers → dist/handlers}/managedOAuth.js +102 -30
  30. package/dist/handlers/plugin.d.ts +1 -0
  31. package/{handlers → dist/handlers}/plugin.js +59 -27
  32. package/dist/handlers/user.d.ts +1 -0
  33. package/{handlers → dist/handlers}/user.js +45 -27
  34. package/dist/index.d.ts +1 -0
  35. package/{index.js → dist/index.js} +538 -449
  36. package/dist/jest.config.d.ts +1 -0
  37. package/dist/jest.config.js +65 -0
  38. package/dist/lib/analytics.d.ts +4 -0
  39. package/{lib → dist/lib}/analytics.js +8 -6
  40. package/dist/lib/authSession.d.ts +5 -0
  41. package/{lib → dist/lib}/authSession.js +15 -43
  42. package/dist/lib/cacheCleanup.d.ts +4 -0
  43. package/{lib → dist/lib}/cacheCleanup.js +5 -17
  44. package/dist/lib/callLogComposer.d.ts +109 -0
  45. package/{lib → dist/lib}/callLogComposer.js +157 -197
  46. package/dist/lib/callLogLookup.d.ts +6 -0
  47. package/{lib → dist/lib}/callLogLookup.js +12 -34
  48. package/dist/lib/constants.d.ts +6 -0
  49. package/dist/lib/constants.js +9 -0
  50. package/dist/lib/debugTracer.d.ts +17 -0
  51. package/{lib → dist/lib}/debugTracer.js +7 -83
  52. package/dist/lib/encode.d.ts +3 -0
  53. package/dist/lib/encode.js +50 -0
  54. package/dist/lib/errorHandler.d.ts +7 -0
  55. package/dist/lib/errorHandler.js +161 -0
  56. package/dist/lib/generalErrorMessage.d.ts +7 -0
  57. package/{lib → dist/lib}/generalErrorMessage.js +6 -6
  58. package/dist/lib/jwt.d.ts +4 -0
  59. package/dist/lib/jwt.js +18 -0
  60. package/dist/lib/logger.d.ts +24 -0
  61. package/dist/lib/logger.js +126 -0
  62. package/dist/lib/migrateCallLogsSchema.d.ts +32 -0
  63. package/{lib → dist/lib}/migrateCallLogsSchema.js +75 -160
  64. package/dist/lib/oauth.d.ts +4 -0
  65. package/{lib → dist/lib}/oauth.js +157 -160
  66. package/dist/lib/ringcentral.d.ts +24 -0
  67. package/dist/lib/ringcentral.js +226 -0
  68. package/dist/lib/s3ErrorLogReport.d.ts +4 -0
  69. package/{lib → dist/lib}/s3ErrorLogReport.js +11 -23
  70. package/dist/lib/sharedSMSComposer.d.ts +7 -0
  71. package/{lib → dist/lib}/sharedSMSComposer.js +21 -107
  72. package/dist/lib/util.d.ts +7 -0
  73. package/{lib → dist/lib}/util.js +9 -20
  74. package/dist/mcp/lib/oauthError.d.ts +1 -0
  75. package/dist/mcp/lib/oauthError.js +25 -0
  76. package/dist/mcp/lib/validator.d.ts +1 -0
  77. package/{mcp → dist/mcp}/lib/validator.js +16 -20
  78. package/dist/mcp/lib/widgetSessionToken.d.ts +1 -0
  79. package/dist/mcp/lib/widgetSessionToken.js +46 -0
  80. package/dist/mcp/mcpHandler.d.ts +8 -0
  81. package/{mcp → dist/mcp}/mcpHandler.js +98 -88
  82. package/dist/mcp/tools/cancelAppointment.d.ts +1 -0
  83. package/{mcp → dist/mcp}/tools/cancelAppointment.js +7 -16
  84. package/dist/mcp/tools/checkAuthStatus.d.ts +1 -0
  85. package/{mcp → dist/mcp}/tools/checkAuthStatus.js +21 -14
  86. package/dist/mcp/tools/confirmAppointment.d.ts +1 -0
  87. package/{mcp → dist/mcp}/tools/confirmAppointment.js +7 -16
  88. package/dist/mcp/tools/createAppointment.d.ts +1 -0
  89. package/{mcp → dist/mcp}/tools/createAppointment.js +7 -19
  90. package/dist/mcp/tools/createCallLog.d.ts +1 -0
  91. package/{mcp → dist/mcp}/tools/createCallLog.js +18 -29
  92. package/dist/mcp/tools/createContact.d.ts +1 -0
  93. package/{mcp → dist/mcp}/tools/createContact.js +8 -20
  94. package/dist/mcp/tools/createMessageLog.d.ts +1 -0
  95. package/{mcp → dist/mcp}/tools/createMessageLog.js +14 -26
  96. package/dist/mcp/tools/doAuth.d.ts +1 -0
  97. package/{mcp → dist/mcp}/tools/doAuth.js +17 -13
  98. package/dist/mcp/tools/findContactByName.d.ts +1 -0
  99. package/{mcp → dist/mcp}/tools/findContactByName.js +9 -15
  100. package/dist/mcp/tools/findContactByPhone.d.ts +1 -0
  101. package/{mcp → dist/mcp}/tools/findContactByPhone.js +8 -15
  102. package/dist/mcp/tools/getCallLog.d.ts +1 -0
  103. package/{mcp → dist/mcp}/tools/getCallLog.js +12 -21
  104. package/dist/mcp/tools/getGoogleFilePicker.d.ts +1 -0
  105. package/{mcp → dist/mcp}/tools/getGoogleFilePicker.js +9 -18
  106. package/dist/mcp/tools/getHelp.d.ts +1 -0
  107. package/{mcp → dist/mcp}/tools/getHelp.js +5 -6
  108. package/dist/mcp/tools/getPublicConnectors.d.ts +1 -0
  109. package/{mcp → dist/mcp}/tools/getPublicConnectors.js +19 -18
  110. package/dist/mcp/tools/getSessionInfo.d.ts +1 -0
  111. package/{mcp → dist/mcp}/tools/getSessionInfo.js +10 -16
  112. package/dist/mcp/tools/index.d.ts +8 -0
  113. package/dist/mcp/tools/index.js +50 -0
  114. package/dist/mcp/tools/listAppointments.d.ts +1 -0
  115. package/{mcp → dist/mcp}/tools/listAppointments.js +7 -19
  116. package/dist/mcp/tools/logout.d.ts +1 -0
  117. package/{mcp → dist/mcp}/tools/logout.js +16 -14
  118. package/dist/mcp/tools/rcGetCallLogs.d.ts +1 -0
  119. package/{mcp → dist/mcp}/tools/rcGetCallLogs.js +10 -8
  120. package/dist/mcp/tools/updateAppointment.d.ts +1 -0
  121. package/{mcp → dist/mcp}/tools/updateAppointment.js +17 -22
  122. package/dist/mcp/tools/updateCallLog.d.ts +1 -0
  123. package/{mcp → dist/mcp}/tools/updateCallLog.js +16 -26
  124. package/dist/models/accountDataModel.d.ts +3 -0
  125. package/dist/models/accountDataModel.js +39 -0
  126. package/dist/models/adminConfigModel.d.ts +2 -0
  127. package/dist/models/adminConfigModel.js +39 -0
  128. package/dist/models/cacheModel.d.ts +2 -0
  129. package/{models → dist/models}/cacheModel.js +7 -3
  130. package/dist/models/callDownListModel.d.ts +2 -0
  131. package/{models → dist/models}/callDownListModel.js +8 -4
  132. package/dist/models/callLogModel.d.ts +2 -0
  133. package/dist/models/callLogModel.js +43 -0
  134. package/dist/models/dynamo/connectorSchema.d.ts +2 -0
  135. package/dist/models/dynamo/connectorSchema.js +141 -0
  136. package/dist/models/dynamo/lockSchema.d.ts +2 -0
  137. package/{models → dist/models}/dynamo/lockSchema.js +5 -7
  138. package/dist/models/dynamo/noteCacheSchema.d.ts +2 -0
  139. package/{models → dist/models}/dynamo/noteCacheSchema.js +4 -6
  140. package/dist/models/llmSessionModel.d.ts +2 -0
  141. package/dist/models/llmSessionModel.js +21 -0
  142. package/dist/models/messageLogModel.d.ts +2 -0
  143. package/{models → dist/models}/messageLogModel.js +8 -4
  144. package/dist/models/sequelize.d.ts +2 -0
  145. package/dist/models/sequelize.js +68 -0
  146. package/dist/models/userModel.d.ts +2 -0
  147. package/dist/models/userModel.js +49 -0
  148. package/dist/package.json +100 -0
  149. package/dist/releaseNotes.json +1222 -0
  150. package/dist/tsconfig.json +14 -0
  151. package/dist/types/admin.d.ts +141 -0
  152. package/dist/types/analytics.d.ts +14 -0
  153. package/dist/types/appointment.d.ts +50 -0
  154. package/dist/types/auth.d.ts +137 -0
  155. package/dist/types/authSession.d.ts +35 -0
  156. package/dist/types/cacheCleanup.d.ts +12 -0
  157. package/dist/types/calldown.d.ts +54 -0
  158. package/dist/types/common.d.ts +46 -0
  159. package/dist/types/connector.d.ts +165 -0
  160. package/dist/types/contact.d.ts +125 -0
  161. package/dist/types/errorHandler.d.ts +60 -0
  162. package/dist/types/index.d.ts +76 -0
  163. package/dist/types/json.d.ts +9 -0
  164. package/dist/types/jwt.d.ts +8 -0
  165. package/dist/types/logging.d.ts +224 -0
  166. package/dist/types/managedAuth.d.ts +114 -0
  167. package/dist/types/managedOAuth.d.ts +59 -0
  168. package/dist/types/manifest.d.ts +120 -0
  169. package/dist/types/migration.d.ts +15 -0
  170. package/dist/types/plugin.d.ts +74 -0
  171. package/dist/types/ringcentral.d.ts +61 -0
  172. package/dist/types/s3ErrorLogReport.d.ts +16 -0
  173. package/dist/types/sharedSMSComposer.d.ts +105 -0
  174. package/dist/types/user.d.ts +46 -0
  175. package/dist/types/util.d.ts +7 -0
  176. package/package.json +34 -6
  177. package/releaseNotes.json +8 -0
  178. package/.env.test +0 -5
  179. package/connector/proxy/engine.js +0 -165
  180. package/connector/proxy/index.js +0 -500
  181. package/connector/registry.js +0 -252
  182. package/docs/README.md +0 -50
  183. package/docs/architecture.md +0 -94
  184. package/docs/connectors.md +0 -116
  185. package/docs/handlers.md +0 -128
  186. package/docs/libraries.md +0 -98
  187. package/docs/models.md +0 -146
  188. package/docs/routes.md +0 -119
  189. package/docs/tests.md +0 -73
  190. package/handlers/calldown.js +0 -99
  191. package/jest.config.js +0 -57
  192. package/lib/constants.js +0 -9
  193. package/lib/encode.js +0 -30
  194. package/lib/errorHandler.js +0 -218
  195. package/lib/jwt.js +0 -18
  196. package/lib/logger.js +0 -190
  197. package/lib/ringcentral.js +0 -267
  198. package/mcp/README.md +0 -420
  199. package/mcp/tools/index.js +0 -51
  200. package/mcp/ui/App/App.tsx +0 -358
  201. package/mcp/ui/App/components/AuthInfoForm.tsx +0 -113
  202. package/mcp/ui/App/components/AuthSuccess.tsx +0 -22
  203. package/mcp/ui/App/components/ConnectorList.tsx +0 -82
  204. package/mcp/ui/App/components/DebugPanel.tsx +0 -43
  205. package/mcp/ui/App/components/OAuthConnect.tsx +0 -270
  206. package/mcp/ui/App/lib/callTool.ts +0 -130
  207. package/mcp/ui/App/lib/debugLog.ts +0 -41
  208. package/mcp/ui/App/lib/developerPortal.ts +0 -111
  209. package/mcp/ui/App/main.css +0 -6
  210. package/mcp/ui/App/root.tsx +0 -13
  211. package/mcp/ui/dist/index.html +0 -53
  212. package/mcp/ui/vite.config.ts +0 -16
  213. package/models/accountDataModel.js +0 -34
  214. package/models/adminConfigModel.js +0 -35
  215. package/models/callLogModel.js +0 -39
  216. package/models/dynamo/connectorSchema.js +0 -146
  217. package/models/llmSessionModel.js +0 -17
  218. package/models/sequelize.js +0 -17
  219. package/models/userModel.js +0 -45
  220. package/test/connector/developerPortal.test.js +0 -166
  221. package/test/connector/mock.test.js +0 -131
  222. package/test/connector/proxy/engine.test.js +0 -211
  223. package/test/connector/proxy/index.test.js +0 -525
  224. package/test/connector/proxy/sample.json +0 -162
  225. package/test/connector/registry.test.js +0 -416
  226. package/test/handlers/admin.test.js +0 -960
  227. package/test/handlers/appointment.test.js +0 -260
  228. package/test/handlers/auth.test.js +0 -1096
  229. package/test/handlers/calldown.test.js +0 -310
  230. package/test/handlers/contact.test.js +0 -1014
  231. package/test/handlers/disposition.test.js +0 -396
  232. package/test/handlers/log.test.js +0 -1847
  233. package/test/handlers/managedAuth.test.js +0 -458
  234. package/test/handlers/managedOAuth.test.js +0 -262
  235. package/test/handlers/plugin.test.js +0 -429
  236. package/test/handlers/user.test.js +0 -381
  237. package/test/index.test.js +0 -301
  238. package/test/lib/analytics.test.js +0 -146
  239. package/test/lib/authSession.test.js +0 -173
  240. package/test/lib/cacheCleanup.test.js +0 -127
  241. package/test/lib/callLogComposer.test.js +0 -1231
  242. package/test/lib/debugTracer.test.js +0 -328
  243. package/test/lib/encode.test.js +0 -59
  244. package/test/lib/errorHandler.test.js +0 -246
  245. package/test/lib/generalErrorMessage.test.js +0 -82
  246. package/test/lib/jwt.test.js +0 -176
  247. package/test/lib/logger.test.js +0 -206
  248. package/test/lib/oauth.test.js +0 -359
  249. package/test/lib/ringcentral.test.js +0 -467
  250. package/test/lib/s3ErrorLogReport.test.js +0 -187
  251. package/test/lib/sharedSMSComposer.test.js +0 -1084
  252. package/test/lib/util.test.js +0 -329
  253. package/test/mcp/mcpHandler.test.js +0 -73
  254. package/test/mcp/mcpHandlerMore.test.js +0 -384
  255. package/test/mcp/tools/appointmentTools.test.js +0 -362
  256. package/test/mcp/tools/checkAuthStatus.test.js +0 -83
  257. package/test/mcp/tools/createCallLog.test.js +0 -436
  258. package/test/mcp/tools/createContact.test.js +0 -58
  259. package/test/mcp/tools/createMessageLog.test.js +0 -595
  260. package/test/mcp/tools/doAuth.test.js +0 -113
  261. package/test/mcp/tools/findContactByName.test.js +0 -275
  262. package/test/mcp/tools/findContactByPhone.test.js +0 -296
  263. package/test/mcp/tools/getCallLog.test.js +0 -298
  264. package/test/mcp/tools/getGoogleFilePicker.test.js +0 -281
  265. package/test/mcp/tools/getPublicConnectors.test.js +0 -107
  266. package/test/mcp/tools/getSessionInfo.test.js +0 -127
  267. package/test/mcp/tools/logout.test.js +0 -233
  268. package/test/mcp/tools/rcGetCallLogs.test.js +0 -56
  269. package/test/mcp/tools/updateCallLog.test.js +0 -360
  270. package/test/models/accountDataModel.test.js +0 -98
  271. package/test/models/callDownListModel.test.js +0 -125
  272. package/test/models/dynamo/connectorSchema.test.js +0 -189
  273. package/test/models/dynamo/lockSchema.test.js +0 -37
  274. package/test/models/dynamo/noteCacheSchema.test.js +0 -45
  275. package/test/models/llmSessionModel.test.js +0 -91
  276. package/test/models/models.test.js +0 -660
  277. package/test/routes/calldownRoutes.test.js +0 -224
  278. package/test/routes/coreRouterBroadRoutes.test.js +0 -855
  279. package/test/routes/dispositionRoutes.test.js +0 -192
  280. package/test/routes/managedAuthRoutes.test.js +0 -386
  281. package/test/routes/pluginRoutes.test.js +0 -262
  282. package/test/setup.js +0 -178
  283. /package/{mcp → dist/mcp}/ui/index.html +0 -0
  284. /package/{mcp → dist/mcp}/ui/package-lock.json +0 -0
  285. /package/{mcp → dist/mcp}/ui/package.json +0 -0
  286. /package/{mcp → dist/mcp}/ui/tsconfig.json +0 -0
@@ -1,525 +0,0 @@
1
- jest.mock('axios', () => jest.fn());
2
- jest.mock('../../../models/dynamo/connectorSchema', () => ({
3
- Connector: { getProxyConfig: jest.fn() }
4
- }));
5
- jest.mock('awesome-phonenumber', () => ({
6
- parsePhoneNumber: jest.fn().mockReturnValue({})
7
- }));
8
- jest.mock('../../../models/userModel', () => ({
9
- UserModel: { findByPk: jest.fn() }
10
- }));
11
-
12
- const axios = require('axios');
13
- const { Connector } = require('../../../models/dynamo/connectorSchema');
14
- const { UserModel } = require('../../../models/userModel');
15
- const proxy = require('../../../connector/proxy/index');
16
- const sampleConfig = require('./sample.json');
17
-
18
- describe('proxy connector (high-level)', () => {
19
- beforeEach(() => {
20
- axios.mockReset();
21
- });
22
-
23
- test('createCallLog returns mapped logId using provided proxyConfig', async () => {
24
- // Response matching mapping: response.activity.id (engine wraps as { response: response.data })
25
- axios.mockResolvedValue({ data: { activity: { id: 'A-100' } } });
26
-
27
- const user = { accessToken: 't-123', platformAdditionalInfo: { proxyId: 'p1' } };
28
- const contactInfo = { id: 'c-1', name: 'Alice' };
29
- const callLog = { direction: 'Outbound', startTime: Date.now(), duration: 60 };
30
-
31
- const res = await proxy.createCallLog({
32
- user,
33
- contactInfo,
34
- authHeader: 'Basic abc',
35
- callLog,
36
- note: 'hello',
37
- additionalSubmission: {},
38
- aiNote: '',
39
- transcript: '',
40
- hashedAccountId: 'h1',
41
- isFromSSCL: false,
42
- composedLogDetails: 'details',
43
- proxyConfig: sampleConfig
44
- });
45
-
46
- expect(res.logId).toBe('A-100');
47
- expect(res.returnMessage.messageType).toBe('success');
48
- expect(axios).toHaveBeenCalledTimes(1);
49
- const args = axios.mock.calls[0][0];
50
- expect(args.method).toBe('POST');
51
- expect(args.url).toMatch(/\/activities$/);
52
- expect(args.headers['Content-Type']).toBe('application/json');
53
- expect(args.data.subject).toMatch(/Call/);
54
- expect(args.data.linked_contacts[0].contact_id).toBe('c-1');
55
- });
56
-
57
- test('getCallLog maps subject, note and fullBody', async () => {
58
- axios.mockResolvedValue({ data: { activity: { subject: 'S', note: 'N', description: 'D' } } });
59
-
60
- const out = await proxy.getCallLog({
61
- user: { accessToken: 't-123', platformAdditionalInfo: { proxyId: 'p1' } },
62
- callLogId: '123',
63
- contactId: 'c-1',
64
- authHeader: 'x',
65
- proxyConfig: sampleConfig
66
- });
67
-
68
- expect(out.callLogInfo.subject).toBe('S');
69
- expect(out.callLogInfo.note).toBe('N');
70
- expect(out.callLogInfo.fullBody).toBe('D');
71
- expect(out.callLogInfo.fullLogResponse).toBeDefined();
72
- });
73
-
74
- test('updateCallLog performs PUT and returns success message', async () => {
75
- axios.mockResolvedValue({ data: { ok: true } });
76
-
77
- const start = new Date('2020-01-01T00:00:00Z');
78
- const res = await proxy.updateCallLog({
79
- user: { accessToken: 't-123', platformAdditionalInfo: { proxyId: 'p1' } },
80
- existingCallLog: { thirdPartyLogId: '77' },
81
- authHeader: 'x',
82
- recordingLink: '',
83
- recordingDownloadLink: '',
84
- subject: 'Subj',
85
- note: 'Note',
86
- startTime: start,
87
- duration: 90,
88
- result: 'Completed',
89
- aiNote: '',
90
- transcript: '',
91
- legs: [],
92
- additionalSubmission: {},
93
- composedLogDetails: 'Body',
94
- existingCallLogDetails: {},
95
- hashedAccountId: 'h',
96
- isFromSSCL: false,
97
- proxyConfig: sampleConfig
98
- });
99
-
100
- expect(res.returnMessage.message).toMatch(/updated/i);
101
- const args = axios.mock.calls[0][0];
102
- expect(args.method).toBe('PUT');
103
- expect(args.url).toMatch(/\/activities\/77$/);
104
- expect(args.data.subject).toBe('Subj');
105
- expect(args.data.end_date).toBeDefined();
106
- });
107
-
108
- test('getLogFormatType returns meta.logFormat or custom', () => {
109
- expect(proxy.getLogFormatType('x', sampleConfig)).toBe('text/plain');
110
- expect(proxy.getLogFormatType('x', null)).toBe('custom');
111
- });
112
- });
113
-
114
- describe('proxy connector - more coverage', () => {
115
- beforeEach(() => {
116
- axios.mockReset();
117
- Connector.getProxyConfig.mockReset();
118
- });
119
-
120
- test('getAuthType returns apiKey', async () => {
121
- expect(await proxy.getAuthType()).toBe('apiKey');
122
- });
123
-
124
- test('getBasicAuth encodes apiKey with colon', () => {
125
- const token = proxy.getBasicAuth({ apiKey: 'abc' });
126
- expect(token).toBe(Buffer.from('abc:').toString('base64'));
127
- });
128
-
129
- test('getOauthInfo maps configured OAuth settings and falls back when config loading fails', async () => {
130
- const oauthConfig = {
131
- auth: {
132
- type: 'oauth',
133
- clientId: 'client-id',
134
- clientSecret: 'client-secret',
135
- tokenUrl: 'https://auth.example.com/token',
136
- redirectUri: 'https://app.example.com/callback'
137
- },
138
- operations: {}
139
- };
140
-
141
- await expect(proxy.getOauthInfo({
142
- proxyConfig: oauthConfig,
143
- tokenUrl: 'https://override.example.com/token'
144
- })).resolves.toEqual({
145
- clientId: 'client-id',
146
- clientSecret: 'client-secret',
147
- accessTokenUri: 'https://override.example.com/token',
148
- redirectUri: 'https://app.example.com/callback'
149
- });
150
-
151
- Connector.getProxyConfig.mockRejectedValueOnce(new Error('config unavailable'));
152
- await expect(proxy.getOauthInfo({ proxyId: 'missing-config' })).resolves.toEqual({});
153
- await expect(proxy.getAuthType({ proxyId: '' })).resolves.toBe('apiKey');
154
- });
155
-
156
- test('getUserInfo returns a warning when the proxy config has no getUserInfo operation', async () => {
157
- await expect(proxy.getUserInfo({
158
- proxyConfig: { operations: {} },
159
- platform: 'minimal'
160
- })).resolves.toMatchObject({
161
- successful: false,
162
- returnMessage: {
163
- messageType: 'warning',
164
- message: 'Could not load user information. The platform does not support getUserInfo operation.'
165
- }
166
- });
167
- });
168
-
169
- test('getUserList maps configured list responses and returns empty when unsupported', async () => {
170
- const userListConfig = {
171
- requestDefaults: { baseUrl: 'https://api.example.com' },
172
- operations: {
173
- getUserList: {
174
- method: 'GET',
175
- url: '/users',
176
- responseMapping: {
177
- listPath: 'body.records',
178
- idPath: 'user.id',
179
- namePath: 'profile.name',
180
- emailPath: 'email'
181
- }
182
- }
183
- }
184
- };
185
- axios.mockResolvedValueOnce({
186
- data: {
187
- records: [
188
- { user: { id: 'u1' }, profile: { name: 'Ada' }, email: 'ada@example.com' },
189
- { user: { id: 'u2' }, profile: { name: 'Grace' }, email: 'grace@example.com' }
190
- ]
191
- }
192
- });
193
-
194
- await expect(proxy.getUserList({
195
- user: { platformAdditionalInfo: { proxyId: 'p1' } },
196
- authHeader: 'Bearer token',
197
- proxyConfig: userListConfig
198
- })).resolves.toEqual([
199
- { id: 'u1', name: 'Ada', email: 'ada@example.com' },
200
- { id: 'u2', name: 'Grace', email: 'grace@example.com' }
201
- ]);
202
-
203
- await expect(proxy.getUserList({
204
- user: { platformAdditionalInfo: { proxyId: 'p1' } },
205
- proxyConfig: { operations: {} }
206
- })).resolves.toEqual([]);
207
- });
208
-
209
- test('getUserInfo maps id/name/message/platformAdditionalInfo', async () => {
210
- const cfg = JSON.parse(JSON.stringify(sampleConfig));
211
- delete cfg.auth; // ensure provided authHeader is used
212
- Connector.getProxyConfig.mockResolvedValue(cfg);
213
- axios.mockResolvedValue({ data: { user: { username: 'u1', role: 'admin' }, message: 'OK' } });
214
-
215
- const res = await proxy.getUserInfo({
216
- authHeader: 'Basic t',
217
- hostname: 'host',
218
- additionalInfo: { foo: 'bar' },
219
- platform: 'test',
220
- apiKey: 'k',
221
- proxyId: 'p1'
222
- });
223
-
224
- expect(res.successful).toBe(true);
225
- expect(res.platformUserInfo.id).toBe('u1-test');
226
- expect(res.platformUserInfo.name).toBe('u1');
227
- expect(res.returnMessage.message).toBe('OK');
228
- expect(res.platformUserInfo.platformAdditionalInfo.userResponse).toEqual({ username: 'u1', role: 'admin' });
229
- });
230
-
231
- test('findContact maps list items', async () => {
232
- Connector.getProxyConfig.mockResolvedValue(sampleConfig);
233
- axios.mockResolvedValue({ data: { contacts: [ { id: 'c1', name: 'Alice', type: 'Contact', phone: '+1' } ] } });
234
-
235
- const out = await proxy.findContact({
236
- user: { accessToken: 't', platformAdditionalInfo: { proxyId: 'p1' } },
237
- authHeader: 'x',
238
- phoneNumber: '+1',
239
- overridingFormat: '',
240
- isExtension: false
241
- });
242
-
243
- expect(out.successful).toBe(true);
244
- expect(out.matchedContactInfo.length).toBe(1);
245
- expect(out.matchedContactInfo[0].id).toBe('c1');
246
- });
247
-
248
- test('contact operations return supported empty responses when omitted from manifest', async () => {
249
- const proxyConfig = { operations: {} };
250
- const user = { accessToken: 't', platformAdditionalInfo: { proxyId: 'p1' } };
251
-
252
- await expect(proxy.findContact({
253
- user,
254
- authHeader: 'x',
255
- phoneNumber: '+1',
256
- proxyConfig
257
- })).resolves.toEqual({ successful: true, matchedContactInfo: [] });
258
-
259
- await expect(proxy.findContactWithName({
260
- user,
261
- authHeader: 'x',
262
- name: 'Ada',
263
- proxyConfig
264
- })).resolves.toEqual({ successful: true, matchedContactInfo: [] });
265
-
266
- await expect(proxy.createContact({
267
- user,
268
- authHeader: 'x',
269
- phoneNumber: '+1',
270
- newContactName: 'Ada',
271
- newContactType: 'Contact',
272
- proxyConfig
273
- })).resolves.toEqual({
274
- contactInfo: null,
275
- returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 }
276
- });
277
- });
278
-
279
- test('createContact maps object response', async () => {
280
- Connector.getProxyConfig.mockResolvedValue(sampleConfig);
281
- axios.mockResolvedValue({ data: { id: 'c2', name: 'Bob', type: 'Lead' } });
282
-
283
- const res = await proxy.createContact({
284
- user: { accessToken: 't', platformAdditionalInfo: { proxyId: 'p1' } },
285
- authHeader: 'x',
286
- phoneNumber: '+1',
287
- newContactName: 'Bob',
288
- newContactType: 'Lead',
289
- additionalSubmission: {}
290
- });
291
-
292
- expect(res.contactInfo).toEqual({ id: 'c2', name: 'Bob', type: 'Lead' });
293
- expect(res.returnMessage.messageType).toBe('success');
294
- });
295
-
296
- test('call and message log operations return Not supported when omitted from manifest', async () => {
297
- const proxyConfig = { operations: {} };
298
- const user = { accessToken: 't', platformAdditionalInfo: { proxyId: 'p1' } };
299
- const commonCall = {
300
- user,
301
- contactInfo: { id: 'c1', name: 'Ada' },
302
- authHeader: 'x',
303
- proxyConfig
304
- };
305
-
306
- await expect(proxy.createCallLog({
307
- ...commonCall,
308
- callLog: { direction: 'Inbound', startTime: Date.now(), duration: 30 },
309
- note: ''
310
- })).resolves.toEqual({
311
- logId: undefined,
312
- returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 }
313
- });
314
-
315
- await expect(proxy.getCallLog({
316
- user,
317
- callLogId: 'L1',
318
- contactId: 'c1',
319
- authHeader: 'x',
320
- proxyConfig
321
- })).resolves.toEqual({
322
- callLogInfo: null,
323
- returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 }
324
- });
325
-
326
- await expect(proxy.updateCallLog({
327
- user,
328
- existingCallLog: { thirdPartyLogId: 'L1' },
329
- authHeader: 'x',
330
- startTime: Date.now(),
331
- duration: 30,
332
- proxyConfig
333
- })).resolves.toEqual({
334
- returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 }
335
- });
336
-
337
- await expect(proxy.createMessageLog({
338
- user,
339
- contactInfo: { id: 'c1', name: 'Ada' },
340
- authHeader: 'x',
341
- message: { creationTime: Date.now() },
342
- proxyConfig
343
- })).resolves.toEqual({
344
- logId: undefined,
345
- returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 }
346
- });
347
-
348
- await expect(proxy.updateMessageLog({
349
- user,
350
- contactInfo: { id: 'c1', name: 'Ada' },
351
- existingMessageLog: { thirdPartyLogId: 'M1' },
352
- message: { creationTime: Date.now() },
353
- authHeader: 'x',
354
- proxyConfig
355
- })).resolves.toEqual({
356
- returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 }
357
- });
358
- });
359
-
360
- test('createMessageLog maps idPath and updateMessageLog returns success', async () => {
361
- Connector.getProxyConfig.mockResolvedValue(sampleConfig);
362
- axios.mockResolvedValueOnce({ data: { activity: { id: 'M1' } } });
363
-
364
- const create = await proxy.createMessageLog({
365
- user: { accessToken: 't', platformAdditionalInfo: { proxyId: 'p1' } },
366
- contactInfo: { id: 'c1', name: 'Alice' },
367
- authHeader: 'x',
368
- message: { subject: 'S', direction: 'Outbound', from: { phoneNumber: '+1' }, creationTime: Date.now() },
369
- additionalSubmission: {},
370
- recordingLink: '',
371
- faxDocLink: '',
372
- faxDownloadLink: '',
373
- imageLink: '',
374
- videoLink: ''
375
- });
376
- expect(create.logId).toBe('M1');
377
-
378
- axios.mockResolvedValueOnce({ data: { ok: true } });
379
- const update = await proxy.updateMessageLog({
380
- user: { accessToken: 't', platformAdditionalInfo: { proxyId: 'p1' } },
381
- contactInfo: { id: 'c1', name: 'Alice' },
382
- existingMessageLog: { thirdPartyLogId: 'M1' },
383
- message: { subject: 'S', direction: 'Outbound', from: { phoneNumber: '+1' }, creationTime: Date.now() },
384
- authHeader: 'x',
385
- additionalSubmission: {},
386
- imageLink: '',
387
- videoLink: ''
388
- });
389
- expect(update.returnMessage.message).toMatch(/updated/i);
390
- const args2 = axios.mock.calls[1][0];
391
- expect(args2.url).toMatch(/\/activities\/M1$/);
392
- });
393
-
394
- test('upsertCallDisposition returns Not supported when op missing', async () => {
395
- Connector.getProxyConfig.mockResolvedValue(sampleConfig);
396
- const res = await proxy.upsertCallDisposition({
397
- user: { accessToken: 't', platformAdditionalInfo: { proxyId: 'p1' } },
398
- existingCallLog: { thirdPartyLogId: 'L1' },
399
- authHeader: 'x',
400
- dispositions: []
401
- });
402
- expect(res.returnMessage.message).toMatch(/Not supported/);
403
- });
404
-
405
- test('upsertCallDisposition performs configured operation when supported', async () => {
406
- const dispositionConfig = {
407
- requestDefaults: { baseUrl: 'https://api.example.com' },
408
- operations: {
409
- upsertCallDisposition: {
410
- method: 'POST',
411
- url: '/activities/{{thirdPartyLogId}}/disposition',
412
- body: {
413
- result: '{{dispositions.0.value}}'
414
- }
415
- }
416
- }
417
- };
418
- Connector.getProxyConfig.mockResolvedValue(dispositionConfig);
419
- axios.mockResolvedValueOnce({ data: { ok: true } });
420
-
421
- const res = await proxy.upsertCallDisposition({
422
- user: { accessToken: 't', platformAdditionalInfo: { proxyId: 'p1' } },
423
- existingCallLog: { thirdPartyLogId: 'L1' },
424
- authHeader: 'x',
425
- dispositions: [{ value: 'Connected' }]
426
- });
427
-
428
- expect(res).toEqual({
429
- logId: 'L1',
430
- returnMessage: { message: 'Disposition updated', messageType: 'success', ttl: 2000 }
431
- });
432
- expect(axios.mock.calls[0][0]).toMatchObject({
433
- method: 'POST',
434
- url: 'https://api.example.com/activities/L1/disposition',
435
- data: { result: 'Connected' }
436
- });
437
- });
438
-
439
- test('getLicenseStatus maps values with custom config', async () => {
440
- const licenseConfig = {
441
- requestDefaults: { baseUrl: 'https://api.example.com' },
442
- operations: {
443
- getLicenseStatus: {
444
- method: 'GET',
445
- url: '/license/{{userId}}',
446
- responseMapping: {
447
- isLicenseValidPath: 'body.valid',
448
- licenseStatusPath: 'body.status',
449
- licenseStatusDescriptionPath: 'body.desc'
450
- }
451
- }
452
- }
453
- };
454
- Connector.getProxyConfig.mockResolvedValue(licenseConfig);
455
- axios.mockResolvedValue({ data: { valid: true, status: 'Pro', desc: 'All good' } });
456
- UserModel.findByPk.mockResolvedValue({ id: 'u1', accessToken: 't', platformAdditionalInfo: { proxyId: 'p1' } });
457
-
458
- const s = await proxy.getLicenseStatus({ userId: 'u1', platform: 'x' });
459
- expect(s.isLicenseValid).toBe(true);
460
- expect(s.licenseStatus).toBe('Pro');
461
- expect(s.licenseStatusDescription).toBe('All good');
462
- });
463
-
464
- test('getLicenseStatus handles missing users and missing license operations', async () => {
465
- UserModel.findByPk.mockResolvedValueOnce(null);
466
- await expect(proxy.getLicenseStatus({ userId: 'missing', platform: 'x' })).resolves.toEqual({
467
- isLicenseValid: false,
468
- licenseStatus: 'Invalid (User not found)',
469
- licenseStatusDescription: ''
470
- });
471
-
472
- UserModel.findByPk.mockResolvedValueOnce({ id: 'u1', accessToken: 't', platformAdditionalInfo: { proxyId: 'p1' } });
473
- Connector.getProxyConfig.mockResolvedValueOnce({ operations: {} });
474
- await expect(proxy.getLicenseStatus({ userId: 'u1', platform: 'x' })).resolves.toEqual({
475
- isLicenseValid: true,
476
- licenseStatus: 'Basic',
477
- licenseStatusDescription: ''
478
- });
479
- });
480
-
481
- test('unAuthorize without custom op clears tokens and saves user', async () => {
482
- Connector.getProxyConfig.mockResolvedValue(sampleConfig); // no unAuthorize op
483
- const user = { accessToken: 't', refreshToken: 'r', save: jest.fn(), platformAdditionalInfo: { proxyId: 'p1' } };
484
- const out = await proxy.unAuthorize({ user });
485
- expect(user.accessToken).toBe('');
486
- expect(user.refreshToken).toBe('');
487
- expect(user.save).toHaveBeenCalled();
488
- expect(out.returnMessage.messageType).toBe('success');
489
- });
490
-
491
- test('unAuthorize with custom op triggers request then clears tokens', async () => {
492
- const cfg = {
493
- requestDefaults: { baseUrl: 'https://api.example.com' },
494
- operations: { unAuthorize: { method: 'POST', url: '/logout' } }
495
- };
496
- Connector.getProxyConfig.mockResolvedValue(cfg);
497
- axios.mockResolvedValue({ data: { ok: true } });
498
- const user = { accessToken: 't', refreshToken: 'r', save: jest.fn(), platformAdditionalInfo: { proxyId: 'p1' } };
499
- const out = await proxy.unAuthorize({ user });
500
- expect(axios).toHaveBeenCalledTimes(1);
501
- expect(out.returnMessage.message).toMatch(/Logged out/);
502
- expect(user.accessToken).toBe('');
503
- });
504
-
505
- test('unAuthorize returns a database warning when saving cleared tokens fails', async () => {
506
- Connector.getProxyConfig.mockResolvedValue(sampleConfig);
507
- const user = {
508
- accessToken: 't',
509
- refreshToken: 'r',
510
- save: jest.fn().mockRejectedValue(new Error('save failed')),
511
- platformAdditionalInfo: { proxyId: 'p1' }
512
- };
513
-
514
- await expect(proxy.unAuthorize({ user })).resolves.toMatchObject({
515
- successful: false,
516
- returnMessage: {
517
- message: 'Database operation failed',
518
- messageType: 'warning'
519
- }
520
- });
521
- expect(user.accessToken).toBe('');
522
- expect(user.refreshToken).toBe('');
523
- });
524
- });
525
-
@@ -1,162 +0,0 @@
1
- {
2
- "meta": {
3
- "name": "",
4
- "displayName": "",
5
- "logFormat": "text/plain"
6
- },
7
- "auth": {
8
- "type": "apiKey",
9
- "scheme": "Basic",
10
- "credentialTemplate": "{{apiKey}}",
11
- "encode": "base64",
12
- "headerName": "Authorization"
13
- },
14
- "requestDefaults": {
15
- "baseUrl": "",
16
- "timeoutSeconds": 30,
17
- "defaultHeaders": {
18
- "Accept": "application/json",
19
- "X-Secret-Key": "{{secretKey}}"
20
- }
21
- },
22
- "operations": {
23
- "getUserInfo": {
24
- "method": "GET",
25
- "url": "/authentication",
26
- "responseMapping": {
27
- "type": "object",
28
- "idPath": "body.user.username",
29
- "namePath": "body.user.username",
30
- "messagePath": "body.message",
31
- "platformAdditionalInfoPaths": {
32
- "userResponse": "body.user"
33
- }
34
- }
35
- },
36
- "findContact": {
37
- "method": "GET",
38
- "url": "/contacts",
39
- "query": {
40
- "phone": "{{phoneNumber}}"
41
- },
42
- "responseMapping": {
43
- "type": "list",
44
- "listPath": "body.contacts",
45
- "item": {
46
- "idPath": "id",
47
- "namePath": "name",
48
- "typePath": "",
49
- "phonePath": "",
50
- "createdDatePath": "",
51
- "additionalInfoPath": ""
52
- }
53
- }
54
- },
55
- "createContact": {
56
- "method": "POST",
57
- "url": "/contacts",
58
- "headers": {
59
- "Content-Type": "application/json"
60
- },
61
- "body": {
62
- "name": "{{newContactName}}",
63
- "type": "{{newContactType}}",
64
- "phone": "{{phoneNumber}}"
65
- },
66
- "responseMapping": {
67
- "type": "object",
68
- "idPath": "body.id",
69
- "namePath": "body.name",
70
- "typePath": "body.type"
71
- }
72
- },
73
- "createCallLog": {
74
- "method": "POST",
75
- "url": "/activities",
76
- "headers": {
77
- "Content-Type": "application/json"
78
- },
79
- "body": {
80
- "subject": "{{subject}}",
81
- "description": "{{composedLogDetails}}",
82
- "start_date": "{{startTime}}",
83
- "end_date": "{{endTime}}",
84
- "activity_code_id": 3,
85
- "repeats": "never",
86
- "linked_contacts": [
87
- { "contact_id": "{{contactInfo.id}}" }
88
- ]
89
- },
90
- "responseMapping": {
91
- "type": "object",
92
- "idPath": "body.activity.id"
93
- }
94
- },
95
- "updateCallLog": {
96
- "method": "PUT",
97
- "url": "/activities/{{thirdPartyLogId}}",
98
- "headers": {
99
- "Content-Type": "application/json"
100
- },
101
- "body": {
102
- "subject": "{{subject}}",
103
- "description": "{{composedLogDetails}}",
104
- "start_date": "{{startTime}}",
105
- "end_date": "{{endTime}}"
106
- }
107
- },
108
- "getCallLog": {
109
- "method": "GET",
110
- "url": "/activities/{{thirdPartyLogId}}",
111
- "headers": {
112
- "include": "linked_contacts"
113
- },
114
- "responseMapping": {
115
- "type": "object",
116
- "subjectPath": "body.activity.subject",
117
- "notePath": "body.activity.note",
118
- "fullBodyPath": "body.activity.description"
119
- }
120
- },
121
- "createMessageLog": {
122
- "method": "POST",
123
- "url": "/activities",
124
- "headers": {
125
- "Content-Type": "application/json"
126
- },
127
- "body": {
128
- "subject": "Message with {{contactInfo.name}}",
129
- "description": "Subject: {{message.subject}}\nDirection: {{message.direction}}\n phoneNumber: {{message.from.phoneNumber}}\nRecording link: {{recordingLink}}\n",
130
- "start_date": "{{creationTime}}",
131
- "end_date": "{{creationTime}}",
132
- "activity_code_id": 3,
133
- "repeats": "never",
134
- "linked_contacts": [
135
- { "contact_id": "{{contactInfo.id}}" }
136
- ]
137
- },
138
- "responseMapping": {
139
- "type": "object",
140
- "idPath": "body.activity.id"
141
- }
142
- },
143
- "updateMessageLog": {
144
- "method": "PUT",
145
- "url": "/activities/{{thirdPartyLogId}}",
146
- "headers": {
147
- "Content-Type": "application/json"
148
- },
149
- "body": {
150
- "subject": "Message with {{contactInfo.name}}",
151
- "description": "Subject: {{message.subject}}\nDirection: {{message.direction}}\nRecording link: {{recordingLink}}\n",
152
- "start_date": "{{creationTime}}",
153
- "end_date": "{{creationTime}}",
154
- "activity_code_id": 3,
155
- "repeats": "never",
156
- "linked_contacts": [
157
- { "contact_id": "{{contactInfo.id}}" }
158
- ]
159
- }
160
- }
161
- }
162
- }