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

@gzbapp/business-support

v2.1.4

Published

--- name: '@gzbapp/business-support' ---

Readme


name: '@gzbapp/business-support'

概览

面向 GZB 应用的业务支撑库,提供统一的鉴权初始化、菜单权限、RPC/History/ThirdParty 注入、组织选择器适配与通用上报能力,替代应用内的 rootModel、menuModel 以统一分权逻辑。

2.x.x 版本技术栈

正式版起点为 2.0.0,面向 React 18 项目。

React / React DOM ^18.3.1 开发基线,配套 React 18 类型声明;TypeScript ^4.9.5;

安装

yarn add @gzbapp/business-support

快速开始

import {
  useRootModel,
  useMenuModel,
  appReport,
  EventTypeEnum,
} from '@gzbapp/business-support'

const root = useRootModel()
const menu = useMenuModel()

await root.initBusinessSupport({
  appId: window.APP_ID,
})

await root.auth({
  businessConfig: {
    appId: window.APP_ID,
  },
})

const firstRoute = menu.firstMenu()

await appReport({
  appId: window.APP_ID,
  eventType: EventTypeEnum.appLoad,
})

核心能力

  • 统一初始化:封装 RPC、History、AuthService、ThirdParty 的注入与默认实例获取
  • 统一鉴权:自动登录、鉴权恢复、后台入口重定向与回调扩展
  • 权限菜单:后台菜单初始化、无权限兜底与首个可用路由获取
  • 组织选择器适配:对接 jm-org-selector 的组织、部门、人员、角色数据能力
  • 通用上报:应用启动、后台启动等事件上报

API 总览

模型与 Hook

  • useRootModel:RootModel 单例,用于初始化与鉴权
  • useMenuModel:MenuModel 单例,用于菜单获取与首路由计算
  • RootModel / MenuModel:模型类型

初始化与鉴权

  • RootModel.initBusinessSupport(params: BusinessInitParams)
  • RootModel.auth(params?: AuthParams)
  • RootModel.logout()
  • RootModel.checkAuth()

插件与实例

  • rpc / history / authService / thirdParty:当前注入实例
  • getAppRpc / getAppHistory / getAppAuthService / getAppThirdParty:注入自定义实例并返回
  • rpcAuthRefreshInterceptor:刷新 token 的拦截器挂载

菜单

  • getMenuByUserId(appId?: string, extraHeader?: Record<string, string>)
  • MenuInfo / RouteInfo / unauthorizedMenu

组织选择器

  • Adaptor:JmOrgSelector 的统一适配器
  • JmOrgSelectorService 中的查询方法(导出所有 service 方法)

上报

  • appReport(params: AppReportParams)
  • EventTypeEnum / DeviceTypeEnum / SourceEnum

关键类型

BusinessInitParams

export interface BusinessInitParams {
  rpc?: JSONRPC
  history?: JmHistory
  authService?: Auth
  thirdParty?: ThirdPartyHandler
  extraHeader?: Record<string, string>
  encrypt?: boolean
  encryptHeaders?: any
}

AuthParams

export interface AuthParams {
  adminPage?: string[]
  appPage?: string[]
  businessConfig?: {
    initThirdParty?: boolean
    initAdminMenu?: boolean
    appId: string
  }
  cb?: {
    overrideFromPcAndIsInApp?: () => void
    overrideRedirectAdmin?: () => void
    onFinishAuth?: () => void
  }
}

使用建议

  • 先调用 initBusinessSupport,再调用 auth
  • appId 优先从 window.APP_ID 读取并在 businessConfig 中传入
  • 需要追加请求头时使用 extraHeader
  • 如果业务自行管理 RPC 加密初始化,可传入 encrypt=false

环境与依赖

  • peerDependencies:react、react-dom、@gzbapp/sdk
  • 依赖:mobx、dayjs、qs、@gzbapp/jm-rc-components