everyapp 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import{a as o,b as s}from"./chunk-YRO4PVS3.js";import"./chunk-JOHMESCX.js";import{proposeCompletions as r}from"@stricli/core";var t=process.argv.slice(3);process.env.COMP_LINE?.endsWith(" ")&&t.push("");await r(s,t,o(process));try{for(let{completion:p}of await r(s,t,o(process)))process.stdout.write(`${p}
2
+ import{a as o,b as s}from"./chunk-OYJHDLMN.js";import"./chunk-VOYWQ73B.js";import{proposeCompletions as r}from"@stricli/core";var t=process.argv.slice(3);process.env.COMP_LINE?.endsWith(" ")&&t.push("");await r(s,t,o(process));try{for(let{completion:p}of await r(s,t,o(process)))process.stdout.write(`${p}
3
3
  `)}catch{}
@@ -1 +1 @@
1
- import{c as n}from"./chunk-JOHMESCX.js";import a from"chalk";var p="https://registry.npmjs.org/everyapp?fields=dist-tags",f=2e3,i=null;function y(){i||(i=d().then(t=>t&&t!==n&&g(n,t)?{updateAvailable:!0,latestVersion:t,currentVersion:n}:{updateAvailable:!1,currentVersion:n}))}var u=!1;async function m(){if(u||!i)return;u=!0;let t=await i;h(t)}async function V(t){await m(),process.exit(t)}async function d(){try{let t=new AbortController,o=setTimeout(()=>t.abort(),f),e=await fetch(p,{signal:t.signal});return clearTimeout(o),e.ok?(await e.json())["dist-tags"].latest:null}catch{return null}}function g(t,o){let e=t.split(".").map(Number),s=o.split(".").map(Number);for(let r=0;r<Math.max(e.length,s.length);r++){let l=e[r]??0,c=s[r]??0;if(l<c)return!0;if(l>c)return!1}return!1}function h(t){t.updateAvailable&&t.latestVersion&&(console.log(),console.log(a.yellow(` Update available: ${t.currentVersion} \u2192 ${t.latestVersion}`)),console.log(a.dim(` Update: ${a.cyan("npm install -g everyapp@latest")}`)))}export{y as a,m as b,V as c};
1
+ import{c as n}from"./chunk-VOYWQ73B.js";import a from"chalk";var p="https://registry.npmjs.org/everyapp?fields=dist-tags",f=2e3,i=null;function y(){i||(i=d().then(t=>t&&t!==n&&g(n,t)?{updateAvailable:!0,latestVersion:t,currentVersion:n}:{updateAvailable:!1,currentVersion:n}))}var u=!1;async function m(){if(u||!i)return;u=!0;let t=await i;h(t)}async function V(t){await m(),process.exit(t)}async function d(){try{let t=new AbortController,o=setTimeout(()=>t.abort(),f),e=await fetch(p,{signal:t.signal});return clearTimeout(o),e.ok?(await e.json())["dist-tags"].latest:null}catch{return null}}function g(t,o){let e=t.split(".").map(Number),s=o.split(".").map(Number);for(let r=0;r<Math.max(e.length,s.length);r++){let l=e[r]??0,c=s[r]??0;if(l<c)return!0;if(l>c)return!1}return!1}function h(t){t.updateAvailable&&t.latestVersion&&(console.log(),console.log(a.yellow(` Update available: ${t.currentVersion} \u2192 ${t.latestVersion}`)),console.log(a.dim(` Update: ${a.cyan("npm install -g everyapp@latest")}`)))}export{y as a,m as b,V as c};
@@ -1,4 +1,4 @@
1
- import{c as e}from"./chunk-ASNYTFJJ.js";import n from"node:fs/promises";import p from"node:path";import o from"chalk";var a=["every-app.jsonc","every-app.json"];async function f(){let r=process.cwd();for(let c of a){let t=p.join(r,c);try{await n.access(t);return}catch{}}console.log(o.yellow(`
1
+ import{c as e}from"./chunk-APTBZ2LQ.js";import n from"node:fs/promises";import p from"node:path";import o from"chalk";var a=["every-app.jsonc","every-app.json"];async function f(){let r=process.cwd();for(let c of a){let t=p.join(r,c);try{await n.access(t);return}catch{}}console.log(o.yellow(`
2
2
  Not inside an Every App project`)),console.log(o.dim(` No every-app.jsonc found
3
3
  `)),console.log("To create a new app, run the below command from the directory where you store your projects:"),console.log(o.dim(` npx everyapp app create
4
4
  `)),await e(1)}export{f as a};
@@ -1,4 +1,4 @@
1
- import{c as l}from"./chunk-VYHFMMFQ.js";import{a,e as r}from"./chunk-EOQC6VQV.js";import i from"chalk";async function c({targetDir:n,verbose:o=!1}){try{o||console.log(`
1
+ import{c as l}from"./chunk-XKKQYCSJ.js";import{a,e as r}from"./chunk-TUDP36IL.js";import i from"chalk";async function c({targetDir:n,verbose:o=!1}){try{o||console.log(`
2
2
  Setting up Cloudflare for local dev...`),await a("pnpm",["run","cf-typegen"],{cwd:n,verbose:o,logCommandToConsole:!1}),await a("pnpm",["run","build"],{cwd:n,verbose:o,logCommandToConsole:!1}),o||console.log(i.dim(` Finished.
3
3
  `)),await a("pnpm",["run","db:migrate:local"],{cwd:n,verbose:o}),console.log(`
4
4
  Local database migrations complete.
@@ -1,4 +1,4 @@
1
- import{c as p}from"./chunk-ASNYTFJJ.js";import b from"node:fs/promises";import l from"node:path";import D from"node:os";import*as w from"smol-toml";import i from"chalk";function I(){let e=D.homedir(),t=D.platform(),n;return t==="win32"?n=l.join(process.env.LOCALAPPDATA||l.join(e,"AppData","Local"),".wrangler"):t==="darwin"?n=l.join(e,"Library","Preferences",".wrangler"):n=l.join(e,".wrangler"),l.join(n,"config","default.toml")}async function N(){let e=I();try{let t=await b.readFile(e,"utf-8"),n=w.parse(t);if(!n.oauth_token||!n.refresh_token)throw new Error("OAuth tokens not found in wrangler config");return n}catch(t){throw t.code==="ENOENT"?new Error("Wrangler config not found. Please run 'npx wrangler login' first."):t}}async function T(e){let t=I(),n=l.dirname(t);await b.mkdir(n,{recursive:!0});let r=w.stringify(e);await b.writeFile(t,r,"utf-8")}function L(e){let t=new Date(e).getTime(),n=Date.now(),r=1*60*1e3;return t-n<r}async function $(e){let t=await fetch("https://dash.cloudflare.com/oauth2/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:"54d11594-84e4-41aa-b438-e81b8fa78ee7"})});if(!t.ok)throw new Error(`Failed to refresh OAuth token: ${t.status} ${t.statusText}`);let n=await t.json();return{oauth_token:n.access_token,expiration_time:new Date(Date.now()+n.expires_in*1e3).toISOString(),refresh_token:n.refresh_token||e,scopes:n.scope?n.scope.split(" "):[]}}async function F(e={}){let{showNewUserHelp:t=!1}=e,n=!!process.env.CLOUDFLARE_API_TOKEN,r=!!process.env.CLOUDFLARE_ACCOUNT_ID;if(n&&!r&&(console.log(i.yellow(`
1
+ import{c as p}from"./chunk-APTBZ2LQ.js";import b from"node:fs/promises";import l from"node:path";import D from"node:os";import*as w from"smol-toml";import i from"chalk";function I(){let e=D.homedir(),t=D.platform(),n;return t==="win32"?n=l.join(process.env.LOCALAPPDATA||l.join(e,"AppData","Local"),".wrangler"):t==="darwin"?n=l.join(e,"Library","Preferences",".wrangler"):n=l.join(e,".wrangler"),l.join(n,"config","default.toml")}async function N(){let e=I();try{let t=await b.readFile(e,"utf-8"),n=w.parse(t);if(!n.oauth_token||!n.refresh_token)throw new Error("OAuth tokens not found in wrangler config");return n}catch(t){throw t.code==="ENOENT"?new Error("Wrangler config not found. Please run 'npx wrangler login' first."):t}}async function T(e){let t=I(),n=l.dirname(t);await b.mkdir(n,{recursive:!0});let r=w.stringify(e);await b.writeFile(t,r,"utf-8")}function L(e){let t=new Date(e).getTime(),n=Date.now(),r=1*60*1e3;return t-n<r}async function $(e){let t=await fetch("https://dash.cloudflare.com/oauth2/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:"54d11594-84e4-41aa-b438-e81b8fa78ee7"})});if(!t.ok)throw new Error(`Failed to refresh OAuth token: ${t.status} ${t.statusText}`);let n=await t.json();return{oauth_token:n.access_token,expiration_time:new Date(Date.now()+n.expires_in*1e3).toISOString(),refresh_token:n.refresh_token||e,scopes:n.scope?n.scope.split(" "):[]}}async function F(e={}){let{showNewUserHelp:t=!1}=e,n=!!process.env.CLOUDFLARE_API_TOKEN,r=!!process.env.CLOUDFLARE_ACCOUNT_ID;if(n&&!r&&(console.log(i.yellow(`
2
2
  Missing CLOUDFLARE_ACCOUNT_ID
3
3
  `)),console.log(`When using CLOUDFLARE_API_TOKEN, you must also set CLOUDFLARE_ACCOUNT_ID.
4
4
  `),console.log(i.dim(` export CLOUDFLARE_ACCOUNT_ID=<your_account_id>
@@ -1,4 +1,4 @@
1
- import{b as l}from"./chunk-QKHNAJYY.js";import{f as s,m as c,n as a,o as m}from"./chunk-4AODVGRU.js";import{c as r}from"./chunk-ASNYTFJJ.js";import A from"enquirer";import t from"chalk";async function D(){if(process.env.CLOUDFLARE_API_TOKEN){let i=process.env.CLOUDFLARE_ACCOUNT_ID;return i?s(i):(console.log(t.yellow(`
1
+ import{b as l}from"./chunk-ZWRZQCN2.js";import{f as s,m as c,n as a,o as m}from"./chunk-JWYVVDE3.js";import{c as r}from"./chunk-APTBZ2LQ.js";import A from"enquirer";import t from"chalk";async function D(){if(process.env.CLOUDFLARE_API_TOKEN){let i=process.env.CLOUDFLARE_ACCOUNT_ID;return i?s(i):(console.log(t.yellow(`
2
2
  CLOUDFLARE_ACCOUNT_ID is required when using CLOUDFLARE_API_TOKEN
3
3
  `)),r(1))}let n=await c(),{account:o,otherAccounts:e}=await m(n);return a(o,e),{id:o.account.id,name:o.account.name}}async function R(n="this",o=!1){let e=await D();if(process.env.CLOUDFLARE_API_TOKEN&&(console.log(t.dim(` ${e.name} (${e.id})`)),console.log()),o)return console.log(t.dim(`Skipping deployment confirmation due to -y flag.
4
4
  `)),!0;let{confirm:i}=await A.prompt({type:"confirm",name:"confirm",message:`Do you want to deploy ${n} to ${e.name}?`,initial:!1});return i}import g from"chalk";import f from"chalk";function z(n,o){n&&console.log(f.dim(o))}function u(n,...o){n&&o.forEach(e=>console.log(f.dim(e)))}var p="npx",d=["drizzle-kit","migrate","--config=drizzle-prod.config.ts"];async function N({cwd:n,verbose:o=!1}){console.log(`
@@ -1,6 +1,6 @@
1
- import{a as t,b as a,c as r}from"./chunk-JOHMESCX.js";import s from"node:fs";import l from"node:os";import p from"node:path";function R(e){return{process:e,os:l,fs:s,path:p}}import{buildApplication as h,buildRouteMap as C}from"@stricli/core";import{buildInstallCommand as v,buildUninstallCommand as w}from"@stricli/auto-complete";import{buildCommand as o,buildRouteMap as d}from"@stricli/core";var m=o({loader:async()=>import("./create-PFP7ROFX.js"),parameters:{positional:{kind:"tuple",parameters:[{brief:"App ID (kebab-case format)",parse:String,optional:!0}]},flags:{verbose:{kind:"boolean",brief:"Show detailed output during creation",optional:!0},yes:{kind:"boolean",brief:"Skip deployment confirmation",optional:!0}},aliases:{y:"yes"}},docs:{brief:"Create a new app from the starter template",fullDescription:["Copies the simple-todo starter template, deploys to Cloudflare, and configures local development.","","Usage: every app create [name]","","The command will:"," 1. Prompt for app ID (or use provided name)"," 2. Deploy to Cloudflare (D1 database, KV namespace, Worker)"," 3. Configure wrangler.jsonc, package.json, and .env files"," 4. Install dependencies and run local migrations","","After creation, run 'pnpm run dev' to start developing."].join(`
2
- `)}}),u=o({loader:async()=>{let{deploy:e}=await import("./deploy-EECMKLNC.js");return e},parameters:{positional:{kind:"tuple",parameters:[]},flags:{verbose:{kind:"boolean",brief:"Show detailed output during deployment",optional:!0},yes:{kind:"boolean",brief:"Skip deployment confirmation",optional:!0}},aliases:{y:"yes"}},docs:{brief:"Deploy an app to Cloudflare",fullDescription:["Deploys the current app to Cloudflare Workers from the current directory.","The deployment process:"," 1. Reads wrangler.jsonc to determine required resources"," 2. Creates or links D1 databases and KV namespaces"," 3. Updates wrangler.jsonc with resource IDs"," 4. Installs dependencies if needed"," 5. Runs database migrations against production D1"," 6. Builds and deploys using wrangler deploy"].join(`
3
- `)}}),c=o({loader:async()=>{let{setupLocal:e}=await import("./setupLocal-VSCBS52B.js");return e},parameters:{positional:{kind:"tuple",parameters:[]},flags:{verbose:{kind:"boolean",brief:"Show detailed output during local setup",optional:!0}}},docs:{brief:"Set up local development in an existing app",fullDescription:["Configures local development for an existing Every App project in the current directory.","","Usage: every app setup-local","","The command will:"," 1. Verify the current directory is an Every App project"," 2. Verify Cloudflare and gateway setup"," 3. Install dependencies"," 4. Create or refresh .env.local"," 5. Generate Cloudflare types and run local database migrations","","This is useful after cloning an existing Every App repository."].join(`
4
- `)}}),f=o({loader:async()=>{let{remoteD1Shell:e}=await import("./remoteD1Shell-HUPEYTS7.js");return e},parameters:{flags:{},positional:{kind:"array",parameter:{brief:"Command and arguments to run with environment variables",parse:String}}},docs:{brief:"Run a command with Cloudflare D1 connection environment variables",fullDescription:["Sets environment variables needed to connect to remote Cloudflare D1 and runs any command that requires D1 access.","","The command will:"," 1. Get the Cloudflare account ID"," 2. Look up the database ID from the database name in wrangler.jsonc"," 3. Get a valid OAuth token"," 4. Run the provided command with CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_DATABASE_ID, CLOUDFLARE_API_TOKEN, and MIGRATE_REMOTE set","","Common use cases:"," - Running Drizzle migrations: npx everyapp app remote-d1-shell -- npx drizzle-kit migrate"," - Opening Drizzle Studio: npx everyapp app remote-d1-shell -- npx drizzle-kit studio"," - Pushing schema changes: npx everyapp app remote-d1-shell -- npx drizzle-kit push","","This command is useful for any operation that needs direct access to your production D1 database."].join(`
5
- `)}}),n=d({routes:{create:m,deploy:u,"setup-local":c,"remote-d1-shell":f},docs:{brief:"App management commands"}});import{buildCommand as y,buildRouteMap as b}from"@stricli/core";var g=y({loader:async()=>{let{deploy:e}=await import("./deploy-S4QY3MQA.js");return e},parameters:{positional:{kind:"tuple",parameters:[]},flags:{repo:{kind:"parsed",parse:String,brief:"Git repository URL to deploy",optional:!0},verbose:{kind:"boolean",brief:"Show detailed output during deployment",optional:!0},localGateway:{kind:"parsed",parse:String,brief:"Path to local gateway tarball (for testing)",optional:!0},yes:{kind:"boolean",brief:"Skip deployment confirmation",optional:!0}},aliases:{y:"yes"}},docs:{brief:"Deploy the gateway application to Cloudflare",fullDescription:["Clones the gateway repository, installs dependencies, runs migrations, and deploys to Cloudflare Workers.","The deployment process:"," 1. Clones the repository to a temporary directory"," 2. Installs npm dependencies"," 3. Runs database migrations against production D1"," 4. Runs wrangler deploy"," 5. Cleans up temporary files"].join(`
1
+ import{a as t,b as a,c as r}from"./chunk-VOYWQ73B.js";import s from"node:fs";import l from"node:os";import p from"node:path";function R(e){return{process:e,os:l,fs:s,path:p}}import{buildApplication as h,buildRouteMap as C}from"@stricli/core";import{buildInstallCommand as v,buildUninstallCommand as w}from"@stricli/auto-complete";import{buildCommand as o,buildRouteMap as d}from"@stricli/core";var m=o({loader:async()=>import("./create-MDOGNG7C.js"),parameters:{positional:{kind:"tuple",parameters:[{brief:"App ID (kebab-case format)",parse:String,optional:!0}]},flags:{verbose:{kind:"boolean",brief:"Show detailed output during creation",optional:!0},yes:{kind:"boolean",brief:"Skip deployment confirmation",optional:!0}},aliases:{y:"yes"}},docs:{brief:"Create a new app from the starter template",fullDescription:["Copies the simple-todo starter template, deploys to Cloudflare, and configures local development.","","Usage: every app create [name]","","The command will:"," 1. Prompt for app ID (or use provided name)"," 2. Deploy to Cloudflare (D1 database, KV namespace, Worker)"," 3. Configure wrangler.jsonc, package.json, and .env files"," 4. Install dependencies and run local migrations","","After creation, run 'pnpm run dev' to start developing."].join(`
2
+ `)}}),u=o({loader:async()=>{let{deploy:e}=await import("./deploy-6OHCTGYN.js");return e},parameters:{positional:{kind:"tuple",parameters:[]},flags:{verbose:{kind:"boolean",brief:"Show detailed output during deployment",optional:!0},yes:{kind:"boolean",brief:"Skip deployment confirmation",optional:!0}},aliases:{y:"yes"}},docs:{brief:"Deploy an app to Cloudflare",fullDescription:["Deploys the current app to Cloudflare Workers from the current directory.","The deployment process:"," 1. Reads wrangler.jsonc to determine required resources"," 2. Creates or links D1 databases and KV namespaces"," 3. Updates wrangler.jsonc with resource IDs"," 4. Installs dependencies if needed"," 5. Runs database migrations against production D1"," 6. Builds and deploys using wrangler deploy"].join(`
3
+ `)}}),c=o({loader:async()=>{let{setupLocal:e}=await import("./setupLocal-Y7ZUHJBN.js");return e},parameters:{positional:{kind:"tuple",parameters:[]},flags:{verbose:{kind:"boolean",brief:"Show detailed output during local setup",optional:!0}}},docs:{brief:"Set up local development in an existing app",fullDescription:["Configures local development for an existing Every App project in the current directory.","","Usage: every app setup-local","","The command will:"," 1. Verify the current directory is an Every App project"," 2. Verify Cloudflare and gateway setup"," 3. Install dependencies"," 4. Create or refresh .env.local"," 5. Generate Cloudflare types and run local database migrations","","This is useful after cloning an existing Every App repository."].join(`
4
+ `)}}),f=o({loader:async()=>{let{remoteD1Shell:e}=await import("./remoteD1Shell-6YR7TPHZ.js");return e},parameters:{flags:{},positional:{kind:"array",parameter:{brief:"Command and arguments to run with environment variables",parse:String}}},docs:{brief:"Run a command with Cloudflare D1 connection environment variables",fullDescription:["Sets environment variables needed to connect to remote Cloudflare D1 and runs any command that requires D1 access.","","The command will:"," 1. Get the Cloudflare account ID"," 2. Look up the database ID from the database name in wrangler.jsonc"," 3. Get a valid OAuth token"," 4. Run the provided command with CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_DATABASE_ID, CLOUDFLARE_API_TOKEN, and MIGRATE_REMOTE set","","Common use cases:"," - Running Drizzle migrations: npx everyapp app remote-d1-shell -- npx drizzle-kit migrate"," - Opening Drizzle Studio: npx everyapp app remote-d1-shell -- npx drizzle-kit studio"," - Pushing schema changes: npx everyapp app remote-d1-shell -- npx drizzle-kit push","","This command is useful for any operation that needs direct access to your production D1 database."].join(`
5
+ `)}}),n=d({routes:{create:m,deploy:u,"setup-local":c,"remote-d1-shell":f},docs:{brief:"App management commands"}});import{buildCommand as y,buildRouteMap as b}from"@stricli/core";var g=y({loader:async()=>{let{deploy:e}=await import("./deploy-5JWY65YE.js");return e},parameters:{positional:{kind:"tuple",parameters:[]},flags:{repo:{kind:"parsed",parse:String,brief:"Git repository URL to deploy",optional:!0},verbose:{kind:"boolean",brief:"Show detailed output during deployment",optional:!0},localGateway:{kind:"parsed",parse:String,brief:"Path to local gateway tarball (for testing)",optional:!0},yes:{kind:"boolean",brief:"Skip deployment confirmation",optional:!0}},aliases:{y:"yes"}},docs:{brief:"Deploy the gateway application to Cloudflare",fullDescription:["Clones the gateway repository, installs dependencies, runs migrations, and deploys to Cloudflare Workers.","The deployment process:"," 1. Clones the repository to a temporary directory"," 2. Installs npm dependencies"," 3. Runs database migrations against production D1"," 4. Runs wrangler deploy"," 5. Cleans up temporary files"].join(`
6
6
  `)}}),i=b({routes:{deploy:g},docs:{brief:"Gateway management commands"}});var D=C({routes:{app:n,gateway:i,install:v("everyapp",{bash:"__everyapp_bash_complete"}),uninstall:w("everyapp",{bash:!0})},docs:{brief:a,hideRoute:{install:!0,uninstall:!0}}}),G=h(D,{name:t,versionInfo:{currentVersion:r},scanner:{allowArgumentEscapeSequence:!0}});export{R as a,G as b};
@@ -0,0 +1,21 @@
1
+ import{a as F,e as Q}from"./chunk-ZR6E5CZN.js";import{d as q}from"./chunk-KIA3P5KV.js";import{a as _,e as W}from"./chunk-TUDP36IL.js";import{a as O,c as N,e as I,g as E,h as B,i as G,j as V,k as L,l as R,q as K,s as M}from"./chunk-JWYVVDE3.js";import{c as C}from"./chunk-APTBZ2LQ.js";import l from"chalk";async function j({appId:e,needsR2Bucket:t=!1,verbose:o=!1}){console.log(`
2
+ Setting up your Cloudflare ${t?"D1 Database, KV Store, and R2 Bucket":"D1 Database and KV Store"}...
3
+ `);let s=await I(),a=O(e),c;t&&(c=await re(a,s,o));let n=await ee(a,s,o),p=await te(a,s,o);return{d1DatabaseId:n,kvNamespaceId:p,r2BucketName:c,resourceName:a}}async function ee(e,t,o){o&&(console.log(l.bold(`Processing D1 database...
4
+ `)),console.log(` Checking D1 database: ${e}`));let r=await G(e,t);return o?r.wasCreated?console.log(l.green(` Created D1 database: ${e} (${r.id})
5
+ `)):console.log(l.dim(` Linking to existing D1 database: ${e} (${r.id})
6
+ `)):r.wasCreated?console.log(l.green(" D1 successfully created.")):console.log(" D1 already set up."),r.id}async function te(e,t,o){o&&(console.log(l.bold(`Processing KV namespace...
7
+ `)),console.log(` Checking KV namespace: ${e}`));let r=await V(e,t);return o?r.wasCreated?console.log(l.green(` Created KV namespace: ${e} (${r.id})
8
+ `)):console.log(l.dim(` Linking to existing KV namespace: ${e} (${r.id})
9
+ `)):r.wasCreated?console.log(l.green(" KV successfully created.")):console.log(" KV already set up."),r.id}async function re(e,t,o){o&&(console.log(l.bold(`Processing R2 bucket...
10
+ `)),console.log(` Checking R2 bucket: ${e}`));let r;try{r=await L(e,t)}catch(s){let a=await R(s,{accountId:t});throw a&&(console.log(a.formatted),await C(1)),s}return o?r.wasCreated?console.log(l.green(` Created R2 bucket: ${e}
11
+ `)):console.log(l.dim(` Linking to existing R2 bucket: ${e}
12
+ `)):r.wasCreated?console.log(l.green(" R2 successfully created.")):console.log(" R2 already set up."),r.name}import oe from"chalk";async function z({cwd:e,gatewayUrl:t,appId:o,verbose:r}){let s={...process.env,VITE_GATEWAY_URL:t,VITE_APP_ID:o};try{await _("npx",["vite","build"],{cwd:e,description:`Building your application...
13
+ `,env:s,verbose:r}),await _("npx",["wrangler","deploy"],{cwd:e,description:`Deploying your application to Cloudflare workers...
14
+
15
+ This could take up to a minute.`,env:s,verbose:r})}catch(a){let c=await R(a);throw c&&(console.log(c.formatted),await C(1)),console.error(oe.red(`
16
+ Failed to build or deploy`)),a}}import f from"chalk";import P from"enquirer";var se="every-app-gateway";async function k(){let e=await I(),o=(await B(e)).find(r=>r.name===se);return o?{accountId:e,databaseId:o.uuid}:null}import A from"chalk";async function m(e,t,o,r){try{let s=await N(),a={sql:o};r&&r.length>0&&(a.params=r);let c=await fetch(`https://api.cloudflare.com/client/v4/accounts/${e}/d1/database/${t}/query`,{method:"POST",headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},body:JSON.stringify(a)}),n=await c.json();if(!c.ok||!n.success){let d=n.errors?n.errors.map(u=>`[${u.code}] ${u.message}`).join(", "):c.statusText;throw console.error(A.red(`
17
+ D1 Query Error:`)),console.error(A.dim(`SQL: ${o}`)),console.error(A.dim(`Error: ${d}`)),new Error(`D1 query failed: ${d}`)}let p=n.result;if(!p||p.length===0)throw new Error("No results returned from D1 query");let g=p[0];if(!g)throw new Error("First result is undefined");return g.results}catch(s){throw s instanceof Error&&!s.message.includes("D1 query failed")&&(console.error(A.red(`
18
+ D1 Query Error:`)),console.error(A.dim(`SQL: ${o}`))),s}}async function v(e){return m(e.accountId,e.databaseId,"SELECT id, name, email, role FROM users")}import{randomUUID as H}from"node:crypto";async function h(e,t){return(await m(e.accountId,e.databaseId,"SELECT id, dev_url, is_default FROM apps WHERE app_id = ?",[t]))[0]??null}async function x(e,t){let o=await h(e,t.appId),r=Date.now(),s=t.isDefault??!!(o?.is_default??0);if(o){let c=t.devUrl??o.dev_url??null;return await m(e.accountId,e.databaseId,"UPDATE apps SET name = ?, description = ?, app_url = ?, dev_url = ?, is_default = ?, updated_at = ? WHERE id = ?",[t.name,t.description,t.appUrl,c,s?1:0,r,o.id]),o.id}let a=H();return await m(e.accountId,e.databaseId,"INSERT INTO apps (id, app_id, name, description, app_url, dev_url, is_default, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",[a,t.appId,t.name,t.description,t.appUrl,t.devUrl??null,s?1:0,r,r]),a}async function ae(e,t,o){return(await m(e.accountId,e.databaseId,"SELECT id FROM user_app_access WHERE user_id = ? AND app_id = ?",[t,o])).length>0}async function $(e,t,o){if(await ae(e,t,o))return{created:!1};let s=Date.now(),a=H();return await m(e.accountId,e.databaseId,"INSERT INTO user_app_access (id, user_id, app_id, granted_at, granted_by) VALUES (?, ?, ?, ?, ?)",[a,t,o,s,null]),{created:!0}}async function Y(e){let{appId:t,appUrl:o,verbose:r=!1,appName:s,appDescription:a,devUrl:c}=e;try{console.log(""),r&&console.log("Adding apps to user gateways...");let n=await k();if(!n){console.warn(f.yellow(`every-app-gateway database not found. Skipping UserApp record creation.
19
+ `));return}let p=await v(n),g=p.filter(i=>i.role==="owner"),d=p.filter(i=>i.role!=="owner"),u=await h(n,t),y=u===null,U=s||t,J=a||t;!y&&r&&console.log(f.dim("App already configured in gateway. Skipping access prompts."));let T=y?await ie("Add future users by default to this app?"):!!u?.is_default,D=y?d.length===0?"owner-only":await ce():"none",w=g.map(i=>i.id);if(d.length===0&&D==="select")throw new Error("No users found in the database to select from. Please create a user first.");D==="all"?w=g.map(i=>i.id).concat(d.map(i=>i.id)):D==="select"&&(w=w.concat(await le(d))),w=Array.from(new Set(w));let X=await x(n,{appId:t,appUrl:o,name:U,description:J,devUrl:c,isDefault:T}),b=p.filter(i=>w.includes(i.id));r&&b.length>1&&console.log(f.yellow(`Adding app to ${b.length} user(s)...
20
+ `));for(let i of b)await ne(n,i,{appRecordId:X,verbose:r});if(r){let i=g.length,S=b.length-i,Z=b.length===0?"no users":D==="all"?"all users":D==="select"?i>0?`${S} selected users + owner`:`${S} selected users`:i>1?"owner users":"owner user";console.log(f.dim(` Default access: ${T?"enabled":"disabled"}`)),console.log(f.dim(` Access granted to ${Z}
21
+ `))}}catch(n){throw console.error(f.red("Failed to insert UserApp records:"),n instanceof Error?n.message:n),n}}async function ne(e,t,o){let{verbose:r,appRecordId:s}=o;(await $(e,t.id,s)).created?console.log(` UserApp record created for user ${t.name} (${t.email})`):r&&console.log(f.dim(` UserApp record already exists for user ${t.name} (${t.email})`))}async function ie(e){let{confirm:t}=await P.prompt({type:"confirm",name:"confirm",message:e,initial:!0});return t}async function ce(){let{mode:e}=await P.prompt({type:"select",name:"mode",message:"Add existing users now?",choices:[{name:"all",message:"All users"},{name:"select",message:"Select users"},{name:"none",message:"None"}],initial:0});return e}async function le(e){let{selected:t}=await P.prompt({type:"multiselect",name:"selected",message:"Select users to grant access",choices:e.map(o=>({name:o.id,message:pe(o)}))});return t}function pe(e){return e.name&&e.name.trim()?`${e.name} <${e.email}>`:e.email}async function je(e){let{cwd:t,appId:o,verbose:r,devUrl:s}=e,c=!!(await M(t)).r2_buckets?.length,{d1DatabaseId:n,kvNamespaceId:p,r2BucketName:g,resourceName:d}=await j({appId:o,needsR2Bucket:c,verbose:r});await K({configPath:t,name:d,d1DatabaseId:n,d1DatabaseName:d,kvNamespaceId:p,r2BucketName:g,verbose:r});let u=await E("every-app-gateway");console.log(),await W({cwd:t,description:"Installing dependencies for Cloudflare deployment...",verbose:r}),await q({cwd:t,verbose:r}),await z({cwd:t,gatewayUrl:u,appId:o,verbose:r});let y=await E(d),U=await F(t);return await Y({appId:o,appUrl:y,verbose:r,appName:U.displayName,appDescription:U.description,devUrl:s}),await Q({gatewayUrl:u,appPath:t,appId:o,verbose:r}),{workerUrl:y,gatewayUrl:u}}export{je as a};
@@ -1,4 +1,4 @@
1
- import{d as u,e as m,g as x,r as k}from"./chunk-4AODVGRU.js";import{c as f}from"./chunk-ASNYTFJJ.js";import p from"chalk";var C="every-app-gateway";async function G(t){try{return await fetch(t,{method:"HEAD",signal:AbortSignal.timeout(5e3)}),!0}catch(e){let o=e instanceof Error?e.message.toLowerCase():"",n=e instanceof Error&&"cause"in e&&e.cause?.code?.toLowerCase()||"";return!["ssl","tls","certificate","cert","cipher","handshake","secure"].some(a=>o.includes(a)||n.includes(a))}}async function E(t){try{let e=await fetch(`${t}/api/admin/has-owner`);return e.ok?(await e.json()).hasOwner:!1}catch{return!1}}async function O(){try{let t=await m();return await u(`/accounts/${t}/workers/scripts/${C}/settings`),!0}catch{return!1}}async function S(){return x(C)}async function $(){if(!await O())return{isDeployed:!1,hasOwner:!1,gatewayUrl:await S()};let e=await S();return{isDeployed:!0,hasOwner:await E(e),gatewayUrl:e}}async function A(){let{isDeployed:t,hasOwner:e,gatewayUrl:o}=await $();if(t||(console.log(p.yellow(`
1
+ import{d as u,e as m,g as x,r as k}from"./chunk-JWYVVDE3.js";import{c as f}from"./chunk-APTBZ2LQ.js";import p from"chalk";var C="every-app-gateway";async function G(t){try{return await fetch(t,{method:"HEAD",signal:AbortSignal.timeout(5e3)}),!0}catch(e){let o=e instanceof Error?e.message.toLowerCase():"",n=e instanceof Error&&"cause"in e&&e.cause?.code?.toLowerCase()||"";return!["ssl","tls","certificate","cert","cipher","handshake","secure"].some(a=>o.includes(a)||n.includes(a))}}async function E(t){try{let e=await fetch(`${t}/api/admin/has-owner`);return e.ok?(await e.json()).hasOwner:!1}catch{return!1}}async function O(){try{let t=await m();return await u(`/accounts/${t}/workers/scripts/${C}/settings`),!0}catch{return!1}}async function S(){return x(C)}async function $(){if(!await O())return{isDeployed:!1,hasOwner:!1,gatewayUrl:await S()};let e=await S();return{isDeployed:!0,hasOwner:await E(e),gatewayUrl:e}}async function A(){let{isDeployed:t,hasOwner:e,gatewayUrl:o}=await $();if(t||(console.log(p.yellow(`
2
2
  Gateway not deployed
3
3
  `)),console.log(`You need to deploy the Every App Gateway before creating or deploying apps.
4
4
  `),console.log(p.dim(` Run: npx everyapp gateway deploy
@@ -1 +1 @@
1
- var p="everyapp";var i="Every App CLI - Deploy and manage apps.";var n="0.1.7";export{p as a,i as b,n as c};
1
+ var p="everyapp";var i="Every App CLI - Deploy and manage apps.";var n="0.1.8";export{p as a,i as b,n as c};
@@ -1,4 +1,4 @@
1
- import{g as p}from"./chunk-4AODVGRU.js";import r from"node:fs/promises";import c from"node:path";import f from"node:os";import m from"chalk";async function u(e,t,o={}){let n=o.exclude||[];await r.mkdir(t,{recursive:!0});let a=await r.readdir(e,{withFileTypes:!0});for(let i of a){let s=c.join(e,i.name),l=c.join(t,i.name);n.some(y=>i.name===y)||(i.isDirectory()?await u(s,l,o):await r.copyFile(s,l))}}async function T(e){try{return(await r.stat(e)).isDirectory()}catch{return!1}}async function D({targetDir:e,appId:t,gatewayUrl:o,gatewayAppApiToken:n}){let a=o??await p("every-app-gateway"),i=n?`GATEWAY_APP_API_TOKEN=${n}
1
+ import{g as p}from"./chunk-JWYVVDE3.js";import r from"node:fs/promises";import c from"node:path";import f from"node:os";import m from"chalk";async function u(e,t,o={}){let n=o.exclude||[];await r.mkdir(t,{recursive:!0});let a=await r.readdir(e,{withFileTypes:!0});for(let i of a){let s=c.join(e,i.name),l=c.join(t,i.name);n.some(y=>i.name===y)||(i.isDirectory()?await u(s,l,o):await r.copyFile(s,l))}}async function T(e){try{return(await r.stat(e)).isDirectory()}catch{return!1}}async function D({targetDir:e,appId:t,gatewayUrl:o,gatewayAppApiToken:n}){let a=o??await p("every-app-gateway"),i=n?`GATEWAY_APP_API_TOKEN=${n}
2
2
  `:"",s=`# Vite client-side secrets
3
3
  VITE_APP_ID=${t}
4
4
  VITE_GATEWAY_URL=${a}
@@ -1,4 +1,4 @@
1
- import{g as p,h as c}from"./chunk-EOQC6VQV.js";import{c as f}from"./chunk-4AODVGRU.js";import u from"node:fs/promises";import y from"node:path";import*as l from"jsonc-parser";import{z as s}from"zod";var d="every-app.jsonc",A=s.object({appId:s.string().min(1,"appId cannot be empty"),displayName:s.string().min(1,"displayName cannot be empty").optional(),description:s.string().optional()});async function h(e){let n=y.join(e,d);try{let o=await u.readFile(n,"utf-8"),t=l.parse(o);return A.parse(t)}catch(o){if(o instanceof Error&&"code"in o&&o.code==="ENOENT")throw new Error("every-app.jsonc not found. Make sure you're running this command from an Every App project directory.");if(o instanceof s.ZodError){let t=o.issues.map(r=>r.message).join(", ");throw new Error(`Invalid every-app.jsonc: ${t}`)}throw o}}function T(e){return e.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" ")}async function I(e,n){let o=y.join(e,d),t={...n,displayName:n.displayName??T(n.appId)},r=JSON.stringify(t,null,2)+`
1
+ import{g as p,h as c}from"./chunk-TUDP36IL.js";import{c as f}from"./chunk-JWYVVDE3.js";import u from"node:fs/promises";import y from"node:path";import*as l from"jsonc-parser";import{z as s}from"zod";var d="every-app.jsonc",A=s.object({appId:s.string().min(1,"appId cannot be empty"),displayName:s.string().min(1,"displayName cannot be empty").optional(),description:s.string().optional()});async function h(e){let n=y.join(e,d);try{let o=await u.readFile(n,"utf-8"),t=l.parse(o);return A.parse(t)}catch(o){if(o instanceof Error&&"code"in o&&o.code==="ENOENT")throw new Error("every-app.jsonc not found. Make sure you're running this command from an Every App project directory.");if(o instanceof s.ZodError){let t=o.issues.map(r=>r.message).join(", ");throw new Error(`Invalid every-app.jsonc: ${t}`)}throw o}}function T(e){return e.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" ")}async function I(e,n){let o=y.join(e,d),t={...n,displayName:n.displayName??T(n.appId)},r=JSON.stringify(t,null,2)+`
2
2
  `;await u.writeFile(o,r)}async function O(e){return(await h(e)).appId}var w="GATEWAY_URL",E="GATEWAY_APP_API_TOKEN",N="/api/internal/app-token/provision",P=["provider:openai"];function k(e){if(!e.trim())return null;try{return JSON.parse(e)}catch{return null}}function m(e){if(!e||typeof e!="object")return null;let n=e.error;return typeof n!="string"||!n.trim()?null:n}async function v({gatewayUrl:e,appId:n}){let o=await f(),t=await fetch(`${e}${N}`,{method:"POST",headers:{authorization:`Bearer ${o}`,"content-type":"application/json"},body:JSON.stringify({appSlug:n,scopes:P})}),r=await t.text(),a=k(r);if(!t.ok){let g=m(a)||`Gateway token provisioning failed with status ${t.status}`;throw t.status===401||t.status===403?new Error(`${g}. Ensure your Cloudflare credentials target the same account that hosts this gateway.`):t.status===404?new Error("Gateway does not support token provisioning yet. Redeploy the gateway with `npx everyapp gateway deploy` and try again."):t.status===409?new Error(`${m(a)||"Gateway rejected token provisioning with a conflict"}. If this gateway is outdated, run \`npx everyapp gateway deploy\` and try again.`):new Error(g)}let i=a?.token;if(typeof i!="string"||!i.trim())throw new Error("Gateway returned an invalid token provisioning response");return i}async function R({gatewayUrl:e,appPath:n,appId:o,verbose:t=!1}){t&&console.log("Configuring Secrets...");try{if(await p({secretName:w,cwd:n,verbose:t})||await c({secretName:w,secretValue:e,cwd:n,verbose:t,description:`Setting GATEWAY_URL to: ${e}`}),!await p({secretName:E,cwd:n,verbose:t})){t&&console.log("Provisioning gateway app API token...");let i=await v({gatewayUrl:e,appId:o});await c({secretName:E,secretValue:i,cwd:n,verbose:t,description:"Setting GATEWAY_APP_API_TOKEN for gateway requests"})}t&&console.log(`Secret setup complete!
3
3
  `)}catch(r){throw console.error(`
4
4
  Failed to setup secrets`,r instanceof Error?`
@@ -1 +1 @@
1
- import{c as d,e as c,h as f,s as D}from"./chunk-4AODVGRU.js";import{execa as g}from"execa";async function m(s){let e=await D(s);if(!e.d1_databases||e.d1_databases.length===0)throw new Error("No D1 databases found in wrangler.jsonc. Please add a D1 database configuration.");let n=e.d1_databases[0];if(!n)throw new Error("No D1 database configuration found in wrangler.jsonc.");let a=n.database_name;if(!a)throw new Error("No database_name found in D1 database configuration in wrangler.jsonc.");let[t,r]=await Promise.all([c(),d()]),o=(await f(t)).find(u=>u.name===a);if(!o)throw new Error(`Database "${a}" not found in your Cloudflare account. Have you run deployment to create the database?`);return{CLOUDFLARE_ACCOUNT_ID:t,CLOUDFLARE_DATABASE_ID:o.uuid,CLOUDFLARE_API_TOKEN:r}}async function w(s,e,n){let{cwd:a,env:t={},verbose:r=!1}=n,i=await m(a),o={cwd:a,stdio:r?"inherit":"pipe",env:{...process.env,...t,...i}};await g(s,e,o)}export{m as a,w as b};
1
+ import{c as d,e as c,h as f,s as D}from"./chunk-JWYVVDE3.js";import{execa as g}from"execa";async function m(s){let e=await D(s);if(!e.d1_databases||e.d1_databases.length===0)throw new Error("No D1 databases found in wrangler.jsonc. Please add a D1 database configuration.");let n=e.d1_databases[0];if(!n)throw new Error("No D1 database configuration found in wrangler.jsonc.");let a=n.database_name;if(!a)throw new Error("No database_name found in D1 database configuration in wrangler.jsonc.");let[t,r]=await Promise.all([c(),d()]),o=(await f(t)).find(u=>u.name===a);if(!o)throw new Error(`Database "${a}" not found in your Cloudflare account. Have you run deployment to create the database?`);return{CLOUDFLARE_ACCOUNT_ID:t,CLOUDFLARE_DATABASE_ID:o.uuid,CLOUDFLARE_API_TOKEN:r}}async function w(s,e,n){let{cwd:a,env:t={},verbose:r=!1}=n,i=await m(a),o={cwd:a,stdio:r?"inherit":"pipe",env:{...process.env,...t,...i}};await g(s,e,o)}export{m as a,w as b};
@@ -1,4 +1,4 @@
1
- import{a as b}from"./chunk-AIRNFEUQ.js";import{a as x}from"./chunk-3DCJZ6LU.js";import{b as v,d as P}from"./chunk-FFEUD43M.js";import{a as k}from"./chunk-QHXECEAW.js";import{a as y,b as w,d as u,e as h}from"./chunk-VYHFMMFQ.js";import{a as s,d as C}from"./chunk-EOQC6VQV.js";import"./chunk-QKHNAJYY.js";import{b as g}from"./chunk-4AODVGRU.js";import{c as l}from"./chunk-ASNYTFJJ.js";import"./chunk-JOHMESCX.js";import f from"chalk";async function A({url:o,targetDir:e,verbose:t=!1}){try{await s("git",["clone",o,e],{verbose:t,logCommandToConsole:!1})}catch(a){throw new Error(`Failed to clone repository from ${o}: ${a instanceof Error?a.message:"Unknown error"}`)}}async function T({targetDir:o,verbose:e=!1}){try{await s("git",["init"],{verbose:e,logCommandToConsole:!1,cwd:o}),await s("git",["add","."],{verbose:e,logCommandToConsole:!1,cwd:o}),await s("git",["commit","-m","Starter template"],{verbose:e,logCommandToConsole:!1,cwd:o})}catch(t){throw new Error(`Failed to initialize git repository: ${t instanceof Error?t.message:"Unknown error"}`)}}import J from"node:fs/promises";import L from"node:path";import d from"chalk";var G=["every-app.jsonc","every-app.json"];async function D(){let o=process.cwd();for(let e of G){let t=L.join(o,e);try{await J.access(t),console.log(d.yellow(`
1
+ import{a as b}from"./chunk-RHADZBGF.js";import{a as x}from"./chunk-BFYVBU6B.js";import{b as v,d as P}from"./chunk-ZR6E5CZN.js";import{a as k}from"./chunk-KIA3P5KV.js";import{a as y,b as w,d as u,e as h}from"./chunk-XKKQYCSJ.js";import{a as s,d as C}from"./chunk-TUDP36IL.js";import"./chunk-ZWRZQCN2.js";import{b as g}from"./chunk-JWYVVDE3.js";import{c as l}from"./chunk-APTBZ2LQ.js";import"./chunk-VOYWQ73B.js";import f from"chalk";async function A({url:o,targetDir:e,verbose:t=!1}){try{await s("git",["clone",o,e],{verbose:t,logCommandToConsole:!1})}catch(a){throw new Error(`Failed to clone repository from ${o}: ${a instanceof Error?a.message:"Unknown error"}`)}}async function T({targetDir:o,verbose:e=!1}){try{await s("git",["init"],{verbose:e,logCommandToConsole:!1,cwd:o}),await s("git",["add","."],{verbose:e,logCommandToConsole:!1,cwd:o}),await s("git",["commit","-m","Starter template"],{verbose:e,logCommandToConsole:!1,cwd:o})}catch(t){throw new Error(`Failed to initialize git repository: ${t instanceof Error?t.message:"Unknown error"}`)}}import J from"node:fs/promises";import L from"node:path";import d from"chalk";var G=["every-app.jsonc","every-app.json"];async function D(){let o=process.cwd();for(let e of G){let t=L.join(o,e);try{await J.access(t),console.log(d.yellow(`
2
2
  Already inside an Every App project`)),console.log(d.dim(` Found ${e}
3
3
  `)),console.log(`To create a new app, run app create from the directory where you store your projects.
4
4
  `),console.log("If you meant to deploy this app, run:"),console.log(d.dim(` npx everyapp app deploy
@@ -1,4 +1,4 @@
1
- import{a as W,b as h,c as S,d as P}from"./chunk-QHXECEAW.js";import{d as U,e as L}from"./chunk-VYHFMMFQ.js";import{a as G,b as y,c as E,e as $,f as I,h as m}from"./chunk-EOQC6VQV.js";import"./chunk-QKHNAJYY.js";import{b as A,e as R,g as _,i as b,j as k,l as D,p as x,q as v,r as K}from"./chunk-4AODVGRU.js";import{c as T}from"./chunk-ASNYTFJJ.js";import"./chunk-JOHMESCX.js";import g from"chalk";import de from"node:path";import d from"chalk";var j="every-app-gateway",q="every-app-gateway";async function O({verbose:e=!1}={}){console.log(`
1
+ import{a as W,b as h,c as S,d as P}from"./chunk-KIA3P5KV.js";import{d as U,e as L}from"./chunk-XKKQYCSJ.js";import{a as G,b as y,c as E,e as $,f as I,h as m}from"./chunk-TUDP36IL.js";import"./chunk-ZWRZQCN2.js";import{b as A,e as R,g as _,i as b,j as k,l as D,p as x,q as v,r as K}from"./chunk-JWYVVDE3.js";import{c as T}from"./chunk-APTBZ2LQ.js";import"./chunk-VOYWQ73B.js";import g from"chalk";import de from"node:path";import d from"chalk";var j="every-app-gateway",q="every-app-gateway";async function O({verbose:e=!1}={}){console.log(`
2
2
  Setting up your Cloudflare D1 Database and KV Store...
3
3
  `);let o=await R(),a=await Q(j,o,e),t=await X(q,o,e);return console.log(),{d1DatabaseId:a,kvNamespaceId:t,accountId:o}}async function Q(e,o,a){a&&console.log(` Checking D1 database: ${e}`);let t=await b(e,o);return a?t.wasCreated?console.log(d.green(` Created D1 database: ${e} (${t.id})
4
4
  `)):console.log(d.dim(` Linking to existing D1 database: ${e} (${t.id})
@@ -1,4 +1,4 @@
1
- import{a as p}from"./chunk-AIRNFEUQ.js";import{a as s}from"./chunk-7IPT3FRI.js";import{c}from"./chunk-FFEUD43M.js";import{a}from"./chunk-QHXECEAW.js";import{d as l}from"./chunk-EOQC6VQV.js";import"./chunk-QKHNAJYY.js";import{b as n}from"./chunk-4AODVGRU.js";import"./chunk-ASNYTFJJ.js";import"./chunk-JOHMESCX.js";import o from"chalk";async function A(e){await n(),await l();let t=process.cwd(),i=e.verbose||!1,m=e.yes||!1;await s();let r=await c(t);if(console.log(o.bold(`
1
+ import{a as p}from"./chunk-RHADZBGF.js";import{a as s}from"./chunk-BEO4F5X6.js";import{c}from"./chunk-ZR6E5CZN.js";import{a}from"./chunk-KIA3P5KV.js";import{d as l}from"./chunk-TUDP36IL.js";import"./chunk-ZWRZQCN2.js";import{b as n}from"./chunk-JWYVVDE3.js";import"./chunk-APTBZ2LQ.js";import"./chunk-VOYWQ73B.js";import o from"chalk";async function A(e){await n(),await l();let t=process.cwd(),i=e.verbose||!1,m=e.yes||!1;await s();let r=await c(t);if(console.log(o.bold(`
2
2
  Project: ${r}
3
3
  `)),!await a("this app",m)){console.log(o.red(`
4
4
  Deployment cancelled by user
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{a as i,b as t}from"./chunk-YRO4PVS3.js";import{a as r,b as o}from"./chunk-ASNYTFJJ.js";import"./chunk-JOHMESCX.js";import{run as e}from"@stricli/core";r();await e(t,process.argv.slice(2),i(process));await o();
2
+ import{a as i,b as t}from"./chunk-OYJHDLMN.js";import{a as r,b as o}from"./chunk-APTBZ2LQ.js";import"./chunk-VOYWQ73B.js";import{run as e}from"@stricli/core";r();await e(t,process.argv.slice(2),i(process));await o();
@@ -1,4 +1,4 @@
1
- import{a}from"./chunk-QKHNAJYY.js";import{b as i}from"./chunk-4AODVGRU.js";import"./chunk-ASNYTFJJ.js";import"./chunk-JOHMESCX.js";import r from"chalk";import{execa as l}from"execa";async function g(m,...o){await i();let n=process.cwd();try{if(!o||o.length===0)throw new Error(`No command provided. Usage: npx everyapp app remote-d1-shell -- <command>
1
+ import{a}from"./chunk-ZWRZQCN2.js";import{b as i}from"./chunk-JWYVVDE3.js";import"./chunk-APTBZ2LQ.js";import"./chunk-VOYWQ73B.js";import r from"chalk";import{execa as l}from"execa";async function g(m,...o){await i();let n=process.cwd();try{if(!o||o.length===0)throw new Error(`No command provided. Usage: npx everyapp app remote-d1-shell -- <command>
2
2
  Example: npx everyapp app remote-d1-shell -- npx drizzle-kit migrate`);let[e,...t]=o;if(!e)throw new Error("Invalid command");console.log("Retrieving shell info from Cloudflare...");let c=await a(n);console.log(r.bold(`
3
3
  Running: ${r.cyan([e,...t].join(" "))}
4
4
  `)),await l(e,t,{cwd:n,stdio:"inherit",env:{...process.env,...c}}),console.log(`
@@ -1,4 +1,4 @@
1
- import{a as l}from"./chunk-3DCJZ6LU.js";import{a as c}from"./chunk-7IPT3FRI.js";import{c as p,d as i}from"./chunk-FFEUD43M.js";import"./chunk-VYHFMMFQ.js";import{d as r}from"./chunk-EOQC6VQV.js";import{b as n}from"./chunk-4AODVGRU.js";import"./chunk-ASNYTFJJ.js";import"./chunk-JOHMESCX.js";import o from"chalk";async function L(s){let t=process.cwd(),m=s.verbose||!1;await c(),await n();let a=await r(),e=await p(t),u=await i({gatewayUrl:a,appId:e});console.log(o.bold(`
1
+ import{a as l}from"./chunk-BFYVBU6B.js";import{a as c}from"./chunk-BEO4F5X6.js";import{c as p,d as i}from"./chunk-ZR6E5CZN.js";import"./chunk-XKKQYCSJ.js";import{d as r}from"./chunk-TUDP36IL.js";import{b as n}from"./chunk-JWYVVDE3.js";import"./chunk-APTBZ2LQ.js";import"./chunk-VOYWQ73B.js";import o from"chalk";async function L(s){let t=process.cwd(),m=s.verbose||!1;await c(),await n();let a=await r(),e=await p(t),u=await i({gatewayUrl:a,appId:e});console.log(o.bold(`
2
2
  Setting up local environment for ${e}
3
3
  `)),await l({targetDir:t,appId:e,gatewayUrl:a,gatewayAppApiToken:u,verbose:m,installDeps:!0}),console.log(o.green(`Local setup complete!
4
4
  `)),console.log(`Run the app locally:
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "description": "Every App CLI - Deploy and manage apps.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "version": "0.1.7",
7
+ "version": "0.1.8",
8
8
  "files": [
9
9
  "dist"
10
10
  ],
@@ -1,21 +0,0 @@
1
- import{a as V,e as q}from"./chunk-FFEUD43M.js";import{d as K}from"./chunk-QHXECEAW.js";import{a as _,e as L}from"./chunk-EOQC6VQV.js";import{a as T,c as S,e as C,g as E,h as N,i as O,j as B,k as G,l as I,q as F,s as W}from"./chunk-4AODVGRU.js";import{c as U}from"./chunk-ASNYTFJJ.js";import l from"chalk";async function M({appId:e,needsR2Bucket:t=!1,verbose:a=!1}){console.log(`
2
- Setting up your Cloudflare ${t?"D1 Database, KV Store, and R2 Bucket":"D1 Database and KV Store"}...
3
- `);let o=await C(),s=T(e),i;t&&(i=await X(s,o,a));let n=await Y(s,o,a),c=await J(s,o,a);return{d1DatabaseId:n,kvNamespaceId:c,r2BucketName:i,resourceName:s}}async function Y(e,t,a){a&&(console.log(l.bold(`Processing D1 database...
4
- `)),console.log(` Checking D1 database: ${e}`));let r=await O(e,t);return a?r.wasCreated?console.log(l.green(` Created D1 database: ${e} (${r.id})
5
- `)):console.log(l.dim(` Linking to existing D1 database: ${e} (${r.id})
6
- `)):r.wasCreated?console.log(l.green(" D1 successfully created.")):console.log(" D1 already set up."),r.id}async function J(e,t,a){a&&(console.log(l.bold(`Processing KV namespace...
7
- `)),console.log(` Checking KV namespace: ${e}`));let r=await B(e,t);return a?r.wasCreated?console.log(l.green(` Created KV namespace: ${e} (${r.id})
8
- `)):console.log(l.dim(` Linking to existing KV namespace: ${e} (${r.id})
9
- `)):r.wasCreated?console.log(l.green(" KV successfully created.")):console.log(" KV already set up."),r.id}async function X(e,t,a){a&&(console.log(l.bold(`Processing R2 bucket...
10
- `)),console.log(` Checking R2 bucket: ${e}`));let r;try{r=await G(e,t)}catch(o){let s=await I(o,{accountId:t});throw s&&(console.log(s.formatted),await U(1)),o}return a?r.wasCreated?console.log(l.green(` Created R2 bucket: ${e}
11
- `)):console.log(l.dim(` Linking to existing R2 bucket: ${e}
12
- `)):r.wasCreated?console.log(l.green(" R2 successfully created.")):console.log(" R2 already set up."),r.name}import Z from"chalk";async function Q({cwd:e,gatewayUrl:t,appId:a,verbose:r}){let o={...process.env,VITE_GATEWAY_URL:t,VITE_APP_ID:a};try{await _("npx",["vite","build"],{cwd:e,description:`Building your application...
13
- `,env:o,verbose:r}),await _("npx",["wrangler","deploy"],{cwd:e,description:`Deploying your application to Cloudflare workers...
14
-
15
- This could take up to a minute.`,env:o,verbose:r})}catch(s){let i=await I(s);throw i&&(console.log(i.formatted),await U(1)),console.error(Z.red(`
16
- Failed to build or deploy`)),s}}import f from"chalk";import P from"enquirer";var ee="every-app-gateway";async function k(){let e=await C(),a=(await N(e)).find(r=>r.name===ee);return a?{accountId:e,databaseId:a.uuid}:null}import D from"chalk";async function u(e,t,a,r){try{let o=await S(),s={sql:a};r&&r.length>0&&(s.params=r);let i=await fetch(`https://api.cloudflare.com/client/v4/accounts/${e}/d1/database/${t}/query`,{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify(s)}),n=await i.json();if(!i.ok||!n.success){let p=n.errors?n.errors.map(d=>`[${d.code}] ${d.message}`).join(", "):i.statusText;throw console.error(D.red(`
17
- D1 Query Error:`)),console.error(D.dim(`SQL: ${a}`)),console.error(D.dim(`Error: ${p}`)),new Error(`D1 query failed: ${p}`)}let c=n.result;if(!c||c.length===0)throw new Error("No results returned from D1 query");let g=c[0];if(!g)throw new Error("First result is undefined");return g.results}catch(o){throw o instanceof Error&&!o.message.includes("D1 query failed")&&(console.error(D.red(`
18
- D1 Query Error:`)),console.error(D.dim(`SQL: ${a}`))),o}}async function v(e){return u(e.accountId,e.databaseId,"SELECT id, name, email FROM users")}import{randomUUID as j}from"node:crypto";async function R(e,t){return(await u(e.accountId,e.databaseId,"SELECT id, dev_url, is_default FROM apps WHERE app_id = ?",[t]))[0]??null}async function x(e,t){let a=await R(e,t.appId),r=Date.now(),o=t.isDefault??!!(a?.is_default??0);if(a){let i=t.devUrl??a.dev_url??null;return await u(e.accountId,e.databaseId,"UPDATE apps SET name = ?, description = ?, app_url = ?, dev_url = ?, is_default = ?, updated_at = ? WHERE id = ?",[t.name,t.description,t.appUrl,i,o?1:0,r,a.id]),a.id}let s=j();return await u(e.accountId,e.databaseId,"INSERT INTO apps (id, app_id, name, description, app_url, dev_url, is_default, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",[s,t.appId,t.name,t.description,t.appUrl,t.devUrl??null,o?1:0,r,r]),s}async function te(e,t,a){return(await u(e.accountId,e.databaseId,"SELECT id FROM user_app_access WHERE user_id = ? AND app_id = ?",[t,a])).length>0}async function $(e,t,a){if(await te(e,t,a))return{created:!1};let o=Date.now(),s=j();return await u(e.accountId,e.databaseId,"INSERT INTO user_app_access (id, user_id, app_id, granted_at, granted_by) VALUES (?, ?, ?, ?, ?)",[s,t,a,o,null]),{created:!0}}async function z(e){let{appId:t,appUrl:a,verbose:r=!1,appName:o,appDescription:s,devUrl:i}=e;try{console.log(""),r&&console.log("Adding apps to user gateways...");let n=await k();if(!n){console.warn(f.yellow(`every-app-gateway database not found. Skipping UserApp record creation.
19
- `));return}let c=await v(n),g=await R(n,t),p=g===null,d=o||t,b=s||t;!p&&r&&console.log(f.dim("App already configured in gateway. Skipping access prompts."));let y=p?await ae("Add future users by default to this app?"):!!g?.is_default,w=p?await oe():"none",h=[];if(c.length===0&&w==="select")throw new Error("No users found in the database to select from. Please create a user first.");w==="all"?h=c.map(m=>m.id):w==="select"&&(h=await se(c));let H=await x(n,{appId:t,appUrl:a,name:d,description:b,devUrl:i,isDefault:y}),A=c.filter(m=>h.includes(m.id));r&&A.length>1&&console.log(f.yellow(`Adding app to ${A.length} user(s)...
20
- `));for(let m of A)await re(n,m,{appRecordId:H,verbose:r});if(r){let m=w==="all"?"all users":w==="select"?`${A.length} selected users`:"no users";console.log(f.dim(` Default access: ${y?"enabled":"disabled"}`)),console.log(f.dim(` Access granted to ${m}
21
- `))}}catch(n){throw console.error(f.red("Failed to insert UserApp records:"),n instanceof Error?n.message:n),n}}async function re(e,t,a){let{verbose:r,appRecordId:o}=a;(await $(e,t.id,o)).created?console.log(` UserApp record created for user ${t.name} (${t.email})`):r&&console.log(f.dim(` UserApp record already exists for user ${t.name} (${t.email})`))}async function ae(e){let{confirm:t}=await P.prompt({type:"confirm",name:"confirm",message:e,initial:!0});return t}async function oe(){let{mode:e}=await P.prompt({type:"select",name:"mode",message:"Add existing users now?",choices:[{name:"all",message:"All users"},{name:"select",message:"Select users"},{name:"none",message:"None"}],initial:0});return e}async function se(e){let{selected:t}=await P.prompt({type:"multiselect",name:"selected",message:"Select users to grant access",choices:e.map(a=>({name:a.id,message:ne(a)}))});return t}function ne(e){return e.name&&e.name.trim()?`${e.name} <${e.email}>`:e.email}async function Ke(e){let{cwd:t,appId:a,verbose:r,devUrl:o}=e,i=!!(await W(t)).r2_buckets?.length,{d1DatabaseId:n,kvNamespaceId:c,r2BucketName:g,resourceName:p}=await M({appId:a,needsR2Bucket:i,verbose:r});await F({configPath:t,name:p,d1DatabaseId:n,d1DatabaseName:p,kvNamespaceId:c,r2BucketName:g,verbose:r});let d=await E("every-app-gateway");console.log(),await L({cwd:t,description:"Installing dependencies for Cloudflare deployment...",verbose:r}),await K({cwd:t,verbose:r}),await Q({cwd:t,gatewayUrl:d,appId:a,verbose:r});let b=await E(p),y=await V(t);return await z({appId:a,appUrl:b,verbose:r,appName:y.displayName,appDescription:y.description,devUrl:o}),await q({gatewayUrl:d,appPath:t,appId:a,verbose:r}),{workerUrl:b,gatewayUrl:d}}export{Ke as a};