Skip to content

Commit adfac33

Browse files
author
danyuandefine
committed
上传客户端工具包代码
1 parent ed5ef0d commit adfac33

17 files changed

+6050
-0
lines changed

.babelrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"presets": [
3+
["@babel/preset-env", {
4+
"targets": {
5+
"node": "current"
6+
}
7+
}]
8+
]
9+
}

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
.DS_Store
2+
node_modules
3+
/dist
4+
/client_dist
5+
/dist_electron
6+
/lib
7+
# local env files
8+
.env.local
9+
.env.*.local
10+
11+
# Log files
12+
npm-debug.log*
13+
yarn-debug.log*
14+
yarn-error.log*
15+
pnpm-debug.log*
16+
17+
# Editor directories and files
18+
.idea
19+
.vscode
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
25+
/target/*
26+

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
### easy-api-client 简介
2+
> 此项目用于快速接入服务端api框架easy-spring-boot-api,基于axios,可用于web或者node环境。提供了ApiClient工具,自动对api加签、验签、加解密等等功能,在保障服务器api安全的前提下,能做到业务无感知,简化前后端开发人员的联调工作。
3+
* 安装依赖
4+
`npm install easy-api-client`或者`yarn add easy-api-client`
5+
6+
* 功能使用示例
7+
```ts
8+
import {ApiClient, newApiClientInstance, RequestType} from "easy-api-client";
9+
let client: ApiClient = newApiClientInstance({
10+
baseUrl: "http://localhost:8080/server/",
11+
channelId: "web",
12+
appId: "test-demo",
13+
secret: "NKVNcuwwEF56c22A",
14+
locale: "zh_CN",
15+
apiSuffix: ".do"
16+
});
17+
client.request({
18+
apiName: "/demo/pay",
19+
type: RequestType.post,
20+
needSignResult: true,
21+
needSign: true
22+
}, {
23+
appId: client.options.appId,
24+
orderId: "easy_api_client001",
25+
description: "just a test!",
26+
currency: "CNY",
27+
totalAmount: 1,
28+
originalAmount: 5,
29+
userId: "U008958",
30+
userNickname: "小明"
31+
}).then((response: any) => {
32+
console.log(response.data);
33+
}, (reason: any) => {
34+
console.log(reason);
35+
});
36+
```
37+
### npm包的发布流程
38+
1. 构建项目
39+
> `npm run build`
40+
2. 登录账号
41+
> `npm login --registry=https://registry.npmjs.org/`
42+
3. 发布包
43+
> `npm publish --registry=https://registry.npmjs.org/`

jest.config.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export default {
2+
//automock: false,
3+
verbose: true,
4+
clearMocks: true, // 是否每次运行清除mock
5+
collectCoverageFrom: ['src/*.{js,ts}', 'src/**/*.{js,ts}'], //覆盖率文件
6+
coverageDirectory: 'coverage', // 生成覆盖率的文件名
7+
coverageProvider: 'v8',
8+
coverageThreshold: { // 覆盖率阈值
9+
global: {
10+
branches: 90,
11+
functions: 95,
12+
lines: 95,
13+
statements: 95,
14+
},
15+
},
16+
moduleFileExtensions: ['ts', 'tsx', 'js', 'json', 'jsx', 'node'], // 文件扩展
17+
preset: 'ts-jest', //ts
18+
setupFilesAfterEnv: [ // 每次test的启动文件,类似main.ts
19+
"<rootDir>/test/boot.ts"
20+
],
21+
testEnvironment: 'node', // node、jsdom
22+
testRegex: '(/test/.+\\.(test|spec))\\.(ts|tsx|js)$', // 要进行test的文件正则
23+
};

0 commit comments

Comments
 (0)