strapi-plugin-magic-sessionmanager 4.8.0 → 4.9.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 (72) hide show
  1. package/CHANGELOG.md +90 -5
  2. package/README.md +379 -641
  3. package/dist/admin/Analytics-dyJmyxO-.mjs +418 -0
  4. package/dist/admin/Analytics-lVDnHBYp.js +420 -0
  5. package/dist/admin/App-CdgiY_Y7.js +1896 -0
  6. package/dist/admin/App-Cgf_CSjw.mjs +1894 -0
  7. package/dist/admin/License-1XUfQty5.js +443 -0
  8. package/dist/admin/License-C4WSYoqY.mjs +443 -0
  9. package/dist/admin/OnlineUsersWidget-DJC4V1KS.mjs +255 -0
  10. package/dist/admin/OnlineUsersWidget-DMPtuIpm.js +274 -0
  11. package/dist/admin/SectionCard-BlWv8CRt.js +54 -0
  12. package/dist/admin/SectionCard-D51bv4Hi.mjs +55 -0
  13. package/dist/admin/Settings-0QsyY7fe.js +3570 -0
  14. package/dist/admin/Settings-DgeuUiMF.mjs +3568 -0
  15. package/dist/admin/de-BFKoGEVT.js +544 -0
  16. package/dist/admin/de-j0oZH9Pz.mjs +544 -0
  17. package/dist/admin/en-UY4Tb5tE.mjs +544 -0
  18. package/dist/admin/en-s7Ksdkcg.js +544 -0
  19. package/dist/admin/es-07OGMe_5.js +544 -0
  20. package/dist/admin/es-DGBcZwQy.mjs +544 -0
  21. package/dist/admin/fr-B6-DWhGO.mjs +544 -0
  22. package/dist/admin/fr-ETj_2UBY.js +544 -0
  23. package/dist/admin/index-Ck19e8qw.mjs +1760 -0
  24. package/dist/admin/index-D-Nr0TCm.js +1761 -0
  25. package/dist/admin/index.js +1 -1
  26. package/dist/admin/index.mjs +2 -2
  27. package/dist/admin/maskSensitiveValue-BWcSjow7.js +9 -0
  28. package/dist/admin/maskSensitiveValue-lLRhN_S7.mjs +10 -0
  29. package/dist/admin/pt-C7PwrQtV.js +544 -0
  30. package/dist/admin/pt-YMRLm9gx.mjs +544 -0
  31. package/dist/server/index.js +1092 -463
  32. package/dist/server/index.mjs +1092 -463
  33. package/package.json +10 -1
  34. package/pics/analytics.png +0 -0
  35. package/pics/dashboard-dark.png +0 -0
  36. package/pics/dashboard.png +0 -0
  37. package/pics/dashboardsessionmodal.png +0 -0
  38. package/pics/mobile-dashboard.png +0 -0
  39. package/pics/mobile-session.png +0 -0
  40. package/pics/sessioninfopanel.png +0 -0
  41. package/pics/settings1.png +0 -0
  42. package/pics/settings2.png +0 -0
  43. package/pics/widget.png +0 -0
  44. package/scripts/geoip-updater.cjs +35 -24
  45. package/dist/admin/Analytics-CaRlu5ad.js +0 -332
  46. package/dist/admin/Analytics-THqDbNX0.mjs +0 -330
  47. package/dist/admin/App-AbZwLHtF.js +0 -1263
  48. package/dist/admin/App-hSh7guii.mjs +0 -1261
  49. package/dist/admin/FormField-C8kIT2NE.mjs +0 -59
  50. package/dist/admin/FormField-b5KBvkrj.js +0 -60
  51. package/dist/admin/License-BXBVwUVu.mjs +0 -299
  52. package/dist/admin/License-CABdPwnd.js +0 -301
  53. package/dist/admin/OnlineUsersWidget-BnWFj9IM.mjs +0 -230
  54. package/dist/admin/OnlineUsersWidget-CPFAACSb.js +0 -230
  55. package/dist/admin/PluginPageLayout-BPFMcgrx.mjs +0 -42
  56. package/dist/admin/PluginPageLayout-DmNzMdqu.js +0 -43
  57. package/dist/admin/Settings-B4DNdeKx.js +0 -2152
  58. package/dist/admin/Settings-C4RsJosh.mjs +0 -2150
  59. package/dist/admin/de-AwIFTd9i.mjs +0 -450
  60. package/dist/admin/de-D23nmqnl.js +0 -450
  61. package/dist/admin/en-C5iYQ0mC.js +0 -450
  62. package/dist/admin/en-D6QEGeRh.mjs +0 -450
  63. package/dist/admin/es-CIXnsG-p.js +0 -435
  64. package/dist/admin/es-CnFfVdKw.mjs +0 -435
  65. package/dist/admin/fr-BglXE-W4.js +0 -435
  66. package/dist/admin/fr-DefoR7uH.mjs +0 -435
  67. package/dist/admin/index-BFVITQ-o.mjs +0 -624
  68. package/dist/admin/index-DlMm-NyK.js +0 -625
  69. package/dist/admin/maskSensitiveValue-1uGWmrfG.mjs +0 -20
  70. package/dist/admin/maskSensitiveValue-B9vhxPad.js +0 -19
  71. package/dist/admin/pt-J5sf7jiY.js +0 -435
  72. package/dist/admin/pt-TODwvNQA.mjs +0 -435
@@ -1,330 +0,0 @@
1
- import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
- import { useState, useEffect } from "react";
3
- import { useIntl } from "react-intl";
4
- import { useFetchClient } from "@strapi/strapi/admin";
5
- import styled from "styled-components";
6
- import { Loader, Alert, Button, Typography, Flex, Box, Badge, EmptyStateLayout } from "@strapi/design-system";
7
- import { ChartBubble, User, Clock, Monitor } from "@strapi/icons";
8
- import { g as getSessionStatus, p as pluginId, l as logSafeAdminError, R as ReadableText, a as getTranslation } from "./index-BFVITQ-o.mjs";
9
- import { P as PluginPageLayout } from "./PluginPageLayout-BPFMcgrx.mjs";
10
- function increment(target, key) {
11
- target[key] = (target[key] || 0) + 1;
12
- }
13
- function getUserKey(session) {
14
- return session?.user?.documentId || session?.user?.id || session?.user?.email || session?.user?.username || null;
15
- }
16
- function getDurationMinutes(session, now) {
17
- const start = Date.parse(session?.loginTime);
18
- if (!Number.isFinite(start)) return null;
19
- const endValue = session.logoutTime || session.lastActive;
20
- const end = endValue ? Date.parse(endValue) : now;
21
- if (!Number.isFinite(end)) return null;
22
- return Math.max(0, Math.floor((end - start) / 6e4));
23
- }
24
- function computeSessionAnalytics(sessions = [], { now = Date.now() } = {}) {
25
- const dayAgo = now - 24 * 60 * 60 * 1e3;
26
- const weekAgo = now - 7 * 24 * 60 * 60 * 1e3;
27
- const devices = {};
28
- const browsers = {};
29
- const operatingSystems = {};
30
- const loginHours = Array(24).fill(0);
31
- const uniqueUsers = /* @__PURE__ */ new Set();
32
- const uniqueIPs = /* @__PURE__ */ new Set();
33
- const durations = [];
34
- let todayLogins = 0;
35
- let weekLogins = 0;
36
- let loggedOut = 0;
37
- let terminated = 0;
38
- for (const session of sessions) {
39
- const ua = String(session?.userAgent || "").toLowerCase();
40
- const loginTime = Date.parse(session?.loginTime);
41
- if (Number.isFinite(loginTime)) {
42
- if (loginTime > dayAgo) todayLogins++;
43
- if (loginTime > weekAgo) weekLogins++;
44
- loginHours[new Date(loginTime).getHours()]++;
45
- }
46
- if (ua.includes("tablet") || ua.includes("ipad") || ua.includes("android") && !ua.includes("mobile")) {
47
- increment(devices, "Tablet");
48
- } else if (ua.includes("mobile") || ua.includes("android") || ua.includes("iphone")) {
49
- increment(devices, "Mobile");
50
- } else {
51
- increment(devices, "Desktop");
52
- }
53
- if (ua.includes("edg")) increment(browsers, "Edge");
54
- else if (ua.includes("chrome")) increment(browsers, "Chrome");
55
- else if (ua.includes("firefox")) increment(browsers, "Firefox");
56
- else if (ua.includes("safari")) increment(browsers, "Safari");
57
- else if (ua.includes("postman") || ua.includes("curl")) increment(browsers, "API Client");
58
- else increment(browsers, "Other");
59
- if (ua.includes("android")) increment(operatingSystems, "Android");
60
- else if (ua.includes("ios") || ua.includes("iphone") || ua.includes("ipad")) increment(operatingSystems, "iOS");
61
- else if (ua.includes("windows") || ua.includes("win32") || ua.includes("win64")) increment(operatingSystems, "Windows");
62
- else if (ua.includes("mac") || ua.includes("darwin")) increment(operatingSystems, "macOS");
63
- else if (ua.includes("linux")) increment(operatingSystems, "Linux");
64
- else increment(operatingSystems, "Other");
65
- const userKey = getUserKey(session);
66
- if (userKey) uniqueUsers.add(userKey);
67
- if (session?.ipAddress) uniqueIPs.add(session.ipAddress);
68
- const status = getSessionStatus(session);
69
- if (status === "loggedout") loggedOut++;
70
- else if (!session?.isActive && status === "terminated") terminated++;
71
- const duration = getDurationMinutes(session, now);
72
- if (duration !== null) durations.push(duration);
73
- }
74
- const mobileCount = (devices.Mobile || 0) + (devices.Tablet || 0);
75
- return {
76
- totalSessions: sessions.length,
77
- activeSessions: sessions.filter((session) => session?.isActive && session?.isTrulyActive).length,
78
- todayLogins,
79
- weekLogins,
80
- devices,
81
- browsers,
82
- operatingSystems,
83
- loginHours,
84
- peakHour: loginHours.indexOf(Math.max(...loginHours)),
85
- uniqueUsers: uniqueUsers.size,
86
- uniqueIPs: uniqueIPs.size,
87
- loggedOut,
88
- terminated,
89
- mobileRatio: sessions.length > 0 ? Math.round(mobileCount / sessions.length * 100) : 0,
90
- avgSessionDuration: durations.length > 0 ? Math.floor(durations.reduce((sum, duration) => sum + duration, 0) / durations.length) : 0
91
- };
92
- }
93
- const Container = styled(Box)`
94
- width: 100%;
95
- min-width: 0;
96
- `;
97
- const StatsGrid = styled.div`
98
- display: grid;
99
- grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
100
- gap: 12px;
101
- min-width: 0;
102
- margin-bottom: 16px;
103
- `;
104
- const StatCard = styled(Box)`
105
- background: ${(p) => p.theme.colors.neutral0};
106
- border: 1px solid ${(p) => p.theme.colors.neutral150};
107
- border-top: 3px solid ${(p) => p.theme.colors.primary600};
108
- border-radius: 4px;
109
- min-width: 0;
110
- padding: 16px;
111
- display: flex;
112
- flex-direction: column;
113
- align-items: flex-start;
114
- gap: 4px;
115
-
116
- && > p {
117
- max-width: none;
118
- margin: 0;
119
- line-height: 1.25;
120
- }
121
-
122
- && > p + p {
123
- margin-block-start: 0;
124
- }
125
- `;
126
- const StatIcon = styled(Box)`
127
- width: 36px;
128
- height: 36px;
129
- border-radius: 4px;
130
- display: flex;
131
- align-items: center;
132
- justify-content: center;
133
- background: ${(p) => p.theme.colors.primary100};
134
- color: ${(p) => p.theme.colors.primary600};
135
- margin-bottom: 8px;
136
-
137
- svg {
138
- width: 20px;
139
- height: 20px;
140
- }
141
- `;
142
- const ChartCard = styled(Box)`
143
- background: ${(p) => p.theme.colors.neutral0};
144
- border-radius: 4px;
145
- border: 1px solid ${(p) => p.theme.colors.neutral150};
146
- min-width: 0;
147
- padding: 20px;
148
- `;
149
- const BarChart = styled.div`
150
- display: flex;
151
- flex-direction: column;
152
- gap: 12px;
153
- min-width: 0;
154
- `;
155
- const BarRow = styled.div`
156
- display: flex;
157
- align-items: center;
158
- gap: 12px;
159
- min-width: 0;
160
- `;
161
- const BarContainer = styled.div`
162
- flex: 1;
163
- min-width: 0;
164
- height: 28px;
165
- background: ${(p) => p.theme.colors.neutral100};
166
- border-radius: 4px;
167
- overflow: hidden;
168
- position: relative;
169
- `;
170
- const BarFill = styled.div`
171
- height: 100%;
172
- width: ${(props) => `${Math.max(0, Math.min(100, props.$percentage || 0))}%`};
173
- background: ${(p) => p.theme.colors.primary600};
174
- border-radius: 4px;
175
- `;
176
- const LoadingOverlay = styled(Flex)`
177
- min-height: 240px;
178
- align-items: center;
179
- justify-content: center;
180
- `;
181
- const AnalyticsPage = () => {
182
- const { formatMessage } = useIntl();
183
- const { get } = useFetchClient();
184
- const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
185
- const [loading, setLoading] = useState(true);
186
- const [analytics, setAnalytics] = useState(null);
187
- const [loadError, setLoadError] = useState(false);
188
- useEffect(() => {
189
- fetchAnalytics();
190
- }, []);
191
- const fetchAnalytics = async () => {
192
- setLoading(true);
193
- setLoadError(false);
194
- try {
195
- const { data } = await get(`/${pluginId}/sessions`);
196
- const sessions = data.data || [];
197
- setAnalytics(computeSessionAnalytics(sessions));
198
- } catch (err) {
199
- setLoadError(true);
200
- logSafeAdminError("analytics.load", err);
201
- } finally {
202
- setLoading(false);
203
- }
204
- };
205
- if (loading) {
206
- return /* @__PURE__ */ jsx(
207
- PluginPageLayout,
208
- {
209
- headingId: "magic-sessionmanager-analytics-title",
210
- title: t("analytics.title", "Session Analytics"),
211
- subtitle: t("analytics.subtitle", "Session activity and device trends"),
212
- children: /* @__PURE__ */ jsx(LoadingOverlay, { children: /* @__PURE__ */ jsx(Loader, { children: t("analytics.loading", "Loading analytics data...") }) })
213
- }
214
- );
215
- }
216
- if (loadError) {
217
- return /* @__PURE__ */ jsx(
218
- PluginPageLayout,
219
- {
220
- headingId: "magic-sessionmanager-analytics-title",
221
- title: t("analytics.title", "Session Analytics"),
222
- subtitle: t("analytics.subtitle", "Session activity and device trends"),
223
- children: /* @__PURE__ */ jsx(
224
- Alert,
225
- {
226
- variant: "danger",
227
- title: t("analytics.error.title", "Analytics could not be loaded"),
228
- closeLabel: t("common.close", "Close"),
229
- action: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: fetchAnalytics, children: t("common.retry", "Retry") }),
230
- children: /* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral700", tag: "span", children: t("analytics.error.description", "Try again. If the problem continues, check session API access and permissions.") })
231
- }
232
- )
233
- }
234
- );
235
- }
236
- const maxDevices = Math.max(...Object.values(analytics?.devices || {}), 1);
237
- const maxBrowsers = Math.max(...Object.values(analytics?.browsers || {}), 1);
238
- const hasSessions = Number(analytics?.totalSessions) > 0;
239
- return /* @__PURE__ */ jsx(
240
- PluginPageLayout,
241
- {
242
- headingId: "magic-sessionmanager-analytics-title",
243
- title: t("analytics.title", "Session Analytics"),
244
- subtitle: t("analytics.subtitle", "Session activity and device trends"),
245
- children: /* @__PURE__ */ jsxs(Container, { children: [
246
- /* @__PURE__ */ jsxs(StatsGrid, { children: [
247
- /* @__PURE__ */ jsxs(StatCard, { padding: 4, background: "neutral0", children: [
248
- /* @__PURE__ */ jsx(StatIcon, { "aria-hidden": "true", children: /* @__PURE__ */ jsx(ChartBubble, {}) }),
249
- /* @__PURE__ */ jsx(Typography, { variant: "delta", fontWeight: "semiBold", tag: "p", children: analytics?.totalSessions || 0 }),
250
- /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: t("analytics.stats.total", "Total sessions") })
251
- ] }),
252
- /* @__PURE__ */ jsxs(StatCard, { padding: 4, background: "neutral0", children: [
253
- /* @__PURE__ */ jsx(StatIcon, { "aria-hidden": "true", children: /* @__PURE__ */ jsx(User, {}) }),
254
- /* @__PURE__ */ jsx(Typography, { variant: "delta", fontWeight: "semiBold", tag: "p", children: analytics?.activeSessions || 0 }),
255
- /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: t("analytics.stats.active", "Online now") })
256
- ] }),
257
- /* @__PURE__ */ jsxs(StatCard, { padding: 4, background: "neutral0", children: [
258
- /* @__PURE__ */ jsx(StatIcon, { "aria-hidden": "true", children: /* @__PURE__ */ jsx(Clock, {}) }),
259
- /* @__PURE__ */ jsx(Typography, { variant: "delta", fontWeight: "semiBold", tag: "p", children: analytics?.todayLogins || 0 }),
260
- /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: t("analytics.stats.today", "Logins today") })
261
- ] }),
262
- /* @__PURE__ */ jsxs(StatCard, { padding: 4, background: "neutral0", children: [
263
- /* @__PURE__ */ jsx(StatIcon, { "aria-hidden": "true", children: /* @__PURE__ */ jsx(Clock, {}) }),
264
- /* @__PURE__ */ jsx(Typography, { variant: "delta", fontWeight: "semiBold", tag: "p", children: analytics?.weekLogins || 0 }),
265
- /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", tag: "p", children: t("analytics.stats.week", "Logins this week") })
266
- ] })
267
- ] }),
268
- hasSessions ? /* @__PURE__ */ jsxs(Fragment, { children: [
269
- /* @__PURE__ */ jsxs(Flex, { gap: 4, wrap: "wrap", style: { marginBottom: "28px" }, children: [
270
- /* @__PURE__ */ jsx(Box, { style: { flex: "1 1 320px", minWidth: 0 }, children: /* @__PURE__ */ jsxs(ChartCard, { children: [
271
- /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", style: { marginBottom: 16 }, children: [
272
- /* @__PURE__ */ jsx(Monitor, {}),
273
- /* @__PURE__ */ jsx(Typography, { variant: "epsilon", fontWeight: "semiBold", tag: "h2", children: t("analytics.devices.title", "Devices") })
274
- ] }),
275
- /* @__PURE__ */ jsx(BarChart, { children: analytics?.devices && Object.entries(analytics.devices).sort(([, a], [, b]) => b - a).map(([device, count]) => /* @__PURE__ */ jsxs(BarRow, { children: [
276
- /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral700", style: { flex: "0 0 96px", minWidth: 0, overflowWrap: "anywhere" }, children: device }),
277
- /* @__PURE__ */ jsxs(BarContainer, { children: [
278
- /* @__PURE__ */ jsx(
279
- BarFill,
280
- {
281
- $percentage: count / maxDevices * 100
282
- }
283
- ),
284
- /* @__PURE__ */ jsx(Typography, { variant: "pi", fontWeight: "semiBold", textColor: "neutral800", style: { position: "absolute", top: "50%", right: 8, transform: "translateY(-50%)", fontVariantNumeric: "tabular-nums" }, children: count })
285
- ] })
286
- ] }, device)) })
287
- ] }) }),
288
- /* @__PURE__ */ jsx(Box, { style: { flex: "1 1 320px", minWidth: 0 }, children: /* @__PURE__ */ jsxs(ChartCard, { children: [
289
- /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", style: { marginBottom: 16 }, children: [
290
- /* @__PURE__ */ jsx(Monitor, {}),
291
- /* @__PURE__ */ jsx(Typography, { variant: "epsilon", fontWeight: "semiBold", tag: "h2", children: t("analytics.browsers.title", "Browsers") })
292
- ] }),
293
- /* @__PURE__ */ jsx(BarChart, { children: analytics?.browsers && Object.entries(analytics.browsers).sort(([, a], [, b]) => b - a).map(([browser, count]) => /* @__PURE__ */ jsxs(BarRow, { children: [
294
- /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral700", style: { flex: "0 0 96px", minWidth: 0, overflowWrap: "anywhere" }, children: browser }),
295
- /* @__PURE__ */ jsxs(BarContainer, { children: [
296
- /* @__PURE__ */ jsx(
297
- BarFill,
298
- {
299
- $percentage: count / maxBrowsers * 100
300
- }
301
- ),
302
- /* @__PURE__ */ jsx(Typography, { variant: "pi", fontWeight: "semiBold", textColor: "neutral800", style: { position: "absolute", top: "50%", right: 8, transform: "translateY(-50%)", fontVariantNumeric: "tabular-nums" }, children: count })
303
- ] })
304
- ] }, browser)) })
305
- ] }) })
306
- ] }),
307
- /* @__PURE__ */ jsxs(ChartCard, { children: [
308
- /* @__PURE__ */ jsxs(Flex, { alignItems: "center", justifyContent: "space-between", children: [
309
- /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", children: [
310
- /* @__PURE__ */ jsx(Clock, {}),
311
- /* @__PURE__ */ jsx(Typography, { variant: "epsilon", fontWeight: "semiBold", tag: "h2", children: t("analytics.duration.title", "Average session duration") })
312
- ] }),
313
- /* @__PURE__ */ jsx(Badge, { variant: "primary", size: "M", children: t("analytics.duration.minutes", "{count} min", { count: analytics?.avgSessionDuration || 0 }) })
314
- ] }),
315
- analytics?.avgSessionDuration > 0 && /* @__PURE__ */ jsx(Box, { marginTop: 4, padding: 4, background: "neutral100", hasRadius: true, children: /* @__PURE__ */ jsx(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.") }) })
316
- ] })
317
- ] }) : /* @__PURE__ */ jsx(
318
- EmptyStateLayout,
319
- {
320
- icon: /* @__PURE__ */ jsx(ChartBubble, { "aria-hidden": "true" }),
321
- content: t("analytics.empty", "Session analytics will appear here after end users sign in.")
322
- }
323
- )
324
- ] })
325
- }
326
- );
327
- };
328
- export {
329
- AnalyticsPage as default
330
- };