@alviere/core 0.15.2 → 0.15.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.
package/dist/index.mjs
CHANGED
|
@@ -845,6 +845,21 @@ function getJWTExpiration(jwt) {
|
|
|
845
845
|
}
|
|
846
846
|
return new Date(payload.exp * 1e3);
|
|
847
847
|
}
|
|
848
|
+
function getJWTRefreshTime(jwt, earlyFraction = 0.05) {
|
|
849
|
+
const payload = decodeJWTPayload(jwt);
|
|
850
|
+
if (!payload || !payload.exp) return null;
|
|
851
|
+
const expMs = payload.exp * 1e3;
|
|
852
|
+
if (payload.iat) {
|
|
853
|
+
const iatMs = payload.iat * 1e3;
|
|
854
|
+
const lifetime = expMs - iatMs;
|
|
855
|
+
if (lifetime <= 0) return null;
|
|
856
|
+
return expMs - lifetime * earlyFraction;
|
|
857
|
+
}
|
|
858
|
+
const now = Date.now();
|
|
859
|
+
const remaining = expMs - now;
|
|
860
|
+
if (remaining <= 0) return null;
|
|
861
|
+
return now + remaining * (1 - earlyFraction);
|
|
862
|
+
}
|
|
848
863
|
class PaymentsGateway extends AlcoreBase {
|
|
849
864
|
/**
|
|
850
865
|
*
|
|
@@ -2519,6 +2534,7 @@ export {
|
|
|
2519
2534
|
getCERTIFICATE_ID,
|
|
2520
2535
|
getErrorMessage,
|
|
2521
2536
|
getJWTExpiration,
|
|
2537
|
+
getJWTRefreshTime,
|
|
2522
2538
|
getRSA_PUB_KEY,
|
|
2523
2539
|
getRuntimeConfig,
|
|
2524
2540
|
getSanitizedBody,
|