Comparing version 1.2.4 to 1.2.5
@@ -1,1 +0,1 @@ | ||
var h="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36";function f(i){let e=new URLSearchParams(i).toString();return e?`?${e}`:""}function R(i){let e={},s=i.split(",").map(t=>t.trim().split(";")[0]).filter(t=>t?.includes("="));for(let t of s){let[u,n]=t.split("=");!u||!n||(e[u.trim()]=n.trim())}return e}function m(i){return Object.entries(i).map(([s,t])=>encodeURI(`${s}=${t}`)).join("; ")}function y(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 p=class i{constructor(e){this._headers={};this._cookies={};this._params={};this.headers={set:(e,s)=>{this._headers[e]=s},get:e=>this._headers[e],getAll:()=>this._headers,remove:e=>{delete this._headers[e]},update:e=>{this._headers={...e,...this._headers}}};this.cookies={set:(e,s)=>{this._cookies[e]=s},get:e=>this._cookies[e],getAll:()=>this._cookies,remove:e=>{delete this._cookies[e]},update:e=>{this._cookies={...e,...this._cookies}},toString:()=>m(this.cookies.getAll())};if(typeof e=="string"){this._baseUrl=e;return}this._baseUrl=e?.baseUrl??"",this._headers=e?.headers??{},this._cookies=e?.cookies??{},this._params=e?.params??{},this._storeCookies=e?.storeCookies??!0,this._headers["User-Agent"]=e?.userAgent??h,this._onRequest=e?.onRequest}async _request(e,s,t){if(e.startsWith("/")&&this._baseUrl==null)throw new Error("Cannot make request with relative URL without a base URL");let u=f({...t?.params,...this._params}),n=`${this._baseUrl}${e}${u}`;n.endsWith("/")&&(n=n.slice(0,-1));let l=y(t?.body),_={...l?{"Content-Type":l}:{},...t?.headers},d=this.cookies.toString(),o={method:s,headers:{...this.headers.getAll(),..._,...d?{Cookie:d}:{}},body:typeof t?.body=="object"&&!(t?.body instanceof FormData)&&!(t?.body instanceof URLSearchParams)&&!(t?.body instanceof Blob)&&!(t?.body instanceof ArrayBuffer)&&(typeof ReadableStream>"u"||!(t?.body instanceof ReadableStream))&&!(t?.body instanceof URL)&&!(t?.body instanceof Uint8Array)?JSON.stringify(t?.body):t?.body},g=await this._onRequest?.(n,o);o={...o,...g,headers:{...o.headers,...g?.headers}};let c=await fetch(n,o).then(async r=>{let{headers:a}=r,b=a.get("Content-Type")?.includes("application/json"),k=R(a.get("Set-Cookie")||"");return{...r,url:r.url,ok:r.ok,redirected:r.redirected,status:r.status,statusText:r.statusText,request:{url:e,method:s,options:o},headers:a,cookies:k,data:await(b?r.json():r.text())}});if(t?.ignoreCookies===!1&&this._storeCookies&&Object.entries(c.cookies).forEach(([r,a])=>{this.cookies.set(r,a)}),this._onResponse){let r=await this._onResponse(n,o,c);if(r)return r?.headers instanceof Headers?r:{...c,data:r}}return c}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,s){return this._request(e,"GET",s)}post(e,s){return this._request(e,"POST",s)}put(e,s){return this._request(e,"PUT",s)}delete(e,s){return this._request(e,"DELETE",s)}patch(e,s){return this._request(e,"PATCH",s)}onRequest(e){this._onRequest=e}onResponse(e){this._onResponse=e}},T=new p,U=T;export{p as Requestly,U as default,T as requestly}; | ||
var h="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36";function f(i){let e=new URLSearchParams(i).toString();return e?`?${e}`:""}function R(i){let e={},s=i.split(",").map(t=>t.trim().split(";")[0]).filter(t=>t?.includes("="));for(let t of s){let[u,n]=t.split("=");!u||!n||(e[u.trim()]=n.trim())}return e}function m(i){return Object.entries(i).map(([s,t])=>encodeURI(`${s}=${t}`)).join("; ")}function y(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 p=class i{constructor(e){this._headers={};this._cookies={};this._params={};this.headers={set:(e,s)=>{this._headers[e]=s},get:e=>this._headers[e],getAll:()=>this._headers,remove:e=>{delete this._headers[e]},update:e=>{this._headers={...e,...this._headers}}};this.cookies={set:(e,s)=>{this._cookies[e]=s},get:e=>this._cookies[e],getAll:()=>this._cookies,remove:e=>{delete this._cookies[e]},update:e=>{this._cookies={...e,...this._cookies}},toString:()=>m(this.cookies.getAll())};if(typeof e=="string"){this._baseUrl=e;return}this._baseUrl=e?.baseUrl??"",this._headers=e?.headers??{},this._cookies=e?.cookies??{},this._params=e?.params??{},this._storeCookies=e?.storeCookies??!0,this._headers["User-Agent"]=e?.userAgent??h,this._onRequest=e?.onRequest}async _request(e,s,t){if(e.startsWith("/")&&this._baseUrl==null)throw new Error("Cannot make request with relative URL without a base URL");let u=f({...t?.params,...this._params}),n=`${this._baseUrl}${e}${u}`;n.endsWith("/")&&(n=n.slice(0,-1));let l=y(t?.body),_={...l?{"Content-Type":l}:{},...t?.headers},d=this.cookies.toString(),o={method:s,headers:{...this.headers.getAll(),..._,...d?{Cookie:d}:{}},body:typeof t?.body=="object"&&!(t?.body instanceof FormData)&&!(t?.body instanceof URLSearchParams)&&!(t?.body instanceof Blob)&&!(t?.body instanceof ArrayBuffer)&&(typeof ReadableStream>"u"||!(t?.body instanceof ReadableStream))&&!(t?.body instanceof URL)&&!(t?.body instanceof Uint8Array)?JSON.stringify(t?.body):t?.body},g=await this._onRequest?.(n,o);o={...o,...g,headers:{...o.headers,...g?.headers}};let c=await fetch(n,o).then(async r=>{let{headers:a}=r,b=a.get("Content-Type")?.includes("application/json"),k=R(a.get("Set-Cookie")||"");return{...r,url:r.url,ok:r.ok,redirected:r.redirected,status:r.status,statusText:r.statusText,request:{url:e,method:s,options:o},headers:a,cookies:k,data:await(b?r.json():r.text())}});if(this._storeCookies&&Object.entries(c.cookies).forEach(([r,a])=>{this.cookies.set(r,a)}),this._onResponse){let r=await this._onResponse(n,o,c);if(r)return r?.headers instanceof Headers?r:{...c,data:r}}return c}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,s){return this._request(e,"GET",s)}post(e,s){return this._request(e,"POST",s)}put(e,s){return this._request(e,"PUT",s)}delete(e,s){return this._request(e,"DELETE",s)}patch(e,s){return this._request(e,"PATCH",s)}onRequest(e){this._onRequest=e}onResponse(e){this._onResponse=e}},T=new p,U=T;export{p as Requestly,U as default,T as requestly}; |
@@ -18,3 +18,2 @@ type RequestMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH"; | ||
cookies?: Record<string, string>; | ||
ignoreCookies?: boolean; | ||
body?: T; | ||
@@ -21,0 +20,0 @@ } |
{ | ||
"name": "requestly", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"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
19715
102