Skip to content

Commit

Permalink
feat: v8 (#599)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Replace support for Node.js http(s) Agents with documentation on using fetch dispatchers instead

BREAKING CHANGE: Remove ability to pass custom request options, except from `method`, `headers`, `body`, `signal`, `data`

---------

Co-authored-by: Keegan Campbell <me@kfcampbell.com>
Co-authored-by: wolfy1339 <4595477+wolfy1339@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 7, 2023
1 parent 60e9b57 commit ebf0865
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 61 deletions.
30 changes: 10 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,35 +245,36 @@ const { data: app } = await requestWithAuth(
</tr>
<tr>
<th align=left>
<code>options.mediaType.format</code>
<code>options.method</code>
</th>
<td>
String
</td>
<td>
Media type param, such as `raw`, `html`, or `full`. See <a href="https://developer.github.com/v3/media/">Media Types</a>.
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.previews</code>
<code>options.mediaType.format</code>
</th>
<td>
Array of strings
String
</td>
<td>
Name of previews, such as `mercy`, `symmetra`, or `scarlet-witch`. See <a href="https://developer.github.com/v3/previews/">API Previews</a>.
Media type param, such as `raw`, `html`, or `full`. See <a href="https://developer.github.com/v3/media/">Media Types</a>.
</td>
</tr>
<tr>
<th align=left>
<code>options.method</code>
<code>options.mediaType.previews</code>
</th>
<td>
String
Array of strings
</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>.
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.
</td>
</tr>
<tr>
Expand All @@ -299,18 +300,7 @@ 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>
<a name="options-request-agent"></a>
<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>
Expand Down
24 changes: 20 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"@octokit/endpoint": "^8.0.1",
"@octokit/request-error": "^4.0.1",
"@octokit/types": "^10.0.0",
"@octokit/types": "^11.0.0",
"is-plain-object": "^5.0.0",
"universal-user-agent": "^6.0.0"
},
Expand Down
27 changes: 10 additions & 17 deletions src/fetch-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,16 @@ export default function fetchWrapper(
);
}

return fetch(
requestOptions.url,
Object.assign(
{
method: requestOptions.method,
body: requestOptions.body,
headers: requestOptions.headers as HeadersInit,
redirect: requestOptions.redirect,
// duplex must be set if request.body is ReadableStream or Async Iterables.
// See https://fetch.spec.whatwg.org/#dom-requestinit-duplex.
...(requestOptions.body && { duplex: "half" }),
},
// `requestOptions.request.agent` type is incompatible
// see https://github.com/octokit/types.ts/pull/264
requestOptions.request as any,
),
)
return fetch(requestOptions.url, {
method: requestOptions.method,
body: requestOptions.body,
headers: requestOptions.headers as HeadersInit,
signal: (requestOptions as any).signal,
data: (requestOptions as any).data,
// duplex must be set if request.body is ReadableStream or Async Iterables.
// See https://fetch.spec.whatwg.org/#dom-requestinit-duplex.
...(requestOptions.body && { duplex: "half" }),
})
.then(async (response) => {
url = response.url;
status = response.status;
Expand Down
19 changes: 0 additions & 19 deletions test/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,25 +561,6 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
);
});

it("options.request.signal is passed as option to fetch", function () {
return request("/", {
request: {
// We pass a value that is not an `AbortSignal`, and expect `fetch` to
// throw an exception complaining about the value
signal: "funk",
},
})
.then(() => {
throw new Error("Should not resolve");
})

.catch((error) => {
// We can't match on the entire string because the message differs between
// Node versions.
expect(error.message).toMatch(/AbortSignal/);
});
});

it("options.request.fetch", function () {
return request("/", {
request: {
Expand Down

0 comments on commit ebf0865

Please sign in to comment.