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 🙏

© 2026 – Pkg Stats / Ryan Hefner

higress-console-api

v1.0.0

Published

Higress Console API client for managing consumers and route bindings

Readme

Higress Console API Client

一个用于管理Higress Console中消费者和路由绑定的Node.js客户端库。

功能特性

  • 智能消费者绑定:自动创建不存在的消费者并绑定到路由
  • 自动重新登录:检测到会话过期时自动重新登录
  • ✅ 消费者管理(创建、删除、查询)
  • ✅ 路由管理(查询、更新认证配置)
  • ✅ 批量操作支持
  • ✅ TypeScript支持
  • ✅ 完整的错误处理
  • ✅ Cookie会话管理

安装

npm install higress-console-api

核心特性

🎯 智能消费者绑定

  • 如果消费者不存在,自动创建(token格式:{消费者名}_${20位随机字符串}
  • 如果消费者存在,返回其第一个token
  • 智能处理路由绑定逻辑

🔄 自动重新登录

  • 检测到401错误时自动重新登录
  • 无缝重试失败的API请求
  • 保持会话状态

快速开始

import { HigressConsoleAPI } from 'higress-console-api';

// 初始化客户端
const api = new HigressConsoleAPI({
  baseUrl: 'http://your-higress-console:8001',
  username: 'admin',
  password: 'your-password'
});

// 核心功能:绑定消费者到路由
const result = await api.bindConsumerToRoute('my-route', 'my-consumer');
console.log(result.message);

API 文档

初始化

const api = new HigressConsoleAPI({
  baseUrl: 'http://localhost:8001',  // Higress Console URL
  username: 'admin',                 // 登录用户名
  password: 'password',              // 登录密码
  timeout: 30000                     // 可选:请求超时时间(毫秒)
});

核心功能

bindConsumerToRoute(routeName, consumerName)

将指定的消费者绑定到路由。如果路由已经有消费者,则返回现有消费者信息。

const result = await api.bindConsumerToRoute('my-route', 'my-consumer');

if (result.success) {
  console.log('绑定成功:', result.message);
} else {
  console.log('绑定失败:', result.message);
  if (result.existingConsumers) {
    console.log('现有消费者:', result.existingConsumers);
  }
}

消费者管理

createConsumer(options)

创建新消费者:

await api.createConsumer({
  name: 'my-consumer',
  authType: 'key-auth',
  token: 'secret-token-123',
  tokenSource: 'HEADER',
  headerName: 'X-API-Key'
});

getConsumers()

获取所有消费者:

const consumers = await api.getConsumers();
console.log('消费者列表:', consumers);

deleteConsumer(name)

删除消费者:

await api.deleteConsumer('consumer-name');

batchCreateConsumers(configs)

批量创建消费者:

const results = await api.batchCreateConsumers([
  {
    name: 'consumer1',
    authType: 'key-auth',
    token: 'token1'
  },
  {
    name: 'consumer2',
    authType: 'key-auth',
    token: 'token2'
  }
]);

路由管理

getRoutes()

获取所有路由:

const routes = await api.getRoutes();

getRouteByName(routeName)

根据名称获取路由:

const route = await api.getRouteByName('my-route');

updateRouteConsumers(options)

更新路由的消费者绑定:

await api.updateRouteConsumers({
  routeName: 'my-route',
  consumerNames: ['consumer1', 'consumer2'],
  enableAuth: true
});

辅助方法

listConsumers()

打印格式化的消费者列表:

await api.listConsumers();

listRoutes()

打印格式化的路由列表:

await api.listRoutes();

在Next.js中使用

// pages/api/higress.ts
import { HigressConsoleAPI } from 'higress-console-api';

export default async function handler(req, res) {
  const api = new HigressConsoleAPI({
    baseUrl: process.env.HIGRESS_CONSOLE_URL,
    username: process.env.HIGRESS_USERNAME,
    password: process.env.HIGRESS_PASSWORD
  });

  try {
    const result = await api.bindConsumerToRoute(
      req.body.routeName,
      req.body.consumerName
    );
    
    res.status(200).json(result);
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
}

类型定义

interface HigressConfig {
  baseUrl: string;
  username: string;
  password: string;
  timeout?: number;
}

interface CreateConsumerOptions {
  name: string;
  authType?: 'key-auth' | 'oauth2' | 'jwt';
  token?: string;
  tokenSource?: 'BEARER' | 'HEADER' | 'QUERY';
  headerName?: string;
}

interface UpdateRouteConsumersOptions {
  routeName: string;
  consumerNames: string[];
  enableAuth?: boolean;
}

开发

# 安装依赖
npm install

# 构建
npm run build

# 运行测试
npm test

# 运行示例
npm run example

许可证

MIT