dce-reactkit 3.8.5 → 3.8.7

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.
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Send a server-to-server request from this sever to another server that uses
3
+ * dce-reactkit [for server only]
4
+ * @author Gabe Abrams
5
+ * @param opts object containing all arguments
6
+ * @param opts.path - the path of the other server's endpoint
7
+ * @param [opts.method=GET] - the method of the endpoint
8
+ * @param [opts.params] - query/body parameters to include
9
+ * @param [opts.headers] - headers to include
10
+ * @returns response from server
11
+ */
12
+ declare const visitEndpointOnAnotherServer: (opts: {
13
+ path: string;
14
+ method?: "GET" | "POST" | "DELETE" | "PUT" | undefined;
15
+ params?: {
16
+ [x: string]: any;
17
+ } | undefined;
18
+ headers?: {
19
+ [x: string]: any;
20
+ } | undefined;
21
+ }) => Promise<any>;
22
+ export default visitEndpointOnAnotherServer;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Sends and retries an http request
3
+ * @author Gabriel Abrams
4
+ * @param opts object containing all arguments
5
+ * @param opts.path path to send request to
6
+ * @param [opts.host] host to send request to
7
+ * @param [opts.method=GET] http method to use
8
+ * @param [opts.params] body/data to include in the request
9
+ * @param [opts.headers] headers to include in the request
10
+ * @param [opts.sendCrossDomainCredentials=true if in development mode] if true,
11
+ * send cross-domain credentials even if not in dev mode
12
+ * @param [opts.responseType=JSON] expected response type
13
+ * @returns { body, status, headers } on success
14
+ */
15
+ declare const sendServerToServerRequest: (opts: {
16
+ path: string;
17
+ host?: string | undefined;
18
+ method?: "GET" | "POST" | "DELETE" | "PUT" | undefined;
19
+ params?: {
20
+ [x: string]: any;
21
+ } | undefined;
22
+ headers?: {
23
+ [x: string]: any;
24
+ } | undefined;
25
+ responseType?: "Text" | "JSON" | undefined;
26
+ }) => Promise<{
27
+ body: any;
28
+ status: number;
29
+ headers: {
30
+ [x: string]: any;
31
+ };
32
+ }>;
33
+ export default sendServerToServerRequest;
@@ -21,6 +21,7 @@ import Tooltip from './components/Tooltip';
21
21
  import ToggleSwitch from './components/ToggleSwitch';
22
22
  import AutoscrollToBottomContainer from './components/AutoscrollToBottomContainer';
23
23
  import MultiSwitch from './components/MultiSwitch';
24
+ import Dropdown from './components/Dropdown';
24
25
  import ErrorWithCode from './errors/ErrorWithCode';
25
26
  import MINUTE_IN_MS from './constants/MINUTE_IN_MS';
26
27
  import HOUR_IN_MS from './constants/HOUR_IN_MS';
@@ -92,8 +93,9 @@ import LogBuiltInMetadata from './types/LogBuiltInMetadata';
92
93
  import LogMetadataType from './types/LogMetadataType';
93
94
  import LogFunction from './types/LogFunction';
94
95
  import IntelliTableColumn from './types/IntelliTableColumn';
96
+ import DropdownItemType from './types/DropdownItemType';
95
97
  import PickableItem from './components/ItemPicker/types/PickableItem';
96
98
  import DBEntry from './components/DBEntryManagerPanel/types/DBEntry';
97
99
  import DBEntryField from './components/DBEntryManagerPanel/types/DBEntryField';
98
100
  import DBEntryFieldType from './components/DBEntryManagerPanel/types/DBEntryFieldType';
99
- export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, DBEntryManagerPanel, Tooltip, ToggleSwitch, AutoscrollToBottomContainer, MultiSwitch, 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, PickableItem, DBEntry, DBEntryField, DBEntryFieldType, ParamType, };
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, };
@@ -15,6 +15,9 @@ declare enum ReactKitErrorCode {
15
15
  NotAdmin = "DRK10",
16
16
  NotAllowedToReviewLogs = "DRK11",
17
17
  ThemeCheckedBeforeReactKitReady = "DRK12",
18
- SessionExpiredMessageGottenBeforeReactKitReady = "DRK13"
18
+ SessionExpiredMessageGottenBeforeReactKitReady = "DRK13",
19
+ NotConnected = "DRK14",
20
+ SelfSigned = "DRK15",
21
+ ResponseParseError = "DRK16"
19
22
  }
20
23
  export default ReactKitErrorCode;
package/dist/index.d.ts CHANGED
@@ -24,7 +24,7 @@ declare enum Variant {
24
24
  * @author Gabe Abrams
25
25
  */
26
26
 
27
- type Props$k = {
27
+ type Props$l = {
28
28
  children: React$1.ReactNode;
29
29
  };
30
30
  /**
@@ -75,7 +75,7 @@ declare const showFatalError: (error: any, errorTitle?: string) => Promise<void>
75
75
  * @author Gabe Abrams
76
76
  */
77
77
  declare const addFatalErrorHandler: (handler: () => void) => void;
78
- declare const AppWrapper: React$1.FC<Props$k>;
78
+ declare const AppWrapper: React$1.FC<Props$l>;
79
79
 
80
80
  /**
81
81
  * Loading spinner/indicator
@@ -88,14 +88,14 @@ declare const LoadingSpinner: () => JSX.Element;
88
88
  * @author Gabe Abrams
89
89
  */
90
90
 
91
- type Props$j = {
91
+ type Props$k = {
92
92
  error: any;
93
93
  title?: string;
94
94
  onClose?: () => void;
95
95
  variant?: Variant;
96
96
  icon?: IconProp;
97
97
  };
98
- declare const ErrorBox: React$1.FC<Props$j>;
98
+ declare const ErrorBox: React$1.FC<Props$k>;
99
99
 
100
100
  /**
101
101
  * Types of buttons in the modal
@@ -191,20 +191,20 @@ declare const Modal: React$1.FC<ModalProps>;
191
191
  * @author Gabe Abrams
192
192
  */
193
193
 
194
- type Props$i = {
194
+ type Props$j = {
195
195
  title: React$1.ReactNode;
196
196
  children: React$1.ReactNode;
197
197
  noBottomMargin?: boolean;
198
198
  noBottomPadding?: boolean;
199
199
  };
200
- declare const TabBox: React$1.FC<Props$i>;
200
+ declare const TabBox: React$1.FC<Props$j>;
201
201
 
202
202
  /**
203
203
  * A radio selection button
204
204
  * @author Gabe Abrams
205
205
  */
206
206
 
207
- type Props$h = {
207
+ type Props$i = {
208
208
  text: React$1.ReactNode;
209
209
  onSelected: () => void;
210
210
  ariaLabel: string;
@@ -216,14 +216,14 @@ type Props$h = {
216
216
  unselectedVariant?: Variant;
217
217
  small?: boolean;
218
218
  };
219
- declare const RadioButton: React$1.FC<Props$h>;
219
+ declare const RadioButton: React$1.FC<Props$i>;
220
220
 
221
221
  /**
222
222
  * A checkbox button
223
223
  * @author Gabe Abrams
224
224
  */
225
225
 
226
- type Props$g = {
226
+ type Props$h = {
227
227
  text: React$1.ReactNode;
228
228
  onChanged: (checked: boolean) => void;
229
229
  ariaLabel: string;
@@ -237,14 +237,14 @@ type Props$g = {
237
237
  small?: boolean;
238
238
  dashed?: boolean;
239
239
  };
240
- declare const CheckboxButton: React$1.FC<Props$g>;
240
+ declare const CheckboxButton: React$1.FC<Props$h>;
241
241
 
242
242
  /**
243
243
  * Input group with a title and space for buttons
244
244
  * @author Gabe Abrams
245
245
  */
246
246
 
247
- type Props$f = {
247
+ type Props$g = {
248
248
  label: React$1.ReactNode;
249
249
  minLabelWidth?: string;
250
250
  children: React$1.ReactNode;
@@ -253,14 +253,14 @@ type Props$f = {
253
253
  isAdminFeature?: boolean;
254
254
  noMarginOnBottom?: boolean;
255
255
  };
256
- declare const ButtonInputGroup: React$1.FC<Props$f>;
256
+ declare const ButtonInputGroup: React$1.FC<Props$g>;
257
257
 
258
258
  /**
259
259
  * A very simple, lightweight date chooser
260
260
  * @author Gabe Abrams
261
261
  */
262
262
 
263
- type Props$e = {
263
+ type Props$f = {
264
264
  ariaLabel: string;
265
265
  name: string;
266
266
  month: number;
@@ -276,62 +276,62 @@ type Props$e = {
276
276
  numMonthsToShow?: number;
277
277
  chooseFromPast?: boolean;
278
278
  };
279
- declare const SimpleDateChooser: React$1.FC<Props$e>;
279
+ declare const SimpleDateChooser: React$1.FC<Props$f>;
280
280
 
281
281
  /**
282
282
  * Drawer container
283
283
  * @author Gabe Abrams
284
284
  */
285
285
 
286
- type Props$d = {
286
+ type Props$e = {
287
287
  grayBackground?: boolean;
288
288
  customBackgroundColor?: string;
289
289
  children: React$1.ReactNode;
290
290
  };
291
- declare const Drawer: React$1.FC<Props$d>;
291
+ declare const Drawer: React$1.FC<Props$e>;
292
292
 
293
293
  /**
294
294
  * Success checkmark that pops into view
295
295
  * @author Gabe Abrams
296
296
  */
297
297
 
298
- type Props$c = {
298
+ type Props$d = {
299
299
  sizeRem?: number;
300
300
  circleVariant?: string;
301
301
  checkVariant?: string;
302
302
  };
303
- declare const PopSuccessMark: React$1.FC<Props$c>;
303
+ declare const PopSuccessMark: React$1.FC<Props$d>;
304
304
 
305
305
  /**
306
306
  * Failure x mark that pops into view
307
307
  * @author Gabe Abrams
308
308
  */
309
309
 
310
- type Props$b = {
310
+ type Props$c = {
311
311
  sizeRem?: number;
312
312
  circleVariant?: string;
313
313
  xVariant?: string;
314
314
  };
315
- declare const PopFailureMark: React$1.FC<Props$b>;
315
+ declare const PopFailureMark: React$1.FC<Props$c>;
316
316
 
317
317
  /**
318
318
  * Failure pending that pops into view
319
319
  * @author Gabe Abrams
320
320
  */
321
321
 
322
- type Props$a = {
322
+ type Props$b = {
323
323
  sizeRem?: number;
324
324
  circleVariant?: string;
325
325
  hourglassVariant?: string;
326
326
  };
327
- declare const PopPendingMark: React$1.FC<Props$a>;
327
+ declare const PopPendingMark: React$1.FC<Props$b>;
328
328
 
329
329
  /**
330
330
  * Copiable text box
331
331
  * @author Gabe Abrams
332
332
  */
333
333
 
334
- type Props$9 = {
334
+ type Props$a = {
335
335
  text: string;
336
336
  maxTextWidthRem?: number;
337
337
  label?: string;
@@ -343,7 +343,7 @@ type Props$9 = {
343
343
  textAreaId?: string;
344
344
  copyButtonId?: string;
345
345
  };
346
- declare const CopiableBox: React$1.FC<Props$9>;
346
+ declare const CopiableBox: React$1.FC<Props$a>;
347
347
 
348
348
  /**
349
349
  * An item that can be chosen (for use within ItemPicker)
@@ -366,7 +366,7 @@ type PickableItem = ({
366
366
  * @author Yuen Ler Chow
367
367
  */
368
368
 
369
- type Props$8 = {
369
+ type Props$9 = {
370
370
  title: string;
371
371
  items: PickableItem[];
372
372
  /**
@@ -377,7 +377,7 @@ type Props$8 = {
377
377
  onChanged: (updatedItems: PickableItem[]) => void;
378
378
  noBottomMargin?: boolean;
379
379
  };
380
- declare const ItemPicker: React$1.FC<Props$8>;
380
+ declare const ItemPicker: React$1.FC<Props$9>;
381
381
 
382
382
  /**
383
383
  * Type of the context map in a LogMetadata file
@@ -422,11 +422,11 @@ type LogMetadataType = {
422
422
  * @author Gabe Abrams
423
423
  */
424
424
 
425
- type Props$7 = {
425
+ type Props$8 = {
426
426
  LogMetadata: LogMetadataType;
427
427
  onClose: () => void;
428
428
  };
429
- declare const LogReviewer: React$1.FC<Props$7>;
429
+ declare const LogReviewer: React$1.FC<Props$8>;
430
430
 
431
431
  /**
432
432
  * Server-side API param types
@@ -461,7 +461,7 @@ type IntelliTableColumn = {
461
461
  * @author Gabe Abrams
462
462
  */
463
463
 
464
- type Props$6 = {
464
+ type Props$7 = {
465
465
  title: string;
466
466
  id: string;
467
467
  data: {
@@ -471,14 +471,14 @@ type Props$6 = {
471
471
  columns: IntelliTableColumn[];
472
472
  csvName?: string;
473
473
  };
474
- declare const IntelliTable: React$1.FC<Props$6>;
474
+ declare const IntelliTable: React$1.FC<Props$7>;
475
475
 
476
476
  /**
477
477
  * Button for downloading a csv file
478
478
  * @author Gabe Abrams
479
479
  */
480
480
 
481
- type Props$5 = {
481
+ type Props$6 = {
482
482
  filename: string;
483
483
  csv: string;
484
484
  id?: string;
@@ -490,7 +490,7 @@ type Props$5 = {
490
490
  onClick?: () => void;
491
491
  children?: React$1.ReactNode;
492
492
  };
493
- declare const CSVDownloadButton: React$1.FC<Props$5>;
493
+ declare const CSVDownloadButton: React$1.FC<Props$6>;
494
494
 
495
495
  /**
496
496
  * Generic type for an object
@@ -566,7 +566,7 @@ type DBEntryField = ({
566
566
  * @author Gabe Abrams
567
567
  */
568
568
 
569
- type Props$4 = {
569
+ type Props$5 = {
570
570
  entryFields: DBEntryField[];
571
571
  idPropName: string;
572
572
  titlePropName: string;
@@ -592,18 +592,18 @@ type Props$4 = {
592
592
  [k: string]: any;
593
593
  };
594
594
  };
595
- declare const DBEntryManagerPanel: React$1.FC<Props$4>;
595
+ declare const DBEntryManagerPanel: React$1.FC<Props$5>;
596
596
 
597
597
  /**
598
598
  * Simple tooltip component
599
599
  * @author Gabe Abrams
600
600
  */
601
601
 
602
- type Props$3 = {
602
+ type Props$4 = {
603
603
  text: string;
604
604
  children: JSX.Element;
605
605
  };
606
- declare const Tooltip: React$1.FC<Props$3>;
606
+ declare const Tooltip: React$1.FC<Props$4>;
607
607
 
608
608
  /**
609
609
  * A toggle switch that toggles on or off
@@ -611,7 +611,7 @@ declare const Tooltip: React$1.FC<Props$3>;
611
611
  * @author Gabe Abrams
612
612
  */
613
613
 
614
- type Props$2 = {
614
+ type Props$3 = {
615
615
  isOn: boolean;
616
616
  /**
617
617
  * A handler to call when the switch is toggled
@@ -623,7 +623,7 @@ type Props$2 = {
623
623
  description: string;
624
624
  backgroundVariantWhenOn?: Variant;
625
625
  };
626
- declare const ToggleSwitch: React$1.FC<Props$2>;
626
+ declare const ToggleSwitch: React$1.FC<Props$3>;
627
627
 
628
628
  /**
629
629
  * Container that automatically scrolls when new items are added,
@@ -634,7 +634,7 @@ declare const ToggleSwitch: React$1.FC<Props$2>;
634
634
  * @author Gabe Abrams
635
635
  */
636
636
 
637
- type Props$1 = {
637
+ type Props$2 = {
638
638
  itemsName?: string;
639
639
  items: AutoScrollItem[];
640
640
  jumpToBottomButtonVariant?: Variant;
@@ -645,7 +645,7 @@ type AutoScrollItem = {
645
645
  id: string | number;
646
646
  item: React$1.ReactNode;
647
647
  };
648
- declare const AutoscrollToBottomContainer: React$1.FC<Props$1>;
648
+ declare const AutoscrollToBottomContainer: React$1.FC<Props$2>;
649
649
 
650
650
  /**
651
651
  * A switch with multiple options for selection
@@ -654,7 +654,7 @@ declare const AutoscrollToBottomContainer: React$1.FC<Props$1>;
654
654
  * @author Austen Money
655
655
  */
656
656
 
657
- type Props = {
657
+ type Props$1 = {
658
658
  options: Option[];
659
659
  selectedOptionId: string;
660
660
  /**
@@ -669,7 +669,43 @@ type Option = {
669
669
  icon: IconProp;
670
670
  id: string;
671
671
  };
672
- declare const MultiSwitch: React$1.FC<Props>;
672
+ declare const MultiSwitch: React$1.FC<Props$1>;
673
+
674
+ declare enum DropdownItemType {
675
+ Header = "Header",
676
+ Divider = "Divider",
677
+ Item = "Item"
678
+ }
679
+
680
+ /**
681
+ * A simple dropdown menu
682
+ * @author Alessandra De Lucas
683
+ * @author Yuen Ler Chow
684
+ * @author Gabe Abrams
685
+ */
686
+
687
+ type Props = {
688
+ items: DropdownItem[];
689
+ dropdownButton: {
690
+ ariaLabel: string;
691
+ id: string;
692
+ content?: React$1.ReactNode;
693
+ variant?: Variant;
694
+ };
695
+ };
696
+ type DropdownItem = ({
697
+ type: DropdownItemType.Header;
698
+ content: React$1.ReactNode;
699
+ } | {
700
+ type: DropdownItemType.Divider;
701
+ } | {
702
+ type: DropdownItemType.Item;
703
+ content: React$1.ReactNode;
704
+ ariaLabel: string;
705
+ id: string;
706
+ onClick: () => void;
707
+ });
708
+ declare const Dropdown: React$1.FC<Props>;
673
709
 
674
710
  /**
675
711
  * An error with a code
@@ -1584,7 +1620,10 @@ declare enum ReactKitErrorCode {
1584
1620
  NotAdmin = "DRK10",
1585
1621
  NotAllowedToReviewLogs = "DRK11",
1586
1622
  ThemeCheckedBeforeReactKitReady = "DRK12",
1587
- SessionExpiredMessageGottenBeforeReactKitReady = "DRK13"
1623
+ SessionExpiredMessageGottenBeforeReactKitReady = "DRK13",
1624
+ NotConnected = "DRK14",
1625
+ SelfSigned = "DRK15",
1626
+ ResponseParseError = "DRK16"
1588
1627
  }
1589
1628
 
1590
1629
  /**
@@ -1617,4 +1656,4 @@ declare const LogBuiltInMetadata: {
1617
1656
  };
1618
1657
  };
1619
1658
 
1620
- export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntry, DBEntryField, DBEntryFieldType, DBEntryManagerPanel, DayOfWeek, Drawer, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, IntelliTableColumn, ItemPicker, LoadingSpinner, Log, LogAction, LogBuiltInMetadata, LogFunction, LogMetadataType, LogReviewer, LogSource, LogType, MINUTE_IN_MS, Modal, ModalButtonType, ModalSize, ModalType, MultiSwitch, ParamType, PickableItem, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode, SimpleDateChooser, TabBox, ToggleSwitch, Tooltip, 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 };
1659
+ export { AppWrapper, AutoscrollToBottomContainer, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DBEntry, DBEntryField, DBEntryFieldType, DBEntryManagerPanel, DayOfWeek, Drawer, Dropdown, DropdownItemType, DynamicWord, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, IntelliTableColumn, ItemPicker, LoadingSpinner, Log, LogAction, LogBuiltInMetadata, LogFunction, LogMetadataType, LogReviewer, LogSource, LogType, MINUTE_IN_MS, Modal, ModalButtonType, ModalSize, ModalType, MultiSwitch, ParamType, PickableItem, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode, SimpleDateChooser, TabBox, ToggleSwitch, Tooltip, 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "3.8.5",
3
+ "version": "3.8.7",
4
4
  "description": "Shared components for Harvard DCE apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -24,6 +24,7 @@
24
24
  },
25
25
  "homepage": "https://github.com/harvard-edtech/dce-reactkit#readme",
26
26
  "dependencies": {
27
+ "qs": "^6.x.x",
27
28
  "react-select": "^5.7.3"
28
29
  },
29
30
  "peerDependencies": {
@@ -0,0 +1,90 @@
1
+ // Import custom error
2
+ import ErrorWithCode from '../../errors/ErrorWithCode';
3
+
4
+ // Import shared types
5
+ import ReactKitErrorCode from '../../types/ReactKitErrorCode';
6
+
7
+ // Import other helpers
8
+ import sendServerToServerRequest from './sendServerToServerRequest';
9
+
10
+ /**
11
+ * Send a server-to-server request from this sever to another server that uses
12
+ * dce-reactkit [for server only]
13
+ * @author Gabe Abrams
14
+ * @param opts object containing all arguments
15
+ * @param opts.path - the path of the other server's endpoint
16
+ * @param [opts.method=GET] - the method of the endpoint
17
+ * @param [opts.params] - query/body parameters to include
18
+ * @param [opts.headers] - headers to include
19
+ * @returns response from server
20
+ */
21
+ const visitEndpointOnAnotherServer = async (
22
+ opts: {
23
+ path: string,
24
+ method?: ('GET' | 'POST' | 'DELETE' | 'PUT'),
25
+ params?: { [key in string]: any },
26
+ headers?: { [k in string]: any },
27
+ },
28
+ ): Promise<any> => {
29
+ // Remove properties with undefined values
30
+ let params: { [key in string]: any } | undefined;
31
+ if (opts.params) {
32
+ params = Object.fromEntries(
33
+ Object
34
+ .entries(opts.params)
35
+ .filter(([, value]) => {
36
+ return value !== undefined;
37
+ }),
38
+ );
39
+ }
40
+
41
+ // Automatically JSONify arrays and objects
42
+ if (params) {
43
+ params = Object.fromEntries(
44
+ Object
45
+ .entries(params)
46
+ .map(([key, value]) => {
47
+ if (Array.isArray(value) || typeof value === 'object') {
48
+ return [key, JSON.stringify(value)];
49
+ }
50
+ return [key, value];
51
+ }),
52
+ );
53
+ }
54
+
55
+ // Send the request
56
+ const response = await sendServerToServerRequest({
57
+ path: opts.path,
58
+ method: opts.method ?? 'GET',
59
+ params,
60
+ });
61
+
62
+ // Check for failure
63
+ if (!response || !response.body) {
64
+ throw new ErrorWithCode(
65
+ 'We didn\'t get a response from the server. Please check your internet connection.',
66
+ ReactKitErrorCode.NoResponse,
67
+ );
68
+ }
69
+ if (!response.body.success) {
70
+ // Other errors
71
+ throw new ErrorWithCode(
72
+ (
73
+ response.body.message
74
+ || 'An unknown error occurred. Please contact an admin.'
75
+ ),
76
+ (
77
+ response.body.code
78
+ || ReactKitErrorCode.NoCode
79
+ ),
80
+ );
81
+ }
82
+
83
+ // Success! Extract the body
84
+ const { body } = response.body;
85
+
86
+ // Return
87
+ return body;
88
+ };
89
+
90
+ export default visitEndpointOnAnotherServer;