@moontra/moonui-pro 3.4.3 → 3.4.5

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,30 @@
1
+ /**
2
+ * Next.js Config Plugin for MoonUI Pro
3
+ * Automatically resolves and injects license token at build time
4
+ *
5
+ * Usage in next.config.js:
6
+ *
7
+ * ```js
8
+ * const { withMoonUIProToken } = require('@moontra/moonui-pro/next-config');
9
+ *
10
+ * const nextConfig = {
11
+ * // your config
12
+ * };
13
+ *
14
+ * module.exports = withMoonUIProToken(nextConfig);
15
+ * ```
16
+ */
17
+ interface NextConfig {
18
+ env?: Record<string, string>;
19
+ [key: string]: any;
20
+ }
21
+ /**
22
+ * Next.js config wrapper that auto-resolves MoonUI Pro token
23
+ */
24
+ declare function withMoonUIProToken(nextConfig?: NextConfig): NextConfig;
25
+ /**
26
+ * Async version for webpack plugins (advanced usage)
27
+ */
28
+ declare function resolveTokenAsync(): Promise<string | null>;
29
+
30
+ export { withMoonUIProToken as default, resolveTokenAsync, withMoonUIProToken };
@@ -0,0 +1,202 @@
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/next-config-plugin.ts
153
+ function withMoonUIProToken(nextConfig = {}) {
154
+ console.log("[MoonUI Next.js Plugin] === INITIALIZING ===");
155
+ let token = resolveTokenSync();
156
+ if (token) {
157
+ console.log("[MoonUI Next.js Plugin] \u2713 Existing token found");
158
+ } else {
159
+ const licenseKey = getLicenseKeyFromEnv();
160
+ if (licenseKey) {
161
+ console.log("[MoonUI Next.js Plugin] License key found, will attempt runtime generation...");
162
+ console.log("[MoonUI Next.js Plugin] \u2139 Token will be generated on first use (runtime fallback)");
163
+ } else {
164
+ console.log("[MoonUI Next.js Plugin] No license key found in environment");
165
+ console.log("[MoonUI Next.js Plugin] Set MOONUI_LICENSE_KEY to enable Pro features");
166
+ }
167
+ }
168
+ const enhancedConfig = {
169
+ ...nextConfig,
170
+ env: {
171
+ ...nextConfig.env,
172
+ NEXT_PUBLIC_MOONUI_PRO_TOKEN: token || ""
173
+ }
174
+ };
175
+ if (token) {
176
+ console.log("[MoonUI Next.js Plugin] \u2713 Token injected into NEXT_PUBLIC_MOONUI_PRO_TOKEN");
177
+ } else {
178
+ console.log("[MoonUI Next.js Plugin] Running without Pro token (will use runtime fallback)");
179
+ }
180
+ console.log("[MoonUI Next.js Plugin] === INITIALIZATION COMPLETE ===");
181
+ return enhancedConfig;
182
+ }
183
+ async function resolveTokenAsync() {
184
+ const syncToken = resolveTokenSync();
185
+ if (syncToken) {
186
+ return syncToken;
187
+ }
188
+ const licenseKey = getLicenseKeyFromEnv();
189
+ if (!licenseKey) {
190
+ return null;
191
+ }
192
+ console.log("[MoonUI Next.js Plugin] Generating token asynchronously...");
193
+ const result = await generateTokenIfMissing({ silent: false });
194
+ if (result.success && result.token) {
195
+ const tokenString = JSON.stringify(result.token);
196
+ return Buffer.from(tokenString).toString("base64");
197
+ }
198
+ return null;
199
+ }
200
+ var next_config_plugin_default = withMoonUIProToken;
201
+
202
+ export { next_config_plugin_default as default, resolveTokenAsync, withMoonUIProToken };
package/dist/server.d.ts CHANGED
@@ -118,6 +118,7 @@ interface LicenseToken {
118
118
  declare function readLicenseTokenServer(): LicenseToken | null;
119
119
  /**
120
120
  * Read license token (server-side only)
121
+ * With runtime fallback if token not found
121
122
  */
122
123
  declare function readLicenseToken(): LicenseToken | null;
123
124
  /**
package/dist/server.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
1
3
  import * as crypto from 'crypto';
2
4
  import crypto__default from 'crypto';
3
5
 
@@ -20,9 +22,16 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
20
22
  return require.apply(this, arguments);
21
23
  throw new Error('Dynamic require of "' + x + '" is not supported');
22
24
  });
25
+ var __esm = (fn, res) => function __init() {
26
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
27
+ };
23
28
  var __commonJS = (cb, mod) => function __require2() {
24
29
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
25
30
  };
31
+ var __export = (target, all) => {
32
+ for (var name in all)
33
+ __defProp(target, name, { get: all[name], enumerable: true });
34
+ };
26
35
  var __copyProps = (to, from, except, desc) => {
27
36
  if (from && typeof from === "object" || typeof from === "function") {
28
37
  for (let key of __getOwnPropNames(from))
@@ -39,6 +48,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
39
48
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
40
49
  mod
41
50
  ));
51
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
42
52
 
43
53
  // ../../node_modules/next/dist/compiled/@edge-runtime/cookies/index.js
44
54
  var require_cookies = __commonJS({
@@ -47,7 +57,7 @@ var require_cookies = __commonJS({
47
57
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
48
58
  var __getOwnPropNames2 = Object.getOwnPropertyNames;
49
59
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
50
- var __export = (target, all) => {
60
+ var __export2 = (target, all) => {
51
61
  for (var name in all)
52
62
  __defProp2(target, name, { get: all[name], enumerable: true });
53
63
  };
@@ -59,16 +69,16 @@ var require_cookies = __commonJS({
59
69
  }
60
70
  return to;
61
71
  };
62
- var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
72
+ var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
63
73
  var src_exports = {};
64
- __export(src_exports, {
74
+ __export2(src_exports, {
65
75
  RequestCookies: () => RequestCookies,
66
76
  ResponseCookies: () => ResponseCookies,
67
77
  parseCookie: () => parseCookie,
68
78
  parseSetCookie: () => parseSetCookie,
69
79
  stringifyCookie: () => stringifyCookie
70
80
  });
71
- module.exports = __toCommonJS(src_exports);
81
+ module.exports = __toCommonJS2(src_exports);
72
82
  function stringifyCookie(c) {
73
83
  var _a;
74
84
  const attrs = [
@@ -113,7 +123,7 @@ var require_cookies = __commonJS({
113
123
  expires,
114
124
  httponly,
115
125
  maxage,
116
- path,
126
+ path: path2,
117
127
  samesite,
118
128
  secure,
119
129
  partitioned,
@@ -131,7 +141,7 @@ var require_cookies = __commonJS({
131
141
  ...expires && { expires: new Date(expires) },
132
142
  ...httponly && { httpOnly: true },
133
143
  ...typeof maxage === "string" && { maxAge: Number(maxage) },
134
- path,
144
+ path: path2,
135
145
  ...samesite && { sameSite: parseSameSite(samesite) },
136
146
  ...secure && { secure: true },
137
147
  ...priority && { priority: parsePriority(priority) },
@@ -2960,6 +2970,152 @@ var require_headers3 = __commonJS({
2960
2970
  }
2961
2971
  });
2962
2972
 
2973
+ // src/lib/license-token-generator.ts
2974
+ var license_token_generator_exports = {};
2975
+ __export(license_token_generator_exports, {
2976
+ generateTokenIfMissing: () => generateTokenIfMissing,
2977
+ getLicenseKeyFromEnv: () => getLicenseKeyFromEnv,
2978
+ resolveTokenSync: () => resolveTokenSync
2979
+ });
2980
+ function findExistingToken() {
2981
+ if (typeof window !== "undefined") {
2982
+ return null;
2983
+ }
2984
+ const possiblePaths = [
2985
+ path.join(process.cwd(), ".moonui-license-token"),
2986
+ path.join(process.cwd(), "..", ".moonui-license-token"),
2987
+ path.join(process.cwd(), "..", "..", ".moonui-license-token")
2988
+ ];
2989
+ if (process.env.VERCEL_ARTIFACTS_PATH) {
2990
+ possiblePaths.push(path.join(process.env.VERCEL_ARTIFACTS_PATH, ".moonui-license-token"));
2991
+ }
2992
+ if (process.env.NETLIFY_BUILD_BASE) {
2993
+ possiblePaths.push(path.join(process.env.NETLIFY_BUILD_BASE, ".moonui-license-token"));
2994
+ }
2995
+ possiblePaths.push("/tmp/.moonui-license-token");
2996
+ for (const filePath of possiblePaths) {
2997
+ if (fs.existsSync(filePath)) {
2998
+ try {
2999
+ return fs.readFileSync(filePath, "utf8");
3000
+ } catch (err) {
3001
+ console.error(`[MoonUI Token Generator] Failed to read token from ${filePath}:`, err);
3002
+ }
3003
+ }
3004
+ }
3005
+ return null;
3006
+ }
3007
+ async function generateTokenIfMissing(options = {}) {
3008
+ const { silent = false, forceRegenerate = false } = options;
3009
+ try {
3010
+ if (!forceRegenerate && process.env.MOONUI_PRO_TOKEN) {
3011
+ if (!silent) {
3012
+ console.log("[MoonUI Token Generator] Token found in environment variable");
3013
+ }
3014
+ return {
3015
+ success: true,
3016
+ token: JSON.parse(Buffer.from(process.env.MOONUI_PRO_TOKEN, "base64").toString("utf8")),
3017
+ cached: true
3018
+ };
3019
+ }
3020
+ if (!forceRegenerate) {
3021
+ const existingToken = findExistingToken();
3022
+ if (existingToken) {
3023
+ if (!silent) {
3024
+ console.log("[MoonUI Token Generator] Token file already exists");
3025
+ }
3026
+ return {
3027
+ success: true,
3028
+ token: JSON.parse(Buffer.from(existingToken, "base64").toString("utf8")),
3029
+ cached: true
3030
+ };
3031
+ }
3032
+ }
3033
+ 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;
3034
+ if (!licenseKey) {
3035
+ if (!silent) {
3036
+ console.log("[MoonUI Token Generator] No license key found in environment variables");
3037
+ }
3038
+ return {
3039
+ success: false,
3040
+ error: "No license key found"
3041
+ };
3042
+ }
3043
+ const postInstallPath = path.join(__dirname, "../../scripts/postinstall.cjs");
3044
+ if (!fs.existsSync(postInstallPath)) {
3045
+ if (!silent) {
3046
+ console.error("[MoonUI Token Generator] PostInstall script not found at:", postInstallPath);
3047
+ }
3048
+ return {
3049
+ success: false,
3050
+ error: "PostInstall script not found"
3051
+ };
3052
+ }
3053
+ const postInstall = __require(postInstallPath);
3054
+ if (!silent) {
3055
+ console.log("[MoonUI Token Generator] Validating license key and generating token...");
3056
+ }
3057
+ const result = await postInstall.validateAndCreateToken(licenseKey, { silent });
3058
+ if (result.success && result.token) {
3059
+ const saveSuccess = postInstall.saveLicenseToken(result.token);
3060
+ if (saveSuccess) {
3061
+ if (!silent) {
3062
+ console.log("[MoonUI Token Generator] \u2713 Token generated and saved successfully");
3063
+ }
3064
+ return {
3065
+ success: true,
3066
+ token: result.token
3067
+ };
3068
+ } else {
3069
+ if (!silent) {
3070
+ console.log("[MoonUI Token Generator] \u26A0 Token generated but failed to save");
3071
+ }
3072
+ return {
3073
+ success: false,
3074
+ error: "Failed to save token"
3075
+ };
3076
+ }
3077
+ } else {
3078
+ if (!silent) {
3079
+ console.log("[MoonUI Token Generator] \u2717 License validation failed:", result.error);
3080
+ }
3081
+ return {
3082
+ success: false,
3083
+ error: result.error || "License validation failed"
3084
+ };
3085
+ }
3086
+ } catch (error) {
3087
+ if (!silent) {
3088
+ console.error("[MoonUI Token Generator] Error:", error.message);
3089
+ }
3090
+ return {
3091
+ success: false,
3092
+ error: error.message
3093
+ };
3094
+ }
3095
+ }
3096
+ function resolveTokenSync() {
3097
+ try {
3098
+ if (process.env.MOONUI_PRO_TOKEN) {
3099
+ return process.env.MOONUI_PRO_TOKEN;
3100
+ }
3101
+ const existingToken = findExistingToken();
3102
+ if (existingToken) {
3103
+ return existingToken;
3104
+ }
3105
+ return null;
3106
+ } catch (error) {
3107
+ console.error("[MoonUI Token Generator] Error resolving token:", error);
3108
+ return null;
3109
+ }
3110
+ }
3111
+ function getLicenseKeyFromEnv() {
3112
+ 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;
3113
+ }
3114
+ var init_license_token_generator = __esm({
3115
+ "src/lib/license-token-generator.ts"() {
3116
+ }
3117
+ });
3118
+
2963
3119
  // src/lib/server-auth.ts
2964
3120
  var import_headers = __toESM(require_headers3(), 1);
2965
3121
 
@@ -3184,27 +3340,27 @@ function readLicenseTokenServer() {
3184
3340
  console.error("[MoonUI] Failed to parse MOONUI_PRO_TOKEN:", envError);
3185
3341
  }
3186
3342
  }
3187
- const fs = __require("fs");
3188
- const path = __require("path");
3343
+ const fs2 = __require("fs");
3344
+ const path2 = __require("path");
3189
3345
  const possiblePaths = [
3190
- path.join(process.cwd(), ".moonui-license"),
3191
- path.join(process.cwd(), "..", ".moonui-license"),
3192
- path.join(process.cwd(), "..", "..", ".moonui-license"),
3193
- path.join(__dirname, "..", "..", "..", "..", ".moonui-license")
3346
+ path2.join(process.cwd(), ".moonui-license"),
3347
+ path2.join(process.cwd(), "..", ".moonui-license"),
3348
+ path2.join(process.cwd(), "..", "..", ".moonui-license"),
3349
+ path2.join(__dirname, "..", "..", "..", "..", ".moonui-license")
3194
3350
  ];
3195
3351
  if (process.env.VERCEL_ARTIFACTS_PATH) {
3196
- possiblePaths.push(path.join(process.env.VERCEL_ARTIFACTS_PATH, ".moonui-license"));
3352
+ possiblePaths.push(path2.join(process.env.VERCEL_ARTIFACTS_PATH, ".moonui-license"));
3197
3353
  }
3198
3354
  if (process.env.NETLIFY_BUILD_BASE) {
3199
- possiblePaths.push(path.join(process.env.NETLIFY_BUILD_BASE, ".moonui-license"));
3355
+ possiblePaths.push(path2.join(process.env.NETLIFY_BUILD_BASE, ".moonui-license"));
3200
3356
  }
3201
3357
  possiblePaths.push("/tmp/.moonui-license");
3202
3358
  let encryptedData = null;
3203
3359
  let foundPath = null;
3204
3360
  for (const filePath of possiblePaths) {
3205
- if (fs.existsSync(filePath)) {
3361
+ if (fs2.existsSync(filePath)) {
3206
3362
  foundPath = filePath;
3207
- const fileContent = fs.readFileSync(filePath, "utf8");
3363
+ const fileContent = fs2.readFileSync(filePath, "utf8");
3208
3364
  encryptedData = JSON.parse(fileContent);
3209
3365
  break;
3210
3366
  }
@@ -3230,8 +3386,51 @@ function readLicenseTokenServer() {
3230
3386
  return null;
3231
3387
  }
3232
3388
  }
3389
+ async function generateTokenAtRuntime() {
3390
+ try {
3391
+ if (typeof window !== "undefined") {
3392
+ return null;
3393
+ }
3394
+ console.log("[MoonUI] Runtime fallback: Attempting to generate token...");
3395
+ const { generateTokenIfMissing: generateTokenIfMissing2 } = (init_license_token_generator(), __toCommonJS(license_token_generator_exports));
3396
+ const result = await generateTokenIfMissing2({ silent: false });
3397
+ if (result.success && result.token) {
3398
+ console.log("[MoonUI] \u2713 Token generated at runtime");
3399
+ return result.token;
3400
+ } else {
3401
+ console.log("[MoonUI] \u2717 Runtime token generation failed:", result.error);
3402
+ return null;
3403
+ }
3404
+ } catch (error) {
3405
+ console.error("[MoonUI] Runtime fallback error:", error.message);
3406
+ return null;
3407
+ }
3408
+ }
3409
+ var runtimeToken = void 0;
3410
+ var runtimeTokenAttempted = false;
3233
3411
  function readLicenseToken() {
3234
- return readLicenseTokenServer();
3412
+ const token = readLicenseTokenServer();
3413
+ if (token) {
3414
+ return token;
3415
+ }
3416
+ if (runtimeTokenAttempted) {
3417
+ return runtimeToken || null;
3418
+ }
3419
+ if (typeof window === "undefined") {
3420
+ console.log("[MoonUI] Token not found, scheduling runtime generation...");
3421
+ generateTokenAtRuntime().then((token2) => {
3422
+ runtimeToken = token2;
3423
+ runtimeTokenAttempted = true;
3424
+ if (token2) {
3425
+ console.log("[MoonUI] \u2713 Runtime token generation completed");
3426
+ }
3427
+ }).catch((error) => {
3428
+ console.error("[MoonUI] Runtime token generation failed:", error);
3429
+ runtimeTokenAttempted = true;
3430
+ runtimeToken = null;
3431
+ });
3432
+ }
3433
+ return null;
3235
3434
  }
3236
3435
  function hasProAccessFromToken() {
3237
3436
  const token = readLicenseToken();
@@ -0,0 +1,38 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ /**
4
+ * Vite Plugin for MoonUI Pro
5
+ * Automatically resolves and injects license token at build time
6
+ *
7
+ * Usage in vite.config.ts:
8
+ *
9
+ * ```ts
10
+ * import { moonUIProPlugin } from '@moontra/moonui-pro/vite';
11
+ * import { defineConfig } from 'vite';
12
+ *
13
+ * export default defineConfig({
14
+ * plugins: [
15
+ * moonUIProPlugin(),
16
+ * ],
17
+ * });
18
+ * ```
19
+ */
20
+
21
+ interface MoonUIProPluginOptions {
22
+ /**
23
+ * Suppress console logs
24
+ * @default false
25
+ */
26
+ silent?: boolean;
27
+ /**
28
+ * Force token regeneration even if exists
29
+ * @default false
30
+ */
31
+ forceRegenerate?: boolean;
32
+ }
33
+ /**
34
+ * Vite plugin for MoonUI Pro license token management
35
+ */
36
+ declare function moonUIProPlugin(options?: MoonUIProPluginOptions): Plugin;
37
+
38
+ export { moonUIProPlugin as default, moonUIProPlugin };
@@ -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.3",
3
+ "version": "3.4.5",
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
+ };