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

@kayak-sj/http

v1.0.2

Published

PC / H5 共用的 Kayak 网关 HTTP 客户端(不依赖 Vue 与任何 UI 库)

Downloads

682

Readme

@kayak-sj/http

Kayak 网关 HTTP 客户端,PC 管理台与 H5 共用。

对应旧工程 components/kayak-common/utils/httputil.js

定位

| 该放 | 不该放 | | --------------------------------------------------- | ----------------------------------------------- | | HttpClient 请求 / 业务码校验 / 下载 / 上传 | ElMessageshowToast 等 UI 调用 | | head_* 公共参数拼装、tran_code、设备号 | vue-router 跳转 | | 超时 / 网络异常文案映射 | 登录态 store、权限判断 | | 全局单例注册 createHttp / getHttp | 业务接口聚合(→ @kayak-sj/cms-base、app apis/) |

判断口诀: 跟「请求怎么发、响应怎么判」有关 → http;跟「错误怎么展示、失效怎么跳」有关 → 各端适配层。

本包不依赖 Vue、Element Plus、Vant,因此 PC 与 H5 可以共用同一份实现; 各端差异通过构造参数注入。

技术栈

  • TypeScript(无框架依赖)
  • axios

目录结构

http/
├── README.md
├── package.json
└── src/
    ├── index.ts        # 统一导出
    ├── HttpClient.ts   # 客户端实现
    ├── registry.ts     # createHttp / getHttp / httpGet / httpPost 全局单例
    ├── types.ts        # HttpClient 类型定义
    ├── kayakApi.ts     # Kayak 网关接口类型(KResponse / KParams / KRowsResponse)
    ├── constants.ts    # HTTP 成功码 / 超时 / 提示等网络常量
    ├── apiUrls.ts      # 接口 URL 工具(buildKayakApiUrls / buildTemplateDownloadBaseUrl)
    ├── resolveUrl.ts   # tran_code 解析与 URL 拼接
    └── deviceId.ts     # head_osnumber 设备标识

端差异注入点

| 参数 | 作用 | PC 实现 | H5 实现 | | --------------------- | ------------------------------------------------- | ----------------------------------------- | -------------------- | | onError | 展示错误提示 | ElMessage.error | Vant showToast | | onSuccess | 业务成功且带 head_ret_msg 时回调 | 审核类文案弹成功提示 | 不处理 | | onUnauthorized | 登录超时后清登录态并跳转 | 清 store + router.replace('/login') | 清 store + 跳登录页 | | extendCommonParams | 追加 / 覆盖网关公共参数 | wujie props.token 覆盖会话 ID | head_jsessionid 等 | | accessor | 读取会话 ID、用户信息、切换全局 loading | login store | auth store |

onError 的第二个参数 context.scene 区分错误来源,适配层可据此决定提示样式:

| scene | 触发时机 | | -------------- | -------------------------------------------- | | network | axios 抛错、超时、响应体为空 | | business | head_ret_code 非成功码且 checkCode !== false | | unauthorized | head_ret_code 命中 loginTimeoutCodes |

用法

PC(由 @kayak-sj/cms-base 适配后使用)

PC 应用不直接依赖本包,@kayak-sj/cms-base/http 已接好 Element Plus 与路由跳转:

import { createHttp, httpGet, httpPost } from '@kayak-sj/cms-base/http'

详见 cms-base README

H5

import { HttpClient } from '@kayak-sj/http'
import { showToast } from 'vant'

export const http = new HttpClient({
  baseURL: appConfig.apiBaseUrl,
  systemId: appConfig.systemId,
  accessor: {
    getSessionId: () => useAuthStore().token,
    getUserInfo: () => useAuthStore().userInfo
  },
  onError: (message) => showToast(message),
  onUnauthorized: () => {
    useAuthStore().clearAuth()
    void router.replace({ name: 'login' })
  },
  // H5 网关鉴权字段是 legacy 的 head_jsessionid(无下划线),并去掉默认的 head_jsession_id
  extendCommonParams: ({ sessionId }) => ({
    head_jsessionid: sessionId,
    head_jsession_id: undefined
  })
})

公共参数

getCommonParams 默认拼装以下字段,随后依次被 extendCommonParams 返回值、 调用方传入的业务 params 覆盖;extendCommonParams 设为 undefined 可移除默认字段:

| 字段 | 取值 | | ------------------ | --------------------------------------------------- | | head_system_id | params.system_idoptions.systemId | | head_channel_id | userInfo.channel_idoptions.headChannelId | | head_trans_code | URL 末段(去扩展名) → params.userid | | head_jsession_id | accessor.getSessionId() | | head_osnumber | 设备编号,写入 localStorage.kayak_osnumber | | batch_param | 固定空串 |

HttpRequestOptions

| 选项 | 类型 | 默认 | 说明 | | ------------ | --------- | ------ | ---------------------------------------- | | checkCode | boolean | true | 是否校验 head_ret_code 并提示 | | loading | boolean | true | 是否展示全局 loading(需 setLoading) | | method | string | POST | HTTP 方法 | | external | boolean | — | 调用外部完整 URL | | outWebSite | boolean | — | 外部系统接口,直接使用 url |

依赖关系

@kayak-sj/cms-base(PC 适配)   @kayak/h5-rights(H5 适配)
            └───────┬───────────────┘
                @kayak-sj/http    ← 本包(无 workspace 依赖;接口类型与网络常量已并入)

相关文档