@microlink/mql 0.11.0-0 → 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-0",
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": "./dist/lightweight.mjs",
17
- "require": "./src/lightweight.js"
18
14
  }
19
15
  },
20
16
  "author": {
@@ -55,34 +51,32 @@
55
51
  "query"
56
52
  ],
57
53
  "dependencies": {
58
- "ky": "~1.0.0",
59
54
  "flattie": "~1.1.0",
60
55
  "got": "~11.8.6",
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
67
  "async-listen": "latest",
75
- "ava": "3",
68
+ "ava": "latest",
76
69
  "c8": "latest",
77
70
  "ci-publish": "latest",
78
71
  "conventional-github-releaser": "latest",
79
72
  "esm": "latest",
73
+ "execa": "~8.0.1",
80
74
  "git-authors-cli": "latest",
75
+ "ky": "latest",
81
76
  "nano-staged": "latest",
82
77
  "npm-check-updates": "latest",
83
78
  "prettier-standard": "latest",
84
79
  "rollup": "latest",
85
- "rollup-plugin-cjs-es": "~2.0.0",
86
80
  "rollup-plugin-filesize": "latest",
87
81
  "rollup-plugin-magic-string": "~1.0.4",
88
82
  "rollup-plugin-rewrite": "~0.0.4",
@@ -98,20 +92,17 @@
98
92
  "node": ">= 12"
99
93
  },
100
94
  "files": [
101
- "dist",
102
- "index.d.ts",
103
95
  "lightweight",
104
- "src"
96
+ "src/factory.js",
97
+ "src/index.d.ts",
98
+ "src/ky.js",
99
+ "src/node.js"
105
100
  ],
106
101
  "license": "MIT",
107
102
  "ava": {
108
103
  "files": [
109
104
  "test/**/*",
110
- "!test/browser-globals.js",
111
- "!test/clients.js"
112
- ],
113
- "require": [
114
- "esm"
105
+ "!test/clients.mjs"
115
106
  ],
116
107
  "timeout": "1m"
117
108
  },
@@ -139,6 +130,7 @@
139
130
  "standard": {
140
131
  "ignore": [
141
132
  "dist",
133
+ "lightweight/index.js",
142
134
  "src/ky.js"
143
135
  ]
144
136
  },
@@ -154,7 +146,7 @@
154
146
  "build": "rollup -c rollup.config.js --bundleConfigAsCjs",
155
147
  "build:kys": "[ -f src/ky.js ] || rollup node_modules/ky/distribution/index.js --format=umd --name=ky --exports=named --file=src/ky.js",
156
148
  "clean": "rm -rf node_modules",
157
- "clean:build": "rm -rf dist",
149
+ "clean:build": "rm -rf dist lightweight/index.js",
158
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",
159
151
  "dev": "npm run build -- -w",
160
152
  "lint": "standard && tsd",
@@ -4,7 +4,7 @@ const urlHttp = require('url-http/lightweight')
4
4
  const { flattie: flatten } = require('flattie')
5
5
 
6
6
  const factory = require('./factory')
7
- const { default: ky } = require('ky')
7
+ const { default: ky } = require('./ky')
8
8
 
9
9
  class MicrolinkError extends Error {
10
10
  constructor (props) {
package/dist/mql.js DELETED
@@ -1,777 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
- typeof define === 'function' && define.amd ? define(factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.mql = factory());
5
- })(this, (function () { 'use strict';
6
-
7
- function getDefaultExportFromCjs (x) {
8
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
9
- }
10
-
11
- function getAugmentedNamespace(n) {
12
- if (n.__esModule) return n;
13
- var f = n.default;
14
- if (typeof f == "function") {
15
- var a = function a () {
16
- if (this instanceof a) {
17
- return Reflect.construct(f, arguments, this.constructor);
18
- }
19
- return f.apply(this, arguments);
20
- };
21
- a.prototype = f.prototype;
22
- } else a = {};
23
- Object.defineProperty(a, '__esModule', {value: true});
24
- Object.keys(n).forEach(function (k) {
25
- var d = Object.getOwnPropertyDescriptor(n, k);
26
- Object.defineProperty(a, k, d.get ? d : {
27
- enumerable: true,
28
- get: function () {
29
- return n[k];
30
- }
31
- });
32
- });
33
- return a;
34
- }
35
-
36
- const REGEX_HTTP_PROTOCOL = /^https?:\/\//i;
37
-
38
- var lightweight$2 = url => {
39
- try {
40
- const { href } = new URL(url);
41
- return REGEX_HTTP_PROTOCOL.test(href) && href
42
- } catch (err) {
43
- return false
44
- }
45
- };
46
-
47
- var dist = {};
48
-
49
- function iter(output, nullish, sep, val, key) {
50
- var k, pfx = key ? (key + sep) : key;
51
-
52
- if (val == null) {
53
- if (nullish) output[key] = val;
54
- } else if (typeof val != 'object') {
55
- output[key] = val;
56
- } else if (Array.isArray(val)) {
57
- for (k=0; k < val.length; k++) {
58
- iter(output, nullish, sep, val[k], pfx + k);
59
- }
60
- } else {
61
- for (k in val) {
62
- iter(output, nullish, sep, val[k], pfx + k);
63
- }
64
- }
65
- }
66
-
67
- function flattie(input, glue, toNull) {
68
- var output = {};
69
- if (typeof input == 'object') {
70
- iter(output, !!toNull, glue || '.', input, '');
71
- }
72
- return output;
73
- }
74
-
75
- dist.flattie = flattie;
76
-
77
- const ENDPOINT = {
78
- FREE: 'https://api.microlink.io/',
79
- PRO: 'https://pro.microlink.io/'
80
- };
81
-
82
- const isObject$1 = input => input !== null && typeof input === 'object';
83
-
84
- const isBuffer = input =>
85
- input != null &&
86
- input.constructor != null &&
87
- typeof input.constructor.isBuffer === 'function' &&
88
- input.constructor.isBuffer(input);
89
-
90
- const parseBody = (input, error, url) => {
91
- try {
92
- return JSON.parse(input)
93
- } catch (_) {
94
- const message = input || error.message;
95
-
96
- return {
97
- status: 'error',
98
- data: { url: message },
99
- more: 'https://microlink.io/efatalclient',
100
- code: 'EFATALCLIENT',
101
- message,
102
- url
103
- }
104
- }
105
- };
106
-
107
- const factory$1 = ({ VERSION, MicrolinkError, urlHttp, got, flatten }) => {
108
- const assertUrl = (url = '') => {
109
- if (!urlHttp(url)) {
110
- const message = `The \`url\` as \`${url}\` is not valid. Ensure it has protocol (http or https) and hostname.`;
111
- throw new MicrolinkError({
112
- status: 'fail',
113
- data: { url: message },
114
- more: 'https://microlink.io/docs/api/api-parameters/url',
115
- code: 'EINVALURLCLIENT',
116
- message,
117
- url
118
- })
119
- }
120
- };
121
-
122
- const mapRules = rules => {
123
- if (!isObject$1(rules)) return
124
- const flatRules = flatten(rules);
125
- return Object.keys(flatRules).reduce((acc, key) => {
126
- acc[`data.${key}`] = flatRules[key].toString();
127
- return acc
128
- }, {})
129
- };
130
-
131
- const fetchFromApi = async (apiUrl, opts = {}) => {
132
- try {
133
- const response = await got(apiUrl, opts);
134
- return opts.responseType === 'buffer'
135
- ? { body: response.body, response }
136
- : { ...response.body, response }
137
- } catch (err) {
138
- const { response = {} } = err;
139
- const {
140
- statusCode,
141
- body: rawBody,
142
- headers = {},
143
- url: uri = apiUrl
144
- } = response;
145
- const isBodyBuffer = isBuffer(rawBody);
146
-
147
- const body =
148
- isObject$1(rawBody) && !isBodyBuffer
149
- ? rawBody
150
- : parseBody(isBodyBuffer ? rawBody.toString() : rawBody, err, uri);
151
-
152
- throw new MicrolinkError({
153
- ...body,
154
- message: body.message,
155
- url: uri,
156
- statusCode,
157
- headers
158
- })
159
- }
160
- };
161
-
162
- const getApiUrl = (
163
- url,
164
- { data, apiKey, endpoint, retry, cache, ...opts } = {},
165
- { responseType = 'json', headers: gotHeaders, ...gotOpts } = {}
166
- ) => {
167
- const isPro = !!apiKey;
168
- const apiEndpoint = endpoint || ENDPOINT[isPro ? 'PRO' : 'FREE'];
169
-
170
- const apiUrl = `${apiEndpoint}?${new URLSearchParams({
171
- url,
172
- ...mapRules(data),
173
- ...flatten(opts)
174
- }).toString()}`;
175
-
176
- const headers = isPro
177
- ? { ...gotHeaders, 'x-api-key': apiKey }
178
- : { ...gotHeaders };
179
- return [apiUrl, { ...gotOpts, responseType, cache, retry, headers }]
180
- };
181
-
182
- const createMql = defaultOpts => async (url, opts, gotOpts) => {
183
- assertUrl(url);
184
- const [apiUrl, fetchOpts] = getApiUrl(url, opts, {
185
- ...defaultOpts,
186
- ...gotOpts
187
- });
188
- return fetchFromApi(apiUrl, fetchOpts)
189
- };
190
-
191
- const mql = createMql();
192
- mql.MicrolinkError = MicrolinkError;
193
- mql.getApiUrl = getApiUrl;
194
- mql.fetchFromApi = fetchFromApi;
195
- mql.mapRules = mapRules;
196
- mql.version = VERSION;
197
- mql.stream = got.stream;
198
- mql.buffer = createMql({ responseType: 'buffer' });
199
-
200
- return mql
201
- };
202
-
203
- var factory_1 = factory$1;
204
-
205
- // eslint-lint-disable-next-line @typescript-eslint/naming-convention
206
- class HTTPError extends Error {
207
- constructor(response, request, options) {
208
- const code = (response.status || response.status === 0) ? response.status : '';
209
- const title = response.statusText || '';
210
- const status = `${code} ${title}`.trim();
211
- const reason = status ? `status code ${status}` : 'an unknown error';
212
- super(`Request failed with ${reason}`);
213
- Object.defineProperty(this, "response", {
214
- enumerable: true,
215
- configurable: true,
216
- writable: true,
217
- value: void 0
218
- });
219
- Object.defineProperty(this, "request", {
220
- enumerable: true,
221
- configurable: true,
222
- writable: true,
223
- value: void 0
224
- });
225
- Object.defineProperty(this, "options", {
226
- enumerable: true,
227
- configurable: true,
228
- writable: true,
229
- value: void 0
230
- });
231
- this.name = 'HTTPError';
232
- this.response = response;
233
- this.request = request;
234
- this.options = options;
235
- }
236
- }
237
-
238
- class TimeoutError extends Error {
239
- constructor(request) {
240
- super('Request timed out');
241
- Object.defineProperty(this, "request", {
242
- enumerable: true,
243
- configurable: true,
244
- writable: true,
245
- value: void 0
246
- });
247
- this.name = 'TimeoutError';
248
- this.request = request;
249
- }
250
- }
251
-
252
- // eslint-disable-next-line @typescript-eslint/ban-types
253
- const isObject = (value) => value !== null && typeof value === 'object';
254
-
255
- const validateAndMerge = (...sources) => {
256
- for (const source of sources) {
257
- if ((!isObject(source) || Array.isArray(source)) && source !== undefined) {
258
- throw new TypeError('The `options` argument must be an object');
259
- }
260
- }
261
- return deepMerge({}, ...sources);
262
- };
263
- const mergeHeaders = (source1 = {}, source2 = {}) => {
264
- const result = new globalThis.Headers(source1);
265
- const isHeadersInstance = source2 instanceof globalThis.Headers;
266
- const source = new globalThis.Headers(source2);
267
- for (const [key, value] of source.entries()) {
268
- if ((isHeadersInstance && value === 'undefined') || value === undefined) {
269
- result.delete(key);
270
- }
271
- else {
272
- result.set(key, value);
273
- }
274
- }
275
- return result;
276
- };
277
- // TODO: Make this strongly-typed (no `any`).
278
- const deepMerge = (...sources) => {
279
- let returnValue = {};
280
- let headers = {};
281
- for (const source of sources) {
282
- if (Array.isArray(source)) {
283
- if (!Array.isArray(returnValue)) {
284
- returnValue = [];
285
- }
286
- returnValue = [...returnValue, ...source];
287
- }
288
- else if (isObject(source)) {
289
- for (let [key, value] of Object.entries(source)) {
290
- if (isObject(value) && key in returnValue) {
291
- value = deepMerge(returnValue[key], value);
292
- }
293
- returnValue = { ...returnValue, [key]: value };
294
- }
295
- if (isObject(source.headers)) {
296
- headers = mergeHeaders(headers, source.headers);
297
- returnValue.headers = headers;
298
- }
299
- }
300
- }
301
- return returnValue;
302
- };
303
-
304
- const supportsRequestStreams = (() => {
305
- let duplexAccessed = false;
306
- let hasContentType = false;
307
- const supportsReadableStream = typeof globalThis.ReadableStream === 'function';
308
- const supportsRequest = typeof globalThis.Request === 'function';
309
- if (supportsReadableStream && supportsRequest) {
310
- hasContentType = new globalThis.Request('https://empty.invalid', {
311
- body: new globalThis.ReadableStream(),
312
- method: 'POST',
313
- // @ts-expect-error - Types are outdated.
314
- get duplex() {
315
- duplexAccessed = true;
316
- return 'half';
317
- },
318
- }).headers.has('Content-Type');
319
- }
320
- return duplexAccessed && !hasContentType;
321
- })();
322
- const supportsAbortController = typeof globalThis.AbortController === 'function';
323
- const supportsResponseStreams = typeof globalThis.ReadableStream === 'function';
324
- const supportsFormData = typeof globalThis.FormData === 'function';
325
- const requestMethods = ['get', 'post', 'put', 'patch', 'head', 'delete'];
326
- const responseTypes = {
327
- json: 'application/json',
328
- text: 'text/*',
329
- formData: 'multipart/form-data',
330
- arrayBuffer: '*/*',
331
- blob: '*/*',
332
- };
333
- // The maximum value of a 32bit int (see issue #117)
334
- const maxSafeTimeout = 2147483647;
335
- const stop = Symbol('stop');
336
-
337
- const normalizeRequestMethod = (input) => requestMethods.includes(input) ? input.toUpperCase() : input;
338
- const retryMethods = ['get', 'put', 'head', 'delete', 'options', 'trace'];
339
- const retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
340
- const retryAfterStatusCodes = [413, 429, 503];
341
- const defaultRetryOptions = {
342
- limit: 2,
343
- methods: retryMethods,
344
- statusCodes: retryStatusCodes,
345
- afterStatusCodes: retryAfterStatusCodes,
346
- maxRetryAfter: Number.POSITIVE_INFINITY,
347
- backoffLimit: Number.POSITIVE_INFINITY,
348
- };
349
- const normalizeRetryOptions = (retry = {}) => {
350
- if (typeof retry === 'number') {
351
- return {
352
- ...defaultRetryOptions,
353
- limit: retry,
354
- };
355
- }
356
- if (retry.methods && !Array.isArray(retry.methods)) {
357
- throw new Error('retry.methods must be an array');
358
- }
359
- if (retry.statusCodes && !Array.isArray(retry.statusCodes)) {
360
- throw new Error('retry.statusCodes must be an array');
361
- }
362
- return {
363
- ...defaultRetryOptions,
364
- ...retry,
365
- afterStatusCodes: retryAfterStatusCodes,
366
- };
367
- };
368
-
369
- // `Promise.race()` workaround (#91)
370
- async function timeout(request, abortController, options) {
371
- return new Promise((resolve, reject) => {
372
- const timeoutId = setTimeout(() => {
373
- if (abortController) {
374
- abortController.abort();
375
- }
376
- reject(new TimeoutError(request));
377
- }, options.timeout);
378
- void options
379
- .fetch(request)
380
- .then(resolve)
381
- .catch(reject)
382
- .then(() => {
383
- clearTimeout(timeoutId);
384
- });
385
- });
386
- }
387
-
388
- // https://github.com/sindresorhus/delay/tree/ab98ae8dfcb38e1593286c94d934e70d14a4e111
389
- async function delay(ms, { signal }) {
390
- return new Promise((resolve, reject) => {
391
- if (signal) {
392
- signal.throwIfAborted();
393
- signal.addEventListener('abort', abortHandler, { once: true });
394
- }
395
- function abortHandler() {
396
- clearTimeout(timeoutId);
397
- reject(signal.reason);
398
- }
399
- const timeoutId = setTimeout(() => {
400
- signal?.removeEventListener('abort', abortHandler);
401
- resolve();
402
- }, ms);
403
- });
404
- }
405
-
406
- class Ky {
407
- static create(input, options) {
408
- const ky = new Ky(input, options);
409
- const fn = async () => {
410
- if (typeof ky._options.timeout === 'number' && ky._options.timeout > maxSafeTimeout) {
411
- throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);
412
- }
413
- // Delay the fetch so that body method shortcuts can set the Accept header
414
- await Promise.resolve();
415
- let response = await ky._fetch();
416
- for (const hook of ky._options.hooks.afterResponse) {
417
- // eslint-disable-next-line no-await-in-loop
418
- const modifiedResponse = await hook(ky.request, ky._options, ky._decorateResponse(response.clone()));
419
- if (modifiedResponse instanceof globalThis.Response) {
420
- response = modifiedResponse;
421
- }
422
- }
423
- ky._decorateResponse(response);
424
- if (!response.ok && ky._options.throwHttpErrors) {
425
- let error = new HTTPError(response, ky.request, ky._options);
426
- for (const hook of ky._options.hooks.beforeError) {
427
- // eslint-disable-next-line no-await-in-loop
428
- error = await hook(error);
429
- }
430
- throw error;
431
- }
432
- // If `onDownloadProgress` is passed, it uses the stream API internally
433
- /* istanbul ignore next */
434
- if (ky._options.onDownloadProgress) {
435
- if (typeof ky._options.onDownloadProgress !== 'function') {
436
- throw new TypeError('The `onDownloadProgress` option must be a function');
437
- }
438
- if (!supportsResponseStreams) {
439
- throw new Error('Streams are not supported in your environment. `ReadableStream` is missing.');
440
- }
441
- return ky._stream(response.clone(), ky._options.onDownloadProgress);
442
- }
443
- return response;
444
- };
445
- const isRetriableMethod = ky._options.retry.methods.includes(ky.request.method.toLowerCase());
446
- const result = (isRetriableMethod ? ky._retry(fn) : fn());
447
- for (const [type, mimeType] of Object.entries(responseTypes)) {
448
- result[type] = async () => {
449
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
450
- ky.request.headers.set('accept', ky.request.headers.get('accept') || mimeType);
451
- const awaitedResult = await result;
452
- const response = awaitedResult.clone();
453
- if (type === 'json') {
454
- if (response.status === 204) {
455
- return '';
456
- }
457
- const arrayBuffer = await response.clone().arrayBuffer();
458
- const responseSize = arrayBuffer.byteLength;
459
- if (responseSize === 0) {
460
- return '';
461
- }
462
- if (options.parseJson) {
463
- return options.parseJson(await response.text());
464
- }
465
- }
466
- return response[type]();
467
- };
468
- }
469
- return result;
470
- }
471
- // eslint-disable-next-line complexity
472
- constructor(input, options = {}) {
473
- Object.defineProperty(this, "request", {
474
- enumerable: true,
475
- configurable: true,
476
- writable: true,
477
- value: void 0
478
- });
479
- Object.defineProperty(this, "abortController", {
480
- enumerable: true,
481
- configurable: true,
482
- writable: true,
483
- value: void 0
484
- });
485
- Object.defineProperty(this, "_retryCount", {
486
- enumerable: true,
487
- configurable: true,
488
- writable: true,
489
- value: 0
490
- });
491
- Object.defineProperty(this, "_input", {
492
- enumerable: true,
493
- configurable: true,
494
- writable: true,
495
- value: void 0
496
- });
497
- Object.defineProperty(this, "_options", {
498
- enumerable: true,
499
- configurable: true,
500
- writable: true,
501
- value: void 0
502
- });
503
- this._input = input;
504
- this._options = {
505
- // TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
506
- credentials: this._input.credentials || 'same-origin',
507
- ...options,
508
- headers: mergeHeaders(this._input.headers, options.headers),
509
- hooks: deepMerge({
510
- beforeRequest: [],
511
- beforeRetry: [],
512
- beforeError: [],
513
- afterResponse: [],
514
- }, options.hooks),
515
- method: normalizeRequestMethod(options.method ?? this._input.method),
516
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
517
- prefixUrl: String(options.prefixUrl || ''),
518
- retry: normalizeRetryOptions(options.retry),
519
- throwHttpErrors: options.throwHttpErrors !== false,
520
- timeout: options.timeout ?? 10000,
521
- fetch: options.fetch ?? globalThis.fetch.bind(globalThis),
522
- };
523
- if (typeof this._input !== 'string' && !(this._input instanceof URL || this._input instanceof globalThis.Request)) {
524
- throw new TypeError('`input` must be a string, URL, or Request');
525
- }
526
- if (this._options.prefixUrl && typeof this._input === 'string') {
527
- if (this._input.startsWith('/')) {
528
- throw new Error('`input` must not begin with a slash when using `prefixUrl`');
529
- }
530
- if (!this._options.prefixUrl.endsWith('/')) {
531
- this._options.prefixUrl += '/';
532
- }
533
- this._input = this._options.prefixUrl + this._input;
534
- }
535
- if (supportsAbortController) {
536
- this.abortController = new globalThis.AbortController();
537
- if (this._options.signal) {
538
- const originalSignal = this._options.signal;
539
- this._options.signal.addEventListener('abort', () => {
540
- this.abortController.abort(originalSignal.reason);
541
- });
542
- }
543
- this._options.signal = this.abortController.signal;
544
- }
545
- if (supportsRequestStreams) {
546
- // @ts-expect-error - Types are outdated.
547
- this._options.duplex = 'half';
548
- }
549
- this.request = new globalThis.Request(this._input, this._options);
550
- if (this._options.searchParams) {
551
- // eslint-disable-next-line unicorn/prevent-abbreviations
552
- const textSearchParams = typeof this._options.searchParams === 'string'
553
- ? this._options.searchParams.replace(/^\?/, '')
554
- : new URLSearchParams(this._options.searchParams).toString();
555
- // eslint-disable-next-line unicorn/prevent-abbreviations
556
- const searchParams = '?' + textSearchParams;
557
- const url = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, searchParams);
558
- // To provide correct form boundary, Content-Type header should be deleted each time when new Request instantiated from another one
559
- if (((supportsFormData && this._options.body instanceof globalThis.FormData)
560
- || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers['content-type'])) {
561
- this.request.headers.delete('content-type');
562
- }
563
- // The spread of `this.request` is required as otherwise it misses the `duplex` option for some reason and throws.
564
- this.request = new globalThis.Request(new globalThis.Request(url, { ...this.request }), this._options);
565
- }
566
- if (this._options.json !== undefined) {
567
- this._options.body = JSON.stringify(this._options.json);
568
- this.request.headers.set('content-type', this._options.headers.get('content-type') ?? 'application/json');
569
- this.request = new globalThis.Request(this.request, { body: this._options.body });
570
- }
571
- }
572
- _calculateRetryDelay(error) {
573
- this._retryCount++;
574
- if (this._retryCount < this._options.retry.limit && !(error instanceof TimeoutError)) {
575
- if (error instanceof HTTPError) {
576
- if (!this._options.retry.statusCodes.includes(error.response.status)) {
577
- return 0;
578
- }
579
- const retryAfter = error.response.headers.get('Retry-After');
580
- if (retryAfter && this._options.retry.afterStatusCodes.includes(error.response.status)) {
581
- let after = Number(retryAfter);
582
- if (Number.isNaN(after)) {
583
- after = Date.parse(retryAfter) - Date.now();
584
- }
585
- else {
586
- after *= 1000;
587
- }
588
- if (this._options.retry.maxRetryAfter !== undefined && after > this._options.retry.maxRetryAfter) {
589
- return 0;
590
- }
591
- return after;
592
- }
593
- if (error.response.status === 413) {
594
- return 0;
595
- }
596
- }
597
- const BACKOFF_FACTOR = 0.3;
598
- return Math.min(this._options.retry.backoffLimit, BACKOFF_FACTOR * (2 ** (this._retryCount - 1)) * 1000);
599
- }
600
- return 0;
601
- }
602
- _decorateResponse(response) {
603
- if (this._options.parseJson) {
604
- response.json = async () => this._options.parseJson(await response.text());
605
- }
606
- return response;
607
- }
608
- async _retry(fn) {
609
- try {
610
- return await fn();
611
- }
612
- catch (error) {
613
- const ms = Math.min(this._calculateRetryDelay(error), maxSafeTimeout);
614
- if (ms !== 0 && this._retryCount > 0) {
615
- await delay(ms, { signal: this._options.signal });
616
- for (const hook of this._options.hooks.beforeRetry) {
617
- // eslint-disable-next-line no-await-in-loop
618
- const hookResult = await hook({
619
- request: this.request,
620
- options: this._options,
621
- error: error,
622
- retryCount: this._retryCount,
623
- });
624
- // If `stop` is returned from the hook, the retry process is stopped
625
- if (hookResult === stop) {
626
- return;
627
- }
628
- }
629
- return this._retry(fn);
630
- }
631
- throw error;
632
- }
633
- }
634
- async _fetch() {
635
- for (const hook of this._options.hooks.beforeRequest) {
636
- // eslint-disable-next-line no-await-in-loop
637
- const result = await hook(this.request, this._options);
638
- if (result instanceof Request) {
639
- this.request = result;
640
- break;
641
- }
642
- if (result instanceof Response) {
643
- return result;
644
- }
645
- }
646
- if (this._options.timeout === false) {
647
- return this._options.fetch(this.request.clone());
648
- }
649
- return timeout(this.request.clone(), this.abortController, this._options);
650
- }
651
- /* istanbul ignore next */
652
- _stream(response, onDownloadProgress) {
653
- const totalBytes = Number(response.headers.get('content-length')) || 0;
654
- let transferredBytes = 0;
655
- if (response.status === 204) {
656
- if (onDownloadProgress) {
657
- onDownloadProgress({ percent: 1, totalBytes, transferredBytes }, new Uint8Array());
658
- }
659
- return new globalThis.Response(null, {
660
- status: response.status,
661
- statusText: response.statusText,
662
- headers: response.headers,
663
- });
664
- }
665
- return new globalThis.Response(new globalThis.ReadableStream({
666
- async start(controller) {
667
- const reader = response.body.getReader();
668
- if (onDownloadProgress) {
669
- onDownloadProgress({ percent: 0, transferredBytes: 0, totalBytes }, new Uint8Array());
670
- }
671
- async function read() {
672
- const { done, value } = await reader.read();
673
- if (done) {
674
- controller.close();
675
- return;
676
- }
677
- if (onDownloadProgress) {
678
- transferredBytes += value.byteLength;
679
- const percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
680
- onDownloadProgress({ percent, transferredBytes, totalBytes }, value);
681
- }
682
- controller.enqueue(value);
683
- await read();
684
- }
685
- await read();
686
- },
687
- }), {
688
- status: response.status,
689
- statusText: response.statusText,
690
- headers: response.headers,
691
- });
692
- }
693
- }
694
-
695
- /*! MIT License © Sindre Sorhus */
696
- const createInstance = (defaults) => {
697
- // eslint-disable-next-line @typescript-eslint/promise-function-async
698
- const ky = (input, options) => Ky.create(input, validateAndMerge(defaults, options));
699
- for (const method of requestMethods) {
700
- // eslint-disable-next-line @typescript-eslint/promise-function-async
701
- ky[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method }));
702
- }
703
- ky.create = (newDefaults) => createInstance(validateAndMerge(newDefaults));
704
- ky.extend = (newDefaults) => createInstance(validateAndMerge(defaults, newDefaults));
705
- ky.stop = stop;
706
- return ky;
707
- };
708
- const ky$1 = createInstance();
709
-
710
- var distribution = /*#__PURE__*/Object.freeze({
711
- __proto__: null,
712
- HTTPError: HTTPError,
713
- TimeoutError: TimeoutError,
714
- default: ky$1
715
- });
716
-
717
- var require$$3 = /*@__PURE__*/getAugmentedNamespace(distribution);
718
-
719
- const urlHttp = lightweight$2;
720
- const { flattie: flatten } = dist;
721
-
722
- const factory = factory_1;
723
- const { default: ky } = require$$3;
724
-
725
- class MicrolinkError extends Error {
726
- constructor (props) {
727
- super();
728
- this.name = 'MicrolinkError';
729
- Object.assign(this, props);
730
- this.description = this.message;
731
- this.message = this.code
732
- ? `${this.code}, ${this.description}`
733
- : this.description;
734
- }
735
- }
736
-
737
- const got = async (url, opts) => {
738
- try {
739
- if (opts.retry > 0) opts.retry = opts.retry + 1;
740
- if (opts.timeout === undefined) opts.timeout = false;
741
- const response = await ky(url, opts);
742
- const body = await response.json();
743
- const { headers, status: statusCode } = response;
744
- return { url: response.url, body, headers, statusCode }
745
- } catch (err) {
746
- if (err.response) {
747
- const { response } = err;
748
- err.response = {
749
- ...response,
750
- headers: Array.from(response.headers.entries()).reduce(
751
- (acc, [key, value]) => {
752
- acc[key] = value;
753
- return acc
754
- },
755
- {}
756
- ),
757
- statusCode: response.status,
758
- body: await response.text()
759
- };
760
- }
761
- throw err
762
- }
763
- };
764
-
765
- var lightweight = factory({
766
- MicrolinkError,
767
- urlHttp,
768
- got,
769
- flatten,
770
- VERSION: '0.10.39'
771
- });
772
-
773
- var lightweight$1 = /*@__PURE__*/getDefaultExportFromCjs(lightweight);
774
-
775
- return lightweight$1;
776
-
777
- }));
package/dist/mql.min.js DELETED
@@ -1,2 +0,0 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).mql=e()}(this,(function(){"use strict";function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function e(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var r=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach((function(e){var s=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(r,e,s.get?s:{enumerable:!0,get:function(){return t[e]}})})),r}const r=/^https?:\/\//i;var s={};function o(t,e,r,s,n){var i,a=n?n+r:n;if(null==s)e&&(t[n]=s);else if("object"!=typeof s)t[n]=s;else if(Array.isArray(s))for(i=0;i<s.length;i++)o(t,e,r,s[i],a+i);else for(i in s)o(t,e,r,s[i],a+i)}s.flattie=function(t,e,r){var s={};return"object"==typeof t&&o(s,!!r,e||".",t,""),s};const n={FREE:"https://api.microlink.io/",PRO:"https://pro.microlink.io/"},i=t=>null!==t&&"object"==typeof t;var a=({VERSION:t,MicrolinkError:e,urlHttp:r,got:s,flatten:o})=>{const a=t=>{if(!i(t))return;const e=o(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:n,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=i(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:n,headers:u})}var o},l=(t,{data:e,apiKey:r,endpoint:s,retry:i,cache:u,...l}={},{responseType:h="json",headers:c,...p}={})=>{const f=!!r;return[`${s||n[f?"PRO":"FREE"]}?${new URLSearchParams({url:t,...a(e),...o(l)}).toString()}`,{...p,responseType:h,cache:u,retry:i,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};class u 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 l 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 h=t=>null!==t&&"object"==typeof t,c=(...t)=>{for(const e of t)if((!h(e)||Array.isArray(e))&&void 0!==e)throw new TypeError("The `options` argument must be an object");return f({},...t)},p=(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},f=(...t)=>{let e={},r={};for(const s of t)if(Array.isArray(s))Array.isArray(e)||(e=[]),e=[...e,...s];else if(h(s)){for(let[t,r]of Object.entries(s))h(r)&&t in e&&(r=f(e[t],r)),e={...e,[t]:r};h(s.headers)&&(r=p(r,s.headers),e.headers=r)}return e},d=(()=>{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})(),y="function"==typeof globalThis.AbortController,b="function"==typeof globalThis.ReadableStream,m="function"==typeof globalThis.FormData,_=["get","post","put","patch","head","delete"],g={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*"},w=2147483647,T=Symbol("stop"),R=t=>_.includes(t)?t.toUpperCase():t,v=[413,429,503],E={limit:2,methods:["get","put","head","delete","options","trace"],statusCodes:[408,413,429,500,502,503,504],afterStatusCodes:v,maxRetryAfter:Number.POSITIVE_INFINITY,backoffLimit:Number.POSITIVE_INFINITY},q=(t={})=>{if("number"==typeof t)return{...E,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{...E,...t,afterStatusCodes:v}};class j{static create(t,e){const r=new j(t,e),s=async()=>{if("number"==typeof r._options.timeout&&r._options.timeout>w)throw new RangeError("The `timeout` option cannot be greater than 2147483647");await Promise.resolve();let t=await r._fetch();for(const e of r._options.hooks.afterResponse){const s=await e(r.request,r._options,r._decorateResponse(t.clone()));s instanceof globalThis.Response&&(t=s)}if(r._decorateResponse(t),!t.ok&&r._options.throwHttpErrors){let e=new u(t,r.request,r._options);for(const t of r._options.hooks.beforeError)e=await t(e);throw e}if(r._options.onDownloadProgress){if("function"!=typeof r._options.onDownloadProgress)throw new TypeError("The `onDownloadProgress` option must be a function");if(!b)throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");return r._stream(t.clone(),r._options.onDownloadProgress)}return t},o=r._options.retry.methods.includes(r.request.method.toLowerCase())?r._retry(s):s();for(const[t,s]of Object.entries(g))o[t]=async()=>{r.request.headers.set("accept",r.request.headers.get("accept")||s);const n=(await o).clone();if("json"===t){if(204===n.status)return"";if(0===(await n.clone().arrayBuffer()).byteLength)return"";if(e.parseJson)return e.parseJson(await n.text())}return n[t]()};return o}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:p(this._input.headers,e.headers),hooks:f({beforeRequest:[],beforeRetry:[],beforeError:[],afterResponse:[]},e.hooks),method:R(e.method??this._input.method),prefixUrl:String(e.prefixUrl||""),retry:q(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(y){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(d&&(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);!(m&&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 l)){if(t instanceof u){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 e=.3;return Math.min(this._options.retry.backoffLimit,e*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 async function(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)}))}(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})===T)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()):async function(t,e,r){return new Promise(((s,o)=>{const n=setTimeout((()=>{e&&e.abort(),o(new l(t))}),r.timeout);r.fetch(t).then(s).catch(o).then((()=>{clearTimeout(n)}))}))}(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();e&&e({percent:0,transferredBytes:0,totalBytes:r},new Uint8Array),await async function t(){const{done:i,value:a}=await n.read();if(i)o.close();else{if(e){s+=a.byteLength;e({percent:0===r?0:s/r,transferredBytes:s,totalBytes:r},a)}o.enqueue(a),await t()}}()}}),{status:t.status,statusText:t.statusText,headers:t.headers})}}
2
- /*! MIT License © Sindre Sorhus */const P=t=>{const e=(e,r)=>j.create(e,c(t,r));for(const r of _)e[r]=(e,s)=>j.create(e,c(t,s,{method:r}));return e.create=t=>P(c(t)),e.extend=e=>P(c(t,e)),e.stop=T,e},C=P();var O=e(Object.freeze({__proto__:null,HTTPError:u,TimeoutError:l,default:C}));const x=t=>{try{const{href:e}=new URL(t);return r.test(e)&&e}catch(t){return!1}},{flattie:A}=s,S=a,{default:k}=O;class L 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}}return t(S({MicrolinkError:L,urlHttp:x,got:async(t,e)=>{try{e.retry>0&&(e.retry=e.retry+1),void 0===e.timeout&&(e.timeout=!1);const r=await k(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:A,VERSION:"0.10.39"}))}));
package/index.d.ts DELETED
@@ -1,29 +0,0 @@
1
- import { MqlPayload, MqlOptions, MicrolinkApiOptions } from './lightweight'
2
-
3
- export { MqlPayload } from './lightweight'
4
-
5
- export type MqlResponse = MqlPayload & {
6
- response: {
7
- url: string;
8
- isFromCache?: boolean;
9
- statusCode: number;
10
- headers: { [key: string]: string };
11
- body: MqlPayload
12
- };
13
- }
14
-
15
- declare function mql(
16
- url: string,
17
- opts?: MqlOptions & MicrolinkApiOptions,
18
- gotOpts?: object
19
- ): Promise<MqlResponse>;
20
-
21
- declare namespace mql {
22
- function stream(
23
- url: string,
24
- opts?: MqlOptions & MicrolinkApiOptions,
25
- gotOpts?: object
26
- ): NodeJS.ReadableStream;
27
- }
28
-
29
- export default mql;
@@ -1,193 +0,0 @@
1
- import require$$0 from 'url-http/lightweight';
2
- import { flattie as require$$1 } from 'flattie';
3
- import require$$3 from 'ky';
4
-
5
- function getDefaultExportFromCjs (x) {
6
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
7
- }
8
-
9
- const ENDPOINT = {
10
- FREE: 'https://api.microlink.io/',
11
- PRO: 'https://pro.microlink.io/'
12
- };
13
-
14
- const isObject = input => input !== null && typeof input === 'object';
15
-
16
- const isBuffer = input =>
17
- input != null &&
18
- input.constructor != null &&
19
- typeof input.constructor.isBuffer === 'function' &&
20
- input.constructor.isBuffer(input);
21
-
22
- const parseBody = (input, error, url) => {
23
- try {
24
- return JSON.parse(input)
25
- } catch (_) {
26
- const message = input || error.message;
27
-
28
- return {
29
- status: 'error',
30
- data: { url: message },
31
- more: 'https://microlink.io/efatalclient',
32
- code: 'EFATALCLIENT',
33
- message,
34
- url
35
- }
36
- }
37
- };
38
-
39
- const factory$1 = ({ VERSION, MicrolinkError, urlHttp, got, flatten }) => {
40
- const assertUrl = (url = '') => {
41
- if (!urlHttp(url)) {
42
- const message = `The \`url\` as \`${url}\` is not valid. Ensure it has protocol (http or https) and hostname.`;
43
- throw new MicrolinkError({
44
- status: 'fail',
45
- data: { url: message },
46
- more: 'https://microlink.io/docs/api/api-parameters/url',
47
- code: 'EINVALURLCLIENT',
48
- message,
49
- url
50
- })
51
- }
52
- };
53
-
54
- const mapRules = rules => {
55
- if (!isObject(rules)) return
56
- const flatRules = flatten(rules);
57
- return Object.keys(flatRules).reduce((acc, key) => {
58
- acc[`data.${key}`] = flatRules[key].toString();
59
- return acc
60
- }, {})
61
- };
62
-
63
- const fetchFromApi = async (apiUrl, opts = {}) => {
64
- try {
65
- const response = await got(apiUrl, opts);
66
- return opts.responseType === 'buffer'
67
- ? { body: response.body, response }
68
- : { ...response.body, response }
69
- } catch (err) {
70
- const { response = {} } = err;
71
- const {
72
- statusCode,
73
- body: rawBody,
74
- headers = {},
75
- url: uri = apiUrl
76
- } = response;
77
- const isBodyBuffer = isBuffer(rawBody);
78
-
79
- const body =
80
- isObject(rawBody) && !isBodyBuffer
81
- ? rawBody
82
- : parseBody(isBodyBuffer ? rawBody.toString() : rawBody, err, uri);
83
-
84
- throw new MicrolinkError({
85
- ...body,
86
- message: body.message,
87
- url: uri,
88
- statusCode,
89
- headers
90
- })
91
- }
92
- };
93
-
94
- const getApiUrl = (
95
- url,
96
- { data, apiKey, endpoint, retry, cache, ...opts } = {},
97
- { responseType = 'json', headers: gotHeaders, ...gotOpts } = {}
98
- ) => {
99
- const isPro = !!apiKey;
100
- const apiEndpoint = endpoint || ENDPOINT[isPro ? 'PRO' : 'FREE'];
101
-
102
- const apiUrl = `${apiEndpoint}?${new URLSearchParams({
103
- url,
104
- ...mapRules(data),
105
- ...flatten(opts)
106
- }).toString()}`;
107
-
108
- const headers = isPro
109
- ? { ...gotHeaders, 'x-api-key': apiKey }
110
- : { ...gotHeaders };
111
- return [apiUrl, { ...gotOpts, responseType, cache, retry, headers }]
112
- };
113
-
114
- const createMql = defaultOpts => async (url, opts, gotOpts) => {
115
- assertUrl(url);
116
- const [apiUrl, fetchOpts] = getApiUrl(url, opts, {
117
- ...defaultOpts,
118
- ...gotOpts
119
- });
120
- return fetchFromApi(apiUrl, fetchOpts)
121
- };
122
-
123
- const mql = createMql();
124
- mql.MicrolinkError = MicrolinkError;
125
- mql.getApiUrl = getApiUrl;
126
- mql.fetchFromApi = fetchFromApi;
127
- mql.mapRules = mapRules;
128
- mql.version = VERSION;
129
- mql.stream = got.stream;
130
- mql.buffer = createMql({ responseType: 'buffer' });
131
-
132
- return mql
133
- };
134
-
135
- var factory_1 = factory$1;
136
-
137
- const urlHttp = require$$0;
138
- const { flattie: flatten } = require$$1;
139
-
140
- const factory = factory_1;
141
- const { default: ky } = require$$3;
142
-
143
- class MicrolinkError extends Error {
144
- constructor (props) {
145
- super();
146
- this.name = 'MicrolinkError';
147
- Object.assign(this, props);
148
- this.description = this.message;
149
- this.message = this.code
150
- ? `${this.code}, ${this.description}`
151
- : this.description;
152
- }
153
- }
154
-
155
- const got = async (url, opts) => {
156
- try {
157
- if (opts.retry > 0) opts.retry = opts.retry + 1;
158
- if (opts.timeout === undefined) opts.timeout = false;
159
- const response = await ky(url, opts);
160
- const body = await response.json();
161
- const { headers, status: statusCode } = response;
162
- return { url: response.url, body, headers, statusCode }
163
- } catch (err) {
164
- if (err.response) {
165
- const { response } = err;
166
- err.response = {
167
- ...response,
168
- headers: Array.from(response.headers.entries()).reduce(
169
- (acc, [key, value]) => {
170
- acc[key] = value;
171
- return acc
172
- },
173
- {}
174
- ),
175
- statusCode: response.status,
176
- body: await response.text()
177
- };
178
- }
179
- throw err
180
- }
181
- };
182
-
183
- var lightweight = factory({
184
- MicrolinkError,
185
- urlHttp,
186
- got,
187
- flatten,
188
- VERSION: '0.10.39'
189
- });
190
-
191
- var lightweight$1 = /*@__PURE__*/getDefaultExportFromCjs(lightweight);
192
-
193
- export { lightweight$1 as default };
package/src/node.mjs DELETED
@@ -1,158 +0,0 @@
1
- import require$$1 from 'whoops';
2
- import require$$2 from 'url-http/lightweight';
3
- import require$$3 from 'got';
4
- import { flattie as require$$4 } from 'flattie';
5
-
6
- function getDefaultExportFromCjs (x) {
7
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
8
- }
9
-
10
- var node$1 = {exports: {}};
11
-
12
- const ENDPOINT = {
13
- FREE: 'https://api.microlink.io/',
14
- PRO: 'https://pro.microlink.io/'
15
- };
16
-
17
- const isObject = input => input !== null && typeof input === 'object';
18
-
19
- const isBuffer = input =>
20
- input != null &&
21
- input.constructor != null &&
22
- typeof input.constructor.isBuffer === 'function' &&
23
- input.constructor.isBuffer(input);
24
-
25
- const parseBody = (input, error, url) => {
26
- try {
27
- return JSON.parse(input)
28
- } catch (_) {
29
- const message = input || error.message;
30
-
31
- return {
32
- status: 'error',
33
- data: { url: message },
34
- more: 'https://microlink.io/efatalclient',
35
- code: 'EFATALCLIENT',
36
- message,
37
- url
38
- }
39
- }
40
- };
41
-
42
- const factory = ({ VERSION, MicrolinkError, urlHttp, got, flatten }) => {
43
- const assertUrl = (url = '') => {
44
- if (!urlHttp(url)) {
45
- const message = `The \`url\` as \`${url}\` is not valid. Ensure it has protocol (http or https) and hostname.`;
46
- throw new MicrolinkError({
47
- status: 'fail',
48
- data: { url: message },
49
- more: 'https://microlink.io/docs/api/api-parameters/url',
50
- code: 'EINVALURLCLIENT',
51
- message,
52
- url
53
- })
54
- }
55
- };
56
-
57
- const mapRules = rules => {
58
- if (!isObject(rules)) return
59
- const flatRules = flatten(rules);
60
- return Object.keys(flatRules).reduce((acc, key) => {
61
- acc[`data.${key}`] = flatRules[key].toString();
62
- return acc
63
- }, {})
64
- };
65
-
66
- const fetchFromApi = async (apiUrl, opts = {}) => {
67
- try {
68
- const response = await got(apiUrl, opts);
69
- return opts.responseType === 'buffer'
70
- ? { body: response.body, response }
71
- : { ...response.body, response }
72
- } catch (err) {
73
- const { response = {} } = err;
74
- const {
75
- statusCode,
76
- body: rawBody,
77
- headers = {},
78
- url: uri = apiUrl
79
- } = response;
80
- const isBodyBuffer = isBuffer(rawBody);
81
-
82
- const body =
83
- isObject(rawBody) && !isBodyBuffer
84
- ? rawBody
85
- : parseBody(isBodyBuffer ? rawBody.toString() : rawBody, err, uri);
86
-
87
- throw new MicrolinkError({
88
- ...body,
89
- message: body.message,
90
- url: uri,
91
- statusCode,
92
- headers
93
- })
94
- }
95
- };
96
-
97
- const getApiUrl = (
98
- url,
99
- { data, apiKey, endpoint, retry, cache, ...opts } = {},
100
- { responseType = 'json', headers: gotHeaders, ...gotOpts } = {}
101
- ) => {
102
- const isPro = !!apiKey;
103
- const apiEndpoint = endpoint || ENDPOINT[isPro ? 'PRO' : 'FREE'];
104
-
105
- const apiUrl = `${apiEndpoint}?${new URLSearchParams({
106
- url,
107
- ...mapRules(data),
108
- ...flatten(opts)
109
- }).toString()}`;
110
-
111
- const headers = isPro
112
- ? { ...gotHeaders, 'x-api-key': apiKey }
113
- : { ...gotHeaders };
114
- return [apiUrl, { ...gotOpts, responseType, cache, retry, headers }]
115
- };
116
-
117
- const createMql = defaultOpts => async (url, opts, gotOpts) => {
118
- assertUrl(url);
119
- const [apiUrl, fetchOpts] = getApiUrl(url, opts, {
120
- ...defaultOpts,
121
- ...gotOpts
122
- });
123
- return fetchFromApi(apiUrl, fetchOpts)
124
- };
125
-
126
- const mql = createMql();
127
- mql.MicrolinkError = MicrolinkError;
128
- mql.getApiUrl = getApiUrl;
129
- mql.fetchFromApi = fetchFromApi;
130
- mql.mapRules = mapRules;
131
- mql.version = VERSION;
132
- mql.stream = got.stream;
133
- mql.buffer = createMql({ responseType: 'buffer' });
134
-
135
- return mql
136
- };
137
-
138
- var factory_1 = factory;
139
-
140
- node$1.exports = factory_1({
141
- MicrolinkError: require$$1('MicrolinkError'),
142
- urlHttp: require$$2,
143
- got: require$$3.extend({ headers: { 'user-agent': undefined } }),
144
- flatten: require$$4.flattie,
145
- VERSION: '0.10.39'
146
- });
147
-
148
- var render = node$1.exports.render = (input, { width = '650px' } = {}) => {
149
- if (input && input.url && input.type) {
150
- return `<img width="${width}" src="${input.url}" />`
151
- }
152
- return input
153
- };
154
-
155
- var nodeExports = node$1.exports;
156
- var node = /*@__PURE__*/getDefaultExportFromCjs(nodeExports);
157
-
158
- export { node as default, render };