Fix dependency incompatibilities

This commit is contained in:
Henry Mercer 2023-07-13 11:17:33 +01:00
parent 40a500c743
commit c1f49580cf
749 changed files with 372856 additions and 91172 deletions

View file

@ -3,34 +3,33 @@
> Send parameterized requests to GitHubs APIs with sensible defaults in browsers and Node
[![@latest](https://img.shields.io/npm/v/@octokit/request.svg)](https://www.npmjs.com/package/@octokit/request)
[![Build Status](https://github.com/octokit/request.js/workflows/Test/badge.svg)](https://github.com/octokit/request.js/actions?query=workflow%3ATest+branch%3Amain)
[![Build Status](https://github.com/octokit/request.js/workflows/Test/badge.svg)](https://github.com/octokit/request.js/actions?query=workflow%3ATest+branch%3Amaster)
`@octokit/request` is a request library for browsers & node that makes it easier
to interact with [GitHubs REST API](https://developer.github.com/v3/) and
[GitHubs GraphQL API](https://developer.github.com/v4/guides/forming-calls/#the-graphql-endpoint).
It uses [`@octokit/endpoint`](https://github.com/octokit/endpoint.js) to parse
the passed options and sends the request using [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). You can pass a custom `fetch` function using the `options.request.fetch` option, see below.
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).
<!-- update table of contents by running `npx markdown-toc README.md -i` -->
<!-- toc -->
- [request.js](#requestjs)
- [Features](#features)
- [Usage](#usage)
- [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)
- [Authentication](#authentication)
- [request()](#request)
- [`request.defaults()`](#requestdefaults)
- [`request.endpoint`](#requestendpoint)
- [Special cases](#special-cases)
- [The `data` parameter set request body directly](#the-data-parameter--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)
- [Set a custom Agent to your requests](#set-a-custom-agent-to-your-requests)
- [LICENSE](#license)
- [Features](#features)
- [Usage](#usage)
- [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)
- [Authentication](#authentication)
- [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)
- [LICENSE](#license)
<!-- tocstop -->
@ -58,7 +57,7 @@ request("POST /repos/{owner}/{repo}/issues/{number}/labels", {
- `baseUrl`: `https://api.github.com`
- `headers.accept`: `application/vnd.github.v3+json`
- `headers['user-agent']`: `octokit-request.js/<current version> <OS information>`, e.g. `octokit-request.js/1.2.3 Node.js/10.15.0 (macOS Mojave; x64)`
- `headers.agent`: `octokit-request.js/<current version> <OS information>`, e.g. `octokit-request.js/1.2.3 Node.js/10.15.0 (macOS Mojave; x64)`
👌 Simple to test: mock requests by passing a custom fetch method.
@ -71,11 +70,11 @@ request("POST /repos/{owner}/{repo}/issues/{number}/labels", {
<tr><th>
Browsers
</th><td width=100%>
Load <code>@octokit/request</code> directly from <a href="https://esm.sh">esm.sh</a>
Load <code>@octokit/request</code> directly from <a href="https://cdn.skypack.dev">cdn.skypack.dev</a>
```html
<script type="module">
import { request } from "https://esm.sh/@octokit/request";
import { request } from "https://cdn.skypack.dev/@octokit/request";
</script>
```
@ -187,7 +186,7 @@ const { data: app } = await requestWithAuth(
owner: "octocat",
repo: "hello-world",
title: "Hello from the engine room",
},
}
);
```
@ -245,17 +244,6 @@ const { data: app } = await requestWithAuth(
<em><code>headers['accept']</code> defaults to <code>application/vnd.github.v3+json</code>.<br> Use <code>options.mediaType.{format,previews}</code> to request API previews and custom media types.
</td>
</tr>
<tr>
<th align=left>
<code>options.method</code>
</th>
<td>
String
</td>
<td>
Any supported <a href="https://developer.github.com/v3/#http-verbs">http verb</a>, case insensitive. <em>Defaults to <code>Get</code></em>.
</td>
</tr>
<tr>
<th align=left>
<code>options.mediaType.format</code>
@ -275,8 +263,18 @@ const { data: app } = await requestWithAuth(
Array of strings
</td>
<td>
Name of previews, such as `mercy`, `symmetra`, or `scarlet-witch`. See <a href="https://docs.github.com/graphql/overview/schema-previews">GraphQL Schema Previews</a>.
Note that these only apply to GraphQL requests and have no effect on REST routes.
Name of previews, such as `mercy`, `symmetra`, or `scarlet-witch`. See <a href="https://developer.github.com/v3/previews/">API Previews</a>.
</td>
</tr>
<tr>
<th align=left>
<code>options.method</code>
</th>
<td>
String
</td>
<td>
Any supported <a href="https://developer.github.com/v3/#http-verbs">http verb</a>, case insensitive. <em>Defaults to <code>Get</code></em>.
</td>
</tr>
<tr>
@ -302,7 +300,17 @@ const { data: app } = await requestWithAuth(
Set request body directly instead of setting it to JSON based on additional parameters. See <a href="#data-parameter">"The `data` parameter"</a> below.
</td>
</tr>
<tr>
<th align=left>
<code>options.request.agent</code>
</th>
<td>
<a href="https://nodejs.org/api/http.html#http_class_http_agent">http(s).Agent</a> instance
</td>
<td>
Node only. Useful for custom proxy, certificate, or dns lookup.
</td>
</tr>
<tr>
<th align=left>
<code>options.request.fetch</code>
@ -311,7 +319,7 @@ const { data: app } = await requestWithAuth(
Function
</td>
<td>
Custom replacement for <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">fetch</a>. Useful for testing or request hooks.
Custom replacement for <a href="https://github.com/bitinn/node-fetch">built-in fetch method</a>. Useful for testing or request hooks.
</td>
</tr>
<tr>
@ -346,15 +354,15 @@ const { data: app } = await requestWithAuth(
Used for internal logging. Defaults to <a href="https://developer.mozilla.org/en-US/docs/Web/API/console"><code>console</code></a>.
</td>
</tr>
</tr>
<tr>
<th align=left>
<code>options.request.parseSuccessResponseBody</code>
<code>options.request.timeout</code>
</th>
<td>
<code>boolean</code>
Number
</td>
<td>
If set to <code>false</code> the returned `response` will be passed through from `fetch`. This is useful to stream response.body when downloading files from the GitHub API.
Node only. Request/response timeout in ms, it resets on redirect. 0 to disable (OS limit applies). <a href="#options-request-signal">options.request.signal</a> is recommended instead.
</td>
</tr>
</table>
@ -367,7 +375,7 @@ All other options except `options.request.*` will be passed depending on the `me
**Result**
`request` returns a promise. If the request was successful, the promise resolves with an object containing 4 keys:
`request` returns a promise and resolves with 4 keys
<table>
<thead>
@ -405,14 +413,12 @@ All other options except `options.request.*` will be passed depending on the `me
</tr>
</table>
If an error occurs, the promise is rejected with an `error` object containing 3 keys to help with debugging:
If an error occurs, the `error` instance has additional properties to help with debugging
- `error.status` The http response status code
- `error.request` The request options such as `method`, `url` and `data`
- `error.response` The http response object with `url`, `headers`, and `data`
If the error is due to an `AbortSignal` being used, the resulting `AbortError` is bubbled up to the caller.
## `request.defaults()`
Override or set default options. Example:
@ -536,44 +542,10 @@ request(
authorization: `token 0000000000000000000000000000000000000001`,
},
data: "Hello, world!",
},
}
);
```
### Set a custom Agent to your requests
The way to pass a custom `Agent` to requests is by creating a custom `fetch` function and pass it as `options.request.fetch`. A good example can be [undici's `fetch` implementation](https://undici.nodejs.org/#/?id=undicifetchinput-init-promise).
Example ([See example in CodeSandbox](https://codesandbox.io/p/sandbox/nifty-stitch-wdlwlf))
```js
import { request } from "@octokit/request";
import { fetch as undiciFetch, Agent } from "undici";
/** @type {typeof import("undici").fetch} */
const myFetch = (url, options) => {
return undiciFetch(url, {
...options,
dispatcher: new Agent({
keepAliveTimeout: 10,
keepAliveMaxTimeout: 10,
}),
});
};
const { data } = await request("GET /users/{username}", {
username: "octocat",
headers: {
"X-GitHub-Api-Version": "2022-11-28",
},
options: {
request: {
fetch: myFetch,
},
},
});
```
## LICENSE
[MIT](LICENSE)