@microlink/mql 0.10.33 → 0.10.35
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/README.md +2 -1
- package/dist/mql.js +221 -109
- package/dist/mql.js.map +1 -1
- package/dist/mql.min.js +2 -2
- package/dist/mql.min.js.map +1 -1
- package/dist/mql.min.mjs +2 -2
- package/dist/mql.min.mjs.map +1 -1
- package/dist/mql.mjs +221 -109
- package/dist/mql.mjs.map +1 -1
- package/index.d.ts +18 -227
- package/lightweight/index.d.ts +172 -0
- package/lightweight/package.json +2 -2
- package/package.json +11 -13
- package/src/factory.js +1 -5
- package/src/ky.js +203 -92
- package/src/{browser.js → lightweight.js} +1 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
type ColorScheme = | "dark" | "light";
|
|
2
|
+
|
|
3
|
+
type WaitUntilEvent = "load" | "domcontentloaded" | "networkidle0" | "networkidle2";
|
|
4
|
+
|
|
5
|
+
type PixelUnit = string | number;
|
|
6
|
+
|
|
7
|
+
type ScreenshotOverlay = {
|
|
8
|
+
background?: string,
|
|
9
|
+
browser?: 'dark' | 'light'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type PdfMargin = {
|
|
13
|
+
top?: string | number;
|
|
14
|
+
bottom?: string | number;
|
|
15
|
+
left?: string | number;
|
|
16
|
+
right?: string | number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type PdfOptions = {
|
|
20
|
+
format?: string;
|
|
21
|
+
height?: PixelUnit;
|
|
22
|
+
landscape?: string;
|
|
23
|
+
margin?: string | PdfMargin;
|
|
24
|
+
pageRanges?: string;
|
|
25
|
+
scale?: number;
|
|
26
|
+
width?: PixelUnit;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type ScreenshotOptions = {
|
|
30
|
+
codeScheme?: string;
|
|
31
|
+
omitBackground?: boolean;
|
|
32
|
+
type?: "jpeg" | "png";
|
|
33
|
+
element?: string;
|
|
34
|
+
fullPage?: boolean;
|
|
35
|
+
overlay?: ScreenshotOverlay
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type MqlOptions = {
|
|
39
|
+
endpoint?: string;
|
|
40
|
+
apiKey?: string;
|
|
41
|
+
retry?: number;
|
|
42
|
+
cache?: Map<string, any>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
type MqlQuery = {
|
|
46
|
+
[field: string]: MqlQueryOptions;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type MqlQueryOptions = {
|
|
50
|
+
attr?: string | string[] | MqlQuery;
|
|
51
|
+
evaluate?: string;
|
|
52
|
+
selector?: string | string[];
|
|
53
|
+
selectorAll?: string | string[];
|
|
54
|
+
type?: "audio" | "author" | "auto" | "boolean" | "date" | "description" | "email" | "image" | "ip" | "lang" | "logo" | "number" | "object" | "publisher" | "regexp" | "string" | "title" | "url" | "video";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type MicrolinkApiOptions = {
|
|
58
|
+
adblock?: boolean;
|
|
59
|
+
animations?: boolean;
|
|
60
|
+
audio?: boolean;
|
|
61
|
+
click?: string | string[];
|
|
62
|
+
colorScheme?: ColorScheme;
|
|
63
|
+
data?: MqlQuery;
|
|
64
|
+
device?: string;
|
|
65
|
+
embed?: string;
|
|
66
|
+
filename?: string;
|
|
67
|
+
filter?: string;
|
|
68
|
+
force?: boolean;
|
|
69
|
+
function?: string;
|
|
70
|
+
headers?: Record<string, string>;
|
|
71
|
+
iframe?: boolean | { maxWidth?: number, maxHeight?: number };
|
|
72
|
+
insights?: boolean | { lighthouse?: boolean | object, technologies?: boolean };
|
|
73
|
+
javascript?: boolean;
|
|
74
|
+
mediaType?: string;
|
|
75
|
+
meta?: boolean | { logo: { square: boolean } };
|
|
76
|
+
modules?: string | string[];
|
|
77
|
+
palette?: boolean;
|
|
78
|
+
pdf?: boolean | PdfOptions;
|
|
79
|
+
ping?: boolean | object;
|
|
80
|
+
prerender?: boolean | "auto";
|
|
81
|
+
proxy?: string | { countryCode?: string };
|
|
82
|
+
retry?: number;
|
|
83
|
+
screenshot?: boolean | ScreenshotOptions;
|
|
84
|
+
scripts?: string | string[];
|
|
85
|
+
scroll?: string;
|
|
86
|
+
styles?: string | string[];
|
|
87
|
+
staleTtl?: string | number;
|
|
88
|
+
timeout?: number;
|
|
89
|
+
ttl?: string | number;
|
|
90
|
+
video?: boolean;
|
|
91
|
+
viewport?: object;
|
|
92
|
+
waitForSelector?: string;
|
|
93
|
+
waitForTimeout?: number;
|
|
94
|
+
waitUntil?: WaitUntilEvent | WaitUntilEvent[];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
type IframeInfo = {
|
|
98
|
+
html: string;
|
|
99
|
+
scripts: Record<string, unknown>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
type MediaInfo = {
|
|
103
|
+
type?: string;
|
|
104
|
+
palette?: string[];
|
|
105
|
+
background_color?: string;
|
|
106
|
+
color?: string;
|
|
107
|
+
alternative_color?: string;
|
|
108
|
+
width?: number;
|
|
109
|
+
height?: number;
|
|
110
|
+
duration?: number;
|
|
111
|
+
duration_pretty?: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
type MqlResponseData = {
|
|
115
|
+
// A human-readable representation of the author's name.
|
|
116
|
+
author?: string | null;
|
|
117
|
+
// An ISO 8601 representation of the date the article was published.
|
|
118
|
+
date?: string | null;
|
|
119
|
+
// The publisher's chosen description of the article.
|
|
120
|
+
description?: string | null;
|
|
121
|
+
// An ISO 639-1 representation of the url content language.
|
|
122
|
+
lang?: string | null;
|
|
123
|
+
// An image URL that best represents the publisher brand.
|
|
124
|
+
logo?: MediaInfo | null;
|
|
125
|
+
// A human-readable representation of the publisher's name.
|
|
126
|
+
publisher?: string | null;
|
|
127
|
+
// The publisher's chosen title of the article.
|
|
128
|
+
title?: string | null;
|
|
129
|
+
// The URL of the article.
|
|
130
|
+
url?: string;
|
|
131
|
+
image?: MediaInfo | null;
|
|
132
|
+
screenshot?: MediaInfo | null;
|
|
133
|
+
video?: MediaInfo | null;
|
|
134
|
+
audio?: MediaInfo | null;
|
|
135
|
+
iframe?: IframeInfo | null;
|
|
136
|
+
function?: MqlFunctionResult;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
type MqlFunctionResult = {
|
|
140
|
+
isFulfilled: boolean;
|
|
141
|
+
isRejected: boolean;
|
|
142
|
+
value: any;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
type MqlStatus = "success" | "fail" | "error";
|
|
146
|
+
|
|
147
|
+
export type MqlPayload = {
|
|
148
|
+
status: MqlStatus;
|
|
149
|
+
data: MqlResponseData;
|
|
150
|
+
statusCode: number;
|
|
151
|
+
headers: { [key: string]: string };
|
|
152
|
+
more?: string,
|
|
153
|
+
code?: string,
|
|
154
|
+
url?: string
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
type MqlResponse = MqlPayload & {
|
|
158
|
+
response: {
|
|
159
|
+
url: string;
|
|
160
|
+
statusCode: number;
|
|
161
|
+
headers: Headers;
|
|
162
|
+
body: MqlPayload
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
declare function mql(
|
|
167
|
+
url: string,
|
|
168
|
+
opts?: MqlOptions & MicrolinkApiOptions,
|
|
169
|
+
gotOpts?: object
|
|
170
|
+
): Promise<MqlResponse>;
|
|
171
|
+
|
|
172
|
+
export default mql;
|
package/lightweight/package.json
CHANGED
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
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://nicedoc.io/microlinkhq/mql",
|
|
5
|
-
"version": "0.10.
|
|
6
|
-
"browser": "src/
|
|
5
|
+
"version": "0.10.35",
|
|
6
|
+
"browser": "src/lightweight.js",
|
|
7
7
|
"main": "src/node.js",
|
|
8
8
|
"author": {
|
|
9
9
|
"email": "josefrancisco.verdu@gmail.com",
|
|
@@ -51,25 +51,20 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@commitlint/cli": "latest",
|
|
53
53
|
"@commitlint/config-conventional": "latest",
|
|
54
|
+
"@ksmithut/prettier-standard": "latest",
|
|
54
55
|
"@rollup/plugin-commonjs": "latest",
|
|
55
56
|
"@rollup/plugin-node-resolve": "latest",
|
|
56
57
|
"@rollup/plugin-replace": "latest",
|
|
57
58
|
"@rollup/plugin-terser": "latest",
|
|
58
|
-
"
|
|
59
|
+
"async-listen": "latest",
|
|
59
60
|
"ava": "3",
|
|
60
|
-
"beauty-error": "latest",
|
|
61
61
|
"c8": "latest",
|
|
62
|
-
"chalk": "latest",
|
|
63
62
|
"ci-publish": "latest",
|
|
64
63
|
"conventional-github-releaser": "latest",
|
|
65
|
-
"eachdir": "latest",
|
|
66
64
|
"esm": "latest",
|
|
67
|
-
"exists-file": "latest",
|
|
68
65
|
"git-authors-cli": "latest",
|
|
69
66
|
"ky": "latest",
|
|
70
|
-
"meow": "latest",
|
|
71
67
|
"nano-staged": "latest",
|
|
72
|
-
"node-fetch": "2",
|
|
73
68
|
"npm-check-updates": "latest",
|
|
74
69
|
"prettier-standard": "latest",
|
|
75
70
|
"rollup": "latest",
|
|
@@ -80,8 +75,7 @@
|
|
|
80
75
|
"standard-markdown": "latest",
|
|
81
76
|
"standard-version": "latest",
|
|
82
77
|
"stream-to-promise": "latest",
|
|
83
|
-
"
|
|
84
|
-
"web-streams-polyfill": "latest"
|
|
78
|
+
"tsd": "latest"
|
|
85
79
|
},
|
|
86
80
|
"engines": {
|
|
87
81
|
"node": ">= 12"
|
|
@@ -99,7 +93,7 @@
|
|
|
99
93
|
"clean:build": "rm -rf dist",
|
|
100
94
|
"contributors": "(npx git-authors-cli && npx finepack --sort-ignore-object-at ava && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
|
|
101
95
|
"dev": "npm run build -- -w",
|
|
102
|
-
"lint": "standard",
|
|
96
|
+
"lint": "standard && tsd",
|
|
103
97
|
"postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
|
|
104
98
|
"prebuild": "npm run clean:build && npm run build:kys",
|
|
105
99
|
"prerelease": "npm run update:check",
|
|
@@ -130,7 +124,8 @@
|
|
|
130
124
|
},
|
|
131
125
|
"nano-staged": {
|
|
132
126
|
"*.js,!*.min.js,": [
|
|
133
|
-
"prettier-standard"
|
|
127
|
+
"prettier-standard",
|
|
128
|
+
"standard --fix"
|
|
134
129
|
],
|
|
135
130
|
"*.md": [
|
|
136
131
|
"standard-markdown"
|
|
@@ -154,6 +149,9 @@
|
|
|
154
149
|
"postbump": "npm run build"
|
|
155
150
|
}
|
|
156
151
|
},
|
|
152
|
+
"tsd": {
|
|
153
|
+
"directory": "test"
|
|
154
|
+
},
|
|
157
155
|
"types": "index.d.ts",
|
|
158
156
|
"umd:main": "dist/mql.js",
|
|
159
157
|
"unpkg": "dist/mql.js"
|
package/src/factory.js
CHANGED
|
@@ -52,7 +52,7 @@ const factory = ({ VERSION, MicrolinkError, urlHttp, got, flatten }) => {
|
|
|
52
52
|
}, {})
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
const fetchFromApi = async (apiUrl, opts = {}
|
|
55
|
+
const fetchFromApi = async (apiUrl, opts = {}) => {
|
|
56
56
|
try {
|
|
57
57
|
const response = await got(apiUrl, opts)
|
|
58
58
|
return opts.responseType === 'buffer'
|
|
@@ -73,10 +73,6 @@ const factory = ({ VERSION, MicrolinkError, urlHttp, got, flatten }) => {
|
|
|
73
73
|
? rawBody
|
|
74
74
|
: parseBody(isBodyBuffer ? rawBody.toString() : rawBody, err, uri)
|
|
75
75
|
|
|
76
|
-
if (body.code === 'EFATALCLIENT' && retryCount++ < 2) {
|
|
77
|
-
return fetchFromApi(apiUrl, opts, retryCount)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
76
|
throw new MicrolinkError({
|
|
81
77
|
...body,
|
|
82
78
|
message: body.message,
|