everyapp 0.3.0-rc.4 → 0.3.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access-DNIB63DI.js +1 -0
- package/dist/{activity-RTCAUMQS.js → activity-X4RPCV3W.js} +1 -1
- package/dist/ai-GHPXRRZK.js +6 -0
- package/dist/{apps-PEOBCDNU.js → apps-2OAZFYU3.js} +1 -1
- package/dist/{chunk-H4EZTXIK.js → chunk-23CPMF6I.js} +1 -1
- package/dist/chunk-2PP3ZU44.js +20 -0
- package/dist/chunk-4JP237FP.js +18 -0
- package/dist/{chunk-QFTBDXLF.js → chunk-52ZPBQ2M.js} +52 -52
- package/dist/chunk-5AUOAM57.js +1 -0
- package/dist/chunk-5DTY6SR4.js +40 -0
- package/dist/chunk-62XLUW2Z.js +8 -0
- package/dist/chunk-6BVZ7OOC.js +2 -0
- package/dist/{chunk-3EADVHFN.js → chunk-753QJBIK.js} +1 -1
- package/dist/chunk-7IO5QSK4.js +8 -0
- package/dist/chunk-AGGUD3LY.js +93 -0
- package/dist/{chunk-QKHLRLK3.js → chunk-AHAKMPNT.js} +1 -1
- package/dist/{chunk-EQLY5I46.js → chunk-B2UHEXGS.js} +1 -1
- package/dist/chunk-BL7INQ2V.js +27 -0
- package/dist/chunk-CU4WS7DF.js +1 -0
- package/dist/chunk-CV45436M.js +1 -0
- package/dist/chunk-D5HKHQTL.js +1 -0
- package/dist/{chunk-VVKQJSF3.js → chunk-DNI45OIP.js} +1 -1
- package/dist/chunk-DRDHAGMO.js +2 -0
- package/dist/{chunk-O64FPLGX.js → chunk-EOALGESI.js} +1 -1
- package/dist/chunk-EZLXWXCD.js +1 -0
- package/dist/chunk-F2SWGK4U.js +1 -0
- package/dist/{chunk-TIYSZWP5.js → chunk-G6E6ASCF.js} +1 -1
- package/dist/{chunk-NDOEON54.js → chunk-GCRYALFY.js} +1 -1
- package/dist/{chunk-RL72BUT4.js → chunk-GGZLG3MC.js} +1 -1
- package/dist/chunk-GJRF7PIC.js +5 -0
- package/dist/chunk-GP5EMUH3.js +1 -0
- package/dist/chunk-GSJHO4P7.js +1 -0
- package/dist/{chunk-BK4NK34C.js → chunk-GUS7QNHK.js} +1 -1
- package/dist/chunk-H4FU65LN.js +2 -0
- package/dist/chunk-HOR4CK57.js +8 -0
- package/dist/{chunk-TUXKBLLJ.js → chunk-J2YDBF6F.js} +1 -1
- package/dist/{chunk-KQM6ZUX5.js → chunk-JH5EEU6E.js} +1 -1
- package/dist/{chunk-SGRGD7L4.js → chunk-JQSU5VM5.js} +1 -1
- package/dist/{chunk-AMCNAKYU.js → chunk-KQAA5HYI.js} +1 -1
- package/dist/{chunk-ORGV2NNT.js → chunk-LGVZOR22.js} +1 -1
- package/dist/chunk-LWMA2GWN.js +1 -0
- package/dist/{chunk-I7FNTTUY.js → chunk-MDNG2D3M.js} +1 -1
- package/dist/{chunk-MEIWV7FJ.js → chunk-N56HPZCZ.js} +1 -1
- package/dist/chunk-OH5GXYX2.js +29 -0
- package/dist/{chunk-R7JOHK7Y.js → chunk-OPSXAHNF.js} +1 -1
- package/dist/chunk-ORHNWNQ4.js +2 -0
- package/dist/chunk-P3YEHCHV.js +14 -0
- package/dist/chunk-PBHIXZKL.js +2 -0
- package/dist/chunk-PRGCYHQF.js +45 -0
- package/dist/{chunk-FB2OC32C.js → chunk-R5MABGNW.js} +3 -3
- package/dist/chunk-SAOL43T3.js +47 -0
- package/dist/{chunk-LI3YLKLC.js → chunk-SAVGRJLI.js} +1 -1
- package/dist/chunk-SKEL7TJM.js +1 -0
- package/dist/chunk-TC2TNQFK.js +22 -0
- package/dist/chunk-VDYNSRWF.js +46 -0
- package/dist/chunk-X22RKNHX.js +4 -0
- package/dist/{chunk-YAZHTVUV.js → chunk-X5BYKHDN.js} +1 -1
- package/dist/chunk-Y32TS22S.js +10 -0
- package/dist/chunk-YAP4HLRA.js +9 -0
- package/dist/configure-ZRZQK6YU.js +1 -0
- package/dist/create-KGP7AQTX.js +15 -0
- package/dist/{db-B7KO37SV.js → db-PUVRWGR7.js} +1 -1
- package/dist/delete-XM6I4PG5.js +3 -0
- package/dist/deploy-NMR2BDBR.js +1 -0
- package/dist/dev-4U62GQHK.js +86 -0
- package/dist/{email-SWJQXEUR.js → email-OPJYM2LS.js} +1 -1
- package/dist/{events-GJV2KVIU.js → events-EKT2E65G.js} +1 -1
- package/dist/{groups-NNTLSXMK.js → groups-ZUPQUQTD.js} +1 -1
- package/dist/index.js +98 -92
- package/dist/install-7TEG6AFG.js +1 -0
- package/dist/login-6E2PBHMI.js +1 -0
- package/dist/mcp-NEHEN57H.js +1 -0
- package/dist/provider-7RNFWF7W.js +1 -0
- package/dist/release-CYJINL2Q.js +2 -0
- package/dist/restore-37UK7CR7.js +3 -0
- package/dist/scopeSets-ML62IVVO.js +5 -0
- package/dist/secret-RDMTPPDM.js +1 -0
- package/dist/setup-SRC6JZEW.js +1 -0
- package/dist/{signin-EP5JLAT5.js → signin-HHNCDYGV.js} +1 -1
- package/dist/skills-OWAJGHBJ.js +2 -0
- package/dist/status-JJLUUQR7.js +5 -0
- package/dist/teardown-M6KPZCTY.js +22 -0
- package/dist/token-QRSF2UFM.js +1 -0
- package/dist/update-UQHWUVIE.js +1 -0
- package/dist/{workspace-VW7ZZRFP.js → workspace-65U26ZPG.js} +1 -1
- package/package.json +8 -6
- package/skills/build-every-app/SKILL.md +32 -25
- package/skills/build-every-app/patterns.md +45 -40
- package/skills/everyapp/SKILL.md +18 -10
- package/skills/everyapp/mcp.md +8 -3
- package/skills/everyapp/setup/README.md +13 -11
- package/skills/everyapp/setup/access.md +1 -1
- package/skills/everyapp/setup/ai-gateway.md +1 -1
- package/skills/everyapp/setup/ai.md +8 -5
- package/skills/everyapp/setup/email.md +5 -5
- package/skills/everyapp/setup/gateway.md +7 -8
- package/skills/everyapp/setup/google.md +16 -11
- package/skills/everyapp/setup/openai.md +1 -1
- package/skills/everyapp/setup/openrouter.md +16 -16
- package/skills/everyapp/setup/providers.md +11 -206
- package/skills/everyapp/setup/workers-ai.md +11 -11
- package/starter/.github/workflows/release.yml +30 -0
- package/starter/.prettierignore +8 -0
- package/starter/AGENTS.md +35 -0
- package/starter/CLAUDE.md +1 -0
- package/starter/README.md +35 -0
- package/starter/cloudflare.config.ts +11 -0
- package/starter/drizzle/0000_todos.sql +7 -0
- package/starter/drizzle/meta/0000_snapshot.json +65 -0
- package/starter/drizzle/meta/_journal.json +13 -0
- package/starter/drizzle.config.ts +7 -0
- package/starter/everyapp.config.ts +19 -0
- package/starter/gitignore +20 -0
- package/starter/knip.jsonc +20 -0
- package/starter/package.json +48 -0
- package/starter/public/apple-touch-icon.png +0 -0
- package/starter/public/favicon.ico +0 -0
- package/starter/src/db/index.ts +5 -0
- package/starter/src/db/schema.ts +13 -0
- package/starter/src/entry.worker.ts +9 -0
- package/starter/src/env.d.ts +5 -0
- package/starter/src/routeTree.gen.ts +86 -0
- package/starter/src/router.tsx +6 -0
- package/starter/src/routes/__root.tsx +34 -0
- package/starter/src/routes/health.ts +18 -0
- package/starter/src/routes/index.tsx +264 -0
- package/starter/src/server/events.test.ts +50 -0
- package/starter/src/server/events.ts +30 -0
- package/starter/src/server/todos.test.ts +49 -0
- package/starter/src/server/todos.ts +74 -0
- package/starter/src/serverFunctions/home.ts +61 -0
- package/starter/src/serverFunctions/todos.ts +31 -0
- package/starter/src/styles/app.css +5 -0
- package/starter/src/tools.test.ts +61 -0
- package/starter/src/tools.ts +59 -0
- package/starter/tsconfig.json +18 -0
- package/starter/vite.config.ts +29 -0
- package/starter/vitest.config.ts +8 -0
- package/dist/access-YWM4BSBD.js +0 -1
- package/dist/ai-UOYQFTAX.js +0 -5
- package/dist/chunk-26KS6TD6.js +0 -1
- package/dist/chunk-4LKLQOM7.js +0 -7
- package/dist/chunk-5IC3ZN52.js +0 -1
- package/dist/chunk-ASCNE7GS.js +0 -2
- package/dist/chunk-BCTEWNN4.js +0 -6
- package/dist/chunk-DCFHBCCW.js +0 -9
- package/dist/chunk-DWTJ4OLZ.js +0 -6
- package/dist/chunk-EP3IQ354.js +0 -20
- package/dist/chunk-EP4HRYXP.js +0 -2
- package/dist/chunk-F5XK23HV.js +0 -1
- package/dist/chunk-FQ2A7YAP.js +0 -57
- package/dist/chunk-GAPQSINH.js +0 -1
- package/dist/chunk-GJK6GAWO.js +0 -1
- package/dist/chunk-HJGZGZFE.js +0 -32
- package/dist/chunk-KOBKGQ27.js +0 -91
- package/dist/chunk-KVCL64LI.js +0 -1
- package/dist/chunk-LEEUODYR.js +0 -1
- package/dist/chunk-MLTNW3AM.js +0 -8
- package/dist/chunk-NW7SJPSP.js +0 -37
- package/dist/chunk-PDPUGYJW.js +0 -47
- package/dist/chunk-R2DF3ENZ.js +0 -2
- package/dist/chunk-S2G4G73L.js +0 -18
- package/dist/chunk-V7BWZOSZ.js +0 -26
- package/dist/chunk-WVHJIYQ3.js +0 -14
- package/dist/chunk-XBD7PQN5.js +0 -2
- package/dist/configure-CAWCTPYY.js +0 -1
- package/dist/create-3ZWJQXPK.js +0 -22
- package/dist/delete-CB3EPOU4.js +0 -3
- package/dist/deploy-5O7LV5OX.js +0 -1
- package/dist/dev-4JYCVVOZ.js +0 -86
- package/dist/install-UAG3CNYW.js +0 -1
- package/dist/login-QEKMLMUB.js +0 -1
- package/dist/mcp-AFGVOM5D.js +0 -1
- package/dist/provider-622VM7UZ.js +0 -29
- package/dist/release-CXEX6O7F.js +0 -1
- package/dist/restore-PGIVEA5P.js +0 -3
- package/dist/secret-3LUDEDUW.js +0 -1
- package/dist/setup-PUD375AM.js +0 -1
- package/dist/status-LK6DNLCI.js +0 -5
- package/dist/teardown-6RURRSME.js +0 -22
- package/dist/update-YJFTOZEV.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as d,b as e,c as f,d as g,e as h,f as i}from"./chunk-N56HPZCZ.js";import{a,b,c}from"./chunk-J2YDBF6F.js";import"./chunk-QJRZFIYC.js";import"./chunk-SAOL43T3.js";import"./chunk-TC2TNQFK.js";import"./chunk-CV45436M.js";import"./chunk-AHAKMPNT.js";import"./chunk-LGVZOR22.js";import"./chunk-SKEL7TJM.js";import"./chunk-LWMA2GWN.js";import"./chunk-753QJBIK.js";import"./chunk-B2UHEXGS.js";import"./chunk-Y32TS22S.js";import"./chunk-AGGUD3LY.js";import"./chunk-GJRF7PIC.js";import"./chunk-GGZLG3MC.js";import"./chunk-G6E6ASCF.js";import"./chunk-KQAA5HYI.js";import"./chunk-MDNG2D3M.js";import"./chunk-RQBSTNL7.js";import"./chunk-P3YEHCHV.js";import"./chunk-PRGCYHQF.js";export{c as APPS_APPLICATION_NAME,b as GATEWAY_APPLICATION_NAME,a as POLICY_NAME,e as off,d as on,f as show,i as showAccess,h as turnAccessOff,g as turnAccessOn};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as v,c as w,d as x,e as A,f as g}from"./chunk-
|
|
1
|
+
import{a as v,c as w,d as x,e as A,f as g}from"./chunk-23CPMF6I.js";import{P as L,Q as R,S as U,V as z,W as D,X as j,Y as B,Z as H,l as F,m as N}from"./chunk-52ZPBQ2M.js";import"./chunk-CV45436M.js";import"./chunk-LWMA2GWN.js";import"./chunk-Y32TS22S.js";import"./chunk-AGGUD3LY.js";import"./chunk-GJRF7PIC.js";import"./chunk-GGZLG3MC.js";import"./chunk-G6E6ASCF.js";import"./chunk-MDNG2D3M.js";import"./chunk-RQBSTNL7.js";import"./chunk-P3YEHCHV.js";import{Wc as y,a as f,bd as $,d as k,lc as W,vb as I,yb as M}from"./chunk-PRGCYHQF.js";import t from"chalk";var C="workspace.update";async function ue(e){await $(e,n=>J({flags:e,out:n}))}async function ge(e){await $(e,n=>V({flags:e,out:n}))}async function fe(e){await $(e,n=>Q({flags:e,out:n}))}async function ke(e){await $(e,n=>Z({flags:e,out:n}))}async function ye(e,n){await $(e,o=>ee({flags:e,out:o},n))}async function $e(e){await $(e,n=>te({flags:e,out:n}))}async function ve(e,n){await $(e,o=>ae({flags:e,out:o},n))}var u=e=>e.toLocaleString("en-US"),T=e=>e===0?t.dim("\u2013"):`$${(e/1e6).toFixed(4)}`,K=e=>`$${(e/1e6).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}`;async function J(e){let{out:n,flags:o}=e,{ws:r}=await v(e),i=o.month??L(new Date(r.now)),s=await R(r,i),l=a=>{if(!a.callable)return t.dim("removed");if(a.capUnlimited)return t.dim("none (unlimited)");let h=[a.effectiveMonthlyCallCap===null?null:{kind:"calls",cap:u(a.effectiveMonthlyCallCap),source:a.capSource},a.effectiveMonthlyCostCapMicros===null?null:{kind:"cost",cap:K(a.effectiveMonthlyCostCapMicros),source:a.costCapSource}].filter(b=>b!==null);return h.length===0?t.dim("none"):h.map(b=>{let P=b.source==="default"?`${b.cap} ${t.dim("(default)")}`:b.cap;return a.pausedBy===b.kind?`${P} ${t.yellow("paused")}`:P}).join(" / ")},m=y(["APP","CALLS","FAILED","TOOL CALLS","TOKENS IN/OUT","COST","CAP"],s.byApp.map(a=>[a.appSlug??a.appRowId,u(a.calls),a.failures>0?t.yellow(u(a.failures)):t.dim("0"),u(a.toolCalls),`${u(a.inputTokens)}/${u(a.outputTokens)}`,T(a.costMicros),l(a)])),p=y(["MEMBER","CALLS","FAILED","TOOL CALLS","TOKENS IN/OUT","COST"],s.byMember.map(a=>[a.userId===""?t.dim("the apps themselves"):a.email??t.dim(`${a.userId} (no longer a member)`),u(a.calls),a.failures>0?t.yellow(u(a.failures)):t.dim("0"),u(a.toolCalls),`${u(a.inputTokens)}/${u(a.outputTokens)}`,T(a.costMicros)])),c=y(["PROVIDER","KIND","CALLS","FAILED","TOKENS IN/OUT","COST"],s.byTarget.map(a=>[a.target,a.kind,u(a.calls),a.failures>0?t.yellow(u(a.failures)):t.dim("0"),`${u(a.inputTokens)}/${u(a.outputTokens)}`,T(a.costMicros)])),d=s.byApp.reduce((a,h)=>a+h.calls,0),X=s.byApp.reduce((a,h)=>a+h.toolCalls,0),S=s.byApp.filter(a=>a.paused).length,E=`${r.organization.name}, ${i}: ${k(d,"provider call")} and ${k(X,"tool call")} across ${k(s.byApp.length,"app")}${S>0?`, ${S} paused`:""}`,O=[s.defaultMonthlyCallCap===null?null:`${u(s.defaultMonthlyCallCap)} calls a month`,s.defaultMonthlyCostCapMicros===null?null:`${K(s.defaultMonthlyCostCapMicros)} a month`].filter(a=>a!==null),G=O.length===0?"No workspace default cap.":`Workspace default cap: ${O.join(" or ")} for every app without its own.`;n.emit({type:"done",message:E,display:[E,t.dim(G),"",t.bold("By app"),...s.byApp.length>0?m:[t.dim("no apps")],"",t.bold("By member"),...s.byMember.length>0?p:[t.dim("no calls")],"",t.bold("By provider"),...s.byTarget.length>0?c:[t.dim("no calls")],"",t.dim(`Cap an app: ${f} workspace app cap <app> [<n|off>] [--usd <dollars|off>] [--unlimited]; the default: ${f} workspace cap default [<n|off>] [--usd <dollars|off>]`)].join(`
|
|
2
2
|
`),data:{organization:r.organization,...s}})}async function V(e){let{out:n,flags:o}=e,{ws:r}=await v(e),i=o.app===void 0?void 0:await N(r,o.app,{callable:!0}),s=o.user===void 0?void 0:await w(r,o.user),l=await U(r,{limit:o.limit,before:o.before,appRowId:i?.id,userId:s?.id,decision:o.decision,risk:o.risk,since:o.since}),m=y(["WHEN (UTC)","WHO","APP","TOOL","RISK","DECISION","OUTCOME","MS","CLIENT"],l.calls.map(d=>[A(d.createdAt),d.user.email??t.dim(d.user.id),d.app.slug?`${d.app.slug}${d.app.removed?t.dim(" (removed)"):""}`:t.dim("gateway"),d.tool.via?`${d.tool.name} ${t.dim(`via ${d.tool.via}`)}`:d.tool.name,d.tool.risk??t.dim("\u2013"),d.decision==="allowed"?t.green("allowed"):t.red(`blocked${d.reason?t.dim(` (${d.reason})`):""}`),d.outcome,d.durationMs===null?t.dim("\u2013"):String(d.durationMs),d.credential.clientName??d.credential.clientInfo??t.dim(d.credential.kind)])),p=l.nextBefore?`${l.nextBefore.createdAt}:${l.nextBefore.id}`:null,c=`${k(l.calls.length,"tool call")} in ${r.organization.name}${l.nextBefore?" (more before this page)":""}`;n.emit({type:"done",message:c,display:[l.calls.length>0?m.join(`
|
|
3
3
|
`):t.dim("No tool calls match."),...p?[t.dim(`Next page: ${f} workspace activity --before ${p}`)]:[]].join(`
|
|
4
4
|
`),data:{organization:r.organization,calls:l.calls.map(d=>({...d,createdAt:g(d.createdAt)})),nextBefore:p,...p?{next:[{command:`${f} workspace activity --before ${p}`,note:"the next page"}]}:{}}})}async function Y(e,n){try{return(await F(e,n)).id}catch(o){if(!(o instanceof W)||o.code!=="USER_NOT_FOUND")throw o;return n.trim()}}async function Q(e){let{out:n,flags:o}=e,{ws:r}=await v(e),i=o.actor===void 0?void 0:await Y(r,o.actor),s=await z(r,{limit:o.limit,before:o.before,actorId:i,type:o.type,since:o.since}),l=y(["WHEN (UTC)","WHO","WHAT","SUBJECT","TYPE"],s.events.map(c=>[A(c.time),I(c.actor),c.label,M(c.subject)||t.dim("\u2013"),t.dim(c.type)])),m=s.nextBefore?`${s.nextBefore.time}:${s.nextBefore.id}`:null,p=`${k(s.events.length,"audit event")} in ${r.organization.name}${s.nextBefore?" (more before this page)":""}`;n.emit({type:"done",message:p,display:[s.events.length>0?l.join(`
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{c as Y,d as j,e as f,f as F,k as W}from"./chunk-52ZPBQ2M.js";import{C as I}from"./chunk-SAOL43T3.js";import{a as k}from"./chunk-TC2TNQFK.js";import"./chunk-CV45436M.js";import{a as x,f as R}from"./chunk-GP5EMUH3.js";import"./chunk-LGVZOR22.js";import"./chunk-SKEL7TJM.js";import"./chunk-LWMA2GWN.js";import"./chunk-753QJBIK.js";import"./chunk-X22RKNHX.js";import"./chunk-OH5GXYX2.js";import"./chunk-B2UHEXGS.js";import{d as D,f as P}from"./chunk-Y32TS22S.js";import"./chunk-AGGUD3LY.js";import"./chunk-GJRF7PIC.js";import"./chunk-GGZLG3MC.js";import"./chunk-G6E6ASCF.js";import"./chunk-KQAA5HYI.js";import{a as E}from"./chunk-MDNG2D3M.js";import"./chunk-RQBSTNL7.js";import"./chunk-P3YEHCHV.js";import{V as h,Vc as T,Wc as G,a as d,bd as y,i as b,lc as v}from"./chunk-PRGCYHQF.js";import m from"chalk";var z="everyapp",A="ai.update";async function me(t){await y(t,e=>V({flags:t,out:e}))}async function ue(t){await y(t,e=>q({flags:t,out:e}))}async function ge(t,e){await y(t,a=>U({flags:t,out:a},e))}async function pe(t,e){await y(t,a=>B({flags:t,out:a},e,{chat:t.chat,embeddings:t.embeddings}))}async function ye(t){await y(t,e=>H({flags:t,out:e},t.id))}async function fe(t){await y(t,e=>J({flags:t,out:e}))}async function w(t){let{flags:e,out:a,createCf:o}=t,s=await P({gateway:D(e.gateway),accountId:e["account-id"],interactive:E(e.json??!1),login:{json:e.json,out:a,step:"login"},createCf:o}),i=await W(s.db,s.deployer,{now:t.now?.()});return{gateway:s,ws:i,registry:await k(s.db,s.install)}}function C(t){let{resolution:e,aiGateway:a}=t;return{provider:e.provider,label:e.label,model:e.model,...e.embeddingsModel?{embeddingsModel:e.embeddingsModel}:{},seed:e.seed,source:e.source,configured:e.configured,settings:e.settings,via:e.via,chat:e.chat,...e.embeddings?{embeddings:e.embeddings}:{},candidates:e.candidates,...e.problem?{problem:e.problem}:{},aiGateway:a}}var _=t=>`${t.label} (${t.model})`,O=(t,e)=>t===void 0?m.dim("\u2014"):t===e?`${t} ${m.dim("(seed)")}`:t,N=["Provider","Name","Key","Setting","Chat model","Embeddings model",""];function S(t,e){return t.map(a=>[a.id===e?m.bold(a.id):a.id,a.label,a.configured?m.green("set"):m.dim("not set"),a.settings.join(" "),O(a.model,a.seed.chat),O(a.embeddingsModel,a.seed.embeddings),a.id===e?m.green("\u2190 the default"):""])}function K(t){let{resolution:e}=t;switch(e.source){case"setting":return e.configured?`Chosen with ${d} ai default; ${e.settings.join(" and ")} ${e.settings.length===1?"is":"are"} set.`:`Chosen with ${d} ai default, but ${b(e.settings)} ${e.settings.length===1?"isn't":"aren't"} set: apps get ai_default_not_configured until ${d} secret set ${e.settings.join(" ")}.`;case"order":return`Nothing chosen: the first provider of the order whose key is set. ${d} ai default <provider> picks another.`;case"none":return`Nothing is set yet: apps that need a chat model show "Needs setup" until one key is set (${d} secret set ${e.settings.join(" ")}, or any provider's below).`}}async function V(t){let{out:e}=t,{gateway:a,ws:o,registry:s}=await w(t),i=await f(a.cf,o,s),{resolution:n,aiGateway:u}=i,c=[...T([{label:"Default",value:n.configured?_(n):`${_(n)} ${m.yellow("not configured")}`},{label:"Route",value:`/api/ai/default/v1/chat/completions \u2192 ${n.chat.path}${n.embeddings?`; /v1/embeddings \u2192 ${n.embeddings.path}`:""}`},{label:"Through",value:u.on?"Cloudflare AI Gateway":`direct (${d} ai gateway on puts AI Gateway in front)`}]),"",K(i),...n.problem?[m.yellow(`The stored choice can't serve: ${n.problem}.`)]:[],"",...G(N,S(n.candidates,n.provider))];e.emit({type:"done",message:c.join(`
|
|
2
|
+
`),data:C(i)})}async function q(t){let{out:e}=t,{gateway:a,ws:o,registry:s}=await w(t),i=await f(a.cf,o,s),{resolution:n}=i;e.emit({type:"done",message:[...G(N,S(n.candidates,n.provider)),"",`An app that pins a provider lists it under providers; one that takes the default says ai: { chat: true }. ${d} ai default <provider>[/<model>] chooses; ${d} ai model <provider> --chat <model> --embeddings <model> sets a provider's models (seed puts the catalog's back).`].join(`
|
|
3
|
+
`),data:{candidates:n.candidates,provider:n.provider,aiGateway:i.aiGateway}})}async function U(t,e){let{out:a}=t,o=F(e),{gateway:s,ws:i,registry:n}=await w(t);a.emit({type:"step",step:A,status:"start",message:"Setting the default model provider..."});let u=await Y(i,o,n),c=await f(s.cf,i,n),{resolution:r}=c,l=p=>p===null?"the shipped order":h(p);a.emit({type:"step",step:A,status:"ok",message:`${i.organization.name}: the default model provider is ${l(o)}`,data:{choice:o===null?null:h(o),was:u.was===null?null:h(u.was)}});let g=[u.changed?`${i.organization.name}: the default is ${l(o)} (was ${l(u.was)}).`:`${i.organization.name} had ${l(o)} already. Nothing changed.`,`Apps that ask for the default get ${_(r)} on the Gateway within 30 seconds.`];r.configured||g.push(m.yellow(`${b(r.settings)} ${r.settings.length===1?"isn't":"aren't"} set: until then those apps get ai_default_not_configured. Set it: ${d} secret set ${r.settings.join(" ")}`)),a.emit({type:"done",message:g.join(`
|
|
4
|
+
`),data:C(c)})}function M(t){if(t===void 0)return;let e=t.trim();return e==="seed"?null:e}async function B(t,e,a){let{out:o}=t,s=e.trim(),i=M(a.chat),n=M(a.embeddings);if(i===void 0&&n===void 0)throw new v("AI_DEFAULT_INVALID","Give --chat <model>, --embeddings <model>, or both (seed puts the catalog's back)",{fix:`${d} ai model ${s||"<provider>"} --chat <model>`});let{gateway:u,ws:c}=await w(t);o.emit({type:"step",step:A,status:"start",message:`Setting ${s}'s default models...`});let r=await j(c,s,{...i===void 0?{}:{chat:i},...n===void 0?{}:{embeddings:n}}),l=await f(u.cf,c),g=l.resolution.candidates.find($=>$.id===s);o.emit({type:"step",step:A,status:"ok",message:`${c.organization.name}: ${s}'s default models are set`,data:{provider:s,models:r.models,previous:r.previous}});let p=$=>$??"the seed",L=[r.changed?`${c.organization.name}: ${s} serves chat ${p(r.models.chat)}, embeddings ${p(r.models.embeddings)} (was chat ${p(r.previous.chat)}, embeddings ${p(r.previous.embeddings)}).`:`${c.organization.name}: ${s}'s models were set like that already. Nothing changed.`,g?`Apps that take the default and name no model get ${g.model}${g.embeddingsModel?` and ${g.embeddingsModel} for embeddings`:""} from ${g.label} within 30 seconds${l.resolution.provider===s?"":` once it is the default (now ${l.resolution.label})`}.`:""].filter(Boolean);o.emit({type:"done",message:L.join(`
|
|
5
|
+
`),data:{...C(l),change:r}})}async function H(t,e=z){let{out:a}=t,o=e.trim().toLowerCase();if(!x(o))throw new v("AI_GATEWAY_ID_INVALID",`${e} isn't a valid AI Gateway id: lowercase letters, digits and single hyphens, 64 characters at most`,{fix:`${d} ai gateway on --id <name>`});let s=await w(t),i=t.ensureAiGateway??R;a.emit({type:"step",step:"ai.gateway",status:"start",message:`Finding AI Gateway ${o}...`});let n=await i(s.gateway.cf,{id:o,accountId:s.gateway.accountId});a.emit({type:"step",step:"ai.gateway",status:"ok",message:n.created?`Made AI Gateway ${n.id}`:`AI Gateway ${n.id} exists`,data:{id:n.id,url:n.url,created:n.created}}),await I(s.gateway,{AI_GATEWAY_ID:n.id},{flags:t.flags,out:a}),a.emit({type:"done",message:[`Every model call to a provider AI Gateway fronts goes through ${n.url} from the Gateway's next request, the provider's own key still on it.`,`Logs: Cloudflare dashboard \u2192 AI \u2192 AI Gateway \u2192 ${n.id}. For an authenticated gateway: ${d} secret set AI_GATEWAY_API_KEY.`].join(`
|
|
6
|
+
`),data:{id:n.id,url:n.url,created:n.created}})}async function J(t){let{out:e}=t,a=await w(t),o=await f(a.gateway.cf,a.ws);if(!o.names.includes("AI_GATEWAY_ID")){e.emit({type:"done",message:"AI Gateway isn't in front: AI_GATEWAY_ID isn't set. Nothing changed.",data:{on:!1,changed:!1}});return}await I(a.gateway,{AI_GATEWAY_ID:null},{flags:t.flags,out:e}),e.emit({type:"done",message:`Model calls go direct from the Gateway's next request. The AI Gateway and its logs stay in the account${o.names.includes("AI_GATEWAY_API_KEY")?`; AI_GATEWAY_API_KEY stays until ${d} secret unset AI_GATEWAY_API_KEY`:""}.`,data:{on:!1,changed:!0}})}export{U as chooseDefault,B as chooseModels,fe as gatewayOff,ye as gatewayOn,ue as list,q as listCandidates,ge as setDefault,pe as setModel,me as show,V as showDefault,J as turnGatewayOff,H as turnGatewayOn};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as v,g as X,h as O,j as Y}from"./chunk-
|
|
1
|
+
import{a as v,g as X,h as O,j as Y}from"./chunk-23CPMF6I.js";import{H,J,K,L as q,M as B,N as Q,m as V}from"./chunk-52ZPBQ2M.js";import{a as D,e as _,f as L}from"./chunk-CV45436M.js";import"./chunk-LWMA2GWN.js";import"./chunk-Y32TS22S.js";import"./chunk-AGGUD3LY.js";import"./chunk-GJRF7PIC.js";import{a as R}from"./chunk-GGZLG3MC.js";import"./chunk-G6E6ASCF.js";import"./chunk-MDNG2D3M.js";import"./chunk-RQBSTNL7.js";import"./chunk-P3YEHCHV.js";import{Wc as E,a as C,bd as $,d as w,lc as N,pc as F}from"./chunk-PRGCYHQF.js";import m from"chalk";var h="workspace.update";async function ke(e){await $(e,n=>re({flags:e,out:n}))}async function Ce(e,n){await $(e,a=>pe({flags:e,out:a},n))}async function Se(e,n){await $(e,a=>ce({flags:e,out:a},n))}var ee=e=>e==="off"?null:e;async function Ae(e,n,a){await $(e,r=>le({flags:e,out:r},n,a===void 0?void 0:ee(a),e.unlimited??!1,e.usd))}async function Me(e,n){await $(e,a=>ue({flags:e,out:a},n===void 0?void 0:ee(n),e.usd))}function se(e){if(!e)return null;try{let n=JSON.parse(e);return n&&typeof n=="object"&&!Array.isArray(n)?n:null}catch{return null}}function ie(e,n){let a=se(e.manifest);if(!a||e.tier==="dispatch"||e.status==="pending")return null;try{return L(a)?_({manifest:a,appId:e.appSlug,gatewayNames:n,secretNames:R(e.secretNames)}).setup:null}catch{return null}}var P=(e,n)=>({id:e.id,appId:e.appSlug,name:e.name,description:e.description,status:e.status,scope:e.scope,tier:e.tier,hostname:e.hostname,everyone:e.everyone,accessCount:e.accessCount,...n===void 0?{}:{setup:n}});async function re(e){let{out:n}=e,{gateway:a,ws:r}=await v(e),u=await H(r),s=null;try{s=await D(a.cf)}catch(t){n.emit({type:"warning",code:"SETTINGS_UNKNOWN",message:`Couldn't list the Gateway's settings, so what each app needs set is unknown
|
|
2
2
|
${F(t)}`})}let p=u.map(t=>({app:t,setup:ie(t,s)})),l=E(["APP","NAME","STATUS","WHO CAN OPEN","SETUP"],p.map(({app:t,setup:o})=>[t.appSlug,t.name,t.status==="active"?m.green(t.status):m.yellow(t.status),t.scope==="shared"?"everyone, every organization":t.everyone?`everyone ${m.dim(`(${t.accessCount})`)}`:w(t.accessCount,"member"),o===null?m.dim("\u2013"):o.ready?m.green("ready"):m.yellow(`needs ${o.unmet.map(g=>g.names.join(" or ")).join(", ")}`)])),c=p.filter(({setup:t})=>t&&!t.ready);n.emit({type:"done",message:`${w(u.length,"app")} in ${r.organization.name}${c.length>0?`, ${c.length} needing setup`:""}`,display:u.length>0?l.join(`
|
|
3
3
|
`):m.dim(`No apps in ${r.organization.name} yet.`),data:{organization:r.organization,apps:p.map(({app:t,setup:o})=>P(t,o)),...c.length>0?{next:c.flatMap(({app:t,setup:o})=>o?.command?[{command:o.command.command,note:t.appSlug}]:[])}:{}}})}async function pe(e,n){let{out:a,flags:r}=e,{ws:u}=await v(e);a.emit({type:"step",step:h,status:"start",message:`Updating ${n}...`});let{app:s,granted:p}=await J(u,n,{name:r.name,description:r.description,everyone:r.everyone===void 0?void 0:r.everyone==="on"});a.emit({type:"step",step:h,status:"ok",message:`Updated ${s.appSlug}`,data:{appRowId:s.id,granted:p}});let l=[`${s.appSlug} is "${s.name}"${s.description?`: ${s.description}`:""}.`,s.scope==="shared"?"A shared app: every member of every organization can open it.":s.everyone?`Available to everyone in ${u.organization.name}${p>0?` (${w(p,"member")} granted now)`:""}; new members get it on joining.`:`Private: ${w(s.accessCount,"member")} can open it (workspace app access ${s.appSlug}).`];a.emit({type:"done",message:l.join(`
|
|
4
4
|
`),display:[l[0],m.dim(l[1])].join(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{k as m,l as d}from"./chunk-52ZPBQ2M.js";import{d as l,f as p}from"./chunk-Y32TS22S.js";import{a as i}from"./chunk-MDNG2D3M.js";import{lc as o}from"./chunk-PRGCYHQF.js";import s from"chalk";async function b(e){let{flags:t,out:r,createCf:n}=e,a=await p({gateway:l(t.gateway),accountId:t["account-id"],interactive:i(t.json??!1),login:{json:t.json,out:r,step:"login"},createCf:n}),g=await m(a.db,a.deployer,{org:t.org,now:e.now?.()});return{gateway:a,ws:g,gatewayUrl:a.gatewayUrl}}function x(e){return e.interactive??i(e.flags.json??!1)}async function W(e,t){try{let r=await d(e,t);return{id:r.id,email:r.email,member:!0}}catch(r){if(!(r instanceof o)||r.code!=="USER_NOT_FOUND"||t.includes("@"))throw r;return{id:t.trim(),email:null,member:!1}}}var v=e=>e.member?e.email??e.id:`${e.id} (no longer a member)`;function F(e){return e===null?s.dim("never"):new Date(e).toISOString().slice(0,16).replace("T"," ")}var c=e=>e===null?null:new Date(e).toISOString();function C(e){return e.deactivated?s.yellow("deactivated"):s.green("active")}function h(e){return{id:e.id,email:e.email,name:e.name,role:e.primaryRole??e.role,deactivated:e.deactivated,createdAt:c(e.createdAt)}}function O(e){return{id:e.id,email:e.email,role:e.role,status:e.status,expiresAt:c(e.expiresAt),expired:!e.live&&e.status==="pending",createdAt:c(e.createdAt)}}function A(e){let{add:t,remove:r,set:n}=e;if(n&&(t||r))throw new o("FLAGS_CONFLICT","--set replaces the whole list: give it alone, or --add and --remove without it");return!t&&!r&&!n?{change:null}:{change:{add:t,remove:r,set:n}}}export{b as a,x as b,W as c,v as d,F as e,c as f,C as g,h,O as i,A as j};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import{a as he}from"./chunk-U4ATZJEU.js";import{c as pe,d as le,e as ue}from"./chunk-PBHIXZKL.js";import{a as de,b as B,c as fe,d as x,g as me,h as ge}from"./chunk-6BVZ7OOC.js";import{d as ne,h as ie,j as se,l as oe}from"./chunk-GJRF7PIC.js";import{d as ae,e as ce,f as z}from"./chunk-KQAA5HYI.js";import{b as N,c as Z,e as ee,h as te,i as re}from"./chunk-P3YEHCHV.js";import{Fc as X,Jc as D,L as C,Mb as J,Ob as K,Rb as G,Ub as R,a as T,h as Y,ic as H,lc as d,qc as Q}from"./chunk-PRGCYHQF.js";import{spawn as xe,spawnSync as Le}from"node:child_process";import M from"node:fs";import A from"node:fs/promises";import{createRequire as We}from"node:module";import g from"node:path";import{z as v}from"zod";import we from"node:fs/promises";import ye from"node:path";async function ke(e){let t=ye.join(e,C),r;try{r=(await we.readdir(t)).filter(n=>n.endsWith(".json")).sort()}catch(n){if(D(n))return[];throw n}let s=[];for(let n of r){let o=`${C}/${n}`,i=await we.readFile(ye.join(t,n),"utf8"),c;try{c=JSON.parse(i)}catch{c=i}s.push({file:o,spec:c})}return s}function lt(e){return(e??[]).map((t,r)=>({file:`release.json#providers[${r}]`,spec:t}))}function ut(e){return JSON.stringify(F(e))}function F(e){return Array.isArray(e)?e.map(F):e&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(t=>[t,F(e[t])])):e}var U="everyapp-release.tar.gz",_="migrations",be=g.join(".cloudflare","output"),j="v0",Ne="0.3.0",Te="0.3.0",Ee=/^(\.DS_Store|\._.*)$/;function Ce(e){try{return We(g.join(e,"package.json"))("@every-app/sdk/package.json").version??null}catch{return null}}var ze=ne.extend({kind:v.literal("app"),appId:v.string().min(1),cliVersion:v.string(),sdkVersion:v.string().nullable(),manifest:v.record(v.string(),v.unknown()),providers:v.array(v.unknown()).max(50).optional()});function jt(e){switch(e.kind){case"github":return`github.com/${e.repo} (release ${e.tag})`;case"url":return e.url;case"file":return e.path;case"checkout":return"this checkout"}}function Fe(e){if(e.migrations?.engine==="prisma")throw new d("RELEASE_MIGRATIONS_UNSUPPORTED",`${e.id} migrates with Prisma, which a release can't carry
|
|
2
|
+
Prisma migrations (migrations.engine "prisma") need the app's source and its Prisma CLI.`,{rerun:`${T} deploy`,rerunNote:"from the app's checkout"});if(e.migrations?.dialect==="postgresql")return z(e);let t=e.resources?.d1??[];return t.length===0?null:(ce(t,e.migrations),z(e))}async function Me(e){return(await A.readdir(e,{recursive:!0,withFileTypes:!0})).filter(t=>!t.isDirectory()).map(t=>g.relative(e,g.join(t.parentPath,t.name)).split(g.sep).join("/")).sort()}async function Ue(e){let t=(await Me(e)).filter(r=>{let s=g.posix.basename(r);return s.startsWith(".dev.vars")||s.startsWith(".env")||s.endsWith(".pem")||/(^|\/)\.cloudflare\/(state|types)(\/|$)/.test(r)||/(^|\/)\.(wrangler|everyapp)(\/|$)/.test(r)});if(t.length>0)throw new d("RELEASE_LOCAL_STATE",`Refusing to pack local state or secrets into the release:
|
|
3
|
+
${t.join(`
|
|
4
|
+
`)}`)}async function Ve(e){let t;try{t=await A.readFile(g.join(e,"meta","_journal.json"),"utf8")}catch(s){if(D(s))return[];throw s}return(JSON.parse(t).entries??[]).map(({tag:s,when:n})=>({tag:s,when:n}))}function ve(e,t){let r=Le("git",t,{cwd:e,encoding:"utf8"});return r.status===0?r.stdout.trim():null}function qe(e){return new Promise((t,r)=>{let s=xe("tar",e,{stdio:["ignore","ignore","pipe"],env:{...process.env,COPYFILE_DISABLE:"1"}}),n="";s.stderr.on("data",o=>n+=o.toString()),s.once("error",r),s.once("close",o=>o===0?t():r(new d("RELEASE_PACK_FAILED",`tar couldn't pack the release (exit ${o}): ${n.trim()}`)))})}async function _t({cwd:e,manifest:t,outFile:r,cfVersion:s,builtAt:n=new Date}){let o=g.join(e,be),i=M.existsSync(o)?(await A.readdir(o)).filter(h=>!Ee.test(h)):[];if(i.length!==1||i[0]!==j)throw new d("RELEASE_PACK_FAILED",`Expected the Build Output ${j} alone in ${o}, found ${i.length?i.join(", "):"none"}.`);let c=g.join(o,j);if(!await x(c))throw new d("RELEASE_PACK_FAILED",`The app's Build Output isn't a production build
|
|
5
|
+
A release ships only one.`,{fix:"build with `cf build` (production by default)"});let l=Fe(t),w=(await ke(e)).map(({file:h,spec:m})=>{if(typeof m=="string")throw new d("RELEASE_PACK_FAILED",`${h} isn't JSON
|
|
6
|
+
A release carries the app's provider specs; fix or delete the file.`);return m}),{dir:u,cleanup:P}=await te("app-release-stage-");try{let h=(a,p)=>A.cp(a,g.join(u,p),{recursive:!0,dereference:!0,filter:f=>!Ee.test(g.basename(f))});await h(c,g.join(be,j));let m=l?g.resolve(e,l):null,E=m!==null&&M.existsSync(m)&&M.statSync(m).isDirectory();E&&await h(m,_),await Ue(u);let $=JSON.parse(await A.readFile(g.join(e,"package.json"),"utf8").catch(()=>"{}")),k=ve(e,["rev-parse","HEAD"]),I=k!==null&&!!ve(e,["status","--porcelain","--","."]),y={schema:1,kind:"app",appId:t.id,version:$.version??"0.0.0",gitSha:k?`${k}${I?"-dirty":""}`:"unknown",builtAt:n.toISOString(),cfVersion:s,cliVersion:N,sdkVersion:Ce(e),buildOutputVersion:j,sha256:await ie(u),migrations:E?await Ve(g.join(u,_)):[],minCli:Ne,minSdk:Te,...w.length>0?{providers:w}:{},manifest:t.migrations||E?{...t,migrations:{engine:"drizzle",...t.migrations,dir:_}}:t};return await A.writeFile(g.join(u,"release.json"),`${JSON.stringify(y,null,2)}
|
|
7
|
+
`),await A.mkdir(g.dirname(r),{recursive:!0}),await A.rm(r,{force:!0}),await qe(["-czf",r,"-C",u,"."]),y}finally{await P()}}async function Ye(e,{origin:t={kind:"file",path:e},version:r=N}={}){let{dir:s,manifest:n,cleanup:o}=await se(e,"app",ze);try{oe(n,r,`${n.appId} ${n.version}`);let i;try{i=K(n.manifest,ae)}catch(l){throw l instanceof J?new d("RELEASE_INVALID",`${e} carries a manifest this everyapp refuses: ${l.message}`):l}if(i.id!==n.appId)throw new d("RELEASE_INVALID",`${e} says it is ${n.appId}, but its manifest is ${i.id}'s.`);let c=i.migrations?.dir;if(c!==void 0&&c!==_)throw new d("RELEASE_INVALID",`${e}'s manifest keeps its migrations in ${c}; a release keeps them in ${_}/.`);return{dir:s,release:n,manifest:i,origin:t,cleanup:o}}catch(i){throw await o(),i}}async function Dt(e,{out:t,fetch:r,version:s}){let n=pe(e)?ue(e):null,o;try{o=await le(e,{asset:U,what:"the app",step:"app.release",missing:`${e} is neither a URL nor a file
|
|
8
|
+
Pass a GitHub repository URL (https://github.com/<owner>/<repo>), a release tarball's URL, or a downloaded ${U}.`,out:t,fetch:r})}catch(i){throw n&&i instanceof d&&i.code==="RELEASE_NOT_FOUND"?new d("NO_RELEASE",`${n.repo} publishes no everyapp release${n.tag?` ${n.tag}`:""}
|
|
9
|
+
Its GitHub releases have no ${U}.`,{fix:`clone it, then run pnpm install in it and this checkout's ${T} deploy from its directory`}):i}try{let i=await Ye(o.tarball,{origin:o.origin,version:s});return{...i,cleanup:async()=>{await i.cleanup(),await o.cleanup()}}}catch(i){throw await o.cleanup(),i}}import{rmSync as Je}from"node:fs";import S from"node:fs/promises";import b from"node:path";import{execa as Ke}from"execa";var Ge=["drizzle.config.ts","drizzle.config.js"],Se=12e4;async function Mt({cwd:e,manifest:t,out:r}){let s=t.migrations?.engine??"drizzle",n=t.migrations?.dialect==="postgresql",o=(h,m={})=>r.emit({type:"warning",code:"SCHEMA_CHECK_SKIPPED",step:"app.schema",message:`Can't check the schema against the migrations: ${h}${m.detail?`
|
|
10
|
+
${m.detail}`:""}`,...m.fix?{data:{fix:m.fix}}:{}});if(s==="prisma"){r.emit({type:"progress",step:"app.schema",message:"To check a Prisma schema against its migrations: prisma migrate diff --from-migrations <dir> --to-schema <schema> --exit-code, with datasource.shadowDatabaseUrl set in prisma.config.ts."}),r.emit({type:"step",step:"app.schema",status:"skip",message:"Schema not checked against migrations (Prisma needs a shadow database; --verbose shows how)",data:{engine:s}});return}if(!n&&!t.resources?.d1?.length||s!=="drizzle")return;let i;try{i=(await ee(e,"drizzle-kit","drizzle-kit")).binPath}catch{o("drizzle-kit isn't installed",{fix:"add drizzle-kit to devDependencies"});return}let c=t.migrations?.config,l=await He(e,c?[c]:Ge);if(!l){o(c?`no ${c} (migrations.config)`:"no drizzle.config.ts",c?{}:{detail:'An app whose drizzle config lives elsewhere sets migrations.config to its path; an app that writes its SQL by hand sets migrations.engine to "d1-sql".'});return}r.emit({type:"step",step:"app.schema",status:"start",message:"Checking the schema..."});let w=b.resolve(e,t.migrations?.dir??"drizzle");he(e,".everyapp/"),await S.mkdir(b.join(e,".everyapp"),{recursive:!0});let u=await S.mkdtemp(b.join(e,".everyapp","schema-check-")),P=X({sync:()=>Je(u,{recursive:!0,force:!0})});try{let h=b.join(u,"migrations");await S.cp(w,h,{recursive:!0}).catch(async y=>{if(y.code!=="ENOENT")throw y;await S.mkdir(h)});let m=new Set(await $e(h)),E=b.join(u,"drizzle.config.ts");await S.writeFile(E,[`import config from ${JSON.stringify(l)};`,`export default { ...config, out: ${JSON.stringify(b.relative(e,h).split(b.sep).join("/"))} };`,""].join(`
|
|
11
|
+
`));let $=b.join(u,"report-failure.cjs");await S.writeFile($,["const report = console.error;","console.error = (...args) => {"," if (args.some((arg) => arg instanceof Error)) process.exitCode = 1;"," report(...args);","};",""].join(`
|
|
12
|
+
`));let k=await Ke(process.execPath,["--require",$,i,"generate","--config",E],{cwd:e,stdin:"ignore",reject:!1,timeout:Se,env:{NODE_NO_WARNINGS:"1"}});if((await $e(h)).filter(y=>!m.has(y)).length>0)throw new d("SCHEMA_DRIFT",`The schema has changes no migration covers
|
|
13
|
+
drizzle-kit would write a new migration for them. Nothing was migrated or uploaded.`,{rerun:"pnpm db:generate",rerunNote:"then run this again"});if(k.failed){let y=k.stderr.split(`
|
|
14
|
+
`).map(p=>p.trim()).filter(Boolean),a=y.find(p=>/^\w*Error\b/.test(p))??y.at(-1)??(k.timedOut?`no answer in ${Se/1e3} s`:`exit ${k.exitCode}`);throw new d("SCHEMA_CHECK_FAILED",`drizzle-kit couldn't compare the schema with the migrations
|
|
15
|
+
${a}. Nothing was migrated or uploaded.`,{rerun:"pnpm db:generate",rerunNote:"in a terminal; it asks about renamed columns and tables"})}r.emit({type:"step",step:"app.schema",status:"ok",message:"The schema matches the migrations."})}finally{await S.rm(u,{recursive:!0,force:!0}),P()}}async function He(e,t){for(let r of t){let s=b.join(e,r);try{if((await S.stat(s)).isFile())return s}catch{}}return null}async function $e(e){return(await S.readdir(e,{recursive:!0,withFileTypes:!0})).filter(r=>r.isFile()&&r.name.endsWith(".sql")).map(r=>b.relative(e,b.join(r.parentPath,r.name)))}var Qe=6e5,Ae={EVERYAPP_BUILD:"1"};async function Gt({cwd:e,cf:t,buildCommand:r,verbose:s}){if(r){await re(r,[],{cwd:e,env:{...process.env,...Ae,NODE_OPTIONS:Z(process.env.NODE_OPTIONS)},shell:!0,echo:s,what:"Build",code:"BUILD_FAILED"});return}await t.run({args:["build"],plane:"project",cwd:e,mode:"text",env:Ae,timeoutMs:Qe,...s?{onOutput:n=>void process.stderr.write(n)}:{}}).catch(n=>{throw n instanceof Q?new d("BUILD_FAILED",["Build failed","cf build's last lines:",...Y(n.stdout,n.stderr).map(o=>` ${o}`)].join(`
|
|
16
|
+
`)):n})}import Xe from"node:fs/promises";import V from"node:path";var Ze=new Set(["text","json","secret","version-metadata","assets","d1","kv","r2","durable-object","workflow","worker","hyperdrive","queue","vectorize","ai","browser","images","send-email","secrets-store-secret","analytics-engine-dataset"]);function Oe(e,t){return e==="EVERY_APP_GATEWAY"&&t.worker===G&&t.exportName==="AppGateway"}function L(e,t){return e===t||e.startsWith(`${t}${R}`)}var et=["allowedSenderAddresses","destinationAddress","allowedDestinationAddresses"];function Pe(e){return e===void 0?"none":Array.isArray(e)?`[${[...new Set(e.map(String))].sort().join(", ")}]`:String(e)}function Re(e){return Array.isArray(e)?`list:${[...new Set(e.map(r=>JSON.stringify(r)))].sort().join(",")}`:`one:${JSON.stringify(e??null)}`}function tt(e,t,r){let s=r?.sendEmail??[],n=s.find(i=>i.name===e);if(!n){let i=s.map(c=>c.name);return`${e} is a send-email binding that everyapp.config.ts doesn't declare in resources.sendEmail${i.length?` (it declares ${i.join(", ")})`:""}`}let o=et.filter(i=>Re(t[i])!==Re(n[i])).map(i=>`${i} is ${Pe(t[i])}, not ${Pe(n[i])}`);return o.length?`${e} isn't the send-email binding resources.sendEmail declares: ${o.join("; ")}`:null}function rt(e,t){let{workerName:r,helperWorkers:s=[]}=t,n=[];e.name!==r&&n.push(`its name is "${e.name}", not "${r}"`),n.push(...je(e),..._e(e,t));let o=e.env??{};for(let c of["EVERYAPP_IDENTITY_PUBLIC_KEYS","EVERYAPP_IDENTITY_ISSUER"])o[c]?.type!=="text"&&n.push(`${c} isn't built in`);let i=o.EVERYAPP_AUDIENCE;return(i?.type!=="text"||i.value!==r)&&n.push(`EVERYAPP_AUDIENCE isn't the Worker's name ("${r}")`),n.push(...De(o,t,(c,l)=>Oe(c,l)||s.includes(String(l.worker))),...Be(e.exports??{},t.deletedDurableObjects??[],r)),n}function nt(e,t,r){let s=[];return e.name!==t&&s.push(`its name is "${e.name}", not "${t}"`),s.push(...je(e),..._e(e,r),...De(e.env??{},r,Oe),...Be(e.exports??{},[],r.workerName)),s}function je(e){let t=[];e.workersDev!==!1&&t.push("workersDev isn't false"),e.previewUrls!==!1&&t.push("previewUrls isn't false"),e.domains?.length&&t.push("it declares domains (apps are served through the gateway)");for(let r of e.triggers??[])r.type==="scheduled"||r.type==="queue"||t.push(r.type==="fetch"?"it declares routes (apps are served through the gateway)":`it declares a trigger of type "${String(r.type)}" (apps may only declare cron schedules and consumers of their own queues)`);return e.env?.EVERYAPP_DEV&&t.push("EVERYAPP_DEV is set, which only `everyapp dev` may do"),t}function _e(e,{resources:t}){let r=Object.values(t.queues??{}).map(o=>o.name),s=r.length?`which isn't one of the app's queues in resources.queues (${r.join(", ")})`:"but an app consumes only its own queues, declared in resources.queues",n=[];for(let o of e.triggers??[]){if(o.type!=="queue")continue;let i=String(o.name??"");r.includes(i)||n.push(`it consumes queue "${i}", ${s}`);let c=o.deadLetterQueue;c!==void 0&&!r.includes(String(c))&&n.push(`its consumer of queue "${i}" sends failed messages to "${String(c)}", ${s}`)}return n}function De(e,{workerName:t,resources:r,helperWorkers:s=[],declared:n},o){let i=[],c=new Set([t,...s]),l=new Set(Object.values(r.d1??{}).map(a=>a.id)),w=new Set(Object.values(r.kv??{}).map(a=>a.id)),u=new Set(Object.values(r.hyperdrive??{}).map(a=>a.id)),P=new Set(Object.values(r.queues??{}).map(a=>a.name)),h=new Set(Object.values(r.vectorize??{}).map(a=>a.name)),m=Object.values(r.r2??{}).map(a=>a.name),E=n?.ai??[],$=n?.browser??[],k=n?.images??[],I=r.secretsStore??{},y=n?.analyticsEngine??[];for(let[a,p]of Object.entries(e)){if(!Ze.has(String(p.type))){i.push(`${a} is a ${String(p.type)} binding, which EveryApp apps can't use`);continue}switch(p.type){case"worker":o(a,p)||i.push(`${a} binds Worker "${String(p.worker)}"; apps may only bind the gateway's AppGateway and, from the app's own Worker, its helper Workers`);break;case"durable-object":c.has(String(p.worker))||i.push(`${a} binds another Worker's Durable Object ("${String(p.worker)}")`);break;case"d1":l.has(String(p.id))||i.push(`${a} isn't a D1 database the deploy provisioned`);break;case"kv":w.has(String(p.id))||i.push(`${a} isn't a KV namespace the deploy provisioned`);break;case"hyperdrive":u.has(String(p.id))||i.push(`${a} isn't a Hyperdrive config the deploy provisioned`);break;case"queue":P.has(String(p.name))||i.push(`${a} is queue "${String(p.name)}", which isn't a queue the deploy provisioned (declare it in resources.queues)`);break;case"vectorize":h.has(String(p.name))||i.push(`${a} is Vectorize index "${String(p.name)}", which isn't one the deploy provisioned`);break;case"ai":E.includes(a)||i.push(E.length>0?`${a} is a Workers AI binding, which isn't one of the app's in resources.ai (${E.join(", ")})`:`${a} is a Workers AI binding, which everyapp.config.ts doesn't declare; list it in resources.ai`);break;case"browser":$.includes(a)||i.push($.length>0?`${a} is a Browser Rendering binding, which isn't one of the app's in resources.browser (${$.join(", ")})`:`${a} is a Browser Rendering binding, which everyapp.config.ts doesn't declare; list it in resources.browser`);break;case"images":k.includes(a)||i.push(k.length>0?`${a} is an Images binding, which isn't one of the app's in resources.images (${k.join(", ")})`:`${a} is an Images binding, which everyapp.config.ts doesn't declare; list it in resources.images`);break;case"secrets-store-secret":{let f=Object.hasOwn(I,a)?I[a]:void 0;(!f||p.storeId!==f.storeId||p.secretName!==f.secretName)&&i.push(`${a} is Secrets Store secret "${String(p.secretName)}" in store "${String(p.storeId)}", which isn't the one the deploy provisioned for a binding in resources.secretsStore`);break}case"analytics-engine-dataset":{let f=y.find(W=>W.name===a);if(!f){i.push(y.length>0?`${a} is an Analytics Engine binding, which isn't one of the app's in resources.analyticsEngine (${y.map(W=>W.name).join(", ")})`:`${a} is an Analytics Engine binding, which everyapp.config.ts doesn't declare; list it in resources.analyticsEngine`);break}let q=f.dataset??H(t,a),O=String(p.name??"");O!==q?i.push(`${a} writes to dataset "${O}", not "${q}", which resources.analyticsEngine declares`):O.startsWith("every-")&&!L(O,t)&&i.push(`${a} writes to dataset "${O}", which is named like another app's; a dataset resources.analyticsEngine names starts with "every-" only as ${t}${R}<name>`);break}case"r2":{let f=String(p.name??"");m.length>0?m.includes(f)||i.push(`${a} is bucket "${f}", which isn't one of the app's buckets in resources.r2 (${m.join(", ")})`):L(f,t)||i.push(`${a} is bucket "${f}"; an app's buckets are named after its Worker (${t} or ${t}${R}<name>)`);break}case"send-email":{let f=tt(a,p,n);f&&i.push(f);break}case"workflow":{let f=String(p.name??"");(!c.has(String(p.worker))||!L(f,t))&&i.push(`${a} binds Workflow "${f}" of Worker "${String(p.worker)}"; an app binds only its own Workflows, named after its Worker (${t}${R}<name>)`);break}}}return i}function Be(e,t,r){let s=[];for(let[n,o]of Object.entries(e))if(o.type!=="worker"){if(o.type==="workflow"){let i=String(o.name??"");L(i,r)||s.push(`Workflow ${n} is named "${i}"; an app's Workflows are named after its Worker (${r}${R}<name>)`);continue}if(o.type!=="durable-object"){s.push(`export ${n} is a ${String(o.type)}, which EveryApp apps can't declare`);continue}switch(o.container!==void 0&&s.push(`Durable Object class ${n} is backed by a container, which EveryApp apps can't run`),o.state??"created"){case"created":case"renamed":break;case"deleted":t.includes(n)||s.push(`Durable Object class ${n} is marked deleted, which deletes its data; remove it from everyapp.config.ts and deploy with --allow-delete-durable-object-data instead`);break;case"transferred":s.push(`Durable Object class ${n} would move its data to Worker "${String(o.transferredTo)}"`);break;case"expecting-transfer":s.push(`Durable Object class ${n} would take the data of Worker "${String(o.transferFrom)}"'s class`);break;default:s.push(`Durable Object class ${n} has state "${o.state}", which everyapp doesn't deploy`)}}return s}async function nr({cwd:e,inputs:t}){if(!await x(V.join(e,de)))throw new d("APP_POLICY","The app's Build Output isn't a production build. The manifest's build command must run `cf build` (production by default).");let r=await st(e),s=t.helperWorkers??[],n=[],o=r.get(B);if(!o)throw new d("APP_POLICY","The app's Build Output has no default Worker. Build it from everyAppWorker() in cloudflare.config.ts.");n.push(...rt(o.config,t));for(let[c,{config:l}]of r){if(c===B)continue;let w=String(l.name);if(!s.includes(w)){n.push(`the build has a Worker "${w}" that everyapp.config.ts doesn't declare in workers`);continue}n.push(...nt(l,w,t).map(u=>`${w}: ${u}`))}for(let c of s)[...r.values()].some(({config:l})=>l.name===c)||n.push(`the build has no Worker ${c}, which everyapp.config.ts declares; add it to the Vite plugin's auxiliaryWorkers with everyAppAuxiliaryWorker()`);if(n.length>0)throw new d("APP_POLICY",`The built Worker can't be deployed as an EveryApp app:
|
|
17
|
+
- ${n.join(`
|
|
18
|
+
- `)}
|
|
19
|
+
Build it from everyAppWorker() in cloudflare.config.ts.`);let i={};for(let[c,{config:l,directory:w}]of r){if(c!==B){let u=String(l.name);i[u]=Ie(l,u)}if(l.manifest){let u={...l.manifest.modules??{}};for(let P of await ge(V.join(w,"bundle")))u[P]={type:"sourcemap"};l.manifest={...l.manifest,modules:u}}me(l),await Xe.writeFile(V.join(w,"worker.config.json"),`${JSON.stringify(l,null,2)}
|
|
20
|
+
`)}return{workflows:Ie(o.config,t.workerName),helperWorkflows:i,r2Buckets:[...new Set([...r.values()].flatMap(({config:c})=>it(c)))].sort()}}function it(e){let t=e.env??{};return Object.values(t).filter(r=>r?.type==="r2"&&typeof r.name=="string").map(r=>r.name)}function Ie(e,t){let r=[...Object.values(e.exports??{}).filter(s=>s.type==="workflow").map(s=>String(s.name)),...Object.values(e.env??{}).filter(s=>s.type==="workflow"&&s.worker===t).map(s=>String(s.name))];return[...new Set(r)]}async function st(e){let t=new Map;for await(let{name:r,config:s,directory:n}of fe(e))t.set(r,{config:s,directory:n});return t}export{Mt as a,Gt as b,nr as c,ke as d,lt as e,ut as f,U as g,jt as h,_t as i,Dt as j};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import{e as De,f as ve}from"./chunk-6BVZ7OOC.js";import{a as ye,c as ke,d as M}from"./chunk-X5BYKHDN.js";import{b as he,c as T}from"./chunk-GUS7QNHK.js";import{a as me,b as ue}from"./chunk-LGVZOR22.js";import{b as C,c as N}from"./chunk-SKEL7TJM.js";import{a as fe,c as ge,e as we}from"./chunk-SAVGRJLI.js";import{h as Q}from"./chunk-B2UHEXGS.js";import{V as de,d as ee,f as te,g as ae,h as re,i as ce,k as pe,l as G}from"./chunk-AGGUD3LY.js";import{a as oe,g as ne,i as se,k as _,m as ie,n as le}from"./chunk-GJRF7PIC.js";import{a as X}from"./chunk-G6E6ASCF.js";import{c as Z,h as q,i as J}from"./chunk-P3YEHCHV.js";import{Ic as A,Rb as D,Wb as j,a as R,b as I,d as O,lc as h,oc as F,pc as V,qc as K,rc as Y}from"./chunk-PRGCYHQF.js";import{execFile as x}from"node:child_process";import y from"node:fs/promises";import k from"node:path";import{promisify as L}from"node:util";var P=["apps/every-app-gateway","packages/sdk","packages/perimeter","packages/toolbus","pnpm-workspace.yaml","pnpm-lock.yaml"],$e=3;function Oe(e){return k.join(e,"node_modules",".cache","everyapp")}async function W(e){let t;try{({stdout:t}=await L(x)("git",["ls-files","-z","--cached","--others","--exclude-standard","--",...P],{cwd:e,maxBuffer:64*1024*1024}))}catch{return null}let a=[...new Set(t.split("\0").filter(Boolean))];return a.length>0?se(e,a):null}async function be(e){try{let{stdout:t}=await L(x)("git",["log","-1","--format=%ct","--",...P],{cwd:e}),a=Number.parseInt(t.trim(),10);return Number.isFinite(a)?a*1e3:null}catch{return null}}async function _e(e,t){let a=r=>L(x)("git",r,{cwd:e}),o=()=>a(["diff","--quiet",`gateway-v${t}`,"HEAD","--",...P]).then(()=>!1,()=>!0);try{let[r,l]=await Promise.all([a(["rev-parse","--short","HEAD"]),a(["status","--porcelain","--",...P])]),n=l.stdout.trim()!=="";return!n&&!await o()?null:{hash:r.stdout.trim(),uncommittedChanges:n}}catch{return null}}async function mt(e){let t=k.join(e,"apps","every-app-gateway"),a=async c=>JSON.parse(await y.readFile(k.join(t,c),"utf8")),[o,r,l,n]=await Promise.all([W(e),be(e),a("drizzle/meta/_journal.json"),a("package.json")]),s=String(n.version??"unknown"),i=await _e(e,s);return{treeSha256:o,origin:{kind:"checkout"},...i?{commit:i}:{},version:s,order:{schema:ie(l.entries??[]),committedAt:r??Date.now()}}}async function Ge({root:e,out:t,build:a,keep:o=$e}){let[r,l]=await Promise.all([W(e),be(e)]),n=Oe(e),s=r?k.join(n,`${r}.tar.gz`):null,i={origin:{kind:"checkout"},treeSha256:r,committedAt:l};if(s&&await A(s))try{let m=await _(s,i),d=new Date;return await y.utimes(s,d,d),t.emit({type:"step",step:"gateway.release",status:"ok",message:`Using the Gateway ${m.manifest.version} built from this checkout before (${r.slice(0,12)}).`,data:{cached:!0,treeSha256:r,release:m.manifest.version}}),m}catch{await y.rm(s,{force:!0})}let c=await a();s&&await W(e)===r&&await Te(c,s,o);let p=await _(c,{origin:{kind:"checkout"},treeSha256:s&&await A(s)?r:null,committedAt:l});return t.emit({type:"step",step:"gateway.release",status:"ok",message:`Built the Gateway ${p.manifest.version} from this checkout.`,data:{cached:!1,treeSha256:p.source.treeSha256,release:p.manifest.version}}),p}async function Te(e,t,a){let o=k.dirname(t);await y.mkdir(o,{recursive:!0});let r=`${t}.${process.pid}.partial`;await y.copyFile(e,r),await y.rename(r,t);let l=await Promise.all((await y.readdir(o)).filter(n=>n.endsWith(".tar.gz")).map(async n=>({file:k.join(o,n),usedAt:(await y.stat(k.join(o,n))).mtimeMs})));for(let{file:n}of l.sort((s,i)=>i.usedAt-s.usedAt).slice(a))n!==t&&await y.rm(n,{force:!0})}function ut({root:e,out:t,verbose:a}){return Ge({root:e,out:t,build:()=>Me(e,t,a??!1)})}async function Me(e,t,a,o=process.env){let r=k.join(e,"apps","every-app-gateway");t.emit({type:"step",step:"gateway.release",status:"start",message:"Building the Gateway from this checkout (usually 1\u20132m)",data:{dir:r}});let l=(n,s)=>J("pnpm",n,{cwd:s,env:{...o,NODE_OPTIONS:Z(o.NODE_OPTIONS)},echo:a,what:"Building the Gateway",code:"GATEWAY_BUILD_FAILED",fix:"fix the build error above, then run this again",logName:"gateway-build"});return await l(["--filter","@every-app/sdk","build"],e),await l(["run","build:release"],r),k.join(r,oe)}var We=`SELECT apps.app_slug, apps.worker_name, apps.hostname, apps.status,
|
|
2
|
+
organization_keys.org_key
|
|
3
|
+
FROM apps LEFT JOIN organization_keys
|
|
4
|
+
ON organization_keys.organization_id = apps.organization_id
|
|
5
|
+
WHERE apps.status IN ('binding', 'active', 'disabled')
|
|
6
|
+
AND apps.worker_name IS NOT NULL AND apps.hostname IS NOT NULL
|
|
7
|
+
ORDER BY apps.worker_name`;function Se(e){let t=new Map;return a=>{let o=t.get(a);return o||(o=N(e,a).then(r=>r!==null),t.set(a,o)),o}}var Re=4;async function z(e,t){let[a=[]]=await e.run([{sql:We}]),o=[],r=[];for(let c of a){let p={appId:String(c.app_slug),workerName:String(c.worker_name),hostname:String(c.hostname),status:String(c.status)};j({appId:p.appId,workerName:p.workerName,orgKey:typeof c.org_key=="string"?c.org_key:null})?o.push(p):r.push({appId:p.appId,workerName:p.workerName})}let l=[];for(let c=0;c<o.length;c+=Re){let p=o.slice(c,c+Re);l.push(...await Promise.all(p.map(m=>t(m.workerName))))}let n=o.filter((c,p)=>l[p]),s=o.filter((c,p)=>!l[p]).map(({appId:c,workerName:p})=>({appId:c,workerName:p})),i=[...new Set(n.map(c=>c.workerName))].sort();return{apps:n,appWorkers:i,appHosts:[...new Set(n.map(c=>c.hostname.toLowerCase()))].sort(),skipped:r,missing:s}}import Fe from"node:fs/promises";import Ve from"node:os";import Ke from"node:path";var xe=new Set(["A","AAAA","CNAME","NS"]),E=100,Le=95;async function B(e){let t=new Set(e.liveDomains),a=[...new Set(e.domains)].filter(c=>!t.has(c));if(a.length===0)return[];let{out:o,step:r,zone:l}=e,n=new Set(e.domains).size;if(n>E)throw new h("ZONE_CUSTOM_DOMAIN_LIMIT",`${l.name} would go over Cloudflare's ${E} Custom Domains per zone
|
|
8
|
+
The Gateway alone needs ${n} there, before other Workers' domains.`,{fix:`delete apps you no longer use (${R} delete <app>), or install a second Gateway on another domain`,data:{total:n,limit:E}});n>=Le&&o.emit({type:"warning",code:"ZONE_CUSTOM_DOMAIN_LIMIT_NEAR",step:r,message:`${l.name} is close to Cloudflare's ${E} Custom Domains per zone
|
|
9
|
+
It will hold at least ${n}, and other Workers' domains there count too.`,data:{total:n,limit:E}});let s=await Be(e,a),i=a.filter(c=>!s.includes(c));return!e.cfAsks&&i.length>0&&o.emit({type:"warning",code:"CUSTOM_DOMAIN_OWNER_UNCHECKED",step:r,message:`If another Worker already serves ${i.length===1?i[0]:`any of ${i.join(", ")}`}, it will be replaced by this deployment.`,data:{hosts:i}}),a}function ze(e){let t;return()=>t??=C(e,D).then(a=>new Set(a)).catch(a=>{if(a instanceof K)return new Set;throw a})}async function Ie({cf:e,zone:t,forceDns:a},o){try{return await ye(e,t.id,o)}catch(r){if(!Y(r,"auth"))throw r;if(a)return[];throw new h("DNS_UNREADABLE",`Can't read ${t.name}'s DNS records with this Cloudflare login
|
|
10
|
+
So it can't tell whether publishing ${o} would replace one.`,{fix:"give the API token Zone \u2192 DNS \u2192 Read",rerun:I(["--force-dns"]),authorize:!0})}}async function Be(e,t){let{cf:a,out:o,step:r,zone:l,forceDns:n}=e,s=[],i=[],c=ze(a),p=!1,m=f=>f.filter(u=>xe.has(u.type.toUpperCase())),d=new Map;for(let f of t){let u=await Ie(e,f),$=m(u);if($.length>0&&(await c()).has(f)){o.emit({type:"progress",step:r,message:`${f} is already this Gateway's Custom Domain (an earlier run published it, then stopped)`,data:{host:f}}),i.push(f);continue}if($.length>0&&s.push({host:f,records:$.map(M).join(", ")}),u.length===0&&f!==l.name){let S=ke(f);d.has(S)||d.set(S,Ie(e,S));let U=m(await d.get(S));U.length>0&&(s.push({host:f,records:`${U.map(M).join(", ")}, through ${S}`}),p=!0)}}if(s.length===0)return i;let g=s.length===1,v=g?`${s[0].host} already points somewhere else`:`${s.length} hostnames already point somewhere else`,b=g?`Its DNS record: ${s[0].records}.`:`${s.map(f=>`${f.host} (${f.records})`).join("; ")}.`,w=p?" A wildcard record stays, and keeps answering every other name.":"";if(n)return o.emit({type:"warning",code:"DNS_RECORD_REPLACED",step:r,message:g?`Replacing ${s[0].host}'s DNS record (${s[0].records})${w?`
|
|
11
|
+
${w.trim()}`:""}`:`Replacing the DNS records of ${s.length} hostnames
|
|
12
|
+
${b}${w}`,data:{conflicts:s}}),i;throw new h("DNS_RECORD_CONFLICT",`${v}
|
|
13
|
+
${b} Publishing ${g?"it replaces the record":"them replaces those records"}.${w}`,{fix:`delete ${g?"the record":"the records"} in Cloudflare (${l.name} \u2192 DNS), or use another name`})}async function It({cf:e,out:t,install:a,hostname:o,forceDns:r,cfAsks:l}){let n=!he(o,a.appBaseDomain),s=!n&&!a.liveDomains.includes(o);return s&&await B({cf:e,out:t,step:"app.domain",zone:{id:a.zoneId,name:a.zoneName},domains:[...a.liveDomains,o],liveDomains:a.liveDomains,forceDns:r,cfAsks:l}),{outsideBase:n,newHost:s}}import He from"node:fs/promises";import Ue from"node:path";async function Ae({cf:e,databaseId:t,accountId:a,dir:o,registry:r,target:l,restoreCommand:n}){let{nested:s,count:i}=await je(o),c=await ae({cf:e,databaseId:t,dir:o,nested:s});if(c.length===0)return{applied:[],fresh:!1,rollback:null};let p=c.length===i,m=null;if(p)await we(r,l);else{let d=await ee(e,t),{email:g}=await X(e);await ge(r,{target:l,databaseId:t,bookmark:d,migrations:c,createdAt:Date.now(),createdBy:de(g,a).actor}),m={restoreCommand:n,rollbackCommand:te(t,d,a)}}try{return{applied:await re({cf:e,databaseId:t,dir:o,nested:s}),fresh:p,rollback:m}}catch(d){throw new h("MIGRATION_FAILED",["Database migration failed",V(d),"Nothing was uploaded; the version that's serving keeps running.",...m?[`To roll the database back to before this run: ${m.restoreCommand}`]:[]].join(`
|
|
14
|
+
`),{data:{fix:"correct the migration",...m?{rollbackCommand:m.rollbackCommand}:{}}})}}async function je(e){let t=await He.readdir(e,{withFileTypes:!0}).catch(()=>[]),a=t.filter(r=>r.isDirectory()&&r.name!=="meta"),o=(await Promise.all(a.map(r=>A(Ue.join(e,r.name,"migration.sql"))))).filter(Boolean).length;return o>0?{nested:!0,count:o}:{nested:!1,count:t.filter(r=>r.isFile()&&r.name.endsWith(".sql")).length}}function Ee(e){return e?` Restore point saved; to undo: ${e.restoreCommand}`:""}function Ce(e){return{applied:e.applied,fresh:e.fresh,...e.rollback}}var Ye={deploy:"gateway.deploy",upgrade:"gateway.upgrade",reconcile:"gateway.reconcile"};function Ze(e){return{...e.source,version:e.manifest.version,sha256:e.manifest.sha256,minCli:e.manifest.minCli}}function qe(e,t){return t.liveVersionId===null?!1:e.manifest.sha256===t.releaseSha256||e.source.treeSha256!==null&&e.source.treeSha256===t.sourceTreeSha256}function Je(e,t){return e.sha256&&e.sha256===t.releaseSha256||e.treeSha256&&e.treeSha256===t.sourceTreeSha256?!1:le(e.order,t.releaseOrder)<0}function Xe(e,t,a={}){if(Je(e,t))throw Qe(e,t,a)}function Qe(e,t,{allowDowngradeFlag:a=!1}={}){let o=e.version===t.releaseVersion,r=c=>new Date(c.committedAt).toLocaleDateString("en-US",{month:"short",day:"numeric",timeZone:"UTC"}),l=e.origin.kind==="checkout",n=l?"This checkout's Gateway":`The Gateway from ${ne(e.origin)}`,s=o?`${n} (${e.version} from ${r(e.order)}) is older than the live one (from ${r(t.releaseOrder)})`:`${n} (${e.version}) is older than the live one (${t.releaseVersion})`,i={live:t.releaseVersion,candidate:e.version};return a?new h("DOWNGRADE_REFUSED",s,{fix:l?"git pull, then run setup again":"pass --release a newer Gateway release",rerun:I(["--allow-downgrade"]),authorize:!0,data:i}):new h("DOWNGRADE_REFUSED",s,{fix:l?"git pull":"run everyapp from a checkout at least as new",rerun:I(),rerunNote:"after that",data:i})}var H=class{constructor(t,a){this.options=t;this.liveDomains=a;this.checked=new Set(t.checkedDomains)}checked;warned=new Set;domainsFor(t){let{appBaseDomain:a,gatewayHost:o,out:r}=this.options,l=T(t,a),s=t.filter(i=>!l.includes(i)).filter(i=>!this.warned.has(i));if(s.length>0){r.emit({type:"warning",code:"APP_HOST_OUTSIDE_BASE",message:`Skipping ${s.join(", ")}: ${s.length===1?"it isn't":"they aren't"} under ${a}
|
|
15
|
+
Apps live one level below the Gateway's domain (<name>.${a}).`,data:{hosts:s}});for(let i of s)this.warned.add(i)}return De({gatewayHost:o,appHosts:l})}async check(t){await B({cf:this.options.cf,out:this.options.out,step:"gateway.domains",zone:this.options.zone,domains:t,liveDomains:[...this.liveDomains,...this.checked],forceDns:this.options.forceDns,cfAsks:this.options.interactive&&this.options.out.verbose});for(let a of t)this.checked.add(a)}};async function ra(e){let{cf:t,reason:a,release:o,db:r}=e,l=e.heldLease?null:await Q(e,Ye[a]),n=e.heldLease??l,s=null;try{let i=await pe(r);i&&!e.allowDowngrade&&Xe(Ze(o),i,{allowDowngradeFlag:e.allowDowngradeFlag});let c=i!==null&&i.liveVersionId===null&&(await C(t,D)).includes(i.gatewayHost.toLowerCase());(!i||i.liveVersionId===null)&&await G(r,Pe(e,{liveVersionId:null,liveDomains:[],liveAppWorkers:[],jwtPublicKey:null,deploymentMode:null}));let p=new H(e,i?.liveDomains??[]),m=Se(t),d=i!==null&&qe(o,i);if(a!=="reconcile"||!d){await Ne(e,{appWorkers:[],appHosts:[]},async()=>{});let v=await z(r,m).catch(()=>null);await p.check(p.domainsFor(v?.appHosts??[])),c?e.out.emit({type:"step",step:"gateway.resume",status:"ok",message:`Replacing the Gateway an earlier run uploaded at ${i.gatewayHost}
|
|
16
|
+
That run stopped before it could finish; nothing uses that upload yet.`,data:{gatewayHost:i.gatewayHost}}):await ue({cf:t,workerName:D,shownAs:"the Gateway",recordedVersionIds:[i?.liveVersionId],interactive:e.interactive,confirm:e.confirm,change:{question:`Replace it with ${o.manifest.version}?`,effect:"If it runs a newer release (an upgrade that stopped before recording itself), this puts an older one back."}}),await n.check(),s=await et(e)}let g=i?.deploymentMode??e.deploymentMode;return await tt({...e,deploymentMode:g},p,m,{liveDomains:i?.liveDomains??[],liveVersionId:i?.liveVersionId??null},n)}catch(i){throw F(i,s)}finally{await l?.release()}}async function et({cf:e,out:t,resources:a,release:o,accountId:r,db:l}){t.emit({type:"step",step:"gateway.migrations",status:"start",message:"Migrating the Gateway's database"});let n=await Ae({cf:e,databaseId:a.d1Id,accountId:r,dir:Ke.join(o.dir,"drizzle"),registry:l,target:fe,restoreCommand:`${R} db restore --gateway`});return t.emit({type:"step",step:"gateway.migrations",status:"ok",message:n.fresh?"Database created":n.applied.length>0?`Applied ${O(n.applied.length,"migration")}.${Ee(n.rollback)}`:"Database up to date",data:Ce(n)}),n.rollback}async function tt(e,t,a,o,r){let{cf:l,out:n,release:s,db:i,gatewayHost:c}=e,p=await N(l,D)===null,m=p||o.liveVersionId===null,d=await z(i,a);for(let u of d.skipped)n.emit({type:"warning",code:"APP_NOT_BOUND",message:`Skipping ${u.appId}: its Worker isn't the one everyapp registered
|
|
17
|
+
So the Gateway won't route to it.`,data:{appId:u.appId,workerName:u.workerName,fix:`deploy ${u.appId} again, or remove it with ${R} delete ${u.appId}`}});for(let u of d.missing)n.emit({type:"warning",code:"APP_WORKER_MISSING",message:`Skipping ${u.appId}: its Worker is missing
|
|
18
|
+
It was deleted by hand or never uploaded, so the Gateway won't route to it.`,data:{appId:u.appId,workerName:u.workerName,fix:`deploy ${u.appId} again, or remove it with ${R} delete ${u.appId}`}});let g=t.domainsFor(d.appHosts);await t.check(g),await r.check(),n.emit({type:"step",step:"gateway.deploy",status:"start",message:`Uploading Gateway ${s.manifest.version} with ${O(d.appWorkers.length,"app")}`,data:{appWorkers:d.appWorkers,domains:g}});let v=e.deploymentMode??"self_hosted",b=m?ce({gatewayUrl:`https://${c}`,accountId:e.accountId,deploymentMode:v}):null,w=await at(e,d,g,{before:o,secrets:{...b?.secrets,...e.stagedSecrets},jwtPublicKey:b?.jwtPublicKey??null,deploymentMode:b?v:null}),f=g.filter(u=>!t.liveDomains.includes(u));return n.emit({type:"step",step:"gateway.deploy",status:"ok",message:w.versionId?`Uploaded version ${w.versionId}`:"Uploaded",data:{versionId:w.versionId}}),{versionId:w.versionId,firstDeploy:p,appWorkers:d.appWorkers,domains:g,newHosts:f}}function at(e,t,a,{before:o,secrets:r,jwtPublicKey:l,deploymentMode:n}){return Ne(e,t,s=>me({cf:e.cf,cwd:s,workerName:D,accountId:e.accountId,message:`everyapp ${e.cliVersion} gateway ${e.release.manifest.version} (${e.reason})`,secrets:r,interactive:e.interactive,attach:e.out.verbose,cliCf:!0,out:e.out,step:"gateway.deploy",onUploaded:(i,c)=>rt(e,t,i,c?{liveDomains:a}:o,{jwtPublicKey:l,deploymentMode:n})}))}async function Ne(e,t,a){let{dir:o,cleanup:r}=await q("gateway-deploy-");try{return await Fe.cp(e.release.dir,o,{recursive:!0}),await ve(o,{d1Id:e.resources.d1Id,oauthKvId:e.resources.oauthKvId,release:{version:e.release.manifest.version,sha256:e.release.manifest.sha256},gatewayHost:e.gatewayHost,appBaseDomain:e.appBaseDomain,appWorkers:t.appWorkers,appHosts:T(t.appHosts,e.appBaseDomain)}),await a(o)}finally{await r()}}function rt(e,t,a,o,r){return G(e.db,Pe(e,{liveVersionId:a,liveDomains:o.liveDomains,liveAppWorkers:t.appWorkers,...r}))}function Pe(e,t){return{accountId:e.accountId,zoneId:e.zone.id,zoneName:e.zone.name,gatewayHost:e.gatewayHost,appBaseDomain:e.appBaseDomain,oauthKvId:e.resources.oauthKvId,releaseVersion:e.release.manifest.version,releaseSha256:e.release.manifest.sha256,releaseOrder:e.release.source.order,sourceTreeSha256:e.release.source.treeSha256,releaseOrigin:e.release.source.origin,releaseGitSha:e.release.manifest.gitSha,...t,updatedAt:Date.now(),updatedBy:`everyapp ${e.cliVersion} on ${Ve.hostname()}`}}export{Oe as a,W as b,mt as c,ut as d,B as e,It as f,Ae as g,Ee as h,Ce as i,Se as j,z as k,Ze as l,qe as m,Je as n,Xe as o,ra as p};
|