"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const undici=require("undici");var d=Object.defineProperty,c=(s,e,t)=>e in s?d(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,p=(s,e,t)=>(c(s,typeof e!="symbol"?e+"":e,t),t);const f=/filename[^;=\n]*=(?:(\\?['"])(.*?)\1|(?:[^\s]+'.*?')?([^;\n]*))/i;class LuraphException extends Error{constructor(e){let t=e.map(({param:r,message:o})=>r?`${r}: ${o}`:o).join(" | ");super(`${t}`),p(this,"errors"),this.name=this.constructor.name,this.errors=e}}class Luraph{constructor(e){p(this,"apiKey"),this.apiKey=e}async doRequest(e,t=!1,r=void 0,o=!1){const a=await undici.fetch(new URL(e,"https://api.lura.ph/v1/"),{method:t?"POST":"GET",headers:{"Luraph-API-Key":this.apiKey,"Content-Type":"application/json"},body:JSON.stringify(r)});if(o&&a.ok)return a;const u=await a.text(),n=u.length?JSON.parse(u):{};if(n.warnings)for(const i of n.warnings)console.warn(`Luraph API warning: ${i}`);if(a.ok)return n;{let i=n?.errors;throw i||(i=[{message:"An unknown error occurred",rawBody:n}]),new LuraphException(i)}}getNodes(){return this.doRequest("obfuscate/nodes")}createNewJob(e,t,r,o,a=!1,u=!1){return t=Buffer.from(t).toString("base64"),this.doRequest("obfuscate/new",!0,{node:e,script:t,fileName:r,options:o,useTokens:a,enforceSettings:u})}async getJobStatus(e){const t=await this.doRequest(`obfuscate/status/${e}`);return{success:!t.error,error:t.error}}async downloadResult(e){const t=await this.doRequest(`obfuscate/download/${e}`,!1,void 0,!0),r=f.exec(t.headers.get("content-disposition"))?.[2]||"script-obfuscated.lua";return{data:await t.text(),fileName:r}}}exports.Luraph=Luraph,exports.LuraphException=LuraphException,exports.default=Luraph;