@alipay/ams-checkout 0.0.1755258862-dev.4 → 0.0.1755258862-dev.5

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.
@@ -12,8 +12,37 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
12
12
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
13
  import axios from 'axios';
14
14
  import { ServiceProvider } from '..';
15
- import { errorEnum } from "./deps";
16
- import { appId, device, fomatGetwayError, get, hostSignMap, isPC, lightSandboxMap, queryParse, requestHost, safeJson, sdkVersion, sofaId, tntInstId } from "./deps";
15
+ import { lightSandboxMap, appId, hostSignMap, requestHost, sofaId, tntInstId } from "../../../config/request";
16
+ import { device, isPC, queryParse, safeJson } from "../../../util";
17
+ import { fomatGetwayError } from "../../../request/utils";
18
+ import { get } from "../../../util/get";
19
+ import { sdkVersion } from "../../../config/index";
20
+ import { errorEnum } from "../../../types";
21
+
22
+ // import { errorEnum } from './deps';
23
+ // import {
24
+ // appId,
25
+ // device,
26
+ // fomatGetwayError,
27
+ // get,
28
+ // hostSignMap,
29
+ // IoptionsParams,
30
+ // isPC,
31
+ // lightSandboxMap,
32
+ // LogExtra,
33
+ // LogPayload,
34
+ // LogService,
35
+ // PaymentContext,
36
+ // queryParse,
37
+ // RequestConfig,
38
+ // requestHost,
39
+ // safeJson,
40
+ // SDKMetaData,
41
+ // sdkVersion,
42
+ // Service,
43
+ // sofaId,
44
+ // tntInstId,
45
+ // } from './deps'
17
46
 
18
47
  /**
19
48
  * @author congle.zzq <congle.zzq@alipay.com>
@@ -46,18 +75,13 @@ export var RequesterService = /*#__PURE__*/function () {
46
75
  key: "request",
47
76
  value: (function () {
48
77
  var _request = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(requestData, options) {
49
- var logger, envInfo, _data, startTime, traceId, myRequest, _yield$myRequest, data, headers, resData, handleGetWayError, errorMessage, errorCode, _error$message, _error, timeoutCode, _errorCode;
78
+ var envInfo, _data, startTime, traceId, myRequest, _yield$myRequest, data, headers, resData, handleGetWayError, errorMessage, errorCode, _error$message, _error, timeoutCode, _errorCode;
50
79
  return _regeneratorRuntime().wrap(function _callee$(_context) {
51
80
  while (1) switch (_context.prev = _context.next) {
52
81
  case 0:
53
- console.log('[DEBUG] request start', requestData, options);
54
- logger = ServiceProvider.getInstance(this.instanceId).getService('Log');
55
- logger.logInfo({
56
- title: '[DEBUG] request start',
57
- msg: JSON.stringify({
58
- requestData: requestData,
59
- options: options
60
- })
82
+ console.log('[DEBUG] - request start', {
83
+ requestData: requestData,
84
+ options: options
61
85
  });
62
86
  envInfo = this.getEnvInfo(options);
63
87
  _data = [_objectSpread(_objectSpread({}, requestData), {}, {
@@ -68,65 +92,31 @@ export var RequesterService = /*#__PURE__*/function () {
68
92
  })];
69
93
  startTime = Date.now();
70
94
  traceId = '';
71
- _context.prev = 7;
72
- console.log('[DEBUG] createRequestInstance start');
73
- logger.logInfo({
74
- title: '[DEBUG] createRequestInstance start'
75
- });
95
+ _context.prev = 5;
96
+ console.log('[DEBUG] - createRequestInstance start', options);
76
97
  myRequest = this.createRequestInstance(options);
77
- console.log('[DEBUG] createRequestInstance completed', myRequest);
78
- logger.logInfo({
79
- title: '[DEBUG] createRequestInstance completed',
80
- msg: JSON.stringify({
81
- myRequest: myRequest
82
- })
83
- });
84
- console.log('[DEBUG] myRequest start');
85
- logger.logInfo({
86
- title: '[DEBUG] myRequest start'
87
- });
88
- _context.next = 17;
98
+ console.log('[DEBUG] - createRequestInstance completed', myRequest);
99
+ console.log('[DEBUG] - request payload:', _data);
100
+ _context.next = 12;
89
101
  return myRequest({
90
102
  data: _data
91
103
  });
92
- case 17:
104
+ case 12:
93
105
  _yield$myRequest = _context.sent;
94
106
  data = _yield$myRequest.data;
95
107
  headers = _yield$myRequest.headers;
96
- console.log('[DEBUG] myRequest completed', data, headers);
97
- logger.logInfo({
98
- title: '[DEBUG] myRequest completed',
99
- msg: JSON.stringify({
100
- data: data,
101
- headers: headers
102
- })
103
- });
104
108
  resData = data || {};
109
+ console.log('[DEBUG] - request response:', {
110
+ resData: resData,
111
+ headers: headers
112
+ });
105
113
  traceId = get(headers, 'Mgw-TraceId') || get(headers, 'mgw-traceid', '');
106
114
  resData.traceId = traceId || '';
107
- console.log('[DEBUG] handleGetWayError start');
108
- logger.logInfo({
109
- title: '[DEBUG] handleGetWayError start'
110
- });
111
115
  handleGetWayError = fomatGetwayError(headers, traceId);
112
- console.log('[DEBUG] handleGetWayError completed', handleGetWayError);
113
- logger.logInfo({
114
- title: '[DEBUG] handleGetWayError completed',
115
- msg: JSON.stringify({
116
- handleGetWayError: handleGetWayError
117
- })
118
- });
119
116
  if (!(handleGetWayError !== null && handleGetWayError !== void 0 && handleGetWayError.errorCode)) {
120
- _context.next = 39;
117
+ _context.next = 25;
121
118
  break;
122
119
  }
123
- console.log('[DEBUG] handleGetWayError errorCode', handleGetWayError === null || handleGetWayError === void 0 ? void 0 : handleGetWayError.errorCode);
124
- logger.logInfo({
125
- title: '[DEBUG] handleGetWayError errorCode',
126
- msg: JSON.stringify({
127
- errorCode: handleGetWayError === null || handleGetWayError === void 0 ? void 0 : handleGetWayError.errorCode
128
- })
129
- });
130
120
  errorMessage = (resData === null || resData === void 0 ? void 0 : resData.errorMessage) || (handleGetWayError === null || handleGetWayError === void 0 ? void 0 : handleGetWayError.errorMessage);
131
121
  errorCode = handleGetWayError === null || handleGetWayError === void 0 ? void 0 : handleGetWayError.errorCode;
132
122
  this.reportRequestTimeCost({
@@ -139,25 +129,12 @@ export var RequesterService = /*#__PURE__*/function () {
139
129
  msg: errorMessage,
140
130
  traceId: traceId
141
131
  });
142
- console.log('[DEBUG] handleGetWayError error', {
143
- errorMessage: errorMessage,
144
- errorCode: errorCode,
145
- success: false
146
- });
147
- logger.logInfo({
148
- title: '[DEBUG] handleGetWayError error',
149
- msg: JSON.stringify({
150
- errorMessage: errorMessage,
151
- errorCode: errorCode,
152
- success: false
153
- })
154
- });
155
132
  throw new Error(JSON.stringify({
156
133
  errorMessage: errorMessage,
157
134
  errorCode: errorCode,
158
135
  success: false
159
136
  }));
160
- case 39:
137
+ case 25:
161
138
  this.reportRequestTimeCost({
162
139
  title: 'a3753.b101271.c388193.d521387',
163
140
  name: options === null || options === void 0 ? void 0 : options['Operation-Type'],
@@ -168,31 +145,17 @@ export var RequesterService = /*#__PURE__*/function () {
168
145
  msg: '',
169
146
  traceId: traceId
170
147
  });
171
- console.log('[DEBUG] request completed', resData);
172
- logger.logInfo({
173
- title: '[DEBUG] request completed',
174
- msg: JSON.stringify({
175
- resData: resData
176
- })
177
- });
178
148
  return _context.abrupt("return", resData);
179
- case 45:
180
- _context.prev = 45;
181
- _context.t0 = _context["catch"](7);
149
+ case 29:
150
+ _context.prev = 29;
151
+ _context.t0 = _context["catch"](5);
152
+ console.log('[DEBUG] - request error:', _context.t0);
182
153
  _error = safeJson(_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message, {
183
154
  success: false,
184
155
  errorCode: errorEnum.SYSTEM,
185
156
  traceId: traceId,
186
157
  errorMessage: _context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message
187
158
  });
188
- console.log('[DEBUG] request error 1', _error, 'Original error:', _context.t0);
189
- logger.logInfo({
190
- title: '[DEBUG] request error 1',
191
- msg: JSON.stringify({
192
- _error: _error,
193
- originalError: _context.t0
194
- })
195
- });
196
159
  timeoutCode = _context.t0 !== null && _context.t0 !== void 0 && (_error$message = _context.t0.message) !== null && _error$message !== void 0 && _error$message.includes('timeout') ? errorEnum.TIMEOUT : '';
197
160
  _errorCode = (_error === null || _error === void 0 ? void 0 : _error.errorCode) || timeoutCode;
198
161
  this.reportRequestTimeCost({
@@ -204,32 +167,17 @@ export var RequesterService = /*#__PURE__*/function () {
204
167
  code: _errorCode,
205
168
  msg: JSON.stringify((_error === null || _error === void 0 ? void 0 : _error.message) || _context.t0)
206
169
  });
207
- console.log('[DEBUG] request error 2', {
208
- success: false,
209
- errorCode: _errorCode,
210
- traceId: traceId,
211
- errorMessage: _error === null || _error === void 0 ? void 0 : _error.message
212
- });
213
- logger.logInfo({
214
- title: '[DEBUG] request error 2',
215
- msg: JSON.stringify({
216
- success: false,
217
- errorCode: _errorCode,
218
- traceId: traceId,
219
- errorMessage: _error === null || _error === void 0 ? void 0 : _error.message
220
- })
221
- });
222
170
  return _context.abrupt("return", Promise.reject({
223
171
  success: false,
224
172
  errorCode: _errorCode,
225
173
  traceId: traceId,
226
174
  errorMessage: _error === null || _error === void 0 ? void 0 : _error.message
227
175
  }));
228
- case 56:
176
+ case 37:
229
177
  case "end":
230
178
  return _context.stop();
231
179
  }
232
- }, _callee, this, [[7, 45]]);
180
+ }, _callee, this, [[5, 29]]);
233
181
  }));
234
182
  function request(_x, _x2) {
235
183
  return _request.apply(this, arguments);
@@ -278,109 +226,41 @@ export var RequesterService = /*#__PURE__*/function () {
278
226
  }, {
279
227
  key: "createRequestInstance",
280
228
  value: function createRequestInstance(options) {
281
- var _options$timeout, _options$withCredenti;
282
- console.log('[DEBUG] createRequestInstance start with options:', {
283
- env: options.env,
284
- 'Operation-Type': options['Operation-Type'],
285
- hostSign: options === null || options === void 0 ? void 0 : options.hostSign,
286
- timeout: options.timeout,
287
- method: options === null || options === void 0 ? void 0 : options.method,
288
- withCredentials: options.withCredentials,
289
- headers: Object.keys(options.headers || {})
290
- });
291
- var logger = ServiceProvider.getInstance(this.instanceId).getService('Log');
292
- logger.logInfo({
293
- title: '[DEBUG] createRequestInstance start',
294
- msg: JSON.stringify({
295
- env: options.env,
296
- 'Operation-Type': options['Operation-Type'],
297
- hostSign: options === null || options === void 0 ? void 0 : options.hostSign,
298
- timeout: options.timeout,
299
- method: options === null || options === void 0 ? void 0 : options.method,
300
- withCredentials: options.withCredentials,
301
- headers: Object.keys(options.headers || {})
302
- })
303
- });
229
+ var _options$timeout, _options$withCredenti, _options$timeout2, _options$withCredenti2;
230
+ console.log('[DEBUG] - createRequestInstance options:', options);
304
231
  var date = new Date(); // 获取当前时间
305
232
  var timestamp = date.getTime(); // 获取时间戳
306
233
  var utcTimestamp = timestamp + date.getTimezoneOffset() * 60 * 1000; // 获取 UTC 时间戳
307
234
  var env = options.env || 'prod';
308
235
  var lightSandboxConfig = lightSandboxMap(options['Operation-Type'], env); // light_sandbox
309
- console.log('[DEBUG] lightSandboxConfig:', lightSandboxConfig);
310
- logger.logInfo({
311
- title: '[DEBUG] lightSandboxConfig',
312
- msg: JSON.stringify(lightSandboxConfig)
313
- });
236
+ console.log('[DEBUG] - createRequestInstance lightSandboxConfig:', lightSandboxConfig);
314
237
  var baseURL = options.baseURL || lightSandboxConfig.baseURL || hostSignMap(options === null || options === void 0 ? void 0 : options.hostSign, env) || requestHost[env];
315
- console.log('[DEBUG] baseURL:', baseURL);
316
- logger.logInfo({
317
- title: '[DEBUG] baseURL',
318
- msg: baseURL
319
- });
320
238
  var _headers = _objectSpread(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
321
239
  appId: lightSandboxConfig.appId || appId,
322
240
  workspaceId: options.env === 'pre' ? 'pre' : 'default'
323
241
  }, "x-cors-".concat(appId.toLowerCase(), "-default"), '1'), "version", '2.0'), 'sofa-group-name', lightSandboxConfig.sofaId || sofaId), 'Operation-Type', lightSandboxConfig['Operation-Type'] || options['Operation-Type'] || ''), 'Client-Time', utcTimestamp), "tntInstId", tntInstId), 'sdk-version', sdkVersion || ''), options.headers);
324
-
242
+ console.log('[DEBUG] - createRequestInstance headers:', _headers);
325
243
  // sandbox 影子链路
326
244
  if (this.sandboxFlag === 'true' || env === 'sandbox') {
327
245
  _headers['load-test'] = true;
328
246
  _headers.sofaPenAttrs = 'instMock=O&loadMode=2';
329
247
  }
330
248
  if (env !== 'dev') delete _headers['sofa-group-name'];
331
- console.log('[DEBUG] request headers keys:', Object.keys(_headers));
332
- logger.logInfo({
333
- title: '[DEBUG] request headers keys',
334
- msg: JSON.stringify(Object.keys(_headers))
335
- });
336
-
337
- // 确保 axios 库正确加载
338
- if (typeof axios === 'undefined') {
339
- console.log('[DEBUG] axios undefined');
340
- logger.logError({
341
- title: '[DEBUG] axios undefined'
342
- });
343
- }
344
- console.log('[DEBUG] axios version:', axios.VERSION);
345
- logger.logInfo({
346
- title: '[DEBUG] axios version',
347
- msg: axios.VERSION
348
- });
349
- var instance = axios.create({
249
+ console.log('[DEBUG] - createRequestInstance config:', {
350
250
  baseURL: baseURL,
351
251
  timeout: (_options$timeout = options.timeout) !== null && _options$timeout !== void 0 ? _options$timeout : 15000,
352
252
  headers: _headers,
353
253
  withCredentials: (_options$withCredenti = options.withCredentials) !== null && _options$withCredenti !== void 0 ? _options$withCredenti : true,
354
254
  method: (options === null || options === void 0 ? void 0 : options.method) || 'POST'
355
255
  });
356
- console.log('[DEBUG] axios instance created with config:', {
357
- baseURL: instance.defaults.baseURL,
358
- timeout: instance.defaults.timeout,
359
- method: instance.defaults.method,
360
- withCredentials: instance.defaults.withCredentials
361
- });
362
- logger.logInfo({
363
- title: '[DEBUG] axios instance created',
364
- msg: JSON.stringify({
365
- baseURL: instance.defaults.baseURL,
366
- timeout: instance.defaults.timeout,
367
- method: instance.defaults.method,
368
- withCredentials: instance.defaults.withCredentials
369
- })
370
- });
371
- console.log('[DEBUG] instance.request', instance.request);
372
- logger.logInfo({
373
- title: '[DEBUG] instance.request',
374
- msg: JSON.stringify(instance.request)
375
- });
376
- console.log('[DEBUG] instance.request.bind(instance)', instance.request.bind(instance));
377
- logger.logInfo({
378
- title: '[DEBUG] instance.request.bind',
379
- msg: JSON.stringify(instance.request.bind(instance))
256
+ var instance = axios.create({
257
+ baseURL: baseURL,
258
+ timeout: (_options$timeout2 = options.timeout) !== null && _options$timeout2 !== void 0 ? _options$timeout2 : 15000,
259
+ headers: _headers,
260
+ withCredentials: (_options$withCredenti2 = options.withCredentials) !== null && _options$withCredenti2 !== void 0 ? _options$withCredenti2 : true,
261
+ method: (options === null || options === void 0 ? void 0 : options.method) || 'POST'
380
262
  });
381
-
382
- // return instance.request;
383
- return instance.request.bind(instance);
263
+ return instance.request;
384
264
  }
385
265
  }]);
386
266
  return RequesterService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1755258862-dev.4",
3
+ "version": "0.0.1755258862-dev.5",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",