@conecli/cone-render 0.10.1-shop-beta.5 → 0.10.1-shop3.0

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.
Files changed (37) hide show
  1. package/dist/api/index.ts +1 -1
  2. package/dist/common/const.ts +1 -1
  3. package/dist/common/index.h5.ts +1 -1
  4. package/dist/common/index.jd.ts +1 -1
  5. package/dist/common/index.ts +1 -1
  6. package/dist/common/index.weapp.ts +1 -1
  7. package/dist/common/pageType.ts +1 -1
  8. package/dist/common/sgmCustomCode.ts +1 -1
  9. package/dist/components/base/CustomVideo/common.ts +1 -0
  10. package/dist/components/base/CustomVideo/index.tsx +1 -1
  11. package/dist/components/base/LazyLoadImage/index.h5.module.scss +8 -4
  12. package/dist/components/base/LazyLoadImage/index.h5.tsx +1 -1
  13. package/dist/components/base/Price/Base/index.tsx +1 -1
  14. package/dist/components/base/Price/Double/index.tsx +1 -1
  15. package/dist/components/floorItem.tsx +1 -1
  16. package/dist/components/isv/Floor/index.tsx +1 -1
  17. package/dist/interface/component.ts +1 -1
  18. package/dist/interface/jumpEventReport.ts +1 -1
  19. package/dist/interface/service.ts +1 -1
  20. package/dist/jumpEventReport/index.weapp.ts +1 -1
  21. package/dist/jumpEventReport/jumpUrlConfig/base.ts +1 -1
  22. package/dist/jumpEventReport/logEventConfig.ts +1 -1
  23. package/dist/modules/ContainerFloorList/index.h5.tsx +1 -1
  24. package/dist/modules/ContainerFloorList/index.tsx +1 -1
  25. package/dist/open/api/util.ts +1 -1
  26. package/dist/service/http/colorSign.ts +1 -1
  27. package/dist/service/http/h5Http.ts +1 -0
  28. package/dist/service/http/index.h5.ts +1 -0
  29. package/dist/service/requestServer.h5.ts +1 -0
  30. package/dist/service/requestServer.ts +1 -1
  31. package/dist/utils/connectNativeJsBridge.ts +1 -1
  32. package/dist/utils/h5Utils.ts +1 -1
  33. package/dist/utils/index.h5.ts +1 -1
  34. package/dist/utils/index.ts +1 -1
  35. package/dist/utils/index.weapp.ts +1 -1
  36. package/dist/utils/utils.ts +1 -1
  37. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ import Taro from '@tarojs/taro'
2
  isSupportHybridHttpRequest,
1
3
  draInterfaceCustomReport,
2
4
  draBusinessCustomReport,
3
5
  jsonHeader = 'application/json;charset=utf-8',
4
6
  formDataHeader = 'application/x-www-form-urlencoded',
5
7
  HYBRID: 'httpRequest_hybrid',
6
8
  TARO: 'httpRequest_taro',
7
9
  #requestTimeStamp: number
8
10
  #responseTimeStamp: number
9
11
  #getResTimeStamp: number
10
12
  #reportType: string
11
13
  #callbackFunction: string
12
14
 
13
15
  async request({
14
16
  url,
15
17
  method = 'POST',
16
18
  timeout = 7000,
17
19
  isColorVerify = false,
18
20
  ...otherOptions
19
21
  }): Promise<Taro.request.SuccessCallbackResult<any>> {
20
22
  const { header: otherHeader, ...otherOpts } = otherOptions
21
23
  const header = {
22
24
  'content-type':
23
25
  method === 'POST'
24
26
  ? RequestHeaderContentType.formDataHeader
25
27
  : RequestHeaderContentType.jsonHeader,
26
28
  ...otherHeader,
27
29
  }
28
30
  let getRequestUrl = url
29
31
  let requestTask
30
32
  const data = otherOpts?.data
31
33
  const isGatewayRequest =
32
34
  url === this.api.apiFunc && typeof data === 'object'
33
35
  if (isGatewayRequest) {
34
36
  getRequestUrl = this._handleSpecialGatewayUrl(url)
35
37
  const shouldUseHybridRequest = this._shouldUseHybridRequest()
36
38
  if (shouldUseHybridRequest) {
37
39
  requestTask = this._hybridRequest(getRequestUrl, data)
38
40
  } else {
39
41
  otherOpts.data = await this._prepareGatewayReqData(data, isColorVerify)
40
42
  requestTask = this._taroRequest(
41
43
  getRequestUrl,
42
44
  otherOpts,
43
45
  method,
44
46
  timeout,
45
47
  header,
46
48
  )
47
49
  }
48
50
  } else {
49
51
  requestTask = this._taroRequest(
50
52
  getRequestUrl,
51
53
  otherOpts,
52
54
  method,
53
55
  timeout,
54
56
  header,
55
57
  )
56
58
  }
57
59
  const requestTimeoutPromise =
58
60
  new Promise<ServiceInterFace.RequestPromiseRes>((resolve) => {
59
61
  setTimeout(() => {
60
62
  resolve({
61
63
  statusCode: 500,
62
64
  resTimeoutState: true,
63
65
  errMsg: 'request timeout',
64
66
  })
65
67
  }, timeout)
66
68
  })
67
69
  return Promise.race([requestTask, requestTimeoutPromise]).then(
68
70
  (res: any) => {
69
71
  if (res && res.statusCode === 500 && res.resTimeoutState) {
70
72
  if (this.#reportType === HTTP_REQUEST_TYPE.HYBRID) {
71
73
  this._clearFunction(this.#callbackFunction)
72
74
  } else {
73
75
  requestTask.abort && requestTask.abort()
74
76
  }
75
77
  }
76
78
  this._handleReportInterfaceError(url, data, timeout, res)
77
79
  return res
78
80
  },
79
81
  )
80
82
  }
81
83
 
82
84
  _handleSpecialGatewayUrl(url: string): string {
83
85
  if (isPc && window.location.hostname.includes('.jd.hk')) {
84
86
  return this.api.hkApiFunc
85
87
  }
86
88
  if (
87
89
  isJdApp &&
88
90
  window?.shopGlobalSwitch?.dualProtocol &&
89
91
  !window.location.href.includes('jshopx_vconsole')
90
92
  ) {
91
93
  return window?.shopGlobalSwitch?.dualProtocol?.apiTestApp || url
92
94
  }
93
95
  return url
94
96
  }
95
97
 
96
98
  _shouldUseHybridRequest(): boolean {
97
99
  try {
98
100
  if (!isJdApp || !isSupportHybridHttpRequest || isJdAndHarmonyDevice) {
99
101
  return false
100
102
  }
101
103
  const configData = global.getDynamicConfig('hybridHttpSwitch')
102
104
  const { globalOn = false, grayscale = {} } = configData || {}
103
105
  const buildType = process.env.BUILD_TYPE || ''
104
106
  const isInvokeGray = globalOn || grayscale[buildType]
105
107
  console.log(
106
108
  '使用hybrid请求是否命中灰度,isInvokeGray:',
107
109
  isInvokeGray,
108
110
  '获取mpaas配置hybridHttpSwitch原始数据configData',
109
111
  configData,
110
112
  )
111
113
  const hasWindowXWebView = !!window.XWebView
112
114
  return isInvokeGray && hasWindowXWebView
113
115
  } catch (e) {
114
116
  console.log('获取是否使用Hybrid请求出错,e:', e)
115
117
  return false
116
118
  }
117
119
  }
118
120
 
119
121
  _hybridRequest(url: string, data: any): Promise<any> {
120
122
  return new Promise((resolve, reject) => {
121
123
  try {
122
124
  const changeCurrentUrl = url.startsWith('//') ? `https:${url}` : url
123
125
  const reqParams = {
124
126
  url: isIosDevice ? `${changeCurrentUrl}/` : changeCurrentUrl,
125
127
  functionId: data?.functionId,
126
128
  body: data?.body,
127
129
  headerType: '0',
128
130
  }
129
131
  const callbackFunction = this._generateCallbackFunction()
130
132
  this.#callbackFunction = callbackFunction
131
133
  this.#requestTimeStamp = Date.now()
132
134
  this.#reportType = HTTP_REQUEST_TYPE.HYBRID
133
135
  window.XWebView.callNative(
134
136
  'ColorQueryPlugin',
135
137
  'colorRequest',
136
138
  JSON.stringify(reqParams),
137
139
  callbackFunction,
138
140
  '1',
139
141
  )
140
142
  window[callbackFunction] = (result) => {
141
143
  this.#responseTimeStamp = Date.now()
142
144
  try {
143
145
  const resultObj =
144
146
  typeof result === 'string' ? JSON.parse(result) : result
145
147
  resolve(resultObj)
146
148
  } catch (error) {
147
149
  const errMsg = 'hybrid网络请求JSON解析失败, error: ' + error
148
150
  draBusinessCustomReport({
149
151
  type: `${HTTP_REQUEST_TYPE.HYBRID}_jsonParseError`,
150
152
  errMsg,
151
153
  result,
152
154
  })
153
155
  reject({ errMsg })
154
156
  }
155
157
  this._clearFunction(callbackFunction)
156
158
  }
157
159
  } catch (error) {
158
160
  reject({
159
161
  errMsg:
160
162
  'hybrid网络请求,App下调用window.XWebView.callNative出错, error: ' +
161
163
  error,
162
164
  })
163
165
  }
164
166
  })
165
167
  }
166
168
 
167
169
  _generateCallbackFunction() {
168
170
  return `hybridHttpRequestCallback_${Date.now()}_${Math.ceil(
169
171
  Math.random() * 100000,
170
172
  )}`
171
173
  }
172
174
 
173
175
  _clearFunction(functionName: string) {
174
176
  try {
175
177
  delete window[functionName]
176
178
  } catch (e) {
177
179
  window[functionName] = undefined
178
180
  }
179
181
  }
180
182
 
181
183
  async _prepareGatewayReqData(
182
184
  data: any,
183
185
  isColorVerify: boolean,
184
186
  ): Promise<any> {
185
187
  const { functionId } = data
186
188
  console.log('获取当前是否需要color加固', isColorVerify, functionId)
187
189
  if (isColorVerify) {
188
190
  const { h5st } = await colorSign.paramsSign(data)
189
191
  h5st && (data.h5st = encodeURI(h5st))
190
192
  console.log(`${functionId}的apiReq_h5st===>:${h5st}`)
191
193
  }
192
194
  const { jsToken } = await colorSign.getFmInfo()
193
195
  console.log(`${functionId}的api jsToken指纹===>:${jsToken}`)
194
196
  jsToken && (data['x-api-eid-token'] = jsToken)
195
197
  return data
196
198
  }
197
199
 
198
200
  _taroRequest(
199
201
  url: string,
200
202
  otherOpts: any,
201
203
  method: string,
202
204
  timeout: number,
203
205
  header: string,
204
206
  ): Promise<any> {
205
207
  const reqParam = {
206
208
  url,
207
209
  method,
208
210
  timeout,
209
211
  header,
210
212
  credentials: 'include',
211
213
  ...otherOpts,
212
214
  }
213
215
  this.#requestTimeStamp = Date.now()
214
216
  this.#reportType = HTTP_REQUEST_TYPE.TARO
215
217
  return Taro.request(reqParam)
216
218
  }
217
219
 
218
220
  _reportRequestTime(url: string, data: any): void {
219
221
  this.#getResTimeStamp = Date.now()
220
222
  if (this.#reportType === HTTP_REQUEST_TYPE.TARO) {
221
223
  this.#responseTimeStamp = this.#getResTimeStamp
222
224
  }
223
225
  draInterfaceCustomReport(
224
226
  {
225
227
  type: `${this.#reportType}_consumeTime`,
226
228
  url,
227
229
  functionId: data?.functionId,
228
230
  requestTimeStamp: this.#requestTimeStamp,
229
231
  responseTimeStamp: this.#responseTimeStamp,
230
232
  errMsg: `使用${this.#reportType}调用接口请求响应耗时`,
231
233
  source: 'remote',
232
234
  },
233
235
  {
234
236
  consumeTime: `${this.#responseTimeStamp - this.#requestTimeStamp}ms`,
235
237
  getResTime: `${this.#getResTimeStamp - this.#requestTimeStamp}ms`,
236
238
  },
237
239
  )
238
240
  }
239
241
 
240
242
  _handleReportInterfaceError(
241
243
  url: string,
242
244
  reqData: any,
243
245
  timeOut: any,
244
246
  res: any,
245
247
  ): void {
246
248
  const source = 'remote'
247
249
  const requestType = this.#reportType
248
250
  let errorType = ''
249
251
  let subMsg = ''
250
252
  let reportFlag = false
251
253
  if (res) {
252
254
  const { statusCode, data, status, resTimeoutState } = res
253
255
  if (statusCode === 500 && resTimeoutState) {
254
256
  reportFlag = true
255
257
  errorType = 'timeout'
256
258
  subMsg = `接口请求超时${timeOut}ms`
257
259
  } else if ((statusCode === 200 || status === '0') && data) {
258
260
  const resCode = Object.prototype.hasOwnProperty.call(data, 'code')
259
261
  ? Number(data.code)
260
262
  : -1
261
263
  const isSuccess = resCode === 0 || resCode === 200
262
264
  if (!isSuccess) {
263
265
  reportFlag = true
264
266
  errorType = 'dataError'
265
267
  subMsg = '接口请求返回数据异常'
266
268
  }
267
269
  } else {
268
270
  reportFlag = true
269
271
  errorType = 'statusError'
270
272
  subMsg = '接口请求本身异常'
271
273
  }
272
274
  }
273
275
  reportFlag &&
274
276
  draInterfaceCustomReport({
275
277
  subMsg,
276
278
  url,
277
279
  source,
278
280
  requestType,
279
281
  errorType,
280
282
  ...reqData,
281
283
  ...res,
282
284
  })
283
285
  }
@@ -0,0 +1 @@
1
+ import H5Http from "./h5Http"