@moontra/moonui-pro 2.37.17 → 2.37.18

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
@@ -146,32 +146,13 @@ interface AuthContextType extends AuthState {
146
146
  refreshAuth: () => Promise<void>;
147
147
  clearAuth: () => void;
148
148
  }
149
- interface MoonUIAuthProviderProps {
150
- children: ReactNode;
151
- /**
152
- * Environment mode - defaults to 'development' if not provided
153
- * In Next.js: environment={process.env.NODE_ENV}
154
- * In Vite: environment={import.meta.env.MODE}
155
- * In CRA: environment={process.env.NODE_ENV}
156
- */
157
- environment?: 'development' | 'production' | 'test';
158
- /**
159
- * License key for production environments
160
- * In Next.js: licenseKey={process.env.NEXT_PUBLIC_MOONUI_LICENSE_KEY}
161
- * In Vite: licenseKey={import.meta.env.VITE_MOONUI_LICENSE_KEY}
162
- * In CRA: licenseKey={process.env.REACT_APP_MOONUI_LICENSE_KEY}
163
- */
164
- licenseKey?: string;
165
- /**
166
- * Force production mode (useful for testing)
167
- */
168
- forceProduction?: boolean;
169
- }
170
149
  /**
171
150
  * MoonUI Auth Provider - Centralized authentication state
172
151
  * This provider ensures only ONE API call is made for all components
173
152
  */
174
- declare function MoonUIAuthProvider({ children, environment, licenseKey, forceProduction }: MoonUIAuthProviderProps): react_jsx_runtime.JSX.Element;
153
+ declare function MoonUIAuthProvider({ children }: {
154
+ children: ReactNode;
155
+ }): react_jsx_runtime.JSX.Element;
175
156
  /**
176
157
  * Hook to use auth context
177
158
  * Falls back to direct API call if context is not available
package/dist/index.mjs CHANGED
@@ -2118,12 +2118,7 @@ var AuthContext = createContext(void 0);
2118
2118
  var authPromise = null;
2119
2119
  var lastFetchTime = 0;
2120
2120
  var FETCH_COOLDOWN = 5e3;
2121
- function MoonUIAuthProvider({
2122
- children,
2123
- environment = "development",
2124
- licenseKey,
2125
- forceProduction = false
2126
- }) {
2121
+ function MoonUIAuthProvider({ children }) {
2127
2122
  const [state, setState] = useState({
2128
2123
  isLoading: true,
2129
2124
  hasProAccess: false,
@@ -2190,16 +2185,30 @@ function MoonUIAuthProvider({
2190
2185
  authPromise = (async () => {
2191
2186
  try {
2192
2187
  lastFetchTime = now;
2193
- const isProduction = forceProduction || environment === "production";
2194
- const isDevelopment = !isProduction;
2195
- const hasLicenseKey = !!licenseKey;
2196
- console.log("[MoonUI Auth] Environment Detection:", {
2197
- environment,
2198
- forceProduction,
2199
- hasLicenseKey,
2200
- isProduction,
2201
- isDevelopment
2202
- });
2188
+ let isProduction = false;
2189
+ let isDevelopment = true;
2190
+ let environmentInfo = {};
2191
+ try {
2192
+ const envResponse = await fetch("/api/environment", {
2193
+ method: "GET",
2194
+ cache: "no-store"
2195
+ });
2196
+ if (envResponse.ok) {
2197
+ environmentInfo = await envResponse.json();
2198
+ isProduction = environmentInfo.isProduction;
2199
+ isDevelopment = environmentInfo.isDevelopment;
2200
+ console.log("[MoonUI Auth] Runtime Environment Detection:", {
2201
+ ...environmentInfo.debug,
2202
+ environment: environmentInfo.environment,
2203
+ isProduction,
2204
+ isDevelopment
2205
+ });
2206
+ } else {
2207
+ console.warn("[MoonUI Auth] Failed to fetch environment info, falling back to development mode");
2208
+ }
2209
+ } catch (error) {
2210
+ console.warn("[MoonUI Auth] Error fetching environment info:", error);
2211
+ }
2203
2212
  if (isDevelopment) {
2204
2213
  let response;
2205
2214
  const authServerUrl = typeof window !== "undefined" ? process.env.NEXT_PUBLIC_MOONUI_AUTH_SERVER || "http://localhost:7878" : "http://localhost:7878";
@@ -2239,47 +2248,63 @@ function MoonUIAuthProvider({
2239
2248
  console.log('[MoonUI Auth] Auth server not available in development. Run "moonui dev" to enable Pro features.');
2240
2249
  }
2241
2250
  }
2242
- if (isProduction && licenseKey) {
2243
- console.log("[MoonUI Auth] Production mode - License key provided");
2244
- const cachedValidation = readValidationFromCookie();
2245
- if (cachedValidation && cachedValidation.valid && cachedValidation.hasProAccess) {
2246
- console.log("[MoonUI Auth] Using cached server validation");
2247
- const newState2 = {
2248
- isLoading: false,
2249
- hasProAccess: cachedValidation.hasProAccess,
2250
- isAuthenticated: true,
2251
- subscriptionPlan: "lifetime",
2252
- subscription: {
2253
- status: "active",
2254
- plan: "lifetime"
2255
- },
2256
- isAdmin: false
2257
- };
2258
- if (isMounted.current) {
2259
- setState(newState2);
2251
+ if (isProduction) {
2252
+ 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;
2253
+ if (licenseKey) {
2254
+ console.log("[MoonUI Auth] Production mode - validating license key...");
2255
+ try {
2256
+ const currentDomain = typeof window !== "undefined" ? window.location.hostname : process.env.VERCEL_URL || process.env.NEXT_PUBLIC_VERCEL_URL || "";
2257
+ const apiUrl = "https://moonui.dev/api/v1/license/validate";
2258
+ const validationResponse = await fetch(apiUrl, {
2259
+ method: "POST",
2260
+ headers: {
2261
+ "Content-Type": "application/json"
2262
+ },
2263
+ body: JSON.stringify({
2264
+ licenseKey,
2265
+ domain: currentDomain
2266
+ })
2267
+ });
2268
+ if (validationResponse.ok) {
2269
+ const validationData = await validationResponse.json();
2270
+ if (validationData.valid && validationData.hasProAccess) {
2271
+ console.log("[MoonUI Auth] License key validated successfully");
2272
+ const newState = {
2273
+ isLoading: false,
2274
+ hasProAccess: validationData.hasProAccess,
2275
+ isAuthenticated: true,
2276
+ subscriptionPlan: validationData.plan === "lifetime" ? "lifetime" : "free",
2277
+ subscription: {
2278
+ status: validationData.hasProAccess ? "active" : "inactive",
2279
+ plan: validationData.plan === "lifetime" ? "lifetime" : "free"
2280
+ },
2281
+ isAdmin: false
2282
+ };
2283
+ if (typeof document !== "undefined" && validationData.cacheDuration) {
2284
+ const cacheData = {
2285
+ valid: true,
2286
+ hasProAccess: validationData.hasProAccess,
2287
+ timestamp: Date.now()
2288
+ };
2289
+ document.cookie = `moonui_pro_status=${encodeURIComponent(
2290
+ JSON.stringify(cacheData)
2291
+ )}; max-age=${Math.floor(validationData.cacheDuration / 1e3)}; path=/; SameSite=Strict`;
2292
+ }
2293
+ if (isMounted.current) {
2294
+ setState(newState);
2295
+ }
2296
+ authPromise = null;
2297
+ return newState;
2298
+ } else {
2299
+ console.warn("[MoonUI Auth] License key validation failed:", validationData.error || "Invalid license");
2300
+ }
2301
+ } else {
2302
+ console.error("[MoonUI Auth] License validation request failed:", validationResponse.status);
2303
+ }
2304
+ } catch (error) {
2305
+ console.error("[MoonUI Auth] License validation error:", error);
2260
2306
  }
2261
- authPromise = null;
2262
- return newState2;
2263
- }
2264
- console.log("[MoonUI Auth] License key detected - granting Pro access");
2265
- console.log("[MoonUI Auth] Note: Actual license validation should be done server-side");
2266
- const newState = {
2267
- isLoading: false,
2268
- hasProAccess: true,
2269
- // Grant access since license key is provided
2270
- isAuthenticated: true,
2271
- subscriptionPlan: "lifetime",
2272
- subscription: {
2273
- status: "active",
2274
- plan: "lifetime"
2275
- },
2276
- isAdmin: false
2277
- };
2278
- if (isMounted.current) {
2279
- setState(newState);
2280
2307
  }
2281
- authPromise = null;
2282
- return newState;
2283
2308
  }
2284
2309
  const freeState = {
2285
2310
  isLoading: false,
package/dist/server.d.ts CHANGED
@@ -53,66 +53,6 @@ declare function performServerValidation(): Promise<{
53
53
  cached?: boolean;
54
54
  }>;
55
55
 
56
- /**
57
- * Server-side license validation helper
58
- * This should be used in API routes or server components to validate license keys
59
- * and set appropriate cookies for client-side caching
60
- */
61
- interface ValidateLicenseOptions {
62
- licenseKey: string;
63
- domain: string;
64
- }
65
- interface ValidationResponse {
66
- valid: boolean;
67
- hasProAccess: boolean;
68
- plan?: 'lifetime' | 'monthly' | 'annual' | 'free';
69
- error?: string;
70
- cacheDuration?: number;
71
- }
72
- /**
73
- * Validate a MoonUI license key on the server
74
- * This function should be called from your API routes or server components
75
- *
76
- * @example Next.js API Route
77
- * ```typescript
78
- * // app/api/validate-license/route.ts
79
- * import { validateLicense } from '@moontra/moonui-pro/server';
80
- * import { NextResponse } from 'next/server';
81
- *
82
- * export async function POST(request: Request) {
83
- * const { licenseKey } = await request.json();
84
- * const domain = request.headers.get('host') || '';
85
- *
86
- * const result = await validateLicense({ licenseKey, domain });
87
- *
88
- * const response = NextResponse.json(result);
89
- *
90
- * // Set cookie if validation successful
91
- * if (result.valid && result.hasProAccess) {
92
- * response.cookies.set('moonui_pro_status', JSON.stringify({
93
- * valid: true,
94
- * hasProAccess: result.hasProAccess,
95
- * timestamp: Date.now()
96
- * }), {
97
- * httpOnly: false, // Must be accessible by client
98
- * secure: process.env.NODE_ENV === 'production',
99
- * sameSite: 'strict',
100
- * maxAge: result.cacheDuration || 86400 // 24 hours default
101
- * });
102
- * }
103
- *
104
- * return response;
105
- * }
106
- * ```
107
- */
108
- declare function validateLicense({ licenseKey, domain }: ValidateLicenseOptions): Promise<ValidationResponse>;
109
- /**
110
- * Helper to set MoonUI auth cookies
111
- * Use this after successful validation
112
- */
113
- declare function setAuthCookie(response: any, // Response object from your framework
114
- validationResult: ValidationResponse): void;
115
-
116
56
  /**
117
57
  * MoonUI Pro Authentication Configuration
118
58
  *
@@ -160,4 +100,4 @@ type AuthConfig = typeof AUTH_CONFIG;
160
100
  type CacheConfig = typeof AUTH_CONFIG.cache;
161
101
  type SecurityConfig = typeof AUTH_CONFIG.security;
162
102
 
163
- export { AUTH_CONFIG, AuthConfig, CacheConfig, SecurityConfig, clearValidationCookies, decryptData, encryptData, generateServerDeviceFingerprint, getValidationFromCookies, performServerValidation, setAuthCookie, setValidationInCookies, validateLicense, validateWithMoonUIServer };
103
+ export { AUTH_CONFIG, AuthConfig, CacheConfig, SecurityConfig, clearValidationCookies, decryptData, encryptData, generateServerDeviceFingerprint, getValidationFromCookies, performServerValidation, setValidationInCookies, validateWithMoonUIServer };
package/dist/server.mjs CHANGED
@@ -3148,67 +3148,6 @@ async function performServerValidation() {
3148
3148
  return { ...result, cached: false };
3149
3149
  }
3150
3150
 
3151
- // src/lib/server-validate.ts
3152
- async function validateLicense({
3153
- licenseKey,
3154
- domain
3155
- }) {
3156
- try {
3157
- const response = await fetch("https://moonui.dev/api/v1/license/validate", {
3158
- method: "POST",
3159
- headers: {
3160
- "Content-Type": "application/json",
3161
- // Add server-side headers to bypass CORS
3162
- "X-Server-Request": "true",
3163
- "X-Request-Domain": domain
3164
- },
3165
- body: JSON.stringify({
3166
- licenseKey,
3167
- domain
3168
- })
3169
- });
3170
- if (!response.ok) {
3171
- return {
3172
- valid: false,
3173
- hasProAccess: false,
3174
- error: `Validation failed: ${response.status}`
3175
- };
3176
- }
3177
- const data = await response.json();
3178
- return data;
3179
- } catch (error) {
3180
- console.error("[MoonUI Server Validate] Error:", error);
3181
- return {
3182
- valid: false,
3183
- hasProAccess: false,
3184
- error: error instanceof Error ? error.message : "Validation error"
3185
- };
3186
- }
3187
- }
3188
- function setAuthCookie(response, validationResult) {
3189
- if (validationResult.valid && validationResult.hasProAccess) {
3190
- const cookieData = {
3191
- valid: true,
3192
- hasProAccess: validationResult.hasProAccess,
3193
- timestamp: Date.now()
3194
- };
3195
- const maxAge = validationResult.cacheDuration || 86400;
3196
- if (typeof response.setHeader === "function") {
3197
- response.setHeader(
3198
- "Set-Cookie",
3199
- `moonui_pro_status=${encodeURIComponent(JSON.stringify(cookieData))}; Max-Age=${maxAge}; Path=/; SameSite=Strict; ${""}`
3200
- );
3201
- } else if (response.cookies && typeof response.cookies.set === "function") {
3202
- response.cookies.set("moonui_pro_status", JSON.stringify(cookieData), {
3203
- maxAge,
3204
- path: "/",
3205
- sameSite: "strict",
3206
- secure: false
3207
- });
3208
- }
3209
- }
3210
- }
3211
-
3212
3151
  // src/server.ts
3213
3152
  if (typeof window !== "undefined") {
3214
3153
  console.warn(
@@ -3216,4 +3155,4 @@ if (typeof window !== "undefined") {
3216
3155
  );
3217
3156
  }
3218
3157
 
3219
- export { AUTH_CONFIG, clearValidationCookies, decryptData, encryptData, generateServerDeviceFingerprint, getValidationFromCookies, performServerValidation, setAuthCookie, setValidationInCookies, validateLicense, validateWithMoonUIServer };
3158
+ export { AUTH_CONFIG, clearValidationCookies, decryptData, encryptData, generateServerDeviceFingerprint, getValidationFromCookies, performServerValidation, setValidationInCookies, validateWithMoonUIServer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moontra/moonui-pro",
3
- "version": "2.37.17",
3
+ "version": "2.37.18",
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",