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 🙏

© 2024 – Pkg Stats / Ryan Hefner

3x-ui

v2.1.1

Published

This is an interface for 3x-ui panel. It will help developers to create, edit and delete inbounds and clients in a simple way.

Downloads

395

Readme

3x-ui Node.js SDK

The 3x-ui is a JavaScript library designed to facilitate communication with the 3x-ui panel, which runs Xray Core for proxy services. This SDK empowers JavaScript developers to create bots and websites for both commercial and non-commercial uses, providing simplicity, abstraction around the API, caching for improved performance, and mutex for asynchronous safety.

This package is developed based on MHSanaei Postman Collection and you can check it out for more information.

Features

  • Simplicity: Designed with simplicity in mind to streamline the process of interacting with the 3x-ui panel.
  • Abstraction: Provides an abstraction layer around the 3x-ui API to simplify finding clients by email, uuid (vmess, vless) or password (trojan).
  • Proxy: Utilizes an underlying proxy agent for communication with the panel if needed.
  • Caching: Caches responses for improved performance.
  • Mutex: Provides a mutex, a lock mechanism, to ensure asynchronous safety and prevent race conditions.
  • Debug Mode: Enables debug mode for detailed logging.
  • TTL: Allows you to set the cache time in seconds.

Installation

To install the 3x-ui SDK, use npm:

npm install 3x-ui

Usage

First, import the SDK:

import { XuiApi } from "3x-ui";

Initialize the SDK with the URL of your 3x-ui panel:

const api = new XuiApi("http://username:password@localhost:2053");
api.debug = true; // Enables debug mode - defualt is false
api.stdTTL = 60; // Cache time in seconds - default is 10s

Then, you can utilize the SDK functions:

const inbounds = await api.getInbounds();
const clientStat = await api.getClient("email or clientId");
const clientOptions = await api.getClientOptions("email or clientId");
const onlines = await api.getOnlineClients();

Proxy

The SDK uses an underlying proxy agent to connect to the panel. You can specify the proxy settings using environment variables such as HTTP_PROXY and HTTPS_PROXY. Refer to the proxy-agent documentation for more information.

HTTP_PROXY="http://proxy-server-over-tcp.com:3128"
HTTPS_PROXY="https://proxy-server-over-tls.com:3129"

API

Inbounds

  • getInbounds(): Returns an array of all inbounds.
  • getInbound(id: number): Returns the inbound with the specified ID.
  • addInbound(options: InboundOptions): Adds a new inbound with the provided options.
  • updateInbound(id: number, options: Partial<InboundOptions>): Updates the inbound with the specified ID using the provided options.
  • resetInboundsStat(): Resets statistics for all inbounds.
  • resetInboundStat(id: number): Resets statistics for the inbound with the specified ID.
  • deleteInbound(id: number): Deletes the inbound with the specified ID.

Clients

  • getClient(clientId: string): Returns a client with the given email or clientId.
  • getClientIps(clientId: string): Returns all client's IPs with the given email or clientId.
  • getClientOptions(clientId: string): Returns all client's options with the given email or clientId.
  • addClient(inboundId: number, options: ClientOptions): Adds a new client with the given options.
  • updateClient(clientId: string, options: Partial<ClientOptions>): Updates a client with the given email or clientId.
  • resetClientIps(clientId: string): Resets all client's IPs with the given email or clientId.
  • resetClientStat(clientId: string): Resets a client's stat with the given email or clientId.
  • deleteClient(clientId: string): Deletes a client with the given email or clientId.
  • deleteDepletedClients(): Deletes all clients that have depleted their traffic.
  • deleteInboundDepletedClients(inboundId: number): Deletes all clients of an inbound that have depleted their traffic.
  • getOnlineClients(): Returns all online clients.

Other Functions

  • sendBackup(): send backup file via Telegram bot.

Example

For more examples, check out the test directory on our GitHub repository.