strapi-plugin-magic-sessionmanager 4.7.1 → 4.8.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 (52) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +17 -38
  3. package/dist/admin/Analytics-CaRlu5ad.js +332 -0
  4. package/dist/admin/Analytics-THqDbNX0.mjs +330 -0
  5. package/dist/admin/App-AbZwLHtF.js +1263 -0
  6. package/dist/admin/App-hSh7guii.mjs +1261 -0
  7. package/dist/admin/FormField-C8kIT2NE.mjs +59 -0
  8. package/dist/admin/FormField-b5KBvkrj.js +60 -0
  9. package/dist/admin/License-BXBVwUVu.mjs +299 -0
  10. package/dist/admin/License-CABdPwnd.js +301 -0
  11. package/dist/admin/OnlineUsersWidget-BnWFj9IM.mjs +230 -0
  12. package/dist/admin/OnlineUsersWidget-CPFAACSb.js +230 -0
  13. package/dist/admin/PluginPageLayout-BPFMcgrx.mjs +42 -0
  14. package/dist/admin/PluginPageLayout-DmNzMdqu.js +43 -0
  15. package/dist/admin/Settings-B4DNdeKx.js +2152 -0
  16. package/dist/admin/Settings-C4RsJosh.mjs +2150 -0
  17. package/dist/admin/{de-JBE-iylO.mjs → de-AwIFTd9i.mjs} +154 -20
  18. package/dist/admin/{de-BnqGCokx.js → de-D23nmqnl.js} +154 -20
  19. package/dist/admin/{en-BRmVwd8-.js → en-C5iYQ0mC.js} +155 -21
  20. package/dist/admin/{en-kQWtdEai.mjs → en-D6QEGeRh.mjs} +155 -21
  21. package/dist/admin/{es-CH691xcL.js → es-CIXnsG-p.js} +154 -20
  22. package/dist/admin/{es-DOQvBxih.mjs → es-CnFfVdKw.mjs} +154 -20
  23. package/dist/admin/{fr-CLExO0w_.js → fr-BglXE-W4.js} +154 -20
  24. package/dist/admin/{fr-CmfCpepX.mjs → fr-DefoR7uH.mjs} +154 -20
  25. package/dist/admin/index-BFVITQ-o.mjs +624 -0
  26. package/dist/admin/{index-Duc7cR_d.js → index-DlMm-NyK.js} +261 -188
  27. package/dist/admin/index.js +1 -1
  28. package/dist/admin/index.mjs +1 -1
  29. package/dist/admin/maskSensitiveValue-1uGWmrfG.mjs +20 -0
  30. package/dist/admin/maskSensitiveValue-B9vhxPad.js +19 -0
  31. package/dist/admin/{pt-BJ_F0yNi.js → pt-J5sf7jiY.js} +154 -20
  32. package/dist/admin/{pt-BSzZdyAH.mjs → pt-TODwvNQA.mjs} +154 -20
  33. package/dist/server/index.js +2812 -6159
  34. package/dist/server/index.mjs +2812 -6159
  35. package/package.json +21 -19
  36. package/scripts/geoip-updater.cjs +234 -15
  37. package/scripts/update-geoip-db.mjs +3 -0
  38. package/dist/admin/Analytics-CsrpxJwQ.mjs +0 -497
  39. package/dist/admin/Analytics-D03ZNNMR.js +0 -499
  40. package/dist/admin/App-B2VCS3cz.js +0 -1481
  41. package/dist/admin/App-qxKnK7G2.mjs +0 -1479
  42. package/dist/admin/License-ClW7sZLR.mjs +0 -318
  43. package/dist/admin/License-fixnQ7wF.js +0 -320
  44. package/dist/admin/OnlineUsersWidget-mR_OMiwi.mjs +0 -185
  45. package/dist/admin/OnlineUsersWidget-qb9utPBy.js +0 -185
  46. package/dist/admin/Settings-U3V4eGMo.mjs +0 -2038
  47. package/dist/admin/Settings-gv2BF54w.js +0 -2040
  48. package/dist/admin/StyledButtons-Cz8oYhmc.mjs +0 -418
  49. package/dist/admin/StyledButtons-DDuxnYz8.js +0 -419
  50. package/dist/admin/index-B_lFjUAg.mjs +0 -551
  51. package/dist/admin/sessionStatus-D_fWEzgj.js +0 -11
  52. package/dist/admin/sessionStatus-kwggjEMw.mjs +0 -12
@@ -0,0 +1,301 @@
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 designSystem = require("@strapi/design-system");
7
+ const admin = require("@strapi/strapi/admin");
8
+ const icons = require("@strapi/icons");
9
+ const styled = require("styled-components");
10
+ const index = require("./index-DlMm-NyK.js");
11
+ const PluginPageLayout = require("./PluginPageLayout-DmNzMdqu.js");
12
+ const maskSensitiveValue = require("./maskSensitiveValue-B9vhxPad.js");
13
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
14
+ const styled__default = /* @__PURE__ */ _interopDefault(styled);
15
+ const Container = styled__default.default(designSystem.Box)`
16
+ width: 100%;
17
+ min-width: 0;
18
+ `;
19
+ const LicenseKeyBanner = styled__default.default(designSystem.Box)`
20
+ background: ${(p) => p.theme.colors.neutral0};
21
+ border: 1px solid ${(p) => p.theme.colors.neutral150};
22
+ border-radius: 4px;
23
+ min-width: 0;
24
+ padding: 20px;
25
+ margin-bottom: 16px;
26
+ `;
27
+ const FeaturePanel = styled__default.default(designSystem.Box)`
28
+ border: 1px solid ${(p) => p.theme.colors.neutral150};
29
+ `;
30
+ const LoaderContainer = styled__default.default(designSystem.Flex)`
31
+ min-height: 400px;
32
+ align-items: center;
33
+ justify-content: center;
34
+ flex-direction: column;
35
+ gap: 16px;
36
+ `;
37
+ const LicensePage = () => {
38
+ const { formatMessage, locale } = reactIntl.useIntl();
39
+ const { get } = admin.useFetchClient();
40
+ const { toggleNotification } = admin.useNotification();
41
+ const t = (id, defaultMessage, values) => formatMessage({ id: index.getTranslation(id), defaultMessage }, values);
42
+ const [loading, setLoading] = react.useState(true);
43
+ const [licenseData, setLicenseData] = react.useState(null);
44
+ const [showLicenseKey, setShowLicenseKey] = react.useState(false);
45
+ const [error, setError] = react.useState(null);
46
+ const fetchLicenseStatus = async () => {
47
+ setLoading(true);
48
+ setShowLicenseKey(false);
49
+ setError(null);
50
+ try {
51
+ const response = await get(`/${index.pluginId}/license/status`);
52
+ setLicenseData(response.data);
53
+ } catch (err) {
54
+ index.logSafeAdminError("activation.load", err);
55
+ setError(t("license.error.load", "Activation information could not be loaded."));
56
+ } finally {
57
+ setLoading(false);
58
+ }
59
+ };
60
+ const handleCopyLicenseKey = async () => {
61
+ try {
62
+ await maskSensitiveValue.copyText(licenseData?.data?.licenseKey || "");
63
+ toggleNotification({
64
+ type: "success",
65
+ message: t("license.success.copied", "Activation key copied to clipboard.")
66
+ });
67
+ } catch (err) {
68
+ index.logSafeAdminError("activation.copyKey", err);
69
+ toggleNotification({
70
+ type: "danger",
71
+ message: t("license.error.copy", "Could not copy the activation key.")
72
+ });
73
+ }
74
+ };
75
+ const handleDownloadLicenseKey = () => {
76
+ try {
77
+ const data2 = licenseData?.data || {};
78
+ const licenseKey = data2.licenseKey || "";
79
+ const email = data2.email || "N/A";
80
+ const firstName = data2.firstName || "";
81
+ const lastName = data2.lastName || "";
82
+ const fullName = `${firstName} ${lastName}`.trim() || "N/A";
83
+ const content = `Magic Session Manager - Optional Activation Key
84
+ =======================================
85
+
86
+ Activation Key: ${licenseKey}
87
+
88
+ Activation Holder Information:
89
+ ---------------------------------------
90
+ Name: ${fullName}
91
+ Email: ${email}
92
+
93
+ Activation Status:
94
+ ---------------------------------------
95
+ Status: ${data2.isActive ? "ACTIVE" : "INACTIVE"}
96
+ Expires: ${data2.expiresAt ? new Date(data2.expiresAt).toLocaleDateString() : "Never"}
97
+
98
+ Features:
99
+ ---------------------------------------
100
+ All Session Manager features are included without a paid key.
101
+
102
+ =======================================
103
+ Generated: ${(/* @__PURE__ */ new Date()).toLocaleString()}
104
+ `;
105
+ const blob = new Blob([content], { type: "text/plain" });
106
+ const url = window.URL.createObjectURL(blob);
107
+ const link = document.createElement("a");
108
+ link.href = url;
109
+ link.download = "session-manager-activation.txt";
110
+ document.body.appendChild(link);
111
+ link.click();
112
+ document.body.removeChild(link);
113
+ window.URL.revokeObjectURL(url);
114
+ toggleNotification({
115
+ type: "success",
116
+ message: t("license.success.downloaded", "Activation key downloaded.")
117
+ });
118
+ } catch (err) {
119
+ toggleNotification({
120
+ type: "danger",
121
+ message: t("license.error.download", "Could not download the activation key.")
122
+ });
123
+ }
124
+ };
125
+ react.useEffect(() => {
126
+ fetchLicenseStatus();
127
+ }, []);
128
+ if (loading) {
129
+ return /* @__PURE__ */ jsxRuntime.jsx(
130
+ PluginPageLayout.PluginPageLayout,
131
+ {
132
+ headingId: "magic-sessionmanager-activation-title",
133
+ title: t("license.title", "Optional activation"),
134
+ subtitle: t("license.subtitle", "An activation key is optional. All features remain available without one."),
135
+ children: /* @__PURE__ */ jsxRuntime.jsx(LoaderContainer, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, { children: t("license.loading", "Loading activation information...") }) })
136
+ }
137
+ );
138
+ }
139
+ if (error) {
140
+ return /* @__PURE__ */ jsxRuntime.jsx(
141
+ PluginPageLayout.PluginPageLayout,
142
+ {
143
+ headingId: "magic-sessionmanager-activation-title",
144
+ title: t("license.title", "Optional activation"),
145
+ subtitle: t("license.subtitle", "An activation key is optional. All features remain available without one."),
146
+ children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 8, children: /* @__PURE__ */ jsxRuntime.jsx(
147
+ designSystem.Alert,
148
+ {
149
+ variant: "danger",
150
+ title: t("common.error", "Error"),
151
+ closeLabel: t("common.close", "Close"),
152
+ action: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "secondary", onClick: fetchLicenseStatus, children: t("common.retry", "Retry") }),
153
+ children: /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "pi", textColor: "neutral700", tag: "span", children: error })
154
+ }
155
+ ) })
156
+ }
157
+ );
158
+ }
159
+ const isValid = licenseData?.valid;
160
+ const data = licenseData?.data || {};
161
+ const hasKey = licenseData?.hasKey ?? Boolean(data.licenseKey);
162
+ return /* @__PURE__ */ jsxRuntime.jsx(
163
+ PluginPageLayout.PluginPageLayout,
164
+ {
165
+ headingId: "magic-sessionmanager-activation-title",
166
+ title: t("license.title", "Optional activation"),
167
+ subtitle: t("license.subtitle", "An activation key is optional. All features remain available without one."),
168
+ primaryAction: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowClockwise, {}), onClick: fetchLicenseStatus, variant: "secondary", children: t("license.refresh", "Refresh status") }),
169
+ children: /* @__PURE__ */ jsxRuntime.jsx(Container, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
170
+ !hasKey ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Alert, { variant: "default", title: t("license.status.noKey.title", "No activation key stored"), closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "pi", textColor: "neutral700", tag: "span", children: t("license.status.noKey.description", "All Session Manager features are available. An activation key is optional and only used for install tracking or display.") }) }) : isValid ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Alert, { variant: "success", title: t("license.status.stored.title", "Activation key stored"), closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "pi", textColor: "neutral700", tag: "span", children: t("license.status.stored.description", "Your optional activation key is stored. All features remain available with or without this key.") }) }) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Alert, { variant: "warning", title: t("license.status.failed.title", "Activation check failed"), closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "pi", textColor: "neutral700", tag: "span", children: t("license.status.failed.description", "The activation server could not verify this key. The plugin still keeps all features available.") }) }),
171
+ data.licenseKey && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginTop: 6, children: /* @__PURE__ */ jsxRuntime.jsx(LicenseKeyBanner, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "flex-start", gap: 4, wrap: "wrap", children: [
172
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { flex: "1 1 240px", minWidth: 0 }, children: [
173
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", style: { marginBottom: "8px", display: "block" }, children: t("license.key.label", "Activation key") }),
174
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { alignItems: "center", gap: 2, wrap: "wrap", style: { marginBottom: "16px" }, children: [
175
+ /* @__PURE__ */ jsxRuntime.jsx(
176
+ designSystem.Typography,
177
+ {
178
+ variant: "epsilon",
179
+ fontWeight: "semiBold",
180
+ style: { fontFamily: "monospace", overflowWrap: "anywhere", minWidth: 0 },
181
+ children: showLicenseKey ? data.licenseKey : maskSensitiveValue.maskSensitiveValue(data.licenseKey)
182
+ }
183
+ ),
184
+ /* @__PURE__ */ jsxRuntime.jsx(
185
+ designSystem.Button,
186
+ {
187
+ type: "button",
188
+ variant: "tertiary",
189
+ size: "S",
190
+ "aria-label": t(
191
+ showLicenseKey ? "license.key.hide" : "license.key.show",
192
+ showLicenseKey ? "Hide key" : "Show key"
193
+ ),
194
+ onClick: () => setShowLicenseKey((visible) => !visible),
195
+ children: t(showLicenseKey ? "license.key.hide" : "license.key.show", showLicenseKey ? "Hide key" : "Show key")
196
+ }
197
+ )
198
+ ] }),
199
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, wrap: "wrap", children: [
200
+ /* @__PURE__ */ jsxRuntime.jsx(
201
+ designSystem.Button,
202
+ {
203
+ onClick: handleCopyLicenseKey,
204
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Duplicate, {}),
205
+ size: "S",
206
+ variant: "secondary",
207
+ children: t("license.key.copy", "Copy key")
208
+ }
209
+ ),
210
+ /* @__PURE__ */ jsxRuntime.jsx(
211
+ designSystem.Button,
212
+ {
213
+ onClick: handleDownloadLicenseKey,
214
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Download, {}),
215
+ size: "S",
216
+ variant: "secondary",
217
+ children: t("license.key.download", "Download as TXT")
218
+ }
219
+ )
220
+ ] })
221
+ ] }),
222
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { variant: data.isActive ? "success" : "neutral", size: "S", children: data.isActive ? t("license.active", "Active") : t("license.inactive", "Inactive") })
223
+ ] }) }) }),
224
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginTop: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Accordion.Root, { defaultValue: "account", collapsible: true, children: [
225
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Accordion.Item, { value: "account", children: [
226
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Trigger, { icon: icons.User, children: t("license.account.title", "Account information") }) }),
227
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 8, wrap: "wrap", children: [
228
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { flex: "1", minWidth: "200px" }, children: [
229
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", style: { marginBottom: "8px", display: "block" }, children: t("license.account.email", "Email address") }),
230
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "semiBold", children: data.email || t("license.value.notProvided", "Not provided") })
231
+ ] }),
232
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { flex: "1", minWidth: "200px" }, children: [
233
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", style: { marginBottom: "8px", display: "block" }, children: t("license.account.holder", "Activation holder") }),
234
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "semiBold", children: data.firstName && data.lastName ? `${data.firstName} ${data.lastName}` : t("license.value.notSpecified", "Not specified") })
235
+ ] })
236
+ ] }) }) })
237
+ ] }),
238
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Accordion.Item, { value: "details", children: [
239
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Trigger, { icon: icons.Shield, children: t("license.details.title", "Activation details") }) }),
240
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 8, wrap: "wrap", children: [
241
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { flex: "1", minWidth: "180px" }, children: [
242
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", style: { marginBottom: "8px", display: "block" }, children: data.isExpired ? t("license.details.expiredOn", "Expired on") : t("license.details.expiresOn", "Expires on") }),
243
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "semiBold", children: data.expiresAt ? new Date(data.expiresAt).toLocaleDateString(locale, {
244
+ year: "numeric",
245
+ month: "long",
246
+ day: "numeric"
247
+ }) : t("license.value.never", "Never") })
248
+ ] }),
249
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { flex: "1", minWidth: "180px" }, children: [
250
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", style: { marginBottom: "8px", display: "block" }, children: t("license.details.deviceName", "Device name") }),
251
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "semiBold", children: data.deviceName || t("license.value.unknown", "Unknown") })
252
+ ] }),
253
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { flex: "1", minWidth: "180px" }, children: [
254
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", style: { marginBottom: "8px", display: "block" }, children: t("license.details.ipAddress", "IP address") }),
255
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "semiBold", children: data.ipAddress || t("license.value.notDetected", "Not detected") })
256
+ ] })
257
+ ] }) }) })
258
+ ] }),
259
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Accordion.Item, { value: "features", children: [
260
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Trigger, { icon: icons.Sparkle, children: t("license.features.title", "Features and capabilities") }) }),
261
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(FeaturePanel, { padding: 5, background: "neutral0", hasRadius: true, children: [
262
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "semiBold", textColor: "neutral800", style: { marginBottom: "16px", display: "block" }, children: t("license.features.included", "All features included") }),
263
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 0, children: [
264
+ /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "pi", textColor: "neutral700", tag: "p", children: t("license.features.geolocation", "IP geolocation with country, city, and timezone") }),
265
+ /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "pi", textColor: "neutral700", tag: "p", children: t("license.features.security", "Security scoring, VPN and proxy detection, and threat analysis") }),
266
+ /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "pi", textColor: "neutral700", tag: "p", children: t("license.features.analytics", "Session analytics, CSV and JSON export, and real-time monitoring") }),
267
+ /* @__PURE__ */ jsxRuntime.jsx(index.ReadableText, { variant: "pi", textColor: "neutral700", tag: "p", children: t("license.features.alerts", "Email alerts, Discord and Slack webhooks, and geofencing") })
268
+ ] })
269
+ ] }) }) })
270
+ ] }),
271
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Accordion.Item, { value: "status", children: [
272
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Trigger, { icon: icons.ChartBubble, children: t("license.system.title", "System status") }) }),
273
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Accordion.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 6, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 8, wrap: "wrap", children: [
274
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { flex: "1", minWidth: "150px" }, children: [
275
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", style: { marginBottom: "8px", display: "block" }, children: t("license.system.activation", "Activation status") }),
276
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "semiBold", children: data.isActive ? t("license.active", "Active") : t("license.inactive", "Inactive") })
277
+ ] }),
278
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { flex: "1", minWidth: "150px" }, children: [
279
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", style: { marginBottom: "8px", display: "block" }, children: t("license.system.connection", "Connection") }),
280
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "semiBold", children: data.isOnline ? t("license.system.online", "Online") : t("license.system.offline", "Offline") })
281
+ ] }),
282
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { flex: "1", minWidth: "150px" }, children: [
283
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", style: { marginBottom: "8px", display: "block" }, children: t("license.system.lastSync", "Last sync") }),
284
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", fontWeight: "semiBold", children: data.lastPingAt ? new Date(data.lastPingAt).toLocaleTimeString(locale) : t("license.value.never", "Never") })
285
+ ] }),
286
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { flex: "1", minWidth: "150px" }, children: [
287
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", style: { marginBottom: "8px", display: "block" }, children: t("license.system.deviceLimit", "Device limit") }),
288
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "omega", fontWeight: "semiBold", children: [
289
+ data.currentDevices || 0,
290
+ " / ",
291
+ data.maxDevices || 1
292
+ ] })
293
+ ] })
294
+ ] }) }) })
295
+ ] })
296
+ ] }) })
297
+ ] }) })
298
+ }
299
+ );
300
+ };
301
+ exports.default = LicensePage;
@@ -0,0 +1,230 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState, useRef, useCallback, useEffect } from "react";
3
+ import { useIntl } from "react-intl";
4
+ import { Box, Alert, Button, Flex, Grid, Typography } from "@strapi/design-system";
5
+ import { l as logSafeAdminError, R as ReadableText, a as getTranslation } from "./index-BFVITQ-o.mjs";
6
+ import { Check, Cross, Clock, User } from "@strapi/icons";
7
+ import { useFetchClient } from "@strapi/strapi/admin";
8
+ function getSessionUserKey(session) {
9
+ return session?.user?.documentId || session?.user?.id || session?.user?.email || session?.user?.username || null;
10
+ }
11
+ function normalizeUserCounts(response) {
12
+ const totalUsers = response?.data?.totalUsers;
13
+ const blockedUsers = response?.data?.blockedUsers;
14
+ if (response?.success !== true || !Number.isSafeInteger(totalUsers) || totalUsers < 0 || !Number.isSafeInteger(blockedUsers) || blockedUsers < 0 || blockedUsers > totalUsers) {
15
+ return null;
16
+ }
17
+ return { totalUsers, blockedUsers };
18
+ }
19
+ function computeOnlineUserStats(sessions, {
20
+ now = Date.now(),
21
+ totalUsers = null,
22
+ blockedUsers = null
23
+ } = {}) {
24
+ const fifteenMin = 15 * 60 * 1e3;
25
+ const thirtyMin = 30 * 60 * 1e3;
26
+ const onlineNow = /* @__PURE__ */ new Set();
27
+ const last15min = /* @__PURE__ */ new Set();
28
+ const last30min = /* @__PURE__ */ new Set();
29
+ for (const session of sessions || []) {
30
+ if (!session?.isActive) continue;
31
+ const userKey = getSessionUserKey(session);
32
+ if (!userKey) continue;
33
+ const lastActive = session.lastActive ? new Date(session.lastActive) : new Date(session.loginTime);
34
+ const lastActiveMs = lastActive.getTime();
35
+ if (!Number.isFinite(lastActiveMs)) continue;
36
+ const timeSinceActive = now - lastActiveMs;
37
+ if (timeSinceActive < fifteenMin) {
38
+ onlineNow.add(userKey);
39
+ last15min.add(userKey);
40
+ last30min.add(userKey);
41
+ } else if (timeSinceActive < thirtyMin) {
42
+ last30min.add(userKey);
43
+ }
44
+ }
45
+ const hasTotalUsers = Number.isSafeInteger(totalUsers) && totalUsers >= 0;
46
+ const hasBlockedUsers = Number.isSafeInteger(blockedUsers) && blockedUsers >= 0;
47
+ return {
48
+ onlineNow: onlineNow.size,
49
+ last15min: last15min.size,
50
+ last30min: last30min.size,
51
+ offline: hasTotalUsers ? Math.max(0, totalUsers - onlineNow.size) : null,
52
+ totalUsers: hasTotalUsers ? totalUsers : null,
53
+ blocked: hasBlockedUsers ? blockedUsers : null
54
+ };
55
+ }
56
+ const OnlineUsersWidget = () => {
57
+ const { formatMessage } = useIntl();
58
+ const { get } = useFetchClient();
59
+ const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
60
+ const [stats, setStats] = useState({
61
+ onlineNow: 0,
62
+ offline: null,
63
+ last15min: 0,
64
+ last30min: 0,
65
+ totalUsers: null,
66
+ blocked: null
67
+ });
68
+ const [loading, setLoading] = useState(true);
69
+ const [loadError, setLoadError] = useState(false);
70
+ const [userCountsUnavailable, setUserCountsUnavailable] = useState(false);
71
+ const requestInProgress = useRef(false);
72
+ const fetchStats = useCallback(async ({ showLoading = true } = {}) => {
73
+ if (requestInProgress.current) return;
74
+ requestInProgress.current = true;
75
+ if (showLoading) setLoading(true);
76
+ try {
77
+ const { data: sessionResponse } = await get("/magic-sessionmanager/sessions");
78
+ const sessions = sessionResponse?.data;
79
+ if (!Array.isArray(sessions)) throw new Error("Invalid session response");
80
+ let userCounts = null;
81
+ let countsUnavailable = false;
82
+ try {
83
+ const { data: userStatsResponse } = await get("/magic-sessionmanager/users/stats");
84
+ userCounts = normalizeUserCounts(userStatsResponse);
85
+ if (!userCounts) throw new Error("Invalid user statistics response");
86
+ } catch (error) {
87
+ logSafeAdminError("onlineUsers.userCounts", error);
88
+ countsUnavailable = true;
89
+ }
90
+ setStats(computeOnlineUserStats(sessions, userCounts || {}));
91
+ setUserCountsUnavailable(countsUnavailable);
92
+ setLoadError(false);
93
+ } catch (error) {
94
+ logSafeAdminError("onlineUsers.loadSessions", error);
95
+ setLoadError(true);
96
+ } finally {
97
+ if (showLoading) setLoading(false);
98
+ requestInProgress.current = false;
99
+ }
100
+ }, [get]);
101
+ useEffect(() => {
102
+ void fetchStats();
103
+ const interval = setInterval(() => {
104
+ void fetchStats({ showLoading: false });
105
+ }, 3e4);
106
+ return () => clearInterval(interval);
107
+ }, [fetchStats]);
108
+ const StatCard = ({ icon: Icon, label, value, color }) => /* @__PURE__ */ jsx(
109
+ Box,
110
+ {
111
+ padding: 4,
112
+ background: "neutral0",
113
+ hasRadius: true,
114
+ shadow: "tableShadow",
115
+ style: {
116
+ textDecoration: "none",
117
+ cursor: "default",
118
+ transition: "box-shadow 0.2s",
119
+ border: "1px solid rgba(128, 128, 128, 0.1)"
120
+ },
121
+ children: /* @__PURE__ */ jsx(Flex, { justifyContent: "space-between", alignItems: "flex-start", children: /* @__PURE__ */ jsxs(Flex, { gap: 3, alignItems: "center", children: [
122
+ /* @__PURE__ */ jsx(
123
+ Box,
124
+ {
125
+ padding: 2,
126
+ background: `${color}100`,
127
+ hasRadius: true,
128
+ style: {
129
+ display: "flex",
130
+ alignItems: "center",
131
+ justifyContent: "center"
132
+ },
133
+ children: /* @__PURE__ */ jsx(Icon, { width: "16px", height: "16px", fill: `${color}600` })
134
+ }
135
+ ),
136
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 1, alignItems: "flex-start", children: [
137
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: label }),
138
+ /* @__PURE__ */ jsx(Typography, { variant: "delta", fontWeight: "bold", textColor: "neutral800", children: value ?? t("common.unavailable", "Unavailable") })
139
+ ] })
140
+ ] }) })
141
+ }
142
+ );
143
+ if (loading) {
144
+ return /* @__PURE__ */ jsx(Box, { padding: 4, children: /* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral600", tag: "p", children: t("common.loading", "Loading...") }) });
145
+ }
146
+ if (loadError) {
147
+ return /* @__PURE__ */ jsx(Box, { padding: 4, role: "alert", children: /* @__PURE__ */ jsx(
148
+ Alert,
149
+ {
150
+ variant: "danger",
151
+ title: t("widget.error.title", "Session statistics could not be loaded"),
152
+ closeLabel: "",
153
+ action: /* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: () => {
154
+ void fetchStats();
155
+ }, children: t("common.retry", "Retry") }),
156
+ children: /* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral700", tag: "span", children: t("widget.error.description", "Try again. If the problem continues, check Session Manager API access.") })
157
+ }
158
+ ) });
159
+ }
160
+ return /* @__PURE__ */ jsx(Box, { padding: 0, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 3, children: [
161
+ userCountsUnavailable && /* @__PURE__ */ jsx(Box, { role: "status", children: /* @__PURE__ */ jsx(
162
+ Alert,
163
+ {
164
+ variant: "warning",
165
+ title: t("widget.partial.title", "Some user counts are unavailable"),
166
+ closeLabel: "",
167
+ children: /* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral700", tag: "span", children: t("widget.partial.description", "Session activity is shown, but total and blocked user counts could not be loaded.") })
168
+ }
169
+ ) }),
170
+ /* @__PURE__ */ jsxs(Grid.Root, { gap: 3, gridCols: 2, children: [
171
+ /* @__PURE__ */ jsx(Grid.Item, { col: 1, children: /* @__PURE__ */ jsx(
172
+ StatCard,
173
+ {
174
+ icon: Check,
175
+ label: t("widget.stats.onlineNow", "Online Now"),
176
+ value: stats.onlineNow,
177
+ color: "success"
178
+ }
179
+ ) }),
180
+ /* @__PURE__ */ jsx(Grid.Item, { col: 1, children: /* @__PURE__ */ jsx(
181
+ StatCard,
182
+ {
183
+ icon: Cross,
184
+ label: t("widget.stats.offline", "Offline"),
185
+ value: stats.offline,
186
+ color: "neutral"
187
+ }
188
+ ) }),
189
+ /* @__PURE__ */ jsx(Grid.Item, { col: 1, children: /* @__PURE__ */ jsx(
190
+ StatCard,
191
+ {
192
+ icon: Clock,
193
+ label: t("widget.stats.last15min", "Last 15 min"),
194
+ value: stats.last15min,
195
+ color: "primary"
196
+ }
197
+ ) }),
198
+ /* @__PURE__ */ jsx(Grid.Item, { col: 1, children: /* @__PURE__ */ jsx(
199
+ StatCard,
200
+ {
201
+ icon: Clock,
202
+ label: t("widget.stats.last30min", "Last 30 min"),
203
+ value: stats.last30min,
204
+ color: "secondary"
205
+ }
206
+ ) }),
207
+ /* @__PURE__ */ jsx(Grid.Item, { col: 1, children: /* @__PURE__ */ jsx(
208
+ StatCard,
209
+ {
210
+ icon: User,
211
+ label: t("widget.stats.totalUsers", "Total Users"),
212
+ value: stats.totalUsers,
213
+ color: "neutral"
214
+ }
215
+ ) }),
216
+ /* @__PURE__ */ jsx(Grid.Item, { col: 1, children: /* @__PURE__ */ jsx(
217
+ StatCard,
218
+ {
219
+ icon: Cross,
220
+ label: t("widget.stats.blocked", "Blocked"),
221
+ value: stats.blocked,
222
+ color: "danger"
223
+ }
224
+ ) })
225
+ ] })
226
+ ] }) });
227
+ };
228
+ export {
229
+ OnlineUsersWidget as default
230
+ };