
Research
Supply Chain Attack on Axios Pulls Malicious Dependency from npm
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.
@skyfox2000/fapi
Advanced tools
这是一个基于 UniApp 和 Axios 的请求库,提供了统一的接口调用方式,支持请求缓存、字段映射、请求合并等高级功能。主要用于优化前端接口调用体验,提高开发效率。
npm install -S @skyfox2000/fapi
配置API_HOST接口域名参数
// 接口域名的格式定义
const API_HOST: {
[key: string]: string;
} = {
SITEHOST_API: "",
};
请求配置支持以下参数:
/**
* 请求数据结构
* @param Option 可选,后端控制配置
* @param Query 可选,查询或者统计条件
* @param Data 可选,需要保存或者处理的数据
*/
export type ReqParams = {
/** 后端控制配置 */
Option?: Record<string, any>;
/** 查询或者统计条件 */
Query?: Record<string, any>;
/** 需要保存或者处理的数据 */
Data?: AnyData;
};
{
/**
* API_HOST接口域名的Key
*/
api: string;
/**
* 接口地址,以/开头
*/
url: string;
/**
* 超时时间,默认5秒
*/
timeout?: number;
/**
* 默认参数
** Option 默认控制
** Query 默认查询
** Data 默认数据
*/
params?: ReqParams;
/**
* 出错时是否隐藏错误提示
** 默认false,默认发生错误立即显示
*/
hideErrorToast?: boolean;
/**
* 缓存时长,
* 默认0
** 0:不缓存
** 1:永久缓存
** 其他:缓存时长(单位:秒)
*/
cacheTime?: number;
/**
* 缓存类型
** memory 内存
** local 本地永久
** session 本地会话
** uni uniapp的缓存
*/
storage?: StorageType;
/**
* 是否需要授权Token
*/
authorize?: boolean;
/**
* 额外前端执行控制参数,不发送
*/
meta?: Record<string, any>;
/**
* 前端字段转换,保留原字段
** 支持数组/对象
** 支持模板{{属性名}}
*/
fieldMap?: Record<string, string>;
/**
* 额外header配置
*/
header?:
| Record<string, string>
| ((headers: Record<string, string>) => void);
/**
* 调用前置处理
* @param config 请求参数
*/
before?: (config: Record<string, any>) => void;
/**
* 调用后置处理
* @param config 请求参数
* @param result 结果数据
*/
after?: (config: Record<string, any>, result: ApiResponse) => void;
/**
* 是否跟踪调用链,请求结果发送到运维服务器
*/
trace?: boolean;
}
查询请求过程执行次序
// PUT请求
const res = await httpPut({
api: 'SITEHOST_API',
url: '/api/users',
params: {
Data: {
name: 'test'
}
}
})
// POST请求,查询
const res = await httpPost({
api: 'SITEHOST_API',
url: '/api/users',
params: {
Query: {
name: 'test'
}
}
})
配置接口列表进行统一管理,调用时,使用接口名即可,方便统一管理修改
import { IUrlInfo } from '@skyfox2000/fapi'
/** 站点相关接口 */
export const HostUrlList: {
/** 站点信息 */
host: IUrlInfo
} = {
host: {
api: 'SITEHOST_API',
url: '/openapi/RCSiteHostSrv/get',
fieldMap: {
hostId: 'Id',
hostName: 'Name',
},
},
}
export const AppUrlList: {
/** 获取应用信息 */
appInfo: IUrlInfo
} = {
appInfo: {
api: 'SITEHOST_API',
url: '/api/RCApplicationSrv/get',
fieldMap: {
appId: 'Id',
appName: 'Name',
},
},
}
/// 调用方法
const res = await httpPost(HostUrlList.host, { Query: { Mobile: mobile } } )
export const UserUrlList: {
/** 用户信息 */
list: IUrlInfo
} = {
list: {
api: 'SITEHOST_API',
url: '/api/users/list',
cacheTime: 60, // 缓存60秒
storage: 'memory',
params: { /// 默认参数,合并数据
Query: {
page: 1
}
}
},
}
/// 调用方法
const res = await httpPost(UserUrlList.list, { Query: { Mobile: mobile } } )
{
status: ResStatus.SUCCESS | ResStatus.ERROR; // 响应状态
errno: number; // 错误码
msg?: string; // 提示信息
timestamp?: string; // 响应时间
data?: T | { // 响应数据
total: number; // 记录总数
rows: T[]; // 数据列表
};
}
库内置了统一的错误处理机制:
默认会通过 Toast 提示错误信息,可以通过 hideErrorToast 配置关闭。
支持多种缓存方式:
可以通过 cacheTime 和 storage 参数配置缓存策略。
export const AppUrlList: {
/** 获取应用信息 */
appInfo: IUrlInfo
} = {
appInfo: {
api: 'SITEHOST_API',
url: '/api/RCApplicationSrv/get',
before: (config: Record<string, any>) => {
// config为request的请求参数
}
},
}
export const AppUrlList: {
/** 获取应用信息 */
appInfo: IUrlInfo
} = {
appInfo: {
api: 'SITEHOST_API',
url: '/api/RCApplicationSrv/get',
after: (config: Record<string, any>, result: ApiResponse) => {
// config为request的请求参数
// result为返回结果
}
},
}
{{field}}///类型提示
{
"exports": {
".": {
"types": "./lib/index.d.ts", /// 必须加在前面,否则类型提示会有问题
"default": "./lib/fapi.es.js"
}
}
}
FAQs
一个扩展的HTTP请求库,支持UniApp和Axios两种方式,支持请求合并、缓存、字段映射、前置/后置处理等高级功能的轻量级封装
We found that @skyfox2000/fapi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.

Security News
TeamPCP is partnering with ransomware group Vect to turn open source supply chain attacks on tools like Trivy and LiteLLM into large-scale ransomware operations.