@microlink/google 1.2.0 → 1.2.2
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/LICENSE.md +0 -0
- package/package.json +6 -5
- package/src/index.js +16 -5
package/LICENSE.md
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@microlink/google",
|
|
3
3
|
"description": "Structured Google data from 10 verticals through Microlink API",
|
|
4
4
|
"homepage": "https://github.com/microlinkhq/microlink",
|
|
5
|
-
"version": "1.2.
|
|
5
|
+
"version": "1.2.2",
|
|
6
6
|
"exports": {
|
|
7
7
|
"types": "./src/index.d.ts",
|
|
8
8
|
"require": "./src/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"serp"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@microlink/mql": "0.
|
|
39
|
+
"@microlink/mql": "0.19.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"ava": "latest",
|
|
@@ -58,12 +58,13 @@
|
|
|
58
58
|
"files": [
|
|
59
59
|
"src"
|
|
60
60
|
],
|
|
61
|
-
"license": "MIT",
|
|
62
61
|
"scripts": {
|
|
63
62
|
"build": "gulp build",
|
|
64
63
|
"dev": "tinyrun \"pnpm dev:src\" \"pnpm dev:server\"",
|
|
65
64
|
"dev:server": "browser-sync start --server docs --files \"docs/index.html, docs/README.md, docs/static/**/*.(css|js)\"",
|
|
66
65
|
"dev:src": "gulp",
|
|
67
66
|
"test": "exit 0"
|
|
68
|
-
}
|
|
69
|
-
|
|
67
|
+
},
|
|
68
|
+
"license": "MIT",
|
|
69
|
+
"gitHead": "c93fff8082b69c8e76bc159be82daf8a26b419bb"
|
|
70
|
+
}
|
package/src/index.js
CHANGED
|
@@ -27,10 +27,11 @@ const fetchDataField = async (url, mqlOpts, field, attr) => {
|
|
|
27
27
|
return data[field]
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const fetchPage = async (url, mqlOpts, page, query) => {
|
|
30
|
+
const fetchPage = async (url, mqlOpts, page, query, last) => {
|
|
31
31
|
if (page > 1) url.searchParams.set('page', String(page))
|
|
32
32
|
else url.searchParams.delete('page')
|
|
33
|
-
const { data } = await mql(url.toString(), mqlOpts)
|
|
33
|
+
const { data, response } = await mql(url.toString(), mqlOpts)
|
|
34
|
+
last.response = response
|
|
34
35
|
const { results, ...extra } = data
|
|
35
36
|
|
|
36
37
|
return {
|
|
@@ -59,7 +60,8 @@ const fetchPage = async (url, mqlOpts, page, query) => {
|
|
|
59
60
|
})
|
|
60
61
|
}
|
|
61
62
|
}),
|
|
62
|
-
next: () =>
|
|
63
|
+
next: () =>
|
|
64
|
+
fetchPage(new URL(url.toString()), mqlOpts, page + 1, query, last)
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
|
|
@@ -68,12 +70,19 @@ const resolve = async (item, key) => {
|
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
const createGoogleClient = ctxOpts => {
|
|
71
|
-
|
|
73
|
+
const last = {}
|
|
74
|
+
const client = async (
|
|
72
75
|
query,
|
|
73
76
|
{ limit, location, type, period, html, markdown, page = 1, ...opts } = {}
|
|
74
77
|
) => {
|
|
75
78
|
const url = buildUrl(query, { limit, location, type, period, page })
|
|
76
|
-
const result = await fetchPage(
|
|
79
|
+
const result = await fetchPage(
|
|
80
|
+
url,
|
|
81
|
+
{ ...ctxOpts, ...opts },
|
|
82
|
+
page,
|
|
83
|
+
query,
|
|
84
|
+
last
|
|
85
|
+
)
|
|
77
86
|
if (html) {
|
|
78
87
|
await resolve(result, 'html')
|
|
79
88
|
await Promise.all(result.results.map(item => resolve(item, 'html')))
|
|
@@ -84,6 +93,8 @@ const createGoogleClient = ctxOpts => {
|
|
|
84
93
|
}
|
|
85
94
|
return result
|
|
86
95
|
}
|
|
96
|
+
Object.defineProperty(client, 'last', { value: last })
|
|
97
|
+
return client
|
|
87
98
|
}
|
|
88
99
|
|
|
89
100
|
module.exports = createGoogleClient
|