-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8cf91a9
Showing
18 changed files
with
390 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
files: | ||
- package.json | ||
plugins: | ||
prerelease: | ||
Linting config files: | ||
plugin: bumped-finepack | ||
postrelease: | ||
Generating CHANGELOG file: | ||
plugin: bumped-changelog | ||
Committing new version: | ||
plugin: bumped-terminal | ||
command: 'git add CHANGELOG.md package.json && git commit -m "Release $newVersion"' | ||
Detecting problems before publish: | ||
plugin: bumped-terminal | ||
command: 'git-dirty && npm test' | ||
Publishing tag to GitHub: | ||
plugin: bumped-terminal | ||
command: 'git tag $newVersion && git push && git push --tags' | ||
Publishing to NPM: | ||
plugin: bumped-terminal | ||
command: npm publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
max_line_length = 100 | ||
indent_brace_style = 1TBS | ||
spaces_around_operators = true | ||
quote_type = auto | ||
|
||
[package.json] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
############################ | ||
# npm | ||
############################ | ||
node_modules | ||
npm-debug.log | ||
.node_history | ||
yarn.lock | ||
package-lock.json | ||
|
||
############################ | ||
# tmp, editor & OS files | ||
############################ | ||
.tmp | ||
*.swo | ||
*.swp | ||
*.swn | ||
*.swm | ||
.DS_Store | ||
*# | ||
*~ | ||
.idea | ||
*sublime* | ||
nbproject | ||
|
||
############################ | ||
# Tests | ||
############################ | ||
testApp | ||
coverage | ||
.nyc_output | ||
|
||
############################ | ||
# Other | ||
############################ | ||
.env | ||
.envrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
unsafe-perm=true | ||
save-prefix=~ | ||
shrinkwrap=false | ||
save=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- "node" | ||
- "lts/*" | ||
after_success: npm run coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright © 2019 microlink.io <hello@microlink.io> (microlink.io) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<h1 align="center"> | ||
<img src="https://microlink.io/banner_mql.png" alt="microlink logo"> | ||
</h1> | ||
|
||
*WORK IN PROGRESS* | ||
|
||
## License | ||
|
||
**mql** © [microlink.io](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/mql/blob/master/LICENSE.md) License.<br> | ||
Authored and maintained by microlink.io with help from [contributors](https://github.com/microlinkhq/mql/contributors). | ||
|
||
> [microlink.io](https://microlink.io) · GitHub [microlink.io](https://github.com/microlinkhq) · Twitter [@microlinkhq](https://twitter.com/microlinkhq) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{ | ||
"name": "mql", | ||
"description": "Microlink Query Language", | ||
"homepage": "https://documentup.com/microlinkhq/mql", | ||
"version": "0.0.0", | ||
"main": "src/node.js", | ||
"author": { | ||
"name": "microlink.io", | ||
"email": "hello@microlink.io", | ||
"url": "https://microlink.io" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/microlinkhq/mql.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/microlinkhq/mql/issues" | ||
}, | ||
"keywords": [ | ||
"microlink" | ||
], | ||
"dependencies": { | ||
"got": "~9.6.0", | ||
"is-url-http": "~1.0.1", | ||
"whoops": "~4.0.1" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "latest", | ||
"@commitlint/config-conventional": "latest", | ||
"ava": "latest", | ||
"conventional-github-releaser": "latest", | ||
"coveralls": "latest", | ||
"finepack": "latest", | ||
"git-authors-cli": "latest", | ||
"git-dirty": "latest", | ||
"husky": "latest", | ||
"lint-staged": "latest", | ||
"npm-check-updates": "latest", | ||
"nyc": "latest", | ||
"prettier-standard": "latest", | ||
"standard": "latest", | ||
"standard-markdown": "latest", | ||
"standard-version": "latest" | ||
}, | ||
"engines": { | ||
"node": ">= 8" | ||
}, | ||
"scripts": { | ||
"clean": "rm -rf node_modules", | ||
"coverage": "nyc report --reporter=text-lcov | coveralls", | ||
"lint": "standard-markdown README.md && standard", | ||
"postrelease": "npm run release:tags && npm run release:github && npm publish", | ||
"precommit": "lint-staged", | ||
"prerelease": "git-dirty && npm run update:check && npm test && git-authors-cli", | ||
"pretest": "npm run lint", | ||
"pretty": "prettier-standard index.js {core,test,bin,scripts}/**/*.js --single-quote --print-width 100", | ||
"release": "git add package.json && standard-version -a", | ||
"release:github": "conventional-github-releaser -p angular", | ||
"release:tags": "git push --follow-tags origin master", | ||
"test": "nyc ava", | ||
"update": "ncu -a", | ||
"update:check": "ncu -- --error-level 2" | ||
}, | ||
"license": "MIT", | ||
"commitlint": { | ||
"extends": [ | ||
"@commitlint/config-conventional" | ||
] | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS", | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"linters": { | ||
"package.json": [ | ||
"finepack", | ||
"git add" | ||
], | ||
"*.js": [ | ||
"prettier-standard", | ||
"git add" | ||
], | ||
"*.md": [ | ||
"standard-markdown", | ||
"git add" | ||
] | ||
} | ||
}, | ||
"standard-version": { | ||
"scripts": { | ||
"prechangelog": "git-authors-cli" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict' | ||
|
||
const ENDPOINT = { | ||
FREE: 'https://api.microlink.io', | ||
PRO: 'https://pro.microlink.io' | ||
} | ||
|
||
module.exports = ({ whoops, isUrlHttp, stringify, got }) => { | ||
const MicrolinkError = whoops('MicrolinkError') | ||
|
||
const assertUrl = url => { | ||
if (!isUrlHttp(url)) { | ||
throw new MicrolinkError({ | ||
code: 'ENOVALIDURL', | ||
message: `The \`url\` value ${ | ||
url ? `'${url}' ` : '' | ||
}is not a valid HTTP URL.`.trim() | ||
}) | ||
} | ||
} | ||
|
||
const apiUrl = (url, { key, ...opts } = {}) => { | ||
const isPro = !!key | ||
const endpoint = ENDPOINT[isPro ? 'PRO' : 'FREE'] | ||
const apiUrl = `${endpoint}?${stringify({ url: url, ...opts })}` | ||
const headers = isPro ? { 'x-api-key': key } : {} | ||
return [apiUrl, { headers }] | ||
} | ||
|
||
// TODO: Add `agent` support | ||
// TODO: Add local `cache` support: https://www.npmjs.com/package/got#cache-1 | ||
// TODO: Add `batch` support https://www.npmjs.com/package/dataloader | ||
const MQL = async ( | ||
targetUrl, | ||
{ retry = 3, timeout = 25000, ...opts } = {} | ||
) => { | ||
assertUrl(targetUrl) | ||
const [url, { headers }] = apiUrl(targetUrl, opts) | ||
const response = await got(url, { retry, timeout, headers, json: true }) | ||
const { body } = response | ||
return { ...body, response } | ||
} | ||
|
||
MQL.MicrolinkError = MicrolinkError | ||
MQL.apiUrl = apiUrl | ||
|
||
return MQL | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = require('./factory')({ | ||
whoops: require('whoops'), | ||
isUrlHttp: require('is-url-http'), | ||
stringify: require('querystring').stringify, | ||
got: require('got') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use strict' | ||
|
||
import test from 'ava' | ||
import { apiUrl } from '..' | ||
|
||
test('url without query params', t => { | ||
t.snapshot(apiUrl('https://kikobeats.com')) | ||
}) | ||
|
||
test('key', t => { | ||
t.snapshot(apiUrl('https://kikobeats.com', { key: 'foobar' })) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict' | ||
|
||
import test from 'ava' | ||
import MQL from '..' | ||
|
||
test('simple url', async t => { | ||
const { status, data, response } = await MQL('https://kikobeats.com') | ||
t.snapshot(status) | ||
t.snapshot(data) | ||
t.snapshot(response.url) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Snapshot report for `test/api-url.js` | ||
|
||
The actual snapshot is saved in `api-url.js.snap`. | ||
|
||
Generated by [AVA](https://ava.li). | ||
|
||
## key | ||
|
||
> Snapshot 1 | ||
[ | ||
'https://pro.microlink.io?url=https%3A%2F%2Fkikobeats.com', | ||
{ | ||
headers: { | ||
'x-api-key': 'foobar', | ||
}, | ||
}, | ||
] | ||
|
||
## url without query params | ||
|
||
> Snapshot 1 | ||
[ | ||
'https://api.microlink.io?url=https%3A%2F%2Fkikobeats.com', | ||
{ | ||
headers: {}, | ||
}, | ||
] |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Snapshot report for `test/index.js` | ||
|
||
The actual snapshot is saved in `index.js.snap`. | ||
|
||
Generated by [AVA](https://ava.li). | ||
|
||
## simple url | ||
|
||
> Snapshot 1 | ||
'success' | ||
|
||
> Snapshot 2 | ||
{ | ||
author: 'kikobeats', | ||
date: null, | ||
description: 'A millennial doing stuff on internet that ships software every day and builds digital products.', | ||
image: { | ||
height: 500, | ||
size: 30285, | ||
size_pretty: '30.3 kB', | ||
type: 'jpg', | ||
url: 'https://kikobeats.com/images/avatar-glitch.jpg', | ||
width: 500, | ||
}, | ||
lang: 'en', | ||
logo: { | ||
height: 500, | ||
size: 30285, | ||
size_pretty: '30.3 kB', | ||
type: 'jpg', | ||
url: 'https://kikobeats.com/images/avatar-glitch.jpg', | ||
width: 500, | ||
}, | ||
publisher: 'Kikobeats', | ||
title: 'Kikobeats', | ||
url: 'https://kikobeats.com/', | ||
} | ||
|
||
> Snapshot 3 | ||
'https://api.microlink.io/?url=https%3A%2F%2Fkikobeats.com' |
Binary file not shown.
Oops, something went wrong.