@tmsfe/tms-core 0.0.202 → 0.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.202",
3
+ "version": "0.2.1",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
package/src/index.js CHANGED
@@ -56,6 +56,14 @@ import * as storage from './storage';
56
56
  import * as uiUtil from './tmsuiUtils';
57
57
  import { throttle, debounce } from './funcUtils';
58
58
  import { formatAmount } from './priceUtils';
59
+ import {
60
+ validTaxId,
61
+ validPhone,
62
+ validName,
63
+ validEmail,
64
+ validIdNumber,
65
+ } from './regCheck';
66
+
59
67
 
60
68
  /**
61
69
  * @public
@@ -241,6 +249,13 @@ const api = {
241
249
  /* 金额方法 */
242
250
  formatAmount,
243
251
 
252
+ /* 常见正则校验 */
253
+ validTaxId,
254
+ validPhone,
255
+ validName,
256
+ validEmail,
257
+ validIdNumber,
258
+
244
259
  /* 时间方法 */
245
260
  groupTimeDuration,
246
261
  formatTimeDuration,
@@ -0,0 +1,40 @@
1
+ /**
2
+ * 常见正则校验
3
+ */
4
+
5
+ // 校验税号
6
+ function validTaxId(taxId) {
7
+ return /^[A-Z0-9]{15}$|^[A-Z0-9]{17}$|^[A-Z0-9]{18}$|^[A-Z0-9]{20}$/.test(taxId);
8
+ }
9
+
10
+ // 校验电话、手机号
11
+ function validPhone(phone) {
12
+ const reg = /^(1[3456789]\d{9}|(\d{3,4}-\d{7,8}))$/;
13
+ return reg.test(phone);
14
+ }
15
+
16
+ // 校验姓名只允许中英文
17
+ function validName(name) {
18
+ const reg = /^[\u4e00-\u9fa5a-zA-Z]+$/;
19
+ return reg.test(name);
20
+ }
21
+
22
+ // 验证邮箱地址
23
+ function validEmail(email) {
24
+ const regExp = /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/;
25
+ return regExp.test(email);
26
+ }
27
+
28
+ // 匹配身份证号
29
+ function validIdNumber(idNumber: string): boolean {
30
+ const regExp = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
31
+ return regExp.test(idNumber);
32
+ }
33
+
34
+ export {
35
+ validTaxId,
36
+ validPhone,
37
+ validName,
38
+ validEmail,
39
+ validIdNumber,
40
+ };
@@ -44,8 +44,8 @@ function getSystemInfo(): ISystemInfo {
44
44
  if (!systemInfo) {
45
45
  const currentSystemInfo = wx.getSystemInfoSync() as any;
46
46
  // eslint-disable-next-line
47
- const { model = '', version: wxVersion = '', platform = '', SDKVersion = '', host } = currentSystemInfo;
48
- systemInfo = { model, wxVersion, platform, SDKVersion, host };
47
+ const { model = '', version: wxVersion = '', platform = '', SDKVersion = '', host, benchmarkLevel, system, memorySize } = currentSystemInfo;
48
+ systemInfo = { model, wxVersion, platform, SDKVersion, host, benchmarkLevel, system, memorySize };
49
49
  }
50
50
  return systemInfo;
51
51
  }
package/src/request.js CHANGED
@@ -407,7 +407,7 @@ export default class Request {
407
407
  const res = await this.invokeRequest(path, param, method, header);
408
408
  // format 业务errcode,用于判断是否做重试
409
409
  const { errCode } = formatResErrCode(path, res.data);
410
- // 重试case1:处理token失效情况(errcode=35)
410
+ // 处理token失效情况(errcode=35)
411
411
  const needRetryLogin = errCode === 35 && isPathNeedRetryLogin(path);
412
412
  if (needRetryLogin) {
413
413
  // 调用runtime的login方法刷新token
@@ -415,24 +415,9 @@ export default class Request {
415
415
  // 刷新后重试一次请求
416
416
  return await this.invokeRequest(path, param, method, header);
417
417
  }
418
-
419
- // 重试case3:处理网关框架码重试 requestRetryFlag?.gatewayCode由七彩石配置
420
- const { requestRetryFlag } = wx.tmsFlagMap || {};
421
- // X-Gateway-Code必须首字母大写,否则真机取不到
422
- const gatewayCode = res?.header?.['X-Gateway-Code'];
423
- if (requestRetryFlag?.gatewayCode && isGatewayCodeNeedRetry(gatewayCode)) {
424
- return await this.handleReTry(path, param, method, header, {
425
- reportMsg: {
426
- gatewayCode,
427
- errMsg: `home gateway code ${gatewayCode} requires retry`,
428
- },
429
- waitTime: 10, // 网关框架码错误10ms后再重试
430
- isSuccess: retryRes => !isGatewayCodeNeedRetry(retryRes?.header?.gatewayCode),
431
- });
432
- }
433
418
  return res;
434
419
  } catch (err) {
435
- // 重试case2:微信系统errno:在重试码白名单内,重试
420
+ // 微信系统errno:在重试码白名单内,重试
436
421
  const { retryFlag, retryApiWhiteMap, requestRetryCount } = wx.tmsFlagMap || {};
437
422
  const isWhiteApi = retryApiWhiteMap?.home === 'all' ? true : (retryApiWhiteMap?.home || []).includes(path);
438
423
  const canRetry = errno => RETRY_WX_ERR_NOS.includes(errno) && isWhiteApi;
@@ -589,7 +574,7 @@ export default class Request {
589
574
  * @returns {Promise} 返回 wx.request 的 requestTask
590
575
  */
591
576
  async createStreamRequestTask(path, params = {}) {
592
- const { param = {}, method = 'POST', header = {}, callbacks = {}, timeout = 60000 } = params;
577
+ const { param = {}, method = 'POST', header = {}, callbacks = {} } = params;
593
578
  const requestParam = await composeParam(param, this.withAuth, this.baseParam);
594
579
  const data = sign(requestParam, this.secretKey);
595
580
 
@@ -601,7 +586,6 @@ export default class Request {
601
586
  header,
602
587
  method,
603
588
  data,
604
- timeout,
605
589
  enableHttp2: this.enableHttp2,
606
590
  enableChunked: this.enableChunked,
607
591
  responseType: this.responseType,
@@ -635,9 +619,6 @@ const isPathNeedRetryLogin = (path) => {
635
619
  return noRetryPaths.every(noRetryPath => !path.includes(noRetryPath));
636
620
  };
637
621
 
638
- // 判断网关框架码是否需要重试
639
- const isGatewayCodeNeedRetry = gatewayCode => (gatewayCode > 0 && gatewayCode <= 999) || +gatewayCode === 5000;
640
-
641
622
  let refreshPromise;
642
623
  async function loginRefresh() {
643
624
  if (!refreshPromise) {