@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,146 +0,0 @@
|
|
|
1
|
-
describe('analytics', () => {
|
|
2
|
-
let mixpanelInit;
|
|
3
|
-
let peopleSetOnce;
|
|
4
|
-
let track;
|
|
5
|
-
let parseUserAgent;
|
|
6
|
-
|
|
7
|
-
function loadAnalytics({ token } = {}) {
|
|
8
|
-
jest.resetModules();
|
|
9
|
-
peopleSetOnce = jest.fn();
|
|
10
|
-
track = jest.fn();
|
|
11
|
-
mixpanelInit = jest.fn(() => ({
|
|
12
|
-
people: {
|
|
13
|
-
set_once: peopleSetOnce
|
|
14
|
-
},
|
|
15
|
-
track
|
|
16
|
-
}));
|
|
17
|
-
parseUserAgent = jest.fn(() => ({
|
|
18
|
-
browser: { name: 'Chrome' },
|
|
19
|
-
os: { name: 'Windows' },
|
|
20
|
-
device: { type: 'desktop' }
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
if (token) {
|
|
24
|
-
process.env.MIXPANEL_TOKEN = token;
|
|
25
|
-
} else {
|
|
26
|
-
delete process.env.MIXPANEL_TOKEN;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
jest.doMock('mixpanel', () => ({
|
|
30
|
-
init: mixpanelInit
|
|
31
|
-
}));
|
|
32
|
-
jest.doMock('ua-parser-js', () => parseUserAgent);
|
|
33
|
-
jest.doMock('../../lib/logger', () => ({
|
|
34
|
-
info: jest.fn(),
|
|
35
|
-
warn: jest.fn(),
|
|
36
|
-
error: jest.fn()
|
|
37
|
-
}));
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
analytics: require('../../lib/analytics'),
|
|
41
|
-
logger: require('../../lib/logger')
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
afterEach(() => {
|
|
46
|
-
delete process.env.MIXPANEL_TOKEN;
|
|
47
|
-
jest.dontMock('mixpanel');
|
|
48
|
-
jest.dontMock('ua-parser-js');
|
|
49
|
-
jest.dontMock('../../lib/logger');
|
|
50
|
-
jest.resetModules();
|
|
51
|
-
jest.clearAllMocks();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('does not initialize Mixpanel when token is missing and skips tracking without an initialized client', () => {
|
|
55
|
-
const { analytics } = loadAnalytics();
|
|
56
|
-
|
|
57
|
-
analytics.init();
|
|
58
|
-
analytics.track({
|
|
59
|
-
eventName: 'Call Log Created',
|
|
60
|
-
connectorName: 'salesforce',
|
|
61
|
-
extensionId: 'ext-1'
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
expect(mixpanelInit).not.toHaveBeenCalled();
|
|
65
|
-
expect(peopleSetOnce).not.toHaveBeenCalled();
|
|
66
|
-
expect(track).not.toHaveBeenCalled();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('skips tracking when extension id is missing', () => {
|
|
70
|
-
const { analytics } = loadAnalytics({ token: 'mixpanel-token' });
|
|
71
|
-
|
|
72
|
-
analytics.init();
|
|
73
|
-
analytics.track({
|
|
74
|
-
eventName: 'Call Log Created',
|
|
75
|
-
connectorName: 'salesforce',
|
|
76
|
-
accountId: 'account-1'
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
expect(mixpanelInit).toHaveBeenCalledWith('mixpanel-token');
|
|
80
|
-
expect(peopleSetOnce).not.toHaveBeenCalled();
|
|
81
|
-
expect(track).not.toHaveBeenCalled();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('tracks event properties, parsed user agent fields, extras, and default source', () => {
|
|
85
|
-
const { analytics, logger } = loadAnalytics({ token: 'mixpanel-token' });
|
|
86
|
-
|
|
87
|
-
analytics.init();
|
|
88
|
-
analytics.track({
|
|
89
|
-
eventName: 'Call Log Created',
|
|
90
|
-
interfaceName: 'desktop',
|
|
91
|
-
connectorName: 'salesforce',
|
|
92
|
-
accountId: 'account-1',
|
|
93
|
-
extensionId: 'ext-1',
|
|
94
|
-
success: true,
|
|
95
|
-
requestDuration: 123,
|
|
96
|
-
userAgent: 'Mozilla/5.0',
|
|
97
|
-
ip: '127.0.0.1',
|
|
98
|
-
author: 'unit-test',
|
|
99
|
-
extras: {
|
|
100
|
-
extraKey: 'extra-value'
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
expect(peopleSetOnce).toHaveBeenCalledWith('ext-1', {
|
|
105
|
-
version: expect.any(String),
|
|
106
|
-
appName: 'App Connect',
|
|
107
|
-
crmPlatform: 'salesforce'
|
|
108
|
-
});
|
|
109
|
-
expect(parseUserAgent).toHaveBeenCalledWith('Mozilla/5.0');
|
|
110
|
-
expect(track).toHaveBeenCalledWith('Call Log Created', expect.objectContaining({
|
|
111
|
-
distinct_id: 'ext-1',
|
|
112
|
-
interfaceName: 'desktop',
|
|
113
|
-
adapterName: 'salesforce',
|
|
114
|
-
rcAccountId: 'account-1',
|
|
115
|
-
extensionId: 'ext-1',
|
|
116
|
-
success: true,
|
|
117
|
-
requestDuration: 123,
|
|
118
|
-
collectedFrom: 'server',
|
|
119
|
-
appName: 'App Connect',
|
|
120
|
-
eventAddedVia: 'server',
|
|
121
|
-
$browser: 'Chrome',
|
|
122
|
-
$os: 'Windows',
|
|
123
|
-
$device: 'desktop',
|
|
124
|
-
ip: '127.0.0.1',
|
|
125
|
-
author: 'unit-test',
|
|
126
|
-
extraKey: 'extra-value'
|
|
127
|
-
}));
|
|
128
|
-
expect(logger.info).toHaveBeenCalledWith('Event: Call Log Created');
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test('uses explicit eventAddedVia when provided', () => {
|
|
132
|
-
const { analytics } = loadAnalytics({ token: 'mixpanel-token' });
|
|
133
|
-
|
|
134
|
-
analytics.init();
|
|
135
|
-
analytics.track({
|
|
136
|
-
eventName: 'Disposition Saved',
|
|
137
|
-
connectorName: 'hubspot',
|
|
138
|
-
extensionId: 'ext-2',
|
|
139
|
-
eventAddedVia: 'browser'
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
expect(track).toHaveBeenCalledWith('Disposition Saved', expect.objectContaining({
|
|
143
|
-
eventAddedVia: 'browser'
|
|
144
|
-
}));
|
|
145
|
-
});
|
|
146
|
-
});
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
const { CacheModel } = require('../../models/cacheModel');
|
|
2
|
-
const {
|
|
3
|
-
createAuthSession,
|
|
4
|
-
getAuthSession,
|
|
5
|
-
updateAuthSession,
|
|
6
|
-
} = require('../../lib/authSession');
|
|
7
|
-
|
|
8
|
-
describe('authSession', () => {
|
|
9
|
-
const baseTime = new Date(Date.now() + (60 * 60 * 1000));
|
|
10
|
-
|
|
11
|
-
beforeEach(async () => {
|
|
12
|
-
await CacheModel.destroy({ where: {} });
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
jest.restoreAllMocks();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('creates a pending auth session record with generated id and expiry', async () => {
|
|
20
|
-
jest.spyOn(Date, 'now').mockReturnValue(baseTime.getTime());
|
|
21
|
-
|
|
22
|
-
await createAuthSession('session-1', {
|
|
23
|
-
platform: 'clio',
|
|
24
|
-
hostname: 'https://example.clio.com',
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const record = await CacheModel.findByPk('auth-session-session-1');
|
|
28
|
-
expect(record).not.toBeNull();
|
|
29
|
-
expect(record.userId).toBe('session-1');
|
|
30
|
-
expect(record.cacheKey).toBe('auth-session');
|
|
31
|
-
expect(record.status).toBe('pending');
|
|
32
|
-
expect(record.expiry.getTime()).toBe(baseTime.getTime() + (5 * 60 * 1000));
|
|
33
|
-
expect(record.data).toMatchObject({
|
|
34
|
-
platform: 'clio',
|
|
35
|
-
hostname: 'https://example.clio.com',
|
|
36
|
-
});
|
|
37
|
-
expect(new Date(record.data.createdAt).toString()).not.toBe('Invalid Date');
|
|
38
|
-
|
|
39
|
-
await expect(getAuthSession('session-1')).resolves.toMatchObject({
|
|
40
|
-
sessionId: 'session-1',
|
|
41
|
-
status: 'pending',
|
|
42
|
-
platform: 'clio',
|
|
43
|
-
hostname: 'https://example.clio.com',
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('creates with an empty hostname when hostname is missing', async () => {
|
|
48
|
-
await createAuthSession('session-no-hostname', {
|
|
49
|
-
platform: 'googleSheets',
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const session = await getAuthSession('session-no-hostname');
|
|
53
|
-
|
|
54
|
-
expect(session).toMatchObject({
|
|
55
|
-
sessionId: 'session-no-hostname',
|
|
56
|
-
status: 'pending',
|
|
57
|
-
platform: 'googleSheets',
|
|
58
|
-
hostname: '',
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('resets an existing session record to pending with new session data', async () => {
|
|
63
|
-
await createAuthSession('retry-session', {
|
|
64
|
-
platform: 'clio',
|
|
65
|
-
hostname: 'old-host',
|
|
66
|
-
});
|
|
67
|
-
const existing = await CacheModel.findByPk('auth-session-retry-session');
|
|
68
|
-
await existing.update({
|
|
69
|
-
status: 'completed',
|
|
70
|
-
data: {
|
|
71
|
-
platform: 'clio',
|
|
72
|
-
hostname: 'old-host',
|
|
73
|
-
jwtToken: 'old-token',
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
await createAuthSession('retry-session', {
|
|
78
|
-
platform: 'bullhorn',
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
const record = await CacheModel.findByPk('auth-session-retry-session');
|
|
82
|
-
expect(record.status).toBe('pending');
|
|
83
|
-
expect(record.data).toMatchObject({
|
|
84
|
-
platform: 'bullhorn',
|
|
85
|
-
hostname: '',
|
|
86
|
-
});
|
|
87
|
-
expect(record.data.jwtToken).toBeUndefined();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test('returns null for missing sessions', async () => {
|
|
91
|
-
await expect(getAuthSession('missing-session')).resolves.toBeNull();
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
test('marks expired sessions as expired and returns current session data', async () => {
|
|
95
|
-
await CacheModel.create({
|
|
96
|
-
id: 'auth-session-expired-session',
|
|
97
|
-
cacheKey: 'auth-session',
|
|
98
|
-
userId: 'expired-session',
|
|
99
|
-
status: 'pending',
|
|
100
|
-
data: {
|
|
101
|
-
platform: 'pipedrive',
|
|
102
|
-
hostname: 'pipedrive-host',
|
|
103
|
-
},
|
|
104
|
-
expiry: new Date(Date.now() - 1000),
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const session = await getAuthSession('expired-session');
|
|
108
|
-
|
|
109
|
-
expect(session).toEqual({
|
|
110
|
-
sessionId: 'expired-session',
|
|
111
|
-
status: 'expired',
|
|
112
|
-
platform: 'pipedrive',
|
|
113
|
-
hostname: 'pipedrive-host',
|
|
114
|
-
});
|
|
115
|
-
const record = await CacheModel.findByPk('auth-session-expired-session');
|
|
116
|
-
expect(record.status).toBe('expired');
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('updates an existing session by merging data and extending settled expiry', async () => {
|
|
120
|
-
jest.spyOn(Date, 'now').mockReturnValue(baseTime.getTime());
|
|
121
|
-
await createAuthSession('update-session', {
|
|
122
|
-
platform: 'netsuite',
|
|
123
|
-
hostname: 'netsuite-host',
|
|
124
|
-
});
|
|
125
|
-
jest.spyOn(Date, 'now').mockReturnValue(baseTime.getTime() + 1000);
|
|
126
|
-
|
|
127
|
-
await updateAuthSession('update-session', {
|
|
128
|
-
status: 'completed',
|
|
129
|
-
jwtToken: 'jwt-token',
|
|
130
|
-
rcExtensionId: 'extension-1',
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
const record = await CacheModel.findByPk('auth-session-update-session');
|
|
134
|
-
expect(record.status).toBe('completed');
|
|
135
|
-
expect(record.expiry.getTime()).toBe(baseTime.getTime() + 1000 + (15 * 60 * 1000));
|
|
136
|
-
expect(record.data).toMatchObject({
|
|
137
|
-
platform: 'netsuite',
|
|
138
|
-
hostname: 'netsuite-host',
|
|
139
|
-
status: 'completed',
|
|
140
|
-
jwtToken: 'jwt-token',
|
|
141
|
-
rcExtensionId: 'extension-1',
|
|
142
|
-
});
|
|
143
|
-
expect(new Date(record.data.updatedAt).toString()).not.toBe('Invalid Date');
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test('keeps pending expiry when update does not settle the session', async () => {
|
|
147
|
-
jest.spyOn(Date, 'now').mockReturnValue(baseTime.getTime());
|
|
148
|
-
await createAuthSession('pending-session', {
|
|
149
|
-
platform: 'redtail',
|
|
150
|
-
});
|
|
151
|
-
jest.spyOn(Date, 'now').mockReturnValue(baseTime.getTime() + 2000);
|
|
152
|
-
|
|
153
|
-
await updateAuthSession('pending-session', {
|
|
154
|
-
hostname: 'new-host',
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
const record = await CacheModel.findByPk('auth-session-pending-session');
|
|
158
|
-
expect(record.status).toBe('pending');
|
|
159
|
-
expect(record.expiry.getTime()).toBe(baseTime.getTime() + 2000 + (5 * 60 * 1000));
|
|
160
|
-
expect(record.data).toMatchObject({
|
|
161
|
-
platform: 'redtail',
|
|
162
|
-
hostname: 'new-host',
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
test('does nothing when updating a missing session', async () => {
|
|
167
|
-
await expect(updateAuthSession('missing-session', {
|
|
168
|
-
status: 'completed',
|
|
169
|
-
})).resolves.toBeUndefined();
|
|
170
|
-
|
|
171
|
-
await expect(CacheModel.findByPk('auth-session-missing-session')).resolves.toBeNull();
|
|
172
|
-
});
|
|
173
|
-
});
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
const { CacheModel } = require('../../models/cacheModel');
|
|
2
|
-
const { AccountDataModel } = require('../../models/accountDataModel');
|
|
3
|
-
const { clearExpiredAccountContactData, clearExpiredCache } = require('../../lib/cacheCleanup');
|
|
4
|
-
|
|
5
|
-
describe('cacheCleanup', () => {
|
|
6
|
-
beforeEach(async () => {
|
|
7
|
-
await CacheModel.destroy({ where: {} });
|
|
8
|
-
await AccountDataModel.destroy({ where: {} });
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('deletes only cache records whose expiry has passed', async () => {
|
|
12
|
-
const now = new Date('2026-05-08T00:00:00.000Z');
|
|
13
|
-
|
|
14
|
-
await CacheModel.bulkCreate([
|
|
15
|
-
{
|
|
16
|
-
id: 'expired-cache',
|
|
17
|
-
userId: 'user-1',
|
|
18
|
-
cacheKey: 'auth-session',
|
|
19
|
-
status: 'expired',
|
|
20
|
-
expiry: new Date('2026-05-07T23:59:59.000Z')
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
id: 'active-cache',
|
|
24
|
-
userId: 'user-1',
|
|
25
|
-
cacheKey: 'auth-session',
|
|
26
|
-
status: 'pending',
|
|
27
|
-
expiry: new Date('2026-05-08T00:00:01.000Z')
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
id: 'cache-without-expiry',
|
|
31
|
-
userId: 'user-2',
|
|
32
|
-
cacheKey: 'contacts',
|
|
33
|
-
status: 'active'
|
|
34
|
-
}
|
|
35
|
-
]);
|
|
36
|
-
|
|
37
|
-
const deletedCount = await clearExpiredCache({ now });
|
|
38
|
-
|
|
39
|
-
expect(deletedCount).toBe(1);
|
|
40
|
-
expect(await CacheModel.findByPk('expired-cache')).toBeNull();
|
|
41
|
-
expect(await CacheModel.findByPk('active-cache')).not.toBeNull();
|
|
42
|
-
expect(await CacheModel.findByPk('cache-without-expiry')).not.toBeNull();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('deletes only account contact data older than three months', async () => {
|
|
46
|
-
const now = new Date('2026-06-08T00:00:00.000Z');
|
|
47
|
-
|
|
48
|
-
await AccountDataModel.bulkCreate([
|
|
49
|
-
{
|
|
50
|
-
rcAccountId: 'account-1',
|
|
51
|
-
platformName: 'test-platform',
|
|
52
|
-
dataKey: 'contact-+1111111111',
|
|
53
|
-
data: [{ id: 'old-contact' }],
|
|
54
|
-
createdAt: new Date('2026-03-07T23:59:59.000Z'),
|
|
55
|
-
updatedAt: new Date('2026-03-07T23:59:59.000Z')
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
rcAccountId: 'account-1',
|
|
59
|
-
platformName: 'test-platform',
|
|
60
|
-
dataKey: 'contact-+2222222222',
|
|
61
|
-
data: [{ id: 'exact-cutoff-contact' }],
|
|
62
|
-
createdAt: new Date('2026-03-08T00:00:00.000Z'),
|
|
63
|
-
updatedAt: new Date('2026-03-08T00:00:00.000Z')
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
rcAccountId: 'account-1',
|
|
67
|
-
platformName: 'test-platform',
|
|
68
|
-
dataKey: 'contact-+3333333333',
|
|
69
|
-
data: [{ id: 'active-contact' }],
|
|
70
|
-
createdAt: new Date('2026-03-08T00:00:01.000Z'),
|
|
71
|
-
updatedAt: new Date('2026-03-08T00:00:01.000Z')
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
rcAccountId: 'account-1',
|
|
75
|
-
platformName: 'test-platform',
|
|
76
|
-
dataKey: 'pluginData',
|
|
77
|
-
data: { jwtToken: 'plugin-token' },
|
|
78
|
-
createdAt: new Date('2026-03-07T23:59:59.000Z'),
|
|
79
|
-
updatedAt: new Date('2026-03-07T23:59:59.000Z')
|
|
80
|
-
}
|
|
81
|
-
]);
|
|
82
|
-
|
|
83
|
-
const deletedCount = await clearExpiredAccountContactData({ now });
|
|
84
|
-
|
|
85
|
-
expect(deletedCount).toBe(1);
|
|
86
|
-
expect(await AccountDataModel.findOne({
|
|
87
|
-
where: { rcAccountId: 'account-1', platformName: 'test-platform', dataKey: 'contact-+1111111111' }
|
|
88
|
-
})).toBeNull();
|
|
89
|
-
expect(await AccountDataModel.findOne({
|
|
90
|
-
where: { rcAccountId: 'account-1', platformName: 'test-platform', dataKey: 'contact-+2222222222' }
|
|
91
|
-
})).not.toBeNull();
|
|
92
|
-
expect(await AccountDataModel.findOne({
|
|
93
|
-
where: { rcAccountId: 'account-1', platformName: 'test-platform', dataKey: 'contact-+3333333333' }
|
|
94
|
-
})).not.toBeNull();
|
|
95
|
-
expect(await AccountDataModel.findOne({
|
|
96
|
-
where: { rcAccountId: 'account-1', platformName: 'test-platform', dataKey: 'pluginData' }
|
|
97
|
-
})).not.toBeNull();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('clearExpiredCache includes expired account contact data cleanup', async () => {
|
|
101
|
-
const now = new Date('2026-06-08T00:00:00.000Z');
|
|
102
|
-
|
|
103
|
-
await CacheModel.create({
|
|
104
|
-
id: 'expired-cache',
|
|
105
|
-
userId: 'user-1',
|
|
106
|
-
cacheKey: 'auth-session',
|
|
107
|
-
status: 'expired',
|
|
108
|
-
expiry: new Date('2026-06-07T23:59:59.000Z')
|
|
109
|
-
});
|
|
110
|
-
await AccountDataModel.create({
|
|
111
|
-
rcAccountId: 'account-1',
|
|
112
|
-
platformName: 'test-platform',
|
|
113
|
-
dataKey: 'contact-+1111111111',
|
|
114
|
-
data: [{ id: 'old-contact' }],
|
|
115
|
-
createdAt: new Date('2026-03-07T23:59:59.000Z'),
|
|
116
|
-
updatedAt: new Date('2026-03-07T23:59:59.000Z')
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
const deletedCount = await clearExpiredCache({ now });
|
|
120
|
-
|
|
121
|
-
expect(deletedCount).toBe(2);
|
|
122
|
-
expect(await CacheModel.findByPk('expired-cache')).toBeNull();
|
|
123
|
-
expect(await AccountDataModel.findOne({
|
|
124
|
-
where: { rcAccountId: 'account-1', platformName: 'test-platform', dataKey: 'contact-+1111111111' }
|
|
125
|
-
})).toBeNull();
|
|
126
|
-
});
|
|
127
|
-
});
|