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.
Files changed (99) hide show
  1. package/.eslintrc.js +93 -0
  2. package/LICENSE +21 -0
  3. package/README.md +17 -0
  4. package/genEncodedSecret.ts +107 -0
  5. package/genSalt.ts +15 -0
  6. package/lib/constants/LOG_REVIEW_PAGE_SIZE.d.ts +6 -0
  7. package/lib/constants/LOG_REVIEW_PAGE_SIZE.js +9 -0
  8. package/lib/constants/LOG_REVIEW_PAGE_SIZE.js.map +1 -0
  9. package/lib/constants/LOG_REVIEW_ROUTE_PATH_PREFIX.d.ts +6 -0
  10. package/lib/constants/LOG_REVIEW_ROUTE_PATH_PREFIX.js +13 -0
  11. package/lib/constants/LOG_REVIEW_ROUTE_PATH_PREFIX.js.map +1 -0
  12. package/lib/constants/LOG_REVIEW_STATUS_ROUTE.d.ts +7 -0
  13. package/lib/constants/LOG_REVIEW_STATUS_ROUTE.js +14 -0
  14. package/lib/constants/LOG_REVIEW_STATUS_ROUTE.js.map +1 -0
  15. package/lib/constants/LOG_ROUTE_PATH.d.ts +6 -0
  16. package/lib/constants/LOG_ROUTE_PATH.js +13 -0
  17. package/lib/constants/LOG_ROUTE_PATH.js.map +1 -0
  18. package/lib/constants/ROUTE_PATH_PREFIX.d.ts +6 -0
  19. package/lib/constants/ROUTE_PATH_PREFIX.js +9 -0
  20. package/lib/constants/ROUTE_PATH_PREFIX.js.map +1 -0
  21. package/lib/errors/ErrorWithCode.d.ts +9 -0
  22. package/lib/errors/ErrorWithCode.js +33 -0
  23. package/lib/errors/ErrorWithCode.js.map +1 -0
  24. package/lib/helpers/addDBEditorEndpoints/generateEndpointPath.d.ts +9 -0
  25. package/lib/helpers/addDBEditorEndpoints/generateEndpointPath.js +17 -0
  26. package/lib/helpers/addDBEditorEndpoints/generateEndpointPath.js.map +1 -0
  27. package/lib/helpers/addDBEditorEndpoints/index.d.ts +41 -0
  28. package/lib/helpers/addDBEditorEndpoints/index.js +134 -0
  29. package/lib/helpers/addDBEditorEndpoints/index.js.map +1 -0
  30. package/lib/helpers/dataSigner.d.ts +40 -0
  31. package/lib/helpers/dataSigner.js +242 -0
  32. package/lib/helpers/dataSigner.js.map +1 -0
  33. package/lib/helpers/genRouteHandler.d.ts +75 -0
  34. package/lib/helpers/genRouteHandler.js +662 -0
  35. package/lib/helpers/genRouteHandler.js.map +1 -0
  36. package/lib/helpers/getLogReviewerLogs.d.ts +27 -0
  37. package/lib/helpers/getLogReviewerLogs.js +238 -0
  38. package/lib/helpers/getLogReviewerLogs.js.map +1 -0
  39. package/lib/helpers/handleError.d.ts +18 -0
  40. package/lib/helpers/handleError.js +51 -0
  41. package/lib/helpers/handleError.js.map +1 -0
  42. package/lib/helpers/handleSuccess.d.ts +8 -0
  43. package/lib/helpers/handleSuccess.js +20 -0
  44. package/lib/helpers/handleSuccess.js.map +1 -0
  45. package/lib/helpers/initCrossServerCredentialCollection.d.ts +11 -0
  46. package/lib/helpers/initCrossServerCredentialCollection.js +15 -0
  47. package/lib/helpers/initCrossServerCredentialCollection.js.map +1 -0
  48. package/lib/helpers/initLogCollection.d.ts +11 -0
  49. package/lib/helpers/initLogCollection.js +26 -0
  50. package/lib/helpers/initLogCollection.js.map +1 -0
  51. package/lib/helpers/initServer.d.ts +45 -0
  52. package/lib/helpers/initServer.js +292 -0
  53. package/lib/helpers/initServer.js.map +1 -0
  54. package/lib/helpers/parseUserAgent.d.ts +17 -0
  55. package/lib/helpers/parseUserAgent.js +108 -0
  56. package/lib/helpers/parseUserAgent.js.map +1 -0
  57. package/lib/helpers/visitEndpointOnAnotherServer/index.d.ts +18 -0
  58. package/lib/helpers/visitEndpointOnAnotherServer/index.js +89 -0
  59. package/lib/helpers/visitEndpointOnAnotherServer/index.js.map +1 -0
  60. package/lib/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.d.ts +23 -0
  61. package/lib/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.js +236 -0
  62. package/lib/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.js.map +1 -0
  63. package/lib/html/genErrorPage.d.ts +19 -0
  64. package/lib/html/genErrorPage.js +27 -0
  65. package/lib/html/genErrorPage.js.map +1 -0
  66. package/lib/html/genInfoPage.d.ts +13 -0
  67. package/lib/html/genInfoPage.js +16 -0
  68. package/lib/html/genInfoPage.js.map +1 -0
  69. package/lib/index.d.ts +11 -0
  70. package/lib/index.js +68 -0
  71. package/lib/index.js.map +1 -0
  72. package/lib/types/CrossServerCredential.d.ts +11 -0
  73. package/lib/types/CrossServerCredential.js +3 -0
  74. package/lib/types/CrossServerCredential.js.map +1 -0
  75. package/lib/types/ExpressKitErrorCode.d.ts +31 -0
  76. package/lib/types/ExpressKitErrorCode.js +38 -0
  77. package/lib/types/ExpressKitErrorCode.js.map +1 -0
  78. package/package.json +53 -0
  79. package/src/constants/LOG_REVIEW_PAGE_SIZE.ts +7 -0
  80. package/src/errors/ErrorWithCode.tsx +15 -0
  81. package/src/helpers/addDBEditorEndpoints/generateEndpointPath.ts +16 -0
  82. package/src/helpers/addDBEditorEndpoints/index.ts +130 -0
  83. package/src/helpers/dataSigner.ts +319 -0
  84. package/src/helpers/genRouteHandler.ts +920 -0
  85. package/src/helpers/getLogReviewerLogs.ts +259 -0
  86. package/src/helpers/handleError.ts +66 -0
  87. package/src/helpers/handleSuccess.ts +18 -0
  88. package/src/helpers/initCrossServerCredentialCollection.ts +19 -0
  89. package/src/helpers/initLogCollection.ts +30 -0
  90. package/src/helpers/initServer.ts +283 -0
  91. package/src/helpers/parseUserAgent.ts +108 -0
  92. package/src/helpers/visitEndpointOnAnotherServer/index.ts +70 -0
  93. package/src/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.ts +257 -0
  94. package/src/html/genErrorPage.ts +144 -0
  95. package/src/html/genInfoPage.ts +101 -0
  96. package/src/index.ts +125 -0
  97. package/src/types/CrossServerCredential.ts +16 -0
  98. package/src/types/ExpressKitErrorCode.ts +37 -0
  99. package/tsconfig.json +19 -0
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Sign a request and get the new request params
3
+ * @author Gabe Abrams
4
+ * @param opts object containing all arguments
5
+ * @param opts.method the method to sign
6
+ * @param opts.path the http request path
7
+ * @param opts.params the data in the body to sign
8
+ * @param opts.key the dcekit key to sign with
9
+ * @param opts.secret the dcekit secret to sign with
10
+ * @return augmented params for the request, including a signature, timestamp, and key
11
+ */
12
+ export declare const signRequest: (opts: {
13
+ method: string;
14
+ path: string;
15
+ params: {
16
+ [key: string]: any;
17
+ };
18
+ key: string;
19
+ secret: string;
20
+ }) => Promise<{
21
+ [key: string]: any;
22
+ }>;
23
+ /**
24
+ * Validate a signed request. Throws an error if invalid
25
+ * @author Gabe Abrams
26
+ * @param opts object containing all arguments
27
+ * @param opts.method the method of the data validate
28
+ * @param opts.path the http request path to validate
29
+ * @param opts.scope the name of the scope to validate
30
+ * @param opts.params the request data to validate
31
+ * @returns parsed and validated params
32
+ */
33
+ export declare const validateSignedRequest: (opts: {
34
+ method: string;
35
+ path: string;
36
+ scope: string;
37
+ params: {
38
+ [key: string]: any;
39
+ };
40
+ }) => Promise<void>;
@@ -0,0 +1,242 @@
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.validateSignedRequest = exports.signRequest = void 0;
54
+ // Import dce-reactkit
55
+ var dce_reactkit_1 = require("dce-reactkit");
56
+ // Import oauth
57
+ var oauth_signature_1 = __importDefault(require("oauth-signature"));
58
+ // Import crypto
59
+ var crypto_1 = __importDefault(require("crypto"));
60
+ // Import shared helpers
61
+ var initServer_1 = require("./initServer");
62
+ // Import shared types
63
+ var ExpressKitErrorCode_1 = __importDefault(require("../types/ExpressKitErrorCode"));
64
+ /*------------------------------------------------------------------------*/
65
+ /* ------------------------------- Helpers ------------------------------ */
66
+ /*------------------------------------------------------------------------*/
67
+ /**
68
+ * Generate an oauth signature
69
+ * @author Gabe Abrams
70
+ * @param opts object containing all arguments
71
+ * @param opts.method the http method
72
+ * @param opts.path the http request path
73
+ * @param opts.params the data in the body to sign
74
+ * @param opts.secret the secret to sign with
75
+ * @return the signature
76
+ */
77
+ var genSignature = function (opts) { return __awaiter(void 0, void 0, void 0, function () {
78
+ var method, path, params, secret, keys, orderedParams;
79
+ return __generator(this, function (_a) {
80
+ method = opts.method, path = opts.path, params = opts.params, secret = opts.secret;
81
+ keys = Object.keys(params !== null && params !== void 0 ? params : {});
82
+ keys.sort();
83
+ orderedParams = {};
84
+ keys.forEach(function (key) {
85
+ // Skip oauth_signature
86
+ if (key === 'oauth_signature') {
87
+ return;
88
+ }
89
+ // Add the param
90
+ orderedParams[key] = (params !== null && params !== void 0 ? params : {})[key];
91
+ });
92
+ // Generate the signature
93
+ return [2 /*return*/, decodeURIComponent(oauth_signature_1.default.generate(method !== null && method !== void 0 ? method : 'GET', path !== null && path !== void 0 ? path : 'no-path', orderedParams, secret))];
94
+ });
95
+ }); };
96
+ /**
97
+ * Decrypt an encrypted string using a secret
98
+ * @author Gabe Abrams
99
+ * @param str the encrypted string
100
+ * @return the decrypted string
101
+ */
102
+ var decrypt = function (encryptedPack) { return __awaiter(void 0, void 0, void 0, function () {
103
+ var DCEKIT_CRED_ENCODING_SALT, _a, ciphertext, iv, tag, decipher, str;
104
+ return __generator(this, function (_b) {
105
+ DCEKIT_CRED_ENCODING_SALT = process.env.DCEKIT_CRED_ENCODING_SALT;
106
+ if (!DCEKIT_CRED_ENCODING_SALT) {
107
+ throw new dce_reactkit_1.ErrorWithCode('Could not decrypt a string because the encryption salt was not set.', ExpressKitErrorCode_1.default.CrossServerNoCredentialEncodingSalt);
108
+ }
109
+ _a = JSON.parse(decodeURIComponent(encryptedPack)), ciphertext = _a.ciphertext, iv = _a.iv, tag = _a.tag;
110
+ decipher = crypto_1.default.createDecipheriv('aes-256-gcm', Buffer.from(DCEKIT_CRED_ENCODING_SALT, 'base64'), Buffer.from(iv, 'base64'));
111
+ // Set the authentication tag
112
+ decipher.setAuthTag(Buffer.from(tag, 'base64'));
113
+ str = decipher.update(ciphertext, 'base64', 'utf8');
114
+ str += decipher.final('utf8');
115
+ // Return the decrypted string
116
+ return [2 /*return*/, str];
117
+ });
118
+ }); };
119
+ /*------------------------------------------------------------------------*/
120
+ /* ------------------------------- Signing ------------------------------ */
121
+ /*------------------------------------------------------------------------*/
122
+ /**
123
+ * Sign a request and get the new request params
124
+ * @author Gabe Abrams
125
+ * @param opts object containing all arguments
126
+ * @param opts.method the method to sign
127
+ * @param opts.path the http request path
128
+ * @param opts.params the data in the body to sign
129
+ * @param opts.key the dcekit key to sign with
130
+ * @param opts.secret the dcekit secret to sign with
131
+ * @return augmented params for the request, including a signature, timestamp, and key
132
+ */
133
+ var signRequest = function (opts) { return __awaiter(void 0, void 0, void 0, function () {
134
+ var method, path, params, key, secret, augmentedParams, signature;
135
+ return __generator(this, function (_a) {
136
+ switch (_a.label) {
137
+ case 0:
138
+ method = opts.method.toUpperCase();
139
+ path = opts.path, params = opts.params, key = opts.key, secret = opts.secret;
140
+ augmentedParams = __assign(__assign({}, params), { oauth_consumer_key: key, oauth_nonce: Math.random().toString(36), oauth_timestamp: Date.now() });
141
+ return [4 /*yield*/, genSignature({
142
+ method: method,
143
+ path: path,
144
+ params: params,
145
+ secret: secret,
146
+ })];
147
+ case 1:
148
+ signature = _a.sent();
149
+ // Add signature to the augmented params
150
+ augmentedParams.oauth_signature = signature;
151
+ // Return the augmented params
152
+ return [2 /*return*/, augmentedParams];
153
+ }
154
+ });
155
+ }); };
156
+ exports.signRequest = signRequest;
157
+ /**
158
+ * Validate a signed request. Throws an error if invalid
159
+ * @author Gabe Abrams
160
+ * @param opts object containing all arguments
161
+ * @param opts.method the method of the data validate
162
+ * @param opts.path the http request path to validate
163
+ * @param opts.scope the name of the scope to validate
164
+ * @param opts.params the request data to validate
165
+ * @returns parsed and validated params
166
+ */
167
+ var validateSignedRequest = function (opts) { return __awaiter(void 0, void 0, void 0, function () {
168
+ var signature, timestamp, key, method, path, params, scope, crossServerCredentialCollection, crossServerCredentialMatches, crossServerCredential, allowedScopes, secret, paramsToSign, expectedSignature, elapsedMs;
169
+ return __generator(this, function (_a) {
170
+ switch (_a.label) {
171
+ case 0:
172
+ /* ---------- Collect Info ---------- */
173
+ // Get the signature
174
+ if (!opts.params.oauth_signature) {
175
+ throw new dce_reactkit_1.ErrorWithCode('Could not validate a cross-server request there was no oauth signature.', ExpressKitErrorCode_1.default.CrossServerMissingSignedRequestInfo);
176
+ }
177
+ signature = opts.params.oauth_signature;
178
+ // Get the timestamp
179
+ if (
180
+ // No timestamp
181
+ !opts.params.oauth_timestamp
182
+ // Invalid timestamp
183
+ || Number.isNaN(Number.parseInt(opts.params.oauth_timestamp, 10))) {
184
+ throw new dce_reactkit_1.ErrorWithCode('Could not validate a cross-server request there was no valid oauth timestamp.', ExpressKitErrorCode_1.default.CrossServerMissingSignedRequestInfo);
185
+ }
186
+ timestamp = Number.parseInt(opts.params.oauth_timestamp, 10);
187
+ // Get the key
188
+ if (!opts.params.oauth_consumer_key) {
189
+ throw new dce_reactkit_1.ErrorWithCode('Could not validate a cross-server request there was no oauth consumer key.', ExpressKitErrorCode_1.default.CrossServerMissingSignedRequestInfo);
190
+ }
191
+ key = opts.params.oauth_consumer_key;
192
+ method = opts.method, path = opts.path, params = opts.params, scope = opts.scope;
193
+ crossServerCredentialCollection = (0, initServer_1.internalGetCrossServerCredentialCollection)();
194
+ if (!crossServerCredentialCollection) {
195
+ throw new dce_reactkit_1.ErrorWithCode('Could not validate a cross-server request because the cross-server credential collection was not ready in time.', ExpressKitErrorCode_1.default.SignedRequestInvalidCollection);
196
+ }
197
+ return [4 /*yield*/, crossServerCredentialCollection.find({ key: key })];
198
+ case 1:
199
+ crossServerCredentialMatches = _a.sent();
200
+ if (!crossServerCredentialMatches || crossServerCredentialMatches.length === 0) {
201
+ throw new dce_reactkit_1.ErrorWithCode('Could not validate a cross-server request because the credential was not found.', ExpressKitErrorCode_1.default.SignedRequestInvalidCredential);
202
+ }
203
+ crossServerCredential = crossServerCredentialMatches[0];
204
+ allowedScopes = crossServerCredential.scopes;
205
+ if (!allowedScopes || !Array.isArray(allowedScopes)) {
206
+ throw new dce_reactkit_1.ErrorWithCode('Could not validate a cross-server request because the credential does not have access to any scopes.', ExpressKitErrorCode_1.default.SignedRequestInvalidScope);
207
+ }
208
+ if (!allowedScopes.includes(scope)) {
209
+ throw new dce_reactkit_1.ErrorWithCode('Could not validate a cross-server request because the required scope was not approved for the credential.', ExpressKitErrorCode_1.default.SignedRequestInvalidScope);
210
+ }
211
+ return [4 /*yield*/, decrypt(crossServerCredential.encodedeSecret)];
212
+ case 2:
213
+ secret = _a.sent();
214
+ paramsToSign = __assign({}, params);
215
+ Object.keys(paramsToSign).forEach(function (key) {
216
+ // Delete oauth params
217
+ if (key.startsWith('oauth_')) {
218
+ delete paramsToSign[key];
219
+ }
220
+ });
221
+ return [4 /*yield*/, genSignature({
222
+ method: method,
223
+ path: path,
224
+ params: paramsToSign,
225
+ secret: secret,
226
+ })];
227
+ case 3:
228
+ expectedSignature = _a.sent();
229
+ // Make sure the signatures match
230
+ if (signature !== expectedSignature) {
231
+ throw new dce_reactkit_1.ErrorWithCode('Could not validate a cross-server request because the signature did not match.', ExpressKitErrorCode_1.default.SignedRequestInvalidSignature);
232
+ }
233
+ elapsedMs = Math.abs(Date.now() - timestamp);
234
+ if (elapsedMs > dce_reactkit_1.MINUTE_IN_MS) {
235
+ throw new dce_reactkit_1.ErrorWithCode('Could not validate a cross-server request because the request was too old.', ExpressKitErrorCode_1.default.SignedRequestInvalidTimestamp);
236
+ }
237
+ return [2 /*return*/];
238
+ }
239
+ });
240
+ }); };
241
+ exports.validateSignedRequest = validateSignedRequest;
242
+ //# sourceMappingURL=dataSigner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataSigner.js","sourceRoot":"","sources":["../../src/helpers/dataSigner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sBAAsB;AACtB,6CAGsB;AAEtB,eAAe;AACf,oEAAoC;AAEpC,gBAAgB;AAChB,kDAA4B;AAE5B,wBAAwB;AACxB,2CAA0E;AAE1E,sBAAsB;AACtB,qFAA+D;AAG/D,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAE5E;;;;;;;;;GASG;AACH,IAAM,YAAY,GAAG,UACnB,IAKC;;;QAIC,MAAM,GAIJ,IAAI,OAJA,EACN,IAAI,GAGF,IAAI,KAHF,EACJ,MAAM,GAEJ,IAAI,OAFA,EACN,MAAM,GACJ,IAAI,OADA,CACC;QAGH,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,EAAE,CAAC;QACN,aAAa,GAEf,EAAE,CAAC;QACP,IAAI,CAAC,OAAO,CAAC,UAAC,GAAG;YACf,uBAAuB;YACvB,IAAI,GAAG,KAAK,iBAAiB,EAAE,CAAC;gBAC9B,OAAO;YACT,CAAC;YAED,gBAAgB;YAChB,aAAa,CAAC,GAAG,CAA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, ParamType } from 'dce-reactkit';
2
+ /**
3
+ * Generate an express API route handler
4
+ * @author Gabe Abrams
5
+ * @param opts object containing all arguments
6
+ * @param opts.paramTypes map containing the types for each parameter that is
7
+ * included in the request (map: param name => type)
8
+ * @param opts.handler function that processes the request
9
+ * @param [opts.crossServerScope] the scope associated with this endpoint.
10
+ * If defined, this is a cross-server endpoint, which will never
11
+ * have any launch data, will never check Canvas roles or launch status, and will
12
+ * instead use scopes and reactkit credentials to sign and validate requests.
13
+ * Never start the path with /api/ttm or /api/admin if the endpoint is a cross-server
14
+ * endpoint because those roles will not be validated
15
+ * @param [opts.skipSessionCheck=true if crossServerScope defined] if true, skip
16
+ * the session check (allow users to not be logged in and launched via LTI).
17
+ * If crossServerScope is defined, this is always true
18
+ * @param [opts.unhandledErrorMessagePrefix] if included, when an error that
19
+ * is not of type ErrorWithCode is thrown, the client will receive an error
20
+ * where the error message is prefixed with this string. For example,
21
+ * if unhandledErrorMessagePrefix is
22
+ * 'While saving progress, we encountered an error:'
23
+ * and the error is 'progressInfo is not an object',
24
+ * the client will receive an error with the message
25
+ * 'While saving progress, we encountered an error: progressInfo is not an object'
26
+ * @returns express route handler that takes the following arguments:
27
+ * params (map: param name => value),
28
+ * req (express request object),
29
+ * next (express next function),
30
+ * send (a function that sends a string to the client),
31
+ * redirect (takes a url and redirects the user to that url),
32
+ * renderErrorPage (shows a static error page to the user),
33
+ * renderInfoPage (shows a static info page to the user),
34
+ * renderCustomHTML (renders custom html and sends it to the user),
35
+ * and returns the value to send to the client as a JSON API response, or
36
+ * calls next() or redirect(...) or send(...) or renderErrorPage(...).
37
+ * Note: params also has userId, userFirstName,
38
+ * userLastName, userEmail, userAvatarURL, isLearner, isTTM, isAdmin,
39
+ * and any other variables that
40
+ * are directly added to the session, if the user does have a session.
41
+ */
42
+ declare const genRouteHandler: (opts: {
43
+ paramTypes?: {
44
+ [k: string]: ParamType;
45
+ };
46
+ handler: (opts: {
47
+ params: {
48
+ [k: string]: any;
49
+ };
50
+ req: any;
51
+ next: () => void;
52
+ redirect: (pathOrURL: string) => void;
53
+ send: (text: string, status?: number) => void;
54
+ renderErrorPage: (opts?: {
55
+ title?: string;
56
+ description?: string;
57
+ code?: string;
58
+ pageTitle?: string;
59
+ status?: number;
60
+ }) => void;
61
+ renderInfoPage: (opts: {
62
+ title: string;
63
+ body: string;
64
+ }) => void;
65
+ renderCustomHTML: (opts: {
66
+ html: string;
67
+ status?: number;
68
+ }) => void;
69
+ logServerEvent: LogFunction;
70
+ }) => any;
71
+ crossServerScope?: string;
72
+ skipSessionCheck?: boolean;
73
+ unhandledErrorMessagePrefix?: string;
74
+ }) => (req: any, res: any, next: () => void) => Promise<undefined>;
75
+ export default genRouteHandler;