@bilte-co/socky-js

中文文档
0.6.3发布于 2026/06/03Apache-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 3869

JavaScript SDK for the Socky Flights API

原始使用文档
文档目录16 节
  1. Install
  2. Quickstart (ESM)
  3. Quickstart (CJS)
  4. Configuration
  5. Error Handling
  6. Pagination
  7. Retries and Timeouts
  8. API
  9. Aircraft
  10. Flights
  11. Locations
  12. Positions
  13. Routes
  14. Stations
  15. Node support
  16. License

socky

JavaScript SDK for the public routes of the Socky Flights API.

Install

aube add @bilte-co/socky-js
# or: npm i @bilte-co/socky-js

Quickstart (ESM)

import { Socky } from 'socky';

// Do not expose your API key to the client.
const client = new Socky({ apiKey: process.env.SOCKY_API_KEY });

// Get flight data
const flight = await client.flights.get('01JCTA5XQZF8B3G5N2W9K7M4VP');

// Get aircraft information
const aircraft = await client.aircraft.get('N12345');

// List stations with pagination
const stations = await client.stations.list();
console.log(stations.items);
console.log(stations.hasMore);

Quickstart (CJS)

const { Socky } = require('socky');

// Do not expose your API key to the client.
const client = new Socky({ apiKey: process.env.SOCKY_API_KEY });

// Use the client as shown above

Configuration

The SDK accepts the following configuration options:

const client = new Socky({
  apiKey: 'your-api-key',        // Required
  baseUrl: 'https://api.custom.com/',  // Optional, defaults to 'https://api.socky.flights/'
  version: 'v1',                  // Optional, defaults to 'v1'
  timeoutMs: 30000,               // Optional, request timeout in ms (default: 30000)
  retries: 2,                     // Optional, number of retries on failure (default: 2)
  retryBackoffMs: 250,            // Optional, initial retry backoff in ms (default: 250)
  userAgent: 'my-app/1.0',       // Optional, custom user agent string
});

Error Handling

The SDK throws typed ApiError instances with detailed information:

import { Socky, ApiError } from 'socky';

try {
  const flight = await client.flights.get('invalid-id');
} catch (error) {
  if (error instanceof ApiError) {
    console.log(error.status);      // HTTP status code
    console.log(error.message);     // Error message
    console.log(error.code);        // Optional error code from API
    console.log(error.requestId);   // Optional request ID for debugging
    console.log(error.retryAfterMs); // Optional retry-after hint
    console.log(error.body);        // Raw error response body
  }
}

Pagination

Paginated endpoints return a Page<T> object with helpers for iteration:

// Manual pagination
let page = await client.stations.list();
console.log(page.items);

if (page.hasMore && page.nextCursor) {
  const nextPage = await client.stations.list(page.nextCursor);
}

// Automatic page iteration
for await (const page of client.stations.paginatePages(20, 10)) {
  console.log(`Page with ${page.items.length} stations`);
}

// Automatic item iteration
for await (const station of client.stations.paginateItems(20, 10)) {
  console.log(station.code);
}

Retries and Timeouts

The SDK automatically retries failed requests for transient errors:

  • Retries on: 429 (rate limit), 503, 504, and 5xx errors
  • Respects Retry-After headers
  • Uses exponential backoff with jitter
  • Network errors are also retried
  • Only GET requests are retried by default

API

The SDK provides access to the following Socky Flights API endpoints:

Aircraft

  • aircraft.get(registration) - Get aircraft by registration
  • aircraft.list(cursor?, limit?) - List aircraft (paginated)
  • aircraft.position(registration) - Get last known position
  • aircraft.flights(registration, cursor?, limit?) - Get flights for aircraft (paginated)

Flights

  • flights.get(ulid) - Get flight by ID
  • flights.track(ulid) - Get flight track data

Locations

  • locations.get(lat, lng) - Get location information

Positions

  • positions.latest(tails) - Get latest positions for aircraft (accepts string or array)

Routes

  • routes.get(from, to) - Get route information between two stations

Stations

  • stations.get(code) - Get station by code
  • stations.list(cursor?, limit?) - List all stations (paginated)
  • stations.search(query) - Search stations by name or code
  • stations.proximity({ latitude, longitude, distance?, unit? }) - Find stations near coordinates
  • stations.near(code, { distance?, unit? }) - Find stations near another station
  • stations.paginatePages(limit?, pageLimit?) - Iterate over pages
  • stations.paginateItems(limit?, pageLimit?) - Iterate over individual items

Node support

Node >= 18.

License

Apache-2.0

版本与发布记录

@bilte-co/socky-js 共发布 10 个版本,首次发布于 2025/10/28;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.6.3latest2026/06/035 个月前
0.6.22026/05/215 个月前
0.6.02026/05/215 个月前
0.5.32025/11/051 年前
0.5.22025/11/051 年前
0.5.12025/11/051 年前

关于 @bilte-co/socky-js 的常见问题

@bilte-co/socky-js 是什么?

JavaScript SDK for the Socky Flights API

如何安装 @bilte-co/socky-js?

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

@bilte-co/socky-js 支持 TypeScript 吗?

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

@bilte-co/socky-js 支持 ESM 还是 CommonJS?

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

@bilte-co/socky-js 需要什么版本的 Node.js?

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

@bilte-co/socky-js 可以商用吗?

@bilte-co/socky-js 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@bilte-co/socky-js 的下载量有多少?

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

@bilte-co/socky-js 还在维护吗?

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