dce-expresskit 4.1.0 → 4.2.1
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/lib/helpers/dataSigner.js +7 -5
- package/lib/helpers/dataSigner.js.map +1 -1
- package/lib/helpers/genRouteHandler.d.ts +1 -1
- package/lib/helpers/genRouteHandler.js +61 -24
- package/lib/helpers/genRouteHandler.js.map +1 -1
- package/lib/helpers/initExpressKitCollections.d.ts +33 -0
- package/lib/helpers/initExpressKitCollections.js +180 -0
- package/lib/helpers/initExpressKitCollections.js.map +1 -0
- package/lib/helpers/initServer.d.ts +0 -33
- package/lib/helpers/initServer.js +31 -63
- package/lib/helpers/initServer.js.map +1 -1
- package/lib/index.d.ts +2 -3
- package/lib/index.js +3 -5
- package/lib/index.js.map +1 -1
- package/lib/types/ExpressKitErrorCode.d.ts +2 -1
- package/lib/types/ExpressKitErrorCode.js +1 -0
- package/lib/types/ExpressKitErrorCode.js.map +1 -1
- package/lib/types/LogReviewerAdmin.d.ts +10 -0
- package/lib/types/LogReviewerAdmin.js +3 -0
- package/lib/types/LogReviewerAdmin.js.map +1 -0
- package/lib/types/SelectAdmin.d.ts +10 -0
- package/lib/types/SelectAdmin.js +3 -0
- package/lib/types/SelectAdmin.js.map +1 -0
- package/package.json +2 -2
- package/src/helpers/dataSigner.ts +2 -2
- package/src/helpers/genRouteHandler.ts +46 -8
- package/src/helpers/initExpressKitCollections.ts +144 -0
- package/src/helpers/initServer.ts +38 -67
- package/src/index.ts +2 -4
- package/src/types/ExpressKitErrorCode.ts +1 -0
- package/src/types/LogReviewerAdmin.ts +14 -0
- package/src/types/SelectAdmin.ts +14 -0
- package/src/helpers/initCrossServerCredentialCollection.ts +0 -19
- package/src/helpers/initLogCollection.ts +0 -30
|
@@ -50,7 +50,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.internalGetCrossServerCredentialCollection = exports.internalGetLogCollection = void 0;
|
|
54
53
|
// Import dce-reactkit
|
|
55
54
|
var dce_reactkit_1 = require("dce-reactkit");
|
|
56
55
|
// Import shared helpers
|
|
@@ -58,33 +57,8 @@ var genRouteHandler_1 = __importDefault(require("./genRouteHandler"));
|
|
|
58
57
|
var getLogReviewerLogs_1 = __importDefault(require("./getLogReviewerLogs"));
|
|
59
58
|
// Import shared types
|
|
60
59
|
var ExpressKitErrorCode_1 = __importDefault(require("../types/ExpressKitErrorCode"));
|
|
61
|
-
//
|
|
62
|
-
var
|
|
63
|
-
// Stored copy of dce-mango cross-server credential collection
|
|
64
|
-
var _crossServerCredentialCollection;
|
|
65
|
-
/*------------------------------------------------------------------------*/
|
|
66
|
-
/* Helpers */
|
|
67
|
-
/*------------------------------------------------------------------------*/
|
|
68
|
-
/**
|
|
69
|
-
* Get log collection
|
|
70
|
-
* @author Gabe Abrams
|
|
71
|
-
* @returns log collection if one was included during launch or null if we don't
|
|
72
|
-
* have a log collection (yet)
|
|
73
|
-
*/
|
|
74
|
-
var internalGetLogCollection = function () {
|
|
75
|
-
return _logCollection !== null && _logCollection !== void 0 ? _logCollection : null;
|
|
76
|
-
};
|
|
77
|
-
exports.internalGetLogCollection = internalGetLogCollection;
|
|
78
|
-
/**
|
|
79
|
-
* Get cross-server credential collection
|
|
80
|
-
* @author Gabe Abrams
|
|
81
|
-
* @return cross-server credential collection if one was included during launch or null
|
|
82
|
-
* if we don't have a cross-server credential collection (yet)
|
|
83
|
-
*/
|
|
84
|
-
var internalGetCrossServerCredentialCollection = function () {
|
|
85
|
-
return _crossServerCredentialCollection !== null && _crossServerCredentialCollection !== void 0 ? _crossServerCredentialCollection : null;
|
|
86
|
-
};
|
|
87
|
-
exports.internalGetCrossServerCredentialCollection = internalGetCrossServerCredentialCollection;
|
|
60
|
+
// Import shared helpers
|
|
61
|
+
var initExpressKitCollections_1 = require("./initExpressKitCollections");
|
|
88
62
|
/*------------------------------------------------------------------------*/
|
|
89
63
|
/* Main */
|
|
90
64
|
/*------------------------------------------------------------------------*/
|
|
@@ -94,23 +68,8 @@ exports.internalGetCrossServerCredentialCollection = internalGetCrossServerCrede
|
|
|
94
68
|
* @param opts object containing all arguments
|
|
95
69
|
* @param opts.app express app from inside of the postprocessor function that
|
|
96
70
|
* we will add routes to
|
|
97
|
-
* @param opts.getLaunchInfo CACCL LTI's get launch info function
|
|
98
|
-
* @param [opts.logCollection] mongo collection from dce-mango to use for
|
|
99
|
-
* storing logs. If none is included, logs are written to the console
|
|
100
|
-
* @param [opts.logReviewAdmins=all] info on which admins can review
|
|
101
|
-
* logs from the client. If not included, all Canvas admins are allowed to
|
|
102
|
-
* review logs. If null, no Canvas admins are allowed to review logs.
|
|
103
|
-
* If an array of Canvas userIds (numbers), only Canvas admins with those
|
|
104
|
-
* userIds are allowed to review logs. If a dce-mango collection, only
|
|
105
|
-
* Canvas admins with entries in that collection ({ userId, ...}) are allowed
|
|
106
|
-
* to review logs
|
|
107
|
-
* @param [opts.crossServerCredentialCollection] mongo collection from dce-mango to use for
|
|
108
|
-
* storing cross-server credentials. If none is included, cross-server credentials
|
|
109
|
-
* are not supported
|
|
110
71
|
*/
|
|
111
72
|
var initServer = function (opts) {
|
|
112
|
-
_logCollection = opts.logCollection;
|
|
113
|
-
_crossServerCredentialCollection = opts.crossServerCredentialCollection;
|
|
114
73
|
/*----------------------------------------*/
|
|
115
74
|
/* Logging */
|
|
116
75
|
/*----------------------------------------*/
|
|
@@ -131,6 +90,10 @@ var initServer = function (opts) {
|
|
|
131
90
|
* @param {string} [target] Target of the action (each app determines the list
|
|
132
91
|
* of targets) These are usually buttons, panels, elements, etc.
|
|
133
92
|
* @param {LogAction} [action] the type of action performed on the target
|
|
93
|
+
* @param {object} [overriddenUserInfo] object containing info to override
|
|
94
|
+
* @param {number} [opts.userId] overriding Canvas id of the user performing the action
|
|
95
|
+
* @param {string} [opts.userFirstName] overriding first name of the user performing the action
|
|
96
|
+
* @param {string} [opts.userLastName] overriding last name of the user performing the action
|
|
134
97
|
* @returns {Log}
|
|
135
98
|
*/
|
|
136
99
|
opts.app.post(dce_reactkit_1.LOG_ROUTE_PATH, (0, genRouteHandler_1.default)({
|
|
@@ -145,6 +108,7 @@ var initServer = function (opts) {
|
|
|
145
108
|
errorStack: dce_reactkit_1.ParamType.StringOptional,
|
|
146
109
|
target: dce_reactkit_1.ParamType.StringOptional,
|
|
147
110
|
action: dce_reactkit_1.ParamType.StringOptional,
|
|
111
|
+
overriddenUserInfo: dce_reactkit_1.ParamType.JSONOptional,
|
|
148
112
|
},
|
|
149
113
|
handler: function (_a) {
|
|
150
114
|
var params = _a.params, logServerEvent = _a.logServerEvent;
|
|
@@ -162,6 +126,9 @@ var initServer = function (opts) {
|
|
|
162
126
|
code: params.errorCode,
|
|
163
127
|
stack: params.errorStack,
|
|
164
128
|
},
|
|
129
|
+
userId: (params.overriddenUserInfo ? params.overriddenUserInfo.userId : undefined),
|
|
130
|
+
userFirstName: (params.overriddenUserInfo ? params.overriddenUserInfo.userFirstName : undefined),
|
|
131
|
+
userLastName: (params.overriddenUserInfo ? params.overriddenUserInfo.userLastName : undefined),
|
|
165
132
|
}
|
|
166
133
|
// Action
|
|
167
134
|
: {
|
|
@@ -172,6 +139,9 @@ var initServer = function (opts) {
|
|
|
172
139
|
metadata: params.metadata,
|
|
173
140
|
target: params.target,
|
|
174
141
|
action: params.action,
|
|
142
|
+
userId: (params.overriddenUserInfo ? params.overriddenUserInfo.userId : undefined),
|
|
143
|
+
userFirstName: (params.overriddenUserInfo ? params.overriddenUserInfo.userFirstName : undefined),
|
|
144
|
+
userLastName: (params.overriddenUserInfo ? params.overriddenUserInfo.userLastName : undefined),
|
|
175
145
|
});
|
|
176
146
|
// Add hidden boolean to change source to "client"
|
|
177
147
|
var logInfoForcedFromClient = __assign(__assign({}, logInfo), { overrideAsClientEvent: true });
|
|
@@ -192,7 +162,7 @@ var initServer = function (opts) {
|
|
|
192
162
|
* @returns true if the user can review logs
|
|
193
163
|
*/
|
|
194
164
|
var canReviewLogs = function (userId, isAdmin) { return __awaiter(void 0, void 0, void 0, function () {
|
|
195
|
-
var matches, err_1;
|
|
165
|
+
var logReviewerAdminCollection, matches, err_1;
|
|
196
166
|
return __generator(this, function (_a) {
|
|
197
167
|
switch (_a.label) {
|
|
198
168
|
case 0:
|
|
@@ -200,29 +170,22 @@ var initServer = function (opts) {
|
|
|
200
170
|
if (!isAdmin) {
|
|
201
171
|
return [2 /*return*/, false];
|
|
202
172
|
}
|
|
203
|
-
|
|
204
|
-
if (!opts.logReviewAdmins) {
|
|
205
|
-
return [2 /*return*/, true];
|
|
206
|
-
}
|
|
207
|
-
_a.label = 1;
|
|
173
|
+
return [4 /*yield*/, (0, initExpressKitCollections_1.internalGetLogReviewerAdminCollection)()];
|
|
208
174
|
case 1:
|
|
209
|
-
_a.
|
|
210
|
-
|
|
211
|
-
if (Array.isArray(opts.logReviewAdmins)) {
|
|
212
|
-
return [2 /*return*/, opts.logReviewAdmins.some(function (allowedId) {
|
|
213
|
-
return (userId === allowedId);
|
|
214
|
-
})];
|
|
215
|
-
}
|
|
216
|
-
return [4 /*yield*/, opts.logReviewAdmins.find({ userId: userId })];
|
|
175
|
+
logReviewerAdminCollection = _a.sent();
|
|
176
|
+
_a.label = 2;
|
|
217
177
|
case 2:
|
|
178
|
+
_a.trys.push([2, 4, , 5]);
|
|
179
|
+
return [4 /*yield*/, logReviewerAdminCollection.find({ id: userId })];
|
|
180
|
+
case 3:
|
|
218
181
|
matches = _a.sent();
|
|
219
182
|
// Make sure at least one entry matches
|
|
220
183
|
return [2 /*return*/, matches.length > 0];
|
|
221
|
-
case
|
|
184
|
+
case 4:
|
|
222
185
|
err_1 = _a.sent();
|
|
223
186
|
// If an error occurred, simply return false
|
|
224
187
|
return [2 /*return*/, false];
|
|
225
|
-
case
|
|
188
|
+
case 5: return [2 /*return*/];
|
|
226
189
|
}
|
|
227
190
|
});
|
|
228
191
|
}); };
|
|
@@ -242,6 +205,7 @@ var initServer = function (opts) {
|
|
|
242
205
|
return [4 /*yield*/, canReviewLogs(userId, isAdmin)];
|
|
243
206
|
case 1:
|
|
244
207
|
canReview = _c.sent();
|
|
208
|
+
// Return result
|
|
245
209
|
return [2 /*return*/, canReview];
|
|
246
210
|
}
|
|
247
211
|
});
|
|
@@ -249,7 +213,8 @@ var initServer = function (opts) {
|
|
|
249
213
|
}));
|
|
250
214
|
/**
|
|
251
215
|
* Get filtered logs based on provided filters
|
|
252
|
-
* @author Gabe Abrams
|
|
216
|
+
* @author Gabe Abrams
|
|
217
|
+
* @author Yuen Ler Chow
|
|
253
218
|
* @param pageNumber the page number to get
|
|
254
219
|
* @param filters the filters to apply to the logs
|
|
255
220
|
* @returns {Log[]} list of logs that match the filters
|
|
@@ -261,7 +226,7 @@ var initServer = function (opts) {
|
|
|
261
226
|
countDocuments: dce_reactkit_1.ParamType.Boolean,
|
|
262
227
|
},
|
|
263
228
|
handler: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
264
|
-
var pageNumber, userId, isAdmin, filters, countDocuments, canReview, response;
|
|
229
|
+
var pageNumber, userId, isAdmin, filters, countDocuments, canReview, logCollection, response;
|
|
265
230
|
var params = _b.params;
|
|
266
231
|
return __generator(this, function (_c) {
|
|
267
232
|
switch (_c.label) {
|
|
@@ -273,13 +238,16 @@ var initServer = function (opts) {
|
|
|
273
238
|
if (!canReview) {
|
|
274
239
|
throw new dce_reactkit_1.ErrorWithCode('You cannot access this resource because you do not have the appropriate permissions.', ExpressKitErrorCode_1.default.NotAllowedToReviewLogs);
|
|
275
240
|
}
|
|
241
|
+
return [4 /*yield*/, (0, initExpressKitCollections_1.internalGetLogCollection)()];
|
|
242
|
+
case 2:
|
|
243
|
+
logCollection = _c.sent();
|
|
276
244
|
return [4 /*yield*/, (0, getLogReviewerLogs_1.default)({
|
|
277
245
|
pageNumber: pageNumber,
|
|
278
246
|
filters: filters,
|
|
279
247
|
countDocuments: countDocuments,
|
|
280
|
-
logCollection:
|
|
248
|
+
logCollection: logCollection,
|
|
281
249
|
})];
|
|
282
|
-
case
|
|
250
|
+
case 3:
|
|
283
251
|
response = _c.sent();
|
|
284
252
|
// Return response
|
|
285
253
|
return [2 /*return*/, response];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initServer.js","sourceRoot":"","sources":["../../src/helpers/initServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"initServer.js","sourceRoot":"","sources":["../../src/helpers/initServer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,sBAAsB;AACtB,6CAOsB;AAEtB,wBAAwB;AACxB,sEAAgD;AAChD,4EAAsD;AAEtD,sBAAsB;AACtB,qFAA+D;AAE/D,wBAAwB;AACxB,yEAGqC;AAErC,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAE5E;;;;;;GAMG;AACH,IAAM,UAAU,GAAG,UACjB,IAEC;IAED,4CAA4C;IAC5C,4CAA4C;IAC5C,4CAA4C;IAE5C;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,IAAI,CAAC,GAAG,CAAC,IAAI,CACX,6BAAc,EACd,IAAA,yBAAe,EAAC;QACd,UAAU,EAAE;YACV,OAAO,EAAE,wBAAS,CAAC,MAAM;YACzB,UAAU,EAAE,wBAAS,CAAC,MAAM;YAC5B,IAAI,EAAE,wBAAS,CAAC,IAAI;YACpB,KAAK,EAAE,wBAAS,CAAC,MAAM;YACvB,QAAQ,EAAE,wBAAS,CAAC,IAAI;YACxB,YAAY,EAAE,wBAAS,CAAC,cAAc;YACtC,SAAS,EAAE,wBAAS,CAAC,cAAc;YACnC,UAAU,EAAE,wBAAS,CAAC,cAAc;YACpC,MAAM,EAAE,wBAAS,CAAC,cAAc;YAChC,MAAM,EAAE,wBAAS,CAAC,cAAc;YAChC,kBA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AO,QAAQ,EAAC;;;aACjB;KACF,CAAC,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,UAAU,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, extractProp, compareArraysByProp, getLocalTimeInfo, genCommaList, prefixWithAOrAn, everyAsync, filterAsync, forEachAsync, mapAsync, someAsync, capitalize, shuffleArray, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, LogFunction, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, ErrorWithCode, ParamType } from 'dce-reactkit';
|
|
2
|
-
import initCrossServerCredentialCollection from './helpers/initCrossServerCredentialCollection';
|
|
3
|
-
import initLogCollection from './helpers/initLogCollection';
|
|
4
2
|
import initServer from './helpers/initServer';
|
|
5
3
|
import genRouteHandler from './helpers/genRouteHandler';
|
|
6
4
|
import handleError from './helpers/handleError';
|
|
7
5
|
import handleSuccess from './helpers/handleSuccess';
|
|
8
6
|
import addDBEditorEndpoints from './helpers/addDBEditorEndpoints';
|
|
9
7
|
import visitEndpointOnAnotherServer from './helpers/visitEndpointOnAnotherServer';
|
|
8
|
+
import initExpressKitCollections from './helpers/initExpressKitCollections';
|
|
10
9
|
import CrossServerCredential from './types/CrossServerCredential';
|
|
11
|
-
export { ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, extractProp, compareArraysByProp, genCommaList, getLocalTimeInfo, prefixWithAOrAn, everyAsync, filterAsync, forEachAsync, mapAsync, someAsync, capitalize, shuffleArray, initServer, genRouteHandler, handleError, handleSuccess,
|
|
10
|
+
export { ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, extractProp, compareArraysByProp, genCommaList, getLocalTimeInfo, prefixWithAOrAn, everyAsync, filterAsync, forEachAsync, mapAsync, someAsync, capitalize, shuffleArray, initServer, genRouteHandler, handleError, handleSuccess, initExpressKitCollections, addDBEditorEndpoints, visitEndpointOnAnotherServer, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, LogFunction, CrossServerCredential, ParamType, };
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ParamType = exports.LogBuiltInMetadata = exports.LogAction = exports.LogSource = exports.LogType = exports.DayOfWeek = exports.visitEndpointOnAnotherServer = exports.addDBEditorEndpoints = exports.
|
|
6
|
+
exports.ParamType = exports.LogBuiltInMetadata = exports.LogAction = exports.LogSource = exports.LogType = exports.DayOfWeek = exports.visitEndpointOnAnotherServer = exports.addDBEditorEndpoints = exports.initExpressKitCollections = exports.handleSuccess = exports.handleError = exports.genRouteHandler = exports.initServer = exports.shuffleArray = exports.capitalize = exports.someAsync = exports.mapAsync = exports.forEachAsync = exports.filterAsync = exports.everyAsync = exports.prefixWithAOrAn = exports.getLocalTimeInfo = exports.genCommaList = exports.compareArraysByProp = exports.extractProp = exports.genCSV = exports.getMonthName = exports.parallelLimit = exports.onlyKeepLetters = exports.stringsToHumanReadableList = exports.getPartOfDay = exports.getHumanReadableDate = exports.startMinWait = exports.getTimeInfoInET = exports.getOrdinal = exports.waitMs = exports.sum = exports.roundToNumDecimals = exports.padZerosLeft = exports.padDecimalZeros = exports.forceNumIntoBounds = exports.floorToNumDecimals = exports.ceilToNumDecimals = exports.avg = exports.abbreviate = exports.DAY_IN_MS = exports.HOUR_IN_MS = exports.MINUTE_IN_MS = exports.ErrorWithCode = void 0;
|
|
7
7
|
// Import dce-reactkit
|
|
8
8
|
var dce_reactkit_1 = require("dce-reactkit");
|
|
9
9
|
Object.defineProperty(exports, "abbreviate", { enumerable: true, get: function () { return dce_reactkit_1.abbreviate; } });
|
|
@@ -49,10 +49,6 @@ Object.defineProperty(exports, "DAY_IN_MS", { enumerable: true, get: function ()
|
|
|
49
49
|
Object.defineProperty(exports, "ErrorWithCode", { enumerable: true, get: function () { return dce_reactkit_1.ErrorWithCode; } });
|
|
50
50
|
Object.defineProperty(exports, "ParamType", { enumerable: true, get: function () { return dce_reactkit_1.ParamType; } });
|
|
51
51
|
// Import helpers
|
|
52
|
-
var initCrossServerCredentialCollection_1 = __importDefault(require("./helpers/initCrossServerCredentialCollection"));
|
|
53
|
-
exports.initCrossServerCredentialCollection = initCrossServerCredentialCollection_1.default;
|
|
54
|
-
var initLogCollection_1 = __importDefault(require("./helpers/initLogCollection"));
|
|
55
|
-
exports.initLogCollection = initLogCollection_1.default;
|
|
56
52
|
var initServer_1 = __importDefault(require("./helpers/initServer"));
|
|
57
53
|
exports.initServer = initServer_1.default;
|
|
58
54
|
var genRouteHandler_1 = __importDefault(require("./helpers/genRouteHandler"));
|
|
@@ -65,4 +61,6 @@ var addDBEditorEndpoints_1 = __importDefault(require("./helpers/addDBEditorEndpo
|
|
|
65
61
|
exports.addDBEditorEndpoints = addDBEditorEndpoints_1.default;
|
|
66
62
|
var visitEndpointOnAnotherServer_1 = __importDefault(require("./helpers/visitEndpointOnAnotherServer"));
|
|
67
63
|
exports.visitEndpointOnAnotherServer = visitEndpointOnAnotherServer_1.default;
|
|
64
|
+
var initExpressKitCollections_1 = __importDefault(require("./helpers/initExpressKitCollections"));
|
|
65
|
+
exports.initExpressKitCollections = initExpressKitCollections_1.default;
|
|
68
66
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sBAAsB;AACtB,6CA8CsB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sBAAsB;AACtB,6CA8CsB;AAuBpB,2FApEA,yBAAU,OAoEA;AACV,oFApEA,kBAAG,OAoEA;AACH,kGApEA,gCAAiB,OAoEA;AACjB,mGApEA,iCAAkB,OAoEA;AAClB,mGApEA,iCAAkB,OAoEA;AAClB,gGApEA,8BAAe,OAoEA;AACf,6FApEA,2BAAY,OAoEA;AACZ,mGApEA,iCAAkB,OAoEA;AAClB,oFApEA,kBAAG,OAoEA;AACH,uFApEA,qBAAM,OAoEA;AACN,2FApEA,yBAAU,OAoEA;AACV,gGApEA,8BAAe,OAoEA;AACf,6FApEA,2BAAY,OAoEA;AACZ,qGApEA,mCAAoB,OAoEA;AACpB,6FApEA,2BAAY,OAoEA;AACZ,2GApEA,yCAA0B,OAoEA;AAC1B,gGApEA,8BAAe,OAoEA;AACf,8FApEA,4BAAa,OAoEA;AACb,6FApEA,2BAAY,OAoEA;AACZ,uFApEA,qBAAM,OAoEA;AACN,4FApEA,0BAAW,OAoEA;AACX,oGApEA,kCAAmB,OAoEA;AAEnB,iGArEA,+BAAgB,OAqEA;AADhB,6FAnEA,2BAAY,OAmEA;AAEZ,gGApEA,8BAAe,OAoEA;AACf,2FApEA,yBAAU,OAoEA;AACV,4FApEA,0BAAW,OAoEA;AACX,6FApEA,2BAAY,OAoEA;AACZ,yFApEA,uBAAQ,OAoEA;AACR,0FApEA,wBAAS,OAoEA;AACT,2FApEA,yBAAU,OAoEA;AACV,6FApEA,2BAAY,OAoEA;AAUZ,0FA7EA,wBAAS,OA6EA;AAET,wFA7EA,sBAAO,OA6EA;AACP,0FA7EA,wBAAS,OA6EA;AACT,0FA7EA,wBAAS,OA6EA;AACT,mGA7EA,iCAAkB,OA6EA;AAlDlB,6FAxBA,2BAAY,OAwBA;AACZ,2FAxBA,yBAAU,OAwBA;AACV,0FAxBA,wBAAS,OAwBA;AAJT,8FAnBA,4BAAa,OAmBA;AAyDb,0FA3EA,wBAAS,OA2EA;AAxEX,iBAAiB;AACjB,oEAA8C;AAqD5C,qBArDK,oBAAU,CAqDL;AApDZ,8EAAwD;AAqDtD,0BArDK,yBAAe,CAqDL;AApDjB,sEAAgD;AAqD9C,sBArDK,qBAAW,CAqDL;AApDb,0EAAoD;AAqDlD,wBArDK,uBAAa,CAqDL;AApDf,wFAAkE;AAsDhE,+BAtDK,8BAAoB,CAsDL;AArDtB,wGAAkF;AAsDhF,uCAtDK,sCAA4B,CAsDL;AArD9B,kGAA4E;AAmD1E,oCAnDK,mCAAyB,CAmDL"}
|
|
@@ -26,6 +26,7 @@ declare enum ExpressKitErrorCode {
|
|
|
26
26
|
NoOauthLib = "DEK31",
|
|
27
27
|
NoCryptoLib = "DEK32",
|
|
28
28
|
InvalidCrossServerCredentialsFormat = "DEK33",
|
|
29
|
-
UnknownCrossServerError = "DEK34"
|
|
29
|
+
UnknownCrossServerError = "DEK34",
|
|
30
|
+
NotSelectAdmin = "DEK35"
|
|
30
31
|
}
|
|
31
32
|
export default ExpressKitErrorCode;
|
|
@@ -33,6 +33,7 @@ var ExpressKitErrorCode;
|
|
|
33
33
|
ExpressKitErrorCode["NoCryptoLib"] = "DEK32";
|
|
34
34
|
ExpressKitErrorCode["InvalidCrossServerCredentialsFormat"] = "DEK33";
|
|
35
35
|
ExpressKitErrorCode["UnknownCrossServerError"] = "DEK34";
|
|
36
|
+
ExpressKitErrorCode["NotSelectAdmin"] = "DEK35";
|
|
36
37
|
})(ExpressKitErrorCode || (ExpressKitErrorCode = {}));
|
|
37
38
|
exports.default = ExpressKitErrorCode;
|
|
38
39
|
//# sourceMappingURL=ExpressKitErrorCode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpressKitErrorCode.js","sourceRoot":"","sources":["../../src/types/ExpressKitErrorCode.ts"],"names":[],"mappings":";AAAA,6BAA6B;;AAE7B;;;GAGG;AACH,IAAK,
|
|
1
|
+
{"version":3,"file":"ExpressKitErrorCode.js","sourceRoot":"","sources":["../../src/types/ExpressKitErrorCode.ts"],"names":[],"mappings":";AAAA,6BAA6B;;AAE7B;;;GAGG;AACH,IAAK,mBA6BJ;AA7BD,WAAK,mBAAmB;IACtB,iBAAiB;IACjB,2CAAoB,CAAA;IACpB,sCAAe,CAAA;IACf,yCAAkB,CAAA;IAClB,uDAAgC,CAAA;IAChC,gEAAyC,CAAA;IACzC,gDAAyB,CAAA;IACzB,gDAAyB,CAAA;IAEzB,4BAA4B;IAC5B,6CAAsB,CAAA;IACtB,2CAAoB,CAAA;IACpB,mDAA4B,CAAA;IAC5B,yDAAkC,CAAA;IAClC,+DAAwC,CAAA;IACxC,+DAAwC,CAAA;IACxC,0DAAmC,CAAA;IACnC,8DAAuC,CAAA;IACvC,8DAAuC,CAAA;IACvC,yDAAkC,CAAA;IAClC,mEAA4C,CAAA;IAC5C,oEAA6C,CAAA;IAC7C,oEAA6C,CAAA;IAC7C,2CAAoB,CAAA;IACpB,4CAAqB,CAAA;IACrB,oEAA6C,CAAA;IAC7C,wDAAiC,CAAA;IACjC,+CAAwB,CAAA;AAC1B,CAAC,EA7BI,mBAAmB,KAAnB,mBAAmB,QA6BvB;AAED,kBAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LogReviewerAdmin.js","sourceRoot":"","sources":["../../src/types/LogReviewerAdmin.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectAdmin.js","sourceRoot":"","sources":["../../src/types/SelectAdmin.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dce-expresskit",
|
|
3
|
-
"version": "4.1
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "Shared functions, helpers, and tools for Harvard DCE Express-based servers",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@fortawesome/free-solid-svg-icons": "^6.7.2",
|
|
26
26
|
"@fortawesome/react-fontawesome": "^0.2.2",
|
|
27
27
|
"bootstrap": "^5.3.3",
|
|
28
|
-
"dce-reactkit": "4.
|
|
28
|
+
"dce-reactkit": "^4.1.8",
|
|
29
29
|
"react": "^19.0.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
@@ -11,7 +11,7 @@ import oauth from 'oauth-signature';
|
|
|
11
11
|
import crypto from 'crypto';
|
|
12
12
|
|
|
13
13
|
// Import shared helpers
|
|
14
|
-
import { internalGetCrossServerCredentialCollection } from './
|
|
14
|
+
import { internalGetCrossServerCredentialCollection } from './initExpressKitCollections';
|
|
15
15
|
|
|
16
16
|
// Import shared types
|
|
17
17
|
import ExpressKitErrorCode from '../types/ExpressKitErrorCode';
|
|
@@ -240,7 +240,7 @@ export const validateSignedRequest = async (
|
|
|
240
240
|
/* ------- Look Up Credential ------- */
|
|
241
241
|
|
|
242
242
|
// Get the cross-server credential collection
|
|
243
|
-
const crossServerCredentialCollection = internalGetCrossServerCredentialCollection();
|
|
243
|
+
const crossServerCredentialCollection = await internalGetCrossServerCredentialCollection();
|
|
244
244
|
if (!crossServerCredentialCollection) {
|
|
245
245
|
throw new ErrorWithCode(
|
|
246
246
|
'Could not validate a cross-server request because the cross-server credential collection was not ready in time.',
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Import dce-reactkit
|
|
2
2
|
import {
|
|
3
3
|
getTimeInfoInET,
|
|
4
|
-
LogFunction,
|
|
5
4
|
Log,
|
|
6
5
|
LogType,
|
|
7
6
|
LogTypeSpecificInfo,
|
|
@@ -13,15 +12,14 @@ import {
|
|
|
13
12
|
ParamType,
|
|
14
13
|
ReactKitErrorCode,
|
|
15
14
|
LogSource,
|
|
15
|
+
LogFunction,
|
|
16
16
|
} from 'dce-reactkit';
|
|
17
17
|
|
|
18
18
|
// Import caccl
|
|
19
19
|
import { getLaunchInfo } from 'caccl/server';
|
|
20
20
|
|
|
21
21
|
// Import caccl functions
|
|
22
|
-
import {
|
|
23
|
-
internalGetLogCollection,
|
|
24
|
-
} from './initServer';
|
|
22
|
+
import { internalGetLogCollection, internalGetSelectAdminCollection } from './initExpressKitCollections';
|
|
25
23
|
|
|
26
24
|
// Import shared types
|
|
27
25
|
import ExpressKitErrorCode from '../types/ExpressKitErrorCode';
|
|
@@ -563,6 +561,32 @@ const genRouteHandler = (
|
|
|
563
561
|
);
|
|
564
562
|
}
|
|
565
563
|
|
|
564
|
+
// Add Select Admin endpoint security
|
|
565
|
+
if (
|
|
566
|
+
// This is a select admin endpoint
|
|
567
|
+
req.path.startsWith('/api/admin/select')
|
|
568
|
+
) {
|
|
569
|
+
// Get select admin collection
|
|
570
|
+
const selectAdminCollection = await internalGetSelectAdminCollection();
|
|
571
|
+
const id = output.userId;
|
|
572
|
+
|
|
573
|
+
// Find match if exists in select admin collection
|
|
574
|
+
const [match] = await selectAdminCollection.find({ id });
|
|
575
|
+
|
|
576
|
+
// Check that user exists in select admin collection
|
|
577
|
+
if (!match) {
|
|
578
|
+
// User does not have access
|
|
579
|
+
return handleError(
|
|
580
|
+
res,
|
|
581
|
+
{
|
|
582
|
+
message: 'This action is only allowed for select Canvas admins. Please go back to Canvas, log in as a select admin, and try again.',
|
|
583
|
+
code: ExpressKitErrorCode.NotSelectAdmin,
|
|
584
|
+
status: 401,
|
|
585
|
+
},
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
566
590
|
/*----------------------------------------*/
|
|
567
591
|
/* ------------- Log Handler ------------ */
|
|
568
592
|
/*----------------------------------------*/
|
|
@@ -595,13 +619,27 @@ const genRouteHandler = (
|
|
|
595
619
|
minute,
|
|
596
620
|
} = getTimeInfoInET();
|
|
597
621
|
|
|
622
|
+
// Get user info
|
|
623
|
+
let userId = (launchInfo ? launchInfo.userId : -1);
|
|
624
|
+
if (logOpts.userId) {
|
|
625
|
+
userId = logOpts.userId;
|
|
626
|
+
}
|
|
627
|
+
let userFirstName = (launchInfo ? launchInfo.userFirstName : 'unknown');
|
|
628
|
+
if (logOpts.userFirstName) {
|
|
629
|
+
userFirstName = logOpts.userFirstName;
|
|
630
|
+
}
|
|
631
|
+
let userLastName = (launchInfo ? launchInfo.userLastName : 'unknown');
|
|
632
|
+
if (logOpts.userLastName) {
|
|
633
|
+
userLastName = logOpts.userLastName;
|
|
634
|
+
}
|
|
635
|
+
|
|
598
636
|
// Main log info
|
|
599
637
|
const mainLogInfo: LogMainInfo = {
|
|
600
638
|
id: `${launchInfo ? launchInfo.userId : 'unknown'}-${Date.now()}-${Math.floor(Math.random() * 100000)}-${Math.floor(Math.random() * 100000)}`,
|
|
601
|
-
userFirstName
|
|
602
|
-
userLastName
|
|
639
|
+
userFirstName,
|
|
640
|
+
userLastName,
|
|
603
641
|
userEmail: (launchInfo ? launchInfo.userEmail : 'unknown'),
|
|
604
|
-
userId
|
|
642
|
+
userId,
|
|
605
643
|
isLearner: (launchInfo && !!launchInfo.isLearner),
|
|
606
644
|
isAdmin: (launchInfo && !!launchInfo.isAdmin),
|
|
607
645
|
isTTM: (launchInfo && !!launchInfo.isTTM),
|
|
@@ -675,7 +713,7 @@ const genRouteHandler = (
|
|
|
675
713
|
};
|
|
676
714
|
|
|
677
715
|
// Either print to console or save to db
|
|
678
|
-
const logCollection = internalGetLogCollection();
|
|
716
|
+
const logCollection = await internalGetLogCollection();
|
|
679
717
|
if (logCollection) {
|
|
680
718
|
// Store to the log collection
|
|
681
719
|
await logCollection.insert(log);
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Import dce-mango
|
|
2
|
+
import { Collection as MangoCollection } from 'dce-mango';
|
|
3
|
+
|
|
4
|
+
// Import dce-reactkit
|
|
5
|
+
import { Log } from 'dce-reactkit';
|
|
6
|
+
|
|
7
|
+
// Import shared types
|
|
8
|
+
import CrossServerCredential from '../types/CrossServerCredential';
|
|
9
|
+
import SelectAdmin from '../types/SelectAdmin';
|
|
10
|
+
import LogReviewerAdmin from '../types/LogReviewerAdmin';
|
|
11
|
+
|
|
12
|
+
/*------------------------------------------------------------------------*/
|
|
13
|
+
/* ------------------------- Collection Storage ------------------------- */
|
|
14
|
+
/*------------------------------------------------------------------------*/
|
|
15
|
+
|
|
16
|
+
// Variables to store collections
|
|
17
|
+
let logCollection: MangoCollection<Log>;
|
|
18
|
+
let crossServerCredentialCollection: MangoCollection<CrossServerCredential>;
|
|
19
|
+
let selectAdminCollection: MangoCollection<SelectAdmin>;
|
|
20
|
+
let logReviewerAdminCollection: MangoCollection<LogReviewerAdmin>;
|
|
21
|
+
|
|
22
|
+
// Promise that resolves when all collections are initialized
|
|
23
|
+
let collectionsInitializedResolve: (v?: unknown) => void;
|
|
24
|
+
let collectionsInitializedReject: (error: Error) => void;
|
|
25
|
+
const collectionsInitialized = new Promise((resolve, reject) => {
|
|
26
|
+
collectionsInitializedResolve = resolve;
|
|
27
|
+
collectionsInitializedReject = reject;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
/*------------------------------------------------------------------------*/
|
|
31
|
+
/* ------------------------- Collection Getters ------------------------- */
|
|
32
|
+
/*------------------------------------------------------------------------*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get the log collection after initialization
|
|
36
|
+
* @author Gardenia Liu
|
|
37
|
+
*/
|
|
38
|
+
export const internalGetLogCollection = async () => {
|
|
39
|
+
// Wait for collections to be initialized
|
|
40
|
+
await collectionsInitialized;
|
|
41
|
+
|
|
42
|
+
// Return the log collection
|
|
43
|
+
return logCollection;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the cross server credential collection after initialization
|
|
48
|
+
* @author Gardenia Liu
|
|
49
|
+
*/
|
|
50
|
+
export const internalGetCrossServerCredentialCollection = async () => {
|
|
51
|
+
// Wait for collections to be initialized
|
|
52
|
+
await collectionsInitialized;
|
|
53
|
+
|
|
54
|
+
// Return the cross server credential collection
|
|
55
|
+
return crossServerCredentialCollection;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get the select admin collection after initialization
|
|
60
|
+
* @author Gardenia Liu
|
|
61
|
+
*/
|
|
62
|
+
export const internalGetSelectAdminCollection = async () => {
|
|
63
|
+
// Wait for collections to be initialized
|
|
64
|
+
await collectionsInitialized;
|
|
65
|
+
|
|
66
|
+
// Return the cross server credential collection
|
|
67
|
+
return selectAdminCollection;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Get the log reviewer admin collection after initialization
|
|
72
|
+
* @author Yuen Ler Chow
|
|
73
|
+
*/
|
|
74
|
+
export const internalGetLogReviewerAdminCollection = async () => {
|
|
75
|
+
// Wait for collections to be initialized
|
|
76
|
+
await collectionsInitialized;
|
|
77
|
+
|
|
78
|
+
// Return the log reviewer admin collection
|
|
79
|
+
return logReviewerAdminCollection;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/*------------------------------------------------------------------------*/
|
|
83
|
+
/* -------------------------------- Main -------------------------------- */
|
|
84
|
+
/*------------------------------------------------------------------------*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Initialize all collections required for expresskit
|
|
88
|
+
* @author Gardenia Liu
|
|
89
|
+
* @author Gabe Abrams
|
|
90
|
+
* @param Collection the Collection class from dce-mango
|
|
91
|
+
*/
|
|
92
|
+
const initExpressKitCollections = (Collection: typeof MangoCollection) => {
|
|
93
|
+
try {
|
|
94
|
+
// Create and store log collection
|
|
95
|
+
logCollection = new Collection<Log>(
|
|
96
|
+
'Log',
|
|
97
|
+
{
|
|
98
|
+
uniqueIndexKey: 'id',
|
|
99
|
+
indexKeys: [
|
|
100
|
+
'courseId',
|
|
101
|
+
'context',
|
|
102
|
+
'subcontext',
|
|
103
|
+
'tags',
|
|
104
|
+
'year',
|
|
105
|
+
'month',
|
|
106
|
+
'day',
|
|
107
|
+
'hour',
|
|
108
|
+
'type',
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
// Create and store cross server credential collection
|
|
114
|
+
crossServerCredentialCollection = new Collection<CrossServerCredential>(
|
|
115
|
+
'CrossServerCredential',
|
|
116
|
+
{
|
|
117
|
+
uniqueIndexKey: 'key',
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
// Create and store select admin collection
|
|
122
|
+
selectAdminCollection = new Collection<SelectAdmin>(
|
|
123
|
+
'SelectAdmin',
|
|
124
|
+
{
|
|
125
|
+
uniqueIndexKey: 'id',
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// Create and store log reviewer admin collection
|
|
130
|
+
logReviewerAdminCollection = new Collection<LogReviewerAdmin>(
|
|
131
|
+
'LogReviewerAdmin',
|
|
132
|
+
{
|
|
133
|
+
uniqueIndexKey: 'id',
|
|
134
|
+
},
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
// Finished! Resolve the promise
|
|
138
|
+
collectionsInitializedResolve();
|
|
139
|
+
} catch (err) {
|
|
140
|
+
return collectionsInitializedReject(err as Error);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export default initExpressKitCollections;
|