strapi-plugin-magic-sessionmanager 4.16.1 → 4.18.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 +76 -0
  2. package/README.md +119 -25
  3. package/dist/admin/{Analytics-CMR62DiD.js → Analytics-C8fV6LDV.js} +1 -1
  4. package/dist/admin/{Analytics-FcRt0X62.mjs → Analytics-CBspdl1I.mjs} +1 -1
  5. package/dist/admin/{App-CmytGbze.js → App-D92MTQmn.js} +33 -170
  6. package/dist/admin/{App-DBieSWB0.mjs → App-PLwqaRSQ.mjs} +3 -140
  7. package/dist/admin/{OnlineUsersWidget-Lzx9XB74.js → OnlineUsersWidget-CiKapC1B.js} +1 -1
  8. package/dist/admin/{OnlineUsersWidget-zP9Hl_it.mjs → OnlineUsersWidget-CwfBJdIX.mjs} +1 -1
  9. package/dist/admin/{Settings-CZOPusQK.mjs → Settings-CMgL-Aub.mjs} +2013 -78
  10. package/dist/admin/{Settings-1v--SXC0.js → Settings-Duil_4jv.js} +2017 -82
  11. package/dist/admin/dashboardModel-BhUonEqc.mjs +189 -0
  12. package/dist/admin/dashboardModel-sksvIc1c.js +188 -0
  13. package/dist/admin/{de-y_9mdVT7.js → de-CnInuvMY.js} +196 -11
  14. package/dist/admin/{de-D3TSA066.mjs → de-D2BqfY1f.mjs} +196 -11
  15. package/dist/admin/{en-B60I97bK.mjs → en-BPy208we.mjs} +196 -11
  16. package/dist/admin/{en-CIQB8nfI.js → en-KnmmYHTF.js} +196 -11
  17. package/dist/admin/{es-CJEL_iGC.mjs → es-B4VNeT0A.mjs} +196 -11
  18. package/dist/admin/{es-DHhHzlRY.js → es-D1NGCAJK.js} +196 -11
  19. package/dist/admin/{fr-BfBK_iuV.mjs → fr-AwhLN1BC.mjs} +196 -11
  20. package/dist/admin/{fr-D86FTt1w.js → fr-D1KNyogi.js} +196 -11
  21. package/dist/admin/{index-tt61o2VH.mjs → index-BmnC2BPs.mjs} +40 -38
  22. package/dist/admin/{index-CSJJn4qy.js → index-Bnt0Jq6O.js} +12 -10
  23. package/dist/admin/index.js +1 -1
  24. package/dist/admin/index.mjs +1 -1
  25. package/dist/admin/{pt-C3PSvC7z.mjs → pt-D6m1TijL.mjs} +196 -11
  26. package/dist/admin/{pt-BE-FT-L8.js → pt-EKThRXPY.js} +196 -11
  27. package/dist/server/index.js +3230 -129
  28. package/dist/server/index.mjs +3230 -129
  29. package/package.json +1 -1
  30. package/dist/admin/riskData-BVs9GpgD.js +0 -26
  31. package/dist/admin/riskData-CI1gm2yI.mjs +0 -27
@@ -9,8 +9,8 @@ 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-CSJJn4qy.js");
13
- const riskData = require("./riskData-BVs9GpgD.js");
12
+ const index = require("./index-Bnt0Jq6O.js");
13
+ const dashboardModel = require("./dashboardModel-sksvIc1c.js");
14
14
  const SectionCard = require("./SectionCard-BlWv8CRt.js");
15
15
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
16
16
  const styled__default = /* @__PURE__ */ _interopDefault(styled);
@@ -25,7 +25,6 @@ const EndReason = ({ session, reason, variant = "omega", textColor = "neutral800
25
25
  });
26
26
  return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant, textColor, "data-end-reason": presentation.reason, children: translate(presentation) });
27
27
  };
28
- const RowActions = ({ children, ...props }) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "flex-end", alignItems: "center", gap: 1, "data-row-actions": "", ...props, children });
29
28
  const MAX_EXPORT_ROWS = 5e4;
30
29
  const EXPORT_BATCH_SIZE = 1e3;
31
30
  const EMPTY_SESSION_STATS = Object.freeze({
@@ -260,23 +259,6 @@ function useBreakpoint() {
260
259
  isBelowLarge: isBelowBreakpoint(breakpoint, "large")
261
260
  };
262
261
  }
263
- function useElementWidth() {
264
- const [width, setWidth] = react.useState(0);
265
- const observerRef = react.useRef(null);
266
- const ref = react.useCallback((node) => {
267
- observerRef.current?.disconnect();
268
- observerRef.current = null;
269
- if (!node || typeof ResizeObserver === "undefined") return;
270
- const observer = new ResizeObserver((entries) => {
271
- const next = Math.round(entries[0]?.contentRect?.width || 0);
272
- setWidth((previous) => previous === next ? previous : next);
273
- });
274
- observer.observe(node);
275
- observerRef.current = observer;
276
- }, []);
277
- react.useEffect(() => () => observerRef.current?.disconnect(), []);
278
- return [ref, width];
279
- }
280
262
  const RISK_LEVEL_MESSAGES = Object.freeze({
281
263
  none: Object.freeze({ messageId: "modal.security.risk.none", defaultMessage: "None" }),
282
264
  low: Object.freeze({ messageId: "modal.security.risk.low", defaultMessage: "Low" }),
@@ -307,7 +289,7 @@ function normalizeGeoData(geo, fallback = {}) {
307
289
  const city = index.presentText(geo.city);
308
290
  const timezone = index.presentText(geo.timezone);
309
291
  if (!country && !city && !timezone) return null;
310
- const riskSource = riskData.isRiskSource(geo.riskSource) ? geo.riskSource : null;
292
+ const riskSource = dashboardModel.isRiskSource(geo.riskSource) ? geo.riskSource : null;
311
293
  const rawScore = typeof geo.securityScore === "number" ? geo.securityScore : fallback?.securityScore;
312
294
  const securityScore = riskSource && typeof rawScore === "number" && Number.isFinite(rawScore) ? rawScore : null;
313
295
  return {
@@ -353,125 +335,6 @@ function interpretLookupResult(payload) {
353
335
  const geo = normalizeGeoData(data);
354
336
  return geo ? { status: "ok", geo } : { status: "failed", geo: null };
355
337
  }
356
- const PAGE_SIZE_OPTIONS = Object.freeze(["10", "25", "50", "100"]);
357
- const DEFAULT_PAGE_SIZE = "25";
358
- const DASHBOARD_TABLE_COLUMNS = 7;
359
- const DASHBOARD_COMPACT_TABLE_COLUMNS = 5;
360
- const AUTO_REFRESH_INTERVAL_MS = 10 * 60 * 1e3;
361
- const HOW_IT_WORKS_STORAGE_KEY = "magic-sessionmanager.dashboard.howSessionsWork";
362
- const USER_EDIT_PATH = "/content-manager/collection-types/plugin::users-permissions.user/";
363
- const readQueryText = (value) => {
364
- if (typeof value !== "string") return "";
365
- try {
366
- return decodeURIComponent(value).trim();
367
- } catch {
368
- return value.trim();
369
- }
370
- };
371
- function parseDashboardQuery(query = {}) {
372
- const source = query || {};
373
- const page = Number.parseInt(String(source.page ?? "1"), 10);
374
- const pageSize = PAGE_SIZE_OPTIONS.includes(String(source.pageSize)) ? String(source.pageSize) : DEFAULT_PAGE_SIZE;
375
- const status = index.isSessionFilter(source.status) ? (
376
- /** @type {string} */
377
- source.status
378
- ) : index.DEFAULT_SESSION_FILTER;
379
- const reason = status === "ended" && index.isEndReasonFilter(source.reason) ? (
380
- /** @type {string} */
381
- source.reason
382
- ) : index.DEFAULT_END_REASON_FILTER;
383
- const search = readQueryText(source.search) || readQueryText(source._q);
384
- return { page: Number.isFinite(page) && page >= 1 ? page : 1, pageSize, status, reason, search };
385
- }
386
- function encodeSearchQuery(value) {
387
- const text = typeof value === "string" ? value.trim() : "";
388
- return text ? encodeURIComponent(text) : void 0;
389
- }
390
- function hasActiveFilters(state) {
391
- if (!state) return false;
392
- return state.status !== index.DEFAULT_SESSION_FILTER || Boolean(state.reason) && state.reason !== index.DEFAULT_END_REASON_FILTER || Boolean(state.search);
393
- }
394
- function getSessionUserLabels(session) {
395
- const username = index.presentText(session?.user?.username);
396
- const email = index.presentText(session?.user?.email);
397
- const primary = username || email;
398
- return {
399
- primary,
400
- secondary: username && email ? email : "",
401
- accessible: primary || index.presentText(session?.id)
402
- };
403
- }
404
- function getUserEditPath(session) {
405
- const documentId = index.presentText(session?.user?.documentId);
406
- return documentId ? `${USER_EDIT_PATH}${encodeURIComponent(documentId)}` : null;
407
- }
408
- function getExportDeviceInfo(session, unavailableValue = "") {
409
- const device = index.getDevicePresentation(session);
410
- return {
411
- device: device.deviceType || unavailableValue,
412
- browser: device.browser || unavailableValue,
413
- browserVersion: device.browserVersion || "",
414
- os: device.os || unavailableValue
415
- };
416
- }
417
- function readDisclosureOpen(storage) {
418
- try {
419
- return storage?.getItem(HOW_IT_WORKS_STORAGE_KEY) === "open";
420
- } catch {
421
- return false;
422
- }
423
- }
424
- function writeDisclosureOpen(storage, open) {
425
- try {
426
- storage?.setItem(HOW_IT_WORKS_STORAGE_KEY, open ? "open" : "closed");
427
- } catch {
428
- }
429
- }
430
- function getBrowserStorage() {
431
- try {
432
- return typeof window !== "undefined" ? window.localStorage : null;
433
- } catch {
434
- return null;
435
- }
436
- }
437
- function shouldIsolateActionKey(key, fromInsideGroup) {
438
- if (!fromInsideGroup) return true;
439
- return key === "Enter" || key === " " || key === "Spacebar";
440
- }
441
- const FULL_TABLE_MIN_WIDTH = 1200;
442
- function shouldUseCompactTable(listWidth, isBelowLarge) {
443
- if (isBelowLarge) return true;
444
- if (!Number.isFinite(listWidth) || listWidth <= 0) return false;
445
- return listWidth < FULL_TABLE_MIN_WIDTH;
446
- }
447
- function shouldRedispatchEscape(key, fromInsideGroup) {
448
- return !fromInsideGroup && key === "Escape";
449
- }
450
- function pickFocusSessionId(previousIds, currentIds, sessionId) {
451
- const current = Array.isArray(currentIds) ? currentIds.map(String) : [];
452
- if (current.length === 0) return null;
453
- const target = String(sessionId);
454
- if (current.includes(target)) return target;
455
- const previous = Array.isArray(previousIds) ? previousIds.map(String) : [];
456
- const index2 = previous.indexOf(target);
457
- if (index2 >= 0) {
458
- for (let next = index2 + 1; next < previous.length; next += 1) {
459
- if (current.includes(previous[next])) return previous[next];
460
- }
461
- for (let before = index2 - 1; before >= 0; before -= 1) {
462
- if (current.includes(previous[before])) return previous[before];
463
- }
464
- }
465
- return current[0];
466
- }
467
- function getErrorStatus(error) {
468
- const err = (
469
- /** @type {any} */
470
- error
471
- );
472
- const status = err?.status ?? err?.response?.status;
473
- return typeof status === "number" ? status : null;
474
- }
475
338
  const TargetLink = styled__default.default(designSystem.Link)`
476
339
  min-height: 3.2rem;
477
340
  display: inline-flex;
@@ -517,8 +380,8 @@ const SessionDetailModal = ({ session, now, onClose, onCloseAutoFocus, onEndSess
517
380
  const userAgent = index.presentText(session.userAgent);
518
381
  const sessionId = index.presentText(session.id);
519
382
  const ipAddress = index.presentText(session.ipAddress);
520
- const user = getSessionUserLabels(session);
521
- const userEditPath = getUserEditPath(session);
383
+ const user = dashboardModel.getSessionUserLabels(session);
384
+ const userEditPath = dashboardModel.getUserEditPath(session);
522
385
  const storedGeo = getStoredGeoData(session);
523
386
  const liveGeo = lookup.status === "ok" ? lookup.geo : null;
524
387
  const geo = liveGeo || storedGeo;
@@ -750,7 +613,7 @@ const SessionDetailModal = ({ session, now, onClose, onCloseAutoFocus, onEndSess
750
613
  "modal.security.riskUnavailableNote",
751
614
  "Needs a risk data source. Location data alone cannot tell VPNs, proxies or Tor apart, so no score was calculated."
752
615
  ) }),
753
- /* @__PURE__ */ jsxRuntime.jsx(TargetLink, { tag: reactRouterDom.NavLink, to: riskData.RISK_SETTINGS_PATH, children: t("modal.security.riskSetup", "Set up risk data") })
616
+ /* @__PURE__ */ jsxRuntime.jsx(TargetLink, { tag: reactRouterDom.NavLink, to: dashboardModel.RISK_SETTINGS_PATH, children: t("modal.security.riskSetup", "Set up risk data") })
754
617
  ] }) : null,
755
618
  lookupControls
756
619
  ] }),
@@ -893,9 +756,9 @@ const isolateActionKeys = (event) => {
893
756
  /** @type {Node} */
894
757
  event.target
895
758
  );
896
- if (!shouldIsolateActionKey(event.key, fromInsideGroup)) return;
759
+ if (!dashboardModel.shouldIsolateActionKey(event.key, fromInsideGroup)) return;
897
760
  event.stopPropagation();
898
- if (shouldRedispatchEscape(event.key, fromInsideGroup)) {
761
+ if (dashboardModel.shouldRedispatchEscape(event.key, fromInsideGroup)) {
899
762
  const { ownerDocument } = event.currentTarget;
900
763
  ownerDocument.dispatchEvent(
901
764
  new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true })
@@ -943,7 +806,7 @@ const SessionActions = ({
943
806
  const t = (id, defaultMessage, values) => formatMessage({ id: index.getTranslation(id), defaultMessage }, values);
944
807
  const [deleteOpen, setDeleteOpen] = react.useState(false);
945
808
  const moreRef = react.useRef(null);
946
- const user = getSessionUserLabels(session).accessible;
809
+ const user = dashboardModel.getSessionUserLabels(session).accessible;
947
810
  const canEnd = session.isActive === true;
948
811
  const device = deviceSummary(session) || deviceTypeLabel(session);
949
812
  const copy = getConfirmationCopy(t, { user, device, isOpen: canEnd });
@@ -970,7 +833,7 @@ const SessionActions = ({
970
833
  );
971
834
  const endKey = `end-${session.id}-${canEnd ? "open" : "ended"}`;
972
835
  if (layout === "table") {
973
- return /* @__PURE__ */ jsxRuntime.jsxs(RowActions, { onKeyDown: isolateActionKeys, onClick: (event) => event.stopPropagation(), children: [
836
+ return /* @__PURE__ */ jsxRuntime.jsxs(dashboardModel.RowActions, { onKeyDown: isolateActionKeys, onClick: (event) => event.stopPropagation(), children: [
974
837
  /* @__PURE__ */ jsxRuntime.jsx(
975
838
  designSystem.IconButton,
976
839
  {
@@ -1111,7 +974,7 @@ const SessionTable = ({
1111
974
  return /* @__PURE__ */ jsxRuntime.jsxs(
1112
975
  designSystem.Table,
1113
976
  {
1114
- colCount: compact ? DASHBOARD_COMPACT_TABLE_COLUMNS : DASHBOARD_TABLE_COLUMNS,
977
+ colCount: compact ? dashboardModel.DASHBOARD_COMPACT_TABLE_COLUMNS : dashboardModel.DASHBOARD_TABLE_COLUMNS,
1115
978
  rowCount: sessions.length + 1,
1116
979
  "aria-labelledby": labelledBy,
1117
980
  "aria-busy": busy,
@@ -1126,7 +989,7 @@ const SessionTable = ({
1126
989
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Th, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { children: t("homepage.table.actions", "Actions") }) })
1127
990
  ] }) }),
1128
991
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: sessions.map((session) => {
1129
- const user = getSessionUserLabels(session);
992
+ const user = dashboardModel.getSessionUserLabels(session);
1130
993
  return /* @__PURE__ */ jsxRuntime.jsxs(
1131
994
  designSystem.Tr,
1132
995
  {
@@ -1202,7 +1065,7 @@ const SessionCardList = ({
1202
1065
  mutationPending,
1203
1066
  getFocusFallback
1204
1067
  }) => /* @__PURE__ */ jsxRuntime.jsx(CardList, { "aria-labelledby": labelledBy, "aria-busy": busy, children: sessions.map((session) => {
1205
- const user = getSessionUserLabels(session);
1068
+ const user = dashboardModel.getSessionUserLabels(session);
1206
1069
  return /* @__PURE__ */ jsxRuntime.jsx(
1207
1070
  designSystem.Box,
1208
1071
  {
@@ -1338,12 +1201,12 @@ const Legend = styled__default.default.ul`
1338
1201
  const HowSessionsWork = () => {
1339
1202
  const { formatMessage } = reactIntl.useIntl();
1340
1203
  const t = (id, defaultMessage, values) => formatMessage({ id: index.getTranslation(id), defaultMessage }, values);
1341
- const [open, setOpen] = react.useState(() => readDisclosureOpen(getBrowserStorage()));
1204
+ const [open, setOpen] = react.useState(() => dashboardModel.readDisclosureOpen(dashboardModel.getBrowserStorage()));
1342
1205
  const contentId = `how-sessions-work-${react.useId().replace(/:/g, "")}`;
1343
1206
  const toggle = () => {
1344
1207
  setOpen((previous) => {
1345
1208
  const next = !previous;
1346
- writeDisclosureOpen(getBrowserStorage(), next);
1209
+ dashboardModel.writeDisclosureOpen(dashboardModel.getBrowserStorage(), next);
1347
1210
  return next;
1348
1211
  });
1349
1212
  };
@@ -1844,10 +1707,10 @@ const HomePage = () => {
1844
1707
  const { toggleNotification } = StrapiAdmin.useNotification();
1845
1708
  const formatters = index.useSessionFormatters();
1846
1709
  const { isBelowSmall, isBelowMedium, isBelowLarge } = useBreakpoint();
1847
- const [listWidthRef, listWidth] = useElementWidth();
1710
+ const [listWidthRef, listWidth] = dashboardModel.useElementWidth();
1848
1711
  const [{ query }, setQuery] = StrapiAdmin.useQueryParams();
1849
1712
  const t = (id, defaultMessage, values) => formatMessage({ id: index.getTranslation(id), defaultMessage }, values);
1850
- const dashboard = parseDashboardQuery(query);
1713
+ const dashboard = dashboardModel.parseDashboardQuery(query);
1851
1714
  const [sessions, setSessions] = react.useState([]);
1852
1715
  const [pagination, setPagination] = react.useState({ total: 0, pageCount: 1 });
1853
1716
  const [stats, setStats] = react.useState(EMPTY_SESSION_STATS);
@@ -1924,7 +1787,7 @@ const HomePage = () => {
1924
1787
  if (showDetailModal || mutationPending) return void 0;
1925
1788
  const interval = setInterval(() => {
1926
1789
  fetchSessions();
1927
- }, AUTO_REFRESH_INTERVAL_MS);
1790
+ }, dashboardModel.AUTO_REFRESH_INTERVAL_MS);
1928
1791
  return () => clearInterval(interval);
1929
1792
  }, [showDetailModal, mutationPending, fetchSessions]);
1930
1793
  const handleTerminateSession = async (session) => {
@@ -1941,7 +1804,7 @@ const HomePage = () => {
1941
1804
  });
1942
1805
  } catch (err) {
1943
1806
  index.logSafeAdminError("dashboard.terminateSession", err);
1944
- if (getErrorStatus(err) === 404) {
1807
+ if (dashboardModel.getErrorStatus(err) === 404) {
1945
1808
  await fetchSessions();
1946
1809
  toggleNotification({
1947
1810
  type: "warning",
@@ -1981,7 +1844,7 @@ const HomePage = () => {
1981
1844
  });
1982
1845
  } catch (err) {
1983
1846
  index.logSafeAdminError("dashboard.deleteSession", err);
1984
- if (getErrorStatus(err) === 404) {
1847
+ if (dashboardModel.getErrorStatus(err) === 404) {
1985
1848
  await fetchSessions();
1986
1849
  toggleNotification({
1987
1850
  type: "warning",
@@ -2037,7 +1900,7 @@ const HomePage = () => {
2037
1900
  if (format === "csv") {
2038
1901
  const csvContent = buildSessionCsv(rows, {
2039
1902
  unavailableValue: "",
2040
- getDeviceInfo: getExportDeviceInfo,
1903
+ getDeviceInfo: dashboardModel.getExportDeviceInfo,
2041
1904
  getSessionStatus: index.getSessionStatus
2042
1905
  });
2043
1906
  downloadFile(csvContent, "text/csv;charset=utf-8;", "csv");
@@ -2047,7 +1910,7 @@ const HomePage = () => {
2047
1910
  totalSessions: stats.total,
2048
1911
  exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
2049
1912
  unavailableValue: "",
2050
- getDeviceInfo: getExportDeviceInfo,
1913
+ getDeviceInfo: dashboardModel.getExportDeviceInfo,
2051
1914
  getSessionStatus: index.getSessionStatus,
2052
1915
  truncated: capped
2053
1916
  });
@@ -2089,7 +1952,7 @@ const HomePage = () => {
2089
1952
  const getFocusFallback = react.useCallback(
2090
1953
  (sessionId) => ({
2091
1954
  get current() {
2092
- const targetId = pickFocusSessionId(
1955
+ const targetId = dashboardModel.pickFocusSessionId(
2093
1956
  mutationSnapshotRef.current,
2094
1957
  visibleIdsRef.current,
2095
1958
  sessionId
@@ -2120,7 +1983,7 @@ const HomePage = () => {
2120
1983
  };
2121
1984
  const handleSearch = react.useCallback(
2122
1985
  (value) => {
2123
- setQuery({ search: encodeSearchQuery(value), _q: void 0, page: "1" }, "push", true);
1986
+ setQuery({ search: dashboardModel.encodeSearchQuery(value), _q: void 0, page: "1" }, "push", true);
2124
1987
  },
2125
1988
  [setQuery]
2126
1989
  );
@@ -2131,7 +1994,7 @@ const HomePage = () => {
2131
1994
  const showSessionData = !loading && hasData;
2132
1995
  const showToolbar = showSessionData && stats.total > 0;
2133
1996
  const canExport = showSessionData && pageResult.total > 0 && !exporting;
2134
- const filtersActive = hasActiveFilters(dashboard);
1997
+ const filtersActive = dashboardModel.hasActiveFilters(dashboard);
2135
1998
  const exportValues = { count: Math.min(pageResult.total, MAX_EXPORT_ROWS) };
2136
1999
  const exportMenu = /* @__PURE__ */ jsxRuntime.jsxs(
2137
2000
  designSystem.SimpleMenu,
@@ -2382,7 +2245,7 @@ const HomePage = () => {
2382
2245
  SessionTable,
2383
2246
  {
2384
2247
  ...listProps,
2385
- compact: shouldUseCompactTable(listWidth, isBelowLarge)
2248
+ compact: dashboardModel.shouldUseCompactTable(listWidth, isBelowLarge)
2386
2249
  }
2387
2250
  ),
2388
2251
  /* @__PURE__ */ jsxRuntime.jsx(PaginationTargets$1, { children: /* @__PURE__ */ jsxRuntime.jsxs(
@@ -2390,9 +2253,9 @@ const HomePage = () => {
2390
2253
  {
2391
2254
  pageCount: pageResult.pageCount,
2392
2255
  total: pageResult.total,
2393
- defaultPageSize: Number(DEFAULT_PAGE_SIZE),
2256
+ defaultPageSize: Number(dashboardModel.DEFAULT_PAGE_SIZE),
2394
2257
  children: [
2395
- /* @__PURE__ */ jsxRuntime.jsx(StrapiAdmin.Pagination.PageSize, { options: [...PAGE_SIZE_OPTIONS] }),
2258
+ /* @__PURE__ */ jsxRuntime.jsx(StrapiAdmin.Pagination.PageSize, { options: [...dashboardModel.PAGE_SIZE_OPTIONS] }),
2396
2259
  /* @__PURE__ */ jsxRuntime.jsx(StrapiAdmin.Pagination.Links, {})
2397
2260
  ]
2398
2261
  }
@@ -2582,7 +2445,7 @@ function withEventAdminNames(row, placeholderName) {
2582
2445
  }
2583
2446
  const HIGHLIGHT_BADGE = { backgroundColor: "primary100", textColor: "neutral800" };
2584
2447
  const keepActionKeys = (event) => {
2585
- if (shouldIsolateActionKey(event.key, true)) event.stopPropagation();
2448
+ if (dashboardModel.shouldIsolateActionKey(event.key, true)) event.stopPropagation();
2586
2449
  };
2587
2450
  const SHRINKING_ADMIN_CELL = { maxWidth: 0, width: "34%" };
2588
2451
  const SHRINKING_ROLES_CELL = { maxWidth: 0, width: "22%" };
@@ -2653,7 +2516,7 @@ const AdminTable = ({
2653
2516
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { style: SHRINKING_ROLES_CELL, children: /* @__PURE__ */ jsxRuntime.jsx(AdminRoles, { admin }) }),
2654
2517
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(AdminStatus, { admin }) }),
2655
2518
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(LastActive, { value: admin.lastActiveAt }) }),
2656
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsxs(RowActions, { onKeyDown: keepActionKeys, children: [
2519
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsxs(dashboardModel.RowActions, { onKeyDown: keepActionKeys, children: [
2657
2520
  /* @__PURE__ */ jsxRuntime.jsx(
2658
2521
  designSystem.IconButton,
2659
2522
  {
@@ -3863,7 +3726,7 @@ const AdminPanelPage = () => {
3863
3726
  setQuery({ filter: filter === "all" ? void 0 : filter, page: "1" });
3864
3727
  };
3865
3728
  const handleSearch = react.useCallback(
3866
- (value) => setQuery({ search: encodeSearchQuery(value), page: "1" }, "push", true),
3729
+ (value) => setQuery({ search: dashboardModel.encodeSearchQuery(value), page: "1" }, "push", true),
3867
3730
  [setQuery]
3868
3731
  );
3869
3732
  const handleClearFilters = () => {
@@ -3906,10 +3769,10 @@ const AdminPanelPage = () => {
3906
3769
  index.logSafeAdminError("adminPanel.signOut", err);
3907
3770
  const message2 = getSignOutErrorMessage(err);
3908
3771
  toggleNotification({
3909
- type: getErrorStatus(err) === 404 ? "warning" : "danger",
3772
+ type: dashboardModel.getErrorStatus(err) === 404 ? "warning" : "danger",
3910
3773
  message: t(message2.messageId, message2.defaultMessage)
3911
3774
  });
3912
- if (getErrorStatus(err) === 404) {
3775
+ if (dashboardModel.getErrorStatus(err) === 404) {
3913
3776
  await Promise.all([fetchAdmins(), selected ? fetchDialogSessions(selected) : null]);
3914
3777
  return;
3915
3778
  }
@@ -1,14 +1,14 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
2
  import { useFetchClient, useNotification, useClipboard, useRBAC, useQueryParams, Pagination, Page } from "@strapi/strapi/admin";
3
3
  import { NavLink, Link as Link$1, Routes, Route } from "react-router-dom";
4
- import { useMemo, useState, useEffect, useRef, useCallback, useId, useLayoutEffect } from "react";
4
+ import { useMemo, useState, useEffect, useRef, useId, useCallback, useLayoutEffect } from "react";
5
5
  import { useIntl } from "react-intl";
6
6
  import { Typography, Flex, Loader, Button, Modal, Accordion, Box, IconButton, Link, SimpleMenu, MenuItem, Grid, Table, Thead, Tr, Th, VisuallyHidden, Tbody, Td, Tooltip, SearchForm, Searchbar, TextButton, SingleSelect, SingleSelectOption, EmptyStateLayout, LinkButton, Badge, Tabs, Dialog } from "@strapi/design-system";
7
7
  import { Earth, Duplicate, Cross, Eye, Trash, More, CaretDown, Download, ArrowClockwise, Check, Clock, User, ChartBubble, Cog, SignOut } from "@strapi/icons";
8
8
  import { EmptyDocuments } from "@strapi/icons/symbols";
9
9
  import styled, { useTheme } from "styled-components";
10
- import { g as getSessionEndReason, a as getEndReasonPresentation, b as getTranslation, p as presentText, i as isSessionFilter, D as DEFAULT_SESSION_FILTER, c as isEndReasonFilter, d as DEFAULT_END_REASON_FILTER, e as getDevicePresentation, u as useSessionFormatters, f as getSessionStatus, h as isNativeOnlySession, j as getSessionEndReasonPresentation, k as DeviceIcon, S as StatusBadge, P as PropertyList, C as ConfirmAction, t as toValidDate, l as pluginId, m as logSafeAdminError, n as PersistentAlert, R as ReadableText, o as pluginPermissions, M as MissingValue, V as ValueOrMissing, q as SESSION_STATES, r as SESSION_STATUS_PRESENTATION, s as isCancelledRequest, v as SESSION_FILTER_OPTIONS, E as END_REASON_FILTER_OPTIONS, w as PageShell, x as StatGrid, y as StatCard, z as restoreDialogFocus, A as requireSessionList, B as getBadgeColors, T as TargetLink$1 } from "./index-tt61o2VH.mjs";
11
- import { i as isRiskSource, R as RISK_SETTINGS_PATH } from "./riskData-CI1gm2yI.mjs";
10
+ import { g as getSessionEndReason, a as getEndReasonPresentation, b as getTranslation, p as presentText, u as useSessionFormatters, c as getSessionStatus, d as getDevicePresentation, i as isNativeOnlySession, e as getSessionEndReasonPresentation, D as DeviceIcon, S as StatusBadge, P as PropertyList, C as ConfirmAction, t as toValidDate, f as pluginId, l as logSafeAdminError, h as PersistentAlert, R as ReadableText, j as pluginPermissions, M as MissingValue, V as ValueOrMissing, k as SESSION_STATES, m as SESSION_STATUS_PRESENTATION, n as isCancelledRequest, o as SESSION_FILTER_OPTIONS, E as END_REASON_FILTER_OPTIONS, q as PageShell, r as StatGrid, s as StatCard, v as restoreDialogFocus, w as requireSessionList, x as getBadgeColors, T as TargetLink$1 } from "./index-BmnC2BPs.mjs";
11
+ import { i as isRiskSource, g as getSessionUserLabels, a as getUserEditPath, R as RISK_SETTINGS_PATH, b as RowActions, s as shouldIsolateActionKey, c as shouldRedispatchEscape, D as DASHBOARD_COMPACT_TABLE_COLUMNS, d as DASHBOARD_TABLE_COLUMNS, r as readDisclosureOpen, e as getBrowserStorage, w as writeDisclosureOpen, u as useElementWidth, p as parseDashboardQuery, A as AUTO_REFRESH_INTERVAL_MS, f as pickFocusSessionId, h as encodeSearchQuery, j as shouldUseCompactTable, P as PAGE_SIZE_OPTIONS, k as DEFAULT_PAGE_SIZE, l as getExportDeviceInfo, m as getErrorStatus, n as hasActiveFilters } from "./dashboardModel-BhUonEqc.mjs";
12
12
  import { S as SectionCard } from "./SectionCard-D51bv4Hi.mjs";
13
13
  const EndReason = ({ session, reason, variant = "omega", textColor = "neutral800" }) => {
14
14
  const { formatMessage } = useIntl();
@@ -21,7 +21,6 @@ const EndReason = ({ session, reason, variant = "omega", textColor = "neutral800
21
21
  });
22
22
  return /* @__PURE__ */ jsx(Typography, { variant, textColor, "data-end-reason": presentation.reason, children: translate(presentation) });
23
23
  };
24
- const RowActions = ({ children, ...props }) => /* @__PURE__ */ jsx(Flex, { justifyContent: "flex-end", alignItems: "center", gap: 1, "data-row-actions": "", ...props, children });
25
24
  const MAX_EXPORT_ROWS = 5e4;
26
25
  const EXPORT_BATCH_SIZE = 1e3;
27
26
  const EMPTY_SESSION_STATS = Object.freeze({
@@ -256,23 +255,6 @@ function useBreakpoint() {
256
255
  isBelowLarge: isBelowBreakpoint(breakpoint, "large")
257
256
  };
258
257
  }
259
- function useElementWidth() {
260
- const [width, setWidth] = useState(0);
261
- const observerRef = useRef(null);
262
- const ref = useCallback((node) => {
263
- observerRef.current?.disconnect();
264
- observerRef.current = null;
265
- if (!node || typeof ResizeObserver === "undefined") return;
266
- const observer = new ResizeObserver((entries) => {
267
- const next = Math.round(entries[0]?.contentRect?.width || 0);
268
- setWidth((previous) => previous === next ? previous : next);
269
- });
270
- observer.observe(node);
271
- observerRef.current = observer;
272
- }, []);
273
- useEffect(() => () => observerRef.current?.disconnect(), []);
274
- return [ref, width];
275
- }
276
258
  const RISK_LEVEL_MESSAGES = Object.freeze({
277
259
  none: Object.freeze({ messageId: "modal.security.risk.none", defaultMessage: "None" }),
278
260
  low: Object.freeze({ messageId: "modal.security.risk.low", defaultMessage: "Low" }),
@@ -349,125 +331,6 @@ function interpretLookupResult(payload) {
349
331
  const geo = normalizeGeoData(data);
350
332
  return geo ? { status: "ok", geo } : { status: "failed", geo: null };
351
333
  }
352
- const PAGE_SIZE_OPTIONS = Object.freeze(["10", "25", "50", "100"]);
353
- const DEFAULT_PAGE_SIZE = "25";
354
- const DASHBOARD_TABLE_COLUMNS = 7;
355
- const DASHBOARD_COMPACT_TABLE_COLUMNS = 5;
356
- const AUTO_REFRESH_INTERVAL_MS = 10 * 60 * 1e3;
357
- const HOW_IT_WORKS_STORAGE_KEY = "magic-sessionmanager.dashboard.howSessionsWork";
358
- const USER_EDIT_PATH = "/content-manager/collection-types/plugin::users-permissions.user/";
359
- const readQueryText = (value) => {
360
- if (typeof value !== "string") return "";
361
- try {
362
- return decodeURIComponent(value).trim();
363
- } catch {
364
- return value.trim();
365
- }
366
- };
367
- function parseDashboardQuery(query = {}) {
368
- const source = query || {};
369
- const page = Number.parseInt(String(source.page ?? "1"), 10);
370
- const pageSize = PAGE_SIZE_OPTIONS.includes(String(source.pageSize)) ? String(source.pageSize) : DEFAULT_PAGE_SIZE;
371
- const status = isSessionFilter(source.status) ? (
372
- /** @type {string} */
373
- source.status
374
- ) : DEFAULT_SESSION_FILTER;
375
- const reason = status === "ended" && isEndReasonFilter(source.reason) ? (
376
- /** @type {string} */
377
- source.reason
378
- ) : DEFAULT_END_REASON_FILTER;
379
- const search = readQueryText(source.search) || readQueryText(source._q);
380
- return { page: Number.isFinite(page) && page >= 1 ? page : 1, pageSize, status, reason, search };
381
- }
382
- function encodeSearchQuery(value) {
383
- const text = typeof value === "string" ? value.trim() : "";
384
- return text ? encodeURIComponent(text) : void 0;
385
- }
386
- function hasActiveFilters(state) {
387
- if (!state) return false;
388
- return state.status !== DEFAULT_SESSION_FILTER || Boolean(state.reason) && state.reason !== DEFAULT_END_REASON_FILTER || Boolean(state.search);
389
- }
390
- function getSessionUserLabels(session) {
391
- const username = presentText(session?.user?.username);
392
- const email = presentText(session?.user?.email);
393
- const primary = username || email;
394
- return {
395
- primary,
396
- secondary: username && email ? email : "",
397
- accessible: primary || presentText(session?.id)
398
- };
399
- }
400
- function getUserEditPath(session) {
401
- const documentId = presentText(session?.user?.documentId);
402
- return documentId ? `${USER_EDIT_PATH}${encodeURIComponent(documentId)}` : null;
403
- }
404
- function getExportDeviceInfo(session, unavailableValue = "") {
405
- const device = getDevicePresentation(session);
406
- return {
407
- device: device.deviceType || unavailableValue,
408
- browser: device.browser || unavailableValue,
409
- browserVersion: device.browserVersion || "",
410
- os: device.os || unavailableValue
411
- };
412
- }
413
- function readDisclosureOpen(storage) {
414
- try {
415
- return storage?.getItem(HOW_IT_WORKS_STORAGE_KEY) === "open";
416
- } catch {
417
- return false;
418
- }
419
- }
420
- function writeDisclosureOpen(storage, open) {
421
- try {
422
- storage?.setItem(HOW_IT_WORKS_STORAGE_KEY, open ? "open" : "closed");
423
- } catch {
424
- }
425
- }
426
- function getBrowserStorage() {
427
- try {
428
- return typeof window !== "undefined" ? window.localStorage : null;
429
- } catch {
430
- return null;
431
- }
432
- }
433
- function shouldIsolateActionKey(key, fromInsideGroup) {
434
- if (!fromInsideGroup) return true;
435
- return key === "Enter" || key === " " || key === "Spacebar";
436
- }
437
- const FULL_TABLE_MIN_WIDTH = 1200;
438
- function shouldUseCompactTable(listWidth, isBelowLarge) {
439
- if (isBelowLarge) return true;
440
- if (!Number.isFinite(listWidth) || listWidth <= 0) return false;
441
- return listWidth < FULL_TABLE_MIN_WIDTH;
442
- }
443
- function shouldRedispatchEscape(key, fromInsideGroup) {
444
- return !fromInsideGroup && key === "Escape";
445
- }
446
- function pickFocusSessionId(previousIds, currentIds, sessionId) {
447
- const current = Array.isArray(currentIds) ? currentIds.map(String) : [];
448
- if (current.length === 0) return null;
449
- const target = String(sessionId);
450
- if (current.includes(target)) return target;
451
- const previous = Array.isArray(previousIds) ? previousIds.map(String) : [];
452
- const index = previous.indexOf(target);
453
- if (index >= 0) {
454
- for (let next = index + 1; next < previous.length; next += 1) {
455
- if (current.includes(previous[next])) return previous[next];
456
- }
457
- for (let before = index - 1; before >= 0; before -= 1) {
458
- if (current.includes(previous[before])) return previous[before];
459
- }
460
- }
461
- return current[0];
462
- }
463
- function getErrorStatus(error) {
464
- const err = (
465
- /** @type {any} */
466
- error
467
- );
468
- const status = err?.status ?? err?.response?.status;
469
- return typeof status === "number" ? status : null;
470
- }
471
334
  const TargetLink = styled(Link)`
472
335
  min-height: 3.2rem;
473
336
  display: inline-flex;
@@ -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-CSJJn4qy.js");
10
+ const index = require("./index-Bnt0Jq6O.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;
@@ -6,7 +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 { m as logSafeAdminError, s as isCancelledRequest, b as getTranslation, R as ReadableText, M as MissingValue } from "./index-tt61o2VH.mjs";
9
+ import { l as logSafeAdminError, n as isCancelledRequest, b as getTranslation, R as ReadableText, M as MissingValue } from "./index-BmnC2BPs.mjs";
10
10
  function normalizeUserCounts(response) {
11
11
  const totalUsers = response?.data?.totalUsers;
12
12
  const blockedUsers = response?.data?.blockedUsers;