@octokit/request
Advanced tools
Comparing version 3.0.3 to 4.0.0
131
package.json
{ | ||
"name": "@octokit/request", | ||
"version": "3.0.3", | ||
"version": "4.0.0", | ||
"publishConfig": { | ||
@@ -10,12 +10,7 @@ "access": "public" | ||
"scripts": { | ||
"prebuild": "mkdirp dist/", | ||
"build": "npm-run-all build:*", | ||
"build:development": "webpack --mode development --entry . --output-library=Octokit --output=./dist/octokit-request.js --profile --json > dist/bundle-stats.json", | ||
"build:production": "webpack --mode production --entry . --plugin=compression-webpack-plugin --output-library=Octokit --output-path=./dist --output-filename=octokit-request.min.js --devtool source-map", | ||
"bundle-report": "webpack-bundle-analyzer dist/bundle-stats.json --mode=static --no-open --report dist/bundle-report.html", | ||
"coverage": "nyc report --reporter=html && open coverage/index.html", | ||
"coverage:upload": "nyc report --reporter=text-lcov | coveralls", | ||
"pretest": "standard", | ||
"test": "nyc mocha test/*-test.js", | ||
"test:browser": "cypress run --browser chrome", | ||
"build": "pack build", | ||
"lint": "prettier --check '{src,test}/**/*' README.md package.json", | ||
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json", | ||
"pretest": "npm run -s lint", | ||
"test": "jest --coverage", | ||
"semantic-release": "semantic-release" | ||
@@ -41,61 +36,87 @@ }, | ||
"@octokit/endpoint": "^5.1.0", | ||
"deprecation": "^1.0.1", | ||
"deprecation": "^2.0.0", | ||
"is-plain-object": "^3.0.0", | ||
"node-fetch": "^2.3.0", | ||
"once": "^1.4.0", | ||
"universal-user-agent": "^2.0.1" | ||
"universal-user-agent": "^2.1.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"compression-webpack-plugin": "^2.0.0", | ||
"coveralls": "^3.0.2", | ||
"cypress": "^3.1.0", | ||
"@gr2m/pika-plugin-bundle-web": "^0.3.16-patch-issue-46-6", | ||
"@pika/pack": "^0.3.7", | ||
"@pika/plugin-build-node": "^0.3.16", | ||
"@pika/plugin-build-web": "^0.3.16", | ||
"@pika/plugin-ts-standard-pkg": "^0.3.16", | ||
"@types/fetch-mock": "^7.2.4", | ||
"@types/jest": "^24.0.12", | ||
"@types/node": "^11.13.8", | ||
"@types/node-fetch": "^2.3.3", | ||
"@types/once": "^1.4.0", | ||
"fetch-mock": "^7.2.0", | ||
"mkdirp": "^0.5.1", | ||
"mocha": "^6.1.1", | ||
"jest": "^24.7.1", | ||
"npm-run-all": "^4.1.3", | ||
"nyc": "^14.0.0", | ||
"pika-plugin-unpkg-field": "^1.1.0", | ||
"prettier": "^1.17.0", | ||
"rollup-plugin-commonjs": "^9.3.4", | ||
"rollup-plugin-json": "^4.0.0", | ||
"rollup-plugin-node-resolve": "^4.2.4", | ||
"semantic-release": "^15.10.5", | ||
"semantic-release-plugin-update-version-in-files": "^1.0.0", | ||
"simple-mock": "^0.8.0", | ||
"standard": "^12.0.1", | ||
"webpack": "^4.22.0", | ||
"webpack-bundle-analyzer": "^3.0.3", | ||
"webpack-cli": "^3.1.2" | ||
"ts-jest": "^24.0.2", | ||
"typescript": "^3.4.5" | ||
}, | ||
"browser": { | ||
"./lib/get-request-agent.js": false, | ||
"./lib/request/get-buffer-response.js": "./lib/request/get-buffer-response-browser.js" | ||
"jest": { | ||
"preset": "ts-jest", | ||
"coverageThreshold": { | ||
"global": { | ||
"statements": 100, | ||
"branches": 100, | ||
"functions": 100, | ||
"lines": 100 | ||
} | ||
} | ||
}, | ||
"bundlesize": [ | ||
{ | ||
"path": "./dist/octokit-request.min.js.gz", | ||
"maxSize": "5KB" | ||
} | ||
"files": [ | ||
"lib" | ||
], | ||
"@pika/pack": { | ||
"pipeline": [ | ||
[ | ||
"@pika/plugin-ts-standard-pkg" | ||
], | ||
[ | ||
"@pika/plugin-build-node" | ||
], | ||
[ | ||
"@pika/plugin-build-web" | ||
], | ||
[ | ||
"@gr2m/pika-plugin-bundle-web", | ||
{ | ||
"browser": true | ||
} | ||
], | ||
[ | ||
"pika-plugin-unpkg-field" | ||
] | ||
] | ||
}, | ||
"release": { | ||
"publish": [ | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator", | ||
"@semantic-release/github", | ||
"@semantic-release/npm", | ||
{ | ||
"path": "@semantic-release/github", | ||
"assets": [ | ||
"dist/*", | ||
"!dist/*.map.gz" | ||
] | ||
} | ||
[ | ||
"semantic-release-plugin-update-version-in-files", | ||
{ | ||
"files": [ | ||
"dist-web/*", | ||
"dist-node/*", | ||
"*/version.*" | ||
] | ||
} | ||
] | ||
] | ||
}, | ||
"standard": { | ||
"globals": [ | ||
"describe", | ||
"before", | ||
"beforeEach", | ||
"afterEach", | ||
"after", | ||
"it", | ||
"expect" | ||
] | ||
}, | ||
"files": [ | ||
"lib" | ||
] | ||
} | ||
} |
206
README.md
@@ -7,3 +7,2 @@ # request.js | ||
[![Build Status](https://travis-ci.org/octokit/request.js.svg?branch=master)](https://travis-ci.org/octokit/request.js) | ||
[![Coverage Status](https://coveralls.io/repos/github/octokit/request.js/badge.svg)](https://coveralls.io/github/octokit/request.js) | ||
[![Greenkeeper](https://badges.greenkeeper.io/octokit/request.js.svg)](https://greenkeeper.io/) | ||
@@ -17,3 +16,3 @@ | ||
the passed options and sends the request using [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) | ||
([node-fetch](https://github.com/bitinn/node-fetch) in Node). | ||
([node-fetch](https://github.com/bitinn/node-fetch) in Node). | ||
@@ -26,13 +25,11 @@ <!-- update table of contents by running `npx markdown-toc README.md -i` --> | ||
- [Usage](#usage) | ||
* [Node](#node) | ||
* [Browser](#browser) | ||
* [REST API example](#rest-api-example) | ||
* [GraphQL example](#graphql-example) | ||
* [Alternative: pass `method` & `url` as part of options](#alternative-pass-method--url-as-part-of-options) | ||
- [octokitRequest()](#octokitrequest) | ||
- [`octokitRequest.defaults()`](#octokitrequestdefaults) | ||
- [`octokitRequest.endpoint`](#octokitrequestendpoint) | ||
- [REST API example](#rest-api-example) | ||
- [GraphQL example](#graphql-example) | ||
- [Alternative: pass `method` & `url` as part of options](#alternative-pass-method--url-as-part-of-options) | ||
- [request()](#request) | ||
- [`request.defaults()`](#requestdefaults) | ||
- [`request.endpoint`](#requestendpoint) | ||
- [Special cases](#special-cases) | ||
* [The `data` parameter – set request body directly](#the-data-parameter-%E2%80%93-set-request-body-directly) | ||
* [Set parameters for both the URL/query and the request body](#set-parameters-for-both-the-urlquery-and-the-request-body) | ||
- [The `data` parameter – set request body directly](#the-data-parameter-%E2%80%93-set-request-body-directly) | ||
- [Set parameters for both the URL/query and the request body](#set-parameters-for-both-the-urlquery-and-the-request-body) | ||
- [LICENSE](#license) | ||
@@ -46,13 +43,14 @@ | ||
```js | ||
request('POST /repos/:owner/:repo/issues/:number/labels', { | ||
headers: { | ||
accept: 'application/vnd.github.symmetra-preview+json' | ||
}, | ||
owner: 'ocotkit', | ||
repo: 'request.js', | ||
number: 1, | ||
labels: ['🐛 bug'] | ||
}) | ||
``` | ||
```js | ||
request("POST /repos/:owner/:repo/issues/:number/labels", { | ||
headers: { | ||
accept: "application/vnd.github.symmetra-preview+json" | ||
}, | ||
owner: "ocotkit", | ||
repo: "request.js", | ||
number: 1, | ||
labels: ["🐛 bug"] | ||
}); | ||
``` | ||
👍 Sensible defaults | ||
@@ -66,3 +64,3 @@ | ||
🧐 Simple to debug: Sets `error.request` to request options causing the error (with redacted credentials). | ||
🧐 Simple to debug: Sets `error.request` to request options causing the error (with redacted credentials). | ||
@@ -73,22 +71,31 @@ 👶 Small bundle size (\<5kb minified + gzipped) | ||
### Node | ||
<table> | ||
<tbody valign=top align=left> | ||
<tr><th> | ||
Browsers | ||
</th><td width=100%> | ||
Load <code>@octokit/request</code> directly from <a href="https://unpkg.com">unpkg.com</a> | ||
```html | ||
<script type="module"> | ||
import { request } from "https://unpkg.com/@octokit/request"; | ||
</script> | ||
``` | ||
Install with `npm install @octokit/request`. | ||
</td></tr> | ||
<tr><th> | ||
Node | ||
</th><td> | ||
Install with <code>npm install @octokit/request</code> | ||
```js | ||
const octokitRequest = require('@octokit/request') | ||
const { request } = require("@octokit/request"); | ||
// or: import { request } from "@octokit/request"; | ||
``` | ||
### Browser | ||
</td></tr> | ||
</tbody> | ||
</table> | ||
1. Download `octokit-request.min.js` from the latest release: https://github.com/octokit/request.js/releases | ||
2. Load it as script into your web application: | ||
```html | ||
<script src="request-rest.min.js"></script> | ||
``` | ||
3. The `octokitRequest` is now available | ||
### REST API example | ||
@@ -99,11 +106,11 @@ | ||
// https://developer.github.com/v3/repos/#list-organization-repositories | ||
const result = await octokitRequest('GET /orgs/:org/repos', { | ||
const result = await request("GET /orgs/:org/repos", { | ||
headers: { | ||
authorization: 'token 0000000000000000000000000000000000000001' | ||
authorization: "token 0000000000000000000000000000000000000001" | ||
}, | ||
org: 'octokit', | ||
type: 'private' | ||
}) | ||
org: "octokit", | ||
type: "private" | ||
}); | ||
console.log(`${result.data.length} repos found.`) | ||
console.log(`${result.data.length} repos found.`); | ||
``` | ||
@@ -114,5 +121,5 @@ | ||
```js | ||
const result = await octokitRequest('POST /graphql', { | ||
const result = await request("POST /graphql", { | ||
headers: { | ||
authorization: 'token 0000000000000000000000000000000000000001' | ||
authorization: "token 0000000000000000000000000000000000000001" | ||
}, | ||
@@ -127,5 +134,5 @@ query: `query ($login: String!) { | ||
variables: { | ||
login: 'octokit' | ||
login: "octokit" | ||
} | ||
}) | ||
}); | ||
``` | ||
@@ -138,16 +145,16 @@ | ||
```js | ||
const result = await octokitRequest({ | ||
method: 'GET', | ||
url: '/orgs/:org/repos', | ||
const result = await request({ | ||
method: "GET", | ||
url: "/orgs/:org/repos", | ||
headers: { | ||
authorization: 'token 0000000000000000000000000000000000000001' | ||
authorization: "token 0000000000000000000000000000000000000001" | ||
}, | ||
org: 'octokit', | ||
type: 'private' | ||
}) | ||
org: "octokit", | ||
type: "private" | ||
}); | ||
``` | ||
## octokitRequest() | ||
## request() | ||
`octokitRequest(route, options)` or `octokitRequest(options)`. | ||
`request(route, options)` or `request(options)`. | ||
@@ -217,3 +224,3 @@ **Options** | ||
<th align=left> | ||
<code>options.mediaType.preview</code> | ||
<code>options.mediaType.previews</code> | ||
</th> | ||
@@ -285,2 +292,13 @@ <td> | ||
<th align=left> | ||
<code>options.request.hook</code> | ||
</th> | ||
<td> | ||
Function | ||
</td> | ||
<td> | ||
Function with the signature <code>hook(endpointOptions, request)</code>, where <code>endpointOptions</code> are the parsed options as returned by <a href="https://github.com/octokit/endpoint.js#endpointmergeroute-options-or-endpointmergeoptions"><code>endpoint.merge()</code></a>, and <code>request</code> is <a href="https://github.com/octokit/request.js#request"><code>request()</code></a>. This option works great in conjuction with <a href="https://github.com/gr2m/before-after-hook">before-after-hook</a>. | ||
</td> | ||
</tr> | ||
<tr> | ||
<th align=left> | ||
<a name="options-request-signal"></a><code>options.request.signal</code> | ||
@@ -316,3 +334,3 @@ </th> | ||
`octokitRequest` returns a promise and resolves with 4 keys | ||
`request` returns a promise and resolves with 4 keys | ||
@@ -361,3 +379,3 @@ <table> | ||
## `octokitRequest.defaults()` | ||
## `request.defaults()` | ||
@@ -367,13 +385,13 @@ Override or set default options. Example: | ||
```js | ||
const myOctokitRequest = require('@octokit/request').defaults({ | ||
baseUrl: 'https://github-enterprise.acme-inc.com/api/v3', | ||
const myrequest = require("@octokit/request").defaults({ | ||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3", | ||
headers: { | ||
'user-agent': 'myApp/1.2.3', | ||
"user-agent": "myApp/1.2.3", | ||
authorization: `token 0000000000000000000000000000000000000001` | ||
}, | ||
org: 'my-project', | ||
org: "my-project", | ||
per_page: 100 | ||
}) | ||
}); | ||
myOctokitRequest(`GET /orgs/:org/repos`) | ||
myrequest(`GET /orgs/:org/repos`); | ||
``` | ||
@@ -384,9 +402,9 @@ | ||
```js | ||
const myProjectRequest = octokitRequest.defaults({ | ||
baseUrl: 'https://github-enterprise.acme-inc.com/api/v3', | ||
const myProjectRequest = request.defaults({ | ||
baseUrl: "https://github-enterprise.acme-inc.com/api/v3", | ||
headers: { | ||
'user-agent': 'myApp/1.2.3' | ||
"user-agent": "myApp/1.2.3" | ||
}, | ||
org: 'my-project' | ||
}) | ||
org: "my-project" | ||
}); | ||
const myProjectRequestWithAuth = myProjectRequest.defaults({ | ||
@@ -396,3 +414,3 @@ headers: { | ||
} | ||
}) | ||
}); | ||
``` | ||
@@ -404,3 +422,3 @@ | ||
## `octokitRequest.endpoint` | ||
## `request.endpoint` | ||
@@ -410,6 +428,6 @@ See https://github.com/octokit/endpoint.js. Example | ||
```js | ||
const options = octokitRequest.endpoint('GET /orgs/:org/repos', { | ||
org: 'my-project', | ||
type: 'private' | ||
}) | ||
const options = request.endpoint("GET /orgs/:org/repos", { | ||
org: "my-project", | ||
type: "private" | ||
}); | ||
@@ -437,2 +455,3 @@ // { | ||
<a name="data-parameter"></a> | ||
### The `data` parameter – set request body directly | ||
@@ -443,9 +462,9 @@ | ||
```js | ||
const options = endpoint('POST /markdown/raw', { | ||
data: 'Hello world github/linguist#1 **cool**, and #1!', | ||
const options = endpoint("POST /markdown/raw", { | ||
data: "Hello world github/linguist#1 **cool**, and #1!", | ||
headers: { | ||
accept: 'text/html;charset=utf-8', | ||
'content-type': 'text/plain' | ||
accept: "text/html;charset=utf-8", | ||
"content-type": "text/plain" | ||
} | ||
}) | ||
}); | ||
@@ -472,12 +491,15 @@ // options is | ||
```js | ||
octokitRequest('POST https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}', { | ||
name: 'example.zip', | ||
label: 'short description', | ||
headers: { | ||
'content-type': 'text/plain', | ||
'content-length': 14, | ||
authorization: `token 0000000000000000000000000000000000000001` | ||
}, | ||
data: 'Hello, world!' | ||
}) | ||
request( | ||
"POST https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}", | ||
{ | ||
name: "example.zip", | ||
label: "short description", | ||
headers: { | ||
"content-type": "text/plain", | ||
"content-length": 14, | ||
authorization: `token 0000000000000000000000000000000000000001` | ||
}, | ||
data: "Hello, world!" | ||
} | ||
); | ||
``` | ||
@@ -484,0 +506,0 @@ |
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
488
18237
23
3
0
1
2
+ Addeddeprecation@2.3.1(transitive)
- Removeddeprecation@1.0.1(transitive)
Updateddeprecation@^2.0.0
Updateduniversal-user-agent@^2.1.0