Package detail

@npmcli/agent

npm40.6mISC3.0.0

the http/https agent used by the npm cli

readme

@npmcli/agent

A pair of Agent implementations for nodejs that provide consistent keep-alives, granular timeouts, dns caching, and proxy support.

Usage

const { getAgent, HttpAgent } = require('@npmcli/agent')
const fetch = require('minipass-fetch')

const main = async () => {
    // if you know what agent you need, you can create one directly
    const agent = new HttpAgent(agentOptions)
    // or you can use the getAgent helper, it will determine and create an Agent
    // instance for you as well as reuse that agent for new requests as appropriate
    const agent = getAgent('https://registry.npmjs.org/npm', agentOptions)
    // minipass-fetch is just an example, this will work for any http client that
    // supports node's Agents
    const res = await fetch('https://registry.npmjs.org/npm', { agent })
}

main()

Options

All options supported by the node Agent implementations are supported here, see the docs for those.

Options that have been added by this module include:

  • family: what tcp family to use, can be 4 for IPv4, 6 for IPv6 or 0 for both.
  • proxy: a URL to a supported proxy, currently supports HTTP CONNECT based http/https proxies as well as socks4 and 5.
  • dns: configuration for the built-in dns cache
    • ttl: how long (in milliseconds) to keep cached dns entries, defaults to 5 * 60 * 100 (5 minutes)
    • lookup: optional function to override how dns lookups are performed, defaults to require('dns').lookup
  • timeouts: a set of granular timeouts, all default to 0
    • connection: time between initiating connection and actually connecting
    • idle: time between data packets (if a top level timeout is provided, it will be copied here)
    • response: time between sending a request and receiving a response
    • transfer: time between starting to receive a request and consuming the response fully

changelog

Changelog

3.0.0 (2024-08-26)

⚠️ BREAKING CHANGES

  • @npmcli/agent now supports node ^18.17.0 || >=20.5.0

Bug Fixes

  • 5dbeb55 #113 align to npm 10 node engine range (@hashtagchris)

Chores

  • bfdccc1 #114 bump @npmcli/eslint-config from 4.0.5 to 5.0.0 (@dependabot[bot])
  • e3fd27f #113 run template-oss-apply (@hashtagchris)
  • 21c1987 #99 linting: no-unused-vars (@lukekarrys)
  • 488db1d #99 bump @npmcli/template-oss to 4.22.0 (@lukekarrys)
  • f797fa1 #95 re-implement skipped windows test (#95) (@lukekarrys)
  • 603173b #111 postinstall for dependabot template-oss PR (@hashtagchris)
  • 0c7400c #111 bump @npmcli/template-oss from 4.22.0 to 4.23.1 (@dependabot[bot])

2.2.2 (2024-04-01)

Bug Fixes

  • 30f7443 #94 set socks proxy socket family (#94) (@lukekarrys)

2.2.1 (2024-02-01)

Bug Fixes

  • 88212cc #92 properly differentiate http and https proxies (#92) (@Torbjorn-Svensson)

Chores

  • 9ffc694 #90 postinstall for dependabot template-oss PR (@lukekarrys)
  • 7243097 #90 bump @npmcli/template-oss from 4.21.1 to 4.21.3 (@dependabot[bot])
  • ee9ea76 #88 postinstall for dependabot template-oss PR (@lukekarrys)
  • e169c95 #88 bump @npmcli/template-oss from 4.19.0 to 4.21.1 (@dependabot[bot])
  • cfdcf70 #73 move proxy:null to correct test (@lukekarrys)

2.2.0 (2023-10-02)

Features

Bug Fixes

  • d2608ea #59 remove unnecessary utils and cleanup destructuring (@lukekarrys)
  • 4d4b70c #67 set proxy from env vars based on truthiness (@lukekarrys)

2.1.1 (2023-09-08)

Bug Fixes

  • 9937e66 #55 use current agent to determine secure proxy (@lukekarrys)

2.1.0 (2023-08-30)

Features

  • 707bff4 #50 use third party proxy agents (@lukekarrys)

2.0.0 (2023-08-15)

⚠️ BREAKING CHANGES

  • support for node 14 has been removed

Bug Fixes

  • c18b8b3 #47 drop node14 support (@lukekarrys)
  • 5c59b3d #47 use lru-cache named export (@lukekarrys)

Dependencies

  • 6a72624 #47 bump lru-cache from 7.18.3 to 10.0.1

1.1.0 (2023-05-16)

Features

  • 93bdc11 #38 implement getAgent function (#38) (@nlf)
  • 35bad06 #37 implement socks proxy (#37) (@nlf)
  • 471f70b #35 implement the family flag for restricting tcp family (#35) (@nlf)
  • ac89410 #34 implement dns cache (#34) (@nlf)
  • 1f97e18 #30 implement granular timeouts (#30) (@nlf)

Bug Fixes

  • 6eede82 #41 pass parameters into errors so we can attach context to them (#41) (@nlf)

Documentation

1.0.0 (2022-12-08)

⚠️ BREAKING CHANGES

  • @npmcli/agent is now compatible with the following semver range for node: ^14.17.0 || ^16.13.0 || >=18.0.0

Features

  • 0c17ff4 #9 postinstall for dependabot template-oss PR (@lukekarrys)
  • eb1fbfc initial commit (@nlf)

Bug Fixes

  • f06b8ea dont use an agent for the CONNECT request (@nlf)