@lark-apaas/client-toolkit 1.2.73 → 1.2.74-alpha.20261011014021
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/lib/utils/getAxiosForBackend.d.ts +11 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @lark-apaas/client-toolkit
|
|
2
2
|
|
|
3
|
+
## 后端 API 请求
|
|
4
|
+
|
|
5
|
+
`axiosForBackend` 是可调用且带有 `.get`、`.post` 等方法的 Axios 实例。它会将
|
|
6
|
+
HTTP 403 响应作为 fulfilled response 返回,而不是交给 `catch`。保留完整 response,
|
|
7
|
+
先终止 403 分支,再读取 `response.data` 或执行成功副作用:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { axiosForBackend } from '@lark-apaas/client-toolkit/utils/getAxiosForBackend';
|
|
11
|
+
|
|
12
|
+
const response = await axiosForBackend.get('/api/resources');
|
|
13
|
+
if (response.status === 403) {
|
|
14
|
+
throw new Error('无权限执行此操作');
|
|
15
|
+
}
|
|
16
|
+
const resources = response.data;
|
|
17
|
+
```
|
|
18
|
+
|
|
3
19
|
## 项目架构设计
|
|
4
20
|
|
|
5
21
|
### apis 目录
|
|
@@ -6,6 +6,16 @@ declare module 'axios' {
|
|
|
6
6
|
};
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* 获取供前端调用后端接口的 Axios 实例。
|
|
11
|
+
*
|
|
12
|
+
* 该实例会将 HTTP 403 响应作为 fulfilled response 返回。调用方必须先保留完整
|
|
13
|
+
* response,在读取 response.data 或执行成功副作用前处理 response.status === 403,
|
|
14
|
+
* 并终止该分支。
|
|
15
|
+
*/
|
|
10
16
|
export declare function getAxiosForBackend(): AxiosInstance;
|
|
17
|
+
/**
|
|
18
|
+
* 供前端调用后端接口的 Axios 实例。HTTP 403 会作为 fulfilled response 返回;先检查
|
|
19
|
+
* response.status 并终止 403 分支,再读取 response.data 或执行成功副作用。
|
|
20
|
+
*/
|
|
11
21
|
export declare const axiosForBackend: AxiosInstance;
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/client-toolkit",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.74-alpha.20261011014021",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"lib"
|
|
8
8
|
],
|
|
9
|
+
"httpContracts": {
|
|
10
|
+
"axiosForBackend": {
|
|
11
|
+
"forbiddenResponse": "fulfilled"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
9
14
|
"publishConfig": {
|
|
10
15
|
"access": "public"
|
|
11
16
|
},
|