npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@panoptic-it-solutions/unifi-api-client

v1.0.15

Published

A Node.js client library for the UniFi Controller API

Readme

@panoptic-it-solutions/unifi-api-client

A modern, fully-typed Node.js client library for the UniFi Controller API.
Supports authentication (including 2FA), robust error handling, modular endpoints, and TypeScript-first development.


Installation

pnpm add @panoptic-it-solutions/unifi-api-client
# or
npm install @panoptic-it-solutions/unifi-api-client

Basic Usage

import { UniFiClient } from '@panoptic-it-solutions/unifi-api-client';

const client = new UniFiClient('https://unifi.example.com:8443', {
  username: 'admin',
  password: 'password',
  site: 'default', // optional, defaults to 'default'
  strictSSL: true, // optional, defaults to true
  timeout: 10000,  // optional, ms
  // logger: customLoggerInstance, // optional
});

await client.login(); // uses stored credentials

// Example: List all devices
const devices = await client.devices.listDevices();
console.log(devices);

await client.logout();

Authentication

  • Username/password authentication (2FA supported if enabled).
  • Session persistence with automatic re-authentication.
  • Emits authentication events for custom handling.
await client.login(); // uses credentials from constructor
// or
await client.login('admin', 'password'); // override credentials

Configuration Options

| Option | Type | Default | Description | |-------------|----------|-----------|---------------------------------------------| | username | string | - | UniFi username | | password | string | - | UniFi password | | site | string | 'default' | UniFi site name | | strictSSL | boolean | true | Enforce SSL certificate validation | | timeout | number | 10000 | Request timeout in milliseconds | | logger | Logger or LoggerOptions | - | Custom logger instance or options |


API Overview

  • Devices: List, adopt, restart, block/unblock, update firmware, etc.
  • Clients: List, block/unblock, authorize guests, get stats.
  • Sites: List, switch, get site info.
  • Networks: List, create, update, delete VLANs and networks.
  • WLANs: List, create, update, delete wireless networks.
  • Statistics: Retrieve usage, client, device, and site stats.
  • System: Get status, settings, logs, alerts, backups, firmware, reboot, factory reset.

Example: Device Management

// List all devices
const devices = await client.devices.listDevices();

// Get a device by MAC
const device = await client.devices.getDevice('aa:bb:cc:dd:ee:ff');

// Adopt a device
await client.devices.adoptDevice('aa:bb:cc:dd:ee:ff');

// Restart a device
await client.devices.restartDevice('aa:bb:cc:dd:ee:ff');

// Set device name
await client.devices.setDeviceName('aa:bb:cc:dd:ee:ff', 'My AP');

Example: Client Management

// List all active clients
const activeClients = await client.getActiveClients();

// Block a client
await client.blockClient('aa:bb:cc:dd:ee:ff');

// Authorize a guest client for 120 minutes
await client.authorizeGuest('aa:bb:cc:dd:ee:ff', 120);

Example: Network and Firewall

// List all networks
const networks = await client.getNetworks();

// Create a new network
const newNetwork = await client.createNetwork({
  name: 'IoT',
  vlan: 20,
  // ...other network options
});

// List all firewall rules
const rules = await client.getFirewallRules();

Error Handling

All methods throw custom error classes (UniFiApiError, UniFiAuthError, etc.).

try {
  await client.login();
  const clients = await client.getClients();
} catch (err) {
  if (err instanceof UniFiAuthError) {
    // Handle authentication error
  } else {
    // Handle other errors
  }
}

Logging

  • Built-in logger with log levels (info, warn, error, debug).
  • Pass a custom logger or use the default.
  • Logs authentication, requests, errors, and more.

TypeScript Support

  • Fully typed API and data models.
  • All endpoint methods and options are type-safe.

API Reference Documentation

  • Generated with TypeDoc.
  • After cloning the repo, run:
    pnpm run docs
    Then open docs/index.html in your browser.

Contributing

  1. Fork the repo and create a feature branch.
  2. Add/modify code and tests.
  3. Run pnpm test to verify.
  4. Submit a pull request with a clear description.

License

MIT License. See LICENSE for details.


Support

For issues, please open a ticket on GitHub Issues.