@app-connect/core 1.7.36 → 1.7.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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} +548 -450
- 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/dist/lib/migrateCallLogsSchema.js +339 -0
- 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 +13 -1
- 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/migrateCallLogsSchema.js +0 -237
- 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
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BuildCallLogSessionWhereParams, CallLogLookupInput, PersistedCallLogIdentity } from '../types';
|
|
2
|
+
declare function getCallLogExtensionNumber(incomingData: CallLogLookupInput): string;
|
|
3
|
+
declare function getCallLogHashedExtensionId(incomingData: CallLogLookupInput, hashKey?: string): string;
|
|
4
|
+
declare function buildCallLogSessionWhere({ sessionId, sessionIds, extensionNumber, hashedExtensionId }: BuildCallLogSessionWhereParams): Record<string | symbol, unknown>;
|
|
5
|
+
declare function findMatchingCallLog(callLogs: PersistedCallLogIdentity[], sessionId: string, extensionNumber: string | number | null | undefined, hashedExtensionId: string | number | null | undefined): PersistedCallLogIdentity | undefined;
|
|
6
|
+
export { buildCallLogSessionWhere, findMatchingCallLog, getCallLogExtensionNumber, getCallLogHashedExtensionId };
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildCallLogSessionWhere = buildCallLogSessionWhere;
|
|
4
|
+
exports.findMatchingCallLog = findMatchingCallLog;
|
|
5
|
+
exports.getCallLogExtensionNumber = getCallLogExtensionNumber;
|
|
6
|
+
exports.getCallLogHashedExtensionId = getCallLogHashedExtensionId;
|
|
1
7
|
const Op = require('sequelize').Op;
|
|
2
8
|
const { getHashValue } = require('./util');
|
|
3
|
-
|
|
4
9
|
function stringOrEmpty(value) {
|
|
5
10
|
return value == null ? '' : value.toString();
|
|
6
11
|
}
|
|
7
|
-
|
|
8
12
|
function getCallLogExtensionNumber(incomingData) {
|
|
9
13
|
return stringOrEmpty(incomingData?.extensionNumber ?? incomingData?.logInfo?.extensionNumber);
|
|
10
14
|
}
|
|
11
|
-
|
|
12
15
|
function getCallLogHashedExtensionId(incomingData, hashKey = process.env.HASH_KEY) {
|
|
13
16
|
const hashedExtensionId = incomingData?.hashedExtensionId ?? incomingData?.logInfo?.hashedExtensionId;
|
|
14
17
|
if (hashedExtensionId) {
|
|
15
18
|
return hashedExtensionId.toString();
|
|
16
19
|
}
|
|
17
|
-
|
|
18
20
|
const rcExtensionId = incomingData?.rcExtensionId ?? incomingData?.logInfo?.rcExtensionId;
|
|
19
21
|
if (rcExtensionId && hashKey) {
|
|
20
22
|
return getHashValue(rcExtensionId.toString(), hashKey);
|
|
21
23
|
}
|
|
22
|
-
|
|
23
24
|
return '';
|
|
24
25
|
}
|
|
25
|
-
|
|
26
26
|
function buildLegacyIdentityWhere(extensionNumberValue) {
|
|
27
27
|
return {
|
|
28
28
|
extensionNumber: extensionNumberValue,
|
|
@@ -32,7 +32,6 @@ function buildLegacyIdentityWhere(extensionNumberValue) {
|
|
|
32
32
|
],
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
|
|
36
35
|
function buildCallLogSessionWhere({ sessionId, sessionIds, extensionNumber, hashedExtensionId }) {
|
|
37
36
|
const where = {};
|
|
38
37
|
if (sessionIds) {
|
|
@@ -43,10 +42,8 @@ function buildCallLogSessionWhere({ sessionId, sessionIds, extensionNumber, hash
|
|
|
43
42
|
else {
|
|
44
43
|
where.sessionId = sessionId;
|
|
45
44
|
}
|
|
46
|
-
|
|
47
45
|
const extensionNumberValue = stringOrEmpty(extensionNumber);
|
|
48
46
|
const hashedExtensionIdValue = stringOrEmpty(hashedExtensionId);
|
|
49
|
-
|
|
50
47
|
if (hashedExtensionIdValue) {
|
|
51
48
|
const identityWhere = [
|
|
52
49
|
{ hashedExtensionId: hashedExtensionIdValue },
|
|
@@ -62,46 +59,27 @@ function buildCallLogSessionWhere({ sessionId, sessionIds, extensionNumber, hash
|
|
|
62
59
|
}
|
|
63
60
|
return where;
|
|
64
61
|
}
|
|
65
|
-
|
|
66
62
|
function hasEmptyHashedExtensionId(callLog) {
|
|
67
63
|
return !stringOrEmpty(callLog.hashedExtensionId);
|
|
68
64
|
}
|
|
69
|
-
|
|
70
65
|
function findMatchingCallLog(callLogs, sessionId, extensionNumber, hashedExtensionId) {
|
|
71
66
|
const extensionNumberValue = stringOrEmpty(extensionNumber);
|
|
72
67
|
const hashedExtensionIdValue = stringOrEmpty(hashedExtensionId);
|
|
73
68
|
const sessionLogs = callLogs.filter(callLog => callLog.sessionId === sessionId);
|
|
74
|
-
|
|
75
69
|
if (hashedExtensionIdValue) {
|
|
76
|
-
const exactHashedLog = sessionLogs.find(callLog => (
|
|
77
|
-
stringOrEmpty(callLog.hashedExtensionId) === hashedExtensionIdValue
|
|
78
|
-
));
|
|
70
|
+
const exactHashedLog = sessionLogs.find(callLog => (stringOrEmpty(callLog.hashedExtensionId) === hashedExtensionIdValue));
|
|
79
71
|
if (exactHashedLog) {
|
|
80
72
|
return exactHashedLog;
|
|
81
73
|
}
|
|
82
|
-
|
|
83
74
|
if (extensionNumberValue) {
|
|
84
|
-
const legacyExtensionLog = sessionLogs.find(callLog => (
|
|
85
|
-
|
|
86
|
-
stringOrEmpty(callLog.extensionNumber) === extensionNumberValue
|
|
87
|
-
));
|
|
75
|
+
const legacyExtensionLog = sessionLogs.find(callLog => (hasEmptyHashedExtensionId(callLog) &&
|
|
76
|
+
stringOrEmpty(callLog.extensionNumber) === extensionNumberValue));
|
|
88
77
|
if (legacyExtensionLog) {
|
|
89
78
|
return legacyExtensionLog;
|
|
90
79
|
}
|
|
91
80
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
hasEmptyHashedExtensionId(callLog) &&
|
|
95
|
-
!stringOrEmpty(callLog.extensionNumber)
|
|
96
|
-
));
|
|
81
|
+
return sessionLogs.find(callLog => (hasEmptyHashedExtensionId(callLog) &&
|
|
82
|
+
!stringOrEmpty(callLog.extensionNumber)));
|
|
97
83
|
}
|
|
98
|
-
|
|
99
|
-
return sessionLogs.find(callLog => (
|
|
100
|
-
!extensionNumberValue || stringOrEmpty(callLog.extensionNumber) === extensionNumberValue
|
|
101
|
-
));
|
|
84
|
+
return sessionLogs.find(callLog => (!extensionNumberValue || stringOrEmpty(callLog.extensionNumber) === extensionNumberValue));
|
|
102
85
|
}
|
|
103
|
-
|
|
104
|
-
exports.getCallLogExtensionNumber = getCallLogExtensionNumber;
|
|
105
|
-
exports.getCallLogHashedExtensionId = getCallLogHashedExtensionId;
|
|
106
|
-
exports.buildCallLogSessionWhere = buildCallLogSessionWhere;
|
|
107
|
-
exports.findMatchingCallLog = findMatchingCallLog;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LOG_DETAILS_FORMAT_TYPE = void 0;
|
|
4
|
+
const LOG_DETAILS_FORMAT_TYPE = {
|
|
5
|
+
PLAIN_TEXT: 'text/plain',
|
|
6
|
+
HTML: 'text/html',
|
|
7
|
+
MARKDOWN: 'text/markdown'
|
|
8
|
+
};
|
|
9
|
+
exports.LOG_DETAILS_FORMAT_TYPE = LOG_DETAILS_FORMAT_TYPE;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DebugTraceData, RequestWithHeaders, TraceActionSummary, TraceEntry, TraceOptions } from '../types';
|
|
2
|
+
declare class DebugTracer {
|
|
3
|
+
traces: TraceEntry[];
|
|
4
|
+
startTime: number;
|
|
5
|
+
requestId: string;
|
|
6
|
+
constructor(headers?: Record<string, unknown>);
|
|
7
|
+
_generateRequestId(): string;
|
|
8
|
+
_captureStackTrace(skipFrames?: number): string[];
|
|
9
|
+
trace(methodName: string, data?: unknown, options?: TraceOptions): DebugTracer;
|
|
10
|
+
traceError(methodName: string, error: Error | string, additionalData?: Record<string, unknown>): DebugTracer;
|
|
11
|
+
_sanitizeData(data: unknown): unknown;
|
|
12
|
+
_buildActionSummary(): TraceActionSummary[];
|
|
13
|
+
getTraceData(): DebugTraceData;
|
|
14
|
+
wrapResponse(response: Record<string, unknown>): Record<string, unknown>;
|
|
15
|
+
static fromRequest(req: RequestWithHeaders): DebugTracer;
|
|
16
|
+
}
|
|
17
|
+
export { DebugTracer };
|
|
@@ -1,46 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DebugTracer = void 0;
|
|
1
4
|
class DebugTracer {
|
|
2
|
-
/**
|
|
3
|
-
* Creates a new DebugTracer instance
|
|
4
|
-
* @param {Object} headers - Request headers object
|
|
5
|
-
*/
|
|
6
5
|
constructor(headers = {}) {
|
|
7
6
|
this.traces = [];
|
|
8
7
|
this.startTime = Date.now();
|
|
9
8
|
this.requestId = this._generateRequestId();
|
|
10
9
|
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Generates a unique request ID for tracking
|
|
14
|
-
* @returns {string} Unique request ID
|
|
15
|
-
*/
|
|
16
10
|
_generateRequestId() {
|
|
17
11
|
return `req_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
18
12
|
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Captures the current stack trace
|
|
22
|
-
* @param {number} skipFrames - Number of frames to skip from the top (default: 2)
|
|
23
|
-
* @returns {string[]} Array of stack trace lines
|
|
24
|
-
*/
|
|
25
13
|
_captureStackTrace(skipFrames = 2) {
|
|
26
14
|
const err = new Error();
|
|
27
15
|
const stack = err.stack || '';
|
|
28
16
|
const lines = stack.split('\n').slice(skipFrames);
|
|
29
17
|
return lines.map(line => line.trim()).filter(line => line.startsWith('at '));
|
|
30
18
|
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Records a trace entry with method name, data, and stack trace
|
|
34
|
-
* @param {string} methodName - Name of the method/function being traced
|
|
35
|
-
* @param {Object} data - Data to record (will be sanitized to remove sensitive info)
|
|
36
|
-
* @param {Object} options - Additional options
|
|
37
|
-
* @param {boolean} options.includeStack - Whether to include stack trace (default: true)
|
|
38
|
-
* @param {string} options.level - Log level: 'info', 'warn', 'error' (default: 'info')
|
|
39
|
-
* @returns {DebugTracer} Returns this for chaining
|
|
40
|
-
*/
|
|
41
19
|
trace(methodName, data = {}, options = {}) {
|
|
42
20
|
const { includeStack = true, level = 'info' } = options;
|
|
43
|
-
|
|
44
21
|
const traceEntry = {
|
|
45
22
|
timestamp: new Date().toISOString(),
|
|
46
23
|
elapsed: Date.now() - this.startTime,
|
|
@@ -48,80 +25,47 @@ class DebugTracer {
|
|
|
48
25
|
level,
|
|
49
26
|
data: this._sanitizeData(data)
|
|
50
27
|
};
|
|
51
|
-
|
|
52
28
|
if (includeStack) {
|
|
53
29
|
traceEntry.stackTrace = this._captureStackTrace(3);
|
|
54
30
|
}
|
|
55
|
-
|
|
56
31
|
this.traces.push(traceEntry);
|
|
57
32
|
return this;
|
|
58
33
|
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Records an error trace with full stack information
|
|
62
|
-
* @param {string} methodName - Name of the method where error occurred
|
|
63
|
-
* @param {Error|string} error - Error object or message
|
|
64
|
-
* @param {Object} additionalData - Additional context data
|
|
65
|
-
* @returns {DebugTracer} Returns this for chaining
|
|
66
|
-
*/
|
|
67
34
|
traceError(methodName, error, additionalData = {}) {
|
|
68
35
|
const errorData = {
|
|
69
36
|
message: error instanceof Error ? error.message : String(error),
|
|
70
37
|
errorStack: error instanceof Error ? error.stack : null,
|
|
71
38
|
...additionalData
|
|
72
39
|
};
|
|
73
|
-
|
|
74
40
|
return this.trace(methodName, errorData, { level: 'error' });
|
|
75
41
|
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Sanitizes data by removing sensitive fields
|
|
79
|
-
* @param {Object} data - Data to sanitize
|
|
80
|
-
* @returns {Object} Sanitized data
|
|
81
|
-
*/
|
|
82
42
|
_sanitizeData(data) {
|
|
83
43
|
if (!data || typeof data !== 'object') {
|
|
84
44
|
return data;
|
|
85
45
|
}
|
|
86
|
-
|
|
87
46
|
const sensitiveFields = [
|
|
88
47
|
'accessToken', 'refreshToken', 'apiKey', 'password',
|
|
89
48
|
'secret', 'token', 'authorization', 'auth', 'key',
|
|
90
49
|
'credential', 'credentials', 'privateKey', 'clientSecret'
|
|
91
50
|
];
|
|
92
|
-
|
|
93
51
|
const sanitized = Array.isArray(data) ? [...data] : { ...data };
|
|
94
|
-
|
|
95
52
|
const sanitizeRecursive = (obj) => {
|
|
96
53
|
if (!obj || typeof obj !== 'object') {
|
|
97
54
|
return obj;
|
|
98
55
|
}
|
|
99
|
-
|
|
100
56
|
for (const key of Object.keys(obj)) {
|
|
101
57
|
const lowerKey = key.toLowerCase();
|
|
102
58
|
if (sensitiveFields.some(field => lowerKey.includes(field.toLowerCase()))) {
|
|
103
|
-
// eslint-disable-next-line no-param-reassign
|
|
104
59
|
obj[key] = '[REDACTED]';
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
obj[key] = sanitizeRecursive(
|
|
108
|
-
Array.isArray(obj[key]) ? [...obj[key]] : { ...obj[key] }
|
|
109
|
-
);
|
|
60
|
+
}
|
|
61
|
+
else if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
62
|
+
obj[key] = sanitizeRecursive(Array.isArray(obj[key]) ? [...obj[key]] : { ...obj[key] });
|
|
110
63
|
}
|
|
111
64
|
}
|
|
112
65
|
return obj;
|
|
113
66
|
};
|
|
114
|
-
|
|
115
67
|
return sanitizeRecursive(sanitized);
|
|
116
68
|
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Builds a compact summary of all recorded actions, one entry per trace.
|
|
120
|
-
* Each entry contains the method name, log level, and elapsed time at the
|
|
121
|
-
* point the trace was recorded, making it easy to skim what happened without
|
|
122
|
-
* reading the full trace list.
|
|
123
|
-
* @returns {string[]} Array of human-readable action summary strings
|
|
124
|
-
*/
|
|
125
69
|
_buildActionSummary() {
|
|
126
70
|
return this.traces.map((t, i) => ({
|
|
127
71
|
index: i + 1,
|
|
@@ -131,11 +75,6 @@ class DebugTracer {
|
|
|
131
75
|
elapsedMs: t.elapsed
|
|
132
76
|
}));
|
|
133
77
|
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Gets the complete trace data for inclusion in response
|
|
137
|
-
* @returns {Object} Trace data object
|
|
138
|
-
*/
|
|
139
78
|
getTraceData() {
|
|
140
79
|
return {
|
|
141
80
|
sum: this._buildActionSummary(),
|
|
@@ -145,33 +84,18 @@ class DebugTracer {
|
|
|
145
84
|
traces: this.traces
|
|
146
85
|
};
|
|
147
86
|
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Gets trace data and merges it into a response object
|
|
151
|
-
* @param {Object} response - Original response object
|
|
152
|
-
* @returns {Object} Response with debug trace data appended (if debug mode enabled)
|
|
153
|
-
*/
|
|
154
87
|
wrapResponse(response) {
|
|
155
88
|
const traceData = this.getTraceData();
|
|
156
89
|
if (!traceData) {
|
|
157
90
|
return response;
|
|
158
91
|
}
|
|
159
|
-
|
|
160
92
|
return {
|
|
161
93
|
...response,
|
|
162
94
|
_debug: traceData
|
|
163
95
|
};
|
|
164
96
|
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Static helper to create tracer from Express request
|
|
168
|
-
* @param {Object} req - Express request object
|
|
169
|
-
* @returns {DebugTracer} New tracer instance
|
|
170
|
-
*/
|
|
171
97
|
static fromRequest(req) {
|
|
172
98
|
return new DebugTracer(req.headers || {});
|
|
173
99
|
}
|
|
174
100
|
}
|
|
175
|
-
|
|
176
|
-
module.exports = { DebugTracer };
|
|
177
|
-
|
|
101
|
+
exports.DebugTracer = DebugTracer;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.decoded = decoded;
|
|
27
|
+
exports.encode = encode;
|
|
28
|
+
const crypto = __importStar(require("crypto"));
|
|
29
|
+
function getCipherKey() {
|
|
30
|
+
if (!process.env.APP_SERVER_SECRET_KEY) {
|
|
31
|
+
throw new Error('APP_SERVER_SECRET_KEY is not defined');
|
|
32
|
+
}
|
|
33
|
+
if (process.env.APP_SERVER_SECRET_KEY.length < 32) {
|
|
34
|
+
// pad secret key with spaces if it is less than 32 bytes
|
|
35
|
+
return process.env.APP_SERVER_SECRET_KEY.padEnd(32, ' ');
|
|
36
|
+
}
|
|
37
|
+
if (process.env.APP_SERVER_SECRET_KEY.length > 32) {
|
|
38
|
+
// truncate secret key if it is more than 32 bytes
|
|
39
|
+
return process.env.APP_SERVER_SECRET_KEY.slice(0, 32);
|
|
40
|
+
}
|
|
41
|
+
return process.env.APP_SERVER_SECRET_KEY;
|
|
42
|
+
}
|
|
43
|
+
function encode(data) {
|
|
44
|
+
const cipher = crypto.createCipheriv('aes-256-cbc', getCipherKey(), Buffer.alloc(16, 0));
|
|
45
|
+
return cipher.update(data, 'utf8', 'hex') + cipher.final('hex');
|
|
46
|
+
}
|
|
47
|
+
function decoded(encryptedData) {
|
|
48
|
+
const decipher = crypto.createDecipheriv('aes-256-cbc', getCipherKey(), Buffer.alloc(16, 0));
|
|
49
|
+
return decipher.update(encryptedData, 'hex', 'utf8') + decipher.final('utf8');
|
|
50
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AsyncRouteHandler, ExpressLikeNext, ExpressLikeRequest, ExpressLikeResponse, LoggerContext, OperationFailureResult, ProviderError, ReturnMessage } from '../types';
|
|
2
|
+
declare function handleApiError(error: ProviderError, platform: string, operation: string, additionalContext?: LoggerContext): OperationFailureResult;
|
|
3
|
+
declare function getOperationErrorMessage(operation: string, platform: string): ReturnMessage;
|
|
4
|
+
declare function handleDatabaseError(error: ProviderError, operation: string, context?: LoggerContext): OperationFailureResult;
|
|
5
|
+
declare function asyncHandler(fn: AsyncRouteHandler): AsyncRouteHandler;
|
|
6
|
+
declare function errorMiddleware(err: ProviderError, req: ExpressLikeRequest, res: ExpressLikeResponse, next: ExpressLikeNext): void;
|
|
7
|
+
export { handleApiError, handleDatabaseError, asyncHandler, errorMiddleware, getOperationErrorMessage };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleApiError = handleApiError;
|
|
4
|
+
exports.handleDatabaseError = handleDatabaseError;
|
|
5
|
+
exports.asyncHandler = asyncHandler;
|
|
6
|
+
exports.errorMiddleware = errorMiddleware;
|
|
7
|
+
exports.getOperationErrorMessage = getOperationErrorMessage;
|
|
8
|
+
const logger = require('./logger');
|
|
9
|
+
const errorMessage = require('./generalErrorMessage');
|
|
10
|
+
function handleApiError(error, platform, operation, additionalContext = {}) {
|
|
11
|
+
const response = error.response;
|
|
12
|
+
const statusCode = response?.status ?? 'unknown';
|
|
13
|
+
logger.error(`${operation} failed for platform ${platform}`, {
|
|
14
|
+
platform,
|
|
15
|
+
operation,
|
|
16
|
+
statusCode,
|
|
17
|
+
errorMessage: error.message,
|
|
18
|
+
errorStack: error.stack,
|
|
19
|
+
errorResponse: response?.data,
|
|
20
|
+
...additionalContext
|
|
21
|
+
});
|
|
22
|
+
if (statusCode === 429) {
|
|
23
|
+
return {
|
|
24
|
+
successful: false,
|
|
25
|
+
returnMessage: errorMessage.rateLimitErrorMessage({ platform }),
|
|
26
|
+
extraDataTracking: {
|
|
27
|
+
statusCode
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const numericStatusCode = Number(statusCode);
|
|
32
|
+
if (numericStatusCode >= 400 && numericStatusCode < 410) {
|
|
33
|
+
return {
|
|
34
|
+
successful: false,
|
|
35
|
+
returnMessage: errorMessage.authorizationErrorMessage({ platform }),
|
|
36
|
+
extraDataTracking: {
|
|
37
|
+
statusCode
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const defaultErrorMessage = getOperationErrorMessage(operation, platform);
|
|
42
|
+
return {
|
|
43
|
+
successful: false,
|
|
44
|
+
returnMessage: defaultErrorMessage,
|
|
45
|
+
extraDataTracking: {
|
|
46
|
+
statusCode
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function getOperationErrorMessage(operation, platform) {
|
|
51
|
+
const operationMessages = {
|
|
52
|
+
createCallLog: {
|
|
53
|
+
message: 'Error creating call log',
|
|
54
|
+
details: ['Please check if your account has permission to CREATE logs.']
|
|
55
|
+
},
|
|
56
|
+
updateCallLog: {
|
|
57
|
+
message: 'Error updating call log',
|
|
58
|
+
details: [`Please check if the log entity still exists on ${platform} and your account has permission to EDIT logs.`]
|
|
59
|
+
},
|
|
60
|
+
getCallLog: {
|
|
61
|
+
message: 'Error getting call log',
|
|
62
|
+
details: ['Please check if your account has permission to READ logs.']
|
|
63
|
+
},
|
|
64
|
+
createMessageLog: {
|
|
65
|
+
message: 'Error creating message log',
|
|
66
|
+
details: ['Please check if your account has permission to CREATE logs.']
|
|
67
|
+
},
|
|
68
|
+
updateMessageLog: {
|
|
69
|
+
message: 'Error updating message log',
|
|
70
|
+
details: [`Please check if the log entity still exists on ${platform} and your account has permission to EDIT logs.`]
|
|
71
|
+
},
|
|
72
|
+
findContact: {
|
|
73
|
+
message: 'Error finding contact',
|
|
74
|
+
details: ['Please check if your account has permission to GET contacts.']
|
|
75
|
+
},
|
|
76
|
+
createContact: {
|
|
77
|
+
message: 'Error creating contact',
|
|
78
|
+
details: ['Please check if your account has permission to CREATE contacts.']
|
|
79
|
+
},
|
|
80
|
+
findContactWithName: {
|
|
81
|
+
message: 'Error searching contacts',
|
|
82
|
+
details: ['Please check if your account has permission to GET contacts.']
|
|
83
|
+
},
|
|
84
|
+
createAppointment: {
|
|
85
|
+
message: 'Error creating appointment',
|
|
86
|
+
details: ['Please check if your account has permission to CREATE appointments. or All attendees have email address.']
|
|
87
|
+
},
|
|
88
|
+
updateAppointment: {
|
|
89
|
+
message: 'Error updating appointment',
|
|
90
|
+
details: [`Please check if the appointment entity still exists on ${platform} and your account has permission to EDIT appointments. or All attendees have email address.`]
|
|
91
|
+
},
|
|
92
|
+
getAppointment: {
|
|
93
|
+
message: 'Error getting appointment',
|
|
94
|
+
details: ['Please check if your account has permission to GET appointments.']
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const operationInfo = operationMessages[operation] || {
|
|
98
|
+
message: `Error performing ${operation}`,
|
|
99
|
+
details: ['Please check if your account has the necessary permissions.']
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
message: operationInfo.message,
|
|
103
|
+
messageType: 'warning',
|
|
104
|
+
details: [
|
|
105
|
+
{
|
|
106
|
+
title: 'Details',
|
|
107
|
+
items: operationInfo.details.map((detail, index) => ({
|
|
108
|
+
id: index + 1,
|
|
109
|
+
type: 'text',
|
|
110
|
+
text: detail
|
|
111
|
+
}))
|
|
112
|
+
}
|
|
113
|
+
],
|
|
114
|
+
ttl: 5000
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function handleDatabaseError(error, operation, context = {}) {
|
|
118
|
+
logger.error(`Database operation failed: ${operation}`, {
|
|
119
|
+
operation,
|
|
120
|
+
errorMessage: error.message,
|
|
121
|
+
errorStack: error.stack,
|
|
122
|
+
...context
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
successful: false,
|
|
126
|
+
returnMessage: {
|
|
127
|
+
message: 'Database operation failed',
|
|
128
|
+
messageType: 'warning',
|
|
129
|
+
ttl: 5000
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function asyncHandler(fn) {
|
|
134
|
+
return (req, res, next) => {
|
|
135
|
+
Promise.resolve(fn(req, res, next)).catch(next);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function errorMiddleware(err, req, res, next) {
|
|
139
|
+
const platform = req.platform || req.query?.platform || 'unknown';
|
|
140
|
+
const operation = req.route?.path || 'unknown';
|
|
141
|
+
logger.error('Request failed', {
|
|
142
|
+
platform,
|
|
143
|
+
operation,
|
|
144
|
+
method: req.method,
|
|
145
|
+
path: req.path,
|
|
146
|
+
statusCode: err.statusCode || 500,
|
|
147
|
+
error: err,
|
|
148
|
+
correlationId: req.correlationId
|
|
149
|
+
});
|
|
150
|
+
const message = process.env.NODE_ENV === 'production'
|
|
151
|
+
? 'An internal error occurred'
|
|
152
|
+
: err.message;
|
|
153
|
+
res.status(err.statusCode || 500).json({
|
|
154
|
+
successful: false,
|
|
155
|
+
returnMessage: {
|
|
156
|
+
message,
|
|
157
|
+
messageType: 'error',
|
|
158
|
+
ttl: 5000
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReturnMessage } from '../types';
|
|
2
|
+
interface ErrorMessageParams {
|
|
3
|
+
platform?: string;
|
|
4
|
+
}
|
|
5
|
+
declare function rateLimitErrorMessage({ platform }: ErrorMessageParams): ReturnMessage;
|
|
6
|
+
declare function authorizationErrorMessage({ platform }: ErrorMessageParams): ReturnMessage;
|
|
7
|
+
export { authorizationErrorMessage, rateLimitErrorMessage };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.authorizationErrorMessage = authorizationErrorMessage;
|
|
4
|
+
exports.rateLimitErrorMessage = rateLimitErrorMessage;
|
|
1
5
|
function rateLimitErrorMessage({ platform }) {
|
|
2
6
|
return {
|
|
3
7
|
message: `Rate limit exceeded`,
|
|
@@ -15,9 +19,8 @@ function rateLimitErrorMessage({ platform }) {
|
|
|
15
19
|
}
|
|
16
20
|
],
|
|
17
21
|
ttl: 5000
|
|
18
|
-
}
|
|
22
|
+
};
|
|
19
23
|
}
|
|
20
|
-
|
|
21
24
|
function authorizationErrorMessage({ platform }) {
|
|
22
25
|
return {
|
|
23
26
|
message: `Authorization error`,
|
|
@@ -35,8 +38,5 @@ function authorizationErrorMessage({ platform }) {
|
|
|
35
38
|
}
|
|
36
39
|
],
|
|
37
40
|
ttl: 5000
|
|
38
|
-
}
|
|
41
|
+
};
|
|
39
42
|
}
|
|
40
|
-
|
|
41
|
-
exports.rateLimitErrorMessage = rateLimitErrorMessage;
|
|
42
|
-
exports.authorizationErrorMessage = authorizationErrorMessage;
|
package/dist/lib/jwt.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeJwt = decodeJwt;
|
|
4
|
+
exports.generateJwt = generateJwt;
|
|
5
|
+
const { sign, verify } = require('jsonwebtoken');
|
|
6
|
+
const logger = require('./logger');
|
|
7
|
+
function generateJwt(data) {
|
|
8
|
+
return sign(data, process.env.APP_SERVER_SECRET_KEY, { expiresIn: '2w' });
|
|
9
|
+
}
|
|
10
|
+
function decodeJwt(token) {
|
|
11
|
+
try {
|
|
12
|
+
return verify(token, process.env.APP_SERVER_SECRET_KEY);
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
logger.error('Error decoding JWT', { stack: e.stack });
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ApiRequestLogOptions, ChildLogger, DatabaseQueryLogOptions, LoggerContext, LoggerLevelName, LoggerOptions } from '../types';
|
|
2
|
+
declare const LOG_LEVELS: Record<LoggerLevelName, number>;
|
|
3
|
+
declare class Logger {
|
|
4
|
+
level: number;
|
|
5
|
+
isProd: boolean;
|
|
6
|
+
enableColors: boolean;
|
|
7
|
+
constructor(options?: LoggerOptions);
|
|
8
|
+
_getLogLevel(levelName: string): number;
|
|
9
|
+
_shouldLog(level: LoggerLevelName): boolean;
|
|
10
|
+
_formatMessage(level: LoggerLevelName, message: string, context?: LoggerContext): string;
|
|
11
|
+
_log(level: LoggerLevelName, message: string, context?: LoggerContext): void;
|
|
12
|
+
error(message: string, context?: LoggerContext): void;
|
|
13
|
+
warn(message: string, context?: LoggerContext): void;
|
|
14
|
+
info(message: string, context?: LoggerContext): void;
|
|
15
|
+
debug(message: string, context?: LoggerContext): void;
|
|
16
|
+
child(defaultContext?: LoggerContext): ChildLogger;
|
|
17
|
+
logApiRequest({ method, url, status, duration, platform, error }: ApiRequestLogOptions): void;
|
|
18
|
+
logDatabaseQuery({ operation, table, duration, error }: DatabaseQueryLogOptions): void;
|
|
19
|
+
}
|
|
20
|
+
declare const logger: Logger & {
|
|
21
|
+
Logger: typeof Logger;
|
|
22
|
+
LOG_LEVELS: typeof LOG_LEVELS;
|
|
23
|
+
};
|
|
24
|
+
export = logger;
|