@microlink/mql
Advanced tools
Comparing version 0.6.1 to 0.6.2
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.6.2](https://github.com/microlinkhq/mql/compare/v0.6.1...v0.6.2) (2020-03-03) | ||
### Bug Fixes | ||
* headers serialization on browser ([23fde59](https://github.com/microlinkhq/mql/commit/23fde599afbe700a94be9a522ab9dfdcfc6f31da)) | ||
### [0.6.1](https://github.com/microlinkhq/mql/compare/v0.6.0...v0.6.1) (2020-03-01) | ||
@@ -7,0 +14,0 @@ |
@@ -1041,3 +1041,11 @@ (function (global, factory) { | ||
const { response } = err; | ||
err.response = { ...response, statusCode: response.status, body: await response.json() }; | ||
err.response = { | ||
...response, | ||
headers: [...response.headers.entries()].reduce( | ||
(acc, [key, value]) => ({ ...acc, [key]: value }), | ||
{} | ||
), | ||
statusCode: response.status, | ||
body: await response.json() | ||
}; | ||
} | ||
@@ -1054,3 +1062,3 @@ throw err | ||
flatten: flat, | ||
VERSION: '0.6.1' | ||
VERSION: '0.6.2' | ||
}); | ||
@@ -1057,0 +1065,0 @@ |
@@ -10,3 +10,3 @@ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("url")):"function"==typeof define&&define.amd?define(["url"],e):(t=t||self).mql=e(t.url)}(this,(function(t){"use strict";t=t&&t.hasOwnProperty("default")?t.default:t;var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function r(t){return t&&t.default||t}var o=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t,r){t.exports=function(){ | ||
*/ | ||
var P=function(t){return null!=t&&null!=t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)},U=D;function N(t){return t}function D(t,e){const r=(e=e||{}).delimiter||".",o=e.maxDepth,s=e.transformKey||N,n={};return function t(i,a,c){c=c||1,Object.keys(i).forEach((function(u){const f=i[u],p=e.safe&&Array.isArray(f),l=Object.prototype.toString.call(f),h=P(f),d="[object Object]"===l||"[object Array]"===l,y=a?a+r+s(u):s(u);if(!p&&!h&&d&&Object.keys(f).length&&(!e.maxDepth||c<o))return t(f,y,c+1);n[y]=f}))}(t),n}D.flatten=D,D.unflatten=function t(e,r){const o=(r=r||{}).delimiter||".",s=r.overwrite||!1,n=r.transformKey||N,i={};if(P(e)||"[object Object]"!==Object.prototype.toString.call(e))return e;function a(t){const e=Number(t);return isNaN(e)||-1!==t.indexOf(".")||r.object?t:e}return e=Object.keys(e).reduce((t,s)=>{const n=Object.prototype.toString.call(e[s]);return!("[object Object]"===n||"[object Array]"===n)||function(t){const e=Object.prototype.toString.call(t),r="[object Array]"===e,o="[object Object]"===e;if(!t)return!0;if(r)return!t.length;if(o)return!Object.keys(t).length}(e[s])?(t[s]=e[s],t):function(t,e,r){return Object.keys(r).reduce((function(e,s){return e[t+o+s]=r[s],e}),e)}(s,t,D(e[s],r))},{}),Object.keys(e).forEach((function(c){const u=c.split(o).map(n);let f=a(u.shift()),p=a(u[0]),l=i;for(;void 0!==p;){const t=Object.prototype.toString.call(l[f]),e="[object Object]"===t||"[object Array]"===t;if(!s&&!e&&void 0!==l[f])return;(s&&!e||!s&&null==l[f])&&(l[f]="number"!=typeof p||r.object?{}:[]),l=l[f],u.length>0&&(f=a(u.shift()),p=a(u[0]))}l[f]=t(e[c],r)})),i};const I={FREE:"https://api.microlink.io",PRO:"https://pro.microlink.io"};var L=({VERSION:t,MicrolinkError:e,isUrlHttp:r,stringify:o,got:s,flatten:n})=>{const i=t=>{if("object"!=typeof t)return;const e=n(t);return Object.keys(e).reduce((t,r)=>({...t,[`data.${r}`]:e[r]}),{})},a=async(t,r={})=>{try{const e=await s(t,r),{body:o}=e;return{...o,response:e}}catch(o){const{name:s,message:n,response:i={}}=o,{statusCode:a=500,body:c,headers:u,url:f=t}=i,p=Number((r.retry*r.timeout).toFixed(0)),l="TimeoutError"===s;if(((t,e)=>"TimeoutError"===t.name||"HTTPError"===t.name&&"5"===e.toString()[0]||"invalid-json"===t.type)(o,a)){const t=`The request reached timeout after ${p}ms.`;throw new e({url:f,data:{url:t},status:"fail",code:l?"ETIMEOUTCLIENT":"ETIMEOUT",message:t,more:`https://microlink.io/${l?"etimeoutclient":"etimeout"}`,statusCode:a,headers:u})}const h=c?"string"==typeof c||Buffer.isBuffer(c)?JSON.parse(c):c:{message:n,status:"fail"};throw e({...h,message:h.message,url:f,statusCode:a,headers:u})}},c=(t,{data:e,apiKey:r,endpoint:s,isStream:a=!1,retry:c=3,timeout:u=3e4,responseType:f="json",...p}={})=>{const l=!!r;var h;return[`${s||I[l?"PRO":"FREE"]}?${o({url:t,...i(e),...n((h=p,Object.keys(h).forEach(t=>null==h[t]&&delete h[t]),h))})}`,{retry:c,timeout:u,responseType:f,isStream:a,headers:l?{"x-api-key":r}:{}}]},u=async(t,o={})=>{((t="")=>{if(!r(t)){const r=`The \`url\` as \`${t}\` is not valid. Ensure it has protocol (http or https) and hostname.`;throw new e({url:t,data:{url:r},status:"fail",code:"EINVALURLCLIENT",message:r,more:"https://microlink.io/docs/api/api-parameters/url"})}})(t);const[s,n]=c(t,o);return a(s,{...o,...n})};return u.MicrolinkError=e,u.getApiUrl=c,u.fetchFromApi=a,u.mapRules=i,u.version=t,u.stream=(t,e)=>s.stream(t,{retry:3,timeout:3e4,...e}),u},$=r(a);const H=o.default||o,{encode:M}=$;return L({MicrolinkError:T("MicrolinkError"),isUrlHttp:t=>{try{return n.test(new s(t).href)}catch(t){return!1}},stringify:M,got:async(t,{responseType:e,...r})=>{try{const e=await H(t,r),o=await e.json(),{headers:s,status:n,statusText:i}=e;return{url:e.url,body:o,headers:s,statusCode:n,statusMessage:i}}catch(t){if(t.response){const{response:e}=t;t.response={...e,statusCode:e.status,body:await e.json()}}throw t}},flatten:U,VERSION:"0.6.1"})})); | ||
var P=function(t){return null!=t&&null!=t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)},U=D;function N(t){return t}function D(t,e){const r=(e=e||{}).delimiter||".",o=e.maxDepth,s=e.transformKey||N,n={};return function t(i,a,c){c=c||1,Object.keys(i).forEach((function(u){const f=i[u],p=e.safe&&Array.isArray(f),l=Object.prototype.toString.call(f),h=P(f),d="[object Object]"===l||"[object Array]"===l,y=a?a+r+s(u):s(u);if(!p&&!h&&d&&Object.keys(f).length&&(!e.maxDepth||c<o))return t(f,y,c+1);n[y]=f}))}(t),n}D.flatten=D,D.unflatten=function t(e,r){const o=(r=r||{}).delimiter||".",s=r.overwrite||!1,n=r.transformKey||N,i={};if(P(e)||"[object Object]"!==Object.prototype.toString.call(e))return e;function a(t){const e=Number(t);return isNaN(e)||-1!==t.indexOf(".")||r.object?t:e}return e=Object.keys(e).reduce((t,s)=>{const n=Object.prototype.toString.call(e[s]);return!("[object Object]"===n||"[object Array]"===n)||function(t){const e=Object.prototype.toString.call(t),r="[object Array]"===e,o="[object Object]"===e;if(!t)return!0;if(r)return!t.length;if(o)return!Object.keys(t).length}(e[s])?(t[s]=e[s],t):function(t,e,r){return Object.keys(r).reduce((function(e,s){return e[t+o+s]=r[s],e}),e)}(s,t,D(e[s],r))},{}),Object.keys(e).forEach((function(c){const u=c.split(o).map(n);let f=a(u.shift()),p=a(u[0]),l=i;for(;void 0!==p;){const t=Object.prototype.toString.call(l[f]),e="[object Object]"===t||"[object Array]"===t;if(!s&&!e&&void 0!==l[f])return;(s&&!e||!s&&null==l[f])&&(l[f]="number"!=typeof p||r.object?{}:[]),l=l[f],u.length>0&&(f=a(u.shift()),p=a(u[0]))}l[f]=t(e[c],r)})),i};const I={FREE:"https://api.microlink.io",PRO:"https://pro.microlink.io"};var L=({VERSION:t,MicrolinkError:e,isUrlHttp:r,stringify:o,got:s,flatten:n})=>{const i=t=>{if("object"!=typeof t)return;const e=n(t);return Object.keys(e).reduce((t,r)=>({...t,[`data.${r}`]:e[r]}),{})},a=async(t,r={})=>{try{const e=await s(t,r),{body:o}=e;return{...o,response:e}}catch(o){const{name:s,message:n,response:i={}}=o,{statusCode:a=500,body:c,headers:u,url:f=t}=i,p=Number((r.retry*r.timeout).toFixed(0)),l="TimeoutError"===s;if(((t,e)=>"TimeoutError"===t.name||"HTTPError"===t.name&&"5"===e.toString()[0]||"invalid-json"===t.type)(o,a)){const t=`The request reached timeout after ${p}ms.`;throw new e({url:f,data:{url:t},status:"fail",code:l?"ETIMEOUTCLIENT":"ETIMEOUT",message:t,more:`https://microlink.io/${l?"etimeoutclient":"etimeout"}`,statusCode:a,headers:u})}const h=c?"string"==typeof c||Buffer.isBuffer(c)?JSON.parse(c):c:{message:n,status:"fail"};throw e({...h,message:h.message,url:f,statusCode:a,headers:u})}},c=(t,{data:e,apiKey:r,endpoint:s,isStream:a=!1,retry:c=3,timeout:u=3e4,responseType:f="json",...p}={})=>{const l=!!r;var h;return[`${s||I[l?"PRO":"FREE"]}?${o({url:t,...i(e),...n((h=p,Object.keys(h).forEach(t=>null==h[t]&&delete h[t]),h))})}`,{retry:c,timeout:u,responseType:f,isStream:a,headers:l?{"x-api-key":r}:{}}]},u=async(t,o={})=>{((t="")=>{if(!r(t)){const r=`The \`url\` as \`${t}\` is not valid. Ensure it has protocol (http or https) and hostname.`;throw new e({url:t,data:{url:r},status:"fail",code:"EINVALURLCLIENT",message:r,more:"https://microlink.io/docs/api/api-parameters/url"})}})(t);const[s,n]=c(t,o);return a(s,{...o,...n})};return u.MicrolinkError=e,u.getApiUrl=c,u.fetchFromApi=a,u.mapRules=i,u.version=t,u.stream=(t,e)=>s.stream(t,{retry:3,timeout:3e4,...e}),u},$=r(a);const H=o.default||o,{encode:M}=$;return L({MicrolinkError:T("MicrolinkError"),isUrlHttp:t=>{try{return n.test(new s(t).href)}catch(t){return!1}},stringify:M,got:async(t,{responseType:e,...r})=>{try{const e=await H(t,r),o=await e.json(),{headers:s,status:n,statusText:i}=e;return{url:e.url,body:o,headers:s,statusCode:n,statusMessage:i}}catch(t){if(t.response){const{response:e}=t;t.response={...e,headers:[...e.headers.entries()].reduce((t,[e,r])=>({...t,[e]:r}),{}),statusCode:e.status,body:await e.json()}}throw t}},flatten:U,VERSION:"0.6.2"})})); | ||
//# sourceMappingURL=mql.min.js.map |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://nicedoc.io/microlinkhq/mql", | ||
"version": "0.6.1", | ||
"version": "0.6.2", | ||
"browser": "src/browser.js", | ||
@@ -8,0 +8,0 @@ "main": "src/node.js", |
@@ -22,3 +22,11 @@ 'use strict' | ||
const { response } = err | ||
err.response = { ...response, statusCode: response.status, body: await response.json() } | ||
err.response = { | ||
...response, | ||
headers: [...response.headers.entries()].reduce( | ||
(acc, [key, value]) => ({ ...acc, [key]: value }), | ||
{} | ||
), | ||
statusCode: response.status, | ||
body: await response.json() | ||
} | ||
} | ||
@@ -25,0 +33,0 @@ throw err |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
175930
1086