@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,7 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-check
|
|
3
|
+
/** @typedef {import('../types').ManagedOAuthAccountParams} ManagedOAuthAccountParams */
|
|
4
|
+
/** @typedef {import('../types').ManagedOAuthPendingParams} ManagedOAuthPendingParams */
|
|
5
|
+
/** @typedef {import('../types').ManagedOAuthRecord} ManagedOAuthRecord */
|
|
6
|
+
/** @typedef {import('../types').ManagedOAuthResolution} ManagedOAuthResolution */
|
|
7
|
+
/** @typedef {import('../types').ManagedOAuthState} ManagedOAuthState */
|
|
8
|
+
/** @typedef {import('../types').ManagedOAuthStateParams} ManagedOAuthStateParams */
|
|
9
|
+
/** @typedef {import('../types').ManagedOAuthStoredData} ManagedOAuthStoredData */
|
|
10
|
+
/** @typedef {import('../types').ManagedOAuthStoredValue} ManagedOAuthStoredValue */
|
|
11
|
+
/** @typedef {import('../types').ManagedOAuthValue} ManagedOAuthValue */
|
|
12
|
+
/** @typedef {import('../types').ManagedOAuthValues} ManagedOAuthValues */
|
|
13
|
+
/** @typedef {import('../types').ResetManagedOAuthResult} ResetManagedOAuthResult */
|
|
14
|
+
/** @typedef {import('../types').UpsertPendingManagedOAuthParams} UpsertPendingManagedOAuthParams */
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
const { AccountDataModel: AccountDataModelImport } = require('../models/accountDataModel');
|
|
17
|
+
const { CacheModel: CacheModelImport } = require('../models/cacheModel');
|
|
18
|
+
const AccountDataModel = /** @type {any} */ (AccountDataModelImport);
|
|
19
|
+
const CacheModel = /** @type {any} */ (CacheModelImport);
|
|
20
|
+
const { encode, decoded } = /** @type {{ encode(data: string): string, decoded(data: string): string }} */ (require('../lib/encode'));
|
|
5
21
|
const MANAGED_OAUTH_ACCOUNT_DATA_KEY = 'managed-oauth-account';
|
|
6
22
|
const MANAGED_OAUTH_CACHE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
7
23
|
const MANAGED_OAUTH_FIELDS = [
|
|
@@ -13,15 +29,24 @@ const MANAGED_OAUTH_FIELDS = [
|
|
|
13
29
|
'scopes',
|
|
14
30
|
'hostname'
|
|
15
31
|
];
|
|
16
|
-
|
|
32
|
+
/**
|
|
33
|
+
* @param {ManagedOAuthPendingParams} params
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
17
36
|
function getPendingManagedOAuthCacheId({ rcAccountId }) {
|
|
18
37
|
return `${rcAccountId}-${MANAGED_OAUTH_ACCOUNT_DATA_KEY}`;
|
|
19
38
|
}
|
|
20
|
-
|
|
39
|
+
/**
|
|
40
|
+
* @param {unknown} value
|
|
41
|
+
* @returns {boolean}
|
|
42
|
+
*/
|
|
21
43
|
function isFilled(value) {
|
|
22
44
|
return value !== undefined && value !== null && value !== '';
|
|
23
45
|
}
|
|
24
|
-
|
|
46
|
+
/**
|
|
47
|
+
* @param {ManagedOAuthValue} value
|
|
48
|
+
* @returns {ManagedOAuthStoredValue}
|
|
49
|
+
*/
|
|
25
50
|
function encryptStoredValue(value) {
|
|
26
51
|
return {
|
|
27
52
|
version: 1,
|
|
@@ -29,19 +54,26 @@ function encryptStoredValue(value) {
|
|
|
29
54
|
value: encode(JSON.stringify(value))
|
|
30
55
|
};
|
|
31
56
|
}
|
|
32
|
-
|
|
57
|
+
/**
|
|
58
|
+
* @param {ManagedOAuthStoredValue | ManagedOAuthValue} value
|
|
59
|
+
* @returns {ManagedOAuthValue | undefined}
|
|
60
|
+
*/
|
|
33
61
|
function decryptStoredValue(value) {
|
|
34
62
|
if (!value) {
|
|
35
63
|
return undefined;
|
|
36
64
|
}
|
|
37
|
-
|
|
38
|
-
|
|
65
|
+
const storedValue = /** @type {ManagedOAuthStoredValue} */ (value);
|
|
66
|
+
if (storedValue?.encrypted && storedValue?.value) {
|
|
67
|
+
return JSON.parse(decoded(storedValue.value));
|
|
39
68
|
}
|
|
40
69
|
return value;
|
|
41
70
|
}
|
|
42
|
-
|
|
71
|
+
/**
|
|
72
|
+
* @param {ManagedOAuthValues} [values]
|
|
73
|
+
* @returns {ManagedOAuthValues}
|
|
74
|
+
*/
|
|
43
75
|
function normalizeManagedOAuthValues(values = {}) {
|
|
44
|
-
const normalized = {};
|
|
76
|
+
const normalized = /** @type {ManagedOAuthValues} */ ({});
|
|
45
77
|
MANAGED_OAUTH_FIELDS.forEach(field => {
|
|
46
78
|
if (isFilled(values[field])) {
|
|
47
79
|
normalized[field] = values[field];
|
|
@@ -49,31 +81,43 @@ function normalizeManagedOAuthValues(values = {}) {
|
|
|
49
81
|
});
|
|
50
82
|
return normalized;
|
|
51
83
|
}
|
|
52
|
-
|
|
84
|
+
/**
|
|
85
|
+
* @param {ManagedOAuthValues} [values]
|
|
86
|
+
* @returns {ManagedOAuthStoredData}
|
|
87
|
+
*/
|
|
53
88
|
function buildStoredData(values = {}) {
|
|
54
89
|
const normalized = normalizeManagedOAuthValues(values);
|
|
55
|
-
const fields = {};
|
|
90
|
+
const fields = /** @type {Record<string, ManagedOAuthStoredValue>} */ ({});
|
|
56
91
|
Object.keys(normalized).forEach(key => {
|
|
57
92
|
fields[key] = encryptStoredValue(normalized[key]);
|
|
58
93
|
});
|
|
59
94
|
return { fields };
|
|
60
95
|
}
|
|
61
|
-
|
|
96
|
+
/**
|
|
97
|
+
* @param {ManagedOAuthStoredData} [data]
|
|
98
|
+
* @returns {ManagedOAuthValues}
|
|
99
|
+
*/
|
|
62
100
|
function decryptStoredData(data = {}) {
|
|
63
101
|
const fields = data?.fields ?? {};
|
|
64
|
-
const values = {};
|
|
102
|
+
const values = /** @type {ManagedOAuthValues} */ ({});
|
|
65
103
|
Object.keys(fields).forEach(key => {
|
|
66
104
|
values[key] = decryptStoredValue(fields[key]);
|
|
67
105
|
});
|
|
68
106
|
return values;
|
|
69
107
|
}
|
|
70
|
-
|
|
108
|
+
/**
|
|
109
|
+
* @param {ManagedOAuthValues} [values]
|
|
110
|
+
* @returns {ManagedOAuthValues}
|
|
111
|
+
*/
|
|
71
112
|
function removeSecret(values = {}) {
|
|
72
113
|
const sanitized = { ...values };
|
|
73
114
|
delete sanitized.clientSecret;
|
|
74
115
|
return sanitized;
|
|
75
116
|
}
|
|
76
|
-
|
|
117
|
+
/**
|
|
118
|
+
* @param {ManagedOAuthAccountParams} params
|
|
119
|
+
* @returns {Promise<ManagedOAuthRecord | null>}
|
|
120
|
+
*/
|
|
77
121
|
async function getAccountManagedOAuthRecord({ rcAccountId, platform }) {
|
|
78
122
|
if (!rcAccountId || !platform) {
|
|
79
123
|
return null;
|
|
@@ -86,7 +130,10 @@ async function getAccountManagedOAuthRecord({ rcAccountId, platform }) {
|
|
|
86
130
|
}
|
|
87
131
|
});
|
|
88
132
|
}
|
|
89
|
-
|
|
133
|
+
/**
|
|
134
|
+
* @param {ManagedOAuthPendingParams} params
|
|
135
|
+
* @returns {Promise<ManagedOAuthRecord | null>}
|
|
136
|
+
*/
|
|
90
137
|
async function getPendingManagedOAuthRecord({ rcAccountId }) {
|
|
91
138
|
if (!rcAccountId) {
|
|
92
139
|
return null;
|
|
@@ -101,17 +148,26 @@ async function getPendingManagedOAuthRecord({ rcAccountId }) {
|
|
|
101
148
|
}
|
|
102
149
|
return record;
|
|
103
150
|
}
|
|
104
|
-
|
|
151
|
+
/**
|
|
152
|
+
* @param {ManagedOAuthAccountParams} params
|
|
153
|
+
* @returns {Promise<ManagedOAuthValues>}
|
|
154
|
+
*/
|
|
105
155
|
async function getAccountManagedOAuthValues({ rcAccountId, platform }) {
|
|
106
156
|
const record = await getAccountManagedOAuthRecord({ rcAccountId, platform });
|
|
107
157
|
return decryptStoredData(record?.data);
|
|
108
158
|
}
|
|
109
|
-
|
|
159
|
+
/**
|
|
160
|
+
* @param {ManagedOAuthPendingParams} params
|
|
161
|
+
* @returns {Promise<ManagedOAuthValues>}
|
|
162
|
+
*/
|
|
110
163
|
async function getPendingManagedOAuthValues({ rcAccountId }) {
|
|
111
164
|
const record = await getPendingManagedOAuthRecord({ rcAccountId });
|
|
112
165
|
return decryptStoredData(record?.data);
|
|
113
166
|
}
|
|
114
|
-
|
|
167
|
+
/**
|
|
168
|
+
* @param {ManagedOAuthStateParams} params
|
|
169
|
+
* @returns {Promise<ManagedOAuthState>}
|
|
170
|
+
*/
|
|
115
171
|
async function getManagedOAuthState({ rcAccountId, platform, isAdmin }) {
|
|
116
172
|
const accountValues = await getAccountManagedOAuthValues({ rcAccountId, platform });
|
|
117
173
|
const hasAccountOAuth = Object.keys(accountValues).length > 0;
|
|
@@ -119,7 +175,6 @@ async function getManagedOAuthState({ rcAccountId, platform, isAdmin }) {
|
|
|
119
175
|
? await getPendingManagedOAuthValues({ rcAccountId })
|
|
120
176
|
: {};
|
|
121
177
|
const hasPendingOAuth = Object.keys(pendingValues).length > 0;
|
|
122
|
-
|
|
123
178
|
return {
|
|
124
179
|
isAdmin: !!isAdmin,
|
|
125
180
|
hasAccountOAuth,
|
|
@@ -128,7 +183,10 @@ async function getManagedOAuthState({ rcAccountId, platform, isAdmin }) {
|
|
|
128
183
|
...(isAdmin && hasPendingOAuth ? { pendingValues } : {})
|
|
129
184
|
};
|
|
130
185
|
}
|
|
131
|
-
|
|
186
|
+
/**
|
|
187
|
+
* @param {UpsertPendingManagedOAuthParams} params
|
|
188
|
+
* @returns {Promise<ManagedOAuthRecord>}
|
|
189
|
+
*/
|
|
132
190
|
async function upsertPendingManagedOAuth({ rcAccountId, values = {} }) {
|
|
133
191
|
if (!rcAccountId) {
|
|
134
192
|
throw new Error('rcAccountId is required');
|
|
@@ -156,7 +214,10 @@ async function upsertPendingManagedOAuth({ rcAccountId, values = {} }) {
|
|
|
156
214
|
expiry
|
|
157
215
|
});
|
|
158
216
|
}
|
|
159
|
-
|
|
217
|
+
/**
|
|
218
|
+
* @param {ManagedOAuthAccountParams} params
|
|
219
|
+
* @returns {Promise<boolean>}
|
|
220
|
+
*/
|
|
160
221
|
async function migratePendingManagedOAuth({ rcAccountId, platform }) {
|
|
161
222
|
const pending = await getPendingManagedOAuthRecord({ rcAccountId });
|
|
162
223
|
if (!pending) {
|
|
@@ -178,7 +239,10 @@ async function migratePendingManagedOAuth({ rcAccountId, platform }) {
|
|
|
178
239
|
await pending.destroy();
|
|
179
240
|
return true;
|
|
180
241
|
}
|
|
181
|
-
|
|
242
|
+
/**
|
|
243
|
+
* @param {ManagedOAuthAccountParams} params
|
|
244
|
+
* @returns {Promise<ManagedOAuthResolution>}
|
|
245
|
+
*/
|
|
182
246
|
async function resolveManagedOAuthInfo({ rcAccountId, platform }) {
|
|
183
247
|
const accountValues = await getAccountManagedOAuthValues({ rcAccountId, platform });
|
|
184
248
|
if (Object.keys(accountValues).length > 0) {
|
|
@@ -199,7 +263,10 @@ async function resolveManagedOAuthInfo({ rcAccountId, platform }) {
|
|
|
199
263
|
oauthInfo: null
|
|
200
264
|
};
|
|
201
265
|
}
|
|
202
|
-
|
|
266
|
+
/**
|
|
267
|
+
* @param {ManagedOAuthPendingParams} params
|
|
268
|
+
* @returns {Promise<number>}
|
|
269
|
+
*/
|
|
203
270
|
async function clearPendingManagedOAuth({ rcAccountId }) {
|
|
204
271
|
if (!rcAccountId) {
|
|
205
272
|
return 0;
|
|
@@ -210,7 +277,10 @@ async function clearPendingManagedOAuth({ rcAccountId }) {
|
|
|
210
277
|
}
|
|
211
278
|
});
|
|
212
279
|
}
|
|
213
|
-
|
|
280
|
+
/**
|
|
281
|
+
* @param {ManagedOAuthAccountParams} params
|
|
282
|
+
* @returns {Promise<number>}
|
|
283
|
+
*/
|
|
214
284
|
async function clearAccountManagedOAuth({ rcAccountId, platform }) {
|
|
215
285
|
if (!rcAccountId || !platform) {
|
|
216
286
|
return 0;
|
|
@@ -223,7 +293,10 @@ async function clearAccountManagedOAuth({ rcAccountId, platform }) {
|
|
|
223
293
|
}
|
|
224
294
|
});
|
|
225
295
|
}
|
|
226
|
-
|
|
296
|
+
/**
|
|
297
|
+
* @param {ManagedOAuthAccountParams} params
|
|
298
|
+
* @returns {Promise<ResetManagedOAuthResult>}
|
|
299
|
+
*/
|
|
227
300
|
async function resetManagedOAuth({ rcAccountId, platform }) {
|
|
228
301
|
const deletedAccountCount = await clearAccountManagedOAuth({ rcAccountId, platform });
|
|
229
302
|
const deletedPendingCount = await clearPendingManagedOAuth({ rcAccountId });
|
|
@@ -232,7 +305,6 @@ async function resetManagedOAuth({ rcAccountId, platform }) {
|
|
|
232
305
|
deletedPendingCount
|
|
233
306
|
};
|
|
234
307
|
}
|
|
235
|
-
|
|
236
308
|
exports.MANAGED_OAUTH_ACCOUNT_DATA_KEY = MANAGED_OAUTH_ACCOUNT_DATA_KEY;
|
|
237
309
|
exports.MANAGED_OAUTH_FIELDS = MANAGED_OAUTH_FIELDS;
|
|
238
310
|
exports.getManagedOAuthState = getManagedOAuthState;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,11 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-check
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
4
|
const { CacheModel } = require('../models/cacheModel');
|
|
2
5
|
const { Op } = require('sequelize');
|
|
3
|
-
const axios = require('axios');
|
|
4
|
-
const { AccountDataModel } = require('../models/accountDataModel');
|
|
6
|
+
const axios = /** @type {any} */ (require('axios'));
|
|
7
|
+
const { AccountDataModel: AccountDataModelImport } = require('../models/accountDataModel');
|
|
8
|
+
const AccountDataModel = /** @type {any} */ (AccountDataModelImport);
|
|
5
9
|
const logger = require('../lib/logger');
|
|
6
|
-
|
|
10
|
+
/** @typedef {import('../types').InstalledPlugin} InstalledPlugin */
|
|
11
|
+
/** @typedef {import('../types').JsonObject} JsonObject */
|
|
12
|
+
/** @typedef {import('../types').PluginAccess} PluginAccess */
|
|
13
|
+
/** @typedef {import('../types').PluginLicenseStatus} PluginLicenseStatus */
|
|
14
|
+
/** @typedef {import('../types').ResolvePluginManifestResult} ResolvePluginManifestResult */
|
|
15
|
+
/** @typedef {import('../types').RegisterPluginAccountResult} RegisterPluginAccountResult */
|
|
16
|
+
/** @typedef {import('../types').UserSettings} UserSettings */
|
|
7
17
|
const PUBLIC_MANIFEST_BASE = 'https://appconnect.labs.ringcentral.com/public-api/connectors';
|
|
8
|
-
|
|
18
|
+
/**
|
|
19
|
+
* @param {{ rcAccountId: string | number }} params
|
|
20
|
+
* @returns {Promise<InstalledPlugin[]>}
|
|
21
|
+
*/
|
|
9
22
|
async function getPluginsFromRcAccountId({ rcAccountId }) {
|
|
10
23
|
const accountData = await AccountDataModel.findAll({
|
|
11
24
|
where: {
|
|
@@ -19,18 +32,25 @@ async function getPluginsFromRcAccountId({ rcAccountId }) {
|
|
|
19
32
|
}));
|
|
20
33
|
return workingPlugins;
|
|
21
34
|
}
|
|
22
|
-
|
|
35
|
+
/**
|
|
36
|
+
* @param {{ userSettings?: UserSettings | null, pluginId: string }} params
|
|
37
|
+
* @returns {JsonObject | null}
|
|
38
|
+
*/
|
|
23
39
|
function getPluginConfigFromUserSettings({ userSettings, pluginId }) {
|
|
24
40
|
if (!userSettings) {
|
|
25
41
|
return null;
|
|
26
42
|
}
|
|
27
43
|
const targetPluginSettings = userSettings[`plugin_${pluginId}`];
|
|
28
|
-
|
|
44
|
+
const targetPluginSettingsValue = /** @type {{ config?: JsonObject } | undefined} */ (targetPluginSettings?.value);
|
|
45
|
+
if (!targetPluginSettingsValue?.config) {
|
|
29
46
|
return null;
|
|
30
47
|
}
|
|
31
|
-
return
|
|
48
|
+
return targetPluginSettingsValue.config;
|
|
32
49
|
}
|
|
33
|
-
|
|
50
|
+
/**
|
|
51
|
+
* @param {{ rcAccountId: string | number, pluginId: string }} params
|
|
52
|
+
* @returns {Promise<PluginLicenseStatus | null>}
|
|
53
|
+
*/
|
|
34
54
|
async function getPluginLicenseStatus({ rcAccountId, pluginId }) {
|
|
35
55
|
const accountData = await AccountDataModel.findOne({
|
|
36
56
|
where: {
|
|
@@ -57,25 +77,32 @@ async function getPluginLicenseStatus({ rcAccountId, pluginId }) {
|
|
|
57
77
|
}
|
|
58
78
|
return licenseStatus;
|
|
59
79
|
}
|
|
60
|
-
|
|
80
|
+
/**
|
|
81
|
+
* @param {{ headers?: Record<string, string> | null }} params
|
|
82
|
+
* @returns {string | null}
|
|
83
|
+
*/
|
|
61
84
|
function getRefreshedJwtTokenFromHeaders({ headers }) {
|
|
62
85
|
if (!headers) {
|
|
63
86
|
return null;
|
|
64
87
|
}
|
|
65
88
|
return headers['x-refreshed-jwt-token'] || headers['X-Refreshed-Jwt-Token'] || null;
|
|
66
89
|
}
|
|
67
|
-
|
|
90
|
+
/**
|
|
91
|
+
* @param {{ pluginId: string, pluginAccess?: PluginAccess, ownerRcAccountId?: string | number, pluginName?: string }} params
|
|
92
|
+
* @returns {Promise<ResolvePluginManifestResult>}
|
|
93
|
+
*/
|
|
68
94
|
async function resolvePluginManifest({ pluginId, pluginAccess, ownerRcAccountId, pluginName }) {
|
|
69
95
|
const manifestFetchers = [];
|
|
70
96
|
if (pluginAccess === 'public') {
|
|
71
97
|
manifestFetchers.push(`${PUBLIC_MANIFEST_BASE}/${pluginId}/manifest?type=plugin`);
|
|
72
|
-
}
|
|
98
|
+
}
|
|
99
|
+
else if (pluginAccess === 'private' || pluginAccess === 'shared') {
|
|
73
100
|
manifestFetchers.push(`${PUBLIC_MANIFEST_BASE}/${pluginId}/manifest?access=internal&type=plugin&accountId=${ownerRcAccountId}`);
|
|
74
|
-
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
75
103
|
manifestFetchers.push(`${PUBLIC_MANIFEST_BASE}/${pluginId}/manifest?type=plugin`);
|
|
76
104
|
manifestFetchers.push(`${PUBLIC_MANIFEST_BASE}/${pluginId}/manifest?access=internal&type=plugin&accountId=${ownerRcAccountId}`);
|
|
77
105
|
}
|
|
78
|
-
|
|
79
106
|
let pluginData = null;
|
|
80
107
|
let lastError = null;
|
|
81
108
|
for (const url of manifestFetchers) {
|
|
@@ -83,27 +110,28 @@ async function resolvePluginManifest({ pluginId, pluginAccess, ownerRcAccountId,
|
|
|
83
110
|
const pluginDataResponse = await axios.get(url);
|
|
84
111
|
pluginData = pluginDataResponse.data;
|
|
85
112
|
break;
|
|
86
|
-
}
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
87
115
|
lastError = error;
|
|
88
116
|
}
|
|
89
117
|
}
|
|
90
|
-
|
|
91
118
|
if (!pluginData) {
|
|
92
119
|
throw lastError || new Error(`Unable to resolve manifest for plugin ${pluginId}`);
|
|
93
120
|
}
|
|
94
|
-
|
|
95
121
|
const platformKey = pluginName || Object.keys(pluginData.platforms || {})[0];
|
|
96
122
|
if (!platformKey || !pluginData.platforms?.[platformKey]) {
|
|
97
123
|
throw new Error(`Unable to resolve platform manifest for plugin ${pluginId}`);
|
|
98
124
|
}
|
|
99
|
-
|
|
100
125
|
return {
|
|
101
126
|
pluginData,
|
|
102
127
|
pluginManifest: pluginData.platforms[platformKey],
|
|
103
128
|
platformKey,
|
|
104
129
|
};
|
|
105
130
|
}
|
|
106
|
-
|
|
131
|
+
/**
|
|
132
|
+
* @param {{ rcAccountId: string | number, pluginId: string, jwtToken: string, pluginData?: JsonObject }} params
|
|
133
|
+
* @returns {Promise<void>}
|
|
134
|
+
*/
|
|
107
135
|
async function persistPluginData({ rcAccountId, pluginId, jwtToken, pluginData = {} }) {
|
|
108
136
|
try {
|
|
109
137
|
const accountData = await AccountDataModel.findOne({
|
|
@@ -122,7 +150,8 @@ async function persistPluginData({ rcAccountId, pluginId, jwtToken, pluginData =
|
|
|
122
150
|
...pluginData,
|
|
123
151
|
},
|
|
124
152
|
});
|
|
125
|
-
}
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
126
155
|
await accountData.update({
|
|
127
156
|
data: {
|
|
128
157
|
jwtToken,
|
|
@@ -130,7 +159,8 @@ async function persistPluginData({ rcAccountId, pluginId, jwtToken, pluginData =
|
|
|
130
159
|
},
|
|
131
160
|
});
|
|
132
161
|
}
|
|
133
|
-
}
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
134
164
|
logger.error('Failed to persist plugin data', {
|
|
135
165
|
pluginId,
|
|
136
166
|
rcAccountId,
|
|
@@ -138,13 +168,15 @@ async function persistPluginData({ rcAccountId, pluginId, jwtToken, pluginData =
|
|
|
138
168
|
});
|
|
139
169
|
}
|
|
140
170
|
}
|
|
141
|
-
|
|
171
|
+
/**
|
|
172
|
+
* @param {{ pluginId: string, rcAccessToken: string, rcAccountId: string | number, pluginAccess?: PluginAccess, pluginName?: string, ownerRcAccountId?: string | number }} params
|
|
173
|
+
* @returns {Promise<RegisterPluginAccountResult>}
|
|
174
|
+
*/
|
|
142
175
|
async function registerPluginAccount({ pluginId, rcAccessToken, rcAccountId, pluginAccess, pluginName, ownerRcAccountId }) {
|
|
143
176
|
const { pluginManifest } = await resolvePluginManifest({ pluginId, pluginAccess, ownerRcAccountId, pluginName });
|
|
144
177
|
if (!pluginManifest?.endpointUrl) {
|
|
145
178
|
throw new Error(`Plugin endpoint URL not found for ${pluginId}`);
|
|
146
179
|
}
|
|
147
|
-
|
|
148
180
|
const registerUrl = pluginManifest.userRegisterEndpointUrl;
|
|
149
181
|
const registerResponse = await axios.post(registerUrl, {
|
|
150
182
|
rcAccessToken,
|
|
@@ -154,21 +186,22 @@ async function registerPluginAccount({ pluginId, rcAccessToken, rcAccountId, plu
|
|
|
154
186
|
if (!pluginJwtToken) {
|
|
155
187
|
throw new Error('Plugin register API did not return jwtToken');
|
|
156
188
|
}
|
|
157
|
-
|
|
158
189
|
await persistPluginData({
|
|
159
190
|
rcAccountId: rcAccountId?.toString(),
|
|
160
191
|
pluginId,
|
|
161
192
|
jwtToken: pluginJwtToken,
|
|
162
193
|
pluginData: pluginManifest,
|
|
163
194
|
});
|
|
164
|
-
|
|
165
195
|
return {
|
|
166
196
|
successful: true,
|
|
167
197
|
registerUrl,
|
|
168
198
|
jwtToken: pluginJwtToken,
|
|
169
199
|
};
|
|
170
200
|
}
|
|
171
|
-
|
|
201
|
+
/**
|
|
202
|
+
* @param {{ pluginId: string, rcAccountId: string | number }} params
|
|
203
|
+
* @returns {Promise<void>}
|
|
204
|
+
*/
|
|
172
205
|
async function unregisterPluginAccount({ pluginId, rcAccountId }) {
|
|
173
206
|
const accountData = await AccountDataModel.findOne({
|
|
174
207
|
where: {
|
|
@@ -181,7 +214,6 @@ async function unregisterPluginAccount({ pluginId, rcAccountId }) {
|
|
|
181
214
|
await accountData.destroy();
|
|
182
215
|
}
|
|
183
216
|
}
|
|
184
|
-
|
|
185
217
|
exports.getPluginsFromRcAccountId = getPluginsFromRcAccountId;
|
|
186
218
|
exports.getPluginConfigFromUserSettings = getPluginConfigFromUserSettings;
|
|
187
219
|
exports.getPluginLicenseStatus = getPluginLicenseStatus;
|
|
@@ -189,4 +221,4 @@ exports.getRefreshedJwtTokenFromHeaders = getRefreshedJwtTokenFromHeaders;
|
|
|
189
221
|
exports.resolvePluginManifest = resolvePluginManifest;
|
|
190
222
|
exports.persistPluginData = persistPluginData;
|
|
191
223
|
exports.registerPluginAccount = registerPluginAccount;
|
|
192
|
-
exports.unregisterPluginAccount = unregisterPluginAccount;
|
|
224
|
+
exports.unregisterPluginAccount = unregisterPluginAccount;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,14 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-check
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const axios = /** @type {any} */ (require('axios'));
|
|
5
|
+
const { AdminConfigModel: AdminConfigModelImport } = require('../models/adminConfigModel');
|
|
3
6
|
const { getHashValue } = require('../lib/util');
|
|
4
|
-
const connectorRegistry = require('../connector/registry');
|
|
7
|
+
const connectorRegistry = /** @type {any} */ (require('../connector/registry'));
|
|
5
8
|
const logger = require('../lib/logger');
|
|
6
9
|
const { handleDatabaseError } = require('../lib/errorHandler');
|
|
7
|
-
const { UserModel } = require('../models/userModel');
|
|
10
|
+
const { UserModel: UserModelImport } = require('../models/userModel');
|
|
8
11
|
const { handleApiError } = require('../lib/errorHandler');
|
|
9
|
-
const oauth = require('../lib/oauth');
|
|
10
|
-
const { Connector } = require('../models/dynamo/connectorSchema');
|
|
11
|
-
|
|
12
|
+
const oauth = /** @type {any} */ (require('../lib/oauth'));
|
|
13
|
+
const { Connector: ConnectorImport } = require('../models/dynamo/connectorSchema');
|
|
14
|
+
const AdminConfigModel = /** @type {any} */ (AdminConfigModelImport);
|
|
15
|
+
const UserModel = /** @type {any} */ (UserModelImport);
|
|
16
|
+
const Connector = /** @type {any} */ (ConnectorImport);
|
|
17
|
+
/** @typedef {import('../types').GetUserSettingsParams} GetUserSettingsParams */
|
|
18
|
+
/** @typedef {import('../types').HandlerResult} HandlerResult */
|
|
19
|
+
/** @typedef {import('../types').RefreshUserInfoParams} RefreshUserInfoParams */
|
|
20
|
+
/** @typedef {import('../types').UpdateUserSettingsParams} UpdateUserSettingsParams */
|
|
21
|
+
/** @typedef {import('../types').UserSettings} UserSettings */
|
|
22
|
+
/** @typedef {import('../types').UserSettingsByAdminParams} UserSettingsByAdminParams */
|
|
23
|
+
/** @typedef {import('../types').UserSettingsByAdminResult} UserSettingsByAdminResult */
|
|
24
|
+
/**
|
|
25
|
+
* @param {RefreshUserInfoParams} params
|
|
26
|
+
* @returns {Promise<HandlerResult>}
|
|
27
|
+
*/
|
|
12
28
|
async function refreshUserInfo({ platform, userId, tracer }) {
|
|
13
29
|
tracer?.trace('refreshUserInfo:start', { platform, userId });
|
|
14
30
|
try {
|
|
@@ -19,7 +35,6 @@ async function refreshUserInfo({ platform, userId, tracer }) {
|
|
|
19
35
|
}
|
|
20
36
|
});
|
|
21
37
|
tracer?.trace('refreshUserInfo:userFound', { user });
|
|
22
|
-
|
|
23
38
|
if (!user || !user.accessToken) {
|
|
24
39
|
tracer?.trace('refreshUserInfo:noUser', { userId });
|
|
25
40
|
return {
|
|
@@ -31,18 +46,15 @@ async function refreshUserInfo({ platform, userId, tracer }) {
|
|
|
31
46
|
}
|
|
32
47
|
};
|
|
33
48
|
}
|
|
34
|
-
|
|
35
49
|
const proxyId = user.platformAdditionalInfo?.proxyId;
|
|
36
50
|
let proxyConfig = null;
|
|
37
51
|
if (proxyId) {
|
|
38
52
|
proxyConfig = await Connector.getProxyConfig(proxyId);
|
|
39
53
|
tracer?.trace('refreshUserInfo:proxyConfig', { proxyConfig });
|
|
40
54
|
}
|
|
41
|
-
|
|
42
55
|
const platformModule = connectorRegistry.getConnector(platform);
|
|
43
56
|
const authType = await platformModule.getAuthType({ proxyId, proxyConfig });
|
|
44
57
|
tracer?.trace('refreshUserInfo:authType', { authType });
|
|
45
|
-
|
|
46
58
|
let authHeader = '';
|
|
47
59
|
switch (authType) {
|
|
48
60
|
case 'oauth':
|
|
@@ -57,7 +69,7 @@ async function refreshUserInfo({ platform, userId, tracer }) {
|
|
|
57
69
|
ttl: 5000
|
|
58
70
|
},
|
|
59
71
|
isRevokeUserSession: true
|
|
60
|
-
}
|
|
72
|
+
};
|
|
61
73
|
}
|
|
62
74
|
authHeader = `Bearer ${user.accessToken}`;
|
|
63
75
|
tracer?.trace('refreshUserInfo:oauthAuth', { authHeader });
|
|
@@ -68,7 +80,6 @@ async function refreshUserInfo({ platform, userId, tracer }) {
|
|
|
68
80
|
tracer?.trace('refreshUserInfo:apiKeyAuth', {});
|
|
69
81
|
break;
|
|
70
82
|
}
|
|
71
|
-
|
|
72
83
|
const { successful, returnMessage } = await platformModule.refreshUserInfo({ user, authHeader, proxyConfig });
|
|
73
84
|
tracer?.trace('refreshUserInfo:platformRefreshResult', { successful, returnMessage });
|
|
74
85
|
return {
|
|
@@ -81,20 +92,21 @@ async function refreshUserInfo({ platform, userId, tracer }) {
|
|
|
81
92
|
return handleApiError(e, platform, 'refreshUserInfo', { userId });
|
|
82
93
|
}
|
|
83
94
|
}
|
|
84
|
-
|
|
95
|
+
/**
|
|
96
|
+
* @param {UserSettingsByAdminParams} params
|
|
97
|
+
* @returns {Promise<UserSettingsByAdminResult>}
|
|
98
|
+
*/
|
|
85
99
|
async function getUserSettingsByAdmin({ rcAccessToken, rcAccountId }) {
|
|
86
100
|
let hashedRcAccountId = null;
|
|
87
101
|
if (rcAccountId) {
|
|
88
102
|
hashedRcAccountId = rcAccountId;
|
|
89
103
|
}
|
|
90
104
|
else {
|
|
91
|
-
const rcExtensionResponse = await axios.get(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
},
|
|
97
|
-
});
|
|
105
|
+
const rcExtensionResponse = await axios.get('https://platform.ringcentral.com/restapi/v1.0/account/~/extension/~', {
|
|
106
|
+
headers: {
|
|
107
|
+
Authorization: `Bearer ${rcAccessToken}`,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
98
110
|
hashedRcAccountId = getHashValue(rcExtensionResponse.data.account.id, process.env.HASH_KEY);
|
|
99
111
|
}
|
|
100
112
|
const adminConfig = await AdminConfigModel.findByPk(hashedRcAccountId);
|
|
@@ -102,21 +114,25 @@ async function getUserSettingsByAdmin({ rcAccessToken, rcAccountId }) {
|
|
|
102
114
|
userSettings: adminConfig?.userSettings
|
|
103
115
|
};
|
|
104
116
|
}
|
|
105
|
-
|
|
117
|
+
/**
|
|
118
|
+
* @param {GetUserSettingsParams} params
|
|
119
|
+
* @returns {Promise<UserSettings>}
|
|
120
|
+
*/
|
|
106
121
|
async function getUserSettings({ user, rcAccessToken, rcAccountId }) {
|
|
122
|
+
/** @type {any} */
|
|
107
123
|
let userSettingsByAdmin = [];
|
|
108
124
|
if (rcAccessToken || rcAccountId) {
|
|
109
125
|
try {
|
|
110
126
|
userSettingsByAdmin = await getUserSettingsByAdmin({ rcAccessToken, rcAccountId });
|
|
111
127
|
}
|
|
112
128
|
catch (e) {
|
|
113
|
-
logger.error('Error getting user settings by admin', { stack: e.stack });
|
|
129
|
+
logger.error('Error getting user settings by admin', { stack: /** @type {any} */ (e).stack });
|
|
114
130
|
userSettingsByAdmin = [];
|
|
115
131
|
}
|
|
116
132
|
}
|
|
117
|
-
|
|
118
133
|
// For non-readonly admin settings, user use its own setting
|
|
119
134
|
let userSettings = await user?.userSettings;
|
|
135
|
+
/** @type {any} */
|
|
120
136
|
let result = {};
|
|
121
137
|
if (!userSettingsByAdmin?.userSettings) {
|
|
122
138
|
result = userSettings;
|
|
@@ -177,7 +193,10 @@ async function getUserSettings({ user, rcAccessToken, rcAccountId }) {
|
|
|
177
193
|
}
|
|
178
194
|
return result;
|
|
179
195
|
}
|
|
180
|
-
|
|
196
|
+
/**
|
|
197
|
+
* @param {UpdateUserSettingsParams} params
|
|
198
|
+
* @returns {Promise<HandlerResult | { userSettings?: UserSettings }>}
|
|
199
|
+
*/
|
|
181
200
|
async function updateUserSettings({ user, userSettings, settingKeysToRemove, platformName }) {
|
|
182
201
|
const keys = Object.keys(userSettings || {});
|
|
183
202
|
let updatedSettings = {
|
|
@@ -223,8 +242,7 @@ async function updateUserSettings({ user, userSettings, settingKeysToRemove, pla
|
|
|
223
242
|
userSettings: user.userSettings
|
|
224
243
|
};
|
|
225
244
|
}
|
|
226
|
-
|
|
227
245
|
exports.refreshUserInfo = refreshUserInfo;
|
|
228
246
|
exports.getUserSettingsByAdmin = getUserSettingsByAdmin;
|
|
229
247
|
exports.getUserSettings = getUserSettings;
|
|
230
|
-
exports.updateUserSettings = updateUserSettings;
|
|
248
|
+
exports.updateUserSettings = updateUserSettings;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|