dce-expresskit 4.0.0-beta.2
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 +84 -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 +231 -0
- package/lib/helpers/dataSigner.js.map +1 -0
- package/lib/helpers/genRouteHandler.d.ts +75 -0
- package/lib/helpers/genRouteHandler.js +661 -0
- package/lib/helpers/genRouteHandler.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 +43 -0
- package/lib/helpers/initServer.js +297 -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 +156 -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 +168 -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 +52 -0
- package/src/constants/LOG_REVIEW_ROUTE_PATH_PREFIX.ts +9 -0
- package/src/constants/LOG_REVIEW_STATUS_ROUTE.ts +10 -0
- package/src/constants/LOG_ROUTE_PATH.ts +9 -0
- package/src/constants/ROUTE_PATH_PREFIX.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 +296 -0
- package/src/helpers/genRouteHandler.ts +914 -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 +31 -0
- package/src/helpers/initServer.ts +284 -0
- package/src/helpers/parseUserAgent.ts +108 -0
- package/src/helpers/visitEndpointOnAnotherServer/index.ts +157 -0
- package/src/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.ts +164 -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,231 @@
|
|
|
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, crossServerCredentialCollection, crossServerCredential, allowedScopes, secret, 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;
|
|
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
|
+
crossServerCredential = _a.sent();
|
|
200
|
+
if (!crossServerCredential) {
|
|
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
|
+
allowedScopes = crossServerCredential.scopes;
|
|
204
|
+
if (!allowedScopes.includes(opts.scope)) {
|
|
205
|
+
throw new dce_reactkit_1.ErrorWithCode('Could not validate a cross-server request because the scope was not included.', ExpressKitErrorCode_1.default.SignedRequestInvalidScope);
|
|
206
|
+
}
|
|
207
|
+
return [4 /*yield*/, decrypt(crossServerCredential.encodedeSecret)];
|
|
208
|
+
case 2:
|
|
209
|
+
secret = _a.sent();
|
|
210
|
+
return [4 /*yield*/, genSignature({
|
|
211
|
+
method: method,
|
|
212
|
+
path: path,
|
|
213
|
+
params: params,
|
|
214
|
+
secret: secret,
|
|
215
|
+
})];
|
|
216
|
+
case 3:
|
|
217
|
+
expectedSignature = _a.sent();
|
|
218
|
+
// Make sure the signatures match
|
|
219
|
+
if (signature !== expectedSignature) {
|
|
220
|
+
throw new dce_reactkit_1.ErrorWithCode('Could not validate a cross-server request because the signature did not match.', ExpressKitErrorCode_1.default.SignedRequestInvalidSignature);
|
|
221
|
+
}
|
|
222
|
+
elapsedMs = Math.abs(Date.now() - timestamp);
|
|
223
|
+
if (elapsedMs < dce_reactkit_1.MINUTE_IN_MS) {
|
|
224
|
+
throw new dce_reactkit_1.ErrorWithCode('Could not validate a cross-server request because the request was too old.', ExpressKitErrorCode_1.default.SignedRequestInvalidTimestamp);
|
|
225
|
+
}
|
|
226
|
+
return [2 /*return*/];
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}); };
|
|
230
|
+
exports.validateSignedRequest = validateSignedRequest;
|
|
231
|
+
//# 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,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C,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;oBACxC,MAAM,IAAI,4BAAa,CACrB,+EAA+E,EAC/E,6BAAmB,CAAC,yBAAyB,CAC9C,CAAC;gBACJ,CAAC;gBAGc,qBAAM,OAAO,CAAC,qBAAqB,CAAC,cAAc,CAAC,EAAA;;gBAA5D,MAAM,GAAG,SAAmD;gBAKxC,qBAAM,YAAY,CAAC;wBAC3C,MAAM,QAAA;wBACN,IAAI,MAAA;wBACJ,MAAM,QAAA;wBACN,MAAM,QAAA;qBACP,CAAC,EAAA;;gBALI,iBAAiB,GAAG,SAKxB;gBAEF,iCAAiC;gBACjC,IAAI,SAAS,KAAK,iBAAiB,EAAE,CAAC;oBACpC,MAAM,IAAI,4BAAa,CACrB,gFAAgF,EAChF,6BAAmB,CAAC,6BAA6B,CAClD,CAAC;gBACJ,CAAC;gBAGK,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,CAAC;gBACnD,IAAI,SAAS,GAAG,2BAAY,EAAE,CAAC;oBAC7B,MAAM,IAAI,4BAAa,CACrB,4EAA4E,EAC5E,6BAAmB,CAAC,6BAA6B,CAClD,CAAC;gBACJ,CAAC;;;;KACF,CAAC;AA3GW,QAAA,qBAAqB,yBA2GhC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { LogFunction, 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;
|