UNPKG

@remnawave/xtls-sdk

Version:

A Typescript SDK for XRAY (XTLS) Core GRPC Api

57 lines (56 loc) 1.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RouterService = void 0; const nice_grpc_1 = require("nice-grpc"); const command_1 = require("../xray-protos/app/router/command/command"); const router_errors_1 = require("../common/errors/router/router.errors"); const models_1 = require("./models"); /** * Service for managing routing rules in XRAY/XTLS * RoutingService is required (enable on XRay Config) to add/remove routing rules. */ class RouterService { /** * Creates an instance of RouterService * @param channel - The gRPC channel to use for communication */ constructor(channel) { this.channel = channel; this.client = (0, nice_grpc_1.createClient)(command_1.RoutingServiceDefinition, channel); } /** * Removes a routing rule by its tag * @param dto - Data transfer object containing rule tag * @param dto.ruleTag - Tag of the rule to remove * @returns Promise resolving to response indicating success or failure */ async removeRuleByRuleTag(dto) { try { await this.client.removeRule({ ruleTag: dto.ruleTag, }); return { isOk: true, data: new models_1.RemoveRuleByRuleTagResponseModel(true), }; } catch (error) { let message = ''; if (error instanceof Error) { message = error.message; } return { isOk: false, ...router_errors_1.ROUTER_ERRORS.REMOVE_RULE_BY_RULE_TAG_ERROR(message), }; } } /** * Gets the raw gRPC client for direct access to all routing service methods * @returns The underlying RoutingServiceClient instance */ get rawClient() { return this.client; } } exports.RouterService = RouterService;