dce-reactkit 3.7.12 → 3.7.15
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/components/ButtonInputGroup.d.ts +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/components/ButtonInputGroup.d.ts +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 +15 -1
- package/package.json +1 -1
- package/src/components/ButtonInputGroup.tsx +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/index.d.ts
CHANGED
|
@@ -244,7 +244,7 @@ declare const CheckboxButton: React$1.FC<Props$g>;
|
|
|
244
244
|
*/
|
|
245
245
|
|
|
246
246
|
type Props$f = {
|
|
247
|
-
label:
|
|
247
|
+
label: React$1.ReactNode;
|
|
248
248
|
minLabelWidth?: string;
|
|
249
249
|
children: React$1.ReactNode;
|
|
250
250
|
className?: string;
|
|
@@ -1003,6 +1003,14 @@ type LogFunction = (opts: ({
|
|
|
1003
1003
|
* @param opts.handler function that processes the request
|
|
1004
1004
|
* @param [opts.skipSessionCheck] if true, skip the session check (allow users
|
|
1005
1005
|
* to not be logged in and launched via LTI)
|
|
1006
|
+
* @param [opts.unhandledErrorMessagePrefix] if included, when an error that
|
|
1007
|
+
* is not of type ErrorWithCode is thrown, the client will receive an error
|
|
1008
|
+
* where the error message is prefixed with this string. For example,
|
|
1009
|
+
* if unhandledErrorMessagePrefix is
|
|
1010
|
+
* 'While saving progress, we encountered an error:'
|
|
1011
|
+
* and the error is 'progressInfo is not an object',
|
|
1012
|
+
* the client will receive an error with the message
|
|
1013
|
+
* 'While saving progress, we encountered an error: progressInfo is not an object'
|
|
1006
1014
|
* @returns express route handler that takes the following arguments:
|
|
1007
1015
|
* params (map: param name => value),
|
|
1008
1016
|
* req (express request object),
|
|
@@ -1011,6 +1019,7 @@ type LogFunction = (opts: ({
|
|
|
1011
1019
|
* redirect (takes a url and redirects the user to that url),
|
|
1012
1020
|
* renderErrorPage (shows a static error page to the user),
|
|
1013
1021
|
* renderInfoPage (shows a static info page to the user),
|
|
1022
|
+
* renderCustomHTML (renders custom html and sends it to the user),
|
|
1014
1023
|
* and returns the value to send to the client as a JSON API response, or
|
|
1015
1024
|
* calls next() or redirect(...) or send(...) or renderErrorPage(...).
|
|
1016
1025
|
* Note: params also has userId, userFirstName,
|
|
@@ -1041,9 +1050,14 @@ declare const genRouteHandler: (opts: {
|
|
|
1041
1050
|
title: string;
|
|
1042
1051
|
body: string;
|
|
1043
1052
|
}) => void;
|
|
1053
|
+
renderCustomHTML: (opts: {
|
|
1054
|
+
html: string;
|
|
1055
|
+
status?: number;
|
|
1056
|
+
}) => void;
|
|
1044
1057
|
logServerEvent: LogFunction;
|
|
1045
1058
|
}) => any;
|
|
1046
1059
|
skipSessionCheck?: boolean | undefined;
|
|
1060
|
+
unhandledErrorMessagePrefix?: string | undefined;
|
|
1047
1061
|
}) => (req: any, res: any, next: () => void) => Promise<undefined>;
|
|
1048
1062
|
|
|
1049
1063
|
/**
|
package/package.json
CHANGED
|
@@ -39,6 +39,14 @@ import LogLevel from '../types/LogLevel';
|
|
|
39
39
|
* @param opts.handler function that processes the request
|
|
40
40
|
* @param [opts.skipSessionCheck] if true, skip the session check (allow users
|
|
41
41
|
* to not be logged in and launched via LTI)
|
|
42
|
+
* @param [opts.unhandledErrorMessagePrefix] if included, when an error that
|
|
43
|
+
* is not of type ErrorWithCode is thrown, the client will receive an error
|
|
44
|
+
* where the error message is prefixed with this string. For example,
|
|
45
|
+
* if unhandledErrorMessagePrefix is
|
|
46
|
+
* 'While saving progress, we encountered an error:'
|
|
47
|
+
* and the error is 'progressInfo is not an object',
|
|
48
|
+
* the client will receive an error with the message
|
|
49
|
+
* 'While saving progress, we encountered an error: progressInfo is not an object'
|
|
42
50
|
* @returns express route handler that takes the following arguments:
|
|
43
51
|
* params (map: param name => value),
|
|
44
52
|
* req (express request object),
|
|
@@ -47,6 +55,7 @@ import LogLevel from '../types/LogLevel';
|
|
|
47
55
|
* redirect (takes a url and redirects the user to that url),
|
|
48
56
|
* renderErrorPage (shows a static error page to the user),
|
|
49
57
|
* renderInfoPage (shows a static info page to the user),
|
|
58
|
+
* renderCustomHTML (renders custom html and sends it to the user),
|
|
50
59
|
* and returns the value to send to the client as a JSON API response, or
|
|
51
60
|
* calls next() or redirect(...) or send(...) or renderErrorPage(...).
|
|
52
61
|
* Note: params also has userId, userFirstName,
|
|
@@ -83,10 +92,17 @@ const genRouteHandler = (
|
|
|
83
92
|
body: string,
|
|
84
93
|
},
|
|
85
94
|
) => void,
|
|
95
|
+
renderCustomHTML: (
|
|
96
|
+
opts: {
|
|
97
|
+
html: string,
|
|
98
|
+
status?: number,
|
|
99
|
+
},
|
|
100
|
+
) => void,
|
|
86
101
|
logServerEvent: LogFunction,
|
|
87
102
|
},
|
|
88
103
|
) => any,
|
|
89
104
|
skipSessionCheck?: boolean,
|
|
105
|
+
unhandledErrorMessagePrefix?: string,
|
|
90
106
|
},
|
|
91
107
|
) => {
|
|
92
108
|
// Return a route handler
|
|
@@ -756,6 +772,22 @@ const genRouteHandler = (
|
|
|
756
772
|
send(html, 200);
|
|
757
773
|
};
|
|
758
774
|
|
|
775
|
+
/**
|
|
776
|
+
* Render custom HTML
|
|
777
|
+
* @author Gabe Abrams
|
|
778
|
+
* @param htmlOpts object containing all arguments
|
|
779
|
+
* @param htmlOpts.html the HTML to send to the client
|
|
780
|
+
* @param [ejsOpts.status=200] the http status code to send
|
|
781
|
+
*/
|
|
782
|
+
const renderCustomHTML = (
|
|
783
|
+
htmlOpts: {
|
|
784
|
+
html: string,
|
|
785
|
+
status?: number,
|
|
786
|
+
},
|
|
787
|
+
) => {
|
|
788
|
+
send(htmlOpts.html, htmlOpts.status ?? 200);
|
|
789
|
+
};
|
|
790
|
+
|
|
759
791
|
// Call the handler
|
|
760
792
|
try {
|
|
761
793
|
const results = await opts.handler({
|
|
@@ -769,6 +801,7 @@ const genRouteHandler = (
|
|
|
769
801
|
redirect,
|
|
770
802
|
renderErrorPage,
|
|
771
803
|
renderInfoPage,
|
|
804
|
+
renderCustomHTML,
|
|
772
805
|
logServerEvent,
|
|
773
806
|
});
|
|
774
807
|
|
|
@@ -777,6 +810,16 @@ const genRouteHandler = (
|
|
|
777
810
|
return handleSuccess(res, results ?? undefined);
|
|
778
811
|
}
|
|
779
812
|
} catch (err) {
|
|
813
|
+
// Prefix error message if needed
|
|
814
|
+
if (
|
|
815
|
+
opts.unhandledErrorMessagePrefix
|
|
816
|
+
&& err instanceof Error
|
|
817
|
+
&& err.message
|
|
818
|
+
&& err.name !== 'ErrorWithCode'
|
|
819
|
+
) {
|
|
820
|
+
err.message = `${opts.unhandledErrorMessagePrefix.trim()} ${err.message.trim()}`;
|
|
821
|
+
}
|
|
822
|
+
|
|
780
823
|
// Send error to client (only if next wasn't called)
|
|
781
824
|
if (!responseSent) {
|
|
782
825
|
handleError(res, err);
|
package/src/html/genInfoPage.ts
CHANGED