@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,262 +0,0 @@
1
- jest.mock('../../models/sequelize', () => {
2
- const { Sequelize } = require('sequelize');
3
- return {
4
- sequelize: new Sequelize({
5
- dialect: 'sqlite',
6
- storage: ':memory:',
7
- logging: false
8
- })
9
- };
10
- });
11
-
12
- const managedOAuth = require('../../handlers/managedOAuth');
13
- const { AccountDataModel } = require('../../models/accountDataModel');
14
- const { CacheModel } = require('../../models/cacheModel');
15
- const { sequelize } = require('../../models/sequelize');
16
-
17
- describe('Managed OAuth Handler', () => {
18
- beforeAll(async () => {
19
- process.env.APP_SERVER_SECRET_KEY = 'test-app-server-secret-key-123456';
20
- await AccountDataModel.sync({ force: true });
21
- await CacheModel.sync({ force: true });
22
- });
23
-
24
- afterEach(async () => {
25
- await AccountDataModel.destroy({ where: {} });
26
- await CacheModel.destroy({ where: {} });
27
- });
28
-
29
- afterAll(async () => {
30
- await sequelize.close();
31
- });
32
-
33
- test('returns empty state when account and platform are missing', async () => {
34
- await expect(managedOAuth.getManagedOAuthState({
35
- rcAccountId: '',
36
- platform: '',
37
- isAdmin: false
38
- })).resolves.toEqual({
39
- isAdmin: false,
40
- hasAccountOAuth: false,
41
- hasPendingOAuth: false
42
- });
43
-
44
- await expect(managedOAuth.clearPendingManagedOAuth({})).resolves.toBe(0);
45
- await expect(managedOAuth.clearAccountManagedOAuth({ rcAccountId: 'acc-1' })).resolves.toBe(0);
46
- });
47
-
48
- test('upserts pending OAuth values, filters empty fields, and exposes pending values to admin', async () => {
49
- const firstRecord = await managedOAuth.upsertPendingManagedOAuth({
50
- rcAccountId: 'acc-1',
51
- values: {
52
- clientId: 'client-id',
53
- clientSecret: 'client-secret',
54
- accessTokenUri: '',
55
- authorizationUri: 'https://auth.example.com',
56
- ignored: 'ignored'
57
- }
58
- });
59
-
60
- expect(firstRecord.id).toBe('acc-1-managed-oauth-account');
61
-
62
- const secondRecord = await managedOAuth.upsertPendingManagedOAuth({
63
- rcAccountId: 'acc-1',
64
- values: {
65
- clientId: 'client-id-2',
66
- redirectUri: 'https://app.example.com/callback',
67
- scopes: ['read', 'write'],
68
- hostname: 'crm.example.com'
69
- }
70
- });
71
-
72
- expect(secondRecord.id).toBe(firstRecord.id);
73
-
74
- const pendingValues = await managedOAuth.getPendingManagedOAuthValues({ rcAccountId: 'acc-1' });
75
- expect(pendingValues).toEqual({
76
- clientId: 'client-id-2',
77
- redirectUri: 'https://app.example.com/callback',
78
- scopes: ['read', 'write'],
79
- hostname: 'crm.example.com'
80
- });
81
-
82
- const state = await managedOAuth.getManagedOAuthState({
83
- rcAccountId: 'acc-1',
84
- platform: 'testCRM',
85
- isAdmin: true
86
- });
87
-
88
- expect(state).toEqual({
89
- isAdmin: true,
90
- hasAccountOAuth: false,
91
- hasPendingOAuth: true,
92
- pendingValues
93
- });
94
- });
95
-
96
- test('expired pending OAuth cache is destroyed and ignored', async () => {
97
- const record = await managedOAuth.upsertPendingManagedOAuth({
98
- rcAccountId: 'expired-acc',
99
- values: {
100
- clientId: 'expired-client'
101
- }
102
- });
103
- await record.update({
104
- expiry: new Date(Date.now() - 1000)
105
- });
106
-
107
- const values = await managedOAuth.getPendingManagedOAuthValues({ rcAccountId: 'expired-acc' });
108
-
109
- expect(values).toEqual({});
110
- expect(await CacheModel.findByPk('expired-acc-managed-oauth-account')).toBeNull();
111
- });
112
-
113
- test('migrates pending OAuth to account record and hides account client secret in state', async () => {
114
- await managedOAuth.upsertPendingManagedOAuth({
115
- rcAccountId: 'acc-2',
116
- values: {
117
- clientId: 'client-id',
118
- clientSecret: 'client-secret',
119
- accessTokenUri: 'https://token.example.com'
120
- }
121
- });
122
-
123
- await expect(managedOAuth.migratePendingManagedOAuth({
124
- rcAccountId: 'acc-2',
125
- platform: 'testCRM'
126
- })).resolves.toBe(true);
127
-
128
- expect(await managedOAuth.getPendingManagedOAuthValues({ rcAccountId: 'acc-2' })).toEqual({});
129
-
130
- const accountValues = await managedOAuth.getAccountManagedOAuthValues({
131
- rcAccountId: 'acc-2',
132
- platform: 'testCRM'
133
- });
134
- expect(accountValues).toEqual({
135
- clientId: 'client-id',
136
- clientSecret: 'client-secret',
137
- accessTokenUri: 'https://token.example.com'
138
- });
139
-
140
- const state = await managedOAuth.getManagedOAuthState({
141
- rcAccountId: 'acc-2',
142
- platform: 'testCRM',
143
- isAdmin: true
144
- });
145
-
146
- expect(state).toEqual({
147
- isAdmin: true,
148
- hasAccountOAuth: true,
149
- hasPendingOAuth: false,
150
- oauthValues: {
151
- clientId: 'client-id',
152
- accessTokenUri: 'https://token.example.com'
153
- }
154
- });
155
- });
156
-
157
- test('migrates pending OAuth into an existing account record and resolves account source first', async () => {
158
- await managedOAuth.upsertPendingManagedOAuth({
159
- rcAccountId: 'acc-3',
160
- values: {
161
- clientId: 'pending-client'
162
- }
163
- });
164
- await AccountDataModel.create({
165
- rcAccountId: 'acc-3',
166
- platformName: 'testCRM',
167
- dataKey: managedOAuth.MANAGED_OAUTH_ACCOUNT_DATA_KEY,
168
- data: {
169
- fields: {
170
- clientId: {
171
- encrypted: false,
172
- value: 'old-client'
173
- }
174
- }
175
- }
176
- });
177
-
178
- await expect(managedOAuth.migratePendingManagedOAuth({
179
- rcAccountId: 'acc-3',
180
- platform: 'testCRM'
181
- })).resolves.toBe(true);
182
-
183
- await expect(managedOAuth.resolveManagedOAuthInfo({
184
- rcAccountId: 'acc-3',
185
- platform: 'testCRM'
186
- })).resolves.toEqual({
187
- source: 'account',
188
- oauthInfo: {
189
- clientId: 'pending-client'
190
- }
191
- });
192
- });
193
-
194
- test('resolveManagedOAuthInfo falls back to pending values or null source', async () => {
195
- await managedOAuth.upsertPendingManagedOAuth({
196
- rcAccountId: 'acc-4',
197
- values: {
198
- clientId: 'pending-client'
199
- }
200
- });
201
-
202
- await expect(managedOAuth.resolveManagedOAuthInfo({
203
- rcAccountId: 'acc-4',
204
- platform: 'testCRM'
205
- })).resolves.toEqual({
206
- source: 'pending',
207
- oauthInfo: {
208
- clientId: 'pending-client'
209
- }
210
- });
211
-
212
- await expect(managedOAuth.resolveManagedOAuthInfo({
213
- rcAccountId: 'missing-acc',
214
- platform: 'testCRM'
215
- })).resolves.toEqual({
216
- source: null,
217
- oauthInfo: null
218
- });
219
- });
220
-
221
- test('clear and reset delete account and pending OAuth data', async () => {
222
- await managedOAuth.upsertPendingManagedOAuth({
223
- rcAccountId: 'acc-5',
224
- values: {
225
- clientId: 'pending-client'
226
- }
227
- });
228
- await managedOAuth.migratePendingManagedOAuth({
229
- rcAccountId: 'acc-5',
230
- platform: 'testCRM'
231
- });
232
- await managedOAuth.upsertPendingManagedOAuth({
233
- rcAccountId: 'acc-5',
234
- values: {
235
- clientId: 'pending-client-2'
236
- }
237
- });
238
-
239
- const resetResult = await managedOAuth.resetManagedOAuth({
240
- rcAccountId: 'acc-5',
241
- platform: 'testCRM'
242
- });
243
-
244
- expect(resetResult).toEqual({
245
- deletedAccountCount: 1,
246
- deletedPendingCount: 1
247
- });
248
- });
249
-
250
- test('throws when upserting pending OAuth without account id and no-ops missing migrations', async () => {
251
- await expect(managedOAuth.upsertPendingManagedOAuth({
252
- values: {
253
- clientId: 'client-id'
254
- }
255
- })).rejects.toThrow('rcAccountId is required');
256
-
257
- await expect(managedOAuth.migratePendingManagedOAuth({
258
- rcAccountId: 'no-pending',
259
- platform: 'testCRM'
260
- })).resolves.toBe(false);
261
- });
262
- });
@@ -1,429 +0,0 @@
1
- // Use in-memory SQLite for isolated model tests
2
- jest.mock('../../models/sequelize', () => {
3
- const { Sequelize } = require('sequelize');
4
- return {
5
- sequelize: new Sequelize({
6
- dialect: 'sqlite',
7
- storage: ':memory:',
8
- logging: false,
9
- }),
10
- };
11
- });
12
- jest.mock('axios');
13
-
14
- const pluginHandler = require('../../handlers/plugin');
15
- const { CacheModel } = require('../../models/cacheModel');
16
- const { AccountDataModel } = require('../../models/accountDataModel');
17
- const axios = require('axios');
18
- const { sequelize } = require('../../models/sequelize');
19
- const logger = require('../../lib/logger');
20
-
21
- describe('Plugin Handler', () => {
22
- beforeAll(async () => {
23
- process.env.HASH_KEY = 'unit-test-hash-key';
24
- await CacheModel.sync({ force: true });
25
- await AccountDataModel.sync({ force: true });
26
- });
27
-
28
- afterEach(async () => {
29
- await CacheModel.destroy({ where: {} });
30
- await AccountDataModel.destroy({ where: {} });
31
- jest.clearAllMocks();
32
- jest.restoreAllMocks();
33
- });
34
-
35
- afterAll(async () => {
36
- await sequelize.close();
37
- });
38
-
39
- describe('registerPluginAccount', () => {
40
- test('should register plugin account and persist plugin jwt token in account data', async () => {
41
- const rcAccountId = '12345';
42
- const pluginId = 'sync-all-caps';
43
-
44
- axios.get.mockResolvedValue({
45
- data: {
46
- platforms: {
47
- 'plugin.sample': {
48
- endpointUrl: `https://plugins.example.com/plugin/${pluginId}`,
49
- userRegisterEndpointUrl: `https://plugins.example.com/plugin/${pluginId}/auth/register`
50
- }
51
- }
52
- }
53
- });
54
- axios.post.mockResolvedValue({
55
- data: {
56
- jwtToken: 'plugin-jwt-token'
57
- }
58
- });
59
-
60
- const result = await pluginHandler.registerPluginAccount({
61
- pluginId,
62
- rcAccessToken: 'rc-access-token',
63
- rcAccountId,
64
- pluginAccess: 'public',
65
- pluginName: 'plugin.sample'
66
- });
67
-
68
- expect(result.successful).toBe(true);
69
- expect(axios.post).toHaveBeenCalledWith(
70
- `https://plugins.example.com/plugin/${pluginId}/auth/register`,
71
- {
72
- rcAccessToken: 'rc-access-token',
73
- rcAccountId
74
- }
75
- );
76
-
77
- const accountData = await AccountDataModel.findOne({
78
- where: {
79
- rcAccountId,
80
- platformName: pluginId,
81
- dataKey: 'pluginData'
82
- }
83
- });
84
- expect(accountData).not.toBeNull();
85
- expect(accountData.data.jwtToken).toBe('plugin-jwt-token');
86
- expect(accountData.data.endpointUrl).toBe(`https://plugins.example.com/plugin/${pluginId}`);
87
- });
88
-
89
- test('should throw when register API does not return jwt token', async () => {
90
- const rcAccountId = '12345';
91
- const pluginId = 'sync-all-caps';
92
-
93
- axios.get.mockResolvedValue({
94
- data: {
95
- platforms: {
96
- 'plugin.sample': {
97
- endpointUrl: `https://plugins.example.com/plugin/${pluginId}`,
98
- userRegisterEndpointUrl: `https://plugins.example.com/plugin/${pluginId}/auth/register`
99
- }
100
- }
101
- }
102
- });
103
- axios.post.mockResolvedValue({ data: {} });
104
-
105
- await expect(pluginHandler.registerPluginAccount({
106
- pluginId,
107
- rcAccessToken: 'rc-access-token',
108
- rcAccountId,
109
- pluginAccess: 'public',
110
- pluginName: 'plugin.sample'
111
- })).rejects.toThrow('Plugin register API did not return jwtToken');
112
- });
113
-
114
- test('should throw when resolved plugin manifest has no endpoint URL', async () => {
115
- axios.get.mockResolvedValue({
116
- data: {
117
- platforms: {
118
- 'plugin.sample': {
119
- userRegisterEndpointUrl: 'https://plugins.example.com/plugin/auth/register'
120
- }
121
- }
122
- }
123
- });
124
-
125
- await expect(pluginHandler.registerPluginAccount({
126
- pluginId: 'missing-endpoint',
127
- rcAccessToken: 'rc-access-token',
128
- rcAccountId: '12345',
129
- pluginAccess: 'public',
130
- pluginName: 'plugin.sample'
131
- })).rejects.toThrow('Plugin endpoint URL not found for missing-endpoint');
132
- });
133
- });
134
-
135
- describe('plugin data helpers', () => {
136
- test('should list persisted plugin data for an RC account', async () => {
137
- await AccountDataModel.bulkCreate([
138
- {
139
- rcAccountId: '12345',
140
- platformName: 'plugin-one',
141
- dataKey: 'pluginData',
142
- data: { endpointUrl: 'https://plugin-one.example.com' }
143
- },
144
- {
145
- rcAccountId: '12345',
146
- platformName: 'plugin-two',
147
- dataKey: 'pluginData',
148
- data: { endpointUrl: 'https://plugin-two.example.com' }
149
- },
150
- {
151
- rcAccountId: '12345',
152
- platformName: 'not-plugin',
153
- dataKey: 'otherData',
154
- data: { ignored: true }
155
- }
156
- ]);
157
-
158
- await expect(pluginHandler.getPluginsFromRcAccountId({ rcAccountId: '12345' }))
159
- .resolves.toEqual([
160
- { id: 'plugin-one', data: { endpointUrl: 'https://plugin-one.example.com' } },
161
- { id: 'plugin-two', data: { endpointUrl: 'https://plugin-two.example.com' } }
162
- ]);
163
- });
164
-
165
- test('should resolve plugin config from user settings and return null for missing config', () => {
166
- expect(pluginHandler.getPluginConfigFromUserSettings({
167
- userSettings: null,
168
- pluginId: 'plugin-one'
169
- })).toBeNull();
170
- expect(pluginHandler.getPluginConfigFromUserSettings({
171
- userSettings: {
172
- 'plugin_plugin-one': {
173
- value: {}
174
- }
175
- },
176
- pluginId: 'plugin-one'
177
- })).toBeNull();
178
- expect(pluginHandler.getPluginConfigFromUserSettings({
179
- userSettings: {
180
- 'plugin_plugin-one': {
181
- value: {
182
- config: {
183
- queueId: 'q-1'
184
- }
185
- }
186
- }
187
- },
188
- pluginId: 'plugin-one'
189
- })).toEqual({ queueId: 'q-1' });
190
- });
191
-
192
- test('should update existing plugin data and log persist failures without throwing', async () => {
193
- await AccountDataModel.create({
194
- rcAccountId: '12345',
195
- platformName: 'plugin-one',
196
- dataKey: 'pluginData',
197
- data: {
198
- jwtToken: 'old-token',
199
- endpointUrl: 'https://old.example.com'
200
- }
201
- });
202
-
203
- await pluginHandler.persistPluginData({
204
- rcAccountId: '12345',
205
- pluginId: 'plugin-one',
206
- jwtToken: 'new-token',
207
- pluginData: {
208
- endpointUrl: 'https://new.example.com'
209
- }
210
- });
211
-
212
- const updated = await AccountDataModel.findOne({
213
- where: {
214
- rcAccountId: '12345',
215
- platformName: 'plugin-one'
216
- }
217
- });
218
- expect(updated.data).toEqual({
219
- jwtToken: 'new-token',
220
- endpointUrl: 'https://new.example.com'
221
- });
222
-
223
- const errorSpy = jest.spyOn(logger, 'error').mockImplementation(() => {});
224
- jest.spyOn(AccountDataModel, 'findOne').mockRejectedValueOnce(new Error('db unavailable'));
225
- await expect(pluginHandler.persistPluginData({
226
- rcAccountId: '12345',
227
- pluginId: 'plugin-one',
228
- jwtToken: 'ignored'
229
- })).resolves.toBeUndefined();
230
- expect(errorSpy).toHaveBeenCalledWith('Failed to persist plugin data', {
231
- pluginId: 'plugin-one',
232
- rcAccountId: '12345',
233
- message: 'db unavailable'
234
- });
235
- });
236
- });
237
-
238
- describe('resolvePluginManifest', () => {
239
- test('should load private manifests with owner account id and infer the platform key', async () => {
240
- axios.get.mockResolvedValue({
241
- data: {
242
- platforms: {
243
- 'plugin.private': {
244
- endpointUrl: 'https://plugins.example.com/private',
245
- userRegisterEndpointUrl: 'https://plugins.example.com/private/register'
246
- }
247
- }
248
- }
249
- });
250
-
251
- const result = await pluginHandler.resolvePluginManifest({
252
- pluginId: 'private-plugin',
253
- pluginAccess: 'private',
254
- ownerRcAccountId: 'owner-account'
255
- });
256
-
257
- expect(axios.get).toHaveBeenCalledWith(
258
- 'https://appconnect.labs.ringcentral.com/public-api/connectors/private-plugin/manifest?access=internal&type=plugin&accountId=owner-account'
259
- );
260
- expect(result.platformKey).toBe('plugin.private');
261
- expect(result.pluginManifest.endpointUrl).toBe('https://plugins.example.com/private');
262
- });
263
-
264
- test('should fall back from public to internal manifest when access is unspecified', async () => {
265
- axios.get
266
- .mockRejectedValueOnce(new Error('public missing'))
267
- .mockResolvedValueOnce({
268
- data: {
269
- platforms: {
270
- 'plugin.shared': {
271
- endpointUrl: 'https://plugins.example.com/shared'
272
- }
273
- }
274
- }
275
- });
276
-
277
- const result = await pluginHandler.resolvePluginManifest({
278
- pluginId: 'shared-plugin',
279
- ownerRcAccountId: 'owner-account'
280
- });
281
-
282
- expect(axios.get).toHaveBeenCalledTimes(2);
283
- expect(axios.get.mock.calls[0][0]).toBe(
284
- 'https://appconnect.labs.ringcentral.com/public-api/connectors/shared-plugin/manifest?type=plugin'
285
- );
286
- expect(axios.get.mock.calls[1][0]).toBe(
287
- 'https://appconnect.labs.ringcentral.com/public-api/connectors/shared-plugin/manifest?access=internal&type=plugin&accountId=owner-account'
288
- );
289
- expect(result.platformKey).toBe('plugin.shared');
290
- });
291
-
292
- test('should throw the last manifest fetch error or platform resolution error', async () => {
293
- axios.get.mockRejectedValueOnce(new Error('manifest unavailable'));
294
-
295
- await expect(pluginHandler.resolvePluginManifest({
296
- pluginId: 'missing-plugin',
297
- pluginAccess: 'public'
298
- })).rejects.toThrow('manifest unavailable');
299
-
300
- axios.get.mockResolvedValueOnce({
301
- data: {
302
- platforms: {}
303
- }
304
- });
305
- await expect(pluginHandler.resolvePluginManifest({
306
- pluginId: 'empty-plugin',
307
- pluginAccess: 'public',
308
- pluginName: 'plugin.missing'
309
- })).rejects.toThrow('Unable to resolve platform manifest for plugin empty-plugin');
310
- });
311
- });
312
-
313
- describe('getPluginLicenseStatus', () => {
314
- test('should return null and skip provider call when plugin account data is missing', async () => {
315
- const result = await pluginHandler.getPluginLicenseStatus({
316
- rcAccountId: '12345',
317
- pluginId: 'sync-all-caps'
318
- });
319
-
320
- expect(result).toBeNull();
321
- expect(axios.get).not.toHaveBeenCalled();
322
- });
323
-
324
- test('should call plugin license status endpoint with stored plugin bearer token', async () => {
325
- const rcAccountId = '12345';
326
- const pluginId = 'sync-all-caps';
327
- await AccountDataModel.create({
328
- rcAccountId,
329
- platformName: pluginId,
330
- dataKey: 'pluginData',
331
- data: {
332
- jwtToken: 'plugin-jwt-token',
333
- licenseStatusUrl: `https://plugins.example.com/plugin/${pluginId}/license`
334
- }
335
- });
336
- axios.get.mockResolvedValue({
337
- data: {
338
- licenseStatus: true,
339
- licenseStatusDescription: 'Active'
340
- }
341
- });
342
-
343
- const result = await pluginHandler.getPluginLicenseStatus({ rcAccountId, pluginId });
344
-
345
- expect(axios.get).toHaveBeenCalledWith(
346
- `https://plugins.example.com/plugin/${pluginId}/license`,
347
- {
348
- headers: {
349
- Authorization: 'Bearer plugin-jwt-token'
350
- }
351
- }
352
- );
353
- expect(result).toEqual({
354
- licenseStatus: true,
355
- licenseStatusDescription: 'Active'
356
- });
357
- });
358
- test('should normalize non-standard plugin license provider responses to invalid status', async () => {
359
- const rcAccountId = '12345';
360
- const pluginId = 'sync-all-caps';
361
- await AccountDataModel.create({
362
- rcAccountId,
363
- platformName: pluginId,
364
- dataKey: 'pluginData',
365
- data: {
366
- jwtToken: 'plugin-jwt-token',
367
- licenseStatusUrl: `https://plugins.example.com/plugin/${pluginId}/license`
368
- }
369
- });
370
- axios.get.mockResolvedValue({
371
- data: {
372
- message: 'temporary unavailable'
373
- }
374
- });
375
-
376
- const result = await pluginHandler.getPluginLicenseStatus({ rcAccountId, pluginId });
377
-
378
- expect(result).toEqual({
379
- licenseStatus: false,
380
- licenseStatusDescription: 'Plugin license status unavailable'
381
- });
382
- });
383
- });
384
- describe('unregisterPluginAccount', () => {
385
- test('should remove persisted plugin account data', async () => {
386
- const rcAccountId = '12345';
387
- const pluginId = 'sync-all-caps';
388
- await AccountDataModel.create({
389
- rcAccountId,
390
- platformName: pluginId,
391
- dataKey: 'pluginData',
392
- data: {
393
- jwtToken: 'plugin-jwt-token'
394
- }
395
- });
396
-
397
- await pluginHandler.unregisterPluginAccount({ rcAccountId, pluginId });
398
-
399
- const accountData = await AccountDataModel.findOne({
400
- where: {
401
- rcAccountId,
402
- platformName: pluginId,
403
- dataKey: 'pluginData'
404
- }
405
- });
406
- expect(accountData).toBeNull();
407
- });
408
- });
409
- describe('token header helper', () => {
410
- test('should parse refreshed jwt token from response headers', () => {
411
- const token = pluginHandler.getRefreshedJwtTokenFromHeaders({
412
- headers: {
413
- 'x-refreshed-jwt-token': 'new-plugin-token'
414
- }
415
- });
416
- expect(token).toBe('new-plugin-token');
417
- });
418
-
419
- test('should parse uppercase refreshed jwt token header and return null without headers', () => {
420
- expect(pluginHandler.getRefreshedJwtTokenFromHeaders({ headers: null })).toBeNull();
421
- expect(pluginHandler.getRefreshedJwtTokenFromHeaders({
422
- headers: {
423
- 'X-Refreshed-Jwt-Token': 'upper-token'
424
- }
425
- })).toBe('upper-token');
426
- });
427
- });
428
- });
429
-