CUSS2.ts

TypeScript SDK for Common Use Self-Service v2 Platform

View Examples API Documentation
🚀

TypeScript First

Built from the ground up with TypeScript, providing complete type safety and excellent IDE support for all CUSS2 operations.

🔌

30+ Components

Full support for all CUSS2 peripheral devices including printers, scanners, card readers, scales, and baggage handling systems.

🔄

Auto Reconnection

Built-in WebSocket management with automatic reconnection, OAuth token refresh, and exponential backoff strategies.

📡

Event-Driven

Reactive architecture with typed events for state changes, component updates, and real-time device data streams.

🎯

State Management

Automatic state synchronization based on required component availability with built-in state transition validation.

🦕

Deno Native

Designed for the modern Deno runtime with ESM modules, while providing browser bundles for web applications.

Quick Start

// Import from CDN
import { Cuss2 } from "https://esm.sh/jsr/@cuss/cuss2-ts@latest";

// Connect to CUSS2 platform
const cuss2 = Cuss2.connect(
  "your-client-id",
  "your-client-secret",
  "wss://platform.example.com" // Optional custom URL
);

// Wait for connection
await cuss2.connected;
console.log("Connected! State:", cuss2.state);

// Work with components
if (cuss2.barcodeReader) {
  await cuss2.barcodeReader.enable();
  cuss2.barcodeReader.on("data", (data) => {
    console.log("Barcodes:", data); // data is string[]
  });
}

Note: Use this code inside a <script type="module"> tag in your HTML file.

// Import from JSR
import { Cuss2 } from "jsr:@cuss/cuss2-ts@latest";

// Connect with full configuration
const cuss2 = Cuss2.connect(
  "client-id",
  "client-secret",
  "wss://cuss-platform.example.com",
  "device-id",
  "https://oauth.example.com/token"
);

// Wait for connection
await cuss2.connected;

// Request state transitions
await cuss2.requestInitializeState();
await cuss2.requestAvailableState();

// Enable components
if (cuss2.boardingPassPrinter) {
  await cuss2.boardingPassPrinter.enable();
  await cuss2.boardingPassPrinter.send(printData);
}
// Install from JSR for Node.js
// npx jsr add @cuss/cuss2-ts

import { Cuss2 } from "@cuss/cuss2-ts";

const cuss2 = Cuss2.connect(
  process.env.CLIENT_ID,
  process.env.CLIENT_SECRET
);

cuss2.connected.then(async () => {
  console.log("Environment:", cuss2.environment);
  console.log("Components:", Object.keys(cuss2.components));

  // Listen for state changes
  cuss2.on("stateChange", (change) => {
    console.log(`State: ${change.previous} → ${change.current}`);
  });
});

Application State Flow

CUSS2 applications transition through well-defined states following strict rules

STOPPED
INITIALIZE
UNAVAILABLE
AVAILABLE
ACTIVE

Supported Components

🏷️
BagTagPrinter
🎫
BoardingPassPrinter
📊
BarcodeReader
💳
CardReader
📄
DocumentReader
📡
RFID
⚖️
Scale
🎤
Announcement
💡
Illumination
📷
Camera
🔢
Keypad
👆
Biometric

API Reference

Cuss2 Class

Main SDK class for platform connection, state management, and component orchestration.

Connection

WebSocket and OAuth management with automatic reconnection and token refresh.

Components

Base component class and specialized implementations for all CUSS2 peripherals.