dce-reactkit 3.8.7 → 3.9.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.
@@ -78,6 +78,7 @@ import mapAsync from './helpers/asyncArrayFunctions/mapAsync';
78
78
  import someAsync from './helpers/asyncArrayFunctions/someAsync';
79
79
  import capitalize from './helpers/capitalize';
80
80
  import shuffleArray from './helpers/shuffleArray';
81
+ import visitEndpointOnAnotherServer from './helpers/visitEndpointOnAnotherServer';
81
82
  import ModalButtonType from './types/ModalButtonType';
82
83
  import ModalSize from './types/ModalSize';
83
84
  import ModalType from './types/ModalType';
@@ -98,4 +99,4 @@ import PickableItem from './components/ItemPicker/types/PickableItem';
98
99
  import DBEntry from './components/DBEntryManagerPanel/types/DBEntry';
99
100
  import DBEntryField from './components/DBEntryManagerPanel/types/DBEntryField';
100
101
  import DBEntryFieldType from './components/DBEntryManagerPanel/types/DBEntryFieldType';
101
- 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, 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, 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, };
package/dist/esm/index.js CHANGED
@@ -4,6 +4,7 @@ import { faExclamationTriangle, faHourglassEnd, faCircle, faDotCircle, faCheckSq
4
4
  import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
5
5
  import ReactDOM, { createPortal } from 'react-dom';
6
6
  import { faCircle as faCircle$1, faSquareMinus, faSquare } from '@fortawesome/free-regular-svg-icons';
7
+ import qs from 'qs';
7
8
 
8
9
  /******************************************************************************
9
10
  Copyright (c) Microsoft Corporation.
@@ -15942,6 +15943,180 @@ const shuffleArray = (arr) => {
15942
15943
  return newArr;
15943
15944
  };
15944
15945
 
15946
+ /**
15947
+ * Sends and retries an http request
15948
+ * @author Gabriel Abrams
15949
+ * @param opts object containing all arguments
15950
+ * @param opts.path path to send request to
15951
+ * @param [opts.host] host to send request to
15952
+ * @param [opts.method=GET] http method to use
15953
+ * @param [opts.params] body/data to include in the request
15954
+ * @param [opts.headers] headers to include in the request
15955
+ * @param [opts.sendCrossDomainCredentials=true if in development mode] if true,
15956
+ * send cross-domain credentials even if not in dev mode
15957
+ * @param [opts.responseType=JSON] expected response type
15958
+ * @returns { body, status, headers } on success
15959
+ */
15960
+ const sendServerToServerRequest = (opts) => __awaiter(void 0, void 0, void 0, function* () {
15961
+ var _a;
15962
+ // Process method
15963
+ const method = (opts.method || 'GET');
15964
+ // Encode objects within params
15965
+ let params;
15966
+ if (opts.params) {
15967
+ params = {};
15968
+ Object.entries(opts.params).forEach(([key, val]) => {
15969
+ if (typeof val === 'object' && !Array.isArray(val)) {
15970
+ params[key] = JSON.stringify(val);
15971
+ }
15972
+ else {
15973
+ params[key] = val;
15974
+ }
15975
+ });
15976
+ }
15977
+ // Stringify parameters
15978
+ const stringifiedParams = qs.stringify(params || {}, {
15979
+ encodeValuesOnly: true,
15980
+ arrayFormat: 'brackets',
15981
+ });
15982
+ // Create url (include query if GET)
15983
+ const query = (method === 'GET' ? `?${stringifiedParams}` : '');
15984
+ let url;
15985
+ if (!opts.host) {
15986
+ // No host included at all. Just send to a path
15987
+ url = `${opts.path}${query}`;
15988
+ }
15989
+ else {
15990
+ url = `https://${opts.host}${opts.path}${query}`;
15991
+ }
15992
+ // Update headers
15993
+ const headers = opts.headers || {};
15994
+ let data = null;
15995
+ if (!headers['Content-Type']) {
15996
+ // Form encoded
15997
+ headers['Content-Type'] = 'application/x-www-form-urlencoded';
15998
+ // Add data if applicable
15999
+ data = (method !== 'GET' ? stringifiedParams : null);
16000
+ }
16001
+ else {
16002
+ // JSON encode
16003
+ data = params;
16004
+ }
16005
+ // Encode data
16006
+ let encodedData;
16007
+ if (data) {
16008
+ if (headers['Content-Type'] === 'application/x-www-form-urlencoded') {
16009
+ encodedData = new URLSearchParams(params);
16010
+ }
16011
+ else {
16012
+ encodedData = JSON.stringify(data);
16013
+ }
16014
+ }
16015
+ // Send request
16016
+ try {
16017
+ const response = yield fetch(url, {
16018
+ method,
16019
+ mode: 'cors',
16020
+ headers: headers !== null && headers !== void 0 ? headers : {},
16021
+ body: ((method !== 'GET' && encodedData)
16022
+ ? encodedData
16023
+ : undefined),
16024
+ redirect: 'follow',
16025
+ });
16026
+ // Get headers map
16027
+ const responseHeaders = {};
16028
+ response.headers.forEach((value, key) => {
16029
+ responseHeaders[key] = value;
16030
+ });
16031
+ // Process response based on responseType
16032
+ try {
16033
+ // Parse response
16034
+ let responseBody;
16035
+ if (opts.responseType
16036
+ && opts.responseType === 'Text') {
16037
+ // Response type is text
16038
+ responseBody = yield response.text();
16039
+ }
16040
+ else {
16041
+ // Response type is JSON
16042
+ responseBody = yield response.json();
16043
+ }
16044
+ // Return response
16045
+ return {
16046
+ body: responseBody,
16047
+ status: response.status,
16048
+ headers: responseHeaders,
16049
+ };
16050
+ }
16051
+ catch (err) {
16052
+ throw new ErrorWithCode(`Failed to parse response as ${opts.responseType}: ${err === null || err === void 0 ? void 0 : err.message}`, ReactKitErrorCode$1.ResponseParseError);
16053
+ }
16054
+ }
16055
+ catch (err) {
16056
+ // Self-signed certificate error:
16057
+ if ((_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.includes('self signed certificate')) {
16058
+ throw new ErrorWithCode('We refused to send a request because the receiver has self-signed certificates.', ReactKitErrorCode$1.SelfSigned);
16059
+ }
16060
+ // No tries left
16061
+ throw new ErrorWithCode(`We encountered an error when trying to send a network request. If this issue persists, contact an admin. Error: ${err === null || err === void 0 ? void 0 : err.message}`, ReactKitErrorCode$1.NotConnected);
16062
+ }
16063
+ });
16064
+
16065
+ /**
16066
+ * Send a server-to-server request from this sever to another server that uses
16067
+ * dce-reactkit [for server only]
16068
+ * @author Gabe Abrams
16069
+ * @param opts object containing all arguments
16070
+ * @param opts.path - the path of the other server's endpoint
16071
+ * @param [opts.method=GET] - the method of the endpoint
16072
+ * @param [opts.params] - query/body parameters to include
16073
+ * @param [opts.headers] - headers to include
16074
+ * @returns response from server
16075
+ */
16076
+ const visitEndpointOnAnotherServer = (opts) => __awaiter(void 0, void 0, void 0, function* () {
16077
+ var _a;
16078
+ // Remove properties with undefined values
16079
+ let params;
16080
+ if (opts.params) {
16081
+ params = Object.fromEntries(Object
16082
+ .entries(opts.params)
16083
+ .filter(([, value]) => {
16084
+ return value !== undefined;
16085
+ }));
16086
+ }
16087
+ // Automatically JSONify arrays and objects
16088
+ if (params) {
16089
+ params = Object.fromEntries(Object
16090
+ .entries(params)
16091
+ .map(([key, value]) => {
16092
+ if (Array.isArray(value) || typeof value === 'object') {
16093
+ return [key, JSON.stringify(value)];
16094
+ }
16095
+ return [key, value];
16096
+ }));
16097
+ }
16098
+ // Send the request
16099
+ const response = yield sendServerToServerRequest({
16100
+ path: opts.path,
16101
+ method: (_a = opts.method) !== null && _a !== void 0 ? _a : 'GET',
16102
+ params,
16103
+ });
16104
+ // Check for failure
16105
+ if (!response || !response.body) {
16106
+ throw new ErrorWithCode('We didn\'t get a response from the server. Please check your internet connection.', ReactKitErrorCode$1.NoResponse);
16107
+ }
16108
+ if (!response.body.success) {
16109
+ // Other errors
16110
+ throw new ErrorWithCode((response.body.message
16111
+ || 'An unknown error occurred. Please contact an admin.'), (response.body.code
16112
+ || ReactKitErrorCode$1.NoCode));
16113
+ }
16114
+ // Success! Extract the body
16115
+ const { body } = response.body;
16116
+ // Return
16117
+ return body;
16118
+ });
16119
+
15945
16120
  /**
15946
16121
  * Days of the week
15947
16122
  * @author Gabe Abrams
@@ -15958,5 +16133,5 @@ var DayOfWeek;
15958
16133
  })(DayOfWeek || (DayOfWeek = {}));
15959
16134
  var DayOfWeek$1 = DayOfWeek;
15960
16135
 
15961
- 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, visitServerEndpoint, waitMs };
16136
+ 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 };
15962
16137
  //# sourceMappingURL=index.js.map