@dialstack/sdk-js

中文文档
3.10.0发布于 2026/11/10MITTypeScriptESM + CJS近 30 天下载 4007

DialStack browser SDK — initialisation, REST client and the self-registering web components

原始使用文档
文档目录7 节
  1. Install
  2. Usage
  3. Importing this package registers the elements
  4. Errors
  5. Which package do I want?
  6. Documentation
  7. License

@dialstack/sdk-js

The DialStack browser SDK — initialization, the REST client, and six self-registering web components.

Everything a plain HTML or JavaScript page needs. React bindings live in @dialstack/sdk-react, which peers on this package.

Install

npm install @dialstack/sdk-js

Or from a <script> tag, no bundler required:

<script src="https://unpkg.com/@dialstack/sdk-js"></script>

The script build exposes everything on window.DialStack.

Usage

import { loadDialstackAndInitialize } from '@dialstack/sdk-js';

const dialstack = await loadDialstackAndInitialize({
  publishableKey: 'pk_live_…',
  fetchClientSecret: async () => {
    const res = await fetch('/api/dialstack-session', { method: 'POST' });
    return (await res.json()).client_secret;
  },
});
<dialstack-call-logs></dialstack-call-logs> <dialstack-voicemails></dialstack-voicemails>

Importing this package registers the elements

That is a side effect, and it is deliberate: the entry point imports each component module, and each ends in customElements.define(...). So a single import '@dialstack/sdk-js' is what makes <dialstack-call-logs> a real element rather than an inert unknown one.

Two things follow.

sideEffects is an allowlist, not false. A blanket false would let a bundler drop those imports as unused, and the failure is silent — document.createElement succeeds for an unregistered tag and returns an element that renders nothing, with no error. If you are vendoring or re-bundling this package, preserve that field.

Use ./pure when you do not want the side effect. Same surface, nothing registered on import; you call registerComponents() yourself. That is what you want for server-side rendering, for tests, and anywhere a module-level customElements.define would run too early or in the wrong realm.

import { registerComponents, loadDialstackAndInitialize } from '@dialstack/sdk-js/pure';

if (typeof window !== 'undefined') registerComponents();

Errors

Catch API failures with isApiError, not instanceof ApiError:

import { isApiError } from '@dialstack/sdk-js';

try {
  await dialstack.phoneNumbers.list();
} catch (err) {
  if (isApiError(err) && err.status === 409) {
    /* … */
  }
}

instanceof compares against one specific class object, so it returns false whenever two copies of this package end up in a tree, or when the error crosses a realm. isApiError reads the fields carried on the error itself and cannot skew.

Which package do I want?

You are buildingInstall
A plain HTML pagethis package alone
A React app with DialStack UIthis package + @dialstack/sdk-react
A softphone in any framework@dialstack/sdk-webrtc
A Node backend@dialstack/sdk-server

Documentation

Full documentation: https://docs.dialstack.ai/sdks

License

MIT

版本与发布记录

@dialstack/sdk-js 共发布 12 个版本,首次发布于 2026/08/10;过去 12 个月发布了 12 个版本。

版本发布日期距今
3.10.0latest2026/11/102 天前
3.9.02026/11/029 天前
3.8.02026/10/2616 天前
3.7.02026/10/1923 天前
3.6.02026/10/1230 天前
3.5.02026/10/051 个月前

其他发布通道:bootstrap → 2.1.0。

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

@dialstack/sdk-js 是什么?

DialStack browser SDK — initialisation, REST client and the self-registering web components

如何安装 @dialstack/sdk-js?

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

@dialstack/sdk-js 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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

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

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