Socket
Socket
Sign inDemoInstall

requestly

Package Overview
Dependencies
9
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1 to 0.1.2

2

lib/index.js

@@ -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 g(o){let e=new URLSearchParams(o).toString();return e?`?${e}`:""}function l(o){let e={},s=o.split(",").map(t=>t.trim().split(";")[0]).filter(t=>t?.includes("="));for(let t of s){let[c,n]=t.split("=");!c||!n||(e[c.trim()]=n.trim())}return e}function R(o){return Object.entries(o).map(([s,t])=>encodeURI(`${s}=${t}`)).join("; ")}import"isomorphic-fetch";var u=class{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:()=>R(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?.interceptors?.onRequest,this._onResponse=e?.interceptors?.onResponse}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 c=g({...t?.params,...this._params}),n=`${this._baseUrl}${e}${c}`,_={...t?.body&&{"Content-Type":t?.contentType||"application/json"},...t?.headers},r={method:s,headers:{...this.headers.getAll(),..._,Cookie:this.cookies.toString()},body:typeof t?.body=="object"&&!(t?.body instanceof FormData)&&!(t?.body instanceof URLSearchParams)&&!(t?.body instanceof Blob)&&!(t?.body instanceof ArrayBuffer)&&!(t?.body instanceof ReadableStream)&&!(t?.body instanceof URL)&&!(t?.body instanceof Uint8Array)?JSON.stringify(t?.body):t?.body},p=await this._onRequest?.(n,r);r={...r,...p,headers:{...r.headers,...p?.headers}};let d=await fetch(n,r).then(async i=>{let{headers:a}=i,b=a.get("Content-Type")?.includes("application/json"),f=l(a.get("Set-Cookie")||"");return{...i,url:i.url,ok:i.ok,redirected:i.redirected,status:i.status,statusText:i.statusText,request:{url:e,method:s,options:r},headers:a,cookies:f,data:await(b?i.json():i.text())}});return t?.ignoreCookies!==!1&&this._storeCookies&&Object.entries(d.cookies).forEach(([i,a])=>this.cookies.set(i,a)),this._onResponse&&await this._onResponse(n,r,d),d}create(e){return new u(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)}intercept({onRequest:e,onResponse:s}={}){this._onRequest=e??this._onRequest,this._onResponse=s??this._onResponse}},k=new u,y=k;export{u as Requestly,y as default};
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 g(o){let e=new URLSearchParams(o).toString();return e?`?${e}`:""}function l(o){let e={},s=o.split(",").map(t=>t.trim().split(";")[0]).filter(t=>t?.includes("="));for(let t of s){let[c,r]=t.split("=");!c||!r||(e[c.trim()]=r.trim())}return e}function R(o){return Object.entries(o).map(([s,t])=>encodeURI(`${s}=${t}`)).join("; ")}import"isomorphic-fetch";var u=class{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:()=>R(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?.interceptors?.onRequest,this._onResponse=e?.interceptors?.onResponse}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 c=g({...t?.params,...this._params}),r=`${this._baseUrl}${e}${c}`;r.endsWith("/")&&(r=r.slice(0,-1));let _={...t?.body&&{"Content-Type":t?.contentType||"application/json"},...t?.headers},n={method:s,headers:{...this.headers.getAll(),..._,Cookie:this.cookies.toString()},body:typeof t?.body=="object"&&!(t?.body instanceof FormData)&&!(t?.body instanceof URLSearchParams)&&!(t?.body instanceof Blob)&&!(t?.body instanceof ArrayBuffer)&&!(t?.body instanceof ReadableStream)&&!(t?.body instanceof URL)&&!(t?.body instanceof Uint8Array)?JSON.stringify(t?.body):t?.body},p=await this._onRequest?.(r,n);n={...n,...p,headers:{...n.headers,...p?.headers}};let d=await fetch(r,n).then(async i=>{let{headers:a}=i,b=a.get("Content-Type")?.includes("application/json"),f=l(a.get("Set-Cookie")||"");return{...i,url:i.url,ok:i.ok,redirected:i.redirected,status:i.status,statusText:i.statusText,request:{url:e,method:s,options:n},headers:a,cookies:f,data:await(b?i.json():i.text())}});return t?.ignoreCookies!==!1&&this._storeCookies&&Object.entries(d.cookies).forEach(([i,a])=>this.cookies.set(i,a)),this._onResponse&&await this._onResponse(r,n,d),d}create(e){return new u(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)}intercept({onRequest:e,onResponse:s}={}){this._onRequest=e??this._onRequest,this._onResponse=s??this._onResponse}},k=new u,y=k;export{u as Requestly,y as default};
{
"name": "requestly",
"version": "0.1.1",
"version": "0.1.2",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc