@genesislcap/foundation-auth 15.68.0 → 15.68.1
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.
|
@@ -11,10 +11,10 @@ export declare const DEFAULT_LOCK_WAIT_MS: number;
|
|
|
11
11
|
* re-checks the session first, so a refresh done by the other tab is picked up without refreshing again.
|
|
12
12
|
*
|
|
13
13
|
* @param options.lockWaitMs - How long to wait for another tab's lock before giving up.
|
|
14
|
-
* @returns true when the session is valid afterwards; false when the server rejected the refresh (NACK or 4xx
|
|
15
|
-
* lock was still held at the deadline.
|
|
16
|
-
* @throws When the refresh could not complete (network error, 5xx, storage unavailable), so callers can tell
|
|
17
|
-
* transient failure from an expired refresh cookie.
|
|
14
|
+
* @returns true when the session is valid afterwards; false when the server rejected the refresh (NACK, or a 4xx other
|
|
15
|
+
* than 408/429) or the lock was still held at the deadline.
|
|
16
|
+
* @throws When the refresh could not complete (network error, 408, 429, 5xx, storage unavailable), so callers can tell
|
|
17
|
+
* a transient failure from an expired refresh cookie.
|
|
18
18
|
* @internal
|
|
19
19
|
*/
|
|
20
20
|
export declare function refreshCookieSession({ lockWaitMs, }?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-refresh.d.ts","sourceRoot":"","sources":["../../../src/machine/session-refresh.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"session-refresh.d.ts","sourceRoot":"","sources":["../../../src/machine/session-refresh.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,eAAO,MAAM,oBAAoB,QAA2C,CAAC;AAuB7E;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,oBAAoB,CAAC,EACzC,UAAiC,GAClC,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAOjD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import {
|
|
2
|
+
import { REAUTH_LOCK_TIMEOUT_MS, SessionRefreshResult, tryRefreshSession, waitForOtherTabReauth, } from '@genesislcap/foundation-comms';
|
|
3
3
|
import { logger } from '../utils';
|
|
4
4
|
/**
|
|
5
5
|
* Upper bound between lock checks, so a lock abandoned without a storage event is still picked up once it goes stale.
|
|
@@ -9,29 +9,19 @@ const LOCK_RECHECK_MS = 1000;
|
|
|
9
9
|
* Long enough for a lock left by another tab to go stale and be cleared by `tryRefreshSession`.
|
|
10
10
|
*/
|
|
11
11
|
export const DEFAULT_LOCK_WAIT_MS = REAUTH_LOCK_TIMEOUT_MS + LOCK_RECHECK_MS;
|
|
12
|
-
const HTTP_CLIENT_ERROR_MIN = 400;
|
|
13
|
-
const HTTP_SERVER_ERROR_MIN = 500;
|
|
14
12
|
const isRefreshed = (result) => result === SessionRefreshResult.SUCCESS || result === SessionRefreshResult.ALREADY_VALID;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
// AbortSignal.timeout's timer doesn't keep Node's event loop alive, so a test waiting only on it exits mid-wait.
|
|
14
|
+
const timeoutSignal = (ms) => {
|
|
15
|
+
const controller = new AbortController();
|
|
16
|
+
setTimeout(() => controller.abort(), ms);
|
|
17
|
+
return controller.signal;
|
|
18
18
|
};
|
|
19
|
-
const waitForLockRelease = (timeoutMs) => new Promise((resolve) => {
|
|
20
|
-
const timeout = setTimeout(() => {
|
|
21
|
-
unsubscribe();
|
|
22
|
-
resolve();
|
|
23
|
-
}, timeoutMs);
|
|
24
|
-
const unsubscribe = onOtherTabReauthComplete(() => {
|
|
25
|
-
clearTimeout(timeout);
|
|
26
|
-
resolve();
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
19
|
const refreshOnceLockIsFree = (deadline) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
20
|
const result = yield tryRefreshSession({ reloadOnFailure: false });
|
|
31
21
|
if (result !== SessionRefreshResult.HANDLED_BY_OTHER_TAB || Date.now() >= deadline) {
|
|
32
22
|
return result;
|
|
33
23
|
}
|
|
34
|
-
yield
|
|
24
|
+
yield waitForOtherTabReauth(timeoutSignal(Math.min(LOCK_RECHECK_MS, Math.max(0, deadline - Date.now()))));
|
|
35
25
|
return refreshOnceLockIsFree(deadline);
|
|
36
26
|
});
|
|
37
27
|
/**
|
|
@@ -43,10 +33,10 @@ const refreshOnceLockIsFree = (deadline) => __awaiter(void 0, void 0, void 0, fu
|
|
|
43
33
|
* re-checks the session first, so a refresh done by the other tab is picked up without refreshing again.
|
|
44
34
|
*
|
|
45
35
|
* @param options.lockWaitMs - How long to wait for another tab's lock before giving up.
|
|
46
|
-
* @returns true when the session is valid afterwards; false when the server rejected the refresh (NACK or 4xx
|
|
47
|
-
* lock was still held at the deadline.
|
|
48
|
-
* @throws When the refresh could not complete (network error, 5xx, storage unavailable), so callers can tell
|
|
49
|
-
* transient failure from an expired refresh cookie.
|
|
36
|
+
* @returns true when the session is valid afterwards; false when the server rejected the refresh (NACK, or a 4xx other
|
|
37
|
+
* than 408/429) or the lock was still held at the deadline.
|
|
38
|
+
* @throws When the refresh could not complete (network error, 408, 429, 5xx, storage unavailable), so callers can tell
|
|
39
|
+
* a transient failure from an expired refresh cookie.
|
|
50
40
|
* @internal
|
|
51
41
|
*/
|
|
52
42
|
export function refreshCookieSession() {
|
|
@@ -55,10 +45,6 @@ export function refreshCookieSession() {
|
|
|
55
45
|
return isRefreshed(yield refreshOnceLockIsFree(Date.now() + lockWaitMs));
|
|
56
46
|
}
|
|
57
47
|
catch (error) {
|
|
58
|
-
if (isRejectedByServer(error)) {
|
|
59
|
-
logger.debug('Session refresh rejected.', error);
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
48
|
logger.warn('Session refresh could not complete.', error);
|
|
63
49
|
throw error;
|
|
64
50
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genesislcap/foundation-auth",
|
|
3
3
|
"description": "Genesis Foundation Auth",
|
|
4
|
-
"version": "15.68.
|
|
4
|
+
"version": "15.68.1",
|
|
5
5
|
"license": "SEE LICENSE IN license.txt",
|
|
6
6
|
"main": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/foundation-auth.d.ts",
|
|
@@ -134,24 +134,24 @@
|
|
|
134
134
|
}
|
|
135
135
|
},
|
|
136
136
|
"devDependencies": {
|
|
137
|
-
"@genesislcap/foundation-testing": "15.68.
|
|
138
|
-
"@genesislcap/genx": "15.68.
|
|
139
|
-
"@genesislcap/ts-builder": "15.68.
|
|
140
|
-
"@genesislcap/uvu-playwright-builder": "15.68.
|
|
141
|
-
"@genesislcap/vite-builder": "15.68.
|
|
142
|
-
"@genesislcap/webpack-builder": "15.68.
|
|
137
|
+
"@genesislcap/foundation-testing": "15.68.1",
|
|
138
|
+
"@genesislcap/genx": "15.68.1",
|
|
139
|
+
"@genesislcap/ts-builder": "15.68.1",
|
|
140
|
+
"@genesislcap/uvu-playwright-builder": "15.68.1",
|
|
141
|
+
"@genesislcap/vite-builder": "15.68.1",
|
|
142
|
+
"@genesislcap/webpack-builder": "15.68.1"
|
|
143
143
|
},
|
|
144
144
|
"dependencies": {
|
|
145
|
-
"@genesislcap/foundation-comms": "15.68.
|
|
146
|
-
"@genesislcap/foundation-events": "15.68.
|
|
147
|
-
"@genesislcap/foundation-i18n": "15.68.
|
|
148
|
-
"@genesislcap/foundation-logger": "15.68.
|
|
149
|
-
"@genesislcap/foundation-state-machine": "15.68.
|
|
150
|
-
"@genesislcap/foundation-store": "15.68.
|
|
151
|
-
"@genesislcap/foundation-ui": "15.68.
|
|
152
|
-
"@genesislcap/foundation-user": "15.68.
|
|
153
|
-
"@genesislcap/foundation-utils": "15.68.
|
|
154
|
-
"@genesislcap/foundation-zero": "15.68.
|
|
145
|
+
"@genesislcap/foundation-comms": "15.68.1",
|
|
146
|
+
"@genesislcap/foundation-events": "15.68.1",
|
|
147
|
+
"@genesislcap/foundation-i18n": "15.68.1",
|
|
148
|
+
"@genesislcap/foundation-logger": "15.68.1",
|
|
149
|
+
"@genesislcap/foundation-state-machine": "15.68.1",
|
|
150
|
+
"@genesislcap/foundation-store": "15.68.1",
|
|
151
|
+
"@genesislcap/foundation-ui": "15.68.1",
|
|
152
|
+
"@genesislcap/foundation-user": "15.68.1",
|
|
153
|
+
"@genesislcap/foundation-utils": "15.68.1",
|
|
154
|
+
"@genesislcap/foundation-zero": "15.68.1",
|
|
155
155
|
"@microsoft/fast-components": "2.30.6",
|
|
156
156
|
"@microsoft/fast-element": "1.14.0",
|
|
157
157
|
"@microsoft/fast-foundation": "2.50.0",
|