@vaiftech/cli 1.7.2 → 1.7.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.
- package/README.md +1 -1
- package/dist/{chunk-KXD5F33V.js → chunk-CMWHBLLZ.js} +52 -62
- package/dist/cli.cjs +62 -72
- package/dist/cli.js +2 -2
- package/dist/index.cjs +61 -71
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
'use strict';require('dotenv/config');var commander=require('commander'),f=require('chalk'),D=require('fs'),w=require('path'),vt=require('pg'),
|
|
2
|
+
'use strict';require('dotenv/config');var commander=require('commander'),f=require('chalk'),D=require('fs'),w=require('path'),vt=require('pg'),W=require('ora'),It=require('prettier'),rt=require('dotenv'),lt=require('os'),child_process=require('child_process'),Ie=require('readline');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var f__default=/*#__PURE__*/_interopDefault(f);var D__default=/*#__PURE__*/_interopDefault(D);var w__default=/*#__PURE__*/_interopDefault(w);var vt__default=/*#__PURE__*/_interopDefault(vt);var W__default=/*#__PURE__*/_interopDefault(W);var It__default=/*#__PURE__*/_interopDefault(It);var rt__default=/*#__PURE__*/_interopDefault(rt);var lt__default=/*#__PURE__*/_interopDefault(lt);var Ie__default=/*#__PURE__*/_interopDefault(Ie);rt__default.default.config();async function A(t){let e=w__default.default.resolve(t);if(!D__default.default.existsSync(e))return null;try{let o=D__default.default.readFileSync(e,"utf-8"),n=JSON.parse(o);return n.database?.url&&(n.database.url=ve(n.database.url)),n.api?.apiKey&&(n.api.apiKey=ve(n.api.apiKey)),n}catch{throw new Error(`Failed to parse config file: ${t}`)}}function ve(t){return t.replace(/\$\{([^}]+)\}/g,(e,o)=>process.env[o]||e)}var ae=w__default.default.join(lt__default.default.homedir(),".vaif"),$=w__default.default.join(ae,"auth.json"),J=process.env.VAIF_API_URL||"https://api.vaif.studio";function dt(){D__default.default.existsSync(ae)||D__default.default.mkdirSync(ae,{recursive:true});}function Ae(t){dt(),D__default.default.writeFileSync($,JSON.stringify(t,null,2),"utf-8"),D__default.default.chmodSync($,384);}function I(){if(!D__default.default.existsSync($))return null;try{let t=D__default.default.readFileSync($,"utf-8");return JSON.parse(t)}catch{return null}}function pt(t){let e=Ie__default.default.createInterface({input:process.stdin,output:process.stdout});return new Promise(o=>{e.question(t,n=>{e.close(),o(n);});})}function ut(t){return new Promise(e=>{let o=Ie__default.default.createInterface({input:process.stdin,output:process.stdout});process.stdin;let r=process.stdout.write.bind(process.stdout),s=false;process.stdout.write=((...i)=>s?true:r(...i)),o.question(t,i=>{s=false,process.stdout.write=r,console.log(""),o.close(),e(i);}),s=true;})}function ft(t){let e=process.platform,o;e==="darwin"?o=`open "${t}"`:e==="win32"?o=`start "" "${t}"`:o=`xdg-open "${t}"`,child_process.exec(o,n=>{});}function gt(t){return new Promise(e=>setTimeout(e,t))}async function mt(t){try{let e=await fetch(`${J}/auth/me`,{headers:{Authorization:`Bearer ${t}`}});if(e.ok){let o=await e.json();return {valid:!0,email:o.user?.email||o.email}}return {valid:!1}}catch{return {valid:false}}}async function ht(t){let e=W__default.default();e.start("Setting up authentication...");let o,n;try{let a=await fetch(`${J}/auth/cli/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})});a.ok||(e.fail("Failed to initiate authentication"),console.log(f__default.default.red(`
|
|
3
3
|
Could not connect to VAIF API. Please try again later.`)),process.exit(1));let c=await a.json();o=c.code,n=c.url;}catch{e.fail("Failed to connect to VAIF API"),console.log(f__default.default.red(`
|
|
4
4
|
Could not connect to VAIF API.`)),console.log(f__default.default.gray("Check your internet connection or try: vaif login --email")),process.exit(1);}e.stop(),console.log(f__default.default.cyan(" Opening browser for authentication...")),console.log(""),console.log(f__default.default.gray(" If the browser doesn't open, visit this URL:")),console.log(f__default.default.white(` ${n}`)),console.log(""),ft(n),e.start("Waiting for browser authentication...");let r=12e4,s=2e3,i=Date.now();for(;Date.now()-i<r;){await gt(s);try{let a=await fetch(`${J}/auth/cli/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:o})});if(!a.ok){let l=await a.json();(l.error==="ExpiredCode"||l.error==="InvalidCode")&&(e.fail("Authentication expired"),console.log(f__default.default.red(`
|
|
5
5
|
The authentication session expired. Please try again.`)),process.exit(1));continue}let c=await a.json();if(c.ok&&c.accessToken){let l={token:c.accessToken,email:c.user?.email,projectId:t,expiresAt:new Date(Date.now()+c.expiresIn*1e3).toISOString()};Ae(l),e.succeed("Logged in successfully"),console.log(""),c.user?.email&&console.log(f__default.default.green(` Authenticated as: ${c.user.email}`)),console.log(f__default.default.gray(` Config saved to: ${$}`)),console.log("");return}}catch{}}e.fail("Authentication timed out"),console.log(f__default.default.red(`
|
|
6
6
|
Timed out waiting for browser authentication.`)),console.log(f__default.default.gray("Try again or use: vaif login --email")),process.exit(1);}async function yt(t){console.log(""),console.log(f__default.default.bold("VAIF CLI Login")),console.log(f__default.default.gray("Enter your VAIF account credentials")),console.log("");let e=await pt(f__default.default.cyan(" Email: "));(!e||e.trim()==="")&&(console.log(f__default.default.red(`
|
|
7
7
|
No email provided. Login cancelled.`)),process.exit(1));let o=await ut(f__default.default.cyan(" Password: "));(!o||o.trim()==="")&&(console.log(f__default.default.red(`
|
|
8
|
-
No password provided. Login cancelled.`)),process.exit(1));let n=
|
|
8
|
+
No password provided. Login cancelled.`)),process.exit(1));let n=W__default.default("Authenticating...").start();try{let r=await fetch(`${J}/auth/cli/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e.trim(),password:o})}),s=await r.json();(!r.ok||!s.ok)&&(n.fail("Login failed"),console.log(f__default.default.red(`
|
|
9
9
|
${s.message||"Invalid email or password."}`)),process.exit(1));let i={token:s.accessToken,email:s.user?.email,projectId:t,expiresAt:new Date(Date.now()+s.expiresIn*1e3).toISOString()};Ae(i),n.succeed("Logged in successfully"),console.log(""),s.user?.email&&console.log(f__default.default.green(` Authenticated as: ${s.user.email}`)),console.log(f__default.default.gray(` Config saved to: ${$}`)),console.log("");}catch{n.fail("Failed to connect to VAIF API"),console.log(f__default.default.red(`
|
|
10
|
-
Could not connect to VAIF API. Please try again later.`)),process.exit(1);}}async function we(t){console.log(""),console.log(f__default.default.bold("Welcome to VAIF CLI")),console.log(f__default.default.gray("Authenticate to access your VAIF projects")),console.log(""),t.email?await yt(t.projectId):await ht(t.projectId),console.log(f__default.default.gray("You can now use VAIF CLI commands like:")),console.log(f__default.default.gray(" vaif pull - Pull remote schema")),console.log(f__default.default.gray(" vaif push - Push schema changes")),console.log(f__default.default.gray(" vaif generate - Generate TypeScript types")),console.log("");}async function Se(){D__default.default.existsSync($)?(D__default.default.unlinkSync($),console.log(f__default.default.green("Logged out successfully"))):console.log(f__default.default.yellow("Not currently logged in"));}async function _e(){let t=I();(!t||!t.token)&&(console.log(f__default.default.yellow("Not logged in")),console.log(f__default.default.gray("Run `vaif login` to authenticate")),process.exit(1));let e=
|
|
10
|
+
Could not connect to VAIF API. Please try again later.`)),process.exit(1);}}async function we(t){console.log(""),console.log(f__default.default.bold("Welcome to VAIF CLI")),console.log(f__default.default.gray("Authenticate to access your VAIF projects")),console.log(""),t.email?await yt(t.projectId):await ht(t.projectId),console.log(f__default.default.gray("You can now use VAIF CLI commands like:")),console.log(f__default.default.gray(" vaif pull - Pull remote schema")),console.log(f__default.default.gray(" vaif push - Push schema changes")),console.log(f__default.default.gray(" vaif generate - Generate TypeScript types")),console.log("");}async function Se(){D__default.default.existsSync($)?(D__default.default.unlinkSync($),console.log(f__default.default.green("Logged out successfully"))):console.log(f__default.default.yellow("Not currently logged in"));}async function _e(){let t=I();(!t||!t.token)&&(console.log(f__default.default.yellow("Not logged in")),console.log(f__default.default.gray("Run `vaif login` to authenticate")),process.exit(1));let e=W__default.default("Checking authentication...").start(),{valid:o,email:n}=await mt(t.token);o||(e.fail("Session expired"),console.log(f__default.default.yellow(`
|
|
11
11
|
Your session has expired. Please login again.`)),process.exit(1)),e.succeed("Authenticated"),console.log(""),console.log(f__default.default.green(` Email: ${n||t.email||"Unknown"}`)),t.projectId&&console.log(f__default.default.green(` Project: ${t.projectId}`)),console.log("");}var At=process.env.VAIF_API_URL||"https://api.vaif.studio";async function wt(t,e){let o=await fetch(`${At}/schema-engine/introspect/${e}`,{headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!o.ok){let a=await o.text();throw new Error(`API introspection failed: ${a}`)}let n=await o.json();if(!n.ok||!n.schemaExists)throw new Error("Project schema does not exist yet. Push a migration first with `vaif db push`.");let r=new Map,s=[];for(let a of n.tables){let c=a.columns.map(l=>({column_name:l.name,data_type:l.type,is_nullable:l.nullable?"YES":"NO",column_default:l.default,udt_name:l.type,is_identity:l.primaryKey&&l.default?.includes("gen_random_uuid")?"YES":"NO",character_maximum_length:null,numeric_precision:null,numeric_scale:null}));r.set(a.name,c);for(let l of a.foreignKeys)s.push({constraint_name:l.constraintName,table_name:a.name,column_name:l.columnName,foreign_table_name:l.refTable,foreign_column_name:l.refColumn});}return {tables:r,enums:new Map,foreignKeys:s}}async function St(t,e){let o=await t.query(`
|
|
12
12
|
SELECT table_name, table_type
|
|
13
13
|
FROM information_schema.tables
|
|
@@ -66,7 +66,7 @@ ${s.join(`
|
|
|
66
66
|
${i.join(`
|
|
67
67
|
`)}
|
|
68
68
|
}`;return {base:a,insert:c,update:l}}function Tt(t,e,o){let n=["/**"," * Auto-generated TypeScript types from database schema"," * Generated by @vaiftech/cli",` * Generated at: ${new Date().toISOString()}`," * "," * DO NOT EDIT MANUALLY - changes will be overwritten"," */",""];if(e.size>0){n.push("// ============ ENUMS ============"),n.push("");for(let[s,i]of e)n.push(Et(s,i)),n.push("");}n.push("// ============ TABLES ============"),n.push("");let r=[];for(let[s,i]of t){let{base:a,insert:c,update:l}=xt(s,i,e);r.push(s),n.push(a),n.push(""),n.push(c),n.push(""),n.push(l),n.push("");}n.push("// ============ DATABASE SCHEMA ============"),n.push(""),n.push("export interface Database {");for(let s of r){let i=le(s);n.push(` ${s}: {`),n.push(` Row: ${i};`),n.push(` Insert: ${i}Insert;`),n.push(` Update: ${i}Update;`),n.push(" };");}return n.push("}"),n.push(""),n.push("export type TableName = keyof Database;"),n.push(""),n.push("// ============ HELPER TYPES ============"),n.push(""),n.push('export type Row<T extends TableName> = Database[T]["Row"];'),n.push('export type Insert<T extends TableName> = Database[T]["Insert"];'),n.push('export type Update<T extends TableName> = Database[T]["Update"];'),n.push(""),n.join(`
|
|
69
|
-
`)}async function xe(t){let e=
|
|
69
|
+
`)}async function xe(t){let e=W__default.default("Loading configuration...").start();try{let o=await A(t.config),n=t.connection||o?.database?.url||process.env.DATABASE_URL,r=n&&!n.includes("${"),s,i,a;if(r){e.text="Connecting to database...";let d=new vt__default.default.Client({connectionString:n});await d.connect(),e.text="Introspecting schema...",{tables:s,enums:i,foreignKeys:a}=await St(d,t.schema),await d.end();}else {let d=I();(!d||!d.token)&&(e.fail("No database connection and not logged in"),console.log(f__default.default.yellow(`
|
|
70
70
|
Either:`)),console.log(f__default.default.gray(" 1. Run `vaif login` to authenticate (no DATABASE_URL needed)")),console.log(f__default.default.gray(" 2. Set DATABASE_URL in your .env file")),console.log(f__default.default.gray(" 3. Pass --connection postgresql://user:pass@host:5432/db")),process.exit(1));let m=o?.projectId||process.env.VAIF_PROJECT_ID||d.projectId;m||(e.fail("No project ID specified"),console.log(f__default.default.yellow(`
|
|
71
71
|
Set projectId in vaif.config.json or use VAIF_PROJECT_ID env var.`)),process.exit(1)),e.text="Introspecting schema via API...",{tables:s,enums:i,foreignKeys:a}=await wt(d.token,m);}if(s.size===0){e.warn("No tables found"),console.log(f__default.default.yellow(`
|
|
72
72
|
Push a migration first: vaif db push`));return}e.text=`Generating types for ${s.size} tables...`;let c=Tt(s,i,a),l=await It__default.default.format(c,{parser:"typescript",semi:!0,singleQuote:!1,trailingComma:"es5",printWidth:100});if(t.dryRun){e.succeed("Generated types (dry run):"),console.log(""),console.log(f__default.default.gray("\u2500".repeat(60))),console.log(l),console.log(f__default.default.gray("\u2500".repeat(60)));return}let p=w__default.default.resolve(t.output),u=w__default.default.dirname(p);D__default.default.existsSync(u)||D__default.default.mkdirSync(u,{recursive:!0}),D__default.default.writeFileSync(p,l,"utf-8"),e.succeed(`Generated types for ${s.size} tables \u2192 ${f__default.default.cyan(t.output)}`),console.log(""),console.log(f__default.default.green("Generated:")),console.log(f__default.default.gray(` Tables: ${s.size}`)),console.log(f__default.default.gray(` Enums: ${i.size}`)),console.log(""),console.log(f__default.default.gray("Import in your code:")),console.log(f__default.default.cyan(` import type { Database, Row, Insert, Update } from "${t.output.replace(/\.ts$/,"")}";`));}catch(o){e.fail("Failed to generate types"),o instanceof Error&&(console.error(f__default.default.red(`
|
|
@@ -185,10 +185,7 @@ NEXT_PUBLIC_VAIF_API_URL=https://api.vaif.studio
|
|
|
185
185
|
NEXT_PUBLIC_VAIF_API_KEY=your-api-key
|
|
186
186
|
VAIF_SECRET_KEY=your-secret-key
|
|
187
187
|
|
|
188
|
-
#
|
|
189
|
-
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
190
|
-
|
|
191
|
-
# CLI uses these (non-prefixed) for vaif db push, vaif secrets, etc.
|
|
188
|
+
# CLI project ID (for vaif generate, vaif pull, vaif secrets, etc.)
|
|
192
189
|
VAIF_PROJECT_ID=your-project-id
|
|
193
190
|
`},{path:".gitignore",content:`node_modules
|
|
194
191
|
.next
|
|
@@ -338,12 +335,12 @@ export default function LoginPage() {
|
|
|
338
335
|
setLoading(true);
|
|
339
336
|
setError(null);
|
|
340
337
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
setError(error.message);
|
|
344
|
-
setLoading(false);
|
|
345
|
-
} else {
|
|
338
|
+
try {
|
|
339
|
+
await vaif.auth.login(email, password);
|
|
346
340
|
router.push("/dashboard");
|
|
341
|
+
} catch (err: any) {
|
|
342
|
+
setError(err.message || "Login failed");
|
|
343
|
+
setLoading(false);
|
|
347
344
|
}
|
|
348
345
|
}
|
|
349
346
|
|
|
@@ -385,12 +382,12 @@ export default function SignupPage() {
|
|
|
385
382
|
setLoading(true);
|
|
386
383
|
setError(null);
|
|
387
384
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
setError(error.message);
|
|
391
|
-
setLoading(false);
|
|
392
|
-
} else {
|
|
385
|
+
try {
|
|
386
|
+
await vaif.auth.signUp(email, password);
|
|
393
387
|
router.push("/");
|
|
388
|
+
} catch (err: any) {
|
|
389
|
+
setError(err.message || "Sign up failed");
|
|
390
|
+
setLoading(false);
|
|
394
391
|
}
|
|
395
392
|
}
|
|
396
393
|
|
|
@@ -683,9 +680,6 @@ interface ImportMeta {
|
|
|
683
680
|
|
|
684
681
|
VITE_VAIF_API_URL=https://api.vaif.studio
|
|
685
682
|
VITE_VAIF_API_KEY=your-api-key
|
|
686
|
-
|
|
687
|
-
# Database connection (for vaif generate, vaif db push)
|
|
688
|
-
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
689
683
|
`},{path:".gitignore",content:`node_modules
|
|
690
684
|
dist
|
|
691
685
|
.env
|
|
@@ -800,12 +794,12 @@ export default function Login() {
|
|
|
800
794
|
setLoading(true);
|
|
801
795
|
setError(null);
|
|
802
796
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
setError(error.message);
|
|
806
|
-
setLoading(false);
|
|
807
|
-
} else {
|
|
797
|
+
try {
|
|
798
|
+
await vaif.auth.login(email, password);
|
|
808
799
|
navigate("/");
|
|
800
|
+
} catch (err: any) {
|
|
801
|
+
setError(err.message || "Login failed");
|
|
802
|
+
setLoading(false);
|
|
809
803
|
}
|
|
810
804
|
}
|
|
811
805
|
|
|
@@ -845,12 +839,12 @@ export default function Signup() {
|
|
|
845
839
|
setLoading(true);
|
|
846
840
|
setError(null);
|
|
847
841
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
setError(error.message);
|
|
851
|
-
setLoading(false);
|
|
852
|
-
} else {
|
|
842
|
+
try {
|
|
843
|
+
await vaif.auth.signUp(email, password);
|
|
853
844
|
navigate("/");
|
|
845
|
+
} catch (err: any) {
|
|
846
|
+
setError(err.message || "Sign up failed");
|
|
847
|
+
setLoading(false);
|
|
854
848
|
}
|
|
855
849
|
}
|
|
856
850
|
|
|
@@ -1464,10 +1458,14 @@ export default function LoginScreen() {
|
|
|
1464
1458
|
|
|
1465
1459
|
async function handleLogin() {
|
|
1466
1460
|
setLoading(true);
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1461
|
+
try {
|
|
1462
|
+
await vaif.auth.login(email, password);
|
|
1463
|
+
router.replace("/");
|
|
1464
|
+
} catch (err: any) {
|
|
1465
|
+
Alert.alert("Error", err.message || "Login failed");
|
|
1466
|
+
} finally {
|
|
1467
|
+
setLoading(false);
|
|
1468
|
+
}
|
|
1471
1469
|
}
|
|
1472
1470
|
|
|
1473
1471
|
return (
|
|
@@ -1502,10 +1500,14 @@ export default function SignupScreen() {
|
|
|
1502
1500
|
|
|
1503
1501
|
async function handleSignup() {
|
|
1504
1502
|
setLoading(true);
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1503
|
+
try {
|
|
1504
|
+
await vaif.auth.signUp(email, password);
|
|
1505
|
+
router.replace("/");
|
|
1506
|
+
} catch (err: any) {
|
|
1507
|
+
Alert.alert("Error", err.message || "Sign up failed");
|
|
1508
|
+
} finally {
|
|
1509
|
+
setLoading(false);
|
|
1510
|
+
}
|
|
1509
1511
|
}
|
|
1510
1512
|
|
|
1511
1513
|
return (
|
|
@@ -1852,7 +1854,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
|
|
1852
1854
|
setState(() { _loading = true; _error = null; });
|
|
1853
1855
|
|
|
1854
1856
|
try {
|
|
1855
|
-
await vaif.auth.
|
|
1857
|
+
await vaif.auth.login(
|
|
1856
1858
|
email: _emailController.text,
|
|
1857
1859
|
password: _passwordController.text,
|
|
1858
1860
|
);
|
|
@@ -2680,9 +2682,6 @@ export async function deleteTodo(id: string): Promise<void> {
|
|
|
2680
2682
|
|
|
2681
2683
|
VITE_VAIF_API_URL=https://api.vaif.studio
|
|
2682
2684
|
VITE_VAIF_API_KEY=your-api-key
|
|
2683
|
-
|
|
2684
|
-
# Database connection (for vaif generate, vaif db push)
|
|
2685
|
-
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
2686
2685
|
`},{path:"README.md",content:`# Todo App \u2014 VAIF Starter
|
|
2687
2686
|
|
|
2688
2687
|
A simple React todo application for learning [VAIF Studio](https://vaif.studio) basics, including typed database queries and CRUD operations.
|
|
@@ -2961,9 +2960,6 @@ export function useRealtimeMessages({
|
|
|
2961
2960
|
|
|
2962
2961
|
VITE_VAIF_API_URL=https://api.vaif.studio
|
|
2963
2962
|
VITE_VAIF_API_KEY=your-api-key
|
|
2964
|
-
|
|
2965
|
-
# Database connection (for vaif generate, vaif db push)
|
|
2966
|
-
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
2967
2963
|
`},{path:"README.md",content:`# Realtime Chat \u2014 VAIF Starter
|
|
2968
2964
|
|
|
2969
2965
|
A React chat application with live messaging powered by [VAIF Studio](https://vaif.studio) realtime subscriptions.
|
|
@@ -3279,10 +3275,7 @@ NEXT_PUBLIC_VAIF_API_URL=https://api.vaif.studio
|
|
|
3279
3275
|
NEXT_PUBLIC_VAIF_API_KEY=your-api-key
|
|
3280
3276
|
VAIF_SECRET_KEY=your-secret-key
|
|
3281
3277
|
|
|
3282
|
-
#
|
|
3283
|
-
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
3284
|
-
|
|
3285
|
-
# CLI uses these (non-prefixed) for vaif db push, vaif secrets, etc.
|
|
3278
|
+
# CLI project ID (for vaif generate, vaif pull, vaif secrets, etc.)
|
|
3286
3279
|
VAIF_PROJECT_ID=your-project-id
|
|
3287
3280
|
`},{path:"README.md",content:`# SaaS Starter \u2014 VAIF Studio
|
|
3288
3281
|
|
|
@@ -3557,10 +3550,7 @@ NEXT_PUBLIC_VAIF_API_URL=https://api.vaif.studio
|
|
|
3557
3550
|
NEXT_PUBLIC_VAIF_API_KEY=your-api-key
|
|
3558
3551
|
VAIF_SECRET_KEY=your-secret-key
|
|
3559
3552
|
|
|
3560
|
-
#
|
|
3561
|
-
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
3562
|
-
|
|
3563
|
-
# CLI uses these (non-prefixed) for vaif db push, vaif secrets, etc.
|
|
3553
|
+
# CLI project ID (for vaif generate, vaif pull, vaif secrets, etc.)
|
|
3564
3554
|
VAIF_PROJECT_ID=your-project-id
|
|
3565
3555
|
`},{path:"README.md",content:`# E-commerce API \u2014 VAIF Studio
|
|
3566
3556
|
|
|
@@ -3709,40 +3699,40 @@ Unknown template: ${t}`)),console.log(f__default.default.yellow(`Run 'vaif templ
|
|
|
3709
3699
|
No features specified.`)),console.log(f__default.default.yellow("Usage: vaif init --template <name> --add-features <features>")),console.log(f__default.default.gray("Available features: auth, database, realtime, storage, functions")),process.exit(1)):o.featureFiles&&Object.keys(o.featureFiles).length>0?n=await Ft(o.defaultFeatures??["database","auth"]):n=o.defaultFeatures??[],e.addOnly?(console.log(""),console.log(f__default.default.bold(`Adding features to ${f__default.default.cyan(o.name)} project...`)),console.log(f__default.default.gray(` Features: ${n.join(", ")}`)),console.log("")):(console.log(""),console.log(f__default.default.bold(`Scaffolding ${f__default.default.cyan(o.name)} template...`)),n.length>0&&console.log(f__default.default.gray(` Features: ${n.join(", ")}`)),console.log(""));let r=e.addOnly?[]:[...o.files];if(o.featureFiles)for(let l of n){let p=o.featureFiles[l];p&&r.push(...p);}let s=0,i=0;for(let l of r){let p=w__default.default.resolve(l.path),u=w__default.default.dirname(p);if(D__default.default.existsSync(u)||D__default.default.mkdirSync(u,{recursive:true}),l.path==="package.json"&&D__default.default.existsSync(p)&&!e.force)try{let d=JSON.parse(D__default.default.readFileSync(p,"utf-8")),m=JSON.parse(l.content),y=L=>{if(!L)return {};let M={};for(let[K,G]of Object.entries(L))!G.startsWith("workspace:")&&!G.startsWith("link:")&&!G.startsWith("file:")&&(M[K]=G);return M};d.dependencies={...y(d.dependencies),...m.dependencies||{}},d.devDependencies={...y(d.devDependencies),...m.devDependencies||{}},m.scripts&&(d.scripts={...d.scripts||{},...m.scripts}),D__default.default.writeFileSync(p,JSON.stringify(d,null,2)+`
|
|
3710
3700
|
`,"utf-8"),console.log(f__default.default.green(` merge ${l.path} (added dependencies)`)),s++;continue}catch{}if(D__default.default.existsSync(p)&&!e.force){console.log(f__default.default.yellow(` skip ${l.path} (already exists)`)),i++;continue}D__default.default.writeFileSync(p,l.content,"utf-8"),console.log(f__default.default.green(` create ${l.path}`)),s++;}console.log(""),s>0&&console.log(f__default.default.green(`Created ${s} file${s!==1?"s":""}.`)),i>0&&console.log(f__default.default.yellow(`Skipped ${i} file${i!==1?"s":""} (use --force to overwrite).`));let a={auth:{"@vaiftech/auth":"^1.0.0"},database:{},realtime:{},storage:{},functions:{}},c=w__default.default.resolve("package.json");if(D__default.default.existsSync(c)&&n.length>0)try{let l=JSON.parse(D__default.default.readFileSync(c,"utf-8")),p=!1;for(let u of n){let d=a[u];if(d)for(let[m,y]of Object.entries(d))l.dependencies?.[m]||(l.dependencies=l.dependencies||{},l.dependencies[m]=y,p=!0);}p&&D__default.default.writeFileSync(c,JSON.stringify(l,null,2)+`
|
|
3711
3701
|
`,"utf-8");}catch{}(o.dependencies?.length||o.devDependencies?.length)&&(console.log(""),console.log(f__default.default.bold("Install dependencies:")),o.dependencies?.length&&console.log(f__default.default.cyan(` npm install ${o.dependencies.join(" ")}`)),o.devDependencies?.length&&console.log(f__default.default.cyan(` npm install -D ${o.devDependencies.join(" ")}`))),console.log(""),console.log(f__default.default.bold.green("Project scaffolded successfully!")),console.log(""),console.log(f__default.default.bold(" Next steps:")),o.postInstructions.forEach(l=>{console.log(f__default.default.gray(` ${l}`));}),console.log(""),console.log(f__default.default.gray(" Get your project credentials at https://vaif.studio/app/security/api-keys")),console.log("");}var jt={$schema:"https://vaif.studio/schemas/config.json",projectId:"",database:{url:"${DATABASE_URL}",schema:"public"},types:{output:"./src/types/database.ts"},api:{baseUrl:"https://api.vaif.studio"}};async function je(t){if(t.addFeatures){t.template||(console.log(f__default.default.red(`
|
|
3712
|
-
--add-features requires --template to know which template to use.`)),console.log(f__default.default.gray("Example: vaif init --template react-spa --add-features functions,storage")),process.exit(1));let n=t.addFeatures.split(",").map(r=>r.trim());await de(t.template,{force:t.force,features:n,addOnly:true});return}let e=
|
|
3702
|
+
--add-features requires --template to know which template to use.`)),console.log(f__default.default.gray("Example: vaif init --template react-spa --add-features functions,storage")),process.exit(1));let n=t.addFeatures.split(",").map(r=>r.trim());await de(t.template,{force:t.force,features:n,addOnly:true});return}let e=W__default.default("Initializing VAIF configuration...").start(),o=w__default.default.resolve("vaif.config.json");D__default.default.existsSync(o)&&!t.force&&(e.fail("vaif.config.json already exists"),console.log(f__default.default.yellow(`
|
|
3713
3703
|
Use --force to overwrite existing configuration.`)),process.exit(1));try{if(D__default.default.writeFileSync(o,JSON.stringify(jt,null,2),"utf-8"),e.succeed("Created vaif.config.json"),t.template){let n=t.features?t.features.split(",").map(r=>r.trim()):void 0;await de(t.template,{force:t.force,features:n});}else {let n=w__default.default.resolve(".env.example");if(D__default.default.existsSync(n)||(D__default.default.writeFileSync(n,`# VAIF Configuration
|
|
3714
3704
|
DATABASE_URL=postgresql://user:password@localhost:5432/database
|
|
3715
3705
|
VAIF_API_KEY=your-api-key
|
|
3716
3706
|
`,"utf-8"),console.log(f__default.default.gray("Created .env.example"))),t.typescript){let r=w__default.default.resolve("src/types");D__default.default.existsSync(r)||(D__default.default.mkdirSync(r,{recursive:!0}),console.log(f__default.default.gray("Created src/types directory")));}console.log(""),console.log(f__default.default.green("VAIF initialized successfully!")),console.log(""),console.log(f__default.default.gray("Next steps:")),console.log(f__default.default.gray(" 1. Update vaif.config.json with your project ID")),console.log(f__default.default.gray(" 2. Set DATABASE_URL in your environment")),console.log(f__default.default.gray(" 3. Run: npx vaif generate")),console.log("");}}catch(n){e.fail("Failed to initialize"),n instanceof Error&&console.error(f__default.default.red(`
|
|
3717
|
-
Error: ${n.message}`)),process.exit(1);}}var Lt=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Vt(t,e,o="public"){let n=await fetch(`${Lt}/v1/projects/${e}/schema?schema=${o}`,{headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!n.ok){let r=await n.text();throw new Error(`Failed to fetch schema: ${r}`)}return n.json()}async function Ce(t){let e=
|
|
3707
|
+
Error: ${n.message}`)),process.exit(1);}}var Lt=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Vt(t,e,o="public"){let n=await fetch(`${Lt}/v1/projects/${e}/schema?schema=${o}`,{headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!n.ok){let r=await n.text();throw new Error(`Failed to fetch schema: ${r}`)}return n.json()}async function Ce(t){let e=W__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;e.start("Loading configuration...");try{r=await A(n);}catch(i){e.fail("Failed to load config"),console.log(f__default.default.red(`
|
|
3718
3708
|
Error: ${i}`)),process.exit(1);}r||(e.fail("No configuration found"),console.log(f__default.default.yellow("\nRun `vaif init` to create a configuration file.")),process.exit(1));let s=t.projectId||r.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(e.fail("No project ID specified"),console.log(f__default.default.yellow(`
|
|
3719
3709
|
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1)),e.text="Fetching remote schema...";try{let i=t.schema||r.database?.schema||"public",a=await Vt(o.token,s,i);e.succeed("Schema fetched successfully");let c=t.output||w__default.default.resolve("vaif.schema.json"),l={$schema:"https://vaif.studio/schemas/schema.json",projectId:s,schema:i,pulledAt:new Date().toISOString(),...a};D__default.default.writeFileSync(c,JSON.stringify(l,null,2),"utf-8"),console.log(""),console.log(f__default.default.green(`Schema saved to: ${c}`)),console.log(""),console.log(f__default.default.gray("Schema summary:")),console.log(f__default.default.gray(` Tables: ${(a.tables||[]).length}`)),console.log(f__default.default.gray(` Enums: ${(a.enums||[]).length}`)),console.log(f__default.default.gray(` Functions: ${(a.functions||[]).length}`)),console.log(""),console.log(f__default.default.gray("Next steps:")),console.log(f__default.default.gray(" - Run `vaif generate` to generate TypeScript types")),console.log(f__default.default.gray(" - Edit the schema and run `vaif push` to deploy changes")),console.log("");}catch(i){e.fail("Failed to fetch schema"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3720
|
-
Error: ${i.message}`)),process.exit(1);}}var Ne=process.env.VAIF_API_URL||"https://api.vaif.studio";function $t(t){let e=Ie__default.default.createInterface({input:process.stdin,output:process.stdout});return new Promise(o=>{e.question(t,n=>{e.close(),o(n);});})}async function Ot(t,e,o){let n=await fetch(`${Ne}/v1/projects/${e}/schema/preview`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({schema:o})});if(!n.ok){let r=await n.text();throw new Error(`Failed to preview changes: ${r}`)}return n.json()}async function Mt(t,e,o){let n=await fetch(`${Ne}/v1/projects/${e}/schema/apply`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({schema:o})});if(!n.ok){let r=await n.text();throw new Error(`Failed to apply changes: ${r}`)}return n.json()}function Kt(t){if(console.log(""),console.log(f__default.default.bold("Schema Changes:")),console.log(""),t.added.length===0&&t.modified.length===0&&t.removed.length===0){console.log(f__default.default.gray(" No changes detected. Schema is up to date."));return}if(t.added.length>0){console.log(f__default.default.green.bold(" + Added:"));for(let e of t.added)console.log(f__default.default.green(` + ${e.type}: ${e.name}`));console.log("");}if(t.modified.length>0){console.log(f__default.default.yellow.bold(" ~ Modified:"));for(let e of t.modified){console.log(f__default.default.yellow(` ~ ${e.type}: ${e.name}`));for(let o of e.changes)console.log(f__default.default.gray(` ${o}`));}console.log("");}if(t.removed.length>0){console.log(f__default.default.red.bold(" - Removed:"));for(let e of t.removed)console.log(f__default.default.red(` - ${e.type}: ${e.name}`));console.log("");}}async function Le(t){let e=
|
|
3710
|
+
Error: ${i.message}`)),process.exit(1);}}var Ne=process.env.VAIF_API_URL||"https://api.vaif.studio";function $t(t){let e=Ie__default.default.createInterface({input:process.stdin,output:process.stdout});return new Promise(o=>{e.question(t,n=>{e.close(),o(n);});})}async function Ot(t,e,o){let n=await fetch(`${Ne}/v1/projects/${e}/schema/preview`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({schema:o})});if(!n.ok){let r=await n.text();throw new Error(`Failed to preview changes: ${r}`)}return n.json()}async function Mt(t,e,o){let n=await fetch(`${Ne}/v1/projects/${e}/schema/apply`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({schema:o})});if(!n.ok){let r=await n.text();throw new Error(`Failed to apply changes: ${r}`)}return n.json()}function Kt(t){if(console.log(""),console.log(f__default.default.bold("Schema Changes:")),console.log(""),t.added.length===0&&t.modified.length===0&&t.removed.length===0){console.log(f__default.default.gray(" No changes detected. Schema is up to date."));return}if(t.added.length>0){console.log(f__default.default.green.bold(" + Added:"));for(let e of t.added)console.log(f__default.default.green(` + ${e.type}: ${e.name}`));console.log("");}if(t.modified.length>0){console.log(f__default.default.yellow.bold(" ~ Modified:"));for(let e of t.modified){console.log(f__default.default.yellow(` ~ ${e.type}: ${e.name}`));for(let o of e.changes)console.log(f__default.default.gray(` ${o}`));}console.log("");}if(t.removed.length>0){console.log(f__default.default.red.bold(" - Removed:"));for(let e of t.removed)console.log(f__default.default.red(` - ${e.type}: ${e.name}`));console.log("");}}async function Le(t){let e=W__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;e.start("Loading configuration...");try{r=await A(n);}catch(c){e.fail("Failed to load config"),console.log(f__default.default.red(`
|
|
3721
3711
|
Error: ${c}`)),process.exit(1);}r||(e.fail("No configuration found"),console.log(f__default.default.yellow("\nRun `vaif init` to create a configuration file.")),process.exit(1));let s=t.projectId||r.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(e.fail("No project ID specified"),console.log(f__default.default.yellow(`
|
|
3722
3712
|
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1));let i=t.schema||w__default.default.resolve("vaif.schema.json");D__default.default.existsSync(i)||(e.fail("No local schema found"),console.log(f__default.default.yellow(`
|
|
3723
3713
|
Expected schema file at: ${i}`)),console.log(f__default.default.gray("Run `vaif pull` first to fetch the current schema.")),process.exit(1));let a;try{let c=D__default.default.readFileSync(i,"utf-8");a=JSON.parse(c);}catch(c){e.fail("Failed to parse schema file"),c instanceof Error&&console.log(f__default.default.red(`
|
|
3724
3714
|
Error: ${c.message}`)),process.exit(1);}e.text="Calculating schema changes...";try{let{diff:c,sql:l}=await Ot(o.token,s,a);if(e.stop(),Kt(c),c.added.length===0&&c.modified.length===0&&c.removed.length===0){console.log("");return}if(l.length>0){console.log(f__default.default.bold("SQL Migrations:")),console.log("");for(let u of l)console.log(f__default.default.gray(` ${u}`));console.log("");}if(t.dryRun){console.log(f__default.default.yellow("Dry run mode - no changes applied.")),console.log(f__default.default.gray("Remove --dry-run to apply these changes."));return}if(!t.force){c.removed.length>0&&(console.log(f__default.default.red.bold("\u26A0\uFE0F Warning: This will remove tables/columns from your database.")),console.log(f__default.default.red(" This action cannot be undone!")),console.log(""));let d=await $t(f__default.default.cyan("Apply these changes? [y/N] "));if(d.toLowerCase()!=="y"&&d.toLowerCase()!=="yes"){console.log(f__default.default.yellow(`
|
|
3725
3715
|
Cancelled. No changes applied.`));return}}e.start("Applying schema changes...");let p=await Mt(o.token,s,a);if(p.success){if(e.succeed("Schema changes applied successfully"),console.log(""),p.migrations.length>0){console.log(f__default.default.gray("Migrations applied:"));for(let u of p.migrations)console.log(f__default.default.gray(` - ${u}`));console.log("");}console.log(f__default.default.green("Your database schema is now up to date.")),console.log(f__default.default.gray("Run `vaif generate` to update your TypeScript types.")),console.log("");}else e.fail("Failed to apply some changes");}catch(c){e.fail("Failed to push schema changes"),c instanceof Error&&console.log(f__default.default.red(`
|
|
3726
|
-
Error: ${c.message}`)),process.exit(1);}}var
|
|
3716
|
+
Error: ${c.message}`)),process.exit(1);}}var H=process.env.VAIF_API_URL||"https://api.vaif.studio";async function zt(t,e,o,n){let r=new URL(`${H}/functions/project/${e}`);n&&r.searchParams.set("envId",n);let s=await fetch(r.toString(),{headers:{Authorization:`Bearer ${t}`}});if(!s.ok)return null;let i=await s.json(),a=i.functions||i;return Array.isArray(a)&&a.find(c=>c.name===o)||null}async function Bt(t,e,o){let n=await fetch(`${H}/functions/`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({projectId:e,name:o.name,runtime:o.runtime,entrypoint:o.entrypoint,envId:o.envId})});if(!n.ok){let r=await n.text();throw new Error(`Failed to create function: ${r}`)}return n.json()}async function qt(t,e,o){let n=await fetch(`${H}/functions/${e}/source`,{method:"PUT",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({sourceCode:o})});if(!n.ok){let r=await n.text();throw new Error(`Failed to deploy source: ${r}`)}}async function Yt(t,e,o){let n=new URL(`${H}/functions/project/${e}`);o&&n.searchParams.set("envId",o);let r=await fetch(n.toString(),{headers:{Authorization:`Bearer ${t}`}});if(!r.ok){let i=await r.text();throw new Error(`Failed to list functions: ${i}`)}let s=await r.json();return s.functions||s}function Ve(t){switch(w__default.default.extname(t).toLowerCase()){case ".ts":return "typescript";case ".js":case ".mjs":return "nodejs";case ".py":return "python";case ".go":return "go";case ".rs":return "rust";default:return "nodejs"}}function De(t){let e=[],o=[".ts",".js",".mjs",".py",".go",".rs"],n=["drizzle.config.ts","tsconfig.json","package.json"];if(!D__default.default.existsSync(t))return e;let r=D__default.default.readdirSync(t,{withFileTypes:true});for(let s of r){let i=w__default.default.join(t,s.name);if(s.isDirectory()){if(s.name!=="node_modules"&&!s.name.startsWith(".")){let a=D__default.default.readdirSync(i,{withFileTypes:true});for(let c of a)if(c.isFile()){let l=w__default.default.extname(c.name).toLowerCase();if(o.includes(l)){e.push(w__default.default.join(i,c.name));break}}}}else if(s.isFile()){let a=w__default.default.extname(s.name).toLowerCase();o.includes(a)&&!n.includes(s.name)&&e.push(i);}}return e}async function ke(t){let e=W__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),console.log(""),console.log(f__default.default.bold("VAIF Functions Deploy")),console.log(""),e.start("Scanning for function files...");let i=w__default.default.resolve("functions"),a=w__default.default.resolve("src/functions"),c=[];if(t.entrypoint){let d=w__default.default.resolve(t.entrypoint);D__default.default.existsSync(d)||(e.fail(`File not found: ${t.entrypoint}`),process.exit(1)),c=[d];}else c=[...De(i),...De(a)];c.length===0&&(e.fail("No function files found"),console.log(f__default.default.yellow(`
|
|
3727
3717
|
Place your functions in:`)),console.log(f__default.default.gray(" - ./functions/")),console.log(f__default.default.gray(" - ./src/functions/")),console.log(f__default.default.gray(`
|
|
3728
3718
|
Or specify an entrypoint with --entrypoint`)),process.exit(1)),e.succeed(`Found ${c.length} function(s)`),t.name&&(c=c.filter(d=>w__default.default.basename(d,w__default.default.extname(d)).includes(t.name)),c.length===0&&(console.log(f__default.default.yellow(`
|
|
3729
|
-
No functions matching "${t.name}" found`)),process.exit(1))),console.log(""),console.log(f__default.default.gray("Functions to deploy:"));for(let d of c){let m=w__default.default.basename(w__default.default.dirname(d)),y=m==="functions"||m==="src"?w__default.default.basename(d,w__default.default.extname(d)):m,L=t.runtime||Ve(d);console.log(f__default.default.gray(` - ${y} (${L})`));}if(console.log(""),t.dryRun){console.log(f__default.default.yellow("Dry run mode - no functions deployed."));return}let l=[];for(let d of c){let m=w__default.default.basename(w__default.default.dirname(d)),y=m==="functions"||m==="src"?w__default.default.basename(d,w__default.default.extname(d)):m,L=t.runtime||Ve(d);e.start(`Deploying ${y}...`);try{let M=D__default.default.readFileSync(d,"utf-8"),K=await zt(o.token,s,y,t.envId);K||(e.text=`Creating ${y}...`,K=await Bt(o.token,s,{name:y,runtime:L,entrypoint:w__default.default.basename(d),envId:t.envId})),e.text=`Deploying ${y}...`,await qt(o.token,K.id,M),e.succeed(`Deployed ${y}`),l.push({name:y,success:!0});}catch(M){let K=M instanceof Error?M.message:"Unknown error";e.fail(`Failed to deploy ${y}`),l.push({name:y,success:false,error:K});}}console.log("");let p=l.filter(d=>d.success).length;if(l.filter(d=>!d.success).length===0)console.log(f__default.default.green(`\u2713 Successfully deployed ${p} function(s)`));else {console.log(f__default.default.yellow(`Deployed ${p}/${l.length} function(s)`)),console.log(""),console.log(f__default.default.red("Failed deployments:"));for(let d of l.filter(m=>!m.success))console.log(f__default.default.red(` - ${d.name}: ${d.error}`));}console.log("");}async function $e(t){let e=
|
|
3719
|
+
No functions matching "${t.name}" found`)),process.exit(1))),console.log(""),console.log(f__default.default.gray("Functions to deploy:"));for(let d of c){let m=w__default.default.basename(w__default.default.dirname(d)),y=m==="functions"||m==="src"?w__default.default.basename(d,w__default.default.extname(d)):m,L=t.runtime||Ve(d);console.log(f__default.default.gray(` - ${y} (${L})`));}if(console.log(""),t.dryRun){console.log(f__default.default.yellow("Dry run mode - no functions deployed."));return}let l=[];for(let d of c){let m=w__default.default.basename(w__default.default.dirname(d)),y=m==="functions"||m==="src"?w__default.default.basename(d,w__default.default.extname(d)):m,L=t.runtime||Ve(d);e.start(`Deploying ${y}...`);try{let M=D__default.default.readFileSync(d,"utf-8"),K=await zt(o.token,s,y,t.envId);K||(e.text=`Creating ${y}...`,K=await Bt(o.token,s,{name:y,runtime:L,entrypoint:w__default.default.basename(d),envId:t.envId})),e.text=`Deploying ${y}...`,await qt(o.token,K.id,M),e.succeed(`Deployed ${y}`),l.push({name:y,success:!0});}catch(M){let K=M instanceof Error?M.message:"Unknown error";e.fail(`Failed to deploy ${y}`),l.push({name:y,success:false,error:K});}}console.log("");let p=l.filter(d=>d.success).length;if(l.filter(d=>!d.success).length===0)console.log(f__default.default.green(`\u2713 Successfully deployed ${p} function(s)`));else {console.log(f__default.default.yellow(`Deployed ${p}/${l.length} function(s)`)),console.log(""),console.log(f__default.default.red("Failed deployments:"));for(let d of l.filter(m=>!m.success))console.log(f__default.default.red(` - ${d.name}: ${d.error}`));}console.log("");}async function $e(t){let e=W__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(console.log(f__default.default.red("No project ID specified")),process.exit(1)),e.start("Fetching functions...");try{let i=await Yt(o.token,s,t.envId);if(e.stop(),i.length===0){console.log(f__default.default.yellow(`
|
|
3730
3720
|
No functions found`)),console.log(f__default.default.gray("Deploy your first function with: vaif functions deploy"));return}console.log(""),console.log(f__default.default.bold(`Functions (${i.length}):`)),console.log(""),console.log(f__default.default.gray(" "+"NAME".padEnd(25)+"RUNTIME".padEnd(15)+"STATUS".padEnd(12)+"INVOCATIONS".padEnd(14)+"LAST DEPLOYED")),console.log(f__default.default.gray(" "+"-".repeat(80)));for(let a of i){let c=a.deployStatus==="deployed"?f__default.default.green:a.deployStatus==="deploying"?f__default.default.yellow:a.deployStatus==="failed"?f__default.default.red:f__default.default.gray;console.log(" "+a.name.padEnd(25)+a.runtime.padEnd(15)+c(a.deployStatus.padEnd(12))+String(a.invocationCount??0).padEnd(14)+(a.deployedAt?new Date(a.deployedAt).toLocaleDateString():"-"));}console.log("");}catch(i){e.fail("Failed to fetch functions"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3731
|
-
Error: ${i.message}`)),process.exit(1);}}var X=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Gt(t,e,o,n,r){let s=await fetch(`${X}/v1/projects/${e}/db/seed`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({table:o,records:n,truncate:r?.truncate??false})});if(!s.ok){let i=await s.text();throw new Error(`Failed to seed ${o}: ${i}`)}return s.json()}async function Jt(t,e){let o=await fetch(`${X}/v1/projects/${e}/db/reset`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!o.ok){let n=await o.text();throw new Error(`Failed to reset database: ${n}`)}return o.json()}function ue(t){let e=[];if(!D__default.default.existsSync(t))return e;let o=D__default.default.readdirSync(t,{withFileTypes:true});for(let n of o)if(n.isFile()){let r=w__default.default.extname(n.name).toLowerCase();(r===".json"||r===".ts"||r===".js")&&e.push(w__default.default.join(t,n.name));}return e.sort()}async function Oe(t){let e=w__default.default.extname(t).toLowerCase();if(e===".json"){let o=D__default.default.readFileSync(t,"utf-8"),n=JSON.parse(o);return Array.isArray(n)?[{table:w__default.default.basename(t,e),data:n}]:n.table&&n.data?[n]:Object.entries(n).map(([r,s])=>({table:r,data:s}))}else if(e===".ts"||e===".js"){let o=await import(t),n=o.default||o;return typeof n=="function"?n():n}throw new Error(`Unsupported file format: ${e}`)}async function Me(t){let e=
|
|
3721
|
+
Error: ${i.message}`)),process.exit(1);}}var X=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Gt(t,e,o,n,r){let s=await fetch(`${X}/v1/projects/${e}/db/seed`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({table:o,records:n,truncate:r?.truncate??false})});if(!s.ok){let i=await s.text();throw new Error(`Failed to seed ${o}: ${i}`)}return s.json()}async function Jt(t,e){let o=await fetch(`${X}/v1/projects/${e}/db/reset`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!o.ok){let n=await o.text();throw new Error(`Failed to reset database: ${n}`)}return o.json()}function ue(t){let e=[];if(!D__default.default.existsSync(t))return e;let o=D__default.default.readdirSync(t,{withFileTypes:true});for(let n of o)if(n.isFile()){let r=w__default.default.extname(n.name).toLowerCase();(r===".json"||r===".ts"||r===".js")&&e.push(w__default.default.join(t,n.name));}return e.sort()}async function Oe(t){let e=w__default.default.extname(t).toLowerCase();if(e===".json"){let o=D__default.default.readFileSync(t,"utf-8"),n=JSON.parse(o);return Array.isArray(n)?[{table:w__default.default.basename(t,e),data:n}]:n.table&&n.data?[n]:Object.entries(n).map(([r,s])=>({table:r,data:s}))}else if(e===".ts"||e===".js"){let o=await import(t),n=o.default||o;return typeof n=="function"?n():n}throw new Error(`Unsupported file format: ${e}`)}async function Me(t){let e=W__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),console.log(""),console.log(f__default.default.bold("VAIF Database Seed")),console.log("");let i=[];if(t.file){let p=w__default.default.resolve(t.file);D__default.default.existsSync(p)||(console.log(f__default.default.red(`File not found: ${t.file}`)),process.exit(1)),i=[p];}else {let p=w__default.default.resolve("seeds"),u=w__default.default.resolve("prisma/seed"),d=w__default.default.resolve("db/seeds");i=[...ue(p),...ue(u),...ue(d)];}i.length===0&&(console.log(f__default.default.yellow("No seed files found")),console.log(f__default.default.gray(`
|
|
3732
3722
|
Place your seed files in one of these directories:`)),console.log(f__default.default.gray(" - ./seeds/")),console.log(f__default.default.gray(" - ./prisma/seed/")),console.log(f__default.default.gray(" - ./db/seeds/")),console.log(f__default.default.gray(`
|
|
3733
3723
|
Or specify a file with --file`)),console.log(f__default.default.gray(`
|
|
3734
|
-
Example seed file (seeds/users.json):`)),console.log(f__default.default.gray(" [")),console.log(f__default.default.gray(' { "name": "John Doe", "email": "john@example.com" },')),console.log(f__default.default.gray(' { "name": "Jane Doe", "email": "jane@example.com" }')),console.log(f__default.default.gray(" ]")),process.exit(1)),console.log(f__default.default.gray("Seed files found:"));for(let p of i)console.log(f__default.default.gray(` - ${w__default.default.relative(process.cwd(),p)}`));if(console.log(""),t.truncate&&(console.log(f__default.default.yellow("\u26A0\uFE0F Tables will be truncated before seeding")),console.log("")),t.dryRun){console.log(f__default.default.yellow("Dry run mode - no data will be inserted.")),console.log("");for(let p of i){e.start(`Loading ${w__default.default.basename(p)}...`);try{let u=await Oe(p);e.stop();for(let d of u)t.table&&d.table!==t.table||(console.log(f__default.default.cyan(`Table: ${d.table}`)),console.log(f__default.default.gray(` Records: ${d.data.length}`)),d.data.length>0&&console.log(f__default.default.gray(` Sample: ${JSON.stringify(d.data[0],null,2).slice(0,100)}...`)),console.log(""));}catch(u){e.fail(`Failed to load ${w__default.default.basename(p)}`),u instanceof Error&&console.log(f__default.default.red(` Error: ${u.message}`));}}return}let a=[];for(let p of i){e.start(`Processing ${w__default.default.basename(p)}...`);try{let u=await Oe(p);e.stop();for(let d of u)if(!(t.table&&d.table!==t.table)){if(d.data.length===0){console.log(f__default.default.gray(` Skipping ${d.table} (no records)`));continue}e.start(`Seeding ${d.table} (${d.data.length} records)...`);try{let m=await Gt(o.token,s,d.table,d.data,{truncate:t.truncate});e.succeed(`Seeded ${d.table}: ${m.inserted} records`),a.push({table:d.table,inserted:m.inserted});}catch(m){let y=m instanceof Error?m.message:"Unknown error";e.fail(`Failed to seed ${d.table}`),a.push({table:d.table,inserted:0,error:y});}}}catch(u){e.fail(`Failed to load ${w__default.default.basename(p)}`),u instanceof Error&&console.log(f__default.default.red(` Error: ${u.message}`));}}console.log("");let c=a.reduce((p,u)=>p+u.inserted,0),l=a.filter(p=>p.error).length;if(l===0)console.log(f__default.default.green(`\u2713 Successfully seeded ${c} records across ${a.length} table(s)`));else {console.log(f__default.default.yellow(`Seeded ${c} records with ${l} error(s)`)),console.log(""),console.log(f__default.default.red("Errors:"));for(let p of a.filter(u=>u.error))console.log(f__default.default.red(` - ${p.table}: ${p.error}`));}console.log("");}async function Ke(t){let e=
|
|
3724
|
+
Example seed file (seeds/users.json):`)),console.log(f__default.default.gray(" [")),console.log(f__default.default.gray(' { "name": "John Doe", "email": "john@example.com" },')),console.log(f__default.default.gray(' { "name": "Jane Doe", "email": "jane@example.com" }')),console.log(f__default.default.gray(" ]")),process.exit(1)),console.log(f__default.default.gray("Seed files found:"));for(let p of i)console.log(f__default.default.gray(` - ${w__default.default.relative(process.cwd(),p)}`));if(console.log(""),t.truncate&&(console.log(f__default.default.yellow("\u26A0\uFE0F Tables will be truncated before seeding")),console.log("")),t.dryRun){console.log(f__default.default.yellow("Dry run mode - no data will be inserted.")),console.log("");for(let p of i){e.start(`Loading ${w__default.default.basename(p)}...`);try{let u=await Oe(p);e.stop();for(let d of u)t.table&&d.table!==t.table||(console.log(f__default.default.cyan(`Table: ${d.table}`)),console.log(f__default.default.gray(` Records: ${d.data.length}`)),d.data.length>0&&console.log(f__default.default.gray(` Sample: ${JSON.stringify(d.data[0],null,2).slice(0,100)}...`)),console.log(""));}catch(u){e.fail(`Failed to load ${w__default.default.basename(p)}`),u instanceof Error&&console.log(f__default.default.red(` Error: ${u.message}`));}}return}let a=[];for(let p of i){e.start(`Processing ${w__default.default.basename(p)}...`);try{let u=await Oe(p);e.stop();for(let d of u)if(!(t.table&&d.table!==t.table)){if(d.data.length===0){console.log(f__default.default.gray(` Skipping ${d.table} (no records)`));continue}e.start(`Seeding ${d.table} (${d.data.length} records)...`);try{let m=await Gt(o.token,s,d.table,d.data,{truncate:t.truncate});e.succeed(`Seeded ${d.table}: ${m.inserted} records`),a.push({table:d.table,inserted:m.inserted});}catch(m){let y=m instanceof Error?m.message:"Unknown error";e.fail(`Failed to seed ${d.table}`),a.push({table:d.table,inserted:0,error:y});}}}catch(u){e.fail(`Failed to load ${w__default.default.basename(p)}`),u instanceof Error&&console.log(f__default.default.red(` Error: ${u.message}`));}}console.log("");let c=a.reduce((p,u)=>p+u.inserted,0),l=a.filter(p=>p.error).length;if(l===0)console.log(f__default.default.green(`\u2713 Successfully seeded ${c} records across ${a.length} table(s)`));else {console.log(f__default.default.yellow(`Seeded ${c} records with ${l} error(s)`)),console.log(""),console.log(f__default.default.red("Errors:"));for(let p of a.filter(u=>u.error))console.log(f__default.default.red(` - ${p.table}: ${p.error}`));}console.log("");}async function Ke(t){let e=W__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1));let i=w__default.default.resolve(t.dir||"./drizzle");if(console.log(""),console.log(f__default.default.bold("VAIF Database Push")),console.log(""),!D__default.default.existsSync(i)){let u=w__default.default.resolve("./migrations");D__default.default.existsSync(u)?console.log(f__default.default.gray(`Using migrations from: ${u}`)):(console.log(f__default.default.red(`Migrations directory not found: ${i}`)),console.log(f__default.default.gray(`
|
|
3735
3725
|
Expected one of:`)),console.log(f__default.default.gray(" - ./drizzle/")),console.log(f__default.default.gray(" - ./migrations/")),console.log(f__default.default.gray(`
|
|
3736
|
-
Or specify with: vaif db push --dir <path>`)),process.exit(1));}let a=[],c=D__default.default.readdirSync(i,{withFileTypes:true});for(let u of c)if(u.isFile()&&u.name.endsWith(".sql"))a.push(w__default.default.join(i,u.name));else if(u.isDirectory()){let d=D__default.default.readdirSync(w__default.default.join(i,u.name),{withFileTypes:true});for(let m of d)m.isFile()&&m.name.endsWith(".sql")&&a.push(w__default.default.join(i,u.name,m.name));}a.sort(),a.length===0&&(console.log(f__default.default.yellow("No SQL migration files found")),process.exit(1)),console.log(f__default.default.gray(`Found ${a.length} migration(s):`));for(let u of a)console.log(f__default.default.gray(` - ${w__default.default.relative(process.cwd(),u)}`));if(console.log(""),t.dryRun){console.log(f__default.default.yellow("Dry run mode - no migrations will be applied.")),console.log("");for(let u of a){let d=D__default.default.readFileSync(u,"utf-8");console.log(f__default.default.cyan(`--- ${w__default.default.basename(u)} ---`)),console.log(f__default.default.gray(d.slice(0,500))),d.length>500&&console.log(f__default.default.gray("...")),console.log("");}return}let l=0,p=0;for(let u of a){let d=D__default.default.readFileSync(u,"utf-8"),m=w__default.default.relative(process.cwd(),u);e.start(`Applying ${m}...`);try{let y=await fetch(`${X}/schema-engine/query/${s}`,{method:"POST",headers:{Authorization:`Bearer ${o.token}`,"Content-Type":"application/json"},body:JSON.stringify({sql:d})});if(!y.ok){let L=await y.text();throw new Error(L)}e.succeed(`Applied ${m}`),l++;}catch(y){let L=y instanceof Error?y.message:"Unknown error";e.fail(`Failed ${m}: ${L}`),p++;}}console.log(""),console.log(p===0?f__default.default.green(`Successfully applied ${l} migration(s)`):f__default.default.yellow(`Applied ${l}, failed ${p} migration(s)`)),console.log("");}async function ze(t){let e=
|
|
3737
|
-
Error: ${a.message}`)),process.exit(1);}}async function Be(t){let e=
|
|
3738
|
-
Error: ${i.message}`)),process.exit(1);}}var Ye=process.env.VAIF_API_URL||"https://api.vaif.studio";function Ge(t,e,o){return t.projectId||e?.projectId||process.env.VAIF_PROJECT_ID||o.projectId||null}async function Je(t){let e=
|
|
3739
|
-
Error: ${a.message}`)),process.exit(1);}}async function
|
|
3726
|
+
Or specify with: vaif db push --dir <path>`)),process.exit(1));}let a=[],c=D__default.default.readdirSync(i,{withFileTypes:true});for(let u of c)if(u.isFile()&&u.name.endsWith(".sql"))a.push(w__default.default.join(i,u.name));else if(u.isDirectory()){let d=D__default.default.readdirSync(w__default.default.join(i,u.name),{withFileTypes:true});for(let m of d)m.isFile()&&m.name.endsWith(".sql")&&a.push(w__default.default.join(i,u.name,m.name));}a.sort(),a.length===0&&(console.log(f__default.default.yellow("No SQL migration files found")),process.exit(1)),console.log(f__default.default.gray(`Found ${a.length} migration(s):`));for(let u of a)console.log(f__default.default.gray(` - ${w__default.default.relative(process.cwd(),u)}`));if(console.log(""),t.dryRun){console.log(f__default.default.yellow("Dry run mode - no migrations will be applied.")),console.log("");for(let u of a){let d=D__default.default.readFileSync(u,"utf-8");console.log(f__default.default.cyan(`--- ${w__default.default.basename(u)} ---`)),console.log(f__default.default.gray(d.slice(0,500))),d.length>500&&console.log(f__default.default.gray("...")),console.log("");}return}let l=0,p=0;for(let u of a){let d=D__default.default.readFileSync(u,"utf-8"),m=w__default.default.relative(process.cwd(),u);e.start(`Applying ${m}...`);try{let y=await fetch(`${X}/schema-engine/query/${s}`,{method:"POST",headers:{Authorization:`Bearer ${o.token}`,"Content-Type":"application/json"},body:JSON.stringify({sql:d})});if(!y.ok){let L=await y.text();throw new Error(L)}e.succeed(`Applied ${m}`),l++;}catch(y){let L=y instanceof Error?y.message:"Unknown error";e.fail(`Failed ${m}: ${L}`),p++;}}console.log(""),console.log(p===0?f__default.default.green(`Successfully applied ${l} migration(s)`):f__default.default.yellow(`Applied ${l}, failed ${p} migration(s)`)),console.log("");}async function ze(t){let e=W__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1));let i=w__default.default.resolve(t.output||"vaif.schema.json");console.log(""),console.log(f__default.default.bold("VAIF Database Pull")),console.log(""),e.start("Pulling schema from remote...");try{let a=await fetch(`${X}/schema-engine/introspect/${s}`,{headers:{Authorization:`Bearer ${o.token}`}});if(!a.ok){let p=await a.text();throw new Error(`Failed to pull schema: ${p}`)}let c=await a.json();D__default.default.writeFileSync(i,JSON.stringify(c,null,2),"utf-8"),e.succeed(`Schema written to ${w__default.default.relative(process.cwd(),i)}`);let l=c.tables?.length??Object.keys(c).length;console.log(f__default.default.gray(` ${l} table(s) pulled`)),console.log("");}catch(a){e.fail("Failed to pull schema"),a instanceof Error&&console.log(f__default.default.red(`
|
|
3727
|
+
Error: ${a.message}`)),process.exit(1);}}async function Be(t){let e=W__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(console.log(f__default.default.red("No project ID specified")),process.exit(1)),console.log(""),console.log(f__default.default.red.bold("\u26A0\uFE0F DATABASE RESET")),console.log(""),console.log(f__default.default.red("This will:")),console.log(f__default.default.red(" - Drop all tables")),console.log(f__default.default.red(" - Delete all data")),console.log(f__default.default.red(" - Reset migrations")),console.log(""),console.log(f__default.default.red.bold("This action cannot be undone!")),console.log(""),t.force||(console.log(f__default.default.yellow("Use --force to confirm this action.")),process.exit(1)),e.start("Resetting database...");try{await Jt(o.token,s),e.succeed("Database reset complete"),console.log(""),console.log(f__default.default.gray("Your database is now empty.")),console.log(f__default.default.gray("Run `vaif push` to apply your schema, then `vaif db seed` to seed data.")),console.log("");}catch(i){e.fail("Failed to reset database"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3728
|
+
Error: ${i.message}`)),process.exit(1);}}var Ye=process.env.VAIF_API_URL||"https://api.vaif.studio";function Ge(t,e,o){return t.projectId||e?.projectId||process.env.VAIF_PROJECT_ID||o.projectId||null}async function Je(t){let e=W__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=Ge(t,r,o);s||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1));let i=t.name||`cli-key-${Date.now()}`;console.log(""),console.log(f__default.default.bold("VAIF Generate API Key")),console.log(""),e.start("Generating API key...");try{let a=await fetch(`${Ye}/v1/projects/${s}/api-keys`,{method:"POST",headers:{Authorization:`Bearer ${o.token}`,"Content-Type":"application/json"},body:JSON.stringify({name:i})});if(!a.ok){let l=await a.text();throw new Error(`Failed to generate key: ${l}`)}let c=await a.json();e.succeed("API key generated"),console.log(""),console.log(f__default.default.green(` Name: ${c.name}`)),console.log(f__default.default.green(` Key: ${c.key}`)),console.log(""),console.log(f__default.default.yellow.bold(" Save this key now - it will not be shown again!")),console.log("");}catch(a){e.fail("Failed to generate API key"),a instanceof Error&&console.log(f__default.default.red(`
|
|
3729
|
+
Error: ${a.message}`)),process.exit(1);}}async function He(t){let e=W__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=Ge(t,r,o);s||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),console.log(""),console.log(f__default.default.bold("VAIF API Keys")),console.log(""),e.start("Fetching API keys...");try{let i=await fetch(`${Ye}/v1/projects/${s}/api-keys`,{headers:{Authorization:`Bearer ${o.token}`}});if(!i.ok){let u=await i.text();throw new Error(`Failed to list keys: ${u}`)}let a=await i.json(),c=a.keys||a;if(e.stop(),!Array.isArray(c)||c.length===0){console.log(f__default.default.yellow("No API keys found")),console.log(f__default.default.gray(`
|
|
3740
3730
|
Generate one with: vaif keys generate`));return}let l=Math.max(8,...c.map(u=>(u.name||"").length)),p=` ${"Name".padEnd(l)} ${"Key".padEnd(24)} Created`;console.log(f__default.default.gray(p)),console.log(f__default.default.gray(" "+"-".repeat(p.length-2)));for(let u of c){let d=(u.name||"unnamed").padEnd(l),m=u.maskedKey||u.prefix||`${(u.key||"").slice(0,12)}...`,y=u.createdAt?new Date(u.createdAt).toLocaleDateString():"N/A";console.log(` ${d} ${m.padEnd(24)} ${y}`);}console.log(""),console.log(f__default.default.gray(` ${c.length} key(s) total`)),console.log("");}catch(i){e.fail("Failed to list API keys"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3741
|
-
Error: ${i.message}`)),process.exit(1);}}var O=process.env.VAIF_API_URL||"https://api.vaif.studio";function
|
|
3742
|
-
Error: ${c.message}`)),process.exit(1);}}async function Xe(t){let e=
|
|
3731
|
+
Error: ${i.message}`)),process.exit(1);}}var O=process.env.VAIF_API_URL||"https://api.vaif.studio";function Wt(t,e,o){return t.projectId||e?.projectId||process.env.VAIF_PROJECT_ID||o.projectId||null}function Z(){let t=I();return (!t||!t.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1)),t}async function ee(t){try{return await A(t||"vaif.config.json")}catch{return null}}function te(t,e,o){let n=Wt(t,e,o);return n||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),n}async function We(t,e,o){let n=W__default.default(),r=Z(),s=await ee(o.config),i=te(o,s,r),a=e;if(o.fromFile)try{a=D__default.default.readFileSync(o.fromFile,"utf-8");}catch(c){console.log(f__default.default.red(`Failed to read file: ${o.fromFile}`)),c instanceof Error&&console.log(f__default.default.gray(c.message)),process.exit(1);}a||(console.log(f__default.default.red("No value provided")),console.log(f__default.default.gray("Provide a value as argument or use --from-file <path>")),process.exit(1)),console.log(""),console.log(f__default.default.bold("VAIF Set Secret")),console.log(""),n.start("Checking for existing secret...");try{let c=new URL(`${O}/functions/secrets/project/${i}`);o.envId&&c.searchParams.set("envId",o.envId);let l=await fetch(c.toString(),{headers:{Authorization:`Bearer ${r.token}`}});if(!l.ok)throw new Error(`Failed to check existing secrets: ${await l.text()}`);let u=(await l.json()).find(d=>d.key===t);if(u){n.text=`Updating secret "${t}"...`;let d=await fetch(`${O}/functions/secrets/${u.id}`,{method:"PUT",headers:{Authorization:`Bearer ${r.token}`,"Content-Type":"application/json"},body:JSON.stringify({value:a})});if(!d.ok)throw new Error(`Failed to update secret: ${await d.text()}`);n.succeed(`Updated secret "${t}"`);}else {n.text=`Creating secret "${t}"...`;let d=await fetch(`${O}/functions/secrets`,{method:"POST",headers:{Authorization:`Bearer ${r.token}`,"Content-Type":"application/json"},body:JSON.stringify({projectId:i,envId:o.envId,key:t,value:a})});if(!d.ok)throw new Error(`Failed to create secret: ${await d.text()}`);n.succeed(`Created secret "${t}"`);}console.log("");}catch(c){n.fail("Failed to set secret"),c instanceof Error&&console.log(f__default.default.red(`
|
|
3732
|
+
Error: ${c.message}`)),process.exit(1);}}async function Xe(t){let e=W__default.default(),o=Z(),n=await ee(t.config),r=te(t,n,o);console.log(""),console.log(f__default.default.bold("VAIF Secrets")),console.log(""),e.start("Fetching secrets...");try{let s=new URL(`${O}/functions/secrets/project/${r}`);t.envId&&s.searchParams.set("envId",t.envId);let i=await fetch(s.toString(),{headers:{Authorization:`Bearer ${o.token}`}});if(!i.ok)throw new Error(`Failed to list secrets: ${await i.text()}`);let a=await i.json();if(e.stop(),a.length===0){console.log(f__default.default.yellow("No secrets found")),console.log(f__default.default.gray(`
|
|
3743
3733
|
Create one with: vaif secrets set <name> <value>`));return}let c=Math.max(8,...a.map(p=>p.key.length)),l=` ${"Name".padEnd(c)} Created`;console.log(f__default.default.gray(l)),console.log(f__default.default.gray(" "+"-".repeat(l.length-2)));for(let p of a){let u=p.key.padEnd(c),d=p.createdAt?new Date(p.createdAt).toLocaleDateString():"N/A";console.log(` ${u} ${d}`);}console.log(""),console.log(f__default.default.gray(` ${a.length} secret(s) total`)),console.log(f__default.default.gray(" Values are hidden. Use `vaif secrets get <name>` to reveal.")),console.log("");}catch(s){e.fail("Failed to list secrets"),s instanceof Error&&console.log(f__default.default.red(`
|
|
3744
|
-
Error: ${s.message}`)),process.exit(1);}}async function Qe(t,e){let o=
|
|
3745
|
-
Error: ${i.message}`)),process.exit(1);}}async function Ze(t,e){let o=
|
|
3746
|
-
Error: ${i.message}`)),process.exit(1);}}var et=process.env.VAIF_API_URL||"https://api.vaif.studio";function Qt(t){try{let e=new URL(t);return e.password&&(e.password="****"),e.toString()}catch{return t.replace(/:[^@/]+@/,":****@")}}async function tt(t){let e=
|
|
3747
|
-
Error: ${i.message}`)),process.exit(1);}}var eo=process.env.VAIF_API_URL||"https://api.vaif.studio";async function ot(t){let e=
|
|
3748
|
-
Error: ${i.message}`)),process.exit(1);}}var nt="1.7.
|
|
3734
|
+
Error: ${s.message}`)),process.exit(1);}}async function Qe(t,e){let o=W__default.default(),n=Z(),r=await ee(e.config),s=te(e,r,n);console.log(""),o.start("Fetching secret...");try{let i=new URL(`${O}/functions/secrets/project/${s}`);e.envId&&i.searchParams.set("envId",e.envId);let a=await fetch(i.toString(),{headers:{Authorization:`Bearer ${n.token}`}});if(!a.ok)throw new Error(`Failed to fetch secrets: ${await a.text()}`);let l=(await a.json()).find(d=>d.key===t);l||(o.fail(`Secret "${t}" not found`),process.exit(1));let p=await fetch(`${O}/functions/secrets/${l.id}/value`,{headers:{Authorization:`Bearer ${n.token}`}});if(!p.ok)throw new Error(`Failed to get secret value: ${await p.text()}`);let u=await p.json();o.stop(),console.log(u.value);}catch(i){o.fail("Failed to get secret"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3735
|
+
Error: ${i.message}`)),process.exit(1);}}async function Ze(t,e){let o=W__default.default(),n=Z(),r=await ee(e.config),s=te(e,r,n);console.log(""),console.log(f__default.default.bold("VAIF Delete Secret")),console.log(""),o.start("Finding secret...");try{let i=new URL(`${O}/functions/secrets/project/${s}`);e.envId&&i.searchParams.set("envId",e.envId);let a=await fetch(i.toString(),{headers:{Authorization:`Bearer ${n.token}`}});if(!a.ok)throw new Error(`Failed to fetch secrets: ${await a.text()}`);let l=(await a.json()).find(u=>u.key===t);l||(o.fail(`Secret "${t}" not found`),process.exit(1)),o.text=`Deleting secret "${t}"...`;let p=await fetch(`${O}/functions/secrets/${l.id}`,{method:"DELETE",headers:{Authorization:`Bearer ${n.token}`}});if(!p.ok)throw new Error(`Failed to delete secret: ${await p.text()}`);o.succeed(`Deleted secret "${t}"`),console.log("");}catch(i){o.fail("Failed to delete secret"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3736
|
+
Error: ${i.message}`)),process.exit(1);}}var et=process.env.VAIF_API_URL||"https://api.vaif.studio";function Qt(t){try{let e=new URL(t);return e.password&&(e.password="****"),e.toString()}catch{return t.replace(/:[^@/]+@/,":****@")}}async function tt(t){let e=W__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),e.start("Fetching project info...");try{let i=await fetch(`${et}/v1/projects/${s}`,{headers:{Authorization:`Bearer ${o.token}`}});if(!i.ok){let p=await i.text();throw new Error(`Failed to fetch project: ${p}`)}let a=await i.json();e.stop(),console.log(""),console.log(f__default.default.bold("VAIF Project Info")),console.log("");let c=16,l=(p,u)=>{console.log(` ${f__default.default.gray(p.padEnd(c))} ${u}`);};l("Name:",f__default.default.white(a.name||"N/A")),l("Project ID:",f__default.default.white(s)),l("Region:",f__default.default.white(a.region||"us-east-1")),l("Plan:",f__default.default.white(a.plan||a.tier||"free")),l("Created:",f__default.default.white(a.createdAt?new Date(a.createdAt).toLocaleDateString():"N/A")),console.log(""),l("API URL:",f__default.default.cyan(a.apiUrl||`${et}/v1`)),l("WS URL:",f__default.default.cyan(a.wsUrl||a.realtimeUrl||"N/A")),l("DB URL:",f__default.default.cyan(a.databaseUrl?Qt(a.databaseUrl):"N/A")),l("Storage URL:",f__default.default.cyan(a.storageUrl||"N/A")),console.log("");}catch(i){e.fail("Failed to fetch project info"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3737
|
+
Error: ${i.message}`)),process.exit(1);}}var eo=process.env.VAIF_API_URL||"https://api.vaif.studio";async function ot(t){let e=W__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),e.start("Fetching project status...");try{let i=await fetch(`${eo}/v1/projects/${s}?include=tables,functions,storage,connections`,{headers:{Authorization:`Bearer ${o.token}`}});if(!i.ok){let y=await i.text();throw new Error(`Failed to fetch project status: ${y}`)}let a=await i.json();e.stop(),console.log(""),console.log(f__default.default.bold("VAIF Project Status")),console.log("");let c=22,l=(y,L)=>{console.log(` ${f__default.default.gray(y.padEnd(c))} ${L}`);};l("Project:",f__default.default.white(a.name||s)),l("Plan:",f__default.default.white(a.plan||a.tier||"free")),console.log(""),console.log(f__default.default.gray(" --- Resources ---")),console.log("");let p=a.tableCount??a.tables?.length??"N/A",u=a.functionCount??a.functions?.length??"N/A",d=a.bucketCount??a.storage?.buckets?.length??"N/A",m=a.activeConnections??a.connections??"N/A";l("Tables:",f__default.default.white(String(p))),l("Functions:",f__default.default.white(String(u))),l("Storage Buckets:",f__default.default.white(String(d))),l("Active Connections:",f__default.default.white(String(m))),a.usage&&(console.log(""),console.log(f__default.default.gray(" --- Usage ---")),console.log(""),a.usage.dbSize&&l("Database Size:",f__default.default.white(a.usage.dbSize)),a.usage.storageSize&&l("Storage Size:",f__default.default.white(a.usage.storageSize)),a.usage.bandwidth&&l("Bandwidth:",f__default.default.white(a.usage.bandwidth)),a.usage.functionInvocations!=null&&l("Function Invocations:",f__default.default.white(String(a.usage.functionInvocations)))),console.log("");}catch(i){e.fail("Failed to fetch project status"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3738
|
+
Error: ${i.message}`)),process.exit(1);}}var nt="1.7.4",fe=f__default.default.hex("#00f0ff"),ge=f__default.default.hex("#7b61ff"),me=f__default.default.hex("#ff3dff"),he=f__default.default.hex("#00ff9d"),S=f__default.default.hex("#555570"),z=f__default.default.hex("#00f0ff");function to(){console.log(""),console.log(fe(" \u2566 \u2566")+ge("\u2554\u2550\u2557\u2566")+me("\u2554\u2550\u2557 ")+he("\u2554\u2550\u2557\u2566 \u2566")),console.log(fe(" \u255A\u2557\u2554\u255D")+ge("\u2560\u2550\u2563\u2551")+me("\u2560\u2563 ")+he("\u2551 \u2551 \u2551")),console.log(fe(" \u255A\u255D ")+ge("\u2569 \u2569\u2569")+me("\u255A ")+he("\u255A\u2550\u255D\u2569\u2550\u255D\u2569")),console.log(""),console.log(S(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),console.log(z(" VAIF Studio CLI")+S(` v${nt}`)),console.log(S(" Build full-stack apps at lightning speed")),console.log(S(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),console.log(""),console.log(f__default.default.bold(" Quick Start")),console.log(S(" $ ")+z("vaif login")+S(" Authenticate")),console.log(S(" $ ")+z("vaif init -t react-spa")+S(" Scaffold project")),console.log(S(" $ ")+z("vaif db push")+S(" Push migrations")),console.log(S(" $ ")+z("vaif generate")+S(" Generate types")),console.log(S(" $ ")+z("vaif functions deploy")+S(" Deploy functions")),console.log(""),console.log(f__default.default.bold(" Categories")),console.log(S(" auth ")+f__default.default.white("login, logout, whoami")),console.log(S(" project ")+f__default.default.white("init, templates, info, status")),console.log(S(" schema ")+f__default.default.white("pull, push, generate")),console.log(S(" database ")+f__default.default.white("db push, db pull, db seed, db reset")),console.log(S(" deploy ")+f__default.default.white("functions deploy, functions list")),console.log(S(" security ")+f__default.default.white("keys, secrets")),console.log(""),console.log(S(" Run ")+z("vaif <command> --help")+S(" for details")),console.log(S(" Docs: ")+f__default.default.underline("https://docs.vaif.studio")),console.log("");}commander.program.name("vaif").description("VAIF CLI - Type generation and development tools").version(nt);commander.program.command("login").description("Authenticate with VAIF (opens browser)").option("-e, --email","Login with email/password instead of browser").option("-p, --project-id <id>","Default project ID").action(we);commander.program.command("logout").description("Log out and remove stored credentials").action(Se);commander.program.command("whoami").description("Show current authenticated user").action(_e);commander.program.command("init").description("Initialize VAIF configuration in your project").option("--typescript","Setup for TypeScript project").option("-f, --force","Overwrite existing config").option("-t, --template <name>","Scaffold from a template (run vaif templates for list)").option("--features <features>","Comma-separated features to include: auth,database,realtime,storage,functions").option("--add-features <features>","Add features to an existing project (requires --template)").action(je);commander.program.command("templates").alias("tpl").description("List available project templates").action(Pe);commander.program.command("info").description("Show project information (name, region, URLs)").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").action(tt);commander.program.command("status").description("Show project status (tables, functions, storage, connections)").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").action(ot);commander.program.command("pull").description("Pull database schema from your VAIF project").option("-c, --config <path>","Config file path","vaif.config.json").option("-o, --output <path>","Output file path","vaif.schema.json").option("-s, --schema <name>","Schema name","public").option("-p, --project-id <id>","Project ID (overrides config)").action(Ce);commander.program.command("push").description("Push local schema changes to your VAIF project").option("-c, --config <path>","Config file path","vaif.config.json").option("-s, --schema <path>","Schema file path","vaif.schema.json").option("-p, --project-id <id>","Project ID (overrides config)").option("--dry-run","Preview changes without applying").option("-f, --force","Apply changes without confirmation").action(Le);commander.program.command("generate").alias("gen").description("Generate TypeScript types from your database schema").option("-c, --connection <url>","Database connection string").option("-o, --output <path>","Output file path","./src/types/database.ts").option("--schema <name>","Schema name","public").option("--config <path>","Config file path","vaif.config.json").option("--dry-run","Preview generated types without writing").action(xe);var at=commander.program.command("functions").alias("fn").description("Manage serverless functions");at.command("deploy").description("Deploy functions to your VAIF project").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID").option("-n, --name <name>","Function name filter").option("-r, --runtime <runtime>","Runtime (nodejs, typescript, python)").option("--entrypoint <file>","Specific entrypoint file").option("--dry-run","Preview deployment without deploying").action(ke);at.command("list").alias("ls").description("List deployed functions").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID").action($e);var oe=commander.program.command("db").description("Database management commands");oe.command("push").description("Push local Drizzle migrations to VAIF project").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-d, --dir <path>","Migrations directory","./drizzle").option("--dry-run","Preview without applying").action(Ke);oe.command("pull").description("Pull schema from VAIF project").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-o, --output <path>","Output file","vaif.schema.json").action(ze);oe.command("seed").description("Seed your database with test data").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-f, --file <path>","Specific seed file").option("-t, --table <name>","Seed specific table only").option("--truncate","Truncate tables before seeding").option("--dry-run","Preview seeding without inserting data").action(Me);oe.command("reset").description("Reset database (drop all tables and data)").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-f, --force","Confirm reset (required)").action(Be);var it=commander.program.command("keys").description("Manage API keys");it.command("generate").description("Generate a new API key").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-n, --name <name>","Key name").action(Je);it.command("list").alias("ls").description("List API keys").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").action(He);var ne=commander.program.command("secrets").alias("sec").description("Manage function secrets");ne.command("set <name> [value]").description("Create or update a secret").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID or name").option("--from-file <path>","Read secret value from a file").action(We);ne.command("list").alias("ls").description("List all secrets (names only)").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID or name").action(Xe);ne.command("get <name>").description("Reveal a secret value").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID or name").action(Qe);ne.command("delete <name>").description("Delete a secret").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID or name").action(Ze);process.argv.slice(2).length||(to(),process.exit(0));commander.program.parse(process.argv);
|