everyapp 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/dist/bash-complete.js +1 -1
- package/dist/chunk-3DCJZ6LU.js +7 -0
- package/dist/chunk-4AODVGRU.js +48 -0
- package/dist/chunk-7IPT3FRI.js +4 -0
- package/dist/chunk-AIRNFEUQ.js +21 -0
- package/dist/{chunk-JVVPUTXX.js → chunk-ASNYTFJJ.js} +1 -1
- package/dist/chunk-EOQC6VQV.js +16 -0
- package/dist/chunk-FFEUD43M.js +5 -0
- package/dist/{chunk-WTPC3PFE.js → chunk-JOHMESCX.js} +1 -1
- package/dist/chunk-QHXECEAW.js +6 -0
- package/dist/chunk-QKHNAJYY.js +1 -0
- package/dist/{chunk-OICI565A.js → chunk-VYHFMMFQ.js} +1 -1
- package/dist/chunk-YRO4PVS3.js +6 -0
- package/dist/create-PFP7ROFX.js +22 -0
- package/dist/deploy-EECMKLNC.js +7 -0
- package/dist/{deploy-CWOGFCWP.js → deploy-S4QY3MQA.js} +3 -3
- package/dist/index.js +1 -1
- package/dist/{remoteD1Shell-Y7UQDJI3.js → remoteD1Shell-HUPEYTS7.js} +1 -1
- package/dist/setupLocal-VSCBS52B.js +6 -0
- package/package.json +1 -1
- package/dist/chunk-7SUABVTF.js +0 -48
- package/dist/chunk-A5KQS3U6.js +0 -5
- package/dist/chunk-GE6XCOLR.js +0 -25
- package/dist/chunk-WJ4TQGFK.js +0 -21
- package/dist/create-R6YYEX43.js +0 -28
- package/dist/deploy-3PIXBICP.js +0 -10
package/README.md
CHANGED
|
@@ -46,6 +46,20 @@ npx everyapp app deploy
|
|
|
46
46
|
|
|
47
47
|
Run this from your app directory to build and deploy updates.
|
|
48
48
|
|
|
49
|
+
### Set up local environment
|
|
50
|
+
|
|
51
|
+
Set up local development for an existing Every App app (for example, after cloning a repo):
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx everyapp app setup-local
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
This will:
|
|
58
|
+
1. Verify Cloudflare and gateway setup
|
|
59
|
+
2. Install dependencies
|
|
60
|
+
3. Create or refresh `.env.local`
|
|
61
|
+
4. Generate Cloudflare types and run local migrations
|
|
62
|
+
|
|
49
63
|
### Remote D1 shell
|
|
50
64
|
|
|
51
65
|
Run commands with access to your production D1 database:
|
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-YRO4PVS3.js";import"./chunk-JOHMESCX.js";import{proposeCompletions as r}from"@stricli/core";var t=process.argv.slice(3);process.env.COMP_LINE?.endsWith(" ")&&t.push("");await r(s,t,o(process));try{for(let{completion:p}of await r(s,t,o(process)))process.stdout.write(`${p}
|
|
3
3
|
`)}catch{}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{c as l}from"./chunk-VYHFMMFQ.js";import{a,e as r}from"./chunk-EOQC6VQV.js";import i from"chalk";async function c({targetDir:n,verbose:o=!1}){try{o||console.log(`
|
|
2
|
+
Setting up Cloudflare for local dev...`),await a("pnpm",["run","cf-typegen"],{cwd:n,verbose:o,logCommandToConsole:!1}),await a("pnpm",["run","build"],{cwd:n,verbose:o,logCommandToConsole:!1}),o||console.log(i.dim(` Finished.
|
|
3
|
+
`)),await a("pnpm",["run","db:migrate:local"],{cwd:n,verbose:o}),console.log(`
|
|
4
|
+
Local database migrations complete.
|
|
5
|
+
`)}catch{console.warn(i.yellow(`
|
|
6
|
+
Failed to run local migrations. You can run them manually with:`)),console.warn(i.dim(` pnpm run db:migrate:local
|
|
7
|
+
`))}}async function y({targetDir:n,appId:o,gatewayUrl:e,gatewayAppApiToken:s,verbose:t=!1,installDeps:m=!1}){m&&await r({cwd:n,description:"Installing dependencies for local development...",verbose:t}),await l({targetDir:n,appId:o,gatewayUrl:e,gatewayAppApiToken:s}),await c({targetDir:n,verbose:t})}export{y as a};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import{c as p}from"./chunk-ASNYTFJJ.js";import b from"node:fs/promises";import l from"node:path";import D from"node:os";import*as w from"smol-toml";import i from"chalk";function I(){let e=D.homedir(),t=D.platform(),n;return t==="win32"?n=l.join(process.env.LOCALAPPDATA||l.join(e,"AppData","Local"),".wrangler"):t==="darwin"?n=l.join(e,"Library","Preferences",".wrangler"):n=l.join(e,".wrangler"),l.join(n,"config","default.toml")}async function N(){let e=I();try{let t=await b.readFile(e,"utf-8"),n=w.parse(t);if(!n.oauth_token||!n.refresh_token)throw new Error("OAuth tokens not found in wrangler config");return n}catch(t){throw t.code==="ENOENT"?new Error("Wrangler config not found. Please run 'npx wrangler login' first."):t}}async function T(e){let t=I(),n=l.dirname(t);await b.mkdir(n,{recursive:!0});let r=w.stringify(e);await b.writeFile(t,r,"utf-8")}function L(e){let t=new Date(e).getTime(),n=Date.now(),r=1*60*1e3;return t-n<r}async function $(e){let t=await fetch("https://dash.cloudflare.com/oauth2/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"refresh_token",refresh_token:e,client_id:"54d11594-84e4-41aa-b438-e81b8fa78ee7"})});if(!t.ok)throw new Error(`Failed to refresh OAuth token: ${t.status} ${t.statusText}`);let n=await t.json();return{oauth_token:n.access_token,expiration_time:new Date(Date.now()+n.expires_in*1e3).toISOString(),refresh_token:n.refresh_token||e,scopes:n.scope?n.scope.split(" "):[]}}async function F(e={}){let{showNewUserHelp:t=!1}=e,n=!!process.env.CLOUDFLARE_API_TOKEN,r=!!process.env.CLOUDFLARE_ACCOUNT_ID;if(n&&!r&&(console.log(i.yellow(`
|
|
2
|
+
Missing CLOUDFLARE_ACCOUNT_ID
|
|
3
|
+
`)),console.log(`When using CLOUDFLARE_API_TOKEN, you must also set CLOUDFLARE_ACCOUNT_ID.
|
|
4
|
+
`),console.log(i.dim(` export CLOUDFLARE_ACCOUNT_ID=<your_account_id>
|
|
5
|
+
`)),await p(1)),!(n&&r))try{await k()}catch{console.log(t?i.yellow(`
|
|
6
|
+
Already have a Cloudflare account?
|
|
7
|
+
`):i.yellow(`
|
|
8
|
+
Please log in to Cloudflare.
|
|
9
|
+
`)),console.log(i.dim(" 1. Cloudflare CLI (recommended): npx wrangler login")),console.log(i.dim(` 2. Environment variables: CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID
|
|
10
|
+
`)),t&&(console.log(i.yellow(`Don't have a Cloudflare account?
|
|
11
|
+
`)),console.log("Every App uses Cloudflare so that you can inexpensively host your applications"),console.log("on a secure and powerful platform without needing to think about the machines"),console.log(`your code runs on.
|
|
12
|
+
`),console.log(`Here are the steps to get started:
|
|
13
|
+
`),console.log(i.dim(" 1. Create a Cloudflare account (free, no credit card required):")),console.log(i.cyan(` https://dash.cloudflare.com/sign-up
|
|
14
|
+
`)),console.log(i.dim(` - Skip any Cloudflare onboarding like configuring a domain, this is unnecessary for Every App.
|
|
15
|
+
`)),console.log(i.dim(` 2. Check your email to verify your email address
|
|
16
|
+
`)),console.log(i.dim(" 3. Log in to Cloudflare via the CLI:")),console.log(i.cyan(` npx wrangler login
|
|
17
|
+
`)),console.log(i.dim(" - Learn more: ")+i.cyan(`https://developers.cloudflare.com/workers/wrangler/commands/#login
|
|
18
|
+
`))),await p(1)}}async function k(){let e=process.env.CLOUDFLARE_API_TOKEN;if(e)return e;let t=await N();if(L(t.expiration_time)){let n=await $(t.refresh_token);return await T(n),n.oauth_token}return t.oauth_token}async function a(e,t={}){let n=await k(),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 s=o.errors?o.errors.map(d=>`[${d.code}] ${d.message}`).join(", "):r.statusText;throw new Error(`Cloudflare API request failed: ${r.status} ${s}`)}if(!o.success){let s=o.errors.map(d=>`[${d.code}] ${d.message}`).join(", ");throw new Error(`Cloudflare API error: ${s}`)}return o.result}async function f(){let e=process.env.CLOUDFLARE_ACCOUNT_ID;if(e)return e;let t=await a("/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 a(`/accounts/${e}`);if(!t||!t.id)throw new Error(`Account ${e} not found`);return t}async function C(e){try{let t=await a(`/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 f(),r=await C(n);return`https://${e}.${r}.workers.dev`}import y from"chalk";var E={EMAIL_NOT_VERIFIED:10034,R2_NOT_ENABLED:10042},S={[E.EMAIL_NOT_VERIFIED]:{userMessage:"Almost there! Your Cloudflare account email needs to be verified first.",action:`To verify your email address:
|
|
19
|
+
|
|
20
|
+
1. Check your inbox for a verification email from Cloudflare
|
|
21
|
+
2. Click the verification link in the email
|
|
22
|
+
3. Or visit ${y.cyan("https://dash.cloudflare.com/profile")} to resend the verification email
|
|
23
|
+
|
|
24
|
+
Then run this command again.`},[E.R2_NOT_ENABLED]:{userMessage:"R2 not enabled",action:`R2 is Cloudflare's file storage service, used for storing images and files.
|
|
25
|
+
|
|
26
|
+
${y.cyan("https://dash.cloudflare.com/{accountId}/r2/plans")}
|
|
27
|
+
|
|
28
|
+
${y.dim(" Visit the URL above to enable R2, then run this command again.")}`}};function M(e){let t=e.match(/\[code:\s*(\d+)\]/);if(t?.[1])return parseInt(t[1],10);let n=e.match(/"code"\s*:\s*(\d+)/);if(n?.[1])return parseInt(n[1],10);let r=e.match(/\[(\d{5})\]/);if(r?.[1])return parseInt(r[1],10)}function W(e){let t=S[e];if(t)return{code:e,...t}}function B(e){let t="";return e instanceof Error?(t=e.message,"stdout"in e&&typeof e.stdout=="string"&&(t+=`
|
|
29
|
+
`+e.stdout),"stderr"in e&&typeof e.stderr=="string"&&(t+=`
|
|
30
|
+
`+e.stderr),"all"in e&&typeof e.all=="string"&&(t+=`
|
|
31
|
+
`+e.all)):typeof e=="string"&&(t=e),t}async function K(e,t){let n=e.action,r=t.accountId;if(!r&&n.includes("{accountId}"))try{r=await f()}catch{}return r&&(n=n.replace(/{accountId}/g,r)),`
|
|
32
|
+
${y.yellow(e.userMessage)}
|
|
33
|
+
|
|
34
|
+
${n}
|
|
35
|
+
`}async function V(e,t={}){let n=B(e),r=M(n);if(r===void 0)return;let o=W(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 a(`/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 f();try{return await C(e)}catch{console.log(),console.log(u.yellow(` Please claim a Cloudflare subdomain.
|
|
36
|
+
`)),console.log(u.dim(` All your apps will be deployed to this domain.
|
|
37
|
+
`)),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"
|
|
38
|
+
`));let t=await J();console.log(u.dim(`
|
|
39
|
+
Creating subdomain: ${t}...
|
|
40
|
+
`));try{let n=await z(e,t);return console.log(u.green(` Successfully created subdomain: ${u.cyan(n)}
|
|
41
|
+
`)),n}catch(n){throw console.error(u.red(`
|
|
42
|
+
Failed to create subdomain`),u.dim(`
|
|
43
|
+
${n instanceof Error?n.message:"Unknown error"}`)),n}}}import{z as m}from"zod";var _="every-";function Y(e){return e.startsWith(_)?e:`${_}${e}`}var X=m.object({uuid:m.string(),name:m.string(),created_at:m.string().optional(),version:m.string().optional()}),R=m.array(X);async function O(e){let t=await a(`/accounts/${e}/d1/database?per_page=1000`);return R.parse(t)}async function G(e,t){let n=await a(`/accounts/${t}/d1/database`,{method:"POST",body:JSON.stringify({name:e})});if(!n||!n.uuid)throw new Error("Failed to create D1 database: no UUID returned");return n.uuid}async function Q(e,t){let r=(await O(t)).find(s=>s.name===e);return r?{id:r.uuid,name:e,wasCreated:!1}:{id:await G(e,t),name:e,wasCreated:!0}}async function Z(e){return(await a(`/accounts/${e}/storage/kv/namespaces?per_page=1000`)).map(n=>({id:n.id,title:n.title}))}async function ee(e,t){let n=await a(`/accounts/${t}/storage/kv/namespaces`,{method:"POST",body:JSON.stringify({title:e})});if(!n||!n.id)throw new Error("Failed to create KV namespace: no ID returned");return n.id}async function te(e,t){let r=(await Z(t)).find(s=>s.title===e);return r?{id:r.id,name:e,wasCreated:!1}:{id:await ee(e,t),name:e,wasCreated:!0}}async function ne(e){return(await a(`/accounts/${e}/r2/buckets?per_page=1000`)).buckets.map(n=>({name:n.name,creation_date:n.creation_date}))}async function re(e,t){let n=await a(`/accounts/${t}/r2/buckets`,{method:"POST",body:JSON.stringify({name:e})});if(!n||!n.name)throw new Error("Failed to create R2 bucket: no name returned");return n.name}async function oe(e,t){return(await ne(t)).find(o=>o.name===e)?{name:e,wasCreated:!1}:(await re(e,t),{name:e,wasCreated:!0})}import g from"chalk";async function ae(){return await a("/memberships")}function A(e){return e.status==="pending"?" (pending)":""}function se(e,t){let n=A(e);console.log(g.dim(` ${e.account.name} (${e.account.id})${n}`)),t.length>0&&(console.log(),console.log(g.dim(" Other accounts (set CLOUDFLARE_ACCOUNT_ID to switch):")),t.forEach(r=>{let o=A(r);console.log(g.dim(` - ${r.account.name}: ${r.account.id}${o}`))})),console.log()}async function ie(e){return console.log(g.yellow(`Multiple Cloudflare accounts found.
|
|
44
|
+
`)),console.log(`Please set the CLOUDFLARE_ACCOUNT_ID environment variable:
|
|
45
|
+
`),e.forEach(t=>{let n=A(t);console.log(g.dim(` ${t.account.name}: ${t.account.id}${n}`))}),console.log(g.dim(`
|
|
46
|
+
export CLOUDFLARE_ACCOUNT_ID=<account_id>
|
|
47
|
+
`)),p(1)}async function ce(e){if(e.length===0)throw new Error("No Cloudflare accounts found");let t=process.env.CLOUDFLARE_ACCOUNT_ID;!t&&e.length>1&&await ie(e);let n=t?e.find(o=>o.account.id===t):e[0];if(!n)throw new Error(`Account ${t} not found in your Cloudflare memberships`);let r=e.filter(o=>o.account.id!==n.account.id);return{account:n,otherAccounts:r}}import h from"node:fs/promises";import v from"node:path";import*as c from"jsonc-parser";import ue from"chalk";async function Ye(e){e.verbose&&console.log("Updating wrangler.jsonc with resource IDs and configuration...");let t=e.configPath;(await h.stat(t)).isDirectory()&&(t=v.join(t,"wrangler.jsonc"));let r=await h.readFile(t,"utf-8"),o=c.parse(r),s=[];if(o.d1_databases){if(o.d1_databases.length===0)throw new Error("No D1 databases found in wrangler.jsonc. Every app must have exactly one D1 database.");if(o.d1_databases.length>1)throw new Error(`Found ${o.d1_databases.length} D1 databases in wrangler.jsonc. Every app must have exactly one D1 database.`)}if(o.kv_namespaces){if(o.kv_namespaces.length===0)throw new Error("No KV namespaces found in wrangler.jsonc. Every app must have exactly one KV namespace.");if(o.kv_namespaces.length>1)throw new Error(`Found ${o.kv_namespaces.length} KV namespaces in wrangler.jsonc. Every app must have exactly one KV namespace.`)}if(o.r2_buckets&&o.r2_buckets.length>1)throw new Error(`Found ${o.r2_buckets.length} R2 buckets in wrangler.jsonc. Every app must have at most one R2 bucket.`);if(e.name&&s.push(...c.modify(r,["name"],e.name,{})),e.d1DatabaseId&&s.push(...c.modify(r,["d1_databases",0,"database_id"],e.d1DatabaseId,{})),e.d1DatabaseName&&s.push(...c.modify(r,["d1_databases",0,"database_name"],e.d1DatabaseName,{})),e.kvNamespaceId&&s.push(...c.modify(r,["kv_namespaces",0,"id"],e.kvNamespaceId,{})),e.r2BucketName&&o.r2_buckets?.length&&s.push(...c.modify(r,["r2_buckets",0,"bucket_name"],e.r2BucketName,{})),e.vars)for(let[P,x]of Object.entries(e.vars))s.push(...c.modify(r,["vars",P],x,{}));let d=c.applyEdits(r,s);await h.writeFile(t,d),e.verbose&&console.log(ue.dim(` wrangler.jsonc updated successfully
|
|
48
|
+
`))}async function Xe(e){let t=await h.readFile(e,"utf-8"),n=c.parse(t);if(!n.name||typeof n.name!="string")throw new Error("Worker name not found in wrangler.jsonc");return n.name}async function Ge(e){let t=v.join(e,"wrangler.jsonc");try{let n=await h.readFile(t,"utf-8");return c.parse(n)}catch(n){throw n instanceof Error&&"code"in n&&n.code==="ENOENT"?new Error("wrangler.jsonc not found in current directory. Make sure you're running this command from your app's root directory."):n}}export{Y as a,F as b,k as c,a as d,f as e,U as f,j as g,O as h,Q as i,te as j,oe as k,V as l,ae as m,se as n,ce as o,H as p,Ye as q,Xe as r,Ge as s};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{c as e}from"./chunk-ASNYTFJJ.js";import n from"node:fs/promises";import p from"node:path";import o from"chalk";var a=["every-app.jsonc","every-app.json"];async function f(){let r=process.cwd();for(let c of a){let t=p.join(r,c);try{await n.access(t);return}catch{}}console.log(o.yellow(`
|
|
2
|
+
Not inside an Every App project`)),console.log(o.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(o.dim(` npx everyapp app create
|
|
4
|
+
`)),await e(1)}export{f as a};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import{a as V,e as q}from"./chunk-FFEUD43M.js";import{d as K}from"./chunk-QHXECEAW.js";import{a as _,e as L}from"./chunk-EOQC6VQV.js";import{a as T,c as S,e as C,g as E,h as N,i as O,j as B,k as G,l as I,q as F,s as W}from"./chunk-4AODVGRU.js";import{c as U}from"./chunk-ASNYTFJJ.js";import l from"chalk";async function M({appId:e,needsR2Bucket:t=!1,verbose:a=!1}){console.log(`
|
|
2
|
+
Setting up your Cloudflare ${t?"D1 Database, KV Store, and R2 Bucket":"D1 Database and KV Store"}...
|
|
3
|
+
`);let o=await C(),s=T(e),i;t&&(i=await X(s,o,a));let n=await Y(s,o,a),c=await J(s,o,a);return{d1DatabaseId:n,kvNamespaceId:c,r2BucketName:i,resourceName:s}}async function Y(e,t,a){a&&(console.log(l.bold(`Processing D1 database...
|
|
4
|
+
`)),console.log(` Checking D1 database: ${e}`));let r=await O(e,t);return a?r.wasCreated?console.log(l.green(` Created D1 database: ${e} (${r.id})
|
|
5
|
+
`)):console.log(l.dim(` Linking to existing D1 database: ${e} (${r.id})
|
|
6
|
+
`)):r.wasCreated?console.log(l.green(" D1 successfully created.")):console.log(" D1 already set up."),r.id}async function J(e,t,a){a&&(console.log(l.bold(`Processing KV namespace...
|
|
7
|
+
`)),console.log(` Checking KV namespace: ${e}`));let r=await B(e,t);return a?r.wasCreated?console.log(l.green(` Created KV namespace: ${e} (${r.id})
|
|
8
|
+
`)):console.log(l.dim(` Linking to existing KV namespace: ${e} (${r.id})
|
|
9
|
+
`)):r.wasCreated?console.log(l.green(" KV successfully created.")):console.log(" KV already set up."),r.id}async function X(e,t,a){a&&(console.log(l.bold(`Processing R2 bucket...
|
|
10
|
+
`)),console.log(` Checking R2 bucket: ${e}`));let r;try{r=await G(e,t)}catch(o){let s=await I(o,{accountId:t});throw s&&(console.log(s.formatted),await U(1)),o}return a?r.wasCreated?console.log(l.green(` Created R2 bucket: ${e}
|
|
11
|
+
`)):console.log(l.dim(` Linking to existing R2 bucket: ${e}
|
|
12
|
+
`)):r.wasCreated?console.log(l.green(" R2 successfully created.")):console.log(" R2 already set up."),r.name}import Z from"chalk";async function Q({cwd:e,gatewayUrl:t,appId:a,verbose:r}){let o={...process.env,VITE_GATEWAY_URL:t,VITE_APP_ID:a};try{await _("npx",["vite","build"],{cwd:e,description:`Building your application...
|
|
13
|
+
`,env:o,verbose:r}),await _("npx",["wrangler","deploy"],{cwd:e,description:`Deploying your application to Cloudflare workers...
|
|
14
|
+
|
|
15
|
+
This could take up to a minute.`,env:o,verbose:r})}catch(s){let i=await I(s);throw i&&(console.log(i.formatted),await U(1)),console.error(Z.red(`
|
|
16
|
+
Failed to build or deploy`)),s}}import f from"chalk";import P from"enquirer";var ee="every-app-gateway";async function k(){let e=await C(),a=(await N(e)).find(r=>r.name===ee);return a?{accountId:e,databaseId:a.uuid}:null}import D from"chalk";async function u(e,t,a,r){try{let o=await S(),s={sql:a};r&&r.length>0&&(s.params=r);let i=await fetch(`https://api.cloudflare.com/client/v4/accounts/${e}/d1/database/${t}/query`,{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify(s)}),n=await i.json();if(!i.ok||!n.success){let p=n.errors?n.errors.map(d=>`[${d.code}] ${d.message}`).join(", "):i.statusText;throw console.error(D.red(`
|
|
17
|
+
D1 Query Error:`)),console.error(D.dim(`SQL: ${a}`)),console.error(D.dim(`Error: ${p}`)),new Error(`D1 query failed: ${p}`)}let c=n.result;if(!c||c.length===0)throw new Error("No results returned from D1 query");let g=c[0];if(!g)throw new Error("First result is undefined");return g.results}catch(o){throw o instanceof Error&&!o.message.includes("D1 query failed")&&(console.error(D.red(`
|
|
18
|
+
D1 Query Error:`)),console.error(D.dim(`SQL: ${a}`))),o}}async function v(e){return u(e.accountId,e.databaseId,"SELECT id, name, email FROM users")}import{randomUUID as j}from"node:crypto";async function R(e,t){return(await u(e.accountId,e.databaseId,"SELECT id, dev_url, is_default FROM apps WHERE app_id = ?",[t]))[0]??null}async function x(e,t){let a=await R(e,t.appId),r=Date.now(),o=t.isDefault??!!(a?.is_default??0);if(a){let i=t.devUrl??a.dev_url??null;return await u(e.accountId,e.databaseId,"UPDATE apps SET name = ?, description = ?, app_url = ?, dev_url = ?, is_default = ?, updated_at = ? WHERE id = ?",[t.name,t.description,t.appUrl,i,o?1:0,r,a.id]),a.id}let s=j();return await u(e.accountId,e.databaseId,"INSERT INTO apps (id, app_id, name, description, app_url, dev_url, is_default, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",[s,t.appId,t.name,t.description,t.appUrl,t.devUrl??null,o?1:0,r,r]),s}async function te(e,t,a){return(await u(e.accountId,e.databaseId,"SELECT id FROM user_app_access WHERE user_id = ? AND app_id = ?",[t,a])).length>0}async function $(e,t,a){if(await te(e,t,a))return{created:!1};let o=Date.now(),s=j();return await u(e.accountId,e.databaseId,"INSERT INTO user_app_access (id, user_id, app_id, granted_at, granted_by) VALUES (?, ?, ?, ?, ?)",[s,t,a,o,null]),{created:!0}}async function z(e){let{appId:t,appUrl:a,verbose:r=!1,appName:o,appDescription:s,devUrl:i}=e;try{console.log(""),r&&console.log("Adding apps to user gateways...");let n=await k();if(!n){console.warn(f.yellow(`every-app-gateway database not found. Skipping UserApp record creation.
|
|
19
|
+
`));return}let c=await v(n),g=await R(n,t),p=g===null,d=o||t,b=s||t;!p&&r&&console.log(f.dim("App already configured in gateway. Skipping access prompts."));let y=p?await ae("Add future users by default to this app?"):!!g?.is_default,w=p?await oe():"none",h=[];if(c.length===0&&w==="select")throw new Error("No users found in the database to select from. Please create a user first.");w==="all"?h=c.map(m=>m.id):w==="select"&&(h=await se(c));let H=await x(n,{appId:t,appUrl:a,name:d,description:b,devUrl:i,isDefault:y}),A=c.filter(m=>h.includes(m.id));r&&A.length>1&&console.log(f.yellow(`Adding app to ${A.length} user(s)...
|
|
20
|
+
`));for(let m of A)await re(n,m,{appRecordId:H,verbose:r});if(r){let m=w==="all"?"all users":w==="select"?`${A.length} selected users`:"no users";console.log(f.dim(` Default access: ${y?"enabled":"disabled"}`)),console.log(f.dim(` Access granted to ${m}
|
|
21
|
+
`))}}catch(n){throw console.error(f.red("Failed to insert UserApp records:"),n instanceof Error?n.message:n),n}}async function re(e,t,a){let{verbose:r,appRecordId:o}=a;(await $(e,t.id,o)).created?console.log(` UserApp record created for user ${t.name} (${t.email})`):r&&console.log(f.dim(` UserApp record already exists for user ${t.name} (${t.email})`))}async function ae(e){let{confirm:t}=await P.prompt({type:"confirm",name:"confirm",message:e,initial:!0});return t}async function oe(){let{mode:e}=await P.prompt({type:"select",name:"mode",message:"Add existing users now?",choices:[{name:"all",message:"All users"},{name:"select",message:"Select users"},{name:"none",message:"None"}],initial:0});return e}async function se(e){let{selected:t}=await P.prompt({type:"multiselect",name:"selected",message:"Select users to grant access",choices:e.map(a=>({name:a.id,message:ne(a)}))});return t}function ne(e){return e.name&&e.name.trim()?`${e.name} <${e.email}>`:e.email}async function Ke(e){let{cwd:t,appId:a,verbose:r,devUrl:o}=e,i=!!(await W(t)).r2_buckets?.length,{d1DatabaseId:n,kvNamespaceId:c,r2BucketName:g,resourceName:p}=await M({appId:a,needsR2Bucket:i,verbose:r});await F({configPath:t,name:p,d1DatabaseId:n,d1DatabaseName:p,kvNamespaceId:c,r2BucketName:g,verbose:r});let d=await E("every-app-gateway");console.log(),await L({cwd:t,description:"Installing dependencies for Cloudflare deployment...",verbose:r}),await K({cwd:t,verbose:r}),await Q({cwd:t,gatewayUrl:d,appId:a,verbose:r});let b=await E(p),y=await V(t);return await z({appId:a,appUrl:b,verbose:r,appName:y.displayName,appDescription:y.description,devUrl:o}),await q({gatewayUrl:d,appPath:t,appId:a,verbose:r}),{workerUrl:b,gatewayUrl:d}}export{Ke as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as n}from"./chunk-
|
|
1
|
+
import{c as n}from"./chunk-JOHMESCX.js";import a from"chalk";var p="https://registry.npmjs.org/everyapp?fields=dist-tags",f=2e3,i=null;function y(){i||(i=d().then(t=>t&&t!==n&&g(n,t)?{updateAvailable:!0,latestVersion:t,currentVersion:n}:{updateAvailable:!1,currentVersion:n}))}var u=!1;async function m(){if(u||!i)return;u=!0;let t=await i;h(t)}async function V(t){await m(),process.exit(t)}async function d(){try{let t=new AbortController,o=setTimeout(()=>t.abort(),f),e=await fetch(p,{signal:t.signal});return clearTimeout(o),e.ok?(await e.json())["dist-tags"].latest:null}catch{return null}}function g(t,o){let e=t.split(".").map(Number),s=o.split(".").map(Number);for(let r=0;r<Math.max(e.length,s.length);r++){let l=e[r]??0,c=s[r]??0;if(l<c)return!0;if(l>c)return!1}return!1}function h(t){t.updateAvailable&&t.latestVersion&&(console.log(),console.log(a.yellow(` Update available: ${t.currentVersion} \u2192 ${t.latestVersion}`)),console.log(a.dim(` Update: ${a.cyan("npm install -g everyapp@latest")}`)))}export{y as a,m as b,V as c};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import{d as u,e as m,g as x,r as k}from"./chunk-4AODVGRU.js";import{c as f}from"./chunk-ASNYTFJJ.js";import p from"chalk";var C="every-app-gateway";async function G(t){try{return await fetch(t,{method:"HEAD",signal:AbortSignal.timeout(5e3)}),!0}catch(e){let o=e instanceof Error?e.message.toLowerCase():"",n=e instanceof Error&&"cause"in e&&e.cause?.code?.toLowerCase()||"";return!["ssl","tls","certificate","cert","cipher","handshake","secure"].some(a=>o.includes(a)||n.includes(a))}}async function E(t){try{let e=await fetch(`${t}/api/admin/has-owner`);return e.ok?(await e.json()).hasOwner:!1}catch{return!1}}async function O(){try{let t=await m();return await u(`/accounts/${t}/workers/scripts/${C}/settings`),!0}catch{return!1}}async function S(){return x(C)}async function $(){if(!await O())return{isDeployed:!1,hasOwner:!1,gatewayUrl:await S()};let e=await S();return{isDeployed:!0,hasOwner:await E(e),gatewayUrl:e}}async function A(){let{isDeployed:t,hasOwner:e,gatewayUrl:o}=await $();if(t||(console.log(p.yellow(`
|
|
2
|
+
Gateway not deployed
|
|
3
|
+
`)),console.log(`You need to deploy the Every App Gateway before creating or deploying apps.
|
|
4
|
+
`),console.log(p.dim(` Run: npx everyapp gateway deploy
|
|
5
|
+
`)),await f(1)),!e){let n=`${o}/sign-up`;console.log(p.yellow(`
|
|
6
|
+
Owner account required
|
|
7
|
+
`)),console.log(`You need to create an owner account on your Gateway before deploying apps.
|
|
8
|
+
`),console.log(` ${p.cyan(n)}
|
|
9
|
+
`),console.log(p.dim(` Visit the URL above to create your owner account, then run this command again.
|
|
10
|
+
`)),await f(1)}return o}import{execa as I}from"execa";import{execa as g}from"execa";import c from"chalk";async function w(t,e,o){let{env:n,cwd:s,verbose:r=!1,description:a,logCommandToConsole:l=!0}=o;return r?P(t,e,o):l?(console.log(`Running: ${t} ${e.join(" ")}`),a&&console.log(c.dim(` ${a}`)),await g(t,e,{cwd:s,env:n,stdio:"pipe"})):await g(t,e,{cwd:s,env:n,stdio:"pipe"})}async function P(t,e,{description:o,cwd:n,env:s}){console.log(c.dim(` \u250C\u2500 Running: ${t} ${e.join(" ")}`)),o&&console.log(c.dim(` \u2502 ${o}`));let r=g(t,e,{cwd:n,env:s,stdio:void 0,all:!0});r.stdout&&r.stdout.on("data",l=>{l.toString().split(`
|
|
11
|
+
`).forEach(i=>{i.trim()&&console.log(c.dim(` \u2502 ${i}`))})}),r.stderr&&r.stderr.on("data",l=>{l.toString().split(`
|
|
12
|
+
`).forEach(i=>{i.trim()&&console.error(c.dim(` \u2502 ${i}`))})});let a=await r;return console.log(c.dim(` \u2514\u2500 Complete
|
|
13
|
+
`)),a}async function U(){try{return await I("pnpm",["--version"],{stdio:"pipe"}),!0}catch{return!1}}async function V({cwd:t,description:e,verbose:o=!1}){let n=await U();try{n?await w("pnpm",["install"],{cwd:t,verbose:o,description:e}):await w("npx",["pnpm","install"],{cwd:t,verbose:o,description:e})}catch(s){throw new Error(`Failed to install dependencies with pnpm: ${s instanceof Error?s.message:"Unknown error"}`)}}import d from"chalk";import W from"node:path";async function y(t){let e=await m(),o=W.join(t,"wrangler.jsonc"),n=await k(o);return{accountId:e,workerName:n}}async function b(t){return await u(`/accounts/${t.accountId}/workers/scripts/${t.workerName}/secrets`)}async function M({cwd:t}){let e=await y(t);return(await b(e)).map(n=>n.name)}async function K({secretName:t,cwd:e,verbose:o=!1}){o&&console.log(d.dim(` Checking secret: ${t}`));let n=await y(e),r=(await b(n)).some(a=>a.name===t);return r&&o&&console.log(d.dim(` Secret already exists
|
|
14
|
+
`)),r}async function z({secretName:t,secretValue:e,cwd:o,verbose:n=!1,description:s}){n&&s&&console.log(d.dim(` ${s}
|
|
15
|
+
`));let r=await y(o);await u(`/accounts/${r.accountId}/workers/scripts/${r.workerName}/secrets`,{method:"PUT",body:JSON.stringify({name:t,text:e,type:"secret_text"})}),n&&console.log(d.green(`Created secret: ${t}
|
|
16
|
+
`))}export{w as a,G as b,E as c,A as d,V as e,M as f,K as g,z as h};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{g as p,h as c}from"./chunk-EOQC6VQV.js";import{c as f}from"./chunk-4AODVGRU.js";import u from"node:fs/promises";import y from"node:path";import*as l from"jsonc-parser";import{z as s}from"zod";var d="every-app.jsonc",A=s.object({appId:s.string().min(1,"appId cannot be empty"),displayName:s.string().min(1,"displayName cannot be empty").optional(),description:s.string().optional()});async function h(e){let n=y.join(e,d);try{let o=await u.readFile(n,"utf-8"),t=l.parse(o);return A.parse(t)}catch(o){if(o instanceof Error&&"code"in o&&o.code==="ENOENT")throw new Error("every-app.jsonc not found. Make sure you're running this command from an Every App project directory.");if(o instanceof s.ZodError){let t=o.issues.map(r=>r.message).join(", ");throw new Error(`Invalid every-app.jsonc: ${t}`)}throw o}}function T(e){return e.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" ")}async function I(e,n){let o=y.join(e,d),t={...n,displayName:n.displayName??T(n.appId)},r=JSON.stringify(t,null,2)+`
|
|
2
|
+
`;await u.writeFile(o,r)}async function O(e){return(await h(e)).appId}var w="GATEWAY_URL",E="GATEWAY_APP_API_TOKEN",N="/api/internal/app-token/provision",P=["provider:openai"];function k(e){if(!e.trim())return null;try{return JSON.parse(e)}catch{return null}}function m(e){if(!e||typeof e!="object")return null;let n=e.error;return typeof n!="string"||!n.trim()?null:n}async function v({gatewayUrl:e,appId:n}){let o=await f(),t=await fetch(`${e}${N}`,{method:"POST",headers:{authorization:`Bearer ${o}`,"content-type":"application/json"},body:JSON.stringify({appSlug:n,scopes:P})}),r=await t.text(),a=k(r);if(!t.ok){let g=m(a)||`Gateway token provisioning failed with status ${t.status}`;throw t.status===401||t.status===403?new Error(`${g}. Ensure your Cloudflare credentials target the same account that hosts this gateway.`):t.status===404?new Error("Gateway does not support token provisioning yet. Redeploy the gateway with `npx everyapp gateway deploy` and try again."):t.status===409?new Error(`${m(a)||"Gateway rejected token provisioning with a conflict"}. If this gateway is outdated, run \`npx everyapp gateway deploy\` and try again.`):new Error(g)}let i=a?.token;if(typeof i!="string"||!i.trim())throw new Error("Gateway returned an invalid token provisioning response");return i}async function R({gatewayUrl:e,appPath:n,appId:o,verbose:t=!1}){t&&console.log("Configuring Secrets...");try{if(await p({secretName:w,cwd:n,verbose:t})||await c({secretName:w,secretValue:e,cwd:n,verbose:t,description:`Setting GATEWAY_URL to: ${e}`}),!await p({secretName:E,cwd:n,verbose:t})){t&&console.log("Provisioning gateway app API token...");let i=await v({gatewayUrl:e,appId:o});await c({secretName:E,secretValue:i,cwd:n,verbose:t,description:"Setting GATEWAY_APP_API_TOKEN for gateway requests"})}t&&console.log(`Secret setup complete!
|
|
3
|
+
`)}catch(r){throw console.error(`
|
|
4
|
+
Failed to setup secrets`,r instanceof Error?`
|
|
5
|
+
${r.message}`:""),r}}export{h as a,I as b,O as c,v as d,R as e};
|
|
@@ -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.7";export{p as a,i as b,n as c};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{b as l}from"./chunk-QKHNAJYY.js";import{f as s,m as c,n as a,o as m}from"./chunk-4AODVGRU.js";import{c as r}from"./chunk-ASNYTFJJ.js";import A from"enquirer";import t from"chalk";async function D(){if(process.env.CLOUDFLARE_API_TOKEN){let i=process.env.CLOUDFLARE_ACCOUNT_ID;return i?s(i):(console.log(t.yellow(`
|
|
2
|
+
CLOUDFLARE_ACCOUNT_ID is required when using CLOUDFLARE_API_TOKEN
|
|
3
|
+
`)),r(1))}let n=await c(),{account:o,otherAccounts:e}=await m(n);return a(o,e),{id:o.account.id,name:o.account.name}}async function R(n="this",o=!1){let e=await D();if(process.env.CLOUDFLARE_API_TOKEN&&(console.log(t.dim(` ${e.name} (${e.id})`)),console.log()),o)return console.log(t.dim(`Skipping deployment confirmation due to -y flag.
|
|
4
|
+
`)),!0;let{confirm:i}=await A.prompt({type:"confirm",name:"confirm",message:`Do you want to deploy ${n} to ${e.name}?`,initial:!1});return i}import g from"chalk";import f from"chalk";function z(n,o){n&&console.log(f.dim(o))}function u(n,...o){n&&o.forEach(e=>console.log(f.dim(e)))}var p="npx",d=["drizzle-kit","migrate","--config=drizzle-prod.config.ts"];async function N({cwd:n,verbose:o=!1}){console.log(`
|
|
5
|
+
Running: ${p} ${d.join(" ")}`),console.log(g.dim(" Running database migrations...")),u(o," Running any pending migrations against your remote D1 Database..."),await l(p,d,{cwd:n,verbose:o}),console.log(g.dim(` Migrations completed.
|
|
6
|
+
`))}export{R as a,z as b,u as c,N as d};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as d,e as c,h as f,s as D}from"./chunk-4AODVGRU.js";import{execa as g}from"execa";async function m(s){let e=await D(s);if(!e.d1_databases||e.d1_databases.length===0)throw new Error("No D1 databases found in wrangler.jsonc. Please add a D1 database configuration.");let n=e.d1_databases[0];if(!n)throw new Error("No D1 database configuration found in wrangler.jsonc.");let a=n.database_name;if(!a)throw new Error("No database_name found in D1 database configuration in wrangler.jsonc.");let[t,r]=await Promise.all([c(),d()]),o=(await f(t)).find(u=>u.name===a);if(!o)throw new Error(`Database "${a}" not found in your Cloudflare account. Have you run deployment to create the database?`);return{CLOUDFLARE_ACCOUNT_ID:t,CLOUDFLARE_DATABASE_ID:o.uuid,CLOUDFLARE_API_TOKEN:r}}async function w(s,e,n){let{cwd:a,env:t={},verbose:r=!1}=n,i=await m(a),o={cwd:a,stdio:r?"inherit":"pipe",env:{...process.env,...t,...i}};await g(s,e,o)}export{m as a,w as b};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{g as p}from"./chunk-
|
|
1
|
+
import{g as p}from"./chunk-4AODVGRU.js";import r from"node:fs/promises";import c from"node:path";import f from"node:os";import m from"chalk";async function u(e,t,o={}){let n=o.exclude||[];await r.mkdir(t,{recursive:!0});let a=await r.readdir(e,{withFileTypes:!0});for(let i of a){let s=c.join(e,i.name),l=c.join(t,i.name);n.some(y=>i.name===y)||(i.isDirectory()?await u(s,l,o):await r.copyFile(s,l))}}async function T(e){try{return(await r.stat(e)).isDirectory()}catch{return!1}}async function D({targetDir:e,appId:t,gatewayUrl:o,gatewayAppApiToken:n}){let a=o??await p("every-app-gateway"),i=n?`GATEWAY_APP_API_TOKEN=${n}
|
|
2
2
|
`:"",s=`# Vite client-side secrets
|
|
3
3
|
VITE_APP_ID=${t}
|
|
4
4
|
VITE_GATEWAY_URL=${a}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{a as t,b as a,c as r}from"./chunk-JOHMESCX.js";import s from"node:fs";import l from"node:os";import p from"node:path";function R(e){return{process:e,os:l,fs:s,path:p}}import{buildApplication as h,buildRouteMap as C}from"@stricli/core";import{buildInstallCommand as v,buildUninstallCommand as w}from"@stricli/auto-complete";import{buildCommand as o,buildRouteMap as d}from"@stricli/core";var m=o({loader:async()=>import("./create-PFP7ROFX.js"),parameters:{positional:{kind:"tuple",parameters:[{brief:"App ID (kebab-case format)",parse:String,optional:!0}]},flags:{verbose:{kind:"boolean",brief:"Show detailed output during creation",optional:!0},yes:{kind:"boolean",brief:"Skip deployment confirmation",optional:!0}},aliases:{y:"yes"}},docs:{brief:"Create a new app from the starter template",fullDescription:["Copies the simple-todo starter template, deploys to Cloudflare, and configures local development.","","Usage: every app create [name]","","The command will:"," 1. Prompt for app ID (or use provided name)"," 2. Deploy to Cloudflare (D1 database, KV namespace, Worker)"," 3. Configure wrangler.jsonc, package.json, and .env files"," 4. Install dependencies and run local migrations","","After creation, run 'pnpm run dev' to start developing."].join(`
|
|
2
|
+
`)}}),u=o({loader:async()=>{let{deploy:e}=await import("./deploy-EECMKLNC.js");return e},parameters:{positional:{kind:"tuple",parameters:[]},flags:{verbose:{kind:"boolean",brief:"Show detailed output during deployment",optional:!0},yes:{kind:"boolean",brief:"Skip deployment confirmation",optional:!0}},aliases:{y:"yes"}},docs:{brief:"Deploy an app to Cloudflare",fullDescription:["Deploys the current app to Cloudflare Workers from the current directory.","The deployment process:"," 1. Reads wrangler.jsonc to determine required resources"," 2. Creates or links D1 databases and KV namespaces"," 3. Updates wrangler.jsonc with resource IDs"," 4. Installs dependencies if needed"," 5. Runs database migrations against production D1"," 6. Builds and deploys using wrangler deploy"].join(`
|
|
3
|
+
`)}}),c=o({loader:async()=>{let{setupLocal:e}=await import("./setupLocal-VSCBS52B.js");return e},parameters:{positional:{kind:"tuple",parameters:[]},flags:{verbose:{kind:"boolean",brief:"Show detailed output during local setup",optional:!0}}},docs:{brief:"Set up local development in an existing app",fullDescription:["Configures local development for an existing Every App project in the current directory.","","Usage: every app setup-local","","The command will:"," 1. Verify the current directory is an Every App project"," 2. Verify Cloudflare and gateway setup"," 3. Install dependencies"," 4. Create or refresh .env.local"," 5. Generate Cloudflare types and run local database migrations","","This is useful after cloning an existing Every App repository."].join(`
|
|
4
|
+
`)}}),f=o({loader:async()=>{let{remoteD1Shell:e}=await import("./remoteD1Shell-HUPEYTS7.js");return e},parameters:{flags:{},positional:{kind:"array",parameter:{brief:"Command and arguments to run with environment variables",parse:String}}},docs:{brief:"Run a command with Cloudflare D1 connection environment variables",fullDescription:["Sets environment variables needed to connect to remote Cloudflare D1 and runs any command that requires D1 access.","","The command will:"," 1. Get the Cloudflare account ID"," 2. Look up the database ID from the database name in wrangler.jsonc"," 3. Get a valid OAuth token"," 4. Run the provided command with CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_DATABASE_ID, CLOUDFLARE_API_TOKEN, and MIGRATE_REMOTE set","","Common use cases:"," - Running Drizzle migrations: npx everyapp app remote-d1-shell -- npx drizzle-kit migrate"," - Opening Drizzle Studio: npx everyapp app remote-d1-shell -- npx drizzle-kit studio"," - Pushing schema changes: npx everyapp app remote-d1-shell -- npx drizzle-kit push","","This command is useful for any operation that needs direct access to your production D1 database."].join(`
|
|
5
|
+
`)}}),n=d({routes:{create:m,deploy:u,"setup-local":c,"remote-d1-shell":f},docs:{brief:"App management commands"}});import{buildCommand as y,buildRouteMap as b}from"@stricli/core";var g=y({loader:async()=>{let{deploy:e}=await import("./deploy-S4QY3MQA.js");return e},parameters:{positional:{kind:"tuple",parameters:[]},flags:{repo:{kind:"parsed",parse:String,brief:"Git repository URL to deploy",optional:!0},verbose:{kind:"boolean",brief:"Show detailed output during deployment",optional:!0},localGateway:{kind:"parsed",parse:String,brief:"Path to local gateway tarball (for testing)",optional:!0},yes:{kind:"boolean",brief:"Skip deployment confirmation",optional:!0}},aliases:{y:"yes"}},docs:{brief:"Deploy the gateway application to Cloudflare",fullDescription:["Clones the gateway repository, installs dependencies, runs migrations, and deploys to Cloudflare Workers.","The deployment process:"," 1. Clones the repository to a temporary directory"," 2. Installs npm dependencies"," 3. Runs database migrations against production D1"," 4. Runs wrangler deploy"," 5. Cleans up temporary files"].join(`
|
|
6
|
+
`)}}),i=b({routes:{deploy:g},docs:{brief:"Gateway management commands"}});var D=C({routes:{app:n,gateway:i,install:v("everyapp",{bash:"__everyapp_bash_complete"}),uninstall:w("everyapp",{bash:!0})},docs:{brief:a,hideRoute:{install:!0,uninstall:!0}}}),G=h(D,{name:t,versionInfo:{currentVersion:r},scanner:{allowArgumentEscapeSequence:!0}});export{R as a,G as b};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import{a as b}from"./chunk-AIRNFEUQ.js";import{a as x}from"./chunk-3DCJZ6LU.js";import{b as v,d as P}from"./chunk-FFEUD43M.js";import{a as k}from"./chunk-QHXECEAW.js";import{a as y,b as w,d as u,e as h}from"./chunk-VYHFMMFQ.js";import{a as s,d as C}from"./chunk-EOQC6VQV.js";import"./chunk-QKHNAJYY.js";import{b as g}from"./chunk-4AODVGRU.js";import{c as l}from"./chunk-ASNYTFJJ.js";import"./chunk-JOHMESCX.js";import f from"chalk";async function A({url:o,targetDir:e,verbose:t=!1}){try{await s("git",["clone",o,e],{verbose:t,logCommandToConsole:!1})}catch(a){throw new Error(`Failed to clone repository from ${o}: ${a instanceof Error?a.message:"Unknown error"}`)}}async function T({targetDir:o,verbose:e=!1}){try{await s("git",["init"],{verbose:e,logCommandToConsole:!1,cwd:o}),await s("git",["add","."],{verbose:e,logCommandToConsole:!1,cwd:o}),await s("git",["commit","-m","Starter template"],{verbose:e,logCommandToConsole:!1,cwd:o})}catch(t){throw new Error(`Failed to initialize git repository: ${t instanceof Error?t.message:"Unknown error"}`)}}import J from"node:fs/promises";import L from"node:path";import d from"chalk";var G=["every-app.jsonc","every-app.json"];async function D(){let o=process.cwd();for(let e of G){let t=L.join(o,e);try{await J.access(t),console.log(d.yellow(`
|
|
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 l(1)}catch{}}}import E from"chalk";import{execa as _}from"execa";async function I(){try{await _("pnpm",["--version"],{stdio:"pipe"})}catch{console.error(E.red(`
|
|
6
|
+
Error: pnpm is required but not installed. Please install it first:`)),console.error(E.cyan(` npm i -g pnpm
|
|
7
|
+
`)),await l(1)}}import q 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 R(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:z});return console.log(),{appId:e.appId}}import U from"node:path";import W from"chalk";var V="https://github.com/every-app/every-app.git",H="templates/simple-todo";async function $({appId:o,verbose:e=!1}){e&&console.log(`Cloning template repository...
|
|
9
|
+
`);let t=await u("every-app-create-");await A({url:V,targetDir:t,verbose:e}),e&&console.log(`Extracting template...
|
|
10
|
+
`);let a=U.join(t,H),n=U.join(process.cwd(),o);if(await w(n))throw new Error(`Directory "${o}" already exists in the current location`);return await y(a,n,{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 ${n}
|
|
11
|
+
`)),{tempDir:t,targetDir:n}}import j from"node:fs/promises";import M from"node:path";async function O({targetDir:o,appId:e}){let t=M.join(o,"package.json"),a=JSON.parse(await j.readFile(t,"utf-8"));a.name=e,await j.writeFile(t,JSON.stringify(a,null,2)+`
|
|
12
|
+
`,"utf-8")}import r from"chalk";function F({appId:o,targetDir:e,gatewayUrl:t,workerUrl:a}){console.log(r.green(`Project created and deployed successfully!
|
|
13
|
+
`)),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:
|
|
14
|
+
`),console.log(r.dim(` ${r.bold(`cd ${o}`)}`)),console.log(r.dim(` ${r.bold("pnpm run dev")}`)),console.log(r.dim(` ${r.bold(`
|
|
15
|
+
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:
|
|
16
|
+
`),console.log(r.dim(` ${r.bold("npx everyapp app deploy")}`)),console.log()}async function Fo(o,e){let t=o.verbose||!1,a=o.yes||!1;await D(),await I(),await g(),await C(),console.log(`
|
|
17
|
+
Create a new Every App project
|
|
18
|
+
`);let{appId:n}=await R(e);if(console.log(f.dim(`.
|
|
19
|
+
`)),!await k("this app",a)){console.log(f.yellow(`
|
|
20
|
+
App creation cancelled.
|
|
21
|
+
`));return}let c=null;try{let{tempDir:p,targetDir:i}=await $({appId:n,verbose:t});c=p,await O({targetDir:i,appId:n}),await v(i,{appId:n});let{workerUrl:N,gatewayUrl:m}=await b({cwd:i,appId:n,verbose:t,devUrl:"http://localhost:3001"}),S=await P({gatewayUrl:m,appId:n});await x({targetDir:i,appId:n,verbose:t,gatewayUrl:m,gatewayAppApiToken:S}),await T({targetDir:i,verbose:t}),F({appId:n,targetDir:i,gatewayUrl:m,workerUrl:N})}catch(p){throw console.error(f.red(`
|
|
22
|
+
Failed to create project:`),p instanceof Error?p.message:"Unknown error"),p}finally{c&&await h({tmpDir:c})}}export{Fo as default};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import{a as p}from"./chunk-AIRNFEUQ.js";import{a as s}from"./chunk-7IPT3FRI.js";import{c}from"./chunk-FFEUD43M.js";import{a}from"./chunk-QHXECEAW.js";import{d as l}from"./chunk-EOQC6VQV.js";import"./chunk-QKHNAJYY.js";import{b as n}from"./chunk-4AODVGRU.js";import"./chunk-ASNYTFJJ.js";import"./chunk-JOHMESCX.js";import o from"chalk";async function A(e){await n(),await l();let t=process.cwd(),i=e.verbose||!1,m=e.yes||!1;await s();let r=await c(t);if(console.log(o.bold(`
|
|
2
|
+
Project: ${r}
|
|
3
|
+
`)),!await a("this app",m)){console.log(o.red(`
|
|
4
|
+
Deployment cancelled by user
|
|
5
|
+
`));return}let{workerUrl:f,gatewayUrl:y}=await p({cwd:t,appId:r,verbose:i});console.log(o.green(`
|
|
6
|
+
Deployment successful!`)),console.log(o.dim(` App URL: ${o.cyan(f)}`)),console.log(` Gateway: ${o.cyan(y)}
|
|
7
|
+
`)}export{A as deploy};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{d as U,e as L}from"./chunk-
|
|
1
|
+
import{a as W,b as h,c as S,d as P}from"./chunk-QHXECEAW.js";import{d as U,e as L}from"./chunk-VYHFMMFQ.js";import{a as G,b as y,c as E,e as $,f as I,h as m}from"./chunk-EOQC6VQV.js";import"./chunk-QKHNAJYY.js";import{b as A,e as R,g as _,i as b,j as k,l as D,p as x,q as v,r as K}from"./chunk-4AODVGRU.js";import{c as T}from"./chunk-ASNYTFJJ.js";import"./chunk-JOHMESCX.js";import g from"chalk";import de from"node:path";import d from"chalk";var j="every-app-gateway",q="every-app-gateway";async function O({verbose:e=!1}={}){console.log(`
|
|
2
2
|
Setting up your Cloudflare D1 Database and KV Store...
|
|
3
3
|
`);let o=await R(),a=await Q(j,o,e),t=await X(q,o,e);return console.log(),{d1DatabaseId:a,kvNamespaceId:t,accountId:o}}async function Q(e,o,a){a&&console.log(` Checking D1 database: ${e}`);let t=await b(e,o);return a?t.wasCreated?console.log(d.green(` Created D1 database: ${e} (${t.id})
|
|
4
4
|
`)):console.log(d.dim(` Linking to existing D1 database: ${e} (${t.id})
|
|
@@ -12,7 +12,7 @@ Setting up your Cloudflare D1 Database and KV Store...
|
|
|
12
12
|
`:` Finished.
|
|
13
13
|
`)}catch(r){throw console.error(`
|
|
14
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
|
|
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 v({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
16
|
|
|
17
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
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
|
|
@@ -32,7 +32,7 @@ Every App Gateway
|
|
|
32
32
|
`)),!await W("the Gateway",t)){console.log(`
|
|
33
33
|
Deployment cancelled by user
|
|
34
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
|
|
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 K(l);s=await _(z),await J({gatewayPath:n,resources:i,workerUrl:s,verbose:o}),await $({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
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
37
|
Gateway deployment successful!
|
|
38
38
|
`)),await E(s))console.log(`Your Gateway is now live at: ${g.cyan(s)}
|
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-YRO4PVS3.js";import{a as r,b as o}from"./chunk-ASNYTFJJ.js";import"./chunk-JOHMESCX.js";import{run as e}from"@stricli/core";r();await e(t,process.argv.slice(2),i(process));await o();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{b as i
|
|
1
|
+
import{a}from"./chunk-QKHNAJYY.js";import{b as i}from"./chunk-4AODVGRU.js";import"./chunk-ASNYTFJJ.js";import"./chunk-JOHMESCX.js";import r from"chalk";import{execa as l}from"execa";async function g(m,...o){await i();let n=process.cwd();try{if(!o||o.length===0)throw new Error(`No command provided. Usage: npx everyapp app remote-d1-shell -- <command>
|
|
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(`
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{a as l}from"./chunk-3DCJZ6LU.js";import{a as c}from"./chunk-7IPT3FRI.js";import{c as p,d as i}from"./chunk-FFEUD43M.js";import"./chunk-VYHFMMFQ.js";import{d as r}from"./chunk-EOQC6VQV.js";import{b as n}from"./chunk-4AODVGRU.js";import"./chunk-ASNYTFJJ.js";import"./chunk-JOHMESCX.js";import o from"chalk";async function L(s){let t=process.cwd(),m=s.verbose||!1;await c(),await n();let a=await r(),e=await p(t),u=await i({gatewayUrl:a,appId:e});console.log(o.bold(`
|
|
2
|
+
Setting up local environment for ${e}
|
|
3
|
+
`)),await l({targetDir:t,appId:e,gatewayUrl:a,gatewayAppApiToken:u,verbose:m,installDeps:!0}),console.log(o.green(`Local setup complete!
|
|
4
|
+
`)),console.log(`Run the app locally:
|
|
5
|
+
`),console.log(o.dim(` ${o.bold("pnpm run dev")}
|
|
6
|
+
`))}export{L as setupLocal};
|
package/package.json
CHANGED
package/dist/chunk-7SUABVTF.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
Missing CLOUDFLARE_ACCOUNT_ID
|
|
3
|
-
`)),console.log(`When using CLOUDFLARE_API_TOKEN, you must also set CLOUDFLARE_ACCOUNT_ID.
|
|
4
|
-
`),console.log(i.dim(` export CLOUDFLARE_ACCOUNT_ID=<your_account_id>
|
|
5
|
-
`)),await h(1)),!(n&&o))try{await w()}catch{console.log(t?i.yellow(`
|
|
6
|
-
Already have a Cloudflare account?
|
|
7
|
-
`):i.yellow(`
|
|
8
|
-
Please log in to Cloudflare.
|
|
9
|
-
`)),console.log(i.dim(" 1. Cloudflare CLI (recommended): npx wrangler login")),console.log(i.dim(` 2. Environment variables: CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID
|
|
10
|
-
`)),t&&(console.log(i.yellow(`Don't have a Cloudflare account?
|
|
11
|
-
`)),console.log("Every App uses Cloudflare so that you can inexpensively host your applications"),console.log("on a secure and powerful platform without needing to think about the machines"),console.log(`your code runs on.
|
|
12
|
-
`),console.log(`Here are the steps to get started:
|
|
13
|
-
`),console.log(i.dim(" 1. Create a Cloudflare account (free, no credit card required):")),console.log(i.cyan(` https://dash.cloudflare.com/sign-up
|
|
14
|
-
`)),console.log(i.dim(` - Skip any Cloudflare onboarding like configuring a domain, this is unnecessary for Every App.
|
|
15
|
-
`)),console.log(i.dim(` 2. Check your email to verify your email address
|
|
16
|
-
`)),console.log(i.dim(" 3. Log in to Cloudflare via the CLI:")),console.log(i.cyan(` npx wrangler login
|
|
17
|
-
`)),console.log(i.dim(" - Learn more: ")+i.cyan(`https://developers.cloudflare.com/workers/wrangler/commands/#login
|
|
18
|
-
`))),await h(1)}}async function w(){let e=process.env.CLOUDFLARE_API_TOKEN;if(e)return e;let t=await L();if(F(t.expiration_time)){let n=await U(t.refresh_token);return await T(n),n.oauth_token}return t.oauth_token}async function s(e,t={}){let n=await w(),o=await fetch(`https://api.cloudflare.com/client/v4${e}`,{...t,headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json",...t.headers}}),r=await o.json();if(!o.ok){let a=r.errors?r.errors.map(u=>`[${u.code}] ${u.message}`).join(", "):o.statusText;throw new Error(`Cloudflare API request failed: ${o.status} ${a}`)}if(!r.success){let a=r.errors.map(u=>`[${u.code}] ${u.message}`).join(", ");throw new Error(`Cloudflare API error: ${a}`)}return r.result}async function l(){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 j(e){let t=await s(`/accounts/${e}`);if(!t||!t.id)throw new Error(`Account ${e} not found`);return t}async function E(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 S(e,t){let n=t||await l(),o=await E(n);return`https://${e}.${o}.workers.dev`}import C from"chalk";var O={EMAIL_NOT_VERIFIED:10034,R2_NOT_ENABLED:10042},W={[O.EMAIL_NOT_VERIFIED]:{userMessage:"Almost there! Your Cloudflare account email needs to be verified first.",action:`To verify your email address:
|
|
19
|
-
|
|
20
|
-
1. Check your inbox for a verification email from Cloudflare
|
|
21
|
-
2. Click the verification link in the email
|
|
22
|
-
3. Or visit ${C.cyan("https://dash.cloudflare.com/profile")} to resend the verification email
|
|
23
|
-
|
|
24
|
-
Then run this command again.`},[O.R2_NOT_ENABLED]:{userMessage:"R2 not enabled",action:`R2 is Cloudflare's file storage service, used for storing images and files.
|
|
25
|
-
|
|
26
|
-
${C.cyan("https://dash.cloudflare.com/{accountId}/r2/plans")}
|
|
27
|
-
|
|
28
|
-
${C.dim(" Visit the URL above to enable R2, then run this command again.")}`}};function M(e){let t=e.match(/\[code:\s*(\d+)\]/);if(t?.[1])return parseInt(t[1],10);let n=e.match(/"code"\s*:\s*(\d+)/);if(n?.[1])return parseInt(n[1],10);let o=e.match(/\[(\d{5})\]/);if(o?.[1])return parseInt(o[1],10)}function B(e){let t=W[e];if(t)return{code:e,...t}}function V(e){let t="";return e instanceof Error?(t=e.message,"stdout"in e&&typeof e.stdout=="string"&&(t+=`
|
|
29
|
-
`+e.stdout),"stderr"in e&&typeof e.stderr=="string"&&(t+=`
|
|
30
|
-
`+e.stderr),"all"in e&&typeof e.all=="string"&&(t+=`
|
|
31
|
-
`+e.all)):typeof e=="string"&&(t=e),t}async function K(e,t){let n=e.action,o=t.accountId;if(!o&&n.includes("{accountId}"))try{o=await l()}catch{}return o&&(n=n.replace(/{accountId}/g,o)),`
|
|
32
|
-
${C.yellow(e.userMessage)}
|
|
33
|
-
|
|
34
|
-
${n}
|
|
35
|
-
`}async function q(e,t={}){let n=V(e),o=M(n);if(o===void 0)return;let r=B(o);return r?{formatted:await K(r,t),code:o}:void 0}import d from"chalk";import z from"enquirer";async function J(e,t){try{let n=t?{subdomain:t}:{},o=await s(`/accounts/${e}/workers/subdomain`,{method:"PUT",body:JSON.stringify(n)});if(!o||!o.subdomain)throw new Error("Failed to initialize workers.dev subdomain");return o.subdomain}catch(n){throw new Error(`Failed to initialize workers.dev subdomain: ${n instanceof Error?n.message:"Unknown error"}`)}}async function H(){return(await z.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 Y(){let e=await l();try{return await E(e)}catch{console.log(),console.log(d.yellow(` Please claim a Cloudflare subdomain.
|
|
36
|
-
`)),console.log(d.dim(` All your apps will be deployed to this domain.
|
|
37
|
-
`)),console.log(d.dim(" You can make it your name or a something fun.")),console.log(d.dim(` E.g. All apps will be deployed to "janedoe.workers.dev"
|
|
38
|
-
`));let t=await H();console.log(d.dim(`
|
|
39
|
-
Creating subdomain: ${t}...
|
|
40
|
-
`));try{let n=await J(e,t);return console.log(d.green(` Successfully created subdomain: ${d.cyan(n)}
|
|
41
|
-
`)),n}catch(n){throw console.error(d.red(`
|
|
42
|
-
Failed to create subdomain`),d.dim(`
|
|
43
|
-
${n instanceof Error?n.message:"Unknown error"}`)),n}}}import{z as g}from"zod";var v="every-";function X(e){return e.startsWith(v)?e:`${v}${e}`}var G=g.object({uuid:g.string(),name:g.string(),created_at:g.string().optional(),version:g.string().optional()}),P=g.array(G);async function k(e){let t=await s(`/accounts/${e}/d1/database?per_page=1000`);return P.parse(t)}async function Q(e,t){let n=await s(`/accounts/${t}/d1/database`,{method:"POST",body:JSON.stringify({name:e})});if(!n||!n.uuid)throw new Error("Failed to create D1 database: no UUID returned");return n.uuid}async function Z(e,t){let o=(await k(t)).find(a=>a.name===e);return o?{id:o.uuid,name:e,wasCreated:!1}:{id:await Q(e,t),name:e,wasCreated:!0}}async function ee(e){return(await s(`/accounts/${e}/storage/kv/namespaces?per_page=1000`)).map(n=>({id:n.id,title:n.title}))}async function te(e,t){let n=await s(`/accounts/${t}/storage/kv/namespaces`,{method:"POST",body:JSON.stringify({title:e})});if(!n||!n.id)throw new Error("Failed to create KV namespace: no ID returned");return n.id}async function ne(e,t){let o=(await ee(t)).find(a=>a.title===e);return o?{id:o.id,name:e,wasCreated:!1}:{id:await te(e,t),name:e,wasCreated:!0}}async function oe(e){return(await s(`/accounts/${e}/r2/buckets?per_page=1000`)).buckets.map(n=>({name:n.name,creation_date:n.creation_date}))}async function re(e,t){let n=await s(`/accounts/${t}/r2/buckets`,{method:"POST",body:JSON.stringify({name:e})});if(!n||!n.name)throw new Error("Failed to create R2 bucket: no name returned");return n.name}async function ae(e,t){return(await oe(t)).find(r=>r.name===e)?{name:e,wasCreated:!1}:(await re(e,t),{name:e,wasCreated:!0})}import p from"chalk";async function se(){return await s("/memberships")}function _(e){return e.status==="pending"?" (pending)":""}function ie(e,t){let n=_(e);console.log(p.dim(` ${e.account.name} (${e.account.id})${n}`)),t.length>0&&(console.log(),console.log(p.dim(" Other accounts (set CLOUDFLARE_ACCOUNT_ID to switch):")),t.forEach(o=>{let r=_(o);console.log(p.dim(` - ${o.account.name}: ${o.account.id}${r}`))})),console.log()}async function ce(e){return console.log(p.yellow(`Multiple Cloudflare accounts found.
|
|
44
|
-
`)),console.log(`Please set the CLOUDFLARE_ACCOUNT_ID environment variable:
|
|
45
|
-
`),e.forEach(t=>{let n=_(t);console.log(p.dim(` ${t.account.name}: ${t.account.id}${n}`))}),console.log(p.dim(`
|
|
46
|
-
export CLOUDFLARE_ACCOUNT_ID=<account_id>
|
|
47
|
-
`)),h(1)}async function ue(e){if(e.length===0)throw new Error("No Cloudflare accounts found");let t=process.env.CLOUDFLARE_ACCOUNT_ID;!t&&e.length>1&&await ce(e);let n=t?e.find(r=>r.account.id===t):e[0];if(!n)throw new Error(`Account ${t} not found in your Cloudflare memberships`);let o=e.filter(r=>r.account.id!==n.account.id);return{account:n,otherAccounts:o}}import b from"node:fs/promises";import x from"node:path";import*as c from"jsonc-parser";import de from"chalk";async function Qe(e){e.verbose&&console.log("Updating wrangler.jsonc with resource IDs and configuration...");let t=e.configPath;(await b.stat(t)).isDirectory()&&(t=x.join(t,"wrangler.jsonc"));let o=await b.readFile(t,"utf-8"),r=c.parse(o),a=[];if(r.d1_databases){if(r.d1_databases.length===0)throw new Error("No D1 databases found in wrangler.jsonc. Every app must have exactly one D1 database.");if(r.d1_databases.length>1)throw new Error(`Found ${r.d1_databases.length} D1 databases in wrangler.jsonc. Every app must have exactly one D1 database.`)}if(r.kv_namespaces){if(r.kv_namespaces.length===0)throw new Error("No KV namespaces found in wrangler.jsonc. Every app must have exactly one KV namespace.");if(r.kv_namespaces.length>1)throw new Error(`Found ${r.kv_namespaces.length} KV namespaces in wrangler.jsonc. Every app must have exactly one KV namespace.`)}if(r.r2_buckets&&r.r2_buckets.length>1)throw new Error(`Found ${r.r2_buckets.length} R2 buckets in wrangler.jsonc. Every app must have at most one R2 bucket.`);if(e.name&&a.push(...c.modify(o,["name"],e.name,{})),e.d1DatabaseId&&a.push(...c.modify(o,["d1_databases",0,"database_id"],e.d1DatabaseId,{})),e.d1DatabaseName&&a.push(...c.modify(o,["d1_databases",0,"database_name"],e.d1DatabaseName,{})),e.kvNamespaceId&&a.push(...c.modify(o,["kv_namespaces",0,"id"],e.kvNamespaceId,{})),e.r2BucketName&&r.r2_buckets?.length&&a.push(...c.modify(o,["r2_buckets",0,"bucket_name"],e.r2BucketName,{})),e.vars)for(let[f,A]of Object.entries(e.vars))a.push(...c.modify(o,["vars",f],A,{}));let u=c.applyEdits(o,a);await b.writeFile(t,u),e.verbose&&console.log(de.dim(` wrangler.jsonc updated successfully
|
|
48
|
-
`))}async function Ze(e){let t=await b.readFile(e,"utf-8"),n=c.parse(t);if(!n.name||typeof n.name!="string")throw new Error("Worker name not found in wrangler.jsonc");return n.name}async function N(e){let t=x.join(e,"wrangler.jsonc");try{let n=await b.readFile(t,"utf-8");return c.parse(n)}catch(n){throw n instanceof Error&&"code"in n&&n.code==="ENOENT"?new Error("wrangler.jsonc not found in current directory. Make sure you're running this command from your app's root directory."):n}}import{execa as le}from"execa";async function fe(e){let t=await N(e);if(!t.d1_databases||t.d1_databases.length===0)throw new Error("No D1 databases found in wrangler.jsonc. Please add a D1 database configuration.");let n=t.d1_databases[0];if(!n)throw new Error("No D1 database configuration found in wrangler.jsonc.");let o=n.database_name;if(!o)throw new Error("No database_name found in D1 database configuration in wrangler.jsonc.");let[r,a]=await Promise.all([l(),w()]),f=(await k(r)).find(A=>A.name===o);if(!f)throw new Error(`Database "${o}" not found in your Cloudflare account. Have you run deployment to create the database?`);return{CLOUDFLARE_ACCOUNT_ID:r,CLOUDFLARE_DATABASE_ID:f.uuid,CLOUDFLARE_API_TOKEN:a}}async function rt(e,t,n){let{cwd:o,env:r={},verbose:a=!1}=n,u=await fe(o),f={cwd:o,stdio:a?"inherit":"pipe",env:{...process.env,...r,...u}};await le(e,t,f)}export{X as a,$ as b,w as c,s as d,l as e,j as f,S as g,k as h,Z as i,ne as j,ae as k,q as l,se as m,ie as n,ue as o,Y as p,Qe as q,Ze as r,N as s,fe as t,rt as u};
|
package/dist/chunk-A5KQS3U6.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
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};
|
package/dist/chunk-GE6XCOLR.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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};
|
package/dist/chunk-WJ4TQGFK.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
CLOUDFLARE_ACCOUNT_ID is required when using CLOUDFLARE_API_TOKEN
|
|
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(`
|
|
5
|
-
Gateway not deployed
|
|
6
|
-
`)),console.log(`You need to deploy the Every App Gateway before creating or deploying apps.
|
|
7
|
-
`),console.log(p.dim(` Run: npx everyapp gateway deploy
|
|
8
|
-
`)),await m(1)),!e){let n=`${t}/sign-up`;console.log(p.yellow(`
|
|
9
|
-
Owner account required
|
|
10
|
-
`)),console.log(`You need to create an owner account on your Gateway before deploying apps.
|
|
11
|
-
`),console.log(` ${p.cyan(n)}
|
|
12
|
-
`),console.log(p.dim(` Visit the URL above to create your owner account, then run this command again.
|
|
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(`
|
|
14
|
-
`).forEach(a=>{a.trim()&&console.log(c.dim(` \u2502 ${a}`))})}),r.stderr&&r.stderr.on("data",l=>{l.toString().split(`
|
|
15
|
-
`).forEach(a=>{a.trim()&&console.error(c.dim(` \u2502 ${a}`))})});let i=await r;return console.log(c.dim(` \u2514\u2500 Complete
|
|
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
|
|
19
|
-
`)),r}async function Ae({secretName:o,secretValue:e,cwd:t,verbose:n=!1,description:s}){n&&s&&console.log(g.dim(` ${s}
|
|
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};
|
package/dist/create-R6YYEX43.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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};
|
package/dist/deploy-3PIXBICP.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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};
|