@be-link/ecommerce-client-backend-service-node-sdk 0.1.30 → 0.1.32
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/utils/http-copy.d.ts +0 -0
- package/utils/http-copy.js +90 -0
package/package.json
CHANGED
|
File without changes
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import stringify from 'safe-stable-stringify'
|
|
3
|
+
// import axios, { AxiosError } from 'axios'
|
|
4
|
+
// import { v4 as uuidV4 } from 'uuid'
|
|
5
|
+
// import axiosRetry from 'axios-retry'
|
|
6
|
+
// import { requestContext } from '@fastify/request-context'
|
|
7
|
+
//
|
|
8
|
+
// declare module '@fastify/request-context' {
|
|
9
|
+
// interface RequestContextData {
|
|
10
|
+
// requestId?: string
|
|
11
|
+
// traceMessageId?: string
|
|
12
|
+
// }
|
|
13
|
+
// }
|
|
14
|
+
// axiosRetry(axios, {
|
|
15
|
+
// retries: 1,
|
|
16
|
+
// retryCondition(error) {
|
|
17
|
+
// return error.response?.status === 502
|
|
18
|
+
// },
|
|
19
|
+
// retryDelay: (retryCount) => {
|
|
20
|
+
// console.info(`retryCount: ${retryCount}, retryDelay: ${retryCount * 500}`)
|
|
21
|
+
// return retryCount * 500
|
|
22
|
+
// },
|
|
23
|
+
// onRetry(retryCount, error, requestConfig) {
|
|
24
|
+
// console.info(
|
|
25
|
+
// `retryCount: ${retryCount}, onRetry: ${error.message}, requestHeader: ${stringify(
|
|
26
|
+
// requestConfig.headers,
|
|
27
|
+
// )}`,
|
|
28
|
+
// )
|
|
29
|
+
// },
|
|
30
|
+
// })
|
|
31
|
+
//
|
|
32
|
+
// type ResponseData = {
|
|
33
|
+
// data: any
|
|
34
|
+
// success: boolean
|
|
35
|
+
// requestId: string
|
|
36
|
+
// message: string
|
|
37
|
+
// errorType: string
|
|
38
|
+
// }
|
|
39
|
+
//
|
|
40
|
+
// export async function callApi<T extends (...args: any[]) => Promise<any>>(
|
|
41
|
+
// url: string,
|
|
42
|
+
// request?: Parameters<T>[0],
|
|
43
|
+
// ): Promise<Awaited<ReturnType<T>>> {
|
|
44
|
+
// const requestId =
|
|
45
|
+
// requestContext.get('requestId') || requestContext.get('traceMessageId') || uuidV4()
|
|
46
|
+
// try {
|
|
47
|
+
// console.info(
|
|
48
|
+
// `准备发起ecommerce-client-backend-service请求[${requestId}]: ${url}, 参数: ${stringify(
|
|
49
|
+
// request,
|
|
50
|
+
// )}`,
|
|
51
|
+
// )
|
|
52
|
+
// const response = await axios.post(url, request || {}, {
|
|
53
|
+
// headers: { 'x-request-id': requestId },
|
|
54
|
+
// })
|
|
55
|
+
// const responseData = response.data as ResponseData
|
|
56
|
+
// return responseData.data
|
|
57
|
+
// } catch (error: any) {
|
|
58
|
+
// const axiosError = error as AxiosError
|
|
59
|
+
// if (axiosError.response) {
|
|
60
|
+
// const response = axiosError.response
|
|
61
|
+
// const data = response.data as ResponseData
|
|
62
|
+
// console.error(
|
|
63
|
+
// `ecommerce-client-backend-service 异常: ${axiosError.message},requestId: ${requestId}`,
|
|
64
|
+
// )
|
|
65
|
+
// console.info('响应信息', data.message)
|
|
66
|
+
// console.error('异常堆栈', stringify(error.stack))
|
|
67
|
+
// throw error
|
|
68
|
+
// }
|
|
69
|
+
// // 调用dns模块解析url
|
|
70
|
+
// const dns = await import('dns')
|
|
71
|
+
// const dnsPromise = new Promise((resolve, reject) => {
|
|
72
|
+
// const lookupRes = dns.lookup(url, (err, address) => {
|
|
73
|
+
// if (err) {
|
|
74
|
+
// console.error(err.message)
|
|
75
|
+
// reject(err)
|
|
76
|
+
// }
|
|
77
|
+
// console.info(`lookup: ${stringify(lookupRes)}`)
|
|
78
|
+
// resolve(address)
|
|
79
|
+
// })
|
|
80
|
+
// })
|
|
81
|
+
// try {
|
|
82
|
+
// const address = await dnsPromise
|
|
83
|
+
// console.info(`address: ${stringify(address)}`)
|
|
84
|
+
// } catch (error) {
|
|
85
|
+
// console.info(`error: ${stringify(error)}`)
|
|
86
|
+
// }
|
|
87
|
+
// console.error(`ecommerce-client-backend-service 未知异常: ${axiosError.message}`, error.stack)
|
|
88
|
+
// throw error
|
|
89
|
+
// }
|
|
90
|
+
// }
|