dce-reactkit 3.7.11 → 3.7.14
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/dist/cjs/index.js +29 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/helpers/genRouteHandler.d.ts +14 -0
- package/dist/cjs/types/html/genInfoPage.d.ts +1 -0
- package/dist/esm/index.js +29 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/helpers/genRouteHandler.d.ts +14 -0
- package/dist/esm/types/html/genInfoPage.d.ts +1 -0
- package/dist/index.d.ts +14 -0
- package/package.json +2 -2
- package/src/helpers/genRouteHandler.ts +43 -0
- package/src/html/genInfoPage.ts +1 -0
package/dist/cjs/index.js
CHANGED
|
@@ -14056,6 +14056,7 @@ const genErrorPage = (opts = {}) => {
|
|
|
14056
14056
|
* @param opts object containing all arguments
|
|
14057
14057
|
* @param opts.title title of the info box
|
|
14058
14058
|
* @param opts.body a human-readable text body for the info alert
|
|
14059
|
+
* @returns the HTML for the info page
|
|
14059
14060
|
*/
|
|
14060
14061
|
const genInfoPage = (opts) => {
|
|
14061
14062
|
const { title, body, } = opts;
|
|
@@ -14254,6 +14255,14 @@ const parseUserAgent = (userAgent) => {
|
|
|
14254
14255
|
* @param opts.handler function that processes the request
|
|
14255
14256
|
* @param [opts.skipSessionCheck] if true, skip the session check (allow users
|
|
14256
14257
|
* to not be logged in and launched via LTI)
|
|
14258
|
+
* @param [opts.unhandledErrorMessagePrefix] if included, when an error that
|
|
14259
|
+
* is not of type ErrorWithCode is thrown, the client will receive an error
|
|
14260
|
+
* where the error message is prefixed with this string. For example,
|
|
14261
|
+
* if unhandledErrorMessagePrefix is
|
|
14262
|
+
* 'While saving progress, we encountered an error:'
|
|
14263
|
+
* and the error is 'progressInfo is not an object',
|
|
14264
|
+
* the client will receive an error with the message
|
|
14265
|
+
* 'While saving progress, we encountered an error: progressInfo is not an object'
|
|
14257
14266
|
* @returns express route handler that takes the following arguments:
|
|
14258
14267
|
* params (map: param name => value),
|
|
14259
14268
|
* req (express request object),
|
|
@@ -14262,6 +14271,7 @@ const parseUserAgent = (userAgent) => {
|
|
|
14262
14271
|
* redirect (takes a url and redirects the user to that url),
|
|
14263
14272
|
* renderErrorPage (shows a static error page to the user),
|
|
14264
14273
|
* renderInfoPage (shows a static info page to the user),
|
|
14274
|
+
* renderCustomHTML (renders custom html and sends it to the user),
|
|
14265
14275
|
* and returns the value to send to the client as a JSON API response, or
|
|
14266
14276
|
* calls next() or redirect(...) or send(...) or renderErrorPage(...).
|
|
14267
14277
|
* Note: params also has userId, userFirstName,
|
|
@@ -14773,6 +14783,17 @@ const genRouteHandler = (opts) => {
|
|
|
14773
14783
|
const html = genInfoPage(renderOpts);
|
|
14774
14784
|
send(html, 200);
|
|
14775
14785
|
};
|
|
14786
|
+
/**
|
|
14787
|
+
* Render custom HTML
|
|
14788
|
+
* @author Gabe Abrams
|
|
14789
|
+
* @param htmlOpts object containing all arguments
|
|
14790
|
+
* @param htmlOpts.html the HTML to send to the client
|
|
14791
|
+
* @param [ejsOpts.status=200] the http status code to send
|
|
14792
|
+
*/
|
|
14793
|
+
const renderCustomHTML = (htmlOpts) => {
|
|
14794
|
+
var _a;
|
|
14795
|
+
send(htmlOpts.html, (_a = htmlOpts.status) !== null && _a !== void 0 ? _a : 200);
|
|
14796
|
+
};
|
|
14776
14797
|
// Call the handler
|
|
14777
14798
|
try {
|
|
14778
14799
|
const results = yield opts.handler({
|
|
@@ -14786,6 +14807,7 @@ const genRouteHandler = (opts) => {
|
|
|
14786
14807
|
redirect,
|
|
14787
14808
|
renderErrorPage,
|
|
14788
14809
|
renderInfoPage,
|
|
14810
|
+
renderCustomHTML,
|
|
14789
14811
|
logServerEvent,
|
|
14790
14812
|
});
|
|
14791
14813
|
// Send results to client (only if next wasn't called)
|
|
@@ -14794,6 +14816,13 @@ const genRouteHandler = (opts) => {
|
|
|
14794
14816
|
}
|
|
14795
14817
|
}
|
|
14796
14818
|
catch (err) {
|
|
14819
|
+
// Prefix error message if needed
|
|
14820
|
+
if (opts.unhandledErrorMessagePrefix
|
|
14821
|
+
&& err instanceof Error
|
|
14822
|
+
&& err.message
|
|
14823
|
+
&& err.name !== 'ErrorWithCode') {
|
|
14824
|
+
err.message = `${opts.unhandledErrorMessagePrefix.trim()} ${err.message.trim()}`;
|
|
14825
|
+
}
|
|
14797
14826
|
// Send error to client (only if next wasn't called)
|
|
14798
14827
|
if (!responseSent) {
|
|
14799
14828
|
handleError(res, err);
|