dce-reactkit 3.6.25 → 3.6.26

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.26",
4
4
  "description": "Shared components for Harvard DCE apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -45,10 +45,12 @@ import LogLevel from '../types/LogLevel';
45
45
  * send (a function that sends a string to the client),
46
46
  * redirect (takes a url and redirects the user to that url),
47
47
  * renderErrorPage (shows a static error page to the user),
48
+ * renderInfoPage (shows a static info page to the user),
48
49
  * and returns the value to send to the client as a JSON API response, or
49
50
  * calls next() or redirect(...) or send(...) or renderErrorPage(...).
50
51
  * Note: params also has userId, userFirstName,
51
- * userLastName, isLearner, isTTM, isAdmin, and any other variables that
52
+ * userLastName, userEmail, userAvatarURL, isLearner, isTTM, isAdmin,
53
+ * and any other variables that
52
54
  * are directly added to the session, if the user does have a session.
53
55
  */
54
56
  const genRouteHandler = (
@@ -74,6 +76,12 @@ const genRouteHandler = (
74
76
  status?: number,
75
77
  },
76
78
  ) => void,
79
+ renderInfoPage: (
80
+ opts: {
81
+ title: string,
82
+ body: string,
83
+ },
84
+ ) => void,
77
85
  logServerEvent: LogFunction,
78
86
  },
79
87
  ) => any,
@@ -724,6 +732,23 @@ const genRouteHandler = (
724
732
  });
725
733
  };
726
734
 
735
+ /**
736
+ * Render an info page
737
+ * @author Gabe Abrams
738
+ * @param renderOpts object containing all arguments
739
+ * @param renderOpts.title title of the info box
740
+ * @param renderOpts.body a human-readable text body for the info alert
741
+ */
742
+ const renderInfoPage = (
743
+ renderOpts: {
744
+ title: string,
745
+ body: string,
746
+ },
747
+ ) => {
748
+ const html = genErrorPage(renderOpts);
749
+ send(html, 200);
750
+ };
751
+
727
752
  // Call the handler
728
753
  try {
729
754
  const results = await opts.handler({
@@ -736,6 +761,7 @@ const genRouteHandler = (
736
761
  },
737
762
  redirect,
738
763
  renderErrorPage,
764
+ renderInfoPage,
739
765
  logServerEvent,
740
766
  });
741
767
 
@@ -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;