🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →

simple-typed-fetch

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-typed-fetch - npm Package Compare versions

Comparing version

to
0.2.16

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

"use strict";var stf=(()=>{var $=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var V=(t,r)=>{for(var e in r)$(t,e,{get:r[e],enumerable:!0})},H=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of z(r))!C.call(t,s)&&s!==e&&$(t,s,{get:()=>r[s],enumerable:!(n=j(r,s))||n.enumerable});return t};var J=t=>H($({},"__esModule",{value:!0}),t);var B={};V(B,{fetchWithValidation:()=>b,simpleFetch:()=>U});var N={withStackTrace:!1},R=(t,r,e=N)=>{let n=r.isOk()?{type:"Ok",value:r.value}:{type:"Err",value:r.error},s=e.withStackTrace?new Error().stack:void 0;return{data:n,message:t,stack:s}};function P(t,r,e,n){function s(a){return a instanceof e?a:new e(function(i){i(a)})}return new(e||(e=Promise))(function(a,i){function o(f){try{w(n.next(f))}catch(l){i(l)}}function p(f){try{w(n.throw(f))}catch(l){i(l)}}function w(f){f.done?a(f.value):s(f.value).then(o,p)}w((n=n.apply(t,[])).next())})}function D(t){var r=typeof Symbol=="function"&&Symbol.iterator,e=r&&t[r],n=0;if(e)return e.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function T(t){return this instanceof T?(this.v=t,this):new T(t)}function F(t,r,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=e.apply(t,r||[]),s,a=[];return s={},i("next"),i("throw"),i("return"),s[Symbol.asyncIterator]=function(){return this},s;function i(h){n[h]&&(s[h]=function(d){return new Promise(function(O,g){a.push([h,d,O,g])>1||o(h,d)})})}function o(h,d){try{p(n[h](d))}catch(O){l(a[0][3],O)}}function p(h){h.value instanceof T?Promise.resolve(h.value.v).then(w,f):l(a[0][2],h)}function w(h){o("next",h)}function f(h){o("throw",h)}function l(h,d){h(d),a.shift(),a.length&&o(a[0][0],a[0][1])}}function q(t){var r,e;return r={},n("next"),n("throw",function(s){throw s}),n("return"),r[Symbol.iterator]=function(){return this},r;function n(s,a){r[s]=t[s]?function(i){return(e=!e)?{value:T(t[s](i)),done:s==="return"}:a?a(i):i}:a}}function M(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=t[Symbol.asyncIterator],e;return r?r.call(t):(t=typeof D=="function"?D(t):t[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(a){e[a]=t[a]&&function(i){return new Promise(function(o,p){i=t[a](i),s(o,p,i.done,i.value)})}}function s(a,i,o,p){Promise.resolve(p).then(function(w){a({value:w,done:o})},i)}}var v=class t{constructor(r){this._promise=r}static fromSafePromise(r){let e=r.then(n=>new y(n));return new t(e)}static fromPromise(r,e){let n=r.then(s=>new y(s)).catch(s=>new m(e(s)));return new t(n)}static fromThrowable(r,e){return(...n)=>new t(P(this,void 0,void 0,function*(){try{return new y(yield r(...n))}catch(s){return new m(e?e(s):s)}}))}static combine(r){return Z(r)}static combineWithAllErrors(r){return G(r)}map(r){return new t(this._promise.then(e=>P(this,void 0,void 0,function*(){return e.isErr()?new m(e.error):new y(yield r(e.value))})))}andThrough(r){return new t(this._promise.then(e=>P(this,void 0,void 0,function*(){if(e.isErr())return new m(e.error);let n=yield r(e.value);return n.isErr()?new m(n.error):new y(e.value)})))}andTee(r){return new t(this._promise.then(e=>P(this,void 0,void 0,function*(){if(e.isErr())return new m(e.error);try{yield r(e.value)}catch{}return new y(e.value)})))}mapErr(r){return new t(this._promise.then(e=>P(this,void 0,void 0,function*(){return e.isOk()?new y(e.value):new m(yield r(e.error))})))}andThen(r){return new t(this._promise.then(e=>{if(e.isErr())return new m(e.error);let n=r(e.value);return n instanceof t?n._promise:n}))}orElse(r){return new t(this._promise.then(e=>P(this,void 0,void 0,function*(){return e.isErr()?r(e.error):new y(e.value)})))}match(r,e){return this._promise.then(n=>n.match(r,e))}unwrapOr(r){return this._promise.then(e=>e.unwrapOr(r))}safeUnwrap(){return F(this,arguments,function*(){return yield T(yield T(yield*q(M(yield T(this._promise.then(e=>e.safeUnwrap()))))))})}then(r,e){return this._promise.then(r,e)}};var S=t=>new v(Promise.resolve(new m(t))),I=v.fromPromise,Q=v.fromSafePromise,X=v.fromThrowable,A=t=>{let r=E([]);for(let e of t)if(e.isErr()){r=c(e.error);break}else r.map(n=>n.push(e.value));return r},Z=t=>v.fromSafePromise(Promise.all(t)).andThen(A),L=t=>{let r=E([]);for(let e of t)e.isErr()&&r.isErr()?r.error.push(e.error):e.isErr()&&r.isOk()?r=c([e.error]):e.isOk()&&r.isOk()&&r.value.push(e.value);return r},G=t=>v.fromSafePromise(Promise.all(t)).andThen(L),k;(function(t){function r(s,a){return(...i)=>{try{let o=s(...i);return E(o)}catch(o){return c(a?a(o):o)}}}t.fromThrowable=r;function e(s){return A(s)}t.combine=e;function n(s){return L(s)}t.combineWithAllErrors=n})(k||(k={}));var E=t=>new y(t);function c(t){return new m(t)}var y=class{constructor(r){this.value=r}isOk(){return!0}isErr(){return!this.isOk()}map(r){return E(r(this.value))}mapErr(r){return E(this.value)}andThen(r){return r(this.value)}andThrough(r){return r(this.value).map(e=>this.value)}andTee(r){try{r(this.value)}catch{}return E(this.value)}orElse(r){return E(this.value)}asyncAndThen(r){return r(this.value)}asyncAndThrough(r){return r(this.value).map(()=>this.value)}asyncMap(r){return v.fromSafePromise(r(this.value))}unwrapOr(r){return this.value}match(r,e){return r(this.value)}safeUnwrap(){let r=this.value;return function*(){return r}()}_unsafeUnwrap(r){return this.value}_unsafeUnwrapErr(r){throw R("Called `_unsafeUnwrapErr` on an Ok",this,r)}},m=class{constructor(r){this.error=r}isOk(){return!1}isErr(){return!this.isOk()}map(r){return c(this.error)}mapErr(r){return c(r(this.error))}andThrough(r){return c(this.error)}andTee(r){return c(this.error)}andThen(r){return c(this.error)}orElse(r){return r(this.error)}asyncAndThen(r){return S(this.error)}asyncAndThrough(r){return S(this.error)}asyncMap(r){return S(this.error)}unwrapOr(r){return r}match(r,e){return e(this.error)}safeUnwrap(){let r=this.error;return function*(){throw yield c(r),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(r){throw R("Called `_unsafeUnwrap` on an Err",this,r)}_unsafeUnwrapErr(r){return this.error}},W=k.fromThrowable;async function b(t,r,e,n){let s={...e,headers:e?.headers??{}},a={requestOptions:s,url:t},i=await I(fetch(t,s),u=>u instanceof Error?c({type:"fetchError",...a,message:`Fetch error: ${u.message}. URL: ${t}`,error:u}):c({type:"unknownFetchThrow",...a,message:`Unknown fetch error. URL: ${t}`,error:u}));if(i.isErr())return i.error;let o=i.value,p={...a,response:o},w=await I(o.text(),u=>u instanceof Error?c({type:"unknownGetTextError",...p,message:`Can't get response content: ${u.message}. URL: ${t}. HTTP ${o.status}`,error:u}):c({type:"unknownGetTextUnknownError",...p,message:`Can't get response content: Unknown error. URL: ${t}. HTTP ${o.status}`,error:u}));if(w.isErr())return w.error;let f=w.value,l={...p,text:f},d=W(JSON.parse,u=>u instanceof Error?c({type:"jsonParseError",...l,message:`Can't parse response as JSON: ${u.message}. URL: ${t}. HTTP ${o.status}. Original response: ${f}`,error:u}):c({type:"jsonParseUnknownError",...l,message:`Unknown JSON parse error. URL: ${t}. HTTP ${o.status}. Original response: ${f}`,error:u}))(f);if(d.isErr()){let u=r.safeParse(f);return u.success?E({...l,data:u.data}):c({type:"jsonParseError",...l,message:`Can't parse response as JSON: ${d.error.error.message}. URL: ${t}. HTTP ${o.status}. Original response: ${f}`,error:d.error.error})}let O=d.value,g;if(n){let u=n.safeParse(O);u.success&&(g=u.data)}if(o.status>=500)return c({type:"serverError",...l,message:`Server error: ${o.status} ${o.statusText}. ${g?`Data: ${JSON.stringify(g)}`:""}`});if(o.status>=400)return c({type:"clientError",...l,message:`Error: ${o.status} ${o.statusText}. URL: ${t}. HTTP ${o.status}. Original response: ${f}`,errorMetadata:g});let _=r.safeParse(O);if(!_.success){let u=_.error.issues.map(x=>`[${x.path.join(".")}] ${x.message}`).join(", ");return c({type:"payloadParseError",...l,message:`Can't recognize response payload: ${u}. URL: ${t}. HTTP ${o.status}. Original response: ${f}`})}return E({...l,data:_.data})}function U(t){return async(...r)=>{let e=await t(...r);if(e.isErr()){let{message:n,url:s}=e.error;throw new Error(`${n} (${s})`)}return e.value.data}}return J(B);})();
"use strict";var stf=(()=>{var $=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var V=(t,r)=>{for(var e in r)$(t,e,{get:r[e],enumerable:!0})},J=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of C(r))!H.call(t,s)&&s!==e&&$(t,s,{get:()=>r[s],enumerable:!(n=z(r,s))||n.enumerable});return t};var N=t=>J($({},"__esModule",{value:!0}),t);var B={};V(B,{fetchWithValidation:()=>S,simpleFetch:()=>U});var F={withStackTrace:!1},A=(t,r,e=F)=>{let n=r.isOk()?{type:"Ok",value:r.value}:{type:"Err",value:r.error},s=e.withStackTrace?new Error().stack:void 0;return{data:n,message:t,stack:s}};function b(t,r,e,n){function s(o){return o instanceof e?o:new e(function(c){c(o)})}return new(e||(e=Promise))(function(o,c){function a(h){try{y(n.next(h))}catch(l){c(l)}}function m(h){try{y(n.throw(h))}catch(l){c(l)}}function y(h){h.done?o(h.value):s(h.value).then(a,m)}y((n=n.apply(t,r||[])).next())})}function R(t){var r=typeof Symbol=="function"&&Symbol.iterator,e=r&&t[r],n=0;if(e)return e.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function E(t){return this instanceof E?(this.v=t,this):new E(t)}function D(t,r,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=e.apply(t,r||[]),s,o=[];return s=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",c),s[Symbol.asyncIterator]=function(){return this},s;function c(i){return function(w){return Promise.resolve(w).then(i,l)}}function a(i,w){n[i]&&(s[i]=function(T){return new Promise(function(P,u){o.push([i,T,P,u])>1||m(i,T)})},w&&(s[i]=w(s[i])))}function m(i,w){try{y(n[i](w))}catch(T){_(o[0][3],T)}}function y(i){i.value instanceof E?Promise.resolve(i.value.v).then(h,l):_(o[0][2],i)}function h(i){m("next",i)}function l(i){m("throw",i)}function _(i,w){i(w),o.shift(),o.length&&m(o[0][0],o[0][1])}}function q(t){var r,e;return r={},n("next"),n("throw",function(s){throw s}),n("return"),r[Symbol.iterator]=function(){return this},r;function n(s,o){r[s]=t[s]?function(c){return(e=!e)?{value:E(t[s](c)),done:!1}:o?o(c):c}:o}}function M(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=t[Symbol.asyncIterator],e;return r?r.call(t):(t=typeof R=="function"?R(t):t[Symbol.iterator](),e={},n("next"),n("throw"),n("return"),e[Symbol.asyncIterator]=function(){return this},e);function n(o){e[o]=t[o]&&function(c){return new Promise(function(a,m){c=t[o](c),s(a,m,c.done,c.value)})}}function s(o,c,a,m){Promise.resolve(m).then(function(y){o({value:y,done:a})},c)}}var O=class t{constructor(r){this._promise=r}static fromSafePromise(r){let e=r.then(n=>new d(n));return new t(e)}static fromPromise(r,e){let n=r.then(s=>new d(s)).catch(s=>new p(e(s)));return new t(n)}static fromThrowable(r,e){return(...n)=>new t(b(this,void 0,void 0,function*(){try{return new d(yield r(...n))}catch(s){return new p(e?e(s):s)}}))}static combine(r){return Z(r)}static combineWithAllErrors(r){return G(r)}map(r){return new t(this._promise.then(e=>b(this,void 0,void 0,function*(){return e.isErr()?new p(e.error):new d(yield r(e.value))})))}andThrough(r){return new t(this._promise.then(e=>b(this,void 0,void 0,function*(){if(e.isErr())return new p(e.error);let n=yield r(e.value);return n.isErr()?new p(n.error):new d(e.value)})))}andTee(r){return new t(this._promise.then(e=>b(this,void 0,void 0,function*(){if(e.isErr())return new p(e.error);try{yield r(e.value)}catch{}return new d(e.value)})))}mapErr(r){return new t(this._promise.then(e=>b(this,void 0,void 0,function*(){return e.isOk()?new d(e.value):new p(yield r(e.error))})))}andThen(r){return new t(this._promise.then(e=>{if(e.isErr())return new p(e.error);let n=r(e.value);return n instanceof t?n._promise:n}))}orElse(r){return new t(this._promise.then(e=>b(this,void 0,void 0,function*(){return e.isErr()?r(e.error):new d(e.value)})))}match(r,e){return this._promise.then(n=>n.match(r,e))}unwrapOr(r){return this._promise.then(e=>e.unwrapOr(r))}safeUnwrap(){return D(this,arguments,function*(){return yield E(yield E(yield*q(M(yield E(this._promise.then(e=>e.safeUnwrap()))))))})}then(r,e){return this._promise.then(r,e)}[Symbol.asyncIterator](){return D(this,arguments,function*(){let e=yield E(this._promise);return e.isErr()&&(yield yield E(g(e.error))),yield E(e.value)})}};var g=t=>new O(Promise.resolve(new p(t))),I=O.fromPromise,Q=O.fromSafePromise,X=O.fromThrowable,L=t=>{let r=v([]);for(let e of t)if(e.isErr()){r=f(e.error);break}else r.map(n=>n.push(e.value));return r},Z=t=>O.fromSafePromise(Promise.all(t)).andThen(L),W=t=>{let r=v([]);for(let e of t)e.isErr()&&r.isErr()?r.error.push(e.error):e.isErr()&&r.isOk()?r=f([e.error]):e.isOk()&&r.isOk()&&r.value.push(e.value);return r},G=t=>O.fromSafePromise(Promise.all(t)).andThen(W),k;(function(t){function r(s,o){return(...c)=>{try{let a=s(...c);return v(a)}catch(a){return f(o?o(a):a)}}}t.fromThrowable=r;function e(s){return L(s)}t.combine=e;function n(s){return W(s)}t.combineWithAllErrors=n})(k||(k={}));var v=t=>new d(t);function f(t){return new p(t)}var d=class{constructor(r){this.value=r}isOk(){return!0}isErr(){return!this.isOk()}map(r){return v(r(this.value))}mapErr(r){return v(this.value)}andThen(r){return r(this.value)}andThrough(r){return r(this.value).map(e=>this.value)}andTee(r){try{r(this.value)}catch{}return v(this.value)}orElse(r){return v(this.value)}asyncAndThen(r){return r(this.value)}asyncAndThrough(r){return r(this.value).map(()=>this.value)}asyncMap(r){return O.fromSafePromise(r(this.value))}unwrapOr(r){return this.value}match(r,e){return r(this.value)}safeUnwrap(){let r=this.value;return function*(){return r}()}_unsafeUnwrap(r){return this.value}_unsafeUnwrapErr(r){throw A("Called `_unsafeUnwrapErr` on an Ok",this,r)}*[Symbol.iterator](){return this.value}},p=class{constructor(r){this.error=r}isOk(){return!1}isErr(){return!this.isOk()}map(r){return f(this.error)}mapErr(r){return f(r(this.error))}andThrough(r){return f(this.error)}andTee(r){return f(this.error)}andThen(r){return f(this.error)}orElse(r){return r(this.error)}asyncAndThen(r){return g(this.error)}asyncAndThrough(r){return g(this.error)}asyncMap(r){return g(this.error)}unwrapOr(r){return r}match(r,e){return e(this.error)}safeUnwrap(){let r=this.error;return function*(){throw yield f(r),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(r){throw A("Called `_unsafeUnwrap` on an Err",this,r)}_unsafeUnwrapErr(r){return this.error}*[Symbol.iterator](){let r=this;return yield r,r}},j=k.fromThrowable;async function S(t,r,e,n){let s={...e,headers:e?.headers??{}},o={requestOptions:s,url:t},c=await I(fetch(t,s),u=>u instanceof Error?f({type:"fetchError",...o,message:`Fetch error: ${u.message}. URL: ${t}`,error:u}):f({type:"unknownFetchThrow",...o,message:`Unknown fetch error. URL: ${t}`,error:u}));if(c.isErr())return c.error;let a=c.value,m={...o,response:a},y=await I(a.text(),u=>u instanceof Error?f({type:"unknownGetTextError",...m,message:`Can't get response content: ${u.message}. URL: ${t}. HTTP ${a.status}`,error:u}):f({type:"unknownGetTextUnknownError",...m,message:`Can't get response content: Unknown error. URL: ${t}. HTTP ${a.status}`,error:u}));if(y.isErr())return y.error;let h=y.value,l={...m,text:h},i=j(JSON.parse,u=>u instanceof Error?f({type:"jsonParseError",...l,message:`Can't parse response as JSON: ${u.message}. URL: ${t}. HTTP ${a.status}. Original response: ${h}`,error:u}):f({type:"jsonParseUnknownError",...l,message:`Unknown JSON parse error. URL: ${t}. HTTP ${a.status}. Original response: ${h}`,error:u}))(h);if(i.isErr()){let u=r.safeParse(h);return u.success?v({...l,data:u.data}):f({type:"jsonParseError",...l,message:`Can't parse response as JSON: ${i.error.error.message}. URL: ${t}. HTTP ${a.status}. Original response: ${h}`,error:i.error.error})}let w=i.value,T;if(n){let u=n.safeParse(w);u.success&&(T=u.data)}if(a.status>=500)return f({type:"serverError",...l,message:`Server error. URL: ${t}. HTTP ${a.status} ${a.statusText}. Original response: ${h}. ${T?`Data: ${JSON.stringify(T)}`:""}`});if(a.status>=400)return f({type:"clientError",...l,message:`Error: ${a.status} ${a.statusText}. URL: ${t}. HTTP ${a.status}. Original response: ${h}`,errorMetadata:T});let P=r.safeParse(w);if(!P.success){let u=P.error.issues.map(x=>`[${x.path.join(".")}] ${x.message}`).join(", ");return f({type:"payloadParseError",...l,message:`Can't recognize response payload: ${u}. URL: ${t}. HTTP ${a.status}. Original response: ${h}`})}return v({...l,data:P.data})}function U(t){return async(...r)=>{let e=await t(...r);if(e.isErr()){let{message:n,url:s}=e.error;throw new Error(`${n} (${s})`)}return e.value.data}}return N(B);})();
//# sourceMappingURL=browser.global.js.map

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

import"isomorphic-unfetch";import{err as s,fromPromise as g,fromThrowable as I,ok as l}from"neverthrow";async function y(t,i,n,c){let p={...n,headers:n?.headers??{}},m={requestOptions:p,url:t},E=await g(fetch(t,p),r=>r instanceof Error?s({type:"fetchError",...m,message:`Fetch error: ${r.message}. URL: ${t}`,error:r}):s({type:"unknownFetchThrow",...m,message:`Unknown fetch error. URL: ${t}`,error:r}));if(E.isErr())return E.error;let e=E.value,d={...m,response:e},$=await g(e.text(),r=>r instanceof Error?s({type:"unknownGetTextError",...d,message:`Can't get response content: ${r.message}. URL: ${t}. HTTP ${e.status}`,error:r}):s({type:"unknownGetTextUnknownError",...d,message:`Can't get response content: Unknown error. URL: ${t}. HTTP ${e.status}`,error:r}));if($.isErr())return $.error;let a=$.value,o={...d,text:a},u=I(JSON.parse,r=>r instanceof Error?s({type:"jsonParseError",...o,message:`Can't parse response as JSON: ${r.message}. URL: ${t}. HTTP ${e.status}. Original response: ${a}`,error:r}):s({type:"jsonParseUnknownError",...o,message:`Unknown JSON parse error. URL: ${t}. HTTP ${e.status}. Original response: ${a}`,error:r}))(a);if(u.isErr()){let r=i.safeParse(a);return r.success?l({...o,data:r.data}):s({type:"jsonParseError",...o,message:`Can't parse response as JSON: ${u.error.error.message}. URL: ${t}. HTTP ${e.status}. Original response: ${a}`,error:u.error.error})}let O=u.value,f;if(c){let r=c.safeParse(O);r.success&&(f=r.data)}if(e.status>=500)return s({type:"serverError",...o,message:`Server error: ${e.status} ${e.statusText}. ${f?`Data: ${JSON.stringify(f)}`:""}`});if(e.status>=400)return s({type:"clientError",...o,message:`Error: ${e.status} ${e.statusText}. URL: ${t}. HTTP ${e.status}. Original response: ${a}`,errorMetadata:f});let h=i.safeParse(O);if(!h.success){let r=h.error.issues.map(T=>`[${T.path.join(".")}] ${T.message}`).join(", ");return s({type:"payloadParseError",...o,message:`Can't recognize response payload: ${r}. URL: ${t}. HTTP ${e.status}. Original response: ${a}`})}return l({...o,data:h.data})}function P(t){return async(...i)=>{let n=await t(...i);if(n.isErr()){let{message:c,url:p}=n.error;throw new Error(`${c} (${p})`)}return n.value.data}}export{y as fetchWithValidation,P as simpleFetch};
import"isomorphic-unfetch";import{err as s,fromPromise as g,fromThrowable as I,ok as l}from"neverthrow";async function y(t,i,n,c){let p={...n,headers:n?.headers??{}},m={requestOptions:p,url:t},E=await g(fetch(t,p),r=>r instanceof Error?s({type:"fetchError",...m,message:`Fetch error: ${r.message}. URL: ${t}`,error:r}):s({type:"unknownFetchThrow",...m,message:`Unknown fetch error. URL: ${t}`,error:r}));if(E.isErr())return E.error;let e=E.value,$={...m,response:e},d=await g(e.text(),r=>r instanceof Error?s({type:"unknownGetTextError",...$,message:`Can't get response content: ${r.message}. URL: ${t}. HTTP ${e.status}`,error:r}):s({type:"unknownGetTextUnknownError",...$,message:`Can't get response content: Unknown error. URL: ${t}. HTTP ${e.status}`,error:r}));if(d.isErr())return d.error;let a=d.value,o={...$,text:a},u=I(JSON.parse,r=>r instanceof Error?s({type:"jsonParseError",...o,message:`Can't parse response as JSON: ${r.message}. URL: ${t}. HTTP ${e.status}. Original response: ${a}`,error:r}):s({type:"jsonParseUnknownError",...o,message:`Unknown JSON parse error. URL: ${t}. HTTP ${e.status}. Original response: ${a}`,error:r}))(a);if(u.isErr()){let r=i.safeParse(a);return r.success?l({...o,data:r.data}):s({type:"jsonParseError",...o,message:`Can't parse response as JSON: ${u.error.error.message}. URL: ${t}. HTTP ${e.status}. Original response: ${a}`,error:u.error.error})}let O=u.value,f;if(c){let r=c.safeParse(O);r.success&&(f=r.data)}if(e.status>=500)return s({type:"serverError",...o,message:`Server error. URL: ${t}. HTTP ${e.status} ${e.statusText}. Original response: ${a}. ${f?`Data: ${JSON.stringify(f)}`:""}`});if(e.status>=400)return s({type:"clientError",...o,message:`Error: ${e.status} ${e.statusText}. URL: ${t}. HTTP ${e.status}. Original response: ${a}`,errorMetadata:f});let h=i.safeParse(O);if(!h.success){let r=h.error.issues.map(T=>`[${T.path.join(".")}] ${T.message}`).join(", ");return s({type:"payloadParseError",...o,message:`Can't recognize response payload: ${r}. URL: ${t}. HTTP ${e.status}. Original response: ${a}`})}return l({...o,data:h.data})}function P(t){return async(...i)=>{let n=await t(...i);if(n.isErr()){let{message:c,url:p}=n.error;throw new Error(`${c} (${p})`)}return n.value.data}}export{y as fetchWithValidation,P as simpleFetch};
//# sourceMappingURL=index.js.map

@@ -7,3 +7,3 @@ {

},
"version": "0.2.15",
"version": "0.2.16",
"description": "Making HTTP requests human way",

@@ -42,3 +42,3 @@ "main": "./dist/index.cjs",

"isomorphic-unfetch": "^4.0.2",
"neverthrow": "^8.0.0",
"neverthrow": "^8.1.1",
"patch-package": "^8.0.0",

@@ -57,5 +57,5 @@ "zod": "^3.23.8"

"eslint-config-xo-typescript": "^4.0.0",
"rimraf": "^5.0.7",
"tsup": "^8.3.0",
"typescript": "^5.6.2"
"rimraf": "^6.0.1",
"tsup": "^8.3.5",
"typescript": "^5.6.3"
},

@@ -62,0 +62,0 @@ "pnpm": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet