@btravstack/temporal-client

中文文档
0.58.0发布于 2026/11/08MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 7702

Scoped DI bindings for @temporal-contract/client

原始使用文档

@btravstack/temporal-client

Bind a native Temporal connection and an @temporal-contract/client TypedClient to application DI ports. Add temporalConnection(connectionPort, settingsPort) and temporalClient(clientPort, connectionPort, settingsPort) to the module's providers. Settings supply address and namespace. The connection closes with the module scope; an unreachable service returns the modeled TemporalClientUnreachable error.

Pass a fourth port, temporalClient(clientPort, connectionPort, settingsPort, dataConverterPort), to encode payloads with the DataConverter it resolves — the same port the worker's dataConverter option names.

The settings may also carry the connection's security — TLS, a server CA and name, an mTLS certificate and key, or an API key — and temporalSecurity binds them from Temporal's own variables (TEMPORAL_TLS, TEMPORAL_TLS_SERVER_CA_CERT_PATH, TEMPORAL_TLS_SERVER_NAME, TEMPORAL_TLS_CLIENT_CERT_PATH, TEMPORAL_TLS_CLIENT_KEY_PATH, TEMPORAL_API_KEY, TEMPORAL_API_KEY_PATH). Mounted files are read again every TEMPORAL_CREDENTIALS_RELOAD_MS, so a renewed certificate or key is used without a restart. Atomic projected Secret generations are read coherently, with bounded retry when their targets change; stable missing and empty files remain reported together. A combination it cannot connect with is a ConfigInvalid. See the reference.

Call client.for(contract) to obtain the typed workflow and schedule API. The schedule deployment shows the providers in a real module. Workflow arguments and schedule policy remain in the application.

client.for(contract) also runs a contract's activity with no workflow around it (Temporal Server 1.32 or later):

const result = await client.for(pdfContract).executeActivity("renderInvoice", {
  activityId: `invoice-${invoiceId}`,
  args: { invoiceId },
});

startActivity returns a handle at once and getActivityHandle reattaches to one.

An application can supply renewable bearer credentials through an apiKey port implementing TemporalApiKeySource.read(). The source owns token acquisition, caching and expiry; the starter polls it with the credentials reload interval. A source requires TLS and excludes inline/file API keys and mTLS. See the reference for composition and fail-closed behavior.

版本与发布记录

@btravstack/temporal-client 共发布 45 个版本,首次发布于 2026/10/09;过去 12 个月发布了 45 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.58.0latest2026/11/08今天
0.57.02026/11/071 天前
0.56.12026/11/062 天前
0.56.02026/11/062 天前
0.55.12026/11/035 天前
0.55.02026/11/035 天前

关于 @btravstack/temporal-client 的常见问题

@btravstack/temporal-client 是什么?

Scoped DI bindings for @temporal-contract/client

如何安装 @btravstack/temporal-client?

在项目目录运行 npm install @btravstack/temporal-client,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:unthrown(^5.12.0)、@btravstack/di(^0.58.0)、@btravstack/config(^0.58.0)、@temporalio/client(^1.24.0)、@temporalio/common(^1.24.0)、@temporal-contract/client(^8.0.0-beta.15)、@temporal-contract/contract(^8.0.0-beta.15)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@btravstack/temporal-client 支持 TypeScript 吗?

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

@btravstack/temporal-client 支持 ESM 还是 CommonJS?

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

@btravstack/temporal-client 需要什么版本的 Node.js?

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

@btravstack/temporal-client 可以商用吗?

@btravstack/temporal-client 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@btravstack/temporal-client 的下载量有多少?

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

@btravstack/temporal-client 还在维护吗?

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