@bluebillywig/bb-sapi-node-sdk

中文文档
1.1.1发布于 2026/10/27TypeScriptES Module零依赖近 30 天下载 2175

Blue Billywig Server API SDK for Node.js

原始使用文档
文档目录13 节
  1. Requirements
  2. Installation
  3. Quick Start
  4. Authentication
  5. Entities
  6. Media Clips
  7. Playlists, Channels, Playouts, Subtitles
  8. File Uploads
  9. Thumbnails
  10. Response Handling
  11. Error Handling
  12. Configuration
  13. Development

Blue Billywig SAPI Node.js SDK

This Node.js SDK provides abstractions to interact with the Blue Billywig Server API.

Requirements

  • Node.js >= 18
  • Zero runtime dependencies

Installation

npm install @bluebillywig/bb-sapi-node-sdk

Quick Start

import { Sdk } from '@bluebillywig/bb-sapi-node-sdk';

const sdk = Sdk.withRPCTokenAuthentication(
  'my-publication',
  1,              // token ID
  'shared-secret' // shared secret
);

// List media clips
const response = await sdk.mediaclip.list();
const data = response.json();
console.log(data);

Authentication

The SDK uses HOTP-based RPC token authentication. You need a token ID and shared secret from your Blue Billywig publication settings.

// Recommended: use the convenience factory
const sdk = Sdk.withRPCTokenAuthentication('my-publication', tokenId, sharedSecret);

// Or provide a custom authenticator
import { Sdk, RPCTokenAuthenticator } from '@bluebillywig/bb-sapi-node-sdk';

const authenticator = new RPCTokenAuthenticator(tokenId, sharedSecret);
const sdk = new Sdk('my-publication', authenticator);

Clock synchronization: The RPC token is time-based (HOTP). Both client and server clocks must be reasonably synchronized (within the token expiration window, default 120 seconds). Significant clock drift will cause authentication failures.

Entities

All entities support standard CRUD operations where applicable:

EntityListGetCreateUpdateDelete
sdk.mediaclipYesYesYesYesYes
sdk.playlistYesYesYesYesYes
sdk.channelYesYesYesYesYes
sdk.playoutYesYesYesYesYes
sdk.subtitleYesYesYesYesYes
sdk.thumbnail-----

Media Clips

// List
const response = await sdk.mediaclip.list(15, 0, 'createddate desc');

// Get (with optional language and job inclusion)
const response = await sdk.mediaclip.get(123);
const response = await sdk.mediaclip.get(123, 'en', false);

// Create
const response = await sdk.mediaclip.create({ title: 'My Video' });

// Update
const response = await sdk.mediaclip.update(123, { title: 'Updated Title' });

// Delete (with optional purge)
const response = await sdk.mediaclip.delete(123);
const response = await sdk.mediaclip.delete(123, true); // purge

Playlists, Channels, Playouts, Subtitles

// All follow the same pattern
const response = await sdk.playlist.list();
const response = await sdk.playlist.get(1);
const response = await sdk.playlist.create({ title: 'My Playlist' });
const response = await sdk.playlist.update(1, { title: 'Updated' });
const response = await sdk.playlist.delete(1);

File Uploads

The SDK supports single-chunk and multi-part streaming uploads to S3 via presigned URLs.

// 1. Initialize the upload
const initResponse = await sdk.mediaclip.initializeUpload('/path/to/video.mp4');
initResponse.assertOk();
const uploadData = initResponse.json();

// 2. Execute the upload (streams file data, no full-file buffering)
const success = await sdk.mediaclip.executeUpload('/path/to/video.mp4', uploadData);

// 3. (Optional) Track upload progress
for await (const progress of sdk.mediaclip.uploadProgressGenerator(
  uploadData.listPartsUrl,
  uploadData.headObjectUrl,
  uploadData.chunks,
)) {
  console.log(`Upload progress: ${progress}%`);
}

Thumbnails

// Generate an absolute thumbnail URL with dimensions
const url = sdk.thumbnail.getAbsoluteImagePath('/path/to/image.jpg', 640, 360);
// => https://my-publication.bbvms.com/image/640/360/path/to/image.jpg

Response Handling

All entity methods return a SapiResponse object:

const response = await sdk.mediaclip.get(123);

// Check status
if (response.ok) {
  const data = response.json();
}

// Or assert (throws on non-2xx)
response.assertOk();
const data = response.json();

// Access response details
response.statusCode;           // e.g. 200
response.body;                 // raw body string
response.header('Content-Type');
response.queryParam('limit');  // query param from the request URL
response.statusCategory;       // HTTPStatusCodeCategory enum

// Batch response utilities
SapiResponse.allOk(responses);         // true if all 2xx
SapiResponse.assertAllOk(responses);   // throws on first non-2xx
SapiResponse.failedResponses(responses); // generator yielding non-2xx responses

Error Handling

The SDK throws typed exceptions for HTTP errors:

import {
  HTTPRequestException,
  HTTPClientErrorException,
  HTTPServerErrorException,
} from '@bluebillywig/bb-sapi-node-sdk';

try {
  const response = await sdk.mediaclip.get(999);
  response.assertOk();
} catch (error) {
  if (error instanceof HTTPClientErrorException) {
    // 4xx error
    console.error(`Client error ${error.statusCode}: ${error.message}`);
    console.error('Response body:', error.responseBody);
  } else if (error instanceof HTTPServerErrorException) {
    // 5xx error
    console.error(`Server error ${error.statusCode}: ${error.message}`);
  }
}

Configuration

const sdk = Sdk.withRPCTokenAuthentication('my-publication', tokenId, sharedSecret, {
  // Override the base URI (useful for testing or custom deployments)
  baseUri: 'https://custom-host.example.com',

  // Inject a custom fetch implementation (useful for testing)
  fetch: customFetchFn,
});

Development

# Install dependencies
npm install

# Type check
npm run typecheck

# Run tests
npm test

# Build
npm run build

版本与发布记录

@bluebillywig/bb-sapi-node-sdk 共发布 3 个版本,首次发布于 2026/03/20;过去 12 个月发布了 3 个版本。

版本发布日期距今
1.1.1latest2026/10/2712 天前
1.0.12026/03/207 个月前
1.0.02026/03/207 个月前

关于 @bluebillywig/bb-sapi-node-sdk 的常见问题

@bluebillywig/bb-sapi-node-sdk 是什么?

Blue Billywig Server API SDK for Node.js

如何安装 @bluebillywig/bb-sapi-node-sdk?

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

@bluebillywig/bb-sapi-node-sdk 支持 TypeScript 吗?

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

@bluebillywig/bb-sapi-node-sdk 支持 ESM 还是 CommonJS?

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

@bluebillywig/bb-sapi-node-sdk 需要什么版本的 Node.js?

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

@bluebillywig/bb-sapi-node-sdk 可以商用吗?

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

@bluebillywig/bb-sapi-node-sdk 的下载量有多少?

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

@bluebillywig/bb-sapi-node-sdk 还在维护吗?

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