@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
@@ -1,660 +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
-
13
- const { CallLogModel } = require('../../models/callLogModel');
14
- const { MessageLogModel } = require('../../models/messageLogModel');
15
- const { UserModel } = require('../../models/userModel');
16
- const { CacheModel } = require('../../models/cacheModel');
17
- const { AdminConfigModel } = require('../../models/adminConfigModel');
18
- const { sequelize } = require('../../models/sequelize');
19
- const {
20
- ensureCallLogsHashedExtensionIdSchema,
21
- sqliteCallLogsPkIncludesHashedExtension,
22
- } = require('../../lib/migrateCallLogsSchema');
23
-
24
- describe('Core Models', () => {
25
- beforeAll(async () => {
26
- await CallLogModel.sync({ force: true });
27
- await MessageLogModel.sync({ force: true });
28
- await UserModel.sync({ force: true });
29
- await CacheModel.sync({ force: true });
30
- await AdminConfigModel.sync({ force: true });
31
- });
32
-
33
- afterEach(async () => {
34
- await CallLogModel.destroy({ where: {} });
35
- await MessageLogModel.destroy({ where: {} });
36
- await UserModel.destroy({ where: {} });
37
- await CacheModel.destroy({ where: {} });
38
- await AdminConfigModel.destroy({ where: {} });
39
- });
40
-
41
- afterAll(async () => {
42
- await sequelize.close();
43
- });
44
-
45
- describe('UserModel', () => {
46
- test('should create user with required fields', async () => {
47
- // Arrange & Act
48
- const user = await UserModel.create({
49
- id: 'user-1',
50
- platform: 'testCRM',
51
- accessToken: 'token-123'
52
- });
53
-
54
- // Assert
55
- expect(user.id).toBe('user-1');
56
- expect(user.platform).toBe('testCRM');
57
- expect(user.accessToken).toBe('token-123');
58
- });
59
-
60
- test('should create user with all optional fields', async () => {
61
- // Arrange
62
- const tokenExpiry = new Date('2024-12-31');
63
-
64
- // Act
65
- const user = await UserModel.create({
66
- id: 'user-full',
67
- platform: 'testCRM',
68
- hostname: 'test.example.com',
69
- accessToken: 'token-123',
70
- refreshToken: 'refresh-123',
71
- tokenExpiry: tokenExpiry,
72
- rcAccountId: 'rc-account-123',
73
- timezoneOffset: '-08:00',
74
- timezoneName: 'America/Los_Angeles',
75
- platformAdditionalInfo: { customField: 'value' },
76
- userSettings: { autoLog: true }
77
- });
78
-
79
- // Assert
80
- expect(user.hostname).toBe('test.example.com');
81
- expect(user.refreshToken).toBe('refresh-123');
82
- expect(user.rcAccountId).toBe('rc-account-123');
83
- expect(user.platformAdditionalInfo).toEqual({ customField: 'value' });
84
- expect(user.userSettings).toEqual({ autoLog: true });
85
- });
86
-
87
- test('should find user by primary key', async () => {
88
- // Arrange
89
- await UserModel.create({
90
- id: 'user-find',
91
- platform: 'testCRM',
92
- accessToken: 'token'
93
- });
94
-
95
- // Act
96
- const user = await UserModel.findByPk('user-find');
97
-
98
- // Assert
99
- expect(user).not.toBeNull();
100
- expect(user.id).toBe('user-find');
101
- });
102
-
103
- test('should find user by platform and id', async () => {
104
- // Arrange
105
- await UserModel.create({
106
- id: 'user-platform',
107
- platform: 'testCRM',
108
- accessToken: 'token'
109
- });
110
-
111
- // Act
112
- const user = await UserModel.findOne({
113
- where: { id: 'user-platform', platform: 'testCRM' }
114
- });
115
-
116
- // Assert
117
- expect(user).not.toBeNull();
118
- expect(user.platform).toBe('testCRM');
119
- });
120
-
121
- test('should update user fields', async () => {
122
- // Arrange
123
- const user = await UserModel.create({
124
- id: 'user-update',
125
- platform: 'testCRM',
126
- accessToken: 'old-token'
127
- });
128
-
129
- // Act
130
- await user.update({ accessToken: 'new-token' });
131
-
132
- // Assert
133
- const updated = await UserModel.findByPk('user-update');
134
- expect(updated.accessToken).toBe('new-token');
135
- });
136
-
137
- test('should delete user', async () => {
138
- // Arrange
139
- await UserModel.create({
140
- id: 'user-delete',
141
- platform: 'testCRM',
142
- accessToken: 'token'
143
- });
144
-
145
- // Act
146
- await UserModel.destroy({ where: { id: 'user-delete' } });
147
-
148
- // Assert
149
- const user = await UserModel.findByPk('user-delete');
150
- expect(user).toBeNull();
151
- });
152
- });
153
-
154
- describe('CallLogModel', () => {
155
- test('should create call log with required fields', async () => {
156
- // Arrange & Act
157
- const log = await CallLogModel.create({
158
- id: 'call-1',
159
- sessionId: 'session-123',
160
- platform: 'testCRM',
161
- thirdPartyLogId: 'third-party-1',
162
- userId: 'user-1'
163
- });
164
-
165
- // Assert
166
- expect(log.id).toBe('call-1');
167
- expect(log.sessionId).toBe('session-123');
168
- expect(log.thirdPartyLogId).toBe('third-party-1');
169
- });
170
-
171
- test('should create call log with optional contactId', async () => {
172
- // Act
173
- const log = await CallLogModel.create({
174
- id: 'call-contact',
175
- sessionId: 'session-456',
176
- platform: 'testCRM',
177
- thirdPartyLogId: 'third-party-2',
178
- userId: 'user-1',
179
- contactId: 'contact-123'
180
- });
181
-
182
- // Assert
183
- expect(log.contactId).toBe('contact-123');
184
- });
185
-
186
- test('should use extensionNumber as part of call log primary key', async () => {
187
- // Arrange & Act
188
- await CallLogModel.create({
189
- id: 'call-shared',
190
- sessionId: 'session-shared',
191
- extensionNumber: '101',
192
- platform: 'testCRM',
193
- thirdPartyLogId: 'third-party-101',
194
- userId: 'user-1'
195
- });
196
- await CallLogModel.create({
197
- id: 'call-shared',
198
- sessionId: 'session-shared',
199
- extensionNumber: '102',
200
- platform: 'testCRM',
201
- thirdPartyLogId: 'third-party-102',
202
- userId: 'user-1'
203
- });
204
-
205
- // Assert
206
- const logs = await CallLogModel.findAll({
207
- where: {
208
- id: 'call-shared',
209
- sessionId: 'session-shared'
210
- }
211
- });
212
- expect(logs).toHaveLength(2);
213
- });
214
-
215
- test('should use hashedExtensionId as part of call log primary key', async () => {
216
- // Arrange & Act
217
- await CallLogModel.create({
218
- id: 'call-shared-hash',
219
- sessionId: 'session-shared-hash',
220
- extensionNumber: '',
221
- hashedExtensionId: 'hashed-1',
222
- platform: 'testCRM',
223
- thirdPartyLogId: 'third-party-hash-1',
224
- userId: 'user-1'
225
- });
226
- await CallLogModel.create({
227
- id: 'call-shared-hash',
228
- sessionId: 'session-shared-hash',
229
- extensionNumber: '',
230
- hashedExtensionId: 'hashed-2',
231
- platform: 'testCRM',
232
- thirdPartyLogId: 'third-party-hash-2',
233
- userId: 'user-1'
234
- });
235
-
236
- // Assert
237
- const logs = await CallLogModel.findAll({
238
- where: {
239
- id: 'call-shared-hash',
240
- sessionId: 'session-shared-hash'
241
- }
242
- });
243
- expect(logs).toHaveLength(2);
244
- });
245
-
246
- test('should migrate legacy call log schema to hashed extension identity key', async () => {
247
- await CallLogModel.drop();
248
- await sequelize.query(`
249
- CREATE TABLE callLogs (
250
- id VARCHAR(255) NOT NULL,
251
- sessionId VARCHAR(255) NOT NULL,
252
- extensionNumber VARCHAR(255) NOT NULL DEFAULT '',
253
- platform VARCHAR(255),
254
- thirdPartyLogId VARCHAR(255),
255
- userId VARCHAR(255),
256
- contactId VARCHAR(255),
257
- createdAt DATETIME NOT NULL,
258
- updatedAt DATETIME NOT NULL,
259
- PRIMARY KEY (id, sessionId, extensionNumber)
260
- );
261
- `);
262
- await sequelize.query(`
263
- INSERT INTO callLogs (
264
- id,
265
- sessionId,
266
- extensionNumber,
267
- platform,
268
- thirdPartyLogId,
269
- userId,
270
- contactId,
271
- createdAt,
272
- updatedAt
273
- ) VALUES (
274
- 'legacy-call',
275
- 'legacy-session',
276
- '101',
277
- 'testCRM',
278
- 'third-party-legacy',
279
- 'user-1',
280
- 'contact-1',
281
- '2026-01-01T00:00:00.000Z',
282
- '2026-01-01T00:00:00.000Z'
283
- );
284
- `);
285
-
286
- await ensureCallLogsHashedExtensionIdSchema(sequelize);
287
-
288
- const tableDescription = await sequelize.getQueryInterface().describeTable('callLogs');
289
- expect(tableDescription.hashedExtensionId).toBeDefined();
290
- await expect(sqliteCallLogsPkIncludesHashedExtension(sequelize)).resolves.toBe(true);
291
- const migratedLog = await CallLogModel.findOne({
292
- where: {
293
- id: 'legacy-call',
294
- sessionId: 'legacy-session',
295
- extensionNumber: '101',
296
- hashedExtensionId: ''
297
- }
298
- });
299
- expect(migratedLog).not.toBeNull();
300
- expect(migratedLog.thirdPartyLogId).toBe('third-party-legacy');
301
- });
302
-
303
- test('should find call logs by session ID', async () => {
304
- // Arrange
305
- await CallLogModel.create({
306
- id: 'call-session',
307
- sessionId: 'unique-session',
308
- platform: 'testCRM',
309
- thirdPartyLogId: 'third-party-3',
310
- userId: 'user-1'
311
- });
312
-
313
- // Act
314
- const log = await CallLogModel.findOne({
315
- where: { sessionId: 'unique-session' }
316
- });
317
-
318
- // Assert
319
- expect(log).not.toBeNull();
320
- expect(log.id).toBe('call-session');
321
- });
322
-
323
- test('should find multiple call logs by session IDs', async () => {
324
- // Arrange
325
- await CallLogModel.bulkCreate([
326
- { id: 'call-multi-1', sessionId: 'session-a', platform: 'testCRM', thirdPartyLogId: 'tp-1', userId: 'user-1' },
327
- { id: 'call-multi-2', sessionId: 'session-b', platform: 'testCRM', thirdPartyLogId: 'tp-2', userId: 'user-1' },
328
- { id: 'call-multi-3', sessionId: 'session-c', platform: 'testCRM', thirdPartyLogId: 'tp-3', userId: 'user-1' }
329
- ]);
330
-
331
- // Act
332
- const { Op } = require('sequelize');
333
- const logs = await CallLogModel.findAll({
334
- where: {
335
- sessionId: { [Op.in]: ['session-a', 'session-c'] }
336
- }
337
- });
338
-
339
- // Assert
340
- expect(logs).toHaveLength(2);
341
- });
342
- });
343
-
344
- describe('MessageLogModel', () => {
345
- test('should create message log with required fields', async () => {
346
- // Arrange & Act
347
- const log = await MessageLogModel.create({
348
- id: 'msg-1',
349
- platform: 'testCRM',
350
- conversationId: 'conv-123',
351
- thirdPartyLogId: 'third-party-msg-1',
352
- userId: 'user-1'
353
- });
354
-
355
- // Assert
356
- expect(log.id).toBe('msg-1');
357
- expect(log.conversationId).toBe('conv-123');
358
- });
359
-
360
- test('should create message log with conversationLogId', async () => {
361
- // Act
362
- const log = await MessageLogModel.create({
363
- id: 'msg-conv',
364
- platform: 'testCRM',
365
- conversationId: 'conv-456',
366
- conversationLogId: 'conv-log-456',
367
- thirdPartyLogId: 'third-party-msg-2',
368
- userId: 'user-1'
369
- });
370
-
371
- // Assert
372
- expect(log.conversationLogId).toBe('conv-log-456');
373
- });
374
-
375
- test('should find message logs by conversation ID', async () => {
376
- // Arrange
377
- await MessageLogModel.create({
378
- id: 'msg-find',
379
- platform: 'testCRM',
380
- conversationId: 'conv-find',
381
- thirdPartyLogId: 'third-party-find',
382
- userId: 'user-1'
383
- });
384
-
385
- // Act
386
- const log = await MessageLogModel.findOne({
387
- where: { conversationId: 'conv-find' }
388
- });
389
-
390
- // Assert
391
- expect(log).not.toBeNull();
392
- expect(log.id).toBe('msg-find');
393
- });
394
-
395
- test('should find message logs by conversationLogId', async () => {
396
- // Arrange
397
- await MessageLogModel.create({
398
- id: 'msg-conv-log',
399
- platform: 'testCRM',
400
- conversationId: 'conv-789',
401
- conversationLogId: 'conv-log-789',
402
- thirdPartyLogId: 'third-party-789',
403
- userId: 'user-1'
404
- });
405
-
406
- // Act
407
- const log = await MessageLogModel.findOne({
408
- where: { conversationLogId: 'conv-log-789' }
409
- });
410
-
411
- // Assert
412
- expect(log).not.toBeNull();
413
- expect(log.conversationLogId).toBe('conv-log-789');
414
- });
415
- });
416
-
417
- describe('CacheModel', () => {
418
- test('should create cache entry', async () => {
419
- // Arrange & Act
420
- const cache = await CacheModel.create({
421
- id: 'cache-1',
422
- userId: 'user-123',
423
- cacheKey: 'contacts',
424
- status: 'active'
425
- });
426
-
427
- // Assert
428
- expect(cache.id).toBe('cache-1');
429
- expect(cache.userId).toBe('user-123');
430
- expect(cache.cacheKey).toBe('contacts');
431
- expect(cache.status).toBe('active');
432
- });
433
-
434
- test('should update cache status', async () => {
435
- // Arrange
436
- const cache = await CacheModel.create({
437
- id: 'cache-update',
438
- userId: 'user-123',
439
- cacheKey: 'contacts',
440
- status: 'pending'
441
- });
442
-
443
- // Act
444
- await cache.update({ status: 'completed' });
445
-
446
- // Assert
447
- const updated = await CacheModel.findByPk('cache-update');
448
- expect(updated.status).toBe('completed');
449
- });
450
-
451
- test('should find cache by userId and cacheKey', async () => {
452
- // Arrange
453
- await CacheModel.create({
454
- id: 'cache-find',
455
- userId: 'user-find',
456
- cacheKey: 'contacts-cache',
457
- status: 'active'
458
- });
459
-
460
- // Act
461
- const cache = await CacheModel.findOne({
462
- where: { userId: 'user-find', cacheKey: 'contacts-cache' }
463
- });
464
-
465
- // Assert
466
- expect(cache).not.toBeNull();
467
- expect(cache.status).toBe('active');
468
- });
469
- });
470
-
471
- describe('AdminConfigModel', () => {
472
- test('should create admin config with basic settings', async () => {
473
- // Arrange & Act
474
- const config = await AdminConfigModel.create({
475
- id: 'admin-1',
476
- userSettings: { autoLogCalls: true, autoLogMessages: false }
477
- });
478
-
479
- // Assert
480
- expect(config.id).toBe('admin-1');
481
- expect(config.userSettings).toEqual({ autoLogCalls: true, autoLogMessages: false });
482
- });
483
-
484
- test('should create admin config with tokens', async () => {
485
- // Arrange
486
- const expiry = new Date('2024-12-31');
487
-
488
- // Act
489
- const config = await AdminConfigModel.create({
490
- id: 'admin-tokens',
491
- adminAccessToken: 'access-token',
492
- adminRefreshToken: 'refresh-token',
493
- adminTokenExpiry: expiry
494
- });
495
-
496
- // Assert
497
- expect(config.adminAccessToken).toBe('access-token');
498
- expect(config.adminRefreshToken).toBe('refresh-token');
499
- });
500
-
501
- test('should create admin config with user mappings', async () => {
502
- // Arrange
503
- const userMappings = [
504
- { crmUserId: 'crm-1', rcExtensionId: ['ext-1'] },
505
- { crmUserId: 'crm-2', rcExtensionId: ['ext-2', 'ext-3'] }
506
- ];
507
-
508
- // Act
509
- const config = await AdminConfigModel.create({
510
- id: 'admin-mappings',
511
- userMappings: userMappings
512
- });
513
-
514
- // Assert
515
- expect(config.userMappings).toEqual(userMappings);
516
- });
517
-
518
- test('should update admin config settings', async () => {
519
- // Arrange
520
- const config = await AdminConfigModel.create({
521
- id: 'admin-update',
522
- userSettings: { autoLog: false }
523
- });
524
-
525
- // Act
526
- await config.update({ userSettings: { autoLog: true } });
527
-
528
- // Assert
529
- const updated = await AdminConfigModel.findByPk('admin-update');
530
- expect(updated.userSettings).toEqual({ autoLog: true });
531
- });
532
-
533
- test('should find admin config by primary key', async () => {
534
- // Arrange
535
- await AdminConfigModel.create({
536
- id: 'admin-find',
537
- userSettings: { enabled: true }
538
- });
539
-
540
- // Act
541
- const config = await AdminConfigModel.findByPk('admin-find');
542
-
543
- // Assert
544
- expect(config).not.toBeNull();
545
- expect(config.id).toBe('admin-find');
546
- });
547
- });
548
-
549
- describe('Model Relationships and Edge Cases', () => {
550
- test('should handle null JSON fields', async () => {
551
- // Act
552
- const user = await UserModel.create({
553
- id: 'user-null-json',
554
- platform: 'testCRM',
555
- accessToken: 'token',
556
- platformAdditionalInfo: null,
557
- userSettings: null
558
- });
559
-
560
- // Assert
561
- expect(user.platformAdditionalInfo).toBeNull();
562
- expect(user.userSettings).toBeNull();
563
- });
564
-
565
- test('should handle empty JSON objects', async () => {
566
- // Act
567
- const user = await UserModel.create({
568
- id: 'user-empty-json',
569
- platform: 'testCRM',
570
- accessToken: 'token',
571
- platformAdditionalInfo: {},
572
- userSettings: {}
573
- });
574
-
575
- // Assert
576
- expect(user.platformAdditionalInfo).toEqual({});
577
- expect(user.userSettings).toEqual({});
578
- });
579
-
580
- test('should handle complex nested JSON', async () => {
581
- // Arrange
582
- const complexData = {
583
- level1: {
584
- level2: {
585
- level3: {
586
- value: 'deep',
587
- array: [1, 2, 3]
588
- }
589
- },
590
- items: [
591
- { id: 1, name: 'Item 1' },
592
- { id: 2, name: 'Item 2' }
593
- ]
594
- }
595
- };
596
-
597
- // Act
598
- const user = await UserModel.create({
599
- id: 'user-complex-json',
600
- platform: 'testCRM',
601
- accessToken: 'token',
602
- platformAdditionalInfo: complexData
603
- });
604
-
605
- // Assert
606
- expect(user.platformAdditionalInfo).toEqual(complexData);
607
- expect(user.platformAdditionalInfo.level1.level2.level3.value).toBe('deep');
608
- });
609
-
610
- test('should enforce unique primary key constraint', async () => {
611
- // Arrange
612
- await UserModel.create({
613
- id: 'unique-user',
614
- platform: 'testCRM',
615
- accessToken: 'token-1'
616
- });
617
-
618
- // Act & Assert
619
- await expect(
620
- UserModel.create({
621
- id: 'unique-user',
622
- platform: 'testCRM',
623
- accessToken: 'token-2'
624
- })
625
- ).rejects.toThrow();
626
- });
627
-
628
- test('should handle bulk create', async () => {
629
- // Arrange
630
- const users = [
631
- { id: 'bulk-1', platform: 'testCRM', accessToken: 'token-1' },
632
- { id: 'bulk-2', platform: 'testCRM', accessToken: 'token-2' },
633
- { id: 'bulk-3', platform: 'testCRM', accessToken: 'token-3' }
634
- ];
635
-
636
- // Act
637
- await UserModel.bulkCreate(users);
638
-
639
- // Assert
640
- const count = await UserModel.count({ where: { platform: 'testCRM' } });
641
- expect(count).toBe(3);
642
- });
643
-
644
- test('should handle bulk destroy', async () => {
645
- // Arrange
646
- await UserModel.bulkCreate([
647
- { id: 'destroy-1', platform: 'destroyTest', accessToken: 'token-1' },
648
- { id: 'destroy-2', platform: 'destroyTest', accessToken: 'token-2' }
649
- ]);
650
-
651
- // Act
652
- await UserModel.destroy({ where: { platform: 'destroyTest' } });
653
-
654
- // Assert
655
- const count = await UserModel.count({ where: { platform: 'destroyTest' } });
656
- expect(count).toBe(0);
657
- });
658
- });
659
- });
660
-