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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ebscn/adapter

v0.0.32-beta

Published

adapter beta

Downloads

18

Readme

adapter

支持的功能

用户登录:

await getAuthParam(5, 1, requestFlag); requestFlag 0 读取缓存 token 1 网络请求 token

注:

1)requestFlag 通常默认传 0 , 如果接口返回验权失败错误号,再 requestFlag = 1 2)该支持包最终会提供 http 方法,无需调用方做 setheader

return type GetAuthParamJWTResult = { 'api-token'?: string; };

做了哪些事?

1)判断客户端版本号是否支持,如不支持调转到 app 下载页面 2)判断当前用户是否已登录,未登录则调用登录框自动登录并回调 token 3)支持 pc 调试,可模拟 app 返回数据

使用

请参考 dist/docs 文档

请参考 native hybrid 交互规范及接口文档

例子

说明

开发和调试

  • npm install
  • npm link
  • npm link adapter
  • npm run start

Adapter使用文档

1、getAppId方法,判断当前端

字典值:jyg(金阳光) web(浏览器) wx(微信端)

type AppIdType = 'jyg' | 'web' | 'wx'
export const getAppId = ()=>AppIdType

2、checkLogin方法,判断当前是否登录

/**
 * 检查登录状态 - web交易登录上线后需要扩展
 * @function checkLogin
 * @param {number} account_type 登录类型 0 普通账户, 1 信用账号, 3 期权账号, 5 用户
 * @param {string} appid 当前环境 非必传,默认取自getAppId方法返回值
 * @returns {Promise<{code, msg, data}>}
 */
type AccountType = 0 | 1 | 3 | 5
export const checkLogin = async (account_type: AccountType, appid?: AppIdType)=>Promise<{
    code: 0 | any, // code为0时成功,其他值错误
    msg:string, // 报错/成功信息
    data: string // 登录的对应类型账号值
}
需注意app端外暂不支持信用和期权账号

3、beginLogin方法,判断当前是否登录,若无登录则发起登录,此方法调用同checkLogin,唯一区别只在于登录动作是否业务方自行控制

/**
 * 检查登录状态并在未登录情况下调用登录功能 - web交易登录上线后需要扩展
 * @function beginLogin
 * @param {number} loginType 登录类型 0 普通账户, 1 信用账号, 3 期权账号, 5 用户
 * @param {string} appid 当前环境 非必传,默认取自getAppId方法返回值
 * @returns {Promise<any>}
 */
export const beginLogin = async (
  account_type: AccountType = 0,
  appid?: 'web' | 'wx' | 'jyg'
)=> Promise<{
    code: 0 | any, // code为0时成功,其他值错误
    msg:string, // 报错/成功信息
    data: string // 登录的对应类型账号值
}>

4、getAuthParam(重要方法),获取统一认证票据或token,新业务默认对接token,未登录则自动发起登录

/**
 * 检查登录状态并在未登录情况下调用登录功能 - web交易登录上线后需要扩展
 * @function getAuth
 * @param {number} account_type 登录类型 0 普通账户, 1 信用账号, 3 期权账号, 5 用户
 * @param {number} version 统一认证版本 0 老版本(缺省) 1 新版本
 * @param {number} requestFlag 是否丛缓存读取 0 读取缓存 1 请求最新
 * @param {string} appid 当前环境 非必传,默认取自getAppId方法返回值
 * @param {number | string} staleTime 单位秒,端外登录的缓存失效时间,默认与统一认证保持一致,900秒
 * @returns {Promise<any>}
 */
// 统一认证老版本票据
type GetAuthParamTicketResult = {
    appid?: number | undefined;
    authId?: string | undefined;
    authType?: string | undefined;
    ipAddress?: string | undefined;
    terminalWay?: string | undefined;
    macAddress?: string | undefined;
    serviceTicketId?: string | undefined;
    checkString?: string | undefined;
}
// 统一认证新版本token
type GetAuthParamJWTResult = {
    appid?: string | undefined;        
    'api-token'?: string | undefined;  // token
    userId?: string | undefined;       // 手机号登录的userId
    accountValue?: string | undefined; // 登录账号值
}
export const getAuthParam = async (account_type: AccountType = 0,
  version: VersionType = 1,
  requestFlag: RequestFlagType = 0,
  appid?: string,
  staleTime?: string | number)
  =>Promise<GetAuthParamTicketResult | GetAuthParamJWTResult | {
    code,
    msg
  }>

5、http(重要方法,推荐优先使用),基于axios扩展,适用于统一认证的请求方法,结合上述所有方法,业务方无需关心token失效的重新获取以及多请求并发情况下的token获取。只需确认所需的认证类型即可

interface HttpRequestParams extends AxiosRequestConfig {
  version?: VersionType。      // 认证版本,同上
  account_type?: AccountType   // 账号类型,同上
  errorHandler?: (errorMsg:string)=>void    // 自定义错误请求函数,可拿到请求的错误msg信息
  noAuth?: boolean //为true时不鉴权(判断优先级高于version和account_type) 不传时version和account_type必传
  appid?: AppIdType
  onAuthCb?: (
    authParams: void | LoginResultParam | GetAuthParamTicketResult | GetAuthParamJWTResult
    requestFlag: number
  ) => void     // 获取认证参数之后的钩子函数
  staleTime?: number | string // 端外登录的token主动过期时间 单位秒 同getAuthParam中的staleTime
}
export const http = async <T = object>(
  params: HttpRequestParams
) => Promise<{ code: string | number; msg: string; data?: T }>

6、跳转链接生成,目前支持端外scheme、端内中转以及消息推送超链接等

/**
 *
 * @param paramStr urlQuery拼接形式,支持参数见jssdk文档goWebview方法 如targetUrl=encodeURIComponent(${targetUrl})&navBarStyle=3
 * @param appid 当前环境,不传默认从jssdk获取
 * @param environment app环境,默认测试环境
 * @param newVersionOnly 是否只运行在金阳光7020版本及以上,默认false
 * @param withDownload 是否用通用下载页承载端外跳转功能 默认false
 * @param msgPush 是否站内信推送超链接格式 默认false
 * @returns scheme 返回生成的scheme
 */
type generateTransformPageParams = {
  paramStr: string
  environment?: 0 | 1 | 2 // 0 测试 1 仿真 2生产
  appid?: 'jyg' | 'wx' | 'web' // 打开端
  newVersionOnly?: boolean // 是否7000版本后
  withDownload?: boolean // 是否通过下载页打开
  msgPush?: boolean // 是否用于消息推送
}
export const generateTransformPage = async (params: generateTransformPageParams)=>string