@microlink/google 1.0.5 → 1.2.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/LICENSE.md +0 -0
- package/package.json +8 -56
- package/src/index.d.ts +4 -0
- package/src/index.js +25 -13
package/LICENSE.md
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microlink/google",
|
|
3
3
|
"description": "Structured Google data from 10 verticals through Microlink API",
|
|
4
|
-
"homepage": "https://github.com/microlinkhq/
|
|
5
|
-
"version": "1.0
|
|
4
|
+
"homepage": "https://github.com/microlinkhq/microlink",
|
|
5
|
+
"version": "1.2.0",
|
|
6
6
|
"exports": {
|
|
7
7
|
"types": "./src/index.d.ts",
|
|
8
8
|
"require": "./src/index.js",
|
|
@@ -21,46 +21,34 @@
|
|
|
21
21
|
}
|
|
22
22
|
],
|
|
23
23
|
"repository": {
|
|
24
|
+
"directory": "packages/search",
|
|
24
25
|
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/microlinkhq/
|
|
26
|
+
"url": "git+https://github.com/microlinkhq/microlink.git"
|
|
26
27
|
},
|
|
27
28
|
"bugs": {
|
|
28
|
-
"url": "https://github.com/microlinkhq/
|
|
29
|
+
"url": "https://github.com/microlinkhq/microlink/issues"
|
|
29
30
|
},
|
|
30
31
|
"keywords": [
|
|
31
32
|
"google",
|
|
32
33
|
"integration",
|
|
33
34
|
"microlink",
|
|
34
35
|
"search",
|
|
35
|
-
"search",
|
|
36
36
|
"serp"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@microlink/mql": "
|
|
39
|
+
"@microlink/mql": "0.18.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@commitlint/cli": "latest",
|
|
43
|
-
"@commitlint/config-conventional": "latest",
|
|
44
42
|
"ava": "latest",
|
|
45
43
|
"browser-sync": "latest",
|
|
46
|
-
"c8": "latest",
|
|
47
|
-
"ci-publish": "latest",
|
|
48
|
-
"conventional-changelog-cli": "latest",
|
|
49
44
|
"cssnano": "latest",
|
|
50
45
|
"cssnano-preset-advanced": "latest",
|
|
51
|
-
"finepack": "latest",
|
|
52
|
-
"git-authors-cli": "latest",
|
|
53
|
-
"github-generate-release": "latest",
|
|
54
46
|
"gulp": "latest",
|
|
55
47
|
"gulp-concat": "latest",
|
|
56
48
|
"gulp-postcss": "latest",
|
|
57
49
|
"gulp-uglify": "latest",
|
|
58
|
-
"nano-staged": "latest",
|
|
59
50
|
"postcss-focus": "latest",
|
|
60
51
|
"proxyquire": "latest",
|
|
61
|
-
"simple-git-hooks": "latest",
|
|
62
|
-
"standard": "latest",
|
|
63
|
-
"standard-version": "latest",
|
|
64
52
|
"tinyrun": "latest",
|
|
65
53
|
"tinyspawn": "latest"
|
|
66
54
|
},
|
|
@@ -70,48 +58,12 @@
|
|
|
70
58
|
"files": [
|
|
71
59
|
"src"
|
|
72
60
|
],
|
|
61
|
+
"license": "MIT",
|
|
73
62
|
"scripts": {
|
|
74
63
|
"build": "gulp build",
|
|
75
|
-
"clean": "rm -rf node_modules",
|
|
76
|
-
"contributors": "(git-authors-cli && finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
|
|
77
|
-
"coverage": "c8 report --reporter=text-lcov > coverage/lcov.info",
|
|
78
64
|
"dev": "tinyrun \"pnpm dev:src\" \"pnpm dev:server\"",
|
|
79
65
|
"dev:server": "browser-sync start --server docs --files \"docs/index.html, docs/README.md, docs/static/**/*.(css|js)\"",
|
|
80
66
|
"dev:src": "gulp",
|
|
81
|
-
"lint": "standard",
|
|
82
|
-
"postrelease": "pnpm release:tags && pnpm release:github && (ci-publish || pnpm publish --access=public)",
|
|
83
|
-
"pretest": "pnpm lint",
|
|
84
|
-
"release": "pnpm release:version && pnpm release:changelog && pnpm release:commit && pnpm release:tag",
|
|
85
|
-
"release:changelog": "conventional-changelog -p conventionalcommits -i CHANGELOG.md -s",
|
|
86
|
-
"release:commit": "git add package.json CHANGELOG.md && git commit -m \"chore(release): $(node -p \"require('./package.json').version\")\"",
|
|
87
|
-
"release:github": "github-generate-release",
|
|
88
|
-
"release:tag": "git tag -a v$(node -p \"require('./package.json').version\") -m \"v$(node -p \"require('./package.json').version\")\"",
|
|
89
|
-
"release:tags": "git push origin HEAD:master --follow-tags",
|
|
90
|
-
"release:version": "standard-version --skip.changelog --skip.commit --skip.tag",
|
|
91
67
|
"test": "exit 0"
|
|
92
|
-
},
|
|
93
|
-
"license": "MIT",
|
|
94
|
-
"commitlint": {
|
|
95
|
-
"extends": [
|
|
96
|
-
"@commitlint/config-conventional"
|
|
97
|
-
],
|
|
98
|
-
"rules": {
|
|
99
|
-
"body-max-line-length": [
|
|
100
|
-
0
|
|
101
|
-
]
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
"nano-staged": {
|
|
105
|
-
"*.js": [
|
|
106
|
-
"npx @kikobeats/prettier-standard",
|
|
107
|
-
"standard --fix"
|
|
108
|
-
],
|
|
109
|
-
"package.json": [
|
|
110
|
-
"finepack"
|
|
111
|
-
]
|
|
112
|
-
},
|
|
113
|
-
"simple-git-hooks": {
|
|
114
|
-
"commit-msg": "npx commitlint --edit",
|
|
115
|
-
"pre-commit": "npx nano-staged"
|
|
116
68
|
}
|
|
117
|
-
}
|
|
69
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -56,6 +56,9 @@ interface Options {
|
|
|
56
56
|
limit?: number
|
|
57
57
|
location?: Location
|
|
58
58
|
period?: Period
|
|
59
|
+
page?: number
|
|
60
|
+
html?: boolean
|
|
61
|
+
markdown?: boolean
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
interface Sitelink {
|
|
@@ -315,6 +318,7 @@ export declare function buildUrl(
|
|
|
315
318
|
location?: string
|
|
316
319
|
type?: Type
|
|
317
320
|
period?: Period
|
|
321
|
+
page?: number
|
|
318
322
|
}
|
|
319
323
|
): URL
|
|
320
324
|
|
package/src/index.js
CHANGED
|
@@ -9,10 +9,11 @@ const buildPath = (query, limit, location) =>
|
|
|
9
9
|
.filter(v => v !== undefined)
|
|
10
10
|
.join('/')
|
|
11
11
|
|
|
12
|
-
const buildUrl = (query, { limit, location, type, period } = {}) => {
|
|
12
|
+
const buildUrl = (query, { limit, location, type, period, page } = {}) => {
|
|
13
13
|
const url = new URL(`https://${DOMAIN}/${buildPath(query, limit, location)}`)
|
|
14
14
|
if (type) url.searchParams.set('type', type)
|
|
15
15
|
if (period) url.searchParams.set('period', period)
|
|
16
|
+
if (page > 1) url.searchParams.set('page', String(page))
|
|
16
17
|
return url
|
|
17
18
|
}
|
|
18
19
|
|
|
@@ -26,8 +27,9 @@ const fetchDataField = async (url, mqlOpts, field, attr) => {
|
|
|
26
27
|
return data[field]
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
const fetchPage = async (url, mqlOpts,
|
|
30
|
-
url.searchParams.set('
|
|
30
|
+
const fetchPage = async (url, mqlOpts, page, query) => {
|
|
31
|
+
if (page > 1) url.searchParams.set('page', String(page))
|
|
32
|
+
else url.searchParams.delete('page')
|
|
31
33
|
const { data } = await mql(url.toString(), mqlOpts)
|
|
32
34
|
const { results, ...extra } = data
|
|
33
35
|
|
|
@@ -57,20 +59,30 @@ const fetchPage = async (url, mqlOpts, offset, query) => {
|
|
|
57
59
|
})
|
|
58
60
|
}
|
|
59
61
|
}),
|
|
60
|
-
next: () =>
|
|
61
|
-
fetchPage(
|
|
62
|
-
new URL(url.toString()),
|
|
63
|
-
mqlOpts,
|
|
64
|
-
offset + results.length,
|
|
65
|
-
query
|
|
66
|
-
)
|
|
62
|
+
next: () => fetchPage(new URL(url.toString()), mqlOpts, page + 1, query)
|
|
67
63
|
}
|
|
68
64
|
}
|
|
69
65
|
|
|
66
|
+
const resolve = async (item, key) => {
|
|
67
|
+
if (typeof item[key] === 'function') item[key] = await item[key]()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
70
|
const createGoogleClient = ctxOpts => {
|
|
71
|
-
return async (
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
return async (
|
|
72
|
+
query,
|
|
73
|
+
{ limit, location, type, period, html, markdown, page = 1, ...opts } = {}
|
|
74
|
+
) => {
|
|
75
|
+
const url = buildUrl(query, { limit, location, type, period, page })
|
|
76
|
+
const result = await fetchPage(url, { ...ctxOpts, ...opts }, page, query)
|
|
77
|
+
if (html) {
|
|
78
|
+
await resolve(result, 'html')
|
|
79
|
+
await Promise.all(result.results.map(item => resolve(item, 'html')))
|
|
80
|
+
}
|
|
81
|
+
if (markdown) {
|
|
82
|
+
await resolve(result, 'markdown')
|
|
83
|
+
await Promise.all(result.results.map(item => resolve(item, 'markdown')))
|
|
84
|
+
}
|
|
85
|
+
return result
|
|
74
86
|
}
|
|
75
87
|
}
|
|
76
88
|
|