@app-connect/core 1.7.34 → 1.7.36
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.
- package/connector/mock.js +9 -4
- package/connector/proxy/engine.js +3 -2
- package/connector/proxy/index.js +2 -2
- package/docs/architecture.md +1 -0
- package/docs/handlers.md +1 -1
- package/docs/models.md +2 -0
- package/docs/routes.md +1 -1
- package/handlers/disposition.js +3 -2
- package/handlers/log.js +18 -6
- package/handlers/plugin.js +13 -6
- package/index.js +22 -11
- package/lib/callLogLookup.js +82 -9
- package/lib/migrateCallLogsSchema.js +128 -7
- package/models/callLogModel.js +6 -0
- package/package.json +1 -1
- package/releaseNotes.json +44 -0
- package/test/connector/developerPortal.test.js +166 -0
- package/test/connector/mock.test.js +131 -0
- package/test/connector/proxy/engine.test.js +85 -0
- package/test/connector/proxy/index.test.js +246 -0
- package/test/connector/proxy/sample.json +1 -0
- package/test/handlers/admin.test.js +344 -0
- package/test/handlers/appointment.test.js +260 -0
- package/test/handlers/auth.test.js +6 -2
- package/test/handlers/calldown.test.js +310 -0
- package/test/handlers/disposition.test.js +396 -0
- package/test/handlers/log.test.js +327 -3
- package/test/handlers/managedOAuth.test.js +262 -0
- package/test/handlers/plugin.test.js +305 -0
- package/test/handlers/user.test.js +381 -0
- package/test/index.test.js +166 -1
- package/test/lib/analytics.test.js +146 -0
- package/test/lib/authSession.test.js +173 -0
- package/test/lib/encode.test.js +59 -0
- package/test/lib/errorHandler.test.js +246 -0
- package/test/lib/generalErrorMessage.test.js +82 -0
- package/test/lib/s3ErrorLogReport.test.js +187 -0
- package/test/mcp/mcpHandlerMore.test.js +384 -0
- package/test/mcp/tools/appointmentTools.test.js +362 -0
- package/test/models/callDownListModel.test.js +125 -0
- package/test/models/dynamo/lockSchema.test.js +37 -0
- package/test/models/dynamo/noteCacheSchema.test.js +45 -0
- package/test/models/llmSessionModel.test.js +91 -0
- package/test/models/models.test.js +92 -0
- package/test/routes/calldownRoutes.test.js +224 -0
- package/test/routes/coreRouterBroadRoutes.test.js +855 -0
- package/test/routes/dispositionRoutes.test.js +192 -0
- package/test/routes/managedAuthRoutes.test.js +151 -0
- package/test/routes/pluginRoutes.test.js +262 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
jest.mock('../../lib/oauth');
|
|
2
|
+
jest.mock('../../models/dynamo/connectorSchema', () => ({
|
|
3
|
+
Connector: {
|
|
4
|
+
getProxyConfig: jest.fn(),
|
|
5
|
+
},
|
|
6
|
+
}));
|
|
7
|
+
|
|
8
|
+
const disposition = require('../../handlers/disposition');
|
|
9
|
+
const connectorRegistry = require('../../connector/registry');
|
|
10
|
+
const oauth = require('../../lib/oauth');
|
|
11
|
+
const { Connector } = require('../../models/dynamo/connectorSchema');
|
|
12
|
+
const { CallLogModel } = require('../../models/callLogModel');
|
|
13
|
+
const { UserModel } = require('../../models/userModel');
|
|
14
|
+
|
|
15
|
+
describe('Disposition Handler', () => {
|
|
16
|
+
beforeAll(async () => {
|
|
17
|
+
await UserModel.sync({ force: true });
|
|
18
|
+
await CallLogModel.sync({ force: true });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(async () => {
|
|
22
|
+
await CallLogModel.destroy({ where: {} });
|
|
23
|
+
await UserModel.destroy({ where: {} });
|
|
24
|
+
jest.restoreAllMocks();
|
|
25
|
+
jest.clearAllMocks();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
async function createUser(overrides = {}) {
|
|
29
|
+
return UserModel.create({
|
|
30
|
+
id: 'user-1',
|
|
31
|
+
platform: 'testCRM',
|
|
32
|
+
hostname: 'crm.example.com',
|
|
33
|
+
accessToken: 'access-token',
|
|
34
|
+
platformAdditionalInfo: {},
|
|
35
|
+
...overrides,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function createCallLog(overrides = {}) {
|
|
40
|
+
return CallLogModel.create({
|
|
41
|
+
id: 'call-log-1',
|
|
42
|
+
sessionId: 'session-1',
|
|
43
|
+
extensionNumber: '',
|
|
44
|
+
hashedExtensionId: '',
|
|
45
|
+
platform: 'testCRM',
|
|
46
|
+
thirdPartyLogId: 'third-party-log-1',
|
|
47
|
+
userId: 'user-1',
|
|
48
|
+
contactId: 'contact-1',
|
|
49
|
+
...overrides,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function mockApiKeyConnector(overrides = {}) {
|
|
54
|
+
return {
|
|
55
|
+
getAuthType: jest.fn().mockResolvedValue('apiKey'),
|
|
56
|
+
getBasicAuth: jest.fn().mockReturnValue('encoded-api-key'),
|
|
57
|
+
upsertCallDisposition: jest.fn().mockResolvedValue({
|
|
58
|
+
logId: 'disposition-log-1',
|
|
59
|
+
returnMessage: {
|
|
60
|
+
message: 'Disposition saved',
|
|
61
|
+
messageType: 'success',
|
|
62
|
+
ttl: 2000,
|
|
63
|
+
},
|
|
64
|
+
extraDataTracking: {
|
|
65
|
+
providerStatus: 'updated',
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
...overrides,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
test('returns a warning when no matching call log exists', async () => {
|
|
73
|
+
await createUser();
|
|
74
|
+
const getConnectorSpy = jest.spyOn(connectorRegistry, 'getConnector');
|
|
75
|
+
|
|
76
|
+
const result = await disposition.upsertCallDisposition({
|
|
77
|
+
platform: 'testCRM',
|
|
78
|
+
userId: 'user-1',
|
|
79
|
+
sessionId: 'missing-session',
|
|
80
|
+
dispositions: [{ id: 'disposition-1' }],
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect(result).toEqual({
|
|
84
|
+
successful: false,
|
|
85
|
+
returnMessage: {
|
|
86
|
+
message: 'Cannot find log',
|
|
87
|
+
messageType: 'warning',
|
|
88
|
+
ttl: 3000,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
expect(getConnectorSpy).not.toHaveBeenCalled();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('returns a warning when the matching call log exists but user is missing', async () => {
|
|
95
|
+
await createCallLog();
|
|
96
|
+
const getConnectorSpy = jest.spyOn(connectorRegistry, 'getConnector');
|
|
97
|
+
|
|
98
|
+
const result = await disposition.upsertCallDisposition({
|
|
99
|
+
platform: 'testCRM',
|
|
100
|
+
userId: 'missing-user',
|
|
101
|
+
sessionId: 'session-1',
|
|
102
|
+
dispositions: [{ id: 'disposition-1' }],
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
expect(result).toEqual({
|
|
106
|
+
successful: false,
|
|
107
|
+
returnMessage: {
|
|
108
|
+
message: 'Cannot find user',
|
|
109
|
+
messageType: 'warning',
|
|
110
|
+
ttl: 3000,
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
expect(getConnectorSpy).not.toHaveBeenCalled();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('upserts dispositions with apiKey auth and existing call log', async () => {
|
|
117
|
+
await createUser();
|
|
118
|
+
const existingCallLog = await createCallLog({
|
|
119
|
+
extensionNumber: '101',
|
|
120
|
+
});
|
|
121
|
+
const connector = mockApiKeyConnector();
|
|
122
|
+
jest.spyOn(connectorRegistry, 'getConnector').mockReturnValue(connector);
|
|
123
|
+
const dispositions = [
|
|
124
|
+
{ id: 'disp-1', value: 'Interested' },
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
const result = await disposition.upsertCallDisposition({
|
|
128
|
+
platform: 'testCRM',
|
|
129
|
+
userId: 'user-1',
|
|
130
|
+
sessionId: 'session-1',
|
|
131
|
+
extensionNumber: '101',
|
|
132
|
+
dispositions,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
expect(connectorRegistry.getConnector).toHaveBeenCalledWith('testCRM');
|
|
136
|
+
expect(connector.getAuthType).toHaveBeenCalledWith({
|
|
137
|
+
proxyId: undefined,
|
|
138
|
+
proxyConfig: null,
|
|
139
|
+
});
|
|
140
|
+
expect(connector.getBasicAuth).toHaveBeenCalledWith({
|
|
141
|
+
apiKey: 'access-token',
|
|
142
|
+
});
|
|
143
|
+
expect(connector.upsertCallDisposition).toHaveBeenCalledWith({
|
|
144
|
+
user: expect.objectContaining({ id: 'user-1' }),
|
|
145
|
+
existingCallLog: expect.objectContaining({
|
|
146
|
+
id: existingCallLog.id,
|
|
147
|
+
sessionId: 'session-1',
|
|
148
|
+
extensionNumber: '101',
|
|
149
|
+
}),
|
|
150
|
+
authHeader: 'Basic encoded-api-key',
|
|
151
|
+
dispositions,
|
|
152
|
+
proxyConfig: null,
|
|
153
|
+
});
|
|
154
|
+
expect(result).toEqual({
|
|
155
|
+
successful: true,
|
|
156
|
+
logId: 'disposition-log-1',
|
|
157
|
+
returnMessage: {
|
|
158
|
+
message: 'Disposition saved',
|
|
159
|
+
messageType: 'success',
|
|
160
|
+
ttl: 2000,
|
|
161
|
+
},
|
|
162
|
+
extraDataTracking: {
|
|
163
|
+
providerStatus: 'updated',
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('returns unsuccessful when provider upsert does not return a log id', async () => {
|
|
169
|
+
await createUser();
|
|
170
|
+
await createCallLog();
|
|
171
|
+
const connector = mockApiKeyConnector({
|
|
172
|
+
upsertCallDisposition: jest.fn().mockResolvedValue({
|
|
173
|
+
returnMessage: {
|
|
174
|
+
message: 'Provider did not update disposition',
|
|
175
|
+
messageType: 'warning',
|
|
176
|
+
ttl: 3000,
|
|
177
|
+
},
|
|
178
|
+
}),
|
|
179
|
+
});
|
|
180
|
+
jest.spyOn(connectorRegistry, 'getConnector').mockReturnValue(connector);
|
|
181
|
+
|
|
182
|
+
const result = await disposition.upsertCallDisposition({
|
|
183
|
+
platform: 'testCRM',
|
|
184
|
+
userId: 'user-1',
|
|
185
|
+
sessionId: 'session-1',
|
|
186
|
+
dispositions: [{ id: 'disp-1' }],
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
expect(result.successful).toBe(false);
|
|
190
|
+
expect(result.logId).toBeUndefined();
|
|
191
|
+
expect(result.returnMessage.message).toBe('Provider did not update disposition');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test('matches call log by hashed extension id when extension number differs', async () => {
|
|
195
|
+
await createUser();
|
|
196
|
+
await createCallLog({
|
|
197
|
+
id: 'hashed-call-log',
|
|
198
|
+
extensionNumber: '',
|
|
199
|
+
hashedExtensionId: 'hashed-extension-1',
|
|
200
|
+
});
|
|
201
|
+
const connector = mockApiKeyConnector();
|
|
202
|
+
jest.spyOn(connectorRegistry, 'getConnector').mockReturnValue(connector);
|
|
203
|
+
|
|
204
|
+
await disposition.upsertCallDisposition({
|
|
205
|
+
platform: 'testCRM',
|
|
206
|
+
userId: 'user-1',
|
|
207
|
+
sessionId: 'session-1',
|
|
208
|
+
extensionNumber: '101',
|
|
209
|
+
hashedExtensionId: 'hashed-extension-1',
|
|
210
|
+
dispositions: [{ id: 'disp-1' }],
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
expect(connector.upsertCallDisposition).toHaveBeenCalledWith(expect.objectContaining({
|
|
214
|
+
existingCallLog: expect.objectContaining({
|
|
215
|
+
id: 'hashed-call-log',
|
|
216
|
+
hashedExtensionId: 'hashed-extension-1',
|
|
217
|
+
}),
|
|
218
|
+
}));
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('falls back to legacy extension-number match when hashed extension id is provided', async () => {
|
|
222
|
+
await createUser();
|
|
223
|
+
await createCallLog({
|
|
224
|
+
id: 'legacy-extension-call-log',
|
|
225
|
+
extensionNumber: '101',
|
|
226
|
+
hashedExtensionId: '',
|
|
227
|
+
});
|
|
228
|
+
const connector = mockApiKeyConnector();
|
|
229
|
+
jest.spyOn(connectorRegistry, 'getConnector').mockReturnValue(connector);
|
|
230
|
+
|
|
231
|
+
await disposition.upsertCallDisposition({
|
|
232
|
+
platform: 'testCRM',
|
|
233
|
+
userId: 'user-1',
|
|
234
|
+
sessionId: 'session-1',
|
|
235
|
+
extensionNumber: '101',
|
|
236
|
+
hashedExtensionId: 'new-hashed-extension',
|
|
237
|
+
dispositions: [{ id: 'disp-1' }],
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
expect(connector.upsertCallDisposition).toHaveBeenCalledWith(expect.objectContaining({
|
|
241
|
+
existingCallLog: expect.objectContaining({
|
|
242
|
+
id: 'legacy-extension-call-log',
|
|
243
|
+
extensionNumber: '101',
|
|
244
|
+
hashedExtensionId: '',
|
|
245
|
+
}),
|
|
246
|
+
}));
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('uses OAuth app and refreshed access token for oauth connectors', async () => {
|
|
250
|
+
await createUser({
|
|
251
|
+
accessToken: 'old-access-token',
|
|
252
|
+
refreshToken: 'refresh-token',
|
|
253
|
+
platformAdditionalInfo: {
|
|
254
|
+
tokenUrl: 'https://crm.example.com/oauth/token',
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
await createCallLog();
|
|
258
|
+
const connector = mockApiKeyConnector({
|
|
259
|
+
getAuthType: jest.fn().mockResolvedValue('oauth'),
|
|
260
|
+
getOauthInfo: jest.fn().mockResolvedValue({
|
|
261
|
+
clientId: 'client-id',
|
|
262
|
+
clientSecret: 'client-secret',
|
|
263
|
+
}),
|
|
264
|
+
});
|
|
265
|
+
jest.spyOn(connectorRegistry, 'getConnector').mockReturnValue(connector);
|
|
266
|
+
const oauthApp = { app: true };
|
|
267
|
+
oauth.getOAuthApp.mockReturnValue(oauthApp);
|
|
268
|
+
oauth.checkAndRefreshAccessToken.mockResolvedValue({
|
|
269
|
+
id: 'user-1',
|
|
270
|
+
accessToken: 'refreshed-access-token',
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
await disposition.upsertCallDisposition({
|
|
274
|
+
platform: 'testCRM',
|
|
275
|
+
userId: 'user-1',
|
|
276
|
+
sessionId: 'session-1',
|
|
277
|
+
dispositions: [{ id: 'disp-1' }],
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
expect(connector.getOauthInfo).toHaveBeenCalledWith({
|
|
281
|
+
tokenUrl: 'https://crm.example.com/oauth/token',
|
|
282
|
+
hostname: 'crm.example.com',
|
|
283
|
+
proxyId: undefined,
|
|
284
|
+
proxyConfig: null,
|
|
285
|
+
});
|
|
286
|
+
expect(oauth.getOAuthApp).toHaveBeenCalledWith({
|
|
287
|
+
clientId: 'client-id',
|
|
288
|
+
clientSecret: 'client-secret',
|
|
289
|
+
});
|
|
290
|
+
expect(oauth.checkAndRefreshAccessToken).toHaveBeenCalledWith(oauthApp, expect.objectContaining({
|
|
291
|
+
id: 'user-1',
|
|
292
|
+
accessToken: 'old-access-token',
|
|
293
|
+
}));
|
|
294
|
+
expect(connector.upsertCallDisposition).toHaveBeenCalledWith(expect.objectContaining({
|
|
295
|
+
authHeader: 'Bearer refreshed-access-token',
|
|
296
|
+
user: expect.objectContaining({
|
|
297
|
+
accessToken: 'refreshed-access-token',
|
|
298
|
+
}),
|
|
299
|
+
}));
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
test('returns revoke-session warning when OAuth refresh cannot return a user', async () => {
|
|
303
|
+
await createUser();
|
|
304
|
+
await createCallLog();
|
|
305
|
+
const connector = mockApiKeyConnector({
|
|
306
|
+
getAuthType: jest.fn().mockResolvedValue('oauth'),
|
|
307
|
+
getOauthInfo: jest.fn().mockResolvedValue({}),
|
|
308
|
+
});
|
|
309
|
+
jest.spyOn(connectorRegistry, 'getConnector').mockReturnValue(connector);
|
|
310
|
+
oauth.getOAuthApp.mockReturnValue({});
|
|
311
|
+
oauth.checkAndRefreshAccessToken.mockResolvedValue(null);
|
|
312
|
+
|
|
313
|
+
const result = await disposition.upsertCallDisposition({
|
|
314
|
+
platform: 'testCRM',
|
|
315
|
+
userId: 'user-1',
|
|
316
|
+
sessionId: 'session-1',
|
|
317
|
+
dispositions: [{ id: 'disp-1' }],
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
expect(result).toEqual({
|
|
321
|
+
successful: false,
|
|
322
|
+
returnMessage: {
|
|
323
|
+
message: 'User session expired. Please connect again.',
|
|
324
|
+
messageType: 'warning',
|
|
325
|
+
ttl: 5000,
|
|
326
|
+
},
|
|
327
|
+
isRevokeUserSession: true,
|
|
328
|
+
});
|
|
329
|
+
expect(connector.upsertCallDisposition).not.toHaveBeenCalled();
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test('loads proxy config and passes it to connector methods', async () => {
|
|
333
|
+
await createUser({
|
|
334
|
+
platformAdditionalInfo: {
|
|
335
|
+
proxyId: 'proxy-1',
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
await createCallLog();
|
|
339
|
+
const proxyConfig = {
|
|
340
|
+
operations: {
|
|
341
|
+
upsertCallDisposition: { method: 'POST' },
|
|
342
|
+
},
|
|
343
|
+
};
|
|
344
|
+
Connector.getProxyConfig.mockResolvedValue(proxyConfig);
|
|
345
|
+
const connector = mockApiKeyConnector();
|
|
346
|
+
jest.spyOn(connectorRegistry, 'getConnector').mockReturnValue(connector);
|
|
347
|
+
|
|
348
|
+
await disposition.upsertCallDisposition({
|
|
349
|
+
platform: 'testCRM',
|
|
350
|
+
userId: 'user-1',
|
|
351
|
+
sessionId: 'session-1',
|
|
352
|
+
dispositions: [{ id: 'disp-1' }],
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
expect(Connector.getProxyConfig).toHaveBeenCalledWith('proxy-1');
|
|
356
|
+
expect(connector.getAuthType).toHaveBeenCalledWith({
|
|
357
|
+
proxyId: 'proxy-1',
|
|
358
|
+
proxyConfig,
|
|
359
|
+
});
|
|
360
|
+
expect(connector.upsertCallDisposition).toHaveBeenCalledWith(expect.objectContaining({
|
|
361
|
+
proxyConfig,
|
|
362
|
+
}));
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test('maps provider failures through the API error handler', async () => {
|
|
366
|
+
await createUser();
|
|
367
|
+
await createCallLog();
|
|
368
|
+
const providerError = new Error('provider unauthorized');
|
|
369
|
+
providerError.response = {
|
|
370
|
+
status: 401,
|
|
371
|
+
data: {
|
|
372
|
+
message: 'Unauthorized',
|
|
373
|
+
},
|
|
374
|
+
};
|
|
375
|
+
const connector = mockApiKeyConnector({
|
|
376
|
+
upsertCallDisposition: jest.fn().mockRejectedValue(providerError),
|
|
377
|
+
});
|
|
378
|
+
jest.spyOn(connectorRegistry, 'getConnector').mockReturnValue(connector);
|
|
379
|
+
|
|
380
|
+
const result = await disposition.upsertCallDisposition({
|
|
381
|
+
platform: 'testCRM',
|
|
382
|
+
userId: 'user-1',
|
|
383
|
+
sessionId: 'session-1',
|
|
384
|
+
extensionNumber: '101',
|
|
385
|
+
hashedExtensionId: 'hashed-extension-1',
|
|
386
|
+
dispositions: [{ id: 'disp-1' }],
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
expect(result.successful).toBe(false);
|
|
390
|
+
expect(result.returnMessage.message).toBe('Authorization error');
|
|
391
|
+
expect(result.extraDataTracking).toEqual({
|
|
392
|
+
statusCode: 401,
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
|