xray-sdk — API
ISdkResponse
Section titled “ISdkResponse”src/common/types/sdk-response.ts
export interface ISdkResponse<T> { isOk: boolean; data?: T; message?: string;}TAccountTypesKey
Section titled “TAccountTypesKey”src/common/utils/decode-user/types/account-type-keys.type.ts
export type TAccountTypesKey = keyof typeof ACCOUNT_TYPES;AccountTypeMapping
Section titled “AccountTypeMapping”src/common/utils/decode-user/types/account-type-mapping.type.ts
export type AccountTypeMapping = ReturnType< (typeof ACCOUNT_TYPES)[TAccountTypesKey]['getCredentials']>;DecodedUser
Section titled “DecodedUser”src/common/utils/decode-user/types/decoded-user.type.ts
export interface DecodedUser { username: string; level: number; protocol: string; trojan?: Omit<TrojanAccount, '$type'>; vless?: Omit<VlessAccount, '$type'>; http?: Omit<HttpAccount, '$type'>; shadowsocks?: Omit<ShadowsocksAccount, '$type'>; shadowsocks2022?: Omit<Shadowsocks2022Account, '$type'>; socks?: Omit<SocksAccount, '$type'>;}IAddHttpUser
Section titled “IAddHttpUser”src/handler/interfaces/add-user/add-http-user.interface.ts
export interface IAddHttpUser { tag: string; username: string; level: number; http_username: string; http_password: string;}IAddShadowsocksUser
Section titled “IAddShadowsocksUser”src/handler/interfaces/add-user/add-shadowsocks-user.interface.ts
export interface IAddShadowsocksUser { tag: string; username: string; level: number; password: string; cipherType: CipherType; ivCheck: boolean;}IAddShadowsocks2022User
Section titled “IAddShadowsocks2022User”src/handler/interfaces/add-user/add-shadowsocks2022-user.interface.ts
export interface IAddShadowsocks2022User { username: string; level: number; key: string; tag: string;}IAddSocksUser
Section titled “IAddSocksUser”src/handler/interfaces/add-user/add-socks-user.interface.ts
export interface IAddSocksUser { username: string; level: number; socks_username: string; socks_password: string; tag: string;}IAddTrojanUser
Section titled “IAddTrojanUser”src/handler/interfaces/add-user/add-trojan-user.interface.ts
export interface IAddTrojanUser { username: string; level: number; password: string; tag: string;}IAddVlessUser
Section titled “IAddVlessUser”src/handler/interfaces/add-user/add-vless-user.interface.ts
export interface IAddVlessUser { username: string; level: number; uuid: string; flow: 'xtls-rprx-vision' | ''; tag: string;}AddUserResponseModel
Section titled “AddUserResponseModel”src/handler/models/add-user/add-user.response.model.ts
export class AddUserResponseModel { public isAdded: boolean;
constructor(isAdded: boolean) { this.isAdded = isAdded; }}GetInboundUsersResponseModel
Section titled “GetInboundUsersResponseModel”src/handler/models/get-inbound-users/get-inbound-users.response.model.ts
export class GetInboundUsersResponseModel { public users: DecodedUser[];
constructor(users: User[]) { this.users = users.map(decodeUser); }}RemoveUserResponseModel
Section titled “RemoveUserResponseModel”src/handler/models/remove-user/remove-user.response.model.ts
export class RemoveUserResponseModel { public readonly isDeleted: boolean;
constructor(isDeleted: boolean) { this.isDeleted = isDeleted; }}IAddSourceIpRule
Section titled “IAddSourceIpRule”src/router/interfaces/add-source-ip-rule.interface.ts
export interface IAddSourceIpRule { ruleTag: string; ip: string; outbound: string; append: boolean;}IRemoveRuleByRuleTag
Section titled “IRemoveRuleByRuleTag”src/router/interfaces/remove-rule-by-rule-tag.interface.ts
export interface IRemoveRuleByRuleTag { ruleTag: string;}AddSourceIpRuleResponseModel
Section titled “AddSourceIpRuleResponseModel”src/router/models/add-source-ip-rule/add-source-ip-rule.response.model.ts
export class AddSourceIpRuleResponseModel { public isAdded: boolean;
constructor(isAdded: boolean) { this.isAdded = isAdded; }}RemoveRuleByRuleTagResponseModel
Section titled “RemoveRuleByRuleTagResponseModel”src/router/models/remove-rule-by-rule-tag/remove-rule-by-rule-tag.response.model.ts
export class RemoveRuleByRuleTagResponseModel { public isRemoved: boolean;
constructor(isRemoved: boolean) { this.isRemoved = isRemoved; }}GetAllInboundsStatsResponseModel
Section titled “GetAllInboundsStatsResponseModel”src/stats/models/get-all-inbounds-stats/get-all-inbounds-stats.response.model.ts
export class GetAllInboundsStatsResponseModel { /** Array of inbound statistics containing inbound tag, uplink and downlink data */ public inbounds: IInboundStat[];
/** * Creates an instance of GetAllInboundsStatsResponseModel * @param data Raw stats response data from the query */ constructor(data: QueryStatsResponse) { this.inbounds = this.parseData(data); }
/** * Parses and formats the raw stats data into inbound-specific statistics * @param data Raw stats response data containing individual stat entries * @returns Array of formatted inbound statistics */ private parseData(data: QueryStatsResponse): IInboundStat[] { const formattedStats = data.stat.reduce((acc: IInboundStat[], curr: Stat) => { const nameParts = curr.name.split('>>>'); const tagValue = nameParts[1]; const type = nameParts[3]; const value = curr.value;
let inbound = acc.find((item) => item.inbound === tagValue);
if (!inbound) { inbound = { inbound: tagValue, uplink: 0, downlink: 0 }; acc.push(inbound); }
if (type === 'uplink') { inbound.uplink += value; } else if (type === 'downlink') { inbound.downlink += value; }
return acc; }, []);
return formattedStats; }}IInboundStat
Section titled “IInboundStat”src/stats/models/get-all-inbounds-stats/interfaces/inbound.interface.ts
export interface IInboundStat { inbound: string; uplink: number; downlink: number;}GetAllOutboundsStatsResponseModel
Section titled “GetAllOutboundsStatsResponseModel”src/stats/models/get-all-outbounds-stats/get-all-outbounds-stats.response.model.ts
export class GetAllOutboundsStatsResponseModel { /** Array of outbound statistics containing outbound tag, uplink and downlink data */ public outbounds: IOutboundStat[];
/** * Creates an instance of GetAllOutboundsStatsResponseModel * @param data Raw stats response data from the query */ constructor(data: QueryStatsResponse) { this.outbounds = this.parseData(data); }
/** * Parses and formats the raw stats data into outbound-specific statistics * @param data Raw stats response data containing individual stat entries * @returns Array of formatted outbound statistics */ private parseData(data: QueryStatsResponse): IOutboundStat[] { const formattedStats = data.stat.reduce((acc: IOutboundStat[], curr: Stat) => { const nameParts = curr.name.split('>>>'); const tagValue = nameParts[1]; const type = nameParts[3]; const value = curr.value;
let outbound = acc.find((item) => item.outbound === tagValue);
if (!outbound) { outbound = { outbound: tagValue, uplink: 0, downlink: 0 }; acc.push(outbound); }
if (type === 'uplink') { outbound.uplink += value; } else if (type === 'downlink') { outbound.downlink += value; }
return acc; }, []);
return formattedStats; }}IOutboundStat
Section titled “IOutboundStat”src/stats/models/get-all-outbounds-stats/interfaces/outbound.interface.ts
export interface IOutboundStat { outbound: string; uplink: number; downlink: number;}GetAllUsersStatsResponseModel
Section titled “GetAllUsersStatsResponseModel”src/stats/models/get-all-users-stats/get-all-users-stats.response.model.ts
export class GetAllUsersStatsResponseModel { /** Array of user statistics containing username, uplink and downlink data */ public users: IUserStat[];
/** * Creates an instance of GetAllUsersStatsResponseModel * @param data Raw stats response data from the query */ constructor(data: QueryStatsResponse) { this.users = this.parseData(data); }
/** * Parses and formats the raw stats data into user-specific statistics * @param data Raw stats response data containing individual stat entries * @returns Array of formatted user statistics */ private parseData(data: QueryStatsResponse): IUserStat[] { const formattedStats = data.stat.reduce((acc: IUserStat[], curr: Stat) => { const nameParts = curr.name.split('>>>'); const username = nameParts[1]; const type = nameParts[3]; const value = curr.value;
let user = acc.find((item) => item.username === username);
if (!user) { user = { username, uplink: 0, downlink: 0 }; acc.push(user); }
if (type === 'uplink') { user.uplink += value; } else if (type === 'downlink') { user.downlink += value; }
return acc; }, []);
return formattedStats; }}IUserStat
Section titled “IUserStat”src/stats/models/get-all-users-stats/interfaces/user.interface.ts
export interface IUserStat { username: string; uplink: number; downlink: number;}GetInboundStatsResponseModel
Section titled “GetInboundStatsResponseModel”src/stats/models/get-inbound-stats/get-inbound-stats.response.model.ts
export class GetInboundStatsResponseModel { /** * The inbound statistics data, or null if no data is available. * Contains traffic statistics (uplink/downlink) for a specific inbound connection. */ public inbound: IInboundStat | null;
/** * Creates a new GetInboundStatsResponseModel instance. * * @param data - The raw query stats response from the Xray server */ constructor(data: QueryStatsResponse) { const inbounds = this.parseData(data); this.inbound = inbounds[0] ?? null; }
/** * Parses the raw stats response data into formatted inbound statistics. * * @param data - The raw query stats response to parse * @returns An array of formatted inbound statistics containing traffic data * @private */ private parseData(data: QueryStatsResponse): IInboundStat[] { const formattedStats = data.stat.reduce((acc: IInboundStat[], curr: Stat) => { const nameParts = curr.name.split('>>>'); const inboundTag = nameParts[1]; const type = nameParts[3]; const value = curr.value;
let inbound = acc.find((item) => item.inbound === inboundTag);
if (!inbound) { inbound = { inbound: inboundTag, uplink: 0, downlink: 0 }; acc.push(inbound); }
if (type === 'uplink') { inbound.uplink += value; } else if (type === 'downlink') { inbound.downlink += value; }
return acc; }, []);
return formattedStats; }}IInboundStat
Section titled “IInboundStat”src/stats/models/get-inbound-stats/interfaces/inbound.interface.ts
export interface IInboundStat { inbound: string; uplink: number; downlink: number;}GetOutboundStatsResponseModel
Section titled “GetOutboundStatsResponseModel”src/stats/models/get-outbound-stats/get-outbound-stats.response.model.ts
export class GetOutboundStatsResponseModel { /** * The outbound statistics data, or null if no data is available. * Contains traffic statistics (uplink/downlink) for a specific outbound connection. */ public outbound: IOutboundStat | null;
/** * Creates a new GetOutboundStatsResponseModel instance. * * @param data - The raw query stats response from the Xray server */ constructor(data: QueryStatsResponse) { const outbounds = this.parseData(data); this.outbound = outbounds[0] ?? null; }
/** * Parses the raw stats response data into formatted outbound statistics. * * @param data - The raw query stats response to parse * @returns An array of formatted outbound statistics containing traffic data * @private */ private parseData(data: QueryStatsResponse): IOutboundStat[] { const formattedStats = data.stat.reduce((acc: IOutboundStat[], curr: Stat) => { const nameParts = curr.name.split('>>>'); const outboundTag = nameParts[1]; const type = nameParts[3]; const value = curr.value;
let outbound = acc.find((item) => item.outbound === outboundTag);
if (!outbound) { outbound = { outbound: outboundTag, uplink: 0, downlink: 0 }; acc.push(outbound); }
if (type === 'uplink') { outbound.uplink += value; } else if (type === 'downlink') { outbound.downlink += value; }
return acc; }, []);
return formattedStats; }}