@microlink/mql 0.18.0 → 0.19.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/dist/index.d.ts +21 -3
- package/dist/index.js +12 -5
- package/dist/index.umd.js +12 -5
- package/package.json +2 -2
- package/src/index.js +11 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export type ColorScheme = 'dark' | 'light'
|
|
1
|
+
export type ColorScheme = 'dark' | 'light' | 'no-preference'
|
|
2
2
|
|
|
3
3
|
type WaitUntilEvent =
|
|
4
|
+
| 'auto'
|
|
4
5
|
| 'load'
|
|
5
6
|
| 'domcontentloaded'
|
|
6
7
|
| 'networkidle0'
|
|
@@ -31,15 +32,30 @@ type PdfOptions = {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
type ScreenshotOptions = {
|
|
35
|
+
animated?: boolean
|
|
34
36
|
codeScheme?: string
|
|
35
37
|
element?: string
|
|
36
38
|
fullPage?: boolean
|
|
37
39
|
omitBackground?: boolean
|
|
38
40
|
optimizeForSpeed?: boolean
|
|
39
41
|
overlay?: ScreenshotOverlay
|
|
42
|
+
palette?: boolean
|
|
43
|
+
quality?: number
|
|
40
44
|
type?: 'jpeg' | 'png'
|
|
41
45
|
}
|
|
42
46
|
|
|
47
|
+
type MetaOptions = {
|
|
48
|
+
author?: boolean
|
|
49
|
+
date?: boolean
|
|
50
|
+
description?: boolean
|
|
51
|
+
image?: boolean
|
|
52
|
+
lang?: boolean
|
|
53
|
+
logo?: boolean | { square: boolean }
|
|
54
|
+
publisher?: boolean
|
|
55
|
+
title?: boolean
|
|
56
|
+
url?: boolean
|
|
57
|
+
}
|
|
58
|
+
|
|
43
59
|
type MqlClientOptions = {
|
|
44
60
|
apiKey?: string
|
|
45
61
|
endpoint?: string
|
|
@@ -81,6 +97,7 @@ export type MicrolinkApiOptions = {
|
|
|
81
97
|
adblock?: boolean
|
|
82
98
|
animations?: boolean
|
|
83
99
|
audio?: boolean
|
|
100
|
+
cacheKey?: string
|
|
84
101
|
click?: string | string[]
|
|
85
102
|
colorScheme?: ColorScheme
|
|
86
103
|
data?: MqlQuery
|
|
@@ -95,13 +112,13 @@ export type MicrolinkApiOptions = {
|
|
|
95
112
|
insights?: boolean | { lighthouse?: boolean | object; technologies?: boolean }
|
|
96
113
|
javascript?: boolean
|
|
97
114
|
mediaType?: string
|
|
98
|
-
meta?: boolean |
|
|
115
|
+
meta?: boolean | MetaOptions
|
|
99
116
|
modules?: string | string[]
|
|
100
117
|
palette?: boolean
|
|
101
118
|
pdf?: boolean | PdfOptions
|
|
102
119
|
ping?: boolean | object
|
|
103
120
|
prerender?: boolean | 'auto'
|
|
104
|
-
proxy?: string | {
|
|
121
|
+
proxy?: string | { url: string } | { location: string }
|
|
105
122
|
retry?: number
|
|
106
123
|
screenshot?: boolean | ScreenshotOptions
|
|
107
124
|
scripts?: string | string[]
|
|
@@ -194,6 +211,7 @@ export type MqlErrorProps = {
|
|
|
194
211
|
code: string
|
|
195
212
|
status: MqlStatus
|
|
196
213
|
message: string
|
|
214
|
+
cause?: Error
|
|
197
215
|
data?: MqlResponseData
|
|
198
216
|
headers?: { [key: string]: string }
|
|
199
217
|
more?: string
|
package/dist/index.js
CHANGED
|
@@ -1869,7 +1869,7 @@ var distribution = /*#__PURE__*/Object.freeze({
|
|
|
1869
1869
|
|
|
1870
1870
|
var require$$1 = /*@__PURE__*/getAugmentedNamespace(distribution);
|
|
1871
1871
|
|
|
1872
|
-
const VERSION = '0.
|
|
1872
|
+
const VERSION = '0.19.0';
|
|
1873
1873
|
|
|
1874
1874
|
var constants = {
|
|
1875
1875
|
VERSION,
|
|
@@ -1919,11 +1919,17 @@ var constants = {
|
|
|
1919
1919
|
typeof input?.constructor?.isBuffer === 'function' &&
|
|
1920
1920
|
input.constructor.isBuffer(input);
|
|
1921
1921
|
|
|
1922
|
+
const rootCause = error => {
|
|
1923
|
+
let cause = error;
|
|
1924
|
+
while (cause?.cause instanceof Error) cause = cause.cause;
|
|
1925
|
+
return cause
|
|
1926
|
+
};
|
|
1927
|
+
|
|
1922
1928
|
const parseBody = (input, error, url) => {
|
|
1923
1929
|
try {
|
|
1924
1930
|
return JSON.parse(input)
|
|
1925
1931
|
} catch (_) {
|
|
1926
|
-
const message = input || error.message;
|
|
1932
|
+
const message = input || rootCause(error).message;
|
|
1927
1933
|
|
|
1928
1934
|
return {
|
|
1929
1935
|
status: 'error',
|
|
@@ -1946,8 +1952,8 @@ var constants = {
|
|
|
1946
1952
|
};
|
|
1947
1953
|
|
|
1948
1954
|
class MicrolinkError extends Error {
|
|
1949
|
-
constructor (props) {
|
|
1950
|
-
super();
|
|
1955
|
+
constructor ({ cause, ...props }) {
|
|
1956
|
+
super(undefined, cause ? { cause } : undefined);
|
|
1951
1957
|
this.name = 'MicrolinkError';
|
|
1952
1958
|
Object.assign(this, props);
|
|
1953
1959
|
this.description = this.message;
|
|
@@ -2034,7 +2040,8 @@ var constants = {
|
|
|
2034
2040
|
...body,
|
|
2035
2041
|
url: uri,
|
|
2036
2042
|
statusCode,
|
|
2037
|
-
headers
|
|
2043
|
+
headers,
|
|
2044
|
+
cause: error
|
|
2038
2045
|
})
|
|
2039
2046
|
}
|
|
2040
2047
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1875,7 +1875,7 @@
|
|
|
1875
1875
|
|
|
1876
1876
|
var require$$1 = /*@__PURE__*/getAugmentedNamespace(distribution);
|
|
1877
1877
|
|
|
1878
|
-
const VERSION = '0.
|
|
1878
|
+
const VERSION = '0.19.0';
|
|
1879
1879
|
|
|
1880
1880
|
var constants = {
|
|
1881
1881
|
VERSION,
|
|
@@ -1925,11 +1925,17 @@
|
|
|
1925
1925
|
typeof input?.constructor?.isBuffer === 'function' &&
|
|
1926
1926
|
input.constructor.isBuffer(input);
|
|
1927
1927
|
|
|
1928
|
+
const rootCause = error => {
|
|
1929
|
+
let cause = error;
|
|
1930
|
+
while (cause?.cause instanceof Error) cause = cause.cause;
|
|
1931
|
+
return cause
|
|
1932
|
+
};
|
|
1933
|
+
|
|
1928
1934
|
const parseBody = (input, error, url) => {
|
|
1929
1935
|
try {
|
|
1930
1936
|
return JSON.parse(input)
|
|
1931
1937
|
} catch (_) {
|
|
1932
|
-
const message = input || error.message;
|
|
1938
|
+
const message = input || rootCause(error).message;
|
|
1933
1939
|
|
|
1934
1940
|
return {
|
|
1935
1941
|
status: 'error',
|
|
@@ -1952,8 +1958,8 @@
|
|
|
1952
1958
|
};
|
|
1953
1959
|
|
|
1954
1960
|
class MicrolinkError extends Error {
|
|
1955
|
-
constructor (props) {
|
|
1956
|
-
super();
|
|
1961
|
+
constructor ({ cause, ...props }) {
|
|
1962
|
+
super(undefined, cause ? { cause } : undefined);
|
|
1957
1963
|
this.name = 'MicrolinkError';
|
|
1958
1964
|
Object.assign(this, props);
|
|
1959
1965
|
this.description = this.message;
|
|
@@ -2040,7 +2046,8 @@
|
|
|
2040
2046
|
...body,
|
|
2041
2047
|
url: uri,
|
|
2042
2048
|
statusCode,
|
|
2043
|
-
headers
|
|
2049
|
+
headers,
|
|
2050
|
+
cause: error
|
|
2044
2051
|
})
|
|
2045
2052
|
}
|
|
2046
2053
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@microlink/mql",
|
|
3
3
|
"description": "Microlink Query Language. The official HTTP client to interact with Microlink API for Node.js, browsers & Deno.",
|
|
4
4
|
"homepage": "https://microlink.io/mql",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.19.0",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
},
|
|
102
102
|
"directory": "test"
|
|
103
103
|
},
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "c93fff8082b69c8e76bc159be82daf8a26b419bb"
|
|
105
105
|
}
|
package/src/index.js
CHANGED
|
@@ -31,11 +31,17 @@ const isBuffer = input =>
|
|
|
31
31
|
typeof input?.constructor?.isBuffer === 'function' &&
|
|
32
32
|
input.constructor.isBuffer(input)
|
|
33
33
|
|
|
34
|
+
const rootCause = error => {
|
|
35
|
+
let cause = error
|
|
36
|
+
while (cause?.cause instanceof Error) cause = cause.cause
|
|
37
|
+
return cause
|
|
38
|
+
}
|
|
39
|
+
|
|
34
40
|
const parseBody = (input, error, url) => {
|
|
35
41
|
try {
|
|
36
42
|
return JSON.parse(input)
|
|
37
43
|
} catch (_) {
|
|
38
|
-
const message = input || error.message
|
|
44
|
+
const message = input || rootCause(error).message
|
|
39
45
|
|
|
40
46
|
return {
|
|
41
47
|
status: 'error',
|
|
@@ -58,8 +64,8 @@ const isURL = url => {
|
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
class MicrolinkError extends Error {
|
|
61
|
-
constructor (props) {
|
|
62
|
-
super()
|
|
67
|
+
constructor ({ cause, ...props }) {
|
|
68
|
+
super(undefined, cause ? { cause } : undefined)
|
|
63
69
|
this.name = 'MicrolinkError'
|
|
64
70
|
Object.assign(this, props)
|
|
65
71
|
this.description = this.message
|
|
@@ -146,7 +152,8 @@ const fetchFromApi = async (apiUrl, opts = {}) => {
|
|
|
146
152
|
...body,
|
|
147
153
|
url: uri,
|
|
148
154
|
statusCode,
|
|
149
|
-
headers
|
|
155
|
+
headers,
|
|
156
|
+
cause: error
|
|
150
157
|
})
|
|
151
158
|
}
|
|
152
159
|
}
|