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