UNPKG

@remnawave/xtls-sdk

Version:

A Typescript SDK for XRAY (XTLS) Core GRPC Api

146 lines 7.67 kB
import { Channel } from 'nice-grpc'; import { IAddHttpUser, IAddHysteriaUser, IAddShadowsocks2022User, IAddShadowsocksUser, IAddSocksUser, IAddTrojanUser, IAddVlessUser } from './interfaces'; import { HandlerServiceClient } from '../xray-protos/app/proxyman/command/command'; import { AddUserResponseModel, GetInboundUsersResponseModel, RemoveUserResponseModel } from './models'; import { ISdkResponse } from '../common/types/sdk-response'; /** * Service for managing Xray inbound handlers and their users */ export declare class HandlerService { private readonly channel; private readonly client; constructor(channel: Channel); /** * Retrieves all users from a specified inbound handler. * This method fetches user information including their credentials and metadata from the Xray server. * * @param {string} tag - The tag identifying the inbound handler to query * @returns {Promise<ISdkResponse<GetInboundUsersResponseModel>>} A promise that resolves to: * - On success: An object with `isOk: true` and `data` containing an array of decoded user information * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS * * @example * ```typescript * const handler = new HandlerService(channel); * const response = await handler.getInboundUsers('Personal'); * * if (response.isOk) { * console.log(response.data.users); // Array of DecodedUser objects * } else { * console.error(response.message); // Error message * } * ``` */ getInboundUsers(tag: string): Promise<ISdkResponse<GetInboundUsersResponseModel>>; /** * Adds a new Trojan user to a specified inbound handler. * * @param {IAddTrojanUser} data - The user data containing tag, username, password and level * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to: * - On success: An object with `isOk: true` and `data.success` indicating if user was added * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS */ addTrojanUser(data: IAddTrojanUser): Promise<ISdkResponse<AddUserResponseModel>>; /** * Adds a new VLESS user to a specified inbound handler. * * @param {IAddVlessUser} data - The user data containing tag, username, UUID, flow and level * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to: * - On success: An object with `isOk: true` and `data.success` indicating if user was added * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS */ addVlessUser(data: IAddVlessUser): Promise<ISdkResponse<AddUserResponseModel>>; /** * Adds a new Shadowsocks user to a specified inbound handler. * * @param {IAddShadowsocksUser} data - The user data containing tag, username, password, cipher type, IV check and level * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to: * - On success: An object with `isOk: true` and `data.success` indicating if user was added * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS */ addShadowsocksUser(data: IAddShadowsocksUser): Promise<ISdkResponse<AddUserResponseModel>>; /** * Adds a new Shadowsocks 2022 user to a specified inbound handler. * * @param {IAddShadowsocks2022User} data - The user data containing tag, username, key and level * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to: * - On success: An object with `isOk: true` and `data.success` indicating if user was added * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS */ addShadowsocks2022User(data: IAddShadowsocks2022User): Promise<ISdkResponse<AddUserResponseModel>>; /** * Adds a new SOCKS user to a specified inbound handler. * * @param {IAddSocksUser} data - The user data containing tag, username, SOCKS username, SOCKS password and level * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to: * - On success: An object with `isOk: true` and `data.success` indicating if user was added * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS */ addSocksUser(data: IAddSocksUser): Promise<ISdkResponse<AddUserResponseModel>>; /** * Adds a new HTTP user to a specified inbound handler. * * @param {IAddHttpUser} data - The user data containing tag, username, HTTP username, HTTP password and level * @returns {Promise<ISdkResponse<AddUserResponseModel>>} A promise that resolves to: * - On success: An object with `isOk: true` and `data.success` indicating if user was added * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS */ addHttpUser(data: IAddHttpUser): Promise<ISdkResponse<AddUserResponseModel>>; /** * Adds a new Hysteria user to a specified inbound handler. * * @remarks * This method adds a user for the Hysteria protocol to an Xray server inbound handler. * * @param data - The user data for the new Hysteria user. * @param data.tag - The tag identifying the inbound handler. * @param data.username - The email/username for the user. * @param data.level - The user privilege level. * @param data.uuid - The authentication string for Hysteria (typically a password). * * @returns A promise that resolves to an {@link ISdkResponse} containing {@link AddUserResponseModel}. * * @example * ```typescript * const handler = new HandlerService(channel); * const result = await handler.addHysteriaUser({ * tag: 'hysteria-inbound', * username: 'example@example.com', * level: 0, * uuid: 'random-password', * }); * if (result.isOk && result.data.success) { * // User added successfully * } * ``` * * @throws An error with details from {@link HANDLER_ERRORS.ADD_USER_ERROR} if the operation fails. * Returns `isOk: true` and `success: false` if the user already exists. */ addHysteriaUser(data: IAddHysteriaUser): Promise<ISdkResponse<AddUserResponseModel>>; /** * Removes a user from a specified inbound handler. * * @param {string} tag - The tag identifying the inbound handler * @param {string} username - The username/email of the user to remove * @returns {Promise<ISdkResponse<RemoveUserResponseModel>>} A promise that resolves to: * - On success: An object with `isOk: true` and `data.success` indicating if user was removed * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS */ removeUser(tag: string, username: string): Promise<ISdkResponse<RemoveUserResponseModel>>; /** * Gets the count of users in a specified inbound handler. * * @param {string} tag - The tag identifying the inbound handler * @returns {Promise<ISdkResponse<number>>} A promise that resolves to: * - On success: An object with `isOk: true` and `data` containing the user count * - On failure: An object with `isOk: false` and error details from HANDLER_ERRORS */ getInboundUsersCount(tag: string): Promise<ISdkResponse<number>>; /** * Gets the raw gRPC client for direct access to all handler service methods * @returns The underlying HandlerServiceClient instance */ get rawClient(): HandlerServiceClient; } //# sourceMappingURL=handler.service.d.ts.map