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

@visiblebase/plugin-balance

v0.1.3

Published

VisibleBase balance plugin for global user balance, ledger, and topup orders.

Readme

@visiblebase/plugin-balance

VisibleBase 官方全局余额插件。

这个插件只负责四件事:

  • 用户全局余额
  • 余额流水
  • 充值单
  • redeem_code

计费策略不写死在插件里。推荐在业务 hook 中直接调用插件的 read() / require() / sub() / add()

如果你需要一次性礼品码充值,可以让 admin 创建 redeem_code,然后由用户直接兑换入账。

安装

pnpm add @visiblebase/plugin-balance

使用

import { Base, AIService } from "@visiblebase/core";
import { balancePlugin } from "@visiblebase/plugin-balance";

const balance = balancePlugin({
  init: 100,
  unit: "credits",
});

base.use(balance);

const ai = new AIService();

ai.hook.before(async (ctx) => {
  if (!ctx.user || ctx.action?.id !== "chat/completions") return;
  await balance.require(ctx.user.user_id, 10);
  ctx.locals.balance_amount = 10;
});

ai.hook.after(async (ctx) => {
  if (!ctx.user || ctx.action?.id !== "chat/completions") return;
  const amount = Number(ctx.locals.balance_amount ?? 0);
  if (amount <= 0) return;

  await balance.sub(ctx.user.user_id, amount, {
    note: "agent chat",
    meta: {
      product_id: ctx.product?.product_id,
      model_id: ctx.variant?.id,
    },
  });
});

路由

  • GET /v1/balance/me
  • GET /v1/balance/history/me
  • GET /v1/balance/topups/me
  • POST /v1/balance/topups/create
  • POST /v1/balance/redeem-codes/redeem
  • GET /v1/balance/users
  • GET /v1/balance/history
  • GET /v1/balance/topups
  • GET /v1/balance/redeem-codes
  • POST /v1/balance/add
  • POST /v1/balance/sub
  • POST /v1/balance/topups/finish
  • POST /v1/balance/topups/cancel
  • POST /v1/balance/redeem-codes/create
  • POST /v1/balance/redeem-codes/disable