dce-expresskit 4.0.0-beta-logreviewer.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/.eslintrc.js +93 -0
- package/LICENSE +21 -0
- package/README.md +17 -0
- package/genEncodedSecret.ts +107 -0
- package/genSalt.ts +15 -0
- package/lib/constants/LOG_REVIEW_PAGE_SIZE.d.ts +6 -0
- package/lib/constants/LOG_REVIEW_PAGE_SIZE.js +9 -0
- package/lib/constants/LOG_REVIEW_PAGE_SIZE.js.map +1 -0
- package/lib/constants/LOG_REVIEW_ROUTE_PATH_PREFIX.d.ts +6 -0
- package/lib/constants/LOG_REVIEW_ROUTE_PATH_PREFIX.js +13 -0
- package/lib/constants/LOG_REVIEW_ROUTE_PATH_PREFIX.js.map +1 -0
- package/lib/constants/LOG_REVIEW_STATUS_ROUTE.d.ts +7 -0
- package/lib/constants/LOG_REVIEW_STATUS_ROUTE.js +14 -0
- package/lib/constants/LOG_REVIEW_STATUS_ROUTE.js.map +1 -0
- package/lib/constants/LOG_ROUTE_PATH.d.ts +6 -0
- package/lib/constants/LOG_ROUTE_PATH.js +13 -0
- package/lib/constants/LOG_ROUTE_PATH.js.map +1 -0
- package/lib/constants/ROUTE_PATH_PREFIX.d.ts +6 -0
- package/lib/constants/ROUTE_PATH_PREFIX.js +9 -0
- package/lib/constants/ROUTE_PATH_PREFIX.js.map +1 -0
- package/lib/errors/ErrorWithCode.d.ts +9 -0
- package/lib/errors/ErrorWithCode.js +33 -0
- package/lib/errors/ErrorWithCode.js.map +1 -0
- package/lib/helpers/addDBEditorEndpoints/generateEndpointPath.d.ts +9 -0
- package/lib/helpers/addDBEditorEndpoints/generateEndpointPath.js +17 -0
- package/lib/helpers/addDBEditorEndpoints/generateEndpointPath.js.map +1 -0
- package/lib/helpers/addDBEditorEndpoints/index.d.ts +41 -0
- package/lib/helpers/addDBEditorEndpoints/index.js +134 -0
- package/lib/helpers/addDBEditorEndpoints/index.js.map +1 -0
- package/lib/helpers/dataSigner.d.ts +40 -0
- package/lib/helpers/dataSigner.js +242 -0
- package/lib/helpers/dataSigner.js.map +1 -0
- package/lib/helpers/genRouteHandler.d.ts +75 -0
- package/lib/helpers/genRouteHandler.js +662 -0
- package/lib/helpers/genRouteHandler.js.map +1 -0
- package/lib/helpers/getLogReviewerLogs.d.ts +27 -0
- package/lib/helpers/getLogReviewerLogs.js +238 -0
- package/lib/helpers/getLogReviewerLogs.js.map +1 -0
- package/lib/helpers/handleError.d.ts +18 -0
- package/lib/helpers/handleError.js +51 -0
- package/lib/helpers/handleError.js.map +1 -0
- package/lib/helpers/handleSuccess.d.ts +8 -0
- package/lib/helpers/handleSuccess.js +20 -0
- package/lib/helpers/handleSuccess.js.map +1 -0
- package/lib/helpers/initCrossServerCredentialCollection.d.ts +11 -0
- package/lib/helpers/initCrossServerCredentialCollection.js +15 -0
- package/lib/helpers/initCrossServerCredentialCollection.js.map +1 -0
- package/lib/helpers/initLogCollection.d.ts +11 -0
- package/lib/helpers/initLogCollection.js +26 -0
- package/lib/helpers/initLogCollection.js.map +1 -0
- package/lib/helpers/initServer.d.ts +45 -0
- package/lib/helpers/initServer.js +292 -0
- package/lib/helpers/initServer.js.map +1 -0
- package/lib/helpers/parseUserAgent.d.ts +17 -0
- package/lib/helpers/parseUserAgent.js +108 -0
- package/lib/helpers/parseUserAgent.js.map +1 -0
- package/lib/helpers/visitEndpointOnAnotherServer/index.d.ts +18 -0
- package/lib/helpers/visitEndpointOnAnotherServer/index.js +89 -0
- package/lib/helpers/visitEndpointOnAnotherServer/index.js.map +1 -0
- package/lib/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.d.ts +23 -0
- package/lib/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.js +236 -0
- package/lib/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.js.map +1 -0
- package/lib/html/genErrorPage.d.ts +19 -0
- package/lib/html/genErrorPage.js +27 -0
- package/lib/html/genErrorPage.js.map +1 -0
- package/lib/html/genInfoPage.d.ts +13 -0
- package/lib/html/genInfoPage.js +16 -0
- package/lib/html/genInfoPage.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +68 -0
- package/lib/index.js.map +1 -0
- package/lib/types/CrossServerCredential.d.ts +11 -0
- package/lib/types/CrossServerCredential.js +3 -0
- package/lib/types/CrossServerCredential.js.map +1 -0
- package/lib/types/ExpressKitErrorCode.d.ts +31 -0
- package/lib/types/ExpressKitErrorCode.js +38 -0
- package/lib/types/ExpressKitErrorCode.js.map +1 -0
- package/package.json +53 -0
- package/src/constants/LOG_REVIEW_PAGE_SIZE.ts +7 -0
- package/src/errors/ErrorWithCode.tsx +15 -0
- package/src/helpers/addDBEditorEndpoints/generateEndpointPath.ts +16 -0
- package/src/helpers/addDBEditorEndpoints/index.ts +130 -0
- package/src/helpers/dataSigner.ts +319 -0
- package/src/helpers/genRouteHandler.ts +920 -0
- package/src/helpers/getLogReviewerLogs.ts +259 -0
- package/src/helpers/handleError.ts +66 -0
- package/src/helpers/handleSuccess.ts +18 -0
- package/src/helpers/initCrossServerCredentialCollection.ts +19 -0
- package/src/helpers/initLogCollection.ts +30 -0
- package/src/helpers/initServer.ts +283 -0
- package/src/helpers/parseUserAgent.ts +108 -0
- package/src/helpers/visitEndpointOnAnotherServer/index.ts +70 -0
- package/src/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.ts +257 -0
- package/src/html/genErrorPage.ts +144 -0
- package/src/html/genInfoPage.ts +101 -0
- package/src/index.ts +125 -0
- package/src/types/CrossServerCredential.ts +16 -0
- package/src/types/ExpressKitErrorCode.ts +37 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.internalGetCrossServerCredentialCollection = exports.internalGetLogCollection = void 0;
|
|
54
|
+
// Import dce-reactkit
|
|
55
|
+
var dce_reactkit_1 = require("dce-reactkit");
|
|
56
|
+
// Import shared helpers
|
|
57
|
+
var genRouteHandler_1 = __importDefault(require("./genRouteHandler"));
|
|
58
|
+
var getLogReviewerLogs_1 = __importDefault(require("./getLogReviewerLogs"));
|
|
59
|
+
// Import shared types
|
|
60
|
+
var ExpressKitErrorCode_1 = __importDefault(require("../types/ExpressKitErrorCode"));
|
|
61
|
+
// Stored copy of dce-mango log collection
|
|
62
|
+
var _logCollection;
|
|
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;
|
|
88
|
+
/*------------------------------------------------------------------------*/
|
|
89
|
+
/* Main */
|
|
90
|
+
/*------------------------------------------------------------------------*/
|
|
91
|
+
/**
|
|
92
|
+
* Prepare dce-reactkit to run on the server
|
|
93
|
+
* @author Gabe Abrams
|
|
94
|
+
* @param opts object containing all arguments
|
|
95
|
+
* @param opts.app express app from inside of the postprocessor function that
|
|
96
|
+
* 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
|
+
*/
|
|
111
|
+
var initServer = function (opts) {
|
|
112
|
+
_logCollection = opts.logCollection;
|
|
113
|
+
_crossServerCredentialCollection = opts.crossServerCredentialCollection;
|
|
114
|
+
/*----------------------------------------*/
|
|
115
|
+
/* Logging */
|
|
116
|
+
/*----------------------------------------*/
|
|
117
|
+
/**
|
|
118
|
+
* Log an event
|
|
119
|
+
* @author Gabe Abrams
|
|
120
|
+
* @param {string} context Context of the event (each app determines how to
|
|
121
|
+
* organize its contexts)
|
|
122
|
+
* @param {string} subcontext Subcontext of the event (each app determines
|
|
123
|
+
* how to organize its subcontexts)
|
|
124
|
+
* @param {string} tags stringified list of tags that apply to this action
|
|
125
|
+
* (each app determines tag usage)
|
|
126
|
+
* @param {string} metadata stringified object containing optional custom metadata
|
|
127
|
+
* @param {string} level log level
|
|
128
|
+
* @param {string} [errorMessage] error message if type is an error
|
|
129
|
+
* @param {string} [errorCode] error code if type is an error
|
|
130
|
+
* @param {string} [errorStack] error stack if type is an error
|
|
131
|
+
* @param {string} [target] Target of the action (each app determines the list
|
|
132
|
+
* of targets) These are usually buttons, panels, elements, etc.
|
|
133
|
+
* @param {LogAction} [action] the type of action performed on the target
|
|
134
|
+
* @returns {Log}
|
|
135
|
+
*/
|
|
136
|
+
opts.app.post(dce_reactkit_1.LOG_ROUTE_PATH, (0, genRouteHandler_1.default)({
|
|
137
|
+
paramTypes: {
|
|
138
|
+
context: dce_reactkit_1.ParamType.String,
|
|
139
|
+
subcontext: dce_reactkit_1.ParamType.String,
|
|
140
|
+
tags: dce_reactkit_1.ParamType.JSON,
|
|
141
|
+
level: dce_reactkit_1.ParamType.String,
|
|
142
|
+
metadata: dce_reactkit_1.ParamType.JSON,
|
|
143
|
+
errorMessage: dce_reactkit_1.ParamType.StringOptional,
|
|
144
|
+
errorCode: dce_reactkit_1.ParamType.StringOptional,
|
|
145
|
+
errorStack: dce_reactkit_1.ParamType.StringOptional,
|
|
146
|
+
target: dce_reactkit_1.ParamType.StringOptional,
|
|
147
|
+
action: dce_reactkit_1.ParamType.StringOptional,
|
|
148
|
+
},
|
|
149
|
+
handler: function (_a) {
|
|
150
|
+
var params = _a.params, logServerEvent = _a.logServerEvent;
|
|
151
|
+
// Create log info
|
|
152
|
+
var logInfo = ((params.errorMessage || params.errorCode || params.errorStack)
|
|
153
|
+
// Error
|
|
154
|
+
? {
|
|
155
|
+
context: params.context,
|
|
156
|
+
subcontext: params.subcontext,
|
|
157
|
+
tags: params.tags,
|
|
158
|
+
level: params.level,
|
|
159
|
+
metadata: params.metadata,
|
|
160
|
+
error: {
|
|
161
|
+
message: params.errorMessage,
|
|
162
|
+
code: params.errorCode,
|
|
163
|
+
stack: params.errorStack,
|
|
164
|
+
},
|
|
165
|
+
}
|
|
166
|
+
// Action
|
|
167
|
+
: {
|
|
168
|
+
context: params.context,
|
|
169
|
+
subcontext: params.subcontext,
|
|
170
|
+
tags: params.tags,
|
|
171
|
+
level: params.level,
|
|
172
|
+
metadata: params.metadata,
|
|
173
|
+
target: params.target,
|
|
174
|
+
action: params.action,
|
|
175
|
+
});
|
|
176
|
+
// Add hidden boolean to change source to "client"
|
|
177
|
+
var logInfoForcedFromClient = __assign(__assign({}, logInfo), { overrideAsClientEvent: true });
|
|
178
|
+
// Write the log
|
|
179
|
+
var log = logServerEvent(logInfoForcedFromClient);
|
|
180
|
+
// Return
|
|
181
|
+
return log;
|
|
182
|
+
},
|
|
183
|
+
}));
|
|
184
|
+
/*----------------------------------------*/
|
|
185
|
+
/* Log Reviewer */
|
|
186
|
+
/*----------------------------------------*/
|
|
187
|
+
/**
|
|
188
|
+
* Check if a given user is allowed to review logs
|
|
189
|
+
* @author Gabe Abrams
|
|
190
|
+
* @param userId the id of the user
|
|
191
|
+
* @param isAdmin if true, the user is an admin
|
|
192
|
+
* @returns true if the user can review logs
|
|
193
|
+
*/
|
|
194
|
+
var canReviewLogs = function (userId, isAdmin) { return __awaiter(void 0, void 0, void 0, function () {
|
|
195
|
+
var matches, err_1;
|
|
196
|
+
return __generator(this, function (_a) {
|
|
197
|
+
switch (_a.label) {
|
|
198
|
+
case 0:
|
|
199
|
+
// Immediately deny access if user is not an admin
|
|
200
|
+
if (!isAdmin) {
|
|
201
|
+
return [2 /*return*/, false];
|
|
202
|
+
}
|
|
203
|
+
// If all admins are allowed, we're done
|
|
204
|
+
if (!opts.logReviewAdmins) {
|
|
205
|
+
return [2 /*return*/, true];
|
|
206
|
+
}
|
|
207
|
+
_a.label = 1;
|
|
208
|
+
case 1:
|
|
209
|
+
_a.trys.push([1, 3, , 4]);
|
|
210
|
+
// Array of userIds
|
|
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 })];
|
|
217
|
+
case 2:
|
|
218
|
+
matches = _a.sent();
|
|
219
|
+
// Make sure at least one entry matches
|
|
220
|
+
return [2 /*return*/, matches.length > 0];
|
|
221
|
+
case 3:
|
|
222
|
+
err_1 = _a.sent();
|
|
223
|
+
// If an error occurred, simply return false
|
|
224
|
+
return [2 /*return*/, false];
|
|
225
|
+
case 4: return [2 /*return*/];
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}); };
|
|
229
|
+
/**
|
|
230
|
+
* Check if the current user has access to logs
|
|
231
|
+
* @author Gabe Abrams
|
|
232
|
+
* @returns {boolean} true if user has access
|
|
233
|
+
*/
|
|
234
|
+
opts.app.get(dce_reactkit_1.LOG_REVIEW_STATUS_ROUTE, (0, genRouteHandler_1.default)({
|
|
235
|
+
handler: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
236
|
+
var userId, isAdmin, canReview;
|
|
237
|
+
var params = _b.params;
|
|
238
|
+
return __generator(this, function (_c) {
|
|
239
|
+
switch (_c.label) {
|
|
240
|
+
case 0:
|
|
241
|
+
userId = params.userId, isAdmin = params.isAdmin;
|
|
242
|
+
return [4 /*yield*/, canReviewLogs(userId, isAdmin)];
|
|
243
|
+
case 1:
|
|
244
|
+
canReview = _c.sent();
|
|
245
|
+
return [2 /*return*/, canReview];
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}); },
|
|
249
|
+
}));
|
|
250
|
+
/**
|
|
251
|
+
* Get filtered logs based on provided filters
|
|
252
|
+
* @author Gabe Abrams, Yuen Ler Chow
|
|
253
|
+
* @param pageNumber the page number to get
|
|
254
|
+
* @param filters the filters to apply to the logs
|
|
255
|
+
* @returns {Log[]} list of logs that match the filters
|
|
256
|
+
*/
|
|
257
|
+
opts.app.get(dce_reactkit_1.LOG_REVIEW_GET_LOGS_ROUTE, (0, genRouteHandler_1.default)({
|
|
258
|
+
paramTypes: {
|
|
259
|
+
pageNumber: dce_reactkit_1.ParamType.Int,
|
|
260
|
+
filters: dce_reactkit_1.ParamType.JSON,
|
|
261
|
+
countDocuments: dce_reactkit_1.ParamType.Boolean,
|
|
262
|
+
},
|
|
263
|
+
handler: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
264
|
+
var pageNumber, userId, isAdmin, filters, countDocuments, canReview, response;
|
|
265
|
+
var params = _b.params;
|
|
266
|
+
return __generator(this, function (_c) {
|
|
267
|
+
switch (_c.label) {
|
|
268
|
+
case 0:
|
|
269
|
+
pageNumber = params.pageNumber, userId = params.userId, isAdmin = params.isAdmin, filters = params.filters, countDocuments = params.countDocuments;
|
|
270
|
+
return [4 /*yield*/, canReviewLogs(userId, isAdmin)];
|
|
271
|
+
case 1:
|
|
272
|
+
canReview = _c.sent();
|
|
273
|
+
if (!canReview) {
|
|
274
|
+
throw new dce_reactkit_1.ErrorWithCode('You cannot access this resource because you do not have the appropriate permissions.', ExpressKitErrorCode_1.default.NotAllowedToReviewLogs);
|
|
275
|
+
}
|
|
276
|
+
return [4 /*yield*/, (0, getLogReviewerLogs_1.default)({
|
|
277
|
+
pageNumber: pageNumber,
|
|
278
|
+
filters: filters,
|
|
279
|
+
countDocuments: countDocuments,
|
|
280
|
+
logCollection: _logCollection,
|
|
281
|
+
})];
|
|
282
|
+
case 2:
|
|
283
|
+
response = _c.sent();
|
|
284
|
+
// Return response
|
|
285
|
+
return [2 /*return*/, response];
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}); },
|
|
289
|
+
}));
|
|
290
|
+
};
|
|
291
|
+
exports.default = initServer;
|
|
292
|
+
//# sourceMappingURL=initServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initServer.js","sourceRoot":"","sources":["../../src/helpers/initServer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,sBAAsB;AACtB,6CAQsB;AAEtB,wBAAwB;AACxB,sEAAgD;AAChD,4EAAsD;AAEtD,sBAAsB;AACtB,qFAA+D;AAG/D,0CAA0C;AAC1C,IAAI,cAA+B,CAAC;AAEpC,8DAA8D;AAC9D,IAAI,gCAAmE,CAAC;AAExE,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAE5E;;;;;GAKG;AACI,IAAM,wBAAwB,GAAG;IACtC,OAAO,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,IAAI,CAAC;AAChC,CAAC,CAAC;AAFW,QAAA,wBAAwB,4BAEnC;AAEF;;;;;GAKG;AACI,IAAM,0CAA0C,GAAG;IACxD,OAAO,gCAAgC,aAAhC,gCAAgC,cAAhC,gCAAgC,GAAI,IAAI,CAAC;AAClD,CAAC,CAAC;AAFW,QAAA,0CAA0C,8CAErD;A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AAU,YAAA;gCACV,OAAO,SAAA;gCACP,cAAc,gBAAA;gCACd,aAAa,EAAE,cAAc;6BAC9B,CAAC,EAAA;;wBALI,QAAQ,GAAG,SAKf;wBAEF,kBAAkB;wBAClB,sBAAO,QAAQ,EAAC;;;aACjB;KACF,CAAC,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Perform a rudimentary parsing of the user's browser agent string
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
* @param userAgent the user's browser agent
|
|
5
|
+
* @returns user info
|
|
6
|
+
*/
|
|
7
|
+
declare const parseUserAgent: (userAgent: string) => {
|
|
8
|
+
browser: {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
};
|
|
12
|
+
device: {
|
|
13
|
+
isMobile: boolean;
|
|
14
|
+
os: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export default parseUserAgent;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Perform a rudimentary parsing of the user's browser agent string
|
|
5
|
+
* @author Gabe Abrams
|
|
6
|
+
* @param userAgent the user's browser agent
|
|
7
|
+
* @returns user info
|
|
8
|
+
*/
|
|
9
|
+
var parseUserAgent = function (userAgent) {
|
|
10
|
+
/* ------------- Browser ------------ */
|
|
11
|
+
var browser = {
|
|
12
|
+
name: 'Unknown',
|
|
13
|
+
version: 'Unknown',
|
|
14
|
+
};
|
|
15
|
+
// Parse user agent
|
|
16
|
+
var verOffset;
|
|
17
|
+
var nameOffset;
|
|
18
|
+
if ((verOffset = userAgent.indexOf('Opera')) !== -1) {
|
|
19
|
+
// In Opera, the true version is after 'Opera' or after 'Version'
|
|
20
|
+
browser = {
|
|
21
|
+
name: 'Opera',
|
|
22
|
+
version: userAgent.substring(verOffset + 6),
|
|
23
|
+
};
|
|
24
|
+
if ((verOffset = userAgent.indexOf('Version')) !== -1) {
|
|
25
|
+
browser.version = userAgent.substring(verOffset + 8);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else if ((verOffset = userAgent.indexOf('MSIE')) !== -1) {
|
|
29
|
+
// In MSIE, the true version is after 'MSIE' in userAgent
|
|
30
|
+
browser = {
|
|
31
|
+
name: 'Internet Explorer',
|
|
32
|
+
version: userAgent.substring(verOffset + 5),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
else if ((verOffset = userAgent.indexOf('Chrome')) !== -1) {
|
|
36
|
+
// In Chrome, the true version is after 'Chrome'
|
|
37
|
+
browser = {
|
|
38
|
+
name: 'Chrome',
|
|
39
|
+
version: userAgent.substring(verOffset + 7),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
else if ((verOffset = userAgent.indexOf('Safari')) !== -1) {
|
|
43
|
+
// In Safari, the true version is after 'Safari' or after 'Version'
|
|
44
|
+
browser = {
|
|
45
|
+
name: 'Safari',
|
|
46
|
+
version: userAgent.substring(verOffset + 7),
|
|
47
|
+
};
|
|
48
|
+
if ((verOffset = userAgent.indexOf('Version')) !== -1) {
|
|
49
|
+
browser.version = userAgent.substring(verOffset + 8);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if ((verOffset = userAgent.indexOf('Firefox')) != -1) {
|
|
53
|
+
// In Firefox, the true version is after 'Firefox'
|
|
54
|
+
browser = {
|
|
55
|
+
name: 'Firefox',
|
|
56
|
+
version: userAgent.substring(verOffset + 8),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
else if ((nameOffset = userAgent.lastIndexOf(' ') + 1)
|
|
60
|
+
< (verOffset = userAgent.lastIndexOf('/'))) {
|
|
61
|
+
browser = {
|
|
62
|
+
name: userAgent.substring(nameOffset, verOffset),
|
|
63
|
+
version: userAgent.substring(verOffset + 1),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
// Postprocess version
|
|
67
|
+
// trim the fullVersion string at semicolon/space if present
|
|
68
|
+
var ix;
|
|
69
|
+
if ((ix = browser.version.indexOf(';')) !== -1) {
|
|
70
|
+
browser.version = browser.version.substring(0, ix);
|
|
71
|
+
}
|
|
72
|
+
if ((ix = browser.version.indexOf(' ')) !== -1) {
|
|
73
|
+
browser.version = browser.version.substring(0, ix);
|
|
74
|
+
}
|
|
75
|
+
/* ------------- Device ------------- */
|
|
76
|
+
// Detect os
|
|
77
|
+
var os = 'Unknown';
|
|
78
|
+
if (userAgent.includes('Linux')) {
|
|
79
|
+
os = 'Linux';
|
|
80
|
+
}
|
|
81
|
+
else if (userAgent.includes('like Mac')) {
|
|
82
|
+
os = 'iOS';
|
|
83
|
+
}
|
|
84
|
+
else if (userAgent.includes('Mac')) {
|
|
85
|
+
os = 'Mac';
|
|
86
|
+
}
|
|
87
|
+
else if (userAgent.includes('Android')) {
|
|
88
|
+
os = 'Android';
|
|
89
|
+
}
|
|
90
|
+
else if (userAgent.includes('Win')) {
|
|
91
|
+
os = 'Win';
|
|
92
|
+
}
|
|
93
|
+
// Check if mobile
|
|
94
|
+
var isMobile = !!userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/);
|
|
95
|
+
// Device
|
|
96
|
+
var device = {
|
|
97
|
+
isMobile: isMobile,
|
|
98
|
+
os: os,
|
|
99
|
+
};
|
|
100
|
+
/* ------------- Finish ------------- */
|
|
101
|
+
// Return info
|
|
102
|
+
return {
|
|
103
|
+
browser: browser,
|
|
104
|
+
device: device,
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
exports.default = parseUserAgent;
|
|
108
|
+
//# sourceMappingURL=parseUserAgent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseUserAgent.js","sourceRoot":"","sources":["../../src/helpers/parseUserAgent.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,IAAM,cAAc,GAAG,UAAC,SAAiB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OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAC/C,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,wCAAwC;IAExC,YAAY;IACZ,IAAI,EAAE,GAAG,SAAS,CAAC;IACnB,IAAI,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAChC,EAAE,GAAG,OAAO,CAAC;IACf,CAAC;SAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1C,EAAE,GAAG,KAAK,CAAC;IACb,CAAC;SAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,EAAE,GAAG,KAAK,CAAC;IACb,CAAC;SAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QACzC,EAAE,GAAG,SAAS,CAAC;IACjB,CAAC;SAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACrC,EAAE,GAAG,KAAK,CAAC;IACb,CAAC;IAED,kBAAkB;IAClB,IAAM,QAAQ,GAAG,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAE5E,SAAS;IACT,IAAM,MAAM,GAAG;QACb,QAAQ,UAAA;QACR,EAAE,IAAA;KACH,CAAC;IAEF,wCAAwC;IAExC,cAAc;IACd,OAAO;QACL,OAAO,SAAA;QACP,MAAM,QAAA;KACP,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Visit an endpoint on another server
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
* @param opts object containing all arguments
|
|
5
|
+
* @param opts.method the method of the endpoint
|
|
6
|
+
* @param opts.path the path of the other server's endpoint
|
|
7
|
+
* @param opts.host the host of the other server
|
|
8
|
+
* @param [opts.params={}] query/body parameters to include
|
|
9
|
+
* @param [opts.responseType=JSON] the response type from the other server
|
|
10
|
+
*/
|
|
11
|
+
declare const visitEndpointOnAnotherServer: (opts: {
|
|
12
|
+
method: "GET" | "POST" | "DELETE" | "PUT";
|
|
13
|
+
path: string;
|
|
14
|
+
host: string;
|
|
15
|
+
params?: { [key in string]: any; };
|
|
16
|
+
responseType?: "JSON" | "Text";
|
|
17
|
+
}) => Promise<any>;
|
|
18
|
+
export default visitEndpointOnAnotherServer;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
// Import dce-reactkit
|
|
43
|
+
var dce_reactkit_1 = require("dce-reactkit");
|
|
44
|
+
// Import shared types
|
|
45
|
+
var sendServerToServerRequest_1 = __importDefault(require("./sendServerToServerRequest"));
|
|
46
|
+
/*------------------------------------------------------------------------*/
|
|
47
|
+
/* -------------------------------- Main -------------------------------- */
|
|
48
|
+
/*------------------------------------------------------------------------*/
|
|
49
|
+
/**
|
|
50
|
+
* Visit an endpoint on another server
|
|
51
|
+
* @author Gabe Abrams
|
|
52
|
+
* @param opts object containing all arguments
|
|
53
|
+
* @param opts.method the method of the endpoint
|
|
54
|
+
* @param opts.path the path of the other server's endpoint
|
|
55
|
+
* @param opts.host the host of the other server
|
|
56
|
+
* @param [opts.params={}] query/body parameters to include
|
|
57
|
+
* @param [opts.responseType=JSON] the response type from the other server
|
|
58
|
+
*/
|
|
59
|
+
var visitEndpointOnAnotherServer = function (opts) { return __awaiter(void 0, void 0, void 0, function () {
|
|
60
|
+
var response, body;
|
|
61
|
+
return __generator(this, function (_a) {
|
|
62
|
+
switch (_a.label) {
|
|
63
|
+
case 0: return [4 /*yield*/, (0, sendServerToServerRequest_1.default)({
|
|
64
|
+
path: opts.path,
|
|
65
|
+
host: opts.host,
|
|
66
|
+
method: opts.method,
|
|
67
|
+
params: opts.params,
|
|
68
|
+
responseType: opts.responseType,
|
|
69
|
+
})];
|
|
70
|
+
case 1:
|
|
71
|
+
response = _a.sent();
|
|
72
|
+
// Check for failure
|
|
73
|
+
if (!response || !response.body) {
|
|
74
|
+
throw new dce_reactkit_1.ErrorWithCode('We didn\'t get a response from the other server. Please check the network between the two connection.', dce_reactkit_1.ReactKitErrorCode.NoResponse);
|
|
75
|
+
}
|
|
76
|
+
if (!response.body.success) {
|
|
77
|
+
// Other errors
|
|
78
|
+
throw new dce_reactkit_1.ErrorWithCode((response.body.message
|
|
79
|
+
|| 'An unknown error occurred. Please contact an admin.'), (response.body.code
|
|
80
|
+
|| dce_reactkit_1.ReactKitErrorCode.NoCode));
|
|
81
|
+
}
|
|
82
|
+
body = response.body.body;
|
|
83
|
+
// Return
|
|
84
|
+
return [2 /*return*/, body];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}); };
|
|
88
|
+
exports.default = visitEndpointOnAnotherServer;
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
|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Sends and retries an http request
|
|
3
|
+
* @author Gabriel Abrams
|
|
4
|
+
* @param opts object containing all arguments
|
|
5
|
+
* @param opts.path path to send request to
|
|
6
|
+
* @param [opts.host] host to send request to
|
|
7
|
+
* @param [opts.method=GET] http method to use
|
|
8
|
+
* @param [opts.params] body/data to include in the request
|
|
9
|
+
* @param [opts.responseType=JSON] expected response type
|
|
10
|
+
* @returns { body, status, headers } on success
|
|
11
|
+
*/
|
|
12
|
+
declare const sendServerToServerRequest: (opts: {
|
|
13
|
+
path: string;
|
|
14
|
+
host?: string;
|
|
15
|
+
method?: ("GET" | "POST" | "PUT" | "DELETE");
|
|
16
|
+
params?: { [k in string]: any; };
|
|
17
|
+
responseType?: "Text" | "JSON";
|
|
18
|
+
}) => Promise<{
|
|
19
|
+
body: any;
|
|
20
|
+
status: number;
|
|
21
|
+
headers: { [k in string]: any; };
|
|
22
|
+
}>;
|
|
23
|
+
export default sendServerToServerRequest;
|