dce-reactkit 3.6.24 → 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/esm/index.js CHANGED
@@ -42161,16 +42161,18 @@ const parseUserAgent = (userAgent) => {
42161
42161
  * send (a function that sends a string to the client),
42162
42162
  * redirect (takes a url and redirects the user to that url),
42163
42163
  * renderErrorPage (shows a static error page to the user),
42164
+ * renderInfoPage (shows a static info page to the user),
42164
42165
  * and returns the value to send to the client as a JSON API response, or
42165
42166
  * calls next() or redirect(...) or send(...) or renderErrorPage(...).
42166
42167
  * Note: params also has userId, userFirstName,
42167
- * userLastName, isLearner, isTTM, isAdmin, and any other variables that
42168
+ * userLastName, userEmail, userAvatarURL, isLearner, isTTM, isAdmin,
42169
+ * and any other variables that
42168
42170
  * are directly added to the session, if the user does have a session.
42169
42171
  */
42170
42172
  const genRouteHandler = (opts) => {
42171
42173
  // Return a route handler
42172
42174
  return (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
42173
- var _a, _b;
42175
+ var _a, _b, _c;
42174
42176
  // Output params
42175
42177
  const output = {};
42176
42178
  /*----------------------------------------*/
@@ -42381,6 +42383,9 @@ const genRouteHandler = (opts) => {
42381
42383
  output.userEmail = (launchInfo
42382
42384
  ? launchInfo.userEmail
42383
42385
  : undefined);
42386
+ output.userAvatarURL = (launchInfo
42387
+ ? ((_b = launchInfo.userImage) !== null && _b !== void 0 ? _b : 'http://www.gravatar.com/avatar/?d=identicon')
42388
+ : undefined);
42384
42389
  output.isLearner = (launchInfo
42385
42390
  ? !!launchInfo.isLearner
42386
42391
  : undefined);
@@ -42391,7 +42396,7 @@ const genRouteHandler = (opts) => {
42391
42396
  ? !!launchInfo.isAdmin
42392
42397
  : undefined);
42393
42398
  output.courseId = (launchInfo
42394
- ? ((_b = output.courseId) !== null && _b !== void 0 ? _b : launchInfo.courseId)
42399
+ ? ((_c = output.courseId) !== null && _c !== void 0 ? _c : launchInfo.courseId)
42395
42400
  : undefined);
42396
42401
  output.courseName = (launchInfo
42397
42402
  ? launchInfo.contextLabel
@@ -42469,7 +42474,7 @@ const genRouteHandler = (opts) => {
42469
42474
  * @author Gabe Abrams
42470
42475
  */
42471
42476
  const logServerEvent = (logOpts) => __awaiter(void 0, void 0, void 0, function* () {
42472
- var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
42477
+ var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
42473
42478
  // NOTE: internally, we slip through an opts.overrideAsClientEvent boolean
42474
42479
  // that indicates that this is actually a client event, but we don't
42475
42480
  // include that in the LogFunction type because this is internal and
@@ -42501,24 +42506,24 @@ const genRouteHandler = (opts) => {
42501
42506
  timestamp,
42502
42507
  context: (typeof logOpts.context === 'string'
42503
42508
  ? logOpts.context
42504
- : ((_d = ((_c = logOpts.context) !== null && _c !== void 0 ? _c : {})._) !== null && _d !== void 0 ? _d : LogBuiltInMetadata.Context.Uncategorized)),
42505
- subcontext: ((_e = logOpts.subcontext) !== null && _e !== void 0 ? _e : LogBuiltInMetadata.Context.Uncategorized),
42506
- tags: ((_f = logOpts.tags) !== null && _f !== void 0 ? _f : []),
42507
- level: ((_g = logOpts.level) !== null && _g !== void 0 ? _g : LogLevel$1.Info),
42508
- metadata: ((_h = logOpts.metadata) !== null && _h !== void 0 ? _h : {}),
42509
+ : ((_e = ((_d = logOpts.context) !== null && _d !== void 0 ? _d : {})._) !== null && _e !== void 0 ? _e : LogBuiltInMetadata.Context.Uncategorized)),
42510
+ subcontext: ((_f = logOpts.subcontext) !== null && _f !== void 0 ? _f : LogBuiltInMetadata.Context.Uncategorized),
42511
+ tags: ((_g = logOpts.tags) !== null && _g !== void 0 ? _g : []),
42512
+ level: ((_h = logOpts.level) !== null && _h !== void 0 ? _h : LogLevel$1.Info),
42513
+ metadata: ((_j = logOpts.metadata) !== null && _j !== void 0 ? _j : {}),
42509
42514
  };
42510
42515
  // Type-specific info
42511
42516
  const typeSpecificInfo = (('error' in opts && opts.error)
42512
42517
  ? {
42513
42518
  type: LogType$1.Error,
42514
- errorMessage: (_j = logOpts.error.message) !== null && _j !== void 0 ? _j : 'Unknown message',
42515
- errorCode: (_k = logOpts.error.code) !== null && _k !== void 0 ? _k : ReactKitErrorCode$1.NoCode,
42516
- errorStack: (_l = logOpts.error.stack) !== null && _l !== void 0 ? _l : 'No stack',
42519
+ errorMessage: (_k = logOpts.error.message) !== null && _k !== void 0 ? _k : 'Unknown message',
42520
+ errorCode: (_l = logOpts.error.code) !== null && _l !== void 0 ? _l : ReactKitErrorCode$1.NoCode,
42521
+ errorStack: (_m = logOpts.error.stack) !== null && _m !== void 0 ? _m : 'No stack',
42517
42522
  }
42518
42523
  : {
42519
42524
  type: LogType$1.Action,
42520
- target: ((_m = logOpts.target) !== null && _m !== void 0 ? _m : LogBuiltInMetadata.Target.NoTarget),
42521
- action: ((_o = logOpts.action) !== null && _o !== void 0 ? _o : LogAction$1.Unknown),
42525
+ target: ((_o = logOpts.target) !== null && _o !== void 0 ? _o : LogBuiltInMetadata.Target.NoTarget),
42526
+ action: ((_p = logOpts.action) !== null && _p !== void 0 ? _p : LogAction$1.Unknown),
42522
42527
  });
42523
42528
  // Source-specific info
42524
42529
  const sourceSpecificInfo = (logOpts.overrideAsClientEvent
@@ -42657,6 +42662,17 @@ const genRouteHandler = (opts) => {
42657
42662
  },
42658
42663
  });
42659
42664
  };
42665
+ /**
42666
+ * Render an info page
42667
+ * @author Gabe Abrams
42668
+ * @param renderOpts object containing all arguments
42669
+ * @param renderOpts.title title of the info box
42670
+ * @param renderOpts.body a human-readable text body for the info alert
42671
+ */
42672
+ const renderInfoPage = (renderOpts) => {
42673
+ const html = genErrorPage(renderOpts);
42674
+ send(html, 200);
42675
+ };
42660
42676
  // Call the handler
42661
42677
  try {
42662
42678
  const results = yield opts.handler({
@@ -42669,6 +42685,7 @@ const genRouteHandler = (opts) => {
42669
42685
  },
42670
42686
  redirect,
42671
42687
  renderErrorPage,
42688
+ renderInfoPage,
42672
42689
  logServerEvent,
42673
42690
  });
42674
42691
  // Send results to client (only if next wasn't called)