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

@xesam/cloud-vendor-feie

v0.1.0

Published

飞鹅云打印 JavaScript SDK:小票、标签、随单图片与设备管理

Readme

@xesam/cloud-vendor-feie · 飞鹅云打印 SDK

飞鹅云打印 JavaScript SDK:小票、标签、随单图片与设备管理。通过 @xesam/cloud-core 提供统一的设备、订单和错误模型;请求与签名按运行环境注入,无需构建。

本文说明 0.1.0 的 API。厂商适配器不能独立使用,须同时安装同版本的 core。功能支持以实际机型与固件为准。

快速开始:Node.js 小票打印

使用 Node.js 18.17 或更高版本运行以下示例。示例选择 axios 作为请求客户端,使用 Node.js 内置 crypto 签名;axios 不是 SDK 的运行时依赖。

先在新建的 Node.js 项目中安装 core、厂商包和示例所需的 axios。core 与厂商包必须使用同一版本:

pnpm add @xesam/[email protected] @xesam/[email protected] axios

在飞鹅开放平台获取账号凭据,并将一台小票打印机绑定到该账号。账号凭据与打印机 SN/KEY 不是同一组信息:

| 环境变量 | 填写内容 | | --- | --- | | FEIE_ID | 开放平台 USER | | FEIE_SECRET | 开放平台 UKEY | | FEIE_DEVICE_SN | 已绑定到该账号的小票打印机 SN |

将下面代码保存为 print.js:

// 保存为 print.js;账号配置从环境变量读取,不要写入源码。
const {createHash} = require('node:crypto');
const axios = require('axios');
const CloudCore = require('@xesam/cloud-core');
const CloudApi = require('@xesam/cloud-vendor-feie');

const signer = {
    SHA1(data) {
        return createHash('sha1').update(data).digest('hex');
    },
    MD5(data) {
        return createHash('md5').update(data).digest('hex').toUpperCase();
    }
};
const requestClient = axios.create({timeout: 15000});

async function main() {
    const id = (process.env.FEIE_ID || '').trim();
    const secret = (process.env.FEIE_SECRET || '').trim();
    const sn = (process.env.FEIE_DEVICE_SN || '').trim();
    if (!id || !secret || !sn) {
        throw new Error('请配置 FEIE_ID、FEIE_SECRET、FEIE_DEVICE_SN');
    }
    const api = new CloudApi(
        new CloudCore.CloudAuth(id, secret),
        new CloudCore.CloudClient(signer, requestClient)
    );
    const result = await api.printMsgOrder(
        new CloudCore.Device({sn}),
        new CloudCore.Order({content: '测试小票<BR>', copies: 1})
    );
    console.log('已受理,订单 ID:' + result.id());
}

main().catch(error => {
    console.error(error.code || 'ERROR', error.message);
    if (error.code === CloudCore.CloudErrorCode.NETWORK) {
        console.error('请求可能已被受理,请先核对订单结果,不要直接重试。');
    }
    process.exitCode = 1;
});

在终端或部署环境中配置上表的三个环境变量,然后执行:

node print.js

该示例会提交一张小票订单。 成功时输出 已受理,订单 ID:...;这只代表平台受理,不等于已经出纸。请检查打印机实际输出,或调用 queryOrder(new CloudCore.Order({id: '返回的订单 ID'})) 查询状态。网络失败后不要直接重试,以免重复打印。

常用 API

| 方法 | 用途 | | --- | --- | | addDevice(devices) / deleteDevice(devices) | 批量添加/删除设备,返回 {success, fail} | | queryDevice(device) / updateDevice(device) | 查询设备状态/修改设备 | | printMsgOrder(device, order) | 提交小票订单 | | printLabelOrder(device, order) | 提交标签订单 | | queryOrder(order) | 查询订单打印状态 | | queryOrderCount(device, queryOption) | 查询指定日期的订单统计 | | clearOrders(device) | 清理设备打印队列,谨慎调用 |

以上方法返回 Promise。批量接口还需检查 fail,不能只判断 Promise 是否成功。参数、结果和错误说明见 core API 参考与错误处理。

厂商能力与限制

  • 支持小票、标签、日期统计与秒级绝对截止时间;不支持统一设备设置。
  • 标签订单支持 Order.image({data, filename}) 随单上传 PNG/JPEG(1–10240 字节),content 内须有一个 <IMG x="8" y="40"> 定位标签;supports('labelImage') 为 true。RequestClient 须原样发送 SDK 生成的 ArrayBuffer 与 Content-Type。
  • 小票只能用 <LOGO> 引用设备预置图片,不接受 Order.image。
  • 添加设备必须提供 key;批量增删返回 {success, fail},失败项的 .error() 为 CloudError。
  • expiresAt 透传为 expired,允许未来 24 小时内(含边界)的 Unix 秒数。
  • 修改设备须带 name;可带 cardno,空字符串转发不代表厂商保证清空。
  • 官方协议:飞鹅开放平台。

能力对照见 三厂商能力矩阵;标签与图片用法见 订单内图片。各厂商排版指令并不通用,切换厂商时需要调整 Order.content。

小程序与安全部署

可通过注入平台的请求 API 与签名实现适配微信小程序,见小程序接入与 Signer / RequestClient 约定。本包的 miniprogram 入口与 main 相同;使用微信开发者工具「构建 npm」生成运行产物。

不要将长期厂商密钥硬编码到源码、浏览器页面或公开分发的小程序中,也不要记录完整鉴权请求、密钥或含敏感配置的错误对象。生产系统优先由受控服务端保存密钥并调用 SDK,客户端请求自己的业务服务。小程序直接签名的例子仅用于受控接入调试,不应作为生产密钥分发方案。

文档与更新