dce-reactkit 3.6.1 → 3.6.3

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.
@@ -50,7 +50,7 @@ export declare const confirm: (title: string, text: string, opts?: {
50
50
  * @param error the error to show
51
51
  * @param [errorTitle] title of the error box
52
52
  */
53
- export declare const showFatalError: (error: any, errorTitle?: string) => undefined;
53
+ export declare const showFatalError: (error: any, errorTitle?: string) => Promise<void>;
54
54
  /**
55
55
  * Add a handler for when a fatal error occurs
56
56
  * @author Gabe Abrams
@@ -60,6 +60,6 @@ export declare const addFatalErrorHandler: (handler: () => void) => void;
60
60
  * Show the "session expired" message
61
61
  * @author Gabe Abrams
62
62
  */
63
- export declare const showSessionExpiredMessage: () => undefined;
63
+ export declare const showSessionExpiredMessage: () => Promise<void>;
64
64
  declare const AppWrapper: React.FC<Props>;
65
65
  export default AppWrapper;
package/dist/esm/index.js CHANGED
@@ -644,6 +644,36 @@ var LogLevel;
644
644
  })(LogLevel || (LogLevel = {}));
645
645
  var LogLevel$1 = LogLevel;
646
646
 
647
+ /*------------------------------------------------------------------------*/
648
+ /* --------------------------- Static Helpers --------------------------- */
649
+ /*------------------------------------------------------------------------*/
650
+ // Timestamp after initialization when helpers should be available
651
+ const timestampWhenHelpersShouldBeAvailable$1 = Date.now() + 2000;
652
+ /**
653
+ * Wait for a little while for a helper to exist
654
+ * @author Gabe Abrams
655
+ * @param checkForHelper a function that returns true if the helper exists
656
+ * @returns true if the helper exists, false if the process timed out
657
+ */
658
+ const waitForHelper$1 = (checkForHelper) => __awaiter(void 0, void 0, void 0, function* () {
659
+ // Wait for helper to exist
660
+ while (!checkForHelper()) {
661
+ // Check if we should stop waiting
662
+ if (Date.now() > timestampWhenHelpersShouldBeAvailable$1) {
663
+ // Stop waiting
664
+ return false;
665
+ }
666
+ // Wait a little while
667
+ yield waitMs(10);
668
+ }
669
+ // Helper exists
670
+ return true;
671
+ });
672
+ /*------------------------------------------------------------------------*/
673
+ /* Listener */
674
+ /*------------------------------------------------------------------------*/
675
+ // Handler for session expiry
676
+ let sessionExpiryHandler;
647
677
  // Keep track of whether or not session expiry has already been handled
648
678
  let sessionAlreadyExpired = false;
649
679
  /*------------------------------------------------------------------------*/
@@ -736,6 +766,10 @@ const visitServerEndpoint = (opts) => __awaiter(void 0, void 0, void 0, function
736
766
  });
737
767
  }
738
768
  sessionAlreadyExpired = true;
769
+ // Wait for helper to exist
770
+ yield waitForHelper$1(() => {
771
+ return !!sessionExpiryHandler;
772
+ });
739
773
  // Show session expiration message
740
774
  {
741
775
  // Fallback to alert
@@ -802,6 +836,28 @@ const logClientEvent = (opts) => __awaiter(void 0, void 0, void 0, function* ()
802
836
  /*------------------------------------------------------------------------*/
803
837
  /* --------------------------- Static Helpers --------------------------- */
804
838
  /*------------------------------------------------------------------------*/
839
+ // Timestamp after initialization when helpers should be available
840
+ const timestampWhenHelpersShouldBeAvailable = Date.now() + 2000;
841
+ /**
842
+ * Wait for a little while for a helper to exist
843
+ * @author Gabe Abrams
844
+ * @param checkForHelper a function that returns true if the helper exists
845
+ * @returns true if the helper exists, false if the process timed out
846
+ */
847
+ const waitForHelper = (checkForHelper) => __awaiter(void 0, void 0, void 0, function* () {
848
+ // Wait for helper to exist
849
+ while (!checkForHelper()) {
850
+ // Check if we should stop waiting
851
+ if (Date.now() > timestampWhenHelpersShouldBeAvailable) {
852
+ // Stop waiting
853
+ return false;
854
+ }
855
+ // Wait a little while
856
+ yield waitMs(10);
857
+ }
858
+ // Helper exists
859
+ return true;
860
+ });
805
861
  /*----------------------------------------*/
806
862
  /* ----------- Redirect/Leave ----------- */
807
863
  /*----------------------------------------*/
@@ -848,6 +904,10 @@ let onAlertClosed;
848
904
  * @param text the text to display in the alert
849
905
  */
850
906
  const alert$1 = (title, text) => __awaiter(void 0, void 0, void 0, function* () {
907
+ // Wait for helper to exist
908
+ yield waitForHelper(() => {
909
+ return !!setAlertInfo;
910
+ });
851
911
  // Fallback if alert not available
852
912
  if (!setAlertInfo) {
853
913
  // eslint-disable-next-line no-alert
@@ -889,6 +949,10 @@ let onConfirmClosed;
889
949
  * @returns true if the user confirmed
890
950
  */
891
951
  const confirm = (title, text, opts) => __awaiter(void 0, void 0, void 0, function* () {
952
+ // Wait for helper to exist
953
+ yield waitForHelper(() => {
954
+ return !!setConfirmInfo;
955
+ });
892
956
  // Fallback if confirm is not available
893
957
  if (!setConfirmInfo) {
894
958
  // eslint-disable-next-line no-alert
@@ -923,7 +987,7 @@ const fatalErrorHandlers = [];
923
987
  * @param error the error to show
924
988
  * @param [errorTitle] title of the error box
925
989
  */
926
- const showFatalError = (error, errorTitle = 'An Error Occurred') => {
990
+ const showFatalError = (error, errorTitle = 'An Error Occurred') => __awaiter(void 0, void 0, void 0, function* () {
927
991
  var _a, _b;
928
992
  // Determine message and code
929
993
  const message = (typeof error === 'string'
@@ -953,17 +1017,21 @@ const showFatalError = (error, errorTitle = 'An Error Occurred') => {
953
1017
  errorTitle,
954
1018
  },
955
1019
  });
1020
+ // Wait for helper to exist
1021
+ yield waitForHelper(() => {
1022
+ return (!!setFatalErrorMessage
1023
+ && !!setFatalErrorCode);
1024
+ });
956
1025
  // Handle case where app hasn't loaded
957
1026
  if (!setFatalErrorMessage || !setFatalErrorCode) {
958
1027
  alert$1(errorTitle, `${message} (code: ${code}). Please contact support.`);
959
- return undefined;
1028
+ return;
960
1029
  }
961
1030
  // Use setters
962
1031
  setFatalErrorMessage(message);
963
1032
  setFatalErrorCode(code);
964
1033
  setFatalErrorTitle(errorTitle);
965
- return undefined;
966
- };
1034
+ });
967
1035
  /**
968
1036
  * Add a handler for when a fatal error occurs
969
1037
  * @author Gabe Abrams