@droz-js/sdk

中文文档
0.26.52发布于 2026/11/13CommonJS近 30 天下载 1万

Droz SDK

原始使用文档
文档目录7 节
  1. Setup (required)
  2. Global Error Handling
  3. Websocket
  4. Example with AsyncIterator
  5. Available Sdks
  6. Droz Nexo
  7. Droz Chat

@droz-js/sdk

Setup (required)

To set up the sdk you need to tell the tenant and the authentication method, the tenant is required. You must run this first before making any sdk calls. The sdk will fail if you don't set up the tenant.

import { DrozSdk } from '@droz-js/sdk';

DrozSdk.forTenant('dev').withAuthorization('Basic', 'username', 'password');

You can also split the setup in two steps

import { DrozSdk } from '@droz-js/sdk';

// first step (required)
DrozSdk.forTenant('dev');

// (optional) later when you have the authentication token you can set it and it will automatically be used in the new requests
DrozSdk.withAuthorization('Basic', 'username', 'password');

Global Error Handling

The sdk will throw an error on every request that fails, but you can also catch the error globally by using the on method.

import { DrozSdk } from '@droz-js/sdk';

DrozSdk.on('error', (error) => {
  console.log(error);
});

Every error sent is of type SdkError and contains the following properties:

  • message: the original error message sent from the server;
  • statusCode: similar to the http status codes and indicates the class of the error, 400 bad request, 403 forbidden, 404 not found...;
  • errorCode: a unique identifier for the error, this is useful to for i18n friendly messages;

Websocket

For websockets we use graphql-ws protocol with AsyncIterator to handle the subscriptions. The sdk will automatically handle the connection and reconnection for you, see https://the-guild.dev/graphql/ws/recipes#client-usage-with-asynciterator on how to use the AsyncIterator.

Example with AsyncIterator

import { DrozSdk } from '@droz-js/sdk';
import { DrozChat } from '@droz-js/sdk/drozchat';

DrozSdk.forTenant('dev');

const chat = new DrozChat();
const iterable = chat.onTicketInQueue();
for await (const result of iterable) {
  console.log(result);
}

For the React developers

import { DrozSdk } from '@droz-js/sdk';
import { DrozChat } from '@droz-js/sdk/drozchat';

DrozSdk.forTenant('dev');

function useOnTicketInQueue() {
  const chat = new DrozChat();
  const [tickets, setTickets] = useState<Ticket[]>([]);

  useEffect(() => {
    const subscription = chat.onTicketInQueue();

    // YES I KNOW, REACT SUCKS
    (async () => {
      // attention! this is just an example what you do with the result is up to you
      for await (const each of subscription) setTickets(tickets => [...tickets, each]);
    })();

    // this is required to close the subscription when the component unmounts
    return () => subscription.return();
  }, []);
}

Available Sdks

Droz Nexo

import { DrozNexo } from '@droz-js/sdk/droznexo';

Droz Chat

import { DrozChat } from '@droz-js/sdk/drozchat';

版本与发布记录

@droz-js/sdk 共发布 480 个版本,首次发布于 2023/10/07;过去 12 个月发布了 241 个版本。

版本发布日期距今
0.26.52latest2026/11/13今天
0.26.512026/11/121 天前
0.26.502026/11/121 天前
0.26.492026/11/121 天前
0.26.482026/11/112 天前
0.26.472026/11/103 天前

关于 @droz-js/sdk 的常见问题

@droz-js/sdk 是什么?

Droz SDK

如何安装 @droz-js/sdk?

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

@droz-js/sdk 支持 TypeScript 吗?

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

@droz-js/sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@droz-js/sdk 可以商用吗?

@droz-js/sdk 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@droz-js/sdk 的下载量有多少?

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

@droz-js/sdk 还在维护吗?

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