@alipay/ams-checkout 2.0.2 → 2.0.3

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.
@@ -369,7 +369,7 @@ var ElementController = /*#__PURE__*/function () {
369
369
  _context4.next = 11;
370
370
  return new Promise( /*#__PURE__*/function () {
371
371
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
372
- var that, recordResultCallback, params, processStep, _yield$_this3$onValid2, data, errorResult;
372
+ var that, recordResultCallback, params, processStep, _yield$_this3$onValid2, data, errorString, errorResult;
373
373
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
374
374
  while (1) switch (_context3.prev = _context3.next) {
375
375
  case 0:
@@ -458,14 +458,16 @@ var ElementController = /*#__PURE__*/function () {
458
458
  recordResult = data;
459
459
  recordResultCallback(recordResult);
460
460
  case 21:
461
- _context3.next = 29;
461
+ _context3.next = 30;
462
462
  break;
463
463
  case 23:
464
464
  _context3.prev = 23;
465
465
  _context3.t0 = _context3["catch"](2);
466
+ // 修复error为{}空对象的问题,上报stack&message
467
+ errorString = JSON.stringify(_context3.t0, Object.getOwnPropertyNames(_context3.t0));
466
468
  errorResult = {
467
469
  error: _objectSpread(_objectSpread({}, ERRORMESSAGE.ERR_DATA_STRUCT_UNRECOGNIZED), {}, {
468
- context: JSON.stringify(_context3.t0)
470
+ context: errorString
469
471
  }),
470
472
  status: PaymentStatus.FAIL
471
473
  };
@@ -476,7 +478,7 @@ var ElementController = /*#__PURE__*/function () {
476
478
  });
477
479
  recordResult = errorResult;
478
480
  recordResultCallback(errorResult);
479
- case 29:
481
+ case 30:
480
482
  case "end":
481
483
  return _context3.stop();
482
484
  }
@@ -63,14 +63,20 @@ export function checkCanMount(_ref) {
63
63
  return {
64
64
  success: false,
65
65
  errorMsg: "Element with selector ".concat(sdkSelector, " not found."),
66
- error: ERRORMESSAGE.PARAM_INVALID
66
+ error: {
67
+ code: ERRORMESSAGE.PARAM_INVALID.code,
68
+ message: "Element with selector ".concat(sdkSelector, " not found.")
69
+ }
67
70
  };
68
71
  }
69
72
  if (status === IElementStatus.DESTROYED) {
70
73
  return {
71
74
  success: false,
72
75
  errorMsg: "Creating components in the destroyed state is forbidden.",
73
- error: ERRORMESSAGE.UI_STATE_ERROR
76
+ error: {
77
+ code: ERRORMESSAGE.UI_STATE_ERROR.code,
78
+ message: "Creating components in the destroyed state is forbidden."
79
+ }
74
80
  };
75
81
  }
76
82
  if (status === IElementStatus.READY) {
@@ -82,7 +88,10 @@ export function checkCanMount(_ref) {
82
88
  return {
83
89
  success: false,
84
90
  errorMsg: "SDK status error.",
85
- error: ERRORMESSAGE.UI_STATE_ERROR
91
+ error: {
92
+ code: ERRORMESSAGE.UI_STATE_ERROR.code,
93
+ message: "SDK status error."
94
+ }
86
95
  };
87
96
  }
88
97
  return {
@@ -35,6 +35,7 @@ export declare class LogService implements Service {
35
35
  log(type: string, payload: LogPayload, extra?: LogExtra, enableExtractCompliance?: boolean): LogService;
36
36
  private reportLogs;
37
37
  private loadScript;
38
+ private fallbackLoadScript;
38
39
  private initTracker;
39
40
  send(): void;
40
41
  setComponentStartTime(val: number): void;
@@ -183,6 +183,43 @@ export var LogService = /*#__PURE__*/function () {
183
183
  }, {
184
184
  key: "loadScript",
185
185
  value: function loadScript(url, callback) {
186
+ var _this3 = this;
187
+ /*
188
+ * 如果宿主环境存在AMD加载器,通过直接创建script标签的方式加载会造成宿主环境报错:
189
+ * Message: Mismatched anonymous define() module
190
+ * 原因是直接通过script标签加载的模块如果没有定义模块名,会被AMD加载器认为是匿名模块,
191
+ * 而宿主环境中已经存在匿名模块,导致报错。
192
+ *
193
+ * TODO: 所有通过window.iTracker调用的方法都需要判断
194
+ * 是否是AMD环境,如果是,需要通过require加载获取iTracker实例
195
+ * */
196
+ if (typeof window.define === 'function' && window.define.amd && typeof window.require === 'function') {
197
+ var moduleId = 'antom_iTracker';
198
+ try {
199
+ var _specified, _ref;
200
+ // 避免重复 config
201
+ if (!((_specified = (_ref = window.require).specified) !== null && _specified !== void 0 && _specified.call(_ref, moduleId))) {
202
+ // @ts-expect-error amd
203
+ window.require.config({
204
+ paths: _defineProperty({}, moduleId, url.replace(/\.js$/, ''))
205
+ });
206
+ }
207
+
208
+ // @ts-expect-error amd
209
+ window.require([moduleId], callback, function (err) {
210
+ console.error('AMD load failed, falling back to script tag', err);
211
+ _this3.fallbackLoadScript(url, callback);
212
+ });
213
+ return;
214
+ } catch (e) {
215
+ console.warn('require not available, using script tag', e);
216
+ }
217
+ }
218
+ this.fallbackLoadScript(url, callback);
219
+ }
220
+ }, {
221
+ key: "fallbackLoadScript",
222
+ value: function fallbackLoadScript(url, callback) {
186
223
  var script = document.createElement('script');
187
224
  script.type = 'text/javascript';
188
225
  script.src = url;
@@ -195,16 +232,16 @@ export var LogService = /*#__PURE__*/function () {
195
232
  }, {
196
233
  key: "initTracker",
197
234
  value: function initTracker() {
198
- var _this3 = this;
235
+ var _this4 = this;
199
236
  if (this.isLoaded) return;
200
237
  this.isLoaded = true;
201
238
  try {
202
239
  if (typeof localStorage !== 'undefined') {
203
240
  this.loadScript(this.config.scriptUrl, function () {
204
241
  var _window4;
205
- (_window4 = window) === null || _window4 === void 0 || _window4.iTracker.initiTracker(_this3.config);
242
+ (_window4 = window) === null || _window4 === void 0 || _window4.iTracker.initiTracker(_this4.config);
206
243
  setTimeout(function () {
207
- _this3.reportLogs();
244
+ _this4.reportLogs();
208
245
  }, 80);
209
246
  });
210
247
  }
package/esm/main.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AddressComponent } from './core/component/address';
2
2
  import { ElementComponent } from './core/component/element';
3
3
  import { AMSComponent } from './core/component/index';
4
- import { ComponentSignEnum, IcreateComponent, IElementOptions, IoptionsAddressParams, IoptionsParams, IPreloadOptions } from './types';
4
+ import { ComponentSignEnum, IcreateComponent, IElementOptions, IoptionsAddressParams, IoptionsParams, IPreloadOptions, ValidationResult } from './types';
5
5
  export { AMSCheckoutPage } from './core/component/ckp';
6
6
  export * from './types';
7
7
  export declare class AMSCheckout extends AMSComponent {
@@ -14,6 +14,15 @@ export declare class AMSAutoDebitPay extends AMSCheckout {
14
14
  export declare class AMSCashierPayment extends AMSCheckout {
15
15
  constructor(options: IoptionsParams);
16
16
  static preload(options?: IPreloadOptions): void;
17
+ /**
18
+ * Form validation function
19
+ * If the form is currently displayed:
20
+ * - Successful validation: isValid is true
21
+ * - Failed validation: isValid is false, and error messages are displayed on the form page
22
+ * If not on the form display page, isValid returns false
23
+ * @returns {Promise<ValidationResult>} Returns a Promise containing the validation result
24
+ */
25
+ validateFields(): Promise<ValidationResult>;
17
26
  }
18
27
  export declare class AMSVaulting extends AMSCheckout {
19
28
  constructor(options: IoptionsParams);
package/esm/main.js CHANGED
@@ -112,7 +112,21 @@ export var AMSCashierPayment = /*#__PURE__*/function (_AMSCheckout2) {
112
112
  }
113
113
  return _super3.call(this, _options, currentChannelType);
114
114
  }
115
- _createClass(AMSCashierPayment, null, [{
115
+ _createClass(AMSCashierPayment, [{
116
+ key: "validateFields",
117
+ value:
118
+ /**
119
+ * Form validation function
120
+ * If the form is currently displayed:
121
+ * - Successful validation: isValid is true
122
+ * - Failed validation: isValid is false, and error messages are displayed on the form page
123
+ * If not on the form display page, isValid returns false
124
+ * @returns {Promise<ValidationResult>} Returns a Promise containing the validation result
125
+ */
126
+ function validateFields() {
127
+ return this._validateFields();
128
+ }
129
+ }], [{
116
130
  key: "preload",
117
131
  value: function preload() {
118
132
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
@@ -238,7 +252,8 @@ export var AMSEasyPay = /*#__PURE__*/function () {
238
252
  displayInfo: {
239
253
  type: DisplayTypeEnum.popup
240
254
  },
241
- isAppWebview: params.isAppWebview
255
+ isAppWebview: params.isAppWebview,
256
+ isNativeAppWebview: params.isNativeAppWebview
242
257
  });
243
258
  }
244
259
  }, {
@@ -56,6 +56,7 @@ export declare class Logger {
56
56
  reportRPC(rpcData: LogPayload, extra?: Extra): Logger;
57
57
  reportLogs(): void;
58
58
  loadScript(url: string, callback: () => void): void;
59
+ private fallbackLoadScript;
59
60
  initTracker(): void;
60
61
  send(): void;
61
62
  setComponentStartTime(val: number): void;
@@ -176,6 +176,43 @@ export var Logger = /*#__PURE__*/function () {
176
176
  }, {
177
177
  key: "loadScript",
178
178
  value: function loadScript(url, callback) {
179
+ var _this5 = this;
180
+ /*
181
+ * 如果宿主环境存在AMD加载器,通过直接创建script标签的方式加载会造成宿主环境报错:
182
+ * Message: Mismatched anonymous define() module
183
+ * 原因是直接通过script标签加载的模块如果没有定义模块名,会被AMD加载器认为是匿名模块,
184
+ * 而宿主环境中已经存在匿名模块,导致报错。
185
+ *
186
+ * TODO: 所有通过window.iTracker调用的方法都需要判断
187
+ * 是否是AMD环境,如果是,需要通过require加载获取iTracker实例
188
+ * */
189
+ if (typeof window.define === 'function' && window.define.amd && typeof window.require === 'function') {
190
+ var moduleId = 'antom_iTracker';
191
+ try {
192
+ var _specified, _ref;
193
+ // 避免重复 config
194
+ if (!((_specified = (_ref = window.require).specified) !== null && _specified !== void 0 && _specified.call(_ref, moduleId))) {
195
+ // @ts-expect-error amd
196
+ window.require.config({
197
+ paths: _defineProperty({}, moduleId, url.replace(/\.js$/, ''))
198
+ });
199
+ }
200
+
201
+ // @ts-expect-error amd
202
+ window.require([moduleId], callback, function (err) {
203
+ console.error('AMD load failed, falling back to script tag', err);
204
+ _this5.fallbackLoadScript(url, callback);
205
+ });
206
+ return;
207
+ } catch (e) {
208
+ console.warn('require not available, using script tag', e);
209
+ }
210
+ }
211
+ this.fallbackLoadScript(url, callback);
212
+ }
213
+ }, {
214
+ key: "fallbackLoadScript",
215
+ value: function fallbackLoadScript(url, callback) {
179
216
  var script = document.createElement('script');
180
217
  script.type = 'text/javascript';
181
218
  script.src = url;
@@ -188,16 +225,16 @@ export var Logger = /*#__PURE__*/function () {
188
225
  }, {
189
226
  key: "initTracker",
190
227
  value: function initTracker() {
191
- var _this5 = this;
228
+ var _this6 = this;
192
229
  if (this.isLoaded) return;
193
230
  this.isLoaded = true;
194
231
  try {
195
232
  if (typeof localStorage !== 'undefined') {
196
233
  this.loadScript(this.config.scriptUrl, function () {
197
234
  var _window4;
198
- (_window4 = window) === null || _window4 === void 0 || _window4.iTracker.initiTracker(_this5.config);
235
+ (_window4 = window) === null || _window4 === void 0 || _window4.iTracker.initiTracker(_this6.config);
199
236
  setTimeout(function () {
200
- _this5.reportLogs();
237
+ _this6.reportLogs();
201
238
  }, 80);
202
239
  });
203
240
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",