@arcjet/transport

中文文档
1.15.0发布于 2026/10/29Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 33.4万

Transport mechanisms for the Arcjet protocol

原始使用文档
文档目录13 节
  1. What is this?
  2. When should I use this?
  3. Install
  4. Node.js version support
  5. Use
  6. API
  7. createTransport(baseUrl[, options])
  8. createHttp2Transport(baseUrl[, http2SessionOptions])
  9. Proxy support
  10. ProxyEnvironment
  11. TransportLogger
  12. TransportOptions
  13. License
Arcjet Logo

@arcjet/transport

npm badge

Transport mechanisms for the Arcjet protocol.

What is this?

This package provides a way to talk to our protocol.

When should I use this?

This is an internal Arcjet package not designed for public use. See our Get started guide for how to use Arcjet in your application.

Install

This package is ESM only. Install with npm in Node.js:

npm install @arcjet/transport

Node.js version support

This package requires >=22.21.0 <23 || >=24.5.0. Proxy support relies on the built-in proxy support of the Node.js HTTP agent, which is only available on Node.js >=22.21.0 and, on the 24 line, >=24.5.0. Node.js 20 is end-of-life and Node.js 23 is not supported. Anyone tracking an active LTS release is unaffected.

Because every Arcjet SDK depends on this package, the same requirement applies across the Arcjet SDKs.

Use

import { createTransport } from "@arcjet/transport";

const transport = createTransport("https://decide.arcjet.com");
// This can now be passed to `createClient` from `@arcjet/protocol`.

API

This package exports the identifier createTransport. There is no default export.

The unconditional subpath @arcjet/transport/http2 exports createHttp2Transport for callers that need the Node HTTP/2 Connect path regardless of the package's runtime export conditions (used by @arcjet/guard on Bun).

This package exports the TypeScript types ProxyEnvironment, TransportLogger, and TransportOptions.

createTransport(baseUrl[, options])

Creates a transport that talks to the Arcjet API. On Node.js it uses @connectrpc/connect-node over HTTP/2; separate entry points for Bun, Deno, Edge Light, and workerd use @connectrpc/connect-web instead. This is a thin wrapper around createConnectTransport.

Direct HTTP/2 sessions (and HTTP/2-over-CONNECT when proxyHttpVersion is "2") enable PING keep-alive and recycle the connection after consecutive deadline failures, matching the recovery behavior introduced for Guard in #6137.

createHttp2Transport(baseUrl[, http2SessionOptions])

Creates a direct HTTP/2 Connect transport with PING keep-alive and deadline-based connection recycling. Returns { transport, sessionManager } so callers can tear the session down. Import from @arcjet/transport/http2.

Proxy support

The standard proxy environment variables (HTTP_PROXY and HTTPS_PROXY, while respecting NO_PROXY) are auto-detected, making it possible to connect to the Arcjet API through a proxy such as Squid. When a proxy is in use, a line is logged at startup at info level (so set ARCJET_LOG_LEVEL=info to see it). The proxy URL itself is not logged, since it can contain credentials. How the request is actually proxied depends on the runtime, using each runtime's built-in proxy support:

  • Node.js — requests are routed through the proxy over HTTP/1.1 using the built-in proxy support of the Node.js HTTP agent; otherwise they are made directly over HTTP/2. Set proxyHttpVersion: "2" to instead keep HTTP/2 while proxying (see HTTP/2 through a proxy below).
  • Bun and Deno — the runtime's fetch performs the proxying natively.
  • Edge Light and workerd — these edge runtimes don't support outbound proxy environment variables, so no proxy is used.

NO_PROXY accepts a comma- or space-separated list of host suffixes, each with an optional leading . or *. and an optional :port, plus * to bypass the proxy for every host. Entries are matched as host names; IP/CIDR ranges (such as 10.0.0.0/8) are not supported, the same as curl. On Bun and Deno the runtime's fetch applies NO_PROXY itself, so its exact semantics are the runtime's.

HTTP/2 through a proxy

By default, proxying on Node.js downgrades the connection from HTTP/2 to HTTP/1.1, because Node's built-in agent proxy support only works over HTTP/1.1. For a latency-sensitive API this is unfortunate: it gives up HTTP/2's multiplexing, so a burst of concurrent requests opens a new proxy connection each instead of sharing one.

Setting proxyHttpVersion: "2" keeps HTTP/2 end-to-end. The transport opens an HTTP CONNECT tunnel to the proxy and then performs the TLS handshake — and the ALPN negotiation that selects h2 — directly with the origin. The proxy only blindly forwards the tunnel, so it never sees, and cannot downgrade, the negotiated protocol.

This comes with caveats:

  • Node.js only. Bun and Deno don't implement the agent option this builds on; they proxy through their fetch (over HTTP/1.1) regardless of this setting, and the edge runtimes don't proxy at all.
  • Requires a tunneling (CONNECT) proxy — the common kind for HTTPS egress, including Squid. A proxy that terminates TLS and re-originates an HTTP/1.1 connection to the origin (a TLS-intercepting / "MITM" proxy) cannot preserve HTTP/2 no matter what this option is set to.
  • The proxy must not buffer the tunnel. HTTP/2 sends many small, dependent frames. The transport disables Nagle's algorithm (TCP_NODELAY) on its side of the tunnel, but if the proxy buffers tunneled bytes (or leaves Nagle enabled on its upstream socket) the interaction with delayed ACKs can add roughly 40 ms of latency per round trip, erasing the benefit. Tunneling proxies such as Squid set TCP_NODELAY on CONNECT tunnels by default; verify this if you use a different proxy.

When no proxy applies, this option has no effect — direct connections always use HTTP/2.

Parameters
  • baseUrl (string, example: https://example.com/my-api) — the base URL for all HTTP requests
  • options (TransportOptions, optional) — configuration
Returns

A Connect transport that you can pass to createClient from @arcjet/protocol.

ProxyEnvironment

Map of environment variables used to detect an outbound proxy (TypeScript type). This is the same shape as process.env.

TransportLogger

Logger used to print a line at startup when a proxy is detected (TypeScript type). It must provide an info method.

TransportOptions

Configuration for createTransport (TypeScript type).

Fields
  • log (TransportLogger, optional) — logger used to print a line at startup when a proxy is detected; defaults to a logger configured from the ARCJET_LOG_LEVEL environment variable
  • proxyEnv (ProxyEnvironment or false, optional) — environment variables used to detect an outbound proxy; defaults to process.env so standard proxy environment variables are auto-detected; pass false to ignore proxy environment variables
  • proxyHttpVersion ("1.1" or "2", optional, default "1.1") — HTTP version to use when a proxy is in use on Node.js; "1.1" routes through the proxy using the Node.js HTTP agent, while "2" keeps HTTP/2 by tunneling through the proxy with CONNECT; has no effect without a proxy, or on Bun, Deno, and the edge runtimes (see HTTP/2 through a proxy)

License

Apache License, Version 2.0 © Arcjet Labs, Inc.

版本与发布记录

@arcjet/transport 共发布 58 个版本,首次发布于 2024/08/06;过去 12 个月发布了 30 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.15.0latest2026/10/298 天前
1.14.12026/10/0730 天前
1.14.02026/10/021 个月前
1.13.02026/09/171 个月前
1.12.02026/09/091 个月前
1.11.02026/08/272 个月前

其他发布通道:rc → 1.10.0-rc.1。

关于 @arcjet/transport 的常见问题

@arcjet/transport 是什么?

Transport mechanisms for the Arcjet protocol

如何安装 @arcjet/transport?

在项目目录运行 npm install @arcjet/transport,或使用 pnpm add / yarn add / bun add。

@arcjet/transport 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@arcjet/transport 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@arcjet/transport 需要什么版本的 Node.js?

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

@arcjet/transport 可以商用吗?

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

@arcjet/transport 的下载量有多少?

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

@arcjet/transport 还在维护吗?

最新版本 1.15.0 发布于 2026/10/29(8 天前);至今共发布 58 个版本,其中过去 12 个月发布了 30 个;首次发布于 2024/08/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。