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.0.1 to 0.0.2

2

lib/index.js

@@ -1,1 +0,1 @@

var g="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36";function h(o){return new URLSearchParams(o).toString()}function R(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 l(o){return Object.entries(o).map(([s,t])=>encodeURI(`${s}=${t}`)).join("; ")}import"isomorphic-fetch";var u=class{constructor(e){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:()=>l(this.cookies.getAll())};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??g,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=h({...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},d=await this._onRequest?.(n,r);r={...r,...d,headers:{...r.headers,...d?.headers}};let p=await fetch(n,r).then(async i=>{let{headers:a}=i,b=a.get("Content-Type")?.includes("application/json"),q=R(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:q,data:await(b?i.json():i.text())}});return t?.ignoreCookies!==!1&&this._storeCookies&&Object.entries(p.cookies).forEach(([i,a])=>this.cookies.set(i,a)),this._onResponse&&await this._onResponse(n,r,p),p}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;export{u as Requestly,k as requests};
var g="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36";function h(o){let e=new URLSearchParams(o).toString();return e?`?${e}`:""}function R(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 l(o){return Object.entries(o).map(([s,t])=>encodeURI(`${s}=${t}`)).join("; ")}import"isomorphic-fetch";var u=class{constructor(e){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:()=>l(this.cookies.getAll())};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??g,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=h({...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},d=await this._onRequest?.(n,r);r={...r,...d,headers:{...r.headers,...d?.headers}};let p=await fetch(n,r).then(async i=>{let{headers:a}=i,b=a.get("Content-Type")?.includes("application/json"),q=R(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:q,data:await(b?i.json():i.text())}});return t?.ignoreCookies!==!1&&this._storeCookies&&Object.entries(p.cookies).forEach(([i,a])=>this.cookies.set(i,a)),this._onResponse&&await this._onResponse(n,r,p),p}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;export{u as Requestly,k as requests};
{
"name": "requestly",
"version": "0.0.1",
"version": "0.0.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