strapi-plugin-magic-sessionmanager 4.8.0 → 4.9.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.
- package/CHANGELOG.md +83 -5
- package/README.md +379 -641
- package/dist/admin/Analytics-B6d-39Qh.js +420 -0
- package/dist/admin/Analytics-DxOWXHn8.mjs +418 -0
- package/dist/admin/App-ZsSGj7n8.mjs +1894 -0
- package/dist/admin/App-mRFV50K6.js +1896 -0
- package/dist/admin/License-BE6UQ_V3.mjs +443 -0
- package/dist/admin/License-DXt2oi6u.js +443 -0
- package/dist/admin/OnlineUsersWidget-CFvM3Vbp.js +273 -0
- package/dist/admin/OnlineUsersWidget-_tJ6aeWl.mjs +254 -0
- package/dist/admin/SectionCard-BlWv8CRt.js +54 -0
- package/dist/admin/SectionCard-D51bv4Hi.mjs +55 -0
- package/dist/admin/Settings-BUc12TP5.js +3570 -0
- package/dist/admin/Settings-dtW7cjTX.mjs +3568 -0
- package/dist/admin/de-BFKoGEVT.js +544 -0
- package/dist/admin/de-j0oZH9Pz.mjs +544 -0
- package/dist/admin/en-UY4Tb5tE.mjs +544 -0
- package/dist/admin/en-s7Ksdkcg.js +544 -0
- package/dist/admin/es-07OGMe_5.js +544 -0
- package/dist/admin/es-DGBcZwQy.mjs +544 -0
- package/dist/admin/fr-B6-DWhGO.mjs +544 -0
- package/dist/admin/fr-ETj_2UBY.js +544 -0
- package/dist/admin/index-C_SyRULc.mjs +1750 -0
- package/dist/admin/index-D4kEnXSp.js +1751 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +2 -2
- package/dist/admin/maskSensitiveValue-BWcSjow7.js +9 -0
- package/dist/admin/maskSensitiveValue-lLRhN_S7.mjs +10 -0
- package/dist/admin/pt-C7PwrQtV.js +544 -0
- package/dist/admin/pt-YMRLm9gx.mjs +544 -0
- package/dist/server/index.js +1092 -463
- package/dist/server/index.mjs +1092 -463
- package/package.json +10 -1
- package/pics/analytics.png +0 -0
- package/pics/dashboard-dark.png +0 -0
- package/pics/dashboard.png +0 -0
- package/pics/dashboardsessionmodal.png +0 -0
- package/pics/mobile-dashboard.png +0 -0
- package/pics/mobile-session.png +0 -0
- package/pics/sessioninfopanel.png +0 -0
- package/pics/settings1.png +0 -0
- package/pics/settings2.png +0 -0
- package/pics/widget.png +0 -0
- package/scripts/geoip-updater.cjs +35 -24
- package/dist/admin/Analytics-CaRlu5ad.js +0 -332
- package/dist/admin/Analytics-THqDbNX0.mjs +0 -330
- package/dist/admin/App-AbZwLHtF.js +0 -1263
- package/dist/admin/App-hSh7guii.mjs +0 -1261
- package/dist/admin/FormField-C8kIT2NE.mjs +0 -59
- package/dist/admin/FormField-b5KBvkrj.js +0 -60
- package/dist/admin/License-BXBVwUVu.mjs +0 -299
- package/dist/admin/License-CABdPwnd.js +0 -301
- package/dist/admin/OnlineUsersWidget-BnWFj9IM.mjs +0 -230
- package/dist/admin/OnlineUsersWidget-CPFAACSb.js +0 -230
- package/dist/admin/PluginPageLayout-BPFMcgrx.mjs +0 -42
- package/dist/admin/PluginPageLayout-DmNzMdqu.js +0 -43
- package/dist/admin/Settings-B4DNdeKx.js +0 -2152
- package/dist/admin/Settings-C4RsJosh.mjs +0 -2150
- package/dist/admin/de-AwIFTd9i.mjs +0 -450
- package/dist/admin/de-D23nmqnl.js +0 -450
- package/dist/admin/en-C5iYQ0mC.js +0 -450
- package/dist/admin/en-D6QEGeRh.mjs +0 -450
- package/dist/admin/es-CIXnsG-p.js +0 -435
- package/dist/admin/es-CnFfVdKw.mjs +0 -435
- package/dist/admin/fr-BglXE-W4.js +0 -435
- package/dist/admin/fr-DefoR7uH.mjs +0 -435
- package/dist/admin/index-BFVITQ-o.mjs +0 -624
- package/dist/admin/index-DlMm-NyK.js +0 -625
- package/dist/admin/maskSensitiveValue-1uGWmrfG.mjs +0 -20
- package/dist/admin/maskSensitiveValue-B9vhxPad.js +0 -19
- package/dist/admin/pt-J5sf7jiY.js +0 -435
- package/dist/admin/pt-TODwvNQA.mjs +0 -435
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.
|
|
2
|
+
"version": "4.9.0",
|
|
3
3
|
"keywords": [
|
|
4
4
|
"strapi",
|
|
5
5
|
"plugin",
|
|
@@ -49,6 +49,10 @@
|
|
|
49
49
|
"test": "node --test tests/*.test.js tests/*.test.mjs",
|
|
50
50
|
"test:ts:front": "tsc --noEmit --allowJs --jsx react-jsx --moduleResolution bundler --module esnext -p admin/jsconfig.json",
|
|
51
51
|
"test:ts:back": "tsc --noEmit --allowJs --moduleResolution node --module commonjs -p server/jsconfig.json",
|
|
52
|
+
"lint": "eslint .",
|
|
53
|
+
"lint:fix": "eslint . --fix",
|
|
54
|
+
"format": "prettier --write .",
|
|
55
|
+
"format:check": "prettier --check .",
|
|
52
56
|
"build": "npm run clean && strapi-plugin build && node scripts/build-server-bundle.mjs",
|
|
53
57
|
"watch": "strapi-plugin watch",
|
|
54
58
|
"watch:link": "strapi-plugin watch:link",
|
|
@@ -62,6 +66,7 @@
|
|
|
62
66
|
"sanitize-html": "^2.18.0"
|
|
63
67
|
},
|
|
64
68
|
"devDependencies": {
|
|
69
|
+
"@eslint/js": "^10.0.1",
|
|
65
70
|
"@semantic-release/changelog": "^7.0.0",
|
|
66
71
|
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
67
72
|
"@semantic-release/git": "^11.0.1",
|
|
@@ -73,6 +78,10 @@
|
|
|
73
78
|
"@strapi/sdk-plugin": "^6.1.1",
|
|
74
79
|
"@strapi/strapi": "5.61.0",
|
|
75
80
|
"esbuild": "^0.28.2",
|
|
81
|
+
"eslint": "^10.14.0",
|
|
82
|
+
"eslint-config-prettier": "^10.1.8",
|
|
83
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
84
|
+
"globals": "^17.14.0",
|
|
76
85
|
"prettier": "^3.9.10",
|
|
77
86
|
"react": "^18.3.1",
|
|
78
87
|
"react-dom": "^18.3.1",
|
|
Binary file
|
|
Binary file
|
package/pics/dashboard.png
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/pics/settings1.png
CHANGED
|
Binary file
|
package/pics/settings2.png
CHANGED
|
Binary file
|
package/pics/widget.png
CHANGED
|
Binary file
|
|
@@ -11,7 +11,12 @@ const gunzip = promisify(zlib.gunzip);
|
|
|
11
11
|
|
|
12
12
|
const DEFAULT_EDITION_ID = 'GeoLite2-City';
|
|
13
13
|
const DEFAULT_MMDB_NAME = `${DEFAULT_EDITION_ID}.mmdb`;
|
|
14
|
-
const DEFAULT_GEOIP_DIRECTORY = path.resolve(
|
|
14
|
+
const DEFAULT_GEOIP_DIRECTORY = path.resolve(
|
|
15
|
+
process.cwd(),
|
|
16
|
+
'data',
|
|
17
|
+
'magic-sessionmanager',
|
|
18
|
+
'geoip'
|
|
19
|
+
);
|
|
15
20
|
const DEFAULT_OUTPUT_PATH = path.join(DEFAULT_GEOIP_DIRECTORY, DEFAULT_MMDB_NAME);
|
|
16
21
|
const SUPPORTED_EDITION_IDS = new Set([
|
|
17
22
|
'GeoLite2-City',
|
|
@@ -19,7 +24,9 @@ const SUPPORTED_EDITION_IDS = new Set([
|
|
|
19
24
|
'GeoIP2-City',
|
|
20
25
|
'GeoIP2-Country',
|
|
21
26
|
]);
|
|
22
|
-
const SUPPORTED_MMDB_NAMES = new Set(
|
|
27
|
+
const SUPPORTED_MMDB_NAMES = new Set(
|
|
28
|
+
[...SUPPORTED_EDITION_IDS].map((editionId) => `${editionId}.mmdb`)
|
|
29
|
+
);
|
|
23
30
|
|
|
24
31
|
/**
|
|
25
32
|
* Resolves a supported MMDB filename into the plugin's dedicated database
|
|
@@ -171,9 +178,9 @@ function resolveConfig(env = process.env, argv = process.argv.slice(2), override
|
|
|
171
178
|
'';
|
|
172
179
|
const editionId = normalizeEditionId(
|
|
173
180
|
overrides.editionId ||
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
181
|
+
env.MAXMIND_EDITION_ID ||
|
|
182
|
+
inferEditionIdFromPath(configuredOutputPath) ||
|
|
183
|
+
DEFAULT_EDITION_ID
|
|
177
184
|
);
|
|
178
185
|
const databaseDirectory = overrides.databaseDirectory || DEFAULT_GEOIP_DIRECTORY;
|
|
179
186
|
const outputPath = resolveDatabaseTarget(
|
|
@@ -197,12 +204,7 @@ function resolveConfig(env = process.env, argv = process.argv.slice(2), override
|
|
|
197
204
|
* @param {object} options Comparison inputs and force flag
|
|
198
205
|
* @returns {boolean} Whether the updater should fetch a fresh archive
|
|
199
206
|
*/
|
|
200
|
-
function needsDownload({
|
|
201
|
-
force,
|
|
202
|
-
localExists,
|
|
203
|
-
localMetadata,
|
|
204
|
-
remoteLastModified,
|
|
205
|
-
}) {
|
|
207
|
+
function needsDownload({ force, localExists, localMetadata, remoteLastModified }) {
|
|
206
208
|
if (force) return true;
|
|
207
209
|
if (!localExists) return true;
|
|
208
210
|
if (!remoteLastModified) return true;
|
|
@@ -420,12 +422,14 @@ async function updateGeoIpDatabase(config = resolveConfig()) {
|
|
|
420
422
|
fileExists(outputPath),
|
|
421
423
|
]);
|
|
422
424
|
|
|
423
|
-
if (
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
425
|
+
if (
|
|
426
|
+
!needsDownload({
|
|
427
|
+
force: config.force,
|
|
428
|
+
localExists,
|
|
429
|
+
localMetadata,
|
|
430
|
+
remoteLastModified: head.lastModified,
|
|
431
|
+
})
|
|
432
|
+
) {
|
|
429
433
|
return {
|
|
430
434
|
changed: false,
|
|
431
435
|
outputPath,
|
|
@@ -438,13 +442,20 @@ async function updateGeoIpDatabase(config = resolveConfig()) {
|
|
|
438
442
|
const extracted = await extractMmdbFromTarGz(archive, mmdbFileName);
|
|
439
443
|
|
|
440
444
|
await writeAtomic(outputPath, extracted.data);
|
|
441
|
-
await writeAtomic(
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
445
|
+
await writeAtomic(
|
|
446
|
+
metadataPath,
|
|
447
|
+
JSON.stringify(
|
|
448
|
+
{
|
|
449
|
+
editionId,
|
|
450
|
+
sourceFile: extracted.name,
|
|
451
|
+
lastModified: head.lastModified,
|
|
452
|
+
downloadedAt: new Date().toISOString(),
|
|
453
|
+
sourceUrl: url,
|
|
454
|
+
},
|
|
455
|
+
null,
|
|
456
|
+
2
|
|
457
|
+
)
|
|
458
|
+
);
|
|
448
459
|
|
|
449
460
|
return {
|
|
450
461
|
changed: true,
|
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
-
const react = require("react");
|
|
5
|
-
const reactIntl = require("react-intl");
|
|
6
|
-
const admin = require("@strapi/strapi/admin");
|
|
7
|
-
const styled = require("styled-components");
|
|
8
|
-
const designSystem = require("@strapi/design-system");
|
|
9
|
-
const icons = require("@strapi/icons");
|
|
10
|
-
const index = require("./index-DlMm-NyK.js");
|
|
11
|
-
const PluginPageLayout = require("./PluginPageLayout-DmNzMdqu.js");
|
|
12
|
-
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
13
|
-
const styled__default = /* @__PURE__ */ _interopDefault(styled);
|
|
14
|
-
function increment(target, key) {
|
|
15
|
-
target[key] = (target[key] || 0) + 1;
|
|
16
|
-
}
|
|
17
|
-
function getUserKey(session) {
|
|
18
|
-
return session?.user?.documentId || session?.user?.id || session?.user?.email || session?.user?.username || null;
|
|
19
|
-
}
|
|
20
|
-
function getDurationMinutes(session, now) {
|
|
21
|
-
const start = Date.parse(session?.loginTime);
|
|
22
|
-
if (!Number.isFinite(start)) return null;
|
|
23
|
-
const endValue = session.logoutTime || session.lastActive;
|
|
24
|
-
const end = endValue ? Date.parse(endValue) : now;
|
|
25
|
-
if (!Number.isFinite(end)) return null;
|
|
26
|
-
return Math.max(0, Math.floor((end - start) / 6e4));
|
|
27
|
-
}
|
|
28
|
-
function computeSessionAnalytics(sessions = [], { now = Date.now() } = {}) {
|
|
29
|
-
const dayAgo = now - 24 * 60 * 60 * 1e3;
|
|
30
|
-
const weekAgo = now - 7 * 24 * 60 * 60 * 1e3;
|
|
31
|
-
const devices = {};
|
|
32
|
-
const browsers = {};
|
|
33
|
-
const operatingSystems = {};
|
|
34
|
-
const loginHours = Array(24).fill(0);
|
|
35
|
-
const uniqueUsers = /* @__PURE__ */ new Set();
|
|
36
|
-
const uniqueIPs = /* @__PURE__ */ new Set();
|
|
37
|
-
const durations = [];
|
|
38
|
-
let todayLogins = 0;
|
|
39
|
-
let weekLogins = 0;
|
|
40
|
-
let loggedOut = 0;
|
|
41
|
-
let terminated = 0;
|
|
42
|
-
for (const session of sessions) {
|
|
43
|
-
const ua = String(session?.userAgent || "").toLowerCase();
|
|
44
|
-
const loginTime = Date.parse(session?.loginTime);
|
|
45
|
-
if (Number.isFinite(loginTime)) {
|
|
46
|
-
if (loginTime > dayAgo) todayLogins++;
|
|
47
|
-
if (loginTime > weekAgo) weekLogins++;
|
|
48
|
-
loginHours[new Date(loginTime).getHours()]++;
|
|
49
|
-
}
|
|
50
|
-
if (ua.includes("tablet") || ua.includes("ipad") || ua.includes("android") && !ua.includes("mobile")) {
|
|
51
|
-
increment(devices, "Tablet");
|
|
52
|
-
} else if (ua.includes("mobile") || ua.includes("android") || ua.includes("iphone")) {
|
|
53
|
-
increment(devices, "Mobile");
|
|
54
|
-
} else {
|
|
55
|
-
increment(devices, "Desktop");
|
|
56
|
-
}
|
|
57
|
-
if (ua.includes("edg")) increment(browsers, "Edge");
|
|
58
|
-
else if (ua.includes("chrome")) increment(browsers, "Chrome");
|
|
59
|
-
else if (ua.includes("firefox")) increment(browsers, "Firefox");
|
|
60
|
-
else if (ua.includes("safari")) increment(browsers, "Safari");
|
|
61
|
-
else if (ua.includes("postman") || ua.includes("curl")) increment(browsers, "API Client");
|
|
62
|
-
else increment(browsers, "Other");
|
|
63
|
-
if (ua.includes("android")) increment(operatingSystems, "Android");
|
|
64
|
-
else if (ua.includes("ios") || ua.includes("iphone") || ua.includes("ipad")) increment(operatingSystems, "iOS");
|
|
65
|
-
else if (ua.includes("windows") || ua.includes("win32") || ua.includes("win64")) increment(operatingSystems, "Windows");
|
|
66
|
-
else if (ua.includes("mac") || ua.includes("darwin")) increment(operatingSystems, "macOS");
|
|
67
|
-
else if (ua.includes("linux")) increment(operatingSystems, "Linux");
|
|
68
|
-
else increment(operatingSystems, "Other");
|
|
69
|
-
const userKey = getUserKey(session);
|
|
70
|
-
if (userKey) uniqueUsers.add(userKey);
|
|
71
|
-
if (session?.ipAddress) uniqueIPs.add(session.ipAddress);
|
|
72
|
-
const status = index.getSessionStatus(session);
|
|
73
|
-
if (status === "loggedout") loggedOut++;
|
|
74
|
-
else if (!session?.isActive && status === "terminated") terminated++;
|
|
75
|
-
const duration = getDurationMinutes(session, now);
|
|
76
|
-
if (duration !== null) durations.push(duration);
|
|
77
|
-
}
|
|
78
|
-
const mobileCount = (devices.Mobile || 0) + (devices.Tablet || 0);
|
|
79
|
-
return {
|
|
80
|
-
totalSessions: sessions.length,
|
|
81
|
-
activeSessions: sessions.filter((session) => session?.isActive && session?.isTrulyActive).length,
|
|
82
|
-
todayLogins,
|
|
83
|
-
weekLogins,
|
|
84
|
-
devices,
|
|
85
|
-
browsers,
|
|
86
|
-
operatingSystems,
|
|
87
|
-
loginHours,
|
|
88
|
-
peakHour: loginHours.indexOf(Math.max(...loginHours)),
|
|
89
|
-
uniqueUsers: uniqueUsers.size,
|
|
90
|
-
uniqueIPs: uniqueIPs.size,
|
|
91
|
-
loggedOut,
|
|
92
|
-
terminated,
|
|
93
|
-
mobileRatio: sessions.length > 0 ? Math.round(mobileCount / sessions.length * 100) : 0,
|
|
94
|
-
avgSessionDuration: durations.length > 0 ? Math.floor(durations.reduce((sum, duration) => sum + duration, 0) / durations.length) : 0
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
const Container = styled__default.default(designSystem.Box)`
|
|
98
|
-
width: 100%;
|
|
99
|
-
min-width: 0;
|
|
100
|
-
`;
|
|
101
|
-
const StatsGrid = styled__default.default.div`
|
|
102
|
-
display: grid;
|
|
103
|
-
grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
|
|
104
|
-
gap: 12px;
|
|
105
|
-
min-width: 0;
|
|
106
|
-
margin-bottom: 16px;
|
|
107
|
-
`;
|
|
108
|
-
const StatCard = styled__default.default(designSystem.Box)`
|
|
109
|
-
background: ${(p) => p.theme.colors.neutral0};
|
|
110
|
-
border: 1px solid ${(p) => p.theme.colors.neutral150};
|
|
111
|
-
border-top: 3px solid ${(p) => p.theme.colors.primary600};
|
|
112
|
-
border-radius: 4px;
|
|
113
|
-
min-width: 0;
|
|
114
|
-
padding: 16px;
|
|
115
|
-
display: flex;
|
|
116
|
-
flex-direction: column;
|
|
117
|
-
align-items: flex-start;
|
|
118
|
-
gap: 4px;
|
|
119
|
-
|
|
120
|
-
&& > p {
|
|
121
|
-
max-width: none;
|
|
122
|
-
margin: 0;
|
|
123
|
-
line-height: 1.25;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
&& > p + p {
|
|
127
|
-
margin-block-start: 0;
|
|
128
|
-
}
|
|
129
|
-
`;
|
|
130
|
-
const StatIcon = styled__default.default(designSystem.Box)`
|
|
131
|
-
width: 36px;
|
|
132
|
-
height: 36px;
|
|
133
|
-
border-radius: 4px;
|
|
134
|
-
display: flex;
|
|
135
|
-
align-items: center;
|
|
136
|
-
justify-content: center;
|
|
137
|
-
background: ${(p) => p.theme.colors.primary100};
|
|
138
|
-
color: ${(p) => p.theme.colors.primary600};
|
|
139
|
-
margin-bottom: 8px;
|
|
140
|
-
|
|
141
|
-
svg {
|
|
142
|
-
width: 20px;
|
|
143
|
-
height: 20px;
|
|
144
|
-
}
|
|
145
|
-
`;
|
|
146
|
-
const ChartCard = styled__default.default(designSystem.Box)`
|
|
147
|
-
background: ${(p) => p.theme.colors.neutral0};
|
|
148
|
-
border-radius: 4px;
|
|
149
|
-
border: 1px solid ${(p) => p.theme.colors.neutral150};
|
|
150
|
-
min-width: 0;
|
|
151
|
-
padding: 20px;
|
|
152
|
-
`;
|
|
153
|
-
const BarChart = styled__default.default.div`
|
|
154
|
-
display: flex;
|
|
155
|
-
flex-direction: column;
|
|
156
|
-
gap: 12px;
|
|
157
|
-
min-width: 0;
|
|
158
|
-
`;
|
|
159
|
-
const BarRow = styled__default.default.div`
|
|
160
|
-
display: flex;
|
|
161
|
-
align-items: center;
|
|
162
|
-
gap: 12px;
|
|
163
|
-
min-width: 0;
|
|
164
|
-
`;
|
|
165
|
-
const BarContainer = styled__default.default.div`
|
|
166
|
-
flex: 1;
|
|
167
|
-
min-width: 0;
|
|
168
|
-
height: 28px;
|
|
169
|
-
background: ${(p) => p.theme.colors.neutral100};
|
|
170
|
-
border-radius: 4px;
|
|
171
|
-
overflow: hidden;
|
|
172
|
-
position: relative;
|
|
173
|
-
`;
|
|
174
|
-
const BarFill = styled__default.default.div`
|
|
175
|
-
height: 100%;
|
|
176
|
-
width: ${(props) => `${Math.max(0, Math.min(100, props.$percentage || 0))}%`};
|
|
177
|
-
background: ${(p) => p.theme.colors.primary600};
|
|
178
|
-
border-radius: 4px;
|
|
179
|
-
`;
|
|
180
|
-
const LoadingOverlay = styled__default.default(designSystem.Flex)`
|
|
181
|
-
min-height: 240px;
|
|
182
|
-
align-items: center;
|
|
183
|
-
justify-content: center;
|
|
184
|
-
`;
|
|
185
|
-
const AnalyticsPage = () => {
|
|
186
|
-
const { formatMessage } = reactIntl.useIntl();
|
|
187
|
-
const { get } = admin.useFetchClient();
|
|
188
|
-
const t = (id, defaultMessage, values) => formatMessage({ id: index.getTranslation(id), defaultMessage }, values);
|
|
189
|
-
const [loading, setLoading] = react.useState(true);
|
|
190
|
-
const [analytics, setAnalytics] = react.useState(null);
|
|
191
|
-
const [loadError, setLoadError] = react.useState(false);
|
|
192
|
-
react.useEffect(() => {
|
|
193
|
-
fetchAnalytics();
|
|
194
|
-
}, []);
|
|
195
|
-
const fetchAnalytics = async () => {
|
|
196
|
-
setLoading(true);
|
|
197
|
-
setLoadError(false);
|
|
198
|
-
try {
|
|
199
|
-
const { data } = await get(`/${index.pluginId}/sessions`);
|
|
200
|
-
const sessions = data.data || [];
|
|
201
|
-
setAnalytics(computeSessionAnalytics(sessions));
|
|
202
|
-
} catch (err) {
|
|
203
|
-
setLoadError(true);
|
|
204
|
-
index.logSafeAdminError("analytics.load", err);
|
|
205
|
-
} finally {
|
|
206
|
-
setLoading(false);
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
if (loading) {
|
|
210
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
211
|
-
PluginPageLayout.PluginPageLayout,
|
|
212
|
-
{
|
|
213
|
-
headingId: "magic-sessionmanager-analytics-title",
|
|
214
|
-
title: t("analytics.title", "Session Analytics"),
|
|
215
|
-
subtitle: t("analytics.subtitle", "Session activity and device trends"),
|
|
216
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(LoadingOverlay, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { children: t("analytics.loading", "Loading analytics data...") }) })
|
|
217
|
-
}
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
if (loadError) {
|
|
221
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
222
|
-
PluginPageLayout.PluginPageLayout,
|
|
223
|
-
{
|
|
224
|
-
headingId: "magic-sessionmanager-analytics-title",
|
|
225
|
-
title: t("analytics.title", "Session Analytics"),
|
|
226
|
-
subtitle: t("analytics.subtitle", "Session activity and device trends"),
|
|
227
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
228
|
-
designSystem.Alert,
|
|
229
|
-
{
|
|
230
|
-
variant: "danger",
|
|
231
|
-
title: t("analytics.error.title", "Analytics could not be loaded"),
|
|
232
|
-
closeLabel: t("common.close", "Close"),
|
|
233
|
-
action: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "secondary", onClick: fetchAnalytics, children: t("common.retry", "Retry") }),
|
|
234
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "pi", textColor: "neutral700", tag: "span", children: t("analytics.error.description", "Try again. If the problem continues, check session API access and permissions.") })
|
|
235
|
-
}
|
|
236
|
-
)
|
|
237
|
-
}
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
const maxDevices = Math.max(...Object.values(analytics?.devices || {}), 1);
|
|
241
|
-
const maxBrowsers = Math.max(...Object.values(analytics?.browsers || {}), 1);
|
|
242
|
-
const hasSessions = Number(analytics?.totalSessions) > 0;
|
|
243
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
244
|
-
PluginPageLayout.PluginPageLayout,
|
|
245
|
-
{
|
|
246
|
-
headingId: "magic-sessionmanager-analytics-title",
|
|
247
|
-
title: t("analytics.title", "Session Analytics"),
|
|
248
|
-
subtitle: t("analytics.subtitle", "Session activity and device trends"),
|
|
249
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs(Container, { children: [
|
|
250
|
-
/* @__PURE__ */ jsxRuntime.jsxs(StatsGrid, { children: [
|
|
251
|
-
/* @__PURE__ */ jsxRuntime.jsxs(StatCard, { padding: 4, background: "neutral0", children: [
|
|
252
|
-
/* @__PURE__ */ jsxRuntime.jsx(StatIcon, { "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(icons.ChartBubble, {}) }),
|
|
253
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "semiBold", tag: "p", children: analytics?.totalSessions || 0 }),
|
|
254
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: t("analytics.stats.total", "Total sessions") })
|
|
255
|
-
] }),
|
|
256
|
-
/* @__PURE__ */ jsxRuntime.jsxs(StatCard, { padding: 4, background: "neutral0", children: [
|
|
257
|
-
/* @__PURE__ */ jsxRuntime.jsx(StatIcon, { "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(icons.User, {}) }),
|
|
258
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "semiBold", tag: "p", children: analytics?.activeSessions || 0 }),
|
|
259
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: t("analytics.stats.active", "Online now") })
|
|
260
|
-
] }),
|
|
261
|
-
/* @__PURE__ */ jsxRuntime.jsxs(StatCard, { padding: 4, background: "neutral0", children: [
|
|
262
|
-
/* @__PURE__ */ jsxRuntime.jsx(StatIcon, { "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Clock, {}) }),
|
|
263
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "semiBold", tag: "p", children: analytics?.todayLogins || 0 }),
|
|
264
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: t("analytics.stats.today", "Logins today") })
|
|
265
|
-
] }),
|
|
266
|
-
/* @__PURE__ */ jsxRuntime.jsxs(StatCard, { padding: 4, background: "neutral0", children: [
|
|
267
|
-
/* @__PURE__ */ jsxRuntime.jsx(StatIcon, { "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Clock, {}) }),
|
|
268
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "semiBold", tag: "p", children: analytics?.weekLogins || 0 }),
|
|
269
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: t("analytics.stats.week", "Logins this week") })
|
|
270
|
-
] })
|
|
271
|
-
] }),
|
|
272
|
-
hasSessions ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
273
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 4, wrap: "wrap", style: { marginBottom: "28px" }, children: [
|
|
274
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { flex: "1 1 320px", minWidth: 0 }, children: /* @__PURE__ */ jsxRuntime.jsxs(ChartCard, { children: [
|
|
275
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "center", style: { marginBottom: 16 }, children: [
|
|
276
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.Monitor, {}),
|
|
277
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", fontWeight: "semiBold", tag: "h2", children: t("analytics.devices.title", "Devices") })
|
|
278
|
-
] }),
|
|
279
|
-
/* @__PURE__ */ jsxRuntime.jsx(BarChart, { children: analytics?.devices && Object.entries(analytics.devices).sort(([, a], [, b]) => b - a).map(([device, count]) => /* @__PURE__ */ jsxRuntime.jsxs(BarRow, { children: [
|
|
280
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral700", style: { flex: "0 0 96px", minWidth: 0, overflowWrap: "anywhere" }, children: device }),
|
|
281
|
-
/* @__PURE__ */ jsxRuntime.jsxs(BarContainer, { children: [
|
|
282
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
283
|
-
BarFill,
|
|
284
|
-
{
|
|
285
|
-
$percentage: count / maxDevices * 100
|
|
286
|
-
}
|
|
287
|
-
),
|
|
288
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "semiBold", textColor: "neutral800", style: { position: "absolute", top: "50%", right: 8, transform: "translateY(-50%)", fontVariantNumeric: "tabular-nums" }, children: count })
|
|
289
|
-
] })
|
|
290
|
-
] }, device)) })
|
|
291
|
-
] }) }),
|
|
292
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { flex: "1 1 320px", minWidth: 0 }, children: /* @__PURE__ */ jsxRuntime.jsxs(ChartCard, { children: [
|
|
293
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "center", style: { marginBottom: 16 }, children: [
|
|
294
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.Monitor, {}),
|
|
295
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", fontWeight: "semiBold", tag: "h2", children: t("analytics.browsers.title", "Browsers") })
|
|
296
|
-
] }),
|
|
297
|
-
/* @__PURE__ */ jsxRuntime.jsx(BarChart, { children: analytics?.browsers && Object.entries(analytics.browsers).sort(([, a], [, b]) => b - a).map(([browser, count]) => /* @__PURE__ */ jsxRuntime.jsxs(BarRow, { children: [
|
|
298
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral700", style: { flex: "0 0 96px", minWidth: 0, overflowWrap: "anywhere" }, children: browser }),
|
|
299
|
-
/* @__PURE__ */ jsxRuntime.jsxs(BarContainer, { children: [
|
|
300
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
301
|
-
BarFill,
|
|
302
|
-
{
|
|
303
|
-
$percentage: count / maxBrowsers * 100
|
|
304
|
-
}
|
|
305
|
-
),
|
|
306
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "semiBold", textColor: "neutral800", style: { position: "absolute", top: "50%", right: 8, transform: "translateY(-50%)", fontVariantNumeric: "tabular-nums" }, children: count })
|
|
307
|
-
] })
|
|
308
|
-
] }, browser)) })
|
|
309
|
-
] }) })
|
|
310
|
-
] }),
|
|
311
|
-
/* @__PURE__ */ jsxRuntime.jsxs(ChartCard, { children: [
|
|
312
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { alignItems: "center", justifyContent: "space-between", children: [
|
|
313
|
-
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "center", children: [
|
|
314
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.Clock, {}),
|
|
315
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", fontWeight: "semiBold", tag: "h2", children: t("analytics.duration.title", "Average session duration") })
|
|
316
|
-
] }),
|
|
317
|
-
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { variant: "primary", size: "M", children: t("analytics.duration.minutes", "{count} min", { count: analytics?.avgSessionDuration || 0 }) })
|
|
318
|
-
] }),
|
|
319
|
-
analytics?.avgSessionDuration > 0 && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginTop: 4, padding: 4, background: "neutral100", hasRadius: true, children: /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "pi", textColor: "neutral700", tag: "p", children: t("analytics.duration.description", "Average time between login and last activity. Higher values can indicate idle or abandoned sessions.") }) })
|
|
320
|
-
] })
|
|
321
|
-
] }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
322
|
-
designSystem.EmptyStateLayout,
|
|
323
|
-
{
|
|
324
|
-
icon: /* @__PURE__ */ jsxRuntime.jsx(icons.ChartBubble, { "aria-hidden": "true" }),
|
|
325
|
-
content: t("analytics.empty", "Session analytics will appear here after end users sign in.")
|
|
326
|
-
}
|
|
327
|
-
)
|
|
328
|
-
] })
|
|
329
|
-
}
|
|
330
|
-
);
|
|
331
|
-
};
|
|
332
|
-
exports.default = AnalyticsPage;
|