@octokit/request
Advanced tools
Comparing version 8.0.4 to 8.1.0
@@ -30,3 +30,3 @@ "use strict"; | ||
// pkg/dist-src/version.js | ||
var VERSION = "8.0.4"; | ||
var VERSION = "8.1.0"; | ||
@@ -44,4 +44,5 @@ // pkg/dist-src/fetch-wrapper.js | ||
function fetchWrapper(requestOptions) { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
const log = requestOptions.request && requestOptions.request.log ? requestOptions.request.log : console; | ||
const parseSuccessResponseBody = ((_a = requestOptions.request) == null ? void 0 : _a.parseSuccessResponseBody) !== false; | ||
if ((0, import_is_plain_object.isPlainObject)(requestOptions.body) || Array.isArray(requestOptions.body)) { | ||
@@ -54,3 +55,3 @@ requestOptions.body = JSON.stringify(requestOptions.body); | ||
let { fetch } = globalThis; | ||
if ((_a = requestOptions.request) == null ? void 0 : _a.fetch) { | ||
if ((_b = requestOptions.request) == null ? void 0 : _b.fetch) { | ||
fetch = requestOptions.request.fetch; | ||
@@ -67,3 +68,3 @@ } | ||
headers: requestOptions.headers, | ||
signal: (_b = requestOptions.request) == null ? void 0 : _b.signal, | ||
signal: (_c = requestOptions.request) == null ? void 0 : _c.signal, | ||
// duplex must be set if request.body is ReadableStream or Async Iterables. | ||
@@ -126,3 +127,3 @@ // See https://fetch.spec.whatwg.org/#dom-requestinit-duplex. | ||
} | ||
return getResponseData(response); | ||
return parseSuccessResponseBody ? await getResponseData(response) : response.body; | ||
}).then((data) => { | ||
@@ -129,0 +130,0 @@ return { |
@@ -6,2 +6,3 @@ import { isPlainObject } from "is-plain-object"; | ||
const log = requestOptions.request && requestOptions.request.log ? requestOptions.request.log : console; | ||
const parseSuccessResponseBody = requestOptions.request?.parseSuccessResponseBody !== false; | ||
if (isPlainObject(requestOptions.body) || Array.isArray(requestOptions.body)) { | ||
@@ -84,3 +85,3 @@ requestOptions.body = JSON.stringify(requestOptions.body); | ||
} | ||
return getResponseData(response); | ||
return parseSuccessResponseBody ? await getResponseData(response) : response.body; | ||
}).then((data) => { | ||
@@ -87,0 +88,0 @@ return { |
@@ -1,4 +0,4 @@ | ||
const VERSION = "8.0.4"; | ||
const VERSION = "8.1.0"; | ||
export { | ||
VERSION | ||
}; |
@@ -1,1 +0,1 @@ | ||
export declare const VERSION = "8.0.4"; | ||
export declare const VERSION = "8.1.0"; |
@@ -6,3 +6,3 @@ // pkg/dist-src/index.js | ||
// pkg/dist-src/version.js | ||
var VERSION = "8.0.4"; | ||
var VERSION = "8.1.0"; | ||
@@ -21,2 +21,3 @@ // pkg/dist-src/fetch-wrapper.js | ||
const log = requestOptions.request && requestOptions.request.log ? requestOptions.request.log : console; | ||
const parseSuccessResponseBody = requestOptions.request?.parseSuccessResponseBody !== false; | ||
if (isPlainObject(requestOptions.body) || Array.isArray(requestOptions.body)) { | ||
@@ -99,3 +100,3 @@ requestOptions.body = JSON.stringify(requestOptions.body); | ||
} | ||
return getResponseData(response); | ||
return parseSuccessResponseBody ? await getResponseData(response) : response.body; | ||
}).then((data) => { | ||
@@ -102,0 +103,0 @@ return { |
{ | ||
"name": "@octokit/request", | ||
"version": "8.0.4", | ||
"version": "8.1.0", | ||
"publishConfig": { | ||
@@ -20,3 +20,3 @@ "access": "public" | ||
"@octokit/request-error": "^5.0.0", | ||
"@octokit/types": "^11.0.0", | ||
"@octokit/types": "^11.1.0", | ||
"is-plain-object": "^5.0.0", | ||
@@ -23,0 +23,0 @@ "universal-user-agent": "^6.0.0" |
@@ -32,2 +32,3 @@ # request.js | ||
- [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) | ||
@@ -349,2 +350,13 @@ | ||
</tr> | ||
</tr> | ||
<th align=left> | ||
<code>options.request.parseSuccessResponseBody</code> | ||
</th> | ||
<td> | ||
<code>boolean</code> | ||
</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. | ||
</td> | ||
</tr> | ||
</table> | ||
@@ -533,4 +545,38 @@ | ||
### 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) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
55201
543
580
Updated@octokit/types@^11.1.0