strapi-plugin-magic-sessionmanager 4.6.4 → 4.7.1

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 (33) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +15 -8
  3. package/dist/admin/{Analytics-B5IR0Awr.mjs → Analytics-CsrpxJwQ.mjs} +90 -69
  4. package/dist/admin/{Analytics-BJlc-yE3.js → Analytics-D03ZNNMR.js} +90 -69
  5. package/dist/admin/{App-DisCm99X.js → App-B2VCS3cz.js} +22 -27
  6. package/dist/admin/{App-BEniJePD.mjs → App-qxKnK7G2.mjs} +9 -14
  7. package/dist/admin/{License-BjP7GvCt.mjs → License-ClW7sZLR.mjs} +1 -1
  8. package/dist/admin/{License-DqDBPjZH.js → License-fixnQ7wF.js} +1 -1
  9. package/dist/admin/{OnlineUsersWidget-Cm9O0Fjb.mjs → OnlineUsersWidget-mR_OMiwi.mjs} +1 -2
  10. package/dist/admin/{OnlineUsersWidget-DXdeGmfV.js → OnlineUsersWidget-qb9utPBy.js} +1 -2
  11. package/dist/admin/{Settings-CnO501iu.mjs → Settings-U3V4eGMo.mjs} +10 -5
  12. package/dist/admin/{Settings-DoLec2MD.js → Settings-gv2BF54w.js} +10 -5
  13. package/dist/admin/{de-DjP2WJ_V.js → de-BnqGCokx.js} +6 -5
  14. package/dist/admin/{de-6rIvkYOp.mjs → de-JBE-iylO.mjs} +6 -5
  15. package/dist/admin/{en-0pesBbOT.js → en-BRmVwd8-.js} +6 -5
  16. package/dist/admin/{en-8hiv31Dv.mjs → en-kQWtdEai.mjs} +6 -5
  17. package/dist/admin/{es-DdBRpF7F.js → es-CH691xcL.js} +6 -5
  18. package/dist/admin/{es-LRQ148f5.mjs → es-DOQvBxih.mjs} +6 -5
  19. package/dist/admin/{fr-DJ6DbeDy.js → fr-CLExO0w_.js} +6 -5
  20. package/dist/admin/{fr-CKhx_qil.mjs → fr-CmfCpepX.mjs} +6 -5
  21. package/dist/admin/{index-CpMDG2XI.mjs → index-B_lFjUAg.mjs} +15 -15
  22. package/dist/admin/{index-DJHhzin_.js → index-Duc7cR_d.js} +15 -15
  23. package/dist/admin/index.js +1 -1
  24. package/dist/admin/index.mjs +1 -1
  25. package/dist/admin/{pt-D0SMoAmo.js → pt-BJ_F0yNi.js} +6 -5
  26. package/dist/admin/{pt-DXizUvcj.mjs → pt-BSzZdyAH.mjs} +6 -5
  27. package/dist/admin/sessionStatus-D_fWEzgj.js +11 -0
  28. package/dist/admin/sessionStatus-kwggjEMw.mjs +12 -0
  29. package/dist/server/index.js +708 -349
  30. package/dist/server/index.mjs +708 -349
  31. package/package.json +8 -8
  32. package/scripts/geoip-updater.cjs +39 -4
  33. package/scripts/update-geoip-db.mjs +1 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## [4.7.1](https://github.com/Schero94/Magic-Sessionmanager/compare/v4.7.0...v4.7.1) (2026-07-10)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * harden session lifecycle and admin analytics ([8f32862](https://github.com/Schero94/Magic-Sessionmanager/commit/8f328626460988b1c75a10e580ad300bc81ccb0b))
7
+
8
+ # [4.7.0](https://github.com/Schero94/Magic-Sessionmanager/compare/v4.6.4...v4.7.0) (2026-07-09)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * define analytics float animation ([e248680](https://github.com/Schero94/Magic-Sessionmanager/commit/e248680989e68b4cf082d50b565e978ce50d316d))
14
+
15
+
16
+ ### Features
17
+
18
+ * support local GeoLite2 City database ([298d2a0](https://github.com/Schero94/Magic-Sessionmanager/commit/298d2a0948dd1a08f06ee70ada3953ed7d4dd2e6))
19
+
1
20
  ## [4.6.4](https://github.com/Schero94/Magic-Sessionmanager/compare/v4.6.3...v4.6.4) (2026-07-09)
2
21
 
3
22
 
package/README.md CHANGED
@@ -283,17 +283,21 @@ Add to `config/plugins.ts`:
283
283
 
284
284
  ### Local GeoIP Firewall (Recommended)
285
285
 
286
- For login blocking, use a local MaxMind GeoLite2 Country database. This avoids
287
- remote API timeouts and rate limits in the login path.
286
+ For login blocking and city-level session display, use a local MaxMind
287
+ GeoLite2 City database. This avoids remote API timeouts and rate limits in the
288
+ login path while still giving the admin UI city, region, timezone and
289
+ coordinates. Existing GeoLite2 Country databases remain supported as a
290
+ country-only fallback.
288
291
 
289
- 1. Create a free MaxMind account and download `GeoLite2-Country.mmdb`:
292
+ 1. Create a free MaxMind account and download `GeoLite2-City.mmdb`:
290
293
  https://dev.maxmind.com/geoip/geolite2-free-geolocation-data/
291
294
  2. Store the file on your Strapi server, for example:
292
- `/var/lib/strapi/GeoLite2-Country.mmdb`
295
+ `/var/lib/strapi/GeoLite2-City.mmdb`
293
296
  3. Configure the plugin:
294
297
 
295
298
  ```bash
296
- MAGIC_SESSIONMANAGER_GEOIP_DATABASE=/var/lib/strapi/GeoLite2-Country.mmdb
299
+ MAGIC_SESSIONMANAGER_GEOIP_DATABASE=/var/lib/strapi/GeoLite2-City.mmdb
300
+ MAXMIND_EDITION_ID=GeoLite2-City
297
301
  MAXMIND_ACCOUNT_ID=your-account-id
298
302
  MAXMIND_LICENSE_KEY=your-license-key
299
303
  ```
@@ -311,6 +315,7 @@ Strapi plugin store instead):
311
315
  ```bash
312
316
  export MAXMIND_ACCOUNT_ID=your_account_id
313
317
  export MAXMIND_LICENSE_KEY=your_license_key
318
+ export MAXMIND_EDITION_ID=GeoLite2-City
314
319
  npm run geoip:update
315
320
  ```
316
321
 
@@ -352,9 +357,11 @@ Provider options:
352
357
  - `ipapi`: legacy remote provider
353
358
  - `disabled`: no GEOIP lookup
354
359
 
355
- Country firewall rules use the local database. VPN/proxy/threat detection still
356
- requires a provider that supplies those risk signals; a free country database
357
- does not reliably identify VPNs or proxies.
360
+ Local City and Country databases both support country firewall rules. City
361
+ databases additionally populate city, region, timezone, coordinates and postal
362
+ data for the admin UI. VPN/proxy/threat detection still requires a provider
363
+ that supplies those risk signals; free GeoLite databases do not reliably
364
+ identify VPNs or proxies.
358
365
 
359
366
  ### Threat Detection
360
367
 
@@ -4,7 +4,91 @@ import { useFetchClient } from "@strapi/strapi/admin";
4
4
  import styled, { css, keyframes } from "styled-components";
5
5
  import { Loader, Flex, Box, Badge, Typography } from "@strapi/design-system";
6
6
  import { ChartBubble, User, Clock, Monitor } from "@strapi/icons";
7
- import { a as pluginId } from "./index-CpMDG2XI.mjs";
7
+ import { a as pluginId } from "./index-B_lFjUAg.mjs";
8
+ import { g as getSessionStatus } from "./sessionStatus-kwggjEMw.mjs";
9
+ function increment(target, key) {
10
+ target[key] = (target[key] || 0) + 1;
11
+ }
12
+ function getUserKey(session) {
13
+ return session?.user?.documentId || session?.user?.id || session?.user?.email || session?.user?.username || null;
14
+ }
15
+ function getDurationMinutes(session, now) {
16
+ const start = Date.parse(session?.loginTime);
17
+ if (!Number.isFinite(start)) return null;
18
+ const endValue = session.logoutTime || session.lastActive;
19
+ const end = endValue ? Date.parse(endValue) : now;
20
+ if (!Number.isFinite(end)) return null;
21
+ return Math.max(0, Math.floor((end - start) / 6e4));
22
+ }
23
+ function computeSessionAnalytics(sessions = [], { now = Date.now() } = {}) {
24
+ const dayAgo = now - 24 * 60 * 60 * 1e3;
25
+ const weekAgo = now - 7 * 24 * 60 * 60 * 1e3;
26
+ const devices = {};
27
+ const browsers = {};
28
+ const operatingSystems = {};
29
+ const loginHours = Array(24).fill(0);
30
+ const uniqueUsers = /* @__PURE__ */ new Set();
31
+ const uniqueIPs = /* @__PURE__ */ new Set();
32
+ const durations = [];
33
+ let todayLogins = 0;
34
+ let weekLogins = 0;
35
+ let loggedOut = 0;
36
+ let terminated = 0;
37
+ for (const session of sessions) {
38
+ const ua = String(session?.userAgent || "").toLowerCase();
39
+ const loginTime = Date.parse(session?.loginTime);
40
+ if (Number.isFinite(loginTime)) {
41
+ if (loginTime > dayAgo) todayLogins++;
42
+ if (loginTime > weekAgo) weekLogins++;
43
+ loginHours[new Date(loginTime).getHours()]++;
44
+ }
45
+ if (ua.includes("tablet") || ua.includes("ipad") || ua.includes("android") && !ua.includes("mobile")) {
46
+ increment(devices, "Tablet");
47
+ } else if (ua.includes("mobile") || ua.includes("android") || ua.includes("iphone")) {
48
+ increment(devices, "Mobile");
49
+ } else {
50
+ increment(devices, "Desktop");
51
+ }
52
+ if (ua.includes("edg")) increment(browsers, "Edge");
53
+ else if (ua.includes("chrome")) increment(browsers, "Chrome");
54
+ else if (ua.includes("firefox")) increment(browsers, "Firefox");
55
+ else if (ua.includes("safari")) increment(browsers, "Safari");
56
+ else if (ua.includes("postman") || ua.includes("curl")) increment(browsers, "API Client");
57
+ else increment(browsers, "Other");
58
+ if (ua.includes("android")) increment(operatingSystems, "Android");
59
+ else if (ua.includes("ios") || ua.includes("iphone") || ua.includes("ipad")) increment(operatingSystems, "iOS");
60
+ else if (ua.includes("windows") || ua.includes("win32") || ua.includes("win64")) increment(operatingSystems, "Windows");
61
+ else if (ua.includes("mac") || ua.includes("darwin")) increment(operatingSystems, "macOS");
62
+ else if (ua.includes("linux")) increment(operatingSystems, "Linux");
63
+ else increment(operatingSystems, "Other");
64
+ const userKey = getUserKey(session);
65
+ if (userKey) uniqueUsers.add(userKey);
66
+ if (session?.ipAddress) uniqueIPs.add(session.ipAddress);
67
+ const status = getSessionStatus(session);
68
+ if (status === "loggedout") loggedOut++;
69
+ else if (!session?.isActive && status === "terminated") terminated++;
70
+ const duration = getDurationMinutes(session, now);
71
+ if (duration !== null) durations.push(duration);
72
+ }
73
+ const mobileCount = (devices.Mobile || 0) + (devices.Tablet || 0);
74
+ return {
75
+ totalSessions: sessions.length,
76
+ activeSessions: sessions.filter((session) => session?.isActive && session?.isTrulyActive).length,
77
+ todayLogins,
78
+ weekLogins,
79
+ devices,
80
+ browsers,
81
+ operatingSystems,
82
+ loginHours,
83
+ peakHour: loginHours.indexOf(Math.max(...loginHours)),
84
+ uniqueUsers: uniqueUsers.size,
85
+ uniqueIPs: uniqueIPs.size,
86
+ loggedOut,
87
+ terminated,
88
+ mobileRatio: sessions.length > 0 ? Math.round(mobileCount / sessions.length * 100) : 0,
89
+ avgSessionDuration: durations.length > 0 ? Math.floor(durations.reduce((sum, duration) => sum + duration, 0) / durations.length) : 0
90
+ };
91
+ }
8
92
  const theme = {
9
93
  shadows: {
10
94
  sm: "0 1px 3px 0 rgba(0, 0, 0, 0.1)",
@@ -35,6 +119,10 @@ const pulse = keyframes`
35
119
  0%, 100% { opacity: 1; }
36
120
  50% { opacity: 0.8; }
37
121
  `;
122
+ const float = keyframes`
123
+ 0%, 100% { transform: translateY(0px); }
124
+ 50% { transform: translateY(-5px); }
125
+ `;
38
126
  const growBar = keyframes`
39
127
  from { width: 0; }
40
128
  to { width: var(--bar-width); }
@@ -276,74 +364,7 @@ const AnalyticsPage = () => {
276
364
  try {
277
365
  const { data } = await get(`/${pluginId}/sessions`);
278
366
  const sessions = data.data || [];
279
- const now = Date.now();
280
- const dayAgo = now - 24 * 60 * 60 * 1e3;
281
- const weekAgo = now - 7 * 24 * 60 * 60 * 1e3;
282
- const todayLogins = sessions.filter((s) => new Date(s.loginTime).getTime() > dayAgo);
283
- const weekLogins = sessions.filter((s) => new Date(s.loginTime).getTime() > weekAgo);
284
- const devices = {};
285
- const browsers = {};
286
- const operatingSystems = {};
287
- const countries = {};
288
- const loginHours = Array(24).fill(0);
289
- const uniqueUsers = /* @__PURE__ */ new Set();
290
- const uniqueIPs = /* @__PURE__ */ new Set();
291
- sessions.forEach((session) => {
292
- const ua = session.userAgent.toLowerCase();
293
- if (ua.includes("mobile") || ua.includes("android") || ua.includes("iphone")) {
294
- devices["Mobile"] = (devices["Mobile"] || 0) + 1;
295
- } else if (ua.includes("tablet") || ua.includes("ipad")) {
296
- devices["Tablet"] = (devices["Tablet"] || 0) + 1;
297
- } else {
298
- devices["Desktop"] = (devices["Desktop"] || 0) + 1;
299
- }
300
- if (ua.includes("chrome") && !ua.includes("edg")) browsers["Chrome"] = (browsers["Chrome"] || 0) + 1;
301
- else if (ua.includes("firefox")) browsers["Firefox"] = (browsers["Firefox"] || 0) + 1;
302
- else if (ua.includes("safari") && !ua.includes("chrome")) browsers["Safari"] = (browsers["Safari"] || 0) + 1;
303
- else if (ua.includes("edg")) browsers["Edge"] = (browsers["Edge"] || 0) + 1;
304
- else if (ua.includes("postman") || ua.includes("curl")) browsers["API Client"] = (browsers["API Client"] || 0) + 1;
305
- else browsers["Other"] = (browsers["Other"] || 0) + 1;
306
- if (ua.includes("windows") || ua.includes("win32") || ua.includes("win64")) {
307
- operatingSystems["Windows"] = (operatingSystems["Windows"] || 0) + 1;
308
- } else if (ua.includes("mac") || ua.includes("darwin")) {
309
- operatingSystems["macOS"] = (operatingSystems["macOS"] || 0) + 1;
310
- } else if (ua.includes("linux")) {
311
- operatingSystems["Linux"] = (operatingSystems["Linux"] || 0) + 1;
312
- } else if (ua.includes("android")) {
313
- operatingSystems["Android"] = (operatingSystems["Android"] || 0) + 1;
314
- } else if (ua.includes("ios") || ua.includes("iphone") || ua.includes("ipad")) {
315
- operatingSystems["iOS"] = (operatingSystems["iOS"] || 0) + 1;
316
- } else {
317
- operatingSystems["Other"] = (operatingSystems["Other"] || 0) + 1;
318
- }
319
- const loginHour = new Date(session.loginTime).getHours();
320
- loginHours[loginHour]++;
321
- if (session.user?.id) uniqueUsers.add(session.user.id);
322
- if (session.ipAddress) uniqueIPs.add(session.ipAddress);
323
- });
324
- const peakHour = loginHours.indexOf(Math.max(...loginHours));
325
- const loggedOut = sessions.filter((s) => !s.isActive && s.logoutTime).length;
326
- const terminated = sessions.filter((s) => !s.isActive && !s.logoutTime).length;
327
- const mobileCount = (devices["Mobile"] || 0) + (devices["Tablet"] || 0);
328
- const desktopCount = devices["Desktop"] || 0;
329
- const mobileRatio = sessions.length > 0 ? Math.round(mobileCount / sessions.length * 100) : 0;
330
- setAnalytics({
331
- totalSessions: sessions.length,
332
- activeSessions: sessions.filter((s) => s.isActive && s.isTrulyActive).length,
333
- todayLogins: todayLogins.length,
334
- weekLogins: weekLogins.length,
335
- devices,
336
- browsers,
337
- operatingSystems,
338
- loginHours,
339
- peakHour,
340
- uniqueUsers: uniqueUsers.size,
341
- uniqueIPs: uniqueIPs.size,
342
- loggedOut,
343
- terminated,
344
- mobileRatio,
345
- avgSessionDuration: sessions.length > 0 ? Math.floor(sessions.reduce((sum, s) => sum + (s.minutesSinceActive || 0), 0) / sessions.length) : 0
346
- });
367
+ setAnalytics(computeSessionAnalytics(sessions));
347
368
  } catch (err) {
348
369
  console.error("[Analytics] Error:", err);
349
370
  } finally {
@@ -6,9 +6,93 @@ const admin = require("@strapi/strapi/admin");
6
6
  const styled = require("styled-components");
7
7
  const designSystem = require("@strapi/design-system");
8
8
  const icons = require("@strapi/icons");
9
- const index = require("./index-DJHhzin_.js");
9
+ const index = require("./index-Duc7cR_d.js");
10
+ const sessionStatus = require("./sessionStatus-D_fWEzgj.js");
10
11
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
11
12
  const styled__default = /* @__PURE__ */ _interopDefault(styled);
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
+ function getDurationMinutes(session, now) {
20
+ const start = Date.parse(session?.loginTime);
21
+ if (!Number.isFinite(start)) return null;
22
+ const endValue = session.logoutTime || session.lastActive;
23
+ const end = endValue ? Date.parse(endValue) : now;
24
+ if (!Number.isFinite(end)) return null;
25
+ return Math.max(0, Math.floor((end - start) / 6e4));
26
+ }
27
+ function computeSessionAnalytics(sessions = [], { now = Date.now() } = {}) {
28
+ const dayAgo = now - 24 * 60 * 60 * 1e3;
29
+ const weekAgo = now - 7 * 24 * 60 * 60 * 1e3;
30
+ const devices = {};
31
+ const browsers = {};
32
+ const operatingSystems = {};
33
+ const loginHours = Array(24).fill(0);
34
+ const uniqueUsers = /* @__PURE__ */ new Set();
35
+ const uniqueIPs = /* @__PURE__ */ new Set();
36
+ const durations = [];
37
+ let todayLogins = 0;
38
+ let weekLogins = 0;
39
+ let loggedOut = 0;
40
+ let terminated = 0;
41
+ for (const session of sessions) {
42
+ const ua = String(session?.userAgent || "").toLowerCase();
43
+ const loginTime = Date.parse(session?.loginTime);
44
+ if (Number.isFinite(loginTime)) {
45
+ if (loginTime > dayAgo) todayLogins++;
46
+ if (loginTime > weekAgo) weekLogins++;
47
+ loginHours[new Date(loginTime).getHours()]++;
48
+ }
49
+ if (ua.includes("tablet") || ua.includes("ipad") || ua.includes("android") && !ua.includes("mobile")) {
50
+ increment(devices, "Tablet");
51
+ } else if (ua.includes("mobile") || ua.includes("android") || ua.includes("iphone")) {
52
+ increment(devices, "Mobile");
53
+ } else {
54
+ increment(devices, "Desktop");
55
+ }
56
+ if (ua.includes("edg")) increment(browsers, "Edge");
57
+ else if (ua.includes("chrome")) increment(browsers, "Chrome");
58
+ else if (ua.includes("firefox")) increment(browsers, "Firefox");
59
+ else if (ua.includes("safari")) increment(browsers, "Safari");
60
+ else if (ua.includes("postman") || ua.includes("curl")) increment(browsers, "API Client");
61
+ else increment(browsers, "Other");
62
+ if (ua.includes("android")) increment(operatingSystems, "Android");
63
+ else if (ua.includes("ios") || ua.includes("iphone") || ua.includes("ipad")) increment(operatingSystems, "iOS");
64
+ else if (ua.includes("windows") || ua.includes("win32") || ua.includes("win64")) increment(operatingSystems, "Windows");
65
+ else if (ua.includes("mac") || ua.includes("darwin")) increment(operatingSystems, "macOS");
66
+ else if (ua.includes("linux")) increment(operatingSystems, "Linux");
67
+ else increment(operatingSystems, "Other");
68
+ const userKey = getUserKey(session);
69
+ if (userKey) uniqueUsers.add(userKey);
70
+ if (session?.ipAddress) uniqueIPs.add(session.ipAddress);
71
+ const status = sessionStatus.getSessionStatus(session);
72
+ if (status === "loggedout") loggedOut++;
73
+ else if (!session?.isActive && status === "terminated") terminated++;
74
+ const duration = getDurationMinutes(session, now);
75
+ if (duration !== null) durations.push(duration);
76
+ }
77
+ const mobileCount = (devices.Mobile || 0) + (devices.Tablet || 0);
78
+ return {
79
+ totalSessions: sessions.length,
80
+ activeSessions: sessions.filter((session) => session?.isActive && session?.isTrulyActive).length,
81
+ todayLogins,
82
+ weekLogins,
83
+ devices,
84
+ browsers,
85
+ operatingSystems,
86
+ loginHours,
87
+ peakHour: loginHours.indexOf(Math.max(...loginHours)),
88
+ uniqueUsers: uniqueUsers.size,
89
+ uniqueIPs: uniqueIPs.size,
90
+ loggedOut,
91
+ terminated,
92
+ mobileRatio: sessions.length > 0 ? Math.round(mobileCount / sessions.length * 100) : 0,
93
+ avgSessionDuration: durations.length > 0 ? Math.floor(durations.reduce((sum, duration) => sum + duration, 0) / durations.length) : 0
94
+ };
95
+ }
12
96
  const theme = {
13
97
  shadows: {
14
98
  sm: "0 1px 3px 0 rgba(0, 0, 0, 0.1)",
@@ -39,6 +123,10 @@ const pulse = styled.keyframes`
39
123
  0%, 100% { opacity: 1; }
40
124
  50% { opacity: 0.8; }
41
125
  `;
126
+ const float = styled.keyframes`
127
+ 0%, 100% { transform: translateY(0px); }
128
+ 50% { transform: translateY(-5px); }
129
+ `;
42
130
  const growBar = styled.keyframes`
43
131
  from { width: 0; }
44
132
  to { width: var(--bar-width); }
@@ -280,74 +368,7 @@ const AnalyticsPage = () => {
280
368
  try {
281
369
  const { data } = await get(`/${index.pluginId}/sessions`);
282
370
  const sessions = data.data || [];
283
- const now = Date.now();
284
- const dayAgo = now - 24 * 60 * 60 * 1e3;
285
- const weekAgo = now - 7 * 24 * 60 * 60 * 1e3;
286
- const todayLogins = sessions.filter((s) => new Date(s.loginTime).getTime() > dayAgo);
287
- const weekLogins = sessions.filter((s) => new Date(s.loginTime).getTime() > weekAgo);
288
- const devices = {};
289
- const browsers = {};
290
- const operatingSystems = {};
291
- const countries = {};
292
- const loginHours = Array(24).fill(0);
293
- const uniqueUsers = /* @__PURE__ */ new Set();
294
- const uniqueIPs = /* @__PURE__ */ new Set();
295
- sessions.forEach((session) => {
296
- const ua = session.userAgent.toLowerCase();
297
- if (ua.includes("mobile") || ua.includes("android") || ua.includes("iphone")) {
298
- devices["Mobile"] = (devices["Mobile"] || 0) + 1;
299
- } else if (ua.includes("tablet") || ua.includes("ipad")) {
300
- devices["Tablet"] = (devices["Tablet"] || 0) + 1;
301
- } else {
302
- devices["Desktop"] = (devices["Desktop"] || 0) + 1;
303
- }
304
- if (ua.includes("chrome") && !ua.includes("edg")) browsers["Chrome"] = (browsers["Chrome"] || 0) + 1;
305
- else if (ua.includes("firefox")) browsers["Firefox"] = (browsers["Firefox"] || 0) + 1;
306
- else if (ua.includes("safari") && !ua.includes("chrome")) browsers["Safari"] = (browsers["Safari"] || 0) + 1;
307
- else if (ua.includes("edg")) browsers["Edge"] = (browsers["Edge"] || 0) + 1;
308
- else if (ua.includes("postman") || ua.includes("curl")) browsers["API Client"] = (browsers["API Client"] || 0) + 1;
309
- else browsers["Other"] = (browsers["Other"] || 0) + 1;
310
- if (ua.includes("windows") || ua.includes("win32") || ua.includes("win64")) {
311
- operatingSystems["Windows"] = (operatingSystems["Windows"] || 0) + 1;
312
- } else if (ua.includes("mac") || ua.includes("darwin")) {
313
- operatingSystems["macOS"] = (operatingSystems["macOS"] || 0) + 1;
314
- } else if (ua.includes("linux")) {
315
- operatingSystems["Linux"] = (operatingSystems["Linux"] || 0) + 1;
316
- } else if (ua.includes("android")) {
317
- operatingSystems["Android"] = (operatingSystems["Android"] || 0) + 1;
318
- } else if (ua.includes("ios") || ua.includes("iphone") || ua.includes("ipad")) {
319
- operatingSystems["iOS"] = (operatingSystems["iOS"] || 0) + 1;
320
- } else {
321
- operatingSystems["Other"] = (operatingSystems["Other"] || 0) + 1;
322
- }
323
- const loginHour = new Date(session.loginTime).getHours();
324
- loginHours[loginHour]++;
325
- if (session.user?.id) uniqueUsers.add(session.user.id);
326
- if (session.ipAddress) uniqueIPs.add(session.ipAddress);
327
- });
328
- const peakHour = loginHours.indexOf(Math.max(...loginHours));
329
- const loggedOut = sessions.filter((s) => !s.isActive && s.logoutTime).length;
330
- const terminated = sessions.filter((s) => !s.isActive && !s.logoutTime).length;
331
- const mobileCount = (devices["Mobile"] || 0) + (devices["Tablet"] || 0);
332
- const desktopCount = devices["Desktop"] || 0;
333
- const mobileRatio = sessions.length > 0 ? Math.round(mobileCount / sessions.length * 100) : 0;
334
- setAnalytics({
335
- totalSessions: sessions.length,
336
- activeSessions: sessions.filter((s) => s.isActive && s.isTrulyActive).length,
337
- todayLogins: todayLogins.length,
338
- weekLogins: weekLogins.length,
339
- devices,
340
- browsers,
341
- operatingSystems,
342
- loginHours,
343
- peakHour,
344
- uniqueUsers: uniqueUsers.size,
345
- uniqueIPs: uniqueIPs.size,
346
- loggedOut,
347
- terminated,
348
- mobileRatio,
349
- avgSessionDuration: sessions.length > 0 ? Math.floor(sessions.reduce((sum, s) => sum + (s.minutesSinceActive || 0), 0) / sessions.length) : 0
350
- });
371
+ setAnalytics(computeSessionAnalytics(sessions));
351
372
  } catch (err) {
352
373
  console.error("[Analytics] Error:", err);
353
374
  } finally {
@@ -5,9 +5,10 @@ const react = require("react");
5
5
  const reactIntl = require("react-intl");
6
6
  const admin = require("@strapi/strapi/admin");
7
7
  const styled = require("styled-components");
8
- const index = require("./index-DJHhzin_.js");
8
+ const index = require("./index-Duc7cR_d.js");
9
9
  const designSystem = require("@strapi/design-system");
10
10
  const icons = require("@strapi/icons");
11
+ const sessionStatus = require("./sessionStatus-D_fWEzgj.js");
11
12
  const StyledButtons = require("./StyledButtons-DDuxnYz8.js");
12
13
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
13
14
  const styled__default = /* @__PURE__ */ _interopDefault(styled);
@@ -271,7 +272,7 @@ const SessionDetailModal = ({ session, onClose, onSessionTerminated }) => {
271
272
  /* @__PURE__ */ jsxRuntime.jsx(SectionTitle, { children: t("modal.section.user", "User") }),
272
273
  /* @__PURE__ */ jsxRuntime.jsx(DetailRow, { compact: true, icon: icons.Check, label: t("modal.user.username", "Username"), value: session.user?.username || t("modal.user.na", "N/A") }),
273
274
  /* @__PURE__ */ jsxRuntime.jsx(DetailRow, { compact: true, icon: icons.Information, label: t("modal.user.email", "Email"), value: session.user?.email || t("modal.user.na", "N/A") }),
274
- /* @__PURE__ */ jsxRuntime.jsx(DetailRow, { compact: true, icon: icons.Information, label: t("modal.user.id", "User ID"), value: session.user?.id || t("modal.user.na", "N/A") })
275
+ /* @__PURE__ */ jsxRuntime.jsx(DetailRow, { compact: true, icon: icons.Information, label: t("modal.user.id", "User ID"), value: session.user?.documentId || session.user?.id || t("modal.user.na", "N/A") })
275
276
  ] }),
276
277
  /* @__PURE__ */ jsxRuntime.jsxs(Section, { children: [
277
278
  /* @__PURE__ */ jsxRuntime.jsx(SectionTitle, { children: t("modal.section.device", "Device") }),
@@ -934,7 +935,7 @@ const HomePage = () => {
934
935
  const escapeCsvValue = (value) => `"${String(value ?? "").replace(/"/g, '""')}"`;
935
936
  const rows = filteredSessions.map((session) => {
936
937
  const deviceInfo = index.parseUserAgent(session.userAgent);
937
- const status = getSessionStatus(session);
938
+ const status = sessionStatus.getSessionStatus(session);
938
939
  return [
939
940
  session.id,
940
941
  status,
@@ -982,9 +983,9 @@ const HomePage = () => {
982
983
  const deviceInfo = index.parseUserAgent(session.userAgent);
983
984
  return {
984
985
  id: session.id,
985
- status: getSessionStatus(session),
986
+ status: sessionStatus.getSessionStatus(session),
986
987
  user: {
987
- id: session.user?.id,
988
+ id: session.user?.documentId || session.user?.id,
988
989
  email: session.user?.email,
989
990
  username: session.user?.username
990
991
  },
@@ -1027,9 +1028,9 @@ const HomePage = () => {
1027
1028
  return icons.Server;
1028
1029
  };
1029
1030
  const activeSessions = sessions.filter((s) => s.isActive && s.isTrulyActive);
1030
- const idleSessions = sessions.filter((s) => s.isActive && !s.isTrulyActive);
1031
- const loggedOutSessions = sessions.filter((s) => !s.isActive && s.logoutTime);
1032
- const terminatedSessions = sessions.filter((s) => !s.isActive && !s.logoutTime);
1031
+ const idleSessions = sessions.filter((s) => sessionStatus.getSessionStatus(s) === "idle");
1032
+ const loggedOutSessions = sessions.filter((s) => sessionStatus.getSessionStatus(s) === "loggedout");
1033
+ const terminatedSessions = sessions.filter((s) => sessionStatus.getSessionStatus(s) === "terminated");
1033
1034
  const handleSessionClick = (session) => {
1034
1035
  setSelectedSession(session);
1035
1036
  setShowDetailModal(true);
@@ -1041,18 +1042,12 @@ const HomePage = () => {
1041
1042
  const handleSessionTerminated = () => {
1042
1043
  fetchSessions();
1043
1044
  };
1044
- const getSessionStatus = (session) => {
1045
- if (!session.isActive) {
1046
- return session.logoutTime ? "loggedout" : "terminated";
1047
- }
1048
- return session.isTrulyActive ? "active" : "idle";
1049
- };
1050
1045
  const filteredSessions = sessions.filter((session) => {
1051
- const sessionStatus = getSessionStatus(session);
1052
- if (filterStatus === "active" && sessionStatus !== "active") return false;
1053
- if (filterStatus === "idle" && sessionStatus !== "idle") return false;
1054
- if (filterStatus === "loggedout" && sessionStatus !== "loggedout") return false;
1055
- if (filterStatus === "terminated" && sessionStatus !== "terminated") return false;
1046
+ const sessionStatus$1 = sessionStatus.getSessionStatus(session);
1047
+ if (filterStatus === "active" && sessionStatus$1 !== "active") return false;
1048
+ if (filterStatus === "idle" && sessionStatus$1 !== "idle") return false;
1049
+ if (filterStatus === "loggedout" && sessionStatus$1 !== "loggedout") return false;
1050
+ if (filterStatus === "terminated" && sessionStatus$1 !== "terminated") return false;
1056
1051
  if (searchQuery) {
1057
1052
  const query = searchQuery.toLowerCase();
1058
1053
  const matchesUser = session.user?.email?.toLowerCase().includes(query) || session.user?.username?.toLowerCase().includes(query);
@@ -1160,8 +1155,8 @@ const HomePage = () => {
1160
1155
  size: "S",
1161
1156
  children: [
1162
1157
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "all", children: t("homepage.filter.all", "All Sessions") }),
1163
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "active", children: t("homepage.filter.active", "Active (less than 15 min)") }),
1164
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "idle", children: t("homepage.filter.idle", "Idle (more than 15 min)") }),
1158
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "active", children: t("homepage.filter.active", "Currently active") }),
1159
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "idle", children: t("homepage.filter.idle", "Inactive") }),
1165
1160
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "loggedout", children: t("homepage.filter.loggedout", "Logged Out") }),
1166
1161
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "terminated", children: t("homepage.filter.terminated", "Terminated") })
1167
1162
  ]
@@ -1197,7 +1192,7 @@ const HomePage = () => {
1197
1192
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tbody, { children: filteredSessions.map((session) => {
1198
1193
  const deviceInfo = index.parseUserAgent(session.userAgent);
1199
1194
  const DeviceIcon = getDeviceIcon(deviceInfo.device);
1200
- const sessionStatus = getSessionStatus(session);
1195
+ const sessionStatus$1 = sessionStatus.getSessionStatus(session);
1201
1196
  const statusConfig = {
1202
1197
  active: {
1203
1198
  bg: "rgba(22, 163, 74, 0.06)",
@@ -1226,7 +1221,7 @@ const HomePage = () => {
1226
1221
  opacity: 0.6
1227
1222
  }
1228
1223
  };
1229
- const config = statusConfig[sessionStatus];
1224
+ const config = statusConfig[sessionStatus$1];
1230
1225
  return /* @__PURE__ */ jsxRuntime.jsxs(
1231
1226
  ClickableRow,
1232
1227
  {
@@ -1236,8 +1231,8 @@ const HomePage = () => {
1236
1231
  opacity: config.opacity || 1
1237
1232
  },
1238
1233
  children: [
1239
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsxs(StatusBadge, { $status: sessionStatus, children: [
1240
- /* @__PURE__ */ jsxRuntime.jsx(StatusDot, { $status: sessionStatus }),
1234
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsxs(StatusBadge, { $status: sessionStatus$1, children: [
1235
+ /* @__PURE__ */ jsxRuntime.jsx(StatusDot, { $status: sessionStatus$1 }),
1241
1236
  config.label
1242
1237
  ] }) }),
1243
1238
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", children: [
@@ -1259,7 +1254,7 @@ const HomePage = () => {
1259
1254
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral700", children: new Date(session.loginTime).toLocaleString() }) }),
1260
1255
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", children: [
1261
1256
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral700", children: new Date(session.lastActive || session.loginTime).toLocaleString() }),
1262
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: sessionStatus === "active" ? "success600" : "neutral500", children: t("homepage.time.minAgo", "{minutes} min ago", { minutes: session.minutesSinceActive }) })
1257
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: sessionStatus$1 === "active" ? "success600" : "neutral500", children: t("homepage.time.minAgo", "{minutes} min ago", { minutes: session.minutesSinceActive }) })
1263
1258
  ] }) }),
1264
1259
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Td, { onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsxRuntime.jsxs(ActionButtons, { className: "action-buttons", children: [
1265
1260
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -1280,7 +1275,7 @@ const HomePage = () => {
1280
1275
  e.stopPropagation();
1281
1276
  handleTerminateSession(session.id);
1282
1277
  },
1283
- disabled: sessionStatus !== "active" && sessionStatus !== "idle",
1278
+ disabled: sessionStatus$1 !== "active" && sessionStatus$1 !== "idle",
1284
1279
  title: session.isActive ? t("homepage.actions.terminate", "Terminate (Logout)") : t("homepage.actions.alreadyInactive", "Already inactive"),
1285
1280
  children: /* @__PURE__ */ jsxRuntime.jsx(icons.Cross, {})
1286
1281
  }
@@ -3,9 +3,10 @@ import { useState, useEffect } from "react";
3
3
  import { useIntl } from "react-intl";
4
4
  import { useFetchClient, useNotification, Page } from "@strapi/strapi/admin";
5
5
  import styled, { css, keyframes } from "styled-components";
6
- import { p as parseUserAgent, a as pluginId$1, g as getTranslation } from "./index-CpMDG2XI.mjs";
6
+ import { p as parseUserAgent, a as pluginId$1, g as getTranslation } from "./index-B_lFjUAg.mjs";
7
7
  import { Modal, Flex, Box, Typography, Divider, Button, Loader, SingleSelect, SingleSelectOption, Thead, Tr, Th, Tbody, Td, Table } from "@strapi/design-system";
8
8
  import { Check, Information, Monitor, Server, Clock, Cross, Earth, Shield, Phone, Download, User, Eye, Trash, Search } from "@strapi/icons";
9
+ import { g as getSessionStatus } from "./sessionStatus-kwggjEMw.mjs";
9
10
  import { S as ShowHideButton, T as TertiaryButton, D as DangerButton, I as IconButtonPrimary, a as IconButtonWarning, b as IconButtonDanger } from "./StyledButtons-Cz8oYhmc.mjs";
10
11
  const theme = {
11
12
  shadows: {
@@ -267,7 +268,7 @@ const SessionDetailModal = ({ session, onClose, onSessionTerminated }) => {
267
268
  /* @__PURE__ */ jsx(SectionTitle, { children: t("modal.section.user", "User") }),
268
269
  /* @__PURE__ */ jsx(DetailRow, { compact: true, icon: Check, label: t("modal.user.username", "Username"), value: session.user?.username || t("modal.user.na", "N/A") }),
269
270
  /* @__PURE__ */ jsx(DetailRow, { compact: true, icon: Information, label: t("modal.user.email", "Email"), value: session.user?.email || t("modal.user.na", "N/A") }),
270
- /* @__PURE__ */ jsx(DetailRow, { compact: true, icon: Information, label: t("modal.user.id", "User ID"), value: session.user?.id || t("modal.user.na", "N/A") })
271
+ /* @__PURE__ */ jsx(DetailRow, { compact: true, icon: Information, label: t("modal.user.id", "User ID"), value: session.user?.documentId || session.user?.id || t("modal.user.na", "N/A") })
271
272
  ] }),
272
273
  /* @__PURE__ */ jsxs(Section, { children: [
273
274
  /* @__PURE__ */ jsx(SectionTitle, { children: t("modal.section.device", "Device") }),
@@ -980,7 +981,7 @@ const HomePage = () => {
980
981
  id: session.id,
981
982
  status: getSessionStatus(session),
982
983
  user: {
983
- id: session.user?.id,
984
+ id: session.user?.documentId || session.user?.id,
984
985
  email: session.user?.email,
985
986
  username: session.user?.username
986
987
  },
@@ -1023,9 +1024,9 @@ const HomePage = () => {
1023
1024
  return Server;
1024
1025
  };
1025
1026
  const activeSessions = sessions.filter((s) => s.isActive && s.isTrulyActive);
1026
- const idleSessions = sessions.filter((s) => s.isActive && !s.isTrulyActive);
1027
- const loggedOutSessions = sessions.filter((s) => !s.isActive && s.logoutTime);
1028
- const terminatedSessions = sessions.filter((s) => !s.isActive && !s.logoutTime);
1027
+ const idleSessions = sessions.filter((s) => getSessionStatus(s) === "idle");
1028
+ const loggedOutSessions = sessions.filter((s) => getSessionStatus(s) === "loggedout");
1029
+ const terminatedSessions = sessions.filter((s) => getSessionStatus(s) === "terminated");
1029
1030
  const handleSessionClick = (session) => {
1030
1031
  setSelectedSession(session);
1031
1032
  setShowDetailModal(true);
@@ -1037,12 +1038,6 @@ const HomePage = () => {
1037
1038
  const handleSessionTerminated = () => {
1038
1039
  fetchSessions();
1039
1040
  };
1040
- const getSessionStatus = (session) => {
1041
- if (!session.isActive) {
1042
- return session.logoutTime ? "loggedout" : "terminated";
1043
- }
1044
- return session.isTrulyActive ? "active" : "idle";
1045
- };
1046
1041
  const filteredSessions = sessions.filter((session) => {
1047
1042
  const sessionStatus = getSessionStatus(session);
1048
1043
  if (filterStatus === "active" && sessionStatus !== "active") return false;
@@ -1156,8 +1151,8 @@ const HomePage = () => {
1156
1151
  size: "S",
1157
1152
  children: [
1158
1153
  /* @__PURE__ */ jsx(SingleSelectOption, { value: "all", children: t("homepage.filter.all", "All Sessions") }),
1159
- /* @__PURE__ */ jsx(SingleSelectOption, { value: "active", children: t("homepage.filter.active", "Active (less than 15 min)") }),
1160
- /* @__PURE__ */ jsx(SingleSelectOption, { value: "idle", children: t("homepage.filter.idle", "Idle (more than 15 min)") }),
1154
+ /* @__PURE__ */ jsx(SingleSelectOption, { value: "active", children: t("homepage.filter.active", "Currently active") }),
1155
+ /* @__PURE__ */ jsx(SingleSelectOption, { value: "idle", children: t("homepage.filter.idle", "Inactive") }),
1161
1156
  /* @__PURE__ */ jsx(SingleSelectOption, { value: "loggedout", children: t("homepage.filter.loggedout", "Logged Out") }),
1162
1157
  /* @__PURE__ */ jsx(SingleSelectOption, { value: "terminated", children: t("homepage.filter.terminated", "Terminated") })
1163
1158
  ]
@@ -4,7 +4,7 @@ import { Loader, Box, Alert, Flex, Typography, Button, Badge, Accordion } from "
4
4
  import { useFetchClient, useNotification } from "@strapi/strapi/admin";
5
5
  import { ArrowClockwise, Duplicate, Download, User, Shield, Sparkle, ChartBubble } from "@strapi/icons";
6
6
  import styled, { css, keyframes } from "styled-components";
7
- import { a as pluginId } from "./index-CpMDG2XI.mjs";
7
+ import { a as pluginId } from "./index-B_lFjUAg.mjs";
8
8
  const theme = {
9
9
  borderRadius: { lg: "12px" }
10
10
  };