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

@zhin.js/client

v2.0.5

Published

Zhin Remote Console client SDK (entries loader, app registry, REST/SSE) — UI lives in zhin-console repo

Readme

@zhin.js/client

Remote Console 浏览器 SDK(entries 加载、路由/工具注册、带 Token 的 REST)。不含 UI — 壳层在独立仓库 zhin-console

路径约定:本包位于 packages/console/client/(npm @zhin.js/client)。源码在 client/,构建产物在 dist/

安装

pnpm add @zhin.js/client

Peer:react >= 18createPluginRegisterHostApi 需要 React 引用)。

概览

| 导出 | 用途 | |------|------| | loadConsoleEntries | 拉 GET /entries、动态 import 各 entry、调用 register(hostApi) | | createPluginRegisterHostApi | 由壳层的 React / addRoute / addTool 构造 PluginRegisterHostApi | | apiFetch | 相对 Host API Base 的 fetch,自动附加 Authorization: Bearer | | getApiBase / getToken | 读取登录页写入 localStorage 的 API Base 与 Token | | app | 路由与工具注册单例(addRouteaddTool 等) | | configureConsole / getRuntimeEnv | 运行时环境(development / production) | | createRegistryStore / useRegistry | 可选 registry store |

类型与 Entry 契约来自 @zhin.js/contract

启动:加载插件 Console Entry

Remote Console 壳层在登录后调用:

import React from "react";
import {
  app,
  createPluginRegisterHostApi,
  loadConsoleEntries,
} from "@zhin.js/client";

const hostApi = createPluginRegisterHostApi({
  React,
  addRoute: app.addRoute.bind(app),
  addTool: app.addTool.bind(app),
});

await loadConsoleEntries({
  hostApi,
  // Remote Console:Host 监听地址,用于解析 /@dev、/@assets 模块 URL
  assetOrigin: "http://127.0.0.1:8086",
  fetchInit: () => ({
    headers: { Authorization: `Bearer ${localStorage.getItem("zhin_api_token")}` },
  }),
  onFetchError: (status) => console.error("entries fetch failed", status),
  onEmpty: () => console.warn("no console entries"),
});

loadConsoleEntries 内部:fetchConsoleEntriesregisterConsolePluginsFromEntries → 各 entry 模块的 registerdefault.register

插件 client/ 入口示例:

import type { PluginRegisterHostApi } from "@zhin.js/contract";

export async function register(hostApi: PluginRegisterHostApi) {
  hostApi.addRoute({
    path: "/my-plugin",
    name: "My Plugin",
    element: hostApi.React.createElement(MyPage),
    icon: "Puzzle",
  });
}

Host API 请求

登录页将 API Base 与 Token 存入 localStorage(键 zhin_api_basezhin_api_token)。业务请求使用 apiFetch

import { apiFetch } from "@zhin.js/client";

const res = await apiFetch("/api/console/request", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ method: "system.status", params: {} }),
});

401 时清除 Token 并派发 zhin:auth-required

辅助:resolveApiUrlresolveWebSocketUrl(SSE /api/events 等)。

createPluginRegisterHostApi

将壳层已有的 React 与路由/工具注册函数适配为契约中的 PluginRegisterHostApi(含 addPage 别名 → addRoute):

import { createPluginRegisterHostApi } from "@zhin.js/client";

const hostApi = createPluginRegisterHostApi({ React, addRoute, addTool });

低级 API

  • fetchConsoleEntries(options?) — 仅拉 JSON,不 import
  • registerConsolePluginsFromEntries(entries, hostApi, ...) — 已知 entries 列表时注册
  • getRegisterFn(mod) — 从动态模块解析 register 导出

构建

pnpm --filter @zhin.js/client build

相关文档