strapi-plugin-magic-sessionmanager 4.10.0 → 4.12.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.
Files changed (31) hide show
  1. package/CHANGELOG.md +92 -6
  2. package/README.md +263 -72
  3. package/dist/admin/{Analytics-PRqsLMEx.mjs → Analytics-C_c24Uzq.mjs} +45 -75
  4. package/dist/admin/{Analytics-CdmRsigN.js → Analytics-lP0-RsVd.js} +45 -75
  5. package/dist/admin/{App-BSeYF7KA.mjs → App-DCyNPn1k.mjs} +162 -119
  6. package/dist/admin/{App-DUMCbuCr.js → App-miWDdmdX.js} +162 -119
  7. package/dist/admin/{OnlineUsersWidget-CDZ19_PT.js → OnlineUsersWidget-C6b7e4jb.js} +18 -26
  8. package/dist/admin/{OnlineUsersWidget-B5pXzqM9.mjs → OnlineUsersWidget-C6wlwENC.mjs} +18 -26
  9. package/dist/admin/{Settings-CrLzRXrA.js → Settings-D9zyn5xn.js} +9 -3
  10. package/dist/admin/{Settings-B-GRuWjT.mjs → Settings-DssYw2W4.mjs} +8 -2
  11. package/dist/admin/{de-DwUCBY1b.mjs → de--yNl7MPl.mjs} +4 -48
  12. package/dist/admin/{de-Dzo1tVoJ.js → de-DjPEATFf.js} +4 -48
  13. package/dist/admin/{en-Dd0wXfgR.mjs → en-5U7g51cH.mjs} +4 -48
  14. package/dist/admin/{en-CL5llI55.js → en-BoO12UQw.js} +4 -48
  15. package/dist/admin/{es-Cl5IwDA4.mjs → es-BJR-zCXL.mjs} +4 -48
  16. package/dist/admin/{es-CiNDwv_f.js → es-BLpEuycJ.js} +4 -48
  17. package/dist/admin/{fr-DBOQ-UDm.js → fr-BE828R9Q.js} +4 -48
  18. package/dist/admin/{fr-DhADj8Zs.mjs → fr-CeeCYQCs.mjs} +4 -48
  19. package/dist/admin/{index-CaLVyCio.js → index-CfQOMZVX.js} +9 -56
  20. package/dist/admin/{index-CHACmZsg.mjs → index-rbxJZcLv.mjs} +35 -82
  21. package/dist/admin/index.js +1 -1
  22. package/dist/admin/index.mjs +2 -2
  23. package/dist/admin/{pt-m73K1nJ0.js → pt-BWEFiuvo.js} +4 -48
  24. package/dist/admin/{pt-CT6VpDMM.mjs → pt-CorrU3yG.mjs} +4 -48
  25. package/dist/server/index.js +815 -628
  26. package/dist/server/index.mjs +815 -628
  27. package/package.json +29 -13
  28. package/dist/admin/License-BeD7Du6r.js +0 -443
  29. package/dist/admin/License-D5W_l35e.mjs +0 -443
  30. package/dist/admin/maskSensitiveValue-BWcSjow7.js +0 -9
  31. package/dist/admin/maskSensitiveValue-lLRhN_S7.mjs +0 -10
@@ -9,7 +9,7 @@ const designSystem = require("@strapi/design-system");
9
9
  const icons = require("@strapi/icons");
10
10
  const symbols = require("@strapi/icons/symbols");
11
11
  const styled = require("styled-components");
12
- const index = require("./index-CaLVyCio.js");
12
+ const index = require("./index-CfQOMZVX.js");
13
13
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
14
14
  const styled__default = /* @__PURE__ */ _interopDefault(styled);
15
15
  const EndReason = ({ session, reason, variant = "omega", textColor = "neutral800" }) => {
@@ -23,27 +23,71 @@ const EndReason = ({ session, reason, variant = "omega", textColor = "neutral800
23
23
  });
24
24
  return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant, textColor, "data-end-reason": presentation.reason, children: translate(presentation) });
25
25
  };
26
- function paginateSessions(sessions = [], currentPage = 1, pageSize = 25) {
27
- const items = Array.isArray(sessions) ? sessions : [];
28
- const requestedSize = Number(pageSize);
29
- const normalizedSize = Number.isFinite(requestedSize) && requestedSize > 0 ? Math.floor(requestedSize) : 1;
30
- const total = items.length;
31
- const pageCount = Math.max(1, Math.ceil(total / normalizedSize));
32
- const requestedPage = Number(currentPage);
33
- const page = Math.min(
34
- pageCount,
35
- Math.max(1, Number.isFinite(requestedPage) ? Math.floor(requestedPage) : 1)
26
+ const MAX_EXPORT_ROWS = 5e4;
27
+ const EXPORT_BATCH_SIZE = 1e3;
28
+ const EMPTY_SESSION_STATS = Object.freeze({
29
+ total: 0,
30
+ open: 0,
31
+ active: 0,
32
+ idle: 0,
33
+ ended: 0,
34
+ loggedOut: 0,
35
+ timedOut: 0,
36
+ otherReasons: 0,
37
+ usersOnline: 0,
38
+ nativeOnly: 0
39
+ });
40
+ function filterParams(query) {
41
+ const params = {};
42
+ if (query.status && query.status !== "all") params.status = query.status;
43
+ if (query.status === "ended" && query.reason && query.reason !== "all") {
44
+ params.reason = query.reason;
45
+ }
46
+ const search = typeof query.search === "string" ? query.search.trim().slice(0, 100) : "";
47
+ if (search) params.search = search;
48
+ return params;
49
+ }
50
+ function buildListParams(query) {
51
+ return {
52
+ page: String(Math.max(1, Number(query.page) || 1)),
53
+ pageSize: String(query.pageSize),
54
+ ...filterParams(query)
55
+ };
56
+ }
57
+ function buildExportParams(query, cursor) {
58
+ return {
59
+ limit: String(EXPORT_BATCH_SIZE),
60
+ ...filterParams(query),
61
+ ...cursor ? { cursor } : {}
62
+ };
63
+ }
64
+ const isCount = (value) => Number.isInteger(value) && value >= 0;
65
+ function readSessionPage(payload) {
66
+ const body = (
67
+ /** @type {any} */
68
+ payload
36
69
  );
37
- const offset = (page - 1) * normalizedSize;
70
+ const pagination = body?.meta?.pagination;
71
+ if (!Array.isArray(body?.data) || !isCount(pagination?.total) || !isCount(pagination?.pageCount)) {
72
+ throw new Error("Invalid session page response");
73
+ }
38
74
  return {
39
- items: items.slice(offset, offset + normalizedSize),
40
- page,
41
- pageCount,
42
- startIndex: total === 0 ? 0 : offset + 1,
43
- endIndex: Math.min(total, offset + normalizedSize),
44
- total
75
+ rows: body.data,
76
+ pagination: { total: pagination.total, pageCount: Math.max(1, pagination.pageCount) }
45
77
  };
46
78
  }
79
+ function readSessionStats(payload) {
80
+ const data = (
81
+ /** @type {any} */
82
+ payload?.data
83
+ );
84
+ const stats = { ...EMPTY_SESSION_STATS };
85
+ for (const key of Object.keys(EMPTY_SESSION_STATS)) {
86
+ if (!isCount(data?.[key])) throw new Error("Invalid session statistics response");
87
+ stats[key] = data[key];
88
+ }
89
+ return stats;
90
+ }
47
91
  const CSV_HEADERS = Object.freeze([
48
92
  "ID",
49
93
  "Status",
@@ -59,7 +103,12 @@ const CSV_HEADERS = Object.freeze([
59
103
  "Minutes Idle",
60
104
  "End Reason"
61
105
  ]);
62
- const escapeCsvValue = (value) => `"${String(value ?? "").replace(/"/g, '""')}"`;
106
+ const FORMULA_START = /^[=+\-@\t\r]/;
107
+ const escapeCsvValue = (value) => {
108
+ const text = String(value ?? "");
109
+ const safe = typeof value === "string" && FORMULA_START.test(text) ? `'${text}` : text;
110
+ return `"${safe.replace(/"/g, '""')}"`;
111
+ };
63
112
  function toIsoTimestamp(value) {
64
113
  if (value === null || value === void 0 || value === "") return "";
65
114
  const date = value instanceof Date ? value : new Date(
@@ -330,39 +379,6 @@ function hasActiveFilters(state) {
330
379
  if (!state) return false;
331
380
  return state.status !== index.DEFAULT_SESSION_FILTER || Boolean(state.reason) && state.reason !== index.DEFAULT_END_REASON_FILTER || Boolean(state.search);
332
381
  }
333
- const getUserKey = (session) => {
334
- const user = session?.user;
335
- return index.presentText(user?.documentId) || index.presentText(user?.id) || index.presentText(user?.email);
336
- };
337
- function getSessionStats(sessions) {
338
- const rows = Array.isArray(sessions) ? sessions : [];
339
- const stats = {
340
- active: 0,
341
- idle: 0,
342
- ended: 0,
343
- total: rows.length,
344
- usersOnline: 0,
345
- loggedOut: 0,
346
- timedOut: 0,
347
- otherReasons: 0
348
- };
349
- const onlineUsers = /* @__PURE__ */ new Set();
350
- for (const session of rows) {
351
- const state = index.getSessionState(session);
352
- stats[state] += 1;
353
- if (state === "active") {
354
- const key = getUserKey(session);
355
- if (key) onlineUsers.add(key);
356
- } else if (state === "ended") {
357
- const reason = index.getSessionEndReason(session);
358
- if (reason === "logout") stats.loggedOut += 1;
359
- else if (reason === "idle") stats.timedOut += 1;
360
- else stats.otherReasons += 1;
361
- }
362
- }
363
- stats.usersOnline = onlineUsers.size;
364
- return stats;
365
- }
366
382
  function getSessionUserLabels(session) {
367
383
  const username = index.presentText(session?.user?.username);
368
384
  const email = index.presentText(session?.user?.email);
@@ -1298,7 +1314,6 @@ const HowSessionsWork = () => {
1298
1314
  )
1299
1315
  ] });
1300
1316
  };
1301
- const LOADED_SESSIONS_LIMIT = 1e3;
1302
1317
  const CLOCK_TICK_MS = 30 * 1e3;
1303
1318
  const ANALYTICS_PATH = `/settings/${index.pluginId}/analytics`;
1304
1319
  const CONFIGURATION_PATH = `/settings/${index.pluginId}/general`;
@@ -1336,7 +1351,9 @@ const HomePage = () => {
1336
1351
  const t = (id, defaultMessage, values) => formatMessage({ id: index.getTranslation(id), defaultMessage }, values);
1337
1352
  const dashboard = parseDashboardQuery(query);
1338
1353
  const [sessions, setSessions] = react.useState([]);
1339
- const [truncated, setTruncated] = react.useState(false);
1354
+ const [pagination, setPagination] = react.useState({ total: 0, pageCount: 1 });
1355
+ const [stats, setStats] = react.useState(EMPTY_SESSION_STATS);
1356
+ const [exporting, setExporting] = react.useState(false);
1340
1357
  const [loading, setLoading] = react.useState(true);
1341
1358
  const [refreshing, setRefreshing] = react.useState(false);
1342
1359
  const [loadError, setLoadError] = react.useState(false);
@@ -1356,6 +1373,16 @@ const HomePage = () => {
1356
1373
  const mutationSnapshotRef = react.useRef([]);
1357
1374
  const listHeadingId = `session-list-caption-${react.useId().replace(/:/g, "")}`;
1358
1375
  const mutationPending = Boolean(terminatingSessionId || deletingSessionId);
1376
+ const listQuery = react.useMemo(
1377
+ () => ({
1378
+ page: dashboard.page,
1379
+ pageSize: dashboard.pageSize,
1380
+ status: dashboard.status,
1381
+ reason: dashboard.reason,
1382
+ search: dashboard.search
1383
+ }),
1384
+ [dashboard.page, dashboard.pageSize, dashboard.status, dashboard.reason, dashboard.search]
1385
+ );
1359
1386
  react.useEffect(() => {
1360
1387
  const timer = setInterval(() => setNow(Date.now()), CLOCK_TICK_MS);
1361
1388
  return () => clearInterval(timer);
@@ -1366,11 +1393,16 @@ const HomePage = () => {
1366
1393
  if (hasLoadedRef.current) setRefreshing(true);
1367
1394
  else setLoading(true);
1368
1395
  try {
1369
- const { data } = await get(`/${index.pluginId}/sessions`);
1370
- const list = index.requireSessionList(data);
1396
+ const [listResponse, statsResponse] = await Promise.all([
1397
+ get(`/${index.pluginId}/sessions`, { params: buildListParams(listQuery) }),
1398
+ get(`/${index.pluginId}/sessions/stats`)
1399
+ ]);
1400
+ const page = readSessionPage(listResponse.data);
1401
+ const nextStats = readSessionStats(statsResponse.data);
1371
1402
  if (requestId !== requestIdRef.current) return;
1372
- setSessions(list);
1373
- setTruncated(data?.meta?.truncated === true);
1403
+ setSessions(page.rows);
1404
+ setPagination(page.pagination);
1405
+ setStats(nextStats);
1374
1406
  setLoadError(false);
1375
1407
  setHasData(true);
1376
1408
  setLastUpdated(Date.now());
@@ -1386,7 +1418,7 @@ const HomePage = () => {
1386
1418
  setRefreshing(false);
1387
1419
  }
1388
1420
  }
1389
- }, [get]);
1421
+ }, [get, listQuery]);
1390
1422
  react.useEffect(() => {
1391
1423
  fetchSessions();
1392
1424
  }, [fetchSessions]);
@@ -1474,53 +1506,74 @@ const HomePage = () => {
1474
1506
  setDeletingSessionId(null);
1475
1507
  }
1476
1508
  };
1477
- const filteredSessions = react.useMemo(
1478
- () => index.filterSessionsBySearch(
1479
- index.filterSessionsByStatus(sessions, dashboard.status, dashboard.reason),
1480
- dashboard.search,
1481
- formatters.deviceTypeLabel
1482
- ),
1483
- [sessions, dashboard.status, dashboard.reason, dashboard.search, formatters]
1484
- );
1485
- const pageResult = paginateSessions(filteredSessions, dashboard.page, dashboard.pageSize);
1509
+ const pageSize = Number(dashboard.pageSize);
1510
+ const pageResult = {
1511
+ items: sessions,
1512
+ total: pagination.total,
1513
+ pageCount: pagination.pageCount,
1514
+ startIndex: pagination.total > 0 ? (dashboard.page - 1) * pageSize + 1 : 0,
1515
+ endIndex: pagination.total > 0 ? (dashboard.page - 1) * pageSize + sessions.length : 0
1516
+ };
1486
1517
  const visibleIds = pageResult.items.map((session) => String(session.id));
1487
1518
  react.useLayoutEffect(() => {
1488
1519
  visibleIdsRef.current = visibleIds;
1489
1520
  });
1490
- const handleExportCSV = () => {
1491
- try {
1492
- const csvContent = buildSessionCsv(filteredSessions, {
1493
- unavailableValue: "",
1494
- getDeviceInfo: getExportDeviceInfo,
1495
- getSessionStatus: index.getSessionStatus
1521
+ const fetchExportRows = async () => {
1522
+ const rows = [];
1523
+ let cursor = null;
1524
+ do {
1525
+ const { data } = await get(`/${index.pluginId}/sessions/export`, {
1526
+ params: buildExportParams(listQuery, cursor)
1496
1527
  });
1497
- downloadFile(csvContent, "text/csv;charset=utf-8;", "csv");
1498
- } catch (err) {
1499
- index.logSafeAdminError("dashboard.exportCsv", err);
1500
- toggleNotification({
1501
- type: "danger",
1502
- message: t("notifications.error.exportFailed", "The export could not be created.")
1503
- });
1504
- }
1528
+ rows.push(...index.requireSessionList(data));
1529
+ cursor = typeof data?.meta?.nextCursor === "string" ? data.meta.nextCursor : null;
1530
+ } while (cursor && rows.length < MAX_EXPORT_ROWS);
1531
+ const capped = rows.length > MAX_EXPORT_ROWS || Boolean(cursor) && rows.length >= MAX_EXPORT_ROWS;
1532
+ return { rows: rows.slice(0, MAX_EXPORT_ROWS), capped };
1505
1533
  };
1506
- const handleExportJSON = () => {
1534
+ const handleExport = async (format) => {
1535
+ if (exporting) return;
1536
+ setExporting(true);
1507
1537
  try {
1508
- const jsonContent = buildSessionJson(filteredSessions, {
1509
- filterStatus: dashboard.status,
1510
- totalSessions: sessions.length,
1511
- exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
1512
- unavailableValue: "",
1513
- getDeviceInfo: getExportDeviceInfo,
1514
- getSessionStatus: index.getSessionStatus,
1515
- truncated
1516
- });
1517
- downloadFile(jsonContent, "application/json", "json");
1538
+ const { rows, capped } = await fetchExportRows();
1539
+ if (format === "csv") {
1540
+ const csvContent = buildSessionCsv(rows, {
1541
+ unavailableValue: "",
1542
+ getDeviceInfo: getExportDeviceInfo,
1543
+ getSessionStatus: index.getSessionStatus
1544
+ });
1545
+ downloadFile(csvContent, "text/csv;charset=utf-8;", "csv");
1546
+ } else {
1547
+ const jsonContent = buildSessionJson(rows, {
1548
+ filterStatus: dashboard.status,
1549
+ totalSessions: stats.total,
1550
+ exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
1551
+ unavailableValue: "",
1552
+ getDeviceInfo: getExportDeviceInfo,
1553
+ getSessionStatus: index.getSessionStatus,
1554
+ truncated: capped
1555
+ });
1556
+ downloadFile(jsonContent, "application/json", "json");
1557
+ }
1558
+ if (capped) {
1559
+ toggleNotification({
1560
+ type: "warning",
1561
+ message: t(
1562
+ "homepage.export.capped",
1563
+ "The export contains the newest {limit, number} sessions. Narrow the filter to export the rest.",
1564
+ { limit: MAX_EXPORT_ROWS }
1565
+ )
1566
+ });
1567
+ }
1518
1568
  } catch (err) {
1519
- index.logSafeAdminError("dashboard.exportJson", err);
1569
+ if (index.isCancelledRequest(err)) return;
1570
+ index.logSafeAdminError(format === "csv" ? "dashboard.exportCsv" : "dashboard.exportJson", err);
1520
1571
  toggleNotification({
1521
1572
  type: "danger",
1522
1573
  message: t("notifications.error.exportFailed", "The export could not be created.")
1523
1574
  });
1575
+ } finally {
1576
+ setExporting(false);
1524
1577
  }
1525
1578
  };
1526
1579
  const handleSessionClick = (session, opener) => {
@@ -1555,10 +1608,10 @@ const HomePage = () => {
1555
1608
  []
1556
1609
  );
1557
1610
  react.useEffect(() => {
1558
- if (!loading && dashboard.page > pageResult.pageCount) {
1611
+ if (!loading && !refreshing && dashboard.page > pageResult.pageCount) {
1559
1612
  setQuery({ page: String(pageResult.pageCount) }, "push", true);
1560
1613
  }
1561
- }, [loading, dashboard.page, pageResult.pageCount, setQuery]);
1614
+ }, [loading, refreshing, dashboard.page, pageResult.pageCount, setQuery]);
1562
1615
  const handleStatusChange = (value) => {
1563
1616
  const status = String(value);
1564
1617
  setQuery({ status: status === "all" ? void 0 : status, reason: void 0, page: "1" });
@@ -1577,12 +1630,11 @@ const HomePage = () => {
1577
1630
  setQuery({ search: void 0, _q: void 0, status: void 0, reason: void 0, page: "1" });
1578
1631
  listHeadingRef.current?.focus();
1579
1632
  };
1580
- const stats = getSessionStats(sessions);
1581
1633
  const showSessionData = !loading && hasData;
1582
- const showToolbar = showSessionData && sessions.length > 0;
1583
- const canExport = showSessionData && filteredSessions.length > 0;
1634
+ const showToolbar = showSessionData && stats.total > 0;
1635
+ const canExport = showSessionData && pageResult.total > 0 && !exporting;
1584
1636
  const filtersActive = hasActiveFilters(dashboard);
1585
- const exportValues = { count: filteredSessions.length, limit: LOADED_SESSIONS_LIMIT };
1637
+ const exportValues = { count: Math.min(pageResult.total, MAX_EXPORT_ROWS) };
1586
1638
  const exportMenu = /* @__PURE__ */ jsxRuntime.jsxs(
1587
1639
  designSystem.SimpleMenu,
1588
1640
  {
@@ -1591,20 +1643,12 @@ const HomePage = () => {
1591
1643
  startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Download, {}),
1592
1644
  disabled: !canExport,
1593
1645
  children: [
1594
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.MenuItem, { onSelect: handleExportCSV, children: truncated ? t(
1595
- "homepage.export.csvTruncated",
1596
- "{count, plural, one {Export # session as CSV} other {Export # sessions as CSV}} (latest {limit, number} sessions only)",
1597
- exportValues
1598
- ) : t(
1646
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.MenuItem, { onSelect: () => void handleExport("csv"), children: t(
1599
1647
  "homepage.export.csv",
1600
1648
  "{count, plural, one {Export # session as CSV} other {Export # sessions as CSV}}",
1601
1649
  exportValues
1602
1650
  ) }),
1603
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.MenuItem, { onSelect: handleExportJSON, children: truncated ? t(
1604
- "homepage.export.jsonTruncated",
1605
- "{count, plural, one {Export # session as JSON} other {Export # sessions as JSON}} (latest {limit, number} sessions only)",
1606
- exportValues
1607
- ) : t(
1651
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.MenuItem, { onSelect: () => void handleExport("json"), children: t(
1608
1652
  "homepage.export.json",
1609
1653
  "{count, plural, one {Export # session as JSON} other {Export # sessions as JSON}}",
1610
1654
  exportValues
@@ -1736,13 +1780,13 @@ const HomePage = () => {
1736
1780
  children: /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "omega", textColor: "neutral800", tag: "span", children: t("homepage.error.load", "Sessions could not be loaded.") })
1737
1781
  }
1738
1782
  ) : null,
1739
- showSessionData && truncated ? /* @__PURE__ */ jsxRuntime.jsx(index.PersistentAlert, { variant: "default", closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "pi", textColor: "neutral700", tag: "span", children: t(
1740
- "homepage.truncated.body",
1741
- "Only the latest {limit, number} sessions are loaded. Counts, filters and exports cover these sessions only.",
1742
- { limit: LOADED_SESSIONS_LIMIT }
1783
+ showSessionData && stats.nativeOnly > 0 ? /* @__PURE__ */ jsxRuntime.jsx(index.PersistentAlert, { variant: "default", closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "pi", textColor: "neutral700", tag: "span", children: t(
1784
+ "homepage.nativeOnly.body",
1785
+ "{count, plural, one {# open Strapi session has} other {# open Strapi sessions have}} no session details from this plugin. They are listed on each user’s session panel, not in this list.",
1786
+ { count: stats.nativeOnly }
1743
1787
  ) }) }) : null,
1744
1788
  loading ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 8, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { children: t("homepage.loading", "Loading sessions") }) }) : null,
1745
- showSessionData && sessions.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(HowSessionsWork, {}) : null,
1789
+ showSessionData && stats.total > 0 ? /* @__PURE__ */ jsxRuntime.jsx(HowSessionsWork, {}) : null,
1746
1790
  showSessionData && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
1747
1791
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "h2", children: t("homepage.stats.label", "Session statistics") }) }),
1748
1792
  /* @__PURE__ */ jsxRuntime.jsxs(index.StatGrid, { label: t("homepage.stats.label", "Session statistics"), children: [
@@ -1831,7 +1875,7 @@ const HomePage = () => {
1831
1875
  ),
1832
1876
  lastUpdatedLine
1833
1877
  ] }),
1834
- filteredSessions.length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1878
+ pageResult.total > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1835
1879
  isBelowMedium ? /* @__PURE__ */ jsxRuntime.jsx(SessionCardList, { ...listProps }) : /* @__PURE__ */ jsxRuntime.jsx(
1836
1880
  SessionTable,
1837
1881
  {
@@ -1863,7 +1907,7 @@ const HomePage = () => {
1863
1907
  }
1864
1908
  )
1865
1909
  ] }),
1866
- showSessionData && sessions.length === 0 && /* @__PURE__ */ jsxRuntime.jsx(
1910
+ showSessionData && stats.total === 0 && /* @__PURE__ */ jsxRuntime.jsx(
1867
1911
  designSystem.EmptyStateLayout,
1868
1912
  {
1869
1913
  icon: /* @__PURE__ */ jsxRuntime.jsx(symbols.EmptyDocuments, { width: "16rem", height: "8.8rem", "aria-hidden": "true" }),
@@ -1889,8 +1933,7 @@ const HomePage = () => {
1889
1933
  }
1890
1934
  );
1891
1935
  };
1892
- const LicenseGuard = ({ children }) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
1893
1936
  const App = () => {
1894
- return /* @__PURE__ */ jsxRuntime.jsx(StrapiAdmin.Page.Protect, { permissions: index.pluginPermissions.access, children: /* @__PURE__ */ jsxRuntime.jsx(LicenseGuard, { children: /* @__PURE__ */ jsxRuntime.jsx(HomePage, {}) }) });
1937
+ return /* @__PURE__ */ jsxRuntime.jsx(StrapiAdmin.Page.Protect, { permissions: index.pluginPermissions.access, children: /* @__PURE__ */ jsxRuntime.jsx(HomePage, {}) });
1895
1938
  };
1896
1939
  exports.default = App;
@@ -7,7 +7,7 @@ const styled = require("styled-components");
7
7
  const designSystem = require("@strapi/design-system");
8
8
  const icons = require("@strapi/icons");
9
9
  const StrapiAdmin = require("@strapi/strapi/admin");
10
- const index = require("./index-CaLVyCio.js");
10
+ const index = require("./index-CfQOMZVX.js");
11
11
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
12
12
  function _interopNamespace(e) {
13
13
  if (e && e.__esModule) return e;
@@ -28,9 +28,6 @@ function _interopNamespace(e) {
28
28
  }
29
29
  const styled__default = /* @__PURE__ */ _interopDefault(styled);
30
30
  const StrapiAdmin__namespace = /* @__PURE__ */ _interopNamespace(StrapiAdmin);
31
- function getSessionUserKey(session) {
32
- return session?.user?.documentId || session?.user?.id || session?.user?.email || session?.user?.username || null;
33
- }
34
31
  function normalizeUserCounts(response) {
35
32
  const totalUsers = response?.data?.totalUsers;
36
33
  const blockedUsers = response?.data?.blockedUsers;
@@ -39,27 +36,22 @@ function normalizeUserCounts(response) {
39
36
  }
40
37
  return { totalUsers, blockedUsers };
41
38
  }
42
- function computeWidgetStats(sessions) {
43
- const rows = Array.isArray(sessions) ? sessions : [];
44
- const onlineUsers = /* @__PURE__ */ new Set();
45
- let activeSessions = 0;
46
- let idleSessions = 0;
47
- for (const session of rows) {
48
- if (!session || typeof session !== "object" || session.isActive !== true) continue;
49
- if (session.isTrulyActive === true) {
50
- activeSessions += 1;
51
- const userKey = getSessionUserKey(session);
52
- if (userKey) onlineUsers.add(userKey);
53
- } else {
54
- idleSessions += 1;
55
- }
56
- }
57
- return {
58
- onlineUsers: onlineUsers.size,
59
- activeSessions,
60
- idleSessions,
61
- sessionCount: rows.length
39
+ function widgetStatsFromCounts(payload) {
40
+ const data = (
41
+ /** @type {any} */
42
+ payload?.data
43
+ );
44
+ const read = (value) => Number.isFinite(value) && value >= 0 ? Math.floor(value) : NaN;
45
+ const stats = {
46
+ onlineUsers: read(data?.usersOnline),
47
+ activeSessions: read(data?.active),
48
+ idleSessions: read(data?.idle),
49
+ sessionCount: read(data?.total)
62
50
  };
51
+ if (Object.values(stats).some((value) => Number.isNaN(value))) {
52
+ throw new Error("Invalid session statistics response");
53
+ }
54
+ return stats;
63
55
  }
64
56
  const REFRESH_INTERVAL_MS = 3e4;
65
57
  const pickAdminExport = (name) => {
@@ -170,11 +162,11 @@ const OnlineUsersWidget = () => {
170
162
  requestInProgress.current = true;
171
163
  try {
172
164
  const [sessionResult, countResult] = await Promise.allSettled([
173
- get("/magic-sessionmanager/sessions"),
165
+ get("/magic-sessionmanager/sessions/stats"),
174
166
  get("/magic-sessionmanager/users/stats")
175
167
  ]);
176
168
  if (sessionResult.status === "rejected") throw sessionResult.reason;
177
- setStats(computeWidgetStats(index.requireSessionList(sessionResult.value?.data)));
169
+ setStats(widgetStatsFromCounts(sessionResult.value?.data));
178
170
  setLoadError(false);
179
171
  const counts = countResult.status === "fulfilled" ? normalizeUserCounts(countResult.value?.data) : null;
180
172
  if (counts) {
@@ -6,10 +6,7 @@ import { Flex, Loader, Button, Box, Typography } from "@strapi/design-system";
6
6
  import { User, Lightning, Clock, Lock, WarningCircle } from "@strapi/icons";
7
7
  import * as StrapiAdmin from "@strapi/strapi/admin";
8
8
  import { useFetchClient } from "@strapi/strapi/admin";
9
- import { s as requireSessionList, n as logSafeAdminError, v as isCancelledRequest, b as getTranslation, R as ReadableText, M as MissingValue } from "./index-CHACmZsg.mjs";
10
- function getSessionUserKey(session) {
11
- return session?.user?.documentId || session?.user?.id || session?.user?.email || session?.user?.username || null;
12
- }
9
+ import { m as logSafeAdminError, r as isCancelledRequest, b as getTranslation, R as ReadableText, M as MissingValue } from "./index-rbxJZcLv.mjs";
13
10
  function normalizeUserCounts(response) {
14
11
  const totalUsers = response?.data?.totalUsers;
15
12
  const blockedUsers = response?.data?.blockedUsers;
@@ -18,27 +15,22 @@ function normalizeUserCounts(response) {
18
15
  }
19
16
  return { totalUsers, blockedUsers };
20
17
  }
21
- function computeWidgetStats(sessions) {
22
- const rows = Array.isArray(sessions) ? sessions : [];
23
- const onlineUsers = /* @__PURE__ */ new Set();
24
- let activeSessions = 0;
25
- let idleSessions = 0;
26
- for (const session of rows) {
27
- if (!session || typeof session !== "object" || session.isActive !== true) continue;
28
- if (session.isTrulyActive === true) {
29
- activeSessions += 1;
30
- const userKey = getSessionUserKey(session);
31
- if (userKey) onlineUsers.add(userKey);
32
- } else {
33
- idleSessions += 1;
34
- }
35
- }
36
- return {
37
- onlineUsers: onlineUsers.size,
38
- activeSessions,
39
- idleSessions,
40
- sessionCount: rows.length
18
+ function widgetStatsFromCounts(payload) {
19
+ const data = (
20
+ /** @type {any} */
21
+ payload?.data
22
+ );
23
+ const read = (value) => Number.isFinite(value) && value >= 0 ? Math.floor(value) : NaN;
24
+ const stats = {
25
+ onlineUsers: read(data?.usersOnline),
26
+ activeSessions: read(data?.active),
27
+ idleSessions: read(data?.idle),
28
+ sessionCount: read(data?.total)
41
29
  };
30
+ if (Object.values(stats).some((value) => Number.isNaN(value))) {
31
+ throw new Error("Invalid session statistics response");
32
+ }
33
+ return stats;
42
34
  }
43
35
  const REFRESH_INTERVAL_MS = 3e4;
44
36
  const pickAdminExport = (name) => {
@@ -149,11 +141,11 @@ const OnlineUsersWidget = () => {
149
141
  requestInProgress.current = true;
150
142
  try {
151
143
  const [sessionResult, countResult] = await Promise.allSettled([
152
- get("/magic-sessionmanager/sessions"),
144
+ get("/magic-sessionmanager/sessions/stats"),
153
145
  get("/magic-sessionmanager/users/stats")
154
146
  ]);
155
147
  if (sessionResult.status === "rejected") throw sessionResult.reason;
156
- setStats(computeWidgetStats(requireSessionList(sessionResult.value?.data)));
148
+ setStats(widgetStatsFromCounts(sessionResult.value?.data));
157
149
  setLoadError(false);
158
150
  const counts = countResult.status === "fulfilled" ? normalizeUserCounts(countResult.value?.data) : null;
159
151
  if (counts) {
@@ -6,10 +6,9 @@ const designSystem = require("@strapi/design-system");
6
6
  const StrapiAdmin = require("@strapi/strapi/admin");
7
7
  const icons = require("@strapi/icons");
8
8
  const styled = require("styled-components");
9
- const index = require("./index-CaLVyCio.js");
9
+ const index = require("./index-CfQOMZVX.js");
10
10
  const reactIntl = require("react-intl");
11
11
  const SectionCard = require("./SectionCard-BlWv8CRt.js");
12
- const maskSensitiveValue = require("./maskSensitiveValue-BWcSjow7.js");
13
12
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
14
13
  const styled__default = /* @__PURE__ */ _interopDefault(styled);
15
14
  const SETTINGS_TAB_IDS = Object.freeze([
@@ -348,6 +347,13 @@ const SettingsToggleRow = ({
348
347
  }
349
348
  );
350
349
  };
350
+ const KEY_MASK = "••••••••";
351
+ function maskSensitiveValue(value) {
352
+ if (typeof value !== "string" || value.length <= 4) {
353
+ return KEY_MASK;
354
+ }
355
+ return `${KEY_MASK}${value.slice(-4)}`;
356
+ }
351
357
  const ENCRYPTION_KEY_ENV_NAME = "SESSION_ENCRYPTION_KEY";
352
358
  const ENCRYPTION_KEY_BYTES = 32;
353
359
  const HEX = "0123456789abcdef";
@@ -535,7 +541,7 @@ const EncryptionKeyCard = ({ draft, copyValue, notify }) => {
535
541
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", tag: "div", children: t("settings.security.encryption.envLabel", "Add to .env file:") }),
536
542
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", tag: "p", children: /* @__PURE__ */ jsxRuntime.jsx("code", { "data-env-preview": "", children: formatEnvLine(
537
543
  ENCRYPTION_KEY_ENV_NAME,
538
- showEncryptionKey ? encryptionKey : maskSensitiveValue.maskSensitiveValue(encryptionKey)
544
+ showEncryptionKey ? encryptionKey : maskSensitiveValue(encryptionKey)
539
545
  ) }) })
540
546
  ] }) }) : null
541
547
  ] });
@@ -4,10 +4,9 @@ import { Field, Typography, Switch, Box, TextInput, Flex, Button, Link, SingleSe
4
4
  import { ConfirmDialog, useNotification, useFetchClient, useQueryParams, Page, Form, Blocker, useForm } from "@strapi/strapi/admin";
5
5
  import { EyeStriked, Eye, Key, Duplicate, Cross, Plus, Trash, Check } from "@strapi/icons";
6
6
  import styled from "styled-components";
7
- import { H as ReadableParagraphs, b as getTranslation, n as logSafeAdminError, R as ReadableText, I as EqualGrid, o as PersistentAlert, P as PropertyList, J as formatSessionDate, C as ConfirmAction, K as refocusIfLost, m as pluginId, L as requireSuccessfulMutation, z as PageShell } from "./index-CHACmZsg.mjs";
7
+ import { B as ReadableParagraphs, b as getTranslation, m as logSafeAdminError, R as ReadableText, F as EqualGrid, n as PersistentAlert, P as PropertyList, G as formatSessionDate, C as ConfirmAction, H as refocusIfLost, l as pluginId, I as requireSuccessfulMutation, v as PageShell } from "./index-rbxJZcLv.mjs";
8
8
  import { useIntl } from "react-intl";
9
9
  import { S as SectionCard } from "./SectionCard-D51bv4Hi.mjs";
10
- import { m as maskSensitiveValue } from "./maskSensitiveValue-lLRhN_S7.mjs";
11
10
  const SETTINGS_TAB_IDS = Object.freeze([
12
11
  "sessions",
13
12
  "login-protection",
@@ -344,6 +343,13 @@ const SettingsToggleRow = ({
344
343
  }
345
344
  );
346
345
  };
346
+ const KEY_MASK = "••••••••";
347
+ function maskSensitiveValue(value) {
348
+ if (typeof value !== "string" || value.length <= 4) {
349
+ return KEY_MASK;
350
+ }
351
+ return `${KEY_MASK}${value.slice(-4)}`;
352
+ }
347
353
  const ENCRYPTION_KEY_ENV_NAME = "SESSION_ENCRYPTION_KEY";
348
354
  const ENCRYPTION_KEY_BYTES = 32;
349
355
  const HEX = "0123456789abcdef";