@every-app/cli 0.0.29 → 0.0.30

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-L2AU5B4R.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-QSBOPBPF.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{}
@@ -0,0 +1,28 @@
1
+ import{b as g,g as O,h as _,i as G}from"./chunk-XJKWPT3C.js";import{a as R,c as x,e as w,g as A,h as k,i as P,j as $,k as S,l as b,q as T,s as N}from"./chunk-GSJPLB2P.js";import V from"node:fs/promises";import j from"node:path";import*as B from"jsonc-parser";import{z as f}from"zod";var F="every-app.jsonc",Q=f.object({appId:f.string().min(1,"appId cannot be empty"),displayName:f.string().min(1,"displayName cannot be empty").optional(),description:f.string().optional()});async function C(t){let o=j.join(t,F);try{let e=await V.readFile(o,"utf-8"),r=B.parse(e);return Q.parse(r)}catch(e){if(e instanceof Error&&"code"in e&&e.code==="ENOENT")throw new Error("every-app.jsonc not found. Make sure you're running this command from an Every App project directory.");if(e instanceof f.ZodError){let r=e.issues.map(n=>n.message).join(", ");throw new Error(`Invalid every-app.jsonc: ${r}`)}throw e}}function z(t){return t.split("-").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" ")}async function pe(t,o){let e=j.join(t,F),r={...o,displayName:o.displayName??z(o.appId)},n=JSON.stringify(r,null,2)+`
2
+ `;await V.writeFile(e,n)}async function ce(t){return(await C(t)).appId}import{execa as Y}from"execa";async function J(){try{return await Y("pnpm",["--version"],{stdio:"pipe"}),!0}catch{return!1}}async function L({cwd:t,description:o,verbose:e=!1}){let r=await J();try{r?await g("pnpm",["install"],{cwd:t,verbose:e,description:o}):await g("npx",["pnpm","install"],{cwd:t,verbose:e,description:o})}catch(n){throw new Error(`Failed to install dependencies with pnpm: ${n instanceof Error?n.message:"Unknown error"}`)}}import c from"chalk";async function W({appId:t,needsR2Bucket:o=!1,verbose:e=!1}){console.log(`
3
+ Setting up your Cloudflare ${o?"D1 Database, KV Store, and R2 Bucket":"D1 Database and KV Store"}...
4
+ `);let n=await w(),s=R(t),i;o&&(i=await X(s,n,e));let a=await H(s,n,e),p=await Z(s,n,e);return{d1DatabaseId:a,kvNamespaceId:p,r2BucketName:i,resourceName:s}}async function H(t,o,e){e&&(console.log(c.bold(`Processing D1 database...
5
+ `)),console.log(` Checking D1 database: ${t}`));let r=await P(t,o);return e?r.wasCreated?console.log(c.green(` Created D1 database: ${t} (${r.id})
6
+ `)):console.log(c.dim(` Linking to existing D1 database: ${t} (${r.id})
7
+ `)):r.wasCreated?console.log(c.green(" D1 successfully created.")):console.log(" D1 already set up."),r.id}async function Z(t,o,e){e&&(console.log(c.bold(`Processing KV namespace...
8
+ `)),console.log(` Checking KV namespace: ${t}`));let r=await $(t,o);return e?r.wasCreated?console.log(c.green(` Created KV namespace: ${t} (${r.id})
9
+ `)):console.log(c.dim(` Linking to existing KV namespace: ${t} (${r.id})
10
+ `)):r.wasCreated?console.log(c.green(" KV successfully created.")):console.log(" KV already set up."),r.id}async function X(t,o,e){e&&(console.log(c.bold(`Processing R2 bucket...
11
+ `)),console.log(` Checking R2 bucket: ${t}`));let r;try{r=await S(t,o)}catch(n){let s=await b(n,{accountId:o});throw s&&(console.log(s.formatted),process.exit(1)),n}return e?r.wasCreated?console.log(c.green(` Created R2 bucket: ${t}
12
+ `)):console.log(c.dim(` Linking to existing R2 bucket: ${t}
13
+ `)):r.wasCreated?console.log(c.green(" R2 successfully created.")):console.log(" R2 already set up."),r.name}import ee from"chalk";async function K({cwd:t,gatewayUrl:o,appId:e,verbose:r}){let n={...process.env,VITE_GATEWAY_URL:o,VITE_APP_ID:e};try{await g("npx",["vite","build"],{cwd:t,description:`Building your application...
14
+ `,env:n,verbose:r}),await g("npx",["wrangler","deploy"],{cwd:t,description:`Deploying your application to Cloudflare workers...
15
+
16
+ This could take up to a minute.`,env:n,verbose:r})}catch(s){let i=await b(s);throw i&&(console.log(i.formatted),process.exit(1)),console.error(ee.red(`
17
+ Failed to build or deploy`)),s}}import D from"chalk";var re="every-app-gateway";async function U(){let t=await w(),e=(await k(t)).find(r=>r.name===re);return e?{accountId:t,databaseId:e.uuid}:null}import m from"chalk";async function y(t,o,e,r){try{let n=await x(),s={sql:e};r&&r.length>0&&(s.params=r);let i=await fetch(`https://api.cloudflare.com/client/v4/accounts/${t}/d1/database/${o}/query`,{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify(s)}),a=await i.json();if(!i.ok||!a.success){let l=a.errors?a.errors.map(d=>`[${d.code}] ${d.message}`).join(", "):i.statusText;throw console.error(m.red(`
18
+ D1 Query Error:`)),console.error(m.dim(`SQL: ${e}`)),console.error(m.dim(`Error: ${l}`)),new Error(`D1 query failed: ${l}`)}let p=a.result;if(!p||p.length===0)throw new Error("No results returned from D1 query");let u=p[0];if(!u)throw new Error("First result is undefined");return u.results}catch(n){throw n instanceof Error&&!n.message.includes("D1 query failed")&&(console.error(m.red(`
19
+ D1 Query Error:`)),console.error(m.dim(`SQL: ${e}`))),n}}async function h(t){return y(t.accountId,t.databaseId,"SELECT id, name, email FROM users")}import{randomUUID as te}from"node:crypto";async function oe(t,o,e){return(await y(t.accountId,t.databaseId,"SELECT id FROM user_apps WHERE user_id = ? AND app_id = ?",[o,e])).length>0}async function E(t,o,e){if(await oe(t,o.id,e.appId))return{created:!1};let n=Math.floor(Date.now()/1e3),s=te(),i=`
20
+ INSERT INTO user_apps (id, user_id, app_id, name, description, app_url, dev_url, created_at, updated_at)
21
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
22
+ `;return await y(t.accountId,t.databaseId,i,[s,o.id,e.appId,e.name,e.description,e.appUrl,e.devUrl??null,n,n]),{created:!0}}async function M(t){let{appId:o,appUrl:e,verbose:r=!1,appName:n,appDescription:s,devUrl:i}=t;try{console.log(""),r&&console.log("Adding apps to user gateways...");let a=await U();if(!a){console.warn(D.yellow(`every-app-gateway database not found. Skipping UserApp record creation.
23
+ `));return}let p=await h(a);if(p.length===0)throw new Error("No users found in the database. Please create a user first before deploying apps.");let u=n||o,l=s||o;r&&p.length>1&&console.log(D.yellow(`Multiple users found (${p.length}). Adding app to all users...
24
+ `));for(let d of p)await ne(a,d,{appId:o,appUrl:e,name:u,description:l,devUrl:i,verbose:r});r&&p.length>1&&console.log(` UserApp records processed for ${p.length} users
25
+ `)}catch(a){throw console.error(D.red("Failed to insert UserApp records:"),a instanceof Error?a.message:a),a}}async function ne(t,o,e){let{verbose:r,...n}=e;(await E(t,o,n)).created?console.log(` UserApp record created for user ${o.name} (${o.email})`):r&&console.log(D.dim(` UserApp record already exists for user ${o.name} (${o.email})`))}async function q({gatewayUrl:t,appPath:o,verbose:e=!1}){e&&console.log("Configuring Secrets...");try{await _({secretName:"GATEWAY_URL",cwd:o,verbose:e})||await G({secretName:"GATEWAY_URL",secretValue:t,cwd:o,verbose:e,description:`Setting GATEWAY_URL to: ${t}`}),e&&console.log(`Secret setup complete!
26
+ `)}catch(r){throw console.error(`
27
+ Failed to setup secrets`,r instanceof Error?`
28
+ ${r.message}`:""),r}}async function Ye(t){let{cwd:o,appId:e,verbose:r,devUrl:n}=t,i=!!(await N(o)).r2_buckets?.length,{d1DatabaseId:a,kvNamespaceId:p,r2BucketName:u,resourceName:l}=await W({appId:e,needsR2Bucket:i,verbose:r});await T({configPath:o,name:l,d1DatabaseId:a,d1DatabaseName:l,kvNamespaceId:p,r2BucketName:u,verbose:r});let d=await A("every-app-gateway");console.log(),await L({cwd:o,description:"Installing dependencies for Cloudflare deployment...",verbose:r}),await O({cwd:o,verbose:r}),await K({cwd:o,gatewayUrl:d,appId:e,verbose:r}),await q({gatewayUrl:d,appPath:o,verbose:r});let I=await A(l),v=await C(o);return await M({appId:e,appUrl:I,verbose:r,appName:v.displayName,appDescription:v.description,devUrl:n}),{workerUrl:I,gatewayUrl:d}}export{pe as a,ce as b,Ye as c};
@@ -1,11 +1,11 @@
1
- import D from"node:fs/promises";import l from"node:path";import _ from"node:os";import*as y from"smol-toml";import p from"chalk";function I(){let e=_.homedir(),t=_.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 T(){let e=I();try{let t=await D.readFile(e,"utf-8"),n=y.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 N(e){let t=I(),n=l.dirname(t);await D.mkdir(n,{recursive:!0});let r=y.stringify(e);await D.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 F(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 $(){let e=!!process.env.CLOUDFLARE_API_TOKEN,t=!!process.env.CLOUDFLARE_ACCOUNT_ID;if(e&&!t&&(console.log(p.yellow(`
1
+ import A from"node:fs/promises";import l from"node:path";import _ from"node:os";import*as y from"smol-toml";import p from"chalk";function I(){let e=_.homedir(),t=_.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 T(){let e=I();try{let t=await A.readFile(e,"utf-8"),n=y.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 N(e){let t=I(),n=l.dirname(t);await A.mkdir(n,{recursive:!0});let r=y.stringify(e);await A.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 F(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 $(){let e=!!process.env.CLOUDFLARE_API_TOKEN,t=!!process.env.CLOUDFLARE_ACCOUNT_ID;if(e&&!t&&(console.log(p.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(p.dim(` export CLOUDFLARE_ACCOUNT_ID=<your_account_id>
5
5
  `)),process.exit(1)),!(e&&t))try{await h()}catch{console.log(p.yellow(`
6
6
  Please log in to Cloudflare.
7
7
  `)),console.log(p.dim(" 1. Cloudflare CLI (recommended): npx wrangler login")),console.log(p.dim(` 2. Environment variables: CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID
8
- `)),process.exit(1)}}async function h(){let e=process.env.CLOUDFLARE_API_TOKEN;if(e)return e;let t=await T();if(L(t.expiration_time)){let n=await F(t.refresh_token);return await N(n),n.oauth_token}return t.oauth_token}async function s(e,t={}){let n=await h(),r=await fetch(`https://api.cloudflare.com/client/v4${e}`,{...t,headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json",...t.headers}}),o=await r.json();if(!r.ok){let a=o.errors?o.errors.map(c=>`[${c.code}] ${c.message}`).join(", "):r.statusText;throw new Error(`Cloudflare API request failed: ${r.status} ${a}`)}if(!o.success){let a=o.errors.map(c=>`[${c.code}] ${c.message}`).join(", ");throw new Error(`Cloudflare API error: ${a}`)}return o.result}async function d(){let e=process.env.CLOUDFLARE_ACCOUNT_ID;if(e)return e;let t=await s("/accounts");if(!t||t.length===0)throw new Error("No Cloudflare accounts found");let n=t[0];if(!n)throw new Error("No Cloudflare accounts found");return n.id}async function U(e){let t=await s(`/accounts/${e}`);if(!t||!t.id)throw new Error(`Account ${e} not found`);return t}async function A(e){try{let t=await s(`/accounts/${e}/workers/subdomain`);if(!t||!t.subdomain)throw new Error("No workers.dev subdomain found for this account");return t.subdomain}catch(t){throw new Error(`Failed to get workers.dev subdomain: ${t instanceof Error?t.message:"Unknown error"}`)}}async function j(e,t){let n=t||await d(),r=await A(n);return`https://${e}.${r}.workers.dev`}import w from"chalk";var R={EMAIL_NOT_VERIFIED:10034,R2_NOT_ENABLED:10042},S={[R.EMAIL_NOT_VERIFIED]:{userMessage:"Almost there! Your Cloudflare account email needs to be verified first.",action:`To verify your email address:
8
+ `)),process.exit(1)}}async function h(){let e=process.env.CLOUDFLARE_API_TOKEN;if(e)return e;let t=await T();if(L(t.expiration_time)){let n=await F(t.refresh_token);return await N(n),n.oauth_token}return t.oauth_token}async function s(e,t={}){let n=await h(),r=await fetch(`https://api.cloudflare.com/client/v4${e}`,{...t,headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json",...t.headers}}),o=await r.json();if(!r.ok){let a=o.errors?o.errors.map(c=>`[${c.code}] ${c.message}`).join(", "):r.statusText;throw new Error(`Cloudflare API request failed: ${r.status} ${a}`)}if(!o.success){let a=o.errors.map(c=>`[${c.code}] ${c.message}`).join(", ");throw new Error(`Cloudflare API error: ${a}`)}return o.result}async function d(){let e=process.env.CLOUDFLARE_ACCOUNT_ID;if(e)return e;let t=await s("/accounts");if(!t||t.length===0)throw new Error("No Cloudflare accounts found");let n=t[0];if(!n)throw new Error("No Cloudflare accounts found");return n.id}async function U(e){let t=await s(`/accounts/${e}`);if(!t||!t.id)throw new Error(`Account ${e} not found`);return t}async function D(e){try{let t=await s(`/accounts/${e}/workers/subdomain`);if(!t||!t.subdomain)throw new Error("No workers.dev subdomain found for this account");return t.subdomain}catch(t){throw new Error(`Failed to get workers.dev subdomain: ${t instanceof Error?t.message:"Unknown error"}`)}}async function j(e,t){let n=t||await d(),r=await D(n);return`https://${e}.${r}.workers.dev`}import w from"chalk";var R={EMAIL_NOT_VERIFIED:10034,R2_NOT_ENABLED:10042},S={[R.EMAIL_NOT_VERIFIED]:{userMessage:"Almost there! Your Cloudflare account email needs to be verified first.",action:`To verify your email address:
9
9
 
10
10
  1. Check your inbox for a verification email from Cloudflare
11
11
  2. Click the verification link in the email
@@ -27,7 +27,7 @@ Once it's enabled, run the deploy command again.`}};function W(e){let t=e.match(
27
27
  ${w.yellow(e.userMessage)}
28
28
 
29
29
  ${n}
30
- `}async function V(e,t={}){let n=B(e),r=W(n);if(r===void 0)return;let o=M(r);return o?{formatted:await K(o,t),code:r}:void 0}import u from"chalk";import q from"enquirer";async function z(e,t){try{let n=t?{subdomain:t}:{},r=await s(`/accounts/${e}/workers/subdomain`,{method:"PUT",body:JSON.stringify(n)});if(!r||!r.subdomain)throw new Error("Failed to initialize workers.dev subdomain");return r.subdomain}catch(n){throw new Error(`Failed to initialize workers.dev subdomain: ${n instanceof Error?n.message:"Unknown error"}`)}}async function J(){return(await q.prompt({type:"input",name:"subdomain",message:" Choose a subdomain name:",validate:t=>!t||t.trim()===""?"Subdomain cannot be empty":/^[a-z0-9-]+$/.test(t)?t.startsWith("-")||t.endsWith("-")?"Subdomain cannot start or end with a hyphen":!0:"Subdomain must contain only lowercase letters, numbers, and hyphens"})).subdomain.trim()}async function H(){let e=await d();try{return await A(e)}catch{console.log(),console.log(u.yellow(` Please claim a Cloudflare subdomain.
30
+ `}async function V(e,t={}){let n=B(e),r=W(n);if(r===void 0)return;let o=M(r);return o?{formatted:await K(o,t),code:r}:void 0}import u from"chalk";import q from"enquirer";async function z(e,t){try{let n=t?{subdomain:t}:{},r=await s(`/accounts/${e}/workers/subdomain`,{method:"PUT",body:JSON.stringify(n)});if(!r||!r.subdomain)throw new Error("Failed to initialize workers.dev subdomain");return r.subdomain}catch(n){throw new Error(`Failed to initialize workers.dev subdomain: ${n instanceof Error?n.message:"Unknown error"}`)}}async function J(){return(await q.prompt({type:"input",name:"subdomain",message:" Choose a subdomain name:",validate:t=>!t||t.trim()===""?"Subdomain cannot be empty":/^[a-z0-9-]+$/.test(t)?t.startsWith("-")||t.endsWith("-")?"Subdomain cannot start or end with a hyphen":!0:"Subdomain must contain only lowercase letters, numbers, and hyphens"})).subdomain.trim()}async function H(){let e=await d();try{return await D(e)}catch{console.log(),console.log(u.yellow(` Please claim a Cloudflare subdomain.
31
31
  `)),console.log(u.dim(` All your apps will be deployed to this domain.
32
32
  `)),console.log(u.dim(" You can make it your name or a something fun.")),console.log(u.dim(` E.g. All apps will be deployed to "janedoe.workers.dev"
33
33
  `));let t=await J();console.log(u.dim(`
@@ -1,4 +1,4 @@
1
- import{g as l}from"./chunk-EV6OC476.js";import r from"node:fs/promises";import n from"node:path";import f from"node:os";import p from"chalk";async function u(e,t,i={}){let a=i.exclude||[];await r.mkdir(t,{recursive:!0});let m=await r.readdir(e,{withFileTypes:!0});for(let o of m){let s=n.join(e,o.name),c=n.join(t,o.name);a.some(y=>o.name===y)||(o.isDirectory()?await u(s,c,i):await r.copyFile(s,c))}}async function P(e){try{return(await r.stat(e)).isDirectory()}catch{return!1}}async function x({targetDir:e,appId:t}){let i=await l("every-app-gateway"),a=`# Vite client-side secrets
1
+ import{g as l}from"./chunk-GSJPLB2P.js";import r from"node:fs/promises";import n from"node:path";import f from"node:os";import p from"chalk";async function u(e,t,i={}){let a=i.exclude||[];await r.mkdir(t,{recursive:!0});let m=await r.readdir(e,{withFileTypes:!0});for(let o of m){let s=n.join(e,o.name),c=n.join(t,o.name);a.some(y=>o.name===y)||(o.isDirectory()?await u(s,c,i):await r.copyFile(s,c))}}async function P(e){try{return(await r.stat(e)).isDirectory()}catch{return!1}}async function x({targetDir:e,appId:t}){let i=await l("every-app-gateway"),a=`# Vite client-side secrets
2
2
  VITE_APP_ID=${t}
3
3
  VITE_GATEWAY_URL=${i}
4
4
  # Set Cloudflare secrets locally
@@ -1,5 +1,5 @@
1
- import p from"node:fs";import l from"node:os";import d from"node:path";function A(e){return{process:e,os:l,fs:p,path:d}}import{buildApplication as g,buildRouteMap as C}from"@stricli/core";import{buildInstallCommand as D,buildUninstallCommand as v}from"@stricli/auto-complete";var r="@every-app/cli";var n="Every App CLI - Deploy and manage apps.";var a="0.0.29";import{buildCommand as o,buildRouteMap as m}from"@stricli/core";var c=o({loader:async()=>import("./create-UIHDIRHR.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}}},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-PM4XTO7G.js");return e},parameters:{positional:{kind:"tuple",parameters:[]},flags:{verbose:{kind:"boolean",brief:"Show detailed output during deployment",optional:!0}}},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
- `)}}),y=o({loader:async()=>{let{remoteD1Shell:e}=await import("./remoteD1Shell-MF6FYSNX.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 @every-app/cli app remote-d1-shell -- npx drizzle-kit migrate"," - Opening Drizzle Studio: npx @every-app/cli app remote-d1-shell -- npx drizzle-kit studio"," - Pushing schema changes: npx @every-app/cli 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(`
4
- `)}}),i=m({routes:{create:c,deploy:u,"remote-d1-shell":y},docs:{brief:"App management commands"}});import{buildCommand as f,buildRouteMap as b}from"@stricli/core";var h=f({loader:async()=>{let{deploy:e}=await import("./deploy-3PSGIJ55.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}}},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 p from"node:fs";import l from"node:os";import d from"node:path";function A(e){return{process:e,os:l,fs:p,path:d}}import{buildApplication as g,buildRouteMap as C}from"@stricli/core";import{buildInstallCommand as D,buildUninstallCommand as v}from"@stricli/auto-complete";var r="@every-app/cli";var n="Every App CLI - Deploy and manage apps.";var a="0.0.30";import{buildCommand as o,buildRouteMap as m}from"@stricli/core";var c=o({loader:async()=>import("./create-7WJ6XHDQ.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}}},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-3MFXRA6S.js");return e},parameters:{positional:{kind:"tuple",parameters:[]},flags:{verbose:{kind:"boolean",brief:"Show detailed output during deployment",optional:!0}}},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
+ `)}}),y=o({loader:async()=>{let{remoteD1Shell:e}=await import("./remoteD1Shell-IGDH3UOE.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 @every-app/cli app remote-d1-shell -- npx drizzle-kit migrate"," - Opening Drizzle Studio: npx @every-app/cli app remote-d1-shell -- npx drizzle-kit studio"," - Pushing schema changes: npx @every-app/cli 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(`
4
+ `)}}),i=m({routes:{create:c,deploy:u,"remote-d1-shell":y},docs:{brief:"App management commands"}});import{buildCommand as f,buildRouteMap as b}from"@stricli/core";var h=f({loader:async()=>{let{deploy:e}=await import("./deploy-ICYDKP4C.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}}},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(`
5
5
  `)}}),s=b({routes:{deploy:h},docs:{brief:"Gateway management commands"}});var w=C({routes:{app:i,gateway:s,install:D("every",{bash:"__every_bash_complete"}),uninstall:v("every",{bash:!0})},docs:{brief:n,hideRoute:{install:!0,uninstall:!0}}}),M=g(w,{name:r,versionInfo:{currentVersion:a},scanner:{allowArgumentEscapeSequence:!0}});export{A as a,M as b};
@@ -0,0 +1,20 @@
1
+ import{d as u,e as g,f as w,g as y,m as h,n as x,o as O,r as b,u as A}from"./chunk-GSJPLB2P.js";import S from"enquirer";import C from"chalk";async function U(){if(process.env.CLOUDFLARE_API_TOKEN){let n=process.env.CLOUDFLARE_ACCOUNT_ID;return n||(console.log(C.yellow(`
2
+ CLOUDFLARE_ACCOUNT_ID is required when using CLOUDFLARE_API_TOKEN
3
+ `)),process.exit(1)),w(n)}let o=await h(),{account:e,otherAccounts:t}=O(o);return x(e,t),{id:e.account.id,name:e.account.name}}async function q(o="this"){let e=await U();process.env.CLOUDFLARE_API_TOKEN&&(console.log(C.dim(` ${e.name} (${e.id})`)),console.log());let{confirm:t}=await S.prompt({type:"confirm",name:"confirm",message:`Do you want to deploy ${o} to ${e.name}?`,initial:!1});return t}import m from"chalk";var I="every-app-gateway";async function L(o){try{let e=await fetch(`${o}/api/admin/has-owner`);return e.ok?(await e.json()).hasOwner:!1}catch{return!1}}async function N(){try{let o=await g();return await u(`/accounts/${o}/workers/scripts/${I}/settings`),!0}catch{return!1}}async function k(){return y(I)}async function _(){if(!await N())return{isDeployed:!1,hasOwner:!1,gatewayUrl:await k()};let e=await k();return{isDeployed:!0,hasOwner:await L(e),gatewayUrl:e}}async function J(){let{isDeployed:o,hasOwner:e,gatewayUrl:t}=await _();if(o||(console.log(m.yellow(`
4
+ Gateway not deployed
5
+ `)),console.log(`You need to deploy the Every App Gateway before creating or deploying apps.
6
+ `),console.log(m.dim(` Run: npx @every-app/cli gateway deploy
7
+ `)),process.exit(1)),!e){let n=`${t}/sign-up`;console.log(m.yellow(`
8
+ Owner account required
9
+ `)),console.log(`You need to create an owner account on your Gateway before deploying apps.
10
+ `),console.log(` ${m.cyan(n)}
11
+ `),console.log(m.dim(` Visit the URL above to create your owner account, then run this command again.
12
+ `)),process.exit(1)}return t}import v from"chalk";import D from"chalk";function X(o,e){o&&console.log(D.dim(e))}function $(o,...e){o&&e.forEach(t=>console.log(D.dim(t)))}var E="npx",R=["drizzle-kit","migrate","--config=drizzle-prod.config.ts"];async function ne({cwd:o,verbose:e=!1}){console.log(`
13
+ Running: ${E} ${R.join(" ")}`),console.log(v.dim(" Running database migrations...")),$(e," Running any pending migrations against your remote D1 Database..."),await A(E,R,{cwd:o,verbose:e}),console.log(v.dim(` Migrations completed.
14
+ `))}import{execa as p}from"execa";import c from"chalk";async function ae(o,e,t){let{env:n,cwd:s,verbose:r=!1,description:i,logCommandToConsole:l=!0}=t;return r?G(o,e,t):l?(console.log(`Running: ${o} ${e.join(" ")}`),i&&console.log(c.dim(` ${i}`)),await p(o,e,{cwd:s,env:n,stdio:"pipe"})):await p(o,e,{cwd:s,env:n,stdio:"pipe"})}async function G(o,e,{description:t,cwd:n,env:s}){console.log(c.dim(` \u250C\u2500 Running: ${o} ${e.join(" ")}`)),t&&console.log(c.dim(` \u2502 ${t}`));let r=p(o,e,{cwd:n,env:s,stdio:void 0,all:!0});r.stdout&&r.stdout.on("data",l=>{l.toString().split(`
15
+ `).forEach(a=>{a.trim()&&console.log(c.dim(` \u2502 ${a}`))})}),r.stderr&&r.stderr.on("data",l=>{l.toString().split(`
16
+ `).forEach(a=>{a.trim()&&console.error(c.dim(` \u2502 ${a}`))})});let i=await r;return console.log(c.dim(` \u2514\u2500 Complete
17
+ `)),i}import f from"chalk";import W from"node:path";async function P(o){let e=await g(),t=W.join(o,"wrangler.jsonc"),n=await b(t);return{accountId:e,workerName:n}}async function M(o){return await u(`/accounts/${o.accountId}/workers/scripts/${o.workerName}/secrets`)}async function fe({secretName:o,cwd:e,verbose:t=!1}){t&&console.log(f.dim(` Checking secret: ${o}`));let n=await P(e),r=(await M(n)).some(i=>i.name===o);return r&&t&&console.log(f.dim(` Secret already exists
18
+ `)),r}async function pe({secretName:o,secretValue:e,cwd:t,verbose:n=!1,description:s}){n&&s&&console.log(f.dim(` ${s}
19
+ `));let r=await P(t);await u(`/accounts/${r.accountId}/workers/scripts/${r.workerName}/secrets`,{method:"PUT",body:JSON.stringify({name:o,text:e,type:"secret_text"})}),n&&console.log(f.green(`Created secret: ${o}
20
+ `))}export{q as a,ae as b,L as c,J as d,X as e,$ as f,ne as g,fe as h,pe as i};
@@ -0,0 +1,24 @@
1
+ import{a as C,c as k}from"./chunk-3ACCBC4V.js";import{a as d,b as f,c as u,d as y,e as w}from"./chunk-MWLBLZ4J.js";import{a as h,b as a,d as b}from"./chunk-XJKWPT3C.js";import{b as g}from"./chunk-GSJPLB2P.js";import m from"chalk";async function x({url:o,targetDir:e,verbose:t=!1}){try{await a("git",["clone",o,e],{verbose:t,logCommandToConsole:!1})}catch(r){throw new Error(`Failed to clone repository from ${o}: ${r instanceof Error?r.message:"Unknown error"}`)}}async function P({targetDir:o,verbose:e=!1}){try{await a("git",["init"],{verbose:e,logCommandToConsole:!1,cwd:o}),await a("git",["add","."],{verbose:e,logCommandToConsole:!1,cwd:o}),await a("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 v from"chalk";import{execa as L}from"execa";async function T(){try{await L("pnpm",["--version"],{stdio:"pipe"})}catch{console.error(v.red(`
2
+ Error: pnpm is required but not installed. Please install it first:`)),console.error(v.cyan(` npm i -g pnpm
3
+ `)),process.exit(1)}}import j from"enquirer";function S(o){return!o||o.trim().length===0?"App ID cannot be empty":o.length>64?"App ID must be 64 characters or less":/^[a-z][a-z0-9-]*$/.test(o)?!0:"App ID must be in kebab-case format (lowercase letters, numbers, and hyphens only, starting with a letter)"}async function D(o){console.log(`Project Configuration
4
+ `);let e=await j.prompt({type:"input",name:"appId",message:"Enter your app ID (kebab-case format)",initial:o,validate:S});return console.log(),{appId:e.appId}}import E from"node:path";import J from"chalk";var N="https://github.com/every-app/every-app.git",M="templates/simple-todo";async function I({appId:o,verbose:e=!1}){e&&console.log(`Cloning template repository...
5
+ `);let t=await y("every-app-create-");await x({url:N,targetDir:t,verbose:e}),e&&console.log(`Extracting template...
6
+ `);let r=E.join(t,M),l=E.join(process.cwd(),o);if(await f(l))throw new Error(`Directory "${o}" already exists in the current location`);return await d(r,l,{exclude:["node_modules",".git","pnpm-lock.yaml","package-lock.json",".env.local",".env.production",".dev.vars","manual-steps.md"]}),e&&console.log(J.dim(` Template copied to ${l}
7
+ `)),{tempDir:t,targetDir:l}}import R from"node:fs/promises";import _ from"node:path";async function O({targetDir:o,appId:e}){let t=_.join(o,"package.json"),r=JSON.parse(await R.readFile(t,"utf-8"));r.name=e,await R.writeFile(t,JSON.stringify(r,null,2)+`
8
+ `,"utf-8")}import c from"chalk";async function A({targetDir:o,verbose:e=!1}){try{e||console.log(`
9
+ Setting up Cloudflare for local dev...`),await a("pnpm",["run","cf-typegen"],{cwd:o,verbose:e,logCommandToConsole:!1}),await a("pnpm",["run","build"],{cwd:o,verbose:e,logCommandToConsole:!1}),e||console.log(c.dim(` Finished.
10
+ `)),await a("pnpm",["run","db:migrate:local"],{cwd:o,verbose:e}),console.log(`
11
+ Local database migrations complete.
12
+ `)}catch{console.warn(c.yellow(`
13
+ Failed to run local migrations. You can run them manually with:`)),console.warn(c.dim(` pnpm run db:migrate:local
14
+ `))}}import n from"chalk";function $({appId:o,targetDir:e,gatewayUrl:t,workerUrl:r}){console.log(n.green(`Project created and deployed successfully!
15
+ `)),console.log(n.dim(` Location: ${e}`)),console.log(n.dim(` App URL: ${n.cyan(r)}`)),console.log(n.dim(` Gateway: ${n.cyan(t)}`)),console.log(),console.log(`For local development:
16
+ `),console.log(n.dim(` ${n.bold(`cd ${o}`)}`)),console.log(n.dim(` ${n.bold("pnpm run dev")}`)),console.log(n.dim(` ${n.bold(`
17
+ Then, go to the Gateway and click the "Dev" button on the app to go to the app running locally instead of on cloudflare.`)}`)),console.log(),console.log(`To deploy updates after changes:
18
+ `),console.log(n.dim(` ${n.bold("npx @every-app/cli app deploy")}`)),console.log()}async function Po(o,e){let t=o.verbose||!1;await T(),await g(),await b(),console.log(`
19
+ Create a new Every App project
20
+ `);let{appId:r}=await D(e);if(console.log(m.dim(`.
21
+ `)),!await h("this app")){console.log(m.yellow(`
22
+ App creation cancelled.
23
+ `));return}let s=null;try{let{tempDir:p,targetDir:i}=await I({appId:r,verbose:t});s=p,await O({targetDir:i,appId:r}),await C(i,{appId:r});let{workerUrl:F,gatewayUrl:U}=await k({cwd:i,appId:r,verbose:t,devUrl:"http://localhost:3001"});await u({targetDir:i,appId:r}),await A({targetDir:i,verbose:t}),await P({targetDir:i,verbose:t}),$({appId:r,targetDir:i,gatewayUrl:U,workerUrl:F})}catch(p){throw console.error(m.red(`
24
+ Failed to create project:`),p instanceof Error?p.message:"Unknown error"),p}finally{s&&await w({tmpDir:s})}}export{Po as default};
@@ -0,0 +1,7 @@
1
+ import{b as a,c}from"./chunk-3ACCBC4V.js";import{a as n,d as l}from"./chunk-XJKWPT3C.js";import{b as r}from"./chunk-GSJPLB2P.js";import o from"chalk";async function C(p){await r(),await l();let e=process.cwd(),m=p.verbose||!1,t=await a(e);if(console.log(o.bold(`
2
+ Project: ${t}
3
+ `)),!await n("this app")){console.log(o.red(`
4
+ Deployment cancelled by user
5
+ `));return}let{workerUrl:s,gatewayUrl:i}=await c({cwd:e,appId:t,verbose:m});console.log(o.green(`
6
+ Deployment successful!`)),console.log(o.dim(` App URL: ${o.cyan(s)}`)),console.log(` Gateway: ${o.cyan(i)}
7
+ `)}export{C as deploy};
@@ -0,0 +1,30 @@
1
+ import{d as k,e as R}from"./chunk-MWLBLZ4J.js";import{a as D,b as _,c as b,e as g,f as w,g as U,h as m,i as d}from"./chunk-XJKWPT3C.js";import{b as E,e as C,g as h,i as T,j as A,l as S,p as x,q as K,r as $}from"./chunk-GSJPLB2P.js";import l from"chalk";import ne from"node:path";import c from"chalk";var J="every-app-gateway",Y="every-app-gateway";async function G({verbose:o=!1}={}){console.log(`
2
+ Setting up your Cloudflare D1 Database and KV Store...
3
+ `);let e=await C(),t=await B(J,e,o),r=await F(Y,e,o);return console.log(),{d1DatabaseId:t,kvNamespaceId:r,accountId:e}}async function B(o,e,t){t&&console.log(` Checking D1 database: ${o}`);let r=await T(o,e);return t?r.wasCreated?console.log(c.green(` Created D1 database: ${o} (${r.id})
4
+ `)):console.log(c.dim(` Linking to existing D1 database: ${o} (${r.id})
5
+ `)):r.wasCreated?console.log(c.green(` D1 successfully created.
6
+ `)):console.log(" D1 already set up."),r.id}async function F(o,e,t){t&&console.log(` Checking KV namespace: ${o}`);let r=await A(o,e);return t?r.wasCreated?console.log(c.green(` Created KV namespace: ${o} (${r.id})
7
+ `)):console.log(c.dim(` Linking to existing KV namespace: ${o} (${r.id})
8
+ `)):r.wasCreated?console.log(c.green(" KV successfully created.")):console.log(" KV already set up."),r.id}import j from"node:crypto";import H from"node:path";import W from"node:crypto";import y from"chalk";function M(){return W.randomBytes(32).toString("base64")}function z(){let{privateKey:o,publicKey:e}=W.generateKeyPairSync("rsa",{modulusLength:2048,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}});return{privateKey:o,publicKey:e}}async function L({gatewayUrl:o,gatewayPath:e,verbose:t=!1}){console.log("Configuring Secrets...");try{if(await m({secretName:"GATEWAY_URL",cwd:e,verbose:t})||await d({secretName:"GATEWAY_URL",secretValue:o,cwd:e,verbose:t,description:`Setting GATEWAY_URL to: ${o}`}),!await m({secretName:"BETTER_AUTH_SECRET",cwd:e,verbose:t})){let p=M();await d({secretName:"BETTER_AUTH_SECRET",secretValue:p,cwd:e,verbose:t,description:"Generating new Better Auth secret..."})}let n=await m({secretName:"JWT_PRIVATE_KEY",cwd:e,verbose:t}),i=await m({secretName:"JWT_PUBLIC_KEY",cwd:e,verbose:t});if(n&&i)t&&console.log(y.dim(` JWT key pair already exists
9
+ `));else if(!n&&!i){t&&console.log(y.dim(` Generating new JWT key pair...
10
+ `));let p=z();await d({secretName:"JWT_PRIVATE_KEY",secretValue:p.privateKey,cwd:e,verbose:t}),await d({secretName:"JWT_PUBLIC_KEY",secretValue:p.publicKey,cwd:e,verbose:t}),t&&console.log(y.green(`Created JWT key pair secrets
11
+ `))}else throw new Error("JWT key pair is incomplete. Both JWT_PRIVATE_KEY and JWT_PUBLIC_KEY must exist together. Please delete the existing key and redeploy.");console.log(t?`Secret setup complete!
12
+ `:` Finished.
13
+ `)}catch(r){throw console.error(`
14
+ Failed to setup secrets`,r instanceof Error?`
15
+ ${r.message}`:""),r}}async function P({gatewayPath:o,resources:e,workerUrl:t,verbose:r=!1}){let a=H.join(o,"dist","server","wrangler.json");await K({configPath:a,d1DatabaseId:e.d1DatabaseId,kvNamespaceId:e.kvNamespaceId,verbose:r});let n=j.randomUUID();console.log(),await _("npx",["wrangler","deploy"],{cwd:o,description:`Deploying your Gateway to Cloudflare workers...
16
+
17
+ This could take up to a minute.`,env:{...process.env,BETTER_AUTH_SECRET:n},verbose:r}),console.log(),await L({gatewayUrl:t,gatewayPath:o,verbose:r})}import u from"node:fs";import q from"node:path";import{Readable as Q}from"node:stream";import{pipeline as X}from"node:stream/promises";import{createWriteStream as Z}from"node:fs";import{spawn as ee}from"node:child_process";var te="every-app",oe="every-app",v="every-app-gateway-build.tar.gz";function re(){return`https://github.com/${te}/${oe}/releases/download/gateway-latest/${v}`}async function ae(o,e){let t=await fetch(o,{redirect:"follow"});if(!t.ok)throw new Error(`Failed to download file: ${t.status} ${t.statusText}`);if(!t.body)throw new Error("Response body is null");let r=Z(e),a=Q.fromWeb(t.body);await X(a,r)}async function V(o,e){return new Promise((t,r)=>{let a=ee("tar",["-xzf",o,"-C",e]);a.on("error",r),a.on("close",n=>{n===0?t():r(new Error(`tar extraction failed with code ${n}`))})})}async function I(o,e=!1){console.log("Getting latest gateway release..."),u.mkdirSync(o,{recursive:!0});let t=re();g(e,`URL: ${t}`);let r=q.join(o,v);try{await ae(t,r)}catch(a){throw a instanceof Error&&a.message.includes("404")?new Error("Gateway release not found. Make sure a release has been published."):a}return w(e,`Downloaded to: ${r}`,"Extracting archive..."),await V(r,o),u.unlinkSync(r),g(e,`Extraction complete
18
+ `),o}async function N(o,e,t=!1){if(console.log("Using local gateway tarball..."),!u.existsSync(o))throw new Error(`Local gateway tarball not found: ${o}`);return u.mkdirSync(e,{recursive:!0}),w(t,`Tarball: ${o}`,"Extracting archive..."),await V(o,e),g(t,`Extraction complete
19
+ `),e}async function Ie(o){await E();let e=o.verbose||!1,t=o.localGateway;if(console.log(l.bold(`
20
+ Every App Gateway
21
+ `)),!await D("the Gateway")){console.log(`
22
+ Deployment cancelled by user
23
+ `);return}await x();let a=await G({verbose:e}),n=await k("gateway-deploy-");e&&console.log(l.dim(`Working directory: ${n}
24
+ `));let i=null;try{let s=t?await N(t,n,e):await I(n,e),f=ne.join(s,"wrangler.jsonc"),O=await $(f);i=await h(O),await P({gatewayPath:s,resources:a,workerUrl:i,verbose:e}),await U({cwd:s,verbose:e})}catch(s){let f=await S(s);throw f&&(console.log(f.formatted),process.exit(1)),console.error(`
25
+ Deployment failed:`,s instanceof Error?s.message:s),s}finally{await R({tmpDir:n,verbose:e})}if(!i)throw new Error("Worker URL not set properly during deployment");if(console.log(l.green(`
26
+ Gateway deployment successful!
27
+ `)),await b(i))console.log(`Your Gateway is now live at: ${l.cyan(i)}
28
+ `);else{let s=`${i}/sign-up`;console.log(`Your Gateway is now live at: ${l.cyan(s)}
29
+ `),console.log(l.dim(` Create an owner account to get started with your Gateway.
30
+ `))}}export{Ie as deploy};
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{a as r,b as o}from"./chunk-L2AU5B4R.js";import{run as i}from"@stricli/core";await i(o,process.argv.slice(2),r(process));
2
+ import{a as r,b as o}from"./chunk-QSBOPBPF.js";import{run as i}from"@stricli/core";await i(o,process.argv.slice(2),r(process));
@@ -1,4 +1,4 @@
1
- import{b as i,t as c}from"./chunk-EV6OC476.js";import r from"chalk";import{execa as a}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 @every-app/cli app remote-d1-shell -- <command>
1
+ import{b as i,t as c}from"./chunk-GSJPLB2P.js";import r from"chalk";import{execa as a}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 @every-app/cli app remote-d1-shell -- <command>
2
2
  Example: npx @every-app/cli 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 l=await c(n);console.log(r.bold(`
3
3
  Running: ${r.cyan([e,...t].join(" "))}
4
4
  `)),await a(e,t,{cwd:n,stdio:"inherit",env:{...process.env,...l}}),console.log(`
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.0.29",
7
+ "version": "0.0.30",
8
8
  "files": [
9
9
  "dist"
10
10
  ],
@@ -1,28 +0,0 @@
1
- import{b as A,c as O,f as _,g as G,h as V}from"./chunk-UECRZPI5.js";import{a as v,c as k,e as y,g as D,h as x,i as $,j as P,k as S,l as w,q as T,s as N}from"./chunk-EV6OC476.js";import j from"node:fs/promises";import B from"node:path";import*as L from"jsonc-parser";import{z as g}from"zod";var F="every-app.jsonc",Q=g.object({appId:g.string().min(1,"appId cannot be empty"),displayName:g.string().min(1,"displayName cannot be empty").optional(),description:g.string().optional()});async function C(t){let o=B.join(t,F);try{let e=await j.readFile(o,"utf-8"),r=L.parse(e);return Q.parse(r)}catch(e){if(e instanceof Error&&"code"in e&&e.code==="ENOENT")throw new Error("every-app.jsonc not found. Make sure you're running this command from an Every App project directory.");if(e instanceof g.ZodError){let r=e.issues.map(n=>n.message).join(", ");throw new Error(`Invalid every-app.jsonc: ${r}`)}throw e}}function z(t){return t.split("-").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" ")}async function ae(t,o){let e=B.join(t,F),r={...o,displayName:o.displayName??z(o.appId)},n=JSON.stringify(r,null,2)+`
2
- `;await j.writeFile(e,n)}async function ie(t){return(await C(t)).appId}import c from"chalk";async function K({appId:t,needsR2Bucket:o=!1,verbose:e=!1}){console.log(`
3
- Setting up your Cloudflare ${o?"D1 Database, KV Store, and R2 Bucket":"D1 Database and KV Store"}...
4
- `);let n=await y(),s=v(t),i;o&&(i=await H(s,n,e));let a=await Y(s,n,e),p=await J(s,n,e);return{d1DatabaseId:a,kvNamespaceId:p,r2BucketName:i,resourceName:s}}async function Y(t,o,e){e&&(console.log(c.bold(`Processing D1 database...
5
- `)),console.log(` Checking D1 database: ${t}`));let r=await $(t,o);return e?r.wasCreated?console.log(c.green(` Created D1 database: ${t} (${r.id})
6
- `)):console.log(c.dim(` Linking to existing D1 database: ${t} (${r.id})
7
- `)):r.wasCreated?console.log(c.green(" D1 successfully created.")):console.log(" D1 already set up."),r.id}async function J(t,o,e){e&&(console.log(c.bold(`Processing KV namespace...
8
- `)),console.log(` Checking KV namespace: ${t}`));let r=await P(t,o);return e?r.wasCreated?console.log(c.green(` Created KV namespace: ${t} (${r.id})
9
- `)):console.log(c.dim(` Linking to existing KV namespace: ${t} (${r.id})
10
- `)):r.wasCreated?console.log(c.green(" KV successfully created.")):console.log(" KV already set up."),r.id}async function H(t,o,e){e&&(console.log(c.bold(`Processing R2 bucket...
11
- `)),console.log(` Checking R2 bucket: ${t}`));let r;try{r=await S(t,o)}catch(n){let s=await w(n,{accountId:o});throw s&&(console.log(s.formatted),process.exit(1)),n}return e?r.wasCreated?console.log(c.green(` Created R2 bucket: ${t}
12
- `)):console.log(c.dim(` Linking to existing R2 bucket: ${t}
13
- `)):r.wasCreated?console.log(c.green(" R2 successfully created.")):console.log(" R2 already set up."),r.name}import Z from"chalk";async function W({cwd:t,gatewayUrl:o,appId:e,verbose:r}){let n={...process.env,VITE_GATEWAY_URL:o,VITE_APP_ID:e};try{await A("npx",["vite","build"],{cwd:t,description:`Building your application...
14
- `,env:n,verbose:r}),await A("npx",["wrangler","deploy"],{cwd:t,description:`Deploying your application to Cloudflare workers...
15
-
16
- This could take up to a minute.`,env:n,verbose:r})}catch(s){let i=await w(s);throw i&&(console.log(i.formatted),process.exit(1)),console.error(Z.red(`
17
- Failed to build or deploy`)),s}}import b from"chalk";var X="every-app-gateway";async function U(){let t=await y(),e=(await x(t)).find(r=>r.name===X);return e?{accountId:t,databaseId:e.uuid}:null}import f from"chalk";async function m(t,o,e,r){try{let n=await k(),s={sql:e};r&&r.length>0&&(s.params=r);let i=await fetch(`https://api.cloudflare.com/client/v4/accounts/${t}/d1/database/${o}/query`,{method:"POST",headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:JSON.stringify(s)}),a=await i.json();if(!i.ok||!a.success){let l=a.errors?a.errors.map(d=>`[${d.code}] ${d.message}`).join(", "):i.statusText;throw console.error(f.red(`
18
- D1 Query Error:`)),console.error(f.dim(`SQL: ${e}`)),console.error(f.dim(`Error: ${l}`)),new Error(`D1 query failed: ${l}`)}let p=a.result;if(!p||p.length===0)throw new Error("No results returned from D1 query");let u=p[0];if(!u)throw new Error("First result is undefined");return u.results}catch(n){throw n instanceof Error&&!n.message.includes("D1 query failed")&&(console.error(f.red(`
19
- D1 Query Error:`)),console.error(f.dim(`SQL: ${e}`))),n}}async function E(t){return m(t.accountId,t.databaseId,"SELECT id, name, email FROM users")}import{randomUUID as ee}from"node:crypto";async function re(t,o,e){return(await m(t.accountId,t.databaseId,"SELECT id FROM user_apps WHERE user_id = ? AND app_id = ?",[o,e])).length>0}async function h(t,o,e){if(await re(t,o.id,e.appId))return{created:!1};let n=Math.floor(Date.now()/1e3),s=ee(),i=`
20
- INSERT INTO user_apps (id, user_id, app_id, name, description, app_url, dev_url, created_at, updated_at)
21
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
22
- `;return await m(t.accountId,t.databaseId,i,[s,o.id,e.appId,e.name,e.description,e.appUrl,e.devUrl??null,n,n]),{created:!0}}async function M(t){let{appId:o,appUrl:e,verbose:r=!1,appName:n,appDescription:s,devUrl:i}=t;try{console.log(""),r&&console.log("Adding apps to user gateways...");let a=await U();if(!a){console.warn(b.yellow(`every-app-gateway database not found. Skipping UserApp record creation.
23
- `));return}let p=await E(a);if(p.length===0)throw new Error("No users found in the database. Please create a user first before deploying apps.");let u=n||o,l=s||o;r&&p.length>1&&console.log(b.yellow(`Multiple users found (${p.length}). Adding app to all users...
24
- `));for(let d of p)await te(a,d,{appId:o,appUrl:e,name:u,description:l,devUrl:i,verbose:r});r&&p.length>1&&console.log(` UserApp records processed for ${p.length} users
25
- `)}catch(a){throw console.error(b.red("Failed to insert UserApp records:"),a instanceof Error?a.message:a),a}}async function te(t,o,e){let{verbose:r,...n}=e;(await h(t,o,n)).created?console.log(` UserApp record created for user ${o.name} (${o.email})`):r&&console.log(b.dim(` UserApp record already exists for user ${o.name} (${o.email})`))}async function q({gatewayUrl:t,appPath:o,verbose:e=!1}){e&&console.log("Configuring Secrets...");try{await G({secretName:"GATEWAY_URL",cwd:o,verbose:e})||await V({secretName:"GATEWAY_URL",secretValue:t,cwd:o,verbose:e,description:`Setting GATEWAY_URL to: ${t}`}),e&&console.log(`Secret setup complete!
26
- `)}catch(r){throw console.error(`
27
- Failed to setup secrets`,r instanceof Error?`
28
- ${r.message}`:""),r}}async function We(t){let{cwd:o,appId:e,verbose:r,devUrl:n}=t,i=!!(await N(o)).r2_buckets?.length,{d1DatabaseId:a,kvNamespaceId:p,r2BucketName:u,resourceName:l}=await K({appId:e,needsR2Bucket:i,verbose:r});await T({configPath:o,name:l,d1DatabaseId:a,d1DatabaseName:l,kvNamespaceId:p,r2BucketName:u,verbose:r});let d=await D("every-app-gateway");console.log(),await O({cwd:o,description:"Installing dependencies for Cloudflare deployment...",verbose:r}),await _({cwd:o,verbose:r}),await W({cwd:o,gatewayUrl:d,appId:e,verbose:r}),await q({gatewayUrl:d,appPath:o,verbose:r});let I=await D(l),R=await C(o);return await M({appId:e,appUrl:I,verbose:r,appName:R.displayName,appDescription:R.description,devUrl:n}),{workerUrl:I,gatewayUrl:d}}export{ae as a,ie as b,We as c};
@@ -1,11 +0,0 @@
1
- import{d as f,e as d,f as w,m as x,n as h,o as C,r as y,u as I}from"./chunk-EV6OC476.js";import E from"enquirer";import b from"chalk";async function P(){if(process.env.CLOUDFLARE_API_TOKEN){let t=process.env.CLOUDFLARE_ACCOUNT_ID;return t||(console.log(b.yellow(`
2
- CLOUDFLARE_ACCOUNT_ID is required when using CLOUDFLARE_API_TOKEN
3
- `)),process.exit(1)),w(t)}let e=await x(),{account:o,otherAccounts:n}=C(e);return h(o,n),{id:o.account.id,name:o.account.name}}async function M(e="this"){let o=await P();process.env.CLOUDFLARE_API_TOKEN&&(console.log(b.dim(` ${o.name} (${o.id})`)),console.log());let{confirm:n}=await E.prompt({type:"confirm",name:"confirm",message:`Do you want to deploy ${e} to ${o.name}?`,initial:!1});return n}import{execa as S}from"execa";import{execa as p}from"execa";import a from"chalk";async function u(e,o,n){let{env:t,cwd:i,verbose:r=!1,description:s,logCommandToConsole:l=!0}=n;return r?R(e,o,n):l?(console.log(`Running: ${e} ${o.join(" ")}`),s&&console.log(a.dim(` ${s}`)),await p(e,o,{cwd:i,env:t,stdio:"pipe"})):await p(e,o,{cwd:i,env:t,stdio:"pipe"})}async function R(e,o,{description:n,cwd:t,env:i}){console.log(a.dim(` \u250C\u2500 Running: ${e} ${o.join(" ")}`)),n&&console.log(a.dim(` \u2502 ${n}`));let r=p(e,o,{cwd:t,env:i,stdio:void 0,all:!0});r.stdout&&r.stdout.on("data",l=>{l.toString().split(`
4
- `).forEach(c=>{c.trim()&&console.log(a.dim(` \u2502 ${c}`))})}),r.stderr&&r.stderr.on("data",l=>{l.toString().split(`
5
- `).forEach(c=>{c.trim()&&console.error(a.dim(` \u2502 ${c}`))})});let s=await r;return console.log(a.dim(` \u2514\u2500 Complete
6
- `)),s}async function L(){try{return await S("pnpm",["--version"],{stdio:"pipe"}),!0}catch{return!1}}async function V({cwd:e,description:o,verbose:n=!1}){let t=await L();try{t?await u("pnpm",["install"],{cwd:e,verbose:n,description:o}):await u("npx",["pnpm","install"],{cwd:e,verbose:n,description:o})}catch(i){throw new Error(`Failed to install dependencies with pnpm: ${i instanceof Error?i.message:"Unknown error"}`)}}import $ from"chalk";import O from"chalk";function X(e,o){e&&console.log(O.dim(o))}function A(e,...o){e&&o.forEach(n=>console.log(O.dim(n)))}var k="npx",D=["drizzle-kit","migrate","--config=drizzle-prod.config.ts"];async function no({cwd:e,verbose:o=!1}){console.log(`
7
- Running: ${k} ${D.join(" ")}`),console.log($.dim(" Running database migrations...")),A(o," Running any pending migrations against your remote D1 Database..."),await I(k,D,{cwd:e,verbose:o}),console.log($.dim(` Migrations completed.
8
- `))}import m from"chalk";import N from"node:path";async function v(e){let o=await d(),n=N.join(e,"wrangler.jsonc"),t=await y(n);return{accountId:o,workerName:t}}async function _(e){return await f(`/accounts/${e.accountId}/workers/scripts/${e.workerName}/secrets`)}async function ao({secretName:e,cwd:o,verbose:n=!1}){n&&console.log(m.dim(` Checking secret: ${e}`));let t=await v(o),r=(await _(t)).some(s=>s.name===e);return r&&n&&console.log(m.dim(` Secret already exists
9
- `)),r}async function lo({secretName:e,secretValue:o,cwd:n,verbose:t=!1,description:i}){t&&i&&console.log(m.dim(` ${i}
10
- `));let r=await v(n);await f(`/accounts/${r.accountId}/workers/scripts/${r.workerName}/secrets`,{method:"PUT",body:JSON.stringify({name:e,text:o,type:"secret_text"})}),t&&console.log(m.green(`Created secret: ${e}
11
- `))}export{M as a,u as b,V as c,X as d,A as e,no as f,ao as g,lo as h};
@@ -1,24 +0,0 @@
1
- import{a as C,c as b}from"./chunk-C2ECOZQW.js";import{a as d,b as f,c as u,d as y,e as w}from"./chunk-OD7IDDKP.js";import{a as h,b as a}from"./chunk-UECRZPI5.js";import{b as g}from"./chunk-EV6OC476.js";import m from"chalk";async function k({url:o,targetDir:e,verbose:t=!1}){try{await a("git",["clone",o,e],{verbose:t,logCommandToConsole:!1})}catch(r){throw new Error(`Failed to clone repository from ${o}: ${r instanceof Error?r.message:"Unknown error"}`)}}async function x({targetDir:o,verbose:e=!1}){try{await a("git",["init"],{verbose:e,logCommandToConsole:!1,cwd:o}),await a("git",["add","."],{verbose:e,logCommandToConsole:!1,cwd:o}),await a("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 P from"chalk";import{execa as U}from"execa";async function v(){try{await U("pnpm",["--version"],{stdio:"pipe"})}catch{console.error(P.red(`
2
- Error: pnpm is required but not installed. Please install it first:`)),console.error(P.cyan(` npm i -g pnpm
3
- `)),process.exit(1)}}import L from"enquirer";function j(o){return!o||o.trim().length===0?"App ID cannot be empty":o.length>64?"App ID must be 64 characters or less":/^[a-z][a-z0-9-]*$/.test(o)?!0:"App ID must be in kebab-case format (lowercase letters, numbers, and hyphens only, starting with a letter)"}async function T(o){console.log(`Project Configuration
4
- `);let e=await L.prompt({type:"input",name:"appId",message:"Enter your app ID (kebab-case format)",initial:o,validate:j});return console.log(),{appId:e.appId}}import D from"node:path";import J from"chalk";var S="https://github.com/every-app/every-app.git",N="templates/simple-todo";async function E({appId:o,verbose:e=!1}){e&&console.log(`Cloning template repository...
5
- `);let t=await y("every-app-create-");await k({url:S,targetDir:t,verbose:e}),e&&console.log(`Extracting template...
6
- `);let r=D.join(t,N),l=D.join(process.cwd(),o);if(await f(l))throw new Error(`Directory "${o}" already exists in the current location`);return await d(r,l,{exclude:["node_modules",".git","pnpm-lock.yaml","package-lock.json",".env.local",".env.production",".dev.vars","manual-steps.md"]}),e&&console.log(J.dim(` Template copied to ${l}
7
- `)),{tempDir:t,targetDir:l}}import I from"node:fs/promises";import M from"node:path";async function R({targetDir:o,appId:e}){let t=M.join(o,"package.json"),r=JSON.parse(await I.readFile(t,"utf-8"));r.name=e,await I.writeFile(t,JSON.stringify(r,null,2)+`
8
- `,"utf-8")}import c from"chalk";async function O({targetDir:o,verbose:e=!1}){try{e||console.log(`
9
- Setting up Cloudflare for local dev...`),await a("pnpm",["run","cf-typegen"],{cwd:o,verbose:e,logCommandToConsole:!1}),await a("pnpm",["run","build"],{cwd:o,verbose:e,logCommandToConsole:!1}),e||console.log(c.dim(` Finished.
10
- `)),await a("pnpm",["run","db:migrate:local"],{cwd:o,verbose:e}),console.log(`
11
- Local database migrations complete.
12
- `)}catch{console.warn(c.yellow(`
13
- Failed to run local migrations. You can run them manually with:`)),console.warn(c.dim(` pnpm run db:migrate:local
14
- `))}}import n from"chalk";function A({appId:o,targetDir:e,gatewayUrl:t,workerUrl:r}){console.log(n.green(`Project created and deployed successfully!
15
- `)),console.log(n.dim(` Location: ${e}`)),console.log(n.dim(` App URL: ${n.cyan(r)}`)),console.log(n.dim(` Gateway: ${n.cyan(t)}`)),console.log(),console.log(`For local development:
16
- `),console.log(n.dim(` ${n.bold(`cd ${o}`)}`)),console.log(n.dim(` ${n.bold("pnpm run dev")}`)),console.log(n.dim(` ${n.bold(`
17
- Then, go to the Gateway and click the "Dev" button on the app to go to the app running locally instead of on cloudflare.`)}`)),console.log(),console.log(`To deploy updates after changes:
18
- `),console.log(n.dim(` ${n.bold("npx @every-app/cli app deploy")}`)),console.log()}async function ko(o,e){let t=o.verbose||!1;await v(),await g(),console.log(`
19
- Create a new Every App project
20
- `);let{appId:r}=await T(e);if(console.log(m.dim(`.
21
- `)),!await h("this app")){console.log(m.yellow(`
22
- App creation cancelled.
23
- `));return}let p=null;try{let{tempDir:s,targetDir:i}=await E({appId:r,verbose:t});p=s,await R({targetDir:i,appId:r}),await C(i,{appId:r});let{workerUrl:$,gatewayUrl:F}=await b({cwd:i,appId:r,verbose:t,devUrl:"http://localhost:3001"});await u({targetDir:i,appId:r}),await O({targetDir:i,verbose:t}),await x({targetDir:i,verbose:t}),A({appId:r,targetDir:i,gatewayUrl:F,workerUrl:$})}catch(s){throw console.error(m.red(`
24
- Failed to create project:`),s instanceof Error?s.message:"Unknown error"),s}finally{p&&await w({tmpDir:p})}}export{ko as default};
@@ -1,30 +0,0 @@
1
- import{d as S,e as b}from"./chunk-OD7IDDKP.js";import{a as D,b as R,c as $,d as g,e as w,f as G,g as m,h as d}from"./chunk-UECRZPI5.js";import{b as E,e as h,g as C,i as T,j as k,l as x,p as A,q as _,r as K}from"./chunk-EV6OC476.js";import l from"chalk";import se from"node:path";import c from"chalk";var Y="every-app-gateway",B="every-app-gateway";async function U({verbose:t=!1}={}){console.log(`
2
- Setting up your Cloudflare D1 Database and KV Store...
3
- `);let e=await h(),o=await F(Y,e,t),r=await M(B,e,t);return console.log(),{d1DatabaseId:o,kvNamespaceId:r,accountId:e}}async function F(t,e,o){o&&console.log(` Checking D1 database: ${t}`);let r=await T(t,e);return o?r.wasCreated?console.log(c.green(` Created D1 database: ${t} (${r.id})
4
- `)):console.log(c.dim(` Linking to existing D1 database: ${t} (${r.id})
5
- `)):r.wasCreated?console.log(c.green(` D1 successfully created.
6
- `)):console.log(" D1 already set up."),r.id}async function M(t,e,o){o&&console.log(` Checking KV namespace: ${t}`);let r=await k(t,e);return o?r.wasCreated?console.log(c.green(` Created KV namespace: ${t} (${r.id})
7
- `)):console.log(c.dim(` Linking to existing KV namespace: ${t} (${r.id})
8
- `)):r.wasCreated?console.log(c.green(" KV successfully created.")):console.log(" KV already set up."),r.id}import H from"node:crypto";import q from"node:path";import W from"node:crypto";import y from"chalk";function j(){return W.randomBytes(32).toString("base64")}function z(){let{privateKey:t,publicKey:e}=W.generateKeyPairSync("rsa",{modulusLength:2048,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}});return{privateKey:t,publicKey:e}}async function L({gatewayUrl:t,gatewayPath:e,verbose:o=!1}){console.log("Configuring Secrets...");try{if(await m({secretName:"GATEWAY_URL",cwd:e,verbose:o})||await d({secretName:"GATEWAY_URL",secretValue:t,cwd:e,verbose:o,description:`Setting GATEWAY_URL to: ${t}`}),!await m({secretName:"BETTER_AUTH_SECRET",cwd:e,verbose:o})){let p=j();await d({secretName:"BETTER_AUTH_SECRET",secretValue:p,cwd:e,verbose:o,description:"Generating new Better Auth secret..."})}let n=await m({secretName:"JWT_PRIVATE_KEY",cwd:e,verbose:o}),i=await m({secretName:"JWT_PUBLIC_KEY",cwd:e,verbose:o});if(n&&i)o&&console.log(y.dim(` JWT key pair already exists
9
- `));else if(!n&&!i){o&&console.log(y.dim(` Generating new JWT key pair...
10
- `));let p=z();await d({secretName:"JWT_PRIVATE_KEY",secretValue:p.privateKey,cwd:e,verbose:o}),await d({secretName:"JWT_PUBLIC_KEY",secretValue:p.publicKey,cwd:e,verbose:o}),o&&console.log(y.green(`Created JWT key pair secrets
11
- `))}else throw new Error("JWT key pair is incomplete. Both JWT_PRIVATE_KEY and JWT_PUBLIC_KEY must exist together. Please delete the existing key and redeploy.");console.log(o?`Secret setup complete!
12
- `:` Finished.
13
- `)}catch(r){throw console.error(`
14
- Failed to setup secrets`,r instanceof Error?`
15
- ${r.message}`:""),r}}async function P({gatewayPath:t,resources:e,workerUrl:o,verbose:r=!1}){let a=q.join(t,"dist","server","wrangler.json");await _({configPath:a,d1DatabaseId:e.d1DatabaseId,kvNamespaceId:e.kvNamespaceId,verbose:r});let n=H.randomUUID();console.log(),await R("npx",["wrangler","deploy"],{cwd:t,description:`Deploying your Gateway to Cloudflare workers...
16
-
17
- This could take up to a minute.`,env:{...process.env,BETTER_AUTH_SECRET:n},verbose:r}),console.log(),await L({gatewayUrl:o,gatewayPath:t,verbose:r})}import u from"node:fs";import Q from"node:path";import{Readable as X}from"node:stream";import{pipeline as Z}from"node:stream/promises";import{createWriteStream as ee}from"node:fs";import{spawn as te}from"node:child_process";var oe="every-app",re="every-app",v="every-app-gateway-build.tar.gz";function ae(){return`https://github.com/${oe}/${re}/releases/download/gateway-latest/${v}`}async function ne(t,e){let o=await fetch(t,{redirect:"follow"});if(!o.ok)throw new Error(`Failed to download file: ${o.status} ${o.statusText}`);if(!o.body)throw new Error("Response body is null");let r=ee(e),a=X.fromWeb(o.body);await Z(a,r)}async function O(t,e){return new Promise((o,r)=>{let a=te("tar",["-xzf",t,"-C",e]);a.on("error",r),a.on("close",n=>{n===0?o():r(new Error(`tar extraction failed with code ${n}`))})})}async function I(t,e=!1){console.log("Getting latest gateway release..."),u.mkdirSync(t,{recursive:!0});let o=ae();g(e,`URL: ${o}`);let r=Q.join(t,v);try{await ne(o,r)}catch(a){throw a instanceof Error&&a.message.includes("404")?new Error("Gateway release not found. Make sure a release has been published."):a}return w(e,`Downloaded to: ${r}`,"Extracting archive..."),await O(r,t),u.unlinkSync(r),g(e,`Extraction complete
18
- `),t}async function V(t,e,o=!1){if(console.log("Using local gateway tarball..."),!u.existsSync(t))throw new Error(`Local gateway tarball not found: ${t}`);return u.mkdirSync(e,{recursive:!0}),w(o,`Tarball: ${t}`,"Extracting archive..."),await O(t,e),g(o,`Extraction complete
19
- `),e}async function N(t){try{let e=await fetch(`${t}/api/admin/has-owner`);return e.ok?(await e.json()).hasOwner:!1}catch{return!1}}async function Je(t){await E();let e=t.verbose||!1,o=t.localGateway;if(console.log(l.bold(`
20
- Every App Gateway
21
- `)),!await D("the Gateway")){console.log(`
22
- Deployment cancelled by user
23
- `);return}await A();let a=await U({verbose:e}),n=await S("gateway-deploy-");e&&console.log(l.dim(`Working directory: ${n}
24
- `));let i=null;try{let s=o?await V(o,n,e):await I(n,e),f=se.join(s,"wrangler.jsonc"),J=await K(f);i=await C(J),await P({gatewayPath:s,resources:a,workerUrl:i,verbose:e}),await $({cwd:s,verbose:e,description:"Installing dependencies for migrations..."}),await G({cwd:s,verbose:e})}catch(s){let f=await x(s);throw f&&(console.log(f.formatted),process.exit(1)),console.error(`
25
- Deployment failed:`,s instanceof Error?s.message:s),s}finally{await b({tmpDir:n,verbose:e})}if(!i)throw new Error("Worker URL not set properly during deployment");if(console.log(l.green(`
26
- Gateway deployment successful!
27
- `)),await N(i))console.log(`Your Gateway is now live at: ${l.cyan(i)}
28
- `);else{let s=`${i}/sign-up`;console.log(`Your Gateway is now live at: ${l.cyan(s)}
29
- `),console.log(l.dim(` Create an owner account to get started with your Gateway.
30
- `))}}export{Je as deploy};
@@ -1,7 +0,0 @@
1
- import{b as l,c}from"./chunk-C2ECOZQW.js";import{a as r}from"./chunk-UECRZPI5.js";import{b as t}from"./chunk-EV6OC476.js";import o from"chalk";async function u(a){await t();let e=process.cwd(),p=a.verbose||!1,n=await l(e);if(console.log(o.bold(`
2
- Project: ${n}
3
- `)),!await r("this app")){console.log(o.red(`
4
- Deployment cancelled by user
5
- `));return}let{workerUrl:s,gatewayUrl:m}=await c({cwd:e,appId:n,verbose:p});console.log(o.green(`
6
- Deployment successful!`)),console.log(o.dim(` App URL: ${o.cyan(s)}`)),console.log(` Gateway: ${o.cyan(m)}
7
- `)}export{u as deploy};