corsair 0.1.181 → 0.1.182
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.js +1 -1
- package/package.json +3 -3
package/dist/http.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk-SOY77BN4.js";var M=new Set(["
|
|
1
|
+
import"./chunk-SOY77BN4.js";var M=new Set(["apikey","xapikey","key","appkey","appid","token","apitoken","accesstoken","authtoken","clientsecret","secret","password"]);function T(t){let e=t;try{e=decodeURIComponent(t)}catch{e=t}return M.has(e.toLowerCase().replace(/[-_]/g,""))}function F(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),a=!1,o=i.split("&").map(c=>{if(!c)return c;let u=c.indexOf("="),d=u===-1?c:c.slice(0,u);return T(d)?(a=!0,`${d}=[REDACTED]`):c}).join("&");return a?r+o+s:t}function q(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()])T(s)&&(r.searchParams.set(s,"[REDACTED]"),i=!0);return i?e?r.toString():r.pathname+r.search+r.hash:t}catch{return F(t)}}function U(t){let e=q(t.url),n=!1,r=t.query;if(t.query){r={...t.query};for(let i of Object.keys(r))T(i)&&(r[i]="[REDACTED]",n=!0)}return!n&&e===t.url?t:{...t,url:e,...n?{query:r}:{}}}var f=class extends Error{url;status;statusText;body;request;retryAfter;rateLimitReset;rateLimitRemaining;rateLimitLimit;constructor(e,n,r,i){super(r),this.name="ApiError",this.url=q(n.url),this.status=n.status,this.statusText=n.statusText,this.body=n.body,this.request=U(e),this.retryAfter=i?.retryAfter,this.rateLimitReset=i?.rateLimitReset,this.rateLimitRemaining=i?.rateLimitRemaining,this.rateLimitLimit=i?.rateLimitLimit}isRateLimitError(){return this.status===429}};var A=class extends Error{constructor(e){super(e),this.name="CancelError"}get isCancelled(){return!0}},g=class{#t;#r;#e;#n;#s;#a;#i;constructor(e){this.#t=!1,this.#r=!1,this.#e=!1,this.#n=[],this.#s=new Promise((n,r)=>{this.#a=n,this.#i=r;let i=o=>{this.#t||this.#r||this.#e||(this.#t=!0,this.#a&&this.#a(o))},s=o=>{this.#t||this.#r||this.#e||(this.#r=!0,this.#i&&this.#i(o))},a=o=>{this.#t||this.#r||this.#e||this.#n.push(o)};return Object.defineProperty(a,"isResolved",{get:()=>this.#t}),Object.defineProperty(a,"isRejected",{get:()=>this.#r}),Object.defineProperty(a,"isCancelled",{get:()=>this.#e}),e(i,s,a)})}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.#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 A("Request aborted"))}}get isCancelled(){return this.#e}};var w={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 N(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(),a=i>1e12?i:i*1e3;n.rateLimitReset=a,a>s&&(n.retryAfter=a-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 I(t,e,n){return n.enabled?t===429?!0:n.isRateLimitError?n.isRateLimitError(t,e):!1:!1}function E(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 x(t){return new Promise(e=>setTimeout(e,t))}var O=t=>t!=null,h=t=>typeof t=="string",L=t=>h(t)&&t!=="",v=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]),D=t=>t instanceof FormData,_=t=>{try{return btoa(t)}catch{return Buffer.from(t).toString("base64")}},J=t=>{let e=[],n=(i,s)=>{e.push(`${encodeURIComponent(i)}=${encodeURIComponent(String(s))}`)},r=(i,s)=>{O(s)&&(Array.isArray(s)?s.forEach(a=>{r(i,a)}):typeof s=="object"?Object.entries(s).forEach(([a,o])=>{r(`${i}[${a}]`,o)}):n(i,s))};return Object.entries(t).forEach(([i,s])=>{r(i,s)}),e.length>0?`?${e.join("&")}`:""},z=(t,e)=>{let n=t.ENCODE_PATH||encodeURI,r=e.url.replace("{api-version}",t.VERSION).replace(/{(.*?)}/g,(o,c)=>e.path?.hasOwnProperty(c)?n(String(e.path[c])):o),i=t.BASE.endsWith("/")?t.BASE.slice(0,-1):t.BASE,s=r.startsWith("/")?r.slice(1):r,a=`${i}/${s}`;return e.query?`${a}${J(e.query)}`:a},Q=t=>{if(t.formData){let e=new FormData,n=(r,i)=>{h(i)||v(i)?e.append(r,i):e.append(r,JSON.stringify(i))};return Object.entries(t.formData).filter(([r,i])=>O(i)).forEach(([r,i])=>{Array.isArray(i)?i.forEach(s=>n(r,s)):n(r,i)}),e}},R=async(t,e)=>typeof e=="function"?e(t):e,G=async(t,e)=>{let[n,r,i,s]=await Promise.all([R(e,t.TOKEN),R(e,t.USERNAME),R(e,t.PASSWORD),R(e,t.HEADERS)]),a=Object.entries({Accept:"application/json",...s,...e.headers}).filter(([o,c])=>O(c)).reduce((o,[c,u])=>({...o,[c]:String(u)}),{});if(L(n)&&(a.Authorization=`Bearer ${n}`),L(r)&&L(i)){let o=_(`${r}:${i}`);a.Authorization=`Basic ${o}`}return e.body!==void 0&&(e.mediaType?a["Content-Type"]=e.mediaType:v(e.body)?a["Content-Type"]=e.body.type||"application/octet-stream":h(e.body)?a["Content-Type"]="text/plain":D(e.body)||(a["Content-Type"]="application/json")),new Headers(a)},V=t=>{if(t.body!==void 0)return t.mediaType?.includes("/json")?JSON.stringify(t.body):h(t.body)||v(t.body)||D(t.body)?t.body:JSON.stringify(t.body)},K=async(t,e,n,r,i,s,a)=>{let o=new AbortController,c=t.TIMEOUT??2e4,u={headers:s,body:r??i,method:e.method,signal:AbortSignal.any([o.signal,AbortSignal.timeout(c)])};return t.WITH_CREDENTIALS&&(u.credentials=t.CREDENTIALS),a(()=>o.abort()),await fetch(n,u)},Y=(t,e)=>{if(e){let n=t.headers.get(e);if(h(n))return n}},X=async t=>{if(t.status!==204)try{let e=t.headers.get("Content-Type");if(e)return["application/json","application/problem+json"].some(i=>e.toLowerCase().startsWith(i))?await t.json():await t.text()}catch(e){console.error(e)}},k=(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 f(t,e,i,n);if(!e.ok){let s=e.status??"unknown",a=e.statusText??"unknown",o=(()=>{try{return JSON.stringify(e.body,null,2)}catch{return}})(),c=e.body?.message||e.body?.error||e.body?.detail||`Generic Error: status: ${s}; status text: ${a}; body: ${o}`;throw new f(t,e,c,n)}},Z=(t,e,n)=>{let r=n?.rateLimitConfig||w;return new g(async(i,s,a)=>{let o=0,c=r.maxRetries+1;for(;o<c;){o++;try{let u=z(t,e),d=Q(e),B=V(e),j=await G(t,e);if(a.isCancelled)return;let l=await K(t,e,u,B,d,j,a),P=await X(l),$=Y(l,e.responseHeader),b={url:u,ok:l.ok,status:l.status,statusText:l.statusText,body:l.ok?$??P:P};if(r.enabled&&I(l.status,b.body,r)){let S=N(l,r);if(o<c){let W=E(o,S,r);await x(W);continue}k(e,b,S)}k(e,b),i(b.body);return}catch(u){if(u instanceof f&&u.isRateLimitError()&&o<c){let d=u.retryAfter?u.retryAfter:E(o,{retryAfter:u.retryAfter,rateLimitReset:u.rateLimitReset},r);await x(d);continue}if(o>=c){s(u);return}if(u instanceof f&&u.isRateLimitError())continue;s(u);return}}})};var C=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 m from"crypto";function ee(t,e,n,r="sha256"){if(!n||!e)return!1;let i=m.createHmac(r,e).update(t).digest("hex");try{return m.timingSafeEqual(Buffer.from(n),Buffer.from(i))}catch{return!1}}function te(t,e,n,r,i="sha256"){if(!n||!e||!n.startsWith(r))return!1;let s=n.slice(r.length),a=m.createHmac(i,e).update(t).digest("hex");try{return m.timingSafeEqual(Buffer.from(s),Buffer.from(a))}catch{return!1}}function H(t,e,n,r,i=300){if(!e||!r||!n)return!1;let s=Math.floor(Date.now()/1e3),a=parseInt(n,10);if(Math.abs(s-a)>i)return!1;let o=`v0:${n}:${t}`,c="v0="+m.createHmac("sha256",e).update(o).digest("hex");try{return m.timingSafeEqual(Buffer.from(r),Buffer.from(c))}catch{return!1}}function re(t,e,n,r,i=300){return H(t,e,n,r,i)}export{f as ApiError,C as BaseWebhookHandler,Z as request,H as verifyHmacSha256Signature,ee as verifyHmacSignature,te as verifyHmacSignatureWithPrefix,re as verifySlackSignature};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "corsair",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.182",
|
|
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-x64": "0.1.117",
|
|
93
94
|
"@corsair-dev/frpc-linux-arm64": "0.1.117",
|
|
94
|
-
"@corsair-dev/frpc-win32-arm64": "0.1.117",
|
|
95
95
|
"@corsair-dev/frpc-win32-x64": "0.1.117",
|
|
96
|
-
"@corsair-dev/frpc-
|
|
96
|
+
"@corsair-dev/frpc-win32-arm64": "0.1.117"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"@testing-library/react": "^16.3.2",
|