@vaiftech/cli 1.9.7 → 1.9.8
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 +4 -2
- package/dist/cli.cjs +180 -51
- package/dist/cli.js +157 -28
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -234,7 +234,7 @@ vaif keys list # List all keys
|
|
|
234
234
|
Manage encrypted secrets that your VAIF Functions can access at runtime. Secret values are encrypted at rest and injected into function invocations automatically.
|
|
235
235
|
|
|
236
236
|
```bash
|
|
237
|
-
vaif secrets set API_KEY
|
|
237
|
+
vaif secrets set API_KEY YOUR_API_KEY # Create or update a secret
|
|
238
238
|
vaif secrets set CERT --from-file cert.pem # Set secret from file
|
|
239
239
|
vaif secrets list # List secret names (values hidden)
|
|
240
240
|
vaif secrets get API_KEY # Reveal a secret value
|
|
@@ -280,7 +280,9 @@ vaif claude-setup -o ./my-app # Custom output directory
|
|
|
280
280
|
**Generated files:**
|
|
281
281
|
|
|
282
282
|
- **`.mcp.json`** — Configures the `@vaiftech/mcp` server so Claude Code can query your database, manage schema, upload files, invoke functions, and more.
|
|
283
|
-
- **`CLAUDE.md`** — Gives Claude full context about your project: SDK setup with your actual API key, complete database schema with types and constraints, CRUD examples using your real table names, auth/storage/realtime/functions usage patterns, row-level security (RLS), storage policies, edge function deployment, API key management, secrets management,
|
|
283
|
+
- **`CLAUDE.md`** — Gives Claude full context about your project: SDK setup with your actual API key, complete database schema with types and constraints, CRUD examples using your real table names, auth/storage/realtime/functions usage patterns, row-level security (RLS), storage policies, edge function deployment, API key management, secrets management, filter/pagination reference, JSONB subkey filters, compound filters (AND+OR), full-text search, aggregation, FK joins, upsert, `vaif.auth` context in functions, function-to-function invocation, and database triggers.
|
|
284
|
+
|
|
285
|
+
The MCP server also includes guided prompts (`setup-backend`, `add-feature`, `generate-api-code`, `debug-query`) accessible via `/mcp` in Claude Code.
|
|
284
286
|
|
|
285
287
|
## Configuration
|
|
286
288
|
|
package/dist/cli.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
'use strict';require('dotenv/config');var commander=require('commander'),f=require('chalk'),U=require('fs'),_=require('path'),
|
|
2
|
+
'use strict';require('dotenv/config');var module$1=require('module'),commander=require('commander'),f=require('chalk'),U=require('fs'),_=require('path'),Pt=require('pg'),Q=require('ora'),Ct=require('prettier'),yt=require('dotenv'),vt=require('os'),child_process=require('child_process'),Ee=require('readline');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var f__default=/*#__PURE__*/_interopDefault(f);var U__default=/*#__PURE__*/_interopDefault(U);var ___default=/*#__PURE__*/_interopDefault(_);var Pt__default=/*#__PURE__*/_interopDefault(Pt);var Q__default=/*#__PURE__*/_interopDefault(Q);var Ct__default=/*#__PURE__*/_interopDefault(Ct);var yt__default=/*#__PURE__*/_interopDefault(yt);var vt__default=/*#__PURE__*/_interopDefault(vt);var Ee__default=/*#__PURE__*/_interopDefault(Ee);var mt=()=>typeof document>"u"?new URL(`file:${__filename}`).href:document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"?document.currentScript.src:new URL("main.js",document.baseURI).href,j=mt();yt__default.default.config();async function A(t){let e=___default.default.resolve(t);if(!U__default.default.existsSync(e))return null;try{let n=U__default.default.readFileSync(e,"utf-8"),o=JSON.parse(n);return o.database?.url&&(o.database.url=Se(o.database.url)),o.api?.apiKey&&(o.api.apiKey=Se(o.api.apiKey)),o}catch{throw new Error(`Failed to parse config file: ${t}`)}}function Se(t){return t.replace(/\$\{([^}]+)\}/g,(e,n)=>process.env[n]||e)}var se=___default.default.join(vt__default.default.homedir(),".vaif"),K=___default.default.join(se,"auth.json"),H=process.env.VAIF_API_URL||"https://api.vaif.studio";function It(){U__default.default.existsSync(se)||U__default.default.mkdirSync(se,{recursive:true});}function Te(t){It(),U__default.default.writeFileSync(K,JSON.stringify(t,null,2),"utf-8"),U__default.default.chmodSync(K,384);}function I(){if(!U__default.default.existsSync(K))return null;try{let t=U__default.default.readFileSync(K,"utf-8");return JSON.parse(t)}catch{return null}}function At(t){let e=Ee__default.default.createInterface({input:process.stdin,output:process.stdout});return new Promise(n=>{e.question(t,o=>{e.close(),n(o);});})}function wt(t){return new Promise(e=>{let n=Ee__default.default.createInterface({input:process.stdin,output:process.stdout});process.stdin;let s=process.stdout.write.bind(process.stdout),i=false;process.stdout.write=((...r)=>i?true:s(...r)),n.question(t,r=>{i=false,process.stdout.write=s,console.log(""),n.close(),e(r);}),i=true;})}function St(t){let e=process.platform,n;e==="darwin"?n=`open "${t}"`:e==="win32"?n=`start "" "${t}"`:n=`xdg-open "${t}"`,child_process.exec(n,o=>{});}function _t(t){return new Promise(e=>setTimeout(e,t))}async function Et(t){try{let e=await fetch(`${H}/auth/me`,{headers:{Authorization:`Bearer ${t}`}});if(e.ok){let n=await e.json();return {valid:!0,email:n.user?.email||n.email}}return {valid:!1}}catch{return {valid:false}}}async function Tt(t){let e=Q__default.default();e.start("Setting up authentication...");let n,o;try{let a=await fetch(`${H}/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 l=await a.json();n=l.code,o=l.url;}catch{e.fail("Failed to connect to VAIF API"),console.log(f__default.default.red(`
|
|
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(` ${o}`)),console.log(""),
|
|
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(` ${o}`)),console.log(""),St(o),e.start("Waiting for browser authentication...");let s=12e4,i=2e3,r=Date.now();for(;Date.now()-r<s;){await _t(i);try{let a=await fetch(`${H}/auth/cli/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:n})});if(!a.ok){let d=await a.json();(d.error==="ExpiredCode"||d.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 l=await a.json();if(l.ok&&l.accessToken){let d={token:l.accessToken,email:l.user?.email,projectId:t,expiresAt:new Date(Date.now()+l.expiresIn*1e3).toISOString()};Te(d),e.succeed("Logged in successfully"),console.log(""),l.user?.email&&console.log(f__default.default.green(` Authenticated as: ${l.user.email}`)),console.log(f__default.default.gray(` Config saved to: ${K}`)),console.log("");return}}catch{}}e.fail("Authentication timed out"),console.log(f__default.default.red(`
|
|
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
|
|
7
|
-
No email provided. Login cancelled.`)),process.exit(1));let n=await
|
|
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 xt(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 At(f__default.default.cyan(" Email: "));(!e||e.trim()==="")&&(console.log(f__default.default.red(`
|
|
7
|
+
No email provided. Login cancelled.`)),process.exit(1));let n=await wt(f__default.default.cyan(" Password: "));(!n||n.trim()==="")&&(console.log(f__default.default.red(`
|
|
8
8
|
No password provided. Login cancelled.`)),process.exit(1));let o=Q__default.default("Authenticating...").start();try{let s=await fetch(`${H}/auth/cli/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e.trim(),password:n})}),i=await s.json();(!s.ok||!i.ok)&&(o.fail("Login failed"),console.log(f__default.default.red(`
|
|
9
9
|
${i.message||"Invalid email or password."}`)),process.exit(1));let r={token:i.accessToken,email:i.user?.email,projectId:t,expiresAt:new Date(Date.now()+i.expiresIn*1e3).toISOString()};Te(r),o.succeed("Logged in successfully"),console.log(""),i.user?.email&&console.log(f__default.default.green(` Authenticated as: ${i.user.email}`)),console.log(f__default.default.gray(` Config saved to: ${K}`)),console.log("");}catch{o.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 xe(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
|
|
11
|
-
Your session has expired. Please login again.`)),process.exit(1)),e.succeed("Authenticated"),console.log(""),console.log(f__default.default.green(` Email: ${o||t.email||"Unknown"}`)),t.projectId&&console.log(f__default.default.green(` Project: ${t.projectId}`)),console.log("");}var jt=process.env.VAIF_API_URL||"https://api.vaif.studio";async function
|
|
10
|
+
Could not connect to VAIF API. Please try again later.`)),process.exit(1);}}async function xe(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 xt(t.projectId):await Tt(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 Pe(){U__default.default.existsSync(K)?(U__default.default.unlinkSync(K),console.log(f__default.default.green("Logged out successfully"))):console.log(f__default.default.yellow("Not currently logged in"));}async function Fe(){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=Q__default.default("Checking authentication...").start(),{valid:n,email:o}=await Et(t.token);n||(e.fail("Session expired"),console.log(f__default.default.yellow(`
|
|
11
|
+
Your session has expired. Please login again.`)),process.exit(1)),e.succeed("Authenticated"),console.log(""),console.log(f__default.default.green(` Email: ${o||t.email||"Unknown"}`)),t.projectId&&console.log(f__default.default.green(` Project: ${t.projectId}`)),console.log("");}var jt=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Rt(t,e){let n=await fetch(`${jt}/schema-engine/introspect/${e}`,{headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!n.ok){let a=await n.text();throw new Error(`API introspection failed: ${a}`)}let o=await n.json();if(!o.ok||!o.schemaExists)throw new Error("Project schema does not exist yet. Push a migration first with `vaif db push`.");let s=new Map,i=[];for(let a of o.tables){let l=a.columns.map(d=>({column_name:d.name,data_type:d.type,is_nullable:d.nullable?"YES":"NO",column_default:d.default,udt_name:d.type,is_identity:d.primaryKey&&d.default?.includes("gen_random_uuid")?"YES":"NO",character_maximum_length:null,numeric_precision:null,numeric_scale:null}));s.set(a.name,l);for(let d of a.foreignKeys)i.push({constraint_name:d.constraintName,table_name:a.name,column_name:d.columnName,foreign_table_name:d.refTable,foreign_column_name:d.refColumn});}return {tables:s,enums:new Map,foreignKeys:i}}async function kt(t,e){let n=await t.query(`
|
|
12
12
|
SELECT table_name, table_type
|
|
13
13
|
FROM information_schema.tables
|
|
14
14
|
WHERE table_schema = $1
|
|
@@ -54,9 +54,9 @@ Your session has expired. Please login again.`)),process.exit(1)),e.succeed("Aut
|
|
|
54
54
|
JOIN pg_namespace n ON n.oid = t.typnamespace
|
|
55
55
|
WHERE n.nspname = $1
|
|
56
56
|
ORDER BY t.typname, e.enumsortorder
|
|
57
|
-
`,[e]),r=new Map;for(let l of n.rows)r.set(l.table_name,[]);for(let l of o.rows){let d=r.get(l.table_name);d&&d.push(l);}let a=new Map;for(let l of i.rows){let d=a.get(l.enum_name)||[];d.push(l.enum_value),a.set(l.enum_name,d);}return {tables:r,enums:a,foreignKeys:s.rows}}var ce={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
|
|
57
|
+
`,[e]),r=new Map;for(let l of n.rows)r.set(l.table_name,[]);for(let l of o.rows){let d=r.get(l.table_name);d&&d.push(l);}let a=new Map;for(let l of i.rows){let d=a.get(l.enum_name)||[];d.push(l.enum_value),a.set(l.enum_name,d);}return {tables:r,enums:a,foreignKeys:s.rows}}var ce={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 Nt(t,e){let{data_type:n,udt_name:o,is_nullable:s}=t;if(e.has(o)){let a=e.get(o).map(l=>`"${l}"`).join(" | ");return s==="YES"?`(${a}) | null`:a}if(n==="ARRAY"){let r=o.replace(/^_/,"");if(e.has(r)){let d=e.get(r).map(p=>`"${p}"`).join(" | ");return s==="YES"?`(${d})[] | null`:`(${d})[]`}let a=ce[r]||"unknown";return s==="YES"?`${a}[] | null`:`${a}[]`}let i=ce[n]||ce[o]||"unknown";return s==="YES"&&(i=`${i} | null`),i}function de(t){return t.split(/[_\-\s]+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join("")}function Lt(t,e){let n=de(t),o=e.map(s=>` | "${s}"`).join(`
|
|
58
58
|
`);return `export type ${n} =
|
|
59
|
-
${o};`}function
|
|
59
|
+
${o};`}function Dt(t,e,n){let o=de(t),s=[],i=[],r=[];for(let p of e){let u=Nt(p,n),c=p.column_name,g=p.column_default!==null||p.is_identity==="YES",h=p.is_nullable==="YES";s.push(` ${c}: ${u};`),g||p.column_name==="id"?i.push(` ${c}?: ${u.replace(" | null","")} | null;`):h?i.push(` ${c}?: ${u};`):i.push(` ${c}: ${u.replace(" | null","")};`),r.push(` ${c}?: ${u.replace(" | null","")} | null;`);}let a=`export interface ${o} {
|
|
60
60
|
${s.join(`
|
|
61
61
|
`)}
|
|
62
62
|
}`,l=`export interface ${o}Insert {
|
|
@@ -65,11 +65,11 @@ ${i.join(`
|
|
|
65
65
|
}`,d=`export interface ${o}Update {
|
|
66
66
|
${r.join(`
|
|
67
67
|
`)}
|
|
68
|
-
}`;return {base:a,insert:l,update:d}}function
|
|
69
|
-
`)}async function
|
|
68
|
+
}`;return {base:a,insert:l,update:d}}function Vt(t,e,n){let o=["/**"," * 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){o.push("// ============ ENUMS ============"),o.push("");for(let[i,r]of e)o.push(Lt(i,r)),o.push("");}o.push("// ============ TABLES ============"),o.push("");let s=[];for(let[i,r]of t){let{base:a,insert:l,update:d}=Dt(i,r,e);s.push(i),o.push(a),o.push(""),o.push(l),o.push(""),o.push(d),o.push("");}o.push("// ============ DATABASE SCHEMA ============"),o.push(""),o.push("export interface Database {");for(let i of s){let r=de(i);o.push(` ${i}: {`),o.push(` Row: ${r};`),o.push(` Insert: ${r}Insert;`),o.push(` Update: ${r}Update;`),o.push(" };");}return o.push("}"),o.push(""),o.push("export type TableName = keyof Database;"),o.push(""),o.push("// ============ HELPER TYPES ============"),o.push(""),o.push('export type Row<T extends TableName> = Database[T]["Row"];'),o.push('export type Insert<T extends TableName> = Database[T]["Insert"];'),o.push('export type Update<T extends TableName> = Database[T]["Update"];'),o.push(""),o.join(`
|
|
69
|
+
`)}async function je(t){let e=Q__default.default("Loading configuration...").start();try{let n=await A(t.config),o=t.connection||n?.database?.url||process.env.DATABASE_URL,s=o&&!o.includes("${"),i,r,a;if(s){e.text="Connecting to database...";let c=new Pt__default.default.Client({connectionString:o});await c.connect(),e.text="Introspecting schema...",{tables:i,enums:r,foreignKeys:a}=await kt(c,t.schema),await c.end();}else {let c=I();(!c||!c.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 g=n?.projectId||process.env.VAIF_PROJECT_ID||c.projectId;g||(e.fail("No project ID specified"),console.log(f__default.default.yellow(`
|
|
71
|
-
Set projectId in vaif.config.json or use VAIF_PROJECT_ID env var.`)),process.exit(1)),e.text="Introspecting schema via API...",{tables:i,enums:r,foreignKeys:a}=await
|
|
72
|
-
Push a migration first: vaif db push`));return}e.text=`Generating types for ${i.size} tables...`;let l=
|
|
71
|
+
Set projectId in vaif.config.json or use VAIF_PROJECT_ID env var.`)),process.exit(1)),e.text="Introspecting schema via API...",{tables:i,enums:r,foreignKeys:a}=await Rt(c.token,g);}if(i.size===0){e.warn("No tables found"),console.log(f__default.default.yellow(`
|
|
72
|
+
Push a migration first: vaif db push`));return}e.text=`Generating types for ${i.size} tables...`;let l=Vt(i,r,a),d=await Ct__default.default.format(l,{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(d),console.log(f__default.default.gray("\u2500".repeat(60)));return}let p=___default.default.resolve(t.output),u=___default.default.dirname(p);U__default.default.existsSync(u)||U__default.default.mkdirSync(u,{recursive:!0}),U__default.default.writeFileSync(p,d,"utf-8"),e.succeed(`Generated types for ${i.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: ${i.size}`)),console.log(f__default.default.gray(` Enums: ${r.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(n){e.fail("Failed to generate types"),n instanceof Error&&(console.error(f__default.default.red(`
|
|
73
73
|
Error: ${n.message}`)),n.message.includes("ECONNREFUSED")&&console.log(f__default.default.yellow(`
|
|
74
74
|
Make sure your database is running and accessible.`))),process.exit(1);}}var q=[{name:"database",label:"Database",description:"CRUD queries, type-safe operations"},{name:"auth",label:"Authentication",description:"login, signup, OAuth, sessions"},{name:"realtime",label:"Realtime",description:"live subscriptions, presence"},{name:"storage",label:"Storage",description:"file uploads, signed URLs"},{name:"functions",label:"Functions",description:"serverless function calls"}],ke={"nextjs-fullstack":{name:"Next.js Full-Stack",description:"Next.js app with server/client VAIF client, auth middleware, and React hooks",tag:"Next.js",defaultFeatures:["database","auth"],files:[{path:"package.json",content:`{
|
|
75
75
|
"name": "my-vaif-app",
|
|
@@ -3775,58 +3775,58 @@ export const posts = pgTable("posts", {
|
|
|
3775
3775
|
|
|
3776
3776
|
return Response.json({ message: \`Hello, \${name}!\` });
|
|
3777
3777
|
}
|
|
3778
|
-
`}]},dependencies:["@vaiftech/client","@vaiftech/auth"],postInstructions:["Copy .env.example to .env.local and fill in your project credentials","Create a 'product-images' storage bucket in your VAIF dashboard","Import storage helpers from '@/lib/storage' in your API routes","Use uploadProductImage() in your product creation flow","Run: npx vaif generate to generate TypeScript types"]}};function Ne(){console.log(""),console.log(f__default.default.bold("Available project templates")),console.log("");let t=26,e=22;console.log(` ${f__default.default.gray("Template".padEnd(t))}${f__default.default.gray("Stack".padEnd(e))}${f__default.default.gray("Description")}`),console.log(f__default.default.gray(" "+"-".repeat(t+e+40)));for(let[n,o]of Object.entries(ke))console.log(` ${f__default.default.cyan(n.padEnd(t))}${f__default.default.yellow(o.tag.padEnd(e))}${f__default.default.white(o.description)}`);console.log(""),console.log(f__default.default.gray("Usage:")),console.log(f__default.default.gray(" npx @vaiftech/cli init --template <name>")),console.log(f__default.default.gray(" npx @vaiftech/cli init -t nextjs-fullstack")),console.log(f__default.default.gray(" npx @vaiftech/cli init -t react-spa --features auth,database,realtime")),console.log(""),console.log(f__default.default.gray("Available features: auth, database, realtime, storage, functions")),console.log("");}async function
|
|
3779
|
-
? Which VAIF features do you want to include?`)),q.forEach((a,l)=>{let d=e.has(l)?f__default.default.green("[x]"):"[ ]",
|
|
3778
|
+
`}]},dependencies:["@vaiftech/client","@vaiftech/auth"],postInstructions:["Copy .env.example to .env.local and fill in your project credentials","Create a 'product-images' storage bucket in your VAIF dashboard","Import storage helpers from '@/lib/storage' in your API routes","Use uploadProductImage() in your product creation flow","Run: npx vaif generate to generate TypeScript types"]}};function Ne(){console.log(""),console.log(f__default.default.bold("Available project templates")),console.log("");let t=26,e=22;console.log(` ${f__default.default.gray("Template".padEnd(t))}${f__default.default.gray("Stack".padEnd(e))}${f__default.default.gray("Description")}`),console.log(f__default.default.gray(" "+"-".repeat(t+e+40)));for(let[n,o]of Object.entries(ke))console.log(` ${f__default.default.cyan(n.padEnd(t))}${f__default.default.yellow(o.tag.padEnd(e))}${f__default.default.white(o.description)}`);console.log(""),console.log(f__default.default.gray("Usage:")),console.log(f__default.default.gray(" npx @vaiftech/cli init --template <name>")),console.log(f__default.default.gray(" npx @vaiftech/cli init -t nextjs-fullstack")),console.log(f__default.default.gray(" npx @vaiftech/cli init -t react-spa --features auth,database,realtime")),console.log(""),console.log(f__default.default.gray("Available features: auth, database, realtime, storage, functions")),console.log("");}async function Ut(t){if(!process.stdin.isTTY||!process.stdout.isTTY)return t;let e=new Set(t.map(o=>q.findIndex(s=>s.name===o)).filter(o=>o>=0)),n=0;return new Promise(o=>{let s=Ee__default.default.createInterface({input:process.stdin,output:process.stdout});Ee__default.default.emitKeypressEvents(process.stdin,s),process.stdin.setRawMode&&process.stdin.setRawMode(true);function i(){let a=q.length+2;process.stdout.write(`\x1B[${a}A`),r();}function r(){console.log(f__default.default.bold(`
|
|
3779
|
+
? Which VAIF features do you want to include?`)),q.forEach((a,l)=>{let d=e.has(l)?f__default.default.green("[x]"):"[ ]",p=l===n?f__default.default.cyan("> "):" ";console.log(`${p}${d} ${a.label} ${f__default.default.gray(`(${a.description})`)}`);}),console.log(f__default.default.gray(" (up/down to move, space to toggle, enter to confirm)"));}r(),process.stdin.on("keypress",(a,l)=>{if(l.name==="up"&&n>0)n--,i();else if(l.name==="down"&&n<q.length-1)n++,i();else if(l.name==="space")e.has(n)?e.delete(n):e.add(n),i();else if(l.name==="return"){process.stdin.setRawMode&&process.stdin.setRawMode(false),s.close();let d=[...e].sort().map(p=>q[p].name);o(d.length>0?d:t);}else l.name==="c"&&l.ctrl&&(process.stdin.setRawMode&&process.stdin.setRawMode(false),s.close(),process.exit(0));});})}async function pe(t,e={}){let n=ke[t];n||(console.log(f__default.default.red(`
|
|
3780
3780
|
Unknown template: ${t}`)),console.log(f__default.default.yellow(`Run 'vaif templates' to see available templates.
|
|
3781
3781
|
`)),process.exit(1));let o;e.features&&e.features.length>0?o=e.features.filter(c=>q.some(g=>g.name===c)):e.addOnly?(console.log(f__default.default.red(`
|
|
3782
|
-
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)):n.featureFiles&&Object.keys(n.featureFiles).length>0?o=await
|
|
3783
|
-
`,"utf-8"),console.log(f__default.default.green(` merge ${c.path} (added dependencies)`)),l++;continue}catch{}if(U__default.default.existsSync(g)&&!e.force){console.log(f__default.default.yellow(` skip ${c.path} (already exists)`)),d++;continue}U__default.default.writeFileSync(g,c.content,"utf-8"),console.log(f__default.default.green(` create ${c.path}`)),l++;}console.log(""),l>0&&console.log(f__default.default.green(`Created ${l} file${l!==1?"s":""}.`)),d>0&&console.log(f__default.default.yellow(`Skipped ${d} file${d!==1?"s":""} (use --force to overwrite).`));let
|
|
3784
|
-
`,"utf-8");}catch{}(n.dependencies?.length||n.devDependencies?.length)&&(console.log(""),console.log(f__default.default.bold("Install dependencies:")),n.dependencies?.length&&console.log(f__default.default.cyan(` npm install ${n.dependencies.join(" ")}`)),n.devDependencies?.length&&console.log(f__default.default.cyan(` npm install -D ${n.devDependencies.join(" ")}`))),console.log(""),console.log(f__default.default.bold.green("Project scaffolded successfully!")),console.log(""),console.log(f__default.default.bold(" Next steps:")),n.postInstructions.forEach(c=>{console.log(f__default.default.gray(` ${c}`));}),console.log(""),console.log(f__default.default.gray(" Get your project credentials at https://vaif.studio/app/security/api-keys")),console.log("");}var
|
|
3785
|
-
--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 o=t.addFeatures.split(",").map(s=>s.trim());await
|
|
3786
|
-
Use --force to overwrite existing configuration.`)),process.exit(1));try{if(U__default.default.writeFileSync(n,JSON.stringify(
|
|
3782
|
+
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)):n.featureFiles&&Object.keys(n.featureFiles).length>0?o=await Ut(n.defaultFeatures??["database","auth"]):o=n.defaultFeatures??[],e.addOnly?(console.log(""),console.log(f__default.default.bold(`Adding features to ${f__default.default.cyan(n.name)} project...`)),console.log(f__default.default.gray(` Features: ${o.join(", ")}`)),console.log("")):(console.log(""),console.log(f__default.default.bold(`Scaffolding ${f__default.default.cyan(n.name)} template...`)),o.length>0&&console.log(f__default.default.gray(` Features: ${o.join(", ")}`)),console.log(""));let s=e.addOnly?[]:[...n.files],i=new Set,r=[];if(n.featureFiles)for(let c of o){let g=n.featureFiles[c];if(g)for(let h of g)i.add(h.path),r.push(h);}let a=s.filter(c=>!i.has(c.path)).concat(r),l=0,d=0;for(let c of a){let g=___default.default.resolve(c.path),h=___default.default.dirname(g);if(U__default.default.existsSync(h)||U__default.default.mkdirSync(h,{recursive:true}),c.path==="package.json"&&U__default.default.existsSync(g)&&!e.force)try{let T=JSON.parse(U__default.default.readFileSync(g,"utf-8")),D=JSON.parse(c.content),$=Ie=>{if(!Ie)return {};let Ae={};for(let[gt,W]of Object.entries(Ie))!W.startsWith("workspace:")&&!W.startsWith("link:")&&!W.startsWith("file:")&&(Ae[gt]=W);return Ae};T.dependencies={...$(T.dependencies),...D.dependencies||{}},T.devDependencies={...$(T.devDependencies),...D.devDependencies||{}},D.scripts&&(T.scripts={...T.scripts||{},...D.scripts}),U__default.default.writeFileSync(g,JSON.stringify(T,null,2)+`
|
|
3783
|
+
`,"utf-8"),console.log(f__default.default.green(` merge ${c.path} (added dependencies)`)),l++;continue}catch{}if(U__default.default.existsSync(g)&&!e.force){console.log(f__default.default.yellow(` skip ${c.path} (already exists)`)),d++;continue}U__default.default.writeFileSync(g,c.content,"utf-8"),console.log(f__default.default.green(` create ${c.path}`)),l++;}console.log(""),l>0&&console.log(f__default.default.green(`Created ${l} file${l!==1?"s":""}.`)),d>0&&console.log(f__default.default.yellow(`Skipped ${d} file${d!==1?"s":""} (use --force to overwrite).`));let p={auth:{"@vaiftech/auth":"^1.0.0"},database:{},realtime:{},storage:{},functions:{}},u=___default.default.resolve("package.json");if(U__default.default.existsSync(u)&&o.length>0)try{let c=JSON.parse(U__default.default.readFileSync(u,"utf-8")),g=!1;for(let h of o){let T=p[h];if(T)for(let[D,$]of Object.entries(T))c.dependencies?.[D]||(c.dependencies=c.dependencies||{},c.dependencies[D]=$,g=!0);}g&&U__default.default.writeFileSync(u,JSON.stringify(c,null,2)+`
|
|
3784
|
+
`,"utf-8");}catch{}(n.dependencies?.length||n.devDependencies?.length)&&(console.log(""),console.log(f__default.default.bold("Install dependencies:")),n.dependencies?.length&&console.log(f__default.default.cyan(` npm install ${n.dependencies.join(" ")}`)),n.devDependencies?.length&&console.log(f__default.default.cyan(` npm install -D ${n.devDependencies.join(" ")}`))),console.log(""),console.log(f__default.default.bold.green("Project scaffolded successfully!")),console.log(""),console.log(f__default.default.bold(" Next steps:")),n.postInstructions.forEach(c=>{console.log(f__default.default.gray(` ${c}`));}),console.log(""),console.log(f__default.default.gray(" Get your project credentials at https://vaif.studio/app/security/api-keys")),console.log("");}var Ot={$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 Le(t){if(t.addFeatures){t.template||(console.log(f__default.default.red(`
|
|
3785
|
+
--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 o=t.addFeatures.split(",").map(s=>s.trim());await pe(t.template,{force:t.force,features:o,addOnly:true});return}let e=Q__default.default("Initializing VAIF configuration...").start(),n=___default.default.resolve("vaif.config.json");U__default.default.existsSync(n)&&!t.force&&(e.fail("vaif.config.json already exists"),console.log(f__default.default.yellow(`
|
|
3786
|
+
Use --force to overwrite existing configuration.`)),process.exit(1));try{if(U__default.default.writeFileSync(n,JSON.stringify(Ot,null,2),"utf-8"),e.succeed("Created vaif.config.json"),t.template){let o=t.features?t.features.split(",").map(s=>s.trim()):void 0;await pe(t.template,{force:t.force,features:o});}else {let o=___default.default.resolve(".env.example");if(U__default.default.existsSync(o)||(U__default.default.writeFileSync(o,`# VAIF Configuration
|
|
3787
3787
|
DATABASE_URL=postgresql://user:password@localhost:5432/database
|
|
3788
3788
|
VAIF_API_KEY=your-api-key
|
|
3789
3789
|
`,"utf-8"),console.log(f__default.default.gray("Created .env.example"))),t.typescript){let s=___default.default.resolve("src/types");U__default.default.existsSync(s)||(U__default.default.mkdirSync(s,{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(o){e.fail("Failed to initialize"),o instanceof Error&&console.error(f__default.default.red(`
|
|
3790
|
-
Error: ${o.message}`)),process.exit(1);}}var
|
|
3790
|
+
Error: ${o.message}`)),process.exit(1);}}var Bt=process.env.VAIF_API_URL||"https://api.vaif.studio";async function qt(t,e,n="public"){let o=await fetch(`${Bt}/projects/${e}/schema?schema=${n}`,{headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!o.ok){let s=await o.text();throw new Error(`Failed to fetch schema: ${s}`)}return o.json()}async function De(t){let e=Q__default.default(),n=I();(!n||!n.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 o=t.config||"vaif.config.json",s=null;e.start("Loading configuration...");try{s=await A(o);}catch(r){e.fail("Failed to load config"),console.log(f__default.default.red(`
|
|
3791
3791
|
Error: ${r}`)),process.exit(1);}s||(e.fail("No configuration found"),console.log(f__default.default.yellow("\nRun `vaif init` to create a configuration file.")),process.exit(1));let i=t.projectId||s.projectId||process.env.VAIF_PROJECT_ID||n.projectId;i||(e.fail("No project ID specified"),console.log(f__default.default.yellow(`
|
|
3792
|
-
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1)),e.text="Fetching remote schema...";try{let r=t.schema||s.database?.schema||"public",a=await
|
|
3793
|
-
Error: ${r.message}`)),process.exit(1);}}var Ue=process.env.VAIF_API_URL||"https://api.vaif.studio";function
|
|
3792
|
+
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1)),e.text="Fetching remote schema...";try{let r=t.schema||s.database?.schema||"public",a=await qt(n.token,i,r);e.succeed("Schema fetched successfully");let l=t.output||___default.default.resolve("vaif.schema.json"),d={$schema:"https://vaif.studio/schemas/schema.json",projectId:i,schema:r,pulledAt:new Date().toISOString(),...a};U__default.default.writeFileSync(l,JSON.stringify(d,null,2),"utf-8"),console.log(""),console.log(f__default.default.green(`Schema saved to: ${l}`)),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(r){e.fail("Failed to fetch schema"),r instanceof Error&&console.log(f__default.default.red(`
|
|
3793
|
+
Error: ${r.message}`)),process.exit(1);}}var Ue=process.env.VAIF_API_URL||"https://api.vaif.studio";function Wt(t){let e=Ee__default.default.createInterface({input:process.stdin,output:process.stdout});return new Promise(n=>{e.question(t,o=>{e.close(),n(o);});})}async function Ht(t,e,n){let o=await fetch(`${Ue}/projects/${e}/schema/preview`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({schema:n})});if(!o.ok){let s=await o.text();throw new Error(`Failed to preview changes: ${s}`)}return o.json()}async function Xt(t,e,n){let o=await fetch(`${Ue}/projects/${e}/schema/apply`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({schema:n})});if(!o.ok){let s=await o.text();throw new Error(`Failed to apply changes: ${s}`)}return o.json()}function Qt(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 n of e.changes)console.log(f__default.default.gray(` ${n}`));}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 $e(t){let e=Q__default.default(),n=I();(!n||!n.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 o=t.config||"vaif.config.json",s=null;e.start("Loading configuration...");try{s=await A(o);}catch(l){e.fail("Failed to load config"),console.log(f__default.default.red(`
|
|
3794
3794
|
Error: ${l}`)),process.exit(1);}s||(e.fail("No configuration found"),console.log(f__default.default.yellow("\nRun `vaif init` to create a configuration file.")),process.exit(1));let i=t.projectId||s.projectId||process.env.VAIF_PROJECT_ID||n.projectId;i||(e.fail("No project ID specified"),console.log(f__default.default.yellow(`
|
|
3795
3795
|
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1));let r=t.schema||___default.default.resolve("vaif.schema.json");U__default.default.existsSync(r)||(e.fail("No local schema found"),console.log(f__default.default.yellow(`
|
|
3796
3796
|
Expected schema file at: ${r}`)),console.log(f__default.default.gray("Run `vaif pull` first to fetch the current schema.")),process.exit(1));let a;try{let l=U__default.default.readFileSync(r,"utf-8");a=JSON.parse(l);}catch(l){e.fail("Failed to parse schema file"),l instanceof Error&&console.log(f__default.default.red(`
|
|
3797
|
-
Error: ${l.message}`)),process.exit(1);}e.text="Calculating schema changes...";try{let{diff:l,sql:d}=await
|
|
3798
|
-
Cancelled. No changes applied.`));return}}e.start("Applying schema changes...");let
|
|
3799
|
-
Error: ${l.message}`)),process.exit(1);}}var X=process.env.VAIF_API_URL||"https://api.vaif.studio";async function
|
|
3797
|
+
Error: ${l.message}`)),process.exit(1);}e.text="Calculating schema changes...";try{let{diff:l,sql:d}=await Ht(n.token,i,a);if(e.stop(),Qt(l),l.added.length===0&&l.modified.length===0&&l.removed.length===0){console.log("");return}if(d.length>0){console.log(f__default.default.bold("SQL Migrations:")),console.log("");for(let u of d)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){l.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 c=await Wt(f__default.default.cyan("Apply these changes? [y/N] "));if(c.toLowerCase()!=="y"&&c.toLowerCase()!=="yes"){console.log(f__default.default.yellow(`
|
|
3798
|
+
Cancelled. No changes applied.`));return}}e.start("Applying schema changes...");let p=await Xt(n.token,i,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(l){e.fail("Failed to push schema changes"),l instanceof Error&&console.log(f__default.default.red(`
|
|
3799
|
+
Error: ${l.message}`)),process.exit(1);}}var X=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Zt(t,e,n,o){let s=new URL(`${X}/functions/project/${e}`);o&&s.searchParams.set("envId",o);let i=await fetch(s.toString(),{headers:{Authorization:`Bearer ${t}`}});if(!i.ok)return null;let r=await i.json(),a=r.functions||r;return Array.isArray(a)&&a.find(l=>l.name===n)||null}async function eo(t,e,n){let o=await fetch(`${X}/functions/`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({projectId:e,name:n.name,runtime:n.runtime,entrypoint:n.entrypoint,envId:n.envId})});if(!o.ok){let s=await o.text();throw new Error(`Failed to create function: ${s}`)}return o.json()}async function to(t,e,n){let o=await fetch(`${X}/functions/${e}/source`,{method:"PUT",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({sourceCode:n})});if(!o.ok){let s=await o.text();throw new Error(`Failed to deploy source: ${s}`)}}async function oo(t,e,n){let o=new URL(`${X}/functions/project/${e}`);n&&o.searchParams.set("envId",n);let s=await fetch(o.toString(),{headers:{Authorization:`Bearer ${t}`}});if(!s.ok){let r=await s.text();throw new Error(`Failed to list functions: ${r}`)}let i=await s.json();return i.functions||i}function Oe(t){switch(___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 Me(t){let e=[],n=[".ts",".js",".mjs",".py",".go",".rs"],o=["drizzle.config.ts","tsconfig.json","package.json"];if(!U__default.default.existsSync(t))return e;let s=U__default.default.readdirSync(t,{withFileTypes:true});for(let i of s){let r=___default.default.join(t,i.name);if(i.isDirectory()){if(i.name!=="node_modules"&&!i.name.startsWith(".")){let a=U__default.default.readdirSync(r,{withFileTypes:true});for(let l of a)if(l.isFile()){let d=___default.default.extname(l.name).toLowerCase();if(n.includes(d)){e.push(___default.default.join(r,l.name));break}}}}else if(i.isFile()){let a=___default.default.extname(i.name).toLowerCase();n.includes(a)&&!o.includes(i.name)&&e.push(r);}}return e}async function ze(t){let e=Q__default.default(),n=I();(!n||!n.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 o=t.config||"vaif.config.json",s=null;try{s=await A(o);}catch{}let i=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||n.projectId;i||(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 r=___default.default.resolve("functions"),a=___default.default.resolve("src/functions"),l=[];if(t.entrypoint){let c=___default.default.resolve(t.entrypoint);U__default.default.existsSync(c)||(e.fail(`File not found: ${t.entrypoint}`),process.exit(1)),l=[c];}else l=[...Me(r),...Me(a)];l.length===0&&(e.fail("No function files found"),console.log(f__default.default.yellow(`
|
|
3800
3800
|
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(`
|
|
3801
3801
|
Or specify an entrypoint with --entrypoint`)),process.exit(1)),e.succeed(`Found ${l.length} function(s)`),t.name&&(l=l.filter(c=>___default.default.basename(c,___default.default.extname(c)).includes(t.name)),l.length===0&&(console.log(f__default.default.yellow(`
|
|
3802
|
-
No functions matching "${t.name}" found`)),process.exit(1))),console.log(""),console.log(f__default.default.gray("Functions to deploy:"));for(let c of l){let g=___default.default.basename(___default.default.dirname(c)),h=g==="functions"||g==="src"?___default.default.basename(c,___default.default.extname(c)):g,T=t.runtime||Oe(c);console.log(f__default.default.gray(` - ${h} (${T})`));}if(console.log(""),t.dryRun){console.log(f__default.default.yellow("Dry run mode - no functions deployed."));return}let d=[];for(let c of l){let g=___default.default.basename(___default.default.dirname(c)),h=g==="functions"||g==="src"?___default.default.basename(c,___default.default.extname(c)):g,T=t.runtime||Oe(c);e.start(`Deploying ${h}...`);try{let D=U__default.default.readFileSync(c,"utf-8"),$=await
|
|
3802
|
+
No functions matching "${t.name}" found`)),process.exit(1))),console.log(""),console.log(f__default.default.gray("Functions to deploy:"));for(let c of l){let g=___default.default.basename(___default.default.dirname(c)),h=g==="functions"||g==="src"?___default.default.basename(c,___default.default.extname(c)):g,T=t.runtime||Oe(c);console.log(f__default.default.gray(` - ${h} (${T})`));}if(console.log(""),t.dryRun){console.log(f__default.default.yellow("Dry run mode - no functions deployed."));return}let d=[];for(let c of l){let g=___default.default.basename(___default.default.dirname(c)),h=g==="functions"||g==="src"?___default.default.basename(c,___default.default.extname(c)):g,T=t.runtime||Oe(c);e.start(`Deploying ${h}...`);try{let D=U__default.default.readFileSync(c,"utf-8"),$=await Zt(n.token,i,h,t.envId);$||(e.text=`Creating ${h}...`,$=await eo(n.token,i,{name:h,runtime:T,entrypoint:___default.default.basename(c),envId:t.envId})),e.text=`Deploying ${h}...`,await to(n.token,$.id,D),e.succeed(`Deployed ${h}`),d.push({name:h,success:!0});}catch(D){let $=D instanceof Error?D.message:"Unknown error";e.fail(`Failed to deploy ${h}`),d.push({name:h,success:false,error:$});}}console.log("");let p=d.filter(c=>c.success).length;if(d.filter(c=>!c.success).length===0)console.log(f__default.default.green(`\u2713 Successfully deployed ${p} function(s)`));else {console.log(f__default.default.yellow(`Deployed ${p}/${d.length} function(s)`)),console.log(""),console.log(f__default.default.red("Failed deployments:"));for(let c of d.filter(g=>!g.success))console.log(f__default.default.red(` - ${c.name}: ${c.error}`));}console.log("");}async function Be(t){let e=Q__default.default(),n=I();(!n||!n.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 o=t.config||"vaif.config.json",s=null;try{s=await A(o);}catch{}let i=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||n.projectId;i||(console.log(f__default.default.red("No project ID specified")),process.exit(1)),e.start("Fetching functions...");try{let r=await oo(n.token,i,t.envId);if(e.stop(),r.length===0){console.log(f__default.default.yellow(`
|
|
3803
3803
|
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 (${r.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 r){let l=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)+l(a.deployStatus.padEnd(12))+String(a.invocationCount??0).padEnd(14)+(a.deployedAt?new Date(a.deployedAt).toLocaleDateString():"-"));}console.log("");}catch(r){e.fail("Failed to fetch functions"),r instanceof Error&&console.log(f__default.default.red(`
|
|
3804
|
-
Error: ${r.message}`)),process.exit(1);}}var Z=process.env.VAIF_API_URL||"https://api.vaif.studio";async function
|
|
3804
|
+
Error: ${r.message}`)),process.exit(1);}}var Z=process.env.VAIF_API_URL||"https://api.vaif.studio";async function no(t,e,n,o,s){let i=await fetch(`${Z}/projects/${e}/db/seed`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({table:n,records:o,truncate:s?.truncate??false})});if(!i.ok){let r=await i.text();throw new Error(`Failed to seed ${n}: ${r}`)}return i.json()}async function ao(t,e){let n=await fetch(`${Z}/projects/${e}/db/reset`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!n.ok){let o=await n.text();throw new Error(`Failed to reset database: ${o}`)}return n.json()}function ge(t){let e=[];if(!U__default.default.existsSync(t))return e;let n=U__default.default.readdirSync(t,{withFileTypes:true});for(let o of n)if(o.isFile()){let s=___default.default.extname(o.name).toLowerCase();(s===".json"||s===".ts"||s===".js")&&e.push(___default.default.join(t,o.name));}return e.sort()}async function qe(t){let e=___default.default.extname(t).toLowerCase();if(e===".json"){let n=U__default.default.readFileSync(t,"utf-8"),o=JSON.parse(n);return Array.isArray(o)?[{table:___default.default.basename(t,e),data:o}]:o.table&&o.data?[o]:Object.entries(o).map(([s,i])=>({table:s,data:i}))}else if(e===".ts"||e===".js"){let n=await import(t),o=n.default||n;return typeof o=="function"?o():o}throw new Error(`Unsupported file format: ${e}`)}async function Ye(t){let e=Q__default.default(),n=I();(!n||!n.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 o=t.config||"vaif.config.json",s=null;try{s=await A(o);}catch{}let i=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||n.projectId;i||(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 r=[];if(t.file){let p=___default.default.resolve(t.file);U__default.default.existsSync(p)||(console.log(f__default.default.red(`File not found: ${t.file}`)),process.exit(1)),r=[p];}else {let p=___default.default.resolve("seeds"),u=___default.default.resolve("prisma/seed"),c=___default.default.resolve("db/seeds");r=[...ge(p),...ge(u),...ge(c)];}r.length===0&&(console.log(f__default.default.yellow("No seed files found")),console.log(f__default.default.gray(`
|
|
3805
3805
|
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(`
|
|
3806
3806
|
Or specify a file with --file`)),console.log(f__default.default.gray(`
|
|
3807
|
-
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
|
|
3807
|
+
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 r)console.log(f__default.default.gray(` - ${___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 r){e.start(`Loading ${___default.default.basename(p)}...`);try{let u=await qe(p);e.stop();for(let c of u)t.table&&c.table!==t.table||(console.log(f__default.default.cyan(`Table: ${c.table}`)),console.log(f__default.default.gray(` Records: ${c.data.length}`)),c.data.length>0&&console.log(f__default.default.gray(` Sample: ${JSON.stringify(c.data[0],null,2).slice(0,100)}...`)),console.log(""));}catch(u){e.fail(`Failed to load ${___default.default.basename(p)}`),u instanceof Error&&console.log(f__default.default.red(` Error: ${u.message}`));}}return}let a=[];for(let p of r){e.start(`Processing ${___default.default.basename(p)}...`);try{let u=await qe(p);e.stop();for(let c of u)if(!(t.table&&c.table!==t.table)){if(c.data.length===0){console.log(f__default.default.gray(` Skipping ${c.table} (no records)`));continue}e.start(`Seeding ${c.table} (${c.data.length} records)...`);try{let g=await no(n.token,i,c.table,c.data,{truncate:t.truncate});e.succeed(`Seeded ${c.table}: ${g.inserted} records`),a.push({table:c.table,inserted:g.inserted});}catch(g){let h=g instanceof Error?g.message:"Unknown error";e.fail(`Failed to seed ${c.table}`),a.push({table:c.table,inserted:0,error:h});}}}catch(u){e.fail(`Failed to load ${___default.default.basename(p)}`),u instanceof Error&&console.log(f__default.default.red(` Error: ${u.message}`));}}console.log("");let l=a.reduce((p,u)=>p+u.inserted,0),d=a.filter(p=>p.error).length;if(d===0)console.log(f__default.default.green(`\u2713 Successfully seeded ${l} records across ${a.length} table(s)`));else {console.log(f__default.default.yellow(`Seeded ${l} records with ${d} 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 Je(t){let e=Q__default.default(),n=I();(!n||!n.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 o=t.config||"vaif.config.json",s=null;try{s=await A(o);}catch{}let i=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||n.projectId;i||(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 r=___default.default.resolve(t.dir||"./drizzle");if(console.log(""),console.log(f__default.default.bold("VAIF Database Push")),console.log(""),!U__default.default.existsSync(r)){let u=___default.default.resolve("./migrations");U__default.default.existsSync(u)?console.log(f__default.default.gray(`Using migrations from: ${u}`)):(console.log(f__default.default.red(`Migrations directory not found: ${r}`)),console.log(f__default.default.gray(`
|
|
3808
3808
|
Expected one of:`)),console.log(f__default.default.gray(" - ./drizzle/")),console.log(f__default.default.gray(" - ./migrations/")),console.log(f__default.default.gray(`
|
|
3809
|
-
Or specify with: vaif db push --dir <path>`)),process.exit(1));}let a=[],l=U__default.default.readdirSync(r,{withFileTypes:true});for(let
|
|
3810
|
-
Error: ${a.message}`)),process.exit(1);}}async function We(t){let e=Q__default.default(),n=I();(!n||!n.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 o=t.config||"vaif.config.json",s=null;try{s=await A(o);}catch{}let i=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||n.projectId;i||(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
|
|
3809
|
+
Or specify with: vaif db push --dir <path>`)),process.exit(1));}let a=[],l=U__default.default.readdirSync(r,{withFileTypes:true});for(let u of l)if(u.isFile()&&u.name.endsWith(".sql"))a.push(___default.default.join(r,u.name));else if(u.isDirectory()){let c=U__default.default.readdirSync(___default.default.join(r,u.name),{withFileTypes:true});for(let g of c)g.isFile()&&g.name.endsWith(".sql")&&a.push(___default.default.join(r,u.name,g.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(` - ${___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 c=U__default.default.readFileSync(u,"utf-8");console.log(f__default.default.cyan(`--- ${___default.default.basename(u)} ---`)),console.log(f__default.default.gray(c.slice(0,500))),c.length>500&&console.log(f__default.default.gray("...")),console.log("");}return}let d=0,p=0;for(let u of a){let c=U__default.default.readFileSync(u,"utf-8"),g=___default.default.relative(process.cwd(),u);e.start(`Applying ${g}...`);try{let h=await fetch(`${Z}/schema-engine/query/${i}`,{method:"POST",headers:{Authorization:`Bearer ${n.token}`,"Content-Type":"application/json"},body:JSON.stringify({sql:c})});if(!h.ok){let T=await h.text();throw new Error(T)}e.succeed(`Applied ${g}`),d++;}catch(h){let T=h instanceof Error?h.message:"Unknown error";e.fail(`Failed ${g}: ${T}`),p++;}}console.log(""),console.log(p===0?f__default.default.green(`Successfully applied ${d} migration(s)`):f__default.default.yellow(`Applied ${d}, failed ${p} migration(s)`)),console.log("");}async function Ge(t){let e=Q__default.default(),n=I();(!n||!n.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 o=t.config||"vaif.config.json",s=null;try{s=await A(o);}catch{}let i=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||n.projectId;i||(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 r=___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(`${Z}/schema-engine/introspect/${i}`,{headers:{Authorization:`Bearer ${n.token}`}});if(!a.ok){let p=await a.text();throw new Error(`Failed to pull schema: ${p}`)}let l=await a.json();U__default.default.writeFileSync(r,JSON.stringify(l,null,2),"utf-8"),e.succeed(`Schema written to ${___default.default.relative(process.cwd(),r)}`);let d=l.tables?.length??Object.keys(l).length;console.log(f__default.default.gray(` ${d} table(s) pulled`)),console.log("");}catch(a){e.fail("Failed to pull schema"),a instanceof Error&&console.log(f__default.default.red(`
|
|
3810
|
+
Error: ${a.message}`)),process.exit(1);}}async function We(t){let e=Q__default.default(),n=I();(!n||!n.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 o=t.config||"vaif.config.json",s=null;try{s=await A(o);}catch{}let i=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||n.projectId;i||(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 ao(n.token,i),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(r){e.fail("Failed to reset database"),r instanceof Error&&console.log(f__default.default.red(`
|
|
3811
3811
|
Error: ${r.message}`)),process.exit(1);}}var Xe=process.env.VAIF_API_URL||"https://api.vaif.studio";function Qe(t,e,n){return t.projectId||e?.projectId||process.env.VAIF_PROJECT_ID||n.projectId||null}async function Ze(t){let e=Q__default.default(),n=I();(!n||!n.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 o=t.config||"vaif.config.json",s=null;try{s=await A(o);}catch{}let i=Qe(t,s,n);i||(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 r=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(`${Xe}/projects/${i}/api-keys`,{method:"POST",headers:{Authorization:`Bearer ${n.token}`,"Content-Type":"application/json"},body:JSON.stringify({name:r})});if(!a.ok){let d=await a.text();throw new Error(`Failed to generate key: ${d}`)}let l=await a.json();e.succeed("API key generated"),console.log(""),console.log(f__default.default.green(` Name: ${l.name}`)),console.log(f__default.default.green(` Key: ${l.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(`
|
|
3812
|
-
Error: ${a.message}`)),process.exit(1);}}async function et(t){let e=Q__default.default(),n=I();(!n||!n.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 o=t.config||"vaif.config.json",s=null;try{s=await A(o);}catch{}let i=Qe(t,s,n);i||(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 r=await fetch(`${Xe}/projects/${i}/api-keys`,{headers:{Authorization:`Bearer ${n.token}`}});if(!r.ok){let
|
|
3813
|
-
Generate one with: vaif keys generate`));return}let d=Math.max(8,...l.map(
|
|
3814
|
-
Error: ${r.message}`)),process.exit(1);}}var z=process.env.VAIF_API_URL||"https://api.vaif.studio";function
|
|
3812
|
+
Error: ${a.message}`)),process.exit(1);}}async function et(t){let e=Q__default.default(),n=I();(!n||!n.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 o=t.config||"vaif.config.json",s=null;try{s=await A(o);}catch{}let i=Qe(t,s,n);i||(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 r=await fetch(`${Xe}/projects/${i}/api-keys`,{headers:{Authorization:`Bearer ${n.token}`}});if(!r.ok){let u=await r.text();throw new Error(`Failed to list keys: ${u}`)}let a=await r.json(),l=a.keys||a;if(e.stop(),!Array.isArray(l)||l.length===0){console.log(f__default.default.yellow("No API keys found")),console.log(f__default.default.gray(`
|
|
3813
|
+
Generate one with: vaif keys generate`));return}let d=Math.max(8,...l.map(u=>(u.name||"").length)),p=` ${"Name".padEnd(d)} ${"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 l){let c=(u.name||"unnamed").padEnd(d),g=u.maskedKey||u.prefix||`${(u.key||"").slice(0,12)}...`,h=u.createdAt?new Date(u.createdAt).toLocaleDateString():"N/A";console.log(` ${c} ${g.padEnd(24)} ${h}`);}console.log(""),console.log(f__default.default.gray(` ${l.length} key(s) total`)),console.log("");}catch(r){e.fail("Failed to list API keys"),r instanceof Error&&console.log(f__default.default.red(`
|
|
3814
|
+
Error: ${r.message}`)),process.exit(1);}}var z=process.env.VAIF_API_URL||"https://api.vaif.studio";function so(t,e,n){return t.projectId||e?.projectId||process.env.VAIF_PROJECT_ID||n.projectId||null}function te(){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 oe(t){try{return await A(t||"vaif.config.json")}catch{return null}}function ne(t,e,n){let o=so(t,e,n);return o||(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)),o}async function tt(t,e,n){let o=Q__default.default(),s=te(),i=await oe(n.config),r=ne(n,i,s),a=e;if(n.fromFile)try{a=U__default.default.readFileSync(n.fromFile,"utf-8");}catch(l){console.log(f__default.default.red(`Failed to read file: ${n.fromFile}`)),l instanceof Error&&console.log(f__default.default.gray(l.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(""),o.start("Checking for existing secret...");try{let l=new URL(`${z}/functions/secrets/project/${r}`);n.envId&&l.searchParams.set("envId",n.envId);let d=await fetch(l.toString(),{headers:{Authorization:`Bearer ${s.token}`}});if(!d.ok)throw new Error(`Failed to check existing secrets: ${await d.text()}`);let u=(await d.json()).find(c=>c.key===t);if(u){o.text=`Updating secret "${t}"...`;let c=await fetch(`${z}/functions/secrets/${u.id}`,{method:"PUT",headers:{Authorization:`Bearer ${s.token}`,"Content-Type":"application/json"},body:JSON.stringify({value:a})});if(!c.ok)throw new Error(`Failed to update secret: ${await c.text()}`);o.succeed(`Updated secret "${t}"`);}else {o.text=`Creating secret "${t}"...`;let c=await fetch(`${z}/functions/secrets`,{method:"POST",headers:{Authorization:`Bearer ${s.token}`,"Content-Type":"application/json"},body:JSON.stringify({projectId:r,envId:n.envId,key:t,value:a})});if(!c.ok)throw new Error(`Failed to create secret: ${await c.text()}`);o.succeed(`Created secret "${t}"`);}console.log("");}catch(l){o.fail("Failed to set secret"),l instanceof Error&&console.log(f__default.default.red(`
|
|
3815
3815
|
Error: ${l.message}`)),process.exit(1);}}async function ot(t){let e=Q__default.default(),n=te(),o=await oe(t.config),s=ne(t,o,n);console.log(""),console.log(f__default.default.bold("VAIF Secrets")),console.log(""),e.start("Fetching secrets...");try{let i=new URL(`${z}/functions/secrets/project/${s}`);t.envId&&i.searchParams.set("envId",t.envId);let r=await fetch(i.toString(),{headers:{Authorization:`Bearer ${n.token}`}});if(!r.ok)throw new Error(`Failed to list secrets: ${await r.text()}`);let a=await r.json();if(e.stop(),a.length===0){console.log(f__default.default.yellow("No secrets found")),console.log(f__default.default.gray(`
|
|
3816
|
-
Create one with: vaif secrets set <name> <value>`));return}let l=Math.max(8,...a.map(
|
|
3817
|
-
Error: ${i.message}`)),process.exit(1);}}async function nt(t,e){let n=Q__default.default(),o=te(),s=await oe(e.config),i=ne(e,s,o);console.log(""),n.start("Fetching secret...");try{let r=new URL(`${z}/functions/secrets/project/${i}`);e.envId&&r.searchParams.set("envId",e.envId);let a=await fetch(r.toString(),{headers:{Authorization:`Bearer ${o.token}`}});if(!a.ok)throw new Error(`Failed to fetch secrets: ${await a.text()}`);let d=(await a.json()).find(c=>c.key===t);d||(n.fail(`Secret "${t}" not found`),process.exit(1));let
|
|
3818
|
-
Error: ${r.message}`)),process.exit(1);}}async function at(t,e){let n=Q__default.default(),o=te(),s=await oe(e.config),i=ne(e,s,o);console.log(""),console.log(f__default.default.bold("VAIF Delete Secret")),console.log(""),n.start("Finding secret...");try{let r=new URL(`${z}/functions/secrets/project/${i}`);e.envId&&r.searchParams.set("envId",e.envId);let a=await fetch(r.toString(),{headers:{Authorization:`Bearer ${o.token}`}});if(!a.ok)throw new Error(`Failed to fetch secrets: ${await a.text()}`);let d=(await a.json()).find(
|
|
3819
|
-
Error: ${r.message}`)),process.exit(1);}}var it=process.env.VAIF_API_URL||"https://api.vaif.studio";function
|
|
3820
|
-
Error: ${r.message}`)),process.exit(1);}}var
|
|
3821
|
-
Error: ${r.message}`)),process.exit(1);}}var J=process.env.VAIF_API_URL||"https://api.vaif.studio";function
|
|
3822
|
-
`);for(let r=0;r<o.length;r++)console.log(f__default.default.gray(` ${r+1}.`)+` ${f__default.default.white(o[r].name)} ${f__default.default.gray(`(${o[r].id})`)}`);console.log("");let s=await
|
|
3823
|
-
Invalid selection.`)),null):o[i].id}catch{return e.fail("Could not fetch projects"),null}}function
|
|
3816
|
+
Create one with: vaif secrets set <name> <value>`));return}let l=Math.max(8,...a.map(p=>p.key.length)),d=` ${"Name".padEnd(l)} Created`;console.log(f__default.default.gray(d)),console.log(f__default.default.gray(" "+"-".repeat(d.length-2)));for(let p of a){let u=p.key.padEnd(l),c=p.createdAt?new Date(p.createdAt).toLocaleDateString():"N/A";console.log(` ${u} ${c}`);}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(i){e.fail("Failed to list secrets"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3817
|
+
Error: ${i.message}`)),process.exit(1);}}async function nt(t,e){let n=Q__default.default(),o=te(),s=await oe(e.config),i=ne(e,s,o);console.log(""),n.start("Fetching secret...");try{let r=new URL(`${z}/functions/secrets/project/${i}`);e.envId&&r.searchParams.set("envId",e.envId);let a=await fetch(r.toString(),{headers:{Authorization:`Bearer ${o.token}`}});if(!a.ok)throw new Error(`Failed to fetch secrets: ${await a.text()}`);let d=(await a.json()).find(c=>c.key===t);d||(n.fail(`Secret "${t}" not found`),process.exit(1));let p=await fetch(`${z}/functions/secrets/${d.id}/value`,{headers:{Authorization:`Bearer ${o.token}`}});if(!p.ok)throw new Error(`Failed to get secret value: ${await p.text()}`);let u=await p.json();n.stop(),console.log(u.value);}catch(r){n.fail("Failed to get secret"),r instanceof Error&&console.log(f__default.default.red(`
|
|
3818
|
+
Error: ${r.message}`)),process.exit(1);}}async function at(t,e){let n=Q__default.default(),o=te(),s=await oe(e.config),i=ne(e,s,o);console.log(""),console.log(f__default.default.bold("VAIF Delete Secret")),console.log(""),n.start("Finding secret...");try{let r=new URL(`${z}/functions/secrets/project/${i}`);e.envId&&r.searchParams.set("envId",e.envId);let a=await fetch(r.toString(),{headers:{Authorization:`Bearer ${o.token}`}});if(!a.ok)throw new Error(`Failed to fetch secrets: ${await a.text()}`);let d=(await a.json()).find(u=>u.key===t);d||(n.fail(`Secret "${t}" not found`),process.exit(1)),n.text=`Deleting secret "${t}"...`;let p=await fetch(`${z}/functions/secrets/${d.id}`,{method:"DELETE",headers:{Authorization:`Bearer ${o.token}`}});if(!p.ok)throw new Error(`Failed to delete secret: ${await p.text()}`);n.succeed(`Deleted secret "${t}"`),console.log("");}catch(r){n.fail("Failed to delete secret"),r instanceof Error&&console.log(f__default.default.red(`
|
|
3819
|
+
Error: ${r.message}`)),process.exit(1);}}var it=process.env.VAIF_API_URL||"https://api.vaif.studio";function lo(t){try{let e=new URL(t);return e.password&&(e.password="****"),e.toString()}catch{return t.replace(/:[^@/]+@/,":****@")}}async function st(t){let e=Q__default.default(),n=I();(!n||!n.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 o=t.config||"vaif.config.json",s=null;try{s=await A(o);}catch{}let i=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||n.projectId;i||(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 r=await fetch(`${it}/projects/${i}`,{headers:{Authorization:`Bearer ${n.token}`}});if(!r.ok){let p=await r.text();throw new Error(`Failed to fetch project: ${p}`)}let a=await r.json();e.stop(),console.log(""),console.log(f__default.default.bold("VAIF Project Info")),console.log("");let l=16,d=(p,u)=>{console.log(` ${f__default.default.gray(p.padEnd(l))} ${u}`);};d("Name:",f__default.default.white(a.name||"N/A")),d("Project ID:",f__default.default.white(i)),d("Region:",f__default.default.white(a.region||"us-east-1")),d("Plan:",f__default.default.white(a.plan||a.tier||"free")),d("Created:",f__default.default.white(a.createdAt?new Date(a.createdAt).toLocaleDateString():"N/A")),console.log(""),d("API URL:",f__default.default.cyan(a.apiUrl||`${it}/v1`)),d("WS URL:",f__default.default.cyan(a.wsUrl||a.realtimeUrl||"N/A")),d("DB URL:",f__default.default.cyan(a.databaseUrl?lo(a.databaseUrl):"N/A")),d("Storage URL:",f__default.default.cyan(a.storageUrl||"N/A")),console.log("");}catch(r){e.fail("Failed to fetch project info"),r instanceof Error&&console.log(f__default.default.red(`
|
|
3820
|
+
Error: ${r.message}`)),process.exit(1);}}var uo=process.env.VAIF_API_URL||"https://api.vaif.studio";async function rt(t){let e=Q__default.default(),n=I();(!n||!n.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 o=t.config||"vaif.config.json",s=null;try{s=await A(o);}catch{}let i=t.projectId||s?.projectId||process.env.VAIF_PROJECT_ID||n.projectId;i||(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 r=await fetch(`${uo}/projects/${i}?include=tables,functions,storage,connections`,{headers:{Authorization:`Bearer ${n.token}`}});if(!r.ok){let h=await r.text();throw new Error(`Failed to fetch project status: ${h}`)}let a=await r.json();e.stop(),console.log(""),console.log(f__default.default.bold("VAIF Project Status")),console.log("");let l=22,d=(h,T)=>{console.log(` ${f__default.default.gray(h.padEnd(l))} ${T}`);};d("Project:",f__default.default.white(a.name||i)),d("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",c=a.bucketCount??a.storage?.buckets?.length??"N/A",g=a.activeConnections??a.connections??"N/A";d("Tables:",f__default.default.white(String(p))),d("Functions:",f__default.default.white(String(u))),d("Storage Buckets:",f__default.default.white(String(c))),d("Active Connections:",f__default.default.white(String(g))),a.usage&&(console.log(""),console.log(f__default.default.gray(" --- Usage ---")),console.log(""),a.usage.dbSize&&d("Database Size:",f__default.default.white(a.usage.dbSize)),a.usage.storageSize&&d("Storage Size:",f__default.default.white(a.usage.storageSize)),a.usage.bandwidth&&d("Bandwidth:",f__default.default.white(a.usage.bandwidth)),a.usage.functionInvocations!=null&&d("Function Invocations:",f__default.default.white(String(a.usage.functionInvocations)))),console.log("");}catch(r){e.fail("Failed to fetch project status"),r instanceof Error&&console.log(f__default.default.red(`
|
|
3821
|
+
Error: ${r.message}`)),process.exit(1);}}var J=process.env.VAIF_API_URL||"https://api.vaif.studio";function fo(t){let e=Ee__default.default.createInterface({input:process.stdin,output:process.stdout});return new Promise(n=>{e.question(t,o=>{e.close(),n(o.trim());});})}function go(t,e,n){return t.projectId||e?.projectId||process.env.VAIF_PROJECT_ID||n.projectId||null}async function mo(t){let e=Q__default.default("Fetching your projects...").start();try{let n=await fetch(`${J}/projects`,{headers:{Authorization:`Bearer ${t}`}});if(!n.ok)return e.fail("Could not fetch projects"),null;let o=await n.json();if(!o||o.length===0)return e.fail("No projects found. Create a project at https://vaif.studio first."),null;if(o.length===1)return e.succeed(`Found project: ${f__default.default.cyan(o[0].name)} (${o[0].id})`),o[0].id;e.succeed(`Found ${o.length} projects
|
|
3822
|
+
`);for(let r=0;r<o.length;r++)console.log(f__default.default.gray(` ${r+1}.`)+` ${f__default.default.white(o[r].name)} ${f__default.default.gray(`(${o[r].id})`)}`);console.log("");let s=await fo(f__default.default.cyan(` Select a project [1-${o.length}]: `)),i=parseInt(s,10)-1;return isNaN(i)||i<0||i>=o.length?(console.log(f__default.default.red(`
|
|
3823
|
+
Invalid selection.`)),null):o[i].id}catch{return e.fail("Could not fetch projects"),null}}function ho(t){if(!t||t.length===0)return "*No tables found. Create tables in the VAIF Studio dashboard.*";let e="";for(let n of t){e+=`### \`${n.name}\`
|
|
3824
3824
|
|
|
3825
3825
|
`,e+=`| Column | Type | Nullable | Default | Constraints |
|
|
3826
3826
|
`,e+=`|--------|------|----------|---------|-------------|
|
|
3827
3827
|
`;for(let o of n.columns){let s=[];o.isPrimaryKey&&s.push("PK"),o.nullable||s.push("NOT NULL");let i=n.foreignKeys?.find(r=>r.column===o.name);i&&s.push(`FK \u2192 ${i.foreignTable}.${i.foreignColumn}`),e+=`| ${o.name} | ${o.type} | ${o.nullable?"yes":"no"} | ${o.defaultValue||"-"} | ${s.join(", ")||"-"} |
|
|
3828
3828
|
`;}e+=`
|
|
3829
|
-
`;}return e}function
|
|
3829
|
+
`;}return e}function yo(t,e,n){let o=t.slice(0,3);if(o.length===0)return "";let s="";for(let i of o){let r=i.columns.filter(l=>!l.isPrimaryKey&&l.name!=="created_at"&&l.name!=="updated_at"),a=r.slice(0,3).map(l=>` ${l.name}: ${vo(l)}`).join(`,
|
|
3830
3830
|
`);s+=`### \`${i.name}\`
|
|
3831
3831
|
|
|
3832
3832
|
`,s+="```typescript\n",s+=`// Select all
|
|
@@ -3860,7 +3860,7 @@ await vaif.from("${i.name}").delete(recordId);
|
|
|
3860
3860
|
`,s+=` headers: { "x-vaif-key": "${n}" },
|
|
3861
3861
|
`,s+=`});
|
|
3862
3862
|
`,s+=`const { data: record } = await res2.json();
|
|
3863
|
-
`,s+="```\n\n");}return s}function
|
|
3863
|
+
`,s+="```\n\n");}return s}function vo(t){let e=t.type.toLowerCase();return e.includes("uuid")?'"crypto.randomUUID()"':e.includes("int")||e.includes("serial")?"42":e.includes("bool")?"true":e.includes("timestamp")||e.includes("date")?'"new Date().toISOString()"':e.includes("json")?"{}":e.includes("float")||e.includes("numeric")||e.includes("decimal")||e.includes("double")?"3.14":`"example_${t.name}"`}function bo(t){let{projectId:e,apiKey:n,apiUrl:o,projectName:s,schema:i}=t,r=ho(i.tables),a=yo(i.tables,o,n);return `# VAIF Studio Backend
|
|
3864
3864
|
|
|
3865
3865
|
This project uses **VAIF Studio** as its backend. Project: **${s}** (\`${e}\`).
|
|
3866
3866
|
|
|
@@ -4178,6 +4178,50 @@ const result = await vaif.functions.invoke("send_welcome_email", {
|
|
|
4178
4178
|
});
|
|
4179
4179
|
\`\`\`
|
|
4180
4180
|
|
|
4181
|
+
### Authenticated Context in Functions
|
|
4182
|
+
|
|
4183
|
+
Access the caller's verified identity via \\\`vaif.auth\\\`:
|
|
4184
|
+
|
|
4185
|
+
\`\`\`typescript
|
|
4186
|
+
export default async function handler(req) {
|
|
4187
|
+
const auth = vaif.auth;
|
|
4188
|
+
// auth.type = 'user' | 'api_key' | 'function'
|
|
4189
|
+
// auth.userId \u2014 User ID (for user/function types)
|
|
4190
|
+
// auth.email \u2014 User email (for user type)
|
|
4191
|
+
// auth.projectId \u2014 Always present
|
|
4192
|
+
// auth.scopes \u2014 API key scopes (for api_key type)
|
|
4193
|
+
|
|
4194
|
+
if (!auth || auth.type !== 'user') {
|
|
4195
|
+
return { statusCode: 401, body: { error: 'Unauthorized' } };
|
|
4196
|
+
}
|
|
4197
|
+
|
|
4198
|
+
return { body: { message: "Hello " + auth.email } };
|
|
4199
|
+
}
|
|
4200
|
+
\`\`\`
|
|
4201
|
+
|
|
4202
|
+
### Function-to-Function Invocation
|
|
4203
|
+
|
|
4204
|
+
Call other functions from within a handler:
|
|
4205
|
+
|
|
4206
|
+
\`\`\`typescript
|
|
4207
|
+
export default async function handler(req) {
|
|
4208
|
+
const result = await vaif.invoke("send_email", {
|
|
4209
|
+
to: "user@example.com",
|
|
4210
|
+
subject: "Hello",
|
|
4211
|
+
});
|
|
4212
|
+
return { statusCode: 200, body: result };
|
|
4213
|
+
}
|
|
4214
|
+
\`\`\`
|
|
4215
|
+
|
|
4216
|
+
### Database Triggers
|
|
4217
|
+
|
|
4218
|
+
Fire functions automatically on insert/update/delete events. Configure triggers via the API:
|
|
4219
|
+
|
|
4220
|
+
\`\`\`
|
|
4221
|
+
POST /functions/\\\${functionId}/triggers
|
|
4222
|
+
{ "event": "db.insert", "tableName": "orders", "enabled": true }
|
|
4223
|
+
\`\`\`
|
|
4224
|
+
|
|
4181
4225
|
## API Key Management
|
|
4182
4226
|
|
|
4183
4227
|
API keys are project-scoped and used for data-plane authentication (CRUD, storage, functions).
|
|
@@ -4264,6 +4308,87 @@ The SDK supports these filter operators:
|
|
|
4264
4308
|
| \`ilike\` | Pattern match (case-insensitive) | \`.ilike("name", "%john%")\` |
|
|
4265
4309
|
| \`is\` | IS comparison (null, true, false) | \`.is("deleted_at", null)\` |
|
|
4266
4310
|
|
|
4311
|
+
### JSONB Subkey Filters
|
|
4312
|
+
|
|
4313
|
+
Filter on nested JSONB fields using arrow notation:
|
|
4314
|
+
|
|
4315
|
+
| Filter | SQL Generated |
|
|
4316
|
+
|--------|--------------|
|
|
4317
|
+
| \\\`filter[metadata->status]=active\\\` | \\\`metadata->>'status' = 'active'\\\` |
|
|
4318
|
+
| \\\`filter[config->theme.ilike]=%dark%\\\` | \\\`config->>'theme' ILIKE '%dark%'\\\` |
|
|
4319
|
+
| \\\`filter[data->user->role]=admin\\\` | \\\`data->'user'->>'role' = 'admin'\\\` |
|
|
4320
|
+
|
|
4321
|
+
All standard operators work with JSONB paths. The last segment uses \\\`->>\\\` (text extraction).
|
|
4322
|
+
|
|
4323
|
+
### Compound Filters (AND + OR)
|
|
4324
|
+
|
|
4325
|
+
Combine AND and OR conditions:
|
|
4326
|
+
|
|
4327
|
+
\`\`\`
|
|
4328
|
+
?filter[status]=active&or_filter[role]=admin&or_filter[role]=moderator
|
|
4329
|
+
\`\`\`
|
|
4330
|
+
|
|
4331
|
+
This generates: \\\`WHERE status = 'active' AND (role = 'admin' OR role = 'moderator')\\\`
|
|
4332
|
+
|
|
4333
|
+
### Full-Text Search
|
|
4334
|
+
|
|
4335
|
+
\`\`\`typescript
|
|
4336
|
+
const results = await fetch("${o}/generated/posts/search", {
|
|
4337
|
+
method: "POST",
|
|
4338
|
+
headers: { "x-vaif-key": "${n}", "Content-Type": "application/json" },
|
|
4339
|
+
body: JSON.stringify({
|
|
4340
|
+
query: "search term",
|
|
4341
|
+
columns: ["title", "body"],
|
|
4342
|
+
limit: 20,
|
|
4343
|
+
}),
|
|
4344
|
+
});
|
|
4345
|
+
// Results ranked by ts_rank score
|
|
4346
|
+
\`\`\`
|
|
4347
|
+
|
|
4348
|
+
### Aggregation
|
|
4349
|
+
|
|
4350
|
+
\`\`\`typescript
|
|
4351
|
+
const stats = await fetch("${o}/generated/orders/aggregate", {
|
|
4352
|
+
method: "POST",
|
|
4353
|
+
headers: { "x-vaif-key": "${n}", "Content-Type": "application/json" },
|
|
4354
|
+
body: JSON.stringify({
|
|
4355
|
+
aggregates: [
|
|
4356
|
+
{ fn: "count", column: "*" },
|
|
4357
|
+
{ fn: "sum", column: "total" },
|
|
4358
|
+
{ fn: "avg", column: "total" },
|
|
4359
|
+
],
|
|
4360
|
+
groupBy: ["status"],
|
|
4361
|
+
}),
|
|
4362
|
+
});
|
|
4363
|
+
\`\`\`
|
|
4364
|
+
|
|
4365
|
+
### Joins (Foreign Key Includes)
|
|
4366
|
+
|
|
4367
|
+
Include related rows by specifying foreign key columns:
|
|
4368
|
+
|
|
4369
|
+
\`\`\`
|
|
4370
|
+
GET /generated/posts?include=author_id&include=category_id
|
|
4371
|
+
\`\`\`
|
|
4372
|
+
|
|
4373
|
+
Returns posts with \\\`author_id_included\\\` and \\\`category_id_included\\\` objects containing the related rows.
|
|
4374
|
+
|
|
4375
|
+
### Upsert
|
|
4376
|
+
|
|
4377
|
+
Insert or update on conflict:
|
|
4378
|
+
|
|
4379
|
+
\`\`\`typescript
|
|
4380
|
+
const result = await fetch("${o}/generated/users", {
|
|
4381
|
+
method: "POST",
|
|
4382
|
+
headers: { "x-vaif-key": "${n}", "Content-Type": "application/json" },
|
|
4383
|
+
body: JSON.stringify({
|
|
4384
|
+
email: "alice@example.com",
|
|
4385
|
+
name: "Alice",
|
|
4386
|
+
_upsert: true,
|
|
4387
|
+
_conflictColumns: ["email"],
|
|
4388
|
+
}),
|
|
4389
|
+
});
|
|
4390
|
+
\`\`\`
|
|
4391
|
+
|
|
4267
4392
|
### Pagination
|
|
4268
4393
|
|
|
4269
4394
|
\`\`\`typescript
|
|
@@ -4328,14 +4453,18 @@ The \`.mcp.json\` file configures an MCP server that gives Claude Code direct ac
|
|
|
4328
4453
|
| Tool | What it does |
|
|
4329
4454
|
|------|-------------|
|
|
4330
4455
|
| \`list_tables\`, \`describe_table\` | Inspect database schema |
|
|
4331
|
-
| \`query_rows\`, \`insert_row\`, \`update_row\`, \`delete_row\` | CRUD operations on any table |
|
|
4332
|
-
| \`create_function\`, \`deploy_function\`, \`invoke_function\` | Create, deploy, and call serverless functions |
|
|
4333
|
-
| \`create_bucket\`, \`list_buckets\`, \`list_files\`, \`get_signed_url\` | Storage management |
|
|
4334
|
-
| \`enable_realtime\`, \`realtime_status\` | Enable/check realtime subscriptions |
|
|
4335
4456
|
| \`get_schema\` | Full schema as JSON |
|
|
4457
|
+
| \`create_tables\` | Create or update tables declaratively |
|
|
4458
|
+
| \`query_rows\` | Query with filters, JSONB paths, pagination |
|
|
4459
|
+
| \`insert_row\`, \`update_row\`, \`delete_row\` | CRUD operations on any table |
|
|
4460
|
+
| \`list_functions\`, \`deploy_function\`, \`invoke_function\` | Function management |
|
|
4461
|
+
| \`get_function_logs\` | Execution history with status filters |
|
|
4462
|
+
| \`set_secret\`, \`list_secrets\`, \`delete_secret\` | Function secrets |
|
|
4463
|
+
| \`list_buckets\`, \`list_files\`, \`get_signed_url\` | Storage operations |
|
|
4464
|
+
| \`enable_realtime\`, \`realtime_status\` | Realtime subscriptions |
|
|
4336
4465
|
|
|
4337
4466
|
> **Note**: MCP tools are only available to the main Claude Code session, not to spawned sub-agents (Task tool). The main session should handle all VAIF backend operations directly.
|
|
4338
|
-
`}async function dt(t){let e=Q__default.default(),n=I();(!n||!n.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 o=t.config||"vaif.config.json",s=null;try{s=await A(o);}catch{}let i=
|
|
4339
|
-
`)),i=await
|
|
4340
|
-
Tip: pass --project-id <id> or set projectId in vaif.config.json`)),process.exit(1)));let r=___default.default.resolve(t.outputDir||".");console.log(""),console.log(f__default.default.bold("VAIF Claude Code Setup")),console.log(f__default.default.gray(` Project: ${i}`)),console.log(""),e.start("Fetching database schema...");let a={tables:[]};try{let
|
|
4341
|
-
`,"utf-8"),e.succeed(`Written ${f__default.default.cyan(".mcp.json")}`);}if(!t.skipClaudeMd){e.start("Writing CLAUDE.md...");let p=vo({projectId:i,apiKey:u,apiUrl:d,projectName:l,schema:a}),c=___default.default.join(r,"CLAUDE.md");U__default.default.writeFileSync(c,p,"utf-8"),e.succeed(`Written ${f__default.default.cyan("CLAUDE.md")}`);}console.log(""),console.log(f__default.default.green.bold(" Claude Code integration configured!")),console.log(""),t.skipMcp||console.log(f__default.default.gray(" MCP Server: ")+f__default.default.white(".mcp.json")),t.skipClaudeMd||console.log(f__default.default.gray(" Context: ")+f__default.default.white("CLAUDE.md")),console.log(""),console.log(f__default.default.bold(" Next steps:")),console.log(f__default.default.gray(" 1. Open this project in Claude Code")),console.log(f__default.default.gray(" 2. The MCP server auto-connects to your VAIF project")),console.log(f__default.default.gray(" 3. Ask Claude to query, modify, or build against your schema")),console.log("");}var pt="1.9.7",he=f__default.default.hex("#00f0ff"),ye=f__default.default.hex("#7b61ff"),ve=f__default.default.hex("#ff3dff"),be=f__default.default.hex("#00ff9d"),S=f__default.default.hex("#555570"),B=f__default.default.hex("#00f0ff");function bo(){console.log(""),console.log(he(" \u2566 \u2566")+ye("\u2554\u2550\u2557\u2566")+ve("\u2554\u2550\u2557 ")+be("\u2554\u2550\u2557\u2566 \u2566")),console.log(he(" \u255A\u2557\u2554\u255D")+ye("\u2560\u2550\u2563\u2551")+ve("\u2560\u2563 ")+be("\u2551 \u2551 \u2551")),console.log(he(" \u255A\u255D ")+ye("\u2569 \u2569\u2569")+ve("\u255A ")+be("\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(B(" VAIF Studio CLI")+S(` v${pt}`)),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(" $ ")+B("vaif login")+S(" Authenticate")),console.log(S(" $ ")+B("vaif init -t react-spa")+S(" Scaffold project")),console.log(S(" $ ")+B("vaif db push")+S(" Push migrations")),console.log(S(" $ ")+B("vaif generate")+S(" Generate types")),console.log(S(" $ ")+B("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(S(" ai ")+f__default.default.white("claude-setup")),console.log(""),console.log(S(" Run ")+B("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(pt);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(xe);commander.program.command("logout").description("Log out and remove stored credentials").action(Pe);commander.program.command("whoami").description("Show current authenticated user").action(Fe);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(Le);commander.program.command("templates").alias("tpl").description("List available project templates").action(Ne);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(st);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(rt);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(De);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($e);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(Ce);var ut=commander.program.command("functions").alias("fn").description("Manage serverless functions");ut.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(ze);ut.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(Be);var ae=commander.program.command("db").description("Database management commands");ae.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(Je);ae.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(Ge);ae.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(Ye);ae.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 ft=commander.program.command("keys").description("Manage API keys");ft.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(Ze);ft.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(et);var ie=commander.program.command("secrets").alias("sec").description("Manage function secrets");ie.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(tt);ie.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(ot);ie.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(nt);ie.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(at);commander.program.command("claude-setup").description("Configure Claude Code integration (MCP server + CLAUDE.md)").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID").option("-k, --api-key <key>","API key for MCP server").option("--skip-mcp","Skip generating .mcp.json").option("--skip-claude-md","Skip generating CLAUDE.md").option("-o, --output-dir <dir>","Output directory",".").action(dt);process.argv.slice(2).length||(bo(),process.exit(0));commander.program.parse(process.argv);
|
|
4467
|
+
`}async function dt(t){let e=Q__default.default(),n=I();(!n||!n.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 o=t.config||"vaif.config.json",s=null;try{s=await A(o);}catch{}let i=go(t,s,n);i||(console.log(f__default.default.yellow(`No project ID specified \u2014 fetching your projects...
|
|
4468
|
+
`)),i=await mo(n.token),i||(console.log(f__default.default.gray(`
|
|
4469
|
+
Tip: pass --project-id <id> or set projectId in vaif.config.json`)),process.exit(1)));let r=___default.default.resolve(t.outputDir||".");console.log(""),console.log(f__default.default.bold("VAIF Claude Code Setup")),console.log(f__default.default.gray(` Project: ${i}`)),console.log(""),e.start("Fetching database schema...");let a={tables:[]};try{let u=await fetch(`${J}/schema-engine/introspect/${i}`,{headers:{Authorization:`Bearer ${n.token}`}});u.ok?(a=await u.json(),e.succeed(`Fetched schema (${a.tables?.length||0} tables)`)):e.warn("Could not fetch schema \u2014 continuing without it");}catch{e.warn("Could not fetch schema \u2014 continuing without it");}e.start("Fetching project info...");let l=i,d=J;try{let u=await fetch(`${J}/projects/${i}`,{headers:{Authorization:`Bearer ${n.token}`}});if(u.ok){let c=await u.json(),g=c.project||c;l=g.name||i,d=g.apiUrl||J,e.succeed(`Project: ${l}`);}else e.warn("Could not fetch project info \u2014 using defaults");}catch{e.warn("Could not fetch project info \u2014 using defaults");}let p=t.apiKey||s?.api?.apiKey||"";if(!p){e.start("Generating API key for Claude Code...");try{let u=`claude-code-${Date.now()}`,c=await fetch(`${J}/projects/${i}/api-keys`,{method:"POST",headers:{Authorization:`Bearer ${n.token}`,"Content-Type":"application/json"},body:JSON.stringify({name:u,scopes:["crud","realtime","functions","storage"]})});if(c.ok){let g=await c.json();p=g.apiKey||g.key,e.succeed(`Generated API key: ${u}`);}else e.fail("Could not auto-generate API key"),console.log(f__default.default.yellow(" Pass one with --api-key or generate via `vaif keys generate`")),process.exit(1);}catch{e.fail("Could not auto-generate API key"),console.log(f__default.default.yellow(" Pass one with --api-key or generate via `vaif keys generate`")),process.exit(1);}}if(!t.skipMcp){e.start("Writing .mcp.json...");let u={mcpServers:{"vaif-studio":{command:"npx",args:["@vaiftech/mcp"],env:{VAIF_API_KEY:p,VAIF_PROJECT_ID:i,VAIF_API_URL:d,VAIF_AUTH_TOKEN:n.token}}}},c=___default.default.join(r,".mcp.json");U__default.default.writeFileSync(c,JSON.stringify(u,null,2)+`
|
|
4470
|
+
`,"utf-8"),e.succeed(`Written ${f__default.default.cyan(".mcp.json")}`);}if(!t.skipClaudeMd){e.start("Writing CLAUDE.md...");let u=bo({projectId:i,apiKey:p,apiUrl:d,projectName:l,schema:a}),c=___default.default.join(r,"CLAUDE.md");U__default.default.writeFileSync(c,u,"utf-8"),e.succeed(`Written ${f__default.default.cyan("CLAUDE.md")}`);}console.log(""),console.log(f__default.default.green.bold(" Claude Code integration configured!")),console.log(""),t.skipMcp||console.log(f__default.default.gray(" MCP Server: ")+f__default.default.white(".mcp.json")),t.skipClaudeMd||console.log(f__default.default.gray(" Context: ")+f__default.default.white("CLAUDE.md")),console.log(""),console.log(f__default.default.bold(" Next steps:")),console.log(f__default.default.gray(" 1. Open this project in Claude Code")),console.log(f__default.default.gray(" 2. The MCP server auto-connects to your VAIF project")),console.log(f__default.default.gray(" 3. Ask Claude to query, modify, or build against your schema")),console.log("");}var Ao=module$1.createRequire(j),{version:ut}=Ao("../package.json"),he=f__default.default.hex("#00f0ff"),ye=f__default.default.hex("#7b61ff"),ve=f__default.default.hex("#ff3dff"),be=f__default.default.hex("#00ff9d"),S=f__default.default.hex("#555570"),B=f__default.default.hex("#00f0ff");function wo(){console.log(""),console.log(he(" \u2566 \u2566")+ye("\u2554\u2550\u2557\u2566")+ve("\u2554\u2550\u2557 ")+be("\u2554\u2550\u2557\u2566 \u2566")),console.log(he(" \u255A\u2557\u2554\u255D")+ye("\u2560\u2550\u2563\u2551")+ve("\u2560\u2563 ")+be("\u2551 \u2551 \u2551")),console.log(he(" \u255A\u255D ")+ye("\u2569 \u2569\u2569")+ve("\u255A ")+be("\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(B(" VAIF Studio CLI")+S(` v${ut}`)),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(" $ ")+B("vaif login")+S(" Authenticate")),console.log(S(" $ ")+B("vaif init -t react-spa")+S(" Scaffold project")),console.log(S(" $ ")+B("vaif db push")+S(" Push migrations")),console.log(S(" $ ")+B("vaif generate")+S(" Generate types")),console.log(S(" $ ")+B("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(S(" ai ")+f__default.default.white("claude-setup")),console.log(""),console.log(S(" Run ")+B("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(ut);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(xe);commander.program.command("logout").description("Log out and remove stored credentials").action(Pe);commander.program.command("whoami").description("Show current authenticated user").action(Fe);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(Le);commander.program.command("templates").alias("tpl").description("List available project templates").action(Ne);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(st);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(rt);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(De);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($e);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(je);var pt=commander.program.command("functions").alias("fn").description("Manage serverless functions");pt.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(ze);pt.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(Be);var ae=commander.program.command("db").description("Database management commands");ae.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(Je);ae.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(Ge);ae.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(Ye);ae.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 ft=commander.program.command("keys").description("Manage API keys");ft.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(Ze);ft.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(et);var ie=commander.program.command("secrets").alias("sec").description("Manage function secrets");ie.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(tt);ie.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(ot);ie.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(nt);ie.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(at);commander.program.command("claude-setup").description("Configure Claude Code integration (MCP server + CLAUDE.md)").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID").option("-k, --api-key <key>","API key for MCP server").option("--skip-mcp","Skip generating .mcp.json").option("--skip-claude-md","Skip generating CLAUDE.md").option("-o, --output-dir <dir>","Output directory",".").action(dt);process.argv.slice(2).length||(wo(),process.exit(0));commander.program.parse(process.argv);
|
package/dist/cli.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {c,d,e,h,g,f as f$1,b,a}from'./chunk-T7GOLIY4.js';import'dotenv/config';import {program}from'commander';import f from'chalk';import F from'fs';import $ from'path';import J from'ora';import We from'readline';var Be=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Ke(o,e,t="public"){let n=await fetch(`${Be}/projects/${e}/schema?schema=${t}`,{headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"}});if(!n.ok){let i=await n.text();throw new Error(`Failed to fetch schema: ${i}`)}return n.json()}async function ce(o){let e=J(),t=b();(!t||!t.token)&&(console.log(f.red("Not logged in")),console.log(f.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=o.config||"vaif.config.json",i=null;e.start("Loading configuration...");try{i=await a(n);}catch(r){e.fail("Failed to load config"),console.log(f.red(`
|
|
2
|
+
import {c,d,e,h,g,f as f$1,b,a}from'./chunk-T7GOLIY4.js';import'dotenv/config';import {createRequire}from'module';import {program}from'commander';import f from'chalk';import F from'fs';import b$1 from'path';import J from'ora';import We from'readline';var Be=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Ke(o,e,t="public"){let n=await fetch(`${Be}/projects/${e}/schema?schema=${t}`,{headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"}});if(!n.ok){let i=await n.text();throw new Error(`Failed to fetch schema: ${i}`)}return n.json()}async function ce(o){let e=J(),t=b();(!t||!t.token)&&(console.log(f.red("Not logged in")),console.log(f.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=o.config||"vaif.config.json",i=null;e.start("Loading configuration...");try{i=await a(n);}catch(r){e.fail("Failed to load config"),console.log(f.red(`
|
|
3
3
|
Error: ${r}`)),process.exit(1);}i||(e.fail("No configuration found"),console.log(f.yellow("\nRun `vaif init` to create a configuration file.")),process.exit(1));let a$1=o.projectId||i.projectId||process.env.VAIF_PROJECT_ID||t.projectId;a$1||(e.fail("No project ID specified"),console.log(f.yellow(`
|
|
4
|
-
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1)),e.text="Fetching remote schema...";try{let r=o.schema||i.database?.schema||"public",s=await Ke(t.token,a$1,r);e.succeed("Schema fetched successfully");let c=o.output
|
|
5
|
-
Error: ${r.message}`)),process.exit(1);}}var de=process.env.VAIF_API_URL||"https://api.vaif.studio";function Ge(o){let e=We.createInterface({input:process.stdin,output:process.stdout});return new Promise(t=>{e.question(o,n=>{e.close(),t(n);});})}async function
|
|
4
|
+
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1)),e.text="Fetching remote schema...";try{let r=o.schema||i.database?.schema||"public",s=await Ke(t.token,a$1,r);e.succeed("Schema fetched successfully");let c=o.output||b$1.resolve("vaif.schema.json"),g={$schema:"https://vaif.studio/schemas/schema.json",projectId:a$1,schema:r,pulledAt:new Date().toISOString(),...s};F.writeFileSync(c,JSON.stringify(g,null,2),"utf-8"),console.log(""),console.log(f.green(`Schema saved to: ${c}`)),console.log(""),console.log(f.gray("Schema summary:")),console.log(f.gray(` Tables: ${(s.tables||[]).length}`)),console.log(f.gray(` Enums: ${(s.enums||[]).length}`)),console.log(f.gray(` Functions: ${(s.functions||[]).length}`)),console.log(""),console.log(f.gray("Next steps:")),console.log(f.gray(" - Run `vaif generate` to generate TypeScript types")),console.log(f.gray(" - Edit the schema and run `vaif push` to deploy changes")),console.log("");}catch(r){e.fail("Failed to fetch schema"),r instanceof Error&&console.log(f.red(`
|
|
5
|
+
Error: ${r.message}`)),process.exit(1);}}var de=process.env.VAIF_API_URL||"https://api.vaif.studio";function Ge(o){let e=We.createInterface({input:process.stdin,output:process.stdout});return new Promise(t=>{e.question(o,n=>{e.close(),t(n);});})}async function He(o,e,t){let n=await fetch(`${de}/projects/${e}/schema/preview`,{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({schema:t})});if(!n.ok){let i=await n.text();throw new Error(`Failed to preview changes: ${i}`)}return n.json()}async function Ye(o,e,t){let n=await fetch(`${de}/projects/${e}/schema/apply`,{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({schema:t})});if(!n.ok){let i=await n.text();throw new Error(`Failed to apply changes: ${i}`)}return n.json()}function Qe(o){if(console.log(""),console.log(f.bold("Schema Changes:")),console.log(""),o.added.length===0&&o.modified.length===0&&o.removed.length===0){console.log(f.gray(" No changes detected. Schema is up to date."));return}if(o.added.length>0){console.log(f.green.bold(" + Added:"));for(let e of o.added)console.log(f.green(` + ${e.type}: ${e.name}`));console.log("");}if(o.modified.length>0){console.log(f.yellow.bold(" ~ Modified:"));for(let e of o.modified){console.log(f.yellow(` ~ ${e.type}: ${e.name}`));for(let t of e.changes)console.log(f.gray(` ${t}`));}console.log("");}if(o.removed.length>0){console.log(f.red.bold(" - Removed:"));for(let e of o.removed)console.log(f.red(` - ${e.type}: ${e.name}`));console.log("");}}async function fe(o){let e=J(),t=b();(!t||!t.token)&&(console.log(f.red("Not logged in")),console.log(f.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=o.config||"vaif.config.json",i=null;e.start("Loading configuration...");try{i=await a(n);}catch(c){e.fail("Failed to load config"),console.log(f.red(`
|
|
6
6
|
Error: ${c}`)),process.exit(1);}i||(e.fail("No configuration found"),console.log(f.yellow("\nRun `vaif init` to create a configuration file.")),process.exit(1));let a$1=o.projectId||i.projectId||process.env.VAIF_PROJECT_ID||t.projectId;a$1||(e.fail("No project ID specified"),console.log(f.yellow(`
|
|
7
|
-
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1));let r=o.schema
|
|
7
|
+
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1));let r=o.schema||b$1.resolve("vaif.schema.json");F.existsSync(r)||(e.fail("No local schema found"),console.log(f.yellow(`
|
|
8
8
|
Expected schema file at: ${r}`)),console.log(f.gray("Run `vaif pull` first to fetch the current schema.")),process.exit(1));let s;try{let c=F.readFileSync(r,"utf-8");s=JSON.parse(c);}catch(c){e.fail("Failed to parse schema file"),c instanceof Error&&console.log(f.red(`
|
|
9
|
-
Error: ${c.message}`)),process.exit(1);}e.text="Calculating schema changes...";try{let{diff:c,sql:g}=await
|
|
10
|
-
Cancelled. No changes applied.`));return}}e.start("Applying schema changes...");let p=await
|
|
11
|
-
Error: ${c.message}`)),process.exit(1);}}var z=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Xe(o,e,t,n){let i=new URL(`${z}/functions/project/${e}`);n&&i.searchParams.set("envId",n);let a=await fetch(i.toString(),{headers:{Authorization:`Bearer ${o}`}});if(!a.ok)return null;let r=await a.json(),s=r.functions||r;return Array.isArray(s)&&s.find(c=>c.name===t)||null}async function Ze(o,e,t){let n=await fetch(`${z}/functions/`,{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({projectId:e,name:t.name,runtime:t.runtime,entrypoint:t.entrypoint,envId:t.envId})});if(!n.ok){let i=await n.text();throw new Error(`Failed to create function: ${i}`)}return n.json()}async function eo(o,e,t){let n=await fetch(`${z}/functions/${e}/source`,{method:"PUT",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({sourceCode:t})});if(!n.ok){let i=await n.text();throw new Error(`Failed to deploy source: ${i}`)}}async function oo(o,e,t){let n=new URL(`${z}/functions/project/${e}`);t&&n.searchParams.set("envId",t);let i=await fetch(n.toString(),{headers:{Authorization:`Bearer ${o}`}});if(!i.ok){let r=await i.text();throw new Error(`Failed to list functions: ${r}`)}let a=await i.json();return a.functions||a}function ge(o){switch(
|
|
9
|
+
Error: ${c.message}`)),process.exit(1);}e.text="Calculating schema changes...";try{let{diff:c,sql:g}=await He(t.token,a$1,s);if(e.stop(),Qe(c),c.added.length===0&&c.modified.length===0&&c.removed.length===0){console.log("");return}if(g.length>0){console.log(f.bold("SQL Migrations:")),console.log("");for(let d of g)console.log(f.gray(` ${d}`));console.log("");}if(o.dryRun){console.log(f.yellow("Dry run mode - no changes applied.")),console.log(f.gray("Remove --dry-run to apply these changes."));return}if(!o.force){c.removed.length>0&&(console.log(f.red.bold("\u26A0\uFE0F Warning: This will remove tables/columns from your database.")),console.log(f.red(" This action cannot be undone!")),console.log(""));let l=await Ge(f.cyan("Apply these changes? [y/N] "));if(l.toLowerCase()!=="y"&&l.toLowerCase()!=="yes"){console.log(f.yellow(`
|
|
10
|
+
Cancelled. No changes applied.`));return}}e.start("Applying schema changes...");let p=await Ye(t.token,a$1,s);if(p.success){if(e.succeed("Schema changes applied successfully"),console.log(""),p.migrations.length>0){console.log(f.gray("Migrations applied:"));for(let d of p.migrations)console.log(f.gray(` - ${d}`));console.log("");}console.log(f.green("Your database schema is now up to date.")),console.log(f.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.red(`
|
|
11
|
+
Error: ${c.message}`)),process.exit(1);}}var z=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Xe(o,e,t,n){let i=new URL(`${z}/functions/project/${e}`);n&&i.searchParams.set("envId",n);let a=await fetch(i.toString(),{headers:{Authorization:`Bearer ${o}`}});if(!a.ok)return null;let r=await a.json(),s=r.functions||r;return Array.isArray(s)&&s.find(c=>c.name===t)||null}async function Ze(o,e,t){let n=await fetch(`${z}/functions/`,{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({projectId:e,name:t.name,runtime:t.runtime,entrypoint:t.entrypoint,envId:t.envId})});if(!n.ok){let i=await n.text();throw new Error(`Failed to create function: ${i}`)}return n.json()}async function eo(o,e,t){let n=await fetch(`${z}/functions/${e}/source`,{method:"PUT",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({sourceCode:t})});if(!n.ok){let i=await n.text();throw new Error(`Failed to deploy source: ${i}`)}}async function oo(o,e,t){let n=new URL(`${z}/functions/project/${e}`);t&&n.searchParams.set("envId",t);let i=await fetch(n.toString(),{headers:{Authorization:`Bearer ${o}`}});if(!i.ok){let r=await i.text();throw new Error(`Failed to list functions: ${r}`)}let a=await i.json();return a.functions||a}function ge(o){switch(b$1.extname(o).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 pe(o){let e=[],t=[".ts",".js",".mjs",".py",".go",".rs"],n=["drizzle.config.ts","tsconfig.json","package.json"];if(!F.existsSync(o))return e;let i=F.readdirSync(o,{withFileTypes:true});for(let a of i){let r=b$1.join(o,a.name);if(a.isDirectory()){if(a.name!=="node_modules"&&!a.name.startsWith(".")){let s=F.readdirSync(r,{withFileTypes:true});for(let c of s)if(c.isFile()){let g=b$1.extname(c.name).toLowerCase();if(t.includes(g)){e.push(b$1.join(r,c.name));break}}}}else if(a.isFile()){let s=b$1.extname(a.name).toLowerCase();t.includes(s)&&!n.includes(a.name)&&e.push(r);}}return e}async function he(o){let e=J(),t=b();(!t||!t.token)&&(console.log(f.red("Not logged in")),console.log(f.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=o.config||"vaif.config.json",i=null;try{i=await a(n);}catch{}let a$1=o.projectId||i?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;a$1||(console.log(f.red("No project ID specified")),console.log(f.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),console.log(""),console.log(f.bold("VAIF Functions Deploy")),console.log(""),e.start("Scanning for function files...");let r=b$1.resolve("functions"),s=b$1.resolve("src/functions"),c=[];if(o.entrypoint){let l=b$1.resolve(o.entrypoint);F.existsSync(l)||(e.fail(`File not found: ${o.entrypoint}`),process.exit(1)),c=[l];}else c=[...pe(r),...pe(s)];c.length===0&&(e.fail("No function files found"),console.log(f.yellow(`
|
|
12
12
|
Place your functions in:`)),console.log(f.gray(" - ./functions/")),console.log(f.gray(" - ./src/functions/")),console.log(f.gray(`
|
|
13
|
-
Or specify an entrypoint with --entrypoint`)),process.exit(1)),e.succeed(`Found ${c.length} function(s)`),o.name&&(c=c.filter(l
|
|
14
|
-
No functions matching "${o.name}" found`)),process.exit(1))),console.log(""),console.log(f.gray("Functions to deploy:"));for(let l of c){let u
|
|
13
|
+
Or specify an entrypoint with --entrypoint`)),process.exit(1)),e.succeed(`Found ${c.length} function(s)`),o.name&&(c=c.filter(l=>b$1.basename(l,b$1.extname(l)).includes(o.name)),c.length===0&&(console.log(f.yellow(`
|
|
14
|
+
No functions matching "${o.name}" found`)),process.exit(1))),console.log(""),console.log(f.gray("Functions to deploy:"));for(let l of c){let u=b$1.basename(b$1.dirname(l)),y=u==="functions"||u==="src"?b$1.basename(l,b$1.extname(l)):u,T=o.runtime||ge(l);console.log(f.gray(` - ${y} (${T})`));}if(console.log(""),o.dryRun){console.log(f.yellow("Dry run mode - no functions deployed."));return}let g=[];for(let l of c){let u=b$1.basename(b$1.dirname(l)),y=u==="functions"||u==="src"?b$1.basename(l,b$1.extname(l)):u,T=o.runtime||ge(l);e.start(`Deploying ${y}...`);try{let V=F.readFileSync(l,"utf-8"),L=await Xe(t.token,a$1,y,o.envId);L||(e.text=`Creating ${y}...`,L=await Ze(t.token,a$1,{name:y,runtime:T,entrypoint:b$1.basename(l),envId:o.envId})),e.text=`Deploying ${y}...`,await eo(t.token,L.id,V),e.succeed(`Deployed ${y}`),g.push({name:y,success:!0});}catch(V){let L=V instanceof Error?V.message:"Unknown error";e.fail(`Failed to deploy ${y}`),g.push({name:y,success:false,error:L});}}console.log("");let p=g.filter(l=>l.success).length;if(g.filter(l=>!l.success).length===0)console.log(f.green(`\u2713 Successfully deployed ${p} function(s)`));else {console.log(f.yellow(`Deployed ${p}/${g.length} function(s)`)),console.log(""),console.log(f.red("Failed deployments:"));for(let l of g.filter(u=>!u.success))console.log(f.red(` - ${l.name}: ${l.error}`));}console.log("");}async function me(o){let e=J(),t=b();(!t||!t.token)&&(console.log(f.red("Not logged in")),console.log(f.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=o.config||"vaif.config.json",i=null;try{i=await a(n);}catch{}let a$1=o.projectId||i?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;a$1||(console.log(f.red("No project ID specified")),process.exit(1)),e.start("Fetching functions...");try{let r=await oo(t.token,a$1,o.envId);if(e.stop(),r.length===0){console.log(f.yellow(`
|
|
15
15
|
No functions found`)),console.log(f.gray("Deploy your first function with: vaif functions deploy"));return}console.log(""),console.log(f.bold(`Functions (${r.length}):`)),console.log(""),console.log(f.gray(" "+"NAME".padEnd(25)+"RUNTIME".padEnd(15)+"STATUS".padEnd(12)+"INVOCATIONS".padEnd(14)+"LAST DEPLOYED")),console.log(f.gray(" "+"-".repeat(80)));for(let s of r){let c=s.deployStatus==="deployed"?f.green:s.deployStatus==="deploying"?f.yellow:s.deployStatus==="failed"?f.red:f.gray;console.log(" "+s.name.padEnd(25)+s.runtime.padEnd(15)+c(s.deployStatus.padEnd(12))+String(s.invocationCount??0).padEnd(14)+(s.deployedAt?new Date(s.deployedAt).toLocaleDateString():"-"));}console.log("");}catch(r){e.fail("Failed to fetch functions"),r instanceof Error&&console.log(f.red(`
|
|
16
|
-
Error: ${r.message}`)),process.exit(1);}}var B=process.env.VAIF_API_URL||"https://api.vaif.studio";async function to(o,e,t,n,i){let a=await fetch(`${B}/projects/${e}/db/seed`,{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({table:t,records:n,truncate:i?.truncate??false})});if(!a.ok){let r=await a.text();throw new Error(`Failed to seed ${t}: ${r}`)}return a.json()}async function no(o,e){let t=await fetch(`${B}/projects/${e}/db/reset`,{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"}});if(!t.ok){let n=await t.text();throw new Error(`Failed to reset database: ${n}`)}return t.json()}function
|
|
16
|
+
Error: ${r.message}`)),process.exit(1);}}var B=process.env.VAIF_API_URL||"https://api.vaif.studio";async function to(o,e,t,n,i){let a=await fetch(`${B}/projects/${e}/db/seed`,{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({table:t,records:n,truncate:i?.truncate??false})});if(!a.ok){let r=await a.text();throw new Error(`Failed to seed ${t}: ${r}`)}return a.json()}async function no(o,e){let t=await fetch(`${B}/projects/${e}/db/reset`,{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"}});if(!t.ok){let n=await t.text();throw new Error(`Failed to reset database: ${n}`)}return t.json()}function Y(o){let e=[];if(!F.existsSync(o))return e;let t=F.readdirSync(o,{withFileTypes:true});for(let n of t)if(n.isFile()){let i=b$1.extname(n.name).toLowerCase();(i===".json"||i===".ts"||i===".js")&&e.push(b$1.join(o,n.name));}return e.sort()}async function ye(o){let e=b$1.extname(o).toLowerCase();if(e===".json"){let t=F.readFileSync(o,"utf-8"),n=JSON.parse(t);return Array.isArray(n)?[{table:b$1.basename(o,e),data:n}]:n.table&&n.data?[n]:Object.entries(n).map(([i,a])=>({table:i,data:a}))}else if(e===".ts"||e===".js"){let t=await import(o),n=t.default||t;return typeof n=="function"?n():n}throw new Error(`Unsupported file format: ${e}`)}async function we(o){let e=J(),t=b();(!t||!t.token)&&(console.log(f.red("Not logged in")),console.log(f.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=o.config||"vaif.config.json",i=null;try{i=await a(n);}catch{}let a$1=o.projectId||i?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;a$1||(console.log(f.red("No project ID specified")),console.log(f.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),console.log(""),console.log(f.bold("VAIF Database Seed")),console.log("");let r=[];if(o.file){let p=b$1.resolve(o.file);F.existsSync(p)||(console.log(f.red(`File not found: ${o.file}`)),process.exit(1)),r=[p];}else {let p=b$1.resolve("seeds"),d=b$1.resolve("prisma/seed"),l=b$1.resolve("db/seeds");r=[...Y(p),...Y(d),...Y(l)];}r.length===0&&(console.log(f.yellow("No seed files found")),console.log(f.gray(`
|
|
17
17
|
Place your seed files in one of these directories:`)),console.log(f.gray(" - ./seeds/")),console.log(f.gray(" - ./prisma/seed/")),console.log(f.gray(" - ./db/seeds/")),console.log(f.gray(`
|
|
18
18
|
Or specify a file with --file`)),console.log(f.gray(`
|
|
19
|
-
Example seed file (seeds/users.json):`)),console.log(f.gray(" [")),console.log(f.gray(' { "name": "John Doe", "email": "john@example.com" },')),console.log(f.gray(' { "name": "Jane Doe", "email": "jane@example.com" }')),console.log(f.gray(" ]")),process.exit(1)),console.log(f.gray("Seed files found:"));for(let p of r)console.log(f.gray(` - ${
|
|
19
|
+
Example seed file (seeds/users.json):`)),console.log(f.gray(" [")),console.log(f.gray(' { "name": "John Doe", "email": "john@example.com" },')),console.log(f.gray(' { "name": "Jane Doe", "email": "jane@example.com" }')),console.log(f.gray(" ]")),process.exit(1)),console.log(f.gray("Seed files found:"));for(let p of r)console.log(f.gray(` - ${b$1.relative(process.cwd(),p)}`));if(console.log(""),o.truncate&&(console.log(f.yellow("\u26A0\uFE0F Tables will be truncated before seeding")),console.log("")),o.dryRun){console.log(f.yellow("Dry run mode - no data will be inserted.")),console.log("");for(let p of r){e.start(`Loading ${b$1.basename(p)}...`);try{let d=await ye(p);e.stop();for(let l of d)o.table&&l.table!==o.table||(console.log(f.cyan(`Table: ${l.table}`)),console.log(f.gray(` Records: ${l.data.length}`)),l.data.length>0&&console.log(f.gray(` Sample: ${JSON.stringify(l.data[0],null,2).slice(0,100)}...`)),console.log(""));}catch(d){e.fail(`Failed to load ${b$1.basename(p)}`),d instanceof Error&&console.log(f.red(` Error: ${d.message}`));}}return}let s=[];for(let p of r){e.start(`Processing ${b$1.basename(p)}...`);try{let d=await ye(p);e.stop();for(let l of d)if(!(o.table&&l.table!==o.table)){if(l.data.length===0){console.log(f.gray(` Skipping ${l.table} (no records)`));continue}e.start(`Seeding ${l.table} (${l.data.length} records)...`);try{let u=await to(t.token,a$1,l.table,l.data,{truncate:o.truncate});e.succeed(`Seeded ${l.table}: ${u.inserted} records`),s.push({table:l.table,inserted:u.inserted});}catch(u){let y=u instanceof Error?u.message:"Unknown error";e.fail(`Failed to seed ${l.table}`),s.push({table:l.table,inserted:0,error:y});}}}catch(d){e.fail(`Failed to load ${b$1.basename(p)}`),d instanceof Error&&console.log(f.red(` Error: ${d.message}`));}}console.log("");let c=s.reduce((p,d)=>p+d.inserted,0),g=s.filter(p=>p.error).length;if(g===0)console.log(f.green(`\u2713 Successfully seeded ${c} records across ${s.length} table(s)`));else {console.log(f.yellow(`Seeded ${c} records with ${g} error(s)`)),console.log(""),console.log(f.red("Errors:"));for(let p of s.filter(d=>d.error))console.log(f.red(` - ${p.table}: ${p.error}`));}console.log("");}async function je(o){let e=J(),t=b();(!t||!t.token)&&(console.log(f.red("Not logged in")),console.log(f.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=o.config||"vaif.config.json",i=null;try{i=await a(n);}catch{}let a$1=o.projectId||i?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;a$1||(console.log(f.red("No project ID specified")),console.log(f.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1));let r=b$1.resolve(o.dir||"./drizzle");if(console.log(""),console.log(f.bold("VAIF Database Push")),console.log(""),!F.existsSync(r)){let d=b$1.resolve("./migrations");F.existsSync(d)?console.log(f.gray(`Using migrations from: ${d}`)):(console.log(f.red(`Migrations directory not found: ${r}`)),console.log(f.gray(`
|
|
20
20
|
Expected one of:`)),console.log(f.gray(" - ./drizzle/")),console.log(f.gray(" - ./migrations/")),console.log(f.gray(`
|
|
21
|
-
Or specify with: vaif db push --dir <path>`)),process.exit(1));}let s=[],c=F.readdirSync(r,{withFileTypes:true});for(let d of c)if(d.isFile()&&d.name.endsWith(".sql"))s.push(
|
|
21
|
+
Or specify with: vaif db push --dir <path>`)),process.exit(1));}let s=[],c=F.readdirSync(r,{withFileTypes:true});for(let d of c)if(d.isFile()&&d.name.endsWith(".sql"))s.push(b$1.join(r,d.name));else if(d.isDirectory()){let l=F.readdirSync(b$1.join(r,d.name),{withFileTypes:true});for(let u of l)u.isFile()&&u.name.endsWith(".sql")&&s.push(b$1.join(r,d.name,u.name));}s.sort(),s.length===0&&(console.log(f.yellow("No SQL migration files found")),process.exit(1)),console.log(f.gray(`Found ${s.length} migration(s):`));for(let d of s)console.log(f.gray(` - ${b$1.relative(process.cwd(),d)}`));if(console.log(""),o.dryRun){console.log(f.yellow("Dry run mode - no migrations will be applied.")),console.log("");for(let d of s){let l=F.readFileSync(d,"utf-8");console.log(f.cyan(`--- ${b$1.basename(d)} ---`)),console.log(f.gray(l.slice(0,500))),l.length>500&&console.log(f.gray("...")),console.log("");}return}let g=0,p=0;for(let d of s){let l=F.readFileSync(d,"utf-8"),u=b$1.relative(process.cwd(),d);e.start(`Applying ${u}...`);try{let y=await fetch(`${B}/schema-engine/query/${a$1}`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"Content-Type":"application/json"},body:JSON.stringify({sql:l})});if(!y.ok){let T=await y.text();throw new Error(T)}e.succeed(`Applied ${u}`),g++;}catch(y){let T=y instanceof Error?y.message:"Unknown error";e.fail(`Failed ${u}: ${T}`),p++;}}console.log(""),console.log(p===0?f.green(`Successfully applied ${g} migration(s)`):f.yellow(`Applied ${g}, failed ${p} migration(s)`)),console.log("");}async function ve(o){let e=J(),t=b();(!t||!t.token)&&(console.log(f.red("Not logged in")),console.log(f.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=o.config||"vaif.config.json",i=null;try{i=await a(n);}catch{}let a$1=o.projectId||i?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;a$1||(console.log(f.red("No project ID specified")),console.log(f.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1));let r=b$1.resolve(o.output||"vaif.schema.json");console.log(""),console.log(f.bold("VAIF Database Pull")),console.log(""),e.start("Pulling schema from remote...");try{let s=await fetch(`${B}/schema-engine/introspect/${a$1}`,{headers:{Authorization:`Bearer ${t.token}`}});if(!s.ok){let p=await s.text();throw new Error(`Failed to pull schema: ${p}`)}let c=await s.json();F.writeFileSync(r,JSON.stringify(c,null,2),"utf-8"),e.succeed(`Schema written to ${b$1.relative(process.cwd(),r)}`);let g=c.tables?.length??Object.keys(c).length;console.log(f.gray(` ${g} table(s) pulled`)),console.log("");}catch(s){e.fail("Failed to pull schema"),s instanceof Error&&console.log(f.red(`
|
|
22
22
|
Error: ${s.message}`)),process.exit(1);}}async function Ie(o){let e=J(),t=b();(!t||!t.token)&&(console.log(f.red("Not logged in")),console.log(f.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=o.config||"vaif.config.json",i=null;try{i=await a(n);}catch{}let a$1=o.projectId||i?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;a$1||(console.log(f.red("No project ID specified")),process.exit(1)),console.log(""),console.log(f.red.bold("\u26A0\uFE0F DATABASE RESET")),console.log(""),console.log(f.red("This will:")),console.log(f.red(" - Drop all tables")),console.log(f.red(" - Delete all data")),console.log(f.red(" - Reset migrations")),console.log(""),console.log(f.red.bold("This action cannot be undone!")),console.log(""),o.force||(console.log(f.yellow("Use --force to confirm this action.")),process.exit(1)),e.start("Resetting database...");try{await no(t.token,a$1),e.succeed("Database reset complete"),console.log(""),console.log(f.gray("Your database is now empty.")),console.log(f.gray("Run `vaif push` to apply your schema, then `vaif db seed` to seed data.")),console.log("");}catch(r){e.fail("Failed to reset database"),r instanceof Error&&console.log(f.red(`
|
|
23
|
-
Error: ${r.message}`)),process.exit(1);}}var
|
|
24
|
-
Error: ${s.message}`)),process.exit(1);}}async function Ae(o){let e=J(),t=b();(!t||!t.token)&&(console.log(f.red("Not logged in")),console.log(f.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=o.config||"vaif.config.json",i=null;try{i=await a(n);}catch{}let a$1=Se(o,i,t);a$1||(console.log(f.red("No project ID specified")),console.log(f.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),console.log(""),console.log(f.bold("VAIF API Keys")),console.log(""),e.start("Fetching API keys...");try{let r=await fetch(`${
|
|
23
|
+
Error: ${r.message}`)),process.exit(1);}}var $e=process.env.VAIF_API_URL||"https://api.vaif.studio";function Se(o,e,t){return o.projectId||e?.projectId||process.env.VAIF_PROJECT_ID||t.projectId||null}async function ke(o){let e=J(),t=b();(!t||!t.token)&&(console.log(f.red("Not logged in")),console.log(f.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=o.config||"vaif.config.json",i=null;try{i=await a(n);}catch{}let a$1=Se(o,i,t);a$1||(console.log(f.red("No project ID specified")),console.log(f.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1));let r=o.name||`cli-key-${Date.now()}`;console.log(""),console.log(f.bold("VAIF Generate API Key")),console.log(""),e.start("Generating API key...");try{let s=await fetch(`${$e}/projects/${a$1}/api-keys`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"Content-Type":"application/json"},body:JSON.stringify({name:r})});if(!s.ok){let g=await s.text();throw new Error(`Failed to generate key: ${g}`)}let c=await s.json();e.succeed("API key generated"),console.log(""),console.log(f.green(` Name: ${c.name}`)),console.log(f.green(` Key: ${c.key}`)),console.log(""),console.log(f.yellow.bold(" Save this key now - it will not be shown again!")),console.log("");}catch(s){e.fail("Failed to generate API key"),s instanceof Error&&console.log(f.red(`
|
|
24
|
+
Error: ${s.message}`)),process.exit(1);}}async function Ae(o){let e=J(),t=b();(!t||!t.token)&&(console.log(f.red("Not logged in")),console.log(f.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=o.config||"vaif.config.json",i=null;try{i=await a(n);}catch{}let a$1=Se(o,i,t);a$1||(console.log(f.red("No project ID specified")),console.log(f.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),console.log(""),console.log(f.bold("VAIF API Keys")),console.log(""),e.start("Fetching API keys...");try{let r=await fetch(`${$e}/projects/${a$1}/api-keys`,{headers:{Authorization:`Bearer ${t.token}`}});if(!r.ok){let d=await r.text();throw new Error(`Failed to list keys: ${d}`)}let s=await r.json(),c=s.keys||s;if(e.stop(),!Array.isArray(c)||c.length===0){console.log(f.yellow("No API keys found")),console.log(f.gray(`
|
|
25
25
|
Generate one with: vaif keys generate`));return}let g=Math.max(8,...c.map(d=>(d.name||"").length)),p=` ${"Name".padEnd(g)} ${"Key".padEnd(24)} Created`;console.log(f.gray(p)),console.log(f.gray(" "+"-".repeat(p.length-2)));for(let d of c){let l=(d.name||"unnamed").padEnd(g),u=d.maskedKey||d.prefix||`${(d.key||"").slice(0,12)}...`,y=d.createdAt?new Date(d.createdAt).toLocaleDateString():"N/A";console.log(` ${l} ${u.padEnd(24)} ${y}`);}console.log(""),console.log(f.gray(` ${c.length} key(s) total`)),console.log("");}catch(r){e.fail("Failed to list API keys"),r instanceof Error&&console.log(f.red(`
|
|
26
|
-
Error: ${r.message}`)),process.exit(1);}}var _=process.env.VAIF_API_URL||"https://api.vaif.studio";function io(o,e,t){return o.projectId||e?.projectId||process.env.VAIF_PROJECT_ID||t.projectId||null}function
|
|
27
|
-
Error: ${c.message}`)),process.exit(1);}}async function Ce(o){let e=J(),t=
|
|
26
|
+
Error: ${r.message}`)),process.exit(1);}}var _=process.env.VAIF_API_URL||"https://api.vaif.studio";function io(o,e,t){return o.projectId||e?.projectId||process.env.VAIF_PROJECT_ID||t.projectId||null}function q(){let o=b();return (!o||!o.token)&&(console.log(f.red("Not logged in")),console.log(f.gray("Run `vaif login` first to authenticate")),process.exit(1)),o}async function M(o){try{return await a(o||"vaif.config.json")}catch{return null}}function W(o,e,t){let n=io(o,e,t);return n||(console.log(f.red("No project ID specified")),console.log(f.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),n}async function Pe(o,e,t){let n=J(),i=q(),a=await M(t.config),r=W(t,a,i),s=e;if(t.fromFile)try{s=F.readFileSync(t.fromFile,"utf-8");}catch(c){console.log(f.red(`Failed to read file: ${t.fromFile}`)),c instanceof Error&&console.log(f.gray(c.message)),process.exit(1);}s||(console.log(f.red("No value provided")),console.log(f.gray("Provide a value as argument or use --from-file <path>")),process.exit(1)),console.log(""),console.log(f.bold("VAIF Set Secret")),console.log(""),n.start("Checking for existing secret...");try{let c=new URL(`${_}/functions/secrets/project/${r}`);t.envId&&c.searchParams.set("envId",t.envId);let g=await fetch(c.toString(),{headers:{Authorization:`Bearer ${i.token}`}});if(!g.ok)throw new Error(`Failed to check existing secrets: ${await g.text()}`);let d=(await g.json()).find(l=>l.key===o);if(d){n.text=`Updating secret "${o}"...`;let l=await fetch(`${_}/functions/secrets/${d.id}`,{method:"PUT",headers:{Authorization:`Bearer ${i.token}`,"Content-Type":"application/json"},body:JSON.stringify({value:s})});if(!l.ok)throw new Error(`Failed to update secret: ${await l.text()}`);n.succeed(`Updated secret "${o}"`);}else {n.text=`Creating secret "${o}"...`;let l=await fetch(`${_}/functions/secrets`,{method:"POST",headers:{Authorization:`Bearer ${i.token}`,"Content-Type":"application/json"},body:JSON.stringify({projectId:r,envId:t.envId,key:o,value:s})});if(!l.ok)throw new Error(`Failed to create secret: ${await l.text()}`);n.succeed(`Created secret "${o}"`);}console.log("");}catch(c){n.fail("Failed to set secret"),c instanceof Error&&console.log(f.red(`
|
|
27
|
+
Error: ${c.message}`)),process.exit(1);}}async function Ce(o){let e=J(),t=q(),n=await M(o.config),i=W(o,n,t);console.log(""),console.log(f.bold("VAIF Secrets")),console.log(""),e.start("Fetching secrets...");try{let a=new URL(`${_}/functions/secrets/project/${i}`);o.envId&&a.searchParams.set("envId",o.envId);let r=await fetch(a.toString(),{headers:{Authorization:`Bearer ${t.token}`}});if(!r.ok)throw new Error(`Failed to list secrets: ${await r.text()}`);let s=await r.json();if(e.stop(),s.length===0){console.log(f.yellow("No secrets found")),console.log(f.gray(`
|
|
28
28
|
Create one with: vaif secrets set <name> <value>`));return}let c=Math.max(8,...s.map(p=>p.key.length)),g=` ${"Name".padEnd(c)} Created`;console.log(f.gray(g)),console.log(f.gray(" "+"-".repeat(g.length-2)));for(let p of s){let d=p.key.padEnd(c),l=p.createdAt?new Date(p.createdAt).toLocaleDateString():"N/A";console.log(` ${d} ${l}`);}console.log(""),console.log(f.gray(` ${s.length} secret(s) total`)),console.log(f.gray(" Values are hidden. Use `vaif secrets get <name>` to reveal.")),console.log("");}catch(a){e.fail("Failed to list secrets"),a instanceof Error&&console.log(f.red(`
|
|
29
|
-
Error: ${a.message}`)),process.exit(1);}}async function Ee(o,e){let t=J(),n=
|
|
30
|
-
Error: ${r.message}`)),process.exit(1);}}async function xe(o,e){let t=J(),n=
|
|
31
|
-
Error: ${r.message}`)),process.exit(1);}}var Fe=process.env.VAIF_API_URL||"https://api.vaif.studio";function ao(o){try{let e=new URL(o);return e.password&&(e.password="****"),e.toString()}catch{return o.replace(/:[^@/]+@/,":****@")}}async function
|
|
32
|
-
Error: ${r.message}`)),process.exit(1);}}var lo=process.env.VAIF_API_URL||"https://api.vaif.studio";async function
|
|
33
|
-
Error: ${r.message}`)),process.exit(1);}}var
|
|
29
|
+
Error: ${a.message}`)),process.exit(1);}}async function Ee(o,e){let t=J(),n=q(),i=await M(e.config),a=W(e,i,n);console.log(""),t.start("Fetching secret...");try{let r=new URL(`${_}/functions/secrets/project/${a}`);e.envId&&r.searchParams.set("envId",e.envId);let s=await fetch(r.toString(),{headers:{Authorization:`Bearer ${n.token}`}});if(!s.ok)throw new Error(`Failed to fetch secrets: ${await s.text()}`);let g=(await s.json()).find(l=>l.key===o);g||(t.fail(`Secret "${o}" not found`),process.exit(1));let p=await fetch(`${_}/functions/secrets/${g.id}/value`,{headers:{Authorization:`Bearer ${n.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(r){t.fail("Failed to get secret"),r instanceof Error&&console.log(f.red(`
|
|
30
|
+
Error: ${r.message}`)),process.exit(1);}}async function xe(o,e){let t=J(),n=q(),i=await M(e.config),a=W(e,i,n);console.log(""),console.log(f.bold("VAIF Delete Secret")),console.log(""),t.start("Finding secret...");try{let r=new URL(`${_}/functions/secrets/project/${a}`);e.envId&&r.searchParams.set("envId",e.envId);let s=await fetch(r.toString(),{headers:{Authorization:`Bearer ${n.token}`}});if(!s.ok)throw new Error(`Failed to fetch secrets: ${await s.text()}`);let g=(await s.json()).find(d=>d.key===o);g||(t.fail(`Secret "${o}" not found`),process.exit(1)),t.text=`Deleting secret "${o}"...`;let p=await fetch(`${_}/functions/secrets/${g.id}`,{method:"DELETE",headers:{Authorization:`Bearer ${n.token}`}});if(!p.ok)throw new Error(`Failed to delete secret: ${await p.text()}`);t.succeed(`Deleted secret "${o}"`),console.log("");}catch(r){t.fail("Failed to delete secret"),r instanceof Error&&console.log(f.red(`
|
|
31
|
+
Error: ${r.message}`)),process.exit(1);}}var Fe=process.env.VAIF_API_URL||"https://api.vaif.studio";function ao(o){try{let e=new URL(o);return e.password&&(e.password="****"),e.toString()}catch{return o.replace(/:[^@/]+@/,":****@")}}async function Te(o){let e=J(),t=b();(!t||!t.token)&&(console.log(f.red("Not logged in")),console.log(f.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=o.config||"vaif.config.json",i=null;try{i=await a(n);}catch{}let a$1=o.projectId||i?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;a$1||(console.log(f.red("No project ID specified")),console.log(f.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),e.start("Fetching project info...");try{let r=await fetch(`${Fe}/projects/${a$1}`,{headers:{Authorization:`Bearer ${t.token}`}});if(!r.ok){let p=await r.text();throw new Error(`Failed to fetch project: ${p}`)}let s=await r.json();e.stop(),console.log(""),console.log(f.bold("VAIF Project Info")),console.log("");let c=16,g=(p,d)=>{console.log(` ${f.gray(p.padEnd(c))} ${d}`);};g("Name:",f.white(s.name||"N/A")),g("Project ID:",f.white(a$1)),g("Region:",f.white(s.region||"us-east-1")),g("Plan:",f.white(s.plan||s.tier||"free")),g("Created:",f.white(s.createdAt?new Date(s.createdAt).toLocaleDateString():"N/A")),console.log(""),g("API URL:",f.cyan(s.apiUrl||`${Fe}/v1`)),g("WS URL:",f.cyan(s.wsUrl||s.realtimeUrl||"N/A")),g("DB URL:",f.cyan(s.databaseUrl?ao(s.databaseUrl):"N/A")),g("Storage URL:",f.cyan(s.storageUrl||"N/A")),console.log("");}catch(r){e.fail("Failed to fetch project info"),r instanceof Error&&console.log(f.red(`
|
|
32
|
+
Error: ${r.message}`)),process.exit(1);}}var lo=process.env.VAIF_API_URL||"https://api.vaif.studio";async function De(o){let e=J(),t=b();(!t||!t.token)&&(console.log(f.red("Not logged in")),console.log(f.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=o.config||"vaif.config.json",i=null;try{i=await a(n);}catch{}let a$1=o.projectId||i?.projectId||process.env.VAIF_PROJECT_ID||t.projectId;a$1||(console.log(f.red("No project ID specified")),console.log(f.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),e.start("Fetching project status...");try{let r=await fetch(`${lo}/projects/${a$1}?include=tables,functions,storage,connections`,{headers:{Authorization:`Bearer ${t.token}`}});if(!r.ok){let y=await r.text();throw new Error(`Failed to fetch project status: ${y}`)}let s=await r.json();e.stop(),console.log(""),console.log(f.bold("VAIF Project Status")),console.log("");let c=22,g=(y,T)=>{console.log(` ${f.gray(y.padEnd(c))} ${T}`);};g("Project:",f.white(s.name||a$1)),g("Plan:",f.white(s.plan||s.tier||"free")),console.log(""),console.log(f.gray(" --- Resources ---")),console.log("");let p=s.tableCount??s.tables?.length??"N/A",d=s.functionCount??s.functions?.length??"N/A",l=s.bucketCount??s.storage?.buckets?.length??"N/A",u=s.activeConnections??s.connections??"N/A";g("Tables:",f.white(String(p))),g("Functions:",f.white(String(d))),g("Storage Buckets:",f.white(String(l))),g("Active Connections:",f.white(String(u))),s.usage&&(console.log(""),console.log(f.gray(" --- Usage ---")),console.log(""),s.usage.dbSize&&g("Database Size:",f.white(s.usage.dbSize)),s.usage.storageSize&&g("Storage Size:",f.white(s.usage.storageSize)),s.usage.bandwidth&&g("Bandwidth:",f.white(s.usage.bandwidth)),s.usage.functionInvocations!=null&&g("Function Invocations:",f.white(String(s.usage.functionInvocations)))),console.log("");}catch(r){e.fail("Failed to fetch project status"),r instanceof Error&&console.log(f.red(`
|
|
33
|
+
Error: ${r.message}`)),process.exit(1);}}var N=process.env.VAIF_API_URL||"https://api.vaif.studio";function go(o){let e=We.createInterface({input:process.stdin,output:process.stdout});return new Promise(t=>{e.question(o,n=>{e.close(),t(n.trim());});})}function po(o,e,t){return o.projectId||e?.projectId||process.env.VAIF_PROJECT_ID||t.projectId||null}async function uo(o){let e=J("Fetching your projects...").start();try{let t=await fetch(`${N}/projects`,{headers:{Authorization:`Bearer ${o}`}});if(!t.ok)return e.fail("Could not fetch projects"),null;let n=await t.json();if(!n||n.length===0)return e.fail("No projects found. Create a project at https://vaif.studio first."),null;if(n.length===1)return e.succeed(`Found project: ${f.cyan(n[0].name)} (${n[0].id})`),n[0].id;e.succeed(`Found ${n.length} projects
|
|
34
34
|
`);for(let r=0;r<n.length;r++)console.log(f.gray(` ${r+1}.`)+` ${f.white(n[r].name)} ${f.gray(`(${n[r].id})`)}`);console.log("");let i=await go(f.cyan(` Select a project [1-${n.length}]: `)),a=parseInt(i,10)-1;return isNaN(a)||a<0||a>=n.length?(console.log(f.red(`
|
|
35
35
|
Invalid selection.`)),null):n[a].id}catch{return e.fail("Could not fetch projects"),null}}function ho(o){if(!o||o.length===0)return "*No tables found. Create tables in the VAIF Studio dashboard.*";let e="";for(let t of o){e+=`### \`${t.name}\`
|
|
36
36
|
|
|
@@ -390,6 +390,50 @@ const result = await vaif.functions.invoke("send_welcome_email", {
|
|
|
390
390
|
});
|
|
391
391
|
\`\`\`
|
|
392
392
|
|
|
393
|
+
### Authenticated Context in Functions
|
|
394
|
+
|
|
395
|
+
Access the caller's verified identity via \\\`vaif.auth\\\`:
|
|
396
|
+
|
|
397
|
+
\`\`\`typescript
|
|
398
|
+
export default async function handler(req) {
|
|
399
|
+
const auth = vaif.auth;
|
|
400
|
+
// auth.type = 'user' | 'api_key' | 'function'
|
|
401
|
+
// auth.userId \u2014 User ID (for user/function types)
|
|
402
|
+
// auth.email \u2014 User email (for user type)
|
|
403
|
+
// auth.projectId \u2014 Always present
|
|
404
|
+
// auth.scopes \u2014 API key scopes (for api_key type)
|
|
405
|
+
|
|
406
|
+
if (!auth || auth.type !== 'user') {
|
|
407
|
+
return { statusCode: 401, body: { error: 'Unauthorized' } };
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
return { body: { message: "Hello " + auth.email } };
|
|
411
|
+
}
|
|
412
|
+
\`\`\`
|
|
413
|
+
|
|
414
|
+
### Function-to-Function Invocation
|
|
415
|
+
|
|
416
|
+
Call other functions from within a handler:
|
|
417
|
+
|
|
418
|
+
\`\`\`typescript
|
|
419
|
+
export default async function handler(req) {
|
|
420
|
+
const result = await vaif.invoke("send_email", {
|
|
421
|
+
to: "user@example.com",
|
|
422
|
+
subject: "Hello",
|
|
423
|
+
});
|
|
424
|
+
return { statusCode: 200, body: result };
|
|
425
|
+
}
|
|
426
|
+
\`\`\`
|
|
427
|
+
|
|
428
|
+
### Database Triggers
|
|
429
|
+
|
|
430
|
+
Fire functions automatically on insert/update/delete events. Configure triggers via the API:
|
|
431
|
+
|
|
432
|
+
\`\`\`
|
|
433
|
+
POST /functions/\\\${functionId}/triggers
|
|
434
|
+
{ "event": "db.insert", "tableName": "orders", "enabled": true }
|
|
435
|
+
\`\`\`
|
|
436
|
+
|
|
393
437
|
## API Key Management
|
|
394
438
|
|
|
395
439
|
API keys are project-scoped and used for data-plane authentication (CRUD, storage, functions).
|
|
@@ -476,6 +520,87 @@ The SDK supports these filter operators:
|
|
|
476
520
|
| \`ilike\` | Pattern match (case-insensitive) | \`.ilike("name", "%john%")\` |
|
|
477
521
|
| \`is\` | IS comparison (null, true, false) | \`.is("deleted_at", null)\` |
|
|
478
522
|
|
|
523
|
+
### JSONB Subkey Filters
|
|
524
|
+
|
|
525
|
+
Filter on nested JSONB fields using arrow notation:
|
|
526
|
+
|
|
527
|
+
| Filter | SQL Generated |
|
|
528
|
+
|--------|--------------|
|
|
529
|
+
| \\\`filter[metadata->status]=active\\\` | \\\`metadata->>'status' = 'active'\\\` |
|
|
530
|
+
| \\\`filter[config->theme.ilike]=%dark%\\\` | \\\`config->>'theme' ILIKE '%dark%'\\\` |
|
|
531
|
+
| \\\`filter[data->user->role]=admin\\\` | \\\`data->'user'->>'role' = 'admin'\\\` |
|
|
532
|
+
|
|
533
|
+
All standard operators work with JSONB paths. The last segment uses \\\`->>\\\` (text extraction).
|
|
534
|
+
|
|
535
|
+
### Compound Filters (AND + OR)
|
|
536
|
+
|
|
537
|
+
Combine AND and OR conditions:
|
|
538
|
+
|
|
539
|
+
\`\`\`
|
|
540
|
+
?filter[status]=active&or_filter[role]=admin&or_filter[role]=moderator
|
|
541
|
+
\`\`\`
|
|
542
|
+
|
|
543
|
+
This generates: \\\`WHERE status = 'active' AND (role = 'admin' OR role = 'moderator')\\\`
|
|
544
|
+
|
|
545
|
+
### Full-Text Search
|
|
546
|
+
|
|
547
|
+
\`\`\`typescript
|
|
548
|
+
const results = await fetch("${n}/generated/posts/search", {
|
|
549
|
+
method: "POST",
|
|
550
|
+
headers: { "x-vaif-key": "${t}", "Content-Type": "application/json" },
|
|
551
|
+
body: JSON.stringify({
|
|
552
|
+
query: "search term",
|
|
553
|
+
columns: ["title", "body"],
|
|
554
|
+
limit: 20,
|
|
555
|
+
}),
|
|
556
|
+
});
|
|
557
|
+
// Results ranked by ts_rank score
|
|
558
|
+
\`\`\`
|
|
559
|
+
|
|
560
|
+
### Aggregation
|
|
561
|
+
|
|
562
|
+
\`\`\`typescript
|
|
563
|
+
const stats = await fetch("${n}/generated/orders/aggregate", {
|
|
564
|
+
method: "POST",
|
|
565
|
+
headers: { "x-vaif-key": "${t}", "Content-Type": "application/json" },
|
|
566
|
+
body: JSON.stringify({
|
|
567
|
+
aggregates: [
|
|
568
|
+
{ fn: "count", column: "*" },
|
|
569
|
+
{ fn: "sum", column: "total" },
|
|
570
|
+
{ fn: "avg", column: "total" },
|
|
571
|
+
],
|
|
572
|
+
groupBy: ["status"],
|
|
573
|
+
}),
|
|
574
|
+
});
|
|
575
|
+
\`\`\`
|
|
576
|
+
|
|
577
|
+
### Joins (Foreign Key Includes)
|
|
578
|
+
|
|
579
|
+
Include related rows by specifying foreign key columns:
|
|
580
|
+
|
|
581
|
+
\`\`\`
|
|
582
|
+
GET /generated/posts?include=author_id&include=category_id
|
|
583
|
+
\`\`\`
|
|
584
|
+
|
|
585
|
+
Returns posts with \\\`author_id_included\\\` and \\\`category_id_included\\\` objects containing the related rows.
|
|
586
|
+
|
|
587
|
+
### Upsert
|
|
588
|
+
|
|
589
|
+
Insert or update on conflict:
|
|
590
|
+
|
|
591
|
+
\`\`\`typescript
|
|
592
|
+
const result = await fetch("${n}/generated/users", {
|
|
593
|
+
method: "POST",
|
|
594
|
+
headers: { "x-vaif-key": "${t}", "Content-Type": "application/json" },
|
|
595
|
+
body: JSON.stringify({
|
|
596
|
+
email: "alice@example.com",
|
|
597
|
+
name: "Alice",
|
|
598
|
+
_upsert: true,
|
|
599
|
+
_conflictColumns: ["email"],
|
|
600
|
+
}),
|
|
601
|
+
});
|
|
602
|
+
\`\`\`
|
|
603
|
+
|
|
479
604
|
### Pagination
|
|
480
605
|
|
|
481
606
|
\`\`\`typescript
|
|
@@ -540,14 +665,18 @@ The \`.mcp.json\` file configures an MCP server that gives Claude Code direct ac
|
|
|
540
665
|
| Tool | What it does |
|
|
541
666
|
|------|-------------|
|
|
542
667
|
| \`list_tables\`, \`describe_table\` | Inspect database schema |
|
|
543
|
-
| \`query_rows\`, \`insert_row\`, \`update_row\`, \`delete_row\` | CRUD operations on any table |
|
|
544
|
-
| \`create_function\`, \`deploy_function\`, \`invoke_function\` | Create, deploy, and call serverless functions |
|
|
545
|
-
| \`create_bucket\`, \`list_buckets\`, \`list_files\`, \`get_signed_url\` | Storage management |
|
|
546
|
-
| \`enable_realtime\`, \`realtime_status\` | Enable/check realtime subscriptions |
|
|
547
668
|
| \`get_schema\` | Full schema as JSON |
|
|
669
|
+
| \`create_tables\` | Create or update tables declaratively |
|
|
670
|
+
| \`query_rows\` | Query with filters, JSONB paths, pagination |
|
|
671
|
+
| \`insert_row\`, \`update_row\`, \`delete_row\` | CRUD operations on any table |
|
|
672
|
+
| \`list_functions\`, \`deploy_function\`, \`invoke_function\` | Function management |
|
|
673
|
+
| \`get_function_logs\` | Execution history with status filters |
|
|
674
|
+
| \`set_secret\`, \`list_secrets\`, \`delete_secret\` | Function secrets |
|
|
675
|
+
| \`list_buckets\`, \`list_files\`, \`get_signed_url\` | Storage operations |
|
|
676
|
+
| \`enable_realtime\`, \`realtime_status\` | Realtime subscriptions |
|
|
548
677
|
|
|
549
678
|
> **Note**: MCP tools are only available to the main Claude Code session, not to spawned sub-agents (Task tool). The main session should handle all VAIF backend operations directly.
|
|
550
|
-
`}async function
|
|
679
|
+
`}async function Oe(o){let e=J(),t=b();(!t||!t.token)&&(console.log(f.red("Not logged in")),console.log(f.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=o.config||"vaif.config.json",i=null;try{i=await a(n);}catch{}let a$1=po(o,i,t);a$1||(console.log(f.yellow(`No project ID specified \u2014 fetching your projects...
|
|
551
680
|
`)),a$1=await uo(t.token),a$1||(console.log(f.gray(`
|
|
552
|
-
Tip: pass --project-id <id> or set projectId in vaif.config.json`)),process.exit(1)));let r
|
|
553
|
-
`,"utf-8"),e.succeed(`Written ${f.cyan(".mcp.json")}`);}if(!o.skipClaudeMd){e.start("Writing CLAUDE.md...");let d=wo({projectId:a$1,apiKey:p,apiUrl:g,projectName:c,schema:s}),l=$.join(r,"CLAUDE.md");F.writeFileSync(l,d,"utf-8"),e.succeed(`Written ${f.cyan("CLAUDE.md")}`);}console.log(""),console.log(f.green.bold(" Claude Code integration configured!")),console.log(""),o.skipMcp||console.log(f.gray(" MCP Server: ")+f.white(".mcp.json")),o.skipClaudeMd||console.log(f.gray(" Context: ")+f.white("CLAUDE.md")),console.log(""),console.log(f.bold(" Next steps:")),console.log(f.gray(" 1. Open this project in Claude Code")),console.log(f.gray(" 2. The MCP server auto-connects to your VAIF project")),console.log(f.gray(" 3. Ask Claude to query, modify, or build against your schema")),console.log("");}var Oe="1.9.7",X=f.hex("#00f0ff"),Z=f.hex("#7b61ff"),ee=f.hex("#ff3dff"),oe=f.hex("#00ff9d"),j=f.hex("#555570"),N=f.hex("#00f0ff");function jo(){console.log(""),console.log(X(" \u2566 \u2566")+Z("\u2554\u2550\u2557\u2566")+ee("\u2554\u2550\u2557 ")+oe("\u2554\u2550\u2557\u2566 \u2566")),console.log(X(" \u255A\u2557\u2554\u255D")+Z("\u2560\u2550\u2563\u2551")+ee("\u2560\u2563 ")+oe("\u2551 \u2551 \u2551")),console.log(X(" \u255A\u255D ")+Z("\u2569 \u2569\u2569")+ee("\u255A ")+oe("\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(N(" VAIF Studio CLI")+j(` v${Oe}`)),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(f.bold(" Quick Start")),console.log(j(" $ ")+N("vaif login")+j(" Authenticate")),console.log(j(" $ ")+N("vaif init -t react-spa")+j(" Scaffold project")),console.log(j(" $ ")+N("vaif db push")+j(" Push migrations")),console.log(j(" $ ")+N("vaif generate")+j(" Generate types")),console.log(j(" $ ")+N("vaif functions deploy")+j(" Deploy functions")),console.log(""),console.log(f.bold(" Categories")),console.log(j(" auth ")+f.white("login, logout, whoami")),console.log(j(" project ")+f.white("init, templates, info, status")),console.log(j(" schema ")+f.white("pull, push, generate")),console.log(j(" database ")+f.white("db push, db pull, db seed, db reset")),console.log(j(" deploy ")+f.white("functions deploy, functions list")),console.log(j(" security ")+f.white("keys, secrets")),console.log(j(" ai ")+f.white("claude-setup")),console.log(""),console.log(j(" Run ")+N("vaif <command> --help")+j(" for details")),console.log(j(" Docs: ")+f.underline("https://docs.vaif.studio")),console.log("");}program.name("vaif").description("VAIF CLI - Type generation and development tools").version(Oe);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(De);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(Te);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);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(fe);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$1);var Le=program.command("functions").alias("fn").description("Manage serverless functions");Le.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(he);Le.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(me);var G=program.command("db").description("Database management commands");G.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(je);G.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(ve);G.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(we);G.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(Ie);var Ve=program.command("keys").description("Manage API keys");Ve.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(ke);Ve.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(Ae);var Y=program.command("secrets").alias("sec").description("Manage function secrets");Y.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(Pe);Y.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(Ce);Y.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(Ee);Y.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);program.command("claude-setup").description("Configure Claude Code integration (MCP server + CLAUDE.md)").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID").option("-k, --api-key <key>","API key for MCP server").option("--skip-mcp","Skip generating .mcp.json").option("--skip-claude-md","Skip generating CLAUDE.md").option("-o, --output-dir <dir>","Output directory",".").action(Ne);process.argv.slice(2).length||(jo(),process.exit(0));program.parse(process.argv);
|
|
681
|
+
Tip: pass --project-id <id> or set projectId in vaif.config.json`)),process.exit(1)));let r=b$1.resolve(o.outputDir||".");console.log(""),console.log(f.bold("VAIF Claude Code Setup")),console.log(f.gray(` Project: ${a$1}`)),console.log(""),e.start("Fetching database schema...");let s={tables:[]};try{let d=await fetch(`${N}/schema-engine/introspect/${a$1}`,{headers:{Authorization:`Bearer ${t.token}`}});d.ok?(s=await d.json(),e.succeed(`Fetched schema (${s.tables?.length||0} tables)`)):e.warn("Could not fetch schema \u2014 continuing without it");}catch{e.warn("Could not fetch schema \u2014 continuing without it");}e.start("Fetching project info...");let c=a$1,g=N;try{let d=await fetch(`${N}/projects/${a$1}`,{headers:{Authorization:`Bearer ${t.token}`}});if(d.ok){let l=await d.json(),u=l.project||l;c=u.name||a$1,g=u.apiUrl||N,e.succeed(`Project: ${c}`);}else e.warn("Could not fetch project info \u2014 using defaults");}catch{e.warn("Could not fetch project info \u2014 using defaults");}let p=o.apiKey||i?.api?.apiKey||"";if(!p){e.start("Generating API key for Claude Code...");try{let d=`claude-code-${Date.now()}`,l=await fetch(`${N}/projects/${a$1}/api-keys`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"Content-Type":"application/json"},body:JSON.stringify({name:d,scopes:["crud","realtime","functions","storage"]})});if(l.ok){let u=await l.json();p=u.apiKey||u.key,e.succeed(`Generated API key: ${d}`);}else e.fail("Could not auto-generate API key"),console.log(f.yellow(" Pass one with --api-key or generate via `vaif keys generate`")),process.exit(1);}catch{e.fail("Could not auto-generate API key"),console.log(f.yellow(" Pass one with --api-key or generate via `vaif keys generate`")),process.exit(1);}}if(!o.skipMcp){e.start("Writing .mcp.json...");let d={mcpServers:{"vaif-studio":{command:"npx",args:["@vaiftech/mcp"],env:{VAIF_API_KEY:p,VAIF_PROJECT_ID:a$1,VAIF_API_URL:g,VAIF_AUTH_TOKEN:t.token}}}},l=b$1.join(r,".mcp.json");F.writeFileSync(l,JSON.stringify(d,null,2)+`
|
|
682
|
+
`,"utf-8"),e.succeed(`Written ${f.cyan(".mcp.json")}`);}if(!o.skipClaudeMd){e.start("Writing CLAUDE.md...");let d=wo({projectId:a$1,apiKey:p,apiUrl:g,projectName:c,schema:s}),l=b$1.join(r,"CLAUDE.md");F.writeFileSync(l,d,"utf-8"),e.succeed(`Written ${f.cyan("CLAUDE.md")}`);}console.log(""),console.log(f.green.bold(" Claude Code integration configured!")),console.log(""),o.skipMcp||console.log(f.gray(" MCP Server: ")+f.white(".mcp.json")),o.skipClaudeMd||console.log(f.gray(" Context: ")+f.white("CLAUDE.md")),console.log(""),console.log(f.bold(" Next steps:")),console.log(f.gray(" 1. Open this project in Claude Code")),console.log(f.gray(" 2. The MCP server auto-connects to your VAIF project")),console.log(f.gray(" 3. Ask Claude to query, modify, or build against your schema")),console.log("");}var vo=createRequire(import.meta.url),{version:Ne}=vo("../package.json"),X=f.hex("#00f0ff"),Z=f.hex("#7b61ff"),ee=f.hex("#ff3dff"),oe=f.hex("#00ff9d"),j=f.hex("#555570"),O=f.hex("#00f0ff");function Io(){console.log(""),console.log(X(" \u2566 \u2566")+Z("\u2554\u2550\u2557\u2566")+ee("\u2554\u2550\u2557 ")+oe("\u2554\u2550\u2557\u2566 \u2566")),console.log(X(" \u255A\u2557\u2554\u255D")+Z("\u2560\u2550\u2563\u2551")+ee("\u2560\u2563 ")+oe("\u2551 \u2551 \u2551")),console.log(X(" \u255A\u255D ")+Z("\u2569 \u2569\u2569")+ee("\u255A ")+oe("\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${Ne}`)),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(f.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(f.bold(" Categories")),console.log(j(" auth ")+f.white("login, logout, whoami")),console.log(j(" project ")+f.white("init, templates, info, status")),console.log(j(" schema ")+f.white("pull, push, generate")),console.log(j(" database ")+f.white("db push, db pull, db seed, db reset")),console.log(j(" deploy ")+f.white("functions deploy, functions list")),console.log(j(" security ")+f.white("keys, secrets")),console.log(j(" ai ")+f.white("claude-setup")),console.log(""),console.log(j(" Run ")+O("vaif <command> --help")+j(" for details")),console.log(j(" Docs: ")+f.underline("https://docs.vaif.studio")),console.log("");}program.name("vaif").description("VAIF CLI - Type generation and development tools").version(Ne);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(Te);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(De);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);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(fe);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$1);var Le=program.command("functions").alias("fn").description("Manage serverless functions");Le.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(he);Le.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(me);var G=program.command("db").description("Database management commands");G.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(je);G.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(ve);G.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(we);G.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(Ie);var Ue=program.command("keys").description("Manage API keys");Ue.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(ke);Ue.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(Ae);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(Pe);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(Ce);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(Ee);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(xe);program.command("claude-setup").description("Configure Claude Code integration (MCP server + CLAUDE.md)").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID").option("-k, --api-key <key>","API key for MCP server").option("--skip-mcp","Skip generating .mcp.json").option("--skip-claude-md","Skip generating CLAUDE.md").option("-o, --output-dir <dir>","Output directory",".").action(Oe);process.argv.slice(2).length||(Io(),process.exit(0));program.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaiftech/cli",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.8",
|
|
4
4
|
"description": "VAIF CLI - Type generation and development tools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/node": "^22.14.0",
|
|
25
25
|
"@types/pg": "^8.11.0",
|
|
26
|
-
"typescript": "^5.
|
|
26
|
+
"typescript": "^5.8.3",
|
|
27
27
|
"tsup": "^8.5.1"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|