@alipay/ams-checkout 0.0.1766664288-dev.0 → 0.0.1766756057-dev.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.
@@ -1,16 +1,22 @@
1
+ /**
2
+ * Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+ * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
6
+ * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
7
+ */
1
8
  export declare const marmotMap: Record<string, string>;
2
9
  export declare const marmotConfigMap: Record<string, string>;
3
10
  export declare const v2AppMarmotMap: Record<string, string>;
4
11
  export declare const sdkVersion: string;
5
12
  /**
6
13
  * @description: 目前应用层分为v1和v2,会存在两个应用版本号不是同步发布的情况。所以需要把默认的应用版本号配置抽离出来。
7
- * TODO 这里考虑直接换成packagejson.version
8
14
  */
9
- export declare const AMSCheckoutAppVersion = "1.47.2";
10
- export declare const AMSAutoDebitAppVersion = "1.47.2";
11
- export declare const AMSEasyPayAppVersion = "1.47.2";
12
- export declare const AMSCashierPaymentAppVersion = "1.47.2";
13
- export declare const AMSVaultingAppVersion = "1.47.2";
14
- export declare const AMSPaymentElementAppVersion = "1.47.2";
15
- export declare const ADDRESSElementAppVersion = "1.47.2";
16
- export declare const AUTHElementAppVersion = "1.47.2";
15
+ export declare const AMSCheckoutAppVersion: string;
16
+ export declare const AMSAutoDebitAppVersion: string;
17
+ export declare const AMSEasyPayAppVersion: string;
18
+ export declare const AMSCashierPaymentAppVersion: string;
19
+ export declare const AMSVaultingAppVersion: string;
20
+ export declare const AMSPaymentElementAppVersion: string;
21
+ export declare const ADDRESSElementAppVersion: string;
22
+ export declare const AUTHElementAppVersion: string;
@@ -5,7 +5,6 @@
5
5
  * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
6
6
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
7
7
  */
8
- import json from "../../package.json";
9
8
  export var marmotMap = {
10
9
  dev: 'http://page.alipay.net/page/antom-web-checkout/src/component-app',
11
10
  sit: 'http://page.test.alipay.net/page/antom-web-checkout/src/component-app',
@@ -30,17 +29,16 @@ export var v2AppMarmotMap = {
30
29
  light_sandbox: 'https://checkout.antom.com',
31
30
  prod: 'https://checkout.antom.com'
32
31
  };
33
- export var sdkVersion = json.version;
32
+ export var sdkVersion = "".concat("0.0.1766756057-dev.0");
34
33
 
35
34
  /**
36
35
  * @description: 目前应用层分为v1和v2,会存在两个应用版本号不是同步发布的情况。所以需要把默认的应用版本号配置抽离出来。
37
- * TODO 这里考虑直接换成packagejson.version
38
36
  */
39
- export var AMSCheckoutAppVersion = '1.47.2'; // 兜底版本号
40
- export var AMSAutoDebitAppVersion = '1.47.2'; // 代扣
41
- export var AMSEasyPayAppVersion = '1.47.2'; // easypay
42
- export var AMSCashierPaymentAppVersion = '1.47.2'; // 收银台(卡、apm)
43
- export var AMSVaultingAppVersion = '1.47.2'; // 绑卡
44
- export var AMSPaymentElementAppVersion = '1.47.2'; // payment element
45
- export var ADDRESSElementAppVersion = '1.47.2'; // address element
46
- export var AUTHElementAppVersion = '1.47.2'; // auth element
37
+ export var AMSCheckoutAppVersion = sdkVersion; // 兜底版本号
38
+ export var AMSAutoDebitAppVersion = sdkVersion; // 代扣
39
+ export var AMSEasyPayAppVersion = sdkVersion; // easypay
40
+ export var AMSCashierPaymentAppVersion = sdkVersion; // 收银台(卡、apm)
41
+ export var AMSVaultingAppVersion = sdkVersion; // 绑卡
42
+ export var AMSPaymentElementAppVersion = sdkVersion; // payment element
43
+ export var ADDRESSElementAppVersion = sdkVersion; // address element
44
+ export var AUTHElementAppVersion = sdkVersion; // auth element
@@ -1,4 +1,4 @@
1
- import { AddressMountOptions, EventDataMap, EVENTNAME, ICommonApiResponse, IElementOptions, IPaymentApiResponse, LinkAuthMountOptions, PaymentMountOptions, SubmitFuncParams } from '../type';
1
+ import { AddressMountOptions, ICommonApiResponse, IElementOptions, IPaymentApiResponse, LinkAuthMountOptions, PaymentMountOptions } from '../type';
2
2
  declare class ElementController {
3
3
  private options;
4
4
  private elementContainer;
@@ -33,7 +33,7 @@ declare class ElementController {
33
33
  validateFields(): Promise<{
34
34
  isValid: boolean;
35
35
  }>;
36
- submitPayment(submitParams: SubmitFuncParams): Promise<IPaymentApiResponse>;
36
+ submitPayment(): Promise<IPaymentApiResponse>;
37
37
  private changeLoading;
38
38
  private addEventListener;
39
39
  private sendRequestAndWaitWebLaunch;
@@ -44,7 +44,5 @@ declare class ElementController {
44
44
  private destroyHandle;
45
45
  destroy(): void;
46
46
  private setControllerStatusOrView;
47
- on<T extends EVENTNAME>(event: T, callback: (data: EventDataMap[T]) => void): void;
48
- private isEventAllowed;
49
47
  }
50
48
  export default ElementController;
@@ -40,9 +40,8 @@ import { IContainerStatus } from "../elementContainerService/containerService";
40
40
  import { EventCenter as ElementEventCenter } from "../EventCenter/index";
41
41
  import { oneAccountUpdate, sdkActionUpdate } from "../mock";
42
42
  import { ElementPaymentEvent, ElementPaymentMethod, ElementType, EventCallbackCode, EXPOSURE_API_EVENT, MountElementType, PaymentStatus } from "../type";
43
- import { checkCanMount, checkCanUpdate, handleRedirect, isLoadErrorPage, safeParse, safeStringify, showToast } from "../util";
43
+ import { checkCanMount, checkCanUpdate, handleRedirect, isLoadErrorPage, safeStringify, showToast } from "../util";
44
44
  import { convertPaymentSession } from "../../../../foundation/utils/payment_context_utils";
45
- import { productEventScenarios, ProductScene } from "../config";
46
45
  var TIMEOUT_DURATION = 10000;
47
46
  var ElementController = /*#__PURE__*/function () {
48
47
  function ElementController(options) {
@@ -338,7 +337,7 @@ var ElementController = /*#__PURE__*/function () {
338
337
  }, {
339
338
  key: "submitPayment",
340
339
  value: function () {
341
- var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(submitParams) {
340
+ var _submitPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
342
341
  var _this3 = this;
343
342
  var startEventId, res, logParams, recordResult, _recordResult, _recordResult2, _recordResult3, _recordResult4, _recordResult5, _logParams;
344
343
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
@@ -370,7 +369,7 @@ var ElementController = /*#__PURE__*/function () {
370
369
  _context4.next = 11;
371
370
  return new Promise( /*#__PURE__*/function () {
372
371
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
373
- var that, recordResultCallback, params, processStep, _yield$_this3$onValid2, _data, errorResult;
372
+ var that, recordResultCallback, params, processStep, _yield$_this3$onValid2, data, errorString, errorResult;
374
373
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
375
374
  while (1) switch (_context3.prev = _context3.next) {
376
375
  case 0:
@@ -423,7 +422,7 @@ var ElementController = /*#__PURE__*/function () {
423
422
  }
424
423
  }, _callee2);
425
424
  }));
426
- return function processStep(_x3, _x4) {
425
+ return function processStep(_x2, _x3) {
427
426
  return _ref4.apply(this, arguments);
428
427
  };
429
428
  }(); // 按顺序处理步骤
@@ -446,28 +445,29 @@ var ElementController = /*#__PURE__*/function () {
446
445
  return _context3.abrupt("return");
447
446
  case 14:
448
447
  if (!_this3.elementProcessors[ElementType.payment]) {
449
- _context3.next = 22;
448
+ _context3.next = 21;
450
449
  break;
451
450
  }
452
- params.handleAction = (submitParams === null || submitParams === void 0 ? void 0 : submitParams.handleAction) || false;
453
- _context3.next = 18;
451
+ _context3.next = 17;
454
452
  return _this3.onValidateAndSubmitPay(_this3.elementProcessors[ElementType.payment].eventCenter, ElementPaymentMethod.PAYMENT_ELEMENT, params);
455
- case 18:
453
+ case 17:
456
454
  _yield$_this3$onValid2 = _context3.sent;
457
- _data = _yield$_this3$onValid2.data;
455
+ data = _yield$_this3$onValid2.data;
458
456
  // TODO 先快速修复类型, 这里结构和标准返回不一致 @马杰
459
457
  // TODO checkout 返回的错误未包含 status 和 message @马杰 @薛浩
460
- recordResult = _data;
458
+ recordResult = data;
461
459
  recordResultCallback(recordResult);
462
- case 22:
460
+ case 21:
463
461
  _context3.next = 30;
464
462
  break;
465
- case 24:
466
- _context3.prev = 24;
463
+ case 23:
464
+ _context3.prev = 23;
467
465
  _context3.t0 = _context3["catch"](2);
466
+ // 修复error为{}空对象的问题,上报stack&message
467
+ errorString = JSON.stringify(_context3.t0, Object.getOwnPropertyNames(_context3.t0));
468
468
  errorResult = {
469
469
  error: _objectSpread(_objectSpread({}, ERRORMESSAGE.ERR_DATA_STRUCT_UNRECOGNIZED), {}, {
470
- context: JSON.stringify(_context3.t0)
470
+ context: errorString
471
471
  }),
472
472
  status: PaymentStatus.FAIL
473
473
  };
@@ -482,9 +482,9 @@ var ElementController = /*#__PURE__*/function () {
482
482
  case "end":
483
483
  return _context3.stop();
484
484
  }
485
- }, _callee3, null, [[2, 24]]);
485
+ }, _callee3, null, [[2, 23]]);
486
486
  }));
487
- return function (_x2) {
487
+ return function (_x) {
488
488
  return _ref3.apply(this, arguments);
489
489
  };
490
490
  }());
@@ -509,7 +509,7 @@ var ElementController = /*#__PURE__*/function () {
509
509
  }
510
510
  }, _callee4, this, [[8,, 12, 17]]);
511
511
  }));
512
- function submitPayment(_x) {
512
+ function submitPayment() {
513
513
  return _submitPayment.apply(this, arguments);
514
514
  }
515
515
  return submitPayment;
@@ -654,7 +654,7 @@ var ElementController = /*#__PURE__*/function () {
654
654
  }
655
655
  }, _callee5, this, [[1, 20]]);
656
656
  }));
657
- function sendRequestAndWaitWebLaunch(_x5, _x6) {
657
+ function sendRequestAndWaitWebLaunch(_x4, _x5) {
658
658
  return _sendRequestAndWaitWebLaunch.apply(this, arguments);
659
659
  }
660
660
  return sendRequestAndWaitWebLaunch;
@@ -787,7 +787,7 @@ var ElementController = /*#__PURE__*/function () {
787
787
  }
788
788
  }, _callee6);
789
789
  }));
790
- return function (_x8) {
790
+ return function (_x7) {
791
791
  return _ref5.apply(this, arguments);
792
792
  };
793
793
  }()));
@@ -797,7 +797,7 @@ var ElementController = /*#__PURE__*/function () {
797
797
  }
798
798
  }, _callee7);
799
799
  }));
800
- function updatePayment(_x7) {
800
+ function updatePayment(_x6) {
801
801
  return _updatePayment.apply(this, arguments);
802
802
  }
803
803
  return updatePayment;
@@ -834,30 +834,6 @@ var ElementController = /*#__PURE__*/function () {
834
834
  (_this$onStatusChangeC = this.onStatusChangeCallback) === null || _this$onStatusChangeC === void 0 || _this$onStatusChangeC.call(this, "\u72B6\u6001\u7531 ".concat(_status, " \u53D8\u66F4\u4E3A ").concat(status));
835
835
  this.elementContainer.setStatus(status);
836
836
  }
837
- }, {
838
- key: "on",
839
- value: function on(event, callback) {
840
- if (!this.isEventAllowed(event)) {
841
- return console.error("Event \"".concat(event, "\" is not allowed."));
842
- }
843
- this.serviceMap.EventCenter.listen(event, function (data) {
844
- callback === null || callback === void 0 || callback(data);
845
- });
846
- }
847
- }, {
848
- key: "isEventAllowed",
849
- value: function isEventAllowed(event) {
850
- var _safeParse, _this$elementContaine;
851
- // 获取当前场景
852
- var isExpressCheckout = (_safeParse = safeParse((_this$elementContaine = this.elementContainer.getPaymentContext()) === null || _this$elementContaine === void 0 || (_this$elementContaine = _this$elementContaine.paymentSessionObj) === null || _this$elementContaine === void 0 ? void 0 : _this$elementContaine.extendInfo)) === null || _safeParse === void 0 ? void 0 : _safeParse.expressCheckout;
853
- var productScene = isExpressCheckout ? ProductScene.EXPRESS_CHECKOUT : ProductScene.ELEMENT_PAYMENT;
854
- // 查找对应的产品场景
855
- var scenario = productEventScenarios.find(function (s) {
856
- return s.eventName === productScene;
857
- });
858
- // 检查场景存在且事件名称在支持的事件列表中
859
- return scenario !== undefined && scenario.supportedEvents.includes(event);
860
- }
861
837
  }]);
862
838
  return ElementController;
863
839
  }();
@@ -1,4 +1,4 @@
1
- import { EventDataMap, EVENTNAME, IElementOptions, PaymentMountOptions, SubmitFuncParams } from './type';
1
+ import { IElementOptions, PaymentMountOptions } from './type';
2
2
  export declare class ElementComponent {
3
3
  private options;
4
4
  private controller;
@@ -8,7 +8,6 @@ export declare class ElementComponent {
8
8
  validateFields(): Promise<{
9
9
  isValid: boolean;
10
10
  }>;
11
- submitPayment(params: SubmitFuncParams): Promise<import("./type").IPaymentApiResponse>;
11
+ submitPayment(): Promise<import("./type").IPaymentApiResponse>;
12
12
  destroy(): void;
13
- on<T extends EVENTNAME>(event: T, callback: (data: EventDataMap[T]) => void): void;
14
13
  }
@@ -62,19 +62,14 @@ export var ElementComponent = /*#__PURE__*/function () {
62
62
  }
63
63
  }, {
64
64
  key: "submitPayment",
65
- value: function submitPayment(params) {
66
- return this.controller.submitPayment(params);
65
+ value: function submitPayment() {
66
+ return this.controller.submitPayment();
67
67
  }
68
68
  }, {
69
69
  key: "destroy",
70
70
  value: function destroy() {
71
71
  this.controller.destroy();
72
72
  }
73
- }, {
74
- key: "on",
75
- value: function on(event, callback) {
76
- this.controller.on(event, callback);
77
- }
78
73
  }]);
79
74
  return ElementComponent;
80
75
  }();
@@ -261,13 +261,9 @@ export interface AddressSubmitData {
261
261
  shippingId: string;
262
262
  actionFlag?: 'I' | 'U' | 'D';
263
263
  }
264
- export interface SubmitFuncParams {
265
- handleAction?: boolean;
266
- }
267
264
  export interface SubmitServiceParams extends PaymentSubmitData {
268
265
  accountInfo: AuthSubmitData['accountInfo'];
269
266
  shipping?: AddressSubmitData;
270
- handleAction?: boolean;
271
267
  }
272
268
  interface SubmitResultActionForm extends ActionForm {
273
269
  paymentCodeExpireTime: string;
@@ -447,14 +443,4 @@ export declare enum EXPOSURE_API_EVENT {
447
443
  VALIDATAFIELDS = "validateFields",
448
444
  UPDATEPAYMENT = "updatePayment"
449
445
  }
450
- export declare enum EVENTNAME {
451
- PAYMENTMETHODCHANGED = "paymentMethodChanged"
452
- }
453
- interface PaymentMethodChangedData {
454
- type: string;
455
- name: string;
456
- }
457
- export interface EventDataMap {
458
- [EVENTNAME.PAYMENTMETHODCHANGED]: PaymentMethodChangedData;
459
- }
460
446
  export {};
@@ -147,10 +147,4 @@ export var EXPOSURE_API_EVENT = /*#__PURE__*/function (EXPOSURE_API_EVENT) {
147
147
  EXPOSURE_API_EVENT["VALIDATAFIELDS"] = "validateFields";
148
148
  EXPOSURE_API_EVENT["UPDATEPAYMENT"] = "updatePayment";
149
149
  return EXPOSURE_API_EVENT;
150
- }({});
151
- export var EVENTNAME = /*#__PURE__*/function (EVENTNAME) {
152
- EVENTNAME["PAYMENTMETHODCHANGED"] = "paymentMethodChanged";
153
- return EVENTNAME;
154
- }({});
155
-
156
- // 支付方式改变的回调函数的数据结构
150
+ }({});
@@ -83,4 +83,3 @@ export declare const isElementPC: () => boolean;
83
83
  */
84
84
  export declare const isLoadErrorPage: (params: CashierSdkActionQueryResult) => boolean;
85
85
  export declare const safeStringify: (payload: any, defaultValue?: string) => string;
86
- export declare const safeParse: (payload: any, defaultValue?: Record<string, any>) => Record<string, any>;
@@ -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 {
@@ -526,14 +535,4 @@ export var safeStringify = function safeStringify(payload) {
526
535
  console.error('JSON.stringify failed:', e);
527
536
  return defaultValue;
528
537
  }
529
- };
530
- export var safeParse = function safeParse(payload) {
531
- var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
532
- if (!payload) return defaultValue;
533
- try {
534
- return JSON.parse(payload) || defaultValue;
535
- } catch (e) {
536
- console.error('JSON.parse failed:', e);
537
- return defaultValue;
538
- }
539
538
  };
@@ -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;
@@ -7,7 +7,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
7
7
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
8
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
9
  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); }
10
- import json from "../../package.json";
10
+ import { sdkVersion } from "../config";
11
11
  import { LogComplianceProcessor } from "../foundation/service/log/processor";
12
12
  import { SPM_MAP } from "./spm-map";
13
13
  export var Logger = /*#__PURE__*/function () {
@@ -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
  }
@@ -255,6 +292,6 @@ export var LogConfig = {
255
292
  version: 'iteration/20231021',
256
293
  mdata: {
257
294
  firstLogTime: Date.now(),
258
- sdkVersion: json === null || json === void 0 ? void 0 : json.version
295
+ sdkVersion: sdkVersion
259
296
  }
260
297
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1766664288-dev.0",
3
+ "version": "0.0.1766756057-dev.0",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",
@@ -68,7 +68,7 @@
68
68
  "dts-bundle-generator": "^6.13.0",
69
69
  "eslint": "^8.56.0",
70
70
  "eslint-plugin-prettier": "^5.1.3",
71
- "father": "^4.2.3",
71
+ "father": "^4.6.12",
72
72
  "jest": "^29.5.0",
73
73
  "jest-environment-jsdom": "^29.3.1",
74
74
  "prettier": "^2.8.4",
@@ -1,10 +0,0 @@
1
- export declare enum ProductScene {
2
- EXPRESS_CHECKOUT = "EXPRESS_CHECKOUT",
3
- ELEMENT_PAYMENT = "ELEMENT_PAYMENT"
4
- }
5
- interface EventScenario {
6
- eventName: ProductScene;
7
- supportedEvents: string[];
8
- }
9
- export declare const productEventScenarios: EventScenario[];
10
- export {};
@@ -1,17 +0,0 @@
1
- // 定义产品场景的枚举
2
- export var ProductScene = /*#__PURE__*/function (ProductScene) {
3
- ProductScene["EXPRESS_CHECKOUT"] = "EXPRESS_CHECKOUT";
4
- ProductScene["ELEMENT_PAYMENT"] = "ELEMENT_PAYMENT";
5
- return ProductScene;
6
- }({});
7
-
8
- // 定义一个事件场景的接口
9
-
10
- // 存储产品场景及支持的事件名
11
- export var productEventScenarios = [{
12
- eventName: ProductScene.EXPRESS_CHECKOUT,
13
- supportedEvents: [] // 没有支持的事件
14
- }, {
15
- eventName: ProductScene.ELEMENT_PAYMENT,
16
- supportedEvents: ['paymentMethodChanged'] // 支持的事件
17
- }];