@moontra/moonui-pro 3.4.2 → 3.4.4

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.
@@ -0,0 +1,221 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+
4
+ /**
5
+ * @moontra/moonui-pro v2.0.9
6
+ * Premium UI components for MoonUI
7
+ * (c) 2025 MoonUI. All rights reserved.
8
+ * @license Commercial - https://moonui.dev/license
9
+ */
10
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
11
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
12
+ }) : x)(function(x) {
13
+ if (typeof require !== "undefined")
14
+ return require.apply(this, arguments);
15
+ throw new Error('Dynamic require of "' + x + '" is not supported');
16
+ });
17
+ function findExistingToken() {
18
+ if (typeof window !== "undefined") {
19
+ return null;
20
+ }
21
+ const possiblePaths = [
22
+ path.join(process.cwd(), ".moonui-license-token"),
23
+ path.join(process.cwd(), "..", ".moonui-license-token"),
24
+ path.join(process.cwd(), "..", "..", ".moonui-license-token")
25
+ ];
26
+ if (process.env.VERCEL_ARTIFACTS_PATH) {
27
+ possiblePaths.push(path.join(process.env.VERCEL_ARTIFACTS_PATH, ".moonui-license-token"));
28
+ }
29
+ if (process.env.NETLIFY_BUILD_BASE) {
30
+ possiblePaths.push(path.join(process.env.NETLIFY_BUILD_BASE, ".moonui-license-token"));
31
+ }
32
+ possiblePaths.push("/tmp/.moonui-license-token");
33
+ for (const filePath of possiblePaths) {
34
+ if (fs.existsSync(filePath)) {
35
+ try {
36
+ return fs.readFileSync(filePath, "utf8");
37
+ } catch (err) {
38
+ console.error(`[MoonUI Token Generator] Failed to read token from ${filePath}:`, err);
39
+ }
40
+ }
41
+ }
42
+ return null;
43
+ }
44
+ async function generateTokenIfMissing(options = {}) {
45
+ const { silent = false, forceRegenerate = false } = options;
46
+ try {
47
+ if (!forceRegenerate && process.env.MOONUI_PRO_TOKEN) {
48
+ if (!silent) {
49
+ console.log("[MoonUI Token Generator] Token found in environment variable");
50
+ }
51
+ return {
52
+ success: true,
53
+ token: JSON.parse(Buffer.from(process.env.MOONUI_PRO_TOKEN, "base64").toString("utf8")),
54
+ cached: true
55
+ };
56
+ }
57
+ if (!forceRegenerate) {
58
+ const existingToken = findExistingToken();
59
+ if (existingToken) {
60
+ if (!silent) {
61
+ console.log("[MoonUI Token Generator] Token file already exists");
62
+ }
63
+ return {
64
+ success: true,
65
+ token: JSON.parse(Buffer.from(existingToken, "base64").toString("utf8")),
66
+ cached: true
67
+ };
68
+ }
69
+ }
70
+ const licenseKey = process.env.MOONUI_LICENSE_KEY || process.env.NEXT_PUBLIC_MOONUI_LICENSE_KEY || process.env.VITE_MOONUI_LICENSE_KEY || process.env.REACT_APP_MOONUI_LICENSE_KEY;
71
+ if (!licenseKey) {
72
+ if (!silent) {
73
+ console.log("[MoonUI Token Generator] No license key found in environment variables");
74
+ }
75
+ return {
76
+ success: false,
77
+ error: "No license key found"
78
+ };
79
+ }
80
+ const postInstallPath = path.join(__dirname, "../../scripts/postinstall.cjs");
81
+ if (!fs.existsSync(postInstallPath)) {
82
+ if (!silent) {
83
+ console.error("[MoonUI Token Generator] PostInstall script not found at:", postInstallPath);
84
+ }
85
+ return {
86
+ success: false,
87
+ error: "PostInstall script not found"
88
+ };
89
+ }
90
+ const postInstall = __require(postInstallPath);
91
+ if (!silent) {
92
+ console.log("[MoonUI Token Generator] Validating license key and generating token...");
93
+ }
94
+ const result = await postInstall.validateAndCreateToken(licenseKey, { silent });
95
+ if (result.success && result.token) {
96
+ const saveSuccess = postInstall.saveLicenseToken(result.token);
97
+ if (saveSuccess) {
98
+ if (!silent) {
99
+ console.log("[MoonUI Token Generator] \u2713 Token generated and saved successfully");
100
+ }
101
+ return {
102
+ success: true,
103
+ token: result.token
104
+ };
105
+ } else {
106
+ if (!silent) {
107
+ console.log("[MoonUI Token Generator] \u26A0 Token generated but failed to save");
108
+ }
109
+ return {
110
+ success: false,
111
+ error: "Failed to save token"
112
+ };
113
+ }
114
+ } else {
115
+ if (!silent) {
116
+ console.log("[MoonUI Token Generator] \u2717 License validation failed:", result.error);
117
+ }
118
+ return {
119
+ success: false,
120
+ error: result.error || "License validation failed"
121
+ };
122
+ }
123
+ } catch (error) {
124
+ if (!silent) {
125
+ console.error("[MoonUI Token Generator] Error:", error.message);
126
+ }
127
+ return {
128
+ success: false,
129
+ error: error.message
130
+ };
131
+ }
132
+ }
133
+ function resolveTokenSync() {
134
+ try {
135
+ if (process.env.MOONUI_PRO_TOKEN) {
136
+ return process.env.MOONUI_PRO_TOKEN;
137
+ }
138
+ const existingToken = findExistingToken();
139
+ if (existingToken) {
140
+ return existingToken;
141
+ }
142
+ return null;
143
+ } catch (error) {
144
+ console.error("[MoonUI Token Generator] Error resolving token:", error);
145
+ return null;
146
+ }
147
+ }
148
+ function getLicenseKeyFromEnv() {
149
+ return process.env.MOONUI_LICENSE_KEY || process.env.NEXT_PUBLIC_MOONUI_LICENSE_KEY || process.env.VITE_MOONUI_LICENSE_KEY || process.env.REACT_APP_MOONUI_LICENSE_KEY || null;
150
+ }
151
+
152
+ // src/vite-plugin.ts
153
+ function moonUIProPlugin(options = {}) {
154
+ const { silent = false, forceRegenerate = false } = options;
155
+ let token = null;
156
+ let tokenResolved = false;
157
+ return {
158
+ name: "moonui-pro-license",
159
+ enforce: "pre",
160
+ async buildStart() {
161
+ if (tokenResolved && !forceRegenerate) {
162
+ return;
163
+ }
164
+ if (!silent) {
165
+ console.log("[MoonUI Vite Plugin] === INITIALIZING ===");
166
+ }
167
+ token = resolveTokenSync();
168
+ if (token) {
169
+ if (!silent) {
170
+ console.log("[MoonUI Vite Plugin] \u2713 Existing token found");
171
+ }
172
+ tokenResolved = true;
173
+ return;
174
+ }
175
+ const licenseKey = getLicenseKeyFromEnv();
176
+ if (licenseKey) {
177
+ if (!silent) {
178
+ console.log("[MoonUI Vite Plugin] License key found, generating token...");
179
+ }
180
+ const result = await generateTokenIfMissing({ silent, forceRegenerate });
181
+ if (result.success && result.token) {
182
+ const tokenString = JSON.stringify(result.token);
183
+ token = Buffer.from(tokenString).toString("base64");
184
+ if (!silent) {
185
+ console.log("[MoonUI Vite Plugin] \u2713 Token generated successfully");
186
+ }
187
+ } else {
188
+ if (!silent) {
189
+ console.log("[MoonUI Vite Plugin] \u26A0 Token generation failed:", result.error);
190
+ }
191
+ }
192
+ } else {
193
+ if (!silent) {
194
+ console.log("[MoonUI Vite Plugin] No license key found in environment");
195
+ console.log("[MoonUI Vite Plugin] Set MOONUI_LICENSE_KEY to enable Pro features");
196
+ }
197
+ }
198
+ tokenResolved = true;
199
+ if (!silent) {
200
+ if (token) {
201
+ console.log("[MoonUI Vite Plugin] \u2713 Token will be injected into environment");
202
+ } else {
203
+ console.log("[MoonUI Vite Plugin] Running without Pro features");
204
+ }
205
+ console.log("[MoonUI Vite Plugin] === INITIALIZATION COMPLETE ===");
206
+ }
207
+ },
208
+ config(config) {
209
+ return {
210
+ define: {
211
+ ...config.define,
212
+ "import.meta.env.VITE_MOONUI_PRO_TOKEN": JSON.stringify(token || ""),
213
+ "process.env.VITE_MOONUI_PRO_TOKEN": JSON.stringify(token || "")
214
+ }
215
+ };
216
+ }
217
+ };
218
+ }
219
+ var vite_plugin_default = moonUIProPlugin;
220
+
221
+ export { vite_plugin_default as default, moonUIProPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moontra/moonui-pro",
3
- "version": "3.4.2",
3
+ "version": "3.4.4",
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",
@@ -39,6 +39,21 @@
39
39
  "types": "./plugin/index.d.ts",
40
40
  "import": "./plugin/index.js",
41
41
  "require": "./plugin/index.js"
42
+ },
43
+ "./next-config": {
44
+ "types": "./dist/next-config-plugin.d.ts",
45
+ "import": "./dist/next-config-plugin.mjs",
46
+ "require": "./dist/next-config-plugin.mjs",
47
+ "default": "./dist/next-config-plugin.mjs"
48
+ },
49
+ "./vite": {
50
+ "types": "./dist/vite-plugin.d.ts",
51
+ "import": "./dist/vite-plugin.mjs",
52
+ "require": "./dist/vite-plugin.mjs",
53
+ "default": "./dist/vite-plugin.mjs"
54
+ },
55
+ "./scripts/postinstall": {
56
+ "require": "./scripts/postinstall.cjs"
42
57
  }
43
58
  },
44
59
  "scripts": {
@@ -259,6 +259,64 @@ function saveLicenseToken(token) {
259
259
  }
260
260
  }
261
261
 
262
+ /**
263
+ * Validates license key and creates token if valid
264
+ * @param {string} licenseKey - The license key to validate
265
+ * @param {object} options - Optional configuration
266
+ * @param {boolean} options.silent - Suppress console logs
267
+ * @returns {Promise<{success: boolean, token?: object, error?: string}>}
268
+ */
269
+ async function validateAndCreateToken(licenseKey, options = {}) {
270
+ const silent = options.silent || false;
271
+
272
+ try {
273
+ if (!silent) {
274
+ console.log('[MoonUI Pro] Validating license key...');
275
+ }
276
+
277
+ // Validate license with API
278
+ const validationResult = await validateLicense(licenseKey);
279
+
280
+ if (!silent) {
281
+ console.log('[MoonUI Pro] Validation result:', JSON.stringify(validationResult, null, 2));
282
+ }
283
+
284
+ if (validationResult && validationResult.valid && validationResult.hasProAccess) {
285
+ if (!silent) {
286
+ console.log('[MoonUI Pro] ✓ License is valid and has Pro access');
287
+ }
288
+
289
+ // Create token with validation result and expiry
290
+ const token = {
291
+ valid: true,
292
+ hasProAccess: validationResult.hasProAccess,
293
+ plan: validationResult.plan || 'pro',
294
+ expiresAt: Date.now() + CACHE_DURATION,
295
+ timestamp: Date.now()
296
+ };
297
+
298
+ if (!silent) {
299
+ console.log('[MoonUI Pro] Creating token:', JSON.stringify(token, null, 2));
300
+ }
301
+
302
+ return {
303
+ success: true,
304
+ token
305
+ };
306
+ } else {
307
+ return {
308
+ success: false,
309
+ error: 'License validation failed or no Pro access'
310
+ };
311
+ }
312
+ } catch (error) {
313
+ return {
314
+ success: false,
315
+ error: error.message
316
+ };
317
+ }
318
+ }
319
+
262
320
  // Main postinstall logic
263
321
  async function main() {
264
322
  console.log('[MoonUI Pro] === POSTINSTALL SCRIPT STARTED ===');
@@ -283,9 +341,6 @@ async function main() {
283
341
 
284
342
  console.log('[MoonUI Pro] Production environment detected, checking license...');
285
343
 
286
- // Remove the bypass - moonui.dev should also use license key like everyone else
287
- // This prevents security vulnerability where users can set VERCEL_URL=moonui.dev
288
-
289
344
  // Check for license key in environment variables
290
345
  const licenseKey = process.env.MOONUI_LICENSE_KEY ||
291
346
  process.env.NEXT_PUBLIC_MOONUI_LICENSE_KEY ||
@@ -298,30 +353,12 @@ async function main() {
298
353
  return;
299
354
  }
300
355
 
301
- console.log('[MoonUI Pro] Validating license key...');
302
-
303
- // Validate license with API
304
- const validationResult = await validateLicense(licenseKey);
305
-
306
- // Debug: Log the full validation result
307
- console.log('[MoonUI Pro] Validation result:', JSON.stringify(validationResult, null, 2));
308
-
309
- if (validationResult && validationResult.valid && validationResult.hasProAccess) {
310
- console.log('[MoonUI Pro] ✓ License is valid and has Pro access');
311
-
312
- // Create token with validation result and expiry
313
- const token = {
314
- valid: true,
315
- hasProAccess: validationResult.hasProAccess,
316
- plan: validationResult.plan || 'pro',
317
- expiresAt: Date.now() + CACHE_DURATION,
318
- timestamp: Date.now()
319
- };
320
-
321
- console.log('[MoonUI Pro] Creating token:', JSON.stringify(token, null, 2));
356
+ // Use the new validateAndCreateToken function
357
+ const result = await validateAndCreateToken(licenseKey);
322
358
 
359
+ if (result.success && result.token) {
323
360
  // Save encrypted token
324
- const saveResult = saveLicenseToken(token);
361
+ const saveResult = saveLicenseToken(result.token);
325
362
 
326
363
  if (saveResult) {
327
364
  console.log('[MoonUI Pro] ✓ License validated successfully');
@@ -331,11 +368,7 @@ async function main() {
331
368
  }
332
369
  } else {
333
370
  console.log('[MoonUI Pro] License validation failed or no Pro access');
334
- console.log('[MoonUI Pro] Validation result:', {
335
- valid: validationResult?.valid || false,
336
- hasProAccess: validationResult?.hasProAccess || false,
337
- plan: validationResult?.plan || 'none'
338
- });
371
+ console.log('[MoonUI Pro] Error:', result.error);
339
372
  console.log('[MoonUI Pro] Pro features will be disabled');
340
373
  }
341
374
  } catch (error) {
@@ -365,4 +398,9 @@ if (require.main === module) {
365
398
  console.log('[MoonUI Pro] PostInstall script loaded as module');
366
399
  }
367
400
 
368
- module.exports = { validateLicense, saveLicenseToken, isProduction };
401
+ module.exports = {
402
+ validateLicense,
403
+ saveLicenseToken,
404
+ validateAndCreateToken,
405
+ isProduction
406
+ };