@bulbthings/bulbthings-sdk

中文文档
1.9.1发布于 2026/11/05TypeScriptCommonJS构建来源已验证近 30 天下载 2195

Isomorphic JavaScript / TypeScript SDK 为 Bulbthings API 配音

中文使用文档
文档目录12 节
  1. 完整文档
  2. 安装
  3. 认证
  4. 快速启动示例
  5. API 资源
  6. 查找全部
  7. 找到 ById 键盘
  8. 创建
  9. 更新ById
  10. 删除字节
  11. 活动
  12. 示例用途

块状SDK

npm

Bulbthings SDK允许您方便地与Bulbthings API互动. SDK兼容任何支持JavaScript/TypeScript的环境,包括网页浏览器,React Industrial或Node.js应用程序.

更多关于Bulbthings的资讯: https://bulbthings.com (中文(简体) )

完整文档

安装

npm install @bulbthings/bulbthings-sdk

认证

import { Bulbthings } from '@bulbthings/bulbthings-sdk';

const bulbthings = new Bulbthings({ apiToken: '83945b4eaf...7a37a' });

// Authentication can also be overridden per request
bulbthings.entities.findAll({ apiToken: '83945b4eaf...7a37a' });

快速启动示例

// Fetch your workspace
const workspace = await bulbthings.companies.findById('WORKSPACE_ID');

// Create a category of entities
const customCategory = await bulbthings.entityTypes.create({
    companyId: workspace.id,
    label: 'Category',
});

// Show the category in the workspace
await bulbthings.catalogMappings.create({
    companyId: workspace.id,
    entityTypeId: customCategory.id,
    catalogId: workspace.catalogId,
});

// Create an entity
const entity = await bulbthings.entities.create({
    companyId: workspace.id,
    entityTypeId: customCategory.id,
});

// Create a custom field
const customField = await bulbthings.attributeTypes.create({
    companyId: workspace.id,
    schema: { title: 'Custom property', type: 'string' },
});

// Show the field on the category profiles
await bulbthings.entityTypeMappings.create({
    companyId: workspace.id,
    entityTypeId: customCategory.id,
    type: 'attributeType',
    attributeTypeId: customField.id,
});

// Update the field value for the entity
await bulbthings.measurements.create({
    entityId: entity.id,
    attributeTypeId: customField.id,
    value: 'test',
});

API 资源

大多数API资源都采用相同的CRUD模式,方法如下:

查找全部

此方法返回资源列表 .

const entities = await bulbthings.entities.findAll({
    filter: `and(
        gt(attributes.mileage.km, 10000),
        ne(attributes.license, null)
    )`,
    include: ['entityType'],
    page: { limit: 3 },
});

// Or with pagination metadata
const { data: entities, meta } = await bulbthings.entities.findAll(
    { page: { limit: 3 } },
    true
);

找到 ById 键盘

此方法返回单一资源, 使用其标识符 :

const entity = await bulbthings.entities.findById('31845...c8ad6e', {
    include: ['entityType'],
});

创建

这种方法创建了新的资源:

const measurement = await bulbthings.measurements.create({
    entityId: entity.id,
    attributeTypeId: 'mileage',
    value: 42000,
    period: {
        from: new Date(),
        to: new Date(),
    },
    unitId: 'km',
});

更新ById

这种方法更新了资源 :

const updatedMeasurement = await bulbthings.measurements.update(
    measurement.id,
    { value: 43000 }
);

删除字节

此方法删除资源 :

await bulbthings.entities.deleteById(entity.id);

活动

每次创建、修改或删除资源都会引发系统事件(不与实际的 events 资源您可以使用 SDK 实时接收和反应.

示例用途

// Event types follow the format: [resource][Created|Updated|Deleted]
const eventType = 'entityCreated';

bulbthings.on([eventType], (event) => {
    // `data.resource` contains the resource described by the event
    // In case of an update event, `data.previousData` contains
    // the values of updated properties before the change
    const entity = event.data.resource as Entity;
});

版本与发布记录

@bulbthings/bulbthings-sdk 共发布 24 个版本,首次发布于 2026/03/22;过去 12 个月发布了 24 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.9.1latest2026/11/053 天前
1.9.02026/10/2910 天前
1.8.02026/10/2911 天前
1.7.02026/10/2218 天前
1.6.02026/09/301 个月前
1.5.02026/09/211 个月前

关于 @bulbthings/bulbthings-sdk 的常见问题

@bulbthings/bulbthings-sdk 是什么?

Isomorphic JavaScript / TypeScript SDK 为 Bulbthings API 配音

如何安装 @bulbthings/bulbthings-sdk?

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

@bulbthings/bulbthings-sdk 支持 TypeScript 吗?

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

@bulbthings/bulbthings-sdk 支持 ESM 还是 CommonJS?

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

@bulbthings/bulbthings-sdk 可以商用吗?

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

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

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

@bulbthings/bulbthings-sdk 还在维护吗?

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