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

@quantabit/sdk-config

v1.0.9

Published

QuantaBit SDK 统一配置管理 - 所有SDK共享的API配置

Readme

@quantabit/sdk-config

QuantaBit SDK 统一配置管理模块。所有 SDK 共享此配置,修改一处即可全局生效

功能特性

  • 🔧 统一配置管理 - 所有 SDK 共享 API URL、超时等配置
  • 🌍 环境预设 - 开发、测试、生产等环境一键切换
  • 🔄 动态更新 - 支持运行时修改配置
  • ⚛️ React Hook - 提供 useSDKConfig Hook 便捷使用
  • 🔐 Token 管理 - 统一的认证 Token 存储和管理
  • 📝 日志系统 - 可配置的日志级别

安装

npm install @quantabit/sdk-config
# 或
yarn add @quantabit/sdk-config

快速开始

1. 应用启动时初始化配置

// app/layout.tsx 或 main.jsx
import { initConfig } from "@quantabit/sdk-config";

// 使用自定义配置
initConfig({
  apiBaseUrl: "https://api.yoursite.com/api/v1",
  timeout: 15000,
  debug: process.env.NODE_ENV !== "production",
});

// 或使用环境预设
import { initWithEnvironment } from "@quantabit/sdk-config";
initWithEnvironment("production");

2. 在组件中使用 Hook

import { useSDKConfig } from "@quantabit/sdk-config";

function SettingsPanel() {
  const { config, setApiBaseUrl } = useSDKConfig();

  return (
    <div>
      <p>当前 API: {config.apiBaseUrl}</p>
      <button onClick={() => setApiBaseUrl("https://new-api.com")}>
        切换 API
      </button>
    </div>
  );
}

3. 在其他 SDK 中使用

// 其他 SDK 内部使用
import { getConfig, buildApiUrl, getToken } from "@quantabit/sdk-config";

async function fetchData() {
  const config = getConfig();
  const url = buildApiUrl("/users/me");
  const token = getToken();

  const response = await fetch(url, {
    headers: {
      Authorization: `Bearer ${token}`,
    },
    timeout: config.timeout,
  });

  return response.json();
}

API 参考

配置函数

| 函数 | 说明 | | ------------------------------------- | ---------------------------- | | getConfig() | 获取当前配置对象 | | initConfig(options) | 初始化配置(应用启动时调用) | | setApiBaseUrl(url) | 设置 API 基础 URL | | setWsBaseUrl(url) | 设置 WebSocket URL | | setDebug(debug) | 设置调试模式 | | resetConfig() | 重置为默认配置 | | subscribeConfig(listener) | 订阅配置变更 | | initWithEnvironment(env, overrides) | 使用环境预设初始化 |

Token 管理

| 函数 | 说明 | | ----------------------------- | ------------------ | | getToken() | 获取 Access Token | | getRefreshToken() | 获取 Refresh Token | | saveTokens(access, refresh) | 保存 Token | | clearTokens() | 清除所有 Token | | isAuthenticated() | 检查是否已认证 |

工具函数

| 函数 | 说明 | | ----------------------------------- | ---------------- | | buildApiUrl(endpoint, useFullUrl) | 构建完整 API URL | | logger.debug/info/warn/error | 日志输出 |

配置项

| 配置项 | 类型 | 默认值 | 说明 | | ------------ | ------- | -------------- | ---------------- | | apiBaseUrl | string | /api/v1 | API 基础路径 | | apiFullUrl | string | ''(需配置) | 完整 API URL | | timeout | number | 30000 | 请求超时(毫秒) | | retryCount | number | 3 | 重试次数 | | debug | boolean | false | 调试模式 | | logLevel | string | info | 日志级别 | | wsBaseUrl | string | ''(需配置) | WebSocket URL |

环境预设

import { initWithEnvironment } from "@quantabit/sdk-config";

// 开发环境
initWithEnvironment("development");

// 测试环境
initWithEnvironment("staging");

// 生产环境
initWithEnvironment("production");

// 带覆盖配置
initWithEnvironment("production", {
  timeout: 10000,
});

与其他 SDK 集成

所有 QuantaBit SDK 都应从此包读取配置:

// 在 auth-sdk、wallet-sdk 等中
import {
  getConfig,
  buildApiUrl,
  getToken,
  logger,
} from "@quantabit/sdk-config";

class ApiClient {
  async request(endpoint, options = {}) {
    const config = getConfig();
    const url = buildApiUrl(endpoint);
    const token = getToken();

    logger.debug("Requesting:", url);

    const response = await fetch(url, {
      ...options,
      headers: {
        "Content-Type": "application/json",
        Authorization: token ? `Bearer ${token}` : undefined,
        ...options.headers,
      },
    });

    return response.json();
  }
}

License

MIT © QuantaBit Team