dce-reactkit 2.0.10 → 3.0.0
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/cjs/index.js +2 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/lib/components/AppWrapper.d.ts +35 -0
- package/lib/{components → cjs/lib/components}/ErrorBox.d.ts +0 -0
- package/lib/{components → cjs/lib/components}/LoadingSpinner.d.ts +1 -0
- package/lib/cjs/lib/components/Modal.d.ts +40 -0
- package/lib/cjs/lib/components/TabBox.d.ts +11 -0
- package/lib/{errors → cjs/lib/errors}/ErrorWithCode.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/abbreviate.d.ts +1 -0
- package/lib/{helpers → cjs/lib/helpers}/avg.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/ceilToNumDecimals.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/floorToNumDecimals.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/forceNumIntoBounds.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/handleError.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/handleSuccess.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/padDecimalZeros.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/padZerosLeft.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/parseRequest.d.ts +1 -1
- package/lib/{helpers → cjs/lib/helpers}/roundToNumDecimals.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/sum.d.ts +0 -0
- package/lib/{helpers → cjs/lib/helpers}/visitServerEndpoint.d.ts +2 -2
- package/lib/{helpers → cjs/lib/helpers}/waitMs.d.ts +0 -0
- package/lib/cjs/lib/index.d.ts +27 -0
- package/lib/cjs/lib/types/ModalButtonType.d.ts +17 -0
- package/lib/cjs/lib/types/ModalSize.d.ts +11 -0
- package/lib/cjs/lib/types/ModalType.d.ts +16 -0
- package/lib/{types → cjs/lib/types}/ParamType.d.ts +0 -0
- package/lib/{types → cjs/lib/types}/ReactKitErrorCode.d.ts +0 -0
- package/lib/{types → cjs/lib/types}/Variant.d.ts +0 -0
- package/lib/cjs/types/components/AppWrapper.d.ts +40 -0
- package/lib/cjs/types/components/ErrorBox.d.ts +12 -0
- package/lib/cjs/types/components/LoadingSpinner.d.ts +7 -0
- package/lib/cjs/types/components/Modal.d.ts +40 -0
- package/lib/cjs/types/components/TabBox.d.ts +11 -0
- package/lib/cjs/types/errors/ErrorWithCode.d.ts +9 -0
- package/lib/cjs/types/helpers/abbreviate.d.ts +10 -0
- package/lib/cjs/types/helpers/alert.d.ts +2 -0
- package/lib/cjs/types/helpers/avg.d.ts +8 -0
- package/lib/cjs/types/helpers/ceilToNumDecimals.d.ts +9 -0
- package/lib/cjs/types/helpers/confirm.d.ts +2 -0
- package/lib/cjs/types/helpers/floorToNumDecimals.d.ts +9 -0
- package/lib/cjs/types/helpers/forceNumIntoBounds.d.ts +10 -0
- package/lib/cjs/types/helpers/handleError.d.ts +14 -0
- package/lib/cjs/types/helpers/handleSuccess.d.ts +8 -0
- package/lib/cjs/types/helpers/padDecimalZeros.d.ts +10 -0
- package/lib/cjs/types/helpers/padZerosLeft.d.ts +9 -0
- package/lib/cjs/types/helpers/parseRequest.d.ts +21 -0
- package/lib/cjs/types/helpers/roundToNumDecimals.d.ts +9 -0
- package/lib/cjs/types/helpers/showFatalError.d.ts +2 -0
- package/lib/cjs/types/helpers/sum.d.ts +8 -0
- package/lib/cjs/types/helpers/visitServerEndpoint.d.ts +23 -0
- package/lib/cjs/types/helpers/waitMs.d.ts +7 -0
- package/lib/cjs/types/index.d.ts +22 -0
- package/lib/cjs/types/types/ModalButtonType.d.ts +17 -0
- package/lib/cjs/types/types/ModalSize.d.ts +11 -0
- package/lib/cjs/types/types/ModalType.d.ts +16 -0
- package/lib/cjs/types/types/ParamType.d.ts +17 -0
- package/lib/cjs/types/types/ReactKitErrorCode.d.ts +13 -0
- package/lib/cjs/types/types/Variant.d.ts +15 -0
- package/lib/esm/index.js +16 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/lib/components/AppWrapper.d.ts +35 -0
- package/lib/esm/lib/components/ErrorBox.d.ts +12 -0
- package/lib/esm/lib/components/LoadingSpinner.d.ts +7 -0
- package/lib/esm/lib/components/Modal.d.ts +40 -0
- package/lib/esm/lib/components/TabBox.d.ts +11 -0
- package/lib/esm/lib/errors/ErrorWithCode.d.ts +9 -0
- package/lib/esm/lib/helpers/abbreviate.d.ts +10 -0
- package/lib/esm/lib/helpers/avg.d.ts +8 -0
- package/lib/esm/lib/helpers/ceilToNumDecimals.d.ts +9 -0
- package/lib/esm/lib/helpers/floorToNumDecimals.d.ts +9 -0
- package/lib/esm/lib/helpers/forceNumIntoBounds.d.ts +10 -0
- package/lib/esm/lib/helpers/handleError.d.ts +14 -0
- package/lib/esm/lib/helpers/handleSuccess.d.ts +8 -0
- package/lib/esm/lib/helpers/padDecimalZeros.d.ts +10 -0
- package/lib/esm/lib/helpers/padZerosLeft.d.ts +9 -0
- package/lib/esm/lib/helpers/parseRequest.d.ts +21 -0
- package/lib/esm/lib/helpers/roundToNumDecimals.d.ts +9 -0
- package/lib/esm/lib/helpers/sum.d.ts +8 -0
- package/lib/esm/lib/helpers/visitServerEndpoint.d.ts +23 -0
- package/lib/esm/lib/helpers/waitMs.d.ts +7 -0
- package/lib/esm/lib/index.d.ts +27 -0
- package/lib/esm/lib/types/ModalButtonType.d.ts +17 -0
- package/lib/esm/lib/types/ModalSize.d.ts +11 -0
- package/lib/esm/lib/types/ModalType.d.ts +16 -0
- package/lib/esm/lib/types/ParamType.d.ts +17 -0
- package/lib/esm/lib/types/ReactKitErrorCode.d.ts +13 -0
- package/lib/esm/lib/types/Variant.d.ts +15 -0
- package/lib/esm/types/components/AppWrapper.d.ts +40 -0
- package/lib/esm/types/components/ErrorBox.d.ts +12 -0
- package/lib/esm/types/components/LoadingSpinner.d.ts +7 -0
- package/lib/esm/types/components/Modal.d.ts +40 -0
- package/lib/esm/types/components/TabBox.d.ts +11 -0
- package/lib/esm/types/errors/ErrorWithCode.d.ts +9 -0
- package/lib/esm/types/helpers/abbreviate.d.ts +10 -0
- package/lib/esm/types/helpers/alert.d.ts +2 -0
- package/lib/esm/types/helpers/avg.d.ts +8 -0
- package/lib/esm/types/helpers/ceilToNumDecimals.d.ts +9 -0
- package/lib/esm/types/helpers/confirm.d.ts +2 -0
- package/lib/esm/types/helpers/floorToNumDecimals.d.ts +9 -0
- package/lib/esm/types/helpers/forceNumIntoBounds.d.ts +10 -0
- package/lib/esm/types/helpers/handleError.d.ts +14 -0
- package/lib/esm/types/helpers/handleSuccess.d.ts +8 -0
- package/lib/esm/types/helpers/padDecimalZeros.d.ts +10 -0
- package/lib/esm/types/helpers/padZerosLeft.d.ts +9 -0
- package/lib/esm/types/helpers/parseRequest.d.ts +21 -0
- package/lib/esm/types/helpers/roundToNumDecimals.d.ts +9 -0
- package/lib/esm/types/helpers/showFatalError.d.ts +2 -0
- package/lib/esm/types/helpers/sum.d.ts +8 -0
- package/lib/esm/types/helpers/visitServerEndpoint.d.ts +23 -0
- package/lib/esm/types/helpers/waitMs.d.ts +7 -0
- package/lib/esm/types/index.d.ts +22 -0
- package/lib/esm/types/types/ModalButtonType.d.ts +17 -0
- package/lib/esm/types/types/ModalSize.d.ts +11 -0
- package/lib/esm/types/types/ModalType.d.ts +16 -0
- package/lib/esm/types/types/ParamType.d.ts +17 -0
- package/lib/esm/types/types/ReactKitErrorCode.d.ts +13 -0
- package/lib/esm/types/types/Variant.d.ts +15 -0
- package/lib/index.d.ts +274 -0
- package/package.json +26 -5
- package/rollup.config.js +43 -0
- package/src/components/AppWrapper.tsx +212 -36
- package/src/components/LoadingSpinner.tsx +3 -0
- package/src/components/Modal.tsx +65 -95
- package/src/components/TabBox.tsx +136 -0
- package/src/helpers/abbreviate.tsx +2 -0
- package/src/helpers/padDecimalZeros.tsx +1 -1
- package/src/index.ts +61 -0
- package/src/types/ModalButtonType.tsx +18 -0
- package/src/types/ModalSize.tsx +12 -0
- package/src/types/ModalType.tsx +17 -0
- package/tsconfig.json +14 -17
- package/lib/components/AppWrapper.d.ts +0 -20
- package/lib/components/AppWrapper.js +0 -133
- package/lib/components/AppWrapper.js.map +0 -1
- package/lib/components/ErrorBox.js +0 -65
- package/lib/components/ErrorBox.js.map +0 -1
- package/lib/components/LoadingSpinner.js +0 -41
- package/lib/components/LoadingSpinner.js.map +0 -1
- package/lib/components/Modal.d.ts +0 -69
- package/lib/components/Modal.js +0 -315
- package/lib/components/Modal.js.map +0 -1
- package/lib/errors/ErrorWithCode.js +0 -33
- package/lib/errors/ErrorWithCode.js.map +0 -1
- package/lib/helpers/abbreviate.js +0 -21
- package/lib/helpers/abbreviate.js.map +0 -1
- package/lib/helpers/avg.js +0 -24
- package/lib/helpers/avg.js.map +0 -1
- package/lib/helpers/ceilToNumDecimals.js +0 -15
- package/lib/helpers/ceilToNumDecimals.js.map +0 -1
- package/lib/helpers/floorToNumDecimals.js +0 -15
- package/lib/helpers/floorToNumDecimals.js.map +0 -1
- package/lib/helpers/forceNumIntoBounds.js +0 -15
- package/lib/helpers/forceNumIntoBounds.js.map +0 -1
- package/lib/helpers/handleError.js +0 -54
- package/lib/helpers/handleError.js.map +0 -1
- package/lib/helpers/handleSuccess.js +0 -20
- package/lib/helpers/handleSuccess.js.map +0 -1
- package/lib/helpers/padDecimalZeros.js +0 -30
- package/lib/helpers/padDecimalZeros.js.map +0 -1
- package/lib/helpers/padZerosLeft.js +0 -21
- package/lib/helpers/padZerosLeft.js.map +0 -1
- package/lib/helpers/parseRequest.js +0 -240
- package/lib/helpers/parseRequest.js.map +0 -1
- package/lib/helpers/roundToNumDecimals.js +0 -15
- package/lib/helpers/roundToNumDecimals.js.map +0 -1
- package/lib/helpers/showFatalError.d.ts +0 -2
- package/lib/helpers/showFatalError.js +0 -5
- package/lib/helpers/showFatalError.js.map +0 -1
- package/lib/helpers/sum.js +0 -15
- package/lib/helpers/sum.js.map +0 -1
- package/lib/helpers/visitServerEndpoint.js +0 -135
- package/lib/helpers/visitServerEndpoint.js.map +0 -1
- package/lib/helpers/waitMs.js +0 -55
- package/lib/helpers/waitMs.js.map +0 -1
- package/lib/types/ParamType.js +0 -21
- package/lib/types/ParamType.js.map +0 -1
- package/lib/types/ReactKitErrorCode.js +0 -18
- package/lib/types/ReactKitErrorCode.js.map +0 -1
- package/lib/types/Variant.js +0 -19
- package/lib/types/Variant.js.map +0 -1
- package/src/helpers/handleError.ts +0 -65
- package/src/helpers/handleSuccess.ts +0 -18
- package/src/helpers/parseRequest.ts +0 -299
- package/src/helpers/showFatalError.tsx +0 -3
- package/src/helpers/visitServerEndpoint.tsx +0 -110
- package/src/types/ParamType.ts +0 -18
|
@@ -1,135 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"visitServerEndpoint.js","sourceRoot":"","sources":["../../src/helpers/visitServerEndpoint.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mBAAmB;AACnB,uCAA2C;AAE3C,sBAAsB;AACtB,0EAAoD;AACpD,iFAA2D;AAE3D,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAE5E,6BAA6B;AAC7B,IAAI,oBAAgC,CAAC;AAErC,uEAAuE;AACvE,IAAI,qBAAqB,GAAG,KAAK,CAAC;AAElC;;;;GAIG;AACI,IAAM,uBAAuB,GAAG,UAAC,OAAmB;IACzD,oBAAoB,GAAG,OAAO,CAAC;AACjC,CAAC,CAAC;AAFW,QAAA,uBAAuB,2BAElC;AAEF,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAE5E;;;;;;;;GAQG;AACH,IAAM,mBAAmB,GAAG,UAC1B,IAIC;;;;oBAGgB,qBAAM,IAAA,oBAAW,EAAC;oBACjC,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,MAAM,EAAE,IAAI,CAAC,MAAM;iBACpB,CAAC,EAAA;;gBAJI,QAAQ,GAAG,SAIf;gBAEF,oBAAoB;gBACpB,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;oBAC/B,MAAM,IAAI,uBAAa,CACrB,mFAAmF,EACnF,2BAAiB,CAAC,UAAU,CAC7B,CAAC;iBACH;qBACG,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAtB,wBAAsB;qBAEpB,CAAA,QAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,2BAAiB,CAAC,cAAc,CAAA,EAAvD,wBAAuD;qBAErD,qBAAqB,EAArB,wBAAqB;gBACvB,8CAA8C;gBAC9C,qBAAM,IAAI,OAAO,CAA2B;wBAC1C,6BAA6B;oBAC/B,CAAC,CAAC,EAAA;;gBAHF,8CAA8C;gBAC9C,SAEE,CAAC;;;gBAEL,qBAAqB,GAAG,IAAI,CAAC;gBAE7B,kCAAkC;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"}
|
package/lib/helpers/waitMs.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
/**
|
|
40
|
-
* Wait for a certain number of ms
|
|
41
|
-
* @author Gabe Abrams
|
|
42
|
-
* @param ms number of ms to wait
|
|
43
|
-
*/
|
|
44
|
-
var waitMs = function (ms) {
|
|
45
|
-
if (ms === void 0) { ms = 0; }
|
|
46
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
47
|
-
return __generator(this, function (_a) {
|
|
48
|
-
return [2 /*return*/, new Promise(function (resolve) {
|
|
49
|
-
setTimeout(resolve, ms);
|
|
50
|
-
})];
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
exports.default = waitMs;
|
|
55
|
-
//# sourceMappingURL=waitMs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"waitMs.js","sourceRoot":"","sources":["../../src/helpers/waitMs.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;GAIG;AACH,IAAM,MAAM,GAAG,UAAO,EAAM;IAAN,mBAAA,EAAA,MAAM;;;YAC1B,sBAAO,IAAI,OAAO,CAAC,UAAC,OAAO;oBACzB,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;gBAC1B,CAAC,CAAC,EAAC;;;CACJ,CAAC;AAEF,kBAAe,MAAM,CAAC"}
|
package/lib/types/ParamType.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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/lib/types/Variant.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Bootstrap variants
|
|
5
|
-
* @author Gabe Abrams
|
|
6
|
-
*/
|
|
7
|
-
var Variant;
|
|
8
|
-
(function (Variant) {
|
|
9
|
-
Variant["Primary"] = "primary";
|
|
10
|
-
Variant["Secondary"] = "secondary";
|
|
11
|
-
Variant["Success"] = "success";
|
|
12
|
-
Variant["Warning"] = "warning";
|
|
13
|
-
Variant["Info"] = "info";
|
|
14
|
-
Variant["Danger"] = "danger";
|
|
15
|
-
Variant["Light"] = "light";
|
|
16
|
-
Variant["Dark"] = "dark";
|
|
17
|
-
})(Variant || (Variant = {}));
|
|
18
|
-
exports.default = Variant;
|
|
19
|
-
//# sourceMappingURL=Variant.js.map
|
package/lib/types/Variant.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Variant.js","sourceRoot":"","sources":["../../src/types/Variant.tsx"],"names":[],"mappings":";;AAAA;;;GAGG;AACH,IAAK,OASJ;AATD,WAAK,OAAO;IACV,8BAAmB,CAAA;IACnB,kCAAuB,CAAA;IACvB,8BAAmB,CAAA;IACnB,8BAAmB,CAAA;IACnB,wBAAa,CAAA;IACb,4BAAiB,CAAA;IACjB,0BAAe,CAAA;IACf,wBAAa,CAAA;AACf,CAAC,EATI,OAAO,KAAP,OAAO,QASX;AAED,kBAAe,OAAO,CAAC"}
|
|
@@ -1,65 +0,0 @@
|
|
|
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;
|
|
@@ -1,18 +0,0 @@
|
|
|
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;
|
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
// Import caccl libs
|
|
2
|
-
import { getLaunchInfo } from 'caccl-lti';
|
|
3
|
-
|
|
4
|
-
// Import shared types
|
|
5
|
-
import ReactKitErrorCode from '../types/ReactKitErrorCode';
|
|
6
|
-
import ParamType from '../types/ParamType';
|
|
7
|
-
|
|
8
|
-
// Import helpers
|
|
9
|
-
import handleError from './handleError';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Parse express request params and body
|
|
13
|
-
* @author Gabe Abrams
|
|
14
|
-
* @param opts object containing all arguments
|
|
15
|
-
* @param opts.req express request instance
|
|
16
|
-
* @param opts.res express response instance
|
|
17
|
-
* @param opts.params map of parameters that should be parsed out of the request
|
|
18
|
-
* @returns parsed params + user info from session (if it exists) or undefined
|
|
19
|
-
* if an error occurred
|
|
20
|
-
*/
|
|
21
|
-
const parseRequest = (
|
|
22
|
-
opts: {
|
|
23
|
-
req: any,
|
|
24
|
-
res: any,
|
|
25
|
-
params: {
|
|
26
|
-
[k in string]: ParamType
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
): ({ [k in string]: any } | undefined) => {
|
|
30
|
-
// Output
|
|
31
|
-
|
|
32
|
-
const output: { [k in string]: any } = {};
|
|
33
|
-
|
|
34
|
-
/*----------------------------------------*/
|
|
35
|
-
/* Parse Params */
|
|
36
|
-
/*----------------------------------------*/
|
|
37
|
-
|
|
38
|
-
// Process items one by one
|
|
39
|
-
const paramList = Object.entries(opts.params);
|
|
40
|
-
for (let i = 0; i < paramList.length; i++) {
|
|
41
|
-
const [name, type] = paramList[i];
|
|
42
|
-
|
|
43
|
-
// Find the value as a string
|
|
44
|
-
const value = (
|
|
45
|
-
opts.req.params[name]
|
|
46
|
-
|| opts.req.query[name]
|
|
47
|
-
|| opts.req.body[name]
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
// Parse
|
|
51
|
-
if (type === ParamType.Boolean || type === ParamType.BooleanOptional) {
|
|
52
|
-
// Boolean
|
|
53
|
-
|
|
54
|
-
// Handle case where value doesn't exist
|
|
55
|
-
if (value === undefined) {
|
|
56
|
-
if (type === ParamType.BooleanOptional) {
|
|
57
|
-
output[name] = undefined;
|
|
58
|
-
} else {
|
|
59
|
-
return handleError(
|
|
60
|
-
opts.res,
|
|
61
|
-
{
|
|
62
|
-
message: `Parameter ${name} is required, but it was not included.`,
|
|
63
|
-
code: ReactKitErrorCode.MissingParameter,
|
|
64
|
-
status: 422,
|
|
65
|
-
},
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
// Value exists
|
|
70
|
-
|
|
71
|
-
// Simplify value
|
|
72
|
-
const simpleVal = (
|
|
73
|
-
String(value)
|
|
74
|
-
.trim()
|
|
75
|
-
.toLowerCase()
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
// Parse
|
|
79
|
-
output[name] = (
|
|
80
|
-
[
|
|
81
|
-
'true',
|
|
82
|
-
'yes',
|
|
83
|
-
'y',
|
|
84
|
-
'1',
|
|
85
|
-
't',
|
|
86
|
-
].indexOf(simpleVal) >= 0
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
} else if (type === ParamType.Float || type === ParamType.FloatOptional) {
|
|
90
|
-
// Float
|
|
91
|
-
|
|
92
|
-
// Handle case where value doesn't exist
|
|
93
|
-
if (value === undefined) {
|
|
94
|
-
if (type === ParamType.FloatOptional) {
|
|
95
|
-
output[name] = undefined;
|
|
96
|
-
} else {
|
|
97
|
-
return handleError(
|
|
98
|
-
opts.res,
|
|
99
|
-
{
|
|
100
|
-
message: `Parameter ${name} is required, but it was not included.`,
|
|
101
|
-
code: ReactKitErrorCode.MissingParameter,
|
|
102
|
-
status: 422,
|
|
103
|
-
},
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
} else if (!Number.isNaN(Number.parseFloat(String(value)))) {
|
|
107
|
-
// Value is a number
|
|
108
|
-
output[name] = Number.parseFloat(String(value));
|
|
109
|
-
} else {
|
|
110
|
-
// Issue!
|
|
111
|
-
return handleError(
|
|
112
|
-
opts.res,
|
|
113
|
-
{
|
|
114
|
-
message: `Request data was malformed: ${name} was not a valid float.`,
|
|
115
|
-
code: ReactKitErrorCode.InvalidParameter,
|
|
116
|
-
status: 422,
|
|
117
|
-
},
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
} else if (type === ParamType.Int || type === ParamType.IntOptional) {
|
|
121
|
-
// Int
|
|
122
|
-
|
|
123
|
-
// Handle case where value doesn't exist
|
|
124
|
-
if (value === undefined) {
|
|
125
|
-
if (type === ParamType.IntOptional) {
|
|
126
|
-
output[name] = undefined;
|
|
127
|
-
} else {
|
|
128
|
-
return handleError(
|
|
129
|
-
opts.res,
|
|
130
|
-
{
|
|
131
|
-
message: `Parameter ${name} is required, but it was not included.`,
|
|
132
|
-
code: ReactKitErrorCode.MissingParameter,
|
|
133
|
-
status: 422,
|
|
134
|
-
},
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
} else if (!Number.isNaN(Number.parseInt(String(value), 10))) {
|
|
138
|
-
// Value is a number
|
|
139
|
-
output[name] = Number.parseInt(String(value), 10);
|
|
140
|
-
} else {
|
|
141
|
-
// Issue!
|
|
142
|
-
return handleError(
|
|
143
|
-
opts.res,
|
|
144
|
-
{
|
|
145
|
-
message: `Request data was malformed: ${name} was not a valid int.`,
|
|
146
|
-
code: ReactKitErrorCode.InvalidParameter,
|
|
147
|
-
status: 422,
|
|
148
|
-
},
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
} else if (type === ParamType.JSON || type === ParamType.JSONOptional) {
|
|
152
|
-
// Stringified JSON
|
|
153
|
-
|
|
154
|
-
// Handle case where value doesn't exist
|
|
155
|
-
if (value === undefined) {
|
|
156
|
-
if (type === ParamType.JSONOptional) {
|
|
157
|
-
output[name] = undefined;
|
|
158
|
-
} else {
|
|
159
|
-
return handleError(
|
|
160
|
-
opts.res,
|
|
161
|
-
{
|
|
162
|
-
message: `Parameter ${name} is required, but it was not included.`,
|
|
163
|
-
code: ReactKitErrorCode.MissingParameter,
|
|
164
|
-
status: 422,
|
|
165
|
-
},
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
} else {
|
|
169
|
-
// Value exists
|
|
170
|
-
|
|
171
|
-
// Parse
|
|
172
|
-
try {
|
|
173
|
-
output[name] = JSON.parse(String(value));
|
|
174
|
-
} catch (err) {
|
|
175
|
-
return handleError(
|
|
176
|
-
opts.res,
|
|
177
|
-
{
|
|
178
|
-
message: `Request data was malformed: ${name} was not a valid JSON payload.`,
|
|
179
|
-
code: ReactKitErrorCode.InvalidParameter,
|
|
180
|
-
status: 422,
|
|
181
|
-
},
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
} else if (type === ParamType.String || type === ParamType.StringOptional) {
|
|
186
|
-
// String
|
|
187
|
-
|
|
188
|
-
// Handle case where value doesn't exist
|
|
189
|
-
if (value === undefined) {
|
|
190
|
-
if (type === ParamType.StringOptional) {
|
|
191
|
-
output[name] = undefined;
|
|
192
|
-
} else {
|
|
193
|
-
return handleError(
|
|
194
|
-
opts.res,
|
|
195
|
-
{
|
|
196
|
-
message: `Parameter ${name} is required, but it was not included.`,
|
|
197
|
-
code: ReactKitErrorCode.MissingParameter,
|
|
198
|
-
status: 422,
|
|
199
|
-
},
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
} else {
|
|
203
|
-
// Value exists
|
|
204
|
-
|
|
205
|
-
// Leave as is
|
|
206
|
-
output[name] = value;
|
|
207
|
-
}
|
|
208
|
-
} else {
|
|
209
|
-
// No valid data type
|
|
210
|
-
return handleError(
|
|
211
|
-
opts.res,
|
|
212
|
-
{
|
|
213
|
-
message: `An internal error occurred: we could not determine the type of ${name}.`,
|
|
214
|
-
code: ReactKitErrorCode.InvalidParameter,
|
|
215
|
-
status: 422,
|
|
216
|
-
},
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/*----------------------------------------*/
|
|
222
|
-
/* Launch Info */
|
|
223
|
-
/*----------------------------------------*/
|
|
224
|
-
|
|
225
|
-
// Get launch info
|
|
226
|
-
const { launched, launchInfo } = getLaunchInfo(opts.req);
|
|
227
|
-
if (!launched || !launchInfo) {
|
|
228
|
-
return handleError(
|
|
229
|
-
opts.res,
|
|
230
|
-
{
|
|
231
|
-
message: 'Your session has expired. Please refresh the page and try again.',
|
|
232
|
-
code: ReactKitErrorCode.SessionExpired,
|
|
233
|
-
status: 440,
|
|
234
|
-
},
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Error if user info cannot be found
|
|
239
|
-
if (
|
|
240
|
-
!launchInfo.userId
|
|
241
|
-
|| !launchInfo.userFirstName
|
|
242
|
-
|| !launchInfo.userLastName
|
|
243
|
-
|| (
|
|
244
|
-
launchInfo.notInCourse
|
|
245
|
-
&& !launchInfo.isAdmin
|
|
246
|
-
)
|
|
247
|
-
|| (
|
|
248
|
-
!launchInfo.isTTM
|
|
249
|
-
&& !launchInfo.isLearner
|
|
250
|
-
&& !launchInfo.isAdmin
|
|
251
|
-
)
|
|
252
|
-
) {
|
|
253
|
-
return handleError(
|
|
254
|
-
opts.res,
|
|
255
|
-
{
|
|
256
|
-
message: 'Your session was invalid. Please refresh the page and try again.',
|
|
257
|
-
code: ReactKitErrorCode.SessionExpired,
|
|
258
|
-
status: 440,
|
|
259
|
-
},
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// Add launch info to output
|
|
264
|
-
output.userId = launchInfo.userId;
|
|
265
|
-
output.userFirstName = launchInfo.userFirstName;
|
|
266
|
-
output.userLastName = launchInfo.userLastName;
|
|
267
|
-
output.isLearner = !!launchInfo.isLearner;
|
|
268
|
-
output.isTTM = !!launchInfo.isTTM;
|
|
269
|
-
output.isAdmin = !!launchInfo.isAdmin;
|
|
270
|
-
output.isWatchingInPrivate = !!(opts.req.session.isWatchingInPrivate);
|
|
271
|
-
|
|
272
|
-
/*----------------------------------------*/
|
|
273
|
-
/* Require Course Consistency */
|
|
274
|
-
/*----------------------------------------*/
|
|
275
|
-
|
|
276
|
-
// Make sure the user actually launched from the appropriate course
|
|
277
|
-
if (
|
|
278
|
-
output.courseId
|
|
279
|
-
&& launchInfo.courseId
|
|
280
|
-
&& output.courseId !== launchInfo.courseId
|
|
281
|
-
&& !output.isTTM
|
|
282
|
-
&& !output.isAdmin
|
|
283
|
-
) {
|
|
284
|
-
// Course of interest is not the launch course
|
|
285
|
-
return handleError(
|
|
286
|
-
opts.res,
|
|
287
|
-
{
|
|
288
|
-
message: 'You switched sessions by opening Immersive Classroom in another tab. Please refresh the page and try again.',
|
|
289
|
-
code: ReactKitErrorCode.WrongCourse,
|
|
290
|
-
status: 401,
|
|
291
|
-
},
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// Return processed params
|
|
296
|
-
return output;
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
export default parseRequest;
|