@stacksjs/actions 0.70.25 → 0.70.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Ba as t,Ca as r,Da as o,ya as l,za as d}from"../../chunk-kzhgexj4.js";import{gb as U}from"../../chunk-96b7fcmd.js";import V from"process";import{existsSync as p,readFileSync as _E,writeFileSync as a}from"fs";import{bold as J,cyan as g,dim as H,green as f}from"@stacksjs/cli";import{projectPath as I,storagePath as S}from"@stacksjs/path";var c=V.argv.indexOf("--verbose"),A=c!==-1&&V.argv[c+1]!=="false",$E=Bun.nanoseconds(),s=console.log,zE=console.warn,h=[];console.log=(...X)=>{h.push(X.map(String).join(" "))};console.warn=(...X)=>{h.push(X.map(String).join(" "))};var q=S("framework/defaults/views/dashboard"),GE=I("resources/views/dashboard"),y=Number(V.env.PORT_ADMIN)||3002,R=await t(y),P=V.env.APP_URL||"",NE=P!==""&&P!=="localhost"&&!P.includes("localhost:"),n=NE?P.replace(/^https?:\/\//,""):null,C=n?`dashboard.${n}`:null,e=`${V.env.HOME}/.stacks/ssl`;function EE(){console.log=s,console.warn=(...X)=>{let G=X.map(String).join(" ");if(G.includes("[STX] DOM API violation")||G.includes("unsafe expression"))return;zE(...X)}}function F(X,G={}){let Y=new Headers(G.headers);return Y.set("content-type","application/json; charset=utf-8"),Y.set("cache-control","no-store"),new Response(JSON.stringify(X),{...G,headers:Y})}function OE(X){return X.trim().toLowerCase().replace(/['"]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}async function L(X){if(X.method==="GET"||X.method==="HEAD")return{};let G=X.headers.get("content-type")||"";if(G.includes("application/json"))return await X.json().catch(()=>({}));if(G.includes("form")){let Y=await X.formData();return Object.fromEntries(Y.entries())}return{}}var WE={posts:["title","poster","content","excerpt","views","published_at","status","is_featured","author_id","created_at","updated_at"],pages:["title","template","views","published_at","conversions","author_id","created_at","updated_at"],authors:["name","email","user_id","created_at","updated_at"],categories:["name","description","slug","image_url","is_active","parent_category_id","display_order","created_at","updated_at"],tags:["name","slug","description","post_count","color","created_at","updated_at"],comments:["title","body","content","status","author_name","author_email","post_title","is_approved","approved_at","rejected_at","updated_at"]};function b(){let X=V.env.DB_DATABASE_PATH||"database/stacks.sqlite";return X.startsWith("/")?X:I(X)}function D(X){if(!/^[a-z_][a-z0-9_]*$/i.test(X))throw Error(`Invalid CMS database identifier: ${X}`);return`"${X.replace(/"/g,'""')}"`}function i(X,G){let Y=WE[X];if(!Y)throw Error(`Unsupported CMS table: ${X}`);return Object.fromEntries(Object.entries(G).filter(([$,N])=>Y.includes($)&&N!==void 0))}async function KE(){if((V.env.DB_CONNECTION||"sqlite")!=="sqlite"||!p(b()))return;let{Database:X}=await import("bun:sqlite"),G=new X(b());async function Y($,N){return G.query(`select * from ${D($)} where id = ? limit 1`).get(N)}return{async all($,N="created_at"){return G.query(`select * from ${D($)} order by ${D(N)} desc`).all()},async insert($,N){let O=i($,N),W=Object.keys(O),K=W.map(()=>"?").join(", "),Z=`insert into ${D($)} (${W.map(D).join(", ")}) values (${K})`,E=G.query(Z).run(...W.map((_)=>O[_]));return await Y($,Number(E.lastInsertRowid))},async update($,N,O){let W=i($,O),K=Object.keys(W);if(K.length){let Z=K.map((E)=>`${D(E)} = ?`).join(", ");G.query(`update ${D($)} set ${Z} where id = ?`).run(...K.map((E)=>W[E]),N)}return await Y($,N)},async delete($,N){G.query(`delete from ${D($)} where id = ?`).run(N)},find:Y,close(){G.close()}}}async function HE(){let X=await KE();if(X)return X;let{db:G}=await import("@stacksjs/database");return{async all(Y,$="created_at"){let N=G.selectFrom(Y).selectAll();if($)N=N.orderBy($,"desc");return await N.execute()},async insert(Y,$){let N=await G.insertInto(Y).values($).returningAll().executeTakeFirst();if(!N||N.id==null){let O=$.email?["email",$.email]:$.name?["name",$.name]:["title",$.title];N=await G.selectFrom(Y).selectAll().where(O[0],"=",O[1]).orderBy("id","desc").executeTakeFirst()}return N},async update(Y,$,N){return await G.updateTable(Y).set(N).where("id","=",$).execute(),await G.selectFrom(Y).selectAll().where("id","=",$).executeTakeFirst()},async delete(Y,$){await G.deleteFrom(Y).where("id","=",$).execute()},async find(Y,$){return await G.selectFrom(Y).selectAll().where("id","=",$).executeTakeFirst()}}}async function B(X,G,Y="created_at"){try{return await X.all(G,Y)}catch{return[]}}async function FE(X){let G=new URL(X.url);if(!G.pathname.startsWith("/api/dashboard/cms"))return null;let Y;try{Y=await HE();let N=G.pathname.replace(/^\/api\/dashboard\/cms\/?/,"").split("/").filter(Boolean),O=N[0]||"",W=N[1]?Number(N[1]):void 0,K=new Date().toISOString().slice(0,19).replace("T"," ");if(X.method==="GET"&&!O){let[Z,E,_,z,T,M]=await Promise.all([B(Y,"posts"),B(Y,"pages"),B(Y,"authors"),B(Y,"categories"),B(Y,"tags"),B(Y,"comments")]);return F({ok:!0,posts:Z,pages:E,authors:_,categories:z,tags:T,comments:M,stats:{posts:Z.length,publishedPosts:Z.filter((j)=>j.status==="published").length,draftPosts:Z.filter((j)=>j.status==="draft").length,pages:E.length,categories:z.length,tags:T.length,comments:M.length}})}if(O==="posts"){if(X.method==="POST"){let Z=await L(X),E=String(Z.title||"").trim();if(!E)return F({ok:!1,error:"Title is required"},{status:422});let _=await Y.insert("posts",{title:E,poster:String(Z.poster||""),content:String(Z.content||Z.body||""),excerpt:String(Z.excerpt||""),views:Number(Z.views||0),published_at:Z.status==="published"?K:Z.published_at||null,status:String(Z.status||"draft").toLowerCase(),is_featured:Z.is_featured?1:0,author_id:Z.author_id?Number(Z.author_id):null,created_at:K,updated_at:K});return F({ok:!0,post:_},{status:201})}if(X.method==="PATCH"&&W){let Z=await L(X),E={updated_at:K};for(let z of["title","poster","content","excerpt","status","published_at"])if(Z[z]!==void 0)E[z]=z==="status"?String(Z[z]).toLowerCase():Z[z];if(Z.views!==void 0)E.views=Number(Z.views);if(Z.is_featured!==void 0)E.is_featured=Z.is_featured?1:0;let _=await Y.update("posts",W,E);if(!_)return F({ok:!1,error:"Post not found"},{status:404});return F({ok:!0,post:_})}if(X.method==="DELETE"&&W)return await Y.delete("posts",W),F({ok:!0})}if(O==="tags"||O==="categories"){let Z=O;if(X.method==="POST"){let E=await L(X),_=String(E.name||"").trim();if(!_)return F({ok:!1,error:"Name is required"},{status:422});let z={name:_,slug:String(E.slug||OE(_)),description:String(E.description||""),created_at:K,updated_at:K};if(O==="categories")z.is_active=E.is_active===void 0?!0:Boolean(E.is_active);if(O==="tags")z.post_count=Number(E.post_count||0),z.color=String(E.color||"");let T=await Y.insert(Z,z);return F({ok:!0,[O==="categories"?"category":"tag"]:T},{status:201})}if(X.method==="PATCH"&&W){let E=await L(X),_={updated_at:K};for(let T of["name","slug","description","color","image_url","parent_category_id"])if(E[T]!==void 0)_[T]=E[T];if(E.post_count!==void 0)_.post_count=Number(E.post_count);if(E.display_order!==void 0)_.display_order=Number(E.display_order);if(E.is_active!==void 0)_.is_active=E.is_active?1:0;let z=await Y.update(Z,W,_);if(!z)return F({ok:!1,error:`${O==="categories"?"Category":"Tag"} not found`},{status:404});return F({ok:!0,[O==="categories"?"category":"tag"]:z})}if(X.method==="DELETE"&&W)return await Y.delete(Z,W),F({ok:!0})}if(O==="pages"){if(X.method==="POST"){let Z=await L(X),E=String(Z.title||"").trim();if(!E)return F({ok:!1,error:"Title is required"},{status:422});let _=await Y.insert("pages",{title:E,template:String(Z.template||"default"),views:0,conversions:0,published_at:Z.status==="published"?K:null,author_id:Z.author_id?Number(Z.author_id):null,created_at:K,updated_at:K});return F({ok:!0,page:_},{status:201})}if(X.method==="PATCH"&&W){let Z=await L(X),E={updated_at:K};for(let z of["title","template","published_at"])if(Z[z]!==void 0)E[z]=Z[z];if(Z.views!==void 0)E.views=Number(Z.views);if(Z.conversions!==void 0)E.conversions=Number(Z.conversions);if(Z.author_id!==void 0)E.author_id=Z.author_id?Number(Z.author_id):null;let _=await Y.update("pages",W,E);if(!_)return F({ok:!1,error:"Page not found"},{status:404});return F({ok:!0,page:_})}if(X.method==="DELETE"&&W)return await Y.delete("pages",W),F({ok:!0})}if(O==="authors"){if(X.method==="POST"){let Z=await L(X),E=String(Z.name||"").trim(),_=String(Z.email||"").trim();if(!E||!_)return F({ok:!1,error:"Name and email are required"},{status:422});let z=await Y.insert("authors",{name:E,email:_,created_at:K,updated_at:K});return F({ok:!0,author:z},{status:201})}if(X.method==="PATCH"&&W){let Z=await L(X),E={updated_at:K};for(let z of["name","email"])if(Z[z]!==void 0)E[z]=Z[z];if(Z.user_id!==void 0)E.user_id=Z.user_id?Number(Z.user_id):null;let _=await Y.update("authors",W,E);if(!_)return F({ok:!1,error:"Author not found"},{status:404});return F({ok:!0,author:_})}if(X.method==="DELETE"&&W)return await Y.delete("authors",W),F({ok:!0})}if(O==="comments"){if(X.method==="PATCH"&&W){let Z=await L(X),E={updated_at:K};if(Z.content!==void 0)E.content=Z.content,E.body=Z.content;if(Z.body!==void 0)E.content=Z.body,E.body=Z.body;for(let z of["status","author_name","author_email","post_title"])if(Z[z]!==void 0)E[z]=Z[z];if(E.status==="approved")E.is_approved=1;if(E.status&&E.status!=="approved")E.is_approved=0;let _=await Y.update("comments",W,E);if(!_)return F({ok:!1,error:"Comment not found"},{status:404});return F({ok:!0,comment:_})}if(X.method==="DELETE"&&W)return await Y.delete("comments",W),F({ok:!0})}return F({ok:!1,error:"CMS endpoint not found"},{status:404})}catch($){return F({ok:!1,error:$?.message||String($)},{status:500})}finally{Y?.close?.()}}async function TE(){try{await import("@stacksjs/orm")}catch(E){if(A)console.warn("[dashboard] orm preload failed:",E?.message||E)}try{let{hoistDashboardGlobals:E}=await import("./dashboard-globals.js");await E({verbose:A})}catch(E){if(A)console.warn("[dashboard] globals preload failed:",E?.message||E)}let X;try{X=(await import("../../chunk-wv5yb5wb.js")).serve}catch{X=(await import(I("pantry/bun-plugin-stx/dist/serve.js"))).serve}let G;try{let E=I("pantry/@stacksjs/stx/dist/index.js");if(await Bun.file(E).exists())G=await import(E)}catch{}let{listConfigFiles:Y,readConfig:$,updateConfigKey:N}=await import(S("framework/defaults/resources/functions/dashboard/config-io.ts")),O={"/__deps/charts.js":S("framework/core/charts/dist/index.js")},W={...Object.fromEntries(Object.entries(O).map(([E,_])=>[E,async()=>{let z=Bun.file(_);if(!await z.exists())return new Response(`// dependency dist missing: ${_}
|
|
3
|
-
// rebuild with: cd ${
|
|
2
|
+
import{Ba as t,Ca as r,Da as o,ya as l,za as d}from"../../chunk-kzhgexj4.js";import{gb as U}from"../../chunk-96b7fcmd.js";import V from"process";import{existsSync as p,readFileSync as $E,writeFileSync as a}from"fs";import{bold as J,cyan as g,dim as _,green as f}from"@stacksjs/cli";import{projectPath as I,storagePath as S}from"@stacksjs/path";var c=V.argv.indexOf("--verbose"),A=c!==-1&&V.argv[c+1]!=="false",zE=Bun.nanoseconds(),s=console.log,GE=console.warn,h=[];console.log=(...X)=>{h.push(X.map(String).join(" "))};console.warn=(...X)=>{h.push(X.map(String).join(" "))};var q=S("framework/defaults/views/dashboard"),NE=I("resources/views/dashboard"),y=Number(V.env.PORT_ADMIN)||3002,R=await t(y),P=V.env.APP_URL||"",OE=P!==""&&P!=="localhost"&&!P.includes("localhost:"),n=OE?P.replace(/^https?:\/\//,""):null,C=n?`dashboard.${n}`:null,e=`${V.env.HOME}/.stacks/ssl`;function EE(){console.log=s,console.warn=(...X)=>{let N=X.map(String).join(" ");if(N.includes("[STX] DOM API violation")||N.includes("unsafe expression"))return;GE(...X)}}function F(X,N={}){let Y=new Headers(N.headers);return Y.set("content-type","application/json; charset=utf-8"),Y.set("cache-control","no-store"),new Response(JSON.stringify(X),{...N,headers:Y})}function WE(X){return X.trim().toLowerCase().replace(/['"]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}async function L(X){if(X.method==="GET"||X.method==="HEAD")return{};let N=X.headers.get("content-type")||"";if(N.includes("application/json"))return await X.json().catch(()=>({}));if(N.includes("form")){let Y=await X.formData();return Object.fromEntries(Y.entries())}return{}}var KE={posts:["title","poster","content","excerpt","views","published_at","status","is_featured","author_id","created_at","updated_at"],pages:["title","template","views","published_at","conversions","author_id","created_at","updated_at"],authors:["name","email","user_id","created_at","updated_at"],categories:["name","description","slug","image_url","is_active","parent_category_id","display_order","created_at","updated_at"],tags:["name","slug","description","post_count","color","created_at","updated_at"],comments:["title","body","content","status","author_name","author_email","post_title","is_approved","approved_at","rejected_at","updated_at"]};function b(){let X=V.env.DB_DATABASE_PATH||"database/stacks.sqlite";return X.startsWith("/")?X:I(X)}function D(X){if(!/^[a-z_][a-z0-9_]*$/i.test(X))throw Error(`Invalid CMS database identifier: ${X}`);return`"${X.replace(/"/g,'""')}"`}function i(X,N){let Y=KE[X];if(!Y)throw Error(`Unsupported CMS table: ${X}`);return Object.fromEntries(Object.entries(N).filter(([z,O])=>Y.includes(z)&&O!==void 0))}async function HE(){if((V.env.DB_CONNECTION||"sqlite")!=="sqlite"||!p(b()))return;let{Database:X}=await import("bun:sqlite"),N=new X(b());async function Y(z,O){return N.query(`select * from ${D(z)} where id = ? limit 1`).get(O)}return{async all(z,O="created_at"){return N.query(`select * from ${D(z)} order by ${D(O)} desc`).all()},async insert(z,O){let W=i(z,O),K=Object.keys(W),H=K.map(()=>"?").join(", "),Z=`insert into ${D(z)} (${K.map(D).join(", ")}) values (${H})`,E=N.query(Z).run(...K.map(($)=>W[$]));return await Y(z,Number(E.lastInsertRowid))},async update(z,O,W){let K=i(z,W),H=Object.keys(K);if(H.length){let Z=H.map((E)=>`${D(E)} = ?`).join(", ");N.query(`update ${D(z)} set ${Z} where id = ?`).run(...H.map((E)=>K[E]),O)}return await Y(z,O)},async delete(z,O){N.query(`delete from ${D(z)} where id = ?`).run(O)},find:Y,close(){N.close()}}}async function _E(){let X=await HE();if(X)return X;let{db:N}=await import("@stacksjs/database");return{async all(Y,z="created_at"){let O=N.selectFrom(Y).selectAll();if(z)O=O.orderBy(z,"desc");return await O.execute()},async insert(Y,z){let O=await N.insertInto(Y).values(z).returningAll().executeTakeFirst();if(!O||O.id==null){let W=z.email?["email",z.email]:z.name?["name",z.name]:["title",z.title];O=await N.selectFrom(Y).selectAll().where(W[0],"=",W[1]).orderBy("id","desc").executeTakeFirst()}return O},async update(Y,z,O){return await N.updateTable(Y).set(O).where("id","=",z).execute(),await N.selectFrom(Y).selectAll().where("id","=",z).executeTakeFirst()},async delete(Y,z){await N.deleteFrom(Y).where("id","=",z).execute()},async find(Y,z){return await N.selectFrom(Y).selectAll().where("id","=",z).executeTakeFirst()}}}async function B(X,N,Y="created_at"){try{return await X.all(N,Y)}catch{return[]}}async function FE(X){let N=new URL(X.url);if(!N.pathname.startsWith("/api/dashboard/cms"))return null;let Y;try{Y=await _E();let O=N.pathname.replace(/^\/api\/dashboard\/cms\/?/,"").split("/").filter(Boolean),W=O[0]||"",K=O[1]?Number(O[1]):void 0,H=new Date().toISOString().slice(0,19).replace("T"," ");if(X.method==="GET"&&!W){let[Z,E,$,G,T,M]=await Promise.all([B(Y,"posts"),B(Y,"pages"),B(Y,"authors"),B(Y,"categories"),B(Y,"tags"),B(Y,"comments")]);return F({ok:!0,posts:Z,pages:E,authors:$,categories:G,tags:T,comments:M,stats:{posts:Z.length,publishedPosts:Z.filter((j)=>j.status==="published").length,draftPosts:Z.filter((j)=>j.status==="draft").length,pages:E.length,categories:G.length,tags:T.length,comments:M.length}})}if(W==="posts"){if(X.method==="POST"){let Z=await L(X),E=String(Z.title||"").trim();if(!E)return F({ok:!1,error:"Title is required"},{status:422});let $=await Y.insert("posts",{title:E,poster:String(Z.poster||""),content:String(Z.content||Z.body||""),excerpt:String(Z.excerpt||""),views:Number(Z.views||0),published_at:Z.status==="published"?H:Z.published_at||null,status:String(Z.status||"draft").toLowerCase(),is_featured:Z.is_featured?1:0,author_id:Z.author_id?Number(Z.author_id):null,created_at:H,updated_at:H});return F({ok:!0,post:$},{status:201})}if(X.method==="PATCH"&&K){let Z=await L(X),E={updated_at:H};for(let G of["title","poster","content","excerpt","status","published_at"])if(Z[G]!==void 0)E[G]=G==="status"?String(Z[G]).toLowerCase():Z[G];if(Z.views!==void 0)E.views=Number(Z.views);if(Z.is_featured!==void 0)E.is_featured=Z.is_featured?1:0;let $=await Y.update("posts",K,E);if(!$)return F({ok:!1,error:"Post not found"},{status:404});return F({ok:!0,post:$})}if(X.method==="DELETE"&&K)return await Y.delete("posts",K),F({ok:!0})}if(W==="tags"||W==="categories"){let Z=W;if(X.method==="POST"){let E=await L(X),$=String(E.name||"").trim();if(!$)return F({ok:!1,error:"Name is required"},{status:422});let G={name:$,slug:String(E.slug||WE($)),description:String(E.description||""),created_at:H,updated_at:H};if(W==="categories")G.is_active=E.is_active===void 0?!0:Boolean(E.is_active);if(W==="tags")G.post_count=Number(E.post_count||0),G.color=String(E.color||"");let T=await Y.insert(Z,G);return F({ok:!0,[W==="categories"?"category":"tag"]:T},{status:201})}if(X.method==="PATCH"&&K){let E=await L(X),$={updated_at:H};for(let T of["name","slug","description","color","image_url","parent_category_id"])if(E[T]!==void 0)$[T]=E[T];if(E.post_count!==void 0)$.post_count=Number(E.post_count);if(E.display_order!==void 0)$.display_order=Number(E.display_order);if(E.is_active!==void 0)$.is_active=E.is_active?1:0;let G=await Y.update(Z,K,$);if(!G)return F({ok:!1,error:`${W==="categories"?"Category":"Tag"} not found`},{status:404});return F({ok:!0,[W==="categories"?"category":"tag"]:G})}if(X.method==="DELETE"&&K)return await Y.delete(Z,K),F({ok:!0})}if(W==="pages"){if(X.method==="POST"){let Z=await L(X),E=String(Z.title||"").trim();if(!E)return F({ok:!1,error:"Title is required"},{status:422});let $=await Y.insert("pages",{title:E,template:String(Z.template||"default"),views:0,conversions:0,published_at:Z.status==="published"?H:null,author_id:Z.author_id?Number(Z.author_id):null,created_at:H,updated_at:H});return F({ok:!0,page:$},{status:201})}if(X.method==="PATCH"&&K){let Z=await L(X),E={updated_at:H};for(let G of["title","template","published_at"])if(Z[G]!==void 0)E[G]=Z[G];if(Z.views!==void 0)E.views=Number(Z.views);if(Z.conversions!==void 0)E.conversions=Number(Z.conversions);if(Z.author_id!==void 0)E.author_id=Z.author_id?Number(Z.author_id):null;let $=await Y.update("pages",K,E);if(!$)return F({ok:!1,error:"Page not found"},{status:404});return F({ok:!0,page:$})}if(X.method==="DELETE"&&K)return await Y.delete("pages",K),F({ok:!0})}if(W==="authors"){if(X.method==="POST"){let Z=await L(X),E=String(Z.name||"").trim(),$=String(Z.email||"").trim();if(!E||!$)return F({ok:!1,error:"Name and email are required"},{status:422});let G=await Y.insert("authors",{name:E,email:$,created_at:H,updated_at:H});return F({ok:!0,author:G},{status:201})}if(X.method==="PATCH"&&K){let Z=await L(X),E={updated_at:H};for(let G of["name","email"])if(Z[G]!==void 0)E[G]=Z[G];if(Z.user_id!==void 0)E.user_id=Z.user_id?Number(Z.user_id):null;let $=await Y.update("authors",K,E);if(!$)return F({ok:!1,error:"Author not found"},{status:404});return F({ok:!0,author:$})}if(X.method==="DELETE"&&K)return await Y.delete("authors",K),F({ok:!0})}if(W==="comments"){if(X.method==="PATCH"&&K){let Z=await L(X),E={updated_at:H};if(Z.content!==void 0)E.content=Z.content,E.body=Z.content;if(Z.body!==void 0)E.content=Z.body,E.body=Z.body;for(let G of["status","author_name","author_email","post_title"])if(Z[G]!==void 0)E[G]=Z[G];if(E.status==="approved")E.is_approved=1;if(E.status&&E.status!=="approved")E.is_approved=0;let $=await Y.update("comments",K,E);if(!$)return F({ok:!1,error:"Comment not found"},{status:404});return F({ok:!0,comment:$})}if(X.method==="DELETE"&&K)return await Y.delete("comments",K),F({ok:!0})}return F({ok:!1,error:"CMS endpoint not found"},{status:404})}catch(z){return F({ok:!1,error:z?.message||String(z)},{status:500})}finally{Y?.close?.()}}async function TE(){try{await import("@stacksjs/orm")}catch(E){if(A)console.warn("[dashboard] orm preload failed:",E?.message||E)}try{let{hoistDashboardGlobals:E}=await import("./dashboard-globals.js");await E({verbose:A})}catch(E){if(A)console.warn("[dashboard] globals preload failed:",E?.message||E)}let X;try{X=(await import("../../chunk-wv5yb5wb.js")).serve}catch{X=(await import(I("pantry/bun-plugin-stx/dist/serve.js"))).serve}let N;try{let E=I("pantry/@stacksjs/stx/dist/index.js");if(await Bun.file(E).exists())N=await import(E)}catch{}let{listConfigFiles:Y,readConfig:z,updateConfigKey:O}=await import(S("framework/defaults/resources/functions/dashboard/config-io.ts")),W={"/__deps/charts.js":S("framework/core/charts/dist/index.js")},K={...Object.fromEntries(Object.entries(W).map(([E,$])=>[E,async()=>{let G=Bun.file($);if(!await G.exists())return new Response(`// dependency dist missing: ${$}
|
|
3
|
+
// rebuild with: cd ${$.replace(/\/dist\/[^/]+$/,"")} && bun build.ts`,{status:500,headers:{"content-type":"text/javascript; charset=utf-8"}});return new Response(G,{headers:{"content-type":"text/javascript; charset=utf-8","cache-control":"no-cache"}})}])),"/api/config/list":async()=>{try{return Response.json({ok:!0,files:Y()})}catch(E){return Response.json({ok:!1,error:E?.message},{status:500})}},"/api/config/read":async(E)=>{try{let G=new URL(E.url).searchParams.get("name")||"";if(!/^[\w-]+$/.test(G))return Response.json({ok:!1,error:"Invalid config name"},{status:400});let T=await z(G);if(!T)return Response.json({ok:!1,error:"Not found"},{status:404});return Response.json({ok:!0,name:G,fields:T.fields,values:T.values})}catch($){return Response.json({ok:!1,error:$?.message},{status:500})}},"/api/config/source":async(E)=>{try{let G=new URL(E.url).searchParams.get("name")||"";if(!/^[\w-]+$/.test(G))return Response.json({ok:!1,error:"Invalid config name"},{status:400});let T=await z(G);if(!T)return Response.json({ok:!1,error:"Not found"},{status:404});return new Response(T.source,{headers:{"content-type":"text/plain; charset=utf-8"}})}catch($){return Response.json({ok:!1,error:$?.message},{status:500})}},"/api/config/update":async(E)=>{if(E.method!=="POST")return Response.json({ok:!1,error:"Method not allowed"},{status:405});try{let $=await E.json(),G=$.file?.replace(/\.ts$/,"");if(!G||!/^[\w-]+$/.test(G))return Response.json({ok:!1,error:"Invalid file"},{status:400});let T=[];if(Array.isArray($.updates))for(let Q of $.updates){let x=Q.key??Q.path;if(typeof x==="string")T.push({key:x,value:Q.value})}else if($.key)T.push({key:$.key,value:$.value});if(T.length===0)return Response.json({ok:!1,error:"No updates supplied"},{status:400});let M=[];for(let Q of T)try{let x=await O(G,Q.key,H(Q.value));M.push({key:Q.key,ok:!0,newValue:x.newValue})}catch(x){M.push({key:Q.key,ok:!1,error:x?.message})}let j=M.every((Q)=>Q.ok);return Response.json({ok:j,file:G,results:M})}catch($){return Response.json({ok:!1,error:$?.message},{status:500})}}};function H(E){if(typeof E==="boolean"||typeof E==="number")return E;if(E==="true")return!0;if(E==="false")return!1;if(E===""||E==null)return"";if(typeof E==="string"&&/^-?\d+(?:\.\d+)?$/.test(E))return Number(E);return String(E)}X({patterns:[NE,q],port:R,componentsDir:S("framework/defaults/resources/components/Dashboard"),layoutsDir:q,partialsDir:q,quiet:!0,routes:K,onRequest:FE,auth:!1,...N&&{stxModule:N}}).catch((E)=>{EE(),console.error(`
|
|
4
4
|
Failed to start dashboard server: ${E?.message||E}
|
|
5
|
-
`),V.exit(1)})}async function VE(){if(!C)return!1;if(V.env.STACKS_PROXY_MANAGED)return!1;try{let{startProxies:X}=await import("@stacksjs/rpx");return await X({proxies:[{from:`localhost:${R}`,to:C,cleanUrls:!1}],https:{basePath:e,validityDays:825},regenerateUntrustedCerts:!1,verbose:A}),!0}catch(X){if(A)s(` ${
|
|
6
|
-
`),await new Promise(()=>{});let
|
|
7
|
-
`),await new Promise(()=>{})}}else console.log(` ${
|
|
5
|
+
`),V.exit(1)})}async function VE(){if(!C)return!1;if(V.env.STACKS_PROXY_MANAGED)return!1;try{let{startProxies:X}=await import("@stacksjs/rpx");return await X({proxies:[{from:`localhost:${R}`,to:C,cleanUrls:!1}],https:{basePath:e,validityDays:825},regenerateUntrustedCerts:!1,verbose:A}),!0}catch(X){if(A)s(` ${_(`Proxy: ${X}`)}`);return!1}}var QE=R+1;function k(X,N=200,Y={}){return new Response(JSON.stringify(X),{status:N,headers:{"Content-Type":"application/json","Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type",...Y}})}function ME(){Bun.serve({port:QE,fetch:async(X)=>{if(X.method==="OPTIONS")return new Response(null,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}});if(new URL(X.url).pathname==="/api/config/update"&&X.method==="POST")try{let{file:Y,updates:z}=await X.json();if(!Y||Y.includes("..")||!Y.match(/^[\w.-]+\.ts$/))return k({error:"Invalid file name"},400);let O=I(`config/${Y}`),W=$E(O,"utf-8");for(let{path:K,value:H}of z){let E=K.split(".").pop().replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),$=new RegExp(`(${E}\\s*:\\s*)(?:'[^']*'|"[^"]*"|\\d+(?:\\.\\d+)?|true|false)`);if($.test(W)){let G=/^\d+(?:\.\d+)?$/.test(H),T=H==="true"||H==="false",M=H.replace(/'/g,"\\'").replace(/\$/g,"$$$$"),j=G||T?H:`'${M}'`;W=W.replace($,`$1${j}`)}}return a(O,W,"utf-8"),k({success:!0})}catch(Y){return k({error:Y.message},500)}return k({error:"Not found"},404)}})}ME();var[,u]=await Promise.all([TE(),l(I("app/Models"),S("framework/defaults/app/Models"))]);async function LE(){let X={library:!0,content:!0,commerce:!0,marketing:!0,analytics:!0,management:!0,utilities:!0,data:{dashboard:!0,activity:!0,users:!0,teams:!0,subscribers:!0,allModels:!0}};try{let Y=(await import(I("config/dashboard.ts"))).default?.sections??{},z=Y.data??{};return{library:Y.library?.enabled??!0,content:Y.content?.enabled??!0,commerce:Y.commerce?.enabled??!0,marketing:Y.marketing?.enabled??!0,analytics:Y.analytics?.enabled??!0,management:Y.management?.enabled??!0,utilities:Y.utilities?.enabled??!0,data:{dashboard:z.dashboard?.enabled??!0,activity:z.activity?.enabled??!0,users:z.users?.enabled??!0,teams:z.teams?.enabled??!0,subscribers:z.subscribers?.enabled??!0,allModels:z.allModels?.enabled??!0}}}catch{return X}}var XE=await LE(),RE=S("framework/defaults/views/dashboard/.discovered-models.json"),DE={models:d(u),sections:XE};a(RE,JSON.stringify(DE,null,2));var UE=await r(R);EE();var AE=!1;VE().then((X)=>{AE=X}).catch((X)=>{if(A)console.warn("[Dashboard] Reverse proxy failed:",X)});var m=C?`https://${C}`:null,v=`http://localhost:${R}`,IE=v,YE=o(IE,u,XE),ZE=`http://localhost:${R}/?native-sidebar=1`,jE=(Bun.nanoseconds()-zE)/1e6;console.log();console.log(` ${J(g("stacks dashboard"))}`);console.log();if(m)console.log(` ${f("\u279C")} ${J("Local")}: ${g(m)}`),console.log(` ${_("\u279C")} ${_("Origin")}: ${_(v)}`);else console.log(` ${f("\u279C")} ${J("Local")}: ${g(v)}`);console.log(` ${f("\u279C")} ${J("Window")}: ${_("Stacks Dashboard")} ${_("1400\xD7900")}`);console.log(` ${f("\u279C")} ${J("Models")}: ${_(`${u.length} discovered`)}`);if(R!==y)console.log(` ${_("\u279C")} ${_(`Port ${y} in use, using ${R}`)}`);if(!UE)console.log(` ${_("\u26A0")} ${_("Dev server may not be ready yet")}`);console.log();console.log(` ${_(`ready in ${jE.toFixed(0)} ms`)}`);if(A){if(console.log(),console.log(` ${_("\u279C")} ${_("Sidebar")}: ${_(`${YE.sections.length} sections, 240px`)}`),console.log(` ${_("\u279C")} ${_("URL")}: ${_(ZE)}`),C)console.log(` ${_("\u279C")} ${_("SSL")}: ${_(e)}`),console.log(` ${_("\u279C")} ${_("Proxy")}: ${_(`localhost:${R} \u2192 ${C}`)}`);if(h.length>0){console.log();for(let X of h)console.log(` ${_(X)}`)}}console.log();var w=null;try{({createApp:w}=await import("@stacksjs/ts-craft"))}catch{}if(w){let X=I("resources/assets/images/app-icon.png"),N=S("framework/defaults/resources/assets/images/app-icon.png"),Y=await Bun.file(X).exists()?X:await Bun.file(N).exists()?N:void 0,z=(()=>{let W=V.env.CRAFT_BIN;if(W&&p(W))return W;let K=`${V.env.HOME}/Documents/Projects/craft/packages/zig/zig-out/bin/craft`;if(p(K))return K;return})();if(!z)w=null;if(!w)console.log(` ${_("Native window unavailable. Set CRAFT_BIN to a craft binary, or open the URL above in a browser.")}
|
|
6
|
+
`),await new Promise(()=>{});let O=w({url:ZE,quiet:!A,...z&&{craftPath:z},window:{title:"Stacks Dashboard",width:1400,height:900,titlebarHidden:!0,nativeSidebar:!0,sidebarWidth:240,sidebarConfig:YE,...Y&&{icon:Y}}});V.on("SIGINT",()=>{O.close(),V.exit(0)}),V.on("SIGTERM",()=>{O.close(),V.exit(0)});try{await O.show(),V.exit(0)}catch{let W=m||v;console.log(` ${_("Dashboard available at:")} ${g(W)}
|
|
7
|
+
`),await new Promise(()=>{})}}else console.log(` ${_("Native window unavailable. Set CRAFT_BIN to a craft binary, or open the URL above in a browser.")}
|
|
8
8
|
`),V.on("SIGINT",()=>V.exit(0)),V.on("SIGTERM",()=>V.exit(0)),await new Promise(()=>{});
|
package/dist/src/lint/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
1
2
|
// @bun
|
|
2
|
-
import{log as
|
|
3
|
+
import{log as e}from"@stacksjs/cli";import{existsSync as r}from"fs";import{execSync as l,spawnSync as f}from"child_process";e.info("Checking Code Style...");var i=process.cwd(),a=/\.(?:ts|js|json|md|yaml|yml)$/i,g=/(?:^|\/)(?:node_modules|dist|pantry|storage\/framework\/cache|\.git|\.stx|\.stx-serve)(?:\/|$)/;function u(){try{return l("git ls-files -z",{cwd:i,encoding:"utf8"}).split("\x00").filter((t)=>a.test(t)&&!g.test(t))}catch{return[]}}var s=u();if(!s.length)e.success("Linted"),process.exit(0);var d=r(`${i}/pickier.config.ts`)?["--config","pickier.config.ts"]:[],n=120,c=!1;for(let t=0;t<s.length;t+=n){let o=s.slice(t,t+n);if(f("bunx",["--bun","pickier","lint",...o,...d,"--max-warnings","9999"],{cwd:i,stdio:"inherit"}).status!==0)c=!0}if(c)process.exit(1);e.success("Linted");
|
package/dist/src/upgrade.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import"../chunk-96b7fcmd.js";import r from"process";import{intro as b,outro as e,runCommand as d}from"@stacksjs/cli";import{NpmScript as j}from"@stacksjs/enums";import{log as k}from"@stacksjs/logging";import{projectPath as u}from"@stacksjs/path";import*as c from"@stacksjs/storage";import{ExitCode as n}from"@stacksjs/types";var i="0.70.
|
|
2
|
+
import"../chunk-96b7fcmd.js";import r from"process";import{intro as b,outro as e,runCommand as d}from"@stacksjs/cli";import{NpmScript as j}from"@stacksjs/enums";import{log as k}from"@stacksjs/logging";import{projectPath as u}from"@stacksjs/path";import*as c from"@stacksjs/storage";import{ExitCode as n}from"@stacksjs/types";var i="0.70.27";function v(s){try{console.log("checkForUncommittedChanges",s)}catch(t){console.error(t)}}async function f(s){let a=u("updates");if(c.doesFolderExist(a))await c.deleteFolder(a);k.info("Downloading framework updates..."),await d("giget stacks updates",s),k.success(`Your framework updated correctly to version: v${i}`)}async function B(){let s=await b("buddy upgrade:dependencies"),t=await d(j.UpgradeDependencies,{cwd:u()});if(t.isErr)await e("While running the upgrade:dependencies command, there was an issue",{startTime:s,useSeconds:!0},t.error),r.exit(n.FatalError);await e("Freshly updated your dependencies.",{startTime:s,useSeconds:!0}),r.exit(n.Success)}export{B as updateDependencies,f as downloadFrameworkUpdate,v as checkForUncommittedChanges};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/actions",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.70.
|
|
4
|
+
"version": "0.70.27",
|
|
5
5
|
"description": "The Stacks actions.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"contributors": [
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
],
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
|
-
"bun": "./src/index.ts",
|
|
32
31
|
"types": "./dist/index.d.ts",
|
|
32
|
+
"bun": "./src/index.ts",
|
|
33
33
|
"import": "./dist/index.js"
|
|
34
34
|
},
|
|
35
35
|
"./run-action": {
|
|
36
|
-
"bun": "./src/run-action.ts",
|
|
37
36
|
"types": "./dist/run-action.d.ts",
|
|
37
|
+
"bun": "./src/run-action.ts",
|
|
38
38
|
"import": "./dist/run-action.js"
|
|
39
39
|
},
|
|
40
40
|
"./*": {
|