dce-reactkit 3.9.2 → 3.9.4-beta-prompt.1
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/dist/cjs/index.js +184 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/AppWrapper.d.ts +24 -0
- package/dist/cjs/types/helpers/genRouteHandler.d.ts +8 -0
- package/dist/cjs/types/index.d.ts +2 -2
- package/dist/cjs/types/types/ModalType.d.ts +1 -0
- package/dist/cjs/types/types/ReactKitErrorCode.d.ts +2 -0
- package/dist/esm/index.js +184 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/AppWrapper.d.ts +24 -0
- package/dist/esm/types/helpers/genRouteHandler.d.ts +8 -0
- package/dist/esm/types/index.d.ts +2 -2
- package/dist/esm/types/types/ModalType.d.ts +1 -0
- package/dist/esm/types/types/ReactKitErrorCode.d.ts +2 -0
- package/dist/index.d.ts +36 -1
- package/package.json +1 -1
- package/src/components/AppWrapper.tsx +216 -0
- package/src/components/Modal/index.tsx +3 -0
- package/src/helpers/genRouteHandler.ts +99 -0
- package/src/index.ts +2 -0
- package/src/types/ModalType.tsx +1 -0
- package/src/types/ReactKitErrorCode.tsx +3 -1
|
@@ -44,6 +44,30 @@ export declare const confirm: (title: string, text: string, opts?: {
|
|
|
44
44
|
cancelButtonText?: string;
|
|
45
45
|
cancelButtonVariant?: Variant;
|
|
46
46
|
}) => Promise<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* Show a prompt modal asking the user for input
|
|
49
|
+
* @author Yuen Ler Chow
|
|
50
|
+
* @param title the title text to display at the top of the prompt
|
|
51
|
+
* @param text the text to display in the prompt
|
|
52
|
+
* @param [opts={}] additional options for the prompt dialog
|
|
53
|
+
* @param [opts.placeholder] the placeholder text for the input field
|
|
54
|
+
* @param [opts.defaultText] the default text for the input field
|
|
55
|
+
* @param [opts.confirmButtonText=Okay] the text of the confirm button
|
|
56
|
+
* @param [opts.confirmButtonVariant=Variant.Dark] the variant of the confirm button
|
|
57
|
+
* @param [opts.cancelButtonText=Cancel] the text of the cancel button
|
|
58
|
+
* @param [opts.cancelButtonVariant=Variant.Secondary] the variant of the cancel button
|
|
59
|
+
* @returns Promise that resolves with the input string or null if canceled
|
|
60
|
+
*/
|
|
61
|
+
export declare const prompt: (title: string, text: string, currentInputFieldText: string, opts?: {
|
|
62
|
+
placeholder?: string | undefined;
|
|
63
|
+
defaultText?: string | undefined;
|
|
64
|
+
confirmButtonText?: string | undefined;
|
|
65
|
+
confirmButtonVariant?: Variant | undefined;
|
|
66
|
+
cancelButtonText?: string | undefined;
|
|
67
|
+
cancelButtonVariant?: Variant | undefined;
|
|
68
|
+
minNumChars?: number | undefined;
|
|
69
|
+
findValidationError?: ((text: string) => string | undefined) | undefined;
|
|
70
|
+
} | undefined) => Promise<string | null>;
|
|
47
71
|
/**
|
|
48
72
|
* Show a fatal error message
|
|
49
73
|
* @author Gabe Abrams
|
|
@@ -9,6 +9,12 @@ import LogFunction from '../types/LogFunction';
|
|
|
9
9
|
* @param opts.handler function that processes the request
|
|
10
10
|
* @param [opts.skipSessionCheck] if true, skip the session check (allow users
|
|
11
11
|
* to not be logged in and launched via LTI)
|
|
12
|
+
* @param [opts.allowedHosts] if included, only allow requests from these hosts
|
|
13
|
+
* (start a hostname with a "*" to only check the end of the hostname)
|
|
14
|
+
* you can include just one string instead of an array
|
|
15
|
+
* @param [opts.bannedHosts] if included, do not allow requests from these hosts
|
|
16
|
+
* (start a hostname with a "*" to only check the end of the hostname)
|
|
17
|
+
* you can include just one string instead of an array
|
|
12
18
|
* @param [opts.unhandledErrorMessagePrefix] if included, when an error that
|
|
13
19
|
* is not of type ErrorWithCode is thrown, the client will receive an error
|
|
14
20
|
* where the error message is prefixed with this string. For example,
|
|
@@ -63,6 +69,8 @@ declare const genRouteHandler: (opts: {
|
|
|
63
69
|
logServerEvent: LogFunction;
|
|
64
70
|
}) => any;
|
|
65
71
|
skipSessionCheck?: boolean | undefined;
|
|
72
|
+
allowedHosts?: string | string[] | undefined;
|
|
73
|
+
bannedHosts?: string | string[] | undefined;
|
|
66
74
|
unhandledErrorMessagePrefix?: string | undefined;
|
|
67
75
|
}) => (req: any, res: any, next: () => void) => Promise<undefined>;
|
|
68
76
|
export default genRouteHandler;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import AppWrapper, { alert, confirm, showFatalError, addFatalErrorHandler, leaveToURL } from './components/AppWrapper';
|
|
1
|
+
import AppWrapper, { alert, prompt, confirm, showFatalError, addFatalErrorHandler, leaveToURL } from './components/AppWrapper';
|
|
2
2
|
import LoadingSpinner from './components/LoadingSpinner';
|
|
3
3
|
import ErrorBox from './components/ErrorBox';
|
|
4
4
|
import Modal from './components/Modal';
|
|
@@ -99,4 +99,4 @@ import PickableItem from './components/ItemPicker/types/PickableItem';
|
|
|
99
99
|
import DBEntry from './components/DBEntryManagerPanel/types/DBEntry';
|
|
100
100
|
import DBEntryField from './components/DBEntryManagerPanel/types/DBEntryField';
|
|
101
101
|
import DBEntryFieldType from './components/DBEntryManagerPanel/types/DBEntryFieldType';
|
|
102
|
-
export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, DBEntryManagerPanel, Tooltip, ToggleSwitch, AutoscrollToBottomContainer, MultiSwitch, Dropdown, alert, confirm, showFatalError, ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, DynamicWord, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, stubServerEndpoint, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, canReviewLogs, isMobileOrTablet, extractProp, compareArraysByProp, genCommaList, validateEmail, validatePhoneNumber, validateString, getLocalTimeInfo, idify, makeLinksClickable, prefixWithAOrAn, everyAsync, filterAsync, forEachAsync, mapAsync, someAsync, capitalize, shuffleArray, initClient, visitServerEndpoint, logClientEvent, addFatalErrorHandler, leaveToURL, combineClassNames, useForceRender, setClientEventMetadataPopulator, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, addDBEditorEndpoints, visitEndpointOnAnotherServer, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, LogFunction, IntelliTableColumn, DropdownItemType, PickableItem, DBEntry, DBEntryField, DBEntryFieldType, ParamType, };
|
|
102
|
+
export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, DBEntryManagerPanel, Tooltip, ToggleSwitch, AutoscrollToBottomContainer, MultiSwitch, Dropdown, alert, prompt, confirm, showFatalError, ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, DynamicWord, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, stubServerEndpoint, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, canReviewLogs, isMobileOrTablet, extractProp, compareArraysByProp, genCommaList, validateEmail, validatePhoneNumber, validateString, getLocalTimeInfo, idify, makeLinksClickable, prefixWithAOrAn, everyAsync, filterAsync, forEachAsync, mapAsync, someAsync, capitalize, shuffleArray, initClient, visitServerEndpoint, logClientEvent, addFatalErrorHandler, leaveToURL, combineClassNames, useForceRender, setClientEventMetadataPopulator, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, addDBEditorEndpoints, visitEndpointOnAnotherServer, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, LogFunction, IntelliTableColumn, DropdownItemType, PickableItem, DBEntry, DBEntryField, DBEntryFieldType, ParamType, };
|
|
@@ -8,6 +8,8 @@ declare enum ReactKitErrorCode {
|
|
|
8
8
|
SessionExpired = "DRK3",
|
|
9
9
|
MissingParameter = "DRK4",
|
|
10
10
|
InvalidParameter = "DRK5",
|
|
11
|
+
HostNotAllowed = "DRK17",
|
|
12
|
+
HostBanned = "DRK18",
|
|
11
13
|
WrongCourse = "DRK6",
|
|
12
14
|
NoCACCLSendRequestFunction = "DRK7",
|
|
13
15
|
NoCACCLGetLaunchInfoFunction = "DRK8",
|
package/dist/esm/index.js
CHANGED
|
@@ -31,7 +31,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
// Highest error code =
|
|
34
|
+
// Highest error code = DRK18
|
|
35
35
|
/**
|
|
36
36
|
* List of error codes built into the react kit
|
|
37
37
|
* @author Gabe Abrams
|
|
@@ -43,6 +43,8 @@ var ReactKitErrorCode;
|
|
|
43
43
|
ReactKitErrorCode["SessionExpired"] = "DRK3";
|
|
44
44
|
ReactKitErrorCode["MissingParameter"] = "DRK4";
|
|
45
45
|
ReactKitErrorCode["InvalidParameter"] = "DRK5";
|
|
46
|
+
ReactKitErrorCode["HostNotAllowed"] = "DRK17";
|
|
47
|
+
ReactKitErrorCode["HostBanned"] = "DRK18";
|
|
46
48
|
ReactKitErrorCode["WrongCourse"] = "DRK6";
|
|
47
49
|
ReactKitErrorCode["NoCACCLSendRequestFunction"] = "DRK7";
|
|
48
50
|
ReactKitErrorCode["NoCACCLGetLaunchInfoFunction"] = "DRK8";
|
|
@@ -156,6 +158,7 @@ var ModalButtonType$1 = ModalButtonType;
|
|
|
156
158
|
var ModalType;
|
|
157
159
|
(function (ModalType) {
|
|
158
160
|
ModalType["Okay"] = "okay";
|
|
161
|
+
ModalType["Cancel"] = "cancel";
|
|
159
162
|
ModalType["OkayCancel"] = "okay-cancel";
|
|
160
163
|
ModalType["YesNo"] = "yes-no";
|
|
161
164
|
ModalType["YesNoCancel"] = "yes-no-cancel";
|
|
@@ -310,6 +313,9 @@ const modalTypeToModalButtonTypes = {
|
|
|
310
313
|
[ModalType$1.Okay]: [
|
|
311
314
|
ModalButtonType$1.Okay,
|
|
312
315
|
],
|
|
316
|
+
[ModalType$1.Cancel]: [
|
|
317
|
+
ModalButtonType$1.Cancel,
|
|
318
|
+
],
|
|
313
319
|
[ModalType$1.OkayCancel]: [
|
|
314
320
|
ModalButtonType$1.Okay,
|
|
315
321
|
ModalButtonType$1.Cancel,
|
|
@@ -1050,6 +1056,73 @@ const confirm = (title, text, opts) => __awaiter(void 0, void 0, void 0, functio
|
|
|
1050
1056
|
});
|
|
1051
1057
|
});
|
|
1052
1058
|
/*----------------------------------------*/
|
|
1059
|
+
/* --------------- Prompt -------------- */
|
|
1060
|
+
/*----------------------------------------*/
|
|
1061
|
+
// Stored copies of setters
|
|
1062
|
+
let setPromptInfo;
|
|
1063
|
+
// Function to call when prompt is closed
|
|
1064
|
+
let onPromptClosed;
|
|
1065
|
+
/**
|
|
1066
|
+
* Show a prompt modal asking the user for input
|
|
1067
|
+
* @author Yuen Ler Chow
|
|
1068
|
+
* @param title the title text to display at the top of the prompt
|
|
1069
|
+
* @param text the text to display in the prompt
|
|
1070
|
+
* @param [opts={}] additional options for the prompt dialog
|
|
1071
|
+
* @param [opts.placeholder] the placeholder text for the input field
|
|
1072
|
+
* @param [opts.defaultText] the default text for the input field
|
|
1073
|
+
* @param [opts.confirmButtonText=Okay] the text of the confirm button
|
|
1074
|
+
* @param [opts.confirmButtonVariant=Variant.Dark] the variant of the confirm button
|
|
1075
|
+
* @param [opts.cancelButtonText=Cancel] the text of the cancel button
|
|
1076
|
+
* @param [opts.cancelButtonVariant=Variant.Secondary] the variant of the cancel button
|
|
1077
|
+
* @returns Promise that resolves with the input string or null if canceled
|
|
1078
|
+
*/
|
|
1079
|
+
const prompt = (title, text, currentInputFieldText, opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1080
|
+
var _a;
|
|
1081
|
+
// Wait for helper to exist
|
|
1082
|
+
yield waitForHelper(() => {
|
|
1083
|
+
return !!setPromptInfo;
|
|
1084
|
+
});
|
|
1085
|
+
// Fallback if prompt is not available
|
|
1086
|
+
if (!setPromptInfo) {
|
|
1087
|
+
const resultPassesValidation = false;
|
|
1088
|
+
while (!resultPassesValidation) {
|
|
1089
|
+
// eslint-disable-next-line no-alert
|
|
1090
|
+
const result = window.prompt(`${title}\n\n${text}`, (_a = opts === null || opts === void 0 ? void 0 : opts.defaultText) !== null && _a !== void 0 ? _a : '');
|
|
1091
|
+
if (result === null) {
|
|
1092
|
+
return null;
|
|
1093
|
+
}
|
|
1094
|
+
// Validate min num chars
|
|
1095
|
+
const minNumCharsValidationError = (((opts === null || opts === void 0 ? void 0 : opts.minNumChars) && result.length < opts.minNumChars)
|
|
1096
|
+
? `Please enter at least ${opts.minNumChars} characters.`
|
|
1097
|
+
: undefined);
|
|
1098
|
+
// Run custom validation
|
|
1099
|
+
const customValidationError = ((opts === null || opts === void 0 ? void 0 : opts.findValidationError)
|
|
1100
|
+
&& opts.findValidationError(result));
|
|
1101
|
+
// Show validation issue
|
|
1102
|
+
if (minNumCharsValidationError || customValidationError) {
|
|
1103
|
+
alert('Invalid Input', `${minNumCharsValidationError !== null && minNumCharsValidationError !== void 0 ? minNumCharsValidationError : ''} ${customValidationError !== null && customValidationError !== void 0 ? customValidationError : ''}`);
|
|
1104
|
+
}
|
|
1105
|
+
else {
|
|
1106
|
+
return result;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
// Return promise that resolves with result of prompt
|
|
1111
|
+
return new Promise((resolve) => {
|
|
1112
|
+
// Setup handler
|
|
1113
|
+
onPromptClosed = (result) => {
|
|
1114
|
+
resolve(result);
|
|
1115
|
+
};
|
|
1116
|
+
// Show the prompt
|
|
1117
|
+
setPromptInfo({
|
|
1118
|
+
title,
|
|
1119
|
+
text,
|
|
1120
|
+
currentInputFieldText,
|
|
1121
|
+
opts: (opts !== null && opts !== void 0 ? opts : {}),
|
|
1122
|
+
});
|
|
1123
|
+
});
|
|
1124
|
+
});
|
|
1125
|
+
/*----------------------------------------*/
|
|
1053
1126
|
/* ------------- Fatal Error ------------ */
|
|
1054
1127
|
/*----------------------------------------*/
|
|
1055
1128
|
// Stored copies of setters
|
|
@@ -1065,14 +1138,14 @@ const fatalErrorHandlers = [];
|
|
|
1065
1138
|
* @param [errorTitle] title of the error box
|
|
1066
1139
|
*/
|
|
1067
1140
|
const showFatalError = (error, errorTitle = 'An Error Occurred') => __awaiter(void 0, void 0, void 0, function* () {
|
|
1068
|
-
var
|
|
1141
|
+
var _b, _c;
|
|
1069
1142
|
// Determine message and code
|
|
1070
1143
|
const message = (typeof error === 'string'
|
|
1071
1144
|
? error.trim()
|
|
1072
|
-
: String((
|
|
1145
|
+
: String((_b = error.message) !== null && _b !== void 0 ? _b : 'An unknown error occurred.'));
|
|
1073
1146
|
const code = (typeof error === 'string'
|
|
1074
1147
|
? ReactKitErrorCode$1.NoCode
|
|
1075
|
-
: String((
|
|
1148
|
+
: String((_c = error.code) !== null && _c !== void 0 ? _c : ReactKitErrorCode$1.NoCode));
|
|
1076
1149
|
// Call all fatal error listeners
|
|
1077
1150
|
try {
|
|
1078
1151
|
fatalErrorHandlers.forEach((handler) => {
|
|
@@ -1199,6 +1272,9 @@ const AppWrapper = (props) => {
|
|
|
1199
1272
|
// Confirm
|
|
1200
1273
|
const [confirmInfo, setConfirmInfoInner,] = useState(undefined);
|
|
1201
1274
|
setConfirmInfo = setConfirmInfoInner;
|
|
1275
|
+
// Prompt
|
|
1276
|
+
const [promptInfo, setPromptInfoInner] = useState(undefined);
|
|
1277
|
+
setPromptInfo = setPromptInfoInner;
|
|
1202
1278
|
// Session expired
|
|
1203
1279
|
const [sessionHasExpired, setSessionHasExpiredInner,] = useState(false);
|
|
1204
1280
|
setSessionHasExpired = setSessionHasExpiredInner;
|
|
@@ -1229,6 +1305,37 @@ const AppWrapper = (props) => {
|
|
|
1229
1305
|
}
|
|
1230
1306
|
}, onTopOfOtherModals: true, dontAllowBackdropExit: true }, confirmInfo.text));
|
|
1231
1307
|
}
|
|
1308
|
+
/* ------------- Prompt ------------ */
|
|
1309
|
+
if (promptInfo) {
|
|
1310
|
+
// Run min char validation
|
|
1311
|
+
const minNumCharsValidationError = ((promptInfo.opts.minNumChars
|
|
1312
|
+
&& promptInfo.currentInputFieldText.length < promptInfo.opts.minNumChars)
|
|
1313
|
+
? `Please enter at least ${promptInfo.opts.minNumChars} characters.`
|
|
1314
|
+
: undefined);
|
|
1315
|
+
// Run custom validation
|
|
1316
|
+
const customValidationError = (promptInfo.opts.findValidationError
|
|
1317
|
+
&& promptInfo.opts.findValidationError(promptInfo.currentInputFieldText));
|
|
1318
|
+
modal = (React__default.createElement(Modal, { key: `prompt-${promptInfo.title}-${promptInfo.text}`, title: promptInfo.title,
|
|
1319
|
+
// Don't show ok button if there is a validation error
|
|
1320
|
+
type: ((customValidationError || minNumCharsValidationError)
|
|
1321
|
+
? ModalType$1.Cancel
|
|
1322
|
+
: ModalType$1.OkayCancel), okayLabel: promptInfo.opts.confirmButtonText, okayVariant: promptInfo.opts.confirmButtonVariant, cancelLabel: promptInfo.opts.cancelButtonText, cancelVariant: promptInfo.opts.cancelButtonVariant, onClose: (buttonType) => {
|
|
1323
|
+
const result = (buttonType === ModalButtonType$1.Okay
|
|
1324
|
+
? promptInfo.currentInputFieldText
|
|
1325
|
+
: null);
|
|
1326
|
+
setPromptInfo(undefined);
|
|
1327
|
+
if (onPromptClosed) {
|
|
1328
|
+
onPromptClosed(result);
|
|
1329
|
+
}
|
|
1330
|
+
}, onTopOfOtherModals: true, dontAllowBackdropExit: true },
|
|
1331
|
+
React__default.createElement("div", { className: "d-flex flex-column align-items-center" },
|
|
1332
|
+
React__default.createElement("p", null, promptInfo.text),
|
|
1333
|
+
React__default.createElement("input", { type: "text", placeholder: promptInfo.opts.placeholder, value: promptInfo.currentInputFieldText, onChange: (e) => {
|
|
1334
|
+
return setPromptInfo(Object.assign(Object.assign({}, promptInfo), { currentInputFieldText: e.target.value }));
|
|
1335
|
+
} }),
|
|
1336
|
+
minNumCharsValidationError && (React__default.createElement("div", { className: "text-danger bg-danger bg-opacity-25 p-2 m-1 rounded" }, minNumCharsValidationError)),
|
|
1337
|
+
customValidationError && (React__default.createElement("div", { className: "text-danger bg-danger bg-opacity-25 p-2 m-1 rounded" }, customValidationError)))));
|
|
1338
|
+
}
|
|
1232
1339
|
/* ------ Custom Modal Portals ------ */
|
|
1233
1340
|
// Custom modal portals
|
|
1234
1341
|
const customModalPortals = [];
|
|
@@ -14441,6 +14548,12 @@ const parseUserAgent = (userAgent) => {
|
|
|
14441
14548
|
* @param opts.handler function that processes the request
|
|
14442
14549
|
* @param [opts.skipSessionCheck] if true, skip the session check (allow users
|
|
14443
14550
|
* to not be logged in and launched via LTI)
|
|
14551
|
+
* @param [opts.allowedHosts] if included, only allow requests from these hosts
|
|
14552
|
+
* (start a hostname with a "*" to only check the end of the hostname)
|
|
14553
|
+
* you can include just one string instead of an array
|
|
14554
|
+
* @param [opts.bannedHosts] if included, do not allow requests from these hosts
|
|
14555
|
+
* (start a hostname with a "*" to only check the end of the hostname)
|
|
14556
|
+
* you can include just one string instead of an array
|
|
14444
14557
|
* @param [opts.unhandledErrorMessagePrefix] if included, when an error that
|
|
14445
14558
|
* is not of type ErrorWithCode is thrown, the client will receive an error
|
|
14446
14559
|
* where the error message is prefixed with this string. For example,
|
|
@@ -14472,6 +14585,72 @@ const genRouteHandler = (opts) => {
|
|
|
14472
14585
|
// Output params
|
|
14473
14586
|
const output = {};
|
|
14474
14587
|
/*----------------------------------------*/
|
|
14588
|
+
/* ----------- Hostname Check ----------- */
|
|
14589
|
+
/*----------------------------------------*/
|
|
14590
|
+
// Get hostnames
|
|
14591
|
+
const originURL = String(req.get('origin')
|
|
14592
|
+
|| req.headers.origin
|
|
14593
|
+
|| req.headers.referer);
|
|
14594
|
+
const originHostname = (originURL
|
|
14595
|
+
// Remove protocol
|
|
14596
|
+
.replace(/(^\w+:|^)\/\//, '')
|
|
14597
|
+
// Remove port
|
|
14598
|
+
.replace(/:\d+$/, ''));
|
|
14599
|
+
const serverHostname = String(req.hostname);
|
|
14600
|
+
// Check allowed
|
|
14601
|
+
if (opts.allowedHosts) {
|
|
14602
|
+
// Only accept requests from allowed hosts
|
|
14603
|
+
const allowedArray = (Array.isArray(opts.allowedHosts)
|
|
14604
|
+
? opts.allowedHosts
|
|
14605
|
+
: [opts.allowedHosts]);
|
|
14606
|
+
// Check if server is localhost
|
|
14607
|
+
if (serverHostname === 'localhost') {
|
|
14608
|
+
// Allow localhost
|
|
14609
|
+
allowedArray.push('localhost');
|
|
14610
|
+
}
|
|
14611
|
+
// Check if current host is allowed
|
|
14612
|
+
const allowed = allowedArray.some((allowedHost) => {
|
|
14613
|
+
if (allowedHost.startsWith('*')) {
|
|
14614
|
+
// Check end of hostname
|
|
14615
|
+
return originHostname.endsWith(allowedHost.substring(1));
|
|
14616
|
+
}
|
|
14617
|
+
// Check full hostname
|
|
14618
|
+
return originHostname.toLowerCase() === allowedHost.toLowerCase();
|
|
14619
|
+
});
|
|
14620
|
+
// If not allowed, return error
|
|
14621
|
+
if (!allowed) {
|
|
14622
|
+
return handleError(res, {
|
|
14623
|
+
message: 'You are not allowed to access this endpoint.',
|
|
14624
|
+
code: ReactKitErrorCode$1.HostNotAllowed,
|
|
14625
|
+
status: 403,
|
|
14626
|
+
});
|
|
14627
|
+
}
|
|
14628
|
+
}
|
|
14629
|
+
// Check banned
|
|
14630
|
+
if (opts.bannedHosts) {
|
|
14631
|
+
// Do not allow requests from banned hosts
|
|
14632
|
+
const bannedArray = (Array.isArray(opts.bannedHosts)
|
|
14633
|
+
? opts.bannedHosts
|
|
14634
|
+
: [opts.bannedHosts]);
|
|
14635
|
+
// Check if current host is banned
|
|
14636
|
+
const banned = bannedArray.some((bannedHost) => {
|
|
14637
|
+
if (bannedHost.startsWith('*')) {
|
|
14638
|
+
// Check end of hostname
|
|
14639
|
+
return originHostname.endsWith(bannedHost.substring(1));
|
|
14640
|
+
}
|
|
14641
|
+
// Check full hostname
|
|
14642
|
+
return originHostname.toLowerCase() === bannedHost.toLowerCase();
|
|
14643
|
+
});
|
|
14644
|
+
// If banned, return error
|
|
14645
|
+
if (banned) {
|
|
14646
|
+
return handleError(res, {
|
|
14647
|
+
message: 'You are not allowed to access this endpoint.',
|
|
14648
|
+
code: ReactKitErrorCode$1.HostBanned,
|
|
14649
|
+
status: 403,
|
|
14650
|
+
});
|
|
14651
|
+
}
|
|
14652
|
+
}
|
|
14653
|
+
/*----------------------------------------*/
|
|
14475
14654
|
/* ------------ Parse Params ------------ */
|
|
14476
14655
|
/*----------------------------------------*/
|
|
14477
14656
|
// Process items one by one
|
|
@@ -16135,5 +16314,5 @@ var DayOfWeek;
|
|
|
16135
16314
|
})(DayOfWeek || (DayOfWeek = {}));
|
|
16136
16315
|
var DayOfWeek$1 = DayOfWeek;
|
|
16137
16316
|
|
|
16138
|
-
export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntryFieldType$1 as DBEntryFieldType, DBEntryManagerPanel, DayOfWeek$1 as DayOfWeek, Drawer, Dropdown, DropdownItemType$1 as DropdownItemType, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, ItemPicker, LoadingSpinner, LogAction$1 as LogAction, LogBuiltInMetadata, LogReviewer, LogSource$1 as LogSource, LogType$1 as LogType, MINUTE_IN_MS, Modal, ModalButtonType$1 as ModalButtonType, ModalSize$1 as ModalSize, ModalType$1 as ModalType, MultiSwitch, ParamType$1 as ParamType, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode$1 as ReactKitErrorCode, SimpleDateChooser, TabBox, ToggleSwitch, Tooltip, Variant$1 as Variant, abbreviate, addDBEditorEndpoints, addFatalErrorHandler, alert, avg, canReviewLogs, capitalize, ceilToNumDecimals, combineClassNames, compareArraysByProp, confirm, everyAsync, extractProp, filterAsync, floorToNumDecimals, forEachAsync, forceNumIntoBounds, genCSV, genCommaList, genRouteHandler, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, idify, initClient, initLogCollection, initServer, isMobileOrTablet, leaveToURL, logClientEvent, makeLinksClickable, mapAsync, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, prefixWithAOrAn, roundToNumDecimals, setClientEventMetadataPopulator, showFatalError, shuffleArray, someAsync, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, useForceRender, validateEmail, validatePhoneNumber, validateString, visitEndpointOnAnotherServer, visitServerEndpoint, waitMs };
|
|
16317
|
+
export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntryFieldType$1 as DBEntryFieldType, DBEntryManagerPanel, DayOfWeek$1 as DayOfWeek, Drawer, Dropdown, DropdownItemType$1 as DropdownItemType, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, ItemPicker, LoadingSpinner, LogAction$1 as LogAction, LogBuiltInMetadata, LogReviewer, LogSource$1 as LogSource, LogType$1 as LogType, MINUTE_IN_MS, Modal, ModalButtonType$1 as ModalButtonType, ModalSize$1 as ModalSize, ModalType$1 as ModalType, MultiSwitch, ParamType$1 as ParamType, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode$1 as ReactKitErrorCode, SimpleDateChooser, TabBox, ToggleSwitch, Tooltip, Variant$1 as Variant, abbreviate, addDBEditorEndpoints, addFatalErrorHandler, alert, avg, canReviewLogs, capitalize, ceilToNumDecimals, combineClassNames, compareArraysByProp, confirm, everyAsync, extractProp, filterAsync, floorToNumDecimals, forEachAsync, forceNumIntoBounds, genCSV, genCommaList, genRouteHandler, getHumanReadableDate, getLocalTimeInfo, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, idify, initClient, initLogCollection, initServer, isMobileOrTablet, leaveToURL, logClientEvent, makeLinksClickable, mapAsync, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, prefixWithAOrAn, prompt, roundToNumDecimals, setClientEventMetadataPopulator, showFatalError, shuffleArray, someAsync, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, useForceRender, validateEmail, validatePhoneNumber, validateString, visitEndpointOnAnotherServer, visitServerEndpoint, waitMs };
|
|
16139
16318
|
//# sourceMappingURL=index.js.map
|