@tmsfe/tms-core 0.0.176 → 0.0.178
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 +1 -1
- package/src/encrypt/encrypt-util.ts +3 -3
- package/src/encrypt/index.ts +15 -5
package/package.json
CHANGED
|
@@ -317,7 +317,7 @@ const cryptRuleUtil = {
|
|
|
317
317
|
// 远程加密服务是否开启
|
|
318
318
|
isServerOpen: (): boolean => !!wx.$_publicKey,
|
|
319
319
|
// 检查path是否符合下发的路由前缀
|
|
320
|
-
|
|
320
|
+
pathInUnablePrefix: (path: string): boolean => {
|
|
321
321
|
if (!wx.$_publicKey) {
|
|
322
322
|
return false;
|
|
323
323
|
}
|
|
@@ -392,8 +392,8 @@ const isCryptoRuleMath = (path: string, reqData: any): BaseResp<boolean> => {
|
|
|
392
392
|
if (!cryptRuleUtil.isServerOpen()) {
|
|
393
393
|
return new baseUtil.BaseRespFac(false, false, '服务端加密未开启');
|
|
394
394
|
}
|
|
395
|
-
//
|
|
396
|
-
if (
|
|
395
|
+
// 请求路由满足服务端下发的不加密规则,不走加密
|
|
396
|
+
if (cryptRuleUtil.pathInUnablePrefix(path)) {
|
|
397
397
|
return new baseUtil.BaseRespFac(false, false, '未命中服务端加密规则');
|
|
398
398
|
}
|
|
399
399
|
// 请求接口是加密性能埋点上报接口,不加密
|
package/src/encrypt/index.ts
CHANGED
|
@@ -52,7 +52,7 @@ function proxyWxRequest(): void {
|
|
|
52
52
|
enumerable: true,
|
|
53
53
|
configurable: true,
|
|
54
54
|
value(options: any) {
|
|
55
|
-
|
|
55
|
+
let startTime = Date.now();
|
|
56
56
|
const { url, method, data, header = {}, success, fail, complete, dataType, responseType } = options;
|
|
57
57
|
const traceparent = genTraceparent();
|
|
58
58
|
const traceId = traceparent.split('-')[1];
|
|
@@ -113,22 +113,26 @@ function proxyWxRequest(): void {
|
|
|
113
113
|
responseType: 'arraybuffer',
|
|
114
114
|
success: async (result) => {
|
|
115
115
|
// 网络响应耗时
|
|
116
|
+
let now = Date.now();
|
|
116
117
|
wx.reportEvent?.('cost_encrypt_statistic', {
|
|
117
118
|
period: 'receive_data',
|
|
118
|
-
cost:
|
|
119
|
+
cost: now - startTime,
|
|
119
120
|
path: originalOptions.url,
|
|
120
121
|
trace_id: traceparent,
|
|
121
122
|
});
|
|
123
|
+
startTime = now;
|
|
122
124
|
const { header: resHeader, data: resData } = result;
|
|
123
125
|
const { success: decSuccess, msg, res } = await encryptUtil
|
|
124
126
|
.resDecrypt(traceId, resHeader, resData, cryptoKeyInfo);
|
|
125
127
|
// 解密响应耗时
|
|
128
|
+
now = Date.now();
|
|
126
129
|
wx.reportEvent?.('cost_encrypt_statistic', {
|
|
127
130
|
period: 'decrypt_data',
|
|
128
|
-
cost:
|
|
131
|
+
cost: now - startTime,
|
|
129
132
|
path: originalOptions.url,
|
|
130
133
|
trace_id: traceparent,
|
|
131
134
|
});
|
|
135
|
+
startTime = now;
|
|
132
136
|
if (res.retry) { // 解密出现问题,需要明文重试
|
|
133
137
|
util.reportFunc(url, traceparent, `解密失败:${msg}`);
|
|
134
138
|
const newTraceparent = genTraceparent();
|
|
@@ -141,12 +145,14 @@ function proxyWxRequest(): void {
|
|
|
141
145
|
});
|
|
142
146
|
success?.call(this, res);
|
|
143
147
|
// 接口重试耗时
|
|
148
|
+
const now = Date.now();
|
|
144
149
|
wx.reportEvent?.('cost_encrypt_statistic', {
|
|
145
150
|
period: 'retry_request',
|
|
146
151
|
cost: Date.now() - startTime,
|
|
147
152
|
path: originalOptions.url,
|
|
148
153
|
trace_id: traceparent,
|
|
149
154
|
});
|
|
155
|
+
startTime = now;
|
|
150
156
|
},
|
|
151
157
|
header: { ...header, Traceparent: newTraceparent },
|
|
152
158
|
});
|
|
@@ -159,12 +165,14 @@ function proxyWxRequest(): void {
|
|
|
159
165
|
});
|
|
160
166
|
success?.call(this, res);
|
|
161
167
|
// 响应回调耗时
|
|
168
|
+
const now = Date.now();
|
|
162
169
|
wx.reportEvent?.('cost_encrypt_statistic', {
|
|
163
170
|
period: 'response_callback',
|
|
164
|
-
cost:
|
|
171
|
+
cost: now - startTime,
|
|
165
172
|
path: originalOptions.url,
|
|
166
173
|
trace_id: traceparent,
|
|
167
174
|
});
|
|
175
|
+
startTime = now;
|
|
168
176
|
} else { // 不支持明文重试,且解密失败
|
|
169
177
|
util.reportFunc(url, traceparent, `解密失败:${msg}`);
|
|
170
178
|
fail?.call(this, new Error(msg));
|
|
@@ -184,12 +192,14 @@ function proxyWxRequest(): void {
|
|
|
184
192
|
},
|
|
185
193
|
});
|
|
186
194
|
// 加密请求准备耗时
|
|
195
|
+
const now = Date.now();
|
|
187
196
|
wx.reportEvent?.('cost_encrypt_statistic', {
|
|
188
197
|
period: 'before_request',
|
|
189
|
-
cost:
|
|
198
|
+
cost: now - startTime,
|
|
190
199
|
path: url,
|
|
191
200
|
trace_id: traceparent,
|
|
192
201
|
});
|
|
202
|
+
startTime = now;
|
|
193
203
|
},
|
|
194
204
|
});
|
|
195
205
|
}
|