@app-connect/core 1.7.36 → 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 (287) 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} +548 -450
  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/dist/lib/migrateCallLogsSchema.js +339 -0
  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 +13 -1
  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/migrateCallLogsSchema.js +0 -237
  198. package/lib/ringcentral.js +0 -267
  199. package/mcp/README.md +0 -420
  200. package/mcp/tools/index.js +0 -51
  201. package/mcp/ui/App/App.tsx +0 -358
  202. package/mcp/ui/App/components/AuthInfoForm.tsx +0 -113
  203. package/mcp/ui/App/components/AuthSuccess.tsx +0 -22
  204. package/mcp/ui/App/components/ConnectorList.tsx +0 -82
  205. package/mcp/ui/App/components/DebugPanel.tsx +0 -43
  206. package/mcp/ui/App/components/OAuthConnect.tsx +0 -270
  207. package/mcp/ui/App/lib/callTool.ts +0 -130
  208. package/mcp/ui/App/lib/debugLog.ts +0 -41
  209. package/mcp/ui/App/lib/developerPortal.ts +0 -111
  210. package/mcp/ui/App/main.css +0 -6
  211. package/mcp/ui/App/root.tsx +0 -13
  212. package/mcp/ui/dist/index.html +0 -53
  213. package/mcp/ui/vite.config.ts +0 -16
  214. package/models/accountDataModel.js +0 -34
  215. package/models/adminConfigModel.js +0 -35
  216. package/models/callLogModel.js +0 -39
  217. package/models/dynamo/connectorSchema.js +0 -146
  218. package/models/llmSessionModel.js +0 -17
  219. package/models/sequelize.js +0 -17
  220. package/models/userModel.js +0 -45
  221. package/test/connector/developerPortal.test.js +0 -166
  222. package/test/connector/mock.test.js +0 -131
  223. package/test/connector/proxy/engine.test.js +0 -211
  224. package/test/connector/proxy/index.test.js +0 -525
  225. package/test/connector/proxy/sample.json +0 -162
  226. package/test/connector/registry.test.js +0 -416
  227. package/test/handlers/admin.test.js +0 -960
  228. package/test/handlers/appointment.test.js +0 -260
  229. package/test/handlers/auth.test.js +0 -1096
  230. package/test/handlers/calldown.test.js +0 -310
  231. package/test/handlers/contact.test.js +0 -1014
  232. package/test/handlers/disposition.test.js +0 -396
  233. package/test/handlers/log.test.js +0 -1847
  234. package/test/handlers/managedAuth.test.js +0 -458
  235. package/test/handlers/managedOAuth.test.js +0 -262
  236. package/test/handlers/plugin.test.js +0 -429
  237. package/test/handlers/user.test.js +0 -381
  238. package/test/index.test.js +0 -301
  239. package/test/lib/analytics.test.js +0 -146
  240. package/test/lib/authSession.test.js +0 -173
  241. package/test/lib/cacheCleanup.test.js +0 -127
  242. package/test/lib/callLogComposer.test.js +0 -1231
  243. package/test/lib/debugTracer.test.js +0 -328
  244. package/test/lib/encode.test.js +0 -59
  245. package/test/lib/errorHandler.test.js +0 -246
  246. package/test/lib/generalErrorMessage.test.js +0 -82
  247. package/test/lib/jwt.test.js +0 -176
  248. package/test/lib/logger.test.js +0 -206
  249. package/test/lib/oauth.test.js +0 -359
  250. package/test/lib/ringcentral.test.js +0 -467
  251. package/test/lib/s3ErrorLogReport.test.js +0 -187
  252. package/test/lib/sharedSMSComposer.test.js +0 -1084
  253. package/test/lib/util.test.js +0 -329
  254. package/test/mcp/mcpHandler.test.js +0 -73
  255. package/test/mcp/mcpHandlerMore.test.js +0 -384
  256. package/test/mcp/tools/appointmentTools.test.js +0 -362
  257. package/test/mcp/tools/checkAuthStatus.test.js +0 -83
  258. package/test/mcp/tools/createCallLog.test.js +0 -436
  259. package/test/mcp/tools/createContact.test.js +0 -58
  260. package/test/mcp/tools/createMessageLog.test.js +0 -595
  261. package/test/mcp/tools/doAuth.test.js +0 -113
  262. package/test/mcp/tools/findContactByName.test.js +0 -275
  263. package/test/mcp/tools/findContactByPhone.test.js +0 -296
  264. package/test/mcp/tools/getCallLog.test.js +0 -298
  265. package/test/mcp/tools/getGoogleFilePicker.test.js +0 -281
  266. package/test/mcp/tools/getPublicConnectors.test.js +0 -107
  267. package/test/mcp/tools/getSessionInfo.test.js +0 -127
  268. package/test/mcp/tools/logout.test.js +0 -233
  269. package/test/mcp/tools/rcGetCallLogs.test.js +0 -56
  270. package/test/mcp/tools/updateCallLog.test.js +0 -360
  271. package/test/models/accountDataModel.test.js +0 -98
  272. package/test/models/callDownListModel.test.js +0 -125
  273. package/test/models/dynamo/connectorSchema.test.js +0 -189
  274. package/test/models/dynamo/lockSchema.test.js +0 -37
  275. package/test/models/dynamo/noteCacheSchema.test.js +0 -45
  276. package/test/models/llmSessionModel.test.js +0 -91
  277. package/test/models/models.test.js +0 -660
  278. package/test/routes/calldownRoutes.test.js +0 -224
  279. package/test/routes/coreRouterBroadRoutes.test.js +0 -855
  280. package/test/routes/dispositionRoutes.test.js +0 -192
  281. package/test/routes/managedAuthRoutes.test.js +0 -386
  282. package/test/routes/pluginRoutes.test.js +0 -262
  283. package/test/setup.js +0 -178
  284. /package/{mcp → dist/mcp}/ui/index.html +0 -0
  285. /package/{mcp → dist/mcp}/ui/package-lock.json +0 -0
  286. /package/{mcp → dist/mcp}/ui/package.json +0 -0
  287. /package/{mcp → dist/mcp}/ui/tsconfig.json +0 -0
@@ -0,0 +1,511 @@
1
+ "use strict";
2
+ /* eslint-disable no-param-reassign */
3
+ // @ts-check
4
+ /** @typedef {import('../../types').OperationFailureResult} OperationFailureResult */
5
+ /** @typedef {import('../../types').ProxyConfig} ProxyConfig */
6
+ /** @typedef {import('../../types').ProxyResponse} ProxyResponse */
7
+ /** @typedef {import('../../types').ReturnMessage} ReturnMessage */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const { parsePhoneNumber } = /** @type {any} */ (require('awesome-phonenumber'));
10
+ const moment = /** @type {any} */ (require('moment'));
11
+ const { performRequest, mapFindContactResponse, mapCreateCallLogResponse, mapGetCallLogResponse, getByPath, } = require('./engine');
12
+ const { Connector: ConnectorImport } = require('../../models/dynamo/connectorSchema');
13
+ const { UserModel: UserModelImport } = require('../../models/userModel');
14
+ const Connector = /** @type {any} */ (ConnectorImport);
15
+ const UserModel = /** @type {any} */ (UserModelImport);
16
+ const logger = require('../../lib/logger');
17
+ const { handleDatabaseError } = require('../../lib/errorHandler');
18
+ /**
19
+ * @param {string | undefined} proxyId
20
+ * @returns {Promise<ProxyConfig | null>}
21
+ */
22
+ async function loadPlatformConfig(proxyId) {
23
+ if (!proxyId) {
24
+ return null;
25
+ }
26
+ try {
27
+ const proxyConfig = await Connector.getProxyConfig(proxyId);
28
+ return proxyConfig;
29
+ }
30
+ catch (error) {
31
+ logger.error('Error getting proxy config: ', { proxyId, stack: error.stack });
32
+ return null;
33
+ }
34
+ }
35
+ /**
36
+ * @param {{ proxyId?: string, proxyConfig?: ProxyConfig | null }} [params]
37
+ * @returns {Promise<string>}
38
+ */
39
+ async function getAuthType({ proxyId, proxyConfig } = {}) {
40
+ const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(proxyId));
41
+ if (!cfg) {
42
+ return 'apiKey';
43
+ }
44
+ return cfg.auth.type || 'apiKey';
45
+ }
46
+ /**
47
+ * @param {{ proxyId?: string, proxyConfig?: ProxyConfig | null, tokenUrl?: string }} [params]
48
+ * @returns {Promise<Record<string, any>>}
49
+ */
50
+ async function getOauthInfo({ proxyId, proxyConfig, tokenUrl } = {}) {
51
+ const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(proxyId));
52
+ if (!cfg) {
53
+ return {};
54
+ }
55
+ return {
56
+ clientId: cfg.auth.clientId,
57
+ clientSecret: cfg.auth.clientSecret,
58
+ accessTokenUri: tokenUrl || cfg.auth.tokenUrl,
59
+ redirectUri: cfg.auth.redirectUri,
60
+ };
61
+ }
62
+ /**
63
+ * @param {{ apiKey: string }} params
64
+ * @returns {string}
65
+ */
66
+ function getBasicAuth({ apiKey }) {
67
+ return Buffer.from(`${apiKey}:`).toString('base64');
68
+ }
69
+ /**
70
+ * @param {Record<string, any>} [params]
71
+ * @returns {Promise<Record<string, any>>}
72
+ */
73
+ async function getUserInfo({ authHeader, hostname, additionalInfo, platform, apiKey, proxyId, proxyConfig, userEmail } = {}) {
74
+ const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(proxyId));
75
+ if (!cfg || !cfg.operations?.getUserInfo) {
76
+ // Fallback if no getUserInfo operation defined
77
+ return {
78
+ successful: false,
79
+ returnMessage: {
80
+ messageType: 'warning',
81
+ message: `Could not load user information. The platform does not support getUserInfo operation.`,
82
+ ttl: 1000
83
+ }
84
+ };
85
+ }
86
+ const response = await performRequest({
87
+ config: cfg,
88
+ opName: 'getUserInfo',
89
+ inputs: {
90
+ additionalInfo,
91
+ apiKey,
92
+ hostname,
93
+ platform,
94
+ userEmail,
95
+ },
96
+ user: {},
97
+ authHeader
98
+ });
99
+ const map = cfg.operations.getUserInfo.responseMapping || {};
100
+ const responseCtx = {
101
+ body: response.data,
102
+ additionalInfo,
103
+ apiKey,
104
+ hostname,
105
+ platform,
106
+ };
107
+ const rawUserId = map.idPath ? getByPath(responseCtx, map.idPath) : undefined;
108
+ const id = `${rawUserId}-${platform}`;
109
+ const name = map.namePath ? getByPath(responseCtx, map.namePath) : rawUserId;
110
+ const timezoneName = map.timezoneNamePath ? getByPath(responseCtx, map.timezoneNamePath) : undefined;
111
+ const overridingApiKey = map.overridingApiKeyPath ? getByPath(responseCtx, map.overridingApiKeyPath) : undefined;
112
+ // platformAdditionalInfo mapping and cleanup
113
+ const platformAdditionalInfo = Object.assign({}, additionalInfo || {});
114
+ if (platformAdditionalInfo.password)
115
+ delete platformAdditionalInfo.password;
116
+ if (map.platformAdditionalInfoPaths && typeof map.platformAdditionalInfoPaths === 'object') {
117
+ for (const [key, expr] of Object.entries(map.platformAdditionalInfoPaths)) {
118
+ platformAdditionalInfo[key] = getByPath(responseCtx, expr);
119
+ }
120
+ }
121
+ const message = map.messagePath ? (getByPath(responseCtx, map.messagePath) || `Connected to ${platform}.`) : `Connected to ${platform}.`;
122
+ return {
123
+ successful: true,
124
+ platformUserInfo: Object.assign({ id, name }, timezoneName ? { timezoneName } : {}, overridingApiKey ? { overridingApiKey } : {}, Object.keys(platformAdditionalInfo).length ? { platformAdditionalInfo } : {}),
125
+ returnMessage: {
126
+ messageType: 'success',
127
+ message,
128
+ ttl: 1000
129
+ }
130
+ };
131
+ }
132
+ /**
133
+ * @param {Record<string, any>} params
134
+ * @returns {Promise<Record<string, any>[]>}
135
+ */
136
+ async function getUserList({ user, authHeader, proxyConfig }) {
137
+ const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
138
+ if (!cfg.operations?.getUserList) {
139
+ return [];
140
+ }
141
+ const response = await performRequest({
142
+ config: cfg,
143
+ opName: 'getUserList',
144
+ inputs: { user },
145
+ user,
146
+ authHeader
147
+ });
148
+ const map = cfg.operations.getUserList.responseMapping || {};
149
+ const responseCtx = { body: response.data };
150
+ const userList = map.listPath ? getByPath(responseCtx, map.listPath) : [];
151
+ return (userList || []).map(item => ({
152
+ id: getByPath(item, map.idPath || 'id'),
153
+ name: getByPath(item, map.namePath || 'name'),
154
+ email: getByPath(item, map.emailPath || 'email'),
155
+ }));
156
+ }
157
+ /**
158
+ * @param {{ user: Record<string, any> }} params
159
+ * @returns {Promise<Record<string, any> | OperationFailureResult>}
160
+ */
161
+ async function unAuthorize({ user }) {
162
+ const cfg = await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId);
163
+ if (cfg?.operations?.unAuthorize) {
164
+ await performRequest({
165
+ config: cfg,
166
+ opName: 'unAuthorize',
167
+ inputs: {},
168
+ user,
169
+ });
170
+ }
171
+ user.accessToken = '';
172
+ user.refreshToken = '';
173
+ try {
174
+ await user.save();
175
+ }
176
+ catch (error) {
177
+ return handleDatabaseError(error, 'Error saving user');
178
+ }
179
+ return {
180
+ successful: true,
181
+ returnMessage: {
182
+ messageType: 'success',
183
+ message: 'Logged out',
184
+ ttl: 1000
185
+ }
186
+ };
187
+ }
188
+ /**
189
+ * @param {Record<string, any>} params
190
+ * @returns {Promise<Record<string, any>>}
191
+ */
192
+ async function findContact({ user, authHeader, phoneNumber, overridingFormat, isExtension, proxyConfig }) {
193
+ const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
194
+ if (!cfg.operations?.findContact) {
195
+ return { successful: true, matchedContactInfo: [] };
196
+ }
197
+ let formattedPhoneNumber = phoneNumber.replace(' ', '+');
198
+ const parsedPhoneNumber = parsePhoneNumber(formattedPhoneNumber);
199
+ const response = await performRequest({
200
+ config: cfg,
201
+ opName: 'findContact',
202
+ inputs: { phoneNumber, parsedPhoneNumber, overridingFormat, isExtension },
203
+ user,
204
+ authHeader
205
+ });
206
+ const matchedContactInfo = mapFindContactResponse({ config: cfg, response, opName: 'findContact' });
207
+ return {
208
+ successful: true,
209
+ matchedContactInfo,
210
+ returnMessage: {
211
+ messageType: 'success',
212
+ message: `Found ${matchedContactInfo.length} contacts`,
213
+ ttl: 3000
214
+ }
215
+ };
216
+ }
217
+ /**
218
+ * @param {Record<string, any>} params
219
+ * @returns {Promise<Record<string, any>>}
220
+ */
221
+ async function createContact({ user, authHeader, phoneNumber, newContactName, newContactType, additionalSubmission, proxyConfig }) {
222
+ const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
223
+ if (!cfg.operations?.createContact) {
224
+ return { contactInfo: null, returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 } };
225
+ }
226
+ const response = await performRequest({
227
+ config: cfg,
228
+ opName: 'createContact',
229
+ inputs: { phoneNumber, newContactName, newContactType, additionalSubmission },
230
+ user,
231
+ authHeader
232
+ });
233
+ const map = cfg.operations.createContact.responseMapping || {};
234
+ const responseCtx = { body: response.data };
235
+ const contactInfo = map.idPath ? {
236
+ id: getByPath(responseCtx, map.idPath || 'body.id'),
237
+ name: getByPath(responseCtx, map.namePath || 'body.name'),
238
+ type: getByPath(responseCtx, map.typePath || 'body.type') || 'Contact',
239
+ } : null;
240
+ return { contactInfo, returnMessage: { message: 'Contact created', messageType: 'success', ttl: 2000 } };
241
+ }
242
+ /**
243
+ * @param {Record<string, any>} params
244
+ * @returns {Promise<Record<string, any>>}
245
+ */
246
+ async function findContactWithName({ user, authHeader, name, proxyConfig }) {
247
+ const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
248
+ if (!cfg.operations?.findContactWithName) {
249
+ return { successful: true, matchedContactInfo: [] };
250
+ }
251
+ const response = await performRequest({
252
+ config: cfg,
253
+ opName: 'findContactWithName',
254
+ inputs: { name },
255
+ user,
256
+ authHeader
257
+ });
258
+ const matchedContactInfo = mapFindContactResponse({ config: cfg, response, opName: 'findContactWithName' });
259
+ return {
260
+ successful: true,
261
+ matchedContactInfo,
262
+ returnMessage: {
263
+ messageType: 'success',
264
+ message: `Found ${matchedContactInfo.length} contacts`,
265
+ ttl: 3000
266
+ }
267
+ };
268
+ }
269
+ /**
270
+ * @param {string} platform
271
+ * @param {ProxyConfig | null | undefined} proxyConfig
272
+ * @returns {string}
273
+ */
274
+ function getLogFormatType(platform, proxyConfig) {
275
+ return proxyConfig ? proxyConfig.meta?.logFormat : 'custom';
276
+ }
277
+ /**
278
+ * @param {Record<string, any>} params
279
+ * @returns {Promise<Record<string, any>>}
280
+ */
281
+ async function createCallLog({ user, contactInfo, authHeader, callLog, note, additionalSubmission, aiNote, transcript, ringSenseTranscript = '', ringSenseSummary = '', ringSenseAIScore = '', ringSenseBulletedSummary = '', ringSenseLink = '', composedLogDetails, hashedAccountId, isFromSSCL, proxyConfig = null, }) {
282
+ const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
283
+ if (!cfg || !cfg.operations?.createCallLog) {
284
+ return { logId: undefined, returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 } };
285
+ }
286
+ const response = await performRequest({
287
+ config: cfg,
288
+ opName: 'createCallLog',
289
+ inputs: {
290
+ contactInfo,
291
+ callLog,
292
+ note,
293
+ additionalSubmission,
294
+ aiNote,
295
+ transcript,
296
+ composedLogDetails,
297
+ hashedAccountId,
298
+ isFromSSCL,
299
+ subject: callLog.customSubject ?? `${callLog.direction} Call ${callLog.direction === 'Outbound' ? 'to' : 'from'} ${contactInfo.name}`,
300
+ startTime: moment(callLog.startTime).utc().toISOString(),
301
+ endTime: moment(callLog.startTime).utc().add(callLog.duration, 'seconds').toISOString(),
302
+ ringSenseTranscript,
303
+ ringSenseSummary,
304
+ ringSenseAIScore,
305
+ ringSenseBulletedSummary,
306
+ ringSenseLink,
307
+ },
308
+ user,
309
+ authHeader
310
+ });
311
+ const { logId } = mapCreateCallLogResponse({ config: cfg, response });
312
+ return {
313
+ logId,
314
+ returnMessage: {
315
+ message: 'Call logged',
316
+ messageType: 'success',
317
+ ttl: 2000
318
+ }
319
+ };
320
+ }
321
+ /**
322
+ * @param {Record<string, any>} params
323
+ * @returns {Promise<Record<string, any>>}
324
+ */
325
+ async function getCallLog({ user, callLogId, contactId, authHeader, proxyConfig = null }) {
326
+ const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
327
+ if (!cfg || !cfg.operations?.getCallLog) {
328
+ return { callLogInfo: null, returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 } };
329
+ }
330
+ const response = await performRequest({
331
+ config: cfg,
332
+ opName: 'getCallLog',
333
+ inputs: { thirdPartyLogId: callLogId, contactId },
334
+ user,
335
+ authHeader
336
+ });
337
+ const mapped = mapGetCallLogResponse({ config: cfg, response });
338
+ return Object.assign(mapped, { returnMessage: { message: 'Call log fetched.', messageType: 'success', ttl: 3000 } });
339
+ }
340
+ /**
341
+ * @param {Record<string, any>} params
342
+ * @returns {Promise<Record<string, any>>}
343
+ */
344
+ async function updateCallLog({ user, existingCallLog, authHeader, recordingLink, recordingDownloadLink, subject, note, startTime, duration, result, aiNote, transcript, legs, ringSenseTranscript = '', ringSenseSummary = '', ringSenseAIScore = '', ringSenseBulletedSummary = '', ringSenseLink = '', additionalSubmission, composedLogDetails, existingCallLogDetails, hashedAccountId, isFromSSCL, proxyConfig = null, }) {
345
+ const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
346
+ if (!cfg || !cfg.operations?.updateCallLog) {
347
+ return { returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 } };
348
+ }
349
+ await performRequest({
350
+ config: cfg,
351
+ opName: 'updateCallLog',
352
+ inputs: {
353
+ thirdPartyLogId: existingCallLog?.thirdPartyLogId,
354
+ existingCallLog,
355
+ recordingLink,
356
+ recordingDownloadLink,
357
+ subject,
358
+ note,
359
+ startTime: moment(startTime).utc().toISOString(),
360
+ endTime: moment(startTime).utc().add(duration, 'seconds').toISOString(),
361
+ duration,
362
+ result,
363
+ aiNote,
364
+ transcript,
365
+ legs,
366
+ additionalSubmission,
367
+ composedLogDetails,
368
+ existingCallLogDetails,
369
+ hashedAccountId,
370
+ isFromSSCL,
371
+ ringSenseTranscript,
372
+ ringSenseSummary,
373
+ ringSenseAIScore,
374
+ ringSenseBulletedSummary,
375
+ ringSenseLink,
376
+ },
377
+ user,
378
+ authHeader
379
+ });
380
+ return {
381
+ updatedNote: null,
382
+ returnMessage: {
383
+ message: 'Call log updated.',
384
+ messageType: 'success',
385
+ ttl: 3000
386
+ }
387
+ };
388
+ }
389
+ /**
390
+ * @param {Record<string, any>} params
391
+ * @returns {Promise<Record<string, any>>}
392
+ */
393
+ async function upsertCallDisposition({ user, existingCallLog, authHeader, dispositions, proxyConfig }) {
394
+ const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
395
+ if (!cfg.operations?.upsertCallDisposition) {
396
+ return { returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 } };
397
+ }
398
+ await performRequest({
399
+ config: cfg,
400
+ opName: 'upsertCallDisposition',
401
+ inputs: { existingCallLog, dispositions, thirdPartyLogId: existingCallLog?.thirdPartyLogId },
402
+ user,
403
+ authHeader
404
+ });
405
+ return { logId: existingCallLog.thirdPartyLogId, returnMessage: { message: 'Disposition updated', messageType: 'success', ttl: 2000 } };
406
+ }
407
+ /**
408
+ * @param {Record<string, any>} params
409
+ * @returns {Promise<Record<string, any>>}
410
+ */
411
+ async function createMessageLog({ user, contactInfo, authHeader, message, additionalSubmission, recordingLink, faxDocLink, faxDownloadLink, imageLink, videoLink, proxyConfig }) {
412
+ const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
413
+ if (!cfg.operations?.createMessageLog) {
414
+ return { logId: undefined, returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 } };
415
+ }
416
+ const response = await performRequest({
417
+ config: cfg,
418
+ opName: 'createMessageLog',
419
+ inputs: {
420
+ contactInfo,
421
+ message,
422
+ additionalSubmission,
423
+ recordingLink,
424
+ faxDocLink,
425
+ faxDownloadLink,
426
+ imageLink,
427
+ videoLink,
428
+ creationTime: moment(message.creationTime).utc().toISOString(),
429
+ },
430
+ user,
431
+ authHeader
432
+ });
433
+ const map = cfg.operations.createMessageLog.responseMapping || {};
434
+ const responseCtx = { body: response.data };
435
+ const logId = getByPath(responseCtx, map.idPath || 'body.id');
436
+ return {
437
+ logId: logId ? String(logId) : undefined,
438
+ returnMessage: { message: 'Message logged', messageType: 'success', ttl: 1000 }
439
+ };
440
+ }
441
+ /**
442
+ * @param {Record<string, any>} params
443
+ * @returns {Promise<Record<string, any>>}
444
+ */
445
+ async function updateMessageLog({ user, contactInfo, existingMessageLog, message, authHeader, additionalSubmission, imageLink, videoLink, proxyConfig }) {
446
+ const cfg = proxyConfig ? proxyConfig : (await loadPlatformConfig(user?.platformAdditionalInfo?.proxyId));
447
+ if (!cfg.operations?.updateMessageLog) {
448
+ return { returnMessage: { message: 'Not supported', messageType: 'warning', ttl: 2000 } };
449
+ }
450
+ await performRequest({
451
+ config: cfg,
452
+ opName: 'updateMessageLog',
453
+ inputs: {
454
+ contactInfo,
455
+ existingMessageLog,
456
+ thirdPartyLogId: existingMessageLog?.thirdPartyLogId,
457
+ message,
458
+ additionalSubmission,
459
+ imageLink,
460
+ videoLink,
461
+ creationTime: moment(message.creationTime).utc().toISOString(),
462
+ },
463
+ user,
464
+ authHeader
465
+ });
466
+ return { returnMessage: { message: 'Message log updated', messageType: 'success', ttl: 3000 } };
467
+ }
468
+ /**
469
+ * @param {{ userId: string | number, platform: string }} params
470
+ * @returns {Promise<Record<string, any>>}
471
+ */
472
+ async function getLicenseStatus({ userId, platform }) {
473
+ const user = await UserModel.findByPk(userId);
474
+ if (!user || !user.accessToken) {
475
+ return { isLicenseValid: false, licenseStatus: 'Invalid (User not found)', licenseStatusDescription: '' };
476
+ }
477
+ const proxyId = user.platformAdditionalInfo?.proxyId;
478
+ const cfg = await loadPlatformConfig(proxyId);
479
+ if (!cfg.operations?.getLicenseStatus) {
480
+ return { isLicenseValid: true, licenseStatus: 'Basic', licenseStatusDescription: '' };
481
+ }
482
+ const response = await performRequest({
483
+ config: cfg,
484
+ opName: 'getLicenseStatus',
485
+ inputs: { userId, platform },
486
+ user,
487
+ });
488
+ const map = cfg.operations.getLicenseStatus.responseMapping || {};
489
+ const responseCtx = { body: response.data };
490
+ const isLicenseValid = getByPath(responseCtx, map.isLicenseValidPath || 'body.isLicenseValid');
491
+ const licenseStatus = getByPath(responseCtx, map.licenseStatusPath || 'body.licenseStatus');
492
+ const licenseStatusDescription = getByPath(responseCtx, map.licenseStatusDescriptionPath || 'body.licenseStatusDescription');
493
+ return { isLicenseValid, licenseStatus, licenseStatusDescription };
494
+ }
495
+ exports.getAuthType = getAuthType;
496
+ exports.getOauthInfo = getOauthInfo;
497
+ exports.getBasicAuth = getBasicAuth;
498
+ exports.getUserInfo = getUserInfo;
499
+ exports.createCallLog = createCallLog;
500
+ exports.updateCallLog = updateCallLog;
501
+ exports.getCallLog = getCallLog;
502
+ exports.createMessageLog = createMessageLog;
503
+ exports.updateMessageLog = updateMessageLog;
504
+ exports.findContact = findContact;
505
+ exports.createContact = createContact;
506
+ exports.findContactWithName = findContactWithName;
507
+ exports.unAuthorize = unAuthorize;
508
+ exports.getLicenseStatus = getLicenseStatus;
509
+ exports.upsertCallDisposition = upsertCallDisposition;
510
+ exports.getUserList = getUserList;
511
+ exports.getLogFormatType = getLogFormatType;
@@ -0,0 +1 @@
1
+ export {};