@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
|
@@ -1,67 +1,107 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-check
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
/** @typedef {import('../types').AdminConfigRecord} AdminConfigRecord */
|
|
5
|
+
/** @typedef {import('../types').AdminConnectorImplementation} AdminConnectorImplementation */
|
|
6
|
+
/** @typedef {import('../types').AdminHandlerUser} AdminHandlerUser */
|
|
7
|
+
/** @typedef {import('../types').AdminReportParams} AdminReportParams */
|
|
8
|
+
/** @typedef {import('../types').AdminSettingsParams} AdminSettingsParams */
|
|
9
|
+
/** @typedef {import('../types').CrmUserInfo} CrmUserInfo */
|
|
10
|
+
/** @typedef {import('../types').OAuthInfo} OAuthInfo */
|
|
11
|
+
/** @typedef {import('../types').ProxyConfig} ProxyConfig */
|
|
12
|
+
/** @typedef {import('../types').RcExtensionInfo} RcExtensionInfo */
|
|
13
|
+
/** @typedef {import('../types').RingCentralSdkLike} RingCentralSdkLike */
|
|
14
|
+
/** @typedef {import('../types').ServerLoggingSettingsParams} ServerLoggingSettingsParams */
|
|
15
|
+
/** @typedef {import('../types').UpdateAdminRcTokensParams} UpdateAdminRcTokensParams */
|
|
16
|
+
/** @typedef {import('../types').UpdateServerLoggingSettingsParams} UpdateServerLoggingSettingsParams */
|
|
17
|
+
/** @typedef {import('../types').UpsertAdminSettingsParams} UpsertAdminSettingsParams */
|
|
18
|
+
/** @typedef {import('../types').UserMappingParams} UserMappingParams */
|
|
19
|
+
/** @typedef {import('../types').UserMappingResultItem} UserMappingResultItem */
|
|
20
|
+
/** @typedef {import('../types').UserReportParams} UserReportParams */
|
|
21
|
+
/** @typedef {import('../types').ValidateAdminRoleParams} ValidateAdminRoleParams */
|
|
22
|
+
/** @typedef {import('../types').ValidateAdminRoleResult} ValidateAdminRoleResult */
|
|
23
|
+
/** @typedef {import('../types').ValidateRcUserTokenParams} ValidateRcUserTokenParams */
|
|
24
|
+
/** @typedef {import('../types').ValidateRcUserTokenResult} ValidateRcUserTokenResult */
|
|
25
|
+
const axios = /** @type {{ get(url: string, config?: Record<string, unknown>): Promise<{ data?: any }> }} */ ( /** @type {unknown} */(require('axios')));
|
|
26
|
+
const { AdminConfigModel: RawAdminConfigModel } = require('../models/adminConfigModel');
|
|
27
|
+
const AdminConfigModel = /** @type {{ findByPk(id: string): Promise<AdminConfigRecord | null>, create(values: Record<string, unknown>): Promise<AdminConfigRecord>, update(values: Record<string, unknown>, options?: Record<string, unknown>): Promise<any> }} */ (RawAdminConfigModel);
|
|
28
|
+
const connectorRegistry = /** @type {{ getConnector(platform: string): AdminConnectorImplementation }} */ ( /** @type {unknown} */(require('../connector/registry')));
|
|
29
|
+
const oauth = /** @type {{ getOAuthApp(info: OAuthInfo): any, checkAndRefreshAccessToken(oauthApp: any, user: AdminHandlerUser): Promise<AdminHandlerUser | null> }} */ (require('../lib/oauth'));
|
|
30
|
+
const { RingCentral: RawRingCentral } = require('../lib/ringcentral');
|
|
31
|
+
const RingCentral = /** @type {new (options: Record<string, unknown>) => RingCentralSdkLike} */ ( /** @type {unknown} */(RawRingCentral));
|
|
32
|
+
const { Connector: RawConnector } = require('../models/dynamo/connectorSchema');
|
|
33
|
+
const Connector = /** @type {{ getProxyConfig(proxyId: string): Promise<ProxyConfig | null> }} */ ( /** @type {unknown} */(RawConnector));
|
|
34
|
+
const logger = /** @type {{ error(message: string, context?: Record<string, unknown>): void }} */ (require('../lib/logger'));
|
|
35
|
+
const { handleDatabaseError: rawHandleDatabaseError } = require('../lib/errorHandler');
|
|
36
|
+
const handleDatabaseError = /** @type {(error: unknown, message: string) => any} */ (rawHandleDatabaseError);
|
|
37
|
+
const { getHashValue: rawGetHashValue } = require('../lib/util');
|
|
38
|
+
const getHashValue = /** @type {(value: string | number, key?: string) => string} */ (rawGetHashValue);
|
|
39
|
+
const CALL_AGGREGATION_GROUPS = ["Company", "CompanyNumbers", "Users", "Queues", "IVRs", "IVAs", "SharedLines", "UserGroups", "Sites", "Departments"];
|
|
12
40
|
const RC_EXTENSION_ENDPOINT = 'https://platform.ringcentral.com/restapi/v1.0/account/~/extension/~';
|
|
13
|
-
|
|
41
|
+
/**
|
|
42
|
+
* @param {ValidateRcUserTokenParams} params
|
|
43
|
+
* @returns {Promise<ValidateRcUserTokenResult>}
|
|
44
|
+
*/
|
|
14
45
|
async function validateRcUserToken({ rcAccessToken }) {
|
|
15
46
|
if (!rcAccessToken) {
|
|
16
47
|
throw new Error('rcAccessToken is required');
|
|
17
48
|
}
|
|
18
|
-
const rcExtensionResponse = await axios.get(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
});
|
|
49
|
+
const rcExtensionResponse = await axios.get(RC_EXTENSION_ENDPOINT, {
|
|
50
|
+
headers: {
|
|
51
|
+
Authorization: `Bearer ${rcAccessToken}`,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
25
54
|
const extensionData = rcExtensionResponse.data ?? {};
|
|
26
55
|
return {
|
|
27
56
|
rcAccountId: extensionData?.account?.id?.toString() ?? '',
|
|
28
57
|
rcExtensionId: extensionData?.id?.toString() ?? ''
|
|
29
58
|
};
|
|
30
59
|
}
|
|
31
|
-
|
|
60
|
+
/**
|
|
61
|
+
* @param {ValidateAdminRoleParams} params
|
|
62
|
+
* @returns {Promise<ValidateAdminRoleResult>}
|
|
63
|
+
*/
|
|
32
64
|
async function validateAdminRole({ rcAccessToken }) {
|
|
33
|
-
const rcExtensionResponse = await axios.get(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
},
|
|
39
|
-
});
|
|
65
|
+
const rcExtensionResponse = await axios.get(RC_EXTENSION_ENDPOINT, {
|
|
66
|
+
headers: {
|
|
67
|
+
Authorization: `Bearer ${rcAccessToken}`,
|
|
68
|
+
},
|
|
69
|
+
});
|
|
40
70
|
return {
|
|
41
71
|
isValidated: !!rcExtensionResponse.data?.permissions?.admin?.enabled || (!!process.env.ADMIN_EXTENSION_ID_DEV_PASS_LIST && process.env.ADMIN_EXTENSION_ID_DEV_PASS_LIST.split(',').includes(rcExtensionResponse.data.id.toString())),
|
|
42
72
|
rcAccountId: rcExtensionResponse.data.account.id
|
|
43
73
|
};
|
|
44
74
|
}
|
|
45
|
-
|
|
75
|
+
/**
|
|
76
|
+
* @param {UpsertAdminSettingsParams} params
|
|
77
|
+
* @returns {Promise<void>}
|
|
78
|
+
*/
|
|
46
79
|
async function upsertAdminSettings({ hashedRcAccountId, adminSettings }) {
|
|
47
80
|
let existingAdminConfig = await AdminConfigModel.findByPk(hashedRcAccountId);
|
|
48
81
|
if (existingAdminConfig) {
|
|
49
82
|
await existingAdminConfig.update({
|
|
50
83
|
...adminSettings
|
|
51
84
|
});
|
|
52
|
-
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
53
87
|
await AdminConfigModel.create({
|
|
54
88
|
id: hashedRcAccountId,
|
|
55
89
|
...adminSettings
|
|
56
90
|
});
|
|
57
91
|
}
|
|
58
92
|
}
|
|
59
|
-
|
|
93
|
+
/**
|
|
94
|
+
* @param {AdminSettingsParams} params
|
|
95
|
+
* @returns {Promise<AdminConfigRecord | null>}
|
|
96
|
+
*/
|
|
60
97
|
async function getAdminSettings({ hashedRcAccountId }) {
|
|
61
98
|
const existingAdminConfig = await AdminConfigModel.findByPk(hashedRcAccountId);
|
|
62
99
|
return existingAdminConfig;
|
|
63
100
|
}
|
|
64
|
-
|
|
101
|
+
/**
|
|
102
|
+
* @param {UpdateAdminRcTokensParams} params
|
|
103
|
+
* @returns {Promise<void>}
|
|
104
|
+
*/
|
|
65
105
|
async function updateAdminRcTokens({ hashedRcAccountId, adminAccessToken, adminRefreshToken, adminTokenExpiry }) {
|
|
66
106
|
const existingAdminConfig = await AdminConfigModel.findByPk(hashedRcAccountId);
|
|
67
107
|
if (existingAdminConfig) {
|
|
@@ -76,7 +116,10 @@ async function updateAdminRcTokens({ hashedRcAccountId, adminAccessToken, adminR
|
|
|
76
116
|
});
|
|
77
117
|
}
|
|
78
118
|
}
|
|
79
|
-
|
|
119
|
+
/**
|
|
120
|
+
* @param {ServerLoggingSettingsParams} params
|
|
121
|
+
* @returns {Promise<unknown>}
|
|
122
|
+
*/
|
|
80
123
|
async function getServerLoggingSettings({ user }) {
|
|
81
124
|
const platformModule = connectorRegistry.getConnector(user.platform);
|
|
82
125
|
if (platformModule.getServerLoggingSettings) {
|
|
@@ -85,7 +128,10 @@ async function getServerLoggingSettings({ user }) {
|
|
|
85
128
|
}
|
|
86
129
|
return {};
|
|
87
130
|
}
|
|
88
|
-
|
|
131
|
+
/**
|
|
132
|
+
* @param {UpdateServerLoggingSettingsParams} params
|
|
133
|
+
* @returns {Promise<unknown>}
|
|
134
|
+
*/
|
|
89
135
|
async function updateServerLoggingSettings({ user, additionalFieldValues }) {
|
|
90
136
|
const platformModule = connectorRegistry.getConnector(user.platform);
|
|
91
137
|
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname })));
|
|
@@ -95,7 +141,10 @@ async function updateServerLoggingSettings({ user, additionalFieldValues }) {
|
|
|
95
141
|
}
|
|
96
142
|
return {};
|
|
97
143
|
}
|
|
98
|
-
|
|
144
|
+
/**
|
|
145
|
+
* @param {AdminReportParams} params
|
|
146
|
+
* @returns {Promise<Record<string, unknown>>}
|
|
147
|
+
*/
|
|
99
148
|
async function getAdminReport({ rcAccountId, timezone, timeFrom, timeTo, groupBy }) {
|
|
100
149
|
try {
|
|
101
150
|
if (!process.env.RINGCENTRAL_SERVER || !process.env.RINGCENTRAL_CLIENT_ID || !process.env.RINGCENTRAL_CLIENT_SECRET) {
|
|
@@ -110,7 +159,7 @@ async function getAdminReport({ rcAccountId, timezone, timeFrom, timeTo, groupBy
|
|
|
110
159
|
redirectUri: `${process.env.APP_SERVER}/ringcentral/oauth/callback`
|
|
111
160
|
});
|
|
112
161
|
const hashedRcAccountId = getHashValue(rcAccountId, process.env.HASH_KEY);
|
|
113
|
-
let adminConfig = await AdminConfigModel.findByPk(hashedRcAccountId);
|
|
162
|
+
let adminConfig = /** @type {any} */ (await AdminConfigModel.findByPk(hashedRcAccountId));
|
|
114
163
|
const isTokenExpired = adminConfig.adminTokenExpiry < new Date();
|
|
115
164
|
if (isTokenExpired) {
|
|
116
165
|
const { access_token, refresh_token, expire_time } = await rcSDK.refreshToken({
|
|
@@ -127,7 +176,9 @@ async function getAdminReport({ rcAccountId, timezone, timeFrom, timeTo, groupBy
|
|
|
127
176
|
timeTo,
|
|
128
177
|
groupBy: groupBy == 'undefined' ? CALL_AGGREGATION_GROUPS[0] : groupBy
|
|
129
178
|
});
|
|
179
|
+
/** @type {Record<string, unknown>[]} */
|
|
130
180
|
var callLogStats = [];
|
|
181
|
+
/** @type {string[]} */
|
|
131
182
|
var itemKeys = [];
|
|
132
183
|
for (const record of callsAggregationData.data.records) {
|
|
133
184
|
if (!record?.info?.name) {
|
|
@@ -158,14 +209,18 @@ async function getAdminReport({ rcAccountId, timezone, timeFrom, timeTo, groupBy
|
|
|
158
209
|
groupedBy: callsAggregationData.data.groupedBy,
|
|
159
210
|
groupKeys: CALL_AGGREGATION_GROUPS
|
|
160
211
|
};
|
|
161
|
-
}
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
162
214
|
logger.error('Error getting admin report', { error });
|
|
163
215
|
return {
|
|
164
216
|
callLogStats: {}
|
|
165
217
|
};
|
|
166
218
|
}
|
|
167
219
|
}
|
|
168
|
-
|
|
220
|
+
/**
|
|
221
|
+
* @param {UserReportParams} params
|
|
222
|
+
* @returns {Promise<Record<string, unknown> | null>}
|
|
223
|
+
*/
|
|
169
224
|
async function getUserReport({ rcAccountId, rcExtensionId, timezone, timeFrom, timeTo }) {
|
|
170
225
|
try {
|
|
171
226
|
if (!process.env.RINGCENTRAL_SERVER || !process.env.RINGCENTRAL_CLIENT_ID || !process.env.RINGCENTRAL_CLIENT_SECRET) {
|
|
@@ -180,7 +235,7 @@ async function getUserReport({ rcAccountId, rcExtensionId, timezone, timeFrom, t
|
|
|
180
235
|
redirectUri: `${process.env.APP_SERVER}/ringcentral/oauth/callback`
|
|
181
236
|
});
|
|
182
237
|
const hashedRcAccountId = getHashValue(rcAccountId, process.env.HASH_KEY);
|
|
183
|
-
let adminConfig = await AdminConfigModel.findByPk(hashedRcAccountId);
|
|
238
|
+
let adminConfig = /** @type {any} */ (await AdminConfigModel.findByPk(hashedRcAccountId));
|
|
184
239
|
const isTokenExpired = adminConfig.adminTokenExpiry < new Date();
|
|
185
240
|
if (isTokenExpired) {
|
|
186
241
|
const { access_token, refresh_token, expire_time } = await rcSDK.refreshToken({
|
|
@@ -229,12 +284,16 @@ async function getUserReport({ rcAccountId, rcExtensionId, timezone, timeFrom, t
|
|
|
229
284
|
}
|
|
230
285
|
};
|
|
231
286
|
return reportStats;
|
|
232
|
-
}
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
233
289
|
logger.error('Error getting user report', { error });
|
|
234
290
|
return null;
|
|
235
291
|
}
|
|
236
292
|
}
|
|
237
|
-
|
|
293
|
+
/**
|
|
294
|
+
* @param {UserMappingParams} params
|
|
295
|
+
* @returns {Promise<UserMappingResultItem[] | any>}
|
|
296
|
+
*/
|
|
238
297
|
async function getUserMapping({ user, hashedRcAccountId, rcExtensionList }) {
|
|
239
298
|
let adminConfig = null;
|
|
240
299
|
try {
|
|
@@ -259,8 +318,8 @@ async function getUserMapping({ user, hashedRcAccountId, rcExtensionList }) {
|
|
|
259
318
|
case 'oauth':
|
|
260
319
|
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname, proxyId, proxyConfig })));
|
|
261
320
|
// eslint-disable-next-line no-param-reassign
|
|
262
|
-
|
|
263
|
-
if (!
|
|
321
|
+
const refreshedUser = await oauth.checkAndRefreshAccessToken(oauthApp, user);
|
|
322
|
+
if (!refreshedUser) {
|
|
264
323
|
return {
|
|
265
324
|
successful: false,
|
|
266
325
|
returnMessage: {
|
|
@@ -269,8 +328,9 @@ async function getUserMapping({ user, hashedRcAccountId, rcExtensionList }) {
|
|
|
269
328
|
ttl: 5000
|
|
270
329
|
},
|
|
271
330
|
isRevokeUserSession: true
|
|
272
|
-
}
|
|
331
|
+
};
|
|
273
332
|
}
|
|
333
|
+
user = refreshedUser;
|
|
274
334
|
authHeader = `Bearer ${user.accessToken}`;
|
|
275
335
|
break;
|
|
276
336
|
case 'apiKey':
|
|
@@ -279,10 +339,13 @@ async function getUserMapping({ user, hashedRcAccountId, rcExtensionList }) {
|
|
|
279
339
|
break;
|
|
280
340
|
}
|
|
281
341
|
const crmUserList = await platformModule.getUserList({ user, authHeader, proxyConfig });
|
|
342
|
+
/** @type {UserMappingResultItem[]} */
|
|
282
343
|
const userMappingResult = [];
|
|
344
|
+
/** @type {Array<{ crmUserId: string, rcExtensionId: string[] }>} */
|
|
283
345
|
const newUserMappings = [];
|
|
284
346
|
for (const crmUser of crmUserList) {
|
|
285
347
|
const existingMapping = adminConfig?.userMappings?.find(u => u.crmUserId == crmUser.id);
|
|
348
|
+
/** @type {Array<string | number>} */
|
|
286
349
|
let existingMappingRcExtensionIds = [];
|
|
287
350
|
// TEMP: backward compatibility for string value
|
|
288
351
|
if (existingMapping?.rcExtensionId) {
|
|
@@ -290,7 +353,7 @@ async function getUserMapping({ user, hashedRcAccountId, rcExtensionList }) {
|
|
|
290
353
|
existingMappingRcExtensionIds = [existingMapping.rcExtensionId];
|
|
291
354
|
}
|
|
292
355
|
else {
|
|
293
|
-
existingMappingRcExtensionIds = existingMapping.rcExtensionId;
|
|
356
|
+
existingMappingRcExtensionIds = /** @type {Array<string | number>} */ (existingMapping.rcExtensionId);
|
|
294
357
|
}
|
|
295
358
|
}
|
|
296
359
|
const rcExtension = rcExtensionList.filter(e => existingMappingRcExtensionIds.includes(e.id));
|
|
@@ -312,11 +375,9 @@ async function getUserMapping({ user, hashedRcAccountId, rcExtensionList }) {
|
|
|
312
375
|
}
|
|
313
376
|
// Case: new mapping
|
|
314
377
|
else {
|
|
315
|
-
const rcExtensionForNewMapping = rcExtensionList.find(u =>
|
|
316
|
-
u.email === crmUser.email ||
|
|
378
|
+
const rcExtensionForNewMapping = rcExtensionList.find(u => u.email === crmUser.email ||
|
|
317
379
|
u.name === crmUser.name ||
|
|
318
|
-
(`${u.firstName} ${u.lastName}` === crmUser.name)
|
|
319
|
-
);
|
|
380
|
+
(`${u.firstName} ${u.lastName}` === crmUser.name));
|
|
320
381
|
if (rcExtensionForNewMapping) {
|
|
321
382
|
userMappingResult.push({
|
|
322
383
|
crmUser: {
|
|
@@ -325,11 +386,11 @@ async function getUserMapping({ user, hashedRcAccountId, rcExtensionList }) {
|
|
|
325
386
|
email: crmUser.email ?? '',
|
|
326
387
|
},
|
|
327
388
|
rcUser: [{
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
389
|
+
extensionId: rcExtensionForNewMapping.id,
|
|
390
|
+
name: rcExtensionForNewMapping.name || `${rcExtensionForNewMapping.firstName} ${rcExtensionForNewMapping.lastName}`,
|
|
391
|
+
extensionNumber: rcExtensionForNewMapping?.extensionNumber ?? '',
|
|
392
|
+
email: rcExtensionForNewMapping?.email ?? ''
|
|
393
|
+
}]
|
|
333
394
|
});
|
|
334
395
|
newUserMappings.push({
|
|
335
396
|
crmUserId: crmUser.id.toString(),
|
|
@@ -350,12 +411,14 @@ async function getUserMapping({ user, hashedRcAccountId, rcExtensionList }) {
|
|
|
350
411
|
}
|
|
351
412
|
// One-time init
|
|
352
413
|
if (!adminConfig?.userMappings) {
|
|
414
|
+
/** @type {Array<{ crmUserId: string, rcExtensionId: string[] }>} */
|
|
353
415
|
const initialUserMappings = [];
|
|
354
416
|
for (const userMapping of userMappingResult) {
|
|
355
|
-
|
|
417
|
+
const rcUser = /** @type {any} */ (userMapping.rcUser);
|
|
418
|
+
if (rcUser?.extensionId) {
|
|
356
419
|
initialUserMappings.push({
|
|
357
420
|
crmUserId: userMapping.crmUser.id.toString(),
|
|
358
|
-
rcExtensionId: [
|
|
421
|
+
rcExtensionId: [rcUser.extensionId.toString()]
|
|
359
422
|
});
|
|
360
423
|
}
|
|
361
424
|
}
|
|
@@ -375,10 +438,10 @@ async function getUserMapping({ user, hashedRcAccountId, rcExtensionList }) {
|
|
|
375
438
|
if (newUserMappings.length > 0) {
|
|
376
439
|
// TEMP: convert string to array
|
|
377
440
|
if (adminConfig?.userMappings) {
|
|
378
|
-
adminConfig.userMappings = adminConfig.userMappings.map(u => ({
|
|
441
|
+
adminConfig.userMappings = /** @type {any} */ (adminConfig.userMappings.map(u => ({
|
|
379
442
|
...u,
|
|
380
443
|
rcExtensionId: [u.rcExtensionId]
|
|
381
|
-
}));
|
|
444
|
+
})));
|
|
382
445
|
try {
|
|
383
446
|
await upsertAdminSettings({
|
|
384
447
|
hashedRcAccountId,
|
|
@@ -409,13 +472,15 @@ async function getUserMapping({ user, hashedRcAccountId, rcExtensionList }) {
|
|
|
409
472
|
}
|
|
410
473
|
return [];
|
|
411
474
|
}
|
|
412
|
-
|
|
475
|
+
/**
|
|
476
|
+
* @param {UserMappingParams} params
|
|
477
|
+
* @returns {Promise<UserMappingResultItem[] | any>}
|
|
478
|
+
*/
|
|
413
479
|
async function reinitializeUserMapping({ user, hashedRcAccountId, rcExtensionList }) {
|
|
414
480
|
const platformModule = connectorRegistry.getConnector(user.platform);
|
|
415
481
|
if (!platformModule.getUserList) {
|
|
416
482
|
return [];
|
|
417
483
|
}
|
|
418
|
-
|
|
419
484
|
const proxyId = user.platformAdditionalInfo?.proxyId;
|
|
420
485
|
let proxyConfig = null;
|
|
421
486
|
if (proxyId) {
|
|
@@ -424,15 +489,14 @@ async function reinitializeUserMapping({ user, hashedRcAccountId, rcExtensionLis
|
|
|
424
489
|
return [];
|
|
425
490
|
}
|
|
426
491
|
}
|
|
427
|
-
|
|
428
492
|
const authType = await platformModule.getAuthType({ proxyId, proxyConfig });
|
|
429
493
|
let authHeader = '';
|
|
430
494
|
switch (authType) {
|
|
431
495
|
case 'oauth':
|
|
432
496
|
const oauthApp = oauth.getOAuthApp((await platformModule.getOauthInfo({ tokenUrl: user?.platformAdditionalInfo?.tokenUrl, hostname: user?.hostname, proxyId, proxyConfig })));
|
|
433
497
|
// eslint-disable-next-line no-param-reassign
|
|
434
|
-
|
|
435
|
-
if (!
|
|
498
|
+
const refreshedUser = await oauth.checkAndRefreshAccessToken(oauthApp, user);
|
|
499
|
+
if (!refreshedUser) {
|
|
436
500
|
return {
|
|
437
501
|
successful: false,
|
|
438
502
|
returnMessage: {
|
|
@@ -441,8 +505,9 @@ async function reinitializeUserMapping({ user, hashedRcAccountId, rcExtensionLis
|
|
|
441
505
|
ttl: 5000
|
|
442
506
|
},
|
|
443
507
|
isRevokeUserSession: true
|
|
444
|
-
}
|
|
508
|
+
};
|
|
445
509
|
}
|
|
510
|
+
user = refreshedUser;
|
|
446
511
|
authHeader = `Bearer ${user.accessToken}`;
|
|
447
512
|
break;
|
|
448
513
|
case 'apiKey':
|
|
@@ -450,19 +515,16 @@ async function reinitializeUserMapping({ user, hashedRcAccountId, rcExtensionLis
|
|
|
450
515
|
authHeader = `Basic ${basicAuth}`;
|
|
451
516
|
break;
|
|
452
517
|
}
|
|
453
|
-
|
|
454
518
|
const crmUserList = await platformModule.getUserList({ user, authHeader, proxyConfig });
|
|
519
|
+
/** @type {UserMappingResultItem[]} */
|
|
455
520
|
const userMappingResult = [];
|
|
521
|
+
/** @type {Array<{ crmUserId: string, rcExtensionId: string[] }>} */
|
|
456
522
|
const initialUserMappings = [];
|
|
457
|
-
|
|
458
523
|
// Auto-match CRM users with RC extensions by email or name
|
|
459
524
|
for (const crmUser of crmUserList) {
|
|
460
|
-
const rcExtensionForMapping = rcExtensionList.find(u =>
|
|
461
|
-
u.email === crmUser.email ||
|
|
525
|
+
const rcExtensionForMapping = rcExtensionList.find(u => u.email === crmUser.email ||
|
|
462
526
|
u.name === crmUser.name ||
|
|
463
|
-
(`${u.firstName} ${u.lastName}` === crmUser.name)
|
|
464
|
-
);
|
|
465
|
-
|
|
527
|
+
(`${u.firstName} ${u.lastName}` === crmUser.name));
|
|
466
528
|
if (rcExtensionForMapping) {
|
|
467
529
|
userMappingResult.push({
|
|
468
530
|
crmUser: {
|
|
@@ -471,11 +533,11 @@ async function reinitializeUserMapping({ user, hashedRcAccountId, rcExtensionLis
|
|
|
471
533
|
email: crmUser.email ?? '',
|
|
472
534
|
},
|
|
473
535
|
rcUser: [{
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
536
|
+
extensionId: rcExtensionForMapping.id,
|
|
537
|
+
name: rcExtensionForMapping.name || `${rcExtensionForMapping.firstName} ${rcExtensionForMapping.lastName}`,
|
|
538
|
+
extensionNumber: rcExtensionForMapping?.extensionNumber ?? '',
|
|
539
|
+
email: rcExtensionForMapping?.email ?? ''
|
|
540
|
+
}]
|
|
479
541
|
});
|
|
480
542
|
initialUserMappings.push({
|
|
481
543
|
crmUserId: crmUser.id.toString(),
|
|
@@ -493,7 +555,6 @@ async function reinitializeUserMapping({ user, hashedRcAccountId, rcExtensionLis
|
|
|
493
555
|
});
|
|
494
556
|
}
|
|
495
557
|
}
|
|
496
|
-
|
|
497
558
|
// Overwrite existing mappings with fresh auto-matched mappings
|
|
498
559
|
try {
|
|
499
560
|
await upsertAdminSettings({
|
|
@@ -506,10 +567,8 @@ async function reinitializeUserMapping({ user, hashedRcAccountId, rcExtensionLis
|
|
|
506
567
|
catch (error) {
|
|
507
568
|
return handleDatabaseError(error, 'Error reinitializing user mapping');
|
|
508
569
|
}
|
|
509
|
-
|
|
510
570
|
return userMappingResult;
|
|
511
571
|
}
|
|
512
|
-
|
|
513
572
|
exports.validateAdminRole = validateAdminRole;
|
|
514
573
|
exports.validateRcUserToken = validateRcUserToken;
|
|
515
574
|
exports.upsertAdminSettings = upsertAdminSettings;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** @typedef {import('../types').AppointmentAuthParams} AppointmentAuthParams */
|
|
2
|
+
/** @typedef {import('../types').AppointmentAuthFailure} AppointmentAuthFailure */
|
|
3
|
+
/** @typedef {import('../types').AppointmentAuthResult} AppointmentAuthResult */
|
|
4
|
+
/** @typedef {import('../types').AppointmentHandlerResult} AppointmentHandlerResult */
|
|
5
|
+
/** @typedef {import('../types').AppointmentPayloadParams} AppointmentPayloadParams */
|
|
6
|
+
/** @typedef {import('../types').AppointmentPatchParams} AppointmentPatchParams */
|
|
7
|
+
/** @typedef {import('../types').AppointmentRecordParams} AppointmentRecordParams */
|
|
8
|
+
/** @typedef {import('../types').ListAppointmentsParams} ListAppointmentsParams */
|
|
9
|
+
export {};
|
|
@@ -1,16 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-check
|
|
3
|
+
/** @typedef {import('../types').AppointmentAuthParams} AppointmentAuthParams */
|
|
4
|
+
/** @typedef {import('../types').AppointmentAuthFailure} AppointmentAuthFailure */
|
|
5
|
+
/** @typedef {import('../types').AppointmentAuthResult} AppointmentAuthResult */
|
|
6
|
+
/** @typedef {import('../types').AppointmentHandlerResult} AppointmentHandlerResult */
|
|
7
|
+
/** @typedef {import('../types').AppointmentPayloadParams} AppointmentPayloadParams */
|
|
8
|
+
/** @typedef {import('../types').AppointmentPatchParams} AppointmentPatchParams */
|
|
9
|
+
/** @typedef {import('../types').AppointmentRecordParams} AppointmentRecordParams */
|
|
10
|
+
/** @typedef {import('../types').ListAppointmentsParams} ListAppointmentsParams */
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const { UserModel: UserModelImport } = require('../models/userModel');
|
|
13
|
+
const UserModel = /** @type {any} */ (UserModelImport);
|
|
14
|
+
const oauth = /** @type {any} */ (require('../lib/oauth'));
|
|
15
|
+
const connectorRegistry = /** @type {any} */ (require('../connector/registry'));
|
|
16
|
+
const { Connector: ConnectorImport } = require('../models/dynamo/connectorSchema');
|
|
17
|
+
const Connector = /** @type {any} */ (ConnectorImport);
|
|
5
18
|
const { handleApiError, handleDatabaseError } = require('../lib/errorHandler');
|
|
6
|
-
|
|
19
|
+
/**
|
|
20
|
+
* @param {AppointmentAuthParams} params
|
|
21
|
+
* @returns {Promise<AppointmentAuthResult>}
|
|
22
|
+
*/
|
|
7
23
|
async function resolveAuth({ platform, userId }) {
|
|
8
24
|
let user = null;
|
|
9
25
|
try {
|
|
10
26
|
user = await UserModel.findByPk(userId);
|
|
11
27
|
}
|
|
12
28
|
catch (error) {
|
|
13
|
-
return handleDatabaseError(error, 'Error finding user');
|
|
29
|
+
return /** @type {AppointmentAuthFailure} */ (handleDatabaseError(error, 'Error finding user'));
|
|
14
30
|
}
|
|
15
31
|
if (!user || !user.accessToken) {
|
|
16
32
|
return {
|
|
@@ -22,14 +38,12 @@ async function resolveAuth({ platform, userId }) {
|
|
|
22
38
|
}
|
|
23
39
|
};
|
|
24
40
|
}
|
|
25
|
-
|
|
26
41
|
const platformModule = connectorRegistry.getConnector(platform);
|
|
27
42
|
const proxyId = user.platformAdditionalInfo?.proxyId;
|
|
28
43
|
let proxyConfig = null;
|
|
29
44
|
if (proxyId) {
|
|
30
45
|
proxyConfig = await Connector.getProxyConfig(proxyId);
|
|
31
46
|
}
|
|
32
|
-
|
|
33
47
|
const authType = await platformModule.getAuthType({ proxyId, proxyConfig });
|
|
34
48
|
let authHeader = '';
|
|
35
49
|
switch (authType) {
|
|
@@ -63,7 +77,6 @@ async function resolveAuth({ platform, userId }) {
|
|
|
63
77
|
default:
|
|
64
78
|
break;
|
|
65
79
|
}
|
|
66
|
-
|
|
67
80
|
return {
|
|
68
81
|
successful: true,
|
|
69
82
|
user,
|
|
@@ -72,12 +85,15 @@ async function resolveAuth({ platform, userId }) {
|
|
|
72
85
|
proxyConfig
|
|
73
86
|
};
|
|
74
87
|
}
|
|
75
|
-
|
|
88
|
+
/**
|
|
89
|
+
* @param {ListAppointmentsParams} params
|
|
90
|
+
* @returns {Promise<AppointmentHandlerResult>}
|
|
91
|
+
*/
|
|
76
92
|
async function listAppointments({ platform, userId, range, mineOnly, forceSync }) {
|
|
77
93
|
try {
|
|
78
94
|
const authResult = await resolveAuth({ platform, userId });
|
|
79
|
-
if (!authResult.successful)
|
|
80
|
-
|
|
95
|
+
if (!authResult.successful)
|
|
96
|
+
return authResult;
|
|
81
97
|
const result = await authResult.platformModule.listAppointments({
|
|
82
98
|
user: authResult.user,
|
|
83
99
|
authHeader: authResult.authHeader,
|
|
@@ -92,12 +108,15 @@ async function listAppointments({ platform, userId, range, mineOnly, forceSync }
|
|
|
92
108
|
return handleApiError(e, platform, 'listAppointments', { userId });
|
|
93
109
|
}
|
|
94
110
|
}
|
|
95
|
-
|
|
111
|
+
/**
|
|
112
|
+
* @param {AppointmentPayloadParams} params
|
|
113
|
+
* @returns {Promise<AppointmentHandlerResult>}
|
|
114
|
+
*/
|
|
96
115
|
async function createAppointment({ platform, userId, payload }) {
|
|
97
116
|
try {
|
|
98
117
|
const authResult = await resolveAuth({ platform, userId });
|
|
99
|
-
if (!authResult.successful)
|
|
100
|
-
|
|
118
|
+
if (!authResult.successful)
|
|
119
|
+
return authResult;
|
|
101
120
|
const result = await authResult.platformModule.createAppointment({
|
|
102
121
|
user: authResult.user,
|
|
103
122
|
authHeader: authResult.authHeader,
|
|
@@ -110,12 +129,15 @@ async function createAppointment({ platform, userId, payload }) {
|
|
|
110
129
|
return handleApiError(e, platform, 'createAppointment', { userId });
|
|
111
130
|
}
|
|
112
131
|
}
|
|
113
|
-
|
|
132
|
+
/**
|
|
133
|
+
* @param {AppointmentPatchParams} params
|
|
134
|
+
* @returns {Promise<AppointmentHandlerResult>}
|
|
135
|
+
*/
|
|
114
136
|
async function updateAppointment({ platform, userId, appointmentId, patchBody }) {
|
|
115
137
|
try {
|
|
116
138
|
const authResult = await resolveAuth({ platform, userId });
|
|
117
|
-
if (!authResult.successful)
|
|
118
|
-
|
|
139
|
+
if (!authResult.successful)
|
|
140
|
+
return authResult;
|
|
119
141
|
const result = await authResult.platformModule.updateAppointment({
|
|
120
142
|
user: authResult.user,
|
|
121
143
|
authHeader: authResult.authHeader,
|
|
@@ -129,12 +151,15 @@ async function updateAppointment({ platform, userId, appointmentId, patchBody })
|
|
|
129
151
|
return handleApiError(e, platform, 'updateAppointment', { userId, appointmentId });
|
|
130
152
|
}
|
|
131
153
|
}
|
|
132
|
-
|
|
154
|
+
/**
|
|
155
|
+
* @param {AppointmentRecordParams} params
|
|
156
|
+
* @returns {Promise<AppointmentHandlerResult>}
|
|
157
|
+
*/
|
|
133
158
|
async function refreshAppointment({ platform, userId, appointmentId }) {
|
|
134
159
|
try {
|
|
135
160
|
const authResult = await resolveAuth({ platform, userId });
|
|
136
|
-
if (!authResult.successful)
|
|
137
|
-
|
|
161
|
+
if (!authResult.successful)
|
|
162
|
+
return authResult;
|
|
138
163
|
const result = await authResult.platformModule.refreshAppointment({
|
|
139
164
|
user: authResult.user,
|
|
140
165
|
authHeader: authResult.authHeader,
|
|
@@ -147,12 +172,15 @@ async function refreshAppointment({ platform, userId, appointmentId }) {
|
|
|
147
172
|
return handleApiError(e, platform, 'refreshAppointment', { userId, appointmentId });
|
|
148
173
|
}
|
|
149
174
|
}
|
|
150
|
-
|
|
175
|
+
/**
|
|
176
|
+
* @param {AppointmentRecordParams} params
|
|
177
|
+
* @returns {Promise<AppointmentHandlerResult>}
|
|
178
|
+
*/
|
|
151
179
|
async function confirmAppointment({ platform, userId, appointmentId }) {
|
|
152
180
|
try {
|
|
153
181
|
const authResult = await resolveAuth({ platform, userId });
|
|
154
|
-
if (!authResult.successful)
|
|
155
|
-
|
|
182
|
+
if (!authResult.successful)
|
|
183
|
+
return authResult;
|
|
156
184
|
const result = await authResult.platformModule.confirmAppointment({
|
|
157
185
|
user: authResult.user,
|
|
158
186
|
authHeader: authResult.authHeader,
|
|
@@ -165,12 +193,15 @@ async function confirmAppointment({ platform, userId, appointmentId }) {
|
|
|
165
193
|
return handleApiError(e, platform, 'confirmAppointment', { userId, appointmentId });
|
|
166
194
|
}
|
|
167
195
|
}
|
|
168
|
-
|
|
196
|
+
/**
|
|
197
|
+
* @param {AppointmentRecordParams} params
|
|
198
|
+
* @returns {Promise<AppointmentHandlerResult>}
|
|
199
|
+
*/
|
|
169
200
|
async function cancelAppointment({ platform, userId, appointmentId }) {
|
|
170
201
|
try {
|
|
171
202
|
const authResult = await resolveAuth({ platform, userId });
|
|
172
|
-
if (!authResult.successful)
|
|
173
|
-
|
|
203
|
+
if (!authResult.successful)
|
|
204
|
+
return authResult;
|
|
174
205
|
const result = await authResult.platformModule.cancelAppointment({
|
|
175
206
|
user: authResult.user,
|
|
176
207
|
authHeader: authResult.authHeader,
|
|
@@ -183,11 +214,9 @@ async function cancelAppointment({ platform, userId, appointmentId }) {
|
|
|
183
214
|
return handleApiError(e, platform, 'cancelAppointment', { userId, appointmentId });
|
|
184
215
|
}
|
|
185
216
|
}
|
|
186
|
-
|
|
187
217
|
exports.listAppointments = listAppointments;
|
|
188
218
|
exports.createAppointment = createAppointment;
|
|
189
219
|
exports.updateAppointment = updateAppointment;
|
|
190
220
|
exports.refreshAppointment = refreshAppointment;
|
|
191
221
|
exports.confirmAppointment = confirmAppointment;
|
|
192
222
|
exports.cancelAppointment = cancelAppointment;
|
|
193
|
-
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** @typedef {import('../types').ApiKeyLoginParams} ApiKeyLoginParams */
|
|
2
|
+
/** @typedef {import('../types').AuthHandlerResult} AuthHandlerResult */
|
|
3
|
+
/** @typedef {import('../types').AuthValidationParams} AuthValidationParams */
|
|
4
|
+
/** @typedef {import('../types').AuthValidationResult} AuthValidationResult */
|
|
5
|
+
/** @typedef {import('../types').LicenseStatusParams} LicenseStatusParams */
|
|
6
|
+
/** @typedef {import('../types').OAuthCallbackParams} OAuthCallbackParams */
|
|
7
|
+
/** @typedef {import('../types').RingcentralOAuthCallbackParams} RingcentralOAuthCallbackParams */
|
|
8
|
+
/** @typedef {import('../types').SaveUserInfoParams} SaveUserInfoParams */
|
|
9
|
+
export {};
|