@tstdl/base 0.93.147 → 0.93.148
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.
|
@@ -23,6 +23,7 @@ import { Logger } from '../../logger/index.js';
|
|
|
23
23
|
import { MessageBus } from '../../message-bus/index.js';
|
|
24
24
|
import { computed, signal, toObservable } from '../../signals/api.js';
|
|
25
25
|
import { currentTimestampSeconds } from '../../utils/date-time.js';
|
|
26
|
+
import { clamp } from '../../utils/math.js';
|
|
26
27
|
import { timeout } from '../../utils/timing.js';
|
|
27
28
|
import { assertDefinedPass, isDefined, isInstanceOf, isNotFunction, isNullOrUndefined, isUndefined } from '../../utils/type-guards.js';
|
|
28
29
|
import { millisecondsPerMinute, millisecondsPerSecond, secondsPerHour } from '../../utils/units.js';
|
|
@@ -36,6 +37,7 @@ const impersonatorAuthenticationDataStorageKey = 'AuthenticationService:imperson
|
|
|
36
37
|
const tokenUpdateBusName = 'AuthenticationService:tokenUpdate';
|
|
37
38
|
const loggedOutBusName = 'AuthenticationService:loggedOut';
|
|
38
39
|
const refreshLockResource = 'AuthenticationService:refresh';
|
|
40
|
+
const minRefreshDelay = millisecondsPerMinute;
|
|
39
41
|
const maxRefreshDelay = 15 * millisecondsPerMinute;
|
|
40
42
|
const lockTimeout = 10_000;
|
|
41
43
|
const logoutTimeout = 150;
|
|
@@ -409,14 +411,16 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
409
411
|
const now = this.estimatedServerTimestampSeconds();
|
|
410
412
|
const forceRefresh = this.forceRefreshRequested();
|
|
411
413
|
const refreshBufferSeconds = calculateRefreshBufferSeconds(token);
|
|
412
|
-
|
|
414
|
+
// Integer comparison consistency: floor the threshold to avoid busy loops when 'now' (in seconds) is slightly below a float threshold
|
|
415
|
+
const needsRefresh = forceRefresh || (now >= Math.floor(token.exp - refreshBufferSeconds));
|
|
413
416
|
if (needsRefresh) {
|
|
414
417
|
const lockResult = await this.lock.tryUse(undefined, async () => {
|
|
415
418
|
const currentToken = this.token();
|
|
416
419
|
const currentNow = this.estimatedServerTimestampSeconds();
|
|
417
420
|
const currentRefreshBufferSeconds = isDefined(currentToken) ? calculateRefreshBufferSeconds(currentToken) : 0;
|
|
418
421
|
// Passive Sync: Check if another tab refreshed the token while we were waiting for the lock (or trying to get it)
|
|
419
|
-
|
|
422
|
+
// Integer comparison consistency: floor the threshold
|
|
423
|
+
const stillNeedsRefresh = isDefined(currentToken) && (this.forceRefreshRequested() || (currentNow >= Math.floor(currentToken.exp - currentRefreshBufferSeconds)));
|
|
420
424
|
if (stillNeedsRefresh) {
|
|
421
425
|
await this.refresh();
|
|
422
426
|
}
|
|
@@ -438,11 +442,14 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
438
442
|
}
|
|
439
443
|
}
|
|
440
444
|
const currentToken = this.token();
|
|
441
|
-
|
|
442
|
-
|
|
445
|
+
if (isUndefined(currentToken)) {
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
const currentRefreshBufferSeconds = calculateRefreshBufferSeconds(currentToken);
|
|
449
|
+
const delay = clamp((currentToken.exp - this.estimatedServerTimestampSeconds() - currentRefreshBufferSeconds) * millisecondsPerSecond, minRefreshDelay, maxRefreshDelay);
|
|
443
450
|
const wakeUpSignals = [
|
|
444
451
|
from(this.disposeSignal),
|
|
445
|
-
this.token$.pipe(filter((t) => t?.jti != currentToken
|
|
452
|
+
this.token$.pipe(filter((t) => t?.jti != currentToken.jti)),
|
|
446
453
|
];
|
|
447
454
|
if (!forceRefresh) {
|
|
448
455
|
wakeUpSignals.push(this.forceRefreshRequested$.pipe(filter((requested) => requested)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.93.
|
|
3
|
+
"version": "0.93.148",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -190,13 +190,13 @@
|
|
|
190
190
|
"@types/mjml": "4.7",
|
|
191
191
|
"@types/node": "25",
|
|
192
192
|
"@types/nodemailer": "7.0",
|
|
193
|
-
"@types/pg": "8.
|
|
193
|
+
"@types/pg": "8.18",
|
|
194
194
|
"@vitest/coverage-v8": "4.0",
|
|
195
195
|
"@vitest/ui": "4.0",
|
|
196
196
|
"concurrently": "9.2",
|
|
197
197
|
"drizzle-kit": "0.31",
|
|
198
198
|
"eslint": "9.39",
|
|
199
|
-
"globals": "17.
|
|
199
|
+
"globals": "17.4",
|
|
200
200
|
"tsc-alias": "1.8",
|
|
201
201
|
"typedoc-github-wiki-theme": "2.1",
|
|
202
202
|
"typedoc-plugin-markdown": "4.10",
|