@nemphi/sdk

中文文档
0.2.4682发布于 2026/11/02MITTypeScriptES Module零依赖

Typed TypeScript client for the Nemphi API — auth, tools, and the same pipeline the product uses

原始使用文档
文档目录7 节
  1. Install
  2. Quick start
  3. Configuration
  4. Auth
  5. Errors
  6. What it covers
  7. Maintainer workflow

@nemphi/sdk

Typed TypeScript client for the Nemphi API. Zero runtime dependencies. It uses the platform fetch. Business tool invocations use the same tenant scoping, policy, idempotency, and action ledger as the product UI.

Install

npm install @nemphi/sdk
# or: pnpm add @nemphi/sdk / yarn add @nemphi/sdk

Requires Node 20+ (or any runtime with global fetch).

Quick start

import { createClient } from "@nemphi/sdk";

const nemphi = createClient({
  baseUrl: "https://api.nemphi.com",
  // API key (nk_…) is tenant-bound. Session tokens (nse_…) also need tenantId.
  token: process.env.NEMPHI_API_KEY!,
});

const { invoice, journal_entry } = await nemphi.postInvoice(invoiceId, {
  idempotencyKey: `post-${invoiceId}`,
});

console.log(invoice.status, journal_entry.entry_number);

Configuration

OptionDescription
baseUrlAPI origin, e.g. https://api.nemphi.com
tokenBearer credential: API key (nk_…) or session token (nse_…)
tenantIdRequired for tenant-scoped calls when using a user session
headersExtra headers on every request
fetchCustom fetch (defaults to the global)

Auth

  • API keys are created in the workspace settings and are already bound to one tenant — pass them as token, no tenantId needed.
  • User sessions need both token and tenantId (X-Tenant-Id).
const session = createClient({
  baseUrl: "https://api.nemphi.com",
  token: sessionToken,
  tenantId: workspaceId,
});

Errors

import { ApiError } from "@nemphi/sdk";

try {
  await nemphi.postInvoice(id);
} catch (err) {
  if (err instanceof ApiError) {
    // status, code (e.g. "approval_required"), message, body
    console.error(err.status, err.code, err.message);
  }
  throw err;
}

What it covers

The client mirrors the HTTP surface used by the Nemphi web app: auth, workspaces, tools (invoke / typed helpers), actions, runs, dashboards, mail, CRM, and more. Types live next to the client in the same module.

For the design contract, see docs/backbone.md in the monorepo (§3 pillars, §9 API contracts).

Maintainer workflow

The web and mobile apps use workspace:*. Rebuild their SDK with pnpm build:sdk after source changes. Merging an SDK change to master publishes it to npm; PUBLISHING.md covers versioning, package checks, and releases.

The private @nemphi/admin-sdk owns /v1/admin/*; those methods do not belong in this public package.

版本与发布记录

@nemphi/sdk 共发布 8 个版本,首次发布于 2026/04/18;过去 12 个月发布了 8 个版本。

版本发布日期距今
0.2.4682latest2026/11/021 天前
0.2.46482026/11/021 天前
0.2.46432026/11/021 天前
0.2.46112026/11/021 天前
0.2.46092026/11/021 天前
0.2.45992026/11/021 天前

关于 @nemphi/sdk 的常见问题

@nemphi/sdk 是什么?

用于Nemphi API的类型化TypeScript客户端——授权、工具和产品使用的相同管道

如何安装 @nemphi/sdk?

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

@nemphi/sdk 支持 TypeScript 吗?

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

@nemphi/sdk 支持 ESM 还是 CommonJS?

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

@nemphi/sdk 需要什么版本的 Node.js?

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

@nemphi/sdk 可以商用吗?

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

@nemphi/sdk 还在维护吗?

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