strapi-plugin-magic-sessionmanager 4.7.2 → 4.8.0
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/CHANGELOG.md +20 -0
- package/README.md +17 -38
- package/dist/admin/Analytics-CaRlu5ad.js +332 -0
- package/dist/admin/Analytics-THqDbNX0.mjs +330 -0
- package/dist/admin/App-AbZwLHtF.js +1263 -0
- package/dist/admin/App-hSh7guii.mjs +1261 -0
- package/dist/admin/FormField-C8kIT2NE.mjs +59 -0
- package/dist/admin/FormField-b5KBvkrj.js +60 -0
- package/dist/admin/License-BXBVwUVu.mjs +299 -0
- package/dist/admin/License-CABdPwnd.js +301 -0
- package/dist/admin/OnlineUsersWidget-BnWFj9IM.mjs +230 -0
- package/dist/admin/OnlineUsersWidget-CPFAACSb.js +230 -0
- package/dist/admin/PluginPageLayout-BPFMcgrx.mjs +42 -0
- package/dist/admin/PluginPageLayout-DmNzMdqu.js +43 -0
- package/dist/admin/Settings-B4DNdeKx.js +2152 -0
- package/dist/admin/Settings-C4RsJosh.mjs +2150 -0
- package/dist/admin/{de-JBE-iylO.mjs → de-AwIFTd9i.mjs} +154 -20
- package/dist/admin/{de-BnqGCokx.js → de-D23nmqnl.js} +154 -20
- package/dist/admin/{en-BRmVwd8-.js → en-C5iYQ0mC.js} +155 -21
- package/dist/admin/{en-kQWtdEai.mjs → en-D6QEGeRh.mjs} +155 -21
- package/dist/admin/{es-CH691xcL.js → es-CIXnsG-p.js} +154 -20
- package/dist/admin/{es-DOQvBxih.mjs → es-CnFfVdKw.mjs} +154 -20
- package/dist/admin/{fr-CLExO0w_.js → fr-BglXE-W4.js} +154 -20
- package/dist/admin/{fr-CmfCpepX.mjs → fr-DefoR7uH.mjs} +154 -20
- package/dist/admin/index-BFVITQ-o.mjs +624 -0
- package/dist/admin/{index-Duc7cR_d.js → index-DlMm-NyK.js} +261 -188
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/maskSensitiveValue-1uGWmrfG.mjs +20 -0
- package/dist/admin/maskSensitiveValue-B9vhxPad.js +19 -0
- package/dist/admin/{pt-BJ_F0yNi.js → pt-J5sf7jiY.js} +154 -20
- package/dist/admin/{pt-BSzZdyAH.mjs → pt-TODwvNQA.mjs} +154 -20
- package/dist/server/index.js +4396 -7820
- package/dist/server/index.mjs +4396 -7820
- package/package.json +21 -19
- package/scripts/geoip-updater.cjs +234 -15
- package/scripts/update-geoip-db.mjs +3 -0
- package/dist/admin/Analytics-CsrpxJwQ.mjs +0 -497
- package/dist/admin/Analytics-D03ZNNMR.js +0 -499
- package/dist/admin/App-B2VCS3cz.js +0 -1481
- package/dist/admin/App-qxKnK7G2.mjs +0 -1479
- package/dist/admin/License-ClW7sZLR.mjs +0 -318
- package/dist/admin/License-fixnQ7wF.js +0 -320
- package/dist/admin/OnlineUsersWidget-mR_OMiwi.mjs +0 -185
- package/dist/admin/OnlineUsersWidget-qb9utPBy.js +0 -185
- package/dist/admin/Settings-U3V4eGMo.mjs +0 -2038
- package/dist/admin/Settings-gv2BF54w.js +0 -2040
- package/dist/admin/StyledButtons-Cz8oYhmc.mjs +0 -418
- package/dist/admin/StyledButtons-DDuxnYz8.js +0 -419
- package/dist/admin/index-B_lFjUAg.mjs +0 -551
- package/dist/admin/sessionStatus-D_fWEzgj.js +0 -11
- package/dist/admin/sessionStatus-kwggjEMw.mjs +0 -12
|
@@ -0,0 +1,1261 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
|
+
import { useIntl } from "react-intl";
|
|
4
|
+
import { useFetchClient, useNotification, Page } from "@strapi/strapi/admin";
|
|
5
|
+
import styled from "styled-components";
|
|
6
|
+
import { g as getSessionStatus, R as ReadableText, a as getTranslation, p as pluginId, l as logSafeAdminError, b as parseUserAgent, D as DEFAULT_SESSION_FILTER, f as filterSessionsByStatus, c as pluginPermissions } from "./index-BFVITQ-o.mjs";
|
|
7
|
+
import { Modal, Flex, Box, Typography, Badge, Divider, Button, Alert, Loader, TextInput, SingleSelect, SingleSelectOption, Table, Thead, Tr, Th, Tbody, Td, EmptyStateLayout } from "@strapi/design-system";
|
|
8
|
+
import { Information, Cross, Phone, Monitor, Server, Download, Check, Clock, User, Search, Eye, Trash } from "@strapi/icons";
|
|
9
|
+
import { P as PluginPageLayout } from "./PluginPageLayout-BPFMcgrx.mjs";
|
|
10
|
+
import { F as FormField } from "./FormField-C8kIT2NE.mjs";
|
|
11
|
+
const theme = {
|
|
12
|
+
spacing: {
|
|
13
|
+
xs: "4px",
|
|
14
|
+
sm: "8px",
|
|
15
|
+
md: "16px",
|
|
16
|
+
lg: "24px",
|
|
17
|
+
xl: "32px"
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
function paginateSessions(sessions = [], currentPage = 1, pageSize = 25) {
|
|
21
|
+
const items = Array.isArray(sessions) ? sessions : [];
|
|
22
|
+
const requestedSize = Number(pageSize);
|
|
23
|
+
const normalizedSize = Number.isFinite(requestedSize) && requestedSize > 0 ? Math.floor(requestedSize) : 1;
|
|
24
|
+
const total = items.length;
|
|
25
|
+
const pageCount = Math.max(1, Math.ceil(total / normalizedSize));
|
|
26
|
+
const requestedPage = Number(currentPage);
|
|
27
|
+
const page = Math.min(
|
|
28
|
+
pageCount,
|
|
29
|
+
Math.max(1, Number.isFinite(requestedPage) ? Math.floor(requestedPage) : 1)
|
|
30
|
+
);
|
|
31
|
+
const offset = (page - 1) * normalizedSize;
|
|
32
|
+
return {
|
|
33
|
+
items: items.slice(offset, offset + normalizedSize),
|
|
34
|
+
page,
|
|
35
|
+
pageCount,
|
|
36
|
+
startIndex: total === 0 ? 0 : offset + 1,
|
|
37
|
+
endIndex: Math.min(total, offset + normalizedSize),
|
|
38
|
+
total
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const CSV_HEADERS = [
|
|
42
|
+
"ID",
|
|
43
|
+
"Status",
|
|
44
|
+
"User Email",
|
|
45
|
+
"Username",
|
|
46
|
+
"Device",
|
|
47
|
+
"Browser",
|
|
48
|
+
"OS",
|
|
49
|
+
"IP Address",
|
|
50
|
+
"Login Time",
|
|
51
|
+
"Last Active",
|
|
52
|
+
"Logout Time",
|
|
53
|
+
"Minutes Idle"
|
|
54
|
+
];
|
|
55
|
+
const escapeCsvValue = (value) => `"${String(value ?? "").replace(/"/g, '""')}"`;
|
|
56
|
+
function buildSessionCsv(sessions, { unavailableValue, getDeviceInfo, getSessionStatus: getSessionStatus2 }) {
|
|
57
|
+
const rows = Array.isArray(sessions) ? sessions : [];
|
|
58
|
+
const csvRows = rows.map((session) => {
|
|
59
|
+
const deviceInfo = getDeviceInfo(session, unavailableValue);
|
|
60
|
+
return [
|
|
61
|
+
session.id,
|
|
62
|
+
getSessionStatus2(session),
|
|
63
|
+
session.user?.email || "",
|
|
64
|
+
session.user?.username || "",
|
|
65
|
+
deviceInfo.device,
|
|
66
|
+
deviceInfo.browser,
|
|
67
|
+
deviceInfo.os,
|
|
68
|
+
session.ipAddress || unavailableValue,
|
|
69
|
+
new Date(session.loginTime).toISOString(),
|
|
70
|
+
new Date(session.lastActive || session.loginTime).toISOString(),
|
|
71
|
+
session.logoutTime ? new Date(session.logoutTime).toISOString() : "",
|
|
72
|
+
session.minutesSinceActive
|
|
73
|
+
];
|
|
74
|
+
});
|
|
75
|
+
return [
|
|
76
|
+
CSV_HEADERS.map(escapeCsvValue).join(","),
|
|
77
|
+
...csvRows.map((row) => row.map(escapeCsvValue).join(","))
|
|
78
|
+
].join("\n");
|
|
79
|
+
}
|
|
80
|
+
function buildSessionJson(sessions, {
|
|
81
|
+
filterStatus,
|
|
82
|
+
totalSessions,
|
|
83
|
+
exportedAt,
|
|
84
|
+
unavailableValue,
|
|
85
|
+
getDeviceInfo,
|
|
86
|
+
getSessionStatus: getSessionStatus2
|
|
87
|
+
}) {
|
|
88
|
+
const rows = Array.isArray(sessions) ? sessions : [];
|
|
89
|
+
const exportData = {
|
|
90
|
+
exportedAt,
|
|
91
|
+
filter: filterStatus,
|
|
92
|
+
totalSessions,
|
|
93
|
+
exportedSessions: rows.length,
|
|
94
|
+
sessions: rows.map((session) => {
|
|
95
|
+
const deviceInfo = getDeviceInfo(session, unavailableValue);
|
|
96
|
+
return {
|
|
97
|
+
id: session.id,
|
|
98
|
+
status: getSessionStatus2(session),
|
|
99
|
+
user: {
|
|
100
|
+
id: session.user?.documentId || session.user?.id,
|
|
101
|
+
email: session.user?.email,
|
|
102
|
+
username: session.user?.username
|
|
103
|
+
},
|
|
104
|
+
device: {
|
|
105
|
+
type: deviceInfo.device,
|
|
106
|
+
browser: deviceInfo.browser,
|
|
107
|
+
browserVersion: deviceInfo.browserVersion,
|
|
108
|
+
os: deviceInfo.os
|
|
109
|
+
},
|
|
110
|
+
ipAddress: session.ipAddress || unavailableValue,
|
|
111
|
+
loginTime: session.loginTime,
|
|
112
|
+
lastActive: session.lastActive,
|
|
113
|
+
logoutTime: session.logoutTime,
|
|
114
|
+
minutesSinceActive: session.minutesSinceActive,
|
|
115
|
+
isActive: session.isActive,
|
|
116
|
+
isTrulyActive: session.isTrulyActive
|
|
117
|
+
};
|
|
118
|
+
})
|
|
119
|
+
};
|
|
120
|
+
return JSON.stringify(exportData, null, 2);
|
|
121
|
+
}
|
|
122
|
+
const BROWSER_VERSION_PATTERNS = [
|
|
123
|
+
/\bEdg(?:A|iOS)?\/([\d.]+)/i,
|
|
124
|
+
/\bOPR\/([\d.]+)/i,
|
|
125
|
+
/\b(?:Chrome|CriOS)\/([\d.]+)/i,
|
|
126
|
+
/\bFirefox\/([\d.]+)/i,
|
|
127
|
+
/\bVersion\/([\d.]+).*Safari/i
|
|
128
|
+
];
|
|
129
|
+
function getBrowserVersionFromUserAgent(userAgent) {
|
|
130
|
+
if (typeof userAgent !== "string" || !userAgent.trim() || userAgent.trim().toLowerCase() === "unknown") {
|
|
131
|
+
return "";
|
|
132
|
+
}
|
|
133
|
+
for (const pattern of BROWSER_VERSION_PATTERNS) {
|
|
134
|
+
const match = userAgent.match(pattern);
|
|
135
|
+
if (match?.[1]) return match[1];
|
|
136
|
+
}
|
|
137
|
+
return "";
|
|
138
|
+
}
|
|
139
|
+
function formatSessionDateTime(value, locale, fallback) {
|
|
140
|
+
if (value === null || value === void 0 || value === "") return fallback;
|
|
141
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
142
|
+
if (!Number.isFinite(date.getTime())) return fallback;
|
|
143
|
+
const options = { dateStyle: "medium", timeStyle: "short" };
|
|
144
|
+
try {
|
|
145
|
+
return new Intl.DateTimeFormat(locale || "en", options).format(date);
|
|
146
|
+
} catch {
|
|
147
|
+
return new Intl.DateTimeFormat("en", options).format(date);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const TwoColumnGrid = styled.div`
|
|
151
|
+
display: grid;
|
|
152
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
153
|
+
gap: 24px;
|
|
154
|
+
min-width: 0;
|
|
155
|
+
|
|
156
|
+
& > * {
|
|
157
|
+
min-width: 0;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
@media (max-width: 767px) {
|
|
161
|
+
grid-template-columns: minmax(0, 1fr);
|
|
162
|
+
}
|
|
163
|
+
`;
|
|
164
|
+
const Section = styled(Box)`
|
|
165
|
+
min-width: 0;
|
|
166
|
+
margin-bottom: 24px;
|
|
167
|
+
`;
|
|
168
|
+
const DetailsList = styled.dl`
|
|
169
|
+
display: grid;
|
|
170
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
171
|
+
column-gap: 24px;
|
|
172
|
+
row-gap: 0;
|
|
173
|
+
width: 100%;
|
|
174
|
+
min-width: 0;
|
|
175
|
+
margin: 8px 0 0;
|
|
176
|
+
|
|
177
|
+
@media (max-width: 519px) {
|
|
178
|
+
grid-template-columns: minmax(0, 1fr);
|
|
179
|
+
}
|
|
180
|
+
`;
|
|
181
|
+
const DetailItem = styled.div`
|
|
182
|
+
display: flex;
|
|
183
|
+
flex-direction: column;
|
|
184
|
+
gap: 4px;
|
|
185
|
+
min-width: 0;
|
|
186
|
+
padding: 10px 0 12px;
|
|
187
|
+
border-bottom: 1px solid ${(props) => props.theme.colors.neutral150};
|
|
188
|
+
`;
|
|
189
|
+
const DetailLabel = styled(Typography)`
|
|
190
|
+
display: block;
|
|
191
|
+
width: 100%;
|
|
192
|
+
min-width: 0;
|
|
193
|
+
margin: 0;
|
|
194
|
+
font-size: 12px;
|
|
195
|
+
line-height: 1.5;
|
|
196
|
+
font-weight: 600;
|
|
197
|
+
text-wrap: pretty;
|
|
198
|
+
`;
|
|
199
|
+
const DetailValue = styled(Typography)`
|
|
200
|
+
display: block;
|
|
201
|
+
width: 100%;
|
|
202
|
+
min-width: 0;
|
|
203
|
+
margin: 0;
|
|
204
|
+
font-size: 14px;
|
|
205
|
+
line-height: 1.5;
|
|
206
|
+
overflow-wrap: anywhere;
|
|
207
|
+
word-break: break-word;
|
|
208
|
+
`;
|
|
209
|
+
const ModalActions = styled(Flex)`
|
|
210
|
+
width: 100%;
|
|
211
|
+
min-width: 0;
|
|
212
|
+
gap: 12px;
|
|
213
|
+
flex-wrap: wrap;
|
|
214
|
+
|
|
215
|
+
@media (max-width: 519px) {
|
|
216
|
+
flex-direction: column;
|
|
217
|
+
align-items: stretch;
|
|
218
|
+
|
|
219
|
+
& > button {
|
|
220
|
+
width: 100%;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
`;
|
|
224
|
+
const getStoredGeoData = (session) => {
|
|
225
|
+
let geoLocation = session?.geoLocation;
|
|
226
|
+
if (typeof geoLocation === "string") {
|
|
227
|
+
try {
|
|
228
|
+
geoLocation = JSON.parse(geoLocation);
|
|
229
|
+
} catch {
|
|
230
|
+
geoLocation = null;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (!geoLocation || typeof geoLocation !== "object") return null;
|
|
234
|
+
if (!geoLocation.country && !geoLocation.country_code && !geoLocation.city && !geoLocation.timezone) return null;
|
|
235
|
+
const hasSecurityScore = typeof session.securityScore === "number";
|
|
236
|
+
return {
|
|
237
|
+
country_flag: geoLocation.country_flag || "",
|
|
238
|
+
country: geoLocation.country || geoLocation.country_code || null,
|
|
239
|
+
city: geoLocation.city || null,
|
|
240
|
+
timezone: geoLocation.timezone || null,
|
|
241
|
+
securityScore: hasSecurityScore ? session.securityScore : null,
|
|
242
|
+
riskLevel: hasSecurityScore ? session.securityScore < 50 ? "High" : "Low" : null,
|
|
243
|
+
isVpn: typeof geoLocation.isVpn === "boolean" ? geoLocation.isVpn : null,
|
|
244
|
+
isProxy: typeof geoLocation.isProxy === "boolean" ? geoLocation.isProxy : null
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
const getSessionDeviceInfo$1 = (session, unavailableValue) => {
|
|
248
|
+
const normalize = (value) => typeof value === "string" && value.trim() && value.trim().toLowerCase() !== "unknown" ? value.trim() : "";
|
|
249
|
+
const userAgent = typeof session?.userAgent === "string" ? session.userAgent.trim() : "";
|
|
250
|
+
if (userAgent && userAgent.toLowerCase() !== "unknown") {
|
|
251
|
+
const parsed = parseUserAgent(userAgent);
|
|
252
|
+
const device = normalize(parsed.device);
|
|
253
|
+
return {
|
|
254
|
+
device: device || unavailableValue,
|
|
255
|
+
browser: normalize(parsed.browser) || unavailableValue,
|
|
256
|
+
browserVersion: getBrowserVersionFromUserAgent(userAgent) || normalize(session?.browserVersion),
|
|
257
|
+
os: normalize(parsed.os) || unavailableValue,
|
|
258
|
+
hasDeviceType: Boolean(device)
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
const deviceName = normalize(session?.deviceName);
|
|
262
|
+
const deviceType = normalize(session?.deviceType);
|
|
263
|
+
const browserName = normalize(session?.browserName);
|
|
264
|
+
const osName = normalize(session?.osName);
|
|
265
|
+
return {
|
|
266
|
+
device: deviceName || deviceType || unavailableValue,
|
|
267
|
+
browser: browserName || unavailableValue,
|
|
268
|
+
browserVersion: normalize(session?.browserVersion),
|
|
269
|
+
os: osName || unavailableValue,
|
|
270
|
+
hasDeviceType: Boolean(deviceType)
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
const SessionDetailModal = ({ session, onClose, onSessionTerminated }) => {
|
|
274
|
+
const { formatMessage, locale } = useIntl();
|
|
275
|
+
const { get, post } = useFetchClient();
|
|
276
|
+
const { toggleNotification } = useNotification();
|
|
277
|
+
const [terminating, setTerminating] = useState(false);
|
|
278
|
+
const [showUserAgent, setShowUserAgent] = useState(false);
|
|
279
|
+
const [geoData, setGeoData] = useState(null);
|
|
280
|
+
const [geoLoading, setGeoLoading] = useState(false);
|
|
281
|
+
const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
|
|
282
|
+
const unavailableValue = t("modal.user.na", "Unavailable");
|
|
283
|
+
useEffect(() => {
|
|
284
|
+
let cancelled = false;
|
|
285
|
+
const ipAddress = session?.ipAddress;
|
|
286
|
+
const storedGeoData = getStoredGeoData(session);
|
|
287
|
+
if (storedGeoData) {
|
|
288
|
+
setGeoData(storedGeoData);
|
|
289
|
+
setGeoLoading(false);
|
|
290
|
+
return () => {
|
|
291
|
+
cancelled = true;
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
if (!ipAddress) {
|
|
295
|
+
setGeoData(null);
|
|
296
|
+
setGeoLoading(false);
|
|
297
|
+
return () => {
|
|
298
|
+
cancelled = true;
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
const fetchGeolocationData = async () => {
|
|
302
|
+
setGeoData(null);
|
|
303
|
+
setGeoLoading(true);
|
|
304
|
+
try {
|
|
305
|
+
const { data } = await get(`/${pluginId}/geolocation/${encodeURIComponent(ipAddress)}`);
|
|
306
|
+
if (!cancelled) {
|
|
307
|
+
setGeoData(data.data);
|
|
308
|
+
}
|
|
309
|
+
} catch (err) {
|
|
310
|
+
logSafeAdminError("sessionDetails.geolocation", err);
|
|
311
|
+
if (!cancelled) {
|
|
312
|
+
setGeoData(null);
|
|
313
|
+
}
|
|
314
|
+
} finally {
|
|
315
|
+
if (!cancelled) {
|
|
316
|
+
setGeoLoading(false);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
fetchGeolocationData();
|
|
321
|
+
return () => {
|
|
322
|
+
cancelled = true;
|
|
323
|
+
};
|
|
324
|
+
}, [get, session]);
|
|
325
|
+
if (!session) return null;
|
|
326
|
+
const deviceInfo = getSessionDeviceInfo$1(session, unavailableValue);
|
|
327
|
+
const sessionStatus = getSessionStatus(session);
|
|
328
|
+
const statusVariant = {
|
|
329
|
+
active: "success",
|
|
330
|
+
idle: "warning",
|
|
331
|
+
loggedout: "neutral",
|
|
332
|
+
terminated: "neutral"
|
|
333
|
+
}[sessionStatus] || "neutral";
|
|
334
|
+
const statusLabel = {
|
|
335
|
+
active: t("modal.status.online", "Active"),
|
|
336
|
+
idle: t("modal.status.idle", "Idle"),
|
|
337
|
+
loggedout: t("modal.status.loggedOut", "Logged out"),
|
|
338
|
+
terminated: t("modal.status.terminated", "Terminated")
|
|
339
|
+
}[sessionStatus] || t("modal.status.terminated", "Terminated");
|
|
340
|
+
const securityData = geoData || {
|
|
341
|
+
country_flag: "",
|
|
342
|
+
country: unavailableValue,
|
|
343
|
+
city: unavailableValue,
|
|
344
|
+
timezone: unavailableValue,
|
|
345
|
+
securityScore: null,
|
|
346
|
+
riskLevel: null,
|
|
347
|
+
isVpn: null,
|
|
348
|
+
isProxy: null
|
|
349
|
+
};
|
|
350
|
+
const getDeviceIcon = (deviceType) => {
|
|
351
|
+
if (deviceType === "Mobile" || deviceType === "Tablet") return Phone;
|
|
352
|
+
if (deviceType === "Desktop" || deviceType === "Laptop") return Monitor;
|
|
353
|
+
return Server;
|
|
354
|
+
};
|
|
355
|
+
const DeviceIcon = deviceInfo.hasDeviceType ? getDeviceIcon(deviceInfo.device) : Information;
|
|
356
|
+
const handleTerminate = async () => {
|
|
357
|
+
if (!confirm(t("modal.confirm.terminate", "Are you sure you want to terminate this session?"))) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
setTerminating(true);
|
|
361
|
+
try {
|
|
362
|
+
await post(`/${pluginId}/sessions/${session.id}/terminate`);
|
|
363
|
+
toggleNotification({
|
|
364
|
+
type: "success",
|
|
365
|
+
message: t("notifications.success.terminated", "Session terminated successfully")
|
|
366
|
+
});
|
|
367
|
+
onSessionTerminated();
|
|
368
|
+
onClose();
|
|
369
|
+
} catch (err) {
|
|
370
|
+
logSafeAdminError("sessionDetails.terminate", err);
|
|
371
|
+
toggleNotification({
|
|
372
|
+
type: "danger",
|
|
373
|
+
message: t("notifications.error.terminate", "Failed to terminate session")
|
|
374
|
+
});
|
|
375
|
+
} finally {
|
|
376
|
+
setTerminating(false);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
const DetailField = ({ label, value }) => /* @__PURE__ */ jsxs(DetailItem, { children: [
|
|
380
|
+
/* @__PURE__ */ jsx(DetailLabel, { variant: "pi", textColor: "neutral600", tag: "dt", children: label }),
|
|
381
|
+
/* @__PURE__ */ jsx(DetailValue, { variant: "omega", textColor: "neutral800", tag: "dd", children: value })
|
|
382
|
+
] });
|
|
383
|
+
const browserValue = [deviceInfo.browser, deviceInfo.browserVersion].filter(Boolean).join(" ") || unavailableValue;
|
|
384
|
+
const idleMinutes = session.minutesSinceActive;
|
|
385
|
+
const idleTimeValue = idleMinutes !== null && idleMinutes !== void 0 && Number.isFinite(Number(idleMinutes)) ? t("modal.timeline.minutes", "{minutes} min", { minutes: Number(idleMinutes) }) : unavailableValue;
|
|
386
|
+
return /* @__PURE__ */ jsx(Modal.Root, { open: true, onOpenChange: onClose, children: /* @__PURE__ */ jsxs(
|
|
387
|
+
Modal.Content,
|
|
388
|
+
{
|
|
389
|
+
style: {
|
|
390
|
+
width: "min(900px, calc(100vw - 24px))",
|
|
391
|
+
maxHeight: "calc(100vh - 24px)",
|
|
392
|
+
display: "flex",
|
|
393
|
+
flexDirection: "column"
|
|
394
|
+
},
|
|
395
|
+
children: [
|
|
396
|
+
/* @__PURE__ */ jsx(Modal.Header, { children: /* @__PURE__ */ jsxs(Flex, { gap: 3, alignItems: "center", style: { minWidth: 0 }, children: [
|
|
397
|
+
/* @__PURE__ */ jsx(
|
|
398
|
+
Box,
|
|
399
|
+
{
|
|
400
|
+
padding: 2,
|
|
401
|
+
background: "neutral100",
|
|
402
|
+
hasRadius: true,
|
|
403
|
+
style: { display: "flex", alignItems: "center", justifyContent: "center" },
|
|
404
|
+
children: /* @__PURE__ */ jsx(DeviceIcon, { width: "24px", height: "24px" })
|
|
405
|
+
}
|
|
406
|
+
),
|
|
407
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", style: { minWidth: 0 }, children: [
|
|
408
|
+
/* @__PURE__ */ jsx(Typography, { variant: "beta", fontWeight: "bold", style: { overflowWrap: "anywhere" }, children: t("modal.title", "Session Details") }),
|
|
409
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", style: { overflowWrap: "anywhere" }, children: t("modal.id", "ID: {id}", { id: session.id }) })
|
|
410
|
+
] })
|
|
411
|
+
] }) }),
|
|
412
|
+
/* @__PURE__ */ jsx(Modal.Body, { style: { overflowY: "auto", minHeight: 0 }, children: /* @__PURE__ */ jsxs(Box, { padding: { initial: 3, small: 5 }, style: { minWidth: 0 }, children: [
|
|
413
|
+
/* @__PURE__ */ jsx(Flex, { justifyContent: "flex-start", style: { marginBottom: "24px" }, children: /* @__PURE__ */ jsx(Badge, { variant: statusVariant, size: "M", children: statusLabel }) }),
|
|
414
|
+
/* @__PURE__ */ jsx(Divider, { style: { marginBottom: "24px" } }),
|
|
415
|
+
/* @__PURE__ */ jsxs(TwoColumnGrid, { children: [
|
|
416
|
+
/* @__PURE__ */ jsxs(Box, { children: [
|
|
417
|
+
/* @__PURE__ */ jsxs(Section, { children: [
|
|
418
|
+
/* @__PURE__ */ jsx(Typography, { variant: "epsilon", fontWeight: "semiBold", textColor: "neutral800", tag: "h2", style: { marginBottom: "8px" }, children: t("modal.section.user", "User") }),
|
|
419
|
+
/* @__PURE__ */ jsxs(DetailsList, { children: [
|
|
420
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("modal.user.username", "Username"), value: session.user?.username || unavailableValue }),
|
|
421
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("modal.user.email", "Email"), value: session.user?.email || unavailableValue }),
|
|
422
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("modal.user.id", "User ID"), value: session.user?.documentId || session.user?.id || unavailableValue })
|
|
423
|
+
] })
|
|
424
|
+
] }),
|
|
425
|
+
/* @__PURE__ */ jsxs(Section, { children: [
|
|
426
|
+
/* @__PURE__ */ jsx(Typography, { variant: "epsilon", fontWeight: "semiBold", textColor: "neutral800", tag: "h2", style: { marginBottom: "8px" }, children: t("modal.section.device", "Device") }),
|
|
427
|
+
/* @__PURE__ */ jsxs(DetailsList, { children: [
|
|
428
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("modal.device.device", "Device"), value: deviceInfo.device }),
|
|
429
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("modal.device.browser", "Browser"), value: browserValue }),
|
|
430
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("modal.device.os", "OS"), value: deviceInfo.os }),
|
|
431
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("modal.device.ip", "IP"), value: session.ipAddress || unavailableValue })
|
|
432
|
+
] })
|
|
433
|
+
] })
|
|
434
|
+
] }),
|
|
435
|
+
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(Section, { children: [
|
|
436
|
+
/* @__PURE__ */ jsx(Typography, { variant: "epsilon", fontWeight: "semiBold", textColor: "neutral800", tag: "h2", style: { marginBottom: "8px" }, children: t("modal.section.timeline", "Timeline") }),
|
|
437
|
+
/* @__PURE__ */ jsxs(DetailsList, { children: [
|
|
438
|
+
/* @__PURE__ */ jsx(
|
|
439
|
+
DetailField,
|
|
440
|
+
{
|
|
441
|
+
label: t("modal.timeline.login", "Login"),
|
|
442
|
+
value: formatSessionDateTime(session.loginTime, locale, unavailableValue)
|
|
443
|
+
}
|
|
444
|
+
),
|
|
445
|
+
/* @__PURE__ */ jsx(
|
|
446
|
+
DetailField,
|
|
447
|
+
{
|
|
448
|
+
label: t("modal.timeline.lastActive", "Last Active"),
|
|
449
|
+
value: formatSessionDateTime(session.lastActive || session.loginTime, locale, unavailableValue)
|
|
450
|
+
}
|
|
451
|
+
),
|
|
452
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("modal.timeline.idleTime", "Idle Time"), value: idleTimeValue }),
|
|
453
|
+
session.logoutTime && /* @__PURE__ */ jsx(
|
|
454
|
+
DetailField,
|
|
455
|
+
{
|
|
456
|
+
label: t("modal.timeline.logout", "Logout"),
|
|
457
|
+
value: formatSessionDateTime(session.logoutTime, locale, unavailableValue)
|
|
458
|
+
}
|
|
459
|
+
)
|
|
460
|
+
] })
|
|
461
|
+
] }) })
|
|
462
|
+
] }),
|
|
463
|
+
/* @__PURE__ */ jsxs(Section, { children: [
|
|
464
|
+
/* @__PURE__ */ jsx(Typography, { variant: "epsilon", fontWeight: "semiBold", textColor: "neutral800", tag: "h2", style: { marginBottom: "8px" }, children: t("modal.section.security", "Location and Security") }),
|
|
465
|
+
geoLoading ? /* @__PURE__ */ jsx(Box, { padding: 4, style: { textAlign: "center" }, children: /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("modal.security.loading", "Loading location data...") }) }) : /* @__PURE__ */ jsxs(DetailsList, { children: [
|
|
466
|
+
/* @__PURE__ */ jsx(
|
|
467
|
+
DetailField,
|
|
468
|
+
{
|
|
469
|
+
label: t("modal.security.country", "Country"),
|
|
470
|
+
value: [securityData.country_flag, securityData.country].filter(Boolean).join(" ") || unavailableValue
|
|
471
|
+
}
|
|
472
|
+
),
|
|
473
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("modal.security.city", "City"), value: securityData.city || unavailableValue }),
|
|
474
|
+
/* @__PURE__ */ jsx(DetailField, { label: t("modal.security.timezone", "Timezone"), value: securityData.timezone || unavailableValue }),
|
|
475
|
+
/* @__PURE__ */ jsx(
|
|
476
|
+
DetailField,
|
|
477
|
+
{
|
|
478
|
+
label: t("modal.security.score", "Security"),
|
|
479
|
+
value: typeof securityData.securityScore === "number" ? `${securityData.securityScore}/100 (${securityData.riskLevel || unavailableValue})` : unavailableValue
|
|
480
|
+
}
|
|
481
|
+
),
|
|
482
|
+
/* @__PURE__ */ jsx(
|
|
483
|
+
DetailField,
|
|
484
|
+
{
|
|
485
|
+
label: t("modal.security.vpn", "VPN"),
|
|
486
|
+
value: typeof securityData.isVpn === "boolean" ? securityData.isVpn ? t("modal.security.vpnWarning", "Yes") : t("modal.security.no", "No") : unavailableValue
|
|
487
|
+
}
|
|
488
|
+
),
|
|
489
|
+
/* @__PURE__ */ jsx(
|
|
490
|
+
DetailField,
|
|
491
|
+
{
|
|
492
|
+
label: t("modal.security.proxy", "Proxy"),
|
|
493
|
+
value: typeof securityData.isProxy === "boolean" ? securityData.isProxy ? t("modal.security.vpnWarning", "Yes") : t("modal.security.no", "No") : unavailableValue
|
|
494
|
+
}
|
|
495
|
+
)
|
|
496
|
+
] })
|
|
497
|
+
] }),
|
|
498
|
+
/* @__PURE__ */ jsxs(Section, { children: [
|
|
499
|
+
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", style: { marginBottom: "12px", minWidth: 0, flexWrap: "wrap", gap: "8px" }, children: [
|
|
500
|
+
/* @__PURE__ */ jsx(Typography, { variant: "epsilon", fontWeight: "semiBold", textColor: "neutral800", tag: "h2", children: t("modal.section.technical", "Technical Details") }),
|
|
501
|
+
/* @__PURE__ */ jsx(
|
|
502
|
+
Button,
|
|
503
|
+
{
|
|
504
|
+
variant: "tertiary",
|
|
505
|
+
size: "S",
|
|
506
|
+
onClick: () => setShowUserAgent(!showUserAgent),
|
|
507
|
+
"aria-expanded": showUserAgent,
|
|
508
|
+
"aria-controls": "session-user-agent-details",
|
|
509
|
+
children: showUserAgent ? t("modal.technical.hide", "Hide Details") : t("modal.technical.show", "Show Details")
|
|
510
|
+
}
|
|
511
|
+
)
|
|
512
|
+
] }),
|
|
513
|
+
/* @__PURE__ */ jsx("div", { id: "session-user-agent-details", hidden: !showUserAgent, children: showUserAgent && /* @__PURE__ */ jsx(
|
|
514
|
+
Box,
|
|
515
|
+
{
|
|
516
|
+
padding: 3,
|
|
517
|
+
background: "neutral100",
|
|
518
|
+
hasRadius: true,
|
|
519
|
+
style: {
|
|
520
|
+
fontFamily: "monospace",
|
|
521
|
+
fontSize: "12px",
|
|
522
|
+
lineHeight: 1.5,
|
|
523
|
+
overflowWrap: "anywhere",
|
|
524
|
+
maxHeight: "min(16rem, 30vh)",
|
|
525
|
+
overflow: "auto",
|
|
526
|
+
marginTop: "8px"
|
|
527
|
+
},
|
|
528
|
+
children: /* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral600", tag: "p", children: typeof session.userAgent === "string" && session.userAgent.trim() && session.userAgent.trim().toLowerCase() !== "unknown" ? session.userAgent : unavailableValue })
|
|
529
|
+
}
|
|
530
|
+
) })
|
|
531
|
+
] })
|
|
532
|
+
] }) }),
|
|
533
|
+
/* @__PURE__ */ jsx(Modal.Footer, { children: /* @__PURE__ */ jsxs(ModalActions, { justifyContent: "space-between", children: [
|
|
534
|
+
/* @__PURE__ */ jsx(Button, { variant: "tertiary", onClick: onClose, children: t("modal.actions.close", "Close") }),
|
|
535
|
+
/* @__PURE__ */ jsx(
|
|
536
|
+
Button,
|
|
537
|
+
{
|
|
538
|
+
variant: "danger-light",
|
|
539
|
+
onClick: handleTerminate,
|
|
540
|
+
disabled: !session.isActive || terminating,
|
|
541
|
+
loading: terminating,
|
|
542
|
+
startIcon: /* @__PURE__ */ jsx(Cross, {}),
|
|
543
|
+
children: t("modal.actions.terminate", "Terminate Session")
|
|
544
|
+
}
|
|
545
|
+
)
|
|
546
|
+
] }) })
|
|
547
|
+
]
|
|
548
|
+
}
|
|
549
|
+
) });
|
|
550
|
+
};
|
|
551
|
+
const breakpoints = {
|
|
552
|
+
mobile: "768px"
|
|
553
|
+
};
|
|
554
|
+
const getSessionDeviceInfo = (session, unavailableValue) => {
|
|
555
|
+
const normalize = (value) => typeof value === "string" && value.trim() && value.trim().toLowerCase() !== "unknown" ? value.trim() : "";
|
|
556
|
+
const userAgent = typeof session?.userAgent === "string" ? session.userAgent.trim() : "";
|
|
557
|
+
if (userAgent && userAgent.toLowerCase() !== "unknown") {
|
|
558
|
+
const parsed = parseUserAgent(userAgent);
|
|
559
|
+
const device = normalize(parsed.device);
|
|
560
|
+
return {
|
|
561
|
+
device: device || unavailableValue,
|
|
562
|
+
browser: normalize(parsed.browser) || unavailableValue,
|
|
563
|
+
browserVersion: "",
|
|
564
|
+
os: normalize(parsed.os) || unavailableValue,
|
|
565
|
+
hasDeviceType: Boolean(device)
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
const deviceName = normalize(session?.deviceName);
|
|
569
|
+
const deviceType = normalize(session?.deviceType);
|
|
570
|
+
const browserName = normalize(session?.browserName);
|
|
571
|
+
const osName = normalize(session?.osName);
|
|
572
|
+
return {
|
|
573
|
+
device: deviceName || deviceType || unavailableValue,
|
|
574
|
+
browser: browserName || unavailableValue,
|
|
575
|
+
browserVersion: "",
|
|
576
|
+
os: osName || unavailableValue,
|
|
577
|
+
hasDeviceType: Boolean(deviceType)
|
|
578
|
+
};
|
|
579
|
+
};
|
|
580
|
+
const getStatusPresentation = (status, translate) => {
|
|
581
|
+
const labels = {
|
|
582
|
+
active: ["success", "homepage.status.active", "Active"],
|
|
583
|
+
idle: ["warning", "homepage.status.idle", "Idle"],
|
|
584
|
+
loggedout: ["neutral", "homepage.status.loggedOut", "Logged Out"],
|
|
585
|
+
terminated: ["neutral", "homepage.status.terminated", "Terminated"]
|
|
586
|
+
};
|
|
587
|
+
const [variant, id, fallback] = labels[status] || labels.terminated;
|
|
588
|
+
return { variant, label: translate(id, fallback) };
|
|
589
|
+
};
|
|
590
|
+
const StatsGrid = styled.div`
|
|
591
|
+
display: grid;
|
|
592
|
+
grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
|
|
593
|
+
gap: ${theme.spacing.md};
|
|
594
|
+
width: 100%;
|
|
595
|
+
min-width: 0;
|
|
596
|
+
margin-bottom: ${theme.spacing.lg};
|
|
597
|
+
`;
|
|
598
|
+
const StatCard = styled.div`
|
|
599
|
+
background: ${(p) => p.theme.colors.neutral0};
|
|
600
|
+
border: 1px solid ${(p) => p.theme.colors.neutral150};
|
|
601
|
+
border-top: 3px solid ${(p) => p.theme.colors.primary600};
|
|
602
|
+
border-radius: 4px;
|
|
603
|
+
min-width: 0;
|
|
604
|
+
padding: ${theme.spacing.md};
|
|
605
|
+
display: flex;
|
|
606
|
+
flex-direction: column;
|
|
607
|
+
align-items: flex-start;
|
|
608
|
+
gap: 4px;
|
|
609
|
+
min-height: 112px;
|
|
610
|
+
`;
|
|
611
|
+
const StatIcon = styled.div`
|
|
612
|
+
width: 36px;
|
|
613
|
+
height: 36px;
|
|
614
|
+
border-radius: 4px;
|
|
615
|
+
display: flex;
|
|
616
|
+
align-items: center;
|
|
617
|
+
justify-content: center;
|
|
618
|
+
background: ${(p) => p.theme.colors.primary100};
|
|
619
|
+
color: ${(p) => p.theme.colors.primary600};
|
|
620
|
+
margin-bottom: ${theme.spacing.sm};
|
|
621
|
+
|
|
622
|
+
svg {
|
|
623
|
+
width: 20px;
|
|
624
|
+
height: 20px;
|
|
625
|
+
}
|
|
626
|
+
`;
|
|
627
|
+
const DataTable = styled.div`
|
|
628
|
+
background: ${(p) => p.theme.colors.neutral0};
|
|
629
|
+
border-radius: 4px;
|
|
630
|
+
overflow: auto;
|
|
631
|
+
border: 1px solid ${(p) => p.theme.colors.neutral150};
|
|
632
|
+
min-width: 0;
|
|
633
|
+
max-width: 100%;
|
|
634
|
+
margin-bottom: ${theme.spacing.xl};
|
|
635
|
+
`;
|
|
636
|
+
const FilterBar = styled.div`
|
|
637
|
+
display: grid;
|
|
638
|
+
grid-template-columns: repeat(3, minmax(0, 1fr));
|
|
639
|
+
align-items: start;
|
|
640
|
+
background: ${(p) => p.theme.colors.neutral0};
|
|
641
|
+
padding: ${theme.spacing.md} ${theme.spacing.lg};
|
|
642
|
+
border-radius: 4px;
|
|
643
|
+
margin-bottom: ${theme.spacing.lg};
|
|
644
|
+
border: 1px solid ${(p) => p.theme.colors.neutral150};
|
|
645
|
+
gap: ${theme.spacing.md};
|
|
646
|
+
min-width: 0;
|
|
647
|
+
|
|
648
|
+
@media screen and (max-width: ${breakpoints.mobile}) {
|
|
649
|
+
grid-template-columns: minmax(0, 1fr);
|
|
650
|
+
padding: ${theme.spacing.md};
|
|
651
|
+
}
|
|
652
|
+
`;
|
|
653
|
+
const ActionButtons = styled.div`
|
|
654
|
+
display: flex;
|
|
655
|
+
gap: ${theme.spacing.xs};
|
|
656
|
+
justify-content: flex-end;
|
|
657
|
+
`;
|
|
658
|
+
const DesktopSessionTable = styled.div`
|
|
659
|
+
display: block;
|
|
660
|
+
min-width: 0;
|
|
661
|
+
|
|
662
|
+
@media screen and (max-width: ${breakpoints.mobile}) {
|
|
663
|
+
display: none;
|
|
664
|
+
}
|
|
665
|
+
`;
|
|
666
|
+
const MobileSessionCards = styled.div`
|
|
667
|
+
display: none;
|
|
668
|
+
min-width: 0;
|
|
669
|
+
|
|
670
|
+
@media screen and (max-width: ${breakpoints.mobile}) {
|
|
671
|
+
display: flex;
|
|
672
|
+
flex-direction: column;
|
|
673
|
+
gap: ${theme.spacing.md};
|
|
674
|
+
margin-bottom: ${theme.spacing.lg};
|
|
675
|
+
}
|
|
676
|
+
`;
|
|
677
|
+
const MobileSessionCard = styled.div`
|
|
678
|
+
background: ${(p) => p.theme.colors.neutral0};
|
|
679
|
+
min-width: 0;
|
|
680
|
+
border: 1px solid ${(p) => p.theme.colors.neutral150};
|
|
681
|
+
border-radius: 4px;
|
|
682
|
+
overflow-wrap: anywhere;
|
|
683
|
+
padding: ${theme.spacing.md};
|
|
684
|
+
`;
|
|
685
|
+
const HomePage = () => {
|
|
686
|
+
const { formatMessage } = useIntl();
|
|
687
|
+
const { get, post, del } = useFetchClient();
|
|
688
|
+
const { toggleNotification } = useNotification();
|
|
689
|
+
const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
|
|
690
|
+
const unavailableValue = t("homepage.user.unknown", "Unavailable");
|
|
691
|
+
const [sessions, setSessions] = useState([]);
|
|
692
|
+
const [loading, setLoading] = useState(true);
|
|
693
|
+
const [loadError, setLoadError] = useState(null);
|
|
694
|
+
const [filterStatus, setFilterStatus] = useState(DEFAULT_SESSION_FILTER);
|
|
695
|
+
const [entriesPerPage, setEntriesPerPage] = useState("25");
|
|
696
|
+
const [currentPage, setCurrentPage] = useState(1);
|
|
697
|
+
const [searchQuery, setSearchQuery] = useState("");
|
|
698
|
+
const [selectedSession, setSelectedSession] = useState(null);
|
|
699
|
+
const [showDetailModal, setShowDetailModal] = useState(false);
|
|
700
|
+
const [terminatingSessionId, setTerminatingSessionId] = useState(null);
|
|
701
|
+
const [deletingSessionId, setDeletingSessionId] = useState(null);
|
|
702
|
+
useEffect(() => {
|
|
703
|
+
fetchSessions();
|
|
704
|
+
const interval = setInterval(() => {
|
|
705
|
+
if (!showDetailModal) {
|
|
706
|
+
fetchSessions();
|
|
707
|
+
}
|
|
708
|
+
}, 10 * 60 * 1e3);
|
|
709
|
+
return () => clearInterval(interval);
|
|
710
|
+
}, [showDetailModal]);
|
|
711
|
+
const fetchSessions = async () => {
|
|
712
|
+
setLoading(true);
|
|
713
|
+
setLoadError(null);
|
|
714
|
+
try {
|
|
715
|
+
const { data } = await get(`/${pluginId}/sessions`);
|
|
716
|
+
setSessions(data.data || []);
|
|
717
|
+
} catch (err) {
|
|
718
|
+
setLoadError(t("homepage.error.load", "Session data could not be loaded. Try again."));
|
|
719
|
+
logSafeAdminError("dashboard.loadSessions", err);
|
|
720
|
+
} finally {
|
|
721
|
+
setLoading(false);
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
const handleTerminateSession = async (sessionId) => {
|
|
725
|
+
if (terminatingSessionId || deletingSessionId) return;
|
|
726
|
+
if (!confirm(t("homepage.confirm.terminate", "Are you sure you want to terminate this session?\n\nThis will set isActive to false (user will be logged out)."))) {
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
setTerminatingSessionId(sessionId);
|
|
730
|
+
try {
|
|
731
|
+
await post(`/${pluginId}/sessions/${sessionId}/terminate`);
|
|
732
|
+
await fetchSessions();
|
|
733
|
+
toggleNotification({
|
|
734
|
+
type: "success",
|
|
735
|
+
message: t("notifications.success.terminated", "Session terminated successfully")
|
|
736
|
+
});
|
|
737
|
+
} catch (err) {
|
|
738
|
+
logSafeAdminError("dashboard.terminateSession", err);
|
|
739
|
+
toggleNotification({
|
|
740
|
+
type: "danger",
|
|
741
|
+
message: t("notifications.error.terminate", "Failed to terminate session")
|
|
742
|
+
});
|
|
743
|
+
} finally {
|
|
744
|
+
setTerminatingSessionId(null);
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
const handleDeleteSession = async (sessionId) => {
|
|
748
|
+
if (terminatingSessionId || deletingSessionId) return;
|
|
749
|
+
if (!confirm(t(
|
|
750
|
+
"homepage.confirm.delete",
|
|
751
|
+
"Remove this session's details? Any unexpired access token remains blocked until it expires."
|
|
752
|
+
))) {
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
setDeletingSessionId(sessionId);
|
|
756
|
+
try {
|
|
757
|
+
await del(`/${pluginId}/sessions/${sessionId}`);
|
|
758
|
+
await fetchSessions();
|
|
759
|
+
toggleNotification({
|
|
760
|
+
type: "success",
|
|
761
|
+
message: t("notifications.success.deleted", "Session details removed. Token revocation remains until expiry.")
|
|
762
|
+
});
|
|
763
|
+
} catch (err) {
|
|
764
|
+
logSafeAdminError("dashboard.deleteSession", err);
|
|
765
|
+
toggleNotification({
|
|
766
|
+
type: "danger",
|
|
767
|
+
message: t("notifications.error.delete", "Failed to delete session")
|
|
768
|
+
});
|
|
769
|
+
} finally {
|
|
770
|
+
setDeletingSessionId(null);
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
const handleExportCSV = () => {
|
|
774
|
+
try {
|
|
775
|
+
const csvContent = buildSessionCsv(filteredSessions, {
|
|
776
|
+
unavailableValue,
|
|
777
|
+
getDeviceInfo: getSessionDeviceInfo,
|
|
778
|
+
getSessionStatus
|
|
779
|
+
});
|
|
780
|
+
const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
|
|
781
|
+
const link = document.createElement("a");
|
|
782
|
+
link.href = URL.createObjectURL(blob);
|
|
783
|
+
link.download = `sessions-export-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}.csv`;
|
|
784
|
+
link.click();
|
|
785
|
+
toggleNotification({
|
|
786
|
+
type: "success",
|
|
787
|
+
message: t("notifications.success.exported", "Exported {count} sessions to {format}", { count: filteredSessions.length, format: "CSV" })
|
|
788
|
+
});
|
|
789
|
+
} catch (err) {
|
|
790
|
+
logSafeAdminError("dashboard.exportCsv", err);
|
|
791
|
+
toggleNotification({
|
|
792
|
+
type: "danger",
|
|
793
|
+
message: t("notifications.error.export", "Failed to export sessions")
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
const handleExportJSON = () => {
|
|
798
|
+
try {
|
|
799
|
+
const jsonContent = buildSessionJson(filteredSessions, {
|
|
800
|
+
filterStatus,
|
|
801
|
+
totalSessions: sessions.length,
|
|
802
|
+
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
803
|
+
unavailableValue,
|
|
804
|
+
getDeviceInfo: getSessionDeviceInfo,
|
|
805
|
+
getSessionStatus
|
|
806
|
+
});
|
|
807
|
+
const blob = new Blob([jsonContent], { type: "application/json" });
|
|
808
|
+
const link = document.createElement("a");
|
|
809
|
+
link.href = URL.createObjectURL(blob);
|
|
810
|
+
link.download = `sessions-export-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}.json`;
|
|
811
|
+
link.click();
|
|
812
|
+
toggleNotification({
|
|
813
|
+
type: "success",
|
|
814
|
+
message: t("notifications.success.exported", "Exported {count} sessions to {format}", { count: filteredSessions.length, format: "JSON" })
|
|
815
|
+
});
|
|
816
|
+
} catch (err) {
|
|
817
|
+
logSafeAdminError("dashboard.exportJson", err);
|
|
818
|
+
toggleNotification({
|
|
819
|
+
type: "danger",
|
|
820
|
+
message: t("notifications.error.export", "Failed to export sessions")
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
const getDeviceIcon = (deviceType) => {
|
|
825
|
+
if (deviceType === "Mobile" || deviceType === "Tablet") return Phone;
|
|
826
|
+
if (deviceType === "Desktop" || deviceType === "Laptop") return Monitor;
|
|
827
|
+
return Server;
|
|
828
|
+
};
|
|
829
|
+
const activeSessions = sessions.filter((s) => s.isActive && s.isTrulyActive);
|
|
830
|
+
const idleSessions = sessions.filter((s) => getSessionStatus(s) === "idle");
|
|
831
|
+
const loggedOutSessions = sessions.filter((s) => getSessionStatus(s) === "loggedout");
|
|
832
|
+
const terminatedSessions = sessions.filter((s) => getSessionStatus(s) === "terminated");
|
|
833
|
+
const handleSessionClick = (session) => {
|
|
834
|
+
setSelectedSession(session);
|
|
835
|
+
setShowDetailModal(true);
|
|
836
|
+
};
|
|
837
|
+
const handleModalClose = () => {
|
|
838
|
+
setShowDetailModal(false);
|
|
839
|
+
setSelectedSession(null);
|
|
840
|
+
};
|
|
841
|
+
const handleSessionTerminated = () => {
|
|
842
|
+
fetchSessions();
|
|
843
|
+
};
|
|
844
|
+
const filteredSessions = filterSessionsByStatus(sessions, filterStatus).filter((session) => {
|
|
845
|
+
if (searchQuery) {
|
|
846
|
+
const query = searchQuery.toLowerCase();
|
|
847
|
+
const matchesUser = session.user?.email?.toLowerCase().includes(query) || session.user?.username?.toLowerCase().includes(query);
|
|
848
|
+
const matchesIp = session.ipAddress?.toLowerCase().includes(query);
|
|
849
|
+
const deviceInfo = getSessionDeviceInfo(session, unavailableValue);
|
|
850
|
+
const matchesDevice = deviceInfo.device?.toLowerCase().includes(query) || deviceInfo.browser?.toLowerCase().includes(query) || deviceInfo.os?.toLowerCase().includes(query);
|
|
851
|
+
return matchesUser || matchesIp || matchesDevice;
|
|
852
|
+
}
|
|
853
|
+
return true;
|
|
854
|
+
});
|
|
855
|
+
const pageResult = paginateSessions(filteredSessions, currentPage, entriesPerPage);
|
|
856
|
+
const exportActions = filteredSessions.length > 0 ? /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", children: [
|
|
857
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleExportCSV, startIcon: /* @__PURE__ */ jsx(Download, {}), variant: "secondary", children: t("homepage.export.csv", "Export CSV") }),
|
|
858
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleExportJSON, startIcon: /* @__PURE__ */ jsx(Download, {}), variant: "secondary", children: t("homepage.export.json", "Export JSON") })
|
|
859
|
+
] }) : null;
|
|
860
|
+
return /* @__PURE__ */ jsx(
|
|
861
|
+
PluginPageLayout,
|
|
862
|
+
{
|
|
863
|
+
headingId: "magic-sessionmanager-dashboard-title",
|
|
864
|
+
title: t("homepage.title", "Session Manager"),
|
|
865
|
+
subtitle: t("homepage.subtitle", "Monitor and manage end-user sessions"),
|
|
866
|
+
primaryAction: exportActions,
|
|
867
|
+
children: /* @__PURE__ */ jsxs(Box, { style: { width: "100%", minWidth: 0 }, children: [
|
|
868
|
+
!loading && loadError ? /* @__PURE__ */ jsx(
|
|
869
|
+
Alert,
|
|
870
|
+
{
|
|
871
|
+
variant: "danger",
|
|
872
|
+
title: t("homepage.error.title", "Unable to load sessions"),
|
|
873
|
+
closeLabel: t("common.close", "Close"),
|
|
874
|
+
action: /* @__PURE__ */ jsx(Button, { size: "S", variant: "secondary", onClick: fetchSessions, children: t("common.retry", "Retry") }),
|
|
875
|
+
children: /* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral700", tag: "span", children: loadError })
|
|
876
|
+
}
|
|
877
|
+
) : null,
|
|
878
|
+
/* @__PURE__ */ jsxs(StatsGrid, { children: [
|
|
879
|
+
/* @__PURE__ */ jsxs(StatCard, { children: [
|
|
880
|
+
/* @__PURE__ */ jsx(StatIcon, { "aria-hidden": "true", children: /* @__PURE__ */ jsx(Check, {}) }),
|
|
881
|
+
/* @__PURE__ */ jsx(Typography, { variant: "delta", fontWeight: "semiBold", tag: "p", style: { margin: 0 }, children: activeSessions.length }),
|
|
882
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", tag: "p", style: { margin: 0 }, children: t("homepage.stats.active", "Active") })
|
|
883
|
+
] }),
|
|
884
|
+
/* @__PURE__ */ jsxs(StatCard, { children: [
|
|
885
|
+
/* @__PURE__ */ jsx(StatIcon, { "aria-hidden": "true", children: /* @__PURE__ */ jsx(Clock, {}) }),
|
|
886
|
+
/* @__PURE__ */ jsx(Typography, { variant: "delta", fontWeight: "semiBold", tag: "p", style: { margin: 0 }, children: idleSessions.length }),
|
|
887
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", tag: "p", style: { margin: 0 }, children: t("homepage.stats.idle", "Idle") })
|
|
888
|
+
] }),
|
|
889
|
+
/* @__PURE__ */ jsxs(StatCard, { children: [
|
|
890
|
+
/* @__PURE__ */ jsx(StatIcon, { "aria-hidden": "true", children: /* @__PURE__ */ jsx(Cross, {}) }),
|
|
891
|
+
/* @__PURE__ */ jsx(Typography, { variant: "delta", fontWeight: "semiBold", tag: "p", style: { margin: 0 }, children: loggedOutSessions.length }),
|
|
892
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", tag: "p", style: { margin: 0 }, children: t("homepage.stats.loggedOut", "Logged Out") })
|
|
893
|
+
] }),
|
|
894
|
+
/* @__PURE__ */ jsxs(StatCard, { children: [
|
|
895
|
+
/* @__PURE__ */ jsx(StatIcon, { "aria-hidden": "true", children: /* @__PURE__ */ jsx(Cross, {}) }),
|
|
896
|
+
/* @__PURE__ */ jsx(Typography, { variant: "delta", fontWeight: "semiBold", tag: "p", style: { margin: 0 }, children: terminatedSessions.length }),
|
|
897
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", tag: "p", style: { margin: 0 }, children: t("homepage.stats.terminated", "Terminated") })
|
|
898
|
+
] }),
|
|
899
|
+
/* @__PURE__ */ jsxs(StatCard, { children: [
|
|
900
|
+
/* @__PURE__ */ jsx(StatIcon, { "aria-hidden": "true", children: /* @__PURE__ */ jsx(User, {}) }),
|
|
901
|
+
/* @__PURE__ */ jsx(Typography, { variant: "delta", fontWeight: "semiBold", tag: "p", style: { margin: 0 }, children: sessions.length }),
|
|
902
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", tag: "p", style: { margin: 0 }, children: t("homepage.stats.total", "Total") })
|
|
903
|
+
] })
|
|
904
|
+
] }),
|
|
905
|
+
loading && /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 8, children: /* @__PURE__ */ jsx(Loader, { children: t("homepage.loading", "Loading sessions...") }) }),
|
|
906
|
+
!loading && sessions.length > 0 && /* @__PURE__ */ jsxs(Box, { children: [
|
|
907
|
+
/* @__PURE__ */ jsx(Box, { style: { marginBottom: theme.spacing.md }, children: /* @__PURE__ */ jsx(Typography, { variant: "delta", textColor: "neutral700", style: { marginBottom: theme.spacing.md }, children: t("homepage.allSessions", "All Sessions") }) }),
|
|
908
|
+
/* @__PURE__ */ jsxs(FilterBar, { children: [
|
|
909
|
+
/* @__PURE__ */ jsx(
|
|
910
|
+
FormField,
|
|
911
|
+
{
|
|
912
|
+
id: "session-search",
|
|
913
|
+
name: "sessionSearch",
|
|
914
|
+
label: t("homepage.search.label", "Search sessions"),
|
|
915
|
+
description: t("homepage.search.hint", "Search end-user sessions by username, email, IP address, or device."),
|
|
916
|
+
children: /* @__PURE__ */ jsx(
|
|
917
|
+
TextInput,
|
|
918
|
+
{
|
|
919
|
+
value: searchQuery,
|
|
920
|
+
onChange: (e) => {
|
|
921
|
+
setSearchQuery(e.target.value);
|
|
922
|
+
setCurrentPage(1);
|
|
923
|
+
},
|
|
924
|
+
placeholder: t("homepage.search.placeholder", "Search by user, IP address, or device..."),
|
|
925
|
+
startAction: /* @__PURE__ */ jsx(Search, {})
|
|
926
|
+
}
|
|
927
|
+
)
|
|
928
|
+
}
|
|
929
|
+
),
|
|
930
|
+
/* @__PURE__ */ jsx(
|
|
931
|
+
FormField,
|
|
932
|
+
{
|
|
933
|
+
id: "session-status-filter",
|
|
934
|
+
name: "sessionStatus",
|
|
935
|
+
label: t("homepage.filter.label", "Filter sessions by status"),
|
|
936
|
+
description: t("homepage.filter.hint", "Limit the list to sessions with this status."),
|
|
937
|
+
children: /* @__PURE__ */ jsxs(
|
|
938
|
+
SingleSelect,
|
|
939
|
+
{
|
|
940
|
+
value: filterStatus,
|
|
941
|
+
onChange: (value) => {
|
|
942
|
+
setFilterStatus(value);
|
|
943
|
+
setCurrentPage(1);
|
|
944
|
+
},
|
|
945
|
+
size: "S",
|
|
946
|
+
children: [
|
|
947
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "all", children: t("homepage.filter.all", "All Sessions") }),
|
|
948
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "active", children: t("homepage.filter.active", "Currently active") }),
|
|
949
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "idle", children: t("homepage.filter.idle", "Inactive") }),
|
|
950
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "loggedout", children: t("homepage.filter.loggedout", "Logged Out") }),
|
|
951
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "terminated", children: t("homepage.filter.terminated", "Terminated") })
|
|
952
|
+
]
|
|
953
|
+
}
|
|
954
|
+
)
|
|
955
|
+
}
|
|
956
|
+
),
|
|
957
|
+
/* @__PURE__ */ jsx(
|
|
958
|
+
FormField,
|
|
959
|
+
{
|
|
960
|
+
id: "sessions-per-page",
|
|
961
|
+
name: "sessionsPerPage",
|
|
962
|
+
label: t("homepage.entries.label", "Sessions per page"),
|
|
963
|
+
description: t("homepage.entries.hint", "Choose how many sessions appear on each page."),
|
|
964
|
+
children: /* @__PURE__ */ jsxs(
|
|
965
|
+
SingleSelect,
|
|
966
|
+
{
|
|
967
|
+
value: entriesPerPage,
|
|
968
|
+
onChange: (value) => {
|
|
969
|
+
setEntriesPerPage(value);
|
|
970
|
+
setCurrentPage(1);
|
|
971
|
+
},
|
|
972
|
+
size: "S",
|
|
973
|
+
children: [
|
|
974
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "10", children: t("homepage.entries.10", "10 entries") }),
|
|
975
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "25", children: t("homepage.entries.25", "25 entries") }),
|
|
976
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "50", children: t("homepage.entries.50", "50 entries") }),
|
|
977
|
+
/* @__PURE__ */ jsx(SingleSelectOption, { value: "100", children: t("homepage.entries.100", "100 entries") })
|
|
978
|
+
]
|
|
979
|
+
}
|
|
980
|
+
)
|
|
981
|
+
}
|
|
982
|
+
)
|
|
983
|
+
] }),
|
|
984
|
+
/* @__PURE__ */ jsx(Box, { style: { marginBottom: theme.spacing.md }, children: /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: searchQuery ? t(
|
|
985
|
+
"homepage.pagination.filteredRange",
|
|
986
|
+
'Showing {start}-{end} of {count} matching sessions (filtered by "{query}")',
|
|
987
|
+
{ start: pageResult.startIndex, end: pageResult.endIndex, count: pageResult.total, query: searchQuery }
|
|
988
|
+
) : t(
|
|
989
|
+
"homepage.pagination.range",
|
|
990
|
+
"Showing {start}-{end} of {count} sessions",
|
|
991
|
+
{ start: pageResult.startIndex, end: pageResult.endIndex, count: pageResult.total }
|
|
992
|
+
) }) }),
|
|
993
|
+
filteredSessions.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
994
|
+
/* @__PURE__ */ jsx(DesktopSessionTable, { children: /* @__PURE__ */ jsx(DataTable, { children: /* @__PURE__ */ jsxs(Table, { style: { minWidth: 1024 }, children: [
|
|
995
|
+
/* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
|
|
996
|
+
/* @__PURE__ */ jsx(Th, { children: t("homepage.table.status", "Status") }),
|
|
997
|
+
/* @__PURE__ */ jsx(Th, { children: t("homepage.table.user", "User") }),
|
|
998
|
+
/* @__PURE__ */ jsx(Th, { children: t("homepage.table.device", "Device") }),
|
|
999
|
+
/* @__PURE__ */ jsx(Th, { children: t("homepage.table.ipAddress", "IP Address") }),
|
|
1000
|
+
/* @__PURE__ */ jsx(Th, { children: t("homepage.table.loginTime", "Login Time") }),
|
|
1001
|
+
/* @__PURE__ */ jsx(Th, { children: t("homepage.table.lastActive", "Last Active") }),
|
|
1002
|
+
/* @__PURE__ */ jsx(Th, { children: t("homepage.table.actions", "Actions") })
|
|
1003
|
+
] }) }),
|
|
1004
|
+
/* @__PURE__ */ jsx(Tbody, { children: pageResult.items.map((session) => {
|
|
1005
|
+
const deviceInfo = getSessionDeviceInfo(session, unavailableValue);
|
|
1006
|
+
const DeviceIcon = getDeviceIcon(deviceInfo.device);
|
|
1007
|
+
const sessionStatus = getSessionStatus(session);
|
|
1008
|
+
const config = getStatusPresentation(sessionStatus, t);
|
|
1009
|
+
return /* @__PURE__ */ jsxs(
|
|
1010
|
+
Tr,
|
|
1011
|
+
{
|
|
1012
|
+
tabIndex: 0,
|
|
1013
|
+
style: { cursor: "pointer" },
|
|
1014
|
+
"aria-label": `${config.label}: ${session.user?.email || session.user?.username || t("homepage.user.unknown", "Unknown")}`,
|
|
1015
|
+
onClick: () => handleSessionClick(session),
|
|
1016
|
+
onKeyDown: (event) => {
|
|
1017
|
+
if (event.target !== event.currentTarget) return;
|
|
1018
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
1019
|
+
event.preventDefault();
|
|
1020
|
+
handleSessionClick(session);
|
|
1021
|
+
}
|
|
1022
|
+
},
|
|
1023
|
+
children: [
|
|
1024
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Badge, { variant: config.variant, size: "S", children: config.label }) }),
|
|
1025
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", children: [
|
|
1026
|
+
/* @__PURE__ */ jsx(Typography, { fontWeight: "semiBold", ellipsis: true, children: session.user?.username || session.user?.email || t("homepage.user.unknown", "Unknown") }),
|
|
1027
|
+
session.user?.email && session.user?.username && /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", ellipsis: true, children: session.user.email })
|
|
1028
|
+
] }) }),
|
|
1029
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsxs(Flex, { alignItems: "center", gap: 2, children: [
|
|
1030
|
+
deviceInfo.hasDeviceType && /* @__PURE__ */ jsx(DeviceIcon, { width: "18px", height: "18px" }),
|
|
1031
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", children: [
|
|
1032
|
+
/* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", children: deviceInfo.device }),
|
|
1033
|
+
/* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "neutral600", children: [
|
|
1034
|
+
deviceInfo.browser,
|
|
1035
|
+
" on ",
|
|
1036
|
+
deviceInfo.os
|
|
1037
|
+
] })
|
|
1038
|
+
] })
|
|
1039
|
+
] }) }),
|
|
1040
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { variant: "omega", style: { fontFamily: "monospace" }, children: session.ipAddress || unavailableValue }) }),
|
|
1041
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral700", children: new Date(session.loginTime).toLocaleString() }) }),
|
|
1042
|
+
/* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", children: [
|
|
1043
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral700", children: new Date(session.lastActive || session.loginTime).toLocaleString() }),
|
|
1044
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: sessionStatus === "active" ? "success600" : "neutral500", children: t("homepage.time.minAgo", "{minutes} min ago", { minutes: session.minutesSinceActive }) })
|
|
1045
|
+
] }) }),
|
|
1046
|
+
/* @__PURE__ */ jsx(Td, { onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsxs(ActionButtons, { className: "action-buttons", children: [
|
|
1047
|
+
/* @__PURE__ */ jsx(
|
|
1048
|
+
Button,
|
|
1049
|
+
{
|
|
1050
|
+
size: "S",
|
|
1051
|
+
variant: "tertiary",
|
|
1052
|
+
"aria-label": `${t("homepage.actions.viewDetails", "View Details")}: ${session.user?.email || session.user?.username || ""}`,
|
|
1053
|
+
onClick: (e) => {
|
|
1054
|
+
e.stopPropagation();
|
|
1055
|
+
handleSessionClick(session);
|
|
1056
|
+
},
|
|
1057
|
+
title: t("homepage.actions.viewDetails", "View Details"),
|
|
1058
|
+
children: /* @__PURE__ */ jsx(Eye, {})
|
|
1059
|
+
}
|
|
1060
|
+
),
|
|
1061
|
+
/* @__PURE__ */ jsx(
|
|
1062
|
+
Button,
|
|
1063
|
+
{
|
|
1064
|
+
size: "S",
|
|
1065
|
+
variant: "danger-light",
|
|
1066
|
+
"aria-label": `${t("homepage.actions.terminate", "Terminate (Logout)")}: ${session.user?.email || session.user?.username || ""}`,
|
|
1067
|
+
onClick: (e) => {
|
|
1068
|
+
e.stopPropagation();
|
|
1069
|
+
handleTerminateSession(session.id);
|
|
1070
|
+
},
|
|
1071
|
+
loading: terminatingSessionId === session.id,
|
|
1072
|
+
disabled: !session.isActive || Boolean(terminatingSessionId) || Boolean(deletingSessionId),
|
|
1073
|
+
title: session.isActive ? t("homepage.actions.terminate", "Terminate (Logout)") : t("homepage.actions.alreadyInactive", "Already inactive"),
|
|
1074
|
+
children: /* @__PURE__ */ jsx(Cross, {})
|
|
1075
|
+
}
|
|
1076
|
+
),
|
|
1077
|
+
/* @__PURE__ */ jsx(
|
|
1078
|
+
Button,
|
|
1079
|
+
{
|
|
1080
|
+
size: "S",
|
|
1081
|
+
variant: "danger-light",
|
|
1082
|
+
"aria-label": t("homepage.actions.deletePermanently", "Remove session details"),
|
|
1083
|
+
onClick: (e) => {
|
|
1084
|
+
e.stopPropagation();
|
|
1085
|
+
handleDeleteSession(session.id);
|
|
1086
|
+
},
|
|
1087
|
+
loading: deletingSessionId === session.id,
|
|
1088
|
+
disabled: Boolean(terminatingSessionId) || Boolean(deletingSessionId),
|
|
1089
|
+
title: t("homepage.actions.deletePermanently", "Remove Session Details"),
|
|
1090
|
+
children: /* @__PURE__ */ jsx(Trash, {})
|
|
1091
|
+
}
|
|
1092
|
+
)
|
|
1093
|
+
] }) })
|
|
1094
|
+
]
|
|
1095
|
+
},
|
|
1096
|
+
session.id
|
|
1097
|
+
);
|
|
1098
|
+
}) })
|
|
1099
|
+
] }) }) }),
|
|
1100
|
+
/* @__PURE__ */ jsx(MobileSessionCards, { "aria-label": t("homepage.mobileList.label", "Session results"), children: pageResult.items.map((session) => {
|
|
1101
|
+
const deviceInfo = getSessionDeviceInfo(session, unavailableValue);
|
|
1102
|
+
const DeviceIcon = getDeviceIcon(deviceInfo.device);
|
|
1103
|
+
const presentation = getStatusPresentation(getSessionStatus(session), t);
|
|
1104
|
+
const userLabel = session.user?.username || session.user?.email || t("homepage.user.unknown", "Unknown");
|
|
1105
|
+
return /* @__PURE__ */ jsxs(MobileSessionCard, { children: [
|
|
1106
|
+
/* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", gap: 2, wrap: "wrap", children: [
|
|
1107
|
+
/* @__PURE__ */ jsx(Badge, { variant: presentation.variant, size: "S", children: presentation.label }),
|
|
1108
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: new Date(session.lastActive || session.loginTime).toLocaleString() })
|
|
1109
|
+
] }),
|
|
1110
|
+
/* @__PURE__ */ jsx(Box, { marginTop: 3, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [
|
|
1111
|
+
/* @__PURE__ */ jsx(Typography, { variant: "epsilon", fontWeight: "semiBold", children: userLabel }),
|
|
1112
|
+
session.user?.email && session.user?.username ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: session.user.email }) : null
|
|
1113
|
+
] }) }),
|
|
1114
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, marginTop: 3, children: [
|
|
1115
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", children: [
|
|
1116
|
+
deviceInfo.hasDeviceType ? /* @__PURE__ */ jsx(DeviceIcon, { "aria-hidden": "true" }) : null,
|
|
1117
|
+
/* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "neutral700", children: [
|
|
1118
|
+
deviceInfo.device,
|
|
1119
|
+
" · ",
|
|
1120
|
+
deviceInfo.browser,
|
|
1121
|
+
" on ",
|
|
1122
|
+
deviceInfo.os
|
|
1123
|
+
] })
|
|
1124
|
+
] }),
|
|
1125
|
+
/* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "neutral600", children: [
|
|
1126
|
+
t("homepage.table.ipAddress", "IP Address"),
|
|
1127
|
+
": ",
|
|
1128
|
+
session.ipAddress || unavailableValue
|
|
1129
|
+
] }),
|
|
1130
|
+
/* @__PURE__ */ jsxs(Typography, { variant: "pi", textColor: "neutral600", children: [
|
|
1131
|
+
t("homepage.table.loginTime", "Login Time"),
|
|
1132
|
+
": ",
|
|
1133
|
+
new Date(session.loginTime).toLocaleString()
|
|
1134
|
+
] }),
|
|
1135
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("homepage.time.minAgo", "{minutes} min ago", {
|
|
1136
|
+
minutes: Number.isFinite(session.minutesSinceActive) ? session.minutesSinceActive : unavailableValue
|
|
1137
|
+
}) })
|
|
1138
|
+
] }),
|
|
1139
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", marginTop: 4, children: [
|
|
1140
|
+
/* @__PURE__ */ jsx(
|
|
1141
|
+
Button,
|
|
1142
|
+
{
|
|
1143
|
+
size: "S",
|
|
1144
|
+
variant: "tertiary",
|
|
1145
|
+
startIcon: /* @__PURE__ */ jsx(Eye, {}),
|
|
1146
|
+
onClick: () => handleSessionClick(session),
|
|
1147
|
+
"aria-label": `${t("homepage.actions.viewDetails", "View Details")}: ${userLabel}`,
|
|
1148
|
+
children: t("homepage.actions.viewDetails", "View Details")
|
|
1149
|
+
}
|
|
1150
|
+
),
|
|
1151
|
+
/* @__PURE__ */ jsx(
|
|
1152
|
+
Button,
|
|
1153
|
+
{
|
|
1154
|
+
size: "S",
|
|
1155
|
+
variant: "danger-light",
|
|
1156
|
+
startIcon: /* @__PURE__ */ jsx(Cross, {}),
|
|
1157
|
+
onClick: () => handleTerminateSession(session.id),
|
|
1158
|
+
loading: terminatingSessionId === session.id,
|
|
1159
|
+
disabled: !session.isActive || Boolean(terminatingSessionId) || Boolean(deletingSessionId),
|
|
1160
|
+
children: t("homepage.actions.terminate", "Terminate")
|
|
1161
|
+
}
|
|
1162
|
+
),
|
|
1163
|
+
/* @__PURE__ */ jsx(
|
|
1164
|
+
Button,
|
|
1165
|
+
{
|
|
1166
|
+
size: "S",
|
|
1167
|
+
variant: "tertiary",
|
|
1168
|
+
startIcon: /* @__PURE__ */ jsx(Trash, {}),
|
|
1169
|
+
onClick: () => handleDeleteSession(session.id),
|
|
1170
|
+
loading: deletingSessionId === session.id,
|
|
1171
|
+
disabled: Boolean(terminatingSessionId) || Boolean(deletingSessionId),
|
|
1172
|
+
children: t("homepage.actions.deletePermanently", "Remove Session Details")
|
|
1173
|
+
}
|
|
1174
|
+
)
|
|
1175
|
+
] })
|
|
1176
|
+
] }, session.id);
|
|
1177
|
+
}) }),
|
|
1178
|
+
pageResult.pageCount > 1 && /* @__PURE__ */ jsx("nav", { "aria-label": t("homepage.pagination.label", "Session pages"), children: /* @__PURE__ */ jsxs(
|
|
1179
|
+
Flex,
|
|
1180
|
+
{
|
|
1181
|
+
justifyContent: "space-between",
|
|
1182
|
+
alignItems: "center",
|
|
1183
|
+
gap: 3,
|
|
1184
|
+
wrap: "wrap",
|
|
1185
|
+
style: { marginTop: theme.spacing.md },
|
|
1186
|
+
children: [
|
|
1187
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", "aria-live": "polite", children: t("homepage.pagination.page", "Page {page} of {pages}", {
|
|
1188
|
+
page: pageResult.page,
|
|
1189
|
+
pages: pageResult.pageCount
|
|
1190
|
+
}) }),
|
|
1191
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
|
1192
|
+
/* @__PURE__ */ jsx(
|
|
1193
|
+
Button,
|
|
1194
|
+
{
|
|
1195
|
+
variant: "tertiary",
|
|
1196
|
+
size: "S",
|
|
1197
|
+
disabled: pageResult.page <= 1,
|
|
1198
|
+
onClick: () => setCurrentPage(pageResult.page - 1),
|
|
1199
|
+
children: t("homepage.pagination.previous", "Previous")
|
|
1200
|
+
}
|
|
1201
|
+
),
|
|
1202
|
+
/* @__PURE__ */ jsx(
|
|
1203
|
+
Button,
|
|
1204
|
+
{
|
|
1205
|
+
variant: "tertiary",
|
|
1206
|
+
size: "S",
|
|
1207
|
+
disabled: pageResult.page >= pageResult.pageCount,
|
|
1208
|
+
onClick: () => setCurrentPage(pageResult.page + 1),
|
|
1209
|
+
children: t("homepage.pagination.next", "Next")
|
|
1210
|
+
}
|
|
1211
|
+
)
|
|
1212
|
+
] })
|
|
1213
|
+
]
|
|
1214
|
+
}
|
|
1215
|
+
) })
|
|
1216
|
+
] }) : /* @__PURE__ */ jsx(
|
|
1217
|
+
EmptyStateLayout,
|
|
1218
|
+
{
|
|
1219
|
+
icon: /* @__PURE__ */ jsx(Search, { "aria-hidden": "true" }),
|
|
1220
|
+
content: /* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral700", tag: "span", children: t("homepage.noResults.description", "Try adjusting your search or status filter.") }),
|
|
1221
|
+
action: /* @__PURE__ */ jsx(
|
|
1222
|
+
Button,
|
|
1223
|
+
{
|
|
1224
|
+
variant: "secondary",
|
|
1225
|
+
onClick: () => {
|
|
1226
|
+
setSearchQuery("");
|
|
1227
|
+
setFilterStatus(DEFAULT_SESSION_FILTER);
|
|
1228
|
+
setCurrentPage(1);
|
|
1229
|
+
},
|
|
1230
|
+
children: t("homepage.noResults.reset", "Clear filters")
|
|
1231
|
+
}
|
|
1232
|
+
)
|
|
1233
|
+
}
|
|
1234
|
+
)
|
|
1235
|
+
] }),
|
|
1236
|
+
!loading && sessions.length === 0 && !loadError && /* @__PURE__ */ jsx(
|
|
1237
|
+
EmptyStateLayout,
|
|
1238
|
+
{
|
|
1239
|
+
icon: /* @__PURE__ */ jsx(Monitor, { "aria-hidden": "true" }),
|
|
1240
|
+
content: /* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral700", tag: "span", children: t("homepage.empty.description", "Sessions will appear here when end users log in.") })
|
|
1241
|
+
}
|
|
1242
|
+
),
|
|
1243
|
+
showDetailModal && selectedSession && /* @__PURE__ */ jsx(
|
|
1244
|
+
SessionDetailModal,
|
|
1245
|
+
{
|
|
1246
|
+
session: selectedSession,
|
|
1247
|
+
onClose: handleModalClose,
|
|
1248
|
+
onSessionTerminated: handleSessionTerminated
|
|
1249
|
+
}
|
|
1250
|
+
)
|
|
1251
|
+
] })
|
|
1252
|
+
}
|
|
1253
|
+
);
|
|
1254
|
+
};
|
|
1255
|
+
const LicenseGuard = ({ children }) => /* @__PURE__ */ jsx(Fragment, { children });
|
|
1256
|
+
const App = () => {
|
|
1257
|
+
return /* @__PURE__ */ jsx(Page.Protect, { permissions: pluginPermissions.access, children: /* @__PURE__ */ jsx(LicenseGuard, { children: /* @__PURE__ */ jsx(HomePage, {}) }) });
|
|
1258
|
+
};
|
|
1259
|
+
export {
|
|
1260
|
+
App as default
|
|
1261
|
+
};
|