dce-reactkit 3.6.3 → 3.6.4

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.
@@ -1,9 +1,3 @@
1
- /**
2
- * Set the session expiry handler
3
- * @author Gabe Abrams
4
- * @param handler new handler to use when session expires
5
- */
6
- export declare const setSessionExpiryHandler: (handler: () => void) => void;
7
1
  /**
8
2
  * Add a stub response
9
3
  * @author Gabe Abrams
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "3.6.3",
3
+ "version": "3.6.4",
4
4
  "description": "Shared components for Harvard DCE apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -5,57 +5,10 @@ import ErrorWithCode from '../errors/ErrorWithCode';
5
5
  import ReactKitErrorCode from '../types/ReactKitErrorCode';
6
6
 
7
7
  // Import helpers
8
+ // TODO: fix dependency cycle
9
+ // eslint-disable-next-line import/no-cycle
8
10
  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
- };
40
-
41
- /*------------------------------------------------------------------------*/
42
- /* Listener */
43
- /*------------------------------------------------------------------------*/
44
-
45
- // Handler for session expiry
46
- let sessionExpiryHandler: () => void;
47
-
48
- // Keep track of whether or not session expiry has already been handled
49
- let sessionAlreadyExpired = false;
50
-
51
- /**
52
- * Set the session expiry handler
53
- * @author Gabe Abrams
54
- * @param handler new handler to use when session expires
55
- */
56
- export const setSessionExpiryHandler = (handler: () => void) => {
57
- sessionExpiryHandler = handler;
58
- };
11
+ import { showSessionExpiredMessage } from '../components/AppWrapper';
59
12
 
60
13
  /*------------------------------------------------------------------------*/
61
14
  /* Stub Logic */
@@ -188,33 +141,10 @@ const visitServerEndpoint = async (
188
141
  if (!response.body.success) {
189
142
  // Session expired
190
143
  if (response.body.code === ReactKitErrorCode.SessionExpired) {
191
- // Skip notice if session was already expired
192
- if (sessionAlreadyExpired) {
193
- // Never return (browser is already reloading)
194
- await new Promise<{ [key in string]: any }>(() => {
195
- // Promise that never returns
196
- });
197
- }
198
- sessionAlreadyExpired = true;
199
-
200
- // Wait for helper to exist
201
- await waitForHelper(() => {
202
- return !!sessionExpiryHandler;
203
- });
204
-
205
- // Show session expiration message
206
- if (sessionExpiryHandler) {
207
- // Use handler
208
- sessionExpiryHandler();
209
- } else {
210
- // Fallback to alert
211
-
212
- // eslint-disable-next-line no-alert
213
- alert('Your session has expired. Please start over.');
214
- }
144
+ showSessionExpiredMessage();
215
145
 
216
146
  // Never return (don't continue execution)
217
- await new Promise<{ [key in string]: any }>(() => {
147
+ await new Promise(() => {
218
148
  // Promise that never returns
219
149
  });
220
150
  }