dce-reactkit 3.6.2 → 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.
@@ -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: () => void;
63
+ export declare const showSessionExpiredMessage: () => Promise<void>;
64
64
  declare const AppWrapper: React.FC<Props>;
65
65
  export default AppWrapper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "3.6.2",
3
+ "version": "3.6.3",
4
4
  "description": "Shared components for Harvard DCE apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -329,8 +329,21 @@ let setSessionHasExpired: (isExpired: boolean) => void;
329
329
  * Show the "session expired" message
330
330
  * @author Gabe Abrams
331
331
  */
332
- export const showSessionExpiredMessage = () => {
333
- setSessionHasExpired(true);
332
+ export const showSessionExpiredMessage = async () => {
333
+ // Wait for helper to exist
334
+ await waitForHelper(() => {
335
+ return !!setSessionHasExpired;
336
+ });
337
+
338
+ // Show session expired message
339
+ if (setSessionHasExpired) {
340
+ setSessionHasExpired(true);
341
+ } else {
342
+ showFatalError(
343
+ 'Your session has expired. Please start over.',
344
+ 'Session Expired',
345
+ );
346
+ }
334
347
  };
335
348
 
336
349
  /*------------------------------------------------------------------------*/
@@ -1,9 +1,42 @@
1
+ /* eslint-disable no-underscore-dangle */
2
+ /* eslint-disable @typescript-eslint/naming-convention */
1
3
  // Import custom error
2
4
  import ErrorWithCode from '../errors/ErrorWithCode';
3
5
  import ReactKitErrorCode from '../types/ReactKitErrorCode';
4
6
 
5
7
  // Import helpers
6
8
  import { getSendRequest } from '../client/initClient';
9
+ import waitMs from './waitMs';
10
+
11
+ /*------------------------------------------------------------------------*/
12
+ /* --------------------------- Static Helpers --------------------------- */
13
+ /*------------------------------------------------------------------------*/
14
+
15
+ // Timestamp after initialization when helpers should be available
16
+ const timestampWhenHelpersShouldBeAvailable = Date.now() + 2000;
17
+
18
+ /**
19
+ * Wait for a little while for a helper to exist
20
+ * @author Gabe Abrams
21
+ * @param checkForHelper a function that returns true if the helper exists
22
+ * @returns true if the helper exists, false if the process timed out
23
+ */
24
+ const waitForHelper = async (checkForHelper: () => boolean): Promise<boolean> => {
25
+ // Wait for helper to exist
26
+ while (!checkForHelper()) {
27
+ // Check if we should stop waiting
28
+ if (Date.now() > timestampWhenHelpersShouldBeAvailable) {
29
+ // Stop waiting
30
+ return false;
31
+ }
32
+
33
+ // Wait a little while
34
+ await waitMs(10);
35
+ }
36
+
37
+ // Helper exists
38
+ return true;
39
+ };
7
40
 
8
41
  /*------------------------------------------------------------------------*/
9
42
  /* Listener */
@@ -164,6 +197,11 @@ const visitServerEndpoint = async (
164
197
  }
165
198
  sessionAlreadyExpired = true;
166
199
 
200
+ // Wait for helper to exist
201
+ await waitForHelper(() => {
202
+ return !!sessionExpiryHandler;
203
+ });
204
+
167
205
  // Show session expiration message
168
206
  if (sessionExpiryHandler) {
169
207
  // Use handler