/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@discordjs/proxy@2.1.1/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__name=(e,r)=>__defProp(e,"name",{value:r,configurable:!0}),__export=(e,r)=>{for(var o in r)__defProp(e,o,{get:r[o],enumerable:!0})},__copyProps=(e,r,o,t)=>{if(r&&"object"==typeof r||"function"==typeof r)for(let s of __getOwnPropNames(r))__hasOwnProp.call(e,s)||s===o||__defProp(e,s,{get:()=>r[s],enumerable:!(t=__getOwnPropDesc(r,s))||t.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),src_exports={};__export(src_exports,{populateAbortErrorResponse:()=>populateAbortErrorResponse,populateErrorResponse:()=>populateErrorResponse,populateGeneralErrorResponse:()=>populateGeneralErrorResponse,populateRatelimitErrorResponse:()=>populateRatelimitErrorResponse,populateSuccessfulResponse:()=>populateSuccessfulResponse,proxyRequests:()=>proxyRequests,version:()=>version}),module.exports=__toCommonJS(src_exports);var import_node_url=require("url"),import_node_stream=require("stream"),import_promises=require("stream/promises"),import_rest=require("@discordjs/rest");async function populateSuccessfulResponse(e,r){e.statusCode=r.status;for(const[o,t]of r.headers)/^x-ratelimit/i.test(o)||e.setHeader(o,t);r.body&&await(0,import_promises.pipeline)(r.body instanceof import_node_stream.Readable?r.body:import_node_stream.Readable.fromWeb(r.body),e)}function populateGeneralErrorResponse(e,r){e.statusCode=r.status,"rawError"in r&&(e.setHeader("Content-Type","application/json"),e.write(JSON.stringify(r.rawError)))}function populateRatelimitErrorResponse(e,r){e.statusCode=429,e.setHeader("Retry-After",r.timeToReset/1e3)}function populateAbortErrorResponse(e){e.statusCode=504,e.statusMessage="Upstream timed out"}function populateErrorResponse(e,r){if(r instanceof import_rest.DiscordAPIError||r instanceof import_rest.HTTPError)populateGeneralErrorResponse(e,r);else if(r instanceof import_rest.RateLimitError)populateRatelimitErrorResponse(e,r);else{if(!(r instanceof Error&&"AbortError"===r.name))return!1;populateAbortErrorResponse(e)}return!0}function proxyRequests(e){return async(r,o)=>{const{method:t,url:s}=r;if(!t||!s)throw new TypeError("Invalid request. Missing method and/or url, implying that this is not a Server IncomingMessage");const p=new import_node_url.URL(s,"http://noop"),a=p.pathname.replace(/^\/api(\/v\d+)?/,""),n={"Content-Type":r.headers["content-type"]};r.headers.authorization&&(n.authorization=r.headers.authorization),r.headers["x-audit-log-reason"]&&(n["x-audit-log-reason"]=r.headers["x-audit-log-reason"]);try{const s=await e.queueRequest({body:r,fullRoute:a,method:t,auth:!1,passThroughBody:!0,query:p.searchParams,headers:n});await populateSuccessfulResponse(o,s)}catch(e){if(!populateErrorResponse(o,e))throw e}finally{o.end()}}}__name(populateSuccessfulResponse,"populateSuccessfulResponse"),__name(populateGeneralErrorResponse,"populateGeneralErrorResponse"),__name(populateRatelimitErrorResponse,"populateRatelimitErrorResponse"),__name(populateAbortErrorResponse,"populateAbortErrorResponse"),__name(populateErrorResponse,"populateErrorResponse"),__name(proxyRequests,"proxyRequests");var version="2.1.1";
//# sourceMappingURL=/sm/3fa91cfac6bc792db6bbc5b9035b61780d35ca83f5cf6045b63899c97b1a34de.map