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

@origen-ui/http

v2.0.2

Published

Generic HTTP layer: ApiClient (dedup-cancel / trace-id / retry / 401 silent refresh) + TokenManager

Readme

@origen-ui/http

@origen-ui/http 是基于 Axios 的请求传输边界,面向需要请求取消、幂等重试、追踪 ID、响应协议适配和可刷新鉴权的应用,同时不把业务规则塞进客户端。

import {
  ApiClient,
  createApiEnvelopeAdapter,
  createBearerAuthStrategy,
  responseDataAdapter,
  TokenManager,
} from '@origen-ui/http'

const tokens = new TokenManager({
  accessKey: 'admin-access-token',
  accessStorage: window.localStorage,
})

const api = new ApiClient({
  baseURL: '/api',
  responseAdapter: createApiEnvelopeAdapter(),
  auth: createBearerAuthStrategy({
    tokenManager: tokens,
    refresh: async ({ refreshToken, traceId }) => refreshSession({ refreshToken, traceId }),
    shouldRefresh: (error) => error.kind === 'business' && error.code === 40101,
    onExpired: () => navigateToLogin(),
  }),
  retry: 1,
})

成功请求解析为数据;失败请求 reject 为 ApiError。信封协议失败会具体 reject 为 ApiBusinessError,并保留后端 code、data、HTTP 状态码、追踪 ID 和请求上下文。

const users = await api.get<User[]>('/users', {
  params: { page: 1, pageSize: 20 },
})

const exportFile = await api.get<Blob>('/users/export', {
  responseType: 'blob',
  responseAdapter: responseDataAdapter,
})

TokenManager 默认使用内存存储。应用需要在刷新页面后保留令牌时,应显式传入存储适配器。DTO 归一化、分页参数映射和面向用户的业务错误翻译由业务仓库负责;本包只负责可靠的传输行为。如果注入的 onError 回调自身抛错,ApiClient 会记录回调错误,同时仍以原始 ApiError reject。

根入口 API 索引

| 分类 | 可见根入口 API | | ------------ | ---------------------------------------------------------------------------------------------------------------------------- | | 错误边界 | ApiBusinessError, ApiError, isApiError, ApiBusinessErrorOptions, ApiErrorKind, ApiErrorOptions, RequestContext | | 客户端与请求 | ApiClient, ApiClientOptions, RequestOptions | | 鉴权 | createBearerAuthStrategy, AuthStrategy, BearerAuthOptions, RefreshResult | | 响应适配 | createApiEnvelopeAdapter, rawResponseAdapter, responseDataAdapter, ResponseAdapter, ResponseContext | | 令牌管理 | TokenManager, TokenManagerOptions, TokenStorage |

上方示例说明这些入口在一次请求与刷新流程中的组合方式。

令牌与刷新边界

ApiClient 和 TokenManager 都由应用持有;本包不会安装单例客户端或存储策略。只有在分别传入对应存储选项时,访问令牌和刷新令牌才会独立持久化。刷新回调会收到当前刷新令牌、新的追踪 ID 和可选的 CSRF 令牌,并且必须返回新的访问令牌。刷新请求的传输方式和 Cookie 策略仍由应用负责。

resolveHeaders 会先解析每次请求的默认请求头,再应用显式请求头,因此调用方可以注入语言或租户请求头,而不必让客户端耦合应用状态。 HTTP 包不依赖 Element Plus,也不会把传输错误翻译为 UI 消息。