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
@@ -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-CHACmZsg.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-rbxJZcLv.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(
@@ -9,18 +9,11 @@ const styled = require("styled-components");
9
9
  const designSystem = require("@strapi/design-system");
10
10
  const icons = require("@strapi/icons");
11
11
  const symbols = require("@strapi/icons/symbols");
12
- const index = require("./index-CaLVyCio.js");
12
+ const index = require("./index-CfQOMZVX.js");
13
13
  const SectionCard = require("./SectionCard-BlWv8CRt.js");
14
14
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
15
15
  const styled__default = /* @__PURE__ */ _interopDefault(styled);
16
16
  const ANALYTICS_UNKNOWN_KEY = "unknown";
17
- function increment(target, key) {
18
- target[key] = (target[key] || 0) + 1;
19
- }
20
- function getUserKey(session) {
21
- return session?.user?.documentId || session?.user?.id || session?.user?.email || session?.user?.username || null;
22
- }
23
- const toTime = (value) => value ? Date.parse(value) : Number.NaN;
24
17
  const VERSION_TOKEN = /^v?\d[\w.]*$/i;
25
18
  function toNameBucket(value) {
26
19
  if (typeof value !== "string") return ANALYTICS_UNKNOWN_KEY;
@@ -36,22 +29,6 @@ function getDeviceBucket(session) {
36
29
  function getBrowserBucket(session) {
37
30
  return toNameBucket(session?.browserName);
38
31
  }
39
- function getSessionDurationMinutes(session, now = Date.now()) {
40
- const start = toTime(session?.loginTime);
41
- if (!Number.isFinite(start)) return null;
42
- const lastActive = toTime(session?.lastActive);
43
- const logoutTime = toTime(session?.logoutTime);
44
- let end;
45
- if (session?.isActive) {
46
- end = Number.isFinite(lastActive) ? lastActive : now;
47
- } else if (Number.isFinite(logoutTime)) {
48
- end = logoutTime;
49
- } else {
50
- end = lastActive;
51
- }
52
- if (!Number.isFinite(end)) return null;
53
- return Math.max(0, Math.floor((end - start) / 6e4));
54
- }
55
32
  function getAnalyticsBarRows(counts) {
56
33
  const entries = Object.entries(counts || {}).filter(
57
34
  ([, count]) => Number.isFinite(count) && count > 0
@@ -67,49 +44,50 @@ function getAnalyticsBarRows(counts) {
67
44
  percent: Math.max(0, Math.min(100, Math.round(count / max * 100)))
68
45
  }));
69
46
  }
70
- function computeSessionAnalytics(sessions = [], { now = Date.now() } = {}) {
71
- const rows = Array.isArray(sessions) ? sessions : [];
72
- const dayAgo = now - 24 * 60 * 60 * 1e3;
73
- const weekAgo = now - 7 * 24 * 60 * 60 * 1e3;
74
- const devices = {};
75
- const browsers = {};
76
- const uniqueUsers = /* @__PURE__ */ new Set();
77
- const durations = [];
78
- let activeSessions = 0;
79
- let idleSessions = 0;
80
- let endedSessions = 0;
81
- let signInsLast24Hours = 0;
82
- let signInsLast7Days = 0;
83
- for (const session of rows) {
84
- const loginTime = toTime(session?.loginTime);
85
- if (Number.isFinite(loginTime)) {
86
- if (loginTime > dayAgo) signInsLast24Hours++;
87
- if (loginTime > weekAgo) signInsLast7Days++;
88
- }
89
- if (session?.isActive) {
90
- if (session.isTrulyActive) activeSessions++;
91
- else idleSessions++;
92
- } else {
93
- endedSessions++;
47
+ function mergeGroups(groups, bucket) {
48
+ const out = {};
49
+ for (const group of Array.isArray(groups) ? groups : []) {
50
+ const count = Number(group?.count);
51
+ if (!Number.isInteger(count) || count <= 0) continue;
52
+ const key = bucket(group?.value ?? null);
53
+ out[key] = (out[key] || 0) + count;
54
+ }
55
+ return out;
56
+ }
57
+ function analyticsFromServer(payload) {
58
+ const data = (
59
+ /** @type {any} */
60
+ payload?.data
61
+ );
62
+ const counts = [
63
+ "totalSessions",
64
+ "activeSessions",
65
+ "idleSessions",
66
+ "endedSessions",
67
+ "signInsLast24Hours",
68
+ "signInsLast7Days",
69
+ "uniqueUsers",
70
+ "avgSessionDuration"
71
+ ];
72
+ for (const key of counts) {
73
+ if (!Number.isInteger(data?.[key]) || data[key] < 0) {
74
+ throw new Error("Invalid session analytics response");
94
75
  }
95
- increment(devices, getDeviceBucket(session));
96
- increment(browsers, getBrowserBucket(session));
97
- const userKey = getUserKey(session);
98
- if (userKey) uniqueUsers.add(userKey);
99
- const duration = getSessionDurationMinutes(session, now);
100
- if (duration !== null) durations.push(duration);
76
+ }
77
+ if (!Array.isArray(data.devices) || !Array.isArray(data.browsers)) {
78
+ throw new Error("Invalid session analytics response");
101
79
  }
102
80
  return {
103
- totalSessions: rows.length,
104
- activeSessions,
105
- idleSessions,
106
- endedSessions,
107
- signInsLast24Hours,
108
- signInsLast7Days,
109
- devices,
110
- browsers,
111
- uniqueUsers: uniqueUsers.size,
112
- avgSessionDuration: durations.length > 0 ? Math.floor(durations.reduce((sum, duration) => sum + duration, 0) / durations.length) : 0
81
+ totalSessions: data.totalSessions,
82
+ activeSessions: data.activeSessions,
83
+ idleSessions: data.idleSessions,
84
+ endedSessions: data.endedSessions,
85
+ signInsLast24Hours: data.signInsLast24Hours,
86
+ signInsLast7Days: data.signInsLast7Days,
87
+ devices: mergeGroups(data.devices, (value) => getDeviceBucket({ deviceType: value })),
88
+ browsers: mergeGroups(data.browsers, (value) => getBrowserBucket({ browserName: value })),
89
+ uniqueUsers: data.uniqueUsers,
90
+ avgSessionDuration: data.avgSessionDuration
113
91
  };
114
92
  }
115
93
  const BAR_ROW_INLINE_REM = 24;
@@ -197,7 +175,6 @@ const AnalyticsPage = () => {
197
175
  const [loading, setLoading] = react.useState(true);
198
176
  const [refreshing, setRefreshing] = react.useState(false);
199
177
  const [analytics, setAnalytics] = react.useState(null);
200
- const [truncated, setTruncated] = react.useState(false);
201
178
  const [updatedAt, setUpdatedAt] = react.useState(null);
202
179
  const [loadError, setLoadError] = react.useState(false);
203
180
  const [forbidden, setForbidden] = react.useState(false);
@@ -206,10 +183,8 @@ const AnalyticsPage = () => {
206
183
  if (requestPendingRef.current) return;
207
184
  requestPendingRef.current = true;
208
185
  try {
209
- const { data } = await get(`/${index.pluginId}/sessions`);
210
- const sessions = index.requireSessionList(data);
211
- setAnalytics(computeSessionAnalytics(sessions));
212
- setTruncated(data?.meta?.truncated === true);
186
+ const { data } = await get(`/${index.pluginId}/sessions/analytics`);
187
+ setAnalytics(analyticsFromServer(data));
213
188
  setUpdatedAt(Date.now());
214
189
  setLoadError(false);
215
190
  } catch (err) {
@@ -241,7 +216,7 @@ const AnalyticsPage = () => {
241
216
  const subtitle = analytics ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "epsilon", textColor: "neutral600", tag: "p", children: [
242
217
  t(
243
218
  "analytics.subtitle",
244
- "{count, plural, =0 {No sessions are loaded yet.} one {Based on the latest # loaded session.} other {Based on the latest # loaded sessions.}}",
219
+ "{count, plural, =0 {No sessions yet.} one {Based on all # session.} other {Based on all # sessions.}}",
245
220
  { count: totalSessions }
246
221
  ),
247
222
  updatedAt ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
@@ -302,11 +277,6 @@ const AnalyticsPage = () => {
302
277
  primaryAction: headerActions,
303
278
  children: [
304
279
  errorAlert,
305
- truncated ? /* @__PURE__ */ jsxRuntime.jsx(index.PersistentAlert, { variant: "default", closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "omega", textColor: "neutral800", tag: "span", children: t(
306
- "analytics.truncated",
307
- "Only the latest {count, number} sessions are loaded. Counts, filters and exports cover these sessions only.",
308
- { count: totalSessions }
309
- ) }) }) : null,
310
280
  hasSessions ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
311
281
  /* @__PURE__ */ jsxRuntime.jsxs(index.StatGrid, { label: t("analytics.stats.label", "Session overview"), alignValues: true, children: [
312
282
  /* @__PURE__ */ jsxRuntime.jsx(