@uxland/fetch-client
Advanced tools
Comparing version 1.0.1-alpha.15 to 1.0.1-alpha.16
@@ -6,2 +6,13 @@ # Change Log | ||
## [1.0.1-alpha.16](https://github.com/uxland/uxland/compare/@uxland/fetch-client@1.0.1-alpha.15...@uxland/fetch-client@1.0.1-alpha.16) (2021-06-03) | ||
### Bug Fixes | ||
* exclude external libs from build ([fb0b859](https://github.com/uxland/uxland/commit/fb0b859bbfe165987709fade29ebdced36b3fab7)) | ||
## [1.0.1-alpha.15](https://github.com/uxland/uxland/compare/@uxland/fetch-client@1.0.1-alpha.14...@uxland/fetch-client@1.0.1-alpha.15) (2021-06-03) | ||
@@ -8,0 +19,0 @@ |
217
index.min.js
import { | ||
publish as y | ||
publish as c | ||
} from '@uxland/event-aggregator/event-aggregator'; | ||
var g = 'UXL-FETCH:INVALID_CREDENTIALS_EVENT', E = 'UXL-FETCH:INVALID_REQUEST_EVENT', W = async t => { | ||
var n = () => new Promise(n => n()); | ||
var p = 'UXL-FETCH:INVALID_CREDENTIALS_EVENT', d = 'UXL-FETCH:INVALID_REQUEST_EVENT', u = async t => { | ||
var e = () => new Promise(e => e()); | ||
if (t.ok) return t; | ||
{ | ||
let e; | ||
let a; | ||
try { | ||
var r = await t.json(); | ||
e = { | ||
var n = await t.json(); | ||
a = { | ||
...new Error(), | ||
data: r, | ||
data: n, | ||
status: t.status, | ||
statusText: t.statusText | ||
}; | ||
} catch (n) { | ||
e = { | ||
} catch (e) { | ||
a = { | ||
...new Error(), | ||
@@ -25,167 +25,78 @@ status: t.status, | ||
} | ||
throw 401 === t.status ? (await n(), y(g, e)) : (await n(), y(E, e)), e; | ||
throw 401 === t.status ? (await e(), c(p, a)) : (await e(), c(d, a)), a; | ||
} | ||
}, w = 'Content-Type', L = 'application/json', D = n => -1 !== n.headers?.get(w)?.indexOf(L), _ = async (n, e = []) => D(n) ? await n.json().then(n => e.reduce((n, e) => e(n), n)) : await n.text(), R = function(n) { | ||
return null == n ? '' : encodeURIComponent(n); | ||
}, v = function(n) { | ||
let e = []; | ||
for (var t in n) { | ||
var r = n[t]; | ||
e.push(null !== r && 'object' == typeof r ? `${encodeURIComponent(t)}=${JSON.stringify(r)}` : encodeURIComponent(t) + '=' + R(r)); | ||
}, R = 'Content-Type', h = 'application/json', x = e => -1 !== e.headers?.get(R)?.indexOf(h), m = async (e, a = []) => x(e) ? await e.json().then(e => a.reduce((e, a) => a(e), e)) : await e.text(), l = function(e) { | ||
return null == e ? '' : encodeURIComponent(e); | ||
}, g = function(e) { | ||
let a = []; | ||
for (var t in e) { | ||
var n = e[t]; | ||
a.push(null !== n && 'object' == typeof n ? `${encodeURIComponent(t)}=${JSON.stringify(n)}` : encodeURIComponent(t) + '=' + l(n)); | ||
} | ||
return e.join('&'); | ||
}, k = /^([a-z][a-z0-9+\-.]*:)?\/\//i, q = {}, P = function(n, e, t = {}) { | ||
if (k.test(e)) return e; | ||
e = (n || '') + (e || ''), t = v({ | ||
...q, | ||
return a.join('&'); | ||
}, N = /^([a-z][a-z0-9+\-.]*:)?\/\//i, y = {}, E = function(e, a, t = {}) { | ||
if (N.test(a)) return a; | ||
a = (e || '') + (a || ''), t = g({ | ||
...y, | ||
...t | ||
}); | ||
return t ? e + '?' + t : e; | ||
return t ? a + '?' + t : a; | ||
}; | ||
function f(n) { | ||
return null != n && 'object' == typeof n && !0 === n['t']; | ||
} | ||
import { | ||
isNil as C, | ||
mergeDeepRight as _ | ||
} from 'ramda'; | ||
function u(t) { | ||
return function n(e) { | ||
return 0 === arguments.length || f(e) ? n : t.apply(this, arguments); | ||
}; | ||
} | ||
function n(r) { | ||
return function n(e, t) { | ||
switch (arguments.length) { | ||
case 0: | ||
return n; | ||
case 1: | ||
return f(e) ? n : u(function(n) { | ||
return r(e, n); | ||
}); | ||
default: | ||
return f(e) && f(t) ? n : f(e) ? u(function(n) { | ||
return r(n, t); | ||
}) : f(t) ? u(function(n) { | ||
return r(e, n); | ||
}) : r(e, t); | ||
} | ||
}; | ||
} | ||
function m(o) { | ||
return function e(t, r, a) { | ||
switch (arguments.length) { | ||
case 0: | ||
return e; | ||
case 1: | ||
return f(t) ? e : n(function(n, e) { | ||
return o(t, n, e); | ||
}); | ||
case 2: | ||
return f(t) && f(r) ? e : f(t) ? n(function(n, e) { | ||
return o(n, r, e); | ||
}) : f(r) ? n(function(n, e) { | ||
return o(t, n, e); | ||
}) : u(function(n) { | ||
return o(t, r, n); | ||
}); | ||
default: | ||
return f(t) && f(r) && f(a) ? e : f(t) && f(r) ? n(function(n, e) { | ||
return o(n, e, a); | ||
}) : f(t) && f(a) ? n(function(n, e) { | ||
return o(n, r, e); | ||
}) : f(r) && f(a) ? n(function(n, e) { | ||
return o(t, n, e); | ||
}) : f(t) ? u(function(n) { | ||
return o(n, r, a); | ||
}) : f(r) ? u(function(n) { | ||
return o(t, n, a); | ||
}) : f(a) ? u(function(n) { | ||
return o(t, r, n); | ||
}) : o(t, r, a); | ||
} | ||
}; | ||
} | ||
function d(n, e) { | ||
return Object.prototype.hasOwnProperty.call(e, n); | ||
} | ||
var A = u(function(n) { | ||
return null == n; | ||
}), x = A; | ||
function i(n) { | ||
return '[object Object]' === Object.prototype.toString.call(n); | ||
} | ||
var c, B = m(function(n, e, t) { | ||
var r, u = {}; | ||
for (r in e) d(r, e) && (u[r] = d(r, t) ? n(r, e[r], t[r]) : e[r]); | ||
for (r in t) d(r, t) && !d(r, u) && (u[r] = t[r]); | ||
return u; | ||
}), T = B, C = m(function r(u, n, e) { | ||
return T(function(n, e, t) { | ||
return i(e) && i(t) ? r(u, e, t) : u(n, e, t); | ||
}, n, e); | ||
}), I = C, S = n(function(n, e) { | ||
return I(function(n, e, t) { | ||
return t; | ||
}, n, e); | ||
}), j = S, N = (n, e) => x(e) ? n : j(n, e), b = 'application/json', h = [], O = { | ||
u: b | ||
}, l = { | ||
var a, f = (e, a) => C(a) ? e : _(e, a), I = 'application/json', i = [], T = { | ||
t: I | ||
}, n = { | ||
headers: { | ||
...O | ||
...T | ||
}, | ||
credentials: 'include', | ||
mode: 'cors' | ||
}, Ie = n => c = n, Ne = () => c, Oe = n => { | ||
h.push(n); | ||
}, we = () => h, Le = n => { | ||
l = { | ||
...l, | ||
...n | ||
}, z = e => a = e, J = () => a, B = e => { | ||
i.push(e); | ||
}, F = () => i, X = e => { | ||
n = { | ||
...n, | ||
...e | ||
}; | ||
}, De = () => l, ke = n => { | ||
l = { | ||
...l, | ||
}, Y = () => n, k = e => { | ||
n = { | ||
...n, | ||
headers: { | ||
...l.headers, | ||
...n | ||
...n.headers, | ||
...e | ||
} | ||
}; | ||
}, qe = () => l?.headers, Ae = n => { | ||
l?.headers[n] && delete l.headers[n]; | ||
}, Be = () => { | ||
l = { | ||
...l, | ||
}, $ = () => n?.headers, G = e => { | ||
n?.headers[e] && delete n.headers[e]; | ||
}, K = () => { | ||
n = { | ||
...n, | ||
headers: { | ||
...O | ||
...T | ||
} | ||
}; | ||
}, Ce = async (n, e, t) => { | ||
e = await fetch(P(c, n, t), N(e, l)), e = await W(e); | ||
return await _(e, h); | ||
}, M = async (e, t, r) => { | ||
t = await fetch(E(a, e, r), f(t, n)), t = await u(t); | ||
return await m(t, i); | ||
}; | ||
export { | ||
g as INVALID_CREDENTIALS_EVENT, | ||
E as INVALID_REQUEST_EVENT, | ||
Le as configure, | ||
Ce as doFetch, | ||
Ne as getBaseUrl, | ||
De as getConfiguration, | ||
qe as getHeaders, | ||
we as getResponseHandlers, | ||
Oe as registerResponseHandler, | ||
Ae as removeHeader, | ||
Be as resetHeaders, | ||
Ie as setBaseUrl, | ||
ke as setHeaders | ||
p as INVALID_CREDENTIALS_EVENT, | ||
d as INVALID_REQUEST_EVENT, | ||
X as configure, | ||
M as doFetch, | ||
J as getBaseUrl, | ||
Y as getConfiguration, | ||
$ as getHeaders, | ||
F as getResponseHandlers, | ||
B as registerResponseHandler, | ||
G as removeHeader, | ||
K as resetHeaders, | ||
z as setBaseUrl, | ||
k as setHeaders | ||
}; |
@@ -1,2 +0,2 @@ | ||
import{publish as y}from"@uxland/event-aggregator/event-aggregator";var g="UXL-FETCH:INVALID_CREDENTIALS_EVENT",E="UXL-FETCH:INVALID_REQUEST_EVENT",W=async e=>{let s=()=>new Promise(t=>t());if(!e.ok){let t;try{let r=await e.json();t={...new Error,data:r,status:e.status,statusText:e.statusText}}catch(r){t={...new Error,status:e.status,statusText:e.statusText}}throw e.status===401?(await s(),y(g,t)):(await s(),y(E,t)),t}return e};var w="Content-Type",L="application/json",D=e=>e.headers?.get(w)?.indexOf(L)!==-1,_=async(e,s=[])=>D(e)?await e.json().then(t=>s.reduce((r,a)=>a(r),t)):await e.text();var R=function(e){return e===null||typeof e=="undefined"?"":encodeURIComponent(e)};var v=function(e){let s=[];for(let t in e){let r=e[t];s.push(r!==null&&typeof r=="object"?`${encodeURIComponent(t)}=${JSON.stringify(r)}`:encodeURIComponent(t)+"="+R(r))}return s.join("&")};var k=/^([a-z][a-z0-9+\-.]*:)?\/\//i,q={},P=function(e,s,t={}){if(k.test(s))return s;let r=(e||"")+(s||""),a=v({...q,...t});return a?r+"?"+a:r};function f(e){return e!=null&&typeof e=="object"&&e["@@functional/placeholder"]===!0}function u(e){return function s(t){return arguments.length===0||f(t)?s:e.apply(this,arguments)}}function n(e){return function s(t,r){switch(arguments.length){case 0:return s;case 1:return f(t)?s:u(function(a){return e(t,a)});default:return f(t)&&f(r)?s:f(t)?u(function(a){return e(a,r)}):f(r)?u(function(a){return e(t,a)}):e(t,r)}}}function m(e){return function s(t,r,a){switch(arguments.length){case 0:return s;case 1:return f(t)?s:n(function(o,p){return e(t,o,p)});case 2:return f(t)&&f(r)?s:f(t)?n(function(o,p){return e(o,r,p)}):f(r)?n(function(o,p){return e(t,o,p)}):u(function(o){return e(t,r,o)});default:return f(t)&&f(r)&&f(a)?s:f(t)&&f(r)?n(function(o,p){return e(o,p,a)}):f(t)&&f(a)?n(function(o,p){return e(o,r,p)}):f(r)&&f(a)?n(function(o,p){return e(t,o,p)}):f(t)?u(function(o){return e(o,r,a)}):f(r)?u(function(o){return e(t,o,a)}):f(a)?u(function(o){return e(t,r,o)}):e(t,r,a)}}}function d(e,s){return Object.prototype.hasOwnProperty.call(s,e)}var A=u(function(s){return s==null}),x=A;function i(e){return Object.prototype.toString.call(e)==="[object Object]"}var B=m(function(s,t,r){var a={},o;for(o in t)d(o,t)&&(a[o]=d(o,r)?s(o,t[o],r[o]):t[o]);for(o in r)d(o,r)&&!d(o,a)&&(a[o]=r[o]);return a}),T=B;var C=m(function e(s,t,r){return T(function(a,o,p){return i(o)&&i(p)?e(s,o,p):s(a,o,p)},t,r)}),I=C;var S=n(function(s,t){return I(function(r,a,o){return o},s,t)}),j=S;var N=(e,s)=>x(s)?e:j(e,s);var b="application/json",c,h=[],O={"Content-Type":b},l={headers:{...O},credentials:"include",mode:"cors"},Ie=e=>c=e,Ne=()=>c,Oe=e=>{h.push(e)},we=()=>h,Le=e=>{l={...l,...e}},De=()=>l,ke=e=>{l={...l,headers:{...l.headers,...e}}},qe=()=>l?.headers,Ae=e=>{l?.headers[e]&&delete l.headers[e]},Be=()=>{l={...l,headers:{...O}}},Ce=async(e,s,t)=>{let r=await fetch(P(c,e,t),N(s,l)),a=await W(r);return await _(a,h)};export{g as INVALID_CREDENTIALS_EVENT,E as INVALID_REQUEST_EVENT,Le as configure,Ce as doFetch,Ne as getBaseUrl,De as getConfiguration,qe as getHeaders,we as getResponseHandlers,Oe as registerResponseHandler,Ae as removeHeader,Be as resetHeaders,Ie as setBaseUrl,ke as setHeaders}; | ||
import{publish as c}from"@uxland/event-aggregator/event-aggregator";var p="UXL-FETCH:INVALID_CREDENTIALS_EVENT",d="UXL-FETCH:INVALID_REQUEST_EVENT",u=async e=>{let t=()=>new Promise(r=>r());if(!e.ok){let r;try{let o=await e.json();r={...new Error,data:o,status:e.status,statusText:e.statusText}}catch(o){r={...new Error,status:e.status,statusText:e.statusText}}throw e.status===401?(await t(),c(p,r)):(await t(),c(d,r)),r}return e};var R="Content-Type",h="application/json",x=e=>e.headers?.get(R)?.indexOf(h)!==-1,m=async(e,t=[])=>x(e)?await e.json().then(r=>t.reduce((o,s)=>s(o),r)):await e.text();var l=function(e){return e===null||typeof e=="undefined"?"":encodeURIComponent(e)};var g=function(e){let t=[];for(let r in e){let o=e[r];t.push(o!==null&&typeof o=="object"?`${encodeURIComponent(r)}=${JSON.stringify(o)}`:encodeURIComponent(r)+"="+l(o))}return t.join("&")};var N=/^([a-z][a-z0-9+\-.]*:)?\/\//i,y={},E=function(e,t,r={}){if(N.test(t))return t;let o=(e||"")+(t||""),s=g({...y,...r});return s?o+"?"+s:o};import{isNil as C,mergeDeepRight as _}from"ramda";var f=(e,t)=>C(t)?e:_(e,t);var I="application/json",a,i=[],T={"Content-Type":I},n={headers:{...T},credentials:"include",mode:"cors"},z=e=>a=e,J=()=>a,B=e=>{i.push(e)},F=()=>i,X=e=>{n={...n,...e}},Y=()=>n,k=e=>{n={...n,headers:{...n.headers,...e}}},$=()=>n?.headers,G=e=>{n?.headers[e]&&delete n.headers[e]},K=()=>{n={...n,headers:{...T}}},M=async(e,t,r)=>{let o=await fetch(E(a,e,r),f(t,n)),s=await u(o);return await m(s,i)};export{p as INVALID_CREDENTIALS_EVENT,d as INVALID_REQUEST_EVENT,X as configure,M as doFetch,J as getBaseUrl,Y as getConfiguration,$ as getHeaders,F as getResponseHandlers,B as registerResponseHandler,G as removeHeader,K as resetHeaders,z as setBaseUrl,k as setHeaders}; | ||
/* | ||
@@ -3,0 +3,0 @@ * @license |
{ | ||
"name": "@uxland/fetch-client", | ||
"version": "1.0.1-alpha.15", | ||
"version": "1.0.1-alpha.16", | ||
"description": "Fetch Client", | ||
@@ -33,3 +33,3 @@ "author": "UXLand <dev@uxland.es>", | ||
"build:es": "esbuild *.ts handlers/*.ts helpers/*.ts --minify --format=esm --outdir=.", | ||
"prebuild:uglify": "esbuild index.ts --bundle --minify --external:@uxland/* --format=esm --outdir=./lib", | ||
"prebuild:uglify": "esbuild index.ts --bundle --minify --external:@uxland/* --external:ramda --format=esm --outdir=./lib", | ||
"build:uglify": "uglifyjs lib/index.js --compress --mangle --mangle-props --no-annotations --beautify quote_style=1 -o index.min.js", | ||
@@ -79,6 +79,6 @@ "build": "npm-run-all --parallel build:es build:dts build:uglify", | ||
"dependencies": { | ||
"@uxland/event-aggregator": "^1.0.1-alpha.15", | ||
"@uxland/event-aggregator": "^1.0.1-alpha.16", | ||
"ramda": "^0.27.1" | ||
}, | ||
"gitHead": "bd729cc390d3591780ff9b81542856e1abc0bf07" | ||
"gitHead": "d7711f6d100a7e10193be76fd7203d0c0fde8de4" | ||
} |
34842
344