@vaiftech/cli 1.7.0 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{chunk-OB2QEQ2L.js → chunk-KXD5F33V.js} +80 -67
- package/dist/cli.cjs +101 -97
- package/dist/cli.js +28 -37
- package/dist/index.cjs +86 -82
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
'use strict';require('dotenv/config');var commander=require('commander'),f=require('chalk'),
|
|
2
|
+
'use strict';require('dotenv/config');var commander=require('commander'),f=require('chalk'),D=require('fs'),w=require('path'),vt=require('pg'),H=require('ora'),It=require('prettier'),rt=require('dotenv'),lt=require('os'),child_process=require('child_process'),Ie=require('readline');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var f__default=/*#__PURE__*/_interopDefault(f);var D__default=/*#__PURE__*/_interopDefault(D);var w__default=/*#__PURE__*/_interopDefault(w);var vt__default=/*#__PURE__*/_interopDefault(vt);var H__default=/*#__PURE__*/_interopDefault(H);var It__default=/*#__PURE__*/_interopDefault(It);var rt__default=/*#__PURE__*/_interopDefault(rt);var lt__default=/*#__PURE__*/_interopDefault(lt);var Ie__default=/*#__PURE__*/_interopDefault(Ie);rt__default.default.config();async function A(t){let e=w__default.default.resolve(t);if(!D__default.default.existsSync(e))return null;try{let o=D__default.default.readFileSync(e,"utf-8"),n=JSON.parse(o);return n.database?.url&&(n.database.url=ve(n.database.url)),n.api?.apiKey&&(n.api.apiKey=ve(n.api.apiKey)),n}catch{throw new Error(`Failed to parse config file: ${t}`)}}function ve(t){return t.replace(/\$\{([^}]+)\}/g,(e,o)=>process.env[o]||e)}var ae=w__default.default.join(lt__default.default.homedir(),".vaif"),$=w__default.default.join(ae,"auth.json"),J=process.env.VAIF_API_URL||"https://api.vaif.studio";function dt(){D__default.default.existsSync(ae)||D__default.default.mkdirSync(ae,{recursive:true});}function Ae(t){dt(),D__default.default.writeFileSync($,JSON.stringify(t,null,2),"utf-8"),D__default.default.chmodSync($,384);}function I(){if(!D__default.default.existsSync($))return null;try{let t=D__default.default.readFileSync($,"utf-8");return JSON.parse(t)}catch{return null}}function pt(t){let e=Ie__default.default.createInterface({input:process.stdin,output:process.stdout});return new Promise(o=>{e.question(t,n=>{e.close(),o(n);});})}function ut(t){return new Promise(e=>{let o=Ie__default.default.createInterface({input:process.stdin,output:process.stdout});process.stdin;let r=process.stdout.write.bind(process.stdout),s=false;process.stdout.write=((...i)=>s?true:r(...i)),o.question(t,i=>{s=false,process.stdout.write=r,console.log(""),o.close(),e(i);}),s=true;})}function ft(t){let e=process.platform,o;e==="darwin"?o=`open "${t}"`:e==="win32"?o=`start "" "${t}"`:o=`xdg-open "${t}"`,child_process.exec(o,n=>{});}function gt(t){return new Promise(e=>setTimeout(e,t))}async function mt(t){try{let e=await fetch(`${J}/auth/me`,{headers:{Authorization:`Bearer ${t}`}});if(e.ok){let o=await e.json();return {valid:!0,email:o.user?.email||o.email}}return {valid:!1}}catch{return {valid:false}}}async function ht(t){let e=H__default.default();e.start("Setting up authentication...");let o,n;try{let a=await fetch(`${J}/auth/cli/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})});a.ok||(e.fail("Failed to initiate authentication"),console.log(f__default.default.red(`
|
|
3
|
+
Could not connect to VAIF API. Please try again later.`)),process.exit(1));let c=await a.json();o=c.code,n=c.url;}catch{e.fail("Failed to connect to VAIF API"),console.log(f__default.default.red(`
|
|
4
|
+
Could not connect to VAIF API.`)),console.log(f__default.default.gray("Check your internet connection or try: vaif login --email")),process.exit(1);}e.stop(),console.log(f__default.default.cyan(" Opening browser for authentication...")),console.log(""),console.log(f__default.default.gray(" If the browser doesn't open, visit this URL:")),console.log(f__default.default.white(` ${n}`)),console.log(""),ft(n),e.start("Waiting for browser authentication...");let r=12e4,s=2e3,i=Date.now();for(;Date.now()-i<r;){await gt(s);try{let a=await fetch(`${J}/auth/cli/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:o})});if(!a.ok){let l=await a.json();(l.error==="ExpiredCode"||l.error==="InvalidCode")&&(e.fail("Authentication expired"),console.log(f__default.default.red(`
|
|
5
|
+
The authentication session expired. Please try again.`)),process.exit(1));continue}let c=await a.json();if(c.ok&&c.accessToken){let l={token:c.accessToken,email:c.user?.email,projectId:t,expiresAt:new Date(Date.now()+c.expiresIn*1e3).toISOString()};Ae(l),e.succeed("Logged in successfully"),console.log(""),c.user?.email&&console.log(f__default.default.green(` Authenticated as: ${c.user.email}`)),console.log(f__default.default.gray(` Config saved to: ${$}`)),console.log("");return}}catch{}}e.fail("Authentication timed out"),console.log(f__default.default.red(`
|
|
6
|
+
Timed out waiting for browser authentication.`)),console.log(f__default.default.gray("Try again or use: vaif login --email")),process.exit(1);}async function yt(t){console.log(""),console.log(f__default.default.bold("VAIF CLI Login")),console.log(f__default.default.gray("Enter your VAIF account credentials")),console.log("");let e=await pt(f__default.default.cyan(" Email: "));(!e||e.trim()==="")&&(console.log(f__default.default.red(`
|
|
7
|
+
No email provided. Login cancelled.`)),process.exit(1));let o=await ut(f__default.default.cyan(" Password: "));(!o||o.trim()==="")&&(console.log(f__default.default.red(`
|
|
8
|
+
No password provided. Login cancelled.`)),process.exit(1));let n=H__default.default("Authenticating...").start();try{let r=await fetch(`${J}/auth/cli/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e.trim(),password:o})}),s=await r.json();(!r.ok||!s.ok)&&(n.fail("Login failed"),console.log(f__default.default.red(`
|
|
9
|
+
${s.message||"Invalid email or password."}`)),process.exit(1));let i={token:s.accessToken,email:s.user?.email,projectId:t,expiresAt:new Date(Date.now()+s.expiresIn*1e3).toISOString()};Ae(i),n.succeed("Logged in successfully"),console.log(""),s.user?.email&&console.log(f__default.default.green(` Authenticated as: ${s.user.email}`)),console.log(f__default.default.gray(` Config saved to: ${$}`)),console.log("");}catch{n.fail("Failed to connect to VAIF API"),console.log(f__default.default.red(`
|
|
10
|
+
Could not connect to VAIF API. Please try again later.`)),process.exit(1);}}async function we(t){console.log(""),console.log(f__default.default.bold("Welcome to VAIF CLI")),console.log(f__default.default.gray("Authenticate to access your VAIF projects")),console.log(""),t.email?await yt(t.projectId):await ht(t.projectId),console.log(f__default.default.gray("You can now use VAIF CLI commands like:")),console.log(f__default.default.gray(" vaif pull - Pull remote schema")),console.log(f__default.default.gray(" vaif push - Push schema changes")),console.log(f__default.default.gray(" vaif generate - Generate TypeScript types")),console.log("");}async function Se(){D__default.default.existsSync($)?(D__default.default.unlinkSync($),console.log(f__default.default.green("Logged out successfully"))):console.log(f__default.default.yellow("Not currently logged in"));}async function _e(){let t=I();(!t||!t.token)&&(console.log(f__default.default.yellow("Not logged in")),console.log(f__default.default.gray("Run `vaif login` to authenticate")),process.exit(1));let e=H__default.default("Checking authentication...").start(),{valid:o,email:n}=await mt(t.token);o||(e.fail("Session expired"),console.log(f__default.default.yellow(`
|
|
11
|
+
Your session has expired. Please login again.`)),process.exit(1)),e.succeed("Authenticated"),console.log(""),console.log(f__default.default.green(` Email: ${n||t.email||"Unknown"}`)),t.projectId&&console.log(f__default.default.green(` Project: ${t.projectId}`)),console.log("");}var At=process.env.VAIF_API_URL||"https://api.vaif.studio";async function wt(t,e){let o=await fetch(`${At}/schema-engine/introspect/${e}`,{headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!o.ok){let a=await o.text();throw new Error(`API introspection failed: ${a}`)}let n=await o.json();if(!n.ok||!n.schemaExists)throw new Error("Project schema does not exist yet. Push a migration first with `vaif db push`.");let r=new Map,s=[];for(let a of n.tables){let c=a.columns.map(l=>({column_name:l.name,data_type:l.type,is_nullable:l.nullable?"YES":"NO",column_default:l.default,udt_name:l.type,is_identity:l.primaryKey&&l.default?.includes("gen_random_uuid")?"YES":"NO",character_maximum_length:null,numeric_precision:null,numeric_scale:null}));r.set(a.name,c);for(let l of a.foreignKeys)s.push({constraint_name:l.constraintName,table_name:a.name,column_name:l.columnName,foreign_table_name:l.refTable,foreign_column_name:l.refColumn});}return {tables:r,enums:new Map,foreignKeys:s}}async function St(t,e){let o=await t.query(`
|
|
3
12
|
SELECT table_name, table_type
|
|
4
13
|
FROM information_schema.tables
|
|
5
14
|
WHERE table_schema = $1
|
|
@@ -45,22 +54,24 @@
|
|
|
45
54
|
JOIN pg_namespace n ON n.oid = t.typnamespace
|
|
46
55
|
WHERE n.nspname = $1
|
|
47
56
|
ORDER BY t.typname, e.enumsortorder
|
|
48
|
-
`,[e]),i=new Map;for(let
|
|
57
|
+
`,[e]),i=new Map;for(let c of o.rows)i.set(c.table_name,[]);for(let c of n.rows){let l=i.get(c.table_name);l&&l.push(c);}let a=new Map;for(let c of s.rows){let l=a.get(c.enum_name)||[];l.push(c.enum_value),a.set(c.enum_name,l);}return {tables:i,enums:a,foreignKeys:r.rows}}var re={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 _t(t,e){let{data_type:o,udt_name:n,is_nullable:r}=t;if(e.has(n)){let a=e.get(n).map(c=>`"${c}"`).join(" | ");return r==="YES"?`(${a}) | null`:a}if(o==="ARRAY"){let i=n.replace(/^_/,"");if(e.has(i)){let l=e.get(i).map(p=>`"${p}"`).join(" | ");return r==="YES"?`(${l})[] | null`:`(${l})[]`}let a=re[i]||"unknown";return r==="YES"?`${a}[] | null`:`${a}[]`}let s=re[o]||re[n]||"unknown";return r==="YES"&&(s=`${s} | null`),s}function le(t){return t.split(/[_\-\s]+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join("")}function Et(t,e){let o=le(t),n=e.map(r=>` | "${r}"`).join(`
|
|
49
58
|
`);return `export type ${o} =
|
|
50
|
-
${n};`}function
|
|
59
|
+
${n};`}function xt(t,e,o){let n=le(t),r=[],s=[],i=[];for(let p of e){let u=_t(p,o),d=p.column_name,m=p.column_default!==null||p.is_identity==="YES",y=p.is_nullable==="YES";r.push(` ${d}: ${u};`),m||p.column_name==="id"?s.push(` ${d}?: ${u.replace(" | null","")} | null;`):y?s.push(` ${d}?: ${u};`):s.push(` ${d}: ${u.replace(" | null","")};`),i.push(` ${d}?: ${u.replace(" | null","")} | null;`);}let a=`export interface ${n} {
|
|
51
60
|
${r.join(`
|
|
52
61
|
`)}
|
|
53
|
-
}`,
|
|
62
|
+
}`,c=`export interface ${n}Insert {
|
|
54
63
|
${s.join(`
|
|
55
64
|
`)}
|
|
56
|
-
}`,
|
|
65
|
+
}`,l=`export interface ${n}Update {
|
|
57
66
|
${i.join(`
|
|
58
67
|
`)}
|
|
59
|
-
}`;return {base:a,insert:
|
|
60
|
-
`)}async function
|
|
61
|
-
|
|
68
|
+
}`;return {base:a,insert:c,update:l}}function Tt(t,e,o){let n=["/**"," * Auto-generated TypeScript types from database schema"," * Generated by @vaiftech/cli",` * Generated at: ${new Date().toISOString()}`," * "," * DO NOT EDIT MANUALLY - changes will be overwritten"," */",""];if(e.size>0){n.push("// ============ ENUMS ============"),n.push("");for(let[s,i]of e)n.push(Et(s,i)),n.push("");}n.push("// ============ TABLES ============"),n.push("");let r=[];for(let[s,i]of t){let{base:a,insert:c,update:l}=xt(s,i,e);r.push(s),n.push(a),n.push(""),n.push(c),n.push(""),n.push(l),n.push("");}n.push("// ============ DATABASE SCHEMA ============"),n.push(""),n.push("export interface Database {");for(let s of r){let i=le(s);n.push(` ${s}: {`),n.push(` Row: ${i};`),n.push(` Insert: ${i}Insert;`),n.push(` Update: ${i}Update;`),n.push(" };");}return n.push("}"),n.push(""),n.push("export type TableName = keyof Database;"),n.push(""),n.push("// ============ HELPER TYPES ============"),n.push(""),n.push('export type Row<T extends TableName> = Database[T]["Row"];'),n.push('export type Insert<T extends TableName> = Database[T]["Insert"];'),n.push('export type Update<T extends TableName> = Database[T]["Update"];'),n.push(""),n.join(`
|
|
69
|
+
`)}async function xe(t){let e=H__default.default("Loading configuration...").start();try{let o=await A(t.config),n=t.connection||o?.database?.url||process.env.DATABASE_URL,r=n&&!n.includes("${"),s,i,a;if(r){e.text="Connecting to database...";let d=new vt__default.default.Client({connectionString:n});await d.connect(),e.text="Introspecting schema...",{tables:s,enums:i,foreignKeys:a}=await St(d,t.schema),await d.end();}else {let d=I();(!d||!d.token)&&(e.fail("No database connection and not logged in"),console.log(f__default.default.yellow(`
|
|
70
|
+
Either:`)),console.log(f__default.default.gray(" 1. Run `vaif login` to authenticate (no DATABASE_URL needed)")),console.log(f__default.default.gray(" 2. Set DATABASE_URL in your .env file")),console.log(f__default.default.gray(" 3. Pass --connection postgresql://user:pass@host:5432/db")),process.exit(1));let m=o?.projectId||process.env.VAIF_PROJECT_ID||d.projectId;m||(e.fail("No project ID specified"),console.log(f__default.default.yellow(`
|
|
71
|
+
Set projectId in vaif.config.json or use VAIF_PROJECT_ID env var.`)),process.exit(1)),e.text="Introspecting schema via API...",{tables:s,enums:i,foreignKeys:a}=await wt(d.token,m);}if(s.size===0){e.warn("No tables found"),console.log(f__default.default.yellow(`
|
|
72
|
+
Push a migration first: vaif db push`));return}e.text=`Generating types for ${s.size} tables...`;let c=Tt(s,i,a),l=await It__default.default.format(c,{parser:"typescript",semi:!0,singleQuote:!1,trailingComma:"es5",printWidth:100});if(t.dryRun){e.succeed("Generated types (dry run):"),console.log(""),console.log(f__default.default.gray("\u2500".repeat(60))),console.log(l),console.log(f__default.default.gray("\u2500".repeat(60)));return}let p=w__default.default.resolve(t.output),u=w__default.default.dirname(p);D__default.default.existsSync(u)||D__default.default.mkdirSync(u,{recursive:!0}),D__default.default.writeFileSync(p,l,"utf-8"),e.succeed(`Generated types for ${s.size} tables \u2192 ${f__default.default.cyan(t.output)}`),console.log(""),console.log(f__default.default.green("Generated:")),console.log(f__default.default.gray(` Tables: ${s.size}`)),console.log(f__default.default.gray(` Enums: ${i.size}`)),console.log(""),console.log(f__default.default.gray("Import in your code:")),console.log(f__default.default.cyan(` import type { Database, Row, Insert, Update } from "${t.output.replace(/\.ts$/,"")}";`));}catch(o){e.fail("Failed to generate types"),o instanceof Error&&(console.error(f__default.default.red(`
|
|
62
73
|
Error: ${o.message}`)),o.message.includes("ECONNREFUSED")&&console.log(f__default.default.yellow(`
|
|
63
|
-
Make sure your database is running and accessible.`))),process.exit(1);}}var B=[{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"}],
|
|
74
|
+
Make sure your database is running and accessible.`))),process.exit(1);}}var B=[{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"}],Fe={"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:`{
|
|
64
75
|
"name": "my-vaif-app",
|
|
65
76
|
"private": true,
|
|
66
77
|
"version": "0.1.0",
|
|
@@ -156,24 +167,27 @@ body {
|
|
|
156
167
|
|
|
157
168
|
// Browser client \u2013 safe to use in Client Components
|
|
158
169
|
export const vaif = createVaifClient({
|
|
159
|
-
|
|
170
|
+
baseUrl: process.env.NEXT_PUBLIC_VAIF_API_URL || 'https://api.vaif.studio',
|
|
160
171
|
apiKey: process.env.NEXT_PUBLIC_VAIF_API_KEY!,
|
|
161
172
|
});
|
|
162
173
|
|
|
163
174
|
// Server client \u2013 use in Server Components, Route Handlers, Server Actions
|
|
164
175
|
export function createVaifServer() {
|
|
165
176
|
return createVaifClient({
|
|
166
|
-
|
|
167
|
-
|
|
177
|
+
baseUrl: process.env.NEXT_PUBLIC_VAIF_API_URL || 'https://api.vaif.studio',
|
|
178
|
+
apiKey: process.env.VAIF_SECRET_KEY!,
|
|
168
179
|
});
|
|
169
180
|
}
|
|
170
181
|
`},{path:".env.local.example",content:`# VAIF Configuration
|
|
171
182
|
# Get these values from https://vaif.studio/app/security/api-keys \u2192 Project Settings \u2192 API Keys
|
|
172
183
|
|
|
173
|
-
|
|
174
|
-
NEXT_PUBLIC_VAIF_API_KEY=your-
|
|
184
|
+
NEXT_PUBLIC_VAIF_API_URL=https://api.vaif.studio
|
|
185
|
+
NEXT_PUBLIC_VAIF_API_KEY=your-api-key
|
|
175
186
|
VAIF_SECRET_KEY=your-secret-key
|
|
176
187
|
|
|
188
|
+
# Database connection (for vaif generate, vaif db push)
|
|
189
|
+
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
190
|
+
|
|
177
191
|
# CLI uses these (non-prefixed) for vaif db push, vaif secrets, etc.
|
|
178
192
|
VAIF_PROJECT_ID=your-project-id
|
|
179
193
|
`},{path:".gitignore",content:`node_modules
|
|
@@ -289,8 +303,8 @@ export async function middleware(request: NextRequest) {
|
|
|
289
303
|
if (!isProtected) return NextResponse.next();
|
|
290
304
|
|
|
291
305
|
const vaif = createVaifClient({
|
|
292
|
-
|
|
293
|
-
|
|
306
|
+
baseUrl: process.env.NEXT_PUBLIC_VAIF_API_URL || 'https://api.vaif.studio',
|
|
307
|
+
apiKey: process.env.VAIF_SECRET_KEY!,
|
|
294
308
|
});
|
|
295
309
|
|
|
296
310
|
return authMiddleware(vaif, request, {
|
|
@@ -651,13 +665,13 @@ function Home() {
|
|
|
651
665
|
`},{path:"src/lib/vaif.ts",content:`import { createVaifClient } from "@vaiftech/client";
|
|
652
666
|
|
|
653
667
|
export const vaif = createVaifClient({
|
|
654
|
-
|
|
668
|
+
baseUrl: import.meta.env.VITE_VAIF_API_URL || 'https://api.vaif.studio',
|
|
655
669
|
apiKey: import.meta.env.VITE_VAIF_API_KEY,
|
|
656
670
|
});
|
|
657
671
|
`},{path:"src/vite-env.d.ts",content:`/// <reference types="vite/client" />
|
|
658
672
|
|
|
659
673
|
interface ImportMetaEnv {
|
|
660
|
-
readonly
|
|
674
|
+
readonly VITE_VAIF_API_URL: string;
|
|
661
675
|
readonly VITE_VAIF_API_KEY: string;
|
|
662
676
|
}
|
|
663
677
|
|
|
@@ -665,13 +679,13 @@ interface ImportMeta {
|
|
|
665
679
|
readonly env: ImportMetaEnv;
|
|
666
680
|
}
|
|
667
681
|
`},{path:".env.example",content:`# VAIF Configuration
|
|
668
|
-
# Get these values from https://vaif.studio/app/security/api-keys
|
|
682
|
+
# Get these values from https://vaif.studio/app/security/api-keys
|
|
669
683
|
|
|
670
|
-
|
|
671
|
-
VITE_VAIF_API_KEY=your-
|
|
684
|
+
VITE_VAIF_API_URL=https://api.vaif.studio
|
|
685
|
+
VITE_VAIF_API_KEY=your-api-key
|
|
672
686
|
|
|
673
|
-
#
|
|
674
|
-
|
|
687
|
+
# Database connection (for vaif generate, vaif db push)
|
|
688
|
+
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
675
689
|
`},{path:".gitignore",content:`node_modules
|
|
676
690
|
dist
|
|
677
691
|
.env
|
|
@@ -2610,7 +2624,7 @@ func HelloHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
2610
2624
|
`}]},postInstructions:["go mod tidy","# Copy .env.example to .env and add your VAIF credentials","go run main.go"]},"todo-app":{name:"Todo App",description:"Simple React todo app \u2013 great for learning VAIF basics",tag:"React Starter",defaultFeatures:["database"],files:[{path:"src/lib/vaif.ts",content:`import { createVaifClient } from "@vaiftech/client";
|
|
2611
2625
|
|
|
2612
2626
|
export const vaif = createVaifClient({
|
|
2613
|
-
|
|
2627
|
+
baseUrl: import.meta.env.VITE_VAIF_API_URL || 'https://api.vaif.studio',
|
|
2614
2628
|
apiKey: import.meta.env.VITE_VAIF_API_KEY,
|
|
2615
2629
|
});
|
|
2616
2630
|
|
|
@@ -2662,13 +2676,13 @@ export async function deleteTodo(id: string): Promise<void> {
|
|
|
2662
2676
|
if (error) throw error;
|
|
2663
2677
|
}
|
|
2664
2678
|
`},{path:".env.example",content:`# VAIF Configuration
|
|
2665
|
-
# Get these values from https://vaif.studio/app/security/api-keys
|
|
2679
|
+
# Get these values from https://vaif.studio/app/security/api-keys
|
|
2666
2680
|
|
|
2667
|
-
|
|
2668
|
-
VITE_VAIF_API_KEY=your-
|
|
2681
|
+
VITE_VAIF_API_URL=https://api.vaif.studio
|
|
2682
|
+
VITE_VAIF_API_KEY=your-api-key
|
|
2669
2683
|
|
|
2670
|
-
#
|
|
2671
|
-
|
|
2684
|
+
# Database connection (for vaif generate, vaif db push)
|
|
2685
|
+
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
2672
2686
|
`},{path:"README.md",content:`# Todo App \u2014 VAIF Starter
|
|
2673
2687
|
|
|
2674
2688
|
A simple React todo application for learning [VAIF Studio](https://vaif.studio) basics, including typed database queries and CRUD operations.
|
|
@@ -2804,15 +2818,8 @@ export const posts = pgTable("posts", {
|
|
|
2804
2818
|
`}]},dependencies:["@vaiftech/client","@vaiftech/react"],postInstructions:["Copy .env.example to .env and fill in your project credentials","Create a 'todos' table in your VAIF dashboard with columns: id (uuid), title (text), done (boolean), created_at (timestamptz)","Import helpers from './lib/vaif' in your components","Run: npx vaif generate to generate TypeScript types"]},"realtime-chat":{name:"Realtime Chat",description:"React chat app with VAIF realtime subscriptions for live messaging",tag:"React + Realtime",defaultFeatures:["database","realtime","auth"],files:[{path:"src/lib/vaif.ts",content:`import { createVaifClient } from "@vaiftech/client";
|
|
2805
2819
|
|
|
2806
2820
|
export const vaif = createVaifClient({
|
|
2807
|
-
|
|
2821
|
+
baseUrl: import.meta.env.VITE_VAIF_API_URL || 'https://api.vaif.studio',
|
|
2808
2822
|
apiKey: import.meta.env.VITE_VAIF_API_KEY,
|
|
2809
|
-
realtime: {
|
|
2810
|
-
enabled: true,
|
|
2811
|
-
// Automatically reconnect on connection loss
|
|
2812
|
-
reconnect: true,
|
|
2813
|
-
reconnectInterval: 1000,
|
|
2814
|
-
maxReconnectAttempts: 10,
|
|
2815
|
-
},
|
|
2816
2823
|
});
|
|
2817
2824
|
|
|
2818
2825
|
export interface Message {
|
|
@@ -2950,13 +2957,13 @@ export function useRealtimeMessages({
|
|
|
2950
2957
|
return { messages, isLoading, error, refresh };
|
|
2951
2958
|
}
|
|
2952
2959
|
`},{path:".env.example",content:`# VAIF Configuration
|
|
2953
|
-
# Get these values from https://vaif.studio/app/security/api-keys
|
|
2960
|
+
# Get these values from https://vaif.studio/app/security/api-keys
|
|
2954
2961
|
|
|
2955
|
-
|
|
2956
|
-
VITE_VAIF_API_KEY=your-
|
|
2962
|
+
VITE_VAIF_API_URL=https://api.vaif.studio
|
|
2963
|
+
VITE_VAIF_API_KEY=your-api-key
|
|
2957
2964
|
|
|
2958
|
-
#
|
|
2959
|
-
|
|
2965
|
+
# Database connection (for vaif generate, vaif db push)
|
|
2966
|
+
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
2960
2967
|
`},{path:"README.md",content:`# Realtime Chat \u2014 VAIF Starter
|
|
2961
2968
|
|
|
2962
2969
|
A React chat application with live messaging powered by [VAIF Studio](https://vaif.studio) realtime subscriptions.
|
|
@@ -3107,15 +3114,15 @@ export const posts = pgTable("posts", {
|
|
|
3107
3114
|
|
|
3108
3115
|
// Browser client \u2013 use in Client Components
|
|
3109
3116
|
export const vaif = createVaifClient({
|
|
3110
|
-
|
|
3117
|
+
baseUrl: process.env.NEXT_PUBLIC_VAIF_API_URL || 'https://api.vaif.studio',
|
|
3111
3118
|
apiKey: process.env.NEXT_PUBLIC_VAIF_API_KEY!,
|
|
3112
3119
|
});
|
|
3113
3120
|
|
|
3114
3121
|
// Server client \u2013 use in Server Components, Route Handlers, Server Actions
|
|
3115
3122
|
export function createVaifServer() {
|
|
3116
3123
|
return createVaifClient({
|
|
3117
|
-
|
|
3118
|
-
|
|
3124
|
+
baseUrl: process.env.NEXT_PUBLIC_VAIF_API_URL || 'https://api.vaif.studio',
|
|
3125
|
+
apiKey: process.env.VAIF_SECRET_KEY!,
|
|
3119
3126
|
});
|
|
3120
3127
|
}
|
|
3121
3128
|
`},{path:"lib/auth.ts",content:`import { createVaifServer } from "./vaif";
|
|
@@ -3268,10 +3275,13 @@ export async function requireTeamRole(
|
|
|
3268
3275
|
`},{path:".env.example",content:`# VAIF Configuration
|
|
3269
3276
|
# Get these values from https://vaif.studio/app/security/api-keys \u2192 Project Settings \u2192 API Keys
|
|
3270
3277
|
|
|
3271
|
-
|
|
3272
|
-
NEXT_PUBLIC_VAIF_API_KEY=your-
|
|
3278
|
+
NEXT_PUBLIC_VAIF_API_URL=https://api.vaif.studio
|
|
3279
|
+
NEXT_PUBLIC_VAIF_API_KEY=your-api-key
|
|
3273
3280
|
VAIF_SECRET_KEY=your-secret-key
|
|
3274
3281
|
|
|
3282
|
+
# Database connection (for vaif generate, vaif db push)
|
|
3283
|
+
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
3284
|
+
|
|
3275
3285
|
# CLI uses these (non-prefixed) for vaif db push, vaif secrets, etc.
|
|
3276
3286
|
VAIF_PROJECT_ID=your-project-id
|
|
3277
3287
|
`},{path:"README.md",content:`# SaaS Starter \u2014 VAIF Studio
|
|
@@ -3420,15 +3430,15 @@ export const posts = pgTable("posts", {
|
|
|
3420
3430
|
|
|
3421
3431
|
// Browser client
|
|
3422
3432
|
export const vaif = createVaifClient({
|
|
3423
|
-
|
|
3433
|
+
baseUrl: process.env.NEXT_PUBLIC_VAIF_API_URL || 'https://api.vaif.studio',
|
|
3424
3434
|
apiKey: process.env.NEXT_PUBLIC_VAIF_API_KEY!,
|
|
3425
3435
|
});
|
|
3426
3436
|
|
|
3427
3437
|
// Server client
|
|
3428
3438
|
export function createVaifServer() {
|
|
3429
3439
|
return createVaifClient({
|
|
3430
|
-
|
|
3431
|
-
|
|
3440
|
+
baseUrl: process.env.NEXT_PUBLIC_VAIF_API_URL || 'https://api.vaif.studio',
|
|
3441
|
+
apiKey: process.env.VAIF_SECRET_KEY!,
|
|
3432
3442
|
});
|
|
3433
3443
|
}
|
|
3434
3444
|
`},{path:"lib/storage.ts",content:`import { createVaifServer } from "./vaif";
|
|
@@ -3543,10 +3553,13 @@ function getContentType(fileName: string): string {
|
|
|
3543
3553
|
`},{path:".env.example",content:`# VAIF Configuration
|
|
3544
3554
|
# Get these values from https://vaif.studio/app/security/api-keys \u2192 Project Settings \u2192 API Keys
|
|
3545
3555
|
|
|
3546
|
-
|
|
3547
|
-
NEXT_PUBLIC_VAIF_API_KEY=your-
|
|
3556
|
+
NEXT_PUBLIC_VAIF_API_URL=https://api.vaif.studio
|
|
3557
|
+
NEXT_PUBLIC_VAIF_API_KEY=your-api-key
|
|
3548
3558
|
VAIF_SECRET_KEY=your-secret-key
|
|
3549
3559
|
|
|
3560
|
+
# Database connection (for vaif generate, vaif db push)
|
|
3561
|
+
# DATABASE_URL=postgresql://user:password@host:5432/dbname
|
|
3562
|
+
|
|
3550
3563
|
# CLI uses these (non-prefixed) for vaif db push, vaif secrets, etc.
|
|
3551
3564
|
VAIF_PROJECT_ID=your-project-id
|
|
3552
3565
|
`},{path:"README.md",content:`# E-commerce API \u2014 VAIF Studio
|
|
@@ -3689,56 +3702,47 @@ export const posts = pgTable("posts", {
|
|
|
3689
3702
|
|
|
3690
3703
|
return Response.json({ message: \`Hello, \${name}!\` });
|
|
3691
3704
|
}
|
|
3692
|
-
`}]},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
|
|
3693
|
-
? Which VAIF features do you want to include?`)),B.forEach((a,
|
|
3705
|
+
`}]},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 Pe(){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[o,n]of Object.entries(Fe))console.log(` ${f__default.default.cyan(o.padEnd(t))}${f__default.default.yellow(n.tag.padEnd(e))}${f__default.default.white(n.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 Ft(t){if(!process.stdin.isTTY||!process.stdout.isTTY)return t;let e=new Set(t.map(n=>B.findIndex(r=>r.name===n)).filter(n=>n>=0)),o=0;return new Promise(n=>{let r=Ie__default.default.createInterface({input:process.stdin,output:process.stdout});Ie__default.default.emitKeypressEvents(process.stdin,r),process.stdin.setRawMode&&process.stdin.setRawMode(true);function s(){let a=B.length+2;process.stdout.write(`\x1B[${a}A`),i();}function i(){console.log(f__default.default.bold(`
|
|
3706
|
+
? Which VAIF features do you want to include?`)),B.forEach((a,c)=>{let l=e.has(c)?f__default.default.green("[x]"):"[ ]",p=c===o?f__default.default.cyan("> "):" ";console.log(`${p}${l} ${a.label} ${f__default.default.gray(`(${a.description})`)}`);}),console.log(f__default.default.gray(" (up/down to move, space to toggle, enter to confirm)"));}i(),process.stdin.on("keypress",(a,c)=>{if(c.name==="up"&&o>0)o--,s();else if(c.name==="down"&&o<B.length-1)o++,s();else if(c.name==="space")e.has(o)?e.delete(o):e.add(o),s();else if(c.name==="return"){process.stdin.setRawMode&&process.stdin.setRawMode(false),r.close();let l=[...e].sort().map(p=>B[p].name);n(l.length>0?l:t);}else c.name==="c"&&c.ctrl&&(process.stdin.setRawMode&&process.stdin.setRawMode(false),r.close(),process.exit(0));});})}async function de(t,e={}){let o=Fe[t];o||(console.log(f__default.default.red(`
|
|
3694
3707
|
Unknown template: ${t}`)),console.log(f__default.default.yellow(`Run 'vaif templates' to see available templates.
|
|
3695
|
-
`)),process.exit(1));let n;e.features&&e.features.length>0?n=e.features.filter(
|
|
3696
|
-
No features specified.`)),console.log(f__default.default.yellow("Usage: vaif init --template <name> --add-features <features>")),console.log(f__default.default.gray("Available features: auth, database, realtime, storage, functions")),process.exit(1)):o.featureFiles&&Object.keys(o.featureFiles).length>0?n=await
|
|
3697
|
-
`,"utf-8"),console.log(f__default.default.green(` merge ${
|
|
3698
|
-
`,"utf-8");}catch{}(o.dependencies?.length||o.devDependencies?.length)&&(console.log(""),console.log(f__default.default.bold("Install dependencies:")),o.dependencies?.length&&console.log(f__default.default.cyan(` npm install ${o.dependencies.join(" ")}`)),o.devDependencies?.length&&console.log(f__default.default.cyan(` npm install -D ${o.devDependencies.join(" ")}`))),console.log(""),console.log(f__default.default.bold.green("Project scaffolded successfully!")),console.log(""),console.log(f__default.default.bold(" Next steps:")),o.postInstructions.forEach(
|
|
3699
|
-
--add-features requires --template to know which template to use.`)),console.log(f__default.default.gray("Example: vaif init --template react-spa --add-features functions,storage")),process.exit(1));let n=t.addFeatures.split(",").map(r=>r.trim());await
|
|
3700
|
-
Use --force to overwrite existing configuration.`)),process.exit(1));try{if(
|
|
3708
|
+
`)),process.exit(1));let n;e.features&&e.features.length>0?n=e.features.filter(l=>B.some(p=>p.name===l)):e.addOnly?(console.log(f__default.default.red(`
|
|
3709
|
+
No features specified.`)),console.log(f__default.default.yellow("Usage: vaif init --template <name> --add-features <features>")),console.log(f__default.default.gray("Available features: auth, database, realtime, storage, functions")),process.exit(1)):o.featureFiles&&Object.keys(o.featureFiles).length>0?n=await Ft(o.defaultFeatures??["database","auth"]):n=o.defaultFeatures??[],e.addOnly?(console.log(""),console.log(f__default.default.bold(`Adding features to ${f__default.default.cyan(o.name)} project...`)),console.log(f__default.default.gray(` Features: ${n.join(", ")}`)),console.log("")):(console.log(""),console.log(f__default.default.bold(`Scaffolding ${f__default.default.cyan(o.name)} template...`)),n.length>0&&console.log(f__default.default.gray(` Features: ${n.join(", ")}`)),console.log(""));let r=e.addOnly?[]:[...o.files];if(o.featureFiles)for(let l of n){let p=o.featureFiles[l];p&&r.push(...p);}let s=0,i=0;for(let l of r){let p=w__default.default.resolve(l.path),u=w__default.default.dirname(p);if(D__default.default.existsSync(u)||D__default.default.mkdirSync(u,{recursive:true}),l.path==="package.json"&&D__default.default.existsSync(p)&&!e.force)try{let d=JSON.parse(D__default.default.readFileSync(p,"utf-8")),m=JSON.parse(l.content),y=L=>{if(!L)return {};let M={};for(let[K,G]of Object.entries(L))!G.startsWith("workspace:")&&!G.startsWith("link:")&&!G.startsWith("file:")&&(M[K]=G);return M};d.dependencies={...y(d.dependencies),...m.dependencies||{}},d.devDependencies={...y(d.devDependencies),...m.devDependencies||{}},m.scripts&&(d.scripts={...d.scripts||{},...m.scripts}),D__default.default.writeFileSync(p,JSON.stringify(d,null,2)+`
|
|
3710
|
+
`,"utf-8"),console.log(f__default.default.green(` merge ${l.path} (added dependencies)`)),s++;continue}catch{}if(D__default.default.existsSync(p)&&!e.force){console.log(f__default.default.yellow(` skip ${l.path} (already exists)`)),i++;continue}D__default.default.writeFileSync(p,l.content,"utf-8"),console.log(f__default.default.green(` create ${l.path}`)),s++;}console.log(""),s>0&&console.log(f__default.default.green(`Created ${s} file${s!==1?"s":""}.`)),i>0&&console.log(f__default.default.yellow(`Skipped ${i} file${i!==1?"s":""} (use --force to overwrite).`));let a={auth:{"@vaiftech/auth":"^1.0.0"},database:{},realtime:{},storage:{},functions:{}},c=w__default.default.resolve("package.json");if(D__default.default.existsSync(c)&&n.length>0)try{let l=JSON.parse(D__default.default.readFileSync(c,"utf-8")),p=!1;for(let u of n){let d=a[u];if(d)for(let[m,y]of Object.entries(d))l.dependencies?.[m]||(l.dependencies=l.dependencies||{},l.dependencies[m]=y,p=!0);}p&&D__default.default.writeFileSync(c,JSON.stringify(l,null,2)+`
|
|
3711
|
+
`,"utf-8");}catch{}(o.dependencies?.length||o.devDependencies?.length)&&(console.log(""),console.log(f__default.default.bold("Install dependencies:")),o.dependencies?.length&&console.log(f__default.default.cyan(` npm install ${o.dependencies.join(" ")}`)),o.devDependencies?.length&&console.log(f__default.default.cyan(` npm install -D ${o.devDependencies.join(" ")}`))),console.log(""),console.log(f__default.default.bold.green("Project scaffolded successfully!")),console.log(""),console.log(f__default.default.bold(" Next steps:")),o.postInstructions.forEach(l=>{console.log(f__default.default.gray(` ${l}`));}),console.log(""),console.log(f__default.default.gray(" Get your project credentials at https://vaif.studio/app/security/api-keys")),console.log("");}var jt={$schema:"https://vaif.studio/schemas/config.json",projectId:"",database:{url:"${DATABASE_URL}",schema:"public"},types:{output:"./src/types/database.ts"},api:{baseUrl:"https://api.vaif.studio"}};async function je(t){if(t.addFeatures){t.template||(console.log(f__default.default.red(`
|
|
3712
|
+
--add-features requires --template to know which template to use.`)),console.log(f__default.default.gray("Example: vaif init --template react-spa --add-features functions,storage")),process.exit(1));let n=t.addFeatures.split(",").map(r=>r.trim());await de(t.template,{force:t.force,features:n,addOnly:true});return}let e=H__default.default("Initializing VAIF configuration...").start(),o=w__default.default.resolve("vaif.config.json");D__default.default.existsSync(o)&&!t.force&&(e.fail("vaif.config.json already exists"),console.log(f__default.default.yellow(`
|
|
3713
|
+
Use --force to overwrite existing configuration.`)),process.exit(1));try{if(D__default.default.writeFileSync(o,JSON.stringify(jt,null,2),"utf-8"),e.succeed("Created vaif.config.json"),t.template){let n=t.features?t.features.split(",").map(r=>r.trim()):void 0;await de(t.template,{force:t.force,features:n});}else {let n=w__default.default.resolve(".env.example");if(D__default.default.existsSync(n)||(D__default.default.writeFileSync(n,`# VAIF Configuration
|
|
3701
3714
|
DATABASE_URL=postgresql://user:password@localhost:5432/database
|
|
3702
3715
|
VAIF_API_KEY=your-api-key
|
|
3703
|
-
`,"utf-8"),console.log(f__default.default.gray("Created .env.example"))),t.typescript){let r=
|
|
3704
|
-
Error: ${n.message}`)),process.exit(1);}}var
|
|
3705
|
-
Could not connect to VAIF API. Please try again later.`)),process.exit(1));let l=await a.json();o=l.code,n=l.url;}catch{e.fail("Failed to connect to VAIF API"),console.log(f__default.default.red(`
|
|
3706
|
-
Could not connect to VAIF API.`)),console.log(f__default.default.gray("Check your internet connection or try: vaif login --email")),process.exit(1);}e.stop(),console.log(f__default.default.cyan(" Opening browser for authentication...")),console.log(""),console.log(f__default.default.gray(" If the browser doesn't open, visit this URL:")),console.log(f__default.default.white(` ${n}`)),console.log(""),Et(n),e.start("Waiting for browser authentication...");let r=12e4,s=2e3,i=Date.now();for(;Date.now()-i<r;){await xt(s);try{let a=await fetch(`${G}/auth/cli/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:o})});if(!a.ok){let c=await a.json();(c.error==="ExpiredCode"||c.error==="InvalidCode")&&(e.fail("Authentication expired"),console.log(f__default.default.red(`
|
|
3707
|
-
The authentication session expired. Please try again.`)),process.exit(1));continue}let l=await a.json();if(l.ok&&l.accessToken){let c={token:l.accessToken,email:l.user?.email,projectId:t,expiresAt:new Date(Date.now()+l.expiresIn*1e3).toISOString()};Te(c),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: ${$}`)),console.log("");return}}catch{}}e.fail("Authentication timed out"),console.log(f__default.default.red(`
|
|
3708
|
-
Timed out waiting for browser authentication.`)),console.log(f__default.default.gray("Try again or use: vaif login --email")),process.exit(1);}async function Ft(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 wt(f__default.default.cyan(" Email: "));(!e||e.trim()==="")&&(console.log(f__default.default.red(`
|
|
3709
|
-
No email provided. Login cancelled.`)),process.exit(1));let o=await St(f__default.default.cyan(" Password: "));(!o||o.trim()==="")&&(console.log(f__default.default.red(`
|
|
3710
|
-
No password provided. Login cancelled.`)),process.exit(1));let n=H__default.default("Authenticating...").start();try{let r=await fetch(`${G}/auth/cli/login`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:e.trim(),password:o})}),s=await r.json();(!r.ok||!s.ok)&&(n.fail("Login failed"),console.log(f__default.default.red(`
|
|
3711
|
-
${s.message||"Invalid email or password."}`)),process.exit(1));let i={token:s.accessToken,email:s.user?.email,projectId:t,expiresAt:new Date(Date.now()+s.expiresIn*1e3).toISOString()};Te(i),n.succeed("Logged in successfully"),console.log(""),s.user?.email&&console.log(f__default.default.green(` Authenticated as: ${s.user.email}`)),console.log(f__default.default.gray(` Config saved to: ${$}`)),console.log("");}catch{n.fail("Failed to connect to VAIF API"),console.log(f__default.default.red(`
|
|
3712
|
-
Could not connect to VAIF API. Please try again later.`)),process.exit(1);}}async function Fe(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 Ft(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(){L__default.default.existsSync($)?(L__default.default.unlinkSync($),console.log(f__default.default.green("Logged out successfully"))):console.log(f__default.default.yellow("Not currently logged in"));}async function je(){let t=S();(!t||!t.token)&&(console.log(f__default.default.yellow("Not logged in")),console.log(f__default.default.gray("Run `vaif login` to authenticate")),process.exit(1));let e=H__default.default("Checking authentication...").start(),{valid:o,email:n}=await _t(t.token);o||(e.fail("Session expired"),console.log(f__default.default.yellow(`
|
|
3713
|
-
Your session has expired. Please login again.`)),process.exit(1)),e.succeed("Authenticated"),console.log(""),console.log(f__default.default.green(` Email: ${n||t.email||"Unknown"}`)),t.projectId&&console.log(f__default.default.green(` Project: ${t.projectId}`)),console.log("");}var Rt=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Nt(t,e,o="public"){let n=await fetch(`${Rt}/v1/projects/${e}/schema?schema=${o}`,{headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!n.ok){let r=await n.text();throw new Error(`Failed to fetch schema: ${r}`)}return n.json()}async function Ce(t){let e=H__default.default(),o=S();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;e.start("Loading configuration...");try{r=await I(n);}catch(i){e.fail("Failed to load config"),console.log(f__default.default.red(`
|
|
3716
|
+
`,"utf-8"),console.log(f__default.default.gray("Created .env.example"))),t.typescript){let r=w__default.default.resolve("src/types");D__default.default.existsSync(r)||(D__default.default.mkdirSync(r,{recursive:!0}),console.log(f__default.default.gray("Created src/types directory")));}console.log(""),console.log(f__default.default.green("VAIF initialized successfully!")),console.log(""),console.log(f__default.default.gray("Next steps:")),console.log(f__default.default.gray(" 1. Update vaif.config.json with your project ID")),console.log(f__default.default.gray(" 2. Set DATABASE_URL in your environment")),console.log(f__default.default.gray(" 3. Run: npx vaif generate")),console.log("");}}catch(n){e.fail("Failed to initialize"),n instanceof Error&&console.error(f__default.default.red(`
|
|
3717
|
+
Error: ${n.message}`)),process.exit(1);}}var Lt=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Vt(t,e,o="public"){let n=await fetch(`${Lt}/v1/projects/${e}/schema?schema=${o}`,{headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!n.ok){let r=await n.text();throw new Error(`Failed to fetch schema: ${r}`)}return n.json()}async function Ce(t){let e=H__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;e.start("Loading configuration...");try{r=await A(n);}catch(i){e.fail("Failed to load config"),console.log(f__default.default.red(`
|
|
3714
3718
|
Error: ${i}`)),process.exit(1);}r||(e.fail("No configuration found"),console.log(f__default.default.yellow("\nRun `vaif init` to create a configuration file.")),process.exit(1));let s=t.projectId||r.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(e.fail("No project ID specified"),console.log(f__default.default.yellow(`
|
|
3715
|
-
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1)),e.text="Fetching remote schema...";try{let i=t.schema||r.database?.schema||"public",a=await
|
|
3716
|
-
Error: ${i.message}`)),process.exit(1);}}var Ne=process.env.VAIF_API_URL||"https://api.vaif.studio";function
|
|
3717
|
-
Error: ${
|
|
3718
|
-
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1));let i=t.schema||
|
|
3719
|
-
Expected schema file at: ${i}`)),console.log(f__default.default.gray("Run `vaif pull` first to fetch the current schema.")),process.exit(1));let a;try{let
|
|
3720
|
-
Error: ${
|
|
3721
|
-
Cancelled. No changes applied.`));return}}e.start("Applying schema changes...");let
|
|
3722
|
-
Error: ${
|
|
3719
|
+
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1)),e.text="Fetching remote schema...";try{let i=t.schema||r.database?.schema||"public",a=await Vt(o.token,s,i);e.succeed("Schema fetched successfully");let c=t.output||w__default.default.resolve("vaif.schema.json"),l={$schema:"https://vaif.studio/schemas/schema.json",projectId:s,schema:i,pulledAt:new Date().toISOString(),...a};D__default.default.writeFileSync(c,JSON.stringify(l,null,2),"utf-8"),console.log(""),console.log(f__default.default.green(`Schema saved to: ${c}`)),console.log(""),console.log(f__default.default.gray("Schema summary:")),console.log(f__default.default.gray(` Tables: ${(a.tables||[]).length}`)),console.log(f__default.default.gray(` Enums: ${(a.enums||[]).length}`)),console.log(f__default.default.gray(` Functions: ${(a.functions||[]).length}`)),console.log(""),console.log(f__default.default.gray("Next steps:")),console.log(f__default.default.gray(" - Run `vaif generate` to generate TypeScript types")),console.log(f__default.default.gray(" - Edit the schema and run `vaif push` to deploy changes")),console.log("");}catch(i){e.fail("Failed to fetch schema"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3720
|
+
Error: ${i.message}`)),process.exit(1);}}var Ne=process.env.VAIF_API_URL||"https://api.vaif.studio";function $t(t){let e=Ie__default.default.createInterface({input:process.stdin,output:process.stdout});return new Promise(o=>{e.question(t,n=>{e.close(),o(n);});})}async function Ot(t,e,o){let n=await fetch(`${Ne}/v1/projects/${e}/schema/preview`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({schema:o})});if(!n.ok){let r=await n.text();throw new Error(`Failed to preview changes: ${r}`)}return n.json()}async function Mt(t,e,o){let n=await fetch(`${Ne}/v1/projects/${e}/schema/apply`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({schema:o})});if(!n.ok){let r=await n.text();throw new Error(`Failed to apply changes: ${r}`)}return n.json()}function Kt(t){if(console.log(""),console.log(f__default.default.bold("Schema Changes:")),console.log(""),t.added.length===0&&t.modified.length===0&&t.removed.length===0){console.log(f__default.default.gray(" No changes detected. Schema is up to date."));return}if(t.added.length>0){console.log(f__default.default.green.bold(" + Added:"));for(let e of t.added)console.log(f__default.default.green(` + ${e.type}: ${e.name}`));console.log("");}if(t.modified.length>0){console.log(f__default.default.yellow.bold(" ~ Modified:"));for(let e of t.modified){console.log(f__default.default.yellow(` ~ ${e.type}: ${e.name}`));for(let o of e.changes)console.log(f__default.default.gray(` ${o}`));}console.log("");}if(t.removed.length>0){console.log(f__default.default.red.bold(" - Removed:"));for(let e of t.removed)console.log(f__default.default.red(` - ${e.type}: ${e.name}`));console.log("");}}async function Le(t){let e=H__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;e.start("Loading configuration...");try{r=await A(n);}catch(c){e.fail("Failed to load config"),console.log(f__default.default.red(`
|
|
3721
|
+
Error: ${c}`)),process.exit(1);}r||(e.fail("No configuration found"),console.log(f__default.default.yellow("\nRun `vaif init` to create a configuration file.")),process.exit(1));let s=t.projectId||r.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(e.fail("No project ID specified"),console.log(f__default.default.yellow(`
|
|
3722
|
+
Set projectId in vaif.config.json or use --project-id flag.`)),process.exit(1));let i=t.schema||w__default.default.resolve("vaif.schema.json");D__default.default.existsSync(i)||(e.fail("No local schema found"),console.log(f__default.default.yellow(`
|
|
3723
|
+
Expected schema file at: ${i}`)),console.log(f__default.default.gray("Run `vaif pull` first to fetch the current schema.")),process.exit(1));let a;try{let c=D__default.default.readFileSync(i,"utf-8");a=JSON.parse(c);}catch(c){e.fail("Failed to parse schema file"),c instanceof Error&&console.log(f__default.default.red(`
|
|
3724
|
+
Error: ${c.message}`)),process.exit(1);}e.text="Calculating schema changes...";try{let{diff:c,sql:l}=await Ot(o.token,s,a);if(e.stop(),Kt(c),c.added.length===0&&c.modified.length===0&&c.removed.length===0){console.log("");return}if(l.length>0){console.log(f__default.default.bold("SQL Migrations:")),console.log("");for(let u of l)console.log(f__default.default.gray(` ${u}`));console.log("");}if(t.dryRun){console.log(f__default.default.yellow("Dry run mode - no changes applied.")),console.log(f__default.default.gray("Remove --dry-run to apply these changes."));return}if(!t.force){c.removed.length>0&&(console.log(f__default.default.red.bold("\u26A0\uFE0F Warning: This will remove tables/columns from your database.")),console.log(f__default.default.red(" This action cannot be undone!")),console.log(""));let d=await $t(f__default.default.cyan("Apply these changes? [y/N] "));if(d.toLowerCase()!=="y"&&d.toLowerCase()!=="yes"){console.log(f__default.default.yellow(`
|
|
3725
|
+
Cancelled. No changes applied.`));return}}e.start("Applying schema changes...");let p=await Mt(o.token,s,a);if(p.success){if(e.succeed("Schema changes applied successfully"),console.log(""),p.migrations.length>0){console.log(f__default.default.gray("Migrations applied:"));for(let u of p.migrations)console.log(f__default.default.gray(` - ${u}`));console.log("");}console.log(f__default.default.green("Your database schema is now up to date.")),console.log(f__default.default.gray("Run `vaif generate` to update your TypeScript types.")),console.log("");}else e.fail("Failed to apply some changes");}catch(c){e.fail("Failed to push schema changes"),c instanceof Error&&console.log(f__default.default.red(`
|
|
3726
|
+
Error: ${c.message}`)),process.exit(1);}}var W=process.env.VAIF_API_URL||"https://api.vaif.studio";async function zt(t,e,o,n){let r=new URL(`${W}/functions/project/${e}`);n&&r.searchParams.set("envId",n);let s=await fetch(r.toString(),{headers:{Authorization:`Bearer ${t}`}});if(!s.ok)return null;let i=await s.json(),a=i.functions||i;return Array.isArray(a)&&a.find(c=>c.name===o)||null}async function Bt(t,e,o){let n=await fetch(`${W}/functions/`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({projectId:e,name:o.name,runtime:o.runtime,entrypoint:o.entrypoint,envId:o.envId})});if(!n.ok){let r=await n.text();throw new Error(`Failed to create function: ${r}`)}return n.json()}async function qt(t,e,o){let n=await fetch(`${W}/functions/${e}/source`,{method:"PUT",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({sourceCode:o})});if(!n.ok){let r=await n.text();throw new Error(`Failed to deploy source: ${r}`)}}async function Yt(t,e,o){let n=new URL(`${W}/functions/project/${e}`);o&&n.searchParams.set("envId",o);let r=await fetch(n.toString(),{headers:{Authorization:`Bearer ${t}`}});if(!r.ok){let i=await r.text();throw new Error(`Failed to list functions: ${i}`)}let s=await r.json();return s.functions||s}function Ve(t){switch(w__default.default.extname(t).toLowerCase()){case ".ts":return "typescript";case ".js":case ".mjs":return "nodejs";case ".py":return "python";case ".go":return "go";case ".rs":return "rust";default:return "nodejs"}}function De(t){let e=[],o=[".ts",".js",".mjs",".py",".go",".rs"],n=["drizzle.config.ts","tsconfig.json","package.json"];if(!D__default.default.existsSync(t))return e;let r=D__default.default.readdirSync(t,{withFileTypes:true});for(let s of r){let i=w__default.default.join(t,s.name);if(s.isDirectory()){if(s.name!=="node_modules"&&!s.name.startsWith(".")){let a=D__default.default.readdirSync(i,{withFileTypes:true});for(let c of a)if(c.isFile()){let l=w__default.default.extname(c.name).toLowerCase();if(o.includes(l)){e.push(w__default.default.join(i,c.name));break}}}}else if(s.isFile()){let a=w__default.default.extname(s.name).toLowerCase();o.includes(a)&&!n.includes(s.name)&&e.push(i);}}return e}async function ke(t){let e=H__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),console.log(""),console.log(f__default.default.bold("VAIF Functions Deploy")),console.log(""),e.start("Scanning for function files...");let i=w__default.default.resolve("functions"),a=w__default.default.resolve("src/functions"),c=[];if(t.entrypoint){let d=w__default.default.resolve(t.entrypoint);D__default.default.existsSync(d)||(e.fail(`File not found: ${t.entrypoint}`),process.exit(1)),c=[d];}else c=[...De(i),...De(a)];c.length===0&&(e.fail("No function files found"),console.log(f__default.default.yellow(`
|
|
3723
3727
|
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(`
|
|
3724
|
-
Or specify an entrypoint with --entrypoint`)),process.exit(1)),e.succeed(`Found ${
|
|
3725
|
-
No functions matching "${t.name}" found`)),process.exit(1))),console.log(""),console.log(f__default.default.gray("Functions to deploy:"));for(let
|
|
3726
|
-
No functions found`)),console.log(f__default.default.gray("Deploy your first function with: vaif functions deploy"));return}console.log(""),console.log(f__default.default.bold(`Functions (${i.length}):`)),console.log(""),console.log(f__default.default.gray(" "+"NAME".padEnd(25)+"RUNTIME".padEnd(15)+"STATUS".padEnd(12)+"INVOCATIONS".padEnd(14)+"LAST DEPLOYED")),console.log(f__default.default.gray(" "+"-".repeat(80)));for(let a of i){let
|
|
3727
|
-
Error: ${i.message}`)),process.exit(1);}}var X=process.env.VAIF_API_URL||"https://api.vaif.studio";async function
|
|
3728
|
+
Or specify an entrypoint with --entrypoint`)),process.exit(1)),e.succeed(`Found ${c.length} function(s)`),t.name&&(c=c.filter(d=>w__default.default.basename(d,w__default.default.extname(d)).includes(t.name)),c.length===0&&(console.log(f__default.default.yellow(`
|
|
3729
|
+
No functions matching "${t.name}" found`)),process.exit(1))),console.log(""),console.log(f__default.default.gray("Functions to deploy:"));for(let d of c){let m=w__default.default.basename(w__default.default.dirname(d)),y=m==="functions"||m==="src"?w__default.default.basename(d,w__default.default.extname(d)):m,L=t.runtime||Ve(d);console.log(f__default.default.gray(` - ${y} (${L})`));}if(console.log(""),t.dryRun){console.log(f__default.default.yellow("Dry run mode - no functions deployed."));return}let l=[];for(let d of c){let m=w__default.default.basename(w__default.default.dirname(d)),y=m==="functions"||m==="src"?w__default.default.basename(d,w__default.default.extname(d)):m,L=t.runtime||Ve(d);e.start(`Deploying ${y}...`);try{let M=D__default.default.readFileSync(d,"utf-8"),K=await zt(o.token,s,y,t.envId);K||(e.text=`Creating ${y}...`,K=await Bt(o.token,s,{name:y,runtime:L,entrypoint:w__default.default.basename(d),envId:t.envId})),e.text=`Deploying ${y}...`,await qt(o.token,K.id,M),e.succeed(`Deployed ${y}`),l.push({name:y,success:!0});}catch(M){let K=M instanceof Error?M.message:"Unknown error";e.fail(`Failed to deploy ${y}`),l.push({name:y,success:false,error:K});}}console.log("");let p=l.filter(d=>d.success).length;if(l.filter(d=>!d.success).length===0)console.log(f__default.default.green(`\u2713 Successfully deployed ${p} function(s)`));else {console.log(f__default.default.yellow(`Deployed ${p}/${l.length} function(s)`)),console.log(""),console.log(f__default.default.red("Failed deployments:"));for(let d of l.filter(m=>!m.success))console.log(f__default.default.red(` - ${d.name}: ${d.error}`));}console.log("");}async function $e(t){let e=H__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(console.log(f__default.default.red("No project ID specified")),process.exit(1)),e.start("Fetching functions...");try{let i=await Yt(o.token,s,t.envId);if(e.stop(),i.length===0){console.log(f__default.default.yellow(`
|
|
3730
|
+
No functions found`)),console.log(f__default.default.gray("Deploy your first function with: vaif functions deploy"));return}console.log(""),console.log(f__default.default.bold(`Functions (${i.length}):`)),console.log(""),console.log(f__default.default.gray(" "+"NAME".padEnd(25)+"RUNTIME".padEnd(15)+"STATUS".padEnd(12)+"INVOCATIONS".padEnd(14)+"LAST DEPLOYED")),console.log(f__default.default.gray(" "+"-".repeat(80)));for(let a of i){let c=a.deployStatus==="deployed"?f__default.default.green:a.deployStatus==="deploying"?f__default.default.yellow:a.deployStatus==="failed"?f__default.default.red:f__default.default.gray;console.log(" "+a.name.padEnd(25)+a.runtime.padEnd(15)+c(a.deployStatus.padEnd(12))+String(a.invocationCount??0).padEnd(14)+(a.deployedAt?new Date(a.deployedAt).toLocaleDateString():"-"));}console.log("");}catch(i){e.fail("Failed to fetch functions"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3731
|
+
Error: ${i.message}`)),process.exit(1);}}var X=process.env.VAIF_API_URL||"https://api.vaif.studio";async function Gt(t,e,o,n,r){let s=await fetch(`${X}/v1/projects/${e}/db/seed`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},body:JSON.stringify({table:o,records:n,truncate:r?.truncate??false})});if(!s.ok){let i=await s.text();throw new Error(`Failed to seed ${o}: ${i}`)}return s.json()}async function Jt(t,e){let o=await fetch(`${X}/v1/projects/${e}/db/reset`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"}});if(!o.ok){let n=await o.text();throw new Error(`Failed to reset database: ${n}`)}return o.json()}function ue(t){let e=[];if(!D__default.default.existsSync(t))return e;let o=D__default.default.readdirSync(t,{withFileTypes:true});for(let n of o)if(n.isFile()){let r=w__default.default.extname(n.name).toLowerCase();(r===".json"||r===".ts"||r===".js")&&e.push(w__default.default.join(t,n.name));}return e.sort()}async function Oe(t){let e=w__default.default.extname(t).toLowerCase();if(e===".json"){let o=D__default.default.readFileSync(t,"utf-8"),n=JSON.parse(o);return Array.isArray(n)?[{table:w__default.default.basename(t,e),data:n}]:n.table&&n.data?[n]:Object.entries(n).map(([r,s])=>({table:r,data:s}))}else if(e===".ts"||e===".js"){let o=await import(t),n=o.default||o;return typeof n=="function"?n():n}throw new Error(`Unsupported file format: ${e}`)}async function Me(t){let e=H__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),console.log(""),console.log(f__default.default.bold("VAIF Database Seed")),console.log("");let i=[];if(t.file){let p=w__default.default.resolve(t.file);D__default.default.existsSync(p)||(console.log(f__default.default.red(`File not found: ${t.file}`)),process.exit(1)),i=[p];}else {let p=w__default.default.resolve("seeds"),u=w__default.default.resolve("prisma/seed"),d=w__default.default.resolve("db/seeds");i=[...ue(p),...ue(u),...ue(d)];}i.length===0&&(console.log(f__default.default.yellow("No seed files found")),console.log(f__default.default.gray(`
|
|
3728
3732
|
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(`
|
|
3729
3733
|
Or specify a file with --file`)),console.log(f__default.default.gray(`
|
|
3730
|
-
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
|
|
3734
|
+
Example seed file (seeds/users.json):`)),console.log(f__default.default.gray(" [")),console.log(f__default.default.gray(' { "name": "John Doe", "email": "john@example.com" },')),console.log(f__default.default.gray(' { "name": "Jane Doe", "email": "jane@example.com" }')),console.log(f__default.default.gray(" ]")),process.exit(1)),console.log(f__default.default.gray("Seed files found:"));for(let p of i)console.log(f__default.default.gray(` - ${w__default.default.relative(process.cwd(),p)}`));if(console.log(""),t.truncate&&(console.log(f__default.default.yellow("\u26A0\uFE0F Tables will be truncated before seeding")),console.log("")),t.dryRun){console.log(f__default.default.yellow("Dry run mode - no data will be inserted.")),console.log("");for(let p of i){e.start(`Loading ${w__default.default.basename(p)}...`);try{let u=await Oe(p);e.stop();for(let d of u)t.table&&d.table!==t.table||(console.log(f__default.default.cyan(`Table: ${d.table}`)),console.log(f__default.default.gray(` Records: ${d.data.length}`)),d.data.length>0&&console.log(f__default.default.gray(` Sample: ${JSON.stringify(d.data[0],null,2).slice(0,100)}...`)),console.log(""));}catch(u){e.fail(`Failed to load ${w__default.default.basename(p)}`),u instanceof Error&&console.log(f__default.default.red(` Error: ${u.message}`));}}return}let a=[];for(let p of i){e.start(`Processing ${w__default.default.basename(p)}...`);try{let u=await Oe(p);e.stop();for(let d of u)if(!(t.table&&d.table!==t.table)){if(d.data.length===0){console.log(f__default.default.gray(` Skipping ${d.table} (no records)`));continue}e.start(`Seeding ${d.table} (${d.data.length} records)...`);try{let m=await Gt(o.token,s,d.table,d.data,{truncate:t.truncate});e.succeed(`Seeded ${d.table}: ${m.inserted} records`),a.push({table:d.table,inserted:m.inserted});}catch(m){let y=m instanceof Error?m.message:"Unknown error";e.fail(`Failed to seed ${d.table}`),a.push({table:d.table,inserted:0,error:y});}}}catch(u){e.fail(`Failed to load ${w__default.default.basename(p)}`),u instanceof Error&&console.log(f__default.default.red(` Error: ${u.message}`));}}console.log("");let c=a.reduce((p,u)=>p+u.inserted,0),l=a.filter(p=>p.error).length;if(l===0)console.log(f__default.default.green(`\u2713 Successfully seeded ${c} records across ${a.length} table(s)`));else {console.log(f__default.default.yellow(`Seeded ${c} records with ${l} error(s)`)),console.log(""),console.log(f__default.default.red("Errors:"));for(let p of a.filter(u=>u.error))console.log(f__default.default.red(` - ${p.table}: ${p.error}`));}console.log("");}async function Ke(t){let e=H__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1));let i=w__default.default.resolve(t.dir||"./drizzle");if(console.log(""),console.log(f__default.default.bold("VAIF Database Push")),console.log(""),!D__default.default.existsSync(i)){let u=w__default.default.resolve("./migrations");D__default.default.existsSync(u)?console.log(f__default.default.gray(`Using migrations from: ${u}`)):(console.log(f__default.default.red(`Migrations directory not found: ${i}`)),console.log(f__default.default.gray(`
|
|
3731
3735
|
Expected one of:`)),console.log(f__default.default.gray(" - ./drizzle/")),console.log(f__default.default.gray(" - ./migrations/")),console.log(f__default.default.gray(`
|
|
3732
|
-
Or specify with: vaif db push --dir <path>`)),process.exit(1));}let a=[],
|
|
3733
|
-
Error: ${a.message}`)),process.exit(1);}}async function Be(t){let e=H__default.default(),o=
|
|
3734
|
-
Error: ${i.message}`)),process.exit(1);}}var Ye=process.env.VAIF_API_URL||"https://api.vaif.studio";function
|
|
3735
|
-
Error: ${a.message}`)),process.exit(1);}}async function We(t){let e=H__default.default(),o=
|
|
3736
|
-
Generate one with: vaif keys generate`));return}let
|
|
3737
|
-
Error: ${i.message}`)),process.exit(1);}}var O=process.env.VAIF_API_URL||"https://api.vaif.studio";function
|
|
3738
|
-
Error: ${
|
|
3739
|
-
Create one with: vaif secrets set <name> <value>`));return}let
|
|
3740
|
-
Error: ${s.message}`)),process.exit(1);}}async function Qe(t,e){let o=H__default.default(),n=Z(),r=await ee(e.config),s=te(e,r,n);console.log(""),o.start("Fetching secret...");try{let i=new URL(`${O}/functions/secrets/project/${s}`);e.envId&&i.searchParams.set("envId",e.envId);let a=await fetch(i.toString(),{headers:{Authorization:`Bearer ${n.token}`}});if(!a.ok)throw new Error(`Failed to fetch secrets: ${await a.text()}`);let
|
|
3741
|
-
Error: ${i.message}`)),process.exit(1);}}async function Ze(t,e){let o=H__default.default(),n=Z(),r=await ee(e.config),s=te(e,r,n);console.log(""),console.log(f__default.default.bold("VAIF Delete Secret")),console.log(""),o.start("Finding secret...");try{let i=new URL(`${O}/functions/secrets/project/${s}`);e.envId&&i.searchParams.set("envId",e.envId);let a=await fetch(i.toString(),{headers:{Authorization:`Bearer ${n.token}`}});if(!a.ok)throw new Error(`Failed to fetch secrets: ${await a.text()}`);let
|
|
3742
|
-
Error: ${i.message}`)),process.exit(1);}}var et=process.env.VAIF_API_URL||"https://api.vaif.studio";function
|
|
3743
|
-
Error: ${i.message}`)),process.exit(1);}}var
|
|
3744
|
-
Error: ${i.message}`)),process.exit(1);}}var nt="1.7.
|
|
3736
|
+
Or specify with: vaif db push --dir <path>`)),process.exit(1));}let a=[],c=D__default.default.readdirSync(i,{withFileTypes:true});for(let u of c)if(u.isFile()&&u.name.endsWith(".sql"))a.push(w__default.default.join(i,u.name));else if(u.isDirectory()){let d=D__default.default.readdirSync(w__default.default.join(i,u.name),{withFileTypes:true});for(let m of d)m.isFile()&&m.name.endsWith(".sql")&&a.push(w__default.default.join(i,u.name,m.name));}a.sort(),a.length===0&&(console.log(f__default.default.yellow("No SQL migration files found")),process.exit(1)),console.log(f__default.default.gray(`Found ${a.length} migration(s):`));for(let u of a)console.log(f__default.default.gray(` - ${w__default.default.relative(process.cwd(),u)}`));if(console.log(""),t.dryRun){console.log(f__default.default.yellow("Dry run mode - no migrations will be applied.")),console.log("");for(let u of a){let d=D__default.default.readFileSync(u,"utf-8");console.log(f__default.default.cyan(`--- ${w__default.default.basename(u)} ---`)),console.log(f__default.default.gray(d.slice(0,500))),d.length>500&&console.log(f__default.default.gray("...")),console.log("");}return}let l=0,p=0;for(let u of a){let d=D__default.default.readFileSync(u,"utf-8"),m=w__default.default.relative(process.cwd(),u);e.start(`Applying ${m}...`);try{let y=await fetch(`${X}/schema-engine/query/${s}`,{method:"POST",headers:{Authorization:`Bearer ${o.token}`,"Content-Type":"application/json"},body:JSON.stringify({sql:d})});if(!y.ok){let L=await y.text();throw new Error(L)}e.succeed(`Applied ${m}`),l++;}catch(y){let L=y instanceof Error?y.message:"Unknown error";e.fail(`Failed ${m}: ${L}`),p++;}}console.log(""),console.log(p===0?f__default.default.green(`Successfully applied ${l} migration(s)`):f__default.default.yellow(`Applied ${l}, failed ${p} migration(s)`)),console.log("");}async function ze(t){let e=H__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1));let i=w__default.default.resolve(t.output||"vaif.schema.json");console.log(""),console.log(f__default.default.bold("VAIF Database Pull")),console.log(""),e.start("Pulling schema from remote...");try{let a=await fetch(`${X}/schema-engine/introspect/${s}`,{headers:{Authorization:`Bearer ${o.token}`}});if(!a.ok){let p=await a.text();throw new Error(`Failed to pull schema: ${p}`)}let c=await a.json();D__default.default.writeFileSync(i,JSON.stringify(c,null,2),"utf-8"),e.succeed(`Schema written to ${w__default.default.relative(process.cwd(),i)}`);let l=c.tables?.length??Object.keys(c).length;console.log(f__default.default.gray(` ${l} table(s) pulled`)),console.log("");}catch(a){e.fail("Failed to pull schema"),a instanceof Error&&console.log(f__default.default.red(`
|
|
3737
|
+
Error: ${a.message}`)),process.exit(1);}}async function Be(t){let e=H__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(console.log(f__default.default.red("No project ID specified")),process.exit(1)),console.log(""),console.log(f__default.default.red.bold("\u26A0\uFE0F DATABASE RESET")),console.log(""),console.log(f__default.default.red("This will:")),console.log(f__default.default.red(" - Drop all tables")),console.log(f__default.default.red(" - Delete all data")),console.log(f__default.default.red(" - Reset migrations")),console.log(""),console.log(f__default.default.red.bold("This action cannot be undone!")),console.log(""),t.force||(console.log(f__default.default.yellow("Use --force to confirm this action.")),process.exit(1)),e.start("Resetting database...");try{await Jt(o.token,s),e.succeed("Database reset complete"),console.log(""),console.log(f__default.default.gray("Your database is now empty.")),console.log(f__default.default.gray("Run `vaif push` to apply your schema, then `vaif db seed` to seed data.")),console.log("");}catch(i){e.fail("Failed to reset database"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3738
|
+
Error: ${i.message}`)),process.exit(1);}}var Ye=process.env.VAIF_API_URL||"https://api.vaif.studio";function Ge(t,e,o){return t.projectId||e?.projectId||process.env.VAIF_PROJECT_ID||o.projectId||null}async function Je(t){let e=H__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=Ge(t,r,o);s||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1));let i=t.name||`cli-key-${Date.now()}`;console.log(""),console.log(f__default.default.bold("VAIF Generate API Key")),console.log(""),e.start("Generating API key...");try{let a=await fetch(`${Ye}/v1/projects/${s}/api-keys`,{method:"POST",headers:{Authorization:`Bearer ${o.token}`,"Content-Type":"application/json"},body:JSON.stringify({name:i})});if(!a.ok){let l=await a.text();throw new Error(`Failed to generate key: ${l}`)}let c=await a.json();e.succeed("API key generated"),console.log(""),console.log(f__default.default.green(` Name: ${c.name}`)),console.log(f__default.default.green(` Key: ${c.key}`)),console.log(""),console.log(f__default.default.yellow.bold(" Save this key now - it will not be shown again!")),console.log("");}catch(a){e.fail("Failed to generate API key"),a instanceof Error&&console.log(f__default.default.red(`
|
|
3739
|
+
Error: ${a.message}`)),process.exit(1);}}async function We(t){let e=H__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=Ge(t,r,o);s||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),console.log(""),console.log(f__default.default.bold("VAIF API Keys")),console.log(""),e.start("Fetching API keys...");try{let i=await fetch(`${Ye}/v1/projects/${s}/api-keys`,{headers:{Authorization:`Bearer ${o.token}`}});if(!i.ok){let u=await i.text();throw new Error(`Failed to list keys: ${u}`)}let a=await i.json(),c=a.keys||a;if(e.stop(),!Array.isArray(c)||c.length===0){console.log(f__default.default.yellow("No API keys found")),console.log(f__default.default.gray(`
|
|
3740
|
+
Generate one with: vaif keys generate`));return}let l=Math.max(8,...c.map(u=>(u.name||"").length)),p=` ${"Name".padEnd(l)} ${"Key".padEnd(24)} Created`;console.log(f__default.default.gray(p)),console.log(f__default.default.gray(" "+"-".repeat(p.length-2)));for(let u of c){let d=(u.name||"unnamed").padEnd(l),m=u.maskedKey||u.prefix||`${(u.key||"").slice(0,12)}...`,y=u.createdAt?new Date(u.createdAt).toLocaleDateString():"N/A";console.log(` ${d} ${m.padEnd(24)} ${y}`);}console.log(""),console.log(f__default.default.gray(` ${c.length} key(s) total`)),console.log("");}catch(i){e.fail("Failed to list API keys"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3741
|
+
Error: ${i.message}`)),process.exit(1);}}var O=process.env.VAIF_API_URL||"https://api.vaif.studio";function Ht(t,e,o){return t.projectId||e?.projectId||process.env.VAIF_PROJECT_ID||o.projectId||null}function Z(){let t=I();return (!t||!t.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1)),t}async function ee(t){try{return await A(t||"vaif.config.json")}catch{return null}}function te(t,e,o){let n=Ht(t,e,o);return n||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),n}async function He(t,e,o){let n=H__default.default(),r=Z(),s=await ee(o.config),i=te(o,s,r),a=e;if(o.fromFile)try{a=D__default.default.readFileSync(o.fromFile,"utf-8");}catch(c){console.log(f__default.default.red(`Failed to read file: ${o.fromFile}`)),c instanceof Error&&console.log(f__default.default.gray(c.message)),process.exit(1);}a||(console.log(f__default.default.red("No value provided")),console.log(f__default.default.gray("Provide a value as argument or use --from-file <path>")),process.exit(1)),console.log(""),console.log(f__default.default.bold("VAIF Set Secret")),console.log(""),n.start("Checking for existing secret...");try{let c=new URL(`${O}/functions/secrets/project/${i}`);o.envId&&c.searchParams.set("envId",o.envId);let l=await fetch(c.toString(),{headers:{Authorization:`Bearer ${r.token}`}});if(!l.ok)throw new Error(`Failed to check existing secrets: ${await l.text()}`);let u=(await l.json()).find(d=>d.key===t);if(u){n.text=`Updating secret "${t}"...`;let d=await fetch(`${O}/functions/secrets/${u.id}`,{method:"PUT",headers:{Authorization:`Bearer ${r.token}`,"Content-Type":"application/json"},body:JSON.stringify({value:a})});if(!d.ok)throw new Error(`Failed to update secret: ${await d.text()}`);n.succeed(`Updated secret "${t}"`);}else {n.text=`Creating secret "${t}"...`;let d=await fetch(`${O}/functions/secrets`,{method:"POST",headers:{Authorization:`Bearer ${r.token}`,"Content-Type":"application/json"},body:JSON.stringify({projectId:i,envId:o.envId,key:t,value:a})});if(!d.ok)throw new Error(`Failed to create secret: ${await d.text()}`);n.succeed(`Created secret "${t}"`);}console.log("");}catch(c){n.fail("Failed to set secret"),c instanceof Error&&console.log(f__default.default.red(`
|
|
3742
|
+
Error: ${c.message}`)),process.exit(1);}}async function Xe(t){let e=H__default.default(),o=Z(),n=await ee(t.config),r=te(t,n,o);console.log(""),console.log(f__default.default.bold("VAIF Secrets")),console.log(""),e.start("Fetching secrets...");try{let s=new URL(`${O}/functions/secrets/project/${r}`);t.envId&&s.searchParams.set("envId",t.envId);let i=await fetch(s.toString(),{headers:{Authorization:`Bearer ${o.token}`}});if(!i.ok)throw new Error(`Failed to list secrets: ${await i.text()}`);let a=await i.json();if(e.stop(),a.length===0){console.log(f__default.default.yellow("No secrets found")),console.log(f__default.default.gray(`
|
|
3743
|
+
Create one with: vaif secrets set <name> <value>`));return}let c=Math.max(8,...a.map(p=>p.key.length)),l=` ${"Name".padEnd(c)} Created`;console.log(f__default.default.gray(l)),console.log(f__default.default.gray(" "+"-".repeat(l.length-2)));for(let p of a){let u=p.key.padEnd(c),d=p.createdAt?new Date(p.createdAt).toLocaleDateString():"N/A";console.log(` ${u} ${d}`);}console.log(""),console.log(f__default.default.gray(` ${a.length} secret(s) total`)),console.log(f__default.default.gray(" Values are hidden. Use `vaif secrets get <name>` to reveal.")),console.log("");}catch(s){e.fail("Failed to list secrets"),s instanceof Error&&console.log(f__default.default.red(`
|
|
3744
|
+
Error: ${s.message}`)),process.exit(1);}}async function Qe(t,e){let o=H__default.default(),n=Z(),r=await ee(e.config),s=te(e,r,n);console.log(""),o.start("Fetching secret...");try{let i=new URL(`${O}/functions/secrets/project/${s}`);e.envId&&i.searchParams.set("envId",e.envId);let a=await fetch(i.toString(),{headers:{Authorization:`Bearer ${n.token}`}});if(!a.ok)throw new Error(`Failed to fetch secrets: ${await a.text()}`);let l=(await a.json()).find(d=>d.key===t);l||(o.fail(`Secret "${t}" not found`),process.exit(1));let p=await fetch(`${O}/functions/secrets/${l.id}/value`,{headers:{Authorization:`Bearer ${n.token}`}});if(!p.ok)throw new Error(`Failed to get secret value: ${await p.text()}`);let u=await p.json();o.stop(),console.log(u.value);}catch(i){o.fail("Failed to get secret"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3745
|
+
Error: ${i.message}`)),process.exit(1);}}async function Ze(t,e){let o=H__default.default(),n=Z(),r=await ee(e.config),s=te(e,r,n);console.log(""),console.log(f__default.default.bold("VAIF Delete Secret")),console.log(""),o.start("Finding secret...");try{let i=new URL(`${O}/functions/secrets/project/${s}`);e.envId&&i.searchParams.set("envId",e.envId);let a=await fetch(i.toString(),{headers:{Authorization:`Bearer ${n.token}`}});if(!a.ok)throw new Error(`Failed to fetch secrets: ${await a.text()}`);let l=(await a.json()).find(u=>u.key===t);l||(o.fail(`Secret "${t}" not found`),process.exit(1)),o.text=`Deleting secret "${t}"...`;let p=await fetch(`${O}/functions/secrets/${l.id}`,{method:"DELETE",headers:{Authorization:`Bearer ${n.token}`}});if(!p.ok)throw new Error(`Failed to delete secret: ${await p.text()}`);o.succeed(`Deleted secret "${t}"`),console.log("");}catch(i){o.fail("Failed to delete secret"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3746
|
+
Error: ${i.message}`)),process.exit(1);}}var et=process.env.VAIF_API_URL||"https://api.vaif.studio";function Qt(t){try{let e=new URL(t);return e.password&&(e.password="****"),e.toString()}catch{return t.replace(/:[^@/]+@/,":****@")}}async function tt(t){let e=H__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),e.start("Fetching project info...");try{let i=await fetch(`${et}/v1/projects/${s}`,{headers:{Authorization:`Bearer ${o.token}`}});if(!i.ok){let p=await i.text();throw new Error(`Failed to fetch project: ${p}`)}let a=await i.json();e.stop(),console.log(""),console.log(f__default.default.bold("VAIF Project Info")),console.log("");let c=16,l=(p,u)=>{console.log(` ${f__default.default.gray(p.padEnd(c))} ${u}`);};l("Name:",f__default.default.white(a.name||"N/A")),l("Project ID:",f__default.default.white(s)),l("Region:",f__default.default.white(a.region||"us-east-1")),l("Plan:",f__default.default.white(a.plan||a.tier||"free")),l("Created:",f__default.default.white(a.createdAt?new Date(a.createdAt).toLocaleDateString():"N/A")),console.log(""),l("API URL:",f__default.default.cyan(a.apiUrl||`${et}/v1`)),l("WS URL:",f__default.default.cyan(a.wsUrl||a.realtimeUrl||"N/A")),l("DB URL:",f__default.default.cyan(a.databaseUrl?Qt(a.databaseUrl):"N/A")),l("Storage URL:",f__default.default.cyan(a.storageUrl||"N/A")),console.log("");}catch(i){e.fail("Failed to fetch project info"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3747
|
+
Error: ${i.message}`)),process.exit(1);}}var eo=process.env.VAIF_API_URL||"https://api.vaif.studio";async function ot(t){let e=H__default.default(),o=I();(!o||!o.token)&&(console.log(f__default.default.red("Not logged in")),console.log(f__default.default.gray("Run `vaif login` first to authenticate")),process.exit(1));let n=t.config||"vaif.config.json",r=null;try{r=await A(n);}catch{}let s=t.projectId||r?.projectId||process.env.VAIF_PROJECT_ID||o.projectId;s||(console.log(f__default.default.red("No project ID specified")),console.log(f__default.default.yellow("Set projectId in vaif.config.json or use --project-id flag.")),process.exit(1)),e.start("Fetching project status...");try{let i=await fetch(`${eo}/v1/projects/${s}?include=tables,functions,storage,connections`,{headers:{Authorization:`Bearer ${o.token}`}});if(!i.ok){let y=await i.text();throw new Error(`Failed to fetch project status: ${y}`)}let a=await i.json();e.stop(),console.log(""),console.log(f__default.default.bold("VAIF Project Status")),console.log("");let c=22,l=(y,L)=>{console.log(` ${f__default.default.gray(y.padEnd(c))} ${L}`);};l("Project:",f__default.default.white(a.name||s)),l("Plan:",f__default.default.white(a.plan||a.tier||"free")),console.log(""),console.log(f__default.default.gray(" --- Resources ---")),console.log("");let p=a.tableCount??a.tables?.length??"N/A",u=a.functionCount??a.functions?.length??"N/A",d=a.bucketCount??a.storage?.buckets?.length??"N/A",m=a.activeConnections??a.connections??"N/A";l("Tables:",f__default.default.white(String(p))),l("Functions:",f__default.default.white(String(u))),l("Storage Buckets:",f__default.default.white(String(d))),l("Active Connections:",f__default.default.white(String(m))),a.usage&&(console.log(""),console.log(f__default.default.gray(" --- Usage ---")),console.log(""),a.usage.dbSize&&l("Database Size:",f__default.default.white(a.usage.dbSize)),a.usage.storageSize&&l("Storage Size:",f__default.default.white(a.usage.storageSize)),a.usage.bandwidth&&l("Bandwidth:",f__default.default.white(a.usage.bandwidth)),a.usage.functionInvocations!=null&&l("Function Invocations:",f__default.default.white(String(a.usage.functionInvocations)))),console.log("");}catch(i){e.fail("Failed to fetch project status"),i instanceof Error&&console.log(f__default.default.red(`
|
|
3748
|
+
Error: ${i.message}`)),process.exit(1);}}var nt="1.7.2",fe=f__default.default.hex("#00f0ff"),ge=f__default.default.hex("#7b61ff"),me=f__default.default.hex("#ff3dff"),he=f__default.default.hex("#00ff9d"),S=f__default.default.hex("#555570"),z=f__default.default.hex("#00f0ff");function to(){console.log(""),console.log(fe(" \u2566 \u2566")+ge("\u2554\u2550\u2557\u2566")+me("\u2554\u2550\u2557 ")+he("\u2554\u2550\u2557\u2566 \u2566")),console.log(fe(" \u255A\u2557\u2554\u255D")+ge("\u2560\u2550\u2563\u2551")+me("\u2560\u2563 ")+he("\u2551 \u2551 \u2551")),console.log(fe(" \u255A\u255D ")+ge("\u2569 \u2569\u2569")+me("\u255A ")+he("\u255A\u2550\u255D\u2569\u2550\u255D\u2569")),console.log(""),console.log(S(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),console.log(z(" VAIF Studio CLI")+S(` v${nt}`)),console.log(S(" Build full-stack apps at lightning speed")),console.log(S(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")),console.log(""),console.log(f__default.default.bold(" Quick Start")),console.log(S(" $ ")+z("vaif login")+S(" Authenticate")),console.log(S(" $ ")+z("vaif init -t react-spa")+S(" Scaffold project")),console.log(S(" $ ")+z("vaif db push")+S(" Push migrations")),console.log(S(" $ ")+z("vaif generate")+S(" Generate types")),console.log(S(" $ ")+z("vaif functions deploy")+S(" Deploy functions")),console.log(""),console.log(f__default.default.bold(" Categories")),console.log(S(" auth ")+f__default.default.white("login, logout, whoami")),console.log(S(" project ")+f__default.default.white("init, templates, info, status")),console.log(S(" schema ")+f__default.default.white("pull, push, generate")),console.log(S(" database ")+f__default.default.white("db push, db pull, db seed, db reset")),console.log(S(" deploy ")+f__default.default.white("functions deploy, functions list")),console.log(S(" security ")+f__default.default.white("keys, secrets")),console.log(""),console.log(S(" Run ")+z("vaif <command> --help")+S(" for details")),console.log(S(" Docs: ")+f__default.default.underline("https://docs.vaif.studio")),console.log("");}commander.program.name("vaif").description("VAIF CLI - Type generation and development tools").version(nt);commander.program.command("login").description("Authenticate with VAIF (opens browser)").option("-e, --email","Login with email/password instead of browser").option("-p, --project-id <id>","Default project ID").action(we);commander.program.command("logout").description("Log out and remove stored credentials").action(Se);commander.program.command("whoami").description("Show current authenticated user").action(_e);commander.program.command("init").description("Initialize VAIF configuration in your project").option("--typescript","Setup for TypeScript project").option("-f, --force","Overwrite existing config").option("-t, --template <name>","Scaffold from a template (run vaif templates for list)").option("--features <features>","Comma-separated features to include: auth,database,realtime,storage,functions").option("--add-features <features>","Add features to an existing project (requires --template)").action(je);commander.program.command("templates").alias("tpl").description("List available project templates").action(Pe);commander.program.command("info").description("Show project information (name, region, URLs)").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").action(tt);commander.program.command("status").description("Show project status (tables, functions, storage, connections)").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").action(ot);commander.program.command("pull").description("Pull database schema from your VAIF project").option("-c, --config <path>","Config file path","vaif.config.json").option("-o, --output <path>","Output file path","vaif.schema.json").option("-s, --schema <name>","Schema name","public").option("-p, --project-id <id>","Project ID (overrides config)").action(Ce);commander.program.command("push").description("Push local schema changes to your VAIF project").option("-c, --config <path>","Config file path","vaif.config.json").option("-s, --schema <path>","Schema file path","vaif.schema.json").option("-p, --project-id <id>","Project ID (overrides config)").option("--dry-run","Preview changes without applying").option("-f, --force","Apply changes without confirmation").action(Le);commander.program.command("generate").alias("gen").description("Generate TypeScript types from your database schema").option("-c, --connection <url>","Database connection string").option("-o, --output <path>","Output file path","./src/types/database.ts").option("--schema <name>","Schema name","public").option("--config <path>","Config file path","vaif.config.json").option("--dry-run","Preview generated types without writing").action(xe);var at=commander.program.command("functions").alias("fn").description("Manage serverless functions");at.command("deploy").description("Deploy functions to your VAIF project").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID").option("-n, --name <name>","Function name filter").option("-r, --runtime <runtime>","Runtime (nodejs, typescript, python)").option("--entrypoint <file>","Specific entrypoint file").option("--dry-run","Preview deployment without deploying").action(ke);at.command("list").alias("ls").description("List deployed functions").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID").action($e);var oe=commander.program.command("db").description("Database management commands");oe.command("push").description("Push local Drizzle migrations to VAIF project").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-d, --dir <path>","Migrations directory","./drizzle").option("--dry-run","Preview without applying").action(Ke);oe.command("pull").description("Pull schema from VAIF project").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-o, --output <path>","Output file","vaif.schema.json").action(ze);oe.command("seed").description("Seed your database with test data").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-f, --file <path>","Specific seed file").option("-t, --table <name>","Seed specific table only").option("--truncate","Truncate tables before seeding").option("--dry-run","Preview seeding without inserting data").action(Me);oe.command("reset").description("Reset database (drop all tables and data)").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-f, --force","Confirm reset (required)").action(Be);var it=commander.program.command("keys").description("Manage API keys");it.command("generate").description("Generate a new API key").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-n, --name <name>","Key name").action(Je);it.command("list").alias("ls").description("List API keys").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").action(We);var ne=commander.program.command("secrets").alias("sec").description("Manage function secrets");ne.command("set <name> [value]").description("Create or update a secret").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID or name").option("--from-file <path>","Read secret value from a file").action(He);ne.command("list").alias("ls").description("List all secrets (names only)").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID or name").action(Xe);ne.command("get <name>").description("Reveal a secret value").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID or name").action(Qe);ne.command("delete <name>").description("Delete a secret").option("-c, --config <path>","Config file path","vaif.config.json").option("-p, --project-id <id>","Project ID (overrides config)").option("-e, --env-id <id>","Environment ID or name").action(Ze);process.argv.slice(2).length||(to(),process.exit(0));commander.program.parse(process.argv);
|