Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openapi-fetch

Package Overview
Dependencies
Maintainers
0
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-fetch - npm Package Compare versions

Comparing version 0.10.1 to 0.10.2

6

CHANGELOG.md
# openapi-fetch
## 0.10.2
### Patch Changes
- [#1696](https://github.com/openapi-ts/openapi-typescript/pull/1696) [`aea31a8`](https://github.com/openapi-ts/openapi-typescript/commit/aea31a8679b901745a98f856fea9d53dff6807b3) Thanks [@swachter](https://github.com/swachter)! - Fix: encode primitive path parameters
## 0.10.1

@@ -4,0 +10,0 @@

2

dist/index.js

@@ -427,3 +427,3 @@ // settings & const

}
nextURL = nextURL.replace(match, style === "label" ? `.${value}` : value);
nextURL = nextURL.replace(match, style === "label" ? `.${encodeURIComponent(value)}` : encodeURIComponent(value));
}

@@ -430,0 +430,0 @@ return nextURL;

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

var H={"Content-Type":"application/json"},I=/\{[^{}]+\}/g,E=class extends Request{constructor(t,e){super(t,e);for(let r in e)r in this||(this[r]=e[r])}};function P(){return Math.random().toString(36).slice(2,11)}function L(s){let{baseUrl:t="",fetch:e=globalThis.fetch,querySerializer:r,bodySerializer:n,headers:o,...a}={...s};t.endsWith("/")&&(t=t.substring(0,t.length-1)),o=O(H,o);let l=[];async function u(f,i){let{fetch:p=e,headers:C,params:b={},parseAs:j="json",querySerializer:m,bodySerializer:T=n??F,...D}=i||{},x=typeof r=="function"?r:z(r);m&&(x=typeof m=="function"?m:z({...typeof r=="object"?r:{},...m}));let h={redirect:"follow",...a,...D,headers:O(o,C,b.header)};h.body&&(h.body=T(h.body)),h.body instanceof FormData&&h.headers.delete("Content-Type");let g,$,w=new E(N(f,{baseUrl:t,params:b,querySerializer:x}),h);if(l.length){g=P(),$=Object.freeze({baseUrl:t,fetch:p,parseAs:j,querySerializer:x,bodySerializer:T});for(let d of l)if(d&&typeof d=="object"&&typeof d.onRequest=="function"){let y=await d.onRequest({request:w,schemaPath:f,params:b,options:$,id:g});if(y){if(!(y instanceof Request))throw new Error("onRequest: must return new Request() when modifying the request");w=y}}}let c=await p(w);if(l.length)for(let d=l.length-1;d>=0;d--){let y=l[d];if(y&&typeof y=="object"&&typeof y.onResponse=="function"){let A=await y.onResponse({request:w,response:c,schemaPath:f,params:b,options:$,id:g});if(A){if(!(A instanceof Response))throw new Error("onResponse: must return new Response() when modifying the response");c=A}}}if(c.status===204||c.headers.get("Content-Length")==="0")return c.ok?{data:{},response:c}:{error:{},response:c};if(c.ok)return j==="stream"?{data:c.body,response:c}:{data:await c[j](),response:c};let S=await c.text();try{S=JSON.parse(S)}catch{}return{error:S,response:c}}return{async GET(f,i){return u(f,{...i,method:"GET"})},async PUT(f,i){return u(f,{...i,method:"PUT"})},async POST(f,i){return u(f,{...i,method:"POST"})},async DELETE(f,i){return u(f,{...i,method:"DELETE"})},async OPTIONS(f,i){return u(f,{...i,method:"OPTIONS"})},async HEAD(f,i){return u(f,{...i,method:"HEAD"})},async PATCH(f,i){return u(f,{...i,method:"PATCH"})},async TRACE(f,i){return u(f,{...i,method:"TRACE"})},use(...f){for(let i of f)if(i){if(typeof i!="object"||!("onRequest"in i||"onResponse"in i))throw new Error("Middleware must be an object with one of `onRequest()` or `onResponse()`");l.push(i)}},eject(...f){for(let i of f){let p=l.indexOf(i);p!==-1&&l.splice(p,1)}}}}function R(s,t,e){if(t==null)return"";if(typeof t=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return`${s}=${e?.allowReserved===!0?t:encodeURIComponent(t)}`}function q(s,t,e){if(!t||typeof t!="object")return"";let r=[],n={simple:",",label:".",matrix:";"}[e.style]||"&";if(e.style!=="deepObject"&&e.explode===!1){for(let l in t)r.push(l,e.allowReserved===!0?t[l]:encodeURIComponent(t[l]));let a=r.join(",");switch(e.style){case"form":return`${s}=${a}`;case"label":return`.${a}`;case"matrix":return`;${s}=${a}`;default:return a}}for(let a in t){let l=e.style==="deepObject"?`${s}[${a}]`:a;r.push(R(l,t[a],e))}let o=r.join(n);return e.style==="label"||e.style==="matrix"?`${n}${o}`:o}function U(s,t,e){if(!Array.isArray(t))return"";if(e.explode===!1){let o={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[e.style]||",",a=(e.allowReserved===!0?t:t.map(l=>encodeURIComponent(l))).join(o);switch(e.style){case"simple":return a;case"label":return`.${a}`;case"matrix":return`;${s}=${a}`;default:return`${s}=${a}`}}let r={simple:",",label:".",matrix:";"}[e.style]||"&",n=[];for(let o of t)e.style==="simple"||e.style==="label"?n.push(e.allowReserved===!0?o:encodeURIComponent(o)):n.push(R(s,o,e));return e.style==="label"||e.style==="matrix"?`${r}${n.join(r)}`:n.join(r)}function z(s){return function(e){let r=[];if(e&&typeof e=="object")for(let n in e){let o=e[n];if(o!=null){if(Array.isArray(o)){r.push(U(n,o,{style:"form",explode:!0,...s?.array,allowReserved:s?.allowReserved||!1}));continue}if(typeof o=="object"){r.push(q(n,o,{style:"deepObject",explode:!0,...s?.object,allowReserved:s?.allowReserved||!1}));continue}r.push(R(n,o,s))}}return r.join("&")}}function k(s,t){let e=s;for(let r of s.match(I)??[]){let n=r.substring(1,r.length-1),o=!1,a="simple";if(n.endsWith("*")&&(o=!0,n=n.substring(0,n.length-1)),n.startsWith(".")?(a="label",n=n.substring(1)):n.startsWith(";")&&(a="matrix",n=n.substring(1)),!t||t[n]===void 0||t[n]===null)continue;let l=t[n];if(Array.isArray(l)){e=e.replace(r,U(n,l,{style:a,explode:o}));continue}if(typeof l=="object"){e=e.replace(r,q(n,l,{style:a,explode:o}));continue}if(a==="matrix"){e=e.replace(r,`;${R(n,l)}`);continue}e=e.replace(r,a==="label"?`.${l}`:l)}return e}function F(s){return JSON.stringify(s)}function N(s,t){let e=`${t.baseUrl}${s}`;t.params?.path&&(e=k(e,t.params.path));let r=t.querySerializer(t.params.query??{});return r.startsWith("?")&&(r=r.substring(1)),r&&(e+=`?${r}`),e}function O(...s){let t=new Headers;for(let e of s){if(!e||typeof e!="object")continue;let r=e instanceof Headers?e.entries():Object.entries(e);for(let[n,o]of r)if(o===null)t.delete(n);else if(Array.isArray(o))for(let a of o)t.append(n,a);else o!==void 0&&t.set(n,o)}return t}export{N as createFinalURL,z as createQuerySerializer,L as default,F as defaultBodySerializer,k as defaultPathSerializer,O as mergeHeaders,P as randomID,U as serializeArrayParam,q as serializeObjectParam,R as serializePrimitiveParam};
var H={"Content-Type":"application/json"},I=/\{[^{}]+\}/g,E=class extends Request{constructor(t,e){super(t,e);for(let r in e)r in this||(this[r]=e[r])}};function P(){return Math.random().toString(36).slice(2,11)}function L(s){let{baseUrl:t="",fetch:e=globalThis.fetch,querySerializer:r,bodySerializer:n,headers:o,...a}={...s};t.endsWith("/")&&(t=t.substring(0,t.length-1)),o=O(H,o);let l=[];async function u(c,i){let{fetch:h=e,headers:C,params:b={},parseAs:j="json",querySerializer:m,bodySerializer:T=n??F,...D}=i||{},x=typeof r=="function"?r:z(r);m&&(x=typeof m=="function"?m:z({...typeof r=="object"?r:{},...m}));let p={redirect:"follow",...a,...D,headers:O(o,C,b.header)};p.body&&(p.body=T(p.body)),p.body instanceof FormData&&p.headers.delete("Content-Type");let g,$,R=new E(N(c,{baseUrl:t,params:b,querySerializer:x}),p);if(l.length){g=P(),$=Object.freeze({baseUrl:t,fetch:h,parseAs:j,querySerializer:x,bodySerializer:T});for(let d of l)if(d&&typeof d=="object"&&typeof d.onRequest=="function"){let y=await d.onRequest({request:R,schemaPath:c,params:b,options:$,id:g});if(y){if(!(y instanceof Request))throw new Error("onRequest: must return new Request() when modifying the request");R=y}}}let f=await h(R);if(l.length)for(let d=l.length-1;d>=0;d--){let y=l[d];if(y&&typeof y=="object"&&typeof y.onResponse=="function"){let A=await y.onResponse({request:R,response:f,schemaPath:c,params:b,options:$,id:g});if(A){if(!(A instanceof Response))throw new Error("onResponse: must return new Response() when modifying the response");f=A}}}if(f.status===204||f.headers.get("Content-Length")==="0")return f.ok?{data:{},response:f}:{error:{},response:f};if(f.ok)return j==="stream"?{data:f.body,response:f}:{data:await f[j](),response:f};let S=await f.text();try{S=JSON.parse(S)}catch{}return{error:S,response:f}}return{async GET(c,i){return u(c,{...i,method:"GET"})},async PUT(c,i){return u(c,{...i,method:"PUT"})},async POST(c,i){return u(c,{...i,method:"POST"})},async DELETE(c,i){return u(c,{...i,method:"DELETE"})},async OPTIONS(c,i){return u(c,{...i,method:"OPTIONS"})},async HEAD(c,i){return u(c,{...i,method:"HEAD"})},async PATCH(c,i){return u(c,{...i,method:"PATCH"})},async TRACE(c,i){return u(c,{...i,method:"TRACE"})},use(...c){for(let i of c)if(i){if(typeof i!="object"||!("onRequest"in i||"onResponse"in i))throw new Error("Middleware must be an object with one of `onRequest()` or `onResponse()`");l.push(i)}},eject(...c){for(let i of c){let h=l.indexOf(i);h!==-1&&l.splice(h,1)}}}}function w(s,t,e){if(t==null)return"";if(typeof t=="object")throw new Error("Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these.");return`${s}=${e?.allowReserved===!0?t:encodeURIComponent(t)}`}function q(s,t,e){if(!t||typeof t!="object")return"";let r=[],n={simple:",",label:".",matrix:";"}[e.style]||"&";if(e.style!=="deepObject"&&e.explode===!1){for(let l in t)r.push(l,e.allowReserved===!0?t[l]:encodeURIComponent(t[l]));let a=r.join(",");switch(e.style){case"form":return`${s}=${a}`;case"label":return`.${a}`;case"matrix":return`;${s}=${a}`;default:return a}}for(let a in t){let l=e.style==="deepObject"?`${s}[${a}]`:a;r.push(w(l,t[a],e))}let o=r.join(n);return e.style==="label"||e.style==="matrix"?`${n}${o}`:o}function U(s,t,e){if(!Array.isArray(t))return"";if(e.explode===!1){let o={form:",",spaceDelimited:"%20",pipeDelimited:"|"}[e.style]||",",a=(e.allowReserved===!0?t:t.map(l=>encodeURIComponent(l))).join(o);switch(e.style){case"simple":return a;case"label":return`.${a}`;case"matrix":return`;${s}=${a}`;default:return`${s}=${a}`}}let r={simple:",",label:".",matrix:";"}[e.style]||"&",n=[];for(let o of t)e.style==="simple"||e.style==="label"?n.push(e.allowReserved===!0?o:encodeURIComponent(o)):n.push(w(s,o,e));return e.style==="label"||e.style==="matrix"?`${r}${n.join(r)}`:n.join(r)}function z(s){return function(e){let r=[];if(e&&typeof e=="object")for(let n in e){let o=e[n];if(o!=null){if(Array.isArray(o)){r.push(U(n,o,{style:"form",explode:!0,...s?.array,allowReserved:s?.allowReserved||!1}));continue}if(typeof o=="object"){r.push(q(n,o,{style:"deepObject",explode:!0,...s?.object,allowReserved:s?.allowReserved||!1}));continue}r.push(w(n,o,s))}}return r.join("&")}}function k(s,t){let e=s;for(let r of s.match(I)??[]){let n=r.substring(1,r.length-1),o=!1,a="simple";if(n.endsWith("*")&&(o=!0,n=n.substring(0,n.length-1)),n.startsWith(".")?(a="label",n=n.substring(1)):n.startsWith(";")&&(a="matrix",n=n.substring(1)),!t||t[n]===void 0||t[n]===null)continue;let l=t[n];if(Array.isArray(l)){e=e.replace(r,U(n,l,{style:a,explode:o}));continue}if(typeof l=="object"){e=e.replace(r,q(n,l,{style:a,explode:o}));continue}if(a==="matrix"){e=e.replace(r,`;${w(n,l)}`);continue}e=e.replace(r,a==="label"?`.${encodeURIComponent(l)}`:encodeURIComponent(l))}return e}function F(s){return JSON.stringify(s)}function N(s,t){let e=`${t.baseUrl}${s}`;t.params?.path&&(e=k(e,t.params.path));let r=t.querySerializer(t.params.query??{});return r.startsWith("?")&&(r=r.substring(1)),r&&(e+=`?${r}`),e}function O(...s){let t=new Headers;for(let e of s){if(!e||typeof e!="object")continue;let r=e instanceof Headers?e.entries():Object.entries(e);for(let[n,o]of r)if(o===null)t.delete(n);else if(Array.isArray(o))for(let a of o)t.append(n,a);else o!==void 0&&t.set(n,o)}return t}export{N as createFinalURL,z as createQuerySerializer,L as default,F as defaultBodySerializer,k as defaultPathSerializer,O as mergeHeaders,P as randomID,U as serializeArrayParam,q as serializeObjectParam,w as serializePrimitiveParam};
{
"name": "openapi-fetch",
"description": "Fast, type-safe fetch client for your OpenAPI schema. Only 5 kb (min). Works with React, Vue, Svelte, or vanilla JS.",
"version": "0.10.1",
"version": "0.10.2",
"author": {

@@ -6,0 +6,0 @@ "name": "Drew Powers",

@@ -427,3 +427,3 @@ // settings & const

}
nextURL = nextURL.replace(match, style === "label" ? `.${value}` : value);
nextURL = nextURL.replace(match, style === "label" ? `.${encodeURIComponent(value)}` : encodeURIComponent(value));
}

@@ -430,0 +430,0 @@ return nextURL;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc