@shipstatic/ship 0.3.14 → 0.3.15

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/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var nt=Object.create;var oe=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var ot=Object.getOwnPropertyNames;var st=Object.getPrototypeOf,rt=Object.prototype.hasOwnProperty;var x=(n,e)=>()=>(n&&(e=n(n=0)),e);var _=(n,e)=>{for(var t in e)oe(n,t,{get:e[t],enumerable:!0})},ie=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ot(e))!rt.call(n,s)&&s!==t&&oe(n,s,{get:()=>e[s],enumerable:!(i=it(e,s))||i.enumerable});return n},p=(n,e,t)=>(ie(n,e,"default"),t&&ie(t,e,"default")),E=(n,e,t)=>(t=n!=null?nt(st(n)):{},ie(e||!n||!n.__esModule?oe(t,"default",{value:n,enumerable:!0}):t,n)),at=n=>ie(oe({},"__esModule",{value:!0}),n);var ze={};_(ze,{__setTestEnvironment:()=>G,getENV:()=>g});function G(n){De=n}function lt(){return typeof process<"u"&&process.versions&&process.versions.node?"node":typeof window<"u"||typeof self<"u"?"browser":"unknown"}function g(){return De||lt()}var De,C=x(()=>{"use strict";De=null});function B(n){Fe=n}function A(){if(Fe===null)throw _e.ShipError.config("Platform configuration not initialized. The SDK must fetch configuration from the API before performing operations.");return Fe}var _e,Fe,M=x(()=>{"use strict";_e=require("@shipstatic/types"),Fe=null});var Ue={};_(Ue,{loadConfig:()=>K});function Be(n){try{return ut.parse(n)}catch(e){if(e instanceof U.z.ZodError){let t=e.issues[0],i=t.path.length>0?` at ${t.path.join(".")}`:"";throw le.ShipError.config(`Configuration validation failed${i}: ${t.message}`)}throw le.ShipError.config("Configuration validation failed")}}async function dt(n){try{if(g()!=="node")return{};let{cosmiconfigSync:e}=await import("cosmiconfig"),t=await import("os"),i=e(Ee,{searchPlaces:[`.${Ee}rc`,"package.json",`${t.homedir()}/.${Ee}rc`],stopDir:t.homedir()}),s;if(n?s=i.load(n):s=i.search(),s&&s.config)return Be(s.config)}catch(e){if(e instanceof le.ShipError)throw e}return{}}async function K(n){if(g()!=="node")return{};let e={apiUrl:process.env.SHIP_API_URL,apiKey:process.env.SHIP_API_KEY,deployToken:process.env.SHIP_DEPLOY_TOKEN},t=await dt(n),i={apiUrl:e.apiUrl??t.apiUrl,apiKey:e.apiKey??t.apiKey,deployToken:e.deployToken??t.deployToken};return Be(i)}var U,le,Ee,ut,pe=x(()=>{"use strict";U=require("zod"),le=require("@shipstatic/types");C();Ee="ship",ut=U.z.object({apiUrl:U.z.string().url().optional(),apiKey:U.z.string().optional(),deployToken:U.z.string().optional()}).strict()});async function yt(n){let e=(await import("spark-md5")).default;return new Promise((t,i)=>{let o=Math.ceil(n.size/2097152),r=0,a=new e.ArrayBuffer,d=new FileReader,c=()=>{let w=r*2097152,l=Math.min(w+2097152,n.size);d.readAsArrayBuffer(n.slice(w,l))};d.onload=w=>{let l=w.target?.result;if(!l){i(N.ShipError.business("Failed to read file chunk"));return}a.append(l),r++,r<o?c():t({md5:a.end()})},d.onerror=()=>{i(N.ShipError.business("Failed to calculate MD5: FileReader error"))},c()})}async function gt(n){let e=await import("crypto");if(Buffer.isBuffer(n)){let i=e.createHash("md5");return i.update(n),{md5:i.digest("hex")}}let t=await import("fs");return new Promise((i,s)=>{let o=e.createHash("md5"),r=t.createReadStream(n);r.on("error",a=>s(N.ShipError.business(`Failed to read file for MD5: ${a.message}`))),r.on("data",a=>o.update(a)),r.on("end",()=>i({md5:o.digest("hex")}))})}async function k(n){let e=g();if(e==="browser"){if(!(n instanceof Blob))throw N.ShipError.business("Invalid input for browser MD5 calculation: Expected Blob or File.");return yt(n)}if(e==="node"){if(!(Buffer.isBuffer(n)||typeof n=="string"))throw N.ShipError.business("Invalid input for Node.js MD5 calculation: Expected Buffer or file path string.");return gt(n)}throw N.ShipError.business("Unknown or unsupported execution environment for MD5 calculation.")}var N,J=x(()=>{"use strict";C();N=require("@shipstatic/types")});function z(n){return!n||n.length===0?[]:n.filter(e=>{if(!e)return!1;let t=e.replace(/\\/g,"/").split("/").filter(Boolean);if(t.length===0)return!0;let i=t[t.length-1];if((0,He.isJunk)(i))return!1;let s=t.slice(0,-1);for(let o of s)if(fe.some(r=>o.toLowerCase()===r.toLowerCase()))return!1;return!0})}var He,fe,me=x(()=>{"use strict";He=require("junk"),fe=["__MACOSX",".Trashes",".fseventsd",".Spotlight-V100"]});function je(n){if(!n||n.length===0)return"";let e=n.filter(o=>o&&typeof o=="string").map(o=>o.replace(/\\/g,"/"));if(e.length===0)return"";if(e.length===1)return e[0];let t=e.map(o=>o.split("/").filter(Boolean)),i=[],s=Math.min(...t.map(o=>o.length));for(let o=0;o<s;o++){let r=t[0][o];if(t.every(a=>a[o]===r))i.push(r);else break}return i.join("/")}function ue(n){return n.replace(/\\/g,"/").replace(/\/+/g,"/").replace(/^\/+/,"")}var xe=x(()=>{"use strict"});function L(n,e={}){if(e.flatten===!1)return n.map(i=>({path:ue(i),name:Re(i)}));let t=wt(n);return n.map(i=>{let s=ue(i);if(t){let o=t.endsWith("/")?t:`${t}/`;s.startsWith(o)&&(s=s.substring(o.length))}return s||(s=Re(i)),{path:s,name:Re(i)}})}function wt(n){if(!n.length)return"";let t=n.map(o=>ue(o)).map(o=>o.split("/")),i=[],s=Math.min(...t.map(o=>o.length));for(let o=0;o<s-1;o++){let r=t[0][o];if(t.every(a=>a[o]===r))i.push(r);else break}return i.join("/")}function Re(n){return n.split(/[/\\]/).pop()||n}var de=x(()=>{"use strict";xe()});function Ve(n,e=new Set){let t=[],i=T.realpathSync(n);if(e.has(i))return t;e.add(i);let s=T.readdirSync(n);for(let o of s){let r=S.join(n,o),a=T.statSync(r);if(a.isDirectory()){let d=Ve(r,e);t.push(...d)}else a.isFile()&&t.push(r)}return t}async function ee(n,e={}){if(g()!=="node")throw I.ShipError.business("processFilesForNode can only be called in Node.js environment.");let t=n.flatMap(m=>{let u=S.resolve(m);try{return T.statSync(u).isDirectory()?Ve(u):[u]}catch{throw I.ShipError.file(`Path does not exist: ${m}`,m)}}),i=[...new Set(t)],s=z(i);if(s.length===0)return[];let o=n.map(m=>S.resolve(m)),r=je(o.map(m=>{try{return T.statSync(m).isDirectory()?m:S.dirname(m)}catch{return S.dirname(m)}})),a=s.map(m=>{if(r&&r.length>0){let u=S.relative(r,m);if(u&&typeof u=="string"&&!u.startsWith(".."))return u.replace(/\\/g,"/")}return S.basename(m)}),d=L(a,{flatten:e.pathDetect!==!1}),c=[],w=0,l=A();for(let m=0;m<s.length;m++){let u=s[m],P=d[m].path;try{let R=T.statSync(u);if(R.size===0){console.warn(`Skipping empty file: ${u}`);continue}if(R.size>l.maxFileSize)throw I.ShipError.business(`File ${u} is too large. Maximum allowed size is ${l.maxFileSize/(1024*1024)}MB.`);if(w+=R.size,w>l.maxTotalSize)throw I.ShipError.business(`Total deploy size is too large. Maximum allowed is ${l.maxTotalSize/(1024*1024)}MB.`);let V=T.readFileSync(u),{md5:tt}=await k(V);if(P.includes("\0")||P.includes("/../")||P.startsWith("../")||P.endsWith("/.."))throw I.ShipError.business(`Security error: Unsafe file path "${P}" for file: ${u}`);c.push({path:P,content:V,size:V.length,md5:tt})}catch(R){if(R instanceof I.ShipError)throw R;let V=R instanceof Error?R.message:String(R);throw I.ShipError.file(`Failed to read file "${u}": ${V}`,u)}}if(c.length>l.maxFilesCount)throw I.ShipError.business(`Too many files to deploy. Maximum allowed is ${l.maxFilesCount} files.`);return c}var I,T,S,$e=x(()=>{"use strict";C();J();me();I=require("@shipstatic/types");M();de();xe();T=E(require("fs"),1),S=E(require("path"),1)});async function Ge(n,e={}){let{getENV:t}=await Promise.resolve().then(()=>(C(),ze));if(t()!=="browser")throw Oe.ShipError.business("processFilesForBrowser can only be called in a browser environment.");let i=n,s=i.map(l=>l.webkitRelativePath||l.name),o=L(s,{flatten:e.pathDetect!==!1}),r=[];for(let l=0;l<i.length;l++){let m=i[l],u=o[l].path;if(u.includes("..")||u.includes("\0"))throw Oe.ShipError.business(`Security error: Unsafe file path "${u}" for file: ${m.name}`);r.push({file:m,relativePath:u})}let a=r.map(l=>l.relativePath),d=z(a),c=new Set(d),w=[];for(let l of r){if(!c.has(l.relativePath))continue;let{md5:m}=await k(l.file);w.push({content:l.file,path:l.relativePath,size:l.file.size,md5:m})}return w}var Oe,We=x(()=>{"use strict";J();Oe=require("@shipstatic/types");me();de()});var Ze={};_(Ze,{convertBrowserInput:()=>Qe,convertDeployInput:()=>Ct,convertNodeInput:()=>Me});function Je(n,e={}){let t=A();if(!e.skipEmptyCheck&&n.length===0)throw F.ShipError.business("No files to deploy.");if(n.length>t.maxFilesCount)throw F.ShipError.business(`Too many files to deploy. Maximum allowed is ${t.maxFilesCount}.`);let i=0;for(let s of n){if(s.size>t.maxFileSize)throw F.ShipError.business(`File ${s.name} is too large. Maximum allowed size is ${t.maxFileSize/(1024*1024)}MB.`);if(i+=s.size,i>t.maxTotalSize)throw F.ShipError.business(`Total deploy size is too large. Maximum allowed is ${t.maxTotalSize/(1024*1024)}MB.`)}}function Ye(n,e){if(e==="node"){if(!Array.isArray(n))throw F.ShipError.business("Invalid input type for Node.js environment. Expected string[] file paths.");if(n.length===0)throw F.ShipError.business("No files to deploy.");if(!n.every(t=>typeof t=="string"))throw F.ShipError.business("Invalid input type for Node.js environment. Expected string[] file paths.")}}function Xe(n){let e=n.map(t=>({name:t.path,size:t.size}));return Je(e,{skipEmptyCheck:!0}),n.forEach(t=>{t.path&&(t.path=t.path.replace(/\\/g,"/"))}),n}async function Me(n,e={}){Ye(n,"node");let t=await ee(n,e);return Xe(t)}async function Qe(n,e={}){Ye(n,"browser");let t;if(Array.isArray(n)){if(n.length>0&&typeof n[0]=="string")throw F.ShipError.business("Invalid input type for browser environment. Expected File[].");t=n}else throw F.ShipError.business("Invalid input type for browser environment. Expected File[].");t=t.filter(s=>s.size===0?(console.warn(`Skipping empty file: ${s.name}`),!1):!0),Je(t);let i=await Ge(t,e);return Xe(i)}async function Ct(n,e={},t){let i=g();if(i!=="node"&&i!=="browser")throw F.ShipError.business("Unsupported execution environment.");let s;if(i==="node")if(typeof n=="string")s=await Me([n],e);else if(Array.isArray(n)&&n.every(o=>typeof o=="string"))s=await Me(n,e);else throw F.ShipError.business("Invalid input type for Node.js environment. Expected string[] file paths.");else s=await Qe(n,e);return s}var F,et=x(()=>{"use strict";F=require("@shipstatic/types");C();$e();We();M()});var ne={};_(ne,{ApiHttp:()=>b,DEFAULT_API:()=>ce.DEFAULT_API,ErrorType:()=>O.ErrorType,FILE_VALIDATION_STATUS:()=>h.FileValidationStatus,JUNK_DIRECTORIES:()=>fe,Ship:()=>te,ShipError:()=>O.ShipError,__setTestEnvironment:()=>G,allValidFilesReady:()=>ke,calculateMD5:()=>k,createAccountResource:()=>Q,createDeploymentResource:()=>Y,createDomainResource:()=>X,createTokenResource:()=>Z,default:()=>Ne,ensureShipError:()=>Ie,filterJunk:()=>z,formatFileSize:()=>j,getCurrentConfig:()=>A,getENV:()=>g,getValidFiles:()=>he,loadConfig:()=>K,mergeDeployOptions:()=>W,optimizeDeployPaths:()=>L,pluralize:()=>Pe,processFilesForNode:()=>ee,resolveConfig:()=>q,setConfig:()=>B,setPlatformConfig:()=>B,validateFiles:()=>Ae});module.exports=at(ne);var y={};_(y,{ApiHttp:()=>b,DEFAULT_API:()=>ce.DEFAULT_API,ErrorType:()=>O.ErrorType,FILE_VALIDATION_STATUS:()=>h.FileValidationStatus,JUNK_DIRECTORIES:()=>fe,Ship:()=>te,ShipError:()=>O.ShipError,__setTestEnvironment:()=>G,allValidFilesReady:()=>ke,calculateMD5:()=>k,createAccountResource:()=>Q,createDeploymentResource:()=>Y,createDomainResource:()=>X,createTokenResource:()=>Z,default:()=>Ne,ensureShipError:()=>Ie,filterJunk:()=>z,formatFileSize:()=>j,getCurrentConfig:()=>A,getENV:()=>g,getValidFiles:()=>he,loadConfig:()=>K,mergeDeployOptions:()=>W,optimizeDeployPaths:()=>L,pluralize:()=>Pe,processFilesForNode:()=>ee,resolveConfig:()=>q,setConfig:()=>B,setPlatformConfig:()=>B,validateFiles:()=>Ae});var ve=E(require("mime-db"),1),we={};for(let n in ve.default){let e=ve.default[n];e&&e.extensions&&e.extensions.forEach(t=>{we[t]||(we[t]=n)})}function se(n){let e=n.includes(".")?n.substring(n.lastIndexOf(".")+1).toLowerCase():"";return we[e]||"application/octet-stream"}var D=require("@shipstatic/types");var re=class{constructor(){this.handlers=new Map}on(e,t){this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t)}off(e,t){let i=this.handlers.get(e);i&&(i.delete(t),i.size===0&&this.handlers.delete(e))}emit(e,...t){let i=this.handlers.get(e);if(!i)return;let s=Array.from(i);for(let o of s)try{o(...t)}catch(r){i.delete(o),e!=="error"&&setTimeout(()=>{r instanceof Error?this.emit("error",r,String(e)):this.emit("error",new Error(String(r)),String(e))},0)}}transfer(e){this.handlers.forEach((t,i)=>{t.forEach(s=>{e.on(i,s)})})}clear(){this.handlers.clear()}};C();var ae="/deployments",Le="/ping",$="/domains",pt="/config",ct="/account",Se="/tokens",ft="/spa-check",mt=3e4,b=class extends re{constructor(e){super(),this.apiUrl=e.apiUrl||D.DEFAULT_API,this.getAuthHeadersCallback=e.getAuthHeaders,this.timeout=e.timeout??mt}transferEventsTo(e){this.transfer(e)}async request(e,t={},i){let s=this.getAuthHeaders(t.headers),o=new AbortController,r=setTimeout(()=>o.abort(),this.timeout),a=t.signal?this.combineSignals(t.signal,o.signal):o.signal,d={...t,headers:s,credentials:s.Authorization?void 0:"include",signal:a};this.emit("request",e,d);try{let c=await fetch(e,d);clearTimeout(r),c.ok||await this.handleResponseError(c,i);let w=this.safeClone(c),l=this.safeClone(c);return this.emit("response",w,e),await this.parseResponse(l)}catch(c){throw clearTimeout(r),this.emit("error",c,e),this.handleFetchError(c,i),c}}combineSignals(e,t){let i=new AbortController,s=()=>i.abort();return e.addEventListener("abort",s),t.addEventListener("abort",s),(e.aborted||t.aborted)&&i.abort(),i.signal}async requestWithStatus(e,t={},i){let s=this.getAuthHeaders(t.headers),o=new AbortController,r=setTimeout(()=>o.abort(),this.timeout),a=t.signal?this.combineSignals(t.signal,o.signal):o.signal,d={...t,headers:s,credentials:s.Authorization?void 0:"include",signal:a};this.emit("request",e,d);try{let c=await fetch(e,d);clearTimeout(r),c.ok||await this.handleResponseError(c,i);let w=this.safeClone(c),l=this.safeClone(c);return this.emit("response",w,e),{data:await this.parseResponse(l),status:c.status}}catch(c){throw clearTimeout(r),this.emit("error",c,e),this.handleFetchError(c,i),c}}getAuthHeaders(e={}){let t=this.getAuthHeadersCallback();return{...e,...t}}safeClone(e){try{return e.clone()}catch{return e}}async parseResponse(e){if(!(e.headers.get("Content-Length")==="0"||e.status===204))return await e.json()}async handleResponseError(e,t){let i={};try{e.headers.get("content-type")?.includes("application/json")?i=await e.json():i={message:await e.text()}}catch{i={message:"Failed to parse error response"}}let s=i.message||i.error||`${t} failed due to API error`;throw e.status===401?D.ShipError.authentication(s):D.ShipError.api(s,e.status,i.code,i)}handleFetchError(e,t){throw e.name==="AbortError"?D.ShipError.cancelled(`${t} operation was cancelled.`):e instanceof TypeError&&e.message.includes("fetch")?D.ShipError.network(`${t} failed due to network error: ${e.message}`,e):e instanceof D.ShipError?e:D.ShipError.business(`An unexpected error occurred during ${t}: ${e.message||"Unknown error"}`)}async ping(){return(await this.request(`${this.apiUrl}${Le}`,{method:"GET"},"Ping"))?.success||!1}async getPingResponse(){return await this.request(`${this.apiUrl}${Le}`,{method:"GET"},"Ping")}async getConfig(){return await this.request(`${this.apiUrl}${pt}`,{method:"GET"},"Config")}async deploy(e,t={}){this.validateFiles(e);let{requestBody:i,requestHeaders:s}=await this.prepareRequestPayload(e,t.tags),o={};t.deployToken?o={Authorization:`Bearer ${t.deployToken}`}:t.apiKey&&(o={Authorization:`Bearer ${t.apiKey}`});let r={method:"POST",body:i,headers:{...s,...o},signal:t.signal||null};return await this.request(`${t.apiUrl||this.apiUrl}${ae}`,r,"Deploy")}async listDeployments(){return await this.request(`${this.apiUrl}${ae}`,{method:"GET"},"List Deployments")}async getDeployment(e){return await this.request(`${this.apiUrl}${ae}/${e}`,{method:"GET"},"Get Deployment")}async removeDeployment(e){await this.request(`${this.apiUrl}${ae}/${e}`,{method:"DELETE"},"Remove Deployment")}async setDomain(e,t,i){let s={};t&&(s.deployment=t),i&&i.length>0&&(s.tags=i);let o=`${this.apiUrl}${$}/${encodeURIComponent(e)}`,{data:r,status:a}=await this.requestWithStatus(o,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)},"Set Domain");return{...r,isCreate:a===201}}async getDomain(e){return await this.request(`${this.apiUrl}${$}/${encodeURIComponent(e)}`,{method:"GET"},"Get Domain")}async listDomains(){return await this.request(`${this.apiUrl}${$}`,{method:"GET"},"List Domains")}async removeDomain(e){await this.request(`${this.apiUrl}${$}/${encodeURIComponent(e)}`,{method:"DELETE"},"Remove Domain")}async confirmDomain(e){return await this.request(`${this.apiUrl}${$}/${encodeURIComponent(e)}/confirm`,{method:"POST"},"Confirm Domain")}async getDomainDns(e){return await this.request(`${this.apiUrl}${$}/${encodeURIComponent(e)}/dns`,{method:"GET"},"Get Domain DNS")}async getDomainRecords(e){return await this.request(`${this.apiUrl}${$}/${encodeURIComponent(e)}/records`,{method:"GET"},"Get Domain Records")}async getDomainShare(e){return await this.request(`${this.apiUrl}${$}/${encodeURIComponent(e)}/share`,{method:"GET"},"Get Domain Share")}async getAccount(){return await this.request(`${this.apiUrl}${ct}`,{method:"GET"},"Get Account")}async createToken(e,t){let i={};return e!==void 0&&(i.ttl=e),t&&t.length>0&&(i.tags=t),await this.request(`${this.apiUrl}${Se}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)},"Create Token")}async listTokens(){return await this.request(`${this.apiUrl}${Se}`,{method:"GET"},"List Tokens")}async removeToken(e){await this.request(`${this.apiUrl}${Se}/${encodeURIComponent(e)}`,{method:"DELETE"},"Remove Token")}async checkSPA(e){let t=e.find(r=>r.path==="index.html"||r.path==="/index.html");if(!t||t.size>100*1024)return!1;let i;if(typeof Buffer<"u"&&Buffer.isBuffer(t.content))i=t.content.toString("utf-8");else if(typeof Blob<"u"&&t.content instanceof Blob)i=await t.content.text();else if(typeof File<"u"&&t.content instanceof File)i=await t.content.text();else return!1;let s={files:e.map(r=>r.path),index:i};return(await this.request(`${this.apiUrl}${ft}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)},"SPA Check")).isSPA}validateFiles(e){if(!e.length)throw D.ShipError.business("No files to deploy.");for(let t of e)if(!t.md5)throw D.ShipError.file(`MD5 checksum missing for file: ${t.path}`,t.path)}async prepareRequestPayload(e,t){if(g()==="browser")return{requestBody:this.createBrowserBody(e,t),requestHeaders:{}};if(g()==="node"){let{body:i,headers:s}=await this.createNodeBody(e,t);return{requestBody:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),requestHeaders:s}}else throw D.ShipError.business("Unknown or unsupported execution environment")}createBrowserBody(e,t){let i=new FormData,s=[];for(let o of e){if(!(o.content instanceof File||o.content instanceof Blob))throw D.ShipError.file(`Unsupported file.content type for browser FormData: ${o.path}`,o.path);if(!o.md5)throw D.ShipError.file(`File missing md5 checksum: ${o.path}`,o.path);let r=this.getBrowserContentType(o.content instanceof File?o.content:o.path),a=new File([o.content],o.path,{type:r});i.append("files[]",a),s.push(o.md5)}return i.append("checksums",JSON.stringify(s)),t&&t.length>0&&i.append("tags",JSON.stringify(t)),i}async createNodeBody(e,t){let{FormData:i,File:s}=await import("formdata-node"),{FormDataEncoder:o}=await import("form-data-encoder"),r=new i,a=[];for(let l of e){let m=se(l.path),u;if(Buffer.isBuffer(l.content))u=new s([l.content],l.path,{type:m});else if(typeof Blob<"u"&&l.content instanceof Blob)u=new s([l.content],l.path,{type:m});else throw D.ShipError.file(`Unsupported file.content type for Node.js FormData: ${l.path}`,l.path);if(!l.md5)throw D.ShipError.file(`File missing md5 checksum: ${l.path}`,l.path);let P=l.path.startsWith("/")?l.path:"/"+l.path;r.append("files[]",u,P),a.push(l.md5)}r.append("checksums",JSON.stringify(a)),t&&t.length>0&&r.append("tags",JSON.stringify(t));let d=new o(r),c=[];for await(let l of d.encode())c.push(Buffer.from(l));let w=Buffer.concat(c);return{body:w,headers:{"Content-Type":d.contentType,"Content-Length":Buffer.byteLength(w).toString()}}}getBrowserContentType(e){return typeof e=="string"?se(e):e.type||se(e.name)}};var Te=require("@shipstatic/types");M();var Ke=require("@shipstatic/types");C();async function ht(n){let e=g();if(e==="browser")return{};if(e==="node"){let{loadConfig:t}=await Promise.resolve().then(()=>(pe(),Ue));return t(n)}else return{}}function q(n={},e={}){let t={apiUrl:n.apiUrl||e.apiUrl||Ke.DEFAULT_API,apiKey:n.apiKey!==void 0?n.apiKey:e.apiKey,deployToken:n.deployToken!==void 0?n.deployToken:e.deployToken},i={apiUrl:t.apiUrl};return t.apiKey!==void 0&&(i.apiKey=t.apiKey),t.deployToken!==void 0&&(i.deployToken=t.deployToken),i}function W(n,e){let t={...n};return t.apiUrl===void 0&&e.apiUrl!==void 0&&(t.apiUrl=e.apiUrl),t.apiKey===void 0&&e.apiKey!==void 0&&(t.apiKey=e.apiKey),t.deployToken===void 0&&e.deployToken!==void 0&&(t.deployToken=e.deployToken),t.timeout===void 0&&e.timeout!==void 0&&(t.timeout=e.timeout),t.maxConcurrency===void 0&&e.maxConcurrency!==void 0&&(t.maxConcurrency=e.maxConcurrency),t.onProgress===void 0&&e.onProgress!==void 0&&(t.onProgress=e.onProgress),t}var Ce=require("@shipstatic/types");J();async function vt(){let e=JSON.stringify({rewrites:[{source:"/(.*)",destination:"/index.html"}]},null,2),t;typeof Buffer<"u"?t=Buffer.from(e,"utf-8"):t=new Blob([e],{type:"application/json"});let{md5:i}=await k(t);return{path:Ce.DEPLOYMENT_CONFIG_FILENAME,content:t,size:e.length,md5:i}}async function qe(n,e,t){if(t.spaDetect===!1||n.some(i=>i.path===Ce.DEPLOYMENT_CONFIG_FILENAME))return n;try{if(await e.checkSPA(n)){let s=await vt();return[...n,s]}}catch{}return n}function Y(n,e,t,i,s){return{create:async(o,r={})=>{t&&await t();let a=e?W(r,e):r;if(s&&!s()&&!a.deployToken&&!a.apiKey)throw new Error("Authentication credentials are required for deployment. Please call setDeployToken() or setApiKey() first, or pass credentials in the deployment options.");let d=n();if(!i)throw new Error("processInput function is not provided.");let c=await i(o,a);return c=await qe(c,d,a),await d.deploy(c,a)},list:async()=>(t&&await t(),n().listDeployments()),remove:async o=>{t&&await t(),await n().removeDeployment(o)},get:async o=>(t&&await t(),n().getDeployment(o))}}function X(n,e){return{set:async(t,i,s)=>(e&&await e(),n().setDomain(t,i,s)),get:async t=>(e&&await e(),n().getDomain(t)),list:async()=>(e&&await e(),n().listDomains()),remove:async t=>{e&&await e(),await n().removeDomain(t)},confirm:async t=>(e&&await e(),n().confirmDomain(t)),dns:async t=>(e&&await e(),n().getDomainDns(t)),records:async t=>(e&&await e(),n().getDomainRecords(t)),share:async t=>(e&&await e(),n().getDomainShare(t))}}function Q(n,e){return{get:async()=>(e&&await e(),n().getAccount())}}function Z(n,e){return{create:async(t,i)=>(e&&await e(),n().createToken(t,i)),list:async()=>(e&&await e(),n().listTokens()),remove:async t=>{e&&await e(),await n().removeToken(t)}}}var H=class{constructor(e={}){this.initPromise=null;this._config=null;this.auth=null;this.clientOptions=e,e.deployToken?this.auth={type:"token",value:e.deployToken}:e.apiKey&&(this.auth={type:"apiKey",value:e.apiKey}),this.authHeadersCallback=()=>this.getAuthHeaders();let t=this.resolveInitialConfig(e);this.http=new b({...e,...t,getAuthHeaders:this.authHeadersCallback});let i=()=>this.ensureInitialized(),s=()=>this.http;this._deployments=Y(s,this.clientOptions,i,(o,r)=>this.processInput(o,r),()=>this.hasAuth()),this._domains=X(s,i),this._account=Q(s,i),this._tokens=Z(s,i)}async ensureInitialized(){return this.initPromise||(this.initPromise=this.loadFullConfig()),this.initPromise}async ping(){return await this.ensureInitialized(),this.http.ping()}async deploy(e,t){return this.deployments.create(e,t)}async whoami(){return this.account.get()}get deployments(){return this._deployments}get domains(){return this._domains}get account(){return this._account}get tokens(){return this._tokens}async getConfig(){return this._config?this._config:(await this.ensureInitialized(),this._config=A(),this._config)}on(e,t){this.http.on(e,t)}off(e,t){this.http.off(e,t)}replaceHttpClient(e){if(this.http?.transferEventsTo)try{this.http.transferEventsTo(e)}catch(t){console.warn("Event transfer failed during client replacement:",t)}this.http=e}setDeployToken(e){if(!e||typeof e!="string")throw Te.ShipError.business("Invalid deploy token provided. Deploy token must be a non-empty string.");this.auth={type:"token",value:e}}setApiKey(e){if(!e||typeof e!="string")throw Te.ShipError.business("Invalid API key provided. API key must be a non-empty string.");this.auth={type:"apiKey",value:e}}getAuthHeaders(){if(!this.auth)return{};switch(this.auth.type){case"token":return{Authorization:`Bearer ${this.auth.value}`};case"apiKey":return{Authorization:`Bearer ${this.auth.value}`};default:return{}}}hasAuth(){return this.clientOptions.useCredentials?!0:this.auth!==null}};var ge=require("@shipstatic/types");C();pe();M();var f={};_(f,{ApiHttp:()=>b,DEFAULT_API:()=>ce.DEFAULT_API,ErrorType:()=>O.ErrorType,FILE_VALIDATION_STATUS:()=>h.FileValidationStatus,JUNK_DIRECTORIES:()=>fe,Ship:()=>H,ShipError:()=>O.ShipError,__setTestEnvironment:()=>G,allValidFilesReady:()=>ke,calculateMD5:()=>k,createAccountResource:()=>Q,createDeploymentResource:()=>Y,createDomainResource:()=>X,createTokenResource:()=>Z,ensureShipError:()=>Ie,filterJunk:()=>z,formatFileSize:()=>j,getENV:()=>g,getValidFiles:()=>he,loadConfig:()=>ht,mergeDeployOptions:()=>W,optimizeDeployPaths:()=>L,pluralize:()=>Pe,resolveConfig:()=>q,validateFiles:()=>Ae});var v={};p(v,require("@shipstatic/types"));p(f,v);var ce=require("@shipstatic/types");J();function Pe(n,e,t,i=!0){let s=n===1?e:t;return i?`${n} ${s}`:s}me();de();C();var h=require("@shipstatic/types"),be=E(require("mime-db"),1),Dt=new Set(Object.keys(be.default)),St=new Map(Object.entries(be.default).filter(([n,e])=>e.extensions).map(([n,e])=>[n,new Set(e.extensions)]));function j(n,e=1){if(n===0)return"0 Bytes";let t=1024,i=["Bytes","KB","MB","GB"],s=Math.floor(Math.log(n)/Math.log(t));return parseFloat((n/Math.pow(t,s)).toFixed(e))+" "+i[s]}function Ft(n){if(/[?&#%<>\[\]{}|\\^~`;$()'"*\r\n\t]/.test(n))return{valid:!1,reason:"File name contains unsafe characters"};if(n.startsWith(".")===!1&&(n.startsWith(" ")||n.endsWith(" ")||n.endsWith(".")))return{valid:!1,reason:"File name cannot start/end with spaces or end with dots"};let t=/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\.|$)/i,i=n.split("/").pop()||n;return t.test(i)?{valid:!1,reason:"File name uses a reserved system name"}:n.includes("..")?{valid:!1,reason:"File name contains path traversal pattern"}:{valid:!0}}function Et(n,e){if(n.startsWith("."))return!0;let t=n.toLowerCase().split(".");if(t.length>1&&t[t.length-1]){let i=t[t.length-1],s=St.get(e);if(s&&!s.has(i))return!1}return!0}function Ae(n,e){let t=[],i=[];if(n.length===0){let o="At least one file must be provided";return{files:[],validFiles:[],error:{error:"No Files Provided",details:o,errors:[o],isClientError:!0}}}if(n.length>e.maxFilesCount){let o=`Number of files (${n.length}) exceeds the limit of ${e.maxFilesCount}.`;return{files:n.map(r=>({...r,status:h.FileValidationStatus.VALIDATION_FAILED,statusMessage:o})),validFiles:[],error:{error:"File Count Exceeded",details:o,errors:[o],isClientError:!0}}}let s=0;for(let o of n){let r=h.FileValidationStatus.READY,a="Ready for upload",d=o.name?Ft(o.name):{valid:!1,reason:"File name cannot be empty"};o.status===h.FileValidationStatus.PROCESSING_ERROR?(r=h.FileValidationStatus.PROCESSING_ERROR,a=o.statusMessage||"A file failed during processing.",t.push(`${o.name}: ${a}`)):!o.name||o.name.trim().length===0?(r=h.FileValidationStatus.VALIDATION_FAILED,a="File name cannot be empty",t.push(`${o.name||"(empty)"}: ${a}`)):o.name.includes("\0")?(r=h.FileValidationStatus.VALIDATION_FAILED,a="File name contains invalid characters (null byte)",t.push(`${o.name}: ${a}`)):d.valid?o.size<=0?(r=h.FileValidationStatus.EMPTY_FILE,a=o.size===0?"File is empty (0 bytes)":"File size must be positive",t.push(`${o.name}: ${a}`)):!o.type||o.type.trim().length===0?(r=h.FileValidationStatus.VALIDATION_FAILED,a="File MIME type is required",t.push(`${o.name}: ${a}`)):e.allowedMimeTypes.some(c=>o.type.startsWith(c))?Dt.has(o.type)?Et(o.name,o.type)?o.size>e.maxFileSize?(r=h.FileValidationStatus.VALIDATION_FAILED,a=`File size (${j(o.size)}) exceeds limit of ${j(e.maxFileSize)}`,t.push(`${o.name}: ${a}`)):(s+=o.size,s>e.maxTotalSize&&(r=h.FileValidationStatus.VALIDATION_FAILED,a=`Total size would exceed limit of ${j(e.maxTotalSize)}`,t.push(`${o.name}: ${a}`))):(r=h.FileValidationStatus.VALIDATION_FAILED,a="File extension does not match MIME type",t.push(`${o.name}: ${a}`)):(r=h.FileValidationStatus.VALIDATION_FAILED,a=`Invalid MIME type "${o.type}"`,t.push(`${o.name}: ${a}`)):(r=h.FileValidationStatus.VALIDATION_FAILED,a=`File type "${o.type}" is not allowed`,t.push(`${o.name}: ${a}`)):(r=h.FileValidationStatus.VALIDATION_FAILED,a=d.reason||"Invalid file name",t.push(`${o.name}: ${a}`)),i.push({...o,status:r,statusMessage:a})}if(t.length>0){let o=i.find(a=>a.status!==h.FileValidationStatus.READY&&a.status!==h.FileValidationStatus.PENDING),r="Validation Failed";return o?.status===h.FileValidationStatus.PROCESSING_ERROR?r="Processing Error":o?.status===h.FileValidationStatus.EMPTY_FILE?r="Empty File":o?.statusMessage?.includes("File name cannot be empty")||o?.statusMessage?.includes("Invalid file name")||o?.statusMessage?.includes("File name contains")||o?.statusMessage?.includes("File name uses")||o?.statusMessage?.includes("File name cannot start")||o?.statusMessage?.includes("traversal")?r="Invalid File Name":o?.statusMessage?.includes("File size must be positive")?r="Invalid File Size":o?.statusMessage?.includes("MIME type is required")?r="Missing MIME Type":o?.statusMessage?.includes("Invalid MIME type")?r="Invalid MIME Type":o?.statusMessage?.includes("not allowed")?r="Invalid File Type":o?.statusMessage?.includes("extension does not match")?r="Extension Mismatch":o?.statusMessage?.includes("Total size")?r="Total Size Exceeded":o?.statusMessage?.includes("exceeds limit")&&(r="File Too Large"),{files:i.map(a=>({...a,status:h.FileValidationStatus.VALIDATION_FAILED})),validFiles:[],error:{error:r,details:t.length===1?t[0]:`${t.length} file(s) failed validation`,errors:t,isClientError:!0}}}return{files:i,validFiles:i,error:null}}function he(n){return n.filter(e=>e.status===h.FileValidationStatus.READY)}function ke(n){return he(n).length>0}var ye=require("@shipstatic/types");function Ie(n){return n instanceof ye.ShipError?n:n instanceof Error?ye.ShipError.business(n.message):ye.ShipError.business(String(n??"Unknown error"))}var O=require("@shipstatic/types");p(y,f);pe();M();M();$e();C();var te=class extends H{constructor(e={}){if(g()!=="node")throw ge.ShipError.business("Node.js Ship class can only be used in Node.js environment.");super(e)}resolveInitialConfig(e){return q(e,{})}async loadFullConfig(){try{let e=await K(this.clientOptions.configFile),t=q(this.clientOptions,e);t.deployToken&&!this.clientOptions.deployToken?this.setDeployToken(t.deployToken):t.apiKey&&!this.clientOptions.apiKey&&this.setApiKey(t.apiKey);let i=new b({...this.clientOptions,...t,getAuthHeaders:this.authHeadersCallback});this.replaceHttpClient(i);let s=await this.http.getConfig();B(s)}catch(e){throw this.initPromise=null,e}}async processInput(e,t){if(!this.#e(e))throw ge.ShipError.business("Invalid input type for Node.js environment. Expected string[] file paths.");if(Array.isArray(e)&&e.length===0)throw ge.ShipError.business("No files to deploy.");let{convertDeployInput:i}=await Promise.resolve().then(()=>(et(),Ze));return i(e,t,this.http)}#e(e){return typeof e=="string"?!0:Array.isArray(e)?e.every(t=>typeof t=="string"):!1}},Ne=te;p(ne,y,module.exports);0&&(module.exports={ApiHttp,DEFAULT_API,ErrorType,FILE_VALIDATION_STATUS,JUNK_DIRECTORIES,Ship,ShipError,__setTestEnvironment,allValidFilesReady,calculateMD5,createAccountResource,createDeploymentResource,createDomainResource,createTokenResource,ensureShipError,filterJunk,formatFileSize,getCurrentConfig,getENV,getValidFiles,loadConfig,mergeDeployOptions,optimizeDeployPaths,pluralize,processFilesForNode,resolveConfig,setConfig,setPlatformConfig,validateFiles});
1
+ "use strict";var We=Object.create;var ee=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames;var Xe=Object.getPrototypeOf,Qe=Object.prototype.hasOwnProperty;var P=(n,e)=>()=>(n&&(e=n(n=0)),e);var z=(n,e)=>{for(var t in e)ee(n,t,{get:e[t],enumerable:!0})},Z=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Je(e))!Qe.call(n,r)&&r!==t&&ee(n,r,{get:()=>e[r],enumerable:!(o=Ye(e,r))||o.enumerable});return n},p=(n,e,t)=>(Z(n,e,"default"),t&&Z(t,e,"default")),E=(n,e,t)=>(t=n!=null?We(Xe(n)):{},Z(e||!n||!n.__esModule?ee(t,"default",{value:n,enumerable:!0}):t,n)),Ze=n=>Z(ee({},"__esModule",{value:!0}),n);function K(n){he=n}function k(){if(he===null)throw Me.ShipError.config("Platform configuration not initialized. The SDK must fetch configuration from the API before performing operations.");return he}var Me,he,q=P(()=>{"use strict";Me=require("@shipstatic/types"),he=null});function oe(n){ye=n}function it(){return typeof process<"u"&&process.versions&&process.versions.node?"node":typeof window<"u"||typeof self<"u"?"browser":"unknown"}function C(){return ye||it()}var ye,I=P(()=>{"use strict";ye=null});var _e={};z(_e,{loadConfig:()=>M});function Be(n){try{return rt.parse(n)}catch(e){if(e instanceof N.z.ZodError){let t=e.issues[0],o=t.path.length>0?` at ${t.path.join(".")}`:"";throw ie.ShipError.config(`Configuration validation failed${o}: ${t.message}`)}throw ie.ShipError.config("Configuration validation failed")}}async function st(n){try{if(C()!=="node")return{};let{cosmiconfigSync:e}=await import("cosmiconfig"),t=await import("os"),o=e(ge,{searchPlaces:[`.${ge}rc`,"package.json",`${t.homedir()}/.${ge}rc`],stopDir:t.homedir()}),r;if(n?r=o.load(n):r=o.search(),r&&r.config)return Be(r.config)}catch(e){if(e instanceof ie.ShipError)throw e}return{}}async function M(n){if(C()!=="node")return{};let e={apiUrl:process.env.SHIP_API_URL,apiKey:process.env.SHIP_API_KEY,deployToken:process.env.SHIP_DEPLOY_TOKEN},t=await st(n),o={apiUrl:e.apiUrl??t.apiUrl,apiKey:e.apiKey??t.apiKey,deployToken:e.deployToken??t.deployToken};return Be(o)}var N,ie,ge,rt,re=P(()=>{"use strict";N=require("zod"),ie=require("@shipstatic/types");I();ge="ship",rt=N.z.object({apiUrl:N.z.string().url().optional(),apiKey:N.z.string().optional(),deployToken:N.z.string().optional()}).strict()});async function pt(n){let e=(await import("spark-md5")).default;return new Promise((t,o)=>{let i=Math.ceil(n.size/2097152),s=0,a=new e.ArrayBuffer,f=new FileReader,c=()=>{let y=s*2097152,l=Math.min(y+2097152,n.size);f.readAsArrayBuffer(n.slice(y,l))};f.onload=y=>{let l=y.target?.result;if(!l){o(O.ShipError.business("Failed to read file chunk"));return}a.append(l),s++,s<i?c():t({md5:a.end()})},f.onerror=()=>{o(O.ShipError.business("Failed to calculate MD5: FileReader error"))},c()})}async function lt(n){let e=await import("crypto");if(Buffer.isBuffer(n)){let o=e.createHash("md5");return o.update(n),{md5:o.digest("hex")}}let t=await import("fs");return new Promise((o,r)=>{let i=e.createHash("md5"),s=t.createReadStream(n);s.on("error",a=>r(O.ShipError.business(`Failed to read file for MD5: ${a.message}`))),s.on("data",a=>i.update(a)),s.on("end",()=>o({md5:i.digest("hex")}))})}async function $(n){let e=C();if(e==="browser"){if(!(n instanceof Blob))throw O.ShipError.business("Invalid input for browser MD5 calculation: Expected Blob or File.");return pt(n)}if(e==="node"){if(!(Buffer.isBuffer(n)||typeof n=="string"))throw O.ShipError.business("Invalid input for Node.js MD5 calculation: Expected Buffer or file path string.");return lt(n)}throw O.ShipError.business("Unknown or unsupported execution environment for MD5 calculation.")}var O,se=P(()=>{"use strict";I();O=require("@shipstatic/types")});function Y(n){return!n||n.length===0?[]:n.filter(e=>{if(!e)return!1;let t=e.replace(/\\/g,"/").split("/").filter(Boolean);if(t.length===0)return!0;let o=t[t.length-1];if((0,qe.isJunk)(o))return!1;let r=t.slice(0,-1);for(let i of r)if(pe.some(s=>i.toLowerCase()===s.toLowerCase()))return!1;return!0})}var qe,pe,xe=P(()=>{"use strict";qe=require("junk"),pe=["__MACOSX",".Trashes",".fseventsd",".Spotlight-V100"]});function He(n){if(!n||n.length===0)return"";let e=n.filter(i=>i&&typeof i=="string").map(i=>i.replace(/\\/g,"/"));if(e.length===0)return"";if(e.length===1)return e[0];let t=e.map(i=>i.split("/").filter(Boolean)),o=[],r=Math.min(...t.map(i=>i.length));for(let i=0;i<r;i++){let s=t[0][i];if(t.every(a=>a[i]===s))o.push(s);else break}return o.join("/")}function le(n){return n.replace(/\\/g,"/").replace(/\/+/g,"/").replace(/^\/+/,"")}var we=P(()=>{"use strict"});function J(n,e={}){if(e.flatten===!1)return n.map(o=>({path:le(o),name:Ae(o)}));let t=ut(n);return n.map(o=>{let r=le(o);if(t){let i=t.endsWith("/")?t:`${t}/`;r.startsWith(i)&&(r=r.substring(i.length))}return r||(r=Ae(o)),{path:r,name:Ae(o)}})}function ut(n){if(!n.length)return"";let t=n.map(i=>le(i)).map(i=>i.split("/")),o=[],r=Math.min(...t.map(i=>i.length));for(let i=0;i<r-1;i++){let s=t[0][i];if(t.every(a=>a[i]===s))o.push(s);else break}return o.join("/")}function Ae(n){return n.split(/[/\\]/).pop()||n}var Pe=P(()=>{"use strict";we()});var je={};z(je,{processFilesForNode:()=>fe});function Ve(n,e=new Set){let t=[],o=T.realpathSync(n);if(e.has(o))return t;e.add(o);let r=T.readdirSync(n);for(let i of r){let s=v.join(n,i),a=T.statSync(s);if(a.isDirectory()){let f=Ve(s,e);t.push(...f)}else a.isFile()&&t.push(s)}return t}async function fe(n,e={}){if(C()!=="node")throw A.ShipError.business("processFilesForNode can only be called in Node.js environment.");let t=n.flatMap(h=>{let g=v.resolve(h);try{return T.statSync(g).isDirectory()?Ve(g):[g]}catch{throw A.ShipError.file(`Path does not exist: ${h}`,h)}}),o=[...new Set(t)],r=Y(o);if(r.length===0)return[];let i=n.map(h=>v.resolve(h)),s=He(i.map(h=>{try{return T.statSync(h).isDirectory()?h:v.dirname(h)}catch{return v.dirname(h)}})),a=r.map(h=>{if(s&&s.length>0){let g=v.relative(s,h);if(g&&typeof g=="string"&&!g.startsWith(".."))return g.replace(/\\/g,"/")}return v.basename(h)}),f=J(a,{flatten:e.pathDetect!==!1}),c=[],y=0,l=k();for(let h=0;h<r.length;h++){let g=r[h],R=f[h].path;try{let x=T.statSync(g);if(x.size===0)continue;if(x.size>l.maxFileSize)throw A.ShipError.business(`File ${g} is too large. Maximum allowed size is ${l.maxFileSize/(1024*1024)}MB.`);if(y+=x.size,y>l.maxTotalSize)throw A.ShipError.business(`Total deploy size is too large. Maximum allowed is ${l.maxTotalSize/(1024*1024)}MB.`);let U=T.readFileSync(g),{md5:Ge}=await $(U);if(R.includes("\0")||R.includes("/../")||R.startsWith("../")||R.endsWith("/.."))throw A.ShipError.business(`Security error: Unsafe file path "${R}" for file: ${g}`);c.push({path:R,content:U,size:U.length,md5:Ge})}catch(x){if(x instanceof A.ShipError)throw x;let U=x instanceof Error?x.message:String(x);throw A.ShipError.file(`Failed to read file "${g}": ${U}`,g)}}if(c.length>l.maxFilesCount)throw A.ShipError.business(`Too many files to deploy. Maximum allowed is ${l.maxFilesCount} files.`);return c}var A,T,v,Oe=P(()=>{"use strict";I();se();xe();A=require("@shipstatic/types");q();Pe();we();T=E(require("fs"),1),v=E(require("path"),1)});var Q={};z(Q,{ApiHttp:()=>w,DEFAULT_API:()=>ae.DEFAULT_API,ErrorType:()=>b.ErrorType,FILE_VALIDATION_STATUS:()=>m.FileValidationStatus,JUNK_DIRECTORIES:()=>pe,Ship:()=>X,ShipError:()=>b.ShipError,__setTestEnvironment:()=>oe,allValidFilesReady:()=>be,calculateMD5:()=>$,createAccountResource:()=>G,createDeploymentResource:()=>V,createDomainResource:()=>j,createTokenResource:()=>W,default:()=>$e,ensureShipError:()=>ke,filterJunk:()=>Y,formatFileSize:()=>L,getCurrentConfig:()=>k,getENV:()=>C,getValidFiles:()=>ce,loadConfig:()=>M,mergeDeployOptions:()=>H,optimizeDeployPaths:()=>J,pluralize:()=>Re,processFilesForNode:()=>fe,resolveConfig:()=>B,setPlatformConfig:()=>K,validateFiles:()=>Ie});module.exports=Ze(Q);var d={};z(d,{ApiHttp:()=>w,DEFAULT_API:()=>ae.DEFAULT_API,ErrorType:()=>b.ErrorType,FILE_VALIDATION_STATUS:()=>m.FileValidationStatus,JUNK_DIRECTORIES:()=>pe,Ship:()=>X,ShipError:()=>b.ShipError,__setTestEnvironment:()=>oe,allValidFilesReady:()=>be,calculateMD5:()=>$,createAccountResource:()=>G,createDeploymentResource:()=>V,createDomainResource:()=>j,createTokenResource:()=>W,default:()=>$e,ensureShipError:()=>ke,filterJunk:()=>Y,formatFileSize:()=>L,getCurrentConfig:()=>k,getENV:()=>C,getValidFiles:()=>ce,loadConfig:()=>M,mergeDeployOptions:()=>H,optimizeDeployPaths:()=>J,pluralize:()=>Re,processFilesForNode:()=>fe,resolveConfig:()=>B,setPlatformConfig:()=>K,validateFiles:()=>Ie});var S=require("@shipstatic/types");var te=class{constructor(){this.handlers=new Map}on(e,t){this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t)}off(e,t){let o=this.handlers.get(e);o&&(o.delete(t),o.size===0&&this.handlers.delete(e))}emit(e,...t){let o=this.handlers.get(e);if(!o)return;let r=Array.from(o);for(let i of r)try{i(...t)}catch(s){o.delete(i),e!=="error"&&setTimeout(()=>{s instanceof Error?this.emit("error",s,String(e)):this.emit("error",new Error(String(s)),String(e))},0)}}transfer(e){this.handlers.forEach((t,o)=>{t.forEach(r=>{e.on(o,r)})})}clear(){this.handlers.clear()}};var ne="/deployments",Ne="/ping",F="/domains",et="/config",tt="/account",de="/tokens",nt="/spa-check",ot=3e4,w=class extends te{constructor(e){super(),this.apiUrl=e.apiUrl||S.DEFAULT_API,this.getAuthHeadersCallback=e.getAuthHeaders,this.timeout=e.timeout??ot,this.createDeployBody=e.createDeployBody}transferEventsTo(e){this.transfer(e)}async request(e,t={},o){let r=this.getAuthHeaders(t.headers),i=new AbortController,s=setTimeout(()=>i.abort(),this.timeout),a=t.signal?this.combineSignals(t.signal,i.signal):i.signal,f={...t,headers:r,credentials:r.Authorization?void 0:"include",signal:a};this.emit("request",e,f);try{let c=await fetch(e,f);clearTimeout(s),c.ok||await this.handleResponseError(c,o);let y=this.safeClone(c),l=this.safeClone(c);return this.emit("response",y,e),await this.parseResponse(l)}catch(c){throw clearTimeout(s),this.emit("error",c,e),this.handleFetchError(c,o),c}}combineSignals(e,t){let o=new AbortController,r=()=>o.abort();return e.addEventListener("abort",r),t.addEventListener("abort",r),(e.aborted||t.aborted)&&o.abort(),o.signal}async requestWithStatus(e,t={},o){let r=this.getAuthHeaders(t.headers),i=new AbortController,s=setTimeout(()=>i.abort(),this.timeout),a=t.signal?this.combineSignals(t.signal,i.signal):i.signal,f={...t,headers:r,credentials:r.Authorization?void 0:"include",signal:a};this.emit("request",e,f);try{let c=await fetch(e,f);clearTimeout(s),c.ok||await this.handleResponseError(c,o);let y=this.safeClone(c),l=this.safeClone(c);return this.emit("response",y,e),{data:await this.parseResponse(l),status:c.status}}catch(c){throw clearTimeout(s),this.emit("error",c,e),this.handleFetchError(c,o),c}}getAuthHeaders(e={}){let t=this.getAuthHeadersCallback();return{...e,...t}}safeClone(e){try{return e.clone()}catch{return e}}async parseResponse(e){if(!(e.headers.get("Content-Length")==="0"||e.status===204))return await e.json()}async handleResponseError(e,t){let o={};try{e.headers.get("content-type")?.includes("application/json")?o=await e.json():o={message:await e.text()}}catch{o={message:"Failed to parse error response"}}let r=o.message||o.error||`${t} failed due to API error`;throw e.status===401?S.ShipError.authentication(r):S.ShipError.api(r,e.status,o.code,o)}handleFetchError(e,t){throw e.name==="AbortError"?S.ShipError.cancelled(`${t} operation was cancelled.`):e instanceof TypeError&&e.message.includes("fetch")?S.ShipError.network(`${t} failed due to network error: ${e.message}`,e):e instanceof S.ShipError?e:S.ShipError.business(`An unexpected error occurred during ${t}: ${e.message||"Unknown error"}`)}async ping(){return(await this.request(`${this.apiUrl}${Ne}`,{method:"GET"},"Ping"))?.success||!1}async getPingResponse(){return await this.request(`${this.apiUrl}${Ne}`,{method:"GET"},"Ping")}async getConfig(){return await this.request(`${this.apiUrl}${et}`,{method:"GET"},"Config")}async deploy(e,t={}){if(!e.length)throw S.ShipError.business("No files to deploy.");for(let a of e)if(!a.md5)throw S.ShipError.file(`MD5 checksum missing for file: ${a.path}`,a.path);let{body:o,headers:r}=await this.createDeployBody(e,t.tags,t.via),i={};t.deployToken?i.Authorization=`Bearer ${t.deployToken}`:t.apiKey&&(i.Authorization=`Bearer ${t.apiKey}`),t.caller&&(i["X-Caller"]=t.caller);let s={method:"POST",body:o,headers:{...r,...i},signal:t.signal||null};return await this.request(`${t.apiUrl||this.apiUrl}${ne}`,s,"Deploy")}async listDeployments(){return await this.request(`${this.apiUrl}${ne}`,{method:"GET"},"List Deployments")}async getDeployment(e){return await this.request(`${this.apiUrl}${ne}/${e}`,{method:"GET"},"Get Deployment")}async removeDeployment(e){await this.request(`${this.apiUrl}${ne}/${e}`,{method:"DELETE"},"Remove Deployment")}async setDomain(e,t,o){let r={};t&&(r.deployment=t),o&&o.length>0&&(r.tags=o);let i=`${this.apiUrl}${F}/${encodeURIComponent(e)}`,{data:s,status:a}=await this.requestWithStatus(i,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)},"Set Domain");return{...s,isCreate:a===201}}async getDomain(e){return await this.request(`${this.apiUrl}${F}/${encodeURIComponent(e)}`,{method:"GET"},"Get Domain")}async listDomains(){return await this.request(`${this.apiUrl}${F}`,{method:"GET"},"List Domains")}async removeDomain(e){await this.request(`${this.apiUrl}${F}/${encodeURIComponent(e)}`,{method:"DELETE"},"Remove Domain")}async verifyDomain(e){return await this.request(`${this.apiUrl}${F}/${encodeURIComponent(e)}/verify`,{method:"POST"},"Verify Domain")}async getDomainDns(e){return await this.request(`${this.apiUrl}${F}/${encodeURIComponent(e)}/dns`,{method:"GET"},"Get Domain DNS")}async getDomainRecords(e){return await this.request(`${this.apiUrl}${F}/${encodeURIComponent(e)}/records`,{method:"GET"},"Get Domain Records")}async getDomainShare(e){return await this.request(`${this.apiUrl}${F}/${encodeURIComponent(e)}/share`,{method:"GET"},"Get Domain Share")}async getAccount(){return await this.request(`${this.apiUrl}${tt}`,{method:"GET"},"Get Account")}async createToken(e,t){let o={};return e!==void 0&&(o.ttl=e),t&&t.length>0&&(o.tags=t),await this.request(`${this.apiUrl}${de}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)},"Create Token")}async listTokens(){return await this.request(`${this.apiUrl}${de}`,{method:"GET"},"List Tokens")}async removeToken(e){await this.request(`${this.apiUrl}${de}/${encodeURIComponent(e)}`,{method:"DELETE"},"Remove Token")}async checkSPA(e){let t=e.find(s=>s.path==="index.html"||s.path==="/index.html");if(!t||t.size>100*1024)return!1;let o;if(typeof Buffer<"u"&&Buffer.isBuffer(t.content))o=t.content.toString("utf-8");else if(typeof Blob<"u"&&t.content instanceof Blob)o=await t.content.text();else if(typeof File<"u"&&t.content instanceof File)o=await t.content.text();else return!1;let r={files:e.map(s=>s.path),index:o};return(await this.request(`${this.apiUrl}${nt}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)},"SPA Check")).isSPA}};var ve=require("@shipstatic/types");q();var Ce=require("@shipstatic/types");var Le=require("@shipstatic/types");I();async function at(n){let e=C();if(e==="browser")return{};if(e==="node"){let{loadConfig:t}=await Promise.resolve().then(()=>(re(),_e));return t(n)}else return{}}function B(n={},e={}){let t={apiUrl:n.apiUrl||e.apiUrl||Le.DEFAULT_API,apiKey:n.apiKey!==void 0?n.apiKey:e.apiKey,deployToken:n.deployToken!==void 0?n.deployToken:e.deployToken},o={apiUrl:t.apiUrl};return t.apiKey!==void 0&&(o.apiKey=t.apiKey),t.deployToken!==void 0&&(o.deployToken=t.deployToken),o}function H(n,e){let t={...n};return t.apiUrl===void 0&&e.apiUrl!==void 0&&(t.apiUrl=e.apiUrl),t.apiKey===void 0&&e.apiKey!==void 0&&(t.apiKey=e.apiKey),t.deployToken===void 0&&e.deployToken!==void 0&&(t.deployToken=e.deployToken),t.timeout===void 0&&e.timeout!==void 0&&(t.timeout=e.timeout),t.maxConcurrency===void 0&&e.maxConcurrency!==void 0&&(t.maxConcurrency=e.maxConcurrency),t.onProgress===void 0&&e.onProgress!==void 0&&(t.onProgress=e.onProgress),t.caller===void 0&&e.caller!==void 0&&(t.caller=e.caller),t}var De=require("@shipstatic/types");se();async function ct(){let e=JSON.stringify({rewrites:[{source:"/(.*)",destination:"/index.html"}]},null,2),t;typeof Buffer<"u"?t=Buffer.from(e,"utf-8"):t=new Blob([e],{type:"application/json"});let{md5:o}=await $(t);return{path:De.DEPLOYMENT_CONFIG_FILENAME,content:t,size:e.length,md5:o}}async function Ue(n,e,t){if(t.spaDetect===!1||n.some(o=>o.path===De.DEPLOYMENT_CONFIG_FILENAME))return n;try{if(await e.checkSPA(n)){let r=await ct();return[...n,r]}}catch{}return n}function V(n){let{getApi:e,ensureInit:t,processInput:o,clientDefaults:r,hasAuth:i}=n;return{create:async(s,a={})=>{await t();let f=r?H(a,r):a;if(i&&!i()&&!f.deployToken&&!f.apiKey)throw Ce.ShipError.authentication("Authentication credentials are required for deployment. Please call setDeployToken() or setApiKey() first, or pass credentials in the deployment options.");if(!o)throw Ce.ShipError.config("processInput function is not provided.");let c=e(),y=await o(s,f);return y=await Ue(y,c,f),c.deploy(y,f)},list:async()=>(await t(),e().listDeployments()),remove:async s=>{await t(),await e().removeDeployment(s)},get:async s=>(await t(),e().getDeployment(s))}}function j(n){let{getApi:e,ensureInit:t}=n;return{set:async(o,r,i)=>(await t(),e().setDomain(o,r,i)),get:async o=>(await t(),e().getDomain(o)),list:async()=>(await t(),e().listDomains()),remove:async o=>{await t(),await e().removeDomain(o)},verify:async o=>(await t(),e().verifyDomain(o)),dns:async o=>(await t(),e().getDomainDns(o)),records:async o=>(await t(),e().getDomainRecords(o)),share:async o=>(await t(),e().getDomainShare(o))}}function G(n){let{getApi:e,ensureInit:t}=n;return{get:async()=>(await t(),e().getAccount())}}function W(n){let{getApi:e,ensureInit:t}=n;return{create:async(o,r)=>(await t(),e().createToken(o,r)),list:async()=>(await t(),e().listTokens()),remove:async o=>{await t(),await e().removeToken(o)}}}var _=class{constructor(e={}){this.initPromise=null;this._config=null;this.auth=null;this.clientOptions=e,e.deployToken?this.auth={type:"token",value:e.deployToken}:e.apiKey&&(this.auth={type:"apiKey",value:e.apiKey}),this.authHeadersCallback=()=>this.getAuthHeaders();let t=this.resolveInitialConfig(e);this.http=new w({...e,...t,getAuthHeaders:this.authHeadersCallback,createDeployBody:this.getDeployBodyCreator()});let o={getApi:()=>this.http,ensureInit:()=>this.ensureInitialized()};this._deployments=V({...o,processInput:(r,i)=>this.processInput(r,i),clientDefaults:this.clientOptions,hasAuth:()=>this.hasAuth()}),this._domains=j(o),this._account=G(o),this._tokens=W(o)}async ensureInitialized(){return this.initPromise||(this.initPromise=this.loadFullConfig()),this.initPromise}async ping(){return await this.ensureInitialized(),this.http.ping()}async deploy(e,t){return this.deployments.create(e,t)}async whoami(){return this.account.get()}get deployments(){return this._deployments}get domains(){return this._domains}get account(){return this._account}get tokens(){return this._tokens}async getConfig(){return this._config?this._config:(await this.ensureInitialized(),this._config=k(),this._config)}on(e,t){this.http.on(e,t)}off(e,t){this.http.off(e,t)}replaceHttpClient(e){if(this.http?.transferEventsTo)try{this.http.transferEventsTo(e)}catch(t){console.warn("Event transfer failed during client replacement:",t)}this.http=e}setDeployToken(e){if(!e||typeof e!="string")throw ve.ShipError.business("Invalid deploy token provided. Deploy token must be a non-empty string.");this.auth={type:"token",value:e}}setApiKey(e){if(!e||typeof e!="string")throw ve.ShipError.business("Invalid API key provided. API key must be a non-empty string.");this.auth={type:"apiKey",value:e}}getAuthHeaders(){return this.auth?{Authorization:`Bearer ${this.auth.value}`}:{}}hasAuth(){return this.clientOptions.useCredentials?!0:this.auth!==null}};var me=require("@shipstatic/types");I();re();q();var Te=require("@shipstatic/types");var Ee=E(require("mime-db"),1),Se={};for(let n in Ee.default){let e=Ee.default[n];e&&e.extensions&&e.extensions.forEach(t=>{Se[t]||(Se[t]=n)})}function ze(n){let e=n.includes(".")?n.substring(n.lastIndexOf(".")+1).toLowerCase():"";return Se[e]||"application/octet-stream"}async function Ke(n,e,t){let{FormData:o,File:r}=await import("formdata-node"),{FormDataEncoder:i}=await import("form-data-encoder"),s=new o,a=[];for(let l of n){let h=ze(l.path),g;if(Buffer.isBuffer(l.content))g=new r([l.content],l.path,{type:h});else if(typeof Blob<"u"&&l.content instanceof Blob)g=new r([l.content],l.path,{type:h});else throw Te.ShipError.file(`Unsupported file.content type for Node.js: ${l.path}`,l.path);if(!l.md5)throw Te.ShipError.file(`File missing md5 checksum: ${l.path}`,l.path);let R=l.path.startsWith("/")?l.path:"/"+l.path;s.append("files[]",g,R),a.push(l.md5)}s.append("checksums",JSON.stringify(a)),e&&e.length>0&&s.append("tags",JSON.stringify(e)),t&&s.append("via",t);let f=new i(s),c=[];for await(let l of f.encode())c.push(Buffer.from(l));let y=Buffer.concat(c);return{body:y.buffer.slice(y.byteOffset,y.byteOffset+y.byteLength),headers:{"Content-Type":f.contentType,"Content-Length":Buffer.byteLength(y).toString()}}}var u={};z(u,{ApiHttp:()=>w,DEFAULT_API:()=>ae.DEFAULT_API,ErrorType:()=>b.ErrorType,FILE_VALIDATION_STATUS:()=>m.FileValidationStatus,JUNK_DIRECTORIES:()=>pe,Ship:()=>_,ShipError:()=>b.ShipError,__setTestEnvironment:()=>oe,allValidFilesReady:()=>be,calculateMD5:()=>$,createAccountResource:()=>G,createDeploymentResource:()=>V,createDomainResource:()=>j,createTokenResource:()=>W,ensureShipError:()=>ke,filterJunk:()=>Y,formatFileSize:()=>L,getENV:()=>C,getValidFiles:()=>ce,loadConfig:()=>at,mergeDeployOptions:()=>H,optimizeDeployPaths:()=>J,pluralize:()=>Re,resolveConfig:()=>B,validateFiles:()=>Ie});var D={};p(D,require("@shipstatic/types"));p(u,D);var ae=require("@shipstatic/types");se();function Re(n,e,t,o=!0){let r=n===1?e:t;return o?`${n} ${r}`:r}xe();Pe();I();var m=require("@shipstatic/types"),Fe=E(require("mime-db"),1),ft=new Set(Object.keys(Fe.default)),mt=new Map(Object.entries(Fe.default).filter(([n,e])=>e.extensions).map(([n,e])=>[n,new Set(e.extensions)]));var dt=[[/File name cannot|Invalid file name|File name contains|File name uses|traversal/i,"Invalid File Name"],[/File size must be positive/i,"Invalid File Size"],[/MIME type is required/i,"Missing MIME Type"],[/Invalid MIME type/i,"Invalid MIME Type"],[/not allowed/i,"Invalid File Type"],[/extension does not match/i,"Extension Mismatch"],[/Total size/i,"Total Size Exceeded"],[/exceeds limit/i,"File Too Large"]];function ht(n,e){if(n===m.FileValidationStatus.PROCESSING_ERROR)return"Processing Error";if(n===m.FileValidationStatus.EMPTY_FILE)return"Empty File";if(!e)return"Validation Failed";for(let[t,o]of dt)if(t.test(e))return o;return"Validation Failed"}function L(n,e=1){if(n===0)return"0 Bytes";let t=1024,o=["Bytes","KB","MB","GB"],r=Math.floor(Math.log(n)/Math.log(t));return parseFloat((n/Math.pow(t,r)).toFixed(e))+" "+o[r]}function yt(n){if(/[?&#%<>\[\]{}|\\^~`;$()'"*\r\n\t]/.test(n))return{valid:!1,reason:"File name contains unsafe characters"};if(n.startsWith(" ")||n.endsWith(" "))return{valid:!1,reason:"File name cannot start/end with spaces"};if(n.endsWith("."))return{valid:!1,reason:"File name cannot end with dots"};let t=/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(\.|$)/i,o=n.split("/").pop()||n;return t.test(o)?{valid:!1,reason:"File name uses a reserved system name"}:n.includes("..")?{valid:!1,reason:"File name contains path traversal pattern"}:{valid:!0}}function gt(n,e){if(n.startsWith("."))return!0;let t=n.toLowerCase().split(".");if(t.length>1&&t[t.length-1]){let o=t[t.length-1],r=mt.get(e);if(r&&!r.has(o))return!1}return!0}function Ie(n,e){let t=[],o=[];if(n.length===0){let i="At least one file must be provided";return{files:[],validFiles:[],error:{error:"No Files Provided",details:i,errors:[i],isClientError:!0}}}if(n.length>e.maxFilesCount){let i=`Number of files (${n.length}) exceeds the limit of ${e.maxFilesCount}.`;return{files:n.map(s=>({...s,status:m.FileValidationStatus.VALIDATION_FAILED,statusMessage:i})),validFiles:[],error:{error:"File Count Exceeded",details:i,errors:[i],isClientError:!0}}}let r=0;for(let i of n){let s=m.FileValidationStatus.READY,a="Ready for upload",f=i.name?yt(i.name):{valid:!1,reason:"File name cannot be empty"};i.status===m.FileValidationStatus.PROCESSING_ERROR?(s=m.FileValidationStatus.PROCESSING_ERROR,a=i.statusMessage||"A file failed during processing.",t.push(`${i.name}: ${a}`)):!i.name||i.name.trim().length===0?(s=m.FileValidationStatus.VALIDATION_FAILED,a="File name cannot be empty",t.push(`${i.name||"(empty)"}: ${a}`)):i.name.includes("\0")?(s=m.FileValidationStatus.VALIDATION_FAILED,a="File name contains invalid characters (null byte)",t.push(`${i.name}: ${a}`)):f.valid?i.size<=0?(s=m.FileValidationStatus.EMPTY_FILE,a=i.size===0?"File is empty (0 bytes)":"File size must be positive",t.push(`${i.name}: ${a}`)):!i.type||i.type.trim().length===0?(s=m.FileValidationStatus.VALIDATION_FAILED,a="File MIME type is required",t.push(`${i.name}: ${a}`)):e.allowedMimeTypes.some(c=>i.type.startsWith(c))?ft.has(i.type)?gt(i.name,i.type)?i.size>e.maxFileSize?(s=m.FileValidationStatus.VALIDATION_FAILED,a=`File size (${L(i.size)}) exceeds limit of ${L(e.maxFileSize)}`,t.push(`${i.name}: ${a}`)):(r+=i.size,r>e.maxTotalSize&&(s=m.FileValidationStatus.VALIDATION_FAILED,a=`Total size would exceed limit of ${L(e.maxTotalSize)}`,t.push(`${i.name}: ${a}`))):(s=m.FileValidationStatus.VALIDATION_FAILED,a="File extension does not match MIME type",t.push(`${i.name}: ${a}`)):(s=m.FileValidationStatus.VALIDATION_FAILED,a=`Invalid MIME type "${i.type}"`,t.push(`${i.name}: ${a}`)):(s=m.FileValidationStatus.VALIDATION_FAILED,a=`File type "${i.type}" is not allowed`,t.push(`${i.name}: ${a}`)):(s=m.FileValidationStatus.VALIDATION_FAILED,a=f.reason||"Invalid file name",t.push(`${i.name}: ${a}`)),o.push({...i,status:s,statusMessage:a})}if(t.length>0){let i=o.find(a=>a.status!==m.FileValidationStatus.READY&&a.status!==m.FileValidationStatus.PENDING),s=ht(i?.status,i?.statusMessage);return{files:o.map(a=>({...a,status:m.FileValidationStatus.VALIDATION_FAILED})),validFiles:[],error:{error:s,details:t.length===1?t[0]:`${t.length} file(s) failed validation`,errors:t,isClientError:!0}}}return{files:o,validFiles:o,error:null}}function ce(n){return n.filter(e=>e.status===m.FileValidationStatus.READY)}function be(n){return ce(n).length>0}var ue=require("@shipstatic/types");function ke(n){return n instanceof ue.ShipError?n:n instanceof Error?ue.ShipError.business(n.message):ue.ShipError.business(String(n??"Unknown error"))}var b=require("@shipstatic/types");p(d,u);re();q();Oe();I();var X=class extends _{constructor(e={}){if(C()!=="node")throw me.ShipError.business("Node.js Ship class can only be used in Node.js environment.");super(e)}resolveInitialConfig(e){return B(e,{})}async loadFullConfig(){try{let e=await M(this.clientOptions.configFile),t=B(this.clientOptions,e);t.deployToken&&!this.clientOptions.deployToken?this.setDeployToken(t.deployToken):t.apiKey&&!this.clientOptions.apiKey&&this.setApiKey(t.apiKey);let o=new w({...this.clientOptions,...t,getAuthHeaders:this.authHeadersCallback,createDeployBody:this.getDeployBodyCreator()});this.replaceHttpClient(o);let r=await this.http.getConfig();K(r)}catch(e){throw this.initPromise=null,e}}async processInput(e,t){let o=typeof e=="string"?[e]:e;if(!Array.isArray(o)||!o.every(i=>typeof i=="string"))throw me.ShipError.business("Invalid input type for Node.js environment. Expected string or string[].");if(o.length===0)throw me.ShipError.business("No files to deploy.");let{processFilesForNode:r}=await Promise.resolve().then(()=>(Oe(),je));return r(o,t)}getDeployBodyCreator(){return Ke}},$e=X;p(Q,d,module.exports);0&&(module.exports={ApiHttp,DEFAULT_API,ErrorType,FILE_VALIDATION_STATUS,JUNK_DIRECTORIES,Ship,ShipError,__setTestEnvironment,allValidFilesReady,calculateMD5,createAccountResource,createDeploymentResource,createDomainResource,createTokenResource,ensureShipError,filterJunk,formatFileSize,getCurrentConfig,getENV,getValidFiles,loadConfig,mergeDeployOptions,optimizeDeployPaths,pluralize,processFilesForNode,resolveConfig,setPlatformConfig,validateFiles});
2
2
 
3
3
  // Ship SDK: Enable axios-style CommonJS imports
4
4
  const originalExports = module.exports;