@bulbthings/bulbthings-sdk

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

Isomorphic JavaScript/TypeScript SDK for the Bulbthings API

原始使用文档
文档目录12 节
  1. Full documentation
  2. Installation
  3. Authentication
  4. Quick start example
  5. API resources
  6. findAll
  7. findById
  8. create
  9. updateById
  10. deleteById
  11. Events
  12. Example usage

Bulbthings SDK

npm

The Bulbthings SDK allows you to conveniently interact with the Bulbthings API. The SDK is compatible with any environment where JavaScript/TypeScript is supported, including web browsers, React Native or Node.js applications.

Learn more about Bulbthings on our website: https://bulbthings.com

Full documentation

Installation

npm install @bulbthings/bulbthings-sdk

Authentication

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' });

Quick start example

// 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 resources

Most API resources follow the same CRUD model with the following methods:

findAll

This method returns a list of resources.

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
);

findById

This method returns a single resource, using its identifier:

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

create

This method creates a new resource:

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

updateById

This method updates a resource:

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

deleteById

This method deletes a resource:

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

Events

Every creation, modification or deletion of resources will trigger system events (not to be confused with the actual events resource) that you can receive and react to in real-time using the SDK.

Example usage

// 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 for the 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 和提交记录判断。