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

quanma-order-sdk

v0.1.2

Published

TypeScript SDK for Quanma order APIs

Downloads

24

Readme

Quanma API SDK (TypeScript)

基于券码无忧接单 API 文档封装,包含以下能力:

  • 自动拼接公共请求头(channeliddevCodetxntimesigntoken
  • 自动签名:MD5(bodyjson + key + txntime)
  • 对接口返回统一处理:仅 rtnCode = 000000 视为成功
  • 已封装文档中的 10 个接口
  • 支持自动续 token(可选)

安装

npm install quanma-order-sdk

示例

  • 可运行示例见 examples 目录:basic.mjsauto-refresh.mjsorder-flow.mjsupload-voucher.mjs
  • 运行说明见 examples/README.md

快速开始

import { QuanmaClient } from "quanma-order-sdk";

const client = new QuanmaClient({
  devCode: "你的devCode",
  secretKey: "平台分配的私钥",
  channelId: "OP0002", // 默认就是 OP0002,可不填
  autoRefreshToken: true, // 可选:自动定时刷新 token
  refreshIntervalMs: 30 * 60 * 1000, // 可选:默认 30 分钟
  maxRetries: 2, // 可选:默认 2(总请求次数=1+重试次数)
  retryBaseDelayMs: 300, // 可选:默认 300ms
  retryMaxDelayMs: 3000, // 可选:默认 3000ms
  retryOnHttpStatus: [408, 429, 500, 502, 503, 504], // 可选
  retryOnRtnCodes: [], // 可选:需要按业务码重试时填写
});

async function main() {
  // 1) 获取 token(默认会自动写入 client 内部)
  const login = await client.getToken();
  console.log("token=", login.token);

  // 2) 查询账号信息
  const user = await client.getUserInfo();
  console.log(user);

  // 3) 产品分页
  const products = await client.getFullProducts({ pageNum: 1 });
  console.log(products);
}

main().catch(console.error);

自动续 token

  • autoRefreshToken: true 时,客户端会在初始化后立即尝试获取 token,并按 refreshIntervalMs 周期续期。
  • 你也可以手动控制:
client.startTokenAutoRefresh();
client.stopTokenAutoRefresh();

重试与退避

  • 默认对网络超时、网络错误和 408/429/5xx 做重试。
  • 退避策略为指数退避:retryBaseDelayMs * 2^attempt,上限 retryMaxDelayMs
  • 你可以通过 retryOnRtnCodes 指定业务错误码重试(例如某些可恢复状态)。

类型化返回

SDK 默认返回强类型(例如 AccountInfoProductInfoOrderInfo):

import { QuanmaClient, type ProductInfo } from "quanma-order-sdk";

const client = new QuanmaClient({
  devCode: "你的devCode",
  secretKey: "平台私钥",
});

const products = await client.getFullProducts({ pageNum: 1 });
const first: ProductInfo | undefined = products[0];
console.log(first?.couponName);

已封装接口

  • getToken() -> /api/user-server/user/dev/login
  • getUserInfo() -> /api/coupons-server/coupons/user/basic/userinfo
  • uploadFile(file) -> /api/user-server/user/common/file/upload
  • getFullProducts({ pageNum }) -> /api/coupons-server/coupons/vediocharge/info/get/fullproducts
  • getProductDetail({ id }) -> /api/coupons-server/coupons/vediocharge/info/get/productdetail
  • receiveOrder({ productId, callbackUrl, templateConfigMap }) -> /api/coupons-server/coupons/vedio/receive
  • reportOrder({ id, imgUrlArray }) -> /api/coupons-server/coupons/vedio/report
  • updateVoucher({ id, imgUrlArray }) -> /api/coupons-server/coupons/vedio/updimg
  • closeOrder({ id }) -> /api/coupons-server/coupons/vedio/close
  • getOrderDetail({ id }) -> /api/coupons-server/coupons/vedio/get/order/detail

注意

  • 签名计算使用 UTF-8 字符串。
  • 当 JSON body 为空时,签名按 {} 参与计算。
  • uploadFilemultipart/form-data,签名仍按 {} 计算。
  • 接口返回非 000000 时会抛出 QuanmaApiError
  • 运行环境需 Node.js 18+(依赖原生 fetchFormDataBlob)。