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

@earthchen/xianyu-sdk

v0.4.0

Published

TypeScript SDK for Xianyu (Goofish) APIs — HTTP, WebSocket messaging, and QR code login

Readme

@earthchen/xianyu-sdk

TypeScript SDK for Xianyu (Goofish/闲鱼) — wraps the platform's MTOP HTTP API, WebSocket real-time messaging, and QR-code login. Targets Node.js servers.

Features

  • HTTP / MTOP — 26 typed methods covering auth, item publishing/lifecycle, orders, shipping, ratings, blacklist, account notifications, and user lookups.
  • WebSocket real-time — typed dispatch (onMessage / onChat / onCard / onCardUpdate / onSystemTip) with itemId, decoded contentType ('text' | 'image'), and imageUrls populated.
  • Card messages[卡片消息] marker auto-routes to onCard with cardTitle extracted from dxCard.item.main.exContent.title.
  • QR loginqrcodeLogin() runs the full flow via HTTP only (no browser).
  • Cookie store — pluggable CookieStore interface; MemoryCookieStore and FileCookieStore provided.
  • Lifecycle hooksonClose / onError exposed; the SDK does not auto-reconnect (callers own backoff via calculateRetryDelay).
  • Dual ESM + CJS build via tsup.

Installation

pnpm add @earthchen/xianyu-sdk

Requires Node.js >= 18.

Quick Start

import { XianyuClient, FileCookieStore, makeText } from '@earthchen/xianyu-sdk';

const store = new FileCookieStore('~/.xianyu/cookies.json');
const cookies = await store.load();

const client = new XianyuClient({ cookies });

client.onMessage(async (msg, ws) => {
  console.log(`${msg.sendUserName}: ${msg.message}`);
  await client.live.sendMessage(
    msg.conversationId,
    msg.sendUserId,
    makeText('收到!'),
  );
});

await client.connect();

Programmatic Login

import { XianyuClient } from '@earthchen/xianyu-sdk';

const client = await XianyuClient.qrcodeLogin({
  onQrUrl(url) {
    // Render the QR in your UI
    console.log('QR:', url);
  },
  onStatusChange(status, desc, remaining) {
    console.log(`[${status}] ${desc}`);
  },
});

API Overview

XianyuClient

| Symbol | Description | |---|---| | new XianyuClient({ cookies, deviceId?, cookieStore?, logger? }) | Construct from cookies | | XianyuClient.qrcodeLogin(options?) | Static — QR login returns instance | | XianyuClient.buildInitialCookies() | Static — bootstrap pre-login cookies | | client.api | XianyuApi instance (26 MTOP methods) | | client.live | XianyuLive instance | | client.onMessage(handler) | Unified message callback | | client.onChat / onCard / onCardUpdate / onSystemTip | Typed message callbacks | | client.onClose(cb) / client.onError(cb) | WS lifecycle hooks | | client.connect() / client.disconnect() | WS connection | | client.saveCookies() | Persist cookies via CookieStore |

XianyuApi — selected methods

| Method | MTOP endpoint | |---|---| | getToken() / refreshToken() | Auth | | getItemInfo(itemId) | mtop.taobao.idle.pc.detail | | publish(imagesPaths, desc, price, delivery) | mtop.idle.pc.idleitem.publish | | deleteItem(itemId) / batchOfflineItems(ids) / polishItem(itemId) | Item lifecycle | | confirmShipping({ orderId, ... }) / freeshipping({...}) | Shipping | | getOrderDetail(orderId) / closeOrderBySeller(orderId) | Orders | | listSoldOrders({...}) / listRefunds({...}) / listPendingRates({...}) | Reporting | | addToBlacklist(cid) / queryBlacklist(cid) / removeFromBlacklist(cid) | Blacklist | | getUserByCid(cid, { isOwner? }) | User lookup | | closeAccountNotice() | Notifications |

All MTOP methods route through the internal mtopPost() helper. A typed variant mtopPostTyped<T>() returns MtopResponse<T> for callers that want a typed data shape.

XianyuLive — message types

Inbound messages carry a messageType discriminator: 'chat' | 'card' | 'cardUpdate' | 'systemTip'. Chat messages expose itemId, contentType ('text' | 'image'), and imageUrls. Card messages carry cardTitle. System tips are filtered out of the chat flow but still fire onSystemTip.

Helpers

| Export | Purpose | |---|---| | parseRecord(record) | Parse a decrypted sync record into a ReceivedMessage | | parseCardMessage(record) / parseCardUpdateMessage(record) | Same for card shapes | | isChatMessage / isCardMessage / isCardUpdateMessage / isSystemTipMessage | Classifiers | | extractMessageId(record) | Dedup key | | extractCardTitle(record) | Card title extraction | | decodeSyncData(raw) | Decode sync data string (base64+JSON or decrypt+JSON) | | extractAccountUserIdFromCookie(cookies) | Pull unb from cookies | | validateCookies(cookies) | Pre-flight cookie check | | parseCookieString / formatCookieString | Cookie codec | | canonicalGoofishItemUrl(itemId) | Build item URL | | calculateRetryDelay(attempt, kind?) | Backoff for reconnection |

CLI

npx xianyu-login
npx xianyu-login --output ./cookies.json

The QR-login CLI writes cookies to ~/.xianyu/cookies.json by default.

文档

| 文档 | 内容 | |---|---| | docs/API.md | 全部 26 个 MTOP HTTP 方法的签名、endpoint、payload 备注 | | docs/MESSAGING.md | WebSocket 消息类型联合、分类器、解析器、[卡片消息] 重定向 | | docs/LIFECYCLE.md | 连接生命周期、onClose / onError、重连退避、Cookie 持久化 | | AGENTS.md | 给 AI agent 看的项目约定、架构、文件变更指引(中文) |

License

MIT