Comparing version 2.0.1 to 2.0.3
@@ -1,4 +0,14 @@ | ||
import { SerializedCookie } from 'tough-cookie'; | ||
import { RequestlyOptions, RequestOptions, RequestlyResponse, MaybePromise, OnResponse, RequestMethod } from './types.js'; | ||
interface SerializedCookie { | ||
key: string; | ||
value: string; | ||
expires?: string; | ||
maxAge?: number; | ||
domain?: string; | ||
path?: string; | ||
secure?: boolean; | ||
httpOnly?: boolean; | ||
} | ||
declare class Requestly { | ||
@@ -5,0 +15,0 @@ private _baseUrl?; |
@@ -1,1 +0,1 @@ | ||
import{Cookie as w,CookieJar as l}from"tough-cookie";import{splitCookiesString as x}from"set-cookie-parser";var m="Requestly/1.0";function y(s){if(!s)return"";let e=new URLSearchParams(s);return e.toString()?`?${e.toString()}`:""}function q(s){if(s instanceof FormData)return"multipart/form-data";if(s instanceof URLSearchParams)return"application/x-www-form-urlencoded";if(typeof s=="object"&&s!==null)return"application/json"}function b(s){return typeof s=="object"&&s!==null?JSON.stringify(s):s}async function T(s,e,t){let o=await(s.headers.get("Content-Type")?.includes("application/json")?s.json():s.text());return{...s,url:s.url,ok:s.ok,redirected:e.redirectCount>0,status:s.status,statusText:s.statusText,request:{url:e.url,method:e.method,options:e.options},cookies:{},headers:s.headers,data:o,retry:t}}var J=new Set([301,302,303,307,308]),R=class s{_baseUrl;_headers={};_params={};_cookieJar;_onRequest;_onResponse;_maxRedirects;constructor(e){if(typeof e=="string"){this._baseUrl=e,this._cookieJar=new l,this._maxRedirects=20;return}this._baseUrl=e?.baseUrl??"",this._headers=e?.headers??{},this._params=e?.params??{},this._cookieJar=new l,e?.cookies&&this.cookies.deserialize(e.cookies),this._headers["User-Agent"]=e?.userAgent??m,this._onRequest=e?.onRequest,this._maxRedirects=e?.maxRedirects??20}async _request(e,t,r,o=0){if(e.startsWith("/")&&this._baseUrl==null)throw new Error("Cannot make request with relative URL without a base URL");let d=y({...r?.params,...this._params}),i=`${this._baseUrl}${e}${d}`;i.endsWith("/")&&(i=i.slice(0,-1)),!i.startsWith("http://")&&!i.startsWith("https://")&&(i=`https://${i}`);let f=q(r?.body),C={...f?{"Content-Type":f}:{},...r?.headers},k=await this._cookieJar.getCookieString(i),a={method:t,headers:{...this.headers.getAll(),...C,...k?{Cookie:k}:{}},body:b(r?.body)},v=await this._onRequest?.(i,a);a={...a,...v,redirect:"manual"};let u=await fetch(i,a),h={},_=u.headers.get("Set-Cookie");if(_){let n=x(_);for(let g of n){let c=w.parse(g);c&&(h[c.key]=c.value,await this._cookieJar.setCookie(c,i,{ignoreError:!0}))}}let O=await this._cookieJar.getCookies(i);for(let n of O)h[n.key]=n.value;if(J.has(u.status)&&o<this._maxRedirects){let n=u.headers.get("Location");if(n){let g=new URL(n,i).pathname,c=u.status===303?"GET":t,S=u.status===303?void 0:r?.body;return this._request(g,c,{...r,body:S},o+1)}}let p=await T(u,{url:e,method:t,options:a,redirectCount:o},()=>this._request(e,t,r,o+1));if(this._onResponse){let n=await this._onResponse({url:i,init:a,response:p});if(n)return n.headers instanceof Headers?n:{...p,data:n.data}}return{...p,cookies:h}}cookies={serialize:()=>this._cookieJar.serializeSync()?.cookies??[],deserialize:e=>{this._cookieJar=l.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(d=>d.key===e)?.value??null;let r=await this._cookieJar.serialize();for(let o of r.cookies)if(o.key?.toLowerCase()===e.toLowerCase())return o.value??null;return null},getAll:async e=>this._cookieJar.getCookies(e),set:async(e,t)=>{let r=new w(t);this._cookieJar.setCookie(r,e)},clear:()=>{this._cookieJar=new l}};get baseUrl(){return this._baseUrl}set baseUrl(e){this._baseUrl=e}create(e){return new s(e)}get params(){return this._params}set params(e){this._params=e}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}}};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={set:e=>{this._onRequest=e},remove:()=>{this._onRequest=void 0}};onResponse={set:e=>{this._onResponse=e},remove:()=>{this._onResponse=void 0}};fetch(e,t){return this._request(e,t?.method||"GET",t)}},P=new R,E=P;export{R as Requestly,E as default,P as requestly}; | ||
var E=Object.create;var q=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var M=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var B=(t,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of D(e))!W.call(t,i)&&i!==s&&q(t,i,{get:()=>e[i],enumerable:!(r=$(e,i))||r.enumerable});return t};var V=(t,e,s)=>(s=t!=null?E(I(t)):{},B(e||!t||!t.__esModule?q(s,"default",{value:t,enumerable:!0}):s,t));var A=M((Y,R)=>{"use strict";var y={decodeValues:!0,map:!1,silent:!1};function x(t){return typeof t=="string"&&!!t.trim()}function w(t,e){var s=t.split(";").filter(x),r=s.shift(),i=H(r),u=i.name,a=i.value;e=e?Object.assign({},y,e):y;try{a=e.decodeValues?decodeURIComponent(a):a}catch(l){console.error("set-cookie-parser encountered an error while decoding a cookie with value '"+a+"'. Set options.decodeValues to false to disable this feature.",l)}var n={name:u,value:a};return s.forEach(function(l){var c=l.split("="),o=c.shift().trimLeft().toLowerCase(),p=c.join("=");o==="expires"?n.expires=new Date(p):o==="max-age"?n.maxAge=parseInt(p,10):o==="secure"?n.secure=!0:o==="httponly"?n.httpOnly=!0:o==="samesite"?n.sameSite=p:o==="partitioned"?n.partitioned=!0:n[o]=p}),n}function H(t){var e="",s="",r=t.split("=");return r.length>1?(e=r.shift(),s=r.join("=")):s=t,{name:e,value:s}}function O(t,e){if(e=e?Object.assign({},y,e):y,!t)return e.map?{}:[];if(t.headers)if(typeof t.headers.getSetCookie=="function")t=t.headers.getSetCookie();else if(t.headers["set-cookie"])t=t.headers["set-cookie"];else{var s=t.headers[Object.keys(t.headers).find(function(i){return i.toLowerCase()==="set-cookie"})];!s&&t.headers.cookie&&!e.silent&&console.warn("Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."),t=s}if(Array.isArray(t)||(t=[t]),e=e?Object.assign({},y,e):y,e.map){var r={};return t.filter(x).reduce(function(i,u){var a=w(u,e);return i[a.name]=a,i},r)}else return t.filter(x).map(function(i){return w(i,e)})}function N(t){if(Array.isArray(t))return t;if(typeof t!="string")return[];var e=[],s=0,r,i,u,a,n;function l(){for(;s<t.length&&/\s/.test(t.charAt(s));)s+=1;return s<t.length}function c(){return i=t.charAt(s),i!=="="&&i!==";"&&i!==","}for(;s<t.length;){for(r=s,n=!1;l();)if(i=t.charAt(s),i===","){for(u=s,s+=1,l(),a=s;s<t.length&&c();)s+=1;s<t.length&&t.charAt(s)==="="?(n=!0,s=a,e.push(t.substring(r,u)),r=s):s=u+1}else s+=1;(!n||s>=t.length)&&e.push(t.substring(r,t.length))}return e}R.exports=O;R.exports.parse=O;R.exports.parseString=w;R.exports.splitCookiesString=N});var g=class t{key;value;expires;maxAge;domain;path;secure;httpOnly;constructor(e){this.key=e.key,this.value=e.value,this.expires=e.expires,this.maxAge=e.maxAge,this.domain=e.domain,this.path=e.path,this.secure=e.secure||!1,this.httpOnly=e.httpOnly||!1}static parse(e){let s=e.split(";").map(l=>l.trim()),[r,...i]=s,[u,a]=r.split("=").map(l=>l.trim());if(!u||!a)return null;let n={key:u,value:a};return i.forEach(l=>{let[c,o]=l.split("=").map(p=>p.trim());switch(c.toLowerCase()){case"expires":n.expires=new Date(o);break;case"max-age":n.maxAge=parseInt(o,10);break;case"domain":n.domain=o;break;case"path":n.path=o;break;case"secure":n.secure=!0;break;case"httponly":n.httpOnly=!0;break}}),new t(n)}toString(){let e=`${this.key}=${this.value}`;return this.expires&&(e+=`; Expires=${this.expires.toUTCString()}`),this.maxAge!==void 0&&(e+=`; Max-Age=${this.maxAge}`),this.domain&&(e+=`; Domain=${this.domain}`),this.path&&(e+=`; Path=${this.path}`),this.secure&&(e+="; Secure"),this.httpOnly&&(e+="; HttpOnly"),e}},d=class t{cookies=[];async setCookie(e,s,r={}){let i=new URL(s).hostname;if(e.domain&&!i.endsWith(e.domain)){if(!r.ignoreError)throw new Error("Cookie domain does not match URL");return}this.cookies=this.cookies.filter(u=>u.key!==e.key||u.domain!==e.domain),this.cookies.push(e)}async getCookies(e){let s=new URL(e).hostname,r=new URL(e).pathname;return this.cookies.filter(i=>(!i.domain||s.endsWith(i.domain))&&(!i.path||r.startsWith(i.path)))}async getCookieString(e){return(await this.getCookies(e)).map(r=>`${r.key}=${r.value}`).join("; ")}serializeSync(){return{cookies:this.cookies.map(e=>({key:e.key,value:e.value,expires:e.expires?.toISOString(),maxAge:e.maxAge,domain:e.domain,path:e.path,secure:e.secure,httpOnly:e.httpOnly}))}}static deserializeSync(e){let s=new t;return s.cookies=e.cookies.map(r=>new g({key:r.key,value:r.value,expires:r.expires?new Date(r.expires):void 0,maxAge:typeof r.maxAge=="number"?r.maxAge:void 0,domain:r.domain,path:r.path,secure:typeof r.secure=="boolean"?r.secure:void 0,httpOnly:typeof r.httpOnly=="boolean"?r.httpOnly:void 0})),s}};var L=V(A(),1);var T="Requestly/1.0";function U(t){if(!t)return"";let e=new URLSearchParams(t);return e.toString()?`?${e.toString()}`:""}function P(t){if(t instanceof FormData)return"multipart/form-data";if(t instanceof URLSearchParams)return"application/x-www-form-urlencoded";if(typeof t=="object"&&t!==null)return"application/json"}function S(t){return typeof t=="object"&&t!==null?JSON.stringify(t):t}async function J(t,e,s){let i=await(t.headers.get("Content-Type")?.includes("application/json")?t.json():t.text());return{...t,url:t.url,ok:t.ok,redirected:e.redirectCount>0,status:t.status,statusText:t.statusText,request:{url:e.url,method:e.method,options:e.options},cookies:{},headers:t.headers,data:i,retry:s}}var G=new Set([301,302,303,307,308]),_=class t{_baseUrl;_headers={};_params={};_cookieJar;_onRequest;_onResponse;_maxRedirects;constructor(e){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??T,this._onRequest=e?.onRequest,this._maxRedirects=e?.maxRedirects??20}async _request(e,s,r,i=0){if(e.startsWith("/")&&this._baseUrl==null)throw new Error("Cannot make request with relative URL without a base URL");let u=U({...r?.params,...this._params}),a=`${this._baseUrl}${e}${u}`;a.endsWith("/")&&(a=a.slice(0,-1)),!a.startsWith("http://")&&!a.startsWith("https://")&&(a=`https://${a}`);let n=P(r?.body),l={...n?{"Content-Type":n}:{},...r?.headers},c=await this._cookieJar.getCookieString(a),o={method:s,headers:{...this.headers.getAll(),...l,...c?{Cookie:c}:{}},body:S(r?.body)},p=await this._onRequest?.(a,o);o={...o,...p,redirect:"manual"};let f=await fetch(a,o),b={},C=f.headers.get("Set-Cookie");if(C){let h=(0,L.splitCookiesString)(C);for(let v of h){let m=g.parse(v);m&&(b[m.key]=m.value,await this._cookieJar.setCookie(m,a,{ignoreError:!0}))}}let j=await this._cookieJar.getCookies(a);for(let h of j)b[h.key]=h.value;if(G.has(f.status)&&i<this._maxRedirects){let h=f.headers.get("Location");if(h){let v=new URL(h,a).pathname,m=f.status===303?"GET":s,z=f.status===303?void 0:r?.body;return this._request(v,m,{...r,body:z},i+1)}}let k=await J(f,{url:e,method:s,options:o,redirectCount:i},()=>this._request(e,s,r,i+1));if(this._onResponse){let h=await this._onResponse({url:a,init:o,response:k});if(h)return h.headers instanceof Headers?h:{...k,data:h.data}}return{...k,cookies:b}}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,s)=>{if(s)return(await this._cookieJar.getCookies(s)).find(u=>u.key===e)?.value??null;let r=this._cookieJar.serializeSync();for(let i of r.cookies)if(i.key?.toLowerCase()===e.toLowerCase())return i.value??null;return null},getAll:async e=>this._cookieJar.getCookies(e),set:async(e,s)=>{let r=new g(s);this._cookieJar.setCookie(r,e)},clear:()=>{this._cookieJar=new d}};get baseUrl(){return this._baseUrl}set baseUrl(e){this._baseUrl=e}create(e){return new t(e)}get params(){return this._params}set params(e){this._params=e}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}}};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={set:e=>{this._onRequest=e},remove:()=>{this._onRequest=void 0}};onResponse={set:e=>{this._onResponse=e},remove:()=>{this._onResponse=void 0}};fetch(e,s){return this._request(e,s?.method||"GET",s)}},K=new _,te=K;export{_ as Requestly,te as default,K as requestly}; |
{ | ||
"name": "requestly", | ||
"version": "2.0.1", | ||
"version": "2.0.3", | ||
"description": "A minimal, but powerful HTTP Client for Node.js", | ||
@@ -33,6 +33,7 @@ "publishConfig": { | ||
}, | ||
"dependencies": { | ||
"hono": "^4.6.3" | ||
}, | ||
"devDependencies": { | ||
"@types/bun": "^1.1.10", | ||
"@types/set-cookie-parser": "^2.4.10", | ||
"@types/tough-cookie": "^4.0.5", | ||
"tsup": "8.0.1", | ||
@@ -58,8 +59,3 @@ "typescript": "5.3.3" | ||
"http" | ||
], | ||
"dependencies": { | ||
"hono": "^4.6.3", | ||
"set-cookie-parser": "^2.7.0", | ||
"tough-cookie": "^5.0.0" | ||
} | ||
] | ||
} |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
31588
1
3
169
0
- Removedset-cookie-parser@^2.7.0
- Removedtough-cookie@^5.0.0
- Removedset-cookie-parser@2.7.1(transitive)
- Removedtldts@6.1.64(transitive)
- Removedtldts-core@6.1.64(transitive)
- Removedtough-cookie@5.0.0(transitive)