// @bun
var{defineProperty:V,getOwnPropertyNames:X,getOwnPropertyDescriptor:Y}=Object,Z=Object.prototype.hasOwnProperty;function _(j){return this[j]}var N=(j)=>{var A=(W??=new WeakMap).get(j),H;if(A)return A;if(A=V({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var D of X(j))if(!Z.call(A,D))V(A,D,{get:_.bind(j,D),enumerable:!(H=Y(j,D))||H.enumerable})}return W.set(j,A),A},W;var $=(j)=>j;function w(j,A){this[j]=$.bind(null,A)}var T=(j,A)=>{for(var H in A)V(j,H,{get:A[H],enumerable:!0,configurable:!0,set:w.bind(A,H)})};var U=(j,A)=>()=>(j&&(A=j(j=0)),A);var k=import.meta.require;function S(j){let{token:A,baseUrl:H="https://api.netlify.com/api/v1"}=j;async function D(E,C,J={}){let L=`${H}${C}`,O={Authorization:`Bearer ${A}`,"User-Agent":"stx-deploy/1.0"},M;if(J.rawBody)O["Content-Type"]=J.contentType||"application/octet-stream",M=J.rawBody;else if(J.body)O["Content-Type"]="application/json",M=JSON.stringify(J.body);let F=await fetch(L,{method:E,headers:O,body:M});if(!F.ok){let Q=Error(`Netlify API error: ${F.status} ${F.statusText}`);Q.status=F.status;try{let R=await F.json();Q.message=R.message||Q.message,Q.code=R.code,Q.details=R}catch{}throw Q}let K=await F.text();if(!K)return{};return JSON.parse(K)}return{async getSite(E){return D("GET",`/sites/${E}`)},async listSites(){return D("GET","/sites")},async createSite(E){let C={};if(E)C.name=E;return D("POST","/sites",{body:C})},async createDeploy(E,C){let J={files:C.files,draft:C.draft??!0,async:C.async??!0};if(C.title)J.title=C.title;if(C.branch)J.branch=C.branch;if(C.functions)J.functions=C.functions;return D("POST",`/sites/${E}/deploys`,{body:J})},async uploadFile(E,C,J){let L=C.startsWith("/")?C.slice(1):C;await D("PUT",`/deploys/${E}/files/${L}`,{rawBody:J,contentType:"application/octet-stream"})},async uploadFiles(E,C){let L=[...C],O=async()=>{while(L.length>0){let F=L.shift();if(F)await this.uploadFile(E,F.path,F.content)}},M=Array.from({length:Math.min(5,C.length)},()=>O());await Promise.all(M)},async getDeploy(E){return D("GET",`/deploys/${E}`)},async waitForDeploy(E,C={}){let{timeout:J=300000,pollInterval:L=2000,onProgress:O}=C,M=Date.now();while(!0){let F=await this.getDeploy(E);if(O)O(F);if(F.state==="ready")return F;if(F.state==="error"){let K=Error(`Deploy failed: ${F.error_message||"Unknown error"}`);throw K.status=500,K.details=F,K}if(Date.now()-M>J){let K=Error(`Deploy timed out after ${J}ms`);throw K.status=408,K.details=F,K}await new Promise((K)=>setTimeout(K,L))}},async lockDeploy(E){return D("POST",`/deploys/${E}/lock`)},async unlockDeploy(E){return D("POST",`/deploys/${E}/unlock`)}}}async function G(j){let A=await crypto.subtle.digest("SHA-1",j);return Array.from(new Uint8Array(A)).map((D)=>D.toString(16).padStart(2,"0")).join("")}async function x(j,A={}){let{ignore:H=["node_modules",".git",".env*","*.map"]}=A,D=[],E=new Bun.Glob("**/*");for await(let C of E.scan({cwd:j,onlyFiles:!0,dot:!1})){if(H.some((K)=>{if(K.includes("*"))return new RegExp(`^${K.replace(/\*/g,".*")}$`).test(C);return C.includes(K)}))continue;let L=`${j}/${C}`,M=await Bun.file(L).arrayBuffer(),F=await G(M);D.push({path:C,content:new Uint8Array(M),sha1:F})}return D}function g(j){let A={};for(let H of j)A[`/${H.path}`]=H.sha1;return A}function v(j,A){let H=new Set(A.map((D)=>D.startsWith("/")?D.slice(1):D));return j.filter((D)=>H.has(D.path))}function P(j){if(j<1024)return`${j} B`;if(j<1048576)return`${(j/1024).toFixed(1)} KB`;if(j<1073741824)return`${(j/1048576).toFixed(1)} MB`;return`${(j/1073741824).toFixed(1)} GB`}function q(j){return j.reduce((A,H)=>A+H.content.byteLength,0)}export{q as getTotalSize,P as formatSize,v as filterRequiredFiles,S as createNetlifyClient,g as createFileManifest,x as collectDeployFiles,G as calculateSha1};
