@adobe/aio-lib-core-networking

中文文档
5.1.0发布于 2025/11/17Apache-2.0CommonJS近 30 天下载 9.4万

Adobe I/O Lib Core Networking

原始使用文档
文档目录18 节
  1. Installing
  2. Usage
  3. Classes
  4. Functions
  5. Typedefs
  6. HttpExponentialBackoff
  7. new HttpExponentialBackoff([options])
  8. httpExponentialBackoff.exponentialBackoff(url, requestOptio…
  9. ProxyFetch
  10. new ProxyFetch(proxyOptions)
  11. proxyFetch.fetch(resource, options) ⇒ Promise.<Response>
  12. createFetch([proxyOptions]) ⇒ function
  13. parseRetryAfterHeader(header) ⇒ number
  14. RetryOptions : object
  15. ProxyOptions : object
  16. Debug Logs
  17. Contributing
  18. Licensing

Version Downloads/week Node.js CI License Codecov Coverage

Adobe I/O Core Networking Lib

Installing

$ npm install @adobe/aio-lib-core-networking

Usage

  1. Initialize the SDK
const { HttpExponentialBackoff, createFetch } = require('@adobe/aio-lib-core-networking')
const fetchRetry = new HttpExponentialBackoff()
const proxyFetch = createFetch()
  1. Call methods using the initialized SDK

const { HttpExponentialBackoff, createFetch } = require('@adobe/aio-lib-core-networking')
const fetchRetry = new HttpExponentialBackoff()
async function sdkTest() {

  return new Promise((resolve, reject) => {
    fetchRetry.exponentialBackoff(url, requestOptions, retryOptions, retryOn, retryDelay)
    .then((response) => {
      if (!response.ok) {
        throw Error(reduceError(response))
      }
      resolve(response.json())
    })
    .catch(err => {
      reject(
        new codes.ERROR_GET_SOMETHING({ sdkDetails, messageValues: err }))
    })
  }) 
}

let proxyFetch 
// this will get the proxy settings from the the HTTP_PROXY or HTTPS_PROXY environment variables, if set
proxyFetch = createFetch()

// this will use the passed in proxy settings. Embed basic auth in the url, if required
proxyFetch = createFetch({ proxyUrl: 'http://my.proxy:8080' })

// if the proxy settings are not passed in, and not available in the HTTP_PROXY or HTTPS_PROXY environment variables, it falls back to a simple fetch
const simpleFetch = createFetch()

Classes

HttpExponentialBackoff

This class provides methods to implement fetch with retries. The retries use exponential backoff strategy with defaults set to max of 3 retries and initial Delay as 100ms

ProxyFetch

This provides a wrapper for fetch that facilitates proxy auth authorization.

Functions

createFetch([proxyOptions]) ⇒ function

Return the appropriate Fetch function depending on proxy settings.

parseRetryAfterHeader(header) ⇒ number

Parse the Retry-After header Spec: https://tools.ietf.org/html/rfc7231#section-7.1.3

Typedefs

RetryOptions : object

Fetch Retry Options

ProxyOptions : object

Proxy Auth Options

HttpExponentialBackoff

This class provides methods to implement fetch with retries. The retries use exponential backoff strategy with defaults set to max of 3 retries and initial Delay as 100ms

Kind: global class

new HttpExponentialBackoff([options])

Creates an instance of HttpExponentialBackoff

ParamTypeDescription
[options]objectconfiguration options
[options.logLevel]stringthe log level to use (default: process.env.LOG_LEVEL or 'info')
[options.logRetryAfterSeconds]numberthe number of seconds after which to log a warning if the Retry-After header is greater than the number of seconds. Set to 0 to disable.

httpExponentialBackoff.exponentialBackoff(url, requestOptions, [retryOptions], [retryOn], [retryDelay]) ⇒ Promise.<Response>

This function will retry connecting to a url end-point, with exponential backoff. Returns a Promise.

Kind: instance method of HttpExponentialBackoff
Returns: Promise.<Response> - Promise object representing the http response

ParamTypeDescription
urlstringendpoint url
requestOptionsobject | Requestrequest options
[retryOptions]RetryOptions(optional) retry options
[retryOn]function | Array(optional) Function or Array. If provided, will be used instead of the default
[retryDelay]function | number(optional) Function or number. If provided, will be used instead of the default

ProxyFetch

This provides a wrapper for fetch that facilitates proxy auth authorization.

Kind: global class

new ProxyFetch(proxyOptions)

Initialize this class with Proxy auth options

ParamTypeDescription
proxyOptionsProxyOptionsthe auth options to connect with

proxyFetch.fetch(resource, options) ⇒ Promise.<Response>

Fetch function, using the configured fetch options, and proxy options (set in the constructor).

Kind: instance method of ProxyFetch
Returns: Promise.<Response> - Promise object representing the http response

ParamTypeDescription
resourcestring | Requestthe url or Request object to fetch from
optionsobjectthe fetch options

createFetch([proxyOptions]) ⇒ function

Return the appropriate Fetch function depending on proxy settings.

Kind: global function
Returns: function - the Fetch API function

ParamTypeDescription
[proxyOptions]ProxyOptionsthe proxy options

parseRetryAfterHeader(header) ⇒ number

Parse the Retry-After header Spec: https://tools.ietf.org/html/rfc7231#section-7.1.3

Kind: global function
Returns: number - Number of milliseconds to sleep until the next call to getEventsFromJournal

ParamTypeDescription
headerstringRetry-After header value

RetryOptions : object

Fetch Retry Options

Kind: global typedef
Properties

NameTypeDescription
maxRetriesnumberthe maximum number of retries to try (default:3)
initialDelayInMillisnumberthe initial delay in milliseconds (default:100ms)
proxyProxyOptionsthe (optional) proxy auth options

ProxyOptions : object

Proxy Auth Options

Kind: global typedef
Properties

NameTypeDescription
proxyUrlstringthe proxy's url
[username]stringthe username for basic auth
[password]stringthe password for basic auth
rejectUnauthorizedbooleanset to false to not reject unauthorized server certs
[logLevel]stringthe log level to use (default: process.env.LOG_LEVEL or 'info')

Debug Logs

LOG_LEVEL=debug <your_call_here>

Prepend the LOG_LEVEL environment variable and debug value to the call that invokes your function, on the command line. This should output a lot of debug data for your SDK calls.

Contributing

Contributions are welcome! Read the Contributing Guide for more information.

Licensing

This project is licensed under the Apache V2 License. See LICENSE for more information.

版本与发布记录

@adobe/aio-lib-core-networking 共发布 14 个版本,首次发布于 2020/02/24;过去 12 个月发布了 1 个版本。

版本发布日期距今
5.1.0latest2025/11/1711 个月前
5.0.42025/02/261.7 年前
5.0.32024/11/142 年前
5.0.22024/06/132 年前
5.0.12024/02/122 年前
5.0.02024/01/102 年前

其他发布通道:next → 4.1.0-pre.2024-01-08.87a2e7f9。

关于 @adobe/aio-lib-core-networking 的常见问题

@adobe/aio-lib-core-networking 是什么?

Adobe I/O Lib Core Networking

如何安装 @adobe/aio-lib-core-networking?

在项目目录运行 npm install @adobe/aio-lib-core-networking,或使用 pnpm add / yarn add / bun add。

@adobe/aio-lib-core-networking 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/adobe__aio-lib-core-networking 是否存在。

@adobe/aio-lib-core-networking 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@adobe/aio-lib-core-networking 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@adobe/aio-lib-core-networking 可以商用吗?

@adobe/aio-lib-core-networking 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@adobe/aio-lib-core-networking 的下载量有多少?

根据 npm 官方下载统计,@adobe/aio-lib-core-networking 在 2026/10/05 – 2026/11/03 这 30 天内被下载 94,455 次,日均约 3,149 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adobe/aio-lib-core-networking 还在维护吗?

最新版本 5.1.0 发布于 2025/11/17(11 个月前);至今共发布 14 个版本,其中过去 12 个月发布了 1 个;首次发布于 2020/02/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。