@revealui/setup 0.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/LICENSE +22 -0
- package/README.md +306 -0
- package/dist/environment/index.d.ts +95 -0
- package/dist/environment/index.js +462 -0
- package/dist/environment/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +473 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/index.d.ts +48 -0
- package/dist/utils/index.js +134 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/validators/index.d.ts +68 -0
- package/dist/validators/index.js +136 -0
- package/dist/validators/index.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// src/utils/logger.ts
|
|
2
|
+
var LOG_LEVELS = {
|
|
3
|
+
debug: 0,
|
|
4
|
+
info: 1,
|
|
5
|
+
warn: 2,
|
|
6
|
+
error: 3,
|
|
7
|
+
silent: 4
|
|
8
|
+
};
|
|
9
|
+
function getColors(enabled) {
|
|
10
|
+
if (!enabled) {
|
|
11
|
+
return {
|
|
12
|
+
reset: "",
|
|
13
|
+
red: "",
|
|
14
|
+
green: "",
|
|
15
|
+
yellow: "",
|
|
16
|
+
blue: "",
|
|
17
|
+
cyan: "",
|
|
18
|
+
magenta: "",
|
|
19
|
+
dim: "",
|
|
20
|
+
bold: ""
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
reset: "\x1B[0m",
|
|
25
|
+
red: "\x1B[31m",
|
|
26
|
+
green: "\x1B[32m",
|
|
27
|
+
yellow: "\x1B[33m",
|
|
28
|
+
blue: "\x1B[34m",
|
|
29
|
+
cyan: "\x1B[36m",
|
|
30
|
+
magenta: "\x1B[35m",
|
|
31
|
+
dim: "\x1B[2m",
|
|
32
|
+
bold: "\x1B[1m"
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function createLogger(options = {}) {
|
|
36
|
+
const {
|
|
37
|
+
level = process.env.LOG_LEVEL || "info",
|
|
38
|
+
prefix = "",
|
|
39
|
+
colors = process.env.FORCE_COLOR !== "0" && process.stdout.isTTY !== false,
|
|
40
|
+
timestamps = false
|
|
41
|
+
} = options;
|
|
42
|
+
const currentLevel = LOG_LEVELS[level] ?? LOG_LEVELS.info;
|
|
43
|
+
const c = getColors(colors);
|
|
44
|
+
function shouldLog(msgLevel) {
|
|
45
|
+
return LOG_LEVELS[msgLevel] >= currentLevel;
|
|
46
|
+
}
|
|
47
|
+
function formatPrefix() {
|
|
48
|
+
const parts = [];
|
|
49
|
+
if (timestamps) {
|
|
50
|
+
parts.push(`${c.dim}[${(/* @__PURE__ */ new Date()).toISOString()}]${c.reset}`);
|
|
51
|
+
}
|
|
52
|
+
if (prefix) {
|
|
53
|
+
parts.push(`${c.cyan}[${prefix}]${c.reset}`);
|
|
54
|
+
}
|
|
55
|
+
return parts.length > 0 ? `${parts.join(" ")} ` : "";
|
|
56
|
+
}
|
|
57
|
+
function formatArgs(args) {
|
|
58
|
+
if (args.length === 0) return "";
|
|
59
|
+
return " " + args.map((arg) => typeof arg === "object" ? JSON.stringify(arg) : String(arg)).join(" ");
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
debug(msg, ...args) {
|
|
63
|
+
if (!shouldLog("debug")) return;
|
|
64
|
+
console.log(`${formatPrefix()}${c.dim}[DEBUG]${c.reset} ${msg}${formatArgs(args)}`);
|
|
65
|
+
},
|
|
66
|
+
info(msg, ...args) {
|
|
67
|
+
if (!shouldLog("info")) return;
|
|
68
|
+
console.log(`${formatPrefix()}${c.blue}[INFO]${c.reset} ${msg}${formatArgs(args)}`);
|
|
69
|
+
},
|
|
70
|
+
warn(msg, ...args) {
|
|
71
|
+
if (!shouldLog("warn")) return;
|
|
72
|
+
console.warn(`${formatPrefix()}${c.yellow}[WARN]${c.reset} ${msg}${formatArgs(args)}`);
|
|
73
|
+
},
|
|
74
|
+
error(msg, ...args) {
|
|
75
|
+
if (!shouldLog("error")) return;
|
|
76
|
+
console.error(`${formatPrefix()}${c.red}[ERROR]${c.reset} ${msg}${formatArgs(args)}`);
|
|
77
|
+
},
|
|
78
|
+
success(msg, ...args) {
|
|
79
|
+
if (!shouldLog("info")) return;
|
|
80
|
+
console.log(`${formatPrefix()}${c.green}[OK]${c.reset} ${msg}${formatArgs(args)}`);
|
|
81
|
+
},
|
|
82
|
+
warning(msg, ...args) {
|
|
83
|
+
this.warn(msg, ...args);
|
|
84
|
+
},
|
|
85
|
+
header(msg) {
|
|
86
|
+
if (!shouldLog("info")) return;
|
|
87
|
+
const line = "=".repeat(msg.length + 4);
|
|
88
|
+
console.log(`
|
|
89
|
+
${c.cyan}${line}`);
|
|
90
|
+
console.log(`| ${msg} |`);
|
|
91
|
+
console.log(`${line}${c.reset}
|
|
92
|
+
`);
|
|
93
|
+
},
|
|
94
|
+
divider() {
|
|
95
|
+
if (!shouldLog("info")) return;
|
|
96
|
+
console.log(`${c.dim}${"\u2500".repeat(60)}${c.reset}`);
|
|
97
|
+
},
|
|
98
|
+
table(data) {
|
|
99
|
+
if (!shouldLog("info")) return;
|
|
100
|
+
console.table(data);
|
|
101
|
+
},
|
|
102
|
+
group(label) {
|
|
103
|
+
if (!shouldLog("info")) return;
|
|
104
|
+
console.group(`${c.bold}${label}${c.reset}`);
|
|
105
|
+
},
|
|
106
|
+
groupEnd() {
|
|
107
|
+
if (!shouldLog("info")) return;
|
|
108
|
+
console.groupEnd();
|
|
109
|
+
},
|
|
110
|
+
progress(current, total, label = "") {
|
|
111
|
+
if (!shouldLog("info")) return;
|
|
112
|
+
const percent = Math.round(current / total * 100);
|
|
113
|
+
const filled = Math.round(percent / 5);
|
|
114
|
+
const empty = 20 - filled;
|
|
115
|
+
const bar = `${"\u2588".repeat(filled)}${"\u2591".repeat(empty)}`;
|
|
116
|
+
const labelText = label ? ` ${label}` : "";
|
|
117
|
+
process.stdout.write(`\r${c.cyan}${bar}${c.reset} ${percent}%${labelText}`);
|
|
118
|
+
if (current === total) {
|
|
119
|
+
console.log();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function handleASTParseError(filePath, error, logger2) {
|
|
125
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
126
|
+
logger2.warning(`AST Parse Error in ${filePath}: ${message}`);
|
|
127
|
+
}
|
|
128
|
+
var logger = createLogger();
|
|
129
|
+
export {
|
|
130
|
+
createLogger,
|
|
131
|
+
handleASTParseError,
|
|
132
|
+
logger
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/logger.ts"],"sourcesContent":["/**\n * Unified Logger for RevealUI Scripts\n *\n * Provides consistent logging across all scripts with color support,\n * structured output, and log level filtering.\n */\n\nexport type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent'\n\nexport interface LoggerOptions {\n level?: LogLevel\n prefix?: string\n colors?: boolean\n timestamps?: boolean\n}\n\nconst LOG_LEVELS: Record<LogLevel, number> = {\n debug: 0,\n info: 1,\n warn: 2,\n error: 3,\n silent: 4,\n}\n\ninterface ColorMap {\n reset: string\n red: string\n green: string\n yellow: string\n blue: string\n cyan: string\n magenta: string\n dim: string\n bold: string\n}\n\nfunction getColors(enabled: boolean): ColorMap {\n if (!enabled) {\n return {\n reset: '',\n red: '',\n green: '',\n yellow: '',\n blue: '',\n cyan: '',\n magenta: '',\n dim: '',\n bold: '',\n }\n }\n return {\n reset: '\\x1b[0m',\n red: '\\x1b[31m',\n green: '\\x1b[32m',\n yellow: '\\x1b[33m',\n blue: '\\x1b[34m',\n cyan: '\\x1b[36m',\n magenta: '\\x1b[35m',\n dim: '\\x1b[2m',\n bold: '\\x1b[1m',\n }\n}\n\nexport interface Logger {\n debug: (msg: string, ...args: unknown[]) => void\n info: (msg: string, ...args: unknown[]) => void\n warn: (msg: string, ...args: unknown[]) => void\n error: (msg: string, ...args: unknown[]) => void\n success: (msg: string, ...args: unknown[]) => void\n warning: (msg: string, ...args: unknown[]) => void\n header: (msg: string) => void\n divider: () => void\n table: (data: Record<string, unknown>[]) => void\n group: (label: string) => void\n groupEnd: () => void\n progress: (current: number, total: number, label?: string) => void\n}\n\n/**\n * Creates a logger instance with configurable options.\n *\n * @example\n * ```typescript\n * const logger = createLogger({ level: 'info', prefix: 'MyScript' })\n * logger.info('Starting process')\n * logger.success('Completed!')\n * ```\n */\nexport function createLogger(options: LoggerOptions = {}): Logger {\n const {\n level = (process.env.LOG_LEVEL as LogLevel) || 'info',\n prefix = '',\n colors = process.env.FORCE_COLOR !== '0' && process.stdout.isTTY !== false,\n timestamps = false,\n } = options\n\n const currentLevel = LOG_LEVELS[level] ?? LOG_LEVELS.info\n const c = getColors(colors)\n\n function shouldLog(msgLevel: LogLevel): boolean {\n return LOG_LEVELS[msgLevel] >= currentLevel\n }\n\n function formatPrefix(): string {\n const parts: string[] = []\n if (timestamps) {\n parts.push(`${c.dim}[${new Date().toISOString()}]${c.reset}`)\n }\n if (prefix) {\n parts.push(`${c.cyan}[${prefix}]${c.reset}`)\n }\n return parts.length > 0 ? `${parts.join(' ')} ` : ''\n }\n\n function formatArgs(args: unknown[]): string {\n if (args.length === 0) return ''\n return (\n ' ' +\n args.map((arg) => (typeof arg === 'object' ? JSON.stringify(arg) : String(arg))).join(' ')\n )\n }\n\n return {\n debug(msg: string, ...args: unknown[]) {\n if (!shouldLog('debug')) return\n console.log(`${formatPrefix()}${c.dim}[DEBUG]${c.reset} ${msg}${formatArgs(args)}`)\n },\n\n info(msg: string, ...args: unknown[]) {\n if (!shouldLog('info')) return\n console.log(`${formatPrefix()}${c.blue}[INFO]${c.reset} ${msg}${formatArgs(args)}`)\n },\n\n warn(msg: string, ...args: unknown[]) {\n if (!shouldLog('warn')) return\n console.warn(`${formatPrefix()}${c.yellow}[WARN]${c.reset} ${msg}${formatArgs(args)}`)\n },\n\n error(msg: string, ...args: unknown[]) {\n if (!shouldLog('error')) return\n console.error(`${formatPrefix()}${c.red}[ERROR]${c.reset} ${msg}${formatArgs(args)}`)\n },\n\n success(msg: string, ...args: unknown[]) {\n if (!shouldLog('info')) return\n console.log(`${formatPrefix()}${c.green}[OK]${c.reset} ${msg}${formatArgs(args)}`)\n },\n\n warning(msg: string, ...args: unknown[]) {\n this.warn(msg, ...args)\n },\n\n header(msg: string) {\n if (!shouldLog('info')) return\n const line = '='.repeat(msg.length + 4)\n console.log(`\\n${c.cyan}${line}`)\n console.log(`| ${msg} |`)\n console.log(`${line}${c.reset}\\n`)\n },\n\n divider() {\n if (!shouldLog('info')) return\n console.log(`${c.dim}${'─'.repeat(60)}${c.reset}`)\n },\n\n table(data: Record<string, unknown>[]) {\n if (!shouldLog('info')) return\n console.table(data)\n },\n\n group(label: string) {\n if (!shouldLog('info')) return\n console.group(`${c.bold}${label}${c.reset}`)\n },\n\n groupEnd() {\n if (!shouldLog('info')) return\n console.groupEnd()\n },\n\n progress(current: number, total: number, label = '') {\n if (!shouldLog('info')) return\n const percent = Math.round((current / total) * 100)\n const filled = Math.round(percent / 5)\n const empty = 20 - filled\n const bar = `${'█'.repeat(filled)}${'░'.repeat(empty)}`\n const labelText = label ? ` ${label}` : ''\n process.stdout.write(`\\r${c.cyan}${bar}${c.reset} ${percent}%${labelText}`)\n if (current === total) {\n console.log() // New line when complete\n }\n },\n }\n}\n\n/**\n * Standardized error handler for AST parsing errors\n */\nexport function handleASTParseError(filePath: string, error: unknown, logger: Logger): void {\n const message = error instanceof Error ? error.message : String(error)\n logger.warning(`AST Parse Error in ${filePath}: ${message}`)\n}\n\n/**\n * Default logger instance for quick usage\n */\nexport const logger = createLogger()\n"],"mappings":";AAgBA,IAAM,aAAuC;AAAA,EAC3C,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AACV;AAcA,SAAS,UAAU,SAA4B;AAC7C,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,MACL,OAAO;AA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AAO,QAAQ,sBAAsB,QAAQ,KAAK,OAAO,EAAE;AAC7D;AAKO,IAAM,SAAS,aAAa;","names":["logger"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment variable validation
|
|
3
|
+
*/
|
|
4
|
+
interface EnvVariable {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
required: boolean;
|
|
8
|
+
validator?: (value: string) => boolean;
|
|
9
|
+
}
|
|
10
|
+
interface ValidationResult {
|
|
11
|
+
valid: boolean;
|
|
12
|
+
missing: string[];
|
|
13
|
+
invalid: string[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Validates environment variables against required schema.
|
|
17
|
+
*
|
|
18
|
+
* @param required - Array of required environment variable definitions
|
|
19
|
+
* @param env - Environment variable object to validate
|
|
20
|
+
* @returns Validation result
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const result = validateEnv([
|
|
25
|
+
* { name: 'DB_URL', description: 'Database URL', required: true }
|
|
26
|
+
* ], process.env)
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function validateEnv(required: EnvVariable[], env: Record<string, string | undefined>): ValidationResult;
|
|
30
|
+
/**
|
|
31
|
+
* Common environment variable validators
|
|
32
|
+
*/
|
|
33
|
+
declare const validators: {
|
|
34
|
+
/**
|
|
35
|
+
* Validates PostgreSQL connection string format
|
|
36
|
+
*/
|
|
37
|
+
postgresUrl: (value: string) => boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Validates Stripe secret key format
|
|
40
|
+
*/
|
|
41
|
+
stripeSecretKey: (value: string) => boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Validates Stripe publishable key format
|
|
44
|
+
*/
|
|
45
|
+
stripePublishableKey: (value: string) => boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Validates URL format
|
|
48
|
+
*/
|
|
49
|
+
url: (value: string) => boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Validates minimum length
|
|
52
|
+
*/
|
|
53
|
+
minLength: (min: number) => (value: string) => boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Validates email format
|
|
56
|
+
*/
|
|
57
|
+
email: (value: string) => boolean;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Common required environment variables for RevealUI
|
|
61
|
+
*/
|
|
62
|
+
declare const REQUIRED_ENV_VARS: EnvVariable[];
|
|
63
|
+
/**
|
|
64
|
+
* Optional environment variables
|
|
65
|
+
*/
|
|
66
|
+
declare const OPTIONAL_ENV_VARS: EnvVariable[];
|
|
67
|
+
|
|
68
|
+
export { type EnvVariable, OPTIONAL_ENV_VARS, REQUIRED_ENV_VARS, type ValidationResult, validateEnv, validators };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// src/validators/env.ts
|
|
2
|
+
function validateEnv(required, env) {
|
|
3
|
+
const missing = [];
|
|
4
|
+
const invalid = [];
|
|
5
|
+
for (const variable of required) {
|
|
6
|
+
const value = env[variable.name];
|
|
7
|
+
if (variable.required && (!value || value.trim() === "")) {
|
|
8
|
+
missing.push(variable.name);
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
if (value && variable.validator && !variable.validator(value)) {
|
|
12
|
+
invalid.push(variable.name);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
valid: missing.length === 0 && invalid.length === 0,
|
|
17
|
+
missing,
|
|
18
|
+
invalid
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
var validators = {
|
|
22
|
+
/**
|
|
23
|
+
* Validates PostgreSQL connection string format
|
|
24
|
+
*/
|
|
25
|
+
postgresUrl: (value) => {
|
|
26
|
+
try {
|
|
27
|
+
const url = new URL(value);
|
|
28
|
+
return url.protocol === "postgresql:" || url.protocol === "postgres:";
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
/**
|
|
34
|
+
* Validates Stripe secret key format
|
|
35
|
+
*/
|
|
36
|
+
stripeSecretKey: (value) => {
|
|
37
|
+
return value.startsWith("sk_test_") || value.startsWith("sk_live_");
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* Validates Stripe publishable key format
|
|
41
|
+
*/
|
|
42
|
+
stripePublishableKey: (value) => {
|
|
43
|
+
return value.startsWith("pk_test_") || value.startsWith("pk_live_");
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* Validates URL format
|
|
47
|
+
*/
|
|
48
|
+
url: (value) => {
|
|
49
|
+
try {
|
|
50
|
+
new URL(value);
|
|
51
|
+
return true;
|
|
52
|
+
} catch {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* Validates minimum length
|
|
58
|
+
*/
|
|
59
|
+
minLength: (min) => (value) => {
|
|
60
|
+
return value.length >= min;
|
|
61
|
+
},
|
|
62
|
+
/**
|
|
63
|
+
* Validates email format
|
|
64
|
+
*/
|
|
65
|
+
email: (value) => {
|
|
66
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
var REQUIRED_ENV_VARS = [
|
|
70
|
+
{
|
|
71
|
+
name: "REVEALUI_SECRET",
|
|
72
|
+
description: "Secret key for JWT tokens and session encryption (min 32 chars)",
|
|
73
|
+
required: true,
|
|
74
|
+
validator: validators.minLength(32)
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: "POSTGRES_URL",
|
|
78
|
+
description: "PostgreSQL connection string",
|
|
79
|
+
required: true,
|
|
80
|
+
validator: validators.postgresUrl
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: "BLOB_READ_WRITE_TOKEN",
|
|
84
|
+
description: "Vercel Blob storage token",
|
|
85
|
+
required: true
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "STRIPE_SECRET_KEY",
|
|
89
|
+
description: "Stripe secret key (sk_test_... or sk_live_...)",
|
|
90
|
+
required: true,
|
|
91
|
+
validator: validators.stripeSecretKey
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: "NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY",
|
|
95
|
+
description: "Stripe publishable key (pk_test_... or pk_live_...)",
|
|
96
|
+
required: true,
|
|
97
|
+
validator: validators.stripePublishableKey
|
|
98
|
+
}
|
|
99
|
+
];
|
|
100
|
+
var OPTIONAL_ENV_VARS = [
|
|
101
|
+
{
|
|
102
|
+
name: "STRIPE_WEBHOOK_SECRET",
|
|
103
|
+
description: "Stripe webhook secret (whsec_...)",
|
|
104
|
+
required: false
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: "NEXT_PUBLIC_SUPABASE_URL",
|
|
108
|
+
description: "Supabase project URL",
|
|
109
|
+
required: false,
|
|
110
|
+
validator: validators.url
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: "NEXT_PUBLIC_SUPABASE_ANON_KEY",
|
|
114
|
+
description: "Supabase anonymous key",
|
|
115
|
+
required: false
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: "REVEALUI_ADMIN_EMAIL",
|
|
119
|
+
description: "Initial admin email",
|
|
120
|
+
required: false,
|
|
121
|
+
validator: validators.email
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: "REVEALUI_ADMIN_PASSWORD",
|
|
125
|
+
description: "Initial admin password (min 12 chars)",
|
|
126
|
+
required: false,
|
|
127
|
+
validator: validators.minLength(12)
|
|
128
|
+
}
|
|
129
|
+
];
|
|
130
|
+
export {
|
|
131
|
+
OPTIONAL_ENV_VARS,
|
|
132
|
+
REQUIRED_ENV_VARS,
|
|
133
|
+
validateEnv,
|
|
134
|
+
validators
|
|
135
|
+
};
|
|
136
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/validators/env.ts"],"sourcesContent":["/**\n * Environment variable validation\n */\n\nexport interface EnvVariable {\n name: string\n description: string\n required: boolean\n validator?: (value: string) => boolean\n}\n\nexport interface ValidationResult {\n valid: boolean\n missing: string[]\n invalid: string[]\n}\n\n/**\n * Validates environment variables against required schema.\n *\n * @param required - Array of required environment variable definitions\n * @param env - Environment variable object to validate\n * @returns Validation result\n *\n * @example\n * ```typescript\n * const result = validateEnv([\n * { name: 'DB_URL', description: 'Database URL', required: true }\n * ], process.env)\n * ```\n */\nexport function validateEnv(\n required: EnvVariable[],\n env: Record<string, string | undefined>,\n): ValidationResult {\n const missing: string[] = []\n const invalid: string[] = []\n\n for (const variable of required) {\n const value = env[variable.name]\n\n // Check if required variable is missing\n if (variable.required && (!value || value.trim() === '')) {\n missing.push(variable.name)\n continue\n }\n\n // Check if value passes custom validator\n if (value && variable.validator && !variable.validator(value)) {\n invalid.push(variable.name)\n }\n }\n\n return {\n valid: missing.length === 0 && invalid.length === 0,\n missing,\n invalid,\n }\n}\n\n/**\n * Common environment variable validators\n */\nexport const validators = {\n /**\n * Validates PostgreSQL connection string format\n */\n postgresUrl: (value: string): boolean => {\n try {\n const url = new URL(value)\n return url.protocol === 'postgresql:' || url.protocol === 'postgres:'\n } catch {\n return false\n }\n },\n\n /**\n * Validates Stripe secret key format\n */\n stripeSecretKey: (value: string): boolean => {\n return value.startsWith('sk_test_') || value.startsWith('sk_live_')\n },\n\n /**\n * Validates Stripe publishable key format\n */\n stripePublishableKey: (value: string): boolean => {\n return value.startsWith('pk_test_') || value.startsWith('pk_live_')\n },\n\n /**\n * Validates URL format\n */\n url: (value: string): boolean => {\n try {\n new URL(value)\n return true\n } catch {\n return false\n }\n },\n\n /**\n * Validates minimum length\n */\n minLength:\n (min: number) =>\n (value: string): boolean => {\n return value.length >= min\n },\n\n /**\n * Validates email format\n */\n email: (value: string): boolean => {\n return /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(value)\n },\n}\n\n/**\n * Common required environment variables for RevealUI\n */\nexport const REQUIRED_ENV_VARS: EnvVariable[] = [\n {\n name: 'REVEALUI_SECRET',\n description: 'Secret key for JWT tokens and session encryption (min 32 chars)',\n required: true,\n validator: validators.minLength(32),\n },\n {\n name: 'POSTGRES_URL',\n description: 'PostgreSQL connection string',\n required: true,\n validator: validators.postgresUrl,\n },\n {\n name: 'BLOB_READ_WRITE_TOKEN',\n description: 'Vercel Blob storage token',\n required: true,\n },\n {\n name: 'STRIPE_SECRET_KEY',\n description: 'Stripe secret key (sk_test_... or sk_live_...)',\n required: true,\n validator: validators.stripeSecretKey,\n },\n {\n name: 'NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY',\n description: 'Stripe publishable key (pk_test_... or pk_live_...)',\n required: true,\n validator: validators.stripePublishableKey,\n },\n]\n\n/**\n * Optional environment variables\n */\nexport const OPTIONAL_ENV_VARS: EnvVariable[] = [\n {\n name: 'STRIPE_WEBHOOK_SECRET',\n description: 'Stripe webhook secret (whsec_...)',\n required: false,\n },\n {\n name: 'NEXT_PUBLIC_SUPABASE_URL',\n description: 'Supabase project URL',\n required: false,\n validator: validators.url,\n },\n {\n name: 'NEXT_PUBLIC_SUPABASE_ANON_KEY',\n description: 'Supabase anonymous key',\n required: false,\n },\n {\n name: 'REVEALUI_ADMIN_EMAIL',\n description: 'Initial admin email',\n required: false,\n validator: validators.email,\n },\n {\n name: 'REVEALUI_ADMIN_PASSWORD',\n description: 'Initial admin password (min 12 chars)',\n required: false,\n validator: validators.minLength(12),\n },\n]\n"],"mappings":";AA+BO,SAAS,YACd,UACA,KACkB;AAClB,QAAM,UAAoB,CAAC;AAC3B,QAAM,UAAoB,CAAC;AAE3B,aAAW,YAAY,UAAU;AAC/B,UAAM,QAAQ,IAAI,SAAS,IAAI;AAG/B,QAAI,SAAS,aAAa,CAAC,SAAS,MAAM,KAAK,MAAM,KAAK;AACxD,cAAQ,KAAK,SAAS,IAAI;AAC1B;AAAA,IACF;AAGA,QAAI,SAAS,SAA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ACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,IACV,WAAW,WAAW;AAAA,EACxB;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,IACV,WAAW,WAAW;AAAA,EACxB;AACF;AAKO,IAAM,oBAAmC;AAAA,EAC9C;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,IACV,WAAW,WAAW;AAAA,EACxB;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,IACV,WAAW,WAAW;AAAA,EACxB;AAAA,EACA;AAAA,IACE,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,IACV,WAAW,WAAW,UAAU,EAAE;AAAA,EACpC;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@revealui/setup",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Setup utilities for RevealUI projects - environment, database, and configuration management",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cli",
|
|
7
|
+
"configuration",
|
|
8
|
+
"database",
|
|
9
|
+
"environment",
|
|
10
|
+
"revealui",
|
|
11
|
+
"setup"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/RevealUIStudio/revealui.git",
|
|
16
|
+
"directory": "packages/setup"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "RevealUI Team",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"chalk": "^5.6.2",
|
|
22
|
+
"execa": "^9.0.0",
|
|
23
|
+
"inquirer": "^12.0.0",
|
|
24
|
+
"ora": "^8.0.1",
|
|
25
|
+
"zod": "^4.3.5",
|
|
26
|
+
"@revealui/config": "0.2.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/inquirer": "^9.0.7",
|
|
30
|
+
"@types/node": "^25.3.0",
|
|
31
|
+
"tsup": "^8.0.0",
|
|
32
|
+
"typescript": "^5.7.2",
|
|
33
|
+
"vitest": "^4.0.18"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=24.12.0"
|
|
37
|
+
},
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"import": "./dist/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./environment": {
|
|
44
|
+
"types": "./dist/environment/index.d.ts",
|
|
45
|
+
"import": "./dist/environment/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./utils": {
|
|
48
|
+
"types": "./dist/utils/index.d.ts",
|
|
49
|
+
"import": "./dist/utils/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./validators": {
|
|
52
|
+
"types": "./dist/validators/index.d.ts",
|
|
53
|
+
"import": "./dist/validators/index.js"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"dist",
|
|
58
|
+
"README.md"
|
|
59
|
+
],
|
|
60
|
+
"main": "./dist/index.js",
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "public",
|
|
63
|
+
"registry": "https://registry.npmjs.org"
|
|
64
|
+
},
|
|
65
|
+
"type": "module",
|
|
66
|
+
"types": "./dist/index.d.ts",
|
|
67
|
+
"scripts": {
|
|
68
|
+
"build": "tsup",
|
|
69
|
+
"dev": "tsup --watch",
|
|
70
|
+
"lint": "biome check .",
|
|
71
|
+
"test": "vitest",
|
|
72
|
+
"test:coverage": "vitest --coverage",
|
|
73
|
+
"typecheck": "tsc --noEmit"
|
|
74
|
+
}
|
|
75
|
+
}
|