@tmsfe/tms-core 0.0.174 → 0.0.176

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.176",
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,23 @@ 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
+ trace_id: traceparent,
121
+ });
113
122
  const { header: resHeader, data: resData } = result;
114
123
  const { success: decSuccess, msg, res } = await encryptUtil
115
124
  .resDecrypt(traceId, resHeader, resData, cryptoKeyInfo);
125
+ // 解密响应耗时
126
+ wx.reportEvent?.('cost_encrypt_statistic', {
127
+ period: 'decrypt_data',
128
+ cost: Date.now() - startTime,
129
+ path: originalOptions.url,
130
+ trace_id: traceparent,
131
+ });
116
132
  if (res.retry) { // 解密出现问题,需要明文重试
117
133
  util.reportFunc(url, traceparent, `解密失败:${msg}`);
118
134
  const newTraceparent = genTraceparent();
@@ -124,6 +140,13 @@ function proxyWxRequest(): void {
124
140
  msg && util.reportFunc(url, traceId, msg);
125
141
  });
126
142
  success?.call(this, res);
143
+ // 接口重试耗时
144
+ wx.reportEvent?.('cost_encrypt_statistic', {
145
+ period: 'retry_request',
146
+ cost: Date.now() - startTime,
147
+ path: originalOptions.url,
148
+ trace_id: traceparent,
149
+ });
127
150
  },
128
151
  header: { ...header, Traceparent: newTraceparent },
129
152
  });
@@ -135,6 +158,13 @@ function proxyWxRequest(): void {
135
158
  msg && util.reportFunc(url, traceId, msg);
136
159
  });
137
160
  success?.call(this, res);
161
+ // 响应回调耗时
162
+ wx.reportEvent?.('cost_encrypt_statistic', {
163
+ period: 'response_callback',
164
+ cost: Date.now() - startTime,
165
+ path: originalOptions.url,
166
+ trace_id: traceparent,
167
+ });
138
168
  } else { // 不支持明文重试,且解密失败
139
169
  util.reportFunc(url, traceparent, `解密失败:${msg}`);
140
170
  fail?.call(this, new Error(msg));
@@ -153,6 +183,13 @@ function proxyWxRequest(): void {
153
183
  completeResolver(res);
154
184
  },
155
185
  });
186
+ // 加密请求准备耗时
187
+ wx.reportEvent?.('cost_encrypt_statistic', {
188
+ period: 'before_request',
189
+ cost: Date.now() - startTime,
190
+ path: url,
191
+ trace_id: traceparent,
192
+ });
156
193
  },
157
194
  });
158
195
  }
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 () => {