strapi-plugin-magic-sessionmanager 4.11.0 → 4.13.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 (32) hide show
  1. package/CHANGELOG.md +84 -1
  2. package/README.md +75 -24
  3. package/dist/admin/{Analytics-CBHeWeGn.js → Analytics-BikQQx_J.js} +45 -75
  4. package/dist/admin/{Analytics-D56O8Q6e.mjs → Analytics-DIY51RI_.mjs} +45 -75
  5. package/dist/admin/{App-EDIkLJdb.mjs → App-B3vaybSO.mjs} +584 -120
  6. package/dist/admin/{App-D4cBPwB_.js → App-BV1LM9Bp.js} +584 -120
  7. package/dist/admin/{OnlineUsersWidget-MwUutkKQ.mjs → OnlineUsersWidget-T-2upsDd.mjs} +18 -26
  8. package/dist/admin/{OnlineUsersWidget-BF2R2YIy.js → OnlineUsersWidget-fJogM1xl.js} +18 -26
  9. package/dist/admin/{Settings-CMzEF8EH.js → Settings-AyYka8wn.js} +1 -1
  10. package/dist/admin/{Settings-bLMyi0BN.mjs → Settings-BpBlXyMY.mjs} +1 -1
  11. package/dist/admin/{de-CxfuTF6C.mjs → de-BSCDuq1i.mjs} +41 -6
  12. package/dist/admin/{de-DVNTHmSo.js → de-z0aHRwdw.js} +41 -6
  13. package/dist/admin/{en-BcPIlQYL.mjs → en-B4Cuq9JN.mjs} +41 -6
  14. package/dist/admin/{en-BuVXIcHA.js → en-BWPOiiMt.js} +41 -6
  15. package/dist/admin/{es-CEteHmBO.js → es-CMskkUh-.js} +41 -6
  16. package/dist/admin/{es-DxHpaNA1.mjs → es-DBAmysKi.mjs} +41 -6
  17. package/dist/admin/{fr-Dw43lHg7.mjs → fr-BNGdtjEl.mjs} +41 -6
  18. package/dist/admin/{fr-BMd2-wW7.js → fr-ClJ2BkrE.js} +41 -6
  19. package/dist/admin/{index-DvNfekoR.js → index-DyE1rLW0.js} +22 -56
  20. package/dist/admin/{index-qa6Qnfkc.mjs → index-mCVi1j7e.mjs} +48 -82
  21. package/dist/admin/index.js +1 -1
  22. package/dist/admin/index.mjs +2 -2
  23. package/dist/admin/{pt-BvO63p01.js → pt-CRh_J7JS.js} +41 -6
  24. package/dist/admin/{pt-7jnxDSX-.mjs → pt-Cl7TWsOV.mjs} +41 -6
  25. package/dist/server/index.js +1495 -51
  26. package/dist/server/index.mjs +1495 -51
  27. package/package.json +10 -2
  28. package/pics/untracked-confirm-dialog.webp +0 -0
  29. package/pics/untracked-disclosure-warning-dark.webp +0 -0
  30. package/pics/untracked-disclosure-warning.webp +0 -0
  31. package/pics/untracked-mobile-notice-warning.webp +0 -0
  32. package/pics/untracked-notice-neutral.webp +0 -0
@@ -7,16 +7,9 @@ import styled from "styled-components";
7
7
  import { Typography, Flex, LinkButton, Button, EmptyStateLayout, VisuallyHidden } from "@strapi/design-system";
8
8
  import { ArrowClockwise, ChartBubble, User, Clock, Calendar } from "@strapi/icons";
9
9
  import { EmptyDocuments } from "@strapi/icons/symbols";
10
- import { N as normalizeDeviceType, u as useSessionFormatters, m as pluginId, s as requireSessionList, n as logSafeAdminError, o as PersistentAlert, R as ReadableText, z as PageShell, A as StatGrid, B as StatCard, I as EqualGrid, b as getTranslation, O as getDeviceTypeMessage } from "./index-qa6Qnfkc.mjs";
10
+ import { J as normalizeDeviceType, u as useSessionFormatters, l as pluginId, m as logSafeAdminError, n as PersistentAlert, R as ReadableText, v as PageShell, w as StatGrid, x as StatCard, F as EqualGrid, b as getTranslation, K as getDeviceTypeMessage } from "./index-mCVi1j7e.mjs";
11
11
  import { S as SectionCard } from "./SectionCard-D51bv4Hi.mjs";
12
12
  const ANALYTICS_UNKNOWN_KEY = "unknown";
13
- function increment(target, key) {
14
- target[key] = (target[key] || 0) + 1;
15
- }
16
- function getUserKey(session) {
17
- return session?.user?.documentId || session?.user?.id || session?.user?.email || session?.user?.username || null;
18
- }
19
- const toTime = (value) => value ? Date.parse(value) : Number.NaN;
20
13
  const VERSION_TOKEN = /^v?\d[\w.]*$/i;
21
14
  function toNameBucket(value) {
22
15
  if (typeof value !== "string") return ANALYTICS_UNKNOWN_KEY;
@@ -32,22 +25,6 @@ function getDeviceBucket(session) {
32
25
  function getBrowserBucket(session) {
33
26
  return toNameBucket(session?.browserName);
34
27
  }
35
- function getSessionDurationMinutes(session, now = Date.now()) {
36
- const start = toTime(session?.loginTime);
37
- if (!Number.isFinite(start)) return null;
38
- const lastActive = toTime(session?.lastActive);
39
- const logoutTime = toTime(session?.logoutTime);
40
- let end;
41
- if (session?.isActive) {
42
- end = Number.isFinite(lastActive) ? lastActive : now;
43
- } else if (Number.isFinite(logoutTime)) {
44
- end = logoutTime;
45
- } else {
46
- end = lastActive;
47
- }
48
- if (!Number.isFinite(end)) return null;
49
- return Math.max(0, Math.floor((end - start) / 6e4));
50
- }
51
28
  function getAnalyticsBarRows(counts) {
52
29
  const entries = Object.entries(counts || {}).filter(
53
30
  ([, count]) => Number.isFinite(count) && count > 0
@@ -63,49 +40,50 @@ function getAnalyticsBarRows(counts) {
63
40
  percent: Math.max(0, Math.min(100, Math.round(count / max * 100)))
64
41
  }));
65
42
  }
66
- function computeSessionAnalytics(sessions = [], { now = Date.now() } = {}) {
67
- const rows = Array.isArray(sessions) ? sessions : [];
68
- const dayAgo = now - 24 * 60 * 60 * 1e3;
69
- const weekAgo = now - 7 * 24 * 60 * 60 * 1e3;
70
- const devices = {};
71
- const browsers = {};
72
- const uniqueUsers = /* @__PURE__ */ new Set();
73
- const durations = [];
74
- let activeSessions = 0;
75
- let idleSessions = 0;
76
- let endedSessions = 0;
77
- let signInsLast24Hours = 0;
78
- let signInsLast7Days = 0;
79
- for (const session of rows) {
80
- const loginTime = toTime(session?.loginTime);
81
- if (Number.isFinite(loginTime)) {
82
- if (loginTime > dayAgo) signInsLast24Hours++;
83
- if (loginTime > weekAgo) signInsLast7Days++;
84
- }
85
- if (session?.isActive) {
86
- if (session.isTrulyActive) activeSessions++;
87
- else idleSessions++;
88
- } else {
89
- endedSessions++;
43
+ function mergeGroups(groups, bucket) {
44
+ const out = {};
45
+ for (const group of Array.isArray(groups) ? groups : []) {
46
+ const count = Number(group?.count);
47
+ if (!Number.isInteger(count) || count <= 0) continue;
48
+ const key = bucket(group?.value ?? null);
49
+ out[key] = (out[key] || 0) + count;
50
+ }
51
+ return out;
52
+ }
53
+ function analyticsFromServer(payload) {
54
+ const data = (
55
+ /** @type {any} */
56
+ payload?.data
57
+ );
58
+ const counts = [
59
+ "totalSessions",
60
+ "activeSessions",
61
+ "idleSessions",
62
+ "endedSessions",
63
+ "signInsLast24Hours",
64
+ "signInsLast7Days",
65
+ "uniqueUsers",
66
+ "avgSessionDuration"
67
+ ];
68
+ for (const key of counts) {
69
+ if (!Number.isInteger(data?.[key]) || data[key] < 0) {
70
+ throw new Error("Invalid session analytics response");
90
71
  }
91
- increment(devices, getDeviceBucket(session));
92
- increment(browsers, getBrowserBucket(session));
93
- const userKey = getUserKey(session);
94
- if (userKey) uniqueUsers.add(userKey);
95
- const duration = getSessionDurationMinutes(session, now);
96
- if (duration !== null) durations.push(duration);
72
+ }
73
+ if (!Array.isArray(data.devices) || !Array.isArray(data.browsers)) {
74
+ throw new Error("Invalid session analytics response");
97
75
  }
98
76
  return {
99
- totalSessions: rows.length,
100
- activeSessions,
101
- idleSessions,
102
- endedSessions,
103
- signInsLast24Hours,
104
- signInsLast7Days,
105
- devices,
106
- browsers,
107
- uniqueUsers: uniqueUsers.size,
108
- avgSessionDuration: durations.length > 0 ? Math.floor(durations.reduce((sum, duration) => sum + duration, 0) / durations.length) : 0
77
+ totalSessions: data.totalSessions,
78
+ activeSessions: data.activeSessions,
79
+ idleSessions: data.idleSessions,
80
+ endedSessions: data.endedSessions,
81
+ signInsLast24Hours: data.signInsLast24Hours,
82
+ signInsLast7Days: data.signInsLast7Days,
83
+ devices: mergeGroups(data.devices, (value) => getDeviceBucket({ deviceType: value })),
84
+ browsers: mergeGroups(data.browsers, (value) => getBrowserBucket({ browserName: value })),
85
+ uniqueUsers: data.uniqueUsers,
86
+ avgSessionDuration: data.avgSessionDuration
109
87
  };
110
88
  }
111
89
  const BAR_ROW_INLINE_REM = 24;
@@ -193,7 +171,6 @@ const AnalyticsPage = () => {
193
171
  const [loading, setLoading] = useState(true);
194
172
  const [refreshing, setRefreshing] = useState(false);
195
173
  const [analytics, setAnalytics] = useState(null);
196
- const [truncated, setTruncated] = useState(false);
197
174
  const [updatedAt, setUpdatedAt] = useState(null);
198
175
  const [loadError, setLoadError] = useState(false);
199
176
  const [forbidden, setForbidden] = useState(false);
@@ -202,10 +179,8 @@ const AnalyticsPage = () => {
202
179
  if (requestPendingRef.current) return;
203
180
  requestPendingRef.current = true;
204
181
  try {
205
- const { data } = await get(`/${pluginId}/sessions`);
206
- const sessions = requireSessionList(data);
207
- setAnalytics(computeSessionAnalytics(sessions));
208
- setTruncated(data?.meta?.truncated === true);
182
+ const { data } = await get(`/${pluginId}/sessions/analytics`);
183
+ setAnalytics(analyticsFromServer(data));
209
184
  setUpdatedAt(Date.now());
210
185
  setLoadError(false);
211
186
  } catch (err) {
@@ -237,7 +212,7 @@ const AnalyticsPage = () => {
237
212
  const subtitle = analytics ? /* @__PURE__ */ jsxs(Typography, { variant: "epsilon", textColor: "neutral600", tag: "p", children: [
238
213
  t(
239
214
  "analytics.subtitle",
240
- "{count, plural, =0 {No sessions are loaded yet.} one {Based on the latest # loaded session.} other {Based on the latest # loaded sessions.}}",
215
+ "{count, plural, =0 {No sessions yet.} one {Based on all # session.} other {Based on all # sessions.}}",
241
216
  { count: totalSessions }
242
217
  ),
243
218
  updatedAt ? /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -298,11 +273,6 @@ const AnalyticsPage = () => {
298
273
  primaryAction: headerActions,
299
274
  children: [
300
275
  errorAlert,
301
- truncated ? /* @__PURE__ */ jsx(PersistentAlert, { variant: "default", closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral800", tag: "span", children: t(
302
- "analytics.truncated",
303
- "Only the latest {count, number} sessions are loaded. Counts, filters and exports cover these sessions only.",
304
- { count: totalSessions }
305
- ) }) }) : null,
306
276
  hasSessions ? /* @__PURE__ */ jsxs(Fragment, { children: [
307
277
  /* @__PURE__ */ jsxs(StatGrid, { label: t("analytics.stats.label", "Session overview"), alignValues: true, children: [
308
278
  /* @__PURE__ */ jsx(