@vaiftech/cli 1.6.6 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{chunk-OB2QEQ2L.js → chunk-N7OY2COL.js} +65 -63
- package/dist/cli.cjs +100 -98
- package/dist/cli.js +30 -30
- package/dist/index.cjs +58 -56
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {d,c,b,a}from'./chunk-
|
|
2
|
+
import {d,c,b,a}from'./chunk-N7OY2COL.js';import'dotenv/config';import {program}from'commander';import l from'chalk';import D from'fs';import j from'path';import Be from'os';import {exec}from'child_process';import M from'ora';import le from'readline';var X=j.join(Be.homedir(),".vaif"),V=j.join(X,"auth.json"),J=process.env.VAIF_API_URL||"https://api.vaif.studio";function Ke(){D.existsSync(X)||D.mkdirSync(X,{recursive:true});}function ge(e){Ke(),D.writeFileSync(V,JSON.stringify(e,null,2),"utf-8"),D.chmodSync(V,384);}function I(){if(!D.existsSync(V))return null;try{let e=D.readFileSync(V,"utf-8");return JSON.parse(e)}catch{return null}}function qe(e){let o=le.createInterface({input:process.stdin,output:process.stdout});return new Promise(t=>{o.question(e,s=>{o.close(),t(s);});})}function We(e){return new Promise(o=>{let t=le.createInterface({input:process.stdin,output:process.stdout});process.stdin;let c=process.stdout.write.bind(process.stdout),r=false;process.stdout.write=((...i)=>r?true:c(...i)),t.question(e,i=>{r=false,process.stdout.write=c,console.log(""),t.close(),o(i);}),r=true;})}function Ge(e){let o=process.platform,t;o==="darwin"?t=`open "${e}"`:o==="win32"?t=`start "" "${e}"`:t=`xdg-open "${e}"`,exec(t,s=>{});}function Ye(e){return new Promise(o=>setTimeout(o,e))}async function Qe(e){try{let o=await fetch(`${J}/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 He(e){let o=M();o.start("Setting up authentication...");let t,s;try{let n=await fetch(`${J}/auth/cli/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})});n.ok||(o.fail("Failed to initiate authentication"),console.log(l.red(`
|
|
3
3
|
Could not connect to VAIF API. Please try again later.`)),process.exit(1));let a=await n.json();t=a.code,s=a.url;}catch{o.fail("Failed to connect to VAIF API"),console.log(l.red(`
|
|
4
|
-
Could not connect to VAIF API.`)),console.log(l.gray("Check your internet connection or try: vaif login --email")),process.exit(1);}o.stop(),console.log(l.cyan(" Opening browser for authentication...")),console.log(""),console.log(l.gray(" If the browser doesn't open, visit this URL:")),console.log(l.white(` ${s}`)),console.log(""),
|
|
5
|
-
The authentication session expired. Please try again.`)),process.exit(1));continue}let a=await n.json();if(a.ok&&a.accessToken){let f={token:a.accessToken,email:a.user?.email,projectId:e,expiresAt:new Date(Date.now()+a.expiresIn*1e3).toISOString()};
|
|
6
|
-
Timed out waiting for browser authentication.`)),console.log(l.gray("Try again or use: vaif login --email")),process.exit(1);}async function
|
|
7
|
-
No email provided. Login cancelled.`)),process.exit(1));let t=await
|
|
8
|
-
No password provided. Login cancelled.`)),process.exit(1));let s=
|
|
9
|
-
${r.message||"Invalid email or password."}`)),process.exit(1));let i={token:r.accessToken,email:r.user?.email,projectId:e,expiresAt:new Date(Date.now()+r.expiresIn*1e3).toISOString()};
|
|
10
|
-
Could not connect to VAIF API. Please try again later.`)),process.exit(1);}}async function
|
|
11
|
-
Your session has expired. Please login again.`)),process.exit(1)),o.succeed("Authenticated"),console.log(""),console.log(l.green(` Email: ${s||e.email||"Unknown"}`)),e.projectId&&console.log(l.green(` Project: ${e.projectId}`)),console.log("");}var
|
|
4
|
+
Could not connect to VAIF API.`)),console.log(l.gray("Check your internet connection or try: vaif login --email")),process.exit(1);}o.stop(),console.log(l.cyan(" Opening browser for authentication...")),console.log(""),console.log(l.gray(" If the browser doesn't open, visit this URL:")),console.log(l.white(` ${s}`)),console.log(""),Ge(s),o.start("Waiting for browser authentication...");let c=12e4,r=2e3,i=Date.now();for(;Date.now()-i<c;){await Ye(r);try{let n=await fetch(`${J}/auth/cli/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:t})});if(!n.ok){let f=await n.json();(f.error==="ExpiredCode"||f.error==="InvalidCode")&&(o.fail("Authentication expired"),console.log(l.red(`
|
|
5
|
+
The authentication session expired. Please try again.`)),process.exit(1));continue}let a=await n.json();if(a.ok&&a.accessToken){let f={token:a.accessToken,email:a.user?.email,projectId:e,expiresAt:new Date(Date.now()+a.expiresIn*1e3).toISOString()};ge(f),o.succeed("Logged in successfully"),console.log(""),a.user?.email&&console.log(l.green(` Authenticated as: ${a.user.email}`)),console.log(l.gray(` Config saved to: ${V}`)),console.log("");return}}catch{}}o.fail("Authentication timed out"),console.log(l.red(`
|
|
6
|
+
Timed out waiting for browser authentication.`)),console.log(l.gray("Try again or use: vaif login --email")),process.exit(1);}async function Xe(e){console.log(""),console.log(l.bold("VAIF CLI Login")),console.log(l.gray("Enter your VAIF account credentials")),console.log("");let o=await qe(l.cyan(" Email: "));(!o||o.trim()==="")&&(console.log(l.red(`
|
|
7
|
+
No email provided. Login cancelled.`)),process.exit(1));let t=await We(l.cyan(" Password: "));(!t||t.trim()==="")&&(console.log(l.red(`
|
|
8
|
+
No password provided. Login cancelled.`)),process.exit(1));let s=M("Authenticating...").start();try{let c=await fetch(`${J}/auth/cli/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:o.trim(),password:t})}),r=await c.json();(!c.ok||!r.ok)&&(s.fail("Login failed"),console.log(l.red(`
|
|
9
|
+
${r.message||"Invalid email or password."}`)),process.exit(1));let i={token:r.accessToken,email:r.user?.email,projectId:e,expiresAt:new Date(Date.now()+r.expiresIn*1e3).toISOString()};ge(i),s.succeed("Logged in successfully"),console.log(""),r.user?.email&&console.log(l.green(` Authenticated as: ${r.user.email}`)),console.log(l.gray(` Config saved to: ${V}`)),console.log("");}catch{s.fail("Failed to connect to VAIF API"),console.log(l.red(`
|
|
10
|
+
Could not connect to VAIF API. Please try again later.`)),process.exit(1);}}async function fe(e){console.log(""),console.log(l.bold("Welcome to VAIF CLI")),console.log(l.gray("Authenticate to access your VAIF projects")),console.log(""),e.email?await Xe(e.projectId):await He(e.projectId),console.log(l.gray("You can now use VAIF CLI commands like:")),console.log(l.gray(" vaif pull - Pull remote schema")),console.log(l.gray(" vaif push - Push schema changes")),console.log(l.gray(" vaif generate - Generate TypeScript types")),console.log("");}async function de(){D.existsSync(V)?(D.unlinkSync(V),console.log(l.green("Logged out successfully"))):console.log(l.yellow("Not currently logged in"));}async function pe(){let e=I();(!e||!e.token)&&(console.log(l.yellow("Not logged in")),console.log(l.gray("Run `vaif login` to authenticate")),process.exit(1));let o=M("Checking authentication...").start(),{valid:t,email:s}=await Qe(e.token);t||(o.fail("Session expired"),console.log(l.yellow(`
|
|
11
|
+
Your session has expired. Please login again.`)),process.exit(1)),o.succeed("Authenticated"),console.log(""),console.log(l.green(` Email: ${s||e.email||"Unknown"}`)),e.projectId&&console.log(l.green(` Project: ${e.projectId}`)),console.log("");}var to=process.env.VAIF_API_URL||"https://api.vaif.studio";async function no(e,o,t="public"){let s=await fetch(`${to}/v1/projects/${o}/schema?schema=${t}`,{headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!s.ok){let c=await s.text();throw new Error(`Failed to fetch schema: ${c}`)}return s.json()}async function ue(e){let o=M(),t=I();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let s=e.config||"vaif.config.json",c=null;o.start("Loading configuration...");try{c=await a(s);}catch(i){o.fail("Failed to load config"),console.log(l.red(`
|
|
12
12
|
Error: ${i}`)),process.exit(1);}c||(o.fail("No configuration found"),console.log(l.yellow("\nRun `vaif init` to create a configuration file.")),process.exit(1));let r=e.projectId||c.projectId||process.env.VAIF_PROJECT_ID||t.projectId;r||(o.fail("No project ID specified"),console.log(l.yellow(`
|
|
13
|
-
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1)),o.text="Fetching remote schema...";try{let i=e.schema||c.database?.schema||"public",n=await
|
|
14
|
-
Error: ${i.message}`)),process.exit(1);}}var
|
|
13
|
+
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1)),o.text="Fetching remote schema...";try{let i=e.schema||c.database?.schema||"public",n=await no(t.token,r,i);o.succeed("Schema fetched successfully");let a=e.output||j.resolve("vaif.schema.json"),f={$schema:"https://vaif.studio/schemas/schema.json",projectId:r,schema:i,pulledAt:new Date().toISOString(),...n};D.writeFileSync(a,JSON.stringify(f,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(i){o.fail("Failed to fetch schema"),i instanceof Error&&console.log(l.red(`
|
|
14
|
+
Error: ${i.message}`)),process.exit(1);}}var he=process.env.VAIF_API_URL||"https://api.vaif.studio";function co(e){let o=le.createInterface({input:process.stdin,output:process.stdout});return new Promise(t=>{o.question(e,s=>{o.close(),t(s);});})}async function ao(e,o,t){let s=await fetch(`${he}/v1/projects/${o}/schema/preview`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify({schema:t})});if(!s.ok){let c=await s.text();throw new Error(`Failed to preview changes: ${c}`)}return s.json()}async function lo(e,o,t){let s=await fetch(`${he}/v1/projects/${o}/schema/apply`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify({schema:t})});if(!s.ok){let c=await s.text();throw new Error(`Failed to apply changes: ${c}`)}return s.json()}function go(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 ye(e){let o=M(),t=I();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let s=e.config||"vaif.config.json",c=null;o.start("Loading configuration...");try{c=await a(s);}catch(a){o.fail("Failed to load config"),console.log(l.red(`
|
|
15
15
|
Error: ${a}`)),process.exit(1);}c||(o.fail("No configuration found"),console.log(l.yellow("\nRun `vaif init` to create a configuration file.")),process.exit(1));let r=e.projectId||c.projectId||process.env.VAIF_PROJECT_ID||t.projectId;r||(o.fail("No project ID specified"),console.log(l.yellow(`
|
|
16
|
-
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1));let i=e.schema||j.resolve("vaif.schema.json");
|
|
17
|
-
Expected schema file at: ${i}`)),console.log(l.gray("Run `vaif pull` first to fetch the current schema.")),process.exit(1));let n;try{let a=
|
|
18
|
-
Error: ${a.message}`)),process.exit(1);}o.text="Calculating schema changes...";try{let{diff:a,sql:f}=await
|
|
19
|
-
Cancelled. No changes applied.`));return}}o.start("Applying schema changes...");let p=await
|
|
20
|
-
Error: ${a.message}`)),process.exit(1);}}var
|
|
16
|
+
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1));let i=e.schema||j.resolve("vaif.schema.json");D.existsSync(i)||(o.fail("No local schema found"),console.log(l.yellow(`
|
|
17
|
+
Expected schema file at: ${i}`)),console.log(l.gray("Run `vaif pull` first to fetch the current schema.")),process.exit(1));let n;try{let a=D.readFileSync(i,"utf-8");n=JSON.parse(a);}catch(a){o.fail("Failed to parse schema file"),a instanceof Error&&console.log(l.red(`
|
|
18
|
+
Error: ${a.message}`)),process.exit(1);}o.text="Calculating schema changes...";try{let{diff:a,sql:f}=await ao(t.token,r,n);if(o.stop(),go(a),a.added.length===0&&a.modified.length===0&&a.removed.length===0){console.log("");return}if(f.length>0){console.log(l.bold("SQL Migrations:")),console.log("");for(let d of f)console.log(l.gray(` ${d}`));console.log("");}if(e.dryRun){console.log(l.yellow("Dry run mode - no changes applied.")),console.log(l.gray("Remove --dry-run to apply these changes."));return}if(!e.force){a.removed.length>0&&(console.log(l.red.bold("\u26A0\uFE0F Warning: This will remove tables/columns from your database.")),console.log(l.red(" This action cannot be undone!")),console.log(""));let g=await co(l.cyan("Apply these changes? [y/N] "));if(g.toLowerCase()!=="y"&&g.toLowerCase()!=="yes"){console.log(l.yellow(`
|
|
19
|
+
Cancelled. No changes applied.`));return}}o.start("Applying schema changes...");let p=await lo(t.token,r,n);if(p.success){if(o.succeed("Schema changes applied successfully"),console.log(""),p.migrations.length>0){console.log(l.gray("Migrations applied:"));for(let d of p.migrations)console.log(l.gray(` - ${d}`));console.log("");}console.log(l.green("Your database schema is now up to date.")),console.log(l.gray("Run `vaif generate` to update your TypeScript types.")),console.log("");}else o.fail("Failed to apply some changes");}catch(a){o.fail("Failed to push schema changes"),a instanceof Error&&console.log(l.red(`
|
|
20
|
+
Error: ${a.message}`)),process.exit(1);}}var B=process.env.VAIF_API_URL||"https://api.vaif.studio";async function fo(e,o,t,s){let c=new URL(`${B}/functions/project/${o}`);s&&c.searchParams.set("envId",s);let r=await fetch(c.toString(),{headers:{Authorization:`Bearer ${e}`}});if(!r.ok)return null;let i=await r.json(),n=i.functions||i;return Array.isArray(n)&&n.find(a=>a.name===t)||null}async function po(e,o,t){let s=await fetch(`${B}/functions/`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify({projectId:o,name:t.name,runtime:t.runtime,entrypoint:t.entrypoint,envId:t.envId})});if(!s.ok){let c=await s.text();throw new Error(`Failed to create function: ${c}`)}return s.json()}async function uo(e,o,t){let s=await fetch(`${B}/functions/${o}/source`,{method:"PUT",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify({sourceCode:t})});if(!s.ok){let c=await s.text();throw new Error(`Failed to deploy source: ${c}`)}}async function mo(e,o,t){let s=new URL(`${B}/functions/project/${o}`);t&&s.searchParams.set("envId",t);let c=await fetch(s.toString(),{headers:{Authorization:`Bearer ${e}`}});if(!c.ok){let i=await c.text();throw new Error(`Failed to list functions: ${i}`)}let r=await c.json();return r.functions||r}function we(e){switch(j.extname(e).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 je(e){let o=[],t=[".ts",".js",".mjs",".py",".go",".rs"],s=["drizzle.config.ts","tsconfig.json","package.json"];if(!D.existsSync(e))return o;let c=D.readdirSync(e,{withFileTypes:true});for(let r of c){let i=j.join(e,r.name);if(r.isDirectory()){if(r.name!=="node_modules"&&!r.name.startsWith(".")){let n=D.readdirSync(i,{withFileTypes:true});for(let a of n)if(a.isFile()){let f=j.extname(a.name).toLowerCase();if(t.includes(f)){o.push(j.join(i,a.name));break}}}}else if(r.isFile()){let n=j.extname(r.name).toLowerCase();t.includes(n)&&!s.includes(r.name)&&o.push(i);}}return o}async function Ie(e){let o=M(),t=I();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let s=e.config||"vaif.config.json",c=null;try{c=await a(s);}catch{}let r=e.projectId||c?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;r||(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)),console.log(""),console.log(l.bold("VAIF Functions Deploy")),console.log(""),o.start("Scanning for function files...");let i=j.resolve("functions"),n=j.resolve("src/functions"),a$1=[];if(e.entrypoint){let g=j.resolve(e.entrypoint);D.existsSync(g)||(o.fail(`File not found: ${e.entrypoint}`),process.exit(1)),a$1=[g];}else a$1=[...je(i),...je(n)];a$1.length===0&&(o.fail("No function files found"),console.log(l.yellow(`
|
|
21
21
|
Place your functions in:`)),console.log(l.gray(" - ./functions/")),console.log(l.gray(" - ./src/functions/")),console.log(l.gray(`
|
|
22
22
|
Or specify an entrypoint with --entrypoint`)),process.exit(1)),o.succeed(`Found ${a$1.length} function(s)`),e.name&&(a$1=a$1.filter(g=>j.basename(g,j.extname(g)).includes(e.name)),a$1.length===0&&(console.log(l.yellow(`
|
|
23
|
-
No functions matching "${e.name}" found`)),process.exit(1))),console.log(""),console.log(l.gray("Functions to deploy:"));for(let g of a$1){let y=j.basename(j.dirname(g)),w=y==="functions"||y==="src"?j.basename(g,j.extname(g)):y,
|
|
23
|
+
No functions matching "${e.name}" found`)),process.exit(1))),console.log(""),console.log(l.gray("Functions to deploy:"));for(let g of a$1){let y=j.basename(j.dirname(g)),w=y==="functions"||y==="src"?j.basename(g,j.extname(g)):y,E=e.runtime||we(g);console.log(l.gray(` - ${w} (${E})`));}if(console.log(""),e.dryRun){console.log(l.yellow("Dry run mode - no functions deployed."));return}let f=[];for(let g of a$1){let y=j.basename(j.dirname(g)),w=y==="functions"||y==="src"?j.basename(g,j.extname(g)):y,E=e.runtime||we(g);o.start(`Deploying ${w}...`);try{let z=D.readFileSync(g,"utf-8"),_=await fo(t.token,r,w,e.envId);_||(o.text=`Creating ${w}...`,_=await po(t.token,r,{name:w,runtime:E,entrypoint:j.basename(g),envId:e.envId})),o.text=`Deploying ${w}...`,await uo(t.token,_.id,z),o.succeed(`Deployed ${w}`),f.push({name:w,success:!0});}catch(z){let _=z instanceof Error?z.message:"Unknown error";o.fail(`Failed to deploy ${w}`),f.push({name:w,success:false,error:_});}}console.log("");let p=f.filter(g=>g.success).length;if(f.filter(g=>!g.success).length===0)console.log(l.green(`\u2713 Successfully deployed ${p} function(s)`));else {console.log(l.yellow(`Deployed ${p}/${f.length} function(s)`)),console.log(""),console.log(l.red("Failed deployments:"));for(let g of f.filter(y=>!y.success))console.log(l.red(` - ${g.name}: ${g.error}`));}console.log("");}async function $e(e){let o=M(),t=I();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let s=e.config||"vaif.config.json",c=null;try{c=await a(s);}catch{}let r=e.projectId||c?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;r||(console.log(l.red("No project ID specified")),process.exit(1)),o.start("Fetching functions...");try{let i=await mo(t.token,r,e.envId);if(o.stop(),i.length===0){console.log(l.yellow(`
|
|
24
24
|
No functions found`)),console.log(l.gray("Deploy your first function with: vaif functions deploy"));return}console.log(""),console.log(l.bold(`Functions (${i.length}):`)),console.log(""),console.log(l.gray(" "+"NAME".padEnd(25)+"RUNTIME".padEnd(15)+"STATUS".padEnd(12)+"INVOCATIONS".padEnd(14)+"LAST DEPLOYED")),console.log(l.gray(" "+"-".repeat(80)));for(let n of i){let a=n.deployStatus==="deployed"?l.green:n.deployStatus==="deploying"?l.yellow:n.deployStatus==="failed"?l.red:l.gray;console.log(" "+n.name.padEnd(25)+n.runtime.padEnd(15)+a(n.deployStatus.padEnd(12))+String(n.invocationCount??0).padEnd(14)+(n.deployedAt?new Date(n.deployedAt).toLocaleDateString():"-"));}console.log("");}catch(i){o.fail("Failed to fetch functions"),i instanceof Error&&console.log(l.red(`
|
|
25
|
-
Error: ${i.message}`)),process.exit(1);}}var
|
|
25
|
+
Error: ${i.message}`)),process.exit(1);}}var K=process.env.VAIF_API_URL||"https://api.vaif.studio";async function ho(e,o,t,s,c){let r=await fetch(`${K}/v1/projects/${o}/db/seed`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify({table:t,records:s,truncate:c?.truncate??false})});if(!r.ok){let i=await r.text();throw new Error(`Failed to seed ${t}: ${i}`)}return r.json()}async function yo(e,o){let t=await fetch(`${K}/v1/projects/${o}/db/reset`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"}});if(!t.ok){let s=await t.text();throw new Error(`Failed to reset database: ${s}`)}return t.json()}function ee(e){let o=[];if(!D.existsSync(e))return o;let t=D.readdirSync(e,{withFileTypes:true});for(let s of t)if(s.isFile()){let c=j.extname(s.name).toLowerCase();(c===".json"||c===".ts"||c===".js")&&o.push(j.join(e,s.name));}return o.sort()}async function be(e){let o=j.extname(e).toLowerCase();if(o===".json"){let t=D.readFileSync(e,"utf-8"),s=JSON.parse(t);return Array.isArray(s)?[{table:j.basename(e,o),data:s}]:s.table&&s.data?[s]:Object.entries(s).map(([c,r])=>({table:c,data:r}))}else if(o===".ts"||o===".js"){let t=await import(e),s=t.default||t;return typeof s=="function"?s():s}throw new Error(`Unsupported file format: ${o}`)}async function Se(e){let o=M(),t=I();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let s=e.config||"vaif.config.json",c=null;try{c=await a(s);}catch{}let r=e.projectId||c?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;r||(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)),console.log(""),console.log(l.bold("VAIF Database Seed")),console.log("");let i=[];if(e.file){let p=j.resolve(e.file);D.existsSync(p)||(console.log(l.red(`File not found: ${e.file}`)),process.exit(1)),i=[p];}else {let p=j.resolve("seeds"),d=j.resolve("prisma/seed"),g=j.resolve("db/seeds");i=[...ee(p),...ee(d),...ee(g)];}i.length===0&&(console.log(l.yellow("No seed files found")),console.log(l.gray(`
|
|
26
26
|
Place your seed files in one of these directories:`)),console.log(l.gray(" - ./seeds/")),console.log(l.gray(" - ./prisma/seed/")),console.log(l.gray(" - ./db/seeds/")),console.log(l.gray(`
|
|
27
27
|
Or specify a file with --file`)),console.log(l.gray(`
|
|
28
|
-
Example seed file (seeds/users.json):`)),console.log(l.gray(" [")),console.log(l.gray(' { "name": "John Doe", "email": "john@example.com" },')),console.log(l.gray(' { "name": "Jane Doe", "email": "jane@example.com" }')),console.log(l.gray(" ]")),process.exit(1)),console.log(l.gray("Seed files found:"));for(let p of i)console.log(l.gray(` - ${j.relative(process.cwd(),p)}`));if(console.log(""),e.truncate&&(console.log(l.yellow("\u26A0\uFE0F Tables will be truncated before seeding")),console.log("")),e.dryRun){console.log(l.yellow("Dry run mode - no data will be inserted.")),console.log("");for(let p of i){o.start(`Loading ${j.basename(p)}...`);try{let d=await
|
|
28
|
+
Example seed file (seeds/users.json):`)),console.log(l.gray(" [")),console.log(l.gray(' { "name": "John Doe", "email": "john@example.com" },')),console.log(l.gray(' { "name": "Jane Doe", "email": "jane@example.com" }')),console.log(l.gray(" ]")),process.exit(1)),console.log(l.gray("Seed files found:"));for(let p of i)console.log(l.gray(` - ${j.relative(process.cwd(),p)}`));if(console.log(""),e.truncate&&(console.log(l.yellow("\u26A0\uFE0F Tables will be truncated before seeding")),console.log("")),e.dryRun){console.log(l.yellow("Dry run mode - no data will be inserted.")),console.log("");for(let p of i){o.start(`Loading ${j.basename(p)}...`);try{let d=await be(p);o.stop();for(let g of d)e.table&&g.table!==e.table||(console.log(l.cyan(`Table: ${g.table}`)),console.log(l.gray(` Records: ${g.data.length}`)),g.data.length>0&&console.log(l.gray(` Sample: ${JSON.stringify(g.data[0],null,2).slice(0,100)}...`)),console.log(""));}catch(d){o.fail(`Failed to load ${j.basename(p)}`),d instanceof Error&&console.log(l.red(` Error: ${d.message}`));}}return}let n=[];for(let p of i){o.start(`Processing ${j.basename(p)}...`);try{let d=await be(p);o.stop();for(let g of d)if(!(e.table&&g.table!==e.table)){if(g.data.length===0){console.log(l.gray(` Skipping ${g.table} (no records)`));continue}o.start(`Seeding ${g.table} (${g.data.length} records)...`);try{let y=await ho(t.token,r,g.table,g.data,{truncate:e.truncate});o.succeed(`Seeded ${g.table}: ${y.inserted} records`),n.push({table:g.table,inserted:y.inserted});}catch(y){let w=y instanceof Error?y.message:"Unknown error";o.fail(`Failed to seed ${g.table}`),n.push({table:g.table,inserted:0,error:w});}}}catch(d){o.fail(`Failed to load ${j.basename(p)}`),d instanceof Error&&console.log(l.red(` Error: ${d.message}`));}}console.log("");let a$1=n.reduce((p,d)=>p+d.inserted,0),f=n.filter(p=>p.error).length;if(f===0)console.log(l.green(`\u2713 Successfully seeded ${a$1} records across ${n.length} table(s)`));else {console.log(l.yellow(`Seeded ${a$1} records with ${f} error(s)`)),console.log(""),console.log(l.red("Errors:"));for(let p of n.filter(d=>d.error))console.log(l.red(` - ${p.table}: ${p.error}`));}console.log("");}async function Ae(e){let o=M(),t=I();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let s=e.config||"vaif.config.json",c=null;try{c=await a(s);}catch{}let r=e.projectId||c?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;r||(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));let i=j.resolve(e.dir||"./drizzle");if(console.log(""),console.log(l.bold("VAIF Database Push")),console.log(""),!D.existsSync(i)){let d=j.resolve("./migrations");D.existsSync(d)?console.log(l.gray(`Using migrations from: ${d}`)):(console.log(l.red(`Migrations directory not found: ${i}`)),console.log(l.gray(`
|
|
29
29
|
Expected one of:`)),console.log(l.gray(" - ./drizzle/")),console.log(l.gray(" - ./migrations/")),console.log(l.gray(`
|
|
30
|
-
Or specify with: vaif db push --dir <path>`)),process.exit(1));}let n=[],a$1=
|
|
31
|
-
Error: ${n.message}`)),process.exit(1);}}async function
|
|
32
|
-
Error: ${i.message}`)),process.exit(1);}}var
|
|
33
|
-
Error: ${n.message}`)),process.exit(1);}}async function
|
|
30
|
+
Or specify with: vaif db push --dir <path>`)),process.exit(1));}let n=[],a$1=D.readdirSync(i,{withFileTypes:true});for(let d of a$1)if(d.isFile()&&d.name.endsWith(".sql"))n.push(j.join(i,d.name));else if(d.isDirectory()){let g=D.readdirSync(j.join(i,d.name),{withFileTypes:true});for(let y of g)y.isFile()&&y.name.endsWith(".sql")&&n.push(j.join(i,d.name,y.name));}n.sort(),n.length===0&&(console.log(l.yellow("No SQL migration files found")),process.exit(1)),console.log(l.gray(`Found ${n.length} migration(s):`));for(let d of n)console.log(l.gray(` - ${j.relative(process.cwd(),d)}`));if(console.log(""),e.dryRun){console.log(l.yellow("Dry run mode - no migrations will be applied.")),console.log("");for(let d of n){let g=D.readFileSync(d,"utf-8");console.log(l.cyan(`--- ${j.basename(d)} ---`)),console.log(l.gray(g.slice(0,500))),g.length>500&&console.log(l.gray("...")),console.log("");}return}let f=0,p=0;for(let d of n){let g=D.readFileSync(d,"utf-8"),y=j.relative(process.cwd(),d);o.start(`Applying ${y}...`);try{let w=await fetch(`${K}/schema-engine/query/${r}`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"Content-Type":"application/json"},body:JSON.stringify({sql:g})});if(!w.ok){let E=await w.text();throw new Error(E)}o.succeed(`Applied ${y}`),f++;}catch(w){let E=w instanceof Error?w.message:"Unknown error";o.fail(`Failed ${y}: ${E}`),p++;}}console.log(""),console.log(p===0?l.green(`Successfully applied ${f} migration(s)`):l.yellow(`Applied ${f}, failed ${p} migration(s)`)),console.log("");}async function Pe(e){let o=M(),t=I();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let s=e.config||"vaif.config.json",c=null;try{c=await a(s);}catch{}let r=e.projectId||c?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;r||(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));let i=j.resolve(e.output||"vaif.schema.json");console.log(""),console.log(l.bold("VAIF Database Pull")),console.log(""),o.start("Pulling schema from remote...");try{let n=await fetch(`${K}/schema-engine/introspect/${r}`,{headers:{Authorization:`Bearer ${t.token}`}});if(!n.ok){let p=await n.text();throw new Error(`Failed to pull schema: ${p}`)}let a=await n.json();D.writeFileSync(i,JSON.stringify(a,null,2),"utf-8"),o.succeed(`Schema written to ${j.relative(process.cwd(),i)}`);let f=a.tables?.length??Object.keys(a).length;console.log(l.gray(` ${f} table(s) pulled`)),console.log("");}catch(n){o.fail("Failed to pull schema"),n instanceof Error&&console.log(l.red(`
|
|
31
|
+
Error: ${n.message}`)),process.exit(1);}}async function xe(e){let o=M(),t=I();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let s=e.config||"vaif.config.json",c=null;try{c=await a(s);}catch{}let r=e.projectId||c?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;r||(console.log(l.red("No project ID specified")),process.exit(1)),console.log(""),console.log(l.red.bold("\u26A0\uFE0F DATABASE RESET")),console.log(""),console.log(l.red("This will:")),console.log(l.red(" - Drop all tables")),console.log(l.red(" - Delete all data")),console.log(l.red(" - Reset migrations")),console.log(""),console.log(l.red.bold("This action cannot be undone!")),console.log(""),e.force||(console.log(l.yellow("Use --force to confirm this action.")),process.exit(1)),o.start("Resetting database...");try{await yo(t.token,r),o.succeed("Database reset complete"),console.log(""),console.log(l.gray("Your database is now empty.")),console.log(l.gray("Run `vaif push` to apply your schema, then `vaif db seed` to seed data.")),console.log("");}catch(i){o.fail("Failed to reset database"),i instanceof Error&&console.log(l.red(`
|
|
32
|
+
Error: ${i.message}`)),process.exit(1);}}var ke=process.env.VAIF_API_URL||"https://api.vaif.studio";function Ce(e,o,t){return e.projectId||o?.projectId||process.env.VAIF_PROJECT_ID||t.projectId||null}async function De(e){let o=M(),t=I();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let s=e.config||"vaif.config.json",c=null;try{c=await a(s);}catch{}let r=Ce(e,c,t);r||(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));let i=e.name||`cli-key-${Date.now()}`;console.log(""),console.log(l.bold("VAIF Generate API Key")),console.log(""),o.start("Generating API key...");try{let n=await fetch(`${ke}/v1/projects/${r}/api-keys`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"Content-Type":"application/json"},body:JSON.stringify({name:i})});if(!n.ok){let f=await n.text();throw new Error(`Failed to generate key: ${f}`)}let a=await n.json();o.succeed("API key generated"),console.log(""),console.log(l.green(` Name: ${a.name}`)),console.log(l.green(` Key: ${a.key}`)),console.log(""),console.log(l.yellow.bold(" Save this key now - it will not be shown again!")),console.log("");}catch(n){o.fail("Failed to generate API key"),n instanceof Error&&console.log(l.red(`
|
|
33
|
+
Error: ${n.message}`)),process.exit(1);}}async function Ee(e){let o=M(),t=I();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let s=e.config||"vaif.config.json",c=null;try{c=await a(s);}catch{}let r=Ce(e,c,t);r||(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)),console.log(""),console.log(l.bold("VAIF API Keys")),console.log(""),o.start("Fetching API keys...");try{let i=await fetch(`${ke}/v1/projects/${r}/api-keys`,{headers:{Authorization:`Bearer ${t.token}`}});if(!i.ok){let d=await i.text();throw new Error(`Failed to list keys: ${d}`)}let n=await i.json(),a=n.keys||n;if(o.stop(),!Array.isArray(a)||a.length===0){console.log(l.yellow("No API keys found")),console.log(l.gray(`
|
|
34
34
|
Generate one with: vaif keys generate`));return}let f=Math.max(8,...a.map(d=>(d.name||"").length)),p=` ${"Name".padEnd(f)} ${"Key".padEnd(24)} Created`;console.log(l.gray(p)),console.log(l.gray(" "+"-".repeat(p.length-2)));for(let d of a){let g=(d.name||"unnamed").padEnd(f),y=d.maskedKey||d.prefix||`${(d.key||"").slice(0,12)}...`,w=d.createdAt?new Date(d.createdAt).toLocaleDateString():"N/A";console.log(` ${g} ${y.padEnd(24)} ${w}`);}console.log(""),console.log(l.gray(` ${a.length} key(s) total`)),console.log("");}catch(i){o.fail("Failed to list API keys"),i instanceof Error&&console.log(l.red(`
|
|
35
|
-
Error: ${i.message}`)),process.exit(1);}}var
|
|
36
|
-
Error: ${a.message}`)),process.exit(1);}}async function
|
|
35
|
+
Error: ${i.message}`)),process.exit(1);}}var T=process.env.VAIF_API_URL||"https://api.vaif.studio";function jo(e,o,t){return e.projectId||o?.projectId||process.env.VAIF_PROJECT_ID||t.projectId||null}function W(){let e=I();return (!e||!e.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1)),e}async function G(e){try{return await a(e||"vaif.config.json")}catch{return null}}function Y(e,o,t){let s=jo(e,o,t);return s||(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)),s}async function Re(e,o,t){let s=M(),c=W(),r=await G(t.config),i=Y(t,r,c),n=o;if(t.fromFile)try{n=D.readFileSync(t.fromFile,"utf-8");}catch(a){console.log(l.red(`Failed to read file: ${t.fromFile}`)),a instanceof Error&&console.log(l.gray(a.message)),process.exit(1);}n||(console.log(l.red("No value provided")),console.log(l.gray("Provide a value as argument or use --from-file <path>")),process.exit(1)),console.log(""),console.log(l.bold("VAIF Set Secret")),console.log(""),s.start("Checking for existing secret...");try{let a=new URL(`${T}/functions/secrets/project/${i}`);t.envId&&a.searchParams.set("envId",t.envId);let f=await fetch(a.toString(),{headers:{Authorization:`Bearer ${c.token}`}});if(!f.ok)throw new Error(`Failed to check existing secrets: ${await f.text()}`);let d=(await f.json()).find(g=>g.key===e);if(d){s.text=`Updating secret "${e}"...`;let g=await fetch(`${T}/functions/secrets/${d.id}`,{method:"PUT",headers:{Authorization:`Bearer ${c.token}`,"Content-Type":"application/json"},body:JSON.stringify({value:n})});if(!g.ok)throw new Error(`Failed to update secret: ${await g.text()}`);s.succeed(`Updated secret "${e}"`);}else {s.text=`Creating secret "${e}"...`;let g=await fetch(`${T}/functions/secrets`,{method:"POST",headers:{Authorization:`Bearer ${c.token}`,"Content-Type":"application/json"},body:JSON.stringify({projectId:i,envId:t.envId,key:e,value:n})});if(!g.ok)throw new Error(`Failed to create secret: ${await g.text()}`);s.succeed(`Created secret "${e}"`);}console.log("");}catch(a){s.fail("Failed to set secret"),a instanceof Error&&console.log(l.red(`
|
|
36
|
+
Error: ${a.message}`)),process.exit(1);}}async function Oe(e){let o=M(),t=W(),s=await G(e.config),c=Y(e,s,t);console.log(""),console.log(l.bold("VAIF Secrets")),console.log(""),o.start("Fetching secrets...");try{let r=new URL(`${T}/functions/secrets/project/${c}`);e.envId&&r.searchParams.set("envId",e.envId);let i=await fetch(r.toString(),{headers:{Authorization:`Bearer ${t.token}`}});if(!i.ok)throw new Error(`Failed to list secrets: ${await i.text()}`);let n=await i.json();if(o.stop(),n.length===0){console.log(l.yellow("No secrets found")),console.log(l.gray(`
|
|
37
37
|
Create one with: vaif secrets set <name> <value>`));return}let a=Math.max(8,...n.map(p=>p.key.length)),f=` ${"Name".padEnd(a)} Created`;console.log(l.gray(f)),console.log(l.gray(" "+"-".repeat(f.length-2)));for(let p of n){let d=p.key.padEnd(a),g=p.createdAt?new Date(p.createdAt).toLocaleDateString():"N/A";console.log(` ${d} ${g}`);}console.log(""),console.log(l.gray(` ${n.length} secret(s) total`)),console.log(l.gray(" Values are hidden. Use `vaif secrets get <name>` to reveal.")),console.log("");}catch(r){o.fail("Failed to list secrets"),r instanceof Error&&console.log(l.red(`
|
|
38
|
-
Error: ${r.message}`)),process.exit(1);}}async function
|
|
39
|
-
Error: ${i.message}`)),process.exit(1);}}async function
|
|
40
|
-
Error: ${i.message}`)),process.exit(1);}}var
|
|
41
|
-
Error: ${i.message}`)),process.exit(1);}}var
|
|
42
|
-
Error: ${i.message}`)),process.exit(1);}}program.name("vaif").description("VAIF CLI - Type generation and development tools").version(
|
|
38
|
+
Error: ${r.message}`)),process.exit(1);}}async function Ne(e,o){let t=M(),s=W(),c=await G(o.config),r=Y(o,c,s);console.log(""),t.start("Fetching secret...");try{let i=new URL(`${T}/functions/secrets/project/${r}`);o.envId&&i.searchParams.set("envId",o.envId);let n=await fetch(i.toString(),{headers:{Authorization:`Bearer ${s.token}`}});if(!n.ok)throw new Error(`Failed to fetch secrets: ${await n.text()}`);let f=(await n.json()).find(g=>g.key===e);f||(t.fail(`Secret "${e}" not found`),process.exit(1));let p=await fetch(`${T}/functions/secrets/${f.id}/value`,{headers:{Authorization:`Bearer ${s.token}`}});if(!p.ok)throw new Error(`Failed to get secret value: ${await p.text()}`);let d=await p.json();t.stop(),console.log(d.value);}catch(i){t.fail("Failed to get secret"),i instanceof Error&&console.log(l.red(`
|
|
39
|
+
Error: ${i.message}`)),process.exit(1);}}async function Ve(e,o){let t=M(),s=W(),c=await G(o.config),r=Y(o,c,s);console.log(""),console.log(l.bold("VAIF Delete Secret")),console.log(""),t.start("Finding secret...");try{let i=new URL(`${T}/functions/secrets/project/${r}`);o.envId&&i.searchParams.set("envId",o.envId);let n=await fetch(i.toString(),{headers:{Authorization:`Bearer ${s.token}`}});if(!n.ok)throw new Error(`Failed to fetch secrets: ${await n.text()}`);let f=(await n.json()).find(d=>d.key===e);f||(t.fail(`Secret "${e}" not found`),process.exit(1)),t.text=`Deleting secret "${e}"...`;let p=await fetch(`${T}/functions/secrets/${f.id}`,{method:"DELETE",headers:{Authorization:`Bearer ${s.token}`}});if(!p.ok)throw new Error(`Failed to delete secret: ${await p.text()}`);t.succeed(`Deleted secret "${e}"`),console.log("");}catch(i){t.fail("Failed to delete secret"),i instanceof Error&&console.log(l.red(`
|
|
40
|
+
Error: ${i.message}`)),process.exit(1);}}var Te=process.env.VAIF_API_URL||"https://api.vaif.studio";function Io(e){try{let o=new URL(e);return o.password&&(o.password="****"),o.toString()}catch{return e.replace(/:[^@/]+@/,":****@")}}async function Le(e){let o=M(),t=I();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let s=e.config||"vaif.config.json",c=null;try{c=await a(s);}catch{}let r=e.projectId||c?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;r||(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 i=await fetch(`${Te}/v1/projects/${r}`,{headers:{Authorization:`Bearer ${t.token}`}});if(!i.ok){let p=await i.text();throw new Error(`Failed to fetch project: ${p}`)}let n=await i.json();o.stop(),console.log(""),console.log(l.bold("VAIF Project Info")),console.log("");let a=16,f=(p,d)=>{console.log(` ${l.gray(p.padEnd(a))} ${d}`);};f("Name:",l.white(n.name||"N/A")),f("Project ID:",l.white(r)),f("Region:",l.white(n.region||"us-east-1")),f("Plan:",l.white(n.plan||n.tier||"free")),f("Created:",l.white(n.createdAt?new Date(n.createdAt).toLocaleDateString():"N/A")),console.log(""),f("API URL:",l.cyan(n.apiUrl||`${Te}/v1`)),f("WS URL:",l.cyan(n.wsUrl||n.realtimeUrl||"N/A")),f("DB URL:",l.cyan(n.databaseUrl?Io(n.databaseUrl):"N/A")),f("Storage URL:",l.cyan(n.storageUrl||"N/A")),console.log("");}catch(i){o.fail("Failed to fetch project info"),i instanceof Error&&console.log(l.red(`
|
|
41
|
+
Error: ${i.message}`)),process.exit(1);}}var bo=process.env.VAIF_API_URL||"https://api.vaif.studio";async function _e(e){let o=M(),t=I();(!t||!t.token)&&(console.log(l.red("Not logged in")),console.log(l.gray("Run `vaif login` first to authenticate")),process.exit(1));let s=e.config||"vaif.config.json",c=null;try{c=await a(s);}catch{}let r=e.projectId||c?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;r||(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 i=await fetch(`${bo}/v1/projects/${r}?include=tables,functions,storage,connections`,{headers:{Authorization:`Bearer ${t.token}`}});if(!i.ok){let w=await i.text();throw new Error(`Failed to fetch project status: ${w}`)}let n=await i.json();o.stop(),console.log(""),console.log(l.bold("VAIF Project Status")),console.log("");let a=22,f=(w,E)=>{console.log(` ${l.gray(w.padEnd(a))} ${E}`);};f("Project:",l.white(n.name||r)),f("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",d=n.functionCount??n.functions?.length??"N/A",g=n.bucketCount??n.storage?.buckets?.length??"N/A",y=n.activeConnections??n.connections??"N/A";f("Tables:",l.white(String(p))),f("Functions:",l.white(String(d))),f("Storage Buckets:",l.white(String(g))),f("Active Connections:",l.white(String(y))),n.usage&&(console.log(""),console.log(l.gray(" --- Usage ---")),console.log(""),n.usage.dbSize&&f("Database Size:",l.white(n.usage.dbSize)),n.usage.storageSize&&f("Storage Size:",l.white(n.usage.storageSize)),n.usage.bandwidth&&f("Bandwidth:",l.white(n.usage.bandwidth)),n.usage.functionInvocations!=null&&f("Function Invocations:",l.white(String(n.usage.functionInvocations)))),console.log("");}catch(i){o.fail("Failed to fetch project status"),i instanceof Error&&console.log(l.red(`
|
|
42
|
+
Error: ${i.message}`)),process.exit(1);}}var Ue="1.7.1",oe=l.hex("#00f0ff"),te=l.hex("#7b61ff"),ne=l.hex("#ff3dff"),se=l.hex("#00ff9d"),v=l.hex("#555570"),L=l.hex("#00f0ff");function So(){console.log(""),console.log(oe(" \u2566 \u2566")+te("\u2554\u2550\u2557\u2566")+ne("\u2554\u2550\u2557 ")+se("\u2554\u2550\u2557\u2566 \u2566")),console.log(oe(" \u255A\u2557\u2554\u255D")+te("\u2560\u2550\u2563\u2551")+ne("\u2560\u2563 ")+se("\u2551 \u2551 \u2551")),console.log(oe(" \u255A\u255D ")+te("\u2569 \u2569\u2569")+ne("\u255A ")+se("\u255A\u2550\u255D\u2569\u2550\u255D\u2569")),console.log(""),console.log(v(" \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(L(" VAIF Studio CLI")+v(` v${Ue}`)),console.log(v(" Build full-stack apps at lightning speed")),console.log(v(" \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(v(" $ ")+L("vaif login")+v(" Authenticate")),console.log(v(" $ ")+L("vaif init -t react-spa")+v(" Scaffold project")),console.log(v(" $ ")+L("vaif db push")+v(" Push migrations")),console.log(v(" $ ")+L("vaif generate")+v(" Generate types")),console.log(v(" $ ")+L("vaif functions deploy")+v(" Deploy functions")),console.log(""),console.log(l.bold(" Categories")),console.log(v(" auth ")+l.white("login, logout, whoami")),console.log(v(" project ")+l.white("init, templates, info, status")),console.log(v(" schema ")+l.white("pull, push, generate")),console.log(v(" database ")+l.white("db push, db pull, db seed, db reset")),console.log(v(" deploy ")+l.white("functions deploy, functions list")),console.log(v(" security ")+l.white("keys, secrets")),console.log(""),console.log(v(" Run ")+L("vaif <command> --help")+v(" for details")),console.log(v(" Docs: ")+l.underline("https://docs.vaif.studio")),console.log("");}program.name("vaif").description("VAIF CLI - Type generation and development tools").version(Ue);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(fe);program.command("logout").description("Log out and remove stored credentials").action(de);program.command("whoami").description("Show current authenticated user").action(pe);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(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(Le);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(_e);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(ue);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(ye);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 ze=program.command("functions").alias("fn").description("Manage serverless functions");ze.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(Ie);ze.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 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(Ae);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(Pe);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(Se);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(xe);var Je=program.command("keys").description("Manage API keys");Je.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(De);Je.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(Ee);var H=program.command("secrets").alias("sec").description("Manage function secrets");H.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(Re);H.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(Oe);H.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(Ne);H.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(Ve);process.argv.slice(2).length||(So(),process.exit(0));program.parse(process.argv);
|