dce-reactkit 3.6.25 → 3.6.27

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.
@@ -16,10 +16,12 @@ import LogFunction from '../types/LogFunction';
16
16
  * send (a function that sends a string to the client),
17
17
  * redirect (takes a url and redirects the user to that url),
18
18
  * renderErrorPage (shows a static error page to the user),
19
+ * renderInfoPage (shows a static info page to the user),
19
20
  * and returns the value to send to the client as a JSON API response, or
20
21
  * calls next() or redirect(...) or send(...) or renderErrorPage(...).
21
22
  * Note: params also has userId, userFirstName,
22
- * userLastName, isLearner, isTTM, isAdmin, and any other variables that
23
+ * userLastName, userEmail, userAvatarURL, isLearner, isTTM, isAdmin,
24
+ * and any other variables that
23
25
  * are directly added to the session, if the user does have a session.
24
26
  */
25
27
  declare const genRouteHandler: (opts: {
@@ -41,6 +43,10 @@ declare const genRouteHandler: (opts: {
41
43
  pageTitle?: string;
42
44
  status?: number;
43
45
  }) => void;
46
+ renderInfoPage: (opts: {
47
+ title: string;
48
+ body: string;
49
+ }) => void;
44
50
  logServerEvent: LogFunction;
45
51
  }) => any;
46
52
  skipSessionCheck?: boolean | undefined;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Generate a static info page
3
+ * @author Gabe Abrams
4
+ * @param opts object containing all arguments
5
+ * @param opts.title title of the info box
6
+ * @param opts.body a human-readable text body for the info alert
7
+ */
8
+ declare const genInfoPage: (opts: {
9
+ title: string;
10
+ body: string;
11
+ }) => string;
12
+ export default genInfoPage;
package/dist/index.d.ts CHANGED
@@ -1006,10 +1006,12 @@ type LogFunction = (opts: ({
1006
1006
  * send (a function that sends a string to the client),
1007
1007
  * redirect (takes a url and redirects the user to that url),
1008
1008
  * renderErrorPage (shows a static error page to the user),
1009
+ * renderInfoPage (shows a static info page to the user),
1009
1010
  * and returns the value to send to the client as a JSON API response, or
1010
1011
  * calls next() or redirect(...) or send(...) or renderErrorPage(...).
1011
1012
  * Note: params also has userId, userFirstName,
1012
- * userLastName, isLearner, isTTM, isAdmin, and any other variables that
1013
+ * userLastName, userEmail, userAvatarURL, isLearner, isTTM, isAdmin,
1014
+ * and any other variables that
1013
1015
  * are directly added to the session, if the user does have a session.
1014
1016
  */
1015
1017
  declare const genRouteHandler: (opts: {
@@ -1031,6 +1033,10 @@ declare const genRouteHandler: (opts: {
1031
1033
  pageTitle?: string;
1032
1034
  status?: number;
1033
1035
  }) => void;
1036
+ renderInfoPage: (opts: {
1037
+ title: string;
1038
+ body: string;
1039
+ }) => void;
1034
1040
  logServerEvent: LogFunction;
1035
1041
  }) => any;
1036
1042
  skipSessionCheck?: boolean | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "3.6.25",
3
+ "version": "3.6.27",
4
4
  "description": "Shared components for Harvard DCE apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -14,6 +14,7 @@ import ParamType from '../types/ParamType';
14
14
  import handleError from './handleError';
15
15
  import handleSuccess from './handleSuccess';
16
16
  import genErrorPage from '../html/genErrorPage';
17
+ import genInfoPage from '../html/genInfoPage';
17
18
  import parseUserAgent from './parseUserAgent';
18
19
  import getTimeInfoInET from './getTimeInfoInET';
19
20
 
@@ -45,10 +46,12 @@ import LogLevel from '../types/LogLevel';
45
46
  * send (a function that sends a string to the client),
46
47
  * redirect (takes a url and redirects the user to that url),
47
48
  * renderErrorPage (shows a static error page to the user),
49
+ * renderInfoPage (shows a static info page to the user),
48
50
  * and returns the value to send to the client as a JSON API response, or
49
51
  * calls next() or redirect(...) or send(...) or renderErrorPage(...).
50
52
  * Note: params also has userId, userFirstName,
51
- * userLastName, isLearner, isTTM, isAdmin, and any other variables that
53
+ * userLastName, userEmail, userAvatarURL, isLearner, isTTM, isAdmin,
54
+ * and any other variables that
52
55
  * are directly added to the session, if the user does have a session.
53
56
  */
54
57
  const genRouteHandler = (
@@ -74,6 +77,12 @@ const genRouteHandler = (
74
77
  status?: number,
75
78
  },
76
79
  ) => void,
80
+ renderInfoPage: (
81
+ opts: {
82
+ title: string,
83
+ body: string,
84
+ },
85
+ ) => void,
77
86
  logServerEvent: LogFunction,
78
87
  },
79
88
  ) => any,
@@ -399,7 +408,7 @@ const genRouteHandler = (
399
408
  });
400
409
 
401
410
  /*----------------------------------------*/
402
- /* Require Course Consistency */
411
+ /* ----- Require Course Consistency ----- */
403
412
  /*----------------------------------------*/
404
413
 
405
414
  // Make sure the user actually launched from the appropriate course
@@ -468,7 +477,7 @@ const genRouteHandler = (
468
477
  }
469
478
 
470
479
  /*----------------------------------------*/
471
- /* Log Handler */
480
+ /* ------------- Log Handler ------------ */
472
481
  /*----------------------------------------*/
473
482
 
474
483
  // Create a log handler function
@@ -724,6 +733,23 @@ const genRouteHandler = (
724
733
  });
725
734
  };
726
735
 
736
+ /**
737
+ * Render an info page
738
+ * @author Gabe Abrams
739
+ * @param renderOpts object containing all arguments
740
+ * @param renderOpts.title title of the info box
741
+ * @param renderOpts.body a human-readable text body for the info alert
742
+ */
743
+ const renderInfoPage = (
744
+ renderOpts: {
745
+ title: string,
746
+ body: string,
747
+ },
748
+ ) => {
749
+ const html = genInfoPage(renderOpts);
750
+ send(html, 200);
751
+ };
752
+
727
753
  // Call the handler
728
754
  try {
729
755
  const results = await opts.handler({
@@ -736,6 +762,7 @@ const genRouteHandler = (
736
762
  },
737
763
  redirect,
738
764
  renderErrorPage,
765
+ renderInfoPage,
739
766
  logServerEvent,
740
767
  });
741
768
 
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Generate a static info page
3
+ * @author Gabe Abrams
4
+ * @param opts object containing all arguments
5
+ * @param opts.title title of the info box
6
+ * @param opts.body a human-readable text body for the info alert
7
+ */
8
+ const genInfoPage = (
9
+ opts: {
10
+ title: string,
11
+ body: string,
12
+ },
13
+ ): string => {
14
+ const {
15
+ title,
16
+ body,
17
+ } = opts;
18
+
19
+ return `
20
+ <head>
21
+ <!-- Metadata -->
22
+ <meta
23
+ name="viewport"
24
+ content="width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0"
25
+ >
26
+
27
+ <!-- Title -->
28
+ <title>${title}</title>
29
+
30
+ <!-- Bootstrap -->
31
+ <link
32
+ rel="stylesheet"
33
+ href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.1/css/bootstrap.min.css"
34
+ integrity="sha512-siwe/oXMhSjGCwLn+scraPOWrJxHlUgMBMZXdPe2Tnk3I0x3ESCoLz7WZ5NTH6SZrywMY+PB1cjyqJ5jAluCOg=="
35
+ crossorigin="anonymous"
36
+ referrerpolicy="no-referrer"
37
+ />
38
+ <script
39
+ src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.2.1/js/bootstrap.min.js"
40
+ integrity="sha512-vyRAVI0IEm6LI/fVSv/Wq/d0KUfrg3hJq2Qz5FlfER69sf3ZHlOrsLriNm49FxnpUGmhx+TaJKwJ+ByTLKT+Yg=="
41
+ crossorigin="anonymous"
42
+ referrerpolicy="no-referrer"
43
+ ></script>
44
+
45
+ <!-- FontAwesome -->
46
+ <link
47
+ rel="stylesheet"
48
+ href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css"
49
+ integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A=="
50
+ crossorigin="anonymous"
51
+ referrerpolicy="no-referrer"
52
+ />
53
+
54
+ <!-- Style -->
55
+ <style>
56
+ .DCEReactKit-pop-in {
57
+ animation-name: DCEReactKit-pop-in;
58
+ animation-duration: 0.5s;
59
+ animation-iteration-count: 1;
60
+ animation-timing-function: ease-out;
61
+ animation-fill-mode: both;
62
+
63
+ transform-origin: center;
64
+ }
65
+
66
+ @keyframes DCEReactKit-pop-in {
67
+ 0% {
68
+ opacity: 0;
69
+ transform: scale(0.9);
70
+ }
71
+ 100% {
72
+ opacity: 1;
73
+ transform: scale(1);
74
+ }
75
+ }
76
+ </style>
77
+ </head>
78
+
79
+ <!-- Body -->
80
+ <body class="bg-dark text-center pt-3 ps-3 pe-3">
81
+ <!-- Alert -->
82
+ <div
83
+ class="DCEReactKit-pop-in alert alert-info d-inline-block"
84
+ style="width: 50em; max-width: 100%"
85
+ >
86
+ <!-- Title -->
87
+ <h2>
88
+ <i class="me-1 fa-solid fa-circle-info"></i>
89
+ ${title}
90
+ </h2>
91
+ <!-- Body -->
92
+ <div>
93
+ ${body}
94
+ </div>
95
+ </div>
96
+ </body>
97
+ `;
98
+ };
99
+
100
+ export default genInfoPage;