@forklaunch/universal-sdk

中文文档
1.4.1发布于 2026/10/23MITTypeScriptESM + CJS近 30 天下载 1.3万

Cross runtime fetch library for forklaunch router sdks

原始使用文档

Native service declarations

A native service publishes type-only sdk.ts declarations, including its named DTOs and NotesSdkClient. Consumers import those types and use this package:

import type { NotesSdkClient, HealthResponse } from '@app/notes/sdk';
import { universalSdk } from '@forklaunch/universal-sdk';

const notesSdkClient = universalSdk<NotesSdkClient>;
const notes = await notesSdkClient({
  host: 'https://notes.example.test',
  registryOptions: { url: 'https://notes.example.test/api-definitions' }
});

Native registry operations carry x-forklaunch-operation descriptors. The framework validates their format and dispatches through the checked portable engine, retaining schema, status, media, header, date and SSE validation. Unknown formats fail closed. A type import alone cannot supply runtime validation; consumers must use the matching checked registry and this runtime version. Ordinary TypeScript OpenAPI registries keep the existing dispatch path.

src/portableRuntime.ts is a framework-owned generated snapshot of the canonical Rust compiler runtime. The core sdk_package_layout test checks exact equality; regenerate from its FORKLAUNCH_PACKAGE_SDK_FIXTURE output when changing that runtime. Service packages contain declarations, not copies of this engine.

Service-to-service HMAC

Internal (access: 'internal') routes take the ForkLaunch request HMAC. Pass the target service's key and the SDK signs every request itself, with a fresh timestamp and random nonce, over the final method, URL path (no query) and body bytes:

const billing = await universalSdk<BillingSdkClient>({
  host: process.env.BILLING_URL!,
  registryOptions: { url: `${process.env.BILLING_URL}/openapi.json` },
  hmac: { secretKey: process.env.BILLING_HMAC_SECRET_KEY! } // keyId defaults to 'default'
});

createHmacAuthorization and hmacSignedFetch expose the same signer for hand-written calls. The signed path is the full wire path (POST /payment-link), which every verifier accepts. Express routers used to verify the router-relative req.path (/); that form is still accepted for existing callers but is deprecated, because it is not bound to a mount. Servers can reject it with HMAC_ACCEPT_MOUNT_RELATIVE_PATHS=false.

版本与发布记录

@forklaunch/universal-sdk 共发布 146 个版本,首次发布于 2024/09/11;过去 12 个月发布了 78 个版本。

版本发布日期距今
1.4.1latest2026/10/2323 天前
1.4.02026/10/2323 天前
1.3.02026/10/2125 天前
1.2.312026/10/2126 天前
1.2.302026/10/161 个月前
1.2.292026/09/291 个月前

关于 @forklaunch/universal-sdk 的常见问题

@forklaunch/universal-sdk 是什么?

Cross runtime fetch library for forklaunch router sdks

如何安装 @forklaunch/universal-sdk?

在项目目录运行 npm install @forklaunch/universal-sdk,或使用 pnpm add / yarn add / bun add。

@forklaunch/universal-sdk 支持 TypeScript 吗?

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

@forklaunch/universal-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@forklaunch/universal-sdk 可以商用吗?

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

@forklaunch/universal-sdk 的下载量有多少?

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

@forklaunch/universal-sdk 还在维护吗?

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