formreader-session-timeout 0.2.0 → 0.2.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.
- package/dist/index.d.ts +9 -1
- package/dist/index.js +44 -0
- package/dist/index.mjs +43 -0
- package/package.json +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Session Timeout Micro Frontend Types
|
|
3
5
|
* Configurable, reusable types for multi-application token refresh management
|
|
@@ -213,4 +215,10 @@ declare function useSessionTimeout(options?: UseSessionTimeoutOptions): {
|
|
|
213
215
|
manager: SessionManager;
|
|
214
216
|
};
|
|
215
217
|
|
|
216
|
-
|
|
218
|
+
/**
|
|
219
|
+
* SessionStatus - Displays countdown timer
|
|
220
|
+
* Drop this component in your header to show session time remaining
|
|
221
|
+
*/
|
|
222
|
+
declare function SessionStatus(): react_jsx_runtime.JSX.Element;
|
|
223
|
+
|
|
224
|
+
export { DEFAULT_SESSION_CONFIG, JWTPayload, RefreshTokenResponse, SessionConfig, SessionManager, SessionState, SessionStatus, TokenInfo, UseSessionTimeoutOptions, clearToken, getSessionManager, getStoredToken, getTimeUntilExpiry, getTokenInfo, isTokenExpired, resetSessionManager, storeToken, useSessionTimeout, validateToken };
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ var session_timeout_exports = {};
|
|
|
21
21
|
__export(session_timeout_exports, {
|
|
22
22
|
DEFAULT_SESSION_CONFIG: () => DEFAULT_SESSION_CONFIG,
|
|
23
23
|
SessionManager: () => SessionManager,
|
|
24
|
+
SessionStatus: () => SessionStatus,
|
|
24
25
|
clearToken: () => clearToken,
|
|
25
26
|
getSessionManager: () => getSessionManager,
|
|
26
27
|
getStoredToken: () => getStoredToken,
|
|
@@ -573,10 +574,53 @@ function useSessionTimeout(options = {}) {
|
|
|
573
574
|
manager: managerRef.current
|
|
574
575
|
};
|
|
575
576
|
}
|
|
577
|
+
|
|
578
|
+
// components/SessionStatus.tsx
|
|
579
|
+
var import_react2 = require("react");
|
|
580
|
+
var import_react_router_dom = require("react-router-dom");
|
|
581
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
582
|
+
function SessionStatus() {
|
|
583
|
+
const [displayTime, setDisplayTime] = (0, import_react2.useState)("--:--");
|
|
584
|
+
const [isActive, setIsActive] = (0, import_react2.useState)(true);
|
|
585
|
+
const navigate = (0, import_react_router_dom.useNavigate)();
|
|
586
|
+
(0, import_react2.useEffect)(() => {
|
|
587
|
+
const updateTime = () => {
|
|
588
|
+
try {
|
|
589
|
+
const token = getStoredToken();
|
|
590
|
+
if (!token)
|
|
591
|
+
return;
|
|
592
|
+
const info = getTokenInfo(token);
|
|
593
|
+
if (info) {
|
|
594
|
+
const seconds = Math.round(info.expiresIn / 1e3);
|
|
595
|
+
const minutes = Math.floor(seconds / 60);
|
|
596
|
+
const secs = seconds % 60;
|
|
597
|
+
setDisplayTime(`${minutes}:${secs.toString().padStart(2, "0")}`);
|
|
598
|
+
setIsActive(info.expiresIn > 0);
|
|
599
|
+
}
|
|
600
|
+
} catch (error) {
|
|
601
|
+
console.error("[SessionStatus] Error:", error);
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
updateTime();
|
|
605
|
+
const interval = setInterval(updateTime, 1e3);
|
|
606
|
+
return () => clearInterval(interval);
|
|
607
|
+
}, [navigate]);
|
|
608
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "bg-white border-b border-gray-200 px-4 py-2 flex justify-between items-center", children: [
|
|
609
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "text-sm font-medium text-gray-700", children: [
|
|
610
|
+
"Session expires: ",
|
|
611
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "font-mono font-bold text-blue-600", children: displayTime })
|
|
612
|
+
] }) }),
|
|
613
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
614
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `w-2 h-2 rounded-full ${isActive ? "bg-green-500" : "bg-red-500"}` }),
|
|
615
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-sm text-gray-600", children: isActive ? "Active" : "Expired" })
|
|
616
|
+
] })
|
|
617
|
+
] });
|
|
618
|
+
}
|
|
576
619
|
// Annotate the CommonJS export names for ESM import in node:
|
|
577
620
|
0 && (module.exports = {
|
|
578
621
|
DEFAULT_SESSION_CONFIG,
|
|
579
622
|
SessionManager,
|
|
623
|
+
SessionStatus,
|
|
580
624
|
clearToken,
|
|
581
625
|
getSessionManager,
|
|
582
626
|
getStoredToken,
|
package/dist/index.mjs
CHANGED
|
@@ -537,9 +537,52 @@ function useSessionTimeout(options = {}) {
|
|
|
537
537
|
manager: managerRef.current
|
|
538
538
|
};
|
|
539
539
|
}
|
|
540
|
+
|
|
541
|
+
// components/SessionStatus.tsx
|
|
542
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
543
|
+
import { useNavigate } from "react-router-dom";
|
|
544
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
545
|
+
function SessionStatus() {
|
|
546
|
+
const [displayTime, setDisplayTime] = useState2("--:--");
|
|
547
|
+
const [isActive, setIsActive] = useState2(true);
|
|
548
|
+
const navigate = useNavigate();
|
|
549
|
+
useEffect2(() => {
|
|
550
|
+
const updateTime = () => {
|
|
551
|
+
try {
|
|
552
|
+
const token = getStoredToken();
|
|
553
|
+
if (!token)
|
|
554
|
+
return;
|
|
555
|
+
const info = getTokenInfo(token);
|
|
556
|
+
if (info) {
|
|
557
|
+
const seconds = Math.round(info.expiresIn / 1e3);
|
|
558
|
+
const minutes = Math.floor(seconds / 60);
|
|
559
|
+
const secs = seconds % 60;
|
|
560
|
+
setDisplayTime(`${minutes}:${secs.toString().padStart(2, "0")}`);
|
|
561
|
+
setIsActive(info.expiresIn > 0);
|
|
562
|
+
}
|
|
563
|
+
} catch (error) {
|
|
564
|
+
console.error("[SessionStatus] Error:", error);
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
updateTime();
|
|
568
|
+
const interval = setInterval(updateTime, 1e3);
|
|
569
|
+
return () => clearInterval(interval);
|
|
570
|
+
}, [navigate]);
|
|
571
|
+
return /* @__PURE__ */ jsxs("div", { className: "bg-white border-b border-gray-200 px-4 py-2 flex justify-between items-center", children: [
|
|
572
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsxs("span", { className: "text-sm font-medium text-gray-700", children: [
|
|
573
|
+
"Session expires: ",
|
|
574
|
+
/* @__PURE__ */ jsx("span", { className: "font-mono font-bold text-blue-600", children: displayTime })
|
|
575
|
+
] }) }),
|
|
576
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
577
|
+
/* @__PURE__ */ jsx("div", { className: `w-2 h-2 rounded-full ${isActive ? "bg-green-500" : "bg-red-500"}` }),
|
|
578
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm text-gray-600", children: isActive ? "Active" : "Expired" })
|
|
579
|
+
] })
|
|
580
|
+
] });
|
|
581
|
+
}
|
|
540
582
|
export {
|
|
541
583
|
DEFAULT_SESSION_CONFIG,
|
|
542
584
|
SessionManager,
|
|
585
|
+
SessionStatus,
|
|
543
586
|
clearToken,
|
|
544
587
|
getSessionManager,
|
|
545
588
|
getStoredToken,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formreader-session-timeout",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Session timeout microfrontend: configurable JWT expiry decoding and refresh with idle tracking",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"clean": "rm -rf dist"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"react": "^16 || ^17 || ^18"
|
|
16
|
+
"react": "^16 || ^17 || ^18",
|
|
17
|
+
"react-router-dom": "^6"
|
|
17
18
|
},
|
|
18
19
|
"dependencies": {
|
|
19
20
|
"whatwg-fetch": "^3.6.2"
|
|
@@ -21,6 +22,8 @@
|
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"@types/node": "^25.0.3",
|
|
23
24
|
"@types/react": "^19.2.7",
|
|
25
|
+
"@types/react-router-dom": "^5.3.3",
|
|
26
|
+
"react-router-dom": "^7.11.0",
|
|
24
27
|
"tsup": "^6.5.0",
|
|
25
28
|
"typescript": "^4.9.5"
|
|
26
29
|
},
|