@microlink/function 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -949,7 +949,7 @@
949
949
  var browser = factory_1$1({
950
950
  mql: browser$1,
951
951
  toCompress: code => code.toString(),
952
- VERSION: '0.1.5'
952
+ VERSION: '0.1.6'
953
953
  });
954
954
 
955
955
  return browser;
@@ -1,3 +1,3 @@
1
1
  !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("url")):"function"==typeof define&&define.amd?define(["url"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).microlink=e(t.require$$0$1)}(this,(function(t){"use strict";function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=e(t),o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function s(t){if(t.__esModule)return t;var e=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(t).forEach((function(r){var o=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,o.get?o:{enumerable:!0,get:function(){return t[r]}})})),e}var n=({mql:t,VERSION:e,toCompress:r})=>{const o=(e,o,s)=>{const n=r(e);return async(e,r)=>{const{data:i}=await t(e,{function:await n,meta:!1,...o,...r},s);return i.function}};return o.version=e,o.mql=t,o};const i=o.window?window.URL:r.default.URL,a=/^https?:\/\//i;var u={};function c(t,e,r,o,s){var n,i=s?s+r:s;if(null==o)e&&(t[s]=o);else if("object"!=typeof o)t[s]=o;else if(Array.isArray(o))for(n=0;n<o.length;n++)c(t,e,r,o[n],i+n);else for(n in o)c(t,e,r,o[n],i+n)}function p(t){if(!t)return"";var e=decodeURIComponent(t);return"false"!==e&&("true"===e||(0*+e==0?+e:e))}u.flattie=function(t,e,r){var o={};return"object"==typeof t&&c(o,!!r,e||".",t,""),o};var l=s(Object.freeze({__proto__:null,encode:function(t,e){var r,o,s,n="";for(r in t)if(void 0!==(s=t[r]))if(Array.isArray(s))for(o=0;o<s.length;o++)n&&(n+="&"),n+=encodeURIComponent(r)+"="+encodeURIComponent(s[o]);else n&&(n+="&"),n+=encodeURIComponent(r)+"="+encodeURIComponent(s);return(e||"")+n},decode:function(t){for(var e,r,o={},s=t.split("&");e=s.shift();)void 0!==o[r=(e=e.split("=")).shift()]?o[r]=[].concat(o[r],p(e.shift())):o[r]=p(e.shift());return o}})),f={exports:{}};const h=s(Object.freeze({__proto__:null,default:{}})),d=/\s+at.*(?:\(|\s)(.*)\)?/,y=/^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)\.js:\d+:\d+)|native)/,m=void 0===h.homedir?"":h.homedir();const b=(t,e,r,o)=>{if("length"===r||"prototype"===r)return;const s=Object.getOwnPropertyDescriptor(t,r),n=Object.getOwnPropertyDescriptor(e,r);!g(s,n)&&o||Object.defineProperty(t,r,n)},g=function(t,e){return void 0===t||t.configurable||t.writable===e.writable&&t.enumerable===e.enumerable&&t.configurable===e.configurable&&(t.writable||t.value===e.value)},w=(t,e)=>`/* Wrapped ${t}*/\n${e}`,_=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),R=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name");var E=(t,e,{ignoreNonConfigurable:r=!1}={})=>{const{name:o}=t;for(const o of Reflect.ownKeys(e))b(t,e,o,r);return((t,e)=>{const r=Object.getPrototypeOf(e);r!==Object.getPrototypeOf(t)&&Object.setPrototypeOf(t,r)})(t,e),((t,e,r)=>{const o=""===r?"":`with ${r.trim()}() `,s=w.bind(null,o,e.toString());Object.defineProperty(s,"name",R),Object.defineProperty(t,"toString",{..._,value:s})})(t,e,o),t},T={isFunction:t=>"function"==typeof t,isString:t=>"string"==typeof t,composeErrorMessage:(t,e)=>`${t}, ${e}`,inherits:(t,e)=>{t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}};const{isFunction:v,composeErrorMessage:j}=T;const O=(t,e)=>(e=Object.assign({pretty:!1},e),t.replace(/\\/g,"/").split("\n").filter((t=>{const e=t.match(d);if(null===e||!e[1])return!0;const r=e[1];return!r.includes(".app/Contents/Resources/electron.asar")&&!r.includes(".app/Contents/Resources/default_app.asar")&&!y.test(r)})).filter((t=>""!==t.trim())).map((t=>e.pretty?t.replace(d,((t,e)=>t.replace(e,e.replace(m,"~")))):t)).join("\n")),C=E,q=function(t,...e){Object.assign(t,...e),t.description=v(t.message)?t.message(t):t.message,t.message=t.code?j(t.code,t.description):t.description},{isString:x}=T;var P=function(t,e){function r(r){const o=new t,s=x(r)?{message:r}:r;return q(o,e,s),o.stack=O(o.stack),o}return r.prototype=t.prototype,C(r,t),r};const{inherits:A}=T,S=E,U=/[^0-9a-zA-Z_$]/;const k=P,N=function(t){if("string"!=typeof t)throw new TypeError("Expected className to be a string");if(U.test(t))throw new Error("className contains invalid characters");function e(){Object.defineProperty(this,"name",{configurable:!0,value:t,writable:!0}),Error.captureStackTrace(this,this.constructor)}return A(e,Error),S(e,Error),e},I=t=>(e,r)=>{const o=N(e||t.name);return k(o,r)};f.exports=I(Error),f.exports.type=I(TypeError),f.exports.range=I(RangeError),f.exports.eval=I(EvalError),f.exports.syntax=I(SyntaxError),f.exports.reference=I(ReferenceError),f.exports.uri=I(URIError);const $={FREE:"https://api.microlink.io",PRO:"https://pro.microlink.io"},D=t=>null!==t&&"object"==typeof t;var L=({VERSION:t,MicrolinkError:e,isUrlHttp:r,stringify:o,got:s,flatten:n})=>{const i=t=>{if(!D(t))return;const e=n(t);return Object.keys(e).reduce(((t,r)=>(t[`data.${r}`]=e[r].toString(),t)),{})},a=async(t,r={},o=0)=>{try{const e=await s(t,r);return"buffer"===r.responseType?{body:e.body,response:e}:{...e.body,response:e}}catch(s){const{response:n={}}=s,{statusCode:i,body:u,headers:c,url:p=t}=n,l=Buffer.isBuffer(u),f=D(u)&&!l?u:((t,e,r)=>{try{return JSON.parse(t)}catch(o){const s=t||e.message;return{status:"error",data:{url:s},more:"https://microlink.io/efatalclient",code:"EFATALCLIENT",message:s,url:r}}})(l?u.toString():u,s,p);if("EFATALCLIENT"===f.code&&o++<2)return a(t,r,o);throw e({...f,message:f.message,url:p,statusCode:i,headers:c})}},u=(t,{data:e,apiKey:r,endpoint:s,retry:a,cache:u,...c}={},{responseType:p="json",headers:l,...f}={})=>{const h=!!r;return[`${s||$[h?"PRO":"FREE"]}?${o({url:t,...i(e),...n(c)})}`,{...f,responseType:p,cache:u,retry:a,headers:h?{...l,"x-api-key":r}:{...l}}]},c=t=>async(o,s,n)=>{((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({status:"fail",data:{url:r},more:"https://microlink.io/docs/api/api-parameters/url",code:"EINVALURLCLIENT",message:r,url:t})}})(o);const[i,c]=u(o,s,{...t,...n});return a(i,c)},p=c();return p.MicrolinkError=e,p.getApiUrl=u,p.fetchFromApi=a,p.mapRules=i,p.version=t,p.stream=s.stream,p.buffer=c({responseType:"buffer"}),p},F={exports:{}};!function(t,e){!function(t){class e extends Error{constructor(t,e,r){const o=`${t.status||0===t.status?t.status:""} ${t.statusText||""}`.trim();super("Request failed with "+(o?`status code ${o}`:"an unknown error")),this.name="HTTPError",this.response=t,this.request=e,this.options=r}}class r extends Error{constructor(t){super("Request timed out"),this.name="TimeoutError",this.request=t}}const o=t=>null!==t&&"object"==typeof t,s=(...t)=>{for(const e of t)if((!o(e)||Array.isArray(e))&&void 0!==e)throw new TypeError("The `options` argument must be an object");return i({},...t)},n=(t={},e={})=>{const r=new globalThis.Headers(t),o=e instanceof globalThis.Headers,s=new globalThis.Headers(e);for(const[t,e]of s.entries())o&&"undefined"===e||void 0===e?r.delete(t):r.set(t,e);return r},i=(...t)=>{let e={},r={};for(const s of t)if(Array.isArray(s))Array.isArray(e)||(e=[]),e=[...e,...s];else if(o(s)){for(let[t,r]of Object.entries(s))o(r)&&t in e&&(r=i(e[t],r)),e={...e,[t]:r};o(s.headers)&&(r=n(r,s.headers),e.headers=r)}return e},a="function"==typeof globalThis.AbortController,u="function"==typeof globalThis.ReadableStream,c="function"==typeof globalThis.FormData,p=["get","post","put","patch","head","delete"],l={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*"},f=2147483647,h=Symbol("stop"),d=t=>p.includes(t)?t.toUpperCase():t,y=[413,429,503],m={limit:2,methods:["get","put","head","delete","options","trace"],statusCodes:[408,413,429,500,502,503,504],afterStatusCodes:y,maxRetryAfter:Number.POSITIVE_INFINITY},b=(t={})=>{if("number"==typeof t)return{...m,limit:t};if(t.methods&&!Array.isArray(t.methods))throw new Error("retry.methods must be an array");if(t.statusCodes&&!Array.isArray(t.statusCodes))throw new Error("retry.statusCodes must be an array");return{...m,...t,afterStatusCodes:y}},g=async(t,e,o)=>new Promise(((s,n)=>{const i=setTimeout((()=>{e&&e.abort(),n(new r(t))}),o.timeout);o.fetch(t).then(s).catch(n).then((()=>{clearTimeout(i)}))})),w=async t=>new Promise((e=>{setTimeout(e,t)}));class _{constructor(t,e={}){var r,o;if(this._retryCount=0,this._input=t,this._options={credentials:this._input.credentials||"same-origin",...e,headers:n(this._input.headers,e.headers),hooks:i({beforeRequest:[],beforeRetry:[],afterResponse:[]},e.hooks),method:d(null!==(r=e.method)&&void 0!==r?r:this._input.method),prefixUrl:String(e.prefixUrl||""),retry:b(e.retry),throwHttpErrors:!1!==e.throwHttpErrors,timeout:void 0===e.timeout?1e4:e.timeout,fetch:null!==(o=e.fetch)&&void 0!==o?o:globalThis.fetch.bind(globalThis)},"string"!=typeof this._input&&!(this._input instanceof URL||this._input instanceof globalThis.Request))throw new TypeError("`input` must be a string, URL, or Request");if(this._options.prefixUrl&&"string"==typeof this._input){if(this._input.startsWith("/"))throw new Error("`input` must not begin with a slash when using `prefixUrl`");this._options.prefixUrl.endsWith("/")||(this._options.prefixUrl+="/"),this._input=this._options.prefixUrl+this._input}if(a&&(this.abortController=new globalThis.AbortController,this._options.signal&&this._options.signal.addEventListener("abort",(()=>{this.abortController.abort()})),this._options.signal=this.abortController.signal),this.request=new globalThis.Request(this._input,this._options),this._options.searchParams){const t="?"+("string"==typeof this._options.searchParams?this._options.searchParams.replace(/^\?/,""):new URLSearchParams(this._options.searchParams).toString()),e=this.request.url.replace(/(?:\?.*?)?(?=#|$)/,t);!(c&&this._options.body instanceof globalThis.FormData||this._options.body instanceof URLSearchParams)||this._options.headers&&this._options.headers["content-type"]||this.request.headers.delete("content-type"),this.request=new globalThis.Request(new globalThis.Request(e,this.request),this._options)}void 0!==this._options.json&&(this._options.body=JSON.stringify(this._options.json),this.request.headers.set("content-type","application/json"),this.request=new globalThis.Request(this.request,{body:this._options.body}))}static create(t,r){const o=new _(t,r),s=async()=>{if(o._options.timeout>f)throw new RangeError(`The \`timeout\` option cannot be greater than ${f}`);await Promise.resolve();let t=await o._fetch();for(const e of o._options.hooks.afterResponse){const r=await e(o.request,o._options,o._decorateResponse(t.clone()));r instanceof globalThis.Response&&(t=r)}if(o._decorateResponse(t),!t.ok&&o._options.throwHttpErrors)throw new e(t,o.request,o._options);if(o._options.onDownloadProgress){if("function"!=typeof o._options.onDownloadProgress)throw new TypeError("The `onDownloadProgress` option must be a function");if(!u)throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");return o._stream(t.clone(),o._options.onDownloadProgress)}return t},n=o._options.retry.methods.includes(o.request.method.toLowerCase())?o._retry(s):s();for(const[t,e]of Object.entries(l))n[t]=async()=>{o.request.headers.set("accept",o.request.headers.get("accept")||e);const s=(await n).clone();if("json"===t){if(204===s.status)return"";if(r.parseJson)return r.parseJson(await s.text())}return s[t]()};return n}_calculateRetryDelay(t){if(this._retryCount++,this._retryCount<this._options.retry.limit&&!(t instanceof r)){if(t instanceof e){if(!this._options.retry.statusCodes.includes(t.response.status))return 0;const e=t.response.headers.get("Retry-After");if(e&&this._options.retry.afterStatusCodes.includes(t.response.status)){let t=Number(e);return Number.isNaN(t)?t=Date.parse(e)-Date.now():t*=1e3,void 0!==this._options.retry.maxRetryAfter&&t>this._options.retry.maxRetryAfter?0:t}if(413===t.response.status)return 0}return.3*2**(this._retryCount-1)*1e3}return 0}_decorateResponse(t){return this._options.parseJson&&(t.json=async()=>this._options.parseJson(await t.text())),t}async _retry(t){try{return await t()}catch(e){const r=Math.min(this._calculateRetryDelay(e),f);if(0!==r&&this._retryCount>0){await w(r);for(const t of this._options.hooks.beforeRetry)if(await t({request:this.request,options:this._options,error:e,retryCount:this._retryCount})===h)return;return this._retry(t)}throw e}}async _fetch(){for(const t of this._options.hooks.beforeRequest){const e=await t(this.request,this._options);if(e instanceof Request){this.request=e;break}if(e instanceof Response)return e}return!1===this._options.timeout?this._options.fetch(this.request.clone()):g(this.request.clone(),this.abortController,this._options)}_stream(t,e){const r=Number(t.headers.get("content-length"))||0;let o=0;return new globalThis.Response(new globalThis.ReadableStream({async start(s){const n=t.body.getReader();async function i(){const{done:t,value:a}=await n.read();t?s.close():(e&&(o+=a.byteLength,e({percent:0===r?0:o/r,transferredBytes:o,totalBytes:r},a)),s.enqueue(a),await i())}e&&e({percent:0,transferredBytes:0,totalBytes:r},new Uint8Array),await i()}}))}}
2
- /*! MIT License © Sindre Sorhus */const R=t=>{const e=(e,r)=>_.create(e,s(t,r));for(const r of p)e[r]=(e,o)=>_.create(e,s(t,o,{method:r}));return e.create=t=>R(s(t)),e.extend=e=>R(s(t,e)),e.stop=h,e},E=R();t.HTTPError=e,t.TimeoutError=r,t.default=E,Object.defineProperty(t,"__esModule",{value:!0})}(e)}(0,F.exports);const M=t=>{try{return a.test(new i(t).href)}catch(t){return!1}},{flattie:H}=u,{encode:B}=l,J=f.exports,V=L,{default:z}=F.exports;return n({mql:V({MicrolinkError:J("MicrolinkError"),isUrlHttp:M,stringify:B,got:async(t,e)=>{try{void 0===e.timeout&&(e.timeout=!1);const r=await z(t,e),o=await r.json(),{headers:s,status:n,statusText:i}=r;return{url:r.url,body:o,headers:s,statusCode:n,statusMessage:i}}catch(t){if(t.response){const{response:e}=t;t.response={...e,headers:Array.from(e.headers.entries()).reduce(((t,[e,r])=>(t[e]=r,t)),{}),statusCode:e.status,body:await e.text()}}throw t}},flatten:H,VERSION:"0.10.15"}),toCompress:t=>t.toString(),VERSION:"0.1.5"})}));
2
+ /*! MIT License © Sindre Sorhus */const R=t=>{const e=(e,r)=>_.create(e,s(t,r));for(const r of p)e[r]=(e,o)=>_.create(e,s(t,o,{method:r}));return e.create=t=>R(s(t)),e.extend=e=>R(s(t,e)),e.stop=h,e},E=R();t.HTTPError=e,t.TimeoutError=r,t.default=E,Object.defineProperty(t,"__esModule",{value:!0})}(e)}(0,F.exports);const M=t=>{try{return a.test(new i(t).href)}catch(t){return!1}},{flattie:H}=u,{encode:B}=l,J=f.exports,V=L,{default:z}=F.exports;return n({mql:V({MicrolinkError:J("MicrolinkError"),isUrlHttp:M,stringify:B,got:async(t,e)=>{try{void 0===e.timeout&&(e.timeout=!1);const r=await z(t,e),o=await r.json(),{headers:s,status:n,statusText:i}=r;return{url:r.url,body:o,headers:s,statusCode:n,statusMessage:i}}catch(t){if(t.response){const{response:e}=t;t.response={...e,headers:Array.from(e.headers.entries()).reduce(((t,[e,r])=>(t[e]=r,t)),{}),statusCode:e.status,body:await e.text()}}throw t}},flatten:H,VERSION:"0.10.15"}),toCompress:t=>t.toString(),VERSION:"0.1.6"})}));
3
3
  //# sourceMappingURL=microlink-function.min.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@microlink/function",
3
3
  "homepage": "https://github.com/microlinkhq/function#readme",
4
- "version": "0.1.5",
4
+ "version": "0.1.6",
5
5
  "main": "src/node.js",
6
6
  "browser": "src/browser.js",
7
7
  "author": {
@@ -70,5 +70,5 @@
70
70
  },
71
71
  "umd:main": "dist/microlink-function.js",
72
72
  "unpkg": "dist/microlink-function.js",
73
- "gitHead": "5f1fd7e860762e79eb238498b9e388a43bf8f839"
73
+ "gitHead": "09d3b07a27a4fccbd26a823bfacc25bb1df46c05"
74
74
  }