@tmsfe/tms-core 0.0.144 → 0.0.145

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.144",
3
+ "version": "0.0.145",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
package/src/encrypt.js CHANGED
@@ -56,6 +56,19 @@ function _getEccPublicKey() {
56
56
  function _getEccPublicId() {
57
57
  return wx.$_publicKey && wx.$_publicKey.id;
58
58
  }
59
+ // 检查path是否符合下发的路由前缀
60
+ function _checkPathInEnablePrefix(path) {
61
+ if (wx.$_publicKey && wx.$_publicKey.path === '*') {
62
+ return true;
63
+ }
64
+ const prefixArr = wx.$_publicKey && wx.$_publicKey.path ? wx.$_publicKey.path.split(',').map(item => item.trim()): [];
65
+ for (let i = 0, len = prefixArr.length; i < len; i++) {
66
+ if (path.indexOf(prefixArr[i]) > -1) {
67
+ return true;
68
+ }
69
+ }
70
+ return false;
71
+ }
59
72
 
60
73
  // 获取私钥
61
74
  let privateKeyInfo = null;
@@ -212,12 +225,13 @@ const updateDecryptKey = (publicKeyInfo) => {
212
225
  wx.$_publicKey = null;
213
226
  return;
214
227
  }
215
- const { publicKey, expireDate, id } = publicKeyInfo;
228
+ const { publicKey, expireDate, id, path } = publicKeyInfo;
216
229
  // 1. 存储新的公钥
217
230
  wx.$_publicKey = {
218
231
  publicKey,
219
232
  expireDate,
220
233
  id,
234
+ path,
221
235
  };
222
236
  // 2. 生成新的私钥
223
237
  _getPrivateKeyInfo(true);
@@ -236,6 +250,11 @@ function needsEncryption(url, params) {
236
250
  if (!_getEccPublicKey()) {
237
251
  return false;
238
252
  }
253
+ // 判断是否属于加密白名单, 如果不符合,直接返回false, 如果符合,则走下面的逻辑
254
+ const enablePathPrefix = _checkPathInEnablePrefix(url);
255
+ if (!enablePathPrefix) {
256
+ return false;
257
+ }
239
258
  // 如果是日志上报接口,需要过滤性能日志,不需要加密
240
259
  if (url.indexOf('basic/event/upload') > -1) {
241
260
  if (params.batch?.length === 1 && params.batch[0][31] === 'tms-performance-log') {
package/src/request.js CHANGED
@@ -349,7 +349,8 @@ export default class Request {
349
349
  // wx请求封装成promise
350
350
  async wxRequest(path, method, header = {}, data, needReport, seqId) {
351
351
  if (needReport && path.indexOf('basic/event/upload') < 0) {
352
- reporter.reportPerformance(
352
+ console.log(
353
+ 'tms-performance-log',
353
354
  'request_encrypt_log', 'main', 'send_unencrypt_request', seqId,
354
355
  !!wx.$_publicKey, Request.requestEncryptOpen, path,
355
356
  );
@@ -357,7 +358,7 @@ export default class Request {
357
358
  return new Promise((resolve, reject) => {
358
359
  wx.request({
359
360
  url: path,
360
- header: { ...header, 'X-Trace-Id': seqId },
361
+ header: { ...header, 'X-Seq-Id': seqId },
361
362
  method,
362
363
  data,
363
364
  enableHttp2: true,
@@ -380,7 +381,7 @@ export default class Request {
380
381
  encryptObj.updateDecryptKey(res.data.resData);
381
382
  } catch (e) {
382
383
  encryptObj.updateDecryptKey(null);
383
- reporter.reportPerformance('request_encrypt_log', 'main', 'refresh_encrypt_key_false', e);
384
+ console.log('tms-performance-log', 'request_encrypt_log', 'main', 'refresh_encrypt_key_false', e);
384
385
  }
385
386
  }
386
387
 
@@ -477,7 +478,7 @@ export default class Request {
477
478
  header: encryptHeader, data: encryptData, aesKey,
478
479
  } = encryptObj.reqEncrypt(method, data, header, '');
479
480
  // 2. 发送请求
480
- reporter.reportPerformance('request_encrypt_log', 'main', 'send_encrypt_request', seqId);
481
+ console.log('tms-performance-log', 'request_encrypt_log', 'main', 'send_encrypt_request', seqId, '', '', path);
481
482
  const result = await this.wxRequest(finalUrl, method, encryptHeader, encryptData, false, seqId);
482
483
  const { header: resHeader, data: resData } = result;
483
484
  // 3. 解密响应
@@ -486,11 +487,11 @@ export default class Request {
486
487
  reporter.reportPerformance('request_encrypt_log', 'main', 'local_response_decrypt_fail', seqId);
487
488
  return this.createRequestTask(path, param, method, header, false);
488
489
  }
489
- reporter.reportPerformance('request_encrypt_log', 'main', 'decrypt_response_success', seqId);
490
+ console.log('tms-performance-log', 'request_encrypt_log', 'main', 'decrypt_response_success', seqId);
490
491
  // 4. 处理解密失败的响应
491
492
  const errCodeType = encryptObj.getErrcodeType(decryptData.errCode, decryptData.errMsg);
492
493
  if (errCodeType === encryptObj.reqErrType.pubKeyInvalid) { // 秘钥失效
493
- reporter.reportPerformance(
494
+ console.log('tms-performance-log',
494
495
  'request_encrypt_log', 'main', 'remote_response_decrypt_fail',
495
496
  seqId, decryptData.errCode, retryTimes,
496
497
  );
@@ -501,7 +502,7 @@ export default class Request {
501
502
  return this.createRequestTask(path, param, method, header, encryptSwitch, retryTimes + 1);
502
503
  }
503
504
  if (errCodeType === encryptObj.reqErrType.decryptError) { // 解密失败
504
- reporter.reportPerformance(
505
+ console.log('tms-performance-log',
505
506
  'request_encrypt_log', 'main', 'remote_response_decrypt_fail',
506
507
  seqId, decryptData.errCode, retryTimes,
507
508
  );