Comparing version 9.0.0 to 10.0.0
68
index.js
@@ -1,8 +0,8 @@ | ||
'use strict'; | ||
const got = require('got'); | ||
import process from 'node:process'; | ||
import got from 'got'; | ||
const getRateLimit = headers => ({ | ||
limit: parseInt(headers['x-ratelimit-limit'], 10), | ||
remaining: parseInt(headers['x-ratelimit-remaining'], 10), | ||
reset: new Date(parseInt(headers['x-ratelimit-reset'], 10) * 1000) | ||
limit: Number.parseInt(headers['x-ratelimit-limit'], 10), | ||
remaining: Number.parseInt(headers['x-ratelimit-remaining'], 10), | ||
reset: new Date(Number.parseInt(headers['x-ratelimit-reset'], 10) * 1000), | ||
}); | ||
@@ -14,17 +14,38 @@ | ||
accept: 'application/vnd.github.v3+json', | ||
'user-agent': 'https://github.com/sindresorhus/gh-got' | ||
'user-agent': 'https://github.com/sindresorhus/gh-got', | ||
}, | ||
responseType: 'json', | ||
token: process.env.GITHUB_TOKEN, | ||
context: { | ||
token: process.env.GITHUB_TOKEN, | ||
}, | ||
hooks: { | ||
init: [ | ||
(raw, options) => { | ||
// TODO: This should be fixed in Got. | ||
// TODO: This doesn't seem to have any effect. | ||
if (typeof options.url === 'string' && options.url.startsWith('/')) { | ||
options.url = options.url.slice(1); | ||
} | ||
if ('token' in raw) { | ||
options.context.token = raw.token; | ||
delete raw.token; | ||
} | ||
}, | ||
], | ||
}, | ||
handlers: [ | ||
(options, next) => { | ||
// TODO: This should be fixed in Got | ||
// TODO: This doesn't seem to have any effect. | ||
if (typeof options.url === 'string' && options.url.startsWith('/')) { | ||
options.url = options.url.slice(1); | ||
} | ||
// Authorization | ||
if (options.token && !options.headers.authorization) { | ||
options.headers.authorization = `token ${options.token}`; | ||
const {token} = options.context; | ||
if (token && !options.headers.authorization) { | ||
options.headers.authorization = `token ${token}`; | ||
} | ||
// `options.body` -> `options.json` | ||
options.json = options.body; | ||
delete options.body; | ||
// Don't touch streams | ||
@@ -50,3 +71,3 @@ if (options.isStream) { | ||
error.name = 'GitHubError'; | ||
error.message = `${response.body.message} (${error.response.statusCode})`; | ||
error.message = `${response.body.message} (${response.statusCode})`; | ||
} | ||
@@ -62,21 +83,12 @@ | ||
})(); | ||
} | ||
}, | ||
], | ||
hooks: { | ||
init: [ | ||
options => { | ||
// TODO: This should be fixed in Got | ||
// Remove leading slashes | ||
if (typeof options.url === 'string' && options.url.startsWith('/')) { | ||
options.url = options.url.slice(1); | ||
} | ||
} | ||
] | ||
} | ||
}); | ||
module.exports = create(); | ||
const ghGot = create(); | ||
export default ghGot; | ||
if (process.env.NODE_ENV === 'test') { | ||
module.exports.recreate = create; | ||
ghGot.recreate = create; | ||
} |
{ | ||
"name": "gh-got", | ||
"version": "9.0.0", | ||
"version": "10.0.0", | ||
"description": "Convenience wrapper for Got to interact with the GitHub API", | ||
@@ -13,4 +13,6 @@ "license": "MIT", | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=14.16" | ||
}, | ||
@@ -36,10 +38,10 @@ "scripts": { | ||
"dependencies": { | ||
"got": "^10.5.7" | ||
"got": "^12.5.2" | ||
}, | ||
"devDependencies": { | ||
"ava": "^3.0.2", | ||
"get-stream": "^5.1.0", | ||
"nock": "^12.0.0", | ||
"xo": "^0.26.1" | ||
"ava": "^4.3.3", | ||
"get-stream": "^6.0.1", | ||
"nock": "^13.2.9", | ||
"xo": "^0.52.4" | ||
} | ||
} |
@@ -1,10 +0,12 @@ | ||
# gh-got [![Build Status](https://travis-ci.org/sindresorhus/gh-got.svg?branch=master)](https://travis-ci.org/sindresorhus/gh-got) | ||
# gh-got | ||
> Convenience wrapper for [Got](https://github.com/sindresorhus/got) to interact with the [GitHub API](https://developer.github.com/v3/) | ||
Unless you're already using Got, you should probably use GitHub's own [@octokit/rest.js](https://github.com/octokit/rest.js) or [@octokit/graphql.js](https://github.com/octokit/graphql.js) packages instead. | ||
## Install | ||
```sh | ||
npm install gh-got | ||
``` | ||
$ npm install gh-got | ||
``` | ||
@@ -16,17 +18,16 @@ ## Usage | ||
```js | ||
const got = require('got'); | ||
import got from 'got'; | ||
const token = 'foo'; | ||
(async () => { | ||
const {body} = await got('https://api.github.com/users/sindresorhus', { | ||
json: true, | ||
headers: { | ||
'accept': 'application/vnd.github.v3+json', | ||
'authorization': `token ${token}` | ||
} | ||
}); | ||
const {body} = await got('https://api.github.com/users/sindresorhus', { | ||
json: true, | ||
headers: { | ||
'accept': 'application/vnd.github.v3+json', | ||
'authorization': `token ${token}` | ||
} | ||
}); | ||
console.log(body.login); | ||
//=> 'sindresorhus' | ||
})(); | ||
console.log(body.login); | ||
//=> 'sindresorhus' | ||
``` | ||
@@ -37,10 +38,12 @@ | ||
```js | ||
const ghGot = require('gh-got'); | ||
import ghGot from 'gh-got'; | ||
(async () => { | ||
const {body} = await ghGot('users/sindresorhus', {token: 'foo'}); | ||
const {body} = await ghGot('users/sindresorhus', { | ||
context: { | ||
token: 'foo' | ||
} | ||
}); | ||
console.log(body.login); | ||
//=> 'sindresorhus' | ||
})(); | ||
console.log(body.login); | ||
//=> 'sindresorhus' | ||
``` | ||
@@ -51,10 +54,12 @@ | ||
```js | ||
const ghGot = require('gh-got'); | ||
import ghGot from 'gh-got'; | ||
(async () => { | ||
const {body} = await ghGot('https://api.github.com/users/sindresorhus', {token: 'foo'}); | ||
const {body} = await ghGot('https://api.github.com/users/sindresorhus', { | ||
context: { | ||
token: 'foo' | ||
} | ||
}); | ||
console.log(body.login); | ||
//=> 'sindresorhus' | ||
})(); | ||
console.log(body.login); | ||
//=> 'sindresorhus' | ||
``` | ||
@@ -98,10 +103,8 @@ | ||
```js | ||
const ghGot = require('gh-got'); | ||
import ghGot from 'gh-got'; | ||
(async () => { | ||
const {rateLimit} = await ghGot('users/sindresorhus'); | ||
const {rateLimit} = await ghGot('users/sindresorhus'); | ||
console.log(rateLimit); | ||
//=> {limit: 5000, remaining: 4899, reset: [Date 2018-12-31T20:45:20.000Z]} | ||
})(); | ||
console.log(rateLimit); | ||
//=> {limit: 5000, remaining: 4899, reset: [Date 2018-12-31T20:45:20.000Z]} | ||
``` | ||
@@ -120,15 +123,13 @@ | ||
```js | ||
const ghGot = require(`gh-got`); | ||
import ghGot from 'gh-got'; | ||
(async () => { | ||
const options = { | ||
headers: { | ||
authorization: `Bearer ${jwt}` | ||
} | ||
}; | ||
const {body} = await ghGot('app', options); | ||
const options = { | ||
headers: { | ||
authorization: `Bearer ${jwt}` | ||
} | ||
}; | ||
const {body} = await ghGot('app', options); | ||
console.log(body.name); | ||
//=> 'MyApp' | ||
})(); | ||
console.log(body.name); | ||
//=> 'MyApp' | ||
``` | ||
@@ -138,2 +139,2 @@ | ||
See the [Got docs](https://github.com/sindresorhus/got#pagination). | ||
See the [Got docs](https://github.com/sindresorhus/got/blob/main/documentation/4-pagination.md). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7488
77
135
Yes
+ Added@sindresorhus/is@5.6.0(transitive)
+ Added@szmarczak/http-timer@5.0.1(transitive)
+ Addedcacheable-lookup@7.0.0(transitive)
+ Addedcacheable-request@10.2.14(transitive)
+ Addeddecompress-response@6.0.0(transitive)
+ Addedform-data-encoder@2.1.4(transitive)
+ Addedget-stream@6.0.1(transitive)
+ Addedgot@12.6.1(transitive)
+ Addedhttp2-wrapper@2.2.1(transitive)
+ Addedlowercase-keys@3.0.0(transitive)
+ Addedmimic-response@3.1.04.0.0(transitive)
+ Addednormalize-url@8.0.1(transitive)
+ Addedp-cancelable@3.0.0(transitive)
+ Addedquick-lru@5.1.1(transitive)
+ Addedresolve-alpn@1.2.1(transitive)
+ Addedresponselike@3.0.0(transitive)
- Removed@sindresorhus/is@2.1.1(transitive)
- Removed@szmarczak/http-timer@4.0.6(transitive)
- Removed@types/cacheable-request@6.0.3(transitive)
- Removed@types/keyv@3.1.4(transitive)
- Removed@types/node@22.7.7(transitive)
- Removed@types/responselike@1.0.3(transitive)
- Removedcacheable-lookup@2.0.1(transitive)
- Removedcacheable-request@7.0.4(transitive)
- Removedclone-response@1.0.3(transitive)
- Removeddecompress-response@5.0.0(transitive)
- Removedduplexer3@0.1.5(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedget-stream@5.2.0(transitive)
- Removedgot@10.7.0(transitive)
- Removedlowercase-keys@2.0.0(transitive)
- Removedmimic-response@1.0.12.1.0(transitive)
- Removednormalize-url@6.1.0(transitive)
- Removedonce@1.4.0(transitive)
- Removedp-cancelable@2.1.1(transitive)
- Removedp-event@4.2.0(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedp-timeout@3.2.0(transitive)
- Removedpump@3.0.2(transitive)
- Removedresponselike@2.0.1(transitive)
- Removedto-readable-stream@2.1.0(transitive)
- Removedtype-fest@0.10.0(transitive)
- Removedundici-types@6.19.8(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedgot@^12.5.2