UNPKG

@visulima/email

Version:

A comprehensive email library with multi-provider support, crypto utilities, and template engines

2 lines (1 loc) 1.5 kB
var b=Object.defineProperty;var h=(s,t)=>b(s,"name",{value:t,configurable:!0});import d from"./EmailError-zm2ffVav.js";var g=Object.defineProperty,p=h((s,t)=>g(s,"name",{value:t,configurable:!0}),"l");const E=globalThis.Buffer!==void 0,q=p(async(s,t={},a)=>{const m=typeof s=="string"?new URL(s):s;try{const r=new Headers;t.headers&&Object.entries(t.headers).forEach(([e,u])=>{r.set(e,u)});const o={headers:r,method:t.method||(a?"POST":"GET")};a&&(typeof a=="string"||a instanceof Uint8Array?o.body=a:E&&a instanceof globalThis.Buffer?o.body=new Uint8Array(a):o.body=new Uint8Array(a));let c,n;t.timeout&&(c=new AbortController,n=setTimeout(()=>{c?.abort()},t.timeout),o.signal=c.signal);try{const e=await fetch(m.toString(),o);n&&clearTimeout(n);const u=(e.headers.get("content-type")||"").includes("application/json");let i;if(u)try{i=await e.json()}catch{i=await e.text()}else i=await e.text();const f=e.status>=200&&e.status<300,l={};return e.headers.forEach((y,w)=>{l[w]=y}),{data:{body:i,headers:l,statusCode:e.status},error:f?void 0:new d("http",`Request failed with status ${e.status}`,{code:e.status.toString()}),success:f}}catch(e){if(n&&clearTimeout(n),e instanceof Error&&e.name==="AbortError")return{error:new d("http",`Request timed out after ${t.timeout}ms`),success:!1};throw e}}catch(r){return{error:new d("http",`Request failed: ${r instanceof Error?r.message:String(r)}`,{cause:r instanceof Error?r:new Error(String(r))}),success:!1}}},"makeRequest");export{q as makeRequest};