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.0 to 0.1.1

8

lib/index.d.ts

@@ -32,6 +32,6 @@ import { RequestsOptions, RequestOptions, RequestResponse } from './types.js';

get<T>(url: string, options?: Omit<RequestOptions, "body">): Promise<RequestResponse<T>>;
post<T>(options: RequestOptions): Promise<RequestResponse<T>>;
put<T>(options: RequestOptions): Promise<RequestResponse<T>>;
delete<T>(options: RequestOptions): Promise<RequestResponse<T>>;
patch<T>(options: RequestOptions): Promise<RequestResponse<T>>;
post<T>(url: string, options?: RequestOptions): Promise<RequestResponse<T>>;
put<T>(url: string, options?: RequestOptions): Promise<RequestResponse<T>>;
delete<T>(url: string, options?: RequestOptions): Promise<RequestResponse<T>>;
patch<T>(url: string, options?: RequestOptions): Promise<RequestResponse<T>>;
intercept({ onRequest, onResponse, }?: RequestsOptions["interceptors"]): void;

@@ -38,0 +38,0 @@ }

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

var d="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 R(o){let e={},t=o.split(",").map(s=>s.trim().split(";")[0]).filter(s=>s?.includes("="));for(let s of t){let[c,n]=s.split("=");!c||!n||(e[c.trim()]=n.trim())}return e}function l(o){return Object.entries(o).map(([t,s])=>encodeURI(`${t}=${s}`)).join("; ")}import"isomorphic-fetch";var u=class{constructor(e){this._headers={};this._cookies={};this._params={};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}}};this.cookies={set:(e,t)=>{this._cookies[e]=t},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())};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??d,this._onRequest=e?.interceptors?.onRequest,this._onResponse=e?.interceptors?.onResponse}async _request(e,t,s){if(e.startsWith("/")&&this._baseUrl==null)throw new Error("Cannot make request with relative URL without a base URL");let c=g({...s?.params,...this._params}),n=`${this._baseUrl}${e}${c}`,q={...s?.body&&{"Content-Type":s?.contentType||"application/json"},...s?.headers},r={method:t,headers:{...this.headers.getAll(),...q,Cookie:this.cookies.toString()},body:typeof s?.body=="object"&&!(s?.body instanceof FormData)&&!(s?.body instanceof URLSearchParams)&&!(s?.body instanceof Blob)&&!(s?.body instanceof ArrayBuffer)&&!(s?.body instanceof ReadableStream)&&!(s?.body instanceof URL)&&!(s?.body instanceof Uint8Array)?JSON.stringify(s?.body):s?.body},h=await this._onRequest?.(n,r);r={...r,...h,headers:{...r.headers,...h?.headers}};let p=await fetch(n,r).then(async i=>{let{headers:a}=i,_=a.get("Content-Type")?.includes("application/json"),f=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:t,options:r},headers:a,cookies:f,data:await(_?i.json():i.text())}});return s?.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,t){return this._request(e,"GET",t)}post(e,t){return typeof e=="string"?this._request(e,"POST",t):this._request("","POST",t)}put(e,t){return typeof e=="string"?this._request(e,"PUT",t):this._request("","PUT",t)}delete(e,t){return typeof e=="string"?this._request(e,"DELETE",t):this._request("","DELETE",t)}patch(e,t){return typeof e=="string"?this._request(e,"PATCH",t):this._request("","PATCH",t)}intercept({onRequest:e,onResponse:t}={}){this._onRequest=e??this._onRequest,this._onResponse=t??this._onResponse}},b=new u,y=b;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,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};
{
"name": "requestly",
"version": "0.1.0",
"version": "0.1.1",
"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