@dazl/api-client

中文文档
1.0.98发布于 2026/11/09UNLICENSEDES Module零依赖近 30 天下载 3.6万

Type-safe SDK for Dazl APIs, generated from OpenAPI specifications

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Acting on behalf of a user
  4. Related Docs
  5. Major messaging compatibility

Dazl Internal API Client

Type-safe SDK for Dazl Internal APIs, generated from OpenAPI specifications.

Installation

npm install @dazl/api-client

Usage

Create a client instance with createClient and pass it to every API call:

import { createClient } from '@dazl/api-client/internal/fetch-client';
import { Billing } from '@dazl/api-client/internal';

const client = createClient({
    baseUrl: 'http://api-server-url/private',
    headers: {
        'x-api-key': 'my-secret-api-key',
    },
});

const customerInfoRes = await Billing.getCustomerInfoByDazlId({
    path: { dazlId: 'USER_DAZL_ID' },
    client,
});

if (customerInfoRes.error) {
  throw new Error(customerInfoRes.error.message);
}
const customerInfo = customerInfoRes.data;

Acting on behalf of a user

The recommended pattern is to create a per-request client with the x-user-id header baked in, and store it on the request context:

// middleware — runs once per request
const userClient = createClient({
    baseUrl: 'http://api-server-url/private',
    headers: {
        'x-api-key': 'my-secret-api-key',
        'x-user-id': context.userId,   // userId from the authenticated request
    },
});
context.apiClient = userClient;

// handler — no need to pass headers each time
const customerInfoRes = await Billing.getCustomerInfoByDazlId({
    path: { dazlId: 'USER_DAZL_ID' },
    client: context.apiClient,
});

Additional client fetch documentation can be found here: https://heyapi.dev/openapi-ts/clients/fetch

Major messaging compatibility

The generated WorkspaceMailbox, ChatInbox, and MajorConversation clients include additive reply correlation, sender-only Retry eligibility/creation, and appendMajorIncoming. Generate with npm run update:sdk:local from the repository root. Generated sources under sdk/src/ are build outputs, as for the other API contracts.

Deploy the additive migration and API first, publish the regenerated SDK, then update the dazl SDK dependency before deploying its caller. getWorkspaceMessagingCapabilities distinguishes support from older servers; a failed check is unknown. Receipt responses remain status-only. appendMajorIncoming accepts only the incoming mailbox identity, derives its content and owner on the server, and preserves the destination conversation's title and retention timestamp.

版本与发布记录

@dazl/api-client 共发布 98 个版本,首次发布于 2026/07/06;过去 12 个月发布了 98 个版本。

版本发布日期距今
1.0.98latest2026/11/092 天前
1.0.972026/11/092 天前
1.0.962026/11/083 天前
1.0.952026/11/083 天前
1.0.942026/11/066 天前
1.0.932026/11/056 天前

关于 @dazl/api-client 的常见问题

@dazl/api-client 是什么?

Type-safe SDK for Dazl APIs, generated from OpenAPI specifications

如何安装 @dazl/api-client?

在项目目录运行 npm install @dazl/api-client,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:zod(^4.4.3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dazl/api-client 支持 TypeScript 吗?

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

@dazl/api-client 支持 ESM 还是 CommonJS?

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

@dazl/api-client 可以商用吗?

@dazl/api-client 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@dazl/api-client 的下载量有多少?

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

@dazl/api-client 还在维护吗?

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