New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More โ†’
Socket
Sign inDemoInstall
Socket

uniqhtt

Package Overview
Dependencies
Maintainers
0
Versions
145
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uniqhtt - npm Package Compare versions

Comparing version 1.0.94 to 1.0.96

edge.d.ts

22

index.js

@@ -1,15 +0,13 @@

"use strict";var ae=Object.create;var Y=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var de=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty;var fe=(y,e)=>{for(var t in e)Y(y,t,{get:e[t],enumerable:!0})},te=(y,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ue(e))!le.call(y,o)&&o!==t&&Y(y,o,{get:()=>e[o],enumerable:!(n=ce(e,o))||n.enumerable});return y};var j=(y,e,t)=>(t=y!=null?ae(de(y)):{},te(e||!y||!y.__esModule?Y(t,"default",{value:y,enumerable:!0}):t,y)),he=y=>te(Y({},"__esModule",{value:!0}),y);var Te={};fe(Te,{Cookie:()=>D,CookieJar:()=>se,FormData:()=>v,Uniqhtt:()=>Z,UniqhttBrowser:()=>N,UniqhttNode:()=>J,UniqhttWorker:()=>z,YuniqCookie:()=>q,default:()=>Ce});module.exports=he(Te);var pe=j(require("buffer/")),{Buffer:Q}=pe,G=class y extends Error{response={};constructor(e,t,n,o,s,a,c){if(super(e),t instanceof Response){let r=t.headers.get("Content-Length");this.response={urls:c||[t.url],data:n,status:t.status,statusText:t.statusText,finalUrl:t.url,cookies:void 0,headers:o,contentType:t.headers.get("Content-Type"),contentLength:r?parseInt(r):void 0,config:s}}else a?this.response={data:n,urls:c||[a.url],status:a?.status,statusText:a?.statusText,finalUrl:a?.url,cookies:void 0,headers:a.headers,contentType:a.contentType,contentLength:a.contentLength?parseInt(a.contentLength):void 0,config:s}:this.response={data:n,urls:c||[],status:t?.status,statusText:t?.statusText,finalUrl:t?.url,cookies:t?.cookies??void 0,headers:o,contentType:void 0,config:s,contentLength:void 0};Object.setPrototypeOf(this,y.prototype)}},I=class{jar=null;fetch;innerFetchOption=["headers","mode","cache","referrerPolicy","integrity","keepalive","compress"];environment="node";maxConcurrency=0;concurrencyDelay=1e3;singleRequestDelay=!1;totalBatchCount=0;isCurrentBatch=!1;currentBatch=0;queueSize=0;MIN_DELAY=100;defaultUserAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";constructor(e){this.fetch=fetch,e?.concurrentOpt&&this.setConcurrentOptions(e.concurrentOpt)}async checkForBatch(){try{this.maxConcurrency>0&&this.singleRequestDelay===!1&&this.isCurrentBatch&&await this.checkForBatchWithDelay()}catch(e){throw new Error(`Batch check failed: ${e.message}`)}}async checkForBatchWithDelay(){let e=Date.now(),t=7*24*60*60*1e3;for(;this.currentBatch>0&&this.isCurrentBatch;){if(Date.now()-e>t)throw new Error("Batch processing timeout exceeded (after 7 days) while waiting for a slot in the concurrency pool.");await this.wait(this.MIN_DELAY)}this.currentBatch=0,this.isCurrentBatch=!1,this.totalBatchCount>0&&this.concurrencyDelay>this.MIN_DELAY&&await this.wait(this.concurrencyDelay)}async rateLimiter(){let e=0,t=0;try{if(this.maxConcurrency>0){if(this.queueSize>0&&this.totalBatchCount+1>=this.queueSize)throw new Error("Request queue is full");this.totalBatchCount+=1,e=1,this.singleRequestDelay===!1?(await this.checkForBatch(),this.currentBatch+=1,t+=1,this.currentBatch>=this.maxConcurrency&&(this.isCurrentBatch=!0)):(await this.waitForMyTurn(),this.currentBatch+=1,t+=1,await this.wait(this.concurrencyDelay))}}catch(n){throw e&&(this.totalBatchCount-=e),t&&(this.currentBatch-=t),new Error(`Rate limiting failed: ${n.message}`)}}async waitForMyTurn(){let e=Date.now(),t=7*24*60*60*1e3;for(;this.currentBatch>=this.maxConcurrency;){if(Date.now()-e>t)throw new Error("Wait timeout exceeded (after 7 days) while waiting for a slot in the concurrency pool.");await this.wait(this.MIN_DELAY)}}removeBatch(){try{this.maxConcurrency>0&&this.totalBatchCount>0&&(this.currentBatch=Math.max(0,this.currentBatch-1),this.totalBatchCount=Math.max(0,this.totalBatchCount-1)),this.totalBatchCount<=0&&(this.totalBatchCount=0,this.isCurrentBatch=!1,this.currentBatch=0),this.currentBatch<=0&&(this.currentBatch=0,this.isCurrentBatch=!1)}catch(e){throw new Error(`Batch removal failed: ${e.message}`)}}setConcurrentOptions(e){if(e.maxConcurrency&&e.maxConcurrency<0)throw new Error("maxConcurrency must be non-negative");if(e.concurrencyDelay&&e.concurrencyDelay<this.MIN_DELAY)throw new Error(`concurrencyDelay must be at least ${this.MIN_DELAY}ms`);if(e.queueSize&&e.queueSize<0)throw new Error("queueSize must be non-negative");if(e.queueSize&&e.queueSize>1e4)throw new Error("queueSize must be less than or equal to 10,000, higher queueSize may cause performance issues. please disable queueSize to have no queue limit.");this.queueSize=e.queueSize||0,this.maxConcurrency=e.maxConcurrency||0,this.concurrencyDelay=e.concurrencyDelay||1e3,this.singleRequestDelay=typeof e.singleRequestDelay=="boolean"?e.singleRequestDelay:!0}wait(e){return new Promise(t=>{setTimeout(t,e)})}setCookies(e,t,n){Array.isArray(e)?this.jar.fromArray(e,n):typeof e=="string"&&(t&&e.includes("; ")?this.jar.parseCookieString(e,t,n):e.includes(`
`)&&e.split(" ").length>3&&this.jar.parseNetscapeCookies(e,n))}async get(e,t){return this.request(e,"GET",void 0,t)}clearCookies(){this.jar?.removeAllCookiesSync()}async post(e,t,n){return this.request(e,"POST",t,n)}async postForm(e,t,n){let o="";if(t instanceof URLSearchParams)o=t.toString();else if(t instanceof FormData){let a=[];for(let[c,r]of t.entries())a.push(`${c}=${r}`);o=a.join("&")}else if(typeof t=="string")o=t;else if(typeof t=="object"){let a=new URLSearchParams;for(let[c,r]of Object.entries(t))a.append(c,r?typeof r=="object"?JSON.stringify(r):r.toString():"");o=a.toString()}let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/x-www-form-urlencoded"),this.request(e,"POST",o,{...n,headers:s,isFormData:!0})}async postJson(e,t,n){let o={};if(typeof t=="string"){if(o=this.parseJson(t),!o)throw this.Error({status:400,statusText:"Bad Request"},"Invalid JSON string")}else o=t;let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/json"),this.request(e,"POST",JSON.stringify(o),{...n,headers:s,isJson:!0})}async put(e,t,n){return this.request(e,"POST",t,n)}async putForm(e,t,n){let o="";if(t instanceof URLSearchParams)o=t.toString();else if(t instanceof FormData){let a=[];for(let[c,r]of t.entries())a.push(`${c}=${r}`);o=a.join("&")}else if(typeof t=="string")o=t;else if(typeof t=="object"){let a=new URLSearchParams;for(let[c,r]of Object.entries(t))a.append(c,r?typeof r=="object"?JSON.stringify(r):r.toString():"");o=a.toString()}let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/x-www-form-urlencoded"),this.request(e,"PUT",o,{...n,headers:s,isFormData:!0})}async putJson(e,t,n){let o={};if(typeof t=="string"){if(o=this.parseJson(t),!o)throw this.Error({status:400,statusText:"Bad Request"},"Invalid JSON string")}else o=t;let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/json"),this.request(e,"PUT",JSON.stringify(o),{...n,headers:s,isJson:!0})}async patch(e,t,n){return this.request(e,"PATCH",t,n)}async patchForm(e,t,n){let o="";if(t instanceof URLSearchParams)o=t.toString();else if(t instanceof FormData){let a=[];for(let[c,r]of t.entries())a.push(`${c}=${r}`);o=a.join("&")}else if(typeof t=="string")o=t;else if(typeof t=="object"){let a=new URLSearchParams;for(let[c,r]of Object.entries(t))a.append(c,r?typeof r=="object"?JSON.stringify(r):r.toString():"");o=a.toString()}let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/x-www-form-urlencoded"),this.request(e,"PATCH",o,{...n,headers:s,isFormData:!0})}async patchJson(e,t,n){let o={};if(typeof t=="string"){if(o=this.parseJson(t),!o)throw this.Error({status:400,statusText:"Bad Request"},"Invalid JSON string")}else o=t;let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/json"),this.request(e,"PATCH",JSON.stringify(o),{...n,headers:s,isJson:!0})}async delete(e,t){return this.request(e,"DELETE",void 0,t)}async head(e,t){return this.request(e,"HEAD",void 0,t)}async options(e,t){return this.request(e,"OPTIONS",void 0,t)}parseJson(e){try{return JSON.parse(e)}catch{return null}}async Error(e,t,n,o){if(e instanceof Response){let s=e.headers.get("Content-Type"),a=await this.parseResponseBody(e,s),c={};return e.headers instanceof Headers&&e.headers.forEach((r,i)=>{i.toLowerCase()!=="set-cookie"&&i.toLowerCase()!=="set-cookies"&&(c[i]=r)}),new G(t??e.statusText??"Unknown error",e,a,c,n,void 0,o)}else if(e.headers){let s=e.body instanceof Q?e?.body:e.body,a=e.headers??{},c=e.contentType??null;return new G(t??e.statusText??"Unknown error",e,s&&c?await this.parseResponseBody(e,c):s?s.toString("utf-8"):null,a,n,e)}return new G(t??"Unknown error",e??{},null,{})}async formatResponse(e,t,n,o,s,a=[]){let c=e instanceof Response?e.headers.get("Content-Type"):e.contentType,r=s?null:n?e instanceof Response?Q.from(await e.arrayBuffer()):e.body:await this.parseResponseBody(e,c),i={},d;if(e instanceof Response){let p=e.headers.get("content-length");e.headers.forEach((u,f)=>{this.environment!=="browser"?f.toLowerCase()!=="set-cookie"&&f.toLowerCase()!=="set-cookies"&&(i[f]=u):i[f]=u}),p&&(d=parseInt(p))}else{let p=e.headers["content-length"];p&&(d=parseInt(p)),i=e.headers}return{urls:a,contentLength:d,data:r,status:e.status,statusText:e.statusText,headers:i,finalUrl:t,cookies:this.environment==="browser"?{array:[],string:"",netscape:""}:{array:this.jar.toArray(),string:this.jar.toCookieString(),netscape:this.jar.toNetscapeFormat()},config:o,contentType:c,...s}}async parseResponseBody(e,t){return t&&t.includes("application/json")?e instanceof Response?await e.json():e.body?JSON.parse(e.body.toString("utf-8")):{}:t&&["text","xml","xhtml+xml","html","php","javascript","ecmascript","x-javascript","typescript","x-httpd-php","x-php","x-python","x-python","x-ruby","x-ruby","x-sh","x-bash","x-java","x-java-source","x-c","x-c++","x-csrc","x-chdr","x-csharp","x-csh","x-go","x-go","x-scala","x-scala","x-rust","rust","x-swift","x-swift","x-kotlin","x-kotlin","x-perl","x-perl","x-lua","x-lua","x-haskell","x-haskell","x-sql","sql","css","csv","plain","markdown","x-markdown","x-latex","x-tex"].some(o=>t.includes(o))?e instanceof Response?await e.text():e.body?e.body.toString("utf-8"):"":e instanceof Response?await e.arrayBuffer():e.body?e.body:Q.alloc(0)}prepareFetchOptions(e,t,n,o,s){let c=["post","put","patch"].includes(n.toLowerCase()),r={others:{}},i=e.headers instanceof Headers?e.headers:new Headers(e.headers||{}),d=e.contentType||i.get("Content-Type")||(c?"application/json":void 0);if(e.headers?r.headers=i instanceof Headers?i:new Headers(i):r.headers=new Headers,this.environment!=="browser"&&i.has("Cookie")){let u=i.get("Cookie");e.withCookies&&this.setCookies(u,t),i.delete("Cookie"),r.headers.delete("Cookie")}e.cookies&&e.withCookies&&this.setCookies(e.cookies,t);let p=[];if(this.environment!=="browser"&&(e.useAllCookies?p=this.jar.getAllCookies(t):p=this.jar.getCookies(t)),e.printHeaders&&(console.log("Cookie: ",p.map(u=>`${u.key}=${u.value}`).join("; ")),console.log("Cookies:",p)),p&&p.length>0&&e.withCookies&&r.headers.set("Cookie",p.map(u=>`${u.key}=${u.value}`).join("; ")),e.body&&(r.body=e.body),e?.debug&&console.log(e.body),e.isFormData||e.isJson)e.isFormData?(r.body=e.body,d="application/x-www-form-urlencoded",r.headers.set("Content-Type",d)):(r.body=e.body,d="application/json",r.headers.set("Content-Type",d));else if(e.json)r.body=JSON.stringify(e.json),d="application/json",r.headers.set("Content-Type",d);else if(e.form_params)r.body=new URLSearchParams(e.form_params).toString(),d="application/x-www-form-urlencoded",r.headers.set("Content-Type",d);else if(e.multipart){let u=new FormData;Object.entries(e.multipart).forEach(([f,w])=>{u.append(f,w)}),r.body=u}else if(e.requestType)switch(e.requestType){case"json":d="application/json",typeof r.body=="object"&&(r.body=JSON.stringify(r.body)),r.headers.set("Content-Type",d);break;case"form":d="application/x-www-form-urlencoded",typeof r.body=="object"&&(r.body=new URLSearchParams(r.body).toString()),r.headers.set("Content-Type",d);break;case"formData":if(typeof r.body=="object"){let u=new FormData;Object.entries(r.body).forEach(([f,w])=>{u.append(f,w)}),r.body=u}break;case"text":d="text/plain",r.headers.set("Content-Type",d);break}else if(d){let u=d.toLowerCase();if(u.includes("json"))r.headers.set("Content-Type","application/json"),r.body&&typeof r.body=="object"&&(r.body=JSON.stringify(r.body));else if(u.includes("x-www-form-urlencoded"))r.headers.set("Content-Type","application/x-www-form-urlencoded"),r.body&&typeof r.body=="object"&&(r.body=new URLSearchParams(r.body).toString());else if(u.includes("multipart")){if(r.body&&typeof r.body=="object"){let f=new FormData;Object.entries(r.body).forEach(([w,T])=>{f.append(w,T)}),r.body=f}}else u.includes("text/plain")&&r.headers.set("Content-Type","text/plain")}else d&&!e.withoutContentType&&r.headers.set("Content-Type",d);e.withoutContentType&&r.headers.delete("Content-Type"),e.withoutBodyOnRedirect&&o&&(r.body=void 0),e.printHeaders&&console.log("Fetch headers:",r.headers),(typeof e.autoSetReferer!="boolean"||e.autoSetReferer)&&s&&r.headers.set("Referer",s);for(let u of this.innerFetchOption)Object.keys(e).includes(u)&&typeof e[u]<"u"&&e[u]!==null&&(r.others[u]=e[u]);return r.credentials||(r.credentials="include"),this.environment!=="browser"&&(r.headers.set("Cache-Control","no-cache, no-store, must-revalidate"),r.headers.set("Pragma","no-cache"),r.headers.set("Expires","0")),typeof e.withCookies=="boolean"&&!e.withCookies&&(r.headers.delete("Cookie"),r.credentials="omit"),r}async getHeaders(e){let t=await this.fetch(e,{method:"HEAD"});return Object.fromEntries(t.headers.entries())}};var $=class{static rotateLeft(e,t){return e<<t|e>>>32-t}static addUnsigned(e,t){let n=e&1073741824,o=t&1073741824,s=e&2147483648,a=t&2147483648,c=(e&1073741823)+(t&1073741823);return n&o?c^2147483648^s^a:n|o?c&1073741824?c^3221225472^s^a:c^1073741824^s^a:c^s^a}static F(e,t,n){return e&t|~e&n}static G(e,t,n){return e&n|t&~n}static H(e,t,n){return e^t^n}static I(e,t,n){return t^(e|~n)}static FF(e,t,n,o,s,a,c){return e=this.addUnsigned(e,this.addUnsigned(this.addUnsigned(this.F(t,n,o),s),c)),this.addUnsigned(this.rotateLeft(e,a),t)}static GG(e,t,n,o,s,a,c){return e=this.addUnsigned(e,this.addUnsigned(this.addUnsigned(this.G(t,n,o),s),c)),this.addUnsigned(this.rotateLeft(e,a),t)}static HH(e,t,n,o,s,a,c){return e=this.addUnsigned(e,this.addUnsigned(this.addUnsigned(this.H(t,n,o),s),c)),this.addUnsigned(this.rotateLeft(e,a),t)}static II(e,t,n,o,s,a,c){return e=this.addUnsigned(e,this.addUnsigned(this.addUnsigned(this.I(t,n,o),s),c)),this.addUnsigned(this.rotateLeft(e,a),t)}static convertToWordArray(e){let t=e.length,n=((t+8>>6)+1)*16,o=Array(n-1),s=0,a=0;for(;a<t;){let r=(a-a%4)/4;s=a%4*8,o[r]=o[r]|e.charCodeAt(a)<<s,a++}let c=(a-a%4)/4;return s=a%4*8,o[c]=o[c]|128<<s,o[n-2]=t<<3,o[n-1]=t>>>29,o}static wordToHex(e){let t="";for(let n=0;n<=3;n++)t+=("0"+(e>>>n*8&255).toString(16)).slice(-2);return t}static md5(e){let t=this.convertToWordArray(e),n=1732584193,o=4023233417,s=2562383102,a=271733878,c=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21],r=[3614090360,3905402710,606105819,3250441966,4118548399,1200080426,2821735955,4249261313,1770035416,2336552879,4294925233,2304563134,1804603682,4254626195,2792965006,1236535329,4129170786,3225465664,643717713,3921069994,3593408605,38016083,3634488961,3889429448,568446438,3275163606,4107603335,1163531501,2850285829,4243563512,1735328473,2368359562,4294588738,2272392833,1839030562,4259657740,2763975236,1272893353,4139469664,3200236656,681279174,3936430074,3572445317,76029189,3654602809,3873151461,530742520,3299628645,4096336452,1126891415,2878612391,4237533241,1700485571,2399980690,4293915773,2240044497,1873313359,4264355552,2734768916,1309151649,4149444226,3174756917,718787259,3951481745];for(let i=0;i<t.length;i+=16){let d=n,p=o,u=s,f=a;n=this.FF(n,o,s,a,t[i],c[0],r[0]),a=this.FF(a,n,o,s,t[i+1],c[1],r[1]),s=this.FF(s,a,n,o,t[i+2],c[2],r[2]),o=this.FF(o,s,a,n,t[i+3],c[3],r[3]),n=this.FF(n,o,s,a,t[i+4],c[4],r[4]),a=this.FF(a,n,o,s,t[i+5],c[5],r[5]),s=this.FF(s,a,n,o,t[i+6],c[6],r[6]),o=this.FF(o,s,a,n,t[i+7],c[7],r[7]),n=this.FF(n,o,s,a,t[i+8],c[8],r[8]),a=this.FF(a,n,o,s,t[i+9],c[9],r[9]),s=this.FF(s,a,n,o,t[i+10],c[10],r[10]),o=this.FF(o,s,a,n,t[i+11],c[11],r[11]),n=this.FF(n,o,s,a,t[i+12],c[12],r[12]),a=this.FF(a,n,o,s,t[i+13],c[13],r[13]),s=this.FF(s,a,n,o,t[i+14],c[14],r[14]),o=this.FF(o,s,a,n,t[i+15],c[15],r[15]),n=this.GG(n,o,s,a,t[i+1],c[16],r[16]),a=this.GG(a,n,o,s,t[i+6],c[17],r[17]),s=this.GG(s,a,n,o,t[i+11],c[18],r[18]),o=this.GG(o,s,a,n,t[i],c[19],r[19]),n=this.GG(n,o,s,a,t[i+5],c[20],r[20]),a=this.GG(a,n,o,s,t[i+10],c[21],r[21]),s=this.GG(s,a,n,o,t[i+15],c[22],r[22]),o=this.GG(o,s,a,n,t[i+4],c[23],r[23]),n=this.GG(n,o,s,a,t[i+9],c[24],r[24]),a=this.GG(a,n,o,s,t[i+14],c[25],r[25]),s=this.GG(s,a,n,o,t[i+3],c[26],r[26]),o=this.GG(o,s,a,n,t[i+8],c[27],r[27]),n=this.GG(n,o,s,a,t[i+13],c[28],r[28]),a=this.GG(a,n,o,s,t[i+2],c[29],r[29]),s=this.GG(s,a,n,o,t[i+7],c[30],r[30]),o=this.GG(o,s,a,n,t[i+12],c[31],r[31]),n=this.HH(n,o,s,a,t[i+5],c[32],r[32]),a=this.HH(a,n,o,s,t[i+8],c[33],r[33]),s=this.HH(s,a,n,o,t[i+11],c[34],r[34]),o=this.HH(o,s,a,n,t[i+14],c[35],r[35]),n=this.HH(n,o,s,a,t[i+1],c[36],r[36]),a=this.HH(a,n,o,s,t[i+4],c[37],r[37]),s=this.HH(s,a,n,o,t[i+7],c[38],r[38]),o=this.HH(o,s,a,n,t[i+10],c[39],r[39]),n=this.HH(n,o,s,a,t[i+13],c[40],r[40]),a=this.HH(a,n,o,s,t[i],c[41],r[41]),s=this.HH(s,a,n,o,t[i+3],c[42],r[42]),o=this.HH(o,s,a,n,t[i+6],c[43],r[43]),n=this.HH(n,o,s,a,t[i+9],c[44],r[44]),a=this.HH(a,n,o,s,t[i+12],c[45],r[45]),s=this.HH(s,a,n,o,t[i+15],c[46],r[46]),o=this.HH(o,s,a,n,t[i+2],c[47],r[47]),n=this.II(n,o,s,a,t[i],c[48],r[48]),a=this.II(a,n,o,s,t[i+7],c[49],r[49]),s=this.II(s,a,n,o,t[i+14],c[50],r[50]),o=this.II(o,s,a,n,t[i+5],c[51],r[51]),n=this.II(n,o,s,a,t[i+12],c[52],r[52]),a=this.II(a,n,o,s,t[i+3],c[53],r[53]),s=this.II(s,a,n,o,t[i+10],c[54],r[54]),o=this.II(o,s,a,n,t[i+1],c[55],r[55]),n=this.II(n,o,s,a,t[i+8],c[56],r[56]),a=this.II(a,n,o,s,t[i+15],c[57],r[57]),s=this.II(s,a,n,o,t[i+6],c[58],r[58]),o=this.II(o,s,a,n,t[i+13],c[59],r[59]),n=this.II(n,o,s,a,t[i+4],c[60],r[60]),a=this.II(a,n,o,s,t[i+11],c[61],r[61]),s=this.II(s,a,n,o,t[i+2],c[62],r[62]),o=this.II(o,s,a,n,t[i+9],c[63],r[63]),n=this.addUnsigned(n,d),o=this.addUnsigned(o,p),s=this.addUnsigned(s,u),a=this.addUnsigned(a,f)}return this.wordToHex(n)+this.wordToHex(o)+this.wordToHex(s)+this.wordToHex(a)}};function ee(y){if(y instanceof Date)return y;if(typeof y=="string"&&y!=="Infinity")return ye(y)?new Date(ne(y)):new Date(y);if(typeof y=="number")return new Date(ne(y))}function ye(y){return/^[0-9]+$/.test(y)}Date.prototype.addDay=function(y){let e=new Date(this);return e.setDate(e.getDate()+y),e};function ne(y){let e=y.toString().trim();try{if(typeof y=="number")return e.length===13?y:y*1e3;let t=parseInt(e);return t.toString().length===13?t:t*1e3}catch{return 0}}var D=class y{key;value;expires;isSession;maxAge;domain;path;secure;httpOnly;extensions;creation;creationIndex;hostOnly;pathIsDefault;lastAccessed;sameSite;plainDomain;accessType;hash;constructor(e){this.isSession=!(e.expires||e.maxAge),e={...e,expires:ee(e.expires)??"Infinity",creation:ee(e.creation),lastAccessed:ee(e.lastAccessed)},this.key=e.key||"",this.value=e.value||"",this.expires=e.expires||null,this.maxAge=e.maxAge||null,this.domain=e.domain||null,this.path=e.path||null,this.secure=e.secure||!1,this.httpOnly=e.httpOnly||!1,this.extensions=e.extensions||null,this.creation=e.creation||new Date,this.creationIndex=y.cookiesCreated++,this.hostOnly=e.hostOnly||null,this.pathIsDefault=e.pathIsDefault||null,this.lastAccessed=e.lastAccessed||new Date,this.sameSite=e.sameSite;let t=e.domain&&e.domain.startsWith(".")?"wildcard":"matchDomainOnly",n=e.path&&e.path!=="/"&&e.path.length>1?"matchPathOnly":"";n&&t==="matchDomainOnly"?this.accessType="matchDomainAndPath":n&&t==="wildcard"?this.accessType="matchPathOnly":t==="matchDomainOnly"?this.accessType="matchDomainOnly":this.accessType="wildcard",this.plainDomain=this.domain?this.domain.startsWith(".")?this.domain.substring(1):this.domain:null,this.hash=this.domain?$.md5(`${this.domain.toString()}_${this.key}`):null}toJSON(){let e={};return y.serializableProperties.forEach(t=>{this[t]!==void 0&&(this[t]instanceof Date?e[t]=this[t].toISOString():e[t]=this[t])}),e}clone(){return y.fromJSON(this.toJSON())}validate(){return!(!this.key||this.key.trim()===""||this.value===void 0||this.expires&&!(this.expires instanceof Date)&&this.expires!=="Infinity"||this.maxAge!==null&&typeof this.maxAge!="number"&&this.maxAge!=="Infinity"&&this.maxAge!=="-Infinity"||this.domain&&typeof this.domain!="string"||this.path&&typeof this.path!="string"||typeof this.secure!="boolean"||typeof this.httpOnly!="boolean"||this.sameSite&&!["Strict","Lax","None"].includes(this.sameSite))}setExpires(e){this.expires=e instanceof Date?e:y.parseDate(e)}setMaxAge(e){this.maxAge=isFinite(e)?e:e===1/0?"Infinity":"-Infinity"}cookieString(){return`${this.key}=${this.value}`}toSetCookieString(){let e=this.cookieString();return this.expires instanceof Date&&(e+=`; Expires=${this.expires.toUTCString()}`),this.maxAge!=null&&(e+=`; Max-Age=${this.maxAge}`),this.domain&&(e+=`; Domain=${this.domain}`),this.path&&(e+=`; Path=${this.path}`),this.secure&&(e+="; Secure"),this.httpOnly&&(e+="; HttpOnly"),this.sameSite&&(e+=`; SameSite=${this.sameSite}`),this.extensions&&(e+=`; ${this.extensions.join("; ")}`),e}toArray(){let e={key:this.key,value:this.value};return this.domain&&(e.domain=this.domain),this.path&&(e.path=this.path),this.secure&&(e.secure=this.secure),this.httpOnly&&(e.httpOnly=this.httpOnly),this.sameSite&&(e.sameSite=this.sameSite),this.extensions&&(e.extensions=this.extensions),this.expires&&(e.expires=this.expires),this.creation&&(e.creation=this.creation),this.lastAccessed&&(e.lastAccessed=this.lastAccessed),this.hostOnly&&(e.hostOnly=this.hostOnly),this.pathIsDefault&&(e.pathIsDefault=this.pathIsDefault),this.hash&&(e.hash=this.hash),this.plainDomain&&(e.plainDomain=this.plainDomain),this.maxAge&&(e.maxAge=this.maxAge),e}toString(){return`${this.key}=${this.value}`}toNetscapeFormat(){let e=this.hostOnly?this.domain:this.domain.startsWith(".")?this.domain:"."+this.domain,t=this.secure?"TRUE":"FALSE",n=this.expires&&typeof this.expires!="string"?Math.round(this.expires.getTime()/1e3):0;return`${e} TRUE ${this.path} ${t} ${n} ${this.key} ${this.value}`}TTL(e=Date.now()){return this.expires==="Infinity"||!this.expires?1/0:Math.max(0,this.expires.getTime()-e)}expiryTime(e=new Date){if(this.maxAge!=null){let t=this.maxAge==="Infinity"?1/0:Number(this.maxAge)*1e3;return(this.lastAccessed instanceof Date?this.lastAccessed:e).getTime()+t}return this.expires instanceof Date?this.expires.getTime():void 0}isPersistent(){return this.expires!=null||this.maxAge!=null}canonicalizedDomain(){return this.domain?y.canonicalDomain(this.domain):void 0}cdomain(){return this.canonicalizedDomain()}static parse(e,t={}){try{let n=e.split(";").map(u=>u.trim()),[o,...s]=n,[a,...c]=o.split("=").map(u=>u.trim()),r=c.join("=");if(!a&&!t.loose)return;let i=new y({key:a,value:r});s.forEach(u=>{let[f,w]=u.split("=").map(T=>T.trim());switch(f.toLowerCase()){case"expires":i.expires=y.parseDate(w);break;case"max-age":i.setMaxAge(parseInt(w,10));break;case"domain":i.domain=w;break;case"path":i.path=w;break;case"secure":i.secure=!0;break;case"httponly":i.httpOnly=!0;break;case"samesite":i.sameSite=w;break;default:i.extensions||(i.extensions=[]),i.extensions.push(u)}}),i.isSession=!i.expires;let d=i.domain&&i.domain.startsWith(".")?"wildcard":"matchDomainOnly",p=i.path&&i.path!=="/"&&i.path.length>1?"matchPathOnly":"";return p&&d==="matchDomainOnly"?i.accessType="matchDomainAndPath":p&&d==="wildcard"?i.accessType="matchPathOnly":d==="matchDomainOnly"?i.accessType="matchDomainOnly":i.accessType="wildcard",i}catch{return}}static fromJSONString(e){if(typeof e=="string")try{e=JSON.parse(e)}catch{return}if(typeof e!="object"||e===null)return;let t={};return y.serializableProperties.forEach(n=>{e[n]!==void 0&&(n==="expires"||n==="creation"||n==="lastAccessed"?t[n]=new Date(e[n]):t[n]=e[n])}),new y(t)}static fromJSON(e){if(typeof e=="object"&&e!==null)try{return new y(e)}catch{return}}static parseDate(e){return new Date(e)}static canonicalDomain(e){return e.toLowerCase()}static cookiesCreated=0;static defaultPath="/";static sameSiteLevel={strict:3,lax:2,none:1};static sameSiteCanonical={strict:"Strict",lax:"Lax"};static serializableProperties=["key","value","expires","maxAge","domain","path","secure","httpOnly","extensions","hostOnly","pathIsDefault","creation","lastAccessed","sameSite"];isDomainMatch(e,t){return e=this.isValidUrl(e)?new URL(e).hostname:e,this.isDomainMatching(t,e)}inDomain(e,t=!0){return this.domain?this.isValidUrl(e)?this.isMatched(e,this.domain):this.isDomainMatch(e,this.domain):t}isMatched(e,t){let n=new URL(e).pathname;return n=n.endsWith("/")?n:`${n}/`,e=new URL(e).hostname,this.accessType==="wildcard"?this.isDomainMatching(t,e):this.accessType==="matchDomainAndPath"&&this.isDomainMatching(t,e)&&this.isPathMatching(this.path??"/",n)||this.accessType==="matchPathOnly"&&this.isPathMatching(this.path??"/",n)?!0:!!(this.accessType==="matchDomainOnly"&&this.isDomainMatching(t,e))}isDomainMatching(e,t){if(e=e.toLowerCase(),t=t.toLowerCase(),!e.startsWith("."))return e===t;let n=e.slice(1);return t===n||t.endsWith("."+n)}isPathMatching(e,t){let n=this.normalizePath(e);return t.startsWith("/")||(t="/"+t),t.startsWith(n)}normalizePath(e){let t=e.trim();return(t==="."||t==="./")&&(t="/"),t.startsWith("/")||(t="/"+t),t.length>1&&t.endsWith("/")&&(t=t.slice(0,-1)),t}isValidUrl(e){try{return new URL(e),e.startsWith("http")||e.startsWith("https")}catch{return!1}}};var q=class{constructor(e=!1){this.debug=e}cookies=[];setCookieSync(e,t,n=!0){let o=this.getDomain(t);if(!o)return;e.domain=e.domain?e.domain:o;let s=e.domain?$.md5(`${e.domain.toString()}_${e.key}`):null;e.lastAccessed=new Date;let a=!1;if(s&&this.cookies.find(c=>c.hash===s)){if(n){let c=this.cookies.find(r=>r.hash===s);c&&(e.creationIndex=c.creationIndex,e.creation=c.creation),this.cookies=this.cookies.filter(r=>r.hash!==s)}a=!0}a||(e.creationIndex=this.cookies.length),s&&(e.hash=s),(!a||n)&&this.cookies.push(e),this.removeExpiredCookies()}setResponseCookies(e,t){if(e instanceof Response)if(e?.headers&&typeof e.headers?.getSetCookie<"u")for(let o of e.headers.getSetCookie()){let s=D.parse(o.trim());s&&this.setCookieSync(s,t)}else{let o=e?.headers?.get("set-cookie");o&&o.split(",").forEach(s=>{let a=D.parse(s);a&&this.setCookieSync(a,t)})}else Array.isArray(e)?typeof e[0]=="string"?e.forEach(n=>{let o=D.parse(n.trim());o&&this.setCookieSync(o,t)}):e[0]instanceof D?e.forEach(n=>this.setCookieSync(n,t)):e.forEach(n=>{let o=D.fromJSON(n);o&&this.setCookieSync(o,t)}):typeof e=="string"&&e.includes("=")&&e.includes(",")&&e.split(",").forEach(n=>{let o=D.parse(n);o&&this.setCookieSync(o,t)})}toNetscapeFormat(e){this.removeExpiredCookies();let t=`# Netscape HTTP Cookie File
"use strict";var oe=Object.create;var _=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,ue=Object.prototype.hasOwnProperty;var le=(p,e)=>{for(var t in e)_(p,t,{get:e[t],enumerable:!0})},ee=(p,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ae(e))!ue.call(p,s)&&s!==t&&_(p,s,{get:()=>e[s],enumerable:!(n=re(e,s))||n.enumerable});return p};var F=(p,e,t)=>(t=p!=null?oe(ce(p)):{},ee(e||!p||!p.__esModule?_(t,"default",{value:p,enumerable:!0}):t,p)),de=p=>ee(_({},"__esModule",{value:!0}),p);var Re={};le(Re,{Cookie:()=>U,CookieJar:()=>ne,FormData:()=>E,Uniqhtt:()=>Z,UniqhttEdge:()=>M,UniqhttNode:()=>j,YuniqCookie:()=>P,default:()=>be});module.exports=de(Re);var W=require("node:buffer"),z=class p extends Error{response={};constructor(e,t,n,s,i,r,a){if(super(e),t instanceof Response){let c=t.headers.get("Content-Length");this.response={urls:a||[t.url],data:n,status:t.status,statusText:t.statusText,finalUrl:t.url,cookies:void 0,headers:s,contentType:t.headers.get("Content-Type"),contentLength:c?parseInt(c):void 0,config:i}}else r?this.response={data:n,urls:a||[r.url],status:r?.status,statusText:r?.statusText,finalUrl:r?.url,cookies:void 0,headers:r.headers,contentType:r.contentType,contentLength:r.contentLength?parseInt(r.contentLength):void 0,config:i}:this.response={data:n,urls:a||[],status:t?.status,statusText:t?.statusText,finalUrl:t?.url,cookies:t?.cookies??void 0,headers:s,contentType:void 0,config:i,contentLength:void 0};Object.setPrototypeOf(this,p.prototype)}},A=class{jar=null;fetch;innerFetchOption=["headers","mode","cache","referrerPolicy","integrity","keepalive","compress"];environment="node";maxConcurrency=0;concurrencyDelay=1e3;singleRequestDelay=!1;totalBatchCount=0;isCurrentBatch=!1;currentBatch=0;queueSize=0;MIN_DELAY=100;defaultUserAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";constructor(e){this.fetch=fetch,e?.concurrentOpt&&this.setConcurrentOptions(e.concurrentOpt)}async checkForBatch(){try{this.maxConcurrency>0&&this.singleRequestDelay===!1&&this.isCurrentBatch&&await this.checkForBatchWithDelay()}catch(e){throw new Error(`Batch check failed: ${e.message}`)}}async checkForBatchWithDelay(){let e=Date.now(),t=7*24*60*60*1e3;for(;this.currentBatch>0&&this.isCurrentBatch;){if(Date.now()-e>t)throw new Error("Batch processing timeout exceeded (after 7 days) while waiting for a slot in the concurrency pool.");await this.wait(this.MIN_DELAY)}this.currentBatch=0,this.isCurrentBatch=!1,this.totalBatchCount>0&&this.concurrencyDelay>this.MIN_DELAY&&await this.wait(this.concurrencyDelay)}async rateLimiter(){let e=0,t=0;try{if(this.maxConcurrency>0){if(this.queueSize>0&&this.totalBatchCount+1>=this.queueSize)throw new Error("Request queue is full");this.totalBatchCount+=1,e=1,this.singleRequestDelay===!1?(await this.checkForBatch(),this.currentBatch+=1,t+=1,this.currentBatch>=this.maxConcurrency&&(this.isCurrentBatch=!0)):(await this.waitForMyTurn(),this.currentBatch+=1,t+=1,await this.wait(this.concurrencyDelay))}}catch(n){throw e&&(this.totalBatchCount-=e),t&&(this.currentBatch-=t),new Error(`Rate limiting failed: ${n.message}`)}}async waitForMyTurn(){let e=Date.now(),t=7*24*60*60*1e3;for(;this.currentBatch>=this.maxConcurrency;){if(Date.now()-e>t)throw new Error("Wait timeout exceeded (after 7 days) while waiting for a slot in the concurrency pool.");await this.wait(this.MIN_DELAY)}}removeBatch(){try{this.maxConcurrency>0&&this.totalBatchCount>0&&(this.currentBatch=Math.max(0,this.currentBatch-1),this.totalBatchCount=Math.max(0,this.totalBatchCount-1)),this.totalBatchCount<=0&&(this.totalBatchCount=0,this.isCurrentBatch=!1,this.currentBatch=0),this.currentBatch<=0&&(this.currentBatch=0,this.isCurrentBatch=!1)}catch(e){throw new Error(`Batch removal failed: ${e.message}`)}}setConcurrentOptions(e){if(e.maxConcurrency&&e.maxConcurrency<0)throw new Error("maxConcurrency must be non-negative");if(e.concurrencyDelay&&e.concurrencyDelay<this.MIN_DELAY)throw new Error(`concurrencyDelay must be at least ${this.MIN_DELAY}ms`);if(e.queueSize&&e.queueSize<0)throw new Error("queueSize must be non-negative");if(e.queueSize&&e.queueSize>1e4)throw new Error("queueSize must be less than or equal to 10,000, higher queueSize may cause performance issues. please disable queueSize to have no queue limit.");this.queueSize=e.queueSize||0,this.maxConcurrency=e.maxConcurrency||0,this.concurrencyDelay=e.concurrencyDelay||1e3,this.singleRequestDelay=typeof e.singleRequestDelay=="boolean"?e.singleRequestDelay:!0}wait(e){return new Promise(t=>{setTimeout(t,e)})}setCookies(e,t,n){Array.isArray(e)?this.jar.fromArray(e,n):typeof e=="string"&&(t&&e.includes("; ")?this.jar.parseCookieString(e,t,n):e.includes(`
`)&&e.split(" ").length>3&&this.jar.parseNetscapeCookies(e,n))}async get(e,t){return this.request(e,"GET",void 0,t)}clearCookies(){this.jar?.removeAllCookiesSync()}async post(e,t,n){return this.request(e,"POST",t,n)}async postForm(e,t,n){let s="";if(t instanceof URLSearchParams)s=t.toString();else if(t instanceof FormData){let r=[];for(let[a,c]of t.entries())r.push(`${a}=${c}`);s=r.join("&")}else if(typeof t=="string")s=t;else if(typeof t=="object"){let r=new URLSearchParams;for(let[a,c]of Object.entries(t))r.append(a,c?typeof c=="object"?JSON.stringify(c):c.toString():"");s=r.toString()}let i=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return i.set("Content-Type","application/x-www-form-urlencoded"),this.request(e,"POST",s,{...n,headers:i,isFormData:!0})}async postJson(e,t,n){let s={};if(typeof t=="string"){if(s=this.parseJson(t),!s)throw this.Error({status:400,statusText:"Bad Request"},"Invalid JSON string")}else s=t;let i=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return i.set("Content-Type","application/json"),this.request(e,"POST",JSON.stringify(s),{...n,headers:i,isJson:!0})}async put(e,t,n){return this.request(e,"POST",t,n)}async putForm(e,t,n){let s="";if(t instanceof URLSearchParams)s=t.toString();else if(t instanceof FormData){let r=[];for(let[a,c]of t.entries())r.push(`${a}=${c}`);s=r.join("&")}else if(typeof t=="string")s=t;else if(typeof t=="object"){let r=new URLSearchParams;for(let[a,c]of Object.entries(t))r.append(a,c?typeof c=="object"?JSON.stringify(c):c.toString():"");s=r.toString()}let i=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return i.set("Content-Type","application/x-www-form-urlencoded"),this.request(e,"PUT",s,{...n,headers:i,isFormData:!0})}async putJson(e,t,n){let s={};if(typeof t=="string"){if(s=this.parseJson(t),!s)throw this.Error({status:400,statusText:"Bad Request"},"Invalid JSON string")}else s=t;let i=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return i.set("Content-Type","application/json"),this.request(e,"PUT",JSON.stringify(s),{...n,headers:i,isJson:!0})}async patch(e,t,n){return this.request(e,"PATCH",t,n)}async patchForm(e,t,n){let s="";if(t instanceof URLSearchParams)s=t.toString();else if(t instanceof FormData){let r=[];for(let[a,c]of t.entries())r.push(`${a}=${c}`);s=r.join("&")}else if(typeof t=="string")s=t;else if(typeof t=="object"){let r=new URLSearchParams;for(let[a,c]of Object.entries(t))r.append(a,c?typeof c=="object"?JSON.stringify(c):c.toString():"");s=r.toString()}let i=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return i.set("Content-Type","application/x-www-form-urlencoded"),this.request(e,"PATCH",s,{...n,headers:i,isFormData:!0})}async patchJson(e,t,n){let s={};if(typeof t=="string"){if(s=this.parseJson(t),!s)throw this.Error({status:400,statusText:"Bad Request"},"Invalid JSON string")}else s=t;let i=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return i.set("Content-Type","application/json"),this.request(e,"PATCH",JSON.stringify(s),{...n,headers:i,isJson:!0})}async delete(e,t){return this.request(e,"DELETE",void 0,t)}async head(e,t){return this.request(e,"HEAD",void 0,t)}async options(e,t){return this.request(e,"OPTIONS",void 0,t)}parseJson(e){try{return JSON.parse(e)}catch{return null}}async Error(e,t,n,s){if(e instanceof Response){let i=e.headers.get("Content-Type"),r=await this.parseResponseBody(e,i),a={};return e.headers instanceof Headers&&e.headers.forEach((c,o)=>{o.toLowerCase()!=="set-cookie"&&o.toLowerCase()!=="set-cookies"&&(a[o]=c)}),new z(t??e.statusText??"Unknown error",e,r,a,n,void 0,s)}else if(e.headers){let i=e.body instanceof W.Buffer?e?.body:e.body,r=e.headers??{},a=e.contentType??null;return new z(t??e.statusText??"Unknown error",e,i&&a?await this.parseResponseBody(e,a):i?i.toString("utf-8"):null,r,n,e)}return new z(t??"Unknown error",e??{},null,{})}async formatResponse(e,t,n,s,i,r=[]){let a=e instanceof Response?e.headers.get("Content-Type"):e.contentType,c=i?null:n?e instanceof Response?W.Buffer.from(await e.arrayBuffer()):e.body:await this.parseResponseBody(e,a),o={},g;if(e instanceof Response){let m=e.headers.get("content-length");e.headers.forEach((u,h)=>{o[h]=u}),m&&(g=parseInt(m))}else{let m=e.headers["content-length"];m&&(g=parseInt(m)),o=e.headers}return{urls:r,contentLength:g,data:c,status:e.status,statusText:e.statusText,headers:o,finalUrl:t,cookies:{array:this.jar.toArray(),string:this.jar.toCookieString(),netscape:this.jar.toNetscapeFormat()},config:s,contentType:a,...i}}async parseResponseBody(e,t){return t&&t.includes("application/json")?e instanceof Response?await e.json():e.body?JSON.parse(e.body.toString("utf-8")):{}:t&&["text","xml","xhtml+xml","html","php","javascript","ecmascript","x-javascript","typescript","x-httpd-php","x-php","x-python","x-python","x-ruby","x-ruby","x-sh","x-bash","x-java","x-java-source","x-c","x-c++","x-csrc","x-chdr","x-csharp","x-csh","x-go","x-go","x-scala","x-scala","x-rust","rust","x-swift","x-swift","x-kotlin","x-kotlin","x-perl","x-perl","x-lua","x-lua","x-haskell","x-haskell","x-sql","sql","css","csv","plain","markdown","x-markdown","x-latex","x-tex"].some(s=>t.includes(s))?e instanceof Response?await e.text():e.body?e.body.toString("utf-8"):"":e instanceof Response?await e.arrayBuffer():e.body?e.body:W.Buffer.alloc(0)}async getHeaders(e){let t=await this.fetch(e,{method:"HEAD"});return Object.fromEntries(t.headers.entries())}};var I=class{static rotateLeft(e,t){return e<<t|e>>>32-t}static addUnsigned(e,t){let n=e&1073741824,s=t&1073741824,i=e&2147483648,r=t&2147483648,a=(e&1073741823)+(t&1073741823);return n&s?a^2147483648^i^r:n|s?a&1073741824?a^3221225472^i^r:a^1073741824^i^r:a^i^r}static F(e,t,n){return e&t|~e&n}static G(e,t,n){return e&n|t&~n}static H(e,t,n){return e^t^n}static I(e,t,n){return t^(e|~n)}static FF(e,t,n,s,i,r,a){return e=this.addUnsigned(e,this.addUnsigned(this.addUnsigned(this.F(t,n,s),i),a)),this.addUnsigned(this.rotateLeft(e,r),t)}static GG(e,t,n,s,i,r,a){return e=this.addUnsigned(e,this.addUnsigned(this.addUnsigned(this.G(t,n,s),i),a)),this.addUnsigned(this.rotateLeft(e,r),t)}static HH(e,t,n,s,i,r,a){return e=this.addUnsigned(e,this.addUnsigned(this.addUnsigned(this.H(t,n,s),i),a)),this.addUnsigned(this.rotateLeft(e,r),t)}static II(e,t,n,s,i,r,a){return e=this.addUnsigned(e,this.addUnsigned(this.addUnsigned(this.I(t,n,s),i),a)),this.addUnsigned(this.rotateLeft(e,r),t)}static convertToWordArray(e){let t=e.length,n=((t+8>>6)+1)*16,s=Array(n-1),i=0,r=0;for(;r<t;){let c=(r-r%4)/4;i=r%4*8,s[c]=s[c]|e.charCodeAt(r)<<i,r++}let a=(r-r%4)/4;return i=r%4*8,s[a]=s[a]|128<<i,s[n-2]=t<<3,s[n-1]=t>>>29,s}static wordToHex(e){let t="";for(let n=0;n<=3;n++)t+=("0"+(e>>>n*8&255).toString(16)).slice(-2);return t}static md5(e){let t=this.convertToWordArray(e),n=1732584193,s=4023233417,i=2562383102,r=271733878,a=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21],c=[3614090360,3905402710,606105819,3250441966,4118548399,1200080426,2821735955,4249261313,1770035416,2336552879,4294925233,2304563134,1804603682,4254626195,2792965006,1236535329,4129170786,3225465664,643717713,3921069994,3593408605,38016083,3634488961,3889429448,568446438,3275163606,4107603335,1163531501,2850285829,4243563512,1735328473,2368359562,4294588738,2272392833,1839030562,4259657740,2763975236,1272893353,4139469664,3200236656,681279174,3936430074,3572445317,76029189,3654602809,3873151461,530742520,3299628645,4096336452,1126891415,2878612391,4237533241,1700485571,2399980690,4293915773,2240044497,1873313359,4264355552,2734768916,1309151649,4149444226,3174756917,718787259,3951481745];for(let o=0;o<t.length;o+=16){let g=n,m=s,u=i,h=r;n=this.FF(n,s,i,r,t[o],a[0],c[0]),r=this.FF(r,n,s,i,t[o+1],a[1],c[1]),i=this.FF(i,r,n,s,t[o+2],a[2],c[2]),s=this.FF(s,i,r,n,t[o+3],a[3],c[3]),n=this.FF(n,s,i,r,t[o+4],a[4],c[4]),r=this.FF(r,n,s,i,t[o+5],a[5],c[5]),i=this.FF(i,r,n,s,t[o+6],a[6],c[6]),s=this.FF(s,i,r,n,t[o+7],a[7],c[7]),n=this.FF(n,s,i,r,t[o+8],a[8],c[8]),r=this.FF(r,n,s,i,t[o+9],a[9],c[9]),i=this.FF(i,r,n,s,t[o+10],a[10],c[10]),s=this.FF(s,i,r,n,t[o+11],a[11],c[11]),n=this.FF(n,s,i,r,t[o+12],a[12],c[12]),r=this.FF(r,n,s,i,t[o+13],a[13],c[13]),i=this.FF(i,r,n,s,t[o+14],a[14],c[14]),s=this.FF(s,i,r,n,t[o+15],a[15],c[15]),n=this.GG(n,s,i,r,t[o+1],a[16],c[16]),r=this.GG(r,n,s,i,t[o+6],a[17],c[17]),i=this.GG(i,r,n,s,t[o+11],a[18],c[18]),s=this.GG(s,i,r,n,t[o],a[19],c[19]),n=this.GG(n,s,i,r,t[o+5],a[20],c[20]),r=this.GG(r,n,s,i,t[o+10],a[21],c[21]),i=this.GG(i,r,n,s,t[o+15],a[22],c[22]),s=this.GG(s,i,r,n,t[o+4],a[23],c[23]),n=this.GG(n,s,i,r,t[o+9],a[24],c[24]),r=this.GG(r,n,s,i,t[o+14],a[25],c[25]),i=this.GG(i,r,n,s,t[o+3],a[26],c[26]),s=this.GG(s,i,r,n,t[o+8],a[27],c[27]),n=this.GG(n,s,i,r,t[o+13],a[28],c[28]),r=this.GG(r,n,s,i,t[o+2],a[29],c[29]),i=this.GG(i,r,n,s,t[o+7],a[30],c[30]),s=this.GG(s,i,r,n,t[o+12],a[31],c[31]),n=this.HH(n,s,i,r,t[o+5],a[32],c[32]),r=this.HH(r,n,s,i,t[o+8],a[33],c[33]),i=this.HH(i,r,n,s,t[o+11],a[34],c[34]),s=this.HH(s,i,r,n,t[o+14],a[35],c[35]),n=this.HH(n,s,i,r,t[o+1],a[36],c[36]),r=this.HH(r,n,s,i,t[o+4],a[37],c[37]),i=this.HH(i,r,n,s,t[o+7],a[38],c[38]),s=this.HH(s,i,r,n,t[o+10],a[39],c[39]),n=this.HH(n,s,i,r,t[o+13],a[40],c[40]),r=this.HH(r,n,s,i,t[o],a[41],c[41]),i=this.HH(i,r,n,s,t[o+3],a[42],c[42]),s=this.HH(s,i,r,n,t[o+6],a[43],c[43]),n=this.HH(n,s,i,r,t[o+9],a[44],c[44]),r=this.HH(r,n,s,i,t[o+12],a[45],c[45]),i=this.HH(i,r,n,s,t[o+15],a[46],c[46]),s=this.HH(s,i,r,n,t[o+2],a[47],c[47]),n=this.II(n,s,i,r,t[o],a[48],c[48]),r=this.II(r,n,s,i,t[o+7],a[49],c[49]),i=this.II(i,r,n,s,t[o+14],a[50],c[50]),s=this.II(s,i,r,n,t[o+5],a[51],c[51]),n=this.II(n,s,i,r,t[o+12],a[52],c[52]),r=this.II(r,n,s,i,t[o+3],a[53],c[53]),i=this.II(i,r,n,s,t[o+10],a[54],c[54]),s=this.II(s,i,r,n,t[o+1],a[55],c[55]),n=this.II(n,s,i,r,t[o+8],a[56],c[56]),r=this.II(r,n,s,i,t[o+15],a[57],c[57]),i=this.II(i,r,n,s,t[o+6],a[58],c[58]),s=this.II(s,i,r,n,t[o+13],a[59],c[59]),n=this.II(n,s,i,r,t[o+4],a[60],c[60]),r=this.II(r,n,s,i,t[o+11],a[61],c[61]),i=this.II(i,r,n,s,t[o+2],a[62],c[62]),s=this.II(s,i,r,n,t[o+9],a[63],c[63]),n=this.addUnsigned(n,g),s=this.addUnsigned(s,m),i=this.addUnsigned(i,u),r=this.addUnsigned(r,h)}return this.wordToHex(n)+this.wordToHex(s)+this.wordToHex(i)+this.wordToHex(r)}};function V(p){if(p instanceof Date)return p;if(typeof p=="string"&&p!=="Infinity")return he(p)?new Date(te(p)):new Date(p);if(typeof p=="number")return new Date(te(p))}function he(p){return/^[0-9]+$/.test(p)}Date.prototype.addDay=function(p){let e=new Date(this);return e.setDate(e.getDate()+p),e};function te(p){let e=p.toString().trim();try{if(typeof p=="number")return e.length===13?p:p*1e3;let t=parseInt(e);return t.toString().length===13?t:t*1e3}catch{return 0}}var U=class p{key;value;expires;isSession;maxAge;domain;path;secure;httpOnly;extensions;creation;creationIndex;hostOnly;pathIsDefault;lastAccessed;sameSite;plainDomain;accessType;hash;constructor(e){this.isSession=!(e.expires||e.maxAge),e={...e,expires:V(e.expires)??"Infinity",creation:V(e.creation),lastAccessed:V(e.lastAccessed)},this.key=e.key||"",this.value=e.value||"",this.expires=e.expires||null,this.maxAge=e.maxAge||null,this.domain=e.domain||null,this.path=e.path||null,this.secure=e.secure||!1,this.httpOnly=e.httpOnly||!1,this.extensions=e.extensions||null,this.creation=e.creation||new Date,this.creationIndex=p.cookiesCreated++,this.hostOnly=e.hostOnly||null,this.pathIsDefault=e.pathIsDefault||null,this.lastAccessed=e.lastAccessed||new Date,this.sameSite=e.sameSite;let t=e.domain&&e.domain.startsWith(".")?"wildcard":"matchDomainOnly",n=e.path&&e.path!=="/"&&e.path.length>1?"matchPathOnly":"";n&&t==="matchDomainOnly"?this.accessType="matchDomainAndPath":n&&t==="wildcard"?this.accessType="matchPathOnly":t==="matchDomainOnly"?this.accessType="matchDomainOnly":this.accessType="wildcard",this.plainDomain=this.domain?this.domain.startsWith(".")?this.domain.substring(1):this.domain:null,this.hash=this.domain?I.md5(`${this.domain.toString()}_${this.key}`):null}toJSON(){let e={};return p.serializableProperties.forEach(t=>{this[t]!==void 0&&(this[t]instanceof Date?e[t]=this[t].toISOString():e[t]=this[t])}),e}clone(){return p.fromJSON(this.toJSON())}validate(){return!(!this.key||this.key.trim()===""||this.value===void 0||this.expires&&!(this.expires instanceof Date)&&this.expires!=="Infinity"||this.maxAge!==null&&typeof this.maxAge!="number"&&this.maxAge!=="Infinity"&&this.maxAge!=="-Infinity"||this.domain&&typeof this.domain!="string"||this.path&&typeof this.path!="string"||typeof this.secure!="boolean"||typeof this.httpOnly!="boolean"||this.sameSite&&!["Strict","Lax","None"].includes(this.sameSite))}setExpires(e){this.expires=e instanceof Date?e:p.parseDate(e)}setMaxAge(e){this.maxAge=isFinite(e)?e:e===1/0?"Infinity":"-Infinity"}cookieString(){return`${this.key}=${this.value}`}toSetCookieString(){let e=this.cookieString();return this.expires instanceof Date&&(e+=`; Expires=${this.expires.toUTCString()}`),this.maxAge!=null&&(e+=`; Max-Age=${this.maxAge}`),this.domain&&(e+=`; Domain=${this.domain}`),this.path&&(e+=`; Path=${this.path}`),this.secure&&(e+="; Secure"),this.httpOnly&&(e+="; HttpOnly"),this.sameSite&&(e+=`; SameSite=${this.sameSite}`),this.extensions&&(e+=`; ${this.extensions.join("; ")}`),e}toArray(){let e={key:this.key,value:this.value};return this.domain&&(e.domain=this.domain),this.path&&(e.path=this.path),this.secure&&(e.secure=this.secure),this.httpOnly&&(e.httpOnly=this.httpOnly),this.sameSite&&(e.sameSite=this.sameSite),this.extensions&&(e.extensions=this.extensions),this.expires&&(e.expires=this.expires),this.creation&&(e.creation=this.creation),this.lastAccessed&&(e.lastAccessed=this.lastAccessed),this.hostOnly&&(e.hostOnly=this.hostOnly),this.pathIsDefault&&(e.pathIsDefault=this.pathIsDefault),this.hash&&(e.hash=this.hash),this.plainDomain&&(e.plainDomain=this.plainDomain),this.maxAge&&(e.maxAge=this.maxAge),e}toString(){return`${this.key}=${this.value}`}toNetscapeFormat(){let e=this.hostOnly?this.domain:this.domain.startsWith(".")?this.domain:"."+this.domain,t=this.secure?"TRUE":"FALSE",n=this.expires&&typeof this.expires!="string"?Math.round(this.expires.getTime()/1e3):0;return`${e} TRUE ${this.path} ${t} ${n} ${this.key} ${this.value}`}TTL(e=Date.now()){return this.expires==="Infinity"||!this.expires?1/0:Math.max(0,this.expires.getTime()-e)}expiryTime(e=new Date){if(this.maxAge!=null){let t=this.maxAge==="Infinity"?1/0:Number(this.maxAge)*1e3;return(this.lastAccessed instanceof Date?this.lastAccessed:e).getTime()+t}return this.expires instanceof Date?this.expires.getTime():void 0}isPersistent(){return this.expires!=null||this.maxAge!=null}canonicalizedDomain(){return this.domain?p.canonicalDomain(this.domain):void 0}cdomain(){return this.canonicalizedDomain()}static parse(e,t={}){try{let n=e.split(";").map(u=>u.trim()),[s,...i]=n,[r,...a]=s.split("=").map(u=>u.trim()),c=a.join("=");if(!r&&!t.loose)return;let o=new p({key:r,value:c});i.forEach(u=>{let[h,C]=u.split("=").map(k=>k.trim());switch(h.toLowerCase()){case"expires":o.expires=p.parseDate(C);break;case"max-age":o.setMaxAge(parseInt(C,10));break;case"domain":o.domain=C;break;case"path":o.path=C;break;case"secure":o.secure=!0;break;case"httponly":o.httpOnly=!0;break;case"samesite":o.sameSite=C;break;default:o.extensions||(o.extensions=[]),o.extensions.push(u)}}),o.isSession=!o.expires;let g=o.domain&&o.domain.startsWith(".")?"wildcard":"matchDomainOnly",m=o.path&&o.path!=="/"&&o.path.length>1?"matchPathOnly":"";return m&&g==="matchDomainOnly"?o.accessType="matchDomainAndPath":m&&g==="wildcard"?o.accessType="matchPathOnly":g==="matchDomainOnly"?o.accessType="matchDomainOnly":o.accessType="wildcard",o}catch{return}}static fromJSONString(e){if(typeof e=="string")try{e=JSON.parse(e)}catch{return}if(typeof e!="object"||e===null)return;let t={};return p.serializableProperties.forEach(n=>{e[n]!==void 0&&(n==="expires"||n==="creation"||n==="lastAccessed"?t[n]=new Date(e[n]):t[n]=e[n])}),new p(t)}static fromJSON(e){if(typeof e=="object"&&e!==null)try{return new p(e)}catch{return}}static parseDate(e){return new Date(e)}static canonicalDomain(e){return e.toLowerCase()}static cookiesCreated=0;static defaultPath="/";static sameSiteLevel={strict:3,lax:2,none:1};static sameSiteCanonical={strict:"Strict",lax:"Lax"};static serializableProperties=["key","value","expires","maxAge","domain","path","secure","httpOnly","extensions","hostOnly","pathIsDefault","creation","lastAccessed","sameSite"];isDomainMatch(e,t){return e=this.isValidUrl(e)?new URL(e).hostname:e,this.isDomainMatching(t,e)}inDomain(e,t=!0){return this.domain?this.isValidUrl(e)?this.isMatched(e,this.domain):this.isDomainMatch(e,this.domain):t}isMatched(e,t){let n=new URL(e).pathname;return n=n.endsWith("/")?n:`${n}/`,e=new URL(e).hostname,this.accessType==="wildcard"?this.isDomainMatching(t,e):this.accessType==="matchDomainAndPath"&&this.isDomainMatching(t,e)&&this.isPathMatching(this.path??"/",n)||this.accessType==="matchPathOnly"&&this.isPathMatching(this.path??"/",n)?!0:!!(this.accessType==="matchDomainOnly"&&this.isDomainMatching(t,e))}isDomainMatching(e,t){if(e=e.toLowerCase(),t=t.toLowerCase(),!e.startsWith("."))return e===t;let n=e.slice(1);return t===n||t.endsWith("."+n)}isPathMatching(e,t){let n=this.normalizePath(e);return t.startsWith("/")||(t="/"+t),t.startsWith(n)}normalizePath(e){let t=e.trim();return(t==="."||t==="./")&&(t="/"),t.startsWith("/")||(t="/"+t),t.length>1&&t.endsWith("/")&&(t=t.slice(0,-1)),t}isValidUrl(e){try{return new URL(e),e.startsWith("http")||e.startsWith("https")}catch{return!1}}};var P=class{constructor(e=!1){this.debug=e}cookies=[];setCookieSync(e,t,n=!0){let s=this.getDomain(t);if(!s)return;e.domain=e.domain?e.domain:s;let i=e.domain?I.md5(`${e.domain.toString()}_${e.key}`):null;e.lastAccessed=new Date;let r=!1;if(i&&this.cookies.find(a=>a.hash===i)){if(n){let a=this.cookies.find(c=>c.hash===i);a&&(e.creationIndex=a.creationIndex,e.creation=a.creation),this.cookies=this.cookies.filter(c=>c.hash!==i)}r=!0}r||(e.creationIndex=this.cookies.length),i&&(e.hash=i),(!r||n)&&this.cookies.push(e),this.removeExpiredCookies()}setResponseCookies(e,t){if(e instanceof Response)if(e?.headers&&typeof e.headers?.getSetCookie<"u")for(let s of e.headers.getSetCookie()){let i=U.parse(s.trim());i&&this.setCookieSync(i,t)}else{let s=e?.headers?.get("set-cookie");s&&s.split(",").forEach(i=>{let r=U.parse(i);r&&this.setCookieSync(r,t)})}else Array.isArray(e)?typeof e[0]=="string"?e.forEach(n=>{let s=U.parse(n.trim());s&&this.setCookieSync(s,t)}):e[0]instanceof U?e.forEach(n=>this.setCookieSync(n,t)):e.forEach(n=>{let s=U.fromJSON(n);s&&this.setCookieSync(s,t)}):typeof e=="string"&&e.includes("=")&&e.includes(",")&&e.split(",").forEach(n=>{let s=U.parse(n);s&&this.setCookieSync(s,t)})}toNetscapeFormat(e){this.removeExpiredCookies();let t=`# Netscape HTTP Cookie File
`;return t+=`# This file was generated by YuniqCookie npm package
`,t+=`# https://www.npmjs.com/package/yuniq-cookie
`,t+this.cookies.filter(n=>!e||n.inDomain(e)).map(n=>n.toNetscapeFormat()).join(`
`)||""}getDomain(e){if(!e)return null;try{return new URL(e).hostname}catch{return null}}toArray(){return this.removeExpiredCookies(),this.cookies.map(e=>e.toArray())||[]}toCookieString(e){return this.removeExpiredCookies(),this.allCookies()?.filter(t=>!e||t.inDomain(e,!1)).map(t=>t.toString()).join("; ")||""}toSetCookiesString(e){return this.removeExpiredCookies(),this.allCookies()?.filter(t=>!e||t.inDomain(e,!1)).map(t=>t.toSetCookieString()).join("; ")||""}domainToCookieString(e){return this.removeExpiredCookies(),this.allCookies()?.filter(t=>t.domain===e).map(t=>`${t.key}=${t.value}`).join("; ")||""}removeExpiredCookies(){let e=new Date,t=this.cookies.length;return this.cookies=this.cookies.filter(o=>{if(o.expires instanceof Date&&o.expires.getTime()<=e.getTime())return!1;if((o.expires===null||o.expires===void 0)&&typeof o.maxAge=="number"){let s=o.lastAccessed instanceof Date?o.lastAccessed:o.creation instanceof Date?o.creation:new Date(0);if(new Date(s.getTime()+this.isMillisecondsLength(o.maxAge)).getTime()<=e.getTime())return!1}return!0}),t-this.cookies.length}getCookieByKey(e,t,n){if(this.removeExpiredCookies(),t){let s=this.getCookies(t).map(a=>{let c=n?a?.key.trim():a?.key.trim().toLowerCase(),r=n?e.trim():e.trim().toLowerCase();return c===r?a:null}).filter(a=>a!==null);if(s&&s.length>0)return s[0]}else{let o=this.cookies.map(s=>{let a=s,c=n?a?.key.trim():a?.key.trim().toLowerCase(),r=n?e.trim():e.trim().toLowerCase();return c===r?s:null}).filter(s=>s!==null);if(o&&o.length>0)return o[0]}return null}parseNetscapeCookies(e,t=!0){let n=e.split(`
`);for(let o of n)try{let[s,a,c,r,i,d,p]=o.split(" "),u=`http${r==="TRUE"?"s":""}://${s.startsWith(".")?s.substring(1):s}${c}`;this.setCookieSync(new D({domain:s,path:c,secure:r==="TRUE",expires:i?new Date(parseInt(i)*1e3):void 0,key:d,value:p}),u,t)}catch(s){this.debug&&console.error("Error parsing netscape cookies:",s)}}parseCookieString(e,t,n=!0,o=!0){this.removeExpiredCookies();try{let s=new URL(t),a=e.replaceAll(";","_____").replaceAll("; ","_____").split("_____");for(let c of a){let[r,...i]=c.split("="),d=i.join("=");this.setCookieSync(new D({key:r,value:d,domain:s.hostname,path:"/",...this.setDates(o)}),s.toString(),n)}}catch(s){console.error(s)}}setDates(e){return{expires:e?new Date().addDay(7):"Infinity",creation:e?new Date:null,lastAccessed:e?new Date:null}}fromArray(e,t=!0){for(let n of e)if(n instanceof D)n.domain&&this.setCookieSync(n,`http${n.secure?"s":""}://${n.domain.startsWith(".")?n.domain.substring(1):n.domain}${n.path}`,t);else{let o=D.fromJSON(n);o&&(n.plainDomain&&(o.plainDomain=n.plainDomain),n.hash&&(o.hash=n.hash),n.secure&&(o.secure=n.secure),this.setCookieSync(o,`http${o.secure?"s":""}://${o?.domain?.startsWith(".")?o.domain.substring(1):o.domain}${o.path}`,t))}this.removeExpiredCookies()}parseDate(e){if(e instanceof Date)return e;if(typeof e=="string"&&e!=="Infinity")return this.isNumberOnly(e)?new Date(this.isMillisecondsLength(e)):new Date(e);if(typeof e=="number")return new Date(this.isMillisecondsLength(e))}isNumberOnly(e){return/^[0-9]+$/.test(e)}isMillisecondsLength(e){let t=e.toString().trim();try{if(typeof e=="number")return t.length===13?e:e*1e3;let n=parseInt(t);return n.toString().length===13?n:n*1e3}catch{return 0}}clear(){this.removeAllCookiesSync()}removeAllCookiesSync(){this.cookies.length=0}getCookiesForDomain(e){return this.removeExpiredCookies(),this.allCookies().filter(t=>t.domain&&e.includes(t.domain))}allCookies(){return this.cookies}findCookie(e,t){return this.removeExpiredCookies(),this.allCookies().find(n=>n.key===e&&n.inDomain(t,!1))}getCookies(e,t){this.removeExpiredCookies();try{if(t&&typeof t=="function")t(null,this.cookies.map(n=>n&&n.inDomain(e,!1)?n:null).filter(n=>n!==null));else return this.cookies.map(n=>n&&n.inDomain(e,!1)?n:null).filter(n=>n!==null)}catch(n){if(t&&typeof t=="function")t(n,void 0);else return this.debug&&console.error("Error getting cookies:",n.message),[]}}getAllCookies(e){this.removeExpiredCookies();let t=this.getCookies(e);try{let n=[...t];return this.cookies.forEach(o=>{n.some(s=>s.hash===o.hash)||n.push(new D(o))}),n}catch(n){this.debug&&console.error(`Error parsing cookies: ${n.message}`)}return t}get size(){return this.removeExpiredCookies(),this.allCookies().length}isEmpty(){return this.removeExpiredCookies(),this.allCookies().length===0}*[Symbol.iterator](){for(let e of this.allCookies())yield e}},se=q;var x=j(require("fs")),E=j(require("path")),_=j(require("form-data")),ge=j(require("http")),me=j(require("https")),be=j(require("tunnel")),oe=j(require("socks-proxy-agent"));var L=require("node:zlib"),ie=require("node:stream"),M=class y{static decompressStream(e,t){return e?t?t.toLowerCase().split(/\s*,\s*/).reduce((o,s)=>{switch(s){case"gzip":return o.pipe((0,L.createGunzip)());case"br":return o.pipe((0,L.createBrotliDecompress)());case"deflate":return o.pipe((0,L.createInflate)());case"compress":return o.pipe((0,L.createInflate)());case"x-gzip":return o.pipe((0,L.createGunzip)());case"x-deflate":return o.pipe((0,L.createInflate)());case"gzip-raw":return o.pipe((0,L.createGunzip)({finishFlush:L.constants.Z_SYNC_FLUSH}));default:return o}},e):e:y.createEmptyReadableStream()}static async streamToBuffer(e){return new Promise((t,n)=>{let o=[];e.on("data",s=>o.push(Buffer.from(s))),e.on("end",()=>t(Buffer.concat(o))),e.on("error",n)})}static createEmptyReadableStream(){return new ie.Readable({read(){this.push(null)}})}};var v=_.default,we=_.default.Readable,Re=oe.SocksProxyAgent,J=class extends I{proxy;constructor(e){super(e),this.jar=new q,this.proxy=e?.proxy}setCookies(e,t,n){n&&(this.jar=new q),Array.isArray(e)?this.jar.fromArray(e,n):typeof e=="string"&&(t&&e.includes("; ")?this.jar.parseCookieString(e,t,n):e.includes(`
`)&&e.split(" ").length>3&&this.jar.parseNetscapeCookies(e,n))}getCookies(){return{array:this.jar.toArray(),string:this.jar.toCookieString(),netscape:this.jar.toNetscapeFormat()}}getCookieByKey(e,t,n){return this.jar.getCookieByKey(e,t,n)}async postMultipart(e,t,n){let o=new _.default,s=!1;if(t instanceof _.default)o=t,s=!0;else if(typeof t=="object"){for(let[a,c]of Object.entries(t))o.append(a,c?typeof c=="object"?JSON.stringify(c):c.toString():"");s=!0}else o=t;return this.request(e,"POST",o,{...n,isMultipart:s})}async request(e,t,n=void 0,o={}){await this.rateLimiter();let s=o;typeof s.treat302As303>"u"&&(s.treat302As303=!0);let a=[];typeof s.withCookies!="boolean"&&(s.withCookies=!0);let c,r=typeof s.returnBuffer>"u"?!1:s.returnBuffer,i=["GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"],d=s.maxRetries??0,p=s.retryDelay??0;t=i&&i.includes(t.toUpperCase())?t?.toUpperCase():"GET",s.body=n||s.body;let u=process.hrtime();(s.startNew||s.startNewRequest)&&this.jar?.removeAllCookiesSync();let f,w=s.maxRedirects||10,T=s.debug!==void 0?s.debug:!1,h=s.saveTo||s.fileName,C;if(h){let m=E.basename(h);if(this.checkISPermission(h.length?E.dirname(h):E.resolve(process.cwd()))){let l=m.length<h.length?E.dirname(h):E.join(process.cwd(),"download");x.existsSync(l)||x.mkdirSync(l,{recursive:!0}),C=E.join(l,m)}else if(s.debug)throw this.Error(void 0,`Permission denied to save to ${h}, returning the response data instead`)}let R=0,g=e instanceof URL?e.href:e;s.method=t;let k=null,H=0,B,A;if(s&&s.timeout&&typeof s.timeout=="number"&&s.timeout>100){let m=new AbortController;B=setTimeout(()=>m.abort(),s.timeout),A=m.signal}let U,O;try{for(;;){if(k=null,s.params&&typeof s.params=="object"){let l=new URL(g);for(let[P,b]of Object.entries(s.params))l.searchParams.set(P,b.toString());g=l.toString()}let m=this.prepareHTTPOptions({...s,fileName:C,customHeaders:c},g,t,R>0,U,O);try{let l=await this.makeRequest(g,{...m.requestOptions,signal:A},m.requestBody),P=l.status&&l.status>=300&&l.status<400&&l.redirectUrl&&!s.dontFollowRedirects;if((s.withCookies||s.withCookies===void 0)&&l.cookies&&this.jar.setResponseCookies(l.cookies,g),l.status<200||l.status>309)throw delete m.requestOptions.method,delete m.requestOptions.agent,m.requestOptions.proxy||delete m.requestOptions.proxy,m.requestBody||delete m.requestBody,C?(k={response:l,message:`Failed to download: ${l.statusText}`,config:{...m,method:t}},await this.Error(l,`Failed to download: ${l.statusText}`,{...m,method:t})):(delete m.requestOptions.filename,k={response:l,message:void 0,config:{...m,method:t}},await this.Error(l,void 0,{...m,method:t}));if(a.push(l.url),P){c=void 0;let b=s.onRedirect?s.onRedirect({url:new URL(l.redirectUrl),status:l.status,headers:l.headers,sameDomain:this.isSameDomain(g,l.redirectUrl),method:t.toUpperCase()}):void 0;if(typeof b<"u"){if(typeof b=="boolean"){if(!b)throw await this.Error(l,"Redirect denied by user",{...m,method:t})}else if(!b.redirect)throw await this.Error(l,b.message||"Redirect denied by user",{...m,method:t})}if(R>=w)throw await this.Error(l,`Max redirects (${w}) reached`,{...m,method:t});let F=l.redirectUrl;if(!F)throw await this.Error(l,"Redirect location not found",{...m,method:t});O=g,U=g,g=new URL(F,g).toString(),R++;let S=!1;typeof b=="object"&&b.redirect?(t=b.method||t,s.method=t,g=b.url,b.withoutBody?delete s.body:b.body&&(s.body=b.body),T&&(S=!0,console.log(`
Redirecting to: ${g} using ${t} method`)),b.setHeaders&&(c=b.setHeaders)):l.status===303||s.treat302As303&&l.status===302?(T&&(S=!0,console.log(`
Redirecting to: ${g} using GET method`)),t="GET",s.method=t,delete s.body):S=!1,T&&!S&&console.log(`Redirecting to: ${g}`);continue}if(C&&l.status)if(x.existsSync(C)){let b=x.statSync(C).size,[F,S]=process.hrtime(u),W=F+S/1e9;f={fileName:C,totalTime:this.formatTime(W),downloadSpeed:this.formatSpeed(b/W),size:this.formatSize(b)}}else throw await this.Error(l,`Error saving file: ${C}, please check the permissions`);return this.formatResponse(l,g,r,{...m,method:t},f,a)}catch(l){if(C&&x.existsSync(C)&&x.unlinkSync(C),k&&d>0)if(d>H)s.debug&&console.log(`Request failed with status code ${k.response?.status}, retrying...${p>0?" in "+p+"ms":""}`),H++,p>0&&await new Promise(P=>setTimeout(P,p));else throw s.debug&&console.log(`Max retries (${d}) reached, throwing the last error`),await this.Error(k.response,k.message,k.config);else throw l}}}catch(m){throw m}finally{typeof B<"u"&&clearTimeout(B),this.removeBatch()}}formatTime(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),o=Math.floor(e%3600/60),s=e%60,a=[];if(t>0&&a.push(`${t} day${t!==1?"s":""}`),n>0&&a.push(`${n} hour${n!==1?"s":""}`),o>0&&a.push(`${o} minute${o!==1?"s":""}`),s>0||a.length===0){let c=s<1?s.toFixed(2):Math.floor(s)===s?s.toFixed(0):s.toFixed(1);a.push(`${c} second${c!=="1"?"s":""}`)}if(a.length>1){let c=a.pop();return`${a.join(", ")} and ${c}`}else return a[0]}formatSpeed(e){let t=["B/s","KB/s","MB/s","GB/s"],n=e,o=0;for(;n>=1024&&o<t.length-1;)n/=1024,o++;return`${n.toFixed(2)} ${t[o]}`}formatSize(e){let t=["B","KB","MB","GB","TB"],n=e,o=0;for(;n>=1024&&o<t.length-1;)n/=1024,o++;return`${n.toFixed(2)} ${t[o]}`}async setProxy(e,t){if(e.protocol==="socks5"||e.protocol==="socks4"){let n="";if(e.username&&e.password){let o=encodeURIComponent(e.username),s=encodeURIComponent(e.password);n=`${o}:${s}@`}return new Re(`${e.protocol.replace("5","")}://${n}${e.host}:${e.port}`,{keepAlive:e.keepAlive,timeout:e.timeout??3e4,keepAliveMsecs:e.keepAliveMsecs,maxSockets:e.maxSockets,maxFreeSockets:e.maxFreeSockets})}else if(e.protocol==="http"||e.protocol==="https"){let n=e.protocol==="https"?t.protocol==="https:"?"httpsOverHttps":"httpOverHttps":t.protocol==="https:"?"httpsOverHttp":"httpOverHttp";return be[n]({proxy:{host:e.host,port:e.port,proxyAuth:e.password&&e.username&&e.password.length>1&&e.username.length>2?`${e.username}:${e.password}`:void 0},rejectUnauthorized:!1,keepAlive:e.keepAlive,timeout:e.timeout??3e4,keepAliveMsecs:e.keepAliveMsecs,maxSockets:e.maxSockets,maxFreeSockets:e.maxFreeSockets})}else throw e.protocol?await this.Error({},`Unsupported proxy protocol: ${e.protocol}, supported protocols are socks5, http or https`):await this.Error({},"You must specify a proxy protocol, either socks5, http or https")}async makeRequest(e,t,n){let{proxy:o,filename:s,method:a="GET",...c}=t,r=o?await this.setProxy(o,typeof e=="string"?new URL(e):e):void 0;return new Promise((i,d)=>{e=typeof e=="string"?new URL(e):e;let u=(e.protocol==="https:"?me:ge).request(e,{...c,rejectUnauthorized:!1,followRedirects:!1,agent:r,method:a},async f=>{let w=f.headers,T=w["content-type"],h=w["content-length"],C=w["set-cookie"];delete w["set-cookie"];let R;if(f.statusCode&&f.statusCode>=300&&f.statusCode<400&&f.headers.location)R=new URL(f.headers.location,e).href;else if(f.statusCode&&f.statusCode>=300&&f.statusCode<400&&!f.headers.location)throw await this.Error({headers:w,contentType:T,contentLength:h,cookies:C||[],status:f.statusCode??200,statusText:f.statusMessage??"OK",url:f.url||e.toString(),method:f.method,body:null,redirectUrl:void 0},"Redirect location not found",{...c,method:a});if(s){let g=x.createWriteStream(s);f.pipe(g),g.on("finish",()=>{i({headers:w,contentType:T,contentLength:h,cookies:C||[],status:f.statusCode??200,statusText:f.statusMessage??"OK",url:f.url||e.toString(),method:f.method,body:null,redirectUrl:R})}),g.on("error",async k=>{d(await this.Error({status:f.statusCode??500,statusText:f.statusMessage||"Internal Server Error",headers:w,url:f.url||e.toString(),method:f.method},k.message,{...c,method:a}))})}else{let g=M.decompressStream(f,f.headers["content-encoding"]),k=[];g.on("data",H=>{k.push(H)}),g.on("end",()=>{i({headers:w,contentType:T,contentLength:h,cookies:C||[],status:f.statusCode??200,statusText:f.statusMessage||"OK",url:f.url||e.toString(),method:f.method,body:Buffer.concat(k),redirectUrl:R})})}});u.on("error",async f=>{d(await this.Error({status:500,statusText:f.stack||"Internal Server Error"},f.message,{...c,method:a}))}),n&&(n instanceof URLSearchParams?u.write(n.toString()):n instanceof v?(u.setHeader("Content-Type",`multipart/form-data; boundary=${n.getBoundary()}`),n.pipe(u)):typeof n=="object"&&!(n instanceof Buffer)&&!(n instanceof Uint8Array)&&!(n instanceof we)?u.write(JSON.stringify(n)):u.write(n)),u.end()})}checkISPermission(e){try{return x.accessSync(e,x.constants.R_OK|x.constants.W_OK),!0}catch{return!1}}prepareHTTPOptions(e,t,n,o,s,a){let r=["post","put","patch"].includes(n.toLowerCase()),i={others:{}},d=e.headers instanceof Headers?e.headers:new Headers(e.headers||{}),p=!1,u=e.contentType||d.get("Content-Type")||(r?"application/json":void 0);if(e.customHeaders?i.headers=new Headers(e.customHeaders):e.headers?i.headers=d instanceof Headers?d:new Headers(d):i.headers=new Headers,d.has("Cookie")){let h=d.get("Cookie");e.withCookies&&this.setCookies(h,t),d.delete("Cookie"),i.headers.delete("Cookie")}e.cookies&&(e.withCookies||typeof e.withCookies>"u")&&this.setCookies(e.cookies,t);let f;if(e.useAllCookies?f=this.jar.getAllCookies(t):f=this.jar.getCookies(t),f.length>0&&(e.withCookies||typeof e.withCookies>"u")&&i.headers.set("Cookie",f.map(h=>`${h.key}=${h.value}`).join("; ")),e.body&&(i.body=e.body),e.isFormData||e.isJson||e.isMultipart)e.isFormData?(i.body=e.body,u="application/x-www-form-urlencoded",i.headers.set("Content-Type",u),p=!0):e.isJson?(i.body=e.body,u="application/json",i.headers.set("Content-Type",u),p=!0):e.isMultipart&&(i.body=e.body,p=!0);else if(e.json)i.body=JSON.stringify(e.json),u="application/json",i.headers.set("Content-Type",u),p=!0;else if(e.form_params)i.body=new URLSearchParams(e.form_params).toString(),u="application/x-www-form-urlencoded",i.headers.set("Content-Type",u),p=!0;else if(e.multipart&&!(e.multipart instanceof v)){let h=new v;Object.entries(e.multipart).forEach(([C,R])=>{h.append(C,R)}),i.body=h,p=!0}else if(e.requestType)switch(e.requestType){case"json":u="application/json",typeof i.body=="object"&&(i.body=JSON.stringify(i.body)),i.headers.set("Content-Type",u);break;case"form":u="application/x-www-form-urlencoded",typeof i.body=="object"&&(i.body=new URLSearchParams(i.body).toString()),i.headers.set("Content-Type",u);break;case"formData":if(typeof i.body=="object"){let h=new v;Object.entries(i.body).forEach(([C,R])=>{h.append(C,R?typeof R=="object"?JSON.stringify(R):R.toString():"")}),i.body=h}break;case"text":u="text/plain",i.headers.set("Content-Type",u);break}else if(u){let h=u.toLowerCase();if(h.includes("json"))i.headers.set("Content-Type","application/json"),i.body&&typeof i.body=="object"&&(i.body=JSON.stringify(i.body));else if(h.includes("x-www-form-urlencoded"))i.headers.set("Content-Type","application/x-www-form-urlencoded"),i.body&&typeof i.body=="object"&&(i.body=new URLSearchParams(i.body).toString());else if(h.includes("multipart")){if(i.body&&typeof i.body=="object"){let C=new v;Object.entries(i.body).forEach(([R,g])=>{C.append(R,g)}),i.body=C}}else h.includes("text/plain")&&i.headers.set("Content-Type","text/plain")}else u&&!e.withoutContentType&&i.headers.set("Content-Type",u);e.withoutContentType&&i.headers.delete("Content-Type"),e.withoutBodyOnRedirect&&o&&(i.body=void 0),e.printHeaders&&console.log("Fetch headers:",i.headers),(typeof e.autoSetReferer!="boolean"||e.autoSetReferer)&&s&&(e.customHeaders||i.headers.set("Referer",s));for(let h of this.innerFetchOption)Object.keys(e).includes(h)&&typeof e[h]<"u"&&e[h]!==null&&(i.others[h]=e[h]);typeof e.withCookies=="boolean"&&!e.withCookies&&i.headers.delete("Cookie"),delete i.credentials;let w={requestBody:i.body,requestOptions:{}};n.toLowerCase()==="get"&&i.headers.has("Content-Type")&&i.headers.delete("Content-Type"),i.headers.has("user-agent")||i.headers.set("user-agent",this.defaultUserAgent),i.headers.has("accept")||i.headers.set("accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8"),i.headers.has("accept-language")||i.headers.set("accept-language","en-US,en;q=0.9"),i.headers.has("host")||i.headers.set("host",new URL(t).host),i.headers.has("origin")||["POST","PUT","PATCH","DELETE","OPTIONS"].includes(n.toUpperCase())&&i.headers.set("origin",new URL(a||t).origin),a&&i.headers.has("origin")&&(["POST","PUT","PATCH","DELETE","OPTIONS"].includes(n.toUpperCase())||i.headers.delete("origin")),a&&!i.headers.has("referer")&&i.headers.set("referer",a);let T={};for(let[h,C]of i.headers.entries())T[h]=C;return w.requestOptions.headers=T,w.requestOptions.proxy=e.proxy??this.proxy,w.requestOptions.filename=e.fileName,w.requestOptions.method=n,i=void 0,w}isSameDomain(e,t){return new URL(e).hostname===new URL(t).hostname}};var N=class extends I{constructor(e){super(e),this.environment="browser"}setCookies(e,t,n){}getCookies(){return{array:[],string:"",netscape:""}}getCookieByKey(e,t,n){return null}async request(e,t,n=void 0,o={}){await this.rateLimiter();let s=o;typeof s.treat302As303>"u"&&(s.treat302As303=!0);let a=[];typeof s.withCookies!="boolean"&&(s.withCookies=!0);let c,r=typeof s.returnBuffer>"u"?!1:s.returnBuffer,i=["GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"],d=s.maxRetries??0,p=s.retryDelay??0;t=i&&i.includes(t.toUpperCase())?t?.toUpperCase():"GET",s.body=n||s.body;let u=process.hrtime();(s.startNew||s.startNewRequest)&&this.jar?.removeAllCookiesSync();let f,w=s.maxRedirects||10,T=s.debug!==void 0?s.debug:!1,h;if(s.saveTo)throw this.Error(void 0,"You can only use this feature in Node.js, not in Edge or Browser.");let C=0,R=e instanceof URL?e.href:e;s.method=t;let g=null,k=0,H,B;if(s&&s.timeout&&typeof s.timeout=="number"&&s.timeout>100){let U=new AbortController;H=setTimeout(()=>U.abort(),s.timeout),B=U.signal}let A;try{for(;;){if(g=null,s.params&&typeof s.params=="object"){let O=new URL(R);for(let[m,l]of Object.entries(s.params))O.searchParams.set(m,l.toString());R=O.toString()}let U=this.prepareHTTPOptions({...s,fileName:h,customHeaders:c},R,t,C>0,A);try{let O=await fetch(R,{...U.requestOptions,signal:B}),m=O.status>=300&&O.status<400&&O.headers.has("location")&&!s.dontFollowRedirects;if(O.status<200||O.status>309)throw delete U.requestOptions.method,U.requestBody||delete U.requestBody,g={response:O,message:void 0,config:{...U,method:t}},await this.Error(O,void 0,{...U,method:t});if(a.push(O.url),m){let l=new URL(O.headers.get("Location"),R).toString();c=void 0;let P={};for(let[W,re]of O.headers.entries())P[W.toLowerCase()]=re;let b=s.onRedirect?s.onRedirect({url:new URL(l),status:O.status,headers:P,sameDomain:this.isSameDomain(R,l),method:t.toUpperCase()}):void 0;if(typeof b<"u"){if(typeof b=="boolean"){if(!b)throw await this.Error(O,"Redirect denied by user",{...U,method:t})}else if(!b.redirect)throw await this.Error(O,b.message||"Redirect denied by user",{...U,method:t})}if(C>=w)throw await this.Error(O,`Max redirects (${w}) reached`,{...U,method:t});let F=l;if(!F)throw await this.Error(O,"Redirect location not found",{...U,method:t});A=R,R=new URL(F,R).toString(),C++;let S=!1;typeof b=="object"&&b.redirect?(t=b.method||t,s.method=t,R=b.url,b.withoutBody?delete s.body:b.body&&(s.body=b.body),T&&(S=!0,console.log(`
Redirecting to: ${R} using ${t} method`)),b.setHeaders&&(c=b.setHeaders)):O.status===303||s.treat302As303&&O.status===302?(T&&(S=!0,console.log(`
Redirecting to: ${R} using GET method`)),t="GET",s.method=t,delete s.body):S=!1,T&&!S&&console.log(`Redirecting to: ${R}`);continue}return this.formatResponse(O,R,r,{...U,method:t},f,a)}catch(O){if(g&&d>0)if(d>k)s.debug&&console.log(`Request failed with status code ${g.response?.status}, retrying...${p>0?" in "+p+"ms":""}`),k++,p>0&&await new Promise(m=>setTimeout(m,p));else throw s.debug&&console.log(`Max retries (${d}) reached, throwing the last error`),await this.Error(g.response,g.message,g.config);else throw O}}}catch(U){throw U}finally{typeof H<"u"&&clearTimeout(H),this.removeBatch()}}prepareHTTPOptions(e,t,n,o,s){let c=["post","put","patch"].includes(n.toLowerCase()),r={others:{}},i=e.headers instanceof Headers?e.headers:new Headers(e.headers||{}),d=e.contentType||i.get("Content-Type")||(c?"application/json":void 0);if(e.customHeaders?r.headers=new Headers(e.customHeaders):e.headers?r.headers=i instanceof Headers?i:new Headers(i):r.headers=new Headers,i.has("Cookie")){let u=i.get("Cookie");e.withCookies&&this.setCookies(u,t),i.delete("Cookie"),r.headers.delete("Cookie")}if(e.body&&(r.body=e.body),e.isFormData||e.isJson||e.isMultipart)e.isFormData?(r.body=e.body,d="application/x-www-form-urlencoded",r.headers.set("Content-Type",d)):e.isJson?(r.body=e.body,d="application/json",r.headers.set("Content-Type",d)):e.isMultipart&&(r.body=e.body);else if(e.json)r.body=JSON.stringify(e.json),d="application/json",r.headers.set("Content-Type",d);else if(e.form_params)r.body=new URLSearchParams(e.form_params).toString(),d="application/x-www-form-urlencoded",r.headers.set("Content-Type",d);else if(e.multipart&&!(e.multipart instanceof FormData)){let u=new FormData;Object.entries(e.multipart).forEach(([f,w])=>{u.append(f,w)}),r.body=u}else if(e.requestType)switch(e.requestType){case"json":d="application/json",typeof r.body=="object"&&(r.body=JSON.stringify(r.body)),r.headers.set("Content-Type",d);break;case"form":d="application/x-www-form-urlencoded",typeof r.body=="object"&&(r.body=new URLSearchParams(r.body).toString()),r.headers.set("Content-Type",d);break;case"formData":if(typeof r.body=="object"){let u=new FormData;Object.entries(r.body).forEach(([f,w])=>{u.append(f,w?typeof w=="object"?JSON.stringify(w):w.toString():"")}),r.body=u}break;case"text":d="text/plain",r.headers.set("Content-Type",d);break}else if(d){let u=d.toLowerCase();if(u.includes("json"))r.headers.set("Content-Type","application/json"),r.body&&typeof r.body=="object"&&(r.body=JSON.stringify(r.body));else if(u.includes("x-www-form-urlencoded"))r.headers.set("Content-Type","application/x-www-form-urlencoded"),r.body&&typeof r.body=="object"&&(r.body=new URLSearchParams(r.body).toString());else if(u.includes("multipart")){if(r.body&&typeof r.body=="object"){let f=new FormData;Object.entries(r.body).forEach(([w,T])=>{f.append(w,T)}),r.body=f}}else u.includes("text/plain")&&r.headers.set("Content-Type","text/plain")}else d&&!e.withoutContentType&&r.headers.set("Content-Type",d);e.withoutContentType&&r.headers.delete("Content-Type"),e.withoutBodyOnRedirect&&o&&(r.body=void 0),e.printHeaders&&console.log("Fetch headers:",r.headers);for(let u of this.innerFetchOption)Object.keys(e).includes(u)&&typeof e[u]<"u"&&e[u]!==null&&(r.others[u]=e[u]);n.toLowerCase()==="get"&&r.headers.has("Content-Type")&&r.headers.delete("Content-Type");let p={requestBody:r.body,requestOptions:r};return r=void 0,p}isSameDomain(e,t){return new URL(e).hostname===new URL(t).hostname}};var V=j(require("form-data"));var K=V.default,z=class extends I{constructor(e){super(e),this.jar=new q,this.environment="worker"}setCookies(e,t,n){n&&(this.jar=new q),Array.isArray(e)?this.jar.fromArray(e,n):typeof e=="string"&&(t&&e.includes("; ")?this.jar.parseCookieString(e,t,n):e.includes(`
`)&&e.split(" ").length>3&&this.jar.parseNetscapeCookies(e,n))}getCookies(){return{array:this.jar.toArray(),string:this.jar.toCookieString(),netscape:this.jar.toNetscapeFormat()}}getCookieByKey(e,t,n){return this.jar.getCookieByKey(e,t,n)}async postMultipart(e,t,n){let o=new V.default,s=!1;if(t instanceof V.default)o=t,s=!0;else if(typeof t=="object"){for(let[a,c]of Object.entries(t))o.append(a,c?typeof c=="object"?JSON.stringify(c):c.toString():"");s=!0}else o=t;return this.request(e,"POST",o,{...n,isMultipart:s})}async request(e,t,n=void 0,o={}){await this.rateLimiter();let s=o;typeof s.treat302As303>"u"&&(s.treat302As303=!0);let a=[];typeof s.withCookies!="boolean"&&(s.withCookies=!0);let c,r=typeof s.returnBuffer>"u"?!1:s.returnBuffer,i=["GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"],d=s.maxRetries??0,p=s.retryDelay??0;t=i&&i.includes(t.toUpperCase())?t?.toUpperCase():"GET",s.body=n||s.body;let u=process.hrtime();(s.startNew||s.startNewRequest)&&this.jar?.removeAllCookiesSync();let f,w=s.maxRedirects||10,T=s.debug!==void 0?s.debug:!1,h=s.saveTo||s.fileName,C;if(h)throw this.Error(void 0,"You can only use this feature in Node.js, not in Edge or Browser.");let R=0,g=e instanceof URL?e.href:e;s.method=t;let k=null,H=0,B,A;if(s&&s.timeout&&typeof s.timeout=="number"&&s.timeout>100){let m=new AbortController;B=setTimeout(()=>m.abort(),s.timeout),A=m.signal}let U,O;try{for(;;){if(k=null,s.params&&typeof s.params=="object"){let l=new URL(g);for(let[P,b]of Object.entries(s.params))l.searchParams.set(P,b.toString());g=l.toString()}let m=this.prepareHTTPOptions({...s,fileName:C,customHeaders:c},g,t,R>0,U,O);try{let l=await this.makeRequest(g,{...m.requestOptions,signal:A},m.requestBody),P=l.status&&l.status>=300&&l.status<400&&l.redirectUrl&&!s.dontFollowRedirects;if((s.withCookies||s.withCookies===void 0)&&l.cookies&&this.jar.setResponseCookies(l.cookies,g),l.status<200||l.status>309)throw delete m.requestOptions.method,delete m.requestOptions.agent,m.requestBody||delete m.requestBody,C?(k={response:l,message:`Failed to download: ${l.statusText}`,config:{...m,method:t}},await this.Error(l,`Failed to download: ${l.statusText}`,{...m,method:t})):(k={response:l,message:void 0,config:{...m,method:t}},await this.Error(l,void 0,{...m,method:t}));if(a.push(l.url),P){c=void 0;let b=s.onRedirect?s.onRedirect({url:new URL(l.redirectUrl),status:l.status,headers:l.headers,sameDomain:this.isSameDomain(g,l.redirectUrl),method:t.toUpperCase()}):void 0;if(typeof b<"u"){if(typeof b=="boolean"){if(!b)throw await this.Error(l,"Redirect denied by user",{...m,method:t})}else if(!b.redirect)throw await this.Error(l,b.message||"Redirect denied by user",{...m,method:t})}if(R>=w)throw await this.Error(l,`Max redirects (${w}) reached`,{...m,method:t});let F=l.redirectUrl;if(!F)throw await this.Error(l,"Redirect location not found",{...m,method:t});O=g,U=g,g=new URL(F,g).toString(),R++;let S=!1;typeof b=="object"&&b.redirect?(t=b.method||t,s.method=t,g=b.url,b.withoutBody?delete s.body:b.body&&(s.body=b.body),T&&(S=!0,console.log(`
Redirecting to: ${g} using ${t} method`)),b.setHeaders&&(c=b.setHeaders)):l.status===303||s.treat302As303&&l.status===302?(T&&(S=!0,console.log(`
Redirecting to: ${g} using GET method`)),t="GET",s.method=t,delete s.body):S=!1,T&&!S&&console.log(`Redirecting to: ${g}`);continue}return this.formatResponse(l,g,r,{...m,method:t},f,a)}catch(l){if(k&&d>0)if(d>H)s.debug&&console.log(`Request failed with status code ${k.response?.status}, retrying...${p>0?" in "+p+"ms":""}`),H++,p>0&&await new Promise(P=>setTimeout(P,p));else throw s.debug&&console.log(`Max retries (${d}) reached, throwing the last error`),await this.Error(k.response,k.message,k.config);else throw l}}}catch(m){throw m}finally{typeof B<"u"&&clearTimeout(B),this.removeBatch()}}prepareHTTPOptions(e,t,n,o,s,a){let r=["post","put","patch"].includes(n.toLowerCase()),i={others:{}},d=e.headers instanceof Headers?e.headers:new Headers(e.headers||{}),p=!1,u=e.contentType||d.get("Content-Type")||(r?"application/json":void 0);if(e.customHeaders?i.headers=new Headers(e.customHeaders):e.headers?i.headers=d instanceof Headers?d:new Headers(d):i.headers=new Headers,d.has("Cookie")){let h=d.get("Cookie");e.withCookies&&this.setCookies(h,t),d.delete("Cookie"),i.headers.delete("Cookie")}e.cookies&&(e.withCookies||typeof e.withCookies>"u")&&this.setCookies(e.cookies,t);let f;if(e.useAllCookies?f=this.jar.getAllCookies(t):f=this.jar.getCookies(t),f.length>0&&(e.withCookies||typeof e.withCookies>"u")&&i.headers.set("Cookie",f.map(h=>`${h.key}=${h.value}`).join("; ")),e.body&&(i.body=e.body),e.isFormData||e.isJson||e.isMultipart)e.isFormData?(i.body=e.body,u="application/x-www-form-urlencoded",i.headers.set("Content-Type",u),p=!0):e.isJson?(i.body=e.body,u="application/json",i.headers.set("Content-Type",u),p=!0):e.isMultipart&&(i.body=e.body,p=!0);else if(e.json)i.body=JSON.stringify(e.json),u="application/json",i.headers.set("Content-Type",u),p=!0;else if(e.form_params)i.body=new URLSearchParams(e.form_params).toString(),u="application/x-www-form-urlencoded",i.headers.set("Content-Type",u),p=!0;else if(e.multipart&&!(e.multipart instanceof K)){let h=new K;Object.entries(e.multipart).forEach(([C,R])=>{h.append(C,R)}),i.body=h,p=!0}else if(e.requestType)switch(e.requestType){case"json":u="application/json",typeof i.body=="object"&&(i.body=JSON.stringify(i.body)),i.headers.set("Content-Type",u);break;case"form":u="application/x-www-form-urlencoded",typeof i.body=="object"&&(i.body=new URLSearchParams(i.body).toString()),i.headers.set("Content-Type",u);break;case"formData":if(typeof i.body=="object"){let h=new K;Object.entries(i.body).forEach(([C,R])=>{h.append(C,R?typeof R=="object"?JSON.stringify(R):R.toString():"")}),i.body=h}break;case"text":u="text/plain",i.headers.set("Content-Type",u);break}else if(u){let h=u.toLowerCase();if(h.includes("json"))i.headers.set("Content-Type","application/json"),i.body&&typeof i.body=="object"&&(i.body=JSON.stringify(i.body));else if(h.includes("x-www-form-urlencoded"))i.headers.set("Content-Type","application/x-www-form-urlencoded"),i.body&&typeof i.body=="object"&&(i.body=new URLSearchParams(i.body).toString());else if(h.includes("multipart")){if(i.body&&typeof i.body=="object"){let C=new K;Object.entries(i.body).forEach(([R,g])=>{C.append(R,g)}),i.body=C}}else h.includes("text/plain")&&i.headers.set("Content-Type","text/plain")}else u&&!e.withoutContentType&&i.headers.set("Content-Type",u);e.withoutContentType&&i.headers.delete("Content-Type"),e.withoutBodyOnRedirect&&o&&(i.body=void 0),e.printHeaders&&console.log("Fetch headers:",i.headers),(typeof e.autoSetReferer!="boolean"||e.autoSetReferer)&&s&&(e.customHeaders||i.headers.set("Referer",s));for(let h of this.innerFetchOption)Object.keys(e).includes(h)&&typeof e[h]<"u"&&e[h]!==null&&(i.others[h]=e[h]);typeof e.withCookies=="boolean"&&!e.withCookies&&i.headers.delete("Cookie"),delete i.credentials;let w={requestBody:i.body,requestOptions:{}};n.toLowerCase()==="get"&&i.headers.has("Content-Type")&&i.headers.delete("Content-Type"),i.headers.has("user-agent")||i.headers.set("user-agent",this.defaultUserAgent),i.headers.has("accept")||i.headers.set("accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8"),i.headers.has("accept-language")||i.headers.set("accept-language","en-US,en;q=0.9"),i.headers.has("host")||i.headers.set("host",new URL(t).host),i.headers.has("origin")||["POST","PUT","PATCH","DELETE","OPTIONS"].includes(n.toUpperCase())&&i.headers.set("origin",new URL(a||t).origin),a&&i.headers.has("origin")&&(["POST","PUT","PATCH","DELETE","OPTIONS"].includes(n.toUpperCase())||i.headers.delete("origin")),a&&!i.headers.has("referer")&&i.headers.set("referer",a);let T={};for(let[h,C]of i.headers.entries())T[h]=C;return w.requestOptions.headers=T,w.requestOptions.method=n,i=void 0,w}checkENV(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?!0:typeof caches<"u"||typeof KVNamespace<"u"}async makeRequest(e,t,n){let{method:o="GET",...s}=t,a=this.checkENV();e=typeof e=="string"?new URL(e):e;let c=await this.fetch(e,{signal:t.signal,headers:t.headers?new Headers(t.headers):new Headers,method:t.method,body:n,redirect:"manual",keepalive:t.keepalive,...a?{}:{cache:"no-cache"}}),r=c.headers,i=r.get("content-type")||void 0,d=r.get("content-length")||void 0,p=r?.getSetCookie()||r.get("set-cookie")?.split(",")||[];r.delete("set-cookie");let u=c.status,f=c.headers.get("location"),w=c.headers.get("content-encoding"),T={},h=c.statusText;for(let[R,g]of r.entries())T[R.toLowerCase()]=g;let C;if(u&&u>=300&&u<400&&f)C=new URL(f,e).href;else if(u&&u>=300&&u<400&&!f)throw await this.Error({headers:T,contentType:i,contentLength:d,cookies:p||[],status:u??200,statusText:h??"OK",url:c.url||e.href,method:o,body:null,redirectUrl:void 0},"Redirect location not found",{...s,method:o});return!c.ok&&!u&&(u=500),new Promise((R,g)=>{let k=M.decompressStream(c.body,w||void 0),H=[];k.on("data",B=>{H.push(B)}),k.on("end",()=>{R({headers:T,contentType:i,contentLength:d,cookies:p,status:u??200,statusText:h||"OK",url:c.url||e.toString(),method:o,body:Buffer.concat(H),redirectUrl:C})}),k.on("error",async B=>{g(await this.Error({status:500,statusText:B.stack||"Internal Server Error"},B.message,{...s,method:o}))})})}isSameDomain(e,t){return new URL(e).hostname===new URL(t).hostname}};var X,Z;process.env.BROWSER?(X=new N,Z=N):process.env.WORKER?(X=new z,Z=z):(X=new J,Z=J);var Ce=X;0&&(module.exports={Cookie,CookieJar,FormData,Uniqhtt,UniqhttBrowser,UniqhttNode,UniqhttWorker,YuniqCookie});
`)||""}getDomain(e){if(!e)return null;try{return new URL(e).hostname}catch{return null}}toArray(){return this.removeExpiredCookies(),this.cookies.map(e=>e.toArray())||[]}toCookieString(e){return this.removeExpiredCookies(),this.allCookies()?.filter(t=>!e||t.inDomain(e,!1)).map(t=>t.toString()).join("; ")||""}toSetCookiesString(e){return this.removeExpiredCookies(),this.allCookies()?.filter(t=>!e||t.inDomain(e,!1)).map(t=>t.toSetCookieString()).join("; ")||""}domainToCookieString(e){return this.removeExpiredCookies(),this.allCookies()?.filter(t=>t.domain===e).map(t=>`${t.key}=${t.value}`).join("; ")||""}removeExpiredCookies(){let e=new Date,t=this.cookies.length;return this.cookies=this.cookies.filter(s=>{if(s.expires instanceof Date&&s.expires.getTime()<=e.getTime())return!1;if((s.expires===null||s.expires===void 0)&&typeof s.maxAge=="number"){let i=s.lastAccessed instanceof Date?s.lastAccessed:s.creation instanceof Date?s.creation:new Date(0);if(new Date(i.getTime()+this.isMillisecondsLength(s.maxAge)).getTime()<=e.getTime())return!1}return!0}),t-this.cookies.length}getCookieByKey(e,t,n){if(this.removeExpiredCookies(),t){let i=this.getCookies(t).map(r=>{let a=n?r?.key.trim():r?.key.trim().toLowerCase(),c=n?e.trim():e.trim().toLowerCase();return a===c?r:null}).filter(r=>r!==null);if(i&&i.length>0)return i[0]}else{let s=this.cookies.map(i=>{let r=i,a=n?r?.key.trim():r?.key.trim().toLowerCase(),c=n?e.trim():e.trim().toLowerCase();return a===c?i:null}).filter(i=>i!==null);if(s&&s.length>0)return s[0]}return null}parseNetscapeCookies(e,t=!0){let n=e.split(`
`);for(let s of n)try{let[i,r,a,c,o,g,m]=s.split(" "),u=`http${c==="TRUE"?"s":""}://${i.startsWith(".")?i.substring(1):i}${a}`;this.setCookieSync(new U({domain:i,path:a,secure:c==="TRUE",expires:o?new Date(parseInt(o)*1e3):void 0,key:g,value:m}),u,t)}catch(i){this.debug&&console.error("Error parsing netscape cookies:",i)}}parseCookieString(e,t,n=!0,s=!0){this.removeExpiredCookies();try{let i=new URL(t),r=e.replaceAll(";","_____").replaceAll("; ","_____").split("_____");for(let a of r){let[c,...o]=a.split("="),g=o.join("=");this.setCookieSync(new U({key:c,value:g,domain:i.hostname,path:"/",...this.setDates(s)}),i.toString(),n)}}catch(i){console.error(i)}}setDates(e){return{expires:e?new Date().addDay(7):"Infinity",creation:e?new Date:null,lastAccessed:e?new Date:null}}fromArray(e,t=!0){for(let n of e)if(n instanceof U)n.domain&&this.setCookieSync(n,`http${n.secure?"s":""}://${n.domain.startsWith(".")?n.domain.substring(1):n.domain}${n.path}`,t);else{let s=U.fromJSON(n);s&&(n.plainDomain&&(s.plainDomain=n.plainDomain),n.hash&&(s.hash=n.hash),n.secure&&(s.secure=n.secure),this.setCookieSync(s,`http${s.secure?"s":""}://${s?.domain?.startsWith(".")?s.domain.substring(1):s.domain}${s.path}`,t))}this.removeExpiredCookies()}parseDate(e){if(e instanceof Date)return e;if(typeof e=="string"&&e!=="Infinity")return this.isNumberOnly(e)?new Date(this.isMillisecondsLength(e)):new Date(e);if(typeof e=="number")return new Date(this.isMillisecondsLength(e))}isNumberOnly(e){return/^[0-9]+$/.test(e)}isMillisecondsLength(e){let t=e.toString().trim();try{if(typeof e=="number")return t.length===13?e:e*1e3;let n=parseInt(t);return n.toString().length===13?n:n*1e3}catch{return 0}}clear(){this.removeAllCookiesSync()}removeAllCookiesSync(){this.cookies.length=0}getCookiesForDomain(e){return this.removeExpiredCookies(),this.allCookies().filter(t=>t.domain&&e.includes(t.domain))}allCookies(){return this.cookies}findCookie(e,t){return this.removeExpiredCookies(),this.allCookies().find(n=>n.key===e&&n.inDomain(t,!1))}getCookies(e,t){this.removeExpiredCookies();try{if(t&&typeof t=="function")t(null,this.cookies.map(n=>n&&n.inDomain(e,!1)?n:null).filter(n=>n!==null));else return this.cookies.map(n=>n&&n.inDomain(e,!1)?n:null).filter(n=>n!==null)}catch(n){if(t&&typeof t=="function")t(n,void 0);else return this.debug&&console.error("Error getting cookies:",n.message),[]}}getAllCookies(e){this.removeExpiredCookies();let t=this.getCookies(e);try{let n=[...t];return this.cookies.forEach(s=>{n.some(i=>i.hash===s.hash)||n.push(new U(s))}),n}catch(n){this.debug&&console.error(`Error parsing cookies: ${n.message}`)}return t}get size(){return this.removeExpiredCookies(),this.allCookies().length}isEmpty(){return this.removeExpiredCookies(),this.allCookies().length===0}*[Symbol.iterator](){for(let e of this.allCookies())yield e}},ne=P;var x=F(require("fs")),L=F(require("path")),G=F(require("form-data")),pe=F(require("http")),fe=F(require("https")),ye=F(require("tunnel")),se=F(require("socks-proxy-agent"));var O=require("node:zlib"),ie=require("node:stream"),v=class p{static decompressStream(e,t){return e?t?t.toLowerCase().split(/\s*,\s*/).reduce((s,i)=>{switch(i){case"gzip":return s.pipe((0,O.createGunzip)());case"br":return s.pipe((0,O.createBrotliDecompress)());case"deflate":return s.pipe((0,O.createInflate)());case"compress":return s.pipe((0,O.createInflate)());case"x-gzip":return s.pipe((0,O.createGunzip)());case"x-deflate":return s.pipe((0,O.createInflate)());case"gzip-raw":return s.pipe((0,O.createGunzip)({finishFlush:O.constants.Z_SYNC_FLUSH}));default:return s}},e):e:p.createEmptyReadableStream()}static async streamToBuffer(e){return new Promise((t,n)=>{let s=[];e.on("data",i=>s.push(Buffer.from(i))),e.on("end",()=>t(Buffer.concat(s))),e.on("error",n)})}static createEmptyReadableStream(){return new ie.Readable({read(){this.push(null)}})}};var E=G.default,ge=G.default.Readable,me=se.SocksProxyAgent,j=class extends A{proxy;constructor(e){super(e),this.jar=new P,this.proxy=e?.proxy}setCookies(e,t,n){n&&(this.jar=new P),Array.isArray(e)?this.jar.fromArray(e,n):typeof e=="string"&&(t&&e.includes("; ")?this.jar.parseCookieString(e,t,n):e.includes(`
`)&&e.split(" ").length>3&&this.jar.parseNetscapeCookies(e,n))}getCookies(){return{array:this.jar.toArray(),string:this.jar.toCookieString(),netscape:this.jar.toNetscapeFormat()}}getCookieByKey(e,t,n){return this.jar.getCookieByKey(e,t,n)}async postMultipart(e,t,n){let s=new G.default,i=!1;if(t instanceof G.default)s=t,i=!0;else if(typeof t=="object"){for(let[r,a]of Object.entries(t))s.append(r,a?typeof a=="object"?JSON.stringify(a):a.toString():"");i=!0}else s=t;return this.request(e,"POST",s,{...n,isMultipart:i})}async request(e,t,n=void 0,s={}){await this.rateLimiter();let i=s;typeof i.treat302As303>"u"&&(i.treat302As303=!0);let r=[];typeof i.withCookies!="boolean"&&(i.withCookies=!0);let a,c=typeof i.returnBuffer>"u"?!1:i.returnBuffer,o=["GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"],g=i.maxRetries??0,m=i.retryDelay??0;t=o&&o.includes(t.toUpperCase())?t?.toUpperCase():"GET",i.body=n||i.body;let u=process.hrtime();(i.startNew||i.startNewRequest)&&this.jar?.removeAllCookiesSync();let h,C=i.maxRedirects||10,k=i.debug!==void 0?i.debug:!1,d=i.saveTo||i.fileName,b;if(d){let f=L.basename(d);if(this.checkISPermission(d.length?L.dirname(d):L.resolve(process.cwd()))){let l=f.length<d.length?L.dirname(d):L.join(process.cwd(),"download");x.existsSync(l)||x.mkdirSync(l,{recursive:!0}),b=L.join(l,f)}else if(i.debug)throw this.Error(void 0,`Permission denied to save to ${d}, returning the response data instead`)}let w=0,y=e instanceof URL?e.href:e;i.method=t;let T=null,H=0,D,$;if(i&&i.timeout&&typeof i.timeout=="number"&&i.timeout>100){let f=new AbortController;D=setTimeout(()=>f.abort(),i.timeout),$=f.signal}let J,N;try{for(;;){if(T=null,i.params&&typeof i.params=="object"){let l=new URL(y);for(let[B,R]of Object.entries(i.params))l.searchParams.set(B,R.toString());y=l.toString()}let f=this.prepareHTTPOptions({...i,fileName:b,customHeaders:a},y,t,w>0,J,N);try{let l=await this.makeRequest(y,{...f.requestOptions,signal:$},f.requestBody),B=l.status&&l.status>=300&&l.status<400&&l.redirectUrl&&!i.dontFollowRedirects;if((i.withCookies||i.withCookies===void 0)&&l.cookies&&this.jar.setResponseCookies(l.cookies,y),l.status<200||l.status>309)throw delete f.requestOptions.method,delete f.requestOptions.agent,f.requestOptions.proxy||delete f.requestOptions.proxy,f.requestBody||delete f.requestBody,b?(T={response:l,message:`Failed to download: ${l.statusText}`,config:{...f,method:t}},await this.Error(l,`Failed to download: ${l.statusText}`,{...f,method:t})):(delete f.requestOptions.filename,T={response:l,message:void 0,config:{...f,method:t}},await this.Error(l,void 0,{...f,method:t}));if(r.push(l.url),B){a=void 0;let R=i.onRedirect?i.onRedirect({url:new URL(l.redirectUrl),status:l.status,headers:l.headers,sameDomain:this.isSameDomain(y,l.redirectUrl),method:t.toUpperCase()}):void 0;if(typeof R<"u"){if(typeof R=="boolean"){if(!R)throw await this.Error(l,"Redirect denied by user",{...f,method:t})}else if(!R.redirect)throw await this.Error(l,R.message||"Redirect denied by user",{...f,method:t})}if(w>=C)throw await this.Error(l,`Max redirects (${C}) reached`,{...f,method:t});let q=l.redirectUrl;if(!q)throw await this.Error(l,"Redirect location not found",{...f,method:t});N=y,J=y,y=new URL(q,y).toString(),w++;let S=!1;typeof R=="object"&&R.redirect?(t=R.method||t,i.method=t,y=R.url,R.withoutBody?delete i.body:R.body&&(i.body=R.body),k&&(S=!0,console.log(`
Redirecting to: ${y} using ${t} method`)),R.setHeaders&&(a=R.setHeaders)):l.status===303||i.treat302As303&&l.status===302?(k&&(S=!0,console.log(`
Redirecting to: ${y} using GET method`)),t="GET",i.method=t,delete i.body):S=!1,k&&!S&&console.log(`Redirecting to: ${y}`);continue}if(b&&l.status)if(x.existsSync(b)){let R=x.statSync(b).size,[q,S]=process.hrtime(u),Q=q+S/1e9;h={fileName:b,totalTime:this.formatTime(Q),downloadSpeed:this.formatSpeed(R/Q),size:this.formatSize(R)}}else throw await this.Error(l,`Error saving file: ${b}, please check the permissions`);return this.formatResponse(l,y,c,{...f,method:t},h,r)}catch(l){if(b&&x.existsSync(b)&&x.unlinkSync(b),T&&g>0)if(g>H)i.debug&&console.log(`Request failed with status code ${T.response?.status}, retrying...${m>0?" in "+m+"ms":""}`),H++,m>0&&await new Promise(B=>setTimeout(B,m));else throw i.debug&&console.log(`Max retries (${g}) reached, throwing the last error`),await this.Error(T.response,T.message,T.config);else throw l}}}catch(f){throw f}finally{typeof D<"u"&&clearTimeout(D),this.removeBatch()}}formatTime(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),s=Math.floor(e%3600/60),i=e%60,r=[];if(t>0&&r.push(`${t} day${t!==1?"s":""}`),n>0&&r.push(`${n} hour${n!==1?"s":""}`),s>0&&r.push(`${s} minute${s!==1?"s":""}`),i>0||r.length===0){let a=i<1?i.toFixed(2):Math.floor(i)===i?i.toFixed(0):i.toFixed(1);r.push(`${a} second${a!=="1"?"s":""}`)}if(r.length>1){let a=r.pop();return`${r.join(", ")} and ${a}`}else return r[0]}formatSpeed(e){let t=["B/s","KB/s","MB/s","GB/s"],n=e,s=0;for(;n>=1024&&s<t.length-1;)n/=1024,s++;return`${n.toFixed(2)} ${t[s]}`}formatSize(e){let t=["B","KB","MB","GB","TB"],n=e,s=0;for(;n>=1024&&s<t.length-1;)n/=1024,s++;return`${n.toFixed(2)} ${t[s]}`}async setProxy(e,t){if(e.protocol==="socks5"||e.protocol==="socks4"){let n="";if(e.username&&e.password){let s=encodeURIComponent(e.username),i=encodeURIComponent(e.password);n=`${s}:${i}@`}return new me(`${e.protocol.replace("5","")}://${n}${e.host}:${e.port}`,{keepAlive:e.keepAlive,timeout:e.timeout??3e4,keepAliveMsecs:e.keepAliveMsecs,maxSockets:e.maxSockets,maxFreeSockets:e.maxFreeSockets})}else if(e.protocol==="http"||e.protocol==="https"){let n=e.protocol==="https"?t.protocol==="https:"?"httpsOverHttps":"httpOverHttps":t.protocol==="https:"?"httpsOverHttp":"httpOverHttp";return ye[n]({proxy:{host:e.host,port:e.port,proxyAuth:e.password&&e.username&&e.password.length>1&&e.username.length>2?`${e.username}:${e.password}`:void 0},rejectUnauthorized:!1,keepAlive:e.keepAlive,timeout:e.timeout??3e4,keepAliveMsecs:e.keepAliveMsecs,maxSockets:e.maxSockets,maxFreeSockets:e.maxFreeSockets})}else throw e.protocol?await this.Error({},`Unsupported proxy protocol: ${e.protocol}, supported protocols are socks5, http or https`):await this.Error({},"You must specify a proxy protocol, either socks5, http or https")}async makeRequest(e,t,n){let{proxy:s,filename:i,method:r="GET",...a}=t,c=s?await this.setProxy(s,typeof e=="string"?new URL(e):e):void 0;return new Promise((o,g)=>{e=typeof e=="string"?new URL(e):e;let u=(e.protocol==="https:"?fe:pe).request(e,{...a,rejectUnauthorized:!1,followRedirects:!1,agent:c,method:r},async h=>{let C=h.headers,k=C["content-type"],d=C["content-length"],b=C["set-cookie"];delete C["set-cookie"];let w;if(h.statusCode&&h.statusCode>=300&&h.statusCode<400&&h.headers.location)w=new URL(h.headers.location,e).href;else if(h.statusCode&&h.statusCode>=300&&h.statusCode<400&&!h.headers.location)throw await this.Error({headers:C,contentType:k,contentLength:d,cookies:b||[],status:h.statusCode??200,statusText:h.statusMessage??"OK",url:h.url||e.toString(),method:h.method,body:null,redirectUrl:void 0},"Redirect location not found",{...a,method:r});if(i){let y=x.createWriteStream(i);h.pipe(y),y.on("finish",()=>{o({headers:C,contentType:k,contentLength:d,cookies:b||[],status:h.statusCode??200,statusText:h.statusMessage??"OK",url:h.url||e.toString(),method:h.method,body:null,redirectUrl:w})}),y.on("error",async T=>{g(await this.Error({status:h.statusCode??500,statusText:h.statusMessage||"Internal Server Error",headers:C,url:h.url||e.toString(),method:h.method},T.message,{...a,method:r}))})}else{let y=v.decompressStream(h,h.headers["content-encoding"]),T=[];y.on("data",H=>{T.push(H)}),y.on("end",()=>{o({headers:C,contentType:k,contentLength:d,cookies:b||[],status:h.statusCode??200,statusText:h.statusMessage||"OK",url:h.url||e.toString(),method:h.method,body:Buffer.concat(T),redirectUrl:w})})}});u.on("error",async h=>{g(await this.Error({status:500,statusText:h.stack||"Internal Server Error"},h.message,{...a,method:r}))}),n&&(n instanceof URLSearchParams?u.write(n.toString()):n instanceof E?(u.setHeader("Content-Type",`multipart/form-data; boundary=${n.getBoundary()}`),n.pipe(u)):typeof n=="object"&&!(n instanceof Buffer)&&!(n instanceof Uint8Array)&&!(n instanceof ge)?u.write(JSON.stringify(n)):u.write(n)),u.end()})}checkISPermission(e){try{return x.accessSync(e,x.constants.R_OK|x.constants.W_OK),!0}catch{return!1}}prepareHTTPOptions(e,t,n,s,i,r){let c=["post","put","patch"].includes(n.toLowerCase()),o={others:{}},g=e.headers instanceof Headers?e.headers:new Headers(e.headers||{}),m=!1,u=e.contentType||g.get("Content-Type")||(c?"application/json":void 0);if(e.customHeaders?o.headers=new Headers(e.customHeaders):e.headers?o.headers=g instanceof Headers?g:new Headers(g):o.headers=new Headers,g.has("Cookie")){let d=g.get("Cookie");e.withCookies&&this.setCookies(d,t),g.delete("Cookie"),o.headers.delete("Cookie")}e.cookies&&(e.withCookies||typeof e.withCookies>"u")&&this.setCookies(e.cookies,t);let h;if(e.useAllCookies?h=this.jar.getAllCookies(t):h=this.jar.getCookies(t),h.length>0&&(e.withCookies||typeof e.withCookies>"u")&&o.headers.set("Cookie",h.map(d=>`${d.key}=${d.value}`).join("; ")),e.body&&(o.body=e.body),e.isFormData||e.isJson||e.isMultipart)e.isFormData?(o.body=e.body,u="application/x-www-form-urlencoded",o.headers.set("Content-Type",u),m=!0):e.isJson?(o.body=e.body,u="application/json",o.headers.set("Content-Type",u),m=!0):e.isMultipart&&(o.body=e.body,m=!0);else if(e.json)o.body=JSON.stringify(e.json),u="application/json",o.headers.set("Content-Type",u),m=!0;else if(e.form_params)o.body=new URLSearchParams(e.form_params).toString(),u="application/x-www-form-urlencoded",o.headers.set("Content-Type",u),m=!0;else if(e.multipart&&!(e.multipart instanceof E)){let d=new E;Object.entries(e.multipart).forEach(([b,w])=>{d.append(b,w)}),o.body=d,m=!0}else if(e.requestType)switch(e.requestType){case"json":u="application/json",typeof o.body=="object"&&(o.body=JSON.stringify(o.body)),o.headers.set("Content-Type",u);break;case"form":u="application/x-www-form-urlencoded",typeof o.body=="object"&&(o.body=new URLSearchParams(o.body).toString()),o.headers.set("Content-Type",u);break;case"formData":if(typeof o.body=="object"){let d=new E;Object.entries(o.body).forEach(([b,w])=>{d.append(b,w?typeof w=="object"?JSON.stringify(w):w.toString():"")}),o.body=d}break;case"text":u="text/plain",o.headers.set("Content-Type",u);break}else if(u){let d=u.toLowerCase();if(d.includes("json"))o.headers.set("Content-Type","application/json"),o.body&&typeof o.body=="object"&&(o.body=JSON.stringify(o.body));else if(d.includes("x-www-form-urlencoded"))o.headers.set("Content-Type","application/x-www-form-urlencoded"),o.body&&typeof o.body=="object"&&(o.body=new URLSearchParams(o.body).toString());else if(d.includes("multipart")){if(o.body&&typeof o.body=="object"){let b=new E;Object.entries(o.body).forEach(([w,y])=>{b.append(w,y)}),o.body=b}}else d.includes("text/plain")&&o.headers.set("Content-Type","text/plain")}else u&&!e.withoutContentType&&o.headers.set("Content-Type",u);e.withoutContentType&&o.headers.delete("Content-Type"),e.withoutBodyOnRedirect&&s&&(o.body=void 0),e.printHeaders&&console.log("Fetch headers:",o.headers),(typeof e.autoSetReferer!="boolean"||e.autoSetReferer)&&i&&(e.customHeaders||o.headers.set("Referer",i));for(let d of this.innerFetchOption)Object.keys(e).includes(d)&&typeof e[d]<"u"&&e[d]!==null&&(o.others[d]=e[d]);typeof e.withCookies=="boolean"&&!e.withCookies&&o.headers.delete("Cookie"),delete o.credentials;let C={requestBody:o.body,requestOptions:{}};n.toLowerCase()==="get"&&o.headers.has("Content-Type")&&o.headers.delete("Content-Type"),o.headers.has("user-agent")||o.headers.set("user-agent",this.defaultUserAgent),o.headers.has("accept")||o.headers.set("accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8"),o.headers.has("accept-language")||o.headers.set("accept-language","en-US,en;q=0.9"),o.headers.has("host")||o.headers.set("host",new URL(t).host),o.headers.has("origin")||["POST","PUT","PATCH","DELETE","OPTIONS"].includes(n.toUpperCase())&&o.headers.set("origin",new URL(r||t).origin),r&&o.headers.has("origin")&&(["POST","PUT","PATCH","DELETE","OPTIONS"].includes(n.toUpperCase())||o.headers.delete("origin")),r&&!o.headers.has("referer")&&o.headers.set("referer",r);let k={};for(let[d,b]of o.headers.entries())k[d]=b;return C.requestOptions.headers=k,C.requestOptions.proxy=e.proxy??this.proxy,C.requestOptions.filename=e.fileName,C.requestOptions.method=n,o=void 0,C}isSameDomain(e,t){return new URL(e).hostname===new URL(t).hostname}};var K=F(require("form-data"));var Y=K.default,M=class extends A{constructor(e){super(e),this.jar=new P,this.environment="edge"}setCookies(e,t,n){n&&(this.jar=new P),Array.isArray(e)?this.jar.fromArray(e,n):typeof e=="string"&&(t&&e.includes("; ")?this.jar.parseCookieString(e,t,n):e.includes(`
`)&&e.split(" ").length>3&&this.jar.parseNetscapeCookies(e,n))}getCookies(){return{array:this.jar.toArray(),string:this.jar.toCookieString(),netscape:this.jar.toNetscapeFormat()}}getCookieByKey(e,t,n){return this.jar.getCookieByKey(e,t,n)}async postMultipart(e,t,n){let s=new K.default,i=!1;if(t instanceof K.default)s=t,i=!0;else if(typeof t=="object"){for(let[r,a]of Object.entries(t))s.append(r,a?typeof a=="object"?JSON.stringify(a):a.toString():"");i=!0}else s=t;return this.request(e,"POST",s,{...n,isMultipart:i})}async request(e,t,n=void 0,s={}){await this.rateLimiter();let i=s;typeof i.treat302As303>"u"&&(i.treat302As303=!0);let r=[];typeof i.withCookies!="boolean"&&(i.withCookies=!0);let a,c=typeof i.returnBuffer>"u"?!1:i.returnBuffer,o=["GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"],g=i.maxRetries??0,m=i.retryDelay??0;t=o&&o.includes(t.toUpperCase())?t?.toUpperCase():"GET",i.body=n||i.body;let u=process.hrtime();(i.startNew||i.startNewRequest)&&this.jar?.removeAllCookiesSync();let h,C=i.maxRedirects||10,k=i.debug!==void 0?i.debug:!1,d=i.saveTo||i.fileName,b;if(d)throw this.Error(void 0,"You can only use this feature in Node.js, not in Edge or Browser.");let w=0,y=e instanceof URL?e.href:e;i.method=t;let T=null,H=0,D,$;if(i&&i.timeout&&typeof i.timeout=="number"&&i.timeout>100){let f=new AbortController;D=setTimeout(()=>f.abort(),i.timeout),$=f.signal}let J,N;try{for(;;){if(T=null,i.params&&typeof i.params=="object"){let l=new URL(y);for(let[B,R]of Object.entries(i.params))l.searchParams.set(B,R.toString());y=l.toString()}let f=this.prepareHTTPOptions({...i,fileName:b,customHeaders:a},y,t,w>0,J,N);try{let l=await this.makeRequest(y,{...f.requestOptions,signal:$},f.requestBody),B=l.status&&l.status>=300&&l.status<400&&l.redirectUrl&&!i.dontFollowRedirects;if((i.withCookies||i.withCookies===void 0)&&l.cookies&&this.jar.setResponseCookies(l.cookies,y),l.status<200||l.status>309)throw delete f.requestOptions.method,delete f.requestOptions.agent,f.requestBody||delete f.requestBody,b?(T={response:l,message:`Failed to download: ${l.statusText}`,config:{...f,method:t}},await this.Error(l,`Failed to download: ${l.statusText}`,{...f,method:t})):(T={response:l,message:void 0,config:{...f,method:t}},await this.Error(l,void 0,{...f,method:t}));if(r.push(l.url),B){a=void 0;let R=i.onRedirect?i.onRedirect({url:new URL(l.redirectUrl),status:l.status,headers:l.headers,sameDomain:this.isSameDomain(y,l.redirectUrl),method:t.toUpperCase()}):void 0;if(typeof R<"u"){if(typeof R=="boolean"){if(!R)throw await this.Error(l,"Redirect denied by user",{...f,method:t})}else if(!R.redirect)throw await this.Error(l,R.message||"Redirect denied by user",{...f,method:t})}if(w>=C)throw await this.Error(l,`Max redirects (${C}) reached`,{...f,method:t});let q=l.redirectUrl;if(!q)throw await this.Error(l,"Redirect location not found",{...f,method:t});N=y,J=y,y=new URL(q,y).toString(),w++;let S=!1;typeof R=="object"&&R.redirect?(t=R.method||t,i.method=t,y=R.url,R.withoutBody?delete i.body:R.body&&(i.body=R.body),k&&(S=!0,console.log(`
Redirecting to: ${y} using ${t} method`)),R.setHeaders&&(a=R.setHeaders)):l.status===303||i.treat302As303&&l.status===302?(k&&(S=!0,console.log(`
Redirecting to: ${y} using GET method`)),t="GET",i.method=t,delete i.body):S=!1,k&&!S&&console.log(`Redirecting to: ${y}`);continue}return this.formatResponse(l,y,c,{...f,method:t},h,r)}catch(l){if(T&&g>0)if(g>H)i.debug&&console.log(`Request failed with status code ${T.response?.status}, retrying...${m>0?" in "+m+"ms":""}`),H++,m>0&&await new Promise(B=>setTimeout(B,m));else throw i.debug&&console.log(`Max retries (${g}) reached, throwing the last error`),await this.Error(T.response,T.message,T.config);else throw l}}}catch(f){throw f}finally{typeof D<"u"&&clearTimeout(D),this.removeBatch()}}prepareHTTPOptions(e,t,n,s,i,r){let c=["post","put","patch"].includes(n.toLowerCase()),o={others:{}},g=e.headers instanceof Headers?e.headers:new Headers(e.headers||{}),m=!1,u=e.contentType||g.get("Content-Type")||(c?"application/json":void 0);if(e.customHeaders?o.headers=new Headers(e.customHeaders):e.headers?o.headers=g instanceof Headers?g:new Headers(g):o.headers=new Headers,g.has("Cookie")){let d=g.get("Cookie");e.withCookies&&this.setCookies(d,t),g.delete("Cookie"),o.headers.delete("Cookie")}e.cookies&&(e.withCookies||typeof e.withCookies>"u")&&this.setCookies(e.cookies,t);let h;if(e.useAllCookies?h=this.jar.getAllCookies(t):h=this.jar.getCookies(t),h.length>0&&(e.withCookies||typeof e.withCookies>"u")&&o.headers.set("Cookie",h.map(d=>`${d.key}=${d.value}`).join("; ")),e.body&&(o.body=e.body),e.isFormData||e.isJson||e.isMultipart)e.isFormData?(o.body=e.body,u="application/x-www-form-urlencoded",o.headers.set("Content-Type",u),m=!0):e.isJson?(o.body=e.body,u="application/json",o.headers.set("Content-Type",u),m=!0):e.isMultipart&&(o.body=e.body,m=!0);else if(e.json)o.body=JSON.stringify(e.json),u="application/json",o.headers.set("Content-Type",u),m=!0;else if(e.form_params)o.body=new URLSearchParams(e.form_params).toString(),u="application/x-www-form-urlencoded",o.headers.set("Content-Type",u),m=!0;else if(e.multipart&&!(e.multipart instanceof Y)){let d=new Y;Object.entries(e.multipart).forEach(([b,w])=>{d.append(b,w)}),o.body=d,m=!0}else if(e.requestType)switch(e.requestType){case"json":u="application/json",typeof o.body=="object"&&(o.body=JSON.stringify(o.body)),o.headers.set("Content-Type",u);break;case"form":u="application/x-www-form-urlencoded",typeof o.body=="object"&&(o.body=new URLSearchParams(o.body).toString()),o.headers.set("Content-Type",u);break;case"formData":if(typeof o.body=="object"){let d=new Y;Object.entries(o.body).forEach(([b,w])=>{d.append(b,w?typeof w=="object"?JSON.stringify(w):w.toString():"")}),o.body=d}break;case"text":u="text/plain",o.headers.set("Content-Type",u);break}else if(u){let d=u.toLowerCase();if(d.includes("json"))o.headers.set("Content-Type","application/json"),o.body&&typeof o.body=="object"&&(o.body=JSON.stringify(o.body));else if(d.includes("x-www-form-urlencoded"))o.headers.set("Content-Type","application/x-www-form-urlencoded"),o.body&&typeof o.body=="object"&&(o.body=new URLSearchParams(o.body).toString());else if(d.includes("multipart")){if(o.body&&typeof o.body=="object"){let b=new Y;Object.entries(o.body).forEach(([w,y])=>{b.append(w,y)}),o.body=b}}else d.includes("text/plain")&&o.headers.set("Content-Type","text/plain")}else u&&!e.withoutContentType&&o.headers.set("Content-Type",u);e.withoutContentType&&o.headers.delete("Content-Type"),e.withoutBodyOnRedirect&&s&&(o.body=void 0),e.printHeaders&&console.log("Fetch headers:",o.headers),(typeof e.autoSetReferer!="boolean"||e.autoSetReferer)&&i&&(e.customHeaders||o.headers.set("Referer",i));for(let d of this.innerFetchOption)Object.keys(e).includes(d)&&typeof e[d]<"u"&&e[d]!==null&&(o.others[d]=e[d]);typeof e.withCookies=="boolean"&&!e.withCookies&&o.headers.delete("Cookie"),delete o.credentials;let C={requestBody:o.body,requestOptions:{}};n.toLowerCase()==="get"&&o.headers.has("Content-Type")&&o.headers.delete("Content-Type"),o.headers.has("user-agent")||o.headers.set("user-agent",this.defaultUserAgent),o.headers.has("accept")||o.headers.set("accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8"),o.headers.has("accept-language")||o.headers.set("accept-language","en-US,en;q=0.9"),o.headers.has("host")||o.headers.set("host",new URL(t).host),o.headers.has("origin")||["POST","PUT","PATCH","DELETE","OPTIONS"].includes(n.toUpperCase())&&o.headers.set("origin",new URL(r||t).origin),r&&o.headers.has("origin")&&(["POST","PUT","PATCH","DELETE","OPTIONS"].includes(n.toUpperCase())||o.headers.delete("origin")),r&&!o.headers.has("referer")&&o.headers.set("referer",r);let k={};for(let[d,b]of o.headers.entries())k[d]=b;return C.requestOptions.headers=k,C.requestOptions.method=n,o=void 0,C}checkENV(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?!0:typeof caches<"u"||typeof KVNamespace<"u"}async makeRequest(e,t,n){let{method:s="GET",...i}=t,r=this.checkENV();e=typeof e=="string"?new URL(e):e;let a=await this.fetch(e,{signal:t.signal,headers:t.headers?new Headers(t.headers):new Headers,method:t.method,body:n,redirect:"manual",keepalive:t.keepalive,...r?{}:{cache:"no-cache"}}),c=a.headers,o=c.get("content-type")||void 0,g=c.get("content-length")||void 0,m=c?.getSetCookie()||c.get("set-cookie")?.split(",")||[];c.delete("set-cookie");let u=a.status,h=a.headers.get("location"),C=a.headers.get("content-encoding"),k={},d=a.statusText;for(let[w,y]of c.entries())k[w.toLowerCase()]=y;let b;if(u&&u>=300&&u<400&&h)b=new URL(h,e).href;else if(u&&u>=300&&u<400&&!h)throw await this.Error({headers:k,contentType:o,contentLength:g,cookies:m||[],status:u??200,statusText:d??"OK",url:a.url||e.href,method:s,body:null,redirectUrl:void 0},"Redirect location not found",{...i,method:s});return!a.ok&&!u&&(u=500),new Promise((w,y)=>{let T=v.decompressStream(a.body,C||void 0),H=[];T.on("data",D=>{H.push(D)}),T.on("end",()=>{w({headers:k,contentType:o,contentLength:g,cookies:m,status:u??200,statusText:d||"OK",url:a.url||e.toString(),method:s,body:Buffer.concat(H),redirectUrl:b})}),T.on("error",async D=>{y(await this.Error({status:500,statusText:D.stack||"Internal Server Error"},D.message,{...i,method:s}))})})}isSameDomain(e,t){return new URL(e).hostname===new URL(t).hostname}};var X,Z;process.env.WORKER?(X=new M,Z=M):(X=new j,Z=j);var be=X;0&&(module.exports={Cookie,CookieJar,FormData,Uniqhtt,UniqhttEdge,UniqhttNode,YuniqCookie});

@@ -1,10 +0,10 @@

"use strict";var ee=Object.create;var j=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,se=Object.prototype.hasOwnProperty;var oe=(d,e)=>{for(var t in e)j(d,t,{get:e[t],enumerable:!0})},K=(d,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ne(e))!se.call(d,i)&&i!==t&&j(d,i,{get:()=>e[i],enumerable:!(n=te(e,i))||n.enumerable});return d};var B=(d,e,t)=>(t=d!=null?ee(ie(d)):{},K(e||!d||!d.__esModule?j(t,"default",{value:d,enumerable:!0}):t,d)),re=d=>K(j({},"__esModule",{value:!0}),d);var ge={};oe(ge,{FormData:()=>S,Uniqhtt:()=>fe,default:()=>ye,uniqhtt:()=>Q});module.exports=re(ge);var ae=B(require("buffer/")),{Buffer:N}=ae,H=class d extends Error{response={};constructor(e,t,n,i,s,o,c){if(super(e),t instanceof Response){let a=t.headers.get("Content-Length");this.response={urls:c||[t.url],data:n,status:t.status,statusText:t.statusText,finalUrl:t.url,cookies:void 0,headers:i,contentType:t.headers.get("Content-Type"),contentLength:a?parseInt(a):void 0,config:s}}else o?this.response={data:n,urls:c||[o.url],status:o?.status,statusText:o?.statusText,finalUrl:o?.url,cookies:void 0,headers:o.headers,contentType:o.contentType,contentLength:o.contentLength?parseInt(o.contentLength):void 0,config:s}:this.response={data:n,urls:c||[],status:t?.status,statusText:t?.statusText,finalUrl:t?.url,cookies:t?.cookies??void 0,headers:i,contentType:void 0,config:s,contentLength:void 0};Object.setPrototypeOf(this,d.prototype)}},$=class{jar=null;fetch;innerFetchOption=["headers","mode","cache","referrerPolicy","integrity","keepalive","compress"];environment="node";maxConcurrency=0;concurrencyDelay=1e3;singleRequestDelay=!1;totalBatchCount=0;isCurrentBatch=!1;currentBatch=0;queueSize=0;MIN_DELAY=100;defaultUserAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";constructor(e){this.fetch=fetch,e?.concurrentOpt&&this.setConcurrentOptions(e.concurrentOpt)}async checkForBatch(){try{this.maxConcurrency>0&&this.singleRequestDelay===!1&&this.isCurrentBatch&&await this.checkForBatchWithDelay()}catch(e){throw new Error(`Batch check failed: ${e.message}`)}}async checkForBatchWithDelay(){let e=Date.now(),t=7*24*60*60*1e3;for(;this.currentBatch>0&&this.isCurrentBatch;){if(Date.now()-e>t)throw new Error("Batch processing timeout exceeded (after 7 days) while waiting for a slot in the concurrency pool.");await this.wait(this.MIN_DELAY)}this.currentBatch=0,this.isCurrentBatch=!1,this.totalBatchCount>0&&this.concurrencyDelay>this.MIN_DELAY&&await this.wait(this.concurrencyDelay)}async rateLimiter(){let e=0,t=0;try{if(this.maxConcurrency>0){if(this.queueSize>0&&this.totalBatchCount+1>=this.queueSize)throw new Error("Request queue is full");this.totalBatchCount+=1,e=1,this.singleRequestDelay===!1?(await this.checkForBatch(),this.currentBatch+=1,t+=1,this.currentBatch>=this.maxConcurrency&&(this.isCurrentBatch=!0)):(await this.waitForMyTurn(),this.currentBatch+=1,t+=1,await this.wait(this.concurrencyDelay))}}catch(n){throw e&&(this.totalBatchCount-=e),t&&(this.currentBatch-=t),new Error(`Rate limiting failed: ${n.message}`)}}async waitForMyTurn(){let e=Date.now(),t=7*24*60*60*1e3;for(;this.currentBatch>=this.maxConcurrency;){if(Date.now()-e>t)throw new Error("Wait timeout exceeded (after 7 days) while waiting for a slot in the concurrency pool.");await this.wait(this.MIN_DELAY)}}removeBatch(){try{this.maxConcurrency>0&&this.totalBatchCount>0&&(this.currentBatch=Math.max(0,this.currentBatch-1),this.totalBatchCount=Math.max(0,this.totalBatchCount-1)),this.totalBatchCount<=0&&(this.totalBatchCount=0,this.isCurrentBatch=!1,this.currentBatch=0),this.currentBatch<=0&&(this.currentBatch=0,this.isCurrentBatch=!1)}catch(e){throw new Error(`Batch removal failed: ${e.message}`)}}setConcurrentOptions(e){if(e.maxConcurrency&&e.maxConcurrency<0)throw new Error("maxConcurrency must be non-negative");if(e.concurrencyDelay&&e.concurrencyDelay<this.MIN_DELAY)throw new Error(`concurrencyDelay must be at least ${this.MIN_DELAY}ms`);if(e.queueSize&&e.queueSize<0)throw new Error("queueSize must be non-negative");if(e.queueSize&&e.queueSize>1e4)throw new Error("queueSize must be less than or equal to 10,000, higher queueSize may cause performance issues. please disable queueSize to have no queue limit.");this.queueSize=e.queueSize||0,this.maxConcurrency=e.maxConcurrency||0,this.concurrencyDelay=e.concurrencyDelay||1e3,this.singleRequestDelay=typeof e.singleRequestDelay=="boolean"?e.singleRequestDelay:!0}wait(e){return new Promise(t=>{setTimeout(t,e)})}setCookies(e,t,n){Array.isArray(e)?this.jar.fromArray(e,n):typeof e=="string"&&(t&&e.includes("; ")?this.jar.parseCookieString(e,t,n):e.includes(`
`)&&e.split(" ").length>3&&this.jar.parseNetscapeCookies(e,n))}async get(e,t){return this.request(e,"GET",void 0,t)}clearCookies(){this.jar?.removeAllCookiesSync()}async post(e,t,n){return this.request(e,"POST",t,n)}async postForm(e,t,n){let i="";if(t instanceof URLSearchParams)i=t.toString();else if(t instanceof FormData){let o=[];for(let[c,a]of t.entries())o.push(`${c}=${a}`);i=o.join("&")}else if(typeof t=="string")i=t;else if(typeof t=="object"){let o=new URLSearchParams;for(let[c,a]of Object.entries(t))o.append(c,a?typeof a=="object"?JSON.stringify(a):a.toString():"");i=o.toString()}let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/x-www-form-urlencoded"),this.request(e,"POST",i,{...n,headers:s,isFormData:!0})}async postJson(e,t,n){let i={};if(typeof t=="string"){if(i=this.parseJson(t),!i)throw this.Error({status:400,statusText:"Bad Request"},"Invalid JSON string")}else i=t;let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/json"),this.request(e,"POST",JSON.stringify(i),{...n,headers:s,isJson:!0})}async put(e,t,n){return this.request(e,"POST",t,n)}async putForm(e,t,n){let i="";if(t instanceof URLSearchParams)i=t.toString();else if(t instanceof FormData){let o=[];for(let[c,a]of t.entries())o.push(`${c}=${a}`);i=o.join("&")}else if(typeof t=="string")i=t;else if(typeof t=="object"){let o=new URLSearchParams;for(let[c,a]of Object.entries(t))o.append(c,a?typeof a=="object"?JSON.stringify(a):a.toString():"");i=o.toString()}let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/x-www-form-urlencoded"),this.request(e,"PUT",i,{...n,headers:s,isFormData:!0})}async putJson(e,t,n){let i={};if(typeof t=="string"){if(i=this.parseJson(t),!i)throw this.Error({status:400,statusText:"Bad Request"},"Invalid JSON string")}else i=t;let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/json"),this.request(e,"PUT",JSON.stringify(i),{...n,headers:s,isJson:!0})}async patch(e,t,n){return this.request(e,"PATCH",t,n)}async patchForm(e,t,n){let i="";if(t instanceof URLSearchParams)i=t.toString();else if(t instanceof FormData){let o=[];for(let[c,a]of t.entries())o.push(`${c}=${a}`);i=o.join("&")}else if(typeof t=="string")i=t;else if(typeof t=="object"){let o=new URLSearchParams;for(let[c,a]of Object.entries(t))o.append(c,a?typeof a=="object"?JSON.stringify(a):a.toString():"");i=o.toString()}let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/x-www-form-urlencoded"),this.request(e,"PATCH",i,{...n,headers:s,isFormData:!0})}async patchJson(e,t,n){let i={};if(typeof t=="string"){if(i=this.parseJson(t),!i)throw this.Error({status:400,statusText:"Bad Request"},"Invalid JSON string")}else i=t;let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/json"),this.request(e,"PATCH",JSON.stringify(i),{...n,headers:s,isJson:!0})}async delete(e,t){return this.request(e,"DELETE",void 0,t)}async head(e,t){return this.request(e,"HEAD",void 0,t)}async options(e,t){return this.request(e,"OPTIONS",void 0,t)}parseJson(e){try{return JSON.parse(e)}catch{return null}}async Error(e,t,n,i){if(e instanceof Response){let s=e.headers.get("Content-Type"),o=await this.parseResponseBody(e,s),c={};return e.headers instanceof Headers&&e.headers.forEach((a,r)=>{r.toLowerCase()!=="set-cookie"&&r.toLowerCase()!=="set-cookies"&&(c[r]=a)}),new H(t??e.statusText??"Unknown error",e,o,c,n,void 0,i)}else if(e.headers){let s=e.body instanceof N?e?.body:e.body,o=e.headers??{},c=e.contentType??null;return new H(t??e.statusText??"Unknown error",e,s&&c?await this.parseResponseBody(e,c):s?s.toString("utf-8"):null,o,n,e)}return new H(t??"Unknown error",e??{},null,{})}async formatResponse(e,t,n,i,s,o=[]){let c=e instanceof Response?e.headers.get("Content-Type"):e.contentType,a=s?null:n?e instanceof Response?N.from(await e.arrayBuffer()):e.body:await this.parseResponseBody(e,c),r={},h;if(e instanceof Response){let y=e.headers.get("content-length");e.headers.forEach((u,l)=>{this.environment!=="browser"?l.toLowerCase()!=="set-cookie"&&l.toLowerCase()!=="set-cookies"&&(r[l]=u):r[l]=u}),y&&(h=parseInt(y))}else{let y=e.headers["content-length"];y&&(h=parseInt(y)),r=e.headers}return{urls:o,contentLength:h,data:a,status:e.status,statusText:e.statusText,headers:r,finalUrl:t,cookies:this.environment==="browser"?{array:[],string:"",netscape:""}:{array:this.jar.toArray(),string:this.jar.toCookieString(),netscape:this.jar.toNetscapeFormat()},config:i,contentType:c,...s}}async parseResponseBody(e,t){return t&&t.includes("application/json")?e instanceof Response?await e.json():e.body?JSON.parse(e.body.toString("utf-8")):{}:t&&["text","xml","xhtml+xml","html","php","javascript","ecmascript","x-javascript","typescript","x-httpd-php","x-php","x-python","x-python","x-ruby","x-ruby","x-sh","x-bash","x-java","x-java-source","x-c","x-c++","x-csrc","x-chdr","x-csharp","x-csh","x-go","x-go","x-scala","x-scala","x-rust","rust","x-swift","x-swift","x-kotlin","x-kotlin","x-perl","x-perl","x-lua","x-lua","x-haskell","x-haskell","x-sql","sql","css","csv","plain","markdown","x-markdown","x-latex","x-tex"].some(i=>t.includes(i))?e instanceof Response?await e.text():e.body?e.body.toString("utf-8"):"":e instanceof Response?await e.arrayBuffer():e.body?e.body:N.alloc(0)}prepareFetchOptions(e,t,n,i,s){let c=["post","put","patch"].includes(n.toLowerCase()),a={others:{}},r=e.headers instanceof Headers?e.headers:new Headers(e.headers||{}),h=e.contentType||r.get("Content-Type")||(c?"application/json":void 0);if(e.headers?a.headers=r instanceof Headers?r:new Headers(r):a.headers=new Headers,this.environment!=="browser"&&r.has("Cookie")){let u=r.get("Cookie");e.withCookies&&this.setCookies(u,t),r.delete("Cookie"),a.headers.delete("Cookie")}e.cookies&&e.withCookies&&this.setCookies(e.cookies,t);let y=[];if(this.environment!=="browser"&&(e.useAllCookies?y=this.jar.getAllCookies(t):y=this.jar.getCookies(t)),e.printHeaders&&(console.log("Cookie: ",y.map(u=>`${u.key}=${u.value}`).join("; ")),console.log("Cookies:",y)),y&&y.length>0&&e.withCookies&&a.headers.set("Cookie",y.map(u=>`${u.key}=${u.value}`).join("; ")),e.body&&(a.body=e.body),e?.debug&&console.log(e.body),e.isFormData||e.isJson)e.isFormData?(a.body=e.body,h="application/x-www-form-urlencoded",a.headers.set("Content-Type",h)):(a.body=e.body,h="application/json",a.headers.set("Content-Type",h));else if(e.json)a.body=JSON.stringify(e.json),h="application/json",a.headers.set("Content-Type",h);else if(e.form_params)a.body=new URLSearchParams(e.form_params).toString(),h="application/x-www-form-urlencoded",a.headers.set("Content-Type",h);else if(e.multipart){let u=new FormData;Object.entries(e.multipart).forEach(([l,g])=>{u.append(l,g)}),a.body=u}else if(e.requestType)switch(e.requestType){case"json":h="application/json",typeof a.body=="object"&&(a.body=JSON.stringify(a.body)),a.headers.set("Content-Type",h);break;case"form":h="application/x-www-form-urlencoded",typeof a.body=="object"&&(a.body=new URLSearchParams(a.body).toString()),a.headers.set("Content-Type",h);break;case"formData":if(typeof a.body=="object"){let u=new FormData;Object.entries(a.body).forEach(([l,g])=>{u.append(l,g)}),a.body=u}break;case"text":h="text/plain",a.headers.set("Content-Type",h);break}else if(h){let u=h.toLowerCase();if(u.includes("json"))a.headers.set("Content-Type","application/json"),a.body&&typeof a.body=="object"&&(a.body=JSON.stringify(a.body));else if(u.includes("x-www-form-urlencoded"))a.headers.set("Content-Type","application/x-www-form-urlencoded"),a.body&&typeof a.body=="object"&&(a.body=new URLSearchParams(a.body).toString());else if(u.includes("multipart")){if(a.body&&typeof a.body=="object"){let l=new FormData;Object.entries(a.body).forEach(([g,x])=>{l.append(g,x)}),a.body=l}}else u.includes("text/plain")&&a.headers.set("Content-Type","text/plain")}else h&&!e.withoutContentType&&a.headers.set("Content-Type",h);e.withoutContentType&&a.headers.delete("Content-Type"),e.withoutBodyOnRedirect&&i&&(a.body=void 0),e.printHeaders&&console.log("Fetch headers:",a.headers),(typeof e.autoSetReferer!="boolean"||e.autoSetReferer)&&s&&a.headers.set("Referer",s);for(let u of this.innerFetchOption)Object.keys(e).includes(u)&&typeof e[u]<"u"&&e[u]!==null&&(a.others[u]=e[u]);return a.credentials||(a.credentials="include"),this.environment!=="browser"&&(a.headers.set("Cache-Control","no-cache, no-store, must-revalidate"),a.headers.set("Pragma","no-cache"),a.headers.set("Expires","0")),typeof e.withCookies=="boolean"&&!e.withCookies&&(a.headers.delete("Cookie"),a.credentials="omit"),a}async getHeaders(e){let t=await this.fetch(e,{method:"HEAD"});return Object.fromEntries(t.headers.entries())}};var L=class{static rotateLeft(e,t){return e<<t|e>>>32-t}static addUnsigned(e,t){let n=e&1073741824,i=t&1073741824,s=e&2147483648,o=t&2147483648,c=(e&1073741823)+(t&1073741823);return n&i?c^2147483648^s^o:n|i?c&1073741824?c^3221225472^s^o:c^1073741824^s^o:c^s^o}static F(e,t,n){return e&t|~e&n}static G(e,t,n){return e&n|t&~n}static H(e,t,n){return e^t^n}static I(e,t,n){return t^(e|~n)}static FF(e,t,n,i,s,o,c){return e=this.addUnsigned(e,this.addUnsigned(this.addUnsigned(this.F(t,n,i),s),c)),this.addUnsigned(this.rotateLeft(e,o),t)}static GG(e,t,n,i,s,o,c){return e=this.addUnsigned(e,this.addUnsigned(this.addUnsigned(this.G(t,n,i),s),c)),this.addUnsigned(this.rotateLeft(e,o),t)}static HH(e,t,n,i,s,o,c){return e=this.addUnsigned(e,this.addUnsigned(this.addUnsigned(this.H(t,n,i),s),c)),this.addUnsigned(this.rotateLeft(e,o),t)}static II(e,t,n,i,s,o,c){return e=this.addUnsigned(e,this.addUnsigned(this.addUnsigned(this.I(t,n,i),s),c)),this.addUnsigned(this.rotateLeft(e,o),t)}static convertToWordArray(e){let t=e.length,n=((t+8>>6)+1)*16,i=Array(n-1),s=0,o=0;for(;o<t;){let a=(o-o%4)/4;s=o%4*8,i[a]=i[a]|e.charCodeAt(o)<<s,o++}let c=(o-o%4)/4;return s=o%4*8,i[c]=i[c]|128<<s,i[n-2]=t<<3,i[n-1]=t>>>29,i}static wordToHex(e){let t="";for(let n=0;n<=3;n++)t+=("0"+(e>>>n*8&255).toString(16)).slice(-2);return t}static md5(e){let t=this.convertToWordArray(e),n=1732584193,i=4023233417,s=2562383102,o=271733878,c=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21],a=[3614090360,3905402710,606105819,3250441966,4118548399,1200080426,2821735955,4249261313,1770035416,2336552879,4294925233,2304563134,1804603682,4254626195,2792965006,1236535329,4129170786,3225465664,643717713,3921069994,3593408605,38016083,3634488961,3889429448,568446438,3275163606,4107603335,1163531501,2850285829,4243563512,1735328473,2368359562,4294588738,2272392833,1839030562,4259657740,2763975236,1272893353,4139469664,3200236656,681279174,3936430074,3572445317,76029189,3654602809,3873151461,530742520,3299628645,4096336452,1126891415,2878612391,4237533241,1700485571,2399980690,4293915773,2240044497,1873313359,4264355552,2734768916,1309151649,4149444226,3174756917,718787259,3951481745];for(let r=0;r<t.length;r+=16){let h=n,y=i,u=s,l=o;n=this.FF(n,i,s,o,t[r],c[0],a[0]),o=this.FF(o,n,i,s,t[r+1],c[1],a[1]),s=this.FF(s,o,n,i,t[r+2],c[2],a[2]),i=this.FF(i,s,o,n,t[r+3],c[3],a[3]),n=this.FF(n,i,s,o,t[r+4],c[4],a[4]),o=this.FF(o,n,i,s,t[r+5],c[5],a[5]),s=this.FF(s,o,n,i,t[r+6],c[6],a[6]),i=this.FF(i,s,o,n,t[r+7],c[7],a[7]),n=this.FF(n,i,s,o,t[r+8],c[8],a[8]),o=this.FF(o,n,i,s,t[r+9],c[9],a[9]),s=this.FF(s,o,n,i,t[r+10],c[10],a[10]),i=this.FF(i,s,o,n,t[r+11],c[11],a[11]),n=this.FF(n,i,s,o,t[r+12],c[12],a[12]),o=this.FF(o,n,i,s,t[r+13],c[13],a[13]),s=this.FF(s,o,n,i,t[r+14],c[14],a[14]),i=this.FF(i,s,o,n,t[r+15],c[15],a[15]),n=this.GG(n,i,s,o,t[r+1],c[16],a[16]),o=this.GG(o,n,i,s,t[r+6],c[17],a[17]),s=this.GG(s,o,n,i,t[r+11],c[18],a[18]),i=this.GG(i,s,o,n,t[r],c[19],a[19]),n=this.GG(n,i,s,o,t[r+5],c[20],a[20]),o=this.GG(o,n,i,s,t[r+10],c[21],a[21]),s=this.GG(s,o,n,i,t[r+15],c[22],a[22]),i=this.GG(i,s,o,n,t[r+4],c[23],a[23]),n=this.GG(n,i,s,o,t[r+9],c[24],a[24]),o=this.GG(o,n,i,s,t[r+14],c[25],a[25]),s=this.GG(s,o,n,i,t[r+3],c[26],a[26]),i=this.GG(i,s,o,n,t[r+8],c[27],a[27]),n=this.GG(n,i,s,o,t[r+13],c[28],a[28]),o=this.GG(o,n,i,s,t[r+2],c[29],a[29]),s=this.GG(s,o,n,i,t[r+7],c[30],a[30]),i=this.GG(i,s,o,n,t[r+12],c[31],a[31]),n=this.HH(n,i,s,o,t[r+5],c[32],a[32]),o=this.HH(o,n,i,s,t[r+8],c[33],a[33]),s=this.HH(s,o,n,i,t[r+11],c[34],a[34]),i=this.HH(i,s,o,n,t[r+14],c[35],a[35]),n=this.HH(n,i,s,o,t[r+1],c[36],a[36]),o=this.HH(o,n,i,s,t[r+4],c[37],a[37]),s=this.HH(s,o,n,i,t[r+7],c[38],a[38]),i=this.HH(i,s,o,n,t[r+10],c[39],a[39]),n=this.HH(n,i,s,o,t[r+13],c[40],a[40]),o=this.HH(o,n,i,s,t[r],c[41],a[41]),s=this.HH(s,o,n,i,t[r+3],c[42],a[42]),i=this.HH(i,s,o,n,t[r+6],c[43],a[43]),n=this.HH(n,i,s,o,t[r+9],c[44],a[44]),o=this.HH(o,n,i,s,t[r+12],c[45],a[45]),s=this.HH(s,o,n,i,t[r+15],c[46],a[46]),i=this.HH(i,s,o,n,t[r+2],c[47],a[47]),n=this.II(n,i,s,o,t[r],c[48],a[48]),o=this.II(o,n,i,s,t[r+7],c[49],a[49]),s=this.II(s,o,n,i,t[r+14],c[50],a[50]),i=this.II(i,s,o,n,t[r+5],c[51],a[51]),n=this.II(n,i,s,o,t[r+12],c[52],a[52]),o=this.II(o,n,i,s,t[r+3],c[53],a[53]),s=this.II(s,o,n,i,t[r+10],c[54],a[54]),i=this.II(i,s,o,n,t[r+1],c[55],a[55]),n=this.II(n,i,s,o,t[r+8],c[56],a[56]),o=this.II(o,n,i,s,t[r+15],c[57],a[57]),s=this.II(s,o,n,i,t[r+6],c[58],a[58]),i=this.II(i,s,o,n,t[r+13],c[59],a[59]),n=this.II(n,i,s,o,t[r+4],c[60],a[60]),o=this.II(o,n,i,s,t[r+11],c[61],a[61]),s=this.II(s,o,n,i,t[r+2],c[62],a[62]),i=this.II(i,s,o,n,t[r+9],c[63],a[63]),n=this.addUnsigned(n,h),i=this.addUnsigned(i,y),s=this.addUnsigned(s,u),o=this.addUnsigned(o,l)}return this.wordToHex(n)+this.wordToHex(i)+this.wordToHex(s)+this.wordToHex(o)}};function z(d){if(d instanceof Date)return d;if(typeof d=="string"&&d!=="Infinity")return ce(d)?new Date(V(d)):new Date(d);if(typeof d=="number")return new Date(V(d))}function ce(d){return/^[0-9]+$/.test(d)}Date.prototype.addDay=function(d){let e=new Date(this);return e.setDate(e.getDate()+d),e};function V(d){let e=d.toString().trim();try{if(typeof d=="number")return e.length===13?d:d*1e3;let t=parseInt(e);return t.toString().length===13?t:t*1e3}catch{return 0}}var k=class d{key;value;expires;isSession;maxAge;domain;path;secure;httpOnly;extensions;creation;creationIndex;hostOnly;pathIsDefault;lastAccessed;sameSite;plainDomain;accessType;hash;constructor(e){this.isSession=!(e.expires||e.maxAge),e={...e,expires:z(e.expires)??"Infinity",creation:z(e.creation),lastAccessed:z(e.lastAccessed)},this.key=e.key||"",this.value=e.value||"",this.expires=e.expires||null,this.maxAge=e.maxAge||null,this.domain=e.domain||null,this.path=e.path||null,this.secure=e.secure||!1,this.httpOnly=e.httpOnly||!1,this.extensions=e.extensions||null,this.creation=e.creation||new Date,this.creationIndex=d.cookiesCreated++,this.hostOnly=e.hostOnly||null,this.pathIsDefault=e.pathIsDefault||null,this.lastAccessed=e.lastAccessed||new Date,this.sameSite=e.sameSite;let t=e.domain&&e.domain.startsWith(".")?"wildcard":"matchDomainOnly",n=e.path&&e.path!=="/"&&e.path.length>1?"matchPathOnly":"";n&&t==="matchDomainOnly"?this.accessType="matchDomainAndPath":n&&t==="wildcard"?this.accessType="matchPathOnly":t==="matchDomainOnly"?this.accessType="matchDomainOnly":this.accessType="wildcard",this.plainDomain=this.domain?this.domain.startsWith(".")?this.domain.substring(1):this.domain:null,this.hash=this.domain?L.md5(`${this.domain.toString()}_${this.key}`):null}toJSON(){let e={};return d.serializableProperties.forEach(t=>{this[t]!==void 0&&(this[t]instanceof Date?e[t]=this[t].toISOString():e[t]=this[t])}),e}clone(){return d.fromJSON(this.toJSON())}validate(){return!(!this.key||this.key.trim()===""||this.value===void 0||this.expires&&!(this.expires instanceof Date)&&this.expires!=="Infinity"||this.maxAge!==null&&typeof this.maxAge!="number"&&this.maxAge!=="Infinity"&&this.maxAge!=="-Infinity"||this.domain&&typeof this.domain!="string"||this.path&&typeof this.path!="string"||typeof this.secure!="boolean"||typeof this.httpOnly!="boolean"||this.sameSite&&!["Strict","Lax","None"].includes(this.sameSite))}setExpires(e){this.expires=e instanceof Date?e:d.parseDate(e)}setMaxAge(e){this.maxAge=isFinite(e)?e:e===1/0?"Infinity":"-Infinity"}cookieString(){return`${this.key}=${this.value}`}toSetCookieString(){let e=this.cookieString();return this.expires instanceof Date&&(e+=`; Expires=${this.expires.toUTCString()}`),this.maxAge!=null&&(e+=`; Max-Age=${this.maxAge}`),this.domain&&(e+=`; Domain=${this.domain}`),this.path&&(e+=`; Path=${this.path}`),this.secure&&(e+="; Secure"),this.httpOnly&&(e+="; HttpOnly"),this.sameSite&&(e+=`; SameSite=${this.sameSite}`),this.extensions&&(e+=`; ${this.extensions.join("; ")}`),e}toArray(){let e={key:this.key,value:this.value};return this.domain&&(e.domain=this.domain),this.path&&(e.path=this.path),this.secure&&(e.secure=this.secure),this.httpOnly&&(e.httpOnly=this.httpOnly),this.sameSite&&(e.sameSite=this.sameSite),this.extensions&&(e.extensions=this.extensions),this.expires&&(e.expires=this.expires),this.creation&&(e.creation=this.creation),this.lastAccessed&&(e.lastAccessed=this.lastAccessed),this.hostOnly&&(e.hostOnly=this.hostOnly),this.pathIsDefault&&(e.pathIsDefault=this.pathIsDefault),this.hash&&(e.hash=this.hash),this.plainDomain&&(e.plainDomain=this.plainDomain),this.maxAge&&(e.maxAge=this.maxAge),e}toString(){return`${this.key}=${this.value}`}toNetscapeFormat(){let e=this.hostOnly?this.domain:this.domain.startsWith(".")?this.domain:"."+this.domain,t=this.secure?"TRUE":"FALSE",n=this.expires&&typeof this.expires!="string"?Math.round(this.expires.getTime()/1e3):0;return`${e} TRUE ${this.path} ${t} ${n} ${this.key} ${this.value}`}TTL(e=Date.now()){return this.expires==="Infinity"||!this.expires?1/0:Math.max(0,this.expires.getTime()-e)}expiryTime(e=new Date){if(this.maxAge!=null){let t=this.maxAge==="Infinity"?1/0:Number(this.maxAge)*1e3;return(this.lastAccessed instanceof Date?this.lastAccessed:e).getTime()+t}return this.expires instanceof Date?this.expires.getTime():void 0}isPersistent(){return this.expires!=null||this.maxAge!=null}canonicalizedDomain(){return this.domain?d.canonicalDomain(this.domain):void 0}cdomain(){return this.canonicalizedDomain()}static parse(e,t={}){try{let n=e.split(";").map(u=>u.trim()),[i,...s]=n,[o,...c]=i.split("=").map(u=>u.trim()),a=c.join("=");if(!o&&!t.loose)return;let r=new d({key:o,value:a});s.forEach(u=>{let[l,g]=u.split("=").map(x=>x.trim());switch(l.toLowerCase()){case"expires":r.expires=d.parseDate(g);break;case"max-age":r.setMaxAge(parseInt(g,10));break;case"domain":r.domain=g;break;case"path":r.path=g;break;case"secure":r.secure=!0;break;case"httponly":r.httpOnly=!0;break;case"samesite":r.sameSite=g;break;default:r.extensions||(r.extensions=[]),r.extensions.push(u)}}),r.isSession=!r.expires;let h=r.domain&&r.domain.startsWith(".")?"wildcard":"matchDomainOnly",y=r.path&&r.path!=="/"&&r.path.length>1?"matchPathOnly":"";return y&&h==="matchDomainOnly"?r.accessType="matchDomainAndPath":y&&h==="wildcard"?r.accessType="matchPathOnly":h==="matchDomainOnly"?r.accessType="matchDomainOnly":r.accessType="wildcard",r}catch{return}}static fromJSONString(e){if(typeof e=="string")try{e=JSON.parse(e)}catch{return}if(typeof e!="object"||e===null)return;let t={};return d.serializableProperties.forEach(n=>{e[n]!==void 0&&(n==="expires"||n==="creation"||n==="lastAccessed"?t[n]=new Date(e[n]):t[n]=e[n])}),new d(t)}static fromJSON(e){if(typeof e=="object"&&e!==null)try{return new d(e)}catch{return}}static parseDate(e){return new Date(e)}static canonicalDomain(e){return e.toLowerCase()}static cookiesCreated=0;static defaultPath="/";static sameSiteLevel={strict:3,lax:2,none:1};static sameSiteCanonical={strict:"Strict",lax:"Lax"};static serializableProperties=["key","value","expires","maxAge","domain","path","secure","httpOnly","extensions","hostOnly","pathIsDefault","creation","lastAccessed","sameSite"];isDomainMatch(e,t){return e=this.isValidUrl(e)?new URL(e).hostname:e,this.isDomainMatching(t,e)}inDomain(e,t=!0){return this.domain?this.isValidUrl(e)?this.isMatched(e,this.domain):this.isDomainMatch(e,this.domain):t}isMatched(e,t){let n=new URL(e).pathname;return n=n.endsWith("/")?n:`${n}/`,e=new URL(e).hostname,this.accessType==="wildcard"?this.isDomainMatching(t,e):this.accessType==="matchDomainAndPath"&&this.isDomainMatching(t,e)&&this.isPathMatching(this.path??"/",n)||this.accessType==="matchPathOnly"&&this.isPathMatching(this.path??"/",n)?!0:!!(this.accessType==="matchDomainOnly"&&this.isDomainMatching(t,e))}isDomainMatching(e,t){if(e=e.toLowerCase(),t=t.toLowerCase(),!e.startsWith("."))return e===t;let n=e.slice(1);return t===n||t.endsWith("."+n)}isPathMatching(e,t){let n=this.normalizePath(e);return t.startsWith("/")||(t="/"+t),t.startsWith(n)}normalizePath(e){let t=e.trim();return(t==="."||t==="./")&&(t="/"),t.startsWith("/")||(t="/"+t),t.length>1&&t.endsWith("/")&&(t=t.slice(0,-1)),t}isValidUrl(e){try{return new URL(e),e.startsWith("http")||e.startsWith("https")}catch{return!1}}};var q=class{constructor(e=!1){this.debug=e}cookies=[];setCookieSync(e,t,n=!0){let i=this.getDomain(t);if(!i)return;e.domain=e.domain?e.domain:i;let s=e.domain?L.md5(`${e.domain.toString()}_${e.key}`):null;e.lastAccessed=new Date;let o=!1;if(s&&this.cookies.find(c=>c.hash===s)){if(n){let c=this.cookies.find(a=>a.hash===s);c&&(e.creationIndex=c.creationIndex,e.creation=c.creation),this.cookies=this.cookies.filter(a=>a.hash!==s)}o=!0}o||(e.creationIndex=this.cookies.length),s&&(e.hash=s),(!o||n)&&this.cookies.push(e),this.removeExpiredCookies()}setResponseCookies(e,t){if(e instanceof Response)if(e?.headers&&typeof e.headers?.getSetCookie<"u")for(let i of e.headers.getSetCookie()){let s=k.parse(i.trim());s&&this.setCookieSync(s,t)}else{let i=e?.headers?.get("set-cookie");i&&i.split(",").forEach(s=>{let o=k.parse(s);o&&this.setCookieSync(o,t)})}else Array.isArray(e)?typeof e[0]=="string"?e.forEach(n=>{let i=k.parse(n.trim());i&&this.setCookieSync(i,t)}):e[0]instanceof k?e.forEach(n=>this.setCookieSync(n,t)):e.forEach(n=>{let i=k.fromJSON(n);i&&this.setCookieSync(i,t)}):typeof e=="string"&&e.includes("=")&&e.includes(",")&&e.split(",").forEach(n=>{let i=k.parse(n);i&&this.setCookieSync(i,t)})}toNetscapeFormat(e){this.removeExpiredCookies();let t=`# Netscape HTTP Cookie File
"use strict";var ee=Object.create;var j=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,se=Object.prototype.hasOwnProperty;var oe=(u,e)=>{for(var t in e)j(u,t,{get:e[t],enumerable:!0})},K=(u,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ne(e))!se.call(u,i)&&i!==t&&j(u,i,{get:()=>e[i],enumerable:!(n=te(e,i))||n.enumerable});return u};var B=(u,e,t)=>(t=u!=null?ee(ie(u)):{},K(e||!u||!u.__esModule?j(t,"default",{value:u,enumerable:!0}):t,u)),re=u=>K(j({},"__esModule",{value:!0}),u);var ye={};oe(ye,{FormData:()=>S,Uniqhtt:()=>pe,default:()=>fe,uniqhtt:()=>Q});module.exports=re(ye);var $=require("node:buffer"),H=class u extends Error{response={};constructor(e,t,n,i,s,o,a){if(super(e),t instanceof Response){let c=t.headers.get("Content-Length");this.response={urls:a||[t.url],data:n,status:t.status,statusText:t.statusText,finalUrl:t.url,cookies:void 0,headers:i,contentType:t.headers.get("Content-Type"),contentLength:c?parseInt(c):void 0,config:s}}else o?this.response={data:n,urls:a||[o.url],status:o?.status,statusText:o?.statusText,finalUrl:o?.url,cookies:void 0,headers:o.headers,contentType:o.contentType,contentLength:o.contentLength?parseInt(o.contentLength):void 0,config:s}:this.response={data:n,urls:a||[],status:t?.status,statusText:t?.statusText,finalUrl:t?.url,cookies:t?.cookies??void 0,headers:i,contentType:void 0,config:s,contentLength:void 0};Object.setPrototypeOf(this,u.prototype)}},M=class{jar=null;fetch;innerFetchOption=["headers","mode","cache","referrerPolicy","integrity","keepalive","compress"];environment="node";maxConcurrency=0;concurrencyDelay=1e3;singleRequestDelay=!1;totalBatchCount=0;isCurrentBatch=!1;currentBatch=0;queueSize=0;MIN_DELAY=100;defaultUserAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";constructor(e){this.fetch=fetch,e?.concurrentOpt&&this.setConcurrentOptions(e.concurrentOpt)}async checkForBatch(){try{this.maxConcurrency>0&&this.singleRequestDelay===!1&&this.isCurrentBatch&&await this.checkForBatchWithDelay()}catch(e){throw new Error(`Batch check failed: ${e.message}`)}}async checkForBatchWithDelay(){let e=Date.now(),t=7*24*60*60*1e3;for(;this.currentBatch>0&&this.isCurrentBatch;){if(Date.now()-e>t)throw new Error("Batch processing timeout exceeded (after 7 days) while waiting for a slot in the concurrency pool.");await this.wait(this.MIN_DELAY)}this.currentBatch=0,this.isCurrentBatch=!1,this.totalBatchCount>0&&this.concurrencyDelay>this.MIN_DELAY&&await this.wait(this.concurrencyDelay)}async rateLimiter(){let e=0,t=0;try{if(this.maxConcurrency>0){if(this.queueSize>0&&this.totalBatchCount+1>=this.queueSize)throw new Error("Request queue is full");this.totalBatchCount+=1,e=1,this.singleRequestDelay===!1?(await this.checkForBatch(),this.currentBatch+=1,t+=1,this.currentBatch>=this.maxConcurrency&&(this.isCurrentBatch=!0)):(await this.waitForMyTurn(),this.currentBatch+=1,t+=1,await this.wait(this.concurrencyDelay))}}catch(n){throw e&&(this.totalBatchCount-=e),t&&(this.currentBatch-=t),new Error(`Rate limiting failed: ${n.message}`)}}async waitForMyTurn(){let e=Date.now(),t=7*24*60*60*1e3;for(;this.currentBatch>=this.maxConcurrency;){if(Date.now()-e>t)throw new Error("Wait timeout exceeded (after 7 days) while waiting for a slot in the concurrency pool.");await this.wait(this.MIN_DELAY)}}removeBatch(){try{this.maxConcurrency>0&&this.totalBatchCount>0&&(this.currentBatch=Math.max(0,this.currentBatch-1),this.totalBatchCount=Math.max(0,this.totalBatchCount-1)),this.totalBatchCount<=0&&(this.totalBatchCount=0,this.isCurrentBatch=!1,this.currentBatch=0),this.currentBatch<=0&&(this.currentBatch=0,this.isCurrentBatch=!1)}catch(e){throw new Error(`Batch removal failed: ${e.message}`)}}setConcurrentOptions(e){if(e.maxConcurrency&&e.maxConcurrency<0)throw new Error("maxConcurrency must be non-negative");if(e.concurrencyDelay&&e.concurrencyDelay<this.MIN_DELAY)throw new Error(`concurrencyDelay must be at least ${this.MIN_DELAY}ms`);if(e.queueSize&&e.queueSize<0)throw new Error("queueSize must be non-negative");if(e.queueSize&&e.queueSize>1e4)throw new Error("queueSize must be less than or equal to 10,000, higher queueSize may cause performance issues. please disable queueSize to have no queue limit.");this.queueSize=e.queueSize||0,this.maxConcurrency=e.maxConcurrency||0,this.concurrencyDelay=e.concurrencyDelay||1e3,this.singleRequestDelay=typeof e.singleRequestDelay=="boolean"?e.singleRequestDelay:!0}wait(e){return new Promise(t=>{setTimeout(t,e)})}setCookies(e,t,n){Array.isArray(e)?this.jar.fromArray(e,n):typeof e=="string"&&(t&&e.includes("; ")?this.jar.parseCookieString(e,t,n):e.includes(`
`)&&e.split(" ").length>3&&this.jar.parseNetscapeCookies(e,n))}async get(e,t){return this.request(e,"GET",void 0,t)}clearCookies(){this.jar?.removeAllCookiesSync()}async post(e,t,n){return this.request(e,"POST",t,n)}async postForm(e,t,n){let i="";if(t instanceof URLSearchParams)i=t.toString();else if(t instanceof FormData){let o=[];for(let[a,c]of t.entries())o.push(`${a}=${c}`);i=o.join("&")}else if(typeof t=="string")i=t;else if(typeof t=="object"){let o=new URLSearchParams;for(let[a,c]of Object.entries(t))o.append(a,c?typeof c=="object"?JSON.stringify(c):c.toString():"");i=o.toString()}let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/x-www-form-urlencoded"),this.request(e,"POST",i,{...n,headers:s,isFormData:!0})}async postJson(e,t,n){let i={};if(typeof t=="string"){if(i=this.parseJson(t),!i)throw this.Error({status:400,statusText:"Bad Request"},"Invalid JSON string")}else i=t;let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/json"),this.request(e,"POST",JSON.stringify(i),{...n,headers:s,isJson:!0})}async put(e,t,n){return this.request(e,"POST",t,n)}async putForm(e,t,n){let i="";if(t instanceof URLSearchParams)i=t.toString();else if(t instanceof FormData){let o=[];for(let[a,c]of t.entries())o.push(`${a}=${c}`);i=o.join("&")}else if(typeof t=="string")i=t;else if(typeof t=="object"){let o=new URLSearchParams;for(let[a,c]of Object.entries(t))o.append(a,c?typeof c=="object"?JSON.stringify(c):c.toString():"");i=o.toString()}let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/x-www-form-urlencoded"),this.request(e,"PUT",i,{...n,headers:s,isFormData:!0})}async putJson(e,t,n){let i={};if(typeof t=="string"){if(i=this.parseJson(t),!i)throw this.Error({status:400,statusText:"Bad Request"},"Invalid JSON string")}else i=t;let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/json"),this.request(e,"PUT",JSON.stringify(i),{...n,headers:s,isJson:!0})}async patch(e,t,n){return this.request(e,"PATCH",t,n)}async patchForm(e,t,n){let i="";if(t instanceof URLSearchParams)i=t.toString();else if(t instanceof FormData){let o=[];for(let[a,c]of t.entries())o.push(`${a}=${c}`);i=o.join("&")}else if(typeof t=="string")i=t;else if(typeof t=="object"){let o=new URLSearchParams;for(let[a,c]of Object.entries(t))o.append(a,c?typeof c=="object"?JSON.stringify(c):c.toString():"");i=o.toString()}let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/x-www-form-urlencoded"),this.request(e,"PATCH",i,{...n,headers:s,isFormData:!0})}async patchJson(e,t,n){let i={};if(typeof t=="string"){if(i=this.parseJson(t),!i)throw this.Error({status:400,statusText:"Bad Request"},"Invalid JSON string")}else i=t;let s=n?.headers?n.headers instanceof Headers?n.headers:new Headers(n.headers):new Headers;return s.set("Content-Type","application/json"),this.request(e,"PATCH",JSON.stringify(i),{...n,headers:s,isJson:!0})}async delete(e,t){return this.request(e,"DELETE",void 0,t)}async head(e,t){return this.request(e,"HEAD",void 0,t)}async options(e,t){return this.request(e,"OPTIONS",void 0,t)}parseJson(e){try{return JSON.parse(e)}catch{return null}}async Error(e,t,n,i){if(e instanceof Response){let s=e.headers.get("Content-Type"),o=await this.parseResponseBody(e,s),a={};return e.headers instanceof Headers&&e.headers.forEach((c,r)=>{r.toLowerCase()!=="set-cookie"&&r.toLowerCase()!=="set-cookies"&&(a[r]=c)}),new H(t??e.statusText??"Unknown error",e,o,a,n,void 0,i)}else if(e.headers){let s=e.body instanceof $.Buffer?e?.body:e.body,o=e.headers??{},a=e.contentType??null;return new H(t??e.statusText??"Unknown error",e,s&&a?await this.parseResponseBody(e,a):s?s.toString("utf-8"):null,o,n,e)}return new H(t??"Unknown error",e??{},null,{})}async formatResponse(e,t,n,i,s,o=[]){let a=e instanceof Response?e.headers.get("Content-Type"):e.contentType,c=s?null:n?e instanceof Response?$.Buffer.from(await e.arrayBuffer()):e.body:await this.parseResponseBody(e,a),r={},f;if(e instanceof Response){let g=e.headers.get("content-length");e.headers.forEach((h,l)=>{r[l]=h}),g&&(f=parseInt(g))}else{let g=e.headers["content-length"];g&&(f=parseInt(g)),r=e.headers}return{urls:o,contentLength:f,data:c,status:e.status,statusText:e.statusText,headers:r,finalUrl:t,cookies:{array:this.jar.toArray(),string:this.jar.toCookieString(),netscape:this.jar.toNetscapeFormat()},config:i,contentType:a,...s}}async parseResponseBody(e,t){return t&&t.includes("application/json")?e instanceof Response?await e.json():e.body?JSON.parse(e.body.toString("utf-8")):{}:t&&["text","xml","xhtml+xml","html","php","javascript","ecmascript","x-javascript","typescript","x-httpd-php","x-php","x-python","x-python","x-ruby","x-ruby","x-sh","x-bash","x-java","x-java-source","x-c","x-c++","x-csrc","x-chdr","x-csharp","x-csh","x-go","x-go","x-scala","x-scala","x-rust","rust","x-swift","x-swift","x-kotlin","x-kotlin","x-perl","x-perl","x-lua","x-lua","x-haskell","x-haskell","x-sql","sql","css","csv","plain","markdown","x-markdown","x-latex","x-tex"].some(i=>t.includes(i))?e instanceof Response?await e.text():e.body?e.body.toString("utf-8"):"":e instanceof Response?await e.arrayBuffer():e.body?e.body:$.Buffer.alloc(0)}async getHeaders(e){let t=await this.fetch(e,{method:"HEAD"});return Object.fromEntries(t.headers.entries())}};var L=class{static rotateLeft(e,t){return e<<t|e>>>32-t}static addUnsigned(e,t){let n=e&1073741824,i=t&1073741824,s=e&2147483648,o=t&2147483648,a=(e&1073741823)+(t&1073741823);return n&i?a^2147483648^s^o:n|i?a&1073741824?a^3221225472^s^o:a^1073741824^s^o:a^s^o}static F(e,t,n){return e&t|~e&n}static G(e,t,n){return e&n|t&~n}static H(e,t,n){return e^t^n}static I(e,t,n){return t^(e|~n)}static FF(e,t,n,i,s,o,a){return e=this.addUnsigned(e,this.addUnsigned(this.addUnsigned(this.F(t,n,i),s),a)),this.addUnsigned(this.rotateLeft(e,o),t)}static GG(e,t,n,i,s,o,a){return e=this.addUnsigned(e,this.addUnsigned(this.addUnsigned(this.G(t,n,i),s),a)),this.addUnsigned(this.rotateLeft(e,o),t)}static HH(e,t,n,i,s,o,a){return e=this.addUnsigned(e,this.addUnsigned(this.addUnsigned(this.H(t,n,i),s),a)),this.addUnsigned(this.rotateLeft(e,o),t)}static II(e,t,n,i,s,o,a){return e=this.addUnsigned(e,this.addUnsigned(this.addUnsigned(this.I(t,n,i),s),a)),this.addUnsigned(this.rotateLeft(e,o),t)}static convertToWordArray(e){let t=e.length,n=((t+8>>6)+1)*16,i=Array(n-1),s=0,o=0;for(;o<t;){let c=(o-o%4)/4;s=o%4*8,i[c]=i[c]|e.charCodeAt(o)<<s,o++}let a=(o-o%4)/4;return s=o%4*8,i[a]=i[a]|128<<s,i[n-2]=t<<3,i[n-1]=t>>>29,i}static wordToHex(e){let t="";for(let n=0;n<=3;n++)t+=("0"+(e>>>n*8&255).toString(16)).slice(-2);return t}static md5(e){let t=this.convertToWordArray(e),n=1732584193,i=4023233417,s=2562383102,o=271733878,a=[7,12,17,22,5,9,14,20,4,11,16,23,6,10,15,21],c=[3614090360,3905402710,606105819,3250441966,4118548399,1200080426,2821735955,4249261313,1770035416,2336552879,4294925233,2304563134,1804603682,4254626195,2792965006,1236535329,4129170786,3225465664,643717713,3921069994,3593408605,38016083,3634488961,3889429448,568446438,3275163606,4107603335,1163531501,2850285829,4243563512,1735328473,2368359562,4294588738,2272392833,1839030562,4259657740,2763975236,1272893353,4139469664,3200236656,681279174,3936430074,3572445317,76029189,3654602809,3873151461,530742520,3299628645,4096336452,1126891415,2878612391,4237533241,1700485571,2399980690,4293915773,2240044497,1873313359,4264355552,2734768916,1309151649,4149444226,3174756917,718787259,3951481745];for(let r=0;r<t.length;r+=16){let f=n,g=i,h=s,l=o;n=this.FF(n,i,s,o,t[r],a[0],c[0]),o=this.FF(o,n,i,s,t[r+1],a[1],c[1]),s=this.FF(s,o,n,i,t[r+2],a[2],c[2]),i=this.FF(i,s,o,n,t[r+3],a[3],c[3]),n=this.FF(n,i,s,o,t[r+4],a[4],c[4]),o=this.FF(o,n,i,s,t[r+5],a[5],c[5]),s=this.FF(s,o,n,i,t[r+6],a[6],c[6]),i=this.FF(i,s,o,n,t[r+7],a[7],c[7]),n=this.FF(n,i,s,o,t[r+8],a[8],c[8]),o=this.FF(o,n,i,s,t[r+9],a[9],c[9]),s=this.FF(s,o,n,i,t[r+10],a[10],c[10]),i=this.FF(i,s,o,n,t[r+11],a[11],c[11]),n=this.FF(n,i,s,o,t[r+12],a[12],c[12]),o=this.FF(o,n,i,s,t[r+13],a[13],c[13]),s=this.FF(s,o,n,i,t[r+14],a[14],c[14]),i=this.FF(i,s,o,n,t[r+15],a[15],c[15]),n=this.GG(n,i,s,o,t[r+1],a[16],c[16]),o=this.GG(o,n,i,s,t[r+6],a[17],c[17]),s=this.GG(s,o,n,i,t[r+11],a[18],c[18]),i=this.GG(i,s,o,n,t[r],a[19],c[19]),n=this.GG(n,i,s,o,t[r+5],a[20],c[20]),o=this.GG(o,n,i,s,t[r+10],a[21],c[21]),s=this.GG(s,o,n,i,t[r+15],a[22],c[22]),i=this.GG(i,s,o,n,t[r+4],a[23],c[23]),n=this.GG(n,i,s,o,t[r+9],a[24],c[24]),o=this.GG(o,n,i,s,t[r+14],a[25],c[25]),s=this.GG(s,o,n,i,t[r+3],a[26],c[26]),i=this.GG(i,s,o,n,t[r+8],a[27],c[27]),n=this.GG(n,i,s,o,t[r+13],a[28],c[28]),o=this.GG(o,n,i,s,t[r+2],a[29],c[29]),s=this.GG(s,o,n,i,t[r+7],a[30],c[30]),i=this.GG(i,s,o,n,t[r+12],a[31],c[31]),n=this.HH(n,i,s,o,t[r+5],a[32],c[32]),o=this.HH(o,n,i,s,t[r+8],a[33],c[33]),s=this.HH(s,o,n,i,t[r+11],a[34],c[34]),i=this.HH(i,s,o,n,t[r+14],a[35],c[35]),n=this.HH(n,i,s,o,t[r+1],a[36],c[36]),o=this.HH(o,n,i,s,t[r+4],a[37],c[37]),s=this.HH(s,o,n,i,t[r+7],a[38],c[38]),i=this.HH(i,s,o,n,t[r+10],a[39],c[39]),n=this.HH(n,i,s,o,t[r+13],a[40],c[40]),o=this.HH(o,n,i,s,t[r],a[41],c[41]),s=this.HH(s,o,n,i,t[r+3],a[42],c[42]),i=this.HH(i,s,o,n,t[r+6],a[43],c[43]),n=this.HH(n,i,s,o,t[r+9],a[44],c[44]),o=this.HH(o,n,i,s,t[r+12],a[45],c[45]),s=this.HH(s,o,n,i,t[r+15],a[46],c[46]),i=this.HH(i,s,o,n,t[r+2],a[47],c[47]),n=this.II(n,i,s,o,t[r],a[48],c[48]),o=this.II(o,n,i,s,t[r+7],a[49],c[49]),s=this.II(s,o,n,i,t[r+14],a[50],c[50]),i=this.II(i,s,o,n,t[r+5],a[51],c[51]),n=this.II(n,i,s,o,t[r+12],a[52],c[52]),o=this.II(o,n,i,s,t[r+3],a[53],c[53]),s=this.II(s,o,n,i,t[r+10],a[54],c[54]),i=this.II(i,s,o,n,t[r+1],a[55],c[55]),n=this.II(n,i,s,o,t[r+8],a[56],c[56]),o=this.II(o,n,i,s,t[r+15],a[57],c[57]),s=this.II(s,o,n,i,t[r+6],a[58],c[58]),i=this.II(i,s,o,n,t[r+13],a[59],c[59]),n=this.II(n,i,s,o,t[r+4],a[60],c[60]),o=this.II(o,n,i,s,t[r+11],a[61],c[61]),s=this.II(s,o,n,i,t[r+2],a[62],c[62]),i=this.II(i,s,o,n,t[r+9],a[63],c[63]),n=this.addUnsigned(n,f),i=this.addUnsigned(i,g),s=this.addUnsigned(s,h),o=this.addUnsigned(o,l)}return this.wordToHex(n)+this.wordToHex(i)+this.wordToHex(s)+this.wordToHex(o)}};function z(u){if(u instanceof Date)return u;if(typeof u=="string"&&u!=="Infinity")return ae(u)?new Date(V(u)):new Date(u);if(typeof u=="number")return new Date(V(u))}function ae(u){return/^[0-9]+$/.test(u)}Date.prototype.addDay=function(u){let e=new Date(this);return e.setDate(e.getDate()+u),e};function V(u){let e=u.toString().trim();try{if(typeof u=="number")return e.length===13?u:u*1e3;let t=parseInt(e);return t.toString().length===13?t:t*1e3}catch{return 0}}var k=class u{key;value;expires;isSession;maxAge;domain;path;secure;httpOnly;extensions;creation;creationIndex;hostOnly;pathIsDefault;lastAccessed;sameSite;plainDomain;accessType;hash;constructor(e){this.isSession=!(e.expires||e.maxAge),e={...e,expires:z(e.expires)??"Infinity",creation:z(e.creation),lastAccessed:z(e.lastAccessed)},this.key=e.key||"",this.value=e.value||"",this.expires=e.expires||null,this.maxAge=e.maxAge||null,this.domain=e.domain||null,this.path=e.path||null,this.secure=e.secure||!1,this.httpOnly=e.httpOnly||!1,this.extensions=e.extensions||null,this.creation=e.creation||new Date,this.creationIndex=u.cookiesCreated++,this.hostOnly=e.hostOnly||null,this.pathIsDefault=e.pathIsDefault||null,this.lastAccessed=e.lastAccessed||new Date,this.sameSite=e.sameSite;let t=e.domain&&e.domain.startsWith(".")?"wildcard":"matchDomainOnly",n=e.path&&e.path!=="/"&&e.path.length>1?"matchPathOnly":"";n&&t==="matchDomainOnly"?this.accessType="matchDomainAndPath":n&&t==="wildcard"?this.accessType="matchPathOnly":t==="matchDomainOnly"?this.accessType="matchDomainOnly":this.accessType="wildcard",this.plainDomain=this.domain?this.domain.startsWith(".")?this.domain.substring(1):this.domain:null,this.hash=this.domain?L.md5(`${this.domain.toString()}_${this.key}`):null}toJSON(){let e={};return u.serializableProperties.forEach(t=>{this[t]!==void 0&&(this[t]instanceof Date?e[t]=this[t].toISOString():e[t]=this[t])}),e}clone(){return u.fromJSON(this.toJSON())}validate(){return!(!this.key||this.key.trim()===""||this.value===void 0||this.expires&&!(this.expires instanceof Date)&&this.expires!=="Infinity"||this.maxAge!==null&&typeof this.maxAge!="number"&&this.maxAge!=="Infinity"&&this.maxAge!=="-Infinity"||this.domain&&typeof this.domain!="string"||this.path&&typeof this.path!="string"||typeof this.secure!="boolean"||typeof this.httpOnly!="boolean"||this.sameSite&&!["Strict","Lax","None"].includes(this.sameSite))}setExpires(e){this.expires=e instanceof Date?e:u.parseDate(e)}setMaxAge(e){this.maxAge=isFinite(e)?e:e===1/0?"Infinity":"-Infinity"}cookieString(){return`${this.key}=${this.value}`}toSetCookieString(){let e=this.cookieString();return this.expires instanceof Date&&(e+=`; Expires=${this.expires.toUTCString()}`),this.maxAge!=null&&(e+=`; Max-Age=${this.maxAge}`),this.domain&&(e+=`; Domain=${this.domain}`),this.path&&(e+=`; Path=${this.path}`),this.secure&&(e+="; Secure"),this.httpOnly&&(e+="; HttpOnly"),this.sameSite&&(e+=`; SameSite=${this.sameSite}`),this.extensions&&(e+=`; ${this.extensions.join("; ")}`),e}toArray(){let e={key:this.key,value:this.value};return this.domain&&(e.domain=this.domain),this.path&&(e.path=this.path),this.secure&&(e.secure=this.secure),this.httpOnly&&(e.httpOnly=this.httpOnly),this.sameSite&&(e.sameSite=this.sameSite),this.extensions&&(e.extensions=this.extensions),this.expires&&(e.expires=this.expires),this.creation&&(e.creation=this.creation),this.lastAccessed&&(e.lastAccessed=this.lastAccessed),this.hostOnly&&(e.hostOnly=this.hostOnly),this.pathIsDefault&&(e.pathIsDefault=this.pathIsDefault),this.hash&&(e.hash=this.hash),this.plainDomain&&(e.plainDomain=this.plainDomain),this.maxAge&&(e.maxAge=this.maxAge),e}toString(){return`${this.key}=${this.value}`}toNetscapeFormat(){let e=this.hostOnly?this.domain:this.domain.startsWith(".")?this.domain:"."+this.domain,t=this.secure?"TRUE":"FALSE",n=this.expires&&typeof this.expires!="string"?Math.round(this.expires.getTime()/1e3):0;return`${e} TRUE ${this.path} ${t} ${n} ${this.key} ${this.value}`}TTL(e=Date.now()){return this.expires==="Infinity"||!this.expires?1/0:Math.max(0,this.expires.getTime()-e)}expiryTime(e=new Date){if(this.maxAge!=null){let t=this.maxAge==="Infinity"?1/0:Number(this.maxAge)*1e3;return(this.lastAccessed instanceof Date?this.lastAccessed:e).getTime()+t}return this.expires instanceof Date?this.expires.getTime():void 0}isPersistent(){return this.expires!=null||this.maxAge!=null}canonicalizedDomain(){return this.domain?u.canonicalDomain(this.domain):void 0}cdomain(){return this.canonicalizedDomain()}static parse(e,t={}){try{let n=e.split(";").map(h=>h.trim()),[i,...s]=n,[o,...a]=i.split("=").map(h=>h.trim()),c=a.join("=");if(!o&&!t.loose)return;let r=new u({key:o,value:c});s.forEach(h=>{let[l,R]=h.split("=").map(D=>D.trim());switch(l.toLowerCase()){case"expires":r.expires=u.parseDate(R);break;case"max-age":r.setMaxAge(parseInt(R,10));break;case"domain":r.domain=R;break;case"path":r.path=R;break;case"secure":r.secure=!0;break;case"httponly":r.httpOnly=!0;break;case"samesite":r.sameSite=R;break;default:r.extensions||(r.extensions=[]),r.extensions.push(h)}}),r.isSession=!r.expires;let f=r.domain&&r.domain.startsWith(".")?"wildcard":"matchDomainOnly",g=r.path&&r.path!=="/"&&r.path.length>1?"matchPathOnly":"";return g&&f==="matchDomainOnly"?r.accessType="matchDomainAndPath":g&&f==="wildcard"?r.accessType="matchPathOnly":f==="matchDomainOnly"?r.accessType="matchDomainOnly":r.accessType="wildcard",r}catch{return}}static fromJSONString(e){if(typeof e=="string")try{e=JSON.parse(e)}catch{return}if(typeof e!="object"||e===null)return;let t={};return u.serializableProperties.forEach(n=>{e[n]!==void 0&&(n==="expires"||n==="creation"||n==="lastAccessed"?t[n]=new Date(e[n]):t[n]=e[n])}),new u(t)}static fromJSON(e){if(typeof e=="object"&&e!==null)try{return new u(e)}catch{return}}static parseDate(e){return new Date(e)}static canonicalDomain(e){return e.toLowerCase()}static cookiesCreated=0;static defaultPath="/";static sameSiteLevel={strict:3,lax:2,none:1};static sameSiteCanonical={strict:"Strict",lax:"Lax"};static serializableProperties=["key","value","expires","maxAge","domain","path","secure","httpOnly","extensions","hostOnly","pathIsDefault","creation","lastAccessed","sameSite"];isDomainMatch(e,t){return e=this.isValidUrl(e)?new URL(e).hostname:e,this.isDomainMatching(t,e)}inDomain(e,t=!0){return this.domain?this.isValidUrl(e)?this.isMatched(e,this.domain):this.isDomainMatch(e,this.domain):t}isMatched(e,t){let n=new URL(e).pathname;return n=n.endsWith("/")?n:`${n}/`,e=new URL(e).hostname,this.accessType==="wildcard"?this.isDomainMatching(t,e):this.accessType==="matchDomainAndPath"&&this.isDomainMatching(t,e)&&this.isPathMatching(this.path??"/",n)||this.accessType==="matchPathOnly"&&this.isPathMatching(this.path??"/",n)?!0:!!(this.accessType==="matchDomainOnly"&&this.isDomainMatching(t,e))}isDomainMatching(e,t){if(e=e.toLowerCase(),t=t.toLowerCase(),!e.startsWith("."))return e===t;let n=e.slice(1);return t===n||t.endsWith("."+n)}isPathMatching(e,t){let n=this.normalizePath(e);return t.startsWith("/")||(t="/"+t),t.startsWith(n)}normalizePath(e){let t=e.trim();return(t==="."||t==="./")&&(t="/"),t.startsWith("/")||(t="/"+t),t.length>1&&t.endsWith("/")&&(t=t.slice(0,-1)),t}isValidUrl(e){try{return new URL(e),e.startsWith("http")||e.startsWith("https")}catch{return!1}}};var q=class{constructor(e=!1){this.debug=e}cookies=[];setCookieSync(e,t,n=!0){let i=this.getDomain(t);if(!i)return;e.domain=e.domain?e.domain:i;let s=e.domain?L.md5(`${e.domain.toString()}_${e.key}`):null;e.lastAccessed=new Date;let o=!1;if(s&&this.cookies.find(a=>a.hash===s)){if(n){let a=this.cookies.find(c=>c.hash===s);a&&(e.creationIndex=a.creationIndex,e.creation=a.creation),this.cookies=this.cookies.filter(c=>c.hash!==s)}o=!0}o||(e.creationIndex=this.cookies.length),s&&(e.hash=s),(!o||n)&&this.cookies.push(e),this.removeExpiredCookies()}setResponseCookies(e,t){if(e instanceof Response)if(e?.headers&&typeof e.headers?.getSetCookie<"u")for(let i of e.headers.getSetCookie()){let s=k.parse(i.trim());s&&this.setCookieSync(s,t)}else{let i=e?.headers?.get("set-cookie");i&&i.split(",").forEach(s=>{let o=k.parse(s);o&&this.setCookieSync(o,t)})}else Array.isArray(e)?typeof e[0]=="string"?e.forEach(n=>{let i=k.parse(n.trim());i&&this.setCookieSync(i,t)}):e[0]instanceof k?e.forEach(n=>this.setCookieSync(n,t)):e.forEach(n=>{let i=k.fromJSON(n);i&&this.setCookieSync(i,t)}):typeof e=="string"&&e.includes("=")&&e.includes(",")&&e.split(",").forEach(n=>{let i=k.parse(n);i&&this.setCookieSync(i,t)})}toNetscapeFormat(e){this.removeExpiredCookies();let t=`# Netscape HTTP Cookie File
`;return t+=`# This file was generated by YuniqCookie npm package
`,t+=`# https://www.npmjs.com/package/yuniq-cookie
`,t+this.cookies.filter(n=>!e||n.inDomain(e)).map(n=>n.toNetscapeFormat()).join(`
`)||""}getDomain(e){if(!e)return null;try{return new URL(e).hostname}catch{return null}}toArray(){return this.removeExpiredCookies(),this.cookies.map(e=>e.toArray())||[]}toCookieString(e){return this.removeExpiredCookies(),this.allCookies()?.filter(t=>!e||t.inDomain(e,!1)).map(t=>t.toString()).join("; ")||""}toSetCookiesString(e){return this.removeExpiredCookies(),this.allCookies()?.filter(t=>!e||t.inDomain(e,!1)).map(t=>t.toSetCookieString()).join("; ")||""}domainToCookieString(e){return this.removeExpiredCookies(),this.allCookies()?.filter(t=>t.domain===e).map(t=>`${t.key}=${t.value}`).join("; ")||""}removeExpiredCookies(){let e=new Date,t=this.cookies.length;return this.cookies=this.cookies.filter(i=>{if(i.expires instanceof Date&&i.expires.getTime()<=e.getTime())return!1;if((i.expires===null||i.expires===void 0)&&typeof i.maxAge=="number"){let s=i.lastAccessed instanceof Date?i.lastAccessed:i.creation instanceof Date?i.creation:new Date(0);if(new Date(s.getTime()+this.isMillisecondsLength(i.maxAge)).getTime()<=e.getTime())return!1}return!0}),t-this.cookies.length}getCookieByKey(e,t,n){if(this.removeExpiredCookies(),t){let s=this.getCookies(t).map(o=>{let c=n?o?.key.trim():o?.key.trim().toLowerCase(),a=n?e.trim():e.trim().toLowerCase();return c===a?o:null}).filter(o=>o!==null);if(s&&s.length>0)return s[0]}else{let i=this.cookies.map(s=>{let o=s,c=n?o?.key.trim():o?.key.trim().toLowerCase(),a=n?e.trim():e.trim().toLowerCase();return c===a?s:null}).filter(s=>s!==null);if(i&&i.length>0)return i[0]}return null}parseNetscapeCookies(e,t=!0){let n=e.split(`
`);for(let i of n)try{let[s,o,c,a,r,h,y]=i.split(" "),u=`http${a==="TRUE"?"s":""}://${s.startsWith(".")?s.substring(1):s}${c}`;this.setCookieSync(new k({domain:s,path:c,secure:a==="TRUE",expires:r?new Date(parseInt(r)*1e3):void 0,key:h,value:y}),u,t)}catch(s){this.debug&&console.error("Error parsing netscape cookies:",s)}}parseCookieString(e,t,n=!0,i=!0){this.removeExpiredCookies();try{let s=new URL(t),o=e.replaceAll(";","_____").replaceAll("; ","_____").split("_____");for(let c of o){let[a,...r]=c.split("="),h=r.join("=");this.setCookieSync(new k({key:a,value:h,domain:s.hostname,path:"/",...this.setDates(i)}),s.toString(),n)}}catch(s){console.error(s)}}setDates(e){return{expires:e?new Date().addDay(7):"Infinity",creation:e?new Date:null,lastAccessed:e?new Date:null}}fromArray(e,t=!0){for(let n of e)if(n instanceof k)n.domain&&this.setCookieSync(n,`http${n.secure?"s":""}://${n.domain.startsWith(".")?n.domain.substring(1):n.domain}${n.path}`,t);else{let i=k.fromJSON(n);i&&(n.plainDomain&&(i.plainDomain=n.plainDomain),n.hash&&(i.hash=n.hash),n.secure&&(i.secure=n.secure),this.setCookieSync(i,`http${i.secure?"s":""}://${i?.domain?.startsWith(".")?i.domain.substring(1):i.domain}${i.path}`,t))}this.removeExpiredCookies()}parseDate(e){if(e instanceof Date)return e;if(typeof e=="string"&&e!=="Infinity")return this.isNumberOnly(e)?new Date(this.isMillisecondsLength(e)):new Date(e);if(typeof e=="number")return new Date(this.isMillisecondsLength(e))}isNumberOnly(e){return/^[0-9]+$/.test(e)}isMillisecondsLength(e){let t=e.toString().trim();try{if(typeof e=="number")return t.length===13?e:e*1e3;let n=parseInt(t);return n.toString().length===13?n:n*1e3}catch{return 0}}clear(){this.removeAllCookiesSync()}removeAllCookiesSync(){this.cookies.length=0}getCookiesForDomain(e){return this.removeExpiredCookies(),this.allCookies().filter(t=>t.domain&&e.includes(t.domain))}allCookies(){return this.cookies}findCookie(e,t){return this.removeExpiredCookies(),this.allCookies().find(n=>n.key===e&&n.inDomain(t,!1))}getCookies(e,t){this.removeExpiredCookies();try{if(t&&typeof t=="function")t(null,this.cookies.map(n=>n&&n.inDomain(e,!1)?n:null).filter(n=>n!==null));else return this.cookies.map(n=>n&&n.inDomain(e,!1)?n:null).filter(n=>n!==null)}catch(n){if(t&&typeof t=="function")t(n,void 0);else return this.debug&&console.error("Error getting cookies:",n.message),[]}}getAllCookies(e){this.removeExpiredCookies();let t=this.getCookies(e);try{let n=[...t];return this.cookies.forEach(i=>{n.some(s=>s.hash===i.hash)||n.push(new k(i))}),n}catch(n){this.debug&&console.error(`Error parsing cookies: ${n.message}`)}return t}get size(){return this.removeExpiredCookies(),this.allCookies().length}isEmpty(){return this.removeExpiredCookies(),this.allCookies().length===0}*[Symbol.iterator](){for(let e of this.allCookies())yield e}};var w=B(require("fs")),O=B(require("path")),A=B(require("form-data")),ue=B(require("http")),le=B(require("https")),de=B(require("tunnel")),Z=B(require("socks-proxy-agent"));var U=require("node:zlib"),X=require("node:stream"),J=class d{static decompressStream(e,t){return e?t?t.toLowerCase().split(/\s*,\s*/).reduce((i,s)=>{switch(s){case"gzip":return i.pipe((0,U.createGunzip)());case"br":return i.pipe((0,U.createBrotliDecompress)());case"deflate":return i.pipe((0,U.createInflate)());case"compress":return i.pipe((0,U.createInflate)());case"x-gzip":return i.pipe((0,U.createGunzip)());case"x-deflate":return i.pipe((0,U.createInflate)());case"gzip-raw":return i.pipe((0,U.createGunzip)({finishFlush:U.constants.Z_SYNC_FLUSH}));default:return i}},e):e:d.createEmptyReadableStream()}static async streamToBuffer(e){return new Promise((t,n)=>{let i=[];e.on("data",s=>i.push(Buffer.from(s))),e.on("end",()=>t(Buffer.concat(i))),e.on("error",n)})}static createEmptyReadableStream(){return new X.Readable({read(){this.push(null)}})}};var S=A.default,he=A.default.Readable,pe=Z.SocksProxyAgent,I=class extends ${proxy;constructor(e){super(e),this.jar=new q,this.proxy=e?.proxy}setCookies(e,t,n){n&&(this.jar=new q),Array.isArray(e)?this.jar.fromArray(e,n):typeof e=="string"&&(t&&e.includes("; ")?this.jar.parseCookieString(e,t,n):e.includes(`
`)&&e.split(" ").length>3&&this.jar.parseNetscapeCookies(e,n))}getCookies(){return{array:this.jar.toArray(),string:this.jar.toCookieString(),netscape:this.jar.toNetscapeFormat()}}getCookieByKey(e,t,n){return this.jar.getCookieByKey(e,t,n)}async postMultipart(e,t,n){let i=new A.default,s=!1;if(t instanceof A.default)i=t,s=!0;else if(typeof t=="object"){for(let[o,c]of Object.entries(t))i.append(o,c?typeof c=="object"?JSON.stringify(c):c.toString():"");s=!0}else i=t;return this.request(e,"POST",i,{...n,isMultipart:s})}async request(e,t,n=void 0,i={}){await this.rateLimiter();let s=i;typeof s.treat302As303>"u"&&(s.treat302As303=!0);let o=[];typeof s.withCookies!="boolean"&&(s.withCookies=!0);let c,a=typeof s.returnBuffer>"u"?!1:s.returnBuffer,r=["GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"],h=s.maxRetries??0,y=s.retryDelay??0;t=r&&r.includes(t.toUpperCase())?t?.toUpperCase():"GET",s.body=n||s.body;let u=process.hrtime();(s.startNew||s.startNewRequest)&&this.jar?.removeAllCookiesSync();let l,g=s.maxRedirects||10,x=s.debug!==void 0?s.debug:!1,f=s.saveTo||s.fileName,b;if(f){let m=O.basename(f);if(this.checkISPermission(f.length?O.dirname(f):O.resolve(process.cwd()))){let p=m.length<f.length?O.dirname(f):O.join(process.cwd(),"download");w.existsSync(p)||w.mkdirSync(p,{recursive:!0}),b=O.join(p,m)}else if(s.debug)throw this.Error(void 0,`Permission denied to save to ${f}, returning the response data instead`)}let T=0,R=e instanceof URL?e.href:e;s.method=t;let D=null,v=0,M,G;if(s&&s.timeout&&typeof s.timeout=="number"&&s.timeout>100){let m=new AbortController;M=setTimeout(()=>m.abort(),s.timeout),G=m.signal}let _,W;try{for(;;){if(D=null,s.params&&typeof s.params=="object"){let p=new URL(R);for(let[F,C]of Object.entries(s.params))p.searchParams.set(F,C.toString());R=p.toString()}let m=this.prepareHTTPOptions({...s,fileName:b,customHeaders:c},R,t,T>0,_,W);try{let p=await this.makeRequest(R,{...m.requestOptions,signal:G},m.requestBody),F=p.status&&p.status>=300&&p.status<400&&p.redirectUrl&&!s.dontFollowRedirects;if((s.withCookies||s.withCookies===void 0)&&p.cookies&&this.jar.setResponseCookies(p.cookies,R),p.status<200||p.status>309)throw delete m.requestOptions.method,delete m.requestOptions.agent,m.requestOptions.proxy||delete m.requestOptions.proxy,m.requestBody||delete m.requestBody,b?(D={response:p,message:`Failed to download: ${p.statusText}`,config:{...m,method:t}},await this.Error(p,`Failed to download: ${p.statusText}`,{...m,method:t})):(delete m.requestOptions.filename,D={response:p,message:void 0,config:{...m,method:t}},await this.Error(p,void 0,{...m,method:t}));if(o.push(p.url),F){c=void 0;let C=s.onRedirect?s.onRedirect({url:new URL(p.redirectUrl),status:p.status,headers:p.headers,sameDomain:this.isSameDomain(R,p.redirectUrl),method:t.toUpperCase()}):void 0;if(typeof C<"u"){if(typeof C=="boolean"){if(!C)throw await this.Error(p,"Redirect denied by user",{...m,method:t})}else if(!C.redirect)throw await this.Error(p,C.message||"Redirect denied by user",{...m,method:t})}if(T>=g)throw await this.Error(p,`Max redirects (${g}) reached`,{...m,method:t});let E=p.redirectUrl;if(!E)throw await this.Error(p,"Redirect location not found",{...m,method:t});W=R,_=R,R=new URL(E,R).toString(),T++;let P=!1;typeof C=="object"&&C.redirect?(t=C.method||t,s.method=t,R=C.url,C.withoutBody?delete s.body:C.body&&(s.body=C.body),x&&(P=!0,console.log(`
Redirecting to: ${R} using ${t} method`)),C.setHeaders&&(c=C.setHeaders)):p.status===303||s.treat302As303&&p.status===302?(x&&(P=!0,console.log(`
Redirecting to: ${R} using GET method`)),t="GET",s.method=t,delete s.body):P=!1,x&&!P&&console.log(`Redirecting to: ${R}`);continue}if(b&&p.status)if(w.existsSync(b)){let C=w.statSync(b).size,[E,P]=process.hrtime(u),Y=E+P/1e9;l={fileName:b,totalTime:this.formatTime(Y),downloadSpeed:this.formatSpeed(C/Y),size:this.formatSize(C)}}else throw await this.Error(p,`Error saving file: ${b}, please check the permissions`);return this.formatResponse(p,R,a,{...m,method:t},l,o)}catch(p){if(b&&w.existsSync(b)&&w.unlinkSync(b),D&&h>0)if(h>v)s.debug&&console.log(`Request failed with status code ${D.response?.status}, retrying...${y>0?" in "+y+"ms":""}`),v++,y>0&&await new Promise(F=>setTimeout(F,y));else throw s.debug&&console.log(`Max retries (${h}) reached, throwing the last error`),await this.Error(D.response,D.message,D.config);else throw p}}}catch(m){throw m}finally{typeof M<"u"&&clearTimeout(M),this.removeBatch()}}formatTime(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),i=Math.floor(e%3600/60),s=e%60,o=[];if(t>0&&o.push(`${t} day${t!==1?"s":""}`),n>0&&o.push(`${n} hour${n!==1?"s":""}`),i>0&&o.push(`${i} minute${i!==1?"s":""}`),s>0||o.length===0){let c=s<1?s.toFixed(2):Math.floor(s)===s?s.toFixed(0):s.toFixed(1);o.push(`${c} second${c!=="1"?"s":""}`)}if(o.length>1){let c=o.pop();return`${o.join(", ")} and ${c}`}else return o[0]}formatSpeed(e){let t=["B/s","KB/s","MB/s","GB/s"],n=e,i=0;for(;n>=1024&&i<t.length-1;)n/=1024,i++;return`${n.toFixed(2)} ${t[i]}`}formatSize(e){let t=["B","KB","MB","GB","TB"],n=e,i=0;for(;n>=1024&&i<t.length-1;)n/=1024,i++;return`${n.toFixed(2)} ${t[i]}`}async setProxy(e,t){if(e.protocol==="socks5"||e.protocol==="socks4"){let n="";if(e.username&&e.password){let i=encodeURIComponent(e.username),s=encodeURIComponent(e.password);n=`${i}:${s}@`}return new pe(`${e.protocol.replace("5","")}://${n}${e.host}:${e.port}`,{keepAlive:e.keepAlive,timeout:e.timeout??3e4,keepAliveMsecs:e.keepAliveMsecs,maxSockets:e.maxSockets,maxFreeSockets:e.maxFreeSockets})}else if(e.protocol==="http"||e.protocol==="https"){let n=e.protocol==="https"?t.protocol==="https:"?"httpsOverHttps":"httpOverHttps":t.protocol==="https:"?"httpsOverHttp":"httpOverHttp";return de[n]({proxy:{host:e.host,port:e.port,proxyAuth:e.password&&e.username&&e.password.length>1&&e.username.length>2?`${e.username}:${e.password}`:void 0},rejectUnauthorized:!1,keepAlive:e.keepAlive,timeout:e.timeout??3e4,keepAliveMsecs:e.keepAliveMsecs,maxSockets:e.maxSockets,maxFreeSockets:e.maxFreeSockets})}else throw e.protocol?await this.Error({},`Unsupported proxy protocol: ${e.protocol}, supported protocols are socks5, http or https`):await this.Error({},"You must specify a proxy protocol, either socks5, http or https")}async makeRequest(e,t,n){let{proxy:i,filename:s,method:o="GET",...c}=t,a=i?await this.setProxy(i,typeof e=="string"?new URL(e):e):void 0;return new Promise((r,h)=>{e=typeof e=="string"?new URL(e):e;let u=(e.protocol==="https:"?le:ue).request(e,{...c,rejectUnauthorized:!1,followRedirects:!1,agent:a,method:o},async l=>{let g=l.headers,x=g["content-type"],f=g["content-length"],b=g["set-cookie"];delete g["set-cookie"];let T;if(l.statusCode&&l.statusCode>=300&&l.statusCode<400&&l.headers.location)T=new URL(l.headers.location,e).href;else if(l.statusCode&&l.statusCode>=300&&l.statusCode<400&&!l.headers.location)throw await this.Error({headers:g,contentType:x,contentLength:f,cookies:b||[],status:l.statusCode??200,statusText:l.statusMessage??"OK",url:l.url||e.toString(),method:l.method,body:null,redirectUrl:void 0},"Redirect location not found",{...c,method:o});if(s){let R=w.createWriteStream(s);l.pipe(R),R.on("finish",()=>{r({headers:g,contentType:x,contentLength:f,cookies:b||[],status:l.statusCode??200,statusText:l.statusMessage??"OK",url:l.url||e.toString(),method:l.method,body:null,redirectUrl:T})}),R.on("error",async D=>{h(await this.Error({status:l.statusCode??500,statusText:l.statusMessage||"Internal Server Error",headers:g,url:l.url||e.toString(),method:l.method},D.message,{...c,method:o}))})}else{let R=J.decompressStream(l,l.headers["content-encoding"]),D=[];R.on("data",v=>{D.push(v)}),R.on("end",()=>{r({headers:g,contentType:x,contentLength:f,cookies:b||[],status:l.statusCode??200,statusText:l.statusMessage||"OK",url:l.url||e.toString(),method:l.method,body:Buffer.concat(D),redirectUrl:T})})}});u.on("error",async l=>{h(await this.Error({status:500,statusText:l.stack||"Internal Server Error"},l.message,{...c,method:o}))}),n&&(n instanceof URLSearchParams?u.write(n.toString()):n instanceof S?(u.setHeader("Content-Type",`multipart/form-data; boundary=${n.getBoundary()}`),n.pipe(u)):typeof n=="object"&&!(n instanceof Buffer)&&!(n instanceof Uint8Array)&&!(n instanceof he)?u.write(JSON.stringify(n)):u.write(n)),u.end()})}checkISPermission(e){try{return w.accessSync(e,w.constants.R_OK|w.constants.W_OK),!0}catch{return!1}}prepareHTTPOptions(e,t,n,i,s,o){let a=["post","put","patch"].includes(n.toLowerCase()),r={others:{}},h=e.headers instanceof Headers?e.headers:new Headers(e.headers||{}),y=!1,u=e.contentType||h.get("Content-Type")||(a?"application/json":void 0);if(e.customHeaders?r.headers=new Headers(e.customHeaders):e.headers?r.headers=h instanceof Headers?h:new Headers(h):r.headers=new Headers,h.has("Cookie")){let f=h.get("Cookie");e.withCookies&&this.setCookies(f,t),h.delete("Cookie"),r.headers.delete("Cookie")}e.cookies&&(e.withCookies||typeof e.withCookies>"u")&&this.setCookies(e.cookies,t);let l;if(e.useAllCookies?l=this.jar.getAllCookies(t):l=this.jar.getCookies(t),l.length>0&&(e.withCookies||typeof e.withCookies>"u")&&r.headers.set("Cookie",l.map(f=>`${f.key}=${f.value}`).join("; ")),e.body&&(r.body=e.body),e.isFormData||e.isJson||e.isMultipart)e.isFormData?(r.body=e.body,u="application/x-www-form-urlencoded",r.headers.set("Content-Type",u),y=!0):e.isJson?(r.body=e.body,u="application/json",r.headers.set("Content-Type",u),y=!0):e.isMultipart&&(r.body=e.body,y=!0);else if(e.json)r.body=JSON.stringify(e.json),u="application/json",r.headers.set("Content-Type",u),y=!0;else if(e.form_params)r.body=new URLSearchParams(e.form_params).toString(),u="application/x-www-form-urlencoded",r.headers.set("Content-Type",u),y=!0;else if(e.multipart&&!(e.multipart instanceof S)){let f=new S;Object.entries(e.multipart).forEach(([b,T])=>{f.append(b,T)}),r.body=f,y=!0}else if(e.requestType)switch(e.requestType){case"json":u="application/json",typeof r.body=="object"&&(r.body=JSON.stringify(r.body)),r.headers.set("Content-Type",u);break;case"form":u="application/x-www-form-urlencoded",typeof r.body=="object"&&(r.body=new URLSearchParams(r.body).toString()),r.headers.set("Content-Type",u);break;case"formData":if(typeof r.body=="object"){let f=new S;Object.entries(r.body).forEach(([b,T])=>{f.append(b,T?typeof T=="object"?JSON.stringify(T):T.toString():"")}),r.body=f}break;case"text":u="text/plain",r.headers.set("Content-Type",u);break}else if(u){let f=u.toLowerCase();if(f.includes("json"))r.headers.set("Content-Type","application/json"),r.body&&typeof r.body=="object"&&(r.body=JSON.stringify(r.body));else if(f.includes("x-www-form-urlencoded"))r.headers.set("Content-Type","application/x-www-form-urlencoded"),r.body&&typeof r.body=="object"&&(r.body=new URLSearchParams(r.body).toString());else if(f.includes("multipart")){if(r.body&&typeof r.body=="object"){let b=new S;Object.entries(r.body).forEach(([T,R])=>{b.append(T,R)}),r.body=b}}else f.includes("text/plain")&&r.headers.set("Content-Type","text/plain")}else u&&!e.withoutContentType&&r.headers.set("Content-Type",u);e.withoutContentType&&r.headers.delete("Content-Type"),e.withoutBodyOnRedirect&&i&&(r.body=void 0),e.printHeaders&&console.log("Fetch headers:",r.headers),(typeof e.autoSetReferer!="boolean"||e.autoSetReferer)&&s&&(e.customHeaders||r.headers.set("Referer",s));for(let f of this.innerFetchOption)Object.keys(e).includes(f)&&typeof e[f]<"u"&&e[f]!==null&&(r.others[f]=e[f]);typeof e.withCookies=="boolean"&&!e.withCookies&&r.headers.delete("Cookie"),delete r.credentials;let g={requestBody:r.body,requestOptions:{}};n.toLowerCase()==="get"&&r.headers.has("Content-Type")&&r.headers.delete("Content-Type"),r.headers.has("user-agent")||r.headers.set("user-agent",this.defaultUserAgent),r.headers.has("accept")||r.headers.set("accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8"),r.headers.has("accept-language")||r.headers.set("accept-language","en-US,en;q=0.9"),r.headers.has("host")||r.headers.set("host",new URL(t).host),r.headers.has("origin")||["POST","PUT","PATCH","DELETE","OPTIONS"].includes(n.toUpperCase())&&r.headers.set("origin",new URL(o||t).origin),o&&r.headers.has("origin")&&(["POST","PUT","PATCH","DELETE","OPTIONS"].includes(n.toUpperCase())||r.headers.delete("origin")),o&&!r.headers.has("referer")&&r.headers.set("referer",o);let x={};for(let[f,b]of r.headers.entries())x[f]=b;return g.requestOptions.headers=x,g.requestOptions.proxy=e.proxy??this.proxy,g.requestOptions.filename=e.fileName,g.requestOptions.method=n,r=void 0,g}isSameDomain(e,t){return new URL(e).hostname===new URL(t).hostname}};var fe=I,Q=new I,ye=Q;0&&(module.exports={FormData,Uniqhtt,uniqhtt});
`)||""}getDomain(e){if(!e)return null;try{return new URL(e).hostname}catch{return null}}toArray(){return this.removeExpiredCookies(),this.cookies.map(e=>e.toArray())||[]}toCookieString(e){return this.removeExpiredCookies(),this.allCookies()?.filter(t=>!e||t.inDomain(e,!1)).map(t=>t.toString()).join("; ")||""}toSetCookiesString(e){return this.removeExpiredCookies(),this.allCookies()?.filter(t=>!e||t.inDomain(e,!1)).map(t=>t.toSetCookieString()).join("; ")||""}domainToCookieString(e){return this.removeExpiredCookies(),this.allCookies()?.filter(t=>t.domain===e).map(t=>`${t.key}=${t.value}`).join("; ")||""}removeExpiredCookies(){let e=new Date,t=this.cookies.length;return this.cookies=this.cookies.filter(i=>{if(i.expires instanceof Date&&i.expires.getTime()<=e.getTime())return!1;if((i.expires===null||i.expires===void 0)&&typeof i.maxAge=="number"){let s=i.lastAccessed instanceof Date?i.lastAccessed:i.creation instanceof Date?i.creation:new Date(0);if(new Date(s.getTime()+this.isMillisecondsLength(i.maxAge)).getTime()<=e.getTime())return!1}return!0}),t-this.cookies.length}getCookieByKey(e,t,n){if(this.removeExpiredCookies(),t){let s=this.getCookies(t).map(o=>{let a=n?o?.key.trim():o?.key.trim().toLowerCase(),c=n?e.trim():e.trim().toLowerCase();return a===c?o:null}).filter(o=>o!==null);if(s&&s.length>0)return s[0]}else{let i=this.cookies.map(s=>{let o=s,a=n?o?.key.trim():o?.key.trim().toLowerCase(),c=n?e.trim():e.trim().toLowerCase();return a===c?s:null}).filter(s=>s!==null);if(i&&i.length>0)return i[0]}return null}parseNetscapeCookies(e,t=!0){let n=e.split(`
`);for(let i of n)try{let[s,o,a,c,r,f,g]=i.split(" "),h=`http${c==="TRUE"?"s":""}://${s.startsWith(".")?s.substring(1):s}${a}`;this.setCookieSync(new k({domain:s,path:a,secure:c==="TRUE",expires:r?new Date(parseInt(r)*1e3):void 0,key:f,value:g}),h,t)}catch(s){this.debug&&console.error("Error parsing netscape cookies:",s)}}parseCookieString(e,t,n=!0,i=!0){this.removeExpiredCookies();try{let s=new URL(t),o=e.replaceAll(";","_____").replaceAll("; ","_____").split("_____");for(let a of o){let[c,...r]=a.split("="),f=r.join("=");this.setCookieSync(new k({key:c,value:f,domain:s.hostname,path:"/",...this.setDates(i)}),s.toString(),n)}}catch(s){console.error(s)}}setDates(e){return{expires:e?new Date().addDay(7):"Infinity",creation:e?new Date:null,lastAccessed:e?new Date:null}}fromArray(e,t=!0){for(let n of e)if(n instanceof k)n.domain&&this.setCookieSync(n,`http${n.secure?"s":""}://${n.domain.startsWith(".")?n.domain.substring(1):n.domain}${n.path}`,t);else{let i=k.fromJSON(n);i&&(n.plainDomain&&(i.plainDomain=n.plainDomain),n.hash&&(i.hash=n.hash),n.secure&&(i.secure=n.secure),this.setCookieSync(i,`http${i.secure?"s":""}://${i?.domain?.startsWith(".")?i.domain.substring(1):i.domain}${i.path}`,t))}this.removeExpiredCookies()}parseDate(e){if(e instanceof Date)return e;if(typeof e=="string"&&e!=="Infinity")return this.isNumberOnly(e)?new Date(this.isMillisecondsLength(e)):new Date(e);if(typeof e=="number")return new Date(this.isMillisecondsLength(e))}isNumberOnly(e){return/^[0-9]+$/.test(e)}isMillisecondsLength(e){let t=e.toString().trim();try{if(typeof e=="number")return t.length===13?e:e*1e3;let n=parseInt(t);return n.toString().length===13?n:n*1e3}catch{return 0}}clear(){this.removeAllCookiesSync()}removeAllCookiesSync(){this.cookies.length=0}getCookiesForDomain(e){return this.removeExpiredCookies(),this.allCookies().filter(t=>t.domain&&e.includes(t.domain))}allCookies(){return this.cookies}findCookie(e,t){return this.removeExpiredCookies(),this.allCookies().find(n=>n.key===e&&n.inDomain(t,!1))}getCookies(e,t){this.removeExpiredCookies();try{if(t&&typeof t=="function")t(null,this.cookies.map(n=>n&&n.inDomain(e,!1)?n:null).filter(n=>n!==null));else return this.cookies.map(n=>n&&n.inDomain(e,!1)?n:null).filter(n=>n!==null)}catch(n){if(t&&typeof t=="function")t(n,void 0);else return this.debug&&console.error("Error getting cookies:",n.message),[]}}getAllCookies(e){this.removeExpiredCookies();let t=this.getCookies(e);try{let n=[...t];return this.cookies.forEach(i=>{n.some(s=>s.hash===i.hash)||n.push(new k(i))}),n}catch(n){this.debug&&console.error(`Error parsing cookies: ${n.message}`)}return t}get size(){return this.removeExpiredCookies(),this.allCookies().length}isEmpty(){return this.removeExpiredCookies(),this.allCookies().length===0}*[Symbol.iterator](){for(let e of this.allCookies())yield e}};var w=B(require("fs")),O=B(require("path")),A=B(require("form-data")),ce=B(require("http")),ue=B(require("https")),le=B(require("tunnel")),Z=B(require("socks-proxy-agent"));var U=require("node:zlib"),X=require("node:stream"),J=class u{static decompressStream(e,t){return e?t?t.toLowerCase().split(/\s*,\s*/).reduce((i,s)=>{switch(s){case"gzip":return i.pipe((0,U.createGunzip)());case"br":return i.pipe((0,U.createBrotliDecompress)());case"deflate":return i.pipe((0,U.createInflate)());case"compress":return i.pipe((0,U.createInflate)());case"x-gzip":return i.pipe((0,U.createGunzip)());case"x-deflate":return i.pipe((0,U.createInflate)());case"gzip-raw":return i.pipe((0,U.createGunzip)({finishFlush:U.constants.Z_SYNC_FLUSH}));default:return i}},e):e:u.createEmptyReadableStream()}static async streamToBuffer(e){return new Promise((t,n)=>{let i=[];e.on("data",s=>i.push(Buffer.from(s))),e.on("end",()=>t(Buffer.concat(i))),e.on("error",n)})}static createEmptyReadableStream(){return new X.Readable({read(){this.push(null)}})}};var S=A.default,he=A.default.Readable,de=Z.SocksProxyAgent,I=class extends M{proxy;constructor(e){super(e),this.jar=new q,this.proxy=e?.proxy}setCookies(e,t,n){n&&(this.jar=new q),Array.isArray(e)?this.jar.fromArray(e,n):typeof e=="string"&&(t&&e.includes("; ")?this.jar.parseCookieString(e,t,n):e.includes(`
`)&&e.split(" ").length>3&&this.jar.parseNetscapeCookies(e,n))}getCookies(){return{array:this.jar.toArray(),string:this.jar.toCookieString(),netscape:this.jar.toNetscapeFormat()}}getCookieByKey(e,t,n){return this.jar.getCookieByKey(e,t,n)}async postMultipart(e,t,n){let i=new A.default,s=!1;if(t instanceof A.default)i=t,s=!0;else if(typeof t=="object"){for(let[o,a]of Object.entries(t))i.append(o,a?typeof a=="object"?JSON.stringify(a):a.toString():"");s=!0}else i=t;return this.request(e,"POST",i,{...n,isMultipart:s})}async request(e,t,n=void 0,i={}){await this.rateLimiter();let s=i;typeof s.treat302As303>"u"&&(s.treat302As303=!0);let o=[];typeof s.withCookies!="boolean"&&(s.withCookies=!0);let a,c=typeof s.returnBuffer>"u"?!1:s.returnBuffer,r=["GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"],f=s.maxRetries??0,g=s.retryDelay??0;t=r&&r.includes(t.toUpperCase())?t?.toUpperCase():"GET",s.body=n||s.body;let h=process.hrtime();(s.startNew||s.startNewRequest)&&this.jar?.removeAllCookiesSync();let l,R=s.maxRedirects||10,D=s.debug!==void 0?s.debug:!1,p=s.saveTo||s.fileName,m;if(p){let y=O.basename(p);if(this.checkISPermission(p.length?O.dirname(p):O.resolve(process.cwd()))){let d=y.length<p.length?O.dirname(p):O.join(process.cwd(),"download");w.existsSync(d)||w.mkdirSync(d,{recursive:!0}),m=O.join(d,y)}else if(s.debug)throw this.Error(void 0,`Permission denied to save to ${p}, returning the response data instead`)}let T=0,b=e instanceof URL?e.href:e;s.method=t;let x=null,E=0,N,G;if(s&&s.timeout&&typeof s.timeout=="number"&&s.timeout>100){let y=new AbortController;N=setTimeout(()=>y.abort(),s.timeout),G=y.signal}let _,W;try{for(;;){if(x=null,s.params&&typeof s.params=="object"){let d=new URL(b);for(let[F,C]of Object.entries(s.params))d.searchParams.set(F,C.toString());b=d.toString()}let y=this.prepareHTTPOptions({...s,fileName:m,customHeaders:a},b,t,T>0,_,W);try{let d=await this.makeRequest(b,{...y.requestOptions,signal:G},y.requestBody),F=d.status&&d.status>=300&&d.status<400&&d.redirectUrl&&!s.dontFollowRedirects;if((s.withCookies||s.withCookies===void 0)&&d.cookies&&this.jar.setResponseCookies(d.cookies,b),d.status<200||d.status>309)throw delete y.requestOptions.method,delete y.requestOptions.agent,y.requestOptions.proxy||delete y.requestOptions.proxy,y.requestBody||delete y.requestBody,m?(x={response:d,message:`Failed to download: ${d.statusText}`,config:{...y,method:t}},await this.Error(d,`Failed to download: ${d.statusText}`,{...y,method:t})):(delete y.requestOptions.filename,x={response:d,message:void 0,config:{...y,method:t}},await this.Error(d,void 0,{...y,method:t}));if(o.push(d.url),F){a=void 0;let C=s.onRedirect?s.onRedirect({url:new URL(d.redirectUrl),status:d.status,headers:d.headers,sameDomain:this.isSameDomain(b,d.redirectUrl),method:t.toUpperCase()}):void 0;if(typeof C<"u"){if(typeof C=="boolean"){if(!C)throw await this.Error(d,"Redirect denied by user",{...y,method:t})}else if(!C.redirect)throw await this.Error(d,C.message||"Redirect denied by user",{...y,method:t})}if(T>=R)throw await this.Error(d,`Max redirects (${R}) reached`,{...y,method:t});let v=d.redirectUrl;if(!v)throw await this.Error(d,"Redirect location not found",{...y,method:t});W=b,_=b,b=new URL(v,b).toString(),T++;let P=!1;typeof C=="object"&&C.redirect?(t=C.method||t,s.method=t,b=C.url,C.withoutBody?delete s.body:C.body&&(s.body=C.body),D&&(P=!0,console.log(`
Redirecting to: ${b} using ${t} method`)),C.setHeaders&&(a=C.setHeaders)):d.status===303||s.treat302As303&&d.status===302?(D&&(P=!0,console.log(`
Redirecting to: ${b} using GET method`)),t="GET",s.method=t,delete s.body):P=!1,D&&!P&&console.log(`Redirecting to: ${b}`);continue}if(m&&d.status)if(w.existsSync(m)){let C=w.statSync(m).size,[v,P]=process.hrtime(h),Y=v+P/1e9;l={fileName:m,totalTime:this.formatTime(Y),downloadSpeed:this.formatSpeed(C/Y),size:this.formatSize(C)}}else throw await this.Error(d,`Error saving file: ${m}, please check the permissions`);return this.formatResponse(d,b,c,{...y,method:t},l,o)}catch(d){if(m&&w.existsSync(m)&&w.unlinkSync(m),x&&f>0)if(f>E)s.debug&&console.log(`Request failed with status code ${x.response?.status}, retrying...${g>0?" in "+g+"ms":""}`),E++,g>0&&await new Promise(F=>setTimeout(F,g));else throw s.debug&&console.log(`Max retries (${f}) reached, throwing the last error`),await this.Error(x.response,x.message,x.config);else throw d}}}catch(y){throw y}finally{typeof N<"u"&&clearTimeout(N),this.removeBatch()}}formatTime(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),i=Math.floor(e%3600/60),s=e%60,o=[];if(t>0&&o.push(`${t} day${t!==1?"s":""}`),n>0&&o.push(`${n} hour${n!==1?"s":""}`),i>0&&o.push(`${i} minute${i!==1?"s":""}`),s>0||o.length===0){let a=s<1?s.toFixed(2):Math.floor(s)===s?s.toFixed(0):s.toFixed(1);o.push(`${a} second${a!=="1"?"s":""}`)}if(o.length>1){let a=o.pop();return`${o.join(", ")} and ${a}`}else return o[0]}formatSpeed(e){let t=["B/s","KB/s","MB/s","GB/s"],n=e,i=0;for(;n>=1024&&i<t.length-1;)n/=1024,i++;return`${n.toFixed(2)} ${t[i]}`}formatSize(e){let t=["B","KB","MB","GB","TB"],n=e,i=0;for(;n>=1024&&i<t.length-1;)n/=1024,i++;return`${n.toFixed(2)} ${t[i]}`}async setProxy(e,t){if(e.protocol==="socks5"||e.protocol==="socks4"){let n="";if(e.username&&e.password){let i=encodeURIComponent(e.username),s=encodeURIComponent(e.password);n=`${i}:${s}@`}return new de(`${e.protocol.replace("5","")}://${n}${e.host}:${e.port}`,{keepAlive:e.keepAlive,timeout:e.timeout??3e4,keepAliveMsecs:e.keepAliveMsecs,maxSockets:e.maxSockets,maxFreeSockets:e.maxFreeSockets})}else if(e.protocol==="http"||e.protocol==="https"){let n=e.protocol==="https"?t.protocol==="https:"?"httpsOverHttps":"httpOverHttps":t.protocol==="https:"?"httpsOverHttp":"httpOverHttp";return le[n]({proxy:{host:e.host,port:e.port,proxyAuth:e.password&&e.username&&e.password.length>1&&e.username.length>2?`${e.username}:${e.password}`:void 0},rejectUnauthorized:!1,keepAlive:e.keepAlive,timeout:e.timeout??3e4,keepAliveMsecs:e.keepAliveMsecs,maxSockets:e.maxSockets,maxFreeSockets:e.maxFreeSockets})}else throw e.protocol?await this.Error({},`Unsupported proxy protocol: ${e.protocol}, supported protocols are socks5, http or https`):await this.Error({},"You must specify a proxy protocol, either socks5, http or https")}async makeRequest(e,t,n){let{proxy:i,filename:s,method:o="GET",...a}=t,c=i?await this.setProxy(i,typeof e=="string"?new URL(e):e):void 0;return new Promise((r,f)=>{e=typeof e=="string"?new URL(e):e;let h=(e.protocol==="https:"?ue:ce).request(e,{...a,rejectUnauthorized:!1,followRedirects:!1,agent:c,method:o},async l=>{let R=l.headers,D=R["content-type"],p=R["content-length"],m=R["set-cookie"];delete R["set-cookie"];let T;if(l.statusCode&&l.statusCode>=300&&l.statusCode<400&&l.headers.location)T=new URL(l.headers.location,e).href;else if(l.statusCode&&l.statusCode>=300&&l.statusCode<400&&!l.headers.location)throw await this.Error({headers:R,contentType:D,contentLength:p,cookies:m||[],status:l.statusCode??200,statusText:l.statusMessage??"OK",url:l.url||e.toString(),method:l.method,body:null,redirectUrl:void 0},"Redirect location not found",{...a,method:o});if(s){let b=w.createWriteStream(s);l.pipe(b),b.on("finish",()=>{r({headers:R,contentType:D,contentLength:p,cookies:m||[],status:l.statusCode??200,statusText:l.statusMessage??"OK",url:l.url||e.toString(),method:l.method,body:null,redirectUrl:T})}),b.on("error",async x=>{f(await this.Error({status:l.statusCode??500,statusText:l.statusMessage||"Internal Server Error",headers:R,url:l.url||e.toString(),method:l.method},x.message,{...a,method:o}))})}else{let b=J.decompressStream(l,l.headers["content-encoding"]),x=[];b.on("data",E=>{x.push(E)}),b.on("end",()=>{r({headers:R,contentType:D,contentLength:p,cookies:m||[],status:l.statusCode??200,statusText:l.statusMessage||"OK",url:l.url||e.toString(),method:l.method,body:Buffer.concat(x),redirectUrl:T})})}});h.on("error",async l=>{f(await this.Error({status:500,statusText:l.stack||"Internal Server Error"},l.message,{...a,method:o}))}),n&&(n instanceof URLSearchParams?h.write(n.toString()):n instanceof S?(h.setHeader("Content-Type",`multipart/form-data; boundary=${n.getBoundary()}`),n.pipe(h)):typeof n=="object"&&!(n instanceof Buffer)&&!(n instanceof Uint8Array)&&!(n instanceof he)?h.write(JSON.stringify(n)):h.write(n)),h.end()})}checkISPermission(e){try{return w.accessSync(e,w.constants.R_OK|w.constants.W_OK),!0}catch{return!1}}prepareHTTPOptions(e,t,n,i,s,o){let c=["post","put","patch"].includes(n.toLowerCase()),r={others:{}},f=e.headers instanceof Headers?e.headers:new Headers(e.headers||{}),g=!1,h=e.contentType||f.get("Content-Type")||(c?"application/json":void 0);if(e.customHeaders?r.headers=new Headers(e.customHeaders):e.headers?r.headers=f instanceof Headers?f:new Headers(f):r.headers=new Headers,f.has("Cookie")){let p=f.get("Cookie");e.withCookies&&this.setCookies(p,t),f.delete("Cookie"),r.headers.delete("Cookie")}e.cookies&&(e.withCookies||typeof e.withCookies>"u")&&this.setCookies(e.cookies,t);let l;if(e.useAllCookies?l=this.jar.getAllCookies(t):l=this.jar.getCookies(t),l.length>0&&(e.withCookies||typeof e.withCookies>"u")&&r.headers.set("Cookie",l.map(p=>`${p.key}=${p.value}`).join("; ")),e.body&&(r.body=e.body),e.isFormData||e.isJson||e.isMultipart)e.isFormData?(r.body=e.body,h="application/x-www-form-urlencoded",r.headers.set("Content-Type",h),g=!0):e.isJson?(r.body=e.body,h="application/json",r.headers.set("Content-Type",h),g=!0):e.isMultipart&&(r.body=e.body,g=!0);else if(e.json)r.body=JSON.stringify(e.json),h="application/json",r.headers.set("Content-Type",h),g=!0;else if(e.form_params)r.body=new URLSearchParams(e.form_params).toString(),h="application/x-www-form-urlencoded",r.headers.set("Content-Type",h),g=!0;else if(e.multipart&&!(e.multipart instanceof S)){let p=new S;Object.entries(e.multipart).forEach(([m,T])=>{p.append(m,T)}),r.body=p,g=!0}else if(e.requestType)switch(e.requestType){case"json":h="application/json",typeof r.body=="object"&&(r.body=JSON.stringify(r.body)),r.headers.set("Content-Type",h);break;case"form":h="application/x-www-form-urlencoded",typeof r.body=="object"&&(r.body=new URLSearchParams(r.body).toString()),r.headers.set("Content-Type",h);break;case"formData":if(typeof r.body=="object"){let p=new S;Object.entries(r.body).forEach(([m,T])=>{p.append(m,T?typeof T=="object"?JSON.stringify(T):T.toString():"")}),r.body=p}break;case"text":h="text/plain",r.headers.set("Content-Type",h);break}else if(h){let p=h.toLowerCase();if(p.includes("json"))r.headers.set("Content-Type","application/json"),r.body&&typeof r.body=="object"&&(r.body=JSON.stringify(r.body));else if(p.includes("x-www-form-urlencoded"))r.headers.set("Content-Type","application/x-www-form-urlencoded"),r.body&&typeof r.body=="object"&&(r.body=new URLSearchParams(r.body).toString());else if(p.includes("multipart")){if(r.body&&typeof r.body=="object"){let m=new S;Object.entries(r.body).forEach(([T,b])=>{m.append(T,b)}),r.body=m}}else p.includes("text/plain")&&r.headers.set("Content-Type","text/plain")}else h&&!e.withoutContentType&&r.headers.set("Content-Type",h);e.withoutContentType&&r.headers.delete("Content-Type"),e.withoutBodyOnRedirect&&i&&(r.body=void 0),e.printHeaders&&console.log("Fetch headers:",r.headers),(typeof e.autoSetReferer!="boolean"||e.autoSetReferer)&&s&&(e.customHeaders||r.headers.set("Referer",s));for(let p of this.innerFetchOption)Object.keys(e).includes(p)&&typeof e[p]<"u"&&e[p]!==null&&(r.others[p]=e[p]);typeof e.withCookies=="boolean"&&!e.withCookies&&r.headers.delete("Cookie"),delete r.credentials;let R={requestBody:r.body,requestOptions:{}};n.toLowerCase()==="get"&&r.headers.has("Content-Type")&&r.headers.delete("Content-Type"),r.headers.has("user-agent")||r.headers.set("user-agent",this.defaultUserAgent),r.headers.has("accept")||r.headers.set("accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8"),r.headers.has("accept-language")||r.headers.set("accept-language","en-US,en;q=0.9"),r.headers.has("host")||r.headers.set("host",new URL(t).host),r.headers.has("origin")||["POST","PUT","PATCH","DELETE","OPTIONS"].includes(n.toUpperCase())&&r.headers.set("origin",new URL(o||t).origin),o&&r.headers.has("origin")&&(["POST","PUT","PATCH","DELETE","OPTIONS"].includes(n.toUpperCase())||r.headers.delete("origin")),o&&!r.headers.has("referer")&&r.headers.set("referer",o);let D={};for(let[p,m]of r.headers.entries())D[p]=m;return R.requestOptions.headers=D,R.requestOptions.proxy=e.proxy??this.proxy,R.requestOptions.filename=e.fileName,R.requestOptions.method=n,r=void 0,R}isSameDomain(e,t){return new URL(e).hostname===new URL(t).hostname}};var pe=I,Q=new I,fe=Q;0&&(module.exports={FormData,Uniqhtt,uniqhtt});
{
"name": "uniqhtt",
"version": "1.0.94",
"version": "1.0.96",
"description": "Uniqhtt is a versatile Node.js library designed for handling HTTP requests and responses with advanced cookie management, HTML parsing, and CSS processing capabilities. It leverages powerful tools like jsdom, fetch-cookie, and postcss to provide a robust solution for web scraping, data extraction, and web automation tasks.",

@@ -17,10 +17,6 @@ "main": "./index.js",

},
"./browser": {
"import": "./browser.mjs",
"require": "./browser.js"
"./edge": {
"import": "./edge.mjs",
"require": "./edge.js"
},
"./worker": {
"import": "./worker.mjs",
"require": "./worker.js"
},
"./node.js": {

@@ -30,9 +26,5 @@ "import": "./node.mjs",

},
"./browser.js": {
"import": "./browser.mjs",
"require": "./browser.js"
},
"./worker.js": {
"import": "./worker.mjs",
"require": "./worker.js"
"./edge.js": {
"import": "./edge.mjs",
"require": "./edge.js"
}

@@ -39,0 +31,0 @@ },

# Uniqhtt
Welcome to **Uniqhtt**, a powerful and versatile Node.js library designed to handle advanced HTTP requests, response processing, and web automation. This library stands out with its comprehensive support for cookie management, HTML parsing, CSS transformation, and Wget-like recursive website cloning features. Uniqhtt provides a solid solution for web scraping, data extraction, and automation tasks, making it a valuable tool for developers working in diverse environments ranging from Node.js to serverless platforms and browsers.
Welcome to **Uniqhtt**, a powerful and versatile Node.js library designed to handle advanced HTTP requests, response processing, and web automation. This library stands out with its comprehensive support for cookie management, HTML parsing, CSS transformation, and Wget-like recursive website cloning features. Uniqhtt provides a solid solution for web scraping, data extraction, and automation tasks, making it a valuable tool for developers working in diverse environments ranging from Node.js to serverless platforms and edge computing.

@@ -5,0 +5,0 @@ ## Table of Contents

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc