fastman3-dfyjapp-request 1.0.7 → 1.0.8

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 CHANGED
@@ -33,3 +33,7 @@
33
33
  ### v 1.0.7 - 2021.10.21
34
34
 
35
35
  1. 新增对微信的环境判断输出
36
+
37
+ ### v 1.0.8 - 2022.04.20
38
+
39
+ 1. 新增restful接口-携带(jwt token)请求方式getRouter,postRouter
@@ -45,7 +45,8 @@ var endProductInterceptor = function endProductInterceptor(chain) {
45
45
 
46
46
  if (RESTFUL_PATH_BY_FASTMAN3) {
47
47
  data = res;
48
- code = res.data.code;
48
+ code = res.data.code || res.statusCode == 200 ? 0 : res.statusCode; // 解决restful 接口mock环境 不正常访问
49
+
49
50
  info = res.data.restfulInfo;
50
51
  } // 是否服务端会话过期
51
52
 
@@ -61,13 +62,13 @@ var endProductInterceptor = function endProductInterceptor(chain) {
61
62
  } else if (code >= 1000 && code <= 1999) {
62
63
  return Promise.reject({
63
64
  code: 1000,
64
- info: "\u670D\u52A1\u5668\u53D1\u751F\u9519\u8BEF(" + code + ")"
65
+ info: "\u670D\u52A1\u5668\u53D1\u751F\u9519\u8BEF(".concat(code, ")")
65
66
  });
66
67
  } else if (isServerSessionExpired) {
67
68
  removeStorageSync(TOKEN_KEY);
68
69
  return Promise.reject({
69
70
  code: 3000,
70
- info: "\u672A\u767B\u5F55\u6216\u767B\u5F55\u6001\u5DF2\u5931\u6548(" + code + ")"
71
+ info: "\u672A\u767B\u5F55\u6216\u767B\u5F55\u6001\u5DF2\u5931\u6548(".concat(code, ")")
71
72
  });
72
73
  } else {
73
74
  return Promise.reject({
@@ -74,7 +74,7 @@ var httpStatusInterceptor = function httpStatusInterceptor(chain) {
74
74
  // 其它未能捕获的http异常
75
75
  return Promise.reject({
76
76
  code: res.statusCode,
77
- info: "Http\u53D1\u751F\u5176\u5B83\u5F02\u5E38(" + res.statusCode + ")"
77
+ info: "Http\u53D1\u751F\u5176\u5B83\u5F02\u5E38(".concat(res.statusCode, ")")
78
78
  });
79
79
  }
80
80
  });
@@ -12,11 +12,11 @@ export default function logInterceptor(chain) {
12
12
  FUNCNO_POWER_BY_FASTMAN3 = requestParams.FUNCNO_POWER_BY_FASTMAN3,
13
13
  RESTFUL_PATH_BY_FASTMAN3 = requestParams.RESTFUL_PATH_BY_FASTMAN3; // eslint-disable-next-line no-console
14
14
 
15
- console.log("http " + (method || "GET") + " --> " + url + " data[" + (FUNCNO_POWER_BY_FASTMAN3 || RESTFUL_PATH_BY_FASTMAN3) + "]: ", data);
15
+ console.log("http ".concat(method || "GET", " --> ").concat(url, " data[").concat(FUNCNO_POWER_BY_FASTMAN3 || RESTFUL_PATH_BY_FASTMAN3, "]: "), data);
16
16
  var p = chain.proceed(requestParams);
17
17
  var res = p.then(function (res) {
18
18
  // eslint-disable-next-line no-console
19
- console.log("http <-- " + url + " result[" + FUNCNO_POWER_BY_FASTMAN3 + "]:", JSON.stringify(res));
19
+ console.log("http <-- ".concat(url, " result[").concat(FUNCNO_POWER_BY_FASTMAN3, "]:"), JSON.stringify(res));
20
20
  return res;
21
21
  });
22
22
  if (typeof p.abort === "function") res.abort = p.abort;
@@ -1,4 +1,4 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
2
 
3
3
  /*
4
4
  * @Author: shenzhiwei
@@ -41,6 +41,8 @@ var transformInterceptor = function transformInterceptor(chain) {
41
41
  _system = "iOS";
42
42
  } else if (isFromAndroid()) {
43
43
  _system = "Andriod";
44
+ } else {
45
+ _system = "Weixin"; // 添加默认值
44
46
  }
45
47
  }
46
48
 
package/es/request.d.ts CHANGED
@@ -37,6 +37,24 @@ declare class fetch {
37
37
  * 纯净版request
38
38
  */
39
39
  requestNative(params: any): Taro.RequestTask<any>;
40
+ /**
41
+ * 发起中台新版POST restful -请求
42
+ * HEADER 里面带上jwt token ,即:Authorization: Bearer ${jwt token}
43
+ * @param restfulPath restful接口路径,通常由/xxx/xxx...
44
+ * @param data 数据,对象类型
45
+ */
46
+ postRouter(restfulPath: string, data: {
47
+ [key: string]: any;
48
+ }): Taro.RequestTask<any>;
49
+ /**
50
+ * 发起中台新版 GET restful请求
51
+ * HEADER 里面带上jwt token ,即:Authorization: Bearer ${jwt token}
52
+ * @param restfulPath restful接口路径,通常由/xxx/xxx...
53
+ * @param data 数据,对象类型
54
+ */
55
+ getRouter(restfulPath: string, data?: {
56
+ [key: string]: any;
57
+ }): Taro.RequestTask<any>;
40
58
  }
41
59
  declare const _default: fetch;
42
60
  export default _default;
package/es/request.js CHANGED
@@ -9,6 +9,7 @@ import { addInterceptor, request } from "@tarojs/taro"; // import interceptors f
9
9
  import { endProductInterceptor, transformInterceptor, logInterceptor, securityInterceptor, httpStatusInterceptor, timeoutInterceptor } from "./interceptors";
10
10
  import { isFromApp } from "fastman3-common-helper";
11
11
  import { storeToken, storeDeviceId, createRestfulGetPath } from "./utils";
12
+ import { AppAuthorize } from "fastman3-dfyjapp-jsbridge";
12
13
  addInterceptor(endProductInterceptor);
13
14
  addInterceptor(transformInterceptor);
14
15
  addInterceptor(logInterceptor);
@@ -43,8 +44,10 @@ function () {
43
44
 
44
45
  if (process.env.APP_ENV === "mock" && !RESTFUL_PATH_BY_FASTMAN3) {
45
46
  url = process.env.GATEWAY_URL + "/" + FUNCNO_POWER_BY_FASTMAN3;
46
- } else if (RESTFUL_PATH_BY_FASTMAN3) {
47
+ } else if (RESTFUL_PATH_BY_FASTMAN3 && process.env.APP_ENV != "mock") {
47
48
  url = process.env.GATEWAY_RESTFUL_URL + RESTFUL_PATH_BY_FASTMAN3;
49
+ } else if (RESTFUL_PATH_BY_FASTMAN3 && process.env.APP_ENV === "mock") {
50
+ url = process.env.GATEWAY_URL + RESTFUL_PATH_BY_FASTMAN3;
48
51
  } else {
49
52
  url = process.env.GATEWAY_URL;
50
53
  }
@@ -144,6 +147,78 @@ function () {
144
147
  isNative: true
145
148
  }, params));
146
149
  };
150
+ /**
151
+ * 发起中台新版POST restful -请求
152
+ * HEADER 里面带上jwt token ,即:Authorization: Bearer ${jwt token}
153
+ * @param restfulPath restful接口路径,通常由/xxx/xxx...
154
+ * @param data 数据,对象类型
155
+ */
156
+
157
+
158
+ fetch.prototype.postRouter = function (restfulPath, data) {
159
+ if (typeof data != "string") {
160
+ data = JSON.stringify(data);
161
+ }
162
+
163
+ var fullUrlPath;
164
+
165
+ if (process.env.APP_ENV === "mock") {
166
+ fullUrlPath = process.env.ROUTER_URL + "/" + restfulPath.split("func=")[1];
167
+ } else {
168
+ fullUrlPath = process.env.ROUTER_URL + restfulPath;
169
+ }
170
+
171
+ var params = {
172
+ url: fullUrlPath,
173
+ method: "POST",
174
+ data: data
175
+ }; // header添加Authorization -jwt认证-IF018020-accessToken 登录成功时存在,否则为空
176
+ //@ts-ignore
177
+
178
+ if (!!AppAuthorize.accessToken) {
179
+ params.header = {
180
+ //@ts-ignore
181
+ "Authorization": "Bearer ".concat(AppAuthorize.accessToken)
182
+ };
183
+ }
184
+
185
+ return this.requestNative(params);
186
+ };
187
+ /**
188
+ * 发起中台新版 GET restful请求
189
+ * HEADER 里面带上jwt token ,即:Authorization: Bearer ${jwt token}
190
+ * @param restfulPath restful接口路径,通常由/xxx/xxx...
191
+ * @param data 数据,对象类型
192
+ */
193
+
194
+
195
+ fetch.prototype.getRouter = function (restfulPath, data) {
196
+ if (typeof data != "string") {
197
+ data = JSON.stringify(data);
198
+ }
199
+
200
+ var fullUrlPath;
201
+
202
+ if (process.env.APP_ENV === "mock") {
203
+ fullUrlPath = process.env.ROUTER_URL + restfulPath.split("func=")[1];
204
+ } else {
205
+ fullUrlPath = process.env.ROUTER_URL + createRestfulGetPath(restfulPath, data);
206
+ }
207
+
208
+ var params = {
209
+ url: fullUrlPath
210
+ }; // header添加Authorization -jwt认证-IF018020-accessToken 登录成功时存在,否则为空
211
+ //@ts-ignore
212
+
213
+ if (!!AppAuthorize.accessToken) {
214
+ params.header = {
215
+ //@ts-ignore
216
+ "Authorization": "Bearer ".concat(AppAuthorize.accessToken)
217
+ };
218
+ }
219
+
220
+ return this.requestNative(params);
221
+ };
147
222
 
148
223
  return fetch;
149
224
  }();
package/es/utils.js CHANGED
@@ -67,7 +67,7 @@ export var createRestfulGetPath = function createRestfulGetPath(path, param) {
67
67
 
68
68
  for (var k in param) {
69
69
  var value = param[k] !== undefined ? param[k] : '';
70
- pathLink += "&" + k + "=" + encodeURIComponent(value);
70
+ pathLink += "&".concat(k, "=").concat(encodeURIComponent(value));
71
71
  }
72
72
 
73
73
  pathLink = path + "?" + (pathLink === null || pathLink === void 0 ? void 0 : pathLink.substr(1));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastman3-dfyjapp-request",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "a network request for dfyj app",
5
5
  "main": "es/request.js",
6
6
  "scripts": {