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

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,6 +12,18 @@ 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 { 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 { PaymentContext, Service } from '../../index';
20
+ // import { sdkVersion } from '../../../config/index';
21
+ // import type { LogService } from '../log';
22
+ // import type { IoptionsParams, RequestConfig } from '../../../types';
23
+ // import type { LogExtra, LogPayload } from '../log/types';
24
+ // import type { SDKMetaData } from '../../index';
25
+ // import { errorEnum } from '../../../types';
26
+
15
27
  import { errorEnum } from "./deps";
16
28
  import { appId, device, fomatGetwayError, get, hostSignMap, isPC, lightSandboxMap, queryParse, requestHost, safeJson, sdkVersion, sofaId, tntInstId } from "./deps";
17
29
 
@@ -46,18 +58,13 @@ export var RequesterService = /*#__PURE__*/function () {
46
58
  key: "request",
47
59
  value: (function () {
48
60
  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;
61
+ var envInfo, _data, startTime, traceId, myRequest, _yield$myRequest, data, headers, resData, handleGetWayError, errorMessage, errorCode, _error$message, _error, timeoutCode, _errorCode;
50
62
  return _regeneratorRuntime().wrap(function _callee$(_context) {
51
63
  while (1) switch (_context.prev = _context.next) {
52
64
  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
- })
65
+ console.log('[DEBUG] - request start', {
66
+ requestData: requestData,
67
+ options: options
61
68
  });
62
69
  envInfo = this.getEnvInfo(options);
63
70
  _data = [_objectSpread(_objectSpread({}, requestData), {}, {
@@ -68,65 +75,31 @@ export var RequesterService = /*#__PURE__*/function () {
68
75
  })];
69
76
  startTime = Date.now();
70
77
  traceId = '';
71
- _context.prev = 7;
72
- console.log('[DEBUG] createRequestInstance start');
73
- logger.logInfo({
74
- title: '[DEBUG] createRequestInstance start'
75
- });
78
+ _context.prev = 5;
79
+ console.log('[DEBUG] - createRequestInstance start', options);
76
80
  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;
81
+ console.log('[DEBUG] - createRequestInstance completed', myRequest);
82
+ console.log('[DEBUG] - request payload:', _data);
83
+ _context.next = 12;
89
84
  return myRequest({
90
85
  data: _data
91
86
  });
92
- case 17:
87
+ case 12:
93
88
  _yield$myRequest = _context.sent;
94
89
  data = _yield$myRequest.data;
95
90
  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
91
  resData = data || {};
92
+ console.log('[DEBUG] - request response:', {
93
+ resData: resData,
94
+ headers: headers
95
+ });
105
96
  traceId = get(headers, 'Mgw-TraceId') || get(headers, 'mgw-traceid', '');
106
97
  resData.traceId = traceId || '';
107
- console.log('[DEBUG] handleGetWayError start');
108
- logger.logInfo({
109
- title: '[DEBUG] handleGetWayError start'
110
- });
111
98
  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
99
  if (!(handleGetWayError !== null && handleGetWayError !== void 0 && handleGetWayError.errorCode)) {
120
- _context.next = 39;
100
+ _context.next = 25;
121
101
  break;
122
102
  }
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
103
  errorMessage = (resData === null || resData === void 0 ? void 0 : resData.errorMessage) || (handleGetWayError === null || handleGetWayError === void 0 ? void 0 : handleGetWayError.errorMessage);
131
104
  errorCode = handleGetWayError === null || handleGetWayError === void 0 ? void 0 : handleGetWayError.errorCode;
132
105
  this.reportRequestTimeCost({
@@ -139,25 +112,12 @@ export var RequesterService = /*#__PURE__*/function () {
139
112
  msg: errorMessage,
140
113
  traceId: traceId
141
114
  });
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
115
  throw new Error(JSON.stringify({
156
116
  errorMessage: errorMessage,
157
117
  errorCode: errorCode,
158
118
  success: false
159
119
  }));
160
- case 39:
120
+ case 25:
161
121
  this.reportRequestTimeCost({
162
122
  title: 'a3753.b101271.c388193.d521387',
163
123
  name: options === null || options === void 0 ? void 0 : options['Operation-Type'],
@@ -168,31 +128,17 @@ export var RequesterService = /*#__PURE__*/function () {
168
128
  msg: '',
169
129
  traceId: traceId
170
130
  });
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
131
  return _context.abrupt("return", resData);
179
- case 45:
180
- _context.prev = 45;
181
- _context.t0 = _context["catch"](7);
132
+ case 29:
133
+ _context.prev = 29;
134
+ _context.t0 = _context["catch"](5);
135
+ console.log('[DEBUG] - request error:', _context.t0);
182
136
  _error = safeJson(_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message, {
183
137
  success: false,
184
138
  errorCode: errorEnum.SYSTEM,
185
139
  traceId: traceId,
186
140
  errorMessage: _context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message
187
141
  });
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
142
  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
143
  _errorCode = (_error === null || _error === void 0 ? void 0 : _error.errorCode) || timeoutCode;
198
144
  this.reportRequestTimeCost({
@@ -204,32 +150,17 @@ export var RequesterService = /*#__PURE__*/function () {
204
150
  code: _errorCode,
205
151
  msg: JSON.stringify((_error === null || _error === void 0 ? void 0 : _error.message) || _context.t0)
206
152
  });
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
153
  return _context.abrupt("return", Promise.reject({
223
154
  success: false,
224
155
  errorCode: _errorCode,
225
156
  traceId: traceId,
226
157
  errorMessage: _error === null || _error === void 0 ? void 0 : _error.message
227
158
  }));
228
- case 56:
159
+ case 37:
229
160
  case "end":
230
161
  return _context.stop();
231
162
  }
232
- }, _callee, this, [[7, 45]]);
163
+ }, _callee, this, [[5, 29]]);
233
164
  }));
234
165
  function request(_x, _x2) {
235
166
  return _request.apply(this, arguments);
@@ -278,109 +209,41 @@ export var RequesterService = /*#__PURE__*/function () {
278
209
  }, {
279
210
  key: "createRequestInstance",
280
211
  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
- });
212
+ var _options$timeout, _options$withCredenti, _options$timeout2, _options$withCredenti2;
213
+ console.log('[DEBUG] - createRequestInstance options:', options);
304
214
  var date = new Date(); // 获取当前时间
305
215
  var timestamp = date.getTime(); // 获取时间戳
306
216
  var utcTimestamp = timestamp + date.getTimezoneOffset() * 60 * 1000; // 获取 UTC 时间戳
307
217
  var env = options.env || 'prod';
308
218
  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
- });
219
+ console.log('[DEBUG] - createRequestInstance lightSandboxConfig:', lightSandboxConfig);
314
220
  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
221
  var _headers = _objectSpread(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
321
222
  appId: lightSandboxConfig.appId || appId,
322
223
  workspaceId: options.env === 'pre' ? 'pre' : 'default'
323
224
  }, "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
-
225
+ console.log('[DEBUG] - createRequestInstance headers:', _headers);
325
226
  // sandbox 影子链路
326
227
  if (this.sandboxFlag === 'true' || env === 'sandbox') {
327
228
  _headers['load-test'] = true;
328
229
  _headers.sofaPenAttrs = 'instMock=O&loadMode=2';
329
230
  }
330
231
  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({
232
+ console.log('[DEBUG] - createRequestInstance config:', {
350
233
  baseURL: baseURL,
351
234
  timeout: (_options$timeout = options.timeout) !== null && _options$timeout !== void 0 ? _options$timeout : 15000,
352
235
  headers: _headers,
353
236
  withCredentials: (_options$withCredenti = options.withCredentials) !== null && _options$withCredenti !== void 0 ? _options$withCredenti : true,
354
237
  method: (options === null || options === void 0 ? void 0 : options.method) || 'POST'
355
238
  });
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))
239
+ var instance = axios.create({
240
+ baseURL: baseURL,
241
+ timeout: (_options$timeout2 = options.timeout) !== null && _options$timeout2 !== void 0 ? _options$timeout2 : 15000,
242
+ headers: _headers,
243
+ withCredentials: (_options$withCredenti2 = options.withCredentials) !== null && _options$withCredenti2 !== void 0 ? _options$withCredenti2 : true,
244
+ method: (options === null || options === void 0 ? void 0 : options.method) || 'POST'
380
245
  });
381
-
382
- // return instance.request;
383
- return instance.request.bind(instance);
246
+ return instance.request;
384
247
  }
385
248
  }]);
386
249
  return RequesterService;
@@ -101,6 +101,8 @@ var PreloadHelper = /*#__PURE__*/function () {
101
101
  webAppVersion: ''
102
102
  };
103
103
  sdkMetaData.webAppVersion = getWebAppVersion(sdkMetaData);
104
+ // TEST: Testing Purpose
105
+ sdkMetaData.webAppVersion = "1.31.0";
104
106
  var preloadUrl = getWebAppUrl({
105
107
  environment: environment,
106
108
  sdkMetaData: sdkMetaData,
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.6",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",