@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.
- package/README.md +17 -16
- package/dist/connector/developerPortal.d.ts +6 -0
- package/{connector → dist/connector}/developerPortal.js +29 -12
- package/dist/connector/mock.d.ts +1 -0
- package/{connector → dist/connector}/mock.js +33 -17
- package/dist/connector/proxy/engine.d.ts +10 -0
- package/dist/connector/proxy/engine.js +222 -0
- package/dist/connector/proxy/index.d.ts +5 -0
- package/dist/connector/proxy/index.js +511 -0
- package/dist/connector/registry.d.ts +1 -0
- package/dist/connector/registry.js +243 -0
- package/dist/handlers/admin.d.ts +1 -0
- package/{handlers → dist/handlers}/admin.js +137 -78
- package/dist/handlers/appointment.d.ts +9 -0
- package/{handlers → dist/handlers}/appointment.js +58 -29
- package/dist/handlers/auth.d.ts +9 -0
- package/{handlers → dist/handlers}/auth.js +68 -40
- package/dist/handlers/calldown.d.ts +10 -0
- package/dist/handlers/calldown.js +134 -0
- package/dist/handlers/contact.d.ts +1 -0
- package/{handlers → dist/handlers}/contact.js +61 -39
- package/dist/handlers/disposition.d.ts +1 -0
- package/{handlers → dist/handlers}/disposition.js +20 -10
- package/dist/handlers/log.d.ts +1 -0
- package/{handlers → dist/handlers}/log.js +91 -124
- package/dist/handlers/managedAuth.d.ts +1 -0
- package/{handlers → dist/handlers}/managedAuth.js +134 -61
- package/dist/handlers/managedOAuth.d.ts +13 -0
- package/{handlers → dist/handlers}/managedOAuth.js +102 -30
- package/dist/handlers/plugin.d.ts +1 -0
- package/{handlers → dist/handlers}/plugin.js +59 -27
- package/dist/handlers/user.d.ts +1 -0
- package/{handlers → dist/handlers}/user.js +45 -27
- package/dist/index.d.ts +1 -0
- package/{index.js → dist/index.js} +538 -449
- package/dist/jest.config.d.ts +1 -0
- package/dist/jest.config.js +65 -0
- package/dist/lib/analytics.d.ts +4 -0
- package/{lib → dist/lib}/analytics.js +8 -6
- package/dist/lib/authSession.d.ts +5 -0
- package/{lib → dist/lib}/authSession.js +15 -43
- package/dist/lib/cacheCleanup.d.ts +4 -0
- package/{lib → dist/lib}/cacheCleanup.js +5 -17
- package/dist/lib/callLogComposer.d.ts +109 -0
- package/{lib → dist/lib}/callLogComposer.js +157 -197
- package/dist/lib/callLogLookup.d.ts +6 -0
- package/{lib → dist/lib}/callLogLookup.js +12 -34
- package/dist/lib/constants.d.ts +6 -0
- package/dist/lib/constants.js +9 -0
- package/dist/lib/debugTracer.d.ts +17 -0
- package/{lib → dist/lib}/debugTracer.js +7 -83
- package/dist/lib/encode.d.ts +3 -0
- package/dist/lib/encode.js +50 -0
- package/dist/lib/errorHandler.d.ts +7 -0
- package/dist/lib/errorHandler.js +161 -0
- package/dist/lib/generalErrorMessage.d.ts +7 -0
- package/{lib → dist/lib}/generalErrorMessage.js +6 -6
- package/dist/lib/jwt.d.ts +4 -0
- package/dist/lib/jwt.js +18 -0
- package/dist/lib/logger.d.ts +24 -0
- package/dist/lib/logger.js +126 -0
- package/dist/lib/migrateCallLogsSchema.d.ts +32 -0
- package/{lib → dist/lib}/migrateCallLogsSchema.js +75 -160
- package/dist/lib/oauth.d.ts +4 -0
- package/{lib → dist/lib}/oauth.js +157 -160
- package/dist/lib/ringcentral.d.ts +24 -0
- package/dist/lib/ringcentral.js +226 -0
- package/dist/lib/s3ErrorLogReport.d.ts +4 -0
- package/{lib → dist/lib}/s3ErrorLogReport.js +11 -23
- package/dist/lib/sharedSMSComposer.d.ts +7 -0
- package/{lib → dist/lib}/sharedSMSComposer.js +21 -107
- package/dist/lib/util.d.ts +7 -0
- package/{lib → dist/lib}/util.js +9 -20
- package/dist/mcp/lib/oauthError.d.ts +1 -0
- package/dist/mcp/lib/oauthError.js +25 -0
- package/dist/mcp/lib/validator.d.ts +1 -0
- package/{mcp → dist/mcp}/lib/validator.js +16 -20
- package/dist/mcp/lib/widgetSessionToken.d.ts +1 -0
- package/dist/mcp/lib/widgetSessionToken.js +46 -0
- package/dist/mcp/mcpHandler.d.ts +8 -0
- package/{mcp → dist/mcp}/mcpHandler.js +98 -88
- package/dist/mcp/tools/cancelAppointment.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/cancelAppointment.js +7 -16
- package/dist/mcp/tools/checkAuthStatus.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/checkAuthStatus.js +21 -14
- package/dist/mcp/tools/confirmAppointment.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/confirmAppointment.js +7 -16
- package/dist/mcp/tools/createAppointment.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/createAppointment.js +7 -19
- package/dist/mcp/tools/createCallLog.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/createCallLog.js +18 -29
- package/dist/mcp/tools/createContact.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/createContact.js +8 -20
- package/dist/mcp/tools/createMessageLog.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/createMessageLog.js +14 -26
- package/dist/mcp/tools/doAuth.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/doAuth.js +17 -13
- package/dist/mcp/tools/findContactByName.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/findContactByName.js +9 -15
- package/dist/mcp/tools/findContactByPhone.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/findContactByPhone.js +8 -15
- package/dist/mcp/tools/getCallLog.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/getCallLog.js +12 -21
- package/dist/mcp/tools/getGoogleFilePicker.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/getGoogleFilePicker.js +9 -18
- package/dist/mcp/tools/getHelp.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/getHelp.js +5 -6
- package/dist/mcp/tools/getPublicConnectors.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/getPublicConnectors.js +19 -18
- package/dist/mcp/tools/getSessionInfo.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/getSessionInfo.js +10 -16
- package/dist/mcp/tools/index.d.ts +8 -0
- package/dist/mcp/tools/index.js +50 -0
- package/dist/mcp/tools/listAppointments.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/listAppointments.js +7 -19
- package/dist/mcp/tools/logout.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/logout.js +16 -14
- package/dist/mcp/tools/rcGetCallLogs.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/rcGetCallLogs.js +10 -8
- package/dist/mcp/tools/updateAppointment.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/updateAppointment.js +17 -22
- package/dist/mcp/tools/updateCallLog.d.ts +1 -0
- package/{mcp → dist/mcp}/tools/updateCallLog.js +16 -26
- package/dist/models/accountDataModel.d.ts +3 -0
- package/dist/models/accountDataModel.js +39 -0
- package/dist/models/adminConfigModel.d.ts +2 -0
- package/dist/models/adminConfigModel.js +39 -0
- package/dist/models/cacheModel.d.ts +2 -0
- package/{models → dist/models}/cacheModel.js +7 -3
- package/dist/models/callDownListModel.d.ts +2 -0
- package/{models → dist/models}/callDownListModel.js +8 -4
- package/dist/models/callLogModel.d.ts +2 -0
- package/dist/models/callLogModel.js +43 -0
- package/dist/models/dynamo/connectorSchema.d.ts +2 -0
- package/dist/models/dynamo/connectorSchema.js +141 -0
- package/dist/models/dynamo/lockSchema.d.ts +2 -0
- package/{models → dist/models}/dynamo/lockSchema.js +5 -7
- package/dist/models/dynamo/noteCacheSchema.d.ts +2 -0
- package/{models → dist/models}/dynamo/noteCacheSchema.js +4 -6
- package/dist/models/llmSessionModel.d.ts +2 -0
- package/dist/models/llmSessionModel.js +21 -0
- package/dist/models/messageLogModel.d.ts +2 -0
- package/{models → dist/models}/messageLogModel.js +8 -4
- package/dist/models/sequelize.d.ts +2 -0
- package/dist/models/sequelize.js +68 -0
- package/dist/models/userModel.d.ts +2 -0
- package/dist/models/userModel.js +49 -0
- package/dist/package.json +100 -0
- package/dist/releaseNotes.json +1222 -0
- package/dist/tsconfig.json +14 -0
- package/dist/types/admin.d.ts +141 -0
- package/dist/types/analytics.d.ts +14 -0
- package/dist/types/appointment.d.ts +50 -0
- package/dist/types/auth.d.ts +137 -0
- package/dist/types/authSession.d.ts +35 -0
- package/dist/types/cacheCleanup.d.ts +12 -0
- package/dist/types/calldown.d.ts +54 -0
- package/dist/types/common.d.ts +46 -0
- package/dist/types/connector.d.ts +165 -0
- package/dist/types/contact.d.ts +125 -0
- package/dist/types/errorHandler.d.ts +60 -0
- package/dist/types/index.d.ts +76 -0
- package/dist/types/json.d.ts +9 -0
- package/dist/types/jwt.d.ts +8 -0
- package/dist/types/logging.d.ts +224 -0
- package/dist/types/managedAuth.d.ts +114 -0
- package/dist/types/managedOAuth.d.ts +59 -0
- package/dist/types/manifest.d.ts +120 -0
- package/dist/types/migration.d.ts +15 -0
- package/dist/types/plugin.d.ts +74 -0
- package/dist/types/ringcentral.d.ts +61 -0
- package/dist/types/s3ErrorLogReport.d.ts +16 -0
- package/dist/types/sharedSMSComposer.d.ts +105 -0
- package/dist/types/user.d.ts +46 -0
- package/dist/types/util.d.ts +7 -0
- package/package.json +34 -6
- package/releaseNotes.json +8 -0
- package/.env.test +0 -5
- package/connector/proxy/engine.js +0 -165
- package/connector/proxy/index.js +0 -500
- package/connector/registry.js +0 -252
- package/docs/README.md +0 -50
- package/docs/architecture.md +0 -94
- package/docs/connectors.md +0 -116
- package/docs/handlers.md +0 -128
- package/docs/libraries.md +0 -98
- package/docs/models.md +0 -146
- package/docs/routes.md +0 -119
- package/docs/tests.md +0 -73
- package/handlers/calldown.js +0 -99
- package/jest.config.js +0 -57
- package/lib/constants.js +0 -9
- package/lib/encode.js +0 -30
- package/lib/errorHandler.js +0 -218
- package/lib/jwt.js +0 -18
- package/lib/logger.js +0 -190
- package/lib/ringcentral.js +0 -267
- package/mcp/README.md +0 -420
- package/mcp/tools/index.js +0 -51
- package/mcp/ui/App/App.tsx +0 -358
- package/mcp/ui/App/components/AuthInfoForm.tsx +0 -113
- package/mcp/ui/App/components/AuthSuccess.tsx +0 -22
- package/mcp/ui/App/components/ConnectorList.tsx +0 -82
- package/mcp/ui/App/components/DebugPanel.tsx +0 -43
- package/mcp/ui/App/components/OAuthConnect.tsx +0 -270
- package/mcp/ui/App/lib/callTool.ts +0 -130
- package/mcp/ui/App/lib/debugLog.ts +0 -41
- package/mcp/ui/App/lib/developerPortal.ts +0 -111
- package/mcp/ui/App/main.css +0 -6
- package/mcp/ui/App/root.tsx +0 -13
- package/mcp/ui/dist/index.html +0 -53
- package/mcp/ui/vite.config.ts +0 -16
- package/models/accountDataModel.js +0 -34
- package/models/adminConfigModel.js +0 -35
- package/models/callLogModel.js +0 -39
- package/models/dynamo/connectorSchema.js +0 -146
- package/models/llmSessionModel.js +0 -17
- package/models/sequelize.js +0 -17
- package/models/userModel.js +0 -45
- package/test/connector/developerPortal.test.js +0 -166
- package/test/connector/mock.test.js +0 -131
- package/test/connector/proxy/engine.test.js +0 -211
- package/test/connector/proxy/index.test.js +0 -525
- package/test/connector/proxy/sample.json +0 -162
- package/test/connector/registry.test.js +0 -416
- package/test/handlers/admin.test.js +0 -960
- package/test/handlers/appointment.test.js +0 -260
- package/test/handlers/auth.test.js +0 -1096
- package/test/handlers/calldown.test.js +0 -310
- package/test/handlers/contact.test.js +0 -1014
- package/test/handlers/disposition.test.js +0 -396
- package/test/handlers/log.test.js +0 -1847
- package/test/handlers/managedAuth.test.js +0 -458
- package/test/handlers/managedOAuth.test.js +0 -262
- package/test/handlers/plugin.test.js +0 -429
- package/test/handlers/user.test.js +0 -381
- package/test/index.test.js +0 -301
- package/test/lib/analytics.test.js +0 -146
- package/test/lib/authSession.test.js +0 -173
- package/test/lib/cacheCleanup.test.js +0 -127
- package/test/lib/callLogComposer.test.js +0 -1231
- package/test/lib/debugTracer.test.js +0 -328
- package/test/lib/encode.test.js +0 -59
- package/test/lib/errorHandler.test.js +0 -246
- package/test/lib/generalErrorMessage.test.js +0 -82
- package/test/lib/jwt.test.js +0 -176
- package/test/lib/logger.test.js +0 -206
- package/test/lib/oauth.test.js +0 -359
- package/test/lib/ringcentral.test.js +0 -467
- package/test/lib/s3ErrorLogReport.test.js +0 -187
- package/test/lib/sharedSMSComposer.test.js +0 -1084
- package/test/lib/util.test.js +0 -329
- package/test/mcp/mcpHandler.test.js +0 -73
- package/test/mcp/mcpHandlerMore.test.js +0 -384
- package/test/mcp/tools/appointmentTools.test.js +0 -362
- package/test/mcp/tools/checkAuthStatus.test.js +0 -83
- package/test/mcp/tools/createCallLog.test.js +0 -436
- package/test/mcp/tools/createContact.test.js +0 -58
- package/test/mcp/tools/createMessageLog.test.js +0 -595
- package/test/mcp/tools/doAuth.test.js +0 -113
- package/test/mcp/tools/findContactByName.test.js +0 -275
- package/test/mcp/tools/findContactByPhone.test.js +0 -296
- package/test/mcp/tools/getCallLog.test.js +0 -298
- package/test/mcp/tools/getGoogleFilePicker.test.js +0 -281
- package/test/mcp/tools/getPublicConnectors.test.js +0 -107
- package/test/mcp/tools/getSessionInfo.test.js +0 -127
- package/test/mcp/tools/logout.test.js +0 -233
- package/test/mcp/tools/rcGetCallLogs.test.js +0 -56
- package/test/mcp/tools/updateCallLog.test.js +0 -360
- package/test/models/accountDataModel.test.js +0 -98
- package/test/models/callDownListModel.test.js +0 -125
- package/test/models/dynamo/connectorSchema.test.js +0 -189
- package/test/models/dynamo/lockSchema.test.js +0 -37
- package/test/models/dynamo/noteCacheSchema.test.js +0 -45
- package/test/models/llmSessionModel.test.js +0 -91
- package/test/models/models.test.js +0 -660
- package/test/routes/calldownRoutes.test.js +0 -224
- package/test/routes/coreRouterBroadRoutes.test.js +0 -855
- package/test/routes/dispositionRoutes.test.js +0 -192
- package/test/routes/managedAuthRoutes.test.js +0 -386
- package/test/routes/pluginRoutes.test.js +0 -262
- package/test/setup.js +0 -178
- /package/{mcp → dist/mcp}/ui/index.html +0 -0
- /package/{mcp → dist/mcp}/ui/package-lock.json +0 -0
- /package/{mcp → dist/mcp}/ui/package.json +0 -0
- /package/{mcp → dist/mcp}/ui/tsconfig.json +0 -0
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
authorizationErrorMessage,
|
|
3
|
-
rateLimitErrorMessage,
|
|
4
|
-
} = require('../../lib/generalErrorMessage');
|
|
5
|
-
|
|
6
|
-
describe('generalErrorMessage', () => {
|
|
7
|
-
describe('rateLimitErrorMessage', () => {
|
|
8
|
-
test('builds the standard rate limit warning message', () => {
|
|
9
|
-
const result = rateLimitErrorMessage({ platform: 'Clio' });
|
|
10
|
-
|
|
11
|
-
expect(result).toEqual({
|
|
12
|
-
message: 'Rate limit exceeded',
|
|
13
|
-
messageType: 'warning',
|
|
14
|
-
details: [
|
|
15
|
-
{
|
|
16
|
-
title: 'Details',
|
|
17
|
-
items: [
|
|
18
|
-
{
|
|
19
|
-
id: '1',
|
|
20
|
-
type: 'text',
|
|
21
|
-
text: 'You have exceeded the maximum number of requests allowed by Clio. Please try again in the next minute. If the problem persists please contact support.',
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
ttl: 5000,
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('keeps current interpolation behavior for empty platform input', () => {
|
|
31
|
-
const result = rateLimitErrorMessage({ platform: '' });
|
|
32
|
-
|
|
33
|
-
expect(result.details[0].items[0].text).toContain('allowed by .');
|
|
34
|
-
expect(result.ttl).toBe(5000);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('keeps current interpolation behavior for missing platform input', () => {
|
|
38
|
-
const result = rateLimitErrorMessage({});
|
|
39
|
-
|
|
40
|
-
expect(result.details[0].items[0].text).toContain('allowed by undefined.');
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe('authorizationErrorMessage', () => {
|
|
45
|
-
test('builds the standard authorization warning message', () => {
|
|
46
|
-
const result = authorizationErrorMessage({ platform: 'Bullhorn' });
|
|
47
|
-
|
|
48
|
-
expect(result).toEqual({
|
|
49
|
-
message: 'Authorization error',
|
|
50
|
-
messageType: 'warning',
|
|
51
|
-
details: [
|
|
52
|
-
{
|
|
53
|
-
title: 'Details',
|
|
54
|
-
items: [
|
|
55
|
-
{
|
|
56
|
-
id: '1',
|
|
57
|
-
type: 'text',
|
|
58
|
-
text: "It seems like there's something wrong with your authorization of Bullhorn. Please Logout and then Connect your Bullhorn account within this extension.",
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
ttl: 5000,
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('keeps current interpolation behavior for empty platform input', () => {
|
|
68
|
-
const result = authorizationErrorMessage({ platform: '' });
|
|
69
|
-
|
|
70
|
-
expect(result.details[0].items[0].text).toContain('authorization of .');
|
|
71
|
-
expect(result.details[0].items[0].text).toContain('Connect your account');
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('keeps current interpolation behavior for missing platform input', () => {
|
|
75
|
-
const result = authorizationErrorMessage({});
|
|
76
|
-
|
|
77
|
-
expect(result.details[0].items[0].text).toContain('authorization of undefined.');
|
|
78
|
-
expect(result.details[0].items[0].text).toContain('Connect your undefined account');
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
package/test/lib/jwt.test.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
const jwt = require('../../lib/jwt');
|
|
2
|
-
|
|
3
|
-
describe('JWT Utility', () => {
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
// Reset environment
|
|
6
|
-
process.env.APP_SERVER_SECRET_KEY = 'test-secret-key';
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
describe('generateJwt', () => {
|
|
10
|
-
test('should generate JWT token from payload', () => {
|
|
11
|
-
// Arrange
|
|
12
|
-
const payload = {
|
|
13
|
-
id: 'test-user-id',
|
|
14
|
-
platform: 'testCRM'
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// Act
|
|
18
|
-
const token = jwt.generateJwt(payload);
|
|
19
|
-
|
|
20
|
-
// Assert
|
|
21
|
-
expect(token).toBeDefined();
|
|
22
|
-
expect(typeof token).toBe('string');
|
|
23
|
-
expect(token.split('.')).toHaveLength(3); // JWT has 3 parts
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('should generate different tokens for different payloads', () => {
|
|
27
|
-
// Arrange
|
|
28
|
-
const payload1 = { id: 'user1', platform: 'testCRM' };
|
|
29
|
-
const payload2 = { id: 'user2', platform: 'testCRM' };
|
|
30
|
-
|
|
31
|
-
// Act
|
|
32
|
-
const token1 = jwt.generateJwt(payload1);
|
|
33
|
-
const token2 = jwt.generateJwt(payload2);
|
|
34
|
-
|
|
35
|
-
// Assert
|
|
36
|
-
expect(token1).not.toBe(token2);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('should generate token with about 2 weeks lifetime', () => {
|
|
40
|
-
// Arrange
|
|
41
|
-
const payload = { id: 'user-ttl', platform: 'testCRM' };
|
|
42
|
-
|
|
43
|
-
// Act
|
|
44
|
-
const token = jwt.generateJwt(payload);
|
|
45
|
-
const decoded = jwt.decodeJwt(token);
|
|
46
|
-
const lifetimeSeconds = decoded.exp - decoded.iat;
|
|
47
|
-
|
|
48
|
-
// Assert
|
|
49
|
-
// Keep a tiny tolerance to avoid timing flakiness.
|
|
50
|
-
expect(lifetimeSeconds).toBeGreaterThanOrEqual((14 * 24 * 60 * 60) - 2);
|
|
51
|
-
expect(lifetimeSeconds).toBeLessThanOrEqual((14 * 24 * 60 * 60) + 2);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('decodeJwt', () => {
|
|
56
|
-
test('should decode valid JWT token', () => {
|
|
57
|
-
// Arrange
|
|
58
|
-
const payload = {
|
|
59
|
-
id: 'test-user-id',
|
|
60
|
-
platform: 'testCRM'
|
|
61
|
-
};
|
|
62
|
-
const token = jwt.generateJwt(payload);
|
|
63
|
-
|
|
64
|
-
// Act
|
|
65
|
-
const decoded = jwt.decodeJwt(token);
|
|
66
|
-
|
|
67
|
-
// Assert
|
|
68
|
-
expect(decoded).toMatchObject(payload);
|
|
69
|
-
expect(decoded).toHaveProperty('exp');
|
|
70
|
-
expect(decoded).toHaveProperty('iat');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test('should return null for invalid token', () => {
|
|
74
|
-
// Arrange
|
|
75
|
-
const invalidToken = 'invalid.jwt.token';
|
|
76
|
-
|
|
77
|
-
// Act
|
|
78
|
-
const decoded = jwt.decodeJwt(invalidToken);
|
|
79
|
-
|
|
80
|
-
// Assert
|
|
81
|
-
expect(decoded).toBeNull();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('should return null for malformed token', () => {
|
|
85
|
-
// Arrange
|
|
86
|
-
const malformedToken = 'not-a-jwt-token';
|
|
87
|
-
|
|
88
|
-
// Act
|
|
89
|
-
const decoded = jwt.decodeJwt(malformedToken);
|
|
90
|
-
|
|
91
|
-
// Assert
|
|
92
|
-
expect(decoded).toBeNull();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('should return null for token with wrong secret', () => {
|
|
96
|
-
// Arrange
|
|
97
|
-
const payload = { id: 'test-user-id', platform: 'testCRM' };
|
|
98
|
-
const token = jwt.generateJwt(payload);
|
|
99
|
-
|
|
100
|
-
// Change secret temporarily
|
|
101
|
-
const originalSecret = process.env.APP_SERVER_SECRET_KEY;
|
|
102
|
-
process.env.APP_SERVER_SECRET_KEY = 'different-secret';
|
|
103
|
-
|
|
104
|
-
// Act
|
|
105
|
-
const decoded = jwt.decodeJwt(token);
|
|
106
|
-
|
|
107
|
-
// Restore secret
|
|
108
|
-
process.env.APP_SERVER_SECRET_KEY = originalSecret;
|
|
109
|
-
|
|
110
|
-
// Assert
|
|
111
|
-
expect(decoded).toBeNull();
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
describe('generateJwt and decodeJwt round trip', () => {
|
|
116
|
-
test('should successfully generate and decode complex payload', () => {
|
|
117
|
-
// Arrange
|
|
118
|
-
const complexPayload = {
|
|
119
|
-
id: 'test-user-id',
|
|
120
|
-
platform: 'testCRM',
|
|
121
|
-
timestamp: Date.now(),
|
|
122
|
-
metadata: {
|
|
123
|
-
timezone: 'America/Los_Angeles',
|
|
124
|
-
preferences: {
|
|
125
|
-
autoLog: true,
|
|
126
|
-
callPop: false
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// Act
|
|
132
|
-
const token = jwt.generateJwt(complexPayload);
|
|
133
|
-
const decoded = jwt.decodeJwt(token);
|
|
134
|
-
|
|
135
|
-
// Assert
|
|
136
|
-
expect(decoded).toMatchObject(complexPayload);
|
|
137
|
-
expect(decoded).toHaveProperty('exp');
|
|
138
|
-
expect(decoded).toHaveProperty('iat');
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test('should handle empty payload', () => {
|
|
142
|
-
// Arrange
|
|
143
|
-
const emptyPayload = {};
|
|
144
|
-
|
|
145
|
-
// Act
|
|
146
|
-
const token = jwt.generateJwt(emptyPayload);
|
|
147
|
-
const decoded = jwt.decodeJwt(token);
|
|
148
|
-
|
|
149
|
-
// Assert
|
|
150
|
-
expect(decoded).toMatchObject(emptyPayload);
|
|
151
|
-
expect(decoded).toHaveProperty('exp');
|
|
152
|
-
expect(decoded).toHaveProperty('iat');
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
describe('error handling', () => {
|
|
157
|
-
test('should handle missing secret key', () => {
|
|
158
|
-
// Arrange
|
|
159
|
-
const payload = { id: 'test-user-id' };
|
|
160
|
-
delete process.env.APP_SERVER_SECRET_KEY;
|
|
161
|
-
|
|
162
|
-
// Act & Assert
|
|
163
|
-
expect(() => jwt.generateJwt(payload)).toThrow();
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
test('should handle null payload', () => {
|
|
167
|
-
// Act & Assert
|
|
168
|
-
expect(() => jwt.generateJwt(null)).toThrow();
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
test('should handle undefined payload', () => {
|
|
172
|
-
// Act & Assert
|
|
173
|
-
expect(() => jwt.generateJwt(undefined)).toThrow();
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
});
|
package/test/lib/logger.test.js
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
const { Logger, LOG_LEVELS } = require('../../lib/logger');
|
|
2
|
-
|
|
3
|
-
describe('Logger', () => {
|
|
4
|
-
let originalEnv;
|
|
5
|
-
let consoleSpy;
|
|
6
|
-
let consoleErrorSpy;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
originalEnv = process.env.NODE_ENV;
|
|
10
|
-
consoleSpy = jest.spyOn(console, 'log').mockImplementation();
|
|
11
|
-
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
afterEach(() => {
|
|
15
|
-
process.env.NODE_ENV = originalEnv;
|
|
16
|
-
consoleSpy.mockRestore();
|
|
17
|
-
consoleErrorSpy.mockRestore();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe('Log Levels', () => {
|
|
21
|
-
test('should only log messages at or above the configured level', () => {
|
|
22
|
-
const logger = new Logger({ level: 'WARN' });
|
|
23
|
-
|
|
24
|
-
logger.debug('debug message');
|
|
25
|
-
logger.info('info message');
|
|
26
|
-
logger.warn('warn message');
|
|
27
|
-
logger.error('error message');
|
|
28
|
-
|
|
29
|
-
// Only warn and error should be logged
|
|
30
|
-
expect(consoleSpy).not.toHaveBeenCalled();
|
|
31
|
-
expect(consoleErrorSpy).toHaveBeenCalledTimes(2);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test('should log all messages when level is DEBUG', () => {
|
|
35
|
-
const logger = new Logger({ level: 'DEBUG' });
|
|
36
|
-
|
|
37
|
-
logger.debug('debug message');
|
|
38
|
-
logger.info('info message');
|
|
39
|
-
logger.warn('warn message');
|
|
40
|
-
logger.error('error message');
|
|
41
|
-
|
|
42
|
-
expect(consoleSpy).toHaveBeenCalledTimes(2); // debug and info
|
|
43
|
-
expect(consoleErrorSpy).toHaveBeenCalledTimes(2); // warn and error
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('Production vs Development', () => {
|
|
48
|
-
test('should output JSON in production', () => {
|
|
49
|
-
process.env.NODE_ENV = 'production';
|
|
50
|
-
const logger = new Logger({ level: 'INFO' });
|
|
51
|
-
|
|
52
|
-
logger.info('test message', { userId: '123' });
|
|
53
|
-
|
|
54
|
-
const logOutput = consoleSpy.mock.calls[0][0];
|
|
55
|
-
const parsed = JSON.parse(logOutput);
|
|
56
|
-
|
|
57
|
-
expect(parsed).toHaveProperty('timestamp');
|
|
58
|
-
expect(parsed).toHaveProperty('level', 'INFO');
|
|
59
|
-
expect(parsed).toHaveProperty('message', 'test message');
|
|
60
|
-
expect(parsed).toHaveProperty('userId', '123');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('should output human-readable format in development', () => {
|
|
64
|
-
process.env.NODE_ENV = 'development';
|
|
65
|
-
const logger = new Logger({ level: 'INFO' });
|
|
66
|
-
|
|
67
|
-
logger.info('test message', { userId: '123' });
|
|
68
|
-
|
|
69
|
-
const logOutput = consoleSpy.mock.calls[0][0];
|
|
70
|
-
expect(logOutput).toContain('[INFO]');
|
|
71
|
-
expect(logOutput).toContain('test message');
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('Error Handling', () => {
|
|
76
|
-
test('should extract error information from Error objects', () => {
|
|
77
|
-
process.env.NODE_ENV = 'production';
|
|
78
|
-
const logger = new Logger({ level: 'ERROR' });
|
|
79
|
-
const error = new Error('Test error');
|
|
80
|
-
error.response = {
|
|
81
|
-
status: 500,
|
|
82
|
-
data: { message: 'Server error' },
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
logger.error('Operation failed', { error });
|
|
86
|
-
|
|
87
|
-
const logOutput = consoleErrorSpy.mock.calls[0][0];
|
|
88
|
-
const parsed = JSON.parse(logOutput);
|
|
89
|
-
|
|
90
|
-
expect(parsed).toHaveProperty('errorMessage', 'Test error');
|
|
91
|
-
expect(parsed).toHaveProperty('errorStack');
|
|
92
|
-
expect(parsed).toHaveProperty('errorStatus', 500);
|
|
93
|
-
expect(parsed).toHaveProperty('errorResponse');
|
|
94
|
-
expect(parsed).not.toHaveProperty('error'); // Should be removed
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe('Child Logger', () => {
|
|
99
|
-
test('should create child logger with default context', () => {
|
|
100
|
-
process.env.NODE_ENV = 'production';
|
|
101
|
-
const logger = new Logger({ level: 'INFO' });
|
|
102
|
-
const childLogger = logger.child({ platform: 'clio', userId: '123' });
|
|
103
|
-
|
|
104
|
-
childLogger.info('test message', { operation: 'createLog' });
|
|
105
|
-
|
|
106
|
-
const logOutput = consoleSpy.mock.calls[0][0];
|
|
107
|
-
const parsed = JSON.parse(logOutput);
|
|
108
|
-
|
|
109
|
-
expect(parsed).toHaveProperty('platform', 'clio');
|
|
110
|
-
expect(parsed).toHaveProperty('userId', '123');
|
|
111
|
-
expect(parsed).toHaveProperty('operation', 'createLog');
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test('should support nested child loggers', () => {
|
|
115
|
-
process.env.NODE_ENV = 'production';
|
|
116
|
-
const logger = new Logger({ level: 'INFO' });
|
|
117
|
-
const child1 = logger.child({ platform: 'clio' });
|
|
118
|
-
const child2 = child1.child({ userId: '123' });
|
|
119
|
-
|
|
120
|
-
child2.info('test message');
|
|
121
|
-
|
|
122
|
-
const logOutput = consoleSpy.mock.calls[0][0];
|
|
123
|
-
const parsed = JSON.parse(logOutput);
|
|
124
|
-
|
|
125
|
-
expect(parsed).toHaveProperty('platform', 'clio');
|
|
126
|
-
expect(parsed).toHaveProperty('userId', '123');
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe('API Request Logging', () => {
|
|
131
|
-
test('should log successful API requests at DEBUG level', () => {
|
|
132
|
-
const logger = new Logger({ level: 'DEBUG' });
|
|
133
|
-
|
|
134
|
-
logger.logApiRequest({
|
|
135
|
-
method: 'GET',
|
|
136
|
-
url: 'https://api.example.com/users',
|
|
137
|
-
status: 200,
|
|
138
|
-
duration: 150,
|
|
139
|
-
platform: 'clio',
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
expect(consoleSpy).toHaveBeenCalledTimes(1);
|
|
143
|
-
expect(consoleErrorSpy).not.toHaveBeenCalled();
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test('should log failed API requests at ERROR level', () => {
|
|
147
|
-
const logger = new Logger({ level: 'ERROR' });
|
|
148
|
-
const error = new Error('Request failed');
|
|
149
|
-
|
|
150
|
-
logger.logApiRequest({
|
|
151
|
-
method: 'POST',
|
|
152
|
-
url: 'https://api.example.com/logs',
|
|
153
|
-
status: 500,
|
|
154
|
-
duration: 300,
|
|
155
|
-
platform: 'clio',
|
|
156
|
-
error,
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
|
|
160
|
-
expect(consoleSpy).not.toHaveBeenCalled();
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
test('should log 4xx errors at WARN level', () => {
|
|
164
|
-
const logger = new Logger({ level: 'WARN' });
|
|
165
|
-
|
|
166
|
-
logger.logApiRequest({
|
|
167
|
-
method: 'GET',
|
|
168
|
-
url: 'https://api.example.com/contact/999',
|
|
169
|
-
status: 404,
|
|
170
|
-
duration: 100,
|
|
171
|
-
platform: 'clio',
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe('Database Query Logging', () => {
|
|
179
|
-
test('should log successful queries at DEBUG level', () => {
|
|
180
|
-
const logger = new Logger({ level: 'DEBUG' });
|
|
181
|
-
|
|
182
|
-
logger.logDatabaseQuery({
|
|
183
|
-
operation: 'SELECT',
|
|
184
|
-
table: 'users',
|
|
185
|
-
duration: 50,
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
expect(consoleSpy).toHaveBeenCalledTimes(1);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
test('should log failed queries at ERROR level', () => {
|
|
192
|
-
const logger = new Logger({ level: 'ERROR' });
|
|
193
|
-
const error = new Error('Constraint violation');
|
|
194
|
-
|
|
195
|
-
logger.logDatabaseQuery({
|
|
196
|
-
operation: 'INSERT',
|
|
197
|
-
table: 'call_logs',
|
|
198
|
-
duration: 20,
|
|
199
|
-
error,
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
|