@tstdl/base 0.93.164 → 0.93.165
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.
|
@@ -404,9 +404,7 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
404
404
|
timer(Math.max(10, delayMs)),
|
|
405
405
|
from(this.disposeSignal),
|
|
406
406
|
this.token$.pipe(filter((t) => t?.exp !== referenceExp)),
|
|
407
|
-
this.forceRefreshRequested$.pipe(filter(Boolean),
|
|
408
|
-
// Skip the current value if already true to prevent infinite tight loops
|
|
409
|
-
skip(this.forceRefreshRequested() ? 1 : 0)),
|
|
407
|
+
this.forceRefreshRequested$.pipe(filter(Boolean), skip(1)),
|
|
410
408
|
]), { defaultValue: undefined });
|
|
411
409
|
while (this.disposeSignal.isUnset) {
|
|
412
410
|
const token = this.token();
|
|
@@ -430,10 +428,10 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
430
428
|
const currentNow = this.estimatedServerTimestampSeconds();
|
|
431
429
|
const currentBuffer = calculateRefreshBufferSeconds(currentToken);
|
|
432
430
|
const stillNeedsRefresh = this.forceRefreshRequested() || (currentNow >= currentToken.exp - currentBuffer);
|
|
431
|
+
this.forceRefreshRequested.set(false);
|
|
433
432
|
if (stillNeedsRefresh) {
|
|
434
433
|
await this.refresh();
|
|
435
434
|
}
|
|
436
|
-
this.forceRefreshRequested.set(false);
|
|
437
435
|
});
|
|
438
436
|
// If lock is held by another instance/tab, wait briefly for it to finish (passive sync)
|
|
439
437
|
if (!lockResult.success) {
|
|
@@ -447,7 +445,10 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
447
445
|
}
|
|
448
446
|
// 3. Calculate delay and sleep until the next scheduled refresh window
|
|
449
447
|
const timeUntilRefreshMs = (token.exp - this.estimatedServerTimestampSeconds() - buffer) * millisecondsPerSecond;
|
|
450
|
-
|
|
448
|
+
let delay = clamp(timeUntilRefreshMs, minRefreshDelay, maxRefreshDelay);
|
|
449
|
+
if (Number.isNaN(delay)) {
|
|
450
|
+
delay = minRefreshDelay;
|
|
451
|
+
}
|
|
451
452
|
await waitForNextAction(delay, token.exp);
|
|
452
453
|
}
|
|
453
454
|
catch (error) {
|
|
@@ -471,6 +472,9 @@ let AuthenticationClientService = class AuthenticationClientService {
|
|
|
471
472
|
async syncClock() {
|
|
472
473
|
try {
|
|
473
474
|
const serverTimestamp = await this.client.timestamp();
|
|
475
|
+
if (Number.isNaN(serverTimestamp)) {
|
|
476
|
+
throw new Error('Server timestamp is NaN');
|
|
477
|
+
}
|
|
474
478
|
this.clockOffset = serverTimestamp - currentTimestampSeconds();
|
|
475
479
|
}
|
|
476
480
|
catch (error) {
|
|
@@ -538,5 +542,6 @@ export { AuthenticationClientService };
|
|
|
538
542
|
function calculateRefreshBufferSeconds(token) {
|
|
539
543
|
const iat = token.iat ?? (token.exp - secondsPerHour);
|
|
540
544
|
const lifetime = token.exp - iat;
|
|
541
|
-
|
|
545
|
+
const buffer = (lifetime * 0.1) + 5;
|
|
546
|
+
return Number.isNaN(buffer) ? 5 : buffer;
|
|
542
547
|
}
|