Skip to content

Commit

Permalink
docs: update examples due to changes
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Oct 7, 2024
1 parent 2f30ebf commit f24b39d
Showing 1 changed file with 55 additions and 6 deletions.
61 changes: 55 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,21 +252,70 @@ export const clockTolerance: unique symbol = Symbol()
*
* @example
*
* Using [nodejs/undici](https://github.com/nodejs/undici) to detect and use HTTP proxies.
*
* ```ts
* import * as undici from 'undici'
*
* // see https://undici.nodejs.org/#/docs/api/EnvHttpProxyAgent
* const envHttpProxyAgent = new undici.EnvHttpProxyAgent()
*
* // example use
* await oauth.discoveryRequest(new URL('https://as.example.com'), {
* // @ts-ignore
* [oauth.customFetch](...args) {
* return undici.fetch(args[0], { ...args[1], dispatcher: envHttpProxyAgent }) // prettier-ignore
* },
* })
* ```
*
* @example
*
* Using [nodejs/undici](https://github.com/nodejs/undici) to automatically retry network errors.
*
* ```ts
* import * as undici from 'undici'
*
* // see https://undici.nodejs.org/#/docs/api/RetryAgent
* const retryAgent = new undici.RetryAgent(new undici.Agent(), {
* statusCodes: [],
* errorCodes: [
* 'ECONNRESET',
* 'ECONNREFUSED',
* 'ENOTFOUND',
* 'ENETDOWN',
* 'ENETUNREACH',
* 'EHOSTDOWN',
* 'UND_ERR_SOCKET',
* ],
* })
*
* // example use
* await oauth.discoveryRequest(new URL('https://as.example.com'), {
* // @ts-ignore
* [oauth.customFetch](...args) {
* return undici.fetch(args[0], { ...args[1], dispatcher: retryAgent }) // prettier-ignore
* },
* })
* ```
*
* @example
*
* Using [nodejs/undici](https://github.com/nodejs/undici) to mock responses in tests.
*
* ```js
* ```ts
* import * as undici from 'undici'
*
* // see https://undici.nodejs.org/#/docs/api/MockAgent
* const mockAgent = new undici.MockAgent()
* mockAgent.disableNetConnect()
* undici.setGlobalDispatcher(mockAgent)
*
* // continue as per undici documentation
* // https://github.com/nodejs/undici/blob/v6.2.1/docs/api/MockAgent.md#example---basic-mocked-request
*
* // example use
* await oauth.discoveryRequest(new URL('https://as.example.com'), {
* [oauth.customFetch]: undici.fetch,
* // @ts-ignore
* [oauth.customFetch](...args) {
* return undici.fetch(args[0], { ...args[1], dispatcher: mockAgent }) // prettier-ignore
* },
* })
* ```
*/
Expand Down

0 comments on commit f24b39d

Please sign in to comment.