@moontra/moonui-pro 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -147,15 +147,16 @@ interface AuthContextType extends AuthState {
147
147
  clearAuth: () => void;
148
148
  }
149
149
  /**
150
- * MoonUI Auth Provider - Centralized authentication state
151
- * This provider ensures only ONE API call is made for all components
150
+ * MoonUI Auth Provider - Simplified Authentication
151
+ * 1. Check embedded license token (from PostInstall)
152
+ * 2. Check localhost CLI auth server (development only)
153
+ * 3. No production API calls from browser
152
154
  */
153
155
  declare function MoonUIAuthProvider({ children }: {
154
156
  children: ReactNode;
155
157
  }): react_jsx_runtime.JSX.Element;
156
158
  /**
157
159
  * Hook to use auth context
158
- * Falls back to direct API call if context is not available
159
160
  */
160
161
  declare function useMoonUIAuth(): AuthContextType;
161
162
 
package/dist/index.mjs CHANGED
@@ -2137,6 +2137,17 @@ function readLicenseTokenClient() {
2137
2137
  return null;
2138
2138
  }
2139
2139
  }
2140
+ function saveLicenseTokenClient(token) {
2141
+ try {
2142
+ if (typeof window === "undefined" || !window.localStorage) {
2143
+ return;
2144
+ }
2145
+ localStorage.setItem("moonui_license_token", JSON.stringify(token));
2146
+ console.log("[MoonUI] License token cached in browser");
2147
+ } catch (error) {
2148
+ console.error("[MoonUI] Error saving client license token:", error);
2149
+ }
2150
+ }
2140
2151
  var AuthContext = createContext(void 0);
2141
2152
  var authPromise = null;
2142
2153
  var lastFetchTime = 0;
@@ -2154,24 +2165,6 @@ function MoonUIAuthProvider({ children }) {
2154
2165
  isAdmin: false
2155
2166
  });
2156
2167
  const isMounted = useRef(true);
2157
- const readValidationFromCookie = () => {
2158
- if (typeof document === "undefined")
2159
- return null;
2160
- try {
2161
- const cookies = document.cookie.split(";");
2162
- const statusCookie = cookies.find(
2163
- (c2) => c2.trim().startsWith("moonui_pro_status=")
2164
- );
2165
- if (statusCookie) {
2166
- const value2 = statusCookie.split("=")[1];
2167
- const decoded = decodeURIComponent(value2);
2168
- return JSON.parse(decoded);
2169
- }
2170
- } catch (error) {
2171
- console.error("[MoonUI Auth] Error reading cookie:", error);
2172
- }
2173
- return null;
2174
- };
2175
2168
  const validateAuth = async (forceRefresh2 = false) => {
2176
2169
  const now = Date.now();
2177
2170
  if (!forceRefresh2 && now - lastFetchTime < FETCH_COOLDOWN) {
@@ -2182,79 +2175,34 @@ function MoonUIAuthProvider({ children }) {
2182
2175
  console.log("[MoonUI Auth] Using ongoing request");
2183
2176
  return authPromise;
2184
2177
  }
2185
- const licenseToken = readLicenseTokenClient();
2186
- if (licenseToken && licenseToken.hasProAccess) {
2187
- console.log("[MoonUI Auth] Using embedded license token - Pro access granted");
2188
- const tokenState = {
2189
- isLoading: false,
2190
- hasProAccess: true,
2191
- isAuthenticated: true,
2192
- subscriptionPlan: licenseToken.plan === "lifetime" ? "lifetime" : "free",
2193
- subscription: {
2194
- status: "active",
2195
- plan: licenseToken.plan === "lifetime" ? "lifetime" : "free"
2196
- },
2197
- isAdmin: false
2198
- };
2199
- setState(tokenState);
2200
- return tokenState;
2201
- }
2202
- if (!forceRefresh2) {
2203
- const cached = readValidationFromCookie();
2204
- if (cached && cached.valid) {
2205
- const age = now - cached.timestamp;
2206
- const maxAge = AUTH_CONFIG.cache.serverCacheDuration;
2207
- if (age < maxAge) {
2208
- console.log("[MoonUI Auth] Using cookie cache");
2209
- const cachedState2 = {
2178
+ authPromise = (async () => {
2179
+ try {
2180
+ lastFetchTime = now;
2181
+ const licenseToken = readLicenseTokenClient();
2182
+ if (licenseToken && licenseToken.hasProAccess) {
2183
+ console.log("[MoonUI Auth] Using embedded license token - Pro access granted");
2184
+ const tokenState = {
2210
2185
  isLoading: false,
2211
- hasProAccess: cached.hasProAccess,
2212
- isAuthenticated: cached.valid,
2213
- subscriptionPlan: cached.hasProAccess ? "lifetime" : "free",
2186
+ hasProAccess: true,
2187
+ isAuthenticated: true,
2188
+ subscriptionPlan: licenseToken.plan === "lifetime" ? "lifetime" : "free",
2214
2189
  subscription: {
2215
- status: cached.hasProAccess ? "active" : "inactive",
2216
- plan: cached.hasProAccess ? "lifetime" : "free"
2190
+ status: "active",
2191
+ plan: licenseToken.plan === "lifetime" ? "lifetime" : "free"
2217
2192
  },
2218
2193
  isAdmin: false
2219
2194
  };
2220
- setState(cachedState2);
2221
- return cachedState2;
2222
- }
2223
- }
2224
- }
2225
- authPromise = (async () => {
2226
- try {
2227
- lastFetchTime = now;
2228
- let isProduction = false;
2229
- let isDevelopment = true;
2230
- let environmentInfo = {};
2231
- try {
2232
- const envResponse = await fetch("/api/environment", {
2233
- method: "GET",
2234
- cache: "no-store"
2235
- });
2236
- if (envResponse.ok) {
2237
- environmentInfo = await envResponse.json();
2238
- isProduction = environmentInfo.isProduction;
2239
- isDevelopment = environmentInfo.isDevelopment;
2240
- console.log("[MoonUI Auth] Runtime Environment Detection:", {
2241
- ...environmentInfo.debug,
2242
- environment: environmentInfo.environment,
2243
- isProduction,
2244
- isDevelopment
2245
- });
2246
- } else {
2247
- console.warn("[MoonUI Auth] Failed to fetch environment info, falling back to development mode");
2195
+ if (isMounted.current) {
2196
+ setState(tokenState);
2248
2197
  }
2249
- } catch (error) {
2250
- console.warn("[MoonUI Auth] Error fetching environment info:", error);
2198
+ authPromise = null;
2199
+ return tokenState;
2251
2200
  }
2252
- if (isDevelopment) {
2253
- let response;
2254
- const authServerUrl = typeof window !== "undefined" ? process.env.NEXT_PUBLIC_MOONUI_AUTH_SERVER || "http://localhost:7878" : "http://localhost:7878";
2201
+ const isLocalhost = typeof window !== "undefined" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1");
2202
+ if (isLocalhost) {
2255
2203
  try {
2256
- console.log("[MoonUI Auth] Development mode - checking CLI auth server at:", authServerUrl);
2257
- response = await fetch(`${authServerUrl}/validate`, {
2204
+ console.log("[MoonUI Auth] Development mode - checking CLI auth server");
2205
+ const response = await fetch("http://localhost:7878/validate", {
2258
2206
  method: "GET",
2259
2207
  headers: {
2260
2208
  "X-Component": "MoonUIAuthProvider",
@@ -2263,8 +2211,18 @@ function MoonUIAuthProvider({ children }) {
2263
2211
  credentials: "include"
2264
2212
  });
2265
2213
  if (response && response.ok) {
2266
- console.log("[MoonUI Auth] Using CLI auth server");
2214
+ console.log("[MoonUI Auth] CLI auth server available");
2267
2215
  const data = await response.json();
2216
+ if (data.valid && data.hasProAccess) {
2217
+ saveLicenseTokenClient({
2218
+ valid: true,
2219
+ hasProAccess: data.hasProAccess,
2220
+ plan: data.plan || "lifetime",
2221
+ expiresAt: data.expiresAt || Date.now() + 30 * 24 * 60 * 60 * 1e3,
2222
+ domain: "localhost",
2223
+ timestamp: Date.now()
2224
+ });
2225
+ }
2268
2226
  const newState = {
2269
2227
  isLoading: false,
2270
2228
  hasProAccess: data.hasProAccess || false,
@@ -2281,71 +2239,12 @@ function MoonUIAuthProvider({ children }) {
2281
2239
  }
2282
2240
  authPromise = null;
2283
2241
  return newState;
2284
- } else {
2285
- throw new Error("Auth server not available");
2286
2242
  }
2287
2243
  } catch (error) {
2288
- console.log('[MoonUI Auth] Auth server not available in development. Run "moonui dev" to enable Pro features.');
2289
- }
2290
- }
2291
- if (isProduction) {
2292
- const licenseKey = environmentInfo.hasLicenseKey ? process.env.NEXT_PUBLIC_MOONUI_LICENSE_KEY || process.env.MOONUI_LICENSE_KEY || process.env.VITE_MOONUI_LICENSE_KEY || process.env.REACT_APP_MOONUI_LICENSE_KEY || "check-server" : null;
2293
- if (licenseKey) {
2294
- console.log("[MoonUI Auth] Production mode - validating license key...");
2295
- try {
2296
- const currentDomain = typeof window !== "undefined" ? window.location.hostname : process.env.VERCEL_URL || process.env.NEXT_PUBLIC_VERCEL_URL || "";
2297
- const apiUrl = "https://moonui.dev/api/v1/license/validate";
2298
- const validationResponse = await fetch(apiUrl, {
2299
- method: "POST",
2300
- headers: {
2301
- "Content-Type": "application/json"
2302
- },
2303
- body: JSON.stringify({
2304
- licenseKey,
2305
- domain: currentDomain
2306
- })
2307
- });
2308
- if (validationResponse.ok) {
2309
- const validationData = await validationResponse.json();
2310
- if (validationData.valid && validationData.hasProAccess) {
2311
- console.log("[MoonUI Auth] License key validated successfully");
2312
- const newState = {
2313
- isLoading: false,
2314
- hasProAccess: validationData.hasProAccess,
2315
- isAuthenticated: true,
2316
- subscriptionPlan: validationData.plan === "lifetime" ? "lifetime" : "free",
2317
- subscription: {
2318
- status: validationData.hasProAccess ? "active" : "inactive",
2319
- plan: validationData.plan === "lifetime" ? "lifetime" : "free"
2320
- },
2321
- isAdmin: false
2322
- };
2323
- if (typeof document !== "undefined" && validationData.cacheDuration) {
2324
- const cacheData = {
2325
- valid: true,
2326
- hasProAccess: validationData.hasProAccess,
2327
- timestamp: Date.now()
2328
- };
2329
- document.cookie = `moonui_pro_status=${encodeURIComponent(
2330
- JSON.stringify(cacheData)
2331
- )}; max-age=${Math.floor(validationData.cacheDuration / 1e3)}; path=/; SameSite=Strict`;
2332
- }
2333
- if (isMounted.current) {
2334
- setState(newState);
2335
- }
2336
- authPromise = null;
2337
- return newState;
2338
- } else {
2339
- console.warn("[MoonUI Auth] License key validation failed:", validationData.error || "Invalid license");
2340
- }
2341
- } else {
2342
- console.error("[MoonUI Auth] License validation request failed:", validationResponse.status);
2343
- }
2344
- } catch (error) {
2345
- console.error("[MoonUI Auth] License validation error:", error);
2346
- }
2244
+ console.log('[MoonUI Auth] CLI auth server not available. Run "moonui dev" to enable Pro features.');
2347
2245
  }
2348
2246
  }
2247
+ console.log("[MoonUI Auth] No authentication available - using free plan");
2349
2248
  const freeState = {
2350
2249
  isLoading: false,
2351
2250
  hasProAccess: false,
@@ -2378,9 +2277,8 @@ function MoonUIAuthProvider({ children }) {
2378
2277
  if (isMounted.current) {
2379
2278
  setState(errorState);
2380
2279
  }
2381
- return errorState;
2382
- } finally {
2383
2280
  authPromise = null;
2281
+ return errorState;
2384
2282
  }
2385
2283
  })();
2386
2284
  return authPromise;
@@ -2398,8 +2296,6 @@ function MoonUIAuthProvider({ children }) {
2398
2296
  };
2399
2297
  const clearAuth2 = () => {
2400
2298
  console.log("[MoonUI Auth] Clearing auth");
2401
- document.cookie = "moonui_pro_status=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
2402
- document.cookie = "moonui_auth_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
2403
2299
  setState({
2404
2300
  isLoading: false,
2405
2301
  hasProAccess: false,
@@ -2424,7 +2320,7 @@ function MoonUIAuthProvider({ children }) {
2424
2320
  function useMoonUIAuth() {
2425
2321
  const context = useContext(AuthContext);
2426
2322
  if (!context) {
2427
- console.warn("[MoonUI Auth] No AuthProvider found, components will make individual API calls");
2323
+ console.warn("[MoonUI Auth] No AuthProvider found, using free plan");
2428
2324
  return {
2429
2325
  isLoading: false,
2430
2326
  hasProAccess: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moontra/moonui-pro",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Premium React components for MoonUI - Advanced UI library with 50+ pro components including performance, interactive, and gesture components",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",