@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,328 +0,0 @@
1
- const { DebugTracer } = require('../../lib/debugTracer');
2
-
3
- describe('DebugTracer', () => {
4
- let tracer;
5
-
6
- beforeEach(() => {
7
- tracer = new DebugTracer();
8
- });
9
-
10
- describe('constructor', () => {
11
- test('should initialize with empty traces array', () => {
12
- expect(tracer.traces).toEqual([]);
13
- });
14
-
15
- test('should set start time', () => {
16
- expect(tracer.startTime).toBeDefined();
17
- expect(typeof tracer.startTime).toBe('number');
18
- });
19
-
20
- test('should generate unique request ID', () => {
21
- const tracer2 = new DebugTracer();
22
- expect(tracer.requestId).toBeDefined();
23
- expect(tracer.requestId).toMatch(/^req_\d+_[a-z0-9]+$/);
24
- expect(tracer.requestId).not.toBe(tracer2.requestId);
25
- });
26
-
27
- test('should accept headers parameter', () => {
28
- const headers = { 'x-request-id': 'custom-id' };
29
- const tracerWithHeaders = new DebugTracer(headers);
30
- expect(tracerWithHeaders.requestId).toBeDefined();
31
- });
32
- });
33
-
34
- describe('trace', () => {
35
- test('should add trace entry with method name and data', () => {
36
- tracer.trace('testMethod', { name: 'value', count: 42 });
37
-
38
- expect(tracer.traces).toHaveLength(1);
39
- expect(tracer.traces[0].methodName).toBe('testMethod');
40
- expect(tracer.traces[0].data).toEqual({ name: 'value', count: 42 });
41
- });
42
-
43
- test('should include timestamp and elapsed time', () => {
44
- tracer.trace('testMethod', {});
45
-
46
- expect(tracer.traces[0].timestamp).toBeDefined();
47
- expect(tracer.traces[0].elapsed).toBeGreaterThanOrEqual(0);
48
- });
49
-
50
- test('should default to info level', () => {
51
- tracer.trace('testMethod', {});
52
-
53
- expect(tracer.traces[0].level).toBe('info');
54
- });
55
-
56
- test('should allow custom log level', () => {
57
- tracer.trace('testMethod', {}, { level: 'warn' });
58
-
59
- expect(tracer.traces[0].level).toBe('warn');
60
- });
61
-
62
- test('should include stack trace by default', () => {
63
- tracer.trace('testMethod', {});
64
-
65
- expect(tracer.traces[0].stackTrace).toBeDefined();
66
- expect(Array.isArray(tracer.traces[0].stackTrace)).toBe(true);
67
- });
68
-
69
- test('should exclude stack trace when disabled', () => {
70
- tracer.trace('testMethod', {}, { includeStack: false });
71
-
72
- expect(tracer.traces[0].stackTrace).toBeUndefined();
73
- });
74
-
75
- test('should return this for chaining', () => {
76
- const result = tracer.trace('method1', {});
77
- expect(result).toBe(tracer);
78
-
79
- tracer.trace('method2', {}).trace('method3', {});
80
- expect(tracer.traces).toHaveLength(3);
81
- });
82
-
83
- test('should handle empty data object', () => {
84
- tracer.trace('testMethod');
85
-
86
- expect(tracer.traces[0].data).toEqual({});
87
- });
88
- });
89
-
90
- describe('traceError', () => {
91
- test('should add error trace with Error object', () => {
92
- const error = new Error('Test error message');
93
- tracer.traceError('failingMethod', error);
94
-
95
- expect(tracer.traces).toHaveLength(1);
96
- expect(tracer.traces[0].methodName).toBe('failingMethod');
97
- expect(tracer.traces[0].level).toBe('error');
98
- expect(tracer.traces[0].data.message).toBe('Test error message');
99
- expect(tracer.traces[0].data.errorStack).toContain('Error: Test error message');
100
- });
101
-
102
- test('should handle string error', () => {
103
- tracer.traceError('failingMethod', 'Something went wrong');
104
-
105
- expect(tracer.traces[0].data.message).toBe('Something went wrong');
106
- expect(tracer.traces[0].data.errorStack).toBeNull();
107
- });
108
-
109
- test('should include additional data', () => {
110
- const error = new Error('Test error');
111
- tracer.traceError('failingMethod', error, { userId: 'user-123', action: 'create' });
112
-
113
- expect(tracer.traces[0].data.userId).toBe('user-123');
114
- expect(tracer.traces[0].data.action).toBe('create');
115
- });
116
-
117
- test('should return this for chaining', () => {
118
- const result = tracer.traceError('method', new Error('test'));
119
- expect(result).toBe(tracer);
120
- });
121
- });
122
-
123
- describe('_sanitizeData', () => {
124
- test('should redact sensitive fields', () => {
125
- tracer.trace('testMethod', {
126
- accessToken: 'secret-token',
127
- refreshToken: 'secret-refresh',
128
- apiKey: 'api-key-123',
129
- password: 'secret-password',
130
- username: 'normal-field'
131
- });
132
-
133
- const data = tracer.traces[0].data;
134
- expect(data.accessToken).toBe('[REDACTED]');
135
- expect(data.refreshToken).toBe('[REDACTED]');
136
- expect(data.apiKey).toBe('[REDACTED]');
137
- expect(data.password).toBe('[REDACTED]');
138
- expect(data.username).toBe('normal-field');
139
- });
140
-
141
- test('should sanitize nested objects', () => {
142
- tracer.trace('testMethod', {
143
- user: {
144
- name: 'John',
145
- userPassword: 'secret123',
146
- userAccessToken: 'token123'
147
- }
148
- });
149
-
150
- const data = tracer.traces[0].data;
151
- expect(data.user.name).toBe('John');
152
- expect(data.user.userPassword).toBe('[REDACTED]');
153
- expect(data.user.userAccessToken).toBe('[REDACTED]');
154
- });
155
-
156
- test('should handle arrays', () => {
157
- tracer.trace('testMethod', {
158
- users: [
159
- { name: 'User1', apiKey: 'key1' },
160
- { name: 'User2', apiKey: 'key2' }
161
- ]
162
- });
163
-
164
- const data = tracer.traces[0].data;
165
- expect(data.users[0].name).toBe('User1');
166
- expect(data.users[0].apiKey).toBe('[REDACTED]');
167
- expect(data.users[1].apiKey).toBe('[REDACTED]');
168
- });
169
-
170
- test('should handle null and undefined data', () => {
171
- tracer.trace('testMethod', null);
172
- tracer.trace('testMethod2');
173
-
174
- expect(tracer.traces[0].data).toBeNull();
175
- // When undefined is passed, it defaults to {} from the default parameter
176
- expect(tracer.traces[1].data).toEqual({});
177
- });
178
-
179
- test('should handle primitive data', () => {
180
- tracer.trace('testMethod', 'string-value');
181
- tracer.trace('testMethod2', 42);
182
-
183
- expect(tracer.traces[0].data).toBe('string-value');
184
- expect(tracer.traces[1].data).toBe(42);
185
- });
186
-
187
- test('should redact case-insensitive sensitive fields', () => {
188
- tracer.trace('testMethod', {
189
- AccessToken: 'secret1',
190
- APIKEY: 'secret2',
191
- clientSecret: 'secret3'
192
- });
193
-
194
- const data = tracer.traces[0].data;
195
- expect(data.AccessToken).toBe('[REDACTED]');
196
- expect(data.APIKEY).toBe('[REDACTED]');
197
- expect(data.clientSecret).toBe('[REDACTED]');
198
- });
199
-
200
- test('should redact partial matches', () => {
201
- tracer.trace('testMethod', {
202
- userAuthToken: 'secret',
203
- adminCredentials: 'secret',
204
- myPrivateKey: 'secret'
205
- });
206
-
207
- const data = tracer.traces[0].data;
208
- expect(data.userAuthToken).toBe('[REDACTED]');
209
- expect(data.adminCredentials).toBe('[REDACTED]');
210
- expect(data.myPrivateKey).toBe('[REDACTED]');
211
- });
212
- });
213
-
214
- describe('getTraceData', () => {
215
- test('should return complete trace data', () => {
216
- tracer.trace('method1', { step: 1 });
217
- tracer.trace('method2', { step: 2 });
218
-
219
- const traceData = tracer.getTraceData();
220
-
221
- expect(traceData.requestId).toBe(tracer.requestId);
222
- expect(traceData.totalDuration).toMatch(/\d+ms$/);
223
- expect(traceData.traceCount).toBe(2);
224
- expect(traceData.traces).toHaveLength(2);
225
- });
226
-
227
- test('should return empty traces for new tracer', () => {
228
- const traceData = tracer.getTraceData();
229
-
230
- expect(traceData.traceCount).toBe(0);
231
- expect(traceData.traces).toEqual([]);
232
- });
233
- });
234
-
235
- describe('wrapResponse', () => {
236
- test('should add debug trace to response', () => {
237
- tracer.trace('processRequest', { action: 'test' });
238
-
239
- const response = { success: true, data: { id: 123 } };
240
- const wrappedResponse = tracer.wrapResponse(response);
241
-
242
- expect(wrappedResponse.success).toBe(true);
243
- expect(wrappedResponse.data).toEqual({ id: 123 });
244
- expect(wrappedResponse._debug).toBeDefined();
245
- expect(wrappedResponse._debug.requestId).toBe(tracer.requestId);
246
- });
247
-
248
- test('should preserve original response properties', () => {
249
- const response = {
250
- status: 200,
251
- message: 'OK',
252
- nested: { key: 'value' }
253
- };
254
-
255
- const wrapped = tracer.wrapResponse(response);
256
-
257
- expect(wrapped.status).toBe(200);
258
- expect(wrapped.message).toBe('OK');
259
- expect(wrapped.nested.key).toBe('value');
260
- });
261
- });
262
-
263
- describe('static fromRequest', () => {
264
- test('should create tracer from Express request', () => {
265
- const req = {
266
- headers: {
267
- 'x-request-id': 'req-123',
268
- 'content-type': 'application/json'
269
- }
270
- };
271
-
272
- const tracer = DebugTracer.fromRequest(req);
273
-
274
- expect(tracer).toBeInstanceOf(DebugTracer);
275
- expect(tracer.requestId).toBeDefined();
276
- });
277
-
278
- test('should handle request without headers', () => {
279
- const req = {};
280
-
281
- const tracer = DebugTracer.fromRequest(req);
282
-
283
- expect(tracer).toBeInstanceOf(DebugTracer);
284
- });
285
- });
286
-
287
- describe('_captureStackTrace', () => {
288
- test('should return array of stack trace lines', () => {
289
- tracer.trace('testMethod', {});
290
-
291
- const stackTrace = tracer.traces[0].stackTrace;
292
- expect(Array.isArray(stackTrace)).toBe(true);
293
- stackTrace.forEach(line => {
294
- expect(line).toMatch(/^at /);
295
- });
296
- });
297
- });
298
-
299
- describe('integration', () => {
300
- test('should track multiple operations', () => {
301
- tracer
302
- .trace('startOperation', { userId: 'user-123' })
303
- .trace('fetchData', { query: 'SELECT *' })
304
- .trace('processData', { count: 100 })
305
- .trace('saveResult', { success: true });
306
-
307
- const traceData = tracer.getTraceData();
308
- expect(traceData.traceCount).toBe(4);
309
-
310
- // Verify elapsed times are increasing
311
- for (let i = 1; i < tracer.traces.length; i++) {
312
- expect(tracer.traces[i].elapsed).toBeGreaterThanOrEqual(tracer.traces[i-1].elapsed);
313
- }
314
- });
315
-
316
- test('should handle error in the middle of operations', () => {
317
- tracer
318
- .trace('startOperation', { step: 1 })
319
- .traceError('failedOperation', new Error('Database error'), { query: 'INSERT' })
320
- .trace('cleanupOperation', { step: 3 });
321
-
322
- expect(tracer.traces).toHaveLength(3);
323
- expect(tracer.traces[1].level).toBe('error');
324
- expect(tracer.traces[2].level).toBe('info');
325
- });
326
- });
327
- });
328
-
@@ -1,59 +0,0 @@
1
- const { decoded, encode } = require('../../lib/encode');
2
-
3
- describe('encode', () => {
4
- const originalSecret = process.env.APP_SERVER_SECRET_KEY;
5
-
6
- afterEach(() => {
7
- if (originalSecret === undefined) {
8
- delete process.env.APP_SERVER_SECRET_KEY;
9
- } else {
10
- process.env.APP_SERVER_SECRET_KEY = originalSecret;
11
- }
12
- });
13
-
14
- test('encodes and decodes a string with a 32-character secret', () => {
15
- process.env.APP_SERVER_SECRET_KEY = '12345678901234567890123456789012';
16
-
17
- const encrypted = encode('sensitive token value');
18
-
19
- expect(encrypted).toMatch(/^[0-9a-f]+$/);
20
- expect(encrypted).not.toBe('sensitive token value');
21
- expect(decoded(encrypted)).toBe('sensitive token value');
22
- });
23
-
24
- test('throws a deterministic error when secret is missing', () => {
25
- delete process.env.APP_SERVER_SECRET_KEY;
26
-
27
- expect(() => encode('data')).toThrow('APP_SERVER_SECRET_KEY is not defined');
28
- expect(() => decoded('abcd')).toThrow('APP_SERVER_SECRET_KEY is not defined');
29
- });
30
-
31
- test('pads short secrets with spaces to 32 bytes', () => {
32
- process.env.APP_SERVER_SECRET_KEY = 'short-secret';
33
- const encryptedWithShortSecret = encode('payload');
34
-
35
- process.env.APP_SERVER_SECRET_KEY = 'short-secret'.padEnd(32, ' ');
36
- const encryptedWithPaddedSecret = encode('payload');
37
-
38
- expect(encryptedWithShortSecret).toBe(encryptedWithPaddedSecret);
39
- expect(decoded(encryptedWithShortSecret)).toBe('payload');
40
- });
41
-
42
- test('truncates long secrets to 32 bytes', () => {
43
- process.env.APP_SERVER_SECRET_KEY = '12345678901234567890123456789012-first-suffix';
44
- const encryptedWithLongSecret = encode('payload');
45
-
46
- process.env.APP_SERVER_SECRET_KEY = '12345678901234567890123456789012-second-suffix';
47
- const encryptedWithSamePrefix = encode('payload');
48
-
49
- expect(encryptedWithLongSecret).toBe(encryptedWithSamePrefix);
50
- expect(decoded(encryptedWithLongSecret)).toBe('payload');
51
- });
52
-
53
- test('throws when encrypted input is not valid hex ciphertext', () => {
54
- process.env.APP_SERVER_SECRET_KEY = '12345678901234567890123456789012';
55
-
56
- expect(() => decoded('not-valid-ciphertext')).toThrow();
57
- });
58
- });
59
-
@@ -1,246 +0,0 @@
1
- jest.mock('../../lib/logger', () => ({
2
- error: jest.fn(),
3
- }));
4
-
5
- const logger = require('../../lib/logger');
6
- const {
7
- asyncHandler,
8
- errorMiddleware,
9
- getOperationErrorMessage,
10
- handleApiError,
11
- handleDatabaseError,
12
- } = require('../../lib/errorHandler');
13
-
14
- describe('errorHandler', () => {
15
- beforeEach(() => {
16
- jest.clearAllMocks();
17
- });
18
-
19
- describe('handleApiError', () => {
20
- test('maps rate limit responses to the platform rate limit message', () => {
21
- const error = new Error('too many requests');
22
- error.response = {
23
- status: 429,
24
- data: { message: 'rate limited' },
25
- };
26
-
27
- const result = handleApiError(error, 'Clio', 'createCallLog', { accountId: 'account-1' });
28
-
29
- expect(logger.error).toHaveBeenCalledWith('createCallLog failed for platform Clio', expect.objectContaining({
30
- platform: 'Clio',
31
- operation: 'createCallLog',
32
- statusCode: 429,
33
- accountId: 'account-1',
34
- }));
35
- expect(result).toMatchObject({
36
- successful: false,
37
- extraDataTracking: { statusCode: 429 },
38
- });
39
- expect(result.returnMessage.message).toBe('Rate limit exceeded');
40
- expect(result.returnMessage.details[0].items[0].text).toContain('Clio');
41
- });
42
-
43
- test('maps 400-409 responses to authorization messages', () => {
44
- const error = new Error('unauthorized');
45
- error.response = {
46
- status: 401,
47
- data: { message: 'unauthorized' },
48
- };
49
-
50
- const result = handleApiError(error, 'Bullhorn', 'findContact');
51
-
52
- expect(result.successful).toBe(false);
53
- expect(result.extraDataTracking).toEqual({ statusCode: 401 });
54
- expect(result.returnMessage.message).toBe('Authorization error');
55
- expect(result.returnMessage.details[0].items[0].text).toContain('Bullhorn');
56
- });
57
-
58
- test('maps non-auth provider errors to operation-specific messages', () => {
59
- const error = new Error('provider unavailable');
60
- error.response = {
61
- status: 500,
62
- data: { message: 'unavailable' },
63
- };
64
-
65
- const result = handleApiError(error, 'Salesforce', 'updateCallLog');
66
-
67
- expect(result).toEqual({
68
- successful: false,
69
- returnMessage: {
70
- message: 'Error updating call log',
71
- messageType: 'warning',
72
- details: [
73
- {
74
- title: 'Details',
75
- items: [
76
- {
77
- id: 1,
78
- type: 'text',
79
- text: 'Please check if the log entity still exists on Salesforce and your account has permission to EDIT logs.',
80
- },
81
- ],
82
- },
83
- ],
84
- ttl: 5000,
85
- },
86
- extraDataTracking: {
87
- statusCode: 500,
88
- },
89
- });
90
- });
91
-
92
- test('uses unknown status when the error has no response status', () => {
93
- const result = handleApiError(new Error('network down'), 'Pipedrive', 'createContact');
94
-
95
- expect(result.extraDataTracking).toEqual({ statusCode: 'unknown' });
96
- expect(result.returnMessage.message).toBe('Error creating contact');
97
- });
98
- });
99
-
100
- describe('getOperationErrorMessage', () => {
101
- test('returns configured appointment messages with platform interpolation', () => {
102
- const result = getOperationErrorMessage('updateAppointment', 'Google');
103
-
104
- expect(result.message).toBe('Error updating appointment');
105
- expect(result.details[0].items[0].text).toContain('exists on Google');
106
- expect(result.details[0].items[0].id).toBe(1);
107
- });
108
-
109
- test('returns a generic message for unknown operations', () => {
110
- const result = getOperationErrorMessage('syncCustomObject', 'CRM');
111
-
112
- expect(result).toEqual({
113
- message: 'Error performing syncCustomObject',
114
- messageType: 'warning',
115
- details: [
116
- {
117
- title: 'Details',
118
- items: [
119
- {
120
- id: 1,
121
- type: 'text',
122
- text: 'Please check if your account has the necessary permissions.',
123
- },
124
- ],
125
- },
126
- ],
127
- ttl: 5000,
128
- });
129
- });
130
- });
131
-
132
- describe('handleDatabaseError', () => {
133
- test('logs context and returns the database warning response', () => {
134
- const error = new Error('connection lost');
135
-
136
- const result = handleDatabaseError(error, 'saveUser', { userId: 'user-1' });
137
-
138
- expect(logger.error).toHaveBeenCalledWith('Database operation failed: saveUser', expect.objectContaining({
139
- operation: 'saveUser',
140
- errorMessage: 'connection lost',
141
- userId: 'user-1',
142
- }));
143
- expect(result).toEqual({
144
- successful: false,
145
- returnMessage: {
146
- message: 'Database operation failed',
147
- messageType: 'warning',
148
- ttl: 5000,
149
- },
150
- });
151
- });
152
- });
153
-
154
- describe('asyncHandler', () => {
155
- test('passes through successful async handlers', async () => {
156
- const req = {};
157
- const res = {};
158
- const next = jest.fn();
159
- const handler = jest.fn().mockResolvedValue('done');
160
-
161
- asyncHandler(handler)(req, res, next);
162
- await Promise.resolve();
163
-
164
- expect(handler).toHaveBeenCalledWith(req, res, next);
165
- expect(next).not.toHaveBeenCalled();
166
- });
167
-
168
- test('forwards rejected async handlers to next', async () => {
169
- const req = {};
170
- const res = {};
171
- const next = jest.fn();
172
- const error = new Error('failed');
173
-
174
- asyncHandler(jest.fn().mockRejectedValue(error))(req, res, next);
175
- await Promise.resolve();
176
-
177
- expect(next).toHaveBeenCalledWith(error);
178
- });
179
- });
180
-
181
- describe('errorMiddleware', () => {
182
- const originalNodeEnv = process.env.NODE_ENV;
183
-
184
- afterEach(() => {
185
- process.env.NODE_ENV = originalNodeEnv;
186
- });
187
-
188
- test('responds with development error details and request status code', () => {
189
- process.env.NODE_ENV = 'test';
190
- const err = new Error('visible error');
191
- err.statusCode = 418;
192
- const req = {
193
- platform: 'Clio',
194
- method: 'POST',
195
- path: '/test',
196
- route: { path: '/test' },
197
- correlationId: 'correlation-1',
198
- };
199
- const res = {
200
- status: jest.fn().mockReturnThis(),
201
- json: jest.fn(),
202
- };
203
-
204
- errorMiddleware(err, req, res, jest.fn());
205
-
206
- expect(logger.error).toHaveBeenCalledWith('Request failed', expect.objectContaining({
207
- platform: 'Clio',
208
- operation: '/test',
209
- method: 'POST',
210
- path: '/test',
211
- statusCode: 418,
212
- correlationId: 'correlation-1',
213
- }));
214
- expect(res.status).toHaveBeenCalledWith(418);
215
- expect(res.json).toHaveBeenCalledWith({
216
- successful: false,
217
- returnMessage: {
218
- message: 'visible error',
219
- messageType: 'error',
220
- ttl: 5000,
221
- },
222
- });
223
- });
224
-
225
- test('hides internal error details in production', () => {
226
- process.env.NODE_ENV = 'production';
227
- const res = {
228
- status: jest.fn().mockReturnThis(),
229
- json: jest.fn(),
230
- };
231
-
232
- errorMiddleware(new Error('secret detail'), { query: { platform: 'CRM' } }, res, jest.fn());
233
-
234
- expect(res.status).toHaveBeenCalledWith(500);
235
- expect(res.json).toHaveBeenCalledWith({
236
- successful: false,
237
- returnMessage: {
238
- message: 'An internal error occurred',
239
- messageType: 'error',
240
- ttl: 5000,
241
- },
242
- });
243
- });
244
- });
245
- });
246
-