dce-reactkit 2.0.1 → 2.0.4
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/lib/components/AppWrapper.d.ts +19 -0
- package/lib/components/AppWrapper.js +127 -0
- package/lib/components/AppWrapper.js.map +1 -0
- package/lib/components/ErrorBox.d.ts +12 -0
- package/lib/components/ErrorBox.js +65 -0
- package/lib/components/ErrorBox.js.map +1 -0
- package/lib/errors/ErrorWithCode.d.ts +9 -0
- package/lib/errors/ErrorWithCode.js +33 -0
- package/lib/errors/ErrorWithCode.js.map +1 -0
- package/lib/helpers/handleError.d.ts +14 -0
- package/lib/helpers/handleError.js +54 -0
- package/lib/helpers/handleError.js.map +1 -0
- package/lib/helpers/handleSuccess.d.ts +8 -0
- package/lib/helpers/handleSuccess.js +20 -0
- package/lib/helpers/handleSuccess.js.map +1 -0
- package/lib/helpers/parseRequest.d.ts +21 -0
- package/lib/helpers/parseRequest.js +240 -0
- package/lib/helpers/parseRequest.js.map +1 -0
- package/lib/helpers/showFatalError.d.ts +2 -0
- package/lib/helpers/showFatalError.js +5 -0
- package/lib/helpers/showFatalError.js.map +1 -0
- package/lib/helpers/visitServerEndpoint.d.ts +23 -0
- package/lib/helpers/visitServerEndpoint.js +135 -0
- package/lib/helpers/visitServerEndpoint.js.map +1 -0
- package/lib/types/ParamType.d.ts +17 -0
- package/lib/types/ParamType.js +21 -0
- package/lib/types/ParamType.js.map +1 -0
- package/lib/types/ReactKitErrorCode.d.ts +13 -0
- package/lib/types/ReactKitErrorCode.js +18 -0
- package/lib/types/ReactKitErrorCode.js.map +1 -0
- package/package.json +3 -1
- package/src/components/AppWrapper.tsx +177 -0
- package/src/components/ErrorBox.tsx +124 -0
- package/src/errors/ErrorWithCode.tsx +15 -0
- package/src/helpers/handleError.ts +65 -0
- package/src/helpers/handleSuccess.ts +18 -0
- package/src/helpers/parseRequest.ts +299 -0
- package/src/helpers/showFatalError.tsx +3 -0
- package/src/helpers/visitServerEndpoint.tsx +110 -0
- package/src/types/ParamType.ts +18 -0
- package/src/types/ReactKitErrorCode.tsx +16 -0
- package/tsconfig.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseRequest.js","sourceRoot":"","sources":["../../src/helpers/parseRequest.ts"],"names":[],"mappings":";;;;;AAAA,oBAAoB;AACpB,uCAA0C;AAE1C,sBAAsB;AACtB,iFAA2D;AAC3D,iEAA2C;AAE3C,iBAAiB;AACjB,8DAAwC;AAExC;;;;;;;;;GASG;AACH,IAAM,YAAY,GAAG,UACnB,IAMC;IAED,SAAS;IAET,IAAM,MAAM,GAA2B,EAAE,CAAC;IAE1C,4CAA4C;IAC5C,4CAA4C;IAC5C,4CAA4C;IAE5C,2BAA2B;IAC3B,IAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACnC,IAAA,KAAe,SAAS,CAAC,CAAC,CAAC,EAA1B,MAAI,QAAA,EAAE,IAAI,QAAgB,CAAC;QAElC,6BAA6B;QAC7B,IAAM,KAAK,GAAG,CACZ,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAI,CAAC;eAClB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAI,CAAC;eACpB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAI,CAAC,CACvB,CAAC;QAEF,QAAQ;QACR,IAAI,IAAI,KAAK,mBAAS,CAAC,OAAO,IAAI,IAAI,KAAK,mBAAS,CAAC,eAAe,EAAE;YACpE,UAAU;YAEV,wCAAwC;YACxC,IAAI,KAAK,KAAK,SAAS,EAAE;gBACvB,IAAI,IAAI,KAAK,mBAAS,CAAC,eAAe,EAAE;oBACtC,MAAM,CAAC,MAAI,CAAC,GAAG,SAAS,CAAC;iBAC1B;qBAA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M,CAAC,SAAS,GAAG,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC;IAC1C,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC;IAClC,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC;IACtC,MAAM,CAAC,mBAAmB,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAEtE,4CAA4C;IAC5C,4CAA4C;IAC5C,4CAA4C;IAE5C,mEAAmE;IACnE,IACE,MAAM,CAAC,QAAQ;WACZ,UAAU,CAAC,QAAQ;WACnB,MAAM,CAAC,QAAQ,KAAK,UAAU,CAAC,QAAQ;WACvC,CAAC,MAAM,CAAC,KAAK;WACb,CAAC,MAAM,CAAC,OAAO,EAClB;QACA,8CAA8C;QAC9C,OAAO,IAAA,qBAAW,EAChB,IAAI,CAAC,GAAG,EACR;YACE,OAAO,EAAE,6GAA6G;YACtH,IAAI,EAAE,2BAAiB,CAAC,WAAW;YACnC,MAAM,EAAE,GAAG;SACZ,CACF,CAAC;KACH;IAED,0BAA0B;IAC1B,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,kBAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"showFatalError.js","sourceRoot":"","sources":["../../src/helpers/showFatalError.tsx"],"names":[],"mappings":";;AAAA,uDAA0D;AAE1D,kBAAe,2BAAc,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set the session expiry handler
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
* @param handler new handler to use when session expires
|
|
5
|
+
*/
|
|
6
|
+
export declare const setSessionExpiryHandler: (handler: () => void) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Visit an endpoint on the server [for client only]
|
|
9
|
+
* @author Gabe Abrams
|
|
10
|
+
* @param opts object containing all arguments
|
|
11
|
+
* @param opts.path - the path of the server endpoint
|
|
12
|
+
* @param [opts.method=GET] - the method of the endpoint
|
|
13
|
+
* @param [opts.params] - query/body parameters to include
|
|
14
|
+
* @returns response from server
|
|
15
|
+
*/
|
|
16
|
+
declare const visitServerEndpoint: (opts: {
|
|
17
|
+
path: string;
|
|
18
|
+
method?: ('GET' | 'POST' | 'DELETE' | 'PUT');
|
|
19
|
+
params?: {
|
|
20
|
+
[x: string]: any;
|
|
21
|
+
};
|
|
22
|
+
}) => Promise<any>;
|
|
23
|
+
export default visitServerEndpoint;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.setSessionExpiryHandler = void 0;
|
|
43
|
+
// Initialize caccl
|
|
44
|
+
var client_1 = require("caccl/client");
|
|
45
|
+
// Import custom error
|
|
46
|
+
var ErrorWithCode_1 = __importDefault(require("../errors/ErrorWithCode"));
|
|
47
|
+
var ReactKitErrorCode_1 = __importDefault(require("../types/ReactKitErrorCode"));
|
|
48
|
+
/*------------------------------------------------------------------------*/
|
|
49
|
+
/* Listener */
|
|
50
|
+
/*------------------------------------------------------------------------*/
|
|
51
|
+
// Handler for session expiry
|
|
52
|
+
var sessionExpiryHandler;
|
|
53
|
+
// Keep track of whether or not session expiry has already been handled
|
|
54
|
+
var sessionAlreadyExpired = false;
|
|
55
|
+
/**
|
|
56
|
+
* Set the session expiry handler
|
|
57
|
+
* @author Gabe Abrams
|
|
58
|
+
* @param handler new handler to use when session expires
|
|
59
|
+
*/
|
|
60
|
+
var setSessionExpiryHandler = function (handler) {
|
|
61
|
+
sessionExpiryHandler = handler;
|
|
62
|
+
};
|
|
63
|
+
exports.setSessionExpiryHandler = setSessionExpiryHandler;
|
|
64
|
+
/*------------------------------------------------------------------------*/
|
|
65
|
+
/* Main */
|
|
66
|
+
/*------------------------------------------------------------------------*/
|
|
67
|
+
/**
|
|
68
|
+
* Visit an endpoint on the server [for client only]
|
|
69
|
+
* @author Gabe Abrams
|
|
70
|
+
* @param opts object containing all arguments
|
|
71
|
+
* @param opts.path - the path of the server endpoint
|
|
72
|
+
* @param [opts.method=GET] - the method of the endpoint
|
|
73
|
+
* @param [opts.params] - query/body parameters to include
|
|
74
|
+
* @returns response from server
|
|
75
|
+
*/
|
|
76
|
+
var visitServerEndpoint = function (opts) { return __awaiter(void 0, void 0, void 0, function () {
|
|
77
|
+
var response, body;
|
|
78
|
+
return __generator(this, function (_a) {
|
|
79
|
+
switch (_a.label) {
|
|
80
|
+
case 0: return [4 /*yield*/, (0, client_1.sendRequest)({
|
|
81
|
+
path: opts.path,
|
|
82
|
+
method: opts.method,
|
|
83
|
+
params: opts.params,
|
|
84
|
+
})];
|
|
85
|
+
case 1:
|
|
86
|
+
response = _a.sent();
|
|
87
|
+
// Check for failure
|
|
88
|
+
if (!response || !response.body) {
|
|
89
|
+
throw new ErrorWithCode_1.default('We didn\'t get a response from the server. Please check your internet connection.', ReactKitErrorCode_1.default.NoResponse);
|
|
90
|
+
}
|
|
91
|
+
if (!!response.body.success) return [3 /*break*/, 6];
|
|
92
|
+
if (!(response.body.code === ReactKitErrorCode_1.default.SessionExpired)) return [3 /*break*/, 5];
|
|
93
|
+
if (!sessionAlreadyExpired) return [3 /*break*/, 3];
|
|
94
|
+
// Never return (browser is already reloading)
|
|
95
|
+
return [4 /*yield*/, new Promise(function () {
|
|
96
|
+
// Promise that never returns
|
|
97
|
+
})];
|
|
98
|
+
case 2:
|
|
99
|
+
// Never return (browser is already reloading)
|
|
100
|
+
_a.sent();
|
|
101
|
+
_a.label = 3;
|
|
102
|
+
case 3:
|
|
103
|
+
sessionAlreadyExpired = true;
|
|
104
|
+
// Show session expiration message
|
|
105
|
+
if (sessionExpiryHandler) {
|
|
106
|
+
// Use handler
|
|
107
|
+
sessionExpiryHandler();
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
// Fallback to alert
|
|
111
|
+
// eslint-disable-next-line no-alert
|
|
112
|
+
alert('Your session has expired. Please start over.');
|
|
113
|
+
}
|
|
114
|
+
// Never return (don't continue execution)
|
|
115
|
+
return [4 /*yield*/, new Promise(function () {
|
|
116
|
+
// Promise that never returns
|
|
117
|
+
})];
|
|
118
|
+
case 4:
|
|
119
|
+
// Never return (don't continue execution)
|
|
120
|
+
_a.sent();
|
|
121
|
+
_a.label = 5;
|
|
122
|
+
case 5:
|
|
123
|
+
// Other errors
|
|
124
|
+
throw new ErrorWithCode_1.default((response.body.message
|
|
125
|
+
|| 'An unknown error occurred. Please contact an admin.'), (response.body.code
|
|
126
|
+
|| ReactKitErrorCode_1.default.NoCode));
|
|
127
|
+
case 6:
|
|
128
|
+
body = response.body.body;
|
|
129
|
+
// Return
|
|
130
|
+
return [2 /*return*/, body];
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}); };
|
|
134
|
+
exports.default = visitServerEndpoint;
|
|
135
|
+
//# sourceMappingURL=visitServerEndpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visitServerEndpoint.js","sourceRoot":"","sources":["../../src/helpers/visitServerEndpoint.tsx"],"names":[],"mappings":";;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;gBAClC,IAAI,oBAAoB,EAAE;oBACxB,cAAc;oBACd,oBAAoB,EAAE,CAAC;iBACxB;qBAAM;oBACL,oBAAoB;oBAEpB,oCAAoC;oBACpC,KAAK,CAAC,8CAA8C,CAAC,CAAC;iBACvD;gBAED,0CAA0C;gBAC1C,qBAAM,IAAI,OAAO,CAA2B;wBAC1C,6BAA6B;oBAC/B,CAAC,CAAC,EAAA;;gBAHF,0CAA0C;gBAC1C,SAEE,CAAC;;;YAGL,eAAe;YACf,MAAM,IAAI,uBAAa,CACrB,CACE,QAAQ,CAAC,IAAI,CAAC,OAAO;mBAClB,qDAAqD,CACzD,EACD,CACE,QAAQ,CAAC,IAAI,CAAC,IAAI;mBACf,2BAAiB,CAAC,MAAM,CAC5B,CACF,CAAC;;gBAII,IAAI,GAAK,QAAQ,CAAC,IAAI,KAAlB,CAAmB;gBAE/B,SAAS;gBACT,sBAAO,IAAI,EAAC;;;KACb,CAAC;AAEF,kBAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API param types
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
*/
|
|
5
|
+
declare enum ParamType {
|
|
6
|
+
Boolean = "boolean",
|
|
7
|
+
BooleanOptional = "boolean-optional",
|
|
8
|
+
Float = "float",
|
|
9
|
+
FloatOptional = "float-optional",
|
|
10
|
+
Int = "int",
|
|
11
|
+
IntOptional = "int-optional",
|
|
12
|
+
JSON = "json",
|
|
13
|
+
JSONOptional = "json-optional",
|
|
14
|
+
String = "string",
|
|
15
|
+
StringOptional = "string-optional"
|
|
16
|
+
}
|
|
17
|
+
export default ParamType;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* API param types
|
|
5
|
+
* @author Gabe Abrams
|
|
6
|
+
*/
|
|
7
|
+
var ParamType;
|
|
8
|
+
(function (ParamType) {
|
|
9
|
+
ParamType["Boolean"] = "boolean";
|
|
10
|
+
ParamType["BooleanOptional"] = "boolean-optional";
|
|
11
|
+
ParamType["Float"] = "float";
|
|
12
|
+
ParamType["FloatOptional"] = "float-optional";
|
|
13
|
+
ParamType["Int"] = "int";
|
|
14
|
+
ParamType["IntOptional"] = "int-optional";
|
|
15
|
+
ParamType["JSON"] = "json";
|
|
16
|
+
ParamType["JSONOptional"] = "json-optional";
|
|
17
|
+
ParamType["String"] = "string";
|
|
18
|
+
ParamType["StringOptional"] = "string-optional";
|
|
19
|
+
})(ParamType || (ParamType = {}));
|
|
20
|
+
exports.default = ParamType;
|
|
21
|
+
//# sourceMappingURL=ParamType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ParamType.js","sourceRoot":"","sources":["../../src/types/ParamType.ts"],"names":[],"mappings":";;AAAA;;;GAGG;AACH,IAAK,SAWJ;AAXD,WAAK,SAAS;IACZ,gCAAmB,CAAA;IACnB,iDAAoC,CAAA;IACpC,4BAAe,CAAA;IACf,6CAAgC,CAAA;IAChC,wBAAW,CAAA;IACX,yCAA4B,CAAA;IAC5B,0BAAa,CAAA;IACb,2CAA8B,CAAA;IAC9B,8BAAiB,CAAA;IACjB,+CAAkC,CAAA;AACpC,CAAC,EAXI,SAAS,KAAT,SAAS,QAWb;AAED,kBAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List of error codes built into the react kit
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
*/
|
|
5
|
+
declare enum ReactKitErrorCode {
|
|
6
|
+
NoResponse = "DRK1",
|
|
7
|
+
NoCode = "DRK2",
|
|
8
|
+
SessionExpired = "DRK3",
|
|
9
|
+
MissingParameter = "DRK4",
|
|
10
|
+
InvalidParameter = "DRK5",
|
|
11
|
+
WrongCourse = "DRK6"
|
|
12
|
+
}
|
|
13
|
+
export default ReactKitErrorCode;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Highest error code = DRK2
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
/**
|
|
5
|
+
* List of error codes built into the react kit
|
|
6
|
+
* @author Gabe Abrams
|
|
7
|
+
*/
|
|
8
|
+
var ReactKitErrorCode;
|
|
9
|
+
(function (ReactKitErrorCode) {
|
|
10
|
+
ReactKitErrorCode["NoResponse"] = "DRK1";
|
|
11
|
+
ReactKitErrorCode["NoCode"] = "DRK2";
|
|
12
|
+
ReactKitErrorCode["SessionExpired"] = "DRK3";
|
|
13
|
+
ReactKitErrorCode["MissingParameter"] = "DRK4";
|
|
14
|
+
ReactKitErrorCode["InvalidParameter"] = "DRK5";
|
|
15
|
+
ReactKitErrorCode["WrongCourse"] = "DRK6";
|
|
16
|
+
})(ReactKitErrorCode || (ReactKitErrorCode = {}));
|
|
17
|
+
exports.default = ReactKitErrorCode;
|
|
18
|
+
//# sourceMappingURL=ReactKitErrorCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactKitErrorCode.js","sourceRoot":"","sources":["../../src/types/ReactKitErrorCode.tsx"],"names":[],"mappings":";AAAA,4BAA4B;;AAE5B;;;GAGG;AACH,IAAK,iBAOJ;AAPD,WAAK,iBAAiB;IACpB,wCAAmB,CAAA;IACnB,oCAAe,CAAA;IACf,4CAAuB,CAAA;IACvB,8CAAyB,CAAA;IACzB,8CAAyB,CAAA;IACzB,yCAAoB,CAAA;AACtB,CAAC,EAPI,iBAAiB,KAAjB,iBAAiB,QAOrB;AAED,kBAAe,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dce-reactkit",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"module": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,9 +18,11 @@
|
|
|
18
18
|
"@fortawesome/free-regular-svg-icons": "^6.1.1",
|
|
19
19
|
"@fortawesome/free-solid-svg-icons": "^6.1.1",
|
|
20
20
|
"@fortawesome/react-fontawesome": "^0.1.18",
|
|
21
|
+
"caccl": "^2.0.0-beta.39",
|
|
21
22
|
"react-bootstrap": "^2.2.3"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
25
|
+
"@types/express": "^4.17.13",
|
|
24
26
|
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
|
25
27
|
"@typescript-eslint/parser": "^5.18.0",
|
|
26
28
|
"eslint": "^8.12.0",
|
|
@@ -0,0 +1,177 @@
|
|
|
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
|
+
|
|
7
|
+
// Import React
|
|
8
|
+
import React, { useState, useEffect } from 'react';
|
|
9
|
+
|
|
10
|
+
// Import shared components
|
|
11
|
+
import ErrorBox from './ErrorBox';
|
|
12
|
+
|
|
13
|
+
// Import helpers
|
|
14
|
+
import { setSessionExpiryHandler } from '../helpers/visitServerEndpoint';
|
|
15
|
+
|
|
16
|
+
// Import shared types
|
|
17
|
+
import ReactKitErrorCode from '../types/ReactKitErrorCode';
|
|
18
|
+
|
|
19
|
+
// Import custom errors
|
|
20
|
+
import ErrorWithCode from '../errors/ErrorWithCode';
|
|
21
|
+
|
|
22
|
+
/*------------------------------------------------------------------------*/
|
|
23
|
+
/* Props */
|
|
24
|
+
/*------------------------------------------------------------------------*/
|
|
25
|
+
|
|
26
|
+
type Props = {
|
|
27
|
+
// The entire app
|
|
28
|
+
children: React.ReactNode,
|
|
29
|
+
// True if this app is a dark-themed app
|
|
30
|
+
dark?: boolean,
|
|
31
|
+
// Custom session expired message
|
|
32
|
+
sessionExpiredMessage?: string,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/*------------------------------------------------------------------------*/
|
|
36
|
+
/* Static Helpers */
|
|
37
|
+
/*------------------------------------------------------------------------*/
|
|
38
|
+
|
|
39
|
+
// Stored copies of setters
|
|
40
|
+
let setFatalErrorMessage: (message: string) => void;
|
|
41
|
+
let setFatalErrorCode: (code: string) => void;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Show a fatal error message
|
|
45
|
+
* @author Gabe Abrams
|
|
46
|
+
* @param error the error to show
|
|
47
|
+
*/
|
|
48
|
+
export const showFatalError = (error: any) => {
|
|
49
|
+
// Determine message and code
|
|
50
|
+
const message: string = (
|
|
51
|
+
typeof error === 'string'
|
|
52
|
+
? error.trim()
|
|
53
|
+
: String(error.message ?? 'An unknown error occurred.')
|
|
54
|
+
);
|
|
55
|
+
const code: string = (
|
|
56
|
+
typeof error === 'string'
|
|
57
|
+
? ReactKitErrorCode.NoCode
|
|
58
|
+
: String(error.code ?? ReactKitErrorCode.NoCode)
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// Handle case where app hasn't loaded
|
|
62
|
+
if (!setFatalErrorMessage || !setFatalErrorCode) {
|
|
63
|
+
return alert(`An error has occurred: ${message} (code: ${code}). Please contact support.`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Use setters
|
|
67
|
+
setFatalErrorMessage(message);
|
|
68
|
+
setFatalErrorCode(code);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/*------------------------------------------------------------------------*/
|
|
72
|
+
/* Component */
|
|
73
|
+
/*------------------------------------------------------------------------*/
|
|
74
|
+
|
|
75
|
+
const AppWrapper = (props: Props) => {
|
|
76
|
+
/*------------------------------------------------------------------------*/
|
|
77
|
+
/* Setup */
|
|
78
|
+
/*------------------------------------------------------------------------*/
|
|
79
|
+
|
|
80
|
+
/* -------------- Props ------------- */
|
|
81
|
+
|
|
82
|
+
const {
|
|
83
|
+
children,
|
|
84
|
+
dark,
|
|
85
|
+
sessionExpiredMessage = 'Your session has expired. Please go back to Canvas and start over.',
|
|
86
|
+
} = props;
|
|
87
|
+
|
|
88
|
+
/* -------------- State ------------- */
|
|
89
|
+
|
|
90
|
+
// Fatal error
|
|
91
|
+
const [fatalErrorMessage, setFatalErrorMessageInner] = useState(null);
|
|
92
|
+
setFatalErrorMessage = setFatalErrorMessageInner;
|
|
93
|
+
const [fatalErrorCode, setFatalErrorCodeInner] = useState(null);
|
|
94
|
+
setFatalErrorCode = setFatalErrorCodeInner;
|
|
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
|
+
|
|
122
|
+
/*----------------------------------------*/
|
|
123
|
+
/* Main UI */
|
|
124
|
+
/*----------------------------------------*/
|
|
125
|
+
|
|
126
|
+
// Show error
|
|
127
|
+
if (fatalErrorMessage || fatalErrorCode || sessionHasExpired) {
|
|
128
|
+
// Re-encapsulate in an error
|
|
129
|
+
const error = (
|
|
130
|
+
sessionHasExpired
|
|
131
|
+
? new ErrorWithCode(
|
|
132
|
+
fatalErrorMessage,
|
|
133
|
+
fatalErrorCode,
|
|
134
|
+
)
|
|
135
|
+
: new ErrorWithCode(
|
|
136
|
+
sessionExpiredMessage,
|
|
137
|
+
ReactKitErrorCode.SessionExpired,
|
|
138
|
+
)
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// Build error screen
|
|
142
|
+
return (
|
|
143
|
+
<div
|
|
144
|
+
style={{
|
|
145
|
+
display: 'block',
|
|
146
|
+
width: '100vw',
|
|
147
|
+
minHeight: '100vh',
|
|
148
|
+
paddingTop: '10rem',
|
|
149
|
+
backgroundColor: (
|
|
150
|
+
dark
|
|
151
|
+
? '#222'
|
|
152
|
+
: '#fff'
|
|
153
|
+
),
|
|
154
|
+
}}
|
|
155
|
+
>
|
|
156
|
+
<ErrorBox
|
|
157
|
+
title={(
|
|
158
|
+
sessionHasExpired
|
|
159
|
+
? 'Session Expired'
|
|
160
|
+
: undefined
|
|
161
|
+
)}
|
|
162
|
+
error={error}
|
|
163
|
+
/>
|
|
164
|
+
</div>
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Show the app itself
|
|
169
|
+
return children;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
/*------------------------------------------------------------------------*/
|
|
173
|
+
/* Wrap Up */
|
|
174
|
+
/*------------------------------------------------------------------------*/
|
|
175
|
+
|
|
176
|
+
// Export component
|
|
177
|
+
export default AppWrapper;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Displays an error
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Import React
|
|
7
|
+
import React from 'react';
|
|
8
|
+
|
|
9
|
+
// Import FontAwesome Icons
|
|
10
|
+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
11
|
+
import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
|
|
12
|
+
|
|
13
|
+
// Import shared types
|
|
14
|
+
import ReactKitErrorCode from '../types/ReactKitErrorCode';
|
|
15
|
+
|
|
16
|
+
/*------------------------------------------------------------------------*/
|
|
17
|
+
/* Types */
|
|
18
|
+
/*------------------------------------------------------------------------*/
|
|
19
|
+
|
|
20
|
+
type Props = {
|
|
21
|
+
// Error to display
|
|
22
|
+
error: any,
|
|
23
|
+
// Customized title of error box
|
|
24
|
+
title?: string,
|
|
25
|
+
// Handler for close,
|
|
26
|
+
onClose?: () => void,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/*------------------------------------------------------------------------*/
|
|
30
|
+
/* Component */
|
|
31
|
+
/*------------------------------------------------------------------------*/
|
|
32
|
+
|
|
33
|
+
const ErrorBox: React.FC<Props> = (props) => {
|
|
34
|
+
/*------------------------------------------------------------------------*/
|
|
35
|
+
/* Setup */
|
|
36
|
+
/*------------------------------------------------------------------------*/
|
|
37
|
+
|
|
38
|
+
/* -------------- Props ------------- */
|
|
39
|
+
|
|
40
|
+
const {
|
|
41
|
+
error,
|
|
42
|
+
title = 'An Error Occurred',
|
|
43
|
+
onClose,
|
|
44
|
+
} = props;
|
|
45
|
+
|
|
46
|
+
/*------------------------------------------------------------------------*/
|
|
47
|
+
/* Render */
|
|
48
|
+
/*------------------------------------------------------------------------*/
|
|
49
|
+
|
|
50
|
+
// Determine error text
|
|
51
|
+
const errorText: string = (
|
|
52
|
+
typeof error === 'string'
|
|
53
|
+
? error.trim()
|
|
54
|
+
: String(error.message || 'An unknown error occurred. Please contact support.')
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// Error code box
|
|
58
|
+
let errorCodeBox;
|
|
59
|
+
if (error && (error as any).code) {
|
|
60
|
+
errorCodeBox = (
|
|
61
|
+
<span>
|
|
62
|
+
{' '}
|
|
63
|
+
<span
|
|
64
|
+
style={{
|
|
65
|
+
backgroundColor: 'white',
|
|
66
|
+
borderRadius: '5px',
|
|
67
|
+
paddingLeft: '3px',
|
|
68
|
+
paddingRight: '3px',
|
|
69
|
+
color: '#DC4150',
|
|
70
|
+
fontVariant: 'small-caps',
|
|
71
|
+
fontSize: '80%',
|
|
72
|
+
whiteSpace: 'nowrap',
|
|
73
|
+
}}
|
|
74
|
+
>
|
|
75
|
+
code:
|
|
76
|
+
{' '}
|
|
77
|
+
{String((error as any).code ?? ReactKitErrorCode.NoCode).toUpperCase()}
|
|
78
|
+
</span>
|
|
79
|
+
</span>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Main UI
|
|
84
|
+
return (
|
|
85
|
+
<div
|
|
86
|
+
className="alert alert-danger text-center"
|
|
87
|
+
style={{
|
|
88
|
+
maxWidth: '650px',
|
|
89
|
+
margin: 'auto',
|
|
90
|
+
}}
|
|
91
|
+
>
|
|
92
|
+
<h4 className="mb-1">
|
|
93
|
+
<FontAwesomeIcon
|
|
94
|
+
icon={faExclamationTriangle}
|
|
95
|
+
className="me-2"
|
|
96
|
+
/>
|
|
97
|
+
{title}
|
|
98
|
+
</h4>
|
|
99
|
+
<div>
|
|
100
|
+
{errorText}
|
|
101
|
+
{errorCodeBox}
|
|
102
|
+
</div>
|
|
103
|
+
{onClose && (
|
|
104
|
+
<div className="mt-2">
|
|
105
|
+
<button
|
|
106
|
+
type="button"
|
|
107
|
+
className="btn btn-light"
|
|
108
|
+
aria-label="dismiss error and close this activity or view"
|
|
109
|
+
onClick={onClose}
|
|
110
|
+
>
|
|
111
|
+
Close
|
|
112
|
+
</button>
|
|
113
|
+
</div>
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/*------------------------------------------------------------------------*/
|
|
120
|
+
/* Wrap Up */
|
|
121
|
+
/*------------------------------------------------------------------------*/
|
|
122
|
+
|
|
123
|
+
// Export component
|
|
124
|
+
export default ErrorBox;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An error with a code
|
|
3
|
+
* @author Gabe Abrams
|
|
4
|
+
*/
|
|
5
|
+
class ErrorWithCode extends Error {
|
|
6
|
+
code: string;
|
|
7
|
+
|
|
8
|
+
constructor(message: string, code: string) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'ErrorWithCode';
|
|
11
|
+
this.code = code;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default ErrorWithCode;
|