@microlink/mql 0.10.2 → 0.10.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.
- package/dist/mql.js +1 -1
- package/dist/mql.min.js +1 -1
- package/index.d.ts +123 -46
- package/package.json +11 -7
package/dist/mql.js
CHANGED
package/dist/mql.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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).mql=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}const n=o.window?window.URL:r.default.URL,i=/^https?:\/\//i;var a={};function u(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++)u(t,e,r,o[n],i+n);else for(n in o)u(t,e,r,o[n],i+n)}function c(t){if(!t)return"";var e=decodeURIComponent(t);return"false"!==e&&("true"===e||(0*+e==0?+e:e))}a.flattie=function(t,e,r){var o={};return"object"==typeof t&&u(o,!!r,e||".",t,""),o};var p=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],c(e.shift())):o[r]=c(e.shift());return o}})),h={exports:{}},f=s(Object.freeze({__proto__:null,default:t=>t}));const l=(t,e,r,o)=>{if("length"===r||"prototype"===r)return;const s=Object.getOwnPropertyDescriptor(t,r),n=Object.getOwnPropertyDescriptor(e,r);!d(s,n)&&o||Object.defineProperty(t,r,n)},d=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)},y=(t,e)=>`/* Wrapped ${t}*/\n${e}`,b=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),m=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name");var g=(t,e,{ignoreNonConfigurable:r=!1}={})=>{const{name:o}=t;for(const o of Reflect.ownKeys(e))l(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=y.bind(null,o,e.toString());Object.defineProperty(s,"name",m),Object.defineProperty(t,"toString",{...b,value:s})})(t,e,o),t},w={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:_,composeErrorMessage:E}=w;const R=f,T=g,j=function(t,...e){Object.assign(t,...e),t.description=_(t.message)?t.message(t):t.message,t.message=t.code?E(t.code,t.description):t.description},{isString:x}=w;var v=function(t,e){function r(r){const o=new t,s=x(r)?{message:r}:r;return j(o,e,s),o.stack=R(o.stack),o}return r.prototype=t.prototype,T(r,t),r};const{inherits:C}=w,O=g,q=/[^0-9a-zA-Z_$]/;const P=v,A=function(t){if("string"!=typeof t)throw new TypeError("Expected className to be a string");if(q.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 C(e,Error),O(e,Error),e},S=t=>(e,r)=>{const o=A(e||t.name);return P(o,r)};h.exports=S(Error),h.exports.type=S(TypeError),h.exports.range=S(RangeError),h.exports.eval=S(EvalError),h.exports.syntax=S(SyntaxError),h.exports.reference=S(ReferenceError),h.exports.uri=S(URIError);const U={FREE:"https://api.microlink.io",PRO:"https://pro.microlink.io"},k=t=>null!==t&&"object"==typeof t;var D=({VERSION:t,MicrolinkError:e,isUrlHttp:r,stringify:o,got:s,flatten:n})=>{const i=t=>{if(!k(t))return;const e=n(t);return Object.keys(e).reduce(((t,r)=>({...t,[`data.${r}`]:e[r].toString()})),{})},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,h=k(u)&&!Buffer.isBuffer(u)?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}}})(u,s,p);if("EFATALCLIENT"===h.code&&o++<2)return a(t,r,o);throw e({...h,message:h.message,url:p,statusCode:i,headers:c})}},u=(t,{data:e,apiKey:r,endpoint:s,retry:a,cache:u,...c}={},{responseType:p="json",headers:h,...f}={})=>{const l=!!r;return[`${s||U[l?"PRO":"FREE"]}?${o({url:t,...i(e),...n(c)})}`,{...f,responseType:p,cache:u,retry:a,headers:l?{...h,"x-api-key":r}:{...h}}]},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},L={exports:{}};!function(t,e){t.exports=function(){
|
|
2
2
|
/*! MIT License © Sindre Sorhus */
|
|
3
|
-
const t=t=>null!==t&&"object"==typeof t,e="function"==typeof globalThis.AbortController,r="function"==typeof globalThis.ReadableStream,o="function"==typeof globalThis.FormData,s=(t,e)=>{const r=new globalThis.Headers(t||{}),o=e instanceof globalThis.Headers,s=new globalThis.Headers(e||{});for(const[t,e]of s)o&&"undefined"===e||void 0===e?r.delete(t):r.set(t,e);return r},n=(...e)=>{let r={},o={};for(const i of e){if(Array.isArray(i))Array.isArray(r)||(r=[]),r=[...r,...i];else if(t(i)){for(let[e,o]of Object.entries(i))t(o)&&e in r&&(o=n(r[e],o)),r={...r,[e]:o};t(i.headers)&&(o=s(o,i.headers))}r.headers=o}return r},i=["get","post","put","patch","head","delete"],a={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*"},u=["get","put","head","delete","options","trace"],c=[408,413,429,500,502,503,504],p=[413,429,503],h=Symbol("stop");class f extends Error{constructor(t,e,r){super(t.statusText||String(0===t.status||t.status?t.status:"Unknown response error")),this.name="HTTPError",this.response=t,this.request=e,this.options=r}}class l extends Error{constructor(t){super("Request timed out"),this.name="TimeoutError",this.request=t}}const d=t=>new Promise((e=>setTimeout(e,t))),y=(t,e,r)=>new Promise(((o,s)=>{const n=setTimeout((()=>{e&&e.abort(),s(new l(t))}),r.timeout);r.fetch(t).then(o).catch(s).then((()=>{clearTimeout(n)}))})),b=t=>i.includes(t)?t.toUpperCase():t,m={limit:2,methods:u,statusCodes:c,afterStatusCodes:p},g=(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:p}},w=2147483647;class _{constructor(t,i={}){if(this._retryCount=0,this._input=t,this._options={credentials:this._input.credentials||"same-origin",...i,headers:s(this._input.headers,i.headers),hooks:n({beforeRequest:[],beforeRetry:[],afterResponse:[]},i.hooks),method:b(i.method||this._input.method),prefixUrl:String(i.prefixUrl||""),retry:g(i.retry),throwHttpErrors:!1!==i.throwHttpErrors,timeout:void 0===i.timeout?1e4:i.timeout,fetch:i.fetch||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(e&&(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);!(o&&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}));const u=async()=>{if(this._options.timeout>w)throw new RangeError(`The \`timeout\` option cannot be greater than ${w}`);await d(1);let t=await this._fetch();for(const e of this._options.hooks.afterResponse){const r=await e(this.request,this._options,this._decorateResponse(t.clone()));r instanceof globalThis.Response&&(t=r)}if(this._decorateResponse(t),!t.ok&&this._options.throwHttpErrors)throw new f(t,this.request,this._options);if(this._options.onDownloadProgress){if("function"!=typeof this._options.onDownloadProgress)throw new TypeError("The `onDownloadProgress` option must be a function");if(!r)throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");return this._stream(t.clone(),this._options.onDownloadProgress)}return t},c=this._options.retry.methods.includes(this.request.method.toLowerCase())?this._retry(u):u();for(const[t,e]of Object.entries(a))c[t]=async()=>{this.request.headers.set("accept",this.request.headers.get("accept")||e);const r=(await c).clone();if("json"===t){if(204===r.status)return"";if(i.parseJson)return i.parseJson(await r.text())}return r[t]()};return c}_calculateRetryDelay(t){if(this._retryCount++,this._retryCount<this._options.retry.limit&&!(t instanceof l)){if(t instanceof f){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),w);if(0!==r&&this._retryCount>0){await d(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)}if(this._options.throwHttpErrors)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()):y(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()}}))}}const E=(...e)=>{for(const r of e)if((!t(r)||Array.isArray(r))&&void 0!==r)throw new TypeError("The `options` argument must be an object");return n({},...e)},R=t=>{const e=(e,r)=>new _(e,E(t,r));for(const r of i)e[r]=(e,o)=>new _(e,E(t,o,{method:r}));return e.HTTPError=f,e.TimeoutError=l,e.create=t=>R(E(t)),e.extend=e=>R(E(t,e)),e.stop=h,e};return R()}()}(L);const N=t=>{try{return i.test(new n(t).href)}catch(t){return!1}},{flattie:$}=a,{encode:I}=p,F=h.exports,H=L.exports;return D({MicrolinkError:F("MicrolinkError"),isUrlHttp:N,stringify:I,got:async(t,e)=>{try{void 0===e.timeout&&(e.timeout=!1);const r=await H(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:[...e.headers.entries()].reduce(((t,[e,r])=>({...t,[e]:r})),{}),statusCode:e.status,body:await e.text()}}throw t}},flatten:$,VERSION:"0.10.
|
|
3
|
+
const t=t=>null!==t&&"object"==typeof t,e="function"==typeof globalThis.AbortController,r="function"==typeof globalThis.ReadableStream,o="function"==typeof globalThis.FormData,s=(t,e)=>{const r=new globalThis.Headers(t||{}),o=e instanceof globalThis.Headers,s=new globalThis.Headers(e||{});for(const[t,e]of s)o&&"undefined"===e||void 0===e?r.delete(t):r.set(t,e);return r},n=(...e)=>{let r={},o={};for(const i of e){if(Array.isArray(i))Array.isArray(r)||(r=[]),r=[...r,...i];else if(t(i)){for(let[e,o]of Object.entries(i))t(o)&&e in r&&(o=n(r[e],o)),r={...r,[e]:o};t(i.headers)&&(o=s(o,i.headers))}r.headers=o}return r},i=["get","post","put","patch","head","delete"],a={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*"},u=["get","put","head","delete","options","trace"],c=[408,413,429,500,502,503,504],p=[413,429,503],h=Symbol("stop");class f extends Error{constructor(t,e,r){super(t.statusText||String(0===t.status||t.status?t.status:"Unknown response error")),this.name="HTTPError",this.response=t,this.request=e,this.options=r}}class l extends Error{constructor(t){super("Request timed out"),this.name="TimeoutError",this.request=t}}const d=t=>new Promise((e=>setTimeout(e,t))),y=(t,e,r)=>new Promise(((o,s)=>{const n=setTimeout((()=>{e&&e.abort(),s(new l(t))}),r.timeout);r.fetch(t).then(o).catch(s).then((()=>{clearTimeout(n)}))})),b=t=>i.includes(t)?t.toUpperCase():t,m={limit:2,methods:u,statusCodes:c,afterStatusCodes:p},g=(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:p}},w=2147483647;class _{constructor(t,i={}){if(this._retryCount=0,this._input=t,this._options={credentials:this._input.credentials||"same-origin",...i,headers:s(this._input.headers,i.headers),hooks:n({beforeRequest:[],beforeRetry:[],afterResponse:[]},i.hooks),method:b(i.method||this._input.method),prefixUrl:String(i.prefixUrl||""),retry:g(i.retry),throwHttpErrors:!1!==i.throwHttpErrors,timeout:void 0===i.timeout?1e4:i.timeout,fetch:i.fetch||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(e&&(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);!(o&&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}));const u=async()=>{if(this._options.timeout>w)throw new RangeError(`The \`timeout\` option cannot be greater than ${w}`);await d(1);let t=await this._fetch();for(const e of this._options.hooks.afterResponse){const r=await e(this.request,this._options,this._decorateResponse(t.clone()));r instanceof globalThis.Response&&(t=r)}if(this._decorateResponse(t),!t.ok&&this._options.throwHttpErrors)throw new f(t,this.request,this._options);if(this._options.onDownloadProgress){if("function"!=typeof this._options.onDownloadProgress)throw new TypeError("The `onDownloadProgress` option must be a function");if(!r)throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");return this._stream(t.clone(),this._options.onDownloadProgress)}return t},c=this._options.retry.methods.includes(this.request.method.toLowerCase())?this._retry(u):u();for(const[t,e]of Object.entries(a))c[t]=async()=>{this.request.headers.set("accept",this.request.headers.get("accept")||e);const r=(await c).clone();if("json"===t){if(204===r.status)return"";if(i.parseJson)return i.parseJson(await r.text())}return r[t]()};return c}_calculateRetryDelay(t){if(this._retryCount++,this._retryCount<this._options.retry.limit&&!(t instanceof l)){if(t instanceof f){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),w);if(0!==r&&this._retryCount>0){await d(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)}if(this._options.throwHttpErrors)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()):y(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()}}))}}const E=(...e)=>{for(const r of e)if((!t(r)||Array.isArray(r))&&void 0!==r)throw new TypeError("The `options` argument must be an object");return n({},...e)},R=t=>{const e=(e,r)=>new _(e,E(t,r));for(const r of i)e[r]=(e,o)=>new _(e,E(t,o,{method:r}));return e.HTTPError=f,e.TimeoutError=l,e.create=t=>R(E(t)),e.extend=e=>R(E(t,e)),e.stop=h,e};return R()}()}(L);const N=t=>{try{return i.test(new n(t).href)}catch(t){return!1}},{flattie:$}=a,{encode:I}=p,F=h.exports,H=L.exports;return D({MicrolinkError:F("MicrolinkError"),isUrlHttp:N,stringify:I,got:async(t,e)=>{try{void 0===e.timeout&&(e.timeout=!1);const r=await H(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:[...e.headers.entries()].reduce(((t,[e,r])=>({...t,[e]:r})),{}),statusCode:e.status,body:await e.text()}}throw t}},flatten:$,VERSION:"0.10.6"})}));
|
|
4
4
|
//# sourceMappingURL=mql.min.js.map
|
package/index.d.ts
CHANGED
|
@@ -1,29 +1,39 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
|
|
3
3
|
declare module "@microlink/mql" {
|
|
4
|
-
export type WaitUntilEvent =
|
|
5
|
-
| "load"
|
|
6
|
-
| "domcontentloaded"
|
|
7
|
-
| "networkidle0"
|
|
8
|
-
| "networkidle2";
|
|
4
|
+
export type WaitUntilEvent = "load" | "domcontentloaded" | "networkidle0" | "networkidle2";
|
|
9
5
|
|
|
10
|
-
export type
|
|
11
|
-
background: string;
|
|
12
|
-
browser: "light" | "dark";
|
|
6
|
+
export type AssetOptions = Partial<{
|
|
13
7
|
click: string | string[];
|
|
14
|
-
deviceScaleFactor: number;
|
|
15
8
|
disableAnimations: boolean;
|
|
16
|
-
|
|
17
|
-
fullPage: boolean;
|
|
18
|
-
hasTouch: boolean;
|
|
19
|
-
height: number;
|
|
9
|
+
filename: string;
|
|
20
10
|
hide: string | string[];
|
|
21
|
-
isLandscape: boolean;
|
|
22
|
-
isMobile: boolean;
|
|
23
11
|
scrollTo: string;
|
|
24
|
-
|
|
12
|
+
viewport: object;
|
|
25
13
|
waitFor: number | string;
|
|
14
|
+
waitForSelector: string;
|
|
15
|
+
waitForTimeout: number;
|
|
26
16
|
waitUntil: WaitUntilEvent | WaitUntilEvent[];
|
|
17
|
+
}>;
|
|
18
|
+
|
|
19
|
+
export type ScreenshotOptions = AssetOptions & Partial<{
|
|
20
|
+
background: string;
|
|
21
|
+
browser: "light" | "dark";
|
|
22
|
+
element: string;
|
|
23
|
+
fullPage: boolean;
|
|
24
|
+
omitBackground: object;
|
|
25
|
+
overlay: object;
|
|
26
|
+
type: "jpeg" | "png";
|
|
27
|
+
}>;
|
|
28
|
+
|
|
29
|
+
export type PdfOptions = AssetOptions & Partial<{
|
|
30
|
+
format: string;
|
|
31
|
+
height: number;
|
|
32
|
+
hide: string | string[];
|
|
33
|
+
landscape: string;
|
|
34
|
+
margin: string | object;
|
|
35
|
+
pageRanges: string;
|
|
36
|
+
scale: number;
|
|
27
37
|
width: number;
|
|
28
38
|
}>;
|
|
29
39
|
|
|
@@ -38,10 +48,12 @@ declare module "@microlink/mql" {
|
|
|
38
48
|
| "image"
|
|
39
49
|
| "ip"
|
|
40
50
|
| "lang"
|
|
51
|
+
| "lang"
|
|
41
52
|
| "logo"
|
|
42
53
|
| "number"
|
|
43
54
|
| "object"
|
|
44
55
|
| "publisher"
|
|
56
|
+
| "publisher"
|
|
45
57
|
| "regexp"
|
|
46
58
|
| "string"
|
|
47
59
|
| "title"
|
|
@@ -50,35 +62,38 @@ declare module "@microlink/mql" {
|
|
|
50
62
|
|
|
51
63
|
export type MqlQueryOptions = Partial<{
|
|
52
64
|
attr: string | string[];
|
|
65
|
+
evaluate: string | (() => string)
|
|
53
66
|
selector: string | string[];
|
|
54
67
|
selectorAll: string | string[];
|
|
55
68
|
type: MqlQueryResponseType;
|
|
56
69
|
}>;
|
|
57
70
|
|
|
58
71
|
export interface MqlQuery {
|
|
59
|
-
[field: string]: MqlQueryOptions
|
|
72
|
+
[field: string]: MqlQueryOptions;
|
|
60
73
|
}
|
|
61
74
|
|
|
62
75
|
export type MicrolinkApiOptions = Partial<{
|
|
76
|
+
adblock: boolean;
|
|
63
77
|
animations: boolean;
|
|
64
78
|
audio: boolean;
|
|
65
79
|
click: string | string[];
|
|
66
|
-
colorScheme: "dark" | "light";
|
|
67
80
|
codeScheme: string;
|
|
81
|
+
colorScheme: "dark" | "light";
|
|
68
82
|
data: MqlQuery;
|
|
69
83
|
device: string;
|
|
70
84
|
embed: string;
|
|
71
85
|
filter: string;
|
|
72
86
|
force: boolean;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
iframe: boolean |
|
|
76
|
-
insights: boolean | object
|
|
87
|
+
function: string;
|
|
88
|
+
headers: Record<string, unknown>;
|
|
89
|
+
iframe: boolean | Record<"maxwidth" | "maxheight", number>;
|
|
90
|
+
insights: boolean | Partial<{ lighthouse: boolean | object, technologies: boolean }>;
|
|
77
91
|
javascript: boolean;
|
|
78
|
-
|
|
92
|
+
mediaType: string;
|
|
79
93
|
meta: boolean;
|
|
80
94
|
modules: string | string[];
|
|
81
95
|
palette: boolean;
|
|
96
|
+
pdf: boolean | PdfOptions;
|
|
82
97
|
ping: boolean | object;
|
|
83
98
|
prerender: boolean | "auto";
|
|
84
99
|
proxy: string;
|
|
@@ -87,15 +102,12 @@ declare module "@microlink/mql" {
|
|
|
87
102
|
screenshot: boolean | ScreenshotOptions;
|
|
88
103
|
scripts: string | string[];
|
|
89
104
|
scroll: string;
|
|
105
|
+
staleTtl: string | number;
|
|
90
106
|
styles: string | string[];
|
|
91
107
|
timeout: number;
|
|
92
108
|
ttl: string | number;
|
|
93
109
|
url: string;
|
|
94
110
|
video: boolean;
|
|
95
|
-
viewport: object;
|
|
96
|
-
waitForSelector: string;
|
|
97
|
-
waitForTimeout: number;
|
|
98
|
-
waitUntil: string | string[];
|
|
99
111
|
}>;
|
|
100
112
|
|
|
101
113
|
export type MqlOptions = Partial<{
|
|
@@ -106,33 +118,83 @@ declare module "@microlink/mql" {
|
|
|
106
118
|
timeout: number;
|
|
107
119
|
}>;
|
|
108
120
|
|
|
109
|
-
export interface
|
|
110
|
-
width: number;
|
|
111
|
-
height: number;
|
|
112
|
-
type: string;
|
|
121
|
+
export interface BaseMediaInfo {
|
|
113
122
|
url: string;
|
|
123
|
+
// file type extension.
|
|
124
|
+
type: string;
|
|
125
|
+
// file size in bytes.
|
|
114
126
|
size: number;
|
|
127
|
+
// file size in a human readable format.
|
|
115
128
|
size_pretty: string;
|
|
116
129
|
}
|
|
117
130
|
|
|
118
|
-
export interface PlayableMediaInfo
|
|
131
|
+
export interface PlayableMediaInfo {
|
|
132
|
+
// source duration in seconds.
|
|
119
133
|
duration: number;
|
|
134
|
+
// source duration in a human readable format.
|
|
120
135
|
duration_pretty: string;
|
|
121
136
|
}
|
|
122
137
|
|
|
138
|
+
export interface VisualMediaInfo {
|
|
139
|
+
// file width in pixels.
|
|
140
|
+
width: number;
|
|
141
|
+
// file height in pixels.
|
|
142
|
+
height: number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface AudioInfo extends BaseMediaInfo, PlayableMediaInfo {
|
|
146
|
+
// TODO make this a complete type
|
|
147
|
+
type: "mp3" | string;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface ImageInfo extends BaseMediaInfo, VisualMediaInfo {
|
|
151
|
+
// TODO make this a complete type
|
|
152
|
+
type: "png" | "jpg" | string;
|
|
153
|
+
palette: string[];
|
|
154
|
+
background_color: string;
|
|
155
|
+
color: string;
|
|
156
|
+
alternative_color: string;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface VideoInfo extends BaseMediaInfo, PlayableMediaInfo, VisualMediaInfo {
|
|
160
|
+
// TODO make this a complete type
|
|
161
|
+
type: "mp4" | string;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface IframeInfo {
|
|
165
|
+
html: string;
|
|
166
|
+
scripts: Record<string, unknown>;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export type MqlFunctionResult = {
|
|
170
|
+
isFulfilled: boolean;
|
|
171
|
+
isRejected: boolean;
|
|
172
|
+
value: any;
|
|
173
|
+
};
|
|
174
|
+
|
|
123
175
|
export type MqlResponseData = Partial<{
|
|
124
|
-
author
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
publisher
|
|
129
|
-
|
|
176
|
+
// A human-readable representation of the author's name.
|
|
177
|
+
author: string | null;
|
|
178
|
+
// An ISO 8601 representation of the date the article was published.
|
|
179
|
+
date: string | null;
|
|
180
|
+
// The publisher's chosen description of the article.
|
|
181
|
+
description: string | null;
|
|
182
|
+
// An ISO 639-1 representation of the url content language.
|
|
183
|
+
lang: string | null;
|
|
184
|
+
// An image URL that best represents the publisher brand.
|
|
185
|
+
logo: ImageInfo | null;
|
|
186
|
+
// A human-readable representation of the publisher's name.
|
|
187
|
+
publisher: string | null;
|
|
188
|
+
// The publisher's chosen title of the article.
|
|
189
|
+
title: string | null;
|
|
190
|
+
// The URL of the article.
|
|
130
191
|
url: string;
|
|
131
|
-
image: ImageInfo;
|
|
132
|
-
screenshot: ImageInfo;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
192
|
+
image: ImageInfo | null;
|
|
193
|
+
screenshot: ImageInfo | null;
|
|
194
|
+
video: VideoInfo | null;
|
|
195
|
+
audio: AudioInfo | null;
|
|
196
|
+
iframe: IframeInfo | null;
|
|
197
|
+
function: MqlFunctionResult;
|
|
136
198
|
}>;
|
|
137
199
|
|
|
138
200
|
export type MqlStatus = "success" | "fail";
|
|
@@ -140,14 +202,29 @@ declare module "@microlink/mql" {
|
|
|
140
202
|
export interface MqlResponse {
|
|
141
203
|
status: MqlStatus;
|
|
142
204
|
data: MqlResponseData;
|
|
143
|
-
|
|
205
|
+
// TODO: The response object depends on the context
|
|
206
|
+
// - Under Node.js context
|
|
207
|
+
// import { ServerResponse} from 'http';
|
|
208
|
+
// - Under browser, It will be global `Response`
|
|
209
|
+
response: {
|
|
210
|
+
headers: { [key: string]: string };
|
|
211
|
+
body?: {
|
|
212
|
+
statusCode?: number;
|
|
213
|
+
};
|
|
214
|
+
};
|
|
144
215
|
}
|
|
145
216
|
|
|
146
217
|
declare function mql(
|
|
147
218
|
url: string,
|
|
148
219
|
opts?: MqlOptions & MicrolinkApiOptions,
|
|
149
|
-
//
|
|
150
|
-
//
|
|
220
|
+
// TODO: gotOpts could be different depends the environment where the library is being used
|
|
221
|
+
// - Under Node.js context, types are from `got`
|
|
222
|
+
// https://github.com/microlinkhq/mql/blob/fbb55f4758495fa42d35822867763f95ac5ae960/src/node.js#L5
|
|
223
|
+
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/90a4ec8f0a9c76f33fdeeef0118f26c5d3df5cfa/types/got/index.d.ts#L212
|
|
224
|
+
//
|
|
225
|
+
// - Under brower context, types are from `ky`
|
|
226
|
+
// https://github.com/microlinkhq/mql/blob/fbb55f4758495fa42d35822867763f95ac5ae960/src/browser.js#L9
|
|
227
|
+
// https://github.com/sindresorhus/ky/blob/main/source/types/options.ts#L30
|
|
151
228
|
gotOpts?: object
|
|
152
229
|
): Promise<MqlResponse>;
|
|
153
230
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@microlink/mql",
|
|
3
3
|
"description": "Microlink Query Language. The official HTTP client to interact with Microlink API for Node.js, browsers & Deno.",
|
|
4
4
|
"homepage": "https://nicedoc.io/microlinkhq/mql",
|
|
5
|
-
"version": "0.10.
|
|
5
|
+
"version": "0.10.6",
|
|
6
6
|
"browser": "src/browser.js",
|
|
7
7
|
"main": "src/node.js",
|
|
8
8
|
"author": {
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
{
|
|
19
19
|
"name": "ndom91",
|
|
20
20
|
"email": "yo@ndo.dev"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "Gabe O'Leary",
|
|
24
|
+
"email": "oleary.gabe@gmail.com"
|
|
21
25
|
}
|
|
22
26
|
],
|
|
23
27
|
"repository": {
|
|
@@ -58,8 +62,8 @@
|
|
|
58
62
|
"git-authors-cli": "latest",
|
|
59
63
|
"git-dirty": "latest",
|
|
60
64
|
"ky": "latest",
|
|
61
|
-
"lint-staged": "latest",
|
|
62
65
|
"meow": "latest",
|
|
66
|
+
"nano-staged": "latest",
|
|
63
67
|
"node-fetch": "2",
|
|
64
68
|
"npm-check-updates": "latest",
|
|
65
69
|
"nyc": "latest",
|
|
@@ -121,20 +125,20 @@
|
|
|
121
125
|
"@commitlint/config-conventional"
|
|
122
126
|
]
|
|
123
127
|
},
|
|
124
|
-
"
|
|
125
|
-
"package.json": [
|
|
126
|
-
"finepack --sort-ignore-object-at ava"
|
|
127
|
-
],
|
|
128
|
+
"nano-staged": {
|
|
128
129
|
"*.js,!*.min.js,": [
|
|
129
130
|
"prettier-standard"
|
|
130
131
|
],
|
|
131
132
|
"*.md": [
|
|
132
133
|
"standard-markdown"
|
|
134
|
+
],
|
|
135
|
+
"package.json": [
|
|
136
|
+
"finepack --sort-ignore-object-at ava"
|
|
133
137
|
]
|
|
134
138
|
},
|
|
135
139
|
"simple-git-hooks": {
|
|
136
140
|
"commit-msg": "npx commitlint --edit",
|
|
137
|
-
"pre-commit": "npx
|
|
141
|
+
"pre-commit": "npx nano-staged"
|
|
138
142
|
},
|
|
139
143
|
"standard": {
|
|
140
144
|
"ignore": [
|