strapi-plugin-magic-sessionmanager 4.5.12 → 4.6.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 (39) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +90 -34
  3. package/dist/{_chunks/Analytics-DM4_UffY.js → admin/Analytics-BMkhiuRX.js} +3 -121
  4. package/dist/{_chunks/Analytics--qB2cKuD.mjs → admin/Analytics-CwNJ3TNI.mjs} +5 -123
  5. package/dist/{_chunks/App-DF-VsbDW.js → admin/App-DazHh7Zi.js} +67 -646
  6. package/dist/{_chunks/App-CL5q29Mi.mjs → admin/App-Sk0F9UEN.mjs} +69 -648
  7. package/dist/{_chunks/License-D9piCp34.mjs → admin/License-6SIpR7Rk.mjs} +34 -113
  8. package/dist/{_chunks/License-Dmm1d3fQ.js → admin/License-BwbmzbP_.js} +34 -113
  9. package/dist/{_chunks/OnlineUsersWidget-KchZ_ScS.js → admin/OnlineUsersWidget-BIfnbFcZ.js} +44 -36
  10. package/dist/{_chunks/OnlineUsersWidget-DHsthkt0.mjs → admin/OnlineUsersWidget-Qq_uCTi1.mjs} +44 -36
  11. package/dist/{_chunks/Settings-D6ILgR9X.mjs → admin/Settings-BA7S_8DF.mjs} +286 -112
  12. package/dist/{_chunks/Settings-CUNaxDWk.js → admin/Settings-CCYScjxv.js} +284 -110
  13. package/dist/{_chunks/de-CDA1V0rF.mjs → admin/de-6rIvkYOp.mjs} +37 -14
  14. package/dist/{_chunks/de-I-Q-pWqu.js → admin/de-DjP2WJ_V.js} +37 -14
  15. package/dist/{_chunks/en-Bd7_h-4e.js → admin/en-0pesBbOT.js} +37 -14
  16. package/dist/{_chunks/en-DzmOCyzQ.mjs → admin/en-8hiv31Dv.mjs} +37 -14
  17. package/dist/{_chunks/es-BcAx18XG.js → admin/es-DdBRpF7F.js} +37 -14
  18. package/dist/{_chunks/es-Cx-SN6qV.mjs → admin/es-LRQ148f5.mjs} +37 -14
  19. package/dist/{_chunks/fr-DXlXE5Eo.mjs → admin/fr-CKhx_qil.mjs} +37 -14
  20. package/dist/{_chunks/fr-DCzYMuJ-.js → admin/fr-DJ6DbeDy.js} +37 -14
  21. package/dist/{_chunks/index-CTxGMDHr.js → admin/index-DTskQVDl.js} +12 -25
  22. package/dist/{_chunks/index-CwxKazpc.mjs → admin/index-UTLA1r40.mjs} +12 -25
  23. package/dist/admin/index.js +3 -2
  24. package/dist/admin/index.mjs +1 -1
  25. package/dist/{_chunks/pt-21-MAb72.js → admin/pt-D0SMoAmo.js} +37 -14
  26. package/dist/{_chunks/pt-zsdTSjba.mjs → admin/pt-DXizUvcj.mjs} +37 -14
  27. package/dist/server/index.js +9680 -8914
  28. package/dist/server/index.mjs +9701 -8918
  29. package/package.json +25 -14
  30. package/scripts/geoip-updater.cjs +220 -0
  31. package/scripts/update-geoip-db.mjs +38 -0
  32. package/strapi-admin.js +2 -1
  33. package/strapi-server.js +2 -1
  34. package/dist/_chunks/UpgradePage-D697BVWo.mjs +0 -352
  35. package/dist/_chunks/UpgradePage-Dwrv7g8L.js +0 -354
  36. package/dist/_chunks/useLicense-B9WW9s_d.mjs +0 -86
  37. package/dist/_chunks/useLicense-BEbtA_Zo.js +0 -85
  38. /package/dist/{_chunks → admin}/StyledButtons-Cz8oYhmc.mjs +0 -0
  39. /package/dist/{_chunks → admin}/StyledButtons-DDuxnYz8.js +0 -0
@@ -3,12 +3,10 @@ import { useState, useEffect } from "react";
3
3
  import { useIntl } from "react-intl";
4
4
  import { useFetchClient, useNotification, Page } from "@strapi/strapi/admin";
5
5
  import styled, { css, keyframes } from "styled-components";
6
- import { p as parseUserAgent, a as pluginId$1, g as getTranslation } from "./index-CwxKazpc.mjs";
7
- import { Modal, Flex, Box, Typography, Divider, Button, Loader, SingleSelect, SingleSelectOption, Thead, Tr, Th, Tbody, Td, Table, TextInput } from "@strapi/design-system";
8
- import { Check, Information, Monitor, Server, Clock, Cross, Earth, Shield, Crown, Phone, Download, User, Eye, Trash, Search, Key } from "@strapi/icons";
9
- import { u as useLicense } from "./useLicense-B9WW9s_d.mjs";
6
+ import { p as parseUserAgent, a as pluginId$1, g as getTranslation } from "./index-UTLA1r40.mjs";
7
+ import { Modal, Flex, Box, Typography, Divider, Button, Loader, SingleSelect, SingleSelectOption, Thead, Tr, Th, Tbody, Td, Table } from "@strapi/design-system";
8
+ import { Check, Information, Monitor, Server, Clock, Cross, Earth, Shield, Phone, Download, User, Eye, Trash, Search } from "@strapi/icons";
10
9
  import { S as ShowHideButton, T as TertiaryButton, D as DangerButton, I as IconButtonPrimary, a as IconButtonWarning, b as IconButtonDanger } from "./StyledButtons-Cz8oYhmc.mjs";
11
- import { useNavigate } from "react-router-dom";
12
10
  const theme = {
13
11
  shadows: {
14
12
  sm: "0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1)",
@@ -37,7 +35,7 @@ const TwoColumnGrid = styled.div`
37
35
  display: grid;
38
36
  grid-template-columns: 1fr 1fr;
39
37
  gap: 24px;
40
-
38
+
41
39
  @media (max-width: 768px) {
42
40
  grid-template-columns: 1fr;
43
41
  }
@@ -66,14 +64,14 @@ const ModalStatusBadge = styled.span`
66
64
  font-weight: 700;
67
65
  letter-spacing: 0.5px;
68
66
  text-transform: uppercase;
69
-
67
+
70
68
  ${(props) => props.$online && `
71
69
  background: linear-gradient(135deg, rgba(22, 163, 74, 0.12) 0%, rgba(34, 197, 94, 0.3) 100%);
72
70
  color: var(--colors-success600, #166534);
73
71
  border: 2px solid rgba(34, 197, 94, 0.3);
74
72
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.2);
75
73
  `}
76
-
74
+
77
75
  ${(props) => !props.$online && `
78
76
  background: linear-gradient(135deg, rgba(128, 128, 128, 0.08) 0%, rgba(128, 128, 128, 0.2) 100%);
79
77
  color: var(--colors-neutral600);
@@ -85,85 +83,78 @@ const StatusDot$1 = styled.span`
85
83
  width: 10px;
86
84
  height: 10px;
87
85
  border-radius: 50%;
88
-
86
+
89
87
  ${(props) => props.$online && `
90
88
  background: var(--colors-success600, #22C55E);
91
89
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
92
90
  animation: pulse-green 2s ease-in-out infinite;
93
91
  `}
94
-
92
+
95
93
  ${(props) => !props.$online && `
96
94
  background: var(--colors-neutral500);
97
95
  `}
98
-
96
+
99
97
  @keyframes pulse-green {
100
98
  0%, 100% { opacity: 1; transform: scale(1); }
101
99
  50% { opacity: 0.7; transform: scale(1.15); }
102
100
  }
103
101
  `;
104
- const PremiumButton = styled.button`
105
- background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
106
- color: white;
107
- border: none;
108
- padding: 12px 24px;
109
- border-radius: 10px;
110
- font-weight: 700;
111
- font-size: 14px;
112
- cursor: pointer;
113
- transition: all 0.2s ease;
114
- box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
115
- margin-top: 8px;
116
-
117
- &:hover {
118
- background: linear-gradient(135deg, #D97706 0%, #B45309 100%);
119
- transform: translateY(-2px);
120
- box-shadow: 0 6px 16px rgba(245, 158, 11, 0.4);
121
- }
122
-
123
- &:active {
124
- transform: translateY(0);
125
- }
126
- `;
127
102
  const SessionDetailModal = ({ session, onClose, onSessionTerminated }) => {
128
103
  const { formatMessage } = useIntl();
129
104
  const { get, post } = useFetchClient();
130
105
  const { toggleNotification } = useNotification();
131
- const { isPremium } = useLicense();
132
106
  const [terminating, setTerminating] = useState(false);
133
107
  const [showUserAgent, setShowUserAgent] = useState(false);
134
108
  const [geoData, setGeoData] = useState(null);
135
109
  const [geoLoading, setGeoLoading] = useState(false);
136
110
  const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
137
- if (!session) return null;
138
- const deviceInfo = parseUserAgent(session.userAgent);
139
- const isOnline = session.isTrulyActive;
140
111
  useEffect(() => {
141
- if (isPremium && session.ipAddress && !geoData) {
142
- fetchGeolocationData();
143
- }
144
- }, [isPremium, session.ipAddress]);
145
- const fetchGeolocationData = async () => {
146
- setGeoLoading(true);
147
- try {
148
- const { data } = await get(`/${pluginId$1}/geolocation/${session.ipAddress}`);
149
- setGeoData(data.data);
150
- } catch (err) {
151
- console.error("[SessionDetailModal] Error fetching geolocation:", err);
152
- setGeoData({
153
- country_flag: "",
154
- country: "Unknown",
155
- city: "Unknown",
156
- timezone: "Unknown",
157
- securityScore: 50,
158
- riskLevel: "Unknown",
159
- isVpn: false,
160
- isProxy: false
161
- });
162
- } finally {
112
+ let cancelled = false;
113
+ const ipAddress = session?.ipAddress;
114
+ if (!ipAddress) {
115
+ setGeoData(null);
163
116
  setGeoLoading(false);
117
+ return () => {
118
+ cancelled = true;
119
+ };
164
120
  }
165
- };
166
- const premiumData = geoData || {
121
+ const fetchGeolocationData = async () => {
122
+ setGeoData(null);
123
+ setGeoLoading(true);
124
+ try {
125
+ const { data } = await get(`/${pluginId$1}/geolocation/${encodeURIComponent(ipAddress)}`);
126
+ if (!cancelled) {
127
+ setGeoData(data.data);
128
+ }
129
+ } catch (err) {
130
+ console.error("[SessionDetailModal] Error fetching geolocation:", err);
131
+ if (!cancelled) {
132
+ setGeoData({
133
+ country_flag: "",
134
+ country: "Unknown",
135
+ city: "Unknown",
136
+ timezone: "Unknown",
137
+ securityScore: 50,
138
+ riskLevel: "Unknown",
139
+ isVpn: false,
140
+ isProxy: false
141
+ });
142
+ }
143
+ } finally {
144
+ if (!cancelled) {
145
+ setGeoLoading(false);
146
+ }
147
+ }
148
+ };
149
+ fetchGeolocationData();
150
+ return () => {
151
+ cancelled = true;
152
+ };
153
+ }, [get, session?.ipAddress]);
154
+ if (!session) return null;
155
+ const deviceInfo = parseUserAgent(session.userAgent);
156
+ const isOnline = session.isTrulyActive;
157
+ const securityData = geoData || {
167
158
  country_flag: "",
168
159
  country: "Loading...",
169
160
  city: "Loading...",
@@ -311,7 +302,7 @@ const SessionDetailModal = ({ session, onClose, onSessionTerminated }) => {
311
302
  )
312
303
  ] }) })
313
304
  ] }),
314
- isPremium ? /* @__PURE__ */ jsxs(Section, { children: [
305
+ /* @__PURE__ */ jsxs(Section, { children: [
315
306
  /* @__PURE__ */ jsx(SectionTitle, { children: t("modal.section.security", "Location and Security") }),
316
307
  geoLoading ? /* @__PURE__ */ jsx(Box, { padding: 4, style: { textAlign: "center" }, children: /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("modal.security.loading", "Loading location data...") }) }) : /* @__PURE__ */ jsxs(TwoColumnGrid, { children: [
317
308
  /* @__PURE__ */ jsxs(Box, { children: [
@@ -321,11 +312,11 @@ const SessionDetailModal = ({ session, onClose, onSessionTerminated }) => {
321
312
  compact: true,
322
313
  icon: Earth,
323
314
  label: t("modal.security.country", "Country"),
324
- value: `${premiumData.country_flag || ""} ${premiumData.country}`.trim()
315
+ value: `${securityData.country_flag || ""} ${securityData.country}`.trim()
325
316
  }
326
317
  ),
327
- /* @__PURE__ */ jsx(DetailRow, { compact: true, icon: Earth, label: t("modal.security.city", "City"), value: premiumData.city }),
328
- /* @__PURE__ */ jsx(DetailRow, { compact: true, icon: Clock, label: t("modal.security.timezone", "Timezone"), value: premiumData.timezone })
318
+ /* @__PURE__ */ jsx(DetailRow, { compact: true, icon: Earth, label: t("modal.security.city", "City"), value: securityData.city }),
319
+ /* @__PURE__ */ jsx(DetailRow, { compact: true, icon: Clock, label: t("modal.security.timezone", "Timezone"), value: securityData.timezone })
329
320
  ] }),
330
321
  /* @__PURE__ */ jsxs(Box, { children: [
331
322
  /* @__PURE__ */ jsx(
@@ -334,7 +325,7 @@ const SessionDetailModal = ({ session, onClose, onSessionTerminated }) => {
334
325
  compact: true,
335
326
  icon: Shield,
336
327
  label: t("modal.security.score", "Security"),
337
- value: `${premiumData.securityScore}/100 (${premiumData.riskLevel})`
328
+ value: `${securityData.securityScore}/100 (${securityData.riskLevel})`
338
329
  }
339
330
  ),
340
331
  /* @__PURE__ */ jsx(
@@ -343,7 +334,7 @@ const SessionDetailModal = ({ session, onClose, onSessionTerminated }) => {
343
334
  compact: true,
344
335
  icon: Shield,
345
336
  label: t("modal.security.vpn", "VPN"),
346
- value: premiumData.isVpn ? t("modal.security.vpnWarning", "[WARNING] Yes") : t("modal.security.no", "No")
337
+ value: securityData.isVpn ? t("modal.security.vpnWarning", "[WARNING] Yes") : t("modal.security.no", "No")
347
338
  }
348
339
  ),
349
340
  /* @__PURE__ */ jsx(
@@ -352,35 +343,12 @@ const SessionDetailModal = ({ session, onClose, onSessionTerminated }) => {
352
343
  compact: true,
353
344
  icon: Shield,
354
345
  label: t("modal.security.proxy", "Proxy"),
355
- value: premiumData.isProxy ? t("modal.security.vpnWarning", "[WARNING] Yes") : t("modal.security.no", "No")
346
+ value: securityData.isProxy ? t("modal.security.vpnWarning", "[WARNING] Yes") : t("modal.security.no", "No")
356
347
  }
357
348
  )
358
349
  ] })
359
350
  ] })
360
- ] }) : /* @__PURE__ */ jsx(Section, { children: /* @__PURE__ */ jsx(
361
- Box,
362
- {
363
- padding: 5,
364
- style: {
365
- background: "linear-gradient(135deg, rgba(234, 179, 8, 0.12) 0%, rgba(234, 179, 8, 0.25) 100%)",
366
- borderRadius: "12px",
367
- border: "2px solid rgba(234, 179, 8, 0.4)",
368
- textAlign: "center"
369
- },
370
- children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "center", gap: 3, children: [
371
- /* @__PURE__ */ jsx(Crown, { style: { width: "40px", height: "40px", color: "var(--colors-warning600, #d97706)" } }),
372
- /* @__PURE__ */ jsx(Typography, { variant: "beta", style: { color: "var(--colors-warning600, #92400e)", fontWeight: "700" }, children: t("modal.premium.title", "Location and Security Analysis") }),
373
- /* @__PURE__ */ jsx(Typography, { variant: "omega", style: { color: "var(--colors-warning600, #78350f)", fontSize: "14px", lineHeight: "1.6" }, children: t("modal.premium.description", "Unlock premium features to get IP geolocation, security scoring, and VPN/Proxy detection for every session") }),
374
- /* @__PURE__ */ jsx(
375
- PremiumButton,
376
- {
377
- onClick: () => window.open("https://magicapi.fitlex.me", "_blank"),
378
- children: t("modal.premium.upgrade", "Upgrade to Premium")
379
- }
380
- )
381
- ] })
382
- }
383
- ) }),
351
+ ] }),
384
352
  /* @__PURE__ */ jsxs(Section, { children: [
385
353
  /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", style: { marginBottom: "12px" }, children: [
386
354
  /* @__PURE__ */ jsx(SectionTitle, { style: { marginBottom: 0, paddingBottom: 0, border: "none" }, children: t("modal.section.technical", "Technical Details") }),
@@ -428,7 +396,7 @@ const SessionDetailModal = ({ session, onClose, onSessionTerminated }) => {
428
396
  ] }) })
429
397
  ] }) });
430
398
  };
431
- const fadeIn$1 = keyframes`
399
+ const fadeIn = keyframes`
432
400
  from { opacity: 0; transform: translateY(10px); }
433
401
  to { opacity: 1; transform: translateY(0); }
434
402
  `;
@@ -456,7 +424,7 @@ const breakpoints = {
456
424
  mobile: "768px"
457
425
  };
458
426
  const Container = styled(Box)`
459
- ${css`animation: ${fadeIn$1} ${theme.transitions.slow};`}
427
+ ${css`animation: ${fadeIn} ${theme.transitions.slow};`}
460
428
  min-height: 100vh;
461
429
  max-width: 1440px;
462
430
  margin: 0 auto;
@@ -574,7 +542,7 @@ const StatCard = styled(Box)`
574
542
  position: relative;
575
543
  overflow: hidden;
576
544
  transition: all ${theme.transitions.normal};
577
- ${css`animation: ${fadeIn$1} ${theme.transitions.slow} backwards;`}
545
+ ${css`animation: ${fadeIn} ${theme.transitions.slow} backwards;`}
578
546
  animation-delay: ${(props) => props.$delay || "0s"};
579
547
  box-shadow: ${theme.shadows.sm};
580
548
  border: 1px solid rgba(128, 128, 128, 0.2);
@@ -868,7 +836,6 @@ const HomePage = () => {
868
836
  const { formatMessage } = useIntl();
869
837
  const { get, post, del } = useFetchClient();
870
838
  const { toggleNotification } = useNotification();
871
- const { isPremium } = useLicense();
872
839
  const t = (id, defaultMessage, values) => formatMessage({ id: getTranslation(id), defaultMessage }, values);
873
840
  const [sessions, setSessions] = useState([]);
874
841
  const [loading, setLoading] = useState(true);
@@ -928,15 +895,9 @@ const HomePage = () => {
928
895
  }
929
896
  };
930
897
  const handleExportCSV = () => {
931
- if (!isPremium) {
932
- toggleNotification({
933
- type: "warning",
934
- message: t("notifications.warning.premiumRequired", "Premium license required for export functionality")
935
- });
936
- return;
937
- }
938
898
  try {
939
899
  const headers = ["ID", "Status", "User Email", "Username", "Device", "Browser", "OS", "IP Address", "Login Time", "Last Active", "Logout Time", "Minutes Idle"];
900
+ const escapeCsvValue = (value) => `"${String(value ?? "").replace(/"/g, '""')}"`;
940
901
  const rows = filteredSessions.map((session) => {
941
902
  const deviceInfo = parseUserAgent(session.userAgent);
942
903
  const status = getSessionStatus(session);
@@ -956,8 +917,8 @@ const HomePage = () => {
956
917
  ];
957
918
  });
958
919
  const csvContent = [
959
- headers.join(","),
960
- ...rows.map((row) => row.map((cell) => `"${cell}"`).join(","))
920
+ headers.map(escapeCsvValue).join(","),
921
+ ...rows.map((row) => row.map(escapeCsvValue).join(","))
961
922
  ].join("\n");
962
923
  const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
963
924
  const link = document.createElement("a");
@@ -977,13 +938,6 @@ const HomePage = () => {
977
938
  }
978
939
  };
979
940
  const handleExportJSON = () => {
980
- if (!isPremium) {
981
- toggleNotification({
982
- type: "warning",
983
- message: t("notifications.warning.premiumRequired", "Premium license required for export functionality")
984
- });
985
- return;
986
- }
987
941
  try {
988
942
  const exportData = {
989
943
  exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -1085,7 +1039,7 @@ const HomePage = () => {
1085
1039
  ] }),
1086
1040
  /* @__PURE__ */ jsx(Subtitle, { children: t("homepage.subtitle", "Monitor and manage user sessions in real-time") })
1087
1041
  ] }),
1088
- isPremium && filteredSessions.length > 0 && /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
1042
+ filteredSessions.length > 0 && /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
1089
1043
  /* @__PURE__ */ jsx(
1090
1044
  Button,
1091
1045
  {
@@ -1487,540 +1441,7 @@ const HomePage = () => {
1487
1441
  )
1488
1442
  ] });
1489
1443
  };
1490
- const fadeIn = keyframes`
1491
- from { opacity: 0; }
1492
- to { opacity: 1; }
1493
- `;
1494
- const slideUp = keyframes`
1495
- from {
1496
- opacity: 0;
1497
- transform: translateY(30px);
1498
- }
1499
- to {
1500
- opacity: 1;
1501
- transform: translateY(0);
1502
- }
1503
- `;
1504
- const ModalOverlay = styled.div`
1505
- position: fixed;
1506
- top: 0;
1507
- left: 0;
1508
- right: 0;
1509
- bottom: 0;
1510
- background: rgba(4, 28, 47, 0.85);
1511
- backdrop-filter: blur(8px);
1512
- z-index: 9999;
1513
- display: flex;
1514
- align-items: center;
1515
- justify-content: center;
1516
- animation: ${fadeIn} 0.3s ease-out;
1517
- padding: 20px;
1518
- `;
1519
- const ModalContent = styled(Box)`
1520
- background: ${(p) => p.theme.colors.neutral0};
1521
- border-radius: 16px;
1522
- width: 100%;
1523
- max-width: 580px;
1524
- box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
1525
- animation: ${slideUp} 0.4s cubic-bezier(0.4, 0, 0.2, 1);
1526
- overflow: hidden;
1527
- `;
1528
- const GradientHeader = styled(Box)`
1529
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
1530
- padding: 32px 40px;
1531
- position: relative;
1532
- overflow: hidden;
1533
-
1534
- &::before {
1535
- content: '';
1536
- position: absolute;
1537
- top: -50%;
1538
- right: -50%;
1539
- width: 200%;
1540
- height: 200%;
1541
- background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
1542
- }
1543
- `;
1544
- const IconWrapper = styled.div`
1545
- width: 72px;
1546
- height: 72px;
1547
- border-radius: 50%;
1548
- background: rgba(255, 255, 255, 0.2);
1549
- display: flex;
1550
- align-items: center;
1551
- justify-content: center;
1552
- margin: 0 auto 16px;
1553
- backdrop-filter: blur(10px);
1554
- border: 2px solid rgba(255, 255, 255, 0.3);
1555
-
1556
- svg {
1557
- width: 36px;
1558
- height: 36px;
1559
- color: white;
1560
- }
1561
- `;
1562
- const CloseButton = styled.button`
1563
- position: absolute;
1564
- top: 16px;
1565
- right: 16px;
1566
- background: rgba(255, 255, 255, 0.2);
1567
- border: 2px solid rgba(255, 255, 255, 0.3);
1568
- border-radius: 50%;
1569
- width: 36px;
1570
- height: 36px;
1571
- display: flex;
1572
- align-items: center;
1573
- justify-content: center;
1574
- cursor: pointer;
1575
- transition: all 0.2s;
1576
- z-index: 10;
1577
-
1578
- svg {
1579
- width: 20px;
1580
- height: 20px;
1581
- color: white;
1582
- }
1583
-
1584
- &:hover {
1585
- background: rgba(255, 255, 255, 0.3);
1586
- transform: scale(1.1);
1587
- }
1588
-
1589
- &:active {
1590
- transform: scale(0.95);
1591
- }
1592
- `;
1593
- const ToggleButton = styled.button`
1594
- background: none;
1595
- border: none;
1596
- color: #667eea;
1597
- font-size: 13px;
1598
- font-weight: 600;
1599
- cursor: pointer;
1600
- padding: 8px 0;
1601
- text-decoration: underline;
1602
- transition: color 0.2s;
1603
-
1604
- &:hover {
1605
- color: #764ba2;
1606
- }
1607
- `;
1608
- const LicenseGuard = ({ children }) => {
1609
- const { get, post } = useFetchClient();
1610
- const { toggleNotification } = useNotification();
1611
- const navigate = useNavigate();
1612
- const [isChecking, setIsChecking] = useState(true);
1613
- const [needsLicense, setNeedsLicense] = useState(false);
1614
- const [isCreating, setIsCreating] = useState(false);
1615
- const [useExistingKey, setUseExistingKey] = useState(false);
1616
- const [useAutoCreate, setUseAutoCreate] = useState(true);
1617
- const [existingLicenseKey, setExistingLicenseKey] = useState("");
1618
- const [existingEmail, setExistingEmail] = useState("");
1619
- const [adminUser, setAdminUser] = useState(null);
1620
- const [formData, setFormData] = useState({
1621
- email: "",
1622
- firstName: "",
1623
- lastName: ""
1624
- });
1625
- useEffect(() => {
1626
- checkLicenseStatus();
1627
- fetchAdminUser();
1628
- }, []);
1629
- const fetchAdminUser = async () => {
1630
- try {
1631
- const response = await get("/admin/users/me");
1632
- const userData = response.data?.data || response.data;
1633
- if (userData) {
1634
- setAdminUser(userData);
1635
- setFormData({
1636
- email: userData.email || "",
1637
- firstName: userData.firstname || "",
1638
- lastName: userData.lastname || ""
1639
- });
1640
- }
1641
- } catch (error) {
1642
- console.debug("[LicenseGuard] Could not fetch admin user (not logged in yet)");
1643
- }
1644
- };
1645
- const checkLicenseStatus = async () => {
1646
- setIsChecking(true);
1647
- try {
1648
- const response = await get(`/${pluginId$1}/license/status`);
1649
- if (response.data.valid) {
1650
- setNeedsLicense(false);
1651
- } else {
1652
- setNeedsLicense(true);
1653
- }
1654
- } catch (error) {
1655
- console.error("[LicenseGuard] Error checking license:", error);
1656
- setNeedsLicense(true);
1657
- } finally {
1658
- setIsChecking(false);
1659
- }
1660
- };
1661
- const handleAutoCreateLicense = async (e) => {
1662
- e.preventDefault();
1663
- setIsCreating(true);
1664
- try {
1665
- const response = await post(`/${pluginId$1}/license/auto-create`, {});
1666
- if (response.data && response.data.success) {
1667
- toggleNotification({
1668
- type: "success",
1669
- message: "License automatically created! Reloading..."
1670
- });
1671
- setNeedsLicense(false);
1672
- setTimeout(() => {
1673
- window.location.reload();
1674
- }, 500);
1675
- } else {
1676
- throw new Error("Failed to auto-create license");
1677
- }
1678
- } catch (error) {
1679
- console.error("[LicenseGuard] Error auto-creating license:", error);
1680
- toggleNotification({
1681
- type: "danger",
1682
- message: error?.response?.data?.error?.message || "Failed to auto-create license. Try manual creation."
1683
- });
1684
- setIsCreating(false);
1685
- setUseAutoCreate(false);
1686
- }
1687
- };
1688
- const handleCreateLicense = async (e) => {
1689
- e.preventDefault();
1690
- if (!formData.email || !formData.firstName || !formData.lastName) {
1691
- toggleNotification({
1692
- type: "warning",
1693
- message: "Please fill in all fields"
1694
- });
1695
- return;
1696
- }
1697
- setIsCreating(true);
1698
- try {
1699
- const response = await post(`/${pluginId$1}/license/create`, formData);
1700
- if (response.data && response.data.success) {
1701
- toggleNotification({
1702
- type: "success",
1703
- message: "License created successfully! Reloading..."
1704
- });
1705
- setNeedsLicense(false);
1706
- setTimeout(() => {
1707
- window.location.reload();
1708
- }, 500);
1709
- } else {
1710
- throw new Error("Failed to create license");
1711
- }
1712
- } catch (error) {
1713
- console.error("[LicenseGuard] Error creating license:", error);
1714
- toggleNotification({
1715
- type: "danger",
1716
- message: error?.response?.data?.error?.message || "Failed to create license. Please try again."
1717
- });
1718
- setIsCreating(false);
1719
- }
1720
- };
1721
- const handleValidateExistingKey = async (e) => {
1722
- e.preventDefault();
1723
- if (!existingLicenseKey.trim() || !existingEmail.trim()) {
1724
- toggleNotification({
1725
- type: "warning",
1726
- message: "Please enter both license key and email address"
1727
- });
1728
- return;
1729
- }
1730
- setIsCreating(true);
1731
- try {
1732
- const response = await post(`/${pluginId$1}/license/store-key`, {
1733
- licenseKey: existingLicenseKey.trim(),
1734
- email: existingEmail.trim()
1735
- });
1736
- if (response.data && response.data.success) {
1737
- toggleNotification({
1738
- type: "success",
1739
- message: "License key validated successfully! Reloading..."
1740
- });
1741
- setNeedsLicense(false);
1742
- setTimeout(() => {
1743
- window.location.reload();
1744
- }, 500);
1745
- } else {
1746
- throw new Error("Invalid license key or email");
1747
- }
1748
- } catch (error) {
1749
- console.error("[LicenseGuard] Error validating license key:", error);
1750
- toggleNotification({
1751
- type: "danger",
1752
- message: error?.response?.data?.error?.message || "Invalid license key or email address. Please check and try again."
1753
- });
1754
- setIsCreating(false);
1755
- }
1756
- };
1757
- const handleClose = () => {
1758
- navigate("/content-manager");
1759
- };
1760
- if (isChecking) {
1761
- return /* @__PURE__ */ jsx(Box, { padding: 8, style: { textAlign: "center" }, children: /* @__PURE__ */ jsx(Loader, { children: "Checking license..." }) });
1762
- }
1763
- if (needsLicense) {
1764
- return /* @__PURE__ */ jsx(ModalOverlay, { children: /* @__PURE__ */ jsxs(ModalContent, { children: [
1765
- /* @__PURE__ */ jsxs(GradientHeader, { children: [
1766
- /* @__PURE__ */ jsx(CloseButton, { onClick: handleClose, type: "button", children: /* @__PURE__ */ jsx(Cross, {}) }),
1767
- /* @__PURE__ */ jsx(IconWrapper, { children: /* @__PURE__ */ jsx(Key, {}) }),
1768
- /* @__PURE__ */ jsxs(Box, { style: { textAlign: "center", position: "relative" }, children: [
1769
- /* @__PURE__ */ jsx(
1770
- Typography,
1771
- {
1772
- variant: "alpha",
1773
- style: {
1774
- color: "white",
1775
- fontSize: "24px",
1776
- fontWeight: "700",
1777
- marginBottom: "12px",
1778
- display: "block"
1779
- },
1780
- children: "🔐 Activate Session Manager"
1781
- }
1782
- ),
1783
- /* @__PURE__ */ jsx(
1784
- Typography,
1785
- {
1786
- variant: "epsilon",
1787
- style: {
1788
- color: "rgba(255, 255, 255, 0.9)",
1789
- fontSize: "14px",
1790
- display: "block"
1791
- },
1792
- children: useExistingKey ? "Enter your existing license key" : "Create a license to start using the plugin"
1793
- }
1794
- )
1795
- ] })
1796
- ] }),
1797
- /* @__PURE__ */ jsx("form", { onSubmit: useExistingKey ? handleValidateExistingKey : useAutoCreate ? handleAutoCreateLicense : handleCreateLicense, children: /* @__PURE__ */ jsx(
1798
- Box,
1799
- {
1800
- padding: 6,
1801
- paddingLeft: 8,
1802
- paddingRight: 8,
1803
- children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 5, style: { width: "100%" }, children: [
1804
- /* @__PURE__ */ jsxs(Box, { style: { textAlign: "center", width: "100%" }, children: [
1805
- !useExistingKey && /* @__PURE__ */ jsx(
1806
- ToggleButton,
1807
- {
1808
- type: "button",
1809
- onClick: () => setUseAutoCreate(!useAutoCreate),
1810
- disabled: isCreating,
1811
- style: { marginBottom: "8px", display: "block", margin: "0 auto" },
1812
- children: useAutoCreate ? "→ Manual entry" : "← Auto-create with my account"
1813
- }
1814
- ),
1815
- /* @__PURE__ */ jsx(
1816
- ToggleButton,
1817
- {
1818
- type: "button",
1819
- onClick: () => {
1820
- setUseExistingKey(!useExistingKey);
1821
- if (!useExistingKey) setUseAutoCreate(false);
1822
- },
1823
- disabled: isCreating,
1824
- children: useExistingKey ? "← Create new license" : "Have a license key? →"
1825
- }
1826
- )
1827
- ] }),
1828
- /* @__PURE__ */ jsx(
1829
- Box,
1830
- {
1831
- background: "primary100",
1832
- padding: 4,
1833
- style: {
1834
- borderRadius: "8px",
1835
- border: "2px solid rgba(14, 165, 233, 0.3)",
1836
- width: "100%"
1837
- },
1838
- children: /* @__PURE__ */ jsx(Typography, { variant: "omega", style: { fontSize: "13px", lineHeight: "1.6" }, children: useExistingKey ? "Enter your email and license key to activate." : useAutoCreate && adminUser && adminUser.email ? `Click "Activate" to auto-create a license with your account (${adminUser.email})` : useAutoCreate ? 'Click "Activate" to auto-create a license with your admin account' : "A license will be created with the details below." })
1839
- }
1840
- ),
1841
- useExistingKey ? (
1842
- // Existing License Key Input
1843
- /* @__PURE__ */ jsxs(Fragment, { children: [
1844
- /* @__PURE__ */ jsxs(Box, { style: { width: "100%" }, children: [
1845
- /* @__PURE__ */ jsx(
1846
- Typography,
1847
- {
1848
- variant: "pi",
1849
- fontWeight: "bold",
1850
- style: { marginBottom: "8px", display: "block" },
1851
- children: "Email Address *"
1852
- }
1853
- ),
1854
- /* @__PURE__ */ jsx(
1855
- TextInput,
1856
- {
1857
- placeholder: "admin@example.com",
1858
- type: "email",
1859
- value: existingEmail,
1860
- onChange: (e) => setExistingEmail(e.target.value),
1861
- required: true,
1862
- disabled: isCreating
1863
- }
1864
- ),
1865
- /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", style: { fontSize: "11px", marginTop: "4px" }, children: "Enter the email address associated with this license" })
1866
- ] }),
1867
- /* @__PURE__ */ jsxs(Box, { style: { width: "100%" }, children: [
1868
- /* @__PURE__ */ jsx(
1869
- Typography,
1870
- {
1871
- variant: "pi",
1872
- fontWeight: "bold",
1873
- style: { marginBottom: "8px", display: "block" },
1874
- children: "License Key *"
1875
- }
1876
- ),
1877
- /* @__PURE__ */ jsx(
1878
- TextInput,
1879
- {
1880
- placeholder: "67C5-40D2-7695-718C",
1881
- value: existingLicenseKey,
1882
- onChange: (e) => setExistingLicenseKey(e.target.value),
1883
- required: true,
1884
- disabled: isCreating
1885
- }
1886
- ),
1887
- /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", style: { fontSize: "11px", marginTop: "4px" }, children: "Enter the license key in the format: XXXX-XXXX-XXXX-XXXX" })
1888
- ] })
1889
- ] })
1890
- ) : useAutoCreate && adminUser ? (
1891
- // Auto-create mode - Show user info
1892
- /* @__PURE__ */ jsxs(
1893
- Box,
1894
- {
1895
- background: "success100",
1896
- padding: 5,
1897
- style: {
1898
- borderRadius: "8px",
1899
- border: "2px solid rgba(34, 197, 94, 0.3)",
1900
- textAlign: "center"
1901
- },
1902
- children: [
1903
- /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "bold", style: { marginBottom: "12px", display: "block" }, children: "Ready to activate with your account" }),
1904
- /* @__PURE__ */ jsxs(Typography, { variant: "pi", style: { marginBottom: "4px", display: "block" }, children: [
1905
- adminUser.firstname || "Admin",
1906
- " ",
1907
- adminUser.lastname || "User"
1908
- ] }),
1909
- /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: adminUser.email || "Loading..." })
1910
- ]
1911
- }
1912
- )
1913
- ) : (
1914
- // Manual Create License Fields
1915
- /* @__PURE__ */ jsxs(Fragment, { children: [
1916
- /* @__PURE__ */ jsxs(Box, { style: { width: "100%" }, children: [
1917
- /* @__PURE__ */ jsx(
1918
- Typography,
1919
- {
1920
- variant: "pi",
1921
- fontWeight: "bold",
1922
- style: { marginBottom: "8px", display: "block" },
1923
- children: "Email Address *"
1924
- }
1925
- ),
1926
- /* @__PURE__ */ jsx(
1927
- TextInput,
1928
- {
1929
- placeholder: "admin@example.com",
1930
- type: "email",
1931
- value: formData.email,
1932
- onChange: (e) => setFormData({ ...formData, email: e.target.value }),
1933
- required: true,
1934
- disabled: isCreating
1935
- }
1936
- )
1937
- ] }),
1938
- /* @__PURE__ */ jsxs(Box, { style: { width: "100%" }, children: [
1939
- /* @__PURE__ */ jsx(
1940
- Typography,
1941
- {
1942
- variant: "pi",
1943
- fontWeight: "bold",
1944
- style: { marginBottom: "8px", display: "block" },
1945
- children: "First Name *"
1946
- }
1947
- ),
1948
- /* @__PURE__ */ jsx(
1949
- TextInput,
1950
- {
1951
- placeholder: "John",
1952
- value: formData.firstName,
1953
- onChange: (e) => setFormData({ ...formData, firstName: e.target.value }),
1954
- required: true,
1955
- disabled: isCreating
1956
- }
1957
- )
1958
- ] }),
1959
- /* @__PURE__ */ jsxs(Box, { style: { width: "100%" }, children: [
1960
- /* @__PURE__ */ jsx(
1961
- Typography,
1962
- {
1963
- variant: "pi",
1964
- fontWeight: "bold",
1965
- style: { marginBottom: "8px", display: "block" },
1966
- children: "Last Name *"
1967
- }
1968
- ),
1969
- /* @__PURE__ */ jsx(
1970
- TextInput,
1971
- {
1972
- placeholder: "Doe",
1973
- value: formData.lastName,
1974
- onChange: (e) => setFormData({ ...formData, lastName: e.target.value }),
1975
- required: true,
1976
- disabled: isCreating
1977
- }
1978
- )
1979
- ] })
1980
- ] })
1981
- ),
1982
- /* @__PURE__ */ jsx(Flex, { gap: 3, justifyContent: "center", style: { marginTop: "16px" }, children: useExistingKey ? /* @__PURE__ */ jsx(
1983
- Button,
1984
- {
1985
- type: "submit",
1986
- size: "L",
1987
- startIcon: /* @__PURE__ */ jsx(Check, {}),
1988
- loading: isCreating,
1989
- disabled: isCreating || !existingLicenseKey.trim() || !existingEmail.trim(),
1990
- style: {
1991
- background: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
1992
- color: "white",
1993
- fontWeight: "600",
1994
- border: "none",
1995
- boxShadow: "0 4px 12px rgba(102, 126, 234, 0.4)"
1996
- },
1997
- children: "Validate License"
1998
- }
1999
- ) : /* @__PURE__ */ jsx(
2000
- Button,
2001
- {
2002
- type: "submit",
2003
- size: "L",
2004
- startIcon: /* @__PURE__ */ jsx(Check, {}),
2005
- loading: isCreating,
2006
- disabled: isCreating || !useAutoCreate && (!formData.email || !formData.firstName || !formData.lastName),
2007
- style: {
2008
- background: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
2009
- color: "white",
2010
- fontWeight: "600",
2011
- border: "none",
2012
- boxShadow: "0 4px 12px rgba(102, 126, 234, 0.4)"
2013
- },
2014
- children: useAutoCreate ? "Activate License" : "Create License"
2015
- }
2016
- ) })
2017
- ] })
2018
- }
2019
- ) })
2020
- ] }) });
2021
- }
2022
- return /* @__PURE__ */ jsx(Fragment, { children });
2023
- };
1444
+ const LicenseGuard = ({ children }) => /* @__PURE__ */ jsx(Fragment, { children });
2024
1445
  const pluginId = "magic-sessionmanager";
2025
1446
  const pluginPermissions = {
2026
1447
  access: [{ action: `plugin::${pluginId}.access`, subject: null }]