dce-reactkit 3.3.1 → 3.3.2

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.
@@ -24,14 +24,7 @@ declare type SendRequestFunction = (opts: {
24
24
  * @author Gabe Abrams
25
25
  * @returns sendRequest function
26
26
  */
27
- export declare const getSendRequest: () => SendRequestFunction;
28
- declare let dark: boolean | undefined;
29
- /**
30
- * Get the current dark/light theme
31
- * @author Gabe Abrams
32
- * @returns true if the app has a dark theme
33
- */
34
- export declare const darkModeIsOn: () => boolean;
27
+ export declare const getSendRequest: () => Promise<SendRequestFunction>;
35
28
  declare let sessionExpiredMessage: string | undefined;
36
29
  /**
37
30
  * Get the custom session expired message
@@ -44,12 +37,10 @@ export declare const getSessionExpiredMessage: () => string;
44
37
  * @author Gabe Abrams
45
38
  * @param opts object containing all arguments
46
39
  * @param opts.sendRequest caccl send request functions
47
- * @param [opts.dark] if true, the app is a dark-themed app
48
40
  * @param [opts.sessionExpiredMessage] a custom session expired message
49
41
  */
50
42
  declare const initClient: (opts: {
51
43
  sendRequest: SendRequestFunction;
52
- dark?: boolean;
53
44
  sessionExpiredMessage?: string;
54
45
  }) => void;
55
46
  export default initClient;
@@ -7,6 +7,7 @@ import React from 'react';
7
7
  import Variant from '../types/Variant';
8
8
  declare type Props = {
9
9
  children: React.ReactNode;
10
+ dark?: boolean;
10
11
  };
11
12
  /**
12
13
  * Show an alert modal with an "Okay" button
package/dist/esm/index.js CHANGED
@@ -536,12 +536,14 @@ var LogLevel;
536
536
  })(LogLevel || (LogLevel = {}));
537
537
  var LogLevel$1 = LogLevel;
538
538
 
539
- // Import other components
540
539
  /*----------------------------------------*/
541
540
  /* ---- Static Variables and Getters ---- */
542
541
  /*----------------------------------------*/
543
542
  /* ----------- Initialized ---------- */
544
- let initialized = false;
543
+ let onInitialized;
544
+ let initialized = new Promise((resolve) => {
545
+ onInitialized = resolve;
546
+ });
545
547
  /* ---------- Send Request ---------- */
546
548
  let storedSendRequest;
547
549
  /**
@@ -549,9 +551,18 @@ let storedSendRequest;
549
551
  * @author Gabe Abrams
550
552
  * @returns sendRequest function
551
553
  */
552
- const getSendRequest = () => {
554
+ const getSendRequest = () => __awaiter(void 0, void 0, void 0, function* () {
555
+ // Wait for initialization or timeout
556
+ let timedOut = false;
557
+ yield Promise.all([
558
+ (() => __awaiter(void 0, void 0, void 0, function* () {
559
+ yield waitMs(1000);
560
+ timedOut = true;
561
+ }))(),
562
+ initialized,
563
+ ]);
553
564
  // Error if no send request function
554
- if (!initialized) {
565
+ if (timedOut) {
555
566
  showFatalError(new ErrorWithCode('Could not send a request because the request needed to be sent before dce-reactkit was properly initialized. Perhaps dce-reactkit was not initialized with initClient.', ReactKitErrorCode$1.NoCACCLSendRequestFunction));
556
567
  // Return dummy function that never resolves
557
568
  return (() => {
@@ -560,23 +571,7 @@ const getSendRequest = () => {
560
571
  }
561
572
  // Return
562
573
  return storedSendRequest;
563
- };
564
- /* ------------ Dark Mode ----------- */
565
- let dark;
566
- /**
567
- * Get the current dark/light theme
568
- * @author Gabe Abrams
569
- * @returns true if the app has a dark theme
570
- */
571
- const darkModeIsOn = () => {
572
- // Error if not set up yet
573
- if (!initialized) {
574
- showFatalError(new ErrorWithCode('Could not check theme color because dce-reactkit was properly initialized. Perhaps dce-reactkit was not initialized with initClient.', ReactKitErrorCode$1.ThemeCheckedBeforeReactKitReady));
575
- return false;
576
- }
577
- // Return
578
- return !!dark;
579
- };
574
+ });
580
575
  /* ----- Session Expired Message ---- */
581
576
  let sessionExpiredMessage;
582
577
  /**
@@ -585,11 +580,6 @@ let sessionExpiredMessage;
585
580
  * @returns session expired message
586
581
  */
587
582
  const getSessionExpiredMessage = () => {
588
- // Error if not set up yet
589
- if (!initialized) {
590
- showFatalError(new ErrorWithCode('Could not get the session expired message because dce-reactkit was properly initialized. Perhaps dce-reactkit was not initialized with initClient.', ReactKitErrorCode$1.SessionExpiredMessageGottenBeforeReactKitReady));
591
- return '';
592
- }
593
583
  // Return
594
584
  return (sessionExpiredMessage !== null && sessionExpiredMessage !== void 0 ? sessionExpiredMessage : 'Your session has expired. Please go back to Canvas and start over.');
595
585
  };
@@ -601,16 +591,14 @@ const getSessionExpiredMessage = () => {
601
591
  * @author Gabe Abrams
602
592
  * @param opts object containing all arguments
603
593
  * @param opts.sendRequest caccl send request functions
604
- * @param [opts.dark] if true, the app is a dark-themed app
605
594
  * @param [opts.sessionExpiredMessage] a custom session expired message
606
595
  */
607
596
  const initClient = (opts) => {
608
597
  // Store values
609
598
  storedSendRequest = opts.sendRequest;
610
- dark = !!opts.dark;
611
599
  sessionExpiredMessage = opts.sessionExpiredMessage;
612
600
  // Mark as initialized
613
- initialized = true;
601
+ onInitialized(null);
614
602
  };
615
603
 
616
604
  // Keep track of whether or not session expiry has already been handled
@@ -684,7 +672,7 @@ const visitServerEndpoint = (opts) => __awaiter(void 0, void 0, void 0, function
684
672
  throw new ErrorWithCode(stubResponse.errorMessage, stubResponse.errorCode);
685
673
  }
686
674
  // Send the request
687
- const sendRequest = getSendRequest();
675
+ const sendRequest = yield getSendRequest();
688
676
  const response = yield sendRequest({
689
677
  path: opts.path,
690
678
  method: (_c = opts.method) !== null && _c !== void 0 ? _c : 'GET',
@@ -895,7 +883,7 @@ const AppWrapper = (props) => {
895
883
  /* Setup */
896
884
  /*------------------------------------------------------------------------*/
897
885
  /* -------------- Props ------------- */
898
- const { children, } = props;
886
+ const { children, dark, } = props;
899
887
  /* -------------- State ------------- */
900
888
  // Fatal error
901
889
  const [fatalErrorMessage, setFatalErrorMessageInner,] = useState();
@@ -956,7 +944,7 @@ const AppWrapper = (props) => {
956
944
  width: '100vw',
957
945
  minHeight: '100vh',
958
946
  paddingTop: '2rem',
959
- backgroundColor: (darkModeIsOn()
947
+ backgroundColor: (dark
960
948
  ? '#222'
961
949
  : '#fff'),
962
950
  } },