@microlink/mql 0.14.1 → 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.
- package/{lightweight → dist}/index.d.ts +2 -2
- package/{lightweight → dist}/index.js +80 -80
- package/{lightweight → dist}/index.umd.js +84 -93
- package/package.json +21 -17
- package/src/constants.js +12 -0
- package/src/index.js +71 -0
- package/src/main.mjs +13 -0
- package/src/node.js +0 -24
- /package/{lightweight → dist}/package.json +0 -0
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
1209
|
+
const VERSION = '0.15.0';
|
|
1213
1210
|
|
|
1214
1211
|
var constants = {
|
|
1215
|
-
VERSION
|
|
1216
|
-
USER_AGENT: `mql/${VERSION
|
|
1212
|
+
VERSION,
|
|
1213
|
+
USER_AGENT: `mql/${VERSION}`,
|
|
1217
1214
|
/**
|
|
1218
|
-
*
|
|
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
|
|
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
|
|
1368
|
-
|
|
1369
|
-
const { flattie: flatten } = dist;
|
|
1370
|
-
const { default: ky } = require$$1;
|
|
1363
|
+
var factory_1 = factory;
|
|
1371
1364
|
|
|
1372
|
-
|
|
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
|
|
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
|
-
|
|
1370
|
+
const { VERSION, USER_AGENT, RETRY_STATUS_CODES } = constants;
|
|
1421
1371
|
|
|
1422
|
-
const
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
VERSION
|
|
1427
|
-
});
|
|
1372
|
+
const kyInstance = ky.extend({
|
|
1373
|
+
headers: { 'user-agent': USER_AGENT },
|
|
1374
|
+
retry: { statusCodes: RETRY_STATUS_CODES }
|
|
1375
|
+
});
|
|
1428
1376
|
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
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
|
-
|
|
1439
|
-
|
|
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
|
-
|
|
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(
|
|
3
|
-
typeof define === 'function' && define.amd ? define(
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self,
|
|
5
|
-
})(this, (function (
|
|
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
|
|
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
|
|
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
|
|
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
|
|
1215
|
+
const VERSION = '0.15.0';
|
|
1219
1216
|
|
|
1220
1217
|
var constants = {
|
|
1221
|
-
VERSION
|
|
1222
|
-
USER_AGENT: `mql/${VERSION
|
|
1218
|
+
VERSION,
|
|
1219
|
+
USER_AGENT: `mql/${VERSION}`,
|
|
1223
1220
|
/**
|
|
1224
|
-
*
|
|
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
|
|
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
|
|
1369
|
+
var factory_1 = factory;
|
|
1374
1370
|
|
|
1375
|
-
|
|
1376
|
-
const { default: ky } = require$$1;
|
|
1371
|
+
(function (module) {
|
|
1377
1372
|
|
|
1378
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
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
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
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.
|
|
6
|
-
"types": "
|
|
5
|
+
"version": "0.15.0",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
|
-
"
|
|
9
|
-
"
|
|
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
|
-
"
|
|
51
|
-
"whoops": "~5.1.0"
|
|
50
|
+
"ky": "~1.14.3"
|
|
52
51
|
},
|
|
53
52
|
"devDependencies": {
|
|
54
53
|
"@commitlint/cli": "latest",
|
|
@@ -59,37 +58,35 @@
|
|
|
59
58
|
"@rollup/plugin-replace": "latest",
|
|
60
59
|
"@rollup/plugin-terser": "latest",
|
|
61
60
|
"async-listen": "latest",
|
|
62
|
-
"ava": "
|
|
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
|
-
"
|
|
80
|
+
"dist",
|
|
81
|
+
"src/constants.js",
|
|
86
82
|
"src/factory.js",
|
|
87
|
-
"src/
|
|
83
|
+
"src/index.js",
|
|
84
|
+
"src/main.mjs"
|
|
88
85
|
],
|
|
89
86
|
"scripts": {
|
|
90
87
|
"build": "rollup -c rollup.config.js --bundleConfigAsCjs",
|
|
91
88
|
"clean": "rm -rf node_modules",
|
|
92
|
-
"clean:build": "rm -rf
|
|
89
|
+
"clean:build": "rm -rf dist/index.js",
|
|
93
90
|
"contributors": "(npx git-authors-cli && npx finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
|
|
94
91
|
"dev": "npm run build -- -w",
|
|
95
92
|
"lint": "standard && tsd",
|
|
@@ -138,12 +135,19 @@
|
|
|
138
135
|
},
|
|
139
136
|
"standard": {
|
|
140
137
|
"ignore": [
|
|
141
|
-
"
|
|
142
|
-
"
|
|
143
|
-
"src/node.mjs"
|
|
138
|
+
"dist/index.js",
|
|
139
|
+
"dist/index.umd.js"
|
|
144
140
|
]
|
|
145
141
|
},
|
|
146
142
|
"tsd": {
|
|
143
|
+
"compilerOptions": {
|
|
144
|
+
"baseUrl": ".",
|
|
145
|
+
"paths": {
|
|
146
|
+
"@microlink/mql": [
|
|
147
|
+
"./dist/index.d.ts"
|
|
148
|
+
]
|
|
149
|
+
}
|
|
150
|
+
},
|
|
147
151
|
"directory": "test"
|
|
148
152
|
}
|
|
149
153
|
}
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const VERSION = require('../package.json').version
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
VERSION,
|
|
7
|
+
USER_AGENT: `mql/${VERSION}`,
|
|
8
|
+
/**
|
|
9
|
+
* Retry status codes, excluding 429 (too many requests).
|
|
10
|
+
*/
|
|
11
|
+
RETRY_STATUS_CODES: [408, 413, 500, 502, 503, 504, 521, 522, 524]
|
|
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
|