corsair 0.1.201 → 0.1.202

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/http.d.ts CHANGED
@@ -130,6 +130,7 @@ declare function resolveFileInput(input: FileInput, options?: ResolveFileOptions
130
130
  */
131
131
  declare const FileOutputSchema: z.ZodObject<{
132
132
  contentBase64: z.ZodOptional<z.ZodString>;
133
+ text: z.ZodOptional<z.ZodString>;
133
134
  contentType: z.ZodString;
134
135
  byteLength: z.ZodNumber;
135
136
  filename: z.ZodOptional<z.ZodString>;
@@ -145,11 +146,17 @@ declare const FILE_OUTPUT_MAX_BYTES = 700000;
145
146
  * Shapes downloaded bytes as a `FileOutput`. The content goes in when it was
146
147
  * asked for and fits `maxBytes`; the size and type are always reported, so a
147
148
  * caller that got no content still knows what it would be.
149
+ *
150
+ * A text file in UTF-8 comes back as `text` instead of base64, so a caller can
151
+ * read a CSV or JSON file as it is. A file served as application/octet-stream
152
+ * counts as text when its `filename` ends in a text extension such as .csv.
153
+ * Pass `text: false` to always get base64.
148
154
  */
149
155
  declare function toFileOutput(bytes: Uint8Array, contentType: string | null | undefined, options?: {
150
156
  includeContent?: boolean;
151
157
  maxBytes?: number;
152
158
  filename?: string;
159
+ text?: boolean;
153
160
  }): FileOutput;
154
161
 
155
162
  type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
package/dist/http.js CHANGED
@@ -1 +1 @@
1
- import"./chunk-SOY77BN4.js";var ce=new Set(["apikey","xapikey","key","appkey","appid","token","apitoken","accesstoken","authtoken","clientsecret","secret","password"]);function C(t){let e=t;try{e=decodeURIComponent(t)}catch{e=t}return ce.has(e.toLowerCase().replace(/[-_]/g,""))}function ue(t){let e=t.indexOf("?");if(e===-1)return t;let r=t.indexOf("#",e),n=t.slice(0,e+1),i=r===-1?t.slice(e+1):t.slice(e+1,r),s=r===-1?"":t.slice(r),o=!1,a=i.split("&").map(l=>{if(!l)return l;let c=l.indexOf("="),f=c===-1?l:l.slice(0,c);return C(f)?(o=!0,`${f}=[REDACTED]`):l}).join("&");return o?n+a+s:t}function j(t){if(!t)return t;try{let e=/^[a-z]+:\/\//i.test(t),r=e?void 0:"http://localhost",n=new URL(t,r),i=!1;for(let s of[...n.searchParams.keys()])C(s)&&(n.searchParams.set(s,"[REDACTED]"),i=!0);return i?e?n.toString():n.pathname+n.search+n.hash:t}catch{return ue(t)}}function fe(t){let e=j(t.url),r=!1,n=t.query;if(t.query){n={...t.query};for(let i of Object.keys(n))C(i)&&(n[i]="[REDACTED]",r=!0)}return!r&&e===t.url?t:{...t,url:e,...r?{query:n}:{}}}var h=class extends Error{url;status;statusText;body;request;retryAfter;rateLimitReset;rateLimitRemaining;rateLimitLimit;constructor(e,r,n,i){super(n),this.name="ApiError",this.url=j(r.url),this.status=r.status,this.statusText=r.statusText,this.body=r.body,this.request=fe(e),this.retryAfter=i?.retryAfter,this.rateLimitReset=i?.rateLimitReset,this.rateLimitRemaining=i?.rateLimitRemaining,this.rateLimitLimit=i?.rateLimitLimit}isRateLimitError(){return this.status===429}};import{z as d}from"zod";import{lookup as de}from"dns/promises";import*as V from"http";import*as G from"https";import{pipeline as me,Readable as pe}from"stream";import*as A from"zlib";var he=3e4,ye=25*1024*1024,W=3,be=[["0.0.0.0",8],["10.0.0.0",8],["100.64.0.0",10],["127.0.0.0",8],["169.254.0.0",16],["172.16.0.0",12],["192.0.0.0",24],["192.0.2.0",24],["192.88.99.0",24],["192.168.0.0",16],["198.18.0.0",15],["198.51.100.0",24],["203.0.113.0",24],["224.0.0.0",4],["240.0.0.0",4]];function v(t){let e=t.split(".");if(e.length!==4)return;let r=0;for(let n of e){if(!/^\d{1,3}$/.test(n))return;let i=Number(n);if(i>255)return;r=r*256+i}return r}function J(t){let e=v(t);return e===void 0?!0:be.some(([r,n])=>{let i=v(r);if(i===void 0)return!1;let s=n===0?0:4294967295<<32-n>>>0;return(e&s)===(i&s)})}function ge(t){let e=t,r=e.indexOf("%");r!==-1&&(e=e.slice(0,r));let n=e.lastIndexOf(":");if(n===-1)return;let i=e.slice(n+1);if(i.includes(".")){let u=v(i);if(u===void 0)return;e=`${e.slice(0,n+1)}${(u>>>16).toString(16)}:${(u&65535).toString(16)}`}let s=e.split("::");if(s.length>2)return;let o=u=>u===""?[]:u.split(":").filter(R=>R!==""),a=o(s[0]??""),l=s.length===2?o(s[1]??""):[];if(![...a,...l].every(u=>/^[0-9a-fA-F]{1,4}$/.test(u)))return;if(s.length===1)return a.length===8?a.map(u=>Number.parseInt(u,16)):void 0;let c=8-a.length-l.length;return c<1?void 0:[...a,...Array(c).fill("0"),...l].map(u=>Number.parseInt(u,16))}function Re(t){let e=ge(t);if(!e)return!0;if(e.slice(0,5).every(n=>n===0)&&(e[5]===65535||e[5]===0)){let n=`${e[6]>>8}.${e[6]&255}.${e[7]>>8}.${e[7]&255}`;if(J(n))return!0}return!!(e.every(n=>n===0)||e.slice(0,7).every(n=>n===0)&&e[7]===1||(e[0]&65024)===64512||(e[0]&65472)===65152||(e[0]&65472)===65216||(e[0]&65280)===65280||e[0]===8194||e[0]===100&&e[1]===65435&&e.slice(2,6).every(n=>n===0)||e[0]===100&&e[1]===65435&&e[2]===1)}function Q(t){let e=t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t;return e.includes(":")?Re(e):J(e)}var m=class extends Error{constructor(e){super(e),this.name="UnsafeUrlError"}};async function Ae(t){return(await de(t,{all:!0,verbatim:!0})).map(r=>r.address)}function Te(t){return((e,r,n)=>{let i=n,s=typeof r=="object"&&r!==null&&r.all===!0,o=t.map(l=>({address:l,family:l.includes(":")?6:4}));if(o.length===0){i(new Error("No address to connect to."),"",0);return}if(s){i(null,o);return}let a=o[0];i(null,a.address,a.family)})}var we=(t,e,r)=>{let n=t.protocol==="https:",i=t.hostname.replace(/^\[|\]$/g,""),s={method:"GET",protocol:t.protocol,hostname:i,port:t.port===""?void 0:Number(t.port),path:`${t.pathname}${t.search}`,headers:{Accept:"*/*","Accept-Encoding":"identity"},lookup:Te(e),agent:!1,signal:r};return n&&(s.servername=i),new Promise((o,a)=>{let c=(n?G.request:V.request)(s,f=>{o({status:f.statusCode??0,headers:f.headers,body:f,cancel:()=>f.destroy()})});c.on("error",a),c.end()})};function xe(t,e){return e?e.aborted?Promise.reject(e.reason):new Promise((r,n)=>{let i=()=>n(e.reason);e.addEventListener("abort",i,{once:!0}),t.then(s=>{e.removeEventListener("abort",i),r(s)},s=>{e.removeEventListener("abort",i),n(s)})}):t}async function z(t,e={},r){let n;try{n=new URL(t)}catch{throw new m("The file URL must be an absolute URL.")}if(n.protocol!=="http:"&&n.protocol!=="https:")throw new m("The file URL must use http or https.");let i=n.hostname.replace(/^\[|\]$/g,"");if(i==="")throw new m("The file URL must include a host.");let o=i.includes(":")||v(i)!==void 0?[i]:await xe((e.resolve??Ae)(i).catch(()=>{throw new m(`Could not resolve ${i}.`)}),r);if(o.length===0)throw new m(`Could not resolve ${i}.`);for(let a of o)if(Q(a))throw new m(`The file URL points at ${i}, which resolves to a private or reserved address. Use a publicly reachable URL.`);return{url:n,addresses:o}}function X(t,e){try{let r=new URL(t).pathname.split("/").pop();return r&&r.includes(".")?r:e}catch{return e}}function w(t,e){let r=t[e];return Array.isArray(r)?r[0]:r}function P(t){return new m(`The file is larger than the ${Math.round(t/(1024*1024))} MB limit.`)}async function*Le(t,e){let r=0;for await(let n of t){if(r+=n.byteLength,r>e)throw P(e);yield n}}async function ve(t,e){let r=[],n=0;for await(let o of t){if(n+=o.byteLength,n>e)throw P(e);r.push(o)}let i=new Uint8Array(n),s=0;for(let o of r)i.set(o,s),s+=o.byteLength;return i}async function Ee(t,e,r){let n=e?.trim().toLowerCase();if(!n||n==="identity")return t;let i=n==="gzip"||n==="x-gzip"?A.createGunzip():n==="deflate"?A.createInflate():n==="br"?A.createBrotliDecompress():void 0;if(!i)throw new m(`The file was served with an unsupported Content-Encoding (${n}).`);return me(pe.from(Le(t,r)),i,s=>{s&&i.destroy(s)}),i}function E(t){if(t!==void 0&&!(Number.isSafeInteger(t)&&t>=0))throw new RangeError(`maxBytes must be a whole number of bytes, 0 or more; got ${t}.`)}function Oe(t){if(!t)return;let e=/filename\*\s*=\s*(?:UTF-8|utf-8)''([^;]+)/.exec(t)?.[1];if(e)try{return decodeURIComponent(e.trim())}catch{}let r=/filename\s*=\s*("([^"]*)"|[^;]+)/.exec(t);return(r?.[2]??r?.[1]??"").trim()||void 0}async function I(t,e={},r={}){E(e.maxBytes);let n=e.maxBytes??ye,i=r.transport??we,s=AbortSignal.timeout(e.timeoutMs??he),o=await z(t,r,s);for(let a=0;;a++){let l=await i(o.url,o.addresses,s),c;try{let u=w(l.headers,"location");if(l.status>=300&&l.status<400&&u){if(l.cancel?.(),a>=W)throw new m(`The file URL redirected more than ${W} times.`);o=await z(new URL(u,o.url).toString(),r,s);continue}if(l.status<200||l.status>=300)throw new Error(`Could not download the file (${l.status}). Its URL must be publicly reachable.`);let R=Number(w(l.headers,"content-length"));if(Number.isFinite(R)&&R>n)throw P(n);c=await ve(await Ee(l.body,w(l.headers,"content-encoding"),n),n)}catch(u){throw l.cancel?.(),u}let f=Oe(w(l.headers,"content-disposition"));return{bytes:c,contentType:w(l.headers,"content-type")?.split(";")[0]?.trim()||"application/octet-stream",url:o.url.toString(),...f?{filename:f}:{}}}}var Y={filename:d.string().optional().describe("What to call the file. Defaults to the name in its URL."),contentType:d.string().optional().describe("Media type, for example application/pdf. Defaults to what the server states.")},Ue=d.union([d.string().min(1).describe("A public http(s) URL to the file."),d.object({url:d.string().min(1).describe("A public http(s) URL to the file."),...Y}),d.object({base64:d.string().min(1).describe("The file, base64-encoded."),...Y})]).describe("A file: a public URL to it, or {url, filename?, contentType?}, or {base64, filename?, contentType?} for a small one.");function Se(t){return typeof Blob<"u"&&t instanceof Blob}function O(t,e,r){return{bytes:t,filename:e,contentType:r,file:new File([new Uint8Array(t)],e,{type:r})}}var Ce=/^data:([^;,]*)((?:;[^;,=]+=[^;,]*)*)(;base64)?,(.*)$/is,T=t=>new Error(`The file is larger than the ${Math.round(t/(1024*1024))} MB limit.`);function D(t,e){if(t.byteLength===0)throw new Error("The file is empty.");if(e!==void 0&&t.byteLength>e)throw T(e);return t}function Pe(t,e){if(e!==void 0&&Math.ceil(t.length/3)>e)throw T(e);let r=new TextEncoder().encode(t),n=new Uint8Array(e===void 0?r.length:Math.min(r.length,e)),i=0;for(let s=0;s<r.length;s++){if(e!==void 0&&i===e)throw T(e);let o=r[s]===37?String.fromCharCode(r[s+1]??0,r[s+2]??0):"";/^[0-9a-fA-F]{2}$/.test(o)?(n[i++]=Number.parseInt(o,16),s+=2):n[i++]=r[s]}return i===n.length?n:n.slice(0,i)}var K=()=>new Error("The file is not valid base64."),Ie=new Set([9,10,11,12,13,32]);function De(t,e){if(!t.includes("%"))return t;let r=t.replace(/\s+/g,""),n=e===void 0?r.length:Math.min(r.length,Math.ceil(e/3)*4),i=new Uint8Array(n),s=0;for(let o=0;o<r.length;o++){let a=r.charCodeAt(o),l=a===37?r.slice(o+1,o+3):"";if(/^[0-9a-fA-F]{2}$/.test(l)&&(a=Number.parseInt(l,16),o+=2),!Ie.has(a)){if(a>127)throw K();if(s===n)throw T(e??n);i[s++]=a}}return Buffer.from(i.buffer,0,s).toString("latin1")}function Z(t,e){let r=t.replace(/\s+/g,"");if(r.length%4===0&&(r.endsWith("==")?r=r.slice(0,-2):r.endsWith("=")&&(r=r.slice(0,-1))),r.length===0||r.length%4===1||!/^[A-Za-z0-9+/_-]+$/.test(r))throw K();if(e!==void 0&&Math.floor(r.length*3/4)>e)throw T(e);return D(new Uint8Array(Buffer.from(r,"base64")),e)}async function Fe(t,e={},r={}){E(e.maxBytes);let n=e.fallbackName??"file";if(Se(t)){let a=typeof File<"u"&&t instanceof File&&t.name?t.name:n;if(e.maxBytes!==void 0&&t.size>e.maxBytes)throw T(e.maxBytes);return O(D(new Uint8Array(await t.arrayBuffer()),e.maxBytes),a,t.type||"application/octet-stream")}let i=typeof t=="string"?{url:t}:t;if("base64"in i)return O(Z(i.base64,e.maxBytes),i.filename??n,i.contentType??"application/octet-stream");let s=Ce.exec(i.url);if(s){let[,a,,l,c=""]=s,f=l?Z(De(c,e.maxBytes),e.maxBytes):D(Pe(c,e.maxBytes),e.maxBytes);return O(f,i.filename??n,i.contentType??(a||"application/octet-stream"))}let o=await I(i.url,e,r);return O(o.bytes,i.filename??o.filename??X(o.url,n),i.contentType??o.contentType)}var ke=d.object({contentBase64:d.string().optional().describe("The file, base64-encoded. Missing when contentOmitted is set."),contentType:d.string().describe("Media type of the file, for example application/pdf."),byteLength:d.number().describe("Size of the file in bytes."),filename:d.string().optional().describe("The file name, when known."),contentOmitted:d.enum(["not_requested","over_limit"]).optional().describe("Set when contentBase64 was left out: the caller did not ask for it, or the file was over the limit.")}),ee=7e5;function Be(t,e,r={}){E(r.maxBytes);let n={contentType:e?.split(";")[0]?.trim()||"application/octet-stream",byteLength:t.byteLength,...r.filename?{filename:r.filename}:{}};return r.includeContent===!1?{...n,contentOmitted:"not_requested"}:t.byteLength>(r.maxBytes??ee)?{...n,contentOmitted:"over_limit"}:{...n,contentBase64:Buffer.from(t).toString("base64")}}var F=class extends Error{constructor(e){super(e),this.name="CancelError"}get isCancelled(){return!0}},U=class{#t;#r;#e;#n;#s;#o;#i;constructor(e){this.#t=!1,this.#r=!1,this.#e=!1,this.#n=[],this.#s=new Promise((r,n)=>{this.#o=r,this.#i=n;let i=a=>{this.#t||this.#r||this.#e||(this.#t=!0,this.#o&&this.#o(a))},s=a=>{this.#t||this.#r||this.#e||(this.#r=!0,this.#i&&this.#i(a))},o=a=>{this.#t||this.#r||this.#e||this.#n.push(a)};return Object.defineProperty(o,"isResolved",{get:()=>this.#t}),Object.defineProperty(o,"isRejected",{get:()=>this.#r}),Object.defineProperty(o,"isCancelled",{get:()=>this.#e}),e(i,s,o)})}get[Symbol.toStringTag](){return"Cancellable Promise"}then(e,r){return this.#s.then(e,r)}catch(e){return this.#s.catch(e)}finally(e){return this.#s.finally(e)}cancel(){if(!(this.#t||this.#r||this.#e)){if(this.#e=!0,this.#n.length)try{for(let e of this.#n)e()}catch(e){console.warn("Cancellation threw an error",e);return}this.#n.length=0,this.#i&&this.#i(new F("Request aborted"))}}get isCancelled(){return this.#e}};var te={enabled:!0,maxRetries:3,initialRetryDelay:1e3,backoffMultiplier:2,headerNames:{retryAfter:"retry-after",resetTime:"x-ratelimit-reset",remaining:"x-ratelimit-remaining",limit:"x-ratelimit-limit"}};function re(t,e){let r={};if(e.headerNames.retryAfter){let n=t.headers.get(e.headerNames.retryAfter);if(n){let i=parseInt(n,10);isNaN(i)||(r.retryAfter=i*1e3)}}if(e.headerNames.resetTime){let n=t.headers.get(e.headerNames.resetTime);if(n){let i=parseInt(n,10);if(!isNaN(i)){let s=Date.now(),o=i>1e12?i:i*1e3;r.rateLimitReset=o,o>s&&(r.retryAfter=o-s)}}}if(e.headerNames.remaining){let n=t.headers.get(e.headerNames.remaining);if(n){let i=parseInt(n,10);isNaN(i)||(r.rateLimitRemaining=i)}}if(e.headerNames.limit){let n=t.headers.get(e.headerNames.limit);if(n){let i=parseInt(n,10);isNaN(i)||(r.rateLimitLimit=i)}}return r}function ne(t,e,r){return r.enabled?t===429?!0:r.isRateLimitError?r.isRateLimitError(t,e):!1:!1}function k(t,e,r){if(e.retryAfter)return e.retryAfter;let n=r.initialRetryDelay*Math.pow(r.backoffMultiplier,t-1);return Math.min(n,6e4)}async function B(t){return new Promise(e=>setTimeout(e,t))}var q=t=>t!=null,x=t=>typeof t=="string",N=t=>x(t)&&t!=="",$=t=>typeof t=="object"&&typeof t.type=="string"&&typeof t.stream=="function"&&typeof t.arrayBuffer=="function"&&typeof t.constructor=="function"&&typeof t.constructor.name=="string"&&/^(Blob|File)$/.test(t.constructor.name)&&/^(Blob|File)$/.test(t[Symbol.toStringTag]),se=t=>t instanceof FormData,Ne=t=>{try{return btoa(t)}catch{return Buffer.from(t).toString("base64")}},qe=t=>{let e=[],r=(i,s)=>{e.push(`${encodeURIComponent(i)}=${encodeURIComponent(String(s))}`)},n=(i,s)=>{q(s)&&(Array.isArray(s)?s.forEach(o=>{n(i,o)}):typeof s=="object"?Object.entries(s).forEach(([o,a])=>{n(`${i}[${o}]`,a)}):r(i,s))};return Object.entries(t).forEach(([i,s])=>{n(i,s)}),e.length>0?`?${e.join("&")}`:""},$e=(t,e)=>{let r=t.ENCODE_PATH||encodeURI,n=e.url.replace("{api-version}",t.VERSION).replace(/{(.*?)}/g,(a,l)=>e.path?.hasOwnProperty(l)?r(String(e.path[l])):a),i=t.BASE.endsWith("/")?t.BASE.slice(0,-1):t.BASE,s=n.startsWith("/")?n.slice(1):n,o=`${i}/${s}`;return e.query?`${o}${qe(e.query)}`:o},Me=t=>{if(t.formData){let e=new FormData,r=(n,i)=>{x(i)||$(i)?e.append(n,i):e.append(n,JSON.stringify(i))};return Object.entries(t.formData).filter(([n,i])=>q(i)).forEach(([n,i])=>{Array.isArray(i)?i.forEach(s=>r(n,s)):r(n,i)}),e}},S=async(t,e)=>typeof e=="function"?e(t):e,He=async(t,e)=>{let[r,n,i,s]=await Promise.all([S(e,t.TOKEN),S(e,t.USERNAME),S(e,t.PASSWORD),S(e,t.HEADERS)]),o=Object.entries({Accept:"application/json",...s,...e.headers}).filter(([a,l])=>q(l)).reduce((a,[l,c])=>({...a,[l]:String(c)}),{});if(N(r)&&(o.Authorization=`Bearer ${r}`),N(n)&&N(i)){let a=Ne(`${n}:${i}`);o.Authorization=`Basic ${a}`}return e.body!==void 0&&(e.mediaType?o["Content-Type"]=e.mediaType:$(e.body)?o["Content-Type"]=e.body.type||"application/octet-stream":x(e.body)?o["Content-Type"]="text/plain":se(e.body)||(o["Content-Type"]="application/json")),new Headers(o)},_e=t=>{if(t.body!==void 0)return t.mediaType?.includes("/json")?JSON.stringify(t.body):x(t.body)||$(t.body)||se(t.body)?t.body:JSON.stringify(t.body)},je=async(t,e,r,n,i,s,o)=>{let a=new AbortController,l=t.TIMEOUT??2e4,c={headers:s,body:n??i,method:e.method,signal:AbortSignal.any([a.signal,AbortSignal.timeout(l)])};return t.WITH_CREDENTIALS&&(c.credentials=t.CREDENTIALS),o(()=>a.abort()),await fetch(r,c)},We=(t,e)=>{if(e){let r=t.headers.get(e);if(x(r))return r}},ze=async(t,e)=>{if(e?.responseType==="binary"&&t.status===204)return{bytes:new Uint8Array(0),contentType:t.headers.get("Content-Type")};if(t.status!==204){if(e?.responseType==="binary"&&t.ok)return{bytes:new Uint8Array(await t.arrayBuffer()),contentType:t.headers.get("Content-Type")};try{let r=t.headers.get("Content-Type");if(r)return["application/json","application/problem+json"].some(s=>r.toLowerCase().startsWith(s))?await t.json():await t.text()}catch(r){console.error(r)}}},ie=(t,e,r)=>{let i={400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",429:"Too Many Requests",500:"Internal Server Error",502:"Bad Gateway",503:"Service Unavailable",...t.errors}[e.status];if(i)throw new h(t,e,i,r);if(!e.ok){let s=e.status??"unknown",o=e.statusText??"unknown",a=(()=>{try{return JSON.stringify(e.body,null,2)}catch{return}})(),l=e.body?.message||e.body?.error||e.body?.detail||`Generic Error: status: ${s}; status text: ${o}; body: ${a}`;throw new h(t,e,l,r)}},Ve=(t,e,r)=>{let n=r?.rateLimitConfig||te;return new U(async(i,s,o)=>{let a=0,l=n.maxRetries+1;for(;a<l;){a++;try{let c=$e(t,e),f=Me(e),u=_e(e),R=await He(t,e);if(o.isCancelled)return;let p=await je(t,e,c,u,f,R,o),H=await ze(p,e),ae=We(p,e.responseHeader),L={url:c,ok:p.ok,status:p.status,statusText:p.statusText,body:p.ok?ae??H:H};if(n.enabled&&ne(p.status,L.body,n)){let _=re(p,n);if(a<l){let le=k(a,_,n);await B(le);continue}ie(e,L,_)}ie(e,L),i(L.body);return}catch(c){if(c instanceof h&&c.isRateLimitError()&&a<l){let f=c.retryAfter?c.retryAfter:k(a,{retryAfter:c.retryAfter,rateLimitReset:c.rateLimitReset},n);await B(f);continue}if(a>=l){s(c);return}if(c instanceof h&&c.isRateLimitError())continue;s(c);return}}})};var M=class{handlers=new Map;on(e,r){let n=this.handlers.get(e)||[];return n.push(r),this.handlers.set(e,n),this}off(e,r){let n=this.handlers.get(e)||[],i=n.indexOf(r);return i!==-1&&(n.splice(i,1),this.handlers.set(e,n)),this}getRegisteredEvents(){return Array.from(this.handlers.keys())}hasHandlers(e){let r=this.handlers.get(e);return!!r&&r.length>0}clearHandlers(e){return e?this.handlers.delete(e):this.handlers.clear(),this}async executeHandlers(e,r){let n=this.handlers.get(e)||[];for(let i of n)await i(r)}};import*as g from"crypto";function Ge(t,e,r,n="sha256"){if(!r||!e)return!1;let i=g.createHmac(n,e).update(t).digest("hex");try{return g.timingSafeEqual(Buffer.from(r),Buffer.from(i))}catch{return!1}}function Je(t,e,r,n,i="sha256"){if(!r||!e||!r.startsWith(n))return!1;let s=r.slice(n.length),o=g.createHmac(i,e).update(t).digest("hex");try{return g.timingSafeEqual(Buffer.from(s),Buffer.from(o))}catch{return!1}}function oe(t,e,r,n,i=300){if(!e||!n||!r)return!1;let s=Math.floor(Date.now()/1e3),o=parseInt(r,10);if(Math.abs(s-o)>i)return!1;let a=`v0:${r}:${t}`,l="v0="+g.createHmac("sha256",e).update(a).digest("hex");try{return g.timingSafeEqual(Buffer.from(n),Buffer.from(l))}catch{return!1}}function Qe(t,e,r,n,i=300){return oe(t,e,r,n,i)}export{h as ApiError,M as BaseWebhookHandler,ee as FILE_OUTPUT_MAX_BYTES,Ue as FileInputSchema,ke as FileOutputSchema,m as UnsafeUrlError,I as downloadPublicFile,Q as isBlockedAddress,Ve as request,Fe as resolveFileInput,Be as toFileOutput,oe as verifyHmacSha256Signature,Ge as verifyHmacSignature,Je as verifyHmacSignatureWithPrefix,Qe as verifySlackSignature};
1
+ import"./chunk-SOY77BN4.js";var ce=new Set(["apikey","xapikey","key","appkey","appid","token","apitoken","accesstoken","authtoken","clientsecret","secret","password"]);function C(t){let e=t;try{e=decodeURIComponent(t)}catch{e=t}return ce.has(e.toLowerCase().replace(/[-_]/g,""))}function ue(t){let e=t.indexOf("?");if(e===-1)return t;let n=t.indexOf("#",e),r=t.slice(0,e+1),i=n===-1?t.slice(e+1):t.slice(e+1,n),s=n===-1?"":t.slice(n),o=!1,a=i.split("&").map(l=>{if(!l)return l;let c=l.indexOf("="),f=c===-1?l:l.slice(0,c);return C(f)?(o=!0,`${f}=[REDACTED]`):l}).join("&");return o?r+a+s:t}function H(t){if(!t)return t;try{let e=/^[a-z]+:\/\//i.test(t),n=e?void 0:"http://localhost",r=new URL(t,n),i=!1;for(let s of[...r.searchParams.keys()])C(s)&&(r.searchParams.set(s,"[REDACTED]"),i=!0);return i?e?r.toString():r.pathname+r.search+r.hash:t}catch{return ue(t)}}function fe(t){let e=H(t.url),n=!1,r=t.query;if(t.query){r={...t.query};for(let i of Object.keys(r))C(i)&&(r[i]="[REDACTED]",n=!0)}return!n&&e===t.url?t:{...t,url:e,...n?{query:r}:{}}}var h=class extends Error{url;status;statusText;body;request;retryAfter;rateLimitReset;rateLimitRemaining;rateLimitLimit;constructor(e,n,r,i){super(r),this.name="ApiError",this.url=H(n.url),this.status=n.status,this.statusText=n.statusText,this.body=n.body,this.request=fe(e),this.retryAfter=i?.retryAfter,this.rateLimitReset=i?.rateLimitReset,this.rateLimitRemaining=i?.rateLimitRemaining,this.rateLimitLimit=i?.rateLimitLimit}isRateLimitError(){return this.status===429}};import{z as d}from"zod";import{lookup as de}from"dns/promises";import*as V from"http";import*as X from"https";import{pipeline as me,Readable as pe}from"stream";import*as T from"zlib";var he=3e4,ye=25*1024*1024,W=3,be=[["0.0.0.0",8],["10.0.0.0",8],["100.64.0.0",10],["127.0.0.0",8],["169.254.0.0",16],["172.16.0.0",12],["192.0.0.0",24],["192.0.2.0",24],["192.88.99.0",24],["192.168.0.0",16],["198.18.0.0",15],["198.51.100.0",24],["203.0.113.0",24],["224.0.0.0",4],["240.0.0.0",4]];function v(t){let e=t.split(".");if(e.length!==4)return;let n=0;for(let r of e){if(!/^\d{1,3}$/.test(r))return;let i=Number(r);if(i>255)return;n=n*256+i}return n}function G(t){let e=v(t);return e===void 0?!0:be.some(([n,r])=>{let i=v(n);if(i===void 0)return!1;let s=r===0?0:4294967295<<32-r>>>0;return(e&s)===(i&s)})}function ge(t){let e=t,n=e.indexOf("%");n!==-1&&(e=e.slice(0,n));let r=e.lastIndexOf(":");if(r===-1)return;let i=e.slice(r+1);if(i.includes(".")){let u=v(i);if(u===void 0)return;e=`${e.slice(0,r+1)}${(u>>>16).toString(16)}:${(u&65535).toString(16)}`}let s=e.split("::");if(s.length>2)return;let o=u=>u===""?[]:u.split(":").filter(R=>R!==""),a=o(s[0]??""),l=s.length===2?o(s[1]??""):[];if(![...a,...l].every(u=>/^[0-9a-fA-F]{1,4}$/.test(u)))return;if(s.length===1)return a.length===8?a.map(u=>Number.parseInt(u,16)):void 0;let c=8-a.length-l.length;return c<1?void 0:[...a,...Array(c).fill("0"),...l].map(u=>Number.parseInt(u,16))}function Re(t){let e=ge(t);if(!e)return!0;if(e.slice(0,5).every(r=>r===0)&&(e[5]===65535||e[5]===0)){let r=`${e[6]>>8}.${e[6]&255}.${e[7]>>8}.${e[7]&255}`;if(G(r))return!0}return!!(e.every(r=>r===0)||e.slice(0,7).every(r=>r===0)&&e[7]===1||(e[0]&65024)===64512||(e[0]&65472)===65152||(e[0]&65472)===65216||(e[0]&65280)===65280||e[0]===8194||e[0]===100&&e[1]===65435&&e.slice(2,6).every(r=>r===0)||e[0]===100&&e[1]===65435&&e[2]===1)}function J(t){let e=t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t;return e.includes(":")?Re(e):G(e)}var m=class extends Error{constructor(e){super(e),this.name="UnsafeUrlError"}};async function Te(t){return(await de(t,{all:!0,verbatim:!0})).map(n=>n.address)}function xe(t){return((e,n,r)=>{let i=r,s=typeof n=="object"&&n!==null&&n.all===!0,o=t.map(l=>({address:l,family:l.includes(":")?6:4}));if(o.length===0){i(new Error("No address to connect to."),"",0);return}if(s){i(null,o);return}let a=o[0];i(null,a.address,a.family)})}var Ae=(t,e,n)=>{let r=t.protocol==="https:",i=t.hostname.replace(/^\[|\]$/g,""),s={method:"GET",protocol:t.protocol,hostname:i,port:t.port===""?void 0:Number(t.port),path:`${t.pathname}${t.search}`,headers:{Accept:"*/*","Accept-Encoding":"identity"},lookup:xe(e),agent:!1,signal:n};return r&&(s.servername=i),new Promise((o,a)=>{let c=(r?X.request:V.request)(s,f=>{o({status:f.statusCode??0,headers:f.headers,body:f,cancel:()=>f.destroy()})});c.on("error",a),c.end()})};function we(t,e){return e?e.aborted?Promise.reject(e.reason):new Promise((n,r)=>{let i=()=>r(e.reason);e.addEventListener("abort",i,{once:!0}),t.then(s=>{e.removeEventListener("abort",i),n(s)},s=>{e.removeEventListener("abort",i),r(s)})}):t}async function z(t,e={},n){let r;try{r=new URL(t)}catch{throw new m("The file URL must be an absolute URL.")}if(r.protocol!=="http:"&&r.protocol!=="https:")throw new m("The file URL must use http or https.");let i=r.hostname.replace(/^\[|\]$/g,"");if(i==="")throw new m("The file URL must include a host.");let o=i.includes(":")||v(i)!==void 0?[i]:await we((e.resolve??Te)(i).catch(()=>{throw new m(`Could not resolve ${i}.`)}),n);if(o.length===0)throw new m(`Could not resolve ${i}.`);for(let a of o)if(J(a))throw new m(`The file URL points at ${i}, which resolves to a private or reserved address. Use a publicly reachable URL.`);return{url:r,addresses:o}}function Y(t,e){try{let n=new URL(t).pathname.split("/").pop();return n&&n.includes(".")?n:e}catch{return e}}function A(t,e){let n=t[e];return Array.isArray(n)?n[0]:n}function P(t){return new m(`The file is larger than the ${Math.round(t/(1024*1024))} MB limit.`)}async function*Le(t,e){let n=0;for await(let r of t){if(n+=r.byteLength,n>e)throw P(e);yield r}}async function ve(t,e){let n=[],r=0;for await(let o of t){if(r+=o.byteLength,r>e)throw P(e);n.push(o)}let i=new Uint8Array(r),s=0;for(let o of n)i.set(o,s),s+=o.byteLength;return i}async function Ee(t,e,n){let r=e?.trim().toLowerCase();if(!r||r==="identity")return t;let i=r==="gzip"||r==="x-gzip"?T.createGunzip():r==="deflate"?T.createInflate():r==="br"?T.createBrotliDecompress():void 0;if(!i)throw new m(`The file was served with an unsupported Content-Encoding (${r}).`);return me(pe.from(Le(t,n)),i,s=>{s&&i.destroy(s)}),i}function E(t){if(t!==void 0&&!(Number.isSafeInteger(t)&&t>=0))throw new RangeError(`maxBytes must be a whole number of bytes, 0 or more; got ${t}.`)}function Oe(t){if(!t)return;let e=/filename\*\s*=\s*(?:UTF-8|utf-8)''([^;]+)/.exec(t)?.[1];if(e)try{return decodeURIComponent(e.trim())}catch{}let n=/filename\s*=\s*("([^"]*)"|[^;]+)/.exec(t);return(n?.[2]??n?.[1]??"").trim()||void 0}async function I(t,e={},n={}){E(e.maxBytes);let r=e.maxBytes??ye,i=n.transport??Ae,s=AbortSignal.timeout(e.timeoutMs??he),o=await z(t,n,s);for(let a=0;;a++){let l=await i(o.url,o.addresses,s),c;try{let u=A(l.headers,"location");if(l.status>=300&&l.status<400&&u){if(l.cancel?.(),a>=W)throw new m(`The file URL redirected more than ${W} times.`);o=await z(new URL(u,o.url).toString(),n,s);continue}if(l.status<200||l.status>=300)throw new Error(`Could not download the file (${l.status}). Its URL must be publicly reachable.`);let R=Number(A(l.headers,"content-length"));if(Number.isFinite(R)&&R>r)throw P(r);c=await ve(await Ee(l.body,A(l.headers,"content-encoding"),r),r)}catch(u){throw l.cancel?.(),u}let f=Oe(A(l.headers,"content-disposition"));return{bytes:c,contentType:A(l.headers,"content-type")?.split(";")[0]?.trim()||"application/octet-stream",url:o.url.toString(),...f?{filename:f}:{}}}}var Q={filename:d.string().optional().describe("What to call the file. Defaults to the name in its URL."),contentType:d.string().optional().describe("Media type, for example application/pdf. Defaults to what the server states.")},Se=d.union([d.string().min(1).describe("A public http(s) URL to the file."),d.object({url:d.string().min(1).describe("A public http(s) URL to the file."),...Q}),d.object({base64:d.string().min(1).describe("The file, base64-encoded."),...Q})]).describe("A file: a public URL to it, or {url, filename?, contentType?}, or {base64, filename?, contentType?} for a small one.");function Ue(t){return typeof Blob<"u"&&t instanceof Blob}function O(t,e,n){return{bytes:t,filename:e,contentType:n,file:new File([new Uint8Array(t)],e,{type:n})}}var Ce=/^data:([^;,]*)((?:;[^;,=]+=[^;,]*)*)(;base64)?,(.*)$/is,x=t=>new Error(`The file is larger than the ${Math.round(t/(1024*1024))} MB limit.`);function D(t,e){if(t.byteLength===0)throw new Error("The file is empty.");if(e!==void 0&&t.byteLength>e)throw x(e);return t}function Pe(t,e){if(e!==void 0&&Math.ceil(t.length/3)>e)throw x(e);let n=new TextEncoder().encode(t),r=new Uint8Array(e===void 0?n.length:Math.min(n.length,e)),i=0;for(let s=0;s<n.length;s++){if(e!==void 0&&i===e)throw x(e);let o=n[s]===37?String.fromCharCode(n[s+1]??0,n[s+2]??0):"";/^[0-9a-fA-F]{2}$/.test(o)?(r[i++]=Number.parseInt(o,16),s+=2):r[i++]=n[s]}return i===r.length?r:r.slice(0,i)}var K=()=>new Error("The file is not valid base64."),Ie=new Set([9,10,11,12,13,32]);function De(t,e){if(!t.includes("%"))return t;let n=t.replace(/\s+/g,""),r=e===void 0?n.length:Math.min(n.length,Math.ceil(e/3)*4),i=new Uint8Array(r),s=0;for(let o=0;o<n.length;o++){let a=n.charCodeAt(o),l=a===37?n.slice(o+1,o+3):"";if(/^[0-9a-fA-F]{2}$/.test(l)&&(a=Number.parseInt(l,16),o+=2),!Ie.has(a)){if(a>127)throw K();if(s===r)throw x(e??r);i[s++]=a}}return Buffer.from(i.buffer,0,s).toString("latin1")}function Z(t,e){let n=t.replace(/\s+/g,"");if(n.length%4===0&&(n.endsWith("==")?n=n.slice(0,-2):n.endsWith("=")&&(n=n.slice(0,-1))),n.length===0||n.length%4===1||!/^[A-Za-z0-9+/_-]+$/.test(n))throw K();if(e!==void 0&&Math.floor(n.length*3/4)>e)throw x(e);return D(new Uint8Array(Buffer.from(n,"base64")),e)}async function ke(t,e={},n={}){E(e.maxBytes);let r=e.fallbackName??"file";if(Ue(t)){let a=typeof File<"u"&&t instanceof File&&t.name?t.name:r;if(e.maxBytes!==void 0&&t.size>e.maxBytes)throw x(e.maxBytes);return O(D(new Uint8Array(await t.arrayBuffer()),e.maxBytes),a,t.type||"application/octet-stream")}let i=typeof t=="string"?{url:t}:t;if("base64"in i)return O(Z(i.base64,e.maxBytes),i.filename??r,i.contentType??"application/octet-stream");let s=Ce.exec(i.url);if(s){let[,a,,l,c=""]=s,f=l?Z(De(c,e.maxBytes),e.maxBytes):D(Pe(c,e.maxBytes),e.maxBytes);return O(f,i.filename??r,i.contentType??(a||"application/octet-stream"))}let o=await I(i.url,e,n);return O(o.bytes,i.filename??o.filename??Y(o.url,r),i.contentType??o.contentType)}var Fe=d.object({contentBase64:d.string().optional().describe("The file, base64-encoded. Missing when the file came back as text or contentOmitted is set."),text:d.string().optional().describe("The file as text, in place of contentBase64, when it is a text file (CSV, JSON, Markdown, XML and the like) in UTF-8."),contentType:d.string().describe("Media type of the file, for example application/pdf."),byteLength:d.number().describe("Size of the file in bytes."),filename:d.string().optional().describe("The file name, when known."),contentOmitted:d.enum(["not_requested","over_limit"]).optional().describe("Set when the content was left out: the caller did not ask for it, or the file was over the limit.")}),ee=7e5,Be=new Set(["application/json","application/xml","application/javascript","application/ecmascript","application/x-javascript","application/yaml","application/x-yaml","application/toml","application/csv","application/ndjson","application/x-ndjson","application/sql","application/graphql","application/x-sh"]);function Ne(t){let e=t.toLowerCase();return e.startsWith("text/")||e.endsWith("+json")||e.endsWith("+xml")||Be.has(e)}var qe=new Set(["application/octet-stream","binary/octet-stream","application/unknown"]),$e=new Set(["txt","text","csv","tsv","md","markdown","json","jsonl","ndjson","xml","yaml","yml","toml","ini","log","html","htm","css","js","mjs","cjs","ts","tsx","jsx","sql","sh","py","rb","go","rs","java","svg","ics","vcf","srt","vtt"]);function je(t,e){if(Ne(t))return!0;if(!qe.has(t.toLowerCase()))return!1;let n=/\.([a-z0-9]+)$/.exec(e?.toLowerCase()??"")?.[1];return n!==void 0&&$e.has(n)}function Me(t){try{return new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(t)}catch{return}}function _e(t,e,n={}){E(n.maxBytes);let r={contentType:e?.split(";")[0]?.trim()||"application/octet-stream",byteLength:t.byteLength,...n.filename?{filename:n.filename}:{}};if(n.includeContent===!1)return{...r,contentOmitted:"not_requested"};if(t.byteLength>(n.maxBytes??ee))return{...r,contentOmitted:"over_limit"};let i=n.text!==!1&&je(r.contentType,n.filename)?Me(t):void 0;return i!==void 0?{...r,text:i}:{...r,contentBase64:Buffer.from(t).toString("base64")}}var k=class extends Error{constructor(e){super(e),this.name="CancelError"}get isCancelled(){return!0}},S=class{#t;#n;#e;#r;#s;#o;#i;constructor(e){this.#t=!1,this.#n=!1,this.#e=!1,this.#r=[],this.#s=new Promise((n,r)=>{this.#o=n,this.#i=r;let i=a=>{this.#t||this.#n||this.#e||(this.#t=!0,this.#o&&this.#o(a))},s=a=>{this.#t||this.#n||this.#e||(this.#n=!0,this.#i&&this.#i(a))},o=a=>{this.#t||this.#n||this.#e||this.#r.push(a)};return Object.defineProperty(o,"isResolved",{get:()=>this.#t}),Object.defineProperty(o,"isRejected",{get:()=>this.#n}),Object.defineProperty(o,"isCancelled",{get:()=>this.#e}),e(i,s,o)})}get[Symbol.toStringTag](){return"Cancellable Promise"}then(e,n){return this.#s.then(e,n)}catch(e){return this.#s.catch(e)}finally(e){return this.#s.finally(e)}cancel(){if(!(this.#t||this.#n||this.#e)){if(this.#e=!0,this.#r.length)try{for(let e of this.#r)e()}catch(e){console.warn("Cancellation threw an error",e);return}this.#r.length=0,this.#i&&this.#i(new k("Request aborted"))}}get isCancelled(){return this.#e}};var te={enabled:!0,maxRetries:3,initialRetryDelay:1e3,backoffMultiplier:2,headerNames:{retryAfter:"retry-after",resetTime:"x-ratelimit-reset",remaining:"x-ratelimit-remaining",limit:"x-ratelimit-limit"}};function ne(t,e){let n={};if(e.headerNames.retryAfter){let r=t.headers.get(e.headerNames.retryAfter);if(r){let i=parseInt(r,10);isNaN(i)||(n.retryAfter=i*1e3)}}if(e.headerNames.resetTime){let r=t.headers.get(e.headerNames.resetTime);if(r){let i=parseInt(r,10);if(!isNaN(i)){let s=Date.now(),o=i>1e12?i:i*1e3;n.rateLimitReset=o,o>s&&(n.retryAfter=o-s)}}}if(e.headerNames.remaining){let r=t.headers.get(e.headerNames.remaining);if(r){let i=parseInt(r,10);isNaN(i)||(n.rateLimitRemaining=i)}}if(e.headerNames.limit){let r=t.headers.get(e.headerNames.limit);if(r){let i=parseInt(r,10);isNaN(i)||(n.rateLimitLimit=i)}}return n}function re(t,e,n){return n.enabled?t===429?!0:n.isRateLimitError?n.isRateLimitError(t,e):!1:!1}function F(t,e,n){if(e.retryAfter)return e.retryAfter;let r=n.initialRetryDelay*Math.pow(n.backoffMultiplier,t-1);return Math.min(r,6e4)}async function B(t){return new Promise(e=>setTimeout(e,t))}var q=t=>t!=null,w=t=>typeof t=="string",N=t=>w(t)&&t!=="",$=t=>typeof t=="object"&&typeof t.type=="string"&&typeof t.stream=="function"&&typeof t.arrayBuffer=="function"&&typeof t.constructor=="function"&&typeof t.constructor.name=="string"&&/^(Blob|File)$/.test(t.constructor.name)&&/^(Blob|File)$/.test(t[Symbol.toStringTag]),se=t=>t instanceof FormData,He=t=>{try{return btoa(t)}catch{return Buffer.from(t).toString("base64")}},We=t=>{let e=[],n=(i,s)=>{e.push(`${encodeURIComponent(i)}=${encodeURIComponent(String(s))}`)},r=(i,s)=>{q(s)&&(Array.isArray(s)?s.forEach(o=>{r(i,o)}):typeof s=="object"?Object.entries(s).forEach(([o,a])=>{r(`${i}[${o}]`,a)}):n(i,s))};return Object.entries(t).forEach(([i,s])=>{r(i,s)}),e.length>0?`?${e.join("&")}`:""},ze=(t,e)=>{let n=t.ENCODE_PATH||encodeURI,r=e.url.replace("{api-version}",t.VERSION).replace(/{(.*?)}/g,(a,l)=>e.path?.hasOwnProperty(l)?n(String(e.path[l])):a),i=t.BASE.endsWith("/")?t.BASE.slice(0,-1):t.BASE,s=r.startsWith("/")?r.slice(1):r,o=`${i}/${s}`;return e.query?`${o}${We(e.query)}`:o},Ve=t=>{if(t.formData){let e=new FormData,n=(r,i)=>{w(i)||$(i)?e.append(r,i):e.append(r,JSON.stringify(i))};return Object.entries(t.formData).filter(([r,i])=>q(i)).forEach(([r,i])=>{Array.isArray(i)?i.forEach(s=>n(r,s)):n(r,i)}),e}},U=async(t,e)=>typeof e=="function"?e(t):e,Xe=async(t,e)=>{let[n,r,i,s]=await Promise.all([U(e,t.TOKEN),U(e,t.USERNAME),U(e,t.PASSWORD),U(e,t.HEADERS)]),o=Object.entries({Accept:"application/json",...s,...e.headers}).filter(([a,l])=>q(l)).reduce((a,[l,c])=>({...a,[l]:String(c)}),{});if(N(n)&&(o.Authorization=`Bearer ${n}`),N(r)&&N(i)){let a=He(`${r}:${i}`);o.Authorization=`Basic ${a}`}return e.body!==void 0&&(e.mediaType?o["Content-Type"]=e.mediaType:$(e.body)?o["Content-Type"]=e.body.type||"application/octet-stream":w(e.body)?o["Content-Type"]="text/plain":se(e.body)||(o["Content-Type"]="application/json")),new Headers(o)},Ge=t=>{if(t.body!==void 0)return t.mediaType?.includes("/json")?JSON.stringify(t.body):w(t.body)||$(t.body)||se(t.body)?t.body:JSON.stringify(t.body)},Je=async(t,e,n,r,i,s,o)=>{let a=new AbortController,l=t.TIMEOUT??2e4,c={headers:s,body:r??i,method:e.method,signal:AbortSignal.any([a.signal,AbortSignal.timeout(l)])};return t.WITH_CREDENTIALS&&(c.credentials=t.CREDENTIALS),o(()=>a.abort()),await fetch(n,c)},Ye=(t,e)=>{if(e){let n=t.headers.get(e);if(w(n))return n}},Qe=async(t,e)=>{if(e?.responseType==="binary"&&t.status===204)return{bytes:new Uint8Array(0),contentType:t.headers.get("Content-Type")};if(t.status!==204){if(e?.responseType==="binary"&&t.ok)return{bytes:new Uint8Array(await t.arrayBuffer()),contentType:t.headers.get("Content-Type")};try{let n=t.headers.get("Content-Type");if(n)return["application/json","application/problem+json"].some(s=>n.toLowerCase().startsWith(s))?await t.json():await t.text()}catch(n){console.error(n)}}},ie=(t,e,n)=>{let i={400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",429:"Too Many Requests",500:"Internal Server Error",502:"Bad Gateway",503:"Service Unavailable",...t.errors}[e.status];if(i)throw new h(t,e,i,n);if(!e.ok){let s=e.status??"unknown",o=e.statusText??"unknown",a=(()=>{try{return JSON.stringify(e.body,null,2)}catch{return}})(),l=e.body?.message||e.body?.error||e.body?.detail||`Generic Error: status: ${s}; status text: ${o}; body: ${a}`;throw new h(t,e,l,n)}},Ze=(t,e,n)=>{let r=n?.rateLimitConfig||te;return new S(async(i,s,o)=>{let a=0,l=r.maxRetries+1;for(;a<l;){a++;try{let c=ze(t,e),f=Ve(e),u=Ge(e),R=await Xe(t,e);if(o.isCancelled)return;let p=await Je(t,e,c,u,f,R,o),M=await Qe(p,e),ae=Ye(p,e.responseHeader),L={url:c,ok:p.ok,status:p.status,statusText:p.statusText,body:p.ok?ae??M:M};if(r.enabled&&re(p.status,L.body,r)){let _=ne(p,r);if(a<l){let le=F(a,_,r);await B(le);continue}ie(e,L,_)}ie(e,L),i(L.body);return}catch(c){if(c instanceof h&&c.isRateLimitError()&&a<l){let f=c.retryAfter?c.retryAfter:F(a,{retryAfter:c.retryAfter,rateLimitReset:c.rateLimitReset},r);await B(f);continue}if(a>=l){s(c);return}if(c instanceof h&&c.isRateLimitError())continue;s(c);return}}})};var j=class{handlers=new Map;on(e,n){let r=this.handlers.get(e)||[];return r.push(n),this.handlers.set(e,r),this}off(e,n){let r=this.handlers.get(e)||[],i=r.indexOf(n);return i!==-1&&(r.splice(i,1),this.handlers.set(e,r)),this}getRegisteredEvents(){return Array.from(this.handlers.keys())}hasHandlers(e){let n=this.handlers.get(e);return!!n&&n.length>0}clearHandlers(e){return e?this.handlers.delete(e):this.handlers.clear(),this}async executeHandlers(e,n){let r=this.handlers.get(e)||[];for(let i of r)await i(n)}};import*as g from"crypto";function Ke(t,e,n,r="sha256"){if(!n||!e)return!1;let i=g.createHmac(r,e).update(t).digest("hex");try{return g.timingSafeEqual(Buffer.from(n),Buffer.from(i))}catch{return!1}}function et(t,e,n,r,i="sha256"){if(!n||!e||!n.startsWith(r))return!1;let s=n.slice(r.length),o=g.createHmac(i,e).update(t).digest("hex");try{return g.timingSafeEqual(Buffer.from(s),Buffer.from(o))}catch{return!1}}function oe(t,e,n,r,i=300){if(!e||!r||!n)return!1;let s=Math.floor(Date.now()/1e3),o=parseInt(n,10);if(Math.abs(s-o)>i)return!1;let a=`v0:${n}:${t}`,l="v0="+g.createHmac("sha256",e).update(a).digest("hex");try{return g.timingSafeEqual(Buffer.from(r),Buffer.from(l))}catch{return!1}}function tt(t,e,n,r,i=300){return oe(t,e,n,r,i)}export{h as ApiError,j as BaseWebhookHandler,ee as FILE_OUTPUT_MAX_BYTES,Se as FileInputSchema,Fe as FileOutputSchema,m as UnsafeUrlError,I as downloadPublicFile,J as isBlockedAddress,Ze as request,ke as resolveFileInput,_e as toFileOutput,oe as verifyHmacSha256Signature,Ke as verifyHmacSignature,et as verifyHmacSignatureWithPrefix,tt as verifySlackSignature};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corsair",
3
- "version": "0.1.201",
3
+ "version": "0.1.202",
4
4
  "description": "Open-source integration layer for AI agents and apps. Managed OAuth, webhooks, and one API for 350+ integrations, with credentials that stay in your own database.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -90,10 +90,10 @@
90
90
  "optionalDependencies": {
91
91
  "@corsair-dev/frpc-darwin-arm64": "0.1.117",
92
92
  "@corsair-dev/frpc-darwin-x64": "0.1.117",
93
+ "@corsair-dev/frpc-linux-arm64": "0.1.117",
93
94
  "@corsair-dev/frpc-linux-x64": "0.1.117",
94
- "@corsair-dev/frpc-win32-x64": "0.1.117",
95
95
  "@corsair-dev/frpc-win32-arm64": "0.1.117",
96
- "@corsair-dev/frpc-linux-arm64": "0.1.117"
96
+ "@corsair-dev/frpc-win32-x64": "0.1.117"
97
97
  },
98
98
  "devDependencies": {
99
99
  "@testing-library/react": "^16.3.2",