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

wz-coupe-sdk

v2.5.1

Published

Coupe 配置中心前端 SDK,支持配置拉取与实时同步

Readme

wz-coupe-sdk

Coupe 配置中心前端 SDK,通过 projectKey + appSecret 拉取配置数据。

安装

npm install wz-coupe-sdk
# 或
pnpm add wz-coupe-sdk
# 或
yarn add wz-coupe-sdk

快速开始

import { CoupeSDK } from 'wz-coupe-sdk';

const sdk = new CoupeSDK({
  projectKey: 'daojuji',
  appSecret: 'd41afa99cfd92879a4924da1576827a7',
  env: 'stg',
  configKey: 'admin', // 可选,item_key(用户自定义),多个英文逗号分隔,不传则返回该环境下所有配置
});

// 拉取配置数据,返回 { [item_key]: json内容 }
const data = await sdk.fetch();
console.log(data);

参数说明

| 参数 | 类型 | 必填 | 说明 | | ------------ | ------------------------- | ---- | --------------------------------------------------------------------------------------------------- | | projectKey | string | ✅ | 项目标识 | | appSecret | string | ✅ | 应用密钥,从项目管理中获取 | | env | 'stg' \| 'pre' \| 'prd' | ✅ | 运行环境:stg(测试)、pre(预发)、prd(生产) | | configKey | string | ❌ | 配置 Key(item_key,用户自定义),支持多个英文逗号分隔(如 "admin,wx"),不传返回该环境下所有配置 | | baseUrl | string | ❌ | 后端服务地址,默认 https://coupe.szweizhong.cn | | fetcher | Fetcher | ❌ | 自定义请求函数,用于适配微信小程序等无 fetch 的环境,不传则使用 globalThis.fetch |

返回值

fetch() 返回一个对象,结构为 { [item_key]: json内容 }

type ConfigData = Record<string, unknown>;

使用示例

基本用法(拉取该环境全部配置)

import { CoupeSDK } from 'wz-coupe-sdk';

const sdk = new CoupeSDK({
  projectKey: 'daojuji',
  appSecret: 'your-app-secret',
  env: 'stg',
});

const config = await sdk.fetch();

指定单个配置

const sdk = new CoupeSDK({
  projectKey: 'daojuji',
  appSecret: 'your-app-secret',
  env: 'stg',
  configKey: 'admin',
});

const config = await sdk.fetch();

指定多个配置

const sdk = new CoupeSDK({
  projectKey: 'daojuji',
  appSecret: 'your-app-secret',
  env: 'stg',
  configKey: 'admin,wx', // 多个 item_key,英文逗号分隔
});

const config = await sdk.fetch();

自定义后端地址

const sdk = new CoupeSDK({
  projectKey: 'daojuji',
  appSecret: 'your-app-secret',
  env: 'stg',
  baseUrl: 'https://custom-domain.com',
});

const config = await sdk.fetch();

微信小程序

微信小程序环境没有 globalThis.fetch,需要传入自定义 fetcher 适配 wx.request

import { CoupeSDK } from 'wz-coupe-sdk';

const sdk = new CoupeSDK({
  projectKey: 'daojuji',
  appSecret: 'your-app-secret',
  env: 'prd',
  fetcher: (url, { headers }) =>
    new Promise((resolve, reject) => {
      wx.request({
        url,
        header: headers,
        success(res) {
          resolve({
            ok: res.statusCode >= 200 && res.statusCode < 300,
            status: res.statusCode,
            statusText: res.errMsg,
            text: () =>
              Promise.resolve(typeof res.data === 'string' ? res.data : JSON.stringify(res.data)),
            json: () => Promise.resolve(res.data),
          });
        },
        fail(err) {
          reject(new Error(err.errMsg));
        },
      });
    }),
});

const config = await sdk.fetch();

同样适用于 uni-app、Taro、React Native 等任何非标准 fetch 环境。

获取 SDK 配置信息

const sdk = new CoupeSDK({
  projectKey: 'daojuji',
  appSecret: 'your-app-secret',
  env: 'stg',
  configKey: 'admin',
});

console.log(sdk.getInfo());
// {
//   projectKey: 'daojuji',
//   env: 'stg',
//   configKey: 'admin',
//   baseUrl: 'https://coupe.szweizhong.cn',
//   hasSecret: true
// }

getInfo() 不会返回 appSecret 明文,仅通过 hasSecret 标识是否已配置密钥。

环境说明

| 环境 | 说明 | | ----- | -------- | | stg | 测试环境 | | pre | 预发环境 | | prd | 生产环境 |

API 接口

SDK 内部调用以下接口,鉴权通过请求头 x-app-secret 传递 appSecret

GET {baseUrl}/public/sdk/{projectKey}/{env}?config_key={configKey}

Headers:
  x-app-secret: {appSecret}
  x-sdk-version: 2.5.0

config_key 为可选查询参数,不传则返回项目当前环境下所有配置。

License

MIT