@moontra/moonui 2.2.7 → 2.3.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.
package/dist/index.mjs CHANGED
@@ -9622,11 +9622,159 @@ function ProComponentWrapper({
9622
9622
  componentId,
9623
9623
  componentName,
9624
9624
  className,
9625
- fallback
9625
+ fallback,
9626
+ requireCLI = true
9626
9627
  }) {
9627
- {
9628
- return /* @__PURE__ */ jsx("div", { className, children });
9628
+ const [authState, setAuthState] = useState({
9629
+ isAuthenticated: false,
9630
+ deviceValid: false,
9631
+ hasProAccess: false,
9632
+ loading: true
9633
+ });
9634
+ useEffect(() => {
9635
+ const isDevelopment2 = () => {
9636
+ const checks = {
9637
+ nodeEnv: process.env.NODE_ENV === "development",
9638
+ nextPublicEnv: process.env.NEXT_PUBLIC_VERCEL_ENV === "development",
9639
+ localhost: typeof window !== "undefined" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" || window.location.hostname.includes(".local")),
9640
+ port: typeof window !== "undefined" && (window.location.port === "3000" || window.location.port === "3001" || window.location.port === "8080"),
9641
+ vercelEnv: !process.env.VERCEL,
9642
+ ciEnv: !process.env.CI,
9643
+ deploymentEnv: !process.env.DEPLOYMENT_ENV
9644
+ };
9645
+ if (process.env.VERCEL || process.env.NETLIFY || process.env.RENDER || process.env.RAILWAY_ENVIRONMENT || process.env.FLY_APP_NAME || process.env.DEPLOYMENT_ENV === "production") {
9646
+ return false;
9647
+ }
9648
+ return checks.nodeEnv && checks.localhost && !checks.vercelEnv && !checks.ciEnv;
9649
+ };
9650
+ if (!isDevelopment2() || !requireCLI) {
9651
+ setAuthState({
9652
+ isAuthenticated: true,
9653
+ deviceValid: true,
9654
+ hasProAccess: true,
9655
+ loading: false
9656
+ });
9657
+ return;
9658
+ }
9659
+ async function checkAuth() {
9660
+ try {
9661
+ const cliToken = localStorage.getItem("moonui_cli_token");
9662
+ const deviceId = localStorage.getItem("moonui_device_id");
9663
+ if (!cliToken || !deviceId) {
9664
+ setAuthState({
9665
+ isAuthenticated: false,
9666
+ deviceValid: false,
9667
+ hasProAccess: false,
9668
+ loading: false
9669
+ });
9670
+ return;
9671
+ }
9672
+ const response = await fetch("/api/device/validate", {
9673
+ method: "POST",
9674
+ headers: {
9675
+ "Authorization": `Bearer ${cliToken}`,
9676
+ "X-Device-ID": deviceId,
9677
+ "Content-Type": "application/json"
9678
+ },
9679
+ body: JSON.stringify({
9680
+ environment: {
9681
+ nodeEnv: process.env.NODE_ENV,
9682
+ hostname: window.location.hostname,
9683
+ port: window.location.port,
9684
+ protocol: window.location.protocol
9685
+ }
9686
+ })
9687
+ });
9688
+ if (response.ok) {
9689
+ const data = await response.json();
9690
+ setAuthState({
9691
+ isAuthenticated: true,
9692
+ deviceValid: data.valid,
9693
+ hasProAccess: data.hasProAccess,
9694
+ loading: false
9695
+ });
9696
+ } else {
9697
+ setAuthState({
9698
+ isAuthenticated: false,
9699
+ deviceValid: false,
9700
+ hasProAccess: false,
9701
+ loading: false
9702
+ });
9703
+ }
9704
+ } catch (error) {
9705
+ setAuthState({
9706
+ isAuthenticated: false,
9707
+ deviceValid: false,
9708
+ hasProAccess: false,
9709
+ loading: false
9710
+ });
9711
+ }
9712
+ }
9713
+ checkAuth();
9714
+ }, [requireCLI]);
9715
+ if (authState.loading) {
9716
+ return /* @__PURE__ */ jsx("div", { className: cn("animate-pulse bg-gray-200 dark:bg-gray-800 rounded-lg h-32", className), children: /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsx("div", { className: "text-sm text-gray-500", children: "Loading..." }) }) });
9717
+ }
9718
+ const isDevelopment = () => {
9719
+ const checks = {
9720
+ nodeEnv: process.env.NODE_ENV === "development",
9721
+ localhost: typeof window !== "undefined" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" || window.location.hostname.includes(".local")),
9722
+ port: typeof window !== "undefined" && (window.location.port === "3000" || window.location.port === "3001" || window.location.port === "8080")
9723
+ };
9724
+ if (process.env.VERCEL || process.env.NETLIFY || process.env.RENDER || process.env.RAILWAY_ENVIRONMENT || process.env.FLY_APP_NAME) {
9725
+ return false;
9726
+ }
9727
+ return checks.nodeEnv && checks.localhost;
9728
+ };
9729
+ if (isDevelopment() && requireCLI) {
9730
+ if (!authState.isAuthenticated) {
9731
+ return /* @__PURE__ */ jsxs("div", { className: cn("relative", className), children: [
9732
+ /* @__PURE__ */ jsx("div", { className: "blur-sm grayscale-[0.3] opacity-60 pointer-events-none", children: fallback || children }),
9733
+ /* @__PURE__ */ jsx("div", { className: "absolute inset-0 bg-gradient-to-br from-red-500/10 via-transparent to-orange-500/10 border-2 border-dashed border-red-400/30 rounded-lg flex items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "text-center space-y-3 p-6", children: [
9734
+ /* @__PURE__ */ jsxs(Badge, { variant: "destructive", className: "mb-2", children: [
9735
+ /* @__PURE__ */ jsx(Lock, { className: "w-3 h-3 mr-1" }),
9736
+ "CLI AUTH REQUIRED"
9737
+ ] }),
9738
+ /* @__PURE__ */ jsx("h3", { className: "font-semibold text-gray-900 dark:text-gray-100", children: "CLI Authentication Required" }),
9739
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-gray-600 dark:text-gray-400 max-w-xs", children: "Run the following command to authenticate:" }),
9740
+ /* @__PURE__ */ jsx("code", { className: "block bg-black/80 text-green-400 p-2 rounded text-xs", children: "npx moonui auth login" })
9741
+ ] }) })
9742
+ ] });
9743
+ }
9744
+ if (!authState.deviceValid) {
9745
+ return /* @__PURE__ */ jsxs("div", { className: cn("relative", className), children: [
9746
+ /* @__PURE__ */ jsx("div", { className: "blur-sm grayscale-[0.3] opacity-60 pointer-events-none", children: fallback || children }),
9747
+ /* @__PURE__ */ jsx("div", { className: "absolute inset-0 bg-gradient-to-br from-yellow-500/10 via-transparent to-orange-500/10 border-2 border-dashed border-yellow-400/30 rounded-lg flex items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "text-center space-y-3 p-6", children: [
9748
+ /* @__PURE__ */ jsxs(Badge, { variant: "secondary", className: "bg-yellow-500 text-white mb-2", children: [
9749
+ /* @__PURE__ */ jsx(Zap, { className: "w-3 h-3 mr-1" }),
9750
+ "DEVICE LIMIT"
9751
+ ] }),
9752
+ /* @__PURE__ */ jsx("h3", { className: "font-semibold text-gray-900 dark:text-gray-100", children: "Device Limit Exceeded" }),
9753
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-gray-600 dark:text-gray-400 max-w-xs", children: "This device is not registered or you've reached your device limit" }),
9754
+ /* @__PURE__ */ jsx(
9755
+ Button,
9756
+ {
9757
+ size: "sm",
9758
+ className: "bg-gradient-to-r from-yellow-500 to-orange-500",
9759
+ onClick: () => window.open("/dashboard/devices", "_blank"),
9760
+ children: "Manage Devices"
9761
+ }
9762
+ )
9763
+ ] }) })
9764
+ ] });
9765
+ }
9766
+ if (!authState.hasProAccess) {
9767
+ return /* @__PURE__ */ jsx(
9768
+ LockedComponent,
9769
+ {
9770
+ componentName: componentName || componentId,
9771
+ className,
9772
+ children: fallback || children
9773
+ }
9774
+ );
9775
+ }
9629
9776
  }
9777
+ return /* @__PURE__ */ jsx("div", { className, children });
9630
9778
  }
9631
9779
  function ProBadge({ className }) {
9632
9780
  return /* @__PURE__ */ jsxs(