@tmsfe/tms-core 0.0.174 → 0.0.175

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.174",
3
+ "version": "0.0.175",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -52,6 +52,7 @@ function proxyWxRequest(): void {
52
52
  enumerable: true,
53
53
  configurable: true,
54
54
  value(options: any) {
55
+ const startTime = Date.now();
55
56
  const { url, method, data, header = {}, success, fail, complete, dataType, responseType } = options;
56
57
  const traceparent = genTraceparent();
57
58
  const traceId = traceparent.split('-')[1];
@@ -82,7 +83,8 @@ function proxyWxRequest(): void {
82
83
  ...originalOptions,
83
84
  success: async (res) => {
84
85
  const {
85
- success: dealSuccess, msg, res: needDealHeader } = encryptUtil.dealRes(url, traceId, res.header, formatData);
86
+ success: dealSuccess,
87
+ msg, res: needDealHeader } = encryptUtil.dealRes(url, traceId, res.header, formatData);
86
88
  // 性能埋点接口不走验签逻辑
87
89
  if (dealSuccess) {
88
90
  needDealHeader && encryptUtil.dealEncryptionSwitch(url, traceId, res.header).then((msg) => {
@@ -110,9 +112,21 @@ function proxyWxRequest(): void {
110
112
  dataType: '其他',
111
113
  responseType: 'arraybuffer',
112
114
  success: async (result) => {
115
+ // 网络响应耗时
116
+ wx.reportEvent?.('cost_encrypt_statistic', {
117
+ period: 'receive_data',
118
+ cost: Date.now() - startTime,
119
+ path: originalOptions.url,
120
+ });
113
121
  const { header: resHeader, data: resData } = result;
114
122
  const { success: decSuccess, msg, res } = await encryptUtil
115
123
  .resDecrypt(traceId, resHeader, resData, cryptoKeyInfo);
124
+ // 解密响应耗时
125
+ wx.reportEvent?.('cost_encrypt_statistic', {
126
+ period: 'decrypt_data',
127
+ cost: Date.now() - startTime,
128
+ path: originalOptions.url,
129
+ });
116
130
  if (res.retry) { // 解密出现问题,需要明文重试
117
131
  util.reportFunc(url, traceparent, `解密失败:${msg}`);
118
132
  const newTraceparent = genTraceparent();
@@ -124,6 +138,12 @@ function proxyWxRequest(): void {
124
138
  msg && util.reportFunc(url, traceId, msg);
125
139
  });
126
140
  success?.call(this, res);
141
+ // 接口重试耗时
142
+ wx.reportEvent?.('cost_encrypt_statistic', {
143
+ period: 'retry_request',
144
+ cost: Date.now() - startTime,
145
+ path: originalOptions.url,
146
+ });
127
147
  },
128
148
  header: { ...header, Traceparent: newTraceparent },
129
149
  });
@@ -135,6 +155,12 @@ function proxyWxRequest(): void {
135
155
  msg && util.reportFunc(url, traceId, msg);
136
156
  });
137
157
  success?.call(this, res);
158
+ // 响应回调耗时
159
+ wx.reportEvent?.('cost_encrypt_statistic', {
160
+ period: 'response_callback',
161
+ cost: Date.now() - startTime,
162
+ path: originalOptions.url,
163
+ });
138
164
  } else { // 不支持明文重试,且解密失败
139
165
  util.reportFunc(url, traceparent, `解密失败:${msg}`);
140
166
  fail?.call(this, new Error(msg));
@@ -153,6 +179,12 @@ function proxyWxRequest(): void {
153
179
  completeResolver(res);
154
180
  },
155
181
  });
182
+ // 加密请求准备耗时
183
+ wx.reportEvent?.('cost_encrypt_statistic', {
184
+ period: 'before_request',
185
+ cost: Date.now() - startTime,
186
+ path: url,
187
+ });
156
188
  },
157
189
  });
158
190
  }
package/src/env.js CHANGED
@@ -30,10 +30,10 @@ const getAuthInfoQueue = [];
30
30
  * @example
31
31
  * setAuthInfo({
32
32
  firstLogin: 0
33
- openId: "ou8xs5Uo4MHCETZ_P7IUwOAxvr-M"
34
- token: "d8ffecd9317376bd1de3b49e1fa0e3bb"
35
- uid: "407210826"
36
- unionId: "oFghpwpqGK18ixIlNGy34Y28gCb0"
33
+ openId: "xxx"
34
+ token: "xxx"
35
+ uid: "xxx"
36
+ unionId: "xxx"
37
37
  * })
38
38
  */
39
39
  export const setAuthInfo = (authInfo, err) => {
@@ -54,10 +54,10 @@ export const setAuthInfo = (authInfo, err) => {
54
54
  * const data = await getAuthInfo()
55
55
  {
56
56
  firstLogin: 0 // 是否第一次登录
57
- openId: "ou8xs5Uo4MHCETZ_P7IUwOAxvr-M"
58
- token: "d8ffecd9317376bd1de3b49e1fa0e3bb"
59
- uid: "407210826"
60
- unionId: "oFghpwpqGK18ixIlNGy34Y28gCb0"
57
+ openId: "xxx"
58
+ token: "xxx"
59
+ uid: "xxx"
60
+ unionId: "xxx"
61
61
  }
62
62
  */
63
63
  export const getAuthInfo = async () => {