@microlink/mql 0.11.0-1 → 0.11.0-10

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.
@@ -0,0 +1,2 @@
1
+ "undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}const e=/^https?:\/\//i;var r={};function s(t,e,r,o,n){var i,a=n?n+r:n;if(null==o)e&&(t[n]=o);else if("object"!=typeof o)t[n]=o;else if(Array.isArray(o))for(i=0;i<o.length;i++)s(t,e,r,o[i],a+i);else for(i in o)s(t,e,r,o[i],a+i)}r.flattie=function(t,e,r){var o={};return"object"==typeof t&&s(o,!!r,e||".",t,""),o};const o={FREE:"https://api.microlink.io/",PRO:"https://pro.microlink.io/"},n=t=>null!==t&&"object"==typeof t;var i=({VERSION:t,MicrolinkError:e,urlHttp:r,got:s,flatten:i})=>{const a=t=>{if(!n(t))return;const e=i(t);return Object.keys(e).reduce(((t,r)=>(t[`data.${r}`]=e[r].toString(),t)),{})},u=async(t,r={})=>{try{const e=await s(t,r);return"buffer"===r.responseType?{body:e.body,response:e}:{...e.body,response:e}}catch(r){const{response:s={}}=r,{statusCode:i,body:a,headers:u={},url:l=t}=s,h=null!=(o=a)&&null!=o.constructor&&"function"==typeof o.constructor.isBuffer&&o.constructor.isBuffer(o),c=n(a)&&!h?a:((t,e,r)=>{try{return JSON.parse(t)}catch(s){const o=t||e.message;return{status:"error",data:{url:o},more:"https://microlink.io/efatalclient",code:"EFATALCLIENT",message:o,url:r}}})(h?a.toString():a,r,l);throw new e({...c,message:c.message,url:l,statusCode:i,headers:u})}var o},l=(t,{data:e,apiKey:r,endpoint:s,retry:n,cache:u,...l}={},{responseType:h="json",headers:c,...p}={})=>{const f=!!r;return[`${s||o[f?"PRO":"FREE"]}?${new URLSearchParams({url:t,...a(e),...i(l)}).toString()}`,{...p,responseType:h,cache:u,retry:n,headers:f?{...c,"x-api-key":r}:{...c}}]},h=t=>async(s,o,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})}})(s);const[i,a]=l(s,o,{...t,...n});return u(i,a)},c=h();return c.MicrolinkError=e,c.getApiUrl=l,c.fetchFromApi=u,c.mapRules=a,c.version=t,c.stream=s.stream,c.buffer=h({responseType:"buffer"}),c},a={exports:{}};!function(t){class e extends Error{constructor(t,e,r){const s=`${t.status||0===t.status?t.status:""} ${t.statusText||""}`.trim();super("Request failed with "+(s?`status code ${s}`:"an unknown error")),Object.defineProperty(this,"response",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name="HTTPError",this.response=t,this.request=e,this.options=r}}class r extends Error{constructor(t){super("Request timed out"),Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name="TimeoutError",this.request=t}}const s=t=>null!==t&&"object"==typeof t,o=(...t)=>{for(const e of t)if((!s(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),s=e instanceof globalThis.Headers,o=new globalThis.Headers(e);for(const[t,e]of o.entries())s&&"undefined"===e||void 0===e?r.delete(t):r.set(t,e);return r},i=(...t)=>{let e={},r={};for(const o of t)if(Array.isArray(o))Array.isArray(e)||(e=[]),e=[...e,...o];else if(s(o)){for(let[t,r]of Object.entries(o))s(r)&&t in e&&(r=i(e[t],r)),e={...e,[t]:r};s(o.headers)&&(r=n(r,o.headers),e.headers=r)}return e},a=(()=>{let t=!1,e=!1;const r="function"==typeof globalThis.ReadableStream,s="function"==typeof globalThis.Request;return r&&s&&(e=new globalThis.Request("https://empty.invalid",{body:new globalThis.ReadableStream,method:"POST",get duplex(){return t=!0,"half"}}).headers.has("Content-Type")),t&&!e})(),u="function"==typeof globalThis.AbortController,l="function"==typeof globalThis.ReadableStream,h="function"==typeof globalThis.FormData,c=["get","post","put","patch","head","delete"],p={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*"},f=2147483647,d=Symbol("stop"),y=t=>c.includes(t)?t.toUpperCase():t,b=[413,429,503],m={limit:2,methods:["get","put","head","delete","options","trace"],statusCodes:[408,413,429,500,502,503,504],afterStatusCodes:b,maxRetryAfter:Number.POSITIVE_INFINITY,backoffLimit:Number.POSITIVE_INFINITY},w=(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:b}};async function _(t,e,s){return new Promise(((o,n)=>{const i=setTimeout((()=>{e&&e.abort(),n(new r(t))}),s.timeout);s.fetch(t).then(o).catch(n).then((()=>{clearTimeout(i)}))}))}async function g(t,{signal:e}){return new Promise(((r,s)=>{function o(){clearTimeout(n),s(e.reason)}e&&(e.throwIfAborted(),e.addEventListener("abort",o,{once:!0}));const n=setTimeout((()=>{e?.removeEventListener("abort",o),r()}),t)}))}class T{static create(t,r){const s=new T(t,r),o=async()=>{if("number"==typeof s._options.timeout&&s._options.timeout>f)throw new RangeError(`The \`timeout\` option cannot be greater than ${f}`);await Promise.resolve();let t=await s._fetch();for(const e of s._options.hooks.afterResponse){const r=await e(s.request,s._options,s._decorateResponse(t.clone()));r instanceof globalThis.Response&&(t=r)}if(s._decorateResponse(t),!t.ok&&s._options.throwHttpErrors){let r=new e(t,s.request,s._options);for(const t of s._options.hooks.beforeError)r=await t(r);throw r}if(s._options.onDownloadProgress){if("function"!=typeof s._options.onDownloadProgress)throw new TypeError("The `onDownloadProgress` option must be a function");if(!l)throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");return s._stream(t.clone(),s._options.onDownloadProgress)}return t},n=s._options.retry.methods.includes(s.request.method.toLowerCase())?s._retry(o):o();for(const[t,e]of Object.entries(p))n[t]=async()=>{s.request.headers.set("accept",s.request.headers.get("accept")||e);const o=(await n).clone();if("json"===t){if(204===o.status)return"";if(0===(await o.clone().arrayBuffer()).byteLength)return"";if(r.parseJson)return r.parseJson(await o.text())}return o[t]()};return n}constructor(t,e={}){if(Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"abortController",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_retryCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_input",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._input=t,this._options={credentials:this._input.credentials||"same-origin",...e,headers:n(this._input.headers,e.headers),hooks:i({beforeRequest:[],beforeRetry:[],beforeError:[],afterResponse:[]},e.hooks),method:y(e.method??this._input.method),prefixUrl:String(e.prefixUrl||""),retry:w(e.retry),throwHttpErrors:!1!==e.throwHttpErrors,timeout:e.timeout??1e4,fetch:e.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(u){if(this.abortController=new globalThis.AbortController,this._options.signal){const t=this._options.signal;this._options.signal.addEventListener("abort",(()=>{this.abortController.abort(t.reason)}))}this._options.signal=this.abortController.signal}if(a&&(this._options.duplex="half"),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);!(h&&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",this._options.headers.get("content-type")??"application/json"),this.request=new globalThis.Request(this.request,{body:this._options.body}))}_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}const r=.3;return Math.min(this._options.retry.backoffLimit,r*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 g(r,{signal:this._options.signal});for(const t of this._options.hooks.beforeRetry)if(await t({request:this.request,options:this._options,error:e,retryCount:this._retryCount})===d)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()):_(this.request.clone(),this.abortController,this._options)}_stream(t,e){const r=Number(t.headers.get("content-length"))||0;let s=0;return 204===t.status?(e&&e({percent:1,totalBytes:r,transferredBytes:s},new Uint8Array),new globalThis.Response(null,{status:t.status,statusText:t.statusText,headers:t.headers})):new globalThis.Response(new globalThis.ReadableStream({async start(o){const n=t.body.getReader();async function i(){const{done:t,value:a}=await n.read();t?o.close():(e&&(s+=a.byteLength,e({percent:0===r?0:s/r,transferredBytes:s,totalBytes:r},a)),o.enqueue(a),await i())}e&&e({percent:0,transferredBytes:0,totalBytes:r},new Uint8Array),await i()}}),{status:t.status,statusText:t.statusText,headers:t.headers})}}
2
+ /*! MIT License © Sindre Sorhus */const R=t=>{const e=(e,r)=>T.create(e,o(t,r));for(const r of c)e[r]=(e,s)=>T.create(e,o(t,s,{method:r}));return e.create=t=>R(o(t)),e.extend=e=>R(o(t,e)),e.stop=d,e},v=R();t.HTTPError=e,t.TimeoutError=r,t.default=v,Object.defineProperty(t,"__esModule",{value:!0})}(a.exports);var u=a.exports;const l=t=>{try{const{href:r}=new URL(t);return e.test(r)&&r}catch(t){return!1}},{flattie:h}=r,c=i,{default:p}=u;class f extends Error{constructor(t){super(),this.name="MicrolinkError",Object.assign(this,t),this.description=this.message,this.message=this.code?`${this.code}, ${this.description}`:this.description}}var d=t(c({MicrolinkError:f,urlHttp:l,got:async(t,e)=>{try{e.retry>0&&(e.retry=e.retry+1),void 0===e.timeout&&(e.timeout=!1);const r=await p(t,e),s=await r.json(),{headers:o,status:n}=r;return{url:r.url,body:s,headers:o,statusCode:n}}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.39"}));export{d as default};
@@ -1,4 +1,5 @@
1
1
  {
2
- "main": "../src/lightweight.js",
2
+ "main": "index.js",
3
+ "type": "module",
3
4
  "types": "index.d.ts"
4
5
  }
package/package.json CHANGED
@@ -2,19 +2,15 @@
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://microlink.io/mql",
5
- "version": "0.11.0-1",
6
- "types": "index.d.ts",
5
+ "version": "0.11.0-10",
6
+ "types": "lightweight/index.d.ts",
7
7
  "browser": "src/lightweight.js",
8
8
  "umd:main": "dist/mql.js",
9
9
  "unpkg": "dist/mql.js",
10
10
  "exports": {
11
11
  ".": {
12
- "import": "./src/node.mjs",
12
+ "import": "./lightweight/index.js",
13
13
  "require": "./src/node.js"
14
- },
15
- "./lightweight": {
16
- "import": "./src/lightweight.mjs",
17
- "require": "./src/lightweight.js"
18
14
  }
19
15
  },
20
16
  "author": {
@@ -57,33 +53,30 @@
57
53
  "dependencies": {
58
54
  "flattie": "~1.1.0",
59
55
  "got": "~11.8.6",
60
- "ky": "~1.0.0",
61
- "url-http": "^1.1.0",
56
+ "url-http": "~1.1.0",
62
57
  "whoops": "~4.1.1"
63
58
  },
64
59
  "devDependencies": {
65
- "@chialab/cjs-to-esm": "~0.17.11",
66
60
  "@commitlint/cli": "latest",
67
61
  "@commitlint/config-conventional": "latest",
68
62
  "@ksmithut/prettier-standard": "latest",
69
63
  "@rollup/plugin-commonjs": "latest",
70
- "@rollup/plugin-json": "~6.0.0",
71
64
  "@rollup/plugin-node-resolve": "latest",
72
65
  "@rollup/plugin-replace": "latest",
73
66
  "@rollup/plugin-terser": "latest",
74
- "@rollup/plugin-virtual": "~3.0.1",
75
67
  "async-listen": "latest",
76
- "ava": "3",
68
+ "ava": "latest",
77
69
  "c8": "latest",
78
70
  "ci-publish": "latest",
79
71
  "conventional-github-releaser": "latest",
80
72
  "esm": "latest",
73
+ "execa": "~8.0.1",
81
74
  "git-authors-cli": "latest",
75
+ "ky": "latest",
82
76
  "nano-staged": "latest",
83
77
  "npm-check-updates": "latest",
84
78
  "prettier-standard": "latest",
85
79
  "rollup": "latest",
86
- "rollup-plugin-cjs-es": "~2.0.0",
87
80
  "rollup-plugin-filesize": "latest",
88
81
  "rollup-plugin-magic-string": "~1.0.4",
89
82
  "rollup-plugin-rewrite": "~0.0.4",
@@ -99,20 +92,17 @@
99
92
  "node": ">= 12"
100
93
  },
101
94
  "files": [
102
- "dist",
103
- "index.d.ts",
104
95
  "lightweight",
105
- "src"
96
+ "src/factory.js",
97
+ "src/index.d.ts",
98
+ "src/ky.js",
99
+ "src/node.js"
106
100
  ],
107
101
  "license": "MIT",
108
102
  "ava": {
109
103
  "files": [
110
104
  "test/**/*",
111
- "!test/browser-globals.js",
112
- "!test/clients.js"
113
- ],
114
- "require": [
115
- "esm"
105
+ "!test/clients.mjs"
116
106
  ],
117
107
  "timeout": "1m"
118
108
  },
@@ -140,6 +130,7 @@
140
130
  "standard": {
141
131
  "ignore": [
142
132
  "dist",
133
+ "lightweight/index.js",
143
134
  "src/ky.js"
144
135
  ]
145
136
  },
@@ -155,7 +146,7 @@
155
146
  "build": "rollup -c rollup.config.js --bundleConfigAsCjs",
156
147
  "build:kys": "[ -f src/ky.js ] || rollup node_modules/ky/distribution/index.js --format=umd --name=ky --exports=named --file=src/ky.js",
157
148
  "clean": "rm -rf node_modules",
158
- "clean:build": "rm -rf dist",
149
+ "clean:build": "rm -rf dist lightweight/index.js",
159
150
  "contributors": "(npx git-authors-cli && npx finepack --sort-ignore-object-at ava && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
160
151
  "dev": "npm run build -- -w",
161
152
  "lint": "standard && tsd",
@@ -51,5 +51,5 @@ module.exports = factory({
51
51
  urlHttp,
52
52
  got,
53
53
  flatten,
54
- VERSION: require('../package.json').version
54
+ VERSION: '__MQL_VERSION__'
55
55
  })