@microlink/mql 0.14.2 → 0.15.0

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.
@@ -42,7 +42,6 @@ type ScreenshotOptions = {
42
42
 
43
43
  type MqlClientOptions = {
44
44
  apiKey?: string
45
- cache?: Map<string, any>
46
45
  endpoint?: string
47
46
  retry?: number
48
47
  }
@@ -232,8 +231,9 @@ interface mql {
232
231
  opts?: MqlOptions,
233
232
  gotOpts?: object
234
233
  ) => Promise<HTTPResponseRaw>
234
+ buffer: (url: string, opts?: MqlOptions, gotOpts?: object) => Promise<HTTPResponseRaw>
235
235
  extend: (gotOpts?: object) => mql
236
- stream: (input: RequestInfo, init?: RequestInit) => ReadableStream
236
+ stream: (input: RequestInfo, init?: RequestInit) => Promise<ReadableStream | null>
237
237
  MicrolinkError: new (props: object) => MqlErrorProps
238
238
  version: string
239
239
  }
@@ -31,7 +31,7 @@ function getAugmentedNamespace(n) {
31
31
  return a;
32
32
  }
33
33
 
34
- var lightweight = {exports: {}};
34
+ var src = {exports: {}};
35
35
 
36
36
  var dist = {};
37
37
 
@@ -566,9 +566,6 @@ const deepMerge = (...sources) => {
566
566
  returnValue.signal = signals.at(-1);
567
567
  }
568
568
  }
569
- if (returnValue.context === undefined) {
570
- returnValue.context = {};
571
- }
572
569
  return returnValue;
573
570
  };
574
571
 
@@ -1191,7 +1188,7 @@ const createInstance = (defaults) => {
1191
1188
  ky.retry = retry;
1192
1189
  return ky;
1193
1190
  };
1194
- const ky$1 = createInstance();
1191
+ const ky = createInstance();
1195
1192
  // Intentionally not exporting this for now as it's just an implementation detail and we don't want to commit to a certain API yet at least.
1196
1193
  // export {NonError} from './errors/NonError.js';
1197
1194
 
@@ -1200,7 +1197,7 @@ var distribution = /*#__PURE__*/Object.freeze({
1200
1197
  ForceRetryError: ForceRetryError,
1201
1198
  HTTPError: HTTPError,
1202
1199
  TimeoutError: TimeoutError,
1203
- default: ky$1,
1200
+ default: ky,
1204
1201
  isForceRetryError: isForceRetryError,
1205
1202
  isHTTPError: isHTTPError,
1206
1203
  isKyError: isKyError,
@@ -1209,14 +1206,13 @@ var distribution = /*#__PURE__*/Object.freeze({
1209
1206
 
1210
1207
  var require$$1 = /*@__PURE__*/getAugmentedNamespace(distribution);
1211
1208
 
1212
- const VERSION$1 = '0.14.2';
1209
+ const VERSION = '0.15.0';
1213
1210
 
1214
1211
  var constants = {
1215
- VERSION: VERSION$1,
1216
- USER_AGENT: `mql/${VERSION$1}`,
1212
+ VERSION,
1213
+ USER_AGENT: `mql/${VERSION}`,
1217
1214
  /**
1218
- * Based on require('got').defaults.options.retry.statusCodes
1219
- * but without 429 (too many requests)
1215
+ * Retry status codes, excluding 429 (too many requests).
1220
1216
  */
1221
1217
  RETRY_STATUS_CODES: [408, 413, 500, 502, 503, 504, 521, 522, 524]
1222
1218
  };
@@ -1259,7 +1255,7 @@ const isURL = url => {
1259
1255
  }
1260
1256
  };
1261
1257
 
1262
- const factory$1 = streamResponseType => ({
1258
+ const factory = streamResponseType => ({
1263
1259
  VERSION,
1264
1260
  MicrolinkError,
1265
1261
  got,
@@ -1364,78 +1360,82 @@ const factory$1 = streamResponseType => ({
1364
1360
  return mql
1365
1361
  };
1366
1362
 
1367
- var factory_1 = factory$1;
1368
-
1369
- const { flattie: flatten } = dist;
1370
- const { default: ky } = require$$1;
1363
+ var factory_1 = factory;
1371
1364
 
1372
- const { VERSION, USER_AGENT, RETRY_STATUS_CODES } = constants;
1373
-
1374
- const kyInstance = ky.extend({
1375
- headers: { 'user-agent': USER_AGENT },
1376
- retry: { statusCodes: RETRY_STATUS_CODES }
1377
- });
1365
+ (function (module) {
1378
1366
 
1379
- const factory = factory_1('arrayBuffer');
1380
-
1381
- class MicrolinkError extends Error {
1382
- constructor (props) {
1383
- super();
1384
- this.name = 'MicrolinkError';
1385
- Object.assign(this, props);
1386
- this.description = this.message;
1387
- this.message = this.code
1388
- ? `${this.code}, ${this.description}`
1389
- : this.description;
1390
- }
1391
- }
1392
-
1393
- const got = async (url, { responseType, ...opts }) => {
1394
- try {
1395
- if (opts.timeout === undefined) opts.timeout = false;
1396
- const response = await kyInstance(url, opts);
1397
- const body = await response[responseType]();
1398
- const { headers, status: statusCode } = response;
1399
- return { url: response.url, body, headers, statusCode }
1400
- } catch (error) {
1401
- if (error.response) {
1402
- const { response } = error;
1403
- error.response = {
1404
- ...response,
1405
- headers: Array.from(response.headers.entries()).reduce(
1406
- (acc, [key, value]) => {
1407
- acc[key] = value;
1408
- return acc
1409
- },
1410
- {}
1411
- ),
1412
- statusCode: response.status,
1413
- body: await response.text()
1414
- };
1415
- }
1416
- throw error
1417
- }
1418
- };
1367
+ const { flattie: flatten } = dist;
1368
+ const { default: ky } = require$$1;
1419
1369
 
1420
- got.stream = (...args) => kyInstance(...args).then(res => res.body);
1370
+ const { VERSION, USER_AGENT, RETRY_STATUS_CODES } = constants;
1421
1371
 
1422
- const mql = factory({
1423
- MicrolinkError,
1424
- got,
1425
- flatten,
1426
- VERSION
1427
- });
1372
+ const kyInstance = ky.extend({
1373
+ headers: { 'user-agent': USER_AGENT },
1374
+ retry: { statusCodes: RETRY_STATUS_CODES }
1375
+ });
1428
1376
 
1429
- lightweight.exports = mql;
1430
- var arrayBuffer = lightweight.exports.arrayBuffer = mql.extend({ responseType: 'arrayBuffer' });
1431
- var extend = lightweight.exports.extend = mql.extend;
1432
- var fetchFromApi = lightweight.exports.fetchFromApi = mql.fetchFromApi;
1433
- var getApiUrl = lightweight.exports.getApiUrl = mql.getApiUrl;
1434
- var mapRules = lightweight.exports.mapRules = mql.mapRules;
1435
- var MicrolinkError_1 = lightweight.exports.MicrolinkError = mql.MicrolinkError;
1436
- var version = lightweight.exports.version = mql.version;
1377
+ const factory = factory_1('arrayBuffer');
1378
+
1379
+ class MicrolinkError extends Error {
1380
+ constructor (props) {
1381
+ super();
1382
+ this.name = 'MicrolinkError';
1383
+ Object.assign(this, props);
1384
+ this.description = this.message;
1385
+ this.message = this.code
1386
+ ? `${this.code}, ${this.description}`
1387
+ : this.description;
1388
+ }
1389
+ }
1437
1390
 
1438
- var lightweightExports = lightweight.exports;
1439
- var lightweight_default = /*@__PURE__*/getDefaultExportFromCjs(lightweightExports);
1391
+ const got = async (url, { responseType, ...opts }) => {
1392
+ try {
1393
+ if (opts.timeout === undefined) opts.timeout = false;
1394
+ const response = await kyInstance(url, opts);
1395
+ const body = await response[responseType]();
1396
+ const { headers, status: statusCode } = response;
1397
+ return { url: response.url, body, headers, statusCode }
1398
+ } catch (error) {
1399
+ if (error.response) {
1400
+ const { response } = error;
1401
+ error.response = {
1402
+ ...response,
1403
+ headers: Array.from(response.headers.entries()).reduce(
1404
+ (acc, [key, value]) => {
1405
+ acc[key] = value;
1406
+ return acc
1407
+ },
1408
+ {}
1409
+ ),
1410
+ statusCode: response.status,
1411
+ body: await response.text()
1412
+ };
1413
+ }
1414
+ throw error
1415
+ }
1416
+ };
1417
+
1418
+ got.stream = (...args) => kyInstance(...args).then(res => res.body);
1419
+
1420
+ const mql = factory({
1421
+ MicrolinkError,
1422
+ got,
1423
+ flatten,
1424
+ VERSION
1425
+ });
1440
1426
 
1441
- export { MicrolinkError_1 as MicrolinkError, arrayBuffer, lightweight_default as default, extend, fetchFromApi, getApiUrl, mapRules, version };
1427
+ module.exports = mql;
1428
+ module.exports.arrayBuffer = mql.extend({ responseType: 'arrayBuffer' });
1429
+ module.exports.buffer = module.exports.arrayBuffer;
1430
+ module.exports.extend = mql.extend;
1431
+ module.exports.fetchFromApi = mql.fetchFromApi;
1432
+ module.exports.getApiUrl = mql.getApiUrl;
1433
+ module.exports.mapRules = mql.mapRules;
1434
+ module.exports.MicrolinkError = mql.MicrolinkError;
1435
+ module.exports.version = mql.version;
1436
+ } (src));
1437
+
1438
+ var srcExports = src.exports;
1439
+ var index = /*@__PURE__*/getDefaultExportFromCjs(srcExports);
1440
+
1441
+ export { index as default };
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.mql = {}));
5
- })(this, (function (exports) { 'use strict';
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
6
 
7
7
  function getDefaultExportFromCjs (x) {
8
8
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -37,7 +37,7 @@
37
37
  return a;
38
38
  }
39
39
 
40
- var lightweight = {exports: {}};
40
+ var src = {exports: {}};
41
41
 
42
42
  var dist = {};
43
43
 
@@ -572,9 +572,6 @@
572
572
  returnValue.signal = signals.at(-1);
573
573
  }
574
574
  }
575
- if (returnValue.context === undefined) {
576
- returnValue.context = {};
577
- }
578
575
  return returnValue;
579
576
  };
580
577
 
@@ -1197,7 +1194,7 @@
1197
1194
  ky.retry = retry;
1198
1195
  return ky;
1199
1196
  };
1200
- const ky$1 = createInstance();
1197
+ const ky = createInstance();
1201
1198
  // Intentionally not exporting this for now as it's just an implementation detail and we don't want to commit to a certain API yet at least.
1202
1199
  // export {NonError} from './errors/NonError.js';
1203
1200
 
@@ -1206,7 +1203,7 @@
1206
1203
  ForceRetryError: ForceRetryError,
1207
1204
  HTTPError: HTTPError,
1208
1205
  TimeoutError: TimeoutError,
1209
- default: ky$1,
1206
+ default: ky,
1210
1207
  isForceRetryError: isForceRetryError,
1211
1208
  isHTTPError: isHTTPError,
1212
1209
  isKyError: isKyError,
@@ -1215,14 +1212,13 @@
1215
1212
 
1216
1213
  var require$$1 = /*@__PURE__*/getAugmentedNamespace(distribution);
1217
1214
 
1218
- const VERSION$1 = '0.14.2';
1215
+ const VERSION = '0.15.0';
1219
1216
 
1220
1217
  var constants = {
1221
- VERSION: VERSION$1,
1222
- USER_AGENT: `mql/${VERSION$1}`,
1218
+ VERSION,
1219
+ USER_AGENT: `mql/${VERSION}`,
1223
1220
  /**
1224
- * Based on require('got').defaults.options.retry.statusCodes
1225
- * but without 429 (too many requests)
1221
+ * Retry status codes, excluding 429 (too many requests).
1226
1222
  */
1227
1223
  RETRY_STATUS_CODES: [408, 413, 500, 502, 503, 504, 521, 522, 524]
1228
1224
  };
@@ -1265,7 +1261,7 @@
1265
1261
  }
1266
1262
  };
1267
1263
 
1268
- const factory$1 = streamResponseType => ({
1264
+ const factory = streamResponseType => ({
1269
1265
  VERSION,
1270
1266
  MicrolinkError,
1271
1267
  got,
@@ -1370,89 +1366,84 @@
1370
1366
  return mql
1371
1367
  };
1372
1368
 
1373
- var factory_1 = factory$1;
1369
+ var factory_1 = factory;
1374
1370
 
1375
- const { flattie: flatten } = dist;
1376
- const { default: ky } = require$$1;
1371
+ (function (module) {
1377
1372
 
1378
- const { VERSION, USER_AGENT, RETRY_STATUS_CODES } = constants;
1379
-
1380
- const kyInstance = ky.extend({
1381
- headers: { 'user-agent': USER_AGENT },
1382
- retry: { statusCodes: RETRY_STATUS_CODES }
1383
- });
1373
+ const { flattie: flatten } = dist;
1374
+ const { default: ky } = require$$1;
1384
1375
 
1385
- const factory = factory_1('arrayBuffer');
1386
-
1387
- class MicrolinkError extends Error {
1388
- constructor (props) {
1389
- super();
1390
- this.name = 'MicrolinkError';
1391
- Object.assign(this, props);
1392
- this.description = this.message;
1393
- this.message = this.code
1394
- ? `${this.code}, ${this.description}`
1395
- : this.description;
1396
- }
1397
- }
1376
+ const { VERSION, USER_AGENT, RETRY_STATUS_CODES } = constants;
1398
1377
 
1399
- const got = async (url, { responseType, ...opts }) => {
1400
- try {
1401
- if (opts.timeout === undefined) opts.timeout = false;
1402
- const response = await kyInstance(url, opts);
1403
- const body = await response[responseType]();
1404
- const { headers, status: statusCode } = response;
1405
- return { url: response.url, body, headers, statusCode }
1406
- } catch (error) {
1407
- if (error.response) {
1408
- const { response } = error;
1409
- error.response = {
1410
- ...response,
1411
- headers: Array.from(response.headers.entries()).reduce(
1412
- (acc, [key, value]) => {
1413
- acc[key] = value;
1414
- return acc
1415
- },
1416
- {}
1417
- ),
1418
- statusCode: response.status,
1419
- body: await response.text()
1420
- };
1421
- }
1422
- throw error
1423
- }
1424
- };
1378
+ const kyInstance = ky.extend({
1379
+ headers: { 'user-agent': USER_AGENT },
1380
+ retry: { statusCodes: RETRY_STATUS_CODES }
1381
+ });
1425
1382
 
1426
- got.stream = (...args) => kyInstance(...args).then(res => res.body);
1383
+ const factory = factory_1('arrayBuffer');
1384
+
1385
+ class MicrolinkError extends Error {
1386
+ constructor (props) {
1387
+ super();
1388
+ this.name = 'MicrolinkError';
1389
+ Object.assign(this, props);
1390
+ this.description = this.message;
1391
+ this.message = this.code
1392
+ ? `${this.code}, ${this.description}`
1393
+ : this.description;
1394
+ }
1395
+ }
1427
1396
 
1428
- const mql = factory({
1429
- MicrolinkError,
1430
- got,
1431
- flatten,
1432
- VERSION
1433
- });
1397
+ const got = async (url, { responseType, ...opts }) => {
1398
+ try {
1399
+ if (opts.timeout === undefined) opts.timeout = false;
1400
+ const response = await kyInstance(url, opts);
1401
+ const body = await response[responseType]();
1402
+ const { headers, status: statusCode } = response;
1403
+ return { url: response.url, body, headers, statusCode }
1404
+ } catch (error) {
1405
+ if (error.response) {
1406
+ const { response } = error;
1407
+ error.response = {
1408
+ ...response,
1409
+ headers: Array.from(response.headers.entries()).reduce(
1410
+ (acc, [key, value]) => {
1411
+ acc[key] = value;
1412
+ return acc
1413
+ },
1414
+ {}
1415
+ ),
1416
+ statusCode: response.status,
1417
+ body: await response.text()
1418
+ };
1419
+ }
1420
+ throw error
1421
+ }
1422
+ };
1423
+
1424
+ got.stream = (...args) => kyInstance(...args).then(res => res.body);
1425
+
1426
+ const mql = factory({
1427
+ MicrolinkError,
1428
+ got,
1429
+ flatten,
1430
+ VERSION
1431
+ });
1434
1432
 
1435
- lightweight.exports = mql;
1436
- var arrayBuffer = lightweight.exports.arrayBuffer = mql.extend({ responseType: 'arrayBuffer' });
1437
- var extend = lightweight.exports.extend = mql.extend;
1438
- var fetchFromApi = lightweight.exports.fetchFromApi = mql.fetchFromApi;
1439
- var getApiUrl = lightweight.exports.getApiUrl = mql.getApiUrl;
1440
- var mapRules = lightweight.exports.mapRules = mql.mapRules;
1441
- var MicrolinkError_1 = lightweight.exports.MicrolinkError = mql.MicrolinkError;
1442
- var version = lightweight.exports.version = mql.version;
1443
-
1444
- var lightweightExports = lightweight.exports;
1445
- var lightweight_default = /*@__PURE__*/getDefaultExportFromCjs(lightweightExports);
1446
-
1447
- exports.MicrolinkError = MicrolinkError_1;
1448
- exports.arrayBuffer = arrayBuffer;
1449
- exports.default = lightweight_default;
1450
- exports.extend = extend;
1451
- exports.fetchFromApi = fetchFromApi;
1452
- exports.getApiUrl = getApiUrl;
1453
- exports.mapRules = mapRules;
1454
- exports.version = version;
1455
-
1456
- Object.defineProperty(exports, '__esModule', { value: true });
1433
+ module.exports = mql;
1434
+ module.exports.arrayBuffer = mql.extend({ responseType: 'arrayBuffer' });
1435
+ module.exports.buffer = module.exports.arrayBuffer;
1436
+ module.exports.extend = mql.extend;
1437
+ module.exports.fetchFromApi = mql.fetchFromApi;
1438
+ module.exports.getApiUrl = mql.getApiUrl;
1439
+ module.exports.mapRules = mql.mapRules;
1440
+ module.exports.MicrolinkError = mql.MicrolinkError;
1441
+ module.exports.version = mql.version;
1442
+ } (src));
1443
+
1444
+ var srcExports = src.exports;
1445
+ var index = /*@__PURE__*/getDefaultExportFromCjs(srcExports);
1446
+
1447
+ return index;
1457
1448
 
1458
1449
  }));
package/package.json CHANGED
@@ -2,11 +2,11 @@
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.14.2",
6
- "types": "lightweight/index.d.ts",
5
+ "version": "0.15.0",
6
+ "types": "dist/index.d.ts",
7
7
  "exports": {
8
- "require": "./src/node.js",
9
- "default": "./lightweight/index.js"
8
+ "default": "./src/main.mjs",
9
+ "types": "./dist/index.d.ts"
10
10
  },
11
11
  "author": {
12
12
  "email": "josefrancisco.verdu@gmail.com",
@@ -47,8 +47,7 @@
47
47
  ],
48
48
  "dependencies": {
49
49
  "flattie": "~1.1.1",
50
- "got": "~11.8.6",
51
- "whoops": "~5.1.0"
50
+ "ky": "~1.14.3"
52
51
  },
53
52
  "devDependencies": {
54
53
  "@commitlint/cli": "latest",
@@ -59,38 +58,35 @@
59
58
  "@rollup/plugin-replace": "latest",
60
59
  "@rollup/plugin-terser": "latest",
61
60
  "async-listen": "latest",
62
- "ava": "5",
61
+ "ava": "7",
63
62
  "c8": "latest",
64
63
  "ci-publish": "latest",
65
64
  "git-authors-cli": "latest",
66
65
  "github-generate-release": "latest",
67
- "ky": "latest",
68
66
  "nano-staged": "latest",
69
67
  "prettier-standard": "latest",
70
68
  "rollup": "latest",
71
69
  "rollup-plugin-filesize": "latest",
72
- "rollup-plugin-rewrite": "latest",
73
- "rollup-plugin-visualizer": "latest",
74
70
  "simple-git-hooks": "latest",
75
71
  "standard": "latest",
76
72
  "standard-markdown": "latest",
77
73
  "standard-version": "latest",
78
- "stream-to-promise": "latest",
79
74
  "tsd": "latest"
80
75
  },
81
76
  "engines": {
82
77
  "node": ">= 18"
83
78
  },
84
79
  "files": [
85
- "lightweight",
80
+ "dist",
86
81
  "src/constants.js",
87
82
  "src/factory.js",
88
- "src/node.js"
83
+ "src/index.js",
84
+ "src/main.mjs"
89
85
  ],
90
86
  "scripts": {
91
87
  "build": "rollup -c rollup.config.js --bundleConfigAsCjs",
92
88
  "clean": "rm -rf node_modules",
93
- "clean:build": "rm -rf lightweight/index.js",
89
+ "clean:build": "rm -rf dist/index.js",
94
90
  "contributors": "(npx git-authors-cli && npx finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
95
91
  "dev": "npm run build -- -w",
96
92
  "lint": "standard && tsd",
@@ -139,12 +135,19 @@
139
135
  },
140
136
  "standard": {
141
137
  "ignore": [
142
- "lightweight/index.js",
143
- "lightweight/index.umd.js",
144
- "src/node.mjs"
138
+ "dist/index.js",
139
+ "dist/index.umd.js"
145
140
  ]
146
141
  },
147
142
  "tsd": {
143
+ "compilerOptions": {
144
+ "baseUrl": ".",
145
+ "paths": {
146
+ "@microlink/mql": [
147
+ "./dist/index.d.ts"
148
+ ]
149
+ }
150
+ },
148
151
  "directory": "test"
149
152
  }
150
153
  }
package/src/constants.js CHANGED
@@ -6,8 +6,7 @@ module.exports = {
6
6
  VERSION,
7
7
  USER_AGENT: `mql/${VERSION}`,
8
8
  /**
9
- * Based on require('got').defaults.options.retry.statusCodes
10
- * but without 429 (too many requests)
9
+ * Retry status codes, excluding 429 (too many requests).
11
10
  */
12
11
  RETRY_STATUS_CODES: [408, 413, 500, 502, 503, 504, 521, 522, 524]
13
12
  }
package/src/index.js ADDED
@@ -0,0 +1,71 @@
1
+ 'use strict'
2
+
3
+ const { flattie: flatten } = require('flattie')
4
+ const { default: ky } = require('ky')
5
+
6
+ const { VERSION, USER_AGENT, RETRY_STATUS_CODES } = require('./constants')
7
+
8
+ const kyInstance = ky.extend({
9
+ headers: { 'user-agent': USER_AGENT },
10
+ retry: { statusCodes: RETRY_STATUS_CODES }
11
+ })
12
+
13
+ const factory = require('./factory')('arrayBuffer')
14
+
15
+ class MicrolinkError extends Error {
16
+ constructor (props) {
17
+ super()
18
+ this.name = 'MicrolinkError'
19
+ Object.assign(this, props)
20
+ this.description = this.message
21
+ this.message = this.code
22
+ ? `${this.code}, ${this.description}`
23
+ : this.description
24
+ }
25
+ }
26
+
27
+ const got = async (url, { responseType, ...opts }) => {
28
+ try {
29
+ if (opts.timeout === undefined) opts.timeout = false
30
+ const response = await kyInstance(url, opts)
31
+ const body = await response[responseType]()
32
+ const { headers, status: statusCode } = response
33
+ return { url: response.url, body, headers, statusCode }
34
+ } catch (error) {
35
+ if (error.response) {
36
+ const { response } = error
37
+ error.response = {
38
+ ...response,
39
+ headers: Array.from(response.headers.entries()).reduce(
40
+ (acc, [key, value]) => {
41
+ acc[key] = value
42
+ return acc
43
+ },
44
+ {}
45
+ ),
46
+ statusCode: response.status,
47
+ body: await response.text()
48
+ }
49
+ }
50
+ throw error
51
+ }
52
+ }
53
+
54
+ got.stream = (...args) => kyInstance(...args).then(res => res.body)
55
+
56
+ const mql = factory({
57
+ MicrolinkError,
58
+ got,
59
+ flatten,
60
+ VERSION
61
+ })
62
+
63
+ module.exports = mql
64
+ module.exports.arrayBuffer = mql.extend({ responseType: 'arrayBuffer' })
65
+ module.exports.buffer = module.exports.arrayBuffer
66
+ module.exports.extend = mql.extend
67
+ module.exports.fetchFromApi = mql.fetchFromApi
68
+ module.exports.getApiUrl = mql.getApiUrl
69
+ module.exports.mapRules = mql.mapRules
70
+ module.exports.MicrolinkError = mql.MicrolinkError
71
+ module.exports.version = mql.version
package/src/main.mjs ADDED
@@ -0,0 +1,13 @@
1
+ import mql from '../dist/index.js'
2
+
3
+ export const arrayBuffer = mql.arrayBuffer
4
+ export const buffer = mql.buffer
5
+ export const extend = mql.extend
6
+ export const fetchFromApi = mql.fetchFromApi
7
+ export const getApiUrl = mql.getApiUrl
8
+ export const mapRules = mql.mapRules
9
+ export const MicrolinkError = mql.MicrolinkError
10
+ export const stream = mql.stream
11
+ export const version = mql.version
12
+
13
+ export default mql
package/src/node.js DELETED
@@ -1,24 +0,0 @@
1
- 'use strict'
2
-
3
- const got = require('got')
4
-
5
- const { VERSION, USER_AGENT, RETRY_STATUS_CODES } = require('./constants')
6
-
7
- const mql = require('./factory')('buffer')({
8
- MicrolinkError: require('whoops')('MicrolinkError'),
9
- got: got.extend({
10
- headers: { 'user-agent': USER_AGENT },
11
- retry: { statusCodes: RETRY_STATUS_CODES }
12
- }),
13
- flatten: require('flattie').flattie,
14
- VERSION
15
- })
16
-
17
- module.exports = mql
18
- module.exports.buffer = mql.extend({ responseType: 'buffer' })
19
- module.exports.render = (input, { width = '650px' } = {}) => {
20
- if (input && input.url && input.type) {
21
- return `<img width="${width}" src="${input.url}" />`
22
- }
23
- return input
24
- }
File without changes