Comparing version 1.3.5 to 1.3.6
@@ -1,1 +0,1 @@ | ||
import{CookieJar as d}from"tough-cookie";import{splitCookiesString as C}from"set-cookie-parser";var _="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36";function b(i){let e=new URLSearchParams(i).toString();return e?`?${e}`:""}function q(i){return!i||i instanceof FormData?"":i instanceof URLSearchParams?"application/x-www-form-urlencoded":i instanceof Blob||i instanceof ArrayBuffer||typeof ReadableStream<"u"&&i instanceof ReadableStream?"application/octet-stream":i instanceof URL?"text/uri-list":i instanceof Uint8Array?"application/octet-stream":typeof i.uri=="string"&&typeof i.type=="string"?i.type||"application/octet-stream":"application/json"}var O=new Set([301,302,303,307,308]),h=class i{constructor(e){this._headers={};this._params={};this.cookies={serialize:()=>this._cookieJar.serializeSync().cookies,deserialize:e=>{this._cookieJar=d.deserializeSync({rejectPublicSuffixes:!0,storeType:"MemoryCookieStore",version:"tough-cookie@4.1.4",cookies:e})},get:async(e,t)=>{if(t)return(await this._cookieJar.getCookies(t)).find(p=>p.key===e)?.value??null;let s=await this._cookieJar.serialize();for(let a of s.cookies)if(a.key?.toLowerCase()===e.toLowerCase())return a.value;return null},getAll:async e=>this._cookieJar.getCookies(e),set:async(e,t)=>{await this._cookieJar.setCookie(t,e)},clear:()=>{this._cookieJar=new d}};this.headers={set:(e,t)=>{this._headers[e]=t},get:e=>this._headers[e],getAll:()=>this._headers,remove:e=>{delete this._headers[e]},update:e=>{this._headers={...e,...this._headers}}};if(typeof e=="string"){this._baseUrl=e,this._cookieJar=new d,this._maxRedirects=20;return}this._baseUrl=e?.baseUrl??"",this._headers=e?.headers??{},this._params=e?.params??{},this._cookieJar=new d,e?.cookies&&this.cookies.deserialize(e.cookies),this._headers["User-Agent"]=e?.userAgent??_,this._onRequest=e?.onRequest,this._maxRedirects=e?.maxRedirects??20}async _request(e,t,s,a=0){if(e.startsWith("/")&&this._baseUrl==null)throw new Error("Cannot make request with relative URL without a base URL");let p=b({...s?.params,...this._params}),o=`${this._baseUrl}${e}${p}`;o.endsWith("/")&&(o=o.slice(0,-1));let f=q(s?.body),T={...f?{"Content-Type":f}:{},...s?.headers},R=await this._cookieJar.getCookieString(o)+"; "+Object.entries(s?.cookies??{}).map(([n,u])=>`${n}=${u}`).join("; "),c={method:t,headers:{...this.headers.getAll(),...T,...R?{Cookie:R}:{}},body:typeof s?.body=="object"&&!(s?.body instanceof FormData)&&!(s?.body instanceof URLSearchParams)&&!(s?.body instanceof Blob)&&!(s?.body instanceof ArrayBuffer)&&(typeof ReadableStream>"u"||!(s?.body instanceof ReadableStream))&&!(s?.body instanceof URL)&&!(s?.body instanceof Uint8Array)?JSON.stringify(s?.body):s?.body},y=await this._onRequest?.(o,c);c={...c,...y,headers:{...c.headers,...y?.headers},redirect:"manual"};let r=await fetch(o,c),m={},k=r.headers.get("Set-Cookie");if(k){let n=C(k);for(let u of n){let l=await this._cookieJar.setCookie(u,o,{ignoreError:!0});m[l.key]=l.value}}if(O.has(r.status)&&a<this._maxRedirects){let n=r.headers.get("Location");if(n){let u=new URL(n,o).toString(),l=r.status===303?"GET":t,U=r.status===303?void 0:s?.body;return this._request(u,l,{...s,body:U},a+1)}}let w=r.headers.get("Content-Type")?.includes("application/json"),g={...r,url:r.url,ok:r.ok,redirected:a>0,status:r.status,statusText:r.statusText,request:{url:e,method:t,options:c},headers:r.headers,cookies:m,data:await(w?r.json():r.text()),retry:async()=>this._request(e,t,s,a)};if(this._onResponse){let n=await this._onResponse(o,c,g);if(n)return n?.headers instanceof Headers?n:{...g,data:n}}return g}get baseUrl(){return this._baseUrl}set baseUrl(e){this._baseUrl=e}create(e){return new i(e)}get params(){return this._params}set params(e){this._params=e}get(e,t){return this._request(e,"GET",t)}post(e,t){return this._request(e,"POST",t)}put(e,t){return this._request(e,"PUT",t)}delete(e,t){return this._request(e,"DELETE",t)}patch(e,t){return this._request(e,"PATCH",t)}onRequest(e){this._onRequest=e}onResponse(e){this._onResponse=e}},x=new h,J=x;export{h as Requestly,J as default,x as requestly}; | ||
import{CookieJar as d}from"tough-cookie";import{splitCookiesString as S}from"set-cookie-parser";var _="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36";function b(i){let e=new URLSearchParams(i).toString();return e?`?${e}`:""}function q(i){return!i||i instanceof FormData?"":i instanceof URLSearchParams?"application/x-www-form-urlencoded":i instanceof Blob||i instanceof ArrayBuffer||typeof ReadableStream<"u"&&i instanceof ReadableStream?"application/octet-stream":i instanceof URL?"text/uri-list":i instanceof Uint8Array?"application/octet-stream":typeof i.uri=="string"&&typeof i.type=="string"?i.type||"application/octet-stream":"application/json"}var C=new Set([301,302,303,307,308]),h=class i{constructor(e){this._headers={};this._params={};this.cookies={serialize:()=>this._cookieJar.serializeSync().cookies,deserialize:e=>{this._cookieJar=d.deserializeSync({rejectPublicSuffixes:!0,storeType:"MemoryCookieStore",version:"tough-cookie@4.1.4",cookies:e})},get:async(e,t)=>{if(t)return(await this._cookieJar.getCookies(t)).find(p=>p.key===e)?.value??null;let s=await this._cookieJar.serialize();for(let a of s.cookies)if(a.key?.toLowerCase()===e.toLowerCase())return a.value;return null},getAll:async e=>this._cookieJar.getCookies(e),set:async(e,t)=>{await this._cookieJar.setCookie(t,e)},clear:()=>{this._cookieJar=new d}};this.headers={set:(e,t)=>{this._headers[e]=t},get:e=>this._headers[e],getAll:()=>this._headers,remove:e=>{delete this._headers[e]},update:e=>{this._headers={...e,...this._headers}}};if(typeof e=="string"){this._baseUrl=e,this._cookieJar=new d,this._maxRedirects=20;return}this._baseUrl=e?.baseUrl??"",this._headers=e?.headers??{},this._params=e?.params??{},this._cookieJar=new d,e?.cookies&&this.cookies.deserialize(e.cookies),this._headers["User-Agent"]=e?.userAgent??_,this._onRequest=e?.onRequest,this._maxRedirects=e?.maxRedirects??20}async _request(e,t,s,a=0){if(e.startsWith("/")&&this._baseUrl==null)throw new Error("Cannot make request with relative URL without a base URL");let p=b({...s?.params,...this._params}),o=`${this._baseUrl}${e}${p}`;o.endsWith("/")&&(o=o.slice(0,-1));let f=q(s?.body),T={...f?{"Content-Type":f}:{},...s?.headers},R=await this._cookieJar.getCookieString(o)+"; "+Object.entries(s?.cookies??{}).map(([n,u])=>`${n}=${u}`).join("; "),c={method:t,headers:{...this.headers.getAll(),...T,...R?{Cookie:R}:{}},body:typeof s?.body=="object"&&!(s?.body instanceof FormData)&&!(s?.body instanceof URLSearchParams)&&!(s?.body instanceof Blob)&&!(s?.body instanceof ArrayBuffer)&&(typeof ReadableStream>"u"||!(s?.body instanceof ReadableStream))&&!(s?.body instanceof URL)&&!(s?.body instanceof Uint8Array)?JSON.stringify(s?.body):s?.body},y=await this._onRequest?.(o,c);c={...c,...y,headers:{...c.headers,...y?.headers},redirect:"manual"};let r=await fetch(o,c),m={},k=r.headers.get("Set-Cookie");if(k){let n=S(k);for(let u of n){let l=await this._cookieJar.setCookie(u,o,{ignoreError:!0});m[l.key]=l.value}}if(C.has(r.status)&&a<this._maxRedirects){let n=r.headers.get("Location");if(n){let u=new URL(n,o).toString(),l=r.status===303?"GET":t,U=r.status===303?void 0:s?.body;return this._request(u,l,{...s,body:U},a+1)}}let w=r.headers.get("Content-Type")?.includes("application/json"),g={...r,url:r.url,ok:r.ok,redirected:a>0,status:r.status,statusText:r.statusText,request:{url:e,method:t,options:c},headers:r.headers,cookies:m,data:await(w?r.json():r.text()),retry:async()=>this._request(e,t,s,a)};if(this._onResponse){let n=await this._onResponse({url:o,init:c,response:g});if(n)return n?.headers instanceof Headers?n:{...g,data:n.data}}return g}get baseUrl(){return this._baseUrl}set baseUrl(e){this._baseUrl=e}create(e){return new i(e)}get params(){return this._params}set params(e){this._params=e}get(e,t){return this._request(e,"GET",t)}post(e,t){return this._request(e,"POST",t)}put(e,t){return this._request(e,"PUT",t)}delete(e,t){return this._request(e,"DELETE",t)}patch(e,t){return this._request(e,"PATCH",t)}onRequest(e){this._onRequest=e}onResponse(e){this._onResponse=e}},x=new h,J=x;export{h as Requestly,J as default,x as requestly}; |
type RequestMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH"; | ||
type OnResponse<T = any> = (url: string, init: RequestInit, response: RequestlyResponse<T>) => RequestlyResponse<T> | Promise<RequestlyResponse<T>> | Promise<T> | T | void; | ||
type OnResponse<T> = (params: { | ||
url: string; | ||
init: RequestInit; | ||
response: RequestlyResponse<T>; | ||
}) => MaybePromise<RequestlyResponse<T> | void>; | ||
interface RequestlyOptions { | ||
@@ -11,3 +15,3 @@ baseUrl?: string; | ||
onRequest?: (url: string, init: RequestInit) => MaybePromise<RequestInit | void>; | ||
onResponse?: OnResponse; | ||
onResponse?: OnResponse<unknown>; | ||
} | ||
@@ -14,0 +18,0 @@ type MaybePromise<T> = T | Promise<T>; |
{ | ||
"name": "requestly", | ||
"version": "1.3.5", | ||
"version": "1.3.6", | ||
"description": "A minimal, but powerful HTTP Client for Node.js", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21606
112