@vaiftech/cli 1.7.3 → 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 CHANGED
@@ -3,7 +3,7 @@
3
3
  [![npm version](https://img.shields.io/npm/v/@vaiftech/cli)](https://www.npmjs.com/package/@vaiftech/cli)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
- Command-line tools for [VAIF Studio](https://vaif.studio) (v1.7.3) — scaffold full projects from templates with feature selection, browser-based authentication, manage schemas, deploy functions, generate TypeScript types, and more.
6
+ Command-line tools for [VAIF Studio](https://vaif.studio) (v1.7.4) — scaffold full projects from templates with feature selection, browser-based authentication, manage schemas, deploy functions, generate TypeScript types, and more.
7
7
 
8
8
  ## Installation
9
9
 
@@ -6,7 +6,7 @@ Timed out waiting for browser authentication.`)),console.log(c.gray("Try again o
6
6
  No email provided. Login cancelled.`)),process.exit(1));let n=await te(c.cyan(" Password: "));(!n||n.trim()==="")&&(console.log(c.red(`
7
7
  No password provided. Login cancelled.`)),process.exit(1));let e=P("Authenticating...").start();try{let r=await fetch(`${w}/auth/cli/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:t.trim(),password:n})}),o=await r.json();(!r.ok||!o.ok)&&(e.fail("Login failed"),console.log(c.red(`
8
8
  ${o.message||"Invalid email or password."}`)),process.exit(1));let l={token:o.accessToken,email:o.user?.email,projectId:a,expiresAt:new Date(Date.now()+o.expiresIn*1e3).toISOString()};B(l),e.succeed("Logged in successfully"),console.log(""),o.user?.email&&console.log(c.green(` Authenticated as: ${o.user.email}`)),console.log(c.gray(` Config saved to: ${I}`)),console.log("");}catch{e.fail("Failed to connect to VAIF API"),console.log(c.red(`
9
- Could not connect to VAIF API. Please try again later.`)),process.exit(1);}}async function Ne(a){console.log(""),console.log(c.bold("Welcome to VAIF CLI")),console.log(c.gray("Authenticate to access your VAIF projects")),console.log(""),a.email?await re(a.projectId):await oe(a.projectId),console.log(c.gray("You can now use VAIF CLI commands like:")),console.log(c.gray(" vaif pull - Pull remote schema")),console.log(c.gray(" vaif push - Push schema changes")),console.log(c.gray(" vaif generate - Generate TypeScript types")),console.log("");}async function Le(){y.existsSync(I)?(y.unlinkSync(I),console.log(c.green("Logged out successfully"))):console.log(c.yellow("Not currently logged in"));}async function Ue(){let a=R();(!a||!a.token)&&(console.log(c.yellow("Not logged in")),console.log(c.gray("Run `vaif login` to authenticate")),process.exit(1));let t=P("Checking authentication...").start(),{valid:n,email:e}=await ie(a.token);n||(t.fail("Session expired"),console.log(c.yellow(`
9
+ Could not connect to VAIF API. Please try again later.`)),process.exit(1);}}async function Le(a){console.log(""),console.log(c.bold("Welcome to VAIF CLI")),console.log(c.gray("Authenticate to access your VAIF projects")),console.log(""),a.email?await re(a.projectId):await oe(a.projectId),console.log(c.gray("You can now use VAIF CLI commands like:")),console.log(c.gray(" vaif pull - Pull remote schema")),console.log(c.gray(" vaif push - Push schema changes")),console.log(c.gray(" vaif generate - Generate TypeScript types")),console.log("");}async function Ne(){y.existsSync(I)?(y.unlinkSync(I),console.log(c.green("Logged out successfully"))):console.log(c.yellow("Not currently logged in"));}async function Ue(){let a=R();(!a||!a.token)&&(console.log(c.yellow("Not logged in")),console.log(c.gray("Run `vaif login` to authenticate")),process.exit(1));let t=P("Checking authentication...").start(),{valid:n,email:e}=await ie(a.token);n||(t.fail("Session expired"),console.log(c.yellow(`
10
10
  Your session has expired. Please login again.`)),process.exit(1)),t.succeed("Authenticated"),console.log(""),console.log(c.green(` Email: ${e||a.email||"Unknown"}`)),a.projectId&&console.log(c.green(` Project: ${a.projectId}`)),console.log("");}var ue=process.env.VAIF_API_URL||"https://api.vaif.studio";async function de(a,t){let n=await fetch(`${ue}/schema-engine/introspect/${t}`,{headers:{Authorization:`Bearer ${a}`,"Content-Type":"application/json"}});if(!n.ok){let u=await n.text();throw new Error(`API introspection failed: ${u}`)}let e=await n.json();if(!e.ok||!e.schemaExists)throw new Error("Project schema does not exist yet. Push a migration first with `vaif db push`.");let r=new Map,o=[];for(let u of e.tables){let s=u.columns.map(i=>({column_name:i.name,data_type:i.type,is_nullable:i.nullable?"YES":"NO",column_default:i.default,udt_name:i.type,is_identity:i.primaryKey&&i.default?.includes("gen_random_uuid")?"YES":"NO",character_maximum_length:null,numeric_precision:null,numeric_scale:null}));r.set(u.name,s);for(let i of u.foreignKeys)o.push({constraint_name:i.constraintName,table_name:u.name,column_name:i.columnName,foreign_table_name:i.refTable,foreign_column_name:i.refColumn});}return {tables:r,enums:new Map,foreignKeys:o}}async function pe(a,t){let n=await a.query(`
11
11
  SELECT table_name, table_type
12
12
  FROM information_schema.tables
@@ -53,9 +53,9 @@ Your session has expired. Please login again.`)),process.exit(1)),t.succeed("Aut
53
53
  JOIN pg_namespace n ON n.oid = t.typnamespace
54
54
  WHERE n.nspname = $1
55
55
  ORDER BY t.typname, e.enumsortorder
56
- `,[t]),l=new Map;for(let s of n.rows)l.set(s.table_name,[]);for(let s of e.rows){let i=l.get(s.table_name);i&&i.push(s);}let u=new Map;for(let s of o.rows){let i=u.get(s.enum_name)||[];i.push(s.enum_value),u.set(s.enum_name,i);}return {tables:l,enums:u,foreignKeys:r.rows}}var N={smallint:"number",integer:"number",bigint:"string",int2:"number",int4:"number",int8:"string",decimal:"string",numeric:"string",real:"number",float4:"number",float8:"number","double precision":"number",money:"string",boolean:"boolean",bool:"boolean",text:"string",varchar:"string",char:"string",character:"string","character varying":"string",name:"string",citext:"string",date:"string",time:"string",timetz:"string","time without time zone":"string","time with time zone":"string",timestamp:"string",timestamptz:"string","timestamp without time zone":"string","timestamp with time zone":"string",interval:"string",bytea:"Buffer",uuid:"string",json:"unknown",jsonb:"unknown",inet:"string",cidr:"string",macaddr:"string",macaddr8:"string",point:"{ x: number; y: number }",line:"string",lseg:"string",box:"string",path:"string",polygon:"string",circle:"string",ARRAY:"unknown[]"};function me(a,t){let{data_type:n,udt_name:e,is_nullable:r}=a;if(t.has(e)){let u=t.get(e).map(s=>`"${s}"`).join(" | ");return r==="YES"?`(${u}) | null`:u}if(n==="ARRAY"){let l=e.replace(/^_/,"");if(t.has(l)){let i=t.get(l).map(p=>`"${p}"`).join(" | ");return r==="YES"?`(${i})[] | null`:`(${i})[]`}let u=N[l]||"unknown";return r==="YES"?`${u}[] | null`:`${u}[]`}let o=N[n]||N[e]||"unknown";return r==="YES"&&(o=`${o} | null`),o}function L(a){return a.split(/[_\-\s]+/).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("")}function fe(a,t){let n=L(a),e=t.map(r=>` | "${r}"`).join(`
56
+ `,[t]),l=new Map;for(let s of n.rows)l.set(s.table_name,[]);for(let s of e.rows){let i=l.get(s.table_name);i&&i.push(s);}let u=new Map;for(let s of o.rows){let i=u.get(s.enum_name)||[];i.push(s.enum_value),u.set(s.enum_name,i);}return {tables:l,enums:u,foreignKeys:r.rows}}var L={smallint:"number",integer:"number",bigint:"string",int2:"number",int4:"number",int8:"string",decimal:"string",numeric:"string",real:"number",float4:"number",float8:"number","double precision":"number",money:"string",boolean:"boolean",bool:"boolean",text:"string",varchar:"string",char:"string",character:"string","character varying":"string",name:"string",citext:"string",date:"string",time:"string",timetz:"string","time without time zone":"string","time with time zone":"string",timestamp:"string",timestamptz:"string","timestamp without time zone":"string","timestamp with time zone":"string",interval:"string",bytea:"Buffer",uuid:"string",json:"unknown",jsonb:"unknown",inet:"string",cidr:"string",macaddr:"string",macaddr8:"string",point:"{ x: number; y: number }",line:"string",lseg:"string",box:"string",path:"string",polygon:"string",circle:"string",ARRAY:"unknown[]"};function me(a,t){let{data_type:n,udt_name:e,is_nullable:r}=a;if(t.has(e)){let u=t.get(e).map(s=>`"${s}"`).join(" | ");return r==="YES"?`(${u}) | null`:u}if(n==="ARRAY"){let l=e.replace(/^_/,"");if(t.has(l)){let i=t.get(l).map(p=>`"${p}"`).join(" | ");return r==="YES"?`(${i})[] | null`:`(${i})[]`}let u=L[l]||"unknown";return r==="YES"?`${u}[] | null`:`${u}[]`}let o=L[n]||L[e]||"unknown";return r==="YES"&&(o=`${o} | null`),o}function N(a){return a.split(/[_\-\s]+/).map(t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).join("")}function fe(a,t){let n=N(a),e=t.map(r=>` | "${r}"`).join(`
57
57
  `);return `export type ${n} =
58
- ${e};`}function ge(a,t,n){let e=L(a),r=[],o=[],l=[];for(let p of t){let g=me(p,n),m=p.column_name,h=p.column_default!==null||p.is_identity==="YES",A=p.is_nullable==="YES";r.push(` ${m}: ${g};`),h||p.column_name==="id"?o.push(` ${m}?: ${g.replace(" | null","")} | null;`):A?o.push(` ${m}?: ${g};`):o.push(` ${m}: ${g.replace(" | null","")};`),l.push(` ${m}?: ${g.replace(" | null","")} | null;`);}let u=`export interface ${e} {
58
+ ${e};`}function ge(a,t,n){let e=N(a),r=[],o=[],l=[];for(let p of t){let g=me(p,n),m=p.column_name,h=p.column_default!==null||p.is_identity==="YES",A=p.is_nullable==="YES";r.push(` ${m}: ${g};`),h||p.column_name==="id"?o.push(` ${m}?: ${g.replace(" | null","")} | null;`):A?o.push(` ${m}?: ${g};`):o.push(` ${m}: ${g.replace(" | null","")};`),l.push(` ${m}?: ${g.replace(" | null","")} | null;`);}let u=`export interface ${e} {
59
59
  ${r.join(`
60
60
  `)}
61
61
  }`,s=`export interface ${e}Insert {
@@ -64,7 +64,7 @@ ${o.join(`
64
64
  }`,i=`export interface ${e}Update {
65
65
  ${l.join(`
66
66
  `)}
67
- }`;return {base:u,insert:s,update:i}}function he(a,t,n){let e=["/**"," * 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(t.size>0){e.push("// ============ ENUMS ============"),e.push("");for(let[o,l]of t)e.push(fe(o,l)),e.push("");}e.push("// ============ TABLES ============"),e.push("");let r=[];for(let[o,l]of a){let{base:u,insert:s,update:i}=ge(o,l,t);r.push(o),e.push(u),e.push(""),e.push(s),e.push(""),e.push(i),e.push("");}e.push("// ============ DATABASE SCHEMA ============"),e.push(""),e.push("export interface Database {");for(let o of r){let l=L(o);e.push(` ${o}: {`),e.push(` Row: ${l};`),e.push(` Insert: ${l}Insert;`),e.push(` Update: ${l}Update;`),e.push(" };");}return e.push("}"),e.push(""),e.push("export type TableName = keyof Database;"),e.push(""),e.push("// ============ HELPER TYPES ============"),e.push(""),e.push('export type Row<T extends TableName> = Database[T]["Row"];'),e.push('export type Insert<T extends TableName> = Database[T]["Insert"];'),e.push('export type Update<T extends TableName> = Database[T]["Update"];'),e.push(""),e.join(`
67
+ }`;return {base:u,insert:s,update:i}}function he(a,t,n){let e=["/**"," * 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(t.size>0){e.push("// ============ ENUMS ============"),e.push("");for(let[o,l]of t)e.push(fe(o,l)),e.push("");}e.push("// ============ TABLES ============"),e.push("");let r=[];for(let[o,l]of a){let{base:u,insert:s,update:i}=ge(o,l,t);r.push(o),e.push(u),e.push(""),e.push(s),e.push(""),e.push(i),e.push("");}e.push("// ============ DATABASE SCHEMA ============"),e.push(""),e.push("export interface Database {");for(let o of r){let l=N(o);e.push(` ${o}: {`),e.push(` Row: ${l};`),e.push(` Insert: ${l}Insert;`),e.push(` Update: ${l}Update;`),e.push(" };");}return e.push("}"),e.push(""),e.push("export type TableName = keyof Database;"),e.push(""),e.push("// ============ HELPER TYPES ============"),e.push(""),e.push('export type Row<T extends TableName> = Database[T]["Row"];'),e.push('export type Insert<T extends TableName> = Database[T]["Insert"];'),e.push('export type Update<T extends TableName> = Database[T]["Update"];'),e.push(""),e.join(`
68
68
  `)}async function Ye(a){let t=P("Loading configuration...").start();try{let n=await K(a.config),e=a.connection||n?.database?.url||process.env.DATABASE_URL,r=e&&!e.includes("${"),o,l,u;if(r){t.text="Connecting to database...";let m=new se.Client({connectionString:e});await m.connect(),t.text="Introspecting schema...",{tables:o,enums:l,foreignKeys:u}=await pe(m,a.schema),await m.end();}else {let m=R();(!m||!m.token)&&(t.fail("No database connection and not logged in"),console.log(c.yellow(`
69
69
  Either:`)),console.log(c.gray(" 1. Run `vaif login` to authenticate (no DATABASE_URL needed)")),console.log(c.gray(" 2. Set DATABASE_URL in your .env file")),console.log(c.gray(" 3. Pass --connection postgresql://user:pass@host:5432/db")),process.exit(1));let h=n?.projectId||process.env.VAIF_PROJECT_ID||m.projectId;h||(t.fail("No project ID specified"),console.log(c.yellow(`
70
70
  Set projectId in vaif.config.json or use VAIF_PROJECT_ID env var.`)),process.exit(1)),t.text="Introspecting schema via API...",{tables:o,enums:l,foreignKeys:u}=await de(m.token,h);}if(o.size===0){t.warn("No tables found"),console.log(c.yellow(`
@@ -334,12 +334,12 @@ export default function LoginPage() {
334
334
  setLoading(true);
335
335
  setError(null);
336
336
 
337
- const { error } = await vaif.auth.signInWithPassword({ email, password });
338
- if (error) {
339
- setError(error.message);
340
- setLoading(false);
341
- } else {
337
+ try {
338
+ await vaif.auth.login(email, password);
342
339
  router.push("/dashboard");
340
+ } catch (err: any) {
341
+ setError(err.message || "Login failed");
342
+ setLoading(false);
343
343
  }
344
344
  }
345
345
 
@@ -381,12 +381,12 @@ export default function SignupPage() {
381
381
  setLoading(true);
382
382
  setError(null);
383
383
 
384
- const { error } = await vaif.auth.signUp({ email, password });
385
- if (error) {
386
- setError(error.message);
387
- setLoading(false);
388
- } else {
384
+ try {
385
+ await vaif.auth.signUp(email, password);
389
386
  router.push("/");
387
+ } catch (err: any) {
388
+ setError(err.message || "Sign up failed");
389
+ setLoading(false);
390
390
  }
391
391
  }
392
392
 
@@ -793,12 +793,12 @@ export default function Login() {
793
793
  setLoading(true);
794
794
  setError(null);
795
795
 
796
- const { error } = await vaif.auth.signInWithPassword({ email, password });
797
- if (error) {
798
- setError(error.message);
799
- setLoading(false);
800
- } else {
796
+ try {
797
+ await vaif.auth.login(email, password);
801
798
  navigate("/");
799
+ } catch (err: any) {
800
+ setError(err.message || "Login failed");
801
+ setLoading(false);
802
802
  }
803
803
  }
804
804
 
@@ -838,12 +838,12 @@ export default function Signup() {
838
838
  setLoading(true);
839
839
  setError(null);
840
840
 
841
- const { error } = await vaif.auth.signUp({ email, password });
842
- if (error) {
843
- setError(error.message);
844
- setLoading(false);
845
- } else {
841
+ try {
842
+ await vaif.auth.signUp(email, password);
846
843
  navigate("/");
844
+ } catch (err: any) {
845
+ setError(err.message || "Sign up failed");
846
+ setLoading(false);
847
847
  }
848
848
  }
849
849
 
@@ -1457,10 +1457,14 @@ export default function LoginScreen() {
1457
1457
 
1458
1458
  async function handleLogin() {
1459
1459
  setLoading(true);
1460
- const { error } = await vaif.auth.signInWithPassword({ email, password });
1461
- setLoading(false);
1462
- if (error) Alert.alert("Error", error.message);
1463
- else router.replace("/");
1460
+ try {
1461
+ await vaif.auth.login(email, password);
1462
+ router.replace("/");
1463
+ } catch (err: any) {
1464
+ Alert.alert("Error", err.message || "Login failed");
1465
+ } finally {
1466
+ setLoading(false);
1467
+ }
1464
1468
  }
1465
1469
 
1466
1470
  return (
@@ -1495,10 +1499,14 @@ export default function SignupScreen() {
1495
1499
 
1496
1500
  async function handleSignup() {
1497
1501
  setLoading(true);
1498
- const { error } = await vaif.auth.signUp({ email, password });
1499
- setLoading(false);
1500
- if (error) Alert.alert("Error", error.message);
1501
- else router.replace("/");
1502
+ try {
1503
+ await vaif.auth.signUp(email, password);
1504
+ router.replace("/");
1505
+ } catch (err: any) {
1506
+ Alert.alert("Error", err.message || "Sign up failed");
1507
+ } finally {
1508
+ setLoading(false);
1509
+ }
1502
1510
  }
1503
1511
 
1504
1512
  return (
@@ -1845,7 +1853,7 @@ class _LoginScreenState extends State<LoginScreen> {
1845
1853
  setState(() { _loading = true; _error = null; });
1846
1854
 
1847
1855
  try {
1848
- await vaif.auth.signInWithPassword(
1856
+ await vaif.auth.login(
1849
1857
  email: _emailController.text,
1850
1858
  password: _passwordController.text,
1851
1859
  );
@@ -3695,4 +3703,4 @@ Use --force to overwrite existing configuration.`)),process.exit(1));try{if(y.wr
3695
3703
  DATABASE_URL=postgresql://user:password@localhost:5432/database
3696
3704
  VAIF_API_KEY=your-api-key
3697
3705
  `,"utf-8"),console.log(c.gray("Created .env.example"))),a.typescript){let r=U.resolve("src/types");y.existsSync(r)||(y.mkdirSync(r,{recursive:!0}),console.log(c.gray("Created src/types directory")));}console.log(""),console.log(c.green("VAIF initialized successfully!")),console.log(""),console.log(c.gray("Next steps:")),console.log(c.gray(" 1. Update vaif.config.json with your project ID")),console.log(c.gray(" 2. Set DATABASE_URL in your environment")),console.log(c.gray(" 3. Run: npx vaif generate")),console.log("");}}catch(e){t.fail("Failed to initialize"),e instanceof Error&&console.error(c.red(`
3698
- Error: ${e.message}`)),process.exit(1);}}export{K as a,R as b,Ne as c,Le as d,Ue as e,Ye as f,Qe as g,rt as h};
3706
+ Error: ${e.message}`)),process.exit(1);}}export{K as a,R as b,Le as c,Ne as d,Ue as e,Ye as f,Qe as g,rt as h};
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'),H=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 H__default=/*#__PURE__*/_interopDefault(H);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=H__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(`
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=H__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(`
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=H__default.default("Checking authentication...").start(),{valid:o,email:n}=await mt(t.token);o||(e.fail("Session expired"),console.log(f__default.default.yellow(`
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=H__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(`
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(`
@@ -335,12 +335,12 @@ export default function LoginPage() {
335
335
  setLoading(true);
336
336
  setError(null);
337
337
 
338
- const { error } = await vaif.auth.signInWithPassword({ email, password });
339
- if (error) {
340
- setError(error.message);
341
- setLoading(false);
342
- } else {
338
+ try {
339
+ await vaif.auth.login(email, password);
343
340
  router.push("/dashboard");
341
+ } catch (err: any) {
342
+ setError(err.message || "Login failed");
343
+ setLoading(false);
344
344
  }
345
345
  }
346
346
 
@@ -382,12 +382,12 @@ export default function SignupPage() {
382
382
  setLoading(true);
383
383
  setError(null);
384
384
 
385
- const { error } = await vaif.auth.signUp({ email, password });
386
- if (error) {
387
- setError(error.message);
388
- setLoading(false);
389
- } else {
385
+ try {
386
+ await vaif.auth.signUp(email, password);
390
387
  router.push("/");
388
+ } catch (err: any) {
389
+ setError(err.message || "Sign up failed");
390
+ setLoading(false);
391
391
  }
392
392
  }
393
393
 
@@ -794,12 +794,12 @@ export default function Login() {
794
794
  setLoading(true);
795
795
  setError(null);
796
796
 
797
- const { error } = await vaif.auth.signInWithPassword({ email, password });
798
- if (error) {
799
- setError(error.message);
800
- setLoading(false);
801
- } else {
797
+ try {
798
+ await vaif.auth.login(email, password);
802
799
  navigate("/");
800
+ } catch (err: any) {
801
+ setError(err.message || "Login failed");
802
+ setLoading(false);
803
803
  }
804
804
  }
805
805
 
@@ -839,12 +839,12 @@ export default function Signup() {
839
839
  setLoading(true);
840
840
  setError(null);
841
841
 
842
- const { error } = await vaif.auth.signUp({ email, password });
843
- if (error) {
844
- setError(error.message);
845
- setLoading(false);
846
- } else {
842
+ try {
843
+ await vaif.auth.signUp(email, password);
847
844
  navigate("/");
845
+ } catch (err: any) {
846
+ setError(err.message || "Sign up failed");
847
+ setLoading(false);
848
848
  }
849
849
  }
850
850
 
@@ -1458,10 +1458,14 @@ export default function LoginScreen() {
1458
1458
 
1459
1459
  async function handleLogin() {
1460
1460
  setLoading(true);
1461
- const { error } = await vaif.auth.signInWithPassword({ email, password });
1462
- setLoading(false);
1463
- if (error) Alert.alert("Error", error.message);
1464
- else router.replace("/");
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
+ }
1465
1469
  }
1466
1470
 
1467
1471
  return (
@@ -1496,10 +1500,14 @@ export default function SignupScreen() {
1496
1500
 
1497
1501
  async function handleSignup() {
1498
1502
  setLoading(true);
1499
- const { error } = await vaif.auth.signUp({ email, password });
1500
- setLoading(false);
1501
- if (error) Alert.alert("Error", error.message);
1502
- else router.replace("/");
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
+ }
1503
1511
  }
1504
1512
 
1505
1513
  return (
@@ -1846,7 +1854,7 @@ class _LoginScreenState extends State<LoginScreen> {
1846
1854
  setState(() { _loading = true; _error = null; });
1847
1855
 
1848
1856
  try {
1849
- await vaif.auth.signInWithPassword(
1857
+ await vaif.auth.login(
1850
1858
  email: _emailController.text,
1851
1859
  password: _passwordController.text,
1852
1860
  );
@@ -3691,40 +3699,40 @@ Unknown template: ${t}`)),console.log(f__default.default.yellow(`Run 'vaif templ
3691
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)+`
3692
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)+`
3693
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(`
3694
- --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=H__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(`
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(`
3695
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
3696
3704
  DATABASE_URL=postgresql://user:password@localhost:5432/database
3697
3705
  VAIF_API_KEY=your-api-key
3698
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(`
3699
- 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=H__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(`
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(`
3700
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(`
3701
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(`
3702
- 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=H__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(`
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(`
3703
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(`
3704
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(`
3705
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(`
3706
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(`
3707
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(`
3708
- Error: ${c.message}`)),process.exit(1);}}var W=process.env.VAIF_API_URL||"https://api.vaif.studio";async function zt(t,e,o,n){let r=new URL(`${W}/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(`${W}/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(`${W}/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(`${W}/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=H__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(`
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(`
3709
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(`
3710
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(`
3711
- 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=H__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(`
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(`
3712
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(`
3713
- 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=H__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(`
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(`
3714
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(`
3715
3723
  Or specify a file with --file`)),console.log(f__default.default.gray(`
3716
- 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=H__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(`
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(`
3717
3725
  Expected one of:`)),console.log(f__default.default.gray(" - ./drizzle/")),console.log(f__default.default.gray(" - ./migrations/")),console.log(f__default.default.gray(`
3718
- 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=H__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(`
3719
- Error: ${a.message}`)),process.exit(1);}}async function Be(t){let e=H__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(`
3720
- 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=H__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(`
3721
- Error: ${a.message}`)),process.exit(1);}}async function We(t){let e=H__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(`
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(`
3722
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(`
3723
- Error: ${i.message}`)),process.exit(1);}}var O=process.env.VAIF_API_URL||"https://api.vaif.studio";function Ht(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=Ht(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 He(t,e,o){let n=H__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(`
3724
- Error: ${c.message}`)),process.exit(1);}}async function Xe(t){let e=H__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(`
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(`
3725
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(`
3726
- Error: ${s.message}`)),process.exit(1);}}async function Qe(t,e){let o=H__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(`
3727
- Error: ${i.message}`)),process.exit(1);}}async function Ze(t,e){let o=H__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(`
3728
- 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=H__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(`
3729
- Error: ${i.message}`)),process.exit(1);}}var eo=process.env.VAIF_API_URL||"https://api.vaif.studio";async function ot(t){let e=H__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(`
3730
- Error: ${i.message}`)),process.exit(1);}}var nt="1.7.3",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(We);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(He);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);
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);
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import {c,d,e,h,g,f,b,a}from'./chunk-M2UHM7B7.js';import'dotenv/config';import {program}from'commander';import l from'chalk';import C from'fs';import w from'path';import U from'ora';import ze from'readline';var Te=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Le(e,o,t="public"){let i=await fetch(`${Te}/v1/projects/${o}/schema?schema=${t}`,{headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!i.ok){let r=await i.text();throw new Error(`Failed to fetch schema: ${r}`)}return i.json()}async function ie(e){let o=U(),t=b();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let i=e.config||"vaif.config.json",r=null;o.start("Loading configuration...");try{r=await a(i);}catch(s){o.fail("Failed to load config"),console.log(l.red(`
2
+ import {c,d,e,h,g,f,b,a}from'./chunk-CMWHBLLZ.js';import'dotenv/config';import {program}from'commander';import l from'chalk';import C from'fs';import w from'path';import U from'ora';import ze from'readline';var Te=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Le(e,o,t="public"){let i=await fetch(`${Te}/v1/projects/${o}/schema?schema=${t}`,{headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!i.ok){let r=await i.text();throw new Error(`Failed to fetch schema: ${r}`)}return i.json()}async function ie(e){let o=U(),t=b();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let i=e.config||"vaif.config.json",r=null;o.start("Loading configuration...");try{r=await a(i);}catch(s){o.fail("Failed to load config"),console.log(l.red(`
3
3
  Error: ${s}`)),process.exit(1);}r||(o.fail("No configuration found"),console.log(l.yellow("\nRun `vaif init` to create a configuration file.")),process.exit(1));let c=e.projectId||r.projectId||process.env.VAIF_PROJECT_ID||t.projectId;c||(o.fail("No project ID specified"),console.log(l.yellow(`
4
4
  Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1)),o.text="Fetching remote schema...";try{let s=e.schema||r.database?.schema||"public",n=await Le(t.token,c,s);o.succeed("Schema fetched successfully");let a=e.output||w.resolve("vaif.schema.json"),d={$schema:"https://vaif.studio/schemas/schema.json",projectId:c,schema:s,pulledAt:new Date().toISOString(),...n};C.writeFileSync(a,JSON.stringify(d,null,2),"utf-8"),console.log(""),console.log(l.green(`Schema saved to: ${a}`)),console.log(""),console.log(l.gray("Schema summary:")),console.log(l.gray(` Tables: ${(n.tables||[]).length}`)),console.log(l.gray(` Enums: ${(n.enums||[]).length}`)),console.log(l.gray(` Functions: ${(n.functions||[]).length}`)),console.log(""),console.log(l.gray("Next steps:")),console.log(l.gray(" - Run `vaif generate` to generate TypeScript types")),console.log(l.gray(" - Edit the schema and run `vaif push` to deploy changes")),console.log("");}catch(s){o.fail("Failed to fetch schema"),s instanceof Error&&console.log(l.red(`
5
5
  Error: ${s.message}`)),process.exit(1);}}var ce=process.env.VAIF_API_URL||"https://api.vaif.studio";function Be(e){let o=ze.createInterface({input:process.stdin,output:process.stdout});return new Promise(t=>{o.question(e,i=>{o.close(),t(i);});})}async function Je(e,o,t){let i=await fetch(`${ce}/v1/projects/${o}/schema/preview`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify({schema:t})});if(!i.ok){let r=await i.text();throw new Error(`Failed to preview changes: ${r}`)}return i.json()}async function Ke(e,o,t){let i=await fetch(`${ce}/v1/projects/${o}/schema/apply`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify({schema:t})});if(!i.ok){let r=await i.text();throw new Error(`Failed to apply changes: ${r}`)}return i.json()}function Me(e){if(console.log(""),console.log(l.bold("Schema Changes:")),console.log(""),e.added.length===0&&e.modified.length===0&&e.removed.length===0){console.log(l.gray(" No changes detected. Schema is up to date."));return}if(e.added.length>0){console.log(l.green.bold(" + Added:"));for(let o of e.added)console.log(l.green(` + ${o.type}: ${o.name}`));console.log("");}if(e.modified.length>0){console.log(l.yellow.bold(" ~ Modified:"));for(let o of e.modified){console.log(l.yellow(` ~ ${o.type}: ${o.name}`));for(let t of o.changes)console.log(l.gray(` ${t}`));}console.log("");}if(e.removed.length>0){console.log(l.red.bold(" - Removed:"));for(let o of e.removed)console.log(l.red(` - ${o.type}: ${o.name}`));console.log("");}}async function ae(e){let o=U(),t=b();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let i=e.config||"vaif.config.json",r=null;o.start("Loading configuration...");try{r=await a(i);}catch(a){o.fail("Failed to load config"),console.log(l.red(`
@@ -30,4 +30,4 @@ Error: ${c.message}`)),process.exit(1);}}async function Pe(e,o){let t=U(),i=J(),
30
30
  Error: ${s.message}`)),process.exit(1);}}async function xe(e,o){let t=U(),i=J(),r=await K(o.config),c=M(o,r,i);console.log(""),console.log(l.bold("VAIF Delete Secret")),console.log(""),t.start("Finding secret...");try{let s=new URL(`${N}/functions/secrets/project/${c}`);o.envId&&s.searchParams.set("envId",o.envId);let n=await fetch(s.toString(),{headers:{Authorization:`Bearer ${i.token}`}});if(!n.ok)throw new Error(`Failed to fetch secrets: ${await n.text()}`);let d=(await n.json()).find(f=>f.key===e);d||(t.fail(`Secret "${e}" not found`),process.exit(1)),t.text=`Deleting secret "${e}"...`;let p=await fetch(`${N}/functions/secrets/${d.id}`,{method:"DELETE",headers:{Authorization:`Bearer ${i.token}`}});if(!p.ok)throw new Error(`Failed to delete secret: ${await p.text()}`);t.succeed(`Deleted secret "${e}"`),console.log("");}catch(s){t.fail("Failed to delete secret"),s instanceof Error&&console.log(l.red(`
31
31
  Error: ${s.message}`)),process.exit(1);}}var Fe=process.env.VAIF_API_URL||"https://api.vaif.studio";function oo(e){try{let o=new URL(e);return o.password&&(o.password="****"),o.toString()}catch{return e.replace(/:[^@/]+@/,":****@")}}async function ke(e){let o=U(),t=b();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let i=e.config||"vaif.config.json",r=null;try{r=await a(i);}catch{}let c=e.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;c||(console.log(l.red("No project ID specified")),console.log(l.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),o.start("Fetching project info...");try{let s=await fetch(`${Fe}/v1/projects/${c}`,{headers:{Authorization:`Bearer ${t.token}`}});if(!s.ok){let p=await s.text();throw new Error(`Failed to fetch project: ${p}`)}let n=await s.json();o.stop(),console.log(""),console.log(l.bold("VAIF Project Info")),console.log("");let a=16,d=(p,f)=>{console.log(` ${l.gray(p.padEnd(a))} ${f}`);};d("Name:",l.white(n.name||"N/A")),d("Project ID:",l.white(c)),d("Region:",l.white(n.region||"us-east-1")),d("Plan:",l.white(n.plan||n.tier||"free")),d("Created:",l.white(n.createdAt?new Date(n.createdAt).toLocaleDateString():"N/A")),console.log(""),d("API URL:",l.cyan(n.apiUrl||`${Fe}/v1`)),d("WS URL:",l.cyan(n.wsUrl||n.realtimeUrl||"N/A")),d("DB URL:",l.cyan(n.databaseUrl?oo(n.databaseUrl):"N/A")),d("Storage URL:",l.cyan(n.storageUrl||"N/A")),console.log("");}catch(s){o.fail("Failed to fetch project info"),s instanceof Error&&console.log(l.red(`
32
32
  Error: ${s.message}`)),process.exit(1);}}var no=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Ce(e){let o=U(),t=b();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let i=e.config||"vaif.config.json",r=null;try{r=await a(i);}catch{}let c=e.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;c||(console.log(l.red("No project ID specified")),console.log(l.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),o.start("Fetching project status...");try{let s=await fetch(`${no}/v1/projects/${c}?include=tables,functions,storage,connections`,{headers:{Authorization:`Bearer ${t.token}`}});if(!s.ok){let y=await s.text();throw new Error(`Failed to fetch project status: ${y}`)}let n=await s.json();o.stop(),console.log(""),console.log(l.bold("VAIF Project Status")),console.log("");let a=22,d=(y,D)=>{console.log(` ${l.gray(y.padEnd(a))} ${D}`);};d("Project:",l.white(n.name||c)),d("Plan:",l.white(n.plan||n.tier||"free")),console.log(""),console.log(l.gray(" --- Resources ---")),console.log("");let p=n.tableCount??n.tables?.length??"N/A",f=n.functionCount??n.functions?.length??"N/A",g=n.bucketCount??n.storage?.buckets?.length??"N/A",h=n.activeConnections??n.connections??"N/A";d("Tables:",l.white(String(p))),d("Functions:",l.white(String(f))),d("Storage Buckets:",l.white(String(g))),d("Active Connections:",l.white(String(h))),n.usage&&(console.log(""),console.log(l.gray(" --- Usage ---")),console.log(""),n.usage.dbSize&&d("Database Size:",l.white(n.usage.dbSize)),n.usage.storageSize&&d("Storage Size:",l.white(n.usage.storageSize)),n.usage.bandwidth&&d("Bandwidth:",l.white(n.usage.bandwidth)),n.usage.functionInvocations!=null&&d("Function Invocations:",l.white(String(n.usage.functionInvocations)))),console.log("");}catch(s){o.fail("Failed to fetch project status"),s instanceof Error&&console.log(l.red(`
33
- Error: ${s.message}`)),process.exit(1);}}var De="1.7.3",Q=l.hex("#00f0ff"),Y=l.hex("#7b61ff"),H=l.hex("#ff3dff"),X=l.hex("#00ff9d"),j=l.hex("#555570"),O=l.hex("#00f0ff");function so(){console.log(""),console.log(Q(" \u2566 \u2566")+Y("\u2554\u2550\u2557\u2566")+H("\u2554\u2550\u2557 ")+X("\u2554\u2550\u2557\u2566 \u2566")),console.log(Q(" \u255A\u2557\u2554\u255D")+Y("\u2560\u2550\u2563\u2551")+H("\u2560\u2563 ")+X("\u2551 \u2551 \u2551")),console.log(Q(" \u255A\u255D ")+Y("\u2569 \u2569\u2569")+H("\u255A ")+X("\u255A\u2550\u255D\u2569\u2550\u255D\u2569")),console.log(""),console.log(j(" \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(O(" VAIF Studio CLI")+j(` v${De}`)),console.log(j(" Build full-stack apps at lightning speed")),console.log(j(" \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(l.bold(" Quick Start")),console.log(j(" $ ")+O("vaif login")+j(" Authenticate")),console.log(j(" $ ")+O("vaif init -t react-spa")+j(" Scaffold project")),console.log(j(" $ ")+O("vaif db push")+j(" Push migrations")),console.log(j(" $ ")+O("vaif generate")+j(" Generate types")),console.log(j(" $ ")+O("vaif functions deploy")+j(" Deploy functions")),console.log(""),console.log(l.bold(" Categories")),console.log(j(" auth ")+l.white("login, logout, whoami")),console.log(j(" project ")+l.white("init, templates, info, status")),console.log(j(" schema ")+l.white("pull, push, generate")),console.log(j(" database ")+l.white("db push, db pull, db seed, db reset")),console.log(j(" deploy ")+l.white("functions deploy, functions list")),console.log(j(" security ")+l.white("keys, secrets")),console.log(""),console.log(j(" Run ")+O("vaif <command> --help")+j(" for details")),console.log(j(" Docs: ")+l.underline("https://docs.vaif.studio")),console.log("");}program.name("vaif").description("VAIF CLI - Type generation and development tools").version(De);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(c);program.command("logout").description("Log out and remove stored credentials").action(d);program.command("whoami").description("Show current authenticated user").action(e);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(h);program.command("templates").alias("tpl").description("List available project templates").action(g);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(ke);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(Ce);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(ie);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(ae);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(f);var Ee=program.command("functions").alias("fn").description("Manage serverless functions");Ee.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(de);Ee.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(pe);var q=program.command("db").description("Database management commands");q.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(he);q.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(ye);q.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);q.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(we);var Re=program.command("keys").description("Manage API keys");Re.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($e);Re.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(be);var W=program.command("secrets").alias("sec").description("Manage function secrets");W.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(Se);W.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(Ae);W.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(Pe);W.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(xe);process.argv.slice(2).length||(so(),process.exit(0));program.parse(process.argv);
33
+ Error: ${s.message}`)),process.exit(1);}}var De="1.7.4",Q=l.hex("#00f0ff"),Y=l.hex("#7b61ff"),H=l.hex("#ff3dff"),X=l.hex("#00ff9d"),j=l.hex("#555570"),O=l.hex("#00f0ff");function so(){console.log(""),console.log(Q(" \u2566 \u2566")+Y("\u2554\u2550\u2557\u2566")+H("\u2554\u2550\u2557 ")+X("\u2554\u2550\u2557\u2566 \u2566")),console.log(Q(" \u255A\u2557\u2554\u255D")+Y("\u2560\u2550\u2563\u2551")+H("\u2560\u2563 ")+X("\u2551 \u2551 \u2551")),console.log(Q(" \u255A\u255D ")+Y("\u2569 \u2569\u2569")+H("\u255A ")+X("\u255A\u2550\u255D\u2569\u2550\u255D\u2569")),console.log(""),console.log(j(" \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(O(" VAIF Studio CLI")+j(` v${De}`)),console.log(j(" Build full-stack apps at lightning speed")),console.log(j(" \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(l.bold(" Quick Start")),console.log(j(" $ ")+O("vaif login")+j(" Authenticate")),console.log(j(" $ ")+O("vaif init -t react-spa")+j(" Scaffold project")),console.log(j(" $ ")+O("vaif db push")+j(" Push migrations")),console.log(j(" $ ")+O("vaif generate")+j(" Generate types")),console.log(j(" $ ")+O("vaif functions deploy")+j(" Deploy functions")),console.log(""),console.log(l.bold(" Categories")),console.log(j(" auth ")+l.white("login, logout, whoami")),console.log(j(" project ")+l.white("init, templates, info, status")),console.log(j(" schema ")+l.white("pull, push, generate")),console.log(j(" database ")+l.white("db push, db pull, db seed, db reset")),console.log(j(" deploy ")+l.white("functions deploy, functions list")),console.log(j(" security ")+l.white("keys, secrets")),console.log(""),console.log(j(" Run ")+O("vaif <command> --help")+j(" for details")),console.log(j(" Docs: ")+l.underline("https://docs.vaif.studio")),console.log("");}program.name("vaif").description("VAIF CLI - Type generation and development tools").version(De);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(c);program.command("logout").description("Log out and remove stored credentials").action(d);program.command("whoami").description("Show current authenticated user").action(e);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(h);program.command("templates").alias("tpl").description("List available project templates").action(g);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(ke);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(Ce);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(ie);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(ae);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(f);var Ee=program.command("functions").alias("fn").description("Manage serverless functions");Ee.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(de);Ee.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(pe);var q=program.command("db").description("Database management commands");q.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(he);q.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(ye);q.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);q.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(we);var Re=program.command("keys").description("Manage API keys");Re.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($e);Re.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(be);var W=program.command("secrets").alias("sec").description("Manage function secrets");W.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(Se);W.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(Ae);W.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(Pe);W.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(xe);process.argv.slice(2).length||(so(),process.exit(0));program.parse(process.argv);
package/dist/index.cjs CHANGED
@@ -325,12 +325,12 @@ export default function LoginPage() {
325
325
  setLoading(true);
326
326
  setError(null);
327
327
 
328
- const { error } = await vaif.auth.signInWithPassword({ email, password });
329
- if (error) {
330
- setError(error.message);
331
- setLoading(false);
332
- } else {
328
+ try {
329
+ await vaif.auth.login(email, password);
333
330
  router.push("/dashboard");
331
+ } catch (err: any) {
332
+ setError(err.message || "Login failed");
333
+ setLoading(false);
334
334
  }
335
335
  }
336
336
 
@@ -372,12 +372,12 @@ export default function SignupPage() {
372
372
  setLoading(true);
373
373
  setError(null);
374
374
 
375
- const { error } = await vaif.auth.signUp({ email, password });
376
- if (error) {
377
- setError(error.message);
378
- setLoading(false);
379
- } else {
375
+ try {
376
+ await vaif.auth.signUp(email, password);
380
377
  router.push("/");
378
+ } catch (err: any) {
379
+ setError(err.message || "Sign up failed");
380
+ setLoading(false);
381
381
  }
382
382
  }
383
383
 
@@ -784,12 +784,12 @@ export default function Login() {
784
784
  setLoading(true);
785
785
  setError(null);
786
786
 
787
- const { error } = await vaif.auth.signInWithPassword({ email, password });
788
- if (error) {
789
- setError(error.message);
790
- setLoading(false);
791
- } else {
787
+ try {
788
+ await vaif.auth.login(email, password);
792
789
  navigate("/");
790
+ } catch (err: any) {
791
+ setError(err.message || "Login failed");
792
+ setLoading(false);
793
793
  }
794
794
  }
795
795
 
@@ -829,12 +829,12 @@ export default function Signup() {
829
829
  setLoading(true);
830
830
  setError(null);
831
831
 
832
- const { error } = await vaif.auth.signUp({ email, password });
833
- if (error) {
834
- setError(error.message);
835
- setLoading(false);
836
- } else {
832
+ try {
833
+ await vaif.auth.signUp(email, password);
837
834
  navigate("/");
835
+ } catch (err: any) {
836
+ setError(err.message || "Sign up failed");
837
+ setLoading(false);
838
838
  }
839
839
  }
840
840
 
@@ -1448,10 +1448,14 @@ export default function LoginScreen() {
1448
1448
 
1449
1449
  async function handleLogin() {
1450
1450
  setLoading(true);
1451
- const { error } = await vaif.auth.signInWithPassword({ email, password });
1452
- setLoading(false);
1453
- if (error) Alert.alert("Error", error.message);
1454
- else router.replace("/");
1451
+ try {
1452
+ await vaif.auth.login(email, password);
1453
+ router.replace("/");
1454
+ } catch (err: any) {
1455
+ Alert.alert("Error", err.message || "Login failed");
1456
+ } finally {
1457
+ setLoading(false);
1458
+ }
1455
1459
  }
1456
1460
 
1457
1461
  return (
@@ -1486,10 +1490,14 @@ export default function SignupScreen() {
1486
1490
 
1487
1491
  async function handleSignup() {
1488
1492
  setLoading(true);
1489
- const { error } = await vaif.auth.signUp({ email, password });
1490
- setLoading(false);
1491
- if (error) Alert.alert("Error", error.message);
1492
- else router.replace("/");
1493
+ try {
1494
+ await vaif.auth.signUp(email, password);
1495
+ router.replace("/");
1496
+ } catch (err: any) {
1497
+ Alert.alert("Error", err.message || "Sign up failed");
1498
+ } finally {
1499
+ setLoading(false);
1500
+ }
1493
1501
  }
1494
1502
 
1495
1503
  return (
@@ -1836,7 +1844,7 @@ class _LoginScreenState extends State<LoginScreen> {
1836
1844
  setState(() { _loading = true; _error = null; });
1837
1845
 
1838
1846
  try {
1839
- await vaif.auth.signInWithPassword(
1847
+ await vaif.auth.login(
1840
1848
  email: _emailController.text,
1841
1849
  password: _passwordController.text,
1842
1850
  );
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export{f as generateTypes,h as initConfig,a as loadConfig}from'./chunk-M2UHM7B7.js';import T from'pg';import $ from'prettier';async function S(p){let{connectionString:a,schema:e="public"}=p,r=new T.Client({connectionString:a});await r.connect();try{let t=await r.query(`
1
+ export{f as generateTypes,h as initConfig,a as loadConfig}from'./chunk-CMWHBLLZ.js';import T from'pg';import $ from'prettier';async function S(p){let{connectionString:a,schema:e="public"}=p,r=new T.Client({connectionString:a});await r.connect();try{let t=await r.query(`
2
2
  SELECT table_name, table_type
3
3
  FROM information_schema.tables
4
4
  WHERE table_schema = $1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaiftech/cli",
3
- "version": "1.7.3",
3
+ "version": "1.7.4",
4
4
  "description": "VAIF CLI - Type generation and development tools",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",