@vaiftech/cli 1.3.2 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -16
- package/dist/{chunk-7XA2HKEQ.js → chunk-JRB5YVG7.js} +1592 -26
- package/dist/cli.cjs +1626 -60
- package/dist/cli.js +2 -2
- package/dist/index.cjs +1605 -39
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {d,c,b,a}from'./chunk-
|
|
2
|
+
import {d,c,b,a}from'./chunk-JRB5YVG7.js';import {program}from'commander';import F from'fs';import w from'path';import So from'os';import {exec}from'child_process';import V from'ora';import c$1 from'chalk';import q from'readline';var _=w.join(So.homedir(),".vaif"),D=w.join(_,"auth.json"),O=process.env.VAIF_API_URL||"https://api.vaif.studio";function Po(){F.existsSync(_)||F.mkdirSync(_,{recursive:true});}function G(e){Po(),F.writeFileSync(D,JSON.stringify(e,null,2),"utf-8"),F.chmodSync(D,384);}function j(){if(!F.existsSync(D))return null;try{let e=F.readFileSync(D,"utf-8");return JSON.parse(e)}catch{return null}}function xo(e){let o=q.createInterface({input:process.stdin,output:process.stdout});return new Promise(t=>{o.question(e,i=>{o.close(),t(i);});})}function Fo(e){return new Promise(o=>{let t=q.createInterface({input:process.stdin,output:process.stdout});process.stdin;let r=process.stdout.write.bind(process.stdout),l=false;process.stdout.write=((...s)=>l?true:r(...s)),t.question(e,s=>{l=false,process.stdout.write=r,console.log(""),t.close(),o(s);}),l=true;})}function ko(e){let o=process.platform,t;o==="darwin"?t=`open "${e}"`:o==="win32"?t=`start "" "${e}"`:t=`xdg-open "${e}"`,exec(t,i=>{});}function Co(e){return new Promise(o=>setTimeout(o,e))}async function Do(e){try{let o=await fetch(`${O}/auth/me`,{headers:{Authorization:`Bearer ${e}`}});if(o.ok){let t=await o.json();return {valid:!0,email:t.user?.email||t.email}}return {valid:!1}}catch{return {valid:false}}}async function Eo(e){let o=V();o.start("Setting up authentication...");let t,i;try{let n=await fetch(`${O}/auth/cli/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})});n.ok||(o.fail("Failed to initiate authentication"),console.log(c$1.red(`
|
|
3
3
|
Could not connect to VAIF API. Please try again later.`)),process.exit(1));let a=await n.json();t=a.code,i=a.url;}catch{o.fail("Failed to connect to VAIF API"),console.log(c$1.red(`
|
|
4
4
|
Could not connect to VAIF API.`)),console.log(c$1.gray("Check your internet connection or try: vaif login --email")),process.exit(1);}o.stop(),console.log(c$1.cyan(" Opening browser for authentication...")),console.log(""),console.log(c$1.gray(" If the browser doesn't open, visit this URL:")),console.log(c$1.white(` ${i}`)),console.log(""),ko(i),o.start("Waiting for browser authentication...");let r=12e4,l=2e3,s=Date.now();for(;Date.now()-s<r;){await Co(l);try{let n=await fetch(`${O}/auth/cli/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:t})});if(!n.ok){let d=await n.json();(d.error==="ExpiredCode"||d.error==="InvalidCode")&&(o.fail("Authentication expired"),console.log(c$1.red(`
|
|
5
5
|
The authentication session expired. Please try again.`)),process.exit(1));continue}let a=await n.json();if(a.ok&&a.accessToken){let d={token:a.accessToken,email:a.user?.email,projectId:e,expiresAt:new Date(Date.now()+a.expiresIn*1e3).toISOString()};G(d),o.succeed("Logged in successfully"),console.log(""),a.user?.email&&console.log(c$1.green(` Authenticated as: ${a.user.email}`)),console.log(c$1.gray(` Config saved to: ${D}`)),console.log("");return}}catch{}}o.fail("Authentication timed out"),console.log(c$1.red(`
|
|
@@ -34,4 +34,4 @@ Error: ${n.message}`)),process.exit(1);}}async function wo(e){let o=V(),t=j();(!
|
|
|
34
34
|
Generate one with: vaif keys generate`));return}let d=Math.max(8,...a.map(f=>(f.name||"").length)),p=` ${"Name".padEnd(d)} ${"Key".padEnd(24)} Created`;console.log(c$1.gray(p)),console.log(c$1.gray(" "+"-".repeat(p.length-2)));for(let f of a){let g=(f.name||"unnamed").padEnd(d),y=f.maskedKey||f.prefix||`${(f.key||"").slice(0,12)}...`,$=f.createdAt?new Date(f.createdAt).toLocaleDateString():"N/A";console.log(` ${g} ${y.padEnd(24)} ${$}`);}console.log(""),console.log(c$1.gray(` ${a.length} key(s) total`)),console.log("");}catch(s){o.fail("Failed to list API keys"),s instanceof Error&&console.log(c$1.red(`
|
|
35
35
|
Error: ${s.message}`)),process.exit(1);}}var jo=process.env.VAIF_API_URL||"https://api.vaif.studio";function Qo(e){try{let o=new URL(e);return o.password&&(o.password="****"),o.toString()}catch{return e.replace(/:[^@/]+@/,":****@")}}async function vo(e){let o=V(),t=j();(!t||!t.token)&&(console.log(c$1.red("Not logged in")),console.log(c$1.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 l=e.projectId||r?.projectId||t.projectId;l||(console.log(c$1.red("No project ID specified")),console.log(c$1.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(`${jo}/v1/projects/${l}`,{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(c$1.bold("VAIF Project Info")),console.log("");let a=16,d=(p,f)=>{console.log(` ${c$1.gray(p.padEnd(a))} ${f}`);};d("Name:",c$1.white(n.name||"N/A")),d("Project ID:",c$1.white(l)),d("Region:",c$1.white(n.region||"us-east-1")),d("Plan:",c$1.white(n.plan||n.tier||"free")),d("Created:",c$1.white(n.createdAt?new Date(n.createdAt).toLocaleDateString():"N/A")),console.log(""),d("API URL:",c$1.cyan(n.apiUrl||`${jo}/v1`)),d("WS URL:",c$1.cyan(n.wsUrl||n.realtimeUrl||"N/A")),d("DB URL:",c$1.cyan(n.databaseUrl?Qo(n.databaseUrl):"N/A")),d("Storage URL:",c$1.cyan(n.storageUrl||"N/A")),console.log("");}catch(s){o.fail("Failed to fetch project info"),s instanceof Error&&console.log(c$1.red(`
|
|
36
36
|
Error: ${s.message}`)),process.exit(1);}}var Zo=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Io(e){let o=V(),t=j();(!t||!t.token)&&(console.log(c$1.red("Not logged in")),console.log(c$1.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 l=e.projectId||r?.projectId||t.projectId;l||(console.log(c$1.red("No project ID specified")),console.log(c$1.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(`${Zo}/v1/projects/${l}?include=tables,functions,storage,connections`,{headers:{Authorization:`Bearer ${t.token}`}});if(!s.ok){let $=await s.text();throw new Error(`Failed to fetch project status: ${$}`)}let n=await s.json();o.stop(),console.log(""),console.log(c$1.bold("VAIF Project Status")),console.log("");let a=22,d=($,k)=>{console.log(` ${c$1.gray($.padEnd(a))} ${k}`);};d("Project:",c$1.white(n.name||l)),d("Plan:",c$1.white(n.plan||n.tier||"free")),console.log(""),console.log(c$1.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",y=n.activeConnections??n.connections??"N/A";d("Tables:",c$1.white(String(p))),d("Functions:",c$1.white(String(f))),d("Storage Buckets:",c$1.white(String(g))),d("Active Connections:",c$1.white(String(y))),n.usage&&(console.log(""),console.log(c$1.gray(" --- Usage ---")),console.log(""),n.usage.dbSize&&d("Database Size:",c$1.white(n.usage.dbSize)),n.usage.storageSize&&d("Storage Size:",c$1.white(n.usage.storageSize)),n.usage.bandwidth&&d("Bandwidth:",c$1.white(n.usage.bandwidth)),n.usage.functionInvocations!=null&&d("Function Invocations:",c$1.white(String(n.usage.functionInvocations)))),console.log("");}catch(s){o.fail("Failed to fetch project status"),s instanceof Error&&console.log(c$1.red(`
|
|
37
|
-
Error: ${s.message}`)),process.exit(1);}}program.name("vaif").description("VAIF CLI - Type generation and development tools").version("1.
|
|
37
|
+
Error: ${s.message}`)),process.exit(1);}}program.name("vaif").description("VAIF CLI - Type generation and development tools").version("1.5.0");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(Y);program.command("logout").description("Log out and remove stored credentials").action(H);program.command("whoami").description("Show current authenticated user").action(Q);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").action(d);program.command("templates").alias("tpl").description("List available project templates").action(c);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(vo);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(Io);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(X);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(eo);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(b);var bo=program.command("functions").alias("fn").description("Manage serverless functions");bo.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(ro);bo.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(co);var U=program.command("db").description("Database management commands");U.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(go);U.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(fo);U.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(lo);U.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(po);var $o=program.command("keys").description("Manage API keys");$o.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(yo);$o.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(wo);program.parse(process.argv);process.argv.slice(2).length||program.outputHelp();
|