fastman3-dfyjapp-request 1.0.12 → 1.1.2
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 +12 -0
- package/es/interceptors/securityInterceptor.js +7 -4
- package/es/request.d.ts +2 -0
- package/es/request.js +19 -13
- package/es/utils.d.ts +7 -0
- package/es/utils.js +18 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,3 +54,15 @@
|
|
|
54
54
|
### v 1.0.12 - 2022.05.27
|
|
55
55
|
|
|
56
56
|
1. 将内部 getVersion 函数调用一律通过 fastman3-common-helper 库内函数来实现,去除了本地自己实现的 getVersion
|
|
57
|
+
|
|
58
|
+
### v 1.1.0 - 2022.06.05
|
|
59
|
+
|
|
60
|
+
1. 支持统一部署方案
|
|
61
|
+
|
|
62
|
+
### v 1.1.1 - 2022.06.06
|
|
63
|
+
|
|
64
|
+
1. restful接口支持POST请求
|
|
65
|
+
|
|
66
|
+
### v 1.1.2 - 2022.06.27
|
|
67
|
+
|
|
68
|
+
1. restful 接口 token 不需要缓存,解决登录态失效 机构户 登录页面不正常提示问题
|
|
@@ -7,11 +7,11 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
7
7
|
* @Description: 加解密处理 chain
|
|
8
8
|
*/
|
|
9
9
|
import { rsa, hex, aes, ecb, pkcs7, md5, utf8 } from "fastman3-common-crypto";
|
|
10
|
-
import { guid } from "../utils";
|
|
11
|
-
|
|
12
|
-
var appSecret = process.env.APP_SECRET;
|
|
10
|
+
import { guid } from "../utils";
|
|
13
11
|
|
|
14
12
|
var securityInterceptor = function securityInterceptor(chain) {
|
|
13
|
+
// 从配置文件中读取
|
|
14
|
+
var appSecret = process.env.APP_SECRET;
|
|
15
15
|
var requestParams = chain.requestParams;
|
|
16
16
|
if (requestParams === null || requestParams === void 0 ? void 0 : requestParams.isNative) return chain.proceed(requestParams);
|
|
17
17
|
var data = requestParams.data,
|
|
@@ -42,6 +42,9 @@ var securityInterceptor = function securityInterceptor(chain) {
|
|
|
42
42
|
if (RESTFUL_PATH_BY_FASTMAN3) {
|
|
43
43
|
if (method == "GET") {
|
|
44
44
|
requestParams.data = null;
|
|
45
|
+
} else {
|
|
46
|
+
// restful 接口post类型,重新组装 入参data
|
|
47
|
+
requestParams.data = JSON.parse(requestParams.data).payload;
|
|
45
48
|
}
|
|
46
49
|
} else {
|
|
47
50
|
requestParams.data = JSON.stringify(e);
|
|
@@ -60,7 +63,7 @@ var securityInterceptor = function securityInterceptor(chain) {
|
|
|
60
63
|
if (mySign !== responseEntity.sign) {
|
|
61
64
|
return Promise.reject({
|
|
62
65
|
code: -1,
|
|
63
|
-
info: "签名验签失败
|
|
66
|
+
info: "签名验签失败"
|
|
64
67
|
});
|
|
65
68
|
} // 签名通过后对content进行解密
|
|
66
69
|
|
package/es/request.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ declare type Params = {
|
|
|
7
7
|
method: "GET" | "OPTIONS" | "HEAD" | "POST" | "PUT" | "DELETE" | "TRACE" | "CONNECT" | undefined;
|
|
8
8
|
};
|
|
9
9
|
declare class fetch {
|
|
10
|
+
private init;
|
|
11
|
+
constructor();
|
|
10
12
|
baseOptions<T>(params: any, method?: Params["method"]): Promise<T & PromiseSuccessCR>;
|
|
11
13
|
/**
|
|
12
14
|
* 发起中台POST请求
|
package/es/request.js
CHANGED
|
@@ -8,29 +8,35 @@ import { addInterceptor, request } from "@tarojs/taro"; // import interceptors f
|
|
|
8
8
|
|
|
9
9
|
import { endProductInterceptor, transformInterceptor, logInterceptor, securityInterceptor, httpStatusInterceptor, timeoutInterceptor } from "./interceptors";
|
|
10
10
|
import { isFromApp } from "fastman3-common-helper";
|
|
11
|
-
import { storeToken, storeDeviceId, createRestfulGetPath, exceptionCodeOrInfoHandle } from "./utils";
|
|
11
|
+
import { storeToken, storeDeviceId, createRestfulGetPath, createRestfulGetPathNew, exceptionCodeOrInfoHandle } from "./utils";
|
|
12
12
|
import { AppAuthorize } from "fastman3-dfyjapp-jsbridge";
|
|
13
|
-
addInterceptor(endProductInterceptor);
|
|
14
|
-
addInterceptor(transformInterceptor);
|
|
15
|
-
addInterceptor(logInterceptor);
|
|
16
|
-
|
|
17
|
-
if (process.env.APP_ENV !== "mock") {
|
|
18
|
-
addInterceptor(securityInterceptor);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
addInterceptor(httpStatusInterceptor);
|
|
22
|
-
addInterceptor(timeoutInterceptor);
|
|
23
13
|
|
|
24
14
|
var fetch =
|
|
25
15
|
/** @class */
|
|
26
16
|
function () {
|
|
27
|
-
function fetch() {
|
|
17
|
+
function fetch() {
|
|
18
|
+
this.init = false;
|
|
19
|
+
}
|
|
28
20
|
|
|
29
21
|
fetch.prototype.baseOptions = function (params, method) {
|
|
30
22
|
if (method === void 0) {
|
|
31
23
|
method = "GET";
|
|
32
24
|
}
|
|
33
25
|
|
|
26
|
+
if (!this.init) {
|
|
27
|
+
addInterceptor(endProductInterceptor);
|
|
28
|
+
addInterceptor(transformInterceptor);
|
|
29
|
+
addInterceptor(logInterceptor);
|
|
30
|
+
|
|
31
|
+
if (process.env.APP_ENV !== "mock") {
|
|
32
|
+
addInterceptor(securityInterceptor);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
addInterceptor(httpStatusInterceptor);
|
|
36
|
+
addInterceptor(timeoutInterceptor);
|
|
37
|
+
this.init = true;
|
|
38
|
+
}
|
|
39
|
+
|
|
34
40
|
var data = params.data,
|
|
35
41
|
FUNCNO_POWER_BY_FASTMAN3 = params.FUNCNO_POWER_BY_FASTMAN3,
|
|
36
42
|
RESTFUL_PATH_BY_FASTMAN3 = params.RESTFUL_PATH_BY_FASTMAN3; // APP网关完整地址
|
|
@@ -133,7 +139,7 @@ function () {
|
|
|
133
139
|
|
|
134
140
|
fetch.prototype.getRest = function (restfulPath, data) {
|
|
135
141
|
var params = {
|
|
136
|
-
RESTFUL_PATH_BY_FASTMAN3:
|
|
142
|
+
RESTFUL_PATH_BY_FASTMAN3: createRestfulGetPathNew(restfulPath, data)
|
|
137
143
|
};
|
|
138
144
|
return this.baseOptions(params, "GET");
|
|
139
145
|
};
|
package/es/utils.d.ts
CHANGED
|
@@ -19,6 +19,13 @@ export declare const storeDeviceId: (deviceId: string) => void;
|
|
|
19
19
|
* @returns
|
|
20
20
|
*/
|
|
21
21
|
export declare const createRestfulGetPath: (path: string, param: any) => any;
|
|
22
|
+
/**
|
|
23
|
+
* 拼接path,组合成一个完整的restful-get请求路径 新版本
|
|
24
|
+
* @param path 路径path /xxx/xx
|
|
25
|
+
* @param param 参数 {a:1,...}
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export declare var createRestfulGetPathNew: (path: any, param: any) => string;
|
|
22
29
|
/**
|
|
23
30
|
* 统一接口异常 code info 处理 (中台新版 restful请求 使用)
|
|
24
31
|
* @param code 1xxx 3xxx
|
package/es/utils.js
CHANGED
|
@@ -59,6 +59,24 @@ export var createRestfulGetPath = function createRestfulGetPath(path, param) {
|
|
|
59
59
|
pathLink = path + "?" + (pathLink === null || pathLink === void 0 ? void 0 : pathLink.substr(1));
|
|
60
60
|
return pathLink.replace(" ", "");
|
|
61
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* 拼接path,组合成一个完整的restful-get请求路径 新版本
|
|
64
|
+
* @param path 路径path /xxx/xx
|
|
65
|
+
* @param param 参数 {a:1,...}
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
export var createRestfulGetPathNew = function createRestfulGetPath(path, param) {
|
|
70
|
+
var pathLink = "";
|
|
71
|
+
|
|
72
|
+
for (var k in param) {
|
|
73
|
+
pathLink += k + "=" + param[k] + "&";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
pathLink = pathLink.substring(0, pathLink.length - 1);
|
|
77
|
+
pathLink = path + "?" + pathLink;
|
|
78
|
+
return pathLink.replace(" ", "");
|
|
79
|
+
};
|
|
62
80
|
/**
|
|
63
81
|
* 统一接口异常 code info 处理 (中台新版 restful请求 使用)
|
|
64
82
|
* @param code 1xxx 3xxx
|