dce-reactkit 3.7.12 → 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 +1 -1
- package/src/helpers/genRouteHandler.ts +43 -0
- package/src/html/genInfoPage.ts +1 -0
|
@@ -9,6 +9,14 @@ import LogFunction from '../types/LogFunction';
|
|
|
9
9
|
* @param opts.handler function that processes the request
|
|
10
10
|
* @param [opts.skipSessionCheck] if true, skip the session check (allow users
|
|
11
11
|
* to not be logged in and launched via LTI)
|
|
12
|
+
* @param [opts.unhandledErrorMessagePrefix] if included, when an error that
|
|
13
|
+
* is not of type ErrorWithCode is thrown, the client will receive an error
|
|
14
|
+
* where the error message is prefixed with this string. For example,
|
|
15
|
+
* if unhandledErrorMessagePrefix is
|
|
16
|
+
* 'While saving progress, we encountered an error:'
|
|
17
|
+
* and the error is 'progressInfo is not an object',
|
|
18
|
+
* the client will receive an error with the message
|
|
19
|
+
* 'While saving progress, we encountered an error: progressInfo is not an object'
|
|
12
20
|
* @returns express route handler that takes the following arguments:
|
|
13
21
|
* params (map: param name => value),
|
|
14
22
|
* req (express request object),
|
|
@@ -17,6 +25,7 @@ import LogFunction from '../types/LogFunction';
|
|
|
17
25
|
* redirect (takes a url and redirects the user to that url),
|
|
18
26
|
* renderErrorPage (shows a static error page to the user),
|
|
19
27
|
* renderInfoPage (shows a static info page to the user),
|
|
28
|
+
* renderCustomHTML (renders custom html and sends it to the user),
|
|
20
29
|
* and returns the value to send to the client as a JSON API response, or
|
|
21
30
|
* calls next() or redirect(...) or send(...) or renderErrorPage(...).
|
|
22
31
|
* Note: params also has userId, userFirstName,
|
|
@@ -47,8 +56,13 @@ declare const genRouteHandler: (opts: {
|
|
|
47
56
|
title: string;
|
|
48
57
|
body: string;
|
|
49
58
|
}) => void;
|
|
59
|
+
renderCustomHTML: (opts: {
|
|
60
|
+
html: string;
|
|
61
|
+
status?: number;
|
|
62
|
+
}) => void;
|
|
50
63
|
logServerEvent: LogFunction;
|
|
51
64
|
}) => any;
|
|
52
65
|
skipSessionCheck?: boolean | undefined;
|
|
66
|
+
unhandledErrorMessagePrefix?: string | undefined;
|
|
53
67
|
}) => (req: any, res: any, next: () => void) => Promise<undefined>;
|
|
54
68
|
export default genRouteHandler;
|
package/dist/esm/index.js
CHANGED
|
@@ -14029,6 +14029,7 @@ const genErrorPage = (opts = {}) => {
|
|
|
14029
14029
|
* @param opts object containing all arguments
|
|
14030
14030
|
* @param opts.title title of the info box
|
|
14031
14031
|
* @param opts.body a human-readable text body for the info alert
|
|
14032
|
+
* @returns the HTML for the info page
|
|
14032
14033
|
*/
|
|
14033
14034
|
const genInfoPage = (opts) => {
|
|
14034
14035
|
const { title, body, } = opts;
|
|
@@ -14227,6 +14228,14 @@ const parseUserAgent = (userAgent) => {
|
|
|
14227
14228
|
* @param opts.handler function that processes the request
|
|
14228
14229
|
* @param [opts.skipSessionCheck] if true, skip the session check (allow users
|
|
14229
14230
|
* to not be logged in and launched via LTI)
|
|
14231
|
+
* @param [opts.unhandledErrorMessagePrefix] if included, when an error that
|
|
14232
|
+
* is not of type ErrorWithCode is thrown, the client will receive an error
|
|
14233
|
+
* where the error message is prefixed with this string. For example,
|
|
14234
|
+
* if unhandledErrorMessagePrefix is
|
|
14235
|
+
* 'While saving progress, we encountered an error:'
|
|
14236
|
+
* and the error is 'progressInfo is not an object',
|
|
14237
|
+
* the client will receive an error with the message
|
|
14238
|
+
* 'While saving progress, we encountered an error: progressInfo is not an object'
|
|
14230
14239
|
* @returns express route handler that takes the following arguments:
|
|
14231
14240
|
* params (map: param name => value),
|
|
14232
14241
|
* req (express request object),
|
|
@@ -14235,6 +14244,7 @@ const parseUserAgent = (userAgent) => {
|
|
|
14235
14244
|
* redirect (takes a url and redirects the user to that url),
|
|
14236
14245
|
* renderErrorPage (shows a static error page to the user),
|
|
14237
14246
|
* renderInfoPage (shows a static info page to the user),
|
|
14247
|
+
* renderCustomHTML (renders custom html and sends it to the user),
|
|
14238
14248
|
* and returns the value to send to the client as a JSON API response, or
|
|
14239
14249
|
* calls next() or redirect(...) or send(...) or renderErrorPage(...).
|
|
14240
14250
|
* Note: params also has userId, userFirstName,
|
|
@@ -14746,6 +14756,17 @@ const genRouteHandler = (opts) => {
|
|
|
14746
14756
|
const html = genInfoPage(renderOpts);
|
|
14747
14757
|
send(html, 200);
|
|
14748
14758
|
};
|
|
14759
|
+
/**
|
|
14760
|
+
* Render custom HTML
|
|
14761
|
+
* @author Gabe Abrams
|
|
14762
|
+
* @param htmlOpts object containing all arguments
|
|
14763
|
+
* @param htmlOpts.html the HTML to send to the client
|
|
14764
|
+
* @param [ejsOpts.status=200] the http status code to send
|
|
14765
|
+
*/
|
|
14766
|
+
const renderCustomHTML = (htmlOpts) => {
|
|
14767
|
+
var _a;
|
|
14768
|
+
send(htmlOpts.html, (_a = htmlOpts.status) !== null && _a !== void 0 ? _a : 200);
|
|
14769
|
+
};
|
|
14749
14770
|
// Call the handler
|
|
14750
14771
|
try {
|
|
14751
14772
|
const results = yield opts.handler({
|
|
@@ -14759,6 +14780,7 @@ const genRouteHandler = (opts) => {
|
|
|
14759
14780
|
redirect,
|
|
14760
14781
|
renderErrorPage,
|
|
14761
14782
|
renderInfoPage,
|
|
14783
|
+
renderCustomHTML,
|
|
14762
14784
|
logServerEvent,
|
|
14763
14785
|
});
|
|
14764
14786
|
// Send results to client (only if next wasn't called)
|
|
@@ -14767,6 +14789,13 @@ const genRouteHandler = (opts) => {
|
|
|
14767
14789
|
}
|
|
14768
14790
|
}
|
|
14769
14791
|
catch (err) {
|
|
14792
|
+
// Prefix error message if needed
|
|
14793
|
+
if (opts.unhandledErrorMessagePrefix
|
|
14794
|
+
&& err instanceof Error
|
|
14795
|
+
&& err.message
|
|
14796
|
+
&& err.name !== 'ErrorWithCode') {
|
|
14797
|
+
err.message = `${opts.unhandledErrorMessagePrefix.trim()} ${err.message.trim()}`;
|
|
14798
|
+
}
|
|
14770
14799
|
// Send error to client (only if next wasn't called)
|
|
14771
14800
|
if (!responseSent) {
|
|
14772
14801
|
handleError(res, err);
|