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
@@ -0,0 +1,443 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useState, useRef, useCallback, useEffect } from "react";
3
+ import { useIntl } from "react-intl";
4
+ import { Badge, Button, Flex, Typography, Field, TextInput, IconButton } from "@strapi/design-system";
5
+ import { useFetchClient, useNotification, useClipboard, Page } from "@strapi/strapi/admin";
6
+ import { EyeStriked, Eye, Duplicate, Download, ArrowClockwise } from "@strapi/icons";
7
+ import { u as useSessionFormatters, m as pluginId, n as logSafeAdminError, z as PageShell, o as PersistentAlert, R as ReadableText, P as PropertyList, b as getTranslation } from "./index-Ck19e8qw.mjs";
8
+ import { S as SectionCard } from "./SectionCard-D51bv4Hi.mjs";
9
+ import { m as maskSensitiveValue } from "./maskSensitiveValue-lLRhN_S7.mjs";
10
+ const LICENSE_STATE_MESSAGES = Object.freeze({
11
+ noKey: Object.freeze({
12
+ messageId: "license.state.noKey",
13
+ defaultMessage: "No license key stored."
14
+ }),
15
+ valid: Object.freeze({
16
+ messageId: "license.state.valid",
17
+ defaultMessage: "License valid until {date}."
18
+ }),
19
+ validNoExpiry: Object.freeze({
20
+ messageId: "license.state.validNoExpiry",
21
+ defaultMessage: "License valid. It has no expiry date."
22
+ }),
23
+ expired: Object.freeze({
24
+ messageId: "license.state.expired",
25
+ defaultMessage: "License expired on {date}."
26
+ }),
27
+ expiredNoDate: Object.freeze({
28
+ messageId: "license.state.expiredNoDate",
29
+ defaultMessage: "License expired."
30
+ }),
31
+ invalid: Object.freeze({
32
+ messageId: "license.state.invalid",
33
+ defaultMessage: "This license key is not valid."
34
+ }),
35
+ unchecked: Object.freeze({
36
+ messageId: "license.state.unchecked",
37
+ defaultMessage: "The license status could not be checked."
38
+ })
39
+ });
40
+ const LICENSE_FEATURES_MESSAGE = Object.freeze({
41
+ messageId: "license.features.always",
42
+ defaultMessage: "All features are available with or without a key."
43
+ });
44
+ const LICENSE_EXPIRY_DATE_OPTIONS = Object.freeze({ dateStyle: "medium" });
45
+ const present = (value) => typeof value === "string" ? value.trim() !== "" : value !== null && value !== void 0;
46
+ function getLicenseState(response, now = Date.now()) {
47
+ const data = response?.data && typeof response.data === "object" ? response.data : {};
48
+ const hasKey = typeof response?.hasKey === "boolean" ? response.hasKey : present(data.licenseKey);
49
+ const expiresAt = present(data.expiresAt) ? data.expiresAt : null;
50
+ const expiresAtMs = expiresAt ? Date.parse(expiresAt) : Number.NaN;
51
+ const base = { hasKey, expiresAt, serverReachable: data.isOnline === true, data };
52
+ if (!hasKey) return { ...base, state: "noKey" };
53
+ const described = [
54
+ "email",
55
+ "firstName",
56
+ "lastName",
57
+ "expiresAt",
58
+ "lastPingAt",
59
+ "deviceName"
60
+ ].some((field) => present(data[field]));
61
+ if (!described) return { ...base, state: "unchecked" };
62
+ const expired = data.isExpired === true || Number.isFinite(expiresAtMs) && expiresAtMs <= now;
63
+ if (expired)
64
+ return { ...base, state: Number.isFinite(expiresAtMs) ? "expired" : "expiredNoDate" };
65
+ if (data.isActive === false) return { ...base, state: "invalid" };
66
+ return { ...base, state: Number.isFinite(expiresAtMs) ? "valid" : "validNoExpiry" };
67
+ }
68
+ function describeLicenseState(licenseState, formatDate) {
69
+ const descriptor = LICENSE_STATE_MESSAGES[licenseState?.state] || LICENSE_STATE_MESSAGES.unchecked;
70
+ if (licenseState?.state === "valid" || licenseState?.state === "expired") {
71
+ return {
72
+ ...descriptor,
73
+ values: { date: formatDate(licenseState.expiresAt, LICENSE_EXPIRY_DATE_OPTIONS) }
74
+ };
75
+ }
76
+ return { ...descriptor };
77
+ }
78
+ const LICENSE_SUMMARY_MESSAGES = Object.freeze({
79
+ heading: Object.freeze({
80
+ messageId: "license.download.heading",
81
+ defaultMessage: "Session Manager license"
82
+ }),
83
+ status: Object.freeze({ messageId: "license.download.status", defaultMessage: "Status" }),
84
+ key: Object.freeze({ messageId: "license.key.title", defaultMessage: "License key" }),
85
+ holder: Object.freeze({ messageId: "license.details.holder", defaultMessage: "Holder" }),
86
+ email: Object.freeze({ messageId: "license.account.email", defaultMessage: "Email address" }),
87
+ expires: Object.freeze({ messageId: "license.details.expires", defaultMessage: "Expires" }),
88
+ noExpiry: Object.freeze({
89
+ messageId: "license.details.noExpiry",
90
+ defaultMessage: "No expiry date"
91
+ }),
92
+ deviceName: Object.freeze({
93
+ messageId: "license.details.deviceName",
94
+ defaultMessage: "Device name"
95
+ }),
96
+ ipAddress: Object.freeze({
97
+ messageId: "license.details.ipAddress",
98
+ defaultMessage: "IP address"
99
+ }),
100
+ lastCheck: Object.freeze({
101
+ messageId: "license.details.lastCheck",
102
+ defaultMessage: "Last check"
103
+ }),
104
+ deviceLimit: Object.freeze({
105
+ messageId: "license.system.deviceLimit",
106
+ defaultMessage: "Device limit"
107
+ }),
108
+ deviceLimitValue: Object.freeze({
109
+ messageId: "license.system.deviceLimitValue",
110
+ defaultMessage: "{current} of {max}"
111
+ }),
112
+ serverReachable: Object.freeze({
113
+ messageId: "license.details.serverReachable",
114
+ defaultMessage: "License server reachable"
115
+ }),
116
+ yes: Object.freeze({ messageId: "common.yes", defaultMessage: "Yes" }),
117
+ no: Object.freeze({ messageId: "common.no", defaultMessage: "No" }),
118
+ generated: Object.freeze({
119
+ messageId: "license.download.generated",
120
+ defaultMessage: "Generated"
121
+ }),
122
+ notProvided: Object.freeze({
123
+ messageId: "license.value.notProvided",
124
+ defaultMessage: "Not provided"
125
+ })
126
+ });
127
+ const RULE = "========================================";
128
+ const text = (value) => typeof value === "string" ? value.trim() : "";
129
+ function getLicenseHolderName(data) {
130
+ return [text(data?.firstName), text(data?.lastName)].filter(Boolean).join(" ");
131
+ }
132
+ function buildLicenseSummary({
133
+ response,
134
+ translate,
135
+ formatDate,
136
+ generatedAt = Date.now(),
137
+ now = Date.now()
138
+ }) {
139
+ const m = LICENSE_SUMMARY_MESSAGES;
140
+ const licenseState = getLicenseState(response, now);
141
+ const data = licenseState.data;
142
+ const statusMessage = describeLicenseState(licenseState, formatDate);
143
+ const notProvided = translate(m.notProvided);
144
+ const orMissing = (value) => text(value) || notProvided;
145
+ const line = (descriptor, value) => `${translate(descriptor)}: ${value}`;
146
+ return [
147
+ translate(m.heading),
148
+ RULE,
149
+ line(m.status, translate(statusMessage, statusMessage.values)),
150
+ translate(LICENSE_FEATURES_MESSAGE),
151
+ "",
152
+ line(m.key, orMissing(data.licenseKey)),
153
+ line(m.holder, getLicenseHolderName(data) || notProvided),
154
+ line(m.email, orMissing(data.email)),
155
+ line(
156
+ m.expires,
157
+ licenseState.expiresAt ? formatDate(licenseState.expiresAt, LICENSE_EXPIRY_DATE_OPTIONS) : translate(m.noExpiry)
158
+ ),
159
+ line(m.deviceName, orMissing(data.deviceName)),
160
+ line(m.ipAddress, orMissing(data.ipAddress)),
161
+ line(m.lastCheck, data.lastPingAt ? formatDate(data.lastPingAt) : notProvided),
162
+ line(
163
+ m.deviceLimit,
164
+ translate(m.deviceLimitValue, {
165
+ current: Number(data.currentDevices) || 0,
166
+ max: Number(data.maxDevices) || 1
167
+ })
168
+ ),
169
+ line(m.serverReachable, translate(licenseState.serverReachable ? m.yes : m.no)),
170
+ RULE,
171
+ line(m.generated, formatDate(generatedAt)),
172
+ ""
173
+ ].join("\n");
174
+ }
175
+ const isForbidden = (error) => error?.status === 403 || error?.response?.status === 403;
176
+ const LicensePage = () => {
177
+ const { formatMessage } = useIntl();
178
+ const { get } = useFetchClient();
179
+ const { toggleNotification } = useNotification();
180
+ const { copy } = useClipboard();
181
+ const { formatDate } = useSessionFormatters();
182
+ const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
183
+ const translate = (descriptor, values) => formatMessage(
184
+ { id: getTranslation(descriptor.messageId), defaultMessage: descriptor.defaultMessage },
185
+ values
186
+ );
187
+ const [loading, setLoading] = useState(true);
188
+ const [refreshing, setRefreshing] = useState(false);
189
+ const [licenseData, setLicenseData] = useState(null);
190
+ const [showLicenseKey, setShowLicenseKey] = useState(false);
191
+ const [error, setError] = useState(false);
192
+ const [forbidden, setForbidden] = useState(false);
193
+ const requestPendingRef = useRef(false);
194
+ const fetchLicenseStatus = useCallback(async () => {
195
+ if (requestPendingRef.current) return false;
196
+ requestPendingRef.current = true;
197
+ try {
198
+ const response = await get(`/${pluginId}/license/status`);
199
+ setLicenseData(response.data);
200
+ setError(false);
201
+ return true;
202
+ } catch (err) {
203
+ logSafeAdminError("license.load", err);
204
+ if (isForbidden(err)) setForbidden(true);
205
+ setError(true);
206
+ return false;
207
+ } finally {
208
+ requestPendingRef.current = false;
209
+ setRefreshing(false);
210
+ setLoading(false);
211
+ }
212
+ }, [get]);
213
+ const checkLicenseStatus = async ({ announce }) => {
214
+ if (requestPendingRef.current) return;
215
+ setRefreshing(true);
216
+ const loaded = await fetchLicenseStatus();
217
+ if (loaded && announce) {
218
+ toggleNotification({
219
+ type: "success",
220
+ message: t("license.success.refreshed", "License status checked.")
221
+ });
222
+ }
223
+ };
224
+ const handleRefresh = () => checkLicenseStatus({ announce: true });
225
+ const handleCopyLicenseKey = async () => {
226
+ try {
227
+ const copied = await copy(licenseData?.data?.licenseKey || "");
228
+ if (!copied) throw new Error("clipboard_unavailable");
229
+ toggleNotification({
230
+ type: "success",
231
+ message: t("license.success.copied", "Copied.")
232
+ });
233
+ } catch (err) {
234
+ logSafeAdminError("license.copyKey", err);
235
+ toggleNotification({
236
+ type: "danger",
237
+ message: t("license.error.copy", "The key could not be copied.")
238
+ });
239
+ }
240
+ };
241
+ const handleDownloadLicenseKey = () => {
242
+ try {
243
+ const content = buildLicenseSummary({
244
+ response: licenseData,
245
+ translate,
246
+ formatDate,
247
+ generatedAt: Date.now()
248
+ });
249
+ const blob = new Blob([content], { type: "text/plain;charset=utf-8" });
250
+ const url = window.URL.createObjectURL(blob);
251
+ const link = document.createElement("a");
252
+ link.href = url;
253
+ link.download = "session-manager-license.txt";
254
+ document.body.appendChild(link);
255
+ link.click();
256
+ document.body.removeChild(link);
257
+ window.URL.revokeObjectURL(url);
258
+ toggleNotification({
259
+ type: "success",
260
+ message: t("license.success.downloaded", "License details downloaded.")
261
+ });
262
+ } catch (err) {
263
+ logSafeAdminError("license.download", err);
264
+ toggleNotification({
265
+ type: "danger",
266
+ message: t("license.error.download", "The file could not be created.")
267
+ });
268
+ }
269
+ };
270
+ useEffect(() => {
271
+ fetchLicenseStatus();
272
+ }, [fetchLicenseStatus]);
273
+ if (loading) {
274
+ return /* @__PURE__ */ jsx(Page.Loading, {});
275
+ }
276
+ if (forbidden) {
277
+ return /* @__PURE__ */ jsx(Page.NoPermissions, {});
278
+ }
279
+ const licenseState = licenseData ? getLicenseState(licenseData) : null;
280
+ const hasKey = licenseState?.hasKey === true;
281
+ const data = licenseState?.data || {};
282
+ const statusMessage = licenseState ? describeLicenseState(licenseState, formatDate) : null;
283
+ const yesNo = (value) => value ? t("common.yes", "Yes") : t("common.no", "No");
284
+ const detailItems = [
285
+ {
286
+ id: "holder",
287
+ label: t("license.details.holder", "Holder"),
288
+ value: getLicenseHolderName(data)
289
+ },
290
+ {
291
+ id: "email",
292
+ kind: "email",
293
+ label: t("license.account.email", "Email address"),
294
+ value: data.email
295
+ },
296
+ {
297
+ id: "expires",
298
+ label: t("license.details.expires", "Expires"),
299
+ value: licenseState?.expiresAt ? formatDate(licenseState.expiresAt, LICENSE_EXPIRY_DATE_OPTIONS) : t("license.details.noExpiry", "No expiry date")
300
+ },
301
+ {
302
+ id: "device-name",
303
+ label: t("license.details.deviceName", "Device name"),
304
+ value: data.deviceName
305
+ },
306
+ {
307
+ id: "ip",
308
+ kind: "id",
309
+ label: t("license.details.ipAddress", "IP address"),
310
+ value: data.ipAddress
311
+ },
312
+ {
313
+ id: "last-check",
314
+ label: t("license.details.lastCheck", "Last check"),
315
+ value: data.lastPingAt ? formatDate(data.lastPingAt) : null
316
+ },
317
+ {
318
+ id: "device-limit",
319
+ label: t("license.system.deviceLimit", "Device limit"),
320
+ value: t("license.system.deviceLimitValue", "{current} of {max}", {
321
+ current: Number(data.currentDevices) || 0,
322
+ max: Number(data.maxDevices) || 1
323
+ })
324
+ },
325
+ {
326
+ id: "server-reachable",
327
+ label: t("license.details.serverReachable", "License server reachable"),
328
+ render: /* @__PURE__ */ jsx(Badge, { children: yesNo(licenseState?.serverReachable) })
329
+ }
330
+ ];
331
+ return /* @__PURE__ */ jsxs(
332
+ PageShell,
333
+ {
334
+ headingId: "magic-sessionmanager-license-title",
335
+ title: t("license.title", "License"),
336
+ subtitle: t("license.subtitle", "Optional license key for this installation."),
337
+ primaryAction: /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", justifyContent: "flex-end", children: [
338
+ hasKey ? /* @__PURE__ */ jsx(
339
+ Button,
340
+ {
341
+ variant: "secondary",
342
+ startIcon: /* @__PURE__ */ jsx(Download, { "aria-hidden": true }),
343
+ onClick: handleDownloadLicenseKey,
344
+ children: t("license.key.download", "Download as text")
345
+ }
346
+ ) : null,
347
+ /* @__PURE__ */ jsx(
348
+ Button,
349
+ {
350
+ variant: "secondary",
351
+ startIcon: /* @__PURE__ */ jsx(ArrowClockwise, { "aria-hidden": true }),
352
+ onClick: handleRefresh,
353
+ "aria-busy": refreshing,
354
+ children: t("license.refresh", "Check again")
355
+ }
356
+ )
357
+ ] }),
358
+ children: [
359
+ /* @__PURE__ */ jsxs(SectionCard, { title: t("license.status.title", "License status"), children: [
360
+ error ? /* @__PURE__ */ jsx(
361
+ PersistentAlert,
362
+ {
363
+ variant: "danger",
364
+ closeLabel: t("common.close", "Close"),
365
+ action: /* @__PURE__ */ jsx(
366
+ Button,
367
+ {
368
+ variant: "secondary",
369
+ onClick: () => checkLicenseStatus({ announce: false }),
370
+ "aria-busy": refreshing,
371
+ children: t("license.error.retry", "Try again")
372
+ }
373
+ ),
374
+ children: /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral800", tag: "span", children: t("license.error.load", "The license status could not be checked.") })
375
+ }
376
+ ) : null,
377
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, "aria-live": "polite", children: [
378
+ statusMessage ? /* @__PURE__ */ jsx(
379
+ Typography,
380
+ {
381
+ variant: "omega",
382
+ tag: "p",
383
+ textColor: "neutral800",
384
+ fontWeight: "semiBold",
385
+ "data-license-state": "",
386
+ children: translate(statusMessage, statusMessage.values)
387
+ }
388
+ ) : null,
389
+ /* @__PURE__ */ jsx(ReadableText, { variant: "omega", textColor: "neutral600", tag: "p", children: translate(LICENSE_FEATURES_MESSAGE) })
390
+ ] })
391
+ ] }),
392
+ hasKey ? /* @__PURE__ */ jsx(SectionCard, { title: t("license.details.title", "License details"), children: /* @__PURE__ */ jsx(PropertyList, { items: detailItems }) }) : null,
393
+ hasKey ? /* @__PURE__ */ jsx(SectionCard, { title: t("license.key.title", "License key"), children: /* @__PURE__ */ jsxs(
394
+ Field.Root,
395
+ {
396
+ name: "license-key",
397
+ id: "magic-sessionmanager-license-key",
398
+ hint: t("license.key.hint", "The key stays masked until you reveal it."),
399
+ children: [
400
+ /* @__PURE__ */ jsx(Field.Label, { children: t("license.key.label", "Stored key") }),
401
+ /* @__PURE__ */ jsx(
402
+ TextInput,
403
+ {
404
+ readOnly: true,
405
+ autoComplete: "off",
406
+ spellCheck: false,
407
+ value: showLicenseKey ? data.licenseKey : maskSensitiveValue(data.licenseKey),
408
+ endAction: /* @__PURE__ */ jsxs(Flex, { gap: 1, children: [
409
+ /* @__PURE__ */ jsx(
410
+ IconButton,
411
+ {
412
+ variant: "ghost",
413
+ label: t(
414
+ showLicenseKey ? "license.key.hide" : "license.key.show",
415
+ showLicenseKey ? "Hide key" : "Show key"
416
+ ),
417
+ onClick: () => setShowLicenseKey((visible) => !visible),
418
+ children: showLicenseKey ? /* @__PURE__ */ jsx(EyeStriked, { "aria-hidden": true }) : /* @__PURE__ */ jsx(Eye, { "aria-hidden": true })
419
+ }
420
+ ),
421
+ /* @__PURE__ */ jsx(
422
+ IconButton,
423
+ {
424
+ variant: "ghost",
425
+ label: t("license.key.copy", "Copy key"),
426
+ onClick: handleCopyLicenseKey,
427
+ children: /* @__PURE__ */ jsx(Duplicate, { "aria-hidden": true })
428
+ }
429
+ )
430
+ ] })
431
+ }
432
+ ),
433
+ /* @__PURE__ */ jsx(Field.Hint, {})
434
+ ]
435
+ }
436
+ ) }) : null
437
+ ]
438
+ }
439
+ );
440
+ };
441
+ export {
442
+ LicensePage as default
443
+ };
@@ -0,0 +1,255 @@
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, v as isCancelledRequest, b as getTranslation, R as ReadableText, M as MissingValue } from "./index-Ck19e8qw.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
+ if (isCancelledRequest(error)) return;
170
+ logSafeAdminError("onlineUsers.loadSessions", error);
171
+ if (showLoading) setLoadError(true);
172
+ } finally {
173
+ if (showLoading) setLoading(false);
174
+ requestInProgress.current = false;
175
+ }
176
+ },
177
+ [get]
178
+ );
179
+ useEffect(() => {
180
+ void fetchStats();
181
+ const interval = setInterval(() => {
182
+ void fetchStats({ showLoading: false });
183
+ }, REFRESH_INTERVAL_MS);
184
+ return () => clearInterval(interval);
185
+ }, [fetchStats]);
186
+ if (loading) {
187
+ return /* @__PURE__ */ jsx(LoadingState, { label: t("widget.loading", "Loading online users") });
188
+ }
189
+ if (loadError || !stats) {
190
+ return /* @__PURE__ */ jsx(
191
+ ErrorState,
192
+ {
193
+ message: t("widget.error.message", "Online users could not be loaded."),
194
+ retryLabel: t("common.tryAgain", "Try again"),
195
+ onRetry: () => {
196
+ setLoading(true);
197
+ void fetchStats();
198
+ }
199
+ }
200
+ );
201
+ }
202
+ if (stats.sessionCount === 0) {
203
+ return /* @__PURE__ */ jsx(EmptyState, { label: t("widget.empty.noSignIns", "No users have signed in yet.") });
204
+ }
205
+ const onlineUsersDetail = userCounts ? t(
206
+ "widget.stats.registeredUsers",
207
+ "{total, plural, one {of # registered user} other {of # registered users}}",
208
+ { total: userCounts.totalUsers }
209
+ ) : t("widget.stats.userTotalsError", "User totals could not be loaded.");
210
+ const tiles = [
211
+ {
212
+ key: "onlineUsers",
213
+ icon: User,
214
+ tone: "success",
215
+ label: t("widget.stats.onlineUsers", "Online users"),
216
+ value: formatNumber(stats.onlineUsers),
217
+ detail: onlineUsersDetail
218
+ },
219
+ {
220
+ key: "activeSessions",
221
+ icon: Lightning,
222
+ tone: "primary",
223
+ label: t("widget.stats.activeSessions", "Active sessions"),
224
+ value: formatNumber(stats.activeSessions)
225
+ },
226
+ {
227
+ key: "idleSessions",
228
+ icon: Clock,
229
+ tone: "warning",
230
+ label: t("widget.stats.idleSessions", "Idle sessions"),
231
+ value: formatNumber(stats.idleSessions)
232
+ },
233
+ {
234
+ key: "blockedUsers",
235
+ icon: Lock,
236
+ tone: "neutral",
237
+ label: t("widget.stats.blockedUsers", "Blocked users"),
238
+ value: userCounts ? formatNumber(userCounts.blockedUsers) : null
239
+ }
240
+ ];
241
+ 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(
242
+ StatTile,
243
+ {
244
+ icon: tile.icon,
245
+ tone: tile.tone,
246
+ label: tile.label,
247
+ value: tile.value,
248
+ detail: tile.detail
249
+ },
250
+ tile.key
251
+ )) }) });
252
+ };
253
+ export {
254
+ OnlineUsersWidget as default
255
+ };