everyapp 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bash-complete.js +1 -1
- package/dist/{chunk-LEXNJEKD.js → chunk-7SUABVTF.js} +1 -1
- package/dist/chunk-A5KQS3U6.js +5 -0
- package/dist/chunk-GE6XCOLR.js +25 -0
- package/dist/{chunk-ZWOESNNW.js → chunk-JVVPUTXX.js} +1 -1
- package/dist/chunk-OICI565A.js +7 -0
- package/dist/{chunk-6ESWWGJU.js → chunk-WJ4TQGFK.js} +9 -8
- package/dist/{chunk-T47Y5E6R.js → chunk-WTPC3PFE.js} +1 -1
- package/dist/create-R6YYEX43.js +28 -0
- package/dist/deploy-3PIXBICP.js +10 -0
- package/dist/deploy-CWOGFCWP.js +41 -0
- package/dist/index.js +1 -1
- package/dist/{remoteD1Shell-CCEM2O2M.js → remoteD1Shell-Y7UQDJI3.js} +1 -1
- package/package.json +1 -1
- package/dist/chunk-3MEOBH2F.js +0 -28
- package/dist/chunk-B3H55R7L.js +0 -6
- package/dist/chunk-C6HSROI4.js +0 -5
- package/dist/create-KC6PWEDA.js +0 -28
- package/dist/deploy-MHLQR6WA.js +0 -10
- package/dist/deploy-RHHI3X3Y.js +0 -41
package/dist/bash-complete.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as o,b as s}from"./chunk-
|
|
2
|
+
import{a as o,b as s}from"./chunk-A5KQS3U6.js";import"./chunk-WTPC3PFE.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,4 +1,4 @@
|
|
|
1
|
-
import{c as h}from"./chunk-
|
|
1
|
+
import{c as h}from"./chunk-JVVPUTXX.js";import D from"node:fs/promises";import m from"node:path";import I from"node:os";import*as y from"smol-toml";import i from"chalk";function R(){let e=I.homedir(),t=I.platform(),n;return t==="win32"?n=m.join(process.env.LOCALAPPDATA||m.join(e,"AppData","Local"),".wrangler"):t==="darwin"?n=m.join(e,"Library","Preferences",".wrangler"):n=m.join(e,".wrangler"),m.join(n,"config","default.toml")}async function L(){let e=R();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 T(e){let t=R(),n=m.dirname(t);await D.mkdir(n,{recursive:!0});let o=y.stringify(e);await D.writeFile(t,o,"utf-8")}function F(e){let t=new Date(e).getTime(),n=Date.now(),o=1*60*1e3;return t-n<o}async function U(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 $(e={}){let{showNewUserHelp:t=!1}=e,n=!!process.env.CLOUDFLARE_API_TOKEN,o=!!process.env.CLOUDFLARE_ACCOUNT_ID;if(n&&!o&&(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>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{a as t,b as a,c as r}from"./chunk-WTPC3PFE.js";import s from"node:fs";import p from"node:os";import l from"node:path";function R(e){return{process:e,os:p,fs:s,path:l}}import{buildApplication as g,buildRouteMap as h}from"@stricli/core";import{buildInstallCommand as C,buildUninstallCommand as D}from"@stricli/auto-complete";import{buildCommand as o,buildRouteMap as d}from"@stricli/core";var m=o({loader:async()=>import("./create-R6YYEX43.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-3PIXBICP.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{remoteD1Shell:e}=await import("./remoteD1Shell-Y7UQDJI3.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(`
|
|
4
|
+
`)}}),n=d({routes:{create:m,deploy:u,"remote-d1-shell":c},docs:{brief:"App management commands"}});import{buildCommand as f,buildRouteMap as y}from"@stricli/core";var b=f({loader:async()=>{let{deploy:e}=await import("./deploy-CWOGFCWP.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(`
|
|
5
|
+
`)}}),i=y({routes:{deploy:b},docs:{brief:"Gateway management commands"}});var w=h({routes:{app:n,gateway:i,install:C("everyapp",{bash:"__everyapp_bash_complete"}),uninstall:D("everyapp",{bash:!0})},docs:{brief:a,hideRoute:{install:!0,uninstall:!0}}}),U=g(w,{name:t,versionInfo:{currentVersion:r},scanner:{allowArgumentEscapeSequence:!0}});export{R as a,U as b};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import{b as v,f as M,i as q,k as T,l as P}from"./chunk-WJ4TQGFK.js";import{a as B,c as h,e as I,g as _,h as V,i as L,j,k as F,l as U,q as W,s as K}from"./chunk-7SUABVTF.js";import{c as C}from"./chunk-JVVPUTXX.js";import Y from"node:fs/promises";import z from"node:path";import*as Q from"jsonc-parser";import{z as A}from"zod";var J="every-app.jsonc",ae=A.object({appId:A.string().min(1,"appId cannot be empty"),displayName:A.string().min(1,"displayName cannot be empty").optional(),description:A.string().optional()});async function x(e){let t=z.join(e,J);try{let o=await Y.readFile(t,"utf-8"),r=Q.parse(o);return ae.parse(r)}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 A.ZodError){let r=o.issues.map(n=>n.message).join(", ");throw new Error(`Invalid every-app.jsonc: ${r}`)}throw o}}function ie(e){return e.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}async function ke(e,t){let o=z.join(e,J),r={...t,displayName:t.displayName??ie(t.appId)},n=JSON.stringify(r,null,2)+`
|
|
2
|
+
`;await Y.writeFile(o,n)}async function Re(e){return(await x(e)).appId}var H="GATEWAY_URL",Z="GATEWAY_APP_API_TOKEN",ce="/api/internal/app-token/provision",pe=["provider:openai"];function le(e){if(!e.trim())return null;try{return JSON.parse(e)}catch{return null}}function X(e){if(!e||typeof e!="object")return null;let t=e.error;return typeof t!="string"||!t.trim()?null:t}async function de({gatewayUrl:e,appId:t}){let o=await h(),r=await fetch(`${e}${ce}`,{method:"POST",headers:{authorization:`Bearer ${o}`,"content-type":"application/json"},body:JSON.stringify({appSlug:t,scopes:pe})}),n=await r.text(),s=le(n);if(!r.ok){let a=X(s)||`Gateway token provisioning failed with status ${r.status}`;throw r.status===401||r.status===403?new Error(`${a}. Ensure your Cloudflare credentials target the same account that hosts this gateway.`):r.status===404?new Error("Gateway does not support token provisioning yet. Redeploy the gateway with `npx everyapp gateway deploy` and try again."):r.status===409?new Error(`${X(s)||"Gateway rejected token provisioning with a conflict"}. If this gateway is outdated, run \`npx everyapp gateway deploy\` and try again.`):new Error(a)}let i=s?.token;if(typeof i!="string"||!i.trim())throw new Error("Gateway returned an invalid token provisioning response");return i}async function ee({gatewayUrl:e,appPath:t,appId:o,verbose:r=!1}){r&&console.log("Configuring Secrets...");try{if(await T({secretName:H,cwd:t,verbose:r})||await P({secretName:H,secretValue:e,cwd:t,verbose:r,description:`Setting GATEWAY_URL to: ${e}`}),!await T({secretName:Z,cwd:t,verbose:r})){r&&console.log("Provisioning gateway app API token...");let i=await de({gatewayUrl:e,appId:o});await P({secretName:Z,secretValue:i,cwd:t,verbose:r,description:"Setting GATEWAY_APP_API_TOKEN for gateway requests"})}r&&console.log(`Secret setup complete!
|
|
3
|
+
`)}catch(n){throw console.error(`
|
|
4
|
+
Failed to setup secrets`,n instanceof Error?`
|
|
5
|
+
${n.message}`:""),n}}import p from"chalk";async function te({appId:e,needsR2Bucket:t=!1,verbose:o=!1}){console.log(`
|
|
6
|
+
Setting up your Cloudflare ${t?"D1 Database, KV Store, and R2 Bucket":"D1 Database and KV Store"}...
|
|
7
|
+
`);let n=await I(),s=B(e),i;t&&(i=await fe(s,n,o));let a=await ue(s,n,o),c=await ge(s,n,o);return{d1DatabaseId:a,kvNamespaceId:c,r2BucketName:i,resourceName:s}}async function ue(e,t,o){o&&(console.log(p.bold(`Processing D1 database...
|
|
8
|
+
`)),console.log(` Checking D1 database: ${e}`));let r=await L(e,t);return o?r.wasCreated?console.log(p.green(` Created D1 database: ${e} (${r.id})
|
|
9
|
+
`)):console.log(p.dim(` Linking to existing D1 database: ${e} (${r.id})
|
|
10
|
+
`)):r.wasCreated?console.log(p.green(" D1 successfully created.")):console.log(" D1 already set up."),r.id}async function ge(e,t,o){o&&(console.log(p.bold(`Processing KV namespace...
|
|
11
|
+
`)),console.log(` Checking KV namespace: ${e}`));let r=await j(e,t);return o?r.wasCreated?console.log(p.green(` Created KV namespace: ${e} (${r.id})
|
|
12
|
+
`)):console.log(p.dim(` Linking to existing KV namespace: ${e} (${r.id})
|
|
13
|
+
`)):r.wasCreated?console.log(p.green(" KV successfully created.")):console.log(" KV already set up."),r.id}async function fe(e,t,o){o&&(console.log(p.bold(`Processing R2 bucket...
|
|
14
|
+
`)),console.log(` Checking R2 bucket: ${e}`));let r;try{r=await F(e,t)}catch(n){let s=await U(n,{accountId:t});throw s&&(console.log(s.formatted),await C(1)),n}return o?r.wasCreated?console.log(p.green(` Created R2 bucket: ${e}
|
|
15
|
+
`)):console.log(p.dim(` Linking to existing R2 bucket: ${e}
|
|
16
|
+
`)):r.wasCreated?console.log(p.green(" R2 successfully created.")):console.log(" R2 already set up."),r.name}import me from"chalk";async function re({cwd:e,gatewayUrl:t,appId:o,verbose:r}){let n={...process.env,VITE_GATEWAY_URL:t,VITE_APP_ID:o};try{await v("npx",["vite","build"],{cwd:e,description:`Building your application...
|
|
17
|
+
`,env:n,verbose:r}),await v("npx",["wrangler","deploy"],{cwd:e,description:`Deploying your application to Cloudflare workers...
|
|
18
|
+
|
|
19
|
+
This could take up to a minute.`,env:n,verbose:r})}catch(s){let i=await U(s);throw i&&(console.log(i.formatted),await C(1)),console.error(me.red(`
|
|
20
|
+
Failed to build or deploy`)),s}}import m from"chalk";import G from"enquirer";var ye="every-app-gateway";async function S(){let e=await I(),o=(await V(e)).find(r=>r.name===ye);return o?{accountId:e,databaseId:o.uuid}:null}import E from"chalk";async function u(e,t,o,r){try{let n=await h(),s={sql:o};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 ${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(E.red(`
|
|
21
|
+
D1 Query Error:`)),console.error(E.dim(`SQL: ${o}`)),console.error(E.dim(`Error: ${l}`)),new Error(`D1 query failed: ${l}`)}let c=a.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(n){throw n instanceof Error&&!n.message.includes("D1 query failed")&&(console.error(E.red(`
|
|
22
|
+
D1 Query Error:`)),console.error(E.dim(`SQL: ${o}`))),n}}async function N(e){return u(e.accountId,e.databaseId,"SELECT id, name, email FROM users")}import{randomUUID as oe}from"node:crypto";async function k(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 $(e,t){let o=await k(e,t.appId),r=Date.now(),n=t.isDefault??!!(o?.is_default??0);if(o){let i=t.devUrl??o.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,n?1:0,r,o.id]),o.id}let s=oe();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,n?1:0,r,r]),s}async function we(e,t,o){return(await u(e.accountId,e.databaseId,"SELECT id FROM user_app_access WHERE user_id = ? AND app_id = ?",[t,o])).length>0}async function O(e,t,o){if(await we(e,t,o))return{created:!1};let n=Date.now(),s=oe();return await u(e.accountId,e.databaseId,"INSERT INTO user_app_access (id, user_id, app_id, granted_at, granted_by) VALUES (?, ?, ?, ?, ?)",[s,t,o,n,null]),{created:!0}}async function ne(e){let{appId:t,appUrl:o,verbose:r=!1,appName:n,appDescription:s,devUrl:i}=e;try{console.log(""),r&&console.log("Adding apps to user gateways...");let a=await S();if(!a){console.warn(m.yellow(`every-app-gateway database not found. Skipping UserApp record creation.
|
|
23
|
+
`));return}let c=await N(a),g=await k(a,t),l=g===null,d=n||t,D=s||t;!l&&r&&console.log(m.dim("App already configured in gateway. Skipping access prompts."));let y=l?await Ee("Add future users by default to this app?"):!!g?.is_default,w=l?await De():"none",R=[];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"?R=c.map(f=>f.id):w==="select"&&(R=await be(c));let se=await $(a,{appId:t,appUrl:o,name:d,description:D,devUrl:i,isDefault:y}),b=c.filter(f=>R.includes(f.id));r&&b.length>1&&console.log(m.yellow(`Adding app to ${b.length} user(s)...
|
|
24
|
+
`));for(let f of b)await Ae(a,f,{appRecordId:se,verbose:r});if(r){let f=w==="all"?"all users":w==="select"?`${b.length} selected users`:"no users";console.log(m.dim(` Default access: ${y?"enabled":"disabled"}`)),console.log(m.dim(` Access granted to ${f}
|
|
25
|
+
`))}}catch(a){throw console.error(m.red("Failed to insert UserApp records:"),a instanceof Error?a.message:a),a}}async function Ae(e,t,o){let{verbose:r,appRecordId:n}=o;(await O(e,t.id,n)).created?console.log(` UserApp record created for user ${t.name} (${t.email})`):r&&console.log(m.dim(` UserApp record already exists for user ${t.name} (${t.email})`))}async function Ee(e){let{confirm:t}=await G.prompt({type:"confirm",name:"confirm",message:e,initial:!0});return t}async function De(){let{mode:e}=await G.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 be(e){let{selected:t}=await G.prompt({type:"multiselect",name:"selected",message:"Select users to grant access",choices:e.map(o=>({name:o.id,message:Ce(o)}))});return t}function Ce(e){return e.name&&e.name.trim()?`${e.name} <${e.email}>`:e.email}async function ft(e){let{cwd:t,appId:o,verbose:r,devUrl:n}=e,i=!!(await K(t)).r2_buckets?.length,{d1DatabaseId:a,kvNamespaceId:c,r2BucketName:g,resourceName:l}=await te({appId:o,needsR2Bucket:i,verbose:r});await W({configPath:t,name:l,d1DatabaseId:a,d1DatabaseName:l,kvNamespaceId:c,r2BucketName:g,verbose:r});let d=await _("every-app-gateway");console.log(),await M({cwd:t,description:"Installing dependencies for Cloudflare deployment...",verbose:r}),await q({cwd:t,verbose:r}),await re({cwd:t,gatewayUrl:d,appId:o,verbose:r});let D=await _(l),y=await x(t);return await ne({appId:o,appUrl:D,verbose:r,appName:y.displayName,appDescription:y.description,devUrl:n}),await ee({gatewayUrl:d,appPath:t,appId:o,verbose:r}),{workerUrl:D,gatewayUrl:d}}export{ke as a,Re as b,de as c,ft as d};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as n}from"./chunk-
|
|
1
|
+
import{c as n}from"./chunk-WTPC3PFE.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};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{g as p}from"./chunk-7SUABVTF.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
|
+
`:"",s=`# Vite client-side secrets
|
|
3
|
+
VITE_APP_ID=${t}
|
|
4
|
+
VITE_GATEWAY_URL=${a}
|
|
5
|
+
# Set Cloudflare secrets locally
|
|
6
|
+
GATEWAY_URL=${a}
|
|
7
|
+
${i}`;await Promise.all([r.writeFile(c.join(e,".env.local"),s)])}async function E(e){return await r.mkdtemp(c.join(f.tmpdir(),e))}async function x({tmpDir:e,verbose:t=!1}){try{await r.rm(e,{recursive:!0,force:!0}),t&&console.log(m.dim(` Removed: ${e}`))}catch{console.warn(m.yellow("\u26A0\uFE0F Warning: Failed to clean up temporary directory:"),e)}}export{u as a,T as b,D as c,E as d,x as e};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import{d as u,e as f,f as
|
|
1
|
+
import{d as u,e as f,f as b,g as O,m as C,n as k,o as I,r as A,u as E}from"./chunk-7SUABVTF.js";import{c as m}from"./chunk-JVVPUTXX.js";import L from"enquirer";import d from"chalk";async function W(){if(process.env.CLOUDFLARE_API_TOKEN){let n=process.env.CLOUDFLARE_ACCOUNT_ID;return n?b(n):(console.log(d.yellow(`
|
|
2
2
|
CLOUDFLARE_ACCOUNT_ID is required when using CLOUDFLARE_API_TOKEN
|
|
3
|
-
`)),m(1))}let o=await
|
|
3
|
+
`)),m(1))}let o=await C(),{account:e,otherAccounts:t}=await I(o);return k(e,t),{id:e.account.id,name:e.account.name}}async function H(o="this",e=!1){let t=await W();if(process.env.CLOUDFLARE_API_TOKEN&&(console.log(d.dim(` ${t.name} (${t.id})`)),console.log()),e)return console.log(d.dim(`Skipping deployment confirmation due to -y flag.
|
|
4
|
+
`)),!0;let{confirm:n}=await L.prompt({type:"confirm",name:"confirm",message:`Do you want to deploy ${o} to ${t.name}?`,initial:!1});return n}import p from"chalk";var S="every-app-gateway";async function oe(o){try{return await fetch(o,{method:"HEAD",signal:AbortSignal.timeout(5e3)}),!0}catch(e){let t=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(i=>t.includes(i)||n.includes(i))}}async function _(o){try{let e=await fetch(`${o}/api/admin/has-owner`);return e.ok?(await e.json()).hasOwner:!1}catch{return!1}}async function G(){try{let o=await f();return await u(`/accounts/${o}/workers/scripts/${S}/settings`),!0}catch{return!1}}async function D(){return O(S)}async function F(){if(!await G())return{isDeployed:!1,hasOwner:!1,gatewayUrl:await D()};let e=await D();return{isDeployed:!0,hasOwner:await _(e),gatewayUrl:e}}async function te(){let{isDeployed:o,hasOwner:e,gatewayUrl:t}=await F();if(o||(console.log(p.yellow(`
|
|
4
5
|
Gateway not deployed
|
|
5
6
|
`)),console.log(`You need to deploy the Every App Gateway before creating or deploying apps.
|
|
6
7
|
`),console.log(p.dim(` Run: npx everyapp gateway deploy
|
|
@@ -9,12 +10,12 @@ Owner account required
|
|
|
9
10
|
`)),console.log(`You need to create an owner account on your Gateway before deploying apps.
|
|
10
11
|
`),console.log(` ${p.cyan(n)}
|
|
11
12
|
`),console.log(p.dim(` Visit the URL above to create your owner account, then run this command again.
|
|
12
|
-
`)),await m(1)}return t}import{execa as T}from"execa";import{execa as
|
|
13
|
+
`)),await m(1)}return t}import{execa as T}from"execa";import{execa as w}from"execa";import c from"chalk";async function y(o,e,t){let{env:n,cwd:s,verbose:r=!1,description:i,logCommandToConsole:l=!0}=t;return r?M(o,e,t):l?(console.log(`Running: ${o} ${e.join(" ")}`),i&&console.log(c.dim(` ${i}`)),await w(o,e,{cwd:s,env:n,stdio:"pipe"})):await w(o,e,{cwd:s,env:n,stdio:"pipe"})}async function M(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=w(o,e,{cwd:n,env:s,stdio:void 0,all:!0});r.stdout&&r.stdout.on("data",l=>{l.toString().split(`
|
|
13
14
|
`).forEach(a=>{a.trim()&&console.log(c.dim(` \u2502 ${a}`))})}),r.stderr&&r.stderr.on("data",l=>{l.toString().split(`
|
|
14
15
|
`).forEach(a=>{a.trim()&&console.error(c.dim(` \u2502 ${a}`))})});let i=await r;return console.log(c.dim(` \u2514\u2500 Complete
|
|
15
|
-
`)),i}async function z(){try{return await T("pnpm",["--version"],{stdio:"pipe"}),!0}catch{return!1}}async function le({cwd:o,description:e,verbose:t=!1}){let n=await z();try{n?await
|
|
16
|
-
Running: ${R} ${U.join(" ")}`),console.log(v.dim(" Running database migrations...")),P(e," Running any pending migrations against your remote D1 Database..."),await
|
|
17
|
-
`))}import g from"chalk";import j from"node:path";async function
|
|
16
|
+
`)),i}async function z(){try{return await T("pnpm",["--version"],{stdio:"pipe"}),!0}catch{return!1}}async function le({cwd:o,description:e,verbose:t=!1}){let n=await z();try{n?await y("pnpm",["install"],{cwd:o,verbose:t,description:e}):await y("npx",["pnpm","install"],{cwd:o,verbose:t,description:e})}catch(s){throw new Error(`Failed to install dependencies with pnpm: ${s instanceof Error?s.message:"Unknown error"}`)}}import v from"chalk";import $ from"chalk";function pe(o,e){o&&console.log($.dim(e))}function P(o,...e){o&&e.forEach(t=>console.log($.dim(t)))}var R="npx",U=["drizzle-kit","migrate","--config=drizzle-prod.config.ts"];async function ye({cwd:o,verbose:e=!1}){console.log(`
|
|
17
|
+
Running: ${R} ${U.join(" ")}`),console.log(v.dim(" Running database migrations...")),P(e," Running any pending migrations against your remote D1 Database..."),await E(R,U,{cwd:o,verbose:e}),console.log(v.dim(` Migrations completed.
|
|
18
|
+
`))}import g from"chalk";import j from"node:path";async function h(o){let e=await f(),t=j.join(o,"wrangler.jsonc"),n=await A(t);return{accountId:e,workerName:n}}async function N(o){return await u(`/accounts/${o.accountId}/workers/scripts/${o.workerName}/secrets`)}async function ke({cwd:o}){let e=await h(o);return(await N(e)).map(n=>n.name)}async function Ie({secretName:o,cwd:e,verbose:t=!1}){t&&console.log(g.dim(` Checking secret: ${o}`));let n=await h(e),r=(await N(n)).some(i=>i.name===o);return r&&t&&console.log(g.dim(` Secret already exists
|
|
18
19
|
`)),r}async function Ae({secretName:o,secretValue:e,cwd:t,verbose:n=!1,description:s}){n&&s&&console.log(g.dim(` ${s}
|
|
19
|
-
`));let r=await
|
|
20
|
-
`))}export{H as a,
|
|
20
|
+
`));let r=await h(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(g.green(`Created secret: ${o}
|
|
21
|
+
`))}export{H as a,y as b,oe as c,_ as d,te as e,le as f,pe as g,P as h,ye as i,ke as j,Ie as k,Ae as l};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var p="everyapp";var i="Every App CLI - Deploy and manage apps.";var n="0.1.
|
|
1
|
+
var p="everyapp";var i="Every App CLI - Deploy and manage apps.";var n="0.1.6";export{p as a,i as b,n as c};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import{a as x,c as P,d as T}from"./chunk-GE6XCOLR.js";import{a as u,b as w,c as h,d as C,e as k}from"./chunk-OICI565A.js";import{a as v,b as i,e as b}from"./chunk-WJ4TQGFK.js";import{b as y}from"./chunk-7SUABVTF.js";import{c as s}from"./chunk-JVVPUTXX.js";import"./chunk-WTPC3PFE.js";import f from"chalk";async function A({url:o,targetDir:e,verbose:t=!1}){try{await i("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 E({targetDir:o,verbose:e=!1}){try{await i("git",["init"],{verbose:e,logCommandToConsole:!1,cwd:o}),await i("git",["add","."],{verbose:e,logCommandToConsole:!1,cwd:o}),await i("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 G from"node:fs/promises";import _ from"node:path";import d from"chalk";var M=["every-app.jsonc","every-app.json"];async function D(){let o=process.cwd();for(let e of M){let t=_.join(o,e);try{await G.access(t),console.log(d.yellow(`
|
|
2
|
+
Already inside an Every App project`)),console.log(d.dim(` Found ${e}
|
|
3
|
+
`)),console.log(`To create a new app, run app create from the directory where you store your projects.
|
|
4
|
+
`),console.log("If you meant to deploy this app, run:"),console.log(d.dim(` npx everyapp app deploy
|
|
5
|
+
`)),await s(1)}catch{}}}import I from"chalk";import{execa as q}from"execa";async function R(){try{await q("pnpm",["--version"],{stdio:"pipe"})}catch{console.error(I.red(`
|
|
6
|
+
Error: pnpm is required but not installed. Please install it first:`)),console.error(I.cyan(` npm i -g pnpm
|
|
7
|
+
`)),await s(1)}}import W from"enquirer";function z(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 F(o){console.log(`Project Configuration
|
|
8
|
+
`);let e=await W.prompt({type:"input",name:"appId",message:"Enter your app ID (kebab-case format)",initial:o,validate:z});return console.log(),{appId:e.appId}}import O from"node:path";import V from"chalk";var Y="https://github.com/every-app/every-app.git",H="templates/simple-todo";async function U({appId:o,verbose:e=!1}){e&&console.log(`Cloning template repository...
|
|
9
|
+
`);let t=await C("every-app-create-");await A({url:Y,targetDir:t,verbose:e}),e&&console.log(`Extracting template...
|
|
10
|
+
`);let a=O.join(t,H),n=O.join(process.cwd(),o);if(await w(n))throw new Error(`Directory "${o}" already exists in the current location`);return await u(a,n,{exclude:["node_modules",".git","pnpm-lock.yaml","package-lock.json",".env.local",".env.production",".dev.vars","manual-steps.md"]}),e&&console.log(V.dim(` Template copied to ${n}
|
|
11
|
+
`)),{tempDir:t,targetDir:n}}import $ from"node:fs/promises";import B from"node:path";async function j({targetDir:o,appId:e}){let t=B.join(o,"package.json"),a=JSON.parse(await $.readFile(t,"utf-8"));a.name=e,await $.writeFile(t,JSON.stringify(a,null,2)+`
|
|
12
|
+
`,"utf-8")}import g from"chalk";async function N({targetDir:o,verbose:e=!1}){try{e||console.log(`
|
|
13
|
+
Setting up Cloudflare for local dev...`),await i("pnpm",["run","cf-typegen"],{cwd:o,verbose:e,logCommandToConsole:!1}),await i("pnpm",["run","build"],{cwd:o,verbose:e,logCommandToConsole:!1}),e||console.log(g.dim(` Finished.
|
|
14
|
+
`)),await i("pnpm",["run","db:migrate:local"],{cwd:o,verbose:e}),console.log(`
|
|
15
|
+
Local database migrations complete.
|
|
16
|
+
`)}catch{console.warn(g.yellow(`
|
|
17
|
+
Failed to run local migrations. You can run them manually with:`)),console.warn(g.dim(` pnpm run db:migrate:local
|
|
18
|
+
`))}}import r from"chalk";function L({appId:o,targetDir:e,gatewayUrl:t,workerUrl:a}){console.log(r.green(`Project created and deployed successfully!
|
|
19
|
+
`)),console.log(r.dim(` Location: ${e}`)),console.log(r.dim(` App URL: ${r.cyan(a)}`)),console.log(r.dim(` Gateway: ${r.cyan(t)}`)),console.log(),console.log(`For local development:
|
|
20
|
+
`),console.log(r.dim(` ${r.bold(`cd ${o}`)}`)),console.log(r.dim(` ${r.bold("pnpm run dev")}`)),console.log(r.dim(` ${r.bold(`
|
|
21
|
+
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:
|
|
22
|
+
`),console.log(r.dim(` ${r.bold("npx everyapp app deploy")}`)),console.log()}async function Go(o,e){let t=o.verbose||!1,a=o.yes||!1;await D(),await R(),await y(),await b(),console.log(`
|
|
23
|
+
Create a new Every App project
|
|
24
|
+
`);let{appId:n}=await F(e);if(console.log(f.dim(`.
|
|
25
|
+
`)),!await v("this app",a)){console.log(f.yellow(`
|
|
26
|
+
App creation cancelled.
|
|
27
|
+
`));return}let c=null;try{let{tempDir:l,targetDir:p}=await U({appId:n,verbose:t});c=l,await j({targetDir:p,appId:n}),await x(p,{appId:n});let{workerUrl:S,gatewayUrl:m}=await T({cwd:p,appId:n,verbose:t,devUrl:"http://localhost:3001"}),J=await P({gatewayUrl:m,appId:n});await h({targetDir:p,appId:n,gatewayUrl:m,gatewayAppApiToken:J}),await N({targetDir:p,verbose:t}),await E({targetDir:p,verbose:t}),L({appId:n,targetDir:p,gatewayUrl:m,workerUrl:S})}catch(l){throw console.error(f.red(`
|
|
28
|
+
Failed to create project:`),l instanceof Error?l.message:"Unknown error"),l}finally{c&&await k({tmpDir:c})}}export{Go as default};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{b as i,d as m}from"./chunk-GE6XCOLR.js";import{a as s,e as l}from"./chunk-WJ4TQGFK.js";import{b as p}from"./chunk-7SUABVTF.js";import{c as a}from"./chunk-JVVPUTXX.js";import"./chunk-WTPC3PFE.js";import o from"chalk";import u from"node:fs/promises";import g from"node:path";import n from"chalk";var h=["every-app.jsonc","every-app.json"];async function f(){let e=process.cwd();for(let r of h){let t=g.join(e,r);try{await u.access(t);return}catch{}}console.log(n.yellow(`
|
|
2
|
+
Not inside an Every App project`)),console.log(n.dim(` No every-app.jsonc found
|
|
3
|
+
`)),console.log("To create a new app, run the below command from the directory where you store your projects:"),console.log(n.dim(` npx everyapp app create
|
|
4
|
+
`)),await a(1)}async function N(e){await p(),await l();let r=process.cwd(),t=e.verbose||!1,y=e.yes||!1;await f();let c=await i(r);if(console.log(o.bold(`
|
|
5
|
+
Project: ${c}
|
|
6
|
+
`)),!await s("this app",y)){console.log(o.red(`
|
|
7
|
+
Deployment cancelled by user
|
|
8
|
+
`));return}let{workerUrl:d,gatewayUrl:w}=await m({cwd:r,appId:c,verbose:t});console.log(o.green(`
|
|
9
|
+
Deployment successful!`)),console.log(o.dim(` App URL: ${o.cyan(d)}`)),console.log(` Gateway: ${o.cyan(w)}
|
|
10
|
+
`)}export{N as deploy};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import{d as U,e as L}from"./chunk-OICI565A.js";import{a as W,b as G,c as y,d as E,f as K,g as h,h as S,i as P,j as I,l as m}from"./chunk-WJ4TQGFK.js";import{b as A,e as R,g as _,i as b,j as k,l as D,p as x,q as $,r as v}from"./chunk-7SUABVTF.js";import{c as T}from"./chunk-JVVPUTXX.js";import"./chunk-WTPC3PFE.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
|
+
Setting up your Cloudflare D1 Database and KV Store...
|
|
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
|
+
`)):console.log(d.dim(` Linking to existing D1 database: ${e} (${t.id})
|
|
5
|
+
`)):t.wasCreated?console.log(d.green(` D1 successfully created.
|
|
6
|
+
`)):console.log(" D1 already set up."),t.id}async function X(e,o,a){a&&console.log(` Checking KV namespace: ${e}`);let t=await k(e,o);return a?t.wasCreated?console.log(d.green(` Created KV namespace: ${e} (${t.id})
|
|
7
|
+
`)):console.log(d.dim(` Linking to existing KV namespace: ${e} (${t.id})
|
|
8
|
+
`)):t.wasCreated?console.log(d.green(" KV successfully created.")):console.log(" KV already set up."),t.id}import te from"node:crypto";import oe from"node:path";import N from"node:crypto";import f from"chalk";function Z(){return N.randomBytes(32).toString("base64")}function ee(){let{privateKey:e,publicKey:o}=N.generateKeyPairSync("rsa",{modulusLength:2048,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}});return{privateKey:e,publicKey:o}}async function V({gatewayUrl:e,cloudflareAccountId:o,gatewayPath:a,verbose:t=!1}){try{let r=new Set(await I({cwd:a})),i=r.has("GATEWAY_URL"),p=r.has("CLOUDFLARE_ACCOUNT_ID"),s=r.has("BETTER_AUTH_SECRET"),u=r.has("JWT_PRIVATE_KEY"),w=r.has("JWT_PUBLIC_KEY"),n=!s||!u||!w;if(n&&(console.log("Configuring secrets for the authentication service (Better Auth)..."),console.log(f.dim(" BETTER_AUTH_SECRET - Session signing and encryption")),console.log(f.dim(" JWT_PRIVATE_KEY - Signs JWTs issued to your apps")),console.log(f.dim(" JWT_PUBLIC_KEY - Apps use this to verify JWTs")),console.log()),i||await m({secretName:"GATEWAY_URL",secretValue:e,cwd:a,verbose:t,description:`Setting GATEWAY_URL to: ${e}`}),p||await m({secretName:"CLOUDFLARE_ACCOUNT_ID",secretValue:o,cwd:a,verbose:t,description:`Setting CLOUDFLARE_ACCOUNT_ID to: ${o}`}),!s){let l=Z();await m({secretName:"BETTER_AUTH_SECRET",secretValue:l,cwd:a,verbose:t,description:"Generating new Better Auth secret..."})}if(u&&w)t&&console.log(f.dim(` JWT key pair already exists
|
|
9
|
+
`));else if(!u&&!w){t&&console.log(f.dim(` Generating new JWT key pair...
|
|
10
|
+
`));let l=ee();await m({secretName:"JWT_PRIVATE_KEY",secretValue:l.privateKey,cwd:a,verbose:t}),await m({secretName:"JWT_PUBLIC_KEY",secretValue:l.publicKey,cwd:a,verbose:t}),t&&console.log(f.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.");n&&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 J({gatewayPath:e,resources:o,workerUrl:a,verbose:t=!1}){let r=oe.join(e,"dist","server","wrangler.json");await $({configPath:r,d1DatabaseId:o.d1DatabaseId,kvNamespaceId:o.kvNamespaceId,verbose:t});let i=te.randomUUID();console.log(),await G("npx",["wrangler","deploy"],{cwd:e,description:`Deploying your Gateway to Cloudflare workers...
|
|
16
|
+
|
|
17
|
+
This could take up to a minute.`,env:{...process.env,BETTER_AUTH_SECRET:i},verbose:t}),console.log(),await V({gatewayUrl:a,cloudflareAccountId:o.accountId,gatewayPath:e,verbose:t})}import C from"node:fs";import ae from"node:path";import{Readable as re}from"node:stream";import{pipeline as ne}from"node:stream/promises";import{createWriteStream as ie}from"node:fs";import{spawn as se}from"node:child_process";var ce="every-app",le="every-app",Y="every-app-gateway-build.tar.gz";function pe(){return`https://github.com/${ce}/${le}/releases/download/gateway-latest/${Y}`}async function me(e,o){let a=await fetch(e,{redirect:"follow"});if(!a.ok)throw new Error(`Failed to download file: ${a.status} ${a.statusText}`);if(!a.body)throw new Error("Response body is null");let t=ie(o),r=re.fromWeb(a.body);await ne(r,t)}async function B(e,o){return new Promise((a,t)=>{let r=se("tar",["-xzf",e,"-C",o]);r.on("error",t),r.on("close",i=>{i===0?a():t(new Error(`tar extraction failed with code ${i}`))})})}async function F(e,o=!1){console.log("Getting latest gateway release..."),C.mkdirSync(e,{recursive:!0});let a=pe();h(o,`URL: ${a}`);let t=ae.join(e,Y);try{await me(a,t)}catch(r){throw r instanceof Error&&r.message.includes("404")?new Error("Gateway release not found. Make sure a release has been published."):r}return S(o,`Downloaded to: ${t}`,"Extracting archive..."),await B(t,e),C.unlinkSync(t),h(o,`Extraction complete
|
|
18
|
+
`),e}async function M(e,o,a=!1){if(console.log("Using local gateway tarball..."),!C.existsSync(e))throw new Error(`Local gateway tarball not found: ${e}`);return C.mkdirSync(o,{recursive:!0}),S(a,`Tarball: ${e}`,"Extracting archive..."),await B(e,o),h(a,`Extraction complete
|
|
19
|
+
`),o}import c from"chalk";async function H({workerUrl:e,maxWaitMs:o=12e4,pollIntervalMs:a=3e3}){let t=`${e}/sign-up`;console.log(c.green(`
|
|
20
|
+
Gateway deployment successful!
|
|
21
|
+
`)),console.log(`Your Gateway will be available at: ${c.cyan(t)}
|
|
22
|
+
`),console.log(c.dim("Waiting for SSL certificate to be provisioned..."));let r=Date.now();for(;Date.now()-r<o;)if(await new Promise(i=>setTimeout(i,a)),await y(e)){console.log(c.green(`SSL certificate is ready!
|
|
23
|
+
`)),await E(e)?console.log(`Your Gateway is now live at: ${c.cyan(e)}
|
|
24
|
+
`):(console.log(`Your Gateway is now live at: ${c.cyan(t)}
|
|
25
|
+
`),console.log(c.dim(` Create an owner account to get started with your Gateway.
|
|
26
|
+
`)));return}console.log(c.yellow(`
|
|
27
|
+
SSL certificate is still being provisioned. This can take a few minutes.
|
|
28
|
+
`)),console.log(c.dim(` The URL above will be accessible once the SSL certificate is ready.
|
|
29
|
+
`)),console.log(c.dim(` Create an owner account to get started with your Gateway.
|
|
30
|
+
`))}async function Xe(e){await A({showNewUserHelp:!0});let o=e.verbose||!1,a=e.localGateway,t=e.yes||!1;if(console.log(g.bold(`
|
|
31
|
+
Every App Gateway
|
|
32
|
+
`)),!await W("the Gateway",t)){console.log(`
|
|
33
|
+
Deployment cancelled by user
|
|
34
|
+
`);return}await x();let i=await O({verbose:o}),p=await U("gateway-deploy-");o&&console.log(g.dim(`Working directory: ${p}
|
|
35
|
+
`));let s=null;try{let n=a?await M(a,p,o):await F(p,o),l=de.join(n,"wrangler.jsonc"),z=await v(l);s=await _(z),await J({gatewayPath:n,resources:i,workerUrl:s,verbose:o}),await K({cwd:n,verbose:o,description:"Installing dependencies for migrations..."}),await P({cwd:n,verbose:o})}catch(n){let l=await D(n);throw l&&(console.log(l.formatted),await T(1)),console.error(`
|
|
36
|
+
Deployment failed:`,n instanceof Error?n.message:n),n}finally{await L({tmpDir:p,verbose:o})}if(!s)throw new Error("Worker URL not set properly during deployment");if(!await y(s)){await H({workerUrl:s});return}if(console.log(g.green(`
|
|
37
|
+
Gateway deployment successful!
|
|
38
|
+
`)),await E(s))console.log(`Your Gateway is now live at: ${g.cyan(s)}
|
|
39
|
+
`);else{let n=`${s}/sign-up`;console.log(`Your Gateway is now live at: ${g.cyan(n)}
|
|
40
|
+
`),console.log(g.dim(` Create an owner account to get started with your Gateway.
|
|
41
|
+
`))}}export{Xe as deploy};
|
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-
|
|
2
|
+
import{a as i,b as t}from"./chunk-A5KQS3U6.js";import{a as r,b as o}from"./chunk-JVVPUTXX.js";import"./chunk-WTPC3PFE.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{b as i,t as a}from"./chunk-
|
|
1
|
+
import{b as i,t as a}from"./chunk-7SUABVTF.js";import"./chunk-JVVPUTXX.js";import"./chunk-WTPC3PFE.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(`
|
package/package.json
CHANGED
package/dist/chunk-3MEOBH2F.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import{b as U,f as _,i as G,k as V,l as j}from"./chunk-6ESWWGJU.js";import{a as k,c as x,e as w,g as A,h as $,i as P,j as S,k as T,l as b,q as N,s as O}from"./chunk-LEXNJEKD.js";import{c as y}from"./chunk-ZWOESNNW.js";import B from"node:fs/promises";import L from"node:path";import*as W from"jsonc-parser";import{z as g}from"zod";var F="every-app.jsonc",z=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=L.join(t,F);try{let e=await B.readFile(o,"utf-8"),r=W.parse(e);return z.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 Y(t){return t.split("-").map(o=>o.charAt(0).toUpperCase()+o.slice(1)).join(" ")}async function ie(t,o){let e=L.join(t,F),r={...o,displayName:o.displayName??Y(o.appId)},n=JSON.stringify(r,null,2)+`
|
|
2
|
-
`;await B.writeFile(e,n)}async function pe(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 w(),s=k(t),i;o&&(i=await Z(s,n,e));let a=await J(s,n,e),p=await H(s,n,e);return{d1DatabaseId:a,kvNamespaceId:p,r2BucketName:i,resourceName:s}}async function J(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 H(t,o,e){e&&(console.log(c.bold(`Processing KV namespace...
|
|
8
|
-
`)),console.log(` Checking KV namespace: ${t}`));let r=await S(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 Z(t,o,e){e&&(console.log(c.bold(`Processing R2 bucket...
|
|
11
|
-
`)),console.log(` Checking R2 bucket: ${t}`));let r;try{r=await T(t,o)}catch(n){let s=await b(n,{accountId:o});throw s&&(console.log(s.formatted),await y(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 X from"chalk";async function M({cwd:t,gatewayUrl:o,appId:e,verbose:r}){let n={...process.env,VITE_GATEWAY_URL:o,VITE_APP_ID:e};try{await U("npx",["vite","build"],{cwd:t,description:`Building your application...
|
|
14
|
-
`,env:n,verbose:r}),await U("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),await y(1)),console.error(X.red(`
|
|
17
|
-
Failed to build or deploy`)),s}}import D from"chalk";var ee="every-app-gateway";async function h(){let t=await w(),e=(await $(t)).find(r=>r.name===ee);return e?{accountId:t,databaseId:e.uuid}:null}import f from"chalk";async function m(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(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 re}from"node:crypto";async function te(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 I(t,o,e){if(await te(t,o.id,e.appId))return{created:!1};let n=Math.floor(Date.now()/1e3),s=re(),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 q(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 h();if(!a){console.warn(D.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(D.yellow(`Multiple users found (${p.length}). Adding app to all users...
|
|
24
|
-
`));for(let d of p)await oe(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 oe(t,o,e){let{verbose:r,...n}=e;(await I(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 V({secretName:"GATEWAY_URL",cwd:o,verbose:e})||await j({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 Qe(t){let{cwd:o,appId:e,verbose:r,devUrl:n}=t,i=!!(await O(o)).r2_buckets?.length,{d1DatabaseId:a,kvNamespaceId:p,r2BucketName:u,resourceName:l}=await K({appId:e,needsR2Bucket:i,verbose:r});await N({configPath:o,name:l,d1DatabaseId:a,d1DatabaseName:l,kvNamespaceId:p,r2BucketName:u,verbose:r});let d=await A("every-app-gateway");console.log(),await _({cwd:o,description:"Installing dependencies for Cloudflare deployment...",verbose:r}),await G({cwd:o,verbose:r}),await M({cwd:o,gatewayUrl:d,appId:e,verbose:r}),await Q({gatewayUrl:d,appPath:o,verbose:r});let R=await A(l),v=await C(o);return await q({appId:e,appUrl:R,verbose:r,appName:v.displayName,appDescription:v.description,devUrl:n}),{workerUrl:R,gatewayUrl:d}}export{ie as a,pe as b,Qe as c};
|
package/dist/chunk-B3H55R7L.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{g as l}from"./chunk-LEXNJEKD.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
|
-
VITE_APP_ID=${t}
|
|
3
|
-
VITE_GATEWAY_URL=${i}
|
|
4
|
-
# Set Cloudflare secrets locally
|
|
5
|
-
GATEWAY_URL=${i}
|
|
6
|
-
`;await Promise.all([r.writeFile(n.join(e,".env.local"),a)])}async function T(e){return await r.mkdtemp(n.join(f.tmpdir(),e))}async function C({tmpDir:e,verbose:t=!1}){try{await r.rm(e,{recursive:!0,force:!0}),t&&console.log(p.dim(` Removed: ${e}`))}catch{console.warn(p.yellow("\u26A0\uFE0F Warning: Failed to clean up temporary directory:"),e)}}export{u as a,P as b,x as c,T as d,C as e};
|
package/dist/chunk-C6HSROI4.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{a as t,b as r,c as a}from"./chunk-T47Y5E6R.js";import s from"node:fs";import p from"node:os";import l from"node:path";function k(e){return{process:e,os:p,fs:s,path:l}}import{buildApplication as b,buildRouteMap as h}from"@stricli/core";import{buildInstallCommand as C,buildUninstallCommand as D}from"@stricli/auto-complete";import{buildCommand as o,buildRouteMap as d}from"@stricli/core";var m=o({loader:async()=>import("./create-KC6PWEDA.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-MHLQR6WA.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
|
-
`)}}),c=o({loader:async()=>{let{remoteD1Shell:e}=await import("./remoteD1Shell-CCEM2O2M.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(`
|
|
4
|
-
`)}}),n=d({routes:{create:m,deploy:u,"remote-d1-shell":c},docs:{brief:"App management commands"}});import{buildCommand as f,buildRouteMap as y}from"@stricli/core";var g=f({loader:async()=>{let{deploy:e}=await import("./deploy-RHHI3X3Y.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
|
-
`)}}),i=y({routes:{deploy:g},docs:{brief:"Gateway management commands"}});var w=h({routes:{app:n,gateway:i,install:C("everyapp",{bash:"__everyapp_bash_complete"}),uninstall:D("everyapp",{bash:!0})},docs:{brief:r,hideRoute:{install:!0,uninstall:!0}}}),U=b(w,{name:t,versionInfo:{currentVersion:a},scanner:{allowArgumentEscapeSequence:!0}});export{k as a,U as b};
|
package/dist/create-KC6PWEDA.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import{a as x,c as P}from"./chunk-3MEOBH2F.js";import{a as u,b as y,c as w,d as h,e as C}from"./chunk-B3H55R7L.js";import{a as k,b as a,e as v}from"./chunk-6ESWWGJU.js";import{b as f}from"./chunk-LEXNJEKD.js";import{c as s}from"./chunk-ZWOESNNW.js";import"./chunk-T47Y5E6R.js";import g from"chalk";async function b({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 T({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 S from"node:fs/promises";import J from"node:path";import m from"chalk";var _=["every-app.jsonc","every-app.json"];async function E(){let o=process.cwd();for(let e of _){let t=J.join(o,e);try{await S.access(t),console.log(m.yellow(`
|
|
2
|
-
Already inside an Every App project`)),console.log(m.dim(` Found ${e}
|
|
3
|
-
`)),console.log(`To create a new app, run app create from the directory where you store your projects.
|
|
4
|
-
`),console.log("If you meant to deploy this app, run:"),console.log(m.dim(` npx everyapp app deploy
|
|
5
|
-
`)),await s(1)}catch{}}}import D from"chalk";import{execa as M}from"execa";async function I(){try{await M("pnpm",["--version"],{stdio:"pipe"})}catch{console.error(D.red(`
|
|
6
|
-
Error: pnpm is required but not installed. Please install it first:`)),console.error(D.cyan(` npm i -g pnpm
|
|
7
|
-
`)),await s(1)}}import q from"enquirer";function G(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 A(o){console.log(`Project Configuration
|
|
8
|
-
`);let e=await q.prompt({type:"input",name:"appId",message:"Enter your app ID (kebab-case format)",initial:o,validate:G});return console.log(),{appId:e.appId}}import R from"node:path";import W from"chalk";var z="https://github.com/every-app/every-app.git",V="templates/simple-todo";async function F({appId:o,verbose:e=!1}){e&&console.log(`Cloning template repository...
|
|
9
|
-
`);let t=await h("every-app-create-");await b({url:z,targetDir:t,verbose:e}),e&&console.log(`Extracting template...
|
|
10
|
-
`);let r=R.join(t,V),p=R.join(process.cwd(),o);if(await y(p))throw new Error(`Directory "${o}" already exists in the current location`);return await u(r,p,{exclude:["node_modules",".git","pnpm-lock.yaml","package-lock.json",".env.local",".env.production",".dev.vars","manual-steps.md"]}),e&&console.log(W.dim(` Template copied to ${p}
|
|
11
|
-
`)),{tempDir:t,targetDir:p}}import O from"node:fs/promises";import Y from"node:path";async function U({targetDir:o,appId:e}){let t=Y.join(o,"package.json"),r=JSON.parse(await O.readFile(t,"utf-8"));r.name=e,await O.writeFile(t,JSON.stringify(r,null,2)+`
|
|
12
|
-
`,"utf-8")}import d from"chalk";async function $({targetDir:o,verbose:e=!1}){try{e||console.log(`
|
|
13
|
-
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(d.dim(` Finished.
|
|
14
|
-
`)),await a("pnpm",["run","db:migrate:local"],{cwd:o,verbose:e}),console.log(`
|
|
15
|
-
Local database migrations complete.
|
|
16
|
-
`)}catch{console.warn(d.yellow(`
|
|
17
|
-
Failed to run local migrations. You can run them manually with:`)),console.warn(d.dim(` pnpm run db:migrate:local
|
|
18
|
-
`))}}import n from"chalk";function j({appId:o,targetDir:e,gatewayUrl:t,workerUrl:r}){console.log(n.green(`Project created and deployed successfully!
|
|
19
|
-
`)),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:
|
|
20
|
-
`),console.log(n.dim(` ${n.bold(`cd ${o}`)}`)),console.log(n.dim(` ${n.bold("pnpm run dev")}`)),console.log(n.dim(` ${n.bold(`
|
|
21
|
-
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:
|
|
22
|
-
`),console.log(n.dim(` ${n.bold("npx everyapp app deploy")}`)),console.log()}async function No(o,e){let t=o.verbose||!1;await E(),await I(),await f(),await v(),console.log(`
|
|
23
|
-
Create a new Every App project
|
|
24
|
-
`);let{appId:r}=await A(e);if(console.log(g.dim(`.
|
|
25
|
-
`)),!await k("this app")){console.log(g.yellow(`
|
|
26
|
-
App creation cancelled.
|
|
27
|
-
`));return}let c=null;try{let{tempDir:l,targetDir:i}=await F({appId:r,verbose:t});c=l,await U({targetDir:i,appId:r}),await x(i,{appId:r});let{workerUrl:N,gatewayUrl:L}=await P({cwd:i,appId:r,verbose:t,devUrl:"http://localhost:3001"});await w({targetDir:i,appId:r}),await $({targetDir:i,verbose:t}),await T({targetDir:i,verbose:t}),j({appId:r,targetDir:i,gatewayUrl:L,workerUrl:N})}catch(l){throw console.error(g.red(`
|
|
28
|
-
Failed to create project:`),l instanceof Error?l.message:"Unknown error"),l}finally{c&&await C({tmpDir:c})}}export{No as default};
|
package/dist/deploy-MHLQR6WA.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import{b as i,c as m}from"./chunk-3MEOBH2F.js";import{a as s,e as l}from"./chunk-6ESWWGJU.js";import{b as a}from"./chunk-LEXNJEKD.js";import{c as p}from"./chunk-ZWOESNNW.js";import"./chunk-T47Y5E6R.js";import o from"chalk";import w from"node:fs/promises";import g from"node:path";import c from"chalk";var u=["every-app.jsonc","every-app.json"];async function f(){let r=process.cwd();for(let e of u){let t=g.join(r,e);try{await w.access(t);return}catch{}}console.log(c.yellow(`
|
|
2
|
-
Not inside an Every App project`)),console.log(c.dim(` No every-app.jsonc found
|
|
3
|
-
`)),console.log("To create a new app, run the below command from the directory where you store your projects:"),console.log(c.dim(` npx everyapp app create
|
|
4
|
-
`)),await p(1)}async function L(r){await a(),await l();let e=process.cwd(),t=r.verbose||!1;await f();let n=await i(e);if(console.log(o.bold(`
|
|
5
|
-
Project: ${n}
|
|
6
|
-
`)),!await s("this app")){console.log(o.red(`
|
|
7
|
-
Deployment cancelled by user
|
|
8
|
-
`));return}let{workerUrl:y,gatewayUrl:d}=await m({cwd:e,appId:n,verbose:t});console.log(o.green(`
|
|
9
|
-
Deployment successful!`)),console.log(o.dim(` App URL: ${o.cyan(y)}`)),console.log(` Gateway: ${o.cyan(d)}
|
|
10
|
-
`)}export{L as deploy};
|
package/dist/deploy-RHHI3X3Y.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import{d as W,e as D}from"./chunk-B3H55R7L.js";import{a as v,b as G,c as w,d as u,f as U,g as y,h as S,i as L,j as P,l as d}from"./chunk-6ESWWGJU.js";import{b as T,e as b,g as A,i as R,j as k,l as x,p as _,q as $,r as K}from"./chunk-LEXNJEKD.js";import{c as C}from"./chunk-ZWOESNNW.js";import"./chunk-T47Y5E6R.js";import m from"chalk";import me from"node:path";import c from"chalk";var z="every-app-gateway",j="every-app-gateway";async function I({verbose:e=!1}={}){console.log(`
|
|
2
|
-
Setting up your Cloudflare D1 Database and KV Store...
|
|
3
|
-
`);let t=await b(),a=await q(z,t,e),o=await Q(j,t,e);return console.log(),{d1DatabaseId:a,kvNamespaceId:o,accountId:t}}async function q(e,t,a){a&&console.log(` Checking D1 database: ${e}`);let o=await R(e,t);return a?o.wasCreated?console.log(c.green(` Created D1 database: ${e} (${o.id})
|
|
4
|
-
`)):console.log(c.dim(` Linking to existing D1 database: ${e} (${o.id})
|
|
5
|
-
`)):o.wasCreated?console.log(c.green(` D1 successfully created.
|
|
6
|
-
`)):console.log(" D1 already set up."),o.id}async function Q(e,t,a){a&&console.log(` Checking KV namespace: ${e}`);let o=await k(e,t);return a?o.wasCreated?console.log(c.green(` Created KV namespace: ${e} (${o.id})
|
|
7
|
-
`)):console.log(c.dim(` Linking to existing KV namespace: ${e} (${o.id})
|
|
8
|
-
`)):o.wasCreated?console.log(c.green(" KV successfully created.")):console.log(" KV already set up."),o.id}import ee from"node:crypto";import te from"node:path";import O from"node:crypto";import p from"chalk";function X(){return O.randomBytes(32).toString("base64")}function Z(){let{privateKey:e,publicKey:t}=O.generateKeyPairSync("rsa",{modulusLength:2048,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}});return{privateKey:e,publicKey:t}}async function J({gatewayUrl:e,gatewayPath:t,verbose:a=!1}){try{let o=new Set(await P({cwd:t})),n=o.has("GATEWAY_URL"),i=o.has("BETTER_AUTH_SECRET"),s=o.has("JWT_PRIVATE_KEY"),g=o.has("JWT_PUBLIC_KEY"),E=!i||!s||!g;if(E&&(console.log("Configuring secrets for the authentication service (Better Auth)..."),console.log(p.dim(" BETTER_AUTH_SECRET - Session signing and encryption")),console.log(p.dim(" JWT_PRIVATE_KEY - Signs JWTs issued to your apps")),console.log(p.dim(" JWT_PUBLIC_KEY - Apps use this to verify JWTs")),console.log()),n||await d({secretName:"GATEWAY_URL",secretValue:e,cwd:t,verbose:a,description:`Setting GATEWAY_URL to: ${e}`}),!i){let r=X();await d({secretName:"BETTER_AUTH_SECRET",secretValue:r,cwd:t,verbose:a,description:"Generating new Better Auth secret..."})}if(s&&g)a&&console.log(p.dim(` JWT key pair already exists
|
|
9
|
-
`));else if(!s&&!g){a&&console.log(p.dim(` Generating new JWT key pair...
|
|
10
|
-
`));let r=Z();await d({secretName:"JWT_PRIVATE_KEY",secretValue:r.privateKey,cwd:t,verbose:a}),await d({secretName:"JWT_PUBLIC_KEY",secretValue:r.publicKey,cwd:t,verbose:a}),a&&console.log(p.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.");E&&console.log(a?`Secret setup complete!
|
|
12
|
-
`:` Finished.
|
|
13
|
-
`)}catch(o){throw console.error(`
|
|
14
|
-
Failed to setup secrets`,o instanceof Error?`
|
|
15
|
-
${o.message}`:""),o}}async function V({gatewayPath:e,resources:t,workerUrl:a,verbose:o=!1}){let n=te.join(e,"dist","server","wrangler.json");await $({configPath:n,d1DatabaseId:t.d1DatabaseId,kvNamespaceId:t.kvNamespaceId,verbose:o});let i=ee.randomUUID();console.log(),await G("npx",["wrangler","deploy"],{cwd:e,description:`Deploying your Gateway to Cloudflare workers...
|
|
16
|
-
|
|
17
|
-
This could take up to a minute.`,env:{...process.env,BETTER_AUTH_SECRET:i},verbose:o}),console.log(),await J({gatewayUrl:a,gatewayPath:e,verbose:o})}import h from"node:fs";import oe from"node:path";import{Readable as ae}from"node:stream";import{pipeline as re}from"node:stream/promises";import{createWriteStream as ne}from"node:fs";import{spawn as ie}from"node:child_process";var se="every-app",le="every-app",Y="every-app-gateway-build.tar.gz";function ce(){return`https://github.com/${se}/${le}/releases/download/gateway-latest/${Y}`}async function pe(e,t){let a=await fetch(e,{redirect:"follow"});if(!a.ok)throw new Error(`Failed to download file: ${a.status} ${a.statusText}`);if(!a.body)throw new Error("Response body is null");let o=ne(t),n=ae.fromWeb(a.body);await re(n,o)}async function N(e,t){return new Promise((a,o)=>{let n=ie("tar",["-xzf",e,"-C",t]);n.on("error",o),n.on("close",i=>{i===0?a():o(new Error(`tar extraction failed with code ${i}`))})})}async function B(e,t=!1){console.log("Getting latest gateway release..."),h.mkdirSync(e,{recursive:!0});let a=ce();y(t,`URL: ${a}`);let o=oe.join(e,Y);try{await pe(a,o)}catch(n){throw n instanceof Error&&n.message.includes("404")?new Error("Gateway release not found. Make sure a release has been published."):n}return S(t,`Downloaded to: ${o}`,"Extracting archive..."),await N(o,e),h.unlinkSync(o),y(t,`Extraction complete
|
|
18
|
-
`),e}async function F(e,t,a=!1){if(console.log("Using local gateway tarball..."),!h.existsSync(e))throw new Error(`Local gateway tarball not found: ${e}`);return h.mkdirSync(t,{recursive:!0}),S(a,`Tarball: ${e}`,"Extracting archive..."),await N(e,t),y(a,`Extraction complete
|
|
19
|
-
`),t}import l from"chalk";async function M({workerUrl:e,maxWaitMs:t=12e4,pollIntervalMs:a=3e3}){let o=`${e}/sign-up`;console.log(l.green(`
|
|
20
|
-
Gateway deployment successful!
|
|
21
|
-
`)),console.log(`Your Gateway will be available at: ${l.cyan(o)}
|
|
22
|
-
`),console.log(l.dim("Waiting for SSL certificate to be provisioned..."));let n=Date.now();for(;Date.now()-n<t;)if(await new Promise(i=>setTimeout(i,a)),await w(e)){console.log(l.green(`SSL certificate is ready!
|
|
23
|
-
`)),await u(e)?console.log(`Your Gateway is now live at: ${l.cyan(e)}
|
|
24
|
-
`):(console.log(`Your Gateway is now live at: ${l.cyan(o)}
|
|
25
|
-
`),console.log(l.dim(` Create an owner account to get started with your Gateway.
|
|
26
|
-
`)));return}console.log(l.yellow(`
|
|
27
|
-
SSL certificate is still being provisioned. This can take a few minutes.
|
|
28
|
-
`)),console.log(l.dim(` The URL above will be accessible once the SSL certificate is ready.
|
|
29
|
-
`)),console.log(l.dim(` Create an owner account to get started with your Gateway.
|
|
30
|
-
`))}async function Qe(e){await T({showNewUserHelp:!0});let t=e.verbose||!1,a=e.localGateway;if(console.log(m.bold(`
|
|
31
|
-
Every App Gateway
|
|
32
|
-
`)),!await v("the Gateway")){console.log(`
|
|
33
|
-
Deployment cancelled by user
|
|
34
|
-
`);return}await _();let n=await I({verbose:t}),i=await W("gateway-deploy-");t&&console.log(m.dim(`Working directory: ${i}
|
|
35
|
-
`));let s=null;try{let r=a?await F(a,i,t):await B(i,t),f=me.join(r,"wrangler.jsonc"),H=await K(f);s=await A(H),await V({gatewayPath:r,resources:n,workerUrl:s,verbose:t}),await U({cwd:r,verbose:t,description:"Installing dependencies for migrations..."}),await L({cwd:r,verbose:t})}catch(r){let f=await x(r);throw f&&(console.log(f.formatted),await C(1)),console.error(`
|
|
36
|
-
Deployment failed:`,r instanceof Error?r.message:r),r}finally{await D({tmpDir:i,verbose:t})}if(!s)throw new Error("Worker URL not set properly during deployment");if(!await w(s)){await M({workerUrl:s});return}if(console.log(m.green(`
|
|
37
|
-
Gateway deployment successful!
|
|
38
|
-
`)),await u(s))console.log(`Your Gateway is now live at: ${m.cyan(s)}
|
|
39
|
-
`);else{let r=`${s}/sign-up`;console.log(`Your Gateway is now live at: ${m.cyan(r)}
|
|
40
|
-
`),console.log(m.dim(` Create an owner account to get started with your Gateway.
|
|
41
|
-
`))}}export{Qe as deploy};
|