strapi-plugin-magic-sessionmanager 4.7.2 → 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.
Files changed (71) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/README.md +380 -663
  3. package/dist/admin/Analytics-B6d-39Qh.js +420 -0
  4. package/dist/admin/Analytics-DxOWXHn8.mjs +418 -0
  5. package/dist/admin/App-ZsSGj7n8.mjs +1894 -0
  6. package/dist/admin/App-mRFV50K6.js +1896 -0
  7. package/dist/admin/License-BE6UQ_V3.mjs +443 -0
  8. package/dist/admin/License-DXt2oi6u.js +443 -0
  9. package/dist/admin/OnlineUsersWidget-CFvM3Vbp.js +273 -0
  10. package/dist/admin/OnlineUsersWidget-_tJ6aeWl.mjs +254 -0
  11. package/dist/admin/SectionCard-BlWv8CRt.js +54 -0
  12. package/dist/admin/SectionCard-D51bv4Hi.mjs +55 -0
  13. package/dist/admin/Settings-BUc12TP5.js +3570 -0
  14. package/dist/admin/Settings-dtW7cjTX.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-C_SyRULc.mjs +1750 -0
  24. package/dist/admin/index-D4kEnXSp.js +1751 -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 +3555 -6350
  32. package/dist/server/index.mjs +3555 -6350
  33. package/package.json +30 -19
  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 +266 -36
  45. package/scripts/update-geoip-db.mjs +3 -0
  46. package/dist/admin/Analytics-CsrpxJwQ.mjs +0 -497
  47. package/dist/admin/Analytics-D03ZNNMR.js +0 -499
  48. package/dist/admin/App-B2VCS3cz.js +0 -1481
  49. package/dist/admin/App-qxKnK7G2.mjs +0 -1479
  50. package/dist/admin/License-ClW7sZLR.mjs +0 -318
  51. package/dist/admin/License-fixnQ7wF.js +0 -320
  52. package/dist/admin/OnlineUsersWidget-mR_OMiwi.mjs +0 -185
  53. package/dist/admin/OnlineUsersWidget-qb9utPBy.js +0 -185
  54. package/dist/admin/Settings-U3V4eGMo.mjs +0 -2038
  55. package/dist/admin/Settings-gv2BF54w.js +0 -2040
  56. package/dist/admin/StyledButtons-Cz8oYhmc.mjs +0 -418
  57. package/dist/admin/StyledButtons-DDuxnYz8.js +0 -419
  58. package/dist/admin/de-BnqGCokx.js +0 -316
  59. package/dist/admin/de-JBE-iylO.mjs +0 -316
  60. package/dist/admin/en-BRmVwd8-.js +0 -316
  61. package/dist/admin/en-kQWtdEai.mjs +0 -316
  62. package/dist/admin/es-CH691xcL.js +0 -301
  63. package/dist/admin/es-DOQvBxih.mjs +0 -301
  64. package/dist/admin/fr-CLExO0w_.js +0 -301
  65. package/dist/admin/fr-CmfCpepX.mjs +0 -301
  66. package/dist/admin/index-B_lFjUAg.mjs +0 -551
  67. package/dist/admin/index-Duc7cR_d.js +0 -552
  68. package/dist/admin/pt-BJ_F0yNi.js +0 -301
  69. package/dist/admin/pt-BSzZdyAH.mjs +0 -301
  70. package/dist/admin/sessionStatus-D_fWEzgj.js +0 -11
  71. package/dist/admin/sessionStatus-kwggjEMw.mjs +0 -12
@@ -0,0 +1,273 @@
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 styled = require("styled-components");
7
+ const designSystem = require("@strapi/design-system");
8
+ const icons = require("@strapi/icons");
9
+ const StrapiAdmin = require("@strapi/strapi/admin");
10
+ const index = require("./index-D4kEnXSp.js");
11
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
12
+ function _interopNamespace(e) {
13
+ if (e && e.__esModule) return e;
14
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
15
+ if (e) {
16
+ for (const k in e) {
17
+ if (k !== "default") {
18
+ const d = Object.getOwnPropertyDescriptor(e, k);
19
+ Object.defineProperty(n, k, d.get ? d : {
20
+ enumerable: true,
21
+ get: () => e[k]
22
+ });
23
+ }
24
+ }
25
+ }
26
+ n.default = e;
27
+ return Object.freeze(n);
28
+ }
29
+ const styled__default = /* @__PURE__ */ _interopDefault(styled);
30
+ const StrapiAdmin__namespace = /* @__PURE__ */ _interopNamespace(StrapiAdmin);
31
+ function getSessionUserKey(session) {
32
+ return session?.user?.documentId || session?.user?.id || session?.user?.email || session?.user?.username || null;
33
+ }
34
+ function normalizeUserCounts(response) {
35
+ const totalUsers = response?.data?.totalUsers;
36
+ const blockedUsers = response?.data?.blockedUsers;
37
+ if (response?.success !== true || !Number.isSafeInteger(totalUsers) || totalUsers < 0 || !Number.isSafeInteger(blockedUsers) || blockedUsers < 0 || blockedUsers > totalUsers) {
38
+ return null;
39
+ }
40
+ return { totalUsers, blockedUsers };
41
+ }
42
+ function computeWidgetStats(sessions) {
43
+ const rows = Array.isArray(sessions) ? sessions : [];
44
+ const onlineUsers = /* @__PURE__ */ new Set();
45
+ let activeSessions = 0;
46
+ let idleSessions = 0;
47
+ for (const session of rows) {
48
+ if (!session || typeof session !== "object" || session.isActive !== true) continue;
49
+ if (session.isTrulyActive === true) {
50
+ activeSessions += 1;
51
+ const userKey = getSessionUserKey(session);
52
+ if (userKey) onlineUsers.add(userKey);
53
+ } else {
54
+ idleSessions += 1;
55
+ }
56
+ }
57
+ return {
58
+ onlineUsers: onlineUsers.size,
59
+ activeSessions,
60
+ idleSessions,
61
+ sessionCount: rows.length
62
+ };
63
+ }
64
+ const REFRESH_INTERVAL_MS = 3e4;
65
+ const pickAdminExport = (name) => {
66
+ try {
67
+ return StrapiAdmin__namespace[name];
68
+ } catch {
69
+ return void 0;
70
+ }
71
+ };
72
+ const NativeWidget = pickAdminExport("Widget");
73
+ const hasNativeState = (state) => typeof NativeWidget?.[state] === "function";
74
+ const TileFrame = styled__default.default.div`
75
+ width: 100%;
76
+ min-width: 0;
77
+ border: 1px solid ${({ theme }) => theme.colors.neutral200};
78
+ border-radius: ${({ theme }) => theme.borderRadius};
79
+ overflow: hidden;
80
+ container-type: inline-size;
81
+
82
+ @container (max-width: 28rem) {
83
+ & [data-tile-icon] {
84
+ display: none;
85
+ }
86
+ }
87
+ `;
88
+ const TileGrid = styled__default.default.div`
89
+ display: grid;
90
+ grid-template-columns: repeat(2, minmax(0, 1fr));
91
+ grid-auto-rows: 1fr;
92
+ gap: 0;
93
+ min-width: 0;
94
+ margin: 0 -1px -1px 0;
95
+
96
+ & > [data-widget-tile] {
97
+ border-right: 1px solid ${({ theme }) => theme.colors.neutral200};
98
+ border-bottom: 1px solid ${({ theme }) => theme.colors.neutral200};
99
+ overflow-wrap: anywhere;
100
+ }
101
+ `;
102
+ const TileIcon = styled__default.default(designSystem.Flex)`
103
+ svg path {
104
+ fill: ${({ theme, $tone }) => theme.colors[`${$tone}600`]};
105
+ }
106
+ `;
107
+ const StatTile = ({ icon: Icon, tone, label, value, detail }) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { background: "neutral0", padding: 3, minWidth: 0, height: "100%", "data-widget-tile": "", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "flex-start", minWidth: 0, children: [
108
+ /* @__PURE__ */ jsxRuntime.jsx(
109
+ TileIcon,
110
+ {
111
+ $tone: tone,
112
+ background: `${tone}100`,
113
+ hasRadius: true,
114
+ padding: 2,
115
+ shrink: 0,
116
+ justifyContent: "center",
117
+ alignItems: "center",
118
+ "aria-hidden": true,
119
+ "data-tile-icon": "",
120
+ children: /* @__PURE__ */ jsxRuntime.jsx(Icon, { "aria-hidden": true, focusable: false })
121
+ }
122
+ ),
123
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", minWidth: 0, children: [
124
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", textColor: "neutral600", children: label }),
125
+ value === null ? /* @__PURE__ */ jsxRuntime.jsx(index.MissingValue, { variant: "omega", textColor: "neutral800" }) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "bold", textColor: "neutral800", children: value }),
126
+ detail ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: detail }) : null
127
+ ] })
128
+ ] }) });
129
+ const LoadingState = ({ label }) => {
130
+ if (hasNativeState("Loading")) return /* @__PURE__ */ jsxRuntime.jsx(NativeWidget.Loading, { children: label });
131
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { height: "100%", justifyContent: "center", alignItems: "center", padding: 4, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { small: true, children: label }) });
132
+ };
133
+ const CenteredText = styled__default.default(designSystem.Box)`
134
+ text-align: center;
135
+ `;
136
+ const ErrorState = ({ message, retryLabel, onRetry }) => /* @__PURE__ */ jsxRuntime.jsxs(
137
+ designSystem.Flex,
138
+ {
139
+ direction: "column",
140
+ alignItems: "center",
141
+ justifyContent: "center",
142
+ gap: 4,
143
+ height: "100%",
144
+ role: "alert",
145
+ children: [
146
+ hasNativeState("Error") ? /* @__PURE__ */ jsxRuntime.jsx(CenteredText, { children: /* @__PURE__ */ jsxRuntime.jsx(NativeWidget.Error, { children: message }) }) : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "center", gap: 2, children: [
147
+ /* @__PURE__ */ jsxRuntime.jsx(TileIcon, { $tone: "danger", "aria-hidden": true, children: /* @__PURE__ */ jsxRuntime.jsx(icons.WarningCircle, { "aria-hidden": true, focusable: false }) }),
148
+ /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "omega", textColor: "neutral800", tag: "p", textAlign: "center", children: message })
149
+ ] }),
150
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "secondary", size: "S", onClick: onRetry, children: retryLabel })
151
+ ]
152
+ }
153
+ );
154
+ const EmptyState = ({ label }) => {
155
+ if (hasNativeState("NoData")) return /* @__PURE__ */ jsxRuntime.jsx(NativeWidget.NoData, { children: label });
156
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { height: "100%", justifyContent: "center", alignItems: "center", padding: 4, children: /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "omega", textColor: "neutral700", tag: "p", textAlign: "center", children: label }) });
157
+ };
158
+ const OnlineUsersWidget = () => {
159
+ const { formatMessage, formatNumber } = reactIntl.useIntl();
160
+ const { get } = StrapiAdmin.useFetchClient();
161
+ const t = (id, defaultMessage, values) => formatMessage({ id: index.getTranslation(id), defaultMessage }, values);
162
+ const [stats, setStats] = react.useState(null);
163
+ const [userCounts, setUserCounts] = react.useState(null);
164
+ const [loading, setLoading] = react.useState(true);
165
+ const [loadError, setLoadError] = react.useState(false);
166
+ const requestInProgress = react.useRef(false);
167
+ const fetchStats = react.useCallback(
168
+ async ({ showLoading = true } = {}) => {
169
+ if (requestInProgress.current) return;
170
+ requestInProgress.current = true;
171
+ try {
172
+ const [sessionResult, countResult] = await Promise.allSettled([
173
+ get("/magic-sessionmanager/sessions"),
174
+ get("/magic-sessionmanager/users/stats")
175
+ ]);
176
+ if (sessionResult.status === "rejected") throw sessionResult.reason;
177
+ setStats(computeWidgetStats(index.requireSessionList(sessionResult.value?.data)));
178
+ setLoadError(false);
179
+ const counts = countResult.status === "fulfilled" ? normalizeUserCounts(countResult.value?.data) : null;
180
+ if (counts) {
181
+ setUserCounts(counts);
182
+ } else {
183
+ index.logSafeAdminError(
184
+ "onlineUsers.loadUserCounts",
185
+ countResult.status === "rejected" ? countResult.reason : null
186
+ );
187
+ if (showLoading) setUserCounts(null);
188
+ }
189
+ } catch (error) {
190
+ index.logSafeAdminError("onlineUsers.loadSessions", error);
191
+ if (showLoading) setLoadError(true);
192
+ } finally {
193
+ if (showLoading) setLoading(false);
194
+ requestInProgress.current = false;
195
+ }
196
+ },
197
+ [get]
198
+ );
199
+ react.useEffect(() => {
200
+ void fetchStats();
201
+ const interval = setInterval(() => {
202
+ void fetchStats({ showLoading: false });
203
+ }, REFRESH_INTERVAL_MS);
204
+ return () => clearInterval(interval);
205
+ }, [fetchStats]);
206
+ if (loading) {
207
+ return /* @__PURE__ */ jsxRuntime.jsx(LoadingState, { label: t("widget.loading", "Loading online users") });
208
+ }
209
+ if (loadError || !stats) {
210
+ return /* @__PURE__ */ jsxRuntime.jsx(
211
+ ErrorState,
212
+ {
213
+ message: t("widget.error.message", "Online users could not be loaded."),
214
+ retryLabel: t("common.tryAgain", "Try again"),
215
+ onRetry: () => {
216
+ setLoading(true);
217
+ void fetchStats();
218
+ }
219
+ }
220
+ );
221
+ }
222
+ if (stats.sessionCount === 0) {
223
+ return /* @__PURE__ */ jsxRuntime.jsx(EmptyState, { label: t("widget.empty.noSignIns", "No users have signed in yet.") });
224
+ }
225
+ const onlineUsersDetail = userCounts ? t(
226
+ "widget.stats.registeredUsers",
227
+ "{total, plural, one {of # registered user} other {of # registered users}}",
228
+ { total: userCounts.totalUsers }
229
+ ) : t("widget.stats.userTotalsError", "User totals could not be loaded.");
230
+ const tiles = [
231
+ {
232
+ key: "onlineUsers",
233
+ icon: icons.User,
234
+ tone: "success",
235
+ label: t("widget.stats.onlineUsers", "Online users"),
236
+ value: formatNumber(stats.onlineUsers),
237
+ detail: onlineUsersDetail
238
+ },
239
+ {
240
+ key: "activeSessions",
241
+ icon: icons.Lightning,
242
+ tone: "primary",
243
+ label: t("widget.stats.activeSessions", "Active sessions"),
244
+ value: formatNumber(stats.activeSessions)
245
+ },
246
+ {
247
+ key: "idleSessions",
248
+ icon: icons.Clock,
249
+ tone: "warning",
250
+ label: t("widget.stats.idleSessions", "Idle sessions"),
251
+ value: formatNumber(stats.idleSessions)
252
+ },
253
+ {
254
+ key: "blockedUsers",
255
+ icon: icons.Lock,
256
+ tone: "neutral",
257
+ label: t("widget.stats.blockedUsers", "Blocked users"),
258
+ value: userCounts ? formatNumber(userCounts.blockedUsers) : null
259
+ }
260
+ ];
261
+ return /* @__PURE__ */ jsxRuntime.jsx(TileFrame, { children: /* @__PURE__ */ jsxRuntime.jsx(TileGrid, { role: "group", "aria-label": t("widget.online-users.title", "Online users"), children: tiles.map((tile) => /* @__PURE__ */ jsxRuntime.jsx(
262
+ StatTile,
263
+ {
264
+ icon: tile.icon,
265
+ tone: tile.tone,
266
+ label: tile.label,
267
+ value: tile.value,
268
+ detail: tile.detail
269
+ },
270
+ tile.key
271
+ )) }) });
272
+ };
273
+ exports.default = OnlineUsersWidget;
@@ -0,0 +1,254 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState, useRef, useCallback, useEffect } from "react";
3
+ import { useIntl } from "react-intl";
4
+ import styled from "styled-components";
5
+ import { Flex, Loader, Button, Box, Typography } from "@strapi/design-system";
6
+ import { User, Lightning, Clock, Lock, WarningCircle } from "@strapi/icons";
7
+ import * as StrapiAdmin from "@strapi/strapi/admin";
8
+ import { useFetchClient } from "@strapi/strapi/admin";
9
+ import { s as requireSessionList, n as logSafeAdminError, b as getTranslation, R as ReadableText, M as MissingValue } from "./index-C_SyRULc.mjs";
10
+ function getSessionUserKey(session) {
11
+ return session?.user?.documentId || session?.user?.id || session?.user?.email || session?.user?.username || null;
12
+ }
13
+ function normalizeUserCounts(response) {
14
+ const totalUsers = response?.data?.totalUsers;
15
+ const blockedUsers = response?.data?.blockedUsers;
16
+ if (response?.success !== true || !Number.isSafeInteger(totalUsers) || totalUsers < 0 || !Number.isSafeInteger(blockedUsers) || blockedUsers < 0 || blockedUsers > totalUsers) {
17
+ return null;
18
+ }
19
+ return { totalUsers, blockedUsers };
20
+ }
21
+ function computeWidgetStats(sessions) {
22
+ const rows = Array.isArray(sessions) ? sessions : [];
23
+ const onlineUsers = /* @__PURE__ */ new Set();
24
+ let activeSessions = 0;
25
+ let idleSessions = 0;
26
+ for (const session of rows) {
27
+ if (!session || typeof session !== "object" || session.isActive !== true) continue;
28
+ if (session.isTrulyActive === true) {
29
+ activeSessions += 1;
30
+ const userKey = getSessionUserKey(session);
31
+ if (userKey) onlineUsers.add(userKey);
32
+ } else {
33
+ idleSessions += 1;
34
+ }
35
+ }
36
+ return {
37
+ onlineUsers: onlineUsers.size,
38
+ activeSessions,
39
+ idleSessions,
40
+ sessionCount: rows.length
41
+ };
42
+ }
43
+ const REFRESH_INTERVAL_MS = 3e4;
44
+ const pickAdminExport = (name) => {
45
+ try {
46
+ return StrapiAdmin[name];
47
+ } catch {
48
+ return void 0;
49
+ }
50
+ };
51
+ const NativeWidget = pickAdminExport("Widget");
52
+ const hasNativeState = (state) => typeof NativeWidget?.[state] === "function";
53
+ const TileFrame = styled.div`
54
+ width: 100%;
55
+ min-width: 0;
56
+ border: 1px solid ${({ theme }) => theme.colors.neutral200};
57
+ border-radius: ${({ theme }) => theme.borderRadius};
58
+ overflow: hidden;
59
+ container-type: inline-size;
60
+
61
+ @container (max-width: 28rem) {
62
+ & [data-tile-icon] {
63
+ display: none;
64
+ }
65
+ }
66
+ `;
67
+ const TileGrid = styled.div`
68
+ display: grid;
69
+ grid-template-columns: repeat(2, minmax(0, 1fr));
70
+ grid-auto-rows: 1fr;
71
+ gap: 0;
72
+ min-width: 0;
73
+ margin: 0 -1px -1px 0;
74
+
75
+ & > [data-widget-tile] {
76
+ border-right: 1px solid ${({ theme }) => theme.colors.neutral200};
77
+ border-bottom: 1px solid ${({ theme }) => theme.colors.neutral200};
78
+ overflow-wrap: anywhere;
79
+ }
80
+ `;
81
+ const TileIcon = styled(Flex)`
82
+ svg path {
83
+ fill: ${({ theme, $tone }) => theme.colors[`${$tone}600`]};
84
+ }
85
+ `;
86
+ const StatTile = ({ icon: Icon, tone, label, value, detail }) => /* @__PURE__ */ jsx(Box, { background: "neutral0", padding: 3, minWidth: 0, height: "100%", "data-widget-tile": "", children: /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "flex-start", minWidth: 0, children: [
87
+ /* @__PURE__ */ jsx(
88
+ TileIcon,
89
+ {
90
+ $tone: tone,
91
+ background: `${tone}100`,
92
+ hasRadius: true,
93
+ padding: 2,
94
+ shrink: 0,
95
+ justifyContent: "center",
96
+ alignItems: "center",
97
+ "aria-hidden": true,
98
+ "data-tile-icon": "",
99
+ children: /* @__PURE__ */ jsx(Icon, { "aria-hidden": true, focusable: false })
100
+ }
101
+ ),
102
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", minWidth: 0, children: [
103
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", fontWeight: "bold", textColor: "neutral600", children: label }),
104
+ value === null ? /* @__PURE__ */ jsx(MissingValue, { variant: "omega", textColor: "neutral800" }) : /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "bold", textColor: "neutral800", children: value }),
105
+ detail ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: detail }) : null
106
+ ] })
107
+ ] }) });
108
+ const LoadingState = ({ label }) => {
109
+ if (hasNativeState("Loading")) return /* @__PURE__ */ jsx(NativeWidget.Loading, { children: label });
110
+ return /* @__PURE__ */ jsx(Flex, { height: "100%", justifyContent: "center", alignItems: "center", padding: 4, children: /* @__PURE__ */ jsx(Loader, { small: true, children: label }) });
111
+ };
112
+ const CenteredText = styled(Box)`
113
+ text-align: center;
114
+ `;
115
+ const ErrorState = ({ message, retryLabel, onRetry }) => /* @__PURE__ */ jsxs(
116
+ Flex,
117
+ {
118
+ direction: "column",
119
+ alignItems: "center",
120
+ justifyContent: "center",
121
+ gap: 4,
122
+ height: "100%",
123
+ role: "alert",
124
+ children: [
125
+ hasNativeState("Error") ? /* @__PURE__ */ jsx(CenteredText, { children: /* @__PURE__ */ jsx(NativeWidget.Error, { children: message }) }) : /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "center", gap: 2, children: [
126
+ /* @__PURE__ */ jsx(TileIcon, { $tone: "danger", "aria-hidden": true, children: /* @__PURE__ */ jsx(WarningCircle, { "aria-hidden": true, focusable: false }) }),
127
+ /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral800", tag: "p", textAlign: "center", children: message })
128
+ ] }),
129
+ /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "S", onClick: onRetry, children: retryLabel })
130
+ ]
131
+ }
132
+ );
133
+ const EmptyState = ({ label }) => {
134
+ if (hasNativeState("NoData")) return /* @__PURE__ */ jsx(NativeWidget.NoData, { children: label });
135
+ return /* @__PURE__ */ jsx(Flex, { height: "100%", justifyContent: "center", alignItems: "center", padding: 4, children: /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral700", tag: "p", textAlign: "center", children: label }) });
136
+ };
137
+ const OnlineUsersWidget = () => {
138
+ const { formatMessage, formatNumber } = useIntl();
139
+ const { get } = useFetchClient();
140
+ const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
141
+ const [stats, setStats] = useState(null);
142
+ const [userCounts, setUserCounts] = useState(null);
143
+ const [loading, setLoading] = useState(true);
144
+ const [loadError, setLoadError] = useState(false);
145
+ const requestInProgress = useRef(false);
146
+ const fetchStats = useCallback(
147
+ async ({ showLoading = true } = {}) => {
148
+ if (requestInProgress.current) return;
149
+ requestInProgress.current = true;
150
+ try {
151
+ const [sessionResult, countResult] = await Promise.allSettled([
152
+ get("/magic-sessionmanager/sessions"),
153
+ get("/magic-sessionmanager/users/stats")
154
+ ]);
155
+ if (sessionResult.status === "rejected") throw sessionResult.reason;
156
+ setStats(computeWidgetStats(requireSessionList(sessionResult.value?.data)));
157
+ setLoadError(false);
158
+ const counts = countResult.status === "fulfilled" ? normalizeUserCounts(countResult.value?.data) : null;
159
+ if (counts) {
160
+ setUserCounts(counts);
161
+ } else {
162
+ logSafeAdminError(
163
+ "onlineUsers.loadUserCounts",
164
+ countResult.status === "rejected" ? countResult.reason : null
165
+ );
166
+ if (showLoading) setUserCounts(null);
167
+ }
168
+ } catch (error) {
169
+ logSafeAdminError("onlineUsers.loadSessions", error);
170
+ if (showLoading) setLoadError(true);
171
+ } finally {
172
+ if (showLoading) setLoading(false);
173
+ requestInProgress.current = false;
174
+ }
175
+ },
176
+ [get]
177
+ );
178
+ useEffect(() => {
179
+ void fetchStats();
180
+ const interval = setInterval(() => {
181
+ void fetchStats({ showLoading: false });
182
+ }, REFRESH_INTERVAL_MS);
183
+ return () => clearInterval(interval);
184
+ }, [fetchStats]);
185
+ if (loading) {
186
+ return /* @__PURE__ */ jsx(LoadingState, { label: t("widget.loading", "Loading online users") });
187
+ }
188
+ if (loadError || !stats) {
189
+ return /* @__PURE__ */ jsx(
190
+ ErrorState,
191
+ {
192
+ message: t("widget.error.message", "Online users could not be loaded."),
193
+ retryLabel: t("common.tryAgain", "Try again"),
194
+ onRetry: () => {
195
+ setLoading(true);
196
+ void fetchStats();
197
+ }
198
+ }
199
+ );
200
+ }
201
+ if (stats.sessionCount === 0) {
202
+ return /* @__PURE__ */ jsx(EmptyState, { label: t("widget.empty.noSignIns", "No users have signed in yet.") });
203
+ }
204
+ const onlineUsersDetail = userCounts ? t(
205
+ "widget.stats.registeredUsers",
206
+ "{total, plural, one {of # registered user} other {of # registered users}}",
207
+ { total: userCounts.totalUsers }
208
+ ) : t("widget.stats.userTotalsError", "User totals could not be loaded.");
209
+ const tiles = [
210
+ {
211
+ key: "onlineUsers",
212
+ icon: User,
213
+ tone: "success",
214
+ label: t("widget.stats.onlineUsers", "Online users"),
215
+ value: formatNumber(stats.onlineUsers),
216
+ detail: onlineUsersDetail
217
+ },
218
+ {
219
+ key: "activeSessions",
220
+ icon: Lightning,
221
+ tone: "primary",
222
+ label: t("widget.stats.activeSessions", "Active sessions"),
223
+ value: formatNumber(stats.activeSessions)
224
+ },
225
+ {
226
+ key: "idleSessions",
227
+ icon: Clock,
228
+ tone: "warning",
229
+ label: t("widget.stats.idleSessions", "Idle sessions"),
230
+ value: formatNumber(stats.idleSessions)
231
+ },
232
+ {
233
+ key: "blockedUsers",
234
+ icon: Lock,
235
+ tone: "neutral",
236
+ label: t("widget.stats.blockedUsers", "Blocked users"),
237
+ value: userCounts ? formatNumber(userCounts.blockedUsers) : null
238
+ }
239
+ ];
240
+ return /* @__PURE__ */ jsx(TileFrame, { children: /* @__PURE__ */ jsx(TileGrid, { role: "group", "aria-label": t("widget.online-users.title", "Online users"), children: tiles.map((tile) => /* @__PURE__ */ jsx(
241
+ StatTile,
242
+ {
243
+ icon: tile.icon,
244
+ tone: tile.tone,
245
+ label: tile.label,
246
+ value: tile.value,
247
+ detail: tile.detail
248
+ },
249
+ tile.key
250
+ )) }) });
251
+ };
252
+ export {
253
+ OnlineUsersWidget as default
254
+ };
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ const jsxRuntime = require("react/jsx-runtime");
3
+ const react = require("react");
4
+ const designSystem = require("@strapi/design-system");
5
+ const SectionCard = ({
6
+ title,
7
+ subtitle,
8
+ action,
9
+ headingTag = "h2",
10
+ tone = "default",
11
+ fill = false,
12
+ id,
13
+ children
14
+ }) => {
15
+ const generatedId = react.useId();
16
+ const headingId = `${id || "section"}-heading-${generatedId.replace(/:/g, "")}`;
17
+ const hasHeader = Boolean(title || subtitle || action);
18
+ return /* @__PURE__ */ jsxRuntime.jsx(
19
+ designSystem.Box,
20
+ {
21
+ tag: "section",
22
+ id,
23
+ "aria-labelledby": title ? headingId : void 0,
24
+ background: "neutral0",
25
+ hasRadius: true,
26
+ shadow: "tableShadow",
27
+ borderColor: tone === "danger" ? "danger200" : void 0,
28
+ padding: { initial: 4, medium: 6 },
29
+ minWidth: 0,
30
+ height: fill ? "100%" : void 0,
31
+ "data-section-card": tone,
32
+ children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, height: fill ? "100%" : void 0, children: [
33
+ hasHeader ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "flex-start", gap: 4, wrap: "wrap", children: [
34
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "flex-start", gap: 1, minWidth: 0, flex: "1 1 auto", children: [
35
+ title ? /* @__PURE__ */ jsxRuntime.jsx(
36
+ designSystem.Typography,
37
+ {
38
+ id: headingId,
39
+ variant: "delta",
40
+ tag: headingTag,
41
+ textColor: tone === "danger" ? "danger700" : "neutral800",
42
+ children: title
43
+ }
44
+ ) : null,
45
+ subtitle ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: subtitle }) : null
46
+ ] }),
47
+ action ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { gap: 2, wrap: "wrap", children: action }) : null
48
+ ] }) : null,
49
+ children
50
+ ] })
51
+ }
52
+ );
53
+ };
54
+ exports.SectionCard = SectionCard;
@@ -0,0 +1,55 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useId } from "react";
3
+ import { Box, Flex, Typography } from "@strapi/design-system";
4
+ const SectionCard = ({
5
+ title,
6
+ subtitle,
7
+ action,
8
+ headingTag = "h2",
9
+ tone = "default",
10
+ fill = false,
11
+ id,
12
+ children
13
+ }) => {
14
+ const generatedId = useId();
15
+ const headingId = `${id || "section"}-heading-${generatedId.replace(/:/g, "")}`;
16
+ const hasHeader = Boolean(title || subtitle || action);
17
+ return /* @__PURE__ */ jsx(
18
+ Box,
19
+ {
20
+ tag: "section",
21
+ id,
22
+ "aria-labelledby": title ? headingId : void 0,
23
+ background: "neutral0",
24
+ hasRadius: true,
25
+ shadow: "tableShadow",
26
+ borderColor: tone === "danger" ? "danger200" : void 0,
27
+ padding: { initial: 4, medium: 6 },
28
+ minWidth: 0,
29
+ height: fill ? "100%" : void 0,
30
+ "data-section-card": tone,
31
+ children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 4, height: fill ? "100%" : void 0, children: [
32
+ hasHeader ? /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "flex-start", gap: 4, wrap: "wrap", children: [
33
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", gap: 1, minWidth: 0, flex: "1 1 auto", children: [
34
+ title ? /* @__PURE__ */ jsx(
35
+ Typography,
36
+ {
37
+ id: headingId,
38
+ variant: "delta",
39
+ tag: headingTag,
40
+ textColor: tone === "danger" ? "danger700" : "neutral800",
41
+ children: title
42
+ }
43
+ ) : null,
44
+ subtitle ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: subtitle }) : null
45
+ ] }),
46
+ action ? /* @__PURE__ */ jsx(Flex, { gap: 2, wrap: "wrap", children: action }) : null
47
+ ] }) : null,
48
+ children
49
+ ] })
50
+ }
51
+ );
52
+ };
53
+ export {
54
+ SectionCard as S
55
+ };