dce-reactkit 2.0.3 → 2.0.6

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.
Files changed (53) hide show
  1. package/lib/components/AppWrapper.d.ts +19 -0
  2. package/lib/components/AppWrapper.js +127 -0
  3. package/lib/components/AppWrapper.js.map +1 -0
  4. package/{src → lib}/components/AppWrapper.tsx +61 -7
  5. package/lib/components/ErrorBox.d.ts +12 -0
  6. package/lib/components/ErrorBox.js +65 -0
  7. package/lib/components/ErrorBox.js.map +1 -0
  8. package/{src → lib}/components/ErrorBox.tsx +4 -1
  9. package/{src → lib}/components/LoadingSpinner.tsx +0 -0
  10. package/{src → lib}/components/Modal.tsx +0 -0
  11. package/{src → lib}/errors/ErrorWithCode.tsx +0 -0
  12. package/{src → lib}/helpers/abbreviate.tsx +0 -0
  13. package/{src → lib}/helpers/avg.tsx +0 -0
  14. package/{src → lib}/helpers/ceilToNumDecimals.tsx +0 -0
  15. package/{src → lib}/helpers/floorToNumDecimals.tsx +0 -0
  16. package/{src → lib}/helpers/forceNumIntoBounds.tsx +0 -0
  17. package/lib/helpers/handleError.d.ts +14 -0
  18. package/lib/helpers/handleError.js +54 -0
  19. package/lib/helpers/handleError.js.map +1 -0
  20. package/lib/helpers/handleError.ts +65 -0
  21. package/lib/helpers/handleSuccess.d.ts +8 -0
  22. package/lib/helpers/handleSuccess.js +20 -0
  23. package/lib/helpers/handleSuccess.js.map +1 -0
  24. package/lib/helpers/handleSuccess.ts +18 -0
  25. package/{src → lib}/helpers/padDecimalZeros.tsx +0 -0
  26. package/{src → lib}/helpers/padZerosLeft.tsx +0 -0
  27. package/lib/helpers/parseRequest.d.ts +21 -0
  28. package/lib/helpers/parseRequest.js +240 -0
  29. package/lib/helpers/parseRequest.js.map +1 -0
  30. package/lib/helpers/parseRequest.ts +299 -0
  31. package/{src → lib}/helpers/roundToNumDecimals.tsx +0 -0
  32. package/lib/helpers/showFatalError.d.ts +2 -0
  33. package/lib/helpers/showFatalError.js +5 -0
  34. package/lib/helpers/showFatalError.js.map +1 -0
  35. package/{src → lib}/helpers/showFatalError.tsx +0 -0
  36. package/{src → lib}/helpers/sum.tsx +0 -0
  37. package/lib/helpers/visitServerEndpoint.d.ts +7 -1
  38. package/lib/helpers/visitServerEndpoint.js +57 -6
  39. package/lib/helpers/visitServerEndpoint.js.map +1 -1
  40. package/lib/helpers/visitServerEndpoint.tsx +110 -0
  41. package/{src → lib}/helpers/waitMs.tsx +0 -0
  42. package/lib/types/ParamType.d.ts +17 -0
  43. package/lib/types/ParamType.js +21 -0
  44. package/lib/types/ParamType.js.map +1 -0
  45. package/lib/types/ParamType.ts +18 -0
  46. package/lib/types/ReactKitErrorCode.d.ts +5 -1
  47. package/lib/types/ReactKitErrorCode.js +4 -0
  48. package/lib/types/ReactKitErrorCode.js.map +1 -1
  49. package/{src → lib}/types/ReactKitErrorCode.tsx +4 -0
  50. package/{src → lib}/types/Variant.tsx +0 -0
  51. package/package.json +5 -2
  52. package/tsconfig.json +1 -1
  53. package/src/helpers/visitServerEndpoint.tsx +0 -59
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A wrapper for the entire React app that adds global functionality like
3
+ * handling for fatal error messages
4
+ * @author Gabe Abrams
5
+ */
6
+ import React from 'react';
7
+ declare type Props = {
8
+ children: React.ReactNode;
9
+ dark?: boolean;
10
+ sessionExpiredMessage?: string;
11
+ };
12
+ /**
13
+ * Show a fatal error message
14
+ * @author Gabe Abrams
15
+ * @param error the error to show
16
+ */
17
+ export declare const showFatalError: (error: any) => void;
18
+ declare const AppWrapper: (props: Props) => React.ReactElement;
19
+ export default AppWrapper;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.showFatalError = void 0;
18
+ var jsx_runtime_1 = require("react/jsx-runtime");
19
+ /**
20
+ * A wrapper for the entire React app that adds global functionality like
21
+ * handling for fatal error messages
22
+ * @author Gabe Abrams
23
+ */
24
+ // Import React
25
+ var react_1 = require("react");
26
+ // Import shared components
27
+ var ErrorBox_1 = __importDefault(require("./ErrorBox"));
28
+ // Import helpers
29
+ var visitServerEndpoint_1 = require("../helpers/visitServerEndpoint");
30
+ // Import shared types
31
+ var ReactKitErrorCode_1 = __importDefault(require("../types/ReactKitErrorCode"));
32
+ // Import custom errors
33
+ var ErrorWithCode_1 = __importDefault(require("../errors/ErrorWithCode"));
34
+ /*------------------------------------------------------------------------*/
35
+ /* Static Helpers */
36
+ /*------------------------------------------------------------------------*/
37
+ // Stored copies of setters
38
+ var setFatalErrorMessage;
39
+ var setFatalErrorCode;
40
+ /**
41
+ * Show a fatal error message
42
+ * @author Gabe Abrams
43
+ * @param error the error to show
44
+ */
45
+ var showFatalError = function (error) {
46
+ var _a, _b;
47
+ // Determine message and code
48
+ var message = (typeof error === 'string'
49
+ ? error.trim()
50
+ : String((_a = error.message) !== null && _a !== void 0 ? _a : 'An unknown error occurred.'));
51
+ var code = (typeof error === 'string'
52
+ ? ReactKitErrorCode_1.default.NoCode
53
+ : String((_b = error.code) !== null && _b !== void 0 ? _b : ReactKitErrorCode_1.default.NoCode));
54
+ // Handle case where app hasn't loaded
55
+ if (!setFatalErrorMessage || !setFatalErrorCode) {
56
+ return alert("An error has occurred: ".concat(message, " (code: ").concat(code, "). Please contact support."));
57
+ }
58
+ // Use setters
59
+ setFatalErrorMessage(message);
60
+ setFatalErrorCode(code);
61
+ };
62
+ exports.showFatalError = showFatalError;
63
+ /*------------------------------------------------------------------------*/
64
+ /* Component */
65
+ /*------------------------------------------------------------------------*/
66
+ var AppWrapper = function (props) {
67
+ /*------------------------------------------------------------------------*/
68
+ /* Setup */
69
+ /*------------------------------------------------------------------------*/
70
+ /* -------------- Props ------------- */
71
+ var children = props.children, dark = props.dark, _a = props.sessionExpiredMessage, sessionExpiredMessage = _a === void 0 ? 'Your session has expired. Please go back to Canvas and start over.' : _a;
72
+ /* -------------- State ------------- */
73
+ // Fatal error
74
+ var _b = (0, react_1.useState)(null), fatalErrorMessage = _b[0], setFatalErrorMessageInner = _b[1];
75
+ setFatalErrorMessage = setFatalErrorMessageInner;
76
+ var _c = (0, react_1.useState)(null), fatalErrorCode = _c[0], setFatalErrorCodeInner = _c[1];
77
+ setFatalErrorCode = setFatalErrorCodeInner;
78
+ // Session expired
79
+ var _d = (0, react_1.useState)(false), sessionHasExpired = _d[0], setSessionHasExpired = _d[1];
80
+ /*------------------------------------------------------------------------*/
81
+ /* Lifecycle Functions */
82
+ /*------------------------------------------------------------------------*/
83
+ /**
84
+ * Mount
85
+ * @author Gabe Abrams
86
+ */
87
+ (0, react_1.useEffect)(function () {
88
+ // Add session expired handler
89
+ (0, visitServerEndpoint_1.setSessionExpiryHandler)(function () {
90
+ // Session expired!
91
+ setSessionHasExpired(true);
92
+ });
93
+ }, []);
94
+ /*------------------------------------------------------------------------*/
95
+ /* Render */
96
+ /*------------------------------------------------------------------------*/
97
+ /*----------------------------------------*/
98
+ /* Main UI */
99
+ /*----------------------------------------*/
100
+ // Show error
101
+ if (fatalErrorMessage || fatalErrorCode || sessionHasExpired) {
102
+ // Re-encapsulate in an error
103
+ var error = (sessionHasExpired
104
+ ? new ErrorWithCode_1.default(fatalErrorMessage, fatalErrorCode)
105
+ : new ErrorWithCode_1.default(sessionExpiredMessage, ReactKitErrorCode_1.default.SessionExpired));
106
+ // Build error screen
107
+ return ((0, jsx_runtime_1.jsx)("div", __assign({ style: {
108
+ display: 'block',
109
+ width: '100vw',
110
+ minHeight: '100vh',
111
+ paddingTop: '10rem',
112
+ backgroundColor: (dark
113
+ ? '#222'
114
+ : '#fff'),
115
+ } }, { children: (0, jsx_runtime_1.jsx)(ErrorBox_1.default, { title: (sessionHasExpired
116
+ ? 'Session Expired'
117
+ : undefined), error: error }) })));
118
+ }
119
+ // Show the app itself
120
+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: children }));
121
+ };
122
+ /*------------------------------------------------------------------------*/
123
+ /* Wrap Up */
124
+ /*------------------------------------------------------------------------*/
125
+ // Export component
126
+ exports.default = AppWrapper;
127
+ //# sourceMappingURL=AppWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AppWrapper.js","sourceRoot":"","sources":["../../src/components/AppWrapper.tsx"],"names":[],"mappings":"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"}
@@ -5,11 +5,14 @@
5
5
  */
6
6
 
7
7
  // Import React
8
- import React, { useState } from 'react';
8
+ import React, { useState, useEffect } from 'react';
9
9
 
10
10
  // Import shared components
11
11
  import ErrorBox from './ErrorBox';
12
12
 
13
+ // Import helpers
14
+ import { setSessionExpiryHandler } from '../helpers/visitServerEndpoint';
15
+
13
16
  // Import shared types
14
17
  import ReactKitErrorCode from '../types/ReactKitErrorCode';
15
18
 
@@ -25,6 +28,8 @@ type Props = {
25
28
  children: React.ReactNode,
26
29
  // True if this app is a dark-themed app
27
30
  dark?: boolean,
31
+ // Custom session expired message
32
+ sessionExpiredMessage?: string,
28
33
  };
29
34
 
30
35
  /*------------------------------------------------------------------------*/
@@ -67,7 +72,7 @@ export const showFatalError = (error: any) => {
67
72
  /* Component */
68
73
  /*------------------------------------------------------------------------*/
69
74
 
70
- const AppWrapper = (props: Props) => {
75
+ const AppWrapper = (props: Props): React.ReactElement => {
71
76
  /*------------------------------------------------------------------------*/
72
77
  /* Setup */
73
78
  /*------------------------------------------------------------------------*/
@@ -77,6 +82,7 @@ const AppWrapper = (props: Props) => {
77
82
  const {
78
83
  children,
79
84
  dark,
85
+ sessionExpiredMessage = 'Your session has expired. Please go back to Canvas and start over.',
80
86
  } = props;
81
87
 
82
88
  /* -------------- State ------------- */
@@ -87,18 +93,52 @@ const AppWrapper = (props: Props) => {
87
93
  const [fatalErrorCode, setFatalErrorCodeInner] = useState(null);
88
94
  setFatalErrorCode = setFatalErrorCodeInner;
89
95
 
96
+ // Session expired
97
+ const [sessionHasExpired, setSessionHasExpired] = useState(false);
98
+
99
+ /*------------------------------------------------------------------------*/
100
+ /* Lifecycle Functions */
101
+ /*------------------------------------------------------------------------*/
102
+
103
+ /**
104
+ * Mount
105
+ * @author Gabe Abrams
106
+ */
107
+ useEffect(
108
+ () => {
109
+ // Add session expired handler
110
+ setSessionExpiryHandler(() => {
111
+ // Session expired!
112
+ setSessionHasExpired(true);
113
+ });
114
+ },
115
+ [],
116
+ );
117
+
118
+ /*------------------------------------------------------------------------*/
119
+ /* Render */
120
+ /*------------------------------------------------------------------------*/
121
+
90
122
  /*----------------------------------------*/
91
123
  /* Main UI */
92
124
  /*----------------------------------------*/
93
125
 
94
126
  // Show error
95
- if (fatalErrorMessage || fatalErrorCode) {
127
+ if (fatalErrorMessage || fatalErrorCode || sessionHasExpired) {
96
128
  // Re-encapsulate in an error
97
- const error = new ErrorWithCode(
98
- fatalErrorMessage,
99
- fatalErrorCode,
129
+ const error = (
130
+ sessionHasExpired
131
+ ? new ErrorWithCode(
132
+ fatalErrorMessage,
133
+ fatalErrorCode,
134
+ )
135
+ : new ErrorWithCode(
136
+ sessionExpiredMessage,
137
+ ReactKitErrorCode.SessionExpired,
138
+ )
100
139
  );
101
140
 
141
+ // Build error screen
102
142
  return (
103
143
  <div
104
144
  style={{
@@ -106,9 +146,19 @@ const AppWrapper = (props: Props) => {
106
146
  width: '100vw',
107
147
  minHeight: '100vh',
108
148
  paddingTop: '10rem',
149
+ backgroundColor: (
150
+ dark
151
+ ? '#222'
152
+ : '#fff'
153
+ ),
109
154
  }}
110
155
  >
111
156
  <ErrorBox
157
+ title={(
158
+ sessionHasExpired
159
+ ? 'Session Expired'
160
+ : undefined
161
+ )}
112
162
  error={error}
113
163
  />
114
164
  </div>
@@ -116,7 +166,11 @@ const AppWrapper = (props: Props) => {
116
166
  }
117
167
 
118
168
  // Show the app itself
119
- return children;
169
+ return (
170
+ <>
171
+ {children}
172
+ </>
173
+ );
120
174
  };
121
175
 
122
176
  /*------------------------------------------------------------------------*/
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Displays an error
3
+ * @author Gabe Abrams
4
+ */
5
+ import React from 'react';
6
+ declare type Props = {
7
+ error: any;
8
+ title?: string;
9
+ onClose?: () => void;
10
+ };
11
+ declare const ErrorBox: React.FC<Props>;
12
+ export default ErrorBox;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ var jsx_runtime_1 = require("react/jsx-runtime");
18
+ // Import FontAwesome Icons
19
+ var react_fontawesome_1 = require("@fortawesome/react-fontawesome");
20
+ var free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
21
+ // Import shared types
22
+ var ReactKitErrorCode_1 = __importDefault(require("../types/ReactKitErrorCode"));
23
+ /*------------------------------------------------------------------------*/
24
+ /* Component */
25
+ /*------------------------------------------------------------------------*/
26
+ var ErrorBox = function (props) {
27
+ /*------------------------------------------------------------------------*/
28
+ /* Setup */
29
+ /*------------------------------------------------------------------------*/
30
+ var _a;
31
+ /* -------------- Props ------------- */
32
+ var error = props.error, _b = props.title, title = _b === void 0 ? 'An Error Occurred' : _b, onClose = props.onClose;
33
+ /*------------------------------------------------------------------------*/
34
+ /* Render */
35
+ /*------------------------------------------------------------------------*/
36
+ // Determine error text
37
+ var errorText = (typeof error === 'string'
38
+ ? error.trim()
39
+ : String(error.message || 'An unknown error occurred. Please contact support.'));
40
+ // Error code box
41
+ var errorCodeBox;
42
+ if (error && error.code) {
43
+ errorCodeBox = ((0, jsx_runtime_1.jsxs)("span", { children: [' ', (0, jsx_runtime_1.jsxs)("span", __assign({ style: {
44
+ backgroundColor: 'white',
45
+ borderRadius: '5px',
46
+ paddingLeft: '3px',
47
+ paddingRight: '3px',
48
+ color: '#DC4150',
49
+ fontVariant: 'small-caps',
50
+ fontSize: '80%',
51
+ whiteSpace: 'nowrap',
52
+ } }, { children: ["code:", ' ', String((_a = error.code) !== null && _a !== void 0 ? _a : ReactKitErrorCode_1.default.NoCode).toUpperCase()] }))] }));
53
+ }
54
+ // Main UI
55
+ return ((0, jsx_runtime_1.jsxs)("div", __assign({ className: "alert alert-danger text-center", style: {
56
+ maxWidth: '650px',
57
+ margin: 'auto',
58
+ } }, { children: [(0, jsx_runtime_1.jsxs)("h4", __assign({ className: "mb-1" }, { children: [(0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { icon: free_solid_svg_icons_1.faExclamationTriangle, className: "me-2" }), title] })), (0, jsx_runtime_1.jsxs)("div", { children: [errorText, errorCodeBox] }), onClose && ((0, jsx_runtime_1.jsx)("div", __assign({ className: "mt-2" }, { children: (0, jsx_runtime_1.jsx)("button", __assign({ type: "button", className: "btn btn-light", "aria-label": "dismiss error and close this activity or view", onClick: onClose }, { children: "Close" })) })))] })));
59
+ };
60
+ /*------------------------------------------------------------------------*/
61
+ /* Wrap Up */
62
+ /*------------------------------------------------------------------------*/
63
+ // Export component
64
+ exports.default = ErrorBox;
65
+ //# sourceMappingURL=ErrorBox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorBox.js","sourceRoot":"","sources":["../../src/components/ErrorBox.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAQA,2BAA2B;AAC3B,oEAAiE;AACjE,0EAA0E;AAE1E,sBAAsB;AACtB,iFAA2D;AAe3D,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAE5E,IAAM,QAAQ,GAAoB,UAAC,KAAK;IACtC,4EAA4E;IAC5E,4EAA4E;IAC5E,4EAA4E;;IAE5E,wCAAwC;IAGtC,IAAA,KAAK,GAGH,KAAK,MAHF,EACL,KAEE,KAAK,MAFoB,EAA3B,KAAK,mBAAG,mBAAmB,KAAA,EAC3B,OAAO,GACL,KAAK,QADA,CACC;IAEV,4EAA4E;IAC5E,4EAA4E;IAC5E,4EAA4E;IAE5E,uBAAuB;IACvB,IAAM,SAAS,GAAW,CACxB,OAAO,KAAK,KAAK,QAAQ;QACvB,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE;QACd,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,IAAI,oDAAoD,CAAC,CAClF,CAAC;IAEF,iBAAiB;IACjB,IAAI,YAAY,CAAC;IACjB,IAAI,KAAK,IAAK,KAAa,CAAC,IAAI,EAAE;QAChC,YAAY,GAAG,CACb,6CACG,GAAG,EACJ,2CACE,KAAK,EAAE;wBACL,eAAe,EAAE,OAAO;wBACxB,YAAY,EAAE,KAAK;wBACnB,WAAW,EAAE,KAAK;wBAClB,YAAY,EAAE,KAAK;wBACnB,KAAK,EAAE,SAAS;wBAChB,WAAW,EAAE,YAAY;wBACzB,QAAQ,EAAE,KAAK;wBACf,UAAU,EAAE,QAAQ;qBACrB,0BAGA,GAAG,EACH,MAAM,CAAC,MAAC,KAAa,CAAC,IAAI,mCAAI,2BAAiB,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,KACjE,IACF,CACR,CAAC;KACH;IAED,UAAU;IACV,OAAO,CACL,0CACE,SAAS,EAAC,gCAAgC,EAC1C,KAAK,EAAE;YACL,QAAQ,EAAE,OAAO;YACjB,MAAM,EAAE,MAAM;SACf,iBAED,yCAAI,SAAS,EAAC,MAAM,iBAClB,uBAAC,mCAAe,IACd,IAAI,EAAE,4CAAqB,EAC3B,SAAS,EAAC,MAAM,GAChB,EACD,KAAK,KACH,EACL,4CACG,SAAS,EACT,YAAY,IACT,EACL,OAAO,IAAI,CACV,yCAAK,SAAS,EAAC,MAAM,gBACnB,4CACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,eAAe,gBACd,+CAA+C,EAC1D,OAAO,EAAE,OAAO,2BAGT,IACL,CACP,KACG,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAE5E,mBAAmB;AACnB,kBAAe,QAAQ,CAAC"}
@@ -20,6 +20,8 @@ import ReactKitErrorCode from '../types/ReactKitErrorCode';
20
20
  type Props = {
21
21
  // Error to display
22
22
  error: any,
23
+ // Customized title of error box
24
+ title?: string,
23
25
  // Handler for close,
24
26
  onClose?: () => void,
25
27
  };
@@ -37,6 +39,7 @@ const ErrorBox: React.FC<Props> = (props) => {
37
39
 
38
40
  const {
39
41
  error,
42
+ title = 'An Error Occurred',
40
43
  onClose,
41
44
  } = props;
42
45
 
@@ -91,7 +94,7 @@ const ErrorBox: React.FC<Props> = (props) => {
91
94
  icon={faExclamationTriangle}
92
95
  className="me-2"
93
96
  />
94
- An Error Occurred
97
+ {title}
95
98
  </h4>
96
99
  <div>
97
100
  {errorText}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Handle an error and respond to the client
3
+ * @author Gabe Abrams
4
+ * @param res express response
5
+ * @param error error info
6
+ * @param opts.err the error to send to the client
7
+ * or the error message
8
+ * @param [opts.code] an error code (only used if err.code is not
9
+ * included)
10
+ * @param [opts.status=500] the https status code to use
11
+ * defined)
12
+ */
13
+ declare const handleError: (res: any, error: any) => undefined;
14
+ export default handleError;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ // Import shared types
7
+ var ReactKitErrorCode_1 = __importDefault(require("../types/ReactKitErrorCode"));
8
+ /**
9
+ * Handle an error and respond to the client
10
+ * @author Gabe Abrams
11
+ * @param res express response
12
+ * @param error error info
13
+ * @param opts.err the error to send to the client
14
+ * or the error message
15
+ * @param [opts.code] an error code (only used if err.code is not
16
+ * included)
17
+ * @param [opts.status=500] the https status code to use
18
+ * defined)
19
+ */
20
+ var handleError = function (res, error) {
21
+ // Get the error message
22
+ var message;
23
+ if (error && error.message) {
24
+ message = (error.message || 'An unknown error occurred.');
25
+ }
26
+ else if (typeof error === 'string') {
27
+ message = (error.trim().length > 0
28
+ ? error
29
+ : 'An unknown error occurred.');
30
+ }
31
+ else {
32
+ message = 'An unknown error occurred.';
33
+ }
34
+ // Get the error code
35
+ var code = (error.code || ReactKitErrorCode_1.default.NoCode);
36
+ // Get the status code
37
+ var status = (error.status || 500);
38
+ // Respond to user
39
+ res
40
+ // Set the http status code
41
+ .status(status)
42
+ // Send a JSON response
43
+ .json({
44
+ // Error message
45
+ message: message,
46
+ // Error code
47
+ code: code,
48
+ // Success = false flag so client can detect server-side errors
49
+ success: false,
50
+ });
51
+ return undefined;
52
+ };
53
+ exports.default = handleError;
54
+ //# sourceMappingURL=handleError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleError.js","sourceRoot":"","sources":["../../src/helpers/handleError.ts"],"names":[],"mappings":";;;;;AAAA,sBAAsB;AACtB,iFAA2D;AAE3D;;;;;;;;;;;GAWG;AACH,IAAM,WAAW,GAAG,UAClB,GAAQ,EACR,KASC;IAED,wBAAwB;IACxB,IAAI,OAAO,CAAC;IACZ,IAAI,KAAK,IAAK,KAAa,CAAC,OAAO,EAAE;QACnC,OAAO,GAAG,CAAC,KAAK,CAAC,OAAO,IAAI,4BAA4B,CAAC,CAAC;KAC3D;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACpC,OAAO,GAAG,CACR,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;YACrB,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,4BAA4B,CACjC,CAAC;KACH;SAAM;QACL,OAAO,GAAG,4BAA4B,CAAC;KACxC;IAED,qBAAqB;IACrB,IAAM,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,2BAAiB,CAAC,MAAM,CAAC,CAAC;IAEtD,sBAAsB;IACtB,IAAM,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC;IAErC,kBAAkB;IAClB,GAAG;QACD,2BAA2B;SAC1B,MAAM,CAAC,MAAM,CAAC;QACf,uBAAuB;SACtB,IAAI,CAAC;QACJ,gBAAgB;QAChB,OAAO,SAAA;QACP,aAAa;QACb,IAAI,MAAA;QACJ,+DAA+D;QAC/D,OAAO,EAAE,KAAK;KACf,CAAC,CAAC;IACL,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF,kBAAe,WAAW,CAAC"}
@@ -0,0 +1,65 @@
1
+ // Import shared types
2
+ import ReactKitErrorCode from '../types/ReactKitErrorCode';
3
+
4
+ /**
5
+ * Handle an error and respond to the client
6
+ * @author Gabe Abrams
7
+ * @param res express response
8
+ * @param error error info
9
+ * @param opts.err the error to send to the client
10
+ * or the error message
11
+ * @param [opts.code] an error code (only used if err.code is not
12
+ * included)
13
+ * @param [opts.status=500] the https status code to use
14
+ * defined)
15
+ */
16
+ const handleError = (
17
+ res: any,
18
+ error: (
19
+ | {
20
+ message: any,
21
+ code?: string,
22
+ status?: number,
23
+ }
24
+ | Error
25
+ | string
26
+ | any
27
+ ),
28
+ ): undefined => {
29
+ // Get the error message
30
+ let message;
31
+ if (error && (error as any).message) {
32
+ message = (error.message || 'An unknown error occurred.');
33
+ } else if (typeof error === 'string') {
34
+ message = (
35
+ error.trim().length > 0
36
+ ? error
37
+ : 'An unknown error occurred.'
38
+ );
39
+ } else {
40
+ message = 'An unknown error occurred.';
41
+ }
42
+
43
+ // Get the error code
44
+ const code = (error.code || ReactKitErrorCode.NoCode);
45
+
46
+ // Get the status code
47
+ const status = (error.status || 500);
48
+
49
+ // Respond to user
50
+ res
51
+ // Set the http status code
52
+ .status(status)
53
+ // Send a JSON response
54
+ .json({
55
+ // Error message
56
+ message,
57
+ // Error code
58
+ code,
59
+ // Success = false flag so client can detect server-side errors
60
+ success: false,
61
+ });
62
+ return undefined;
63
+ };
64
+
65
+ export default handleError;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Send successful API response
3
+ * @author Gabe Abrams
4
+ * @param res express response
5
+ * @param body the body of the response to send to the client
6
+ */
7
+ declare const handleSuccess: (res: any, body: any) => undefined;
8
+ export default handleSuccess;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Send successful API response
5
+ * @author Gabe Abrams
6
+ * @param res express response
7
+ * @param body the body of the response to send to the client
8
+ */
9
+ var handleSuccess = function (res, body) {
10
+ // Send a http 200 json response
11
+ res.json({
12
+ // Include the body as a parameter
13
+ body: body,
14
+ // Success = true flag so client can detect successful responses
15
+ success: true,
16
+ });
17
+ return undefined;
18
+ };
19
+ exports.default = handleSuccess;
20
+ //# sourceMappingURL=handleSuccess.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handleSuccess.js","sourceRoot":"","sources":["../../src/helpers/handleSuccess.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,IAAM,aAAa,GAAG,UAAC,GAAQ,EAAE,IAAS;IACxC,gCAAgC;IAChC,GAAG,CAAC,IAAI,CAAC;QACP,kCAAkC;QAClC,IAAI,MAAA;QACJ,gEAAgE;QAChE,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF,kBAAe,aAAa,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Send successful API response
3
+ * @author Gabe Abrams
4
+ * @param res express response
5
+ * @param body the body of the response to send to the client
6
+ */
7
+ const handleSuccess = (res: any, body: any): undefined => {
8
+ // Send a http 200 json response
9
+ res.json({
10
+ // Include the body as a parameter
11
+ body,
12
+ // Success = true flag so client can detect successful responses
13
+ success: true,
14
+ });
15
+ return undefined;
16
+ };
17
+
18
+ export default handleSuccess;
File without changes
File without changes
@@ -0,0 +1,21 @@
1
+ import ParamType from '../types/ParamType';
2
+ /**
3
+ * Parse express request params and body
4
+ * @author Gabe Abrams
5
+ * @param opts object containing all arguments
6
+ * @param opts.req express request instance
7
+ * @param opts.res express response instance
8
+ * @param opts.params map of parameters that should be parsed out of the request
9
+ * @returns parsed params + user info from session (if it exists) or undefined
10
+ * if an error occurred
11
+ */
12
+ declare const parseRequest: (opts: {
13
+ req: any;
14
+ res: any;
15
+ params: {
16
+ [x: string]: ParamType;
17
+ };
18
+ }) => {
19
+ [x: string]: any;
20
+ };
21
+ export default parseRequest;