
Security News
Frontier AI Is Now Critical Infrastructure
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.
soapi-cli
Advanced tools
接口平台前端开发使用的 sdk 开发工具,用于将接口平台的 schema/route 自动化的生成前端 api 代码。
npm install soapi-cli
or use yarn
yarn add soapi-cli
在项目目录下创建.sdkrc.yml或.sdkrc.json文件进行 sdk 配置
| field | type | default | description |
|---|---|---|---|
| *platform | string | - | 接口平台地址 |
| *output | string | - | 输出 sdk 的文件夹路径 |
| node | boolean | false | 是否是 node 版本,node 版本 sdk 需要安装node-fetch |
| *applications | object[] | - | 需要生成 sdk 的接口平台应用,详细结构请看下文 |
| field | type | default | description |
|---|---|---|---|
| *appId | number | - | 应用 id |
| *token | string | - | 应用的授权 token |
YAML 格式配置如下:
platform: 'http://localhost:4003'
output: src/apis/
node: true
applications:
- appId: 0
token: 'yourToken'
JSON 格式配置如下:
{
"platform": "http://localhost:4003",
"output": "src/apis/",
"node": false,
"applications": [
{
"appId": 0,
"token": "yourToken"
}
]
}
| commander | description |
|---|---|
npx soapi-cli upgrade | 生成/升级 sdk |
| options | description | example |
|---|---|---|
--force | 强制更新全部 API | npx soapi-cli upgrade --force |
-h --help | show help | npx soapi-cli -h |
-v --version | show soapi-cli version | npx soapi-cli -v |
--debug | 展示 debug 信息 | npx soapi-cli --debug trace |
import getArticle from 'sdk/appName.get.api.article'
import app from 'sdk/appName'
import {
setEnv,
checkSchema,
catchError,
} from '@soapi/middlewares'
/**
* 全局中间件配置
* 所有api接口调用时都会执行
*/
app
/**
* 配置接口运行环境
* 不同的运行环境会调用不同的url
* 各环境url配置请到接口平台,sdk插件中配置
* 如果使用中间件进行设置,则默认优先取SDK_ENV,其次取NODE_ENV
* 如果无法取得有效值,默认为`prod`环境。
*/
.use(setEnv(process.env.NODE_ENV))
.use(catchError(error => {
console.log('what the fuck!')
/**
* 这里如果不抛出错误
* sdk会认为您已经将错误正确的处理,并将继续执行
* 这将导致sdk的api被调用时候,向外抛出的错误被中间件拦截并处理
* 调用的地方将无法得知错误的发生,并按照正常调用处理
*/
throw error
}))
// use in saga
try {
/**
* 根据文档平台定义和入参对象的key自动设置headers,body,query和params
* 入参对象中未匹配到的key将会放入body对象中
*/
yield getArticle({ articleId: 1 })
} cache (e) {
// handle error
}
// 指定body,支持链式调用
yield getArticle().send({ articleId: 1 })
// 指定headers,支持链式调用
yield getArticle().set('Content-Type', 'application/json').set({ Token: 'token' })
// 指定query,支持链式调用
yield getArticle().query('pageSize', 10).query({ current: 1 })
// 指定params,支持链式调用
yield getArticle().params('id', 1).params({ pid: 1 })
@soapi/middlewares 提供一些通用的 middleware,详见:http://gitlab.shein.com/nj_shein_fed/soapi/tree/master/modules/middlewares。
start=>start: 开始
end=>end: 结束
checkPackage=>condition: 是否安装soapi-cli
installPackage=>operation: 安装soapi-cli
editConfig=>operation: 编辑配置文件
save=>operation: 保存配置
runCli=>operation: 运行cli
checkField=>condition: CLI: 检查配置文件
checkApplicationSDKPlugin=>condition: 检查应用是否安装了sdk插件
alertInstalSDKPlugin=>operation: 警告“应用需要启动sdk服务插件,以配置应用的运行环境信息”
downloadSDK=>subroutine: CLI: 下载sdk需要的应用信息(需要授权key和applicationId)
至output目录
importSDK=>operation: import 'output/appName.xxx.xxx'
start->checkPackage(yes)->runCli
checkPackage(no, bottom)->installPackage->editConfig
editConfig->save
save->runCli->checkField(no)->editConfig
checkField(yes)->checkApplicationSDKPlugin(no)->alertInstalSDKPlugin->end
checkApplicationSDKPlugin(yes)->downloadSDK->importSDK->end
sdk 自动生成的代码依赖于fetch、Symbol,如果运行环境不支持,请添加相应的 polyfill。sdk生成代码需要依赖 sdk-service 插件提供一些额外的配置信息。(如:不同环境的应用 url)请先在接口平台的应用中启动SDK插件FAQs
接口平台前端开发使用的 sdk 开发工具
The npm package soapi-cli receives a total of 570 weekly downloads. As such, soapi-cli popularity was classified as not popular.
We found that soapi-cli demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers 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.

Security News
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.